ltcai 4.0.1 → 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.
Files changed (150) hide show
  1. package/README.md +28 -23
  2. package/desktop/electron/main.cjs +44 -0
  3. package/docs/CHANGELOG.md +42 -0
  4. package/docs/V4_1_FRONTEND_ARCHITECTURE_REVIEW.md +65 -0
  5. package/docs/V4_1_FRONTEND_MIGRATION_REPORT.md +70 -0
  6. package/docs/V4_1_VALIDATION_REPORT.md +47 -0
  7. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +26 -19
  8. package/frontend/index.html +24 -0
  9. package/frontend/openapi.json +14190 -0
  10. package/frontend/src/App.tsx +184 -0
  11. package/frontend/src/api/client.ts +317 -0
  12. package/frontend/src/api/openapi.ts +16637 -0
  13. package/frontend/src/components/primitives.tsx +204 -0
  14. package/frontend/src/components/ui/badge.tsx +27 -0
  15. package/frontend/src/components/ui/button.tsx +37 -0
  16. package/frontend/src/components/ui/card.tsx +22 -0
  17. package/frontend/src/components/ui/input.tsx +16 -0
  18. package/frontend/src/components/ui/textarea.tsx +16 -0
  19. package/frontend/src/lib/utils.ts +33 -0
  20. package/frontend/src/main.tsx +23 -0
  21. package/frontend/src/pages/Act.tsx +245 -0
  22. package/frontend/src/pages/Ask.tsx +200 -0
  23. package/frontend/src/pages/Brain.tsx +267 -0
  24. package/frontend/src/pages/Capture.tsx +158 -0
  25. package/frontend/src/pages/Library.tsx +187 -0
  26. package/frontend/src/pages/System.tsx +344 -0
  27. package/frontend/src/routes.ts +85 -0
  28. package/frontend/src/store/appStore.ts +54 -0
  29. package/frontend/src/styles.css +107 -0
  30. package/latticeai/__init__.py +1 -1
  31. package/latticeai/api/setup.py +5 -4
  32. package/latticeai/api/static_routes.py +4 -4
  33. package/latticeai/core/marketplace.py +1 -1
  34. package/latticeai/core/multi_agent.py +1 -1
  35. package/latticeai/core/workspace_os.py +1 -1
  36. package/package.json +54 -15
  37. package/scripts/build_frontend_assets.mjs +38 -0
  38. package/scripts/bump_version.py +1 -1
  39. package/scripts/export_openapi.py +31 -0
  40. package/scripts/lint_frontend.mjs +86 -0
  41. package/scripts/run_python.mjs +47 -0
  42. package/src-tauri/Cargo.lock +4833 -0
  43. package/src-tauri/Cargo.toml +19 -0
  44. package/src-tauri/build.rs +3 -0
  45. package/src-tauri/capabilities/default.json +7 -0
  46. package/src-tauri/src/main.rs +78 -0
  47. package/src-tauri/tauri.conf.json +36 -0
  48. package/static/app/asset-manifest.json +32 -0
  49. package/static/app/assets/core-CwxXejkd.js +2 -0
  50. package/static/app/assets/core-CwxXejkd.js.map +1 -0
  51. package/static/app/assets/index-CJRAzNnf.js +333 -0
  52. package/static/app/assets/index-CJRAzNnf.js.map +1 -0
  53. package/static/app/assets/index-CSwBBgf4.css +2 -0
  54. package/static/app/index.html +25 -0
  55. package/static/manifest.json +2 -2
  56. package/static/sw.js +4 -4
  57. package/scripts/build_v3_assets.mjs +0 -170
  58. package/scripts/lint_v3.mjs +0 -120
  59. package/static/v3/asset-manifest.json +0 -63
  60. package/static/v3/css/lattice.base.49deefb5.css +0 -128
  61. package/static/v3/css/lattice.base.css +0 -128
  62. package/static/v3/css/lattice.components.cde18231.css +0 -472
  63. package/static/v3/css/lattice.components.css +0 -472
  64. package/static/v3/css/lattice.shell.29d36d85.css +0 -452
  65. package/static/v3/css/lattice.shell.css +0 -452
  66. package/static/v3/css/lattice.tokens.304cbc40.css +0 -135
  67. package/static/v3/css/lattice.tokens.css +0 -135
  68. package/static/v3/css/lattice.views.0a18b6c5.css +0 -360
  69. package/static/v3/css/lattice.views.css +0 -360
  70. package/static/v3/index.html +0 -68
  71. package/static/v3/js/app.c5c80c46.js +0 -26
  72. package/static/v3/js/app.js +0 -26
  73. package/static/v3/js/core/api.ba0fbf14.js +0 -625
  74. package/static/v3/js/core/api.js +0 -625
  75. package/static/v3/js/core/components.f25b3b93.js +0 -230
  76. package/static/v3/js/core/components.js +0 -230
  77. package/static/v3/js/core/dom.a2773eb0.js +0 -148
  78. package/static/v3/js/core/dom.js +0 -148
  79. package/static/v3/js/core/i18n.880e1fec.js +0 -575
  80. package/static/v3/js/core/i18n.js +0 -575
  81. package/static/v3/js/core/router.584570f2.js +0 -37
  82. package/static/v3/js/core/router.js +0 -37
  83. package/static/v3/js/core/routes.37522821.js +0 -101
  84. package/static/v3/js/core/routes.js +0 -101
  85. package/static/v3/js/core/shell.e3f6bbfa.js +0 -420
  86. package/static/v3/js/core/shell.js +0 -420
  87. package/static/v3/js/core/store.7b2aa044.js +0 -123
  88. package/static/v3/js/core/store.js +0 -123
  89. package/static/v3/js/views/account.eff40715.js +0 -143
  90. package/static/v3/js/views/account.js +0 -143
  91. package/static/v3/js/views/activity.0d271ef9.js +0 -67
  92. package/static/v3/js/views/activity.js +0 -67
  93. package/static/v3/js/views/admin-audit.660a1fb1.js +0 -185
  94. package/static/v3/js/views/admin-audit.js +0 -185
  95. package/static/v3/js/views/admin-permissions.a7ae5f09.js +0 -177
  96. package/static/v3/js/views/admin-permissions.js +0 -177
  97. package/static/v3/js/views/admin-policies.3658fd86.js +0 -102
  98. package/static/v3/js/views/admin-policies.js +0 -102
  99. package/static/v3/js/views/admin-private-vpc.7d342d36.js +0 -135
  100. package/static/v3/js/views/admin-private-vpc.js +0 -135
  101. package/static/v3/js/views/admin-security.07c66b72.js +0 -180
  102. package/static/v3/js/views/admin-security.js +0 -180
  103. package/static/v3/js/views/admin-users.f7ac7b43.js +0 -166
  104. package/static/v3/js/views/admin-users.js +0 -166
  105. package/static/v3/js/views/agents.17c5288d.js +0 -564
  106. package/static/v3/js/views/agents.js +0 -564
  107. package/static/v3/js/views/chat.e250e2cc.js +0 -624
  108. package/static/v3/js/views/chat.js +0 -624
  109. package/static/v3/js/views/files.adad14c1.js +0 -365
  110. package/static/v3/js/views/files.js +0 -365
  111. package/static/v3/js/views/graph-canvas.17c15d65.js +0 -509
  112. package/static/v3/js/views/graph-canvas.js +0 -509
  113. package/static/v3/js/views/home.24f8b8ae.js +0 -200
  114. package/static/v3/js/views/home.js +0 -200
  115. package/static/v3/js/views/hooks.37895880.js +0 -220
  116. package/static/v3/js/views/hooks.js +0 -220
  117. package/static/v3/js/views/hybrid-search.2fb63ed9.js +0 -194
  118. package/static/v3/js/views/hybrid-search.js +0 -194
  119. package/static/v3/js/views/knowledge-graph.4d09c537.js +0 -529
  120. package/static/v3/js/views/knowledge-graph.js +0 -529
  121. package/static/v3/js/views/marketplace.ab0583d4.js +0 -141
  122. package/static/v3/js/views/marketplace.js +0 -141
  123. package/static/v3/js/views/mcp.99b5c6a7.js +0 -114
  124. package/static/v3/js/views/mcp.js +0 -114
  125. package/static/v3/js/views/memory.4ebdf474.js +0 -147
  126. package/static/v3/js/views/memory.js +0 -147
  127. package/static/v3/js/views/models.a1ffa147.js +0 -256
  128. package/static/v3/js/views/models.js +0 -256
  129. package/static/v3/js/views/my-computer.d9d9ae1c.js +0 -463
  130. package/static/v3/js/views/my-computer.js +0 -463
  131. package/static/v3/js/views/network.52a4f181.js +0 -97
  132. package/static/v3/js/views/network.js +0 -97
  133. package/static/v3/js/views/pipeline.c522f1ce.js +0 -157
  134. package/static/v3/js/views/pipeline.js +0 -157
  135. package/static/v3/js/views/planning.4876fd77.js +0 -174
  136. package/static/v3/js/views/planning.js +0 -174
  137. package/static/v3/js/views/runs.b63b2afa.js +0 -144
  138. package/static/v3/js/views/runs.js +0 -144
  139. package/static/v3/js/views/settings.b7140634.js +0 -317
  140. package/static/v3/js/views/settings.js +0 -317
  141. package/static/v3/js/views/skills.c6c2f965.js +0 -109
  142. package/static/v3/js/views/skills.js +0 -109
  143. package/static/v3/js/views/snapshots.6f5db095.js +0 -135
  144. package/static/v3/js/views/snapshots.js +0 -135
  145. package/static/v3/js/views/tools.e4f11276.js +0 -108
  146. package/static/v3/js/views/tools.js +0 -108
  147. package/static/v3/js/views/workflows.7752225a.js +0 -213
  148. package/static/v3/js/views/workflows.js +0 -213
  149. package/static/v3/js/views/workspace-admin.c466029b.js +0 -156
  150. package/static/v3/js/views/workspace-admin.js +0 -156
@@ -1,180 +0,0 @@
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 /admin/security/overview and renders unavailable state when it cannot
8
- * load.
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.
21
- const res = await ctx.api.adminSecurity();
22
- const sec = normalizeSecurity(res.data);
23
- const source = res.source;
24
-
25
- const risky = num(sec.risky_messages);
26
- const compliant = num(sec.compliant_messages);
27
- const total = risky + compliant;
28
- const sev = sec.severity_counts || { high: 0, medium: 0, low: 0 };
29
- const sevMax = Math.max(1, sev.high || 0, sev.medium || 0, sev.low || 0);
30
- const dlp = Array.isArray(sec.dlp_fields) ? sec.dlp_fields : [];
31
- const dlpMax = Math.max(1, ...dlp.map((f) => num(f.hits)));
32
-
33
- const root = h("div.lt3-stack-6",
34
- c.viewHeader({
35
- eyebrow: "Administration",
36
- title: "Security",
37
- sub: "Sensitive-data signals and DLP",
38
- actions: [
39
- c.sourceBadge(source),
40
- h("button.lt3-btn.lt3-btn--ghost", {
41
- on: { click: () => ctx.toast("DLP rule editing is not available in this build; rules are enforced by the runtime defaults.", "warn") },
42
- }, icon("adjustments"), "Tune rules"),
43
- h("button.lt3-btn.lt3-btn--primary", {
44
- on: { click: () => navigate("admin/audit") },
45
- }, icon("history"), "View audit log"),
46
- ],
47
- }),
48
-
49
- 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"),
50
-
51
- // ── Headline stats ──────────────────────────────────────────────────────
52
- h("section",
53
- c.sectionHead("Last scan window", c.sourceBadge(source)),
54
- h("div.lt3-statrow",
55
- c.stat({ label: "Risk rate", value: pct(sec.risk_rate), icon: "gauge", delta: `${c.fmtNum(risky)} of ${c.fmtNum(total)}` }),
56
- c.stat({ label: "Risky messages", value: c.fmtNum(risky), icon: "alert-triangle" }),
57
- c.stat({ label: "Compliant messages", value: c.fmtNum(compliant), icon: "circle-check" }),
58
- 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" }),
59
- ),
60
- ),
61
-
62
- h("div.lt3-grid-2",
63
- buildSeverityPanel(ctx, sev, sevMax, source),
64
- buildDlpPanel(ctx, dlp, dlpMax, total, source),
65
- ),
66
- );
67
-
68
- return root;
69
- }
70
-
71
- /* ── Severity breakdown ──────────────────────────────────────────────────── */
72
- function buildSeverityPanel(ctx, sev, sevMax, source) {
73
- const { h, icon, c } = ctx;
74
- const totalSignals = (sev.high || 0) + (sev.medium || 0) + (sev.low || 0);
75
-
76
- const rows = SEVERITY.map((s) => {
77
- const count = num(sev[s.key]);
78
- return h("div.lt3-stack-2",
79
- h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "center" } },
80
- h("div.lt3-row-2",
81
- h("span.lt3-stat__label", { style: { margin: "0" } }, icon(s.icon), s.label),
82
- h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, s.desc),
83
- ),
84
- h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)", "font-weight": "var(--lt3-weight-semi)" } }, c.fmtNum(count)),
85
- ),
86
- c.meter(count / sevMax, s.variant),
87
- );
88
- });
89
-
90
- return c.panel({
91
- eyebrow: "Signals",
92
- title: "Severity breakdown",
93
- sub: totalSignals === 0
94
- ? "No sensitive-data signals in this window — the workspace is clean."
95
- : `${c.fmtNum(totalSignals)} ${totalSignals === 1 ? "signal" : "signals"} flagged, normalized to the busiest tier.`,
96
- children: h("div.lt3-stack-4", rows),
97
- });
98
- }
99
-
100
- /* ── DLP field hits ──────────────────────────────────────────────────────── */
101
- function buildDlpPanel(ctx, dlp, dlpMax, total, source) {
102
- const { h, c } = ctx;
103
-
104
- const columns = [
105
- {
106
- key: "field",
107
- label: "Field",
108
- render: (row) => h("span.lt3-mono", { style: { "font-size": "var(--lt3-text-sm)" } }, String(row.field || "—")),
109
- },
110
- {
111
- key: "hits",
112
- label: "Hits",
113
- width: "72px",
114
- render: (row) => h("span.lt3-weight-semi", c.fmtNum(num(row.hits))),
115
- },
116
- {
117
- key: "share",
118
- label: "Relative",
119
- render: (row) => h("div", { style: { "min-width": "120px" } }, c.meter(num(row.hits) / dlpMax, "vector")),
120
- },
121
- ];
122
-
123
- const totalHits = dlp.reduce((sum, f) => sum + num(f.hits), 0);
124
-
125
- return c.panel({
126
- eyebrow: "Patterns",
127
- title: "DLP field hits",
128
- sub: "Sensitive field patterns matched during local inspection.",
129
- actions: c.sourceBadge(source),
130
- children: h("div.lt3-stack-3",
131
- dlp.length
132
- ? c.table(columns, dlp)
133
- : c.emptyState({ icon: "shield-check", title: "No field hits", body: "No sensitive field patterns matched in this window." }),
134
- dlp.length
135
- ? h("div.lt3-row-2", { style: { "justify-content": "space-between" } },
136
- 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"}`),
137
- c.sourceBadge(source),
138
- )
139
- : null,
140
- ),
141
- });
142
- }
143
-
144
- /* ── helpers ─────────────────────────────────────────────────────────────── */
145
- // Normalize the live /admin/security/overview payload into one
146
- // shape: { risk_rate, risky_messages, compliant_messages, severity_counts, dlp_fields }.
147
- function normalizeSecurity(data) {
148
- const d = data || {};
149
- const cards = d.cards || {};
150
- const risky = num(d.risky_messages != null ? d.risky_messages : cards.risky_chats);
151
- const riskRate = num(d.risk_rate);
152
- let compliant = num(d.compliant_messages);
153
- if (d.compliant_messages == null && riskRate > 0) {
154
- const total = Math.round(risky / (riskRate / 100));
155
- compliant = Math.max(0, total - risky);
156
- }
157
- let dlp = Array.isArray(d.dlp_fields) ? d.dlp_fields : null;
158
- if (!dlp && d.field_counts && typeof d.field_counts === "object") {
159
- dlp = Object.entries(d.field_counts).map(([field, hits]) => ({ field, hits: num(hits) }));
160
- }
161
- return {
162
- risk_rate: riskRate,
163
- risky_messages: risky,
164
- compliant_messages: compliant,
165
- severity_counts: d.severity_counts || { high: 0, medium: 0, low: 0 },
166
- dlp_fields: dlp || [],
167
- };
168
- }
169
-
170
- function num(v) {
171
- const n = Number(v);
172
- return Number.isFinite(n) ? n : 0;
173
- }
174
-
175
- function pct(v) {
176
- const n = Number(v);
177
- if (!Number.isFinite(n)) return "—";
178
- // Trim a trailing .0 so "1.2%" stays clean and "0%" doesn't read "0.0%".
179
- return `${(Math.round(n * 10) / 10).toString().replace(/\.0$/, "")}%`;
180
- }
@@ -1,166 +0,0 @@
1
- /* ============================================================================
2
- * View: Admin · Users — workspace members and access.
3
- * Surfaces the membership roster and access summary for the active workspace.
4
- * Reads from /admin/summary + /admin/users (fallback-safe, badged) and never
5
- * invents backend mutations — actionable controls report unavailable write
6
- * operations when the backend does not expose them.
7
- * ========================================================================== */
8
-
9
- import { timeAgo } from "../core/dom.a2773eb0.js";
10
-
11
- export async function render(ctx) {
12
- const { h, icon, api, c, toast, navigate } = ctx;
13
-
14
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
15
- const tableHost = h("div", c.loading({ lines: 4 }));
16
- const srcSlot = h("span", c.sourceBadge("pending"));
17
-
18
- const root = h("div.lt3-stack-6",
19
- c.viewHeader({
20
- eyebrow: "Administration",
21
- title: "Users",
22
- sub: "Workspace members and access.",
23
- actions: [
24
- h("button.lt3-btn.lt3-btn--primary",
25
- { on: { click: () => navigate("workspace-admin") } },
26
- icon("user-plus"), "Invite user"),
27
- ],
28
- }),
29
- statHost,
30
- c.panel({
31
- eyebrow: "Roster",
32
- head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
33
- h("div",
34
- h("div.lt3-eyebrow", "Roster"),
35
- h("h3.lt3-panel__title", "Members"),
36
- ),
37
- srcSlot,
38
- ),
39
- children: tableHost,
40
- }),
41
- );
42
-
43
- async function load() {
44
- const [summary, users] = await Promise.all([api.adminSummary(), api.adminUsers()]);
45
- renderStats(summary);
46
- renderTable(users, c.sourceBadge(users.source));
47
- }
48
-
49
- function renderStats(res) {
50
- const s = normalizeSummary(res.data);
51
- statHost.replaceChildren(
52
- c.stat({ label: "Total users", value: c.fmtNum(s.total_users), icon: "users" }),
53
- c.stat({ label: "Active", value: c.fmtNum(s.active_users), icon: "user-check" }),
54
- c.stat({ label: "Admins", value: c.fmtNum(s.admin_users), icon: "shield-lock" }),
55
- c.stat({ label: "Messages", value: c.fmtNum(s.total_messages), icon: "message-2" }),
56
- );
57
- }
58
-
59
- function renderTable(res, badge) {
60
- srcSlot.replaceChildren(badge);
61
- const rows = normalizeUsers(res.data);
62
- if (!rows.length) {
63
- tableHost.replaceChildren(c.emptyState({
64
- icon: "user-off",
65
- title: "No members yet",
66
- body: "Invite teammates to give them access to this workspace.",
67
- action: h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm",
68
- { on: { click: () => navigate("workspace-admin") } },
69
- icon("user-plus"), "Invite user"),
70
- }));
71
- return;
72
- }
73
- tableHost.replaceChildren(c.table(columns(), rows));
74
- }
75
-
76
- function columns() {
77
- return [
78
- {
79
- key: "user", label: "User",
80
- render: (r) => h("div.lt3-row-2",
81
- h("span.lt3-avatar", initials(r.nickname, r.email)),
82
- h("div",
83
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)" } }, r.nickname),
84
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, r.email),
85
- ),
86
- ),
87
- },
88
- {
89
- key: "role", label: "Role", width: "120px",
90
- render: (r) => c.pill(titleCase(r.role), roleVariant(r.role)),
91
- },
92
- {
93
- key: "status", label: "Status", width: "120px",
94
- render: (r) => c.statePill(r.disabled ? "disabled" : "active"),
95
- },
96
- {
97
- key: "last_seen", label: "Last seen", width: "130px",
98
- render: (r) => h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } },
99
- r.last_seen ? timeAgo(r.last_seen) : "—"),
100
- },
101
- {
102
- key: "actions", label: "", width: "48px",
103
- render: (r) => h("button.lt3-iconbtn.lt3-iconbtn--sm",
104
- {
105
- "aria-label": `Manage ${r.nickname || r.email}`,
106
- on: { click: () => toast(`Manage ${r.nickname || r.email} in Workspaces`, "info") },
107
- },
108
- icon("dots-vertical")),
109
- },
110
- ];
111
- }
112
-
113
- load();
114
- return root;
115
- }
116
-
117
- /* ── helpers ─────────────────────────────────────────────────────────────── */
118
- function normalizeSummary(data) {
119
- const d = data && typeof data === "object" ? data : {};
120
- return {
121
- total_users: numOr(d.total_users),
122
- active_users: numOr(d.active_users),
123
- admin_users: numOr(d.admin_users),
124
- total_messages: numOr(d.total_messages),
125
- };
126
- }
127
-
128
- function normalizeUsers(data) {
129
- const list = Array.isArray(data) ? data : Array.isArray(data && data.users) ? data.users : [];
130
- return list
131
- .filter((u) => u && typeof u === "object")
132
- .map((u) => {
133
- const email = String(u.email || "").trim();
134
- return {
135
- email: email || "—",
136
- nickname: String(u.nickname || u.name || "").trim() || email.split("@")[0] || "Member",
137
- role: String(u.role || "member").trim().toLowerCase(),
138
- disabled: Boolean(u.disabled),
139
- last_seen: u.last_seen ?? u.lastSeen ?? null,
140
- };
141
- });
142
- }
143
-
144
- function numOr(v) {
145
- const n = Number(v);
146
- return Number.isFinite(n) ? n : null;
147
- }
148
-
149
- function roleVariant(role) {
150
- const r = String(role || "").toLowerCase();
151
- if (r === "owner" || r === "admin") return "info";
152
- return "";
153
- }
154
-
155
- function initials(nickname, email) {
156
- const base = String(nickname || email || "").trim();
157
- if (!base) return "?";
158
- const words = base.split(/[\s._-]+/).filter(Boolean);
159
- if (words.length >= 2) return (words[0][0] + words[1][0]).toUpperCase();
160
- return base.slice(0, 2).toUpperCase();
161
- }
162
-
163
- function titleCase(s) {
164
- const v = String(s || "");
165
- return v ? v.charAt(0).toUpperCase() + v.slice(1) : "Member";
166
- }
@@ -1,166 +0,0 @@
1
- /* ============================================================================
2
- * View: Admin · Users — workspace members and access.
3
- * Surfaces the membership roster and access summary for the active workspace.
4
- * Reads from /admin/summary + /admin/users (fallback-safe, badged) and never
5
- * invents backend mutations — actionable controls report unavailable write
6
- * operations when the backend does not expose them.
7
- * ========================================================================== */
8
-
9
- import { timeAgo } from "../core/dom.js";
10
-
11
- export async function render(ctx) {
12
- const { h, icon, api, c, toast, navigate } = ctx;
13
-
14
- const statHost = h("div.lt3-statrow", c.loading({ lines: 1 }));
15
- const tableHost = h("div", c.loading({ lines: 4 }));
16
- const srcSlot = h("span", c.sourceBadge("pending"));
17
-
18
- const root = h("div.lt3-stack-6",
19
- c.viewHeader({
20
- eyebrow: "Administration",
21
- title: "Users",
22
- sub: "Workspace members and access.",
23
- actions: [
24
- h("button.lt3-btn.lt3-btn--primary",
25
- { on: { click: () => navigate("workspace-admin") } },
26
- icon("user-plus"), "Invite user"),
27
- ],
28
- }),
29
- statHost,
30
- c.panel({
31
- eyebrow: "Roster",
32
- head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
33
- h("div",
34
- h("div.lt3-eyebrow", "Roster"),
35
- h("h3.lt3-panel__title", "Members"),
36
- ),
37
- srcSlot,
38
- ),
39
- children: tableHost,
40
- }),
41
- );
42
-
43
- async function load() {
44
- const [summary, users] = await Promise.all([api.adminSummary(), api.adminUsers()]);
45
- renderStats(summary);
46
- renderTable(users, c.sourceBadge(users.source));
47
- }
48
-
49
- function renderStats(res) {
50
- const s = normalizeSummary(res.data);
51
- statHost.replaceChildren(
52
- c.stat({ label: "Total users", value: c.fmtNum(s.total_users), icon: "users" }),
53
- c.stat({ label: "Active", value: c.fmtNum(s.active_users), icon: "user-check" }),
54
- c.stat({ label: "Admins", value: c.fmtNum(s.admin_users), icon: "shield-lock" }),
55
- c.stat({ label: "Messages", value: c.fmtNum(s.total_messages), icon: "message-2" }),
56
- );
57
- }
58
-
59
- function renderTable(res, badge) {
60
- srcSlot.replaceChildren(badge);
61
- const rows = normalizeUsers(res.data);
62
- if (!rows.length) {
63
- tableHost.replaceChildren(c.emptyState({
64
- icon: "user-off",
65
- title: "No members yet",
66
- body: "Invite teammates to give them access to this workspace.",
67
- action: h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm",
68
- { on: { click: () => navigate("workspace-admin") } },
69
- icon("user-plus"), "Invite user"),
70
- }));
71
- return;
72
- }
73
- tableHost.replaceChildren(c.table(columns(), rows));
74
- }
75
-
76
- function columns() {
77
- return [
78
- {
79
- key: "user", label: "User",
80
- render: (r) => h("div.lt3-row-2",
81
- h("span.lt3-avatar", initials(r.nickname, r.email)),
82
- h("div",
83
- h("div", { style: { "font-weight": "var(--lt3-weight-semi)" } }, r.nickname),
84
- h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } }, r.email),
85
- ),
86
- ),
87
- },
88
- {
89
- key: "role", label: "Role", width: "120px",
90
- render: (r) => c.pill(titleCase(r.role), roleVariant(r.role)),
91
- },
92
- {
93
- key: "status", label: "Status", width: "120px",
94
- render: (r) => c.statePill(r.disabled ? "disabled" : "active"),
95
- },
96
- {
97
- key: "last_seen", label: "Last seen", width: "130px",
98
- render: (r) => h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-xs)" } },
99
- r.last_seen ? timeAgo(r.last_seen) : "—"),
100
- },
101
- {
102
- key: "actions", label: "", width: "48px",
103
- render: (r) => h("button.lt3-iconbtn.lt3-iconbtn--sm",
104
- {
105
- "aria-label": `Manage ${r.nickname || r.email}`,
106
- on: { click: () => toast(`Manage ${r.nickname || r.email} in Workspaces`, "info") },
107
- },
108
- icon("dots-vertical")),
109
- },
110
- ];
111
- }
112
-
113
- load();
114
- return root;
115
- }
116
-
117
- /* ── helpers ─────────────────────────────────────────────────────────────── */
118
- function normalizeSummary(data) {
119
- const d = data && typeof data === "object" ? data : {};
120
- return {
121
- total_users: numOr(d.total_users),
122
- active_users: numOr(d.active_users),
123
- admin_users: numOr(d.admin_users),
124
- total_messages: numOr(d.total_messages),
125
- };
126
- }
127
-
128
- function normalizeUsers(data) {
129
- const list = Array.isArray(data) ? data : Array.isArray(data && data.users) ? data.users : [];
130
- return list
131
- .filter((u) => u && typeof u === "object")
132
- .map((u) => {
133
- const email = String(u.email || "").trim();
134
- return {
135
- email: email || "—",
136
- nickname: String(u.nickname || u.name || "").trim() || email.split("@")[0] || "Member",
137
- role: String(u.role || "member").trim().toLowerCase(),
138
- disabled: Boolean(u.disabled),
139
- last_seen: u.last_seen ?? u.lastSeen ?? null,
140
- };
141
- });
142
- }
143
-
144
- function numOr(v) {
145
- const n = Number(v);
146
- return Number.isFinite(n) ? n : null;
147
- }
148
-
149
- function roleVariant(role) {
150
- const r = String(role || "").toLowerCase();
151
- if (r === "owner" || r === "admin") return "info";
152
- return "";
153
- }
154
-
155
- function initials(nickname, email) {
156
- const base = String(nickname || email || "").trim();
157
- if (!base) return "?";
158
- const words = base.split(/[\s._-]+/).filter(Boolean);
159
- if (words.length >= 2) return (words[0][0] + words[1][0]).toUpperCase();
160
- return base.slice(0, 2).toUpperCase();
161
- }
162
-
163
- function titleCase(s) {
164
- const v = String(s || "");
165
- return v ? v.charAt(0).toUpperCase() + v.slice(1) : "Member";
166
- }