ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.89 - 2.92 и 2.93 - 2.96 - Ужесточение deep-turn финализацию/response контракт debug до строго AssistantDebugPayload / Вынен общий контракт followup-usage и helper / Протянут typed followupUsage по deep-turn цепочке и убрал inline-cast проверки applied

This commit is contained in:
2026-04-11 11:07:56 +03:00
parent 966be04af9
commit 360b59d7c5
17 changed files with 95 additions and 20 deletions
@@ -35,6 +35,7 @@ import {
} from "./assistantDeepTurnCompositionRuntimeAdapter";
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
import { buildAssistantDeepTurnAnalysisRuntimeInput } from "./assistantDeepTurnAnalysisAttemptInputBuilder";
interface RuntimeAnalysisContextLike {
@@ -50,7 +51,7 @@ export interface RunAssistantDeepTurnAnalysisAttemptRuntimeInput {
normalizedPayload: NormalizeResponsePayload["normalized"];
routeSummary: RouteHintSummary | null;
runtimeAnalysisContext: RuntimeAnalysisContextLike;
followupUsage: unknown | null | undefined;
followupUsage: AssistantFollowupUsage | null | undefined;
investigationState: InvestigationStateWithProblemUnits | null | undefined;
featureAnswerPolicyV11: boolean;
featureProblemCentricAnswerV1: boolean;
@@ -5,6 +5,7 @@ import type {
import type { RunAssistantDeepTurnAnalysisAttemptRuntimeInput } from "./assistantDeepTurnAnalysisAttemptRuntimeAdapter";
import type { RunAssistantDeepTurnAnalysisRuntimeOutput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
import type { RunAssistantDeepTurnResponseAttemptRuntimeInput } from "./assistantDeepTurnResponseAttemptRuntimeAdapter";
import { isAssistantFollowupApplied } from "./assistantFollowupUsage";
export interface BuildAssistantDeepTurnNormalizationRuntimeInputInput {
userMessage: string;
@@ -134,9 +135,7 @@ export function buildAssistantDeepTurnResponseAttemptRuntimeInput<ResponseType =
deepTurnAnalysisRuntime: input.deepTurnAnalysisRuntime,
runtimeAnalysisContext: input.runtimeAnalysisContext,
followupStateUsage: input.normalizationRuntime.followupBinding.usage,
followupApplied: Boolean(
(input.normalizationRuntime.followupBinding.usage as { applied?: unknown } | null)?.applied
),
followupApplied: isAssistantFollowupApplied(input.normalizationRuntime.followupBinding.usage),
previousInvestigationState: input.sessionInvestigationState,
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
@@ -5,6 +5,7 @@ import type { QuestionTypeClass } from "./questionTypeResolver";
import { resolveQuestionType } from "./questionTypeResolver";
import { composeAssistantAnswer } from "./answerComposer";
import type { CompanyAnchorSet } from "./companyAnchorResolver";
import { isAssistantFollowupApplied, type AssistantFollowupUsage } from "./assistantFollowupUsage";
export interface BuildAssistantDeepTurnCompositionInput {
userMessage: string;
@@ -13,7 +14,7 @@ export interface BuildAssistantDeepTurnCompositionInput {
requirements: AssistantRequirement[];
coverageReport: RequirementCoverageReport;
groundingCheck: AnswerGroundingCheck;
followupUsage: unknown | null | undefined;
followupUsage: AssistantFollowupUsage | null | undefined;
investigationState: InvestigationStateWithProblemUnits | null | undefined;
companyAnchors: unknown;
normalizedPayload: NormalizeResponsePayload["normalized"];
@@ -65,7 +66,7 @@ export function buildAssistantDeepTurnComposition(
const resolveQuestionTypeSafe = input.resolveQuestionTypeFn ?? resolveQuestionType;
const composeAssistantAnswerSafe = input.composeAssistantAnswerFn ?? composeAssistantAnswer;
const followupApplied = Boolean((input.followupUsage as { applied?: unknown } | null)?.applied);
const followupApplied = isAssistantFollowupApplied(input.followupUsage);
const focusDomainHint = followupApplied
? input.investigationState?.followup_context?.active_domain ?? input.investigationState?.focus.domain ?? null
: null;
@@ -1,6 +1,7 @@
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
import type { ClaimBoundAnchorAudit } from "./assistantClaimBoundEvidence";
import type { AssistantLiveTemporalHint } from "./assistantDeepTurnRetrievalRuntimeAdapter";
import { isAssistantFollowupApplied, type AssistantFollowupUsage } from "./assistantFollowupUsage";
import type { DomainPolarityGuardAudit, TemporalGuardAudit } from "./assistantRuntimeGuards";
const KNOWN_P0_DOMAINS = new Set([
@@ -35,7 +36,7 @@ export interface BuildAssistantDeepTurnRuntimeContextInput {
period_to: string | null;
source: string | null;
};
followupUsage: unknown | null | undefined;
followupUsage: AssistantFollowupUsage | null | undefined;
resolveCompanyAnchors: (userMessage: string) => unknown;
resolveBusinessScopeAlignment: (input: {
userMessage: string;
@@ -138,7 +139,7 @@ export function buildAssistantDeepTurnRuntimeContext(
focusDomainHint: focusDomainForGuards,
userMessage: input.userMessage,
companyAnchors,
followupApplied: Boolean((input.followupUsage as { applied?: unknown } | null)?.applied)
followupApplied: isAssistantFollowupApplied(input.followupUsage)
});
const resolvedRouteSummary = businessScopeResolution.route_summary_resolved;
const liveTemporalHint = toAnalysisContext(input.runtimeAnalysisContext);
@@ -8,7 +8,7 @@ export interface FinalizeAssistantDeepTurnInput {
assistantReply: string;
replyType: AssistantReplyType;
assistantItem: AssistantConversationItem;
debug: AssistantDebugPayload | Record<string, unknown>;
debug: AssistantDebugPayload;
deepAnalysisLogDetails: Record<string, unknown>;
appendItem: Parameters<typeof commitAssistantTurnAndLog>[0]["appendItem"];
getSession: Parameters<typeof commitAssistantTurnAndLog>[0]["getSession"];
@@ -2,6 +2,7 @@ import type { AssistantReplyType, AssistantRequirement, AnswerGroundingCheck, Re
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
import type { AnswerStructureV11 } from "../types/stage1Contracts";
import type { AssistantDeepTurnPackagingInput } from "./assistantDeepTurnPackaging";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
export interface AssistantDeepTurnInputBuilderArgs {
sessionId: string;
@@ -64,7 +65,7 @@ export interface AssistantDeepTurnInputBuilderArgs {
rbpLiveRouteAudit: unknown | null;
faLiveRouteAudit: unknown | null;
groundedAnswerEligibilityGuard: Record<string, unknown>;
followupStateUsage?: unknown;
followupStateUsage?: AssistantFollowupUsage | null;
composition: {
reply_type: AssistantReplyType;
fallback_type: unknown;
@@ -1,10 +1,11 @@
import type { AssistantMessageRequestPayload } from "../types/assistant";
import type { NormalizeRequestPayload, NormalizeResponsePayload } from "../types/normalizer";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
export interface AssistantDeepTurnFollowupBinding {
normalizedQuestion: string;
mergedContext: NormalizeRequestPayload["context"] | undefined;
usage: unknown | null;
usage: AssistantFollowupUsage | null;
}
export interface BuildAssistantDeepTurnNormalizationRuntimeInput {
@@ -17,6 +17,7 @@ import { assembleAssistantContractsBundleV1, type AssistantContractsBundleV1 } f
import { buildDeepAnswerArtifacts, buildAssistantConversationItem, type DeepAnswerArtifacts } from "./assistantDeepResponseAssembler";
import { buildDeepAnalysisDebugPayload } from "./assistantDebugPayloadAssembler";
import { buildDeepAnalysisProcessedLogDetails } from "./assistantMessageLogAssembler";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
export interface AssistantDeepTurnPackagingInput {
sessionId: string;
@@ -79,7 +80,7 @@ export interface AssistantDeepTurnPackagingInput {
rbpLiveRouteAudit: unknown | null;
faLiveRouteAudit: unknown | null;
groundedAnswerEligibilityGuard: Record<string, unknown>;
followupStateUsage: unknown | null;
followupStateUsage: AssistantFollowupUsage | null;
composition: {
reply_type: AssistantReplyType;
fallback_type: unknown;
@@ -12,6 +12,7 @@ import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemU
import type { AssistantDeepTurnInputBuilderArgs } from "./assistantDeepTurnInputBuilder";
import { buildAssistantDeepTurnPackagingInput } from "./assistantDeepTurnInputBuilder";
import { assembleAssistantDeepTurnPackaging } from "./assistantDeepTurnPackaging";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
import type {
AssistantAnalysisContextForContract,
AssistantRuntimeAnalysisContextForPrePackaging
@@ -59,7 +60,7 @@ export interface AssistantDeepTurnPackagingRuntimeInput {
rbpLiveRouteAudit: unknown | null;
faLiveRouteAudit: unknown | null;
groundedAnswerEligibilityGuard: Record<string, unknown>;
followupStateUsage?: unknown;
followupStateUsage?: AssistantFollowupUsage | null;
followupApplied: boolean;
composition: AssistantDeepTurnCompositionForPackaging;
featureContractsV11: boolean;
@@ -2,6 +2,7 @@ import type { AssistantDebugPayload, AssistantMessageResponsePayload } from "../
import type { NormalizeResponsePayload } from "../types/normalizer";
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
import type { RunAssistantDeepTurnAnalysisRuntimeOutput } from "./assistantDeepTurnAnalysisRuntimeAdapter";
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
import {
runAssistantDeepTurnResponseRuntime,
type RunAssistantDeepTurnResponseRuntimeInput,
@@ -27,7 +28,7 @@ export interface RunAssistantDeepTurnResponseAttemptRuntimeInput<
normalizedQuestion: string;
deepTurnAnalysisRuntime: RunAssistantDeepTurnAnalysisRuntimeOutput;
runtimeAnalysisContext: unknown;
followupStateUsage: unknown;
followupStateUsage: AssistantFollowupUsage | null;
followupApplied: boolean;
previousInvestigationState: InvestigationStateWithProblemUnits | null | undefined;
addressRuntimeMetaForDeep: unknown;
@@ -10,7 +10,7 @@ export interface BuildAssistantDeepTurnSuccessResponseInput {
assistantReply: string;
replyType: AssistantReplyType;
conversationItem: AssistantConversationItem;
debug: AssistantDebugPayload | Record<string, unknown>;
debug: AssistantDebugPayload;
conversation: AssistantConversationItem[];
}
@@ -23,7 +23,7 @@ export function buildAssistantDeepTurnSuccessResponse(
assistant_reply: input.assistantReply,
reply_type: input.replyType,
conversation_item: input.conversationItem,
debug: input.debug as AssistantDebugPayload,
debug: input.debug,
conversation: input.conversation
};
}
@@ -0,0 +1,8 @@
export interface AssistantFollowupUsage {
applied?: unknown;
[key: string]: unknown;
}
export function isAssistantFollowupApplied(usage: AssistantFollowupUsage | null | undefined): boolean {
return Boolean(usage?.applied);
}