UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

141 lines (140 loc) • 4.13 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as isAgentPlanProgressToolName } from "./progress-card-input-WVh4etRi.mjs"; //#region src/chat/tool-call-grouping.ts /** Preserve recorded nesting without guessing relationships from names or arrival order. */ function groupToolCalls(e) { const t = e.map((e) => ({ card: e, children: [] })); const n = /* @__PURE__ */ new Map(); for (const e of t) { const { runId: t, callId: r } = e.card; if (t && r) { const i = JSON.stringify([t, r]); n.set(i, n.has(i) ? null : e); } } const r = /* @__PURE__ */ new Map(); for (const e of t) { const { runId: t, callId: i, parentToolCallId: a } = e.card; if (!t || !a || a === i || i && n.get(JSON.stringify([t, i])) !== e) continue; const o = n.get(JSON.stringify([t, a])); if (o) r.set(e, o); } const i = /* @__PURE__ */ new Set(); for (const e of t) { const t = []; let n = e; while (n && !i.has(n)) { i.add(n); t.push(n); n = r.get(n); } const a = n ? t.indexOf(n) : -1; if (a >= 0) for (const e of t.slice(a)) r.delete(e); } const a = []; for (const e of t) { const t = r.get(e); (t ? t.children : a).push(e); } return a; } //#endregion //#region src/agents/agent-activity-presentation.ts /** * A successfully completed wrapper is replaced only by a recorded call beneath it * that stays visible in progress. A wrapper whose recorded calls are all routine * stays the operation instead of leaving none. */ function resolveCompletedActivityWrappers(e) { const t = /* @__PURE__ */ new Set(); const n = []; const r = groupToolCalls(e); while (r.length > 0) { const e = r.pop(); n.push(e); for (const t of e.children) r.push(t); } const i = /* @__PURE__ */ new Set(); for (const e of n.toReversed()) { const { activity: n } = e.card; const r = e.children.some((e) => i.has(e)); if (r && n?.status === "completed") t.add(e.card); if (r || n && !n.hideFromChannelProgress && !n.suppressChannelProgress) i.add(e); } return t; } function projectAgentActivityItem(e, t = {}) { if (e.kind === "analysis") return { ...e, hideFromChannelProgress: true }; const n = normalizeLowercaseStringOrEmpty(e.name); const r = asOptionalObjectRecord(asOptionalObjectRecord(t.result)?.details); if (e.phase === "end" && e.status === "completed" && (n === "exec" || n === "bash" || n === "process") && r?.status === "completed" && r.exitReason !== "manual-cancel" && typeof r.exitCode === "number" && Number.isFinite(r.exitCode) && r.exitCode !== 0) return { ...e, status: "failed" }; return (t.nativeOperation === "wait" || t.nativeOperation === "process.poll" || isAgentPlanProgressToolName(n) || n === "sessions_yield" || n === "process" && asOptionalObjectRecord(t.args)?.action === "poll" || n === "message" && asOptionalObjectRecord(t.args)?.action === "react") && (e.status === "running" || e.status === "completed") ? { ...e, hideFromChannelProgress: true } : e; } function isCompleteAgentPreamble(e) { return !e.progressText?.trim() || e.phase !== "start" && e.phase !== "update"; } function categoryTools(e, t) { return t.map((t) => [t, e]); } const ACTIVITY_CATEGORIES = new Map([ ...categoryTools("subagents", ["sessions_spawn"]), ...categoryTools("commands", [ "exec", "bash", "shell", "run_command", "run_terminal_cmd" ]), ...categoryTools("reads", [ "read", "read_file", "readfile", "notebookread", "notebook_read" ]), ...categoryTools("edits", [ "edit", "apply_patch", "applypatch", "patch", "edit_file", "multiedit", "multi_edit", "notebookedit", "notebook_edit" ]), ...categoryTools("writes", [ "write", "write_file", "create_file" ]), ...categoryTools("searches", [ "grep", "glob", "find", "ls", "list", "codebase_search", "web_search" ]), ...categoryTools("fetches", [ "web_fetch", "webfetch", "fetch" ]) ]); //#endregion export { projectAgentActivityItem as n, resolveCompletedActivityWrappers as r, isCompleteAgentPreamble as t };