@productmaker/mcp 12.36.1 → 12.44.5

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.
@@ -8,9 +8,41 @@
8
8
  <style>
9
9
  :root {
10
10
  color-scheme: light dark;
11
- font-family: Inter, ui-sans-serif, system-ui, sans-serif;
12
- color: #202635;
13
- background: #fff;
11
+ font-family:
12
+ system-ui,
13
+ -apple-system,
14
+ sans-serif;
15
+ --surface: #fff;
16
+ --muted-surface: #f0f4f8;
17
+ --text: #172033;
18
+ --muted: #536079;
19
+ --line: #d7deea;
20
+ --accent: #5b4ef5;
21
+ --accent-text: #4638dc;
22
+ color: var(--text);
23
+ background: var(--surface);
24
+ }
25
+ :root[data-theme="light"] {
26
+ color-scheme: light;
27
+ }
28
+ :root[data-theme="dark"] {
29
+ color-scheme: dark;
30
+ }
31
+ @media (prefers-color-scheme: dark) {
32
+ :root:not([data-theme]) {
33
+ color-scheme: dark;
34
+ }
35
+ }
36
+ @supports (color: light-dark(white, black)) {
37
+ :root {
38
+ --surface: light-dark(#fff, #171c2b);
39
+ --muted-surface: light-dark(#f0f4f8, #202638);
40
+ --text: light-dark(#172033, #f3f5fb);
41
+ --muted: light-dark(#536079, #a8b0c2);
42
+ --line: light-dark(#d7deea, #343c50);
43
+ --accent: light-dark(#5b4ef5, #8c83ff);
44
+ --accent-text: light-dark(#4638dc, #a59eff);
45
+ }
14
46
  }
15
47
  * {
16
48
  box-sizing: border-box;
@@ -23,6 +55,9 @@
23
55
  margin: auto;
24
56
  padding: 18px;
25
57
  }
58
+ main:not([data-state="ready"]) {
59
+ display: none;
60
+ }
26
61
  h1 {
27
62
  margin: 0 0 12px;
28
63
  font-size: 18px;
@@ -30,7 +65,7 @@
30
65
  }
31
66
  #status {
32
67
  margin: 0;
33
- color: #657083;
68
+ color: var(--muted);
34
69
  font-size: 14px;
35
70
  line-height: 1.5;
36
71
  }
@@ -38,6 +73,154 @@
38
73
  display: grid;
39
74
  gap: 18px;
40
75
  }
76
+ .format-picker {
77
+ display: flex;
78
+ flex-wrap: wrap;
79
+ gap: 16px;
80
+ border-bottom: 1px solid var(--line);
81
+ }
82
+ .format-picker button {
83
+ min-height: 44px;
84
+ padding: 6px 3px;
85
+ border: 0;
86
+ border-bottom: 2px solid transparent;
87
+ color: var(--muted);
88
+ background: transparent;
89
+ font: inherit;
90
+ font-weight: 620;
91
+ cursor: pointer;
92
+ }
93
+ .format-picker button[aria-pressed="true"] {
94
+ color: var(--accent-text);
95
+ border-bottom-color: var(--accent);
96
+ }
97
+ .media-panel {
98
+ display: grid;
99
+ gap: 12px;
100
+ min-width: 0;
101
+ }
102
+ .asset-toolbar {
103
+ display: grid;
104
+ grid-template-columns: minmax(0, 1fr) auto;
105
+ align-items: center;
106
+ gap: 8px;
107
+ }
108
+ .asset-picker,
109
+ .asset-download {
110
+ min-width: 0;
111
+ min-height: 44px;
112
+ padding: 8px 10px;
113
+ border: 1px solid var(--line);
114
+ border-radius: 9px;
115
+ background: var(--surface);
116
+ color: var(--text);
117
+ font: inherit;
118
+ font-size: 14px;
119
+ font-weight: 620;
120
+ }
121
+ .asset-download {
122
+ display: inline-flex;
123
+ align-items: center;
124
+ gap: 7px;
125
+ text-decoration: none;
126
+ }
127
+ .asset-download:hover,
128
+ .asset-picker:hover {
129
+ background: var(--muted-surface);
130
+ }
131
+ .landing-archive {
132
+ justify-self: start;
133
+ }
134
+ .asset-options {
135
+ display: flex;
136
+ flex-wrap: wrap;
137
+ gap: 6px;
138
+ }
139
+ .asset-choice,
140
+ .landing-edit-options button {
141
+ min-height: 44px;
142
+ max-width: 100%;
143
+ padding: 6px 10px;
144
+ border: 1px solid var(--line);
145
+ border-radius: 9px;
146
+ background: var(--surface);
147
+ color: var(--text);
148
+ font: inherit;
149
+ font-size: 14px;
150
+ cursor: pointer;
151
+ }
152
+ .asset-choice[aria-pressed="true"],
153
+ .landing-edit-options button[aria-pressed="true"] {
154
+ border-color: var(--accent);
155
+ color: var(--accent-text);
156
+ background: var(--muted-surface);
157
+ }
158
+ .landing-edit {
159
+ display: grid;
160
+ gap: 12px;
161
+ margin-top: 8px;
162
+ }
163
+ .landing-edit-options {
164
+ display: grid;
165
+ grid-template-columns: repeat(3, minmax(0, 1fr));
166
+ gap: 8px;
167
+ }
168
+ .landing-edit-options button {
169
+ min-height: 48px;
170
+ padding: 8px;
171
+ line-height: 1.3;
172
+ }
173
+ .landing-edit h2 {
174
+ margin: 0;
175
+ font-size: 15px;
176
+ }
177
+ .landing-edit p {
178
+ margin: 0;
179
+ }
180
+ .asset-download::before {
181
+ content: "";
182
+ width: 16px;
183
+ height: 16px;
184
+ background: currentColor;
185
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v12m-4-4 4 4 4-4M5 17v3h14v-3'/%3E%3C/svg%3E")
186
+ center / contain no-repeat;
187
+ }
188
+ .asset-stage figure {
189
+ padding: 8px;
190
+ border-radius: 12px;
191
+ background: var(--muted-surface);
192
+ }
193
+ .asset-stage video,
194
+ .asset-stage img {
195
+ width: auto;
196
+ max-width: 100%;
197
+ max-height: 380px;
198
+ margin: auto;
199
+ }
200
+ .media-panel[data-format="landing"] {
201
+ width: min(100%, 400px);
202
+ margin-inline: auto;
203
+ gap: 12px;
204
+ }
205
+ .landing-status {
206
+ margin: 0;
207
+ color: var(--muted);
208
+ font-size: 13px;
209
+ }
210
+ .landing-preview {
211
+ border: 1px solid var(--line);
212
+ border-radius: 10px;
213
+ overflow: hidden;
214
+ }
215
+ .landing-preview img {
216
+ border-radius: 0;
217
+ max-height: none;
218
+ height: auto;
219
+ }
220
+ .landing-preview .fallback {
221
+ margin: 0;
222
+ padding: 10px 12px;
223
+ }
41
224
  figure {
42
225
  margin: 0;
43
226
  min-width: 0;
@@ -49,27 +232,24 @@
49
232
  max-height: 640px;
50
233
  object-fit: contain;
51
234
  border-radius: 12px;
52
- background: #f3f4f6;
235
+ background: var(--muted-surface);
53
236
  }
54
- img[hidden],
55
- video[hidden],
56
- p[hidden] {
237
+ [hidden] {
57
238
  display: none;
58
239
  }
59
- figcaption {
60
- margin-top: 9px;
61
- font-size: 13px;
62
- }
63
240
  a {
64
- color: #5140cf;
241
+ color: var(--accent-text);
65
242
  text-underline-offset: 3px;
66
243
  }
67
- a:focus-visible {
68
- outline: 2px solid currentColor;
244
+ a:focus-visible,
245
+ button:focus-visible,
246
+ select:focus-visible,
247
+ summary:focus-visible {
248
+ outline: 2px solid var(--accent);
69
249
  outline-offset: 4px;
70
250
  }
71
251
  .fallback {
72
- color: #657083;
252
+ color: var(--muted);
73
253
  line-height: 1.5;
74
254
  font-size: 14px;
75
255
  }
@@ -83,29 +263,19 @@
83
263
  padding: 12px;
84
264
  }
85
265
  }
86
- @media (prefers-color-scheme: dark) {
87
- :root {
88
- color: #f2f4f8;
89
- background: #17191f;
90
- }
91
- #status,
92
- .fallback {
93
- color: #b5becd;
94
- }
95
- img,
96
- video {
97
- background: #222630;
98
- }
99
- a {
100
- color: #b6aaff;
266
+ @media (max-width: 340px) {
267
+ .landing-edit-options {
268
+ grid-template-columns: 1fr;
101
269
  }
102
270
  }
103
271
  </style>
104
272
  </head>
105
273
  <body>
106
274
  <main data-testid="task-results-root" data-state="loading" aria-busy="true">
107
- <h1>Your creative</h1>
108
- <p id="status" role="status" aria-live="polite">Loading your result…</p>
275
+ <h1 data-copy="title">Your creative</h1>
276
+ <p id="status" role="status" aria-live="polite" data-copy="loading">
277
+ Loading your result…
278
+ </p>
109
279
  <div id="media"></div>
110
280
  </main>
111
281
  <script>
@@ -115,6 +285,100 @@
115
285
  const root = document.querySelector("main");
116
286
  const status = document.getElementById("status");
117
287
  const media = document.getElementById("media");
288
+ const copy = {
289
+ en: {
290
+ title: "Your creative",
291
+ loading: "Loading your result…",
292
+ pending:
293
+ "Your creative is still being prepared. Ask in the chat to check its progress.",
294
+ awaitingReview:
295
+ "Your approval is needed. Reply in the chat to continue.",
296
+ taskError:
297
+ "This task couldn't deliver a result. Ask in the chat to check its status.",
298
+ resultError:
299
+ "We couldn't load this result. Ask in the chat to show it again.",
300
+ empty:
301
+ "No preview is available here. Your result can still be opened in ProductMaker.",
302
+ formats: "Creative formats",
303
+ image: "Image",
304
+ video: "Video",
305
+ chooseImage: "Choose an image",
306
+ chooseVideo: "Choose a video",
307
+ download: "Download",
308
+ landingEdit: "What would you like to change?",
309
+ landingEditSection: "Edit a section",
310
+ landingAddImage: "Add an image",
311
+ landingAddGif: "Add a GIF",
312
+ landingSectionPrompt:
313
+ "Reply in the chat: tell ProductMaker which section you want to change and what you want it to say or show.",
314
+ landingImagePrompt:
315
+ "Reply in the chat: tell ProductMaker what image you want to add and where it should go.",
316
+ landingGifPrompt:
317
+ "Reply in the chat: tell ProductMaker what the GIF should show and where it should go.",
318
+ landing: "Page",
319
+ downloadImage: "Download image",
320
+ downloadVideo: "Download video",
321
+ downloadImages: "Download images",
322
+ archiveUnavailable:
323
+ "This download is unavailable. Ask in the chat to reopen the result.",
324
+ openResult: "Open result",
325
+ previewError:
326
+ "Preview unavailable. Ask in the chat for a fresh link, or try the download link.",
327
+ sectionError:
328
+ "This section couldn't load. Ask in the chat to show it again.",
329
+ draft: "Draft · Unpublished",
330
+ published: "Published",
331
+ scriptRewritten:
332
+ "This video uses a revised script instead of the one you approved.",
333
+ },
334
+ es: {
335
+ title: "Tus creativos",
336
+ loading: "Cargando tu resultado…",
337
+ pending:
338
+ "Tu creativo sigue en preparación. Pide una actualización en el chat.",
339
+ awaitingReview:
340
+ "Falta tu aprobación. Responde en el chat para continuar.",
341
+ taskError:
342
+ "La tarea no pudo entregar un resultado. Pide revisar el estado en el chat.",
343
+ resultError:
344
+ "No pudimos cargar el resultado. Pide que lo muestren de nuevo en el chat.",
345
+ empty:
346
+ "Aquí no hay vista previa. Puedes abrir el resultado en ProductMaker.",
347
+ formats: "Formatos de los creativos",
348
+ image: "Imagen",
349
+ video: "Video",
350
+ chooseImage: "Elige una imagen",
351
+ chooseVideo: "Elige un video",
352
+ download: "Descargar",
353
+ landingEdit: "¿Qué quieres cambiar de tu página?",
354
+ landingEditSection: "Editar una sección",
355
+ landingAddImage: "Agregar una imagen",
356
+ landingAddGif: "Agregar un GIF",
357
+ landingSectionPrompt:
358
+ "Responde en el chat: dile a ProductMaker qué sección quieres cambiar y qué debería decir o mostrar.",
359
+ landingImagePrompt:
360
+ "Responde en el chat: dile a ProductMaker qué imagen quieres agregar y en qué parte de la página.",
361
+ landingGifPrompt:
362
+ "Responde en el chat: dile a ProductMaker qué debería mostrar el GIF y en qué parte de la página.",
363
+ landing: "Página",
364
+ downloadImage: "Descargar imagen",
365
+ downloadVideo: "Descargar video",
366
+ downloadImages: "Descargar imágenes",
367
+ archiveUnavailable:
368
+ "La descarga no está disponible. Pide en el chat que vuelva a abrir el resultado.",
369
+ openResult: "Abrir resultado",
370
+ previewError:
371
+ "No se pudo cargar la vista previa. Pide un enlace nuevo en el chat o prueba descargar el archivo.",
372
+ sectionError:
373
+ "No se pudo cargar esta sección. Pide que la muestren de nuevo en el chat.",
374
+ draft: "Borrador · Sin publicar",
375
+ published: "Publicada",
376
+ scriptRewritten:
377
+ "Este video usa un guion distinto al que aprobaste.",
378
+ },
379
+ };
380
+ let locale = "en";
381
+ let resultLocale;
118
382
  let receivedResult = false;
119
383
  let hostReady = false;
120
384
  let initializationSettled = false;
@@ -122,6 +386,40 @@
122
386
  const initializeRequestId = 1;
123
387
  const isRecord = (value) =>
124
388
  value !== null && typeof value === "object" && !Array.isArray(value);
389
+ const text = (node, key) => {
390
+ node.dataset.copy = key;
391
+ const ordinal = node.dataset.copyOrdinal;
392
+ const detail = node.dataset.copyDetail;
393
+ const label = ordinal
394
+ ? `${copy[locale][key]} ${ordinal}`
395
+ : copy[locale][key];
396
+ node.textContent = detail ? `${label} · ${detail}` : label;
397
+ };
398
+ function setHostContext(context) {
399
+ if (!isRecord(context)) return;
400
+ if (context.theme === "light" || context.theme === "dark")
401
+ document.documentElement.dataset.theme = context.theme;
402
+ if (!resultLocale && typeof context.locale === "string")
403
+ setLocale(/^es(?:-|$)/i.test(context.locale) ? "es" : "en");
404
+ }
405
+ function setLocale(next) {
406
+ if (next === locale) return;
407
+ locale = next;
408
+ document.documentElement.lang = locale;
409
+ document.title = `${copy[locale].title} · ProductMaker`;
410
+ root.querySelectorAll("[data-copy]").forEach((node) => {
411
+ text(node, node.dataset.copy);
412
+ });
413
+ root.querySelectorAll("[data-copy-label]").forEach((node) => {
414
+ node.setAttribute(
415
+ "aria-label",
416
+ copy[locale][node.dataset.copyLabel],
417
+ );
418
+ });
419
+ root.querySelectorAll("[data-copy-alt]").forEach((node) => {
420
+ node.setAttribute("alt", copy[locale][node.dataset.copyAlt]);
421
+ });
422
+ }
125
423
  const resultStates = new Set([
126
424
  "ready",
127
425
  "empty",
@@ -158,13 +456,13 @@
158
456
  if (typeof window.openai?.notifyIntrinsicHeight === "function")
159
457
  window.openai.notifyIntrinsicHeight(height);
160
458
  };
161
- function cleanupMedia() {
162
- media.querySelectorAll("video").forEach((video) => {
459
+ function cleanupMedia(container = media) {
460
+ container.querySelectorAll("video").forEach((video) => {
163
461
  video.pause();
164
462
  video.removeAttribute("src");
165
463
  video.load();
166
464
  });
167
- media.replaceChildren();
465
+ container.replaceChildren();
168
466
  }
169
467
  function setState(state, message) {
170
468
  root.dataset.state = state;
@@ -172,7 +470,11 @@
172
470
  "aria-busy",
173
471
  state === "loading" ? "true" : "false",
174
472
  );
175
- status.textContent = message;
473
+ if (message) text(status, message);
474
+ else {
475
+ delete status.dataset.copy;
476
+ status.textContent = "";
477
+ }
176
478
  status.hidden = !message;
177
479
  cleanupMedia();
178
480
  }
@@ -185,23 +487,27 @@
185
487
  link.dataset.testid = testId;
186
488
  return link;
187
489
  }
188
- function addMedia(item, kind, index) {
490
+ function renderMedia(item, kind, index, landing = false) {
189
491
  const figure = document.createElement("figure");
190
492
  const element = document.createElement(kind);
191
493
  element.src = item.url;
192
- element.dataset.testid = `task-results-${kind}-${index}`;
193
- if (kind === "img")
194
- element.alt =
195
- typeof item.alt === "string"
196
- ? item.alt.slice(0, 160)
197
- : "Ad creative";
198
- else {
199
- element.setAttribute(
200
- "aria-label",
201
- typeof item.label === "string"
202
- ? item.label.slice(0, 120)
203
- : "ProductMaker video",
204
- );
494
+ element.dataset.testid = `task-results-${landing ? "landing-section" : kind}-${index}`;
495
+ if (kind === "img") {
496
+ if (typeof item.alt === "string")
497
+ element.alt = item.alt.slice(0, 160);
498
+ else {
499
+ const key = landing ? "landing" : "image";
500
+ element.dataset.copyAlt = key;
501
+ element.alt = copy[locale][key];
502
+ }
503
+ element.loading = "lazy";
504
+ } else {
505
+ if (typeof item.label === "string")
506
+ element.setAttribute("aria-label", item.label.slice(0, 120));
507
+ else {
508
+ element.dataset.copyLabel = "video";
509
+ element.setAttribute("aria-label", copy[locale].video);
510
+ }
205
511
  element.controls = true;
206
512
  element.preload = "metadata";
207
513
  element.playsInline = true;
@@ -209,8 +515,7 @@
209
515
  const fallback = document.createElement("p");
210
516
  fallback.className = "fallback";
211
517
  fallback.hidden = true;
212
- fallback.textContent =
213
- "Preview unavailable. Ask ChatGPT to show it again for a fresh link, or try the download link.";
518
+ text(fallback, landing ? "sectionError" : "previewError");
214
519
  element.addEventListener("error", () => {
215
520
  element.hidden = true;
216
521
  fallback.hidden = false;
@@ -218,23 +523,226 @@
218
523
  });
219
524
  element.addEventListener("load", reportSize);
220
525
  element.addEventListener("loadedmetadata", reportSize);
221
- const caption = document.createElement("figcaption");
222
- caption.append(
223
- download(
224
- item.url,
225
- kind === "img" ? "Download image" : "Download video",
226
- `task-results-download-${kind}-${index}`,
227
- ),
228
- );
229
- figure.append(element, fallback, caption);
526
+ figure.append(element, fallback);
230
527
  if (kind === "video" && item.scriptRewritten === true) {
231
528
  const warning = document.createElement("p");
232
529
  warning.dataset.testid = `task-results-script-warning-${index}`;
233
- warning.textContent =
234
- "This video uses a revised script instead of the one you approved.";
530
+ text(warning, "scriptRewritten");
235
531
  figure.append(warning);
236
532
  }
237
- media.append(figure);
533
+ return figure;
534
+ }
535
+ function renderLandingDownload(value) {
536
+ let url;
537
+ try {
538
+ const candidate = typeof value === "string" && new URL(value);
539
+ if (
540
+ candidate &&
541
+ candidate.origin === assetOrigin &&
542
+ !candidate.username &&
543
+ !candidate.password &&
544
+ /^\/landing-archives\/[\w.-]+\/landing-images\.zip$/.test(
545
+ candidate.pathname,
546
+ )
547
+ ) {
548
+ url = candidate.href;
549
+ }
550
+ } catch {
551
+ // The results app can only download an archive on its asset proxy.
552
+ }
553
+ if (!url) {
554
+ const unavailable = document.createElement("p");
555
+ unavailable.className = "fallback";
556
+ text(unavailable, "archiveUnavailable");
557
+ return unavailable;
558
+ }
559
+ const link = download(url, "", "task-results-landing-download");
560
+ link.className = "asset-download landing-archive";
561
+ text(link, "downloadImages");
562
+ return link;
563
+ }
564
+ function renderSelectedMedia(panel, kind, items) {
565
+ const toolbar = document.createElement("div");
566
+ toolbar.className = "asset-toolbar";
567
+ const stage = document.createElement("div");
568
+ stage.className = "asset-stage";
569
+ const label = kind === "video" ? "video" : "image";
570
+ const pickerLabel = kind === "video" ? "chooseVideo" : "chooseImage";
571
+ const downloadLabel =
572
+ kind === "video" ? "downloadVideo" : "downloadImage";
573
+ const showChoices = items.length > 1 && items.length <= 3;
574
+ const title = document.createElement(
575
+ showChoices ? "div" : items.length > 1 ? "select" : "span",
576
+ );
577
+ const choices = [];
578
+ if (title instanceof HTMLSelectElement) {
579
+ title.className = "asset-picker";
580
+ title.dataset.testid = `task-results-asset-picker-${kind}`;
581
+ title.dataset.copyLabel = pickerLabel;
582
+ title.setAttribute("aria-label", copy[locale][pickerLabel]);
583
+ items.forEach((_, index) => {
584
+ const option = document.createElement("option");
585
+ option.value = String(index);
586
+ option.dataset.copyOrdinal = String(index + 1);
587
+ text(option, label);
588
+ title.append(option);
589
+ });
590
+ title.addEventListener("change", () => show(Number(title.value)));
591
+ } else if (showChoices) {
592
+ title.className = "asset-options";
593
+ title.setAttribute("role", "group");
594
+ title.dataset.copyLabel = pickerLabel;
595
+ title.setAttribute("aria-label", copy[locale][pickerLabel]);
596
+ items.forEach((item, index) => {
597
+ const choice = document.createElement("button");
598
+ choice.type = "button";
599
+ choice.className = "asset-choice";
600
+ choice.dataset.testid = `task-results-${kind}-choice-${index}`;
601
+ choice.dataset.copyOrdinal = String(index + 1);
602
+ if (
603
+ typeof item.selectionLabel === "string" &&
604
+ item.selectionLabel.trim()
605
+ ) {
606
+ choice.dataset.copyDetail = item.selectionLabel
607
+ .trim()
608
+ .slice(0, 80);
609
+ }
610
+ text(choice, label);
611
+ choice.addEventListener("click", () => show(index));
612
+ choices.push(choice);
613
+ title.append(choice);
614
+ });
615
+ } else {
616
+ text(title, label);
617
+ }
618
+ const link = download(items[0].url, "", "");
619
+ link.className = "asset-download";
620
+ link.dataset.copyLabel = downloadLabel;
621
+ link.setAttribute("aria-label", copy[locale][downloadLabel]);
622
+ text(link, "download");
623
+ toolbar.append(title, link);
624
+ panel.append(toolbar, stage);
625
+ let selected;
626
+ function show(index) {
627
+ const item = items[index];
628
+ if (!item || index === selected) return;
629
+ selected = index;
630
+ choices.forEach((choice, position) =>
631
+ choice.setAttribute("aria-pressed", String(index === position)),
632
+ );
633
+ cleanupMedia(stage);
634
+ link.href = item.url;
635
+ link.dataset.testid = `task-results-download-${kind}-${index}`;
636
+ stage.append(renderMedia(item, kind, index));
637
+ reportSize();
638
+ }
639
+ show(0);
640
+ }
641
+ function renderLandingEditChoices() {
642
+ const section = document.createElement("section");
643
+ section.className = "landing-edit";
644
+ const title = document.createElement("h2");
645
+ title.id = "task-results-landing-edit-title";
646
+ text(title, "landingEdit");
647
+ const options = document.createElement("div");
648
+ options.className = "landing-edit-options";
649
+ options.setAttribute("role", "group");
650
+ options.setAttribute("aria-labelledby", title.id);
651
+ const prompt = document.createElement("p");
652
+ prompt.className = "fallback";
653
+ prompt.id = "task-results-landing-edit-prompt";
654
+ prompt.dataset.testid = prompt.id;
655
+ prompt.setAttribute("aria-live", "polite");
656
+ prompt.hidden = true;
657
+ for (const [label, instruction] of [
658
+ ["landingEditSection", "landingSectionPrompt"],
659
+ ["landingAddImage", "landingImagePrompt"],
660
+ ["landingAddGif", "landingGifPrompt"],
661
+ ]) {
662
+ const option = document.createElement("button");
663
+ option.type = "button";
664
+ option.dataset.testid = `task-results-${label}`;
665
+ option.setAttribute("aria-controls", prompt.id);
666
+ option.setAttribute("aria-pressed", "false");
667
+ text(option, label);
668
+ option.addEventListener("click", () => {
669
+ for (const button of options.children)
670
+ button.setAttribute("aria-pressed", String(button === option));
671
+ text(prompt, instruction);
672
+ prompt.hidden = false;
673
+ reportSize();
674
+ });
675
+ options.append(option);
676
+ }
677
+ section.append(title, options, prompt);
678
+ return section;
679
+ }
680
+ function renderLanding(panel, items, landingStatus, archiveUrl) {
681
+ const label = document.createElement("p");
682
+ label.className = "landing-status";
683
+ label.dataset.testid = "task-results-landing-status";
684
+ text(label, landingStatus === "published" ? "published" : "draft");
685
+ const preview = document.createElement("div");
686
+ preview.className = "landing-preview";
687
+ items.forEach((item, index) => {
688
+ preview.append(renderMedia(item, "img", index, true));
689
+ });
690
+ panel.append(
691
+ label,
692
+ preview,
693
+ renderLandingEditChoices(),
694
+ renderLandingDownload(archiveUrl),
695
+ );
696
+ }
697
+ function renderFormats(formats, landingStatus, archiveUrl) {
698
+ const available = formats.filter(({ items }) => items.length);
699
+ const picker = document.createElement("div");
700
+ picker.className = "format-picker";
701
+ picker.dataset.testid = "task-results-tabs";
702
+ picker.dataset.copyLabel = "formats";
703
+ picker.setAttribute("role", "group");
704
+ picker.setAttribute("aria-label", copy[locale].formats);
705
+ if (available.length > 1) media.append(picker);
706
+ const selections = [];
707
+ const select = (selected) => {
708
+ selections.forEach(({ choice, panel }) => {
709
+ panel.hidden = panel !== selected;
710
+ choice.setAttribute("aria-pressed", String(!panel.hidden));
711
+ if (panel.hidden)
712
+ panel
713
+ .querySelectorAll("video")
714
+ .forEach((video) => video.pause());
715
+ });
716
+ reportSize();
717
+ };
718
+ available.forEach(({ format, items }, index) => {
719
+ const panel = document.createElement("section");
720
+ panel.id = `task-results-panel-${format}`;
721
+ panel.dataset.testid = panel.id;
722
+ panel.dataset.format = format;
723
+ panel.className = "media-panel";
724
+ panel.hidden = index !== 0;
725
+ if (format === "landing")
726
+ renderLanding(panel, items, landingStatus, archiveUrl);
727
+ else
728
+ renderSelectedMedia(
729
+ panel,
730
+ format === "video" ? "video" : "img",
731
+ items,
732
+ );
733
+ if (available.length > 1) {
734
+ const choice = document.createElement("button");
735
+ choice.type = "button";
736
+ choice.dataset.testid = `task-results-tab-${format}`;
737
+ choice.setAttribute("aria-controls", panel.id);
738
+ choice.setAttribute("aria-pressed", String(!panel.hidden));
739
+ text(choice, format);
740
+ choice.addEventListener("click", () => select(panel));
741
+ picker.append(choice);
742
+ selections.push({ choice, panel });
743
+ }
744
+ media.append(panel);
745
+ });
238
746
  }
239
747
  function entries(value) {
240
748
  return Array.isArray(value)
@@ -246,6 +754,7 @@
246
754
  url,
247
755
  alt: item.alt,
248
756
  label: item.label,
757
+ selectionLabel: item.selectionLabel,
249
758
  ...(item.scriptRewritten === true
250
759
  ? { scriptRewritten: true }
251
760
  : {}),
@@ -268,59 +777,67 @@
268
777
  !isRecord(data) ||
269
778
  !resultStates.has(data.state)
270
779
  ) {
271
- setState(
272
- "error",
273
- "We couldn't load this result. Ask ChatGPT to show it again.",
274
- );
780
+ setState("error", "resultError");
275
781
  reportSize();
276
782
  return;
277
783
  }
784
+ if (data.locale === "es" || data.locale === "en") {
785
+ resultLocale = data.locale;
786
+ setLocale(resultLocale);
787
+ }
278
788
  if (data.state === "awaiting_review") {
279
- setState(
280
- data.state,
281
- "Your approval is needed. Reply in the chat to continue.",
282
- );
789
+ setState(data.state, "awaitingReview");
283
790
  reportSize();
284
791
  return;
285
792
  }
286
793
  if (data.state === "pending" || data.state === "error") {
287
794
  setState(
288
795
  data.state,
289
- data.state === "pending"
290
- ? "Your creative is still being prepared. Ask ChatGPT to check its progress."
291
- : "This task couldn't deliver a result. Ask ChatGPT to check its status.",
796
+ data.state === "pending" ? "pending" : "taskError",
292
797
  );
293
798
  reportSize();
294
799
  return;
295
800
  }
296
801
  const images = entries(data.images);
297
802
  const videos = entries(data.videos);
298
- const links = entries(data.links);
803
+ const landing = entries(data.landingSections);
804
+ const shown = new Set(
805
+ [...images, ...videos, ...landing].map(({ url }) => url),
806
+ );
807
+ const links = entries(data.links).filter(
808
+ ({ url }) => !shown.has(url),
809
+ );
299
810
  if (
300
811
  data.state === "empty" ||
301
- !(images.length || videos.length || links.length)
812
+ !(images.length || videos.length || links.length || landing.length)
302
813
  ) {
303
- setState(
304
- "empty",
305
- "No preview is available here. Your result can still be opened in ProductMaker.",
306
- );
814
+ setState("empty", "empty");
307
815
  } else {
308
816
  setState("ready", "");
309
- images.forEach((item, index) => addMedia(item, "img", index));
310
- videos.forEach((item, index) => addMedia(item, "video", index));
817
+ renderFormats(
818
+ [
819
+ { format: "video", items: videos },
820
+ { format: "image", items: images },
821
+ { format: "landing", items: landing },
822
+ ],
823
+ data.landingStatus,
824
+ data.landingArchiveUrl,
825
+ );
311
826
  if (links.length) {
312
827
  const list = document.createElement("ul");
313
828
  links.forEach((item, index) => {
314
829
  const row = document.createElement("li");
315
- row.append(
316
- download(
317
- item.url,
318
- typeof item.label === "string"
319
- ? item.label.slice(0, 120)
320
- : "Open result",
321
- `task-results-link-${index}`,
322
- ),
830
+ const label =
831
+ typeof item.label === "string"
832
+ ? item.label.slice(0, 120)
833
+ : "";
834
+ const link = download(
835
+ item.url,
836
+ label,
837
+ `task-results-link-${index}`,
323
838
  );
839
+ if (!label) text(link, "openResult");
840
+ row.append(link);
324
841
  list.append(row);
325
842
  });
326
843
  media.append(list);
@@ -354,7 +871,9 @@
354
871
  resultStates.has(data.state) &&
355
872
  Array.isArray(data.images) &&
356
873
  Array.isArray(data.videos) &&
357
- Array.isArray(data.links)
874
+ Array.isArray(data.links) &&
875
+ (data.landingSections === undefined ||
876
+ Array.isArray(data.landingSections))
358
877
  );
359
878
  });
360
879
  // Globals can arrive before a result or with unrelated host updates.
@@ -413,9 +932,15 @@
413
932
  if (!receivedResult) applyResult({ isError: true });
414
933
  } else {
415
934
  hostReady = true;
935
+ setHostContext(message.result.hostContext);
416
936
  notify("ui/notifications/initialized", {});
417
937
  reportSize();
418
938
  }
939
+ } else if (
940
+ message.method === "ui/notifications/host-context-changed"
941
+ ) {
942
+ setHostContext(message.params);
943
+ reportSize();
419
944
  } else if (message.method === "ui/notifications/tool-result")
420
945
  applyResult(message.params);
421
946
  else if (message.method === "ui/notifications/tool-cancelled")
@@ -423,6 +948,7 @@
423
948
  }
424
949
  function handleGlobals(event) {
425
950
  const globals = event.detail?.globals;
951
+ setHostContext(globals);
426
952
  if (
427
953
  isRecord(globals) &&
428
954
  Object.prototype.hasOwnProperty.call(
@@ -454,6 +980,7 @@
454
980
  },
455
981
  "*",
456
982
  );
983
+ setHostContext(window.openai);
457
984
  applyOpenAiMetadata(window.openai?.toolResponseMetadata);
458
985
  })();
459
986
  </script>