UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 3.06 kB
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { w as resolveProjectedAgentRunProgressState } from "./agent-run-registry-D7vkrqFT.mjs"; import { W as projectGatewaySessionRunState } from "./session-row-prepared-read-B4U_T7SO.mjs"; import { n as resolveAgentIdentity } from "./identity-Cd2mxvzm.mjs"; import { i as resolveProjectedControlUiSessionPrTarget } from "./control-ui-session-pr-read-DJu6I6Wb.mjs"; //#region src/gateway/control-ui-public-session-card-facts.ts const PR_STATES = { merged: "Merged", open: "Open", draft: "Draft", closed: "Closed" }; function cardText(e, t) { return e && truncateUtf16Safe(e, t).trim() || void 0; } function checkSummary(e) { if (!e) return; return [ e.passed ? `${e.passed} passed` : "", e.failed ? `${e.failed} failed` : "", e.running ? `${e.running} running` : "", e.skipped ? `${e.skipped} skipped` : "" ].filter(Boolean).join(" · ") || void 0; } /** The caller admits publication; this projects only its recorded and already cached facts. */ function resolvePublicSessionCardFacts(e) { const { cfg: t, record: n, rowContext: r } = e; const { entry: i } = n; const a = e.now ?? Date.now(); const o = projectGatewaySessionRunState({ key: n.key, entry: i, now: a, rowContext: { ...r, subagentRuns: r.subagentRuns.atTime(a) } }).fields; const s = resolveProjectedAgentRunProgressState({ sessionKeys: [n.key], sessionId: i.sessionId, agentId: n.agentId, index: r.projectedAgentRuns }) !== void 0 || o.hasActiveSubagentRun === true || o.status === "running" || o.status === "queued"; const c = s ? "Running" : o.status === "done" ? "Done" : o.status !== void 0 ? "Failed" : void 0; const l = o.startedAt ?? i.sessionStartedAt; const u = o.runtimeMs ?? (l !== void 0 && (o.endedAt !== void 0 || s) ? (o.endedAt ?? a) - l : void 0); const d = cardText(resolveAgentIdentity(t, n.agentId)?.name, 80); const f = i.worktree || i.projectId ? resolveProjectedControlUiSessionPrTarget(t, n) : void 0; const p = f ? e.pullRequests?.readPrepared(f, () => false) : void 0; const m = cardText(i.worktree?.branch, 180); const h = p?.branch?.branch === i.worktree?.branch ? p?.branch : void 0; const g = p?.pullRequests.find((e) => e.branch === i.worktree?.branch); const _ = p?.repository ?? h ?? g; const v = _ ? cardText(`${_.owner}/${_.repo}`, 160) : void 0; const y = h?.additions ?? g?.additions; const b = h?.deletions ?? g?.deletions; const x = h?.changedFiles ?? g?.changedFiles; const S = checkSummary(g?.checks); return { ...d ? { agentName: d } : {}, ...c ? { status: c } : {}, ...u !== void 0 && Number.isFinite(u) && u >= 0 ? { durationMinutes: Math.round(u / 6e4) } : {}, ...v ? { repoSlug: v } : {}, ...m ? { worktree: { branch: m, ...y !== void 0 ? { additions: y } : {}, ...b !== void 0 ? { deletions: b } : {}, ...x !== void 0 ? { files: x } : {}, ...g ? { prState: PR_STATES[g.state] } : {}, ...S ? { checks: S } : {} } } : {} }; } //#endregion export { resolvePublicSessionCardFacts };