UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

74 lines (73 loc) • 4 kB
import { V as timestampMsToIsoString } from "./number-coercion-D6u-4YD8.mjs"; import { p as resolveSubagentDisplayStatus } from "./subagent-run-liveness-D7qiCtn0.mjs"; import { c as isSameSubagentRun, l as isSameSubagentRunOwner } from "./subagent-run-generation-BCjO9e0_.mjs"; import { v as subagentRuns } from "./subagent-registry-memory-lc6LBIFb.mjs"; import { i as createSubagentSessionListReadView } from "./subagent-registry-state-CMZQXOjY.mjs"; import { t as formatDurationCompact } from "./format-duration-iMnO_MN6.mjs"; import { n as commandReply } from "./command-gates-BZ-IYgiD.mjs"; import { n as formatTimeAgo } from "./format-relative-JG-kbkDF.mjs"; import { a as withSubagentSessionEntry } from "./subagent-session-reconciliation-DttjJoa2.mjs"; import { t as sanitizeRunStatusText } from "./run-status-text-DHsRL0re.mjs"; import { t as formatRunLabel } from "./subagents-utils-DutCBnyZ.mjs"; import { n as resolveSubagentEntryForToken } from "./shared-DvY0vqro.mjs"; //#region src/auto-reply/reply/commands-subagents/action-info.ts function formatTimestampWithAge(e) { if (!e || !Number.isFinite(e) || e <= 0) return "n/a"; const t = timestampMsToIsoString(e); if (!t) return "n/a"; return `${t} (${formatTimeAgo(Date.now() - e, { fallback: "n/a" })})`; } async function handleSubagentsInfoAction(e) { const { params: t, readContext: n, restTokens: r } = e; const i = r[0]; if (!i) return commandReply("ℹ️ Usage: /subagents info <id|#>"); const a = resolveSubagentEntryForToken(n.list.view, i); if ("reply" in a) return a.reply; const o = a.entry; const s = createSubagentSessionListReadView({ env: process.env }); const c = /* @__PURE__ */ new Set([o.runId]); const l = subagentRuns.get(o.runId); const assertCurrent = () => { const e = s.runs(c).get(o.runId); if (!isSameSubagentRun(e, o) || e?.controllerSessionKey !== o.controllerSessionKey || e?.controllerStorePath !== o.controllerStorePath || l && !isSameSubagentRunOwner(subagentRuns.get(o.runId), l)) throw new Error("The selected subagent run changed while reading its info"); }; return withSubagentSessionEntry({ childSessionKey: o.childSessionKey, childAgentId: o.childAgentId, cfg: t.cfg, assertCurrent }, (e) => { const t = o.execution.startedAt && Number.isFinite(o.execution.startedAt) ? formatDurationCompact((o.execution.endedAt ?? Date.now()) - o.execution.startedAt) ?? "n/a" : "n/a"; const r = sanitizeRunStatusText(o.execution.outcome?.error, { errorContext: true }); const i = o.execution.outcome ? `${o.execution.outcome.status}${r ? ` (${r})` : ""}` : "n/a"; const a = sanitizeRunStatusText(o.task) || "n/a"; const s = sanitizeRunStatusText(o.completion?.resultText); const c = sanitizeRunStatusText(o.delivery?.lastError ?? o.delivery?.discardedPayloadSummary?.lastError, { errorContext: true }); const l = [ "ℹ️ Subagent info", `Status: ${resolveSubagentDisplayStatus(o, n.list.pendingDescendants.get(o.childSessionKey) ?? 0)}`, `Label: ${formatRunLabel(o)}`, `Task: ${a}`, `Run: ${o.runId}`, `Session: ${o.childSessionKey}`, `SessionId: ${e?.sessionId ?? "n/a"}`, `Runtime: ${t}`, `Created: ${formatTimestampWithAge(o.createdAt)}`, `Started: ${formatTimestampWithAge(o.execution.startedAt)}`, `Ended: ${formatTimestampWithAge(o.execution.endedAt)}`, `Cleanup: ${o.cleanup}`, o.archiveAtMs ? `Archive: ${formatTimestampWithAge(o.archiveAtMs)}` : void 0, o.cleanupHandled ? "Cleanup handled: yes" : void 0, `Outcome: ${i}`, s ? `Progress: ${s}` : void 0, c ? `Task summary: ${c}` : void 0, r ? `Task error: ${r}` : void 0, o.delivery ? `Delivery: ${o.delivery.status}` : void 0, o.delivery?.discardReason ? `Delivery disposition: ${o.delivery.discardReason}` : void 0, o.delivery?.discardedAt ? `Delivery retired: ${formatTimestampWithAge(o.delivery.discardedAt)}` : void 0 ].filter(Boolean); return commandReply(l.join("\n")); }); } //#endregion export { handleSubagentsInfoAction };