openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
545 lines (543 loc) • 24.4 kB
JavaScript
import "./redact-BDinS1q9.js";
import "./errors-BxyFnvP3.js";
import "./unhandled-rejections-CDJ8dOVP.js";
import "./logger-kwZIqwuw.js";
import "./paths-ViKUYWUK.js";
import "./tmp-openclaw-dir-idKIOMmb.js";
import { r as theme } from "./theme-CdOoMzRk.js";
import { s as setVerbose } from "./globals-DBUMOBZ8.js";
import { h as writeRuntimeJson, m as defaultRuntime } from "./subsystem-DISldKSB.js";
import "./ansi-BEJF8NKS.js";
import "./boolean-C3GkJetE.js";
import "./env-Dnra1IpT.js";
import "./warning-filter-CBhOcgHd.js";
import "./utils-CS0Ikux6.js";
import { t as formatDocsLink } from "./links-8xRhWBQL.js";
import { t as hasExplicitOptions } from "./command-options-5coRiipK.js";
import "./paths-C4Oy7wjk.js";
import "./auth-profiles-DRuJBw5y.js";
import { c as normalizeAgentId } from "./session-key-DAhnzjyr.js";
import { r as listAgentIds } from "./agent-scope-bjWqU22i.js";
import "./boundary-path-Dm0QJ7-y.js";
import "./boundary-file-read-DcZxlWD8.js";
import "./logger-BmpSCz93.js";
import "./exec-B5_AYfQG.js";
import "./workspace-D4K6QX9X.js";
import "./model-selection-BnFtDmP7.js";
import { s as loadConfig } from "./io-y3Az_Onx.js";
import "./shell-env-BOu7XeT_.js";
import "./safe-text-yavot2qw.js";
import "./version-CD3oP1-d.js";
import "./env-substitution-O6uabUmO.js";
import "./includes-Bj3eLUWH.js";
import "./zod-schema.providers-core-COy5nBQ0.js";
import "./legacy-web-search-BB-ZHEhz.js";
import "./registry-C5UkPpaO.js";
import "./config-state-Br0ucqMb.js";
import "./min-host-version-RMBWtIAR.js";
import "./manifest-registry-B5JNQdOM.js";
import "./runtime-guard-PhQ6PwQa.js";
import "./avatar-policy-B5nOfso_.js";
import "./ip-Ce8EDTBZ.js";
import "./zod-schema.agent-runtime-Dtg4Jy6G.js";
import "./zod-schema.core-BuVz8Rk7.js";
import "./config-D4zN4BRl.js";
import "./file-lock-DEiVq2ow.js";
import "./audit-fs-DTQIjp2r.js";
import "./resolve-B7S4PlnO.js";
import "./profiles-COPO-hHI.js";
import { t as formatCliCommand } from "./command-format-DBQUhADm.js";
import "./tailscale-CxY-91GZ.js";
import "./tailnet-DHiKSG7V.js";
import "./net-JAg9zL0G.js";
import "./auth-Buq0Niri.js";
import "./credentials-D8pfRimu.js";
import { h as GATEWAY_CLIENT_NAMES, l as normalizeMessageChannel, m as GATEWAY_CLIENT_MODES } from "./message-channel-BliByQBl.js";
import "./store-C5UK26Ce.js";
import "./runtime-Iz8uZ7EU.js";
import "./plugins-B09-vgme.js";
import "./sessions-D9ZgHCHb.js";
import "./paths-rhN9LKM_.js";
import "./session-write-lock-va3qZE6f.js";
import "./method-scopes-BiEi0X2g.js";
import { c as randomIdempotencyKey, r as callGateway } from "./call-CQbSO4Fr.js";
import "./control-ui-shared-BBhZvISc.js";
import "./onboard-helpers-D5cfC-Ra.js";
import "./prompt-style-C4CV4Y_p.js";
import "./ports-lsof-BLEgL_Gn.js";
import "./restart-stale-pids-BsPvlGJd.js";
import "./ports-FldL_Lhq.js";
import "./logging-CznuqaMu.js";
import "./commands-C6oAw_H-.js";
import "./issue-format-BtLIwOtN.js";
import { n as withProgress } from "./progress-C78aA91n.js";
import { t as formatHelpExamples } from "./help-format-C_5MeE_w.js";
import "./identity-Dp-UIak4.js";
import "./heartbeat-Bdfr_onc.js";
import { ea as agentCommand, na as resolveSessionKeyForRequest, ua as createDefaultDeps } from "./pi-embedded-CbCYZxIb.js";
import "./internal-hooks-CIUghoK4.js";
import "./multimodal-B8yEZcl5.js";
import "./memory-search-B_aq08y5.js";
import "./provider-catalog-rVN7ZbR5.js";
import "./secret-input-DXoOLNgb.js";
import "./bindings-CFudGB9Z.js";
import "./resolve-route-DwFWP4JW.js";
import "./routing-zOQ0wwtV.js";
import "./identity-file-DVLib087.js";
import "./outbound-runtime-m-y0nd6F.js";
import "./provider-env-vars-CpUJqT5v.js";
import "./provider-auth-input-Bus9W_qh.js";
import "./provider-model-minimax-DSmX4BNO.js";
import "./provider-models-BKjzpTsb.js";
import "./anthropic-vertex-provider-B2x4YywE.js";
import "./provider-catalog-BTgF8VyO.js";
import "./provider-catalog-D0IlX18O.js";
import "./provider-catalog-BTmUX0Mp.js";
import "./provider-catalog-sph_Rl63.js";
import "./provider-catalog-C7tUyBwV.js";
import "./provider-catalog-C8dPZpHW.js";
import "./provider-catalog-BJNff1VI.js";
import "./provider-catalog-IAdymoqT.js";
import "./provider-catalog-Bjc7evzh.js";
import "./models-config.providers.discovery-CjkO08q6.js";
import "./text-runtime-DVXt5xhi.js";
import "./tool-catalog-BjSY4C4F.js";
import "./docker-Bhjg8g2t.js";
import "./sandbox-DTlKNieF.js";
import "./common-zReYuoMM.js";
import "./image-ops-By4YfyWa.js";
import "./thinking-CJoSRIGR.js";
import "./path-alias-guards-CwRM04O1.js";
import "./sandbox-paths-Cn8i8Jxm.js";
import "./channel-actions-fV93bLjV.js";
import "./mime-CsUtzcn2.js";
import "./ssrf-0bPJMoZR.js";
import "./fetch-guard-CYl1q2XH.js";
import "./provider-web-search-COZNygbd.js";
import "./manager-Bw8JrihM.js";
import "./config-schema-CPzP2Ds6.js";
import "./channel-plugin-common-ClptUZHU.js";
import "./status-helpers-Cflmo90d.js";
import "./conversation-runtime-nmWgJSXS.js";
import "./runtime-whatsapp-boundary-XjdkYMz_.js";
import "./pairing-store-BGKLrjo6.js";
import "./json-store--JDX3zNL.js";
import "./secret-file-Bif7RlZ-.js";
import "./channel-config-schema-CgpS17zB.js";
import "./setup-binary-C2MYZTCc.js";
import "./archive-pOxyr9r4.js";
import "./fs-safe-DZyOgpPN.js";
import "./signal-cli-install-fVOL9FvX.js";
import "./setup-wizard-proxy-DoOpOF8S.js";
import "./setup-BI3ohdrT.js";
import "./dm-policy-shared-DtcQProI.js";
import "./runtime-env-DQOYrXVl.js";
import "./temp-path-B91lt0LF.js";
import "./diagnostic-CDTtMQBT.js";
import "./logging-CCTKg_fh.js";
import "./config-runtime-BYNizC50.js";
import "./level-overrides-DzIzQ3ZY.js";
import "./exec-approvals-BF_Qfdq8.js";
import "./webhook-ingress-D-H5frou.js";
import "./system-events-BU_NYynX.js";
import "./ssrf-policy-DYINyIKC.js";
import { p as resolveSendableOutboundReplyParts } from "./reply-payload-CiQ7TPgp.js";
import "./hook-runtime-BUYmDbaA.js";
import "./templating-BDXRiJUh.js";
import "./channel-reply-pipeline-BxH4-AP2.js";
import "./reply-history-n7nOPLta.js";
import "./commands-registry.data-BFXJWoqi.js";
import "./commands-registry-Bh9pJ817.js";
import "./frontmatter-CP5371Rm.js";
import "./env-overrides-BNSo89u5.js";
import "./skills-M0AZJeXx.js";
import "./skills-remote-BHxDA4Jw.js";
import "./workspace-dirs-DqDLiRvZ.js";
import "./pairing-token-DAszGmwD.js";
import "./skill-commands-D73dGR_l.js";
import "./config-CLRQPUSt.js";
import "./routes-XT2JfvT-.js";
import "./ssh-tunnel-LM52qY6N.js";
import "./server-middleware-BP59C6FL.js";
import "./provider-auth-ref-CQEp9sp3.js";
import "./provider-auth-helpers-Do3RFvdi.js";
import "./provider-api-key-auth-BEeRW3dq.js";
import "./pairing-labels-D27Y4Vv6.js";
import "./directory-runtime-D9Y42mW-.js";
import "./read-only-account-inspect-CJPRBFj7.js";
import "./src-BoNU6eQs.js";
import "./web-media-PKy3RbRG.js";
import "./media-understanding-BDOSvuM9.js";
import "./web-media-CiSbdGPs.js";
import "./state-paths-Dvb3Mfl3.js";
import "./llm-task-Br6Ixjlh.js";
import "./pi-model-discovery-DO3tFksS.js";
import "./exec-inline-eval-CpmxWJsW.js";
import "./target-registry-9OUOvlxj.js";
import "./external-content-DZI9vlJn.js";
import "./brave-onFD06fq.js";
import "./duckduckgo-CZuAOfiQ.js";
import "./exa-5bwgY04k.js";
import "./security-runtime-xlw0Fxx2.js";
import "./provider-usage-ClxTGn5c.js";
import "./provider-models-Bjv0V4OP.js";
import "./media-understanding-provider-DllGbg-v.js";
import "./media-understanding-provider-BDq4rFL-.js";
import "./provider-onboard-CSnPvkMM.js";
import "./onboard-BU8aRvq7.js";
import "./perplexity-web-search-provider-CI38RNUU.js";
import "./perplexity-CMZbsreI.js";
import "./model-definitions-CLagLj0g.js";
import "./onboard-0P7GBI2D.js";
import "./provider-catalog-CKHo9CRM.js";
import "./provider-models-Dmjtw6kn.js";
import "./stream-C-KGzzT0.js";
import "./web-search-CO1hvu_l.js";
import "./stagger-CFqdtCYL.js";
import "./command-secret-targets-DLs8jC2H.js";
import "./delivery-queue-DHURMSqX.js";
import "./channel-summary-Ctrv7moa.js";
import "./follow-redirects-CVAaqIk4.js";
import "./tool-policy-match-DQWWRSN4.js";
import "./runtime-CAdCdG-M.js";
import "./channel-status-BfM90KqH.js";
import "./discord-core-DLbIyXWy.js";
import "./cli-runtime-Cx1v7N7v.js";
import "./config-presence-DA3j8Nmi.js";
import "./query-expansion-BOJBTXsp.js";
import "./search-manager-DNBHwaee.js";
import "./acp-runtime-BHZj-SLU.js";
import "./telegram-core-DD8gCuaX.js";
import "./audit-BI48Fi3j.js";
import "./gateway-runtime-Dn2qAGY7.js";
import "./connection-auth-Nl2a3tDb.js";
import "./mcp-config-CDIWSqVk.js";
import "./audit-86GvYypd.js";
import "./thread-bindings.messages-C6WRAx05.js";
import "./thread-bindings-neFAVWsT.js";
import "./ui-BU9Tv965.js";
import "./src-VVAfbRUn.js";
import "./resolve-users-D9S1NRZ1.js";
import "./imessage-BRjuIPul.js";
import "./process-runtime-2HF_sK3e.js";
import "./runtime-api-B4lElrxZ.js";
import "./bluebubbles-CdXWcHgX.js";
import "./setup-browser-C8lmlIf9.js";
import "./setup-runtime-CjEiGRp0.js";
import "./setup-tools-CYv8hVOc.js";
import "./setup-group-access-BIiwXi_V.js";
import "./bluebubbles-C-vwXagf.js";
import "./extension-shared-B8dMu-tU.js";
import "./setup-surface-DM-pV9Ix.js";
import "./minimal-Doz_iD-a.js";
import "./setup-api-D7qs7Z5Z.js";
import "./persistent-dedupe-DLTWsJ9z.js";
import "./api-Br05XeQp.js";
import "./feishu-BM7gmhxZ.js";
import "./imessage-core-BbA_1gYA.js";
import "./api-qOpfHwS8.js";
import "./irc-CM9uaPrA.js";
import "./outbound-media-CVWWX2Ba.js";
import "./mattermost-F8jpkSs5.js";
import "./nextcloud-talk-Cj4b_dHp.js";
import "./param-readers-DIbGi64k.js";
import "./slack-core--OdB1drR.js";
import "./resolve-users-BA71J77K.js";
import "./action-runtime-C0myurlB.js";
import "./api-DlugfmwO.js";
import "./accounts-DcKwFiLd.js";
import "./zalo-6U_b4ilp.js";
import "./webhook-shared-wpLr3n4O.js";
import "./runtime-api-BimI9sAG.js";
import "./channel-CBJnbea3.js";
import "./setup-surface-D8ZE2LH6.js";
import "./runtime-DivGFkSR.js";
import "./bluebubbles-x-TzxqSy.js";
import "./discord-9A2HgP-p.js";
import "./setup-core-BcW9GMrI.js";
import "./shared-DTaF-SKX.js";
import "./setup-entry-CUpyuO5R.js";
import "./reactions-D-MAcsS5.js";
import "./feishu-D5J4efNO.js";
import "./runtime-api-CSiGmzHH.js";
import "./channel-1opGQxxp.js";
import "./runtime-fsOjlmjW.js";
import "./directory.static-zlBKePf0.js";
import "./policy-CC9rXiKf.js";
import "./send-Bz-uzZMi.js";
import "./monitor-D_1NURG9.js";
import "./runtime-DGI-s6ww.js";
import "./setup-core-vcqRwDmU.js";
import "./shared-9ze9PBZv.js";
import "./imessage-CaZkDkSp.js";
import "./setup-entry-EQ1kFBYF.js";
import "./channel-B8BhDC3f.js";
import "./irc-C4bMAwz0.js";
import "./line-DGETnHu0.js";
import "./channel-shared-COhzQJI4.js";
import "./setup-entry-Cm-saTVM.js";
import "./runtime-api-BAg5kdUk.js";
import "./channel-Bvdwakg3.js";
import "./mattermost-BsYWfdTH.js";
import "./runtime-api-BfjTlL7o.js";
import "./channel-CqgJouqd.js";
import "./nextcloud-talk-D5oEMARi.js";
import "./signal-CUVrLAug.js";
import "./setup-core-BnluiWdh.js";
import "./shared-twzds-Nk.js";
import "./setup-entry-cO3V5zr8.js";
import "./slack-BWphiJu-.js";
import "./setup-surface-BGae7rU92.js";
import "./setup-entry-BWAA2pOv.js";
import "./setup-surface-r2mesIzg.js";
import "./channel-DFhfHAnA.js";
import "./synology-chat-xdAzk8Oy.js";
import "./telegram-CcmyE7TJ.js";
import "./shared-BfUjqgSp.js";
import "./setup-entry-BObjzcQ7.js";
import "./runtime-api-BMKyGGGe.js";
import "./runtime-api-BRYi0Pok.js";
import "./channel-C7j1bmdJ.js";
import "./runtime-DCO0BW-8.js";
import "./zalo-CD7xjvS-.js";
import "./agent-DtXXgp1u.js";
import "./install-source-utils-C3NuFv6M.js";
import "./installs-Qst5vOrV.js";
import "./status-DI5hmNdJ.js";
import { n as runCommandWithRuntime } from "./cli-utils-C5ijQCJ_.js";
import "./catalog-CgTRyvtW.js";
import "./note-Cq-EkeJ6.js";
import "./clack-prompter-BKFiPwYT.js";
import "./plugin-install-plan-L6kxUjNd.js";
import "./bundled-sources-xtMJNHi6.js";
import "./plugin-install-Bu44eMFG.js";
import { t as collectOption } from "./helpers-CvoyfQ8F.js";
import "./agents.config-DWnSW7wb.js";
import "./provider-auth-choice-helpers-CT6THg0x.js";
import "./provider-auth-guidance-BLTUrTMo.js";
import "./config-validation-VaVjff6z.js";
import { a as agentsBindCommand, i as agentsAddCommand, n as agentsSetIdentityCommand, o as agentsBindingsCommand, r as agentsDeleteCommand, s as agentsUnbindCommand, t as agentsListCommand } from "./agents-BsrwonaH.js";
import "./provider-auth-choices-CD6TBMmn.js";
import "./provider-wizard-P1SWj0Ru.js";
import "./auth-choice-options-C699brOq.js";
import "./auth-choice-prompt-C48RYt6a.js";
import "./provider-auth-choice-Sjh-Nmtp.js";
import "./auth-choice.apply-helpers-D1SvSUlM.js";
import "./provider-auth-choice-preference-ButFS2JN.js";
import "./auth-choice-Dl2xhyk1.js";
import "./onboard-channels-Riz3r-Cw.js";
//#region src/commands/agent-via-gateway.ts
const NO_GATEWAY_TIMEOUT_MS = 2147e6;
function parseTimeoutSeconds(opts) {
const raw = opts.timeout !== void 0 ? Number.parseInt(String(opts.timeout), 10) : opts.cfg.agents?.defaults?.timeoutSeconds ?? 600;
if (Number.isNaN(raw) || raw < 0) throw new Error("--timeout must be a non-negative integer (seconds; 0 means no timeout)");
return raw;
}
function formatPayloadForLog(payload) {
const parts = resolveSendableOutboundReplyParts({
text: payload.text,
mediaUrls: payload.mediaUrls,
mediaUrl: typeof payload.mediaUrl === "string" ? payload.mediaUrl : void 0
});
const lines = [];
if (parts.text) lines.push(parts.text.trimEnd());
for (const url of parts.mediaUrls) lines.push(`MEDIA:${url}`);
return lines.join("\n").trimEnd();
}
async function agentViaGatewayCommand(opts, runtime) {
const body = (opts.message ?? "").trim();
if (!body) throw new Error("Message (--message) is required");
if (!opts.to && !opts.sessionId && !opts.agent) throw new Error("Pass --to <E.164>, --session-id, or --agent to choose a session");
const cfg = loadConfig();
const agentIdRaw = opts.agent?.trim();
const agentId = agentIdRaw ? normalizeAgentId(agentIdRaw) : void 0;
if (agentId) {
if (!listAgentIds(cfg).includes(agentId)) throw new Error(`Unknown agent id "${agentIdRaw}". Use "${formatCliCommand("openclaw agents list")}" to see configured agents.`);
}
const timeoutSeconds = parseTimeoutSeconds({
cfg,
timeout: opts.timeout
});
const gatewayTimeoutMs = timeoutSeconds === 0 ? NO_GATEWAY_TIMEOUT_MS : Math.max(1e4, (timeoutSeconds + 30) * 1e3);
const sessionKey = resolveSessionKeyForRequest({
cfg,
agentId,
to: opts.to,
sessionId: opts.sessionId
}).sessionKey;
const channel = normalizeMessageChannel(opts.channel);
const idempotencyKey = opts.runId?.trim() || randomIdempotencyKey();
const response = await withProgress({
label: "Waiting for agent reply…",
indeterminate: true,
enabled: opts.json !== true
}, async () => await callGateway({
method: "agent",
params: {
message: body,
agentId,
to: opts.to,
replyTo: opts.replyTo,
sessionId: opts.sessionId,
sessionKey,
thinking: opts.thinking,
deliver: Boolean(opts.deliver),
channel,
replyChannel: opts.replyChannel,
replyAccountId: opts.replyAccount,
bestEffortDeliver: opts.bestEffortDeliver,
timeout: timeoutSeconds,
lane: opts.lane,
extraSystemPrompt: opts.extraSystemPrompt,
idempotencyKey
},
expectFinal: true,
timeoutMs: gatewayTimeoutMs,
clientName: GATEWAY_CLIENT_NAMES.CLI,
mode: GATEWAY_CLIENT_MODES.CLI
}));
if (opts.json) {
writeRuntimeJson(runtime, response);
return response;
}
const payloads = (response?.result)?.payloads ?? [];
if (payloads.length === 0) {
runtime.log(response?.summary ? String(response.summary) : "No reply from agent.");
return response;
}
for (const payload of payloads) {
const out = formatPayloadForLog(payload);
if (out) runtime.log(out);
}
return response;
}
async function agentCliCommand(opts, runtime, deps) {
const localOpts = {
...opts,
agentId: opts.agent,
replyAccountId: opts.replyAccount
};
if (opts.local === true) return await agentCommand(localOpts, runtime, deps);
try {
return await agentViaGatewayCommand(opts, runtime);
} catch (err) {
runtime.error?.(`Gateway agent failed; falling back to embedded: ${String(err)}`);
return await agentCommand(localOpts, runtime, deps);
}
}
//#endregion
//#region src/cli/program/register.agent.ts
function registerAgentCommands(program, args) {
program.command("agent").description("Run an agent turn via the Gateway (use --local for embedded)").requiredOption("-m, --message <text>", "Message body for the agent").option("-t, --to <number>", "Recipient number in E.164 used to derive the session key").option("--session-id <id>", "Use an explicit session id").option("--agent <id>", "Agent id (overrides routing bindings)").option("--thinking <level>", "Thinking level: off | minimal | low | medium | high | xhigh").option("--verbose <on|off>", "Persist agent verbose level for the session").option("--channel <channel>", `Delivery channel: ${args.agentChannelOptions} (omit to use the main session channel)`).option("--reply-to <target>", "Delivery target override (separate from session routing)").option("--reply-channel <channel>", "Delivery channel override (separate from routing)").option("--reply-account <id>", "Delivery account id override").option("--local", "Run the embedded agent locally (requires model provider API keys in your shell)", false).option("--deliver", "Send the agent's reply back to the selected channel", false).option("--json", "Output result as JSON", false).option("--timeout <seconds>", "Override agent command timeout (seconds, default 600 or config value)").addHelpText("after", () => `
${theme.heading("Examples:")}
${formatHelpExamples([
["openclaw agent --to +15555550123 --message \"status update\"", "Start a new session."],
["openclaw agent --agent ops --message \"Summarize logs\"", "Use a specific agent."],
["openclaw agent --session-id 1234 --message \"Summarize inbox\" --thinking medium", "Target a session with explicit thinking level."],
["openclaw agent --to +15555550123 --message \"Trace logs\" --verbose on --json", "Enable verbose logging and JSON output."],
["openclaw agent --to +15555550123 --message \"Summon reply\" --deliver", "Deliver reply."],
["openclaw agent --agent ops --message \"Generate report\" --deliver --reply-channel slack --reply-to \"#reports\"", "Send reply to a different channel/target."]
])}
${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/agent")}`).action(async (opts) => {
setVerbose((typeof opts.verbose === "string" ? opts.verbose.toLowerCase() : "") === "on");
const deps = createDefaultDeps();
await runCommandWithRuntime(defaultRuntime, async () => {
await agentCliCommand(opts, defaultRuntime, deps);
});
});
const agents = program.command("agents").description("Manage isolated agents (workspaces + auth + routing)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/agents", "docs.openclaw.ai/cli/agents")}\n`);
agents.command("list").description("List configured agents").option("--json", "Output JSON instead of text", false).option("--bindings", "Include routing bindings", false).action(async (opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsListCommand({
json: Boolean(opts.json),
bindings: Boolean(opts.bindings)
}, defaultRuntime);
});
});
agents.command("bindings").description("List routing bindings").option("--agent <id>", "Filter by agent id").option("--json", "Output JSON instead of text", false).action(async (opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsBindingsCommand({
agent: opts.agent,
json: Boolean(opts.json)
}, defaultRuntime);
});
});
agents.command("bind").description("Add routing bindings for an agent").option("--agent <id>", "Agent id (defaults to current default agent)").option("--bind <channel[:accountId]>", "Binding to add (repeatable). If omitted, accountId is resolved by channel defaults/hooks.", collectOption, []).option("--json", "Output JSON summary", false).action(async (opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsBindCommand({
agent: opts.agent,
bind: Array.isArray(opts.bind) ? opts.bind : void 0,
json: Boolean(opts.json)
}, defaultRuntime);
});
});
agents.command("unbind").description("Remove routing bindings for an agent").option("--agent <id>", "Agent id (defaults to current default agent)").option("--bind <channel[:accountId]>", "Binding to remove (repeatable)", collectOption, []).option("--all", "Remove all bindings for this agent", false).option("--json", "Output JSON summary", false).action(async (opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsUnbindCommand({
agent: opts.agent,
bind: Array.isArray(opts.bind) ? opts.bind : void 0,
all: Boolean(opts.all),
json: Boolean(opts.json)
}, defaultRuntime);
});
});
agents.command("add [name]").description("Add a new isolated agent").option("--workspace <dir>", "Workspace directory for the new agent").option("--model <id>", "Model id for this agent").option("--agent-dir <dir>", "Agent state directory for this agent").option("--bind <channel[:accountId]>", "Route channel binding (repeatable)", collectOption, []).option("--non-interactive", "Disable prompts; requires --workspace", false).option("--json", "Output JSON summary", false).action(async (name, opts, command) => {
await runCommandWithRuntime(defaultRuntime, async () => {
const hasFlags = hasExplicitOptions(command, [
"workspace",
"model",
"agentDir",
"bind",
"nonInteractive"
]);
await agentsAddCommand({
name: typeof name === "string" ? name : void 0,
workspace: opts.workspace,
model: opts.model,
agentDir: opts.agentDir,
bind: Array.isArray(opts.bind) ? opts.bind : void 0,
nonInteractive: Boolean(opts.nonInteractive),
json: Boolean(opts.json)
}, defaultRuntime, { hasFlags });
});
});
agents.command("set-identity").description("Update an agent identity (name/theme/emoji/avatar)").option("--agent <id>", "Agent id to update").option("--workspace <dir>", "Workspace directory used to locate the agent + IDENTITY.md").option("--identity-file <path>", "Explicit IDENTITY.md path to read").option("--from-identity", "Read values from IDENTITY.md", false).option("--name <name>", "Identity name").option("--theme <theme>", "Identity theme").option("--emoji <emoji>", "Identity emoji").option("--avatar <value>", "Identity avatar (workspace path, http(s) URL, or data URI)").option("--json", "Output JSON summary", false).addHelpText("after", () => `
${theme.heading("Examples:")}
${formatHelpExamples([
["openclaw agents set-identity --agent main --name \"OpenClaw\" --emoji \"🦞\"", "Set name + emoji."],
["openclaw agents set-identity --agent main --avatar avatars/openclaw.png", "Set avatar path."],
["openclaw agents set-identity --workspace ~/.openclaw/workspace --from-identity", "Load from IDENTITY.md."],
["openclaw agents set-identity --identity-file ~/.openclaw/workspace/IDENTITY.md --agent main", "Use a specific IDENTITY.md."]
])}
`).action(async (opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsSetIdentityCommand({
agent: opts.agent,
workspace: opts.workspace,
identityFile: opts.identityFile,
fromIdentity: Boolean(opts.fromIdentity),
name: opts.name,
theme: opts.theme,
emoji: opts.emoji,
avatar: opts.avatar,
json: Boolean(opts.json)
}, defaultRuntime);
});
});
agents.command("delete <id>").description("Delete an agent and prune workspace/state").option("--force", "Skip confirmation", false).option("--json", "Output JSON summary", false).action(async (id, opts) => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsDeleteCommand({
id: String(id),
force: Boolean(opts.force),
json: Boolean(opts.json)
}, defaultRuntime);
});
});
agents.action(async () => {
await runCommandWithRuntime(defaultRuntime, async () => {
await agentsListCommand({}, defaultRuntime);
});
});
}
//#endregion
export { registerAgentCommands };