@widgetic/creator 0.4.15 → 0.4.16
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/dist/CreatorApp.svelte
CHANGED
|
@@ -161,7 +161,8 @@
|
|
|
161
161
|
import {
|
|
162
162
|
ChatUploadRefusedError,
|
|
163
163
|
shouldUseTusForChatUpload,
|
|
164
|
-
uploadChatFileToWidgeticApi
|
|
164
|
+
uploadChatFileToWidgeticApi,
|
|
165
|
+
uploadIdFromStoredFileUrl
|
|
165
166
|
} from './utils/widgeticChatUpload.js';
|
|
166
167
|
import {
|
|
167
168
|
PARTNER_UPLOAD_FAILED_MESSAGE,
|
|
@@ -1993,8 +1994,19 @@
|
|
|
1993
1994
|
const name = String(attachment.file_name || '');
|
|
1994
1995
|
return type.startsWith('image/') || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(name) || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(attachment.url);
|
|
1995
1996
|
});
|
|
1997
|
+
const retryUploadIds = [
|
|
1998
|
+
...new Set(
|
|
1999
|
+
retryImageAttachments
|
|
2000
|
+
.map((attachment) => uploadIdFromStoredFileUrl(attachment.url))
|
|
2001
|
+
.filter((id): id is string => !!id),
|
|
2002
|
+
),
|
|
2003
|
+
];
|
|
1996
2004
|
const retryImageDataUrls: string[] = [];
|
|
1997
2005
|
for (const attachment of retryImageAttachments) {
|
|
2006
|
+
// A stored upload is fetched by the API. The browser fetch fails (no CORS
|
|
2007
|
+
// on the file host) and used to toast "Could not load uploaded image"
|
|
2008
|
+
// even though the picture was already saved.
|
|
2009
|
+
if (uploadIdFromStoredFileUrl(attachment.url)) continue;
|
|
1998
2010
|
try {
|
|
1999
2011
|
const dataUrl = await resolvePromptImageForCodegen(undefined, attachment.url);
|
|
2000
2012
|
if (!dataUrl) continue;
|
|
@@ -2006,6 +2018,9 @@
|
|
|
2006
2018
|
console.warn('[Chat→Retry] Could not resend an attachment:', imageErr);
|
|
2007
2019
|
}
|
|
2008
2020
|
}
|
|
2021
|
+
if (retryUploadIds.length > 0) {
|
|
2022
|
+
console.info('[Chat→Retry] Saved image stays on the server', { uploadCount: retryUploadIds.length });
|
|
2023
|
+
}
|
|
2009
2024
|
if (forkUserMessage) {
|
|
2010
2025
|
const bubbleAttachments = retryImageAttachments.map((attachment, index) => ({
|
|
2011
2026
|
id: `retry_${Date.now()}_${index}`,
|
|
@@ -2027,7 +2042,9 @@
|
|
|
2027
2042
|
forceRecreateRepo: true,
|
|
2028
2043
|
skipIntentGate: true,
|
|
2029
2044
|
forkUserMessage,
|
|
2030
|
-
attachmentIds:
|
|
2045
|
+
attachmentIds: retryUploadIds.length > 0
|
|
2046
|
+
? retryUploadIds
|
|
2047
|
+
: (forkUserMessage ? undefined : (draftUploadIds.length > 0 ? draftUploadIds : undefined)),
|
|
2031
2048
|
promptImagesOverride: retryImageDataUrls.length > 0
|
|
2032
2049
|
? retryImageDataUrls
|
|
2033
2050
|
: (forkUserMessage ? [] : (draftImageUrls.length > 0 ? draftImageUrls : undefined)),
|
|
@@ -3325,8 +3342,8 @@
|
|
|
3325
3342
|
const response = await messagesClient.restoreCheckpointRaw({
|
|
3326
3343
|
conversationId,
|
|
3327
3344
|
restoreCheckpointRequest: {
|
|
3328
|
-
|
|
3329
|
-
|
|
3345
|
+
conversationId,
|
|
3346
|
+
checkpointMessageId,
|
|
3330
3347
|
}
|
|
3331
3348
|
}, widgetBuilderRequestInit(widgetBuilderPreviewBaseUrl()));
|
|
3332
3349
|
const json = await response.raw.json();
|
|
@@ -10404,12 +10421,10 @@ Requirements:
|
|
|
10404
10421
|
(url) => typeof url === 'string' && (url.startsWith('data:image/') || /^https?:\/\//i.test(url)) && url.length > 20,
|
|
10405
10422
|
);
|
|
10406
10423
|
const chatAttachmentUrls = options.forkUserMessage ? [] : (panelChat?.getAttachmentDataUrls?.() ?? []);
|
|
10407
|
-
const chatUploadIds =
|
|
10408
|
-
|
|
10409
|
-
: [
|
|
10410
|
-
|
|
10411
|
-
...(panelChat?.getAttachmentUploadIds?.() ?? []),
|
|
10412
|
-
].filter((id, index, arr) => id && arr.indexOf(id) === index);
|
|
10424
|
+
const chatUploadIds = [
|
|
10425
|
+
...(options.attachmentIds || []),
|
|
10426
|
+
...(options.forkUserMessage ? [] : (panelChat?.getAttachmentUploadIds?.() ?? [])),
|
|
10427
|
+
].filter((id, index, arr) => id && arr.indexOf(id) === index);
|
|
10413
10428
|
if (!options.forkUserMessage && chatAttachmentUrls.length > 0 && !(options.promptImagesOverride?.length)) {
|
|
10414
10429
|
const fromChat = chatAttachmentUrls.filter(
|
|
10415
10430
|
(url) => typeof url === 'string' && (url.startsWith('data:image/') || /^https?:\/\//i.test(url)) && url.length > 20,
|
|
@@ -11046,12 +11061,28 @@ Requirements:
|
|
|
11046
11061
|
activePanelRef?.setHasAutoOpenedPreview(true);
|
|
11047
11062
|
pendingCreatePreviewDefaultsWidgetId = generationWidgetId;
|
|
11048
11063
|
suppressNextBuildFromRepoChatMessage = true;
|
|
11049
|
-
//
|
|
11050
|
-
//
|
|
11051
|
-
|
|
11052
|
-
|
|
11064
|
+
// A cache hit did not compile anything. The earlier build may have
|
|
11065
|
+
// failed, so the worker has no HTML and the canvas is still the sketch.
|
|
11066
|
+
// Compile the saved code before saying the preview is ready.
|
|
11067
|
+
const cachedWithoutLivePreview = completedCached && !activePanelRef?.hasLiveWorkerPreview?.();
|
|
11068
|
+
let previewCompiled = false;
|
|
11069
|
+
if (completedCached) {
|
|
11070
|
+
activePanelRef?.clearCodegenPreviewFresh?.();
|
|
11071
|
+
} else {
|
|
11072
|
+
// Codegen already compiled the Worker. A forced GitLab rebuild races the
|
|
11073
|
+
// new commit and overwrites the iframe with the previous version.
|
|
11074
|
+
activePanelRef?.markCodegenPreviewFresh?.();
|
|
11075
|
+
}
|
|
11076
|
+
if (completedPreviewBuildErr || cachedWithoutLivePreview) {
|
|
11053
11077
|
activePanelRef?.setPreviewLoadingState(true);
|
|
11054
|
-
|
|
11078
|
+
if (cachedWithoutLivePreview) {
|
|
11079
|
+
patchCodegenUiState(generationWidgetId, {
|
|
11080
|
+
generateCodeStatus: `Code already saved${commitShort ? ` (${commitShort})` : ''} — compiling preview…`,
|
|
11081
|
+
});
|
|
11082
|
+
}
|
|
11083
|
+
previewCompiled = (await activePanelRef?.triggerBuildFromRepo(
|
|
11084
|
+
completedPreviewBuildErr ? { force: true } : undefined,
|
|
11085
|
+
)) === true;
|
|
11055
11086
|
} else if (activePanelRef?.hasLiveWorkerPreview?.()) {
|
|
11056
11087
|
// WS already remounted the Worker iframe — a second refreshPreview
|
|
11057
11088
|
// cache-busts the same URL and looks like an extra reload.
|
|
@@ -11065,7 +11096,10 @@ Requirements:
|
|
|
11065
11096
|
activePanelRef?.setPreviewLoadingState(true);
|
|
11066
11097
|
await activePanelRef?.refreshPreview?.({ withRetry: true, skipIfAlreadyShowing: true });
|
|
11067
11098
|
}
|
|
11068
|
-
|
|
11099
|
+
const attemptedRepoBuild = !!(completedPreviewBuildErr || cachedWithoutLivePreview);
|
|
11100
|
+
if (!attemptedRepoBuild || previewCompiled) {
|
|
11101
|
+
activePanelRef?.setPreviewBuildError(null);
|
|
11102
|
+
}
|
|
11069
11103
|
// Show Worker preview on the canvas shape (not the previous Live CDN artifact).
|
|
11070
11104
|
// History alignment below moves the dropdown onto the commit this build belongs to.
|
|
11071
11105
|
shapePreviewSourceByWidgetId = {
|
|
@@ -11073,7 +11107,16 @@ Requirements:
|
|
|
11073
11107
|
[generationWidgetId]: 'preview',
|
|
11074
11108
|
};
|
|
11075
11109
|
syncWidgetShapeLivePreviews();
|
|
11076
|
-
if (!
|
|
11110
|
+
if (cachedWithoutLivePreview && !previewCompiled) {
|
|
11111
|
+
panelChat?.updateLatestCodegenStatusMessage?.(
|
|
11112
|
+
`Code already saved${commitShort ? ` (${commitShort})` : ''}, but the preview could not be compiled.`,
|
|
11113
|
+
);
|
|
11114
|
+
patchCodegenUiState(generationWidgetId, {
|
|
11115
|
+
generateCodeStatus: `Code already saved${commitShort ? ` (${commitShort})` : ''} — preview failed.`,
|
|
11116
|
+
lastGenerationFailed: true,
|
|
11117
|
+
lastGenerationError: 'The saved code could not be compiled into a preview.',
|
|
11118
|
+
});
|
|
11119
|
+
} else if (!completedPreviewBuildErr) {
|
|
11077
11120
|
await applyDesignSchemaDefaultsToPreview(generationWidgetId);
|
|
11078
11121
|
pendingCreatePreviewDefaultsWidgetId = null;
|
|
11079
11122
|
panelChat?.updateLatestCodegenStatusMessage?.(
|
|
@@ -1434,20 +1434,20 @@
|
|
|
1434
1434
|
return builder.buildWidgetFromRepo({ widgetId }, widgetBuilderRequestInit(widgetBuilderPublicBaseUrl));
|
|
1435
1435
|
}
|
|
1436
1436
|
|
|
1437
|
-
export async function triggerBuildFromRepo(options?: { force?: boolean }): Promise<
|
|
1437
|
+
export async function triggerBuildFromRepo(options?: { force?: boolean }): Promise<boolean> {
|
|
1438
1438
|
const forceRebuild = options?.force === true;
|
|
1439
|
-
if (!selectedWidgetId) return;
|
|
1439
|
+
if (!selectedWidgetId) return false;
|
|
1440
1440
|
if (shouldDeferPreviewNetworkWork(forceRebuild)) {
|
|
1441
1441
|
// console.log('[WidgetDetails] triggerBuildFromRepo deferred (background panel)');
|
|
1442
1442
|
previewBuildDeferred = true;
|
|
1443
|
-
return;
|
|
1443
|
+
return false;
|
|
1444
1444
|
}
|
|
1445
1445
|
const hasRepo = !!(normalizeRepositoryId(selectedWidget) || currentRepositoryId);
|
|
1446
1446
|
if (!hasRepo) {
|
|
1447
1447
|
// console.log('[WidgetDetails] triggerBuildFromRepo skipped — widget has no repository yet');
|
|
1448
1448
|
previewLoading = false;
|
|
1449
1449
|
previewError = 'NO_CODE_YET';
|
|
1450
|
-
return;
|
|
1450
|
+
return false;
|
|
1451
1451
|
}
|
|
1452
1452
|
const capturedWidgetId = selectedWidgetId;
|
|
1453
1453
|
const runId = ++buildFromRepoRunId;
|
|
@@ -1459,7 +1459,7 @@
|
|
|
1459
1459
|
|
|
1460
1460
|
if (forceRebuild && isCodegenPreviewFresh()) {
|
|
1461
1461
|
const freshProbe = await probeWorkerReachable(workerPreviewUrl);
|
|
1462
|
-
if (selectedWidgetId !== capturedWidgetId || runId !== buildFromRepoRunId) return;
|
|
1462
|
+
if (selectedWidgetId !== capturedWidgetId || runId !== buildFromRepoRunId) return false;
|
|
1463
1463
|
if (freshProbe === 'ok') {
|
|
1464
1464
|
// console.log('[WidgetDetails] triggerBuildFromRepo: skipping GitLab rebuild — codegen preview is fresh');
|
|
1465
1465
|
dynamicWorkerPreviewUrl = workerPreviewUrl;
|
|
@@ -1467,7 +1467,7 @@
|
|
|
1467
1467
|
inlinePanelView = 'preview';
|
|
1468
1468
|
await forceReloadPreviewIframe(workerPreviewUrl);
|
|
1469
1469
|
dispatch('buildFromRepoSuccess', { widgetId: capturedWidgetId, source: 'codegen-fresh' });
|
|
1470
|
-
return;
|
|
1470
|
+
return true;
|
|
1471
1471
|
}
|
|
1472
1472
|
}
|
|
1473
1473
|
|
|
@@ -1499,18 +1499,18 @@
|
|
|
1499
1499
|
|
|
1500
1500
|
// Step 1: Probe Worker — if widget is already compiled, just show preview (unless forced rebuild)
|
|
1501
1501
|
const probeResult = await probeWorkerReachable(workerPreviewUrl);
|
|
1502
|
-
if (isStaleRun()) return;
|
|
1502
|
+
if (isStaleRun()) return false;
|
|
1503
1503
|
if (!forceRebuild && probeResult === 'ok') {
|
|
1504
1504
|
// console.log('[WidgetDetails] triggerBuildFromRepo: Worker already has widget, loading preview directly');
|
|
1505
1505
|
dispatch('buildFromRepoSuccess', { widgetId: capturedWidgetId });
|
|
1506
1506
|
loadPreviewFromWorker();
|
|
1507
|
-
return;
|
|
1507
|
+
return true;
|
|
1508
1508
|
}
|
|
1509
1509
|
if (probeResult === 'unreachable') {
|
|
1510
1510
|
console.warn('[WidgetDetails] triggerBuildFromRepo: Worker unreachable at', workerPreviewUrl);
|
|
1511
1511
|
previewLoading = false;
|
|
1512
1512
|
previewError = 'Widget Builder is not reachable. Make sure the Worker is running.';
|
|
1513
|
-
return;
|
|
1513
|
+
return false;
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
1516
|
// Skip build-from-repo while codegen is running — WS / refreshPreview will load when ready
|
|
@@ -1518,7 +1518,7 @@
|
|
|
1518
1518
|
// console.log('[WidgetDetails] triggerBuildFromRepo: codegen in progress — deferring build-from-repo');
|
|
1519
1519
|
previewLoading = true;
|
|
1520
1520
|
previewError = null;
|
|
1521
|
-
return;
|
|
1521
|
+
return false;
|
|
1522
1522
|
}
|
|
1523
1523
|
|
|
1524
1524
|
// Step 2: Try build-from-repo with retries
|
|
@@ -1528,10 +1528,10 @@
|
|
|
1528
1528
|
const maxRetries = 3;
|
|
1529
1529
|
const retryDelayMs = 3000;
|
|
1530
1530
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
1531
|
-
if (isStaleRun()) return;
|
|
1531
|
+
if (isStaleRun()) return false;
|
|
1532
1532
|
try {
|
|
1533
1533
|
const buildData = await requestBuildFromRepo(capturedWidgetId);
|
|
1534
|
-
if (isStaleRun()) return;
|
|
1534
|
+
if (isStaleRun()) return false;
|
|
1535
1535
|
|
|
1536
1536
|
// console.log('[WidgetDetails] triggerBuildFromRepo succeeded', { buildTimeMs: buildData?.data?.buildTimeMs ?? buildData?.buildTimeMs, attempt });
|
|
1537
1537
|
previewError = null;
|
|
@@ -1545,9 +1545,9 @@
|
|
|
1545
1545
|
buildData?.data?.repo_head_commit_sha ??
|
|
1546
1546
|
buildData?.repoHeadCommitSha,
|
|
1547
1547
|
});
|
|
1548
|
-
if (isStaleRun()) return;
|
|
1548
|
+
if (isStaleRun()) return false;
|
|
1549
1549
|
loadPreviewFromWorker();
|
|
1550
|
-
return;
|
|
1550
|
+
return true;
|
|
1551
1551
|
} catch (buildErr: any) {
|
|
1552
1552
|
let buildErrorCode = '';
|
|
1553
1553
|
lastBuildErrorMsg = buildErr?.message || 'Build request failed'; // Retired-surface 410 (PLANNER_REMOVED / VM_REMOVED): this running
|
|
@@ -1600,7 +1600,7 @@
|
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
1602
|
// Step 3: All builds failed — decide what to show
|
|
1603
|
-
if (isStaleRun()) return;
|
|
1603
|
+
if (isStaleRun()) return false;
|
|
1604
1604
|
|
|
1605
1605
|
// Forced rebuild (user clicked Rebuild) must surface compile errors — never keep a stale iframe.
|
|
1606
1606
|
const allowStalePreviewRecovery = !forceRebuild;
|
|
@@ -1610,12 +1610,12 @@
|
|
|
1610
1610
|
// console.log('[WidgetDetails] triggerBuildFromRepo: build failed but preview iframe already loaded — keeping preview');
|
|
1611
1611
|
previewError = null;
|
|
1612
1612
|
previewLoading = false;
|
|
1613
|
-
return;
|
|
1613
|
+
return true;
|
|
1614
1614
|
}
|
|
1615
1615
|
|
|
1616
1616
|
if (allowStalePreviewRecovery && (await tryRecoverPreviewFromWorker())) {
|
|
1617
1617
|
// console.log('[WidgetDetails] triggerBuildFromRepo: recovered preview from Worker after build-from-repo failure');
|
|
1618
|
-
return;
|
|
1618
|
+
return true;
|
|
1619
1619
|
}
|
|
1620
1620
|
|
|
1621
1621
|
if (selectedWidgetId === capturedWidgetId) {
|
|
@@ -1628,7 +1628,7 @@
|
|
|
1628
1628
|
previewError = null;
|
|
1629
1629
|
previewLoading = true;
|
|
1630
1630
|
applyPreviewUrlToIframe(sourceArtifactUrl);
|
|
1631
|
-
return;
|
|
1631
|
+
return true;
|
|
1632
1632
|
}
|
|
1633
1633
|
console.warn('[WidgetDetails] js_path artifact not reachable — showing Rebuild');
|
|
1634
1634
|
}
|
|
@@ -1655,6 +1655,7 @@
|
|
|
1655
1655
|
dispatch('buildFromRepoFailed', { widgetId: capturedWidgetId });
|
|
1656
1656
|
console.warn('[WidgetDetails] triggerBuildFromRepo: all build attempts failed for widget', capturedWidgetId);
|
|
1657
1657
|
}
|
|
1658
|
+
return false;
|
|
1658
1659
|
} finally {
|
|
1659
1660
|
if (forceRebuild) isRebuildingPreview = false;
|
|
1660
1661
|
}
|
|
@@ -123,7 +123,7 @@ declare const WidgetDetails: $$__sveltets_2_IsomorphicComponent<{
|
|
|
123
123
|
}) => Promise<void>;
|
|
124
124
|
triggerBuildFromRepo?: (options?: {
|
|
125
125
|
force?: boolean;
|
|
126
|
-
}) => Promise<
|
|
126
|
+
}) => Promise<boolean>;
|
|
127
127
|
enqueueAction?: (action: {
|
|
128
128
|
type: "generate";
|
|
129
129
|
prompt: string;
|
|
@@ -225,7 +225,7 @@ declare const WidgetDetails: $$__sveltets_2_IsomorphicComponent<{
|
|
|
225
225
|
}) => Promise<void>;
|
|
226
226
|
triggerBuildFromRepo: (options?: {
|
|
227
227
|
force?: boolean;
|
|
228
|
-
}) => Promise<
|
|
228
|
+
}) => Promise<boolean>;
|
|
229
229
|
enqueueAction: (action: {
|
|
230
230
|
type: "generate";
|
|
231
231
|
prompt: string;
|
|
@@ -39,6 +39,13 @@ export declare function requestTusComplete(url: string, init: RequestInit, optio
|
|
|
39
39
|
abortSignal?: AbortSignal;
|
|
40
40
|
}): Promise<Response>;
|
|
41
41
|
export declare function shouldUseTusForChatUpload(file: File): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Upload id stored in a Widgetic file URL (`uploads/{owner}/{date}/{uploadId}-{name}`).
|
|
44
|
+
* The page can show that URL in an img tag. It cannot read the bytes: the file host
|
|
45
|
+
* does not send CORS headers, so a browser fetch fails and Retry shows a toast.
|
|
46
|
+
* The API fetches the same URL by this id.
|
|
47
|
+
*/
|
|
48
|
+
export declare function uploadIdFromStoredFileUrl(url: string): string | null;
|
|
42
49
|
/**
|
|
43
50
|
* Upload a chat attachment via multipart (≤10MB) or TUS (>10MB).
|
|
44
51
|
*/
|
|
@@ -209,6 +209,23 @@ function uploadTus(file, config, options = {}) {
|
|
|
209
209
|
export function shouldUseTusForChatUpload(file) {
|
|
210
210
|
return file.size > CHAT_MULTIPART_MAX_BYTES;
|
|
211
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Upload id stored in a Widgetic file URL (`uploads/{owner}/{date}/{uploadId}-{name}`).
|
|
214
|
+
* The page can show that URL in an img tag. It cannot read the bytes: the file host
|
|
215
|
+
* does not send CORS headers, so a browser fetch fails and Retry shows a toast.
|
|
216
|
+
* The API fetches the same URL by this id.
|
|
217
|
+
*/
|
|
218
|
+
export function uploadIdFromStoredFileUrl(url) {
|
|
219
|
+
let pathname = '';
|
|
220
|
+
try {
|
|
221
|
+
pathname = new URL(url).pathname;
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const match = pathname.match(/\/uploads\/[A-Za-z0-9_-]+\/\d{4}-\d{2}-\d{2}\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-/i);
|
|
227
|
+
return match ? match[1] : null;
|
|
228
|
+
}
|
|
212
229
|
function normalizeChatUploadFile(file) {
|
|
213
230
|
if (file.name.toLowerCase().endsWith('.csv') && file.type !== 'text/csv') {
|
|
214
231
|
return new File([file], file.name, {
|