ltcai 3.5.0 → 4.0.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 +73 -35
- package/docs/CARRYOVER_AUDIT_v3.6.0.md +61 -0
- package/docs/CHANGELOG.md +32 -0
- package/docs/HANDOVER_v3.6.0.md +46 -0
- package/docs/RUNTIME_HOOK_COVERAGE_v3.6.0.md +49 -0
- package/docs/V4_BRAIN_ARCHITECTURE.md +322 -0
- package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +509 -0
- package/docs/V4_IMPLEMENTATION_PLAN.md +470 -0
- package/docs/architecture.md +13 -12
- package/docs/kg-schema.md +102 -53
- package/docs/privacy.md +18 -2
- package/docs/security-model.md +17 -0
- package/kg_schema.py +139 -10
- package/knowledge_graph.py +874 -26
- package/knowledge_graph_api.py +11 -127
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/admin.py +1 -1
- package/latticeai/api/agents.py +7 -1
- package/latticeai/api/auth.py +27 -4
- package/latticeai/api/browser.py +217 -0
- package/latticeai/api/chat.py +112 -76
- package/latticeai/api/health.py +1 -1
- package/latticeai/api/hooks.py +1 -1
- package/latticeai/api/knowledge_graph.py +146 -0
- package/latticeai/api/local_files.py +1 -1
- package/latticeai/api/mcp.py +23 -11
- package/latticeai/api/memory.py +1 -1
- package/latticeai/api/models.py +1 -1
- package/latticeai/api/network.py +81 -0
- package/latticeai/api/portability.py +93 -0
- package/latticeai/api/realtime.py +1 -1
- package/latticeai/api/search.py +26 -2
- package/latticeai/api/security_dashboard.py +2 -3
- package/latticeai/api/setup.py +2 -2
- package/latticeai/api/static_routes.py +2 -4
- package/latticeai/api/tools.py +3 -0
- package/latticeai/api/workflow_designer.py +46 -0
- package/latticeai/api/workspace.py +71 -49
- package/latticeai/app_factory.py +1710 -0
- package/latticeai/brain/__init__.py +18 -0
- package/latticeai/brain/context.py +213 -0
- package/latticeai/brain/conversations.py +236 -0
- package/latticeai/brain/identity.py +175 -0
- package/latticeai/brain/memory.py +102 -0
- package/latticeai/brain/network.py +205 -0
- package/latticeai/core/agent.py +31 -7
- package/latticeai/core/audit.py +0 -7
- package/latticeai/core/config.py +1 -1
- package/latticeai/core/context_builder.py +1 -2
- package/latticeai/core/enterprise.py +1 -1
- package/latticeai/core/graph_curator.py +2 -2
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/mcp_registry.py +791 -0
- package/latticeai/core/model_compat.py +1 -1
- package/latticeai/core/model_resolution.py +0 -1
- package/latticeai/core/multi_agent.py +238 -4
- package/latticeai/core/security.py +1 -1
- package/latticeai/core/sessions.py +37 -7
- package/latticeai/core/workflow_engine.py +114 -2
- package/latticeai/core/workspace_os.py +58 -10
- package/latticeai/models/__init__.py +7 -0
- package/latticeai/models/router.py +779 -0
- package/latticeai/server_app.py +29 -1504
- package/latticeai/services/agent_runtime.py +1 -0
- package/latticeai/services/app_context.py +75 -14
- package/latticeai/services/ingestion.py +318 -0
- package/latticeai/services/kg_portability.py +207 -0
- package/latticeai/services/memory_service.py +39 -11
- package/latticeai/services/model_runtime.py +2 -5
- package/latticeai/services/platform_runtime.py +100 -23
- package/latticeai/services/search_service.py +17 -8
- package/latticeai/services/tool_dispatch.py +12 -2
- package/latticeai/services/triggers.py +241 -0
- package/latticeai/services/upload_service.py +37 -12
- package/latticeai/services/workspace_service.py +31 -0
- package/llm_router.py +29 -772
- package/ltcai_cli.py +1 -2
- package/mcp_registry.py +25 -788
- package/p_reinforce.py +124 -14
- package/package.json +11 -8
- package/scripts/build_vsix.mjs +72 -0
- package/scripts/bump_version.py +99 -0
- package/scripts/generate_diagrams.py +0 -1
- package/scripts/lint_v3.mjs +82 -18
- package/scripts/validate_release_artifacts.py +0 -1
- package/scripts/wheel_smoke.py +142 -0
- package/server.py +11 -7
- package/setup_wizard.py +1142 -0
- package/static/account.html +2 -4
- package/static/admin.html +3 -5
- package/static/chat.html +3 -6
- package/static/graph.html +2 -4
- package/static/sw.js +81 -52
- package/static/v3/asset-manifest.json +20 -19
- package/static/v3/css/{lattice.base.e4cdd05d.css → lattice.base.49deefb5.css} +1 -1
- package/static/v3/css/lattice.base.css +1 -1
- package/static/v3/css/{lattice.components.9b49d614.css → lattice.components.cde18231.css} +1 -1
- package/static/v3/css/lattice.components.css +1 -1
- package/static/v3/css/{lattice.shell.8fcc9d33.css → lattice.shell.29d36d85.css} +1 -1
- package/static/v3/css/lattice.shell.css +1 -1
- package/static/v3/css/{lattice.tokens.e7018963.css → lattice.tokens.304cbc40.css} +3 -0
- package/static/v3/css/lattice.tokens.css +3 -0
- package/static/v3/css/{lattice.views.22f69117.css → lattice.views.0a18b6c5.css} +2 -2
- package/static/v3/css/lattice.views.css +2 -2
- package/static/v3/index.html +3 -4
- package/static/v3/js/{app.d086489d.js → app.356e6452.js} +1 -1
- package/static/v3/js/core/{api.12b568ad.js → api.7a308b89.js} +39 -1
- package/static/v3/js/core/api.js +38 -0
- package/static/v3/js/core/{routes.d214b399.js → routes.7222343d.js} +22 -22
- package/static/v3/js/core/routes.js +22 -22
- package/static/v3/js/core/{shell.d05266f5.js → shell.a1657f20.js} +4 -4
- package/static/v3/js/core/shell.js +1 -1
- package/static/v3/js/core/{store.34ebd5e6.js → store.204a08b2.js} +1 -1
- package/static/v3/js/core/store.js +1 -1
- package/static/v3/js/views/graph-canvas.17c15d65.js +509 -0
- package/static/v3/js/views/graph-canvas.js +509 -0
- package/static/v3/js/views/{hybrid-search.b22b97e0.js → hybrid-search.2fb63ed9.js} +1 -2
- package/static/v3/js/views/hybrid-search.js +1 -2
- package/static/v3/js/views/knowledge-graph.5e40cbeb.js +509 -0
- package/static/v3/js/views/knowledge-graph.js +326 -54
- package/static/vendor/chart.umd.min.js +20 -0
- package/static/vendor/fonts/inter-latin-300-normal.woff2 +0 -0
- package/static/vendor/fonts/inter-latin-400-normal.woff2 +0 -0
- package/static/vendor/fonts/inter-latin-500-normal.woff2 +0 -0
- package/static/vendor/fonts/inter-latin-600-normal.woff2 +0 -0
- package/static/vendor/fonts/inter-latin-700-normal.woff2 +0 -0
- package/static/vendor/fonts/inter-latin-800-normal.woff2 +0 -0
- package/static/vendor/fonts/inter.css +44 -0
- package/static/vendor/icons/tabler-icons.min.css +4 -0
- package/static/vendor/icons/tabler-icons.woff2 +0 -0
- package/static/vendor/marked.min.js +69 -0
- package/static/workspace.html +2 -2
- package/telegram_bot.py +1 -2
- package/tools/commands.py +4 -2
- package/tools/computer.py +1 -1
- package/tools/documents.py +1 -3
- package/tools/filesystem.py +0 -4
- package/tools/knowledge.py +1 -3
- package/tools/network.py +1 -3
- package/codex_telegram_bot.py +0 -195
- package/docs/assets/v3.4.0/agent-run.png +0 -0
- package/docs/assets/v3.4.0/agents.png +0 -0
- package/docs/assets/v3.4.0/before/chat-before.png +0 -0
- package/docs/assets/v3.4.0/before/files-before.png +0 -0
- package/docs/assets/v3.4.0/chat.png +0 -0
- package/docs/assets/v3.4.0/connect-folder.png +0 -0
- package/docs/assets/v3.4.0/files.png +0 -0
- package/docs/assets/v3.4.0/home.png +0 -0
- package/docs/assets/v3.4.0/hooks-dispatch.png +0 -0
- package/docs/assets/v3.4.0/knowledge-graph.png +0 -0
- package/docs/assets/v3.4.0/local-agent.png +0 -0
- package/docs/assets/v3.4.0/memory.png +0 -0
- package/docs/assets/v3.4.0/settings.png +0 -0
- package/docs/assets/v3.4.0/vision-input.png +0 -0
- package/docs/assets/v3.4.0/workflows.png +0 -0
- package/docs/assets/v3.4.1/e2e_runtime_log.txt +0 -42
- package/docs/assets/v3.4.1/hooks-dispatch.png +0 -0
- package/docs/assets/v3.4.1/local-agent.png +0 -0
- package/docs/images/admin-dashboard.png +0 -0
- package/docs/images/architecture.png +0 -0
- package/docs/images/enterprise.png +0 -0
- package/docs/images/graph.png +0 -0
- package/docs/images/hero.gif +0 -0
- package/docs/images/knowledge-graph.png +0 -0
- package/docs/images/lattice-ai-demo.gif +0 -0
- package/docs/images/lattice-ai-hero.png +0 -0
- package/docs/images/logo.svg +0 -33
- package/docs/images/mobile-responsive.png +0 -0
- package/docs/images/model-recommendation.png +0 -0
- package/docs/images/onboarding.png +0 -0
- package/docs/images/organization.png +0 -0
- package/docs/images/pipeline.png +0 -0
- package/docs/images/screenshot-admin.png +0 -0
- package/docs/images/screenshot-chat.png +0 -0
- package/docs/images/screenshot-graph.png +0 -0
- package/docs/images/skills.png +0 -0
- package/docs/images/workspace-dark.png +0 -0
- package/docs/images/workspace-light.png +0 -0
- package/docs/images/workspace.png +0 -0
- package/requirements.txt +0 -16
- package/static/v3/js/views/knowledge-graph.a14ea7e7.js +0 -237
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/* ============================================================================
|
|
2
|
-
* View: Knowledge Graph —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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.
|
|
5
8
|
* ========================================================================== */
|
|
6
9
|
|
|
7
10
|
import { escapeHtml } from "../core/dom.js";
|
|
11
|
+
import { createGraphCanvas } from "./graph-canvas.js";
|
|
8
12
|
|
|
9
13
|
const TYPE_COLOR = {
|
|
10
14
|
Topic: "var(--lt3-pillar-graph)",
|
|
@@ -12,6 +16,8 @@ const TYPE_COLOR = {
|
|
|
12
16
|
Method: "var(--lt3-pillar-hybrid)",
|
|
13
17
|
Model: "var(--accent-3)",
|
|
14
18
|
File: "var(--faint)",
|
|
19
|
+
Source: "var(--lt3-pillar-hybrid)",
|
|
20
|
+
Document: "var(--accent)",
|
|
15
21
|
Decision: "var(--accent-3)",
|
|
16
22
|
Task: "var(--accent-2)",
|
|
17
23
|
Person: "var(--accent-pink)",
|
|
@@ -19,27 +25,84 @@ const TYPE_COLOR = {
|
|
|
19
25
|
};
|
|
20
26
|
const colorFor = (t) => TYPE_COLOR[t] || TYPE_COLOR.default;
|
|
21
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
|
+
|
|
22
36
|
export async function render(ctx) {
|
|
23
|
-
const { h, icon, api,
|
|
37
|
+
const { h, icon, api, c } = ctx;
|
|
38
|
+
let active = "explore";
|
|
24
39
|
|
|
25
|
-
const
|
|
40
|
+
const tabBar = h("div.lt3-row-2");
|
|
41
|
+
const panelHost = h("div.lt3-stack-4");
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
71
|
|
|
32
72
|
const root = h("div.lt3-stack-6",
|
|
33
73
|
c.viewHeader({
|
|
34
|
-
eyebrow: "
|
|
74
|
+
eyebrow: "Your digital brain",
|
|
35
75
|
title: "Knowledge Graph",
|
|
36
|
-
sub: "
|
|
76
|
+
sub: "Everything you ingest converges here — files, folders, web pages, browser tabs. Models read this graph; local-first keeps it yours.",
|
|
37
77
|
actions: [
|
|
38
|
-
|
|
39
|
-
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => load() } }, icon("refresh"), "Rebuild view"),
|
|
78
|
+
h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => ctx.navigate("files") } }, icon("upload"), "Add sources"),
|
|
40
79
|
h("button.lt3-btn.lt3-btn--primary", { on: { click: () => ctx.navigate("hybrid-search") } }, icon("arrows-join"), "Search graph"),
|
|
41
80
|
],
|
|
42
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
|
+
),
|
|
43
106
|
statHost,
|
|
44
107
|
h("div.lt3-split",
|
|
45
108
|
h("div.lt3-stack-3",
|
|
@@ -69,7 +132,7 @@ export async function render(ctx) {
|
|
|
69
132
|
renderInspector();
|
|
70
133
|
}
|
|
71
134
|
|
|
72
|
-
function renderStats(stats
|
|
135
|
+
function renderStats(stats) {
|
|
73
136
|
const nodes = state.data.nodes.length;
|
|
74
137
|
const edges = state.data.edges.length;
|
|
75
138
|
const types = stats && stats.nodes ? Object.keys(stats.nodes).length : new Set(state.data.nodes.map((n) => n.type)).size;
|
|
@@ -82,47 +145,42 @@ export async function render(ctx) {
|
|
|
82
145
|
);
|
|
83
146
|
}
|
|
84
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
|
+
|
|
85
164
|
function renderCanvas() {
|
|
86
165
|
const { nodes, edges } = state.data;
|
|
87
|
-
if (!nodes.length) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const sel = state.selected === n.id;
|
|
99
|
-
return `<g class="lt3-gnode" data-id="${escapeHtml(n.id)}" opacity="${state.selected && !sel && !isNeighbor(n.id) ? 0.35 : 1}">
|
|
100
|
-
<circle cx="${n.px}" cy="${n.py}" r="${sel ? r + 3 : r}" fill="${colorFor(n.type)}" stroke-width="${sel ? 3 : 2}"></circle>
|
|
101
|
-
<text x="${n.px}" y="${n.py + r + 13}" text-anchor="middle">${escapeHtml(truncate(n.label, 18))}</text>
|
|
102
|
-
</g>`;
|
|
103
|
-
}).join("");
|
|
104
|
-
canvasHost.replaceChildren(
|
|
105
|
-
h("div.lt3-graph-canvas", {
|
|
106
|
-
html: `<svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="xMidYMid meet" role="img" aria-label="Knowledge graph">${edgeSvg}${nodeSvg}</svg>`,
|
|
107
|
-
on: { click: onCanvasClick },
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
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
|
+
}
|
|
110
177
|
}
|
|
111
178
|
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
if (!g) return;
|
|
115
|
-
state.selected = g.dataset.id === state.selected ? null : g.dataset.id;
|
|
116
|
-
renderCanvas();
|
|
179
|
+
function syncSelection() {
|
|
180
|
+
if (graphCanvas) graphCanvas.setSelected(state.selected);
|
|
117
181
|
renderInspector();
|
|
118
182
|
}
|
|
119
183
|
|
|
120
|
-
function isNeighbor(id) {
|
|
121
|
-
if (!state.selected) return false;
|
|
122
|
-
return state.data.edges.some((e) =>
|
|
123
|
-
(e.from === state.selected && e.to === id) || (e.to === state.selected && e.from === id));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
184
|
function renderInspector() {
|
|
127
185
|
if (state.selected) { inspectorHost.replaceChildren(detailView()); return; }
|
|
128
186
|
const q = state.query;
|
|
@@ -137,7 +195,7 @@ export async function render(ctx) {
|
|
|
137
195
|
}
|
|
138
196
|
|
|
139
197
|
function entityRow(n) {
|
|
140
|
-
return h("button.lt3-entity", { on: { click: () => { state.selected = n.id;
|
|
198
|
+
return h("button.lt3-entity", { on: { click: () => { state.selected = n.id; syncSelection(); } } },
|
|
141
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))),
|
|
142
200
|
h("div.lt3-entity__body",
|
|
143
201
|
h("div.lt3-entity__name", n.label),
|
|
@@ -158,7 +216,7 @@ export async function render(ctx) {
|
|
|
158
216
|
})
|
|
159
217
|
.filter((r) => r.other);
|
|
160
218
|
return h("div.lt3-stack-4",
|
|
161
|
-
h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null;
|
|
219
|
+
h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => { state.selected = null; syncSelection(); } } }, icon("arrow-left"), "All entities"),
|
|
162
220
|
h("div.lt3-card.lt3-card--flat",
|
|
163
221
|
h("div.lt3-row-2", { style: { "margin-bottom": "var(--lt3-space-2)" } },
|
|
164
222
|
h("span.lt3-pill", { style: { color: colorFor(n.type) } }, n.type || "Entity"),
|
|
@@ -169,7 +227,7 @@ export async function render(ctx) {
|
|
|
169
227
|
h("div",
|
|
170
228
|
h("div.lt3-eyebrow", { style: { "margin-bottom": "var(--lt3-space-2)" } }, `Relations (${rels.length})`),
|
|
171
229
|
rels.length
|
|
172
|
-
? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id;
|
|
230
|
+
? h("div.lt3-stack-2", rels.map((r) => h("button.lt3-entity", { on: { click: () => { state.selected = r.other.id; syncSelection(); } } },
|
|
173
231
|
h("div.lt3-entity__type", { style: { background: "var(--surface-3)" } }, h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, r.dir)),
|
|
174
232
|
h("div.lt3-entity__body",
|
|
175
233
|
h("div.lt3-entity__name", r.other.label),
|
|
@@ -185,7 +243,221 @@ export async function render(ctx) {
|
|
|
185
243
|
return root;
|
|
186
244
|
}
|
|
187
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
|
+
|
|
188
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
|
+
|
|
189
461
|
function normalize(data) {
|
|
190
462
|
const nodes = (data.nodes || []).map((n) => ({
|
|
191
463
|
id: n.id,
|
|
@@ -208,7 +480,6 @@ function layout(nodes) {
|
|
|
208
480
|
if (hasCoords) {
|
|
209
481
|
return nodes.map((n) => ({ ...n, px: Math.round(60 + n.x * (W - 120)), py: Math.round(50 + n.y * (H - 100)) }));
|
|
210
482
|
}
|
|
211
|
-
// Sunflower (Vogel) spread — even spacing, highest-weight entity centered.
|
|
212
483
|
const order = nodes.map((n, i) => ({ n, i })).sort((a, b) => (b.n.weight || 0) - (a.n.weight || 0));
|
|
213
484
|
const maxR = Math.min(W, H) * 0.42;
|
|
214
485
|
const placed = {};
|
|
@@ -226,11 +497,12 @@ function layout(nodes) {
|
|
|
226
497
|
function truncate(s, n) { s = String(s || ""); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
|
|
227
498
|
|
|
228
499
|
function iconForType(t) {
|
|
229
|
-
return ({ Topic: "bulb", Concept: "atom", Method: "function", Model: "cpu", File: "file",
|
|
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";
|
|
230
502
|
}
|
|
231
503
|
|
|
232
504
|
function buildLegend({ h }) {
|
|
233
|
-
const types = ["
|
|
505
|
+
const types = ["Source", "Document", "Concept", "Person", "Decision"];
|
|
234
506
|
return h("div.lt3-graph-legend",
|
|
235
507
|
types.map((t) => h("span", h("i", { style: { background: colorFor(t) } }), t)),
|
|
236
508
|
);
|