import { captureResponsesRequestContext } from '../../../../../shared/responses-conversation-store.js';
import { captureReqInboundResponsesContextSnapshotWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
export function captureResponsesContextSnapshot(options) {
    const context = captureReqInboundResponsesContextSnapshotWithNative({
        rawRequest: options.rawRequest,
        requestId: options.adapterContext.requestId,
        toolCallIdStyle: options.adapterContext.toolCallIdStyle
    });
    // OpenAI Responses tool loop: store the request context keyed by requestId so that
    // `/v1/responses/:id/submit_tool_outputs` can resume the conversation later.
    //
    // This must be done on the hub pipeline inbound path (not in host/provider), because:
    // - the tool loop is a client-protocol behavior (/v1/responses), independent of providerProtocol;
    // - providers must remain transport-only;
    // - the host may later enhance requestId with providerKey/model for logging, which is handled via rebind.
    const requestId = typeof options.adapterContext.requestId === 'string' && options.adapterContext.requestId.trim().length
        ? options.adapterContext.requestId
        : undefined;
    if (requestId) {
        // captureResponsesRequestContext already best-effort wraps store failures.
        captureResponsesRequestContext({
            requestId,
            payload: options.rawRequest,
            context: context
        });
    }
    return context;
}
