ltcai 2.2.7 → 3.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 (122) hide show
  1. package/README.md +72 -34
  2. package/docs/CHANGELOG.md +119 -0
  3. package/docs/V3_BACKEND_ARCHITECTURE.md +138 -0
  4. package/docs/V3_FRONTEND.md +139 -0
  5. package/knowledge_graph.py +649 -21
  6. package/latticeai/__init__.py +1 -1
  7. package/latticeai/api/admin.py +47 -0
  8. package/latticeai/api/agents.py +54 -31
  9. package/latticeai/api/auth.py +5 -2
  10. package/latticeai/api/chat.py +10 -2
  11. package/latticeai/api/search.py +240 -0
  12. package/latticeai/api/static_routes.py +11 -2
  13. package/latticeai/core/config.py +18 -0
  14. package/latticeai/core/embedding_providers.py +625 -0
  15. package/latticeai/core/local_embeddings.py +86 -0
  16. package/latticeai/core/workspace_os.py +1 -1
  17. package/latticeai/server_app.py +65 -1
  18. package/latticeai/services/agent_runtime.py +245 -0
  19. package/latticeai/services/search_service.py +346 -0
  20. package/package.json +13 -6
  21. package/scripts/build_v3_assets.mjs +164 -0
  22. package/scripts/capture/README.md +28 -0
  23. package/scripts/capture/capture_enterprise.js +8 -0
  24. package/scripts/capture/capture_graph.js +8 -0
  25. package/scripts/capture/capture_onboarding.js +8 -0
  26. package/scripts/capture/capture_page.js +43 -0
  27. package/scripts/capture/capture_release_media.js +125 -0
  28. package/scripts/capture/capture_skills.js +8 -0
  29. package/scripts/capture/capture_workspace.js +8 -0
  30. package/scripts/generate_diagrams.py +513 -0
  31. package/scripts/lint_v3.mjs +33 -0
  32. package/scripts/release-0.3.1.sh +105 -0
  33. package/scripts/take_screenshots.js +69 -0
  34. package/scripts/validate_release_artifacts.py +167 -0
  35. package/static/account.html +9 -9
  36. package/static/activity.html +4 -4
  37. package/static/admin.html +8 -8
  38. package/static/agents.html +4 -4
  39. package/static/chat.html +10 -10
  40. package/static/css/reference/account.css +137 -1
  41. package/static/css/reference/chat.css +31 -37
  42. package/static/css/responsive.css +42 -0
  43. package/static/css/tokens.5a595671.css +260 -0
  44. package/static/css/tokens.css +125 -130
  45. package/static/graph.html +9 -9
  46. package/static/manifest.json +3 -3
  47. package/static/plugins.html +4 -4
  48. package/static/scripts/account.js +4 -4
  49. package/static/scripts/chat.js +40 -8
  50. package/static/scripts/workspace.js +78 -0
  51. package/static/sw.js +3 -1
  52. package/static/v3/asset-manifest.json +47 -0
  53. package/static/v3/css/lattice.base.css +128 -0
  54. package/static/v3/css/lattice.base.e4cdd05d.css +128 -0
  55. package/static/v3/css/lattice.components.011e988b.css +447 -0
  56. package/static/v3/css/lattice.components.css +447 -0
  57. package/static/v3/css/lattice.shell.4920f42d.css +407 -0
  58. package/static/v3/css/lattice.shell.css +407 -0
  59. package/static/v3/css/lattice.tokens.c597ff81.css +132 -0
  60. package/static/v3/css/lattice.tokens.css +132 -0
  61. package/static/v3/css/lattice.views.3ee19d4e.css +277 -0
  62. package/static/v3/css/lattice.views.css +277 -0
  63. package/static/v3/index.html +69 -0
  64. package/static/v3/js/app.46fb61d9.js +26 -0
  65. package/static/v3/js/app.js +26 -0
  66. package/static/v3/js/core/api.22a41d42.js +344 -0
  67. package/static/v3/js/core/api.js +344 -0
  68. package/static/v3/js/core/components.4c83e0a9.js +222 -0
  69. package/static/v3/js/core/components.js +222 -0
  70. package/static/v3/js/core/dom.a2773eb0.js +148 -0
  71. package/static/v3/js/core/dom.js +148 -0
  72. package/static/v3/js/core/router.584570f2.js +37 -0
  73. package/static/v3/js/core/router.js +37 -0
  74. package/static/v3/js/core/routes.f935dd50.js +78 -0
  75. package/static/v3/js/core/routes.js +78 -0
  76. package/static/v3/js/core/shell.1b6199d6.js +363 -0
  77. package/static/v3/js/core/shell.js +363 -0
  78. package/static/v3/js/core/store.34ebd5e6.js +113 -0
  79. package/static/v3/js/core/store.js +113 -0
  80. package/static/v3/js/views/admin-audit.660a1fb1.js +185 -0
  81. package/static/v3/js/views/admin-audit.js +185 -0
  82. package/static/v3/js/views/admin-permissions.a7ae5f09.js +177 -0
  83. package/static/v3/js/views/admin-permissions.js +177 -0
  84. package/static/v3/js/views/admin-policies.3658fd86.js +102 -0
  85. package/static/v3/js/views/admin-policies.js +102 -0
  86. package/static/v3/js/views/admin-private-vpc.7d342d36.js +135 -0
  87. package/static/v3/js/views/admin-private-vpc.js +135 -0
  88. package/static/v3/js/views/admin-security.07c66b72.js +180 -0
  89. package/static/v3/js/views/admin-security.js +180 -0
  90. package/static/v3/js/views/admin-users.03bac88c.js +168 -0
  91. package/static/v3/js/views/admin-users.js +168 -0
  92. package/static/v3/js/views/agents.14e48bdd.js +193 -0
  93. package/static/v3/js/views/agents.js +193 -0
  94. package/static/v3/js/views/chat.718144ce.js +449 -0
  95. package/static/v3/js/views/chat.js +449 -0
  96. package/static/v3/js/views/files.4935197e.js +186 -0
  97. package/static/v3/js/views/files.js +186 -0
  98. package/static/v3/js/views/home.cdde3b32.js +119 -0
  99. package/static/v3/js/views/home.js +119 -0
  100. package/static/v3/js/views/hybrid-search.b22b97e0.js +195 -0
  101. package/static/v3/js/views/hybrid-search.js +195 -0
  102. package/static/v3/js/views/knowledge-graph.a14ea7e7.js +237 -0
  103. package/static/v3/js/views/knowledge-graph.js +237 -0
  104. package/static/v3/js/views/models.a1ffa147.js +256 -0
  105. package/static/v3/js/views/models.js +256 -0
  106. package/static/v3/js/views/my-computer.1b2ff621.js +237 -0
  107. package/static/v3/js/views/my-computer.js +237 -0
  108. package/static/v3/js/views/pipeline.c522f1ce.js +157 -0
  109. package/static/v3/js/views/pipeline.js +157 -0
  110. package/static/v3/js/views/settings.4f777210.js +250 -0
  111. package/static/v3/js/views/settings.js +250 -0
  112. package/static/workflows.html +4 -4
  113. package/static/workspace.css +340 -2
  114. package/static/workspace.html +43 -24
  115. package/docs/images/tmp_frames/frame_00.png +0 -0
  116. package/docs/images/tmp_frames/frame_01.png +0 -0
  117. package/docs/images/tmp_frames/frame_02.png +0 -0
  118. package/docs/images/tmp_frames/frame_03.png +0 -0
  119. package/docs/images/tmp_frames/hero_00.png +0 -0
  120. package/docs/images/tmp_frames/hero_01.png +0 -0
  121. package/docs/images/tmp_frames/hero_02.png +0 -0
  122. package/docs/images/tmp_frames/hero_03.png +0 -0
@@ -0,0 +1,449 @@
1
+ /* ============================================================================
2
+ * View: Chat — a first-class v3 surface (NOT a preview that links out).
3
+ *
4
+ * Native to the /app shell: shares the design system, tokens, command palette,
5
+ * workspace switcher, and mode model. Talks to the REAL backend
6
+ * (POST /chat SSE + /history/* ) through the v3 adapter. Missing endpoints
7
+ * report unavailable state; a live "no model loaded" response stays a
8
+ * user-facing setup message instead of pretending to generate.
9
+ *
10
+ * Layout (flush, 3-pane): conversations · thread+composer · retrieval context
11
+ * (Knowledge Graph · Vector · Hybrid Search · indexed file references).
12
+ * ========================================================================== */
13
+
14
+ import { timeAgo } from "../core/dom.js";
15
+
16
+ export const layout = "flush";
17
+
18
+ export async function render(ctx) {
19
+ const { h, icon, api, store, c, params, navigate, toast } = ctx;
20
+
21
+ const state = {
22
+ conversations: [], convSource: "pending",
23
+ activeId: null, title: "New chat",
24
+ messages: [], // { role: "user"|"ai", content, source?, error? }
25
+ streaming: false, abort: null,
26
+ grounding: { graph: true, vector: true },
27
+ model: "", modelSource: "pending",
28
+ lastQuery: "", lastTrace: null,
29
+ graphCache: null,
30
+ };
31
+
32
+ /* ── element hosts ───────────────────────────────────────────────────── */
33
+ const listItems = h("div.lt3-chatlist__items", c.loading({ lines: 4 }));
34
+ const listSrc = h("span", c.sourceBadge("pending"));
35
+ const threadInner = h("div.lt3-chat__thread-inner");
36
+ const thread = h("div.lt3-chat__thread", { id: "lt3-chat-thread", role: "log", "aria-live": "polite", "aria-label": "Conversation" }, threadInner);
37
+ const titleEl = h("div.lt3-chat__title", state.title);
38
+ const modelPill = h("span", c.pill("model", "info", { dot: true }));
39
+ const barSrc = h("span", c.sourceBadge("pending"));
40
+ const ctxBody = h("div.lt3-chat__context-body", c.loading({ lines: 5 }));
41
+ const ctxSrc = h("span", c.sourceBadge("pending"));
42
+
43
+ const textarea = h("textarea", {
44
+ rows: "1", placeholder: "Message your workspace… (Enter to send · Shift+Enter for newline)",
45
+ "aria-label": "Message", autocomplete: "off",
46
+ on: {
47
+ input: autogrow,
48
+ keydown: (e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); send(); } },
49
+ },
50
+ });
51
+ const sendBtn = h("button.lt3-btn.lt3-btn--primary", { "aria-label": "Send", on: { click: send } }, icon("arrow-up"));
52
+
53
+ const groundChip = (key, label, icn) => h("button.lt3-chip", {
54
+ type: "button", dataset: { active: String(state.grounding[key]) }, "aria-pressed": String(state.grounding[key]),
55
+ title: `Toggle ${label} grounding`,
56
+ 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
+ }, icon(icn), label);
58
+
59
+ /* ── assembled shell ─────────────────────────────────────────────────── */
60
+ const chat = h("div.lt3-chat", { dataset: { list: "closed", context: "closed" } },
61
+ h("div.lt3-chat__scrim", { on: { click: closePanes } }),
62
+
63
+ // Conversations rail
64
+ h("aside.lt3-chatlist", { "aria-label": "Conversations" },
65
+ h("div.lt3-chatlist__head",
66
+ h("div.lt3-row", { style: { "justify-content": "space-between" } },
67
+ h("div.lt3-eyebrow", "Conversations"),
68
+ h("button.lt3-iconbtn.lt3-iconbtn--sm.lt3-chat__pane-close", { "aria-label": "Close conversations", on: { click: closePanes } }, icon("x")),
69
+ ),
70
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--block", { on: { click: () => startNew(true) } }, icon("message-plus"), "New chat"),
71
+ h("div.lt3-row", { style: { "justify-content": "space-between" } }, h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "History"), listSrc),
72
+ ),
73
+ listItems,
74
+ ),
75
+
76
+ // Main thread + composer
77
+ h("div.lt3-chat__main",
78
+ h("div.lt3-chat__bar",
79
+ h("button.lt3-iconbtn.lt3-chat__toggle-list", { "aria-label": "Conversations", on: { click: () => togglePane("list") } }, icon("layout-sidebar")),
80
+ h("div.lt3-avatar", { style: { background: "transparent", color: "var(--accent)" } }, icon("message-2")),
81
+ titleEl,
82
+ h("div.lt3-spacer"),
83
+ modelPill,
84
+ barSrc,
85
+ h("button.lt3-iconbtn.lt3-chat__toggle-context", { "aria-label": "Retrieval context", on: { click: () => togglePane("context") } }, icon("layout-sidebar-right")),
86
+ ),
87
+ thread,
88
+ h("div.lt3-composer",
89
+ h("div.lt3-composer__inner",
90
+ h("div.lt3-composer__box", textarea, sendBtn),
91
+ h("div.lt3-composer__tools",
92
+ groundChip("graph", "Knowledge Graph", "chart-dots-3"),
93
+ groundChip("vector", "Vector", "grid-dots"),
94
+ h("span.lt3-spacer"),
95
+ h("span.lt3-kbd", "↵"),
96
+ ),
97
+ h("div.lt3-composer__hint", "Answers are grounded in your local workspace via hybrid retrieval. Nothing leaves this machine."),
98
+ ),
99
+ ),
100
+ ),
101
+
102
+ // Retrieval context
103
+ h("aside.lt3-chat__context", { "aria-label": "Retrieval context" },
104
+ h("div.lt3-chat__context-head",
105
+ h("div.lt3-eyebrow", icon("stack-2"), "Retrieval context"),
106
+ h("div.lt3-row-2", ctxSrc, h("button.lt3-iconbtn.lt3-iconbtn--sm.lt3-chat__pane-close", { "aria-label": "Close context", on: { click: closePanes } }, icon("x"))),
107
+ ),
108
+ ctxBody,
109
+ ),
110
+ );
111
+
112
+ /* ── boot ────────────────────────────────────────────────────────────── */
113
+ loadModel();
114
+ loadConversations();
115
+ renderContext(""); // index-based defaults until the first answer
116
+ if (params.new) startNew(false); else loadInitial();
117
+
118
+ return chat;
119
+
120
+ /* ── conversations ───────────────────────────────────────────────────── */
121
+ async function loadConversations() {
122
+ const res = await api.chatHistory();
123
+ state.conversations = normalizeConversations(res.data);
124
+ state.convSource = res.source;
125
+ listSrc.replaceChildren(c.sourceBadge(res.source));
126
+ renderConversations();
127
+ }
128
+
129
+ function renderConversations() {
130
+ if (!state.conversations.length) {
131
+ listItems.replaceChildren(c.emptyState({ icon: "message-off", title: "No conversations", body: "Start a new chat to begin." }));
132
+ return;
133
+ }
134
+ listItems.replaceChildren(...state.conversations.map((conv) =>
135
+ h("button.lt3-convo", {
136
+ dataset: { active: String(conv.id === state.activeId) },
137
+ on: { click: () => selectConversation(conv.id) },
138
+ },
139
+ icon("message"),
140
+ h("div.lt3-convo__body",
141
+ h("div.lt3-convo__title", conv.title || "Untitled"),
142
+ conv.updated_at && h("div.lt3-convo__meta", timeAgo(conv.updated_at)),
143
+ ),
144
+ h("span.lt3-iconbtn.lt3-iconbtn--sm.lt3-convo__del", {
145
+ role: "button", tabindex: "0", "aria-label": "Delete conversation",
146
+ on: { click: (e) => { e.stopPropagation(); removeConversation(conv.id); } },
147
+ }, icon("trash")),
148
+ ),
149
+ ));
150
+ }
151
+
152
+ async function selectConversation(id) {
153
+ if (state.streaming) stopStreaming();
154
+ closePanes();
155
+ state.activeId = id;
156
+ const conv = state.conversations.find((x) => x.id === id);
157
+ state.title = conv ? conv.title : "Conversation";
158
+ titleEl.textContent = state.title;
159
+ state.lastTrace = null;
160
+ renderConversations();
161
+ threadInner.replaceChildren(c.loading({ lines: 4 }));
162
+ const res = await api.conversation(id);
163
+ if (state.activeId !== id) return;
164
+ state.messages = (res.data || []).map((m) => ({
165
+ role: m.role === "assistant" ? "ai" : "user",
166
+ content: m.content || "",
167
+ source: res.source,
168
+ }));
169
+ renderMessages();
170
+ const lastUser = [...state.messages].reverse().find((m) => m.role === "user");
171
+ renderContext(lastUser ? lastUser.content : "");
172
+ }
173
+
174
+ function startNew(userInitiated) {
175
+ if (state.streaming) stopStreaming();
176
+ closePanes();
177
+ state.activeId = null;
178
+ state.title = "New chat";
179
+ state.messages = [];
180
+ state.lastTrace = null;
181
+ titleEl.textContent = state.title;
182
+ renderConversations();
183
+ renderMessages();
184
+ renderContext("");
185
+ if (userInitiated) { try { textarea.focus(); } catch {} navigate("chat", { new: "1" }); }
186
+ }
187
+
188
+ async function removeConversation(id) {
189
+ await api.deleteConversation(id);
190
+ state.conversations = state.conversations.filter((x) => x.id !== id);
191
+ if (state.activeId === id) startNew(false);
192
+ else renderConversations();
193
+ toast("Conversation removed", "ok");
194
+ }
195
+
196
+ /* ── messages / thread ───────────────────────────────────────────────── */
197
+ function renderMessages() {
198
+ if (!state.messages.length) {
199
+ threadInner.replaceChildren(emptyThread());
200
+ return;
201
+ }
202
+ threadInner.replaceChildren(...state.messages.map((m) => messageNode(m)));
203
+ scrollToBottom();
204
+ }
205
+
206
+ function emptyThread() {
207
+ return h("div.lt3-empty", { style: { margin: "auto 0" } },
208
+ h("div.lt3-empty__icon", icon("sparkles")),
209
+ h("div.lt3-empty__title", "Ask anything about your workspace"),
210
+ h("div.lt3-empty__body", "Grounded in your knowledge graph and vector index via hybrid retrieval. Try a question, or pick a starter below."),
211
+ h("div.lt3-cluster", { style: { "justify-content": "center", "margin-top": "var(--lt3-space-2)" } },
212
+ ...["How does hybrid search rank results?", "What entities are in my notes?", "Summarize retrieval.md"].map((q) =>
213
+ h("button.lt3-chip", { on: { click: () => { textarea.value = q; autogrow(); send(); } } }, icon("arrow-up-right"), q)),
214
+ ),
215
+ );
216
+ }
217
+
218
+ function messageNode(m) {
219
+ const isUser = m.role === "user";
220
+ const body = h("div.lt3-msg__body",
221
+ h("div.lt3-msg__bubble", m.content),
222
+ m.role === "ai" && m.source && h("div.lt3-row-2", c.sourceBadge(m.source)),
223
+ );
224
+ return h(`div.lt3-msg.lt3-msg--${isUser ? "user" : "ai"}`,
225
+ h("div.lt3-msg__avatar", icon(isUser ? "user" : "sparkles")),
226
+ body,
227
+ );
228
+ }
229
+
230
+ function scrollToBottom() { requestAnimationFrame(() => { thread.scrollTop = thread.scrollHeight; }); }
231
+
232
+ function autogrow() {
233
+ textarea.style.height = "auto";
234
+ textarea.style.height = Math.min(200, textarea.scrollHeight) + "px";
235
+ }
236
+
237
+ /* ── send + stream ───────────────────────────────────────────────────── */
238
+ async function send() {
239
+ const text = textarea.value.trim();
240
+ if (!text || state.streaming) return;
241
+ textarea.value = ""; autogrow();
242
+
243
+ if (!state.messages.length) threadInner.replaceChildren();
244
+ const userMsg = { role: "user", content: text };
245
+ state.messages.push(userMsg);
246
+ threadInner.append(messageNode(userMsg));
247
+ state.lastQuery = text;
248
+ if (!state.activeId) { state.title = text.slice(0, 48); titleEl.textContent = state.title; }
249
+
250
+ // streaming AI bubble
251
+ const bubble = h("div.lt3-msg__bubble");
252
+ const srcRow = h("div.lt3-row-2");
253
+ const aiNode = h("div.lt3-msg.lt3-msg--ai",
254
+ h("div.lt3-msg__avatar", icon("sparkles")),
255
+ h("div.lt3-msg__body", bubble, srcRow),
256
+ );
257
+ bubble.append(typingIndicator());
258
+ threadInner.append(aiNode);
259
+ scrollToBottom();
260
+
261
+ state.streaming = true;
262
+ state.abort = new AbortController();
263
+ setComposerStreaming(true);
264
+ let started = false;
265
+
266
+ const result = await api.streamChat(
267
+ { message: text, conversation_id: state.activeId, grounding: state.grounding },
268
+ {
269
+ signal: state.abort.signal,
270
+ onChunk: (_delta, full) => {
271
+ if (!started) { started = true; bubble.replaceChildren(); }
272
+ bubble.textContent = full;
273
+ scrollToBottom();
274
+ },
275
+ onTrace: (trace) => { state.lastTrace = trace; renderContext(text); },
276
+ },
277
+ );
278
+
279
+ state.streaming = false;
280
+ state.abort = null;
281
+ setComposerStreaming(false);
282
+
283
+ if (result.aborted) {
284
+ if (!result.text) { bubble.textContent = "(stopped)"; bubble.classList.add("lt3-faint"); }
285
+ return;
286
+ }
287
+ if (result.error === "no_model_loaded") {
288
+ aiNode.replaceWith(errorNode(text, result));
289
+ return;
290
+ }
291
+ if (!result.text) {
292
+ aiNode.replaceWith(errorNode(text, result));
293
+ return;
294
+ }
295
+ bubble.textContent = result.text;
296
+ state.messages.push({ role: "ai", content: result.text, source: result.source });
297
+ srcRow.replaceChildren(c.sourceBadge(result.source));
298
+ if (!state.lastTrace) renderContext(text);
299
+ refreshConversationMeta();
300
+ scrollToBottom();
301
+ }
302
+
303
+ function errorNode(retryText, result = {}) {
304
+ const noModel = result.error === "no_model_loaded";
305
+ return h("div.lt3-msg.lt3-msg--ai",
306
+ h("div.lt3-msg__avatar", icon("alert-triangle")),
307
+ h("div.lt3-msg__body",
308
+ h("div.lt3-banner.lt3-banner--err",
309
+ icon("alert-triangle"),
310
+ h("div", h("div", { style: { fontWeight: 600 } }, noModel ? "No local model loaded" : "Couldn't reach the model"),
311
+ h("div.lt3-faint", noModel
312
+ ? "Load a local or OpenAI-compatible model from Models, then retry this message."
313
+ : "The chat backend isn't responding. Check the local runtime and retry.")),
314
+ h("div.lt3-row-2", { style: { "margin-left": "auto" } },
315
+ noModel && h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => navigate("models") } }, icon("cpu"), "Models"),
316
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { textarea.value = retryText; autogrow(); send(); } } }, icon("refresh"), "Retry"),
317
+ ),
318
+ ),
319
+ ),
320
+ );
321
+ }
322
+
323
+ function typingIndicator() { return h("span.lt3-typing", { "aria-label": "Assistant is typing" }, h("i"), h("i"), h("i")); }
324
+
325
+ function setComposerStreaming(on) {
326
+ if (on) {
327
+ sendBtn.replaceChildren(icon("player-stop"));
328
+ sendBtn.setAttribute("aria-label", "Stop");
329
+ sendBtn.onclick = stopStreaming;
330
+ } else {
331
+ sendBtn.replaceChildren(icon("arrow-up"));
332
+ sendBtn.setAttribute("aria-label", "Send");
333
+ sendBtn.onclick = send;
334
+ }
335
+ }
336
+
337
+ function stopStreaming() { if (state.abort) { try { state.abort.abort(); } catch {} } }
338
+
339
+ function refreshConversationMeta() {
340
+ // New, unsaved conversation — reload the list so the backend-assigned id /
341
+ // title appears once persisted.
342
+ if (!state.activeId && state.messages.length) loadConversations();
343
+ }
344
+
345
+ /* ── retrieval context (KG · Vector · Hybrid · files) ────────────────── */
346
+ async function renderContext(query) {
347
+ const q = (query || "").trim();
348
+ let hybrid = [], hybridSource = "pending";
349
+ if (q) { const hs = await api.hybridSearch(q, { mode: groundingMode() }); hybrid = hs.data || []; hybridSource = hs.source; }
350
+
351
+ if (!state.graphCache) state.graphCache = await api.graph();
352
+ const graphNodes = (state.lastTrace && state.lastTrace.graph_nodes) ||
353
+ ((state.graphCache.data.nodes || []).slice(0, 5).map((n) => ({ id: n.id, title: n.label || n.title, type: n.type })));
354
+ const vectorMatches = (state.lastTrace && state.lastTrace.vector_matches) ||
355
+ hybrid.map((r) => ({ path: r.path, score: r.vector }));
356
+ const fileRefs = (state.lastTrace && state.lastTrace.source_files && state.lastTrace.source_files.map((s) => s.source)) ||
357
+ [...new Set(hybrid.map((r) => r.path))];
358
+
359
+ const overall = q ? hybridSource : state.graphCache.source;
360
+ ctxSrc.replaceChildren(c.sourceBadge(overall));
361
+
362
+ ctxBody.replaceChildren(
363
+ ctxSection("Knowledge graph", "chart-dots-3",
364
+ graphNodes.length
365
+ ? graphNodes.slice(0, 6).map((n) => ctxItem("var(--lt3-pillar-graph)", n.title || n.id, n.type))
366
+ : [ctxEmpty("No linked entities yet")]),
367
+
368
+ ctxSection("Vector matches", "grid-dots",
369
+ vectorMatches.length
370
+ ? vectorMatches.slice(0, 5).map((v) => ctxItem("var(--lt3-pillar-vector)", v.path, v.score != null ? v.score.toFixed(2) : null))
371
+ : [ctxEmpty("Run a query to see vector matches")]),
372
+
373
+ ctxSection("Hybrid search", "arrows-join",
374
+ hybrid.length
375
+ ? hybrid.slice(0, 4).map((r) => ctxItem("var(--lt3-pillar-hybrid)", r.title || r.path, r.score != null ? r.score.toFixed(2) : null))
376
+ : [ctxEmpty("Ask a question to fuse graph + vector")]),
377
+
378
+ ctxSection("Indexed files", "files",
379
+ fileRefs.length
380
+ ? fileRefs.slice(0, 6).map((p) => ctxItem("var(--faint)", p, null))
381
+ : [ctxEmpty("No file references yet")]),
382
+
383
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm.lt3-btn--block", { on: { click: () => navigate("hybrid-search", q ? { q } : undefined) } }, icon("arrows-join"), "Open Hybrid Search"),
384
+ );
385
+ }
386
+
387
+ function ctxSection(title, icn, children) {
388
+ return h("section",
389
+ h("div.lt3-ctx-sec__title", icon(icn), title),
390
+ h("div", children),
391
+ );
392
+ }
393
+ function ctxItem(color, label, score) {
394
+ return h("div.lt3-ctx-item",
395
+ h("span.lt3-ctx-item__dot", { style: { background: color } }),
396
+ h("span.lt3-ctx-item__label", { title: String(label) }, String(label)),
397
+ score != null && h("span.lt3-ctx-item__score", String(score)),
398
+ );
399
+ }
400
+ function ctxEmpty(text) { return h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)", padding: "var(--lt3-space-1) 0" } }, text); }
401
+
402
+ function groundingMode() {
403
+ if (state.grounding.graph && state.grounding.vector) return "hybrid";
404
+ if (state.grounding.vector) return "vector";
405
+ if (state.grounding.graph) return "graph";
406
+ return "hybrid";
407
+ }
408
+
409
+ /* ── misc ────────────────────────────────────────────────────────────── */
410
+ async function loadModel() {
411
+ const res = await api.models();
412
+ state.model = (res.data && res.data.current) || "";
413
+ state.modelSource = res.source;
414
+ modelPill.replaceChildren(c.pill(state.model ? shortModel(state.model) : "No model", state.model ? "info" : "warn", { dot: true }));
415
+ barSrc.replaceChildren(c.sourceBadge(res.source));
416
+ }
417
+
418
+ function loadInitial() {
419
+ // Land on the most recent conversation if one exists, else an empty thread.
420
+ api.chatHistory().then((res) => {
421
+ const list = normalizeConversations(res.data);
422
+ if (list.length) selectConversation(list[0].id);
423
+ else renderMessages();
424
+ });
425
+ }
426
+
427
+ function togglePane(which) {
428
+ const other = which === "list" ? "context" : "list";
429
+ chat.dataset[other] = "closed";
430
+ chat.dataset[which] = chat.dataset[which] === "open" ? "closed" : "open";
431
+ }
432
+ function closePanes() { chat.dataset.list = "closed"; chat.dataset.context = "closed"; }
433
+ }
434
+
435
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
436
+ function normalizeConversations(data) {
437
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.conversations) ? data.conversations : []);
438
+ return list.map((conv, i) => ({
439
+ id: conv.id || conv.conversation_id || `conv-${i}`,
440
+ title: conv.title || conv.name || "Untitled",
441
+ updated_at: conv.updated_at || conv.last_message_at || conv.timestamp || null,
442
+ }));
443
+ }
444
+
445
+ function shortModel(id) {
446
+ const s = String(id || "model");
447
+ const tail = s.includes("/") ? s.split("/").pop() : s;
448
+ return tail.length > 22 ? tail.slice(0, 21) + "…" : tail;
449
+ }
@@ -0,0 +1,186 @@
1
+ /* ============================================================================
2
+ * View: Files — connected sources & indexed documents.
3
+ * Lists the sources the workspace has indexed, with a human-readable status
4
+ * roll-up. Data comes from /workspace/indexing (live); when indexing is
5
+ * unavailable, the table renders an empty unavailable state.
6
+ *
7
+ * View contract (shared by all views):
8
+ * export async function render(ctx) -> single DOM node
9
+ * ctx = { h, icon, api, store, c, route, params, navigate, toast }
10
+ * ========================================================================== */
11
+
12
+ import { timeAgo } from "../core/dom.a2773eb0.js";
13
+
14
+ /** Tabler glyph per file kind — keeps the table scannable. */
15
+ const KIND_ICON = {
16
+ markdown: "file-text",
17
+ config: "settings",
18
+ image: "photo",
19
+ data: "table",
20
+ default: "file",
21
+ };
22
+ const iconForKind = (k) => KIND_ICON[k] || KIND_ICON.default;
23
+
24
+ /** Bytes → compact human string (1.0 KB / 4.7 KB / 180 KB / 1.2 MB). */
25
+ function humanSize(bytes) {
26
+ if (bytes === null || bytes === undefined || bytes === "") return "—";
27
+ const n = Number(bytes);
28
+ if (!Number.isFinite(n) || n < 0) return "—";
29
+ if (n < 1024) return `${n} B`;
30
+ const units = ["KB", "MB", "GB", "TB"];
31
+ let v = n / 1024, i = 0;
32
+ while (v >= 1024 && i < units.length - 1) { v /= 1024; i++; }
33
+ return `${v.toFixed(v >= 100 || Number.isInteger(v) ? 0 : 1)} ${units[i]}`;
34
+ }
35
+
36
+ /** Live shape is {sources:[...]}; legacy {files:[...]} payloads normalize too. */
37
+ function normalize(data) {
38
+ if (data && Array.isArray(data.sources)) {
39
+ return data.sources.map((source) => ({
40
+ name: source.label || source.id || "local source",
41
+ kind: "default",
42
+ size: null,
43
+ path: source.root_path || source.id || "",
44
+ indexed: Number(source.success_count || 0) > 0,
45
+ updated: source.last_run_at || source.updated_at || null,
46
+ count: Number(source.success_count || 0),
47
+ status: source.status || (source.watch_active ? "watching" : "idle"),
48
+ }));
49
+ }
50
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.files) ? data.files : null);
51
+ if (!list) return null;
52
+ return list.map((f) => ({
53
+ name: f.name || (f.path ? String(f.path).split("/").pop() : "untitled"),
54
+ kind: f.kind || "default",
55
+ size: Number(f.size) || 0,
56
+ path: f.path || f.name || "",
57
+ indexed: f.indexed === true,
58
+ updated: f.updated || f.modified || f.mtime || null,
59
+ count: Number(f.count || 0),
60
+ status: f.status || null,
61
+ }));
62
+ }
63
+
64
+ export async function render(ctx) {
65
+ const { h, icon, api, c, navigate, toast } = ctx;
66
+
67
+ // Folder connection/watch needs the desktop local-agent connector, which is
68
+ // not enabled in this build. Say so plainly rather than implying it's coming.
69
+ const unavailableToast = () =>
70
+ toast("Connecting a folder requires the Lattice desktop local agent — not available in this build.", "warn");
71
+
72
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
73
+ const srcSlot = h("span", c.sourceBadge("pending"));
74
+ const tableHost = h("div", c.loading({ lines: 4 }));
75
+
76
+ const root = h("div.lt3-stack-6",
77
+ c.viewHeader({
78
+ eyebrow: "Data",
79
+ title: "Files",
80
+ sub: "Connected sources and the documents Lattice has indexed for retrieval. Everything stays on this machine.",
81
+ actions: [
82
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => navigate("knowledge-graph") } }, icon("chart-dots-3"), "View graph"),
83
+ h("button.lt3-btn.lt3-btn--ghost", { title: "Requires the desktop local agent (not in this build)", on: { click: unavailableToast } }, icon("folder-plus"), "Connect folder"),
84
+ ],
85
+ }),
86
+ statHost,
87
+ h("div.lt3-drop",
88
+ h("div.lt3-pillar__icon", icon("cloud-upload")),
89
+ h("div",
90
+ h("div", { style: { "font-weight": "var(--lt3-weight-semi)" } }, "Drag files or connect a folder"),
91
+ h("p.lt3-faint", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-1)" } },
92
+ "Lattice watches the source, chunks it, embeds it, and links it into the knowledge graph."),
93
+ ),
94
+ h("button.lt3-btn.lt3-btn--ghost", { title: "Requires the desktop local agent (not in this build)", on: { click: unavailableToast } }, icon("folder-plus"), "Choose folder"),
95
+ ),
96
+ c.panel({
97
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", width: "100%" } },
98
+ h("div",
99
+ h("div.lt3-eyebrow", "Index"),
100
+ h("h3.lt3-panel__title", "Indexed documents"),
101
+ ),
102
+ srcSlot,
103
+ ),
104
+ children: tableHost,
105
+ }),
106
+ );
107
+
108
+ hydrate(ctx, { statHost, srcSlot, tableHost });
109
+ return root;
110
+ }
111
+
112
+ async function hydrate(ctx, slots) {
113
+ const { h, icon, api, c, toast } = ctx;
114
+ const { statHost, srcSlot, tableHost } = slots;
115
+
116
+ const probe = await api.get("/workspace/indexing", { sources: [], totals: {} });
117
+ const liveFiles = probe.ok && probe.data ? normalize(probe.data) : null;
118
+ const source = probe.source || (liveFiles ? "live" : "unavailable");
119
+ const files = liveFiles || [];
120
+ srcSlot.replaceChildren(c.sourceBadge(source));
121
+
122
+ // ── Stat roll-up ──────────────────────────────────────────────────────────
123
+ const indexedCount = files.filter((f) => f.indexed).length;
124
+ const sourceCount = new Set(
125
+ files.map((f) => (f.path.includes("/") ? f.path.split("/")[0] : "root")),
126
+ ).size;
127
+ const totalBytes = files.reduce((sum, f) => sum + (f.size || 0), 0);
128
+ statHost.replaceChildren(
129
+ c.stat({ label: "Total files", value: c.fmtNum(files.length), icon: "files" }),
130
+ c.stat({ label: "Indexed", value: c.fmtNum(indexedCount), icon: "circle-check" }),
131
+ c.stat({ label: "Sources", value: c.fmtNum(sourceCount), icon: "database" }),
132
+ c.stat({ label: "Total size", value: humanSize(totalBytes), icon: "weight" }),
133
+ );
134
+
135
+ // ── Empty state ─────────────────────────────────────────────────────────────
136
+ if (!files.length) {
137
+ tableHost.replaceChildren(c.emptyState({
138
+ icon: "folder-off",
139
+ title: "No documents indexed yet",
140
+ body: "Connect a folder and Lattice will index it for hybrid retrieval.",
141
+ action: h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm",
142
+ { title: "Requires the desktop local agent (not in this build)",
143
+ on: { click: () => toast("Connecting a folder requires the Lattice desktop local agent — not available in this build.", "warn") } },
144
+ icon("folder-plus"), "Connect folder"),
145
+ }));
146
+ return;
147
+ }
148
+
149
+ // ── Table ───────────────────────────────────────────────────────────────────
150
+ const columns = [
151
+ {
152
+ key: "name", label: "Name",
153
+ render: (row) => h("div.lt3-row-2",
154
+ h("span.lt3-filerow__icon", icon(iconForKind(row.kind))),
155
+ h("span", { style: { "font-weight": "var(--lt3-weight-medium)" } }, row.name),
156
+ ),
157
+ },
158
+ {
159
+ key: "path", label: "Path", width: "30%",
160
+ render: (row) => h("span.lt3-mono.lt3-faint", row.path || "—"),
161
+ },
162
+ {
163
+ key: "count", label: "Indexed", width: "92px",
164
+ render: (row) => h("span.lt3-mono", row.count ? c.fmtNum(row.count) : humanSize(row.size)),
165
+ },
166
+ {
167
+ key: "status", label: "Status", width: "120px",
168
+ render: (row) => c.statePill(row.indexed ? "indexed" : (row.status || "pending")),
169
+ },
170
+ {
171
+ key: "updated", label: "Updated", width: "104px",
172
+ render: (row) => h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } },
173
+ row.updated ? timeAgo(row.updated) : "—"),
174
+ },
175
+ {
176
+ key: "_actions", label: "", width: "44px",
177
+ render: (row) => h("button.lt3-iconbtn.lt3-iconbtn--sm", {
178
+ "aria-label": `Actions for ${row.name}`,
179
+ title: "Requires the desktop local agent (not in this build)",
180
+ on: { click: () => toast(`Per-file actions require the Lattice desktop local agent — not available in this build.`, "warn") },
181
+ }, icon("dots-vertical")),
182
+ },
183
+ ];
184
+
185
+ tableHost.replaceChildren(c.table(columns, files));
186
+ }