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,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.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
- }