130 lines
4.9 KiB
JavaScript
130 lines
4.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ASSISTANT_MCP_DISCOVERY_RUNTIME_DRY_RUN_SCHEMA_VERSION = void 0;
|
|
exports.buildAssistantMcpDiscoveryRuntimeDryRun = buildAssistantMcpDiscoveryRuntimeDryRun;
|
|
const assistantMcpCatalogIndex_1 = require("./assistantMcpCatalogIndex");
|
|
exports.ASSISTANT_MCP_DISCOVERY_RUNTIME_DRY_RUN_SCHEMA_VERSION = "assistant_mcp_discovery_runtime_dry_run_v1";
|
|
function normalizeReasonCode(value) {
|
|
const normalized = value
|
|
.trim()
|
|
.replace(/[^\p{L}\p{N}_.:-]+/gu, "_")
|
|
.replace(/^_+|_+$/g, "")
|
|
.toLowerCase();
|
|
return normalized.length > 0 ? normalized.slice(0, 120) : null;
|
|
}
|
|
function pushReason(target, value) {
|
|
const normalized = normalizeReasonCode(value);
|
|
if (normalized && !target.includes(normalized)) {
|
|
target.push(normalized);
|
|
}
|
|
}
|
|
function uniqueStrings(values) {
|
|
const result = [];
|
|
for (const value of values) {
|
|
const text = value.trim();
|
|
if (text && !result.includes(text)) {
|
|
result.push(text);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
function stepStatusFor(input) {
|
|
if (input.adapterStatus === "blocked") {
|
|
return "blocked";
|
|
}
|
|
if (input.missingAxisOptions.length > 0) {
|
|
return "missing_axes";
|
|
}
|
|
return "ready";
|
|
}
|
|
function stopConditionFor(evidenceFloor) {
|
|
if (evidenceFloor === "rows_matched") {
|
|
return "stop_after_allowed_probe_returns_matched_rows_or_reports_no_match";
|
|
}
|
|
if (evidenceFloor === "rows_received") {
|
|
return "stop_after_allowed_probe_returns_rows_or_reports_empty_source";
|
|
}
|
|
if (evidenceFloor === "source_summary") {
|
|
return "stop_after_allowed_probe_returns_source_summary_or_limitation";
|
|
}
|
|
return "stop_without_fact_claim";
|
|
}
|
|
function adapterStatusFor(planner) {
|
|
if (planner.planner_status === "blocked" || planner.catalog_review.review_status === "catalog_blocked") {
|
|
return "blocked";
|
|
}
|
|
if (planner.planner_status !== "ready_for_execution" || planner.catalog_review.review_status !== "catalog_compatible") {
|
|
return "needs_clarification";
|
|
}
|
|
return "dry_run_ready";
|
|
}
|
|
function fallbackFor(status) {
|
|
if (status === "dry_run_ready") {
|
|
return null;
|
|
}
|
|
if (status === "blocked") {
|
|
return "explain_that_runtime_policy_blocked_mcp_discovery";
|
|
}
|
|
return "ask_for_missing_scope_before_mcp_discovery";
|
|
}
|
|
function buildAssistantMcpDiscoveryRuntimeDryRun(planner) {
|
|
const adapterStatus = adapterStatusFor(planner);
|
|
const reasonCodes = uniqueStrings([
|
|
...planner.reason_codes,
|
|
...planner.discovery_plan.reason_codes,
|
|
...planner.catalog_review.reason_codes
|
|
]);
|
|
const providedAxes = uniqueStrings(planner.required_axes);
|
|
const executionSteps = planner.discovery_plan.allowed_primitives.map((primitiveId, index) => {
|
|
const catalog = (0, assistantMcpCatalogIndex_1.getAssistantMcpCatalogPrimitive)(primitiveId);
|
|
const missingAxisOptions = planner.catalog_review.missing_axes_by_primitive[primitiveId] ?? [];
|
|
return {
|
|
sequence: index + 1,
|
|
primitive_id: primitiveId,
|
|
step_status: stepStatusFor({ adapterStatus, missingAxisOptions }),
|
|
purpose: catalog.purpose,
|
|
provided_axes: providedAxes,
|
|
required_axis_options: catalog.required_axes_any_of,
|
|
missing_axis_options: missingAxisOptions,
|
|
optional_axes: catalog.optional_axes,
|
|
expected_fact_kinds: catalog.output_fact_kinds,
|
|
evidence_floor: catalog.evidence_floor,
|
|
runtime_must_execute: true,
|
|
dry_run_only: true,
|
|
stop_condition: stopConditionFor(catalog.evidence_floor)
|
|
};
|
|
});
|
|
if (adapterStatus === "dry_run_ready") {
|
|
pushReason(reasonCodes, "runtime_dry_run_ready_without_mcp_execution");
|
|
}
|
|
else if (adapterStatus === "blocked") {
|
|
pushReason(reasonCodes, "runtime_dry_run_blocked_before_mcp_execution");
|
|
}
|
|
else {
|
|
pushReason(reasonCodes, "runtime_dry_run_needs_clarification_before_mcp_execution");
|
|
}
|
|
return {
|
|
schema_version: exports.ASSISTANT_MCP_DISCOVERY_RUNTIME_DRY_RUN_SCHEMA_VERSION,
|
|
policy_owner: "assistantMcpDiscoveryRuntimeAdapter",
|
|
adapter_status: adapterStatus,
|
|
planner_status: planner.planner_status,
|
|
mcp_execution_performed: false,
|
|
execution_steps: executionSteps,
|
|
execution_budget: planner.discovery_plan.execution_budget,
|
|
evidence_gate: {
|
|
required: true,
|
|
expected_inputs: [
|
|
"probe_results",
|
|
"confirmed_facts",
|
|
"inferred_facts",
|
|
"unknown_facts",
|
|
"source_rows_summary",
|
|
"query_limitations"
|
|
],
|
|
answer_may_use_raw_model_claims: false
|
|
},
|
|
user_facing_fallback: fallbackFor(adapterStatus),
|
|
reason_codes: reasonCodes
|
|
};
|
|
}
|