UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

161 lines (160 loc) • 7.36 kB
import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { a as isImplicitLocalGatewayTargetFromCli, n as callGatewayFromCli, t as addGatewayClientOptions } from "./gateway-rpc-CxUN2f1a.mjs"; import { t as runWithLocalStateOwner } from "./local-state-owner-DTl7OHpC.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./number-runtime-W4chuk8B.mjs"; import { d as compareCards, et as redactClaimToken, nt as WORKBOARD_STATUSES, tt as redactDispatchResult } from "./store-card-helpers-DOLHSumf.mjs"; import "./terminal-safe-text-DY8-BpAj.mjs"; import { n as parseTimeoutMsWithFallback } from "./parse-timeout-qqSdJSy9.mjs"; import "./gateway-runtime-Du0olVch.mjs"; import "./cli-state-owner-DWH5gh7o.mjs"; import { t as resolveWorkboardCardByIdOrPrefix } from "./card-lookup-DYBEzjOn.mjs"; //#region extensions/workboard/src/cli.ts function parseMaxStarts(e) { const t = parseStrictPositiveInteger(e); if (t === void 0) throw Object.assign(/* @__PURE__ */ new Error("--max-starts must be a positive integer."), { name: "InvalidArgumentError", code: "commander.invalidArgument", exitCode: 1 }); return t; } function writeJson(e) { process.stdout.write(`${JSON.stringify(e, null, 2)}\n`); } function writeLine(e) { process.stdout.write(`${e}\n`); } function formatCardLine(e) { const t = e.metadata?.automation?.boardId ?? "default"; const n = e.agentId ? terminalText` ${e.agentId}` : ""; const r = e.metadata?.archivedAt ? " (archived)" : ""; return terminalText`${e.id.slice(0, 8)} ${e.status.padEnd(8)} ${e.priority.padEnd(6)} ${t}${n} ${e.title}${r}`; } function writeCards(e, t) { if (t.json) { writeJson({ cards: e.map(redactClaimToken) }); return; } for (const t of e) writeLine(formatCardLine(t)); } function writeCard(e, t) { if (t.json) writeJson({ card: redactClaimToken(e) }); else writeLine(formatCardLine(e)); } function registerWorkboardCli(e) { const local = (t, n, r, i) => runWithLocalStateOwner({ method: `${t}.owner`, params: n, target: "Workboard", ...i, recoveryCommand: "openclaw workboard list --json", runLocal: ({ assertCurrent: t }) => e.withStore(async (e) => { t(); return await r(e, t); }) }); const list = async (e) => { const t = /* @__PURE__ */ new Map(); let n; do { const r = await local("workboard.cards.list", { boardId: e, ...n ? { after: n } : {} }, (t) => t.listCards(e, void 0, n)); for (const e of r.cards) t.set(e.id, e); n = r.nextCursor; } while (n); return { cards: [...t.values()].toSorted(compareCards) }; }; const t = e.program.command("workboard").description("Manage Workboard cards and worker dispatch"); t.command("list").description("List Workboard cards").option("--board <id>", "Board id").addOption(t.createOption("--status <status>", "Filter by status").choices([...WORKBOARD_STATUSES])).option("--include-archived", "Include archived cards (default false)").option("--json", "Print JSON", false).action(async (e) => { let t = (await list(e.board)).cards; if (!e.json && e.includeArchived !== true) t = t.filter((e) => !e.metadata?.archivedAt); if (e.status) t = t.filter((t) => t.status === e.status); writeCards(t, e); }); t.command("create").argument("<title...>", "Card title").description("Create a Workboard card").option("--notes <text>", "Card notes").option("--status <status>", "Initial status", "todo").option("--priority <priority>", "Priority", "normal").option("--agent <id>", "Assigned agent id").option("--board <id>", "Board id").option("--labels <items>", "Comma-separated labels").option("--json", "Print JSON", false).action(async (e, t) => { const n = { title: e.join(" "), notes: t.notes, status: t.status, priority: t.priority, agentId: t.agent, boardId: t.board, labels: t.labels }; const { card: r } = await local("workboard.cards.create", n, async (e, t) => ({ card: await e.create({ ...n, workspaceAccess: { unrestricted: true } }, void 0, t) })); writeCard(r, t); }); t.command("show").argument("<id>", "Card id or prefix").description("Show one Workboard card").option("--json", "Print JSON", false).action(async (e, t) => { const n = (await list()).cards; const { card: r, error: i } = resolveWorkboardCardByIdOrPrefix(n, e); if (!r) throw new Error(i); writeCard(r, t); if (!t.json && r.notes) writeLine(r.notes.split("\n").map((e) => terminalText`${e}`).join("\n")); }); t.command("move").argument("<id>", "Card id or prefix").description("Move a Workboard card to another status").requiredOption("--status <status>", "Target status").option("--json", "Print JSON", false).action(async (e, t) => { if (!WORKBOARD_STATUSES.includes(t.status)) throw new Error(`--status must be one of: ${WORKBOARD_STATUSES.join(", ")}.`); const n = (await list()).cards; const { card: r, error: i } = resolveWorkboardCardByIdOrPrefix(n, e); if (!r) throw new Error(i); const a = { id: r.id, status: t.status, expectedUpdatedAt: r.updatedAt }; const { card: o } = await local("workboard.cards.move", a, async (e, n) => ({ card: await e.move(r.id, t.status, void 0, void 0, { expectedUpdatedAt: r.updatedAt, assertOwnerCurrent: n }) })); writeCard(o, t); }); addGatewayClientOptions(t.command("dispatch").description("Promote ready cards and start worker runs through the Gateway").option("--board <id>", "Dispatch a single board").option("--max-starts <count>", "Maximum new worker runs to start in this pass (default 3)", parseMaxStarts).option("--admin", "Request full-host workspace access", false).option("--json", "Print JSON", false)).action(async (e) => { const t = e.maxStarts === void 0 ? "workboard.cards.dispatch" : "workboard.cards.dispatchWithOptions"; const n = { boardId: e.board, ...e.maxStarts !== void 0 ? { maxStarts: e.maxStarts } : {} }; const r = e.admin ? [ "operator.admin", "operator.write", "operator.read" ] : ["operator.write", "operator.read"]; const i = await (!e.token?.trim() && !e.password?.trim() && await isImplicitLocalGatewayTargetFromCli(e) ? local(t, n, async (t, n) => ({ ...redactDispatchResult(await t.dispatch({ boardId: e.board, assertOwnerCurrent: n })), gatewayUnavailable: true, started: [], startFailures: [] }), { scopes: r, timeoutMs: parseTimeoutMsWithFallback(e.timeout, 3e4, { invalidType: "error" }), expectFinal: e.expectFinal }) : callGatewayFromCli(t, e, n, { mode: "cli", scopes: r })); if (e.json) writeJson(i); else { const e = isRecord(i) ? i : {}; if (e.gatewayUnavailable === true) { writeLine(`gateway unavailable; data dispatch only: promoted=${Array.isArray(e.promoted) ? e.promoted.length : 0} blocked=${Array.isArray(e.blocked) ? e.blocked.length : 0}`); return; } const t = Array.isArray(e.started) ? e.started.length : 0; const n = Array.isArray(e.startFailures) ? e.startFailures : []; writeLine(`dispatch complete: started=${t} failures=${n.length}`); for (const e of n) if (isRecord(e) && typeof e.cardId === "string" && typeof e.error === "string") writeLine(terminalText`${e.cardId.slice(0, 8)}: ${e.error}`); } }); } //#endregion export { registerWorkboardCli };