"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildAssistantDeepTurnNormalizationRuntime = buildAssistantDeepTurnNormalizationRuntime; const routeHintAdapter_1 = require("./routeHintAdapter"); function resolveDeepTurnNormalizerPromptVersion(promptVersion) { const normalized = String(promptVersion ?? "").trim().toLowerCase(); if (normalized === "normalizer_v2_0_2" || normalized === "normalizer_v2_0_1" || normalized === "normalizer_v2" || normalized === "normalizer_v1") { return String(promptVersion); } return "normalizer_v2_0_2"; } function canSynthesizeRouteSummary(normalized) { if (!normalized || typeof normalized !== "object") { return false; } const source = normalized; return Array.isArray(source.fragments); } async function buildAssistantDeepTurnNormalizationRuntime(input) { const investigationState = input.sessionInvestigationState; const canUseFollowupBinding = input.featureInvestigationStateV1 && input.featureStateFollowupBindingV1 && investigationState !== null && investigationState !== undefined; const followupBinding = canUseFollowupBinding ? input.buildFollowupStateBinding({ userMessage: input.userMessage, payloadContext: input.payload.context, investigationState }) : { normalizedQuestion: input.userMessage, mergedContext: input.payload.context, usage: null }; const normalizePayload = { llmProvider: input.payload.llmProvider, apiKey: input.payload.apiKey, model: input.payload.model, baseUrl: input.payload.baseUrl, temperature: input.payload.temperature, maxOutputTokens: input.payload.maxOutputTokens, promptVersion: resolveDeepTurnNormalizerPromptVersion(input.payload.promptVersion), schemaVersion: "v2_0_2", systemPrompt: input.payload.systemPrompt, developerPrompt: input.payload.developerPrompt, domainPrompt: input.payload.domainPrompt, fewShotExamples: input.payload.fewShotExamples, userQuestion: followupBinding.normalizedQuestion, context: followupBinding.mergedContext, useMock: Boolean(input.payload.useMock) }; const normalized = await input.normalize(normalizePayload); const normalizedPayload = normalized.normalized; const synthesizedRouteSummary = normalized.route_hint_summary ?? (normalizedPayload && canSynthesizeRouteSummary(normalizedPayload) ? (0, routeHintAdapter_1.toRouteHintSummary)(normalizedPayload) : null); const normalizedWithRouteSummary = synthesizedRouteSummary === normalized.route_hint_summary ? normalized : { ...normalized, route_hint_summary: synthesizedRouteSummary }; return { followupBinding, normalizePayload, normalized: normalizedWithRouteSummary }; }