NODEDC_1C/llm_normalizer/backend/dist/services/assistantDeepTurnResponseRu...

137 lines
6.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAssistantDeepTurnResponseRuntime = runAssistantDeepTurnResponseRuntime;
const assistantDeepTurnPackagingRuntimeAdapter_1 = require("./assistantDeepTurnPackagingRuntimeAdapter");
const assistantDeepTurnFinalizeRuntimeAdapter_1 = require("./assistantDeepTurnFinalizeRuntimeAdapter");
function toNullableString(value) {
if (typeof value !== "string") {
return null;
}
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : null;
}
function toStringArray(value) {
if (!Array.isArray(value)) {
return [];
}
return value
.map((item) => (typeof item === "string" ? item.trim() : ""))
.filter((item) => item.length > 0);
}
function toSnapshotMode(value) {
return value === "force_snapshot" || value === "force_live" ? value : "auto";
}
function normalizeExecutionPlan(value) {
if (!Array.isArray(value)) {
return [];
}
return value.map((item, index) => ({
fragment_id: toNullableString(item.fragment_id) ?? `fragment_${index + 1}`,
requirement_ids: toStringArray(item.requirement_ids),
route: toNullableString(item.route) ?? "unknown_route",
should_execute: Boolean(item.should_execute),
no_route_reason: toNullableString(item.no_route_reason ?? null),
clarification_reason: toNullableString(item.clarification_reason ?? null)
}));
}
function normalizeRuntimeAnalysisContext(value) {
const source = value;
return {
active: Boolean(source?.active),
as_of_date: toNullableString(source?.as_of_date),
period_from: toNullableString(source?.period_from),
period_to: toNullableString(source?.period_to),
source: toNullableString(source?.source),
snapshot_mode: toSnapshotMode(source?.snapshot_mode)
};
}
function normalizeBusinessScopeResolution(value) {
const source = value;
return {
business_scope_raw: toStringArray(source?.business_scope_raw),
business_scope_resolved: toStringArray(source?.business_scope_resolved),
company_grounding_applied: Boolean(source?.company_grounding_applied),
scope_resolution_reason: toStringArray(source?.scope_resolution_reason)
};
}
function normalizeAddressRuntimeMetaForDeep(value) {
const source = value;
if (!source) {
return null;
}
return {
attempted: typeof source.attempted === "boolean" ? source.attempted : undefined,
applied: typeof source.applied === "boolean" ? source.applied : undefined,
reason: toNullableString(source.reason),
provider: toNullableString(source.provider),
fallbackRuleHit: toNullableString(source.fallbackRuleHit),
toolGateDecision: toNullableString(source.toolGateDecision),
toolGateReason: toNullableString(source.toolGateReason),
predecomposeContract: source.predecomposeContract ?? null,
orchestrationContract: source.orchestrationContract ?? null
};
}
function runAssistantDeepTurnResponseRuntime(input) {
const runPackagingRuntimeSafe = input.runPackagingRuntime ?? assistantDeepTurnPackagingRuntimeAdapter_1.runAssistantDeepTurnPackagingRuntime;
const runFinalizeDeepTurnSafe = input.runFinalizeDeepTurn ?? assistantDeepTurnFinalizeRuntimeAdapter_1.finalizeAssistantDeepTurn;
const packagingRuntime = runPackagingRuntimeSafe({
featureInvestigationStateV1: input.featureInvestigationStateV1,
sessionId: input.sessionId,
questionId: input.questionId,
userMessage: input.userMessage,
normalized: input.normalized,
normalizedQuestion: input.normalizedQuestion,
routeSummary: input.routeSummary,
executionPlan: normalizeExecutionPlan(input.executionPlan),
requirementExtractionRequirements: input.requirementExtractionRequirements,
coverageEvaluationRequirements: input.coverageEvaluationRequirements,
coverageReport: input.coverageReport,
groundingCheck: input.groundingCheck,
retrievalCalls: input.retrievalCalls,
retrievalResultsRaw: input.retrievalResultsRaw,
retrievalResults: input.retrievalResults,
questionTypeClass: input.questionTypeClass,
companyAnchors: input.companyAnchors,
runtimeAnalysisContext: normalizeRuntimeAnalysisContext(input.runtimeAnalysisContext),
businessScopeResolution: normalizeBusinessScopeResolution(input.businessScopeResolution),
temporalGuard: input.temporalGuard,
polarityAudit: input.polarityAudit,
claimAnchorAudit: input.claimAnchorAudit,
targetedEvidenceAudit: input.targetedEvidenceAudit,
evidenceAdmissibilityGateAudit: input.evidenceAdmissibilityGateAudit,
rbpLiveRouteAudit: input.rbpLiveRouteAudit ?? null,
faLiveRouteAudit: input.faLiveRouteAudit ?? null,
groundedAnswerEligibilityGuard: input.groundedAnswerEligibilityGuard,
followupStateUsage: input.followupStateUsage,
followupApplied: input.followupApplied,
composition: input.composition,
featureContractsV11: input.featureContractsV11,
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
previousInvestigationState: input.previousInvestigationState ?? null,
addressRuntimeMetaForDeep: normalizeAddressRuntimeMetaForDeep(input.addressRuntimeMetaForDeep),
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
buildDebugRoutes: input.buildDebugRoutes,
extractExecutionState: input.extractExecutionState,
sanitizeReply: input.sanitizeReply,
persistInvestigationState: input.persistInvestigationState,
messageIdFactory: input.messageIdFactory
});
const finalization = runFinalizeDeepTurnSafe({
sessionId: input.sessionId,
assistantReply: packagingRuntime.safeAssistantReply,
replyType: input.composition.reply_type,
assistantItem: packagingRuntime.assistantItem,
debug: packagingRuntime.debug,
deepAnalysisLogDetails: packagingRuntime.deepAnalysisLogDetails,
appendItem: input.appendItem,
getSession: input.getSession,
persistSession: input.persistSession,
cloneConversation: input.cloneConversation,
logEvent: input.logEvent
});
return {
response: finalization.response,
debug: packagingRuntime.debug
};
}