CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
109 lines
2.7 KiB
TypeScript
109 lines
2.7 KiB
TypeScript
/**
|
|
* API Server Augmentation - Universal API Exposure
|
|
*
|
|
* 🌐 Exposes Brainy through REST, WebSocket, and MCP
|
|
* 🔌 Works in Node.js, Deno, and Service Workers
|
|
* 🚀 Single augmentation for all API needs
|
|
*
|
|
* This unifies and replaces:
|
|
* - BrainyMCPBroadcast (Node-specific server)
|
|
* - WebSocketConduitAugmentation (client connections)
|
|
* - Future REST API implementations
|
|
*/
|
|
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
export interface APIServerConfig {
|
|
enabled?: boolean;
|
|
port?: number;
|
|
mcpPort?: number;
|
|
wsPort?: number;
|
|
host?: string;
|
|
cors?: {
|
|
origin?: string | string[];
|
|
credentials?: boolean;
|
|
};
|
|
auth?: {
|
|
required?: boolean;
|
|
apiKeys?: string[];
|
|
bearerTokens?: string[];
|
|
};
|
|
rateLimit?: {
|
|
windowMs?: number;
|
|
max?: number;
|
|
};
|
|
ssl?: {
|
|
cert?: string;
|
|
key?: string;
|
|
};
|
|
}
|
|
/**
|
|
* Unified API Server Augmentation
|
|
* Exposes Brainy through multiple protocols
|
|
*/
|
|
export declare class APIServerAugmentation extends BaseAugmentation {
|
|
readonly name = "api-server";
|
|
readonly timing: "after";
|
|
readonly metadata: "readonly";
|
|
readonly operations: ("all")[];
|
|
readonly priority = 5;
|
|
protected config: APIServerConfig;
|
|
private mcpService?;
|
|
private httpServer?;
|
|
private wsServer?;
|
|
private clients;
|
|
private operationHistory;
|
|
private maxHistorySize;
|
|
constructor(config?: APIServerConfig);
|
|
protected onInitialize(): Promise<void>;
|
|
/**
|
|
* Start Node.js server with Express
|
|
*/
|
|
private startNodeServer;
|
|
/**
|
|
* Setup REST API routes
|
|
*/
|
|
private setupRESTRoutes;
|
|
/**
|
|
* Setup WebSocket server
|
|
*/
|
|
private setupWebSocketServer;
|
|
/**
|
|
* Handle WebSocket message
|
|
*/
|
|
private handleWebSocketMessage;
|
|
/**
|
|
* Execute augmentation - broadcast operations to clients
|
|
*/
|
|
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
/**
|
|
* Auth middleware for Express
|
|
*/
|
|
private authMiddleware;
|
|
/**
|
|
* Rate limiting middleware
|
|
*/
|
|
private rateLimitMiddleware;
|
|
/**
|
|
* Sanitize parameters before broadcasting
|
|
*/
|
|
private sanitizeParams;
|
|
/**
|
|
* Send heartbeats to all connected clients
|
|
*/
|
|
private sendHeartbeats;
|
|
/**
|
|
* Start Deno server
|
|
*/
|
|
private startDenoServer;
|
|
/**
|
|
* Start Service Worker (for browser)
|
|
*/
|
|
private startServiceWorker;
|
|
/**
|
|
* Shutdown the server
|
|
*/
|
|
protected onShutdown(): Promise<void>;
|
|
}
|
|
/**
|
|
* Helper function to create and configure API server
|
|
*/
|
|
export declare function createAPIServer(config?: APIServerConfig): APIServerAugmentation;
|