route-claudecode
Version:
Advanced routing and transformation system for Claude Code outputs to multiple AI providers
137 lines • 3.29 kB
TypeScript
/**
* 统一工具调用检测器
* 对所有OpenAI兼容输入执行监测,确保滑动窗口检测覆盖所有样本
*/
export interface DetectionContext {
provider: string;
model: string;
isStreaming: boolean;
requestId: string;
}
export interface DetectionResult {
hasToolCalls: boolean;
extractedToolCalls: any[];
cleanedText: string[];
detectionMethod: string;
confidence: number;
}
export interface SlidingWindowConfig {
windowSize: number;
overlapSize: number;
minDetectionLength: number;
}
/**
* 滑动窗口工具调用检测器
*/
export declare class SlidingWindowDetector {
private windowConfig;
private logger;
constructor(config?: Partial<SlidingWindowConfig>, port?: number);
/**
* 对文本进行滑动窗口检测
*/
detectInText(text: string, context: DetectionContext): DetectionResult;
/**
* 创建滑动窗口
*/
private createSlidingWindows;
/**
* 在单个窗口中检测工具调用
*/
private detectInWindow;
/**
* 检测JSON格式的工具调用
*/
private detectJSONToolCalls;
/**
* 检测文本格式的工具调用
*/
private detectTextToolCalls;
/**
* 检测直接函数调用格式
*/
private detectDirectToolCalls;
/**
* 检测特定模型的格式
*/
private detectModelSpecificFormats;
/**
* GLM模型格式检测
*/
private detectGLMFormat;
/**
* Qwen模型格式检测
*/
private detectQwenFormat;
/**
* DeepSeek模型格式检测
*/
private detectDeepSeekFormat;
/**
* 验证是否是有效的工具调用
*/
private isValidToolCall;
/**
* 判断函数名是否可能是工具函数
*/
private isLikelyToolFunction;
/**
* 提取清理后的文本
*/
private extractCleanedText;
/**
* 计算检测置信度
*/
private calculateConfidence;
/**
* 🔧 改进的工具调用JSON解析
* 处理大文本中的控制字符和转义问题
*/
private parseToolCallJSON;
/**
* 清理JSON字符串中的控制字符
*/
private cleanJSONString;
}
/**
* 统一工具调用检测器
*/
export declare class UnifiedToolCallDetector {
private slidingWindowDetector;
private logger;
constructor(port?: number);
/**
* 检测并处理工具调用
* 对所有OpenAI兼容输入都执行监测,避免准入条件太严格
*/
detectAndProcess(data: any, context: DetectionContext): Promise<any>;
/**
* 检查是否有文本内容
*/
private hasTextContent;
/**
* 处理文本内容
*/
private processTextContent;
/**
* 计算内容块数量
*/
private countContentBlocks;
/**
* 🔧 改进的工具调用JSON解析
* 处理大文本中的控制字符和转义问题
*/
private parseToolCallJSON;
/**
* 清理JSON字符串中的控制字符
*/
private cleanJSONString;
/**
* 获取检测统计信息
*/
getStats(): {
windowConfig: SlidingWindowConfig;
detectionMethods: string[];
};
}
//# sourceMappingURL=unified-tool-call-detector.d.ts.map