import { normalizeReasoningInChatPayload } from '../../shared/reasoning-normalizer.js';
import { parseReqInboundFormatEnvelopeWithNative, parseRespInboundFormatEnvelopeWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
export class ChatFormatAdapter {
    protocol = 'openai-chat';
    async parseRequest(original, _ctx) {
        const parsed = parseReqInboundFormatEnvelopeWithNative({
            rawRequest: original,
            protocol: this.protocol
        });
        const payload = parsed.payload;
        normalizeReasoningInChatPayload(payload);
        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;
        normalizeReasoningInChatPayload(payload);
        return {
            protocol: this.protocol,
            direction: 'response',
            payload
        };
    }
    async buildResponse(format, _ctx) {
        return format.payload;
    }
}
