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,135 +0,0 @@
1
- import { t } from "../core/i18n.js";
2
-
3
- export async function render(ctx) {
4
- const { h, icon, api, c, toast } = ctx;
5
- const host = h("div.lt3-stack-6", c.loading({ lines: 5, block: true }));
6
-
7
- async function load() {
8
- const [snaps, timeline] = await Promise.all([api.snapshots(), api.timeMachine(80)]);
9
- const rows = normalize(snaps.data);
10
- host.replaceChildren(
11
- c.viewHeader({
12
- eyebrow: t("snapshots.eyebrow"),
13
- title: t("snapshots.title"),
14
- sub: t("snapshots.sub"),
15
- actions: [c.sourceBadge(snaps.source)],
16
- }),
17
- createPanel(),
18
- comparePanel(rows),
19
- snapshotTable(rows),
20
- timelinePanel(timeline),
21
- );
22
- }
23
-
24
- function createPanel() {
25
- const name = h("input.lt3-input", { type: "text", placeholder: t("snapshots.name"), "aria-label": t("snapshots.name") });
26
- return c.panel({
27
- title: t("snapshots.create"),
28
- children: h("div.lt3-row-2",
29
- name,
30
- h("button.lt3-btn.lt3-btn--primary", { on: { click: async () => {
31
- const res = await api.createSnapshot(name.value.trim() || t("snapshots.title"));
32
- toast(resultText(res, t("snapshots.created")), res.ok ? "ok" : "err");
33
- if (res.ok) { name.value = ""; load(); }
34
- } } }, icon("camera"), t("snapshots.create")),
35
- ),
36
- });
37
- }
38
-
39
- function comparePanel(rows) {
40
- const before = select(rows);
41
- const after = select(rows);
42
- const result = h("div");
43
- return c.panel({
44
- title: t("snapshots.compare"),
45
- children: h("div.lt3-stack-4",
46
- h("div.lt3-row-2", before, after, h("button.lt3-btn.lt3-btn--primary", { on: { click: async () => {
47
- if (!before.value || !after.value) return;
48
- result.replaceChildren(c.loading({ lines: 2 }));
49
- const res = await api.compareSnapshots(before.value, after.value);
50
- const d = res.data || {};
51
- result.replaceChildren(res.ok
52
- ? h("dl.lt3-keyval",
53
- h("dt", "nodes_added"), h("dd", String(d.summary?.nodes_added ?? 0)),
54
- h("dt", "nodes_removed"), h("dd", String(d.summary?.nodes_removed ?? 0)),
55
- h("dt", "edges_added"), h("dd", String(d.summary?.edges_added ?? 0)),
56
- h("dt", "edges_removed"), h("dd", String(d.summary?.edges_removed ?? 0)),
57
- )
58
- : c.banner(resultText(res, t("common.unavailable")), "err"));
59
- } } }, icon("git-compare"), t("snapshots.compare"))),
60
- result,
61
- ),
62
- });
63
- }
64
-
65
- function snapshotTable(rows) {
66
- if (!rows.length) return c.emptyState({ icon: "history", title: t("snapshots.title"), body: t("common.none") });
67
- return c.panel({
68
- title: t("snapshots.title"),
69
- children: c.table([
70
- { key: "name", label: t("common.name"), render: (r) => h("div", h("b", r.name || r.id), h("div.lt3-faint", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-2xs)" } }, r.id)) },
71
- { key: "created", label: t("common.created"), width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap" } }, fmt(r.created_at)) },
72
- { key: "nodes", label: "nodes", width: "1%", render: (r) => String(r.node_count ?? 0) },
73
- { key: "edges", label: "edges", width: "1%", render: (r) => String(r.edge_count ?? 0) },
74
- { key: "actions", label: "", width: "1%", render: (r) => h("div.lt3-row-2",
75
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => exportSnapshot(r.id) } }, icon("download"), t("snapshots.export")),
76
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => restoreSnapshot(r.id) } }, icon("restore"), t("snapshots.restore")),
77
- ) },
78
- ], rows),
79
- });
80
- }
81
-
82
- function timelinePanel(res) {
83
- const events = Array.isArray(res.data?.events) ? res.data.events : [];
84
- return c.panel({
85
- title: t("snapshots.timeline"),
86
- actions: [c.sourceBadge(res.source)],
87
- children: events.length ? c.table([
88
- { key: "event", label: t("common.status"), render: (e) => h("span", e.event_type || e.area || "event") },
89
- { key: "area", label: t("common.type"), width: "1%", render: (e) => c.pill(e.area || "workspace") },
90
- { key: "when", label: t("common.created"), width: "1%", render: (e) => h("span.lt3-faint", { style: { "white-space": "nowrap" } }, fmt(e.timestamp)) },
91
- ], events.slice(0, 40)) : c.emptyState({ icon: "history-off", title: t("snapshots.timeline"), body: t("common.none") }),
92
- });
93
- }
94
-
95
- async function exportSnapshot(id) {
96
- const res = await api.snapshotExport(id);
97
- toast(resultText(res, res.data?.export_path || t("snapshots.export")), res.ok ? "ok" : "err");
98
- }
99
- async function restoreSnapshot(id) {
100
- const res = await api.snapshotRestore(id);
101
- toast(resultText(res, t("snapshots.restored")), res.ok ? "ok" : "err");
102
- if (res.ok) load();
103
- }
104
-
105
- await load();
106
- return host;
107
- }
108
-
109
- function select(rows) {
110
- const sel = document.createElement("select");
111
- sel.className = "lt3-select";
112
- sel.setAttribute("aria-label", t("snapshots.title"));
113
- for (const row of rows) {
114
- const opt = document.createElement("option");
115
- opt.value = row.id;
116
- opt.textContent = row.name || row.id;
117
- sel.append(opt);
118
- }
119
- return sel;
120
- }
121
-
122
- function normalize(data) {
123
- return Array.isArray(data?.snapshots) ? data.snapshots : [];
124
- }
125
-
126
- function fmt(ts) {
127
- if (!ts) return "—";
128
- try { return new Date(ts).toLocaleString(); } catch { return String(ts); }
129
- }
130
-
131
- function resultText(res, okText) {
132
- if (res && res.ok) return okText;
133
- const data = (res && res.data) || {};
134
- return String(data.detail || data.error || res?.error || t("common.unavailable"));
135
- }
@@ -1,108 +0,0 @@
1
- /* ============================================================================
2
- * View: Tools — the unified tool registry (local / workspace / MCP).
3
- * Reads /mcp/tools (descriptions + governance) and /tools/permissions for risk
4
- * and approval. Tools are grouped by risk with governance pills; MCP servers
5
- * surface alongside. Unavailable is explicit.
6
- * ========================================================================== */
7
-
8
- const RISK_ORDER = ["high", "medium", "low"];
9
- const RISK_VARIANT = { high: "err", medium: "warn", low: "ok" };
10
-
11
- export async function render(ctx) {
12
- const { h, c } = ctx;
13
- const src = h("span", c.sourceBadge("pending"));
14
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
15
- const groupsHost = h("div", c.loading({ lines: 4, block: true }));
16
-
17
- const root = h("div.lt3-stack-6",
18
- c.viewHeader({
19
- eyebrow: "Platform",
20
- title: "Tool Registry",
21
- sub: "Every tool the agent can call — local, workspace, and MCP — with its governance policy: risk, approval, sandbox, and network access.",
22
- actions: [src],
23
- }),
24
- statHost,
25
- h("section", c.sectionHead("Registered tools"), groupsHost),
26
- );
27
-
28
- load();
29
- return root;
30
-
31
- async function load() {
32
- const [mcp, perms] = await Promise.all([ctx.api.mcpTools(), ctx.api.toolPermissions()]);
33
- src.replaceChildren(c.sourceBadge(mcp.source === "live" || perms.source === "live" ? "live" : "unavailable"));
34
- const permMap = {};
35
- for (const p of normalizePerms(perms.data)) permMap[p.tool] = p;
36
- const tools = mergeTools(mcp.data, permMap);
37
-
38
- if (!tools.length) {
39
- statHost.replaceChildren(c.stat({ label: "Tools", value: "—", icon: "tools" }));
40
- groupsHost.replaceChildren(c.emptyState({ icon: "tool", title: "Tool registry unavailable", body: "Start the backend to read the tool registry." }));
41
- return;
42
- }
43
- const mcpServers = (mcp.data && mcp.data.installed_mcps) || [];
44
- const approval = tools.filter((t) => t.requires_approval).length;
45
- statHost.replaceChildren(
46
- c.stat({ label: "Tools", value: c.fmtNum(tools.length), icon: "tools" }),
47
- c.stat({ label: "Need approval", value: c.fmtNum(approval), icon: "lock" }),
48
- c.stat({ label: "MCP servers", value: c.fmtNum(mcpServers.length), icon: "plug-connected" }),
49
- );
50
-
51
- const byRisk = {};
52
- for (const t of tools) (byRisk[t.risk] = byRisk[t.risk] || []).push(t);
53
- const sections = RISK_ORDER.filter((r) => byRisk[r]).map((risk) =>
54
- h("section",
55
- c.sectionHead(h("span.lt3-row-2", c.pill(`${risk} risk`, RISK_VARIANT[risk]), c.pill(String(byRisk[risk].length))), null),
56
- c.table(
57
- [
58
- { key: "name", label: "Tool", render: (t) => h("div", h("b", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } }, t.name), t.description ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, t.description) : null) },
59
- { key: "approval", label: "Approval", width: "1%", render: (t) => c.statePill(t.requires_approval ? "pending" : "ready") },
60
- { key: "sandbox", label: "Sandbox", width: "1%", render: (t) => t.sandbox ? c.pill(t.sandbox) : h("span.lt3-faint", "—") },
61
- { key: "net", label: "Network", width: "1%", render: (t) => t.network ? c.pill("network", "warn") : h("span.lt3-faint", "—") },
62
- ],
63
- byRisk[risk],
64
- ),
65
- ));
66
- groupsHost.replaceChildren(h("div.lt3-stack-6", ...sections));
67
- }
68
- }
69
-
70
- function normalizePerms(data) {
71
- if (!data) return [];
72
- if (Array.isArray(data.permissions)) return data.permissions;
73
- if (Array.isArray(data)) return data;
74
- return [];
75
- }
76
-
77
- function mergeTools(mcpData, permMap) {
78
- const out = [];
79
- const seen = new Set();
80
- const list = (mcpData && mcpData.tools) || [];
81
- for (const t of list) {
82
- const gov = t.governance || {};
83
- const perm = permMap[t.name] || {};
84
- out.push({
85
- name: t.name,
86
- description: t.description || "",
87
- risk: (perm.risk || riskFromGov(gov) || "medium"),
88
- requires_approval: perm.requires_approval != null ? perm.requires_approval : !gov.auto_approve,
89
- sandbox: gov.sandbox || "",
90
- network: gov.network != null ? gov.network : perm.network,
91
- });
92
- seen.add(t.name);
93
- }
94
- // Tools present only in the permission list (no MCP description).
95
- for (const name of Object.keys(permMap)) {
96
- if (seen.has(name)) continue;
97
- const p = permMap[name];
98
- out.push({ name, description: "", risk: p.risk || "medium", requires_approval: !!p.requires_approval, sandbox: "", network: !!p.network });
99
- }
100
- return out;
101
- }
102
-
103
- function riskFromGov(gov) {
104
- if (gov.risk === "exec" || gov.risk === "destructive") return "high";
105
- if (gov.risk === "write") return "medium";
106
- if (gov.risk === "read") return "low";
107
- return null;
108
- }
@@ -1,108 +0,0 @@
1
- /* ============================================================================
2
- * View: Tools — the unified tool registry (local / workspace / MCP).
3
- * Reads /mcp/tools (descriptions + governance) and /tools/permissions for risk
4
- * and approval. Tools are grouped by risk with governance pills; MCP servers
5
- * surface alongside. Unavailable is explicit.
6
- * ========================================================================== */
7
-
8
- const RISK_ORDER = ["high", "medium", "low"];
9
- const RISK_VARIANT = { high: "err", medium: "warn", low: "ok" };
10
-
11
- export async function render(ctx) {
12
- const { h, c } = ctx;
13
- const src = h("span", c.sourceBadge("pending"));
14
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
15
- const groupsHost = h("div", c.loading({ lines: 4, block: true }));
16
-
17
- const root = h("div.lt3-stack-6",
18
- c.viewHeader({
19
- eyebrow: "Platform",
20
- title: "Tool Registry",
21
- sub: "Every tool the agent can call — local, workspace, and MCP — with its governance policy: risk, approval, sandbox, and network access.",
22
- actions: [src],
23
- }),
24
- statHost,
25
- h("section", c.sectionHead("Registered tools"), groupsHost),
26
- );
27
-
28
- load();
29
- return root;
30
-
31
- async function load() {
32
- const [mcp, perms] = await Promise.all([ctx.api.mcpTools(), ctx.api.toolPermissions()]);
33
- src.replaceChildren(c.sourceBadge(mcp.source === "live" || perms.source === "live" ? "live" : "unavailable"));
34
- const permMap = {};
35
- for (const p of normalizePerms(perms.data)) permMap[p.tool] = p;
36
- const tools = mergeTools(mcp.data, permMap);
37
-
38
- if (!tools.length) {
39
- statHost.replaceChildren(c.stat({ label: "Tools", value: "—", icon: "tools" }));
40
- groupsHost.replaceChildren(c.emptyState({ icon: "tool", title: "Tool registry unavailable", body: "Start the backend to read the tool registry." }));
41
- return;
42
- }
43
- const mcpServers = (mcp.data && mcp.data.installed_mcps) || [];
44
- const approval = tools.filter((t) => t.requires_approval).length;
45
- statHost.replaceChildren(
46
- c.stat({ label: "Tools", value: c.fmtNum(tools.length), icon: "tools" }),
47
- c.stat({ label: "Need approval", value: c.fmtNum(approval), icon: "lock" }),
48
- c.stat({ label: "MCP servers", value: c.fmtNum(mcpServers.length), icon: "plug-connected" }),
49
- );
50
-
51
- const byRisk = {};
52
- for (const t of tools) (byRisk[t.risk] = byRisk[t.risk] || []).push(t);
53
- const sections = RISK_ORDER.filter((r) => byRisk[r]).map((risk) =>
54
- h("section",
55
- c.sectionHead(h("span.lt3-row-2", c.pill(`${risk} risk`, RISK_VARIANT[risk]), c.pill(String(byRisk[risk].length))), null),
56
- c.table(
57
- [
58
- { key: "name", label: "Tool", render: (t) => h("div", h("b", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } }, t.name), t.description ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, t.description) : null) },
59
- { key: "approval", label: "Approval", width: "1%", render: (t) => c.statePill(t.requires_approval ? "pending" : "ready") },
60
- { key: "sandbox", label: "Sandbox", width: "1%", render: (t) => t.sandbox ? c.pill(t.sandbox) : h("span.lt3-faint", "—") },
61
- { key: "net", label: "Network", width: "1%", render: (t) => t.network ? c.pill("network", "warn") : h("span.lt3-faint", "—") },
62
- ],
63
- byRisk[risk],
64
- ),
65
- ));
66
- groupsHost.replaceChildren(h("div.lt3-stack-6", ...sections));
67
- }
68
- }
69
-
70
- function normalizePerms(data) {
71
- if (!data) return [];
72
- if (Array.isArray(data.permissions)) return data.permissions;
73
- if (Array.isArray(data)) return data;
74
- return [];
75
- }
76
-
77
- function mergeTools(mcpData, permMap) {
78
- const out = [];
79
- const seen = new Set();
80
- const list = (mcpData && mcpData.tools) || [];
81
- for (const t of list) {
82
- const gov = t.governance || {};
83
- const perm = permMap[t.name] || {};
84
- out.push({
85
- name: t.name,
86
- description: t.description || "",
87
- risk: (perm.risk || riskFromGov(gov) || "medium"),
88
- requires_approval: perm.requires_approval != null ? perm.requires_approval : !gov.auto_approve,
89
- sandbox: gov.sandbox || "",
90
- network: gov.network != null ? gov.network : perm.network,
91
- });
92
- seen.add(t.name);
93
- }
94
- // Tools present only in the permission list (no MCP description).
95
- for (const name of Object.keys(permMap)) {
96
- if (seen.has(name)) continue;
97
- const p = permMap[name];
98
- out.push({ name, description: "", risk: p.risk || "medium", requires_approval: !!p.requires_approval, sandbox: "", network: !!p.network });
99
- }
100
- return out;
101
- }
102
-
103
- function riskFromGov(gov) {
104
- if (gov.risk === "exec" || gov.risk === "destructive") return "high";
105
- if (gov.risk === "write") return "medium";
106
- if (gov.risk === "read") return "low";
107
- return null;
108
- }
@@ -1,213 +0,0 @@
1
- /* ============================================================================
2
- * View: Workflows — workflow-driven agent execution.
3
- * Trigger → agent chain → tools → memory → result. Reads workflow definitions
4
- * and runs from the real workflow designer backend; runs a definition and shows
5
- * the run ledger with replay. Unavailable state is explicit.
6
- * ========================================================================== */
7
-
8
- const STAGES = ["Trigger", "Agent chain", "Tools", "Memory", "Result"];
9
-
10
- export async function render(ctx) {
11
- const { h, c } = ctx;
12
- const defsHost = h("div", c.loading({ lines: 3, block: true }));
13
- const runsHost = h("div", c.loading({ lines: 3 }));
14
- const triggerHost = h("div", c.loading({ lines: 2 }));
15
- const defsSrc = h("span", c.sourceBadge("pending"));
16
- const runsSrc = h("span", c.sourceBadge("pending"));
17
-
18
- const root = h("div.lt3-stack-6",
19
- c.viewHeader({
20
- eyebrow: "Compute",
21
- title: "Workflow Agents",
22
- sub: "Repeatable automation: a trigger fires an agent chain that calls tools, reads and writes memory, and produces a result.",
23
- }),
24
- stageLegend(ctx),
25
- c.panel({
26
- eyebrow: "Triggers",
27
- title: "Trigger status",
28
- sub: "Interval and brain-event triggers armed from saved workflow definitions.",
29
- children: triggerHost,
30
- }),
31
- h("section", c.sectionHead("Workflow definitions", defsSrc), defsHost),
32
- c.panel({
33
- head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
34
- h("div", h("div.lt3-eyebrow", "Activity"), h("h3.lt3-panel__title", "Recent runs")), runsSrc),
35
- children: runsHost,
36
- }),
37
- );
38
-
39
- loadDefs();
40
- loadTriggers();
41
- loadRuns();
42
- return root;
43
-
44
- function stageLegend(ctx2) {
45
- return h("div.lt3-cluster", { style: { gap: "var(--lt3-space-2)" } }, STAGES.map((s, i) =>
46
- h("div.lt3-row-2", { style: { gap: "var(--lt3-space-2)" } }, c.pill(s, i === STAGES.length - 1 ? "warn" : "info"), i < STAGES.length - 1 ? c.icon("arrow-right") : null)));
47
- }
48
-
49
- async function loadDefs() {
50
- const res = await ctx.api.workflowDefinitions();
51
- defsSrc.replaceChildren(c.sourceBadge(res.source));
52
- const defs = normalizeDefs(res.data);
53
- if (!defs.length) {
54
- defsHost.replaceChildren(c.emptyState({ icon: "sitemap", title: "No workflows yet", body: res.source === "live" ? "Create a workflow definition to automate an agent chain." : "Start the backend to load workflows." }));
55
- return;
56
- }
57
- defsHost.replaceChildren(h("div.lt3-grid-auto", defs.map((w) => defCard(ctx, w))));
58
- }
59
-
60
- function defCard(ctx2, w) {
61
- const nodes = w.nodes || (w.definition && w.definition.nodes) || [];
62
- const triggers = nodes.filter((n) => n.type === "trigger").length || 1;
63
- return c.card(h("div.lt3-stack-3",
64
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
65
- h("div", h("b", w.name || w.id), h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, w.id || "")),
66
- c.pill(`${nodes.length || 0} nodes`),
67
- ),
68
- w.description ? h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, w.description) : null,
69
- h("div.lt3-cluster", (nodes.slice(0, 6)).map((n) => h("span.lt3-chip", c.icon(nodeIcon(n.type)), n.name || n.type))),
70
- triggerControls(ctx2, w, nodes),
71
- h("div.lt3-row-2",
72
- h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => runDef(ctx2, w) } }, c.icon("player-play"), "Run"),
73
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${triggers} trigger${triggers === 1 ? "" : "s"}`),
74
- ),
75
- ), { interactive: false });
76
- }
77
-
78
- async function runDef(ctx2, w) {
79
- const res = await ctx2.api.runWorkflow(w.id, {});
80
- ctx2.toast(res && res.ok ? `Ran ${w.name || w.id}` : "Run unavailable", res && res.ok ? "ok" : "err");
81
- loadRuns();
82
- }
83
-
84
- async function loadRuns() {
85
- const res = await ctx.api.workflowRuns();
86
- runsSrc.replaceChildren(c.sourceBadge(res.source));
87
- const runs = normalizeRuns(res.data);
88
- if (!runs.length) {
89
- runsHost.replaceChildren(c.emptyState({ icon: "history-off", title: "No runs yet", body: "Workflow runs will appear here once a workflow executes." }));
90
- return;
91
- }
92
- runsHost.replaceChildren(c.table(
93
- [
94
- { key: "status", label: "Status", width: "1%", render: (r) => c.statePill(mapStatus(r.status)) },
95
- { key: "name", label: "Workflow", render: (r) => h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, r.workflow_name || r.workflow_id || r.id) },
96
- { key: "when", label: "When", width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap", "font-size": "var(--lt3-text-2xs)" } }, fmtTime(r.created_at || r.started_at)) },
97
- { key: "act", label: "", width: "1%", render: (r) => h("div.lt3-row-2",
98
- isActiveStatus(r.status) ? h("button.lt3-btn.lt3-btn--danger.lt3-btn--sm", { on: { click: () => stop(ctx, r) } }, c.icon("player-stop"), "Stop") : null,
99
- String(r.status || "").toLowerCase() === "awaiting_approval"
100
- ? h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => decide(ctx, r, true) } }, c.icon("circle-check"), "Approve")
101
- : null,
102
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => replay(ctx, r) } }, c.icon("player-track-next"), "Replay"),
103
- ) },
104
- ],
105
- runs.slice(0, 20),
106
- ));
107
- }
108
-
109
- async function replay(ctx2, r) {
110
- const id = r.id || r.run_id;
111
- const res = await ctx2.api.workflowReplay(id);
112
- ctx2.toast(res && res.ok ? `Replay ready for ${id}` : "Replay unavailable", res && res.ok ? "ok" : "err");
113
- }
114
-
115
- async function stop(ctx2, r) {
116
- const id = r.id || r.run_id;
117
- const res = await ctx2.api.stopWorkflowRun(id);
118
- ctx2.toast(res && res.ok ? `Stop requested for ${id}` : "Stop unavailable", res && res.ok ? "ok" : "err");
119
- loadRuns();
120
- }
121
-
122
- async function decide(ctx2, r, approved) {
123
- const id = r.id || r.run_id;
124
- const res = await ctx2.api.resumeWorkflowRun(id, approved);
125
- ctx2.toast(res && res.ok ? `Decision recorded for ${id}` : "Decision unavailable", res && res.ok ? "ok" : "err");
126
- loadRuns();
127
- }
128
-
129
- async function loadTriggers() {
130
- const res = await ctx.api.workflowTriggers();
131
- const armed = Array.isArray(res.data?.armed) ? res.data.armed : [];
132
- triggerHost.replaceChildren(
133
- h("div.lt3-stack-3",
134
- h("div.lt3-row-2", c.sourceBadge(res.source), c.statePill(res.data?.running ? "running" : "idle")),
135
- armed.length ? c.table([
136
- { key: "name", label: "Workflow", render: (r) => h("b", r.name || r.workflow_id) },
137
- { key: "kind", label: "Trigger", width: "1%", render: (r) => c.pill(r.kind) },
138
- { key: "last", label: "Last fired", width: "1%", render: (r) => fmtTime(r.last_fired_at ? Number(r.last_fired_at) * 1000 : null) },
139
- { key: "events", label: "Recent", render: (r) => (r.recent_events || []).slice(-2).map((e) => e.type || e.trigger).join(", ") || "—" },
140
- ], armed) : c.emptyState({ icon: "bolt-off", title: "No triggers armed", body: "Set a workflow trigger below to arm it." }),
141
- ),
142
- );
143
- }
144
-
145
- function triggerControls(ctx2, w, nodes) {
146
- const trigger = nodes.find((n) => n.type === "trigger") || {};
147
- const cfg = trigger.config || {};
148
- const kind = h("select.lt3-select", { "aria-label": "Trigger type" },
149
- ["manual", "interval", "brain_event"].map((value) => h("option", { value, selected: String(cfg.trigger || "manual") === value }, value)));
150
- const seconds = h("input.lt3-input", { type: "number", min: "60", step: "60", value: String(cfg.interval_seconds || 300), "aria-label": "Interval seconds" });
151
- const sourceType = h("input.lt3-input", { type: "text", value: cfg.source_type || "", placeholder: "source_type", "aria-label": "source_type" });
152
- async function save() {
153
- const updated = ensureTrigger(nodes, kind.value, Number(seconds.value) || 300, sourceType.value.trim());
154
- const res = await ctx2.api.updateWorkflow(w.id, { nodes: updated, metadata: { trigger_updated_at: new Date().toISOString() } });
155
- ctx2.toast(res && res.ok ? "Trigger saved" : "Trigger update unavailable", res && res.ok ? "ok" : "err");
156
- if (res && res.ok) { loadDefs(); loadTriggers(); }
157
- }
158
- return h("div.lt3-stack-2",
159
- h("div.lt3-eyebrow", "Trigger configuration"),
160
- h("div.lt3-row-2", kind, seconds, sourceType, h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: save } }, c.icon("device-floppy"), "Save")),
161
- );
162
- }
163
- }
164
-
165
- function ensureTrigger(nodes, triggerKind, intervalSeconds, sourceType) {
166
- const clone = (nodes || []).map((node) => ({ ...node, config: { ...(node.config || {}) } }));
167
- let trigger = clone.find((n) => n.type === "trigger");
168
- if (!trigger) {
169
- trigger = { id: "trigger", type: "trigger", name: "Trigger", next: clone[0]?.id || "output", config: {} };
170
- clone.unshift(trigger);
171
- if (!clone.some((n) => n.id === "output")) clone.push({ id: "output", type: "output", name: "Output", config: {}, next: null });
172
- }
173
- trigger.config.trigger = triggerKind;
174
- delete trigger.config.interval_seconds;
175
- delete trigger.config.source_type;
176
- if (triggerKind === "interval") trigger.config.interval_seconds = Math.max(60, intervalSeconds || 300);
177
- if (triggerKind === "brain_event" && sourceType) trigger.config.source_type = sourceType;
178
- return clone;
179
- }
180
-
181
- function normalizeDefs(data) {
182
- if (!data) return [];
183
- if (Array.isArray(data.workflows)) return data.workflows;
184
- if (Array.isArray(data.definitions)) return data.definitions;
185
- if (Array.isArray(data)) return data;
186
- return [];
187
- }
188
- function normalizeRuns(data) {
189
- if (!data) return [];
190
- if (Array.isArray(data.runs)) return data.runs;
191
- if (Array.isArray(data)) return data;
192
- return [];
193
- }
194
- function nodeIcon(type) {
195
- return { trigger: "bolt", agent: "robot", plugin: "puzzle", tool: "tool", output: "flag", memory: "brain" }[type] || "point";
196
- }
197
- function mapStatus(s) {
198
- const v = String(s || "").toLowerCase();
199
- if (v === "ok" || v === "completed" || v === "success") return "ready";
200
- if (v === "failed" || v === "error") return "failed";
201
- if (v === "running" || v === "queued" || v === "cancelling") return "active";
202
- if (v === "awaiting_approval") return "pending";
203
- if (v === "cancelled" || v === "interrupted") return "warn";
204
- return v || "idle";
205
- }
206
- function isActiveStatus(status) {
207
- return ["running", "queued", "in_progress", "cancelling"].includes(String(status || "").toLowerCase());
208
- }
209
- function fmtTime(ts) {
210
- if (!ts) return "—";
211
- try { const d = new Date(ts); return Number.isNaN(d.getTime()) ? String(ts) : d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }); }
212
- catch { return String(ts); }
213
- }