@widgetic/creator 0.4.14 → 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 +153 -51
- package/dist/components/WidgetDetails.svelte +19 -18
- package/dist/components/WidgetDetails.svelte.d.ts +2 -2
- package/dist/utils/freezeWatchdog.js +2 -14
- package/dist/utils/operationStream.js +0 -9
- package/dist/utils/widgeticChatUpload.d.ts +7 -0
- package/dist/utils/widgeticChatUpload.js +17 -0
- package/package.json +1 -1
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,
|
|
@@ -494,10 +495,10 @@
|
|
|
494
495
|
}
|
|
495
496
|
}
|
|
496
497
|
|
|
497
|
-
/** Project context passed from site /canvas
|
|
498
|
+
/** Project context passed from site /canvas. The create SDK only sends projectId. */
|
|
498
499
|
function embeddedWidgetProjectContext(): Record<string, string> {
|
|
499
500
|
if (!embedded || !projectId) return {};
|
|
500
|
-
const ctx: Record<string, string> = { projectFolder: projectId };
|
|
501
|
+
const ctx: Record<string, string> = { projectId, projectFolder: projectId };
|
|
501
502
|
if (organizationId) ctx.organizationId = organizationId;
|
|
502
503
|
if (workspaceType) ctx.workspaceType = workspaceType;
|
|
503
504
|
return ctx;
|
|
@@ -1918,7 +1919,8 @@
|
|
|
1918
1919
|
|
|
1919
1920
|
// A prompt that already has a commit must not reuse that bubble: Version N and
|
|
1920
1921
|
// Version N+1 would share one message, and "You are here" could not mark the older one.
|
|
1921
|
-
// The
|
|
1922
|
+
// The pictures of that sentence go with the retry, including when an earlier
|
|
1923
|
+
// copy of the same sentence is the one that still has them.
|
|
1922
1924
|
let forkUserMessage = false;
|
|
1923
1925
|
let promptForModel = content;
|
|
1924
1926
|
let retryFileAttachments: Array<{ url: string; file_type: string; file_name: string | null; file_size: number | null }> = [];
|
|
@@ -1930,14 +1932,18 @@
|
|
|
1930
1932
|
const convMessages = await handleLoadMessages(convId, widgetId, { scope: 'all' }) || [];
|
|
1931
1933
|
const needle = content.trim();
|
|
1932
1934
|
let matchIndex = -1;
|
|
1935
|
+
let attachmentIndex = -1;
|
|
1933
1936
|
for (let i = convMessages.length - 1; i >= 0; i--) {
|
|
1934
1937
|
const message = convMessages[i];
|
|
1935
1938
|
const type = message.messageType || message.message_type;
|
|
1936
1939
|
const text = String(message.messageContent || message.message_content || '').trim();
|
|
1937
|
-
if (type
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
+
if (type !== 'user' || text !== needle) continue;
|
|
1941
|
+
if (matchIndex < 0) matchIndex = i;
|
|
1942
|
+
const saved = message.attachments || [];
|
|
1943
|
+
if (attachmentIndex < 0 && saved.some((attachment) => attachment?.url && /^https?:\/\//i.test(attachment.url))) {
|
|
1944
|
+
attachmentIndex = i;
|
|
1940
1945
|
}
|
|
1946
|
+
if (matchIndex >= 0 && attachmentIndex >= 0) break;
|
|
1941
1947
|
}
|
|
1942
1948
|
if (matchIndex >= 0) {
|
|
1943
1949
|
let turnEnd = convMessages.length;
|
|
@@ -1965,25 +1971,67 @@
|
|
|
1965
1971
|
(message.messageType || message.message_type) === 'assistant'
|
|
1966
1972
|
&& messageTextHasCommit(message.messageContent || message.message_content),
|
|
1967
1973
|
);
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1974
|
+
// Retry repeats the pictures of that message. A finished version
|
|
1975
|
+
// used to send the sentence alone, so the model was told nothing
|
|
1976
|
+
// was attached and the new bubble had no thumbnail.
|
|
1977
|
+
const attachmentSource = attachmentIndex >= 0 ? attachmentIndex : matchIndex;
|
|
1978
|
+
retryFileAttachments = (convMessages[attachmentSource].attachments || [])
|
|
1979
|
+
.filter((attachment) => attachment.url && /^https?:\/\//i.test(attachment.url))
|
|
1980
|
+
.map((attachment) => ({
|
|
1981
|
+
url: attachment.url,
|
|
1982
|
+
file_type: attachment.file_type || attachment.fileType || 'application/octet-stream',
|
|
1983
|
+
file_name: attachment.file_name || attachment.fileName || null,
|
|
1984
|
+
file_size: attachment.file_size || attachment.fileSize || null,
|
|
1985
|
+
}));
|
|
1979
1986
|
}
|
|
1980
1987
|
}
|
|
1981
1988
|
} catch (retryAttErr) {
|
|
1982
1989
|
console.warn('[Chat→Retry] Could not load the prompt turn for retry:', retryAttErr);
|
|
1983
1990
|
}
|
|
1984
1991
|
}
|
|
1992
|
+
const retryImageAttachments = retryFileAttachments.filter((attachment) => {
|
|
1993
|
+
const type = String(attachment.file_type || '');
|
|
1994
|
+
const name = String(attachment.file_name || '');
|
|
1995
|
+
return type.startsWith('image/') || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(name) || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(attachment.url);
|
|
1996
|
+
});
|
|
1997
|
+
const retryUploadIds = [
|
|
1998
|
+
...new Set(
|
|
1999
|
+
retryImageAttachments
|
|
2000
|
+
.map((attachment) => uploadIdFromStoredFileUrl(attachment.url))
|
|
2001
|
+
.filter((id): id is string => !!id),
|
|
2002
|
+
),
|
|
2003
|
+
];
|
|
2004
|
+
const retryImageDataUrls: string[] = [];
|
|
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;
|
|
2010
|
+
try {
|
|
2011
|
+
const dataUrl = await resolvePromptImageForCodegen(undefined, attachment.url);
|
|
2012
|
+
if (!dataUrl) continue;
|
|
2013
|
+
const compressed = await compressImageDataUrlForCodegen(dataUrl);
|
|
2014
|
+
if (compressed.startsWith('data:image/') && compressed.length > 100) {
|
|
2015
|
+
retryImageDataUrls.push(compressed);
|
|
2016
|
+
}
|
|
2017
|
+
} catch (imageErr) {
|
|
2018
|
+
console.warn('[Chat→Retry] Could not resend an attachment:', imageErr);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
if (retryUploadIds.length > 0) {
|
|
2022
|
+
console.info('[Chat→Retry] Saved image stays on the server', { uploadCount: retryUploadIds.length });
|
|
2023
|
+
}
|
|
1985
2024
|
if (forkUserMessage) {
|
|
1986
|
-
|
|
2025
|
+
const bubbleAttachments = retryImageAttachments.map((attachment, index) => ({
|
|
2026
|
+
id: `retry_${Date.now()}_${index}`,
|
|
2027
|
+
url: attachment.url,
|
|
2028
|
+
file_type: attachment.file_type || 'image/png',
|
|
2029
|
+
file_name: /design-screenshot/i.test(attachment.file_name || '')
|
|
2030
|
+
? `attached-sketch-${index + 1}.png`
|
|
2031
|
+
: (attachment.file_name || `attachment-${index + 1}.png`),
|
|
2032
|
+
file_size: attachment.file_size ?? undefined,
|
|
2033
|
+
}));
|
|
2034
|
+
panelChat?.addUserMessage?.(content, bubbleAttachments.length > 0 ? bubbleAttachments : undefined);
|
|
1987
2035
|
}
|
|
1988
2036
|
|
|
1989
2037
|
await generateCode({
|
|
@@ -1994,8 +2042,12 @@
|
|
|
1994
2042
|
forceRecreateRepo: true,
|
|
1995
2043
|
skipIntentGate: true,
|
|
1996
2044
|
forkUserMessage,
|
|
1997
|
-
attachmentIds:
|
|
1998
|
-
|
|
2045
|
+
attachmentIds: retryUploadIds.length > 0
|
|
2046
|
+
? retryUploadIds
|
|
2047
|
+
: (forkUserMessage ? undefined : (draftUploadIds.length > 0 ? draftUploadIds : undefined)),
|
|
2048
|
+
promptImagesOverride: retryImageDataUrls.length > 0
|
|
2049
|
+
? retryImageDataUrls
|
|
2050
|
+
: (forkUserMessage ? [] : (draftImageUrls.length > 0 ? draftImageUrls : undefined)),
|
|
1999
2051
|
persistFileAttachments: !forkUserMessage && retryFileAttachments.length > 0 ? retryFileAttachments : undefined,
|
|
2000
2052
|
});
|
|
2001
2053
|
}
|
|
@@ -3061,6 +3113,31 @@
|
|
|
3061
3113
|
}
|
|
3062
3114
|
|
|
3063
3115
|
/** Map chat attachments to API items. Inline data/blob files are uploaded to user storage (CDN URL). */
|
|
3116
|
+
function chatAttachmentForSdk(item: {
|
|
3117
|
+
url: string;
|
|
3118
|
+
file_type: string;
|
|
3119
|
+
file_name?: string;
|
|
3120
|
+
file_size?: number;
|
|
3121
|
+
display_order?: number;
|
|
3122
|
+
}) {
|
|
3123
|
+
// The generated client writes camelCase only. Snake_case size is dropped,
|
|
3124
|
+
// the row insert then fails, and the picture is saved as text alone.
|
|
3125
|
+
const fileSize = typeof item.file_size === 'number' && item.file_size > 0
|
|
3126
|
+
? Math.round(item.file_size)
|
|
3127
|
+
: 1;
|
|
3128
|
+
return {
|
|
3129
|
+
url: item.url,
|
|
3130
|
+
file_type: item.file_type,
|
|
3131
|
+
file_name: item.file_name,
|
|
3132
|
+
file_size: fileSize,
|
|
3133
|
+
display_order: item.display_order,
|
|
3134
|
+
fileType: item.file_type,
|
|
3135
|
+
fileName: item.file_name,
|
|
3136
|
+
fileSize,
|
|
3137
|
+
displayOrder: item.display_order,
|
|
3138
|
+
};
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3064
3141
|
async function mapChatAttachmentsForApi(
|
|
3065
3142
|
attachments?: Array<{
|
|
3066
3143
|
url?: string;
|
|
@@ -3086,13 +3163,13 @@
|
|
|
3086
3163
|
});
|
|
3087
3164
|
url = uploaded.url;
|
|
3088
3165
|
// console.log('[Chat→Backend] Uploaded chat File to user storage:', uploaded.id, url.slice(0, 80));
|
|
3089
|
-
items.push({
|
|
3166
|
+
items.push(chatAttachmentForSdk({
|
|
3090
3167
|
url,
|
|
3091
3168
|
file_type: guessAttachmentFileType(url, uploaded.fileName || fileName, uploaded.fileType || att.file_type || att.file.type),
|
|
3092
3169
|
file_name: uploaded.fileName || fileName,
|
|
3093
3170
|
file_size: uploaded.fileSize,
|
|
3094
3171
|
display_order: att.display_order ?? i + 1,
|
|
3095
|
-
});
|
|
3172
|
+
}));
|
|
3096
3173
|
continue;
|
|
3097
3174
|
} catch (err) {
|
|
3098
3175
|
console.warn('[Chat→Backend] Chat File upload failed, skipping attachment:', err);
|
|
@@ -3116,26 +3193,26 @@
|
|
|
3116
3193
|
});
|
|
3117
3194
|
url = uploaded.url;
|
|
3118
3195
|
// console.log('[Chat→Backend] Uploaded chat file to user storage:', uploaded.id, url.slice(0, 80));
|
|
3119
|
-
items.push({
|
|
3196
|
+
items.push(chatAttachmentForSdk({
|
|
3120
3197
|
url,
|
|
3121
3198
|
file_type: guessAttachmentFileType(url, uploaded.fileName || fileName, uploaded.fileType || att.file_type),
|
|
3122
3199
|
file_name: uploaded.fileName || fileName,
|
|
3123
3200
|
file_size: uploaded.fileSize,
|
|
3124
3201
|
display_order: att.display_order ?? i + 1,
|
|
3125
|
-
});
|
|
3202
|
+
}));
|
|
3126
3203
|
continue;
|
|
3127
3204
|
} catch (err) {
|
|
3128
3205
|
console.warn('[Chat→Backend] Chat file upload failed, skipping attachment:', err);
|
|
3129
3206
|
continue;
|
|
3130
3207
|
}
|
|
3131
3208
|
}
|
|
3132
|
-
items.push({
|
|
3209
|
+
items.push(chatAttachmentForSdk({
|
|
3133
3210
|
url,
|
|
3134
3211
|
file_type: guessAttachmentFileType(url, fileName, att.file_type),
|
|
3135
3212
|
file_name: fileName,
|
|
3136
3213
|
file_size: att.file_size ?? undefined,
|
|
3137
3214
|
display_order: att.display_order ?? i + 1,
|
|
3138
|
-
});
|
|
3215
|
+
}));
|
|
3139
3216
|
}
|
|
3140
3217
|
return items;
|
|
3141
3218
|
}
|
|
@@ -3265,8 +3342,8 @@
|
|
|
3265
3342
|
const response = await messagesClient.restoreCheckpointRaw({
|
|
3266
3343
|
conversationId,
|
|
3267
3344
|
restoreCheckpointRequest: {
|
|
3268
|
-
|
|
3269
|
-
|
|
3345
|
+
conversationId,
|
|
3346
|
+
checkpointMessageId,
|
|
3270
3347
|
}
|
|
3271
3348
|
}, widgetBuilderRequestInit(widgetBuilderPreviewBaseUrl()));
|
|
3272
3349
|
const json = await response.raw.json();
|
|
@@ -10331,10 +10408,10 @@ Requirements:
|
|
|
10331
10408
|
}
|
|
10332
10409
|
|
|
10333
10410
|
// Prepare images for the request (if any) — prefer IDs/URLs captured before clearDraft
|
|
10334
|
-
let panelPromptImages = options.
|
|
10335
|
-
?
|
|
10336
|
-
: options.
|
|
10337
|
-
?
|
|
10411
|
+
let panelPromptImages = options.promptImagesOverride && options.promptImagesOverride.length > 0
|
|
10412
|
+
? options.promptImagesOverride
|
|
10413
|
+
: options.forkUserMessage
|
|
10414
|
+
? []
|
|
10338
10415
|
: generationWidgetId === focusedPanelWidgetId
|
|
10339
10416
|
? promptImages
|
|
10340
10417
|
: panelSnap.promptImages;
|
|
@@ -10344,12 +10421,10 @@ Requirements:
|
|
|
10344
10421
|
(url) => typeof url === 'string' && (url.startsWith('data:image/') || /^https?:\/\//i.test(url)) && url.length > 20,
|
|
10345
10422
|
);
|
|
10346
10423
|
const chatAttachmentUrls = options.forkUserMessage ? [] : (panelChat?.getAttachmentDataUrls?.() ?? []);
|
|
10347
|
-
const chatUploadIds =
|
|
10348
|
-
|
|
10349
|
-
: [
|
|
10350
|
-
|
|
10351
|
-
...(panelChat?.getAttachmentUploadIds?.() ?? []),
|
|
10352
|
-
].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);
|
|
10353
10428
|
if (!options.forkUserMessage && chatAttachmentUrls.length > 0 && !(options.promptImagesOverride?.length)) {
|
|
10354
10429
|
const fromChat = chatAttachmentUrls.filter(
|
|
10355
10430
|
(url) => typeof url === 'string' && (url.startsWith('data:image/') || /^https?:\/\//i.test(url)) && url.length > 20,
|
|
@@ -10986,12 +11061,28 @@ Requirements:
|
|
|
10986
11061
|
activePanelRef?.setHasAutoOpenedPreview(true);
|
|
10987
11062
|
pendingCreatePreviewDefaultsWidgetId = generationWidgetId;
|
|
10988
11063
|
suppressNextBuildFromRepoChatMessage = true;
|
|
10989
|
-
//
|
|
10990
|
-
//
|
|
10991
|
-
|
|
10992
|
-
|
|
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) {
|
|
10993
11077
|
activePanelRef?.setPreviewLoadingState(true);
|
|
10994
|
-
|
|
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;
|
|
10995
11086
|
} else if (activePanelRef?.hasLiveWorkerPreview?.()) {
|
|
10996
11087
|
// WS already remounted the Worker iframe — a second refreshPreview
|
|
10997
11088
|
// cache-busts the same URL and looks like an extra reload.
|
|
@@ -11005,7 +11096,10 @@ Requirements:
|
|
|
11005
11096
|
activePanelRef?.setPreviewLoadingState(true);
|
|
11006
11097
|
await activePanelRef?.refreshPreview?.({ withRetry: true, skipIfAlreadyShowing: true });
|
|
11007
11098
|
}
|
|
11008
|
-
|
|
11099
|
+
const attemptedRepoBuild = !!(completedPreviewBuildErr || cachedWithoutLivePreview);
|
|
11100
|
+
if (!attemptedRepoBuild || previewCompiled) {
|
|
11101
|
+
activePanelRef?.setPreviewBuildError(null);
|
|
11102
|
+
}
|
|
11009
11103
|
// Show Worker preview on the canvas shape (not the previous Live CDN artifact).
|
|
11010
11104
|
// History alignment below moves the dropdown onto the commit this build belongs to.
|
|
11011
11105
|
shapePreviewSourceByWidgetId = {
|
|
@@ -11013,7 +11107,16 @@ Requirements:
|
|
|
11013
11107
|
[generationWidgetId]: 'preview',
|
|
11014
11108
|
};
|
|
11015
11109
|
syncWidgetShapeLivePreviews();
|
|
11016
|
-
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) {
|
|
11017
11120
|
await applyDesignSchemaDefaultsToPreview(generationWidgetId);
|
|
11018
11121
|
pendingCreatePreviewDefaultsWidgetId = null;
|
|
11019
11122
|
panelChat?.updateLatestCodegenStatusMessage?.(
|
|
@@ -12040,10 +12143,9 @@ Requirements:
|
|
|
12040
12143
|
return codegenProgressDebugLine(op, stage, pct);
|
|
12041
12144
|
}
|
|
12042
12145
|
|
|
12043
|
-
function freezeProbe(
|
|
12044
|
-
|
|
12045
|
-
|
|
12046
|
-
void fetch(`http://localhost:3000/health?${query}`).catch(() => {});
|
|
12146
|
+
function freezeProbe(_name: string, _detail = ''): void {
|
|
12147
|
+
// The freeze investigation logged every progress tick. A stall still
|
|
12148
|
+
// reaches the API from the watchdog. Ordinary progress does not.
|
|
12047
12149
|
}
|
|
12048
12150
|
|
|
12049
12151
|
function pushCodegenProgressToUi(op: OperationStatus, widgetId: string | null | undefined) {
|
|
@@ -13390,7 +13492,7 @@ Requirements:
|
|
|
13390
13492
|
for (const record of history || []) {
|
|
13391
13493
|
if (record?.version == null) continue;
|
|
13392
13494
|
const key = versionPromptKey(record?.prompt);
|
|
13393
|
-
if (!key) continue;
|
|
13495
|
+
if (!key || labels[key]) continue;
|
|
13394
13496
|
labels[key] = `Version ${record.version}`;
|
|
13395
13497
|
}
|
|
13396
13498
|
return labels;
|
|
@@ -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;
|
|
@@ -197,9 +197,9 @@ export function installFreezeWatchdog() {
|
|
|
197
197
|
const existing = window.__widgeticFreezeWatchdog;
|
|
198
198
|
if (existing)
|
|
199
199
|
return existing;
|
|
200
|
+
// Stall reports only. The per-second heartbeat and the timer-name probes
|
|
201
|
+
// were for the freeze investigation and flooded the API log.
|
|
200
202
|
const probeBase = import.meta.env.DEV ? 'http://localhost:3000/health' : '';
|
|
201
|
-
if (probeBase)
|
|
202
|
-
installDevTimerProbe(probeBase);
|
|
203
203
|
// Both the comment and the variable contain the token. Replace every one.
|
|
204
204
|
const blob = new Blob([WATCHDOG_SOURCE.replaceAll('__PROBE_BASE__', probeBase)], { type: 'text/javascript' });
|
|
205
205
|
const url = URL.createObjectURL(blob);
|
|
@@ -207,23 +207,11 @@ export function installFreezeWatchdog() {
|
|
|
207
207
|
URL.revokeObjectURL(url);
|
|
208
208
|
let lastStatus = '';
|
|
209
209
|
let pendingBreadcrumbs = [];
|
|
210
|
-
let lastHeartbeatAt = 0;
|
|
211
210
|
worker.onmessage = (event) => {
|
|
212
211
|
const data = event.data;
|
|
213
212
|
if (data?.type === 'ping') {
|
|
214
213
|
worker.postMessage({ type: 'pong', status: lastStatus, breadcrumbs: pendingBreadcrumbs });
|
|
215
214
|
pendingBreadcrumbs = [];
|
|
216
|
-
// One line a second, only while this turn can still answer the worker.
|
|
217
|
-
// The last line before a stall is the last second the page thread lived.
|
|
218
|
-
if (probeBase) {
|
|
219
|
-
const now = Date.now();
|
|
220
|
-
if (now - lastHeartbeatAt >= 1000) {
|
|
221
|
-
lastHeartbeatAt = now;
|
|
222
|
-
const second = new Date(now).toISOString().slice(11, 23);
|
|
223
|
-
const shortTimers = window.__widgeticShortTimerCount?.() ?? 0;
|
|
224
|
-
void fetch(`${probeBase}?probe=heartbeat&status=${encodeURIComponent(`${second} short=${shortTimers}`)}`).catch(() => { });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
215
|
}
|
|
228
216
|
else if (data?.type === 'freeze-report' && data.message) {
|
|
229
217
|
console.warn(data.message);
|
|
@@ -137,15 +137,6 @@ export function streamOperationUpdates(operationId, options) {
|
|
|
137
137
|
}
|
|
138
138
|
try {
|
|
139
139
|
const op = JSON.parse(dataLine);
|
|
140
|
-
// Before any UI update. If this line is missing and the
|
|
141
|
-
// heartbeat has already stopped, the thread died earlier.
|
|
142
|
-
if (import.meta.env.DEV) {
|
|
143
|
-
const query = new URLSearchParams({
|
|
144
|
-
probe: 'stream-read',
|
|
145
|
-
status: `${op?.status ?? ''} ${op?.progress ?? ''}`.slice(0, 180),
|
|
146
|
-
});
|
|
147
|
-
void fetch(`http://localhost:3000/health?${query}`).catch(() => { });
|
|
148
|
-
}
|
|
149
140
|
// Only reset idle timer on real operation payloads — SSE
|
|
150
141
|
// `: keepalive` comment frames must not suppress polling fallback
|
|
151
142
|
// when the terminal `completed` event is lost behind a proxy.
|
|
@@ -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, {
|