NODEDC_1C/llm_normalizer/backend/dist/services/assistantMcpDiscoveryExecut...

84 lines
4.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ASSISTANT_MCP_DISCOVERY_EXECUTION_HANDOFF_SCHEMA_VERSION = void 0;
exports.buildAssistantMcpDiscoveryExecutionHandoff = buildAssistantMcpDiscoveryExecutionHandoff;
exports.ASSISTANT_MCP_DISCOVERY_EXECUTION_HANDOFF_SCHEMA_VERSION = "assistant_mcp_discovery_execution_handoff_v1";
const HOT_HANDOFF_CHAIN_ALLOWLIST = ["value_flow"];
function uniqueStrings(values) {
const result = [];
for (const value of values) {
const text = String(value ?? "").trim();
if (text && !result.includes(text)) {
result.push(text);
}
}
return result;
}
function handoffStatusFor(input, allowedHotChain) {
if (input.bridgeStatus === "needs_clarification" || input.routeCandidate.candidate_status === "needs_user_scope") {
return "awaiting_user_scope";
}
if (input.bridgeStatus === "checked_sources_only") {
return "checked_sources_only";
}
if (input.bridgeStatus === "blocked" ||
input.bridgeStatus === "unsupported" ||
input.routeCandidate.candidate_status === "blocked" ||
input.routeCandidate.candidate_status === "needs_route_enablement") {
return "blocked";
}
if (!allowedHotChain) {
return "not_enabled_for_chain";
}
return "ready_for_guarded_response";
}
function buildAssistantMcpDiscoveryExecutionHandoff(input) {
const allowedHotChain = HOT_HANDOFF_CHAIN_ALLOWLIST.includes(input.routeCandidate.selected_chain_id);
const baseStatus = handoffStatusFor(input, allowedHotChain);
const readinessChecksPassed = baseStatus === "ready_for_guarded_response" &&
input.bridgeStatus === "answer_draft_ready" &&
input.routeCandidate.candidate_status === "ready_for_reviewed_execution" &&
input.routeCandidate.executable_now === true &&
input.pilot.pilot_status === "executed" &&
input.pilot.mcp_execution_performed === true &&
input.businessFactAnswerAllowed === true &&
input.userFacingResponseAllowed === true &&
input.answerDraft.internal_mechanics_allowed === false;
const handoffStatus = readinessChecksPassed ? "ready_for_guarded_response" : baseStatus;
const reasonCodes = uniqueStrings([
`execution_handoff_status_${handoffStatus}`,
allowedHotChain ? "execution_handoff_chain_allowlisted" : "execution_handoff_chain_not_allowlisted",
input.routeCandidate.executable_now
? "execution_handoff_route_candidate_executable"
: "execution_handoff_route_candidate_not_executable",
input.pilot.mcp_execution_performed
? "execution_handoff_mcp_execution_performed"
: "execution_handoff_mcp_execution_not_performed",
input.businessFactAnswerAllowed
? "execution_handoff_business_fact_allowed"
: "execution_handoff_business_fact_not_allowed",
input.userFacingResponseAllowed
? "execution_handoff_user_facing_allowed"
: "execution_handoff_user_facing_not_allowed",
readinessChecksPassed
? "execution_handoff_guarded_response_ready"
: "execution_handoff_guarded_response_not_ready"
]);
return {
schema_version: exports.ASSISTANT_MCP_DISCOVERY_EXECUTION_HANDOFF_SCHEMA_VERSION,
policy_owner: "assistantMcpDiscoveryExecutionHandoff",
handoff_status: handoffStatus,
selected_chain_id: input.routeCandidate.selected_chain_id,
route_candidate_status: input.routeCandidate.candidate_status,
evidence_answer_mode: input.routeCandidate.evidence_answer_mode,
evidence_expected_coverage: input.routeCandidate.evidence_expected_coverage,
pilot_status: input.pilot.pilot_status,
answer_mode: input.answerDraft.answer_mode,
mcp_execution_performed: input.pilot.mcp_execution_performed,
allowed_hot_chain: allowedHotChain,
can_use_guarded_response: readinessChecksPassed,
must_keep_internal_mechanics_hidden: true,
reason_codes: reasonCodes
};
}