openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.45 kB
JavaScript
import{l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{D as parseStrictPositiveInteger}from"./number-coercion-B3CfI447.mjs";import{o as writeRuntimeJson}from"./runtime-DIcLIHcp.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{m as resolveAmbientOwnerAgentId}from"./agent-scope-config-CG9CFpGX.mjs";import{i as GATEWAY_CLIENT_NAMES,r as GATEWAY_CLIENT_MODES}from"./client-info-Dr3-kuD1.mjs";import{t as captureRuntimeConfigAsyncReader}from"./io.runtime-BvSeVFIY.mjs";import"./config-DkZ8y8Gv.mjs";import{n as prepareTemplateInstallSchemaVersions}from"./provenance-runtime-read-DtuKDa_2.mjs";import{a as collectTemplateToolPolicyCandidates,r as prepareCapturedTemplateToolPolicyConsent}from"./tool-policy-runtime-DUKk2eWW.mjs";import{t as createOutboundSendDeps}from"./outbound-send-deps-CZdlQN0d.mjs";import{r as formatCliJsonFailure}from"./failure-output-Gn9zHEk3.mjs";import{r as withProgress}from"./progress-BcNIavn6.mjs";import{u as getScopedChannelsCommandSecretTargets}from"./command-secret-targets-X-olXSJu.mjs";import{t as CHANNEL_MESSAGE_ACTION_NAMES}from"./message-action-names-8lTam9uQ.mjs";import{n as resolveMessageBroadcastAccountPlan,r as validateExplicitMessageAccountSelection}from"./message-account-selection-C2NVCWJd.mjs";import{t as resolveMessageSecretScope}from"./message-secret-scope-Bx2V-nug.mjs";import{i as resolveMessageActionOutcome,r as resolveMessageActionMessageId}from"./message-action-contracts-izoq6ULC.mjs";import{n as runMessageAction}from"./message-action-runner-DTcRCNzt.mjs";import{t as resolveCommandConfigWithSecrets}from"./command-config-resolution-D_5kK7Ri.mjs";
//!src/commands/message.ts
async function messageCommand(e,t,n){const r=await captureRuntimeConfigAsyncReader()();const i=(normalizeOptionalString(e.action)??``)||`send`;const a=normalizeLowercaseStringOrEmpty(i);const o=resolveMessageSecretScope({channel:e.channel,target:e.target,targets:e.targets,accountId:e.accountId});const s=await validateExplicitMessageAccountSelection({cfg:r,channel:o.channel,accountId:e.accountId,checkResolvedAccount:false});if(s){o.accountId=s;e.accountId=s}const c=a===`broadcast`&&!o.channel&&s?await resolveMessageBroadcastAccountPlan({cfg:r,accountId:s}):void 0;const l=getScopedChannelsCommandSecretTargets({config:r,channel:o.channel,...c?{channels:c.secretChannels}:{},accountId:o.accountId});const{effectiveConfig:u}=await resolveCommandConfigWithSecrets({config:r,commandName:`message`,targetIds:l.targetIds,...l.allowedPaths?{allowedPaths:l.allowedPaths}:{},runtime:n,autoEnable:true});const d=resolveAmbientOwnerAgentId(u,void 0,{surface:`message CLI`,hint:`Run ${formatCliCommand(`openclaw config set agents.defaults.systemAgent.agentId <id>`)} with a configured agent ID.`});const f=CHANNEL_MESSAGE_ACTION_NAMES.find(e=>normalizeLowercaseStringOrEmpty(e)===a);if(!f)throw new Error(`Unknown message action "${i}". Use one of ${CHANNEL_MESSAGE_ACTION_NAMES.join(`, `)}. Example: ${formatCliCommand(`openclaw message send --channel <channel> --target <id> --text <message>`)}.`);if(collectTemplateToolPolicyCandidates(u).length>0){(await prepareTemplateInstallSchemaVersions({artifactPreservingReadOnly:false})).publish();prepareCapturedTemplateToolPolicyConsent(u,{})}const p=createOutboundSendDeps(t);const run=async()=>await runMessageAction({cfg:u,action:f,params:e,deps:p,agentId:d,senderIsOwner:e.senderIsOwner!==false,conversationReadOrigin:`direct-operator`,broadcastAccountPlan:c,gateway:{clientName:GATEWAY_CLIENT_NAMES.CLI,mode:GATEWAY_CLIENT_MODES.CLI}});const m=e.json===true;const h=e.dryRun===true;const g=!m&&!h&&(f===`send`||f===`poll`)?await withProgress({label:f===`poll`?`Sending poll...`:`Sending...`,indeterminate:true,enabled:true},run):await run();if(m){const e=resolveMessageActionMessageId(g.payload);const t=g.kind===`send`?g.sendResult:void 0;const r=resolveMessageActionOutcome(g);writeRuntimeJson(n,{...g.kind===`broadcast`?{ok:r.ok}:!r.ok?{...formatCliJsonFailure(r.error),...t?{deliveryStatus:t.deliveryStatus}:{},...r.sentBeforeError?{sentBeforeError:true}:{}}:{},action:g.action,channel:g.channel,dryRun:g.dryRun,handledBy:g.handledBy,...e?{messageId:e}:{},payload:g.payload});return g}const{formatMessageCliText:_}=await import(`./message-format-CGbm1tV0.mjs`);const v=parseStrictPositiveInteger(e.limit);for(const e of _(g,{displayLimit:v}))n.log(e);return g}export{messageCommand};