@gatewaze/admin-embed 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +42 -0
  2. package/dist/AiSkillsPicker-dbFhcanE.js +373 -0
  3. package/dist/ContentAccessPage-D0HRqPFc.js +264 -0
  4. package/dist/DataTable-fe6yRVpF.js +1984 -0
  5. package/dist/DetailPageHeader-D_v7924k.js +69 -0
  6. package/dist/EditionEmail-CyhC8232.js +8382 -0
  7. package/dist/GuideContent-DBXKCu7r.js +7580 -0
  8. package/dist/HostMediaTab-BsIBEQ1v.js +440 -0
  9. package/dist/InboxPage-C8ivCKdx.js +1112 -0
  10. package/dist/NewsletterCanvasEditor--B06apn3.js +11453 -0
  11. package/dist/NewsletterSetupWizard-BqV6-fa5.js +347 -0
  12. package/dist/NewsletterSignup-DRVZIpOs.js +224 -0
  13. package/dist/Page-D3u8IZ2a.js +14 -0
  14. package/dist/Toaster-Cde0i6IA.js +18 -0
  15. package/dist/Tooltip-CqxUlW1d.js +746 -0
  16. package/dist/_collectionSlug_-B3UN6M-Q.js +308 -0
  17. package/dist/_collection_-Qz4k_Qjl.js +139 -0
  18. package/dist/_edition_-DQXwkI_-.js +301 -0
  19. package/dist/_id_-CtT7rT9f.js +257 -0
  20. package/dist/_id_-CzScE4Qn.js +1197 -0
  21. package/dist/_virtual_gatewaze-modules-BeloWlOa.js +991 -0
  22. package/dist/admin-B0Mmrh_O.js +1239 -0
  23. package/dist/admin-CcfoK6vD.js +17 -0
  24. package/dist/admin-embed.js +21844 -0
  25. package/dist/admin.css +2 -0
  26. package/dist/block-editor-vXBShAue.js +226 -0
  27. package/dist/brand-DklYwIeA.js +11 -0
  28. package/dist/brick-editor-CmBitMMK.js +225 -0
  29. package/dist/broadcastService-CBqXNt_N.js +190 -0
  30. package/dist/classnames-uWIYaD6z.js +44 -0
  31. package/dist/contentAccessService-Cs7tdAo-.js +59 -0
  32. package/dist/context-jzuubYRz.js +5 -0
  33. package/dist/createSafeContext-P1pK0sAN.js +17 -0
  34. package/dist/detail-B8SVFJJr.js +26285 -0
  35. package/dist/detail-uFBxRbLF.js +2966 -0
  36. package/dist/dist-DTrOExw8.js +38806 -0
  37. package/dist/edition-slug-CARO24Bs.js +7 -0
  38. package/dist/export-edition-html-C_hdXQu5.js +18893 -0
  39. package/dist/floating-ui.dom-Cyv879E9.js +987 -0
  40. package/dist/hooks-C377EXJG.js +2974 -0
  41. package/dist/img/mlops-logo.png +0 -0
  42. package/dist/img/mlops-logo2.png +0 -0
  43. package/dist/index.d.ts +105 -0
  44. package/dist/jsx-runtime-CjozyJt-.js +180 -0
  45. package/dist/lib-CylJmhlJ.js +828 -0
  46. package/dist/list-C0cz0aQz.js +451 -0
  47. package/dist/list-CIVgIGsU.js +166 -0
  48. package/dist/logo/mlops-alt.png +0 -0
  49. package/dist/logo/mlops-logo.png +0 -0
  50. package/dist/new-r4KWpqa6.js +80 -0
  51. package/dist/outline-DwDYhYcF.js +6538 -0
  52. package/dist/pages-Ersfxcz7.js +216 -0
  53. package/dist/preview/12627f.jpg +0 -0
  54. package/dist/preview/af009d.jpg +0 -0
  55. package/dist/public-api-LD11kMxh.js +238 -0
  56. package/dist/react-DB2tPNit.js +933 -0
  57. package/dist/react-dom-giQNVXng.js +267 -0
  58. package/dist/registry-4XrV9iNG.js +7 -0
  59. package/dist/render-BtUWfMUt.js +59634 -0
  60. package/dist/resolvePeopleByEmail-hivX2l07.js +828 -0
  61. package/dist/runtime-config.js +10 -0
  62. package/dist/sends-BkPO6PG2.js +182 -0
  63. package/dist/server.browser-Pj3QUa7k.js +15227 -0
  64. package/dist/shim-BCerG8nb.js +6681 -0
  65. package/dist/sonnerHostBridge-CXuCMM3R.js +665 -0
  66. package/dist/src-BWDAOzZO.js +799 -0
  67. package/dist/starter-templates-CFs-QUdF.js +3077 -0
  68. package/dist/storage-VDSvnkvR.js +39 -0
  69. package/dist/templateParser-BQ2IsJ6c.js +49 -0
  70. package/dist/templates-rjQjWsRr.js +253 -0
  71. package/dist/theme/gatewaze/android-icon-144x144.png +0 -0
  72. package/dist/theme/gatewaze/android-icon-192x192.png +0 -0
  73. package/dist/theme/gatewaze/android-icon-36x36.png +0 -0
  74. package/dist/theme/gatewaze/android-icon-48x48.png +0 -0
  75. package/dist/theme/gatewaze/android-icon-72x72.png +0 -0
  76. package/dist/theme/gatewaze/android-icon-96x96.png +0 -0
  77. package/dist/theme/gatewaze/favicon-144x144.png +0 -0
  78. package/dist/theme/gatewaze/favicon-16x16.png +0 -0
  79. package/dist/theme/gatewaze/favicon-192x192.png +0 -0
  80. package/dist/theme/gatewaze/favicon-32x32.png +0 -0
  81. package/dist/theme/gatewaze/favicon-96x96.png +0 -0
  82. package/dist/theme/gatewaze/favicon.ico +0 -0
  83. package/dist/theme/gatewaze/gatewaze-icon-512.png +0 -0
  84. package/dist/theme/gatewaze/gatewaze-logo-black.svg +24 -0
  85. package/dist/theme/gatewaze/gatewaze-logo-white.svg +20 -0
  86. package/dist/theme/gatewaze/gatewaze-poweredby-black.svg +25 -0
  87. package/dist/theme/gatewaze/gatewaze-poweredby-white.svg +25 -0
  88. package/dist/theme/gatewaze/logo_black.svg +24 -0
  89. package/dist/theme/gatewaze/logo_white.svg +20 -0
  90. package/dist/theme-D6odw5nx.js +586 -0
  91. package/dist/ui-DRIo9Krs.js +9747 -0
  92. package/dist/upload-DMNfZ6FX.js +505 -0
  93. package/dist/useModuleFeature-DgsFIUpv.js +8 -0
  94. package/dist/utils-BcVvIjaY.js +36 -0
  95. package/dist/with-selector-B8eSdVx_.js +100 -0
  96. package/package.json +33 -0
@@ -0,0 +1,1239 @@
1
+ import { c as e, i as t, t as n } from "./react-DB2tPNit.js";
2
+ import { d as r } from "./shim-BCerG8nb.js";
3
+ import { t as i } from "./jsx-runtime-CjozyJt-.js";
4
+ import { n as a } from "./sonnerHostBridge-CXuCMM3R.js";
5
+ import { i as o, o as s, t as c } from "./dist-DTrOExw8.js";
6
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/services/canvasAiService.ts
7
+ var l = /* @__PURE__ */ e(n()), u = c(), d = globalThis.__GATEWAZE_CONFIG__.VITE_API_URL ?? "";
8
+ async function f(e, t) {
9
+ let { data: n } = await r.auth.getSession(), i = n.session?.access_token, a = new Headers(t?.headers);
10
+ return i && a.set("Authorization", `Bearer ${i}`), a.has("Accept") || a.set("Accept", "application/json"), fetch(`${d}${e}`, {
11
+ ...t,
12
+ headers: a
13
+ });
14
+ }
15
+ async function p(e) {
16
+ let t = {};
17
+ try {
18
+ t = await e.json();
19
+ } catch {}
20
+ let n = e.headers.get("Retry-After"), r = n ? Number(n) : void 0;
21
+ return {
22
+ code: t.error?.code ?? `http_${e.status}`,
23
+ message: t.error?.message ?? `Request failed (${e.status})`,
24
+ httpStatus: e.status,
25
+ ...r && !Number.isNaN(r) ? { retryAfter: r } : {},
26
+ ...t.error?.details ? { details: t.error.details } : {}
27
+ };
28
+ }
29
+ var m = {
30
+ async generate(e, t) {
31
+ let n = await f("/api/admin/modules/editor-ai-copilot/generate", {
32
+ method: "POST",
33
+ headers: { "Content-Type": "application/json" },
34
+ body: JSON.stringify(e),
35
+ ...t ? { signal: t } : {}
36
+ });
37
+ return n.ok ? {
38
+ ok: !0,
39
+ response: await n.json()
40
+ } : {
41
+ ok: !1,
42
+ error: await p(n)
43
+ };
44
+ },
45
+ async loadThread(e) {
46
+ let t = await f(`/api/admin/modules/editor-ai-copilot/thread?${new URLSearchParams({
47
+ host_kind: e.host_kind,
48
+ host_id: e.host_id,
49
+ target_id: e.target_id
50
+ }).toString()}`, { method: "GET" });
51
+ return t.ok ? (await t.json()).messages ?? [] : [];
52
+ },
53
+ async uploadDocument(e) {
54
+ let t = new FormData();
55
+ t.append("file", e.file), t.append("host_kind", e.host_kind), t.append("host_id", e.host_id), t.append("target_id", e.target_id);
56
+ let n = await f("/api/admin/modules/editor-ai-copilot/documents", {
57
+ method: "POST",
58
+ body: t
59
+ });
60
+ if (!n.ok) return {
61
+ ok: !1,
62
+ error: await p(n)
63
+ };
64
+ let r = await n.json();
65
+ return {
66
+ ok: !0,
67
+ doc_id: r.doc_id,
68
+ filename: r.filename,
69
+ warnings: r.warnings
70
+ };
71
+ },
72
+ async uploadDocumentFromUrl(e) {
73
+ let t = await f("/api/admin/modules/editor-ai-copilot/documents", {
74
+ method: "POST",
75
+ headers: { "Content-Type": "application/json" },
76
+ body: JSON.stringify(e)
77
+ });
78
+ if (!t.ok) return {
79
+ ok: !1,
80
+ error: await p(t)
81
+ };
82
+ let n = await t.json();
83
+ return {
84
+ ok: !0,
85
+ doc_id: n.doc_id,
86
+ filename: n.filename,
87
+ warnings: n.warnings
88
+ };
89
+ }
90
+ };
91
+ //#endregion
92
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/components/puck-data-merger.ts
93
+ function h(e) {
94
+ return e.props.id ? e : {
95
+ ...e,
96
+ props: {
97
+ ...e.props,
98
+ id: g()
99
+ }
100
+ };
101
+ }
102
+ function g() {
103
+ if (typeof crypto < "u" && "randomUUID" in crypto) return crypto.randomUUID();
104
+ let e = "";
105
+ for (let t = 0; t < 32; t++) e += "0123456789abcdef"[Math.floor(Math.random() * 16)] ?? "";
106
+ return `${e.slice(0, 8)}-${e.slice(8, 12)}-4${e.slice(13, 16)}-${e.slice(16, 20)}-${e.slice(20, 32)}`;
107
+ }
108
+ function _(e) {
109
+ switch (e.mode) {
110
+ case "replace": return {
111
+ data: {
112
+ content: e.ai.content.map(h),
113
+ root: e.prev.root
114
+ },
115
+ warnings: []
116
+ };
117
+ case "append": return {
118
+ data: {
119
+ content: [...e.prev.content, ...e.ai.content.map(h)],
120
+ root: e.prev.root
121
+ },
122
+ warnings: []
123
+ };
124
+ case "insert-after": {
125
+ if (!e.anchorBlockId) return {
126
+ data: {
127
+ content: [...e.prev.content, ...e.ai.content.map(h)],
128
+ root: e.prev.root
129
+ },
130
+ warnings: [{
131
+ code: "missing_anchor",
132
+ message: "insert-after without anchorBlockId; appended at end"
133
+ }]
134
+ };
135
+ let t = e.prev.content.findIndex((t) => t.props.id === e.anchorBlockId);
136
+ return t < 0 ? {
137
+ data: {
138
+ content: [...e.prev.content, ...e.ai.content.map(h)],
139
+ root: e.prev.root
140
+ },
141
+ warnings: [{
142
+ code: "anchor_not_found",
143
+ message: `anchor ${e.anchorBlockId} not found; appended at end`
144
+ }]
145
+ } : {
146
+ data: {
147
+ content: [
148
+ ...e.prev.content.slice(0, t + 1),
149
+ ...e.ai.content.map(h),
150
+ ...e.prev.content.slice(t + 1)
151
+ ],
152
+ root: e.prev.root
153
+ },
154
+ warnings: []
155
+ };
156
+ }
157
+ case "edit": {
158
+ let t = [], n = e.ai.content.map((n) => n.props.id ? e.prev.content.find((e) => e.props.id === n.props.id) ? n : (t.push({
159
+ code: "ai_unmatched_id",
160
+ message: `AI sent id ${n.props.id} not on this page; treated as insert`
161
+ }), h({
162
+ ...n,
163
+ props: {
164
+ ...n.props,
165
+ id: g()
166
+ }
167
+ })) : h(n)), r = new Set(n.map((e) => e.props.id)), i = e.prev.content.filter((e) => !r.has(e.props.id)).length;
168
+ return i > 0 && t.push({
169
+ code: "edit_dropped_blocks",
170
+ message: `${i} block(s) removed in edit`
171
+ }), {
172
+ data: {
173
+ content: n,
174
+ root: e.prev.root
175
+ },
176
+ warnings: t
177
+ };
178
+ }
179
+ case "edit-block": {
180
+ if (!e.blockId) return {
181
+ data: e.prev,
182
+ warnings: [{
183
+ code: "missing_blockId",
184
+ message: "edit-block called without blockId; no merge"
185
+ }]
186
+ };
187
+ let t = e.ai.content[0];
188
+ if (!t) return {
189
+ data: e.prev,
190
+ warnings: [{
191
+ code: "edit_block_empty_response",
192
+ message: "edit-block returned no block"
193
+ }]
194
+ };
195
+ let n = v(e.prev.content, e.blockId, t);
196
+ return n.found ? {
197
+ data: {
198
+ content: n.content,
199
+ root: e.prev.root
200
+ },
201
+ warnings: []
202
+ } : {
203
+ data: e.prev,
204
+ warnings: [{
205
+ code: "block_not_found_at_merge",
206
+ message: `block ${e.blockId} not found in current data — was it deleted?`
207
+ }]
208
+ };
209
+ }
210
+ }
211
+ }
212
+ function v(e, t, n) {
213
+ let r = !1, i = e.map((e) => {
214
+ if (e.props.id === t) return r = !0, {
215
+ type: e.type,
216
+ props: {
217
+ ...n.props,
218
+ id: t
219
+ }
220
+ };
221
+ if (Array.isArray(e.props.children)) {
222
+ let i = v(e.props.children, t, n);
223
+ if (i.found) return r = !0, {
224
+ ...e,
225
+ props: {
226
+ ...e.props,
227
+ children: i.content
228
+ }
229
+ };
230
+ }
231
+ return e;
232
+ });
233
+ return {
234
+ found: r,
235
+ content: i
236
+ };
237
+ }
238
+ //#endregion
239
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/components/useAiGenerate.ts
240
+ function ee() {
241
+ let [e, t] = (0, l.useState)({
242
+ status: "idle",
243
+ error: null,
244
+ warnings: [],
245
+ lastUsage: null
246
+ }), n = (0, l.useRef)(null), r = (0, l.useCallback)(() => {
247
+ n.current?.abort(), n.current = null, t((e) => e.status === "loading" ? {
248
+ ...e,
249
+ status: "idle"
250
+ } : e);
251
+ }, []), i = (0, l.useCallback)(async (e) => {
252
+ r();
253
+ let i = new AbortController();
254
+ n.current = i, t({
255
+ status: "loading",
256
+ error: null,
257
+ warnings: [],
258
+ lastUsage: null
259
+ });
260
+ try {
261
+ let n = await m.generate(e.request, i.signal);
262
+ if (!n.ok) {
263
+ t({
264
+ status: "error",
265
+ error: n.error,
266
+ warnings: [],
267
+ lastUsage: null
268
+ });
269
+ return;
270
+ }
271
+ let r = e.request.mode, a = _({
272
+ mode: r,
273
+ prev: e.currentData,
274
+ ai: n.response.data,
275
+ ...e.request.anchorBlockId ? { anchorBlockId: e.request.anchorBlockId } : {},
276
+ ...e.request.blockId ? { blockId: e.request.blockId } : {}
277
+ }), o = n.response.usage.input_tokens + n.response.usage.output_tokens, s = n.response.usage.cost_micro_usd / 1e6;
278
+ e.onApply(a.data), t({
279
+ status: "success",
280
+ error: null,
281
+ warnings: [...n.response.warnings, ...a.warnings],
282
+ lastUsage: {
283
+ tokens: o,
284
+ cost_approx: s,
285
+ duration_ms: n.response.usage.duration_ms
286
+ }
287
+ });
288
+ } catch (e) {
289
+ if (i.signal.aborted) return;
290
+ t({
291
+ status: "error",
292
+ error: {
293
+ code: "client_error",
294
+ message: e instanceof Error ? e.message : "Generation failed",
295
+ httpStatus: 0
296
+ },
297
+ warnings: [],
298
+ lastUsage: null
299
+ });
300
+ }
301
+ }, [r]);
302
+ return {
303
+ ...e,
304
+ generate: i,
305
+ abort: r
306
+ };
307
+ }
308
+ //#endregion
309
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/components/AiDocumentUploader.tsx
310
+ var y = i();
311
+ function b(e) {
312
+ let t = e.maxDocs ?? 5, [n, r] = (0, l.useState)("file"), [i, a] = (0, l.useState)(""), [o, s] = (0, l.useState)(!1), [c, u] = (0, l.useState)(null), d = e.attached.length >= t, f = (0, l.useCallback)(async (n) => {
313
+ if (d) {
314
+ u({
315
+ code: "too_many_docs",
316
+ message: `max ${t} documents per generation`,
317
+ httpStatus: 400
318
+ });
319
+ return;
320
+ }
321
+ s(!0), u(null);
322
+ try {
323
+ let t = await m.uploadDocument({
324
+ file: n,
325
+ host_kind: e.hostKind,
326
+ host_id: e.hostId,
327
+ target_id: e.targetId
328
+ });
329
+ if (!t.ok) {
330
+ u(t.error);
331
+ return;
332
+ }
333
+ e.onAttach({
334
+ doc_id: t.doc_id,
335
+ filename: t.filename,
336
+ source: "upload"
337
+ });
338
+ } finally {
339
+ s(!1);
340
+ }
341
+ }, [
342
+ d,
343
+ t,
344
+ e
345
+ ]), p = (0, l.useCallback)(async () => {
346
+ if (i.trim()) {
347
+ if (d) {
348
+ u({
349
+ code: "too_many_docs",
350
+ message: `max ${t} documents per generation`,
351
+ httpStatus: 400
352
+ });
353
+ return;
354
+ }
355
+ s(!0), u(null);
356
+ try {
357
+ let t = await m.uploadDocumentFromUrl({
358
+ url: i.trim(),
359
+ host_kind: e.hostKind,
360
+ host_id: e.hostId,
361
+ target_id: e.targetId
362
+ });
363
+ if (!t.ok) {
364
+ u(t.error);
365
+ return;
366
+ }
367
+ e.onAttach({
368
+ doc_id: t.doc_id,
369
+ filename: t.filename,
370
+ source: "url"
371
+ }), a("");
372
+ } finally {
373
+ s(!1);
374
+ }
375
+ }
376
+ }, [
377
+ i,
378
+ d,
379
+ t,
380
+ e
381
+ ]), h = (0, l.useCallback)((e) => {
382
+ e.preventDefault();
383
+ let t = e.dataTransfer.files?.[0];
384
+ t && f(t);
385
+ }, [f]);
386
+ return /* @__PURE__ */ (0, y.jsxs)("div", {
387
+ className: "ai-doc-uploader",
388
+ children: [
389
+ /* @__PURE__ */ (0, y.jsxs)("div", {
390
+ className: "ai-doc-uploader__tabs",
391
+ children: [/* @__PURE__ */ (0, y.jsx)("button", {
392
+ type: "button",
393
+ onClick: () => r("file"),
394
+ disabled: n === "file",
395
+ children: "From file"
396
+ }), /* @__PURE__ */ (0, y.jsx)("button", {
397
+ type: "button",
398
+ onClick: () => r("url"),
399
+ disabled: n === "url",
400
+ children: "From URL"
401
+ })]
402
+ }),
403
+ n === "file" && /* @__PURE__ */ (0, y.jsx)("div", {
404
+ className: "ai-doc-uploader__dropzone",
405
+ onDragOver: (e) => e.preventDefault(),
406
+ onDrop: h,
407
+ children: /* @__PURE__ */ (0, y.jsxs)("label", { children: [/* @__PURE__ */ (0, y.jsx)("input", {
408
+ type: "file",
409
+ accept: ".pdf,.docx,.md,.markdown,.txt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,text/markdown",
410
+ disabled: o || d,
411
+ onChange: (e) => {
412
+ let t = e.target.files?.[0];
413
+ t && f(t);
414
+ }
415
+ }), /* @__PURE__ */ (0, y.jsx)("span", { children: "Drag a PDF, DOCX, Markdown, or text file — or click to pick." })] })
416
+ }),
417
+ n === "url" && /* @__PURE__ */ (0, y.jsxs)("div", {
418
+ className: "ai-doc-uploader__urlbox",
419
+ children: [
420
+ /* @__PURE__ */ (0, y.jsx)("input", {
421
+ type: "url",
422
+ placeholder: "https:// or a public Google Doc share URL",
423
+ value: i,
424
+ onChange: (e) => a(e.target.value),
425
+ disabled: o || d
426
+ }),
427
+ /* @__PURE__ */ (0, y.jsx)("button", {
428
+ type: "button",
429
+ onClick: () => void p(),
430
+ disabled: o || d || !i.trim(),
431
+ children: o ? "Fetching…" : "Attach"
432
+ }),
433
+ i.includes("docs.google.com") && /* @__PURE__ */ (0, y.jsx)("p", {
434
+ className: "ai-doc-uploader__hint",
435
+ children: "Looks like a Google Doc — make sure sharing is set to “Anyone with the link”."
436
+ })
437
+ ]
438
+ }),
439
+ c && /* @__PURE__ */ (0, y.jsxs)("p", {
440
+ className: "ai-doc-uploader__error",
441
+ children: [
442
+ c.code,
443
+ ": ",
444
+ c.message
445
+ ]
446
+ }),
447
+ e.attached.length > 0 && /* @__PURE__ */ (0, y.jsx)("ul", {
448
+ className: "ai-doc-uploader__list",
449
+ children: e.attached.map((t) => /* @__PURE__ */ (0, y.jsxs)("li", { children: [/* @__PURE__ */ (0, y.jsx)("span", { children: t.filename }), /* @__PURE__ */ (0, y.jsx)("button", {
450
+ type: "button",
451
+ onClick: () => e.onRemove(t.doc_id),
452
+ "aria-label": `Remove ${t.filename}`,
453
+ children: "×"
454
+ })] }, t.doc_id))
455
+ })
456
+ ]
457
+ });
458
+ }
459
+ //#endregion
460
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/components/AiSidebarPane.tsx
461
+ function x(e, t) {
462
+ let n = e.trim().toLowerCase();
463
+ if (!n) return t ? "edit-block" : "replace";
464
+ let r = /\b(this|that|it|the (selected|current|chosen)|this block|this section|this column|this row|this heading|this image|this card|this button|this text|the headline|the subhead|selected block)\b/.test(n);
465
+ if (t && /\b(insert (after|below|underneath)|after (this|that|it)|below (this|that|it)|underneath|right after|next to (this|that|it))\b/.test(n)) return "insert-after";
466
+ if (/\b(append|at the (end|bottom)|to the (end|bottom)|at end|add (a |an |another )?(?:.+? )?at the (end|bottom))\b/.test(n) || !t && /\b(add (a|an|another) (?!image|photo|attachment)\b)/.test(n)) return "append";
467
+ if (t && (r || n.length < 40 && /^(make (it|this) |punchier|shorter|longer|more |less |fix |polish |rewrite |tweak |refine |update )/.test(n))) return "edit-block";
468
+ let i = /\b(update|edit|change|fix|polish|improve|rewrite|tweak|refine|revise|adjust|reword) (the |this )?(page|edition|newsletter|copy|content|email)\b/.test(n), a = /\b(two |duplicate|extra |missing |broken|wrong|conflict|seem to have|appear to have|seems to have|there'?s (an?|two|some|a problem|an? issue|a bug|a duplicate))\b/.test(n), o = /\b(remove|delete|get rid of|take out|drop) (the|that|a|an|one of|both)\b/.test(n);
469
+ return !t && (i || a || o) ? "edit" : t ? "edit-block" : "replace";
470
+ }
471
+ var S = {
472
+ replace: "Drafting page",
473
+ append: "Appending content",
474
+ "insert-after": "Inserting after selection",
475
+ edit: "Editing page",
476
+ "edit-block": "Editing selected block"
477
+ }, C = (0, u.createUsePuck)(), w = {
478
+ rootInitial: {
479
+ display: "flex",
480
+ flexDirection: "column",
481
+ justifyContent: "flex-end",
482
+ height: "100%",
483
+ minHeight: 0,
484
+ padding: 12,
485
+ gap: 12,
486
+ fontSize: 13,
487
+ lineHeight: 1.4,
488
+ color: "var(--puck-color-grey-02, #1f2937)",
489
+ boxSizing: "border-box"
490
+ },
491
+ rootChat: {
492
+ display: "flex",
493
+ flexDirection: "column",
494
+ height: "100%",
495
+ minHeight: 0,
496
+ padding: 0,
497
+ fontSize: 13,
498
+ lineHeight: 1.45,
499
+ color: "var(--puck-color-grey-02, #1f2937)",
500
+ boxSizing: "border-box"
501
+ },
502
+ headerBar: {
503
+ padding: "12px 14px 10px",
504
+ fontSize: 14,
505
+ fontWeight: 600,
506
+ color: "var(--puck-color-grey-01, #111827)",
507
+ borderBottom: "1px solid var(--puck-color-grey-09, #e5e7eb)"
508
+ },
509
+ messages: {
510
+ flex: 1,
511
+ overflowY: "auto",
512
+ padding: "14px 14px 8px",
513
+ display: "flex",
514
+ flexDirection: "column",
515
+ gap: 10,
516
+ minHeight: 0
517
+ },
518
+ userBubble: {
519
+ alignSelf: "flex-end",
520
+ maxWidth: "85%",
521
+ padding: "8px 12px",
522
+ fontSize: 13,
523
+ lineHeight: 1.45,
524
+ color: "var(--puck-color-grey-02, #1f2937)",
525
+ background: "var(--puck-color-azure-10, #e0e7ff)",
526
+ borderRadius: 14,
527
+ borderTopRightRadius: 4,
528
+ wordBreak: "break-word"
529
+ },
530
+ assistantLine: {
531
+ alignSelf: "flex-start",
532
+ maxWidth: "95%",
533
+ fontSize: 13,
534
+ lineHeight: 1.5,
535
+ color: "var(--puck-color-grey-03, #374151)",
536
+ whiteSpace: "pre-wrap",
537
+ wordBreak: "break-word"
538
+ },
539
+ statusChipBase: {
540
+ alignSelf: "flex-start",
541
+ display: "inline-flex",
542
+ alignItems: "center",
543
+ gap: 6,
544
+ padding: "6px 10px 6px 8px",
545
+ fontSize: 12,
546
+ borderRadius: 999,
547
+ borderWidth: 1,
548
+ borderStyle: "solid"
549
+ },
550
+ statusChipPending: {
551
+ borderColor: "var(--puck-color-grey-09, #e5e7eb)",
552
+ background: "var(--puck-color-grey-12, #f9fafb)",
553
+ color: "var(--puck-color-grey-04, #4b5563)"
554
+ },
555
+ statusChipSuccess: {
556
+ borderColor: "var(--puck-color-grey-09, #d1fae5)",
557
+ background: "var(--puck-color-white, #fff)",
558
+ color: "var(--puck-color-grey-03, #065f46)"
559
+ },
560
+ statusChipError: {
561
+ borderColor: "#fecaca",
562
+ background: "#fef2f2",
563
+ color: "#991b1b"
564
+ },
565
+ metaLine: {
566
+ alignSelf: "flex-start",
567
+ fontSize: 11,
568
+ color: "var(--puck-color-grey-05, #9ca3af)",
569
+ fontVariantNumeric: "tabular-nums"
570
+ },
571
+ footer: {
572
+ padding: "8px 12px 12px",
573
+ borderTop: "1px solid var(--puck-color-grey-09, #e5e7eb)",
574
+ display: "flex",
575
+ flexDirection: "column",
576
+ gap: 8
577
+ },
578
+ footerInitial: {
579
+ padding: 0,
580
+ borderTop: "none",
581
+ display: "flex",
582
+ flexDirection: "column",
583
+ gap: 10
584
+ },
585
+ composer: {
586
+ display: "flex",
587
+ flexDirection: "column",
588
+ borderWidth: 1,
589
+ borderStyle: "solid",
590
+ borderColor: "var(--puck-color-grey-08, #d1d5db)",
591
+ borderRadius: 14,
592
+ background: "var(--puck-color-white, #fff)",
593
+ overflow: "hidden",
594
+ transition: "border-color 120ms ease, box-shadow 120ms ease"
595
+ },
596
+ composerFocused: {
597
+ borderColor: "var(--puck-color-azure-04, #1f3a93)",
598
+ boxShadow: "0 0 0 1px var(--puck-color-azure-04, #1f3a93)"
599
+ },
600
+ textarea: {
601
+ width: "100%",
602
+ minHeight: 56,
603
+ maxHeight: 260,
604
+ padding: "12px 14px",
605
+ fontFamily: "inherit",
606
+ fontSize: 13,
607
+ lineHeight: 1.45,
608
+ color: "inherit",
609
+ background: "transparent",
610
+ border: "none",
611
+ outline: "none",
612
+ resize: "none",
613
+ boxSizing: "border-box"
614
+ },
615
+ actionsRow: {
616
+ display: "flex",
617
+ alignItems: "center",
618
+ gap: 6,
619
+ padding: "6px 8px 8px 8px"
620
+ },
621
+ iconButton: {
622
+ display: "inline-flex",
623
+ alignItems: "center",
624
+ justifyContent: "center",
625
+ width: 30,
626
+ height: 30,
627
+ padding: 0,
628
+ background: "transparent",
629
+ borderWidth: 1,
630
+ borderStyle: "solid",
631
+ borderColor: "transparent",
632
+ borderRadius: 8,
633
+ cursor: "pointer",
634
+ color: "var(--puck-color-grey-04, #4b5563)"
635
+ },
636
+ iconButtonActive: {
637
+ background: "var(--puck-color-azure-09, #eef2ff)",
638
+ color: "var(--puck-color-azure-04, #1f3a93)"
639
+ },
640
+ modeHint: {
641
+ fontSize: 11,
642
+ color: "var(--puck-color-grey-05, #6b7280)",
643
+ fontStyle: "italic",
644
+ marginLeft: 4,
645
+ overflow: "hidden",
646
+ textOverflow: "ellipsis",
647
+ whiteSpace: "nowrap",
648
+ flex: "0 1 auto",
649
+ minWidth: 0
650
+ },
651
+ sendButton: {
652
+ display: "inline-flex",
653
+ alignItems: "center",
654
+ justifyContent: "center",
655
+ width: 30,
656
+ height: 30,
657
+ marginLeft: "auto",
658
+ padding: 0,
659
+ fontSize: 13,
660
+ color: "var(--puck-color-white, #fff)",
661
+ background: "var(--puck-color-azure-04, #1f3a93)",
662
+ borderWidth: 1,
663
+ borderStyle: "solid",
664
+ borderColor: "transparent",
665
+ borderRadius: "50%",
666
+ cursor: "pointer"
667
+ },
668
+ sendButtonDisabled: {
669
+ opacity: .4,
670
+ cursor: "not-allowed"
671
+ },
672
+ attachPanel: {
673
+ marginTop: 8,
674
+ padding: 10,
675
+ borderWidth: 1,
676
+ borderStyle: "solid",
677
+ borderColor: "var(--puck-color-grey-09, #e5e7eb)",
678
+ borderRadius: 10,
679
+ background: "var(--puck-color-grey-12, #f9fafb)"
680
+ },
681
+ attachedRow: {
682
+ display: "flex",
683
+ flexWrap: "wrap",
684
+ gap: 6
685
+ },
686
+ chip: {
687
+ display: "inline-flex",
688
+ alignItems: "center",
689
+ gap: 6,
690
+ padding: "4px 8px 4px 10px",
691
+ fontSize: 11,
692
+ color: "var(--puck-color-grey-03, #374151)",
693
+ background: "var(--puck-color-grey-11, #f3f4f6)",
694
+ borderWidth: 1,
695
+ borderStyle: "solid",
696
+ borderColor: "var(--puck-color-grey-09, #e5e7eb)",
697
+ borderRadius: 999,
698
+ maxWidth: "100%"
699
+ },
700
+ chipRemove: {
701
+ display: "inline-flex",
702
+ alignItems: "center",
703
+ justifyContent: "center",
704
+ width: 14,
705
+ height: 14,
706
+ padding: 0,
707
+ color: "var(--puck-color-grey-05, #6b7280)",
708
+ background: "transparent",
709
+ border: "none",
710
+ borderRadius: "50%",
711
+ cursor: "pointer",
712
+ fontSize: 14,
713
+ lineHeight: 1
714
+ },
715
+ chipName: {
716
+ overflow: "hidden",
717
+ textOverflow: "ellipsis",
718
+ whiteSpace: "nowrap",
719
+ maxWidth: 160
720
+ }
721
+ };
722
+ function T() {
723
+ return /* @__PURE__ */ (0, y.jsxs)("svg", {
724
+ width: "16",
725
+ height: "16",
726
+ viewBox: "0 0 24 24",
727
+ fill: "none",
728
+ stroke: "currentColor",
729
+ strokeWidth: "2",
730
+ strokeLinecap: "round",
731
+ strokeLinejoin: "round",
732
+ "aria-hidden": "true",
733
+ children: [/* @__PURE__ */ (0, y.jsx)("path", { d: "M5 12h14" }), /* @__PURE__ */ (0, y.jsx)("path", { d: "M12 5v14" })]
734
+ });
735
+ }
736
+ function E() {
737
+ return /* @__PURE__ */ (0, y.jsxs)("svg", {
738
+ width: "14",
739
+ height: "14",
740
+ viewBox: "0 0 24 24",
741
+ fill: "none",
742
+ stroke: "currentColor",
743
+ strokeWidth: "2.5",
744
+ strokeLinecap: "round",
745
+ strokeLinejoin: "round",
746
+ "aria-hidden": "true",
747
+ children: [/* @__PURE__ */ (0, y.jsx)("path", { d: "M12 19V5" }), /* @__PURE__ */ (0, y.jsx)("path", { d: "m5 12 7-7 7 7" })]
748
+ });
749
+ }
750
+ function D() {
751
+ return /* @__PURE__ */ (0, y.jsx)("svg", {
752
+ width: "12",
753
+ height: "12",
754
+ viewBox: "0 0 24 24",
755
+ fill: "none",
756
+ stroke: "currentColor",
757
+ strokeWidth: "2.5",
758
+ strokeLinecap: "round",
759
+ strokeLinejoin: "round",
760
+ "aria-hidden": "true",
761
+ children: /* @__PURE__ */ (0, y.jsx)("path", { d: "M20 6 9 17l-5-5" })
762
+ });
763
+ }
764
+ function O() {
765
+ return /* @__PURE__ */ (0, y.jsx)("span", {
766
+ "aria-hidden": "true",
767
+ style: {
768
+ display: "inline-flex",
769
+ gap: 3
770
+ },
771
+ children: [
772
+ 0,
773
+ 1,
774
+ 2
775
+ ].map((e) => /* @__PURE__ */ (0, y.jsx)("span", { style: {
776
+ width: 4,
777
+ height: 4,
778
+ borderRadius: "50%",
779
+ background: "currentColor",
780
+ animation: `ai-dot-blink 900ms ${e * 150}ms infinite ease-in-out`,
781
+ opacity: .6
782
+ } }, e))
783
+ });
784
+ }
785
+ function k(e) {
786
+ return `${e}-${Math.random().toString(36).slice(2, 9)}`;
787
+ }
788
+ function A(e) {
789
+ switch (e) {
790
+ case "replace": return "Replaced page";
791
+ case "append": return "Appended blocks";
792
+ case "insert-after": return "Inserted blocks";
793
+ case "edit": return "Edited page";
794
+ case "edit-block": return "Updated block";
795
+ }
796
+ }
797
+ async function j(e) {
798
+ let { mode: t, prev: n, next: r, anchorBlockId: i, dispatch: a, signal: o, perBlockMs: s = 110 } = e, c, l;
799
+ if (t === "replace") c = 0, l = r.content.length;
800
+ else if (t === "append") c = n.content.length, l = r.content.length;
801
+ else if (t === "insert-after") c = (i ? n.content.findIndex((e) => e.props.id === i) : n.content.length - 1) + 1, l = c + (r.content.length - n.content.length);
802
+ else {
803
+ a({
804
+ type: "setData",
805
+ data: r
806
+ });
807
+ return;
808
+ }
809
+ if (l <= c) {
810
+ a({
811
+ type: "setData",
812
+ data: r
813
+ });
814
+ return;
815
+ }
816
+ for (let e = c; e < l; e++) {
817
+ if (o.aborted) return;
818
+ a({
819
+ type: "setData",
820
+ data: {
821
+ content: [...r.content.slice(0, e + 1), ...t === "insert-after" ? r.content.slice(l) : []],
822
+ root: r.root
823
+ }
824
+ }), e < l - 1 && await new Promise((e) => setTimeout(e, s));
825
+ }
826
+ o.aborted || a({
827
+ type: "setData",
828
+ data: r
829
+ });
830
+ }
831
+ function M(e) {
832
+ let t = C((e) => e.appState.ui.itemSelector ?? null), n = C((e) => e.appState.data), r = C((e) => e.dispatch), [i, o] = (0, l.useState)([]), [s, c] = (0, l.useState)([]), u = (0, l.useRef)(!1), [d, f] = (0, l.useState)(""), [p, h] = (0, l.useState)([]), [g, _] = (0, l.useState)(!1), [v, D] = (0, l.useState)(!1), O = (0, l.useRef)(null), M = (0, l.useRef)(null), I = (0, l.useRef)(null), L = (0, l.useMemo)(() => !t || !n ? null : n.content[t.index]?.props.id ?? null, [t, n]), R = (0, l.useMemo)(() => x(d, !!L), [d, L]);
833
+ (0, l.useEffect)(() => {
834
+ let e = O.current;
835
+ e && (e.style.height = "auto", e.style.height = `${Math.min(e.scrollHeight, 260)}px`);
836
+ }, [d]), (0, l.useEffect)(() => {
837
+ M.current?.scrollIntoView({
838
+ behavior: "smooth",
839
+ block: "end"
840
+ });
841
+ }, [i.length, s.length]), (0, l.useEffect)(() => {
842
+ let t = !1;
843
+ return (async () => {
844
+ try {
845
+ let n = await m.loadThread({
846
+ host_kind: e.hostKind,
847
+ host_id: e.hostId,
848
+ target_id: e.targetId
849
+ });
850
+ !t && n.length > 0 && o((e) => e.length === 0 ? n : e);
851
+ } catch {}
852
+ })(), () => {
853
+ t = !0;
854
+ };
855
+ }, [
856
+ e.hostKind,
857
+ e.hostId,
858
+ e.targetId
859
+ ]);
860
+ let { status: z, error: B, warnings: V, lastUsage: H, generate: U, abort: W } = ee();
861
+ (0, l.useEffect)(() => {
862
+ z === "error" && B && o((e) => P(e, {
863
+ state: "error",
864
+ label: `Error: ${B.code}`
865
+ }).concat({
866
+ id: k("asst"),
867
+ kind: "assistant",
868
+ text: B.message
869
+ }));
870
+ }, [z, B]), (0, l.useEffect)(() => {
871
+ if (z === "success" && V.length > 0) for (let e of V) {
872
+ let t = typeof e == "string" ? e : `${e.code}: ${e.message}`;
873
+ a.warning(t);
874
+ }
875
+ }, [z, V]);
876
+ let G = (0, l.useCallback)(async (t) => {
877
+ let i = t.trim();
878
+ if (!i || z === "loading") return;
879
+ if (!n) {
880
+ a.error("AI: no canvas data");
881
+ return;
882
+ }
883
+ let s = x(i, !!L);
884
+ s === "insert-after" && !L && (s = "append"), s === "edit-block" && !L && (s = "edit");
885
+ let c = {
886
+ id: k("user"),
887
+ kind: "user",
888
+ text: i
889
+ }, l = {
890
+ id: k("asst"),
891
+ kind: "assistant",
892
+ text: `${S[s]}…`
893
+ }, u = {
894
+ id: k("stat"),
895
+ kind: "status",
896
+ label: A(s),
897
+ state: "pending"
898
+ };
899
+ o((e) => [
900
+ ...e,
901
+ c,
902
+ l,
903
+ u
904
+ ]), f("");
905
+ let d = {
906
+ host_kind: e.hostKind,
907
+ host_id: e.hostId,
908
+ target_id: e.targetId,
909
+ prompt: i,
910
+ mode: s,
911
+ ...s === "insert-after" && L ? { anchorBlockId: L } : {},
912
+ ...s === "edit-block" && L ? { blockId: L } : {},
913
+ ...p.length > 0 ? { doc_ids: p.map((e) => e.doc_id) } : {},
914
+ ...e.blockDefs && e.blockDefs.length > 0 ? { block_defs: e.blockDefs } : {}
915
+ };
916
+ I.current?.abort();
917
+ let m = new AbortController();
918
+ I.current = m;
919
+ let h = n;
920
+ await U({
921
+ currentData: n,
922
+ request: d,
923
+ onApply: (e) => {
924
+ j({
925
+ mode: s,
926
+ prev: h,
927
+ next: e,
928
+ ...s === "insert-after" && L ? { anchorBlockId: L } : {},
929
+ dispatch: r,
930
+ signal: m.signal
931
+ });
932
+ let t = s === "replace" ? e.content.length : e.content.length - h.content.length;
933
+ o((e) => P(e, {
934
+ state: "success",
935
+ label: s === "edit-block" ? "Updated block" : s === "edit" ? "Edited page" : `${A(s)} (${t} block${t === 1 ? "" : "s"})`
936
+ }).concat({
937
+ id: k("asst"),
938
+ kind: "assistant",
939
+ text: "Done. What would you like next?"
940
+ }));
941
+ }
942
+ });
943
+ }, [
944
+ z,
945
+ n,
946
+ L,
947
+ p,
948
+ e.hostKind,
949
+ e.hostId,
950
+ e.targetId,
951
+ e.blockDefs,
952
+ U,
953
+ r
954
+ ]), K = (0, l.useRef)(null);
955
+ (0, l.useEffect)(() => {
956
+ if (z !== "success" || !H) return;
957
+ let e = `${H.tokens}:${H.duration_ms}`;
958
+ K.current !== e && (K.current = e, o((e) => [...e, {
959
+ id: k("meta"),
960
+ kind: "meta",
961
+ tokens: H.tokens,
962
+ cost_approx: H.cost_approx,
963
+ duration_ms: H.duration_ms
964
+ }]));
965
+ }, [z, H]), (0, l.useEffect)(() => {
966
+ if (u.current || z === "loading" || s.length === 0) return;
967
+ u.current = !0;
968
+ let [e, ...t] = s;
969
+ c(t), G(e).finally(() => {
970
+ u.current = !1;
971
+ });
972
+ }, [
973
+ z,
974
+ s,
975
+ G
976
+ ]);
977
+ let q = (0, l.useCallback)(() => {
978
+ let e = d.trim();
979
+ if (e) {
980
+ if (z === "loading" || s.length > 0) {
981
+ c((t) => [...t, e]), f("");
982
+ return;
983
+ }
984
+ G(d);
985
+ }
986
+ }, [
987
+ d,
988
+ z,
989
+ s.length,
990
+ G
991
+ ]), J = (0, l.useCallback)((e) => {
992
+ e.key === "Enter" && !e.shiftKey && !e.metaKey && !e.ctrlKey ? (e.preventDefault(), q()) : e.key === "Escape" && z === "loading" && (W(), I.current?.abort());
993
+ }, [
994
+ q,
995
+ z,
996
+ W
997
+ ]), te = L ? "Make this block punchier, more concise, friendlier…" : "What do you want to build?", Y = i.length === 0 && z === "idle", X = z === "loading", Z = !!d.trim(), Q = X && !d.trim(), $ = /* @__PURE__ */ (0, y.jsxs)(y.Fragment, { children: [
998
+ /* @__PURE__ */ (0, y.jsxs)("div", {
999
+ style: {
1000
+ ...w.composer,
1001
+ ...v ? w.composerFocused : {}
1002
+ },
1003
+ children: [/* @__PURE__ */ (0, y.jsx)("textarea", {
1004
+ ref: O,
1005
+ rows: 2,
1006
+ value: d,
1007
+ onChange: (e) => f(e.target.value),
1008
+ onKeyDown: J,
1009
+ onFocus: () => D(!0),
1010
+ onBlur: () => D(!1),
1011
+ placeholder: te,
1012
+ maxLength: 2e3,
1013
+ style: w.textarea,
1014
+ autoFocus: Y
1015
+ }), /* @__PURE__ */ (0, y.jsxs)("div", {
1016
+ style: w.actionsRow,
1017
+ children: [
1018
+ /* @__PURE__ */ (0, y.jsx)("button", {
1019
+ type: "button",
1020
+ "aria-label": g ? "Hide source attachments" : "Attach a source document or URL",
1021
+ title: "Attach source",
1022
+ onClick: () => _((e) => !e),
1023
+ style: {
1024
+ ...w.iconButton,
1025
+ ...g ? w.iconButtonActive : {}
1026
+ },
1027
+ children: /* @__PURE__ */ (0, y.jsx)(T, {})
1028
+ }),
1029
+ d.trim().length > 0 && /* @__PURE__ */ (0, y.jsx)("span", {
1030
+ "aria-label": `Detected mode: ${S[R]}`,
1031
+ title: "The AI inferred what you want to do from your prompt.",
1032
+ style: w.modeHint,
1033
+ children: S[R]
1034
+ }),
1035
+ /* @__PURE__ */ (0, y.jsx)("button", {
1036
+ type: "button",
1037
+ "aria-label": Q ? "Cancel generation" : X ? "Queue prompt" : "Send prompt",
1038
+ title: X && d.trim() ? "Will send when the current turn finishes" : void 0,
1039
+ onClick: Q ? () => {
1040
+ W(), I.current?.abort();
1041
+ } : q,
1042
+ disabled: !Q && !Z,
1043
+ style: {
1044
+ ...w.sendButton,
1045
+ ...!Q && !Z ? w.sendButtonDisabled : {}
1046
+ },
1047
+ children: Q ? "×" : /* @__PURE__ */ (0, y.jsx)(E, {})
1048
+ })
1049
+ ]
1050
+ })]
1051
+ }),
1052
+ g && /* @__PURE__ */ (0, y.jsx)("div", {
1053
+ style: w.attachPanel,
1054
+ children: /* @__PURE__ */ (0, y.jsx)(b, {
1055
+ hostKind: e.hostKind,
1056
+ hostId: e.hostId,
1057
+ targetId: e.targetId,
1058
+ attached: p,
1059
+ onAttach: (e) => h((t) => [...t, e]),
1060
+ onRemove: (e) => h((t) => t.filter((t) => t.doc_id !== e))
1061
+ })
1062
+ }),
1063
+ p.length > 0 && /* @__PURE__ */ (0, y.jsx)("div", {
1064
+ style: w.attachedRow,
1065
+ children: p.map((e) => /* @__PURE__ */ (0, y.jsxs)("span", {
1066
+ style: w.chip,
1067
+ children: [/* @__PURE__ */ (0, y.jsx)("span", {
1068
+ style: w.chipName,
1069
+ title: e.filename,
1070
+ children: e.filename
1071
+ }), /* @__PURE__ */ (0, y.jsx)("button", {
1072
+ type: "button",
1073
+ "aria-label": `Remove ${e.filename}`,
1074
+ onClick: () => h((t) => t.filter((t) => t.doc_id !== e.doc_id)),
1075
+ style: w.chipRemove,
1076
+ children: "×"
1077
+ })]
1078
+ }, e.doc_id))
1079
+ })
1080
+ ] });
1081
+ return Y ? /* @__PURE__ */ (0, y.jsxs)("div", {
1082
+ style: w.rootInitial,
1083
+ role: "region",
1084
+ "aria-label": "AI copilot",
1085
+ children: [/* @__PURE__ */ (0, y.jsx)("style", { children: F }), /* @__PURE__ */ (0, y.jsx)("div", {
1086
+ style: w.footerInitial,
1087
+ children: $
1088
+ })]
1089
+ }) : /* @__PURE__ */ (0, y.jsxs)("div", {
1090
+ style: w.rootChat,
1091
+ role: "region",
1092
+ "aria-label": "AI copilot",
1093
+ children: [
1094
+ /* @__PURE__ */ (0, y.jsx)("style", { children: F }),
1095
+ /* @__PURE__ */ (0, y.jsxs)("div", {
1096
+ style: w.headerBar,
1097
+ children: [
1098
+ "AI ",
1099
+ e.hostKind === "newsletter" ? "newsletter" : "page",
1100
+ " builder"
1101
+ ]
1102
+ }),
1103
+ /* @__PURE__ */ (0, y.jsxs)("div", {
1104
+ style: w.messages,
1105
+ "aria-live": "polite",
1106
+ children: [
1107
+ i.map((e) => N(e)),
1108
+ s.map((e, t) => /* @__PURE__ */ (0, y.jsxs)("div", {
1109
+ style: {
1110
+ ...w.userBubble,
1111
+ opacity: .5
1112
+ },
1113
+ children: [e, /* @__PURE__ */ (0, y.jsx)("span", {
1114
+ style: {
1115
+ display: "block",
1116
+ fontSize: 11,
1117
+ opacity: .85,
1118
+ marginTop: 2
1119
+ },
1120
+ children: "queued"
1121
+ })]
1122
+ }, `queued-${t}`)),
1123
+ /* @__PURE__ */ (0, y.jsx)("div", { ref: M })
1124
+ ]
1125
+ }),
1126
+ /* @__PURE__ */ (0, y.jsx)("div", {
1127
+ style: w.footer,
1128
+ children: $
1129
+ })
1130
+ ]
1131
+ });
1132
+ }
1133
+ function N(e) {
1134
+ switch (e.kind) {
1135
+ case "user": return /* @__PURE__ */ (0, y.jsx)("div", {
1136
+ style: w.userBubble,
1137
+ children: e.text
1138
+ }, e.id);
1139
+ case "assistant": return /* @__PURE__ */ (0, y.jsx)("div", {
1140
+ style: w.assistantLine,
1141
+ children: e.text
1142
+ }, e.id);
1143
+ case "status": {
1144
+ let t = e.state === "pending" ? w.statusChipPending : e.state === "error" ? w.statusChipError : w.statusChipSuccess;
1145
+ return /* @__PURE__ */ (0, y.jsxs)("div", {
1146
+ style: {
1147
+ ...w.statusChipBase,
1148
+ ...t
1149
+ },
1150
+ children: [e.state === "pending" ? /* @__PURE__ */ (0, y.jsx)(O, {}) : e.state === "success" ? /* @__PURE__ */ (0, y.jsx)(D, {}) : null, /* @__PURE__ */ (0, y.jsx)("span", { children: e.label })]
1151
+ }, e.id);
1152
+ }
1153
+ case "meta": return /* @__PURE__ */ (0, y.jsxs)("div", {
1154
+ style: w.metaLine,
1155
+ children: [
1156
+ e.tokens.toLocaleString(),
1157
+ " tokens · $",
1158
+ e.cost_approx.toFixed(3),
1159
+ " ·",
1160
+ " ",
1161
+ (e.duration_ms / 1e3).toFixed(1),
1162
+ "s"
1163
+ ]
1164
+ }, e.id);
1165
+ }
1166
+ }
1167
+ function P(e, t) {
1168
+ let n = -1;
1169
+ for (let t = e.length - 1; t >= 0; t--) {
1170
+ let r = e[t];
1171
+ if (r && r.kind === "status" && r.state === "pending") {
1172
+ n = t;
1173
+ break;
1174
+ }
1175
+ }
1176
+ if (n === -1) return e;
1177
+ let r = e[n], i = {
1178
+ ...r,
1179
+ state: t.state,
1180
+ label: t.label ?? r.label
1181
+ };
1182
+ return [
1183
+ ...e.slice(0, n),
1184
+ i,
1185
+ ...e.slice(n + 1)
1186
+ ];
1187
+ }
1188
+ var F = "\n @keyframes ai-dot-blink {\n 0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }\n 40% { opacity: 1; transform: scale(1); }\n }\n";
1189
+ //#endregion
1190
+ //#region ../../../gatewaze-modules/modules/editor-ai-copilot/admin/components/aiPlugin.tsx
1191
+ function I() {
1192
+ let e = (0, l.useContext)(o);
1193
+ if (!e || !e.enabled) {
1194
+ let t = e?.disabledReason ?? "AI copilot is not enabled for this editor.";
1195
+ return /* @__PURE__ */ (0, y.jsx)("div", {
1196
+ style: {
1197
+ padding: 16,
1198
+ fontSize: 13,
1199
+ color: "var(--puck-color-grey-05)"
1200
+ },
1201
+ children: t
1202
+ });
1203
+ }
1204
+ return /* @__PURE__ */ (0, y.jsx)(M, {
1205
+ hostKind: e.hostKind,
1206
+ hostId: e.hostId,
1207
+ targetId: e.targetId,
1208
+ blockDefs: e.blockDefs
1209
+ });
1210
+ }
1211
+ function L() {
1212
+ return /* @__PURE__ */ (0, y.jsxs)("svg", {
1213
+ width: "24",
1214
+ height: "24",
1215
+ viewBox: "0 0 24 24",
1216
+ fill: "none",
1217
+ stroke: "currentColor",
1218
+ strokeWidth: "2",
1219
+ strokeLinecap: "round",
1220
+ strokeLinejoin: "round",
1221
+ "aria-hidden": "true",
1222
+ children: [
1223
+ /* @__PURE__ */ (0, y.jsx)("path", { d: "M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" }),
1224
+ /* @__PURE__ */ (0, y.jsx)("path", { d: "M20 3v4" }),
1225
+ /* @__PURE__ */ (0, y.jsx)("path", { d: "M22 5h-4" }),
1226
+ /* @__PURE__ */ (0, y.jsx)("path", { d: "M4 17v2" }),
1227
+ /* @__PURE__ */ (0, y.jsx)("path", { d: "M5 18H3" })
1228
+ ]
1229
+ });
1230
+ }
1231
+ var R = {
1232
+ name: "editor-ai-copilot",
1233
+ label: "AI",
1234
+ icon: /* @__PURE__ */ (0, y.jsx)(L, {}),
1235
+ render: () => /* @__PURE__ */ (0, y.jsx)(I, {})
1236
+ }, z = /* @__PURE__ */ t({ aiPlugin: () => R });
1237
+ s(R);
1238
+ //#endregion
1239
+ export { z as t };