@hivetechs/hive-ai
Version:
Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API
98 lines • 2.67 kB
TypeScript
/**
* OpenRouter Streaming Client
*
* Advanced streaming client for real-time consensus with live token streaming,
* progress updates, and cancellation support. Built on top of the bulletproof
* error handling system from Phase 2C.
*/
export interface StreamingMessage {
role: 'user' | 'assistant' | 'system';
content: string;
}
export interface StreamingOptions {
temperature?: number;
max_tokens?: number;
stream?: boolean;
top_p?: number;
frequency_penalty?: number;
presence_penalty?: number;
}
export interface StreamChunk {
id: string;
object: string;
created: number;
model: string;
choices: Array<{
index: number;
delta: {
role?: string;
content?: string;
};
finish_reason?: string | null;
}>;
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
export interface StreamingResponse {
id: string;
model: string;
content: string;
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
export interface StreamingCallbacks {
onChunk?: (chunk: string, totalContent: string) => void;
onProgress?: (progress: {
tokens: number;
estimatedTotal?: number;
percentage?: number;
}) => void;
onComplete?: (response: StreamingResponse) => void;
onError?: (error: Error) => void;
onStart?: () => void;
}
export declare class OpenRouterStreamingClient {
private apiKey;
private abortController;
private currentStreamId;
constructor(apiKey: string);
/**
* Stream chat completions with real-time token output
*/
streamChatCompletion(model: string, messages: StreamingMessage[], options?: StreamingOptions, callbacks?: StreamingCallbacks): Promise<StreamingResponse>;
/**
* Perform the actual streaming request
*/
private performStreamingRequest;
/**
* Process the streaming response
*/
private processStreamingResponse;
/**
* Cancel the current streaming request
*/
cancelStream(): boolean;
/**
* Check if a stream is currently active
*/
isStreaming(): boolean;
/**
* Get current stream ID
*/
getCurrentStreamId(): string | null;
}
/**
* Factory function to create streaming client
*/
export declare function createStreamingClient(): Promise<OpenRouterStreamingClient>;
/**
* Test streaming connectivity
*/
export declare function testStreamingConnection(model?: string): Promise<boolean>;
//# sourceMappingURL=openrouter-streaming-client.d.ts.map