@productmaker/mcp 12.36.0 → 12.44.4

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.
@@ -0,0 +1,952 @@
1
+ <!doctype html>
2
+ <html lang="es">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>ProductMaker</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: light dark;
10
+ --paper: #f6f8fb;
11
+ --control: #fff;
12
+ --ink: #172033;
13
+ --muted: #526079;
14
+ --border: #d7deea;
15
+ --accent: #5b4ef5;
16
+ --accent-ink: #fff;
17
+ --quiet: #eeecff;
18
+ }
19
+ @media (prefers-color-scheme: dark) {
20
+ :root:not([data-theme]) {
21
+ --paper: #171c2b;
22
+ --control: #202638;
23
+ --ink: #f3f5fb;
24
+ --muted: #a8b0c2;
25
+ --border: #343c50;
26
+ --accent: #8c83ff;
27
+ --accent-ink: #17132e;
28
+ --quiet: #292552;
29
+ }
30
+ }
31
+ :root[data-theme="dark"] {
32
+ color-scheme: dark;
33
+ --paper: #171c2b;
34
+ --control: #202638;
35
+ --ink: #f3f5fb;
36
+ --muted: #a8b0c2;
37
+ --border: #343c50;
38
+ --accent: #8c83ff;
39
+ --accent-ink: #17132e;
40
+ --quiet: #292552;
41
+ }
42
+ :root[data-theme="light"] {
43
+ color-scheme: light;
44
+ }
45
+ *,
46
+ *::before,
47
+ *::after {
48
+ box-sizing: border-box;
49
+ }
50
+ [hidden] {
51
+ display: none !important;
52
+ }
53
+ body {
54
+ margin: 0;
55
+ color: var(--ink);
56
+ background: transparent;
57
+ font: 1rem / 1.45 var(--font-sans, system-ui, -apple-system, sans-serif);
58
+ }
59
+ main {
60
+ padding: clamp(1rem, 4vw, 1.5rem);
61
+ border: 1px solid var(--border);
62
+ border-radius: 1rem;
63
+ background: var(--paper);
64
+ overflow-wrap: anywhere;
65
+ }
66
+ .byline {
67
+ display: flex;
68
+ flex-wrap: wrap;
69
+ align-items: baseline;
70
+ gap: 0.25rem 0.65rem;
71
+ margin-bottom: 0.7rem;
72
+ font-size: 0.875rem;
73
+ }
74
+ #stage,
75
+ #description,
76
+ #status {
77
+ color: var(--muted);
78
+ }
79
+ h1,
80
+ p {
81
+ margin: 0;
82
+ }
83
+ h1 {
84
+ font-size: clamp(1.25rem, 4vw, 1.6rem);
85
+ font-weight: 660;
86
+ line-height: 1.2;
87
+ letter-spacing: -0.025em;
88
+ }
89
+ #description {
90
+ margin-top: 0.45rem;
91
+ }
92
+ dl {
93
+ margin: 1rem 0 0;
94
+ }
95
+ dl div {
96
+ display: grid;
97
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
98
+ align-items: baseline;
99
+ gap: 0.6rem;
100
+ padding: 0.55rem 0;
101
+ border-top: 1px solid var(--border);
102
+ }
103
+ dt {
104
+ color: var(--muted);
105
+ }
106
+ dd {
107
+ margin: 0;
108
+ text-align: end;
109
+ font-weight: 650;
110
+ }
111
+ #actions {
112
+ margin-top: 1rem;
113
+ }
114
+ .approval-instruction {
115
+ color: var(--muted);
116
+ font-size: 0.875rem;
117
+ }
118
+ .approval-note {
119
+ margin: 0.4rem 0 0;
120
+ padding: 0.6rem 0.8rem;
121
+ border: 1px solid var(--border);
122
+ border-radius: 0.6rem;
123
+ background: var(--quiet);
124
+ font-weight: 650;
125
+ }
126
+ .choices {
127
+ display: grid;
128
+ gap: 0.5rem;
129
+ }
130
+ button,
131
+ select,
132
+ input {
133
+ font: inherit;
134
+ }
135
+ button {
136
+ min-height: 44px;
137
+ padding: 0.625rem 0.85rem;
138
+ border: 1px solid var(--border);
139
+ border-radius: 0.75rem;
140
+ background: var(--control);
141
+ color: inherit;
142
+ }
143
+ .choice-row {
144
+ display: grid;
145
+ grid-template-columns: minmax(0, 1fr) auto;
146
+ align-items: start;
147
+ gap: 0.5rem;
148
+ }
149
+ .choice-row > button:first-child:last-child,
150
+ .choice-row video {
151
+ grid-column: 1 / -1;
152
+ }
153
+ .choice-row video {
154
+ width: 100%;
155
+ max-height: 300px;
156
+ border-radius: 0.75rem;
157
+ background: var(--control);
158
+ }
159
+ .preview-trigger {
160
+ display: grid;
161
+ place-items: center;
162
+ padding: 0.25rem;
163
+ }
164
+ .preview-trigger img {
165
+ width: 52px;
166
+ height: 44px;
167
+ object-fit: cover;
168
+ border-radius: 0.4rem;
169
+ }
170
+ .choice {
171
+ text-align: start;
172
+ }
173
+ .choice strong {
174
+ font-weight: 650;
175
+ }
176
+ .choice span {
177
+ display: block;
178
+ font-size: 0.875rem;
179
+ }
180
+ .choice .choice-detail {
181
+ color: var(--muted);
182
+ margin-top: 0.15rem;
183
+ }
184
+ .choice .recommendation {
185
+ display: inline-block;
186
+ margin-inline-start: 0.6rem;
187
+ color: var(--accent);
188
+ font-size: 0.75rem;
189
+ font-weight: 680;
190
+ }
191
+ .choice.recommended {
192
+ border-color: var(--accent);
193
+ background: var(--quiet);
194
+ }
195
+ .primary {
196
+ background: var(--accent);
197
+ color: var(--accent-ink);
198
+ border-color: var(--accent);
199
+ font-weight: 650;
200
+ }
201
+ button:not(:disabled) {
202
+ cursor: pointer;
203
+ }
204
+ button:not(:disabled):hover {
205
+ border-color: var(--accent);
206
+ }
207
+ button:not(:disabled):active {
208
+ filter: brightness(0.94);
209
+ }
210
+ button:disabled {
211
+ cursor: default;
212
+ }
213
+ button:focus-visible,
214
+ select:focus-visible,
215
+ input:focus-visible {
216
+ outline: 2px solid var(--accent);
217
+ outline-offset: 2px;
218
+ }
219
+ form {
220
+ display: grid;
221
+ gap: 0.45rem;
222
+ }
223
+ form button {
224
+ justify-self: start;
225
+ margin-top: 0.25rem;
226
+ }
227
+ label {
228
+ font-weight: 650;
229
+ }
230
+ input,
231
+ select {
232
+ min-height: 44px;
233
+ width: 100%;
234
+ padding: 0.55rem 0.75rem;
235
+ border: 1px solid var(--border);
236
+ border-radius: 0.6rem;
237
+ color: inherit;
238
+ background: var(--control);
239
+ }
240
+ input::placeholder {
241
+ color: var(--muted);
242
+ opacity: 1;
243
+ }
244
+ #status {
245
+ margin-top: 0.75rem;
246
+ font-size: 0.875rem;
247
+ }
248
+ [data-state="sent"] #status,
249
+ [data-state="uncertain"] #status {
250
+ font-weight: 600;
251
+ }
252
+ #reply {
253
+ display: block;
254
+ margin-top: 0.35rem;
255
+ font-weight: 650;
256
+ white-space: pre-wrap;
257
+ }
258
+ [data-state="sending"] button,
259
+ [data-state="sent"] button,
260
+ [data-state="uncertain"] button {
261
+ opacity: 0.72;
262
+ }
263
+ </style>
264
+ </head>
265
+ <body>
266
+ <main data-testid="guided-step" data-state="loading" aria-busy="true">
267
+ <div class="byline">
268
+ <strong>ProductMaker</strong><span id="stage" hidden></span>
269
+ </div>
270
+ <h1 id="question" hidden></h1>
271
+ <p id="description" hidden></p>
272
+ <dl id="details" hidden></dl>
273
+ <div id="actions" hidden></div>
274
+ <p id="status" role="status" aria-live="polite">
275
+ Preparando el siguiente paso…
276
+ </p>
277
+ <output id="reply" hidden></output>
278
+ </main>
279
+ <script>
280
+ (() => {
281
+ "use strict";
282
+ const root = document.querySelector("main");
283
+ const question = document.getElementById("question");
284
+ const description = document.getElementById("description");
285
+ const stage = document.getElementById("stage");
286
+ const details = document.getElementById("details");
287
+ const actions = document.getElementById("actions");
288
+ const status = document.getElementById("status");
289
+ const reply = document.getElementById("reply");
290
+ const copy = {
291
+ es: {
292
+ loading: "Preparando el siguiente paso…",
293
+ unavailable:
294
+ "No se pudo mostrar el paso. Pide en el chat que te muestre la decisión pendiente.",
295
+ composer: "Puedes responder escribiendo en el chat.",
296
+ confirmInChat: "Para confirmar, escribe esta respuesta en el chat.",
297
+ unsupported: "Escribe tu respuesta en el chat para continuar.",
298
+ answer: "Mi respuesta",
299
+ requiredAnswer: "Escribe una respuesta para continuar.",
300
+ skipOptionalFields:
301
+ "Omito los campos opcionales de este formulario.",
302
+ sending: "Preparando tu respuesta…",
303
+ sent: "Respuesta enviada al chat.",
304
+ permission:
305
+ "Si el chat pide permiso, elige «Permitir una vez». Si cancelas, escribe tu respuesta en el chat:",
306
+ uncertain:
307
+ "No pude confirmar el envío. Revisa el chat antes de reenviar esta respuesta:",
308
+ recommended: "Recomendado",
309
+ submit: "Enviar respuesta",
310
+ },
311
+ en: {
312
+ loading: "Preparing the next step…",
313
+ unavailable:
314
+ "This step couldn't be displayed. Ask in the chat to see what needs your answer.",
315
+ composer: "You can also reply in the chat.",
316
+ confirmInChat: "To confirm, type this answer in the chat.",
317
+ unsupported: "Type your answer in the chat to continue.",
318
+ answer: "My answer",
319
+ requiredAnswer: "Enter an answer to continue.",
320
+ skipOptionalFields:
321
+ "I’m skipping the optional fields in this form.",
322
+ sending: "Preparing your answer…",
323
+ sent: "Answer sent to the chat.",
324
+ permission:
325
+ "If the chat asks for permission, select “Allow once”. If you cancel, type your answer in the chat:",
326
+ uncertain:
327
+ "I couldn't confirm delivery. Check the chat before sending this answer again:",
328
+ recommended: "Suggested",
329
+ submit: "Send answer",
330
+ },
331
+ };
332
+ const maxFormFields = 8;
333
+ const maxFieldLabelLength = 160;
334
+ const maxFieldTextLength = 600;
335
+ const maxStandaloneAnswerLength = 1200;
336
+ // Each line contains a label, ": ", and a value, plus a newline between lines.
337
+ const maxFormAnswerLength =
338
+ maxFormFields * (maxFieldLabelLength + maxFieldTextLength + 2) +
339
+ (maxFormFields - 1);
340
+ const isRecord = (data) =>
341
+ data !== null && typeof data === "object" && !Array.isArray(data);
342
+ const boundedText = (data, max) =>
343
+ typeof data === "string" && data.trim() && data.length <= max
344
+ ? data
345
+ : null;
346
+ let step = null;
347
+ let fingerprint = "";
348
+ let locale = "es";
349
+ let hostOrigin = "*";
350
+ let hostReady = false;
351
+ let textMessaging = false;
352
+ let initializationSettled = false;
353
+ let disposed = false;
354
+ let sentText = null;
355
+ let sendKind = null;
356
+ let sendState = "idle";
357
+ let sendTimer;
358
+ let sizingFrame;
359
+ const initializeId = "productmaker-step-init";
360
+ const messageId = "productmaker-step-answer";
361
+
362
+ function messageKind() {
363
+ if (!initializationSettled) return null;
364
+ if (hostReady && textMessaging) return "mcp";
365
+ return typeof window.openai?.sendFollowUpMessage === "function"
366
+ ? "openai"
367
+ : null;
368
+ }
369
+ function post(payload) {
370
+ if (!disposed)
371
+ window.parent.postMessage(
372
+ { jsonrpc: "2.0", ...payload },
373
+ hostOrigin,
374
+ );
375
+ }
376
+ function resize() {
377
+ if (disposed || sizingFrame !== undefined) return;
378
+ sizingFrame = requestAnimationFrame(() => {
379
+ sizingFrame = undefined;
380
+ const height = Math.ceil(root.getBoundingClientRect().height);
381
+ if (hostReady)
382
+ post({
383
+ method: "ui/notifications/size-changed",
384
+ params: { height },
385
+ });
386
+ else if (typeof window.openai?.notifyIntrinsicHeight === "function")
387
+ window.openai.notifyIntrinsicHeight(height);
388
+ });
389
+ }
390
+ function setHostContext(context) {
391
+ if (!isRecord(context)) return;
392
+ if (context.theme === "dark" || context.theme === "light")
393
+ document.documentElement.dataset.theme = context.theme;
394
+ if (!isRecord(context.styles?.variables)) return;
395
+ const styles = document.documentElement.style;
396
+ const font = context.styles.variables["--font-sans"];
397
+ if (
398
+ typeof font === "string" &&
399
+ font.length <= 200 &&
400
+ CSS.supports("font-family", font)
401
+ )
402
+ styles.setProperty("--font-sans", font);
403
+ resize();
404
+ }
405
+ function normalize(data) {
406
+ if (
407
+ !isRecord(data) ||
408
+ (data.flow !== "product" && data.flow !== "service")
409
+ )
410
+ return null;
411
+ const label = boundedText(data.stage, 160);
412
+ const title = boundedText(data.question, 160);
413
+ if (!label || !title) return null;
414
+ const rawOptions = Array.isArray(data.options)
415
+ ? data.options.slice(0, 6)
416
+ : [];
417
+ const items = rawOptions.flatMap((value) => {
418
+ const text = isRecord(value) ? boundedText(value.label, 160) : null;
419
+ return text
420
+ ? [
421
+ {
422
+ label: text,
423
+ description: boundedText(value.description, 600),
424
+ recommended: value.recommended === true,
425
+ preview:
426
+ typeof value.preview === "string" &&
427
+ /^[a-z0-9-]{1,48}$/.test(value.preview)
428
+ ? value.preview
429
+ : null,
430
+ },
431
+ ]
432
+ : [];
433
+ });
434
+ const fields = Array.isArray(data.details)
435
+ ? data.details.slice(0, 8)
436
+ : [];
437
+ const facts = fields.flatMap((value) => {
438
+ const name = isRecord(value) ? boundedText(value.label, 160) : null;
439
+ const text = isRecord(value) ? boundedText(value.value, 600) : null;
440
+ return name && text ? [{ label: name, value: text }] : [];
441
+ });
442
+ const field = isRecord(data.field)
443
+ ? boundedText(data.field.label, 160)
444
+ : null;
445
+ return {
446
+ flow: data.flow,
447
+ stage: label,
448
+ question: title,
449
+ description: boundedText(data.description, 600),
450
+ options: items,
451
+ field: field
452
+ ? {
453
+ label: field,
454
+ placeholder: boundedText(data.field.placeholder, 160),
455
+ }
456
+ : null,
457
+ form: Array.isArray(data.form?.fields)
458
+ ? data.form.fields
459
+ .slice(0, maxFormFields)
460
+ .filter(
461
+ (entry) =>
462
+ isRecord(entry) &&
463
+ boundedText(entry.label, maxFieldLabelLength) &&
464
+ typeof entry.key === "string" &&
465
+ /^[a-z][a-zA-Z0-9_]{0,39}$/.test(entry.key) &&
466
+ ["text", "number", "select"].includes(entry.kind),
467
+ )
468
+ : [],
469
+ details: facts,
470
+ actionLabel: boundedText(data.actionLabel, 160),
471
+ confirmation: isRecord(data.confirmation)
472
+ ? boundedText(data.confirmation.label, 160)
473
+ : null,
474
+ locale: data.locale === "en" ? "en" : "es",
475
+ };
476
+ }
477
+ function statusForState() {
478
+ const strings = copy[locale];
479
+ const showSelection =
480
+ sendState === "uncertain" ||
481
+ (sendState === "sent" && sendKind === "mcp");
482
+ const current = {
483
+ loading: strings.loading,
484
+ unavailable: strings.unavailable,
485
+ ready: messageKind() ? strings.composer : strings.unsupported,
486
+ sending: strings.sending,
487
+ sent: sendKind === "mcp" ? strings.permission : strings.sent,
488
+ uncertain: strings.uncertain,
489
+ };
490
+ const visibleState = step
491
+ ? sendState === "idle"
492
+ ? "ready"
493
+ : sendState
494
+ : unavailable
495
+ ? "unavailable"
496
+ : "loading";
497
+ root.dataset.state = visibleState;
498
+ root.setAttribute(
499
+ "aria-busy",
500
+ visibleState === "loading" || visibleState === "sending"
501
+ ? "true"
502
+ : "false",
503
+ );
504
+ status.hidden =
505
+ visibleState === "ready" && Boolean(step?.confirmation);
506
+ status.textContent = current[visibleState];
507
+ reply.textContent = showSelection ? sentText : "";
508
+ reply.hidden = !showSelection;
509
+ for (const control of actions.querySelectorAll(
510
+ "button:not([data-media-preview]), input, select",
511
+ )) {
512
+ control.disabled = sendState !== "idle" || !messageKind();
513
+ }
514
+ resize();
515
+ }
516
+ function dismissUnsentStep() {
517
+ if (sendState !== "idle") return;
518
+ step = null;
519
+ fingerprint = "";
520
+ unavailable = true;
521
+ for (const part of [stage, question, description, details, actions])
522
+ part.hidden = true;
523
+ actions.replaceChildren();
524
+ statusForState();
525
+ }
526
+ function receiveStep(data) {
527
+ const next = normalize(data);
528
+ if (!next || disposed || sendState !== "idle") return;
529
+ const key = JSON.stringify(next);
530
+ if (key === fingerprint) return;
531
+ step = next;
532
+ fingerprint = key;
533
+ locale = next.locale;
534
+ document.documentElement.lang = locale;
535
+ window.clearTimeout(resultTimer);
536
+ render();
537
+ }
538
+ function readLegacyResult(candidate) {
539
+ if (!isRecord(candidate)) return;
540
+ const nested = isRecord(candidate.call_tool_result)
541
+ ? candidate.call_tool_result
542
+ : null;
543
+ for (const value of [
544
+ candidate,
545
+ candidate.structuredContent,
546
+ candidate.mcp_tool_result?.structuredContent,
547
+ nested?.structuredContent,
548
+ nested?.mcp_tool_result?.structuredContent,
549
+ ]) {
550
+ if (isRecord(value) && isRecord(value.guidedStep))
551
+ receiveToolResult(value);
552
+ }
553
+ }
554
+ function receiveToolResult(value) {
555
+ if (!isRecord(value)) return;
556
+ if (value.state === "answered" || value.state === "cancelled") {
557
+ window.clearTimeout(resultTimer);
558
+ root.hidden = true;
559
+ status.textContent = "";
560
+ resize();
561
+ return;
562
+ }
563
+ receiveStep(value.guidedStep);
564
+ }
565
+ function element(tag, text) {
566
+ const node = document.createElement(tag);
567
+ if (text) node.textContent = text;
568
+ return node;
569
+ }
570
+ function actionButton(text, className, testId, onClick) {
571
+ const button = element("button", text);
572
+ button.type = "button";
573
+ button.className = className;
574
+ button.dataset.testid = testId;
575
+ button.addEventListener("click", onClick);
576
+ return button;
577
+ }
578
+ function addPreview(row, option, index) {
579
+ const source =
580
+ "https://productmaker.app/assets/narrative-previews/" +
581
+ option.preview;
582
+ const text =
583
+ (locale === "en" ? "Play example: " : "Ver ejemplo: ") +
584
+ option.label;
585
+ const trigger = actionButton(
586
+ "",
587
+ "preview-trigger",
588
+ `guided-step-preview-${index + 1}`,
589
+ toggle,
590
+ );
591
+ trigger.dataset.mediaPreview = "";
592
+ trigger.setAttribute("aria-label", text);
593
+ trigger.setAttribute("aria-expanded", "false");
594
+ const poster = element("img");
595
+ poster.alt = "";
596
+ poster.src = source + ".webp";
597
+ poster.addEventListener("error", () => {
598
+ trigger.textContent = locale === "en" ? "Play" : "Ver";
599
+ });
600
+ trigger.append(poster);
601
+ const player = element("video");
602
+ player.hidden = true;
603
+ player.controls = true;
604
+ player.playsInline = true;
605
+ player.muted = true;
606
+ player.preload = "none";
607
+ player.setAttribute("aria-label", text);
608
+ const error = element(
609
+ "p",
610
+ locale === "en"
611
+ ? "The example could not load."
612
+ : "No se pudo abrir el ejemplo.",
613
+ );
614
+ error.hidden = true;
615
+ error.setAttribute("role", "status");
616
+ function toggle() {
617
+ if (!player.hidden) {
618
+ player.hidden = true;
619
+ player.pause();
620
+ trigger.setAttribute("aria-expanded", "false");
621
+ } else {
622
+ error.hidden = true;
623
+ player.hidden = false;
624
+ trigger.setAttribute("aria-expanded", "true");
625
+ if (!player.src) player.src = source + ".mp4";
626
+ player.play().catch(() => undefined);
627
+ }
628
+ resize();
629
+ }
630
+ player.addEventListener("error", () => {
631
+ player.hidden = true;
632
+ error.hidden = false;
633
+ trigger.setAttribute("aria-expanded", "false");
634
+ resize();
635
+ });
636
+ row.append(trigger, player, error);
637
+ }
638
+ function renderForm(model) {
639
+ const form = element("form");
640
+ const controls = [];
641
+ for (const field of model.form) {
642
+ const label = element("label", field.label);
643
+ const control = element(
644
+ field.kind === "select" ? "select" : "input",
645
+ );
646
+ control.id = "field-" + field.key;
647
+ control.dataset.testid = "guided-step-field-" + field.key;
648
+ control.required = field.required === true;
649
+ label.htmlFor = control.id;
650
+ if (field.kind === "select") {
651
+ control.append(
652
+ new Option(
653
+ locale === "en" ? "Choose an option" : "Elige una opción",
654
+ "",
655
+ ),
656
+ );
657
+ for (const option of Array.isArray(field.options)
658
+ ? field.options.slice(0, 50)
659
+ : []) {
660
+ if (
661
+ isRecord(option) &&
662
+ boundedText(option.label, 160) &&
663
+ boundedText(option.value, 160)
664
+ )
665
+ control.append(new Option(option.label, option.value));
666
+ }
667
+ } else {
668
+ control.type = field.kind;
669
+ if (field.kind === "number") {
670
+ control.step = "any";
671
+ } else {
672
+ control.maxLength = maxFieldTextLength;
673
+ if (control.required) {
674
+ control.pattern = /.*\S.*/.source;
675
+ control.title = copy[locale].requiredAnswer;
676
+ }
677
+ }
678
+ }
679
+ if (
680
+ typeof field.value === "number" ||
681
+ typeof field.value === "string"
682
+ )
683
+ control.value = String(field.value);
684
+ form.append(label, control);
685
+ controls.push({ label: field.label, control });
686
+ }
687
+ const submit = element(
688
+ "button",
689
+ model.actionLabel || copy[locale].submit,
690
+ );
691
+ submit.dataset.testid = "guided-step-form-submit";
692
+ submit.className = "primary";
693
+ form.append(submit);
694
+ form.addEventListener("submit", (event) => {
695
+ event.preventDefault();
696
+ const lines = controls.flatMap(({ label, control }) => {
697
+ if (!control.value.trim()) return [];
698
+ const text =
699
+ control instanceof HTMLSelectElement
700
+ ? control.selectedOptions[0]?.text
701
+ : control.value.trim();
702
+ return text ? [label + ": " + text] : [];
703
+ });
704
+ if (lines.length) {
705
+ send(lines.join("\n"), maxFormAnswerLength);
706
+ } else if (controls.every(({ control }) => !control.required)) {
707
+ send(copy[locale].skipOptionalFields);
708
+ }
709
+ });
710
+ actions.append(form);
711
+ }
712
+ function render() {
713
+ const model = step;
714
+ stage.hidden = false;
715
+ stage.textContent = model.stage;
716
+ question.hidden = false;
717
+ question.textContent = model.question;
718
+ description.hidden = !model.description;
719
+ description.textContent = model.description || "";
720
+ details.replaceChildren();
721
+ for (const { label, value } of model.details) {
722
+ const row = element("div");
723
+ row.append(element("dt", label), element("dd", value));
724
+ details.append(row);
725
+ }
726
+ details.hidden = !model.details.length;
727
+ actions.replaceChildren();
728
+ if (model.confirmation) {
729
+ const instruction = element("p", copy[locale].confirmInChat);
730
+ instruction.className = "approval-instruction";
731
+ const note = element("blockquote", model.confirmation);
732
+ note.className = "approval-note";
733
+ actions.append(instruction, note);
734
+ } else if (model.options.length) {
735
+ const group = element("div");
736
+ group.className = "choices";
737
+ group.setAttribute("role", "group");
738
+ group.setAttribute("aria-labelledby", "question");
739
+ for (const [index, option] of model.options.entries()) {
740
+ const button = actionButton(
741
+ "",
742
+ option.recommended ? "choice recommended" : "choice",
743
+ `guided-step-option-${index + 1}`,
744
+ () => send(option.label),
745
+ );
746
+ button.append(element("strong", option.label));
747
+ if (option.recommended) {
748
+ const badge = element("span", copy[locale].recommended);
749
+ badge.className = "recommendation";
750
+ button.append(badge);
751
+ }
752
+ if (option.description) {
753
+ const context = element("span", option.description);
754
+ context.className = "choice-detail";
755
+ button.append(context);
756
+ }
757
+ const row = element("div");
758
+ row.className = "choice-row";
759
+ row.append(button);
760
+ if (option.preview) addPreview(row, option, index);
761
+ group.append(row);
762
+ }
763
+ actions.append(group);
764
+ } else if (model.form.length) {
765
+ renderForm(model);
766
+ } else if (model.field) {
767
+ const form = element("form");
768
+ const label = element("label", model.field.label);
769
+ label.htmlFor = "answer";
770
+ const input = element("input");
771
+ input.id = "answer";
772
+ input.dataset.testid = "guided-step-answer";
773
+ input.type = "text";
774
+ input.required = true;
775
+ input.maxLength = maxStandaloneAnswerLength;
776
+ if (model.field.placeholder)
777
+ input.placeholder = model.field.placeholder;
778
+ const submit = element(
779
+ "button",
780
+ model.actionLabel || copy[locale].submit,
781
+ );
782
+ submit.type = "submit";
783
+ submit.dataset.testid = "guided-step-submit";
784
+ submit.className = "primary";
785
+ form.append(label, input, submit);
786
+ form.addEventListener("submit", (event) => {
787
+ event.preventDefault();
788
+ if (input.value.trim()) send(input.value);
789
+ });
790
+ actions.append(form);
791
+ }
792
+ actions.hidden = !actions.childElementCount;
793
+ statusForState();
794
+ }
795
+ function settleSend(ok) {
796
+ if (disposed || sendState !== "sending") return;
797
+ window.clearTimeout(sendTimer);
798
+ sendState = ok ? "sent" : "uncertain";
799
+ statusForState();
800
+ }
801
+ async function send(text, maxLength = maxStandaloneAnswerLength) {
802
+ const kind = messageKind();
803
+ if (
804
+ disposed ||
805
+ !kind ||
806
+ sendState !== "idle" ||
807
+ !boundedText(text, maxLength)
808
+ )
809
+ return;
810
+ sentText = text;
811
+ const prompt = `ProductMaker · ${step.question}\n${copy[locale].answer}: ${text}`;
812
+ sendKind = kind;
813
+ sendState = "sending";
814
+ statusForState();
815
+ // The host may post before acknowledging. An error or timeout
816
+ // therefore keeps this card locked and never retries another bridge.
817
+ sendTimer = window.setTimeout(() => settleSend(false), 10000);
818
+ try {
819
+ if (kind === "mcp") {
820
+ post({
821
+ id: messageId,
822
+ method: "ui/message",
823
+ params: {
824
+ role: "user",
825
+ content: [{ type: "text", text: prompt }],
826
+ },
827
+ });
828
+ } else {
829
+ const result = await window.openai.sendFollowUpMessage({
830
+ prompt,
831
+ });
832
+ settleSend(!isRecord(result) || result.isError !== true);
833
+ }
834
+ } catch {
835
+ settleSend(false);
836
+ }
837
+ }
838
+ function readLegacyGlobals() {
839
+ readLegacyResult(window.openai?.toolOutput);
840
+ readLegacyResult(window.openai?.toolResponseMetadata);
841
+ }
842
+ function settleInitialization(result) {
843
+ if (initializationSettled || disposed) return;
844
+ initializationSettled = true;
845
+ window.clearTimeout(initializeTimer);
846
+ if (isRecord(result)) {
847
+ hostReady = true;
848
+ const capability = result.hostCapabilities?.message;
849
+ textMessaging = isRecord(capability) && isRecord(capability.text);
850
+ setHostContext(result.hostContext);
851
+ post({ method: "ui/notifications/initialized", params: {} });
852
+ }
853
+ readLegacyGlobals();
854
+ statusForState();
855
+ }
856
+ function handleGlobals(event) {
857
+ const globals = event.detail?.globals;
858
+ if (!isRecord(globals) || disposed) return;
859
+ if (globals.theme) setHostContext({ theme: globals.theme });
860
+ readLegacyResult(globals.toolOutput);
861
+ readLegacyResult(globals.toolResponseMetadata);
862
+ statusForState();
863
+ }
864
+ function handleMessage(event) {
865
+ if (
866
+ disposed ||
867
+ event.source !== window.parent ||
868
+ window.parent === window ||
869
+ (hostOrigin !== "*" && event.origin !== hostOrigin) ||
870
+ !isRecord(event.data) ||
871
+ event.data.jsonrpc !== "2.0"
872
+ )
873
+ return;
874
+ const message = event.data;
875
+ if (message.method === "ui/resource-teardown") {
876
+ post({ id: message.id, result: {} });
877
+ disposed = true;
878
+ window.clearTimeout(initializeTimer);
879
+ window.clearTimeout(resultTimer);
880
+ window.clearTimeout(sendTimer);
881
+ cancelAnimationFrame(sizingFrame);
882
+ observer.disconnect();
883
+ window.removeEventListener("message", handleMessage);
884
+ window.removeEventListener("openai:set_globals", handleGlobals);
885
+ return;
886
+ }
887
+ if (
888
+ message.method === "ping" &&
889
+ (typeof message.id === "string" || Number.isInteger(message.id))
890
+ ) {
891
+ post({ id: message.id, result: {} });
892
+ return;
893
+ }
894
+ if (message.method === "ui/notifications/host-context-changed")
895
+ setHostContext(message.params);
896
+ if (
897
+ message.method === "ui/notifications/tool-result" &&
898
+ isRecord(message.params)
899
+ ) {
900
+ if (message.params.isError === true) {
901
+ dismissUnsentStep();
902
+ } else {
903
+ receiveToolResult(message.params.structuredContent);
904
+ }
905
+ }
906
+ if (message.method === "ui/notifications/tool-cancelled")
907
+ dismissUnsentStep();
908
+ if (Object.hasOwn(message, "method")) return;
909
+ const hasResult =
910
+ isRecord(message.result) && !Object.hasOwn(message, "error");
911
+ const hasError =
912
+ isRecord(message.error) && !Object.hasOwn(message, "result");
913
+ if (!hasResult && !hasError) return;
914
+ if (message.id === initializeId && !initializationSettled) {
915
+ if (event.origin && event.origin !== "null")
916
+ hostOrigin = event.origin;
917
+ settleInitialization(hasResult ? message.result : null);
918
+ } else if (message.id === messageId) {
919
+ settleSend(hasResult && message.result.isError !== true);
920
+ }
921
+ }
922
+
923
+ let unavailable = false;
924
+ const observer = new ResizeObserver(resize);
925
+ observer.observe(root);
926
+ const resultTimer = window.setTimeout(() => {
927
+ if (!step) {
928
+ unavailable = true;
929
+ statusForState();
930
+ }
931
+ }, 10000);
932
+ const initializeTimer = window.setTimeout(
933
+ () => settleInitialization(null),
934
+ 5000,
935
+ );
936
+ window.addEventListener("message", handleMessage);
937
+ window.addEventListener("openai:set_globals", handleGlobals);
938
+ post({
939
+ id: initializeId,
940
+ method: "ui/initialize",
941
+ params: {
942
+ appInfo: { name: "ProductMaker guided step", version: "1.0.0" },
943
+ appCapabilities: { availableDisplayModes: ["inline"] },
944
+ protocolVersion: "2026-01-26",
945
+ },
946
+ });
947
+ setHostContext({ theme: window.openai?.theme });
948
+ readLegacyGlobals();
949
+ })();
950
+ </script>
951
+ </body>
952
+ </html>