UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.93 kB
import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{n as sha256Hex}from"./node-crypto-DPk8agfR.mjs";import{t as quoteCliArg}from"./quote-cli-arg-BUHoGELl.mjs";import{c as sanitizeServerName}from"./agent-bundle-mcp-names-CR4QEOJd.mjs"; //!src/agents/mcp-oauth-identity.ts function operatorMcpOAuthIdentity(e,t,n){return{storeKey:`${sanitizeServerName(e,/* @__PURE__ */ new Set)}-${sha256Hex(`${e}\0${t}`).slice(0,16)}`,principal:`operator`,serverName:e,serverUrl:t,...n?{configured:Object.hasOwn(n.mcp?.servers??{},e)}:{}}}function mcpOAuthCliLoginSteps(e){if(e.principal!==`operator`||!e.configured)return;const t=formatCliCommand(`openclaw mcp login ${quoteCliArg(e.serverName)}`);return`stop the Gateway with ${formatCliCommand(`openclaw gateway stop`)}, run ${t}, then start the Gateway again`}function mcpOAuthSignInHint(e){if(e.principal===`requester`)return`Reconnect from the channel through the MCP connect flow.`;const t=mcpOAuthCliLoginSteps(e);if(t)return`Sign in from Settings → MCP, or from the Gateway's terminal: ${t}.`;return e.configured===false?`Select Connect on the plugin's page in Settings to sign in again.`:`Sign in again from Settings: select Connect on the plugin's page, or Sign in on the MCP page.`}function requesterMcpOAuthIdentity(e,t,n){const r=operatorMcpOAuthIdentity(e,t);const i=sha256Hex(`${n.messageChannel??``}\0${n.agentAccountId??``}\0${n.requesterSenderId}`);return{...r,storeKey:`${r.storeKey}-r-${i.slice(0,16)}`,principal:`requester`}}function requesterMcpOAuthStoreKeyPrefix(e,t){return`${operatorMcpOAuthIdentity(e,t).storeKey}-r-`}function mcpOAuthStoreKeyFromLegacyFileName(e){return/^[A-Za-z][A-Za-z0-9_-]{0,29}-[0-9a-f]{16}\.json$/u.test(e)?e.slice(0,-5):null}export{requesterMcpOAuthIdentity as a,operatorMcpOAuthIdentity as i,mcpOAuthSignInHint as n,requesterMcpOAuthStoreKeyPrefix as o,mcpOAuthStoreKeyFromLegacyFileName as r,mcpOAuthCliLoginSteps as t};