ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.2 - Усилена оркестрацию в deep/address гейте и follow-up binding в assistantService.ts. Починен кейс UTF-8 follow-up refinement (теперь followup_state_usage.applied=true в нужном сценарии). Убраны регрессии по assistantLivingRouter и stage3 lifecycle probe. Корректное поведение для llm canonical candidate (чтобы не уезжало в clarification_required там, где должен быть address factual).
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
import type {
|
||||
AssistantAddressRuntimeMetaForDeep,
|
||||
AssistantConversationItem,
|
||||
AssistantDebugPayload,
|
||||
AssistantDebugRouteRecord,
|
||||
AssistantExecutionStateRecord,
|
||||
AssistantFallbackType,
|
||||
AssistantProblemAnswerMode,
|
||||
AssistantReplyType,
|
||||
AssistantRequirement,
|
||||
AnswerGroundingCheck,
|
||||
FaLiveRouteAuditDebug,
|
||||
RbpLiveRouteAuditDebug,
|
||||
RequirementCoverageReport,
|
||||
UnifiedRetrievalResult
|
||||
} from "../types/assistant";
|
||||
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
|
||||
import type {
|
||||
NormalizeResponsePayload,
|
||||
NormalizedQueryV2,
|
||||
NormalizedQueryV2_0_1,
|
||||
NormalizedQueryV2_0_2,
|
||||
RouteHintSummary
|
||||
} from "../types/normalizer";
|
||||
import type { AnswerStructureV11 } from "../types/stage1Contracts";
|
||||
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
|
||||
import {
|
||||
assembleAssistantEvidenceBundle,
|
||||
type AssistantEvidenceBundleAssembly
|
||||
@@ -16,8 +30,23 @@ import {
|
||||
import { assembleAssistantContractsBundleV1, type AssistantContractsBundleV1 } from "./assistantContractsBundleAssembler";
|
||||
import { buildDeepAnswerArtifacts, buildAssistantConversationItem, type DeepAnswerArtifacts } from "./assistantDeepResponseAssembler";
|
||||
import { buildDeepAnalysisDebugPayload } from "./assistantDebugPayloadAssembler";
|
||||
import { buildDeepAnalysisProcessedLogDetails } from "./assistantMessageLogAssembler";
|
||||
import {
|
||||
buildDeepAnalysisProcessedLogDetails,
|
||||
type DeepAnalysisLogDetails
|
||||
} from "./assistantMessageLogAssembler";
|
||||
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 AssistantDeepTurnPackagingInput {
|
||||
sessionId: string;
|
||||
@@ -51,13 +80,13 @@ export interface AssistantDeepTurnPackagingInput {
|
||||
coverageEvaluationRequirements: AssistantRequirement[];
|
||||
coverageReport: RequirementCoverageReport;
|
||||
groundingCheck: AnswerGroundingCheck;
|
||||
retrievalCalls: Array<Record<string, unknown>>;
|
||||
retrievalResultsRaw: unknown[];
|
||||
retrievalCalls: AssistantRetrievalCallRecord[];
|
||||
retrievalResultsRaw: AssistantRetrievalRawResultRecord[];
|
||||
retrievalResults: UnifiedRetrievalResult[];
|
||||
routesForDebug: Array<Record<string, unknown>>;
|
||||
resolvedExecutionState: unknown;
|
||||
routesForDebug: AssistantDebugRouteRecord[];
|
||||
resolvedExecutionState: AssistantExecutionStateRecord[];
|
||||
questionTypeClass: string;
|
||||
companyAnchors: unknown;
|
||||
companyAnchors: CompanyAnchorSet | null;
|
||||
runtimeAnalysisContext: {
|
||||
active: boolean;
|
||||
as_of_date: string | null;
|
||||
@@ -72,42 +101,29 @@ export interface AssistantDeepTurnPackagingInput {
|
||||
company_grounding_applied?: boolean;
|
||||
scope_resolution_reason?: string[];
|
||||
};
|
||||
temporalGuard: Record<string, unknown>;
|
||||
polarityAudit: Record<string, unknown>;
|
||||
claimAnchorAudit: Record<string, unknown>;
|
||||
targetedEvidenceAudit: unknown;
|
||||
evidenceAdmissibilityGateAudit: unknown;
|
||||
rbpLiveRouteAudit: unknown | null;
|
||||
faLiveRouteAudit: unknown | null;
|
||||
groundedAnswerEligibilityGuard: Record<string, unknown>;
|
||||
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: unknown;
|
||||
fallback_type: AssistantFallbackType;
|
||||
answer_structure_v11?: AnswerStructureV11 | null;
|
||||
problem_centric_answer_applied?: boolean;
|
||||
problem_units_used_count?: number;
|
||||
problem_answer_mode?: string;
|
||||
problem_answer_mode?: AssistantProblemAnswerMode;
|
||||
problem_unit_ids_used?: string[];
|
||||
};
|
||||
safeAssistantReplyBase: string;
|
||||
featureContractsV11: boolean;
|
||||
featureAnswerPolicyV11: boolean;
|
||||
investigationStateSnapshot: unknown;
|
||||
addressRuntimeMetaForDeep:
|
||||
| {
|
||||
attempted?: boolean;
|
||||
applied?: boolean;
|
||||
reason?: string | null;
|
||||
provider?: string | null;
|
||||
fallbackRuleHit?: string | null;
|
||||
toolGateDecision?: string | null;
|
||||
toolGateReason?: string | null;
|
||||
predecomposeContract?: unknown;
|
||||
orchestrationContract?: unknown;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
investigationStateSnapshot: InvestigationStateWithProblemUnits | null;
|
||||
addressRuntimeMetaForDeep: AssistantAddressRuntimeMetaForDeep | null | undefined;
|
||||
}
|
||||
|
||||
export interface AssistantDeepTurnPackagingOutput {
|
||||
@@ -116,12 +132,25 @@ export interface AssistantDeepTurnPackagingOutput {
|
||||
deepAnswerArtifacts: DeepAnswerArtifacts;
|
||||
debug: AssistantDebugPayload;
|
||||
assistantItem: AssistantConversationItem;
|
||||
deepAnalysisLogDetails: Record<string, unknown>;
|
||||
deepAnalysisLogDetails: DeepAnalysisLogDetails;
|
||||
}
|
||||
|
||||
type NormalizedFragments =
|
||||
| NormalizedQueryV2["fragments"]
|
||||
| NormalizedQueryV2_0_1["fragments"]
|
||||
| NormalizedQueryV2_0_2["fragments"];
|
||||
|
||||
function extractNormalizedFragments(normalized: NormalizeResponsePayload["normalized"] | null): NormalizedFragments {
|
||||
if (!normalized || typeof normalized !== "object") {
|
||||
return [];
|
||||
}
|
||||
const source = normalized as NormalizedQueryV2 | NormalizedQueryV2_0_1 | NormalizedQueryV2_0_2;
|
||||
return Array.isArray(source.fragments) ? source.fragments : [];
|
||||
}
|
||||
|
||||
export function assembleAssistantDeepTurnPackaging(input: AssistantDeepTurnPackagingInput): AssistantDeepTurnPackagingOutput {
|
||||
const normalizedPayload = (input.normalized.normalized ?? null) as Record<string, unknown> | null;
|
||||
const normalizedFragments = Array.isArray(normalizedPayload?.["fragments"]) ? (normalizedPayload?.["fragments"] as unknown[]) : [];
|
||||
const normalizedPayload = input.normalized.normalized ?? null;
|
||||
const normalizedFragments = extractNormalizedFragments(normalizedPayload);
|
||||
const evidenceBundleAssembly = assembleAssistantEvidenceBundle({
|
||||
retrievalCalls: input.retrievalCalls,
|
||||
retrievalResults: input.retrievalResults
|
||||
@@ -232,7 +261,7 @@ export function assembleAssistantDeepTurnPackaging(input: AssistantDeepTurnPacka
|
||||
problem_units_used_count: input.composition.problem_units_used_count ?? 0,
|
||||
problem_answer_mode: input.composition.problem_answer_mode ?? "stage1_policy_v11",
|
||||
problem_unit_ids_used: Array.isArray(input.composition.problem_unit_ids_used) ? input.composition.problem_unit_ids_used : [],
|
||||
fallback_type: input.composition.fallback_type as string
|
||||
fallback_type: input.composition.fallback_type
|
||||
},
|
||||
outcomeClassV1: contractsBundleV1.outcomeClassV1,
|
||||
assistantOrchestrationContractsV1: contractsBundleV1.assistantOrchestrationContractsV1,
|
||||
|
||||
Reference in New Issue
Block a user