Архитектура: централизовать inventory pivot flags и carryover target intent в continuity policy
This commit is contained in:
@@ -11,6 +11,8 @@ exports.resolveAddressDebugContextFacts = resolveAddressDebugContextFacts;
|
||||
exports.resolveAddressDebugCarryoverFilters = resolveAddressDebugCarryoverFilters;
|
||||
exports.hydrateInventoryRootFrameState = hydrateInventoryRootFrameState;
|
||||
exports.buildRootScopedCarryoverFilters = buildRootScopedCarryoverFilters;
|
||||
exports.resolveInventoryFollowupPivotFlags = resolveInventoryFollowupPivotFlags;
|
||||
exports.resolveFollowupTargetIntent = resolveFollowupTargetIntent;
|
||||
exports.shouldUseNavigationTemporalCarryover = shouldUseNavigationTemporalCarryover;
|
||||
exports.applyTemporalCarryoverFilters = applyTemporalCarryoverFilters;
|
||||
exports.applyOrganizationCarryoverFilters = applyOrganizationCarryoverFilters;
|
||||
@@ -241,6 +243,49 @@ function buildRootScopedCarryoverFilters(previousFilters, inventoryRootFrame, to
|
||||
}
|
||||
return nextFilters;
|
||||
}
|
||||
function resolveInventoryFollowupPivotFlags(inventoryRootFrame, sourceIntentHint, currentFrameKind, hasForeignAccountingPivotMessage, inventoryPurchaseDateVatBridge, hasInventoryRootTemporalFollowupPrimary, hasInventoryRootTemporalFollowupAlternate, hasInventoryRootRestatementPrimary, hasInventoryRootRestatementAlternate, hasExplicitInventorySameDatePivotPrimary, hasExplicitInventorySameDatePivotAlternate, isInventorySelectedObjectIntent, isInventoryRootFrameIntent) {
|
||||
const rootContextOnlyPivot = Boolean((isInventorySelectedObjectIntent(sourceIntentHint) || currentFrameKind === "inventory_drilldown") &&
|
||||
hasForeignAccountingPivotMessage &&
|
||||
!inventoryPurchaseDateVatBridge);
|
||||
const inventoryRootTemporalPivot = Boolean(inventoryRootFrame &&
|
||||
(isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root") &&
|
||||
(hasInventoryRootTemporalFollowupPrimary || hasInventoryRootTemporalFollowupAlternate) &&
|
||||
!hasForeignAccountingPivotMessage);
|
||||
const inventoryRootRestatementPivot = Boolean(inventoryRootFrame &&
|
||||
(isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root" ||
|
||||
currentFrameKind === "generic") &&
|
||||
(hasInventoryRootRestatementPrimary || hasInventoryRootRestatementAlternate) &&
|
||||
!hasForeignAccountingPivotMessage);
|
||||
const explicitInventorySameDatePivot = Boolean(!inventoryRootFrame &&
|
||||
(hasExplicitInventorySameDatePivotPrimary || hasExplicitInventorySameDatePivotAlternate) &&
|
||||
!hasForeignAccountingPivotMessage);
|
||||
return {
|
||||
rootScopedPivot: rootContextOnlyPivot || inventoryRootTemporalPivot || inventoryRootRestatementPivot,
|
||||
explicitInventorySameDatePivot
|
||||
};
|
||||
}
|
||||
function resolveFollowupTargetIntent(inventoryPurchaseDateVatBridge, selectedObjectRetargetIntent, explicitIntent, sourceIntent, followupSelectionMode, inventoryRootFrameIntent, displayedEntityTargetIntent, previousIntent, explicitInventorySameDatePivot) {
|
||||
if (inventoryPurchaseDateVatBridge) {
|
||||
return "vat_liability_confirmed_for_tax_period";
|
||||
}
|
||||
if (selectedObjectRetargetIntent &&
|
||||
(explicitIntent === null || explicitIntent === "inventory_on_hand_as_of_date" || explicitIntent === sourceIntent)) {
|
||||
return selectedObjectRetargetIntent;
|
||||
}
|
||||
if (followupSelectionMode === "carry_root_context") {
|
||||
return inventoryRootFrameIntent ?? displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
}
|
||||
if (explicitInventorySameDatePivot) {
|
||||
return "inventory_on_hand_as_of_date";
|
||||
}
|
||||
return displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
}
|
||||
function shouldUseNavigationTemporalCarryover(sourceIntentHint) {
|
||||
const normalizedIntent = fallbackToNonEmptyString(sourceIntentHint);
|
||||
return (normalizedIntent === "inventory_on_hand_as_of_date" ||
|
||||
|
||||
@@ -591,28 +591,7 @@ function createAssistantTransitionPolicy(deps) {
|
||||
}
|
||||
}
|
||||
previousFilters = (0, assistantContinuityPolicy_1.applyTemporalCarryoverFilters)(previousFilters, navigationDateScope, continuityTemporalScope, sourceIntentHint, deps.toNonEmptyString);
|
||||
const rootContextOnlyPivot = Boolean((deps.isInventorySelectedObjectIntent(sourceIntentHint) || currentFrameKind === "inventory_drilldown") &&
|
||||
deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage) &&
|
||||
!inventoryPurchaseDateVatBridge);
|
||||
const inventoryRootTemporalPivot = Boolean(inventoryRootFrame &&
|
||||
(deps.isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
deps.isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root") &&
|
||||
(hasInventoryRootTemporalFollowupPrimary || hasInventoryRootTemporalFollowupAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage));
|
||||
const inventoryRootRestatementPivot = Boolean(inventoryRootFrame &&
|
||||
(deps.isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
deps.isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root" ||
|
||||
currentFrameKind === "generic") &&
|
||||
(hasInventoryRootRestatementPrimary || hasInventoryRootRestatementAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage));
|
||||
const explicitInventorySameDatePivot = Boolean(!inventoryRootFrame &&
|
||||
(hasExplicitInventorySameDatePivotPrimary || hasExplicitInventorySameDatePivotAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage));
|
||||
const rootScopedPivot = rootContextOnlyPivot || inventoryRootTemporalPivot || inventoryRootRestatementPivot;
|
||||
const { rootScopedPivot, explicitInventorySameDatePivot } = (0, assistantContinuityPolicy_1.resolveInventoryFollowupPivotFlags)(inventoryRootFrame, sourceIntentHint, currentFrameKind, deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage), inventoryPurchaseDateVatBridge, hasInventoryRootTemporalFollowupPrimary, hasInventoryRootTemporalFollowupAlternate, hasInventoryRootRestatementPrimary, hasInventoryRootRestatementAlternate, hasExplicitInventorySameDatePivotPrimary, hasExplicitInventorySameDatePivotAlternate, deps.isInventorySelectedObjectIntent, deps.isInventoryRootFrameIntent);
|
||||
if (rootScopedPivot) {
|
||||
previousIntent = null;
|
||||
previousAnchorType = null;
|
||||
@@ -679,18 +658,7 @@ function createAssistantTransitionPolicy(deps) {
|
||||
hasInventoryRootRestatementAlternate ||
|
||||
hasSelectedObjectInventorySignalPrimary ||
|
||||
hasSelectedObjectInventorySignalAlternate));
|
||||
const carryoverTargetIntent = inventoryPurchaseDateVatBridge
|
||||
? "vat_liability_confirmed_for_tax_period"
|
||||
: selectedObjectRetargetIntent &&
|
||||
(explicitIntent === null ||
|
||||
explicitIntent === "inventory_on_hand_as_of_date" ||
|
||||
explicitIntent === sourceIntent)
|
||||
? selectedObjectRetargetIntent
|
||||
: followupSelectionMode === "carry_root_context"
|
||||
? inventoryRootFrame?.intent ?? displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined
|
||||
: explicitInventorySameDatePivot
|
||||
? "inventory_on_hand_as_of_date"
|
||||
: displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
const carryoverTargetIntent = (0, assistantContinuityPolicy_1.resolveFollowupTargetIntent)(inventoryPurchaseDateVatBridge, selectedObjectRetargetIntent, explicitIntent, sourceIntent, followupSelectionMode, deps.toNonEmptyString(inventoryRootFrame?.intent), displayedEntityTargetIntent, previousIntent, explicitInventorySameDatePivot);
|
||||
return {
|
||||
followupContext: {
|
||||
previous_intent: previousIntent ?? undefined,
|
||||
|
||||
@@ -369,6 +369,93 @@ export function buildRootScopedCarryoverFilters(
|
||||
return nextFilters;
|
||||
}
|
||||
|
||||
export function resolveInventoryFollowupPivotFlags(
|
||||
inventoryRootFrame:
|
||||
| {
|
||||
intent?: unknown;
|
||||
}
|
||||
| null
|
||||
| undefined,
|
||||
sourceIntentHint: string | null,
|
||||
currentFrameKind: string | null,
|
||||
hasForeignAccountingPivotMessage: boolean,
|
||||
inventoryPurchaseDateVatBridge: boolean,
|
||||
hasInventoryRootTemporalFollowupPrimary: boolean,
|
||||
hasInventoryRootTemporalFollowupAlternate: boolean,
|
||||
hasInventoryRootRestatementPrimary: boolean,
|
||||
hasInventoryRootRestatementAlternate: boolean,
|
||||
hasExplicitInventorySameDatePivotPrimary: boolean,
|
||||
hasExplicitInventorySameDatePivotAlternate: boolean,
|
||||
isInventorySelectedObjectIntent: (intent: unknown) => boolean,
|
||||
isInventoryRootFrameIntent: (intent: unknown) => boolean
|
||||
): {
|
||||
rootScopedPivot: boolean;
|
||||
explicitInventorySameDatePivot: boolean;
|
||||
} {
|
||||
const rootContextOnlyPivot = Boolean(
|
||||
(isInventorySelectedObjectIntent(sourceIntentHint) || currentFrameKind === "inventory_drilldown") &&
|
||||
hasForeignAccountingPivotMessage &&
|
||||
!inventoryPurchaseDateVatBridge
|
||||
);
|
||||
const inventoryRootTemporalPivot = Boolean(
|
||||
inventoryRootFrame &&
|
||||
(isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root") &&
|
||||
(hasInventoryRootTemporalFollowupPrimary || hasInventoryRootTemporalFollowupAlternate) &&
|
||||
!hasForeignAccountingPivotMessage
|
||||
);
|
||||
const inventoryRootRestatementPivot = Boolean(
|
||||
inventoryRootFrame &&
|
||||
(isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root" ||
|
||||
currentFrameKind === "generic") &&
|
||||
(hasInventoryRootRestatementPrimary || hasInventoryRootRestatementAlternate) &&
|
||||
!hasForeignAccountingPivotMessage
|
||||
);
|
||||
const explicitInventorySameDatePivot = Boolean(
|
||||
!inventoryRootFrame &&
|
||||
(hasExplicitInventorySameDatePivotPrimary || hasExplicitInventorySameDatePivotAlternate) &&
|
||||
!hasForeignAccountingPivotMessage
|
||||
);
|
||||
return {
|
||||
rootScopedPivot: rootContextOnlyPivot || inventoryRootTemporalPivot || inventoryRootRestatementPivot,
|
||||
explicitInventorySameDatePivot
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveFollowupTargetIntent(
|
||||
inventoryPurchaseDateVatBridge: boolean,
|
||||
selectedObjectRetargetIntent: string | null,
|
||||
explicitIntent: string | null,
|
||||
sourceIntent: string | null,
|
||||
followupSelectionMode: string | null,
|
||||
inventoryRootFrameIntent: string | null,
|
||||
displayedEntityTargetIntent: string | null,
|
||||
previousIntent: string | null,
|
||||
explicitInventorySameDatePivot: boolean
|
||||
): string | undefined {
|
||||
if (inventoryPurchaseDateVatBridge) {
|
||||
return "vat_liability_confirmed_for_tax_period";
|
||||
}
|
||||
if (
|
||||
selectedObjectRetargetIntent &&
|
||||
(explicitIntent === null || explicitIntent === "inventory_on_hand_as_of_date" || explicitIntent === sourceIntent)
|
||||
) {
|
||||
return selectedObjectRetargetIntent;
|
||||
}
|
||||
if (followupSelectionMode === "carry_root_context") {
|
||||
return inventoryRootFrameIntent ?? displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
}
|
||||
if (explicitInventorySameDatePivot) {
|
||||
return "inventory_on_hand_as_of_date";
|
||||
}
|
||||
return displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
}
|
||||
|
||||
export function shouldUseNavigationTemporalCarryover(sourceIntentHint: unknown): boolean {
|
||||
const normalizedIntent = fallbackToNonEmptyString(sourceIntentHint);
|
||||
return (
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
resolveAddressDebugCarryoverFilters,
|
||||
resolveAddressDebugAnchorContext,
|
||||
resolveDisplayedEntityFollowupRetarget,
|
||||
resolveFollowupTargetIntent,
|
||||
resolveInventoryFollowupPivotFlags,
|
||||
resolveAssistantOrganizationAuthority
|
||||
} from "./assistantContinuityPolicy";
|
||||
|
||||
@@ -773,36 +775,21 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
sourceIntentHint,
|
||||
deps.toNonEmptyString
|
||||
);
|
||||
const rootContextOnlyPivot = Boolean(
|
||||
(deps.isInventorySelectedObjectIntent(sourceIntentHint) || currentFrameKind === "inventory_drilldown") &&
|
||||
deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage) &&
|
||||
!inventoryPurchaseDateVatBridge
|
||||
const { rootScopedPivot, explicitInventorySameDatePivot } = resolveInventoryFollowupPivotFlags(
|
||||
inventoryRootFrame,
|
||||
sourceIntentHint,
|
||||
currentFrameKind,
|
||||
deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage),
|
||||
inventoryPurchaseDateVatBridge,
|
||||
hasInventoryRootTemporalFollowupPrimary,
|
||||
hasInventoryRootTemporalFollowupAlternate,
|
||||
hasInventoryRootRestatementPrimary,
|
||||
hasInventoryRootRestatementAlternate,
|
||||
hasExplicitInventorySameDatePivotPrimary,
|
||||
hasExplicitInventorySameDatePivotAlternate,
|
||||
deps.isInventorySelectedObjectIntent,
|
||||
deps.isInventoryRootFrameIntent
|
||||
);
|
||||
const inventoryRootTemporalPivot = Boolean(
|
||||
inventoryRootFrame &&
|
||||
(deps.isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
deps.isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root") &&
|
||||
(hasInventoryRootTemporalFollowupPrimary || hasInventoryRootTemporalFollowupAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage)
|
||||
);
|
||||
const inventoryRootRestatementPivot = Boolean(
|
||||
inventoryRootFrame &&
|
||||
(deps.isInventorySelectedObjectIntent(sourceIntentHint) ||
|
||||
deps.isInventoryRootFrameIntent(sourceIntentHint) ||
|
||||
currentFrameKind === "inventory_drilldown" ||
|
||||
currentFrameKind === "inventory_root" ||
|
||||
currentFrameKind === "generic") &&
|
||||
(hasInventoryRootRestatementPrimary || hasInventoryRootRestatementAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage)
|
||||
);
|
||||
const explicitInventorySameDatePivot = Boolean(
|
||||
!inventoryRootFrame &&
|
||||
(hasExplicitInventorySameDatePivotPrimary || hasExplicitInventorySameDatePivotAlternate) &&
|
||||
!deps.hasForeignAccountingPivotOverInventoryMessage(userMessage, alternateMessage)
|
||||
);
|
||||
const rootScopedPivot = rootContextOnlyPivot || inventoryRootTemporalPivot || inventoryRootRestatementPivot;
|
||||
if (rootScopedPivot) {
|
||||
previousIntent = null;
|
||||
previousAnchorType = null;
|
||||
@@ -899,19 +886,17 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
hasSelectedObjectInventorySignalPrimary ||
|
||||
hasSelectedObjectInventorySignalAlternate)
|
||||
);
|
||||
const carryoverTargetIntent =
|
||||
inventoryPurchaseDateVatBridge
|
||||
? "vat_liability_confirmed_for_tax_period"
|
||||
: selectedObjectRetargetIntent &&
|
||||
(explicitIntent === null ||
|
||||
explicitIntent === "inventory_on_hand_as_of_date" ||
|
||||
explicitIntent === sourceIntent)
|
||||
? selectedObjectRetargetIntent
|
||||
: followupSelectionMode === "carry_root_context"
|
||||
? inventoryRootFrame?.intent ?? displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined
|
||||
: explicitInventorySameDatePivot
|
||||
? "inventory_on_hand_as_of_date"
|
||||
: displayedEntityTargetIntent ?? explicitIntent ?? previousIntent ?? undefined;
|
||||
const carryoverTargetIntent = resolveFollowupTargetIntent(
|
||||
inventoryPurchaseDateVatBridge,
|
||||
selectedObjectRetargetIntent,
|
||||
explicitIntent,
|
||||
sourceIntent,
|
||||
followupSelectionMode,
|
||||
deps.toNonEmptyString(inventoryRootFrame?.intent),
|
||||
displayedEntityTargetIntent,
|
||||
previousIntent,
|
||||
explicitInventorySameDatePivot
|
||||
);
|
||||
return {
|
||||
followupContext: {
|
||||
previous_intent: previousIntent ?? undefined,
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
resolveAddressDebugContextFacts,
|
||||
resolveAddressDebugAnchorContext,
|
||||
resolveDisplayedEntityFollowupRetarget,
|
||||
resolveFollowupTargetIntent,
|
||||
resolveInventoryFollowupPivotFlags,
|
||||
resolveAssistantOrganizationAuthority
|
||||
} from "../src/services/assistantContinuityPolicy";
|
||||
|
||||
@@ -254,6 +256,45 @@ describe("assistantContinuityPolicy organization authority", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves inventory root pivots through one shared helper", () => {
|
||||
const flags = resolveInventoryFollowupPivotFlags(
|
||||
{ intent: "inventory_on_hand_as_of_date" },
|
||||
"inventory_purchase_documents_for_item",
|
||||
"inventory_drilldown",
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
(intent) => String(intent ?? "") === "inventory_purchase_documents_for_item",
|
||||
(intent) => String(intent ?? "") === "inventory_on_hand_as_of_date"
|
||||
);
|
||||
|
||||
expect(flags).toEqual({
|
||||
rootScopedPivot: true,
|
||||
explicitInventorySameDatePivot: false
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves follow-up target intent precedence through one shared helper", () => {
|
||||
const targetIntent = resolveFollowupTargetIntent(
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
"customer_revenue_and_payments",
|
||||
"carry_root_context",
|
||||
"inventory_on_hand_as_of_date",
|
||||
"list_contracts_by_counterparty",
|
||||
"customer_revenue_and_payments",
|
||||
false
|
||||
);
|
||||
|
||||
expect(targetIntent).toBe("inventory_on_hand_as_of_date");
|
||||
});
|
||||
|
||||
it("applies organization carryover precedence from historical to shared authority to navigation and clarification", () => {
|
||||
const filters = applyOrganizationCarryoverFilters(
|
||||
{},
|
||||
|
||||
Reference in New Issue
Block a user