АРЧ АП11 - Commit title: Добавить контрактный слой переходов и capability-деклараций ассистента
This commit is contained in:
@@ -1191,6 +1191,75 @@ function isTemporalWarehousePhrase(candidate: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function isLowQualityWarehouseAnchorValue(rawValue: string): boolean {
|
||||
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: string): string {
|
||||
return cleanupAnchorValue(value)
|
||||
.toLowerCase()
|
||||
@@ -1236,6 +1305,7 @@ function extractInventoryWarehouseAnchor(text: string): string | undefined {
|
||||
candidate.includes("->") ||
|
||||
candidate.includes("=>") ||
|
||||
isImplicitSelfScopeWarehouseAnchor(candidate) ||
|
||||
isLowQualityWarehouseAnchorValue(candidate) ||
|
||||
normalizedCandidate.startsWith("по состоянию") ||
|
||||
isTemporalWarehousePhrase(candidate) ||
|
||||
/^(?:сейчас|на|дату|дате|остаток|остатки)$/iu.test(candidate)
|
||||
|
||||
@@ -1949,6 +1949,17 @@ export function resolveAddressIntent(userMessage: string): AddressIntentResoluti
|
||||
};
|
||||
}
|
||||
|
||||
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",
|
||||
|
||||
@@ -1978,7 +1978,14 @@ function hasExplicitPeriodWindow(filters: AddressFilterSet): boolean {
|
||||
}
|
||||
|
||||
function canAutoBroadenPeriodWindow(intent: AddressIntent, filters: AddressFilterSet): boolean {
|
||||
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 (
|
||||
|
||||
@@ -533,6 +533,30 @@ function hasSelectedObjectInventorySignal(text: string): boolean {
|
||||
return /(?:по\s+выбранному\s+объекту|for\s+selected\s+object)/iu.test(String(text ?? ""));
|
||||
}
|
||||
|
||||
function hasSelectedObjectInlineSnapshotMetadata(text: string): boolean {
|
||||
return /(?:дата\s+строки|строка\s+от|количество\s*:|стоимость\s*:|склад\s*:|организация\s*:|\|\s*(?:склад|количество|стоимость|организация|дата\s+строки)\s*:)/iu.test(
|
||||
String(text ?? "")
|
||||
);
|
||||
}
|
||||
|
||||
function extractSelectedObjectItemFromFollowupText(text: string): string | null {
|
||||
const rawSelectedObject = toNonEmptyString(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;
|
||||
}
|
||||
|
||||
export function hasInventorySupplierFollowupCue(text: string): boolean {
|
||||
return hasInventorySupplierCue(String(text ?? ""));
|
||||
}
|
||||
@@ -800,7 +824,7 @@ function mergeFollowupFilters(
|
||||
intent === "inventory_aging_by_purchase_date")
|
||||
) {
|
||||
const inheritedItem = previousItem ?? previousAnchorItem;
|
||||
const explicitQuotedItem = toNonEmptyString(extractSelectedObjectQuotedValue(userMessage));
|
||||
const explicitQuotedItem = extractSelectedObjectItemFromFollowupText(userMessage);
|
||||
const currentItem = toNonEmptyString(merged.item);
|
||||
const shouldAdoptExplicitQuotedItem =
|
||||
Boolean(explicitQuotedItem) &&
|
||||
@@ -873,6 +897,23 @@ function mergeFollowupFilters(
|
||||
}
|
||||
}
|
||||
}
|
||||
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") &&
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
import {
|
||||
ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION,
|
||||
type AssistantCapabilityContract,
|
||||
type AssistantTransitionClassId,
|
||||
type AssistantTransitionContract
|
||||
} from "../types/assistantRuntimeContracts";
|
||||
import type { AddressIntent } from "../types/addressQuery";
|
||||
|
||||
export const ASSISTANT_TRANSITION_CONTRACTS: readonly AssistantTransitionContract[] = [
|
||||
{
|
||||
schema_version: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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"
|
||||
}
|
||||
] as const;
|
||||
|
||||
const SHARED_INVENTORY_ACCEPTANCE_FAMILIES = [
|
||||
"canonical",
|
||||
"colloquial",
|
||||
"ui_selected_object",
|
||||
"ui_selected_object_colloquial",
|
||||
"short_action_followup",
|
||||
"pronoun_followup",
|
||||
"followup_date_carryover"
|
||||
] as const;
|
||||
|
||||
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"
|
||||
] as const;
|
||||
|
||||
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"
|
||||
] as const;
|
||||
|
||||
function inventoryExactCapability(input: {
|
||||
capability_id: string;
|
||||
intent_ids: AddressIntent[];
|
||||
entry_modes: AssistantCapabilityContract["entry_modes"];
|
||||
transitions: AssistantTransitionClassId[];
|
||||
requiresFocusObject: boolean;
|
||||
requiredAnchors: string[];
|
||||
resultShape: string;
|
||||
answerObjectShape: string;
|
||||
bundleReusePolicy: AssistantCapabilityContract["bundle_reuse_policy"];
|
||||
scenarioFamilies?: string[];
|
||||
}): AssistantCapabilityContract {
|
||||
return {
|
||||
schema_version: 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]
|
||||
};
|
||||
}
|
||||
|
||||
export const INVENTORY_CAPABILITY_CONTRACTS: readonly AssistantCapabilityContract[] = [
|
||||
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"]
|
||||
})
|
||||
] as const;
|
||||
|
||||
export function listAssistantTransitionContracts(): readonly AssistantTransitionContract[] {
|
||||
return ASSISTANT_TRANSITION_CONTRACTS;
|
||||
}
|
||||
|
||||
export function getAssistantTransitionContract(transitionId: AssistantTransitionClassId): AssistantTransitionContract | null {
|
||||
return ASSISTANT_TRANSITION_CONTRACTS.find((contract) => contract.transition_id === transitionId) ?? null;
|
||||
}
|
||||
|
||||
export function listInventoryCapabilityContracts(): readonly AssistantCapabilityContract[] {
|
||||
return INVENTORY_CAPABILITY_CONTRACTS;
|
||||
}
|
||||
|
||||
export function getAssistantCapabilityContract(capabilityId: string): AssistantCapabilityContract | null {
|
||||
return INVENTORY_CAPABILITY_CONTRACTS.find((contract) => contract.capability_id === capabilityId) ?? null;
|
||||
}
|
||||
|
||||
export function getAssistantCapabilityContractByIntent(intent: AddressIntent): AssistantCapabilityContract | null {
|
||||
return INVENTORY_CAPABILITY_CONTRACTS.find((contract) => contract.intent_ids.includes(intent)) ?? null;
|
||||
}
|
||||
@@ -4997,6 +4997,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) {
|
||||
|
||||
@@ -26,12 +26,12 @@ export function hasInventorySaleCue(text: string): boolean {
|
||||
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(
|
||||
/(?:продал(?:и|а|о|ы)?|продан(?:а|о|ы)?|продано|реализовал(?:и|а|о|ы)?|реализован(?:а|о|ы)?|реализовано|впарил(?:и|а|о|ы)?|отгрузил(?:и|а|о|ы)?|ушло|ушел|ушла)/iu.test(
|
||||
value
|
||||
);
|
||||
if (hasDirectionCue && hasSaleVerb) {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import type { AddressIntent } from "./addressQuery";
|
||||
|
||||
export const ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION = "assistant_runtime_contracts_v1" as const;
|
||||
|
||||
export type AssistantLivingMode = "address_data" | "assistant_data_scope" | "chat" | "meta_followup" | "clarification";
|
||||
export type AssistantFrameStatus = "active" | "suspended" | "closed" | "blocked";
|
||||
export type AssistantTransitionClassId = "T1" | "T2" | "T3" | "T4" | "T5" | "T6" | "T7" | "T8" | "T9" | "T10";
|
||||
export type AssistantStateSlice =
|
||||
| "living_mode_state"
|
||||
| "root_frame_state"
|
||||
| "selected_object_frame_state"
|
||||
| "meta_frame_state"
|
||||
| "clarification_state"
|
||||
| "coverage_gate_state"
|
||||
| "answer_context_state";
|
||||
export type AssistantCarryoverDepth = "full" | "root_only" | "object_only" | "meta_only" | "none";
|
||||
export type AssistantAnswerMode = "confirmed" | "limited" | "clarification" | "boundary" | "meta" | "recap";
|
||||
|
||||
export interface AssistantDateScopeState {
|
||||
as_of_date: string | null;
|
||||
period_from: string | null;
|
||||
period_to: string | null;
|
||||
}
|
||||
|
||||
export interface AssistantRootFrameState {
|
||||
domain_id: string | null;
|
||||
root_route_id: string | null;
|
||||
organization_scope: string | null;
|
||||
date_scope: AssistantDateScopeState;
|
||||
root_result_set_id: string | null;
|
||||
root_answer_object_ref: string | null;
|
||||
frame_status: AssistantFrameStatus;
|
||||
}
|
||||
|
||||
export interface AssistantSelectedObjectFrameState {
|
||||
focus_object_ref: string | null;
|
||||
focus_object_kind: string | null;
|
||||
source_result_set_id: string | null;
|
||||
compatible_route_family: string[];
|
||||
provenance_bundle_ref: string | null;
|
||||
temporal_ceiling: AssistantDateScopeState;
|
||||
frame_status: AssistantFrameStatus;
|
||||
}
|
||||
|
||||
export interface AssistantMetaFrameState {
|
||||
source_answer_object_ref: string | null;
|
||||
meta_question_kind: "evaluation" | "comparison" | "memory_recap" | "boundary_explanation" | "answer_interpretation" | null;
|
||||
source_gate_status: AssistantCoverageGateState["coverage_status"] | null;
|
||||
meta_truth_mode: AssistantCoverageGateState["truth_mode"] | null;
|
||||
}
|
||||
|
||||
export interface AssistantClarificationState {
|
||||
clarification_kind: string | null;
|
||||
missing_anchors: string[];
|
||||
candidate_scopes: string[];
|
||||
resume_target_route: string | null;
|
||||
resume_target_frame: AssistantStateSlice | null;
|
||||
}
|
||||
|
||||
export interface AssistantCoverageGateState {
|
||||
coverage_status: "full" | "partial" | "blocked";
|
||||
evidence_grade: "none" | "weak" | "medium" | "strong";
|
||||
grounding_status: "grounded" | "partial" | "route_mismatch_blocked" | "no_grounded_answer" | "unsupported";
|
||||
truth_mode: "confirmed" | "limited" | "clarification_required" | "unsupported";
|
||||
carryover_eligibility: AssistantCarryoverDepth;
|
||||
reason_codes: string[];
|
||||
}
|
||||
|
||||
export interface AssistantSessionAggregateState {
|
||||
schema_version: typeof ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION;
|
||||
living_mode_state: {
|
||||
living_mode: AssistantLivingMode;
|
||||
mode_reason: string | null;
|
||||
mode_source: "router" | "transition" | "clarification" | "manual" | null;
|
||||
mode_entry_turn_id: string | null;
|
||||
};
|
||||
root_frame_state: AssistantRootFrameState | null;
|
||||
selected_object_frame_state: AssistantSelectedObjectFrameState | null;
|
||||
meta_frame_state: AssistantMetaFrameState | null;
|
||||
clarification_state: AssistantClarificationState | null;
|
||||
coverage_gate_state: AssistantCoverageGateState | null;
|
||||
answer_context_state: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
export interface AssistantTransitionContract {
|
||||
schema_version: typeof ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION;
|
||||
transition_id: AssistantTransitionClassId;
|
||||
title: string;
|
||||
trigger_class: string;
|
||||
required_prior_state: AssistantStateSlice[];
|
||||
allowed_carryover_depth: AssistantCarryoverDepth;
|
||||
state_mutations: string[];
|
||||
forbidden_carryover: string[];
|
||||
expected_answer_mode: AssistantAnswerMode;
|
||||
}
|
||||
|
||||
export type AssistantCapabilityEntryMode =
|
||||
| "root_entry"
|
||||
| "root_followup"
|
||||
| "selected_object_drilldown"
|
||||
| "meta_reuse"
|
||||
| "clarification_resume";
|
||||
export type AssistantRuntimeLane = "address_exact" | "assistant_data_scope" | "chat" | "meta";
|
||||
export type AssistantFrameRequirement = "required" | "optional" | "forbidden";
|
||||
export type AssistantScopeBehavior = "create" | "reuse" | "reuse_or_clarify" | "narrow" | "reject" | "none";
|
||||
export type AssistantTemporalCeilingPolicy = "none" | "respect_root_temporal_ceiling" | "must_not_expand_without_reason_code";
|
||||
export type AssistantBundleReusePolicy = "none" | "provenance_bundle_preferred" | "sale_trace_bundle_preferred";
|
||||
export type AssistantCoverageGateBehavior = "full_required" | "partial_or_blocked_if_evidence_insufficient";
|
||||
export type AssistantTruthFallback = "limited" | "clarification_required" | "unsupported";
|
||||
|
||||
export interface AssistantCapabilityContract {
|
||||
schema_version: typeof ASSISTANT_RUNTIME_CONTRACTS_SCHEMA_VERSION;
|
||||
capability_id: string;
|
||||
domain_id: string;
|
||||
runtime_lane: AssistantRuntimeLane;
|
||||
intent_ids: AddressIntent[];
|
||||
entry_modes: AssistantCapabilityEntryMode[];
|
||||
supported_transition_classes: AssistantTransitionClassId[];
|
||||
frame_compatibility: {
|
||||
root_frame: AssistantFrameRequirement;
|
||||
selected_object_frame: AssistantFrameRequirement;
|
||||
meta_frame: AssistantFrameRequirement;
|
||||
};
|
||||
required_anchors: string[];
|
||||
optional_anchors: string[];
|
||||
anchor_source_priority: string[];
|
||||
anchor_admissibility_rules: string[];
|
||||
organization_scope_behavior: AssistantScopeBehavior;
|
||||
date_scope_behavior: AssistantScopeBehavior;
|
||||
temporal_ceiling_policy: AssistantTemporalCeilingPolicy;
|
||||
root_context_compatibility: "required" | "optional" | "not_applicable";
|
||||
requires_focus_object: boolean;
|
||||
accepted_focus_object_kinds: string[];
|
||||
focus_object_override_policy: "explicit_new_object_wins" | "preserve_existing" | "not_applicable";
|
||||
bundle_reuse_policy: AssistantBundleReusePolicy;
|
||||
resolver_owner: string;
|
||||
recipe_owner: string;
|
||||
execution_adapter: string;
|
||||
result_shape: string;
|
||||
answer_object_shape: string;
|
||||
minimum_evidence_policy: string;
|
||||
coverage_gate_behavior: AssistantCoverageGateBehavior;
|
||||
truth_mode_fallbacks: AssistantTruthFallback[];
|
||||
blocked_reason_codes: string[];
|
||||
clarification_triggers: string[];
|
||||
clarification_questions: string[];
|
||||
resume_policy: string;
|
||||
empty_match_behavior: string;
|
||||
route_expectation_failure_behavior: string;
|
||||
execution_error_behavior: string;
|
||||
required_unit_tests: string[];
|
||||
required_transition_tests: string[];
|
||||
required_scenario_families: string[];
|
||||
}
|
||||
Reference in New Issue
Block a user