116 lines
2.6 KiB
JavaScript
116 lines
2.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.detectAddressQuestionMode = detectAddressQuestionMode;
|
|
const ADDRESS_ACTION_TOKENS = [
|
|
"show",
|
|
"list",
|
|
"find",
|
|
"get",
|
|
"lookup",
|
|
"open",
|
|
"balance",
|
|
"debt",
|
|
"owe",
|
|
"покажи",
|
|
"список",
|
|
"найди",
|
|
"выведи",
|
|
"кто",
|
|
"кому",
|
|
"какие",
|
|
"остаток",
|
|
"долг",
|
|
"задолж",
|
|
"хвост",
|
|
"незакрыт"
|
|
];
|
|
const ADDRESS_ENTITY_TOKENS = [
|
|
"counterparty",
|
|
"counterparties",
|
|
"contract",
|
|
"contracts",
|
|
"account",
|
|
"accounts",
|
|
"document",
|
|
"documents",
|
|
"balance",
|
|
"payable",
|
|
"payables",
|
|
"receivable",
|
|
"receivables",
|
|
"owe",
|
|
"owes",
|
|
"owed",
|
|
"контрагент",
|
|
"договор",
|
|
"счет",
|
|
"счёт",
|
|
"документ",
|
|
"остаток",
|
|
"дебитор",
|
|
"кредитор",
|
|
"аванс",
|
|
"оплат",
|
|
"долг",
|
|
"должен",
|
|
"должны",
|
|
"должна"
|
|
];
|
|
const DEEP_REASONING_TOKENS = [
|
|
"why",
|
|
"because",
|
|
"root cause",
|
|
"mechanism",
|
|
"prove",
|
|
"chain",
|
|
"почему",
|
|
"причин",
|
|
"механизм",
|
|
"докажи",
|
|
"цепоч",
|
|
"разрыв",
|
|
"ошибк"
|
|
];
|
|
function hasAnyToken(text, tokens) {
|
|
return tokens.some((token) => text.includes(token));
|
|
}
|
|
function detectAddressQuestionMode(userMessage) {
|
|
const text = String(userMessage ?? "").trim().toLowerCase();
|
|
if (!text) {
|
|
return {
|
|
mode: "unsupported",
|
|
confidence: "low",
|
|
reasons: ["empty_message"]
|
|
};
|
|
}
|
|
const hasAddressAction = hasAnyToken(text, ADDRESS_ACTION_TOKENS);
|
|
const hasAddressEntity = hasAnyToken(text, ADDRESS_ENTITY_TOKENS);
|
|
const hasDeepReasoning = hasAnyToken(text, DEEP_REASONING_TOKENS);
|
|
if (hasAddressAction && hasAddressEntity && !hasDeepReasoning) {
|
|
return {
|
|
mode: "address_query",
|
|
confidence: "high",
|
|
reasons: ["address_action_detected", "address_entity_detected"]
|
|
};
|
|
}
|
|
if (hasAddressEntity && !hasDeepReasoning) {
|
|
return {
|
|
mode: "address_query",
|
|
confidence: "medium",
|
|
reasons: ["address_entity_detected"]
|
|
};
|
|
}
|
|
if (hasDeepReasoning) {
|
|
return {
|
|
mode: "deep_analysis",
|
|
confidence: "high",
|
|
reasons: ["deep_reasoning_signal_detected"]
|
|
};
|
|
}
|
|
return {
|
|
mode: "unsupported",
|
|
confidence: "low",
|
|
reasons: ["no_address_or_deep_signal"]
|
|
};
|
|
}
|