openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 2.47 kB
JavaScript
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { n as sha256Hex } from "./node-crypto-B6yuTjmm.mjs";
import { t as quoteCliArg } from "./quote-cli-arg-J7A9UE6m.mjs";
import { c as sanitizeServerName } from "./agent-bundle-mcp-names-856aMFJA.mjs";
//#region src/agents/mcp-oauth-identity.ts
/** Pass `cfg` when known so sign-in errors can name the CLI for `mcp.servers` entries. */
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) } : {}
};
}
/**
* Terminal sign-in steps, or undefined when the CLI cannot sign in: `openclaw mcp login`
* runs offline only and resolves only operator `mcp.servers`, never plugin-declared servers.
*/
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`;
}
/** Recovery sentence for MCP OAuth credential errors. */
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;
}
//#endregion
export { requesterMcpOAuthIdentity as a, operatorMcpOAuthIdentity as i, mcpOAuthSignInHint as n, requesterMcpOAuthStoreKeyPrefix as o, mcpOAuthStoreKeyFromLegacyFileName as r, mcpOAuthCliLoginSteps as t };