@widgetic/creator 0.4.14 → 0.4.15

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.
@@ -494,10 +494,10 @@
494
494
  }
495
495
  }
496
496
 
497
- /** Project context passed from site /canvas — stored on new widgets as project_folder. */
497
+ /** Project context passed from site /canvas. The create SDK only sends projectId. */
498
498
  function embeddedWidgetProjectContext(): Record<string, string> {
499
499
  if (!embedded || !projectId) return {};
500
- const ctx: Record<string, string> = { projectFolder: projectId };
500
+ const ctx: Record<string, string> = { projectId, projectFolder: projectId };
501
501
  if (organizationId) ctx.organizationId = organizationId;
502
502
  if (workspaceType) ctx.workspaceType = workspaceType;
503
503
  return ctx;
@@ -1918,7 +1918,8 @@
1918
1918
 
1919
1919
  // A prompt that already has a commit must not reuse that bubble: Version N and
1920
1920
  // Version N+1 would share one message, and "You are here" could not mark the older one.
1921
- // The standing sketch is attached on the server for the model. It is not copied onto the chat row.
1921
+ // The pictures of that sentence go with the retry, including when an earlier
1922
+ // copy of the same sentence is the one that still has them.
1922
1923
  let forkUserMessage = false;
1923
1924
  let promptForModel = content;
1924
1925
  let retryFileAttachments: Array<{ url: string; file_type: string; file_name: string | null; file_size: number | null }> = [];
@@ -1930,14 +1931,18 @@
1930
1931
  const convMessages = await handleLoadMessages(convId, widgetId, { scope: 'all' }) || [];
1931
1932
  const needle = content.trim();
1932
1933
  let matchIndex = -1;
1934
+ let attachmentIndex = -1;
1933
1935
  for (let i = convMessages.length - 1; i >= 0; i--) {
1934
1936
  const message = convMessages[i];
1935
1937
  const type = message.messageType || message.message_type;
1936
1938
  const text = String(message.messageContent || message.message_content || '').trim();
1937
- if (type === 'user' && text === needle) {
1938
- matchIndex = i;
1939
- break;
1939
+ if (type !== 'user' || text !== needle) continue;
1940
+ if (matchIndex < 0) matchIndex = i;
1941
+ const saved = message.attachments || [];
1942
+ if (attachmentIndex < 0 && saved.some((attachment) => attachment?.url && /^https?:\/\//i.test(attachment.url))) {
1943
+ attachmentIndex = i;
1940
1944
  }
1945
+ if (matchIndex >= 0 && attachmentIndex >= 0) break;
1941
1946
  }
1942
1947
  if (matchIndex >= 0) {
1943
1948
  let turnEnd = convMessages.length;
@@ -1965,25 +1970,53 @@
1965
1970
  (message.messageType || message.message_type) === 'assistant'
1966
1971
  && messageTextHasCommit(message.messageContent || message.message_content),
1967
1972
  );
1968
- if (!forkUserMessage) {
1969
- retryFileAttachments = (convMessages[matchIndex].attachments || [])
1970
- .filter((attachment) => attachment.url && /^https?:\/\//i.test(attachment.url))
1971
- .filter((attachment) => !/design-screenshot/i.test(attachment.file_name || attachment.fileName || ''))
1972
- .map((attachment) => ({
1973
- url: attachment.url,
1974
- file_type: attachment.file_type || attachment.fileType || 'application/octet-stream',
1975
- file_name: attachment.file_name || attachment.fileName || null,
1976
- file_size: attachment.file_size || attachment.fileSize || null,
1977
- }));
1978
- }
1973
+ // Retry repeats the pictures of that message. A finished version
1974
+ // used to send the sentence alone, so the model was told nothing
1975
+ // was attached and the new bubble had no thumbnail.
1976
+ const attachmentSource = attachmentIndex >= 0 ? attachmentIndex : matchIndex;
1977
+ retryFileAttachments = (convMessages[attachmentSource].attachments || [])
1978
+ .filter((attachment) => attachment.url && /^https?:\/\//i.test(attachment.url))
1979
+ .map((attachment) => ({
1980
+ url: attachment.url,
1981
+ file_type: attachment.file_type || attachment.fileType || 'application/octet-stream',
1982
+ file_name: attachment.file_name || attachment.fileName || null,
1983
+ file_size: attachment.file_size || attachment.fileSize || null,
1984
+ }));
1979
1985
  }
1980
1986
  }
1981
1987
  } catch (retryAttErr) {
1982
1988
  console.warn('[Chat→Retry] Could not load the prompt turn for retry:', retryAttErr);
1983
1989
  }
1984
1990
  }
1991
+ const retryImageAttachments = retryFileAttachments.filter((attachment) => {
1992
+ const type = String(attachment.file_type || '');
1993
+ const name = String(attachment.file_name || '');
1994
+ 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
+ const retryImageDataUrls: string[] = [];
1997
+ for (const attachment of retryImageAttachments) {
1998
+ try {
1999
+ const dataUrl = await resolvePromptImageForCodegen(undefined, attachment.url);
2000
+ if (!dataUrl) continue;
2001
+ const compressed = await compressImageDataUrlForCodegen(dataUrl);
2002
+ if (compressed.startsWith('data:image/') && compressed.length > 100) {
2003
+ retryImageDataUrls.push(compressed);
2004
+ }
2005
+ } catch (imageErr) {
2006
+ console.warn('[Chat→Retry] Could not resend an attachment:', imageErr);
2007
+ }
2008
+ }
1985
2009
  if (forkUserMessage) {
1986
- panelChat?.addUserMessage?.(content);
2010
+ const bubbleAttachments = retryImageAttachments.map((attachment, index) => ({
2011
+ id: `retry_${Date.now()}_${index}`,
2012
+ url: attachment.url,
2013
+ file_type: attachment.file_type || 'image/png',
2014
+ file_name: /design-screenshot/i.test(attachment.file_name || '')
2015
+ ? `attached-sketch-${index + 1}.png`
2016
+ : (attachment.file_name || `attachment-${index + 1}.png`),
2017
+ file_size: attachment.file_size ?? undefined,
2018
+ }));
2019
+ panelChat?.addUserMessage?.(content, bubbleAttachments.length > 0 ? bubbleAttachments : undefined);
1987
2020
  }
1988
2021
 
1989
2022
  await generateCode({
@@ -1995,7 +2028,9 @@
1995
2028
  skipIntentGate: true,
1996
2029
  forkUserMessage,
1997
2030
  attachmentIds: forkUserMessage ? undefined : (draftUploadIds.length > 0 ? draftUploadIds : undefined),
1998
- promptImagesOverride: forkUserMessage ? [] : (draftImageUrls.length > 0 ? draftImageUrls : undefined),
2031
+ promptImagesOverride: retryImageDataUrls.length > 0
2032
+ ? retryImageDataUrls
2033
+ : (forkUserMessage ? [] : (draftImageUrls.length > 0 ? draftImageUrls : undefined)),
1999
2034
  persistFileAttachments: !forkUserMessage && retryFileAttachments.length > 0 ? retryFileAttachments : undefined,
2000
2035
  });
2001
2036
  }
@@ -3061,6 +3096,31 @@
3061
3096
  }
3062
3097
 
3063
3098
  /** Map chat attachments to API items. Inline data/blob files are uploaded to user storage (CDN URL). */
3099
+ function chatAttachmentForSdk(item: {
3100
+ url: string;
3101
+ file_type: string;
3102
+ file_name?: string;
3103
+ file_size?: number;
3104
+ display_order?: number;
3105
+ }) {
3106
+ // The generated client writes camelCase only. Snake_case size is dropped,
3107
+ // the row insert then fails, and the picture is saved as text alone.
3108
+ const fileSize = typeof item.file_size === 'number' && item.file_size > 0
3109
+ ? Math.round(item.file_size)
3110
+ : 1;
3111
+ return {
3112
+ url: item.url,
3113
+ file_type: item.file_type,
3114
+ file_name: item.file_name,
3115
+ file_size: fileSize,
3116
+ display_order: item.display_order,
3117
+ fileType: item.file_type,
3118
+ fileName: item.file_name,
3119
+ fileSize,
3120
+ displayOrder: item.display_order,
3121
+ };
3122
+ }
3123
+
3064
3124
  async function mapChatAttachmentsForApi(
3065
3125
  attachments?: Array<{
3066
3126
  url?: string;
@@ -3086,13 +3146,13 @@
3086
3146
  });
3087
3147
  url = uploaded.url;
3088
3148
  // console.log('[Chat→Backend] Uploaded chat File to user storage:', uploaded.id, url.slice(0, 80));
3089
- items.push({
3149
+ items.push(chatAttachmentForSdk({
3090
3150
  url,
3091
3151
  file_type: guessAttachmentFileType(url, uploaded.fileName || fileName, uploaded.fileType || att.file_type || att.file.type),
3092
3152
  file_name: uploaded.fileName || fileName,
3093
3153
  file_size: uploaded.fileSize,
3094
3154
  display_order: att.display_order ?? i + 1,
3095
- });
3155
+ }));
3096
3156
  continue;
3097
3157
  } catch (err) {
3098
3158
  console.warn('[Chat→Backend] Chat File upload failed, skipping attachment:', err);
@@ -3116,26 +3176,26 @@
3116
3176
  });
3117
3177
  url = uploaded.url;
3118
3178
  // console.log('[Chat→Backend] Uploaded chat file to user storage:', uploaded.id, url.slice(0, 80));
3119
- items.push({
3179
+ items.push(chatAttachmentForSdk({
3120
3180
  url,
3121
3181
  file_type: guessAttachmentFileType(url, uploaded.fileName || fileName, uploaded.fileType || att.file_type),
3122
3182
  file_name: uploaded.fileName || fileName,
3123
3183
  file_size: uploaded.fileSize,
3124
3184
  display_order: att.display_order ?? i + 1,
3125
- });
3185
+ }));
3126
3186
  continue;
3127
3187
  } catch (err) {
3128
3188
  console.warn('[Chat→Backend] Chat file upload failed, skipping attachment:', err);
3129
3189
  continue;
3130
3190
  }
3131
3191
  }
3132
- items.push({
3192
+ items.push(chatAttachmentForSdk({
3133
3193
  url,
3134
3194
  file_type: guessAttachmentFileType(url, fileName, att.file_type),
3135
3195
  file_name: fileName,
3136
3196
  file_size: att.file_size ?? undefined,
3137
3197
  display_order: att.display_order ?? i + 1,
3138
- });
3198
+ }));
3139
3199
  }
3140
3200
  return items;
3141
3201
  }
@@ -10331,10 +10391,10 @@ Requirements:
10331
10391
  }
10332
10392
 
10333
10393
  // Prepare images for the request (if any) — prefer IDs/URLs captured before clearDraft
10334
- let panelPromptImages = options.forkUserMessage
10335
- ? []
10336
- : options.promptImagesOverride && options.promptImagesOverride.length > 0
10337
- ? options.promptImagesOverride
10394
+ let panelPromptImages = options.promptImagesOverride && options.promptImagesOverride.length > 0
10395
+ ? options.promptImagesOverride
10396
+ : options.forkUserMessage
10397
+ ? []
10338
10398
  : generationWidgetId === focusedPanelWidgetId
10339
10399
  ? promptImages
10340
10400
  : panelSnap.promptImages;
@@ -12040,10 +12100,9 @@ Requirements:
12040
12100
  return codegenProgressDebugLine(op, stage, pct);
12041
12101
  }
12042
12102
 
12043
- function freezeProbe(name: string, detail = ''): void {
12044
- if (!import.meta.env.DEV) return;
12045
- const query = new URLSearchParams({ probe: name, status: detail.slice(0, 180) });
12046
- void fetch(`http://localhost:3000/health?${query}`).catch(() => {});
12103
+ function freezeProbe(_name: string, _detail = ''): void {
12104
+ // The freeze investigation logged every progress tick. A stall still
12105
+ // reaches the API from the watchdog. Ordinary progress does not.
12047
12106
  }
12048
12107
 
12049
12108
  function pushCodegenProgressToUi(op: OperationStatus, widgetId: string | null | undefined) {
@@ -13390,7 +13449,7 @@ Requirements:
13390
13449
  for (const record of history || []) {
13391
13450
  if (record?.version == null) continue;
13392
13451
  const key = versionPromptKey(record?.prompt);
13393
- if (!key) continue;
13452
+ if (!key || labels[key]) continue;
13394
13453
  labels[key] = `Version ${record.version}`;
13395
13454
  }
13396
13455
  return labels;
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "peerDependencies": {