/** * repair — Tool-call repair pipeline for DeepSeek. * * Harvested from reasonix Pillar 2 (Tool-Call Repair). * * DeepSeek has known failure modes: * 1. Tool-call JSON emitted inside `` blocks, missing from tool_calls * 2. Arguments dropped when schema has >10 params or deeply nested objects * 3. Same tool called repeatedly with identical args (call-storm) * 4. Truncated JSON due to max_tokens hit mid-structure * * This module provides four passes to address each one. */ import type { ToolCallRepairInput } from "./types.js"; /** Detect whether a schema would benefit from flattening. */ export declare function needsFlattening(paramNames: string[], depth: number): boolean; /** * Flatten a deep parameter name by joining with dots. * E.g. `style.color` instead of `style: { color: "red" }`. */ export declare function flattenParamName(path: string[]): string; /** * Estimate whether tool-call arguments JSON is truncated. * Checks by attempting to parse and looking for unbalanced braces/brackets. */ export declare function isTruncatedJSON(text: string): boolean; /** * Attempt to repair truncated JSON by closing open braces/brackets. */ export declare function repairTruncatedJSON(text: string): { repaired: string; fixed: boolean; }; /** * Scavenge tool calls that DeepSeek "leaked" into reasoning_content or * message content (outside the tool_calls array). */ export declare function scavengeToolCalls(content: string | null | undefined): ToolCallRepairInput[]; /** * Detect call-storms: same (tool, args) tuple within a sliding window. * Returns the number of storms detected (the excess calls to suppress). */ export declare function detectCallStorm(calls: ToolCallRepairInput[], windowSize?: number): { clean: ToolCallRepairInput[]; stormCount: number; }; export interface RepairOptions { /** Max params before schema flattening triggers (default: 10). */ maxParams?: number; /** Max nesting depth before flattening triggers (default: 2). */ maxDepth?: number; /** Sliding window for call-storm detection (default: 5). */ stormWindow?: number; } export interface RepairResult { repaired: ToolCallRepairInput[]; scavenged: ToolCallRepairInput[]; stormCount: number; truncatedFixed: number; } /** * Full repair pipeline for a set of tool calls. * * 1. Scavenge — recover tool calls leaked into reasoning_content * 2. Repair truncated JSON in arguments * 3. Detect and break call-storms * * Schema flattening is handled at tool registration time (not runtime). */ export declare function repairToolCalls(calls: ToolCallRepairInput[], reasoningContent?: string | null, options?: RepairOptions): RepairResult;