@productmaker/mcp 12.45.0 → 12.48.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.
- package/README.md +7 -0
- package/dist/http.js +603 -188
- package/dist/stdio.js +503 -110
- package/dist/ui/task-results-app.html +412 -23
- package/package.json +1 -1
|
@@ -272,7 +272,9 @@
|
|
|
272
272
|
</head>
|
|
273
273
|
<body>
|
|
274
274
|
<main data-testid="task-results-root" data-state="loading" aria-busy="true">
|
|
275
|
-
<h1 data-copy="title">
|
|
275
|
+
<h1 data-testid="task-results-product" data-copy="title">
|
|
276
|
+
Your creative
|
|
277
|
+
</h1>
|
|
276
278
|
<p id="status" role="status" aria-live="polite" data-copy="loading">
|
|
277
279
|
Loading your result…
|
|
278
280
|
</p>
|
|
@@ -285,12 +287,24 @@
|
|
|
285
287
|
const root = document.querySelector("main");
|
|
286
288
|
const status = document.getElementById("status");
|
|
287
289
|
const media = document.getElementById("media");
|
|
290
|
+
const heading = document.querySelector("h1");
|
|
288
291
|
const copy = {
|
|
289
292
|
en: {
|
|
290
293
|
title: "Your creative",
|
|
291
294
|
loading: "Loading your result…",
|
|
292
295
|
pending:
|
|
293
296
|
"Your creative is still being prepared. Ask in the chat to check its progress.",
|
|
297
|
+
pendingWatching:
|
|
298
|
+
"Your creative is still being prepared. We'll post here when there's something to review or it's ready.",
|
|
299
|
+
noticeReview:
|
|
300
|
+
"ProductMaker has a decision waiting for me. Show it to me here so I can answer.",
|
|
301
|
+
noticeReady:
|
|
302
|
+
"ProductMaker finished my creative. Show me the result here.",
|
|
303
|
+
noticeError:
|
|
304
|
+
"ProductMaker couldn't finish my creative. Tell me what happened and how to recover it.",
|
|
305
|
+
noticePartial:
|
|
306
|
+
"ProductMaker finished only part of my creative. Show me what arrived and what failed.",
|
|
307
|
+
noticeTask: "task",
|
|
294
308
|
awaitingReview:
|
|
295
309
|
"Your approval is needed. Reply in the chat to continue.",
|
|
296
310
|
taskError:
|
|
@@ -336,6 +350,17 @@
|
|
|
336
350
|
loading: "Cargando tu resultado…",
|
|
337
351
|
pending:
|
|
338
352
|
"Tu creativo sigue en preparación. Pide una actualización en el chat.",
|
|
353
|
+
pendingWatching:
|
|
354
|
+
"Tu creativo sigue en preparación. Te avisaremos aquí cuando haya algo para revisar o esté listo.",
|
|
355
|
+
noticeReview:
|
|
356
|
+
"ProductMaker tiene una decisión pendiente para mí. Muéstramela aquí para responder.",
|
|
357
|
+
noticeReady:
|
|
358
|
+
"ProductMaker terminó mi creativo. Muéstrame el resultado aquí.",
|
|
359
|
+
noticeError:
|
|
360
|
+
"ProductMaker no pudo terminar mi creativo. Dime qué pasó y cómo recuperarlo.",
|
|
361
|
+
noticePartial:
|
|
362
|
+
"ProductMaker terminó solo una parte de mi creativo. Muéstrame lo que llegó y qué falló.",
|
|
363
|
+
noticeTask: "tarea",
|
|
339
364
|
awaitingReview:
|
|
340
365
|
"Falta tu aprobación. Responde en el chat para continuar.",
|
|
341
366
|
taskError:
|
|
@@ -456,6 +481,305 @@
|
|
|
456
481
|
if (typeof window.openai?.notifyIntrinsicHeight === "function")
|
|
457
482
|
window.openai.notifyIntrinsicHeight(height);
|
|
458
483
|
};
|
|
484
|
+
// The server cannot wake the model once its turn ends. While a task
|
|
485
|
+
// runs with no decision open, this view reads it through the host and
|
|
486
|
+
// posts one chat message when a decision, result or failure appears.
|
|
487
|
+
const WATCH_INTERVAL_MS = 20000;
|
|
488
|
+
const WATCH_LIMIT_MS = 90 * 60 * 1000;
|
|
489
|
+
const STALE_NOTICE_MS = 5 * 60 * 1000;
|
|
490
|
+
const announced = new Set();
|
|
491
|
+
const lastReadAt = new Map();
|
|
492
|
+
const pendingRequests = new Map();
|
|
493
|
+
let hostCapabilities = null;
|
|
494
|
+
let nextRequestId = 100;
|
|
495
|
+
let watching = null;
|
|
496
|
+
let lastViewData = null;
|
|
497
|
+
let watchTimer = null;
|
|
498
|
+
let renderedSignature = null;
|
|
499
|
+
const watchChannel = (() => {
|
|
500
|
+
try {
|
|
501
|
+
return typeof BroadcastChannel === "function"
|
|
502
|
+
? new BroadcastChannel("productmaker-task-watch")
|
|
503
|
+
: null;
|
|
504
|
+
} catch {
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
})();
|
|
508
|
+
if (watchChannel)
|
|
509
|
+
watchChannel.onmessage = (event) => {
|
|
510
|
+
const data = event.data;
|
|
511
|
+
if (!isRecord(data) || typeof data.taskId !== "string") return;
|
|
512
|
+
if (data.type === "read" && Number.isFinite(data.at))
|
|
513
|
+
lastReadAt.set(data.taskId, data.at);
|
|
514
|
+
if (data.type === "announce" && typeof data.key === "string")
|
|
515
|
+
announced.add(data.key);
|
|
516
|
+
// Only the newest view of a task follows it; older ones stop.
|
|
517
|
+
if (
|
|
518
|
+
data.type === "claim" &&
|
|
519
|
+
Number.isFinite(data.at) &&
|
|
520
|
+
watching?.taskId === data.taskId &&
|
|
521
|
+
data.at > watching.startedAt
|
|
522
|
+
)
|
|
523
|
+
stopWatching();
|
|
524
|
+
};
|
|
525
|
+
function request(method, params) {
|
|
526
|
+
return new Promise((resolve, reject) => {
|
|
527
|
+
if (disposed) {
|
|
528
|
+
reject(new Error("disposed"));
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const id = nextRequestId++;
|
|
532
|
+
const timer = window.setTimeout(() => {
|
|
533
|
+
pendingRequests.delete(id);
|
|
534
|
+
reject(new Error("timeout"));
|
|
535
|
+
}, 30000);
|
|
536
|
+
pendingRequests.set(id, { resolve, reject, timer });
|
|
537
|
+
window.parent.postMessage(
|
|
538
|
+
{ jsonrpc: "2.0", id, method, params },
|
|
539
|
+
"*",
|
|
540
|
+
);
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
const canReadTask = () =>
|
|
544
|
+
Boolean(hostCapabilities?.serverTools) ||
|
|
545
|
+
typeof window.openai?.callTool === "function";
|
|
546
|
+
const canTellChat = () =>
|
|
547
|
+
Boolean(hostCapabilities?.message) ||
|
|
548
|
+
typeof window.openai?.sendFollowUpMessage === "function";
|
|
549
|
+
function readTask(taskId) {
|
|
550
|
+
const args = { taskId, viewerLocale: locale, waitSeconds: 0 };
|
|
551
|
+
return hostCapabilities?.serverTools
|
|
552
|
+
? request("tools/call", {
|
|
553
|
+
name: "get_task_status",
|
|
554
|
+
arguments: args,
|
|
555
|
+
})
|
|
556
|
+
: window.openai.callTool("get_task_status", args);
|
|
557
|
+
}
|
|
558
|
+
// One notice per decision and per terminal state: later timestamps of
|
|
559
|
+
// a result (GIF, publication) must not post again, while each new
|
|
560
|
+
// decision on the same task does.
|
|
561
|
+
const noticeKey = (data) =>
|
|
562
|
+
data.state === "awaiting_review"
|
|
563
|
+
? `${data.taskId}:${data.state}:${data.reviewGate ?? data.updatedAt ?? ""}`
|
|
564
|
+
: `${data.taskId}:${data.state}`;
|
|
565
|
+
// Signed URLs change on every read; compare the view without them so
|
|
566
|
+
// an unchanged delivery is not redrawn under the person watching it.
|
|
567
|
+
// A signed segment is `<base64url JSON>.<signature>`; its payload minus
|
|
568
|
+
// `exp` names the asset, while the signature and expiry rotate.
|
|
569
|
+
function stableSegment(segment) {
|
|
570
|
+
if (!/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(segment)) return segment;
|
|
571
|
+
try {
|
|
572
|
+
const base64 = segment
|
|
573
|
+
.split(".")[0]
|
|
574
|
+
.replace(/-/g, "+")
|
|
575
|
+
.replace(/_/g, "/");
|
|
576
|
+
const payload = JSON.parse(atob(base64));
|
|
577
|
+
if (!isRecord(payload)) return segment;
|
|
578
|
+
const { exp: _exp, ...asset } = payload;
|
|
579
|
+
return JSON.stringify(asset);
|
|
580
|
+
} catch {
|
|
581
|
+
return segment;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function stableAsset(value) {
|
|
585
|
+
try {
|
|
586
|
+
const url = new URL(value);
|
|
587
|
+
return `${url.origin}${url.pathname
|
|
588
|
+
.split("/")
|
|
589
|
+
.map(stableSegment)
|
|
590
|
+
.join("/")}`;
|
|
591
|
+
} catch {
|
|
592
|
+
return value;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const viewSignature = (data) =>
|
|
596
|
+
JSON.stringify(data, (key, value) =>
|
|
597
|
+
key === "updatedAt" || key === "watch"
|
|
598
|
+
? undefined
|
|
599
|
+
: typeof value === "string" && value.startsWith("https://")
|
|
600
|
+
? stableAsset(value)
|
|
601
|
+
: value,
|
|
602
|
+
);
|
|
603
|
+
// Signed links expire after an hour: an unchanged view is redrawn
|
|
604
|
+
// before then so its downloads and tabs keep working.
|
|
605
|
+
const VIEW_REFRESH_MS = 40 * 60 * 1000;
|
|
606
|
+
let renderedAt = 0;
|
|
607
|
+
function announce(data) {
|
|
608
|
+
const key = noticeKey(data);
|
|
609
|
+
announced.add(key);
|
|
610
|
+
watchChannel?.postMessage({
|
|
611
|
+
type: "announce",
|
|
612
|
+
taskId: data.taskId,
|
|
613
|
+
key,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
const NOTICE_RETRY_MS = [15000, 45000];
|
|
617
|
+
const sendingNotices = new Set();
|
|
618
|
+
// Delivery is marked only after the host accepts the message, so a
|
|
619
|
+
// failed send is retried instead of silently losing the notice.
|
|
620
|
+
async function tellChat(data, attempt = 0) {
|
|
621
|
+
const key = noticeKey(data);
|
|
622
|
+
if (attempt === 0)
|
|
623
|
+
await new Promise((resolve) =>
|
|
624
|
+
window.setTimeout(resolve, Math.floor(Math.random() * 1500)),
|
|
625
|
+
);
|
|
626
|
+
if (announced.has(key) || sendingNotices.has(key) || disposed) return;
|
|
627
|
+
sendingNotices.add(key);
|
|
628
|
+
const noticeCopy =
|
|
629
|
+
data.state === "awaiting_review"
|
|
630
|
+
? "noticeReview"
|
|
631
|
+
: data.state === "error"
|
|
632
|
+
? "noticeError"
|
|
633
|
+
: data.taskFailed === true
|
|
634
|
+
? "noticePartial"
|
|
635
|
+
: "noticeReady";
|
|
636
|
+
let text = copy[locale][noticeCopy];
|
|
637
|
+
try {
|
|
638
|
+
const contextSet = hostCapabilities?.updateModelContext
|
|
639
|
+
? await request("ui/update-model-context", {
|
|
640
|
+
content: [
|
|
641
|
+
{
|
|
642
|
+
type: "text",
|
|
643
|
+
text: `ProductMaker task ${data.taskId} is now ${data.state}. Call get_task_status with this taskId and viewerLocale=${locale} before answering.`,
|
|
644
|
+
},
|
|
645
|
+
],
|
|
646
|
+
}).then(
|
|
647
|
+
() => true,
|
|
648
|
+
() => false,
|
|
649
|
+
)
|
|
650
|
+
: false;
|
|
651
|
+
// Without model context, the message itself names the task so the
|
|
652
|
+
// agent reads the right one when the chat holds several.
|
|
653
|
+
if (!contextSet) {
|
|
654
|
+
const label =
|
|
655
|
+
typeof data.productLabel === "string" && data.productLabel
|
|
656
|
+
? `${data.productLabel} · `
|
|
657
|
+
: "";
|
|
658
|
+
text += `\n\n(${label}${copy[locale].noticeTask} ${data.taskId})`;
|
|
659
|
+
}
|
|
660
|
+
if (hostCapabilities?.message)
|
|
661
|
+
await request("ui/message", {
|
|
662
|
+
role: "user",
|
|
663
|
+
content: [{ type: "text", text }],
|
|
664
|
+
});
|
|
665
|
+
else await window.openai.sendFollowUpMessage({ prompt: text });
|
|
666
|
+
announce(data);
|
|
667
|
+
} catch (error) {
|
|
668
|
+
// An unanswered send may still have reached the chat; resending
|
|
669
|
+
// would duplicate it. Only an explicit rejection is retried.
|
|
670
|
+
if (error instanceof Error && error.message === "timeout") {
|
|
671
|
+
announce(data);
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const delay = NOTICE_RETRY_MS[attempt];
|
|
675
|
+
if (delay !== undefined && !disposed)
|
|
676
|
+
window.setTimeout(() => {
|
|
677
|
+
void tellChat(data, attempt + 1);
|
|
678
|
+
}, delay);
|
|
679
|
+
} finally {
|
|
680
|
+
sendingNotices.delete(key);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function stopWatching() {
|
|
684
|
+
window.clearTimeout(watchTimer);
|
|
685
|
+
watchTimer = null;
|
|
686
|
+
watching = null;
|
|
687
|
+
}
|
|
688
|
+
function scheduleWatch() {
|
|
689
|
+
window.clearTimeout(watchTimer);
|
|
690
|
+
watchTimer = window.setTimeout(
|
|
691
|
+
watchTick,
|
|
692
|
+
WATCH_INTERVAL_MS + Math.floor(Math.random() * 3000),
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
async function watchTick() {
|
|
696
|
+
const current = watching;
|
|
697
|
+
if (!current || disposed) return;
|
|
698
|
+
if (Date.now() - current.startedAt > WATCH_LIMIT_MS) {
|
|
699
|
+
stopWatching();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (
|
|
703
|
+
Date.now() - (lastReadAt.get(current.taskId) ?? 0) <
|
|
704
|
+
WATCH_INTERVAL_MS
|
|
705
|
+
) {
|
|
706
|
+
scheduleWatch();
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const at = Date.now();
|
|
710
|
+
lastReadAt.set(current.taskId, at);
|
|
711
|
+
watchChannel?.postMessage({
|
|
712
|
+
type: "read",
|
|
713
|
+
taskId: current.taskId,
|
|
714
|
+
at,
|
|
715
|
+
});
|
|
716
|
+
let result;
|
|
717
|
+
try {
|
|
718
|
+
result = await readTask(current.taskId);
|
|
719
|
+
} catch {
|
|
720
|
+
if (watching === current) scheduleWatch();
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (watching !== current || disposed) return;
|
|
724
|
+
const found = pickTaskResult(result);
|
|
725
|
+
const data =
|
|
726
|
+
isRecord(found) && isRecord(found._meta)
|
|
727
|
+
? found._meta.taskResults
|
|
728
|
+
: null;
|
|
729
|
+
// A failed read is transient: keep the last good view and retry.
|
|
730
|
+
if (
|
|
731
|
+
!isRecord(found) ||
|
|
732
|
+
found.isError ||
|
|
733
|
+
!isRecord(data) ||
|
|
734
|
+
data.taskId !== current.taskId ||
|
|
735
|
+
!resultStates.has(data.state) ||
|
|
736
|
+
data.retryable === true
|
|
737
|
+
) {
|
|
738
|
+
scheduleWatch();
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
if (
|
|
742
|
+
data.watch === true &&
|
|
743
|
+
viewSignature(data) === renderedSignature &&
|
|
744
|
+
Date.now() - renderedAt < VIEW_REFRESH_MS
|
|
745
|
+
) {
|
|
746
|
+
scheduleWatch();
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
applyResult(found, "watch");
|
|
750
|
+
if (data.watch === true) return;
|
|
751
|
+
const changedAt = Date.parse(data.updatedAt ?? "");
|
|
752
|
+
if (
|
|
753
|
+
!Number.isFinite(changedAt) ||
|
|
754
|
+
changedAt >= current.startedAt - STALE_NOTICE_MS
|
|
755
|
+
)
|
|
756
|
+
await tellChat(data);
|
|
757
|
+
else announce(data);
|
|
758
|
+
}
|
|
759
|
+
function syncWatch(data, source) {
|
|
760
|
+
const watchable =
|
|
761
|
+
data.watch === true &&
|
|
762
|
+
typeof data.taskId === "string" &&
|
|
763
|
+
(data.state === "pending" || data.state === "ready") &&
|
|
764
|
+
canReadTask() &&
|
|
765
|
+
canTellChat();
|
|
766
|
+
if (!watchable) {
|
|
767
|
+
if (source === "host" && typeof data.taskId === "string")
|
|
768
|
+
announce(data);
|
|
769
|
+
stopWatching();
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
if (watching?.taskId !== data.taskId) {
|
|
773
|
+
watching = { taskId: data.taskId, startedAt: Date.now() };
|
|
774
|
+
watchChannel?.postMessage({
|
|
775
|
+
type: "claim",
|
|
776
|
+
taskId: data.taskId,
|
|
777
|
+
at: watching.startedAt,
|
|
778
|
+
});
|
|
779
|
+
scheduleWatch();
|
|
780
|
+
} else if (source === "watch") scheduleWatch();
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
459
783
|
function cleanupMedia(container = media) {
|
|
460
784
|
container.querySelectorAll("video").forEach((video) => {
|
|
461
785
|
video.pause();
|
|
@@ -764,27 +1088,51 @@
|
|
|
764
1088
|
})
|
|
765
1089
|
: [];
|
|
766
1090
|
}
|
|
767
|
-
function applyResult(result) {
|
|
1091
|
+
function applyResult(result, source = "host") {
|
|
768
1092
|
if (disposed) return;
|
|
769
1093
|
receivedResult = true;
|
|
770
1094
|
window.clearTimeout(resultTimeout);
|
|
771
1095
|
const metadata =
|
|
772
1096
|
isRecord(result) && isRecord(result._meta) ? result._meta : null;
|
|
773
1097
|
const data = metadata?.taskResults;
|
|
1098
|
+
const structured =
|
|
1099
|
+
isRecord(result) && isRecord(result.structuredContent)
|
|
1100
|
+
? result.structuredContent
|
|
1101
|
+
: null;
|
|
1102
|
+
const mismatchedTask =
|
|
1103
|
+
isRecord(data) &&
|
|
1104
|
+
typeof data.taskId === "string" &&
|
|
1105
|
+
typeof structured?.taskId === "string" &&
|
|
1106
|
+
data.taskId !== structured.taskId;
|
|
1107
|
+
text(heading, "title");
|
|
774
1108
|
if (
|
|
775
1109
|
!isRecord(result) ||
|
|
776
1110
|
result.isError ||
|
|
1111
|
+
mismatchedTask ||
|
|
777
1112
|
!isRecord(data) ||
|
|
778
1113
|
!resultStates.has(data.state)
|
|
779
1114
|
) {
|
|
1115
|
+
if (source === "host") stopWatching();
|
|
1116
|
+
renderedSignature = null;
|
|
780
1117
|
setState("error", "resultError");
|
|
781
1118
|
reportSize();
|
|
782
1119
|
return;
|
|
783
1120
|
}
|
|
1121
|
+
lastViewData = data;
|
|
1122
|
+
renderedSignature = viewSignature(data);
|
|
1123
|
+
renderedAt = Date.now();
|
|
1124
|
+
const following = syncWatch(data, source);
|
|
784
1125
|
if (data.locale === "es" || data.locale === "en") {
|
|
785
1126
|
resultLocale = data.locale;
|
|
786
1127
|
setLocale(resultLocale);
|
|
787
1128
|
}
|
|
1129
|
+
if (
|
|
1130
|
+
typeof data.productLabel === "string" &&
|
|
1131
|
+
data.productLabel.trim()
|
|
1132
|
+
) {
|
|
1133
|
+
delete heading.dataset.copy;
|
|
1134
|
+
heading.textContent = data.productLabel.trim().slice(0, 160);
|
|
1135
|
+
}
|
|
788
1136
|
if (data.state === "awaiting_review") {
|
|
789
1137
|
setState(data.state, "awaitingReview");
|
|
790
1138
|
reportSize();
|
|
@@ -793,7 +1141,11 @@
|
|
|
793
1141
|
if (data.state === "pending" || data.state === "error") {
|
|
794
1142
|
setState(
|
|
795
1143
|
data.state,
|
|
796
|
-
data.state === "
|
|
1144
|
+
data.state === "error"
|
|
1145
|
+
? "taskError"
|
|
1146
|
+
: following
|
|
1147
|
+
? "pendingWatching"
|
|
1148
|
+
: "pending",
|
|
797
1149
|
);
|
|
798
1150
|
reportSize();
|
|
799
1151
|
return;
|
|
@@ -849,7 +1201,16 @@
|
|
|
849
1201
|
if (!isRecord(metadata) || disposed) return;
|
|
850
1202
|
// ChatGPT preserves the MCP envelope in toolResponseMetadata:
|
|
851
1203
|
// https://developers.openai.com/plugins/reference#capabilities
|
|
852
|
-
|
|
1204
|
+
const result = pickTaskResult(metadata);
|
|
1205
|
+
// Globals can arrive before a result or with unrelated host updates.
|
|
1206
|
+
// Keep delivered playback until a valid result or explicit error.
|
|
1207
|
+
if (result) applyResult(result);
|
|
1208
|
+
}
|
|
1209
|
+
// ChatGPT may wrap a tool result (toolResponseMetadata, callTool), so
|
|
1210
|
+
// the follower reads it through the same known wrappers.
|
|
1211
|
+
// Read only the known wrappers; never search arbitrary nested data.
|
|
1212
|
+
function pickTaskResult(metadata) {
|
|
1213
|
+
if (!isRecord(metadata)) return null;
|
|
853
1214
|
const callResult = isRecord(metadata.call_tool_result)
|
|
854
1215
|
? metadata.call_tool_result
|
|
855
1216
|
: null;
|
|
@@ -860,25 +1221,24 @@
|
|
|
860
1221
|
metadata,
|
|
861
1222
|
{ _meta: metadata },
|
|
862
1223
|
];
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
if (result) applyResult(result);
|
|
1224
|
+
return (
|
|
1225
|
+
candidates.find((candidate) => {
|
|
1226
|
+
if (!isRecord(candidate)) return false;
|
|
1227
|
+
if (candidate.isError === true) return true;
|
|
1228
|
+
const data = isRecord(candidate._meta)
|
|
1229
|
+
? candidate._meta.taskResults
|
|
1230
|
+
: null;
|
|
1231
|
+
return (
|
|
1232
|
+
isRecord(data) &&
|
|
1233
|
+
resultStates.has(data.state) &&
|
|
1234
|
+
Array.isArray(data.images) &&
|
|
1235
|
+
Array.isArray(data.videos) &&
|
|
1236
|
+
Array.isArray(data.links) &&
|
|
1237
|
+
(data.landingSections === undefined ||
|
|
1238
|
+
Array.isArray(data.landingSections))
|
|
1239
|
+
);
|
|
1240
|
+
}) ?? null
|
|
1241
|
+
);
|
|
882
1242
|
}
|
|
883
1243
|
function handleMessage(event) {
|
|
884
1244
|
if (
|
|
@@ -889,7 +1249,26 @@
|
|
|
889
1249
|
)
|
|
890
1250
|
return;
|
|
891
1251
|
const message = event.data;
|
|
1252
|
+
if (
|
|
1253
|
+
pendingRequests.has(message.id) &&
|
|
1254
|
+
!Object.prototype.hasOwnProperty.call(message, "method")
|
|
1255
|
+
) {
|
|
1256
|
+
const pending = pendingRequests.get(message.id);
|
|
1257
|
+
pendingRequests.delete(message.id);
|
|
1258
|
+
window.clearTimeout(pending.timer);
|
|
1259
|
+
if (isRecord(message.error))
|
|
1260
|
+
pending.reject(new Error(String(message.error.message)));
|
|
1261
|
+
else pending.resolve(message.result);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
892
1264
|
if (message.method === "ui/resource-teardown") {
|
|
1265
|
+
stopWatching();
|
|
1266
|
+
watchChannel?.close();
|
|
1267
|
+
pendingRequests.forEach(({ reject, timer }) => {
|
|
1268
|
+
window.clearTimeout(timer);
|
|
1269
|
+
reject(new Error("disposed"));
|
|
1270
|
+
});
|
|
1271
|
+
pendingRequests.clear();
|
|
893
1272
|
cleanupMedia();
|
|
894
1273
|
window.clearTimeout(initializeTimeout);
|
|
895
1274
|
window.clearTimeout(resultTimeout);
|
|
@@ -932,6 +1311,16 @@
|
|
|
932
1311
|
if (!receivedResult) applyResult({ isError: true });
|
|
933
1312
|
} else {
|
|
934
1313
|
hostReady = true;
|
|
1314
|
+
hostCapabilities = isRecord(message.result.hostCapabilities)
|
|
1315
|
+
? message.result.hostCapabilities
|
|
1316
|
+
: null;
|
|
1317
|
+
// A result can arrive before the host reports its capabilities.
|
|
1318
|
+
if (
|
|
1319
|
+
lastViewData &&
|
|
1320
|
+
syncWatch(lastViewData, "host") &&
|
|
1321
|
+
lastViewData.state === "pending"
|
|
1322
|
+
)
|
|
1323
|
+
setState("pending", "pendingWatching");
|
|
935
1324
|
setHostContext(message.result.hostContext);
|
|
936
1325
|
notify("ui/notifications/initialized", {});
|
|
937
1326
|
reportSize();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@productmaker/mcp",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.48.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "ProductMaker MCP server — cost products, generate landing pages, UGC videos, and ad creatives, and publish to Shopify, Meta Ads, and TikTok Ads.",
|