@widgetic/creator 0.4.31 → 0.4.33

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.
@@ -192,6 +192,14 @@
192
192
  type OperationSnapshot
193
193
  } from './utils/generationSharing.js';
194
194
  import { failureNoticeChanges } from './utils/failureNotice.js';
195
+ import { generationVersionAndDocumentFields } from './utils/generationRequestFields.js';
196
+ import {
197
+ generationRefusalText,
198
+ headCommitForComparison,
199
+ operationToFollow,
200
+ readTeamEditingRefusalOf,
201
+ restoreRefusalText
202
+ } from './utils/teamEditingRefusals.js';
195
203
  import { generateEmbedCode, EMBED_FORMATS, type EmbedFormat } from './utils/embedCode.js';
196
204
 
197
205
  function openEmbedTestPage(href: string) {
@@ -216,6 +224,8 @@
216
224
  setHostHandlers,
217
225
  mayUseAddressBar,
218
226
  mayShowAccountBilling,
227
+ maySuggestWidgetName,
228
+ mayNameVersionOrDocumentsInGeneration,
219
229
  mayListenToSiteEvents,
220
230
  announceToSite,
221
231
  eventIsFromCreator,
@@ -3509,16 +3519,23 @@
3509
3519
  checkpointMessageId: string,
3510
3520
  restoreWidgetId?: string | null,
3511
3521
  ): Promise<any> {
3522
+ // The widget whose code the restore puts back, as the panel looks at it when the request is made (the person may look at
3523
+ // another panel while it runs).
3524
+ const widgetIdAtRestore = restoreWidgetId || focusedPanelWidgetId || selectedWidgetId || null;
3512
3525
  try {
3513
3526
  if (!messagesClient) {
3514
3527
  console.warn('[Chat→Backend] messagesClient not initialized');
3515
3528
  return null;
3516
3529
  }
3530
+ // The head the person is looking at. The API refuses the restore, before it deletes a message, when newer code was saved
3531
+ // since (a teammate, another window): rolling back over it would lose it.
3532
+ const expectedHeadSha = widgetIdAtRestore ? shownHeadCommitSha(widgetIdAtRestore) : null;
3517
3533
  const response = await messagesClient.restoreCheckpointRaw({
3518
3534
  conversationId,
3519
3535
  restoreCheckpointRequest: {
3520
3536
  conversationId,
3521
3537
  checkpointMessageId,
3538
+ ...(expectedHeadSha ? { expectedHeadSha } : {}),
3522
3539
  }
3523
3540
  }, widgetBuilderRequestInit(widgetBuilderPreviewBaseUrl()));
3524
3541
  const json = await response.raw.json();
@@ -3668,6 +3685,17 @@
3668
3685
  }
3669
3686
  return data;
3670
3687
  } catch (error) {
3688
+ // The API turns a restore away before it deletes a message or touches a file: while a generation runs (it would commit
3689
+ // over the restored code), after newer code was saved since the person looked, or when it cannot read the head to
3690
+ // compare. The chat and the code are as they were.
3691
+ const refusal = await readTeamEditingRefusalOf(error);
3692
+ const refusalText = restoreRefusalText(refusal, $t);
3693
+ if (refusalText) {
3694
+ console.warn('[Restore] The API refused the restore; nothing was restored', { widgetId: widgetIdAtRestore?.substring(0, 8), refusal });
3695
+ showToast('warning', $t('creator.version.failedToRestoreCheckpoint'), { description: refusalText, duration: 9000 });
3696
+ if (refusal.kind === 'repository_head_changed' && widgetIdAtRestore) void catchUpAfterNewerCode(widgetIdAtRestore);
3697
+ return null;
3698
+ }
3671
3699
  console.error('[Chat→Backend] Failed to restore checkpoint:', error);
3672
3700
  showToast('error', $t('creator.version.failedToRestoreCheckpoint'), {
3673
3701
  description: error instanceof Error ? error.message : $t('creator.general.unknownError'),
@@ -3786,6 +3814,32 @@
3786
3814
  return normalizedA.startsWith(normalizedB.slice(0, 7)) || normalizedB.startsWith(normalizedA.slice(0, 7));
3787
3815
  }
3788
3816
 
3817
+ /**
3818
+ * The head of a widget's code as this panel shows it: the commit the last generation, restore or head probe left in the panel
3819
+ * (or the one this browser kept for the widget). It is the head the person has seen, so a request that names it as
3820
+ * `expectedHeadSha` is refused by the API, before anything is charged, deleted or written, when newer code was saved since
3821
+ * (a teammate, another window). Null when the creator knows no head, or one the API would not accept: then nothing is
3822
+ * compared and the request goes as it always did.
3823
+ */
3824
+ function shownHeadCommitSha(widgetId: string): string | null {
3825
+ return headCommitForComparison(getPanelDisplayState(widgetId).lastCommitId ?? loadCommitIdForWidget(widgetId));
3826
+ }
3827
+
3828
+ /**
3829
+ * Puts the words of a request the API refused back into the chat's message box, so the person can send it again without typing
3830
+ * it again. Only a request that was typed in the chat, and only into an empty box: what the person has typed since stays.
3831
+ */
3832
+ function giveRefusedPromptBack(widgetId: string, refusedPrompt: string): void {
3833
+ try {
3834
+ const panelChat = getChatMethodsForWidget(widgetId);
3835
+ if (!panelChat?.setDraftText || refusedPrompt.trim() === '') return;
3836
+ if ((panelChat.getDraftText?.() ?? '').trim() !== '') return;
3837
+ panelChat.setDraftText(refusedPrompt);
3838
+ } catch (error) {
3839
+ console.warn('[TeamEditing] Could not put the refused request back into the message box', { widgetId, error });
3840
+ }
3841
+ }
3842
+
3789
3843
  function formatCommitShaShort(sha: string | null | undefined): string {
3790
3844
  const normalized = normalizeCommitSha(sha);
3791
3845
  return normalized ? normalized.slice(0, 8) : '—';
@@ -4928,6 +4982,34 @@
4928
4982
  return true;
4929
4983
  }
4930
4984
 
4985
+ /**
4986
+ * A generation that had to create the property (it was not in the schema yet)
4987
+ * still ends with the card, so the next tweak is the control and not another build.
4988
+ */
4989
+ async function attachDesignCardAfterGeneration(widgetId: string, promptText: string): Promise<void> {
4990
+ try {
4991
+ // The generation just wrote design.json. A load that started earlier
4992
+ // still holds the previous schema, so a fresh read is required or the
4993
+ // new property (a font the message just added) never becomes a card.
4994
+ await loadWidgetSchemas(widgetId, { force: true });
4995
+ const ps = getPanelDisplayState(widgetId);
4996
+ const schema = ps.compositionDesignSchema;
4997
+ if (!schema) return;
4998
+ const resolution = resolveDesignIntent(promptText, schema, ps.liveDesignValues ?? {});
4999
+ if (!resolution) return;
5000
+ const card = toDesignControlRequest(
5001
+ resolution,
5002
+ schema,
5003
+ ps.liveDesignValues ?? {},
5004
+ ps.selectedComposition?.id ?? null
5005
+ );
5006
+ getChatMethodsForWidget(widgetId)?.addDesignControlsMessage?.(resolution.summary, card);
5007
+ console.log('[DesignIntent] card after generation', resolution.changes.map((change) => change.propertyId).join(','));
5008
+ } catch (err) {
5009
+ console.warn('[DesignIntent] card after generation skipped', err);
5010
+ }
5011
+ }
5012
+
4931
5013
  /**
4932
5014
  * Jev-backed fallback for the deterministic resolver: when the message names
4933
5015
  * a design property semantically and no literal value can be parsed, ask the
@@ -5275,9 +5357,20 @@
5275
5357
  const panelRef = getWidgetDetailsRef(widgetId);
5276
5358
  const step = widgetId === focusedPanelWidgetId ? widgetDetailsStep : 'create';
5277
5359
  if (step === 'create') {
5278
- // Create shows the generated defaults, not a saved composition.
5279
- // The slides still have to reach both preview iframes.
5360
+ // Create shows the generated defaults, plus a design value the chat
5361
+ // already applied, so a color set here is still there after the
5362
+ // preview reloads.
5280
5363
  postContentItemsToPreviewFrames(widgetId);
5364
+ const ps = getPanelDisplayState(widgetId);
5365
+ const design = ps.liveDesignValues as Record<string, unknown> | undefined;
5366
+ if (design && Object.keys(design).length > 0) {
5367
+ const designMessage = {
5368
+ type: 'widgetic:update',
5369
+ design: flattenDesignValuesForPreview(design),
5370
+ };
5371
+ getWidgetDetailsRef(widgetId)?.sendMessageToPreview(designMessage);
5372
+ resolveLiveWidgetShapeIframe(widgetId)?.contentWindow?.postMessage(designMessage, '*');
5373
+ }
5281
5374
  return;
5282
5375
  }
5283
5376
  if (!panelRef) return;
@@ -5405,16 +5498,15 @@
5405
5498
  ensurePanelPublishHistory(widgetId);
5406
5499
 
5407
5500
  const needsSchemas = !ps.compositionDesignSchema && !ps.compositionContentSchema && !ps.compositionSchemasError;
5408
- const onEditOrEmbed = ps.widgetDetailsStep === 'edit' || ps.widgetDetailsStep === 'embed';
5409
5501
 
5410
- // Load schemas only on Edit/Embed — Create step panels stay hidden and must not compete for API slots
5411
- if (needsSchemas && onEditOrEmbed) {
5502
+ // Create needs the schema too: a chat card (color, number, font) is chosen from it.
5503
+ if (needsSchemas) {
5412
5504
  void scheduleWidgetSchemaLoad(widgetId);
5413
5505
  return;
5414
5506
  }
5415
5507
 
5416
- if (!onEditOrEmbed) return;
5417
-
5508
+ // Create step still needs the composition, so a property edit has a row
5509
+ // to save into and a reload can put that color back on the preview.
5418
5510
  if (!ps.compositions.length || !ps.selectedComposition) {
5419
5511
  void loadCompositionsForPanel(widgetId);
5420
5512
  } else {
@@ -6572,7 +6664,9 @@
6572
6664
  /** This tab's own Stop came after the job had ended: shows how it ended. */
6573
6665
  | 'stop-too-late'
6574
6666
  /** This tab's own Stop could not reach the server: the job may still be running. */
6575
- | 'stop-failed';
6667
+ | 'stop-failed'
6668
+ /** The API refused this tab's request because the person's own generation (another window, another device) is running: the refusal named it. */
6669
+ | 'refused';
6576
6670
 
6577
6671
  /** Forgets the id this browser kept for the widget, when it is this operation's (the id of a newer generation stays). */
6578
6672
  async function forgetStoredOperationId(widgetId: string, operationId: string): Promise<void> {
@@ -6622,7 +6716,8 @@
6622
6716
  // It ended before this tab asked (the tab was away, or the stop came too late): show how it ended. A stop that
6623
6717
  // did go through, whose answer was lost on the way, is on the screen already.
6624
6718
  if (origin === 'stop-failed' && snapshot.status === 'cancelled') return;
6625
- await finishFollowedGeneration(widgetId, operationId, snapshot, origin === 'stored' || origin === 'stop-too-late');
6719
+ // A refused request is waiting for news too: the run it was refused for ended in the meantime, so say how it ended
6720
+ await finishFollowedGeneration(widgetId, operationId, snapshot, origin === 'stored' || origin === 'stop-too-late' || origin === 'refused');
6626
6721
  return;
6627
6722
  }
6628
6723
 
@@ -6656,7 +6751,8 @@
6656
6751
  void getChatMethodsForWidget(widgetId)?.reloadConversationMessages?.();
6657
6752
  // This tab learned of it from the browser's own store: the other tabs may not know of it yet
6658
6753
  if (origin === 'stored') generationChannel?.announceStarted(widgetId, operationId);
6659
- if (widgetId === focusedPanelWidgetId && origin !== 'stop-failed') {
6754
+ // (A refused request has been told already, in the words of its refusal)
6755
+ if (widgetId === focusedPanelWidgetId && origin !== 'stop-failed' && origin !== 'refused') {
6660
6756
  showToast('info', $t('creator.codegen.generationInProgress'), {
6661
6757
  description: $t('creator.codegen.reconnectedToAnActiveCode'),
6662
6758
  duration: 4000
@@ -6816,6 +6912,24 @@
6816
6912
  }
6817
6913
  }
6818
6914
 
6915
+ /**
6916
+ * Brings what the panel knows of a widget's code up to date after the API said that newer code was saved than the person had
6917
+ * seen (a teammate saved, or another window generated): the head the panel names, the version menu and the conversation, read
6918
+ * from the server again. The preview stays as it is: the person looks at the newer code by choosing its version, and the next
6919
+ * request they send names the head they have now.
6920
+ */
6921
+ async function catchUpAfterNewerCode(widgetId: string): Promise<void> {
6922
+ try {
6923
+ await reconcileWidgetHeadCommit(widgetId);
6924
+ const { [widgetId]: _resolved, ...restResolved } = shapeHistoryResolvedByWidgetId;
6925
+ shapeHistoryResolvedByWidgetId = restResolved;
6926
+ await loadPublishHistoryForPanel(widgetId, { silent: true, fresh: true });
6927
+ await getChatMethodsForWidget(widgetId)?.reloadConversationMessages?.();
6928
+ } catch (error) {
6929
+ console.warn('[TeamEditing] Could not bring the widget up to date after newer code was saved', { widgetId, error });
6930
+ }
6931
+ }
6932
+
6819
6933
  /** Follows the generation whose id this browser kept for the widget, when it has one (see `GenerationFollowOrigin`). */
6820
6934
  async function followStoredGeneration(widgetId: string): Promise<void> {
6821
6935
  try {
@@ -10798,6 +10912,11 @@ Requirements:
10798
10912
 
10799
10913
  // console.log('Widget Creator: Starting code generation for widget:', generationWidgetId);
10800
10914
 
10915
+ // What to do once this run has let go of the widget, after the API refused it: follow the person's own generation that holds
10916
+ // the widget, or catch up with the newer code that was saved. It waits for the cleanup in `finally`, because a widget that
10917
+ // still counts as generating in this tab is not followed.
10918
+ let afterRefusal: (() => void) | null = null;
10919
+
10801
10920
  try {
10802
10921
  const generationWidget =
10803
10922
  getWidgetById(generationWidgetId) ||
@@ -10980,6 +11099,21 @@ Requirements:
10980
11099
  ? undefined
10981
11100
  : resolvePlannerModelIdForGeneration(prompt, coderModelForRequest);
10982
11101
  const runtimeLogsForRequest = collectRuntimeLogsForCodegen(generationWidgetId);
11102
+ // The version the person chose to build on, when it is not the head, and the head they chose it on: the API refuses the
11103
+ // request, before it charges anything, when newer code was saved since (a teammate, another window).
11104
+ // (Not with the token of an editor session, a partner's customer: the gateway's door for a session does not list these
11105
+ // fields, nor the text documents, and refuses a request that has one of them, so they are left out of the request
11106
+ // there. A Shopify store's token has no such door. See utils/generationRequestFields.ts.)
11107
+ const mayNameVersionOrDocuments = mayNameVersionOrDocumentsInGeneration(authenticatedClientsToken);
11108
+ const chosenBaseCommitSha =
11109
+ options.compileFixOnly || !mayNameVersionOrDocuments ? null : generationBaseCommitSha(generationWidgetId);
11110
+ const headTheVersionWasChosenOn = chosenBaseCommitSha ? shownHeadCommitSha(generationWidgetId) : null;
11111
+ const versionAndDocumentFields = generationVersionAndDocumentFields({
11112
+ mayNameVersionOrDocuments,
11113
+ baseCommitSha: chosenBaseCommitSha,
11114
+ expectedHeadSha: headTheVersionWasChosenOn,
11115
+ textDocuments: options.forkUserMessage ? undefined : options.textDocuments,
11116
+ });
10983
11117
  // Stopped, or replaced, while the request was being prepared: no job is started for a run nobody waits for
10984
11118
  if (signal.aborted) return;
10985
11119
  // The generated client types this call as void and drops the 202 body.
@@ -10997,9 +11131,10 @@ Requirements:
10997
11131
  : undefined,
10998
11132
  images: imagesToSend,
10999
11133
  attachmentIds: attachmentIdsToSend,
11000
- textDocuments: options.forkUserMessage ? undefined : options.textDocuments,
11134
+ // The text documents, the version to build on and the head it was chosen on: only the ones with something to say,
11135
+ // and none with an editor session's token (see above)
11136
+ ...versionAndDocumentFields,
11001
11137
  runtimeLogs: runtimeLogsForRequest,
11002
- ...(options.compileFixOnly ? {} : { baseCommitSha: generationBaseCommitSha(generationWidgetId) }),
11003
11138
  compileFixOnly: options.compileFixOnly === true,
11004
11139
  skipIntentGate: options.skipIntentGate === true,
11005
11140
  chipIntent: options.chipIntent,
@@ -11049,19 +11184,22 @@ Requirements:
11049
11184
  const schemaProp = collectDesignProperties(psNow.compositionDesignSchema).find(
11050
11185
  (property) => property.id === propertyKey || property.id.endsWith(`.${propertyKey}`)
11051
11186
  );
11052
- const label = schemaProp?.label || propertyKey;
11187
+ const label = schemaProp?.label || (typeof gatedData.label === 'string' ? gatedData.label : '') || propertyKey;
11188
+ const controllerType =
11189
+ schemaProp?.controllerType
11190
+ || (typeof gatedData.controllerType === 'string' ? gatedData.controllerType : '');
11053
11191
  const card: DesignControlRequest = {
11054
11192
  summary: gatedData.reply || $t('creator.general.setTo', { label, value: String(propertyValue) }),
11055
11193
  properties: propertyKey
11056
11194
  ? [{
11057
11195
  id: schemaProp?.id || propertyKey,
11058
11196
  label,
11059
- controllerType: schemaProp?.controllerType ?? '',
11197
+ controllerType,
11060
11198
  value: propertyValue,
11061
11199
  options: schemaProp?.options,
11062
- min: schemaProp?.min,
11063
- max: schemaProp?.max,
11064
- step: schemaProp?.step,
11200
+ min: schemaProp?.min ?? (typeof gatedData.min === 'number' ? gatedData.min : undefined),
11201
+ max: schemaProp?.max ?? (typeof gatedData.max === 'number' ? gatedData.max : undefined),
11202
+ step: schemaProp?.step ?? (typeof gatedData.step === 'number' ? gatedData.step : undefined),
11065
11203
  helpText: schemaProp?.helpText,
11066
11204
  }]
11067
11205
  : [],
@@ -11599,6 +11737,10 @@ Requirements:
11599
11737
  panelChat?.addAssistantMessage(designContractWarning, true);
11600
11738
  }
11601
11739
 
11740
+ if (!options.compileFixOnly && prompt.trim()) {
11741
+ void attachDesignCardAfterGeneration(generationWidgetId, prompt);
11742
+ }
11743
+
11602
11744
  setTimeout(async () => {
11603
11745
  if (!getWidgetDetailsRef(generationWidgetId)) return;
11604
11746
  const activePanelRef = getWidgetDetailsRef(generationWidgetId);
@@ -11708,14 +11850,36 @@ Requirements:
11708
11850
  // Handle concurrent generation conflict (409) — SDK throws ResponseError with .response (native Response)
11709
11851
  const httpStatus = error?.response?.status;
11710
11852
  if (httpStatus === 409) {
11711
- console.warn('Widget Creator: Code generation rejected — already in progress');
11853
+ // The API turned the request away before it charged anything, for one of two reasons it says in the answer: a run holds
11854
+ // the widget's code (the person's own in another window, or a teammate's), or the version to build on was chosen on
11855
+ // code that is no longer the newest. A 409 that says neither keeps the words it always had.
11856
+ const refusal = await readTeamEditingRefusalOf(error);
11857
+ console.warn('Widget Creator: Code generation refused (409)', { widgetId: generationWidgetId.substring(0, 8), refusal });
11858
+ if (options.fromChat && refusal.kind !== 'other') giveRefusedPromptBack(generationWidgetId, prompt);
11859
+
11860
+ if (refusal.kind === 'repository_head_changed') {
11861
+ patchCodegenUiState(generationWidgetId, { generateCodeStatus: 'Ready' });
11862
+ showToast('warning', $t('creator.codegen.newerCodeWasSaved'), {
11863
+ description: $t('creator.codegen.chosenVersionIsOutOfDate'),
11864
+ duration: 10000
11865
+ });
11866
+ afterRefusal = () => void catchUpAfterNewerCode(generationWidgetId);
11867
+ return;
11868
+ }
11869
+
11712
11870
  patchCodegenUiState(generationWidgetId, {
11713
11871
  generateCodeStatus: '⚠️ A code generation is already running. Please wait for it to finish.',
11714
11872
  });
11715
11873
  showToast('warning', $t('creator.codegen.generationAlreadyInProgress'), {
11716
- description: $t('creator.codegen.anotherCodeGenerationIsAlready'),
11717
- duration: 5000
11874
+ description:
11875
+ refusal.kind === 'generation_in_progress'
11876
+ ? generationRefusalText(refusal, $t, get(languageTag))
11877
+ : $t('creator.codegen.anotherCodeGenerationIsAlready'),
11878
+ duration: refusal.kind === 'generation_in_progress' ? 9000 : 5000
11718
11879
  });
11880
+ // The person's own run is followed (its progress shows in the widget, as in any tab that began it), once this run has let go
11881
+ const runToFollow = operationToFollow(refusal);
11882
+ if (runToFollow) afterRefusal = () => void followGeneration(generationWidgetId, runToFollow, 'refused');
11719
11883
  return;
11720
11884
  }
11721
11885
 
@@ -11828,6 +11992,13 @@ Requirements:
11828
11992
  widgetShapeLivePreviewsRef?.requestReload?.(generationWidgetId, { immediate: true });
11829
11993
  });
11830
11994
  }
11995
+ // The API refused this run and the widget is free of it now: follow the person's own generation, or catch up with the
11996
+ // newer code that was saved. (Not awaited: a followed run can take minutes, and the queue behind this one must not wait.)
11997
+ if (afterRefusal) {
11998
+ const actAfterRefusal = afterRefusal;
11999
+ afterRefusal = null;
12000
+ actAfterRefusal();
12001
+ }
11831
12002
  }
11832
12003
  }
11833
12004
  }
@@ -17686,7 +17857,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
17686
17857
  let widgetName = draftName;
17687
17858
  try {
17688
17859
  const sketchForName = screenshot.startsWith('data:image/') ? screenshot : null;
17689
- if (agentClient && (prompt.trim().length >= 2 || sketchForName)) {
17860
+ // (Not in a partner's page: the gateway refuses a session this route, and the draft's name does as well.)
17861
+ if (agentClient && maySuggestWidgetName() && (prompt.trim().length >= 2 || sketchForName)) {
17690
17862
  authStatus = 'Naming widget...';
17691
17863
  const suggestedNameReply = await agentClient.agentWidgetNamePost({
17692
17864
  agentWidgetNamePostRequest: { prompt, ...(sketchForName ? { image: sketchForName } : {}) },
@@ -19544,12 +19716,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19544
19716
  {#if generatingWidgetIds[panelWidgetId] && previewUnblockedByWidgetId[panelWidgetId] && !ps.lastGenerationFailed}
19545
19717
  <span class="codegen-save-spinner inline-block h-3 w-3 shrink-0 animate-spin rounded-full border-2 border-gray-300 border-t-forest-green" aria-hidden="true"></span>
19546
19718
  {/if}
19547
- <div class="generate-code-status-el text-xs flex-1 min-w-0 truncate {ps.lastGenerationFailed && !hourlyLimit ? 'text-red-600' : 'text-gray-500'}">
19548
- {#if ps.lastGenerationFailed && !hourlyLimit}
19549
- <span class="text-red-500 font-medium">{$t('creator.codegen.generationFailed')}</span>
19550
- {:else}
19551
- <span class="text-gray-400">{$t('creator.status.label')}</span> {hourlyLimit ? $t('creator.status.ready') : statusLabel(statusText, $t)}
19552
- {/if}
19719
+ <div class="generate-code-status-el text-xs flex-1 min-w-0 truncate text-gray-500">
19720
+ <span class="text-gray-400">{$t('creator.status.label')}</span> {hourlyLimit || ps.lastGenerationFailed ? $t('creator.status.ready') : statusLabel(statusText, $t)}
19553
19721
  </div>
19554
19722
  </div>
19555
19723
  {#if publishPlanMessageByWidgetId[panelWidgetId]}
@@ -19579,61 +19747,6 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19579
19747
  </div>
19580
19748
  </div>
19581
19749
  {/if}
19582
- {#if ps.lastGenerationFailed && !hourlyLimit}
19583
- <div class="p-3 bg-red-50 border border-red-200" style="border-radius: 0;">
19584
- <p class="text-xs text-red-700 whitespace-pre-wrap">{errorLabel(ps.lastGenerationError, $t)}</p>
19585
- <div class="flex gap-2 mt-3 justify-center">
19586
- {#if isPlanLimitMessage(ps.lastGenerationError)}
19587
- <Button
19588
- onclick={openUpgradePlans}
19589
- variant="default"
19590
- size="sm"
19591
- class="bg-red-600 hover:bg-red-700 text-white rounded-lg"
19592
- >
19593
- {$t('creator.general.upgrade')}
19594
- </Button>
19595
- {:else}
19596
- <Button
19597
- onclick={() => {
19598
- if (!isPanelFocused) focusWidgetPanel(panelWidgetId);
19599
- generateCode({
19600
- prompt: lastGenerationPrompt || ps.codeGenerationPrompt,
19601
- widgetId: panelWidgetId,
19602
- });
19603
- }}
19604
- variant="default"
19605
- size="sm"
19606
- class="bg-red-600 hover:bg-red-700 text-white rounded-lg"
19607
- >
19608
- {$t('creator.common.retry')}
19609
- </Button>
19610
- {/if}
19611
- <Button
19612
- onclick={() => {
19613
- if (!isPanelFocused) focusWidgetPanel(panelWidgetId);
19614
- patchPanelSnapshot(panelWidgetId, {
19615
- lastGenerationFailed: false,
19616
- lastGenerationError: null,
19617
- generateCodeStatus: 'Ready',
19618
- });
19619
- if (isPanelFocused || focusedPanelWidgetId === panelWidgetId) {
19620
- lastGenerationFailed = false;
19621
- lastGenerationError = null;
19622
- generateCodeStatus = 'Ready';
19623
- }
19624
- // A status-only patch does not bump the panel revision, so the
19625
- // banner, which reads that revision, stayed on screen.
19626
- panelDisplayRevision += 1;
19627
- }}
19628
- variant="outline"
19629
- size="sm"
19630
- class="border-gray-300 text-gray-600 hover:bg-gray-50 rounded-lg"
19631
- >
19632
- {$t('creator.general.dismiss')}
19633
- </Button>
19634
- </div>
19635
- </div>
19636
- {/if}
19637
19750
  </div>
19638
19751
  {/if}
19639
19752
  </svelte:fragment>
@@ -19642,12 +19755,65 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19642
19755
  {@const chatUserHeight = rev(panelDisplayRevision, getChatContainerHeightForPanel(panelWidgetId))}
19643
19756
  <!-- svelte-ignore a11y_no_static_element_interactions -->
19644
19757
  <div
19645
- class="generation-scroll-ct flex flex-col h-full min-h-0 overflow-y-auto border-t border-gray-200"
19758
+ class="generation-scroll-ct relative flex flex-col h-full min-h-0 overflow-y-auto border-t border-gray-200"
19646
19759
  style="padding: 0;"
19647
19760
  use:nativeScrollbarPadding={0}
19648
19761
  use:pinScrollToBottom
19649
19762
  onmousedown={() => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); }}
19650
19763
  >
19764
+ {#if ps.lastGenerationFailed && !isHourlyLimitText(ps.lastGenerationError)}
19765
+ <div class="generation-failed-overlay sticky top-0 z-20 mx-3 mt-3 border border-red-200 bg-red-50 p-3">
19766
+ <p class="text-xs text-red-700 whitespace-pre-wrap">{errorLabel(ps.lastGenerationError, $t)}</p>
19767
+ <div class="generation-failed-actions mt-3 flex justify-center gap-2">
19768
+ {#if isPlanLimitMessage(ps.lastGenerationError)}
19769
+ <Button
19770
+ onclick={openUpgradePlans}
19771
+ variant="default"
19772
+ size="sm"
19773
+ class="rounded-lg bg-red-600 text-white hover:bg-red-700"
19774
+ >
19775
+ {$t('creator.general.upgrade')}
19776
+ </Button>
19777
+ {:else}
19778
+ <Button
19779
+ onclick={() => {
19780
+ if (!isPanelFocused) focusWidgetPanel(panelWidgetId);
19781
+ generateCode({
19782
+ prompt: lastGenerationPrompt || ps.codeGenerationPrompt,
19783
+ widgetId: panelWidgetId,
19784
+ });
19785
+ }}
19786
+ variant="default"
19787
+ size="sm"
19788
+ class="rounded-lg bg-red-600 text-white hover:bg-red-700"
19789
+ >
19790
+ {$t('creator.common.retry')}
19791
+ </Button>
19792
+ {/if}
19793
+ <Button
19794
+ onclick={() => {
19795
+ if (!isPanelFocused) focusWidgetPanel(panelWidgetId);
19796
+ patchPanelSnapshot(panelWidgetId, {
19797
+ lastGenerationFailed: false,
19798
+ lastGenerationError: null,
19799
+ generateCodeStatus: 'Ready',
19800
+ });
19801
+ if (isPanelFocused || focusedPanelWidgetId === panelWidgetId) {
19802
+ lastGenerationFailed = false;
19803
+ lastGenerationError = null;
19804
+ generateCodeStatus = 'Ready';
19805
+ }
19806
+ panelDisplayRevision += 1;
19807
+ }}
19808
+ variant="outline"
19809
+ size="sm"
19810
+ class="rounded-lg border-gray-300 text-gray-600 hover:bg-gray-50 focus:outline-none focus:shadow-none"
19811
+ >
19812
+ {$t('creator.general.dismiss')}
19813
+ </Button>
19814
+ </div>
19815
+ </div>
19816
+ {/if}
19651
19817
  {#key panelInstanceKey}
19652
19818
  <div
19653
19819
  class="code-generation-chat-host w-full min-h-0 {chatUserHeight == null ? 'flex-1' : 'shrink-0'}"
@@ -20433,6 +20599,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
20433
20599
  :global(.wc-logo-type path) {
20434
20600
  fill: #0F2010;
20435
20601
  }
20602
+ .generation-failed-overlay :global(button:focus),
20603
+ .generation-failed-overlay :global(button:focus-visible) {
20604
+ outline: none;
20605
+ box-shadow: none;
20606
+ }
20436
20607
  /* Thin scrollbar for canvas dropdown list */
20437
20608
  .wc-canvas-dropdown-items::-webkit-scrollbar {
20438
20609
  width: 4px;