export const normalizeToolArguments = (args) => {
    if (args === undefined || args === null) {
        return { text: '' };
    }
    if (typeof args === 'string') {
        const trimmed = args.trim();
        if (trimmed.length === 0) {
            return { text: '' };
        }
        try {
            const parsed = JSON.parse(trimmed);
            return { text: trimmed, value: parsed };
        }
        catch {
            return { text: trimmed };
        }
    }
    if (typeof args === 'number' || typeof args === 'boolean') {
        return { text: JSON.stringify(args), value: args };
    }
    if (typeof args === 'object') {
        try {
            const serialized = JSON.stringify(args);
            return {
                text: serialized,
                value: args
            };
        }
        catch (error) {
            console.warn('Failed to stringify tool call arguments', { args, error });
            return { text: '' };
        }
    }
    return { text: '' };
};
export const resolveToolCallArgumentsForOllama = (call) => {
    if (call.parsedArguments !== undefined) {
        return call.parsedArguments;
    }
    if (call.arguments && call.arguments.length > 0) {
        try {
            return JSON.parse(call.arguments);
        }
        catch (error) {
            console.warn('Failed to parse tool call arguments for Ollama request', {
                callId: call.callId,
                toolName: call.toolName,
                error
            });
        }
    }
    return {};
};
