ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.562.60 Deep-turn attempt input builder \ Deep-turn analysis-attempt input builder \ Deep-turn response-runtime input builder:
This commit is contained in:
parent
c849eb5f5b
commit
6c9b94ef34
|
|
@ -1689,7 +1689,69 @@ Validation:
|
|||
- `assistantWave10SettlementCorrectiveRegression.test.ts`
|
||||
- `assistantLivingChatMode.test.ts`
|
||||
|
||||
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 + 2.26 + 2.27 + 2.28 + 2.29 + 2.30 + 2.31 + 2.32 + 2.33 + 2.34 + 2.35 + 2.36 + 2.37 + 2.38 + 2.39 + 2.40 + 2.41 + 2.42 + 2.43 + 2.44 + 2.45 + 2.46 + 2.47 + 2.48 + 2.49 + 2.50 + 2.51 + 2.52 + 2.53 + 2.54 + 2.55 completed)**
|
||||
Implemented in current pass (Phase 2.56 + 2.57 + 2.58 + 2.59 + 2.60):
|
||||
1. Extracted deep-turn attempt input assembly into dedicated builder:
|
||||
- `assistantDeepTurnAttemptInputBuilder.ts`
|
||||
- introduced:
|
||||
- `buildAssistantDeepTurnNormalizationRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnAnalysisAttemptRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnResponseAttemptRuntimeInput(...)`
|
||||
2. Rewired `assistantDeepTurnAttemptRuntimeAdapter` to consume deep-turn attempt builder outputs (behavior-preserving):
|
||||
- removed inline normalization/analysis/response attempt payload mapping from adapter body.
|
||||
3. Extracted deep-turn response runtime input mapping into dedicated builder:
|
||||
- `assistantDeepTurnResponseRuntimeInputBuilder.ts`
|
||||
- introduced:
|
||||
- `buildAssistantDeepTurnResponseRuntimeInput(...)`
|
||||
4. Rewired `assistantDeepTurnResponseAttemptRuntimeAdapter` to consume response runtime input builder (behavior-preserving):
|
||||
- moved deep-analysis -> response-runtime field projection behind a single builder boundary.
|
||||
5. Extracted deep-turn analysis-attempt stage input wiring into dedicated builder:
|
||||
- `assistantDeepTurnAnalysisAttemptInputBuilder.ts`
|
||||
- introduced:
|
||||
- `buildAssistantDeepTurnAnalysisRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnContextRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnExecutionPlanRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnRetrievalRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnGuardRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnGroundingRuntimeInput(...)`
|
||||
- `buildAssistantDeepTurnCompositionRuntimeInput(...)`
|
||||
6. Rewired `assistantDeepTurnAnalysisAttemptRuntimeAdapter` to build `runAssistantDeepTurnAnalysisRuntime(...)` contract via builder (behavior-preserving).
|
||||
7. Added focused builder tests:
|
||||
- `assistantDeepTurnAttemptInputBuilder.test.ts`
|
||||
- `assistantDeepTurnResponseRuntimeInputBuilder.test.ts`
|
||||
- `assistantDeepTurnAnalysisAttemptInputBuilder.test.ts`
|
||||
|
||||
Validation:
|
||||
1. `npm run build` passed.
|
||||
2. Targeted living/address/deep followup pack passed:
|
||||
- `assistantDeepTurnAttemptInputBuilder.test.ts`
|
||||
- `assistantDeepTurnResponseRuntimeInputBuilder.test.ts`
|
||||
- `assistantDeepTurnAnalysisAttemptInputBuilder.test.ts`
|
||||
- `assistantDeepTurnAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantDeepTurnResponseAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantDeepTurnAnalysisAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantDeepTurnAnalysisRuntimeAdapter.test.ts`
|
||||
- `assistantDeepTurnResponseRuntimeAdapter.test.ts`
|
||||
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
|
||||
- `assistantAddressAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantLivingChatAttemptInputBuilder.test.ts`
|
||||
- `assistantAddressLaneAttemptInputBuilder.test.ts`
|
||||
- `assistantAddressLaneResponseAttemptInputBuilder.test.ts`
|
||||
- `assistantAddressRuntimeInputBuilder.test.ts`
|
||||
- `assistantTurnRuntimeInputBuilder.test.ts`
|
||||
- `assistantTurnAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantTurnRuntimeDepsAdapter.test.ts`
|
||||
- `assistantOrganizationScopeRuntimeAdapter.test.ts`
|
||||
- `assistantAddressLaneAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantAddressLaneResponseAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantAddressRuntimeAdapter.test.ts`
|
||||
- `assistantAddressLaneResponseRuntimeAdapter.test.ts`
|
||||
- `assistantLivingChatAttemptRuntimeAdapter.test.ts`
|
||||
- `assistantLivingChatHandlerRuntimeAdapter.test.ts`
|
||||
- `assistantLivingChatRuntimeAdapter.test.ts`
|
||||
- `assistantWave10SettlementCorrectiveRegression.test.ts`
|
||||
- `assistantLivingChatMode.test.ts`
|
||||
|
||||
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 + 2.26 + 2.27 + 2.28 + 2.29 + 2.30 + 2.31 + 2.32 + 2.33 + 2.34 + 2.35 + 2.36 + 2.37 + 2.38 + 2.39 + 2.40 + 2.41 + 2.42 + 2.43 + 2.44 + 2.45 + 2.46 + 2.47 + 2.48 + 2.49 + 2.50 + 2.51 + 2.52 + 2.53 + 2.54 + 2.55 + 2.56 + 2.57 + 2.58 + 2.59 + 2.60 completed)**
|
||||
|
||||
## Stage 3 (P2): Hybrid Semantic Layer (LLM + Deterministic Guards)
|
||||
|
||||
|
|
|
|||
116
llm_normalizer/backend/dist/services/assistantDeepTurnAnalysisAttemptInputBuilder.js
vendored
Normal file
116
llm_normalizer/backend/dist/services/assistantDeepTurnAnalysisAttemptInputBuilder.js
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAssistantDeepTurnContextRuntimeInput = buildAssistantDeepTurnContextRuntimeInput;
|
||||
exports.buildAssistantDeepTurnExecutionPlanRuntimeInput = buildAssistantDeepTurnExecutionPlanRuntimeInput;
|
||||
exports.buildAssistantDeepTurnRetrievalRuntimeInput = buildAssistantDeepTurnRetrievalRuntimeInput;
|
||||
exports.buildAssistantDeepTurnGuardRuntimeInput = buildAssistantDeepTurnGuardRuntimeInput;
|
||||
exports.buildAssistantDeepTurnGroundingRuntimeInput = buildAssistantDeepTurnGroundingRuntimeInput;
|
||||
exports.buildAssistantDeepTurnCompositionRuntimeInput = buildAssistantDeepTurnCompositionRuntimeInput;
|
||||
exports.buildAssistantDeepTurnAnalysisRuntimeInput = buildAssistantDeepTurnAnalysisRuntimeInput;
|
||||
const companyAnchorResolver_1 = require("./companyAnchorResolver");
|
||||
const assistantRuntimeGuards_1 = require("./assistantRuntimeGuards");
|
||||
const assistantClaimBoundEvidence_1 = require("./assistantClaimBoundEvidence");
|
||||
function buildAssistantDeepTurnContextRuntimeInput(input) {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
routeSummary: input.routeSummary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.followupUsage,
|
||||
resolveCompanyAnchors: companyAnchorResolver_1.resolveCompanyAnchors,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveTemporalGuard: assistantRuntimeGuards_1.resolveTemporalGuard,
|
||||
resolveDomainPolarityGuard: assistantRuntimeGuards_1.resolveDomainPolarityGuard,
|
||||
resolveClaimBoundAnchors: assistantClaimBoundEvidence_1.resolveClaimBoundAnchors,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnExecutionPlanRuntimeInput(input, runtime) {
|
||||
return {
|
||||
routeSummary: runtime.resolvedRouteSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
claimType: runtime.claimAnchorAudit.claim_type,
|
||||
temporalGuard: runtime.temporalGuard,
|
||||
domainPolarityGuardInitial: runtime.domainPolarityGuardInitial,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
applyTemporalHintToExecutionPlan: assistantRuntimeGuards_1.applyTemporalHintToExecutionPlan,
|
||||
applyPolarityHintToExecutionPlan: assistantRuntimeGuards_1.applyPolarityHintToExecutionPlan
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnRetrievalRuntimeInput(input, runtime) {
|
||||
return {
|
||||
executionPlan: runtime.executionPlan,
|
||||
liveTemporalHint: runtime.liveTemporalHint,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnGuardRuntimeInput(runtime) {
|
||||
return {
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
domainPolarityGuardInitial: runtime.domainPolarityGuardInitial,
|
||||
claimAnchorAudit: runtime.claimAnchorAudit,
|
||||
temporalGuard: runtime.temporalGuard,
|
||||
focusDomainForGuards: runtime.focusDomainForGuards,
|
||||
companyAnchors: runtime.companyAnchors,
|
||||
userMessage: runtime.userMessage
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnGroundingRuntimeInput(input, runtime) {
|
||||
return {
|
||||
claimType: runtime.claimType,
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
rbpPlanAudit: runtime.rbpPlanAudit,
|
||||
faPlanAudit: runtime.faPlanAudit,
|
||||
routeSummary: runtime.routeSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
requirementExtraction: runtime.requirementExtraction,
|
||||
extractRequirements: input.extractRequirements,
|
||||
evaluateCoverage: input.evaluateCoverage,
|
||||
checkGrounding: input.checkGrounding,
|
||||
temporalGuard: runtime.temporalGuard,
|
||||
polarityAudit: runtime.polarityAudit,
|
||||
evidenceAudit: runtime.evidenceAudit,
|
||||
claimAnchorAudit: runtime.claimAnchorAudit,
|
||||
targetedEvidenceHitRate: runtime.targetedEvidenceHitRate,
|
||||
businessScopeResolved: runtime.businessScopeResolved,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnCompositionRuntimeInput(input, runtime) {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
routeSummary: runtime.resolvedRouteSummary,
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
requirements: runtime.requirements,
|
||||
coverageReport: runtime.coverageReport,
|
||||
groundingCheck: runtime.groundingCheck,
|
||||
followupUsage: input.followupUsage,
|
||||
investigationState: input.investigationState,
|
||||
companyAnchors: runtime.companyAnchors,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnAnalysisRuntimeInput(input) {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
runContextRuntime: () => input.runDeepTurnContextRuntimeSafe(buildAssistantDeepTurnContextRuntimeInput(input)),
|
||||
runExecutionPlanRuntime: (runtime) => input.runDeepTurnPlanRuntimeSafe(buildAssistantDeepTurnExecutionPlanRuntimeInput(input, runtime)),
|
||||
runRetrievalRuntime: (runtime) => input.runDeepTurnRetrievalRuntimeSafe(buildAssistantDeepTurnRetrievalRuntimeInput(input, runtime)),
|
||||
runGuardRuntime: (runtime) => input.runDeepTurnGuardRuntimeSafe(buildAssistantDeepTurnGuardRuntimeInput(runtime)),
|
||||
runGroundingRuntime: (runtime) => input.runDeepTurnGroundingRuntimeSafe(buildAssistantDeepTurnGroundingRuntimeInput(input, runtime)),
|
||||
runCompositionRuntime: (runtime) => input.runDeepTurnCompositionRuntimeSafe(buildAssistantDeepTurnCompositionRuntimeInput(input, runtime))
|
||||
};
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAssistantDeepTurnAnalysisAttemptRuntime = runAssistantDeepTurnAnalysisAttemptRuntime;
|
||||
const companyAnchorResolver_1 = require("./companyAnchorResolver");
|
||||
const assistantRuntimeGuards_1 = require("./assistantRuntimeGuards");
|
||||
const assistantClaimBoundEvidence_1 = require("./assistantClaimBoundEvidence");
|
||||
const assistantDeepTurnAnalysisRuntimeAdapter_1 = require("./assistantDeepTurnAnalysisRuntimeAdapter");
|
||||
const assistantDeepTurnContextRuntimeAdapter_1 = require("./assistantDeepTurnContextRuntimeAdapter");
|
||||
const assistantDeepTurnPlanRuntimeAdapter_1 = require("./assistantDeepTurnPlanRuntimeAdapter");
|
||||
|
|
@ -11,6 +8,7 @@ const assistantDeepTurnRetrievalRuntimeAdapter_1 = require("./assistantDeepTurnR
|
|||
const assistantDeepTurnGuardRuntimeAdapter_1 = require("./assistantDeepTurnGuardRuntimeAdapter");
|
||||
const assistantDeepTurnGroundingRuntimeAdapter_1 = require("./assistantDeepTurnGroundingRuntimeAdapter");
|
||||
const assistantDeepTurnCompositionRuntimeAdapter_1 = require("./assistantDeepTurnCompositionRuntimeAdapter");
|
||||
const assistantDeepTurnAnalysisAttemptInputBuilder_1 = require("./assistantDeepTurnAnalysisAttemptInputBuilder");
|
||||
async function runAssistantDeepTurnAnalysisAttemptRuntime(input) {
|
||||
const runDeepTurnAnalysisRuntimeSafe = input.runDeepTurnAnalysisRuntime ?? assistantDeepTurnAnalysisRuntimeAdapter_1.runAssistantDeepTurnAnalysisRuntime;
|
||||
const runDeepTurnContextRuntimeSafe = input.runDeepTurnContextRuntime ?? assistantDeepTurnContextRuntimeAdapter_1.buildAssistantDeepTurnRuntimeContext;
|
||||
|
|
@ -19,88 +17,13 @@ async function runAssistantDeepTurnAnalysisAttemptRuntime(input) {
|
|||
const runDeepTurnGuardRuntimeSafe = input.runDeepTurnGuardRuntime ?? assistantDeepTurnGuardRuntimeAdapter_1.applyAssistantDeepTurnRetrievalGuards;
|
||||
const runDeepTurnGroundingRuntimeSafe = input.runDeepTurnGroundingRuntime ?? assistantDeepTurnGroundingRuntimeAdapter_1.runAssistantDeepTurnGroundingRuntime;
|
||||
const runDeepTurnCompositionRuntimeSafe = input.runDeepTurnCompositionRuntime ?? assistantDeepTurnCompositionRuntimeAdapter_1.buildAssistantDeepTurnComposition;
|
||||
return runDeepTurnAnalysisRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
runContextRuntime: () => runDeepTurnContextRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
routeSummary: input.routeSummary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.followupUsage,
|
||||
resolveCompanyAnchors: companyAnchorResolver_1.resolveCompanyAnchors,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveTemporalGuard: assistantRuntimeGuards_1.resolveTemporalGuard,
|
||||
resolveDomainPolarityGuard: assistantRuntimeGuards_1.resolveDomainPolarityGuard,
|
||||
resolveClaimBoundAnchors: assistantClaimBoundEvidence_1.resolveClaimBoundAnchors,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext
|
||||
}),
|
||||
runExecutionPlanRuntime: ({ resolvedRouteSummary, claimAnchorAudit, temporalGuard, domainPolarityGuardInitial }) => runDeepTurnPlanRuntimeSafe({
|
||||
routeSummary: resolvedRouteSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
claimType: claimAnchorAudit.claim_type,
|
||||
temporalGuard,
|
||||
domainPolarityGuardInitial,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
applyTemporalHintToExecutionPlan: assistantRuntimeGuards_1.applyTemporalHintToExecutionPlan,
|
||||
applyPolarityHintToExecutionPlan: assistantRuntimeGuards_1.applyPolarityHintToExecutionPlan
|
||||
}),
|
||||
runRetrievalRuntime: ({ executionPlan, liveTemporalHint }) => runDeepTurnRetrievalRuntimeSafe({
|
||||
executionPlan: executionPlan,
|
||||
liveTemporalHint,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult
|
||||
}),
|
||||
runGuardRuntime: ({ retrievalResults, domainPolarityGuardInitial, claimAnchorAudit, temporalGuard, focusDomainForGuards, companyAnchors, userMessage: runtimeUserMessage }) => runDeepTurnGuardRuntimeSafe({
|
||||
retrievalResults,
|
||||
domainPolarityGuardInitial: domainPolarityGuardInitial,
|
||||
claimAnchorAudit: claimAnchorAudit,
|
||||
temporalGuard: temporalGuard,
|
||||
focusDomainForGuards: focusDomainForGuards,
|
||||
companyAnchors: companyAnchors,
|
||||
userMessage: runtimeUserMessage
|
||||
}),
|
||||
runGroundingRuntime: ({ claimType, retrievalResults, rbpPlanAudit, faPlanAudit, routeSummary, requirementExtraction, temporalGuard, polarityAudit, evidenceAudit, claimAnchorAudit, targetedEvidenceHitRate, businessScopeResolved }) => runDeepTurnGroundingRuntimeSafe({
|
||||
claimType,
|
||||
retrievalResults,
|
||||
rbpPlanAudit,
|
||||
faPlanAudit,
|
||||
routeSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
requirementExtraction: requirementExtraction,
|
||||
extractRequirements: input.extractRequirements,
|
||||
evaluateCoverage: input.evaluateCoverage,
|
||||
checkGrounding: input.checkGrounding,
|
||||
temporalGuard,
|
||||
polarityAudit,
|
||||
evidenceAudit,
|
||||
claimAnchorAudit,
|
||||
targetedEvidenceHitRate,
|
||||
businessScopeResolved,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit
|
||||
}),
|
||||
runCompositionRuntime: ({ resolvedRouteSummary, retrievalResults, requirements, coverageReport, groundingCheck, companyAnchors }) => runDeepTurnCompositionRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
routeSummary: resolvedRouteSummary,
|
||||
retrievalResults,
|
||||
requirements,
|
||||
coverageReport,
|
||||
groundingCheck,
|
||||
followupUsage: input.followupUsage,
|
||||
investigationState: input.investigationState,
|
||||
companyAnchors,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
})
|
||||
});
|
||||
return runDeepTurnAnalysisRuntimeSafe((0, assistantDeepTurnAnalysisAttemptInputBuilder_1.buildAssistantDeepTurnAnalysisRuntimeInput)({
|
||||
...input,
|
||||
runDeepTurnContextRuntimeSafe,
|
||||
runDeepTurnPlanRuntimeSafe,
|
||||
runDeepTurnRetrievalRuntimeSafe,
|
||||
runDeepTurnGuardRuntimeSafe,
|
||||
runDeepTurnGroundingRuntimeSafe,
|
||||
runDeepTurnCompositionRuntimeSafe
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
80
llm_normalizer/backend/dist/services/assistantDeepTurnAttemptInputBuilder.js
vendored
Normal file
80
llm_normalizer/backend/dist/services/assistantDeepTurnAttemptInputBuilder.js
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAssistantDeepTurnNormalizationRuntimeInput = buildAssistantDeepTurnNormalizationRuntimeInput;
|
||||
exports.buildAssistantDeepTurnAnalysisAttemptRuntimeInput = buildAssistantDeepTurnAnalysisAttemptRuntimeInput;
|
||||
exports.buildAssistantDeepTurnResponseAttemptRuntimeInput = buildAssistantDeepTurnResponseAttemptRuntimeInput;
|
||||
function buildAssistantDeepTurnNormalizationRuntimeInput(input) {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
payload: input.payload,
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureStateFollowupBindingV1: input.featureStateFollowupBindingV1,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
buildFollowupStateBinding: input.buildFollowupStateBinding,
|
||||
normalize: input.normalize
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnAnalysisAttemptRuntimeInput(input) {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizationRuntime.normalized.normalized,
|
||||
routeSummary: input.normalizationRuntime.normalized.route_hint_summary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.normalizationRuntime.followupBinding.usage,
|
||||
investigationState: input.sessionInvestigationState,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult,
|
||||
evaluateCoverage: input.evaluateCoverage,
|
||||
checkGrounding: input.checkGrounding,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
};
|
||||
}
|
||||
function buildAssistantDeepTurnResponseAttemptRuntimeInput(input) {
|
||||
return {
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: {
|
||||
trace_id: input.normalizationRuntime.normalized.trace_id,
|
||||
prompt_version: input.normalizationRuntime.normalized.prompt_version,
|
||||
schema_version: input.normalizationRuntime.normalized.schema_version,
|
||||
normalized: input.normalizationRuntime.normalized.normalized
|
||||
},
|
||||
normalizedQuestion: input.normalizationRuntime.followupBinding.normalizedQuestion,
|
||||
deepTurnAnalysisRuntime: input.deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupStateUsage: input.normalizationRuntime.followupBinding.usage,
|
||||
followupApplied: Boolean(input.normalizationRuntime.followupBinding.usage?.applied),
|
||||
previousInvestigationState: input.sessionInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
extractExecutionState: input.extractExecutionState,
|
||||
sanitizeReply: input.sanitizeReply,
|
||||
persistInvestigationState: input.persistInvestigationState,
|
||||
messageIdFactory: input.messageIdFactory,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
};
|
||||
}
|
||||
|
|
@ -4,11 +4,12 @@ exports.runAssistantDeepTurnAttemptRuntime = runAssistantDeepTurnAttemptRuntime;
|
|||
const assistantDeepTurnNormalizationRuntimeAdapter_1 = require("./assistantDeepTurnNormalizationRuntimeAdapter");
|
||||
const assistantDeepTurnAnalysisAttemptRuntimeAdapter_1 = require("./assistantDeepTurnAnalysisAttemptRuntimeAdapter");
|
||||
const assistantDeepTurnResponseAttemptRuntimeAdapter_1 = require("./assistantDeepTurnResponseAttemptRuntimeAdapter");
|
||||
const assistantDeepTurnAttemptInputBuilder_1 = require("./assistantDeepTurnAttemptInputBuilder");
|
||||
async function runAssistantDeepTurnAttemptRuntime(input) {
|
||||
const runDeepTurnNormalizationRuntimeSafe = input.runDeepTurnNormalizationRuntime ?? assistantDeepTurnNormalizationRuntimeAdapter_1.buildAssistantDeepTurnNormalizationRuntime;
|
||||
const runDeepTurnAnalysisAttemptRuntimeSafe = input.runDeepTurnAnalysisAttemptRuntime ?? assistantDeepTurnAnalysisAttemptRuntimeAdapter_1.runAssistantDeepTurnAnalysisAttemptRuntime;
|
||||
const runDeepTurnResponseAttemptRuntimeSafe = input.runDeepTurnResponseAttemptRuntime ?? assistantDeepTurnResponseAttemptRuntimeAdapter_1.runAssistantDeepTurnResponseAttemptRuntime;
|
||||
const normalizationRuntime = await runDeepTurnNormalizationRuntimeSafe({
|
||||
const normalizationRuntime = await runDeepTurnNormalizationRuntimeSafe((0, assistantDeepTurnAttemptInputBuilder_1.buildAssistantDeepTurnNormalizationRuntimeInput)({
|
||||
userMessage: input.userMessage,
|
||||
payload: input.payload,
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
|
|
@ -16,16 +17,11 @@ async function runAssistantDeepTurnAttemptRuntime(input) {
|
|||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
buildFollowupStateBinding: input.buildFollowupStateBinding,
|
||||
normalize: input.normalize
|
||||
});
|
||||
const followupBinding = normalizationRuntime.followupBinding;
|
||||
const normalized = normalizationRuntime.normalized;
|
||||
const deepTurnAnalysisRuntime = await runDeepTurnAnalysisAttemptRuntimeSafe({
|
||||
}));
|
||||
const deepTurnAnalysisRuntime = await runDeepTurnAnalysisAttemptRuntimeSafe((0, assistantDeepTurnAttemptInputBuilder_1.buildAssistantDeepTurnAnalysisAttemptRuntimeInput)({
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: normalized.normalized,
|
||||
routeSummary: normalized.route_hint_summary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: followupBinding.usage,
|
||||
investigationState: input.sessionInvestigationState,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
|
|
@ -43,27 +39,18 @@ async function runAssistantDeepTurnAttemptRuntime(input) {
|
|||
checkGrounding: input.checkGrounding,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
});
|
||||
const deepTurnResponseRuntime = runDeepTurnResponseAttemptRuntimeSafe({
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor,
|
||||
normalizationRuntime
|
||||
}));
|
||||
const deepTurnResponseRuntime = runDeepTurnResponseAttemptRuntimeSafe((0, assistantDeepTurnAttemptInputBuilder_1.buildAssistantDeepTurnResponseAttemptRuntimeInput)({
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: {
|
||||
trace_id: normalized.trace_id,
|
||||
prompt_version: normalized.prompt_version,
|
||||
schema_version: normalized.schema_version,
|
||||
normalized: normalized.normalized
|
||||
},
|
||||
normalizedQuestion: followupBinding.normalizedQuestion,
|
||||
deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupStateUsage: followupBinding.usage,
|
||||
followupApplied: Boolean(followupBinding.usage?.applied),
|
||||
previousInvestigationState: input.sessionInvestigationState,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
|
|
@ -77,8 +64,10 @@ async function runAssistantDeepTurnAttemptRuntime(input) {
|
|||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
});
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn,
|
||||
normalizationRuntime,
|
||||
deepTurnAnalysisRuntime
|
||||
}));
|
||||
return {
|
||||
response: deepTurnResponseRuntime.response,
|
||||
debug: deepTurnResponseRuntime.debug,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAssistantDeepTurnResponseAttemptRuntime = runAssistantDeepTurnResponseAttemptRuntime;
|
||||
const assistantDeepTurnResponseRuntimeAdapter_1 = require("./assistantDeepTurnResponseRuntimeAdapter");
|
||||
const assistantDeepTurnResponseRuntimeInputBuilder_1 = require("./assistantDeepTurnResponseRuntimeInputBuilder");
|
||||
function runAssistantDeepTurnResponseAttemptRuntime(input) {
|
||||
const runDeepTurnResponseRuntimeSafe = input.runDeepTurnResponseRuntime ?? assistantDeepTurnResponseRuntimeAdapter_1.runAssistantDeepTurnResponseRuntime;
|
||||
const analysis = input.deepTurnAnalysisRuntime;
|
||||
const responseRuntime = runDeepTurnResponseRuntimeSafe({
|
||||
const responseRuntime = runDeepTurnResponseRuntimeSafe((0, assistantDeepTurnResponseRuntimeInputBuilder_1.buildAssistantDeepTurnResponseRuntimeInput)({
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
|
|
@ -14,31 +14,11 @@ function runAssistantDeepTurnResponseAttemptRuntime(input) {
|
|||
userMessage: input.userMessage,
|
||||
normalized: input.normalized,
|
||||
normalizedQuestion: input.normalizedQuestion,
|
||||
routeSummary: analysis.resolvedRouteSummary,
|
||||
executionPlan: analysis.executionPlan,
|
||||
requirementExtractionRequirements: analysis.requirementExtraction.requirements,
|
||||
coverageEvaluationRequirements: analysis.coverageEvaluation.requirements,
|
||||
coverageReport: analysis.coverageEvaluation.coverage,
|
||||
groundingCheck: analysis.groundingCheck,
|
||||
retrievalCalls: analysis.retrievalCalls,
|
||||
retrievalResultsRaw: analysis.retrievalResultsRaw,
|
||||
retrievalResults: analysis.retrievalResults,
|
||||
questionTypeClass: analysis.questionTypeClass,
|
||||
companyAnchors: analysis.companyAnchors,
|
||||
deepTurnAnalysisRuntime: input.deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
businessScopeResolution: analysis.businessScopeResolution,
|
||||
temporalGuard: analysis.temporalGuard,
|
||||
polarityAudit: analysis.polarityGuardResult.audit,
|
||||
claimAnchorAudit: analysis.claimAnchorAudit,
|
||||
targetedEvidenceAudit: analysis.targetedEvidenceResult.audit,
|
||||
evidenceAdmissibilityGateAudit: analysis.evidenceGateResult.audit,
|
||||
rbpLiveRouteAudit: analysis.rbpLiveRouteAudit,
|
||||
faLiveRouteAudit: analysis.faLiveRouteAudit,
|
||||
groundedAnswerEligibilityGuard: analysis.groundedAnswerEligibilityGuard,
|
||||
followupStateUsage: input.followupStateUsage,
|
||||
followupApplied: input.followupApplied,
|
||||
composition: analysis.composition,
|
||||
previousInvestigationState: input.previousInvestigationState ?? null,
|
||||
previousInvestigationState: input.previousInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
|
|
@ -53,7 +33,7 @@ function runAssistantDeepTurnResponseAttemptRuntime(input) {
|
|||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
});
|
||||
}));
|
||||
return {
|
||||
response: responseRuntime.response,
|
||||
debug: responseRuntime.debug
|
||||
|
|
|
|||
55
llm_normalizer/backend/dist/services/assistantDeepTurnResponseRuntimeInputBuilder.js
vendored
Normal file
55
llm_normalizer/backend/dist/services/assistantDeepTurnResponseRuntimeInputBuilder.js
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAssistantDeepTurnResponseRuntimeInput = buildAssistantDeepTurnResponseRuntimeInput;
|
||||
function buildAssistantDeepTurnResponseRuntimeInput(input) {
|
||||
const analysis = input.deepTurnAnalysisRuntime;
|
||||
return {
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: input.normalized,
|
||||
normalizedQuestion: input.normalizedQuestion,
|
||||
routeSummary: analysis.resolvedRouteSummary,
|
||||
executionPlan: analysis.executionPlan,
|
||||
requirementExtractionRequirements: analysis.requirementExtraction.requirements,
|
||||
coverageEvaluationRequirements: analysis.coverageEvaluation.requirements,
|
||||
coverageReport: analysis.coverageEvaluation.coverage,
|
||||
groundingCheck: analysis.groundingCheck,
|
||||
retrievalCalls: analysis.retrievalCalls,
|
||||
retrievalResultsRaw: analysis.retrievalResultsRaw,
|
||||
retrievalResults: analysis.retrievalResults,
|
||||
questionTypeClass: analysis.questionTypeClass,
|
||||
companyAnchors: analysis.companyAnchors,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
businessScopeResolution: analysis.businessScopeResolution,
|
||||
temporalGuard: analysis.temporalGuard,
|
||||
polarityAudit: analysis.polarityGuardResult.audit,
|
||||
claimAnchorAudit: analysis.claimAnchorAudit,
|
||||
targetedEvidenceAudit: analysis.targetedEvidenceResult.audit,
|
||||
evidenceAdmissibilityGateAudit: analysis.evidenceGateResult.audit,
|
||||
rbpLiveRouteAudit: analysis.rbpLiveRouteAudit,
|
||||
faLiveRouteAudit: analysis.faLiveRouteAudit,
|
||||
groundedAnswerEligibilityGuard: analysis.groundedAnswerEligibilityGuard,
|
||||
followupStateUsage: input.followupStateUsage,
|
||||
followupApplied: input.followupApplied,
|
||||
composition: analysis.composition,
|
||||
previousInvestigationState: input.previousInvestigationState ?? null,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
extractExecutionState: input.extractExecutionState,
|
||||
sanitizeReply: input.sanitizeReply,
|
||||
persistInvestigationState: input.persistInvestigationState,
|
||||
messageIdFactory: input.messageIdFactory,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
import { resolveCompanyAnchors } from "./companyAnchorResolver";
|
||||
import {
|
||||
applyPolarityHintToExecutionPlan,
|
||||
applyTemporalHintToExecutionPlan,
|
||||
resolveDomainPolarityGuard,
|
||||
resolveTemporalGuard
|
||||
} from "./assistantRuntimeGuards";
|
||||
import { resolveClaimBoundAnchors } from "./assistantClaimBoundEvidence";
|
||||
import type { RunAssistantDeepTurnAnalysisRuntimeInput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
|
||||
import type {
|
||||
BuildAssistantDeepTurnRuntimeContextInput,
|
||||
BuildAssistantDeepTurnRuntimeContextOutput
|
||||
} from "./assistantDeepTurnContextRuntimeAdapter";
|
||||
import type {
|
||||
BuildAssistantDeepTurnExecutionPlanInput,
|
||||
BuildAssistantDeepTurnExecutionPlanOutput,
|
||||
AssistantRequirementExtractionLike
|
||||
} from "./assistantDeepTurnPlanRuntimeAdapter";
|
||||
import type {
|
||||
AssistantDeepTurnRetrievalExecutionInput,
|
||||
AssistantDeepTurnRetrievalExecutionOutput
|
||||
} from "./assistantDeepTurnRetrievalRuntimeAdapter";
|
||||
import type {
|
||||
AssistantDeepTurnRetrievalGuardPipelineInput,
|
||||
AssistantDeepTurnRetrievalGuardPipelineOutput
|
||||
} from "./assistantDeepTurnGuardRuntimeAdapter";
|
||||
import type {
|
||||
AssistantDeepTurnGroundingRuntimeInput,
|
||||
AssistantDeepTurnGroundingRuntimeOutput
|
||||
} from "./assistantDeepTurnGroundingRuntimeAdapter";
|
||||
import type {
|
||||
BuildAssistantDeepTurnCompositionInput,
|
||||
AssistantDeepTurnCompositionOutput
|
||||
} from "./assistantDeepTurnCompositionRuntimeAdapter";
|
||||
import type { AssistantExecutionPlanItem } from "./assistantQueryPlanning";
|
||||
import type { RunAssistantDeepTurnAnalysisAttemptRuntimeInput } from "./assistantDeepTurnAnalysisAttemptRuntimeAdapter";
|
||||
|
||||
type ExecutionPlanRuntimeArgs = Parameters<RunAssistantDeepTurnAnalysisRuntimeInput["runExecutionPlanRuntime"]>[0];
|
||||
type RetrievalRuntimeArgs = Parameters<RunAssistantDeepTurnAnalysisRuntimeInput["runRetrievalRuntime"]>[0];
|
||||
type GuardRuntimeArgs = Parameters<RunAssistantDeepTurnAnalysisRuntimeInput["runGuardRuntime"]>[0];
|
||||
type GroundingRuntimeArgs = Parameters<RunAssistantDeepTurnAnalysisRuntimeInput["runGroundingRuntime"]>[0];
|
||||
type CompositionRuntimeArgs = Parameters<RunAssistantDeepTurnAnalysisRuntimeInput["runCompositionRuntime"]>[0];
|
||||
|
||||
export interface BuildAssistantDeepTurnAnalysisRuntimeInputInput
|
||||
extends RunAssistantDeepTurnAnalysisAttemptRuntimeInput {
|
||||
runDeepTurnContextRuntimeSafe: (
|
||||
input: BuildAssistantDeepTurnRuntimeContextInput
|
||||
) => BuildAssistantDeepTurnRuntimeContextOutput;
|
||||
runDeepTurnPlanRuntimeSafe: (
|
||||
input: BuildAssistantDeepTurnExecutionPlanInput
|
||||
) => BuildAssistantDeepTurnExecutionPlanOutput;
|
||||
runDeepTurnRetrievalRuntimeSafe: (
|
||||
input: AssistantDeepTurnRetrievalExecutionInput
|
||||
) => Promise<AssistantDeepTurnRetrievalExecutionOutput>;
|
||||
runDeepTurnGuardRuntimeSafe: (
|
||||
input: AssistantDeepTurnRetrievalGuardPipelineInput
|
||||
) => AssistantDeepTurnRetrievalGuardPipelineOutput;
|
||||
runDeepTurnGroundingRuntimeSafe: (
|
||||
input: AssistantDeepTurnGroundingRuntimeInput
|
||||
) => AssistantDeepTurnGroundingRuntimeOutput;
|
||||
runDeepTurnCompositionRuntimeSafe: (
|
||||
input: BuildAssistantDeepTurnCompositionInput
|
||||
) => AssistantDeepTurnCompositionOutput;
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnContextRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput
|
||||
): BuildAssistantDeepTurnRuntimeContextInput {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
routeSummary: input.routeSummary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.followupUsage,
|
||||
resolveCompanyAnchors,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveTemporalGuard: resolveTemporalGuard as any,
|
||||
resolveDomainPolarityGuard: resolveDomainPolarityGuard as any,
|
||||
resolveClaimBoundAnchors: resolveClaimBoundAnchors as any,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnExecutionPlanRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput,
|
||||
runtime: ExecutionPlanRuntimeArgs
|
||||
): BuildAssistantDeepTurnExecutionPlanInput {
|
||||
return {
|
||||
routeSummary: runtime.resolvedRouteSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
claimType: runtime.claimAnchorAudit.claim_type,
|
||||
temporalGuard: runtime.temporalGuard,
|
||||
domainPolarityGuardInitial: runtime.domainPolarityGuardInitial,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
applyTemporalHintToExecutionPlan: applyTemporalHintToExecutionPlan as any,
|
||||
applyPolarityHintToExecutionPlan: applyPolarityHintToExecutionPlan as any
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnRetrievalRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput,
|
||||
runtime: RetrievalRuntimeArgs
|
||||
): AssistantDeepTurnRetrievalExecutionInput {
|
||||
return {
|
||||
executionPlan: runtime.executionPlan as AssistantExecutionPlanItem[],
|
||||
liveTemporalHint: runtime.liveTemporalHint,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnGuardRuntimeInput(
|
||||
runtime: GuardRuntimeArgs
|
||||
): AssistantDeepTurnRetrievalGuardPipelineInput {
|
||||
return {
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
domainPolarityGuardInitial: runtime.domainPolarityGuardInitial as any,
|
||||
claimAnchorAudit: runtime.claimAnchorAudit as any,
|
||||
temporalGuard: runtime.temporalGuard as any,
|
||||
focusDomainForGuards: runtime.focusDomainForGuards as any,
|
||||
companyAnchors: runtime.companyAnchors as any,
|
||||
userMessage: runtime.userMessage
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnGroundingRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput,
|
||||
runtime: GroundingRuntimeArgs
|
||||
): AssistantDeepTurnGroundingRuntimeInput {
|
||||
return {
|
||||
claimType: runtime.claimType,
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
rbpPlanAudit: runtime.rbpPlanAudit,
|
||||
faPlanAudit: runtime.faPlanAudit,
|
||||
routeSummary: runtime.routeSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
requirementExtraction: runtime.requirementExtraction as AssistantRequirementExtractionLike,
|
||||
extractRequirements: input.extractRequirements as any,
|
||||
evaluateCoverage: input.evaluateCoverage as any,
|
||||
checkGrounding: input.checkGrounding as any,
|
||||
temporalGuard: runtime.temporalGuard,
|
||||
polarityAudit: runtime.polarityAudit,
|
||||
evidenceAudit: runtime.evidenceAudit,
|
||||
claimAnchorAudit: runtime.claimAnchorAudit,
|
||||
targetedEvidenceHitRate: runtime.targetedEvidenceHitRate,
|
||||
businessScopeResolved: runtime.businessScopeResolved,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit as any,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit as any
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnCompositionRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput,
|
||||
runtime: CompositionRuntimeArgs
|
||||
): BuildAssistantDeepTurnCompositionInput {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
routeSummary: runtime.resolvedRouteSummary,
|
||||
retrievalResults: runtime.retrievalResults,
|
||||
requirements: runtime.requirements,
|
||||
coverageReport: runtime.coverageReport,
|
||||
groundingCheck: runtime.groundingCheck,
|
||||
followupUsage: input.followupUsage,
|
||||
investigationState: input.investigationState,
|
||||
companyAnchors: runtime.companyAnchors,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnAnalysisRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisRuntimeInputInput
|
||||
): RunAssistantDeepTurnAnalysisRuntimeInput {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
runContextRuntime: () =>
|
||||
input.runDeepTurnContextRuntimeSafe(buildAssistantDeepTurnContextRuntimeInput(input)) as any,
|
||||
runExecutionPlanRuntime: (runtime) =>
|
||||
input.runDeepTurnPlanRuntimeSafe(
|
||||
buildAssistantDeepTurnExecutionPlanRuntimeInput(input, runtime)
|
||||
) as any,
|
||||
runRetrievalRuntime: (runtime) =>
|
||||
input.runDeepTurnRetrievalRuntimeSafe(
|
||||
buildAssistantDeepTurnRetrievalRuntimeInput(input, runtime)
|
||||
) as any,
|
||||
runGuardRuntime: (runtime) =>
|
||||
input.runDeepTurnGuardRuntimeSafe(buildAssistantDeepTurnGuardRuntimeInput(runtime) as any),
|
||||
runGroundingRuntime: (runtime) =>
|
||||
input.runDeepTurnGroundingRuntimeSafe(
|
||||
buildAssistantDeepTurnGroundingRuntimeInput(input, runtime)
|
||||
) as any,
|
||||
runCompositionRuntime: (runtime) =>
|
||||
input.runDeepTurnCompositionRuntimeSafe(
|
||||
buildAssistantDeepTurnCompositionRuntimeInput(input, runtime)
|
||||
) as any
|
||||
};
|
||||
}
|
||||
|
|
@ -1,11 +1,3 @@
|
|||
import { resolveCompanyAnchors } from "./companyAnchorResolver";
|
||||
import {
|
||||
applyPolarityHintToExecutionPlan,
|
||||
applyTemporalHintToExecutionPlan,
|
||||
resolveDomainPolarityGuard,
|
||||
resolveTemporalGuard
|
||||
} from "./assistantRuntimeGuards";
|
||||
import { resolveClaimBoundAnchors } from "./assistantClaimBoundEvidence";
|
||||
import {
|
||||
runAssistantDeepTurnAnalysisRuntime,
|
||||
type RunAssistantDeepTurnAnalysisRuntimeInput,
|
||||
|
|
@ -43,8 +35,7 @@ import {
|
|||
} from "./assistantDeepTurnCompositionRuntimeAdapter";
|
||||
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
|
||||
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
|
||||
import type { AssistantExecutionPlanItem } from "./assistantQueryPlanning";
|
||||
import type { AssistantRequirementExtractionLike } from "./assistantDeepTurnPlanRuntimeAdapter";
|
||||
import { buildAssistantDeepTurnAnalysisRuntimeInput } from "./assistantDeepTurnAnalysisAttemptInputBuilder";
|
||||
|
||||
interface RuntimeAnalysisContextLike {
|
||||
active: boolean;
|
||||
|
|
@ -117,127 +108,15 @@ export async function runAssistantDeepTurnAnalysisAttemptRuntime(
|
|||
const runDeepTurnCompositionRuntimeSafe =
|
||||
input.runDeepTurnCompositionRuntime ?? buildAssistantDeepTurnComposition;
|
||||
|
||||
return runDeepTurnAnalysisRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
runContextRuntime: () =>
|
||||
runDeepTurnContextRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
routeSummary: input.routeSummary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.followupUsage,
|
||||
resolveCompanyAnchors,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveTemporalGuard: resolveTemporalGuard as any,
|
||||
resolveDomainPolarityGuard: resolveDomainPolarityGuard as any,
|
||||
resolveClaimBoundAnchors: resolveClaimBoundAnchors as any,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext
|
||||
}) as any,
|
||||
runExecutionPlanRuntime: ({
|
||||
resolvedRouteSummary,
|
||||
claimAnchorAudit,
|
||||
temporalGuard,
|
||||
domainPolarityGuardInitial
|
||||
}) =>
|
||||
runDeepTurnPlanRuntimeSafe({
|
||||
routeSummary: resolvedRouteSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
claimType: claimAnchorAudit.claim_type,
|
||||
temporalGuard,
|
||||
domainPolarityGuardInitial,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
applyTemporalHintToExecutionPlan: applyTemporalHintToExecutionPlan as any,
|
||||
applyPolarityHintToExecutionPlan: applyPolarityHintToExecutionPlan as any
|
||||
}) as any,
|
||||
runRetrievalRuntime: ({ executionPlan, liveTemporalHint }) =>
|
||||
runDeepTurnRetrievalRuntimeSafe({
|
||||
executionPlan: executionPlan as AssistantExecutionPlanItem[],
|
||||
liveTemporalHint,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult
|
||||
}) as any,
|
||||
runGuardRuntime: ({
|
||||
retrievalResults,
|
||||
domainPolarityGuardInitial,
|
||||
claimAnchorAudit,
|
||||
temporalGuard,
|
||||
focusDomainForGuards,
|
||||
companyAnchors,
|
||||
userMessage: runtimeUserMessage
|
||||
}) =>
|
||||
runDeepTurnGuardRuntimeSafe({
|
||||
retrievalResults,
|
||||
domainPolarityGuardInitial: domainPolarityGuardInitial as any,
|
||||
claimAnchorAudit: claimAnchorAudit as any,
|
||||
temporalGuard: temporalGuard as any,
|
||||
focusDomainForGuards: focusDomainForGuards as any,
|
||||
companyAnchors: companyAnchors as any,
|
||||
userMessage: runtimeUserMessage
|
||||
} as any),
|
||||
runGroundingRuntime: ({
|
||||
claimType,
|
||||
retrievalResults,
|
||||
rbpPlanAudit,
|
||||
faPlanAudit,
|
||||
routeSummary,
|
||||
requirementExtraction,
|
||||
temporalGuard,
|
||||
polarityAudit,
|
||||
evidenceAudit,
|
||||
claimAnchorAudit,
|
||||
targetedEvidenceHitRate,
|
||||
businessScopeResolved
|
||||
}) =>
|
||||
runDeepTurnGroundingRuntimeSafe({
|
||||
claimType,
|
||||
retrievalResults,
|
||||
rbpPlanAudit,
|
||||
faPlanAudit,
|
||||
routeSummary,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
userMessage: input.userMessage,
|
||||
requirementExtraction: requirementExtraction as AssistantRequirementExtractionLike,
|
||||
extractRequirements: input.extractRequirements as any,
|
||||
evaluateCoverage: input.evaluateCoverage as any,
|
||||
checkGrounding: input.checkGrounding as any,
|
||||
temporalGuard,
|
||||
polarityAudit,
|
||||
evidenceAudit,
|
||||
claimAnchorAudit,
|
||||
targetedEvidenceHitRate,
|
||||
businessScopeResolved,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit as any,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit as any
|
||||
} as any),
|
||||
runCompositionRuntime: ({
|
||||
resolvedRouteSummary,
|
||||
retrievalResults,
|
||||
requirements,
|
||||
coverageReport,
|
||||
groundingCheck,
|
||||
companyAnchors
|
||||
}) =>
|
||||
runDeepTurnCompositionRuntimeSafe({
|
||||
userMessage: input.userMessage,
|
||||
routeSummary: resolvedRouteSummary,
|
||||
retrievalResults,
|
||||
requirements,
|
||||
coverageReport,
|
||||
groundingCheck,
|
||||
followupUsage: input.followupUsage,
|
||||
investigationState: input.investigationState,
|
||||
companyAnchors,
|
||||
normalizedPayload: input.normalizedPayload,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
}) as any
|
||||
});
|
||||
return runDeepTurnAnalysisRuntimeSafe(
|
||||
buildAssistantDeepTurnAnalysisRuntimeInput({
|
||||
...input,
|
||||
runDeepTurnContextRuntimeSafe,
|
||||
runDeepTurnPlanRuntimeSafe,
|
||||
runDeepTurnRetrievalRuntimeSafe,
|
||||
runDeepTurnGuardRuntimeSafe,
|
||||
runDeepTurnGroundingRuntimeSafe,
|
||||
runDeepTurnCompositionRuntimeSafe
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,156 @@
|
|||
import type {
|
||||
BuildAssistantDeepTurnNormalizationRuntimeInput,
|
||||
BuildAssistantDeepTurnNormalizationRuntimeOutput
|
||||
} from "./assistantDeepTurnNormalizationRuntimeAdapter";
|
||||
import type { RunAssistantDeepTurnAnalysisAttemptRuntimeInput } from "./assistantDeepTurnAnalysisAttemptRuntimeAdapter";
|
||||
import type { RunAssistantDeepTurnAnalysisRuntimeOutput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
|
||||
import type { RunAssistantDeepTurnResponseAttemptRuntimeInput } from "./assistantDeepTurnResponseAttemptRuntimeAdapter";
|
||||
|
||||
export interface BuildAssistantDeepTurnNormalizationRuntimeInputInput {
|
||||
userMessage: string;
|
||||
payload: BuildAssistantDeepTurnNormalizationRuntimeInput["payload"];
|
||||
featureInvestigationStateV1: boolean;
|
||||
featureStateFollowupBindingV1: boolean;
|
||||
sessionInvestigationState: BuildAssistantDeepTurnNormalizationRuntimeInput["sessionInvestigationState"];
|
||||
buildFollowupStateBinding: BuildAssistantDeepTurnNormalizationRuntimeInput["buildFollowupStateBinding"];
|
||||
normalize: BuildAssistantDeepTurnNormalizationRuntimeInput["normalize"];
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnNormalizationRuntimeInput(
|
||||
input: BuildAssistantDeepTurnNormalizationRuntimeInputInput
|
||||
): BuildAssistantDeepTurnNormalizationRuntimeInput {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
payload: input.payload,
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureStateFollowupBindingV1: input.featureStateFollowupBindingV1,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
buildFollowupStateBinding: input.buildFollowupStateBinding,
|
||||
normalize: input.normalize
|
||||
};
|
||||
}
|
||||
|
||||
export interface BuildAssistantDeepTurnAnalysisAttemptRuntimeInputInput {
|
||||
userMessage: string;
|
||||
runtimeAnalysisContext: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["runtimeAnalysisContext"];
|
||||
sessionInvestigationState: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["investigationState"];
|
||||
featureAnswerPolicyV11: boolean;
|
||||
featureProblemCentricAnswerV1: boolean;
|
||||
featureLifecycleAnswerV1: boolean;
|
||||
resolveBusinessScopeAlignment: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["resolveBusinessScopeAlignment"];
|
||||
inferP0DomainFromMessage: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["inferP0DomainFromMessage"];
|
||||
resolveBusinessScopeFromLiveContext:
|
||||
RunAssistantDeepTurnAnalysisAttemptRuntimeInput["resolveBusinessScopeFromLiveContext"];
|
||||
extractRequirements: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["extractRequirements"];
|
||||
toExecutionPlan: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["toExecutionPlan"];
|
||||
enforceRbpLiveRoutePlan: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["enforceRbpLiveRoutePlan"];
|
||||
enforceFaLiveRoutePlan: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["enforceFaLiveRoutePlan"];
|
||||
executeRouteRuntime: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["executeRouteRuntime"];
|
||||
mapNoRouteReason: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["mapNoRouteReason"];
|
||||
buildSkippedResult: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["buildSkippedResult"];
|
||||
evaluateCoverage: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["evaluateCoverage"];
|
||||
checkGrounding: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["checkGrounding"];
|
||||
collectRbpLiveRouteAudit: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["collectRbpLiveRouteAudit"];
|
||||
collectFaLiveRouteAudit: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["collectFaLiveRouteAudit"];
|
||||
hasExplicitPeriodAnchor: RunAssistantDeepTurnAnalysisAttemptRuntimeInput["hasExplicitPeriodAnchor"];
|
||||
normalizationRuntime: BuildAssistantDeepTurnNormalizationRuntimeOutput;
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnAnalysisAttemptRuntimeInput(
|
||||
input: BuildAssistantDeepTurnAnalysisAttemptRuntimeInputInput
|
||||
): RunAssistantDeepTurnAnalysisAttemptRuntimeInput {
|
||||
return {
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: input.normalizationRuntime.normalized.normalized,
|
||||
routeSummary: input.normalizationRuntime.normalized.route_hint_summary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: input.normalizationRuntime.followupBinding.usage,
|
||||
investigationState: input.sessionInvestigationState,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
resolveBusinessScopeAlignment: input.resolveBusinessScopeAlignment,
|
||||
inferP0DomainFromMessage: input.inferP0DomainFromMessage,
|
||||
resolveBusinessScopeFromLiveContext: input.resolveBusinessScopeFromLiveContext,
|
||||
extractRequirements: input.extractRequirements,
|
||||
toExecutionPlan: input.toExecutionPlan,
|
||||
enforceRbpLiveRoutePlan: input.enforceRbpLiveRoutePlan,
|
||||
enforceFaLiveRoutePlan: input.enforceFaLiveRoutePlan,
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason,
|
||||
buildSkippedResult: input.buildSkippedResult,
|
||||
evaluateCoverage: input.evaluateCoverage,
|
||||
checkGrounding: input.checkGrounding,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
};
|
||||
}
|
||||
|
||||
export interface BuildAssistantDeepTurnResponseAttemptRuntimeInputInput<ResponseType = unknown> {
|
||||
featureInvestigationStateV1: boolean;
|
||||
featureContractsV11: boolean;
|
||||
featureAnswerPolicyV11: boolean;
|
||||
sessionId: string;
|
||||
questionId: string;
|
||||
userMessage: string;
|
||||
runtimeAnalysisContext: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["runtimeAnalysisContext"];
|
||||
sessionInvestigationState: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["previousInvestigationState"];
|
||||
addressRuntimeMetaForDeep: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["addressRuntimeMetaForDeep"];
|
||||
extractDroppedIntentSegments: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["extractDroppedIntentSegments"];
|
||||
buildDebugRoutes: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["buildDebugRoutes"];
|
||||
extractExecutionState: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["extractExecutionState"];
|
||||
sanitizeReply: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["sanitizeReply"];
|
||||
persistInvestigationState: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["persistInvestigationState"];
|
||||
messageIdFactory: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["messageIdFactory"];
|
||||
appendItem: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["appendItem"];
|
||||
getSession: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["getSession"];
|
||||
persistSession: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["persistSession"];
|
||||
cloneConversation: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["cloneConversation"];
|
||||
logEvent: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["logEvent"];
|
||||
runPackagingRuntime?: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["runPackagingRuntime"];
|
||||
runFinalizeDeepTurn?: RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType>["runFinalizeDeepTurn"];
|
||||
normalizationRuntime: BuildAssistantDeepTurnNormalizationRuntimeOutput;
|
||||
deepTurnAnalysisRuntime: RunAssistantDeepTurnAnalysisRuntimeOutput;
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType = unknown>(
|
||||
input: BuildAssistantDeepTurnResponseAttemptRuntimeInputInput<ResponseType>
|
||||
): RunAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType> {
|
||||
return {
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: {
|
||||
trace_id: input.normalizationRuntime.normalized.trace_id,
|
||||
prompt_version: input.normalizationRuntime.normalized.prompt_version,
|
||||
schema_version: input.normalizationRuntime.normalized.schema_version,
|
||||
normalized: input.normalizationRuntime.normalized.normalized
|
||||
},
|
||||
normalizedQuestion: input.normalizationRuntime.followupBinding.normalizedQuestion,
|
||||
deepTurnAnalysisRuntime: input.deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupStateUsage: input.normalizationRuntime.followupBinding.usage,
|
||||
followupApplied: Boolean(
|
||||
(input.normalizationRuntime.followupBinding.usage as { applied?: unknown } | null)?.applied
|
||||
),
|
||||
previousInvestigationState: input.sessionInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
extractExecutionState: input.extractExecutionState,
|
||||
sanitizeReply: input.sanitizeReply,
|
||||
persistInvestigationState: input.persistInvestigationState,
|
||||
messageIdFactory: input.messageIdFactory,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
};
|
||||
}
|
||||
|
|
@ -14,6 +14,11 @@ import {
|
|||
type RunAssistantDeepTurnResponseAttemptRuntimeInput
|
||||
} from "./assistantDeepTurnResponseAttemptRuntimeAdapter";
|
||||
import type { RunAssistantDeepTurnAnalysisRuntimeOutput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
|
||||
import {
|
||||
buildAssistantDeepTurnAnalysisAttemptRuntimeInput,
|
||||
buildAssistantDeepTurnNormalizationRuntimeInput,
|
||||
buildAssistantDeepTurnResponseAttemptRuntimeInput
|
||||
} from "./assistantDeepTurnAttemptInputBuilder";
|
||||
|
||||
export interface RunAssistantDeepTurnAttemptRuntimeInput<ResponseType = AssistantMessageResponsePayload> {
|
||||
sessionId: string;
|
||||
|
|
@ -90,7 +95,8 @@ export async function runAssistantDeepTurnAttemptRuntime<ResponseType = Assistan
|
|||
const runDeepTurnResponseAttemptRuntimeSafe =
|
||||
input.runDeepTurnResponseAttemptRuntime ?? runAssistantDeepTurnResponseAttemptRuntime;
|
||||
|
||||
const normalizationRuntime = await runDeepTurnNormalizationRuntimeSafe({
|
||||
const normalizationRuntime = await runDeepTurnNormalizationRuntimeSafe(
|
||||
buildAssistantDeepTurnNormalizationRuntimeInput({
|
||||
userMessage: input.userMessage,
|
||||
payload: input.payload,
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
|
|
@ -98,18 +104,14 @@ export async function runAssistantDeepTurnAttemptRuntime<ResponseType = Assistan
|
|||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
buildFollowupStateBinding: input.buildFollowupStateBinding,
|
||||
normalize: input.normalize
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const followupBinding = normalizationRuntime.followupBinding;
|
||||
const normalized = normalizationRuntime.normalized;
|
||||
|
||||
const deepTurnAnalysisRuntime = await runDeepTurnAnalysisAttemptRuntimeSafe({
|
||||
const deepTurnAnalysisRuntime = await runDeepTurnAnalysisAttemptRuntimeSafe(
|
||||
buildAssistantDeepTurnAnalysisAttemptRuntimeInput({
|
||||
userMessage: input.userMessage,
|
||||
normalizedPayload: normalized.normalized,
|
||||
routeSummary: normalized.route_hint_summary,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupUsage: followupBinding.usage,
|
||||
investigationState: input.sessionInvestigationState,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
featureProblemCentricAnswerV1: input.featureProblemCentricAnswerV1,
|
||||
featureLifecycleAnswerV1: input.featureLifecycleAnswerV1,
|
||||
|
|
@ -127,28 +129,21 @@ export async function runAssistantDeepTurnAttemptRuntime<ResponseType = Assistan
|
|||
checkGrounding: input.checkGrounding,
|
||||
collectRbpLiveRouteAudit: input.collectRbpLiveRouteAudit,
|
||||
collectFaLiveRouteAudit: input.collectFaLiveRouteAudit,
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor
|
||||
});
|
||||
hasExplicitPeriodAnchor: input.hasExplicitPeriodAnchor,
|
||||
normalizationRuntime
|
||||
})
|
||||
);
|
||||
|
||||
const deepTurnResponseRuntime = runDeepTurnResponseAttemptRuntimeSafe({
|
||||
const deepTurnResponseRuntime = runDeepTurnResponseAttemptRuntimeSafe(
|
||||
buildAssistantDeepTurnResponseAttemptRuntimeInput({
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: {
|
||||
trace_id: normalized.trace_id,
|
||||
prompt_version: normalized.prompt_version,
|
||||
schema_version: normalized.schema_version,
|
||||
normalized: normalized.normalized
|
||||
},
|
||||
normalizedQuestion: followupBinding.normalizedQuestion,
|
||||
deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
followupStateUsage: followupBinding.usage,
|
||||
followupApplied: Boolean((followupBinding.usage as { applied?: unknown } | null)?.applied),
|
||||
previousInvestigationState: input.sessionInvestigationState,
|
||||
sessionInvestigationState: input.sessionInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
|
|
@ -162,8 +157,11 @@ export async function runAssistantDeepTurnAttemptRuntime<ResponseType = Assistan
|
|||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
});
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn,
|
||||
normalizationRuntime,
|
||||
deepTurnAnalysisRuntime
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
response: deepTurnResponseRuntime.response,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
type RunAssistantDeepTurnResponseRuntimeInput,
|
||||
type RunAssistantDeepTurnResponseRuntimeOutput
|
||||
} from "./assistantDeepTurnResponseRuntimeAdapter";
|
||||
import { buildAssistantDeepTurnResponseRuntimeInput } from "./assistantDeepTurnResponseRuntimeInputBuilder";
|
||||
|
||||
export interface RunAssistantDeepTurnResponseAttemptRuntimeInput<
|
||||
ResponseType = AssistantMessageResponsePayload
|
||||
|
|
@ -58,8 +59,8 @@ export function runAssistantDeepTurnResponseAttemptRuntime<
|
|||
} {
|
||||
const runDeepTurnResponseRuntimeSafe =
|
||||
input.runDeepTurnResponseRuntime ?? runAssistantDeepTurnResponseRuntime;
|
||||
const analysis = input.deepTurnAnalysisRuntime;
|
||||
const responseRuntime = runDeepTurnResponseRuntimeSafe({
|
||||
const responseRuntime = runDeepTurnResponseRuntimeSafe(
|
||||
buildAssistantDeepTurnResponseRuntimeInput({
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
|
|
@ -68,31 +69,11 @@ export function runAssistantDeepTurnResponseAttemptRuntime<
|
|||
userMessage: input.userMessage,
|
||||
normalized: input.normalized,
|
||||
normalizedQuestion: input.normalizedQuestion,
|
||||
routeSummary: analysis.resolvedRouteSummary,
|
||||
executionPlan: analysis.executionPlan,
|
||||
requirementExtractionRequirements: analysis.requirementExtraction.requirements,
|
||||
coverageEvaluationRequirements: analysis.coverageEvaluation.requirements,
|
||||
coverageReport: analysis.coverageEvaluation.coverage,
|
||||
groundingCheck: analysis.groundingCheck,
|
||||
retrievalCalls: analysis.retrievalCalls,
|
||||
retrievalResultsRaw: analysis.retrievalResultsRaw,
|
||||
retrievalResults: analysis.retrievalResults,
|
||||
questionTypeClass: analysis.questionTypeClass,
|
||||
companyAnchors: analysis.companyAnchors,
|
||||
deepTurnAnalysisRuntime: input.deepTurnAnalysisRuntime,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
businessScopeResolution: analysis.businessScopeResolution,
|
||||
temporalGuard: analysis.temporalGuard,
|
||||
polarityAudit: analysis.polarityGuardResult.audit,
|
||||
claimAnchorAudit: analysis.claimAnchorAudit,
|
||||
targetedEvidenceAudit: analysis.targetedEvidenceResult.audit,
|
||||
evidenceAdmissibilityGateAudit: analysis.evidenceGateResult.audit,
|
||||
rbpLiveRouteAudit: analysis.rbpLiveRouteAudit,
|
||||
faLiveRouteAudit: analysis.faLiveRouteAudit,
|
||||
groundedAnswerEligibilityGuard: analysis.groundedAnswerEligibilityGuard,
|
||||
followupStateUsage: input.followupStateUsage,
|
||||
followupApplied: input.followupApplied,
|
||||
composition: analysis.composition as any,
|
||||
previousInvestigationState: input.previousInvestigationState ?? null,
|
||||
previousInvestigationState: input.previousInvestigationState,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
|
|
@ -107,7 +88,8 @@ export function runAssistantDeepTurnResponseAttemptRuntime<
|
|||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
response: responseRuntime.response as ResponseType,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
import type { RunAssistantDeepTurnAnalysisRuntimeOutput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
|
||||
import type { RunAssistantDeepTurnResponseRuntimeInput } from "./assistantDeepTurnResponseRuntimeAdapter";
|
||||
|
||||
export interface BuildAssistantDeepTurnResponseRuntimeInputInput {
|
||||
featureInvestigationStateV1: boolean;
|
||||
featureContractsV11: boolean;
|
||||
featureAnswerPolicyV11: boolean;
|
||||
sessionId: string;
|
||||
questionId: string;
|
||||
userMessage: string;
|
||||
normalized: RunAssistantDeepTurnResponseRuntimeInput["normalized"];
|
||||
normalizedQuestion: string;
|
||||
deepTurnAnalysisRuntime: RunAssistantDeepTurnAnalysisRuntimeOutput;
|
||||
runtimeAnalysisContext: RunAssistantDeepTurnResponseRuntimeInput["runtimeAnalysisContext"];
|
||||
followupStateUsage: RunAssistantDeepTurnResponseRuntimeInput["followupStateUsage"];
|
||||
followupApplied: boolean;
|
||||
previousInvestigationState: RunAssistantDeepTurnResponseRuntimeInput["previousInvestigationState"];
|
||||
addressRuntimeMetaForDeep: RunAssistantDeepTurnResponseRuntimeInput["addressRuntimeMetaForDeep"];
|
||||
extractDroppedIntentSegments: RunAssistantDeepTurnResponseRuntimeInput["extractDroppedIntentSegments"];
|
||||
buildDebugRoutes: RunAssistantDeepTurnResponseRuntimeInput["buildDebugRoutes"];
|
||||
extractExecutionState: RunAssistantDeepTurnResponseRuntimeInput["extractExecutionState"];
|
||||
sanitizeReply: RunAssistantDeepTurnResponseRuntimeInput["sanitizeReply"];
|
||||
persistInvestigationState: RunAssistantDeepTurnResponseRuntimeInput["persistInvestigationState"];
|
||||
messageIdFactory: RunAssistantDeepTurnResponseRuntimeInput["messageIdFactory"];
|
||||
appendItem: RunAssistantDeepTurnResponseRuntimeInput["appendItem"];
|
||||
getSession: RunAssistantDeepTurnResponseRuntimeInput["getSession"];
|
||||
persistSession: RunAssistantDeepTurnResponseRuntimeInput["persistSession"];
|
||||
cloneConversation: RunAssistantDeepTurnResponseRuntimeInput["cloneConversation"];
|
||||
logEvent: RunAssistantDeepTurnResponseRuntimeInput["logEvent"];
|
||||
runPackagingRuntime?: RunAssistantDeepTurnResponseRuntimeInput["runPackagingRuntime"];
|
||||
runFinalizeDeepTurn?: RunAssistantDeepTurnResponseRuntimeInput["runFinalizeDeepTurn"];
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnResponseRuntimeInput(
|
||||
input: BuildAssistantDeepTurnResponseRuntimeInputInput
|
||||
): RunAssistantDeepTurnResponseRuntimeInput {
|
||||
const analysis = input.deepTurnAnalysisRuntime;
|
||||
return {
|
||||
featureInvestigationStateV1: input.featureInvestigationStateV1,
|
||||
featureContractsV11: input.featureContractsV11,
|
||||
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
|
||||
sessionId: input.sessionId,
|
||||
questionId: input.questionId,
|
||||
userMessage: input.userMessage,
|
||||
normalized: input.normalized,
|
||||
normalizedQuestion: input.normalizedQuestion,
|
||||
routeSummary: analysis.resolvedRouteSummary,
|
||||
executionPlan: analysis.executionPlan,
|
||||
requirementExtractionRequirements: analysis.requirementExtraction.requirements,
|
||||
coverageEvaluationRequirements: analysis.coverageEvaluation.requirements,
|
||||
coverageReport: analysis.coverageEvaluation.coverage,
|
||||
groundingCheck: analysis.groundingCheck,
|
||||
retrievalCalls: analysis.retrievalCalls,
|
||||
retrievalResultsRaw: analysis.retrievalResultsRaw,
|
||||
retrievalResults: analysis.retrievalResults,
|
||||
questionTypeClass: analysis.questionTypeClass,
|
||||
companyAnchors: analysis.companyAnchors,
|
||||
runtimeAnalysisContext: input.runtimeAnalysisContext,
|
||||
businessScopeResolution: analysis.businessScopeResolution,
|
||||
temporalGuard: analysis.temporalGuard,
|
||||
polarityAudit: analysis.polarityGuardResult.audit,
|
||||
claimAnchorAudit: analysis.claimAnchorAudit,
|
||||
targetedEvidenceAudit: analysis.targetedEvidenceResult.audit,
|
||||
evidenceAdmissibilityGateAudit: analysis.evidenceGateResult.audit,
|
||||
rbpLiveRouteAudit: analysis.rbpLiveRouteAudit,
|
||||
faLiveRouteAudit: analysis.faLiveRouteAudit,
|
||||
groundedAnswerEligibilityGuard: analysis.groundedAnswerEligibilityGuard,
|
||||
followupStateUsage: input.followupStateUsage,
|
||||
followupApplied: input.followupApplied,
|
||||
composition: analysis.composition as any,
|
||||
previousInvestigationState: input.previousInvestigationState ?? null,
|
||||
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
|
||||
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
|
||||
buildDebugRoutes: input.buildDebugRoutes,
|
||||
extractExecutionState: input.extractExecutionState,
|
||||
sanitizeReply: input.sanitizeReply,
|
||||
persistInvestigationState: input.persistInvestigationState,
|
||||
messageIdFactory: input.messageIdFactory,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
runPackagingRuntime: input.runPackagingRuntime,
|
||||
runFinalizeDeepTurn: input.runFinalizeDeepTurn
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { buildAssistantDeepTurnAnalysisRuntimeInput } from "../src/services/assistantDeepTurnAnalysisAttemptInputBuilder";
|
||||
|
||||
function buildInput(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
userMessage: "why debt not closed",
|
||||
normalizedPayload: { fragments: [] },
|
||||
routeSummary: { mode: "deterministic_v2", decisions: [] },
|
||||
runtimeAnalysisContext: {
|
||||
active: true,
|
||||
as_of_date: "2020-07-31",
|
||||
period_from: null,
|
||||
period_to: null,
|
||||
source: "analysis_context"
|
||||
},
|
||||
followupUsage: { applied: true },
|
||||
investigationState: { session_id: "asst-1" },
|
||||
featureAnswerPolicyV11: true,
|
||||
featureProblemCentricAnswerV1: true,
|
||||
featureLifecycleAnswerV1: true,
|
||||
resolveBusinessScopeAlignment: vi.fn(() => ({ route_summary_resolved: { mode: "deterministic_v2", decisions: [] } })),
|
||||
inferP0DomainFromMessage: vi.fn(() => "settlements_60_62"),
|
||||
resolveBusinessScopeFromLiveContext: vi.fn(({ current }) => current),
|
||||
extractRequirements: vi.fn(() => ({ requirements: [{ id: "R1" }], byFragment: new Map([["F1", ["R1"]]]) })),
|
||||
toExecutionPlan: vi.fn(() => [{ fragment_id: "F1", requirement_ids: ["R1"], route: "store_canonical", should_execute: true }]),
|
||||
enforceRbpLiveRoutePlan: vi.fn(({ executionPlan }) => ({ executionPlan, audit: { rbp: true } })),
|
||||
enforceFaLiveRoutePlan: vi.fn(({ executionPlan }) => ({ executionPlan, audit: { fa: true } })),
|
||||
executeRouteRuntime: vi.fn(async () => ({})),
|
||||
mapNoRouteReason: vi.fn(() => "skipped"),
|
||||
buildSkippedResult: vi.fn(() => ({ status: "skipped" })),
|
||||
evaluateCoverage: vi.fn(() => ({ requirements: [{ id: "R1" }], coverage: {} })),
|
||||
checkGrounding: vi.fn(() => ({ status: "grounded", reasons: [] })),
|
||||
collectRbpLiveRouteAudit: vi.fn(() => ({ routed: 1 })),
|
||||
collectFaLiveRouteAudit: vi.fn(() => ({ routed: 1 })),
|
||||
hasExplicitPeriodAnchor: vi.fn(() => false),
|
||||
runDeepTurnContextRuntimeSafe: vi.fn(() => ({ context: true })),
|
||||
runDeepTurnPlanRuntimeSafe: vi.fn(() => ({ plan: true })),
|
||||
runDeepTurnRetrievalRuntimeSafe: vi.fn(async () => ({ retrieval: true })),
|
||||
runDeepTurnGuardRuntimeSafe: vi.fn(() => ({ guard: true })),
|
||||
runDeepTurnGroundingRuntimeSafe: vi.fn(() => ({ grounding: true })),
|
||||
runDeepTurnCompositionRuntimeSafe: vi.fn(() => ({ composition: true })),
|
||||
...overrides
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("assistant deep turn analysis attempt input builder", () => {
|
||||
it("builds analysis runtime callbacks and delegates stage payload mapping", async () => {
|
||||
const input = buildInput();
|
||||
const runtimeInput = buildAssistantDeepTurnAnalysisRuntimeInput(input);
|
||||
|
||||
runtimeInput.runContextRuntime();
|
||||
runtimeInput.runExecutionPlanRuntime({
|
||||
resolvedRouteSummary: { mode: "deterministic_v2", decisions: [] } as any,
|
||||
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" } as any,
|
||||
temporalGuard: { primary_period_window: {} },
|
||||
domainPolarityGuardInitial: { polarity: "supplier_payable" }
|
||||
});
|
||||
await runtimeInput.runRetrievalRuntime({
|
||||
executionPlan: [{ fragment_id: "F1", route: "store_canonical" }],
|
||||
liveTemporalHint: { as_of_date: "2020-07-31", period_from: null, period_to: null, source: "analysis_context" }
|
||||
} as any);
|
||||
runtimeInput.runGuardRuntime({
|
||||
retrievalResults: [],
|
||||
domainPolarityGuardInitial: { polarity: "supplier_payable" },
|
||||
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" },
|
||||
temporalGuard: { primary_period_window: {} },
|
||||
focusDomainForGuards: "settlements_60_62",
|
||||
companyAnchors: { accounts: ["60.01"] },
|
||||
userMessage: "runtime-user-message"
|
||||
} as any);
|
||||
runtimeInput.runGroundingRuntime({
|
||||
claimType: "prove_settlement_closure_state",
|
||||
retrievalResults: [],
|
||||
rbpPlanAudit: { rbp: true },
|
||||
faPlanAudit: { fa: true },
|
||||
routeSummary: { mode: "deterministic_v2", decisions: [] },
|
||||
requirementExtraction: { requirements: [{ id: "R1" }], byFragment: new Map([["F1", ["R1"]]]) },
|
||||
temporalGuard: { primary_period_window: {} },
|
||||
polarityAudit: { polarity: "supplier_payable" },
|
||||
evidenceAudit: { admissible_evidence_count: 1 },
|
||||
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" },
|
||||
targetedEvidenceHitRate: 1,
|
||||
businessScopeResolved: ["company_specific_accounting"]
|
||||
} as any);
|
||||
runtimeInput.runCompositionRuntime({
|
||||
resolvedRouteSummary: { mode: "deterministic_v2", decisions: [] },
|
||||
retrievalResults: [],
|
||||
requirements: [{ id: "R1" }],
|
||||
coverageReport: { requirements_total: 1, requirements_covered: 1 },
|
||||
groundingCheck: { status: "grounded", reasons: [] },
|
||||
companyAnchors: { accounts: ["60.01"] }
|
||||
} as any);
|
||||
|
||||
expect(input.runDeepTurnContextRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
userMessage: "why debt not closed",
|
||||
runtimeAnalysisContext: expect.objectContaining({ as_of_date: "2020-07-31" }),
|
||||
resolveCompanyAnchors: expect.any(Function)
|
||||
})
|
||||
);
|
||||
expect(input.runDeepTurnPlanRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
claimType: "prove_settlement_closure_state",
|
||||
userMessage: "why debt not closed"
|
||||
})
|
||||
);
|
||||
expect(input.runDeepTurnRetrievalRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
executeRouteRuntime: input.executeRouteRuntime,
|
||||
mapNoRouteReason: input.mapNoRouteReason
|
||||
})
|
||||
);
|
||||
expect(input.runDeepTurnGuardRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
userMessage: "runtime-user-message",
|
||||
focusDomainForGuards: "settlements_60_62"
|
||||
})
|
||||
);
|
||||
expect(input.runDeepTurnGroundingRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
normalizedPayload: { fragments: [] },
|
||||
userMessage: "why debt not closed",
|
||||
targetedEvidenceHitRate: 1
|
||||
})
|
||||
);
|
||||
expect(input.runDeepTurnCompositionRuntimeSafe).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
userMessage: "why debt not closed",
|
||||
featureAnswerPolicyV11: true,
|
||||
featureProblemCentricAnswerV1: true,
|
||||
featureLifecycleAnswerV1: true
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildAssistantDeepTurnAnalysisAttemptRuntimeInput,
|
||||
buildAssistantDeepTurnNormalizationRuntimeInput,
|
||||
buildAssistantDeepTurnResponseAttemptRuntimeInput
|
||||
} from "../src/services/assistantDeepTurnAttemptInputBuilder";
|
||||
|
||||
function buildNormalizationRuntime(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
followupBinding: {
|
||||
normalizedQuestion: "normalized-question",
|
||||
mergedContext: {},
|
||||
usage: { applied: true }
|
||||
},
|
||||
normalizePayload: {
|
||||
userQuestion: "normalized-question"
|
||||
},
|
||||
normalized: {
|
||||
trace_id: "trace-1",
|
||||
prompt_version: "normalizer_v2_0_2",
|
||||
schema_version: "normalized_query_v2_0_2",
|
||||
normalized: { fragments: [] },
|
||||
route_hint_summary: { mode: "deterministic_v2", decisions: [] }
|
||||
},
|
||||
...overrides
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("assistant deep turn attempt input builder", () => {
|
||||
it("builds normalization runtime input from turn fields", () => {
|
||||
const normalize = vi.fn(async () => ({}));
|
||||
const runtimeInput = buildAssistantDeepTurnNormalizationRuntimeInput({
|
||||
userMessage: "why debt not closed",
|
||||
payload: { llmProvider: "openai", context: {} } as any,
|
||||
featureInvestigationStateV1: true,
|
||||
featureStateFollowupBindingV1: true,
|
||||
sessionInvestigationState: { session_id: "asst-1" },
|
||||
buildFollowupStateBinding: vi.fn(() => ({
|
||||
normalizedQuestion: "normalized",
|
||||
mergedContext: {},
|
||||
usage: null
|
||||
})),
|
||||
normalize
|
||||
});
|
||||
|
||||
expect(runtimeInput.userMessage).toBe("why debt not closed");
|
||||
expect(runtimeInput.normalize).toBe(normalize);
|
||||
expect(runtimeInput.featureInvestigationStateV1).toBe(true);
|
||||
expect(runtimeInput.featureStateFollowupBindingV1).toBe(true);
|
||||
});
|
||||
|
||||
it("builds analysis and response attempt inputs from normalization runtime", () => {
|
||||
const normalizationRuntime = buildNormalizationRuntime();
|
||||
const deepTurnAnalysisRuntime = {
|
||||
composition: { reply_type: "partial_coverage" }
|
||||
} as any;
|
||||
|
||||
const analysisInput = buildAssistantDeepTurnAnalysisAttemptRuntimeInput({
|
||||
userMessage: "why debt not closed",
|
||||
runtimeAnalysisContext: { active: true, as_of_date: "2020-07-31", period_from: null, period_to: null, source: "analysis_context" },
|
||||
sessionInvestigationState: { session_id: "asst-1" } as any,
|
||||
featureAnswerPolicyV11: true,
|
||||
featureProblemCentricAnswerV1: true,
|
||||
featureLifecycleAnswerV1: true,
|
||||
resolveBusinessScopeAlignment: vi.fn(),
|
||||
inferP0DomainFromMessage: vi.fn(),
|
||||
resolveBusinessScopeFromLiveContext: vi.fn(),
|
||||
extractRequirements: vi.fn(),
|
||||
toExecutionPlan: vi.fn(),
|
||||
enforceRbpLiveRoutePlan: vi.fn(),
|
||||
enforceFaLiveRoutePlan: vi.fn(),
|
||||
executeRouteRuntime: vi.fn(),
|
||||
mapNoRouteReason: vi.fn(),
|
||||
buildSkippedResult: vi.fn(),
|
||||
evaluateCoverage: vi.fn(),
|
||||
checkGrounding: vi.fn(),
|
||||
collectRbpLiveRouteAudit: vi.fn(),
|
||||
collectFaLiveRouteAudit: vi.fn(),
|
||||
hasExplicitPeriodAnchor: vi.fn(),
|
||||
normalizationRuntime
|
||||
});
|
||||
const responseInput = buildAssistantDeepTurnResponseAttemptRuntimeInput({
|
||||
featureInvestigationStateV1: true,
|
||||
featureContractsV11: true,
|
||||
featureAnswerPolicyV11: true,
|
||||
sessionId: "asst-1",
|
||||
questionId: "msg-q1",
|
||||
userMessage: "why debt not closed",
|
||||
runtimeAnalysisContext: { as_of_date: "2020-07-31" } as any,
|
||||
sessionInvestigationState: { session_id: "asst-1" } as any,
|
||||
addressRuntimeMetaForDeep: null,
|
||||
extractDroppedIntentSegments: vi.fn(() => []),
|
||||
buildDebugRoutes: vi.fn(() => []),
|
||||
extractExecutionState: vi.fn(() => []),
|
||||
sanitizeReply: vi.fn((value: string) => value),
|
||||
persistInvestigationState: vi.fn(),
|
||||
messageIdFactory: vi.fn(() => "msg-a1"),
|
||||
appendItem: vi.fn(),
|
||||
getSession: vi.fn(),
|
||||
persistSession: vi.fn(),
|
||||
cloneConversation: vi.fn((items: unknown[]) => items),
|
||||
logEvent: vi.fn(),
|
||||
normalizationRuntime,
|
||||
deepTurnAnalysisRuntime
|
||||
});
|
||||
|
||||
expect(analysisInput.normalizedPayload).toEqual({ fragments: [] });
|
||||
expect(analysisInput.routeSummary).toEqual({ mode: "deterministic_v2", decisions: [] });
|
||||
expect(analysisInput.followupUsage).toEqual({ applied: true });
|
||||
expect(responseInput.normalizedQuestion).toBe("normalized-question");
|
||||
expect(responseInput.normalized.trace_id).toBe("trace-1");
|
||||
expect(responseInput.followupApplied).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { buildAssistantDeepTurnResponseRuntimeInput } from "../src/services/assistantDeepTurnResponseRuntimeInputBuilder";
|
||||
|
||||
function buildDeepRuntime() {
|
||||
return {
|
||||
companyAnchors: { accounts: ["60.01"] },
|
||||
temporalGuard: { primary_period_window: { from: "2020-07-01", to: "2020-07-31" } },
|
||||
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" },
|
||||
businessScopeResolution: { business_scope_resolved: ["company_specific_accounting"] },
|
||||
resolvedRouteSummary: { mode: "deterministic_v2", decisions: [] as any[] },
|
||||
requirementExtraction: {
|
||||
requirements: [{ id: "R1" }],
|
||||
byFragment: new Map<string, string[]>([["F1", ["R1"]]])
|
||||
},
|
||||
executionPlan: [{ fragment_id: "F1", route: "store_canonical" }],
|
||||
retrievalCalls: [{ fragment_id: "F1", route: "store_canonical" }],
|
||||
retrievalResultsRaw: [{ fragment_id: "F1", route: "store_canonical", raw_result: {} }],
|
||||
retrievalResults: [{ fragment_id: "F1", requirement_ids: ["R1"] }],
|
||||
polarityGuardResult: { audit: { polarity: "supplier_payable" } },
|
||||
targetedEvidenceResult: { audit: { targeted_evidence_hit_rate: 1 } },
|
||||
evidenceGateResult: { audit: { admissible_evidence_count: 2 } },
|
||||
rbpLiveRouteAudit: { routed: 1 },
|
||||
faLiveRouteAudit: { routed: 1 },
|
||||
coverageEvaluation: {
|
||||
requirements: [{ id: "R1" }],
|
||||
coverage: { requirements_total: 1, requirements_covered: 1 }
|
||||
},
|
||||
groundedAnswerEligibilityGuard: { eligible: true },
|
||||
groundingCheck: { status: "grounded", reasons: [] },
|
||||
questionTypeClass: "causal_trace",
|
||||
composition: { reply_type: "factual_with_explanation", assistant_reply: "ok" }
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("assistant deep turn response runtime input builder", () => {
|
||||
it("maps analysis runtime into response runtime contract", () => {
|
||||
const runtimeInput = buildAssistantDeepTurnResponseRuntimeInput({
|
||||
featureInvestigationStateV1: true,
|
||||
featureContractsV11: true,
|
||||
featureAnswerPolicyV11: true,
|
||||
sessionId: "asst-1",
|
||||
questionId: "msg-q1",
|
||||
userMessage: "why debt not closed",
|
||||
normalized: {
|
||||
trace_id: "trace-1",
|
||||
prompt_version: "normalizer_v2_0_2",
|
||||
schema_version: "normalized_query_v2_0_2",
|
||||
normalized: { fragments: [] }
|
||||
},
|
||||
normalizedQuestion: "normalized-question",
|
||||
deepTurnAnalysisRuntime: buildDeepRuntime(),
|
||||
runtimeAnalysisContext: { as_of_date: "2020-07-31" },
|
||||
followupStateUsage: { applied: true },
|
||||
followupApplied: true,
|
||||
previousInvestigationState: null,
|
||||
addressRuntimeMetaForDeep: null,
|
||||
extractDroppedIntentSegments: vi.fn(() => []),
|
||||
buildDebugRoutes: vi.fn(() => []),
|
||||
extractExecutionState: vi.fn(() => []),
|
||||
sanitizeReply: vi.fn((value: string) => value),
|
||||
persistInvestigationState: vi.fn(),
|
||||
messageIdFactory: vi.fn(() => "msg-a1"),
|
||||
appendItem: vi.fn(),
|
||||
getSession: vi.fn(),
|
||||
persistSession: vi.fn(),
|
||||
cloneConversation: vi.fn((items: unknown[]) => items),
|
||||
logEvent: vi.fn()
|
||||
});
|
||||
|
||||
expect(runtimeInput.routeSummary).toEqual({ mode: "deterministic_v2", decisions: [] });
|
||||
expect(runtimeInput.requirementExtractionRequirements).toEqual([{ id: "R1" }]);
|
||||
expect(runtimeInput.coverageEvaluationRequirements).toEqual([{ id: "R1" }]);
|
||||
expect(runtimeInput.questionTypeClass).toBe("causal_trace");
|
||||
expect(runtimeInput.polarityAudit).toEqual({ polarity: "supplier_payable" });
|
||||
expect(runtimeInput.targetedEvidenceAudit).toEqual({ targeted_evidence_hit_rate: 1 });
|
||||
expect(runtimeInput.evidenceAdmissibilityGateAudit).toEqual({ admissible_evidence_count: 2 });
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue