import { normalizeReasoningInResponsesPayload } from '../../shared/reasoning-normalizer.js';
import { parseReqInboundFormatEnvelopeWithNative, parseRespInboundFormatEnvelopeWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
export class ResponsesFormatAdapter {
    protocol = 'openai-responses';
    async parseRequest(original, _ctx) {
        const parsed = parseReqInboundFormatEnvelopeWithNative({
            rawRequest: original,
            protocol: this.protocol
        });
        const payload = parsed.payload;
        normalizeReasoningInResponsesPayload(payload, {
            includeInput: true,
            includeInstructions: true
        });
        return {
            protocol: this.protocol,
            direction: 'request',
            payload
        };
    }
    async buildRequest(format, _ctx) {
        return format.payload;
    }
    async parseResponse(original, _ctx) {
        const parsed = parseRespInboundFormatEnvelopeWithNative({
            payload: original,
            protocol: this.protocol
        });
        const payload = parsed.payload;
        normalizeReasoningInResponsesPayload(payload, {
            includeOutput: true,
            includeRequiredAction: true
        });
        return {
            protocol: this.protocol,
            direction: 'response',
            payload
        };
    }
    async buildResponse(format, _ctx) {
        return format.payload;
    }
}
