ltcai 3.2.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +87 -67
  2. package/docs/CHANGELOG.md +36 -0
  3. package/docs/architecture.md +2 -1
  4. package/docs/assets/v3.4.0/agent-run.png +0 -0
  5. package/docs/assets/v3.4.0/agents.png +0 -0
  6. package/docs/assets/v3.4.0/before/chat-before.png +0 -0
  7. package/docs/assets/v3.4.0/before/files-before.png +0 -0
  8. package/docs/assets/v3.4.0/chat.png +0 -0
  9. package/docs/assets/v3.4.0/connect-folder.png +0 -0
  10. package/docs/assets/v3.4.0/files.png +0 -0
  11. package/docs/assets/v3.4.0/home.png +0 -0
  12. package/docs/assets/v3.4.0/hooks-dispatch.png +0 -0
  13. package/docs/assets/v3.4.0/knowledge-graph.png +0 -0
  14. package/docs/assets/v3.4.0/local-agent.png +0 -0
  15. package/docs/assets/v3.4.0/memory.png +0 -0
  16. package/docs/assets/v3.4.0/settings.png +0 -0
  17. package/docs/assets/v3.4.0/vision-input.png +0 -0
  18. package/docs/assets/v3.4.0/workflows.png +0 -0
  19. package/knowledge_graph.py +45 -0
  20. package/knowledge_graph_api.py +10 -0
  21. package/latticeai/__init__.py +1 -1
  22. package/latticeai/api/agents.py +3 -0
  23. package/latticeai/api/hooks.py +39 -0
  24. package/latticeai/api/local_files.py +41 -0
  25. package/latticeai/api/models.py +36 -1
  26. package/latticeai/api/tools.py +16 -1
  27. package/latticeai/api/workflow_designer.py +2 -1
  28. package/latticeai/core/hooks.py +398 -2
  29. package/latticeai/core/marketplace.py +1 -1
  30. package/latticeai/core/multi_agent.py +1 -1
  31. package/latticeai/core/workflow_engine.py +21 -1
  32. package/latticeai/core/workspace_os.py +1 -1
  33. package/latticeai/server_app.py +40 -0
  34. package/latticeai/services/agent_runtime.py +46 -1
  35. package/latticeai/services/upload_service.py +17 -0
  36. package/package.json +1 -1
  37. package/scripts/build_v3_assets.mjs +7 -1
  38. package/scripts/capture/capture_v340.js +88 -0
  39. package/static/css/{tokens.5a595671.css → tokens.3ba22e37.css} +109 -109
  40. package/static/css/tokens.css +109 -109
  41. package/static/v3/asset-manifest.json +25 -25
  42. package/static/v3/css/{lattice.components.011e988b.css → lattice.components.9b49d614.css} +57 -32
  43. package/static/v3/css/lattice.components.css +57 -32
  44. package/static/v3/css/{lattice.shell.4920f42d.css → lattice.shell.6ceea7c8.css} +75 -31
  45. package/static/v3/css/lattice.shell.css +75 -31
  46. package/static/v3/css/lattice.tokens.css +13 -13
  47. package/static/v3/css/{lattice.tokens.c597ff81.css → lattice.tokens.e7018963.css} +13 -13
  48. package/static/v3/css/{lattice.views.3ee19d4e.css → lattice.views.22f69117.css} +98 -15
  49. package/static/v3/css/lattice.views.css +98 -15
  50. package/static/v3/js/{app.a5adc0f3.js → app.c4acfdd8.js} +1 -1
  51. package/static/v3/js/core/{api.603b978f.js → api.12b568ad.js} +126 -4
  52. package/static/v3/js/core/api.js +126 -4
  53. package/static/v3/js/core/{components.4c83e0a9.js → components.35f02e4c.js} +8 -0
  54. package/static/v3/js/core/components.js +8 -0
  55. package/static/v3/js/core/{routes.07ad6696.js → routes.d214b399.js} +16 -12
  56. package/static/v3/js/core/routes.js +16 -12
  57. package/static/v3/js/core/{shell.ea0b9ae5.js → shell.80a6ad82.js} +37 -9
  58. package/static/v3/js/core/shell.js +34 -6
  59. package/static/v3/js/views/agents.014d0b74.js +541 -0
  60. package/static/v3/js/views/agents.js +305 -57
  61. package/static/v3/js/views/{chat.718144ce.js → chat.e6dd7dd0.js} +162 -10
  62. package/static/v3/js/views/chat.js +162 -10
  63. package/static/v3/js/views/files.adad14c1.js +365 -0
  64. package/static/v3/js/views/files.js +269 -90
  65. package/static/v3/js/views/home.24f8b8ae.js +200 -0
  66. package/static/v3/js/views/home.js +96 -15
  67. package/static/v3/js/views/hooks.13845954.js +215 -0
  68. package/static/v3/js/views/hooks.js +117 -1
  69. package/static/v3/js/views/{memory.d2ed7a7c.js → memory.4ebdf474.js} +5 -4
  70. package/static/v3/js/views/memory.js +5 -4
  71. package/static/v3/js/views/{my-computer.1b2ff621.js → my-computer.c3ef5283.js} +224 -1
  72. package/static/v3/js/views/my-computer.js +224 -1
  73. package/static/v3/js/views/{settings.4f777210.js → settings.8631fa5e.js} +70 -2
  74. package/static/v3/js/views/settings.js +70 -2
  75. package/static/v3/js/views/agents.c373d48c.js +0 -293
  76. package/static/v3/js/views/files.4935197e.js +0 -186
  77. package/static/v3/js/views/home.cdde3b32.js +0 -119
  78. package/static/v3/js/views/hooks.f3edebca.js +0 -99
@@ -49,14 +49,17 @@ function buildRail() {
49
49
  return h("aside.lt3-rail", { id: "lt3-rail", "aria-label": "Primary" },
50
50
  h("div.lt3-rail__brand",
51
51
  h("div.lt3-rail__logo", { html: latticeMark() }),
52
- h("div.lt3-rail__word", h("b", "Lattice AI"), h("small", "Local-First Workspace")),
52
+ h("div.lt3-rail__word", h("b", "Lattice AI"), h("small", "Private runtime")),
53
53
  h("button.lt3-iconbtn.lt3-iconbtn--sm.lt3-rail__close", { "aria-label": "Close menu", on: { click: closeDrawer } }, icon("x")),
54
54
  ),
55
55
  h("div.lt3-rail__scope", { id: "lt3-scope" }),
56
56
  h("nav.lt3-rail__nav", { id: "lt3-nav", "aria-label": "Sections" }),
57
57
  h("div.lt3-rail__foot",
58
- h("button.lt3-rail__user", { id: "lt3-user", "aria-label": "Account", on: { click: () => router.navigate("settings") } }),
59
- h("button.lt3-iconbtn", { id: "lt3-theme", "aria-label": "Toggle theme", title: "Toggle theme", on: { click: () => store.toggleTheme() } }, icon("moon")),
58
+ h("div.lt3-rail__status", { id: "lt3-rail-status" }),
59
+ h("div.lt3-rail__foot-row",
60
+ h("button.lt3-rail__user", { id: "lt3-user", "aria-label": "Account", on: { click: () => router.navigate("settings") } }),
61
+ h("button.lt3-iconbtn", { id: "lt3-theme", "aria-label": "Toggle theme", title: "Toggle theme", on: { click: () => store.toggleTheme() } }, icon("moon")),
62
+ ),
60
63
  ),
61
64
  );
62
65
  }
@@ -82,10 +85,14 @@ function navItem(route) {
82
85
  return h("a.lt3-navitem", {
83
86
  href: "#/" + route.key,
84
87
  dataset: { key: route.key },
88
+ title: route.title || route.label,
85
89
  on: { click: () => closeDrawer() },
86
90
  },
87
91
  icon(route.icon),
88
- h("span.lt3-navitem__label", route.label),
92
+ h("span.lt3-navitem__copy",
93
+ h("span.lt3-navitem__label", route.label),
94
+ route.desc ? h("span.lt3-navitem__meta", route.desc) : null,
95
+ ),
89
96
  route.key === "hybrid-search" ? h("span.lt3-navitem__dot", { style: { background: "var(--lt3-pillar-hybrid)" } }) : null,
90
97
  );
91
98
  }
@@ -161,6 +168,23 @@ function renderCrumbs() {
161
168
 
162
169
  function renderIndexChip() {
163
170
  els.idxchip.replaceChildren(c.indexChip(store.get().indexStatus));
171
+ renderRailStatus();
172
+ }
173
+
174
+ function renderRailStatus() {
175
+ if (!els.railStatus) return;
176
+ const status = store.get().indexStatus;
177
+ const pipes = status?.pipelines || {};
178
+ const keys = ["knowledge_graph", "vector_index", "hybrid"];
179
+ const ready = keys.filter((key) => String(pipes[key]?.state || "").toLowerCase() === "ready").length;
180
+ const unavailable = !Object.keys(pipes).length;
181
+ els.railStatus.replaceChildren(
182
+ h("div.lt3-rail__status-top",
183
+ h("span.lt3-rail__status-dot", { dataset: { state: unavailable ? "pending" : ready === keys.length ? "ready" : "partial" } }),
184
+ h("span", unavailable ? "Local index pending" : `${ready}/${keys.length} retrieval signals ready`),
185
+ ),
186
+ h("div.lt3-rail__status-sub", unavailable ? "Start backend to sync live state" : "Graph · vector · hybrid"),
187
+ );
164
188
  }
165
189
 
166
190
  /* ── View rendering ─────────────────────────────────────────────────────── */
@@ -240,8 +264,10 @@ function closeDrawer() { delete els.root.dataset.drawer; }
240
264
 
241
265
  /* ── Command palette ────────────────────────────────────────────────────── */
242
266
  function paletteItems() {
243
- const nav = ROUTES.map((r) => ({
244
- group: "Go to", label: r.label, icon: r.icon, hint: r.group,
267
+ const mode = store.get().mode;
268
+ const currentRoutes = visibleRoutes(mode);
269
+ const nav = currentRoutes.map((r) => ({
270
+ group: "Go to", label: r.title || r.label, icon: r.icon, hint: r.label === r.title ? r.group : r.label,
245
271
  run: () => router.navigate(r.key),
246
272
  }));
247
273
  const actions = [
@@ -340,6 +366,7 @@ function cacheEls(root) {
340
366
  theme: $("#lt3-theme", root),
341
367
  crumbs: $("#lt3-crumbs", root),
342
368
  idxchip: $("#lt3-idxchip", root),
369
+ railStatus: $("#lt3-rail-status", root),
343
370
  outlet: $("#lt3-outlet", root),
344
371
  view: $("#lt3-view", root),
345
372
  };
@@ -349,6 +376,7 @@ function cacheEls(root) {
349
376
  renderMode();
350
377
  updateThemeIcon();
351
378
  renderIndexChip();
379
+ renderRailStatus();
352
380
  }
353
381
 
354
382
  function latticeMark() {
@@ -0,0 +1,541 @@
1
+ /* ============================================================================
2
+ * View: Agents — the multi-agent runtime (roles, real runs, health).
3
+ * Reads the AgentRuntime boundary (/agents/api/runtime/status): the canonical
4
+ * role roster enriched with real run counts, the live recent-runs ledger, and
5
+ * runtime health. Reports unavailable state when the runtime is unreachable.
6
+ * Also drives runs directly: a goal + role selection → POST /agents/api/run →
7
+ * a real timeline (logs), final status/output, queue/status, and stop.
8
+ * ========================================================================== */
9
+
10
+ import { timeAgo } from "../core/dom.a2773eb0.js";
11
+
12
+ const DEFAULT_ROLES = ["planner", "executor", "reviewer"];
13
+
14
+ export async function render(ctx) {
15
+ const { h, icon, c } = ctx;
16
+
17
+ const runHost = h("div", c.loading({ lines: 3, block: true }));
18
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
19
+ const registryHost = h("div", c.loading({ lines: 3, block: true }));
20
+ const rosterHost = h("div", c.loading({ lines: 2, block: true }));
21
+ const runsHost = h("div", c.loading({ lines: 4 }));
22
+ const registrySrc = h("span", c.sourceBadge("pending"));
23
+ const rosterSrc = h("span", c.sourceBadge("pending"));
24
+ const runsSrc = h("span", c.sourceBadge("pending"));
25
+ const runSrc = h("span", c.sourceBadge("pending"));
26
+ const healthSlot = h("span", c.sourceBadge("pending"));
27
+
28
+ const root = h("div.lt3-stack-6",
29
+ c.viewHeader({
30
+ eyebrow: "Compute",
31
+ title: "Agents",
32
+ sub: "The multi-agent runtime: who plans, who builds, who reviews — and how work hands off between them. Every run stays local to this workspace.",
33
+ actions: [healthSlot],
34
+ }),
35
+ c.panel({
36
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
37
+ h("div",
38
+ h("div.lt3-eyebrow", "Run"),
39
+ h("h3.lt3-panel__title", "Run agents"),
40
+ h("p.lt3-panel__sub", "Give the pipeline a goal. Planner → executor → reviewer run synchronously and locally — no model required."),
41
+ ),
42
+ runSrc,
43
+ ),
44
+ children: runHost,
45
+ }),
46
+ statHost,
47
+ h("section",
48
+ c.sectionHead("Agent Registry", registrySrc),
49
+ registryHost,
50
+ ),
51
+ h("section",
52
+ c.sectionHead("Agent roster", rosterSrc),
53
+ rosterHost,
54
+ ),
55
+ c.panel({
56
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
57
+ h("div",
58
+ h("div.lt3-eyebrow", "Activity"),
59
+ h("h3.lt3-panel__title", "Recent runs"),
60
+ ),
61
+ runsSrc,
62
+ ),
63
+ children: runsHost,
64
+ }),
65
+ );
66
+
67
+ // Shared run-console handles refresh + recent-runs + queue so a run can
68
+ // re-hydrate counts and click-through to a run's logs.
69
+ const runConsole = makeRunConsole(ctx, { runHost, runSrc, statHost, runsHost, runsSrc, healthSlot, rosterHost, rosterSrc });
70
+ runConsole.hydrate();
71
+ loadRegistry(ctx, { registryHost, registrySrc });
72
+ return root;
73
+ }
74
+
75
+ /* ── Run console ─────────────────────────────────────────────────────────────
76
+ * Owns the Run panel (goal + role chips + Run button + logs), the stat/queue
77
+ * row, the recent-runs ledger, and the cross-links between them. A single
78
+ * refresh() re-reads the runtime so counts and recent runs stay honest.
79
+ * ========================================================================== */
80
+ function makeRunConsole(ctx, hosts) {
81
+ const { h, icon, c } = ctx;
82
+ const { runHost, runSrc, statHost, runsHost, runsSrc, healthSlot, rosterHost, rosterSrc } = hosts;
83
+
84
+ // Run-panel controls (built once; logs region replaced per run).
85
+ const goalInput = h("textarea.lt3-textarea", {
86
+ placeholder: "What should the agents accomplish?",
87
+ "aria-label": "Agent goal",
88
+ rows: 3,
89
+ });
90
+ const logsHost = h("div");
91
+ const runBtn = h("button.lt3-btn.lt3-btn--primary", { on: { click: () => trigger() } }, c.icon("player-play"), "Run agents");
92
+
93
+ // Role chips — defaults seeded; replaced once runtime defaults arrive.
94
+ let roleState = DEFAULT_ROLES.map((r) => ({ role: r, on: true }));
95
+ const rolesHost = h("div.lt3-cluster");
96
+ renderRoleChips();
97
+
98
+ function renderRoleChips() {
99
+ rolesHost.replaceChildren(
100
+ ...roleState.map((entry, i) => h("button.lt3-chip", {
101
+ type: "button",
102
+ dataset: { active: String(entry.on) },
103
+ "aria-pressed": String(entry.on),
104
+ on: { click: () => { roleState[i].on = !roleState[i].on; renderRoleChips(); } },
105
+ }, c.icon(entry.on ? "check" : "circle"), entry.role)),
106
+ );
107
+ }
108
+
109
+ function selectedRoles() {
110
+ return roleState.filter((e) => e.on).map((e) => e.role);
111
+ }
112
+
113
+ runHost.replaceChildren(
114
+ h("div.lt3-stack-4",
115
+ h("div.lt3-field",
116
+ h("label", "Goal"),
117
+ goalInput,
118
+ ),
119
+ h("div.lt3-field",
120
+ h("label", "Roles"),
121
+ rolesHost,
122
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Toggle which roles take part. Leave all on for the full pipeline."),
123
+ ),
124
+ h("div.lt3-row-2", runBtn),
125
+ logsHost,
126
+ ),
127
+ );
128
+
129
+ /* ── Trigger a run ─────────────────────────────────────────────────────── */
130
+ async function trigger() {
131
+ const goal = goalInput.value.trim();
132
+ if (!goal) { ctx.toast("Enter a goal for the agents", "info"); return; }
133
+ const roles = selectedRoles();
134
+ if (!roles.length) { ctx.toast("Select at least one role", "info"); return; }
135
+
136
+ runBtn.disabled = true;
137
+ runBtn.replaceChildren(c.icon("loader-2"), "Running…");
138
+ runSrc.replaceChildren(c.sourceBadge("pending"));
139
+ logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } }, c.loading({ lines: 4 })));
140
+
141
+ const res = await ctx.api.runAgent(goal, roles);
142
+ runBtn.disabled = false;
143
+ runBtn.replaceChildren(c.icon("player-play"), "Run agents");
144
+
145
+ const data = (res && res.data) || {};
146
+ if (!res || !res.ok) {
147
+ const msg = data.detail || data.error || (res && res.error) || "Agent run unavailable";
148
+ runSrc.replaceChildren(c.sourceBadge("unavailable"));
149
+ logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } },
150
+ c.banner(String(msg), "err"),
151
+ ));
152
+ ctx.toast("Run failed", "err");
153
+ return;
154
+ }
155
+
156
+ runSrc.replaceChildren(c.sourceBadge("live"));
157
+ const run = data.run || {};
158
+ const result = data.result || {};
159
+ logsHost.replaceChildren(renderRunResult(run, result));
160
+ ctx.toast(`Run ${mapStatus(result.status) === "failed" ? "completed with failure" : "complete"}`, mapStatus(result.status) === "failed" ? "warn" : "ok");
161
+
162
+ // Refresh runtime so queue/total/recent-runs reflect this run.
163
+ hydrate();
164
+ }
165
+
166
+ /* ── Render a run's result as logs + summary ───────────────────────────── */
167
+ function renderRunResult(run, result) {
168
+ const runId = run.id || run.run_id || result.run_id || result.id;
169
+ const status = mapStatus(result.status || run.status);
170
+ const timeline = Array.isArray(result.timeline) ? result.timeline : [];
171
+ const output = result.output != null ? String(result.output) : "";
172
+ const retries = Number(result.retries) || 0;
173
+ const active = isActiveStatus(result.status || run.status);
174
+
175
+ return h("div.lt3-stack-4", { style: { "margin-top": "var(--lt3-space-3)" } },
176
+ h("hr.lt3-divider"),
177
+ h("div.lt3-row", { style: { "justify-content": "space-between", "flex-wrap": "wrap", gap: "var(--lt3-space-2)" } },
178
+ h("div.lt3-row-2",
179
+ h("span.lt3-eyebrow", "Result"),
180
+ c.statePill(status),
181
+ retries ? c.pill(`${retries} ${retries === 1 ? "retry" : "retries"}`, "warn") : null,
182
+ runId ? h("span.lt3-faint", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-2xs)" } }, shortId(runId)) : null,
183
+ ),
184
+ runId
185
+ ? h("button.lt3-btn.lt3-btn--danger.lt3-btn--sm", {
186
+ // The synchronous runtime finishes inline; Stop is offered but
187
+ // reports honestly (stopped:false + reason) when there's nothing
188
+ // left to interrupt.
189
+ title: active ? "Stop this run" : "This run has already finished",
190
+ on: { click: (e) => stopRun(runId, e.currentTarget) },
191
+ }, c.icon("player-stop"), "Stop")
192
+ : null,
193
+ ),
194
+ timeline.length
195
+ ? renderTimeline(timeline)
196
+ : h("p.lt3-faint", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, "No timeline entries were recorded for this run."),
197
+ output
198
+ ? h("div.lt3-stack-2",
199
+ h("div.lt3-eyebrow", icon("file-text"), "Output"),
200
+ h("pre.lt3-code", output),
201
+ )
202
+ : null,
203
+ );
204
+ }
205
+
206
+ /* ── Timeline → readable log list ──────────────────────────────────────── */
207
+ function renderTimeline(timeline) {
208
+ return h("div.lt3-stack-2",
209
+ h("div.lt3-eyebrow", icon("list-details"), "Logs"),
210
+ h("div.lt3-timeline",
211
+ timeline.map((entry) => {
212
+ const label = entry.event || entry.message || entry.step || "event";
213
+ const role = entry.role || entry.agent_id;
214
+ const status = entry.status;
215
+ const ts = entry.timestamp || entry.created_at || entry.time;
216
+ return h("div.lt3-timeline__item",
217
+ ts ? h("div.lt3-timeline__time", fmtTime(ts)) : null,
218
+ h("div.lt3-timeline__body",
219
+ h("div.lt3-row-2", { style: { "flex-wrap": "wrap" } },
220
+ role ? h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, shortId(role)) : null,
221
+ h("span", String(label).replace(/_/g, " ")),
222
+ status ? c.statePill(mapStatus(status)) : null,
223
+ ),
224
+ entry.detail || entry.note
225
+ ? h("div.lt3-muted", { style: { "font-size": "var(--lt3-text-xs)", "margin-top": "var(--lt3-space-1)" } }, String(entry.detail || entry.note))
226
+ : null,
227
+ ),
228
+ );
229
+ }),
230
+ ),
231
+ );
232
+ }
233
+
234
+ /* ── Stop an (active) run — honest about synchronous no-op ─────────────── */
235
+ async function stopRun(runId, btn) {
236
+ if (btn) { btn.disabled = true; btn.replaceChildren(c.icon("loader-2"), "Stopping…"); }
237
+ const res = await ctx.api.stopAgentRun(runId);
238
+ if (btn) { btn.disabled = false; btn.replaceChildren(c.icon("player-stop"), "Stop"); }
239
+ const data = (res && res.data) || {};
240
+ if (!res || !res.ok) {
241
+ ctx.toast(String(data.detail || data.error || "Stop unavailable"), "err");
242
+ return;
243
+ }
244
+ if (data.stopped === false || data.stopped == null) {
245
+ // The synchronous runtime cannot interrupt an already-finished run.
246
+ ctx.toast(String(data.reason || "Run already finished — nothing to stop"), "warn");
247
+ } else {
248
+ ctx.toast("Run stopped", "ok");
249
+ }
250
+ hydrate();
251
+ }
252
+
253
+ /* ── Load a recorded run's detail as logs ──────────────────────────────── */
254
+ async function openRun(runId) {
255
+ if (!runId) return;
256
+ logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } }, c.loading({ lines: 3 })));
257
+ const res = await ctx.api.agentRunDetail(runId);
258
+ const data = (res && res.data) || {};
259
+ if (!res || !res.ok) {
260
+ runSrc.replaceChildren(c.sourceBadge("unavailable"));
261
+ logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } },
262
+ c.banner(String(data.detail || data.error || "Run detail unavailable"), "err"),
263
+ ));
264
+ return;
265
+ }
266
+ runSrc.replaceChildren(c.sourceBadge("live"));
267
+ const run = data.run || data || {};
268
+ const result = data.result || data || {};
269
+ logsHost.replaceChildren(renderRunResult(run, result));
270
+ }
271
+
272
+ /* ── Refresh runtime → stats, queue, recent runs, roster, health ───────── */
273
+ async function hydrate() {
274
+ const res = await ctx.api.agentRuntime();
275
+ const data = res.data || {};
276
+ const agents = normalize(data.agents);
277
+ const runtime = data.runtime || {};
278
+ const health = data.health || { status: "unknown" };
279
+ const runs = Array.isArray(data.runs) ? data.runs : [];
280
+ const byId = new Map(agents.map((a) => [a.id, a.name]));
281
+
282
+ // Seed role chips from the runtime's real default pipeline / roles (once).
283
+ if (!roleState.__seeded) {
284
+ const fromRuntime = Array.isArray(runtime.default_pipeline) && runtime.default_pipeline.length
285
+ ? runtime.default_pipeline
286
+ : (Array.isArray(data.roles) ? data.roles.map((r) => r.role).filter(Boolean) : []);
287
+ if (fromRuntime.length) {
288
+ roleState = fromRuntime.map((r) => ({ role: String(r), on: true }));
289
+ roleState.__seeded = true;
290
+ renderRoleChips();
291
+ }
292
+ }
293
+
294
+ rosterSrc.replaceChildren(c.sourceBadge(res.source));
295
+ runsSrc.replaceChildren(c.sourceBadge(res.source));
296
+ healthSlot.replaceChildren(
297
+ c.statePill(health.status === "ok" ? "ready" : health.status === "degraded" ? "warn" : "idle"),
298
+ );
299
+
300
+ // ── Stat row + queue/status (real runtime counts) ───────────────────
301
+ const available = agents.filter((a) => isAvailable(a.state)).length;
302
+ const totalRuns = Number(runtime.total_runs) || runs.length;
303
+ const activeRuns = Number(runtime.active_runs) || 0;
304
+ statHost.replaceChildren(
305
+ c.stat({ label: "Agents", value: c.fmtNum(agents.length), icon: "robot" }),
306
+ c.stat({ label: "Available", value: c.fmtNum(available), icon: "circle-check" }),
307
+ c.stat({ label: "Total runs", value: c.fmtNum(totalRuns), icon: "player-play" }),
308
+ c.stat({
309
+ label: "Queue", value: c.fmtNum(activeRuns), icon: "clock-play",
310
+ delta: activeRuns ? "active" : "idle", deltaDir: activeRuns ? "up" : undefined,
311
+ }),
312
+ );
313
+
314
+ // ── Roster grid ─────────────────────────────────────────────────────
315
+ if (!agents.length) {
316
+ rosterHost.replaceChildren(c.emptyState({
317
+ icon: "robot-off",
318
+ title: "Runtime unavailable",
319
+ body: "The agent runtime did not respond. Start the local server to see the roster.",
320
+ }));
321
+ } else {
322
+ rosterHost.replaceChildren(
323
+ h("div.lt3-grid-auto", agents.map((a) => agentCard(ctx, a, byId))),
324
+ );
325
+ }
326
+
327
+ // ── Recent runs ledger (REAL runs; click → load logs) ───────────────
328
+ if (!runs.length) {
329
+ runsHost.replaceChildren(c.emptyState({ icon: "history-off", title: "No runs yet", body: "Trigger a run above — recorded runs appear here." }));
330
+ } else {
331
+ runsHost.replaceChildren(
332
+ c.table(
333
+ [
334
+ { key: "agent", label: "Agent", render: (r) => h("div.lt3-row-2",
335
+ h("span.lt3-avatar", { style: { width: "26px", height: "26px" } }, icon("robot")),
336
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, r.agent),
337
+ ) },
338
+ { key: "status", label: "Status", width: "1%", render: (r) => c.statePill(r.status) },
339
+ { key: "time", label: "Started", width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-2xs)" } }, r.time) },
340
+ { key: "note", label: "Note", render: (r) => h("span.lt3-muted", r.note) },
341
+ { key: "open", label: "", width: "1%", render: (r) => r.id
342
+ ? h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => openRun(r.id) } }, icon("list-search"), "Logs")
343
+ : null },
344
+ ],
345
+ runs.map((r) => ({
346
+ id: r.id || r.run_id,
347
+ agent: byId.get(r.agent_id) || shortId(r.agent_id),
348
+ status: mapStatus(r.status),
349
+ time: timeAgo(r.created_at || r.completed_at) || fmtTime(r.created_at || r.completed_at),
350
+ note: runNote(r),
351
+ })),
352
+ { empty: c.emptyState({ icon: "history-off", title: "No runs yet", body: "Agent runs recorded by the runtime will appear here." }) },
353
+ ),
354
+ );
355
+ }
356
+ }
357
+
358
+ return { hydrate, openRun };
359
+ }
360
+
361
+ async function loadRegistry(ctx, hosts) {
362
+ const { h, c } = ctx;
363
+ const { registryHost, registrySrc } = hosts;
364
+ const [registryRes, capsRes] = await Promise.all([ctx.api.agentRegistry(), ctx.api.agentCapabilities()]);
365
+ const agents = normalizeRegistry(registryRes.data);
366
+ const caps = (capsRes.data && capsRes.data.capabilities) || {};
367
+ registrySrc.replaceChildren(c.sourceBadge(registryRes.source === "live" || capsRes.source === "live" ? "live" : "unavailable"));
368
+
369
+ const nameInput = h("input.lt3-input", { type: "text", placeholder: "Custom agent name", "aria-label": "Custom agent name" });
370
+ const capsInput = h("input.lt3-input", { type: "text", placeholder: "capability-a, capability-b", "aria-label": "Custom agent capabilities" });
371
+ const registerBtn = h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: register } }, c.icon("plus"), "Register");
372
+
373
+ const capList = Object.keys(caps).sort();
374
+ const body = h("div.lt3-stack-4",
375
+ h("div.lt3-grid-2",
376
+ h("div.lt3-field", h("label", "Name"), nameInput),
377
+ h("div.lt3-field", h("label", "Capabilities"), capsInput),
378
+ ),
379
+ h("div.lt3-row-2", registerBtn,
380
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Custom agents persist in the local registry.")),
381
+ capList.length
382
+ ? h("div.lt3-cluster", capList.slice(0, 18).map((cap) => h("span.lt3-chip", c.icon("sparkles"), `${cap} (${caps[cap].length})`)))
383
+ : h("p.lt3-faint", { style: { margin: 0 } }, "Capabilities appear here when the registry is live."),
384
+ agents.length
385
+ ? h("div.lt3-grid-auto", agents.map((agent) => registryCard(ctx, agent)))
386
+ : c.emptyState({ icon: "robot-off", title: "Agent registry unavailable", body: "Start the local server to register and configure agents." }),
387
+ );
388
+ registryHost.replaceChildren(c.panel({ title: "Registry controls", sub: "Register, discover, and configure built-in or custom agents.", children: body }));
389
+
390
+ async function register() {
391
+ const name = nameInput.value.trim();
392
+ if (!name) { ctx.toast("Enter an agent name", "info"); return; }
393
+ const capabilities = capsInput.value.split(",").map((s) => s.trim()).filter(Boolean);
394
+ registerBtn.disabled = true;
395
+ const res = await ctx.api.registerAgent({ name, type: "custom", capabilities });
396
+ registerBtn.disabled = false;
397
+ if (res && res.ok) {
398
+ ctx.toast(`Registered ${name}`, "ok");
399
+ loadRegistry(ctx, hosts);
400
+ } else {
401
+ ctx.toast("Register unavailable", "err");
402
+ }
403
+ }
404
+ }
405
+
406
+ function registryCard(ctx, agent) {
407
+ const { h, c } = ctx;
408
+ return c.card(h("div.lt3-stack-3",
409
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
410
+ h("div",
411
+ h("b", agent.name),
412
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, agent.id),
413
+ ),
414
+ c.pill(agent.source === "builtin" ? "built-in" : "custom", agent.source === "builtin" ? "info" : "warn"),
415
+ ),
416
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", margin: 0 } }, agent.description || "No description."),
417
+ h("div.lt3-cluster", [c.statePill(agent.enabled ? "ready" : "idle"), c.pill(agent.type), c.pill(`v${agent.version || "1.0.0"}`)]),
418
+ agent.capabilities.length ? h("div.lt3-cluster", agent.capabilities.slice(0, 8).map((cap) => h("span.lt3-chip", cap))) : null,
419
+ h("div.lt3-row-2",
420
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => toggleAgent(ctx, agent) } }, c.icon(agent.enabled ? "toggle-right" : "toggle-left"), agent.enabled ? "Disable" : "Enable"),
421
+ agent.removable ? h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => removeAgent(ctx, agent) } }, c.icon("trash"), "Remove") : null,
422
+ ),
423
+ ), { interactive: false });
424
+ }
425
+
426
+ async function toggleAgent(ctx, agent) {
427
+ const res = await ctx.api.updateAgent(agent.id, { config: agent.config || {}, enabled: !agent.enabled });
428
+ ctx.toast(res && res.ok ? `${agent.name}: ${agent.enabled ? "disabled" : "enabled"}` : "Agent update unavailable", res && res.ok ? "ok" : "err");
429
+ if (res && res.ok) ctx.navigate("agents");
430
+ }
431
+
432
+ async function removeAgent(ctx, agent) {
433
+ const res = await ctx.api.removeAgent(agent.id);
434
+ ctx.toast(res && res.ok ? `Removed ${agent.name}` : "Agent remove unavailable", res && res.ok ? "ok" : "err");
435
+ if (res && res.ok) ctx.navigate("agents");
436
+ }
437
+
438
+ /* ── Agent card ──────────────────────────────────────────────────────────── */
439
+ function agentCard(ctx, agent, byId) {
440
+ const { h, icon, c } = ctx;
441
+ return c.card(
442
+ h("div.lt3-stack-3",
443
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
444
+ h("div.lt3-row-2",
445
+ h("span.lt3-avatar", { style: { width: "40px", height: "40px", "border-radius": "var(--lt3-radius-md)" } }, icon("robot")),
446
+ h("div",
447
+ h("div", { style: { "font-weight": "var(--lt3-weight-semi)", "font-size": "var(--lt3-text-md)" } }, agent.name),
448
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, agent.id),
449
+ ),
450
+ ),
451
+ c.statePill(agent.state),
452
+ ),
453
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", margin: "0" } }, agent.role),
454
+ h("div.lt3-row-2", { style: { "font-size": "var(--lt3-text-xs)", color: "var(--muted)" } },
455
+ icon("player-play"),
456
+ h("b", { style: { color: "var(--text)" } }, c.fmtNum(agent.runs)),
457
+ "runs",
458
+ ),
459
+ agent.handoffs.length
460
+ ? h("div.lt3-stack-2",
461
+ h("div.lt3-eyebrow", icon("arrows-exchange"), "Hands off to"),
462
+ h("div.lt3-cluster", agent.handoffs.map((id) => {
463
+ const name = byId.get(id) || shortId(id);
464
+ return h("span.lt3-chip", icon("arrow-right"), name);
465
+ })),
466
+ )
467
+ : h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Terminal role — no handoffs"),
468
+ ),
469
+ { interactive: false },
470
+ );
471
+ }
472
+
473
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
474
+ function normalize(data) {
475
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.agents) ? data.agents : []);
476
+ return list.map((a, i) => ({
477
+ id: a.id || `agent:${i}`,
478
+ name: a.name || a.id || `Agent ${i + 1}`,
479
+ role: a.role || a.description || "No role description.",
480
+ state: a.state || a.status || "idle",
481
+ runs: a.runs ?? a.run_count ?? a.runs_count ?? 0,
482
+ handoffs: Array.isArray(a.handoffs) ? a.handoffs
483
+ : Array.isArray(a.relationships) ? a.relationships : [],
484
+ }));
485
+ }
486
+
487
+ function normalizeRegistry(data) {
488
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.agents) ? data.agents : []);
489
+ return list.map((agent, i) => ({
490
+ id: agent.id || `agent:${i}`,
491
+ name: agent.name || agent.id || `Agent ${i + 1}`,
492
+ type: agent.type || "custom",
493
+ version: agent.version || "1.0.0",
494
+ description: agent.description || "",
495
+ capabilities: Array.isArray(agent.capabilities) ? agent.capabilities : [],
496
+ source: agent.source || "user",
497
+ enabled: agent.enabled !== false,
498
+ removable: !!agent.removable,
499
+ config: agent.config || {},
500
+ }));
501
+ }
502
+
503
+ const AVAILABLE_STATES = new Set(["available", "ready", "active", "ok", "idle"]);
504
+ function isAvailable(state) {
505
+ return AVAILABLE_STATES.has(String(state).toLowerCase());
506
+ }
507
+
508
+ // Map orchestrator run statuses onto the shared state-pill vocabulary.
509
+ function mapStatus(status) {
510
+ const s = String(status || "").toLowerCase();
511
+ if (s === "ok" || s === "retried_ok") return "ready";
512
+ if (s === "failed" || s === "rejected") return "failed";
513
+ if (s === "running" || s === "in_progress") return "active";
514
+ return s || "idle";
515
+ }
516
+
517
+ // An active run is one that could (in principle) still be stopped.
518
+ const ACTIVE_STATES = new Set(["running", "in_progress", "queued", "pending", "active"]);
519
+ function isActiveStatus(status) {
520
+ return ACTIVE_STATES.has(String(status || "").toLowerCase());
521
+ }
522
+
523
+ function runNote(r) {
524
+ const out = String(r.output || r.input || "").trim();
525
+ if (out) return out.length > 96 ? out.slice(0, 96) + "…" : out;
526
+ return `Run ${shortId(r.agent_id)} — ${r.status || "recorded"}`;
527
+ }
528
+
529
+ function fmtTime(ts) {
530
+ if (!ts) return "—";
531
+ try {
532
+ const d = new Date(ts);
533
+ if (Number.isNaN(d.getTime())) return String(ts);
534
+ return d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
535
+ } catch { return String(ts); }
536
+ }
537
+
538
+ function shortId(id) {
539
+ const s = String(id || "");
540
+ return s.includes(":") ? s.split(":").pop() : s;
541
+ }