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,256 @@
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
+ * Shows the runtime as unavailable when the backend endpoint isn't available.
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
+ export async function render(ctx) {
13
+ const { h, icon, api, c } = ctx;
14
+
15
+ const srcSlot = h("span", c.sourceBadge("pending"));
16
+ const activeHost = h("div", c.loading({ lines: 2, block: true }));
17
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
18
+ const embedHost = h("div", c.loading({ lines: 2 }));
19
+ const tableHost = h("div", c.loading({ lines: 4 }));
20
+
21
+ const root = h("div.lt3-stack-6",
22
+ c.viewHeader({
23
+ eyebrow: "Compute",
24
+ title: "Models",
25
+ sub: "Local and OpenAI-compatible runtime choices. Local models keep generation on this machine; cloud-compatible providers are shown only when configured.",
26
+ actions: [
27
+ srcSlot,
28
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Refresh"),
29
+ ],
30
+ }),
31
+ activeHost,
32
+ statHost,
33
+ c.panel({
34
+ eyebrow: "Retrieval",
35
+ title: "Embedding models",
36
+ sub: "Production semantic providers and the local hash fallback share the same vector-index contract.",
37
+ children: embedHost,
38
+ }),
39
+ c.panel({
40
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", width: "100%" } },
41
+ h("div", h("div.lt3-eyebrow", "Runtime"), h("h3.lt3-panel__title", "Model catalog")),
42
+ h("span", { id: "models-cat-src" }, c.sourceBadge("pending")),
43
+ ),
44
+ children: tableHost,
45
+ }),
46
+ );
47
+
48
+ async function load() {
49
+ activeHost.replaceChildren(c.loading({ lines: 2, block: true }));
50
+ tableHost.replaceChildren(c.loading({ lines: 4 }));
51
+ embedHost.replaceChildren(c.loading({ lines: 2 }));
52
+
53
+ const [res, emb] = await Promise.all([api.models(), api.embeddingsStatus()]);
54
+ const data = res.data || {};
55
+ const catalog = Array.isArray(data.catalog) ? data.catalog : [];
56
+
57
+ srcSlot.replaceChildren(c.sourceBadge(res.source));
58
+ root.querySelector("#models-cat-src")?.replaceChildren(c.sourceBadge(res.source));
59
+
60
+ if (!catalog.length) {
61
+ activeHost.replaceChildren(
62
+ c.emptyState({ icon: "cpu-off", title: "No models available", body: "Start or configure a local/OpenAI-compatible runtime to list models here." }),
63
+ );
64
+ statHost.replaceChildren();
65
+ renderEmbeddings([], emb);
66
+ tableHost.replaceChildren(c.emptyState({ icon: "cpu-off", title: "Catalog is empty", body: "Connect a model runtime to list installed and recommended models." }));
67
+ return;
68
+ }
69
+
70
+ const isEmbedding = (m) => String(m.family || "").toLowerCase() === "embedding";
71
+ const language = catalog.filter((m) => !isEmbedding(m));
72
+ const embeddings = catalog.filter(isEmbedding);
73
+ const loaded = catalog.filter((m) => String(m.state).toLowerCase() === "loaded");
74
+ const active = catalog.find((m) => m.id === data.current)
75
+ || loaded.find((m) => !isEmbedding(m))
76
+ || language[0]
77
+ || catalog[0];
78
+
79
+ renderActive(active);
80
+ renderStats(catalog, embeddings, loaded);
81
+ renderEmbeddings(embeddings, emb);
82
+ renderCatalog(language.length ? language : catalog);
83
+ }
84
+
85
+ function renderActive(m) {
86
+ if (!m) { activeHost.replaceChildren(); return; }
87
+ activeHost.replaceChildren(
88
+ c.card(
89
+ h("div.lt3-stack-3",
90
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "flex-start", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
91
+ h("div.lt3-row-2", { style: { "align-items": "center", gap: "var(--lt3-space-3)" } },
92
+ h("div.lt3-pillar__icon", { style: { background: "var(--lt3-pillar-hybrid-soft)", color: "var(--lt3-pillar-hybrid)" } }, icon("cpu")),
93
+ h("div",
94
+ h("div.lt3-eyebrow", "Active model"),
95
+ h("div", { style: { "font-size": "var(--lt3-text-xl)", "font-weight": 800, "letter-spacing": "-0.01em" } }, m.name || m.id),
96
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)", "margin-top": "var(--lt3-space-1)" } }, m.id),
97
+ ),
98
+ ),
99
+ h("div.lt3-cluster", { style: { "align-items": "center" } },
100
+ m.recommended ? c.pill("Recommended", "info") : null,
101
+ c.statePill("loaded"),
102
+ ),
103
+ ),
104
+ h("div.lt3-cluster",
105
+ specChip(ctx, "category", "Family", titleCase(m.family || "local")),
106
+ specChip(ctx, "stack-2", "Params", m.params || "—"),
107
+ specChip(ctx, "binary", "Quant", m.quant || "—"),
108
+ specChip(ctx, "ruler-2", "Context", c.fmtNum(m.context) + " tok"),
109
+ ),
110
+ ),
111
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-hybrid) 32%, var(--border)); background: var(--lt3-pillar-hybrid-soft)" } },
112
+ ),
113
+ );
114
+ }
115
+
116
+ function renderStats(catalog, embeddings, loaded) {
117
+ const maxCtx = catalog.reduce((mx, m) => Math.max(mx, Number(m.context) || 0), 0);
118
+ statHost.replaceChildren(
119
+ c.stat({ label: "Loaded", value: c.fmtNum(loaded.length), icon: "player-play" }),
120
+ c.stat({ label: "Available", value: c.fmtNum(catalog.length), icon: "stack-2" }),
121
+ c.stat({ label: "Embedding models", value: c.fmtNum(embeddings.length), icon: "grid-dots" }),
122
+ c.stat({ label: "Max context", value: c.fmtNum(maxCtx) + " tok", icon: "ruler-2" }),
123
+ );
124
+ }
125
+
126
+ function renderEmbeddings(embeddings, emb) {
127
+ const statusCard = embeddingStatusCard(ctx, emb);
128
+ if (!embeddings.length) {
129
+ embedHost.replaceChildren(h("div.lt3-stack-4",
130
+ statusCard,
131
+ 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." }),
132
+ ));
133
+ return;
134
+ }
135
+ embedHost.replaceChildren(h("div.lt3-stack-4",
136
+ statusCard,
137
+ h("div.lt3-grid-auto",
138
+ embeddings.map((m) => c.card(
139
+ h("div.lt3-stack-2",
140
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "center" } },
141
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
142
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
143
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
144
+ ),
145
+ c.statePill(m.state),
146
+ ),
147
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
148
+ h("div.lt3-cluster",
149
+ c.pill(`${m.params || "—"} params`, ""),
150
+ c.pill(m.quant || "—", ""),
151
+ c.pill(`${c.fmtNum(m.context)} ctx`, ""),
152
+ ),
153
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Powers the Vector Index → Hybrid Search."),
154
+ ),
155
+ { flat: true },
156
+ )),
157
+ ),
158
+ ));
159
+ }
160
+
161
+ function renderCatalog(rows) {
162
+ const columns = [
163
+ { key: "name", label: "Model", render: (m) => h("div.lt3-stack-2", { style: { gap: "2px" } },
164
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
165
+ h("span.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
166
+ ) },
167
+ { key: "family", label: "Family", render: (m) => titleCase(m.family || "local") },
168
+ { key: "params", label: "Params", render: (m) => h("span.lt3-mono", m.params || "—") },
169
+ { key: "quant", label: "Quant", render: (m) => h("span.lt3-mono", m.quant || "—") },
170
+ { key: "context", label: "Context", render: (m) => h("span.lt3-mono", c.fmtNum(m.context)) },
171
+ { key: "state", label: "State", render: (m) => c.statePill(m.state) },
172
+ { key: "action", label: "", width: "1%", render: (m) => actionButton(m) },
173
+ ];
174
+ tableHost.replaceChildren(
175
+ c.table(columns, rows, {
176
+ empty: c.emptyState({ icon: "cpu-off", title: "No language models", body: "Pull an MLX chat model into the runtime." }),
177
+ }),
178
+ );
179
+ }
180
+
181
+ function actionButton(m) {
182
+ const loaded = String(m.state).toLowerCase() === "loaded";
183
+ const label = loaded ? "Unload" : "Load";
184
+ const ic = loaded ? "player-stop" : "player-play";
185
+ return h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm",
186
+ { "aria-label": `${label} ${m.name || m.id}`, on: { click: () => toggleModel(m) } },
187
+ icon(ic), label,
188
+ );
189
+ }
190
+
191
+ async function toggleModel(m) {
192
+ const loaded = String(m.state).toLowerCase() === "loaded";
193
+ const res = loaded ? await ctx.api.unloadModel(m.id) : await ctx.api.loadModel(m.id, m.recommended_engine);
194
+ if (res && res.ok && res.data && !res.data.detail && !res.data.error) {
195
+ ctx.toast(`${loaded ? "Unloaded" : "Loaded"} ${m.name || m.id}.`, "ok");
196
+ load();
197
+ } else {
198
+ const detail = (res && res.data && (res.data.detail || res.data.error)) || "model runtime unavailable";
199
+ ctx.toast(`Could not ${loaded ? "unload" : "load"} ${m.name || m.id} — ${detail}.`, "warn");
200
+ }
201
+ }
202
+
203
+ load();
204
+ return root;
205
+ }
206
+
207
+ /* ── Active embedding provider status (real /api/embeddings/status) ──────── */
208
+ function embeddingStatusCard(ctx, emb) {
209
+ const { h, icon, c } = ctx;
210
+ const d = (emb && emb.data) || {};
211
+ const state = String(d.state || d.grade || "fallback").toLowerCase();
212
+ const statusPill = state === "production" ? c.pill("Production", "ok")
213
+ : state === "unavailable" ? c.pill("Unavailable", "err")
214
+ : c.pill("Fallback", "warn");
215
+ const label = ({ hash: "Local hash (fallback)", mlx: "MLX (Apple Silicon)", ollama: "Ollama",
216
+ openai: "OpenAI-compatible", custom: "Custom" }[String(d.active_provider || d.provider || "hash")]) || String(d.active_provider || "—");
217
+ const lastIndexed = d.last_indexed_at ? new Date(d.last_indexed_at).toLocaleString() : "Never";
218
+ return c.card(
219
+ h("div.lt3-stack-3",
220
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
221
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
222
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
223
+ h("div",
224
+ h("div.lt3-eyebrow", "Active provider"),
225
+ h("b", { style: { "font-size": "var(--lt3-text-md)" } }, label),
226
+ ),
227
+ ),
228
+ h("div.lt3-row-2", { style: { "align-items": "center" } }, statusPill, c.sourceBadge((emb && emb.source) || "pending")),
229
+ ),
230
+ d.fell_back
231
+ ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", color: "var(--lt3-warn, var(--muted))" } },
232
+ `Requested “${d.requested_provider}” is unavailable (${(d.health && d.health.detail) || "no detail"}); using hash fallback.`)
233
+ : null,
234
+ h("div.lt3-cluster",
235
+ specChip(ctx, "category", "Model", d.model || d.model_id || "—"),
236
+ specChip(ctx, "ruler-2", "Dimensions", String(d.dimensions || "—")),
237
+ specChip(ctx, "clock", "Last index", lastIndexed),
238
+ ),
239
+ ),
240
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-vector) 28%, var(--border)); background: var(--lt3-pillar-vector-soft, transparent)" } },
241
+ );
242
+ }
243
+
244
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
245
+ function specChip({ h, icon }, ic, label, value) {
246
+ return h("span.lt3-pill",
247
+ h("span", { style: { color: "var(--faint)", display: "inline-flex" } }, icon(ic)),
248
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, label),
249
+ h("b", { style: { "font-size": "var(--lt3-text-xs)" } }, value),
250
+ );
251
+ }
252
+
253
+ function titleCase(s) {
254
+ s = String(s || "");
255
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
256
+ }
@@ -0,0 +1,256 @@
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
+ * Shows the runtime as unavailable when the backend endpoint isn't available.
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
+ export async function render(ctx) {
13
+ const { h, icon, api, c } = ctx;
14
+
15
+ const srcSlot = h("span", c.sourceBadge("pending"));
16
+ const activeHost = h("div", c.loading({ lines: 2, block: true }));
17
+ const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
18
+ const embedHost = h("div", c.loading({ lines: 2 }));
19
+ const tableHost = h("div", c.loading({ lines: 4 }));
20
+
21
+ const root = h("div.lt3-stack-6",
22
+ c.viewHeader({
23
+ eyebrow: "Compute",
24
+ title: "Models",
25
+ sub: "Local and OpenAI-compatible runtime choices. Local models keep generation on this machine; cloud-compatible providers are shown only when configured.",
26
+ actions: [
27
+ srcSlot,
28
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Refresh"),
29
+ ],
30
+ }),
31
+ activeHost,
32
+ statHost,
33
+ c.panel({
34
+ eyebrow: "Retrieval",
35
+ title: "Embedding models",
36
+ sub: "Production semantic providers and the local hash fallback share the same vector-index contract.",
37
+ children: embedHost,
38
+ }),
39
+ c.panel({
40
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", width: "100%" } },
41
+ h("div", h("div.lt3-eyebrow", "Runtime"), h("h3.lt3-panel__title", "Model catalog")),
42
+ h("span", { id: "models-cat-src" }, c.sourceBadge("pending")),
43
+ ),
44
+ children: tableHost,
45
+ }),
46
+ );
47
+
48
+ async function load() {
49
+ activeHost.replaceChildren(c.loading({ lines: 2, block: true }));
50
+ tableHost.replaceChildren(c.loading({ lines: 4 }));
51
+ embedHost.replaceChildren(c.loading({ lines: 2 }));
52
+
53
+ const [res, emb] = await Promise.all([api.models(), api.embeddingsStatus()]);
54
+ const data = res.data || {};
55
+ const catalog = Array.isArray(data.catalog) ? data.catalog : [];
56
+
57
+ srcSlot.replaceChildren(c.sourceBadge(res.source));
58
+ root.querySelector("#models-cat-src")?.replaceChildren(c.sourceBadge(res.source));
59
+
60
+ if (!catalog.length) {
61
+ activeHost.replaceChildren(
62
+ c.emptyState({ icon: "cpu-off", title: "No models available", body: "Start or configure a local/OpenAI-compatible runtime to list models here." }),
63
+ );
64
+ statHost.replaceChildren();
65
+ renderEmbeddings([], emb);
66
+ tableHost.replaceChildren(c.emptyState({ icon: "cpu-off", title: "Catalog is empty", body: "Connect a model runtime to list installed and recommended models." }));
67
+ return;
68
+ }
69
+
70
+ const isEmbedding = (m) => String(m.family || "").toLowerCase() === "embedding";
71
+ const language = catalog.filter((m) => !isEmbedding(m));
72
+ const embeddings = catalog.filter(isEmbedding);
73
+ const loaded = catalog.filter((m) => String(m.state).toLowerCase() === "loaded");
74
+ const active = catalog.find((m) => m.id === data.current)
75
+ || loaded.find((m) => !isEmbedding(m))
76
+ || language[0]
77
+ || catalog[0];
78
+
79
+ renderActive(active);
80
+ renderStats(catalog, embeddings, loaded);
81
+ renderEmbeddings(embeddings, emb);
82
+ renderCatalog(language.length ? language : catalog);
83
+ }
84
+
85
+ function renderActive(m) {
86
+ if (!m) { activeHost.replaceChildren(); return; }
87
+ activeHost.replaceChildren(
88
+ c.card(
89
+ h("div.lt3-stack-3",
90
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "flex-start", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
91
+ h("div.lt3-row-2", { style: { "align-items": "center", gap: "var(--lt3-space-3)" } },
92
+ h("div.lt3-pillar__icon", { style: { background: "var(--lt3-pillar-hybrid-soft)", color: "var(--lt3-pillar-hybrid)" } }, icon("cpu")),
93
+ h("div",
94
+ h("div.lt3-eyebrow", "Active model"),
95
+ h("div", { style: { "font-size": "var(--lt3-text-xl)", "font-weight": 800, "letter-spacing": "-0.01em" } }, m.name || m.id),
96
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)", "margin-top": "var(--lt3-space-1)" } }, m.id),
97
+ ),
98
+ ),
99
+ h("div.lt3-cluster", { style: { "align-items": "center" } },
100
+ m.recommended ? c.pill("Recommended", "info") : null,
101
+ c.statePill("loaded"),
102
+ ),
103
+ ),
104
+ h("div.lt3-cluster",
105
+ specChip(ctx, "category", "Family", titleCase(m.family || "local")),
106
+ specChip(ctx, "stack-2", "Params", m.params || "—"),
107
+ specChip(ctx, "binary", "Quant", m.quant || "—"),
108
+ specChip(ctx, "ruler-2", "Context", c.fmtNum(m.context) + " tok"),
109
+ ),
110
+ ),
111
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-hybrid) 32%, var(--border)); background: var(--lt3-pillar-hybrid-soft)" } },
112
+ ),
113
+ );
114
+ }
115
+
116
+ function renderStats(catalog, embeddings, loaded) {
117
+ const maxCtx = catalog.reduce((mx, m) => Math.max(mx, Number(m.context) || 0), 0);
118
+ statHost.replaceChildren(
119
+ c.stat({ label: "Loaded", value: c.fmtNum(loaded.length), icon: "player-play" }),
120
+ c.stat({ label: "Available", value: c.fmtNum(catalog.length), icon: "stack-2" }),
121
+ c.stat({ label: "Embedding models", value: c.fmtNum(embeddings.length), icon: "grid-dots" }),
122
+ c.stat({ label: "Max context", value: c.fmtNum(maxCtx) + " tok", icon: "ruler-2" }),
123
+ );
124
+ }
125
+
126
+ function renderEmbeddings(embeddings, emb) {
127
+ const statusCard = embeddingStatusCard(ctx, emb);
128
+ if (!embeddings.length) {
129
+ embedHost.replaceChildren(h("div.lt3-stack-4",
130
+ statusCard,
131
+ 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." }),
132
+ ));
133
+ return;
134
+ }
135
+ embedHost.replaceChildren(h("div.lt3-stack-4",
136
+ statusCard,
137
+ h("div.lt3-grid-auto",
138
+ embeddings.map((m) => c.card(
139
+ h("div.lt3-stack-2",
140
+ h("div.lt3-row-2", { style: { "justify-content": "space-between", "align-items": "center" } },
141
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
142
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
143
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
144
+ ),
145
+ c.statePill(m.state),
146
+ ),
147
+ h("div.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
148
+ h("div.lt3-cluster",
149
+ c.pill(`${m.params || "—"} params`, ""),
150
+ c.pill(m.quant || "—", ""),
151
+ c.pill(`${c.fmtNum(m.context)} ctx`, ""),
152
+ ),
153
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Powers the Vector Index → Hybrid Search."),
154
+ ),
155
+ { flat: true },
156
+ )),
157
+ ),
158
+ ));
159
+ }
160
+
161
+ function renderCatalog(rows) {
162
+ const columns = [
163
+ { key: "name", label: "Model", render: (m) => h("div.lt3-stack-2", { style: { gap: "2px" } },
164
+ h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, m.name || m.id),
165
+ h("span.lt3-faint.lt3-mono", { style: { "font-size": "var(--lt3-text-2xs)" } }, m.id),
166
+ ) },
167
+ { key: "family", label: "Family", render: (m) => titleCase(m.family || "local") },
168
+ { key: "params", label: "Params", render: (m) => h("span.lt3-mono", m.params || "—") },
169
+ { key: "quant", label: "Quant", render: (m) => h("span.lt3-mono", m.quant || "—") },
170
+ { key: "context", label: "Context", render: (m) => h("span.lt3-mono", c.fmtNum(m.context)) },
171
+ { key: "state", label: "State", render: (m) => c.statePill(m.state) },
172
+ { key: "action", label: "", width: "1%", render: (m) => actionButton(m) },
173
+ ];
174
+ tableHost.replaceChildren(
175
+ c.table(columns, rows, {
176
+ empty: c.emptyState({ icon: "cpu-off", title: "No language models", body: "Pull an MLX chat model into the runtime." }),
177
+ }),
178
+ );
179
+ }
180
+
181
+ function actionButton(m) {
182
+ const loaded = String(m.state).toLowerCase() === "loaded";
183
+ const label = loaded ? "Unload" : "Load";
184
+ const ic = loaded ? "player-stop" : "player-play";
185
+ return h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm",
186
+ { "aria-label": `${label} ${m.name || m.id}`, on: { click: () => toggleModel(m) } },
187
+ icon(ic), label,
188
+ );
189
+ }
190
+
191
+ async function toggleModel(m) {
192
+ const loaded = String(m.state).toLowerCase() === "loaded";
193
+ const res = loaded ? await ctx.api.unloadModel(m.id) : await ctx.api.loadModel(m.id, m.recommended_engine);
194
+ if (res && res.ok && res.data && !res.data.detail && !res.data.error) {
195
+ ctx.toast(`${loaded ? "Unloaded" : "Loaded"} ${m.name || m.id}.`, "ok");
196
+ load();
197
+ } else {
198
+ const detail = (res && res.data && (res.data.detail || res.data.error)) || "model runtime unavailable";
199
+ ctx.toast(`Could not ${loaded ? "unload" : "load"} ${m.name || m.id} — ${detail}.`, "warn");
200
+ }
201
+ }
202
+
203
+ load();
204
+ return root;
205
+ }
206
+
207
+ /* ── Active embedding provider status (real /api/embeddings/status) ──────── */
208
+ function embeddingStatusCard(ctx, emb) {
209
+ const { h, icon, c } = ctx;
210
+ const d = (emb && emb.data) || {};
211
+ const state = String(d.state || d.grade || "fallback").toLowerCase();
212
+ const statusPill = state === "production" ? c.pill("Production", "ok")
213
+ : state === "unavailable" ? c.pill("Unavailable", "err")
214
+ : c.pill("Fallback", "warn");
215
+ const label = ({ hash: "Local hash (fallback)", mlx: "MLX (Apple Silicon)", ollama: "Ollama",
216
+ openai: "OpenAI-compatible", custom: "Custom" }[String(d.active_provider || d.provider || "hash")]) || String(d.active_provider || "—");
217
+ const lastIndexed = d.last_indexed_at ? new Date(d.last_indexed_at).toLocaleString() : "Never";
218
+ return c.card(
219
+ h("div.lt3-stack-3",
220
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "flex-wrap": "wrap", gap: "var(--lt3-space-3)" } },
221
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
222
+ h("span", { style: { color: "var(--lt3-pillar-vector)", display: "inline-flex" } }, icon("grid-dots")),
223
+ h("div",
224
+ h("div.lt3-eyebrow", "Active provider"),
225
+ h("b", { style: { "font-size": "var(--lt3-text-md)" } }, label),
226
+ ),
227
+ ),
228
+ h("div.lt3-row-2", { style: { "align-items": "center" } }, statusPill, c.sourceBadge((emb && emb.source) || "pending")),
229
+ ),
230
+ d.fell_back
231
+ ? h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", color: "var(--lt3-warn, var(--muted))" } },
232
+ `Requested “${d.requested_provider}” is unavailable (${(d.health && d.health.detail) || "no detail"}); using hash fallback.`)
233
+ : null,
234
+ h("div.lt3-cluster",
235
+ specChip(ctx, "category", "Model", d.model || d.model_id || "—"),
236
+ specChip(ctx, "ruler-2", "Dimensions", String(d.dimensions || "—")),
237
+ specChip(ctx, "clock", "Last index", lastIndexed),
238
+ ),
239
+ ),
240
+ { attrs: { style: "border-color: color-mix(in srgb, var(--lt3-pillar-vector) 28%, var(--border)); background: var(--lt3-pillar-vector-soft, transparent)" } },
241
+ );
242
+ }
243
+
244
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
245
+ function specChip({ h, icon }, ic, label, value) {
246
+ return h("span.lt3-pill",
247
+ h("span", { style: { color: "var(--faint)", display: "inline-flex" } }, icon(ic)),
248
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, label),
249
+ h("b", { style: { "font-size": "var(--lt3-text-xs)" } }, value),
250
+ );
251
+ }
252
+
253
+ function titleCase(s) {
254
+ s = String(s || "");
255
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
256
+ }