import { buildAnthropicResponseFromChat } from '../../../../response/response-runtime.js';
import { normalizeResponsesToolCallIds } from '../../../../../shared/responses-tool-utils.js';
import { applyClientPassthroughPatchWithNative, buildResponsesPayloadFromChatWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
import { resolveAliasMapFromSemantics, resolveClientToolsRawFromSemantics } from './chat-process-semantics-bridge.js';
export function buildClientPayloadForProtocol(options) {
    let clientPayload;
    if (options.clientProtocol === 'openai-chat') {
        clientPayload = options.payload;
    }
    else if (options.clientProtocol === 'anthropic-messages') {
        clientPayload = buildAnthropicResponseFromChat(options.payload, {
            aliasMap: resolveAliasMapFromSemantics(options.requestSemantics)
        });
    }
    else {
        const toolsRaw = resolveClientToolsRawFromSemantics(options.requestSemantics);
        clientPayload = buildResponsesPayloadFromChatWithNative(options.payload, {
            requestId: options.requestId,
            ...(toolsRaw ? { toolsRaw } : {})
        });
    }
    const patchedPayload = applyClientPassthroughPatchWithNative(clientPayload, options.payload);
    Object.assign(clientPayload, patchedPayload);
    if (options.clientProtocol === 'openai-responses') {
        normalizeResponsesToolCallIds(clientPayload);
    }
    return clientPayload;
}
