ARCH: разрешить net-flow discovery переопределять stale lifecycle carryover
This commit is contained in:
@@ -152,6 +152,61 @@ function isDiscoveryReadyAddressCandidate(
|
||||
);
|
||||
}
|
||||
|
||||
function isDetectedIntentAlignedWithTurnMeaning(
|
||||
detectedIntent: string | null,
|
||||
turnMeaning: Record<string, unknown> | null
|
||||
): boolean {
|
||||
const normalizedIntent = String(detectedIntent ?? "").trim().toLowerCase();
|
||||
if (!normalizedIntent) {
|
||||
return false;
|
||||
}
|
||||
const askedDomain = String(toNonEmptyString(turnMeaning?.asked_domain_family) ?? "").trim().toLowerCase();
|
||||
const askedAction = String(toNonEmptyString(turnMeaning?.asked_action_family) ?? "").trim().toLowerCase();
|
||||
|
||||
if (normalizedIntent === "counterparty_activity_lifecycle") {
|
||||
return (
|
||||
askedDomain === "counterparty_lifecycle" ||
|
||||
askedAction === "activity_duration" ||
|
||||
askedAction === "age_or_activity_duration"
|
||||
);
|
||||
}
|
||||
if (normalizedIntent === "supplier_payouts_profile") {
|
||||
return askedDomain === "counterparty_value" && askedAction === "payout";
|
||||
}
|
||||
if (normalizedIntent === "customer_revenue_and_payments") {
|
||||
return askedDomain === "counterparty_value" && (askedAction === "turnover" || askedAction === "counterparty_value_or_turnover");
|
||||
}
|
||||
if (normalizedIntent === "receivables_confirmed_as_of_date") {
|
||||
return askedDomain === "receivables" || askedAction === "confirmed_snapshot";
|
||||
}
|
||||
if (normalizedIntent === "payables_confirmed_as_of_date") {
|
||||
return askedDomain === "payables" || askedAction === "confirmed_snapshot";
|
||||
}
|
||||
if (normalizedIntent === "vat_liability_confirmed_for_tax_period") {
|
||||
return askedDomain === "vat" && askedAction === "confirmed_tax_period";
|
||||
}
|
||||
if (normalizedIntent === "vat_payable_confirmed_as_of_date") {
|
||||
return askedDomain === "vat" && askedAction === "confirmed_snapshot";
|
||||
}
|
||||
if (normalizedIntent === "vat_payable_forecast") {
|
||||
return askedDomain === "vat" && askedAction === "forecast";
|
||||
}
|
||||
if (normalizedIntent === "list_documents_by_counterparty") {
|
||||
return askedAction === "list_documents" || askedDomain === "counterparty_documents" || askedDomain === "counterparty";
|
||||
}
|
||||
if (normalizedIntent === "inventory_on_hand_as_of_date" || normalizedIntent === "inventory_aging_by_purchase_date") {
|
||||
return askedDomain === "inventory" && askedAction === "confirmed_snapshot";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function readDiscoveryTurnMeaning(
|
||||
entryPoint: AssistantMcpDiscoveryRuntimeEntryPointContract | null
|
||||
): Record<string, unknown> | null {
|
||||
const turnInput = toRecordObject(entryPoint?.turn_input);
|
||||
return toRecordObject(turnInput?.turn_meaning_ref);
|
||||
}
|
||||
|
||||
function hasAlignedFactualAddressReply(
|
||||
input: ApplyAssistantMcpDiscoveryResponsePolicyInput,
|
||||
entryPoint: AssistantMcpDiscoveryRuntimeEntryPointContract | null
|
||||
@@ -162,33 +217,45 @@ function hasAlignedFactualAddressReply(
|
||||
if (toNonEmptyString(input.currentReplyType) !== "factual") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const detectedIntent = toNonEmptyString(input.addressRuntimeMeta?.detected_intent);
|
||||
const turnInput = toRecordObject(entryPoint?.turn_input);
|
||||
const turnMeaning = toRecordObject(turnInput?.turn_meaning_ref);
|
||||
const askedDomain = toNonEmptyString(turnMeaning?.asked_domain_family);
|
||||
const askedAction = toNonEmptyString(turnMeaning?.asked_action_family);
|
||||
|
||||
if (detectedIntent === "counterparty_activity_lifecycle") {
|
||||
return askedDomain === "counterparty_lifecycle" || askedAction === "activity_duration";
|
||||
}
|
||||
if (detectedIntent === "supplier_payouts_profile") {
|
||||
return askedDomain === "counterparty_value" && askedAction === "payout";
|
||||
}
|
||||
if (detectedIntent === "customer_revenue_and_payments") {
|
||||
return askedDomain === "counterparty_value" && askedAction === "turnover";
|
||||
}
|
||||
return false;
|
||||
return isDetectedIntentAlignedWithTurnMeaning(detectedIntent, readDiscoveryTurnMeaning(entryPoint));
|
||||
}
|
||||
|
||||
function hasMatchedFactualAddressContinuationTarget(
|
||||
input: ApplyAssistantMcpDiscoveryResponsePolicyInput
|
||||
function hasSemanticConflictWithDiscoveryTurnMeaning(
|
||||
input: ApplyAssistantMcpDiscoveryResponsePolicyInput,
|
||||
entryPoint: AssistantMcpDiscoveryRuntimeEntryPointContract | null
|
||||
): boolean {
|
||||
if (!isDiscoveryReadyAddressCandidate(input, entryPoint)) {
|
||||
return false;
|
||||
}
|
||||
if (toNonEmptyString(input.currentReplyType) !== "factual") {
|
||||
return false;
|
||||
}
|
||||
const detectedIntent = toNonEmptyString(input.addressRuntimeMeta?.detected_intent);
|
||||
const dialogContinuationContract = toRecordObject(input.addressRuntimeMeta?.dialogContinuationContract);
|
||||
const turnMeaning = readDiscoveryTurnMeaning(entryPoint);
|
||||
const askedDomain = toNonEmptyString(turnMeaning?.asked_domain_family);
|
||||
const askedAction = toNonEmptyString(turnMeaning?.asked_action_family);
|
||||
const unsupportedFamily = toNonEmptyString(turnMeaning?.unsupported_but_understood_family);
|
||||
if (!detectedIntent || (!askedDomain && !askedAction && !unsupportedFamily)) {
|
||||
return false;
|
||||
}
|
||||
return !isDetectedIntentAlignedWithTurnMeaning(detectedIntent, turnMeaning);
|
||||
}
|
||||
|
||||
function hasMatchedFactualAddressContinuationTarget(
|
||||
input: ApplyAssistantMcpDiscoveryResponsePolicyInput,
|
||||
entryPoint: AssistantMcpDiscoveryRuntimeEntryPointContract | null
|
||||
): boolean {
|
||||
if (toNonEmptyString(input.currentReplyType) !== "factual") {
|
||||
return false;
|
||||
}
|
||||
if (hasSemanticConflictWithDiscoveryTurnMeaning(input, entryPoint)) {
|
||||
return false;
|
||||
}
|
||||
const detectedIntent = toNonEmptyString(input.addressRuntimeMeta?.detected_intent);
|
||||
const dialogContinuationContract =
|
||||
toRecordObject(input.addressRuntimeMeta?.dialogContinuationContract) ??
|
||||
toRecordObject(input.addressRuntimeMeta?.dialog_continuation_contract_v2);
|
||||
const targetIntent = toNonEmptyString(dialogContinuationContract?.target_intent);
|
||||
return Boolean(detectedIntent && targetIntent && detectedIntent === targetIntent);
|
||||
}
|
||||
@@ -203,6 +270,9 @@ function hasFullConfirmedFactualAddressReply(
|
||||
if (toNonEmptyString(input.currentReplyType) !== "factual") {
|
||||
return false;
|
||||
}
|
||||
if (hasSemanticConflictWithDiscoveryTurnMeaning(input, entryPoint)) {
|
||||
return false;
|
||||
}
|
||||
const truthGateStatus = toNonEmptyString(input.addressRuntimeMeta?.truth_gate_contract_status);
|
||||
if (truthGateStatus === "full_confirmed") {
|
||||
return true;
|
||||
@@ -229,7 +299,8 @@ export function applyAssistantMcpDiscoveryResponsePolicy(
|
||||
const discoveryReadyDeepCandidate = isDiscoveryReadyDeepCandidate(input, entryPoint);
|
||||
const discoveryReadyAddressCandidate = isDiscoveryReadyAddressCandidate(input, entryPoint);
|
||||
const alignedFactualAddressReply = hasAlignedFactualAddressReply(input, entryPoint);
|
||||
const matchedFactualAddressContinuationTarget = hasMatchedFactualAddressContinuationTarget(input);
|
||||
const semanticConflictWithDiscoveryTurnMeaning = hasSemanticConflictWithDiscoveryTurnMeaning(input, entryPoint);
|
||||
const matchedFactualAddressContinuationTarget = hasMatchedFactualAddressContinuationTarget(input, entryPoint);
|
||||
const fullConfirmedFactualAddressReply = hasFullConfirmedFactualAddressReply(input, entryPoint);
|
||||
|
||||
if (!entryPoint) {
|
||||
@@ -250,6 +321,9 @@ export function applyAssistantMcpDiscoveryResponsePolicy(
|
||||
if (alignedFactualAddressReply) {
|
||||
pushReason(reasonCodes, "mcp_discovery_response_policy_keep_aligned_factual_address_reply");
|
||||
}
|
||||
if (semanticConflictWithDiscoveryTurnMeaning) {
|
||||
pushReason(reasonCodes, "mcp_discovery_response_policy_semantic_conflict_allows_candidate_override");
|
||||
}
|
||||
if (matchedFactualAddressContinuationTarget) {
|
||||
pushReason(reasonCodes, "mcp_discovery_response_policy_keep_factual_address_continuation_target");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user