/**
 * Shared utilities for sanitizing OpenAI/Synthetic request parameters
 * before sending them over the wire. CLI "ephemeral" settings often
 * contain UX toggles (context limits, shell replacement, etc.) that
 * must never be forwarded to the API.
 */
const OPENAI_ALLOWED_PARAM_KEYS = new Set([
    'temperature',
    'top_p',
    'frequency_penalty',
    'presence_penalty',
    'stop',
    'max_tokens',
    'max_completion_tokens',
    'max_output_tokens',
    'logit_bias',
    'user',
    'n',
    'seed',
    'response_format',
    'stream',
    'stream_options',
    'tool_choice',
    'metadata',
    'modalities',
    'parallel_tool_calls',
    'top_k',
    'top_logprobs',
    'logprobs',
    'reasoning',
    'audio',
    'audio_format',
    'prediction',
]);
const OPENAI_PARAM_KEY_ALIASES = {
    'max-tokens': 'max_tokens',
    maxTokens: 'max_tokens',
    'response-format': 'response_format',
    responseFormat: 'response_format',
    'tool-choice': 'tool_choice',
    toolChoice: 'tool_choice',
};
function normalizeOpenAIParamKey(key) {
    if (OPENAI_PARAM_KEY_ALIASES[key]) {
        return OPENAI_PARAM_KEY_ALIASES[key];
    }
    return key.replace(/-/g, '_');
}
const OPENAI_REASONING_INTERNAL_KEYS = new Set([
    'enabled',
    'includeInContext',
    'includeInResponse',
    'format',
    'stripFromContext',
]);
function stripInternalReasoningKeys(value) {
    if (!value || typeof value !== 'object' || Array.isArray(value)) {
        return undefined;
    }
    const sanitized = {};
    for (const [key, nestedValue] of Object.entries(value)) {
        if (nestedValue === undefined ||
            nestedValue === null ||
            OPENAI_REASONING_INTERNAL_KEYS.has(key)) {
            continue;
        }
        sanitized[key] = nestedValue;
    }
    return Object.keys(sanitized).length > 0 ? sanitized : undefined;
}
export function filterOpenAIRequestParams(source) {
    if (!source) {
        return undefined;
    }
    const filtered = {};
    for (const [rawKey, value] of Object.entries(source)) {
        if (value === undefined || value === null) {
            continue;
        }
        const normalizedKey = normalizeOpenAIParamKey(rawKey);
        if (!OPENAI_ALLOWED_PARAM_KEYS.has(normalizedKey)) {
            continue;
        }
        if (normalizedKey === 'reasoning') {
            const sanitized = stripInternalReasoningKeys(value);
            if (!sanitized) {
                continue;
            }
            filtered[normalizedKey] = sanitized;
            continue;
        }
        filtered[normalizedKey] = value;
    }
    return Object.keys(filtered).length > 0 ? filtered : undefined;
}
//# sourceMappingURL=openaiRequestParams.js.map