ltcai 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -24
- package/desktop/electron/main.cjs +44 -0
- package/docs/CHANGELOG.md +84 -0
- package/docs/V4_1_FRONTEND_ARCHITECTURE_REVIEW.md +65 -0
- package/docs/V4_1_FRONTEND_MIGRATION_REPORT.md +70 -0
- package/docs/V4_1_VALIDATION_REPORT.md +47 -0
- package/docs/V4_2_BRAIN_CORE_ARCHITECTURE.md +97 -0
- package/docs/V4_2_STORAGE_MIGRATION_REPORT.md +91 -0
- package/docs/V4_2_VALIDATION_REPORT.md +89 -0
- package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +31 -26
- package/frontend/index.html +24 -0
- package/frontend/openapi.json +14436 -0
- package/frontend/src/App.tsx +184 -0
- package/frontend/src/api/client.ts +320 -0
- package/frontend/src/api/openapi.ts +16921 -0
- package/frontend/src/components/primitives.tsx +204 -0
- package/frontend/src/components/ui/badge.tsx +27 -0
- package/frontend/src/components/ui/button.tsx +37 -0
- package/frontend/src/components/ui/card.tsx +22 -0
- package/frontend/src/components/ui/input.tsx +16 -0
- package/frontend/src/components/ui/textarea.tsx +16 -0
- package/frontend/src/lib/utils.ts +33 -0
- package/frontend/src/main.tsx +23 -0
- package/frontend/src/pages/Act.tsx +245 -0
- package/frontend/src/pages/Ask.tsx +200 -0
- package/frontend/src/pages/Brain.tsx +267 -0
- package/frontend/src/pages/Capture.tsx +158 -0
- package/frontend/src/pages/Library.tsx +187 -0
- package/frontend/src/pages/System.tsx +378 -0
- package/frontend/src/routes.ts +85 -0
- package/frontend/src/store/appStore.ts +54 -0
- package/frontend/src/styles.css +107 -0
- package/kg_schema.py +1 -1
- package/knowledge_graph.py +4 -4
- package/lattice_brain/__init__.py +70 -0
- package/lattice_brain/_kg_common.py +1 -0
- package/lattice_brain/archive.py +133 -0
- package/lattice_brain/context.py +3 -0
- package/lattice_brain/conversations.py +3 -0
- package/lattice_brain/core.py +82 -0
- package/lattice_brain/discovery.py +1 -0
- package/lattice_brain/documents.py +1 -0
- package/lattice_brain/embeddings.py +82 -0
- package/lattice_brain/identity.py +13 -0
- package/lattice_brain/ingest.py +1 -0
- package/lattice_brain/memory.py +3 -0
- package/lattice_brain/network.py +1 -0
- package/lattice_brain/projection.py +1 -0
- package/lattice_brain/provenance.py +1 -0
- package/lattice_brain/retrieval.py +1 -0
- package/lattice_brain/schema.py +1 -0
- package/lattice_brain/storage/__init__.py +22 -0
- package/lattice_brain/storage/base.py +72 -0
- package/lattice_brain/storage/docker.py +105 -0
- package/lattice_brain/storage/factory.py +31 -0
- package/lattice_brain/storage/migration.py +190 -0
- package/lattice_brain/storage/postgres.py +123 -0
- package/lattice_brain/storage/sqlite.py +128 -0
- package/lattice_brain/store.py +3 -0
- package/lattice_brain/write_master.py +1 -0
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/portability.py +69 -0
- package/latticeai/api/setup.py +5 -4
- package/latticeai/api/static_routes.py +4 -4
- package/latticeai/app_factory.py +17 -10
- package/latticeai/brain/__init__.py +6 -6
- package/latticeai/brain/_kg_common.py +1 -1
- package/latticeai/brain/network.py +1 -1
- package/latticeai/brain/retrieval.py +15 -0
- package/latticeai/brain/store.py +22 -6
- package/latticeai/core/config.py +8 -0
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/multi_agent.py +1 -1
- package/latticeai/core/workspace_os.py +1 -1
- package/latticeai/services/kg_portability.py +82 -1
- package/package.json +55 -15
- package/scripts/build_frontend_assets.mjs +38 -0
- package/scripts/bump_version.py +4 -1
- package/scripts/export_openapi.py +31 -0
- package/scripts/lint_frontend.mjs +91 -0
- package/scripts/migrate_brain_storage.py +53 -0
- package/scripts/run_python.mjs +47 -0
- package/scripts/wheel_smoke.py +3 -0
- package/src-tauri/Cargo.lock +4833 -0
- package/src-tauri/Cargo.toml +19 -0
- package/src-tauri/build.rs +3 -0
- package/src-tauri/capabilities/default.json +7 -0
- package/src-tauri/src/main.rs +78 -0
- package/src-tauri/tauri.conf.json +39 -0
- package/static/app/asset-manifest.json +32 -0
- package/static/app/assets/core-CwxXejkd.js +2 -0
- package/static/app/assets/core-CwxXejkd.js.map +1 -0
- package/static/app/assets/index-CDjiH_se.css +2 -0
- package/static/app/assets/index-C_HAkbAg.js +333 -0
- package/static/app/assets/index-C_HAkbAg.js.map +1 -0
- package/static/app/index.html +25 -0
- package/static/manifest.json +2 -2
- package/static/sw.js +4 -4
- package/scripts/build_v3_assets.mjs +0 -170
- package/scripts/lint_v3.mjs +0 -120
- package/static/v3/asset-manifest.json +0 -63
- package/static/v3/css/lattice.base.49deefb5.css +0 -128
- package/static/v3/css/lattice.base.css +0 -128
- package/static/v3/css/lattice.components.cde18231.css +0 -472
- package/static/v3/css/lattice.components.css +0 -472
- package/static/v3/css/lattice.shell.29d36d85.css +0 -452
- package/static/v3/css/lattice.shell.css +0 -452
- package/static/v3/css/lattice.tokens.304cbc40.css +0 -135
- package/static/v3/css/lattice.tokens.css +0 -135
- package/static/v3/css/lattice.views.0a18b6c5.css +0 -360
- package/static/v3/css/lattice.views.css +0 -360
- package/static/v3/index.html +0 -68
- package/static/v3/js/app.c5c80c46.js +0 -26
- package/static/v3/js/app.js +0 -26
- package/static/v3/js/core/api.ba0fbf14.js +0 -625
- package/static/v3/js/core/api.js +0 -625
- package/static/v3/js/core/components.f25b3b93.js +0 -230
- package/static/v3/js/core/components.js +0 -230
- package/static/v3/js/core/dom.a2773eb0.js +0 -148
- package/static/v3/js/core/dom.js +0 -148
- package/static/v3/js/core/i18n.880e1fec.js +0 -575
- package/static/v3/js/core/i18n.js +0 -575
- package/static/v3/js/core/router.584570f2.js +0 -37
- package/static/v3/js/core/router.js +0 -37
- package/static/v3/js/core/routes.37522821.js +0 -101
- package/static/v3/js/core/routes.js +0 -101
- package/static/v3/js/core/shell.e3f6bbfa.js +0 -420
- package/static/v3/js/core/shell.js +0 -420
- package/static/v3/js/core/store.7b2aa044.js +0 -123
- package/static/v3/js/core/store.js +0 -123
- package/static/v3/js/views/account.eff40715.js +0 -143
- package/static/v3/js/views/account.js +0 -143
- package/static/v3/js/views/activity.0d271ef9.js +0 -67
- package/static/v3/js/views/activity.js +0 -67
- package/static/v3/js/views/admin-audit.660a1fb1.js +0 -185
- package/static/v3/js/views/admin-audit.js +0 -185
- package/static/v3/js/views/admin-permissions.a7ae5f09.js +0 -177
- package/static/v3/js/views/admin-permissions.js +0 -177
- package/static/v3/js/views/admin-policies.3658fd86.js +0 -102
- package/static/v3/js/views/admin-policies.js +0 -102
- package/static/v3/js/views/admin-private-vpc.7d342d36.js +0 -135
- package/static/v3/js/views/admin-private-vpc.js +0 -135
- package/static/v3/js/views/admin-security.07c66b72.js +0 -180
- package/static/v3/js/views/admin-security.js +0 -180
- package/static/v3/js/views/admin-users.f7ac7b43.js +0 -166
- package/static/v3/js/views/admin-users.js +0 -166
- package/static/v3/js/views/agents.17c5288d.js +0 -564
- package/static/v3/js/views/agents.js +0 -564
- package/static/v3/js/views/chat.e250e2cc.js +0 -624
- package/static/v3/js/views/chat.js +0 -624
- package/static/v3/js/views/files.adad14c1.js +0 -365
- package/static/v3/js/views/files.js +0 -365
- package/static/v3/js/views/graph-canvas.17c15d65.js +0 -509
- package/static/v3/js/views/graph-canvas.js +0 -509
- package/static/v3/js/views/home.24f8b8ae.js +0 -200
- package/static/v3/js/views/home.js +0 -200
- package/static/v3/js/views/hooks.37895880.js +0 -220
- package/static/v3/js/views/hooks.js +0 -220
- package/static/v3/js/views/hybrid-search.2fb63ed9.js +0 -194
- package/static/v3/js/views/hybrid-search.js +0 -194
- package/static/v3/js/views/knowledge-graph.4d09c537.js +0 -529
- package/static/v3/js/views/knowledge-graph.js +0 -529
- package/static/v3/js/views/marketplace.ab0583d4.js +0 -141
- package/static/v3/js/views/marketplace.js +0 -141
- package/static/v3/js/views/mcp.99b5c6a7.js +0 -114
- package/static/v3/js/views/mcp.js +0 -114
- package/static/v3/js/views/memory.4ebdf474.js +0 -147
- package/static/v3/js/views/memory.js +0 -147
- package/static/v3/js/views/models.a1ffa147.js +0 -256
- package/static/v3/js/views/models.js +0 -256
- package/static/v3/js/views/my-computer.d9d9ae1c.js +0 -463
- package/static/v3/js/views/my-computer.js +0 -463
- package/static/v3/js/views/network.52a4f181.js +0 -97
- package/static/v3/js/views/network.js +0 -97
- package/static/v3/js/views/pipeline.c522f1ce.js +0 -157
- package/static/v3/js/views/pipeline.js +0 -157
- package/static/v3/js/views/planning.4876fd77.js +0 -174
- package/static/v3/js/views/planning.js +0 -174
- package/static/v3/js/views/runs.b63b2afa.js +0 -144
- package/static/v3/js/views/runs.js +0 -144
- package/static/v3/js/views/settings.b7140634.js +0 -317
- package/static/v3/js/views/settings.js +0 -317
- package/static/v3/js/views/skills.c6c2f965.js +0 -109
- package/static/v3/js/views/skills.js +0 -109
- package/static/v3/js/views/snapshots.6f5db095.js +0 -135
- package/static/v3/js/views/snapshots.js +0 -135
- package/static/v3/js/views/tools.e4f11276.js +0 -108
- package/static/v3/js/views/tools.js +0 -108
- package/static/v3/js/views/workflows.7752225a.js +0 -213
- package/static/v3/js/views/workflows.js +0 -213
- package/static/v3/js/views/workspace-admin.c466029b.js +0 -156
- package/static/v3/js/views/workspace-admin.js +0 -156
|
@@ -1,529 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* View: Knowledge Graph — the user's digital brain (v3.6.0 Knowledge Graph First).
|
|
3
|
-
* Tabs: Explore (entity/relation mesh) · Status (graph + ingestion health) ·
|
|
4
|
-
* Sources (where every node came from) · Capture (web/URL into the graph) ·
|
|
5
|
-
* Backup (local export / import / backup). Everything you ingest converges here;
|
|
6
|
-
* models read this graph; local-first keeps it yours. Missing data renders an
|
|
7
|
-
* honest unavailable state — never fabricated counters.
|
|
8
|
-
* ========================================================================== */
|
|
9
|
-
|
|
10
|
-
import { escapeHtml } from "../core/dom.js";
|
|
11
|
-
import { createGraphCanvas } from "./graph-canvas.js";
|
|
12
|
-
import { t } from "../core/i18n.js";
|
|
13
|
-
|
|
14
|
-
const TYPE_COLOR = {
|
|
15
|
-
Topic: "var(--lt3-pillar-graph)",
|
|
16
|
-
Concept: "var(--lt3-pillar-vector)",
|
|
17
|
-
Method: "var(--lt3-pillar-hybrid)",
|
|
18
|
-
Model: "var(--accent-3)",
|
|
19
|
-
File: "var(--faint)",
|
|
20
|
-
Source: "var(--lt3-pillar-hybrid)",
|
|
21
|
-
Document: "var(--accent)",
|
|
22
|
-
Decision: "var(--accent-3)",
|
|
23
|
-
Task: "var(--accent-2)",
|
|
24
|
-
Person: "var(--accent-pink)",
|
|
25
|
-
default: "var(--accent)",
|
|
26
|
-
};
|
|
27
|
-
const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
|
|
28
|
-
|
|
29
|
-
const TABS = [
|
|
30
|
-
{ key: "explore", label: "Explore", icon: "chart-dots-3" },
|
|
31
|
-
{ key: "status", label: "Status", icon: "activity-heartbeat" },
|
|
32
|
-
{ key: "sources", label: "Sources", icon: "database" },
|
|
33
|
-
{ key: "capture", label: "Capture", icon: "world-www" },
|
|
34
|
-
{ key: "portability", label: "Backup", icon: "archive" },
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export async function render(ctx) {
|
|
38
|
-
const { h, icon, api, c } = ctx;
|
|
39
|
-
let active = "explore";
|
|
40
|
-
|
|
41
|
-
const tabBar = h("div.lt3-row-2");
|
|
42
|
-
const panelHost = h("div.lt3-stack-4");
|
|
43
|
-
|
|
44
|
-
function renderTabs() {
|
|
45
|
-
tabBar.replaceChildren(...TABS.map((t) =>
|
|
46
|
-
h("button.lt3-btn" + (t.key === active ? ".lt3-btn--primary" : ".lt3-btn--ghost"),
|
|
47
|
-
{ on: { click: () => switchTab(t.key) } }, icon(t.icon), t.label)));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function switchTab(key) {
|
|
51
|
-
if (active === key) return;
|
|
52
|
-
active = key;
|
|
53
|
-
renderTabs();
|
|
54
|
-
renderActive();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let exploreNode = null;
|
|
58
|
-
function renderActive() {
|
|
59
|
-
if (active === "explore") {
|
|
60
|
-
if (!exploreNode) exploreNode = buildExplore(ctx);
|
|
61
|
-
panelHost.replaceChildren(exploreNode);
|
|
62
|
-
} else if (active === "status") {
|
|
63
|
-
renderStatus(ctx, panelHost);
|
|
64
|
-
} else if (active === "sources") {
|
|
65
|
-
renderSources(ctx, panelHost);
|
|
66
|
-
} else if (active === "capture") {
|
|
67
|
-
panelHost.replaceChildren(buildCapture(ctx));
|
|
68
|
-
} else if (active === "portability") {
|
|
69
|
-
renderPortability(ctx, panelHost);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const root = h("div.lt3-stack-6",
|
|
74
|
-
c.viewHeader({
|
|
75
|
-
eyebrow: "Your digital brain",
|
|
76
|
-
title: "Knowledge Graph",
|
|
77
|
-
sub: "Everything you ingest converges here — files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
|
|
78
|
-
actions: [
|
|
79
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
|
|
80
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
|
|
81
|
-
],
|
|
82
|
-
}),
|
|
83
|
-
tabBar,
|
|
84
|
-
panelHost,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
renderTabs();
|
|
88
|
-
renderActive();
|
|
89
|
-
return root;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* ── Explore tab (entity/relation mesh) ─────────────────────────────────── */
|
|
93
|
-
function buildExplore(ctx) {
|
|
94
|
-
const { h, icon, api, c } = ctx;
|
|
95
|
-
const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
|
|
96
|
-
|
|
97
|
-
const canvasHost = h("div", c.loading({ lines: 0, block: true }));
|
|
98
|
-
const inspectorHost = h("div", c.loading({ lines: 4 }));
|
|
99
|
-
const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
|
|
100
|
-
const srcSlot = h("span", c.sourceBadge("pending"));
|
|
101
|
-
|
|
102
|
-
const root = h("div.lt3-stack-3",
|
|
103
|
-
h("div.lt3-row-2",
|
|
104
|
-
srcSlot,
|
|
105
|
-
h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
|
|
106
|
-
),
|
|
107
|
-
statHost,
|
|
108
|
-
h("div.lt3-split",
|
|
109
|
-
h("div.lt3-stack-3",
|
|
110
|
-
c.card(canvasHost, { attrs: { style: "padding:0;overflow:hidden" } }),
|
|
111
|
-
buildLegend(ctx),
|
|
112
|
-
),
|
|
113
|
-
h("aside.lt3-panel",
|
|
114
|
-
h("div.lt3-panel__head", h("div", h("div.lt3-eyebrow", "Inspector"), h("h3.lt3-panel__title", "Entities"))),
|
|
115
|
-
h("div.lt3-search", { style: { "margin-bottom": "var(--lt3-space-4)" } },
|
|
116
|
-
icon("search"),
|
|
117
|
-
h("input", { type: "text", placeholder: "Filter entities…", "aria-label": "Filter entities",
|
|
118
|
-
on: { input: (e) => { state.query = e.target.value.toLowerCase(); renderInspector(); } } }),
|
|
119
|
-
),
|
|
120
|
-
inspectorHost,
|
|
121
|
-
),
|
|
122
|
-
),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
async function load() {
|
|
126
|
-
canvasHost.replaceChildren(c.loading({ lines: 0, block: true }));
|
|
127
|
-
const [g, stats] = await Promise.all([api.graph(), api.graphStats()]);
|
|
128
|
-
state.data = normalize(g.data);
|
|
129
|
-
state.source = g.source;
|
|
130
|
-
srcSlot.replaceChildren(c.sourceBadge(g.source));
|
|
131
|
-
renderStats(stats.data, g.data);
|
|
132
|
-
renderCanvas();
|
|
133
|
-
renderInspector();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function renderStats(stats) {
|
|
137
|
-
const nodes = state.data.nodes.length;
|
|
138
|
-
const edges = state.data.edges.length;
|
|
139
|
-
const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
|
|
140
|
-
const density = nodes > 1 ? (edges / (nodes * (nodes - 1) / 2)) : 0;
|
|
141
|
-
statHost.replaceChildren(
|
|
142
|
-
c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
|
|
143
|
-
c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
|
|
144
|
-
c.stat({ label: "Entity types", value: types, icon: "category" }),
|
|
145
|
-
c.stat({ label: "Density", value: density.toFixed(2), icon: "chart-dots" }),
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Live force-directed canvas (zoom / pan / drag / physics) — replaces the
|
|
150
|
-
// static SVG spiral. The renderer only draws the data it is given.
|
|
151
|
-
let graphCanvas = null;
|
|
152
|
-
|
|
153
|
-
function ensureGraphCanvas() {
|
|
154
|
-
if (graphCanvas) return graphCanvas;
|
|
155
|
-
graphCanvas = createGraphCanvas({
|
|
156
|
-
colorFor,
|
|
157
|
-
onSelect: (id) => {
|
|
158
|
-
state.selected = id;
|
|
159
|
-
renderInspector();
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
return graphCanvas;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function renderCanvas() {
|
|
166
|
-
const { nodes, edges } = state.data;
|
|
167
|
-
if (!nodes.length) {
|
|
168
|
-
if (graphCanvas) { graphCanvas.destroy(); graphCanvas = null; }
|
|
169
|
-
canvasHost.replaceChildren(c.emptyState({ icon: "chart-dots-3", title: "No entities yet", body: "Index a source to populate the graph." }));
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const gc = ensureGraphCanvas();
|
|
173
|
-
gc.setData({ nodes, edges });
|
|
174
|
-
gc.setSelected(state.selected);
|
|
175
|
-
if (!gc.el.isConnected || gc.el.parentElement !== canvasHost.querySelector(".lt3-graph-canvas")) {
|
|
176
|
-
canvasHost.replaceChildren(h("div.lt3-graph-canvas", gc.el));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function syncSelection() {
|
|
181
|
-
if (graphCanvas) graphCanvas.setSelected(state.selected);
|
|
182
|
-
renderInspector();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function renderInspector() {
|
|
186
|
-
if (state.selected) { inspectorHost.replaceChildren(detailView()); return; }
|
|
187
|
-
const q = state.query;
|
|
188
|
-
const list = state.data.nodes
|
|
189
|
-
.filter((n) => !q || (n.label || "").toLowerCase().includes(q) || (n.type || "").toLowerCase().includes(q))
|
|
190
|
-
.sort((a, b) => (b.weight || 0) - (a.weight || 0));
|
|
191
|
-
inspectorHost.replaceChildren(
|
|
192
|
-
list.length
|
|
193
|
-
? h("div.lt3-stack-2", list.slice(0, 60).map((n) => entityRow(n)))
|
|
194
|
-
: c.emptyState({ icon: "search-off", title: "No matches", body: "Try a different entity name." }),
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function entityRow(n) {
|
|
199
|
-
return h("button.lt3-entity", { on: { click: () => { state.selected = n.id; syncSelection(); } } },
|
|
200
|
-
h("div.lt3-entity__type", { style: { background: `color-mix(in srgb, ${colorFor(n.type)} 18%, transparent)`, color: colorFor(n.type) } }, icon(iconForType(n.type))),
|
|
201
|
-
h("div.lt3-entity__body",
|
|
202
|
-
h("div.lt3-entity__name", n.label),
|
|
203
|
-
h("div.lt3-entity__meta", `${n.type || "Entity"} · weight ${(n.weight || 0).toFixed(2)}`),
|
|
204
|
-
),
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function detailView() {
|
|
209
|
-
const n = state.data.nodes.find((x) => x.id === state.selected);
|
|
210
|
-
if (!n) { state.selected = null; return c.emptyState({ title: "Not found" }); }
|
|
211
|
-
const rels = state.data.edges
|
|
212
|
-
.filter((e) => e.from === n.id || e.to === n.id)
|
|
213
|
-
.map((e) => {
|
|
214
|
-
const otherId = e.from === n.id ? e.to : e.from;
|
|
215
|
-
const other = state.data.nodes.find((x) => x.id === otherId);
|
|
216
|
-
return { type: e.type, dir: e.from === n.id ? "→" : "←", other };
|
|
217
|
-
})
|
|
218
|
-
.filter((r) => r.other);
|
|
219
|
-
return h("div.lt3-stack-4",
|
|
220
|
-
h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null; syncSelection(); } } }, icon("arrow-left"), "All entities"),
|
|
221
|
-
h("div.lt3-card.lt3-card--flat",
|
|
222
|
-
h("div.lt3-row-2", { style: { "margin-bottom": "var(--lt3-space-2)" } },
|
|
223
|
-
h("span.lt3-pill", { style: { color: colorFor(n.type) } }, n.type || "Entity"),
|
|
224
|
-
),
|
|
225
|
-
h("div", { style: { "font-size": "var(--lt3-text-lg)", "font-weight": 700 } }, n.label),
|
|
226
|
-
n.summary && h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-2)" } }, n.summary),
|
|
227
|
-
),
|
|
228
|
-
h("div",
|
|
229
|
-
h("div.lt3-eyebrow", { style: { "margin-bottom": "var(--lt3-space-2)" } }, `Relations (${rels.length})`),
|
|
230
|
-
rels.length
|
|
231
|
-
? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id; syncSelection(); } } },
|
|
232
|
-
h("div.lt3-entity__type", { style: { background: "var(--surface-3)" } }, h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, r.dir)),
|
|
233
|
-
h("div.lt3-entity__body",
|
|
234
|
-
h("div.lt3-entity__name", r.other.label),
|
|
235
|
-
h("div.lt3-entity__meta", r.type),
|
|
236
|
-
),
|
|
237
|
-
)))
|
|
238
|
-
: c.emptyState({ icon: "unlink", title: "No relations", body: "This entity is currently isolated." }),
|
|
239
|
-
),
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
load();
|
|
244
|
-
return root;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/* ── Status tab (graph + ingestion health) ──────────────────────────────── */
|
|
248
|
-
async function renderStatus(ctx, host) {
|
|
249
|
-
const { h, icon, api, c } = ctx;
|
|
250
|
-
host.replaceChildren(c.loading({ lines: 3 }));
|
|
251
|
-
const [port, gs, idx, coverage] = await Promise.all([api.kgPortability(), api.graphStats(), api.indexStatus(), api.kgProvenanceCoverage()]);
|
|
252
|
-
const p = port.data || {};
|
|
253
|
-
const prov = p.provenance || {};
|
|
254
|
-
const cov = coverage.data || {};
|
|
255
|
-
const nodes = sumCounts((gs.data && gs.data.nodes) || {});
|
|
256
|
-
const edges = sumCounts((gs.data && gs.data.edges) || {});
|
|
257
|
-
const pipelines = (idx.data && idx.data.pipelines) || {};
|
|
258
|
-
const ratio = Number(cov.coverage_ratio ?? cov.ratio ?? 0);
|
|
259
|
-
const covered = Number(cov.nodes_with_provenance ?? cov.covered_nodes ?? 0);
|
|
260
|
-
|
|
261
|
-
host.replaceChildren(
|
|
262
|
-
h("div.lt3-row-2", c.sourceBadge(port.source === "live" || coverage.source === "live" ? "live" : port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } },
|
|
263
|
-
p.graph_schema_version != null ? `Schema v${p.graph_schema_version} · embed dim ${p.embed_dim ?? "—"}` : "Knowledge Graph status")),
|
|
264
|
-
h("div.lt3-statrow",
|
|
265
|
-
c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
|
|
266
|
-
c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
|
|
267
|
-
c.stat({ label: "Ingested items", value: c.fmtNum(prov.total || 0), icon: "package-import" }),
|
|
268
|
-
c.stat({ label: "Embedded (RAG-ready)", value: c.fmtNum(prov.embedded || 0), icon: "vector" }),
|
|
269
|
-
c.stat({ label: t("kg.provenanceCoverage"), value: `${Math.round(ratio * 100)}%`, icon: "shield-check", delta: `${covered}/${cov.total_nodes ?? nodes}` }),
|
|
270
|
-
),
|
|
271
|
-
c.card(
|
|
272
|
-
h("div.lt3-stack-3",
|
|
273
|
-
h("div.lt3-eyebrow", "Pipelines"),
|
|
274
|
-
pipelineRow(ctx, "Knowledge graph", pipelines.knowledge_graph),
|
|
275
|
-
pipelineRow(ctx, "Vector index", pipelines.vector_index),
|
|
276
|
-
pipelineRow(ctx, "Hybrid retrieval", pipelines.hybrid),
|
|
277
|
-
),
|
|
278
|
-
),
|
|
279
|
-
c.card(h("div.lt3-stack-3",
|
|
280
|
-
h("div.lt3-eyebrow", t("kg.provenanceCoverage")),
|
|
281
|
-
h("dl.lt3-keyval",
|
|
282
|
-
h("dt", t("kg.coveredNodes")), h("dd", `${covered}/${cov.total_nodes ?? nodes}`),
|
|
283
|
-
h("dt", t("kg.sourceTypes")), h("dd", compactCounts(cov.provenance_by_source_type || cov.by_source_type || {})),
|
|
284
|
-
h("dt", t("kg.uncoveredTypes")), h("dd", compactCounts(cov.uncovered_by_type || {})),
|
|
285
|
-
),
|
|
286
|
-
)),
|
|
287
|
-
prov.last_ingested_at
|
|
288
|
-
? h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, `Last ingestion: ${fmtWhen(prov.last_ingested_at)} · ${prov.duplicates || 0} duplicate(s) linked, not re-stored.`)
|
|
289
|
-
: c.emptyState({ icon: "package-import", title: "Nothing ingested yet", body: "Add files or capture a page to populate the graph." }),
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function pipelineRow(ctx, label, pipe) {
|
|
294
|
-
const { h, c } = ctx;
|
|
295
|
-
const stateStr = (pipe && pipe.state) || "unavailable";
|
|
296
|
-
const detail = pipe && (pipe.entities != null ? `${pipe.entities} entities` : pipe.vectors != null ? `${pipe.vectors} vectors` : pipe.strategy || "");
|
|
297
|
-
return h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
|
|
298
|
-
h("div", label, detail ? h("span.lt3-muted", { style: { "margin-left": "var(--lt3-space-2)", "font-size": "var(--lt3-text-sm)" } }, detail) : null),
|
|
299
|
-
c.statePill(stateStr),
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/* ── Sources tab (provenance: where every node came from) ────────────────── */
|
|
304
|
-
async function renderSources(ctx, host) {
|
|
305
|
-
const { h, icon, api, c } = ctx;
|
|
306
|
-
host.replaceChildren(c.loading({ lines: 3 }));
|
|
307
|
-
const [port, recent] = await Promise.all([api.kgPortability(), api.kgProvenance(40)]);
|
|
308
|
-
const bySource = (port.data && port.data.provenance && port.data.provenance.by_source_type) || {};
|
|
309
|
-
const items = (recent.data && recent.data.items) || [];
|
|
310
|
-
|
|
311
|
-
const sourceCards = Object.keys(bySource).length
|
|
312
|
-
? h("div.lt3-statrow", Object.entries(bySource).map(([k, v]) =>
|
|
313
|
-
c.stat({ label: prettySource(k), value: c.fmtNum(v), icon: iconForSource(k) })))
|
|
314
|
-
: c.emptyState({ icon: "database", title: "No sources yet", body: "Connect a folder, upload a file, or capture a page." });
|
|
315
|
-
|
|
316
|
-
const recentList = items.length
|
|
317
|
-
? h("div.lt3-stack-2", items.map((it) =>
|
|
318
|
-
h("div.lt3-entity",
|
|
319
|
-
h("div.lt3-entity__type", { style: { background: "var(--surface-3)", color: colorFor("Source") } }, icon(iconForSource(it.source_type))),
|
|
320
|
-
h("div.lt3-entity__body",
|
|
321
|
-
h("div.lt3-entity__name", it.title || it.source_uri || it.node_id),
|
|
322
|
-
h("div.lt3-entity__meta", `${prettySource(it.source_type)} · ${fmtWhen(it.created_at)}${it.embedded ? " · embedded" : ""}${it.duplicate ? " · duplicate" : ""}`),
|
|
323
|
-
),
|
|
324
|
-
)))
|
|
325
|
-
: c.emptyState({ icon: "history", title: "No recent ingestions", body: "Ingested items will appear here with full provenance." });
|
|
326
|
-
|
|
327
|
-
host.replaceChildren(
|
|
328
|
-
h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Every node records where it came from (provenance).")),
|
|
329
|
-
sourceCards,
|
|
330
|
-
c.card(h("div.lt3-stack-3", h("div.lt3-eyebrow", "Recent ingestions"), recentList)),
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/* ── Capture tab (web/URL into the graph) ───────────────────────────────── */
|
|
335
|
-
function buildCapture(ctx) {
|
|
336
|
-
const { h, icon, api, c } = ctx;
|
|
337
|
-
const input = h("input", { type: "url", placeholder: "https://example.com/article", "aria-label": "URL to capture",
|
|
338
|
-
style: { flex: "1" } });
|
|
339
|
-
const result = h("div");
|
|
340
|
-
|
|
341
|
-
async function run() {
|
|
342
|
-
const url = (input.value || "").trim();
|
|
343
|
-
if (!url) { result.replaceChildren(c.banner("Enter a URL first.", "warn", "alert-triangle")); return; }
|
|
344
|
-
result.replaceChildren(c.loading({ lines: 1 }));
|
|
345
|
-
const res = await api.browserReadUrl(url);
|
|
346
|
-
const d = res.data || {};
|
|
347
|
-
if (res.ok && d.status === "ok") {
|
|
348
|
-
result.replaceChildren(c.banner(`Added to your Knowledge Graph${d.duplicate ? " (already present — linked)" : ""}. ${d.chunk_count || 0} chunk(s) indexed.`, "ok", "circle-check"));
|
|
349
|
-
ctx.toast && ctx.toast("Page added to Knowledge Graph");
|
|
350
|
-
} else if (d.status === "empty") {
|
|
351
|
-
result.replaceChildren(c.banner("No readable text was found on that page.", "warn", "alert-triangle"));
|
|
352
|
-
} else {
|
|
353
|
-
const detail = d.detail || (res.status === 422 ? "The page is blocked or login-required." : "Could not read that URL.");
|
|
354
|
-
result.replaceChildren(c.banner(detail, "err", "alert-triangle"));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return h("div.lt3-stack-4",
|
|
359
|
-
c.card(h("div.lt3-stack-3",
|
|
360
|
-
h("div.lt3-eyebrow", "Capture a web page"),
|
|
361
|
-
h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The local runtime fetches the page, extracts readable text, and indexes it into your graph as a web source. Nothing is sent to a cloud service."),
|
|
362
|
-
h("div.lt3-row-2",
|
|
363
|
-
input,
|
|
364
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: run } }, icon("world-download"), "Read into graph"),
|
|
365
|
-
),
|
|
366
|
-
result,
|
|
367
|
-
)),
|
|
368
|
-
c.card(h("div.lt3-stack-2",
|
|
369
|
-
h("div.lt3-eyebrow", "Browser extension"),
|
|
370
|
-
h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Install the local Manifest V3 extension (browser-extension/) to send the current tab to your Knowledge Graph with one click. It posts only to 127.0.0.1 — never to a cloud server."),
|
|
371
|
-
)),
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/* ── Portability tab (export / import / backup) ─────────────────────────── */
|
|
376
|
-
async function renderPortability(ctx, host) {
|
|
377
|
-
const { h, icon, api, c } = ctx;
|
|
378
|
-
host.replaceChildren(c.loading({ lines: 2 }));
|
|
379
|
-
const port = await api.kgPortability();
|
|
380
|
-
const status = h("div");
|
|
381
|
-
|
|
382
|
-
function note(tone, text) {
|
|
383
|
-
status.replaceChildren(c.banner(text, tone, tone === "err" ? "alert-triangle" : tone === "ok" ? "circle-check" : "info-circle"));
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
async function doExport() {
|
|
387
|
-
note("info", "Exporting…");
|
|
388
|
-
const res = await api.graphExport();
|
|
389
|
-
if (!res.ok || !res.data || res.data.raw) { note("err", "Export is unavailable."); return; }
|
|
390
|
-
try {
|
|
391
|
-
const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
|
|
392
|
-
const url = URL.createObjectURL(blob);
|
|
393
|
-
const a = document.createElement("a");
|
|
394
|
-
a.href = url; a.download = "lattice-kg-export.json"; a.click();
|
|
395
|
-
URL.revokeObjectURL(url);
|
|
396
|
-
note("ok", `Exported ${(res.data.counts && res.data.counts.nodes) || 0} nodes. Download started.`);
|
|
397
|
-
} catch (e) { note("err", "Could not build the download."); }
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async function doBackup() {
|
|
401
|
-
note("info", "Backing up…");
|
|
402
|
-
const res = await api.graphBackup();
|
|
403
|
-
if (res.ok && res.data && res.data.path) {
|
|
404
|
-
note("ok", `Backup written locally: ${res.data.path}`);
|
|
405
|
-
} else {
|
|
406
|
-
note("err", (res.data && (res.data.detail || res.data.error)) || "Backup requires admin and a running runtime.");
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const importArea = h("textarea", { rows: 5, placeholder: "Paste a Knowledge Graph export (JSON) to validate, then import…",
|
|
411
|
-
"aria-label": "Import artifact", style: { width: "100%", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } });
|
|
412
|
-
|
|
413
|
-
async function doImport(dryRun) {
|
|
414
|
-
let artifact;
|
|
415
|
-
try { artifact = JSON.parse(importArea.value || ""); }
|
|
416
|
-
catch { note("err", "That is not valid JSON."); return; }
|
|
417
|
-
note("info", dryRun ? "Validating…" : "Importing…");
|
|
418
|
-
const res = await api.graphImport(artifact, "merge", dryRun);
|
|
419
|
-
if (res.ok && res.data && !res.data.detail) {
|
|
420
|
-
const d = res.data;
|
|
421
|
-
note("ok", dryRun
|
|
422
|
-
? `Valid — would import ${d.nodes || 0} nodes, ${d.edges || 0} edges.`
|
|
423
|
-
: `Imported ${d.nodes || 0} nodes, ${d.edges || 0} edges.`);
|
|
424
|
-
} else {
|
|
425
|
-
note("err", (res.data && (res.data.detail || res.data.error)) || "Import requires admin.");
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
const p = port.data || {};
|
|
430
|
-
host.replaceChildren(
|
|
431
|
-
h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "The Knowledge Graph is your durable asset — portable with no cloud.")),
|
|
432
|
-
c.card(h("div.lt3-stack-3",
|
|
433
|
-
h("div.lt3-eyebrow", "Export & backup"),
|
|
434
|
-
h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } }, "Export a portable JSON of nodes/edges/provenance, or write a full local binary backup (DB + blobs)."),
|
|
435
|
-
h("div.lt3-row-2",
|
|
436
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: doExport } }, icon("download"), "Export JSON"),
|
|
437
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: doBackup } }, icon("archive"), "Backup (admin)"),
|
|
438
|
-
),
|
|
439
|
-
)),
|
|
440
|
-
c.card(h("div.lt3-stack-3",
|
|
441
|
-
h("div.lt3-eyebrow", "Import"),
|
|
442
|
-
importArea,
|
|
443
|
-
h("div.lt3-row-2",
|
|
444
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => doImport(true) } }, icon("checks"), "Validate (dry-run)"),
|
|
445
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: () => doImport(false) } }, icon("file-import"), "Import (merge, admin)"),
|
|
446
|
-
),
|
|
447
|
-
)),
|
|
448
|
-
status,
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/* ── helpers ─────────────────────────────────────────────────────────────── */
|
|
453
|
-
function sumCounts(obj) {
|
|
454
|
-
return Object.values(obj || {}).reduce((a, b) => a + (Number(b) || 0), 0);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function compactCounts(obj) {
|
|
458
|
-
const entries = Object.entries(obj || {});
|
|
459
|
-
return entries.length ? entries.map(([k, v]) => `${k}: ${v}`).join(" · ") : "—";
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function prettySource(k) {
|
|
463
|
-
return ({ web_url: "Web URL", browser_tab: "Browser tab", file: "Files", local_file: "Local files",
|
|
464
|
-
note: "Notes", text: "Text", markdown: "Markdown", code: "Code", upload: "Uploads" })[k] || k;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function iconForSource(k) {
|
|
468
|
-
return ({ web_url: "world", browser_tab: "browser", file: "file", local_file: "folder",
|
|
469
|
-
note: "note", text: "text-caption", markdown: "markdown", code: "code", upload: "upload" })[k] || "database";
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function fmtWhen(iso) {
|
|
473
|
-
if (!iso) return "—";
|
|
474
|
-
try {
|
|
475
|
-
const d = new Date(iso);
|
|
476
|
-
if (isNaN(d.getTime())) return String(iso);
|
|
477
|
-
return d.toLocaleString();
|
|
478
|
-
} catch { return String(iso); }
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function normalize(data) {
|
|
482
|
-
const nodes = (data.nodes || []).map((n) => ({
|
|
483
|
-
id: n.id,
|
|
484
|
-
label: n.label || n.title || n.id,
|
|
485
|
-
type: n.type || "Entity",
|
|
486
|
-
weight: n.weight ?? n.importance_norm ?? (n.metadata && n.metadata.graph_metrics && n.metadata.graph_metrics.importance_norm) ?? 0.5,
|
|
487
|
-
summary: n.summary || "",
|
|
488
|
-
x: n.x, y: n.y,
|
|
489
|
-
}));
|
|
490
|
-
const ids = new Set(nodes.map((n) => n.id));
|
|
491
|
-
const edges = (data.edges || []).filter((e) => ids.has(e.from) && ids.has(e.to))
|
|
492
|
-
.map((e) => ({ from: e.from, to: e.to, type: e.type || "related", weight: e.weight || 1 }));
|
|
493
|
-
return { nodes, edges };
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function layout(nodes) {
|
|
497
|
-
const W = 1000, H = 600, cx = W / 2, cy = H / 2;
|
|
498
|
-
const golden = Math.PI * (3 - Math.sqrt(5));
|
|
499
|
-
const hasCoords = nodes.length && nodes.every((n) => typeof n.x === "number" && typeof n.y === "number");
|
|
500
|
-
if (hasCoords) {
|
|
501
|
-
return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
|
|
502
|
-
}
|
|
503
|
-
const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
|
|
504
|
-
const maxR = Math.min(W, H) * 0.42;
|
|
505
|
-
const placed = {};
|
|
506
|
-
order.forEach((o, rank) => {
|
|
507
|
-
const radius = rank === 0 ? 0 : maxR * Math.sqrt(rank / Math.max(1, nodes.length - 1));
|
|
508
|
-
const angle = rank * golden;
|
|
509
|
-
placed[o.i] = {
|
|
510
|
-
px: Math.round(cx + Math.cos(angle) * radius),
|
|
511
|
-
py: Math.round(cy + Math.sin(angle) * radius * 0.66),
|
|
512
|
-
};
|
|
513
|
-
});
|
|
514
|
-
return nodes.map((n, i) => ({ ...n, ...placed[i] }));
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
|
|
518
|
-
|
|
519
|
-
function iconForType(t) {
|
|
520
|
-
return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Source: "world",
|
|
521
|
-
Document: "file-text", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
function buildLegend({ h }) {
|
|
525
|
-
const types = ["Source", "Document", "Concept", "Person", "Decision"];
|
|
526
|
-
return h("div.lt3-graph-legend",
|
|
527
|
-
types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
|
|
528
|
-
);
|
|
529
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* View: Marketplace — agent templates, plugins, and skills.
|
|
3
|
-
* Templates come from /marketplace/templates (offline local catalog incl. the
|
|
4
|
-
* five named agent templates). Install / Clone / Export use the real backend.
|
|
5
|
-
* Plugins and skills marketplace read live directories; unavailable is shown
|
|
6
|
-
* honestly with no fabricated catalog.
|
|
7
|
-
* ========================================================================== */
|
|
8
|
-
|
|
9
|
-
const KIND_VARIANT = { agent: "info", workflow: "warn", plugin: "" };
|
|
10
|
-
|
|
11
|
-
export async function render(ctx) {
|
|
12
|
-
const { h, c } = ctx;
|
|
13
|
-
const body = h("div", c.loading({ lines: 4, block: true }));
|
|
14
|
-
let tab = "templates";
|
|
15
|
-
|
|
16
|
-
const tabsEl = c.tabs(
|
|
17
|
-
[{ key: "templates", label: "Templates" }, { key: "plugins", label: "Plugins" }, { key: "skills", label: "Skills" }],
|
|
18
|
-
tab, (k) => { tab = k; paint(); },
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const root = h("div.lt3-stack-6",
|
|
22
|
-
c.viewHeader({
|
|
23
|
-
eyebrow: "Platform",
|
|
24
|
-
title: "Marketplace",
|
|
25
|
-
sub: "Reusable agent templates, plugins, and skills — install, clone, customize, export, and import, all from /app.",
|
|
26
|
-
}),
|
|
27
|
-
tabsEl,
|
|
28
|
-
body,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
paint();
|
|
32
|
-
return root;
|
|
33
|
-
|
|
34
|
-
function paint() {
|
|
35
|
-
[...tabsEl.querySelectorAll(".lt3-tab")].forEach((b, i) => { b.dataset.active = String(["templates", "plugins", "skills"][i] === tab); });
|
|
36
|
-
body.replaceChildren(c.loading({ lines: 3, block: true }));
|
|
37
|
-
if (tab === "templates") return paintTemplates();
|
|
38
|
-
if (tab === "plugins") return paintPlugins();
|
|
39
|
-
return paintSkills();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function paintTemplates() {
|
|
43
|
-
const res = await ctx.api.templates();
|
|
44
|
-
const list = (res.data && res.data.templates) || [];
|
|
45
|
-
if (!list.length) {
|
|
46
|
-
body.replaceChildren(stateRow(ctx, res.source), c.emptyState({ icon: "package-off", title: "Catalog unavailable", body: "Start the backend to load the template catalog." }));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const byKind = {};
|
|
50
|
-
for (const t of list) (byKind[t.kind] = byKind[t.kind] || []).push(t);
|
|
51
|
-
const sections = Object.keys(byKind).map((kind) =>
|
|
52
|
-
h("section",
|
|
53
|
-
c.sectionHead(`${cap(kind)} templates`, c.pill(String(byKind[kind].length))),
|
|
54
|
-
h("div.lt3-grid-auto", byKind[kind].map((t) => templateCard(ctx, t))),
|
|
55
|
-
));
|
|
56
|
-
body.replaceChildren(h("div.lt3-stack-6", stateRow(ctx, res.source), ...sections));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function templateCard(ctx2, t) {
|
|
60
|
-
const def = t.definition || {};
|
|
61
|
-
const caps = def.capabilities || def.roles || [];
|
|
62
|
-
return c.card(h("div.lt3-stack-3",
|
|
63
|
-
h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
|
|
64
|
-
h("div", h("b", t.name), h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, t.id)),
|
|
65
|
-
c.pill(t.kind, KIND_VARIANT[t.kind] || ""),
|
|
66
|
-
),
|
|
67
|
-
h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, t.description || ""),
|
|
68
|
-
caps.length ? h("div.lt3-cluster", caps.slice(0, 6).map((x) => h("span.lt3-chip", x))) : null,
|
|
69
|
-
h("div.lt3-row-2",
|
|
70
|
-
h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => install(ctx2, t) } }, c.icon("download"), "Install"),
|
|
71
|
-
h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => clone(ctx2, t) } }, c.icon("copy"), "Clone"),
|
|
72
|
-
h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => exportT(ctx2, t) } }, c.icon("file-export"), "Export"),
|
|
73
|
-
),
|
|
74
|
-
h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `v${t.version || "1.0.0"} · ${(t.metadata && t.metadata.category) || "general"}`),
|
|
75
|
-
), { interactive: false });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function install(ctx2, t) {
|
|
79
|
-
const res = await ctx2.api.installTemplate(t);
|
|
80
|
-
ctx2.toast(res && res.ok ? `Installed ${t.name}` : "Install unavailable", res && res.ok ? "ok" : "err");
|
|
81
|
-
}
|
|
82
|
-
async function clone(ctx2, t) {
|
|
83
|
-
const res = await ctx2.api.cloneTemplate(t.kind, t.id, `${t.name} (Copy)`);
|
|
84
|
-
ctx2.toast(res && res.ok ? `Cloned to ${res.data.template.id}` : "Clone unavailable", res && res.ok ? "ok" : "err");
|
|
85
|
-
}
|
|
86
|
-
async function exportT(ctx2, t) {
|
|
87
|
-
const res = await ctx2.api.exportTemplate(t.kind, t.id);
|
|
88
|
-
if (res && res.ok && res.data) {
|
|
89
|
-
try {
|
|
90
|
-
const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
|
|
91
|
-
const a = document.createElement("a");
|
|
92
|
-
a.href = URL.createObjectURL(blob); a.download = `${t.id}.template.json`; a.click();
|
|
93
|
-
URL.revokeObjectURL(a.href);
|
|
94
|
-
ctx2.toast("Exported template", "ok");
|
|
95
|
-
} catch { ctx2.toast("Export failed", "err"); }
|
|
96
|
-
} else { ctx2.toast("Export unavailable", "err"); }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function paintPlugins() {
|
|
100
|
-
const [reg, dir] = await Promise.all([ctx.api.pluginsRegistry(), ctx.api.pluginsDirectory()]);
|
|
101
|
-
const installed = (reg.data && reg.data.plugins) || [];
|
|
102
|
-
const directory = (dir.data && dir.data.plugins) || [];
|
|
103
|
-
if (!installed.length && !directory.length) {
|
|
104
|
-
body.replaceChildren(stateRow(ctx, reg.source), c.emptyState({ icon: "plug-off", title: "No plugins", body: "Plugin registry and directory are unavailable." }));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
body.replaceChildren(h("div.lt3-stack-6",
|
|
108
|
-
stateRow(ctx, reg.source),
|
|
109
|
-
h("section", c.sectionHead("Installed plugins", c.pill(String(installed.length))),
|
|
110
|
-
installed.length ? h("div.lt3-grid-auto", installed.map((p) => simpleCard(ctx, p.name || p.id, p.description, p.version, "ok"))) : hint(ctx, "No plugins installed.")),
|
|
111
|
-
h("section", c.sectionHead("Directory", c.pill(String(directory.length))),
|
|
112
|
-
directory.length ? h("div.lt3-grid-auto", directory.slice(0, 30).map((p) => simpleCard(ctx, p.name, p.description, p.version, null, p.author))) : hint(ctx, "Directory unavailable.")),
|
|
113
|
-
));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function paintSkills() {
|
|
117
|
-
const res = await ctx.api.skillsMarketplace();
|
|
118
|
-
const skills = (res.data && res.data.skills) || [];
|
|
119
|
-
body.replaceChildren(h("div.lt3-stack-3",
|
|
120
|
-
stateRow(ctx, res.source),
|
|
121
|
-
h("p.lt3-faint", { style: { margin: 0 } }, "Manage installed skills in the Skills view; this is the discovery catalog."),
|
|
122
|
-
skills.length
|
|
123
|
-
? h("div.lt3-grid-auto", skills.slice(0, 40).map((s) => simpleCard(ctx, s.skill || s.name, s.description, s.version, s.installed ? "ok" : null, s.author)))
|
|
124
|
-
: c.emptyState({ icon: "puzzle-off", title: "Skills catalog unavailable", body: "The skills marketplace did not respond." }),
|
|
125
|
-
));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function stateRow(ctx, source) {
|
|
130
|
-
return ctx.h("div.lt3-row-2", { style: { "justify-content": "flex-end" } }, ctx.c.sourceBadge(source));
|
|
131
|
-
}
|
|
132
|
-
function simpleCard(ctx, name, desc, version, state, author) {
|
|
133
|
-
const { h, c } = ctx;
|
|
134
|
-
return c.card(h("div.lt3-stack-2",
|
|
135
|
-
h("div.lt3-row", { style: { "justify-content": "space-between" } }, h("b", name || "Untitled"), state ? c.statePill(state === "ok" ? "ready" : state) : null),
|
|
136
|
-
h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, desc || ""),
|
|
137
|
-
h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, [version ? `v${version}` : null, author ? `by ${author}` : null].filter(Boolean).join(" · ")),
|
|
138
|
-
), { flat: true });
|
|
139
|
-
}
|
|
140
|
-
function hint(ctx, text) { return ctx.h("p.lt3-faint", { style: { margin: 0 } }, text); }
|
|
141
|
-
function cap(s) { return String(s || "").charAt(0).toUpperCase() + String(s || "").slice(1); }
|