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,529 +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.a2773eb0.js";
11
- import { createGraphCanvas } from "./graph-canvas.17c15d65.js";
12
- import { t } from "../core/i18n.880e1fec.js";
13
-
14
- const TYPE_COLOR = {
15
- Topic: "var(--lt3-pillar-graph)",
16
- Concept: "var(--lt3-pillar-vector)",
17
- Method: "var(--lt3-pillar-hybrid)",
18
- Model: "var(--accent-3)",
19
- File: "var(--faint)",
20
- Source: "var(--lt3-pillar-hybrid)",
21
- Document: "var(--accent)",
22
- Decision: "var(--accent-3)",
23
- Task: "var(--accent-2)",
24
- Person: "var(--accent-pink)",
25
- default: "var(--accent)",
26
- };
27
- const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
28
-
29
- const TABS = [
30
- { key: "explore", label: "Explore", icon: "chart-dots-3" },
31
- { key: "status", label: "Status", icon: "activity-heartbeat" },
32
- { key: "sources", label: "Sources", icon: "database" },
33
- { key: "capture", label: "Capture", icon: "world-www" },
34
- { key: "portability", label: "Backup", icon: "archive" },
35
- ];
36
-
37
- export async function render(ctx) {
38
- const { h, icon, api, c } = ctx;
39
- let active = "explore";
40
-
41
- const tabBar = h("div.lt3-row-2");
42
- const panelHost = h("div.lt3-stack-4");
43
-
44
- function renderTabs() {
45
- tabBar.replaceChildren(...TABS.map((t) =>
46
- h("button.lt3-btn" + (t.key === active ? ".lt3-btn--primary" : ".lt3-btn--ghost"),
47
- { on: { click: () => switchTab(t.key) } }, icon(t.icon), t.label)));
48
- }
49
-
50
- function switchTab(key) {
51
- if (active === key) return;
52
- active = key;
53
- renderTabs();
54
- renderActive();
55
- }
56
-
57
- let exploreNode = null;
58
- function renderActive() {
59
- if (active === "explore") {
60
- if (!exploreNode) exploreNode = buildExplore(ctx);
61
- panelHost.replaceChildren(exploreNode);
62
- } else if (active === "status") {
63
- renderStatus(ctx, panelHost);
64
- } else if (active === "sources") {
65
- renderSources(ctx, panelHost);
66
- } else if (active === "capture") {
67
- panelHost.replaceChildren(buildCapture(ctx));
68
- } else if (active === "portability") {
69
- renderPortability(ctx, panelHost);
70
- }
71
- }
72
-
73
- const root = h("div.lt3-stack-6",
74
- c.viewHeader({
75
- eyebrow: "Your digital brain",
76
- title: "Knowledge Graph",
77
- sub: "Everything you ingest converges here — files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
78
- actions: [
79
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
80
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
81
- ],
82
- }),
83
- tabBar,
84
- panelHost,
85
- );
86
-
87
- renderTabs();
88
- renderActive();
89
- return root;
90
- }
91
-
92
- /* ── Explore tab (entity/relation mesh) ─────────────────────────────────── */
93
- function buildExplore(ctx) {
94
- const { h, icon, api, c } = ctx;
95
- const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
96
-
97
- const canvasHost = h("div", c.loading({ lines: 0, block: true }));
98
- const inspectorHost = h("div", c.loading({ lines: 4 }));
99
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
100
- const srcSlot = h("span", c.sourceBadge("pending"));
101
-
102
- const root = h("div.lt3-stack-3",
103
- h("div.lt3-row-2",
104
- srcSlot,
105
- h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
106
- ),
107
- statHost,
108
- h("div.lt3-split",
109
- h("div.lt3-stack-3",
110
- c.card(canvasHost, { attrs: { style: "padding:0;overflow:hidden" } }),
111
- buildLegend(ctx),
112
- ),
113
- h("aside.lt3-panel",
114
- h("div.lt3-panel__head", h("div", h("div.lt3-eyebrow", "Inspector"), h("h3.lt3-panel__title", "Entities"))),
115
- h("div.lt3-search", { style: { "margin-bottom": "var(--lt3-space-4)" } },
116
- icon("search"),
117
- h("input", { type: "text", placeholder: "Filter entities…", "aria-label": "Filter entities",
118
- on: { input: (e) => { state.query = e.target.value.toLowerCase(); renderInspector(); } } }),
119
- ),
120
- inspectorHost,
121
- ),
122
- ),
123
- );
124
-
125
- async function load() {
126
- canvasHost.replaceChildren(c.loading({ lines: 0, block: true }));
127
- const [g, stats] = await Promise.all([api.graph(), api.graphStats()]);
128
- state.data = normalize(g.data);
129
- state.source = g.source;
130
- srcSlot.replaceChildren(c.sourceBadge(g.source));
131
- renderStats(stats.data, g.data);
132
- renderCanvas();
133
- renderInspector();
134
- }
135
-
136
- function renderStats(stats) {
137
- const nodes = state.data.nodes.length;
138
- const edges = state.data.edges.length;
139
- const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
140
- const density = nodes > 1 ? (edges / (nodes * (nodes - 1) / 2)) : 0;
141
- statHost.replaceChildren(
142
- c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
143
- c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
144
- c.stat({ label: "Entity types", value: types, icon: "category" }),
145
- c.stat({ label: "Density", value: density.toFixed(2), icon: "chart-dots" }),
146
- );
147
- }
148
-
149
- // Live force-directed canvas (zoom / pan / drag / physics) — replaces the
150
- // static SVG spiral. The renderer only draws the data it is given.
151
- let graphCanvas = null;
152
-
153
- function ensureGraphCanvas() {
154
- if (graphCanvas) return graphCanvas;
155
- graphCanvas = createGraphCanvas({
156
- colorFor,
157
- onSelect: (id) => {
158
- state.selected = id;
159
- renderInspector();
160
- },
161
- });
162
- return graphCanvas;
163
- }
164
-
165
- function renderCanvas() {
166
- const { nodes, edges } = state.data;
167
- if (!nodes.length) {
168
- if (graphCanvas) { graphCanvas.destroy(); graphCanvas = null; }
169
- canvasHost.replaceChildren(c.emptyState({ icon: "chart-dots-3", title: "No entities yet", body: "Index a source to populate the graph." }));
170
- return;
171
- }
172
- const gc = ensureGraphCanvas();
173
- gc.setData({ nodes, edges });
174
- gc.setSelected(state.selected);
175
- if (!gc.el.isConnected || gc.el.parentElement !== canvasHost.querySelector(".lt3-graph-canvas")) {
176
- canvasHost.replaceChildren(h("div.lt3-graph-canvas", gc.el));
177
- }
178
- }
179
-
180
- function syncSelection() {
181
- if (graphCanvas) graphCanvas.setSelected(state.selected);
182
- renderInspector();
183
- }
184
-
185
- function renderInspector() {
186
- if (state.selected) { inspectorHost.replaceChildren(detailView()); return; }
187
- const q = state.query;
188
- const list = state.data.nodes
189
- .filter((n) => !q || (n.label || "").toLowerCase().includes(q) || (n.type || "").toLowerCase().includes(q))
190
- .sort((a, b) => (b.weight || 0) - (a.weight || 0));
191
- inspectorHost.replaceChildren(
192
- list.length
193
- ? h("div.lt3-stack-2", list.slice(0, 60).map((n) => entityRow(n)))
194
- : c.emptyState({ icon: "search-off", title: "No matches", body: "Try a different entity name." }),
195
- );
196
- }
197
-
198
- function entityRow(n) {
199
- return h("button.lt3-entity", { on: { click: () => { state.selected = n.id; syncSelection(); } } },
200
- h("div.lt3-entity__type", { style: { background: `color-mix(in srgb, ${colorFor(n.type)} 18%, transparent)`, color: colorFor(n.type) } }, icon(iconForType(n.type))),
201
- h("div.lt3-entity__body",
202
- h("div.lt3-entity__name", n.label),
203
- h("div.lt3-entity__meta", `${n.type || "Entity"} · weight ${(n.weight || 0).toFixed(2)}`),
204
- ),
205
- );
206
- }
207
-
208
- function detailView() {
209
- const n = state.data.nodes.find((x) => x.id === state.selected);
210
- if (!n) { state.selected = null; return c.emptyState({ title: "Not found" }); }
211
- const rels = state.data.edges
212
- .filter((e) => e.from === n.id || e.to === n.id)
213
- .map((e) => {
214
- const otherId = e.from === n.id ? e.to : e.from;
215
- const other = state.data.nodes.find((x) => x.id === otherId);
216
- return { type: e.type, dir: e.from === n.id ? "→" : "←", other };
217
- })
218
- .filter((r) => r.other);
219
- return h("div.lt3-stack-4",
220
- h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null; syncSelection(); } } }, icon("arrow-left"), "All entities"),
221
- h("div.lt3-card.lt3-card--flat",
222
- h("div.lt3-row-2", { style: { "margin-bottom": "var(--lt3-space-2)" } },
223
- h("span.lt3-pill", { style: { color: colorFor(n.type) } }, n.type || "Entity"),
224
- ),
225
- h("div", { style: { "font-size": "var(--lt3-text-lg)", "font-weight": 700 } }, n.label),
226
- n.summary && h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-2)" } }, n.summary),
227
- ),
228
- h("div",
229
- h("div.lt3-eyebrow", { style: { "margin-bottom": "var(--lt3-space-2)" } }, `Relations (${rels.length})`),
230
- rels.length
231
- ? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id; syncSelection(); } } },
232
- h("div.lt3-entity__type", { style: { background: "var(--surface-3)" } }, h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, r.dir)),
233
- h("div.lt3-entity__body",
234
- h("div.lt3-entity__name", r.other.label),
235
- h("div.lt3-entity__meta", r.type),
236
- ),
237
- )))
238
- : c.emptyState({ icon: "unlink", title: "No relations", body: "This entity is currently isolated." }),
239
- ),
240
- );
241
- }
242
-
243
- load();
244
- return root;
245
- }
246
-
247
- /* ── Status tab (graph + ingestion health) ──────────────────────────────── */
248
- async function renderStatus(ctx, host) {
249
- const { h, icon, api, c } = ctx;
250
- host.replaceChildren(c.loading({ lines: 3 }));
251
- const [port, gs, idx, coverage] = await Promise.all([api.kgPortability(), api.graphStats(), api.indexStatus(), api.kgProvenanceCoverage()]);
252
- const p = port.data || {};
253
- const prov = p.provenance || {};
254
- const cov = coverage.data || {};
255
- const nodes = sumCounts((gs.data && gs.data.nodes) || {});
256
- const edges = sumCounts((gs.data && gs.data.edges) || {});
257
- const pipelines = (idx.data && idx.data.pipelines) || {};
258
- const ratio = Number(cov.coverage_ratio ?? cov.ratio ?? 0);
259
- const covered = Number(cov.nodes_with_provenance ?? cov.covered_nodes ?? 0);
260
-
261
- host.replaceChildren(
262
- h("div.lt3-row-2", c.sourceBadge(port.source === "live" || coverage.source === "live" ? "live" : port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } },
263
- p.graph_schema_version != null ? `Schema v${p.graph_schema_version} · embed dim ${p.embed_dim ?? "—"}` : "Knowledge Graph status")),
264
- h("div.lt3-statrow",
265
- c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
266
- c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
267
- c.stat({ label: "Ingested items", value: c.fmtNum(prov.total || 0), icon: "package-import" }),
268
- c.stat({ label: "Embedded (RAG-ready)", value: c.fmtNum(prov.embedded || 0), icon: "vector" }),
269
- c.stat({ label: t("kg.provenanceCoverage"), value: `${Math.round(ratio * 100)}%`, icon: "shield-check", delta: `${covered}/${cov.total_nodes ?? nodes}` }),
270
- ),
271
- c.card(
272
- h("div.lt3-stack-3",
273
- h("div.lt3-eyebrow", "Pipelines"),
274
- pipelineRow(ctx, "Knowledge graph", pipelines.knowledge_graph),
275
- pipelineRow(ctx, "Vector index", pipelines.vector_index),
276
- pipelineRow(ctx, "Hybrid retrieval", pipelines.hybrid),
277
- ),
278
- ),
279
- c.card(h("div.lt3-stack-3",
280
- h("div.lt3-eyebrow", t("kg.provenanceCoverage")),
281
- h("dl.lt3-keyval",
282
- h("dt", t("kg.coveredNodes")), h("dd", `${covered}/${cov.total_nodes ?? nodes}`),
283
- h("dt", t("kg.sourceTypes")), h("dd", compactCounts(cov.provenance_by_source_type || cov.by_source_type || {})),
284
- h("dt", t("kg.uncoveredTypes")), h("dd", compactCounts(cov.uncovered_by_type || {})),
285
- ),
286
- )),
287
- prov.last_ingested_at
288
- ? 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.`)
289
- : c.emptyState({ icon: "package-import", title: "Nothing ingested yet", body: "Add files or capture a page to populate the graph." }),
290
- );
291
- }
292
-
293
- function pipelineRow(ctx, label, pipe) {
294
- const { h, c } = ctx;
295
- const stateStr = (pipe && pipe.state) || "unavailable";
296
- const detail = pipe && (pipe.entities != null ? `${pipe.entities} entities` : pipe.vectors != null ? `${pipe.vectors} vectors` : pipe.strategy || "");
297
- return h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
298
- h("div", label, detail ? h("span.lt3-muted", { style: { "margin-left": "var(--lt3-space-2)", "font-size": "var(--lt3-text-sm)" } }, detail) : null),
299
- c.statePill(stateStr),
300
- );
301
- }
302
-
303
- /* ── Sources tab (provenance: where every node came from) ────────────────── */
304
- async function renderSources(ctx, host) {
305
- const { h, icon, api, c } = ctx;
306
- host.replaceChildren(c.loading({ lines: 3 }));
307
- const [port, recent] = await Promise.all([api.kgPortability(), api.kgProvenance(40)]);
308
- const bySource = (port.data && port.data.provenance && port.data.provenance.by_source_type) || {};
309
- const items = (recent.data && recent.data.items) || [];
310
-
311
- const sourceCards = Object.keys(bySource).length
312
- ? h("div.lt3-statrow", Object.entries(bySource).map(([k, v]) =>
313
- c.stat({ label: prettySource(k), value: c.fmtNum(v), icon: iconForSource(k) })))
314
- : c.emptyState({ icon: "database", title: "No sources yet", body: "Connect a folder, upload a file, or capture a page." });
315
-
316
- const recentList = items.length
317
- ? h("div.lt3-stack-2", items.map((it) =>
318
- h("div.lt3-entity",
319
- h("div.lt3-entity__type", { style: { background: "var(--surface-3)", color: colorFor("Source") } }, icon(iconForSource(it.source_type))),
320
- h("div.lt3-entity__body",
321
- h("div.lt3-entity__name", it.title || it.source_uri || it.node_id),
322
- h("div.lt3-entity__meta", `${prettySource(it.source_type)} · ${fmtWhen(it.created_at)}${it.embedded ? " · embedded" : ""}${it.duplicate ? " · duplicate" : ""}`),
323
- ),
324
- )))
325
- : c.emptyState({ icon: "history", title: "No recent ingestions", body: "Ingested items will appear here with full provenance." });
326
-
327
- host.replaceChildren(
328
- 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).")),
329
- sourceCards,
330
- c.card(h("div.lt3-stack-3", h("div.lt3-eyebrow", "Recent ingestions"), recentList)),
331
- );
332
- }
333
-
334
- /* ── Capture tab (web/URL into the graph) ───────────────────────────────── */
335
- function buildCapture(ctx) {
336
- const { h, icon, api, c } = ctx;
337
- const input = h("input", { type: "url", placeholder: "https://example.com/article", "aria-label": "URL to capture",
338
- style: { flex: "1" } });
339
- const result = h("div");
340
-
341
- async function run() {
342
- const url = (input.value || "").trim();
343
- if (!url) { result.replaceChildren(c.banner("Enter a URL first.", "warn", "alert-triangle")); return; }
344
- result.replaceChildren(c.loading({ lines: 1 }));
345
- const res = await api.browserReadUrl(url);
346
- const d = res.data || {};
347
- if (res.ok && d.status === "ok") {
348
- result.replaceChildren(c.banner(`Added to your Knowledge Graph${d.duplicate ? " (already present — linked)" : ""}. ${d.chunk_count || 0} chunk(s) indexed.`, "ok", "circle-check"));
349
- ctx.toast && ctx.toast("Page added to Knowledge Graph");
350
- } else if (d.status === "empty") {
351
- result.replaceChildren(c.banner("No readable text was found on that page.", "warn", "alert-triangle"));
352
- } else {
353
- const detail = d.detail || (res.status === 422 ? "The page is blocked or login-required." : "Could not read that URL.");
354
- result.replaceChildren(c.banner(detail, "err", "alert-triangle"));
355
- }
356
- }
357
-
358
- return h("div.lt3-stack-4",
359
- c.card(h("div.lt3-stack-3",
360
- h("div.lt3-eyebrow", "Capture a web page"),
361
- 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."),
362
- h("div.lt3-row-2",
363
- input,
364
- h("button.lt3-btn.lt3-btn--primary", { on: { click: run } }, icon("world-download"), "Read into graph"),
365
- ),
366
- result,
367
- )),
368
- c.card(h("div.lt3-stack-2",
369
- h("div.lt3-eyebrow", "Browser extension"),
370
- 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."),
371
- )),
372
- );
373
- }
374
-
375
- /* ── Portability tab (export / import / backup) ─────────────────────────── */
376
- async function renderPortability(ctx, host) {
377
- const { h, icon, api, c } = ctx;
378
- host.replaceChildren(c.loading({ lines: 2 }));
379
- const port = await api.kgPortability();
380
- const status = h("div");
381
-
382
- function note(tone, text) {
383
- status.replaceChildren(c.banner(text, tone, tone === "err" ? "alert-triangle" : tone === "ok" ? "circle-check" : "info-circle"));
384
- }
385
-
386
- async function doExport() {
387
- note("info", "Exporting…");
388
- const res = await api.graphExport();
389
- if (!res.ok || !res.data || res.data.raw) { note("err", "Export is unavailable."); return; }
390
- try {
391
- const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
392
- const url = URL.createObjectURL(blob);
393
- const a = document.createElement("a");
394
- a.href = url; a.download = "lattice-kg-export.json"; a.click();
395
- URL.revokeObjectURL(url);
396
- note("ok", `Exported ${(res.data.counts && res.data.counts.nodes) || 0} nodes. Download started.`);
397
- } catch (e) { note("err", "Could not build the download."); }
398
- }
399
-
400
- async function doBackup() {
401
- note("info", "Backing up…");
402
- const res = await api.graphBackup();
403
- if (res.ok && res.data && res.data.path) {
404
- note("ok", `Backup written locally: ${res.data.path}`);
405
- } else {
406
- note("err", (res.data && (res.data.detail || res.data.error)) || "Backup requires admin and a running runtime.");
407
- }
408
- }
409
-
410
- const importArea = h("textarea", { rows: 5, placeholder: "Paste a Knowledge Graph export (JSON) to validate, then import…",
411
- "aria-label": "Import artifact", style: { width: "100%", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } });
412
-
413
- async function doImport(dryRun) {
414
- let artifact;
415
- try { artifact = JSON.parse(importArea.value || ""); }
416
- catch { note("err", "That is not valid JSON."); return; }
417
- note("info", dryRun ? "Validating…" : "Importing…");
418
- const res = await api.graphImport(artifact, "merge", dryRun);
419
- if (res.ok && res.data && !res.data.detail) {
420
- const d = res.data;
421
- note("ok", dryRun
422
- ? `Valid — would import ${d.nodes || 0} nodes, ${d.edges || 0} edges.`
423
- : `Imported ${d.nodes || 0} nodes, ${d.edges || 0} edges.`);
424
- } else {
425
- note("err", (res.data && (res.data.detail || res.data.error)) || "Import requires admin.");
426
- }
427
- }
428
-
429
- const p = port.data || {};
430
- host.replaceChildren(
431
- 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.")),
432
- c.card(h("div.lt3-stack-3",
433
- h("div.lt3-eyebrow", "Export & backup"),
434
- 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)."),
435
- h("div.lt3-row-2",
436
- h("button.lt3-btn.lt3-btn--primary", { on: { click: doExport } }, icon("download"), "Export JSON"),
437
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: doBackup } }, icon("archive"), "Backup (admin)"),
438
- ),
439
- )),
440
- c.card(h("div.lt3-stack-3",
441
- h("div.lt3-eyebrow", "Import"),
442
- importArea,
443
- h("div.lt3-row-2",
444
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => doImport(true) } }, icon("checks"), "Validate (dry-run)"),
445
- h("button.lt3-btn.lt3-btn--primary", { on: { click: () => doImport(false) } }, icon("file-import"), "Import (merge, admin)"),
446
- ),
447
- )),
448
- status,
449
- );
450
- }
451
-
452
- /* ── helpers ─────────────────────────────────────────────────────────────── */
453
- function sumCounts(obj) {
454
- return Object.values(obj || {}).reduce((a, b) => a + (Number(b) || 0), 0);
455
- }
456
-
457
- function compactCounts(obj) {
458
- const entries = Object.entries(obj || {});
459
- return entries.length ? entries.map(([k, v]) => `${k}: ${v}`).join(" · ") : "—";
460
- }
461
-
462
- function prettySource(k) {
463
- return ({ web_url: "Web URL", browser_tab: "Browser tab", file: "Files", local_file: "Local files",
464
- note: "Notes", text: "Text", markdown: "Markdown", code: "Code", upload: "Uploads" })[k] || k;
465
- }
466
-
467
- function iconForSource(k) {
468
- return ({ web_url: "world", browser_tab: "browser", file: "file", local_file: "folder",
469
- note: "note", text: "text-caption", markdown: "markdown", code: "code", upload: "upload" })[k] || "database";
470
- }
471
-
472
- function fmtWhen(iso) {
473
- if (!iso) return "—";
474
- try {
475
- const d = new Date(iso);
476
- if (isNaN(d.getTime())) return String(iso);
477
- return d.toLocaleString();
478
- } catch { return String(iso); }
479
- }
480
-
481
- function normalize(data) {
482
- const nodes = (data.nodes || []).map((n) => ({
483
- id: n.id,
484
- label: n.label || n.title || n.id,
485
- type: n.type || "Entity",
486
- weight: n.weight ?? n.importance_norm ?? (n.metadata && n.metadata.graph_metrics && n.metadata.graph_metrics.importance_norm) ?? 0.5,
487
- summary: n.summary || "",
488
- x: n.x, y: n.y,
489
- }));
490
- const ids = new Set(nodes.map((n) => n.id));
491
- const edges = (data.edges || []).filter((e) => ids.has(e.from) && ids.has(e.to))
492
- .map((e) => ({ from: e.from, to: e.to, type: e.type || "related", weight: e.weight || 1 }));
493
- return { nodes, edges };
494
- }
495
-
496
- function layout(nodes) {
497
- const W = 1000, H = 600, cx = W / 2, cy = H / 2;
498
- const golden = Math.PI * (3 - Math.sqrt(5));
499
- const hasCoords = nodes.length && nodes.every((n) => typeof n.x === "number" && typeof n.y === "number");
500
- if (hasCoords) {
501
- return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
502
- }
503
- const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
504
- const maxR = Math.min(W, H) * 0.42;
505
- const placed = {};
506
- order.forEach((o, rank) => {
507
- const radius = rank === 0 ? 0 : maxR * Math.sqrt(rank / Math.max(1, nodes.length - 1));
508
- const angle = rank * golden;
509
- placed[o.i] = {
510
- px: Math.round(cx + Math.cos(angle) * radius),
511
- py: Math.round(cy + Math.sin(angle) * radius * 0.66),
512
- };
513
- });
514
- return nodes.map((n, i) => ({ ...n, ...placed[i] }));
515
- }
516
-
517
- function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
518
-
519
- function iconForType(t) {
520
- return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Source: "world",
521
- Document: "file-text", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
522
- }
523
-
524
- function buildLegend({ h }) {
525
- const types = ["Source", "Document", "Concept", "Person", "Decision"];
526
- return h("div.lt3-graph-legend",
527
- types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
528
- );
529
- }