ltcai 3.6.0 → 4.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 (238) hide show
  1. package/README.md +39 -31
  2. package/docs/CHANGELOG.md +64 -0
  3. package/docs/REALTIME_COLLABORATION.md +3 -3
  4. package/docs/V3_FRONTEND.md +9 -8
  5. package/docs/V4_BRAIN_ARCHITECTURE.md +322 -0
  6. package/docs/V4_DIGITAL_BRAIN_RECOVERY.md +552 -0
  7. package/docs/V4_IMPLEMENTATION_PLAN.md +470 -0
  8. package/docs/kg-schema.md +51 -53
  9. package/docs/spec-vs-impl.md +10 -10
  10. package/kg_schema.py +2 -520
  11. package/knowledge_graph.py +37 -4629
  12. package/knowledge_graph_api.py +11 -127
  13. package/latticeai/__init__.py +1 -1
  14. package/latticeai/api/admin.py +16 -17
  15. package/latticeai/api/agents.py +20 -7
  16. package/latticeai/api/auth.py +46 -15
  17. package/latticeai/api/chat.py +112 -76
  18. package/latticeai/api/health.py +1 -1
  19. package/latticeai/api/hooks.py +1 -1
  20. package/latticeai/api/invitations.py +100 -0
  21. package/latticeai/api/knowledge_graph.py +139 -0
  22. package/latticeai/api/local_files.py +1 -1
  23. package/latticeai/api/mcp.py +23 -11
  24. package/latticeai/api/memory.py +1 -1
  25. package/latticeai/api/models.py +1 -1
  26. package/latticeai/api/network.py +81 -0
  27. package/latticeai/api/plugins.py +3 -6
  28. package/latticeai/api/realtime.py +5 -8
  29. package/latticeai/api/search.py +26 -2
  30. package/latticeai/api/security_dashboard.py +2 -3
  31. package/latticeai/api/setup.py +2 -2
  32. package/latticeai/api/static_routes.py +11 -16
  33. package/latticeai/api/tools.py +3 -0
  34. package/latticeai/api/ui_redirects.py +26 -0
  35. package/latticeai/api/workflow_designer.py +85 -6
  36. package/latticeai/api/workspace.py +93 -57
  37. package/latticeai/app_factory.py +1781 -0
  38. package/latticeai/brain/__init__.py +18 -0
  39. package/latticeai/brain/_kg_common.py +1123 -0
  40. package/latticeai/brain/context.py +213 -0
  41. package/latticeai/brain/conversations.py +236 -0
  42. package/latticeai/brain/discovery.py +1455 -0
  43. package/latticeai/brain/documents.py +218 -0
  44. package/latticeai/brain/identity.py +175 -0
  45. package/latticeai/brain/ingest.py +644 -0
  46. package/latticeai/brain/memory.py +102 -0
  47. package/latticeai/brain/network.py +205 -0
  48. package/latticeai/brain/projection.py +561 -0
  49. package/latticeai/brain/provenance.py +401 -0
  50. package/latticeai/brain/retrieval.py +1316 -0
  51. package/latticeai/brain/schema.py +640 -0
  52. package/latticeai/brain/store.py +216 -0
  53. package/latticeai/brain/write_master.py +225 -0
  54. package/latticeai/core/agent.py +31 -7
  55. package/latticeai/core/audit.py +0 -7
  56. package/latticeai/core/config.py +1 -1
  57. package/latticeai/core/context_builder.py +1 -2
  58. package/latticeai/core/enterprise.py +1 -1
  59. package/latticeai/core/graph_curator.py +2 -2
  60. package/latticeai/core/invitations.py +131 -0
  61. package/latticeai/core/marketplace.py +1 -1
  62. package/latticeai/core/mcp_registry.py +791 -0
  63. package/latticeai/core/model_compat.py +1 -1
  64. package/latticeai/core/model_resolution.py +0 -1
  65. package/latticeai/core/multi_agent.py +238 -4
  66. package/latticeai/core/policy.py +54 -0
  67. package/latticeai/core/realtime.py +65 -44
  68. package/latticeai/core/security.py +1 -1
  69. package/latticeai/core/sessions.py +66 -10
  70. package/latticeai/core/users.py +147 -0
  71. package/latticeai/core/workflow_engine.py +114 -2
  72. package/latticeai/core/workspace_os.py +477 -29
  73. package/latticeai/models/__init__.py +7 -0
  74. package/latticeai/models/router.py +779 -0
  75. package/latticeai/server_app.py +29 -1536
  76. package/latticeai/services/agent_runtime.py +243 -4
  77. package/latticeai/services/app_context.py +75 -14
  78. package/latticeai/services/ingestion.py +47 -0
  79. package/latticeai/services/kg_portability.py +33 -3
  80. package/latticeai/services/memory_service.py +39 -11
  81. package/latticeai/services/model_runtime.py +2 -5
  82. package/latticeai/services/platform_runtime.py +100 -23
  83. package/latticeai/services/run_executor.py +328 -0
  84. package/latticeai/services/search_service.py +17 -8
  85. package/latticeai/services/tool_dispatch.py +12 -2
  86. package/latticeai/services/triggers.py +241 -0
  87. package/latticeai/services/upload_service.py +37 -12
  88. package/latticeai/services/workspace_service.py +55 -16
  89. package/llm_router.py +29 -772
  90. package/ltcai_cli.py +1 -2
  91. package/mcp_registry.py +25 -788
  92. package/p_reinforce.py +124 -14
  93. package/package.json +10 -20
  94. package/scripts/bump_version.py +99 -0
  95. package/scripts/generate_diagrams.py +0 -1
  96. package/scripts/lint_v3.mjs +105 -18
  97. package/scripts/validate_release_artifacts.py +0 -1
  98. package/scripts/wheel_smoke.py +142 -0
  99. package/server.py +11 -7
  100. package/setup_wizard.py +1142 -0
  101. package/static/sw.js +81 -52
  102. package/static/v3/asset-manifest.json +33 -25
  103. package/static/v3/css/{lattice.base.e4cdd05d.css → lattice.base.49deefb5.css} +1 -1
  104. package/static/v3/css/lattice.base.css +1 -1
  105. package/static/v3/css/{lattice.components.9b49d614.css → lattice.components.cde18231.css} +1 -1
  106. package/static/v3/css/lattice.components.css +1 -1
  107. package/static/v3/css/{lattice.shell.8fcc9d33.css → lattice.shell.29d36d85.css} +1 -1
  108. package/static/v3/css/lattice.shell.css +1 -1
  109. package/static/v3/css/{lattice.tokens.e7018963.css → lattice.tokens.304cbc40.css} +3 -0
  110. package/static/v3/css/lattice.tokens.css +3 -0
  111. package/static/v3/css/{lattice.views.22f69117.css → lattice.views.0a18b6c5.css} +2 -2
  112. package/static/v3/css/lattice.views.css +2 -2
  113. package/static/v3/index.html +3 -4
  114. package/static/v3/js/{app.c541f955.js → app.c5c80c46.js} +1 -1
  115. package/static/v3/js/core/{api.33d6320e.js → api.ba0fbf14.js} +58 -1
  116. package/static/v3/js/core/api.js +57 -0
  117. package/static/v3/js/core/i18n.880e1fec.js +575 -0
  118. package/static/v3/js/core/i18n.js +575 -0
  119. package/static/v3/js/core/routes.37522821.js +101 -0
  120. package/static/v3/js/core/routes.js +71 -63
  121. package/static/v3/js/core/{shell.8c163e0e.js → shell.e3f6bbfa.js} +68 -39
  122. package/static/v3/js/core/shell.js +66 -37
  123. package/static/v3/js/core/{store.34ebd5e6.js → store.7b2aa044.js} +11 -1
  124. package/static/v3/js/core/store.js +11 -1
  125. package/static/v3/js/views/account.eff40715.js +143 -0
  126. package/static/v3/js/views/account.js +143 -0
  127. package/static/v3/js/views/activity.0d271ef9.js +67 -0
  128. package/static/v3/js/views/activity.js +67 -0
  129. package/static/v3/js/views/{admin-users.03bac88c.js → admin-users.f7ac7b43.js} +4 -6
  130. package/static/v3/js/views/admin-users.js +4 -6
  131. package/static/v3/js/views/{agents.014d0b74.js → agents.17c5288d.js} +35 -12
  132. package/static/v3/js/views/agents.js +35 -12
  133. package/static/v3/js/views/{chat.e6dd7dd0.js → chat.e250e2cc.js} +23 -0
  134. package/static/v3/js/views/chat.js +23 -0
  135. package/static/v3/js/views/graph-canvas.17c15d65.js +509 -0
  136. package/static/v3/js/views/graph-canvas.js +509 -0
  137. package/static/v3/js/views/{hybrid-search.b22b97e0.js → hybrid-search.2fb63ed9.js} +1 -2
  138. package/static/v3/js/views/hybrid-search.js +1 -2
  139. package/static/v3/js/views/{knowledge-graph.a96040a5.js → knowledge-graph.4d09c537.js} +60 -44
  140. package/static/v3/js/views/knowledge-graph.js +60 -44
  141. package/static/v3/js/views/network.52a4f181.js +97 -0
  142. package/static/v3/js/views/network.js +97 -0
  143. package/static/v3/js/views/{planning.9ac3e313.js → planning.4876fd77.js} +26 -5
  144. package/static/v3/js/views/planning.js +26 -5
  145. package/static/v3/js/views/runs.b63b2afa.js +144 -0
  146. package/static/v3/js/views/runs.js +144 -0
  147. package/static/v3/js/views/{settings.8631fa5e.js → settings.b7140634.js} +7 -8
  148. package/static/v3/js/views/settings.js +7 -8
  149. package/static/v3/js/views/snapshots.6f5db095.js +135 -0
  150. package/static/v3/js/views/snapshots.js +135 -0
  151. package/static/v3/js/views/{workflows.26c57290.js → workflows.7752225a.js} +87 -2
  152. package/static/v3/js/views/workflows.js +87 -2
  153. package/static/v3/js/views/workspace-admin.c466029b.js +156 -0
  154. package/static/v3/js/views/workspace-admin.js +156 -0
  155. package/static/vendor/chart.umd.min.js +20 -0
  156. package/static/vendor/fonts/inter-latin-300-normal.woff2 +0 -0
  157. package/static/vendor/fonts/inter-latin-400-normal.woff2 +0 -0
  158. package/static/vendor/fonts/inter-latin-500-normal.woff2 +0 -0
  159. package/static/vendor/fonts/inter-latin-600-normal.woff2 +0 -0
  160. package/static/vendor/fonts/inter-latin-700-normal.woff2 +0 -0
  161. package/static/vendor/fonts/inter-latin-800-normal.woff2 +0 -0
  162. package/static/vendor/fonts/inter.css +44 -0
  163. package/static/vendor/icons/tabler-icons.min.css +4 -0
  164. package/static/vendor/icons/tabler-icons.woff2 +0 -0
  165. package/static/vendor/marked.min.js +69 -0
  166. package/telegram_bot.py +1 -2
  167. package/tools/commands.py +4 -2
  168. package/tools/computer.py +1 -1
  169. package/tools/documents.py +1 -3
  170. package/tools/filesystem.py +0 -4
  171. package/tools/knowledge.py +1 -3
  172. package/tools/network.py +1 -3
  173. package/codex_telegram_bot.py +0 -195
  174. package/docs/assets/v3.4.0/agent-run.png +0 -0
  175. package/docs/assets/v3.4.0/agents.png +0 -0
  176. package/docs/assets/v3.4.0/before/chat-before.png +0 -0
  177. package/docs/assets/v3.4.0/before/files-before.png +0 -0
  178. package/docs/assets/v3.4.0/chat.png +0 -0
  179. package/docs/assets/v3.4.0/connect-folder.png +0 -0
  180. package/docs/assets/v3.4.0/files.png +0 -0
  181. package/docs/assets/v3.4.0/home.png +0 -0
  182. package/docs/assets/v3.4.0/hooks-dispatch.png +0 -0
  183. package/docs/assets/v3.4.0/knowledge-graph.png +0 -0
  184. package/docs/assets/v3.4.0/local-agent.png +0 -0
  185. package/docs/assets/v3.4.0/memory.png +0 -0
  186. package/docs/assets/v3.4.0/settings.png +0 -0
  187. package/docs/assets/v3.4.0/vision-input.png +0 -0
  188. package/docs/assets/v3.4.0/workflows.png +0 -0
  189. package/docs/assets/v3.4.1/e2e_runtime_log.txt +0 -42
  190. package/docs/assets/v3.4.1/hooks-dispatch.png +0 -0
  191. package/docs/assets/v3.4.1/local-agent.png +0 -0
  192. package/docs/images/admin-dashboard.png +0 -0
  193. package/docs/images/architecture.png +0 -0
  194. package/docs/images/enterprise.png +0 -0
  195. package/docs/images/graph.png +0 -0
  196. package/docs/images/hero.gif +0 -0
  197. package/docs/images/knowledge-graph.png +0 -0
  198. package/docs/images/lattice-ai-demo.gif +0 -0
  199. package/docs/images/lattice-ai-hero.png +0 -0
  200. package/docs/images/logo.svg +0 -33
  201. package/docs/images/mobile-responsive.png +0 -0
  202. package/docs/images/model-recommendation.png +0 -0
  203. package/docs/images/onboarding.png +0 -0
  204. package/docs/images/organization.png +0 -0
  205. package/docs/images/pipeline.png +0 -0
  206. package/docs/images/screenshot-admin.png +0 -0
  207. package/docs/images/screenshot-chat.png +0 -0
  208. package/docs/images/screenshot-graph.png +0 -0
  209. package/docs/images/skills.png +0 -0
  210. package/docs/images/workspace-dark.png +0 -0
  211. package/docs/images/workspace-light.png +0 -0
  212. package/docs/images/workspace.png +0 -0
  213. package/requirements.txt +0 -16
  214. package/static/account.html +0 -115
  215. package/static/activity.html +0 -73
  216. package/static/admin.html +0 -488
  217. package/static/agents.html +0 -139
  218. package/static/chat.html +0 -844
  219. package/static/css/reference/account.css +0 -439
  220. package/static/css/reference/admin.css +0 -610
  221. package/static/css/reference/base.css +0 -1661
  222. package/static/css/reference/chat.css +0 -4623
  223. package/static/css/reference/graph.css +0 -1016
  224. package/static/css/responsive.css +0 -861
  225. package/static/graph.html +0 -124
  226. package/static/platform.css +0 -104
  227. package/static/plugins.html +0 -136
  228. package/static/scripts/account.js +0 -238
  229. package/static/scripts/admin.js +0 -1614
  230. package/static/scripts/chat.js +0 -5081
  231. package/static/scripts/graph.js +0 -1804
  232. package/static/scripts/platform.js +0 -64
  233. package/static/scripts/ux.js +0 -167
  234. package/static/scripts/workspace.js +0 -948
  235. package/static/v3/js/core/routes.2ce3815a.js +0 -93
  236. package/static/workflows.html +0 -146
  237. package/static/workspace.css +0 -1121
  238. package/static/workspace.html +0 -357
@@ -0,0 +1,135 @@
1
+ import { t } from "../core/i18n.js";
2
+
3
+ export async function render(ctx) {
4
+ const { h, icon, api, c, toast } = ctx;
5
+ const host = h("div.lt3-stack-6", c.loading({ lines: 5, block: true }));
6
+
7
+ async function load() {
8
+ const [snaps, timeline] = await Promise.all([api.snapshots(), api.timeMachine(80)]);
9
+ const rows = normalize(snaps.data);
10
+ host.replaceChildren(
11
+ c.viewHeader({
12
+ eyebrow: t("snapshots.eyebrow"),
13
+ title: t("snapshots.title"),
14
+ sub: t("snapshots.sub"),
15
+ actions: [c.sourceBadge(snaps.source)],
16
+ }),
17
+ createPanel(),
18
+ comparePanel(rows),
19
+ snapshotTable(rows),
20
+ timelinePanel(timeline),
21
+ );
22
+ }
23
+
24
+ function createPanel() {
25
+ const name = h("input.lt3-input", { type: "text", placeholder: t("snapshots.name"), "aria-label": t("snapshots.name") });
26
+ return c.panel({
27
+ title: t("snapshots.create"),
28
+ children: h("div.lt3-row-2",
29
+ name,
30
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: async () => {
31
+ const res = await api.createSnapshot(name.value.trim() || t("snapshots.title"));
32
+ toast(resultText(res, t("snapshots.created")), res.ok ? "ok" : "err");
33
+ if (res.ok) { name.value = ""; load(); }
34
+ } } }, icon("camera"), t("snapshots.create")),
35
+ ),
36
+ });
37
+ }
38
+
39
+ function comparePanel(rows) {
40
+ const before = select(rows);
41
+ const after = select(rows);
42
+ const result = h("div");
43
+ return c.panel({
44
+ title: t("snapshots.compare"),
45
+ children: h("div.lt3-stack-4",
46
+ h("div.lt3-row-2", before, after, h("button.lt3-btn.lt3-btn--primary", { on: { click: async () => {
47
+ if (!before.value || !after.value) return;
48
+ result.replaceChildren(c.loading({ lines: 2 }));
49
+ const res = await api.compareSnapshots(before.value, after.value);
50
+ const d = res.data || {};
51
+ result.replaceChildren(res.ok
52
+ ? h("dl.lt3-keyval",
53
+ h("dt", "nodes_added"), h("dd", String(d.summary?.nodes_added ?? 0)),
54
+ h("dt", "nodes_removed"), h("dd", String(d.summary?.nodes_removed ?? 0)),
55
+ h("dt", "edges_added"), h("dd", String(d.summary?.edges_added ?? 0)),
56
+ h("dt", "edges_removed"), h("dd", String(d.summary?.edges_removed ?? 0)),
57
+ )
58
+ : c.banner(resultText(res, t("common.unavailable")), "err"));
59
+ } } }, icon("git-compare"), t("snapshots.compare"))),
60
+ result,
61
+ ),
62
+ });
63
+ }
64
+
65
+ function snapshotTable(rows) {
66
+ if (!rows.length) return c.emptyState({ icon: "history", title: t("snapshots.title"), body: t("common.none") });
67
+ return c.panel({
68
+ title: t("snapshots.title"),
69
+ children: c.table([
70
+ { key: "name", label: t("common.name"), render: (r) => h("div", h("b", r.name || r.id), h("div.lt3-faint", { style: { "font-family": "var(--lt3-font-mono)", "font-size": "var(--lt3-text-2xs)" } }, r.id)) },
71
+ { key: "created", label: t("common.created"), width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap" } }, fmt(r.created_at)) },
72
+ { key: "nodes", label: "nodes", width: "1%", render: (r) => String(r.node_count ?? 0) },
73
+ { key: "edges", label: "edges", width: "1%", render: (r) => String(r.edge_count ?? 0) },
74
+ { key: "actions", label: "", width: "1%", render: (r) => h("div.lt3-row-2",
75
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => exportSnapshot(r.id) } }, icon("download"), t("snapshots.export")),
76
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => restoreSnapshot(r.id) } }, icon("restore"), t("snapshots.restore")),
77
+ ) },
78
+ ], rows),
79
+ });
80
+ }
81
+
82
+ function timelinePanel(res) {
83
+ const events = Array.isArray(res.data?.events) ? res.data.events : [];
84
+ return c.panel({
85
+ title: t("snapshots.timeline"),
86
+ actions: [c.sourceBadge(res.source)],
87
+ children: events.length ? c.table([
88
+ { key: "event", label: t("common.status"), render: (e) => h("span", e.event_type || e.area || "event") },
89
+ { key: "area", label: t("common.type"), width: "1%", render: (e) => c.pill(e.area || "workspace") },
90
+ { key: "when", label: t("common.created"), width: "1%", render: (e) => h("span.lt3-faint", { style: { "white-space": "nowrap" } }, fmt(e.timestamp)) },
91
+ ], events.slice(0, 40)) : c.emptyState({ icon: "history-off", title: t("snapshots.timeline"), body: t("common.none") }),
92
+ });
93
+ }
94
+
95
+ async function exportSnapshot(id) {
96
+ const res = await api.snapshotExport(id);
97
+ toast(resultText(res, res.data?.export_path || t("snapshots.export")), res.ok ? "ok" : "err");
98
+ }
99
+ async function restoreSnapshot(id) {
100
+ const res = await api.snapshotRestore(id);
101
+ toast(resultText(res, t("snapshots.restored")), res.ok ? "ok" : "err");
102
+ if (res.ok) load();
103
+ }
104
+
105
+ await load();
106
+ return host;
107
+ }
108
+
109
+ function select(rows) {
110
+ const sel = document.createElement("select");
111
+ sel.className = "lt3-select";
112
+ sel.setAttribute("aria-label", t("snapshots.title"));
113
+ for (const row of rows) {
114
+ const opt = document.createElement("option");
115
+ opt.value = row.id;
116
+ opt.textContent = row.name || row.id;
117
+ sel.append(opt);
118
+ }
119
+ return sel;
120
+ }
121
+
122
+ function normalize(data) {
123
+ return Array.isArray(data?.snapshots) ? data.snapshots : [];
124
+ }
125
+
126
+ function fmt(ts) {
127
+ if (!ts) return "—";
128
+ try { return new Date(ts).toLocaleString(); } catch { return String(ts); }
129
+ }
130
+
131
+ function resultText(res, okText) {
132
+ if (res && res.ok) return okText;
133
+ const data = (res && res.data) || {};
134
+ return String(data.detail || data.error || res?.error || t("common.unavailable"));
135
+ }
@@ -11,6 +11,7 @@ export async function render(ctx) {
11
11
  const { h, c } = ctx;
12
12
  const defsHost = h("div", c.loading({ lines: 3, block: true }));
13
13
  const runsHost = h("div", c.loading({ lines: 3 }));
14
+ const triggerHost = h("div", c.loading({ lines: 2 }));
14
15
  const defsSrc = h("span", c.sourceBadge("pending"));
15
16
  const runsSrc = h("span", c.sourceBadge("pending"));
16
17
 
@@ -21,6 +22,12 @@ export async function render(ctx) {
21
22
  sub: "Repeatable automation: a trigger fires an agent chain that calls tools, reads and writes memory, and produces a result.",
22
23
  }),
23
24
  stageLegend(ctx),
25
+ c.panel({
26
+ eyebrow: "Triggers",
27
+ title: "Trigger status",
28
+ sub: "Interval and brain-event triggers armed from saved workflow definitions.",
29
+ children: triggerHost,
30
+ }),
24
31
  h("section", c.sectionHead("Workflow definitions", defsSrc), defsHost),
25
32
  c.panel({
26
33
  head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
@@ -30,6 +37,7 @@ export async function render(ctx) {
30
37
  );
31
38
 
32
39
  loadDefs();
40
+ loadTriggers();
33
41
  loadRuns();
34
42
  return root;
35
43
 
@@ -59,6 +67,7 @@ export async function render(ctx) {
59
67
  ),
60
68
  w.description ? h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, w.description) : null,
61
69
  h("div.lt3-cluster", (nodes.slice(0, 6)).map((n) => h("span.lt3-chip", c.icon(nodeIcon(n.type)), n.name || n.type))),
70
+ triggerControls(ctx2, w, nodes),
62
71
  h("div.lt3-row-2",
63
72
  h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => runDef(ctx2, w) } }, c.icon("player-play"), "Run"),
64
73
  h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${triggers} trigger${triggers === 1 ? "" : "s"}`),
@@ -85,7 +94,13 @@ export async function render(ctx) {
85
94
  { key: "status", label: "Status", width: "1%", render: (r) => c.statePill(mapStatus(r.status)) },
86
95
  { key: "name", label: "Workflow", render: (r) => h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, r.workflow_name || r.workflow_id || r.id) },
87
96
  { key: "when", label: "When", width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap", "font-size": "var(--lt3-text-2xs)" } }, fmtTime(r.created_at || r.started_at)) },
88
- { key: "act", label: "", width: "1%", render: (r) => h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => replay(ctx, r) } }, c.icon("player-track-next"), "Replay") },
97
+ { key: "act", label: "", width: "1%", render: (r) => h("div.lt3-row-2",
98
+ isActiveStatus(r.status) ? h("button.lt3-btn.lt3-btn--danger.lt3-btn--sm", { on: { click: () => stop(ctx, r) } }, c.icon("player-stop"), "Stop") : null,
99
+ String(r.status || "").toLowerCase() === "awaiting_approval"
100
+ ? h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => decide(ctx, r, true) } }, c.icon("circle-check"), "Approve")
101
+ : null,
102
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => replay(ctx, r) } }, c.icon("player-track-next"), "Replay"),
103
+ ) },
89
104
  ],
90
105
  runs.slice(0, 20),
91
106
  ));
@@ -96,6 +111,71 @@ export async function render(ctx) {
96
111
  const res = await ctx2.api.workflowReplay(id);
97
112
  ctx2.toast(res && res.ok ? `Replay ready for ${id}` : "Replay unavailable", res && res.ok ? "ok" : "err");
98
113
  }
114
+
115
+ async function stop(ctx2, r) {
116
+ const id = r.id || r.run_id;
117
+ const res = await ctx2.api.stopWorkflowRun(id);
118
+ ctx2.toast(res && res.ok ? `Stop requested for ${id}` : "Stop unavailable", res && res.ok ? "ok" : "err");
119
+ loadRuns();
120
+ }
121
+
122
+ async function decide(ctx2, r, approved) {
123
+ const id = r.id || r.run_id;
124
+ const res = await ctx2.api.resumeWorkflowRun(id, approved);
125
+ ctx2.toast(res && res.ok ? `Decision recorded for ${id}` : "Decision unavailable", res && res.ok ? "ok" : "err");
126
+ loadRuns();
127
+ }
128
+
129
+ async function loadTriggers() {
130
+ const res = await ctx.api.workflowTriggers();
131
+ const armed = Array.isArray(res.data?.armed) ? res.data.armed : [];
132
+ triggerHost.replaceChildren(
133
+ h("div.lt3-stack-3",
134
+ h("div.lt3-row-2", c.sourceBadge(res.source), c.statePill(res.data?.running ? "running" : "idle")),
135
+ armed.length ? c.table([
136
+ { key: "name", label: "Workflow", render: (r) => h("b", r.name || r.workflow_id) },
137
+ { key: "kind", label: "Trigger", width: "1%", render: (r) => c.pill(r.kind) },
138
+ { key: "last", label: "Last fired", width: "1%", render: (r) => fmtTime(r.last_fired_at ? Number(r.last_fired_at) * 1000 : null) },
139
+ { key: "events", label: "Recent", render: (r) => (r.recent_events || []).slice(-2).map((e) => e.type || e.trigger).join(", ") || "—" },
140
+ ], armed) : c.emptyState({ icon: "bolt-off", title: "No triggers armed", body: "Set a workflow trigger below to arm it." }),
141
+ ),
142
+ );
143
+ }
144
+
145
+ function triggerControls(ctx2, w, nodes) {
146
+ const trigger = nodes.find((n) => n.type === "trigger") || {};
147
+ const cfg = trigger.config || {};
148
+ const kind = h("select.lt3-select", { "aria-label": "Trigger type" },
149
+ ["manual", "interval", "brain_event"].map((value) => h("option", { value, selected: String(cfg.trigger || "manual") === value }, value)));
150
+ const seconds = h("input.lt3-input", { type: "number", min: "60", step: "60", value: String(cfg.interval_seconds || 300), "aria-label": "Interval seconds" });
151
+ const sourceType = h("input.lt3-input", { type: "text", value: cfg.source_type || "", placeholder: "source_type", "aria-label": "source_type" });
152
+ async function save() {
153
+ const updated = ensureTrigger(nodes, kind.value, Number(seconds.value) || 300, sourceType.value.trim());
154
+ const res = await ctx2.api.updateWorkflow(w.id, { nodes: updated, metadata: { trigger_updated_at: new Date().toISOString() } });
155
+ ctx2.toast(res && res.ok ? "Trigger saved" : "Trigger update unavailable", res && res.ok ? "ok" : "err");
156
+ if (res && res.ok) { loadDefs(); loadTriggers(); }
157
+ }
158
+ return h("div.lt3-stack-2",
159
+ h("div.lt3-eyebrow", "Trigger configuration"),
160
+ h("div.lt3-row-2", kind, seconds, sourceType, h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: save } }, c.icon("device-floppy"), "Save")),
161
+ );
162
+ }
163
+ }
164
+
165
+ function ensureTrigger(nodes, triggerKind, intervalSeconds, sourceType) {
166
+ const clone = (nodes || []).map((node) => ({ ...node, config: { ...(node.config || {}) } }));
167
+ let trigger = clone.find((n) => n.type === "trigger");
168
+ if (!trigger) {
169
+ trigger = { id: "trigger", type: "trigger", name: "Trigger", next: clone[0]?.id || "output", config: {} };
170
+ clone.unshift(trigger);
171
+ if (!clone.some((n) => n.id === "output")) clone.push({ id: "output", type: "output", name: "Output", config: {}, next: null });
172
+ }
173
+ trigger.config.trigger = triggerKind;
174
+ delete trigger.config.interval_seconds;
175
+ delete trigger.config.source_type;
176
+ if (triggerKind === "interval") trigger.config.interval_seconds = Math.max(60, intervalSeconds || 300);
177
+ if (triggerKind === "brain_event" && sourceType) trigger.config.source_type = sourceType;
178
+ return clone;
99
179
  }
100
180
 
101
181
  function normalizeDefs(data) {
@@ -118,9 +198,14 @@ function mapStatus(s) {
118
198
  const v = String(s || "").toLowerCase();
119
199
  if (v === "ok" || v === "completed" || v === "success") return "ready";
120
200
  if (v === "failed" || v === "error") return "failed";
121
- if (v === "running") return "active";
201
+ if (v === "running" || v === "queued" || v === "cancelling") return "active";
202
+ if (v === "awaiting_approval") return "pending";
203
+ if (v === "cancelled" || v === "interrupted") return "warn";
122
204
  return v || "idle";
123
205
  }
206
+ function isActiveStatus(status) {
207
+ return ["running", "queued", "in_progress", "cancelling"].includes(String(status || "").toLowerCase());
208
+ }
124
209
  function fmtTime(ts) {
125
210
  if (!ts) return "—";
126
211
  try { const d = new Date(ts); return Number.isNaN(d.getTime()) ? String(ts) : d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }); }
@@ -11,6 +11,7 @@ export async function render(ctx) {
11
11
  const { h, c } = ctx;
12
12
  const defsHost = h("div", c.loading({ lines: 3, block: true }));
13
13
  const runsHost = h("div", c.loading({ lines: 3 }));
14
+ const triggerHost = h("div", c.loading({ lines: 2 }));
14
15
  const defsSrc = h("span", c.sourceBadge("pending"));
15
16
  const runsSrc = h("span", c.sourceBadge("pending"));
16
17
 
@@ -21,6 +22,12 @@ export async function render(ctx) {
21
22
  sub: "Repeatable automation: a trigger fires an agent chain that calls tools, reads and writes memory, and produces a result.",
22
23
  }),
23
24
  stageLegend(ctx),
25
+ c.panel({
26
+ eyebrow: "Triggers",
27
+ title: "Trigger status",
28
+ sub: "Interval and brain-event triggers armed from saved workflow definitions.",
29
+ children: triggerHost,
30
+ }),
24
31
  h("section", c.sectionHead("Workflow definitions", defsSrc), defsHost),
25
32
  c.panel({
26
33
  head: h("div.lt3-row", { style: { "justify-content": "space-between", width: "100%" } },
@@ -30,6 +37,7 @@ export async function render(ctx) {
30
37
  );
31
38
 
32
39
  loadDefs();
40
+ loadTriggers();
33
41
  loadRuns();
34
42
  return root;
35
43
 
@@ -59,6 +67,7 @@ export async function render(ctx) {
59
67
  ),
60
68
  w.description ? h("p.lt3-muted", { style: { margin: 0, "font-size": "var(--lt3-text-sm)" } }, w.description) : null,
61
69
  h("div.lt3-cluster", (nodes.slice(0, 6)).map((n) => h("span.lt3-chip", c.icon(nodeIcon(n.type)), n.name || n.type))),
70
+ triggerControls(ctx2, w, nodes),
62
71
  h("div.lt3-row-2",
63
72
  h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => runDef(ctx2, w) } }, c.icon("player-play"), "Run"),
64
73
  h("span.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)" } }, `${triggers} trigger${triggers === 1 ? "" : "s"}`),
@@ -85,7 +94,13 @@ export async function render(ctx) {
85
94
  { key: "status", label: "Status", width: "1%", render: (r) => c.statePill(mapStatus(r.status)) },
86
95
  { key: "name", label: "Workflow", render: (r) => h("b", { style: { "font-size": "var(--lt3-text-sm)" } }, r.workflow_name || r.workflow_id || r.id) },
87
96
  { key: "when", label: "When", width: "1%", render: (r) => h("span.lt3-faint", { style: { "white-space": "nowrap", "font-size": "var(--lt3-text-2xs)" } }, fmtTime(r.created_at || r.started_at)) },
88
- { key: "act", label: "", width: "1%", render: (r) => h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => replay(ctx, r) } }, c.icon("player-track-next"), "Replay") },
97
+ { key: "act", label: "", width: "1%", render: (r) => h("div.lt3-row-2",
98
+ isActiveStatus(r.status) ? h("button.lt3-btn.lt3-btn--danger.lt3-btn--sm", { on: { click: () => stop(ctx, r) } }, c.icon("player-stop"), "Stop") : null,
99
+ String(r.status || "").toLowerCase() === "awaiting_approval"
100
+ ? h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => decide(ctx, r, true) } }, c.icon("circle-check"), "Approve")
101
+ : null,
102
+ h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => replay(ctx, r) } }, c.icon("player-track-next"), "Replay"),
103
+ ) },
89
104
  ],
90
105
  runs.slice(0, 20),
91
106
  ));
@@ -96,6 +111,71 @@ export async function render(ctx) {
96
111
  const res = await ctx2.api.workflowReplay(id);
97
112
  ctx2.toast(res && res.ok ? `Replay ready for ${id}` : "Replay unavailable", res && res.ok ? "ok" : "err");
98
113
  }
114
+
115
+ async function stop(ctx2, r) {
116
+ const id = r.id || r.run_id;
117
+ const res = await ctx2.api.stopWorkflowRun(id);
118
+ ctx2.toast(res && res.ok ? `Stop requested for ${id}` : "Stop unavailable", res && res.ok ? "ok" : "err");
119
+ loadRuns();
120
+ }
121
+
122
+ async function decide(ctx2, r, approved) {
123
+ const id = r.id || r.run_id;
124
+ const res = await ctx2.api.resumeWorkflowRun(id, approved);
125
+ ctx2.toast(res && res.ok ? `Decision recorded for ${id}` : "Decision unavailable", res && res.ok ? "ok" : "err");
126
+ loadRuns();
127
+ }
128
+
129
+ async function loadTriggers() {
130
+ const res = await ctx.api.workflowTriggers();
131
+ const armed = Array.isArray(res.data?.armed) ? res.data.armed : [];
132
+ triggerHost.replaceChildren(
133
+ h("div.lt3-stack-3",
134
+ h("div.lt3-row-2", c.sourceBadge(res.source), c.statePill(res.data?.running ? "running" : "idle")),
135
+ armed.length ? c.table([
136
+ { key: "name", label: "Workflow", render: (r) => h("b", r.name || r.workflow_id) },
137
+ { key: "kind", label: "Trigger", width: "1%", render: (r) => c.pill(r.kind) },
138
+ { key: "last", label: "Last fired", width: "1%", render: (r) => fmtTime(r.last_fired_at ? Number(r.last_fired_at) * 1000 : null) },
139
+ { key: "events", label: "Recent", render: (r) => (r.recent_events || []).slice(-2).map((e) => e.type || e.trigger).join(", ") || "—" },
140
+ ], armed) : c.emptyState({ icon: "bolt-off", title: "No triggers armed", body: "Set a workflow trigger below to arm it." }),
141
+ ),
142
+ );
143
+ }
144
+
145
+ function triggerControls(ctx2, w, nodes) {
146
+ const trigger = nodes.find((n) => n.type === "trigger") || {};
147
+ const cfg = trigger.config || {};
148
+ const kind = h("select.lt3-select", { "aria-label": "Trigger type" },
149
+ ["manual", "interval", "brain_event"].map((value) => h("option", { value, selected: String(cfg.trigger || "manual") === value }, value)));
150
+ const seconds = h("input.lt3-input", { type: "number", min: "60", step: "60", value: String(cfg.interval_seconds || 300), "aria-label": "Interval seconds" });
151
+ const sourceType = h("input.lt3-input", { type: "text", value: cfg.source_type || "", placeholder: "source_type", "aria-label": "source_type" });
152
+ async function save() {
153
+ const updated = ensureTrigger(nodes, kind.value, Number(seconds.value) || 300, sourceType.value.trim());
154
+ const res = await ctx2.api.updateWorkflow(w.id, { nodes: updated, metadata: { trigger_updated_at: new Date().toISOString() } });
155
+ ctx2.toast(res && res.ok ? "Trigger saved" : "Trigger update unavailable", res && res.ok ? "ok" : "err");
156
+ if (res && res.ok) { loadDefs(); loadTriggers(); }
157
+ }
158
+ return h("div.lt3-stack-2",
159
+ h("div.lt3-eyebrow", "Trigger configuration"),
160
+ h("div.lt3-row-2", kind, seconds, sourceType, h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: save } }, c.icon("device-floppy"), "Save")),
161
+ );
162
+ }
163
+ }
164
+
165
+ function ensureTrigger(nodes, triggerKind, intervalSeconds, sourceType) {
166
+ const clone = (nodes || []).map((node) => ({ ...node, config: { ...(node.config || {}) } }));
167
+ let trigger = clone.find((n) => n.type === "trigger");
168
+ if (!trigger) {
169
+ trigger = { id: "trigger", type: "trigger", name: "Trigger", next: clone[0]?.id || "output", config: {} };
170
+ clone.unshift(trigger);
171
+ if (!clone.some((n) => n.id === "output")) clone.push({ id: "output", type: "output", name: "Output", config: {}, next: null });
172
+ }
173
+ trigger.config.trigger = triggerKind;
174
+ delete trigger.config.interval_seconds;
175
+ delete trigger.config.source_type;
176
+ if (triggerKind === "interval") trigger.config.interval_seconds = Math.max(60, intervalSeconds || 300);
177
+ if (triggerKind === "brain_event" && sourceType) trigger.config.source_type = sourceType;
178
+ return clone;
99
179
  }
100
180
 
101
181
  function normalizeDefs(data) {
@@ -118,9 +198,14 @@ function mapStatus(s) {
118
198
  const v = String(s || "").toLowerCase();
119
199
  if (v === "ok" || v === "completed" || v === "success") return "ready";
120
200
  if (v === "failed" || v === "error") return "failed";
121
- if (v === "running") return "active";
201
+ if (v === "running" || v === "queued" || v === "cancelling") return "active";
202
+ if (v === "awaiting_approval") return "pending";
203
+ if (v === "cancelled" || v === "interrupted") return "warn";
122
204
  return v || "idle";
123
205
  }
206
+ function isActiveStatus(status) {
207
+ return ["running", "queued", "in_progress", "cancelling"].includes(String(status || "").toLowerCase());
208
+ }
124
209
  function fmtTime(ts) {
125
210
  if (!ts) return "—";
126
211
  try { const d = new Date(ts); return Number.isNaN(d.getTime()) ? String(ts) : d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }); }
@@ -0,0 +1,156 @@
1
+ import { t } from "../core/i18n.880e1fec.js";
2
+
3
+ export async function render(ctx) {
4
+ const { h, icon, api, store, c, toast } = ctx;
5
+ const host = h("div.lt3-stack-6", c.loading({ lines: 5, block: true }));
6
+
7
+ async function load() {
8
+ const [registry, invites] = await Promise.all([api.workspaceRegistry(), api.invitations()]);
9
+ const data = registry.data || {};
10
+ const workspaces = Array.isArray(data.workspaces) ? data.workspaces : [];
11
+ store.setWorkspaces(workspaces.length ? workspaces : store.get().workspaces);
12
+ host.replaceChildren(
13
+ c.viewHeader({
14
+ eyebrow: t("workspace.eyebrow"),
15
+ title: t("workspace.title"),
16
+ sub: t("workspace.sub"),
17
+ actions: [c.sourceBadge(registry.source)],
18
+ }),
19
+ createOrgPanel(),
20
+ workspaceGrid(workspaces, data),
21
+ invitationsPanel(invites),
22
+ );
23
+ }
24
+
25
+ function createOrgPanel() {
26
+ const name = h("input.lt3-input", { type: "text", "aria-label": t("workspace.orgName"), placeholder: t("workspace.orgName") });
27
+ return c.panel({
28
+ title: t("workspace.createOrg"),
29
+ children: h("div.lt3-row-2",
30
+ name,
31
+ h("button.lt3-btn.lt3-btn--primary", { on: { click: async () => {
32
+ if (!name.value.trim()) return;
33
+ const res = await api.createOrg(name.value.trim());
34
+ toast(resultText(res, t("workspace.createOrg")), res.ok ? "ok" : "err");
35
+ if (res.ok) { name.value = ""; load(); }
36
+ } } }, icon("plus"), t("workspace.createOrg")),
37
+ ),
38
+ });
39
+ }
40
+
41
+ function workspaceGrid(workspaces, registry) {
42
+ if (!workspaces.length) {
43
+ return c.emptyState({ icon: "building-community", title: t("workspace.title"), body: t("common.unavailable") });
44
+ }
45
+ return h("div.lt3-grid-auto", workspaces.map((ws) => workspaceCard(ws, registry)));
46
+ }
47
+
48
+ function workspaceCard(ws, registry) {
49
+ const roleOptions = registry.roles || ["owner", "admin", "member", "viewer"];
50
+ const members = Array.isArray(ws.members) ? ws.members : [];
51
+ const userId = h("input.lt3-input", { type: "text", placeholder: t("workspace.userId"), "aria-label": t("workspace.userId") });
52
+ const role = h("select.lt3-select", { "aria-label": t("common.role") }, roleOptions.map((r) => h("option", { value: r }, roleLabel(r))));
53
+ return c.card(h("div.lt3-stack-4",
54
+ h("div.lt3-row", { style: { "justify-content": "space-between", "align-items": "flex-start", gap: "var(--lt3-space-3)" } },
55
+ h("div",
56
+ h("b", ws.name || ws.workspace_id),
57
+ h("div.lt3-faint", { style: { "font-size": "var(--lt3-text-2xs)", "font-family": "var(--lt3-font-mono)" } }, ws.workspace_id),
58
+ ),
59
+ c.pill(roleLabel(ws.your_role || "member"), "info"),
60
+ ),
61
+ h("dl.lt3-keyval",
62
+ h("dt", t("common.type")), h("dd", ws.type || "—"),
63
+ h("dt", t("common.status")), h("dd", c.statePill(ws.status || "active")),
64
+ h("dt", t("workspace.members")), h("dd", String(ws.member_count ?? members.length)),
65
+ ),
66
+ h("div.lt3-row-2",
67
+ h("button.lt3-btn.lt3-btn--subtle.lt3-btn--sm", { on: { click: () => activate(ws.workspace_id) } }, icon("selector"), t("workspace.activate")),
68
+ ws.type === "organization" ? h("button.lt3-btn.lt3-btn--ghost.lt3-btn--sm", { on: { click: () => archive(ws.workspace_id) } }, icon("archive"), t("workspace.archive")) : null,
69
+ ),
70
+ ws.type === "organization" ? h("div.lt3-stack-3",
71
+ h("div.lt3-eyebrow", t("workspace.members")),
72
+ members.length ? c.table([
73
+ { key: "user", label: t("workspace.userId"), render: (m) => h("span.lt3-mono", m.user_id || "—") },
74
+ { key: "role", label: t("common.role"), width: "1%", render: (m) => c.pill(roleLabel(m.role)) },
75
+ { key: "act", label: "", width: "1%", render: (m) => h("button.lt3-iconbtn.lt3-iconbtn--sm", { "aria-label": t("common.cancel"), on: { click: () => removeMember(ws.workspace_id, m.user_id) } }, icon("trash")) },
76
+ ], members) : c.emptyState({ icon: "users", title: t("workspace.members"), body: t("common.none") }),
77
+ h("div.lt3-row-2", userId, role, h("button.lt3-btn.lt3-btn--primary.lt3-btn--sm", { on: { click: () => addMember(ws.workspace_id, userId.value.trim(), role.value) } }, icon("user-plus"), t("workspace.addMember"))),
78
+ ) : null,
79
+ ), { interactive: false });
80
+ }
81
+
82
+ function invitationsPanel(invites) {
83
+ const rows = Array.isArray(invites.data?.invitations) ? invites.data.invitations : [];
84
+ const email = h("input.lt3-input", { type: "email", placeholder: t("workspace.inviteEmail"), "aria-label": t("workspace.inviteEmail") });
85
+ const workspace = h("input.lt3-input", { type: "text", placeholder: "workspace_id", "aria-label": "workspace_id", value: store.get().workspaceId || "personal" });
86
+ const role = h("select.lt3-select", { "aria-label": t("common.role") },
87
+ ["member", "viewer", "admin"].map((r) => h("option", { value: r }, roleLabel(r))));
88
+ const token = h("input.lt3-input", { type: "text", placeholder: t("workspace.inviteToken"), "aria-label": t("workspace.inviteToken") });
89
+
90
+ return c.panel({
91
+ title: t("workspace.invitations"),
92
+ actions: [c.sourceBadge(invites.source)],
93
+ children: h("div.lt3-stack-4",
94
+ h("div.lt3-grid-2",
95
+ h("div.lt3-field", h("label.lt3-label", t("workspace.inviteEmail")), email),
96
+ h("div.lt3-field", h("label.lt3-label", "workspace_id"), workspace),
97
+ ),
98
+ h("div.lt3-row-2", role, h("button.lt3-btn.lt3-btn--primary", { on: { click: () => createInvite(email.value.trim(), workspace.value.trim(), role.value) } }, icon("mail-plus"), t("workspace.invitations"))),
99
+ rows.length ? c.table([
100
+ { key: "email", label: t("account.email"), render: (r) => r.email || "—" },
101
+ { key: "role", label: t("common.role"), width: "1%", render: (r) => c.pill(roleLabel(r.role)) },
102
+ { key: "token", label: t("workspace.inviteToken"), render: (r) => h("span.lt3-mono", r.token || r.id || "—") },
103
+ { key: "status", label: t("common.status"), width: "1%", render: (r) => c.statePill(r.status || (r.accepted_at ? "ready" : "pending")) },
104
+ ], rows.slice(0, 20)) : c.emptyState({ icon: "mail", title: t("workspace.invitations"), body: t("common.none") }),
105
+ h("hr.lt3-divider"),
106
+ h("div.lt3-row-2", token, h("button.lt3-btn.lt3-btn--ghost", { on: { click: () => acceptInvite(token.value.trim()) } }, icon("circle-check"), t("workspace.acceptInvite"))),
107
+ ),
108
+ });
109
+ }
110
+
111
+ async function activate(workspace_id) {
112
+ const res = await api.activateWorkspace(workspace_id);
113
+ toast(resultText(res, t("workspace.activated")), res.ok ? "ok" : "err");
114
+ if (res.ok) { store.setWorkspace(workspace_id); load(); }
115
+ }
116
+ async function archive(workspace_id) {
117
+ const res = await api.archiveWorkspace(workspace_id);
118
+ toast(resultText(res, t("workspace.archived")), res.ok ? "ok" : "err");
119
+ if (res.ok) load();
120
+ }
121
+ async function addMember(workspace_id, user_id, role) {
122
+ if (!user_id) return;
123
+ const res = await api.addWorkspaceMember(workspace_id, user_id, role);
124
+ toast(resultText(res, t("workspace.memberAdded")), res.ok ? "ok" : "err");
125
+ if (res.ok) load();
126
+ }
127
+ async function removeMember(workspace_id, user_id) {
128
+ const res = await api.removeWorkspaceMember(workspace_id, user_id);
129
+ toast(resultText(res, t("workspace.memberAdded")), res.ok ? "ok" : "err");
130
+ if (res.ok) load();
131
+ }
132
+ async function createInvite(email, workspace_id, role) {
133
+ const res = await api.createInvitation({ email: email || null, workspace_id: workspace_id || null, role, expires_hours: 168 });
134
+ toast(resultText(res, t("workspace.inviteCreated")), res.ok ? "ok" : "err");
135
+ if (res.ok) load();
136
+ }
137
+ async function acceptInvite(token) {
138
+ if (!token) return;
139
+ const res = await api.acceptInvitation(token);
140
+ toast(resultText(res, t("workspace.inviteAccepted")), res.ok ? "ok" : "err");
141
+ if (res.ok) load();
142
+ }
143
+
144
+ await load();
145
+ return host;
146
+ }
147
+
148
+ function roleLabel(role) {
149
+ return t(`common.${String(role || "member")}`) || String(role || "member");
150
+ }
151
+
152
+ function resultText(res, okText) {
153
+ if (res && res.ok) return okText;
154
+ const data = (res && res.data) || {};
155
+ return String(data.detail || data.error || res?.error || t("common.unavailable"));
156
+ }