"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildAssistantAddressOrchestrationRuntime = buildAssistantAddressOrchestrationRuntime; function fallbackAddressPreDecompose(userMessage, llmProvider, buildAddressLlmPredecomposeContractV1, sanitizeAddressMessageForFallback) { const provider = llmProvider === "local" ? "local" : llmProvider === "openai" ? "openai" : null; return { attempted: false, applied: false, provider, traceId: null, effectiveMessage: userMessage, reason: "disabled_by_feature_flag", llmCanonicalCandidateDetected: false, predecomposeContract: buildAddressLlmPredecomposeContractV1({ sourceMessage: userMessage, canonicalMessage: userMessage }), fallbackRuleHit: null, sanitizedUserMessage: sanitizeAddressMessageForFallback(userMessage), toolGateDecision: null, toolGateReason: null }; } async function buildAssistantAddressOrchestrationRuntime(input) { const addressPreDecompose = input.featureAddressLlmPredecomposeV1 ? await input.runAddressLlmPreDecompose() : fallbackAddressPreDecompose(input.userMessage, input.llmProvider, input.buildAddressLlmPredecomposeContractV1, input.sanitizeAddressMessageForFallback); const addressInputMessage = input.toNonEmptyString(addressPreDecompose?.effectiveMessage) ?? input.userMessage; const carryover = input.resolveAddressFollowupCarryoverContext(input.userMessage, input.sessionItems, addressInputMessage, addressPreDecompose); const followupContext = carryover?.followupContext ?? null; const orchestrationDecision = input.resolveAssistantOrchestrationDecision({ rawUserMessage: input.userMessage, effectiveAddressUserMessage: addressInputMessage, followupContext, llmPreDecomposeMeta: addressPreDecompose, useMock: input.useMock }); const dialogContinuationContract = input.buildAddressDialogContinuationContractV2(input.userMessage, addressInputMessage, carryover, addressPreDecompose); const addressRuntimeMeta = { ...addressPreDecompose, toolGateDecision: orchestrationDecision.toolGateDecision ?? null, toolGateReason: orchestrationDecision.toolGateReason ?? null, dialogContinuationContract, orchestrationContract: orchestrationDecision.orchestrationContract ?? null }; const livingModeDecision = { mode: orchestrationDecision.livingMode, reason: orchestrationDecision.livingReason }; return { addressPreDecompose, addressInputMessage, carryover, orchestrationDecision, addressRuntimeMeta, livingModeDecision }; }