import { removeMarkdownCodeFenceBlocks } from "@best-agent/foundation";
export function decodeTextualToolCall(text) {
    const stripped = removeMarkdownCodeFenceBlocks(text);
    const toolMatch = stripped.match(/<tool_call(?:\s[^>]*)?>\s*([A-Za-z0-9_:-]+)/u);
    if (!toolMatch?.[1]) {
        return undefined;
    }
    const pairs = [
        ...stripped.matchAll(/<arg_key>([\s\S]*?)<\/arg_key>\s*<arg_value>([\s\S]*?)<\/arg_value>/gu),
    ];
    if (pairs.length === 0) {
        return undefined;
    }
    const toolInput = {};
    for (const pair of pairs) {
        const key = pair[1]?.trim();
        if (!key) {
            continue;
        }
        toolInput[key] = pair[2]?.trim() ?? "";
    }
    return {
        input: toolInput,
        toolName: toolMatch[1],
    };
}
//# sourceMappingURL=provider-direct-response-policy.js.map