/**
 * Tool choice policy:
 * - If tools exist and no tool_choice, set tool_choice='auto'
 * - If no tools, remove tool_choice
 */
export class RequestToolChoicePolicyFilter {
    name = 'request_tool_choice_policy';
    stage = 'request_post';
    apply(input) {
        try {
            const out = JSON.parse(JSON.stringify(input || {}));
            const tools = Array.isArray(out.tools) ? out.tools : [];
            if (tools.length > 0) {
                const hasOwn = Object.prototype.hasOwnProperty.call(out, 'tool_choice');
                if (!hasOwn || out.tool_choice === undefined) {
                    out.tool_choice = 'auto';
                }
            }
            else {
                if (Object.prototype.hasOwnProperty.call(out, 'tool_choice'))
                    delete out.tool_choice;
            }
            return { ok: true, data: out };
        }
        catch {
            return { ok: true, data: input };
        }
    }
}
