import { defaultSseCodecRegistry } from '../../../../../../sse/index.js';
import { recordStage } from '../../../stages/utils.js';
import { resolveSseStreamModeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
export async function runRespOutboundStage2SseStream(options) {
    const shouldStream = resolveSseStreamModeWithNative(options.wantsStream, options.clientProtocol);
    if (!shouldStream) {
        recordStage(options.stageRecorder, 'chat_process.resp.stage10.sse_stream', {
            passthrough: false,
            protocol: options.clientProtocol,
            payload: options.clientPayload
        });
        return { body: options.clientPayload };
    }
    const codec = defaultSseCodecRegistry.get(options.clientProtocol);
    const stream = await codec.convertJsonToSse(options.clientPayload, {
        requestId: options.requestId
    });
    recordStage(options.stageRecorder, 'chat_process.resp.stage10.sse_stream', {
        passthrough: false,
        protocol: options.clientProtocol,
        payload: options.clientPayload
    });
    return { stream };
}
