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,365 +0,0 @@
1
- /* ============================================================================
2
- * View: Files — uploaded documents, connected folders & folder watch.
3
- * The headline table lists the documents Lattice has actually ingested
4
- * (/knowledge-graph/documents, live) with a per-doc index-state pill. A manual
5
- * upload drop zone ingests files on-device, and Connect Folder indexes a local
6
- * directory (+ watches it for changes) over the on-device runtime. When a
7
- * surface is unavailable its panel renders an honest empty/unavailable state —
8
- * no counts or statuses are fabricated.
9
- *
10
- * View contract (shared by all views):
11
- * export async function render(ctx) -> single DOM node
12
- * ctx = { h, icon, api, store, c, route, params, navigate, toast }
13
- * ========================================================================== */
14
-
15
- import { timeAgo } from "../core/dom.a2773eb0.js";
16
-
17
- /** Tabler glyph per uploaded-document extension. */
18
- const EXT_ICON = {
19
- pdf: "file-type-pdf", docx: "file-type-docx", doc: "file-text",
20
- xlsx: "file-spreadsheet", xls: "file-spreadsheet", csv: "table",
21
- pptx: "presentation", ppt: "presentation",
22
- md: "file-text", txt: "file-text", json: "file-code",
23
- png: "photo", jpg: "photo", jpeg: "photo", gif: "photo",
24
- };
25
- const iconForExt = (ext) => EXT_ICON[String(ext || "").replace(/^\./, "").toLowerCase()] || "file";
26
-
27
- /** Bytes → compact human string (1.0 KB / 4.7 KB / 180 KB / 1.2 MB). */
28
- function humanSize(bytes) {
29
- if (bytes === null || bytes === undefined || bytes === "") return "—";
30
- const n = Number(bytes);
31
- if (!Number.isFinite(n) || n < 0) return "—";
32
- if (n < 1024) return `${n} B`;
33
- const units = ["KB", "MB", "GB", "TB"];
34
- let v = n / 1024, i = 0;
35
- while (v >= 1024 && i < units.length - 1) { v /= 1024; i++; }
36
- return `${v.toFixed(v >= 100 || Number.isInteger(v) ? 0 : 1)} ${units[i]}`;
37
- }
38
-
39
- /** Document types the backend accepts (latticeai/services/upload_service.py). */
40
- const UPLOAD_ACCEPT = ".pdf,.docx,.xlsx,.pptx,.txt,.md,.csv";
41
-
42
- export async function render(ctx) {
43
- const { h, icon, api, c, navigate, toast } = ctx;
44
-
45
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
46
- const srcSlot = h("span", c.sourceBadge("pending"));
47
- const tableHost = h("div", c.loading({ lines: 4 }));
48
- const foldersSrc = h("span", c.sourceBadge("pending"));
49
- const foldersHost = h("div", c.loading({ lines: 3 }));
50
-
51
- // ── Manual upload (works in this build; no desktop agent required) ─────────
52
- let busy = false;
53
- const fileInput = h("input", {
54
- type: "file", multiple: true, accept: UPLOAD_ACCEPT,
55
- style: { display: "none" }, "aria-hidden": "true",
56
- on: { change: (e) => uploadFiles(e.target.files) },
57
- });
58
- const pickFiles = () => { if (!busy) fileInput.click(); };
59
- const slots = { statHost, srcSlot, tableHost, foldersSrc, foldersHost, pickFiles, connectFolder };
60
-
61
- // ── Connect Folder — index a local directory on-device and watch it ────────
62
- // Available now via the on-device runtime (one call does
63
- // request → self-approve → index + watch). No desktop agent required.
64
- async function connectFolder() {
65
- if (busy) return;
66
- const path = window.prompt("Connect a local folder to index (absolute path)", "~/Documents");
67
- if (!path || !String(path).trim()) return;
68
- const target = String(path).trim();
69
- busy = true;
70
- toast(`Connecting “${target}” — indexing on-device…`, "info");
71
- const res = await api.connectFolder(target, { watch: true });
72
- busy = false;
73
- if (res.ok) {
74
- toast(`Connected and indexing ${target} — now watched for changes.`, "ok");
75
- hydrate(ctx, slots);
76
- } else {
77
- toast(res.error || "Could not connect the folder.", "warn");
78
- }
79
- }
80
-
81
- async function uploadFiles(fileList) {
82
- const files = Array.from(fileList || []);
83
- if (!files.length || busy) return;
84
- busy = true;
85
- let ok = 0;
86
- for (const file of files) {
87
- toast(`Uploading “${file.name}”…`, "info");
88
- const res = await api.uploadDocument(file);
89
- if (res.ok && res.data && !res.data.detail && !res.data.error) {
90
- ok++;
91
- } else {
92
- const detail = (res.data && (res.data.detail || res.data.error)) || "the backend is unavailable";
93
- toast(`Could not ingest “${file.name}” — ${detail}.`, "warn");
94
- }
95
- }
96
- fileInput.value = "";
97
- busy = false;
98
- if (ok) {
99
- toast(`Indexed ${ok} document${ok === 1 ? "" : "s"} into the knowledge graph — now searchable in Chat and Hybrid Search.`, "ok");
100
- }
101
- hydrate(ctx, slots);
102
- }
103
-
104
- const dropZone = h("div.lt3-drop", {
105
- on: {
106
- dragover: (e) => { e.preventDefault(); dropZone.classList.add("is-dragover"); },
107
- dragleave: () => dropZone.classList.remove("is-dragover"),
108
- drop: (e) => { e.preventDefault(); dropZone.classList.remove("is-dragover"); uploadFiles(e.dataTransfer && e.dataTransfer.files); },
109
- },
110
- },
111
- fileInput,
112
- h("div.lt3-pillar__icon", icon("cloud-upload")),
113
- h("div",
114
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)" } }, "Drag documents here, or upload manually"),
115
- h("p.lt3-faint", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-1)" } },
116
- "Lattice parses each file, chunks it, embeds it, and links it into the knowledge graph. PDF · DOCX · XLSX · PPTX · TXT · MD · CSV, up to 10 MB each."),
117
- ),
118
- h("div.lt3-drop__meta",
119
- c.pill("Manual upload available", "ok", { dot: true }),
120
- c.pill("Connect a local folder — indexed & watched on-device", "info", { dot: true }),
121
- c.pill("Search + Chat ready after indexing", "info", { dot: true }),
122
- ),
123
- h("div.lt3-row-2",
124
- h("button.lt3-btn.lt3-btn--primary", { type: "button", on: { click: pickFiles } }, icon("upload"), "Upload files"),
125
- h("button.lt3-btn.lt3-btn--ghost", { type: "button", on: { click: connectFolder } }, icon("folder-plus"), "Connect folder"),
126
- ),
127
- );
128
-
129
- const root = h("div.lt3-stack-6",
130
- c.viewHeader({
131
- eyebrow: "Data",
132
- title: "Files",
133
- sub: "Connected sources and the documents Lattice has indexed for retrieval. Everything stays on this machine.",
134
- actions: [
135
- h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => navigate("knowledge-graph") } }, icon("chart-dots-3"), "View graph"),
136
- h("button.lt3-btn.lt3-btn--primary", { on: { click: pickFiles } }, icon("upload"), "Upload files"),
137
- h("button.lt3-btn.lt3-btn--ghost", { title: "Index a local folder on-device and watch it for changes", on: { click: connectFolder } }, icon("folder-plus"), "Connect folder"),
138
- ],
139
- }),
140
- statHost,
141
- dropZone,
142
- c.panel({
143
- head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", width: "100%" } },
144
- h("div",
145
- h("div.lt3-eyebrow", "Index"),
146
- h("h3.lt3-panel__title", "Uploaded documents"),
147
- h("p.lt3-panel__sub", "Every file Lattice has parsed, chunked, embedded and linked into the knowledge graph."),
148
- ),
149
- srcSlot,
150
- ),
151
- children: tableHost,
152
- }),
153
- c.panel({
154
- head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", width: "100%" } },
155
- h("div",
156
- h("div.lt3-eyebrow", "Local sources"),
157
- h("h3.lt3-panel__title", "Connected folders & folder watch"),
158
- h("p.lt3-panel__sub", "Local directories Lattice indexes on-device and re-indexes when their files change."),
159
- ),
160
- foldersSrc,
161
- ),
162
- children: foldersHost,
163
- }),
164
- );
165
-
166
- hydrate(ctx, slots);
167
- return root;
168
- }
169
-
170
- async function hydrate(ctx, slots) {
171
- const { statHost, srcSlot, tableHost, foldersSrc, foldersHost, pickFiles } = slots;
172
-
173
- // Fetch the documents (headline table) and connected local sources in parallel.
174
- const [docsRes, sourcesRes] = await Promise.all([
175
- ctx.api.documents(200),
176
- ctx.api.localSources(),
177
- ]);
178
-
179
- hydrateDocuments(ctx, { statHost, srcSlot, tableHost, pickFiles }, docsRes);
180
- hydrateFolders(ctx, { foldersSrc, foldersHost, slots }, sourcesRes);
181
- }
182
-
183
- /** Headline "Uploaded documents" table + stat roll-up. Data: api.documents(). */
184
- function hydrateDocuments(ctx, { statHost, srcSlot, tableHost, pickFiles }, docsRes) {
185
- const { h, icon, c, toast } = ctx;
186
- const docs = Array.isArray(docsRes.data) ? docsRes.data : [];
187
- const source = docsRes.source || (docsRes.ok ? "live" : "unavailable");
188
- srcSlot.replaceChildren(c.sourceBadge(source));
189
-
190
- // ── Stat roll-up (driven by the real documents list) ──────────────────────
191
- const indexedCount = docs.filter((d) => d.indexed === true || d.ingest_state === "indexed").length;
192
- const sourceCount = new Set(
193
- docs.map((d) => (d.uploader ? `u:${d.uploader}` : `e:${String(d.ext || "").toLowerCase()}`)),
194
- ).size;
195
- const totalBytes = docs.reduce((sum, d) => sum + (Number(d.bytes) || 0), 0);
196
- statHost.replaceChildren(
197
- c.stat({ label: "Total files", value: c.fmtNum(docs.length), icon: "files" }),
198
- c.stat({ label: "Indexed", value: c.fmtNum(indexedCount), icon: "circle-check" }),
199
- c.stat({ label: "Sources", value: c.fmtNum(sourceCount), icon: "database" }),
200
- c.stat({ label: "Total size", value: humanSize(totalBytes), icon: "weight" }),
201
- );
202
-
203
- // ── Empty / unavailable state ─────────────────────────────────────────────
204
- if (!docs.length) {
205
- if (!docsRes.ok) {
206
- tableHost.replaceChildren(c.errorState(
207
- docsRes.error || "The document index is unavailable. Start the backend with the knowledge graph enabled.",
208
- ));
209
- return;
210
- }
211
- tableHost.replaceChildren(c.emptyState({
212
- icon: "folder-off",
213
- title: "No documents indexed yet",
214
- body: "Upload a document and Lattice will parse, embed, and link it into the knowledge graph for hybrid retrieval.",
215
- action: h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm",
216
- { on: { click: () => (pickFiles ? pickFiles() : null) } },
217
- icon("upload"), "Upload files"),
218
- }));
219
- return;
220
- }
221
-
222
- // ── Table ─────────────────────────────────────────────────────────────────
223
- const columns = [
224
- {
225
- key: "filename", label: "Name",
226
- render: (row) => h("div.lt3-row-2",
227
- h("span.lt3-filerow__icon", icon(iconForExt(row.ext))),
228
- h("span", { style: { "font-weight": "var(--lt3-weight-medium)" } }, row.filename || "untitled"),
229
- ),
230
- },
231
- {
232
- key: "uploader", label: "Uploaded by", width: "26%",
233
- render: (row) => h("span.lt3-mono.lt3-faint", row.uploader || "—"),
234
- },
235
- {
236
- key: "chars", label: "Size", width: "100px",
237
- render: (row) => h("span.lt3-mono",
238
- Number(row.chars) > 0 ? `${c.fmtNum(row.chars)} chars` : humanSize(row.bytes)),
239
- },
240
- {
241
- key: "chunks", label: "Chunks", width: "84px",
242
- render: (row) => h("span.lt3-mono", Number(row.chunks) > 0 ? c.fmtNum(row.chunks) : "—"),
243
- },
244
- {
245
- key: "ingest_state", label: "Index", width: "120px",
246
- // "indexed" → green, "ingested" → warn (via components STATE_VARIANT).
247
- render: (row) => c.statePill(row.ingest_state || (row.indexed ? "indexed" : "ingested")),
248
- },
249
- {
250
- key: "updated_at", label: "Updated", width: "104px",
251
- render: (row) => h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } },
252
- (row.updated_at || row.created_at) ? timeAgo(row.updated_at || row.created_at) : "—"),
253
- },
254
- {
255
- key: "_actions", label: "", width: "44px",
256
- // Per-file management is limited — say so honestly rather than implying delete/re-index.
257
- render: (row) => h("button.lt3-iconbtn.lt3-iconbtn--sm", {
258
- "aria-label": `Document info for ${row.filename || "file"}`,
259
- title: "Per-document management isn't available yet",
260
- on: { click: () => toast("Per-document management (delete / re-index) isn't available yet — re-upload to refresh a file.", "info") },
261
- }, icon("dots-vertical")),
262
- },
263
- ];
264
-
265
- tableHost.replaceChildren(c.table(columns, docs));
266
- }
267
-
268
- /** Connected local folders + folder-watch state. Data: api.localSources(). */
269
- function hydrateFolders(ctx, { foldersSrc, foldersHost, slots }, res) {
270
- const { h, icon, c, toast } = ctx;
271
- const data = res.data || {};
272
- const sources = Array.isArray(data.sources) ? data.sources : [];
273
- const watch = data.watch || {};
274
- const source = res.source || (res.ok ? "live" : "unavailable");
275
- foldersSrc.replaceChildren(c.sourceBadge(source));
276
-
277
- const kids = [];
278
-
279
- // Honest note when filesystem watching can't run (watchdog dependency missing).
280
- if (watch.available === false) {
281
- kids.push(c.banner(
282
- watch.error
283
- ? `Folder watch is off: ${watch.error}`
284
- : "Folder watch needs the watchdog dependency — connected folders index once but won't re-index automatically until it's installed.",
285
- "warn",
286
- "alert-triangle",
287
- ));
288
- }
289
-
290
- if (!sources.length) {
291
- if (!res.ok) {
292
- kids.push(c.errorState("Local sources are unavailable — the on-device runtime isn't reachable."));
293
- } else {
294
- kids.push(c.emptyState({
295
- icon: "folder-plus",
296
- title: "No folders connected",
297
- body: "Connect a local folder — Lattice indexes it on-device and watches it for changes.",
298
- action: h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm",
299
- { on: { click: () => (slots.connectFolder ? slots.connectFolder() : null) } },
300
- icon("folder-plus"), "Connect folder"),
301
- }));
302
- }
303
- foldersHost.replaceChildren(...kids);
304
- return;
305
- }
306
-
307
- // ── Connected-folders table ───────────────────────────────────────────────
308
- async function stopWatching(id) {
309
- toast("Stopping folder watch…", "info");
310
- const stop = await ctx.api.localWatchStop(id);
311
- if (stop.ok && stop.data && !stop.data.detail && !stop.data.error) {
312
- toast("Stopped watching that folder.", "ok");
313
- } else {
314
- const detail = (stop.data && (stop.data.detail || stop.data.error)) || "the runtime is unavailable";
315
- toast(`Could not stop watching — ${detail}.`, "warn");
316
- }
317
- hydrate(ctx, slots);
318
- }
319
-
320
- const columns = [
321
- {
322
- key: "label", label: "Folder",
323
- render: (row) => h("div",
324
- h("div.lt3-row-2",
325
- h("span.lt3-filerow__icon", icon("folder")),
326
- h("span", { style: { "font-weight": "var(--lt3-weight-medium)" } }, row.label || "Local folder"),
327
- ),
328
- h("div.lt3-mono.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)", "margin-top": "var(--lt3-space-1)" } },
329
- row.root_path || row.id || "—"),
330
- ),
331
- },
332
- {
333
- key: "success_count", label: "Indexed", width: "92px",
334
- render: (row) => h("span.lt3-mono", c.fmtNum(Number(row.success_count) || 0)),
335
- },
336
- {
337
- key: "watch_active", label: "Watch", width: "120px",
338
- render: (row) => c.statePill(row.watch_active ? "watching" : "idle"),
339
- },
340
- {
341
- key: "watch_status", label: "Last activity", width: "150px",
342
- render: (row) => {
343
- const ws = row.watch_status || {};
344
- if (ws.last_error) {
345
- return h("span", { style: { color: "var(--danger)", "font-size": "var(--lt3-text-xs)" } }, ws.last_error);
346
- }
347
- const at = ws.last_event_at || ws.last_indexed_at;
348
- const label = ws.last_event_at ? "event" : (ws.last_indexed_at ? "indexed" : "");
349
- return h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } },
350
- at ? `${timeAgo(at)}${label ? ` · ${label}` : ""}` : "—");
351
- },
352
- },
353
- {
354
- key: "_stop", label: "", width: "120px",
355
- render: (row) => row.watch_active
356
- ? h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", {
357
- on: { click: () => stopWatching(row.id) },
358
- }, icon("player-stop"), "Stop watching")
359
- : h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "Not watching"),
360
- },
361
- ];
362
-
363
- kids.push(c.table(columns, sources));
364
- foldersHost.replaceChildren(...kids);
365
- }