UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

118 lines (117 loc) • 5.08 kB
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs"; import { o as writeRuntimeJson } from "./runtime-B-SLYP-m.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { m as resolveAmbientOwnerAgentId } from "./agent-scope-config-DmXgFGKP.mjs"; import { i as GATEWAY_CLIENT_NAMES, r as GATEWAY_CLIENT_MODES } from "./client-info-Cm1BcrMm.mjs"; import { t as captureRuntimeConfigAsyncReader } from "./io.runtime-DsJ2dLCQ.mjs"; import "./config-CMA-J084.mjs"; import { n as prepareTemplateInstallSchemaVersions } from "./provenance-runtime-read-CXIQNtS8.mjs"; import { a as collectTemplateToolPolicyCandidates, r as prepareCapturedTemplateToolPolicyConsent } from "./tool-policy-runtime-CvSLQvPo.mjs"; import { t as createOutboundSendDeps } from "./outbound-send-deps-BV7tqdFC.mjs"; import { r as formatCliJsonFailure } from "./failure-output-DVVDqwuu.mjs"; import { t as CHANNEL_MESSAGE_ACTION_NAMES } from "./message-action-names-BPsScVN2.mjs"; import { r as withProgress } from "./progress-DZHhZ1Fk.mjs"; import { u as getScopedChannelsCommandSecretTargets } from "./command-secret-targets-CH2XIeV_.mjs"; import { n as resolveMessageBroadcastAccountPlan, r as validateExplicitMessageAccountSelection } from "./message-account-selection-DxhPXlSt.mjs"; import { t as resolveMessageSecretScope } from "./message-secret-scope-Cz7XDJ3I.mjs"; import { i as resolveMessageActionOutcome, r as resolveMessageActionMessageId } from "./message-action-contracts-Al2l9Lkb.mjs"; import { n as runMessageAction } from "./message-action-runner-CN0QRJoV.mjs"; import { t as resolveCommandConfigWithSecrets } from "./command-config-resolution-Bv3V6f3-.mjs"; //#region 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-D865NdDl.mjs"); const v = parseStrictPositiveInteger(e.limit); for (const e of _(g, { displayLimit: v })) n.log(e); return g; } //#endregion export { messageCommand };