openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4 lines • 4.62 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{f as normalizeStringEntries}from"./string-normalization-D_oBUpO3.mjs";import{i as normalizeChatChannelId}from"./ids-CXs0NhN-.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{t as PluginSetupPreparationRequiredError}from"./plugin-setup-module-DKdTsN2H.mjs";import{t as INTERNAL_MESSAGE_CHANNEL}from"./message-channel-constants-BbP_hczw.mjs";import{i as resolveChannelPluginRegistration,t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{r as resolveReadOnlyChannelPluginsForConfig}from"./read-only-B-Uv2t8Q.mjs";
//!src/commands/doctor-command-owner.ts
function createCommandOwnerChannelResolver(e){let t;return n=>{const r=resolveChannelPluginRegistration(n,{loadedOnly:true})?.plugin;if(r)return r;if(!t)try{t=resolveReadOnlyChannelPluginsForConfig(e,{includePersistedAuthState:false,includeSetupFallbackPlugins:true}).plugins}catch(e){if(e instanceof PluginSetupPreparationRequiredError)throw e;t=[]}const i=t.find(e=>e.id===n);return i?.messaging?.inferTargetChatType?i:getChannelPlugin(n)??i}}function migrateLegacyCommandOwners(e,t){const n=e.commands?.ownerAllowFrom;if(!Array.isArray(n))return e;let r=false;const i=createCommandOwnerChannelResolver(e);const a=n.map((e,n)=>{const a=typeof e===`string`?/^([^:]+):user:([^:\s*]+)$/i.exec(e.trim()):null;const o=a&&normalizeChatChannelId(a[1]);if(!o||!a)return e;const s=i(o);if(!s||s.messaging?.directTargetStyle===`user-prefixed`)return e;r=true;t.push(`Normalized commands.ownerAllowFrom[${n}] from ${o}:user:id to ${o}:id.`);return`${o}:${a[2]}`});return r?{...e,commands:{...e.commands,ownerAllowFrom:a}}:e}function resolveConfiguredCommandOwners(e){const t=e.commands?.ownerAllowFrom;if(!Array.isArray(t))return[];return normalizeStringEntries(t.map(e=>String(e??``))).filter(e=>e!==`*`&&!e.endsWith(`:*`))}function hasConfiguredCommandOwners(e){return resolveConfiguredCommandOwners(e).length>0}function formatCommandOwnerFromChannelSender(e){const t=normalizeOptionalString(e.id);if(!t)return null;const n=t.indexOf(`:`);if(n>0){if(t.slice(0,n).toLowerCase()===String(e.channel).toLowerCase())return t}return`${e.channel}:${t}`}function formatCommandOwnerHint(e){if(e.channel===`webchat`)return`Ask the operator to grant this Gateway client operator.admin access.`;const t=e.channel&&e.id?formatCommandOwnerFromChannelSender({channel:e.channel,id:e.id}):null;if(!t)return`Ask the operator to set commands.ownerAllowFrom to your channel user id.`;if(!e.cfg)return`Ask the operator to add \`${t}\` to \`commands.ownerAllowFrom\`.`;const n=JSON.stringify([.../* @__PURE__ */ new Set([...resolveConfiguredCommandOwners(e.cfg),t])]).replaceAll(`'`,process.platform===`win32`?`''`:`'\\''`);return`Ask the operator to run \`${formatCliCommand(`openclaw config set commands.ownerAllowFrom`)} '${n}'\` in a terminal to make this sender a command owner.`}function noteCommandOwnerHealth(e){if(hasConfiguredCommandOwners(e))return;note([`No channel command owner is configured.`,`A command owner is your trusted human operator account, allowed to update OpenClaw with /update, restart the Gateway, change configuration, and approve commands. Chat allowlists do not grant this authority.`,`Local Control UI/WebChat clients with operator.admin already have owner authority; no channel is required. Run ${formatCliCommand(`openclaw dashboard`)} on the Gateway host and open its link in your browser (use ${formatCliCommand(`openclaw dashboard --json`)} on a headless host).`,`If the Control UI shows limited access, open Inbox > System > Limited access > Request admin, then run its displayed ${formatCliCommand(`openclaw devices approve <requestId>`)} command on the Gateway host.`,`For external channels, run ${formatCliCommand(`openclaw channels add`)} and complete a channel's setup to choose your operator account, including servers and groups without DM pairing.`,`CLI channel pairing approval records the first command owner. Control UI channel-sender approval has a separate owner checkbox.`,`For an existing channel sender, set commands.ownerAllowFrom to your channel user id, for example ${formatCliCommand(`openclaw config set commands.ownerAllowFrom '["telegram:123456789"]'`)}`,`Restart the Gateway after changing commands.ownerAllowFrom if it is already running.`].join(`
`),`Command owner`)}export{migrateLegacyCommandOwners as a,hasConfiguredCommandOwners as i,formatCommandOwnerFromChannelSender as n,noteCommandOwnerHealth as o,formatCommandOwnerHint as r,createCommandOwnerChannelResolver as t};