ltcai 3.3.0 → 3.4.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.
- package/README.md +85 -66
- package/docs/CHANGELOG.md +36 -0
- package/docs/architecture.md +2 -1
- package/docs/assets/v3.4.0/agent-run.png +0 -0
- package/docs/assets/v3.4.0/agents.png +0 -0
- package/docs/assets/v3.4.0/before/chat-before.png +0 -0
- package/docs/assets/v3.4.0/before/files-before.png +0 -0
- package/docs/assets/v3.4.0/chat.png +0 -0
- package/docs/assets/v3.4.0/connect-folder.png +0 -0
- package/docs/assets/v3.4.0/files.png +0 -0
- package/docs/assets/v3.4.0/home.png +0 -0
- package/docs/assets/v3.4.0/hooks-dispatch.png +0 -0
- package/docs/assets/v3.4.0/knowledge-graph.png +0 -0
- package/docs/assets/v3.4.0/local-agent.png +0 -0
- package/docs/assets/v3.4.0/memory.png +0 -0
- package/docs/assets/v3.4.0/settings.png +0 -0
- package/docs/assets/v3.4.0/vision-input.png +0 -0
- package/docs/assets/v3.4.0/workflows.png +0 -0
- package/knowledge_graph.py +45 -0
- package/knowledge_graph_api.py +10 -0
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/agents.py +3 -0
- package/latticeai/api/hooks.py +39 -0
- package/latticeai/api/local_files.py +41 -0
- package/latticeai/api/models.py +36 -1
- package/latticeai/api/tools.py +16 -1
- package/latticeai/api/workflow_designer.py +2 -1
- package/latticeai/core/hooks.py +398 -2
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/multi_agent.py +1 -1
- package/latticeai/core/workflow_engine.py +21 -1
- package/latticeai/core/workspace_os.py +1 -1
- package/latticeai/server_app.py +40 -0
- package/latticeai/services/agent_runtime.py +46 -1
- package/latticeai/services/upload_service.py +17 -0
- package/package.json +1 -1
- package/scripts/capture/capture_v340.js +88 -0
- package/static/css/{tokens.8b8e31bd.css → tokens.3ba22e37.css} +109 -109
- package/static/css/tokens.css +109 -109
- package/static/v3/asset-manifest.json +24 -24
- package/static/v3/css/{lattice.components.011e988b.css → lattice.components.9b49d614.css} +57 -32
- package/static/v3/css/lattice.components.css +57 -32
- package/static/v3/css/{lattice.shell.4920f42d.css → lattice.shell.6ceea7c8.css} +75 -31
- package/static/v3/css/lattice.shell.css +75 -31
- package/static/v3/css/lattice.tokens.css +13 -13
- package/static/v3/css/{lattice.tokens.c597ff81.css → lattice.tokens.e7018963.css} +13 -13
- package/static/v3/css/{lattice.views.1d326beb.css → lattice.views.22f69117.css} +93 -15
- package/static/v3/css/lattice.views.css +93 -15
- package/static/v3/js/{app.cf5bb712.js → app.c4acfdd8.js} +1 -1
- package/static/v3/js/core/{api.113660c5.js → api.12b568ad.js} +67 -0
- package/static/v3/js/core/api.js +67 -0
- package/static/v3/js/core/{components.4c83e0a9.js → components.35f02e4c.js} +8 -0
- package/static/v3/js/core/components.js +8 -0
- package/static/v3/js/core/{routes.07ad6696.js → routes.d214b399.js} +16 -12
- package/static/v3/js/core/routes.js +16 -12
- package/static/v3/js/core/{shell.9e707234.js → shell.80a6ad82.js} +37 -9
- package/static/v3/js/core/shell.js +34 -6
- package/static/v3/js/views/agents.014d0b74.js +541 -0
- package/static/v3/js/views/agents.js +305 -57
- package/static/v3/js/views/{chat.c48fd9e2.js → chat.e6dd7dd0.js} +161 -9
- package/static/v3/js/views/chat.js +161 -9
- package/static/v3/js/views/files.adad14c1.js +365 -0
- package/static/v3/js/views/files.js +212 -79
- package/static/v3/js/views/home.24f8b8ae.js +200 -0
- package/static/v3/js/views/home.js +96 -15
- package/static/v3/js/views/hooks.13845954.js +215 -0
- package/static/v3/js/views/hooks.js +117 -1
- package/static/v3/js/views/{my-computer.1b2ff621.js → my-computer.c3ef5283.js} +224 -1
- package/static/v3/js/views/my-computer.js +224 -1
- package/static/v3/js/views/{settings.c7b0cc05.js → settings.8631fa5e.js} +54 -0
- package/static/v3/js/views/settings.js +54 -0
- package/static/v3/js/views/agents.c373d48c.js +0 -293
- package/static/v3/js/views/files.8464634a.js +0 -232
- package/static/v3/js/views/home.cdde3b32.js +0 -119
- package/static/v3/js/views/hooks.f3edebca.js +0 -99
|
@@ -27,6 +27,10 @@ export async function render(ctx) {
|
|
|
27
27
|
model: "", modelSource: "pending",
|
|
28
28
|
lastQuery: "", lastTrace: null,
|
|
29
29
|
graphCache: null,
|
|
30
|
+
// VLM image input (per-message). state.image holds raw base64 with NO
|
|
31
|
+
// "data:image/...;base64," prefix (what /chat expects); state.imagePreview
|
|
32
|
+
// keeps the full data URL for the <img> thumbnail.
|
|
33
|
+
image: null, imagePreview: null, visionEnabled: false,
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
/* ── element hosts ───────────────────────────────────────────────────── */
|
|
@@ -46,9 +50,29 @@ export async function render(ctx) {
|
|
|
46
50
|
on: {
|
|
47
51
|
input: autogrow,
|
|
48
52
|
keydown: (e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); send(); } },
|
|
53
|
+
paste: onPaste,
|
|
49
54
|
},
|
|
50
55
|
});
|
|
51
|
-
const sendBtn = h("button.lt3-btn.lt3-btn--primary", { "aria-label": "Send", on: { click: send } }, icon("arrow-up"));
|
|
56
|
+
const sendBtn = h("button.lt3-btn.lt3-btn--primary", { "aria-label": "Send", on: { click: () => state.streaming ? stopStreaming() : send() } }, icon("arrow-up"));
|
|
57
|
+
|
|
58
|
+
/* ── VLM image input (upload · drop · paste) ─────────────────────────── */
|
|
59
|
+
// Vision-capability badge — reflects whether the loaded model can read
|
|
60
|
+
// images. Honest by default ("Vision Disabled") until /models confirms.
|
|
61
|
+
const visionPill = h("span", {
|
|
62
|
+
title: "Load a vision-capable model to interpret images",
|
|
63
|
+
}, c.pill("Vision Disabled", "warn", { dot: true }));
|
|
64
|
+
// Hidden native picker, triggered by the "Attach image" button.
|
|
65
|
+
const fileInput = h("input", {
|
|
66
|
+
type: "file", accept: "image/*", style: { display: "none" },
|
|
67
|
+
"aria-hidden": "true", tabindex: "-1",
|
|
68
|
+
on: { change: (e) => { const f = e.target.files && e.target.files[0]; if (f) loadImageFile(f); e.target.value = ""; } },
|
|
69
|
+
});
|
|
70
|
+
const attachBtn = h("button.lt3-chip", {
|
|
71
|
+
type: "button", title: "Attach an image for a vision-capable model to read",
|
|
72
|
+
"aria-label": "Attach image", on: { click: () => fileInput.click() },
|
|
73
|
+
}, icon("photo"), "Image");
|
|
74
|
+
// Preview host, populated above the textarea inside .lt3-composer__inner.
|
|
75
|
+
const imagePreviewHost = h("div", { style: { display: "none" } });
|
|
52
76
|
|
|
53
77
|
const groundChip = (key, label, icn) => h("button.lt3-chip", {
|
|
54
78
|
type: "button", dataset: { active: String(state.grounding[key]) }, "aria-pressed": String(state.grounding[key]),
|
|
@@ -87,10 +111,16 @@ export async function render(ctx) {
|
|
|
87
111
|
thread,
|
|
88
112
|
h("div.lt3-composer",
|
|
89
113
|
h("div.lt3-composer__inner",
|
|
90
|
-
|
|
114
|
+
imagePreviewHost,
|
|
115
|
+
h("div.lt3-composer__box", {
|
|
116
|
+
on: { dragover: onDragOver, dragleave: onDragLeave, drop: onDrop },
|
|
117
|
+
}, textarea, sendBtn),
|
|
91
118
|
h("div.lt3-composer__tools",
|
|
92
119
|
groundChip("graph", "Knowledge Graph", "chart-dots-3"),
|
|
93
120
|
groundChip("vector", "Vector", "grid-dots"),
|
|
121
|
+
attachBtn,
|
|
122
|
+
visionPill,
|
|
123
|
+
fileInput,
|
|
94
124
|
h("span.lt3-spacer"),
|
|
95
125
|
h("span.lt3-kbd", "↵"),
|
|
96
126
|
),
|
|
@@ -152,6 +182,7 @@ export async function render(ctx) {
|
|
|
152
182
|
async function selectConversation(id) {
|
|
153
183
|
if (state.streaming) stopStreaming();
|
|
154
184
|
closePanes();
|
|
185
|
+
clearImage();
|
|
155
186
|
state.activeId = id;
|
|
156
187
|
const conv = state.conversations.find((x) => x.id === id);
|
|
157
188
|
state.title = conv ? conv.title : "Conversation";
|
|
@@ -174,6 +205,7 @@ export async function render(ctx) {
|
|
|
174
205
|
function startNew(userInitiated) {
|
|
175
206
|
if (state.streaming) stopStreaming();
|
|
176
207
|
closePanes();
|
|
208
|
+
clearImage();
|
|
177
209
|
state.activeId = null;
|
|
178
210
|
state.title = "New chat";
|
|
179
211
|
state.messages = [];
|
|
@@ -218,7 +250,13 @@ export async function render(ctx) {
|
|
|
218
250
|
function messageNode(m) {
|
|
219
251
|
const isUser = m.role === "user";
|
|
220
252
|
const body = h("div.lt3-msg__body",
|
|
221
|
-
h("div.lt3-msg__bubble",
|
|
253
|
+
h("div.lt3-msg__bubble",
|
|
254
|
+
m.image && h("img", {
|
|
255
|
+
src: m.image, alt: "Attached image",
|
|
256
|
+
style: { display: "block", "max-height": "220px", "max-width": "100%", "border-radius": "var(--lt3-radius-2, 8px)", border: "1px solid var(--border)", "margin-bottom": m.content ? "var(--lt3-space-2)" : "0" },
|
|
257
|
+
}),
|
|
258
|
+
m.content,
|
|
259
|
+
),
|
|
222
260
|
m.role === "ai" && m.source && h("div.lt3-row-2", c.sourceBadge(m.source)),
|
|
223
261
|
);
|
|
224
262
|
return h(`div.lt3-msg.lt3-msg--${isUser ? "user" : "ai"}`,
|
|
@@ -234,18 +272,122 @@ export async function render(ctx) {
|
|
|
234
272
|
textarea.style.height = Math.min(200, textarea.scrollHeight) + "px";
|
|
235
273
|
}
|
|
236
274
|
|
|
275
|
+
/* ── image: read · preview · clear ───────────────────────────────────── */
|
|
276
|
+
// Read an image File as a data URL, then split off the raw base64 payload
|
|
277
|
+
// (/chat wants the bytes without the "data:...;base64," prefix).
|
|
278
|
+
function loadImageFile(file) {
|
|
279
|
+
if (!file || !/^image\//.test(file.type || "")) return;
|
|
280
|
+
const reader = new FileReader();
|
|
281
|
+
reader.onload = () => {
|
|
282
|
+
const dataUrl = String(reader.result || "");
|
|
283
|
+
const comma = dataUrl.indexOf(",");
|
|
284
|
+
if (comma < 0) return;
|
|
285
|
+
state.imagePreview = dataUrl;
|
|
286
|
+
state.image = dataUrl.slice(comma + 1); // strip the data: prefix
|
|
287
|
+
renderImagePreview();
|
|
288
|
+
};
|
|
289
|
+
reader.onerror = () => toast("Couldn't read that image", "err");
|
|
290
|
+
reader.readAsDataURL(file);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function clearImage() {
|
|
294
|
+
state.image = null;
|
|
295
|
+
state.imagePreview = null;
|
|
296
|
+
renderImagePreview();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function renderImagePreview() {
|
|
300
|
+
if (!state.imagePreview) {
|
|
301
|
+
imagePreviewHost.replaceChildren();
|
|
302
|
+
imagePreviewHost.style.display = "none";
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
imagePreviewHost.style.display = "flex";
|
|
306
|
+
imagePreviewHost.style.setProperty("align-items", "center");
|
|
307
|
+
imagePreviewHost.style.setProperty("gap", "var(--lt3-space-2)");
|
|
308
|
+
imagePreviewHost.style.setProperty("margin-bottom", "var(--lt3-space-2)");
|
|
309
|
+
imagePreviewHost.replaceChildren(
|
|
310
|
+
h("div", { style: { position: "relative", display: "inline-flex" } },
|
|
311
|
+
h("img", {
|
|
312
|
+
src: state.imagePreview, alt: "Attached image preview",
|
|
313
|
+
style: { height: "64px", "border-radius": "var(--lt3-radius-2, 8px)", border: "1px solid var(--border)" },
|
|
314
|
+
}),
|
|
315
|
+
h("button.lt3-iconbtn.lt3-iconbtn--sm", {
|
|
316
|
+
type: "button", "aria-label": "Remove image",
|
|
317
|
+
title: "Remove image",
|
|
318
|
+
style: {
|
|
319
|
+
position: "absolute", top: "-8px", right: "-8px",
|
|
320
|
+
background: "var(--surface-2)", border: "1px solid var(--border)",
|
|
321
|
+
"border-radius": "var(--lt3-radius-pill, 999px)",
|
|
322
|
+
},
|
|
323
|
+
on: { click: clearImage },
|
|
324
|
+
}, icon("x")),
|
|
325
|
+
),
|
|
326
|
+
h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
|
|
327
|
+
state.visionEnabled ? "Image attached" : "Image attached · load a vision-capable model to interpret it"),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* ── drag & drop ─────────────────────────────────────────────────────── */
|
|
332
|
+
function hasImageDrag(e) {
|
|
333
|
+
const dt = e.dataTransfer;
|
|
334
|
+
return !!dt && Array.from(dt.types || []).includes("Files");
|
|
335
|
+
}
|
|
336
|
+
function onDragOver(e) {
|
|
337
|
+
if (!hasImageDrag(e)) return;
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
e.currentTarget.style.setProperty("outline", "2px dashed var(--accent)");
|
|
340
|
+
e.currentTarget.style.setProperty("outline-offset", "2px");
|
|
341
|
+
}
|
|
342
|
+
function onDragLeave(e) {
|
|
343
|
+
e.currentTarget.style.removeProperty("outline");
|
|
344
|
+
e.currentTarget.style.removeProperty("outline-offset");
|
|
345
|
+
}
|
|
346
|
+
function onDrop(e) {
|
|
347
|
+
e.currentTarget.style.removeProperty("outline");
|
|
348
|
+
e.currentTarget.style.removeProperty("outline-offset");
|
|
349
|
+
const dt = e.dataTransfer;
|
|
350
|
+
if (!dt || !dt.files || !dt.files.length) return;
|
|
351
|
+
const file = Array.from(dt.files).find((f) => /^image\//.test(f.type || ""));
|
|
352
|
+
if (!file) return;
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
loadImageFile(file);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* ── paste ───────────────────────────────────────────────────────────── */
|
|
358
|
+
function onPaste(e) {
|
|
359
|
+
const items = e.clipboardData && e.clipboardData.items;
|
|
360
|
+
if (!items) return;
|
|
361
|
+
for (const item of items) {
|
|
362
|
+
if (item.kind === "file" && /^image\//.test(item.type || "")) {
|
|
363
|
+
const file = item.getAsFile();
|
|
364
|
+
if (file) { e.preventDefault(); loadImageFile(file); }
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
237
370
|
/* ── send + stream ───────────────────────────────────────────────────── */
|
|
238
371
|
async function send() {
|
|
239
372
|
const text = textarea.value.trim();
|
|
240
|
-
|
|
373
|
+
// An image alone is a valid message — only bail when there's nothing at all.
|
|
374
|
+
if ((!text && !state.image) || state.streaming) return;
|
|
241
375
|
textarea.value = ""; autogrow();
|
|
242
376
|
|
|
377
|
+
// Snapshot the image for this message, then clear the composer (per-message).
|
|
378
|
+
const imageData = state.image || null;
|
|
379
|
+
const imagePreview = state.imagePreview || null;
|
|
380
|
+
clearImage();
|
|
381
|
+
|
|
243
382
|
if (!state.messages.length) threadInner.replaceChildren();
|
|
244
|
-
const userMsg = { role: "user", content: text };
|
|
383
|
+
const userMsg = { role: "user", content: text, image: imagePreview };
|
|
245
384
|
state.messages.push(userMsg);
|
|
246
385
|
threadInner.append(messageNode(userMsg));
|
|
247
386
|
state.lastQuery = text;
|
|
248
|
-
if (!state.activeId) {
|
|
387
|
+
if (!state.activeId) {
|
|
388
|
+
const seed = text || "Image";
|
|
389
|
+
state.title = seed.slice(0, 48); titleEl.textContent = state.title;
|
|
390
|
+
}
|
|
249
391
|
|
|
250
392
|
// streaming AI bubble
|
|
251
393
|
const bubble = h("div.lt3-msg__bubble");
|
|
@@ -264,7 +406,7 @@ export async function render(ctx) {
|
|
|
264
406
|
let started = false;
|
|
265
407
|
|
|
266
408
|
const result = await api.streamChat(
|
|
267
|
-
{ message: text, conversation_id: state.activeId, grounding: state.grounding },
|
|
409
|
+
{ message: text, conversation_id: state.activeId, grounding: state.grounding, image_data: imageData || undefined },
|
|
268
410
|
{
|
|
269
411
|
signal: state.abort.signal,
|
|
270
412
|
onChunk: (_delta, full) => {
|
|
@@ -326,11 +468,9 @@ export async function render(ctx) {
|
|
|
326
468
|
if (on) {
|
|
327
469
|
sendBtn.replaceChildren(icon("player-stop"));
|
|
328
470
|
sendBtn.setAttribute("aria-label", "Stop");
|
|
329
|
-
sendBtn.onclick = stopStreaming;
|
|
330
471
|
} else {
|
|
331
472
|
sendBtn.replaceChildren(icon("arrow-up"));
|
|
332
473
|
sendBtn.setAttribute("aria-label", "Send");
|
|
333
|
-
sendBtn.onclick = send;
|
|
334
474
|
}
|
|
335
475
|
}
|
|
336
476
|
|
|
@@ -413,6 +553,18 @@ export async function render(ctx) {
|
|
|
413
553
|
state.modelSource = res.source;
|
|
414
554
|
modelPill.replaceChildren(c.pill(state.model ? shortModel(state.model) : "No model", state.model ? "info" : "warn", { dot: true }));
|
|
415
555
|
barSrc.replaceChildren(c.sourceBadge(res.source));
|
|
556
|
+
|
|
557
|
+
// Vision capability — driven by the real /models.vision contract; stays
|
|
558
|
+
// honestly "Disabled" when the field is absent or the call is unavailable.
|
|
559
|
+
state.visionEnabled = !!(res.data && res.data.vision && res.data.vision.enabled);
|
|
560
|
+
visionPill.title = state.visionEnabled
|
|
561
|
+
? "The loaded model can interpret attached images"
|
|
562
|
+
: "Load a vision-capable model to interpret images";
|
|
563
|
+
visionPill.replaceChildren(
|
|
564
|
+
c.pill(state.visionEnabled ? "Vision Enabled" : "Vision Disabled", state.visionEnabled ? "ok" : "warn", { dot: true }),
|
|
565
|
+
);
|
|
566
|
+
// Keep any open preview's helper text in sync with capability.
|
|
567
|
+
if (state.imagePreview) renderImagePreview();
|
|
416
568
|
}
|
|
417
569
|
|
|
418
570
|
function loadInitial() {
|
|
@@ -0,0 +1,365 @@
|
|
|
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
|
+
}
|