АДРЕСНЫЙ РЕЖИМ - M2.3c микро набор вопросов отрабатывается коректно
This commit is contained in:
@@ -78,11 +78,29 @@ function cleanupAnchorValue(value) {
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
// Remove trailing period qualifiers that can be swallowed by broad anchor regexes:
|
||||
// "<counterparty> с 2020-07-01 по 2020-07-31", "<counterparty> from 2020-07-01 to 2020-07-31"
|
||||
const periodTailPattern = /\s+(?:с\s+\d{1,4}[./-]\d{1,2}[./-]\d{1,4}|from\s+\d{1,4}[./-]\d{1,2}[./-]\d{1,4}|between\s+\d{1,4}[./-]\d{1,2}[./-]\d{1,4}|за\s+период)(?:\s+|$)[\s\S]*$/iu;
|
||||
if (periodTailPattern.test(normalized)) {
|
||||
return normalized.replace(periodTailPattern, "").trim();
|
||||
}
|
||||
const allTimeTailPattern = /\s+за\s+вс[её]\s+время(?:\s+|$)[\s\S]*$/iu;
|
||||
if (allTimeTailPattern.test(normalized)) {
|
||||
return normalized.replace(allTimeTailPattern, "").trim();
|
||||
}
|
||||
const allTimeTailPatternEn = /\s+(?:for\s+all\s+time|all\s+time)(?:\s+|$)[\s\S]*$/iu;
|
||||
if (allTimeTailPatternEn.test(normalized)) {
|
||||
return normalized.replace(allTimeTailPatternEn, "").trim();
|
||||
}
|
||||
return normalized
|
||||
.replace(/\s+(?:from|to|between|and)\b[\s\S]*$/i, "")
|
||||
.replace(/\s+(?:с|по|за)\b[\s\S]*$/i, "")
|
||||
.replace(/\s+(?:from|to|between|and)(?:\s+|$)[\s\S]*$/iu, "")
|
||||
.replace(/\s+(?:с|по|за)(?:\s+|$)[\s\S]*$/iu, "")
|
||||
.trim();
|
||||
}
|
||||
function hasAllTimeHint(text) {
|
||||
const value = String(text ?? "");
|
||||
return /(?:за\s+вс[её]\s+время|for\s+all\s+time|all\s+time)/iu.test(value);
|
||||
}
|
||||
function shiftDaysIso(baseIso, deltaDays) {
|
||||
const date = new Date(`${baseIso}T00:00:00.000Z`);
|
||||
date.setUTCDate(date.getUTCDate() + deltaDays);
|
||||
@@ -140,7 +158,8 @@ function extractAddressFilters(userMessage, intent) {
|
||||
// For document/bank lists we default to a short recent window if no explicit period was provided.
|
||||
if ((intent === "list_documents_by_counterparty" || intent === "bank_operations_by_counterparty") &&
|
||||
!filters.period_from &&
|
||||
!filters.period_to) {
|
||||
!filters.period_to &&
|
||||
!hasAllTimeHint(text)) {
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
filters.period_to = today;
|
||||
filters.period_from = shiftDaysIso(today, -90);
|
||||
|
||||
@@ -162,6 +162,16 @@ function buildWhereClause(filters, fieldPath) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function shouldBoostLimitForAllTimeCounterparty(filters) {
|
||||
const hasCounterparty = typeof filters.counterparty === "string" && filters.counterparty.trim().length > 0;
|
||||
if (!hasCounterparty) {
|
||||
return false;
|
||||
}
|
||||
const hasPeriod = Boolean((typeof filters.period_from === "string" && filters.period_from.trim().length > 0) ||
|
||||
(typeof filters.period_to === "string" && filters.period_to.trim().length > 0) ||
|
||||
(typeof filters.as_of_date === "string" && filters.as_of_date.trim().length > 0));
|
||||
return !hasPeriod;
|
||||
}
|
||||
function selectAddressRecipe(intent, filters) {
|
||||
const recipe = BASE_RECIPES.find((item) => item.intent === intent) ?? null;
|
||||
if (!recipe) {
|
||||
@@ -182,9 +192,14 @@ function selectAddressRecipe(intent, filters) {
|
||||
};
|
||||
}
|
||||
function buildAddressRecipePlan(recipe, filters) {
|
||||
const resolvedLimit = typeof filters.limit === "number" && Number.isFinite(filters.limit)
|
||||
const baseLimit = typeof filters.limit === "number" && Number.isFinite(filters.limit)
|
||||
? Math.max(1, Math.min(200, Math.trunc(filters.limit)))
|
||||
: recipe.default_limit;
|
||||
const boostedLimit = (recipe.intent === "list_documents_by_counterparty" || recipe.intent === "bank_operations_by_counterparty") &&
|
||||
shouldBoostLimitForAllTimeCounterparty(filters)
|
||||
? Math.max(baseLimit, 200)
|
||||
: baseLimit;
|
||||
const resolvedLimit = Math.max(1, Math.min(200, boostedLimit));
|
||||
const accountScope = (recipe.intent === "account_balance_snapshot" || recipe.intent === "documents_forming_balance") && filters.account
|
||||
? [String(filters.account)]
|
||||
: Array.isArray(recipe.account_scope)
|
||||
|
||||
Reference in New Issue
Block a user