ltcai 3.3.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 (75) hide show
  1. package/README.md +85 -66
  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/capture/capture_v340.js +88 -0
  38. package/static/css/{tokens.8b8e31bd.css → tokens.3ba22e37.css} +109 -109
  39. package/static/css/tokens.css +109 -109
  40. package/static/v3/asset-manifest.json +24 -24
  41. package/static/v3/css/{lattice.components.011e988b.css → lattice.components.9b49d614.css} +57 -32
  42. package/static/v3/css/lattice.components.css +57 -32
  43. package/static/v3/css/{lattice.shell.4920f42d.css → lattice.shell.6ceea7c8.css} +75 -31
  44. package/static/v3/css/lattice.shell.css +75 -31
  45. package/static/v3/css/lattice.tokens.css +13 -13
  46. package/static/v3/css/{lattice.tokens.c597ff81.css → lattice.tokens.e7018963.css} +13 -13
  47. package/static/v3/css/{lattice.views.1d326beb.css → lattice.views.22f69117.css} +93 -15
  48. package/static/v3/css/lattice.views.css +93 -15
  49. package/static/v3/js/{app.cf5bb712.js → app.c4acfdd8.js} +1 -1
  50. package/static/v3/js/core/{api.113660c5.js → api.12b568ad.js} +67 -0
  51. package/static/v3/js/core/api.js +67 -0
  52. package/static/v3/js/core/{components.4c83e0a9.js → components.35f02e4c.js} +8 -0
  53. package/static/v3/js/core/components.js +8 -0
  54. package/static/v3/js/core/{routes.07ad6696.js → routes.d214b399.js} +16 -12
  55. package/static/v3/js/core/routes.js +16 -12
  56. package/static/v3/js/core/{shell.9e707234.js → shell.80a6ad82.js} +37 -9
  57. package/static/v3/js/core/shell.js +34 -6
  58. package/static/v3/js/views/agents.014d0b74.js +541 -0
  59. package/static/v3/js/views/agents.js +305 -57
  60. package/static/v3/js/views/{chat.c48fd9e2.js → chat.e6dd7dd0.js} +161 -9
  61. package/static/v3/js/views/chat.js +161 -9
  62. package/static/v3/js/views/files.adad14c1.js +365 -0
  63. package/static/v3/js/views/files.js +212 -79
  64. package/static/v3/js/views/home.24f8b8ae.js +200 -0
  65. package/static/v3/js/views/home.js +96 -15
  66. package/static/v3/js/views/hooks.13845954.js +215 -0
  67. package/static/v3/js/views/hooks.js +117 -1
  68. package/static/v3/js/views/{my-computer.1b2ff621.js → my-computer.c3ef5283.js} +224 -1
  69. package/static/v3/js/views/my-computer.js +224 -1
  70. package/static/v3/js/views/{settings.c7b0cc05.js → settings.8631fa5e.js} +54 -0
  71. package/static/v3/js/views/settings.js +54 -0
  72. package/static/v3/js/views/agents.c373d48c.js +0 -293
  73. package/static/v3/js/views/files.8464634a.js +0 -232
  74. package/static/v3/js/views/home.cdde3b32.js +0 -119
  75. package/static/v3/js/views/hooks.f3edebca.js +0 -99
@@ -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
+ }