NODEDC_1C/llm_normalizer/backend/src/services/assistantDeepTurnInputBuild...

127 lines
4.9 KiB
TypeScript

import type {
AssistantAddressRuntimeMetaForDeep,
AssistantDebugRouteRecord,
AssistantExecutionStateRecord,
AssistantFallbackType,
AssistantProblemAnswerMode,
AssistantReplyType,
AssistantRequirement,
AnswerGroundingCheck,
FaLiveRouteAuditDebug,
RbpLiveRouteAuditDebug,
RequirementCoverageReport,
UnifiedRetrievalResult
} from "../types/assistant";
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
import type { AnswerStructureV11 } from "../types/stage1Contracts";
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
import type { AssistantDeepTurnPackagingInput } from "./assistantDeepTurnPackaging";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
import type { ClaimBoundAnchorAudit, TargetedEvidenceAcquisitionAudit } from "./assistantClaimBoundEvidence";
import type { CompanyAnchorSet } from "./companyAnchorResolver";
import type {
DomainPolarityGuardAudit,
EvidenceAdmissibilityAudit,
GroundedAnswerEligibilityAudit,
TemporalGuardAudit
} from "./assistantRuntimeGuards";
import type {
AssistantRetrievalCallRecord,
AssistantRetrievalRawResultRecord
} from "./assistantDeepTurnRetrievalRuntimeAdapter";
export interface AssistantDeepTurnInputBuilderArgs {
sessionId: string;
messageId: string;
userMessage: string;
normalized: {
trace_id: string;
prompt_version: string;
schema_version: string;
normalized: NormalizeResponsePayload["normalized"];
};
normalizedQuestion: string;
routeSummary: RouteHintSummary | null;
droppedIntentSegments: string[];
analysisContextForContract: {
as_of_date: string | null;
period_from: string | null;
period_to: string | null;
source: string | null;
snapshot_mode: "auto" | "force_snapshot" | "force_live";
} | null;
executionPlan: Array<{
fragment_id: string;
requirement_ids: string[];
route: string;
should_execute: boolean;
no_route_reason?: string | null;
clarification_reason?: string | null;
}>;
requirementExtractionRequirements: AssistantRequirement[];
coverageEvaluationRequirements: AssistantRequirement[];
coverageReport: RequirementCoverageReport;
groundingCheck: AnswerGroundingCheck;
retrievalCalls: AssistantRetrievalCallRecord[];
retrievalResultsRaw: AssistantRetrievalRawResultRecord[];
retrievalResults: UnifiedRetrievalResult[];
routesForDebug: AssistantDebugRouteRecord[];
resolvedExecutionState: AssistantExecutionStateRecord[];
questionTypeClass: string;
companyAnchors: CompanyAnchorSet | null;
runtimeAnalysisContext: {
active: boolean;
as_of_date: string | null;
period_from: string | null;
period_to: string | null;
source: string | null;
snapshot_mode: "auto" | "force_snapshot" | "force_live";
};
businessScopeResolution: {
business_scope_raw?: string[];
business_scope_resolved?: string[];
company_grounding_applied?: boolean;
scope_resolution_reason?: string[];
};
temporalGuard: TemporalGuardAudit;
polarityAudit: DomainPolarityGuardAudit;
claimAnchorAudit: ClaimBoundAnchorAudit;
targetedEvidenceAudit: TargetedEvidenceAcquisitionAudit;
evidenceAdmissibilityGateAudit: EvidenceAdmissibilityAudit;
rbpLiveRouteAudit: RbpLiveRouteAuditDebug | null;
faLiveRouteAudit: FaLiveRouteAuditDebug | null;
groundedAnswerEligibilityGuard: GroundedAnswerEligibilityAudit;
followupStateUsage?: AssistantFollowupUsage | null;
composition: {
reply_type: AssistantReplyType;
fallback_type: AssistantFallbackType;
answer_structure_v11?: AnswerStructureV11 | null;
problem_centric_answer_applied?: boolean;
problem_units_used_count?: number;
problem_answer_mode?: AssistantProblemAnswerMode;
problem_unit_ids_used?: string[];
};
safeAssistantReplyBase: string;
featureContractsV11: boolean;
featureAnswerPolicyV11: boolean;
investigationStateSnapshot: InvestigationStateWithProblemUnits | null;
addressRuntimeMetaForDeep: AssistantAddressRuntimeMetaForDeep | null | undefined;
}
export function buildAssistantDeepTurnPackagingInput(args: AssistantDeepTurnInputBuilderArgs): AssistantDeepTurnPackagingInput {
return {
...args,
routesForDebug: Array.isArray(args.routesForDebug) ? args.routesForDebug : [],
followupStateUsage: args.followupStateUsage ?? null,
composition: {
reply_type: args.composition.reply_type,
fallback_type: args.composition.fallback_type,
answer_structure_v11: args.composition.answer_structure_v11 ?? null,
problem_centric_answer_applied: args.composition.problem_centric_answer_applied ?? false,
problem_units_used_count: args.composition.problem_units_used_count ?? 0,
problem_answer_mode: args.composition.problem_answer_mode ?? "stage1_policy_v11",
problem_unit_ids_used: Array.isArray(args.composition.problem_unit_ids_used) ? args.composition.problem_unit_ids_used : []
}
};
}