UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

80 lines (79 loc) • 3.43 kB
import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs"; import { u as getPluginMetadataSnapshotCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs"; import { S as resolveRuntimeConfigCacheKey } from "./runtime-snapshot-WbwbY5b7.mjs"; import { n as resolveMcpTransportConfig } from "./mcp-transport-config-r6XeT3o8.mjs"; import { i as loadEnabledBundleMcpConfig } from "./bundle-mcp-DKz8uq8U.mjs"; import { r as mergeConfiguredBundleMcpServers, u as partitionMcpServersByConnectionScope } from "./bundle-mcp-config-Ca9TXxki.mjs"; import { i as operatorMcpOAuthIdentity } from "./mcp-oauth-identity-B4O1ccto.mjs"; //#region src/plugins/mcp-auth-status.ts /** The shared operator OAuth connection that Settings may inspect and sign in. */ function resolveOperatorMcpOAuthConfig(e, t) { const n = asOptionalObjectRecord(t); if (!n || n.enabled === false) return; const r = resolveMcpTransportConfig(e, n, { logWarnings: false }); return r?.kind === "http" && r.auth === "oauth" && !r.oauth?.authProfileId && Object.hasOwn(partitionMcpServersByConnectionScope({ [e]: n }).staticServers, e) ? r : void 0; } function resolvePluginMcpAuthDeclarations(e, t) { const n = getPluginMetadataSnapshotCache(t); let r = n.metadata.mcpAuthDeclarations.get(t); if (!r) { r = /* @__PURE__ */ new WeakMap(); n.metadata.mcpAuthDeclarations.set(t, r); } const i = resolveRuntimeConfigCacheKey(e); const a = r.get(e); if (a?.configKey === i) return a.declarations; const o = withPluginCache(n, () => loadEnabledBundleMcpConfig({ cfg: e, workspaceDir: t.workspaceDir ?? "", manifestRegistry: t.manifestRegistry })); const s = /* @__PURE__ */ new Map(); for (const [e, t] of Object.entries(o.pluginIdsByServer).toSorted(([e], [t]) => e.localeCompare(t))) { const n = resolveMcpTransportConfig(e, o.config.mcpServers[e], { logWarnings: false }); if (n?.kind === "http") { const r = s.get(t) ?? []; r.push({ serverName: e, url: n.url }); s.set(t, r); } } const c = { byPluginId: s, bundled: o }; r.set(e, { configKey: i, declarations: c }); return c; } /** Select sign-in from the caller's active inventory, with explicit config taking precedence. */ function resolveOperatorMcpOAuthConnection(e) { const t = e.metadata ? mergeConfiguredBundleMcpServers(resolvePluginMcpAuthDeclarations(e.config, e.metadata).bundled, { cfg: e.config }).config.mcpServers[e.serverName] : e.config.mcp?.servers?.[e.serverName]; const n = resolveOperatorMcpOAuthConfig(e.serverName, t); return n && t ? { config: n, server: t } : void 0; } /** Project stored auth state only for a plugin's matching, operator-owned connections. */ async function readPluginMcpAuthStatus(e) { const t = resolvePluginMcpAuthDeclarations(e.config, e.metadata); const n = mergeConfiguredBundleMcpServers(t.bundled, { cfg: e.config }).config.mcpServers; const r = (t.byPluginId.get(e.pluginId) ?? []).flatMap(({ serverName: e, url: t }) => { const r = resolveOperatorMcpOAuthConfig(e, n[e]); return r && r.url === t ? [operatorMcpOAuthIdentity(e, r.url)] : []; }); if (r.length === 0) return; const { readMcpOAuthCredentialsStatuses: i } = await import("./mcp-oauth-Bzsr2nlm.mjs"); const a = await i(r); return r.map((e, t) => ({ serverName: e.serverName, state: a[t].state })); } //#endregion export { resolveOperatorMcpOAuthConnection as n, readPluginMcpAuthStatus as t };