@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
116 lines (115 loc) • 3.27 kB
TypeScript
/**
* Server-Sent Events (SSE) Client for NeuroLink SDK
*
* Provides a dedicated SSE client for server-push streaming connections
* to NeuroLink servers. Supports automatic reconnection, event parsing,
* and typed event handlers.
*
* @module @neurolink/client/sseClient
*/
import type { ClientStreamCallbacks, SSEConfig, SSEEventHandlers, SSERequestOptions, SSEState } from "../types/index.js";
/**
* SSE streaming client for NeuroLink
*
* Provides server-push streaming from NeuroLink servers using Server-Sent Events.
*
* @example Basic usage
* ```typescript
* const sseClient = new NeuroLinkSSE({
* baseUrl: 'https://api.neurolink.example.com',
* apiKey: 'your-api-key',
* });
*
* // Stream with callbacks
* await sseClient.stream('/api/generate', {
* body: { prompt: 'Hello!' },
* }, {
* onText: (text) => console.log('Text:', text),
* onDone: (result) => console.log('Complete:', result),
* onError: (error) => console.error('Error:', error),
* });
* ```
*/
export declare class NeuroLinkSSE {
private config;
private state;
private abortController;
private reconnectAttempts;
private eventHandlers;
constructor(config: SSEConfig);
/**
* Get current connection state
*/
getState(): SSEState;
/**
* Check if connected
*/
isConnected(): boolean;
/**
* Stream from an endpoint using SSE
*/
stream(path: string, options?: SSERequestOptions, callbacks?: ClientStreamCallbacks): Promise<void>;
private _streamInternal;
/**
* Abort the current stream
*/
abort(): void;
/**
* Set global event handlers
*/
setEventHandlers(handlers: SSEEventHandlers): void;
/**
* Stream a generate request
*/
generate(prompt: string, options?: {
provider?: string;
model?: string;
temperature?: number;
maxTokens?: number;
systemPrompt?: string;
} & ClientStreamCallbacks): Promise<string>;
/**
* Stream a chat request
*/
chat(messages: Array<{
role: string;
content: string;
}>, options?: {
agentId?: string;
sessionId?: string;
} & ClientStreamCallbacks): Promise<string>;
/**
* Stream an agent execution
*/
executeAgent(agentId: string, input: string, options?: ClientStreamCallbacks): Promise<string>;
/**
* Stream using the browser's native EventSource API (GET requests only).
* Provides automatic reconnection handled by the browser and a simpler
* implementation, but only supports GET with limited header control.
*/
private streamWithNativeEventSource;
private buildUrl;
private buildHeaders;
private processStream;
private handleEvent;
private setState;
private attemptReconnect;
}
/**
* Create an SSE client instance
*
* @example
* ```typescript
* const client = createSSEClient({
* baseUrl: 'https://api.neurolink.example.com',
* apiKey: 'your-api-key',
* autoReconnect: true,
* });
*
* // Generate with streaming
* const content = await client.generate('Hello!', {
* onText: (text) => process.stdout.write(text),
* });
* ```
*/
export declare function createSSEClient(config: SSEConfig): NeuroLinkSSE;