UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

134 lines (133 loc) • 8.39 kB
import { r as createLazyRuntimeModule } from "./lazy-runtime-CJrzFzqU.mjs"; import { r as theme } from "./theme-DzaUZY4q.mjs"; import { t as formatDocsLink } from "./links-4Bgsoz0M.mjs"; import { t as hasExplicitOptions } from "./command-options-BDuSHeWG.mjs"; import { n as formatHelpExamples } from "./help-format-MN-qfst1.mjs"; import { t as collectOption } from "./helpers-Bd2A8dod.mjs"; //#region src/cli/program/register.agent.ts const loadAgentsBindModule = createLazyRuntimeModule(() => import("./agents.commands.bind-t4yVlpWM.mjs")); async function runAgentsCommandAction(action) { const [{ defaultRuntime }, { runCommandWithRuntime }] = await Promise.all([import("./runtime-pvh-jBbt.mjs"), import("./cli-utils-Db4PF41k.mjs")]); await runCommandWithRuntime(defaultRuntime, () => action(defaultRuntime)); } /** Register `agents` management subcommands for config, bindings, identity, and deletion. */ function registerAgentsCommands(program) { 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).option("--tree", "Render agent creation hierarchy", false).action(async (opts) => { await runAgentsCommandAction(async (runtime) => { const { agentsListCommand } = await import("./agents.commands.list-Cf3gZdy7.mjs"); await agentsListCommand({ json: Boolean(opts.json), bindings: Boolean(opts.bindings), tree: Boolean(opts.tree) }, runtime); }); }); 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 runAgentsCommandAction(async (runtime) => { const { agentsBindingsCommand } = await loadAgentsBindModule(); await agentsBindingsCommand({ agent: opts.agent, json: Boolean(opts.json) }, runtime); }); }); 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 runAgentsCommandAction(async (runtime) => { const { agentsBindCommand } = await loadAgentsBindModule(); await agentsBindCommand({ agent: opts.agent, bind: Array.isArray(opts.bind) ? opts.bind : void 0, json: Boolean(opts.json) }, runtime); }); }); 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 runAgentsCommandAction(async (runtime) => { const { agentsUnbindCommand } = await loadAgentsBindModule(); await agentsUnbindCommand({ agent: opts.agent, bind: Array.isArray(opts.bind) ? opts.bind : void 0, all: Boolean(opts.all), json: Boolean(opts.json) }, runtime); }); }); agents.command("add [name]").description("Add a new isolated agent").option("--workspace <dir>", "Workspace directory for the new agent").option("--role <role>", "Seed a role: coordinator, researcher, writer, reviewer").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 unless --role is set", false).option("--json", "Output JSON summary", false).action(async (name, opts, command) => { await runAgentsCommandAction(async (runtime) => { const hasAutomationFlags = hasExplicitOptions(command, [ "workspace", "model", "agentDir", "bind", "nonInteractive" ]); const { agentsAddCommand } = await import("./agents.commands.add-uIcZ98Jh.mjs"); await agentsAddCommand({ name: typeof name === "string" ? name : void 0, workspace: opts.workspace, role: typeof opts.role === "string" ? opts.role : void 0, model: opts.model, agentDir: opts.agentDir, bind: Array.isArray(opts.bind) ? opts.bind : void 0, nonInteractive: Boolean(opts.nonInteractive), json: Boolean(opts.json) }, runtime, { hasAutomationFlags }); }); }); agents.command("team").description("Create a coordinated team of agents").command("create").description("Create a coordinator and specialists from a bundled preset").option("--preset <name>", "Team preset (team)", "team").option("--coordinator <id>", "Coordinator agent id", "coordinator").option("--prefix <p>", "Prefix every team agent id with <p>-").option("--workspace-root <dir>", "Parent directory for separate team workspaces").option("--non-interactive", "Disable prompts", false).option("--json", "Output JSON summary", false).action(async (opts) => { await runAgentsCommandAction(async (runtime) => { const { agentsTeamCreateCommand } = await import("./agents.commands.team-CVFF6Ttz.mjs"); await agentsTeamCreateCommand({ preset: typeof opts.preset === "string" ? opts.preset : void 0, coordinator: typeof opts.coordinator === "string" ? opts.coordinator : void 0, prefix: typeof opts.prefix === "string" ? opts.prefix : void 0, workspaceRoot: typeof opts.workspaceRoot === "string" ? opts.workspaceRoot : void 0, nonInteractive: Boolean(opts.nonInteractive), json: Boolean(opts.json) }, runtime); }); }); agents.command("set-identity").description("Update an agent identity (name/theme/emoji/avatar)").option("--agent <id>", "Agent id to update").option("--workspace <dir>", "Locate the agent and IDENTITY.md; does not change the stored workspace").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 runAgentsCommandAction(async (runtime) => { const { agentsSetIdentityCommand } = await import("./agents.commands.identity-BVxbSAGC.mjs"); 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) }, runtime); }); }); 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 runAgentsCommandAction(async (runtime) => { const { agentsDeleteCommand } = await import("./agents.commands.delete-B3G0s9OH.mjs"); await agentsDeleteCommand({ id: String(id), force: Boolean(opts.force), json: Boolean(opts.json) }, runtime); }); }); agents.action(async () => { await runAgentsCommandAction(async (runtime) => { const { agentsListCommand } = await import("./agents.commands.list-Cf3gZdy7.mjs"); await agentsListCommand({}, runtime); }); }); } //#endregion export { registerAgentsCommands };