ltcai 4.0.0 → 4.1.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 (195) hide show
  1. package/README.md +42 -33
  2. package/desktop/electron/main.cjs +44 -0
  3. package/docs/CHANGELOG.md +106 -0
  4. package/docs/REALTIME_COLLABORATION.md +3 -3
  5. package/docs/V3_FRONTEND.md +9 -8
  6. package/docs/V4_1_FRONTEND_ARCHITECTURE_REVIEW.md +65 -0
  7. package/docs/V4_1_FRONTEND_MIGRATION_REPORT.md +70 -0
  8. package/docs/V4_1_VALIDATION_REPORT.md +47 -0
  9. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +95 -45
  10. package/docs/kg-schema.md +6 -2
  11. package/docs/spec-vs-impl.md +10 -10
  12. package/frontend/index.html +24 -0
  13. package/frontend/openapi.json +14190 -0
  14. package/frontend/src/App.tsx +184 -0
  15. package/frontend/src/api/client.ts +317 -0
  16. package/frontend/src/api/openapi.ts +16637 -0
  17. package/frontend/src/components/primitives.tsx +204 -0
  18. package/frontend/src/components/ui/badge.tsx +27 -0
  19. package/frontend/src/components/ui/button.tsx +37 -0
  20. package/frontend/src/components/ui/card.tsx +22 -0
  21. package/frontend/src/components/ui/input.tsx +16 -0
  22. package/frontend/src/components/ui/textarea.tsx +16 -0
  23. package/frontend/src/lib/utils.ts +33 -0
  24. package/frontend/src/main.tsx +23 -0
  25. package/frontend/src/pages/Act.tsx +245 -0
  26. package/frontend/src/pages/Ask.tsx +200 -0
  27. package/frontend/src/pages/Brain.tsx +267 -0
  28. package/frontend/src/pages/Capture.tsx +158 -0
  29. package/frontend/src/pages/Library.tsx +187 -0
  30. package/frontend/src/pages/System.tsx +344 -0
  31. package/frontend/src/routes.ts +85 -0
  32. package/frontend/src/store/appStore.ts +54 -0
  33. package/frontend/src/styles.css +107 -0
  34. package/kg_schema.py +2 -603
  35. package/knowledge_graph.py +37 -4958
  36. package/latticeai/__init__.py +1 -1
  37. package/latticeai/api/admin.py +15 -16
  38. package/latticeai/api/agents.py +13 -6
  39. package/latticeai/api/auth.py +19 -11
  40. package/latticeai/api/invitations.py +100 -0
  41. package/latticeai/api/knowledge_graph.py +4 -11
  42. package/latticeai/api/plugins.py +3 -6
  43. package/latticeai/api/realtime.py +4 -7
  44. package/latticeai/api/setup.py +5 -4
  45. package/latticeai/api/static_routes.py +13 -16
  46. package/latticeai/api/ui_redirects.py +26 -0
  47. package/latticeai/api/workflow_designer.py +39 -6
  48. package/latticeai/api/workspace.py +24 -10
  49. package/latticeai/app_factory.py +88 -17
  50. package/latticeai/brain/_kg_common.py +1123 -0
  51. package/latticeai/brain/discovery.py +1455 -0
  52. package/latticeai/brain/documents.py +218 -0
  53. package/latticeai/brain/ingest.py +644 -0
  54. package/latticeai/brain/projection.py +561 -0
  55. package/latticeai/brain/provenance.py +401 -0
  56. package/latticeai/brain/retrieval.py +1316 -0
  57. package/latticeai/brain/schema.py +640 -0
  58. package/latticeai/brain/store.py +216 -0
  59. package/latticeai/brain/write_master.py +225 -0
  60. package/latticeai/core/invitations.py +131 -0
  61. package/latticeai/core/marketplace.py +1 -1
  62. package/latticeai/core/multi_agent.py +1 -1
  63. package/latticeai/core/policy.py +54 -0
  64. package/latticeai/core/realtime.py +65 -44
  65. package/latticeai/core/sessions.py +31 -5
  66. package/latticeai/core/users.py +147 -0
  67. package/latticeai/core/workspace_os.py +420 -20
  68. package/latticeai/services/agent_runtime.py +242 -4
  69. package/latticeai/services/run_executor.py +328 -0
  70. package/latticeai/services/workspace_service.py +27 -19
  71. package/package.json +54 -27
  72. package/scripts/build_frontend_assets.mjs +38 -0
  73. package/scripts/bump_version.py +1 -1
  74. package/scripts/export_openapi.py +31 -0
  75. package/scripts/lint_frontend.mjs +86 -0
  76. package/scripts/run_python.mjs +47 -0
  77. package/src-tauri/Cargo.lock +4833 -0
  78. package/src-tauri/Cargo.toml +19 -0
  79. package/src-tauri/build.rs +3 -0
  80. package/src-tauri/capabilities/default.json +7 -0
  81. package/src-tauri/src/main.rs +78 -0
  82. package/src-tauri/tauri.conf.json +36 -0
  83. package/static/app/asset-manifest.json +32 -0
  84. package/static/app/assets/core-CwxXejkd.js +2 -0
  85. package/static/app/assets/core-CwxXejkd.js.map +1 -0
  86. package/static/app/assets/index-CJRAzNnf.js +333 -0
  87. package/static/app/assets/index-CJRAzNnf.js.map +1 -0
  88. package/static/app/assets/index-CSwBBgf4.css +2 -0
  89. package/static/app/index.html +25 -0
  90. package/static/manifest.json +2 -2
  91. package/static/sw.js +4 -4
  92. package/scripts/build_v3_assets.mjs +0 -170
  93. package/scripts/lint_v3.mjs +0 -97
  94. package/static/account.html +0 -113
  95. package/static/activity.html +0 -73
  96. package/static/admin.html +0 -486
  97. package/static/agents.html +0 -139
  98. package/static/chat.html +0 -841
  99. package/static/css/reference/account.css +0 -439
  100. package/static/css/reference/admin.css +0 -610
  101. package/static/css/reference/base.css +0 -1661
  102. package/static/css/reference/chat.css +0 -4623
  103. package/static/css/reference/graph.css +0 -1016
  104. package/static/css/responsive.css +0 -861
  105. package/static/graph.html +0 -122
  106. package/static/platform.css +0 -104
  107. package/static/plugins.html +0 -136
  108. package/static/scripts/account.js +0 -238
  109. package/static/scripts/admin.js +0 -1614
  110. package/static/scripts/chat.js +0 -5081
  111. package/static/scripts/graph.js +0 -1804
  112. package/static/scripts/platform.js +0 -64
  113. package/static/scripts/ux.js +0 -167
  114. package/static/scripts/workspace.js +0 -948
  115. package/static/v3/asset-manifest.json +0 -56
  116. package/static/v3/css/lattice.base.49deefb5.css +0 -128
  117. package/static/v3/css/lattice.base.css +0 -128
  118. package/static/v3/css/lattice.components.cde18231.css +0 -472
  119. package/static/v3/css/lattice.components.css +0 -472
  120. package/static/v3/css/lattice.shell.29d36d85.css +0 -452
  121. package/static/v3/css/lattice.shell.css +0 -452
  122. package/static/v3/css/lattice.tokens.304cbc40.css +0 -135
  123. package/static/v3/css/lattice.tokens.css +0 -135
  124. package/static/v3/css/lattice.views.0a18b6c5.css +0 -360
  125. package/static/v3/css/lattice.views.css +0 -360
  126. package/static/v3/index.html +0 -68
  127. package/static/v3/js/app.356e6452.js +0 -26
  128. package/static/v3/js/app.js +0 -26
  129. package/static/v3/js/core/api.7a308b89.js +0 -568
  130. package/static/v3/js/core/api.js +0 -568
  131. package/static/v3/js/core/components.f25b3b93.js +0 -230
  132. package/static/v3/js/core/components.js +0 -230
  133. package/static/v3/js/core/dom.a2773eb0.js +0 -148
  134. package/static/v3/js/core/dom.js +0 -148
  135. package/static/v3/js/core/router.584570f2.js +0 -37
  136. package/static/v3/js/core/router.js +0 -37
  137. package/static/v3/js/core/routes.7222343d.js +0 -93
  138. package/static/v3/js/core/routes.js +0 -93
  139. package/static/v3/js/core/shell.a1657f20.js +0 -391
  140. package/static/v3/js/core/shell.js +0 -391
  141. package/static/v3/js/core/store.204a08b2.js +0 -113
  142. package/static/v3/js/core/store.js +0 -113
  143. package/static/v3/js/views/admin-audit.660a1fb1.js +0 -185
  144. package/static/v3/js/views/admin-audit.js +0 -185
  145. package/static/v3/js/views/admin-permissions.a7ae5f09.js +0 -177
  146. package/static/v3/js/views/admin-permissions.js +0 -177
  147. package/static/v3/js/views/admin-policies.3658fd86.js +0 -102
  148. package/static/v3/js/views/admin-policies.js +0 -102
  149. package/static/v3/js/views/admin-private-vpc.7d342d36.js +0 -135
  150. package/static/v3/js/views/admin-private-vpc.js +0 -135
  151. package/static/v3/js/views/admin-security.07c66b72.js +0 -180
  152. package/static/v3/js/views/admin-security.js +0 -180
  153. package/static/v3/js/views/admin-users.03bac88c.js +0 -168
  154. package/static/v3/js/views/admin-users.js +0 -168
  155. package/static/v3/js/views/agents.014d0b74.js +0 -541
  156. package/static/v3/js/views/agents.js +0 -541
  157. package/static/v3/js/views/chat.e6dd7dd0.js +0 -601
  158. package/static/v3/js/views/chat.js +0 -601
  159. package/static/v3/js/views/files.adad14c1.js +0 -365
  160. package/static/v3/js/views/files.js +0 -365
  161. package/static/v3/js/views/graph-canvas.17c15d65.js +0 -509
  162. package/static/v3/js/views/graph-canvas.js +0 -509
  163. package/static/v3/js/views/home.24f8b8ae.js +0 -200
  164. package/static/v3/js/views/home.js +0 -200
  165. package/static/v3/js/views/hooks.37895880.js +0 -220
  166. package/static/v3/js/views/hooks.js +0 -220
  167. package/static/v3/js/views/hybrid-search.2fb63ed9.js +0 -194
  168. package/static/v3/js/views/hybrid-search.js +0 -194
  169. package/static/v3/js/views/knowledge-graph.5e40cbeb.js +0 -509
  170. package/static/v3/js/views/knowledge-graph.js +0 -509
  171. package/static/v3/js/views/marketplace.ab0583d4.js +0 -141
  172. package/static/v3/js/views/marketplace.js +0 -141
  173. package/static/v3/js/views/mcp.99b5c6a7.js +0 -114
  174. package/static/v3/js/views/mcp.js +0 -114
  175. package/static/v3/js/views/memory.4ebdf474.js +0 -147
  176. package/static/v3/js/views/memory.js +0 -147
  177. package/static/v3/js/views/models.a1ffa147.js +0 -256
  178. package/static/v3/js/views/models.js +0 -256
  179. package/static/v3/js/views/my-computer.d9d9ae1c.js +0 -463
  180. package/static/v3/js/views/my-computer.js +0 -463
  181. package/static/v3/js/views/pipeline.c522f1ce.js +0 -157
  182. package/static/v3/js/views/pipeline.js +0 -157
  183. package/static/v3/js/views/planning.9ac3e313.js +0 -153
  184. package/static/v3/js/views/planning.js +0 -153
  185. package/static/v3/js/views/settings.8631fa5e.js +0 -318
  186. package/static/v3/js/views/settings.js +0 -318
  187. package/static/v3/js/views/skills.c6c2f965.js +0 -109
  188. package/static/v3/js/views/skills.js +0 -109
  189. package/static/v3/js/views/tools.e4f11276.js +0 -108
  190. package/static/v3/js/views/tools.js +0 -108
  191. package/static/v3/js/views/workflows.26c57290.js +0 -128
  192. package/static/v3/js/views/workflows.js +0 -128
  193. package/static/workflows.html +0 -146
  194. package/static/workspace.css +0 -1121
  195. package/static/workspace.html +0 -357
@@ -1,509 +0,0 @@
1
- /* ============================================================================
2
- * View: Knowledge Graph — the user's digital brain (v3.6.0 Knowledge Graph First).
3
- * Tabs: Explore (entity/relation mesh) · Status (graph + ingestion health) ·
4
- * Sources (where every node came from) · Capture (web/URL into the graph) ·
5
- * Backup (local export / import / backup). Everything you ingest converges here;
6
- * models read this graph; local-first keeps it yours. Missing data renders an
7
- * honest unavailable state — never fabricated counters.
8
- * ========================================================================== */
9
-
10
- import { escapeHtml } from "../core/dom.js";
11
- import { createGraphCanvas } from "./graph-canvas.js";
12
-
13
- const TYPE_COLOR = {
14
- Topic: "var(--lt3-pillar-graph)",
15
- Concept: "var(--lt3-pillar-vector)",
16
- Method: "var(--lt3-pillar-hybrid)",
17
- Model: "var(--accent-3)",
18
- File: "var(--faint)",
19
- Source: "var(--lt3-pillar-hybrid)",
20
- Document: "var(--accent)",
21
- Decision: "var(--accent-3)",
22
- Task: "var(--accent-2)",
23
- Person: "var(--accent-pink)",
24
- default: "var(--accent)",
25
- };
26
- const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
27
-
28
- const TABS = [
29
- { key: "explore", label: "Explore", icon: "chart-dots-3" },
30
- { key: "status", label: "Status", icon: "activity-heartbeat" },
31
- { key: "sources", label: "Sources", icon: "database" },
32
- { key: "capture", label: "Capture", icon: "world-www" },
33
- { key: "portability", label: "Backup", icon: "archive" },
34
- ];
35
-
36
- export async function render(ctx) {
37
- const { h, icon, api, c } = ctx;
38
- let active = "explore";
39
-
40
- const tabBar = h("div.lt3-row-2");
41
- const panelHost = h("div.lt3-stack-4");
42
-
43
- function renderTabs() {
44
- tabBar.replaceChildren(...TABS.map((t) =>
45
- h("button.lt3-btn" + (t.key === active ? ".lt3-btn--primary" : ".lt3-btn--ghost"),
46
- { on: { click: () => switchTab(t.key) } }, icon(t.icon), t.label)));
47
- }
48
-
49
- function switchTab(key) {
50
- if (active === key) return;
51
- active = key;
52
- renderTabs();
53
- renderActive();
54
- }
55
-
56
- let exploreNode = null;
57
- function renderActive() {
58
- if (active === "explore") {
59
- if (!exploreNode) exploreNode = buildExplore(ctx);
60
- panelHost.replaceChildren(exploreNode);
61
- } else if (active === "status") {
62
- renderStatus(ctx, panelHost);
63
- } else if (active === "sources") {
64
- renderSources(ctx, panelHost);
65
- } else if (active === "capture") {
66
- panelHost.replaceChildren(buildCapture(ctx));
67
- } else if (active === "portability") {
68
- renderPortability(ctx, panelHost);
69
- }
70
- }
71
-
72
- const root = h("div.lt3-stack-6",
73
- c.viewHeader({
74
- eyebrow: "Your digital brain",
75
- title: "Knowledge Graph",
76
- sub: "Everything you ingest converges here — files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
77
- actions: [
78
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
79
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
80
- ],
81
- }),
82
- tabBar,
83
- panelHost,
84
- );
85
-
86
- renderTabs();
87
- renderActive();
88
- return root;
89
- }
90
-
91
- /* ── Explore tab (entity/relation mesh) ─────────────────────────────────── */
92
- function buildExplore(ctx) {
93
- const { h, icon, api, c } = ctx;
94
- const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
95
-
96
- const canvasHost = h("div", c.loading({ lines: 0, block: true }));
97
- const inspectorHost = h("div", c.loading({ lines: 4 }));
98
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
99
- const srcSlot = h("span", c.sourceBadge("pending"));
100
-
101
- const root = h("div.lt3-stack-3",
102
- h("div.lt3-row-2",
103
- srcSlot,
104
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
105
- ),
106
- statHost,
107
- h("div.lt3-split",
108
- h("div.lt3-stack-3",
109
- c.card(canvasHost, { attrs: { style: "padding:0;overflow:hidden" } }),
110
- buildLegend(ctx),
111
- ),
112
- h("aside.lt3-panel",
113
- h("div.lt3-panel__head", h("div", h("div.lt3-eyebrow", "Inspector"), h("h3.lt3-panel__title", "Entities"))),
114
- h("div.lt3-search", { style: { "margin-bottom": "var(--lt3-space-4)" } },
115
- icon("search"),
116
- h("input", { type: "text", placeholder: "Filter entities…", "aria-label": "Filter entities",
117
- on: { input: (e) => { state.query = e.target.value.toLowerCase(); renderInspector(); } } }),
118
- ),
119
- inspectorHost,
120
- ),
121
- ),
122
- );
123
-
124
- async function load() {
125
- canvasHost.replaceChildren(c.loading({ lines: 0, block: true }));
126
- const [g, stats] = await Promise.all([api.graph(), api.graphStats()]);
127
- state.data = normalize(g.data);
128
- state.source = g.source;
129
- srcSlot.replaceChildren(c.sourceBadge(g.source));
130
- renderStats(stats.data, g.data);
131
- renderCanvas();
132
- renderInspector();
133
- }
134
-
135
- function renderStats(stats) {
136
- const nodes = state.data.nodes.length;
137
- const edges = state.data.edges.length;
138
- const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
139
- const density = nodes > 1 ? (edges / (nodes * (nodes - 1) / 2)) : 0;
140
- statHost.replaceChildren(
141
- c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
142
- c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
143
- c.stat({ label: "Entity types", value: types, icon: "category" }),
144
- c.stat({ label: "Density", value: density.toFixed(2), icon: "chart-dots" }),
145
- );
146
- }
147
-
148
- // Live force-directed canvas (zoom / pan / drag / physics) — replaces the
149
- // static SVG spiral. The renderer only draws the data it is given.
150
- let graphCanvas = null;
151
-
152
- function ensureGraphCanvas() {
153
- if (graphCanvas) return graphCanvas;
154
- graphCanvas = createGraphCanvas({
155
- colorFor,
156
- onSelect: (id) => {
157
- state.selected = id;
158
- renderInspector();
159
- },
160
- });
161
- return graphCanvas;
162
- }
163
-
164
- function renderCanvas() {
165
- const { nodes, edges } = state.data;
166
- if (!nodes.length) {
167
- if (graphCanvas) { graphCanvas.destroy(); graphCanvas = null; }
168
- canvasHost.replaceChildren(c.emptyState({ icon: "chart-dots-3", title: "No entities yet", body: "Index a source to populate the graph." }));
169
- return;
170
- }
171
- const gc = ensureGraphCanvas();
172
- gc.setData({ nodes, edges });
173
- gc.setSelected(state.selected);
174
- if (!gc.el.isConnected || gc.el.parentElement !== canvasHost.querySelector(".lt3-graph-canvas")) {
175
- canvasHost.replaceChildren(h("div.lt3-graph-canvas", gc.el));
176
- }
177
- }
178
-
179
- function syncSelection() {
180
- if (graphCanvas) graphCanvas.setSelected(state.selected);
181
- renderInspector();
182
- }
183
-
184
- function renderInspector() {
185
- if (state.selected) { inspectorHost.replaceChildren(detailView()); return; }
186
- const q = state.query;
187
- const list = state.data.nodes
188
- .filter((n) => !q || (n.label || "").toLowerCase().includes(q) || (n.type || "").toLowerCase().includes(q))
189
- .sort((a, b) => (b.weight || 0) - (a.weight || 0));
190
- inspectorHost.replaceChildren(
191
- list.length
192
- ? h("div.lt3-stack-2", list.slice(0, 60).map((n) => entityRow(n)))
193
- : c.emptyState({ icon: "search-off", title: "No matches", body: "Try a different entity name." }),
194
- );
195
- }
196
-
197
- function entityRow(n) {
198
- return h("button.lt3-entity", { on: { click: () => { state.selected = n.id; syncSelection(); } } },
199
- h("div.lt3-entity__type", { style: { background: `color-mix(in srgb, ${colorFor(n.type)} 18%, transparent)`, color: colorFor(n.type) } }, icon(iconForType(n.type))),
200
- h("div.lt3-entity__body",
201
- h("div.lt3-entity__name", n.label),
202
- h("div.lt3-entity__meta", `${n.type || "Entity"} · weight ${(n.weight || 0).toFixed(2)}`),
203
- ),
204
- );
205
- }
206
-
207
- function detailView() {
208
- const n = state.data.nodes.find((x) => x.id === state.selected);
209
- if (!n) { state.selected = null; return c.emptyState({ title: "Not found" }); }
210
- const rels = state.data.edges
211
- .filter((e) => e.from === n.id || e.to === n.id)
212
- .map((e) => {
213
- const otherId = e.from === n.id ? e.to : e.from;
214
- const other = state.data.nodes.find((x) => x.id === otherId);
215
- return { type: e.type, dir: e.from === n.id ? "→" : "←", other };
216
- })
217
- .filter((r) => r.other);
218
- return h("div.lt3-stack-4",
219
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null; syncSelection(); } } }, icon("arrow-left"), "All entities"),
220
- h("div.lt3-card.lt3-card--flat",
221
- h("div.lt3-row-2", { style: { "margin-bottom": "var(--lt3-space-2)" } },
222
- h("span.lt3-pill", { style: { color: colorFor(n.type) } }, n.type || "Entity"),
223
- ),
224
- h("div", { style: { "font-size": "var(--lt3-text-lg)", "font-weight": 700 } }, n.label),
225
- n.summary && h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-2)" } }, n.summary),
226
- ),
227
- h("div",
228
- h("div.lt3-eyebrow", { style: { "margin-bottom": "var(--lt3-space-2)" } }, `Relations (${rels.length})`),
229
- rels.length
230
- ? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id; syncSelection(); } } },
231
- h("div.lt3-entity__type", { style: { background: "var(--surface-3)" } }, h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, r.dir)),
232
- h("div.lt3-entity__body",
233
- h("div.lt3-entity__name", r.other.label),
234
- h("div.lt3-entity__meta", r.type),
235
- ),
236
- )))
237
- : c.emptyState({ icon: "unlink", title: "No relations", body: "This entity is currently isolated." }),
238
- ),
239
- );
240
- }
241
-
242
- load();
243
- return root;
244
- }
245
-
246
- /* ── Status tab (graph + ingestion health) ──────────────────────────────── */
247
- async function renderStatus(ctx, host) {
248
- const { h, icon, api, c } = ctx;
249
- host.replaceChildren(c.loading({ lines: 3 }));
250
- const [port, gs, idx] = await Promise.all([api.kgPortability(), api.graphStats(), api.indexStatus()]);
251
- const p = port.data || {};
252
- const prov = p.provenance || {};
253
- const nodes = sumCounts((gs.data && gs.data.nodes) || {});
254
- const edges = sumCounts((gs.data && gs.data.edges) || {});
255
- const pipelines = (idx.data && idx.data.pipelines) || {};
256
-
257
- host.replaceChildren(
258
- h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } },
259
- p.graph_schema_version != null ? `Schema v${p.graph_schema_version} · embed dim ${p.embed_dim ?? "—"}` : "Knowledge Graph status")),
260
- h("div.lt3-statrow",
261
- c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
262
- c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
263
- c.stat({ label: "Ingested items", value: c.fmtNum(prov.total || 0), icon: "package-import" }),
264
- c.stat({ label: "Embedded (RAG-ready)", value: c.fmtNum(prov.embedded || 0), icon: "vector" }),
265
- ),
266
- c.card(
267
- h("div.lt3-stack-3",
268
- h("div.lt3-eyebrow", "Pipelines"),
269
- pipelineRow(ctx, "Knowledge graph", pipelines.knowledge_graph),
270
- pipelineRow(ctx, "Vector index", pipelines.vector_index),
271
- pipelineRow(ctx, "Hybrid retrieval", pipelines.hybrid),
272
- ),
273
- ),
274
- prov.last_ingested_at
275
- ? h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, `Last ingestion: ${fmtWhen(prov.last_ingested_at)} · ${prov.duplicates || 0} duplicate(s) linked, not re-stored.`)
276
- : c.emptyState({ icon: "package-import", title: "Nothing ingested yet", body: "Add files or capture a page to populate the graph." }),
277
- );
278
- }
279
-
280
- function pipelineRow(ctx, label, pipe) {
281
- const { h, c } = ctx;
282
- const stateStr = (pipe && pipe.state) || "unavailable";
283
- const detail = pipe && (pipe.entities != null ? `${pipe.entities} entities` : pipe.vectors != null ? `${pipe.vectors} vectors` : pipe.strategy || "");
284
- return h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
285
- h("div", label, detail ? h("span.lt3-muted", { style: { "margin-left": "var(--lt3-space-2)", "font-size": "var(--lt3-text-sm)" } }, detail) : null),
286
- c.statePill(stateStr),
287
- );
288
- }
289
-
290
- /* ── Sources tab (provenance: where every node came from) ────────────────── */
291
- async function renderSources(ctx, host) {
292
- const { h, icon, api, c } = ctx;
293
- host.replaceChildren(c.loading({ lines: 3 }));
294
- const [port, recent] = await Promise.all([api.kgPortability(), api.kgProvenance(40)]);
295
- const bySource = (port.data && port.data.provenance && port.data.provenance.by_source_type) || {};
296
- const items = (recent.data && recent.data.items) || [];
297
-
298
- const sourceCards = Object.keys(bySource).length
299
- ? h("div.lt3-statrow", Object.entries(bySource).map(([k, v]) =>
300
- c.stat({ label: prettySource(k), value: c.fmtNum(v), icon: iconForSource(k) })))
301
- : c.emptyState({ icon: "database", title: "No sources yet", body: "Connect a folder, upload a file, or capture a page." });
302
-
303
- const recentList = items.length
304
- ? h("div.lt3-stack-2", items.map((it) =>
305
- h("div.lt3-entity",
306
- h("div.lt3-entity__type", { style: { background: "var(--surface-3)", color: colorFor("Source") } }, icon(iconForSource(it.source_type))),
307
- h("div.lt3-entity__body",
308
- h("div.lt3-entity__name", it.title || it.source_uri || it.node_id),
309
- h("div.lt3-entity__meta", `${prettySource(it.source_type)} · ${fmtWhen(it.created_at)}${it.embedded ? " · embedded" : ""}${it.duplicate ? " · duplicate" : ""}`),
310
- ),
311
- )))
312
- : c.emptyState({ icon: "history", title: "No recent ingestions", body: "Ingested items will appear here with full provenance." });
313
-
314
- host.replaceChildren(
315
- h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Every node records where it came from (provenance).")),
316
- sourceCards,
317
- c.card(h("div.lt3-stack-3", h("div.lt3-eyebrow", "Recent ingestions"), recentList)),
318
- );
319
- }
320
-
321
- /* ── Capture tab (web/URL into the graph) ───────────────────────────────── */
322
- function buildCapture(ctx) {
323
- const { h, icon, api, c } = ctx;
324
- const input = h("input", { type: "url", placeholder: "https://example.com/article", "aria-label": "URL to capture",
325
- style: { flex: "1" } });
326
- const result = h("div");
327
-
328
- async function run() {
329
- const url = (input.value || "").trim();
330
- if (!url) { result.replaceChildren(c.banner({ tone: "warn", text: "Enter a URL first." })); return; }
331
- result.replaceChildren(c.loading({ lines: 1 }));
332
- const res = await api.browserReadUrl(url);
333
- const d = res.data || {};
334
- if (res.ok && d.status === "ok") {
335
- result.replaceChildren(c.banner({ tone: "ok", text: `Added to your Knowledge Graph${d.duplicate ? " (already present — linked)" : ""}. ${d.chunk_count || 0} chunk(s) indexed.` }));
336
- ctx.toast && ctx.toast("Page added to Knowledge Graph");
337
- } else if (d.status === "empty") {
338
- result.replaceChildren(c.banner({ tone: "warn", text: "No readable text was found on that page." }));
339
- } else {
340
- const detail = d.detail || (res.status === 422 ? "The page is blocked or login-required." : "Could not read that URL.");
341
- result.replaceChildren(c.banner({ tone: "err", text: detail }));
342
- }
343
- }
344
-
345
- return h("div.lt3-stack-4",
346
- c.card(h("div.lt3-stack-3",
347
- h("div.lt3-eyebrow", "Capture a web page"),
348
- h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The local runtime fetches the page, extracts readable text, and indexes it into your graph as a web source. Nothing is sent to a cloud service."),
349
- h("div.lt3-row-2",
350
- input,
351
- h("button.lt3-btn.lt3-btn--primary", { on: { click: run } }, icon("world-download"), "Read into graph"),
352
- ),
353
- result,
354
- )),
355
- c.card(h("div.lt3-stack-2",
356
- h("div.lt3-eyebrow", "Browser extension"),
357
- h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Install the local Manifest V3 extension (browser-extension/) to send the current tab to your Knowledge Graph with one click. It posts only to 127.0.0.1 — never to a cloud server."),
358
- )),
359
- );
360
- }
361
-
362
- /* ── Portability tab (export / import / backup) ─────────────────────────── */
363
- async function renderPortability(ctx, host) {
364
- const { h, icon, api, c } = ctx;
365
- host.replaceChildren(c.loading({ lines: 2 }));
366
- const port = await api.kgPortability();
367
- const status = h("div");
368
-
369
- function note(tone, text) { status.replaceChildren(c.banner({ tone, text })); }
370
-
371
- async function doExport() {
372
- note("info", "Exporting…");
373
- const res = await api.graphExport();
374
- if (!res.ok || !res.data || res.data.raw) { note("err", "Export is unavailable."); return; }
375
- try {
376
- const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
377
- const url = URL.createObjectURL(blob);
378
- const a = document.createElement("a");
379
- a.href = url; a.download = "lattice-kg-export.json"; a.click();
380
- URL.revokeObjectURL(url);
381
- note("ok", `Exported ${(res.data.counts && res.data.counts.nodes) || 0} nodes. Download started.`);
382
- } catch (e) { note("err", "Could not build the download."); }
383
- }
384
-
385
- async function doBackup() {
386
- note("info", "Backing up…");
387
- const res = await api.graphBackup();
388
- if (res.ok && res.data && res.data.path) {
389
- note("ok", `Backup written locally: ${res.data.path}`);
390
- } else {
391
- note("err", (res.data && (res.data.detail || res.data.error)) || "Backup requires admin and a running runtime.");
392
- }
393
- }
394
-
395
- const importArea = h("textarea", { rows: 5, placeholder: "Paste a Knowledge Graph export (JSON) to validate, then import…",
396
- "aria-label": "Import artifact", style: { width: "100%", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } });
397
-
398
- async function doImport(dryRun) {
399
- let artifact;
400
- try { artifact = JSON.parse(importArea.value || ""); }
401
- catch { note("err", "That is not valid JSON."); return; }
402
- note("info", dryRun ? "Validating…" : "Importing…");
403
- const res = await api.graphImport(artifact, "merge", dryRun);
404
- if (res.ok && res.data && !res.data.detail) {
405
- const d = res.data;
406
- note("ok", dryRun
407
- ? `Valid — would import ${d.nodes || 0} nodes, ${d.edges || 0} edges.`
408
- : `Imported ${d.nodes || 0} nodes, ${d.edges || 0} edges.`);
409
- } else {
410
- note("err", (res.data && (res.data.detail || res.data.error)) || "Import requires admin.");
411
- }
412
- }
413
-
414
- const p = port.data || {};
415
- host.replaceChildren(
416
- h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The Knowledge Graph is your durable asset — portable with no cloud.")),
417
- c.card(h("div.lt3-stack-3",
418
- h("div.lt3-eyebrow", "Export & backup"),
419
- h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Export a portable JSON of nodes/edges/provenance, or write a full local binary backup (DB + blobs)."),
420
- h("div.lt3-row-2",
421
- h("button.lt3-btn.lt3-btn--primary", { on: { click: doExport } }, icon("download"), "Export JSON"),
422
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: doBackup } }, icon("archive"), "Backup (admin)"),
423
- ),
424
- )),
425
- c.card(h("div.lt3-stack-3",
426
- h("div.lt3-eyebrow", "Import"),
427
- importArea,
428
- h("div.lt3-row-2",
429
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => doImport(true) } }, icon("checks"), "Validate (dry-run)"),
430
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => doImport(false) } }, icon("file-import"), "Import (merge, admin)"),
431
- ),
432
- )),
433
- status,
434
- );
435
- }
436
-
437
- /* ── helpers ─────────────────────────────────────────────────────────────── */
438
- function sumCounts(obj) {
439
- return Object.values(obj || {}).reduce((a, b) => a + (Number(b) || 0), 0);
440
- }
441
-
442
- function prettySource(k) {
443
- return ({ web_url: "Web URL", browser_tab: "Browser tab", file: "Files", local_file: "Local files",
444
- note: "Notes", text: "Text", markdown: "Markdown", code: "Code", upload: "Uploads" })[k] || k;
445
- }
446
-
447
- function iconForSource(k) {
448
- return ({ web_url: "world", browser_tab: "browser", file: "file", local_file: "folder",
449
- note: "note", text: "text-caption", markdown: "markdown", code: "code", upload: "upload" })[k] || "database";
450
- }
451
-
452
- function fmtWhen(iso) {
453
- if (!iso) return "—";
454
- try {
455
- const d = new Date(iso);
456
- if (isNaN(d.getTime())) return String(iso);
457
- return d.toLocaleString();
458
- } catch { return String(iso); }
459
- }
460
-
461
- function normalize(data) {
462
- const nodes = (data.nodes || []).map((n) => ({
463
- id: n.id,
464
- label: n.label || n.title || n.id,
465
- type: n.type || "Entity",
466
- weight: n.weight ?? n.importance_norm ?? (n.metadata && n.metadata.graph_metrics && n.metadata.graph_metrics.importance_norm) ?? 0.5,
467
- summary: n.summary || "",
468
- x: n.x, y: n.y,
469
- }));
470
- const ids = new Set(nodes.map((n) => n.id));
471
- const edges = (data.edges || []).filter((e) => ids.has(e.from) && ids.has(e.to))
472
- .map((e) => ({ from: e.from, to: e.to, type: e.type || "related", weight: e.weight || 1 }));
473
- return { nodes, edges };
474
- }
475
-
476
- function layout(nodes) {
477
- const W = 1000, H = 600, cx = W / 2, cy = H / 2;
478
- const golden = Math.PI * (3 - Math.sqrt(5));
479
- const hasCoords = nodes.length && nodes.every((n) => typeof n.x === "number" && typeof n.y === "number");
480
- if (hasCoords) {
481
- return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
482
- }
483
- const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
484
- const maxR = Math.min(W, H) * 0.42;
485
- const placed = {};
486
- order.forEach((o, rank) => {
487
- const radius = rank === 0 ? 0 : maxR * Math.sqrt(rank / Math.max(1, nodes.length - 1));
488
- const angle = rank * golden;
489
- placed[o.i] = {
490
- px: Math.round(cx + Math.cos(angle) * radius),
491
- py: Math.round(cy + Math.sin(angle) * radius * 0.66),
492
- };
493
- });
494
- return nodes.map((n, i) => ({ ...n, ...placed[i] }));
495
- }
496
-
497
- function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
498
-
499
- function iconForType(t) {
500
- return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Source: "world",
501
- Document: "file-text", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
502
- }
503
-
504
- function buildLegend({ h }) {
505
- const types = ["Source", "Document", "Concept", "Person", "Decision"];
506
- return h("div.lt3-graph-legend",
507
- types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
508
- );
509
- }
@@ -1,141 +0,0 @@
1
- /* ============================================================================
2
- * View: Marketplace — agent templates, plugins, and skills.
3
- * Templates come from /marketplace/templates (offline local catalog incl. the
4
- * five named agent templates). Install / Clone / Export use the real backend.
5
- * Plugins and skills marketplace read live directories; unavailable is shown
6
- * honestly with no fabricated catalog.
7
- * ========================================================================== */
8
-
9
- const KIND_VARIANT = { agent: "info", workflow: "warn", plugin: "" };
10
-
11
- export async function render(ctx) {
12
- const { h, c } = ctx;
13
- const body = h("div", c.loading({ lines: 4, block: true }));
14
- let tab = "templates";
15
-
16
- const tabsEl = c.tabs(
17
- [{ key: "templates", label: "Templates" }, { key: "plugins", label: "Plugins" }, { key: "skills", label: "Skills" }],
18
- tab, (k) => { tab = k; paint(); },
19
- );
20
-
21
- const root = h("div.lt3-stack-6",
22
- c.viewHeader({
23
- eyebrow: "Platform",
24
- title: "Marketplace",
25
- sub: "Reusable agent templates, plugins, and skills — install, clone, customize, export, and import, all from /app.",
26
- }),
27
- tabsEl,
28
- body,
29
- );
30
-
31
- paint();
32
- return root;
33
-
34
- function paint() {
35
- [...tabsEl.querySelectorAll(".lt3-tab")].forEach((b, i) => { b.dataset.active = String(["templates", "plugins", "skills"][i] === tab); });
36
- body.replaceChildren(c.loading({ lines: 3, block: true }));
37
- if (tab === "templates") return paintTemplates();
38
- if (tab === "plugins") return paintPlugins();
39
- return paintSkills();
40
- }
41
-
42
- async function paintTemplates() {
43
- const res = await ctx.api.templates();
44
- const list = (res.data && res.data.templates) || [];
45
- if (!list.length) {
46
- body.replaceChildren(stateRow(ctx, res.source), c.emptyState({ icon: "package-off", title: "Catalog unavailable", body: "Start the backend to load the template catalog." }));
47
- return;
48
- }
49
- const byKind = {};
50
- for (const t of list) (byKind[t.kind] = byKind[t.kind] || []).push(t);
51
- const sections = Object.keys(byKind).map((kind) =>
52
- h("section",
53
- c.sectionHead(`${cap(kind)} templates`, c.pill(String(byKind[kind].length))),
54
- h("div.lt3-grid-auto", byKind[kind].map((t) => templateCard(ctx, t))),
55
- ));
56
- body.replaceChildren(h("div.lt3-stack-6", stateRow(ctx, res.source), ...sections));
57
- }
58
-
59
- function templateCard(ctx2, t) {
60
- const def = t.definition || {};
61
- const caps = def.capabilities || def.roles || [];
62
- return c.card(h("div.lt3-stack-3",
63
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
64
- h("div", h("b", t.name), h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, t.id)),
65
- c.pill(t.kind, KIND_VARIANT[t.kind] || ""),
66
- ),
67
- h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, t.description || ""),
68
- caps.length ? h("div.lt3-cluster", caps.slice(0, 6).map((x) => h("span.lt3-chip", x))) : null,
69
- h("div.lt3-row-2",
70
- h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => install(ctx2, t) } }, c.icon("download"), "Install"),
71
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => clone(ctx2, t) } }, c.icon("copy"), "Clone"),
72
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => exportT(ctx2, t) } }, c.icon("file-export"), "Export"),
73
- ),
74
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `v${t.version || "1.0.0"} · ${(t.metadata && t.metadata.category) || "general"}`),
75
- ), { interactive: false });
76
- }
77
-
78
- async function install(ctx2, t) {
79
- const res = await ctx2.api.installTemplate(t);
80
- ctx2.toast(res && res.ok ? `Installed ${t.name}` : "Install unavailable", res && res.ok ? "ok" : "err");
81
- }
82
- async function clone(ctx2, t) {
83
- const res = await ctx2.api.cloneTemplate(t.kind, t.id, `${t.name} (Copy)`);
84
- ctx2.toast(res && res.ok ? `Cloned to ${res.data.template.id}` : "Clone unavailable", res && res.ok ? "ok" : "err");
85
- }
86
- async function exportT(ctx2, t) {
87
- const res = await ctx2.api.exportTemplate(t.kind, t.id);
88
- if (res && res.ok && res.data) {
89
- try {
90
- const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
91
- const a = document.createElement("a");
92
- a.href = URL.createObjectURL(blob); a.download = `${t.id}.template.json`; a.click();
93
- URL.revokeObjectURL(a.href);
94
- ctx2.toast("Exported template", "ok");
95
- } catch { ctx2.toast("Export failed", "err"); }
96
- } else { ctx2.toast("Export unavailable", "err"); }
97
- }
98
-
99
- async function paintPlugins() {
100
- const [reg, dir] = await Promise.all([ctx.api.pluginsRegistry(), ctx.api.pluginsDirectory()]);
101
- const installed = (reg.data && reg.data.plugins) || [];
102
- const directory = (dir.data && dir.data.plugins) || [];
103
- if (!installed.length && !directory.length) {
104
- body.replaceChildren(stateRow(ctx, reg.source), c.emptyState({ icon: "plug-off", title: "No plugins", body: "Plugin registry and directory are unavailable." }));
105
- return;
106
- }
107
- body.replaceChildren(h("div.lt3-stack-6",
108
- stateRow(ctx, reg.source),
109
- h("section", c.sectionHead("Installed plugins", c.pill(String(installed.length))),
110
- installed.length ? h("div.lt3-grid-auto", installed.map((p) => simpleCard(ctx, p.name || p.id, p.description, p.version, "ok"))) : hint(ctx, "No plugins installed.")),
111
- h("section", c.sectionHead("Directory", c.pill(String(directory.length))),
112
- directory.length ? h("div.lt3-grid-auto", directory.slice(0, 30).map((p) => simpleCard(ctx, p.name, p.description, p.version, null, p.author))) : hint(ctx, "Directory unavailable.")),
113
- ));
114
- }
115
-
116
- async function paintSkills() {
117
- const res = await ctx.api.skillsMarketplace();
118
- const skills = (res.data && res.data.skills) || [];
119
- body.replaceChildren(h("div.lt3-stack-3",
120
- stateRow(ctx, res.source),
121
- h("p.lt3-faint", { style: { margin: 0 } }, "Manage installed skills in the Skills view; this is the discovery catalog."),
122
- skills.length
123
- ? h("div.lt3-grid-auto", skills.slice(0, 40).map((s) => simpleCard(ctx, s.skill || s.name, s.description, s.version, s.installed ? "ok" : null, s.author)))
124
- : c.emptyState({ icon: "puzzle-off", title: "Skills catalog unavailable", body: "The skills marketplace did not respond." }),
125
- ));
126
- }
127
- }
128
-
129
- function stateRow(ctx, source) {
130
- return ctx.h("div.lt3-row-2", { style: { "justify-content": "flex-end" } }, ctx.c.sourceBadge(source));
131
- }
132
- function simpleCard(ctx, name, desc, version, state, author) {
133
- const { h, c } = ctx;
134
- return c.card(h("div.lt3-stack-2",
135
- h("div.lt3-row", { style: { "justify-content": "space-between" } }, h("b", name || "Untitled"), state ? c.statePill(state === "ok" ? "ready" : state) : null),
136
- h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, desc || ""),
137
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, [version ? `v${version}` : null, author ? `by ${author}` : null].filter(Boolean).join(" · ")),
138
- ), { flat: true });
139
- }
140
- function hint(ctx, text) { return ctx.h("p.lt3-faint", { style: { margin: 0 } }, text); }
141
- function cap(s) { return String(s || "").charAt(0).toUpperCase() + String(s || "").slice(1); }