route-claudecode
Version:
Advanced routing and transformation system for Claude Code outputs to multiple AI providers
107 lines • 3.09 kB
TypeScript
/**
* 工具调用解析失败日志记录器
* 将工具调用解析失败的详细信息记录到数据库
* Project Owner: Jason Zhang
*/
export interface ToolParsingFailure {
timestamp: string;
requestId: string;
provider: string;
model: string;
endpoint: string;
failureType: 'parsing_error' | 'format_mismatch' | 'missing_tool_calls' | 'invalid_json' | 'text_instead_of_tools';
originalResponse: any;
expectedFormat: 'openai' | 'anthropic' | 'custom';
errorMessage: string;
responseAnalysis: {
hasToolCalls: boolean;
hasContent: boolean;
contentLength: number;
contentPreview: string;
finishReason: string;
toolCallPatterns?: string[];
};
debugInfo: {
requestTools: any[];
responseStructure: any;
parsingAttempts: string[];
};
}
export declare class ToolParsingFailureLogger {
private dbPath;
private failures;
private maxRecords;
constructor(dbPath?: string);
/**
* 记录工具调用解析失败
*/
logFailure(requestId: string, provider: string, model: string, endpoint: string, originalResponse: any, errorDetails: {
failureType: ToolParsingFailure['failureType'];
errorMessage: string;
expectedFormat: ToolParsingFailure['expectedFormat'];
requestTools?: any[];
parsingAttempts?: string[];
}): Promise<void>;
/**
* 分析响应内容
*/
private analyzeResponse;
/**
* 检测文本内容中的工具调用模式
*/
private detectToolCallPatterns;
/**
* 分析响应结构
*/
private analyzeStructure;
/**
* 清理响应内容(移除敏感信息)
*/
private sanitizeResponse;
/**
* 加载现有的失败记录
*/
private loadExistingFailures;
/**
* 安全的日志记录 - 如果logger未初始化则降级使用console
*/
private safeLog;
/**
* 保存失败记录到文件
*/
private saveFailures;
/**
* 获取失败统计信息
*/
getStats(): {
totalFailures: number;
recentFailures: number;
failuresByType: Record<string, number>;
failuresByProvider: Record<string, number>;
topFailedModels: Array<{
model: string;
count: number;
}>;
};
/**
* 获取特定provider的失败记录
*/
getFailuresForProvider(provider: string, limit?: number): ToolParsingFailure[];
/**
* 获取最近的失败记录
*/
getRecentFailures(hours?: number, limit?: number): ToolParsingFailure[];
/**
* 清理旧记录
*/
cleanup(olderThanDays?: number): void;
}
/**
* 获取全局单例实例 - 延迟初始化避免过早调用logger
*/
export declare function getToolParsingFailureLogger(): ToolParsingFailureLogger;
export declare const toolParsingFailureLogger: {
readonly instance: ToolParsingFailureLogger;
};
export default ToolParsingFailureLogger;
//# sourceMappingURL=tool-parsing-failure-logger.d.ts.map