ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.12.23: декомпозиция deep-turn пайплайна ассистента в runtime-адаптеры
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
import type { NormalizeResponsePayload, RouteHintSummary } from "../types/normalizer";
|
||||
|
||||
const KNOWN_P0_DOMAINS = new Set([
|
||||
"settlements_60_62",
|
||||
"vat_document_register_book",
|
||||
"month_close_costs_20_44",
|
||||
"fixed_asset_amortization"
|
||||
]);
|
||||
|
||||
function toAnalysisContext(
|
||||
runtimeAnalysisContext: BuildAssistantDeepTurnRuntimeContextInput["runtimeAnalysisContext"]
|
||||
): Record<string, string | null> | null {
|
||||
if (!runtimeAnalysisContext.active) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
as_of_date: runtimeAnalysisContext.as_of_date,
|
||||
period_from: runtimeAnalysisContext.period_from,
|
||||
period_to: runtimeAnalysisContext.period_to,
|
||||
source: runtimeAnalysisContext.source
|
||||
};
|
||||
}
|
||||
|
||||
export interface BuildAssistantDeepTurnRuntimeContextInput {
|
||||
userMessage: string;
|
||||
normalizedPayload: NormalizeResponsePayload["normalized"];
|
||||
routeSummary: RouteHintSummary | null;
|
||||
runtimeAnalysisContext: {
|
||||
active: boolean;
|
||||
as_of_date: string | null;
|
||||
period_from: string | null;
|
||||
period_to: string | null;
|
||||
source: string | null;
|
||||
};
|
||||
followupUsage: unknown | null | undefined;
|
||||
resolveCompanyAnchors: (userMessage: string) => unknown;
|
||||
resolveBusinessScopeAlignment: (input: {
|
||||
userMessage: string;
|
||||
companyAnchors: unknown;
|
||||
normalized: NormalizeResponsePayload["normalized"];
|
||||
routeSummary: RouteHintSummary | null;
|
||||
}) => {
|
||||
route_summary_resolved: RouteHintSummary | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
inferP0DomainFromMessage: (userMessage: string) => string | null;
|
||||
resolveTemporalGuard: (input: {
|
||||
userMessage: string;
|
||||
normalized: NormalizeResponsePayload["normalized"];
|
||||
companyAnchors: unknown;
|
||||
analysisContext: Record<string, string | null> | null;
|
||||
}) => {
|
||||
effective_primary_period?: unknown;
|
||||
primary_period_window?: unknown;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
resolveDomainPolarityGuard: (input: {
|
||||
userMessage: string;
|
||||
companyAnchors: unknown;
|
||||
focusDomainHint: string | null;
|
||||
}) => unknown;
|
||||
resolveClaimBoundAnchors: (input: {
|
||||
userMessage: string;
|
||||
companyAnchors: unknown;
|
||||
focusDomainHint: string | null;
|
||||
primaryPeriod: unknown;
|
||||
}) => {
|
||||
claim_type: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
resolveBusinessScopeFromLiveContext: (input: {
|
||||
current: {
|
||||
route_summary_resolved: RouteHintSummary | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
temporalGuard: unknown;
|
||||
claimType: string;
|
||||
focusDomainHint: string | null;
|
||||
userMessage: string;
|
||||
companyAnchors: unknown;
|
||||
followupApplied: boolean;
|
||||
}) => {
|
||||
route_summary_resolved: RouteHintSummary | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
export interface BuildAssistantDeepTurnRuntimeContextOutput {
|
||||
companyAnchors: unknown;
|
||||
initialBusinessScopeResolution: {
|
||||
route_summary_resolved: RouteHintSummary | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
inferredDomainByMessage: string | null;
|
||||
focusDomainForGuards: string | null;
|
||||
temporalGuard: {
|
||||
effective_primary_period?: unknown;
|
||||
primary_period_window?: unknown;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
domainPolarityGuardInitial: unknown;
|
||||
claimAnchorAudit: {
|
||||
claim_type: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
businessScopeResolution: {
|
||||
route_summary_resolved: RouteHintSummary | null;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
resolvedRouteSummary: RouteHintSummary | null;
|
||||
liveTemporalHint: Record<string, string | null> | null;
|
||||
}
|
||||
|
||||
export function buildAssistantDeepTurnRuntimeContext(
|
||||
input: BuildAssistantDeepTurnRuntimeContextInput
|
||||
): BuildAssistantDeepTurnRuntimeContextOutput {
|
||||
const companyAnchors = input.resolveCompanyAnchors(input.userMessage);
|
||||
const initialBusinessScopeResolution = input.resolveBusinessScopeAlignment({
|
||||
userMessage: input.userMessage,
|
||||
companyAnchors,
|
||||
normalized: input.normalizedPayload,
|
||||
routeSummary: input.routeSummary
|
||||
});
|
||||
const inferredDomainByMessage = input.inferP0DomainFromMessage(input.userMessage);
|
||||
const focusDomainForGuards =
|
||||
inferredDomainByMessage && KNOWN_P0_DOMAINS.has(inferredDomainByMessage) ? inferredDomainByMessage : null;
|
||||
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
|
||||
const temporalGuard = input.resolveTemporalGuard({
|
||||
userMessage: input.userMessage,
|
||||
normalized: input.normalizedPayload,
|
||||
companyAnchors,
|
||||
analysisContext
|
||||
});
|
||||
const domainPolarityGuardInitial = input.resolveDomainPolarityGuard({
|
||||
userMessage: input.userMessage,
|
||||
companyAnchors,
|
||||
focusDomainHint: focusDomainForGuards
|
||||
});
|
||||
const claimAnchorAudit = input.resolveClaimBoundAnchors({
|
||||
userMessage: input.userMessage,
|
||||
companyAnchors,
|
||||
focusDomainHint: focusDomainForGuards,
|
||||
primaryPeriod: temporalGuard.effective_primary_period ?? temporalGuard.primary_period_window
|
||||
});
|
||||
const businessScopeResolution = input.resolveBusinessScopeFromLiveContext({
|
||||
current: initialBusinessScopeResolution,
|
||||
temporalGuard,
|
||||
claimType: claimAnchorAudit.claim_type,
|
||||
focusDomainHint: focusDomainForGuards,
|
||||
userMessage: input.userMessage,
|
||||
companyAnchors,
|
||||
followupApplied: Boolean((input.followupUsage as { applied?: unknown } | null)?.applied)
|
||||
});
|
||||
const resolvedRouteSummary = businessScopeResolution.route_summary_resolved;
|
||||
const liveTemporalHint = toAnalysisContext(input.runtimeAnalysisContext);
|
||||
|
||||
return {
|
||||
companyAnchors,
|
||||
initialBusinessScopeResolution,
|
||||
inferredDomainByMessage,
|
||||
focusDomainForGuards,
|
||||
temporalGuard,
|
||||
domainPolarityGuardInitial,
|
||||
claimAnchorAudit,
|
||||
businessScopeResolution,
|
||||
resolvedRouteSummary,
|
||||
liveTemporalHint
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user