Архитектура: закрыть phase17 clarification-resume и обновить readiness-статус перед расширением доменов
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
hasInventorySaleCue,
|
||||
hasInventorySupplierCue
|
||||
} from "../inventoryLifecycleCueHelpers";
|
||||
import { normalizeOrganizationScopeSearchText, organizationsLikelySameEntity } from "../assistantOrganizationMatcher";
|
||||
import { applyAddressLlmSemanticHintsToExtraction } from "./semanticHintOverlay";
|
||||
import type { AddressLlmSemanticHints } from "../../types/addressQuery";
|
||||
|
||||
@@ -393,6 +394,28 @@ function isInventoryLifecycleHistoryIntent(intent: AddressIntent | undefined): b
|
||||
);
|
||||
}
|
||||
|
||||
function shouldSuppressInventoryCounterpartyAlias(
|
||||
intent: AddressIntent,
|
||||
counterparty: string | null,
|
||||
organization: string | null
|
||||
): boolean {
|
||||
if (intent !== "inventory_on_hand_as_of_date") {
|
||||
return false;
|
||||
}
|
||||
if (!counterparty || !organization) {
|
||||
return false;
|
||||
}
|
||||
if (organizationsLikelySameEntity(counterparty, organization)) {
|
||||
return true;
|
||||
}
|
||||
const counterpartyNorm = normalizeOrganizationScopeSearchText(counterparty);
|
||||
const organizationNorm = normalizeOrganizationScopeSearchText(organization);
|
||||
if (!counterpartyNorm || !organizationNorm) {
|
||||
return false;
|
||||
}
|
||||
return organizationNorm.includes(counterpartyNorm) || counterpartyNorm.includes(organizationNorm);
|
||||
}
|
||||
|
||||
function buildInventoryRootFollowupContext(
|
||||
followupContext: AddressFollowupContext | null
|
||||
): AddressFollowupContext | null {
|
||||
@@ -820,12 +843,29 @@ function mergeFollowupFilters(
|
||||
const allTimeRequested = hasAllTimeHint(userMessage);
|
||||
const sameDateRequested = hasSameDateHint(userMessage) || hasSameDatePrepositionHint(userMessage);
|
||||
const samePeriodRequested = hasSamePeriodHint(userMessage);
|
||||
const hasFollowupSignal = hasAddressFollowupContextSignal(userMessage);
|
||||
const hasExplicitPeriodInMessage = hasExplicitPeriodLiteral(userMessage);
|
||||
const hasExplicitCurrentDateInMessage = hasExplicitCurrentDateHint(userMessage);
|
||||
const explicitQuotedItem = extractSelectedObjectItemFromFollowupText(userMessage);
|
||||
if (!toNonEmptyString(merged.organization) && previousOrganization) {
|
||||
merged.organization = previousOrganization;
|
||||
reasons.push("organization_from_followup_context");
|
||||
}
|
||||
|
||||
if (
|
||||
intent === "inventory_on_hand_as_of_date" &&
|
||||
followupContext.previous_intent === "inventory_on_hand_as_of_date" &&
|
||||
followupContext.target_intent === "inventory_on_hand_as_of_date" &&
|
||||
followupContext.previous_anchor_type === "organization" &&
|
||||
!hasFollowupSignal &&
|
||||
!hasExplicitPeriodInMessage &&
|
||||
!hasExplicitCurrentDateInMessage &&
|
||||
toNonEmptyString(merged.counterparty)
|
||||
) {
|
||||
delete merged.counterparty;
|
||||
reasons.push("counterparty_cleared_from_organization_clarification_selection");
|
||||
}
|
||||
|
||||
if (
|
||||
intent === "list_documents_by_counterparty" ||
|
||||
intent === "bank_operations_by_counterparty" ||
|
||||
@@ -835,11 +875,33 @@ function mergeFollowupFilters(
|
||||
previousCounterparty ??
|
||||
(followupContext.previous_anchor_type === "counterparty" ? previousAnchorValue : null);
|
||||
const currentCounterparty = toNonEmptyString(merged.counterparty);
|
||||
const organizationReference =
|
||||
toNonEmptyString(merged.organization) ??
|
||||
previousOrganization ??
|
||||
(followupContext.previous_anchor_type === "organization" ? previousAnchorValue : null);
|
||||
const currentCounterpartyLooksLikeOrganization = shouldSuppressInventoryCounterpartyAlias(
|
||||
intent,
|
||||
currentCounterparty,
|
||||
organizationReference
|
||||
);
|
||||
const inheritedCounterpartyLooksLikeOrganization = shouldSuppressInventoryCounterpartyAlias(
|
||||
intent,
|
||||
inheritedCounterparty,
|
||||
organizationReference
|
||||
);
|
||||
if (!currentCounterparty && inheritedCounterpartyLooksLikeOrganization) {
|
||||
reasons.push("counterparty_cleared_as_organization_scope_alias");
|
||||
}
|
||||
if (currentCounterpartyLooksLikeOrganization) {
|
||||
delete merged.counterparty;
|
||||
reasons.push("counterparty_cleared_as_organization_scope_alias");
|
||||
}
|
||||
const shouldInheritCounterparty =
|
||||
!currentCounterparty ||
|
||||
(Boolean(inheritedCounterparty) &&
|
||||
isLowQualityCounterpartyAnchor(currentCounterparty) &&
|
||||
!isLowQualityCounterpartyAnchor(inheritedCounterparty));
|
||||
!inheritedCounterpartyLooksLikeOrganization &&
|
||||
(!currentCounterparty ||
|
||||
(Boolean(inheritedCounterparty) &&
|
||||
isLowQualityCounterpartyAnchor(currentCounterparty) &&
|
||||
!isLowQualityCounterpartyAnchor(inheritedCounterparty)));
|
||||
if (inheritedCounterparty && shouldInheritCounterparty) {
|
||||
merged.counterparty = inheritedCounterparty;
|
||||
reasons.push(currentCounterparty ? "counterparty_replaced_from_followup_context" : "counterparty_from_followup_context");
|
||||
@@ -925,7 +987,7 @@ function mergeFollowupFilters(
|
||||
intent === "vat_payable_forecast" ||
|
||||
intent === "vat_liability_confirmed_for_tax_period"
|
||||
) {
|
||||
const hasFollowupSignalForConfirmed = hasAddressFollowupContextSignal(userMessage);
|
||||
const hasFollowupSignalForConfirmed = hasFollowupSignal;
|
||||
const inheritedContract = previousContract ?? (followupContext.previous_anchor_type === "contract" ? previousAnchorValue : null);
|
||||
const currentContract = toNonEmptyString(merged.contract);
|
||||
const shouldInheritContract =
|
||||
@@ -1189,9 +1251,6 @@ function mergeFollowupFilters(
|
||||
}
|
||||
}
|
||||
|
||||
const hasFollowupSignal = hasAddressFollowupContextSignal(userMessage);
|
||||
const hasExplicitPeriodInMessage = hasExplicitPeriodLiteral(userMessage);
|
||||
const hasExplicitCurrentDateInMessage = hasExplicitCurrentDateHint(userMessage);
|
||||
const inventoryLifecycleHistoryIntent = isInventoryLifecycleHistoryIntent(intent);
|
||||
const asOfPrimaryIntent =
|
||||
intent === "account_balance_snapshot" ||
|
||||
@@ -1209,6 +1268,19 @@ function mergeFollowupFilters(
|
||||
intent === "vat_payable_confirmed_as_of_date";
|
||||
const currentHasPeriod = hasExplicitPeriodWindow(merged);
|
||||
const previousHasPeriod = hasExplicitPeriodWindow(previous);
|
||||
const currentCounterpartyExplicit = toNonEmptyString(merged.counterparty);
|
||||
const currentContractExplicit = toNonEmptyString(merged.contract);
|
||||
const currentItemExplicit = toNonEmptyString(merged.item);
|
||||
const currentAccountExplicit = toNonEmptyString(merged.account);
|
||||
const shouldSuppressGenericPeriodCarryover =
|
||||
(Boolean(currentCounterpartyExplicit) &&
|
||||
!isLowQualityCounterpartyAnchor(currentCounterpartyExplicit) &&
|
||||
currentCounterpartyExplicit !== previousCounterparty) ||
|
||||
(Boolean(currentContractExplicit) &&
|
||||
!isLowQualityContractAnchor(currentContractExplicit) &&
|
||||
currentContractExplicit !== previousContract) ||
|
||||
(Boolean(currentItemExplicit) && currentItemExplicit !== previousItem) ||
|
||||
(Boolean(currentAccountExplicit) && currentAccountExplicit !== previousAccount);
|
||||
const vatRelativeMonthFollowup =
|
||||
relativeMonthFromFollowupYear &&
|
||||
(intent === "vat_payable_confirmed_as_of_date" ||
|
||||
@@ -1254,7 +1326,8 @@ function mergeFollowupFilters(
|
||||
hasFollowupSignal &&
|
||||
!hasExplicitPeriodInMessage &&
|
||||
!inventoryLifecycleHistoryIntent &&
|
||||
!vatRelativeMonthFollowup
|
||||
!vatRelativeMonthFollowup &&
|
||||
!shouldSuppressGenericPeriodCarryover
|
||||
) {
|
||||
if (previousPeriodFrom) {
|
||||
merged.period_from = previousPeriodFrom;
|
||||
@@ -1295,6 +1368,18 @@ function mergeFollowupFilters(
|
||||
}
|
||||
}
|
||||
|
||||
const finalOrganizationReference =
|
||||
toNonEmptyString(merged.organization) ??
|
||||
previousOrganization ??
|
||||
(followupContext.previous_anchor_type === "organization" ? previousAnchorValue : null);
|
||||
const finalCounterparty = toNonEmptyString(merged.counterparty);
|
||||
if (shouldSuppressInventoryCounterpartyAlias(intent, finalCounterparty, finalOrganizationReference)) {
|
||||
delete merged.counterparty;
|
||||
if (!reasons.includes("counterparty_cleared_as_organization_scope_alias")) {
|
||||
reasons.push("counterparty_cleared_as_organization_scope_alias");
|
||||
}
|
||||
}
|
||||
|
||||
return { filters: merged, reasons };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user