react-semaphor 0.1.368 → 0.1.370

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 (65) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/brand-studio/index.cjs +5 -5
  4. package/dist/brand-studio/index.js +24 -23
  5. package/dist/chunks/{braces-Cc86y9Ov.js → braces-C3-w6xDL.js} +1 -1
  6. package/dist/chunks/{braces-CXvY9MwQ.js → braces-C8QqW4wu.js} +1 -1
  7. package/dist/chunks/{calendar-preferences-dialog-BOFlzOJg.js → calendar-preferences-dialog-6q51A6XC.js} +3 -3
  8. package/dist/chunks/{calendar-preferences-dialog-ZzwfJv2J.js → calendar-preferences-dialog-CUGzkNcE.js} +1 -1
  9. package/dist/chunks/{chevrons-up-down-CUZL1zaU.js → chevrons-up-down-CnCSGY02.js} +1 -1
  10. package/dist/chunks/{chevrons-up-down-qQMadOWA.js → chevrons-up-down-DSvLu4Ye.js} +1 -1
  11. package/dist/chunks/{dashboard-briefing-launcher-9-PCYMjR.js → dashboard-briefing-launcher-BEZnvIla.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-D2lBFqAd.js → dashboard-briefing-launcher-ptERmNJr.js} +176 -177
  13. package/dist/chunks/{dashboard-controls-D4bUHAjX.js → dashboard-controls-CGt6_hMf.js} +11 -11
  14. package/dist/chunks/{dashboard-controls-BIk094Ah.js → dashboard-controls-CqKC5oEk.js} +77 -77
  15. package/dist/chunks/{dashboard-json-DImOf512.js → dashboard-json-6SgPm_QW.js} +13 -14
  16. package/dist/chunks/dashboard-json-CYSbOdmE.js +1 -0
  17. package/dist/chunks/{edit-dashboard-visual-DTxkV6Fl.js → edit-dashboard-visual-ByQx_M2i.js} +8 -9
  18. package/dist/chunks/{edit-dashboard-visual-BHKlcqQR.js → edit-dashboard-visual-w6hKbjlw.js} +1 -1
  19. package/dist/chunks/index-BtqYNH_S.js +1361 -0
  20. package/dist/chunks/{index-BVEIk-rB.js → index-CPyEi9gS.js} +72498 -76193
  21. package/dist/chunks/{palette-DPuAc82h.js → palette-D-f4-82S.js} +1 -1
  22. package/dist/chunks/{palette-C1k347Tb.js → palette-DUGktM-M.js} +1 -1
  23. package/dist/chunks/{resource-management-panel-BeHceP2D.js → resource-management-panel-Bf8-3eUf.js} +1 -1
  24. package/dist/chunks/{resource-management-panel-BOfbSf48.js → resource-management-panel-mJ84NxzC.js} +152 -152
  25. package/dist/chunks/save-D3YYinDz.js +6 -0
  26. package/dist/chunks/save-kkBEBeLg.js +21 -0
  27. package/dist/chunks/{switch-xcWLtWs0.js → switch-Dkx2qEOr.js} +758 -776
  28. package/dist/chunks/{switch-C0S63HAv.js → switch-fIkmwzUt.js} +27 -32
  29. package/dist/chunks/{use-create-flow-overlay-state-B5FygfQL.js → use-create-flow-overlay-state-BfoXDDrd.js} +190 -189
  30. package/dist/chunks/use-create-flow-overlay-state-c6rCm36x.js +26 -0
  31. package/dist/chunks/{use-visual-utils-DxDE8S8M.js → use-visual-utils-C_c-aiqi.js} +1 -1
  32. package/dist/chunks/{use-visual-utils-CszWnFBW.js → use-visual-utils-NN0e3fBP.js} +13 -13
  33. package/dist/chunks/validation-DYL3ArlL.js +1 -0
  34. package/dist/chunks/validation-PPSpYtVf.js +900 -0
  35. package/dist/chunks/validators-CgxWT8UX.js +1 -0
  36. package/dist/chunks/validators-DBNa-eb1.js +1799 -0
  37. package/dist/dashboard/index.cjs +1 -1
  38. package/dist/dashboard/index.js +1 -1
  39. package/dist/dashboard-authoring/index.cjs +1 -1
  40. package/dist/dashboard-authoring/index.js +1 -1
  41. package/dist/data-app-builder/index.cjs +51 -1
  42. package/dist/data-app-builder/index.js +3666 -2
  43. package/dist/data-app-sdk/index.cjs +1 -1
  44. package/dist/data-app-sdk/index.js +661 -389
  45. package/dist/data-app-sdk-validation/index.cjs +1 -1
  46. package/dist/data-app-sdk-validation/index.js +4 -4
  47. package/dist/index.cjs +1 -1
  48. package/dist/index.js +14 -14
  49. package/dist/surfboard/index.cjs +1 -1
  50. package/dist/surfboard/index.js +2 -2
  51. package/dist/types/analytics-protocol.d.ts +472 -3
  52. package/dist/types/dashboard-assistant.d.ts +469 -3
  53. package/dist/types/dashboard-authoring.d.ts +170 -2
  54. package/dist/types/data-app-builder.d.ts +167 -2
  55. package/dist/types/data-app-sdk-validation.d.ts +576 -25
  56. package/dist/types/data-app-sdk.d.ts +655 -37
  57. package/dist/types/main.d.ts +167 -2
  58. package/package.json +1 -1
  59. package/dist/chunks/dashboard-json-Bo1kX6W1.js +0 -1
  60. package/dist/chunks/index-HjDeEytV.js +0 -1411
  61. package/dist/chunks/use-create-flow-overlay-state-DOXTbTcQ.js +0 -26
  62. package/dist/chunks/validation-CrUjNWby.js +0 -689
  63. package/dist/chunks/validation-DGl8wnTt.js +0 -1
  64. package/dist/chunks/validators-Dq5X4mp0.js +0 -1
  65. package/dist/chunks/validators-L0xEXtjf.js +0 -965
@@ -1,4 +1,3668 @@
1
- import { b as r } from "../chunks/index-BVEIk-rB.js";
1
+ import { jsx as r, jsxs as c, Fragment as re } from "react/jsx-runtime";
2
+ import * as Yn from "react";
3
+ import { useContext as Zn, useState as x, useRef as oe, useMemo as je, useEffect as W, useCallback as Ot } from "react";
4
+ import * as Xn from "react-dom/client";
5
+ import { ak as ea, al as ta, am as Lr, an as jr, ao as zr, ap as ra, aq as Wr, ar as Hr, as as Jr, at as Vr, au as _r, av as Ur, aw as Gr, ax as na, ay as aa, az as oa, aA as sa, aB as Ht, aC as on, w as Kr, aD as ia, aE as Vt, aF as _t, aG as sn, aH as la, aI as da, aJ as ca } from "../chunks/index-CPyEi9gS.js";
6
+ import { c as Ve, B as H, P as it, b as lt, d as dt, a2 as ua, a3 as pa, a4 as ha, a5 as ma, a6 as fa, X as He, f as me, R as ga, e as Ut } from "../chunks/switch-Dkx2qEOr.js";
7
+ import { loadSemaphorBrowserRuntime as ot } from "../data-app-builder-browser-runtime/index.js";
8
+ import { S as ba } from "../chunks/save-kkBEBeLg.js";
9
+ /**
10
+ * @license lucide-react v0.453.0 - ISC
11
+ *
12
+ * This source code is licensed under the ISC license.
13
+ * See the LICENSE file in the root directory of this source tree.
14
+ */
15
+ const xa = Ve("CloudUpload", [
16
+ ["path", { d: "M12 13v8", key: "1l5pq0" }],
17
+ ["path", { d: "M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242", key: "1pljnt" }],
18
+ ["path", { d: "m8 17 4-4 4 4", key: "1quai1" }]
19
+ ]);
20
+ /**
21
+ * @license lucide-react v0.453.0 - ISC
22
+ *
23
+ * This source code is licensed under the ISC license.
24
+ * See the LICENSE file in the root directory of this source tree.
25
+ */
26
+ const wa = Ve("Folder", [
27
+ [
28
+ "path",
29
+ {
30
+ d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",
31
+ key: "1kt360"
32
+ }
33
+ ]
34
+ ]);
35
+ /**
36
+ * @license lucide-react v0.453.0 - ISC
37
+ *
38
+ * This source code is licensed under the ISC license.
39
+ * See the LICENSE file in the root directory of this source tree.
40
+ */
41
+ const ya = Ve("ImagePlus", [
42
+ ["path", { d: "M16 5h6", key: "1vod17" }],
43
+ ["path", { d: "M19 2v6", key: "4bpg5p" }],
44
+ ["path", { d: "M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5", key: "1ue2ih" }],
45
+ ["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21", key: "1xmnt7" }],
46
+ ["circle", { cx: "9", cy: "9", r: "2", key: "af1f0g" }]
47
+ ]);
48
+ /**
49
+ * @license lucide-react v0.453.0 - ISC
50
+ *
51
+ * This source code is licensed under the ISC license.
52
+ * See the LICENSE file in the root directory of this source tree.
53
+ */
54
+ const va = Ve("MousePointer2", [
55
+ [
56
+ "path",
57
+ {
58
+ d: "M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",
59
+ key: "edeuup"
60
+ }
61
+ ]
62
+ ]);
63
+ /**
64
+ * @license lucide-react v0.453.0 - ISC
65
+ *
66
+ * This source code is licensed under the ISC license.
67
+ * See the LICENSE file in the root directory of this source tree.
68
+ */
69
+ const ka = Ve("PanelLeftClose", [
70
+ ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
71
+ ["path", { d: "M9 3v18", key: "fh3hqa" }],
72
+ ["path", { d: "m16 15-3-3 3-3", key: "14y99z" }]
73
+ ]), Na = [
74
+ {
75
+ id: "customer-health",
76
+ title: "Customer health workspace",
77
+ description: "KPI cards, customer table, and segment filters for account health review.",
78
+ datasets: ["customers", "orders"],
79
+ prompt: "Build a customer health data app with KPI cards, segment and region filters, a revenue trend, and a customer health table."
80
+ },
81
+ {
82
+ id: "revenue-command",
83
+ title: "Revenue command center",
84
+ description: "Revenue, margin, and order trends with top accounts and category drilldowns.",
85
+ datasets: ["orders", "customers"],
86
+ prompt: "Create a revenue command center with revenue and margin KPIs, a monthly trend chart, a segment performance section, and a top customers table."
87
+ },
88
+ {
89
+ id: "operations-overview",
90
+ title: "Operations overview",
91
+ description: "Operational throughput, exceptions, and detail tables for daily review.",
92
+ datasets: ["orders", "inventory"],
93
+ prompt: "Create an operations dashboard with throughput KPIs, exception tables, trend charts, and filters for date, region, and status."
94
+ }
95
+ ], Sa = [
96
+ {
97
+ id: "context",
98
+ label: "Context",
99
+ detail: "Read the current app files and workspace capabilities.",
100
+ state: "idle"
101
+ },
102
+ {
103
+ id: "generate",
104
+ label: "Generate",
105
+ detail: "Call the hosted model to produce the next React revision.",
106
+ state: "idle"
107
+ },
108
+ {
109
+ id: "edit",
110
+ label: "Edit",
111
+ detail: "Apply source changes through the local bridge.",
112
+ state: "idle"
113
+ },
114
+ {
115
+ id: "typecheck",
116
+ label: "Typecheck",
117
+ detail: "Run the local workspace validation command.",
118
+ state: "idle"
119
+ },
120
+ {
121
+ id: "repair",
122
+ label: "Repair",
123
+ detail: "Use diagnostics for a bounded repair pass if needed.",
124
+ state: "idle"
125
+ },
126
+ {
127
+ id: "preview",
128
+ label: "Preview",
129
+ detail: "Refresh the iframe once the dev server has updated.",
130
+ state: "idle"
131
+ }
132
+ ], Jt = [
133
+ {
134
+ id: "gpt-5.5-low",
135
+ label: "GPT-5.5 fast",
136
+ model: "gpt-5.5",
137
+ reasoningEffort: "low"
138
+ },
139
+ {
140
+ id: "gpt-5.5-medium",
141
+ label: "GPT-5.5 balanced",
142
+ model: "gpt-5.5",
143
+ reasoningEffort: "medium"
144
+ },
145
+ {
146
+ id: "gpt-5.4-mini-minimal",
147
+ label: "GPT-5.4 mini fast",
148
+ model: "gpt-5.4-mini",
149
+ reasoningEffort: "low"
150
+ },
151
+ { id: "gpt-4.1-mini", label: "GPT-4.1 mini", model: "gpt-4.1-mini" }
152
+ ], Qr = "semaphor-data-app-builder-transcript", qr = "semaphor-data-app-builder-preview-url", Yr = "semaphor-data-app-builder-bridge-url", Zr = "semaphor-data-app-builder-project-dir", It = "http://semaphor-data-app.localhost:8088", Xr = "http://localhost:8787", Lt = "/Users/rohit/code/sandbox/semaphor-data-apps/data-app", ze = 3, Aa = 18, jt = 12;
153
+ function he(e, a) {
154
+ return `${e}:${a}`;
155
+ }
156
+ function fe(e) {
157
+ return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
158
+ }
159
+ function Ca(e) {
160
+ return Jt.find((a) => a.id === e) || Jt[0];
161
+ }
162
+ async function O(e, a) {
163
+ const s = await e.text();
164
+ if (!s.trim())
165
+ return {};
166
+ try {
167
+ return JSON.parse(s);
168
+ } catch {
169
+ const d = s.replace(/\s+/g, " ").trim().slice(0, 500);
170
+ throw new Error(
171
+ `${a} returned ${e.status} ${e.statusText} with non-JSON response: ${d}`
172
+ );
173
+ }
174
+ }
175
+ function ln(e, a) {
176
+ const s = e == null ? void 0 : e.trim().replace(/\/$/, "");
177
+ return s ? `${s.endsWith("/api") ? s : `${s}/api`}/data-app-builder${a}` : `/api/data-app-builder${a}`;
178
+ }
179
+ function ye(e, a) {
180
+ const s = e == null ? void 0 : e.trim().replace(/\/$/, "");
181
+ return s ? `${s.endsWith("/api") ? s : `${s}/api`}/data-apps${a}` : `/api/data-apps${a}`;
182
+ }
183
+ function Re(e) {
184
+ return e ? { Authorization: `Bearer ${e}` } : {};
185
+ }
186
+ function Be(e) {
187
+ return e ? "omit" : "include";
188
+ }
189
+ function We(e) {
190
+ if (Array.isArray(e))
191
+ return e.map(We);
192
+ if (!e || typeof e != "object")
193
+ return e;
194
+ const a = {};
195
+ return Object.entries(e).forEach(([s, d]) => {
196
+ if (s !== "contentsBase64") {
197
+ if (s === "assets" && Array.isArray(d)) {
198
+ a.assets = d.map((l) => {
199
+ if (!l || typeof l != "object")
200
+ return l;
201
+ const {
202
+ contentsBase64: p,
203
+ ...h
204
+ } = l;
205
+ return We(h);
206
+ });
207
+ return;
208
+ }
209
+ a[s] = We(d);
210
+ }
211
+ }), a;
212
+ }
213
+ async function Ra({
214
+ apiServiceUrl: e,
215
+ accessToken: a,
216
+ signal: s
217
+ }) {
218
+ const d = await fetch(ln(e, "/status"), {
219
+ cache: "no-store",
220
+ headers: a ? { Authorization: `Bearer ${a}` } : void 0,
221
+ signal: s
222
+ }), l = await O(
223
+ d,
224
+ "Data App Builder status"
225
+ );
226
+ return d.ok ? l : { ok: !1, error: l.error || d.statusText };
227
+ }
228
+ async function Ba(e, {
229
+ apiServiceUrl: a,
230
+ accessToken: s,
231
+ signal: d,
232
+ onProgress: l
233
+ }) {
234
+ const p = await fetch(ln(a, "/turn"), {
235
+ method: "POST",
236
+ signal: d,
237
+ headers: {
238
+ "Content-Type": "application/json",
239
+ ...s ? { Authorization: `Bearer ${s}` } : {}
240
+ },
241
+ body: JSON.stringify({ ...e, stream: !0 })
242
+ }), h = p.headers.get("content-type") || "";
243
+ if (p.body && h.includes("text/event-stream"))
244
+ return $a(p, l);
245
+ const g = await O(
246
+ p,
247
+ "Data App Builder turn"
248
+ );
249
+ if (!p.ok || !g.ok || !g.turn)
250
+ throw new Error(g.error || "Data App Builder could not run the turn.");
251
+ return g.turn;
252
+ }
253
+ async function $a(e, a) {
254
+ var S, f, R;
255
+ const s = (S = e.body) == null ? void 0 : S.getReader();
256
+ if (!s)
257
+ throw new Error("Data App Builder turn stream was empty.");
258
+ const d = new TextDecoder();
259
+ let l = "";
260
+ const p = {
261
+ status: e.status,
262
+ ok: e.ok
263
+ }, h = (v) => {
264
+ var I;
265
+ const B = v.split(`
266
+ `), b = ((I = B.find((F) => F.startsWith("event:"))) == null ? void 0 : I.slice(6).trim()) || "message", E = B.filter((F) => F.startsWith("data:")).map((F) => F.slice(5).trim()).join(`
267
+ `);
268
+ if (!E) return;
269
+ const j = JSON.parse(E);
270
+ if (b === "progress") {
271
+ a == null || a(j);
272
+ return;
273
+ }
274
+ b === "result" && (p.status = typeof j.status == "number" ? j.status : p.status, p.ok = j.ok === !0, p.result = j.body);
275
+ };
276
+ for (; ; ) {
277
+ const { done: v, value: B } = await s.read();
278
+ if (v) break;
279
+ l += d.decode(B, { stream: !0 });
280
+ let b = l.indexOf(`
281
+
282
+ `);
283
+ for (; b >= 0; ) {
284
+ const E = l.slice(0, b).trim();
285
+ l = l.slice(b + 2), E && h(E), b = l.indexOf(`
286
+
287
+ `);
288
+ }
289
+ }
290
+ const g = l.trim();
291
+ if (g && h(g), !p.ok || !((f = p.result) != null && f.ok) || !p.result.turn)
292
+ throw new Error(
293
+ ((R = p.result) == null ? void 0 : R.error) || `Data App Builder could not run the turn (${p.status}).`
294
+ );
295
+ return p.result.turn;
296
+ }
297
+ async function Da(e, {
298
+ apiServiceUrl: a,
299
+ accessToken: s,
300
+ signal: d
301
+ }) {
302
+ var R, v, B;
303
+ const l = e.dataAppId, p = l ? ye(a, `/${l}/draft`) : ye(a, ""), h = l ? {
304
+ title: e.title,
305
+ description: e.description,
306
+ manifest: e.manifest,
307
+ sourceSnapshot: e.sourceSnapshot,
308
+ sourceRevision: e.sourceRevision,
309
+ validationStatus: e.validationStatus,
310
+ bridgeWorkspaceHint: e.bridgeWorkspaceHint
311
+ } : {
312
+ projectId: e.projectId,
313
+ title: e.title,
314
+ description: e.description,
315
+ manifest: e.manifest,
316
+ sourceSnapshot: e.sourceSnapshot,
317
+ sourceRevision: e.sourceRevision,
318
+ validationStatus: e.validationStatus,
319
+ bridgeWorkspaceHint: e.bridgeWorkspaceHint
320
+ }, g = await fetch(p, {
321
+ method: "POST",
322
+ credentials: Be(s),
323
+ signal: d,
324
+ headers: {
325
+ "Content-Type": "application/json",
326
+ ...Re(s)
327
+ },
328
+ body: JSON.stringify(h)
329
+ }), S = await O(g, "Data App save draft");
330
+ if (!g.ok)
331
+ throw new Error(S.error || "Data App draft could not be saved.");
332
+ const f = l || ((R = S.dataApp) == null ? void 0 : R.id);
333
+ if (!f)
334
+ throw new Error("Data App save draft response did not include an app id.");
335
+ return {
336
+ dataAppId: f,
337
+ draftId: (v = S.draft) == null ? void 0 : v.id,
338
+ savedAt: ((B = S.draft) == null ? void 0 : B.updatedAt) || (/* @__PURE__ */ new Date()).toISOString()
339
+ };
340
+ }
341
+ async function Pa(e, {
342
+ apiServiceUrl: a,
343
+ accessToken: s,
344
+ signal: d
345
+ }) {
346
+ var h;
347
+ const l = await fetch(
348
+ ye(a, `/${e.dataAppId}`),
349
+ {
350
+ cache: "no-store",
351
+ credentials: Be(s),
352
+ signal: d,
353
+ headers: Re(s)
354
+ }
355
+ ), p = await O(l, "Data App load");
356
+ if (!l.ok || !((h = p.dataApp) != null && h.id))
357
+ throw new Error(p.error || "Data App could not be loaded.");
358
+ return p.dataApp;
359
+ }
360
+ async function Fa(e, {
361
+ apiServiceUrl: a,
362
+ accessToken: s,
363
+ signal: d,
364
+ onProgress: l
365
+ }) {
366
+ var f, R, v, B;
367
+ if (!e.draftId || !((f = e.sourceRevision) != null && f.snapshotHash))
368
+ throw new Error(
369
+ "Data App publish requires a saved draft and matching source revision."
370
+ );
371
+ const p = We(e.validationStatus);
372
+ l == null || l({
373
+ phase: "start",
374
+ label: "Starting publish session",
375
+ detail: "Creating a versioned publish record in Semaphor."
376
+ });
377
+ const h = await fetch(
378
+ ye(a, `/${e.dataAppId}/publish/start`),
379
+ {
380
+ method: "POST",
381
+ credentials: Be(s),
382
+ signal: d,
383
+ headers: {
384
+ "Content-Type": "application/json",
385
+ ...Re(s)
386
+ },
387
+ body: JSON.stringify({
388
+ draftId: e.draftId,
389
+ sourceRevisionSnapshotHash: (R = e.sourceRevision) == null ? void 0 : R.snapshotHash,
390
+ validationStatus: p
391
+ })
392
+ }
393
+ ), g = await O(h, "Data App publish start");
394
+ if (!h.ok || !((v = g.publishSession) != null && v.versionId))
395
+ throw new Error(
396
+ g.error || "Data App publish session could not be started."
397
+ );
398
+ const S = g.publishSession.versionId;
399
+ try {
400
+ l == null || l({
401
+ phase: "build",
402
+ label: "Building app locally",
403
+ detail: "The local bridge is running the app build."
404
+ });
405
+ const b = await e.buildArtifacts({
406
+ signal: d,
407
+ onProgress: l
408
+ }), E = We(
409
+ b.validationStatus
410
+ );
411
+ for (const [F, z] of b.assets.entries()) {
412
+ l == null || l({
413
+ phase: "upload",
414
+ label: `Uploading asset ${F + 1} of ${b.assets.length}`,
415
+ detail: z.path,
416
+ assetIndex: F + 1,
417
+ assetCount: b.assets.length
418
+ });
419
+ const ve = await fetch(
420
+ ye(a, `/${e.dataAppId}/publish/upload`),
421
+ {
422
+ method: "POST",
423
+ credentials: Be(s),
424
+ signal: d,
425
+ headers: {
426
+ "Content-Type": "application/json",
427
+ ...Re(s)
428
+ },
429
+ body: JSON.stringify({
430
+ versionId: S,
431
+ assetPath: z.path,
432
+ contentsBase64: z.contentsBase64,
433
+ contentType: z.contentType
434
+ })
435
+ }
436
+ ), Y = await O(ve, "Data App publish upload");
437
+ if (!ve.ok)
438
+ throw new Error(
439
+ Y.error || `Upload failed for ${z.path}.`
440
+ );
441
+ }
442
+ l == null || l({
443
+ phase: "complete",
444
+ label: "Finalizing published version",
445
+ detail: "Validating manifest and marking the version ready."
446
+ });
447
+ const j = await fetch(
448
+ ye(a, `/${e.dataAppId}/publish/complete`),
449
+ {
450
+ method: "POST",
451
+ credentials: Be(s),
452
+ signal: d,
453
+ headers: {
454
+ "Content-Type": "application/json",
455
+ ...Re(s)
456
+ },
457
+ body: JSON.stringify({
458
+ versionId: S,
459
+ manifest: b.manifest,
460
+ entryFile: b.entryFile,
461
+ styleFiles: b.styleFiles,
462
+ validationStatus: E
463
+ })
464
+ }
465
+ ), I = await O(j, "Data App publish complete");
466
+ if (!j.ok || !((B = I.version) != null && B.id))
467
+ throw new Error(
468
+ I.error || "Data App publish could not be completed."
469
+ );
470
+ return {
471
+ dataAppId: e.dataAppId,
472
+ versionId: I.version.id,
473
+ version: I.version.version,
474
+ publishedAt: I.version.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
475
+ };
476
+ } catch (b) {
477
+ throw await fetch(ye(a, `/${e.dataAppId}/publish/fail`), {
478
+ method: "POST",
479
+ credentials: Be(s),
480
+ signal: d,
481
+ headers: {
482
+ "Content-Type": "application/json",
483
+ ...Re(s)
484
+ },
485
+ body: JSON.stringify({
486
+ versionId: S,
487
+ validationStatus: {
488
+ ok: !1,
489
+ error: b instanceof Error ? b.message : String(b)
490
+ }
491
+ })
492
+ }).catch(() => {
493
+ }), b;
494
+ }
495
+ }
496
+ function en(e) {
497
+ const a = Array.from(new Set(e)), s = [
498
+ "src/App.tsx",
499
+ "src/data-app/index.tsx",
500
+ "src/data-app/styles.css",
501
+ "src/data-app/format.ts",
502
+ "src/data-app/types.ts",
503
+ "src/index.css",
504
+ "src/main.tsx"
505
+ ], d = [];
506
+ for (const l of s)
507
+ a.includes(l) && d.push(l);
508
+ for (const l of a) {
509
+ if (d.length >= Aa) break;
510
+ d.includes(l) || d.push(l);
511
+ }
512
+ return d;
513
+ }
514
+ function tn(e, a, s = "") {
515
+ const d = Array.from(new Set(e)), l = Ma(s, d), p = [
516
+ a,
517
+ "src/data-app/index.tsx",
518
+ "src/data-app/styles.css",
519
+ "src/data-app/format.ts",
520
+ "src/data-app/types.ts",
521
+ ...l,
522
+ "src/App.tsx",
523
+ "src/index.css",
524
+ "src/lib/utils.ts"
525
+ ].filter((g) => !!g), h = [];
526
+ for (const g of p) {
527
+ if (h.length >= jt) break;
528
+ d.includes(g) && !h.includes(g) && h.push(g);
529
+ }
530
+ for (const g of d) {
531
+ if (h.length >= jt) break;
532
+ h.includes(g) || /^src\/components\/ui\//.test(g) || /^src\/data-app\//.test(g) && h.push(g);
533
+ }
534
+ return h.length > 0 ? h : d.slice(0, jt);
535
+ }
536
+ function Ma(e, a) {
537
+ const s = e.toLowerCase(), d = a.filter(
538
+ (p) => p.startsWith("src/components/ui/")
539
+ );
540
+ if (/\b(shadcn|component|components|ui)\b/.test(s))
541
+ return d;
542
+ const l = [
543
+ ["select", "src/components/ui/select.tsx"],
544
+ ["dropdown", "src/components/ui/select.tsx"],
545
+ ["filter", "src/components/ui/select.tsx"],
546
+ ["progress", "src/components/ui/progress.tsx"],
547
+ ["calendar", "src/components/ui/calendar.tsx"],
548
+ ["date picker", "src/components/ui/calendar.tsx"],
549
+ ["datepicker", "src/components/ui/calendar.tsx"],
550
+ ["card", "src/components/ui/card.tsx"],
551
+ ["table", "src/components/ui/table.tsx"],
552
+ ["chart", "src/components/ui/chart.tsx"],
553
+ ["badge", "src/components/ui/badge.tsx"],
554
+ ["button", "src/components/ui/button.tsx"]
555
+ ].filter(([p]) => s.includes(p)).map(([, p]) => p);
556
+ return Array.from(new Set(l)).filter(
557
+ (p) => a.includes(p)
558
+ );
559
+ }
560
+ function Ta() {
561
+ return Sa.map((e) => ({ ...e }));
562
+ }
563
+ function zt(e) {
564
+ var s, d, l, p, h;
565
+ return [
566
+ e.error,
567
+ (s = e.writePolicyValidation) == null ? void 0 : s.diagnostics.join(`
568
+ `),
569
+ (d = e.importValidation) == null ? void 0 : d.diagnostics.join(`
570
+ `),
571
+ (l = e.dataApiValidation) == null ? void 0 : l.diagnostics.join(`
572
+ `),
573
+ (p = e.command) == null ? void 0 : p.stdout,
574
+ (h = e.command) == null ? void 0 : h.stderr,
575
+ ...(e.attempts || []).flatMap((g) => [
576
+ g.command.stdout,
577
+ g.command.stderr
578
+ ])
579
+ ].filter(Boolean).join(`
580
+
581
+ `).trim() || "Validation failed without diagnostics.";
582
+ }
583
+ function Ea(e) {
584
+ return /\b(type\s*script|typescript|tsc|typecheck|compile|compiler)\b/i.test(
585
+ e
586
+ );
587
+ }
588
+ function Gt(e) {
589
+ return e < 1e3 ? `${e}ms` : `${(e / 1e3).toFixed(e < 1e4 ? 1 : 0)}s`;
590
+ }
591
+ function Oa(e) {
592
+ const a = {
593
+ children: []
594
+ };
595
+ for (const d of e) {
596
+ const l = d.path.split("/").filter(Boolean);
597
+ let p = a, h = "";
598
+ l.forEach((g, S) => {
599
+ h = h ? `${h}/${g}` : g;
600
+ const f = S === l.length - 1;
601
+ let R = p.children.find(
602
+ (v) => v.name === g && v.type === (f ? "file" : "directory")
603
+ );
604
+ R || (R = {
605
+ name: g,
606
+ path: h,
607
+ type: f ? "file" : "directory",
608
+ size: f ? d.size : void 0,
609
+ children: []
610
+ }, p.children.push(R)), p = R;
611
+ });
612
+ }
613
+ function s(d) {
614
+ d.children.sort((l, p) => l.type !== p.type ? l.type === "directory" ? -1 : 1 : l.name.localeCompare(p.name)), d.children.forEach(s);
615
+ }
616
+ return s(a), a.children;
617
+ }
618
+ function Ia(e) {
619
+ return {
620
+ idle: "Working through your request",
621
+ context: "Reading app context",
622
+ thinking: "Thinking through the request",
623
+ "inspecting-data": "Inspecting Semaphor data",
624
+ "reading-files": "Reading requested files",
625
+ generating: "Generating source changes",
626
+ planning: "Planning the changes"
627
+ }[e];
628
+ }
629
+ function La(e) {
630
+ return {
631
+ idle: "Preparing the next step.",
632
+ context: "Reading the app and figuring out what to change.",
633
+ thinking: "Deciding whether this needs an answer, file inspection, or edits.",
634
+ "inspecting-data": "Reading project data and dataset fields.",
635
+ "reading-files": "Loading source files the model asked to inspect.",
636
+ generating: "Writing a bounded source revision.",
637
+ planning: "Mapping your request to file edits."
638
+ }[e];
639
+ }
640
+ function ja(e) {
641
+ var d, l, p;
642
+ const a = typeof e.message == "string" ? e.message.trim() : "";
643
+ if (a) return a;
644
+ const s = (p = (l = (d = e.revision) == null ? void 0 : d.plan) == null ? void 0 : l.files) == null ? void 0 : p.length;
645
+ return s ? `Yes - I'll make that change across ${s} file${s === 1 ? "" : "s"}, then run validation so you can review it.` : "Yes - I'll inspect the app context, make the change, and run validation so you can review it.";
646
+ }
647
+ function dn(e) {
648
+ return e.type === "screenshot" ? `Screenshot attachment: ${e.name}` : [
649
+ `DOM selection attachment: ${e.name}`,
650
+ e.text.slice(0, 1600)
651
+ ].join(`
652
+ `);
653
+ }
654
+ function za(e) {
655
+ const a = e.slice(0, 3).map((d) => d.split("/").pop() || d), s = e.length > a.length ? ` +${e.length - a.length} more` : "";
656
+ return `${a.join(", ")}${s}`;
657
+ }
658
+ function Wa(e) {
659
+ var d, l, p, h, g;
660
+ if (e.type === "user") {
661
+ const S = (e.attachments || []).map(dn).join(`
662
+
663
+ `);
664
+ return {
665
+ role: "user",
666
+ content: [e.content, S].filter(Boolean).join(`
667
+
668
+ `).slice(0, 2200)
669
+ };
670
+ }
671
+ if (e.type === "assistant")
672
+ return {
673
+ role: "assistant",
674
+ content: e.content.slice(0, 1800)
675
+ };
676
+ const a = (l = (d = e.result) == null ? void 0 : d.changedFiles) != null && l.length ? e.result.changedFiles.join(", ") : "none", s = (g = (h = (p = e.result) == null ? void 0 : p.filePlan) == null ? void 0 : h.files) == null ? void 0 : g.map((S) => `${S.action}:${S.path}`).join(", ");
677
+ return {
678
+ role: "system",
679
+ content: [
680
+ `Build run ${e.status} for: ${e.prompt}`,
681
+ `Changed files: ${a}`,
682
+ s ? `File plan: ${s}` : "",
683
+ e.error ? `Error: ${e.error}` : ""
684
+ ].filter(Boolean).join(`
685
+ `).slice(0, 2e3)
686
+ };
687
+ }
688
+ function Je(e) {
689
+ var h;
690
+ const a = Array.isArray(e == null ? void 0 : e.sources) ? e.sources : [], s = Array.isArray(e == null ? void 0 : e.inputs) ? e.inputs : [], d = Array.isArray(e == null ? void 0 : e.views) ? e.views : [], l = Array.isArray(e == null ? void 0 : e.interactions) ? e.interactions : [], p = Array.isArray((h = e == null ? void 0 : e.layout) == null ? void 0 : h.sections) ? e.layout.sections : [];
691
+ return !!(e && (a.length > 0 || s.length > 0 || d.length > 0 || l.length > 0 || p.length > 0));
692
+ }
693
+ function Ha(e) {
694
+ var d;
695
+ const a = (d = e == null ? void 0 : e.semaphor) == null ? void 0 : d.intentManifest;
696
+ if (!a || typeof a != "object") return null;
697
+ const s = a;
698
+ return s.schemaVersion === "data-app-intent/v1" && s.app && Array.isArray(s.sources) && Array.isArray(s.inputs) && Array.isArray(s.views) ? s : null;
699
+ }
700
+ function Ja(e) {
701
+ const a = e.dataAppVersions || [];
702
+ return a.find(
703
+ (s) => s.version === 0 && s.status === "draft"
704
+ ) || e.currentDataAppVersion || a.find((s) => s.status === "ready") || null;
705
+ }
706
+ function Va(e, a) {
707
+ var l, p, h;
708
+ const s = (l = e.bridgeWorkspaceHint) == null ? void 0 : l.trim();
709
+ if (s) return s;
710
+ const d = (h = (p = e.sourceSnapshot) == null ? void 0 : p.metadata) == null ? void 0 : h.projectRoot;
711
+ return typeof d == "string" && d.trim() ? d.trim() : a;
712
+ }
713
+ function _a(e) {
714
+ return JSON.stringify({
715
+ schemaVersion: e.schemaVersion,
716
+ files: [...e.files].map((a) => ({
717
+ path: a.path,
718
+ contents: a.contents,
719
+ hash: a.hash ?? null
720
+ })).sort((a, s) => a.path.localeCompare(s.path))
721
+ });
722
+ }
723
+ async function rn(e) {
724
+ const a = await window.crypto.subtle.digest(
725
+ "SHA-256",
726
+ new TextEncoder().encode(e)
727
+ );
728
+ return Array.from(new Uint8Array(a)).map((s) => s.toString(16).padStart(2, "0")).join("");
729
+ }
730
+ function nn(e) {
731
+ return e.replace(/\\/g, "/").split("/").filter(Boolean).pop();
732
+ }
733
+ async function Ua({
734
+ snapshot: e,
735
+ workspaceContext: a,
736
+ projectDir: s,
737
+ adapter: d
738
+ }) {
739
+ const l = a.projectRoot || s;
740
+ return {
741
+ schemaVersion: "data-app-source-revision/v1",
742
+ snapshotHash: await rn(_a(e)),
743
+ workspace: {
744
+ adapter: d,
745
+ ...nn(l) ? { rootName: nn(l) } : {},
746
+ pathHash: await rn(l)
747
+ },
748
+ collectedAt: (/* @__PURE__ */ new Date()).toISOString()
749
+ };
750
+ }
751
+ function st(e, a) {
752
+ const s = /* @__PURE__ */ new Map();
753
+ for (const d of e)
754
+ s.set(d.id, d);
755
+ for (const d of a)
756
+ s.set(d.id, d);
757
+ return Array.from(s.values());
758
+ }
759
+ function Ga(e, a) {
760
+ return !a || !Je(a) ? e : !e || !Je(e) ? a : {
761
+ schemaVersion: "data-app-intent/v1",
762
+ app: {
763
+ title: a.app.title || e.app.title,
764
+ description: a.app.description || e.app.description,
765
+ goal: a.app.goal || e.app.goal
766
+ },
767
+ sources: st(e.sources, a.sources),
768
+ inputs: st(e.inputs, a.inputs),
769
+ views: st(e.views, a.views),
770
+ interactions: e.interactions || a.interactions ? st(e.interactions || [], a.interactions || []) : void 0,
771
+ layout: a.layout || e.layout
772
+ };
773
+ }
774
+ function an(e, a) {
775
+ var S, f, R, v, B, b, E, j, I;
776
+ const s = e.slice(-12).map(Wa), d = e.slice().reverse().find(
777
+ (F) => {
778
+ var z;
779
+ return F.type === "run" && F.status === "done" && ((z = F.result) == null ? void 0 : z.ok) === !0;
780
+ }
781
+ ), l = e.slice().reverse().find(
782
+ (F) => {
783
+ var z;
784
+ return F.type === "user" && !!((z = F.attachments) != null && z.length);
785
+ }
786
+ ), p = (S = e.slice().reverse().find(
787
+ (F) => F.type === "assistant" && !!F.operation
788
+ )) == null ? void 0 : S.operation, h = (Je(a) ? a : void 0) || ((f = e.slice().reverse().find(
789
+ (F) => F.type === "assistant" && Je(F.intentManifest)
790
+ )) == null ? void 0 : f.intentManifest), g = [
791
+ (R = l == null ? void 0 : l.attachments) != null && R.length ? [
792
+ "Most recent selected/attached target:",
793
+ ...l.attachments.map(
794
+ dn
795
+ )
796
+ ].join(`
797
+ `) : "",
798
+ (B = (v = d == null ? void 0 : d.result) == null ? void 0 : v.changedFiles) != null && B.length ? `Last successful edit changed: ${d.result.changedFiles.join(", ")}` : "",
799
+ p ? `Last app-builder operation: ${p.type}${(b = p.target) != null && b.label ? ` on ${p.target.label}` : ""}` : ""
800
+ ].filter(Boolean);
801
+ return {
802
+ messages: s,
803
+ activeTarget: g.join(`
804
+
805
+ `) || void 0,
806
+ lastSuccessfulRun: d ? {
807
+ prompt: d.prompt,
808
+ changedFiles: ((E = d.result) == null ? void 0 : E.changedFiles) || [],
809
+ summary: (j = d.result) == null ? void 0 : j.summary,
810
+ filePlan: (I = d.result) == null ? void 0 : I.filePlan
811
+ } : void 0,
812
+ lastOperation: p,
813
+ intentManifest: h || void 0
814
+ };
815
+ }
816
+ function Ka({
817
+ files: e,
818
+ selectedPath: a,
819
+ onSelect: s
820
+ }) {
821
+ const d = je(() => Oa(e), [e]);
822
+ return d.length === 0 ? /* @__PURE__ */ r("div", { className: "rounded-[5px] border border-border bg-background p-2 text-[11px] text-muted-foreground", children: "No browser files loaded yet." }) : /* @__PURE__ */ r("div", { className: "space-y-0.5", children: d.map((l) => /* @__PURE__ */ r(
823
+ cn,
824
+ {
825
+ node: l,
826
+ depth: 0,
827
+ selectedPath: a,
828
+ onSelect: s
829
+ },
830
+ l.path || l.name
831
+ )) });
832
+ }
833
+ function cn({
834
+ node: e,
835
+ depth: a,
836
+ selectedPath: s,
837
+ onSelect: d
838
+ }) {
839
+ const l = e.type === "directory", p = s === e.path;
840
+ return /* @__PURE__ */ c(re, { children: [
841
+ /* @__PURE__ */ c(
842
+ "button",
843
+ {
844
+ type: "button",
845
+ disabled: l,
846
+ onClick: () => d(e.path),
847
+ className: `flex w-full items-center gap-1.5 rounded-[4px] py-1.5 pr-2 text-left font-mono text-[11px] ${p ? "bg-background text-foreground" : l ? "cursor-default text-foreground" : "text-muted-foreground hover:bg-background hover:text-foreground"}`,
848
+ style: { paddingLeft: `${8 + a * 14}px` },
849
+ children: [
850
+ l ? /* @__PURE__ */ c(re, { children: [
851
+ /* @__PURE__ */ r(_t, { className: "h-3 w-3 rotate-90 text-muted-foreground" }),
852
+ /* @__PURE__ */ r(wa, { className: "h-3.5 w-3.5 text-muted-foreground" })
853
+ ] }) : /* @__PURE__ */ c(re, { children: [
854
+ /* @__PURE__ */ r("span", { className: "h-3 w-3" }),
855
+ /* @__PURE__ */ r(Vt, { className: "h-3.5 w-3.5 text-muted-foreground" })
856
+ ] }),
857
+ /* @__PURE__ */ r("span", { className: "min-w-0 flex-1 truncate", children: e.name }),
858
+ !l && /* @__PURE__ */ r("span", { className: "shrink-0 text-[10px] text-muted-foreground", children: e.size })
859
+ ]
860
+ }
861
+ ),
862
+ l && e.children.map((h) => /* @__PURE__ */ r(
863
+ cn,
864
+ {
865
+ node: h,
866
+ depth: a + 1,
867
+ selectedPath: s,
868
+ onSelect: d
869
+ },
870
+ h.path
871
+ ))
872
+ ] });
873
+ }
874
+ function Qa({
875
+ manifest: e
876
+ }) {
877
+ if (!e) return null;
878
+ const a = e.packages.filter(
879
+ (d) => d.status === "supported"
880
+ ).length, s = e.packages.length - a;
881
+ return /* @__PURE__ */ c("div", { className: "mt-2 rounded-[5px] border border-border bg-background px-3 py-2", children: [
882
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between gap-2", children: [
883
+ /* @__PURE__ */ c("div", { className: "min-w-0", children: [
884
+ /* @__PURE__ */ r("div", { className: "truncate text-[12px] font-medium text-foreground", children: e.name }),
885
+ /* @__PURE__ */ c("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: [
886
+ e.moduleSystem,
887
+ " · ",
888
+ e.cssPipeline.status
889
+ ] })
890
+ ] }),
891
+ /* @__PURE__ */ r("span", { className: "rounded-[4px] bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-[0.06em] text-muted-foreground", children: e.execution })
892
+ ] }),
893
+ /* @__PURE__ */ c("div", { className: "mt-2 flex flex-wrap gap-1.5 text-[10.5px] text-muted-foreground", children: [
894
+ /* @__PURE__ */ c("span", { className: "rounded-[4px] bg-muted px-1.5 py-0.5", children: [
895
+ e.components.length,
896
+ " components"
897
+ ] }),
898
+ /* @__PURE__ */ c("span", { className: "rounded-[4px] bg-muted px-1.5 py-0.5", children: [
899
+ a,
900
+ " packages"
901
+ ] }),
902
+ s > 0 ? /* @__PURE__ */ c("span", { className: "rounded-[4px] bg-amber-50 px-1.5 py-0.5 text-amber-700", children: [
903
+ s,
904
+ " partial"
905
+ ] }) : null
906
+ ] })
907
+ ] });
908
+ }
909
+ function qa({
910
+ plan: e,
911
+ changedFiles: a
912
+ }) {
913
+ const s = new Set(a || []), d = (e == null ? void 0 : e.files) || [], l = (a || []).filter(
914
+ (p) => !d.some((h) => h.path === p)
915
+ );
916
+ return d.length === 0 && l.length === 0 ? null : /* @__PURE__ */ c("div", { className: "mt-2 rounded-[5px] border border-white/70 bg-background/60 p-2", children: [
917
+ e != null && e.intent ? /* @__PURE__ */ r("div", { className: "mb-1.5 text-[11px] font-medium text-foreground", children: e.intent }) : null,
918
+ /* @__PURE__ */ c("div", { className: "space-y-1", children: [
919
+ d.map((p) => /* @__PURE__ */ c(
920
+ "div",
921
+ {
922
+ className: "flex items-start justify-between gap-2 rounded-[4px] bg-background/70 px-2 py-1",
923
+ children: [
924
+ /* @__PURE__ */ c("div", { className: "min-w-0", children: [
925
+ /* @__PURE__ */ r("div", { className: "truncate font-mono text-[11px] text-foreground", children: p.path }),
926
+ /* @__PURE__ */ r("div", { className: "mt-0.5 line-clamp-2 text-[10.5px] text-muted-foreground", children: p.purpose })
927
+ ] }),
928
+ /* @__PURE__ */ c("div", { className: "flex shrink-0 items-center gap-1", children: [
929
+ /* @__PURE__ */ r("span", { className: "rounded-[4px] bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-[0.04em] text-muted-foreground", children: p.action }),
930
+ s.has(p.path) ? /* @__PURE__ */ r("span", { className: "rounded-[4px] bg-emerald-50 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-[0.04em] text-emerald-700", children: "changed" }) : null
931
+ ] })
932
+ ]
933
+ },
934
+ p.path
935
+ )),
936
+ l.map((p) => /* @__PURE__ */ c(
937
+ "div",
938
+ {
939
+ className: "flex items-center justify-between gap-2 rounded-[4px] bg-background/70 px-2 py-1",
940
+ children: [
941
+ /* @__PURE__ */ r("span", { className: "min-w-0 truncate font-mono text-[11px] text-foreground", children: p }),
942
+ /* @__PURE__ */ r("span", { className: "rounded-[4px] bg-emerald-50 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-[0.04em] text-emerald-700", children: "changed" })
943
+ ]
944
+ },
945
+ p
946
+ ))
947
+ ] })
948
+ ] });
949
+ }
950
+ function yo({
951
+ projectId: e,
952
+ projectName: a,
953
+ dataAppId: s,
954
+ apiServiceUrl: d,
955
+ adapters: l
956
+ }) {
957
+ var v, B;
958
+ const p = Zn(ea), h = typeof window > "u" ? void 0 : window.location.origin, g = d || ((v = p.tokenProps) == null ? void 0 : v.apiServiceUrl) || h, S = (B = p.authToken) == null ? void 0 : B.accessToken, [f, R] = x(() => fe("builder-session"));
959
+ return /* @__PURE__ */ r("main", { className: "flex h-full min-h-0 w-full min-w-0 flex-1 flex-col self-stretch bg-muted/40 text-foreground", children: /* @__PURE__ */ r(
960
+ Ya,
961
+ {
962
+ adapters: l,
963
+ apiServiceUrl: g,
964
+ accessToken: S,
965
+ initialDataAppId: s || null,
966
+ initialPrompt: "",
967
+ path: "bridge",
968
+ projectId: e,
969
+ projectName: a,
970
+ onRestart: () => R(fe("builder-session"))
971
+ },
972
+ f
973
+ ) });
974
+ }
975
+ function Ya({
976
+ adapters: e,
977
+ apiServiceUrl: a,
978
+ accessToken: s,
979
+ initialDataAppId: d,
980
+ initialPrompt: l,
981
+ path: p,
982
+ projectId: h,
983
+ projectName: g,
984
+ onRestart: S
985
+ }) {
986
+ var Or, Ir;
987
+ const [f, R] = x(It), [v, B] = x(Xr), [b, E] = x(Lt), [j, I] = x(!1), [F, z] = x(It), [ve, Y] = x(0), [A] = x(p), [_e, ct] = x(
988
+ l || ""
989
+ ), [ut, Ue] = x([]), [$e, De] = x([]), [Z, ge] = x([]), [Qt, Ge] = x(null), [X, Ke] = x(!1), [ee, qt] = x(!1), [Pe, un] = x(!0), [pn, se] = x("idle"), [hn, ie] = x(null), [Yt, Zt] = x(null), [Xt, Qe] = x(() => Date.now()), [Fe, er] = x(null), [pt, mn] = x("gpt-5.5-low"), q = oe(null), G = oe(null), ht = oe([]), mt = oe(null), ft = oe(null), tr = oe(null), [be, ke] = x(!1), [rr, le] = x(null), [nr, gt] = x(!1), [ar, or] = x(!1), [Me, bt] = x("idle"), [sr, ir] = x(
990
+ null
991
+ ), [fn, lr] = x(""), [gn, dr] = x([]), [xt, cr] = x([]), [wt, ur] = x(null), [pr, bn] = x([]), [xn, wn] = x(null), [yt, hr] = x(null), [vt, mr] = x(null), [xe, qe] = x(
992
+ d || null
993
+ ), [Ye, kt] = x("idle"), [fr, Nt] = x("idle"), [gr, br] = x(null), [xr, wr] = x(null), [St, Ne] = x(null), [de, J] = x(null), [yr, Ze] = x(null), [Xe, At] = x(null), [Ct, et] = x(!1), [Rt, vr] = x(""), [kr, Bt] = x(null), [Nr, Sr] = x(!1), Te = oe(
994
+ null
995
+ ), $t = oe(null), Se = oe(null), Ar = (e == null ? void 0 : e.readStatus) || Ra, tt = (e == null ? void 0 : e.runTurn) || Ba, Dt = (e == null ? void 0 : e.saveDraft) || Da, yn = (e == null ? void 0 : e.loadApp) || Pa, Pt = (e == null ? void 0 : e.publish) || Fa, V = je(() => Ca(pt), [pt]), vn = je(
996
+ () => Z.find(
997
+ (t) => t.type === "run" && t.id === Qt
998
+ ),
999
+ [Qt, Z]
1000
+ ), Ft = je(
1001
+ () => [...Z].reverse().find((t) => t.type === "run"),
1002
+ [Z]
1003
+ ), Mt = je(() => {
1004
+ const t = F.includes("?") ? "&" : "?";
1005
+ return `${F}${t}dataAppBuilderRefresh=${ve}`;
1006
+ }, [F, ve]);
1007
+ W(() => {
1008
+ const t = window.setInterval(() => Qe(Date.now()), 500);
1009
+ return () => window.clearInterval(t);
1010
+ }, []), W(() => {
1011
+ ht.current = Z;
1012
+ }, [Z]), W(() => {
1013
+ if (!Ct) return;
1014
+ const t = () => {
1015
+ et(!1);
1016
+ };
1017
+ return window.addEventListener("blur", t), () => {
1018
+ window.removeEventListener("blur", t);
1019
+ };
1020
+ }, [Ct]), W(() => {
1021
+ I(!1);
1022
+ const t = window.localStorage.getItem(he(qr, h)) || It, n = window.localStorage.getItem(he(Yr, h)) || Xr, i = window.localStorage.getItem(he(Zr, h)) || Lt, o = window.localStorage.getItem(
1023
+ he(Qr, h)
1024
+ );
1025
+ if (R(t), z(t), B(n), E(i), I(!0), o)
1026
+ try {
1027
+ ge(JSON.parse(o));
1028
+ } catch {
1029
+ ge([]);
1030
+ }
1031
+ }, [h]), W(() => {
1032
+ window.localStorage.setItem(
1033
+ he(qr, h),
1034
+ f
1035
+ );
1036
+ }, [f, h]), W(() => {
1037
+ window.localStorage.setItem(
1038
+ he(Yr, h),
1039
+ v
1040
+ );
1041
+ }, [v, h]), W(() => {
1042
+ window.localStorage.setItem(
1043
+ he(Zr, h),
1044
+ b
1045
+ );
1046
+ }, [b, h]), W(() => {
1047
+ var t;
1048
+ window.localStorage.setItem(
1049
+ he(Qr, h),
1050
+ JSON.stringify(Z.map(oo))
1051
+ ), (t = mt.current) == null || t.scrollTo({
1052
+ top: mt.current.scrollHeight,
1053
+ behavior: "smooth"
1054
+ });
1055
+ }, [Z, h]), W(() => {
1056
+ Se.current = yt;
1057
+ }, [yt]);
1058
+ const Tt = Ot(
1059
+ async (t) => {
1060
+ if (A !== "bridge" || !a) return;
1061
+ const n = v.replace(/\/$/, ""), i = await fetch(`${n}/runtime-context`, {
1062
+ method: "POST",
1063
+ signal: t,
1064
+ headers: { "Content-Type": "application/json" },
1065
+ body: JSON.stringify({
1066
+ accessToken: s || null,
1067
+ apiBaseUrl: a,
1068
+ dataApiBaseUrl: a,
1069
+ dataAppId: xe,
1070
+ projectId: h
1071
+ })
1072
+ }), o = await O(i, "Local bridge /runtime-context");
1073
+ if (!i.ok || !o.ok)
1074
+ throw new Error(o.error || "Bridge could not sync runtime context.");
1075
+ },
1076
+ [s, a, v, xe, h, A]
1077
+ );
1078
+ W(() => {
1079
+ if (A !== "bridge" || !a) return;
1080
+ const t = new AbortController();
1081
+ return Tt(t.signal).then(() => {
1082
+ Y((n) => n + 1);
1083
+ }).catch((n) => {
1084
+ t.signal.aborted || (gt(!1), le(
1085
+ n instanceof Error ? n.message : "Bridge could not sync runtime context."
1086
+ ));
1087
+ }), () => t.abort();
1088
+ }, [a, A, Tt]), W(() => {
1089
+ qe(d || null);
1090
+ }, [d]), W(() => {
1091
+ if (!d || !j || $t.current === `${d}:${A}:${b}`)
1092
+ return;
1093
+ const t = new AbortController();
1094
+ return $t.current = `${d}:${A}:${b}`, Ne(null), J({
1095
+ state: "running",
1096
+ label: "Opening Data App",
1097
+ detail: "Loading the saved Data App draft from Semaphor."
1098
+ }), (async () => {
1099
+ var n, i;
1100
+ try {
1101
+ const o = await yn(
1102
+ { dataAppId: d },
1103
+ { apiServiceUrl: a, accessToken: s, signal: t.signal }
1104
+ );
1105
+ if (t.signal.aborted) return;
1106
+ qe(o.id);
1107
+ const u = Ja(o);
1108
+ if (!u) {
1109
+ J({
1110
+ state: "done",
1111
+ label: "Data App opened",
1112
+ detail: "No saved source snapshot exists yet."
1113
+ });
1114
+ return;
1115
+ }
1116
+ const m = Ha(
1117
+ u.manifest
1118
+ );
1119
+ m && At(m), u.status === "draft" ? br(u.updatedAt || null) : u.status === "ready" && wr(u.updatedAt || null);
1120
+ const k = Va(u, b);
1121
+ let w = !1;
1122
+ if (A === "bridge" && ((i = (n = u.sourceSnapshot) == null ? void 0 : n.files) != null && i.length) && (J({
1123
+ state: "running",
1124
+ label: "Restore saved source",
1125
+ detail: "Comparing the saved source snapshot with the bridge workspace."
1126
+ }), w = await Vn({
1127
+ snapshot: u.sourceSnapshot,
1128
+ targetProjectDir: k,
1129
+ signal: t.signal
1130
+ }), w && Y((C) => C + 1)), A === "bridge" && k !== b && E(k), t.signal.aborted) return;
1131
+ J({
1132
+ state: "done",
1133
+ label: "Data App opened",
1134
+ detail: w ? "Saved source was restored into the bridge workspace." : "Saved draft metadata was loaded."
1135
+ });
1136
+ } catch (o) {
1137
+ if (t.signal.aborted) return;
1138
+ const u = o instanceof Error ? o.message : String(o);
1139
+ $t.current = null, Ne(u), J({
1140
+ state: "failed",
1141
+ label: "Open Data App failed",
1142
+ detail: u
1143
+ }), M(`Open Data App failed: ${u}`, "blocked");
1144
+ }
1145
+ })(), () => t.abort();
1146
+ }, [j, d, b, A]), W(() => {
1147
+ function t(n) {
1148
+ var u;
1149
+ if (n.source !== ((u = ft.current) == null ? void 0 : u.contentWindow)) return;
1150
+ const i = n.data;
1151
+ if ((i == null ? void 0 : i.source) !== "semaphor-dev-bridge-inspector") return;
1152
+ if (i.type === "ready" && be) {
1153
+ at("inspect-enable");
1154
+ return;
1155
+ }
1156
+ if (i.type === "enabled") {
1157
+ le("Click an element in the preview. Press Esc to cancel.");
1158
+ return;
1159
+ }
1160
+ if (i.type === "disabled") {
1161
+ ke(!1);
1162
+ return;
1163
+ }
1164
+ if (i.type !== "selection" || !i.payload) return;
1165
+ const o = Mn(i.payload);
1166
+ Ue((m) => [...m, o]), ke(!1), le(`Selected ${o.name}. Add a message and send it.`);
1167
+ }
1168
+ return window.addEventListener("message", t), () => window.removeEventListener("message", t);
1169
+ }, [be]), W(() => {
1170
+ ke(!1), gt(!1), le(null);
1171
+ }, [v, b, A]), W(() => {
1172
+ if (X || ee || $e.length === 0) return;
1173
+ const [t, ...n] = $e;
1174
+ De(n), Br(t);
1175
+ }, [X, ee, $e]), W(() => {
1176
+ let t = !1;
1177
+ const n = new AbortController();
1178
+ async function i() {
1179
+ try {
1180
+ const o = await Ar({
1181
+ apiServiceUrl: a,
1182
+ accessToken: s,
1183
+ signal: n.signal
1184
+ });
1185
+ t || er(o);
1186
+ } catch (o) {
1187
+ t || er({
1188
+ ok: !1,
1189
+ error: o instanceof Error ? o.message : String(o)
1190
+ });
1191
+ }
1192
+ }
1193
+ return i(), () => {
1194
+ t = !0;
1195
+ };
1196
+ }, [s, a, Ar]);
1197
+ const rt = Ot(
1198
+ async (t = G.current) => {
1199
+ if (!t) return;
1200
+ const n = await t.compileBrowserSandboxPreviewHtml();
1201
+ lr(n.html), dr(n.diagnostics), cr(n.warnings || []), ur(n.cssMode || null), Y((i) => i + 1);
1202
+ },
1203
+ []
1204
+ ), Ee = Ot(
1205
+ (t = G.current, n = Se.current) => {
1206
+ var m;
1207
+ if (!t) return;
1208
+ const i = t.listBrowserSandboxFiles(), o = t.readBrowserSandboxWorkspaceContext(), u = n && i.some((k) => k.path === n) ? n : ((m = i[0]) == null ? void 0 : m.path) || null;
1209
+ bn(i), wn(o.runtimeManifest || null), hr(u), Se.current = u, mr(
1210
+ u && t.readBrowserSandboxFiles([u])[0] || null
1211
+ );
1212
+ },
1213
+ []
1214
+ );
1215
+ W(() => {
1216
+ if (A !== "browser") return;
1217
+ let t = !1;
1218
+ async function n() {
1219
+ bt("loading"), ir(null), window.__SEMAPHOR_BROWSER_SANDBOX_VENDOR__ = {
1220
+ React: Yn,
1221
+ ReactDOMClient: Xn
1222
+ };
1223
+ try {
1224
+ const i = await ot();
1225
+ if (t) return;
1226
+ G.current = i, bt("ready"), await rt(i), Ee(i);
1227
+ } catch (i) {
1228
+ if (t) return;
1229
+ bt("failed"), ir(
1230
+ i instanceof Error ? i.message : String(i)
1231
+ );
1232
+ }
1233
+ }
1234
+ return n(), () => {
1235
+ t = !0;
1236
+ };
1237
+ }, [A, Ee, rt]);
1238
+ function kn(t) {
1239
+ const n = G.current;
1240
+ hr(t), Se.current = t, mr(
1241
+ n && n.readBrowserSandboxFiles([t])[0] || null
1242
+ );
1243
+ }
1244
+ async function Cr() {
1245
+ const t = G.current;
1246
+ !t || X || (t.resetBrowserSandbox(), await rt(t), Ee(t), M(
1247
+ "Browser Sandbox reset to the approved starter template. Existing generated browser files were replaced in local browser storage.",
1248
+ "guidance"
1249
+ ));
1250
+ }
1251
+ async function Nn() {
1252
+ if (X || ee) return;
1253
+ if (At(null), Ze(null), vr(""), Bt(null), A === "browser") {
1254
+ await Cr();
1255
+ return;
1256
+ }
1257
+ const t = new AbortController(), n = v.replace(/\/$/, "");
1258
+ try {
1259
+ J({
1260
+ state: "running",
1261
+ label: "Resetting app",
1262
+ detail: "Restoring the local workspace to the blank Data App template."
1263
+ });
1264
+ const i = await fetch(`${n}/reset-app`, {
1265
+ method: "POST",
1266
+ signal: t.signal,
1267
+ headers: { "Content-Type": "application/json" },
1268
+ body: JSON.stringify({})
1269
+ }), o = await O(
1270
+ i,
1271
+ "Local bridge /reset-app"
1272
+ );
1273
+ if (!i.ok || !o.ok)
1274
+ throw new Error(o.error || "Bridge could not reset the app.");
1275
+ z(f), Y((u) => u + 1), J({
1276
+ state: "done",
1277
+ label: "App reset",
1278
+ detail: "Blank template restored and typecheck passed."
1279
+ }), M(
1280
+ "Reset the local app to the blank Data App template. You can start a new build from here.",
1281
+ "guidance"
1282
+ );
1283
+ } catch (i) {
1284
+ const o = i instanceof Error ? i.message : String(i);
1285
+ J({
1286
+ state: "failed",
1287
+ label: "Reset failed",
1288
+ detail: o
1289
+ }), M(`Reset failed: ${o}`, "blocked");
1290
+ }
1291
+ }
1292
+ function Sn(t) {
1293
+ const n = t.durationMs ?? 0;
1294
+ return t.state !== "running" || !t.startedAt ? n : n + Math.max(0, Xt - t.startedAt);
1295
+ }
1296
+ function An(t, n, i) {
1297
+ const o = t.durationMs ?? 0;
1298
+ return t.state !== "running" && n.state === "running" ? {
1299
+ ...n,
1300
+ startedAt: i,
1301
+ durationMs: o
1302
+ } : t.state === "running" && n.state !== "running" ? {
1303
+ ...n,
1304
+ startedAt: void 0,
1305
+ durationMs: o + Math.max(0, i - (t.startedAt ?? i))
1306
+ } : {
1307
+ ...n,
1308
+ startedAt: t.startedAt,
1309
+ durationMs: o
1310
+ };
1311
+ }
1312
+ function Cn(t, n, i) {
1313
+ const o = Date.now();
1314
+ Qe(o), ge(
1315
+ (u) => u.map((m) => {
1316
+ if (m.type !== "run" || m.id !== t) return m;
1317
+ const k = n(m.steps), w = new Map(
1318
+ m.steps.map((C) => [C.id, C])
1319
+ );
1320
+ return {
1321
+ ...m,
1322
+ ...i,
1323
+ steps: k.map((C) => {
1324
+ const y = w.get(C.id);
1325
+ return y ? An(y, C, o) : C;
1326
+ })
1327
+ };
1328
+ })
1329
+ );
1330
+ }
1331
+ function nt(t, n) {
1332
+ ge(
1333
+ (i) => i.map(
1334
+ (o) => o.type === "run" && o.id === t ? { ...o, ...n } : o
1335
+ )
1336
+ );
1337
+ }
1338
+ function M(t, n = "default", i) {
1339
+ const o = Je(
1340
+ i == null ? void 0 : i.intentManifest
1341
+ ) ? i == null ? void 0 : i.intentManifest : void 0;
1342
+ ge((u) => [
1343
+ ...u,
1344
+ {
1345
+ id: fe("assistant"),
1346
+ type: "assistant",
1347
+ content: t,
1348
+ createdAt: Date.now(),
1349
+ tone: n,
1350
+ artifacts: i == null ? void 0 : i.artifacts,
1351
+ operation: i == null ? void 0 : i.operation,
1352
+ intentManifest: o
1353
+ }
1354
+ ]);
1355
+ }
1356
+ function Rn(t) {
1357
+ var i;
1358
+ t.intentManifest && At(
1359
+ (o) => Ga(o, t.intentManifest)
1360
+ );
1361
+ const n = (i = t.artifacts) == null ? void 0 : i.find(
1362
+ (o) => o.type === "dataset_inspector"
1363
+ );
1364
+ n && Ze(n);
1365
+ }
1366
+ function Rr(t) {
1367
+ se({
1368
+ received: "context",
1369
+ authenticating: "context",
1370
+ routing: "thinking",
1371
+ inspecting_data: "inspecting-data",
1372
+ reading_files: "reading-files",
1373
+ planning_revision: "planning",
1374
+ generating_code: "generating",
1375
+ done: "thinking"
1376
+ }[t.phase]), ie(t.detail || t.label);
1377
+ }
1378
+ function Br(t) {
1379
+ const n = t.prompt.trim();
1380
+ if (!n) return;
1381
+ const i = Date.now();
1382
+ ge((o) => [
1383
+ ...o,
1384
+ {
1385
+ id: fe("user"),
1386
+ type: "user",
1387
+ content: n,
1388
+ createdAt: i,
1389
+ attachments: t.attachments
1390
+ }
1391
+ ]), Zt(i), se("context"), ie("Preparing app context and available files."), Kn({ ...t, prompt: n });
1392
+ }
1393
+ async function Bn(t) {
1394
+ if (!t.type.startsWith("image/")) {
1395
+ M("Only image attachments are supported right now.", "blocked");
1396
+ return;
1397
+ }
1398
+ if (t.size > 6 * 1024 * 1024) {
1399
+ M(
1400
+ "That screenshot is larger than 6MB. Please attach a smaller image.",
1401
+ "blocked"
1402
+ );
1403
+ return;
1404
+ }
1405
+ const n = await new Promise((i, o) => {
1406
+ const u = new FileReader();
1407
+ u.onload = () => {
1408
+ typeof u.result == "string" ? i(u.result) : o(new Error("Could not read image attachment."));
1409
+ }, u.onerror = () => o(u.error || new Error("Could not read image attachment.")), u.readAsDataURL(t);
1410
+ });
1411
+ Ue((i) => [
1412
+ ...i,
1413
+ {
1414
+ id: fe("attachment"),
1415
+ type: "screenshot",
1416
+ name: t.name || "Screenshot",
1417
+ imageUrl: n,
1418
+ mediaType: t.type,
1419
+ createdAt: Date.now()
1420
+ }
1421
+ ]);
1422
+ }
1423
+ function $n(t) {
1424
+ Ue(
1425
+ (n) => n.filter((i) => i.id !== t)
1426
+ );
1427
+ }
1428
+ function at(t) {
1429
+ var i, o;
1430
+ let n = "*";
1431
+ try {
1432
+ n = new URL(Mt).origin;
1433
+ } catch {
1434
+ n = "*";
1435
+ }
1436
+ (o = (i = ft.current) == null ? void 0 : i.contentWindow) == null || o.postMessage(
1437
+ { source: "semaphor-data-app-builder", type: t },
1438
+ n
1439
+ );
1440
+ }
1441
+ async function Dn() {
1442
+ const t = v.replace(/\/$/, ""), n = await fetch(`${t}/inspect/install`, {
1443
+ method: "POST",
1444
+ headers: { "Content-Type": "application/json" },
1445
+ body: JSON.stringify({ projectDir: b })
1446
+ }), i = await O(n, "Local bridge /inspect/install");
1447
+ if (!n.ok || !i.ok)
1448
+ throw new Error(i.error || "Bridge could not install inspector.");
1449
+ return i;
1450
+ }
1451
+ async function Pn() {
1452
+ if (A !== "bridge") {
1453
+ M(
1454
+ "Element inspection is only available in Local Bridge mode right now.",
1455
+ "blocked"
1456
+ );
1457
+ return;
1458
+ }
1459
+ try {
1460
+ or(!0), le(nr ? null : "Preparing element inspector…");
1461
+ let t = !1;
1462
+ if (!nr) {
1463
+ const n = await Dn();
1464
+ gt(!!n.installed), t = !!n.changed;
1465
+ }
1466
+ ke(!0), le(
1467
+ t ? "Loading inspector in the preview…" : "Click an element in the preview. Press Esc to cancel."
1468
+ ), t ? (z(f), Y((n) => n + 1)) : window.setTimeout(() => at("inspect-enable"), 50);
1469
+ } catch (t) {
1470
+ ke(!1), le(null), M(
1471
+ t instanceof Error ? t.message : String(t),
1472
+ "blocked"
1473
+ );
1474
+ } finally {
1475
+ or(!1);
1476
+ }
1477
+ }
1478
+ function Fn() {
1479
+ ke(!1), le(null), at("inspect-disable");
1480
+ }
1481
+ function Mn(t) {
1482
+ const n = (y, N = "") => typeof y == "string" && y.trim() ? y.trim() : N, i = (y) => Array.isArray(y) ? y.map(
1483
+ (N) => typeof N == "string" ? N : N && typeof N == "object" ? JSON.stringify(N) : ""
1484
+ ).filter(Boolean) : [], o = n(t.elementLabel) || n(t.name), u = n(t.component), m = o && u && o !== u ? `${o} in ${u}` : o || u || n(t.tagName, "Selected element"), k = i(t.reactOwners), w = i(t.sourceHints), C = [
1485
+ `Clicked element: ${o || m}`,
1486
+ `Nearest component: ${u || "unavailable"}`,
1487
+ `Tag: ${n(t.tagName, "unknown")}`,
1488
+ `Role: ${n(t.role, "none")}`,
1489
+ `Selector: ${n(t.selector, "none")}`,
1490
+ k.length ? `React owner stack: ${k.join(" > ")}` : "React owner stack: unavailable",
1491
+ w.length ? `Source hints: ${w.join(" | ")}` : "Source hints: unavailable",
1492
+ `Bounds: ${JSON.stringify(t.bounds || {})}`,
1493
+ `Ancestors: ${i(t.ancestorSummary).join(" > ") || "none"}`,
1494
+ `Classes: ${n(t.classes, "none")}`,
1495
+ "",
1496
+ "Visible text:",
1497
+ n(t.text, "(no visible text)"),
1498
+ "",
1499
+ "HTML excerpt:",
1500
+ n(t.htmlExcerpt, "(no HTML excerpt)")
1501
+ ].join(`
1502
+ `);
1503
+ return {
1504
+ id: fe("attachment"),
1505
+ type: "dom-selection",
1506
+ name: m,
1507
+ text: C,
1508
+ createdAt: Date.now()
1509
+ };
1510
+ }
1511
+ function Tn(t, n) {
1512
+ De(
1513
+ (i) => i.map((o) => o.id === t ? { ...o, prompt: n } : o)
1514
+ );
1515
+ }
1516
+ function En(t) {
1517
+ De((n) => n.filter((i) => i.id !== t));
1518
+ }
1519
+ function On(t, n) {
1520
+ De(
1521
+ (i) => i.map(
1522
+ (o) => o.id === t ? {
1523
+ ...o,
1524
+ attachments: o.attachments.filter(
1525
+ (u) => u.id !== n
1526
+ )
1527
+ } : o
1528
+ )
1529
+ );
1530
+ }
1531
+ async function $r(t) {
1532
+ for (const n of Array.from(t))
1533
+ await Bn(n);
1534
+ }
1535
+ function Dr(t, n) {
1536
+ var u;
1537
+ const i = n === "browser" ? "Browser Sandbox" : "Local Bridge", o = (u = t.changedFiles) != null && u.length ? t.changedFiles.join(", ") : "no files";
1538
+ return t.ok ? `${i} applied the revision and validation passed. Changed files: ${o}. The preview has been refreshed; inspect the file tree and run card for the exact file plan.` : `${i} could not finish the revision cleanly. Changed files: ${o}. The run card includes the validation output so you can ask a follow-up repair question or switch runtimes.`;
1539
+ }
1540
+ function K(t, n) {
1541
+ Cn(
1542
+ t,
1543
+ (i) => i.map((o) => {
1544
+ if (n === "failed")
1545
+ return {
1546
+ ...o,
1547
+ state: o.state === "running" ? "blocked" : o.state
1548
+ };
1549
+ const u = {
1550
+ reading: [],
1551
+ generating: ["context"],
1552
+ writing: ["context", "generate"],
1553
+ typechecking: ["context", "generate", "edit"],
1554
+ repairing: ["context", "generate", "edit", "typecheck"],
1555
+ complete: ["context", "generate", "edit", "typecheck", "repair", "preview"]
1556
+ }, k = {
1557
+ reading: "context",
1558
+ generating: "generate",
1559
+ writing: "edit",
1560
+ typechecking: "typecheck",
1561
+ repairing: "repair"
1562
+ }[n];
1563
+ return {
1564
+ ...o,
1565
+ state: u[n].includes(o.id) ? "done" : k === o.id ? "running" : o.state === "done" ? "done" : "idle"
1566
+ };
1567
+ })
1568
+ );
1569
+ }
1570
+ async function In(t, n, i) {
1571
+ var k, w, C, y;
1572
+ (k = q.current) == null || k.abort();
1573
+ const o = new AbortController(), u = Date.now();
1574
+ q.current = o, Ke(!0), Ge(n), Qe(u), K(n, "reading");
1575
+ const m = window.setTimeout(() => {
1576
+ o.abort();
1577
+ }, 18e4);
1578
+ try {
1579
+ let N = G.current;
1580
+ N || (N = await ot(), G.current = N);
1581
+ const L = N.readBrowserSandboxWorkspaceContext(), $ = (C = (w = L.files) == null ? void 0 : w.editable) != null && C.length ? tn(
1582
+ L.files.editable,
1583
+ Se.current,
1584
+ t
1585
+ ) : ["src/App.tsx"], ce = N.readBrowserSandboxFiles($), Ae = ce.reduce(
1586
+ (ne, te) => ne + te.contents.length,
1587
+ 0
1588
+ );
1589
+ let Ce = ce, Oe = [], ue = i, Q = null;
1590
+ const pe = [];
1591
+ for (let ne = 0; ne < ze; ne += 1) {
1592
+ const te = Oe.length > 0 || ne > 0, Ie = te ? `repair-${ne + 1}` : "initial";
1593
+ K(n, te ? "repairing" : "generating");
1594
+ const _ = ue || (await tt(
1595
+ {
1596
+ projectId: h,
1597
+ message: t,
1598
+ currentFiles: Ce,
1599
+ workspaceContext: L,
1600
+ diagnostics: Oe,
1601
+ repair: te,
1602
+ generationModel: V.model,
1603
+ generationReasoningEffort: V.reasoningEffort,
1604
+ repairModel: V.model,
1605
+ repairReasoningEffort: V.reasoningEffort
1606
+ },
1607
+ { accessToken: s, apiServiceUrl: a, signal: o.signal }
1608
+ )).revision;
1609
+ if (ue = void 0, !_)
1610
+ throw new Error("Data App Builder did not return a revision.");
1611
+ K(n, "writing");
1612
+ const we = N.applyBrowserSandboxRevision({
1613
+ ..._,
1614
+ attemptLabel: Ie
1615
+ });
1616
+ pe.push(...we.attempts || []), K(n, "typechecking");
1617
+ let D = {
1618
+ ...we,
1619
+ attempts: [...pe],
1620
+ filePlan: _.plan,
1621
+ telemetry: {
1622
+ contextFileCount: ce.length,
1623
+ contextChars: Ae,
1624
+ generatedFileCount: _.files.length,
1625
+ generatedChars: _.files.reduce(
1626
+ (P, U) => P + U.contents.length,
1627
+ 0
1628
+ ),
1629
+ repairAttempts: pe.filter(
1630
+ (P) => P.label.startsWith("repair")
1631
+ ).length
1632
+ }
1633
+ };
1634
+ if (we.ok) {
1635
+ const P = await N.compileBrowserSandboxPreviewHtml();
1636
+ if (lr(P.html), dr(P.diagnostics), cr(P.warnings || []), ur(P.cssMode || null), Y((U) => U + 1), Ee(N), P.diagnostics.length > 0) {
1637
+ const U = {
1638
+ command: "browser sandbox preview compile",
1639
+ durationMs: 0,
1640
+ exitCode: 1,
1641
+ ok: !1,
1642
+ stdout: "",
1643
+ stderr: P.diagnostics.join(`
1644
+ `)
1645
+ };
1646
+ D = {
1647
+ ...D,
1648
+ ok: !1,
1649
+ validation: "typecheck",
1650
+ command: U,
1651
+ attempts: [
1652
+ ...pe,
1653
+ { label: Ie, ok: !1, command: U }
1654
+ ],
1655
+ error: "Generated files failed Browser Sandbox preview compile."
1656
+ };
1657
+ }
1658
+ }
1659
+ if (Q = D, D.ok || ne === ze - 1)
1660
+ break;
1661
+ const T = (y = D.changedFiles) != null && y.length ? D.changedFiles : _.files.map(
1662
+ (P) => P.path
1663
+ );
1664
+ Ce = N.readBrowserSandboxFiles(
1665
+ Array.from(/* @__PURE__ */ new Set([...$, ...T]))
1666
+ ), Oe = [zt(D)];
1667
+ }
1668
+ if (!Q)
1669
+ throw new Error("The browser runtime loop ended without a validation result.");
1670
+ K(n, Q.ok ? "complete" : "failed"), nt(n, {
1671
+ status: Q.ok ? "done" : "failed",
1672
+ result: Q,
1673
+ error: Q.error,
1674
+ finishedAt: Date.now()
1675
+ }), M(
1676
+ Dr(Q, "browser"),
1677
+ Q.ok ? "default" : "blocked"
1678
+ );
1679
+ } catch (N) {
1680
+ const L = N instanceof DOMException && N.name === "AbortError", $ = L ? "Timed out waiting for the browser runtime loop." : N instanceof Error ? N.message : String(N);
1681
+ nt(n, {
1682
+ status: L ? "cancelled" : "failed",
1683
+ error: $,
1684
+ result: {
1685
+ ok: !1,
1686
+ error: $,
1687
+ summary: "The app-builder/browser runtime loop stopped before validation completed."
1688
+ },
1689
+ finishedAt: Date.now()
1690
+ }), M(
1691
+ `Browser Sandbox stopped before it could validate the app: ${$}`,
1692
+ "blocked"
1693
+ ), K(n, "failed");
1694
+ } finally {
1695
+ Ke(!1), Ge(null), q.current = null, window.clearTimeout(m);
1696
+ }
1697
+ }
1698
+ async function Ln(t, n, i) {
1699
+ var k, w, C, y;
1700
+ (k = q.current) == null || k.abort();
1701
+ const o = new AbortController(), u = Date.now();
1702
+ q.current = o, Ke(!0), Ge(n), Qe(u), K(n, "reading");
1703
+ const m = window.setTimeout(() => {
1704
+ o.abort();
1705
+ }, 18e4);
1706
+ try {
1707
+ const N = v.replace(/\/$/, ""), L = async (D) => {
1708
+ const T = await fetch(`${N}/read-files`, {
1709
+ method: "POST",
1710
+ signal: o.signal,
1711
+ headers: { "Content-Type": "application/json" },
1712
+ body: JSON.stringify({ paths: D, projectDir: b })
1713
+ }), P = await O(
1714
+ T,
1715
+ "Local bridge /read-files"
1716
+ );
1717
+ if (!T.ok || !P.ok || !P.files)
1718
+ throw new Error(P.error || "Bridge could not read target files.");
1719
+ return P.files;
1720
+ }, $ = async () => {
1721
+ const D = await fetch(`${N}/workspace-context`, {
1722
+ method: "POST",
1723
+ signal: o.signal,
1724
+ headers: { "Content-Type": "application/json" },
1725
+ body: JSON.stringify({ projectDir: b })
1726
+ }), T = await O(
1727
+ D,
1728
+ "Local bridge /workspace-context"
1729
+ );
1730
+ if (!D.ok || !T.ok || !T.workspaceContext)
1731
+ throw new Error(
1732
+ T.error || "Bridge could not read workspace context."
1733
+ );
1734
+ return T.workspaceContext;
1735
+ };
1736
+ let ce = i;
1737
+ const Ae = async ({
1738
+ currentFiles: D,
1739
+ workspaceContext: T,
1740
+ diagnostics: P = [],
1741
+ repair: U = !1
1742
+ }) => {
1743
+ const ae = ce || (await tt(
1744
+ {
1745
+ projectId: h,
1746
+ message: t,
1747
+ currentFiles: D,
1748
+ workspaceContext: T,
1749
+ diagnostics: P,
1750
+ repair: U,
1751
+ generationModel: V.model,
1752
+ generationReasoningEffort: V.reasoningEffort,
1753
+ repairModel: V.model,
1754
+ repairReasoningEffort: V.reasoningEffort
1755
+ },
1756
+ { accessToken: s, apiServiceUrl: a, signal: o.signal }
1757
+ )).revision;
1758
+ if (ce = void 0, !ae)
1759
+ throw new Error("Data App Builder did not return a revision.");
1760
+ return ae;
1761
+ }, Ce = async (D) => {
1762
+ const T = await fetch(`${N}/apply-files`, {
1763
+ method: "POST",
1764
+ signal: o.signal,
1765
+ headers: { "Content-Type": "application/json" },
1766
+ body: JSON.stringify({ revision: D, projectDir: b })
1767
+ }), P = await O(
1768
+ T,
1769
+ "Local bridge /apply-files"
1770
+ );
1771
+ if (!T.ok && !P.command && !P.writePolicyValidation && !P.importValidation && !P.dataApiValidation)
1772
+ throw new Error(
1773
+ P.error || "Bridge could not apply generated files."
1774
+ );
1775
+ return P;
1776
+ }, Oe = async () => {
1777
+ const D = await fetch(`${N}/validate-typecheck`, {
1778
+ method: "POST",
1779
+ signal: o.signal,
1780
+ headers: { "Content-Type": "application/json" },
1781
+ body: JSON.stringify({ projectDir: b })
1782
+ }), T = await O(
1783
+ D,
1784
+ "Local bridge /validate-typecheck"
1785
+ );
1786
+ if (!D.ok && !T.command)
1787
+ throw new Error(
1788
+ T.error || "Bridge could not typecheck the target app."
1789
+ );
1790
+ return T;
1791
+ }, ue = await $();
1792
+ ue.projectRoot && E(ue.projectRoot);
1793
+ let Q = (C = (w = ue.files) == null ? void 0 : w.editable) != null && C.length ? en(ue.files.editable) : ["src/App.tsx"];
1794
+ const pe = await L(Q), ne = pe.reduce(
1795
+ (D, T) => D + T.contents.length,
1796
+ 0
1797
+ );
1798
+ let te = [];
1799
+ if (Ea(t)) {
1800
+ const D = await Oe();
1801
+ D.ok || (te = [
1802
+ zt(D)
1803
+ ]);
1804
+ }
1805
+ let Ie = pe, _ = null;
1806
+ const we = [];
1807
+ for (let D = 0; D < ze; D += 1) {
1808
+ const T = te.length > 0 || D > 0, P = T ? `repair-${D + 1}` : "initial";
1809
+ K(n, T ? "repairing" : "generating");
1810
+ const U = await Ae({
1811
+ currentFiles: Ie,
1812
+ workspaceContext: ue,
1813
+ diagnostics: te,
1814
+ repair: T
1815
+ });
1816
+ K(n, "writing");
1817
+ const ae = await Ce({
1818
+ ...U,
1819
+ attemptLabel: P
1820
+ });
1821
+ if (z(f), Y((Le) => Le + 1), we.push(...ae.attempts || []), _ = {
1822
+ ...ae,
1823
+ attempts: [...we],
1824
+ filePlan: U.plan,
1825
+ telemetry: {
1826
+ contextFileCount: pe.length,
1827
+ contextChars: ne,
1828
+ generatedFileCount: U.files.length,
1829
+ generatedChars: U.files.reduce(
1830
+ (Le, qn) => Le + qn.contents.length,
1831
+ 0
1832
+ ),
1833
+ repairAttempts: we.filter(
1834
+ (Le) => Le.label.startsWith("repair")
1835
+ ).length
1836
+ }
1837
+ }, K(n, "typechecking"), ae.ok || D === ze - 1)
1838
+ break;
1839
+ Ie = (((y = ae.changedFiles) == null ? void 0 : y.length) || 0) > 0 ? await L(
1840
+ Q = Array.from(
1841
+ /* @__PURE__ */ new Set([
1842
+ ...Q,
1843
+ ...ae.changedFiles || []
1844
+ ])
1845
+ )
1846
+ ) : U.files, te = [zt(ae)];
1847
+ }
1848
+ if (!_)
1849
+ throw new Error("The app-builder loop ended without a validation result.");
1850
+ K(n, _.ok ? "complete" : "failed"), nt(n, {
1851
+ status: _.ok ? "done" : "failed",
1852
+ result: _,
1853
+ error: _.error,
1854
+ finishedAt: Date.now()
1855
+ }), M(
1856
+ Dr(_, "bridge"),
1857
+ _.ok ? "default" : "blocked"
1858
+ );
1859
+ } catch (N) {
1860
+ const L = N instanceof DOMException && N.name === "AbortError", $ = L ? "Timed out waiting for the app-builder/bridge loop. The target app may still have updated through HMR." : N instanceof Error ? N.message : String(N);
1861
+ nt(n, {
1862
+ status: L ? "cancelled" : "failed",
1863
+ error: $,
1864
+ result: {
1865
+ ok: !1,
1866
+ error: $,
1867
+ summary: "The app-builder/bridge loop stopped before validation completed."
1868
+ },
1869
+ finishedAt: Date.now()
1870
+ }), M(
1871
+ `Local Bridge stopped before it could validate the app: ${$}`,
1872
+ "blocked"
1873
+ ), K(n, "failed");
1874
+ } finally {
1875
+ Ke(!1), Ge(null), q.current = null, window.clearTimeout(m);
1876
+ }
1877
+ }
1878
+ async function jn(t) {
1879
+ var u, m;
1880
+ let n = G.current;
1881
+ n || (n = await ot(), G.current = n);
1882
+ const i = n.readBrowserSandboxWorkspaceContext(), o = (m = (u = i.files) == null ? void 0 : u.editable) != null && m.length ? tn(
1883
+ i.files.editable,
1884
+ Se.current,
1885
+ t
1886
+ ) : ["src/App.tsx"];
1887
+ return {
1888
+ currentFiles: n.readBrowserSandboxFiles(o),
1889
+ workspaceContext: i
1890
+ };
1891
+ }
1892
+ async function zn(t) {
1893
+ const n = G.current;
1894
+ return n ? n.readBrowserSandboxFiles(t) : [];
1895
+ }
1896
+ async function Et(t, n) {
1897
+ const i = v.replace(/\/$/, ""), o = await fetch(`${i}/read-files`, {
1898
+ method: "POST",
1899
+ signal: n,
1900
+ headers: { "Content-Type": "application/json" },
1901
+ body: JSON.stringify({ paths: t, projectDir: b })
1902
+ }), u = await O(
1903
+ o,
1904
+ "Local bridge /read-files"
1905
+ );
1906
+ if (!o.ok || !u.ok || !u.files)
1907
+ throw new Error(u.error || "Bridge could not read requested files.");
1908
+ return u.files;
1909
+ }
1910
+ function Wn(t, n) {
1911
+ const i = /* @__PURE__ */ new Map();
1912
+ for (const o of t)
1913
+ i.set(o.path, o);
1914
+ for (const o of n)
1915
+ i.set(o.path, o);
1916
+ return Array.from(i.values());
1917
+ }
1918
+ async function Pr(t) {
1919
+ var k, w;
1920
+ await Tt(t);
1921
+ const n = v.replace(/\/$/, ""), i = await fetch(`${n}/workspace-context`, {
1922
+ method: "POST",
1923
+ signal: t,
1924
+ headers: { "Content-Type": "application/json" },
1925
+ body: JSON.stringify({ projectDir: b })
1926
+ }), o = await O(
1927
+ i,
1928
+ "Local bridge /workspace-context"
1929
+ );
1930
+ if (!i.ok || !o.ok || !o.workspaceContext)
1931
+ throw new Error(
1932
+ o.error || "Bridge could not read workspace context."
1933
+ );
1934
+ const u = o.workspaceContext;
1935
+ u.projectRoot && E(u.projectRoot);
1936
+ const m = (w = (k = u.files) == null ? void 0 : k.editable) != null && w.length ? en(u.files.editable) : ["src/App.tsx"];
1937
+ return {
1938
+ currentFiles: await Et(m, t),
1939
+ workspaceContext: u
1940
+ };
1941
+ }
1942
+ function Fr(t, n) {
1943
+ return {
1944
+ schemaVersion: "data-app/v1",
1945
+ app: {
1946
+ id: xe || void 0,
1947
+ name: `${g} Data App`,
1948
+ createdWith: "semaphor-app-builder"
1949
+ },
1950
+ runtime: {
1951
+ framework: t.framework,
1952
+ bundler: t.framework === "vite-react" ? "vite" : void 0
1953
+ },
1954
+ semaphor: {
1955
+ projectId: h,
1956
+ runtime: A,
1957
+ intentManifest: Xe || void 0
1958
+ },
1959
+ build: {
1960
+ sourceFileCount: n.files.length,
1961
+ validation: t.validation
1962
+ }
1963
+ };
1964
+ }
1965
+ async function Mr(t) {
1966
+ var k, w, C, y, N, L;
1967
+ const { workspaceContext: n } = await Pr(t), i = v.replace(/\/$/, ""), o = await fetch(`${i}/source-snapshot`, {
1968
+ method: "POST",
1969
+ signal: t,
1970
+ headers: { "Content-Type": "application/json" },
1971
+ body: JSON.stringify({ projectDir: b })
1972
+ });
1973
+ if (o.ok) {
1974
+ const $ = await O(
1975
+ o,
1976
+ "Local bridge /source-snapshot"
1977
+ );
1978
+ if (!$.ok || !((k = $.files) != null && k.length))
1979
+ throw new Error(
1980
+ $.error || "Bridge did not return source snapshot files."
1981
+ );
1982
+ return {
1983
+ workspaceContext: n,
1984
+ snapshot: {
1985
+ schemaVersion: "data-app-source-snapshot/v1",
1986
+ files: $.files,
1987
+ metadata: {
1988
+ ...$.metadata,
1989
+ capturedAt: typeof ((w = $.metadata) == null ? void 0 : w.capturedAt) == "string" ? $.metadata.capturedAt : (/* @__PURE__ */ new Date()).toISOString(),
1990
+ projectRoot: n.projectRoot || b,
1991
+ runtime: A
1992
+ }
1993
+ }
1994
+ };
1995
+ }
1996
+ const u = (y = (C = n.files) == null ? void 0 : C.snapshot) != null && y.length ? n.files.snapshot : [
1997
+ ...((N = n.files) == null ? void 0 : N.source) || [],
1998
+ ...((L = n.files) == null ? void 0 : L.root) || []
1999
+ ], m = await Et(
2000
+ [...new Set(u.length ? u : ["src/App.tsx"])],
2001
+ t
2002
+ );
2003
+ return {
2004
+ workspaceContext: n,
2005
+ snapshot: {
2006
+ schemaVersion: "data-app-source-snapshot/v1",
2007
+ files: m,
2008
+ metadata: {
2009
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
2010
+ projectRoot: n.projectRoot || b,
2011
+ runtime: A
2012
+ }
2013
+ }
2014
+ };
2015
+ }
2016
+ async function Hn(t, n) {
2017
+ var m, k;
2018
+ const i = v.replace(/\/$/, ""), o = await fetch(`${i}/source-snapshot`, {
2019
+ method: "POST",
2020
+ signal: n,
2021
+ headers: { "Content-Type": "application/json" },
2022
+ body: JSON.stringify({ projectDir: t })
2023
+ });
2024
+ if (!o.ok) return null;
2025
+ const u = await O(
2026
+ o,
2027
+ "Local bridge /source-snapshot"
2028
+ );
2029
+ return !u.ok || !((m = u.files) != null && m.length) ? null : {
2030
+ schemaVersion: "data-app-source-snapshot/v1",
2031
+ files: u.files,
2032
+ metadata: {
2033
+ ...u.metadata,
2034
+ capturedAt: typeof ((k = u.metadata) == null ? void 0 : k.capturedAt) == "string" ? u.metadata.capturedAt : (/* @__PURE__ */ new Date()).toISOString(),
2035
+ projectRoot: t,
2036
+ runtime: A
2037
+ }
2038
+ };
2039
+ }
2040
+ async function Jn(t, n, i) {
2041
+ const o = v.replace(/\/$/, ""), u = await fetch(`${o}/apply-files`, {
2042
+ method: "POST",
2043
+ signal: i,
2044
+ headers: { "Content-Type": "application/json" },
2045
+ body: JSON.stringify({ revision: t, projectDir: n })
2046
+ }), m = await O(
2047
+ u,
2048
+ "Local bridge /apply-files"
2049
+ );
2050
+ if (!u.ok || !m.ok)
2051
+ throw new Error(m.error || "Bridge could not restore saved files.");
2052
+ return m;
2053
+ }
2054
+ async function Vn({
2055
+ snapshot: t,
2056
+ targetProjectDir: n,
2057
+ signal: i
2058
+ }) {
2059
+ const o = await Hn(
2060
+ n,
2061
+ i
2062
+ );
2063
+ if (!o)
2064
+ throw new Error(
2065
+ `Bridge could not compare the current workspace before restore: ${n}`
2066
+ );
2067
+ const u = new Map(
2068
+ o.files.map((C) => [C.path, C.contents])
2069
+ ), m = t.files.filter(
2070
+ (C) => u.get(C.path) !== C.contents
2071
+ ), k = Math.max(
2072
+ 0,
2073
+ o.files.length - t.files.length
2074
+ );
2075
+ return o && m.length === 0 || !window.confirm(
2076
+ [
2077
+ "Restore this saved Data App source snapshot into the bridge workspace?",
2078
+ "",
2079
+ `Target workspace: ${n}`,
2080
+ "",
2081
+ `${m.length || t.files.length} saved file${(m.length || t.files.length) === 1 ? "" : "s"} will be written. Extra local files are left unchanged.`,
2082
+ k ? `${k} extra local file${k === 1 ? "" : "s"} may remain in the workspace.` : ""
2083
+ ].filter(Boolean).join(`
2084
+ `)
2085
+ ) ? !1 : (await Jn(
2086
+ {
2087
+ provider: "semaphor",
2088
+ summary: "Restore saved Data App source snapshot",
2089
+ files: t.files.map((C) => ({
2090
+ path: C.path,
2091
+ contents: C.contents
2092
+ })),
2093
+ changes: t.files.map((C) => ({
2094
+ kind: "edit",
2095
+ label: C.path
2096
+ }))
2097
+ },
2098
+ n,
2099
+ i
2100
+ ), !0);
2101
+ }
2102
+ async function _n() {
2103
+ var u, m, k, w;
2104
+ let t = G.current;
2105
+ t || (t = await ot(), G.current = t);
2106
+ const n = t.readBrowserSandboxWorkspaceContext(), i = (m = (u = n.files) == null ? void 0 : u.snapshot) != null && m.length ? n.files.snapshot : [
2107
+ ...((k = n.files) == null ? void 0 : k.source) || [],
2108
+ ...((w = n.files) == null ? void 0 : w.root) || []
2109
+ ], o = t.readBrowserSandboxFiles(
2110
+ [...new Set(i.length ? i : ["src/App.tsx"])]
2111
+ );
2112
+ return {
2113
+ workspaceContext: n,
2114
+ snapshot: {
2115
+ schemaVersion: "data-app-source-snapshot/v1",
2116
+ files: o,
2117
+ metadata: {
2118
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
2119
+ projectRoot: "browser-sandbox",
2120
+ runtime: A
2121
+ }
2122
+ }
2123
+ };
2124
+ }
2125
+ async function Tr() {
2126
+ const t = new AbortController();
2127
+ Sr(!0), Bt(null);
2128
+ try {
2129
+ const { workspaceContext: n, snapshot: i } = A === "browser" ? await _n() : await Mr(t.signal), o = Fr(n, i);
2130
+ vr(JSON.stringify(o, null, 2));
2131
+ } catch (n) {
2132
+ Bt(
2133
+ n instanceof Error ? n.message : String(n)
2134
+ );
2135
+ } finally {
2136
+ Sr(!1);
2137
+ }
2138
+ }
2139
+ async function Er() {
2140
+ if (Te.current)
2141
+ return Te.current;
2142
+ if (!Dt)
2143
+ return M(
2144
+ "Save draft is not configured in this host yet.",
2145
+ "blocked"
2146
+ ), null;
2147
+ const t = new AbortController();
2148
+ kt("saving"), Ne(null), J({
2149
+ state: "running",
2150
+ label: "Saving draft",
2151
+ detail: "Reading the bridge source snapshot."
2152
+ });
2153
+ const n = (async () => {
2154
+ var i;
2155
+ try {
2156
+ const { snapshot: o, workspaceContext: u } = await Mr(
2157
+ t.signal
2158
+ ), m = Fr(u, o), k = await Ua({
2159
+ snapshot: o,
2160
+ workspaceContext: u,
2161
+ projectDir: b,
2162
+ adapter: "bridge"
2163
+ }), w = await Dt(
2164
+ {
2165
+ projectId: h,
2166
+ dataAppId: xe,
2167
+ title: xe ? void 0 : ((i = m.app) == null ? void 0 : i.name) || `${g} Data App`,
2168
+ description: xe ? void 0 : null,
2169
+ manifest: m,
2170
+ sourceSnapshot: o,
2171
+ sourceRevision: k,
2172
+ validationStatus: (Ft == null ? void 0 : Ft.result) || null,
2173
+ bridgeWorkspaceHint: u.projectRoot || b
2174
+ },
2175
+ { apiServiceUrl: a, accessToken: s, signal: t.signal }
2176
+ );
2177
+ return qe(w.dataAppId), br(w.savedAt || (/* @__PURE__ */ new Date()).toISOString()), kt("saved"), J({
2178
+ state: "done",
2179
+ label: "Draft saved",
2180
+ detail: "Semaphor has the latest source snapshot."
2181
+ }), M("Draft saved to Semaphor.", "default"), {
2182
+ dataAppId: w.dataAppId,
2183
+ draftId: w.draftId,
2184
+ manifest: m,
2185
+ snapshot: o,
2186
+ sourceRevision: k,
2187
+ workspaceContext: u
2188
+ };
2189
+ } catch (o) {
2190
+ const u = o instanceof Error ? o.message : String(o);
2191
+ return Ne(u), kt("failed"), J({
2192
+ state: "failed",
2193
+ label: "Save draft failed",
2194
+ detail: u
2195
+ }), M(`Save draft failed: ${u}`, "blocked"), null;
2196
+ } finally {
2197
+ Te.current = null;
2198
+ }
2199
+ })();
2200
+ return Te.current = n, n;
2201
+ }
2202
+ async function Un(t) {
2203
+ var u;
2204
+ const n = v.replace(/\/$/, ""), i = await fetch(`${n}/publish-build`, {
2205
+ method: "POST",
2206
+ signal: t,
2207
+ headers: { "Content-Type": "application/json" },
2208
+ body: JSON.stringify({ projectDir: b })
2209
+ }), o = await O(
2210
+ i,
2211
+ "Local bridge /publish-build"
2212
+ );
2213
+ if (!i.ok || !o.ok || !o.manifest || !o.entryFile || !((u = o.assets) != null && u.length))
2214
+ throw new Error(
2215
+ o.error || "Bridge could not build publish artifacts."
2216
+ );
2217
+ return o;
2218
+ }
2219
+ async function Gn() {
2220
+ if (!Pt) {
2221
+ M(
2222
+ "Publish is not configured in this host yet.",
2223
+ "blocked"
2224
+ );
2225
+ return;
2226
+ }
2227
+ if (Ye === "saving" && !Te.current) {
2228
+ M("Save draft is already in progress.", "blocked");
2229
+ return;
2230
+ }
2231
+ const t = await Er(), n = (t == null ? void 0 : t.dataAppId) || xe;
2232
+ if (!t || !n || !t.draftId) {
2233
+ M("Save the Data App before publishing.", "blocked");
2234
+ return;
2235
+ }
2236
+ const i = new AbortController();
2237
+ Nt("publishing"), Ne(null), J({
2238
+ state: "running",
2239
+ label: "Preparing publish",
2240
+ detail: "Checking draft state before the local build."
2241
+ });
2242
+ try {
2243
+ J({
2244
+ state: "running",
2245
+ label: "Starting publish",
2246
+ detail: "Creating a publish session from the saved draft."
2247
+ });
2248
+ const o = await Pt(
2249
+ {
2250
+ projectId: h,
2251
+ dataAppId: n,
2252
+ draftId: t.draftId,
2253
+ title: `${g} Data App`,
2254
+ description: null,
2255
+ sourceSnapshot: t.snapshot,
2256
+ sourceRevision: t.sourceRevision,
2257
+ bridgeWorkspaceHint: t.workspaceContext.projectRoot || b,
2258
+ buildArtifacts: async ({
2259
+ signal: u
2260
+ }) => {
2261
+ const m = await Un(u), k = m.assets;
2262
+ return {
2263
+ manifest: {
2264
+ ...m.manifest,
2265
+ semaphor: {
2266
+ ...m.manifest.semaphor || {},
2267
+ projectId: h,
2268
+ runtime: A,
2269
+ intentManifest: Xe || void 0
2270
+ }
2271
+ },
2272
+ validationStatus: m,
2273
+ bridgeWorkspaceHint: t.workspaceContext.projectRoot || b,
2274
+ assets: k,
2275
+ entryFile: m.entryFile,
2276
+ styleFiles: m.styleFiles || []
2277
+ };
2278
+ }
2279
+ },
2280
+ {
2281
+ apiServiceUrl: a,
2282
+ accessToken: s,
2283
+ signal: i.signal,
2284
+ onProgress: (u) => {
2285
+ J({
2286
+ state: "running",
2287
+ label: u.label,
2288
+ detail: u.detail
2289
+ });
2290
+ }
2291
+ }
2292
+ );
2293
+ qe(o.dataAppId), wr(o.publishedAt || (/* @__PURE__ */ new Date()).toISOString()), Nt("published"), J({
2294
+ state: "done",
2295
+ label: "Published",
2296
+ detail: `Version ${o.version ?? o.versionId} is ready.`
2297
+ }), M(
2298
+ `Published Data App version ${o.version ?? o.versionId}.`,
2299
+ "default"
2300
+ );
2301
+ } catch (o) {
2302
+ const u = o instanceof Error ? o.message : String(o);
2303
+ Ne(u), Nt("failed"), J({
2304
+ state: "failed",
2305
+ label: "Publish failed",
2306
+ detail: u
2307
+ }), M(`Publish failed: ${u}`, "blocked");
2308
+ }
2309
+ }
2310
+ async function Kn(t) {
2311
+ var m, k;
2312
+ const { attachments: n, prompt: i } = t, o = new AbortController();
2313
+ q.current = o, qt(!0);
2314
+ const u = window.setTimeout(() => {
2315
+ o.abort();
2316
+ }, 18e4);
2317
+ try {
2318
+ se("context"), ie("Reading the app manifest and starter context.");
2319
+ let w = A === "browser" ? await jn(i) : await Pr(o.signal);
2320
+ const C = [];
2321
+ let y = null;
2322
+ for (; se("thinking"), ie(
2323
+ w.currentFiles.length > 0 ? "Reviewing the app context and deciding the next step." : "Deciding whether this needs an answer, file inspection, or edits."
2324
+ ), y = await tt(
2325
+ {
2326
+ projectId: h,
2327
+ message: i,
2328
+ currentFiles: w.currentFiles,
2329
+ workspaceContext: w.workspaceContext,
2330
+ conversationContext: an(
2331
+ ht.current,
2332
+ Xe
2333
+ ),
2334
+ attachments: n,
2335
+ repair: !1,
2336
+ allowFileReads: !0,
2337
+ generationModel: V.model,
2338
+ generationReasoningEffort: V.reasoningEffort,
2339
+ repairModel: V.model,
2340
+ repairReasoningEffort: V.reasoningEffort
2341
+ },
2342
+ {
2343
+ accessToken: s,
2344
+ apiServiceUrl: a,
2345
+ signal: o.signal,
2346
+ onProgress: Rr
2347
+ }
2348
+ ), !(!y || y.mode !== "read_files"); ) {
2349
+ const $ = (y.requestedFiles || []).filter(
2350
+ (Ae) => typeof Ae == "string" && !w.currentFiles.some((Ce) => Ce.path === Ae)
2351
+ );
2352
+ if ($.length === 0) {
2353
+ se("thinking"), ie(
2354
+ "No additional source files are needed; preparing the response."
2355
+ ), y = await tt(
2356
+ {
2357
+ projectId: h,
2358
+ message: i,
2359
+ currentFiles: w.currentFiles,
2360
+ workspaceContext: w.workspaceContext,
2361
+ conversationContext: an(
2362
+ ht.current,
2363
+ Xe
2364
+ ),
2365
+ attachments: n,
2366
+ repair: !1,
2367
+ allowFileReads: !1,
2368
+ generationModel: V.model,
2369
+ generationReasoningEffort: V.reasoningEffort,
2370
+ repairModel: V.model,
2371
+ repairReasoningEffort: V.reasoningEffort
2372
+ },
2373
+ {
2374
+ accessToken: s,
2375
+ apiServiceUrl: a,
2376
+ signal: o.signal,
2377
+ onProgress: Rr
2378
+ }
2379
+ );
2380
+ break;
2381
+ }
2382
+ se("reading-files"), ie(
2383
+ `Reading ${$.length} requested file${$.length === 1 ? "" : "s"}: ${za($)}.`
2384
+ ), C.push({
2385
+ tool: "read_files",
2386
+ status: "done",
2387
+ detail: $.join(", ")
2388
+ });
2389
+ const ce = A === "browser" ? await zn($) : await Et($, o.signal);
2390
+ w = {
2391
+ ...w,
2392
+ currentFiles: Wn(
2393
+ w.currentFiles,
2394
+ ce
2395
+ )
2396
+ };
2397
+ }
2398
+ if (!y)
2399
+ throw new Error("Data App Builder did not return a turn.");
2400
+ if (C.length > 0 && (y = {
2401
+ ...y,
2402
+ toolEvents: [...C, ...y.toolEvents || []]
2403
+ }), Rn(y), y.mode === "read_files") {
2404
+ M(
2405
+ "I could not gather enough additional source context for that change. Please point me at the component or file you want to change, or try a narrower instruction.",
2406
+ "guidance"
2407
+ );
2408
+ return;
2409
+ }
2410
+ if (y.mode !== "edit") {
2411
+ M(
2412
+ y.message,
2413
+ y.mode === "clarify" ? "guidance" : "default",
2414
+ {
2415
+ artifacts: y.artifacts,
2416
+ operation: y.operation,
2417
+ intentManifest: y.intentManifest
2418
+ }
2419
+ );
2420
+ return;
2421
+ }
2422
+ if (!y.revision)
2423
+ throw new Error("Data App Builder chose an edit but returned no revision.");
2424
+ M(ja(y), "guidance", {
2425
+ operation: y.operation,
2426
+ intentManifest: y.intentManifest
2427
+ }), se("planning"), ie(
2428
+ (k = (m = y.revision.plan) == null ? void 0 : m.files) != null && k.length ? `Preparing edits for ${y.revision.plan.files.length} file${y.revision.plan.files.length === 1 ? "" : "s"}.` : "Preparing the file edit and validation run."
2429
+ );
2430
+ const N = fe("run"), L = Date.now();
2431
+ ge(($) => [
2432
+ ...$,
2433
+ {
2434
+ id: N,
2435
+ type: "run",
2436
+ prompt: i,
2437
+ status: "running",
2438
+ steps: Ta(),
2439
+ createdAt: L,
2440
+ startedAt: L
2441
+ }
2442
+ ]), q.current = null, A === "browser" ? In(i, N, y.revision) : Ln(i, N, y.revision);
2443
+ } catch (w) {
2444
+ const C = w instanceof DOMException && w.name === "AbortError";
2445
+ M(
2446
+ C ? "The app-builder turn timed out before a response was produced." : w instanceof Error ? w.message : String(w),
2447
+ "blocked"
2448
+ );
2449
+ } finally {
2450
+ qt(!1), se("idle"), ie(null), Zt(null), q.current === o && (q.current = null), window.clearTimeout(u);
2451
+ }
2452
+ }
2453
+ function Qn(t) {
2454
+ t.preventDefault();
2455
+ const n = _e.trim();
2456
+ if (!n) return;
2457
+ const i = Date.now(), o = ut, u = {
2458
+ id: fe("turn"),
2459
+ prompt: n,
2460
+ attachments: o,
2461
+ createdAt: i
2462
+ };
2463
+ if (ct(""), Ue([]), X || ee) {
2464
+ De((m) => [...m, u]);
2465
+ return;
2466
+ }
2467
+ Br(u);
2468
+ }
2469
+ return /* @__PURE__ */ c(
2470
+ ta,
2471
+ {
2472
+ autoSaveId: `semaphor-data-app-builder-${h}`,
2473
+ className: "h-full min-h-0 flex-1",
2474
+ direction: "horizontal",
2475
+ children: [
2476
+ Pe ? /* @__PURE__ */ c(re, { children: [
2477
+ /* @__PURE__ */ r(
2478
+ Lr,
2479
+ {
2480
+ className: "min-w-[320px] max-w-[760px]",
2481
+ defaultSize: 28,
2482
+ maxSize: 55,
2483
+ minSize: 18,
2484
+ order: 1,
2485
+ children: /* @__PURE__ */ c("aside", { className: "flex h-full min-h-0 flex-col border-r border-border", children: [
2486
+ /* @__PURE__ */ c("div", { className: "flex h-10 shrink-0 items-center gap-2 border-b border-border px-3", children: [
2487
+ /* @__PURE__ */ r("span", { className: "text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Chat" }),
2488
+ /* @__PURE__ */ r("div", { className: "ml-auto flex min-w-0 items-center gap-2", children: S ? /* @__PURE__ */ c(jr, { children: [
2489
+ /* @__PURE__ */ r(zr, { asChild: !0, children: /* @__PURE__ */ c(
2490
+ H,
2491
+ {
2492
+ type: "button",
2493
+ variant: "ghost",
2494
+ size: "xs",
2495
+ className: "gap-1.5 px-1.5 text-muted-foreground",
2496
+ title: "Discard this conversation",
2497
+ children: [
2498
+ /* @__PURE__ */ r(ra, { className: "h-3.5 w-3.5" }),
2499
+ "New session"
2500
+ ]
2501
+ }
2502
+ ) }),
2503
+ /* @__PURE__ */ c(Wr, { children: [
2504
+ /* @__PURE__ */ c(Hr, { children: [
2505
+ /* @__PURE__ */ r(Jr, { children: "Discard this conversation?" }),
2506
+ /* @__PURE__ */ r(Vr, { children: "This clears the chat and run history in the builder and starts a new session. Generated files in your project are not affected." })
2507
+ ] }),
2508
+ /* @__PURE__ */ c(_r, { children: [
2509
+ /* @__PURE__ */ r(Ur, { children: "Cancel" }),
2510
+ /* @__PURE__ */ r(Gr, { onClick: S, children: "Discard" })
2511
+ ] })
2512
+ ] })
2513
+ ] }) : null })
2514
+ ] }),
2515
+ /* @__PURE__ */ r(
2516
+ "div",
2517
+ {
2518
+ ref: mt,
2519
+ className: "min-h-0 flex-1 overflow-y-auto px-3 py-4",
2520
+ children: /* @__PURE__ */ c("div", { className: "space-y-4", children: [
2521
+ Z.length === 0 && /* @__PURE__ */ c("div", { children: [
2522
+ /* @__PURE__ */ r("p", { className: "text-[12.5px] font-medium text-foreground", children: "Start with a question or a build instruction" }),
2523
+ /* @__PURE__ */ r("p", { className: "mt-1 text-[11.5px] leading-relaxed text-muted-foreground", children: "Ask about the current files, or describe the app you want." }),
2524
+ /* @__PURE__ */ r("div", { className: "mt-3 grid gap-1.5", children: Na.slice(0, 3).map((t) => /* @__PURE__ */ c(
2525
+ "button",
2526
+ {
2527
+ type: "button",
2528
+ onClick: () => ct(t.prompt),
2529
+ className: "rounded-[5px] border border-border px-2.5 py-2 text-left transition-colors hover:border-foreground/40",
2530
+ children: [
2531
+ /* @__PURE__ */ r("div", { className: "truncate text-[11.5px] font-medium text-foreground", children: t.title }),
2532
+ /* @__PURE__ */ r("div", { className: "mt-0.5 line-clamp-2 text-[10.5px] leading-relaxed text-muted-foreground", children: t.description })
2533
+ ]
2534
+ },
2535
+ t.id
2536
+ )) })
2537
+ ] }),
2538
+ Z.map(
2539
+ (t) => t.type === "user" ? /* @__PURE__ */ r(ao, { message: t }, t.id) : t.type === "assistant" ? /* @__PURE__ */ r(
2540
+ so,
2541
+ {
2542
+ message: t,
2543
+ onOpenDatasetInspector: Ze
2544
+ },
2545
+ t.id
2546
+ ) : /* @__PURE__ */ r(
2547
+ uo,
2548
+ {
2549
+ getStepDuration: Sn,
2550
+ run: t
2551
+ },
2552
+ t.id
2553
+ )
2554
+ ),
2555
+ ee && !vn && /* @__PURE__ */ r(
2556
+ co,
2557
+ {
2558
+ phase: pn,
2559
+ detail: hn,
2560
+ elapsedMs: Yt ? Math.max(0, Xt - Yt) : 0
2561
+ }
2562
+ )
2563
+ ] })
2564
+ }
2565
+ ),
2566
+ /* @__PURE__ */ c(
2567
+ "form",
2568
+ {
2569
+ onSubmit: Qn,
2570
+ className: "border-t border-border p-3",
2571
+ children: [
2572
+ $e.length > 0 ? /* @__PURE__ */ r(
2573
+ no,
2574
+ {
2575
+ turns: $e,
2576
+ onDelete: En,
2577
+ onRemoveAttachment: On,
2578
+ onUpdatePrompt: Tn
2579
+ }
2580
+ ) : null,
2581
+ /* @__PURE__ */ c("div", { className: "rounded-[6px] border border-border focus-within:border-ring", children: [
2582
+ /* @__PURE__ */ r(
2583
+ "textarea",
2584
+ {
2585
+ value: _e,
2586
+ onChange: (t) => ct(t.target.value),
2587
+ onPaste: (t) => {
2588
+ const n = Array.from(t.clipboardData.files).filter(
2589
+ (i) => i.type.startsWith("image/")
2590
+ );
2591
+ n.length !== 0 && (t.preventDefault(), $r(n));
2592
+ },
2593
+ onKeyDown: (t) => {
2594
+ var n;
2595
+ t.key === "Enter" && !t.shiftKey && (t.preventDefault(), (n = t.currentTarget.form) == null || n.requestSubmit());
2596
+ },
2597
+ placeholder: "Ask a question, or write a build instruction like “Add a select filter for region”",
2598
+ className: "block min-h-[64px] w-full resize-none bg-transparent px-2.5 py-2 text-[13px] leading-relaxed text-foreground placeholder:text-muted-foreground focus:outline-none"
2599
+ }
2600
+ ),
2601
+ ut.length > 0 ? /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-1.5 border-t border-border px-2 py-2", children: ut.map((t) => /* @__PURE__ */ r(
2602
+ Kt,
2603
+ {
2604
+ attachment: t,
2605
+ onRemove: $n
2606
+ },
2607
+ t.id
2608
+ )) }) : null,
2609
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between gap-2 border-t border-border px-2 py-1.5", children: [
2610
+ /* @__PURE__ */ c("div", { className: "flex min-w-0 items-center gap-1", children: [
2611
+ /* @__PURE__ */ r(
2612
+ "input",
2613
+ {
2614
+ ref: tr,
2615
+ type: "file",
2616
+ accept: "image/*",
2617
+ className: "hidden",
2618
+ multiple: !0,
2619
+ onChange: (t) => {
2620
+ t.target.files && $r(t.target.files), t.target.value = "";
2621
+ }
2622
+ }
2623
+ ),
2624
+ /* @__PURE__ */ c(it, { children: [
2625
+ /* @__PURE__ */ r(lt, { asChild: !0, children: /* @__PURE__ */ r(
2626
+ H,
2627
+ {
2628
+ type: "button",
2629
+ variant: "ghost",
2630
+ size: "icon",
2631
+ className: "h-7 w-7 text-muted-foreground",
2632
+ title: "Add context",
2633
+ "aria-label": "Add context",
2634
+ children: /* @__PURE__ */ r(na, { className: "h-3.5 w-3.5" })
2635
+ }
2636
+ ) }),
2637
+ /* @__PURE__ */ r(
2638
+ dt,
2639
+ {
2640
+ align: "start",
2641
+ side: "top",
2642
+ className: "w-44 p-1",
2643
+ children: /* @__PURE__ */ c(
2644
+ "button",
2645
+ {
2646
+ type: "button",
2647
+ className: "flex w-full items-center gap-2 rounded-[5px] px-2 py-1.5 text-left text-[12px] text-foreground hover:bg-muted",
2648
+ onClick: () => {
2649
+ var t;
2650
+ return (t = tr.current) == null ? void 0 : t.click();
2651
+ },
2652
+ children: [
2653
+ /* @__PURE__ */ r(ya, { className: "h-3.5 w-3.5 text-muted-foreground" }),
2654
+ "Screenshot"
2655
+ ]
2656
+ }
2657
+ )
2658
+ }
2659
+ )
2660
+ ] }),
2661
+ /* @__PURE__ */ c(ua, { value: pt, onValueChange: mn, children: [
2662
+ /* @__PURE__ */ r(
2663
+ pa,
2664
+ {
2665
+ "aria-label": "Generation model",
2666
+ title: "Model used to generate changes",
2667
+ className: "h-7 w-auto gap-1.5 border-0 bg-transparent px-1.5 text-[11px] text-muted-foreground shadow-none hover:text-foreground focus:ring-0",
2668
+ children: /* @__PURE__ */ r(ha, { placeholder: "Model" })
2669
+ }
2670
+ ),
2671
+ /* @__PURE__ */ r(ma, { align: "start", children: Jt.map((t) => /* @__PURE__ */ r(
2672
+ fa,
2673
+ {
2674
+ value: t.id,
2675
+ className: "text-[12px]",
2676
+ children: t.label
2677
+ },
2678
+ t.id
2679
+ )) })
2680
+ ] })
2681
+ ] }),
2682
+ /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center gap-1.5", children: X || ee ? /* @__PURE__ */ c(re, { children: [
2683
+ /* @__PURE__ */ r(
2684
+ H,
2685
+ {
2686
+ type: "submit",
2687
+ size: "xs",
2688
+ variant: "outline",
2689
+ className: "gap-1.5",
2690
+ disabled: !_e.trim(),
2691
+ children: "Queue"
2692
+ }
2693
+ ),
2694
+ /* @__PURE__ */ c(
2695
+ H,
2696
+ {
2697
+ type: "button",
2698
+ variant: "outline",
2699
+ size: "xs",
2700
+ className: "gap-1.5",
2701
+ title: "Stop the current run",
2702
+ onClick: () => {
2703
+ var t;
2704
+ return (t = q.current) == null ? void 0 : t.abort();
2705
+ },
2706
+ children: [
2707
+ /* @__PURE__ */ r(He, { className: "h-3 w-3" }),
2708
+ "Stop"
2709
+ ]
2710
+ }
2711
+ )
2712
+ ] }) : /* @__PURE__ */ c(
2713
+ H,
2714
+ {
2715
+ type: "submit",
2716
+ size: "xs",
2717
+ className: "gap-1.5",
2718
+ disabled: !_e.trim(),
2719
+ children: [
2720
+ /* @__PURE__ */ r(aa, { className: "h-3 w-3" }),
2721
+ "Send"
2722
+ ]
2723
+ }
2724
+ ) })
2725
+ ] })
2726
+ ] })
2727
+ ]
2728
+ }
2729
+ )
2730
+ ] })
2731
+ }
2732
+ ),
2733
+ /* @__PURE__ */ r(
2734
+ oa,
2735
+ {
2736
+ className: "w-px bg-border/60 transition-colors hover:bg-border"
2737
+ }
2738
+ )
2739
+ ] }) : null,
2740
+ /* @__PURE__ */ r(
2741
+ Lr,
2742
+ {
2743
+ className: "min-w-0",
2744
+ defaultSize: Pe ? 72 : 100,
2745
+ minSize: 35,
2746
+ order: 2,
2747
+ children: /* @__PURE__ */ c("main", { className: "flex h-full min-w-0 flex-col bg-muted/40", children: [
2748
+ /* @__PURE__ */ c("div", { className: "flex h-10 shrink-0 items-center gap-3 border-b border-border px-3", children: [
2749
+ /* @__PURE__ */ r(
2750
+ H,
2751
+ {
2752
+ type: "button",
2753
+ variant: "ghost",
2754
+ size: "xs",
2755
+ className: "-ml-1 gap-1.5 px-1.5 text-muted-foreground",
2756
+ title: Pe ? "Hide chat" : "Show chat",
2757
+ "aria-label": Pe ? "Hide chat" : "Show chat",
2758
+ onClick: () => un((t) => !t),
2759
+ children: Pe ? /* @__PURE__ */ r(ka, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ r(sa, { className: "h-3.5 w-3.5" })
2760
+ }
2761
+ ),
2762
+ /* @__PURE__ */ c("div", { className: "flex min-w-0 items-baseline gap-2", children: [
2763
+ /* @__PURE__ */ r("span", { className: "shrink-0 text-[12px] font-medium text-foreground", children: "Live preview" }),
2764
+ /* @__PURE__ */ r("span", { className: "min-w-0 truncate font-mono text-[11px] text-muted-foreground", children: A === "browser" ? "browser sandbox" : F })
2765
+ ] }),
2766
+ A === "browser" && wt && /* @__PURE__ */ c(
2767
+ "span",
2768
+ {
2769
+ className: `text-[10.5px] ${wt === "tailwind" ? "text-emerald-700 dark:text-emerald-400" : "text-amber-700 dark:text-amber-400"}`,
2770
+ children: [
2771
+ "CSS: ",
2772
+ wt
2773
+ ]
2774
+ }
2775
+ ),
2776
+ rr ? /* @__PURE__ */ r("span", { className: "min-w-0 truncate text-[11px] text-blue-700 dark:text-blue-400", children: rr }) : null,
2777
+ St ? /* @__PURE__ */ r(
2778
+ "span",
2779
+ {
2780
+ className: "min-w-0 truncate text-[11px] text-destructive",
2781
+ title: St,
2782
+ children: St
2783
+ }
2784
+ ) : xr ? /* @__PURE__ */ c("span", { className: "min-w-0 truncate text-[11px] text-emerald-700 dark:text-emerald-400", children: [
2785
+ "Published ",
2786
+ new Date(xr).toLocaleTimeString()
2787
+ ] }) : gr ? /* @__PURE__ */ c("span", { className: "min-w-0 truncate text-[11px] text-muted-foreground", children: [
2788
+ "Saved ",
2789
+ new Date(gr).toLocaleTimeString()
2790
+ ] }) : null,
2791
+ /* @__PURE__ */ c("div", { className: "ml-auto flex items-center gap-1", children: [
2792
+ /* @__PURE__ */ c(
2793
+ it,
2794
+ {
2795
+ open: Ct,
2796
+ onOpenChange: (t) => {
2797
+ et(t), t && Tr();
2798
+ },
2799
+ children: [
2800
+ /* @__PURE__ */ r(lt, { asChild: !0, children: /* @__PURE__ */ c(
2801
+ H,
2802
+ {
2803
+ type: "button",
2804
+ variant: "ghost",
2805
+ size: "xs",
2806
+ className: "gap-1.5 text-muted-foreground",
2807
+ title: "Inspect the current Data App manifest",
2808
+ children: [
2809
+ Nr ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(Ht, { className: "h-3.5 w-3.5" }),
2810
+ "Manifest"
2811
+ ]
2812
+ }
2813
+ ) }),
2814
+ /* @__PURE__ */ c(
2815
+ dt,
2816
+ {
2817
+ align: "end",
2818
+ sideOffset: 6,
2819
+ className: "w-[520px] p-0",
2820
+ onInteractOutside: () => et(!1),
2821
+ onEscapeKeyDown: () => et(!1),
2822
+ children: [
2823
+ /* @__PURE__ */ c("div", { className: "flex h-10 items-center gap-2 border-b border-border px-3", children: [
2824
+ /* @__PURE__ */ r(Ht, { className: "h-3.5 w-3.5 text-muted-foreground" }),
2825
+ /* @__PURE__ */ c("div", { className: "min-w-0 flex-1", children: [
2826
+ /* @__PURE__ */ r("div", { className: "text-[12px] font-medium text-foreground", children: "App manifest" }),
2827
+ /* @__PURE__ */ r("div", { className: "truncate text-[10.5px] text-muted-foreground", children: "Current draft shape generated from the active runtime context" })
2828
+ ] }),
2829
+ /* @__PURE__ */ r(
2830
+ H,
2831
+ {
2832
+ type: "button",
2833
+ variant: "ghost",
2834
+ size: "icon",
2835
+ className: "h-7 w-7 text-muted-foreground",
2836
+ disabled: !Rt,
2837
+ title: "Copy manifest JSON",
2838
+ "aria-label": "Copy manifest JSON",
2839
+ onClick: () => {
2840
+ var t;
2841
+ (t = navigator.clipboard) == null || t.writeText(Rt);
2842
+ },
2843
+ children: /* @__PURE__ */ r(on, { className: "h-3.5 w-3.5" })
2844
+ }
2845
+ ),
2846
+ /* @__PURE__ */ r(
2847
+ H,
2848
+ {
2849
+ type: "button",
2850
+ variant: "ghost",
2851
+ size: "icon",
2852
+ className: "h-7 w-7 text-muted-foreground",
2853
+ title: "Refresh manifest",
2854
+ "aria-label": "Refresh manifest",
2855
+ onClick: () => void Tr(),
2856
+ children: /* @__PURE__ */ r(Kr, { className: "h-3.5 w-3.5" })
2857
+ }
2858
+ )
2859
+ ] }),
2860
+ /* @__PURE__ */ r("div", { className: "max-h-[520px] overflow-auto bg-muted/30 p-3", children: Nr ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-3 py-2 text-[12px] text-muted-foreground", children: [
2861
+ /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }),
2862
+ "Reading current runtime manifest..."
2863
+ ] }) : kr ? /* @__PURE__ */ r("div", { className: "rounded-[5px] border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive", children: kr }) : /* @__PURE__ */ r("pre", { className: "whitespace-pre-wrap break-words rounded-[5px] border border-border bg-background p-3 font-mono text-[11px] leading-relaxed text-muted-foreground", children: Rt || "Open or refresh to inspect the manifest." }) })
2864
+ ]
2865
+ }
2866
+ )
2867
+ ]
2868
+ }
2869
+ ),
2870
+ /* @__PURE__ */ c(jr, { children: [
2871
+ /* @__PURE__ */ r(zr, { asChild: !0, children: /* @__PURE__ */ c(
2872
+ H,
2873
+ {
2874
+ type: "button",
2875
+ variant: "ghost",
2876
+ size: "xs",
2877
+ className: "gap-1.5 text-muted-foreground",
2878
+ disabled: X || ee,
2879
+ title: "Reset the app to a blank development template",
2880
+ children: [
2881
+ /* @__PURE__ */ r(ga, { className: "h-3.5 w-3.5" }),
2882
+ "Reset app"
2883
+ ]
2884
+ }
2885
+ ) }),
2886
+ /* @__PURE__ */ c(Wr, { children: [
2887
+ /* @__PURE__ */ c(Hr, { children: [
2888
+ /* @__PURE__ */ r(Jr, { children: "Reset this app?" }),
2889
+ /* @__PURE__ */ r(Vr, { children: "This restores the active Data App workspace to the blank starter template and clears the builder's current app memory. Saved or published versions in Semaphor are not changed." })
2890
+ ] }),
2891
+ /* @__PURE__ */ c(_r, { children: [
2892
+ /* @__PURE__ */ r(Ur, { children: "Cancel" }),
2893
+ /* @__PURE__ */ r(Gr, { onClick: () => void Nn(), children: "Reset app" })
2894
+ ] })
2895
+ ] })
2896
+ ] }),
2897
+ /* @__PURE__ */ c(
2898
+ H,
2899
+ {
2900
+ type: "button",
2901
+ variant: "ghost",
2902
+ size: "xs",
2903
+ className: "gap-1.5 text-muted-foreground",
2904
+ disabled: X || ee || Ye === "saving" || A !== "bridge" || !Dt,
2905
+ title: "Save the current local source snapshot as a Semaphor draft",
2906
+ onClick: () => void Er(),
2907
+ children: [
2908
+ Ye === "saving" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(ba, { className: "h-3.5 w-3.5" }),
2909
+ "Save draft"
2910
+ ]
2911
+ }
2912
+ ),
2913
+ /* @__PURE__ */ c(
2914
+ H,
2915
+ {
2916
+ type: "button",
2917
+ variant: "ghost",
2918
+ size: "xs",
2919
+ className: "gap-1.5 text-muted-foreground",
2920
+ disabled: X || ee || Ye === "saving" || fr === "publishing" || A !== "bridge" || !Pt,
2921
+ title: "Build, upload, and publish the current Data App",
2922
+ onClick: () => void Gn(),
2923
+ children: [
2924
+ fr === "publishing" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(xa, { className: "h-3.5 w-3.5" }),
2925
+ "Publish"
2926
+ ]
2927
+ }
2928
+ ),
2929
+ A === "bridge" ? /* @__PURE__ */ c(
2930
+ H,
2931
+ {
2932
+ type: "button",
2933
+ variant: be ? "default" : "ghost",
2934
+ size: "xs",
2935
+ disabled: ar,
2936
+ className: be ? "gap-1.5" : "gap-1.5 text-muted-foreground",
2937
+ title: "Select an element in the preview and attach its DOM/React context",
2938
+ onClick: () => be ? Fn() : void Pn(),
2939
+ children: [
2940
+ ar ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(va, { className: "h-3.5 w-3.5" }),
2941
+ be ? "Cancel inspect" : "Inspect"
2942
+ ]
2943
+ }
2944
+ ) : null,
2945
+ /* @__PURE__ */ c(it, { children: [
2946
+ /* @__PURE__ */ r(lt, { asChild: !0, children: /* @__PURE__ */ c(
2947
+ H,
2948
+ {
2949
+ type: "button",
2950
+ variant: "ghost",
2951
+ size: "xs",
2952
+ className: "gap-1.5 text-muted-foreground",
2953
+ children: [
2954
+ /* @__PURE__ */ r(ia, { className: "h-3.5 w-3.5" }),
2955
+ "Runtime",
2956
+ A === "browser" && xt.length > 0 ? /* @__PURE__ */ r("span", { className: "text-[10px] text-amber-600", children: "CSS fallback" }) : null
2957
+ ]
2958
+ }
2959
+ ) }),
2960
+ /* @__PURE__ */ r(
2961
+ dt,
2962
+ {
2963
+ align: "end",
2964
+ sideOffset: 6,
2965
+ className: "w-[380px] p-3",
2966
+ children: A === "bridge" ? /* @__PURE__ */ c("div", { className: "space-y-2.5", children: [
2967
+ /* @__PURE__ */ r(
2968
+ Wt,
2969
+ {
2970
+ label: "App Directory",
2971
+ value: b,
2972
+ placeholder: Lt,
2973
+ onChange: E
2974
+ }
2975
+ ),
2976
+ /* @__PURE__ */ r(
2977
+ Wt,
2978
+ {
2979
+ label: "App Local URL",
2980
+ value: f,
2981
+ onChange: R
2982
+ }
2983
+ ),
2984
+ /* @__PURE__ */ r(
2985
+ Wt,
2986
+ {
2987
+ label: "Bridge URL",
2988
+ value: v,
2989
+ onChange: B
2990
+ }
2991
+ )
2992
+ ] }) : /* @__PURE__ */ c("div", { className: "text-[11px] leading-relaxed text-muted-foreground", children: [
2993
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between gap-3", children: [
2994
+ /* @__PURE__ */ r("span", { className: "min-w-0", children: "Browser files are stored locally in this browser." }),
2995
+ /* @__PURE__ */ r(
2996
+ H,
2997
+ {
2998
+ type: "button",
2999
+ variant: "outline",
3000
+ size: "xs",
3001
+ className: "h-6 shrink-0 text-[10.5px]",
3002
+ disabled: X || ee || Me !== "ready",
3003
+ onClick: () => void Cr(),
3004
+ children: "Reset"
3005
+ }
3006
+ )
3007
+ ] }),
3008
+ xt[0] ? /* @__PURE__ */ r("div", { className: "mt-2 rounded-[5px] border border-border bg-muted/40 px-2 py-1.5 text-muted-foreground", children: xt[0] }) : null,
3009
+ /* @__PURE__ */ r(Qa, { manifest: xn })
3010
+ ] })
3011
+ }
3012
+ )
3013
+ ] }),
3014
+ /* @__PURE__ */ r(
3015
+ H,
3016
+ {
3017
+ variant: "ghost",
3018
+ size: "xs",
3019
+ className: "h-7 w-7 p-0 text-muted-foreground",
3020
+ title: "Reload the live preview",
3021
+ "aria-label": "Reload the live preview",
3022
+ onClick: () => {
3023
+ A === "browser" ? (rt(), Ee()) : (z(f), Y((t) => t + 1));
3024
+ },
3025
+ children: /* @__PURE__ */ r(Kr, { className: "h-3.5 w-3.5" })
3026
+ }
3027
+ )
3028
+ ] })
3029
+ ] }),
3030
+ de ? /* @__PURE__ */ r("div", { className: "shrink-0 border-b border-border bg-background px-3 py-2", children: /* @__PURE__ */ c(
3031
+ "div",
3032
+ {
3033
+ className: `flex items-start gap-2 rounded-[6px] border px-2.5 py-2 text-[11.5px] leading-relaxed ${de.state === "failed" ? "border-destructive/30 bg-destructive/10 text-destructive" : de.state === "done" ? "border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900/60 dark:bg-emerald-950/30 dark:text-emerald-300" : "border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/30 dark:text-blue-300"}`,
3034
+ children: [
3035
+ de.state === "running" ? /* @__PURE__ */ r(me, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin" }) : de.state === "done" ? /* @__PURE__ */ r(Ut, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ r(He, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
3036
+ /* @__PURE__ */ c("div", { className: "min-w-0", children: [
3037
+ /* @__PURE__ */ r("div", { className: "font-medium", children: de.label }),
3038
+ de.detail ? /* @__PURE__ */ r("div", { className: "mt-0.5 truncate opacity-80", children: de.detail }) : null
3039
+ ] })
3040
+ ]
3041
+ }
3042
+ ) }) : null,
3043
+ (A === "browser" && (Me === "loading" || Me === "failed") || Fe && !((Or = Fe.appBuilder) != null && Or.hasOpenAiKey)) && /* @__PURE__ */ c("div", { className: "shrink-0 border-b border-border px-3 py-2", children: [
3044
+ A === "browser" && Me === "loading" && /* @__PURE__ */ r("p", { className: "text-[11px] leading-relaxed text-muted-foreground", children: "Loading the in-browser runtime…" }),
3045
+ A === "browser" && Me === "failed" && /* @__PURE__ */ c("div", { className: "rounded-[5px] border border-border bg-muted/40 px-2 py-1.5 text-[11px] leading-relaxed text-muted-foreground", children: [
3046
+ "Browser runtime is unavailable. Link or install semaphor-browser-runtime, or use the local bridge path.",
3047
+ sr ? /* @__PURE__ */ r("pre", { className: "mt-1.5 whitespace-pre-wrap font-mono text-[10.5px] text-muted-foreground", children: sr }) : null
3048
+ ] }),
3049
+ Fe && !((Ir = Fe.appBuilder) != null && Ir.hasOpenAiKey) && /* @__PURE__ */ r("div", { className: "rounded-[5px] border border-destructive/30 bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive", children: Fe.error || "OPENAI_API_KEY is not configured." })
3050
+ ] }),
3051
+ A === "browser" && gn.length > 0 && /* @__PURE__ */ r("div", { className: "shrink-0 border-b border-border px-3 py-1.5 text-[11px] text-amber-700 dark:text-amber-400", children: "Preview compiled with diagnostics. The next prompt can use them for repair." }),
3052
+ /* @__PURE__ */ c("div", { className: "flex min-h-0 flex-1", children: [
3053
+ A === "browser" && /* @__PURE__ */ c("aside", { className: "flex w-[300px] shrink-0 flex-col border-r border-border", children: [
3054
+ /* @__PURE__ */ c("div", { className: "flex h-10 shrink-0 items-center gap-2 border-b border-border px-3", children: [
3055
+ /* @__PURE__ */ r(Vt, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3056
+ /* @__PURE__ */ r("span", { className: "text-[11.5px] font-medium text-foreground", children: "Files" }),
3057
+ /* @__PURE__ */ r("span", { className: "ml-auto font-mono text-[10px] text-muted-foreground", children: pr.length })
3058
+ ] }),
3059
+ /* @__PURE__ */ r("div", { className: "max-h-72 shrink-0 overflow-y-auto border-b border-border p-2", children: /* @__PURE__ */ r(
3060
+ Ka,
3061
+ {
3062
+ files: pr,
3063
+ selectedPath: yt,
3064
+ onSelect: kn
3065
+ }
3066
+ ) }),
3067
+ /* @__PURE__ */ r("pre", { className: "min-h-0 flex-1 overflow-auto p-3 font-mono text-[11px] leading-relaxed text-muted-foreground", children: (vt == null ? void 0 : vt.contents) || "Select a file to inspect its source." })
3068
+ ] }),
3069
+ /* @__PURE__ */ r(
3070
+ "iframe",
3071
+ {
3072
+ ref: ft,
3073
+ className: "min-h-0 flex-1 bg-background",
3074
+ onLoad: () => {
3075
+ be && window.setTimeout(() => at("inspect-enable"), 100);
3076
+ },
3077
+ src: A === "browser" ? void 0 : Mt,
3078
+ srcDoc: A === "browser" ? fn : void 0,
3079
+ title: "Data app preview"
3080
+ },
3081
+ A === "browser" ? `browser-${ve}` : Mt
3082
+ ),
3083
+ yr ? /* @__PURE__ */ r(
3084
+ lo,
3085
+ {
3086
+ artifact: yr,
3087
+ onClose: () => Ze(null)
3088
+ }
3089
+ ) : null
3090
+ ] })
3091
+ ] })
3092
+ }
3093
+ )
3094
+ ]
3095
+ }
3096
+ );
3097
+ }
3098
+ function Wt({
3099
+ label: e,
3100
+ value: a,
3101
+ placeholder: s,
3102
+ onChange: d
3103
+ }) {
3104
+ return /* @__PURE__ */ c("label", { className: "grid min-w-0 gap-1", children: [
3105
+ /* @__PURE__ */ r("span", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: e }),
3106
+ /* @__PURE__ */ r(
3107
+ "input",
3108
+ {
3109
+ value: a,
3110
+ placeholder: s,
3111
+ spellCheck: !1,
3112
+ autoComplete: "off",
3113
+ onChange: (l) => d(l.target.value),
3114
+ onFocus: (l) => l.target.select(),
3115
+ className: "h-8 w-full min-w-0 rounded-[5px] border border-border bg-background px-2 font-mono text-[12px] text-foreground outline-none focus:border-ring"
3116
+ }
3117
+ )
3118
+ ] });
3119
+ }
3120
+ function Za({ code: e, lang: a }) {
3121
+ const [s, d] = x(!1);
3122
+ return /* @__PURE__ */ c("div", { className: "my-2 overflow-hidden rounded-[6px] border border-border", children: [
3123
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between gap-2 border-b border-border bg-muted/40 px-2.5 py-1", children: [
3124
+ /* @__PURE__ */ r("span", { className: "font-mono text-[10px] uppercase tracking-[0.08em] text-muted-foreground", children: a || "code" }),
3125
+ /* @__PURE__ */ r(
3126
+ "button",
3127
+ {
3128
+ type: "button",
3129
+ onClick: () => {
3130
+ var l;
3131
+ (l = navigator.clipboard) == null || l.writeText(e), d(!0), window.setTimeout(() => d(!1), 1500);
3132
+ },
3133
+ className: "inline-flex items-center gap-1 rounded-[4px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
3134
+ children: s ? /* @__PURE__ */ c(re, { children: [
3135
+ /* @__PURE__ */ r(Ut, { className: "h-3 w-3" }),
3136
+ "Copied"
3137
+ ] }) : /* @__PURE__ */ c(re, { children: [
3138
+ /* @__PURE__ */ r(on, { className: "h-3 w-3" }),
3139
+ "Copy"
3140
+ ] })
3141
+ }
3142
+ )
3143
+ ] }),
3144
+ /* @__PURE__ */ r("div", { className: "overflow-x-auto bg-background", children: /* @__PURE__ */ r(da, { code: e, language: a || "tsx" }) })
3145
+ ] });
3146
+ }
3147
+ const Xa = /(\b[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*\.(?:tsx?|jsx?|mjs|cjs|css|scss|json|mdx?|html?|ya?ml|toml|sql|sh|py|rb|go|rs)\b)/g;
3148
+ function eo(e, a) {
3149
+ return e.split(Xa).map(
3150
+ (s, d) => d % 2 === 1 ? /* @__PURE__ */ c(
3151
+ "span",
3152
+ {
3153
+ className: "mx-px inline-flex items-baseline gap-1 rounded-[4px] border border-border bg-muted/60 px-1 font-mono text-[0.82em] text-foreground",
3154
+ children: [
3155
+ /* @__PURE__ */ r(Ht, { className: "h-3 w-3 shrink-0 translate-y-[1px] text-muted-foreground" }),
3156
+ s
3157
+ ]
3158
+ },
3159
+ `${a}-f${d}`
3160
+ ) : /* @__PURE__ */ r("span", { children: s }, `${a}-t${d}`)
3161
+ );
3162
+ }
3163
+ function to(e, a) {
3164
+ return e.split(`
3165
+ `).map((s, d) => /* @__PURE__ */ c("span", { children: [
3166
+ d > 0 ? /* @__PURE__ */ r("br", {}) : null,
3167
+ s.split(/(`[^`]+`|\*\*[^*]+\*\*)/g).map((l, p) => l.length > 1 && l.startsWith("`") && l.endsWith("`") ? /* @__PURE__ */ r(
3168
+ "code",
3169
+ {
3170
+ className: "mx-px rounded-[4px] bg-foreground/10 px-1 font-mono text-[0.85em] text-foreground",
3171
+ children: l.slice(1, -1)
3172
+ },
3173
+ p
3174
+ ) : l.length > 4 && l.startsWith("**") && l.endsWith("**") ? /* @__PURE__ */ r(
3175
+ "strong",
3176
+ {
3177
+ className: "font-semibold text-foreground",
3178
+ children: l.slice(2, -2)
3179
+ },
3180
+ p
3181
+ ) : /* @__PURE__ */ r("span", { children: eo(l, `${a}-${d}-${p}`) }, p))
3182
+ ] }, `${a}-${d}`));
3183
+ }
3184
+ function ro(e) {
3185
+ return e.split("```").map((a, s) => {
3186
+ if (s % 2 === 1) {
3187
+ let d = "", l = a;
3188
+ const p = a.indexOf(`
3189
+ `);
3190
+ if (p !== -1) {
3191
+ const h = a.slice(0, p).trim();
3192
+ h && /^[A-Za-z0-9_.+-]{1,16}$/.test(h) && (d = h, l = a.slice(p + 1));
3193
+ }
3194
+ return l = l.replace(/^\n/, "").replace(/\s+$/, ""), /* @__PURE__ */ r(Za, { code: l, lang: d }, s);
3195
+ }
3196
+ return /* @__PURE__ */ r("span", { children: to(a, s) }, s);
3197
+ });
3198
+ }
3199
+ function no({
3200
+ turns: e,
3201
+ onDelete: a,
3202
+ onRemoveAttachment: s,
3203
+ onUpdatePrompt: d
3204
+ }) {
3205
+ var g;
3206
+ const [l, p] = x(!1), h = e.length;
3207
+ return /* @__PURE__ */ c("div", { className: "mb-2 overflow-hidden rounded-[6px] border border-border bg-muted/40", children: [
3208
+ /* @__PURE__ */ c(
3209
+ "button",
3210
+ {
3211
+ type: "button",
3212
+ onClick: () => p((S) => !S),
3213
+ "aria-expanded": l,
3214
+ className: "flex w-full items-center gap-2 px-2.5 py-1.5 text-left",
3215
+ children: [
3216
+ /* @__PURE__ */ r(
3217
+ _t,
3218
+ {
3219
+ className: `h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform ${l ? "rotate-90" : ""}`
3220
+ }
3221
+ ),
3222
+ /* @__PURE__ */ c("span", { className: "shrink-0 text-[12px] font-medium text-foreground", children: [
3223
+ h,
3224
+ " queued"
3225
+ ] }),
3226
+ l ? null : /* @__PURE__ */ c("span", { className: "min-w-0 truncate text-[11px] text-muted-foreground", children: [
3227
+ "· ",
3228
+ ((g = e[0]) == null ? void 0 : g.prompt.trim()) || "Queued instruction"
3229
+ ] }),
3230
+ /* @__PURE__ */ r("span", { className: "ml-auto shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: l ? "Hide" : "Show" })
3231
+ ]
3232
+ }
3233
+ ),
3234
+ l ? /* @__PURE__ */ r("div", { className: "max-h-[200px] space-y-1.5 overflow-y-auto border-t border-border p-2", children: e.map((S, f) => /* @__PURE__ */ c(
3235
+ "div",
3236
+ {
3237
+ className: "rounded-[5px] border border-border bg-background p-2",
3238
+ children: [
3239
+ /* @__PURE__ */ c("div", { className: "mb-1.5 flex items-center justify-between gap-2", children: [
3240
+ /* @__PURE__ */ c("span", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: [
3241
+ "Next ",
3242
+ f + 1
3243
+ ] }),
3244
+ /* @__PURE__ */ r(
3245
+ "button",
3246
+ {
3247
+ type: "button",
3248
+ className: "rounded-[4px] px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground",
3249
+ onClick: () => a(S.id),
3250
+ children: "Remove"
3251
+ }
3252
+ )
3253
+ ] }),
3254
+ /* @__PURE__ */ r(
3255
+ "textarea",
3256
+ {
3257
+ value: S.prompt,
3258
+ onChange: (R) => d(S.id, R.target.value),
3259
+ className: "block min-h-[44px] w-full resize-none rounded-[4px] border border-border bg-transparent px-2 py-1.5 text-[12px] leading-relaxed text-foreground focus:border-ring focus:outline-none",
3260
+ placeholder: "Queued instruction"
3261
+ }
3262
+ ),
3263
+ S.attachments.length > 0 ? /* @__PURE__ */ r("div", { className: "mt-1.5 flex flex-wrap gap-1.5", children: S.attachments.map((R) => /* @__PURE__ */ r(
3264
+ Kt,
3265
+ {
3266
+ attachment: R,
3267
+ onRemove: (v) => s(S.id, v)
3268
+ },
3269
+ R.id
3270
+ )) }) : null
3271
+ ]
3272
+ },
3273
+ S.id
3274
+ )) }) : null
3275
+ ] });
3276
+ }
3277
+ function ao({ message: e }) {
3278
+ var a;
3279
+ return /* @__PURE__ */ c("div", { className: "ml-auto max-w-[88%] rounded-[6px] rounded-br-[2px] bg-foreground/10 px-3 py-2 text-[13px] leading-relaxed text-foreground", children: [
3280
+ /* @__PURE__ */ r("div", { children: e.content }),
3281
+ (a = e.attachments) != null && a.length ? /* @__PURE__ */ r("div", { className: "mt-2 flex flex-wrap gap-1.5", children: e.attachments.map((s) => /* @__PURE__ */ r(Kt, { attachment: s }, s.id)) }) : null
3282
+ ] });
3283
+ }
3284
+ function Kt({
3285
+ attachment: e,
3286
+ onRemove: a
3287
+ }) {
3288
+ const s = /* @__PURE__ */ c(re, { children: [
3289
+ e.type === "screenshot" ? /* @__PURE__ */ c(re, { children: [
3290
+ /* @__PURE__ */ r(
3291
+ "img",
3292
+ {
3293
+ alt: "",
3294
+ className: "h-5 w-7 rounded-[3px] border border-border object-cover",
3295
+ src: e.imageUrl
3296
+ }
3297
+ ),
3298
+ /* @__PURE__ */ r("span", { className: "max-w-[140px] truncate", children: e.name })
3299
+ ] }) : /* @__PURE__ */ c(re, { children: [
3300
+ /* @__PURE__ */ r(Vt, { className: "h-3 w-3" }),
3301
+ /* @__PURE__ */ r("span", { className: "max-w-[140px] truncate", children: e.name })
3302
+ ] }),
3303
+ a ? /* @__PURE__ */ r(
3304
+ "button",
3305
+ {
3306
+ type: "button",
3307
+ className: "rounded-[3px] p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",
3308
+ onClick: () => a(e.id),
3309
+ "aria-label": `Remove ${e.name}`,
3310
+ children: /* @__PURE__ */ r(He, { className: "h-3 w-3" })
3311
+ }
3312
+ ) : null
3313
+ ] });
3314
+ return e.type === "dom-selection" ? /* @__PURE__ */ c(it, { children: [
3315
+ /* @__PURE__ */ r(lt, { asChild: !0, children: /* @__PURE__ */ r(
3316
+ "button",
3317
+ {
3318
+ type: "button",
3319
+ className: "inline-flex max-w-full items-center gap-1.5 rounded-[5px] border border-border bg-background px-1.5 py-1 text-[11px] text-muted-foreground hover:border-ring hover:text-foreground",
3320
+ title: "View captured DOM context",
3321
+ children: s
3322
+ }
3323
+ ) }),
3324
+ /* @__PURE__ */ c(dt, { align: "start", sideOffset: 6, className: "w-[420px] p-0", children: [
3325
+ /* @__PURE__ */ c("div", { className: "border-b border-border px-3 py-2", children: [
3326
+ /* @__PURE__ */ r("div", { className: "text-[12px] font-medium text-foreground", children: "Captured DOM context" }),
3327
+ /* @__PURE__ */ r("div", { className: "mt-0.5 truncate text-[11px] text-muted-foreground", children: e.name })
3328
+ ] }),
3329
+ /* @__PURE__ */ r("pre", { className: "max-h-[360px] overflow-auto whitespace-pre-wrap p-3 font-mono text-[11px] leading-relaxed text-muted-foreground", children: e.text })
3330
+ ] })
3331
+ ] }) : /* @__PURE__ */ r("span", { className: "inline-flex max-w-full items-center gap-1.5 rounded-[5px] border border-border bg-background px-1.5 py-1 text-[11px] text-muted-foreground", children: s });
3332
+ }
3333
+ function oo(e) {
3334
+ var a;
3335
+ if (e.type === "assistant") {
3336
+ const { artifacts: s, ...d } = e;
3337
+ return d;
3338
+ }
3339
+ return e.type === "user" && ((a = e.attachments) != null && a.length) ? {
3340
+ ...e,
3341
+ attachments: e.attachments.filter(
3342
+ (s) => s.type !== "screenshot"
3343
+ )
3344
+ } : e;
3345
+ }
3346
+ function so({
3347
+ message: e,
3348
+ onOpenDatasetInspector: a
3349
+ }) {
3350
+ var d;
3351
+ const s = e.tone === "blocked" ? "border-destructive/30 bg-destructive/10 text-destructive" : e.tone === "guidance" ? "border-blue-100 bg-blue-50/60 text-blue-950" : "border-border bg-background text-foreground";
3352
+ return /* @__PURE__ */ c(
3353
+ "div",
3354
+ {
3355
+ className: `max-w-[92%] rounded-[6px] rounded-bl-[2px] border px-3 py-2 text-[13px] leading-relaxed ${s}`,
3356
+ children: [
3357
+ /* @__PURE__ */ r("div", { className: "mb-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Assistant" }),
3358
+ ro(e.content),
3359
+ (d = e.artifacts) == null ? void 0 : d.map(
3360
+ (l) => l.type === "dataset_inspector" ? /* @__PURE__ */ r(
3361
+ io,
3362
+ {
3363
+ artifact: l,
3364
+ onOpen: () => a(l)
3365
+ },
3366
+ l.id
3367
+ ) : null
3368
+ )
3369
+ ]
3370
+ }
3371
+ );
3372
+ }
3373
+ function io({
3374
+ artifact: e,
3375
+ onOpen: a
3376
+ }) {
3377
+ return /* @__PURE__ */ c(
3378
+ "button",
3379
+ {
3380
+ type: "button",
3381
+ onClick: a,
3382
+ className: "mt-2 flex w-full items-center gap-2 rounded-[5px] border border-border bg-background px-2.5 py-2 text-left transition-colors hover:border-foreground/40",
3383
+ children: [
3384
+ /* @__PURE__ */ r(sn, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
3385
+ /* @__PURE__ */ c("span", { className: "min-w-0 flex-1", children: [
3386
+ /* @__PURE__ */ r("span", { className: "block truncate text-[12px] font-medium text-foreground", children: e.title }),
3387
+ /* @__PURE__ */ c("span", { className: "block truncate text-[10.5px] text-muted-foreground", children: [
3388
+ e.counts.total,
3389
+ " fields · ",
3390
+ e.counts.measures,
3391
+ " measures ·",
3392
+ " ",
3393
+ e.counts.dimensions,
3394
+ " dimensions"
3395
+ ] })
3396
+ ] }),
3397
+ /* @__PURE__ */ r("span", { className: "shrink-0 text-[10.5px] font-medium text-muted-foreground", children: "Open" })
3398
+ ]
3399
+ }
3400
+ );
3401
+ }
3402
+ function lo({
3403
+ artifact: e,
3404
+ onClose: a
3405
+ }) {
3406
+ const [s, d] = x(""), [l, p] = x("all"), h = s.trim().toLowerCase(), g = e.fields.filter((f) => {
3407
+ var E, j;
3408
+ const R = (E = f.role) == null ? void 0 : E.toLowerCase(), v = (j = f.dataType) == null ? void 0 : j.toLowerCase(), B = l === "all" || l === "measures" && (R === "measure" || R === "metric") || l === "dimensions" && R === "dimension" || l === "dates" && (R === "date" || v === "date" || v === "timestamp") || l === "identifiers" && R === "identifier" || l === "calculated" && f.source === "calculated", b = !h || [f.name, f.label, f.role, f.dataType].filter((I) => typeof I == "string").some((I) => I.toLowerCase().includes(h));
3409
+ return B && b;
3410
+ }), S = [
3411
+ { id: "all", label: "All", count: e.counts.total },
3412
+ { id: "measures", label: "Measures", count: e.counts.measures },
3413
+ {
3414
+ id: "dimensions",
3415
+ label: "Dimensions",
3416
+ count: e.counts.dimensions
3417
+ },
3418
+ { id: "dates", label: "Dates", count: e.counts.dates },
3419
+ {
3420
+ id: "identifiers",
3421
+ label: "IDs",
3422
+ count: e.counts.identifiers
3423
+ },
3424
+ {
3425
+ id: "calculated",
3426
+ label: "Calc",
3427
+ count: e.counts.calculated
3428
+ }
3429
+ ];
3430
+ return /* @__PURE__ */ c("aside", { className: "flex w-[360px] shrink-0 flex-col border-l border-border bg-background", children: [
3431
+ /* @__PURE__ */ c("div", { className: "flex h-10 shrink-0 items-center gap-2 border-b border-border px-3", children: [
3432
+ /* @__PURE__ */ r(sn, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3433
+ /* @__PURE__ */ r("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ r("div", { className: "truncate text-[12px] font-medium text-foreground", children: "Field inspector" }) }),
3434
+ /* @__PURE__ */ r(
3435
+ H,
3436
+ {
3437
+ type: "button",
3438
+ variant: "ghost",
3439
+ size: "icon",
3440
+ className: "h-7 w-7 text-muted-foreground",
3441
+ "aria-label": "Close field inspector",
3442
+ onClick: a,
3443
+ children: /* @__PURE__ */ r(He, { className: "h-3.5 w-3.5" })
3444
+ }
3445
+ )
3446
+ ] }),
3447
+ /* @__PURE__ */ c("div", { className: "shrink-0 border-b border-border p-3", children: [
3448
+ /* @__PURE__ */ r("div", { className: "text-[13px] font-medium text-foreground", children: e.title }),
3449
+ /* @__PURE__ */ c("div", { className: "mt-0.5 truncate font-mono text-[10.5px] text-muted-foreground", children: [
3450
+ e.domain.label,
3451
+ " · ",
3452
+ e.dataset.name
3453
+ ] }),
3454
+ e.dataset.primaryDateField ? /* @__PURE__ */ c("div", { className: "mt-2 rounded-[5px] bg-muted px-2 py-1 text-[11px] text-muted-foreground", children: [
3455
+ "Primary date: ",
3456
+ e.dataset.primaryDateField
3457
+ ] }) : null,
3458
+ /* @__PURE__ */ c("label", { className: "mt-3 flex h-8 items-center gap-2 rounded-[5px] border border-border bg-background px-2", children: [
3459
+ /* @__PURE__ */ r(la, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3460
+ /* @__PURE__ */ r(
3461
+ "input",
3462
+ {
3463
+ value: s,
3464
+ onChange: (f) => d(f.target.value),
3465
+ placeholder: "Search fields",
3466
+ className: "min-w-0 flex-1 bg-transparent text-[12px] outline-none placeholder:text-muted-foreground"
3467
+ }
3468
+ )
3469
+ ] }),
3470
+ /* @__PURE__ */ r("div", { className: "mt-2 flex flex-wrap gap-1", children: S.map((f) => /* @__PURE__ */ c(
3471
+ "button",
3472
+ {
3473
+ type: "button",
3474
+ onClick: () => p(f.id),
3475
+ className: `rounded-[5px] px-2 py-1 text-[10.5px] ${l === f.id ? "bg-foreground text-background" : "bg-muted text-muted-foreground hover:text-foreground"}`,
3476
+ children: [
3477
+ f.label,
3478
+ " ",
3479
+ f.count
3480
+ ]
3481
+ },
3482
+ f.id
3483
+ )) })
3484
+ ] }),
3485
+ /* @__PURE__ */ r("div", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: g.length > 0 ? /* @__PURE__ */ r("div", { className: "space-y-1", children: g.map((f) => /* @__PURE__ */ c(
3486
+ "div",
3487
+ {
3488
+ className: "rounded-[5px] border border-border px-2 py-1.5",
3489
+ children: [
3490
+ /* @__PURE__ */ r("div", { className: "truncate text-[12px] font-medium text-foreground", children: f.label || f.name }),
3491
+ /* @__PURE__ */ c("div", { className: "mt-0.5 flex min-w-0 items-center gap-1.5 text-[10.5px] text-muted-foreground", children: [
3492
+ /* @__PURE__ */ r("span", { className: "truncate font-mono", children: f.name }),
3493
+ f.role ? /* @__PURE__ */ c("span", { children: [
3494
+ "· ",
3495
+ f.role
3496
+ ] }) : null,
3497
+ f.dataType ? /* @__PURE__ */ c("span", { children: [
3498
+ "· ",
3499
+ f.dataType
3500
+ ] }) : null,
3501
+ f.source === "calculated" ? /* @__PURE__ */ r("span", { children: "· calculated" }) : null
3502
+ ] })
3503
+ ]
3504
+ },
3505
+ `${f.source}:${f.name}`
3506
+ )) }) : /* @__PURE__ */ r("div", { className: "rounded-[5px] border border-dashed border-border px-3 py-6 text-center text-[12px] text-muted-foreground", children: "No fields match this search." }) })
3507
+ ] });
3508
+ }
3509
+ function co({
3510
+ phase: e,
3511
+ detail: a,
3512
+ elapsedMs: s
3513
+ }) {
3514
+ const d = Ia(e), l = a || La(e);
3515
+ return /* @__PURE__ */ c("div", { className: "max-w-[92%] rounded-[6px] rounded-bl-[2px] border border-border bg-background px-3 py-2.5", children: [
3516
+ /* @__PURE__ */ c("div", { className: "flex items-center gap-2", children: [
3517
+ /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground" }),
3518
+ /* @__PURE__ */ r("span", { className: "text-[12.5px] font-medium text-foreground", children: d }),
3519
+ /* @__PURE__ */ r("span", { className: "ml-auto shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground", children: Gt(s) })
3520
+ ] }),
3521
+ /* @__PURE__ */ r("div", { className: "mt-1 flex items-center justify-between gap-3", children: /* @__PURE__ */ r("span", { className: "text-[11px] leading-relaxed text-muted-foreground", children: l }) })
3522
+ ] });
3523
+ }
3524
+ function uo({
3525
+ run: e,
3526
+ getStepDuration: a
3527
+ }) {
3528
+ var f, R, v;
3529
+ const s = e.steps.filter((B) => B.state === "done").length, d = e.steps.length, l = (R = (f = e.result) == null ? void 0 : f.generationMeta) == null ? void 0 : R.durationMs, p = (B) => B.id === "generate" && typeof l == "number" ? l : a(B), h = e.steps.reduce(
3530
+ (B, b) => B + p(b),
3531
+ 0
3532
+ ), g = e.status === "running", S = g ? "running" : e.result ? e.result.ok ? "passed" : "failed" : e.status;
3533
+ return /* @__PURE__ */ c(
3534
+ "details",
3535
+ {
3536
+ open: g,
3537
+ className: "group rounded-[6px] border border-border/60 bg-muted/20",
3538
+ children: [
3539
+ /* @__PURE__ */ c("summary", { className: "flex cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 text-[12px] marker:hidden", children: [
3540
+ /* @__PURE__ */ r(_t, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform group-open:rotate-90" }),
3541
+ /* @__PURE__ */ r(
3542
+ "span",
3543
+ {
3544
+ className: `h-1.5 w-1.5 shrink-0 rounded-full ${g ? "animate-pulse bg-amber-500" : e.status === "done" ? "bg-emerald-500" : "bg-destructive"}`
3545
+ }
3546
+ ),
3547
+ /* @__PURE__ */ r("span", { className: "shrink-0 font-medium text-foreground", children: "Build" }),
3548
+ /* @__PURE__ */ c("span", { className: "min-w-0 truncate text-muted-foreground", children: [
3549
+ "· ",
3550
+ e.prompt
3551
+ ] }),
3552
+ /* @__PURE__ */ c("span", { className: "ml-auto shrink-0 font-mono text-[11px] text-muted-foreground", children: [
3553
+ S,
3554
+ " · ",
3555
+ s,
3556
+ "/",
3557
+ d,
3558
+ " ·",
3559
+ " ",
3560
+ Gt(h)
3561
+ ] })
3562
+ ] }),
3563
+ /* @__PURE__ */ c("div", { className: "space-y-2.5 border-t border-border/60 px-2.5 py-2", children: [
3564
+ g ? /* @__PURE__ */ r("div", { className: "h-1 overflow-hidden rounded-full bg-muted", children: /* @__PURE__ */ r(
3565
+ "div",
3566
+ {
3567
+ className: "h-full rounded-full bg-foreground",
3568
+ style: {
3569
+ width: `${Math.round(s / Math.max(1, d) * 100)}%`
3570
+ }
3571
+ }
3572
+ ) }) : null,
3573
+ /* @__PURE__ */ r("div", { className: "space-y-0.5", children: e.steps.map((B) => {
3574
+ var b, E;
3575
+ return /* @__PURE__ */ r(
3576
+ po,
3577
+ {
3578
+ duration: p(B),
3579
+ repairAttempts: (E = (b = e.result) == null ? void 0 : b.telemetry) == null ? void 0 : E.repairAttempts,
3580
+ step: B
3581
+ },
3582
+ B.id
3583
+ );
3584
+ }) }),
3585
+ e.result && /* @__PURE__ */ c("div", { className: "space-y-1.5 border-t border-border pt-2.5 text-[12px] leading-relaxed text-muted-foreground", children: [
3586
+ /* @__PURE__ */ c("div", { className: "font-medium text-foreground", children: [
3587
+ "Runtime result:",
3588
+ " ",
3589
+ /* @__PURE__ */ r(
3590
+ "span",
3591
+ {
3592
+ className: e.result.ok ? "text-emerald-600" : "text-destructive",
3593
+ children: e.result.ok ? "passed" : "failed"
3594
+ }
3595
+ )
3596
+ ] }),
3597
+ e.result.telemetry && /* @__PURE__ */ c("div", { className: "grid gap-1 font-mono text-[11px] sm:grid-cols-2", children: [
3598
+ /* @__PURE__ */ c("span", { children: [
3599
+ "context: ",
3600
+ e.result.telemetry.contextFileCount ?? 0,
3601
+ " ",
3602
+ "files · ",
3603
+ e.result.telemetry.contextChars ?? 0,
3604
+ " chars"
3605
+ ] }),
3606
+ /* @__PURE__ */ c("span", { children: [
3607
+ "generated:",
3608
+ " ",
3609
+ e.result.telemetry.generatedFileCount ?? 0,
3610
+ " files ·",
3611
+ " ",
3612
+ e.result.telemetry.generatedChars ?? 0,
3613
+ " chars"
3614
+ ] })
3615
+ ] }),
3616
+ (v = e.result.changedFiles) != null && v.length ? /* @__PURE__ */ c("div", { children: [
3617
+ "Changed ",
3618
+ e.result.changedFiles.join(", ")
3619
+ ] }) : null,
3620
+ /* @__PURE__ */ r(
3621
+ qa,
3622
+ {
3623
+ plan: e.result.filePlan,
3624
+ changedFiles: e.result.changedFiles
3625
+ }
3626
+ ),
3627
+ e.result.generationMeta && /* @__PURE__ */ c("div", { children: [
3628
+ "Model: ",
3629
+ e.result.generationMeta.model
3630
+ ] }),
3631
+ e.result.error && /* @__PURE__ */ r("pre", { className: "mt-1 max-h-44 overflow-auto whitespace-pre-wrap rounded-[4px] border border-border bg-muted/40 p-2 font-mono text-[11px] text-foreground", children: e.result.error })
3632
+ ] })
3633
+ ] })
3634
+ ]
3635
+ }
3636
+ );
3637
+ }
3638
+ function po({
3639
+ duration: e,
3640
+ repairAttempts: a,
3641
+ step: s
3642
+ }) {
3643
+ return /* @__PURE__ */ c("div", { className: "grid grid-cols-[16px_minmax(0,1fr)_auto] items-center gap-2 rounded-[4px] px-1.5 py-1 text-[11.5px]", children: [
3644
+ /* @__PURE__ */ r(ho, { state: s.state }),
3645
+ /* @__PURE__ */ c("div", { className: "min-w-0", children: [
3646
+ /* @__PURE__ */ r(
3647
+ "div",
3648
+ {
3649
+ className: `truncate font-mono ${s.state === "idle" ? "text-muted-foreground" : "text-foreground"}`,
3650
+ children: s.label
3651
+ }
3652
+ ),
3653
+ s.state === "running" && /* @__PURE__ */ r("div", { className: "mt-0.5 truncate text-[11px] text-muted-foreground", children: s.detail })
3654
+ ] }),
3655
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-2 font-mono text-[11px] text-muted-foreground", children: s.id === "repair" && s.state === "running" ? /* @__PURE__ */ c("span", { children: [
3656
+ "attempt ",
3657
+ (a || 0) + 1,
3658
+ " / ",
3659
+ ze
3660
+ ] }) : /* @__PURE__ */ r("span", { children: Gt(e) }) })
3661
+ ] });
3662
+ }
3663
+ function ho({ state: e }) {
3664
+ return e === "done" ? /* @__PURE__ */ r(Ut, { className: "h-3.5 w-3.5 text-emerald-600" }) : e === "running" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin text-blue-600" }) : e === "blocked" ? /* @__PURE__ */ r(He, { className: "h-3.5 w-3.5 text-destructive" }) : /* @__PURE__ */ r(ca, { className: "h-2.5 w-2.5 fill-zinc-300 stroke-none" });
3665
+ }
2
3666
  export {
3
- r as DataAppBuilder
3667
+ yo as DataAppBuilder
4
3668
  };