route-claudecode
Version:
Advanced routing and transformation system for Claude Code outputs to multiple AI providers
126 lines • 3.24 kB
TypeScript
/**
* CodeWhisperer 实时流式客户端
* 基于demo2的Go实现移植,实现零延迟流式处理
* 项目所有者: Jason Zhang
*/
import { AnthropicRequest, ICodeWhispererClient } from './client-interface';
import { CodeWhispererStreamingConfig } from './config/streaming-config';
export interface RealtimeClientOptions {
enableZeroDelay: boolean;
maxConcurrentStreams: number;
binaryFrameSize: number;
toolCallStrategy: 'immediate' | 'buffered';
enableCompression: boolean;
}
export declare class CodeWhispererRealtimeClient implements ICodeWhispererClient {
private readonly auth;
private readonly converter;
private readonly parser;
private readonly metrics;
private readonly config;
private readonly options;
private readonly httpTimeout;
private readonly maxRetries;
private tokenBlacklisted;
private consecutiveRefreshFailures;
private readonly maxRefreshFailures;
private activeStreams;
constructor(config: CodeWhispererStreamingConfig);
/**
* 处理流式请求 - 实时流式实现
*/
handleStreamRequest(anthropicReq: AnthropicRequest, writeSSE: (event: string, data: any) => void, onError: (message: string, error: Error) => void): Promise<void>;
/**
* 实时处理响应流 - 核心实时特性
*/
private processRealtimeStream;
/**
* 发送初始事件
*/
private sendInitialEvents;
/**
* 发送结束事件
*/
private sendFinalEvents;
/**
* 处理非流式请求 - 实时优化版本
*/
handleNonStreamRequest(anthropicReq: AnthropicRequest): Promise<any>;
/**
* 实时处理非流式响应
*/
private processRealtimeNonStreamResponse;
/**
* 获取客户端类型
*/
getClientType(): 'buffered' | 'realtime';
/**
* 健康检查
*/
healthCheck(): Promise<{
healthy: boolean;
type: string;
message?: string;
}>;
/**
* Token可用性检查
*/
private isTokenAvailable;
/**
* 标记token为不可用
*/
private markTokenUnavailable;
/**
* 报告token刷新失败
*/
private reportRefreshFailure;
/**
* 报告token刷新成功
*/
private reportRefreshSuccess;
/**
* 执行带重试机制的操作
*/
private executeWithRetry;
/**
* 获取认证信息 - 修复支持authMethod
*/
private getAuthInfo;
/**
* 构建和验证请求 - 修复支持authMethod条件判断
*/
private buildAndValidateRequest;
/**
* 发送HTTP请求
*/
private sendHttpRequest;
/**
* 发送非流式HTTP请求
*/
private sendNonStreamHttpRequest;
/**
* 处理流式请求错误
*/
private handleStreamError;
/**
* 创建请求信息
*/
private createRequestInfo;
/**
* 计算消息长度
*/
private calculateMessageLength;
/**
* 计算内容长度
*/
private calculateContentLength;
/**
* 睡眠函数
*/
private sleep;
/**
* 将Buffer转换为Readable流
*/
private bufferToStream;
}
//# sourceMappingURL=client-realtime.d.ts.map