АРЧ АП11 - Архитектура после регресса: Архитектура: обновить статус pre-multidomain readiness и протянуть continuity snapshot в transition hot path

This commit is contained in:
2026-04-18 14:28:01 +03:00
parent f58ef9ad55
commit 578f6643e6
7 changed files with 418 additions and 43 deletions
@@ -1,4 +1,10 @@
// @ts-nocheck
import {
buildInventoryRootFrameFromAddressDebug,
readAddressDebugFilters,
readAddressDebugItem,
resolveAssistantContinuitySnapshot
} from "./assistantContinuityPolicy";
export function createAssistantTransitionPolicy(deps) {
function normalizeFollowupText(value) {
@@ -186,20 +192,6 @@ export function createAssistantTransitionPolicy(deps) {
return null;
}
function readAddressDebugItemHint(debug) {
if (!debug || typeof debug !== "object") {
return null;
}
const extractedFilters =
debug.extracted_filters && typeof debug.extracted_filters === "object" ? debug.extracted_filters : null;
return (
deps.toNonEmptyString(extractedFilters?.item) ??
(deps.toNonEmptyString(debug.anchor_type) === "item"
? deps.toNonEmptyString(debug.anchor_value_resolved) ?? deps.toNonEmptyString(debug.anchor_value_raw)
: null)
);
}
function findRecentInventoryPurchaseProvenanceItem(items, itemHint = null) {
const normalizedItemHint = deps.toNonEmptyString(itemHint);
for (let index = Array.isArray(items) ? items.length - 1 : -1; index >= 0; index -= 1) {
@@ -214,7 +206,7 @@ export function createAssistantTransitionPolicy(deps) {
if (!normalizedItemHint) {
return item;
}
const candidateItem = readAddressDebugItemHint(debug);
const candidateItem = readAddressDebugItem(debug, deps.toNonEmptyString);
if (candidateItem && candidateItem === normalizedItemHint) {
return item;
}
@@ -421,6 +413,10 @@ export function createAssistantTransitionPolicy(deps) {
? latestAddressItem
: findRecentUsableAddressAssistantItem(items)) ?? latestAddressItem;
const previousAddressDebug = previousAddressItem?.debug ?? null;
const continuitySnapshot = resolveAssistantContinuitySnapshot({
sessionItems: items,
toNonEmptyString: deps.toNonEmptyString
});
const lastOrganizationClarificationDebug = deps.findLastOrganizationClarificationAddressDebug(items);
const organizationClarificationCandidates = Array.isArray(lastOrganizationClarificationDebug?.organization_candidates)
? deps.mergeKnownOrganizations(lastOrganizationClarificationDebug.organization_candidates)
@@ -727,7 +723,10 @@ export function createAssistantTransitionPolicy(deps) {
hasSelectedObjectInventorySignalPrimary || hasSelectedObjectInventorySignalAlternate
? inferSelectedObjectInventoryFollowupIntent(userMessage, alternateMessage)
: null;
let inventoryRootFrame = deps.findRecentInventoryRootFrame(items);
let inventoryRootFrame =
deps.findRecentInventoryRootFrame(items) ??
continuitySnapshot.inventoryRootFrame ??
buildInventoryRootFrameFromAddressDebug(continuitySnapshot.lastGroundedAddressDebug, deps.toNonEmptyString);
if (inventoryRootFrame && navigationOrganization && !deps.toNonEmptyString(inventoryRootFrame.filters?.organization)) {
inventoryRootFrame = {
...inventoryRootFrame,
@@ -794,6 +793,9 @@ export function createAssistantTransitionPolicy(deps) {
previousFilters.organization = historicalOrganization;
}
}
if (!deps.toNonEmptyString(previousFilters.organization) && continuitySnapshot.activeOrganization) {
previousFilters.organization = continuitySnapshot.activeOrganization;
}
if (!deps.toNonEmptyString(previousFilters.organization) && navigationOrganization) {
previousFilters.organization = navigationOrganization;
}
@@ -808,7 +810,7 @@ export function createAssistantTransitionPolicy(deps) {
: findRecentInventoryPurchaseProvenanceItem(
items,
deps.toNonEmptyString(navigationFocusObjectLabel) ??
readAddressDebugItemHint(previousAddressDebug) ??
readAddressDebugItem(previousAddressDebug, deps.toNonEmptyString) ??
deps.toNonEmptyString(previousFilters.item)
) ?? previousAddressItem;
const purchaseBridgeWindow = extractPurchaseDateBridgeWindow(purchaseBridgeItem, addressNavigationState);
@@ -835,6 +837,15 @@ export function createAssistantTransitionPolicy(deps) {
) {
previousFilters.as_of_date = deps.toNonEmptyString(navigationDateScope?.as_of_date);
}
if (
shouldBackfillPreviousDateScopeFromNavigation &&
!deps.toNonEmptyString(previousFilters.as_of_date) &&
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.as_of_date
) {
previousFilters.as_of_date = deps.toNonEmptyString(
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.as_of_date
);
}
if (
shouldBackfillPreviousDateScopeFromNavigation &&
!deps.toNonEmptyString(previousFilters.period_from) &&
@@ -842,6 +853,15 @@ export function createAssistantTransitionPolicy(deps) {
) {
previousFilters.period_from = deps.toNonEmptyString(navigationDateScope?.period_from);
}
if (
shouldBackfillPreviousDateScopeFromNavigation &&
!deps.toNonEmptyString(previousFilters.period_from) &&
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.period_from
) {
previousFilters.period_from = deps.toNonEmptyString(
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.period_from
);
}
if (
shouldBackfillPreviousDateScopeFromNavigation &&
!deps.toNonEmptyString(previousFilters.period_to) &&
@@ -849,6 +869,15 @@ export function createAssistantTransitionPolicy(deps) {
) {
previousFilters.period_to = deps.toNonEmptyString(navigationDateScope?.period_to);
}
if (
shouldBackfillPreviousDateScopeFromNavigation &&
!deps.toNonEmptyString(previousFilters.period_to) &&
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.period_to
) {
previousFilters.period_to = deps.toNonEmptyString(
readAddressDebugFilters(continuitySnapshot.lastGroundedAddressDebug)?.period_to
);
}
const rootContextOnlyPivot = Boolean(
(deps.isInventorySelectedObjectIntent(sourceIntentHint) || currentFrameKind === "inventory_drilldown") &&
deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage) &&
@@ -935,6 +964,7 @@ export function createAssistantTransitionPolicy(deps) {
) {
const selectedObjectLabel =
(navigationFocusObjectType === "item" ? navigationFocusObjectLabel : null) ??
continuitySnapshot.activeItem ??
extractSelectedObjectLabel(userMessage) ??
(deps.toNonEmptyString(alternateMessage) ? extractSelectedObjectLabel(String(alternateMessage ?? "")) : null);
if (selectedObjectLabel) {