UNPKG

route-claudecode

Version:

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

82 lines 2.68 kB
/** * 增强版Max Tokens错误处理器 * 集成智能处理模块,提供滚动截断和压缩等高级功能 * Project Owner: Jason Zhang */ import { BaseRequest } from '@/types'; import { TruncationResult } from './max-tokens-error-handling-module'; export interface EnhancedMaxTokensError extends Error { status: number; code: string; details: { finishReason: string; provider: string; model: string; requestId: string; usage?: any; truncationResult?: TruncationResult; autoRetryAvailable?: boolean; }; } export interface MaxTokensHandlingOptions { enableAutoRetry: boolean; maxRetryAttempts: number; handlingModulePath?: string; } export declare class EnhancedMaxTokensErrorHandler { private handlingModule; private options; constructor(options?: Partial<MaxTokensHandlingOptions>); /** * 检查finish_reason是否表示达到了token限制 */ static isMaxTokensReached(finishReason: string): boolean; /** * 检查Anthropic格式的stop_reason是否表示达到了token限制 */ static isMaxTokensStopReason(stopReason: string): boolean; /** * 智能处理max tokens错误 - 主入口 * @param response API响应对象 * @param provider 提供商名称 * @param model 模型名称 * @param requestId 请求ID * @param originalRequest 原始请求(用于智能处理) * @returns 处理后的请求或抛出错误 */ handleMaxTokensResponse(response: any, provider: string, model: string, requestId: string, originalRequest?: BaseRequest): Promise<{ shouldRetry: boolean; truncatedRequest?: BaseRequest; error?: EnhancedMaxTokensError; }>; /** * 检测max tokens条件 */ private detectMaxTokensCondition; /** * 提取finish reason */ private extractFinishReason; /** * 创建增强版max tokens错误 */ private createEnhancedMaxTokensError; /** * 兼容性方法 - 检查响应并抛出错误(向后兼容) */ static checkAndThrowMaxTokensError(response: any, provider: string, model: string, requestId: string): void; /** * 格式化错误响应 */ static formatErrorResponse(error: EnhancedMaxTokensError): any; /** * 获取处理模块配置 */ getHandlingConfig(): import("./max-tokens-error-handling-module").MaxTokensHandlingConfig; /** * 更新处理模块配置 */ updateHandlingConfig(updates: any): void; } export default EnhancedMaxTokensErrorHandler; //# sourceMappingURL=enhanced-max-tokens-error-handler.d.ts.map