@feltdb/core 0.7.4 → 0.8.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 (106) hide show
  1. package/README.md +25 -0
  2. package/dist/application-development.d.ts +3 -1
  3. package/dist/application-development.d.ts.map +1 -1
  4. package/dist/application-development.js +16 -0
  5. package/dist/application-manifest.d.ts +1 -0
  6. package/dist/application-manifest.d.ts.map +1 -1
  7. package/dist/canonical-application.d.ts +1 -0
  8. package/dist/canonical-application.d.ts.map +1 -1
  9. package/dist/canonical-application.js +3 -2
  10. package/dist/cli/cli.js +1 -1
  11. package/dist/cli/commands.js +225 -42
  12. package/dist/cli/index.js +1 -1
  13. package/dist/cli/managed-environment.js +6 -0
  14. package/dist/cli/managed-project.js +6 -0
  15. package/dist/cli/proposal-client.js +12 -3
  16. package/dist/cli/publish-engine.js +7 -4
  17. package/dist/cli/source-sync.js +47 -3
  18. package/dist/create/cli.js +10 -1
  19. package/dist/create/create.js +10 -12
  20. package/dist/create/managed-account.js +71 -7
  21. package/dist/create/package-versions.js +1 -1
  22. package/dist/create/server-source/crates/feltdb/src/application.rs +10 -0
  23. package/dist/create/server-source/crates/feltdb/src/lib.rs +20 -2
  24. package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +12 -24
  25. package/dist/create/server-source/crates/feltdb-server/src/application_contract.rs +11 -3
  26. package/dist/create/server-source/crates/feltdb-server/src/authenticated_principal.rs +0 -1
  27. package/dist/create/server-source/crates/feltdb-server/src/certification_harness.rs +23 -22
  28. package/dist/create/server-source/crates/feltdb-server/src/delegation_token.rs +5 -15
  29. package/dist/create/server-source/crates/feltdb-server/src/durable_operations.rs +13 -28
  30. package/dist/create/server-source/crates/feltdb-server/src/identity.rs +79 -14
  31. package/dist/create/server-source/crates/feltdb-server/src/key_management.rs +28 -7
  32. package/dist/create/server-source/crates/feltdb-server/src/lib.rs +5 -5
  33. package/dist/create/server-source/crates/feltdb-server/src/main.rs +1777 -259
  34. package/dist/create/server-source/crates/feltdb-server/src/managed_diagnostics.rs +10 -30
  35. package/dist/create/server-source/crates/feltdb-server/src/membership_policy.rs +12 -4
  36. package/dist/create/server-source/crates/feltdb-server/src/request_telemetry.rs +8 -6
  37. package/dist/create/server-source/crates/feltdb-server/src/snapshot_cursor.rs +10 -14
  38. package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +183 -21
  39. package/dist/create/server-source/crates/feltdb-server/src/tenant_policies.rs +9 -21
  40. package/dist/create/server-source/crates/feltdb-server/src/transaction_idempotency.rs +5 -3
  41. package/dist/create/server-source/crates/feltdb-server/src/transaction_recovery.rs +9 -8
  42. package/dist/create/server-source/crates/feltdb-server/tests/revision_recovery_integration_test.rs +1 -4
  43. package/dist/create/template/default-project/feltdb.flow +5 -0
  44. package/dist/flowspec.d.ts +1 -0
  45. package/dist/flowspec.d.ts.map +1 -1
  46. package/dist/flowspec.js +46 -12
  47. package/dist/http-client.d.ts +135 -14
  48. package/dist/http-client.d.ts.map +1 -1
  49. package/dist/http-client.js +79 -31
  50. package/dist/index-core.d.ts +2 -0
  51. package/dist/index-core.d.ts.map +1 -1
  52. package/dist/index-core.js +2 -0
  53. package/dist/module-intent.d.ts +37 -0
  54. package/dist/module-intent.d.ts.map +1 -0
  55. package/dist/module-intent.js +81 -0
  56. package/dist/module.d.ts +76 -0
  57. package/dist/module.d.ts.map +1 -0
  58. package/dist/module.js +61 -0
  59. package/dist/proposal.d.ts +80 -4
  60. package/dist/proposal.d.ts.map +1 -1
  61. package/dist/proposal.js +132 -5
  62. package/dist/studio/app.d.ts +3 -1
  63. package/dist/studio/app.d.ts.map +1 -1
  64. package/dist/studio/components/AskFeltDB.d.ts +2 -1
  65. package/dist/studio/components/AskFeltDB.d.ts.map +1 -1
  66. package/dist/studio/components/ContractInspector.d.ts +7 -0
  67. package/dist/studio/components/ContractInspector.d.ts.map +1 -0
  68. package/dist/studio/components/ManagedInstancePanel.d.ts.map +1 -1
  69. package/dist/studio/components/ManagedInstancePanel.js +1 -5
  70. package/dist/studio/components/ModuleExplorer.d.ts +6 -0
  71. package/dist/studio/components/ModuleExplorer.d.ts.map +1 -0
  72. package/dist/studio/components/ProposalBrowser.d.ts +10 -1
  73. package/dist/studio/components/ProposalBrowser.d.ts.map +1 -1
  74. package/dist/studio/components/StateExplorer.d.ts +6 -7
  75. package/dist/studio/components/StateExplorer.d.ts.map +1 -1
  76. package/dist/studio/components/index.d.ts +2 -0
  77. package/dist/studio/components/index.d.ts.map +1 -1
  78. package/dist/studio/components/index.js +4 -4
  79. package/dist/studio/components-CNSNrmA9.js +2787 -0
  80. package/dist/studio/index.js +193 -147
  81. package/dist/studio/studio.css +1 -1
  82. package/dist/studio/utils/index.d.ts +2 -0
  83. package/dist/studio/utils/index.d.ts.map +1 -1
  84. package/dist/studio/utils/index.js +14 -12
  85. package/dist/studio/utils/managed-instance.d.ts +0 -4
  86. package/dist/studio/utils/managed-instance.d.ts.map +1 -1
  87. package/dist/studio/utils/managed-instance.js +0 -4
  88. package/dist/studio/utils/proposal-api.d.ts +53 -0
  89. package/dist/studio/utils/proposal-api.d.ts.map +1 -0
  90. package/dist/studio/utils/proposal-api.js +91 -0
  91. package/dist/studio/utils/service-api.d.ts +81 -0
  92. package/dist/studio/utils/service-api.d.ts.map +1 -0
  93. package/dist/studio/utils/service-api.js +51 -0
  94. package/dist/studio-app/assets/{dist-DA1MYSzp.js → dist-CCOk39Uc.js} +1 -1
  95. package/dist/studio-app/assets/{feltdb_wasm-B-Ccgccb.js → feltdb_wasm-CSB6KVgw.js} +1 -1
  96. package/dist/studio-app/assets/feltdb_wasm_bg-Dd1fnO9U.wasm +0 -0
  97. package/dist/studio-app/assets/index-Bncji3aN.js +43 -0
  98. package/dist/studio-app/assets/{index-BRrmvaKw.css → index-yazaWMUN.css} +1 -1
  99. package/dist/studio-app/index.html +2 -2
  100. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  101. package/dist/workspace/local-development-authority.d.ts.map +1 -1
  102. package/dist/workspace/local-development-authority.js +64 -3
  103. package/package.json +1 -1
  104. package/dist/studio/components-Bm4sjhcX.js +0 -2162
  105. package/dist/studio-app/assets/feltdb_wasm_bg-wH3enJIA.wasm +0 -0
  106. package/dist/studio-app/assets/index-CEIqowCh.js +0 -42
@@ -0,0 +1,2787 @@
1
+ import { ServiceApiError as e, StudioServiceApi as t, safeDisplayValue as n, serviceApiErrorMessage as r } from "./utils/service-api.js";
2
+ import { StudioProposalApi as i, proposalErrorMessage as a, proposalSections as o } from "./utils/proposal-api.js";
3
+ import "./KeyManagementPanel-DZuSeWBK.js";
4
+ import "./components/ManagedInstancePanel.js";
5
+ import s, { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
6
+ import { Link as p } from "react-router-dom";
7
+ import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
8
+ import { createFeltDB as _, diffFlowSpec as v, emptyFlowSpec as y, formatFlowSpec as b, parseFlowSpec as x, planFlowSpecMigration as S, resolveFeltDBModules as C, validateFlowSpec as w } from "@feltdb/core";
9
+ //#region src/components/OverviewDashboard.tsx
10
+ function T({ stats: e }) {
11
+ return e ? /* @__PURE__ */ g("div", {
12
+ className: "overview-dashboard",
13
+ children: [/* @__PURE__ */ g("div", {
14
+ className: "dashboard-header",
15
+ children: [/* @__PURE__ */ h("h1", { children: "FeltDB Studio" }), /* @__PURE__ */ h("div", {
16
+ className: "namespace-badge",
17
+ children: e.namespace
18
+ })]
19
+ }), /* @__PURE__ */ g("div", {
20
+ className: "dashboard-grid",
21
+ children: [
22
+ /* @__PURE__ */ g("div", {
23
+ className: "stat-card",
24
+ children: [
25
+ /* @__PURE__ */ h("label", { children: "Runtime" }),
26
+ /* @__PURE__ */ h("div", {
27
+ className: `status-indicator ${e.status}`,
28
+ children: "●"
29
+ }),
30
+ /* @__PURE__ */ h("span", { children: e.status.charAt(0).toUpperCase() + e.status.slice(1) })
31
+ ]
32
+ }),
33
+ /* @__PURE__ */ g("div", {
34
+ className: "stat-card",
35
+ children: [/* @__PURE__ */ h("label", { children: "Storage" }), /* @__PURE__ */ g("span", { children: [
36
+ e.persistence,
37
+ " / ",
38
+ e.storageBackend
39
+ ] })]
40
+ }),
41
+ /* @__PURE__ */ g("div", {
42
+ className: "stat-card",
43
+ children: [/* @__PURE__ */ h("label", { children: "Peers" }), /* @__PURE__ */ h("span", {
44
+ className: "stat-number",
45
+ children: e.peersCount
46
+ })]
47
+ }),
48
+ /* @__PURE__ */ g("div", {
49
+ className: "stat-card",
50
+ children: [/* @__PURE__ */ h("label", { children: "Objects" }), /* @__PURE__ */ h("span", {
51
+ className: "stat-number",
52
+ children: e.objectsCount
53
+ })]
54
+ }),
55
+ /* @__PURE__ */ g("div", {
56
+ className: "stat-card",
57
+ children: [/* @__PURE__ */ h("label", { children: "Operations" }), /* @__PURE__ */ h("span", {
58
+ className: "stat-number",
59
+ children: e.operationsCount
60
+ })]
61
+ }),
62
+ /* @__PURE__ */ g("div", {
63
+ className: "stat-card",
64
+ children: [/* @__PURE__ */ h("label", { children: "Capabilities" }), /* @__PURE__ */ h("span", {
65
+ className: "stat-number",
66
+ children: e.capabilitiesCount
67
+ })]
68
+ }),
69
+ /* @__PURE__ */ g("div", {
70
+ className: "stat-card",
71
+ children: [/* @__PURE__ */ h("label", { children: "Executions" }), /* @__PURE__ */ h("span", {
72
+ className: "stat-number",
73
+ children: e.executionsCount
74
+ })]
75
+ }),
76
+ /* @__PURE__ */ g("div", {
77
+ className: "stat-card",
78
+ children: [/* @__PURE__ */ h("label", { children: "Workflows" }), /* @__PURE__ */ h("span", {
79
+ className: "stat-number",
80
+ children: e.workflowsCount
81
+ })]
82
+ }),
83
+ /* @__PURE__ */ g("div", {
84
+ className: "stat-card",
85
+ children: [/* @__PURE__ */ h("label", { children: "Agents" }), /* @__PURE__ */ h("span", {
86
+ className: "stat-number",
87
+ children: e.agentsCount
88
+ })]
89
+ }),
90
+ /* @__PURE__ */ g("div", {
91
+ className: "stat-card",
92
+ children: [/* @__PURE__ */ h("label", { children: "Conflicts" }), /* @__PURE__ */ h("span", {
93
+ className: "stat-number",
94
+ children: e.conflictsCount
95
+ })]
96
+ })
97
+ ]
98
+ })]
99
+ }) : /* @__PURE__ */ h("div", {
100
+ className: "overview-dashboard loading",
101
+ children: /* @__PURE__ */ h("p", { children: "Loading runtime information..." })
102
+ });
103
+ }
104
+ //#endregion
105
+ //#region src/components/StateExplorer.tsx
106
+ function E({ field: e, value: t }) {
107
+ let r = n(e, t);
108
+ if (r == null) return /* @__PURE__ */ h("span", {
109
+ className: "data-null",
110
+ children: "—"
111
+ });
112
+ if (typeof r == "boolean") return /* @__PURE__ */ h("span", {
113
+ className: `data-boolean ${r}`,
114
+ children: r ? "True" : "False"
115
+ });
116
+ if (/date|time/i.test(e.type) && (typeof r == "string" || typeof r == "number")) {
117
+ let e = new Date(r);
118
+ if (!Number.isNaN(e.valueOf())) return /* @__PURE__ */ h("time", {
119
+ dateTime: e.toISOString(),
120
+ children: e.toLocaleString()
121
+ });
122
+ }
123
+ return typeof r == "object" ? !Array.isArray(r) && r.secret === !0 ? /* @__PURE__ */ g("span", {
124
+ className: "secret-state",
125
+ children: [r.configured ? "Configured" : "Not configured", " · Secret"]
126
+ }) : /* @__PURE__ */ g("details", { children: [/* @__PURE__ */ h("summary", { children: Array.isArray(r) ? `${r.length} items` : "Object" }), /* @__PURE__ */ h("pre", { children: JSON.stringify(r, null, 2) })] }) : /* @__PURE__ */ h(m, { children: String(r) });
127
+ }
128
+ function D({ api: e, schema: t, detail: n, onNavigate: i, onClose: a }) {
129
+ let [o, c] = f({}), [l, u] = f(""), d = new Map(n.relationships.map((e) => [e.name, e])), p = async (t) => {
130
+ try {
131
+ let r = await e.records(t.source_collection, void 0, { [t.foreign_field]: String(n.record.id) }, 20);
132
+ c((e) => ({
133
+ ...e,
134
+ [t.name]: r.records
135
+ }));
136
+ } catch (e) {
137
+ u(r(e, t.source_collection));
138
+ }
139
+ };
140
+ return /* @__PURE__ */ g("section", {
141
+ className: "data-detail studio-card",
142
+ "aria-label": `${t.collection} record detail`,
143
+ children: [
144
+ /* @__PURE__ */ g("header", { children: [/* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("span", {
145
+ className: "card-kind",
146
+ children: "record"
147
+ }), /* @__PURE__ */ h("h2", { children: t.collection })] }), /* @__PURE__ */ h("button", {
148
+ className: "data-close",
149
+ onClick: a,
150
+ "aria-label": "Close record",
151
+ children: "×"
152
+ })] }),
153
+ /* @__PURE__ */ h("dl", { children: [{
154
+ name: "id",
155
+ type: "text"
156
+ }, ...t.fields].map((e) => {
157
+ let t = d.get(e.name);
158
+ return /* @__PURE__ */ g(s.Fragment, { children: [/* @__PURE__ */ g("dt", { children: [e.name, /* @__PURE__ */ g("small", { children: [e.type, e.required ? " · required" : ""] })] }), /* @__PURE__ */ h("dd", { children: t?.reference ? /* @__PURE__ */ g("button", {
159
+ className: "reference-value",
160
+ onClick: () => i(t.reference.collection, t.reference.id),
161
+ children: [
162
+ "→ ",
163
+ t.reference.collection,
164
+ " / ",
165
+ t.reference.id
166
+ ]
167
+ }) : /* @__PURE__ */ h(E, {
168
+ field: e,
169
+ value: n.record[e.name]
170
+ }) })] }, e.name);
171
+ }) }),
172
+ t.relationships.filter((e) => e.cardinality === "many").map((e) => /* @__PURE__ */ g("section", {
173
+ className: "reverse-relationship",
174
+ children: [
175
+ /* @__PURE__ */ h("h3", { children: e.source_collection }),
176
+ /* @__PURE__ */ g("p", { children: [
177
+ "References this ",
178
+ t.collection,
179
+ " through ",
180
+ /* @__PURE__ */ h("code", { children: e.foreign_field }),
181
+ "."
182
+ ] }),
183
+ !o[e.name] && /* @__PURE__ */ h("button", {
184
+ className: "btn btn-ghost",
185
+ onClick: () => void p(e),
186
+ children: "Show related records (up to 20)"
187
+ }),
188
+ o[e.name]?.map((t) => /* @__PURE__ */ g("button", {
189
+ className: "reference-value",
190
+ onClick: () => i(e.source_collection, String(t.id)),
191
+ children: [
192
+ "→ ",
193
+ e.source_collection,
194
+ " / ",
195
+ String(t.id)
196
+ ]
197
+ }, String(t.id)))
198
+ ]
199
+ }, e.name)),
200
+ l && /* @__PURE__ */ h("p", {
201
+ role: "alert",
202
+ className: "runtime-error",
203
+ children: l
204
+ })
205
+ ]
206
+ });
207
+ }
208
+ function O({ serviceUrl: n = "", token: i = "", applicationId: a, environment: o, refreshIntervalMs: s = 3e4 }) {
209
+ let d = u(() => new t({
210
+ baseUrl: n,
211
+ token: i,
212
+ applicationId: a,
213
+ environment: o
214
+ }), [
215
+ n,
216
+ i,
217
+ a,
218
+ o
219
+ ]), [p, m] = f(), [_, v] = f(), [y, b] = f(""), [x, S] = f([]), [C, w] = f(), [T, O] = f(), [k, A] = f([]), [j, M] = f(null), [N, P] = f(""), [F, I] = f(""), [L, R] = f({}), [z, B] = f(!0), [V, H] = f(""), U = c(async () => {
220
+ try {
221
+ let [e, t] = await Promise.all([d.application(), d.schema()]);
222
+ m(e), v(t), H(""), b((e) => t.collections.some((t) => t.collection === e) ? e : t.collections[0]?.collection || "");
223
+ } catch (e) {
224
+ H(r(e));
225
+ }
226
+ }, [d]), W = c(async (t, n = L, i = !0) => {
227
+ if (y) {
228
+ B(!0), H(""), w(void 0);
229
+ try {
230
+ let e = await d.records(y, t, n);
231
+ S(e.records), O(t), M(e.pagination.nextCursor);
232
+ } catch (a) {
233
+ if (i && t && a instanceof e && a.code === "invalid_cursor") {
234
+ A([]), await W(void 0, n, !1), H("The cursor expired. Refreshed from the first page.");
235
+ return;
236
+ }
237
+ H(r(a, y)), S([]);
238
+ } finally {
239
+ B(!1);
240
+ }
241
+ }
242
+ }, [
243
+ L,
244
+ d,
245
+ y
246
+ ]);
247
+ l(() => {
248
+ B(!0), U().finally(() => B(!1));
249
+ let e = window.setInterval(() => void U(), s);
250
+ return () => window.clearInterval(e);
251
+ }, [U, s]), l(() => {
252
+ A([]), O(void 0), M(null), R({}), P(""), I(""), y && W(void 0, {});
253
+ }, [y, d]);
254
+ let G = _?.collections.find((e) => e.collection === y), K = _?.collections.find((e) => e.collection === C?.collection), q = async (e, t) => {
255
+ H("");
256
+ try {
257
+ w(await d.record(e, t));
258
+ } catch (t) {
259
+ w(void 0), H(r(t, e));
260
+ }
261
+ }, J = () => {
262
+ let e = N && F ? { [N]: F } : {};
263
+ R(e), A([]), W(void 0, e);
264
+ };
265
+ return /* @__PURE__ */ g("div", {
266
+ className: "studio-model-page data-explorer",
267
+ children: [
268
+ /* @__PURE__ */ g("header", { children: [
269
+ /* @__PURE__ */ h("span", {
270
+ className: "eyebrow",
271
+ children: "Application state"
272
+ }),
273
+ /* @__PURE__ */ h("h1", { children: "Data" }),
274
+ /* @__PURE__ */ h("p", { children: "Real persisted records, authorized and redacted by the FeltDB Service API." })
275
+ ] }),
276
+ /* @__PURE__ */ g("section", {
277
+ className: "application-context",
278
+ "aria-label": "Active application context",
279
+ children: [
280
+ /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("small", { children: "Application" }), /* @__PURE__ */ h("strong", { children: p?.application_name || p?.application_id || a })] }),
281
+ /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("small", { children: "Environment" }), /* @__PURE__ */ h("strong", { children: p?.environment || o })] }),
282
+ /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("small", { children: "Contract" }), /* @__PURE__ */ g("strong", { children: ["v", p?.version ?? _?.contract_version ?? "…"] })] }),
283
+ /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("small", { children: "Contract Hash" }), /* @__PURE__ */ h("code", { children: p?.contract_hash ? `${p.contract_hash.slice(0, 12)}…` : "…" })] }),
284
+ /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("small", { children: "Flow" }), /* @__PURE__ */ h("code", { children: p?.flow_hash ? `${p.flow_hash.slice(0, 12)}…` : "Not recorded" })] })
285
+ ]
286
+ }),
287
+ /* @__PURE__ */ g("div", {
288
+ className: "data-layout",
289
+ children: [/* @__PURE__ */ g("aside", {
290
+ className: "studio-card",
291
+ children: [
292
+ /* @__PURE__ */ h("span", {
293
+ className: "card-kind",
294
+ children: "Collections"
295
+ }),
296
+ _?.collections.map((e) => /* @__PURE__ */ h("button", {
297
+ className: e.collection === y ? "active" : "",
298
+ onClick: () => b(e.collection),
299
+ children: e.collection
300
+ }, e.collection)),
301
+ !_?.collections.length && !z && /* @__PURE__ */ h("p", { children: "No application collections." })
302
+ ]
303
+ }), /* @__PURE__ */ g("section", {
304
+ className: "data-browser",
305
+ children: [
306
+ /* @__PURE__ */ g("header", { children: [/* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("span", {
307
+ className: "card-kind",
308
+ children: "collection"
309
+ }), /* @__PURE__ */ h("h2", { children: y || "Data" })] }), G && /* @__PURE__ */ g("form", {
310
+ onSubmit: (e) => {
311
+ e.preventDefault(), J();
312
+ },
313
+ children: [
314
+ /* @__PURE__ */ g("select", {
315
+ "aria-label": "Filter field",
316
+ value: N,
317
+ onChange: (e) => P(e.target.value),
318
+ children: [/* @__PURE__ */ h("option", {
319
+ value: "",
320
+ children: "Filter field"
321
+ }), G.fields.map((e) => /* @__PURE__ */ h("option", {
322
+ value: e.name,
323
+ children: e.name
324
+ }, e.name))]
325
+ }),
326
+ /* @__PURE__ */ h("input", {
327
+ "aria-label": "Filter value",
328
+ value: F,
329
+ onChange: (e) => I(e.target.value),
330
+ placeholder: "Equals…"
331
+ }),
332
+ /* @__PURE__ */ h("button", { children: "Apply" })
333
+ ]
334
+ })] }),
335
+ V && /* @__PURE__ */ g("div", {
336
+ className: "data-error",
337
+ role: "alert",
338
+ children: [V, /* @__PURE__ */ h("button", {
339
+ onClick: () => void W(void 0),
340
+ children: "Refresh"
341
+ })]
342
+ }),
343
+ z ? /* @__PURE__ */ h("div", {
344
+ className: "model-empty",
345
+ children: "Loading…"
346
+ }) : x.length === 0 ? /* @__PURE__ */ g("div", {
347
+ className: "model-empty",
348
+ children: [
349
+ "No records yet.",
350
+ /* @__PURE__ */ h("br", {}),
351
+ "Create a ",
352
+ y || "record",
353
+ " through your application to see persisted application state here."
354
+ ]
355
+ }) : G && /* @__PURE__ */ h("div", {
356
+ className: "table-shell",
357
+ children: /* @__PURE__ */ g("table", { children: [/* @__PURE__ */ h("thead", { children: /* @__PURE__ */ g("tr", { children: [/* @__PURE__ */ h("th", { children: "id" }), G.fields.map((e) => /* @__PURE__ */ g("th", { children: [e.name, /* @__PURE__ */ g("small", { children: [e.type, e.reference ? ` → ${e.reference}` : ""] })] }, e.name))] }) }), /* @__PURE__ */ h("tbody", { children: x.map((e) => /* @__PURE__ */ g("tr", {
358
+ onClick: () => void q(y, String(e.id)),
359
+ children: [/* @__PURE__ */ h("td", { children: /* @__PURE__ */ h("button", {
360
+ className: "record-link",
361
+ children: String(e.id)
362
+ }) }), G.fields.map((t) => /* @__PURE__ */ h("td", { children: t.reference && e[t.name] != null ? /* @__PURE__ */ g("span", {
363
+ className: "reference-value",
364
+ children: [
365
+ "→ ",
366
+ t.reference,
367
+ " / ",
368
+ String(e[t.name])
369
+ ]
370
+ }) : /* @__PURE__ */ h(E, {
371
+ field: t,
372
+ value: e[t.name]
373
+ }) }, t.name))]
374
+ }, String(e.id))) })] })
375
+ }),
376
+ /* @__PURE__ */ g("footer", {
377
+ className: "data-pagination",
378
+ children: [
379
+ /* @__PURE__ */ g("span", { children: [
380
+ "Showing ",
381
+ +!!x.length,
382
+ "–",
383
+ x.length
384
+ ] }),
385
+ /* @__PURE__ */ h("button", {
386
+ disabled: !k.length,
387
+ onClick: () => {
388
+ let e = k.at(-1);
389
+ A((e) => e.slice(0, -1)), W(e);
390
+ },
391
+ children: "← Previous"
392
+ }),
393
+ /* @__PURE__ */ h("button", {
394
+ disabled: !j,
395
+ onClick: () => {
396
+ A((e) => [...e, T]), W(j || void 0);
397
+ },
398
+ children: "Next →"
399
+ })
400
+ ]
401
+ }),
402
+ C && K && /* @__PURE__ */ h(D, {
403
+ api: d,
404
+ schema: K,
405
+ detail: C,
406
+ onNavigate: (e, t) => void q(e, t),
407
+ onClose: () => w(void 0)
408
+ })
409
+ ]
410
+ })]
411
+ })
412
+ ]
413
+ });
414
+ }
415
+ //#endregion
416
+ //#region src/components/ReferenceExplorer.tsx
417
+ function k(e) {
418
+ let t = e.trim().replace(/^flow:\/\//, "").split("/").filter(Boolean);
419
+ return e.startsWith("flow://") ? t.length >= 3 ? {
420
+ collection: t[t.length - 2],
421
+ id: t[t.length - 1]
422
+ } : null : t.length >= 2 ? {
423
+ collection: t[t.length - 2],
424
+ id: t[t.length - 1]
425
+ } : null;
426
+ }
427
+ function A({ db: e, model: t, namespace: n = "default" }) {
428
+ let [r, i] = f(""), [a, o] = f(), [s, c] = f("Enter a reference to resolve live state."), l = async () => {
429
+ let t = k(r);
430
+ if (!t || !e) {
431
+ o(void 0), c(e ? "Use Collection/id or flow://namespace/Collection/id." : "Runtime unavailable.");
432
+ return;
433
+ }
434
+ let n = await e.collection(t.collection).get(t.id);
435
+ o(n), c(n ? "Materialized locally" : "Reference is valid but is not materialized locally");
436
+ };
437
+ return /* @__PURE__ */ g("div", {
438
+ className: "studio-model-page",
439
+ children: [
440
+ /* @__PURE__ */ g("header", { children: [
441
+ /* @__PURE__ */ h("span", {
442
+ className: "eyebrow",
443
+ children: "Observe"
444
+ }),
445
+ /* @__PURE__ */ h("h1", { children: "References" }),
446
+ /* @__PURE__ */ h("p", { children: "Resolve stable Flow references directly into their materialized state." })
447
+ ] }),
448
+ /* @__PURE__ */ g("div", {
449
+ className: "reference-query",
450
+ children: [/* @__PURE__ */ h("input", {
451
+ value: r,
452
+ onChange: (e) => i(e.target.value),
453
+ onKeyDown: (e) => {
454
+ e.key === "Enter" && l();
455
+ },
456
+ placeholder: `flow://${n}/Collection/id`
457
+ }), /* @__PURE__ */ h("button", {
458
+ onClick: () => void l(),
459
+ children: "Resolve"
460
+ })]
461
+ }),
462
+ /* @__PURE__ */ g("div", {
463
+ className: "reference-layout",
464
+ children: [/* @__PURE__ */ g("article", {
465
+ className: "studio-card",
466
+ children: [/* @__PURE__ */ h("span", {
467
+ className: "card-kind",
468
+ children: "Known collections"
469
+ }), t?.collections.map((e) => /* @__PURE__ */ g("button", {
470
+ className: "reference-example",
471
+ onClick: () => i(`flow://${n}/${e.name}/id`),
472
+ children: [e.name, /* @__PURE__ */ g("small", { children: [e.fields.length, " fields"] })]
473
+ }, e.name))]
474
+ }), /* @__PURE__ */ g("article", {
475
+ className: "studio-card reference-result",
476
+ children: [
477
+ /* @__PURE__ */ h("span", {
478
+ className: "card-kind",
479
+ children: "Resolution"
480
+ }),
481
+ /* @__PURE__ */ h("h2", { children: s }),
482
+ a !== void 0 && /* @__PURE__ */ h("pre", { children: JSON.stringify(a, null, 2) })
483
+ ]
484
+ })]
485
+ })
486
+ ]
487
+ });
488
+ }
489
+ //#endregion
490
+ //#region src/components/OperationsExplorer.tsx
491
+ function j({ db: e, namespace: t = "default" }) {
492
+ let [n, r] = f([]), [i, a] = f("all");
493
+ l(() => {
494
+ if (!e) return;
495
+ let t = !0, n = async () => {
496
+ let n = await e.auditEvents();
497
+ t && r(n.slice().reverse());
498
+ };
499
+ n();
500
+ let i = setInterval(() => void n(), 1e3);
501
+ return () => {
502
+ t = !1, clearInterval(i);
503
+ };
504
+ }, [e]);
505
+ let o = n.filter((e) => i === "all" || e.type === i);
506
+ return /* @__PURE__ */ g("div", {
507
+ className: "studio-model-page",
508
+ children: [
509
+ /* @__PURE__ */ g("header", { children: [
510
+ /* @__PURE__ */ h("span", {
511
+ className: "eyebrow",
512
+ children: "Observe"
513
+ }),
514
+ /* @__PURE__ */ h("h1", { children: "Operations" }),
515
+ /* @__PURE__ */ h("p", { children: "The runtime's durable local mutation log—not a simulated activity feed." })
516
+ ] }),
517
+ /* @__PURE__ */ g("div", {
518
+ className: "model-summary",
519
+ children: [
520
+ /* @__PURE__ */ g("span", { children: [n.length, " recorded"] }),
521
+ /* @__PURE__ */ g("span", { children: [t, " namespace"] }),
522
+ /* @__PURE__ */ g("select", {
523
+ value: i,
524
+ onChange: (e) => a(e.target.value),
525
+ children: [
526
+ /* @__PURE__ */ h("option", {
527
+ value: "all",
528
+ children: "All mutations"
529
+ }),
530
+ /* @__PURE__ */ h("option", {
531
+ value: "put",
532
+ children: "Writes"
533
+ }),
534
+ /* @__PURE__ */ h("option", {
535
+ value: "delete",
536
+ children: "Deletes"
537
+ })
538
+ ]
539
+ })
540
+ ]
541
+ }),
542
+ /* @__PURE__ */ h("div", {
543
+ className: "table-shell",
544
+ children: /* @__PURE__ */ g("table", {
545
+ className: "operations-table",
546
+ children: [/* @__PURE__ */ h("thead", { children: /* @__PURE__ */ g("tr", { children: [
547
+ /* @__PURE__ */ h("th", { children: "Sequence" }),
548
+ /* @__PURE__ */ h("th", { children: "Mutation" }),
549
+ /* @__PURE__ */ h("th", { children: "Collection" }),
550
+ /* @__PURE__ */ h("th", { children: "Key" }),
551
+ /* @__PURE__ */ h("th", { children: "Timestamp" })
552
+ ] }) }), /* @__PURE__ */ g("tbody", { children: [o.map((e) => /* @__PURE__ */ g("tr", { children: [
553
+ /* @__PURE__ */ h("td", { children: e.sequence }),
554
+ /* @__PURE__ */ h("td", { children: /* @__PURE__ */ h("span", {
555
+ className: `event-pill ${e.type}`,
556
+ children: e.type
557
+ }) }),
558
+ /* @__PURE__ */ h("td", { children: e.collection }),
559
+ /* @__PURE__ */ h("td", { children: /* @__PURE__ */ h("code", { children: e.key }) }),
560
+ /* @__PURE__ */ h("td", { children: new Date(e.timestamp).toLocaleString() })
561
+ ] }, `${e.sequence}-${e.key}`)), !o.length && /* @__PURE__ */ h("tr", { children: /* @__PURE__ */ h("td", {
562
+ colSpan: 5,
563
+ className: "empty-message",
564
+ children: "No matching mutations yet. Create or change application state to populate this stream."
565
+ }) })] })]
566
+ })
567
+ })
568
+ ]
569
+ });
570
+ }
571
+ //#endregion
572
+ //#region src/components/PeerMap.tsx
573
+ function M({ peers: e = [], localInstance: t = "local" }) {
574
+ return /* @__PURE__ */ g("div", {
575
+ className: "studio-model-page",
576
+ children: [
577
+ /* @__PURE__ */ g("header", { children: [
578
+ /* @__PURE__ */ h("span", {
579
+ className: "eyebrow",
580
+ children: "Observe"
581
+ }),
582
+ /* @__PURE__ */ h("h1", { children: "Peers" }),
583
+ /* @__PURE__ */ h("p", { children: "The live topology participating in this application's convergence fabric." })
584
+ ] }),
585
+ /* @__PURE__ */ g("div", {
586
+ className: "peer-topology",
587
+ children: [/* @__PURE__ */ g("article", {
588
+ className: "peer-node local",
589
+ children: [
590
+ /* @__PURE__ */ h("span", { children: "this instance" }),
591
+ /* @__PURE__ */ h("h2", { children: t }),
592
+ /* @__PURE__ */ h("small", { children: "online · authoritative local state" })
593
+ ]
594
+ }), e.map((e) => /* @__PURE__ */ g(s.Fragment, { children: [/* @__PURE__ */ h("i", { className: "peer-link" }), /* @__PURE__ */ g("article", {
595
+ className: "peer-node",
596
+ children: [
597
+ /* @__PURE__ */ h("span", { children: "connected peer" }),
598
+ /* @__PURE__ */ h("h2", { children: e }),
599
+ /* @__PURE__ */ h("small", { children: "online · exchanging operations" })
600
+ ]
601
+ })] }, e))]
602
+ }),
603
+ !e.length && /* @__PURE__ */ h("div", {
604
+ className: "model-empty",
605
+ children: "This embedded runtime is operating independently. Its state remains durable and can converge when a network peer is attached."
606
+ })
607
+ ]
608
+ });
609
+ }
610
+ //#endregion
611
+ //#region src/components/CapabilityExplorer.tsx
612
+ function N({ model: e }) {
613
+ let t = e?.capabilities ?? [];
614
+ return /* @__PURE__ */ g("div", {
615
+ className: "studio-model-page",
616
+ children: [
617
+ /* @__PURE__ */ g("header", { children: [
618
+ /* @__PURE__ */ h("span", {
619
+ className: "eyebrow",
620
+ children: "Design"
621
+ }),
622
+ /* @__PURE__ */ h("h1", { children: "Capabilities" }),
623
+ /* @__PURE__ */ g("p", { children: [
624
+ "Declared authority available to workflows and autonomous agents in ",
625
+ e?.app ?? "this application",
626
+ "."
627
+ ] })
628
+ ] }),
629
+ /* @__PURE__ */ g("div", {
630
+ className: "model-summary",
631
+ children: [/* @__PURE__ */ g("span", { children: [t.length, " declared"] }), /* @__PURE__ */ g("span", { children: [new Set(t.flatMap((e) => e.statements)).size, " permission rules"] })]
632
+ }),
633
+ /* @__PURE__ */ g("div", {
634
+ className: "studio-card-grid",
635
+ children: [t.map((e) => /* @__PURE__ */ g("article", {
636
+ className: "studio-card capability-card",
637
+ children: [
638
+ /* @__PURE__ */ h("div", {
639
+ className: "card-kind",
640
+ children: "capability"
641
+ }),
642
+ /* @__PURE__ */ h("h2", { children: e.name }),
643
+ /* @__PURE__ */ h("div", {
644
+ className: "statement-list",
645
+ children: e.statements.map((e) => {
646
+ let [t, ...n] = e.split(" ");
647
+ return /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("b", { children: t }), /* @__PURE__ */ h("code", { children: n.join(" ") })] }, e);
648
+ })
649
+ })
650
+ ]
651
+ }, e.name)), !t.length && /* @__PURE__ */ h("div", {
652
+ className: "model-empty",
653
+ children: "No capabilities are declared in the current project model."
654
+ })]
655
+ })
656
+ ]
657
+ });
658
+ }
659
+ //#endregion
660
+ //#region src/hooks/index.ts
661
+ function P(e, t = "default") {
662
+ let [n, r] = f(null);
663
+ return l(() => {
664
+ if (!e) {
665
+ r(null);
666
+ return;
667
+ }
668
+ let n = e.runtime(), i = n.runtime === "browser" ? "browser" : n.runtime === "node" ? "self-hosted" : "remote";
669
+ r({
670
+ db: e,
671
+ connected: !0,
672
+ namespace: t,
673
+ instanceId: e.instanceId?.() || "unknown",
674
+ environment: i
675
+ });
676
+ }, [e, t]), n;
677
+ }
678
+ function F(e, t = null, n = "default") {
679
+ let [r, i] = f(null);
680
+ return l(() => {
681
+ if (!e) {
682
+ i(null);
683
+ return;
684
+ }
685
+ let r = async () => {
686
+ try {
687
+ let r = e.runtime(), a = e.health(), o = e.sync?.(), s = t ? await Promise.all(t.collections.map((t) => e.collection(t.name).count())) : [];
688
+ i({
689
+ namespace: n,
690
+ status: a?.status || "healthy",
691
+ storageBackend: r.storage,
692
+ persistence: r.persistent ? "durable" : "volatile",
693
+ peersCount: o?.connected_peers?.length || 0,
694
+ objectsCount: s.reduce((e, t) => e + t, 0),
695
+ operationsCount: o?.sequence || 0,
696
+ capabilitiesCount: t?.capabilities.length || 0,
697
+ executionsCount: await e.collection("_flow_executions").count() || await e.collection("Decision").count(),
698
+ workflowsCount: t?.workflows.length || 0,
699
+ agentsCount: t?.agents.length || 0,
700
+ conflictsCount: o?.conflicts_detected || 0
701
+ });
702
+ } catch (e) {
703
+ console.error("Failed to fetch dashboard stats:", e);
704
+ }
705
+ };
706
+ r();
707
+ let a = setInterval(r, 5e3);
708
+ return () => clearInterval(a);
709
+ }, [
710
+ e,
711
+ t,
712
+ n
713
+ ]), r;
714
+ }
715
+ function I(e) {
716
+ let [t, n] = f(null), [r, i] = f(!1), [a, o] = f(null), s = c(async () => {
717
+ if (e) {
718
+ i(!0), o(null);
719
+ try {
720
+ let t = e.health();
721
+ n(t);
722
+ } catch (e) {
723
+ o(e instanceof Error ? e.message : "Failed to fetch diagnostics");
724
+ } finally {
725
+ i(!1);
726
+ }
727
+ }
728
+ }, [e]);
729
+ return l(() => {
730
+ s();
731
+ }, [e, s]), {
732
+ diagnostics: t,
733
+ loading: r,
734
+ error: a,
735
+ refresh: s
736
+ };
737
+ }
738
+ function L(e, t) {
739
+ let [n, r] = f([]), [i, a] = f(!0), [o, s] = f(null);
740
+ return l(() => {
741
+ if (e) {
742
+ a(!0), s(null);
743
+ try {
744
+ let n = e.collection(t).subscribe((e) => {
745
+ r(e), a(!1);
746
+ });
747
+ return () => n();
748
+ } catch (e) {
749
+ s(e instanceof Error ? e.message : "Failed to load collection"), a(!1);
750
+ }
751
+ }
752
+ }, [e, t]), {
753
+ items: n,
754
+ loading: i,
755
+ error: o
756
+ };
757
+ }
758
+ function R(e) {
759
+ let [t, n] = f([]);
760
+ return l(() => {
761
+ if (!e) {
762
+ n([]);
763
+ return;
764
+ }
765
+ let t = () => {
766
+ try {
767
+ let t = e.sync?.();
768
+ n(t?.connected_peers || []);
769
+ } catch (e) {
770
+ console.error("Failed to fetch peers:", e);
771
+ }
772
+ };
773
+ t();
774
+ let r = setInterval(t, 2e3);
775
+ return () => clearInterval(r);
776
+ }, [e]), t;
777
+ }
778
+ function z(e, t) {
779
+ let [n, r] = f(null), [i, a] = f(!1), [o, s] = f(null);
780
+ return l(() => {
781
+ if (!e || !t) {
782
+ r(null);
783
+ return;
784
+ }
785
+ a(!0), s(null), (async () => {
786
+ try {
787
+ let n = e.provenance(t);
788
+ r(n);
789
+ } catch (e) {
790
+ s(e instanceof Error ? e.message : "Failed to fetch provenance");
791
+ } finally {
792
+ a(!1);
793
+ }
794
+ })();
795
+ }, [e, t]), {
796
+ provenance: n,
797
+ loading: i,
798
+ error: o
799
+ };
800
+ }
801
+ //#endregion
802
+ //#region src/components/ExecutionViewer.tsx
803
+ function B({ db: e, name: t, label: n }) {
804
+ let { items: r } = L(e, t);
805
+ return r.length ? /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ g("h2", { children: [n, /* @__PURE__ */ h("span", { children: r.length })] }), /* @__PURE__ */ h("div", {
806
+ className: "execution-list",
807
+ children: r.map((e, r) => /* @__PURE__ */ g("article", {
808
+ className: "execution-row",
809
+ children: [
810
+ /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("b", { children: String(e.name ?? e.workflow ?? e.incident_id ?? e.id ?? n) }), /* @__PURE__ */ h("small", { children: t })] }),
811
+ /* @__PURE__ */ h("span", {
812
+ className: "event-pill put",
813
+ children: String(e.status ?? e.state ?? "materialized")
814
+ }),
815
+ /* @__PURE__ */ h("pre", { children: JSON.stringify(e, null, 2) })
816
+ ]
817
+ }, String(e.id ?? r)))
818
+ })] }) : null;
819
+ }
820
+ function V({ db: e, model: t }) {
821
+ return /* @__PURE__ */ g("div", {
822
+ className: "studio-model-page",
823
+ children: [
824
+ /* @__PURE__ */ g("header", { children: [
825
+ /* @__PURE__ */ h("span", {
826
+ className: "eyebrow",
827
+ children: "Observe"
828
+ }),
829
+ /* @__PURE__ */ h("h1", { children: "Executions" }),
830
+ /* @__PURE__ */ h("p", { children: "Capability work, workflow runs, assignments, and agent decisions as inspectable state." })
831
+ ] }),
832
+ /* @__PURE__ */ g("div", {
833
+ className: "model-summary",
834
+ children: [/* @__PURE__ */ g("span", { children: [t?.workflows.length ?? 0, " workflow definitions"] }), /* @__PURE__ */ g("span", { children: [t?.agents.length ?? 0, " autonomous agents"] })]
835
+ }),
836
+ /* @__PURE__ */ h(B, {
837
+ db: e ?? null,
838
+ name: "_flow_executions",
839
+ label: "Capability executions"
840
+ }),
841
+ /* @__PURE__ */ h(B, {
842
+ db: e ?? null,
843
+ name: "_flow_workflow_runs",
844
+ label: "Workflow runs"
845
+ }),
846
+ /* @__PURE__ */ h(B, {
847
+ db: e ?? null,
848
+ name: "Assignment",
849
+ label: "Materialized assignments"
850
+ }),
851
+ /* @__PURE__ */ h(B, {
852
+ db: e ?? null,
853
+ name: "Decision",
854
+ label: "Agent decisions"
855
+ }),
856
+ /* @__PURE__ */ h(B, {
857
+ db: e ?? null,
858
+ name: "_flow_agent_executions",
859
+ label: "Agent executions"
860
+ }),
861
+ /* @__PURE__ */ g("div", {
862
+ className: "model-empty execution-empty",
863
+ children: [
864
+ "Execution sections appear as soon as their state is committed. Defined workflows: ",
865
+ t?.workflows.map((e) => e.name).join(", ") || "none",
866
+ "."
867
+ ]
868
+ })
869
+ ]
870
+ });
871
+ }
872
+ //#endregion
873
+ //#region src/components/ConflictExplorer.tsx
874
+ function H({ db: e, diagnostics: t }) {
875
+ let n = (() => {
876
+ try {
877
+ return e?.sync();
878
+ } catch {
879
+ return;
880
+ }
881
+ })(), r = n?.conflicts_detected ?? 0;
882
+ return /* @__PURE__ */ g("div", {
883
+ className: "studio-model-page",
884
+ children: [
885
+ /* @__PURE__ */ g("header", { children: [
886
+ /* @__PURE__ */ h("span", {
887
+ className: "eyebrow",
888
+ children: "Observe"
889
+ }),
890
+ /* @__PURE__ */ h("h1", { children: "Conflicts" }),
891
+ /* @__PURE__ */ h("p", { children: "Concurrent mutations detected while replicas converge." })
892
+ ] }),
893
+ /* @__PURE__ */ g("div", {
894
+ className: "metric-grid",
895
+ children: [
896
+ /* @__PURE__ */ g("article", { children: [/* @__PURE__ */ h("b", { children: r }), /* @__PURE__ */ h("span", { children: "detected" })] }),
897
+ /* @__PURE__ */ g("article", { children: [/* @__PURE__ */ h("b", { children: n?.pending_operations ?? 0 }), /* @__PURE__ */ h("span", { children: "pending operations" })] }),
898
+ /* @__PURE__ */ g("article", { children: [/* @__PURE__ */ h("b", { children: n?.connected_peers.length ?? 0 }), /* @__PURE__ */ h("span", { children: "connected peers" })] })
899
+ ]
900
+ }),
901
+ /* @__PURE__ */ g("article", {
902
+ className: "studio-card",
903
+ children: [
904
+ /* @__PURE__ */ h("span", {
905
+ className: "card-kind",
906
+ children: "Convergence"
907
+ }),
908
+ /* @__PURE__ */ h("h2", { children: r ? "Conflict activity detected" : "No conflicts detected" }),
909
+ /* @__PURE__ */ h("p", { children: t?.sync.connected ? "The fabric is connected and applying causal ordering." : "The local replica is independent; conflict detection begins when operations converge with peers." }),
910
+ /* @__PURE__ */ h("code", { children: "Causal ordering → deterministic materialization → auditable resolution" })
911
+ ]
912
+ })
913
+ ]
914
+ });
915
+ }
916
+ //#endregion
917
+ //#region src/components/WorkflowVisualizer.tsx
918
+ function U({ model: e }) {
919
+ let t = e?.workflows ?? [], [n, r] = f(), i = t.find((e) => e.name === n) ?? t[0];
920
+ return /* @__PURE__ */ g("div", {
921
+ className: "studio-model-page",
922
+ children: [/* @__PURE__ */ g("header", { children: [
923
+ /* @__PURE__ */ h("span", {
924
+ className: "eyebrow",
925
+ children: "Design"
926
+ }),
927
+ /* @__PURE__ */ h("h1", { children: "Workflows" }),
928
+ /* @__PURE__ */ h("p", { children: "Durable state transitions declared by the application model." })
929
+ ] }), /* @__PURE__ */ g("div", {
930
+ className: "split-browser",
931
+ children: [/* @__PURE__ */ h("aside", { children: t.map((e) => /* @__PURE__ */ g("button", {
932
+ className: e.name === i?.name ? "active" : "",
933
+ onClick: () => r(e.name),
934
+ children: [/* @__PURE__ */ h("strong", { children: e.name }), /* @__PURE__ */ g("span", { children: [e.steps.length, " steps"] })]
935
+ }, e.name)) }), /* @__PURE__ */ h("section", { children: i ? /* @__PURE__ */ g(m, { children: [
936
+ /* @__PURE__ */ h("div", {
937
+ className: "card-kind",
938
+ children: "workflow"
939
+ }),
940
+ /* @__PURE__ */ h("h2", { children: i.name }),
941
+ i.parameters.length > 0 && /* @__PURE__ */ g("code", {
942
+ className: "signature",
943
+ children: [
944
+ "(",
945
+ i.parameters,
946
+ ")"
947
+ ]
948
+ }),
949
+ /* @__PURE__ */ h("div", {
950
+ className: "workflow-track",
951
+ children: i.steps.map((e, t) => /* @__PURE__ */ g(s.Fragment, { children: [/* @__PURE__ */ g("article", { children: [/* @__PURE__ */ h("span", { children: t + 1 }), /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("strong", { children: e.name }), e.statements.map((e) => /* @__PURE__ */ h("code", { children: e }, e))] })] }), t < i.steps.length - 1 && /* @__PURE__ */ h("i", { children: "→" })] }, e.name))
952
+ })
953
+ ] }) : /* @__PURE__ */ h("div", {
954
+ className: "model-empty",
955
+ children: "No workflows are declared."
956
+ }) })]
957
+ })]
958
+ });
959
+ }
960
+ //#endregion
961
+ //#region src/components/AgentExplorer.tsx
962
+ function W({ model: e }) {
963
+ let t = e?.agents ?? [], [n, r] = f(), i = t.find((e) => e.name === n) ?? t[0];
964
+ return /* @__PURE__ */ g("div", {
965
+ className: "studio-model-page",
966
+ children: [/* @__PURE__ */ g("header", { children: [
967
+ /* @__PURE__ */ h("span", {
968
+ className: "eyebrow",
969
+ children: "Design"
970
+ }),
971
+ /* @__PURE__ */ h("h1", { children: "Agents" }),
972
+ /* @__PURE__ */ h("p", { children: "Autonomous participants whose authority and workflows are part of the model." })
973
+ ] }), /* @__PURE__ */ g("div", {
974
+ className: "split-browser",
975
+ children: [/* @__PURE__ */ h("aside", { children: t.map((e) => /* @__PURE__ */ g("button", {
976
+ className: e.name === i?.name ? "active" : "",
977
+ onClick: () => r(e.name),
978
+ children: [/* @__PURE__ */ h("strong", { children: e.name }), /* @__PURE__ */ g("span", { children: [e.statements.length, " bindings"] })]
979
+ }, e.name)) }), /* @__PURE__ */ h("section", { children: i ? /* @__PURE__ */ h(m, { children: /* @__PURE__ */ g("div", {
980
+ className: "agent-orbit",
981
+ children: [/* @__PURE__ */ g("div", {
982
+ className: "agent-core",
983
+ children: [/* @__PURE__ */ h("span", { children: "agent" }), /* @__PURE__ */ h("strong", { children: i.name })]
984
+ }), i.statements.map((e) => /* @__PURE__ */ g("div", {
985
+ className: "agent-binding",
986
+ children: [/* @__PURE__ */ h("span", { children: e.split(" ")[0] }), /* @__PURE__ */ h("strong", { children: e.split(" ").slice(1).join(" ") })]
987
+ }, e))]
988
+ }) }) : /* @__PURE__ */ h("div", {
989
+ className: "model-empty",
990
+ children: "No agents are declared."
991
+ }) })]
992
+ })]
993
+ });
994
+ }
995
+ //#endregion
996
+ //#region src/components/ProvenanceViewer.tsx
997
+ function G({ db: e, namespace: t = "default", reference: n }) {
998
+ let [r, i] = f(n ?? ""), [a, o] = f(null), [s, c] = f([]), [u, d] = f("Enter a Flow reference to trace it.");
999
+ l(() => {
1000
+ n && i(n);
1001
+ }, [n]);
1002
+ let p = async () => {
1003
+ if (!(!e || !r)) try {
1004
+ let t = e.provenance(r);
1005
+ o(t), d("Causal graph resolved");
1006
+ } catch {
1007
+ o(null);
1008
+ let t = await e.auditEvents(), n = r.split("/"), i = n[n.length - 1] ?? "", a = t.filter((e) => e.key.includes(i));
1009
+ c(a), d(a.length ? "Local mutation lineage" : "No local lineage found for this reference");
1010
+ }
1011
+ };
1012
+ return /* @__PURE__ */ g("div", {
1013
+ className: "studio-model-page",
1014
+ children: [
1015
+ /* @__PURE__ */ g("header", { children: [
1016
+ /* @__PURE__ */ h("span", {
1017
+ className: "eyebrow",
1018
+ children: "Observe"
1019
+ }),
1020
+ /* @__PURE__ */ h("h1", { children: "Provenance" }),
1021
+ /* @__PURE__ */ h("p", { children: "Follow why state exists—from durable mutations to causal workflow and agent edges." })
1022
+ ] }),
1023
+ /* @__PURE__ */ g("div", {
1024
+ className: "reference-query",
1025
+ children: [/* @__PURE__ */ h("input", {
1026
+ value: r,
1027
+ onChange: (e) => i(e.target.value),
1028
+ placeholder: `flow://${t}/Collection/id`
1029
+ }), /* @__PURE__ */ h("button", {
1030
+ onClick: () => void p(),
1031
+ children: "Trace"
1032
+ })]
1033
+ }),
1034
+ /* @__PURE__ */ g("article", {
1035
+ className: "studio-card provenance-result",
1036
+ children: [
1037
+ /* @__PURE__ */ h("span", {
1038
+ className: "card-kind",
1039
+ children: "Lineage"
1040
+ }),
1041
+ /* @__PURE__ */ h("h2", { children: u }),
1042
+ a && /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ g("div", {
1043
+ className: "model-summary",
1044
+ children: [/* @__PURE__ */ g("span", { children: [a.nodes.length, " nodes"] }), /* @__PURE__ */ g("span", { children: [a.edges.length, " edges"] })]
1045
+ }), /* @__PURE__ */ h("div", {
1046
+ className: "provenance-nodes",
1047
+ children: a.nodes.map((e) => /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("b", { children: e.label }), /* @__PURE__ */ h("small", { children: e.type })] }, e.id))
1048
+ })] }),
1049
+ !a && s.map((e) => /* @__PURE__ */ g("div", {
1050
+ className: "provenance-event",
1051
+ children: [
1052
+ /* @__PURE__ */ h("span", { children: e.sequence }),
1053
+ /* @__PURE__ */ g("b", { children: [
1054
+ e.type,
1055
+ " ",
1056
+ e.collection
1057
+ ] }),
1058
+ /* @__PURE__ */ h("code", { children: e.key }),
1059
+ /* @__PURE__ */ h("small", { children: new Date(e.timestamp).toLocaleString() })
1060
+ ]
1061
+ }, `${e.sequence}-${e.key}`))
1062
+ ]
1063
+ })
1064
+ ]
1065
+ });
1066
+ }
1067
+ //#endregion
1068
+ //#region src/components/HealthCenter.tsx
1069
+ function K({ diagnostics: e, model: t }) {
1070
+ let n = e ? [
1071
+ [
1072
+ "Runtime",
1073
+ e.runtime.status,
1074
+ e.runtime.reactive ? "reactive" : "non-reactive"
1075
+ ],
1076
+ [
1077
+ "Storage",
1078
+ e.storage.status,
1079
+ `${e.storage.backend} · ${e.storage.persistent ? "persistent" : "volatile"}`
1080
+ ],
1081
+ [
1082
+ "Synchronization",
1083
+ e.sync.status,
1084
+ `${e.sync.peers} peers · ${e.sync.pendingOperations} pending`
1085
+ ],
1086
+ [
1087
+ "Fabric",
1088
+ e.fabric.status,
1089
+ `${e.fabric.references} references`
1090
+ ],
1091
+ [
1092
+ "Capabilities",
1093
+ e.capabilities.status,
1094
+ `${e.capabilities.available}/${e.capabilities.count} available`
1095
+ ],
1096
+ [
1097
+ "Execution",
1098
+ e.execution.status,
1099
+ `${e.execution.running} running · ${e.execution.failed} failed`
1100
+ ],
1101
+ [
1102
+ "Workflows",
1103
+ e.workflow.status,
1104
+ `${e.workflow.active}/${e.workflow.total} active`
1105
+ ]
1106
+ ] : [];
1107
+ return /* @__PURE__ */ g("div", {
1108
+ className: "studio-model-page",
1109
+ children: [
1110
+ /* @__PURE__ */ g("header", { children: [
1111
+ /* @__PURE__ */ h("span", {
1112
+ className: "eyebrow",
1113
+ children: "Observe"
1114
+ }),
1115
+ /* @__PURE__ */ h("h1", { children: "Health" }),
1116
+ /* @__PURE__ */ h("p", { children: "Runtime diagnostics, not optimistic defaults." })
1117
+ ] }),
1118
+ /* @__PURE__ */ h("div", {
1119
+ className: "health-grid",
1120
+ children: n.map(([e, t, n]) => /* @__PURE__ */ g("article", {
1121
+ className: `health-item status-${t}`,
1122
+ children: [/* @__PURE__ */ h("span", {
1123
+ className: "status-icon",
1124
+ children: t === "healthy" ? "✓" : "!"
1125
+ }), /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("b", { children: e }), /* @__PURE__ */ h("small", { children: n })] })]
1126
+ }, e))
1127
+ }),
1128
+ !e && /* @__PURE__ */ h("div", {
1129
+ className: "model-empty",
1130
+ children: "Diagnostics are unavailable until Studio connects to a runtime."
1131
+ }),
1132
+ e?.issues.map((e, t) => /* @__PURE__ */ g("div", {
1133
+ className: `health-issue ${e.severity}`,
1134
+ children: [
1135
+ /* @__PURE__ */ h("b", { children: e.component }),
1136
+ " ",
1137
+ e.message
1138
+ ]
1139
+ }, t)),
1140
+ /* @__PURE__ */ g("div", {
1141
+ className: "model-summary",
1142
+ children: [
1143
+ /* @__PURE__ */ g("span", { children: [t?.collections.length ?? 0, " collections modeled"] }),
1144
+ /* @__PURE__ */ g("span", { children: [t?.workflows.length ?? 0, " workflows modeled"] }),
1145
+ /* @__PURE__ */ g("span", { children: [t?.agents.length ?? 0, " agents modeled"] })
1146
+ ]
1147
+ })
1148
+ ]
1149
+ });
1150
+ }
1151
+ //#endregion
1152
+ //#region src/components/SettingsPanel.tsx
1153
+ function q({ db: e, remoteUrl: t = "", token: n = "", onConnect: r }) {
1154
+ let [i, a] = f(t), [o, s] = f(n), c = e?.runtime();
1155
+ return l(() => {
1156
+ a(t), s(n);
1157
+ }, [t, n]), /* @__PURE__ */ g("div", {
1158
+ className: "settings-panel",
1159
+ children: [/* @__PURE__ */ h("h2", { children: "Settings" }), /* @__PURE__ */ g("div", {
1160
+ className: "settings-content",
1161
+ children: [
1162
+ /* @__PURE__ */ h("h3", { children: "Connection" }),
1163
+ /* @__PURE__ */ g("div", {
1164
+ className: "connection-info",
1165
+ children: [
1166
+ /* @__PURE__ */ g("div", {
1167
+ className: "info-row",
1168
+ children: [/* @__PURE__ */ h("label", { children: "Runtime Environment" }), /* @__PURE__ */ h("span", { children: c?.runtime || "unavailable" })]
1169
+ }),
1170
+ /* @__PURE__ */ g("div", {
1171
+ className: "info-row",
1172
+ children: [/* @__PURE__ */ h("label", { children: "Storage Backend" }), /* @__PURE__ */ h("span", { children: c?.storage || "unavailable" })]
1173
+ }),
1174
+ /* @__PURE__ */ g("div", {
1175
+ className: "info-row",
1176
+ children: [/* @__PURE__ */ h("label", { children: "Instance ID" }), /* @__PURE__ */ h("span", {
1177
+ className: "monospace",
1178
+ children: e?.instanceId?.() || "unavailable"
1179
+ })]
1180
+ })
1181
+ ]
1182
+ }),
1183
+ /* @__PURE__ */ g("form", {
1184
+ className: "connection-form",
1185
+ onSubmit: (e) => {
1186
+ e.preventDefault(), r?.(i, o);
1187
+ },
1188
+ children: [
1189
+ /* @__PURE__ */ g("label", { children: ["Server or managed endpoint", /* @__PURE__ */ h("input", {
1190
+ type: "url",
1191
+ value: i,
1192
+ onChange: (e) => a(e.target.value),
1193
+ placeholder: "https://your-runtime.example.com"
1194
+ })] }),
1195
+ /* @__PURE__ */ g("label", { children: ["API token", /* @__PURE__ */ h("input", {
1196
+ type: "password",
1197
+ value: o,
1198
+ onChange: (e) => s(e.target.value),
1199
+ placeholder: "fdb_live_…",
1200
+ autoComplete: "off"
1201
+ })] }),
1202
+ /* @__PURE__ */ h("p", { children: "Tokens are kept in this browser session and are never written to the project." }),
1203
+ /* @__PURE__ */ h("button", {
1204
+ className: "btn btn-primary",
1205
+ type: "submit",
1206
+ children: "Connect Studio"
1207
+ })
1208
+ ]
1209
+ })
1210
+ ]
1211
+ })]
1212
+ });
1213
+ }
1214
+ //#endregion
1215
+ //#region src/components/GlobalSearch.tsx
1216
+ function J({ db: e, model: t, onSearch: n }) {
1217
+ let [r, i] = f(""), [a, o] = f([]), s = (e) => {
1218
+ i(e), n && n(e);
1219
+ };
1220
+ return l(() => {
1221
+ let n = !0;
1222
+ return (async () => {
1223
+ let i = r.trim().toLowerCase();
1224
+ if (!i) {
1225
+ o([]);
1226
+ return;
1227
+ }
1228
+ let a = [
1229
+ ...t?.collections.map((e) => ({
1230
+ kind: "collection",
1231
+ name: e.name,
1232
+ detail: `${e.fields.length} fields`
1233
+ })) ?? [],
1234
+ ...t?.capabilities.map((e) => ({
1235
+ kind: "capability",
1236
+ name: e.name,
1237
+ detail: e.statements.join(" · ")
1238
+ })) ?? [],
1239
+ ...t?.workflows.map((e) => ({
1240
+ kind: "workflow",
1241
+ name: e.name,
1242
+ detail: `${e.steps.length} steps`
1243
+ })) ?? [],
1244
+ ...t?.agents.map((e) => ({
1245
+ kind: "agent",
1246
+ name: e.name,
1247
+ detail: e.statements.join(" · ")
1248
+ })) ?? []
1249
+ ].filter((e) => JSON.stringify(e).toLowerCase().includes(i)), s = e && t ? (await Promise.all(t.collections.map(async (t) => (await e.collection(t.name).all()).filter((e) => JSON.stringify(e).toLowerCase().includes(i)).slice(0, 3).map((e) => ({
1250
+ kind: "object",
1251
+ name: `${t.name}/${String(e.id ?? "record")}`,
1252
+ detail: JSON.stringify(e)
1253
+ }))))).flat() : [];
1254
+ n && o([...a, ...s].slice(0, 12));
1255
+ })(), () => {
1256
+ n = !1;
1257
+ };
1258
+ }, [
1259
+ e,
1260
+ t,
1261
+ r
1262
+ ]), /* @__PURE__ */ g("div", {
1263
+ className: "global-search",
1264
+ children: [/* @__PURE__ */ h("input", {
1265
+ type: "text",
1266
+ placeholder: "Search: documents/123, flow://, agent/name, etc.",
1267
+ value: r,
1268
+ onChange: (e) => s(e.target.value),
1269
+ className: "search-input global"
1270
+ }), r && /* @__PURE__ */ h("div", {
1271
+ className: "search-results",
1272
+ children: /* @__PURE__ */ g("div", {
1273
+ className: "results-group",
1274
+ children: [
1275
+ /* @__PURE__ */ h("h4", { children: "Model & runtime" }),
1276
+ a.map((e, t) => /* @__PURE__ */ g("div", {
1277
+ className: "search-result",
1278
+ children: [
1279
+ /* @__PURE__ */ h("b", { children: e.name }),
1280
+ /* @__PURE__ */ h("span", { children: e.kind }),
1281
+ /* @__PURE__ */ h("small", { children: e.detail })
1282
+ ]
1283
+ }, `${e.kind}-${e.name}-${t}`)),
1284
+ !a.length && /* @__PURE__ */ h("div", {
1285
+ className: "empty-message",
1286
+ children: "No matches"
1287
+ })
1288
+ ]
1289
+ })
1290
+ })]
1291
+ });
1292
+ }
1293
+ //#endregion
1294
+ //#region src/components/ApplicationDesigner.tsx
1295
+ var Y = b(y("Application"));
1296
+ function ee({ db: e, namespace: t = "default", projectSpec: n, managedPublish: r, onSpecChange: i }) {
1297
+ let a = `feltdb:studio:draft:${t}`, o = d((() => {
1298
+ if (typeof window > "u") return Y;
1299
+ let e = window.localStorage.getItem(a);
1300
+ if (!e) return Y;
1301
+ try {
1302
+ return x(e), e;
1303
+ } catch {
1304
+ return Y;
1305
+ }
1306
+ })()), s = d(o.current !== Y), [c, p] = f(o.current), [m, C] = f(() => x(o.current)), [T, E] = f([]), [D, O] = f([]), [k, A] = f("Draft is valid"), [j, M] = f(0), [N, P] = f(null), [F, I] = f(null), [L, R] = f(!1), [z, B] = f(!1), [V, H] = f(() => ({
1307
+ url: r?.url || "",
1308
+ namespace: r?.namespace || t,
1309
+ token: r?.token || "",
1310
+ environment: r?.environment,
1311
+ applicationId: r?.applicationId,
1312
+ publishEndpoint: r?.publishEndpoint,
1313
+ allowDestructive: !1
1314
+ })), U = d(null), W = D.length ? D[D.length - 1].source : b(y(m.app)), G = u(() => v(x(W), m), [W, m]), K = u(() => S(x(W), m), [W, m]);
1315
+ l(() => {
1316
+ if (!e || n) return;
1317
+ let t = !1;
1318
+ return (async () => {
1319
+ try {
1320
+ let n = await e.collection("_flow_apps").all(), r = n.find((e) => e.status === "active") ?? n[0];
1321
+ if (!r || t) return;
1322
+ let i = b(r.spec);
1323
+ s.current || (C(r.spec), p(i)), M(r.version ?? 0);
1324
+ let a = (await e.collection("_flow_app_versions").all()).filter((e) => e.app === r.app).sort((e, t) => e.version - t.version);
1325
+ t || (O(a.map((e) => ({
1326
+ version: e.version,
1327
+ source: b(e.spec),
1328
+ savedAt: e.deployed_at
1329
+ }))), A(`Loaded ${r.app} v${r.version}`));
1330
+ } catch (e) {
1331
+ t || A(`Could not load deployed model: ${e instanceof Error ? e.message : String(e)}`);
1332
+ }
1333
+ })(), () => {
1334
+ t = !0;
1335
+ };
1336
+ }, [e, n]), l(() => {
1337
+ let e = window.setTimeout(() => window.localStorage.setItem(a, c), 200);
1338
+ return () => window.clearTimeout(e);
1339
+ }, [a, c]);
1340
+ let q = (e) => {
1341
+ p(e);
1342
+ try {
1343
+ let t = x(e), n = w(t);
1344
+ C(t), i?.(t), E(n), A(n.some((e) => e.severity === "error") ? "Model has validation errors" : "Draft is valid");
1345
+ } catch (e) {
1346
+ E([{
1347
+ severity: "error",
1348
+ message: e instanceof Error ? e.message : String(e)
1349
+ }]), A("DSL parse failed");
1350
+ }
1351
+ };
1352
+ l(() => {
1353
+ if (!n) return;
1354
+ let e = b(n);
1355
+ p(e), C(n), E(w(n)), A(`Loaded ${n.app} project model`);
1356
+ }, [n]);
1357
+ let J = (e) => {
1358
+ C(e), q(b(e));
1359
+ }, ee = () => {
1360
+ if (!F) return I({ name: "" });
1361
+ let e = F.name.trim();
1362
+ if (!/^[A-Z][A-Za-z0-9_]*$/.test(e)) return I({
1363
+ ...F,
1364
+ error: "Use a capitalized name with no spaces."
1365
+ });
1366
+ if (m.collections.some((t) => t.name === e)) return I({
1367
+ ...F,
1368
+ error: "That collection already exists."
1369
+ });
1370
+ J({
1371
+ ...m,
1372
+ collections: [...m.collections, {
1373
+ name: e,
1374
+ fields: [],
1375
+ indexes: []
1376
+ }]
1377
+ }), I(null);
1378
+ }, te = (e) => P({
1379
+ collection: e,
1380
+ name: "",
1381
+ type: "text",
1382
+ reference: "",
1383
+ optional: !1
1384
+ }), ne = () => {
1385
+ if (!N) return;
1386
+ let e = N.name.trim(), t = m.collections.find((e) => e.name === N.collection);
1387
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)) return P({
1388
+ ...N,
1389
+ error: "Use a letter-led name with no spaces."
1390
+ });
1391
+ if (t?.fields.some((t) => t.name === e)) return P({
1392
+ ...N,
1393
+ error: "That field already exists."
1394
+ });
1395
+ if ([
1396
+ "ref",
1397
+ "enum",
1398
+ "array",
1399
+ "map",
1400
+ "vector"
1401
+ ].includes(N.type) && !N.reference.trim()) return P({
1402
+ ...N,
1403
+ error: "Configure this field type."
1404
+ });
1405
+ let n = N.type === "ref" ? `ref ${N.reference}` : N.type === "enum" ? `enum(${N.reference.split(",").map((e) => e.trim()).filter(Boolean).join(",")})` : N.type === "array" ? `array<${N.reference.trim()}>` : N.type === "map" ? `map<${N.reference.trim()}>` : N.type === "vector" ? `vector<${N.reference.trim()}>` : N.type;
1406
+ J({
1407
+ ...m,
1408
+ collections: m.collections.map((t) => t.name === N.collection ? {
1409
+ ...t,
1410
+ fields: [...t.fields, {
1411
+ name: e,
1412
+ type: n,
1413
+ optional: N.optional
1414
+ }]
1415
+ } : t)
1416
+ }), P(null);
1417
+ }, re = () => {
1418
+ let e = [...D, {
1419
+ version: D.length + 1,
1420
+ source: c,
1421
+ savedAt: Date.now()
1422
+ }];
1423
+ O(e), A(`Saved local revision v${e.length}`);
1424
+ }, ie = async () => {
1425
+ if (!e) return A("Local embedded storage is unavailable");
1426
+ if (T.some((e) => e.severity === "error")) return A("Resolve validation errors before deploying");
1427
+ if (K.filter((e) => e.safety === "destructive").length && !L) return A("Review and approve destructive local changes before applying");
1428
+ try {
1429
+ let t = await e.deployFlowSpec(m, j, L), n = [...D, {
1430
+ version: t.version,
1431
+ source: c,
1432
+ savedAt: Date.now()
1433
+ }];
1434
+ O(n), M(t.version), R(!1), A(`Applied locally as ${t.app} v${t.version}`);
1435
+ } catch (e) {
1436
+ A(`Local apply failed: ${e instanceof Error ? e.message : String(e)}`);
1437
+ }
1438
+ }, X = async () => {
1439
+ if (V.publishEndpoint) {
1440
+ H({
1441
+ ...V,
1442
+ publishing: !0,
1443
+ error: void 0
1444
+ });
1445
+ try {
1446
+ let e = await fetch(V.publishEndpoint, {
1447
+ method: "POST",
1448
+ headers: { "content-type": "application/json" },
1449
+ body: JSON.stringify({
1450
+ environment: V.environment,
1451
+ approveDestructive: V.allowDestructive
1452
+ })
1453
+ }), t = await e.json();
1454
+ if (!e.ok) throw Error(t.error || "Publish failed");
1455
+ H({
1456
+ ...V,
1457
+ publishing: !1,
1458
+ error: void 0
1459
+ }), B(!1), A(t.messages?.at(-1) || `Published immutable version ${t.version}`);
1460
+ return;
1461
+ } catch (e) {
1462
+ H({
1463
+ ...V,
1464
+ publishing: !1,
1465
+ error: e instanceof Error ? e.message : String(e)
1466
+ });
1467
+ return;
1468
+ }
1469
+ }
1470
+ if (!V.url.trim() || !V.token.trim()) return H({
1471
+ ...V,
1472
+ error: "Cloud URL and API key are required."
1473
+ });
1474
+ if (T.some((e) => e.severity === "error")) return H({
1475
+ ...V,
1476
+ error: "Resolve validation errors before publishing."
1477
+ });
1478
+ H({
1479
+ ...V,
1480
+ publishing: !0,
1481
+ error: void 0
1482
+ });
1483
+ let e = _({
1484
+ namespace: V.namespace.trim() || t,
1485
+ server: {
1486
+ url: V.url.trim().replace(/\/$/, ""),
1487
+ token: V.token
1488
+ }
1489
+ });
1490
+ try {
1491
+ let t = await e.collection("_flow_apps").get(m.app), n = S(t?.spec ?? y(m.app), m).filter((e) => e.safety === "destructive");
1492
+ if (n.length && !V.allowDestructive) return H({
1493
+ ...V,
1494
+ publishing: !1,
1495
+ destructive: n.map((e) => e.target),
1496
+ error: `Review and approve destructive changes: ${n.map((e) => e.target).join(", ")}`
1497
+ });
1498
+ let r = await e.deployFlowSpec(m, t?.version ?? 0, V.allowDestructive);
1499
+ window.sessionStorage.setItem(`feltdb-token:${V.url.trim()}`, V.token), H({
1500
+ ...V,
1501
+ publishing: !1,
1502
+ error: void 0
1503
+ }), B(!1), A(`Published ${r.app} v${r.version} to ${V.environment || "cloud"}`);
1504
+ } catch (e) {
1505
+ H({
1506
+ ...V,
1507
+ publishing: !1,
1508
+ error: e instanceof Error ? e.message : String(e)
1509
+ });
1510
+ } finally {
1511
+ await e.close();
1512
+ }
1513
+ }, ae = () => {
1514
+ let e = URL.createObjectURL(new Blob([c], { type: "text/plain" })), t = document.createElement("a");
1515
+ t.href = e, t.download = "feltdb.flow", t.click(), URL.revokeObjectURL(e);
1516
+ }, oe = async (e) => {
1517
+ e && q(await e.text());
1518
+ }, se = [
1519
+ ["Data", m.collections.map((e) => e.name)],
1520
+ ["Capabilities", m.capabilities.map((e) => e.name)],
1521
+ ["Agents", m.agents.map((e) => e.name)],
1522
+ ["Workflows", m.workflows.map((e) => e.name)],
1523
+ ["Triggers", m.triggers.map((e) => e.event)],
1524
+ ["Policies", m.policies.map((e) => e.name)],
1525
+ ["Schedules", m.schedules.map((e) => e.name)]
1526
+ ];
1527
+ return /* @__PURE__ */ g("div", {
1528
+ className: "application-designer",
1529
+ children: [
1530
+ /* @__PURE__ */ g("header", {
1531
+ className: "designer-header",
1532
+ children: [/* @__PURE__ */ g("div", { children: [
1533
+ /* @__PURE__ */ h("span", {
1534
+ className: "eyebrow",
1535
+ children: "Application fabric"
1536
+ }),
1537
+ /* @__PURE__ */ h("h1", { children: m.app }),
1538
+ /* @__PURE__ */ h("p", { children: "One model for state, intelligence, automation, security, and placement." })
1539
+ ] }), /* @__PURE__ */ g("div", {
1540
+ className: "designer-actions",
1541
+ children: [
1542
+ /* @__PURE__ */ h("input", {
1543
+ ref: U,
1544
+ hidden: !0,
1545
+ type: "file",
1546
+ accept: ".flow,text/plain",
1547
+ onChange: (e) => void oe(e.target.files?.[0])
1548
+ }),
1549
+ /* @__PURE__ */ h("button", {
1550
+ className: "btn btn-ghost",
1551
+ onClick: () => U.current?.click(),
1552
+ children: "Import"
1553
+ }),
1554
+ /* @__PURE__ */ h("button", {
1555
+ className: "btn btn-ghost",
1556
+ onClick: ae,
1557
+ children: "Export"
1558
+ }),
1559
+ /* @__PURE__ */ h("button", {
1560
+ className: "btn btn-ghost",
1561
+ onClick: re,
1562
+ children: "Version"
1563
+ }),
1564
+ /* @__PURE__ */ h("button", {
1565
+ className: "btn btn-ghost",
1566
+ onClick: () => void ie(),
1567
+ children: "Apply locally"
1568
+ }),
1569
+ /* @__PURE__ */ h("button", {
1570
+ className: "btn btn-primary",
1571
+ onClick: () => B((e) => !e),
1572
+ children: "Publish to cloud"
1573
+ })
1574
+ ]
1575
+ })]
1576
+ }),
1577
+ K.some((e) => e.safety === "destructive") && /* @__PURE__ */ g("label", {
1578
+ className: "local-destructive",
1579
+ children: [/* @__PURE__ */ h("input", {
1580
+ type: "checkbox",
1581
+ checked: L,
1582
+ onChange: (e) => R(e.target.checked)
1583
+ }), /* @__PURE__ */ g("span", { children: ["Approve destructive local changes: ", K.filter((e) => e.safety === "destructive").map((e) => e.target).join(", ")] })]
1584
+ }),
1585
+ z && /* @__PURE__ */ g("form", {
1586
+ className: "cloud-publisher",
1587
+ onSubmit: (e) => {
1588
+ e.preventDefault(), X();
1589
+ },
1590
+ children: [
1591
+ /* @__PURE__ */ g("div", {
1592
+ className: "cloud-publisher-heading",
1593
+ children: [/* @__PURE__ */ g("div", { children: [
1594
+ /* @__PURE__ */ h("span", {
1595
+ className: "eyebrow",
1596
+ children: "Cloud release"
1597
+ }),
1598
+ /* @__PURE__ */ h("h2", { children: "Publish this application definition" }),
1599
+ /* @__PURE__ */ h("p", { children: "FeltDB validates an immutable revision and atomically promotes the environment." })
1600
+ ] }), /* @__PURE__ */ h("button", {
1601
+ type: "button",
1602
+ "aria-label": "Close cloud publisher",
1603
+ onClick: () => B(!1),
1604
+ children: "×"
1605
+ })]
1606
+ }),
1607
+ /* @__PURE__ */ g("div", {
1608
+ className: "cloud-fields",
1609
+ children: [
1610
+ /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "FeltDB Cloud URL" }), /* @__PURE__ */ h("input", {
1611
+ type: "url",
1612
+ value: V.url,
1613
+ readOnly: !!V.publishEndpoint,
1614
+ onChange: (e) => H({
1615
+ ...V,
1616
+ url: e.target.value,
1617
+ error: void 0,
1618
+ destructive: void 0,
1619
+ allowDestructive: !1
1620
+ })
1621
+ })] }),
1622
+ /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Namespace" }), /* @__PURE__ */ h("input", {
1623
+ value: V.namespace,
1624
+ readOnly: !!V.publishEndpoint,
1625
+ onChange: (e) => H({
1626
+ ...V,
1627
+ namespace: e.target.value,
1628
+ error: void 0,
1629
+ destructive: void 0,
1630
+ allowDestructive: !1
1631
+ })
1632
+ })] }),
1633
+ !V.publishEndpoint && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "API key" }), /* @__PURE__ */ h("input", {
1634
+ type: "password",
1635
+ autoComplete: "off",
1636
+ placeholder: "Loaded securely from this project",
1637
+ value: V.token,
1638
+ onChange: (e) => H({
1639
+ ...V,
1640
+ token: e.target.value,
1641
+ error: void 0
1642
+ })
1643
+ })] }),
1644
+ V.environment && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Environment" }), /* @__PURE__ */ h("input", {
1645
+ value: V.environment,
1646
+ readOnly: !0
1647
+ })] }),
1648
+ V.applicationId && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Application" }), /* @__PURE__ */ h("input", {
1649
+ value: V.applicationId,
1650
+ readOnly: !0
1651
+ })] })
1652
+ ]
1653
+ }),
1654
+ (V.destructive?.length || K.some((e) => e.safety === "destructive")) && /* @__PURE__ */ g("label", {
1655
+ className: "cloud-destructive",
1656
+ children: [/* @__PURE__ */ h("input", {
1657
+ type: "checkbox",
1658
+ checked: V.allowDestructive,
1659
+ onChange: (e) => H({
1660
+ ...V,
1661
+ allowDestructive: e.target.checked
1662
+ })
1663
+ }), /* @__PURE__ */ g("span", { children: ["I reviewed and approve destructive model changes", V.destructive?.length ? `: ${V.destructive.join(", ")}` : "."] })]
1664
+ }),
1665
+ V.error && /* @__PURE__ */ h("div", {
1666
+ className: "cloud-error",
1667
+ role: "alert",
1668
+ children: V.error
1669
+ }),
1670
+ /* @__PURE__ */ g("div", {
1671
+ className: "cloud-actions",
1672
+ children: [/* @__PURE__ */ h("button", {
1673
+ type: "button",
1674
+ className: "btn btn-ghost",
1675
+ onClick: () => B(!1),
1676
+ children: "Cancel"
1677
+ }), /* @__PURE__ */ h("button", {
1678
+ className: "btn btn-primary",
1679
+ disabled: V.publishing,
1680
+ type: "submit",
1681
+ children: V.publishing ? "Publishing…" : "Review and publish"
1682
+ })]
1683
+ })
1684
+ ]
1685
+ }),
1686
+ /* @__PURE__ */ g("div", {
1687
+ className: `designer-status ${T.some((e) => e.severity === "error") ? "error" : ""}`,
1688
+ children: [/* @__PURE__ */ h("span", { children: k }), /* @__PURE__ */ g("span", { children: [
1689
+ m.collections.length,
1690
+ " collections · ",
1691
+ m.workflows.length,
1692
+ " workflows · ",
1693
+ D.length ? `v${D.length}` : "draft"
1694
+ ] })]
1695
+ }),
1696
+ /* @__PURE__ */ g("div", {
1697
+ className: "designer-grid",
1698
+ children: [
1699
+ /* @__PURE__ */ g("aside", {
1700
+ className: "model-tree",
1701
+ children: [
1702
+ /* @__PURE__ */ g("div", {
1703
+ className: "panel-title",
1704
+ children: [/* @__PURE__ */ h("span", { children: "Application" }), /* @__PURE__ */ h("button", {
1705
+ "aria-label": "Add collection",
1706
+ onClick: () => I({ name: "" }),
1707
+ children: "+"
1708
+ })]
1709
+ }),
1710
+ F && /* @__PURE__ */ g("form", {
1711
+ className: "collection-editor",
1712
+ onSubmit: (e) => {
1713
+ e.preventDefault(), ee();
1714
+ },
1715
+ onKeyDown: (e) => {
1716
+ e.key === "Escape" && I(null);
1717
+ },
1718
+ children: [
1719
+ /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "New collection" }), /* @__PURE__ */ h("input", {
1720
+ autoFocus: !0,
1721
+ placeholder: "e.g. Customer",
1722
+ value: F.name,
1723
+ onChange: (e) => I({ name: e.target.value })
1724
+ })] }),
1725
+ F.error && /* @__PURE__ */ h("div", {
1726
+ className: "field-error",
1727
+ role: "alert",
1728
+ children: F.error
1729
+ }),
1730
+ /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("button", {
1731
+ type: "button",
1732
+ onClick: () => I(null),
1733
+ children: "Cancel"
1734
+ }), /* @__PURE__ */ h("button", {
1735
+ className: "collection-save",
1736
+ type: "submit",
1737
+ children: "Add"
1738
+ })] })
1739
+ ]
1740
+ }),
1741
+ se.map(([e, t]) => /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h3", { children: e }), t.length ? t.map((e) => /* @__PURE__ */ h("div", {
1742
+ className: "tree-item",
1743
+ children: e
1744
+ }, e)) : /* @__PURE__ */ h("div", {
1745
+ className: "tree-empty",
1746
+ children: "None"
1747
+ })] }, e))
1748
+ ]
1749
+ }),
1750
+ /* @__PURE__ */ g("section", {
1751
+ className: "model-canvas",
1752
+ children: [
1753
+ /* @__PURE__ */ g("div", {
1754
+ className: "panel-title",
1755
+ children: [/* @__PURE__ */ h("span", { children: "Application graph" }), /* @__PURE__ */ h("span", {
1756
+ className: "graph-legend",
1757
+ children: "intent → fabric"
1758
+ })]
1759
+ }),
1760
+ /* @__PURE__ */ g("div", {
1761
+ className: "graph-board",
1762
+ children: [
1763
+ m.collections.map((e) => /* @__PURE__ */ g("article", {
1764
+ className: "model-node",
1765
+ children: [
1766
+ /* @__PURE__ */ h("div", {
1767
+ className: "node-kind",
1768
+ children: "collection"
1769
+ }),
1770
+ /* @__PURE__ */ h("h3", { children: e.name }),
1771
+ e.fields.map((e) => /* @__PURE__ */ g("div", {
1772
+ className: "node-field",
1773
+ children: [/* @__PURE__ */ h("span", { children: e.name }), /* @__PURE__ */ g("code", { children: [e.type, e.optional ? "?" : ""] })]
1774
+ }, e.name)),
1775
+ N?.collection === e.name ? /* @__PURE__ */ g("form", {
1776
+ className: "field-editor",
1777
+ onSubmit: (e) => {
1778
+ e.preventDefault(), ne();
1779
+ },
1780
+ onKeyDown: (e) => {
1781
+ e.key === "Escape" && P(null);
1782
+ },
1783
+ children: [
1784
+ /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Field name" }), /* @__PURE__ */ h("input", {
1785
+ autoFocus: !0,
1786
+ value: N.name,
1787
+ placeholder: "e.g. publishedAt",
1788
+ onChange: (e) => P({
1789
+ ...N,
1790
+ name: e.target.value,
1791
+ error: void 0
1792
+ })
1793
+ })] }),
1794
+ /* @__PURE__ */ g("div", {
1795
+ className: "field-editor-row",
1796
+ children: [
1797
+ /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Type" }), /* @__PURE__ */ g("select", {
1798
+ value: N.type,
1799
+ onChange: (e) => P({
1800
+ ...N,
1801
+ type: e.target.value,
1802
+ error: void 0
1803
+ }),
1804
+ children: [
1805
+ /* @__PURE__ */ h("option", {
1806
+ value: "text",
1807
+ children: "Text"
1808
+ }),
1809
+ /* @__PURE__ */ h("option", {
1810
+ value: "integer",
1811
+ children: "Integer"
1812
+ }),
1813
+ /* @__PURE__ */ h("option", {
1814
+ value: "number",
1815
+ children: "Number"
1816
+ }),
1817
+ /* @__PURE__ */ h("option", {
1818
+ value: "decimal",
1819
+ children: "Decimal"
1820
+ }),
1821
+ /* @__PURE__ */ h("option", {
1822
+ value: "money",
1823
+ children: "Money"
1824
+ }),
1825
+ /* @__PURE__ */ h("option", {
1826
+ value: "bigint",
1827
+ children: "Big integer"
1828
+ }),
1829
+ /* @__PURE__ */ h("option", {
1830
+ value: "boolean",
1831
+ children: "Boolean"
1832
+ }),
1833
+ /* @__PURE__ */ h("option", {
1834
+ value: "datetime",
1835
+ children: "Date & time"
1836
+ }),
1837
+ /* @__PURE__ */ h("option", {
1838
+ value: "date",
1839
+ children: "Date"
1840
+ }),
1841
+ /* @__PURE__ */ h("option", {
1842
+ value: "time",
1843
+ children: "Time"
1844
+ }),
1845
+ /* @__PURE__ */ h("option", {
1846
+ value: "uuid",
1847
+ children: "UUID"
1848
+ }),
1849
+ /* @__PURE__ */ h("option", {
1850
+ value: "email",
1851
+ children: "Email"
1852
+ }),
1853
+ /* @__PURE__ */ h("option", {
1854
+ value: "url",
1855
+ children: "URL"
1856
+ }),
1857
+ /* @__PURE__ */ h("option", {
1858
+ value: "phone",
1859
+ children: "Phone"
1860
+ }),
1861
+ /* @__PURE__ */ h("option", {
1862
+ value: "json",
1863
+ children: "JSON"
1864
+ }),
1865
+ /* @__PURE__ */ h("option", {
1866
+ value: "object",
1867
+ children: "Object"
1868
+ }),
1869
+ /* @__PURE__ */ h("option", {
1870
+ value: "binary",
1871
+ children: "Binary"
1872
+ }),
1873
+ /* @__PURE__ */ h("option", {
1874
+ value: "file",
1875
+ children: "File"
1876
+ }),
1877
+ /* @__PURE__ */ h("option", {
1878
+ value: "geo",
1879
+ children: "Geo point"
1880
+ }),
1881
+ /* @__PURE__ */ h("option", {
1882
+ value: "enum",
1883
+ children: "Enum"
1884
+ }),
1885
+ /* @__PURE__ */ h("option", {
1886
+ value: "array",
1887
+ children: "Array"
1888
+ }),
1889
+ /* @__PURE__ */ h("option", {
1890
+ value: "map",
1891
+ children: "Typed map"
1892
+ }),
1893
+ /* @__PURE__ */ h("option", {
1894
+ value: "vector",
1895
+ children: "Vector"
1896
+ }),
1897
+ /* @__PURE__ */ h("option", {
1898
+ value: "ref",
1899
+ children: "Reference"
1900
+ })
1901
+ ]
1902
+ })] }),
1903
+ N.type === "ref" && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Collection" }), /* @__PURE__ */ h("select", {
1904
+ value: N.reference,
1905
+ onChange: (e) => P({
1906
+ ...N,
1907
+ reference: e.target.value,
1908
+ error: void 0
1909
+ }),
1910
+ children: m.collections.filter((t) => t.name !== e.name).map((e) => /* @__PURE__ */ h("option", {
1911
+ value: e.name,
1912
+ children: e.name
1913
+ }, e.name))
1914
+ })] }),
1915
+ N.type === "enum" && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Values" }), /* @__PURE__ */ h("input", {
1916
+ placeholder: "draft,active,done",
1917
+ value: N.reference,
1918
+ onChange: (e) => P({
1919
+ ...N,
1920
+ reference: e.target.value,
1921
+ error: void 0
1922
+ })
1923
+ })] }),
1924
+ (N.type === "array" || N.type === "map") && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Item type" }), /* @__PURE__ */ h("input", {
1925
+ placeholder: "text, uuid, ref Project…",
1926
+ value: N.reference,
1927
+ onChange: (e) => P({
1928
+ ...N,
1929
+ reference: e.target.value,
1930
+ error: void 0
1931
+ })
1932
+ })] }),
1933
+ N.type === "vector" && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("span", { children: "Dimensions" }), /* @__PURE__ */ h("input", {
1934
+ type: "number",
1935
+ min: "1",
1936
+ placeholder: "1536",
1937
+ value: N.reference,
1938
+ onChange: (e) => P({
1939
+ ...N,
1940
+ reference: e.target.value,
1941
+ error: void 0
1942
+ })
1943
+ })] })
1944
+ ]
1945
+ }),
1946
+ /* @__PURE__ */ g("label", {
1947
+ className: "field-optional",
1948
+ children: [/* @__PURE__ */ h("input", {
1949
+ type: "checkbox",
1950
+ checked: N.optional,
1951
+ onChange: (e) => P({
1952
+ ...N,
1953
+ optional: e.target.checked
1954
+ })
1955
+ }), /* @__PURE__ */ h("span", { children: "Optional field" })]
1956
+ }),
1957
+ N.error && /* @__PURE__ */ h("div", {
1958
+ className: "field-error",
1959
+ role: "alert",
1960
+ children: N.error
1961
+ }),
1962
+ /* @__PURE__ */ g("div", {
1963
+ className: "field-editor-actions",
1964
+ children: [/* @__PURE__ */ h("button", {
1965
+ type: "button",
1966
+ onClick: () => P(null),
1967
+ children: "Cancel"
1968
+ }), /* @__PURE__ */ h("button", {
1969
+ className: "field-save",
1970
+ type: "submit",
1971
+ children: "Add field"
1972
+ })]
1973
+ })
1974
+ ]
1975
+ }) : /* @__PURE__ */ h("button", {
1976
+ className: "node-add",
1977
+ onClick: () => te(e.name),
1978
+ children: "+ field"
1979
+ })
1980
+ ]
1981
+ }, e.name)),
1982
+ m.workflows.map((e) => /* @__PURE__ */ g("article", {
1983
+ className: "model-node workflow-node",
1984
+ children: [
1985
+ /* @__PURE__ */ h("div", {
1986
+ className: "node-kind",
1987
+ children: "workflow"
1988
+ }),
1989
+ /* @__PURE__ */ h("h3", { children: e.name }),
1990
+ e.steps.map((e) => /* @__PURE__ */ h("div", {
1991
+ className: "node-step",
1992
+ children: e.name
1993
+ }, e.name))
1994
+ ]
1995
+ }, e.name)),
1996
+ m.agents.map((e) => /* @__PURE__ */ g("article", {
1997
+ className: "model-node agent-node",
1998
+ children: [
1999
+ /* @__PURE__ */ h("div", {
2000
+ className: "node-kind",
2001
+ children: "agent"
2002
+ }),
2003
+ /* @__PURE__ */ h("h3", { children: e.name }),
2004
+ e.statements.map((e) => /* @__PURE__ */ h("div", {
2005
+ className: "node-step",
2006
+ children: e
2007
+ }, e))
2008
+ ]
2009
+ }, e.name))
2010
+ ]
2011
+ }),
2012
+ /* @__PURE__ */ g("div", {
2013
+ className: "change-strip",
2014
+ children: [
2015
+ /* @__PURE__ */ h("strong", { children: "Model diff" }),
2016
+ /* @__PURE__ */ g("span", {
2017
+ className: "added",
2018
+ children: ["+ ", G.added.join(", ") || "none"]
2019
+ }),
2020
+ /* @__PURE__ */ g("span", {
2021
+ className: "changed",
2022
+ children: ["~ ", G.changed.join(", ") || "none"]
2023
+ }),
2024
+ /* @__PURE__ */ g("span", {
2025
+ className: "removed",
2026
+ children: ["− ", G.removed.join(", ") || "none"]
2027
+ })
2028
+ ]
2029
+ })
2030
+ ]
2031
+ }),
2032
+ /* @__PURE__ */ g("section", {
2033
+ className: "dsl-panel",
2034
+ children: [
2035
+ /* @__PURE__ */ g("div", {
2036
+ className: "panel-title",
2037
+ children: [/* @__PURE__ */ h("span", { children: "Flow DSL" }), /* @__PURE__ */ h("span", { children: "feltdb.flow" })]
2038
+ }),
2039
+ /* @__PURE__ */ h("textarea", {
2040
+ "aria-label": "Flow DSL",
2041
+ spellCheck: !1,
2042
+ value: c,
2043
+ onChange: (e) => q(e.target.value)
2044
+ }),
2045
+ T.length > 0 && /* @__PURE__ */ h("div", {
2046
+ className: "diagnostics",
2047
+ children: T.map((e, t) => /* @__PURE__ */ g("div", {
2048
+ className: e.severity,
2049
+ children: [
2050
+ e.severity,
2051
+ ": ",
2052
+ e.message
2053
+ ]
2054
+ }, t))
2055
+ })
2056
+ ]
2057
+ })
2058
+ ]
2059
+ })
2060
+ ]
2061
+ });
2062
+ }
2063
+ //#endregion
2064
+ //#region src/components/AskFeltDB.tsx
2065
+ function te({ configuration: e, onApplied: t, onProposalCreated: n }) {
2066
+ let [r, i] = f(""), [a, o] = f(), [s, c] = f(), [l, u] = f(""), [d, p] = f(0), [_, v] = f(!1), [y, b] = f([]), S = typeof navigator < "u" && "gpu" in navigator, C = e?.aiModel?.provider === "openai-compatible", w = !!(e?.enabled && (C ? e.aiModel?.credentialConfigured : e.webllmEnabled && S)), T = async () => {
2067
+ if (!(!w || !e)) {
2068
+ u("Loading local model…"), c(void 0), o(void 0);
2069
+ try {
2070
+ let t = await fetch("/_feltdb/contract", { cache: "no-store" }), i = await t.json();
2071
+ if (!t.ok) throw Error(i.error || "Could not load contract");
2072
+ if (i.drift && !i.drift.synchronized) throw Error("Contract drift detected. Review feltdb status before generating.");
2073
+ let a;
2074
+ if (C) {
2075
+ u(`Asking ${e.aiModel?.model} through the local CLI…`);
2076
+ let t = await fetch("/_feltdb/ai/generate", {
2077
+ method: "POST",
2078
+ headers: {
2079
+ "content-type": "application/json",
2080
+ "x-feltdb-studio-token": e.token
2081
+ },
2082
+ body: JSON.stringify({ intent: r })
2083
+ }), n = await t.json();
2084
+ if (!t.ok) throw Error(n.error || "Configured model failed");
2085
+ a = n.proposal;
2086
+ } else {
2087
+ let { WebLLMProvider: t } = await import("@feltdb/webllm"), n = new t({
2088
+ model: e.aiModel?.model,
2089
+ contract: i.snapshot,
2090
+ onProgress: (e) => {
2091
+ p(e.progress), u(e.text);
2092
+ }
2093
+ });
2094
+ try {
2095
+ a = await n.generateFlow(r, { currentFlow: i.source });
2096
+ } finally {
2097
+ await n.shutdown();
2098
+ }
2099
+ }
2100
+ let s = await fetch("/_feltdb/proposals", {
2101
+ method: "POST",
2102
+ headers: {
2103
+ "content-type": "application/json",
2104
+ "x-feltdb-studio-token": e.token
2105
+ },
2106
+ body: JSON.stringify({ proposal: a })
2107
+ }), l = await s.json();
2108
+ if (!s.ok) throw Error(l.error || "Proposal validation failed");
2109
+ o(a), c(l), l.proposalId && l.proposalId !== "ephemeral" && n?.(l.proposalId), b(x(a.proposedFlow).collections.map((e) => ({
2110
+ name: e.name,
2111
+ fields: e.fields.map((e) => e.name)
2112
+ }))), u("Validated proposal ready for review");
2113
+ } catch (e) {
2114
+ u(e instanceof Error ? e.message : String(e));
2115
+ }
2116
+ }
2117
+ }, E = async (t) => {
2118
+ if (!(!s || !e)) {
2119
+ u(t === "approve" ? "Recording approval…" : "Rejecting preview…");
2120
+ try {
2121
+ let n = await fetch(`/_feltdb/proposals/${t}`, {
2122
+ method: "POST",
2123
+ headers: {
2124
+ "content-type": "application/json",
2125
+ "x-feltdb-studio-token": e.token
2126
+ },
2127
+ body: JSON.stringify({
2128
+ proposalId: s.proposalId,
2129
+ confirm: !0,
2130
+ approveAuthorization: _
2131
+ })
2132
+ }), r = await n.json();
2133
+ if (!n.ok) throw Error(r.error || "Proposal decision failed");
2134
+ t === "approve" ? u(`Approved. Run ${r.command} in your project to synchronize the repository.`) : (o(void 0), c(void 0), b([]), u("Preview rejected. The application and repository are unchanged."));
2135
+ } catch (e) {
2136
+ u(e instanceof Error ? e.message : String(e));
2137
+ }
2138
+ }
2139
+ };
2140
+ return /* @__PURE__ */ g("section", {
2141
+ className: "ask-feltdb",
2142
+ children: [
2143
+ /* @__PURE__ */ g("div", { children: [
2144
+ /* @__PURE__ */ h("span", {
2145
+ className: "eyebrow",
2146
+ children: "Contract-aware proposal engine"
2147
+ }),
2148
+ /* @__PURE__ */ h("h2", { children: "Ask FeltDB" }),
2149
+ /* @__PURE__ */ h("p", { children: "Describe a contract change. Your selected model proposes; FeltDB validates, and the CLI owns source synchronization." })
2150
+ ] }),
2151
+ /* @__PURE__ */ g("p", {
2152
+ className: "ai-model-choice",
2153
+ children: [
2154
+ "Model: ",
2155
+ /* @__PURE__ */ h("strong", { children: e?.aiModel?.model ?? "SmolLM2-360M-Instruct" }),
2156
+ " (",
2157
+ C ? "bring-your-own provider; credential held by CLI" : "private local WebLLM",
2158
+ "). Change it with ",
2159
+ /* @__PURE__ */ h("code", { children: "feltdb ai model set" }),
2160
+ "."
2161
+ ]
2162
+ }),
2163
+ C && !e?.aiModel?.credentialConfigured ? /* @__PURE__ */ g("p", {
2164
+ className: "ai-unavailable",
2165
+ children: [
2166
+ "The selected hosted model needs a credential. Pipe it securely with ",
2167
+ /* @__PURE__ */ h("code", { children: "printf %s \"$KEY\" | feltdb ai model set ... --api-key-stdin" }),
2168
+ "."
2169
+ ]
2170
+ }) : !C && !e?.webllmEnabled ? /* @__PURE__ */ g("p", {
2171
+ className: "ai-unavailable",
2172
+ children: [
2173
+ "Local AI is not enabled for this project. Install ",
2174
+ /* @__PURE__ */ h("code", { children: "@feltdb/webllm" }),
2175
+ " to opt in, or configure your own model with ",
2176
+ /* @__PURE__ */ h("code", { children: "feltdb ai model set" }),
2177
+ "."
2178
+ ]
2179
+ }) : !C && !S ? /* @__PURE__ */ h("p", {
2180
+ className: "ai-unavailable",
2181
+ children: "Local FeltDB AI is unavailable because WebGPU is not available. You can configure an OpenAI-compatible model instead."
2182
+ }) : /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("textarea", {
2183
+ "aria-label": "Ask FeltDB",
2184
+ value: r,
2185
+ onChange: (e) => i(e.target.value),
2186
+ placeholder: "Add invitations so organization owners can invite users."
2187
+ }), /* @__PURE__ */ h("button", {
2188
+ className: "btn btn-primary",
2189
+ disabled: !r.trim(),
2190
+ onClick: () => void T(),
2191
+ children: "Generate proposal"
2192
+ })] }),
2193
+ d > 0 && d < 1 && /* @__PURE__ */ h("progress", {
2194
+ value: d,
2195
+ max: 1
2196
+ }),
2197
+ " ",
2198
+ l && /* @__PURE__ */ h("p", {
2199
+ className: "ai-status",
2200
+ children: l
2201
+ }),
2202
+ a && s && /* @__PURE__ */ g("div", {
2203
+ className: "proposal-review",
2204
+ children: [
2205
+ /* @__PURE__ */ h("h3", { children: "Ephemeral application preview" }),
2206
+ /* @__PURE__ */ h("p", { children: a.summary }),
2207
+ /* @__PURE__ */ h("ul", { children: s.changes.map((e) => /* @__PURE__ */ h("li", { children: e }, e)) }),
2208
+ /* @__PURE__ */ g("div", {
2209
+ className: "proposal-app-preview",
2210
+ "aria-label": "Proposed application preview",
2211
+ children: [/* @__PURE__ */ h("nav", { children: y.map((e) => /* @__PURE__ */ h("span", { children: e.name }, e.name)) }), y.map((e) => /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("strong", { children: e.name }), /* @__PURE__ */ h("small", { children: e.fields.join(" · ") || "No fields" })] }, e.name))]
2212
+ }),
2213
+ a.implementation && /* @__PURE__ */ g("section", { children: [
2214
+ /* @__PURE__ */ h("h4", { children: "Module implementation" }),
2215
+ /* @__PURE__ */ g("p", { children: [
2216
+ /* @__PURE__ */ h("strong", { children: a.implementation.module.name }),
2217
+ " · owner ",
2218
+ a.implementation.owner
2219
+ ] }),
2220
+ /* @__PURE__ */ h("pre", { children: a.implementation.stateFlow.join(" → ") }),
2221
+ /* @__PURE__ */ h("p", { children: a.implementation.applicationModels.map((e) => `${e.name}: ${e.ownership}`).join(" · ") })
2222
+ ] }),
2223
+ /* @__PURE__ */ g("p", { children: [
2224
+ /* @__PURE__ */ h("strong", { children: "Source impact" }),
2225
+ ": ",
2226
+ s.sourcePlan.join(", ")
2227
+ ] }),
2228
+ a.warnings.length > 0 && /* @__PURE__ */ h("div", {
2229
+ className: "proposal-warning",
2230
+ children: a.warnings.join(" · ")
2231
+ }),
2232
+ s.authorizationChanges.length > 0 && /* @__PURE__ */ g("div", { children: [s.authorizationChanges.map((e) => /* @__PURE__ */ g("div", {
2233
+ className: "proposal-warning",
2234
+ children: [
2235
+ /* @__PURE__ */ g("strong", { children: ["AUTHORIZATION CHANGE", e.widening ? " — POSSIBLE WIDENING" : ""] }),
2236
+ /* @__PURE__ */ h("br", {}),
2237
+ e.policy,
2238
+ /* @__PURE__ */ h("br", {}),
2239
+ /* @__PURE__ */ g("code", { children: [
2240
+ (e.before ?? ["<absent>"]).join(" | "),
2241
+ " → ",
2242
+ (e.after ?? ["<removed>"]).join(" | ")
2243
+ ] })
2244
+ ]
2245
+ }, e.policy)), /* @__PURE__ */ g("label", {
2246
+ className: "authorization-approval",
2247
+ children: [/* @__PURE__ */ h("input", {
2248
+ type: "checkbox",
2249
+ checked: _,
2250
+ onChange: (e) => v(e.target.checked)
2251
+ }), /* @__PURE__ */ h("span", { children: "I explicitly approve this authorization change." })]
2252
+ })] }),
2253
+ /* @__PURE__ */ g("details", { children: [/* @__PURE__ */ h("summary", { children: "Proposed feltdb.flow" }), /* @__PURE__ */ h("pre", { children: a.proposedFlow })] }),
2254
+ !e?.previewOnly && /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("button", {
2255
+ className: "btn btn-primary",
2256
+ disabled: s.authorizationChanges.length > 0 && !_,
2257
+ onClick: () => void E("approve"),
2258
+ children: "Approve proposal"
2259
+ }), /* @__PURE__ */ h("button", {
2260
+ className: "btn",
2261
+ onClick: () => void E("reject"),
2262
+ children: "Reject preview"
2263
+ })] }),
2264
+ e?.previewOnly && /* @__PURE__ */ g("p", {
2265
+ className: "proposal-boundary",
2266
+ children: [/* @__PURE__ */ h("strong", { children: "Preview-only session:" }), " no proposal artifact or source file will be written."]
2267
+ }),
2268
+ /* @__PURE__ */ h("p", {
2269
+ className: "proposal-boundary",
2270
+ children: "This preview is ephemeral. Approval records a proposal artifact; Studio never writes application source, changes the running contract, or publishes."
2271
+ })
2272
+ ]
2273
+ })
2274
+ ]
2275
+ });
2276
+ }
2277
+ //#endregion
2278
+ //#region src/components/ProposalBrowser.tsx
2279
+ var ne = [
2280
+ "",
2281
+ "proposed",
2282
+ "validated",
2283
+ "previewed",
2284
+ "approved",
2285
+ "applied",
2286
+ "rejected",
2287
+ "expired"
2288
+ ], re = (e) => e ? `${e.slice(0, 12)}…` : "Not recorded", ie = (e) => new Date(typeof e == "number" && e < 1e10 ? e * 1e3 : e).toLocaleString();
2289
+ function X({ name: e, values: t }) {
2290
+ return t.length ? /* @__PURE__ */ g("section", {
2291
+ className: "semantic-section",
2292
+ children: [/* @__PURE__ */ h("h4", { children: e }), t.map((e, t) => /* @__PURE__ */ g("div", { children: ["+ ", e] }, `${e}-${t}`))]
2293
+ }) : null;
2294
+ }
2295
+ function ae({ value: e }) {
2296
+ let t = {
2297
+ contract_changed: "Contract changed since Proposal creation.",
2298
+ flow_changed: "Flow changed since Proposal creation.",
2299
+ module_versions_changed: "Resolved module versions changed.",
2300
+ expired: "Proposal expired."
2301
+ };
2302
+ return /* @__PURE__ */ g("section", {
2303
+ className: `proposal-readiness ${e.readiness}`,
2304
+ children: [
2305
+ /* @__PURE__ */ h("h3", { children: "Readiness" }),
2306
+ /* @__PURE__ */ h("strong", { children: e.readiness === "ready" ? "✓ READY" : "⚠ BLOCKED" }),
2307
+ e.readiness === "ready" ? /* @__PURE__ */ g("ul", { children: [
2308
+ /* @__PURE__ */ h("li", { children: "✓ Contract current" }),
2309
+ /* @__PURE__ */ h("li", { children: "✓ Flow current" }),
2310
+ /* @__PURE__ */ h("li", { children: "✓ Modules resolved" }),
2311
+ /* @__PURE__ */ h("li", { children: "No blockers" })
2312
+ ] }) : /* @__PURE__ */ g(m, { children: [
2313
+ /* @__PURE__ */ h("ul", { children: e.blockers.map((e) => /* @__PURE__ */ h("li", { children: t[e] || e }, e)) }),
2314
+ /* @__PURE__ */ g("dl", { children: [
2315
+ /* @__PURE__ */ h("dt", { children: "Proposal" }),
2316
+ /* @__PURE__ */ h("dd", { children: /* @__PURE__ */ h("code", { children: e.proposal_contract_hash }) }),
2317
+ /* @__PURE__ */ h("dt", { children: "Current" }),
2318
+ /* @__PURE__ */ h("dd", { children: /* @__PURE__ */ h("code", { children: e.current_contract_hash }) })
2319
+ ] }),
2320
+ /* @__PURE__ */ h("p", { children: "Regenerate this Proposal." })
2321
+ ] }),
2322
+ e.notes.length > 0 && /* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("h4", { children: "Notes" }), /* @__PURE__ */ h("ul", { children: e.notes.map((e) => /* @__PURE__ */ h("li", { children: e }, e)) })] })
2323
+ ]
2324
+ });
2325
+ }
2326
+ function oe({ artifact: e }) {
2327
+ let t = e.current_contract ?? e.current, n = e.proposed_contract ?? e.proposed;
2328
+ return /* @__PURE__ */ g("section", {
2329
+ className: "proposal-runtime-preview",
2330
+ children: [/* @__PURE__ */ g("div", {
2331
+ className: "preview-banner",
2332
+ children: [
2333
+ /* @__PURE__ */ h("b", { children: "PROPOSED PREVIEW" }),
2334
+ /* @__PURE__ */ h("br", {}),
2335
+ "Synthetic, isolated state. This is not the live application or repository."
2336
+ ]
2337
+ }), /* @__PURE__ */ g("div", {
2338
+ className: "preview-comparison",
2339
+ children: [
2340
+ /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h4", { children: "Current" }), t.schema.map((e) => /* @__PURE__ */ h("span", { children: e.name }, e.name))] }),
2341
+ /* @__PURE__ */ h("i", { children: "→" }),
2342
+ /* @__PURE__ */ g("section", { children: [
2343
+ /* @__PURE__ */ h("h4", { children: "Proposed" }),
2344
+ n.schema.map((e) => /* @__PURE__ */ h("span", { children: e.name }, e.name)),
2345
+ n.workflows.map((e) => /* @__PURE__ */ h("span", { children: e.name }, e.name))
2346
+ ] })
2347
+ ]
2348
+ })]
2349
+ });
2350
+ }
2351
+ function se({ value: e }) {
2352
+ return /* @__PURE__ */ g("section", {
2353
+ className: `repository-readiness ${e?.ready ? "ready" : "blocked"}`,
2354
+ children: [/* @__PURE__ */ h("h3", { children: "Repository" }), e ? /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("strong", { children: e.ready ? "✓ READY FOR CLI APPLY" : "⚠ BLOCKED" }), /* @__PURE__ */ g("ul", { children: [
2355
+ /* @__PURE__ */ g("li", { children: [
2356
+ e.contractMatches ? "✓" : "⚠",
2357
+ " Contract ",
2358
+ e.contractMatches ? "matches Proposal" : "does not match"
2359
+ ] }),
2360
+ /* @__PURE__ */ g("li", { children: [
2361
+ e.flowMatches ? "✓" : "⚠",
2362
+ " Flow ",
2363
+ e.flowMatches ? "matches Proposal" : "does not match"
2364
+ ] }),
2365
+ /* @__PURE__ */ h("li", { children: e.gitClean ? "✓ Clean" : "⚠ Local source conflicts" }),
2366
+ e.conflicts.map((e) => /* @__PURE__ */ h("li", { children: /* @__PURE__ */ h("code", { children: e }) }, e))
2367
+ ] })] }) : /* @__PURE__ */ g("p", { children: [
2368
+ "Repository context is available when Studio is opened through ",
2369
+ /* @__PURE__ */ h("code", { children: "feltdb studio" }),
2370
+ "."
2371
+ ] })]
2372
+ });
2373
+ }
2374
+ function Z({ serviceUrl: t = "", token: n = "", applicationId: r, environment: d, applicationName: p, sourceSync: _ }) {
2375
+ let v = u(() => new i({
2376
+ baseUrl: t,
2377
+ token: n,
2378
+ applicationId: r,
2379
+ environment: d
2380
+ }), [
2381
+ t,
2382
+ n,
2383
+ r,
2384
+ d
2385
+ ]), [y, b] = f([]), [x, S] = f(), [C, w] = f([]), [T, E] = f(), [D, O] = f(), [k, A] = f(), [j, M] = f(""), [N, P] = f(), [F, I] = f(null), [L, R] = f([]), [z, B] = f(!0), [V, H] = f(""), [U, W] = f(!1), [G, K] = f(!1), [q, J] = f(""), [Y, ee] = f(!1), Z = c(async (t, n = !0) => {
2386
+ B(!0);
2387
+ try {
2388
+ let e = await v.list(j, t);
2389
+ b(e.proposals), P(t), I(e.pagination?.nextCursor ?? null), H("");
2390
+ } catch (r) {
2391
+ if (n && t && r instanceof e && r.code === "invalid_cursor") {
2392
+ R([]), await Z(void 0, !1), H(a(r));
2393
+ return;
2394
+ }
2395
+ H(a(r));
2396
+ } finally {
2397
+ B(!1);
2398
+ }
2399
+ }, [v, j]), Q = c(async (e) => {
2400
+ H("");
2401
+ try {
2402
+ let [t, n, r] = await Promise.all([
2403
+ v.get(e),
2404
+ v.status(e),
2405
+ v.history(e)
2406
+ ]);
2407
+ S(t), E(n), w(r.events), fetch(`/_feltdb/repository-readiness?proposal=${encodeURIComponent(e)}`, { cache: "no-store" }).then((e) => e.ok ? e.json() : void 0).then(A).catch(() => A(void 0)), t.preview_id ? v.preview(t.preview_id).then(O).catch((e) => H(a(e))) : O(void 0);
2408
+ } catch (e) {
2409
+ H(a(e));
2410
+ }
2411
+ }, [v]);
2412
+ l(() => {
2413
+ R([]), Z();
2414
+ }, [Z]), l(() => {
2415
+ if (!x?.id) return;
2416
+ let e = window.setInterval(() => {
2417
+ Q(x.id), Z(N);
2418
+ }, 5e3);
2419
+ return () => window.clearInterval(e);
2420
+ }, [
2421
+ x?.id,
2422
+ Q,
2423
+ Z,
2424
+ N
2425
+ ]);
2426
+ let $ = async () => {
2427
+ await Z(N), x && await Q(x.id);
2428
+ }, ce = async (e) => {
2429
+ if (x) try {
2430
+ e === "approve" ? await v.approve(x.id, Y) : await v.reject(x.id, q || void 0), W(!1), K(!1), await $();
2431
+ } catch (e) {
2432
+ H(a(e));
2433
+ }
2434
+ }, le = async () => {
2435
+ if (x) try {
2436
+ x.status === "proposed" ? await v.validate(x.id) : await v.createPreview(x.id), await $();
2437
+ } catch (e) {
2438
+ H(a(e));
2439
+ }
2440
+ }, ue = x ? o(x) : void 0, de = x?.warnings.some((e) => e.startsWith("Authorization "));
2441
+ return /* @__PURE__ */ g("div", {
2442
+ className: "proposal-workspace",
2443
+ children: [
2444
+ /* @__PURE__ */ g("header", { children: [
2445
+ /* @__PURE__ */ h("span", {
2446
+ className: "eyebrow",
2447
+ children: "Visual control plane"
2448
+ }),
2449
+ /* @__PURE__ */ h("h1", { children: "Proposals" }),
2450
+ /* @__PURE__ */ g("p", { children: [
2451
+ p || r,
2452
+ " · ",
2453
+ d,
2454
+ " · Service API authoritative"
2455
+ ] })
2456
+ ] }),
2457
+ /* @__PURE__ */ h(te, {
2458
+ configuration: _,
2459
+ onProposalCreated: () => void Z()
2460
+ }),
2461
+ V && /* @__PURE__ */ g("div", {
2462
+ className: "data-error",
2463
+ role: "alert",
2464
+ children: [V, /* @__PURE__ */ h("button", {
2465
+ onClick: () => void $(),
2466
+ children: "Refresh"
2467
+ })]
2468
+ }),
2469
+ /* @__PURE__ */ g("div", {
2470
+ className: "proposal-workspace-layout",
2471
+ children: [/* @__PURE__ */ g("aside", {
2472
+ className: "studio-card",
2473
+ children: [
2474
+ /* @__PURE__ */ g("header", { children: [/* @__PURE__ */ h("h2", { children: "Proposals" }), /* @__PURE__ */ h("select", {
2475
+ "aria-label": "Proposal status",
2476
+ value: j,
2477
+ onChange: (e) => M(e.target.value),
2478
+ children: ne.map((e) => /* @__PURE__ */ h("option", {
2479
+ value: e,
2480
+ children: e ? e.toUpperCase() : "ALL STATUSES"
2481
+ }, e || "all"))
2482
+ })] }),
2483
+ z ? /* @__PURE__ */ h("p", { children: "Loading…" }) : y.length ? y.map((e) => /* @__PURE__ */ g("button", {
2484
+ className: `proposal-list-row ${x?.id === e.id ? "active" : ""}`,
2485
+ onClick: () => void Q(e.id),
2486
+ children: [/* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("strong", { children: e.summary }), /* @__PURE__ */ g("small", { children: [
2487
+ e.id,
2488
+ " · ",
2489
+ ie(e.created_at)
2490
+ ] })] }), /* @__PURE__ */ h("b", { children: e.status })]
2491
+ }, e.id)) : /* @__PURE__ */ h("p", { children: "No Proposals yet. Ask FeltDB AI to propose an application change." }),
2492
+ /* @__PURE__ */ g("footer", {
2493
+ className: "data-pagination",
2494
+ children: [/* @__PURE__ */ h("button", {
2495
+ disabled: !L.length,
2496
+ onClick: () => {
2497
+ let e = L.at(-1);
2498
+ R((e) => e.slice(0, -1)), Z(e);
2499
+ },
2500
+ children: "←"
2501
+ }), /* @__PURE__ */ h("button", {
2502
+ disabled: !F,
2503
+ onClick: () => {
2504
+ R((e) => [...e, N]), Z(F || void 0);
2505
+ },
2506
+ children: "→"
2507
+ })]
2508
+ })
2509
+ ]
2510
+ }), /* @__PURE__ */ h("main", {
2511
+ className: "studio-card proposal-detail",
2512
+ children: x ? /* @__PURE__ */ g(m, { children: [
2513
+ /* @__PURE__ */ g("header", { children: [/* @__PURE__ */ g("div", { children: [
2514
+ /* @__PURE__ */ h("span", {
2515
+ className: `proposal-status ${x.status}`,
2516
+ children: x.status
2517
+ }),
2518
+ /* @__PURE__ */ h("h2", { children: x.summary }),
2519
+ x.parent_proposal_id && /* @__PURE__ */ g("p", { children: ["Incremental Proposal · Based on ", /* @__PURE__ */ h("button", {
2520
+ className: "reference-value",
2521
+ onClick: () => void Q(x.parent_proposal_id),
2522
+ children: x.parent_proposal_id
2523
+ })] })
2524
+ ] }), /* @__PURE__ */ g("dl", { children: [
2525
+ /* @__PURE__ */ h("dt", { children: "Application" }),
2526
+ /* @__PURE__ */ h("dd", { children: p || x.application_id }),
2527
+ /* @__PURE__ */ h("dt", { children: "Environment" }),
2528
+ /* @__PURE__ */ h("dd", { children: x.environment }),
2529
+ /* @__PURE__ */ h("dt", { children: "Contract" }),
2530
+ /* @__PURE__ */ g("dd", { children: [
2531
+ "v",
2532
+ x.base_contract_version,
2533
+ " · ",
2534
+ /* @__PURE__ */ h("code", { children: re(x.base_contract_hash) })
2535
+ ] }),
2536
+ /* @__PURE__ */ h("dt", { children: "Flow" }),
2537
+ /* @__PURE__ */ h("dd", { children: /* @__PURE__ */ h("code", { children: re(x.base_flow_hash) }) })
2538
+ ] })] }),
2539
+ x.module_versions.length > 0 && /* @__PURE__ */ h(X, {
2540
+ name: "Modules",
2541
+ values: x.module_versions.map((e) => `${e.id} (${e.provider}) ${e.version}`)
2542
+ }),
2543
+ /* @__PURE__ */ g("section", {
2544
+ className: "semantic-diff",
2545
+ children: [
2546
+ /* @__PURE__ */ h("h3", { children: "Current application → Semantic diff → Proposed application" }),
2547
+ ue && Object.entries(ue).map(([e, t]) => /* @__PURE__ */ h(X, {
2548
+ name: e,
2549
+ values: t
2550
+ }, e)),
2551
+ /* @__PURE__ */ h(X, {
2552
+ name: "Semantic Diff",
2553
+ values: x.contract_diff
2554
+ })
2555
+ ]
2556
+ }),
2557
+ Object.keys(x.module_impact.ownership).length > 0 && /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h3", { children: "State ownership" }), /* @__PURE__ */ h("div", {
2558
+ className: "ownership-grid",
2559
+ children: Object.entries(x.module_impact.ownership).map(([e, t]) => /* @__PURE__ */ g("span", { children: [/* @__PURE__ */ h("strong", { children: e }), /* @__PURE__ */ h("small", { children: t.replace(/_/g, " ") })] }, e))
2560
+ })] }),
2561
+ x.module_impact.state_flow.length > 0 && /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h3", { children: "Reconciliation" }), x.module_impact.state_flow.map((e) => /* @__PURE__ */ h("div", {
2562
+ className: "reconciliation-flow",
2563
+ children: e.split(/\s*->\s*/).map((t, n) => /* @__PURE__ */ g(s.Fragment, { children: [/* @__PURE__ */ h("span", { children: t }), n < e.split(/\s*->\s*/).length - 1 && /* @__PURE__ */ h("i", { children: "↓" })] }, `${t}-${n}`))
2564
+ }, e))] }),
2565
+ (x.module_impact.configuration.length > 0 || x.module_impact.secrets.length > 0) && /* @__PURE__ */ g("section", { children: [
2566
+ /* @__PURE__ */ h("h3", { children: "Configuration" }),
2567
+ x.module_impact.configuration.map((e) => /* @__PURE__ */ g("p", { children: [
2568
+ /* @__PURE__ */ h("strong", { children: e }),
2569
+ /* @__PURE__ */ h("br", {}),
2570
+ /* @__PURE__ */ h("small", { children: "Required · Configuration" })
2571
+ ] }, e)),
2572
+ x.module_impact.secrets.map((e) => /* @__PURE__ */ g("p", { children: [
2573
+ /* @__PURE__ */ h("strong", { children: e }),
2574
+ /* @__PURE__ */ h("br", {}),
2575
+ /* @__PURE__ */ h("small", { children: "Required · Secret · Value never exposed" })
2576
+ ] }, e))
2577
+ ] }),
2578
+ T && /* @__PURE__ */ h(ae, { value: T }),
2579
+ D && /* @__PURE__ */ h(oe, { artifact: D }),
2580
+ /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h3", { children: "Source plan" }), x.source_plan.files.map((e) => /* @__PURE__ */ h("p", { children: /* @__PURE__ */ g("code", { children: [
2581
+ e.operation,
2582
+ " ",
2583
+ e.path
2584
+ ] }) }, e.path))] }),
2585
+ /* @__PURE__ */ h(se, { value: k }),
2586
+ /* @__PURE__ */ g("section", { children: [/* @__PURE__ */ h("h3", { children: "History" }), /* @__PURE__ */ h("ol", {
2587
+ className: "proposal-history",
2588
+ children: C.map((e) => /* @__PURE__ */ g("li", { children: [
2589
+ /* @__PURE__ */ h("strong", { children: e.to_status }),
2590
+ /* @__PURE__ */ h("span", { children: ie(e.created_at) }),
2591
+ /* @__PURE__ */ h("small", { children: e.actor })
2592
+ ] }, e.id))
2593
+ })] }),
2594
+ x.status === "proposed" && /* @__PURE__ */ h("button", {
2595
+ className: "btn btn-primary",
2596
+ onClick: () => void le(),
2597
+ children: "Validate Proposal"
2598
+ }),
2599
+ x.status === "validated" && /* @__PURE__ */ h("button", {
2600
+ className: "btn btn-primary",
2601
+ onClick: () => void le(),
2602
+ children: "Create Proposed Preview"
2603
+ }),
2604
+ x.status === "previewed" && /* @__PURE__ */ g("div", {
2605
+ className: "proposal-actions",
2606
+ children: [/* @__PURE__ */ h("button", {
2607
+ className: "btn btn-primary",
2608
+ disabled: T?.readiness === "blocked",
2609
+ onClick: () => W(!0),
2610
+ children: "Approve Proposal"
2611
+ }), /* @__PURE__ */ h("button", {
2612
+ className: "btn btn-ghost",
2613
+ onClick: () => K(!0),
2614
+ children: "Reject"
2615
+ })]
2616
+ }),
2617
+ ["proposed", "validated"].includes(x.status) && /* @__PURE__ */ h("button", {
2618
+ className: "btn btn-ghost",
2619
+ onClick: () => K(!0),
2620
+ children: "Reject"
2621
+ }),
2622
+ x.status === "approved" && /* @__PURE__ */ g("section", {
2623
+ className: "proposal-boundary",
2624
+ children: [
2625
+ /* @__PURE__ */ h("strong", { children: "Approved · Ready for repository application." }),
2626
+ /* @__PURE__ */ g("code", { children: ["feltdb ai apply ", x.id] }),
2627
+ /* @__PURE__ */ h("button", {
2628
+ className: "btn btn-ghost",
2629
+ onClick: () => void navigator.clipboard.writeText(`feltdb ai apply ${x.id}`),
2630
+ children: "Copy command"
2631
+ }),
2632
+ /* @__PURE__ */ h("p", { children: "Studio cannot mutate repository source." })
2633
+ ]
2634
+ })
2635
+ ] }) : /* @__PURE__ */ h("div", {
2636
+ className: "model-empty",
2637
+ children: "Select a Proposal to inspect its canonical semantics."
2638
+ })
2639
+ })]
2640
+ }),
2641
+ U && x && /* @__PURE__ */ h("div", {
2642
+ className: "proposal-modal",
2643
+ role: "dialog",
2644
+ "aria-modal": "true",
2645
+ children: /* @__PURE__ */ g("section", { children: [
2646
+ /* @__PURE__ */ h("h2", { children: "Approve this Proposal?" }),
2647
+ /* @__PURE__ */ h("p", { children: x.summary }),
2648
+ x.contract_diff.slice(0, 6).map((e) => /* @__PURE__ */ h("div", { children: e }, e)),
2649
+ /* @__PURE__ */ h("p", { children: /* @__PURE__ */ h("strong", { children: "Repository source will not be modified." }) }),
2650
+ de && /* @__PURE__ */ g("label", { children: [/* @__PURE__ */ h("input", {
2651
+ type: "checkbox",
2652
+ checked: Y,
2653
+ onChange: (e) => ee(e.target.checked)
2654
+ }), " I explicitly approve the authorization change."] }),
2655
+ /* @__PURE__ */ g("footer", { children: [/* @__PURE__ */ h("button", {
2656
+ onClick: () => W(!1),
2657
+ children: "Cancel"
2658
+ }), /* @__PURE__ */ h("button", {
2659
+ disabled: de && !Y,
2660
+ onClick: () => void ce("approve"),
2661
+ children: "Approve"
2662
+ })] })
2663
+ ] })
2664
+ }),
2665
+ G && x && /* @__PURE__ */ h("div", {
2666
+ className: "proposal-modal",
2667
+ role: "dialog",
2668
+ "aria-modal": "true",
2669
+ children: /* @__PURE__ */ g("section", { children: [
2670
+ /* @__PURE__ */ h("h2", { children: "Reject Proposal?" }),
2671
+ /* @__PURE__ */ h("textarea", {
2672
+ "aria-label": "Rejection reason",
2673
+ value: q,
2674
+ onChange: (e) => J(e.target.value),
2675
+ placeholder: "Optional reason"
2676
+ }),
2677
+ /* @__PURE__ */ g("footer", { children: [/* @__PURE__ */ h("button", {
2678
+ onClick: () => K(!1),
2679
+ children: "Cancel"
2680
+ }), /* @__PURE__ */ h("button", {
2681
+ onClick: () => void ce("reject"),
2682
+ children: "Reject"
2683
+ })] })
2684
+ ] })
2685
+ })
2686
+ ]
2687
+ });
2688
+ }
2689
+ //#endregion
2690
+ //#region src/components/ModuleExplorer.tsx
2691
+ function Q({ model: e }) {
2692
+ let t = C(e?.modules ?? []);
2693
+ return /* @__PURE__ */ g("section", {
2694
+ className: "module-explorer",
2695
+ children: [
2696
+ /* @__PURE__ */ h("h1", { children: "Modules" }),
2697
+ !t.length && /* @__PURE__ */ h("p", { children: "No modules are declared. Add a module block to feltdb.flow." }),
2698
+ t.map((t) => /* @__PURE__ */ g("article", {
2699
+ className: "proposal-card",
2700
+ children: [
2701
+ /* @__PURE__ */ h("h2", { children: t.name }),
2702
+ /* @__PURE__ */ g("p", { children: [
2703
+ /* @__PURE__ */ g("code", { children: [
2704
+ t.id,
2705
+ "@",
2706
+ t.version
2707
+ ] }),
2708
+ " · provider ",
2709
+ /* @__PURE__ */ h("code", { children: t.provider })
2710
+ ] }),
2711
+ /* @__PURE__ */ h("h3", { children: "Models" }),
2712
+ /* @__PURE__ */ h("p", { children: t.models.map((e) => e.name).join(", ") }),
2713
+ /* @__PURE__ */ h("ul", { children: t.models.map((e) => /* @__PURE__ */ g("li", { children: [
2714
+ e.name,
2715
+ ": ",
2716
+ e.ownership
2717
+ ] }, e.name)) }),
2718
+ /* @__PURE__ */ h("h3", { children: "Application References" }),
2719
+ /* @__PURE__ */ h("ul", { children: (e?.collections ?? []).flatMap((e) => e.fields.filter((e) => e.type.startsWith(`ref ${t.id}.`)).map((t) => /* @__PURE__ */ g("li", { children: [
2720
+ e.name,
2721
+ ".",
2722
+ t.name,
2723
+ " → ",
2724
+ t.type.slice(4)
2725
+ ] }, `${e.name}.${t.name}`))) }),
2726
+ /* @__PURE__ */ h("h3", { children: "Relationships" }),
2727
+ /* @__PURE__ */ h("ul", { children: t.relationships.map((e) => /* @__PURE__ */ g("li", { children: [
2728
+ e.from,
2729
+ " → ",
2730
+ e.to,
2731
+ " (",
2732
+ e.kind,
2733
+ ")"
2734
+ ] }, `${e.from}-${e.to}`)) }),
2735
+ /* @__PURE__ */ h("h3", { children: "Events" }),
2736
+ /* @__PURE__ */ h("p", { children: t.events.join(", ") }),
2737
+ /* @__PURE__ */ h("h3", { children: "Capabilities" }),
2738
+ /* @__PURE__ */ h("p", { children: t.capabilities.join(", ") }),
2739
+ /* @__PURE__ */ h("h3", { children: "Configuration" }),
2740
+ /* @__PURE__ */ h("p", { children: t.configuration.map((e) => e.name).join(", ") || "None" }),
2741
+ /* @__PURE__ */ h("h3", { children: "Secrets" }),
2742
+ /* @__PURE__ */ g("p", { children: [t.secrets.map((e) => e.name).join(", "), " (values are never included in the contract)"] }),
2743
+ /* @__PURE__ */ h("h3", { children: "Reconciliation" }),
2744
+ /* @__PURE__ */ h("ul", { children: t.reconciliation.map((e) => /* @__PURE__ */ g("li", { children: [
2745
+ e.event,
2746
+ " → ",
2747
+ e.workflow,
2748
+ " → ",
2749
+ e.writes.join(", ")
2750
+ ] }, e.event)) })
2751
+ ]
2752
+ }, `${t.id}@${t.version}`))
2753
+ ]
2754
+ });
2755
+ }
2756
+ //#endregion
2757
+ //#region src/components/ContractInspector.tsx
2758
+ function $({ model: e, section: t }) {
2759
+ return e ? /* @__PURE__ */ g("div", {
2760
+ className: "studio-model-page",
2761
+ children: [/* @__PURE__ */ g("header", { children: [/* @__PURE__ */ h("span", {
2762
+ className: "eyebrow",
2763
+ children: "Contract"
2764
+ }), /* @__PURE__ */ h("h1", { children: t === "schema" ? "Schema" : "Policies" })] }), t === "schema" ? e.collections.map((e) => /* @__PURE__ */ g("article", {
2765
+ className: "studio-card",
2766
+ children: [
2767
+ /* @__PURE__ */ h("h2", { children: e.name }),
2768
+ /* @__PURE__ */ h("p", { children: e.fields.map((e) => `${e.name}: ${e.type}${e.optional ? "?" : ""}`).join(" · ") }),
2769
+ /* @__PURE__ */ h(p, {
2770
+ to: {
2771
+ pathname: "/data",
2772
+ search: window.location.search
2773
+ },
2774
+ children: "Inspect records →"
2775
+ })
2776
+ ]
2777
+ }, e.name)) : e.policies.map((e) => /* @__PURE__ */ g("article", {
2778
+ className: "studio-card",
2779
+ children: [/* @__PURE__ */ h("h2", { children: e.name }), /* @__PURE__ */ h("pre", { children: e.statements.join("\n") })]
2780
+ }, e.name))]
2781
+ }) : /* @__PURE__ */ h("div", {
2782
+ className: "model-empty",
2783
+ children: "No active application contract."
2784
+ });
2785
+ }
2786
+ //#endregion
2787
+ export { A as C, j as S, T, R as _, ee as a, N as b, K as c, U as d, H as f, P as g, F as h, te as i, G as l, L as m, Q as n, J as o, V as p, Z as r, q as s, $ as t, W as u, z as v, O as w, M as x, I as y };