74 lines
3.4 KiB
JavaScript
74 lines
3.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.buildAssistantMcpDiscoveryDebugAttachmentFields = buildAssistantMcpDiscoveryDebugAttachmentFields;
|
|
exports.attachAssistantMcpDiscoveryDebug = attachAssistantMcpDiscoveryDebug;
|
|
function toRecordObject(value) {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return null;
|
|
}
|
|
return value;
|
|
}
|
|
function toNonEmptyString(value) {
|
|
if (value === null || value === undefined) {
|
|
return null;
|
|
}
|
|
const text = String(value).trim();
|
|
return text.length > 0 ? text : null;
|
|
}
|
|
function toStringArray(value) {
|
|
if (!Array.isArray(value)) {
|
|
return [];
|
|
}
|
|
const result = [];
|
|
for (const item of value) {
|
|
const text = toNonEmptyString(item);
|
|
if (text && !result.includes(text)) {
|
|
result.push(text);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
function isMcpDiscoveryEntryPointContract(value) {
|
|
const record = toRecordObject(value);
|
|
return (record?.schema_version === "assistant_mcp_discovery_runtime_entry_point_v1" &&
|
|
record?.policy_owner === "assistantMcpDiscoveryRuntimeEntryPoint");
|
|
}
|
|
function resolveEntryPoint(input) {
|
|
if (isMcpDiscoveryEntryPointContract(input.entryPoint)) {
|
|
return input.entryPoint;
|
|
}
|
|
const runtimeMetaEntryPoint = input.addressRuntimeMeta?.mcpDiscoveryRuntimeEntryPoint ??
|
|
input.addressRuntimeMeta?.assistantMcpDiscoveryRuntimeEntryPoint ??
|
|
input.addressRuntimeMeta?.assistant_mcp_discovery_entry_point_v1;
|
|
return isMcpDiscoveryEntryPointContract(runtimeMetaEntryPoint) ? runtimeMetaEntryPoint : null;
|
|
}
|
|
function buildAssistantMcpDiscoveryDebugAttachmentFields(input) {
|
|
const entryPoint = resolveEntryPoint(input);
|
|
const bridge = toRecordObject(entryPoint?.bridge);
|
|
const planner = toRecordObject(bridge?.planner);
|
|
const chainAlignment = toRecordObject(planner?.catalog_chain_template_alignment);
|
|
const answerDraft = toRecordObject(bridge?.answer_draft);
|
|
return {
|
|
assistant_mcp_discovery_entry_point_v1: entryPoint,
|
|
mcp_discovery_entry_status: toNonEmptyString(entryPoint?.entry_status),
|
|
mcp_discovery_attempted: Boolean(entryPoint?.discovery_attempted),
|
|
mcp_discovery_hot_runtime_wired: false,
|
|
mcp_discovery_bridge_status: toNonEmptyString(bridge?.bridge_status),
|
|
mcp_discovery_selected_chain_id: toNonEmptyString(planner?.selected_chain_id),
|
|
mcp_discovery_catalog_chain_template_matches: toStringArray(planner?.catalog_chain_template_matches),
|
|
mcp_discovery_catalog_chain_alignment_status: toNonEmptyString(chainAlignment?.alignment_status),
|
|
mcp_discovery_catalog_chain_top_match: toNonEmptyString(chainAlignment?.top_chain_template_match),
|
|
mcp_discovery_catalog_chain_selected_matches_top: chainAlignment?.selected_chain_matches_top === true,
|
|
mcp_discovery_answer_mode: toNonEmptyString(answerDraft?.answer_mode),
|
|
mcp_discovery_business_fact_answer_allowed: bridge?.business_fact_answer_allowed === true,
|
|
mcp_discovery_user_facing_response_allowed: bridge?.user_facing_response_allowed === true,
|
|
mcp_discovery_requires_clarification: bridge?.requires_user_clarification === true
|
|
};
|
|
}
|
|
function attachAssistantMcpDiscoveryDebug(debugPayload, input) {
|
|
return {
|
|
...debugPayload,
|
|
...buildAssistantMcpDiscoveryDebugAttachmentFields(input)
|
|
};
|
|
}
|