ltcai 4.0.1 → 4.2.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 (192) hide show
  1. package/README.md +33 -24
  2. package/desktop/electron/main.cjs +44 -0
  3. package/docs/CHANGELOG.md +84 -0
  4. package/docs/V4_1_FRONTEND_ARCHITECTURE_REVIEW.md +65 -0
  5. package/docs/V4_1_FRONTEND_MIGRATION_REPORT.md +70 -0
  6. package/docs/V4_1_VALIDATION_REPORT.md +47 -0
  7. package/docs/V4_2_BRAIN_CORE_ARCHITECTURE.md +97 -0
  8. package/docs/V4_2_STORAGE_MIGRATION_REPORT.md +91 -0
  9. package/docs/V4_2_VALIDATION_REPORT.md +89 -0
  10. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +31 -26
  11. package/frontend/index.html +24 -0
  12. package/frontend/openapi.json +14436 -0
  13. package/frontend/src/App.tsx +184 -0
  14. package/frontend/src/api/client.ts +320 -0
  15. package/frontend/src/api/openapi.ts +16921 -0
  16. package/frontend/src/components/primitives.tsx +204 -0
  17. package/frontend/src/components/ui/badge.tsx +27 -0
  18. package/frontend/src/components/ui/button.tsx +37 -0
  19. package/frontend/src/components/ui/card.tsx +22 -0
  20. package/frontend/src/components/ui/input.tsx +16 -0
  21. package/frontend/src/components/ui/textarea.tsx +16 -0
  22. package/frontend/src/lib/utils.ts +33 -0
  23. package/frontend/src/main.tsx +23 -0
  24. package/frontend/src/pages/Act.tsx +245 -0
  25. package/frontend/src/pages/Ask.tsx +200 -0
  26. package/frontend/src/pages/Brain.tsx +267 -0
  27. package/frontend/src/pages/Capture.tsx +158 -0
  28. package/frontend/src/pages/Library.tsx +187 -0
  29. package/frontend/src/pages/System.tsx +378 -0
  30. package/frontend/src/routes.ts +85 -0
  31. package/frontend/src/store/appStore.ts +54 -0
  32. package/frontend/src/styles.css +107 -0
  33. package/kg_schema.py +1 -1
  34. package/knowledge_graph.py +4 -4
  35. package/lattice_brain/__init__.py +70 -0
  36. package/lattice_brain/_kg_common.py +1 -0
  37. package/lattice_brain/archive.py +133 -0
  38. package/lattice_brain/context.py +3 -0
  39. package/lattice_brain/conversations.py +3 -0
  40. package/lattice_brain/core.py +82 -0
  41. package/lattice_brain/discovery.py +1 -0
  42. package/lattice_brain/documents.py +1 -0
  43. package/lattice_brain/embeddings.py +82 -0
  44. package/lattice_brain/identity.py +13 -0
  45. package/lattice_brain/ingest.py +1 -0
  46. package/lattice_brain/memory.py +3 -0
  47. package/lattice_brain/network.py +1 -0
  48. package/lattice_brain/projection.py +1 -0
  49. package/lattice_brain/provenance.py +1 -0
  50. package/lattice_brain/retrieval.py +1 -0
  51. package/lattice_brain/schema.py +1 -0
  52. package/lattice_brain/storage/__init__.py +22 -0
  53. package/lattice_brain/storage/base.py +72 -0
  54. package/lattice_brain/storage/docker.py +105 -0
  55. package/lattice_brain/storage/factory.py +31 -0
  56. package/lattice_brain/storage/migration.py +190 -0
  57. package/lattice_brain/storage/postgres.py +123 -0
  58. package/lattice_brain/storage/sqlite.py +128 -0
  59. package/lattice_brain/store.py +3 -0
  60. package/lattice_brain/write_master.py +1 -0
  61. package/latticeai/__init__.py +1 -1
  62. package/latticeai/api/portability.py +69 -0
  63. package/latticeai/api/setup.py +5 -4
  64. package/latticeai/api/static_routes.py +4 -4
  65. package/latticeai/app_factory.py +17 -10
  66. package/latticeai/brain/__init__.py +6 -6
  67. package/latticeai/brain/_kg_common.py +1 -1
  68. package/latticeai/brain/network.py +1 -1
  69. package/latticeai/brain/retrieval.py +15 -0
  70. package/latticeai/brain/store.py +22 -6
  71. package/latticeai/core/config.py +8 -0
  72. package/latticeai/core/marketplace.py +1 -1
  73. package/latticeai/core/multi_agent.py +1 -1
  74. package/latticeai/core/workspace_os.py +1 -1
  75. package/latticeai/services/kg_portability.py +82 -1
  76. package/package.json +55 -15
  77. package/scripts/build_frontend_assets.mjs +38 -0
  78. package/scripts/bump_version.py +4 -1
  79. package/scripts/export_openapi.py +31 -0
  80. package/scripts/lint_frontend.mjs +91 -0
  81. package/scripts/migrate_brain_storage.py +53 -0
  82. package/scripts/run_python.mjs +47 -0
  83. package/scripts/wheel_smoke.py +3 -0
  84. package/src-tauri/Cargo.lock +4833 -0
  85. package/src-tauri/Cargo.toml +19 -0
  86. package/src-tauri/build.rs +3 -0
  87. package/src-tauri/capabilities/default.json +7 -0
  88. package/src-tauri/src/main.rs +78 -0
  89. package/src-tauri/tauri.conf.json +39 -0
  90. package/static/app/asset-manifest.json +32 -0
  91. package/static/app/assets/core-CwxXejkd.js +2 -0
  92. package/static/app/assets/core-CwxXejkd.js.map +1 -0
  93. package/static/app/assets/index-CDjiH_se.css +2 -0
  94. package/static/app/assets/index-C_HAkbAg.js +333 -0
  95. package/static/app/assets/index-C_HAkbAg.js.map +1 -0
  96. package/static/app/index.html +25 -0
  97. package/static/manifest.json +2 -2
  98. package/static/sw.js +4 -4
  99. package/scripts/build_v3_assets.mjs +0 -170
  100. package/scripts/lint_v3.mjs +0 -120
  101. package/static/v3/asset-manifest.json +0 -63
  102. package/static/v3/css/lattice.base.49deefb5.css +0 -128
  103. package/static/v3/css/lattice.base.css +0 -128
  104. package/static/v3/css/lattice.components.cde18231.css +0 -472
  105. package/static/v3/css/lattice.components.css +0 -472
  106. package/static/v3/css/lattice.shell.29d36d85.css +0 -452
  107. package/static/v3/css/lattice.shell.css +0 -452
  108. package/static/v3/css/lattice.tokens.304cbc40.css +0 -135
  109. package/static/v3/css/lattice.tokens.css +0 -135
  110. package/static/v3/css/lattice.views.0a18b6c5.css +0 -360
  111. package/static/v3/css/lattice.views.css +0 -360
  112. package/static/v3/index.html +0 -68
  113. package/static/v3/js/app.c5c80c46.js +0 -26
  114. package/static/v3/js/app.js +0 -26
  115. package/static/v3/js/core/api.ba0fbf14.js +0 -625
  116. package/static/v3/js/core/api.js +0 -625
  117. package/static/v3/js/core/components.f25b3b93.js +0 -230
  118. package/static/v3/js/core/components.js +0 -230
  119. package/static/v3/js/core/dom.a2773eb0.js +0 -148
  120. package/static/v3/js/core/dom.js +0 -148
  121. package/static/v3/js/core/i18n.880e1fec.js +0 -575
  122. package/static/v3/js/core/i18n.js +0 -575
  123. package/static/v3/js/core/router.584570f2.js +0 -37
  124. package/static/v3/js/core/router.js +0 -37
  125. package/static/v3/js/core/routes.37522821.js +0 -101
  126. package/static/v3/js/core/routes.js +0 -101
  127. package/static/v3/js/core/shell.e3f6bbfa.js +0 -420
  128. package/static/v3/js/core/shell.js +0 -420
  129. package/static/v3/js/core/store.7b2aa044.js +0 -123
  130. package/static/v3/js/core/store.js +0 -123
  131. package/static/v3/js/views/account.eff40715.js +0 -143
  132. package/static/v3/js/views/account.js +0 -143
  133. package/static/v3/js/views/activity.0d271ef9.js +0 -67
  134. package/static/v3/js/views/activity.js +0 -67
  135. package/static/v3/js/views/admin-audit.660a1fb1.js +0 -185
  136. package/static/v3/js/views/admin-audit.js +0 -185
  137. package/static/v3/js/views/admin-permissions.a7ae5f09.js +0 -177
  138. package/static/v3/js/views/admin-permissions.js +0 -177
  139. package/static/v3/js/views/admin-policies.3658fd86.js +0 -102
  140. package/static/v3/js/views/admin-policies.js +0 -102
  141. package/static/v3/js/views/admin-private-vpc.7d342d36.js +0 -135
  142. package/static/v3/js/views/admin-private-vpc.js +0 -135
  143. package/static/v3/js/views/admin-security.07c66b72.js +0 -180
  144. package/static/v3/js/views/admin-security.js +0 -180
  145. package/static/v3/js/views/admin-users.f7ac7b43.js +0 -166
  146. package/static/v3/js/views/admin-users.js +0 -166
  147. package/static/v3/js/views/agents.17c5288d.js +0 -564
  148. package/static/v3/js/views/agents.js +0 -564
  149. package/static/v3/js/views/chat.e250e2cc.js +0 -624
  150. package/static/v3/js/views/chat.js +0 -624
  151. package/static/v3/js/views/files.adad14c1.js +0 -365
  152. package/static/v3/js/views/files.js +0 -365
  153. package/static/v3/js/views/graph-canvas.17c15d65.js +0 -509
  154. package/static/v3/js/views/graph-canvas.js +0 -509
  155. package/static/v3/js/views/home.24f8b8ae.js +0 -200
  156. package/static/v3/js/views/home.js +0 -200
  157. package/static/v3/js/views/hooks.37895880.js +0 -220
  158. package/static/v3/js/views/hooks.js +0 -220
  159. package/static/v3/js/views/hybrid-search.2fb63ed9.js +0 -194
  160. package/static/v3/js/views/hybrid-search.js +0 -194
  161. package/static/v3/js/views/knowledge-graph.4d09c537.js +0 -529
  162. package/static/v3/js/views/knowledge-graph.js +0 -529
  163. package/static/v3/js/views/marketplace.ab0583d4.js +0 -141
  164. package/static/v3/js/views/marketplace.js +0 -141
  165. package/static/v3/js/views/mcp.99b5c6a7.js +0 -114
  166. package/static/v3/js/views/mcp.js +0 -114
  167. package/static/v3/js/views/memory.4ebdf474.js +0 -147
  168. package/static/v3/js/views/memory.js +0 -147
  169. package/static/v3/js/views/models.a1ffa147.js +0 -256
  170. package/static/v3/js/views/models.js +0 -256
  171. package/static/v3/js/views/my-computer.d9d9ae1c.js +0 -463
  172. package/static/v3/js/views/my-computer.js +0 -463
  173. package/static/v3/js/views/network.52a4f181.js +0 -97
  174. package/static/v3/js/views/network.js +0 -97
  175. package/static/v3/js/views/pipeline.c522f1ce.js +0 -157
  176. package/static/v3/js/views/pipeline.js +0 -157
  177. package/static/v3/js/views/planning.4876fd77.js +0 -174
  178. package/static/v3/js/views/planning.js +0 -174
  179. package/static/v3/js/views/runs.b63b2afa.js +0 -144
  180. package/static/v3/js/views/runs.js +0 -144
  181. package/static/v3/js/views/settings.b7140634.js +0 -317
  182. package/static/v3/js/views/settings.js +0 -317
  183. package/static/v3/js/views/skills.c6c2f965.js +0 -109
  184. package/static/v3/js/views/skills.js +0 -109
  185. package/static/v3/js/views/snapshots.6f5db095.js +0 -135
  186. package/static/v3/js/views/snapshots.js +0 -135
  187. package/static/v3/js/views/tools.e4f11276.js +0 -108
  188. package/static/v3/js/views/tools.js +0 -108
  189. package/static/v3/js/views/workflows.7752225a.js +0 -213
  190. package/static/v3/js/views/workflows.js +0 -213
  191. package/static/v3/js/views/workspace-admin.c466029b.js +0 -156
  192. package/static/v3/js/views/workspace-admin.js +0 -156
@@ -1,564 +0,0 @@
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 durable async run, live 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 locally with durable progress and cooperative cancellation."),
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"), "Starting…");
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
- if (data.accepted && (run.id || run.run_id)) {
161
- ctx.toast("Run queued", "ok");
162
- pollRun(run.id || run.run_id);
163
- } else {
164
- ctx.toast(`Run ${mapStatus(result.status) === "failed" ? "completed with failure" : "complete"}`, mapStatus(result.status) === "failed" ? "warn" : "ok");
165
- }
166
-
167
- // Refresh runtime so queue/total/recent-runs reflect this run.
168
- hydrate();
169
- }
170
-
171
- async function pollRun(runId) {
172
- for (let i = 0; i < 80; i += 1) {
173
- await sleep(i < 10 ? 400 : 1200);
174
- const res = await ctx.api.agentRunDetail(runId);
175
- const data = (res && res.data) || {};
176
- if (!res || !res.ok) return;
177
- const run = data.run || {};
178
- logsHost.replaceChildren(renderRunResult(run, run));
179
- hydrate();
180
- if (!isActiveStatus(run.status)) {
181
- const mapped = mapStatus(run.status);
182
- ctx.toast(`Run ${mapped === "failed" ? "completed with failure" : "finished"}`, mapped === "failed" ? "warn" : "ok");
183
- return;
184
- }
185
- }
186
- }
187
-
188
- /* ── Render a run's result as logs + summary ───────────────────────────── */
189
- function renderRunResult(run, result) {
190
- const runId = run.id || run.run_id || result.run_id || result.id;
191
- const status = mapStatus(result.status || run.status);
192
- const timeline = Array.isArray(result.timeline) ? result.timeline : (Array.isArray(run.timeline) ? run.timeline : []);
193
- const output = result.output != null ? String(result.output) : String(run.output_preview || "");
194
- const retries = Number(result.retries) || 0;
195
- const active = isActiveStatus(result.status || run.status);
196
-
197
- return h("div.lt3-stack-4", { style: { "margin-top": "var(--lt3-space-3)" } },
198
- h("hr.lt3-divider"),
199
- h("div.lt3-row", { style: { "justify-content": "space-between", "flex-wrap": "wrap", gap: "var(--lt3-space-2)" } },
200
- h("div.lt3-row-2",
201
- h("span.lt3-eyebrow", "Result"),
202
- c.statePill(status),
203
- retries ? c.pill(`${retries} ${retries === 1 ? "retry" : "retries"}`, "warn") : null,
204
- runId ? h("span.lt3-faint", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-2xs)" } }, shortId(runId)) : null,
205
- ),
206
- runId
207
- ? h("button.lt3-btn.lt3-btn--danger.lt3-btn--sm", {
208
- title: active ? "Stop this run" : "This run has already finished",
209
- on: { click: (e) => stopRun(runId, e.currentTarget) },
210
- }, c.icon("player-stop"), "Stop")
211
- : null,
212
- ),
213
- timeline.length
214
- ? renderTimeline(timeline)
215
- : h("p.lt3-faint", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, "No timeline entries were recorded for this run."),
216
- output
217
- ? h("div.lt3-stack-2",
218
- h("div.lt3-eyebrow", icon("file-text"), "Output"),
219
- h("pre.lt3-code", output),
220
- )
221
- : null,
222
- );
223
- }
224
-
225
- /* ── Timeline → readable log list ──────────────────────────────────────── */
226
- function renderTimeline(timeline) {
227
- return h("div.lt3-stack-2",
228
- h("div.lt3-eyebrow", icon("list-details"), "Logs"),
229
- h("div.lt3-timeline",
230
- timeline.map((entry) => {
231
- const label = entry.event || entry.message || entry.step || "event";
232
- const role = entry.role || entry.agent_id;
233
- const status = entry.status;
234
- const ts = entry.timestamp || entry.created_at || entry.time;
235
- return h("div.lt3-timeline__item",
236
- ts ? h("div.lt3-timeline__time", fmtTime(ts)) : null,
237
- h("div.lt3-timeline__body",
238
- h("div.lt3-row-2", { style: { "flex-wrap": "wrap" } },
239
- role ? h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, shortId(role)) : null,
240
- h("span", String(label).replace(/_/g, " ")),
241
- status ? c.statePill(mapStatus(status)) : null,
242
- ),
243
- entry.detail || entry.note
244
- ? h("div.lt3-muted", { style: { "font-size": "var(--lt3-text-xs)", "margin-top": "var(--lt3-space-1)" } }, String(entry.detail || entry.note))
245
- : null,
246
- ),
247
- );
248
- }),
249
- ),
250
- );
251
- }
252
-
253
- /* ── Stop an (active) run — honest about synchronous no-op ─────────────── */
254
- async function stopRun(runId, btn) {
255
- if (btn) { btn.disabled = true; btn.replaceChildren(c.icon("loader-2"), "Stopping…"); }
256
- const res = await ctx.api.stopAgentRun(runId);
257
- if (btn) { btn.disabled = false; btn.replaceChildren(c.icon("player-stop"), "Stop"); }
258
- const data = (res && res.data) || {};
259
- if (!res || !res.ok) {
260
- ctx.toast(String(data.detail || data.error || "Stop unavailable"), "err");
261
- return;
262
- }
263
- if (data.stopped === false || data.stopped == null) {
264
- ctx.toast(String(data.reason || "Run already finished — nothing to stop"), "warn");
265
- } else {
266
- ctx.toast("Run stopped", "ok");
267
- }
268
- hydrate();
269
- }
270
-
271
- /* ── Load a recorded run's detail as logs ──────────────────────────────── */
272
- async function openRun(runId) {
273
- if (!runId) return;
274
- logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } }, c.loading({ lines: 3 })));
275
- const res = await ctx.api.agentRunDetail(runId);
276
- const data = (res && res.data) || {};
277
- if (!res || !res.ok) {
278
- runSrc.replaceChildren(c.sourceBadge("unavailable"));
279
- logsHost.replaceChildren(h("div", { style: { "margin-top": "var(--lt3-space-3)" } },
280
- c.banner(String(data.detail || data.error || "Run detail unavailable"), "err"),
281
- ));
282
- return;
283
- }
284
- runSrc.replaceChildren(c.sourceBadge("live"));
285
- const run = data.run || data || {};
286
- const result = data.result || data || {};
287
- logsHost.replaceChildren(renderRunResult(run, result));
288
- }
289
-
290
- /* ── Refresh runtime → stats, queue, recent runs, roster, health ───────── */
291
- async function hydrate() {
292
- const res = await ctx.api.agentRuntime();
293
- const data = res.data || {};
294
- const agents = normalize(data.agents);
295
- const runtime = data.runtime || {};
296
- const health = data.health || { status: "unknown" };
297
- const runs = Array.isArray(data.runs) ? data.runs : [];
298
- const byId = new Map(agents.map((a) => [a.id, a.name]));
299
-
300
- // Seed role chips from the runtime's real default pipeline / roles (once).
301
- if (!roleState.__seeded) {
302
- const fromRuntime = Array.isArray(runtime.default_pipeline) && runtime.default_pipeline.length
303
- ? runtime.default_pipeline
304
- : (Array.isArray(data.roles) ? data.roles.map((r) => r.role).filter(Boolean) : []);
305
- if (fromRuntime.length) {
306
- roleState = fromRuntime.map((r) => ({ role: String(r), on: true }));
307
- roleState.__seeded = true;
308
- renderRoleChips();
309
- }
310
- }
311
-
312
- rosterSrc.replaceChildren(c.sourceBadge(res.source));
313
- runsSrc.replaceChildren(c.sourceBadge(res.source));
314
- healthSlot.replaceChildren(
315
- c.statePill(health.status === "ok" ? "ready" : health.status === "degraded" ? "warn" : "idle"),
316
- );
317
-
318
- // ── Stat row + queue/status (real runtime counts) ───────────────────
319
- const available = agents.filter((a) => isAvailable(a.state)).length;
320
- const totalRuns = Number(runtime.total_runs) || runs.length;
321
- const activeRuns = Number(runtime.active_runs) || 0;
322
- statHost.replaceChildren(
323
- c.stat({ label: "Agents", value: c.fmtNum(agents.length), icon: "robot" }),
324
- c.stat({ label: "Available", value: c.fmtNum(available), icon: "circle-check" }),
325
- c.stat({ label: "Total runs", value: c.fmtNum(totalRuns), icon: "player-play" }),
326
- c.stat({
327
- label: "Queue", value: c.fmtNum(activeRuns), icon: "clock-play",
328
- delta: activeRuns ? "active" : "idle", deltaDir: activeRuns ? "up" : undefined,
329
- }),
330
- );
331
-
332
- // ── Roster grid ─────────────────────────────────────────────────────
333
- if (!agents.length) {
334
- rosterHost.replaceChildren(c.emptyState({
335
- icon: "robot-off",
336
- title: "Runtime unavailable",
337
- body: "The agent runtime did not respond. Start the local server to see the roster.",
338
- }));
339
- } else {
340
- rosterHost.replaceChildren(
341
- h("div.lt3-grid-auto", agents.map((a) => agentCard(ctx, a, byId))),
342
- );
343
- }
344
-
345
- // ── Recent runs ledger (REAL runs; click → load logs) ───────────────
346
- if (!runs.length) {
347
- runsHost.replaceChildren(c.emptyState({ icon: "history-off", title: "No runs yet", body: "Trigger a run above — recorded runs appear here." }));
348
- } else {
349
- runsHost.replaceChildren(
350
- c.table(
351
- [
352
- { key: "agent", label: "Agent", render: (r) => h("div.lt3-row-2",
353
- h("span.lt3-avatar", { style: { width: "26px", height: "26px" } }, icon("robot")),
354
- h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, r.agent),
355
- ) },
356
- { key: "status", label: "Status", width: "1%", render: (r) => c.statePill(r.status) },
357
- { 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) },
358
- { key: "note", label: "Note", render: (r) => h("span.lt3-muted", r.note) },
359
- { key: "open", label: "", width: "1%", render: (r) => r.id
360
- ? h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => openRun(r.id) } }, icon("list-search"), "Logs")
361
- : null },
362
- ],
363
- runs.map((r) => ({
364
- id: r.id || r.run_id,
365
- agent: byId.get(r.agent_id) || shortId(r.agent_id),
366
- status: mapStatus(r.status),
367
- time: timeAgo(r.created_at || r.completed_at) || fmtTime(r.created_at || r.completed_at),
368
- note: runNote(r),
369
- })),
370
- { empty: c.emptyState({ icon: "history-off", title: "No runs yet", body: "Agent runs recorded by the runtime will appear here." }) },
371
- ),
372
- );
373
- }
374
- }
375
-
376
- return { hydrate, openRun };
377
- }
378
-
379
- async function loadRegistry(ctx, hosts) {
380
- const { h, c } = ctx;
381
- const { registryHost, registrySrc } = hosts;
382
- const [registryRes, capsRes] = await Promise.all([ctx.api.agentRegistry(), ctx.api.agentCapabilities()]);
383
- const agents = normalizeRegistry(registryRes.data);
384
- const caps = (capsRes.data && capsRes.data.capabilities) || {};
385
- registrySrc.replaceChildren(c.sourceBadge(registryRes.source === "live" || capsRes.source === "live" ? "live" : "unavailable"));
386
-
387
- const nameInput = h("input.lt3-input", { type: "text", placeholder: "Custom agent name", "aria-label": "Custom agent name" });
388
- const capsInput = h("input.lt3-input", { type: "text", placeholder: "capability-a, capability-b", "aria-label": "Custom agent capabilities" });
389
- const registerBtn = h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: register } }, c.icon("plus"), "Register");
390
-
391
- const capList = Object.keys(caps).sort();
392
- const body = h("div.lt3-stack-4",
393
- h("div.lt3-grid-2",
394
- h("div.lt3-field", h("label", "Name"), nameInput),
395
- h("div.lt3-field", h("label", "Capabilities"), capsInput),
396
- ),
397
- h("div.lt3-row-2", registerBtn,
398
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Custom agents persist in the local registry.")),
399
- capList.length
400
- ? h("div.lt3-cluster", capList.slice(0, 18).map((cap) => h("span.lt3-chip", c.icon("sparkles"), `${cap} (${caps[cap].length})`)))
401
- : h("p.lt3-faint", { style: { margin: 0 } }, "Capabilities appear here when the registry is live."),
402
- agents.length
403
- ? h("div.lt3-grid-auto", agents.map((agent) => registryCard(ctx, agent)))
404
- : c.emptyState({ icon: "robot-off", title: "Agent registry unavailable", body: "Start the local server to register and configure agents." }),
405
- );
406
- registryHost.replaceChildren(c.panel({ title: "Registry controls", sub: "Register, discover, and configure built-in or custom agents.", children: body }));
407
-
408
- async function register() {
409
- const name = nameInput.value.trim();
410
- if (!name) { ctx.toast("Enter an agent name", "info"); return; }
411
- const capabilities = capsInput.value.split(",").map((s) => s.trim()).filter(Boolean);
412
- registerBtn.disabled = true;
413
- const res = await ctx.api.registerAgent({ name, type: "custom", capabilities });
414
- registerBtn.disabled = false;
415
- if (res && res.ok) {
416
- ctx.toast(`Registered ${name}`, "ok");
417
- loadRegistry(ctx, hosts);
418
- } else {
419
- ctx.toast("Register unavailable", "err");
420
- }
421
- }
422
- }
423
-
424
- function registryCard(ctx, agent) {
425
- const { h, c } = ctx;
426
- return c.card(h("div.lt3-stack-3",
427
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
428
- h("div",
429
- h("b", agent.name),
430
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, agent.id),
431
- ),
432
- c.pill(agent.source === "builtin" ? "built-in" : "custom", agent.source === "builtin" ? "info" : "warn"),
433
- ),
434
- h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", margin: 0 } }, agent.description || "No description."),
435
- h("div.lt3-cluster", [c.statePill(agent.enabled ? "ready" : "idle"), c.pill(agent.type), c.pill(`v${agent.version || "1.0.0"}`)]),
436
- agent.capabilities.length ? h("div.lt3-cluster", agent.capabilities.slice(0, 8).map((cap) => h("span.lt3-chip", cap))) : null,
437
- h("div.lt3-row-2",
438
- 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"),
439
- agent.removable ? h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => removeAgent(ctx, agent) } }, c.icon("trash"), "Remove") : null,
440
- ),
441
- ), { interactive: false });
442
- }
443
-
444
- async function toggleAgent(ctx, agent) {
445
- const res = await ctx.api.updateAgent(agent.id, { config: agent.config || {}, enabled: !agent.enabled });
446
- ctx.toast(res && res.ok ? `${agent.name}: ${agent.enabled ? "disabled" : "enabled"}` : "Agent update unavailable", res && res.ok ? "ok" : "err");
447
- if (res && res.ok) ctx.navigate("agents");
448
- }
449
-
450
- async function removeAgent(ctx, agent) {
451
- const res = await ctx.api.removeAgent(agent.id);
452
- ctx.toast(res && res.ok ? `Removed ${agent.name}` : "Agent remove unavailable", res && res.ok ? "ok" : "err");
453
- if (res && res.ok) ctx.navigate("agents");
454
- }
455
-
456
- /* ── Agent card ──────────────────────────────────────────────────────────── */
457
- function agentCard(ctx, agent, byId) {
458
- const { h, icon, c } = ctx;
459
- return c.card(
460
- h("div.lt3-stack-3",
461
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
462
- h("div.lt3-row-2",
463
- h("span.lt3-avatar", { style: { width: "40px", height: "40px", "border-radius": "var(--lt3-radius-md)" } }, icon("robot")),
464
- h("div",
465
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)", "font-size": "var(--lt3-text-md)" } }, agent.name),
466
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, agent.id),
467
- ),
468
- ),
469
- c.statePill(agent.state),
470
- ),
471
- h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", margin: "0" } }, agent.role),
472
- h("div.lt3-row-2", { style: { "font-size": "var(--lt3-text-xs)", color: "var(--muted)" } },
473
- icon("player-play"),
474
- h("b", { style: { color: "var(--text)" } }, c.fmtNum(agent.runs)),
475
- "runs",
476
- ),
477
- agent.handoffs.length
478
- ? h("div.lt3-stack-2",
479
- h("div.lt3-eyebrow", icon("arrows-exchange"), "Hands off to"),
480
- h("div.lt3-cluster", agent.handoffs.map((id) => {
481
- const name = byId.get(id) || shortId(id);
482
- return h("span.lt3-chip", icon("arrow-right"), name);
483
- })),
484
- )
485
- : h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Terminal role — no handoffs"),
486
- ),
487
- { interactive: false },
488
- );
489
- }
490
-
491
- /* ── helpers ─────────────────────────────────────────────────────────────── */
492
- function normalize(data) {
493
- const list = Array.isArray(data) ? data : (data && Array.isArray(data.agents) ? data.agents : []);
494
- return list.map((a, i) => ({
495
- id: a.id || `agent:${i}`,
496
- name: a.name || a.id || `Agent ${i + 1}`,
497
- role: a.role || a.description || "No role description.",
498
- state: a.state || a.status || "idle",
499
- runs: a.runs ?? a.run_count ?? a.runs_count ?? 0,
500
- handoffs: Array.isArray(a.handoffs) ? a.handoffs
501
- : Array.isArray(a.relationships) ? a.relationships : [],
502
- }));
503
- }
504
-
505
- function normalizeRegistry(data) {
506
- const list = Array.isArray(data) ? data : (data && Array.isArray(data.agents) ? data.agents : []);
507
- return list.map((agent, i) => ({
508
- id: agent.id || `agent:${i}`,
509
- name: agent.name || agent.id || `Agent ${i + 1}`,
510
- type: agent.type || "custom",
511
- version: agent.version || "1.0.0",
512
- description: agent.description || "",
513
- capabilities: Array.isArray(agent.capabilities) ? agent.capabilities : [],
514
- source: agent.source || "user",
515
- enabled: agent.enabled !== false,
516
- removable: !!agent.removable,
517
- config: agent.config || {},
518
- }));
519
- }
520
-
521
- const AVAILABLE_STATES = new Set(["available", "ready", "active", "ok", "idle"]);
522
- function isAvailable(state) {
523
- return AVAILABLE_STATES.has(String(state).toLowerCase());
524
- }
525
-
526
- // Map orchestrator run statuses onto the shared state-pill vocabulary.
527
- function mapStatus(status) {
528
- const s = String(status || "").toLowerCase();
529
- if (s === "ok" || s === "retried_ok") return "ready";
530
- if (s === "failed" || s === "rejected") return "failed";
531
- if (s === "running" || s === "in_progress" || s === "queued" || s === "cancelling") return "active";
532
- if (s === "cancelled" || s === "interrupted") return "warn";
533
- return s || "idle";
534
- }
535
-
536
- // An active run is one that could (in principle) still be stopped.
537
- const ACTIVE_STATES = new Set(["running", "in_progress", "queued", "pending", "active", "cancelling"]);
538
- function isActiveStatus(status) {
539
- return ACTIVE_STATES.has(String(status || "").toLowerCase());
540
- }
541
-
542
- function sleep(ms) {
543
- return new Promise((resolve) => setTimeout(resolve, ms));
544
- }
545
-
546
- function runNote(r) {
547
- const out = String(r.output || r.input || "").trim();
548
- if (out) return out.length > 96 ? out.slice(0, 96) + "…" : out;
549
- return `Run ${shortId(r.agent_id)} — ${r.status || "recorded"}`;
550
- }
551
-
552
- function fmtTime(ts) {
553
- if (!ts) return "—";
554
- try {
555
- const d = new Date(ts);
556
- if (Number.isNaN(d.getTime())) return String(ts);
557
- return d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
558
- } catch { return String(ts); }
559
- }
560
-
561
- function shortId(id) {
562
- const s = String(id || "");
563
- return s.includes(":") ? s.split(":").pop() : s;
564
- }