openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.62 kB
JavaScript
import{i as asOptionalObjectRecord}from"./record-coerce-BTbqdJ3-.mjs";import{u as getPluginMetadataSnapshotCache,w as withPluginCache}from"./plugin-cache-B6QVpzXr.mjs";import{S as resolveRuntimeConfigCacheKey}from"./runtime-snapshot-Bg5K4JNu.mjs";import{n as resolveMcpTransportConfig}from"./mcp-transport-config-BYp4GLEU.mjs";import{a as loadPluginDeclaredMcpServers,i as loadEnabledBundleMcpConfig}from"./bundle-mcp-C7QktGfB.mjs";import{r as mergeConfiguredBundleMcpServers,u as partitionMcpServersByConnectionScope}from"./bundle-mcp-config-C-R5gRDz.mjs";import{i as operatorMcpOAuthIdentity}from"./mcp-oauth-identity-DSHLyzOx.mjs";
//!src/plugins/mcp-auth-status.ts
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}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}function listPluginMcpOAuthEndpoints(e){return e.flatMap(e=>Object.entries(loadPluginDeclaredMcpServers(e)).flatMap(([e,t])=>{const n=resolveMcpTransportConfig(e,t,{logWarnings:false});return n?.kind===`http`?[{serverName:e,url:n.url}]:[]}))}async function clearRemovedPluginMcpOAuth(e){const{clearMcpOAuthServer:t}=await import(`./mcp-oauth-CL-Jy2gP.mjs`);const n=[];for(const{serverName:r,url:i}of e.endpoints){const a=resolveMcpTransportConfig(r,e.config.mcp?.servers?.[r],{logWarnings:false});if(a?.kind===`http`&&a.url===i)continue;try{await t(operatorMcpOAuthIdentity(r,i),{assertCurrent:e.assertCurrent})}catch{e.assertCurrent();n.push(`The saved sign-in for MCP server "${r}" could not be removed. Reinstall the plugin and select Sign out to remove it.`)}}return n}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-CL-Jy2gP.mjs`);const a=await i(r);return r.map((e,t)=>({serverName:e.serverName,state:a[t].state}))}export{resolveOperatorMcpOAuthConnection as i,listPluginMcpOAuthEndpoints as n,readPluginMcpAuthStatus as r,clearRemovedPluginMcpOAuth as t};