АРЧ АП11 - Commit title: Добавить контрактный слой переходов и capability-деклараций ассистента
This commit is contained in:
@@ -1040,12 +1040,78 @@ function trimInventoryItemArrowSuffix(rawValue) {
|
||||
return cleanupAnchorValue(cleanupAnchorValue(rawValue).replace(/\s*(?:->|=>|→).+$/u, ""));
|
||||
}
|
||||
function isTemporalWarehousePhrase(candidate) {
|
||||
const temporalZaPattern = /^(?:за)\s+(?:январ(?:е|ь)|феврал(?:е|ь)|март(?:е)?|апрел(?:е|ь)|ма(?:й|е)|июн(?:е|ь)|июл(?:е|ь)|август(?:е)?|сентябр(?:е|ь)|октябр(?:е|ь)|ноябр(?:е|ь)|декабр(?:е|ь))(?:\s+\d{4}(?:\s+г(?:\.|ода)?)?)?$/iu;
|
||||
if (temporalZaPattern.test(cleanupAnchorValue(candidate).toLowerCase().replace(/ё/g, "е").trim())) {
|
||||
return true;
|
||||
}
|
||||
const normalized = cleanupAnchorValue(candidate)
|
||||
.toLowerCase()
|
||||
.replace(/ё/g, "е")
|
||||
.trim();
|
||||
return /^(?:в|на)\s+(?:январ(?:е|ь)|феврал(?:е|ь)|март(?:е)?|апрел(?:е|ь)|ма(?:й|е)|июн(?:е|ь)|июл(?:е|ь)|август(?:е)?|сентябр(?:е|ь)|октябр(?:е|ь)|ноябр(?:е|ь)|декабр(?:е|ь))(?:\s+\d{4}(?:\s+г(?:\.|ода)?)?)?$/iu.test(normalized);
|
||||
}
|
||||
function isLowQualityWarehouseAnchorValue(rawValue) {
|
||||
const value = cleanupAnchorValue(rawValue)
|
||||
.toLowerCase()
|
||||
.replace(/ё/g, "е")
|
||||
.trim();
|
||||
if (!value) {
|
||||
return true;
|
||||
}
|
||||
if (isTemporalWarehousePhrase(value) || isImplicitSelfScopeWarehouseAnchor(value)) {
|
||||
return true;
|
||||
}
|
||||
const hasQuestionOrRepairCue = /(?:^|[\s,.;:!?()\-])(?:что|какой|какая|какие|как|где|когда|почему|зачем|имел(?:ось|ся)\s+в\s+виду|имеется\s+в\s+виду|в\s+смысле|то\s+есть|which|what|where|when|why)(?=$|[\s,.;:!?()\-])/iu.test(value) || /[?]/u.test(rawValue);
|
||||
const hasProfanityCue = /(?:^|[\s,.;:!?()\-])(?:аху|оху|хуе|хуё|хуй|ебан|ебуч|бля|блять|пизд|нахуй|shit|fuck|damn)(?=$|[\s,.;:!?()\-])/iu.test(value);
|
||||
const lowQualityTokens = new Set([
|
||||
"что",
|
||||
"какой",
|
||||
"какая",
|
||||
"какие",
|
||||
"как",
|
||||
"где",
|
||||
"когда",
|
||||
"почему",
|
||||
"зачем",
|
||||
"имелось",
|
||||
"имелся",
|
||||
"имеется",
|
||||
"в",
|
||||
"виду",
|
||||
"то",
|
||||
"есть",
|
||||
"лежит",
|
||||
"лежат",
|
||||
"лежало",
|
||||
"лежали",
|
||||
"на",
|
||||
"по",
|
||||
"складе",
|
||||
"складу",
|
||||
"складом",
|
||||
"ебаном",
|
||||
"ахуеть",
|
||||
"охуеть",
|
||||
"пиздец",
|
||||
"блять",
|
||||
"бля"
|
||||
]);
|
||||
const tokens = value
|
||||
.split(/[^a-zа-я0-9]+/iu)
|
||||
.map((token) => token.trim())
|
||||
.filter(Boolean);
|
||||
if (tokens.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const meaningfulTokens = tokens.filter((token) => !lowQualityTokens.has(token) && token.length > 1);
|
||||
if (meaningfulTokens.length === 0) {
|
||||
return true;
|
||||
}
|
||||
if ((hasQuestionOrRepairCue || hasProfanityCue) && meaningfulTokens.length <= 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function normalizeSemanticAnchorCandidate(value) {
|
||||
return cleanupAnchorValue(value)
|
||||
.toLowerCase()
|
||||
@@ -1079,6 +1145,7 @@ function extractInventoryWarehouseAnchor(text) {
|
||||
candidate.includes("->") ||
|
||||
candidate.includes("=>") ||
|
||||
isImplicitSelfScopeWarehouseAnchor(candidate) ||
|
||||
isLowQualityWarehouseAnchorValue(candidate) ||
|
||||
normalizedCandidate.startsWith("по состоянию") ||
|
||||
isTemporalWarehousePhrase(candidate) ||
|
||||
/^(?:сейчас|на|дату|дате|остаток|остатки)$/iu.test(candidate)) {
|
||||
|
||||
@@ -1598,6 +1598,14 @@ function resolveAddressIntent(userMessage) {
|
||||
reasons: ["inventory_selected_object_sale_trace_signal_detected"]
|
||||
};
|
||||
}
|
||||
if (/(?:кому\s+(?:мы\s+)?впарили(?:\s+(?:это|его|товар|позицию))?|кому\s+в\s+итоге\s+мы\s+впарили)/iu.test(text) &&
|
||||
/(?:товар|номенклатур|sku|item|product|позици(?:я|ю|и)|продукци(?:я|ю|и))/iu.test(text)) {
|
||||
return {
|
||||
intent: "inventory_sale_trace_for_item",
|
||||
confidence: "medium",
|
||||
reasons: ["inventory_sale_trace_signal_detected"]
|
||||
};
|
||||
}
|
||||
if (hasInventorySaleTraceSignalV2(text)) {
|
||||
return {
|
||||
intent: "inventory_sale_trace_for_item",
|
||||
|
||||
@@ -1588,7 +1588,13 @@ function hasExplicitPeriodWindow(filters) {
|
||||
(typeof filters.period_to === "string" && filters.period_to.trim().length > 0));
|
||||
}
|
||||
function canAutoBroadenPeriodWindow(intent, filters) {
|
||||
if (!hasExplicitPeriodWindow(filters)) {
|
||||
const hasRecoverableAsOfOnlyWindow = !hasExplicitPeriodWindow(filters) &&
|
||||
typeof filters.as_of_date === "string" &&
|
||||
filters.as_of_date.trim().length > 0 &&
|
||||
typeof filters.item === "string" &&
|
||||
filters.item.trim().length > 0 &&
|
||||
(intent === "inventory_purchase_provenance_for_item" || intent === "inventory_purchase_documents_for_item");
|
||||
if (!hasExplicitPeriodWindow(filters) && !hasRecoverableAsOfOnlyWindow) {
|
||||
return false;
|
||||
}
|
||||
return (intent === "list_documents_by_counterparty" ||
|
||||
|
||||
@@ -32,6 +32,9 @@ function hasAllTimeHint(text) {
|
||||
function hasSameDateHint(text) {
|
||||
return /(?:на\s+ту\s+же\s+дат[ауеы]|на\s+эту\s+же\s+дат[ауеы]|на\s+эту\s+дат[ауеы]|эту\s+дат[ауеы]|та\s+же\s+дата|same\s+date|as\s+of\s+same\s+date|the\s+same\s+date)/iu.test(String(text ?? ""));
|
||||
}
|
||||
function hasSamePeriodHint(text) {
|
||||
return /(?:на\s+тот\s+же\s+период|за\s+тот\s+же\s+период|тот\s+же\s+период(?:\s+рассмотрения)?|на\s+этот\s+же\s+период|за\s+этот\s+же\s+период|аналогичн\w+\s+текущ\w+\s+период\w+|same\s+period|same\s+range|same\s+window)/iu.test(String(text ?? ""));
|
||||
}
|
||||
function hasExplicitPeriodLiteral(text) {
|
||||
return /(?:^|[^\d*×xх])((?:19|20)\d{2}(?:[./-](?:0?[1-9]|1[0-2]))?)(?=$|[^\d*×xх])/iu.test(String(text ?? ""));
|
||||
}
|
||||
@@ -383,10 +386,15 @@ function shouldRestoreInventoryRootFrame(userMessage, intent, extractedFilters,
|
||||
const currentFrameKind = followupContext.current_frame_kind ?? null;
|
||||
const previousIntent = followupContext.previous_intent;
|
||||
const comingFromInventoryDrilldown = currentFrameKind === "inventory_drilldown" || isInventoryDrilldownFrameIntent(previousIntent);
|
||||
if (!comingFromInventoryDrilldown) {
|
||||
const normalized = String(userMessage ?? "");
|
||||
const hasInventoryRootRestatementCue = /(?:склад|остат(?:ок|ки)|позици(?:я|и|ю)|товар(?:ы|ов)?|номенклатур)/iu.test(normalized) &&
|
||||
/(?:покажи|показать|выведи|раскрой|еще\s+раз|ещ[её]\s+раз|снова|опять|верни|вернись|повтори|тот\s+же|этот\s+же|same|again)/iu.test(normalized);
|
||||
const canReenterInventoryRoot = comingFromInventoryDrilldown ||
|
||||
(currentFrameKind === "inventory_root" && hasSamePeriodHint(normalized)) ||
|
||||
(currentFrameKind === "generic" && hasInventoryRootRestatementCue && hasSamePeriodHint(normalized));
|
||||
if (!canReenterInventoryRoot) {
|
||||
return false;
|
||||
}
|
||||
const normalized = String(userMessage ?? "");
|
||||
if (hasSelectedObjectInventorySignal(normalized) ||
|
||||
hasInventorySupplierFollowupCue(normalized) ||
|
||||
hasInventoryPurchaseDocumentsFollowupCue(normalized) ||
|
||||
@@ -401,6 +409,7 @@ function shouldRestoreInventoryRootFrame(userMessage, intent, extractedFilters,
|
||||
}
|
||||
const hasTemporalPatch = hasExplicitPeriodWindow(extractedFilters) ||
|
||||
Boolean(toNonEmptyString(extractedFilters.as_of_date)) ||
|
||||
hasSamePeriodHint(normalized) ||
|
||||
hasExplicitPeriodLiteral(normalized) ||
|
||||
Boolean(resolveRelativeMonthPeriodFromInventoryRoot(normalized, followupContext));
|
||||
return hasTemporalPatch;
|
||||
@@ -408,6 +417,26 @@ function shouldRestoreInventoryRootFrame(userMessage, intent, extractedFilters,
|
||||
function hasSelectedObjectInventorySignal(text) {
|
||||
return /(?:по\s+выбранному\s+объекту|for\s+selected\s+object)/iu.test(String(text ?? ""));
|
||||
}
|
||||
function hasSelectedObjectInlineSnapshotMetadata(text) {
|
||||
return /(?:дата\s+строки|строка\s+от|количество\s*:|стоимость\s*:|склад\s*:|организация\s*:|\|\s*(?:склад|количество|стоимость|организация|дата\s+строки)\s*:)/iu.test(String(text ?? ""));
|
||||
}
|
||||
function extractSelectedObjectItemFromFollowupText(text) {
|
||||
const rawSelectedObject = toNonEmptyString((0, addressFilterExtractor_1.extractSelectedObjectQuotedValue)(text));
|
||||
if (!rawSelectedObject) {
|
||||
return null;
|
||||
}
|
||||
const firstLine = rawSelectedObject
|
||||
.replace(/\r\n?/g, "\n")
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.find(Boolean);
|
||||
const primarySegment = String(firstLine ?? rawSelectedObject)
|
||||
.replace(/^\d+\.\s*/, "")
|
||||
.split("|")[0]
|
||||
?.trim();
|
||||
const normalized = toNonEmptyString(primarySegment);
|
||||
return normalized;
|
||||
}
|
||||
function hasInventorySupplierFollowupCue(text) {
|
||||
return (0, inventoryLifecycleCueHelpers_1.hasInventorySupplierCue)(String(text ?? ""));
|
||||
}
|
||||
@@ -506,6 +535,7 @@ function mergeFollowupFilters(current, intent, userMessage, followupContext) {
|
||||
const relativeMonthFromInventoryRoot = resolveRelativeMonthPeriodFromInventoryRoot(userMessage, followupContext);
|
||||
const allTimeRequested = hasAllTimeHint(userMessage);
|
||||
const sameDateRequested = hasSameDateHint(userMessage);
|
||||
const samePeriodRequested = hasSamePeriodHint(userMessage);
|
||||
if (!toNonEmptyString(merged.organization) && previousOrganization) {
|
||||
merged.organization = previousOrganization;
|
||||
reasons.push("organization_from_followup_context");
|
||||
@@ -618,7 +648,7 @@ function mergeFollowupFilters(current, intent, userMessage, followupContext) {
|
||||
intent === "inventory_purchase_to_sale_chain" ||
|
||||
intent === "inventory_aging_by_purchase_date")) {
|
||||
const inheritedItem = previousItem ?? previousAnchorItem;
|
||||
const explicitQuotedItem = toNonEmptyString((0, addressFilterExtractor_1.extractSelectedObjectQuotedValue)(userMessage));
|
||||
const explicitQuotedItem = extractSelectedObjectItemFromFollowupText(userMessage);
|
||||
const currentItem = toNonEmptyString(merged.item);
|
||||
const shouldAdoptExplicitQuotedItem = Boolean(explicitQuotedItem) &&
|
||||
(!currentItem ||
|
||||
@@ -653,6 +683,22 @@ function mergeFollowupFilters(current, intent, userMessage, followupContext) {
|
||||
reasons.push("as_of_date_from_followup_context");
|
||||
}
|
||||
}
|
||||
if (samePeriodRequested &&
|
||||
(intent === "inventory_on_hand_as_of_date" || intent === "inventory_supplier_stock_overlap_as_of_date")) {
|
||||
if (previousPeriodFrom && merged.period_from !== previousPeriodFrom) {
|
||||
merged.period_from = previousPeriodFrom;
|
||||
reasons.push("period_from_from_followup_context");
|
||||
}
|
||||
if (previousPeriodTo && merged.period_to !== previousPeriodTo) {
|
||||
merged.period_to = previousPeriodTo;
|
||||
reasons.push("period_to_from_followup_context");
|
||||
}
|
||||
const inheritedAsOfDate = previousAsOfDate ?? previousPeriodTo ?? previousPeriodFrom;
|
||||
if (inheritedAsOfDate && merged.as_of_date !== inheritedAsOfDate) {
|
||||
merged.as_of_date = inheritedAsOfDate;
|
||||
reasons.push("as_of_date_from_followup_context");
|
||||
}
|
||||
}
|
||||
if (!sameDateRequested &&
|
||||
(intent === "inventory_aging_by_purchase_date" || isInventoryLifecycleHistoryIntent(intent)) &&
|
||||
!hasExplicitPeriodLiteral(userMessage) &&
|
||||
@@ -668,6 +714,21 @@ function mergeFollowupFilters(current, intent, userMessage, followupContext) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((Boolean(previousPeriodFrom) || Boolean(previousPeriodTo)) &&
|
||||
hasSelectedObjectInventorySignal(userMessage) &&
|
||||
hasSelectedObjectInlineSnapshotMetadata(userMessage) &&
|
||||
(intent === "inventory_purchase_provenance_for_item" || intent === "inventory_purchase_documents_for_item") &&
|
||||
!hasExplicitPeriodLiteral(userMessage) &&
|
||||
!hasExplicitCurrentDateHint(userMessage)) {
|
||||
if (previousPeriodFrom && merged.period_from !== previousPeriodFrom) {
|
||||
merged.period_from = previousPeriodFrom;
|
||||
reasons.push("period_from_from_followup_context");
|
||||
}
|
||||
if (previousPeriodTo && merged.period_to !== previousPeriodTo) {
|
||||
merged.period_to = previousPeriodTo;
|
||||
reasons.push("period_to_from_followup_context");
|
||||
}
|
||||
}
|
||||
if (!sameDateRequested &&
|
||||
(intent === "inventory_on_hand_as_of_date" || intent === "inventory_supplier_stock_overlap_as_of_date") &&
|
||||
!hasExplicitPeriodLiteral(userMessage) &&
|
||||
|
||||
@@ -38,6 +38,47 @@ function findLastGroundedInventoryAddressDebug(items) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function findLastAddressDebugWithItem(items) {
|
||||
if (!Array.isArray(items)) {
|
||||
return null;
|
||||
}
|
||||
for (let index = items.length - 1; index >= 0; index -= 1) {
|
||||
const item = items[index];
|
||||
if (!item || item.role !== "assistant" || !item.debug || typeof item.debug !== "object") {
|
||||
continue;
|
||||
}
|
||||
const debug = item.debug;
|
||||
if (String(debug.execution_lane ?? "") !== "address_query") {
|
||||
continue;
|
||||
}
|
||||
const extractedFilters = debug.extracted_filters && typeof debug.extracted_filters === "object"
|
||||
? debug.extracted_filters
|
||||
: null;
|
||||
const itemLabel = String(extractedFilters?.item ?? "").trim() ||
|
||||
(String(debug.anchor_type ?? "") === "item"
|
||||
? String(debug.anchor_value_resolved ?? debug.anchor_value_raw ?? "").trim()
|
||||
: "");
|
||||
if (itemLabel) {
|
||||
return debug;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function findLastAddressDebug(items) {
|
||||
if (!Array.isArray(items)) {
|
||||
return null;
|
||||
}
|
||||
for (let index = items.length - 1; index >= 0; index -= 1) {
|
||||
const item = items[index];
|
||||
if (!item || item.role !== "assistant" || !item.debug || typeof item.debug !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (String(item.debug.execution_lane ?? "") === "address_query") {
|
||||
return item.debug;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function buildInventoryHistoryCapabilityFollowupReply(input) {
|
||||
const rootFrameContext = input.addressDebug?.address_root_frame_context && typeof input.addressDebug.address_root_frame_context === "object"
|
||||
? input.addressDebug.address_root_frame_context
|
||||
@@ -65,6 +106,42 @@ function buildInventoryHistoryCapabilityFollowupReply(input) {
|
||||
"Если хочешь, сразу покажу нужный исторический период."
|
||||
].join("\n");
|
||||
}
|
||||
function buildAddressMemoryRecapReply(input) {
|
||||
const extractedFilters = input.addressDebug?.extracted_filters && typeof input.addressDebug.extracted_filters === "object"
|
||||
? input.addressDebug.extracted_filters
|
||||
: null;
|
||||
const rootFrameContext = input.addressDebug?.address_root_frame_context && typeof input.addressDebug.address_root_frame_context === "object"
|
||||
? input.addressDebug.address_root_frame_context
|
||||
: null;
|
||||
const item = input.toNonEmptyString(extractedFilters?.item) ??
|
||||
(String(input.addressDebug?.anchor_type ?? "") === "item"
|
||||
? input.toNonEmptyString(input.addressDebug?.anchor_value_resolved) ??
|
||||
input.toNonEmptyString(input.addressDebug?.anchor_value_raw)
|
||||
: null);
|
||||
const organization = input.organization ??
|
||||
input.toNonEmptyString(extractedFilters?.organization) ??
|
||||
input.toNonEmptyString(rootFrameContext?.organization);
|
||||
const scopedDate = formatIsoDateForReply(extractedFilters?.as_of_date) ??
|
||||
formatIsoDateForReply(rootFrameContext?.as_of_date) ??
|
||||
formatIsoDateForReply(extractedFilters?.period_to);
|
||||
if (item) {
|
||||
const datePart = scopedDate ? ` в срезе на ${scopedDate}` : "";
|
||||
const organizationPart = organization ? ` по компании «${organization}»` : "";
|
||||
return [
|
||||
`Да, помню. Мы обсуждали позицию «${item}»${organizationPart}${datePart}.`,
|
||||
"Могу продолжить по ней без переписывания сущности: кто поставил, когда купили, по каким документам или кому продали."
|
||||
].join(" ");
|
||||
}
|
||||
if (organization || scopedDate) {
|
||||
const organizationPart = organization ? ` по компании «${organization}»` : "";
|
||||
const datePart = scopedDate ? ` на ${scopedDate}` : "";
|
||||
return [
|
||||
`Да, помню. Мы уже смотрели адресный контур${organizationPart}${datePart}.`,
|
||||
"Могу кратко напомнить контекст или сразу продолжить следующий шаг по этому же сценарию."
|
||||
].join(" ");
|
||||
}
|
||||
return "Да, помню предыдущий адресный контур. Могу кратко напомнить, что мы уже подтвердили, или сразу продолжить следующий шаг.";
|
||||
}
|
||||
async function runAssistantLivingChatRuntime(input) {
|
||||
const userMessage = String(input.userMessage ?? "");
|
||||
const dataScopeMetaQuery = input.hasAssistantDataScopeMetaQuestionSignal(userMessage);
|
||||
@@ -83,9 +160,13 @@ async function runAssistantLivingChatRuntime(input) {
|
||||
let selectedOrganization = input.toNonEmptyString(input.sessionScope.selectedOrganization);
|
||||
let activeOrganization = input.toNonEmptyString(input.sessionScope.activeOrganization);
|
||||
const contextualInventoryHistoryCapabilityFollowup = input.modeDecision?.reason === "inventory_history_capability_followup_detected";
|
||||
const contextualMemoryRecapFollowup = input.modeDecision?.reason === "memory_recap_followup_detected";
|
||||
const lastGroundedInventoryAddressDebug = contextualInventoryHistoryCapabilityFollowup
|
||||
? findLastGroundedInventoryAddressDebug(input.sessionItems)
|
||||
: null;
|
||||
const lastMemoryAddressDebug = contextualMemoryRecapFollowup
|
||||
? findLastAddressDebugWithItem(input.sessionItems) ?? findLastAddressDebug(input.sessionItems)
|
||||
: null;
|
||||
if (capabilityMetaQuery && (destructiveSignal || dangerSignal)) {
|
||||
chatText = input.buildAssistantSafetyRefusalReply();
|
||||
livingChatSource = "deterministic_safety_refusal";
|
||||
@@ -139,6 +220,16 @@ async function runAssistantLivingChatRuntime(input) {
|
||||
activeOrganization = scopedOrganization ?? activeOrganization;
|
||||
livingChatSource = "deterministic_inventory_history_capability_contract";
|
||||
}
|
||||
else if (contextualMemoryRecapFollowup) {
|
||||
const scopedOrganization = selectedOrganization ?? activeOrganization ?? null;
|
||||
chatText = buildAddressMemoryRecapReply({
|
||||
organization: scopedOrganization,
|
||||
addressDebug: lastMemoryAddressDebug,
|
||||
toNonEmptyString: input.toNonEmptyString
|
||||
});
|
||||
activeOrganization = scopedOrganization ?? activeOrganization;
|
||||
livingChatSource = "deterministic_memory_recap_contract";
|
||||
}
|
||||
else if (capabilityMetaQuery) {
|
||||
chatText = input.buildAssistantCapabilityContractReply();
|
||||
livingChatSource = "deterministic_capability_contract";
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.INVENTORY_CAPABILITY_CONTRACTS = exports.ASSISTANT_TRANSITION_CONTRACTS = void 0;
|
||||
exports.listAssistantTransitionContracts = listAssistantTransitionContracts;
|
||||
exports.getAssistantTransitionContract = getAssistantTransitionContract;
|
||||
exports.listInventoryCapabilityContracts = listInventoryCapabilityContracts;
|
||||
exports.getAssistantCapabilityContract = getAssistantCapabilityContract;
|
||||
exports.getAssistantCapabilityContractByIntent = getAssistantCapabilityContractByIntent;
|
||||
const assistantRuntimeContracts_1 = require("../types/assistantRuntimeContracts");
|
||||
exports.ASSISTANT_TRANSITION_CONTRACTS = [
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T1",
|
||||
title: "Root Query Entry",
|
||||
trigger_class: "new_root_business_question",
|
||||
required_prior_state: ["living_mode_state"],
|
||||
allowed_carryover_depth: "none",
|
||||
state_mutations: ["create_root_frame_state", "clear_selected_object_frame_state", "create_coverage_gate_state"],
|
||||
forbidden_carryover: ["stale_focus_object", "stale_object_intent"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T2",
|
||||
title: "Root Follow-Up With Date Or Scope Change",
|
||||
trigger_class: "root_followup_temporal_or_organization_shift",
|
||||
required_prior_state: ["root_frame_state"],
|
||||
allowed_carryover_depth: "root_only",
|
||||
state_mutations: ["update_root_frame_state", "run_exact_route", "refresh_coverage_gate_state"],
|
||||
forbidden_carryover: ["incompatible_selected_object_route"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T3",
|
||||
title: "Explicit Selected Object Drilldown",
|
||||
trigger_class: "explicit_selected_object_or_ui_object_selection",
|
||||
required_prior_state: ["root_frame_state"],
|
||||
allowed_carryover_depth: "object_only",
|
||||
state_mutations: ["create_selected_object_frame_state", "bind_source_result_set", "preserve_temporal_ceiling"],
|
||||
forbidden_carryover: ["unrelated_prior_focus_object"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T4",
|
||||
title: "Short Action Follow-Up On Selected Object",
|
||||
trigger_class: "short_action_followup_on_active_focus_object",
|
||||
required_prior_state: ["selected_object_frame_state"],
|
||||
allowed_carryover_depth: "object_only",
|
||||
state_mutations: ["reuse_selected_object_frame_state", "route_to_compatible_item_action"],
|
||||
forbidden_carryover: ["generic_chat_fallback", "data_scope_selection_fallback", "object_focus_reset"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T5",
|
||||
title: "Pronoun Or Compressed Object Follow-Up",
|
||||
trigger_class: "pronoun_or_compressed_reference_to_active_focus_object",
|
||||
required_prior_state: ["selected_object_frame_state"],
|
||||
allowed_carryover_depth: "object_only",
|
||||
state_mutations: ["reuse_selected_object_frame_state", "resolve_pronoun_to_focus_object"],
|
||||
forbidden_carryover: ["low_quality_object_rewrite", "semantic_noise_as_anchor"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T6",
|
||||
title: "Domain Pivot With Root-Only Carryover",
|
||||
trigger_class: "supported_domain_pivot_from_active_drilldown",
|
||||
required_prior_state: ["root_frame_state", "selected_object_frame_state"],
|
||||
allowed_carryover_depth: "root_only",
|
||||
state_mutations: ["preserve_root_frame_state", "drop_selected_object_frame_state"],
|
||||
forbidden_carryover: ["object_route_replay_into_new_domain"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T7",
|
||||
title: "Clarification Continuation",
|
||||
trigger_class: "user_resolves_missing_anchor_or_scope",
|
||||
required_prior_state: ["clarification_state"],
|
||||
allowed_carryover_depth: "full",
|
||||
state_mutations: ["resume_target_route", "update_or_clear_clarification_state"],
|
||||
forbidden_carryover: ["forget_suspended_route"],
|
||||
expected_answer_mode: "confirmed"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T8",
|
||||
title: "Meta Follow-Up Over Answer Object",
|
||||
trigger_class: "evaluation_comparison_or_interpretation_of_previous_answer",
|
||||
required_prior_state: ["answer_context_state", "coverage_gate_state"],
|
||||
allowed_carryover_depth: "meta_only",
|
||||
state_mutations: ["create_meta_frame_state", "reuse_answer_object_without_blind_replay"],
|
||||
forbidden_carryover: ["blind_exact_route_replay"],
|
||||
expected_answer_mode: "meta"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T9",
|
||||
title: "Memory Recap",
|
||||
trigger_class: "conversation_memory_recap_request",
|
||||
required_prior_state: ["answer_context_state"],
|
||||
allowed_carryover_depth: "meta_only",
|
||||
state_mutations: ["reuse_grounded_prior_answer_context"],
|
||||
forbidden_carryover: ["invented_conversation_memory"],
|
||||
expected_answer_mode: "recap"
|
||||
},
|
||||
{
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
transition_id: "T10",
|
||||
title: "Unsupported Or Blocked Boundary",
|
||||
trigger_class: "unsupported_route_or_blocked_evidence_gate",
|
||||
required_prior_state: ["coverage_gate_state"],
|
||||
allowed_carryover_depth: "none",
|
||||
state_mutations: ["emit_bounded_boundary_or_clarification"],
|
||||
forbidden_carryover: ["blocked_as_confirmed_factual_answer"],
|
||||
expected_answer_mode: "boundary"
|
||||
}
|
||||
];
|
||||
const SHARED_INVENTORY_ACCEPTANCE_FAMILIES = [
|
||||
"canonical",
|
||||
"colloquial",
|
||||
"ui_selected_object",
|
||||
"ui_selected_object_colloquial",
|
||||
"short_action_followup",
|
||||
"pronoun_followup",
|
||||
"followup_date_carryover"
|
||||
];
|
||||
const INVENTORY_ITEM_ANCHOR_RULES = [
|
||||
"no_low_quality_item_rewrite",
|
||||
"no_numeric_tail_account_poisoning",
|
||||
"no_conversational_noise_as_entity",
|
||||
"confirmed_focus_object_beats_semantic_hint"
|
||||
];
|
||||
const INVENTORY_SELECTED_OBJECT_TESTS = [
|
||||
"selected_object_memory_survives_short_followup",
|
||||
"new_explicit_selected_object_overrides_old_focus",
|
||||
"full_anchor_not_degraded_by_canonical_rewrite"
|
||||
];
|
||||
function inventoryExactCapability(input) {
|
||||
return {
|
||||
schema_version: assistantRuntimeContracts_1.ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
capability_id: input.capability_id,
|
||||
domain_id: "inventory_stock",
|
||||
runtime_lane: "address_exact",
|
||||
intent_ids: input.intent_ids,
|
||||
entry_modes: input.entry_modes,
|
||||
supported_transition_classes: input.transitions,
|
||||
frame_compatibility: {
|
||||
root_frame: input.entry_modes.includes("root_entry") ? "optional" : "required",
|
||||
selected_object_frame: input.requiresFocusObject ? "required" : "optional",
|
||||
meta_frame: "forbidden"
|
||||
},
|
||||
required_anchors: input.requiredAnchors,
|
||||
optional_anchors: ["organization", "warehouse", "date_scope"],
|
||||
anchor_source_priority: ["explicit_user_anchor", "ui_selected_object", "selected_object_frame", "root_frame", "semantic_hint"],
|
||||
anchor_admissibility_rules: [...INVENTORY_ITEM_ANCHOR_RULES],
|
||||
organization_scope_behavior: "reuse_or_clarify",
|
||||
date_scope_behavior: "reuse",
|
||||
temporal_ceiling_policy: input.requiresFocusObject ? "respect_root_temporal_ceiling" : "must_not_expand_without_reason_code",
|
||||
root_context_compatibility: "required",
|
||||
requires_focus_object: input.requiresFocusObject,
|
||||
accepted_focus_object_kinds: input.requiresFocusObject ? ["inventory_item", "item"] : [],
|
||||
focus_object_override_policy: input.requiresFocusObject ? "explicit_new_object_wins" : "not_applicable",
|
||||
bundle_reuse_policy: input.bundleReusePolicy,
|
||||
resolver_owner: "addressIntentResolver",
|
||||
recipe_owner: "addressRecipeCatalog",
|
||||
execution_adapter: "AddressQueryService",
|
||||
result_shape: input.resultShape,
|
||||
answer_object_shape: input.answerObjectShape,
|
||||
minimum_evidence_policy: "route_specific_threshold",
|
||||
coverage_gate_behavior: "partial_or_blocked_if_evidence_insufficient",
|
||||
truth_mode_fallbacks: ["limited", "clarification_required", "unsupported"],
|
||||
blocked_reason_codes: ["missing_anchor", "route_expectation_failure", "execution_error", "insufficient_evidence"],
|
||||
clarification_triggers: ["missing_required_item_anchor", "ambiguous_organization_scope", "ambiguous_date_scope"],
|
||||
clarification_questions: ["Уточните товар, организацию или дату, чтобы не подставлять неподтвержденный anchor."],
|
||||
resume_policy: "resume_original_route_with_resolved_anchors",
|
||||
empty_match_behavior: "truthful_empty_match",
|
||||
route_expectation_failure_behavior: "blocked_route_expectation_failure",
|
||||
execution_error_behavior: "blocked_execution_error",
|
||||
required_unit_tests: input.requiresFocusObject
|
||||
? [...INVENTORY_SELECTED_OBJECT_TESTS, "limited_mode_remains_truthful"]
|
||||
: ["root_context_survives_domain_pivot_without_object_leak", "limited_mode_remains_truthful"],
|
||||
required_transition_tests: input.transitions.map((transitionId) => `transition_${transitionId}`),
|
||||
required_scenario_families: input.scenarioFamilies ?? [...SHARED_INVENTORY_ACCEPTANCE_FAMILIES]
|
||||
};
|
||||
}
|
||||
exports.INVENTORY_CAPABILITY_CONTRACTS = [
|
||||
inventoryExactCapability({
|
||||
capability_id: "confirmed_inventory_on_hand_as_of_date",
|
||||
intent_ids: ["inventory_on_hand_as_of_date"],
|
||||
entry_modes: ["root_entry", "root_followup", "clarification_resume"],
|
||||
transitions: ["T1", "T2", "T7"],
|
||||
requiresFocusObject: false,
|
||||
requiredAnchors: [],
|
||||
resultShape: "item_list_with_quantity_cost_warehouse_organization",
|
||||
answerObjectShape: "inventory_stock_snapshot",
|
||||
bundleReusePolicy: "none",
|
||||
scenarioFamilies: ["canonical", "colloquial", "followup_date_carryover"]
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_purchase_provenance_for_item",
|
||||
intent_ids: ["inventory_purchase_provenance_for_item"],
|
||||
entry_modes: ["selected_object_drilldown", "clarification_resume"],
|
||||
transitions: ["T3", "T4", "T5", "T7"],
|
||||
requiresFocusObject: true,
|
||||
requiredAnchors: ["item"],
|
||||
resultShape: "supplier_purchase_provenance_trace",
|
||||
answerObjectShape: "inventory_provenance_bundle",
|
||||
bundleReusePolicy: "provenance_bundle_preferred"
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_purchase_documents_for_item",
|
||||
intent_ids: ["inventory_purchase_documents_for_item"],
|
||||
entry_modes: ["selected_object_drilldown", "clarification_resume"],
|
||||
transitions: ["T3", "T4", "T5", "T7"],
|
||||
requiresFocusObject: true,
|
||||
requiredAnchors: ["item"],
|
||||
resultShape: "purchase_document_list_for_selected_item",
|
||||
answerObjectShape: "inventory_purchase_documents_bundle",
|
||||
bundleReusePolicy: "provenance_bundle_preferred"
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_supplier_stock_overlap_as_of_date",
|
||||
intent_ids: ["inventory_supplier_stock_overlap_as_of_date"],
|
||||
entry_modes: ["root_entry", "root_followup", "clarification_resume"],
|
||||
transitions: ["T1", "T2", "T7"],
|
||||
requiresFocusObject: false,
|
||||
requiredAnchors: ["supplier"],
|
||||
resultShape: "supplier_to_stock_item_overlap",
|
||||
answerObjectShape: "inventory_supplier_overlap",
|
||||
bundleReusePolicy: "none",
|
||||
scenarioFamilies: ["canonical", "colloquial", "followup_date_carryover"]
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_sale_trace_for_item",
|
||||
intent_ids: ["inventory_sale_trace_for_item"],
|
||||
entry_modes: ["selected_object_drilldown", "clarification_resume"],
|
||||
transitions: ["T3", "T4", "T5", "T7"],
|
||||
requiresFocusObject: true,
|
||||
requiredAnchors: ["item"],
|
||||
resultShape: "buyer_sale_trace_for_selected_item",
|
||||
answerObjectShape: "inventory_sale_trace_bundle",
|
||||
bundleReusePolicy: "sale_trace_bundle_preferred"
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_purchase_to_sale_chain",
|
||||
intent_ids: ["inventory_purchase_to_sale_chain"],
|
||||
entry_modes: ["selected_object_drilldown", "clarification_resume"],
|
||||
transitions: ["T3", "T4", "T5", "T7"],
|
||||
requiresFocusObject: true,
|
||||
requiredAnchors: ["item"],
|
||||
resultShape: "purchase_stock_sale_document_chain",
|
||||
answerObjectShape: "inventory_purchase_to_sale_chain",
|
||||
bundleReusePolicy: "sale_trace_bundle_preferred"
|
||||
}),
|
||||
inventoryExactCapability({
|
||||
capability_id: "inventory_inventory_aging_by_purchase_date",
|
||||
intent_ids: ["inventory_aging_by_purchase_date"],
|
||||
entry_modes: ["root_entry", "root_followup", "clarification_resume"],
|
||||
transitions: ["T1", "T2", "T6", "T7"],
|
||||
requiresFocusObject: false,
|
||||
requiredAnchors: [],
|
||||
resultShape: "oldest_first_inventory_aging_list",
|
||||
answerObjectShape: "inventory_aging_snapshot",
|
||||
bundleReusePolicy: "none",
|
||||
scenarioFamilies: ["canonical", "colloquial", "followup_date_carryover"]
|
||||
})
|
||||
];
|
||||
function listAssistantTransitionContracts() {
|
||||
return exports.ASSISTANT_TRANSITION_CONTRACTS;
|
||||
}
|
||||
function getAssistantTransitionContract(transitionId) {
|
||||
return exports.ASSISTANT_TRANSITION_CONTRACTS.find((contract) => contract.transition_id === transitionId) ?? null;
|
||||
}
|
||||
function listInventoryCapabilityContracts() {
|
||||
return exports.INVENTORY_CAPABILITY_CONTRACTS;
|
||||
}
|
||||
function getAssistantCapabilityContract(capabilityId) {
|
||||
return exports.INVENTORY_CAPABILITY_CONTRACTS.find((contract) => contract.capability_id === capabilityId) ?? null;
|
||||
}
|
||||
function getAssistantCapabilityContractByIntent(intent) {
|
||||
return exports.INVENTORY_CAPABILITY_CONTRACTS.find((contract) => contract.intent_ids.includes(intent)) ?? null;
|
||||
}
|
||||
+128
-2
@@ -2508,6 +2508,32 @@ function isInventoryDrilldownFrameIntent(intent) {
|
||||
intent === "inventory_purchase_to_sale_chain" ||
|
||||
intent === "inventory_aging_by_purchase_date";
|
||||
}
|
||||
function resolveAddressIntentFamily(intent) {
|
||||
const normalizedIntent = toNonEmptyString(intent);
|
||||
if (!normalizedIntent) {
|
||||
return null;
|
||||
}
|
||||
if (normalizedIntent.startsWith("inventory_")) {
|
||||
return "inventory";
|
||||
}
|
||||
if (normalizedIntent.startsWith("vat_")) {
|
||||
return "vat";
|
||||
}
|
||||
if (normalizedIntent === "account_balance_snapshot" || normalizedIntent === "documents_forming_balance") {
|
||||
return "balance";
|
||||
}
|
||||
if (normalizedIntent === "open_items_by_counterparty_or_contract" ||
|
||||
normalizedIntent === "list_documents_by_counterparty" ||
|
||||
normalizedIntent === "bank_operations_by_counterparty" ||
|
||||
normalizedIntent === "list_contracts_by_counterparty" ||
|
||||
normalizedIntent === "list_documents_by_contract" ||
|
||||
normalizedIntent === "bank_operations_by_contract" ||
|
||||
normalizedIntent === "receivables_confirmed_for_period" ||
|
||||
normalizedIntent === "payables_confirmed_for_period") {
|
||||
return "settlements";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function extractAddressCarryoverAnchor(addressDebug) {
|
||||
if (!isAddressLaneDebugPayload(addressDebug)) {
|
||||
return {
|
||||
@@ -2877,6 +2903,18 @@ function resolveAddressFollowupCarryoverContext(userMessage, items, alternateMes
|
||||
? extractDisplayedEntityIndexMention(String(alternateMessage ?? "")) !== null
|
||||
: false;
|
||||
const hasIndexReferenceSignal = hasPrimaryIndexReferenceSignal || hasAlternateIndexReferenceSignal;
|
||||
const hasStrongFollowupReference = hasPrimaryIndexReferenceSignal ||
|
||||
hasAlternateIndexReferenceSignal ||
|
||||
hasOrganizationClarificationContinuation ||
|
||||
hasImplicitContinuationSignal ||
|
||||
inventoryShortFollowupPrimary ||
|
||||
inventoryShortFollowupAlternate ||
|
||||
Boolean(debtRoleSwapIntent) ||
|
||||
hasFollowupMarker(userMessage) ||
|
||||
hasReferentialPointer(userMessage) ||
|
||||
(toNonEmptyString(alternateMessage)
|
||||
? hasFollowupMarker(String(alternateMessage ?? "")) || hasReferentialPointer(String(alternateMessage ?? ""))
|
||||
: false);
|
||||
const hasStandaloneAddressTopic = hasStandaloneAddressTopicSignal(userMessage) ||
|
||||
(toNonEmptyString(alternateMessage) ? hasStandaloneAddressTopicSignal(alternateMessage) : false);
|
||||
if (hasStandaloneAddressTopic &&
|
||||
@@ -2898,6 +2936,23 @@ function resolveAddressFollowupCarryoverContext(userMessage, items, alternateMes
|
||||
return null;
|
||||
}
|
||||
const sourceIntent = toNonEmptyString(previousAddressDebug.detected_intent);
|
||||
const llmExplicitIntent = toNonEmptyString(llmPreDecomposeMeta?.predecomposeContract?.intent);
|
||||
const resolvedPrimaryIntent = (0, addressIntentResolver_1.resolveAddressIntent)(repairAddressMojibake(String(userMessage ?? ""))).intent;
|
||||
const resolvedAlternateIntent = toNonEmptyString(alternateMessage)
|
||||
? (0, addressIntentResolver_1.resolveAddressIntent)(repairAddressMojibake(String(alternateMessage ?? ""))).intent
|
||||
: null;
|
||||
const explicitIntent = llmExplicitIntent && llmExplicitIntent !== "unknown"
|
||||
? llmExplicitIntent
|
||||
: resolvedPrimaryIntent && resolvedPrimaryIntent !== "unknown"
|
||||
? resolvedPrimaryIntent
|
||||
: resolvedAlternateIntent && resolvedAlternateIntent !== "unknown"
|
||||
? resolvedAlternateIntent
|
||||
: null;
|
||||
const sourceIntentFamily = resolveAddressIntentFamily(sourceIntent);
|
||||
const explicitIntentFamily = resolveAddressIntentFamily(explicitIntent);
|
||||
if (sourceIntentFamily && explicitIntentFamily && sourceIntentFamily !== explicitIntentFamily && !hasStrongFollowupReference) {
|
||||
return null;
|
||||
}
|
||||
let previousIntent = sourceIntent;
|
||||
let followupSelectionMode = "carry_previous_intent";
|
||||
if (debtRoleSwapIntent) {
|
||||
@@ -4375,6 +4430,17 @@ function resolveAssistantOrchestrationDecision(input) {
|
||||
hasHistoricalCapabilityFollowupSignal(effectiveAddressUserMessage) ||
|
||||
hasHistoricalCapabilityFollowupSignal(repairedEffectiveAddressUserMessage)) &&
|
||||
isGroundedInventoryContextDebug(lastGroundedAddressDebug));
|
||||
const contextualMemoryRecapFollowupDetected = Boolean(!dataScopeMetaQuery &&
|
||||
!capabilityMetaQuery &&
|
||||
!dataRetrievalSignal &&
|
||||
!strongDataSignal &&
|
||||
!aggregateBusinessAnalyticsSignal &&
|
||||
(hasConversationMemoryRecallFollowupSignal(rawUserMessage) ||
|
||||
hasConversationMemoryRecallFollowupSignal(repairedRawUserMessage) ||
|
||||
hasConversationMemoryRecallFollowupSignal(effectiveAddressUserMessage) ||
|
||||
hasConversationMemoryRecallFollowupSignal(repairedEffectiveAddressUserMessage)) &&
|
||||
(lastGroundedAddressDebug ||
|
||||
findLastAddressAssistantItem(sessionItems)?.debug));
|
||||
const hardMetaMode = dataScopeMetaQuery
|
||||
? "data_scope"
|
||||
: capabilityMetaQuery && !dataRetrievalSignal
|
||||
@@ -4465,6 +4531,34 @@ function resolveAssistantOrchestrationDecision(input) {
|
||||
};
|
||||
}
|
||||
if (nonDomainQueryIndexed) {
|
||||
if (contextualMemoryRecapFollowupDetected) {
|
||||
return {
|
||||
runAddressLane: false,
|
||||
toolGateDecision: "skip_address_lane",
|
||||
toolGateReason: "memory_recap_followup_detected",
|
||||
livingMode: "chat",
|
||||
livingReason: "memory_recap_followup_detected",
|
||||
orchestrationContract: {
|
||||
schema_version: "assistant_orchestration_contract_v1",
|
||||
hard_meta_mode: "non_domain",
|
||||
address_mode: resolvedModeDetection.mode,
|
||||
address_mode_confidence: resolvedModeDetection.confidence,
|
||||
address_intent: resolvedIntentResolution.intent,
|
||||
address_intent_confidence: resolvedIntentResolution.confidence,
|
||||
strong_data_signal_detected: strongDataSignal,
|
||||
data_retrieval_signal_detected: dataRetrievalSignal,
|
||||
followup_context_detected: Boolean(followupContext || lastGroundedAddressDebug),
|
||||
unsupported_address_intent_fallback_to_deep: false,
|
||||
final_decision: {
|
||||
run_address_lane: false,
|
||||
tool_gate_decision: "skip_address_lane",
|
||||
tool_gate_reason: "memory_recap_followup_detected",
|
||||
living_mode: "chat",
|
||||
living_reason: "memory_recap_followup_detected"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
return {
|
||||
runAddressLane: false,
|
||||
toolGateDecision: "skip_address_lane",
|
||||
@@ -4569,6 +4663,9 @@ function resolveAssistantOrchestrationDecision(input) {
|
||||
const vatExplainFollowupSignal = Boolean(followupContext &&
|
||||
toNonEmptyString(followupContext.previous_intent) === "vat_payable_forecast" &&
|
||||
/(?:\u043f\u043e\u0447\u0435\u043c\u0443|why).*(?:\u043f\u0440\u043e\u0433\u043d\u043e\u0437|forecast).*(?:\u0443\u043f\u043b\u0430\u0442|payable|\b0\b)/iu.test(compactWhitespace(`${repairedRawUserMessage} ${repairedEffectiveAddressUserMessage}`)));
|
||||
const vatEvaluativeFollowupSignal = Boolean(followupContext &&
|
||||
toNonEmptyString(followupContext.previous_intent) === "vat_payable_forecast" &&
|
||||
/(?:^|\s)(?:это\s+)?много\s+или\s+мало(?:\?|$)|(?:^|\s)(?:это\s+)?нормально(?:\?|$)|(?:^|\s)(?:это\s+)?плохо(?:\?|$)|(?:^|\s)(?:это\s+)?хорошо(?:\?|$)/iu.test(compactWhitespace(`${repairedRawUserMessage} ${repairedEffectiveAddressUserMessage}`)));
|
||||
const deepAnalysisSignalFallbackToDeep = Boolean(baseToolGate?.runAddressLane &&
|
||||
!llmRuntimeUnavailableDetected &&
|
||||
(deepAnalysisPreferenceDetected || semanticDeepInvestigationHintDetected) &&
|
||||
@@ -4599,7 +4696,7 @@ function resolveAssistantOrchestrationDecision(input) {
|
||||
const hasPriorAddressAnswerContext = Boolean(lastGroundedAddressDebug || toNonEmptyString(followupContext?.previous_intent));
|
||||
const metaFollowupOverGroundedAnswer = Boolean(followupContext &&
|
||||
hasPriorAddressAnswerContext &&
|
||||
metaAnswerFollowupSignal &&
|
||||
(metaAnswerFollowupSignal || vatEvaluativeFollowupSignal) &&
|
||||
!dataScopeMetaQuery &&
|
||||
!capabilityMetaQuery &&
|
||||
!aggregateBusinessAnalyticsSignal &&
|
||||
@@ -4844,7 +4941,28 @@ function hasMetaAnswerFollowupSignal(userMessage) {
|
||||
sample.includes("по этому поводу") ||
|
||||
sample.includes("об этом") ||
|
||||
(sample.includes("это") && hasReferentialPointer(sample)));
|
||||
if (!(hasReflectionCue && hasTopicPointerCue)) {
|
||||
const hasEvaluationCue = samples.some((sample) => /\b(?:много|мало|нормально|хорошо|плохо|критично|перебор|слабо)\b/iu.test(sample));
|
||||
if (!((hasReflectionCue || hasEvaluationCue) &&
|
||||
(hasTopicPointerCue || (hasEvaluationCue && samples.some((sample) => /^(?:это|ну это)\b/iu.test(sample)))))) {
|
||||
return false;
|
||||
}
|
||||
return !samples.some((sample) => hasAssistantDataScopeMetaQuestionSignal(sample) ||
|
||||
shouldHandleAsAssistantCapabilityMetaQuery(sample) ||
|
||||
hasDataRetrievalRequestSignal(sample) ||
|
||||
hasStrongDataIntentSignal(sample));
|
||||
}
|
||||
function hasConversationMemoryRecallFollowupSignal(userMessage) {
|
||||
const rawText = compactWhitespace(String(userMessage ?? "").toLowerCase());
|
||||
const repairedText = compactWhitespace(repairAddressMojibake(String(userMessage ?? "")).toLowerCase());
|
||||
const samples = [rawText, repairedText]
|
||||
.filter((item) => item.length > 0)
|
||||
.map((item) => item.replace(/ё/g, "е"));
|
||||
if (samples.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const hasMemoryCue = samples.some((sample) => /(?:помни(?:шь|те|м)?|remember|recall)/iu.test(sample));
|
||||
const hasDiscussionCue = samples.some((sample) => /(?:обсуждал[аи]?|говорил[аи]?|смотрел[аи]?|разбирал[аи]?|спрашивал[аи]?)/iu.test(sample));
|
||||
if (!hasMemoryCue || !hasDiscussionCue) {
|
||||
return false;
|
||||
}
|
||||
return !samples.some((sample) => hasAssistantDataScopeMetaQuestionSignal(sample) ||
|
||||
@@ -4920,6 +5038,14 @@ function shouldEmitOrganizationSelectionReply(userMessage, selectedOrganization)
|
||||
if (hasSelectionCue) {
|
||||
return true;
|
||||
}
|
||||
const hasAffectiveReactionCue = /(?:^|[\s,.;:!?()\-])(?:ну|мда|ох|ах|офигеть|офигенно|ахуеть|охуеть|пиздец|пизда|нихуя|хуево|хуёво|ебать|ебан|бля|блять|fuck|shit|damn)(?=$|[\s,.;:!?()\-])/iu.test(normalized) ||
|
||||
normalized.includes("\u0430\u0445\u0443") ||
|
||||
normalized.includes("\u043e\u0445\u0443") ||
|
||||
normalized.includes("\u043f\u0438\u0437\u0434") ||
|
||||
normalized.includes("\u0431\u043b\u044f");
|
||||
if (hasAffectiveReactionCue) {
|
||||
return false;
|
||||
}
|
||||
return normalized.length <= 36 && !/[?]/.test(String(userMessage ?? ""));
|
||||
}
|
||||
function hasOperationalAdminActionRequestSignal(text) {
|
||||
|
||||
@@ -11,7 +11,10 @@ function hasInventoryPurchaseStem(text) {
|
||||
}
|
||||
function hasInventorySupplierCue(text) {
|
||||
const value = toText(text);
|
||||
if (/(?:кто\s+(?:(?:это|этот\s+товар|эту\s+позицию)\s+)?(?:нам\s+)?поставил|кто\s+(?:нам\s+)?поставил\s+(?:это|этот\s+товар|эту\s+позицию)|от\s+какого\s+поставщика|у\s+какого\s+поставщика|от\s+кого\s+куплен|у\s+кого\s+купили|у\s+кого\s+куплено|где\s+(?:мы\s+)?купили(?:\s+(?:это|его|этот\s+товар|эту\s+позицию))?|где\s+куплено|supplier|vendor|поставщик)/iu.test(value)) {
|
||||
if (/(?:купил(?:и|о)?\s+у\s+кого|куплен(?:о)?\s+у\s+кого|купил(?:и|о)?\s+от\s+кого|куплен(?:о)?\s+от\s+кого)/iu.test(value)) {
|
||||
return true;
|
||||
}
|
||||
if (/(?:кто\s+(?:(?:это|этот\s+товар|эту\s+позицию)\s+)?(?:нам\s+)?поставил|кто\s+(?:нам\s+)?поставил\s+(?:это|этот\s+товар|эту\s+позицию)|от\s+какого\s+поставщика|у\s+какого\s+поставщика|от\s+кого\s+куплен|у\s+кого\s+купили|у\s+кого\s+куплено|где\s+(?:мы\s+)?купили(?:\s+(?:это|его|этот\s+товар|эту\s+позицию))?|где\s+(?:мы\s+)?взяли(?:\s+(?:это|его|этот\s+товар|эту\s+позицию))?|откуда\s+(?:мы\s+)?взяли(?:\s+(?:это|его|этот\s+товар|эту\s+позицию))?|где\s+куплено|supplier|vendor|поставщик)/iu.test(value)) {
|
||||
return true;
|
||||
}
|
||||
return hasInventoryPurchaseStem(value) && /(?:у\s+кого|от\s+кого|где)/iu.test(value);
|
||||
@@ -21,11 +24,11 @@ function hasInventorySaleCue(text) {
|
||||
if (/(?:buyer|покупател)/iu.test(value)) {
|
||||
return true;
|
||||
}
|
||||
if (/(?:куда\s+ушла\s+позиция|куда\s+ушел\s+товар|кто\s+купил)/iu.test(value)) {
|
||||
if (/(?:куда\s+ушла\s+позиция|куда\s+ушел\s+товар|кто\s+купил|кому\s+(?:мы\s+)?впарили(?:\s+(?:это|его|товар|позицию))?)/iu.test(value)) {
|
||||
return true;
|
||||
}
|
||||
const hasDirectionCue = /(?:кому|каму|куда)/iu.test(value);
|
||||
const hasSaleVerb = /(?:продал(?:и|а|о|ы)?|продан(?:а|о|ы)?|продано|реализовал(?:и|а|о|ы)?|реализован(?:а|о|ы)?|реализовано)/iu.test(value);
|
||||
const hasSaleVerb = /(?:продал(?:и|а|о|ы)?|продан(?:а|о|ы)?|продано|реализовал(?:и|а|о|ы)?|реализован(?:а|о|ы)?|реализовано|впарил(?:и|а|о|ы)?|отгрузил(?:и|а|о|ы)?|ушло|ушел|ушла)/iu.test(value);
|
||||
if (hasDirectionCue && hasSaleVerb) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user