ltcai 4.0.0 → 4.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.
- package/README.md +42 -33
- package/desktop/electron/main.cjs +44 -0
- package/docs/CHANGELOG.md +106 -0
- package/docs/REALTIME_COLLABORATION.md +3 -3
- package/docs/V3_FRONTEND.md +9 -8
- 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_DIGITAL_BRAIN_RECOVERY.md +95 -45
- package/docs/kg-schema.md +6 -2
- package/docs/spec-vs-impl.md +10 -10
- package/frontend/index.html +24 -0
- package/frontend/openapi.json +14190 -0
- package/frontend/src/App.tsx +184 -0
- package/frontend/src/api/client.ts +317 -0
- package/frontend/src/api/openapi.ts +16637 -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 +344 -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 +2 -603
- package/knowledge_graph.py +37 -4958
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/admin.py +15 -16
- package/latticeai/api/agents.py +13 -6
- package/latticeai/api/auth.py +19 -11
- package/latticeai/api/invitations.py +100 -0
- package/latticeai/api/knowledge_graph.py +4 -11
- package/latticeai/api/plugins.py +3 -6
- package/latticeai/api/realtime.py +4 -7
- package/latticeai/api/setup.py +5 -4
- package/latticeai/api/static_routes.py +13 -16
- package/latticeai/api/ui_redirects.py +26 -0
- package/latticeai/api/workflow_designer.py +39 -6
- package/latticeai/api/workspace.py +24 -10
- package/latticeai/app_factory.py +88 -17
- package/latticeai/brain/_kg_common.py +1123 -0
- package/latticeai/brain/discovery.py +1455 -0
- package/latticeai/brain/documents.py +218 -0
- package/latticeai/brain/ingest.py +644 -0
- package/latticeai/brain/projection.py +561 -0
- package/latticeai/brain/provenance.py +401 -0
- package/latticeai/brain/retrieval.py +1316 -0
- package/latticeai/brain/schema.py +640 -0
- package/latticeai/brain/store.py +216 -0
- package/latticeai/brain/write_master.py +225 -0
- package/latticeai/core/invitations.py +131 -0
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/multi_agent.py +1 -1
- package/latticeai/core/policy.py +54 -0
- package/latticeai/core/realtime.py +65 -44
- package/latticeai/core/sessions.py +31 -5
- package/latticeai/core/users.py +147 -0
- package/latticeai/core/workspace_os.py +420 -20
- package/latticeai/services/agent_runtime.py +242 -4
- package/latticeai/services/run_executor.py +328 -0
- package/latticeai/services/workspace_service.py +27 -19
- package/package.json +54 -27
- package/scripts/build_frontend_assets.mjs +38 -0
- package/scripts/bump_version.py +1 -1
- package/scripts/export_openapi.py +31 -0
- package/scripts/lint_frontend.mjs +86 -0
- package/scripts/run_python.mjs +47 -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 +36 -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-CJRAzNnf.js +333 -0
- package/static/app/assets/index-CJRAzNnf.js.map +1 -0
- package/static/app/assets/index-CSwBBgf4.css +2 -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 -97
- package/static/account.html +0 -113
- package/static/activity.html +0 -73
- package/static/admin.html +0 -486
- package/static/agents.html +0 -139
- package/static/chat.html +0 -841
- package/static/css/reference/account.css +0 -439
- package/static/css/reference/admin.css +0 -610
- package/static/css/reference/base.css +0 -1661
- package/static/css/reference/chat.css +0 -4623
- package/static/css/reference/graph.css +0 -1016
- package/static/css/responsive.css +0 -861
- package/static/graph.html +0 -122
- package/static/platform.css +0 -104
- package/static/plugins.html +0 -136
- package/static/scripts/account.js +0 -238
- package/static/scripts/admin.js +0 -1614
- package/static/scripts/chat.js +0 -5081
- package/static/scripts/graph.js +0 -1804
- package/static/scripts/platform.js +0 -64
- package/static/scripts/ux.js +0 -167
- package/static/scripts/workspace.js +0 -948
- package/static/v3/asset-manifest.json +0 -56
- 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.356e6452.js +0 -26
- package/static/v3/js/app.js +0 -26
- package/static/v3/js/core/api.7a308b89.js +0 -568
- package/static/v3/js/core/api.js +0 -568
- 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/router.584570f2.js +0 -37
- package/static/v3/js/core/router.js +0 -37
- package/static/v3/js/core/routes.7222343d.js +0 -93
- package/static/v3/js/core/routes.js +0 -93
- package/static/v3/js/core/shell.a1657f20.js +0 -391
- package/static/v3/js/core/shell.js +0 -391
- package/static/v3/js/core/store.204a08b2.js +0 -113
- package/static/v3/js/core/store.js +0 -113
- 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.03bac88c.js +0 -168
- package/static/v3/js/views/admin-users.js +0 -168
- package/static/v3/js/views/agents.014d0b74.js +0 -541
- package/static/v3/js/views/agents.js +0 -541
- package/static/v3/js/views/chat.e6dd7dd0.js +0 -601
- package/static/v3/js/views/chat.js +0 -601
- 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.5e40cbeb.js +0 -509
- package/static/v3/js/views/knowledge-graph.js +0 -509
- 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/pipeline.c522f1ce.js +0 -157
- package/static/v3/js/views/pipeline.js +0 -157
- package/static/v3/js/views/planning.9ac3e313.js +0 -153
- package/static/v3/js/views/planning.js +0 -153
- package/static/v3/js/views/settings.8631fa5e.js +0 -318
- package/static/v3/js/views/settings.js +0 -318
- package/static/v3/js/views/skills.c6c2f965.js +0 -109
- package/static/v3/js/views/skills.js +0 -109
- 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.26c57290.js +0 -128
- package/static/v3/js/views/workflows.js +0 -128
- package/static/workflows.html +0 -146
- package/static/workspace.css +0 -1121
- package/static/workspace.html +0 -357
|
@@ -1,509 +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.a2773eb0.js";
|
|
11
|
-
import { createGraphCanvas } from "./graph-canvas.17c15d65.js";
|
|
12
|
-
|
|
13
|
-
const TYPE_COLOR = {
|
|
14
|
-
Topic: "var(--lt3-pillar-graph)",
|
|
15
|
-
Concept: "var(--lt3-pillar-vector)",
|
|
16
|
-
Method: "var(--lt3-pillar-hybrid)",
|
|
17
|
-
Model: "var(--accent-3)",
|
|
18
|
-
File: "var(--faint)",
|
|
19
|
-
Source: "var(--lt3-pillar-hybrid)",
|
|
20
|
-
Document: "var(--accent)",
|
|
21
|
-
Decision: "var(--accent-3)",
|
|
22
|
-
Task: "var(--accent-2)",
|
|
23
|
-
Person: "var(--accent-pink)",
|
|
24
|
-
default: "var(--accent)",
|
|
25
|
-
};
|
|
26
|
-
const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
|
|
27
|
-
|
|
28
|
-
const TABS = [
|
|
29
|
-
{ key: "explore", label: "Explore", icon: "chart-dots-3" },
|
|
30
|
-
{ key: "status", label: "Status", icon: "activity-heartbeat" },
|
|
31
|
-
{ key: "sources", label: "Sources", icon: "database" },
|
|
32
|
-
{ key: "capture", label: "Capture", icon: "world-www" },
|
|
33
|
-
{ key: "portability", label: "Backup", icon: "archive" },
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
export async function render(ctx) {
|
|
37
|
-
const { h, icon, api, c } = ctx;
|
|
38
|
-
let active = "explore";
|
|
39
|
-
|
|
40
|
-
const tabBar = h("div.lt3-row-2");
|
|
41
|
-
const panelHost = h("div.lt3-stack-4");
|
|
42
|
-
|
|
43
|
-
function renderTabs() {
|
|
44
|
-
tabBar.replaceChildren(...TABS.map((t) =>
|
|
45
|
-
h("button.lt3-btn" + (t.key === active ? ".lt3-btn--primary" : ".lt3-btn--ghost"),
|
|
46
|
-
{ on: { click: () => switchTab(t.key) } }, icon(t.icon), t.label)));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function switchTab(key) {
|
|
50
|
-
if (active === key) return;
|
|
51
|
-
active = key;
|
|
52
|
-
renderTabs();
|
|
53
|
-
renderActive();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let exploreNode = null;
|
|
57
|
-
function renderActive() {
|
|
58
|
-
if (active === "explore") {
|
|
59
|
-
if (!exploreNode) exploreNode = buildExplore(ctx);
|
|
60
|
-
panelHost.replaceChildren(exploreNode);
|
|
61
|
-
} else if (active === "status") {
|
|
62
|
-
renderStatus(ctx, panelHost);
|
|
63
|
-
} else if (active === "sources") {
|
|
64
|
-
renderSources(ctx, panelHost);
|
|
65
|
-
} else if (active === "capture") {
|
|
66
|
-
panelHost.replaceChildren(buildCapture(ctx));
|
|
67
|
-
} else if (active === "portability") {
|
|
68
|
-
renderPortability(ctx, panelHost);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const root = h("div.lt3-stack-6",
|
|
73
|
-
c.viewHeader({
|
|
74
|
-
eyebrow: "Your digital brain",
|
|
75
|
-
title: "Knowledge Graph",
|
|
76
|
-
sub: "Everything you ingest converges here — files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
|
|
77
|
-
actions: [
|
|
78
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
|
|
79
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
|
|
80
|
-
],
|
|
81
|
-
}),
|
|
82
|
-
tabBar,
|
|
83
|
-
panelHost,
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
renderTabs();
|
|
87
|
-
renderActive();
|
|
88
|
-
return root;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/* ── Explore tab (entity/relation mesh) ─────────────────────────────────── */
|
|
92
|
-
function buildExplore(ctx) {
|
|
93
|
-
const { h, icon, api, c } = ctx;
|
|
94
|
-
const state = { selected: null, query: "", data: { nodes: [], edges: [] }, source: "pending" };
|
|
95
|
-
|
|
96
|
-
const canvasHost = h("div", c.loading({ lines: 0, block: true }));
|
|
97
|
-
const inspectorHost = h("div", c.loading({ lines: 4 }));
|
|
98
|
-
const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
|
|
99
|
-
const srcSlot = h("span", c.sourceBadge("pending"));
|
|
100
|
-
|
|
101
|
-
const root = h("div.lt3-stack-3",
|
|
102
|
-
h("div.lt3-row-2",
|
|
103
|
-
srcSlot,
|
|
104
|
-
h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
|
|
105
|
-
),
|
|
106
|
-
statHost,
|
|
107
|
-
h("div.lt3-split",
|
|
108
|
-
h("div.lt3-stack-3",
|
|
109
|
-
c.card(canvasHost, { attrs: { style: "padding:0;overflow:hidden" } }),
|
|
110
|
-
buildLegend(ctx),
|
|
111
|
-
),
|
|
112
|
-
h("aside.lt3-panel",
|
|
113
|
-
h("div.lt3-panel__head", h("div", h("div.lt3-eyebrow", "Inspector"), h("h3.lt3-panel__title", "Entities"))),
|
|
114
|
-
h("div.lt3-search", { style: { "margin-bottom": "var(--lt3-space-4)" } },
|
|
115
|
-
icon("search"),
|
|
116
|
-
h("input", { type: "text", placeholder: "Filter entities…", "aria-label": "Filter entities",
|
|
117
|
-
on: { input: (e) => { state.query = e.target.value.toLowerCase(); renderInspector(); } } }),
|
|
118
|
-
),
|
|
119
|
-
inspectorHost,
|
|
120
|
-
),
|
|
121
|
-
),
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
async function load() {
|
|
125
|
-
canvasHost.replaceChildren(c.loading({ lines: 0, block: true }));
|
|
126
|
-
const [g, stats] = await Promise.all([api.graph(), api.graphStats()]);
|
|
127
|
-
state.data = normalize(g.data);
|
|
128
|
-
state.source = g.source;
|
|
129
|
-
srcSlot.replaceChildren(c.sourceBadge(g.source));
|
|
130
|
-
renderStats(stats.data, g.data);
|
|
131
|
-
renderCanvas();
|
|
132
|
-
renderInspector();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function renderStats(stats) {
|
|
136
|
-
const nodes = state.data.nodes.length;
|
|
137
|
-
const edges = state.data.edges.length;
|
|
138
|
-
const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
|
|
139
|
-
const density = nodes > 1 ? (edges / (nodes * (nodes - 1) / 2)) : 0;
|
|
140
|
-
statHost.replaceChildren(
|
|
141
|
-
c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
|
|
142
|
-
c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
|
|
143
|
-
c.stat({ label: "Entity types", value: types, icon: "category" }),
|
|
144
|
-
c.stat({ label: "Density", value: density.toFixed(2), icon: "chart-dots" }),
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Live force-directed canvas (zoom / pan / drag / physics) — replaces the
|
|
149
|
-
// static SVG spiral. The renderer only draws the data it is given.
|
|
150
|
-
let graphCanvas = null;
|
|
151
|
-
|
|
152
|
-
function ensureGraphCanvas() {
|
|
153
|
-
if (graphCanvas) return graphCanvas;
|
|
154
|
-
graphCanvas = createGraphCanvas({
|
|
155
|
-
colorFor,
|
|
156
|
-
onSelect: (id) => {
|
|
157
|
-
state.selected = id;
|
|
158
|
-
renderInspector();
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
return graphCanvas;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function renderCanvas() {
|
|
165
|
-
const { nodes, edges } = state.data;
|
|
166
|
-
if (!nodes.length) {
|
|
167
|
-
if (graphCanvas) { graphCanvas.destroy(); graphCanvas = null; }
|
|
168
|
-
canvasHost.replaceChildren(c.emptyState({ icon: "chart-dots-3", title: "No entities yet", body: "Index a source to populate the graph." }));
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const gc = ensureGraphCanvas();
|
|
172
|
-
gc.setData({ nodes, edges });
|
|
173
|
-
gc.setSelected(state.selected);
|
|
174
|
-
if (!gc.el.isConnected || gc.el.parentElement !== canvasHost.querySelector(".lt3-graph-canvas")) {
|
|
175
|
-
canvasHost.replaceChildren(h("div.lt3-graph-canvas", gc.el));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function syncSelection() {
|
|
180
|
-
if (graphCanvas) graphCanvas.setSelected(state.selected);
|
|
181
|
-
renderInspector();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function renderInspector() {
|
|
185
|
-
if (state.selected) { inspectorHost.replaceChildren(detailView()); return; }
|
|
186
|
-
const q = state.query;
|
|
187
|
-
const list = state.data.nodes
|
|
188
|
-
.filter((n) => !q || (n.label || "").toLowerCase().includes(q) || (n.type || "").toLowerCase().includes(q))
|
|
189
|
-
.sort((a, b) => (b.weight || 0) - (a.weight || 0));
|
|
190
|
-
inspectorHost.replaceChildren(
|
|
191
|
-
list.length
|
|
192
|
-
? h("div.lt3-stack-2", list.slice(0, 60).map((n) => entityRow(n)))
|
|
193
|
-
: c.emptyState({ icon: "search-off", title: "No matches", body: "Try a different entity name." }),
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function entityRow(n) {
|
|
198
|
-
return h("button.lt3-entity", { on: { click: () => { state.selected = n.id; syncSelection(); } } },
|
|
199
|
-
h("div.lt3-entity__type", { style: { background: `color-mix(in srgb, ${colorFor(n.type)} 18%, transparent)`, color: colorFor(n.type) } }, icon(iconForType(n.type))),
|
|
200
|
-
h("div.lt3-entity__body",
|
|
201
|
-
h("div.lt3-entity__name", n.label),
|
|
202
|
-
h("div.lt3-entity__meta", `${n.type || "Entity"} · weight ${(n.weight || 0).toFixed(2)}`),
|
|
203
|
-
),
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function detailView() {
|
|
208
|
-
const n = state.data.nodes.find((x) => x.id === state.selected);
|
|
209
|
-
if (!n) { state.selected = null; return c.emptyState({ title: "Not found" }); }
|
|
210
|
-
const rels = state.data.edges
|
|
211
|
-
.filter((e) => e.from === n.id || e.to === n.id)
|
|
212
|
-
.map((e) => {
|
|
213
|
-
const otherId = e.from === n.id ? e.to : e.from;
|
|
214
|
-
const other = state.data.nodes.find((x) => x.id === otherId);
|
|
215
|
-
return { type: e.type, dir: e.from === n.id ? "→" : "←", other };
|
|
216
|
-
})
|
|
217
|
-
.filter((r) => r.other);
|
|
218
|
-
return h("div.lt3-stack-4",
|
|
219
|
-
h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null; syncSelection(); } } }, icon("arrow-left"), "All entities"),
|
|
220
|
-
h("div.lt3-card.lt3-card--flat",
|
|
221
|
-
h("div.lt3-row-2", { style: { "margin-bottom": "var(--lt3-space-2)" } },
|
|
222
|
-
h("span.lt3-pill", { style: { color: colorFor(n.type) } }, n.type || "Entity"),
|
|
223
|
-
),
|
|
224
|
-
h("div", { style: { "font-size": "var(--lt3-text-lg)", "font-weight": 700 } }, n.label),
|
|
225
|
-
n.summary && h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", "margin-top": "var(--lt3-space-2)" } }, n.summary),
|
|
226
|
-
),
|
|
227
|
-
h("div",
|
|
228
|
-
h("div.lt3-eyebrow", { style: { "margin-bottom": "var(--lt3-space-2)" } }, `Relations (${rels.length})`),
|
|
229
|
-
rels.length
|
|
230
|
-
? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id; syncSelection(); } } },
|
|
231
|
-
h("div.lt3-entity__type", { style: { background: "var(--surface-3)" } }, h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, r.dir)),
|
|
232
|
-
h("div.lt3-entity__body",
|
|
233
|
-
h("div.lt3-entity__name", r.other.label),
|
|
234
|
-
h("div.lt3-entity__meta", r.type),
|
|
235
|
-
),
|
|
236
|
-
)))
|
|
237
|
-
: c.emptyState({ icon: "unlink", title: "No relations", body: "This entity is currently isolated." }),
|
|
238
|
-
),
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
load();
|
|
243
|
-
return root;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/* ── Status tab (graph + ingestion health) ──────────────────────────────── */
|
|
247
|
-
async function renderStatus(ctx, host) {
|
|
248
|
-
const { h, icon, api, c } = ctx;
|
|
249
|
-
host.replaceChildren(c.loading({ lines: 3 }));
|
|
250
|
-
const [port, gs, idx] = await Promise.all([api.kgPortability(), api.graphStats(), api.indexStatus()]);
|
|
251
|
-
const p = port.data || {};
|
|
252
|
-
const prov = p.provenance || {};
|
|
253
|
-
const nodes = sumCounts((gs.data && gs.data.nodes) || {});
|
|
254
|
-
const edges = sumCounts((gs.data && gs.data.edges) || {});
|
|
255
|
-
const pipelines = (idx.data && idx.data.pipelines) || {};
|
|
256
|
-
|
|
257
|
-
host.replaceChildren(
|
|
258
|
-
h("div.lt3-row-2", c.sourceBadge(port.source), h("span.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)" } },
|
|
259
|
-
p.graph_schema_version != null ? `Schema v${p.graph_schema_version} · embed dim ${p.embed_dim ?? "—"}` : "Knowledge Graph status")),
|
|
260
|
-
h("div.lt3-statrow",
|
|
261
|
-
c.stat({ label: "Entities", value: c.fmtNum(nodes), icon: "circles" }),
|
|
262
|
-
c.stat({ label: "Relations", value: c.fmtNum(edges), icon: "vector-triangle" }),
|
|
263
|
-
c.stat({ label: "Ingested items", value: c.fmtNum(prov.total || 0), icon: "package-import" }),
|
|
264
|
-
c.stat({ label: "Embedded (RAG-ready)", value: c.fmtNum(prov.embedded || 0), icon: "vector" }),
|
|
265
|
-
),
|
|
266
|
-
c.card(
|
|
267
|
-
h("div.lt3-stack-3",
|
|
268
|
-
h("div.lt3-eyebrow", "Pipelines"),
|
|
269
|
-
pipelineRow(ctx, "Knowledge graph", pipelines.knowledge_graph),
|
|
270
|
-
pipelineRow(ctx, "Vector index", pipelines.vector_index),
|
|
271
|
-
pipelineRow(ctx, "Hybrid retrieval", pipelines.hybrid),
|
|
272
|
-
),
|
|
273
|
-
),
|
|
274
|
-
prov.last_ingested_at
|
|
275
|
-
? 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.`)
|
|
276
|
-
: c.emptyState({ icon: "package-import", title: "Nothing ingested yet", body: "Add files or capture a page to populate the graph." }),
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function pipelineRow(ctx, label, pipe) {
|
|
281
|
-
const { h, c } = ctx;
|
|
282
|
-
const stateStr = (pipe && pipe.state) || "unavailable";
|
|
283
|
-
const detail = pipe && (pipe.entities != null ? `${pipe.entities} entities` : pipe.vectors != null ? `${pipe.vectors} vectors` : pipe.strategy || "");
|
|
284
|
-
return h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
|
|
285
|
-
h("div", label, detail ? h("span.lt3-muted", { style: { "margin-left": "var(--lt3-space-2)", "font-size": "var(--lt3-text-sm)" } }, detail) : null),
|
|
286
|
-
c.statePill(stateStr),
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/* ── Sources tab (provenance: where every node came from) ────────────────── */
|
|
291
|
-
async function renderSources(ctx, host) {
|
|
292
|
-
const { h, icon, api, c } = ctx;
|
|
293
|
-
host.replaceChildren(c.loading({ lines: 3 }));
|
|
294
|
-
const [port, recent] = await Promise.all([api.kgPortability(), api.kgProvenance(40)]);
|
|
295
|
-
const bySource = (port.data && port.data.provenance && port.data.provenance.by_source_type) || {};
|
|
296
|
-
const items = (recent.data && recent.data.items) || [];
|
|
297
|
-
|
|
298
|
-
const sourceCards = Object.keys(bySource).length
|
|
299
|
-
? h("div.lt3-statrow", Object.entries(bySource).map(([k, v]) =>
|
|
300
|
-
c.stat({ label: prettySource(k), value: c.fmtNum(v), icon: iconForSource(k) })))
|
|
301
|
-
: c.emptyState({ icon: "database", title: "No sources yet", body: "Connect a folder, upload a file, or capture a page." });
|
|
302
|
-
|
|
303
|
-
const recentList = items.length
|
|
304
|
-
? h("div.lt3-stack-2", items.map((it) =>
|
|
305
|
-
h("div.lt3-entity",
|
|
306
|
-
h("div.lt3-entity__type", { style: { background: "var(--surface-3)", color: colorFor("Source") } }, icon(iconForSource(it.source_type))),
|
|
307
|
-
h("div.lt3-entity__body",
|
|
308
|
-
h("div.lt3-entity__name", it.title || it.source_uri || it.node_id),
|
|
309
|
-
h("div.lt3-entity__meta", `${prettySource(it.source_type)} · ${fmtWhen(it.created_at)}${it.embedded ? " · embedded" : ""}${it.duplicate ? " · duplicate" : ""}`),
|
|
310
|
-
),
|
|
311
|
-
)))
|
|
312
|
-
: c.emptyState({ icon: "history", title: "No recent ingestions", body: "Ingested items will appear here with full provenance." });
|
|
313
|
-
|
|
314
|
-
host.replaceChildren(
|
|
315
|
-
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).")),
|
|
316
|
-
sourceCards,
|
|
317
|
-
c.card(h("div.lt3-stack-3", h("div.lt3-eyebrow", "Recent ingestions"), recentList)),
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/* ── Capture tab (web/URL into the graph) ───────────────────────────────── */
|
|
322
|
-
function buildCapture(ctx) {
|
|
323
|
-
const { h, icon, api, c } = ctx;
|
|
324
|
-
const input = h("input", { type: "url", placeholder: "https://example.com/article", "aria-label": "URL to capture",
|
|
325
|
-
style: { flex: "1" } });
|
|
326
|
-
const result = h("div");
|
|
327
|
-
|
|
328
|
-
async function run() {
|
|
329
|
-
const url = (input.value || "").trim();
|
|
330
|
-
if (!url) { result.replaceChildren(c.banner({ tone: "warn", text: "Enter a URL first." })); return; }
|
|
331
|
-
result.replaceChildren(c.loading({ lines: 1 }));
|
|
332
|
-
const res = await api.browserReadUrl(url);
|
|
333
|
-
const d = res.data || {};
|
|
334
|
-
if (res.ok && d.status === "ok") {
|
|
335
|
-
result.replaceChildren(c.banner({ tone: "ok", text: `Added to your Knowledge Graph${d.duplicate ? " (already present — linked)" : ""}. ${d.chunk_count || 0} chunk(s) indexed.` }));
|
|
336
|
-
ctx.toast && ctx.toast("Page added to Knowledge Graph");
|
|
337
|
-
} else if (d.status === "empty") {
|
|
338
|
-
result.replaceChildren(c.banner({ tone: "warn", text: "No readable text was found on that page." }));
|
|
339
|
-
} else {
|
|
340
|
-
const detail = d.detail || (res.status === 422 ? "The page is blocked or login-required." : "Could not read that URL.");
|
|
341
|
-
result.replaceChildren(c.banner({ tone: "err", text: detail }));
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return h("div.lt3-stack-4",
|
|
346
|
-
c.card(h("div.lt3-stack-3",
|
|
347
|
-
h("div.lt3-eyebrow", "Capture a web page"),
|
|
348
|
-
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."),
|
|
349
|
-
h("div.lt3-row-2",
|
|
350
|
-
input,
|
|
351
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: run } }, icon("world-download"), "Read into graph"),
|
|
352
|
-
),
|
|
353
|
-
result,
|
|
354
|
-
)),
|
|
355
|
-
c.card(h("div.lt3-stack-2",
|
|
356
|
-
h("div.lt3-eyebrow", "Browser extension"),
|
|
357
|
-
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."),
|
|
358
|
-
)),
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/* ── Portability tab (export / import / backup) ─────────────────────────── */
|
|
363
|
-
async function renderPortability(ctx, host) {
|
|
364
|
-
const { h, icon, api, c } = ctx;
|
|
365
|
-
host.replaceChildren(c.loading({ lines: 2 }));
|
|
366
|
-
const port = await api.kgPortability();
|
|
367
|
-
const status = h("div");
|
|
368
|
-
|
|
369
|
-
function note(tone, text) { status.replaceChildren(c.banner({ tone, text })); }
|
|
370
|
-
|
|
371
|
-
async function doExport() {
|
|
372
|
-
note("info", "Exporting…");
|
|
373
|
-
const res = await api.graphExport();
|
|
374
|
-
if (!res.ok || !res.data || res.data.raw) { note("err", "Export is unavailable."); return; }
|
|
375
|
-
try {
|
|
376
|
-
const blob = new Blob([JSON.stringify(res.data, null, 2)], { type: "application/json" });
|
|
377
|
-
const url = URL.createObjectURL(blob);
|
|
378
|
-
const a = document.createElement("a");
|
|
379
|
-
a.href = url; a.download = "lattice-kg-export.json"; a.click();
|
|
380
|
-
URL.revokeObjectURL(url);
|
|
381
|
-
note("ok", `Exported ${(res.data.counts && res.data.counts.nodes) || 0} nodes. Download started.`);
|
|
382
|
-
} catch (e) { note("err", "Could not build the download."); }
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
async function doBackup() {
|
|
386
|
-
note("info", "Backing up…");
|
|
387
|
-
const res = await api.graphBackup();
|
|
388
|
-
if (res.ok && res.data && res.data.path) {
|
|
389
|
-
note("ok", `Backup written locally: ${res.data.path}`);
|
|
390
|
-
} else {
|
|
391
|
-
note("err", (res.data && (res.data.detail || res.data.error)) || "Backup requires admin and a running runtime.");
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const importArea = h("textarea", { rows: 5, placeholder: "Paste a Knowledge Graph export (JSON) to validate, then import…",
|
|
396
|
-
"aria-label": "Import artifact", style: { width: "100%", "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-sm)" } });
|
|
397
|
-
|
|
398
|
-
async function doImport(dryRun) {
|
|
399
|
-
let artifact;
|
|
400
|
-
try { artifact = JSON.parse(importArea.value || ""); }
|
|
401
|
-
catch { note("err", "That is not valid JSON."); return; }
|
|
402
|
-
note("info", dryRun ? "Validating…" : "Importing…");
|
|
403
|
-
const res = await api.graphImport(artifact, "merge", dryRun);
|
|
404
|
-
if (res.ok && res.data && !res.data.detail) {
|
|
405
|
-
const d = res.data;
|
|
406
|
-
note("ok", dryRun
|
|
407
|
-
? `Valid — would import ${d.nodes || 0} nodes, ${d.edges || 0} edges.`
|
|
408
|
-
: `Imported ${d.nodes || 0} nodes, ${d.edges || 0} edges.`);
|
|
409
|
-
} else {
|
|
410
|
-
note("err", (res.data && (res.data.detail || res.data.error)) || "Import requires admin.");
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const p = port.data || {};
|
|
415
|
-
host.replaceChildren(
|
|
416
|
-
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.")),
|
|
417
|
-
c.card(h("div.lt3-stack-3",
|
|
418
|
-
h("div.lt3-eyebrow", "Export & backup"),
|
|
419
|
-
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)."),
|
|
420
|
-
h("div.lt3-row-2",
|
|
421
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: doExport } }, icon("download"), "Export JSON"),
|
|
422
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: doBackup } }, icon("archive"), "Backup (admin)"),
|
|
423
|
-
),
|
|
424
|
-
)),
|
|
425
|
-
c.card(h("div.lt3-stack-3",
|
|
426
|
-
h("div.lt3-eyebrow", "Import"),
|
|
427
|
-
importArea,
|
|
428
|
-
h("div.lt3-row-2",
|
|
429
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => doImport(true) } }, icon("checks"), "Validate (dry-run)"),
|
|
430
|
-
h("button.lt3-btn.lt3-btn--primary", { on: { click: () => doImport(false) } }, icon("file-import"), "Import (merge, admin)"),
|
|
431
|
-
),
|
|
432
|
-
)),
|
|
433
|
-
status,
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/* ── helpers ─────────────────────────────────────────────────────────────── */
|
|
438
|
-
function sumCounts(obj) {
|
|
439
|
-
return Object.values(obj || {}).reduce((a, b) => a + (Number(b) || 0), 0);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function prettySource(k) {
|
|
443
|
-
return ({ web_url: "Web URL", browser_tab: "Browser tab", file: "Files", local_file: "Local files",
|
|
444
|
-
note: "Notes", text: "Text", markdown: "Markdown", code: "Code", upload: "Uploads" })[k] || k;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function iconForSource(k) {
|
|
448
|
-
return ({ web_url: "world", browser_tab: "browser", file: "file", local_file: "folder",
|
|
449
|
-
note: "note", text: "text-caption", markdown: "markdown", code: "code", upload: "upload" })[k] || "database";
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function fmtWhen(iso) {
|
|
453
|
-
if (!iso) return "—";
|
|
454
|
-
try {
|
|
455
|
-
const d = new Date(iso);
|
|
456
|
-
if (isNaN(d.getTime())) return String(iso);
|
|
457
|
-
return d.toLocaleString();
|
|
458
|
-
} catch { return String(iso); }
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
function normalize(data) {
|
|
462
|
-
const nodes = (data.nodes || []).map((n) => ({
|
|
463
|
-
id: n.id,
|
|
464
|
-
label: n.label || n.title || n.id,
|
|
465
|
-
type: n.type || "Entity",
|
|
466
|
-
weight: n.weight ?? n.importance_norm ?? (n.metadata && n.metadata.graph_metrics && n.metadata.graph_metrics.importance_norm) ?? 0.5,
|
|
467
|
-
summary: n.summary || "",
|
|
468
|
-
x: n.x, y: n.y,
|
|
469
|
-
}));
|
|
470
|
-
const ids = new Set(nodes.map((n) => n.id));
|
|
471
|
-
const edges = (data.edges || []).filter((e) => ids.has(e.from) && ids.has(e.to))
|
|
472
|
-
.map((e) => ({ from: e.from, to: e.to, type: e.type || "related", weight: e.weight || 1 }));
|
|
473
|
-
return { nodes, edges };
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function layout(nodes) {
|
|
477
|
-
const W = 1000, H = 600, cx = W / 2, cy = H / 2;
|
|
478
|
-
const golden = Math.PI * (3 - Math.sqrt(5));
|
|
479
|
-
const hasCoords = nodes.length && nodes.every((n) => typeof n.x === "number" && typeof n.y === "number");
|
|
480
|
-
if (hasCoords) {
|
|
481
|
-
return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
|
|
482
|
-
}
|
|
483
|
-
const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
|
|
484
|
-
const maxR = Math.min(W, H) * 0.42;
|
|
485
|
-
const placed = {};
|
|
486
|
-
order.forEach((o, rank) => {
|
|
487
|
-
const radius = rank === 0 ? 0 : maxR * Math.sqrt(rank / Math.max(1, nodes.length - 1));
|
|
488
|
-
const angle = rank * golden;
|
|
489
|
-
placed[o.i] = {
|
|
490
|
-
px: Math.round(cx + Math.cos(angle) * radius),
|
|
491
|
-
py: Math.round(cy + Math.sin(angle) * radius * 0.66),
|
|
492
|
-
};
|
|
493
|
-
});
|
|
494
|
-
return nodes.map((n, i) => ({ ...n, ...placed[i] }));
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
|
|
498
|
-
|
|
499
|
-
function iconForType(t) {
|
|
500
|
-
return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file", Source: "world",
|
|
501
|
-
Document: "file-text", Decision: "gavel", Task: "checkbox", Person: "user" })[t] || "point";
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function buildLegend({ h }) {
|
|
505
|
-
const types = ["Source", "Document", "Concept", "Person", "Decision"];
|
|
506
|
-
return h("div.lt3-graph-legend",
|
|
507
|
-
types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
|
|
508
|
-
);
|
|
509
|
-
}
|