Архитектура: централизовать root-frame-aware carryover filters в continuity policy и transition glue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
readAddressDebugTemporalScope,
|
||||
resolveAddressDebugCarryoverFilters,
|
||||
resolveAddressDebugContextFacts,
|
||||
resolveAddressDebugAnchorContext,
|
||||
resolveAssistantOrganizationAuthority
|
||||
@@ -100,4 +101,36 @@ describe("assistantContinuityPolicy organization authority", () => {
|
||||
anchorValue: "Рабочая станция"
|
||||
});
|
||||
});
|
||||
it("prefers inventory root-frame filters over stale drilldown date scope in carryover filters", () => {
|
||||
const filters = resolveAddressDebugCarryoverFilters({
|
||||
detected_intent: "inventory_purchase_documents_for_item",
|
||||
extracted_filters: {
|
||||
item: "Workstation",
|
||||
organization: "Org Alt",
|
||||
as_of_date: "2021-04-15"
|
||||
},
|
||||
address_root_frame_context: {
|
||||
root_intent: "inventory_on_hand_as_of_date",
|
||||
root_filters: {
|
||||
organization: "Org Alt",
|
||||
warehouse: "Main Warehouse",
|
||||
as_of_date: "2021-03-31",
|
||||
period_from: "2021-03-01",
|
||||
period_to: "2021-03-31"
|
||||
},
|
||||
root_anchor_type: "organization",
|
||||
root_anchor_value: "Org Alt",
|
||||
current_frame_kind: "inventory_drilldown"
|
||||
}
|
||||
});
|
||||
|
||||
expect(filters).toEqual({
|
||||
item: "Workstation",
|
||||
organization: "Org Alt",
|
||||
warehouse: "Main Warehouse",
|
||||
as_of_date: "2021-03-31",
|
||||
period_from: "2021-03-01",
|
||||
period_to: "2021-03-31"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -754,4 +754,88 @@ describe("assistantTransitionPolicy", () => {
|
||||
});
|
||||
expect(carryover?.followupContext?.previous_anchor_type).toBe("item");
|
||||
});
|
||||
|
||||
it("prefers root-frame dates over stale drilldown filters when hydrating previous filters", () => {
|
||||
const organization = "Org Alt";
|
||||
const policy = buildPolicy({
|
||||
findLastAddressAssistantItem: (_items: unknown[]) => ({
|
||||
text: "Workstation drilldown",
|
||||
debug: {
|
||||
detected_intent: "inventory_purchase_documents_for_item",
|
||||
extracted_filters: {
|
||||
item: "Workstation",
|
||||
organization,
|
||||
as_of_date: "2021-04-15"
|
||||
},
|
||||
anchor_type: "item",
|
||||
anchor_value_resolved: "Workstation",
|
||||
address_root_frame_context: {
|
||||
root_intent: "inventory_on_hand_as_of_date",
|
||||
root_filters: {
|
||||
organization,
|
||||
warehouse: "Main Warehouse",
|
||||
as_of_date: "2021-03-31",
|
||||
period_from: "2021-03-01",
|
||||
period_to: "2021-03-31"
|
||||
},
|
||||
root_anchor_type: "organization",
|
||||
root_anchor_value: organization,
|
||||
current_frame_kind: "inventory_drilldown"
|
||||
}
|
||||
}
|
||||
}),
|
||||
findRecentInventoryRootFrame: () => null,
|
||||
hasInventoryRootTemporalFollowupSignal: (message: string) => /эту же дату/i.test(message)
|
||||
});
|
||||
|
||||
const items = [
|
||||
{
|
||||
role: "assistant",
|
||||
text: "Workstation drilldown",
|
||||
debug: {
|
||||
execution_lane: "address_query",
|
||||
answer_grounding_check: { status: "grounded" },
|
||||
detected_intent: "inventory_purchase_documents_for_item",
|
||||
extracted_filters: {
|
||||
item: "Workstation",
|
||||
organization,
|
||||
as_of_date: "2021-04-15"
|
||||
},
|
||||
anchor_type: "item",
|
||||
anchor_value_resolved: "Workstation",
|
||||
address_root_frame_context: {
|
||||
root_intent: "inventory_on_hand_as_of_date",
|
||||
root_filters: {
|
||||
organization,
|
||||
warehouse: "Main Warehouse",
|
||||
as_of_date: "2021-03-31",
|
||||
period_from: "2021-03-01",
|
||||
period_to: "2021-03-31"
|
||||
},
|
||||
root_anchor_type: "organization",
|
||||
root_anchor_value: organization,
|
||||
current_frame_kind: "inventory_drilldown"
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const carryover = policy.resolveAddressFollowupCarryoverContext(
|
||||
"остатки на эту же дату",
|
||||
items as any,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
expect(carryover?.followupContext?.root_context_only).toBe(true);
|
||||
expect(carryover?.followupContext?.previous_filters).toMatchObject({
|
||||
organization,
|
||||
warehouse: "Main Warehouse",
|
||||
as_of_date: "2021-03-31",
|
||||
period_from: "2021-03-01",
|
||||
period_to: "2021-03-31"
|
||||
});
|
||||
expect(carryover?.followupContext?.previous_filters?.as_of_date).not.toBe("2021-04-15");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user