ltcai 2.2.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +66 -27
  2. package/codex_telegram_bot.py +6 -2
  3. package/docs/CHANGELOG.md +154 -0
  4. package/docs/V3_BACKEND_ARCHITECTURE.md +138 -0
  5. package/docs/V3_FRONTEND.md +136 -0
  6. package/knowledge_graph.py +649 -21
  7. package/latticeai/__init__.py +1 -1
  8. package/latticeai/api/admin.py +47 -0
  9. package/latticeai/api/agents.py +54 -31
  10. package/latticeai/api/auth.py +1 -1
  11. package/latticeai/api/chat.py +10 -2
  12. package/latticeai/api/search.py +236 -0
  13. package/latticeai/api/static_routes.py +21 -2
  14. package/latticeai/core/config.py +16 -0
  15. package/latticeai/core/embedding_providers.py +502 -0
  16. package/latticeai/core/local_embeddings.py +86 -0
  17. package/latticeai/core/logging_safety.py +62 -0
  18. package/latticeai/core/workspace_os.py +1 -1
  19. package/latticeai/server_app.py +49 -1
  20. package/latticeai/services/agent_runtime.py +245 -0
  21. package/latticeai/services/search_service.py +346 -0
  22. package/package.json +8 -4
  23. package/static/account.html +9 -4
  24. package/static/activity.html +4 -4
  25. package/static/admin.html +8 -3
  26. package/static/agents.html +4 -4
  27. package/static/chat.html +16 -11
  28. package/static/css/reference/account.css +439 -0
  29. package/static/css/reference/admin.css +610 -0
  30. package/static/css/reference/base.css +1658 -0
  31. package/static/{lattice-reference.css → css/reference/chat.css} +271 -3633
  32. package/static/css/reference/graph.css +1016 -0
  33. package/static/css/responsive.css +248 -1
  34. package/static/css/tokens.css +132 -126
  35. package/static/favicon.ico +0 -0
  36. package/static/graph.html +9 -4
  37. package/static/manifest.json +3 -3
  38. package/static/platform.css +1 -1
  39. package/static/plugins.html +4 -4
  40. package/static/scripts/account.js +4 -4
  41. package/static/scripts/chat.js +227 -77
  42. package/static/scripts/workspace.js +78 -0
  43. package/static/sw.js +5 -3
  44. package/static/v3/css/lattice.base.css +128 -0
  45. package/static/v3/css/lattice.components.css +447 -0
  46. package/static/v3/css/lattice.shell.css +407 -0
  47. package/static/v3/css/lattice.tokens.css +132 -0
  48. package/static/v3/css/lattice.views.css +277 -0
  49. package/static/v3/index.html +40 -0
  50. package/static/v3/js/app.js +26 -0
  51. package/static/v3/js/core/api.js +327 -0
  52. package/static/v3/js/core/components.js +215 -0
  53. package/static/v3/js/core/dom.js +148 -0
  54. package/static/v3/js/core/fixtures.js +171 -0
  55. package/static/v3/js/core/router.js +37 -0
  56. package/static/v3/js/core/routes.js +73 -0
  57. package/static/v3/js/core/shell.js +363 -0
  58. package/static/v3/js/core/store.js +113 -0
  59. package/static/v3/js/views/admin-audit.js +185 -0
  60. package/static/v3/js/views/admin-permissions.js +178 -0
  61. package/static/v3/js/views/admin-policies.js +103 -0
  62. package/static/v3/js/views/admin-private-vpc.js +138 -0
  63. package/static/v3/js/views/admin-security.js +181 -0
  64. package/static/v3/js/views/admin-users.js +168 -0
  65. package/static/v3/js/views/agents.js +194 -0
  66. package/static/v3/js/views/chat.js +450 -0
  67. package/static/v3/js/views/files.js +180 -0
  68. package/static/v3/js/views/home.js +119 -0
  69. package/static/v3/js/views/hybrid-search.js +195 -0
  70. package/static/v3/js/views/knowledge-graph.js +238 -0
  71. package/static/v3/js/views/models.js +247 -0
  72. package/static/v3/js/views/my-computer.js +237 -0
  73. package/static/v3/js/views/pipeline.js +161 -0
  74. package/static/v3/js/views/settings.js +258 -0
  75. package/static/workflows.html +4 -4
  76. package/static/workspace.css +408 -14
  77. package/static/workspace.html +43 -24
  78. package/telegram_bot.py +18 -14
@@ -0,0 +1,178 @@
1
+ /* ============================================================================
2
+ * View: Permissions — Administration · roles and capability mapping (RBAC).
3
+ * Renders the role → capability matrix and per-role summaries from the admin
4
+ * roles fixture. Capabilities map to product areas; "all" grants everything.
5
+ * Role editing is integration-ready (no backend logic here) — actions surface
6
+ * a clearly-labeled "pending backend" toast.
7
+ *
8
+ * View contract (shared by all views):
9
+ * export async function render(ctx) -> single DOM node
10
+ * ctx = { h, icon, api, store, c, route, params, navigate, toast }
11
+ * ========================================================================== */
12
+
13
+ /* Capability columns, in product-area order. Each maps to a routable surface
14
+ * and a Tabler icon so the matrix reads at a glance. */
15
+ const CAPS = [
16
+ { key: "chat", label: "Chat", icon: "message-2", route: "chat" },
17
+ { key: "search", label: "Search", icon: "arrows-join", route: "hybrid-search" },
18
+ { key: "files", label: "Files", icon: "folders", route: "files" },
19
+ { key: "pipeline", label: "Pipeline", icon: "git-branch", route: "pipeline" },
20
+ { key: "users", label: "Users", icon: "users", route: "admin/users" },
21
+ { key: "policies", label: "Policies", icon: "shield-lock", route: "admin/policies" },
22
+ { key: "audit", label: "Audit", icon: "history", route: "admin/audit" },
23
+ { key: "security", label: "Security", icon: "shield-check", route: "admin/security" },
24
+ ];
25
+
26
+ const ROLE_META = {
27
+ owner: { icon: "crown", variant: "ok" },
28
+ admin: { icon: "shield-check", variant: "info" },
29
+ member: { icon: "user-check", variant: "" },
30
+ viewer: { icon: "eye", variant: "warn" },
31
+ };
32
+ const metaFor = (role) => ROLE_META[String(role).toLowerCase()] || { icon: "user", variant: "" };
33
+
34
+ /** A role grants a capability when it holds "all" or that specific cap. */
35
+ const grants = (caps, key) => Array.isArray(caps) && (caps.includes("all") || caps.includes(key));
36
+ const capLabel = (key) => (CAPS.find((cc) => cc.key === key)?.label) || key;
37
+
38
+ export async function render(ctx) {
39
+ const { h, icon, c, navigate, toast } = ctx;
40
+
41
+ // Live RBAC roles from /admin/roles; clearly-badged sample data on fallback.
42
+ const res = await ctx.api.adminRoles();
43
+ const roles = Array.isArray(res.data && res.data.roles) ? res.data.roles
44
+ : (Array.isArray(res.data) ? res.data : []);
45
+ const source = res.source;
46
+ const totalMembers = roles.reduce((sum, r) => sum + (r.members || 0), 0);
47
+
48
+ const root = h("div.lt3-stack-6",
49
+ c.viewHeader({
50
+ eyebrow: "Administration",
51
+ title: "Permissions",
52
+ sub: "Roles and capability mapping.",
53
+ actions: [
54
+ c.sourceBadge(source),
55
+ h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => navigate("admin/users") } }, icon("users"), "Members"),
56
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: () => pendingToast(toast, "Creating a role") } }, icon("plus"), "New role"),
57
+ ],
58
+ }),
59
+
60
+ c.banner(
61
+ "Access is role-based (RBAC): every member holds exactly one role, and each role grants a set of capabilities that map to product areas. The owner role grants all capabilities.",
62
+ "info",
63
+ "shield-lock",
64
+ ),
65
+
66
+ h("div.lt3-statrow",
67
+ c.stat({ label: "Roles", value: roles.length, icon: "id-badge-2" }),
68
+ c.stat({ label: "Members", value: c.fmtNum(totalMembers), icon: "users" }),
69
+ c.stat({ label: "Capabilities", value: CAPS.length, icon: "key" }),
70
+ c.stat({ label: "Full-access roles", value: roles.filter((r) => (r.caps || []).includes("all")).length, icon: "crown" }),
71
+ ),
72
+
73
+ c.panel({
74
+ eyebrow: "RBAC",
75
+ title: "Capability matrix",
76
+ sub: "Which product areas each role can reach. Scroll horizontally to see every capability.",
77
+ children: buildMatrix(ctx, roles),
78
+ }),
79
+
80
+ h("section",
81
+ c.sectionHead("Roles", c.sourceBadge(source)),
82
+ buildRoleGrid(ctx, roles),
83
+ ),
84
+ );
85
+
86
+ return root;
87
+ }
88
+
89
+ /* ── Capability matrix ──────────────────────────────────────────────────── */
90
+ function buildMatrix(ctx, roles) {
91
+ const { h, icon, c } = ctx;
92
+
93
+ if (!roles.length) {
94
+ return c.emptyState({ icon: "lock-off", title: "No roles defined", body: "Define a role to start mapping capabilities." });
95
+ }
96
+
97
+ const columns = [
98
+ {
99
+ key: "role",
100
+ label: "Role",
101
+ width: "180px",
102
+ render: (r) => {
103
+ const m = metaFor(r.role);
104
+ return h("div.lt3-row-2", { style: { "align-items": "center" } },
105
+ h("span.lt3-result__rank", { style: { color: "var(--accent)" } }, icon(m.icon)),
106
+ h("div.lt3-stack",
107
+ h("b", { style: { "font-size": "var(--lt3-text-sm)", "text-transform": "capitalize" } }, r.role),
108
+ c.pill(`${c.fmtNum(r.members || 0)} ${(r.members === 1) ? "member" : "members"}`, m.variant || "", { dot: true }),
109
+ ),
110
+ );
111
+ },
112
+ },
113
+ ...CAPS.map((cap) => ({
114
+ key: cap.key,
115
+ label: cap.label,
116
+ render: (r) => cell(ctx, grants(r.caps, cap.key)),
117
+ })),
118
+ ];
119
+
120
+ return c.table(columns, roles);
121
+ }
122
+
123
+ /** A matrix cell: accent check when granted, muted dash when not. */
124
+ function cell({ h, icon }, granted) {
125
+ return h("div", { style: { display: "grid", "place-items": "center" }, "aria-label": granted ? "granted" : "not granted" },
126
+ granted
127
+ ? h("span", { style: { color: "var(--accent)", "font-size": "var(--lt3-text-lg)", "line-height": "1" } }, icon("check"))
128
+ : h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-lg)", "line-height": "1" }, "aria-hidden": "true" }, "–"),
129
+ );
130
+ }
131
+
132
+ /* ── Per-role summary cards ─────────────────────────────────────────────── */
133
+ function buildRoleGrid(ctx, roles) {
134
+ const { h } = ctx;
135
+ if (!roles.length) {
136
+ return ctx.c.emptyState({ icon: "lock-off", title: "No roles defined", body: "Define a role to map capabilities." });
137
+ }
138
+ return h("div.lt3-grid-auto", roles.map((r) => roleCard(ctx, r)));
139
+ }
140
+
141
+ function roleCard(ctx, r) {
142
+ const { h, icon, c, toast } = ctx;
143
+ const m = metaFor(r.role);
144
+ const isAll = (r.caps || []).includes("all");
145
+ const grantedKeys = isAll ? CAPS.map((cc) => cc.key) : CAPS.filter((cc) => (r.caps || []).includes(cc.key)).map((cc) => cc.key);
146
+
147
+ return c.card(
148
+ h("div.lt3-stack-3",
149
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
150
+ h("div.lt3-row-2", { style: { "align-items": "center" } },
151
+ h("span.lt3-quick__icon", icon(m.icon)),
152
+ h("div.lt3-stack",
153
+ h("b", { style: { "font-size": "var(--lt3-text-md)", "text-transform": "capitalize" } }, r.role),
154
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${c.fmtNum(r.members || 0)} ${(r.members === 1) ? "member" : "members"}`),
155
+ ),
156
+ ),
157
+ c.pill(isAll ? "Full access" : `${grantedKeys.length}/${CAPS.length}`, m.variant || "info"),
158
+ ),
159
+
160
+ h("div.lt3-cluster", { "aria-label": `${r.role} capabilities` },
161
+ isAll
162
+ ? h("span.lt3-chip", { dataset: { active: "true" } }, icon("infinity"), "All capabilities")
163
+ : (grantedKeys.length
164
+ ? grantedKeys.map((k) => h("span.lt3-chip", { dataset: { active: "true" } }, icon(CAPS.find((cc) => cc.key === k).icon), capLabel(k)))
165
+ : h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, "No capabilities")),
166
+ ),
167
+
168
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { style: { "align-self": "flex-start" }, on: { click: () => pendingToast(toast, `Editing the ${r.role} role`) } },
169
+ icon("edit"), "Edit role"),
170
+ ),
171
+ { attrs: { "data-role": r.role } },
172
+ );
173
+ }
174
+
175
+ /* ── Pending-backend affordance ─────────────────────────────────────────── */
176
+ function pendingToast(toast, what) {
177
+ toast(`${what} is not available in this build — roles are a fixed RBAC model (owner · admin · member · viewer).`, "warn");
178
+ }
@@ -0,0 +1,103 @@
1
+ /* ============================================================================
2
+ * View: Policies — administration · governance and enforcement.
3
+ * Surfaces the local-first guardrails the workspace enforces and the open-core
4
+ * seam where Enterprise governance packs extend them. Policy state reflects the
5
+ * documented future contract (fx.ADMIN.policies); toggles are integration-ready
6
+ * and clearly defer their enforcement to the backend.
7
+ * ========================================================================== */
8
+
9
+ // Governance capabilities that live behind the open-core Enterprise seam. These
10
+ // are extension points, not implemented backend logic — labeled as sample data.
11
+ const PACKS = [
12
+ { id: "siem", icon: "broadcast", title: "SIEM export", desc: "Stream the audit trail to an external SIEM (Splunk, Elastic, Sentinel)." },
13
+ { id: "retention", icon: "archive", title: "Compliance retention", desc: "Configurable retention windows and legal-hold for messages and traces." },
14
+ { id: "isolation", icon: "wall", title: "Tenant isolation", desc: "Hard multi-tenant boundaries with per-tenant keys and storage." },
15
+ ];
16
+
17
+ export async function render(ctx) {
18
+ const { h, icon, c, toast } = ctx;
19
+
20
+ // Live governance posture from /admin/policies; sample data on fallback.
21
+ const res = await ctx.api.adminPolicies();
22
+ const policies = Array.isArray(res.data && res.data.policies) ? res.data.policies
23
+ : (Array.isArray(res.data) ? res.data : []);
24
+ const source = res.source;
25
+
26
+ const root = h("div.lt3-stack-6",
27
+ c.viewHeader({
28
+ eyebrow: "Administration",
29
+ title: "Policies",
30
+ sub: "Governance and enforcement.",
31
+ actions: [c.sourceBadge(source)],
32
+ }),
33
+
34
+ c.banner(
35
+ "Policies enforce Lattice's local-first guardrails. Enterprise packs extend them with org-wide governance.",
36
+ "info",
37
+ "shield-lock",
38
+ ),
39
+
40
+ h("section.lt3-stack-3",
41
+ c.sectionHead(
42
+ "Active guardrails",
43
+ c.sourceBadge(source),
44
+ ),
45
+ policies.length
46
+ ? h("div.lt3-stack-3", policies.map((p) => policyRow(ctx, p)))
47
+ : c.emptyState({ icon: "shield-off", title: "No policies defined", body: "Policies appear once the governance backend is connected." }),
48
+ ),
49
+
50
+ packsPanel(ctx),
51
+ );
52
+
53
+ return root;
54
+ }
55
+
56
+ /* ── One policy row: description and its real, runtime-enforced state ─────── */
57
+ // Policies are enforced by the runtime (approval gating, local-only egress,
58
+ // local storage). They are reported read-only — not user-toggleable — so the UI
59
+ // never implies a guardrail can be relaxed from the browser.
60
+ function policyRow({ h, icon, c }, p) {
61
+ return c.card(
62
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", "gap": "var(--lt3-space-4)", "flex-wrap": "wrap" } },
63
+ h("div.lt3-stack-2", { style: { "min-width": "0", "flex": "1 1 320px" } },
64
+ h("div.lt3-row-2",
65
+ h("span.lt3-card__icon", { style: { color: "var(--accent)" } }, icon("shield-check")),
66
+ h("h3", { style: { "font-size": "var(--lt3-text-base)", "font-weight": "var(--lt3-weight-semibold)", "margin": "0" } }, p.label),
67
+ ),
68
+ h("p.lt3-muted", { style: { "font-size": "var(--lt3-text-sm)", "margin": "0" } }, p.value),
69
+ ),
70
+ h("div.lt3-row-2", { style: { "flex": "none", "align-items": "center" } },
71
+ c.statePill(p.enforced ? "active" : "idle"),
72
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, p.enforced ? "Enforced" : "Not enforced"),
73
+ ),
74
+ ),
75
+ );
76
+ }
77
+
78
+ /* ── Enterprise governance packs (open-core extension points) ────────────── */
79
+ function packsPanel({ h, icon, c }) {
80
+ return c.panel({
81
+ eyebrow: "Open core",
82
+ title: "Policy packs",
83
+ sub: "Governance capabilities available as Enterprise extension points on top of the local-first core.",
84
+ actions: c.sourceBadge("placeholder"),
85
+ children: h("div.lt3-stack-2",
86
+ PACKS.map((pk) => h("div.lt3-card.lt3-card--flat",
87
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center", "gap": "var(--lt3-space-4)", "flex-wrap": "wrap" } },
88
+ h("div.lt3-row-2", { style: { "min-width": "0", "flex": "1 1 320px" } },
89
+ h("span.lt3-card__icon", { style: { color: "var(--muted)" } }, icon(pk.icon)),
90
+ h("div.lt3-stack-2", { style: { "min-width": "0" } },
91
+ h("div", { style: { "font-weight": "var(--lt3-weight-medium)" } }, pk.title),
92
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, pk.desc),
93
+ ),
94
+ ),
95
+ h("div.lt3-row-2", { style: { "flex": "none" } },
96
+ c.pill("Enterprise", "info"),
97
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, "Available as an extension point"),
98
+ ),
99
+ ),
100
+ )),
101
+ ),
102
+ });
103
+ }
@@ -0,0 +1,138 @@
1
+ /* ============================================================================
2
+ * View: Admin · Private VPC — network isolation and peering.
3
+ * Lattice is local-first: by default everything runs on-prem with no external
4
+ * network egress. Private VPC is an Enterprise networking extension for teams
5
+ * that need cloud peering. Reads /vpc/status (fallback-safe, badged) and never
6
+ * invents backend mutations — the peering control explains the write side is
7
+ * pending so the surface stays integration-ready.
8
+ * ========================================================================== */
9
+
10
+ import * as fx from "../core/fixtures.js";
11
+
12
+ const PENDING = "an Enterprise networking feature, not available in this build.";
13
+
14
+ export async function render(ctx) {
15
+ const { h, icon, api, c, toast } = ctx;
16
+
17
+ const statusHost = h("div", c.loading({ lines: 4 }));
18
+ const subnetsHost = h("div", c.loading({ lines: 3 }));
19
+ const srcSlot = h("span", c.sourceBadge("pending"));
20
+
21
+ const root = h("div.lt3-stack-6",
22
+ c.viewHeader({
23
+ eyebrow: "Administration",
24
+ title: "Private VPC",
25
+ sub: "Network isolation and peering.",
26
+ actions: [
27
+ h("button.lt3-btn.lt3-btn--primary",
28
+ { on: { click: () => toast("Configure peering — " + PENDING, "info") } },
29
+ icon("network"), "Configure peering"),
30
+ ],
31
+ }),
32
+
33
+ c.banner(
34
+ "Lattice is local-first. By default everything runs on this machine with no external network egress — Private VPC is an Enterprise networking extension for teams that need cloud peering.",
35
+ "info", "shield-lock"),
36
+
37
+ c.panel({
38
+ eyebrow: "Network",
39
+ head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
40
+ h("div",
41
+ h("div.lt3-eyebrow", "Network"),
42
+ h("h3.lt3-panel__title", "Connectivity status"),
43
+ ),
44
+ srcSlot,
45
+ ),
46
+ children: statusHost,
47
+ }),
48
+
49
+ c.panel({
50
+ eyebrow: "Topology",
51
+ title: "Private subnets",
52
+ sub: "Peered subnets exposed to this workspace.",
53
+ children: subnetsHost,
54
+ }),
55
+
56
+ buildPosture(ctx),
57
+ );
58
+
59
+ hydrate(ctx, { statusHost, subnetsHost, srcSlot });
60
+ return root;
61
+ }
62
+
63
+ /* ── Network posture summary (always-true, local-first facts) ─────────────── */
64
+ function buildPosture({ h, icon, c }) {
65
+ const items = [
66
+ { icon: "plug-connected-x", label: "Egress", value: "None", variant: "ok", note: "No external network calls" },
67
+ { icon: "cpu", label: "Inference", value: "Local", variant: "ok", note: "On-device MLX runtime" },
68
+ { icon: "folder-lock", label: "Storage", value: "~/.ltcai", variant: "info", note: "Single-tenant on disk" },
69
+ ];
70
+ return h("section",
71
+ c.sectionHead("Network posture"),
72
+ h("div.lt3-grid-3",
73
+ items.map((it) => c.card(
74
+ h("div.lt3-stack-2",
75
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start" } },
76
+ h("div.lt3-stat__label", icon(it.icon), it.label),
77
+ c.pill(it.value, it.variant, { dot: true }),
78
+ ),
79
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, it.note),
80
+ ),
81
+ { flat: true },
82
+ )),
83
+ ),
84
+ );
85
+ }
86
+
87
+ /* ── Hydration ────────────────────────────────────────────────────────────── */
88
+ async function hydrate(ctx, hosts) {
89
+ const { h, icon, api, c } = ctx;
90
+ const { statusHost, subnetsHost, srcSlot } = hosts;
91
+
92
+ const res = await api.vpcStatus();
93
+ const vpc = (res.data && typeof res.data === "object") ? res.data : fx.ADMIN.vpc;
94
+ srcSlot.replaceChildren(c.sourceBadge(res.source));
95
+
96
+ const subnets = Array.isArray(vpc.private_subnets) ? vpc.private_subnets : [];
97
+
98
+ // Status key/value block.
99
+ const rows = [
100
+ { icon: "cloud", k: "Provider", v: vpc.provider || "local", mono: true },
101
+ { icon: "map-pin", k: "Region", v: vpc.region || "on-prem", mono: true },
102
+ { icon: "lock", k: "VPN status", node: c.statePill(vpc.vpn_status || "standby") },
103
+ { icon: "arrows-transfer-up", k: "Peering status", node: c.statePill(vpc.peering_status || "not_configured") },
104
+ { icon: "plug-connected-x", k: "Egress", node: c.pill("local-only", "ok", { dot: true }) },
105
+ { icon: "subtask", k: "Subnets", v: String(subnets.length) },
106
+ ];
107
+ statusHost.replaceChildren(
108
+ h("dl.lt3-keyval",
109
+ rows.flatMap((r) => [
110
+ h("dt", h("span.lt3-row-2", icon(r.icon), r.k)),
111
+ h("dd", r.node ? r.node : (r.mono ? h("span.lt3-mono", String(r.v)) : String(r.v))),
112
+ ]),
113
+ ),
114
+ !vpc.enabled && h("div.lt3-row-2", { style: { "margin-top": "var(--lt3-space-4)" } },
115
+ c.pill("Enterprise extension", "info", { dot: true }),
116
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } },
117
+ "Private VPC is inactive — Lattice is running fully local."),
118
+ ),
119
+ );
120
+
121
+ // Private subnets table / empty state.
122
+ if (!subnets.length) {
123
+ subnetsHost.replaceChildren(c.emptyState({
124
+ icon: "network-off",
125
+ title: "No private subnets",
126
+ body: "Peering is not configured. Lattice runs fully local by default.",
127
+ }));
128
+ return;
129
+ }
130
+
131
+ const columns = [
132
+ { key: "name", label: "Subnet", render: (s) => h("span.lt3-row-2", icon("subtask"), String(s.name || s.id || "subnet")) },
133
+ { key: "cidr", label: "CIDR", render: (s) => h("span.lt3-mono", String(s.cidr || s.range || "—")) },
134
+ { key: "zone", label: "Zone", render: (s) => String(s.zone || s.az || "—") },
135
+ { key: "state", label: "State", width: "120px", render: (s) => c.statePill(s.state || "active") },
136
+ ];
137
+ subnetsHost.replaceChildren(c.table(columns, subnets));
138
+ }
@@ -0,0 +1,181 @@
1
+ /* ============================================================================
2
+ * View: Admin · Security — sensitive-data signals and DLP.
3
+ * Surfaces the workspace's data-loss-prevention posture: how many messages
4
+ * tripped a sensitive-data signal, how severe, and which field patterns matched.
5
+ * Calm and local-first by design — every scan runs on this machine, so the
6
+ * reassurance ("nothing leaves the computer") is the headline, not a footnote.
7
+ * Reads fx.ADMIN.security (mirrors the documented /admin/security shape) and
8
+ * badges it as sample data until that endpoint is live.
9
+ * ========================================================================== */
10
+
11
+ const SEVERITY = [
12
+ { key: "high", label: "High", variant: "warn", icon: "alert-triangle", desc: "Strong sensitive-data match" },
13
+ { key: "medium", label: "Medium", variant: "", icon: "alert-circle", desc: "Likely sensitive pattern" },
14
+ { key: "low", label: "Low", variant: "ok", icon: "info-circle", desc: "Low-confidence signal" },
15
+ ];
16
+
17
+ export async function render(ctx) {
18
+ const { h, icon, c, navigate } = ctx;
19
+
20
+ // Live DLP overview from /admin/security/overview; clearly-badged sample data
21
+ // when the endpoint is unavailable (e.g. the viewer is not an admin).
22
+ const res = await ctx.api.adminSecurity();
23
+ const sec = normalizeSecurity(res.data);
24
+ const source = res.source;
25
+
26
+ const risky = num(sec.risky_messages);
27
+ const compliant = num(sec.compliant_messages);
28
+ const total = risky + compliant;
29
+ const sev = sec.severity_counts || { high: 0, medium: 0, low: 0 };
30
+ const sevMax = Math.max(1, sev.high || 0, sev.medium || 0, sev.low || 0);
31
+ const dlp = Array.isArray(sec.dlp_fields) ? sec.dlp_fields : [];
32
+ const dlpMax = Math.max(1, ...dlp.map((f) => num(f.hits)));
33
+
34
+ const root = h("div.lt3-stack-6",
35
+ c.viewHeader({
36
+ eyebrow: "Administration",
37
+ title: "Security",
38
+ sub: "Sensitive-data signals and DLP",
39
+ actions: [
40
+ c.sourceBadge(source),
41
+ h("button.lt3-btn.lt3-btn--ghost", {
42
+ on: { click: () => ctx.toast("DLP rule editing is not available in this build; rules are enforced by the runtime defaults.", "warn") },
43
+ }, icon("adjustments"), "Tune rules"),
44
+ h("button.lt3-btn.lt3-btn--primary", {
45
+ on: { click: () => navigate("admin/audit") },
46
+ }, icon("history"), "View audit log"),
47
+ ],
48
+ }),
49
+
50
+ c.banner("DLP scanning runs entirely on this machine. Messages are inspected locally before they ever reach a model — no content leaves your computer.", "info", "shield-lock"),
51
+
52
+ // ── Headline stats ──────────────────────────────────────────────────────
53
+ h("section",
54
+ c.sectionHead("Last scan window", c.sourceBadge(source)),
55
+ h("div.lt3-statrow",
56
+ c.stat({ label: "Risk rate", value: pct(sec.risk_rate), icon: "gauge", delta: `${c.fmtNum(risky)} of ${c.fmtNum(total)}` }),
57
+ c.stat({ label: "Risky messages", value: c.fmtNum(risky), icon: "alert-triangle" }),
58
+ c.stat({ label: "Compliant messages", value: c.fmtNum(compliant), icon: "circle-check" }),
59
+ c.stat({ label: "High severity", value: c.fmtNum(sev.high || 0), icon: "shield-exclamation", delta: (sev.high || 0) === 0 ? "All clear" : "Needs review", deltaDir: (sev.high || 0) === 0 ? "up" : "down" }),
60
+ ),
61
+ ),
62
+
63
+ h("div.lt3-grid-2",
64
+ buildSeverityPanel(ctx, sev, sevMax, source),
65
+ buildDlpPanel(ctx, dlp, dlpMax, total, source),
66
+ ),
67
+ );
68
+
69
+ return root;
70
+ }
71
+
72
+ /* ── Severity breakdown ──────────────────────────────────────────────────── */
73
+ function buildSeverityPanel(ctx, sev, sevMax, source) {
74
+ const { h, icon, c } = ctx;
75
+ const totalSignals = (sev.high || 0) + (sev.medium || 0) + (sev.low || 0);
76
+
77
+ const rows = SEVERITY.map((s) => {
78
+ const count = num(sev[s.key]);
79
+ return h("div.lt3-stack-2",
80
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
81
+ h("div.lt3-row-2",
82
+ h("span.lt3-stat__label", { style: { margin: "0" } }, icon(s.icon), s.label),
83
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, s.desc),
84
+ ),
85
+ h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)", "font-weight": "var(--lt3-weight-semi)" } }, c.fmtNum(count)),
86
+ ),
87
+ c.meter(count / sevMax, s.variant),
88
+ );
89
+ });
90
+
91
+ return c.panel({
92
+ eyebrow: "Signals",
93
+ title: "Severity breakdown",
94
+ sub: totalSignals === 0
95
+ ? "No sensitive-data signals in this window — the workspace is clean."
96
+ : `${c.fmtNum(totalSignals)} ${totalSignals === 1 ? "signal" : "signals"} flagged, normalized to the busiest tier.`,
97
+ children: h("div.lt3-stack-4", rows),
98
+ });
99
+ }
100
+
101
+ /* ── DLP field hits ──────────────────────────────────────────────────────── */
102
+ function buildDlpPanel(ctx, dlp, dlpMax, total, source) {
103
+ const { h, c } = ctx;
104
+
105
+ const columns = [
106
+ {
107
+ key: "field",
108
+ label: "Field",
109
+ render: (row) => h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, String(row.field || "—")),
110
+ },
111
+ {
112
+ key: "hits",
113
+ label: "Hits",
114
+ width: "72px",
115
+ render: (row) => h("span.lt3-weight-semi", c.fmtNum(num(row.hits))),
116
+ },
117
+ {
118
+ key: "share",
119
+ label: "Relative",
120
+ render: (row) => h("div", { style: { "min-width": "120px" } }, c.meter(num(row.hits) / dlpMax, "vector")),
121
+ },
122
+ ];
123
+
124
+ const totalHits = dlp.reduce((sum, f) => sum + num(f.hits), 0);
125
+
126
+ return c.panel({
127
+ eyebrow: "Patterns",
128
+ title: "DLP field hits",
129
+ sub: "Sensitive field patterns matched during local inspection.",
130
+ actions: c.sourceBadge(source),
131
+ children: h("div.lt3-stack-3",
132
+ dlp.length
133
+ ? c.table(columns, dlp)
134
+ : c.emptyState({ icon: "shield-check", title: "No field hits", body: "No sensitive field patterns matched in this window." }),
135
+ dlp.length
136
+ ? h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
137
+ h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${c.fmtNum(totalHits)} total ${totalHits === 1 ? "hit" : "hits"} across ${c.fmtNum(dlp.length)} ${dlp.length === 1 ? "pattern" : "patterns"}`),
138
+ c.sourceBadge(source),
139
+ )
140
+ : null,
141
+ ),
142
+ });
143
+ }
144
+
145
+ /* ── helpers ─────────────────────────────────────────────────────────────── */
146
+ // Normalize the live /admin/security/overview payload and the fixture into one
147
+ // shape: { risk_rate, risky_messages, compliant_messages, severity_counts, dlp_fields }.
148
+ function normalizeSecurity(data) {
149
+ const d = data || {};
150
+ const cards = d.cards || {};
151
+ const risky = num(d.risky_messages != null ? d.risky_messages : cards.risky_chats);
152
+ const riskRate = num(d.risk_rate);
153
+ let compliant = num(d.compliant_messages);
154
+ if (d.compliant_messages == null && riskRate > 0) {
155
+ const total = Math.round(risky / (riskRate / 100));
156
+ compliant = Math.max(0, total - risky);
157
+ }
158
+ let dlp = Array.isArray(d.dlp_fields) ? d.dlp_fields : null;
159
+ if (!dlp && d.field_counts && typeof d.field_counts === "object") {
160
+ dlp = Object.entries(d.field_counts).map(([field, hits]) => ({ field, hits: num(hits) }));
161
+ }
162
+ return {
163
+ risk_rate: riskRate,
164
+ risky_messages: risky,
165
+ compliant_messages: compliant,
166
+ severity_counts: d.severity_counts || { high: 0, medium: 0, low: 0 },
167
+ dlp_fields: dlp || [],
168
+ };
169
+ }
170
+
171
+ function num(v) {
172
+ const n = Number(v);
173
+ return Number.isFinite(n) ? n : 0;
174
+ }
175
+
176
+ function pct(v) {
177
+ const n = Number(v);
178
+ if (!Number.isFinite(n)) return "—";
179
+ // Trim a trailing .0 so "1.2%" stays clean and "0%" doesn't read "0.0%".
180
+ return `${(Math.round(n * 10) / 10).toString().replace(/\.0$/, "")}%`;
181
+ }