UNPKG

route-claudecode

Version:

Advanced routing and transformation system for Claude Code outputs to multiple AI providers

90 lines 2.45 kB
/** * Max Tokens错误处理模块 - 集中处理token限制问题 * Project Owner: Jason Zhang * * 当收到max_tokens/length stop_reason时的智能处理方案 * Option 1: 滚动截断处理机制 (当前实现) * Option 2: LongContext模型压缩 (预留接口) */ import { BaseRequest } from '@/types'; export interface MaxTokensHandlingConfig { strategy: 'rolling_truncation' | 'longcontext_compression'; rollingTruncation: { historyRetentionPercent: number; useSimplifiedPrompt: boolean; simplifiedPromptPath: string; }; longcontextCompression?: { enabled: boolean; recentHistoryPercent: number; compressionModel: string; compressionEndpoint: string; }; } export interface TruncationResult { success: boolean; originalTokens: number; reducedTokens: number; truncatedRequest: BaseRequest; strategy: string; details: { systemPromptReduced: boolean; historyMessagesRemoved: number; totalMessagesRemaining: number; }; } export declare class MaxTokensErrorHandlingModule { private config; private configPath; constructor(configPath?: string); /** * 加载配置文件 */ private loadConfiguration; /** * 获取默认配置 */ private getDefaultConfig; /** * 保存配置文件 */ private saveConfiguration; /** * 处理max tokens错误 - 主入口 */ handleMaxTokensError(originalRequest: BaseRequest, errorDetails: any, requestId: string): Promise<TruncationResult>; /** * Option 1: 滚动截断处理 */ private handleRollingTruncation; /** * Option 2: LongContext模型压缩 (预留实现) */ private handleLongcontextCompression; /** * 获取简化版系统提示词 */ private getSimplifiedSystemPrompt; /** * 创建默认简化系统提示词 */ private createDefaultSimplifiedPrompt; /** * 保存简化版系统提示词 */ private saveSimplifiedPrompt; /** * 估算请求的token数量 */ private estimateTokens; /** * 获取当前配置 */ getConfig(): MaxTokensHandlingConfig; /** * 更新配置 */ updateConfig(updates: Partial<MaxTokensHandlingConfig>): void; } export default MaxTokensErrorHandlingModule; //# sourceMappingURL=max-tokens-error-handling-module.d.ts.map