ЮИ - Автопрогоны: доработать иконки и hover-состояния saved sessions
This commit is contained in:
@@ -1,6 +1,68 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export function createAssistantTransitionPolicy(deps) {
|
||||
function normalizeFollowupText(value) {
|
||||
return deps.compactWhitespace(deps.repairAddressMojibake(String(value ?? "")).toLowerCase()).replace(/ё/g, "е");
|
||||
}
|
||||
|
||||
function hasSelectedObjectInventoryScopeSignal(text) {
|
||||
const normalized = normalizeFollowupText(text);
|
||||
if (!normalized) {
|
||||
return false;
|
||||
}
|
||||
return /(?:по\s+выбранному\s+объекту|по\s+выбранной\s+позиции|по\s+этой\s+позиции|по\s+этому\s+товару|selected\s+object)/iu.test(
|
||||
normalized
|
||||
);
|
||||
}
|
||||
|
||||
function extractSelectedObjectLabel(text) {
|
||||
const repaired = deps.repairAddressMojibake(String(text ?? ""));
|
||||
const quotedMatch = repaired.match(
|
||||
/(?:по\s+выбранному\s+объекту|по\s+выбранной\s+позиции)\s*[:,-]?\s*[«"]([^"»]+?)["»]/iu
|
||||
);
|
||||
if (quotedMatch?.[1]) {
|
||||
return deps.toNonEmptyString(quotedMatch[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function inferSelectedObjectInventoryFollowupIntent(userMessage, alternateMessage = null) {
|
||||
const samples = [userMessage, alternateMessage].map((item) => normalizeFollowupText(item)).filter(Boolean);
|
||||
if (samples.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
samples.some((sample) =>
|
||||
/(?:где\s+(?:мы\s+)?взял|откуда\s+(?:мы\s+)?взял|у\s+кого\s+купил|кто\s+постав|поставщик|источник\s+поступл|от\s+кого\s+поступ)/iu.test(
|
||||
sample
|
||||
)
|
||||
)
|
||||
) {
|
||||
return "inventory_purchase_provenance_for_item";
|
||||
}
|
||||
if (
|
||||
samples.some((sample) =>
|
||||
/(?:документ|накладн|счет|сч[её]т|акт|поступл|покажи\s+док|все\s+документ|все\s+операц)/iu.test(sample)
|
||||
)
|
||||
) {
|
||||
return "inventory_purchase_documents_for_item";
|
||||
}
|
||||
if (
|
||||
samples.some((sample) =>
|
||||
/(?:кому\s+продал|кому\s+ушл|куда\s+продал|кто\s+купил|реализац|отгруз|продаж)/iu.test(sample)
|
||||
)
|
||||
) {
|
||||
return "inventory_sale_trace_for_item";
|
||||
}
|
||||
if (samples.some((sample) => /(?:рентабел|маржин|прибыл|наценк|выгод)/iu.test(sample))) {
|
||||
return "inventory_profitability_for_item";
|
||||
}
|
||||
if (samples.some((sample) => /(?:цепочк|от\s+закупк.*до\s+продаж|от\s+покупк.*до\s+продаж)/iu.test(sample))) {
|
||||
return "inventory_purchase_to_sale_chain";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseDmyDateToIso(value) {
|
||||
const match = String(value ?? "").trim().match(/^(\d{2})\.(\d{2})\.(\d{4})$/);
|
||||
if (!match) {
|
||||
@@ -90,6 +152,76 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
return earliestIsoDate ? computeMonthWindowFromIso(earliestIsoDate) : null;
|
||||
}
|
||||
|
||||
function isUsableFollowupSourceDebug(debug) {
|
||||
if (!debug || typeof debug !== "object") {
|
||||
return false;
|
||||
}
|
||||
const executionLane = deps.toNonEmptyString(debug.execution_lane);
|
||||
const detectedIntent = deps.toNonEmptyString(debug.detected_intent);
|
||||
const selectedRecipe = deps.toNonEmptyString(debug.selected_recipe);
|
||||
const answerGroundingCheck =
|
||||
debug.answer_grounding_check && typeof debug.answer_grounding_check === "object"
|
||||
? debug.answer_grounding_check
|
||||
: null;
|
||||
const groundingStatus = deps.toNonEmptyString(answerGroundingCheck?.status);
|
||||
if (groundingStatus === "grounded") {
|
||||
return true;
|
||||
}
|
||||
if (selectedRecipe) {
|
||||
return true;
|
||||
}
|
||||
return executionLane === "address_query" && Boolean(detectedIntent && detectedIntent !== "unknown");
|
||||
}
|
||||
|
||||
function findRecentUsableAddressAssistantItem(items) {
|
||||
for (let index = Array.isArray(items) ? items.length - 1 : -1; index >= 0; index -= 1) {
|
||||
const item = items[index];
|
||||
if (!item || item.role !== "assistant" || !item.debug || typeof item.debug !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (isUsableFollowupSourceDebug(item.debug)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
const item = items[index];
|
||||
const debug = item?.debug;
|
||||
if (!item || item.role !== "assistant" || !debug || typeof debug !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (deps.toNonEmptyString(debug.detected_intent) !== "inventory_purchase_provenance_for_item") {
|
||||
continue;
|
||||
}
|
||||
if (!normalizedItemHint) {
|
||||
return item;
|
||||
}
|
||||
const candidateItem = readAddressDebugItemHint(debug);
|
||||
if (candidateItem && candidateItem === normalizedItemHint) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function hasInventoryPurchaseDateVatBridgeSignal(userMessage, alternateMessage, sourceIntentHint, hasInventoryItemFocusHint) {
|
||||
if (
|
||||
sourceIntentHint !== "inventory_purchase_provenance_for_item" &&
|
||||
@@ -270,7 +402,24 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
llmPreDecomposeMeta = null,
|
||||
addressNavigationState = null
|
||||
) {
|
||||
const previousAddressItem = deps.findLastAddressAssistantItem(items);
|
||||
const rawCapabilityMetaQuery =
|
||||
deps.shouldHandleAsAssistantCapabilityMetaQuery(userMessage) ||
|
||||
(deps.toNonEmptyString(alternateMessage)
|
||||
? deps.shouldHandleAsAssistantCapabilityMetaQuery(String(alternateMessage ?? ""))
|
||||
: false);
|
||||
const rawDataRetrievalSignal =
|
||||
deps.hasDataRetrievalRequestSignal(userMessage) ||
|
||||
(deps.toNonEmptyString(alternateMessage)
|
||||
? deps.hasDataRetrievalRequestSignal(String(alternateMessage ?? ""))
|
||||
: false);
|
||||
if (rawCapabilityMetaQuery && !rawDataRetrievalSignal) {
|
||||
return null;
|
||||
}
|
||||
const latestAddressItem = deps.findLastAddressAssistantItem(items);
|
||||
const previousAddressItem =
|
||||
(latestAddressItem && isUsableFollowupSourceDebug(latestAddressItem?.debug)
|
||||
? latestAddressItem
|
||||
: findRecentUsableAddressAssistantItem(items)) ?? latestAddressItem;
|
||||
const previousAddressDebug = previousAddressItem?.debug ?? null;
|
||||
const lastOrganizationClarificationDebug = deps.findLastOrganizationClarificationAddressDebug(items);
|
||||
const organizationClarificationCandidates = Array.isArray(lastOrganizationClarificationDebug?.organization_candidates)
|
||||
@@ -430,6 +579,8 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
}
|
||||
const sourceIntent = deps.toNonEmptyString(previousAddressDebug.detected_intent);
|
||||
const llmExplicitIntent = deps.toNonEmptyString(llmPreDecomposeMeta?.predecomposeContract?.intent);
|
||||
const llmSelectedObjectScopeDetected =
|
||||
llmPreDecomposeMeta?.predecomposeContract?.semantics?.selected_object_scope_detected === true;
|
||||
const resolvedPrimaryIntent = deps.resolveAddressIntent(deps.repairAddressMojibake(String(userMessage ?? ""))).intent;
|
||||
const resolvedAlternateIntent = deps.toNonEmptyString(alternateMessage)
|
||||
? deps.resolveAddressIntent(deps.repairAddressMojibake(String(alternateMessage ?? ""))).intent
|
||||
@@ -567,14 +718,15 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
? deps.hasFollowupMarker(String(alternateMessage ?? "")) ||
|
||||
deps.hasReferentialPointer(String(alternateMessage ?? ""))
|
||||
: false);
|
||||
const hasSelectedObjectInventorySignalPrimary = /(?:по\s+выбранному\s+объекту|по\s+этой\s+позиции|по\s+этому\s+товару|selected\s+object)/iu.test(
|
||||
String(userMessage ?? "")
|
||||
);
|
||||
const hasSelectedObjectInventorySignalPrimary =
|
||||
llmSelectedObjectScopeDetected || hasSelectedObjectInventoryScopeSignal(userMessage);
|
||||
const hasSelectedObjectInventorySignalAlternate = deps.toNonEmptyString(alternateMessage)
|
||||
? /(?:по\s+выбранному\s+объекту|по\s+этой\s+позиции|по\s+этому\s+товару|selected\s+object)/iu.test(
|
||||
String(alternateMessage ?? "")
|
||||
)
|
||||
? hasSelectedObjectInventoryScopeSignal(String(alternateMessage ?? ""))
|
||||
: false;
|
||||
const selectedObjectRetargetIntent =
|
||||
hasSelectedObjectInventorySignalPrimary || hasSelectedObjectInventorySignalAlternate
|
||||
? inferSelectedObjectInventoryFollowupIntent(userMessage, alternateMessage)
|
||||
: null;
|
||||
let inventoryRootFrame = deps.findRecentInventoryRootFrame(items);
|
||||
if (inventoryRootFrame && navigationOrganization && !deps.toNonEmptyString(inventoryRootFrame.filters?.organization)) {
|
||||
inventoryRootFrame = {
|
||||
@@ -649,7 +801,17 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
previousFilters.organization = organizationClarificationSelection;
|
||||
}
|
||||
if (inventoryPurchaseDateVatBridge) {
|
||||
const purchaseBridgeWindow = extractPurchaseDateBridgeWindow(previousAddressItem, addressNavigationState);
|
||||
const purchaseBridgeItem =
|
||||
previousAddressItem &&
|
||||
deps.toNonEmptyString(previousAddressDebug?.detected_intent) === "inventory_purchase_provenance_for_item"
|
||||
? previousAddressItem
|
||||
: findRecentInventoryPurchaseProvenanceItem(
|
||||
items,
|
||||
deps.toNonEmptyString(navigationFocusObjectLabel) ??
|
||||
readAddressDebugItemHint(previousAddressDebug) ??
|
||||
deps.toNonEmptyString(previousFilters.item)
|
||||
) ?? previousAddressItem;
|
||||
const purchaseBridgeWindow = extractPurchaseDateBridgeWindow(purchaseBridgeItem, addressNavigationState);
|
||||
if (purchaseBridgeWindow) {
|
||||
previousFilters.period_from = purchaseBridgeWindow.period_from;
|
||||
previousFilters.period_to = purchaseBridgeWindow.period_to;
|
||||
@@ -761,8 +923,6 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
if (
|
||||
!rootScopedPivot &&
|
||||
!deps.toNonEmptyString(previousFilters.item) &&
|
||||
navigationFocusObjectType === "item" &&
|
||||
navigationFocusObjectLabel &&
|
||||
(sourceIntentHint === "inventory_on_hand_as_of_date" ||
|
||||
sourceIntentHint === "inventory_purchase_provenance_for_item" ||
|
||||
sourceIntentHint === "inventory_purchase_documents_for_item" ||
|
||||
@@ -773,10 +933,14 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
hasSelectedObjectInventorySignalPrimary ||
|
||||
hasSelectedObjectInventorySignalAlternate)
|
||||
) {
|
||||
previousFilters.item = navigationFocusObjectLabel;
|
||||
if (!previousAnchor) {
|
||||
const selectedObjectLabel =
|
||||
(navigationFocusObjectType === "item" ? navigationFocusObjectLabel : null) ??
|
||||
extractSelectedObjectLabel(userMessage) ??
|
||||
(deps.toNonEmptyString(alternateMessage) ? extractSelectedObjectLabel(String(alternateMessage ?? "")) : null);
|
||||
if (selectedObjectLabel) {
|
||||
previousFilters.item = selectedObjectLabel;
|
||||
previousAnchorType = "item";
|
||||
previousAnchor = navigationFocusObjectLabel;
|
||||
previousAnchor = selectedObjectLabel;
|
||||
}
|
||||
}
|
||||
if (organizationClarificationSelection && !previousAnchor) {
|
||||
@@ -817,6 +981,11 @@ export function createAssistantTransitionPolicy(deps) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user