АДРЕСНЫЙ РЕЖИМ - M2.3b тюнинг account-scope и диагностика стадий адресного рантайма
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
import type { AddressIntentResolution } from "../types/addressQuery";
|
||||
|
||||
const RECEIVABLES_STRONG = [
|
||||
"кто должен нам",
|
||||
"нам должны",
|
||||
"who owes us",
|
||||
"receivable",
|
||||
"receivables",
|
||||
"debtor",
|
||||
"debtors",
|
||||
"дебитор",
|
||||
"дебиторск"
|
||||
];
|
||||
|
||||
const PAYABLES_STRONG = [
|
||||
"кому должны мы",
|
||||
"мы должны",
|
||||
"who we owe",
|
||||
"payable",
|
||||
"payables",
|
||||
"creditor",
|
||||
"creditors",
|
||||
"кредитор",
|
||||
"кредиторск"
|
||||
];
|
||||
|
||||
const ACCOUNT_BALANCE_HINTS = [
|
||||
"account balance",
|
||||
"balance by account",
|
||||
"saldo",
|
||||
"остаток по счет",
|
||||
"сальдо по счет",
|
||||
"по счету"
|
||||
];
|
||||
|
||||
const DOCUMENTS_FORMING_BALANCE_HINTS = [
|
||||
"documents forming balance",
|
||||
"documents form balance",
|
||||
"balance documents",
|
||||
"documents for balance",
|
||||
"which documents form balance",
|
||||
"из чего состоит остаток",
|
||||
"какие документы формируют остаток",
|
||||
"раскрой остаток по документам",
|
||||
"документы под остатком"
|
||||
];
|
||||
|
||||
const OPEN_CONTRACTS_HINTS = [
|
||||
"open contracts",
|
||||
"unclosed contracts",
|
||||
"незакрыт",
|
||||
"не закрыт",
|
||||
"открыт",
|
||||
"договор"
|
||||
];
|
||||
|
||||
const OPEN_ITEMS_HINTS = [
|
||||
"open items",
|
||||
"unclosed items",
|
||||
"хвост",
|
||||
"висят",
|
||||
"незакрыт",
|
||||
"открыт",
|
||||
"позици"
|
||||
];
|
||||
|
||||
const DOCUMENTS_BY_COUNTERPARTY_HINTS = [
|
||||
"documents by counterparty",
|
||||
"docs by counterparty",
|
||||
"show documents by counterparty",
|
||||
"list documents by counterparty",
|
||||
"документ",
|
||||
"по контрагент"
|
||||
];
|
||||
|
||||
const BANK_OPERATIONS_BY_COUNTERPARTY_HINTS = [
|
||||
"bank operations by counterparty",
|
||||
"bank payments by counterparty",
|
||||
"payment orders by counterparty",
|
||||
"show bank operations by counterparty",
|
||||
"банков",
|
||||
"выписк",
|
||||
"платеж"
|
||||
];
|
||||
|
||||
function hasAny(text: string, patterns: string[]): boolean {
|
||||
return patterns.some((item) => text.includes(item));
|
||||
}
|
||||
|
||||
function hasAccountNumberAnchor(text: string): boolean {
|
||||
return /(?:account|сч[её]т|счет)\D{0,12}\d{2}(?:[.,]\d{1,2})?/i.test(text);
|
||||
}
|
||||
|
||||
export function resolveAddressIntent(userMessage: string): AddressIntentResolution {
|
||||
const text = String(userMessage ?? "").trim().toLowerCase();
|
||||
|
||||
if (hasAny(text, RECEIVABLES_STRONG)) {
|
||||
return {
|
||||
intent: "list_receivables_counterparties",
|
||||
confidence: "high",
|
||||
reasons: ["receivables_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAny(text, PAYABLES_STRONG)) {
|
||||
return {
|
||||
intent: "list_payables_counterparties",
|
||||
confidence: "high",
|
||||
reasons: ["payables_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAny(text, DOCUMENTS_FORMING_BALANCE_HINTS) && (hasAccountNumberAnchor(text) || text.includes("счет"))) {
|
||||
return {
|
||||
intent: "documents_forming_balance",
|
||||
confidence: "high",
|
||||
reasons: ["documents_forming_balance_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAny(text, ACCOUNT_BALANCE_HINTS) || hasAccountNumberAnchor(text)) {
|
||||
return {
|
||||
intent: "account_balance_snapshot",
|
||||
confidence: "high",
|
||||
reasons: ["account_balance_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
hasAny(text, BANK_OPERATIONS_BY_COUNTERPARTY_HINTS) &&
|
||||
(text.includes("контраг") || text.includes("counterparty"))
|
||||
) {
|
||||
return {
|
||||
intent: "bank_operations_by_counterparty",
|
||||
confidence: "medium",
|
||||
reasons: ["bank_ops_by_counterparty_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
hasAny(text, DOCUMENTS_BY_COUNTERPARTY_HINTS) &&
|
||||
(text.includes("контраг") || text.includes("counterparty"))
|
||||
) {
|
||||
return {
|
||||
intent: "list_documents_by_counterparty",
|
||||
confidence: "medium",
|
||||
reasons: ["documents_by_counterparty_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAny(text, OPEN_ITEMS_HINTS) && (text.includes("контраг") || text.includes("договор") || text.includes("counterparty") || text.includes("contract"))) {
|
||||
return {
|
||||
intent: "open_items_by_counterparty_or_contract",
|
||||
confidence: "medium",
|
||||
reasons: ["open_items_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAny(text, OPEN_CONTRACTS_HINTS) && (text.includes("договор") || text.includes("contract"))) {
|
||||
return {
|
||||
intent: "list_open_contracts",
|
||||
confidence: "medium",
|
||||
reasons: ["open_contract_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
intent: "unknown",
|
||||
confidence: "low",
|
||||
reasons: ["intent_not_supported_in_v1"]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user