@widgetic/chat 0.1.13 → 0.1.14

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.
@@ -19,6 +19,15 @@
19
19
  onRemove,
20
20
  onView
21
21
  }: Props = $props();
22
+
23
+ function portalToBody(node: HTMLElement) {
24
+ document.body.appendChild(node);
25
+ return {
26
+ destroy() {
27
+ node.remove();
28
+ }
29
+ };
30
+ }
22
31
 
23
32
  // Helper functions
24
33
  function getFileIcon(fileType: string): string {
@@ -246,7 +255,7 @@
246
255
  {#if lightboxAttachment}
247
256
  <!-- svelte-ignore a11y_click_events_have_key_events -->
248
257
  <!-- svelte-ignore a11y_no_static_element_interactions -->
249
- <div class="lightbox-overlay" onclick={closeLightbox}>
258
+ <div class="lightbox-overlay" use:portalToBody onclick={closeLightbox}>
250
259
  <button class="lightbox-close" onclick={closeLightbox} title="Close">✕</button>
251
260
  <!-- svelte-ignore a11y_click_events_have_key_events -->
252
261
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -494,7 +503,7 @@
494
503
  .lightbox-overlay {
495
504
  position: fixed;
496
505
  inset: 0;
497
- z-index: 9999;
506
+ z-index: 100000;
498
507
  display: flex;
499
508
  align-items: center;
500
509
  justify-content: center;
@@ -96,6 +96,10 @@
96
96
  * turn reads as the version it produced instead of a commit hash.
97
97
  */
98
98
  versionLabelByCommitSha?: Record<string, string>;
99
+ /** User prompt text → "Version N", when the turn has no commit line. */
100
+ versionLabelByPrompt?: Record<string, string>;
101
+ /** Version selected in the dropdown. You-are-here follows this number. */
102
+ viewingVersion?: number | null;
99
103
  /** Host is running widget codegen — send button becomes stop. */
100
104
  isGenerating?: boolean;
101
105
  onStopGeneration?: () => void;
@@ -136,12 +140,15 @@
136
140
  updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
137
141
  }
138
142
 
139
- let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, isGenerating = false, onStopGeneration }: Props = $props();
143
+ let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, viewingVersion = null, isGenerating = false, onStopGeneration }: Props = $props();
140
144
 
141
145
  function notifyDraftChange() {
142
146
  onDraftChange?.();
143
147
  }
144
148
 
149
+ const promptVersionLabels = $derived(versionLabelByPrompt ?? {});
150
+ const selectedViewingVersion = $derived(viewingVersion ?? null);
151
+
145
152
  // Apply log suppression immediately
146
153
  $effect(() => {
147
154
  setLogsEnabled(showLogs);
@@ -503,7 +510,7 @@
503
510
  activeConversationId,
504
511
  submittedContent,
505
512
  'user',
506
- persistAttachments.length > 0 ? persistAttachments : userMessage.attachments,
513
+ persistAttachments.length > 0 ? persistAttachments : undefined,
507
514
  );
508
515
  if (saved?.id && saved.id !== userMessage.id) {
509
516
  chatStore.actions.updateMessageId(activeConversationId, userMessage.id, saved.id);
@@ -980,6 +987,16 @@
980
987
  await sendMessage(retryContent);
981
988
  }
982
989
 
990
+ function versionLabelForCommitContent(content?: string | null): string | null {
991
+ const match = String(content || '').match(/(?:Commit:?\s+|commit\s+id:\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
992
+ const sha = match?.[1]?.toLowerCase();
993
+ if (!sha) return null;
994
+ return versionLabelByCommitSha[sha]
995
+ ?? versionLabelByCommitSha[sha.slice(0, 8)]
996
+ ?? versionLabelByCommitSha[sha.slice(0, 7)]
997
+ ?? null;
998
+ }
999
+
983
1000
  async function handleRestoreCheckpoint(messageId: string, messageIndex: number) {
984
1001
  // chatLog('Restore checkpoint requested:', { messageId, messageIndex, conversationId: currentConversationId });
985
1002
 
@@ -1022,21 +1039,19 @@
1022
1039
  }
1023
1040
  }
1024
1041
 
1025
- const updatedMessages = currentMessages.map((msg: any) => ({
1026
- ...msg,
1027
- isWidgetHead: headAssistantId ? msg.id === headAssistantId : false,
1028
- rolledBackAt: null,
1029
- }));
1030
-
1031
- // chatLog(`Restoring to checkpoint user message ${checkpointUserId}, head assistant ${headAssistantId}`);
1032
- chatStore.actions.setMessages(currentConversationId, updatedMessages);
1042
+ const checkpointUser = currentMessages.find((msg: any) => msg.id === checkpointUserId);
1043
+ const headAssistant = currentMessages.find((msg: any) => msg.id === headAssistantId);
1044
+ const sourceLabel = versionLabelForCommitContent(headAssistant?.messageContent) || 'a previous version';
1045
+ const promptCopy = String(checkpointUser?.messageContent || '').trim();
1033
1046
 
1034
1047
  if (onRestoreCheckpointBackend) {
1035
1048
  try {
1036
1049
  const result = await onRestoreCheckpointBackend(currentConversationId, checkpointUserId);
1037
- // chatLog('[Chat] Checkpoint restored on backend:', result);
1038
- if (headAssistantId) {
1039
- markWidgetHeadAtLatestCommit(headAssistantId);
1050
+ const rollback = result?.gitRollback || result?.git_rollback || result?.data?.gitRollback || result?.data?.git_rollback;
1051
+ const newSha = String(rollback?.commitId || rollback?.commit_id || '').trim();
1052
+ if (rollback?.success && newSha && promptCopy) {
1053
+ addUserMessage(promptCopy);
1054
+ addAssistantMessage(`Restored from ${sourceLabel}\n\nCommit: ${newSha.slice(0, 8)}`);
1040
1055
  }
1041
1056
  } catch (backendError) {
1042
1057
  console.error('[Chat] Backend checkpoint restore failed, local state updated:', backendError);
@@ -1173,6 +1188,7 @@
1173
1188
  /^Code generation completed/i.test(trimmed) ||
1174
1189
  /^Compile fix applied/i.test(trimmed) ||
1175
1190
  /^Code saved/i.test(trimmed) ||
1191
+ /^Restored from /i.test(trimmed) ||
1176
1192
  isBackendCodegenSummary(trimmed)
1177
1193
  )) {
1178
1194
  return true;
@@ -1606,6 +1622,8 @@
1606
1622
  showGenerationSummaries={config?.features?.showGenerationSummaries === true}
1607
1623
  widgetHeadCommitSha={widgetHeadCommitSha}
1608
1624
  versionLabelByCommitSha={versionLabelByCommitSha}
1625
+ versionLabelByPrompt={promptVersionLabels}
1626
+ viewingVersion={selectedViewingVersion}
1609
1627
  showCommitMeta={showLogs}
1610
1628
  isGenerating={isGenerating || isLoading}
1611
1629
  onSuggestionSelected={handleSuggestionSelected}
@@ -141,6 +141,10 @@ interface Props {
141
141
  * turn reads as the version it produced instead of a commit hash.
142
142
  */
143
143
  versionLabelByCommitSha?: Record<string, string>;
144
+ /** User prompt text → "Version N", when the turn has no commit line. */
145
+ versionLabelByPrompt?: Record<string, string>;
146
+ /** Version selected in the dropdown. You-are-here follows this number. */
147
+ viewingVersion?: number | null;
144
148
  /** Host is running widget codegen — send button becomes stop. */
145
149
  isGenerating?: boolean;
146
150
  onStopGeneration?: () => void;
@@ -39,6 +39,10 @@
39
39
  * is labelled with the version it produced and the hash is debug-only.
40
40
  */
41
41
  versionLabelByCommitSha?: Record<string, string>;
42
+ /** User prompt text → "Version N", for turns that never saved a commit line. */
43
+ versionLabelByPrompt?: Record<string, string>;
44
+ /** Dropdown selection. The badge follows this version, not only a commit sha. */
45
+ viewingVersion?: number | null;
42
46
  /** When false, hide commit hashes next to the version label (user mode). */
43
47
  showCommitMeta?: boolean;
44
48
  /** True while codegen / send is in flight — suppresses premature Retry. */
@@ -63,6 +67,8 @@
63
67
  showGenerationSummaries = false,
64
68
  widgetHeadCommitSha = null,
65
69
  versionLabelByCommitSha = {},
70
+ versionLabelByPrompt = {},
71
+ viewingVersion = null,
66
72
  showCommitMeta = true,
67
73
  isGenerating = false,
68
74
  onSuggestionSelected,
@@ -155,7 +161,7 @@
155
161
  }
156
162
 
157
163
  function extractCommitFromContent(content: string): string | null {
158
- const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|\(commit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
164
+ const match = content.match(/(?:Commit:?\s+|commit\s+id:\s+|\n\nCommit\s+|\(commit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
159
165
  return match?.[1]?.toLowerCase() ?? null;
160
166
  }
161
167
 
@@ -181,9 +187,22 @@
181
187
  if (/^Code saved/i.test(trimmed) && /(?:Commit:?\s+|Code saved\s*\()[a-f0-9]{7,40}/i.test(trimmed)) {
182
188
  return true;
183
189
  }
190
+ if (isRestoreForkContent(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
191
+ return true;
192
+ }
184
193
  return isBackendCodegenSummary(trimmed);
185
194
  }
186
195
 
196
+ /** A copy appended after Restore. It names the new HEAD commit and does not replace the original turn. */
197
+ function isRestoreForkContent(content?: string | null): boolean {
198
+ return /^Restored from /i.test((content || '').trim());
199
+ }
200
+
201
+ function restoreForkLabel(content?: string | null): string | null {
202
+ const line = (content || '').trim().split('\n')[0]?.trim() || '';
203
+ return /^Restored from /i.test(line) ? line : null;
204
+ }
205
+
187
206
  function turnHasCodegenFailure(turn: ChatTurn): boolean {
188
207
  return turn.replies.some(isCodegenFailure);
189
208
  }
@@ -304,6 +323,7 @@
304
323
  }
305
324
 
306
325
  function canRestoreToMessage(message: ChatMessage): boolean {
326
+ if (isRestoreForkContent(message.messageContent)) return false;
307
327
  if (isHeadCommitReply(message)) return false;
308
328
  if (!message.messageContent) return false;
309
329
  const trimmed = message.messageContent.trim();
@@ -318,7 +338,7 @@
318
338
  }
319
339
 
320
340
  function extractCommitShort(content: string): string | null {
321
- const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
341
+ const match = content.match(/(?:Commit:?\s+|commit\s+id:\s+|\n\nCommit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
322
342
  return match?.[1]?.slice(0, 8) ?? null;
323
343
  }
324
344
 
@@ -333,10 +353,74 @@
333
353
  }
334
354
 
335
355
  /** The version this turn produced, when the host knows it. */
336
- function getTurnVersionLabel(turn: ChatTurn): string | null {
337
- const short = getTurnCommitShort(turn);
356
+ function versionLabelFromSha(turn: ChatTurn): string | null {
357
+ const forkLabel = restoreForkLabel(getTurnCommitReply(turn)?.messageContent);
358
+ if (forkLabel) return forkLabel;
359
+ const short = getTurnOwnCommitShort(turn) || getTurnCommitShort(turn);
338
360
  if (!short) return null;
339
- return versionLabelByCommitSha[short.slice(0, 7).toLowerCase()] ?? null;
361
+ const key7 = short.slice(0, 7).toLowerCase();
362
+ const key8 = short.slice(0, 8).toLowerCase();
363
+ return versionLabelByCommitSha[key7]
364
+ ?? versionLabelByCommitSha[key8]
365
+ ?? versionLabelByCommitSha[short.toLowerCase()]
366
+ ?? null;
367
+ }
368
+
369
+ function versionNumberFromLabel(label: string | null): number | null {
370
+ if (!label) return null;
371
+ const match = label.match(/Version\s+(\d+)/i);
372
+ return match ? Number(match[1]) : null;
373
+ }
374
+
375
+ function getTurnVersionLabel(turn: ChatTurn): string | null {
376
+ const fromSha = versionLabelFromSha(turn);
377
+ if (fromSha) return fromSha;
378
+ const fromPrompt = versionLabelFromPrompt(turn);
379
+ if (fromPrompt) return fromPrompt;
380
+ if (turnHasCodegenFailure(turn)) return null;
381
+ if (!showCommitMetaOnUserTurn(turn)) return null;
382
+ const metaTurns = chatTurns.filter((candidate) =>
383
+ !!candidate.user
384
+ && !turnHasCodegenFailure(candidate)
385
+ && (!!getTurnHeadOrCommitReply(candidate) || canRestoreLegacyUserTurn(candidate)),
386
+ );
387
+ const numbered = metaTurns.map((candidate) => ({
388
+ turn: candidate,
389
+ n: versionNumberFromLabel(versionLabelFromSha(candidate)),
390
+ }));
391
+ const index = numbered.findIndex((row) => row.turn === turn);
392
+ if (index < 0) return null;
393
+ const prev = [...numbered.slice(0, index)].reverse().find((row) => row.n != null);
394
+ const next = numbered.slice(index + 1).find((row) => row.n != null);
395
+ if (prev?.n != null && next?.n != null && next.n - prev.n === 2) return `Version ${prev.n + 1}`;
396
+ if (prev?.n != null && next == null) return `Version ${prev.n + 1}`;
397
+ if (prev == null && next?.n != null && next.n > 1) return `Version ${next.n - 1}`;
398
+ return null;
399
+ }
400
+
401
+ /** Sha of the commit this turn itself produced — never the synthesized Head stand-in. */
402
+ function versionPromptKey(text: string | null | undefined): string {
403
+ return String(text || '').replace(/\s+/g, ' ').trim();
404
+ }
405
+
406
+ function versionLabelFromPrompt(turn: ChatTurn): string | null {
407
+ const key = versionPromptKey(turn.user?.messageContent);
408
+ if (!key) return null;
409
+ return versionLabelByPrompt[key] ?? null;
410
+ }
411
+
412
+ /** The dropdown's version, else the commit sha, decides which turn is current. */
413
+ function isViewingTurn(turn: ChatTurn): boolean {
414
+ if (viewingVersion != null) {
415
+ const versionNumber = versionNumberFromLabel(getTurnVersionLabel(turn));
416
+ if (versionNumber != null) return versionNumber === Number(viewingVersion);
417
+ }
418
+ const reply = getTurnHeadOrCommitReply(turn);
419
+ return !!(reply && isHeadCommitReply(reply));
420
+ }
421
+
422
+ function getTurnOwnCommitShort(turn: ChatTurn): string | null {
423
+ return extractCommitShort(getTurnCommitReply(turn)?.messageContent || '');
340
424
  }
341
425
 
342
426
  function getTurnCommitShort(turn: ChatTurn): string | null {
@@ -358,6 +442,22 @@
358
442
  return null;
359
443
  }
360
444
 
445
+ /**
446
+ * What this turn shipped, in the commit's own words — the title persisted
447
+ * beside `is_commit` ("feat: make the badge blue"). Read off the same reply
448
+ * the chrome's version label and sha come from, so the three always describe
449
+ * one commit: when HEAD has moved past every persisted reply, the chrome's
450
+ * commit reply is a synthesized stand-in with no title, and this returns
451
+ * null rather than an older commit's subject next to HEAD's sha.
452
+ *
453
+ * Rows written before title persistence carry none, so legacy turns simply
454
+ * render no title line.
455
+ */
456
+ function getTurnCommitTitle(turn: ChatTurn): string | null {
457
+ const title = getTurnHeadOrCommitReply(turn)?.commitTitle?.trim();
458
+ return title || null;
459
+ }
460
+
361
461
  function conversationHasCommitReply(): boolean {
362
462
  return chatTurns.some((t) => !!getTurnCommitReply(t));
363
463
  }
@@ -376,8 +476,13 @@
376
476
  * than the one the widget now sits on.
377
477
  */
378
478
  function getFallbackHeadReply(turn: ChatTurn): ChatMessage | null {
479
+ // Only while a generation is in flight, before its commit summary is saved.
480
+ // After Restore, HEAD is a new sha: painting it on the last turn made that
481
+ // bubble look like the restored version had moved. The fork copy carries it instead.
482
+ if (!isGenerating) return null;
379
483
  if (!widgetHeadCommitSha || !turn.user) return null;
380
484
  if (!isLastUserTurn(turn)) return null;
485
+ if (turnHasCodegenFailure(turn)) return null;
381
486
  if (conversationMatchesHeadSha()) return null;
382
487
  const sha = widgetHeadCommitSha.slice(0, 8);
383
488
  return {
@@ -390,7 +495,7 @@
390
495
  }
391
496
 
392
497
  /** Older user turns with no persisted assistant commit — Restore still uses the user message id. */
393
- function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
498
+ function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
394
499
  if (!turn.user) return false;
395
500
  if (getTurnCommitReply(turn)) return false;
396
501
  if (turnHasWidgetHead(turn) || canUndoHeadUserTurn(turn)) return false;
@@ -398,13 +503,35 @@
398
503
  return conversationHasCommitReply();
399
504
  }
400
505
 
506
+ /** Failed last prompt: Restore goes back to the previous successful commit. */
507
+ function canRestoreFailedLastTurn(turn: ChatTurn): boolean {
508
+ if (!turn.user) return false;
509
+ if (!isLastUserTurn(turn)) return false;
510
+ if (!turnHasCodegenFailure(turn)) return false;
511
+ return conversationHasCommitReply();
512
+ }
513
+
514
+ function restoreTargetMessageId(turn: ChatTurn, commitReply: ChatMessage | null): string {
515
+ if (commitReply && canRestoreToMessage(commitReply)) return commitReply.id;
516
+ if (canRestoreFailedLastTurn(turn)) {
517
+ for (let i = chatTurns.length - 1; i >= 0; i--) {
518
+ if (chatTurns[i] === turn) continue;
519
+ const previous = getTurnCommitReply(chatTurns[i]);
520
+ if (previous) return previous.id;
521
+ if (chatTurns[i].user) return chatTurns[i].user!.id;
522
+ }
523
+ }
524
+ return turn.user!.id;
525
+ }
526
+
401
527
  function isCodegenStatusBubble(content?: string | null): boolean {
402
528
  const trimmed = (content || '').trim();
403
529
  return (
404
530
  /^Code generation completed/i.test(trimmed) ||
405
531
  /^Code saved/i.test(trimmed) ||
406
532
  /^Compile fix applied/i.test(trimmed) ||
407
- /^Preview recompiled/i.test(trimmed)
533
+ /^Preview recompiled/i.test(trimmed) ||
534
+ /^Restored from /i.test(trimmed)
408
535
  );
409
536
  }
410
537
 
@@ -421,7 +548,10 @@
421
548
  * Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
422
549
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
423
550
  function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
424
- return !!getTurnHeadOrCommitReply(turn) || canRestoreLegacyUserTurn(turn);
551
+ return !!getTurnHeadOrCommitReply(turn)
552
+ || canRestoreLegacyUserTurn(turn)
553
+ || canRestoreFailedLastTurn(turn)
554
+ || !!versionLabelFromPrompt(turn);
425
555
  }
426
556
 
427
557
  type ChatTurn = {
@@ -449,6 +579,19 @@
449
579
  chatTurns = rebalancePreviewRecompiledAcrossTurns(turns);
450
580
  });
451
581
 
582
+ /** Version dropdown changes which commit is "here" — bring that turn into view. */
583
+ $effect(() => {
584
+ const version = viewingVersion;
585
+ const sha = widgetHeadCommitSha;
586
+ if ((version == null && !sha) || !messagesContainer) return;
587
+ void tick().then(() => {
588
+ const here = messagesContainer?.querySelector('[data-you-are-here="true"]');
589
+ if (here && typeof here.scrollIntoView === 'function') {
590
+ here.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
591
+ }
592
+ });
593
+ });
594
+
452
595
  function messageImpliesAttachedFile(content: string): boolean {
453
596
  return /imaginea ata[sș]at[ăa]|attached (reference )?(image|document|file|pdf|video)|reference image|din imagine|ata[sș]at[ăa]?\s+(document|pdf|fi[sș]ier|video)|attached document/i.test(
454
597
  content,
@@ -886,18 +1029,29 @@
886
1029
  <!-- Conversation turns (user prompt + assistant status grouped) -->
887
1030
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
888
1031
  <div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5"
889
- class:wc-chat-turn-head={turnHasWidgetHead(turn)}
1032
+ class:wc-chat-turn-head={isViewingTurn(turn)}
1033
+ data-you-are-here={isViewingTurn(turn) ? 'true' : undefined}
890
1034
  >
891
1035
  {#if turn.user}
892
1036
  {@const userMsg = turn.user}
893
1037
  {@const commitReply = getTurnHeadOrCommitReply(turn)}
894
- <div class="message-container wc-chat-turn-user ml-auto w-fit max-w-[80%] flex flex-col items-stretch"
1038
+ <div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
895
1039
  class:opacity-75={userMsg._optimistic}
896
1040
  class:opacity-50={userMsg._failed}
897
1041
  class:has-attachments={userMsg.attachments && userMsg.attachments.length > 0}
898
1042
  >
899
- <div
900
- class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text"
1043
+ <div class="wc-user-bubble-row flex w-full items-start gap-2">
1044
+ {#if isViewingTurn(turn)}
1045
+ <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title="This is the version you are looking at">
1046
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1047
+ <path d="M20 6L9 17l-5-5"/>
1048
+ </svg>
1049
+ You are here
1050
+ <span class="wc-head-commit-arrow" aria-hidden="true">→</span>
1051
+ </div>
1052
+ {/if}
1053
+ <div
1054
+ class="message-bubble relative ml-auto w-fit max-w-[80%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
901
1055
  class:p-3={!userMsg.attachments || userMsg.attachments.length === 0}
902
1056
  class:p-0={userMsg.attachments && userMsg.attachments.length > 0}
903
1057
  class:bubble-fit-content={userMsg.attachments && userMsg.attachments.length > 0}
@@ -941,6 +1095,7 @@
941
1095
  </div>
942
1096
  {/if}
943
1097
  </div>
1098
+ </div>
944
1099
  {#if turnNeedsRetry(turn) && !isLoading}
945
1100
  <div class="retry-codegen-row flex justify-end mt-1">
946
1101
  <button
@@ -957,16 +1112,16 @@
957
1112
  </div>
958
1113
  {/if}
959
1114
  {#if showCommitMetaOnUserTurn(turn)}
1115
+ {@const commitTitle = getTurnCommitTitle(turn)}
1116
+ {#if showCommitMeta && commitTitle}
1117
+ <div class="wc-user-commit-title-row flex w-full min-w-0 mt-1">
1118
+ <span class="wc-user-commit-title text-xs text-gray-600" title={commitTitle}>
1119
+ {commitTitle}
1120
+ </span>
1121
+ </div>
1122
+ {/if}
960
1123
  <div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
961
1124
  <div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
962
- {#if commitReply && isHeadCommitReply(commitReply)}
963
- <div class="checkpoint-label wc-head-commit-label" title="This is the version you are looking at">
964
- <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
965
- <path d="M20 6L9 17l-5-5"/>
966
- </svg>
967
- You are here
968
- </div>
969
- {/if}
970
1125
  {#if getTurnVersionLabel(turn)}
971
1126
  <span class="wc-user-version-label text-xs text-gray-500">
972
1127
  {getTurnVersionLabel(turn)}
@@ -978,11 +1133,18 @@
978
1133
  </span>
979
1134
  {/if}
980
1135
  </div>
981
- {#if !isLoading && ((commitReply && canRestoreToMessage(commitReply)) || canRestoreLegacyUserTurn(turn))}
1136
+ {#if !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreLegacyUserTurn(turn) || canRestoreFailedLastTurn(turn))}
1137
+ {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply))}
982
1138
  <button
983
1139
  class="restore-checkpoint-btn shrink-0"
984
- onclick={() => handleRestoreCheckpoint((commitReply && canRestoreToMessage(commitReply) ? commitReply.id : turn.user!.id))}
985
- title="Restore widget code to this prompt's commit"
1140
+ disabled={restoreIsCurrentHead}
1141
+ onclick={() => {
1142
+ if (restoreIsCurrentHead) return;
1143
+ handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
1144
+ }}
1145
+ title={restoreIsCurrentHead
1146
+ ? 'This checkpoint is already HEAD'
1147
+ : 'Restore widget code to this prompt\'s commit'}
986
1148
  >
987
1149
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
988
1150
  <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
@@ -1186,10 +1348,27 @@
1186
1348
  margin-bottom: 0;
1187
1349
  }
1188
1350
 
1351
+ .wc-head-commit-arrow {
1352
+ font-size: 11px;
1353
+ line-height: 1;
1354
+ font-weight: 700;
1355
+ margin-left: 2px;
1356
+ }
1357
+
1189
1358
  .wc-head-commit-meta-ct .wc-head-commit-label {
1190
1359
  margin-top: 0;
1191
1360
  }
1192
1361
 
1362
+ /* What the turn shipped, in the commit's own words. Truncated at the turn's
1363
+ width — the full subject stays in the tooltip — so a prompt-derived title
1364
+ cannot widen the bubble past its 80% cap. */
1365
+ .wc-user-commit-title {
1366
+ display: block;
1367
+ overflow: hidden;
1368
+ text-overflow: ellipsis;
1369
+ white-space: nowrap;
1370
+ }
1371
+
1193
1372
  .restore-checkpoint-row {
1194
1373
  margin-top: 4px;
1195
1374
  }
@@ -1221,6 +1400,12 @@
1221
1400
  color: #555;
1222
1401
  border-color: #bbb;
1223
1402
  }
1403
+
1404
+ .restore-checkpoint-btn:disabled {
1405
+ opacity: 0.45;
1406
+ cursor: not-allowed;
1407
+ pointer-events: none;
1408
+ }
1224
1409
 
1225
1410
  .retry-codegen-btn {
1226
1411
  color: #b91c1c;
@@ -30,6 +30,10 @@ interface Props {
30
30
  * is labelled with the version it produced and the hash is debug-only.
31
31
  */
32
32
  versionLabelByCommitSha?: Record<string, string>;
33
+ /** User prompt text → "Version N", for turns that never saved a commit line. */
34
+ versionLabelByPrompt?: Record<string, string>;
35
+ /** Dropdown selection. The badge follows this version, not only a commit sha. */
36
+ viewingVersion?: number | null;
33
37
  /** When false, hide commit hashes next to the version label (user mode). */
34
38
  showCommitMeta?: boolean;
35
39
  /** True while codegen / send is in flight — suppresses premature Retry. */
@@ -23,6 +23,12 @@ export interface ChatMessage {
23
23
  messageType: 'user' | 'assistant';
24
24
  attachments?: ContentItemOutput[];
25
25
  isCommit?: boolean;
26
+ /** What this commit turn shipped, in the commit's own words ("feat: make
27
+ * the badge blue") — persisted beside `is_commit` by the codegen pipeline
28
+ * and rendered on the turn's commit chrome. Absent on rows written before
29
+ * title persistence, and on a synthesized Head reply (the host's HEAD has
30
+ * moved past every persisted reply, so no title for it exists here). */
31
+ commitTitle?: string | null;
26
32
  userId: string;
27
33
  createdAt: Date;
28
34
  updatedAt: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",