ltcai 3.2.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 +87 -67
- 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/build_v3_assets.mjs +7 -1
- package/scripts/capture/capture_v340.js +88 -0
- package/static/css/{tokens.5a595671.css → tokens.3ba22e37.css} +109 -109
- package/static/css/tokens.css +109 -109
- package/static/v3/asset-manifest.json +25 -25
- 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.3ee19d4e.css → lattice.views.22f69117.css} +98 -15
- package/static/v3/css/lattice.views.css +98 -15
- package/static/v3/js/{app.a5adc0f3.js → app.c4acfdd8.js} +1 -1
- package/static/v3/js/core/{api.603b978f.js → api.12b568ad.js} +126 -4
- package/static/v3/js/core/api.js +126 -4
- 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.ea0b9ae5.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.718144ce.js → chat.e6dd7dd0.js} +162 -10
- package/static/v3/js/views/chat.js +162 -10
- package/static/v3/js/views/files.adad14c1.js +365 -0
- package/static/v3/js/views/files.js +269 -90
- 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/{memory.d2ed7a7c.js → memory.4ebdf474.js} +5 -4
- package/static/v3/js/views/memory.js +5 -4
- 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.4f777210.js → settings.8631fa5e.js} +70 -2
- package/static/v3/js/views/settings.js +70 -2
- package/static/v3/js/views/agents.c373d48c.js +0 -293
- package/static/v3/js/views/files.4935197e.js +0 -186
- 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,13 +50,33 @@ 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]),
|
|
55
|
-
title: `
|
|
79
|
+
title: `Show the ${label} signal in the retrieval-context panel`,
|
|
56
80
|
on: { click: (e) => { state.grounding[key] = !state.grounding[key]; const b = e.currentTarget; b.dataset.active = String(state.grounding[key]); b.setAttribute("aria-pressed", String(state.grounding[key])); } },
|
|
57
81
|
}, icon(icn), label);
|
|
58
82
|
|
|
@@ -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() {
|
|
@@ -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,13 +50,33 @@ 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]),
|
|
55
|
-
title: `
|
|
79
|
+
title: `Show the ${label} signal in the retrieval-context panel`,
|
|
56
80
|
on: { click: (e) => { state.grounding[key] = !state.grounding[key]; const b = e.currentTarget; b.dataset.active = String(state.grounding[key]); b.setAttribute("aria-pressed", String(state.grounding[key])); } },
|
|
57
81
|
}, icon(icn), label);
|
|
58
82
|
|
|
@@ -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() {
|