ltcai 2.2.7 → 3.0.1

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 (69) hide show
  1. package/README.md +63 -32
  2. package/docs/CHANGELOG.md +82 -0
  3. package/docs/V3_BACKEND_ARCHITECTURE.md +138 -0
  4. package/docs/V3_FRONTEND.md +136 -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 +1 -1
  10. package/latticeai/api/chat.py +10 -2
  11. package/latticeai/api/search.py +236 -0
  12. package/latticeai/api/static_routes.py +11 -2
  13. package/latticeai/core/config.py +16 -0
  14. package/latticeai/core/embedding_providers.py +502 -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 +49 -1
  18. package/latticeai/services/agent_runtime.py +245 -0
  19. package/latticeai/services/search_service.py +346 -0
  20. package/package.json +6 -4
  21. package/static/account.html +9 -9
  22. package/static/activity.html +4 -4
  23. package/static/admin.html +8 -8
  24. package/static/agents.html +4 -4
  25. package/static/chat.html +10 -10
  26. package/static/css/reference/account.css +137 -1
  27. package/static/css/reference/chat.css +31 -37
  28. package/static/css/responsive.css +42 -0
  29. package/static/css/tokens.css +125 -130
  30. package/static/graph.html +9 -9
  31. package/static/manifest.json +3 -3
  32. package/static/plugins.html +4 -4
  33. package/static/scripts/account.js +4 -4
  34. package/static/scripts/chat.js +40 -8
  35. package/static/scripts/workspace.js +78 -0
  36. package/static/v3/css/lattice.base.css +128 -0
  37. package/static/v3/css/lattice.components.css +447 -0
  38. package/static/v3/css/lattice.shell.css +407 -0
  39. package/static/v3/css/lattice.tokens.css +132 -0
  40. package/static/v3/css/lattice.views.css +277 -0
  41. package/static/v3/index.html +40 -0
  42. package/static/v3/js/app.js +26 -0
  43. package/static/v3/js/core/api.js +327 -0
  44. package/static/v3/js/core/components.js +215 -0
  45. package/static/v3/js/core/dom.js +148 -0
  46. package/static/v3/js/core/fixtures.js +171 -0
  47. package/static/v3/js/core/router.js +37 -0
  48. package/static/v3/js/core/routes.js +73 -0
  49. package/static/v3/js/core/shell.js +363 -0
  50. package/static/v3/js/core/store.js +113 -0
  51. package/static/v3/js/views/admin-audit.js +185 -0
  52. package/static/v3/js/views/admin-permissions.js +178 -0
  53. package/static/v3/js/views/admin-policies.js +103 -0
  54. package/static/v3/js/views/admin-private-vpc.js +138 -0
  55. package/static/v3/js/views/admin-security.js +181 -0
  56. package/static/v3/js/views/admin-users.js +168 -0
  57. package/static/v3/js/views/agents.js +194 -0
  58. package/static/v3/js/views/chat.js +450 -0
  59. package/static/v3/js/views/files.js +180 -0
  60. package/static/v3/js/views/home.js +119 -0
  61. package/static/v3/js/views/hybrid-search.js +195 -0
  62. package/static/v3/js/views/knowledge-graph.js +238 -0
  63. package/static/v3/js/views/models.js +247 -0
  64. package/static/v3/js/views/my-computer.js +237 -0
  65. package/static/v3/js/views/pipeline.js +161 -0
  66. package/static/v3/js/views/settings.js +258 -0
  67. package/static/workflows.html +4 -4
  68. package/static/workspace.css +340 -2
  69. package/static/workspace.html +43 -24
@@ -0,0 +1,247 @@
1
+ /* ============================================================================
2
+ * View: Models — the local MLX runtime.
3
+ * Lists the language models available to the runtime, highlights the loaded
4
+ * one, and shows the local embedding signal that backs the Vector Index.
5
+ * Falls back to clearly-badged sample data when the runtime endpoint isn't
6
+ * available.
7
+ *
8
+ * View contract (shared by all views):
9
+ * export async function render(ctx) -> single DOM node
10
+ * ctx = { h, icon, api, store, c, route, params, navigate, toast }
11
+ * ========================================================================== */
12
+
13
+ const PENDING = "Load and unload models from the classic runtime surface (/workspace → Models); this view is read-only.";
14
+
15
+ export async function render(ctx) {
16
+ const { h, icon, api, c } = ctx;
17
+
18
+ const srcSlot = h("span", c.sourceBadge("pending"));
19
+ const activeHost = h("div", c.loading({ lines: 2, block: true }));
20
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
21
+ const embedHost = h("div", c.loading({ lines: 2 }));
22
+ const tableHost = h("div", c.loading({ lines: 4 }));
23
+
24
+ const root = h("div.lt3-stack-6",
25
+ c.viewHeader({
26
+ eyebrow: "Compute",
27
+ title: "Models",
28
+ sub: "Local and OpenAI-compatible runtime choices. Local models keep generation on this machine; cloud-compatible providers are shown only when configured.",
29
+ actions: [
30
+ srcSlot,
31
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Refresh"),
32
+ ],
33
+ }),
34
+ activeHost,
35
+ statHost,
36
+ c.panel({
37
+ eyebrow: "Retrieval",
38
+ title: "Embedding models",
39
+ sub: "The current default vector signal is lattice-local-hash-v1 fallback embeddings; future local providers can replace it behind the same index.",
40
+ children: embedHost,
41
+ }),
42
+ c.panel({
43
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", width: "100%" } },
44
+ h("div", h("div.lt3-eyebrow", "Runtime"), h("h3.lt3-panel__title", "Model catalog")),
45
+ h("span", { id: "models-cat-src" }, c.sourceBadge("pending")),
46
+ ),
47
+ children: tableHost,
48
+ }),
49
+ );
50
+
51
+ async function load() {
52
+ activeHost.replaceChildren(c.loading({ lines: 2, block: true }));
53
+ tableHost.replaceChildren(c.loading({ lines: 4 }));
54
+ embedHost.replaceChildren(c.loading({ lines: 2 }));
55
+
56
+ const [res, emb] = await Promise.all([api.models(), api.embeddingsStatus()]);
57
+ const data = res.data || {};
58
+ const catalog = Array.isArray(data.catalog) ? data.catalog : [];
59
+
60
+ srcSlot.replaceChildren(c.sourceBadge(res.source));
61
+ root.querySelector("#models-cat-src")?.replaceChildren(c.sourceBadge(res.source));
62
+
63
+ if (!catalog.length) {
64
+ activeHost.replaceChildren(
65
+ c.emptyState({ icon: "cpu-off", title: "No models on this machine", body: "Pull an MLX model into the local runtime to get started." }),
66
+ );
67
+ statHost.replaceChildren();
68
+ renderEmbeddings([], emb);
69
+ tableHost.replaceChildren(c.emptyState({ icon: "cpu-off", title: "Catalog is empty", body: "Connect the MLX runtime to list installed models." }));
70
+ return;
71
+ }
72
+
73
+ const isEmbedding = (m) => String(m.family || "").toLowerCase() === "embedding";
74
+ const language = catalog.filter((m) => !isEmbedding(m));
75
+ const embeddings = catalog.filter(isEmbedding);
76
+ const loaded = catalog.filter((m) => String(m.state).toLowerCase() === "loaded");
77
+ const active = catalog.find((m) => m.id === data.current)
78
+ || loaded.find((m) => !isEmbedding(m))
79
+ || language[0]
80
+ || catalog[0];
81
+
82
+ renderActive(active);
83
+ renderStats(catalog, embeddings, loaded);
84
+ renderEmbeddings(embeddings, emb);
85
+ renderCatalog(language.length ? language : catalog);
86
+ }
87
+
88
+ function renderActive(m) {
89
+ if (!m) { activeHost.replaceChildren(); return; }
90
+ activeHost.replaceChildren(
91
+ c.card(
92
+ h("div.lt3-stack-3",
93
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "flex-start", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
94
+ h("div.lt3-row-2", { style: { "align-items": "center", gap: "var(--lt3-space-3)" } },
95
+ h("div.lt3-pillar__icon", { style: { background: "var(--lt3-pillar-hybrid-soft)", color: "var(--lt3-pillar-hybrid)" } }, icon("cpu")),
96
+ h("div",
97
+ h("div.lt3-eyebrow", "Active model"),
98
+ h("div", { style: { "font-size": "var(--lt3-text-xl)", "font-weight": 800, "letter-spacing": "-0.01em" } }, m.name || m.id),
99
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)", "margin-top": "var(--lt3-space-1)" } }, m.id),
100
+ ),
101
+ ),
102
+ h("div.lt3-cluster", { style: { "align-items": "center" } },
103
+ m.recommended ? c.pill("Recommended", "info") : null,
104
+ c.statePill("loaded"),
105
+ ),
106
+ ),
107
+ h("div.lt3-cluster",
108
+ specChip(ctx, "category", "Family", titleCase(m.family || "local")),
109
+ specChip(ctx, "stack-2", "Params", m.params || "—"),
110
+ specChip(ctx, "binary", "Quant", m.quant || "—"),
111
+ specChip(ctx, "ruler-2", "Context", c.fmtNum(m.context) + " tok"),
112
+ ),
113
+ ),
114
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-hybrid) 32%, var(--border)); background: var(--lt3-pillar-hybrid-soft)" } },
115
+ ),
116
+ );
117
+ }
118
+
119
+ function renderStats(catalog, embeddings, loaded) {
120
+ const maxCtx = catalog.reduce((mx, m) => Math.max(mx, Number(m.context) || 0), 0);
121
+ statHost.replaceChildren(
122
+ c.stat({ label: "Loaded", value: c.fmtNum(loaded.length), icon: "player-play" }),
123
+ c.stat({ label: "Available", value: c.fmtNum(catalog.length), icon: "stack-2" }),
124
+ c.stat({ label: "Embedding models", value: c.fmtNum(embeddings.length), icon: "grid-dots" }),
125
+ c.stat({ label: "Max context", value: c.fmtNum(maxCtx) + " tok", icon: "ruler-2" }),
126
+ );
127
+ }
128
+
129
+ function renderEmbeddings(embeddings, emb) {
130
+ const statusCard = embeddingStatusCard(ctx, emb);
131
+ if (!embeddings.length) {
132
+ embedHost.replaceChildren(h("div.lt3-stack-4",
133
+ statusCard,
134
+ c.emptyState({ icon: "grid-dots", title: "No catalog embedding models", body: "The active provider above powers the Vector Index. Pull a semantic embedding model to list it here." }),
135
+ ));
136
+ return;
137
+ }
138
+ embedHost.replaceChildren(h("div.lt3-stack-4",
139
+ statusCard,
140
+ h("div.lt3-grid-auto",
141
+ embeddings.map((m) => c.card(
142
+ h("div.lt3-stack-2",
143
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "center" } },
144
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
145
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
146
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
147
+ ),
148
+ c.statePill(m.state),
149
+ ),
150
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
151
+ h("div.lt3-cluster",
152
+ c.pill(`${m.params || "—"} params`, ""),
153
+ c.pill(m.quant || "—", ""),
154
+ c.pill(`${c.fmtNum(m.context)} ctx`, ""),
155
+ ),
156
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Powers the Vector Index → Hybrid Search."),
157
+ ),
158
+ { flat: true },
159
+ )),
160
+ ),
161
+ ));
162
+ }
163
+
164
+ function renderCatalog(rows) {
165
+ const columns = [
166
+ { key: "name", label: "Model", render: (m) => h("div.lt3-stack-2", { style: { gap: "2px" } },
167
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
168
+ h("span.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
169
+ ) },
170
+ { key: "family", label: "Family", render: (m) => titleCase(m.family || "local") },
171
+ { key: "params", label: "Params", render: (m) => h("span.lt3-mono", m.params || "—") },
172
+ { key: "quant", label: "Quant", render: (m) => h("span.lt3-mono", m.quant || "—") },
173
+ { key: "context", label: "Context", render: (m) => h("span.lt3-mono", c.fmtNum(m.context)) },
174
+ { key: "state", label: "State", render: (m) => c.statePill(m.state) },
175
+ { key: "action", label: "", width: "1%", render: (m) => actionButton(m) },
176
+ ];
177
+ tableHost.replaceChildren(
178
+ c.table(columns, rows, {
179
+ empty: c.emptyState({ icon: "cpu-off", title: "No language models", body: "Pull an MLX chat model into the runtime." }),
180
+ }),
181
+ );
182
+ }
183
+
184
+ function actionButton(m) {
185
+ const loaded = String(m.state).toLowerCase() === "loaded";
186
+ const label = loaded ? "Unload" : "Load";
187
+ const ic = loaded ? "player-stop" : "player-play";
188
+ return h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm",
189
+ { "aria-label": `${label} ${m.name || m.id}`, on: { click: () => ctx.toast(PENDING, "info") } },
190
+ icon(ic), label,
191
+ );
192
+ }
193
+
194
+ load();
195
+ return root;
196
+ }
197
+
198
+ /* ── Active embedding provider status (real /api/embeddings/status) ──────── */
199
+ function embeddingStatusCard(ctx, emb) {
200
+ const { h, icon, c } = ctx;
201
+ const d = (emb && emb.data) || {};
202
+ const state = String(d.state || d.grade || "fallback").toLowerCase();
203
+ const statusPill = state === "production" ? c.pill("Production", "ok")
204
+ : state === "unavailable" ? c.pill("Unavailable", "err")
205
+ : c.pill("Fallback", "warn");
206
+ const label = ({ hash: "Local hash (fallback)", mlx: "MLX (Apple Silicon)", ollama: "Ollama",
207
+ openai: "OpenAI-compatible", custom: "Custom" }[String(d.active_provider || d.provider || "hash")]) || String(d.active_provider || "—");
208
+ const lastIndexed = d.last_indexed_at ? new Date(d.last_indexed_at).toLocaleString() : "Never";
209
+ return c.card(
210
+ h("div.lt3-stack-3",
211
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
212
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
213
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
214
+ h("div",
215
+ h("div.lt3-eyebrow", "Active provider"),
216
+ h("b", { style: { "font-size": "var(--lt3-text-md)" } }, label),
217
+ ),
218
+ ),
219
+ h("div.lt3-row-2", { style: { "align-items": "center" } }, statusPill, c.sourceBadge((emb && emb.source) || "pending")),
220
+ ),
221
+ d.fell_back
222
+ ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", color: "var(--lt3-warn, var(--muted))" } },
223
+ `Requested “${d.requested_provider}” is unavailable (${(d.health && d.health.detail) || "no detail"}); using hash fallback.`)
224
+ : null,
225
+ h("div.lt3-cluster",
226
+ specChip(ctx, "category", "Model", d.model || d.model_id || "—"),
227
+ specChip(ctx, "ruler-2", "Dimensions", String(d.dimensions || "—")),
228
+ specChip(ctx, "clock", "Last index", lastIndexed),
229
+ ),
230
+ ),
231
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-vector) 28%, var(--border)); background: var(--lt3-pillar-vector-soft, transparent)" } },
232
+ );
233
+ }
234
+
235
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
236
+ function specChip({ h, icon }, ic, label, value) {
237
+ return h("span.lt3-pill",
238
+ h("span", { style: { color: "var(--faint)", display: "inline-flex" } }, icon(ic)),
239
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, label),
240
+ h("b", { style: { "font-size": "var(--lt3-text-xs)" } }, value),
241
+ );
242
+ }
243
+
244
+ function titleCase(s) {
245
+ s = String(s || "");
246
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
247
+ }
@@ -0,0 +1,237 @@
1
+ /* ============================================================================
2
+ * View: My Computer — local hardware, memory, and runtime.
3
+ * Reinforces the local-first promise: every gauge, model, and byte of memory
4
+ * lives on this machine. Live-reads /local/sysinfo + /models and degrades to
5
+ * clearly-badged sample data when those endpoints aren't available yet.
6
+ * ========================================================================== */
7
+
8
+ const GAUGES = [
9
+ { key: "cpu_pct", label: "CPU", icon: "cpu", variant: "graph", sub: () => "Compute cores" },
10
+ { key: "ram_pct", label: "RAM", icon: "device-desktop-analytics", variant: "vector", sub: () => "Unified memory" },
11
+ { key: "gpu_mem_pct", label: "GPU (MLX)", icon: "brand-apple", variant: "hybrid", sub: (d) => `${fmtGb(d.gpu_mem_gb)} GB in use` },
12
+ ];
13
+
14
+ export async function render(ctx) {
15
+ const { h, icon, api, c } = ctx;
16
+
17
+ const state = { memoryOn: false, activities: [], memSource: "pending" };
18
+
19
+ // Hydrated after the async reads land.
20
+ const srcSlot = h("span", c.sourceBadge("pending"));
21
+ const gaugeHost = h("div.lt3-grid-3", c.loading({ lines: 0, block: true }));
22
+ const runtimeHost = h("div", c.loading({ lines: 4 }));
23
+
24
+ const root = h("div.lt3-stack-6",
25
+ c.viewHeader({
26
+ eyebrow: "Compute",
27
+ title: "My Computer",
28
+ sub: "The local hardware and MLX runtime powering this workspace. Inference and indexing run here — on Apple Silicon — never on an external server.",
29
+ actions: [
30
+ srcSlot,
31
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Refresh"),
32
+ ],
33
+ }),
34
+
35
+ c.banner("All inference and indexing happen on this computer. Nothing you index, ask, or remember is sent to external servers.", "info", "shield-lock"),
36
+
37
+ h("section",
38
+ c.sectionHead("Live utilization"),
39
+ gaugeHost,
40
+ ),
41
+
42
+ h("div.lt3-grid-2",
43
+ c.panel({
44
+ eyebrow: "Runtime",
45
+ title: "Local runtime",
46
+ sub: "Where this workspace runs and where it keeps its data.",
47
+ children: runtimeHost,
48
+ }),
49
+ buildMemoryPanel(ctx, state),
50
+ ),
51
+ );
52
+
53
+ async function load() {
54
+ gaugeHost.replaceChildren(c.loading({ lines: 0, block: true }));
55
+ runtimeHost.replaceChildren(c.loading({ lines: 4 }));
56
+
57
+ const [sys, models] = await Promise.all([api.sysinfo(), api.models()]);
58
+
59
+ srcSlot.replaceChildren(c.sourceBadge(sys.source));
60
+ gaugeHost.replaceChildren(buildGauges(ctx, sys));
61
+ runtimeHost.replaceChildren(buildRuntime(ctx, sys, models));
62
+ }
63
+
64
+ // Reflect real local-memory state (enabled + recorded activity) from the backend.
65
+ async function loadMemory() {
66
+ const res = await api.computerMemory();
67
+ const cfg = (res && res.ok && res.data) ? res.data : null;
68
+ state.memSource = cfg ? "live" : "placeholder";
69
+ state.memoryOn = !!(cfg && cfg.enabled);
70
+ state.activities = (cfg && Array.isArray(cfg.activities)) ? cfg.activities.slice().reverse() : [];
71
+ if (state._refreshMemory) state._refreshMemory();
72
+ }
73
+
74
+ load();
75
+ loadMemory();
76
+ return root;
77
+ }
78
+
79
+ /* ── Gauges ──────────────────────────────────────────────────────────────── */
80
+ function buildGauges({ h, icon, c }, sys) {
81
+ const data = (sys && sys.data) || {};
82
+ return h("div.lt3-grid-3",
83
+ GAUGES.map((g) => {
84
+ const raw = Number(data[g.key]);
85
+ const pct = Number.isFinite(raw) ? raw : null;
86
+ return c.card(
87
+ h("div.lt3-stack-3",
88
+ h("div.lt3-row", { style: { "justify-content": "space-between" } },
89
+ h("div.lt3-stat__label", icon(g.icon), g.label),
90
+ c.statePill(pct == null ? "idle" : pct >= 90 ? "warn" : "active"),
91
+ ),
92
+ h("div.lt3-stat__value", { style: { "font-size": "var(--lt3-text-3xl)" } },
93
+ pct == null ? "—" : `${roundPct(pct)}%`),
94
+ c.meter(pct == null ? 0 : pct / 100, g.variant),
95
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, g.sub(data)),
96
+ ),
97
+ );
98
+ }),
99
+ );
100
+ }
101
+
102
+ /* ── Runtime key/value panel ─────────────────────────────────────────────── */
103
+ function buildRuntime({ h, icon, c }, sys, models) {
104
+ const md = (models && models.data) || {};
105
+ const current =
106
+ md.current ||
107
+ (md.catalog || []).find((m) => m.state === "loaded")?.id ||
108
+ "mlx-community/local-model-4bit";
109
+
110
+ const rows = [
111
+ { k: "Platform", v: "Apple Silicon · MLX", icon: "brand-apple" },
112
+ { k: "Loaded model", v: current, mono: true, icon: "cpu" },
113
+ { k: "Local storage", v: "~/.ltcai", mono: true, icon: "folder" },
114
+ { k: "Memory model", v: "Unified memory (CPU + GPU shared)", icon: "stack-2" },
115
+ { k: "Network", v: "Local-only — no external inference", icon: "wifi-off" },
116
+ ];
117
+
118
+ return h("div",
119
+ h("dl.lt3-keyval",
120
+ rows.flatMap((r) => [
121
+ h("dt", h("span.lt3-row-2", icon(r.icon), r.k)),
122
+ h("dd", r.mono ? h("span.lt3-mono", r.v) : r.v),
123
+ ]),
124
+ ),
125
+ h("div.lt3-row-2", { style: { "margin-top": "var(--lt3-space-4)" } },
126
+ c.sourceBadge((models && models.source) || (sys && sys.source)),
127
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Derived from local runtime"),
128
+ ),
129
+ );
130
+ }
131
+
132
+ /* ── Local memory panel (wired to /workspace/computer-memory) ─────────────── */
133
+ function buildMemoryPanel(ctx, state) {
134
+ const { h, icon, c } = ctx;
135
+ const notify = ctx.toast || c.toast;
136
+
137
+ const activityHost = h("div", renderActivity(ctx, state));
138
+ const input = h("input", {
139
+ type: "checkbox",
140
+ "aria-label": "Enable local computer memory",
141
+ checked: state.memoryOn,
142
+ on: {
143
+ change: async (e) => {
144
+ const want = e.target.checked;
145
+ input.disabled = true;
146
+ const res = await ctx.api.setComputerMemory(want);
147
+ input.disabled = false;
148
+ if (res && res.ok) {
149
+ state.memoryOn = want;
150
+ state.memSource = "live";
151
+ const cfg = res.data || {};
152
+ state.activities = Array.isArray(cfg.activities) ? cfg.activities.slice().reverse() : state.activities;
153
+ refresh();
154
+ notify(
155
+ want
156
+ ? "Local memory enabled — context persists on this computer (~/.ltcai)."
157
+ : "Local memory disabled. Nothing will be persisted on this computer.",
158
+ want ? "ok" : "info",
159
+ );
160
+ } else {
161
+ // Revert the toggle; report the real reason (e.g. 403 consent, no backend).
162
+ e.target.checked = state.memoryOn;
163
+ const detail = (res && res.data && (res.data.detail || res.data.error)) || "the runtime is unavailable";
164
+ notify(`Could not change local memory — ${detail}.`, "warn");
165
+ }
166
+ },
167
+ },
168
+ });
169
+
170
+ // Built from the frozen .lt3-switch markup (input + span); no shared file touched.
171
+ const sw = h("label.lt3-switch", { title: "Enable local computer memory" }, input, h("span"));
172
+
173
+ function refresh() {
174
+ input.checked = state.memoryOn;
175
+ activityHost.replaceChildren(renderActivity(ctx, state));
176
+ }
177
+ state._refreshMemory = refresh;
178
+
179
+ return c.panel({
180
+ eyebrow: "On-device",
181
+ title: "Local memory",
182
+ sub: "Let the assistant remember context across sessions — stored only on this computer, never uploaded.",
183
+ children: h("div.lt3-stack-4",
184
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
185
+ h("div.lt3-stack-2", { style: { "max-width": "40ch" } },
186
+ h("div", { style: { "font-weight": "var(--lt3-weight-semi)", "font-size": "var(--lt3-text-sm)" } },
187
+ "Enable local computer memory"),
188
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
189
+ "Persists to ~/.ltcai. Off by default."),
190
+ ),
191
+ sw,
192
+ ),
193
+ h("div",
194
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "margin-bottom": "var(--lt3-space-2)" } },
195
+ h("div.lt3-eyebrow", "Recent local activity"),
196
+ h("span", { "data-mem-src": "1" }, c.sourceBadge(state.memSource)),
197
+ ),
198
+ activityHost,
199
+ ),
200
+ ),
201
+ });
202
+ }
203
+
204
+ function renderActivity({ h, icon, c }, state) {
205
+ if (!state.memoryOn) {
206
+ return c.emptyState({
207
+ icon: "database-off",
208
+ title: "Memory is off",
209
+ body: "Enable local memory to let the assistant retain context on this computer.",
210
+ });
211
+ }
212
+ const items = Array.isArray(state.activities) ? state.activities : [];
213
+ if (!items.length) {
214
+ return c.emptyState({
215
+ icon: "history-off",
216
+ title: "No activity recorded yet",
217
+ body: "Once memory is on, on-device actions the assistant takes will be logged here.",
218
+ });
219
+ }
220
+ return h("div.lt3-list",
221
+ items.slice(0, 8).map((a) => h("div.lt3-list__item",
222
+ icon(a.icon || "activity"),
223
+ h("div.lt3-list__body",
224
+ h("div.lt3-list__title", a.title || a.action || a.kind || "Activity"),
225
+ h("div.lt3-list__meta", a.meta || a.detail || a.timestamp || ""),
226
+ ),
227
+ c.statePill(a.state || "ok"),
228
+ )),
229
+ );
230
+ }
231
+
232
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
233
+ function roundPct(n) { return Math.round(Number(n) * 10) / 10; }
234
+ function fmtGb(n) {
235
+ const v = Number(n);
236
+ return Number.isFinite(v) ? (Math.round(v * 10) / 10).toString() : "—";
237
+ }
@@ -0,0 +1,161 @@
1
+ /* ============================================================================
2
+ * View: Pipeline — ingest / embed / graph-build flows.
3
+ * Renders each workspace workflow as a horizontal stage flow (integration-ready
4
+ * against /workspace/workflows and the index APIs). Pipelines execute on the
5
+ * local runtime; this surface visualizes their stages and run state, falling
6
+ * back to clearly-badged sample data until the backend route is available.
7
+ * ========================================================================== */
8
+
9
+ import { timeAgo } from "../core/dom.js";
10
+ import * as fx from "../core/fixtures.js";
11
+
12
+ export async function render(ctx) {
13
+ const { h, icon, api, c, toast } = ctx;
14
+
15
+ // Pipeline authoring (defining new multi-stage flows) is not available from
16
+ // this view in this build — say so plainly instead of implying it's coming.
17
+ const unavailable = (label) => () => toast(`${label} is managed from the classic workflow designer — not available from this view.`, "warn");
18
+
19
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
20
+ const srcSlot = h("span", c.sourceBadge("pending"));
21
+ const flowsHost = h("div.lt3-stack-6", c.loading({ lines: 3, block: true }));
22
+
23
+ const rebuildBtn = h("button.lt3-btn.lt3-btn--primary", { on: { click: () => rebuild() } }, icon("refresh"), "Rebuild index");
24
+
25
+ const root = h("div.lt3-stack-6",
26
+ c.viewHeader({
27
+ eyebrow: "Data",
28
+ title: "Pipeline",
29
+ sub: "Ingest, embed, and graph-build flows that turn your sources into the retrieval lattice — chunk, embed, extract entities, and link the graph.",
30
+ actions: [rebuildBtn],
31
+ }),
32
+ c.banner(
33
+ "Pipelines execute on this machine's local runtime. Use Rebuild index to re-embed every chunk and relink the knowledge graph from your current sources.",
34
+ "info",
35
+ "server-bolt",
36
+ ),
37
+ statHost,
38
+ h("section",
39
+ c.sectionHead("Flows", srcSlot),
40
+ flowsHost,
41
+ ),
42
+ );
43
+
44
+ load();
45
+ return root;
46
+
47
+ async function load() {
48
+ const res = await api.get("/workspace/workflows", { workflows: fx.PIPELINES });
49
+ const pipelines = normalize(res.data);
50
+ srcSlot.replaceChildren(c.sourceBadge(res.source));
51
+ renderStats(pipelines);
52
+ renderFlows(pipelines);
53
+ }
54
+
55
+ // Real pipeline run: rebuild the vector index (re-embed chunks, relink graph).
56
+ async function rebuild() {
57
+ rebuildBtn.disabled = true;
58
+ rebuildBtn.replaceChildren(icon("loader"), "Rebuilding…");
59
+ const res = await api.rebuildIndex();
60
+ rebuildBtn.disabled = false;
61
+ rebuildBtn.replaceChildren(icon("refresh"), "Rebuild index");
62
+ if (res && res.ok && res.data && res.data.status === "completed") {
63
+ const d = res.data;
64
+ toast(`Index rebuilt — ${d.items_indexed} indexed, ${d.items_skipped} unchanged (${d.embedding_model}).`, "ok");
65
+ load();
66
+ } else {
67
+ const detail = (res && res.data && (res.data.detail || res.data.error)) || "the knowledge graph is unavailable";
68
+ toast(`Could not rebuild the index — ${detail}.`, "warn");
69
+ }
70
+ }
71
+
72
+ function renderStats(pipelines) {
73
+ const active = pipelines.filter((p) => isActive(p.state)).length;
74
+ const stages = pipelines.reduce((sum, p) => sum + p.stages.length, 0);
75
+ const throughput = pipelines.find((p) => p.throughput)?.throughput || "—";
76
+ const lastRun = pipelines
77
+ .map((p) => p.last_run)
78
+ .filter(Boolean)
79
+ .sort((a, b) => new Date(b) - new Date(a))[0];
80
+ statHost.replaceChildren(
81
+ c.stat({ label: "Active pipelines", value: c.fmtNum(active), icon: "player-play" }),
82
+ c.stat({ label: "Total stages", value: c.fmtNum(stages), icon: "stack-2" }),
83
+ c.stat({ label: "Throughput", value: throughput, icon: "gauge" }),
84
+ c.stat({ label: "Last run", value: lastRun ? timeAgo(lastRun) : "—", icon: "history" }),
85
+ );
86
+ }
87
+
88
+ function renderFlows(pipelines) {
89
+ if (!pipelines.length) {
90
+ flowsHost.replaceChildren(
91
+ c.emptyState({
92
+ icon: "git-branch-deleted",
93
+ title: "No pipelines yet",
94
+ body: "Connect a source and create a pipeline to ingest, embed, and build the graph.",
95
+ action: h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => rebuild() } }, icon("refresh"), "Rebuild index"),
96
+ }),
97
+ );
98
+ return;
99
+ }
100
+ flowsHost.replaceChildren(...pipelines.map((p) => pipelinePanel(p)));
101
+ }
102
+
103
+ function pipelinePanel(p) {
104
+ return c.panel({
105
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
106
+ h("div.lt3-row-2",
107
+ h("div.lt3-eyebrow", icon("git-branch"), "Pipeline"),
108
+ ),
109
+ c.statePill(p.state),
110
+ ),
111
+ children: h("div.lt3-stack-4",
112
+ h("h3.lt3-panel__title", { style: { "margin-top": "calc(-1 * var(--lt3-space-2))" } }, p.name),
113
+ flowDiagram(p.stages),
114
+ pipelineFooter(p),
115
+ ),
116
+ });
117
+ }
118
+
119
+ function flowDiagram(stages) {
120
+ const cells = [];
121
+ stages.forEach((stage, i) => {
122
+ if (i > 0) cells.push(h("div.lt3-flow__arrow", { "aria-hidden": "true" }, icon("chevron-right")));
123
+ cells.push(
124
+ h("div.lt3-stage",
125
+ h("div.lt3-stage__num", String(i + 1).padStart(2, "0")),
126
+ h("div.lt3-stage__name", stage),
127
+ ),
128
+ );
129
+ });
130
+ return h("div.lt3-flow", { role: "list", "aria-label": "Pipeline stages" }, cells);
131
+ }
132
+
133
+ function pipelineFooter(p) {
134
+ return h("div.lt3-row", { style: { "justify-content": "space-between", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
135
+ h("div.lt3-cluster",
136
+ h("span.lt3-faint.lt3-row-2", { style: { "font-size": "var(--lt3-text-xs)" } }, icon("history"), p.last_run ? timeAgo(p.last_run) : "—"),
137
+ h("span.lt3-faint.lt3-row-2", { style: { "font-size": "var(--lt3-text-xs)" } }, icon("gauge"), p.throughput || "—"),
138
+ ),
139
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: unavailable(`Running "${p.name}"`) } }, icon("player-play"), "Run"),
140
+ );
141
+ }
142
+ }
143
+
144
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
145
+ function normalize(data) {
146
+ const list = Array.isArray(data) ? data : (data && data.workflows) || [];
147
+ return list.map((p, i) => ({
148
+ id: p.id || `pl-${i}`,
149
+ name: p.name || p.label || "Untitled pipeline",
150
+ state: p.state || "idle",
151
+ stages: Array.isArray(p.stages) ? p.stages.map((s) => String(s))
152
+ : Array.isArray(p.steps) ? p.steps.map((s) => (s && (s.action || s.name)) || String(s))
153
+ : [],
154
+ last_run: p.last_run || p.created_at || null,
155
+ throughput: p.throughput || "",
156
+ }));
157
+ }
158
+
159
+ function isActive(state) {
160
+ return ["active", "running", "indexing", "building"].includes(String(state).toLowerCase());
161
+ }