UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

185 lines (184 loc) • 9.05 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { d as asPositiveFiniteNumber } from "./number-coercion-D6u-4YD8.mjs"; import { n as parseBooleanValue, t as asBoolean } from "./boolean-2vRuVafy.mjs"; import { a as asOptionalRecord, l as isRecord, u as isStringArray } from "./record-coerce-CVPuDqcc.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./number-runtime-W4chuk8B.mjs"; import { s as createMigrationManualItem } from "./migration-C73lp9ea.mjs"; import { l as sanitizeName } from "./helpers-BrAeOFdd.mjs"; import { n as resolveMcpEnvReferences } from "./config-env-CiqB5Wzx.mjs"; //#region extensions/migrate-hermes/config-mcp.ts const MCP_RESOURCE_UTILITY_TOOLS = ["resources_list", "resources_read"]; const MCP_PROMPT_UTILITY_TOOLS = ["prompts_list", "prompts_get"]; function readPositiveNumeric(e) { return asPositiveFiniteNumber(typeof e === "string" ? Number(e) : e); } function readToolFilterList(e) { if (typeof e === "string") return e.trim() ? [e.trim()] : []; if (!isStringArray(e)) return; return [...new Set(e.map((e) => e.trim()).filter(Boolean))]; } function hasUnsupportedToolPattern(e) { return e.includes("?") || e.includes("["); } function mapHermesClientCertificate(e) { const t = e.clientCert ?? e.client_cert; const n = normalizeOptionalString(e.clientKey) ?? normalizeOptionalString(e.client_key); if (Array.isArray(t) && t.length === 2) { const e = normalizeOptionalString(t[0]); const n = normalizeOptionalString(t[1]); return e && n ? { clientCert: e, clientKey: n } : {}; } const r = normalizeOptionalString(t); return r && n ? { clientCert: r, clientKey: n } : {}; } const MCP_CONNECTION_FIELDS = [ "enabled", "command", "args", "cwd", "workingDirectory", "url", "connectionTimeoutMs", "requestTimeoutMs" ]; function mapHermesMcpOauth(e) { const t = asOptionalRecord(e.oauth); if (!t) return; const n = {}; for (const e of [ "authProfileId", "scope", "redirectUrl", "clientMetadataUrl" ]) { const r = normalizeOptionalString(t[e]); if (r) n[e] = r; } return Object.keys(n).length > 0 ? n : void 0; } function planHermesMcpServer(e) { const { name: t, raw: n, includeSecrets: r, env: i } = e; let a = n.env !== void 0 || n.headers !== void 0; let o = false; const s = {}; for (const e of [ ...MCP_CONNECTION_FIELDS, "env", "headers" ]) { const t = n[e]; if (t === void 0) continue; const c = resolveMcpEnvReferences(t, i); const l = e === "env" || e === "headers" || c.referenced; a ||= l; if (l && !r) continue; o ||= c.unresolved; if (!c.unresolved) s[e] = c.value; } const { env: c, headers: l, ...u } = s; const d = normalizeOptionalString(n.transport) ?? normalizeOptionalString(n.type); if (d === "http" || d === "streamable-http") u.transport = "streamable-http"; else if (d === "sse" || d === "stdio") u.transport = d; else if (!d && normalizeOptionalString(u.url)) u.transport = "streamable-http"; for (const [e, t] of [["connectionTimeoutMs", n.connectTimeout ?? n.connect_timeout], ["requestTimeoutMs", n.timeout]]) if (u[e] === void 0 && typeof t === "number" && t > 0 && Number.isFinite(t * 1e3)) u[e] = t * 1e3; u.supportsParallelToolCalls = asBoolean(n.supportsParallelToolCalls ?? n.supports_parallel_tool_calls); u.sslVerify = asBoolean(n.sslVerify ?? n.ssl_verify); const f = normalizeOptionalString(n.auth); u.auth = f === "oauth" ? "oauth" : void 0; u.oauth = mapHermesMcpOauth(n); const p = mapHermesClientCertificate(n); Object.assign(u, p); const m = asOptionalRecord(n.tools); const h = m ? readToolFilterList(m.include) : void 0; const g = m ? readToolFilterList(m.exclude) : void 0; const _ = parseBooleanValue(m?.resources); const v = parseBooleanValue(m?.prompts); const y = asOptionalRecord(n.toolFilter) ?? asOptionalRecord(n.tool_filter); if (y) { const e = readToolFilterList(y.include); const t = readToolFilterList(y.exclude); u.toolFilter = e?.length ? { include: e } : t?.length ? { exclude: t } : void 0; } else if (m) { if (h !== void 0) { const e = [ ...h.filter((e) => !hasUnsupportedToolPattern(e)), ..._ !== false ? MCP_RESOURCE_UTILITY_TOOLS : [], ...v !== false ? MCP_PROMPT_UTILITY_TOOLS : [] ]; u.toolFilter = e.length > 0 ? { include: e } : { exclude: ["*"] }; } else { const e = [ ...g ?? [], ..._ === false ? MCP_RESOURCE_UTILITY_TOOLS : [], ...v === false ? MCP_PROMPT_UTILITY_TOOLS : [] ]; u.toolFilter = e.length > 0 ? { exclude: e } : void 0; } } if (h === void 0 && g?.some(hasUnsupportedToolPattern)) u.enabled = false; u.env = c; u.headers = l; const b = Object.fromEntries(Object.entries(u).filter(([, e]) => e !== void 0)); const x = sanitizeName(t); const S = []; const add = (t, n, r) => { S.push(createMigrationManualItem({ id: `manual:mcp-server-${t}:${x}`, source: e.source, message: n, recommendation: r })); }; if (!r && a) add("secrets", `Hermes MCP server "${t}" has environment-backed values that were not imported without secret consent.`, "Re-run with --include-secrets or configure these values manually."); if (r && o) add("unresolved-secrets", `Hermes MCP server "${t}" references environment values that were not found in its .env file.`, "Define the missing values in OpenClaw's MCP server environment or headers manually."); const C = n.clientCert ?? n.client_cert; const w = normalizeOptionalString(n.clientKey) ?? normalizeOptionalString(n.client_key); if (Array.isArray(C) && C.length === 3) add("client-cert-password", `Hermes MCP server "${t}" uses a password-protected client key, which OpenClaw cannot represent in MCP config.`, "Configure an unencrypted protected key path or an equivalent TLS proxy manually."); else if ((C !== void 0 || w !== void 0) && !p.clientCert) add("client-cert", `Hermes MCP server "${t}" uses a combined or invalid client-certificate shape that was not imported.`, "Configure separate OpenClaw clientCert and clientKey file paths manually."); if (typeof (n.sslVerify ?? n.ssl_verify) === "string") add("tls-ca", `Hermes MCP server "${t}" uses a CA bundle path for TLS verification, which OpenClaw MCP config cannot represent.`, "Install the CA in the host trust store or configure an equivalent TLS proxy manually."); if (d && ![ "http", "streamable-http", "sse", "stdio" ].includes(d)) add("transport", `Hermes MCP server "${t}" uses unsupported transport "${d}".`, "Configure an equivalent OpenClaw MCP transport manually."); if (f && f !== "oauth") add("auth", `Hermes MCP server "${t}" uses unsupported authentication mode "${f}".`, "Configure an equivalent OpenClaw MCP authentication mode manually."); const T = asOptionalRecord(n.oauth); if (f === "oauth" || T) add("oauth-login", `Hermes MCP server "${t}" requires OAuth login in OpenClaw.`, `Run "openclaw mcp login ${t}" after migration.`); if (T && Object.keys(T).some((e) => ![ "authProfileId", "scope", "redirectUrl", "clientMetadataUrl" ].includes(e))) add("oauth-client", `Hermes MCP server "${t}" uses pre-registered OAuth client settings that were not copied into OpenClaw config.`, `Run "openclaw mcp login ${t}" and configure supported OAuth metadata manually.`); if ((h ?? g)?.some(hasUnsupportedToolPattern)) add("tool-patterns", h === void 0 ? `Hermes MCP server "${t}" was imported disabled because its tool exclusions use unsupported fnmatch patterns.` : `Hermes MCP server "${t}" has tool include patterns that were omitted because OpenClaw supports only exact names and "*".`, "Replace ? and bracket patterns with exact tool names or equivalent * patterns in mcp.servers toolFilter, then enable the server if disabled."); if (m && (Object.keys(m).some((e) => ![ "include", "exclude", "resources", "prompts" ].includes(e)) || m.include !== void 0 && !h || m.exclude !== void 0 && !g || m.resources !== void 0 && _ === void 0 || m.prompts !== void 0 && v === void 0)) add("tool-policy", `Hermes MCP server "${t}" has a tool policy that cannot be translated exactly.`, "Review and configure mcp.servers toolFilter manually."); const E = isRecord(n.lifecycle) ? n.lifecycle : {}; const D = [ ["preflight", n.skip_preflight === true], ["sampling", isRecord(n.sampling) && n.sampling.enabled !== false], ["elicitation", isRecord(n.elicitation) && n.elicitation.enabled !== false], ["lifecycle", readPositiveNumeric(n.idle_timeout_seconds ?? E.idle_timeout_seconds) !== void 0 || readPositiveNumeric(n.max_lifetime_seconds ?? E.max_lifetime_seconds) !== void 0], ["keepalive", readPositiveNumeric(n.keepalive_interval) !== void 0] ]; for (const [e, n] of D) if (n) add(e, `Hermes MCP server "${t}" uses ${e} behavior that OpenClaw MCP config does not expose.`, "Review the server requirement and configure an equivalent deployment or runtime policy manually."); return { server: normalizeOptionalString(b.command) || normalizeOptionalString(b.url) ? b : {}, sensitive: r && a, items: S }; } //#endregion export { planHermesMcpServer as t };