NODEDC_1C/llm_normalizer/backend/dist/services/assistantRuntimeContractReg...

287 lines
15 KiB
JavaScript

"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", "T6", "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;
}