АРЧ АП11 - Архитектура: вынести counterparty intent-family из resolveAddressIntent и обновить pre-expansion cut
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
import type { AddressIntentResolution } from "../types/addressQuery";
|
||||
|
||||
type HintList = string[];
|
||||
|
||||
type CounterpartyIntentDeps = {
|
||||
hasAny: (text: string, hints: string[]) => boolean;
|
||||
openItemsHints: HintList;
|
||||
openContractsHints: HintList;
|
||||
documentsByCounterpartyHints: HintList;
|
||||
bankOperationsByCounterpartyHints: HintList;
|
||||
documentsByContractHints: HintList;
|
||||
hasCounterpartyDebtLongevitySignal: (text: string) => boolean;
|
||||
hasInventoryAgingSignal: (text: string) => boolean;
|
||||
hasInventoryProvenanceSignalV2: (text: string) => boolean;
|
||||
hasInventoryPurchaseDocumentsSignalV2: (text: string) => boolean;
|
||||
hasInventorySaleTraceSignalV2: (text: string) => boolean;
|
||||
hasAccountNumberAnchor: (text: string) => boolean;
|
||||
hasCompactAccountCodeToken: (text: string) => boolean;
|
||||
hasPeriodCoverageProfileSignal: (text: string) => boolean;
|
||||
hasPartyAnchorMention: (text: string) => boolean;
|
||||
hasContractAnchorSignal: (text: string) => boolean;
|
||||
hasAccountBalanceSignal: (text: string) => boolean;
|
||||
hasDocumentTypeAndAccountSectionProfileSignal: (text: string) => boolean;
|
||||
hasCounterpartyPopulationAndRolesSignal: (text: string) => boolean;
|
||||
hasCounterpartyActivityLifecycleSignal: (text: string) => boolean;
|
||||
hasContractUsageOverviewSignal: (text: string) => boolean;
|
||||
hasOpenContractsListSignal: (text: string) => boolean;
|
||||
hasCustomerRevenueAndPaymentsSignal: (text: string) => boolean;
|
||||
hasSupplierPayoutsProfileSignal: (text: string) => boolean;
|
||||
hasContractUsageAndValueSignal: (text: string) => boolean;
|
||||
hasContractListByCounterpartySignal: (text: string) => boolean;
|
||||
hasBankOperationSignal: (text: string) => boolean;
|
||||
hasDocumentSignal: (text: string) => boolean;
|
||||
hasLooseByAnchorMention: (text: string) => boolean;
|
||||
hasHeuristicCounterpartyAnchor: (text: string) => boolean;
|
||||
hasCounterpartyShipmentItemFlowSignal: (text: string) => boolean;
|
||||
hasImplicitCounterpartyAnchorAroundDocs: (text: string) => boolean;
|
||||
hasGenericAddressLookupSignal: (text: string) => boolean;
|
||||
};
|
||||
|
||||
export function resolveCounterpartyAddressIntent(
|
||||
text: string,
|
||||
deps: CounterpartyIntentDeps
|
||||
): AddressIntentResolution | null {
|
||||
if (deps.hasOpenContractsListSignal(text)) {
|
||||
return {
|
||||
intent: "open_contracts_confirmed_as_of_date",
|
||||
confidence: "medium",
|
||||
reasons: ["open_contract_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasAny(text, deps.openItemsHints) &&
|
||||
!deps.hasCounterpartyDebtLongevitySignal(text) &&
|
||||
!deps.hasInventoryAgingSignal(text) &&
|
||||
!deps.hasInventoryProvenanceSignalV2(text) &&
|
||||
!deps.hasInventoryPurchaseDocumentsSignalV2(text) &&
|
||||
!deps.hasInventorySaleTraceSignalV2(text) &&
|
||||
(
|
||||
/(?:контраг|договор|контракт|counterparty|contract|покупател|клиент|заказчик|customer|client|buyer|supplier|поставщик)/iu.test(
|
||||
text
|
||||
) ||
|
||||
deps.hasAccountNumberAnchor(text) ||
|
||||
deps.hasCompactAccountCodeToken(text)
|
||||
)
|
||||
) {
|
||||
return {
|
||||
intent: "open_items_by_counterparty_or_contract",
|
||||
confidence: "medium",
|
||||
reasons: ["open_items_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasPeriodCoverageProfileSignal(text) &&
|
||||
!deps.hasPartyAnchorMention(text) &&
|
||||
!deps.hasContractAnchorSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "period_coverage_profile",
|
||||
confidence: "high",
|
||||
reasons: ["period_coverage_profile_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasDocumentTypeAndAccountSectionProfileSignal(text) &&
|
||||
!deps.hasPartyAnchorMention(text) &&
|
||||
!deps.hasContractAnchorSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "document_type_and_account_section_profile",
|
||||
confidence: "high",
|
||||
reasons: ["document_type_and_account_section_profile_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasCounterpartyPopulationAndRolesSignal(text) &&
|
||||
!deps.hasContractAnchorSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "counterparty_population_and_roles",
|
||||
confidence: "high",
|
||||
reasons: ["counterparty_population_and_roles_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasCounterpartyActivityLifecycleSignal(text) &&
|
||||
!deps.hasContractAnchorSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "counterparty_activity_lifecycle",
|
||||
confidence: "high",
|
||||
reasons: ["counterparty_activity_lifecycle_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasContractUsageOverviewSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text) &&
|
||||
!deps.hasOpenContractsListSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "contract_usage_overview",
|
||||
confidence: "high",
|
||||
reasons: ["contract_usage_overview_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasCustomerRevenueAndPaymentsSignal(text) && !deps.hasAccountBalanceSignal(text)) {
|
||||
return {
|
||||
intent: "customer_revenue_and_payments",
|
||||
confidence: "high",
|
||||
reasons: ["customer_revenue_and_payments_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasSupplierPayoutsProfileSignal(text) && !deps.hasAccountBalanceSignal(text)) {
|
||||
return {
|
||||
intent: "supplier_payouts_profile",
|
||||
confidence: "high",
|
||||
reasons: ["supplier_payouts_profile_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasContractUsageAndValueSignal(text) &&
|
||||
!deps.hasAccountBalanceSignal(text) &&
|
||||
!deps.hasOpenContractsListSignal(text)
|
||||
) {
|
||||
return {
|
||||
intent: "contract_usage_and_value",
|
||||
confidence: "high",
|
||||
reasons: ["contract_usage_and_value_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasContractListByCounterpartySignal(text)) {
|
||||
return {
|
||||
intent: "list_contracts_by_counterparty",
|
||||
confidence: "medium",
|
||||
reasons: ["contracts_by_counterparty_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasContractAnchorSignal(text) && deps.hasBankOperationSignal(text)) {
|
||||
return {
|
||||
intent: "bank_operations_by_contract",
|
||||
confidence: "medium",
|
||||
reasons: ["bank_ops_by_contract_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasContractAnchorSignal(text) &&
|
||||
(deps.hasAny(text, deps.documentsByContractHints) || deps.hasDocumentSignal(text))
|
||||
) {
|
||||
return {
|
||||
intent: "list_documents_by_contract",
|
||||
confidence: "medium",
|
||||
reasons: ["documents_by_contract_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasAny(text, deps.bankOperationsByCounterpartyHints) &&
|
||||
(deps.hasPartyAnchorMention(text) || deps.hasLooseByAnchorMention(text) || deps.hasHeuristicCounterpartyAnchor(text))
|
||||
) {
|
||||
return {
|
||||
intent: "bank_operations_by_counterparty",
|
||||
confidence: "medium",
|
||||
reasons: ["bank_ops_by_counterparty_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
(deps.hasAny(text, deps.documentsByCounterpartyHints) || deps.hasCounterpartyShipmentItemFlowSignal(text)) &&
|
||||
(deps.hasPartyAnchorMention(text) ||
|
||||
deps.hasLooseByAnchorMention(text) ||
|
||||
deps.hasImplicitCounterpartyAnchorAroundDocs(text) ||
|
||||
deps.hasHeuristicCounterpartyAnchor(text) ||
|
||||
deps.hasCounterpartyShipmentItemFlowSignal(text))
|
||||
) {
|
||||
return {
|
||||
intent: "list_documents_by_counterparty",
|
||||
confidence: "medium",
|
||||
reasons: [
|
||||
deps.hasCounterpartyShipmentItemFlowSignal(text)
|
||||
? "counterparty_item_flow_signal_detected"
|
||||
: "documents_by_counterparty_signal_detected"
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasAccountBalanceSignal(text)) {
|
||||
return {
|
||||
intent: "account_balance_snapshot",
|
||||
confidence: "high",
|
||||
reasons: ["account_balance_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (deps.hasLooseByAnchorMention(text) && deps.hasGenericAddressLookupSignal(text)) {
|
||||
return {
|
||||
intent: "list_documents_by_counterparty",
|
||||
confidence: "low",
|
||||
reasons: ["generic_lookup_with_loose_anchor_fallback"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
deps.hasAny(text, deps.openContractsHints) &&
|
||||
(text.includes("договор") || text.includes("контракт") || text.includes("contract"))
|
||||
) {
|
||||
return {
|
||||
intent: "open_contracts_confirmed_as_of_date",
|
||||
confidence: "medium",
|
||||
reasons: ["open_contract_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AddressIntentResolution } from "../types/addressQuery";
|
||||
import { resolveCounterpartyAddressIntent } from "./addressCounterpartyIntentSignals";
|
||||
import { resolveInventoryAddressIntent } from "./addressInventoryIntentSignals";
|
||||
import {
|
||||
hasInventoryProfitabilityCue,
|
||||
@@ -2068,6 +2069,45 @@ export function resolveAddressIntent(userMessage: string): AddressIntentResoluti
|
||||
};
|
||||
}
|
||||
|
||||
const counterpartyIntent = resolveCounterpartyAddressIntent(text, {
|
||||
hasAny,
|
||||
openItemsHints: OPEN_ITEMS_HINTS,
|
||||
openContractsHints: OPEN_CONTRACTS_HINTS,
|
||||
documentsByCounterpartyHints: DOCUMENTS_BY_COUNTERPARTY_HINTS,
|
||||
bankOperationsByCounterpartyHints: BANK_OPERATIONS_BY_COUNTERPARTY_HINTS,
|
||||
documentsByContractHints: DOCUMENTS_BY_CONTRACT_HINTS,
|
||||
hasCounterpartyDebtLongevitySignal,
|
||||
hasInventoryAgingSignal,
|
||||
hasInventoryProvenanceSignalV2,
|
||||
hasInventoryPurchaseDocumentsSignalV2,
|
||||
hasInventorySaleTraceSignalV2,
|
||||
hasAccountNumberAnchor,
|
||||
hasCompactAccountCodeToken,
|
||||
hasPeriodCoverageProfileSignal,
|
||||
hasPartyAnchorMention,
|
||||
hasContractAnchorSignal,
|
||||
hasAccountBalanceSignal,
|
||||
hasDocumentTypeAndAccountSectionProfileSignal,
|
||||
hasCounterpartyPopulationAndRolesSignal,
|
||||
hasCounterpartyActivityLifecycleSignal,
|
||||
hasContractUsageOverviewSignal,
|
||||
hasOpenContractsListSignal,
|
||||
hasCustomerRevenueAndPaymentsSignal,
|
||||
hasSupplierPayoutsProfileSignal,
|
||||
hasContractUsageAndValueSignal,
|
||||
hasContractListByCounterpartySignal,
|
||||
hasBankOperationSignal,
|
||||
hasDocumentSignal,
|
||||
hasLooseByAnchorMention,
|
||||
hasHeuristicCounterpartyAnchor,
|
||||
hasCounterpartyShipmentItemFlowSignal,
|
||||
hasImplicitCounterpartyAnchorAroundDocs,
|
||||
hasGenericAddressLookupSignal
|
||||
});
|
||||
if (counterpartyIntent) {
|
||||
return counterpartyIntent;
|
||||
}
|
||||
|
||||
if (hasOpenContractsListSignal(text)) {
|
||||
return {
|
||||
intent: "open_contracts_confirmed_as_of_date",
|
||||
|
||||
Reference in New Issue
Block a user