@widgetic/chat 0.1.13 → 0.1.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.
@@ -39,6 +39,16 @@
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
+ /**
45
+ * Every saved version for this widget. When one prompt produced two versions
46
+ * but the chat stored only one user message, the missing older version is
47
+ * shown as its own turn so "You are here" can land on it.
48
+ */
49
+ versionTimeline?: Array<{ version: number; sha: string; prompt: string }>;
50
+ /** Dropdown selection. The badge follows this version, not only a commit sha. */
51
+ viewingVersion?: number | null;
42
52
  /** When false, hide commit hashes next to the version label (user mode). */
43
53
  showCommitMeta?: boolean;
44
54
  /** True while codegen / send is in flight — suppresses premature Retry. */
@@ -63,6 +73,9 @@
63
73
  showGenerationSummaries = false,
64
74
  widgetHeadCommitSha = null,
65
75
  versionLabelByCommitSha = {},
76
+ versionLabelByPrompt = {},
77
+ versionTimeline = [],
78
+ viewingVersion = null,
66
79
  showCommitMeta = true,
67
80
  isGenerating = false,
68
81
  onSuggestionSelected,
@@ -155,7 +168,7 @@
155
168
  }
156
169
 
157
170
  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);
171
+ 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
172
  return match?.[1]?.toLowerCase() ?? null;
160
173
  }
161
174
 
@@ -181,13 +194,121 @@
181
194
  if (/^Code saved/i.test(trimmed) && /(?:Commit:?\s+|Code saved\s*\()[a-f0-9]{7,40}/i.test(trimmed)) {
182
195
  return true;
183
196
  }
197
+ if (isRestoreForkContent(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
198
+ return true;
199
+ }
184
200
  return isBackendCodegenSummary(trimmed);
185
201
  }
186
202
 
203
+ /** A copy appended after Restore. It names the new HEAD commit and does not replace the original turn. */
204
+ function isRestoreForkContent(content?: string | null): boolean {
205
+ return /^Restored from /i.test((content || '').trim());
206
+ }
207
+
208
+ function restoreForkLabel(content?: string | null): string | null {
209
+ const line = (content || '').trim().split('\n')[0]?.trim() || '';
210
+ return /^Restored from /i.test(line) ? line : null;
211
+ }
212
+
187
213
  function turnHasCodegenFailure(turn: ChatTurn): boolean {
188
214
  return turn.replies.some(isCodegenFailure);
189
215
  }
190
216
 
217
+ function commitsMatch(a: string, b: string): boolean {
218
+ const left = a.toLowerCase();
219
+ const right = b.toLowerCase();
220
+ return left === right || left.startsWith(right.slice(0, 7)) || right.startsWith(left.slice(0, 7));
221
+ }
222
+
223
+ /**
224
+ * A retry that reused one user bubble leaves two commits on that turn, so
225
+ * Version 7 and Version 8 share a message and "You are here" cannot land on
226
+ * the older one. Split at each new commit. Later copies keep the prompt text
227
+ * and drop attachments — the sketch stays on the turn that originally had it.
228
+ */
229
+ function splitTurnsByCommit(turns: ChatTurn[]): ChatTurn[] {
230
+ const split: ChatTurn[] = [];
231
+ for (const turn of turns) {
232
+ if (!turn.user) {
233
+ split.push(turn);
234
+ continue;
235
+ }
236
+ let segment: ChatTurn = { user: turn.user, replies: [] };
237
+ let segmentSha: string | null = null;
238
+ for (const reply of turn.replies) {
239
+ const sha = messageHasCommit(reply) ? extractCommitFromContent(reply.messageContent || '') : null;
240
+ if (sha && segmentSha && !commitsMatch(sha, segmentSha)) {
241
+ split.push(segment);
242
+ segment = {
243
+ user: { ...turn.user, id: `retry-fork-${sha}`, attachments: [] },
244
+ replies: [],
245
+ };
246
+ }
247
+ if (sha) segmentSha = sha;
248
+ segment.replies.push(reply);
249
+ }
250
+ split.push(segment);
251
+ }
252
+ return split;
253
+ }
254
+
255
+ /**
256
+ * One user row can carry only the newest commit after a retry. Older versions
257
+ * of that same prompt still exist in history. Give each of them a turn so
258
+ * selecting Version 7 has a place to show "You are here".
259
+ */
260
+ function expandTurnsForSharedPrompts(turns: ChatTurn[]): ChatTurn[] {
261
+ if (!versionTimeline.length) return turns;
262
+ const represented = new Set<string>();
263
+ for (const turn of turns) {
264
+ const short = getTurnOwnCommitShort(turn);
265
+ if (short) represented.add(short.slice(0, 7).toLowerCase());
266
+ }
267
+ const expanded: ChatTurn[] = [];
268
+ for (const turn of turns) {
269
+ const key = versionPromptKey(turn.user?.messageContent);
270
+ if (!turn.user || !key) {
271
+ expanded.push(turn);
272
+ continue;
273
+ }
274
+ const matches = versionTimeline
275
+ .filter((entry) => versionPromptKey(entry.prompt) === key && entry.sha)
276
+ .sort((a, b) => a.version - b.version);
277
+ const latest = matches[matches.length - 1];
278
+ const older = matches.filter((entry) => {
279
+ const sha7 = entry.sha.slice(0, 7).toLowerCase();
280
+ if (latest && sha7 === latest.sha.slice(0, 7).toLowerCase()) return false;
281
+ return !represented.has(sha7);
282
+ });
283
+ for (const entry of older) {
284
+ const sha7 = entry.sha.slice(0, 7).toLowerCase();
285
+ represented.add(sha7);
286
+ const sha8 = entry.sha.slice(0, 8);
287
+ expanded.push({
288
+ user: { ...turn.user, id: `version-fork-${sha7}`, attachments: [] },
289
+ replies: [{
290
+ ...turn.user,
291
+ id: `version-fork-reply-${sha7}`,
292
+ messageType: 'assistant',
293
+ messageContent: `Code generation completed! Commit: ${sha8}`,
294
+ attachments: [],
295
+ }],
296
+ });
297
+ }
298
+ expanded.push(turn);
299
+ }
300
+ return expanded;
301
+ }
302
+
303
+ function visibleUserAttachments(turn: ChatTurn, turnIndex: number) {
304
+ const attachments = turn.user?.attachments || [];
305
+ const hasEarlierUser = chatTurns.slice(0, turnIndex).some((candidate) => candidate.user);
306
+ if (!hasEarlierUser) return attachments;
307
+ // The opening sketch stays on the first turn. Later prompts must not
308
+ // show it again — the model still receives it as standing context.
309
+ return attachments.filter((attachment) => !/design-screenshot/i.test(attachment.file_name || ''));
310
+ }
311
+
191
312
  function rebalancePreviewRecompiledAcrossTurns(turns: ChatTurn[]): ChatTurn[] {
192
313
  const result = turns.map((t) => ({ user: t.user, replies: [...t.replies] }));
193
314
 
@@ -304,6 +425,8 @@
304
425
  }
305
426
 
306
427
  function canRestoreToMessage(message: ChatMessage): boolean {
428
+ if (message.id?.startsWith('version-fork-')) return false;
429
+ if (isRestoreForkContent(message.messageContent)) return false;
307
430
  if (isHeadCommitReply(message)) return false;
308
431
  if (!message.messageContent) return false;
309
432
  const trimmed = message.messageContent.trim();
@@ -318,7 +441,7 @@
318
441
  }
319
442
 
320
443
  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);
444
+ const match = content.match(/(?:Commit:?\s+|commit\s+id:\s+|\n\nCommit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
322
445
  return match?.[1]?.slice(0, 8) ?? null;
323
446
  }
324
447
 
@@ -333,10 +456,74 @@
333
456
  }
334
457
 
335
458
  /** The version this turn produced, when the host knows it. */
336
- function getTurnVersionLabel(turn: ChatTurn): string | null {
337
- const short = getTurnCommitShort(turn);
459
+ function versionLabelFromSha(turn: ChatTurn): string | null {
460
+ const forkLabel = restoreForkLabel(getTurnCommitReply(turn)?.messageContent);
461
+ if (forkLabel) return forkLabel;
462
+ const short = getTurnOwnCommitShort(turn) || getTurnCommitShort(turn);
338
463
  if (!short) return null;
339
- return versionLabelByCommitSha[short.slice(0, 7).toLowerCase()] ?? null;
464
+ const key7 = short.slice(0, 7).toLowerCase();
465
+ const key8 = short.slice(0, 8).toLowerCase();
466
+ return versionLabelByCommitSha[key7]
467
+ ?? versionLabelByCommitSha[key8]
468
+ ?? versionLabelByCommitSha[short.toLowerCase()]
469
+ ?? null;
470
+ }
471
+
472
+ function versionNumberFromLabel(label: string | null): number | null {
473
+ if (!label) return null;
474
+ const match = label.match(/Version\s+(\d+)/i);
475
+ return match ? Number(match[1]) : null;
476
+ }
477
+
478
+ function getTurnVersionLabel(turn: ChatTurn): string | null {
479
+ const fromSha = versionLabelFromSha(turn);
480
+ if (fromSha) return fromSha;
481
+ const fromPrompt = versionLabelFromPrompt(turn);
482
+ if (fromPrompt) return fromPrompt;
483
+ if (turnHasCodegenFailure(turn)) return null;
484
+ if (!showCommitMetaOnUserTurn(turn)) return null;
485
+ const metaTurns = chatTurns.filter((candidate) =>
486
+ !!candidate.user
487
+ && !turnHasCodegenFailure(candidate)
488
+ && (!!getTurnHeadOrCommitReply(candidate) || canRestoreLegacyUserTurn(candidate)),
489
+ );
490
+ const numbered = metaTurns.map((candidate) => ({
491
+ turn: candidate,
492
+ n: versionNumberFromLabel(versionLabelFromSha(candidate)),
493
+ }));
494
+ const index = numbered.findIndex((row) => row.turn === turn);
495
+ if (index < 0) return null;
496
+ const prev = [...numbered.slice(0, index)].reverse().find((row) => row.n != null);
497
+ const next = numbered.slice(index + 1).find((row) => row.n != null);
498
+ if (prev?.n != null && next?.n != null && next.n - prev.n === 2) return `Version ${prev.n + 1}`;
499
+ if (prev?.n != null && next == null) return `Version ${prev.n + 1}`;
500
+ if (prev == null && next?.n != null && next.n > 1) return `Version ${next.n - 1}`;
501
+ return null;
502
+ }
503
+
504
+ /** Sha of the commit this turn itself produced — never the synthesized Head stand-in. */
505
+ function versionPromptKey(text: string | null | undefined): string {
506
+ return String(text || '').replace(/\s+/g, ' ').trim();
507
+ }
508
+
509
+ function versionLabelFromPrompt(turn: ChatTurn): string | null {
510
+ const key = versionPromptKey(turn.user?.messageContent);
511
+ if (!key) return null;
512
+ return versionLabelByPrompt[key] ?? null;
513
+ }
514
+
515
+ /** The dropdown's version, else the commit sha, decides which turn is current. */
516
+ function isViewingTurn(turn: ChatTurn): boolean {
517
+ if (viewingVersion != null) {
518
+ const versionNumber = versionNumberFromLabel(getTurnVersionLabel(turn));
519
+ if (versionNumber != null) return versionNumber === Number(viewingVersion);
520
+ }
521
+ const reply = getTurnHeadOrCommitReply(turn);
522
+ return !!(reply && isHeadCommitReply(reply));
523
+ }
524
+
525
+ function getTurnOwnCommitShort(turn: ChatTurn): string | null {
526
+ return extractCommitShort(getTurnCommitReply(turn)?.messageContent || '');
340
527
  }
341
528
 
342
529
  function getTurnCommitShort(turn: ChatTurn): string | null {
@@ -358,6 +545,22 @@
358
545
  return null;
359
546
  }
360
547
 
548
+ /**
549
+ * What this turn shipped, in the commit's own words — the title persisted
550
+ * beside `is_commit` ("feat: make the badge blue"). Read off the same reply
551
+ * the chrome's version label and sha come from, so the three always describe
552
+ * one commit: when HEAD has moved past every persisted reply, the chrome's
553
+ * commit reply is a synthesized stand-in with no title, and this returns
554
+ * null rather than an older commit's subject next to HEAD's sha.
555
+ *
556
+ * Rows written before title persistence carry none, so legacy turns simply
557
+ * render no title line.
558
+ */
559
+ function getTurnCommitTitle(turn: ChatTurn): string | null {
560
+ const title = getTurnHeadOrCommitReply(turn)?.commitTitle?.trim();
561
+ return title || null;
562
+ }
563
+
361
564
  function conversationHasCommitReply(): boolean {
362
565
  return chatTurns.some((t) => !!getTurnCommitReply(t));
363
566
  }
@@ -376,8 +579,13 @@
376
579
  * than the one the widget now sits on.
377
580
  */
378
581
  function getFallbackHeadReply(turn: ChatTurn): ChatMessage | null {
582
+ // Only while a generation is in flight, before its commit summary is saved.
583
+ // After Restore, HEAD is a new sha: painting it on the last turn made that
584
+ // bubble look like the restored version had moved. The fork copy carries it instead.
585
+ if (!isGenerating) return null;
379
586
  if (!widgetHeadCommitSha || !turn.user) return null;
380
587
  if (!isLastUserTurn(turn)) return null;
588
+ if (turnHasCodegenFailure(turn)) return null;
381
589
  if (conversationMatchesHeadSha()) return null;
382
590
  const sha = widgetHeadCommitSha.slice(0, 8);
383
591
  return {
@@ -390,7 +598,7 @@
390
598
  }
391
599
 
392
600
  /** Older user turns with no persisted assistant commit — Restore still uses the user message id. */
393
- function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
601
+ function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
394
602
  if (!turn.user) return false;
395
603
  if (getTurnCommitReply(turn)) return false;
396
604
  if (turnHasWidgetHead(turn) || canUndoHeadUserTurn(turn)) return false;
@@ -398,13 +606,35 @@
398
606
  return conversationHasCommitReply();
399
607
  }
400
608
 
609
+ /** Failed last prompt: Restore goes back to the previous successful commit. */
610
+ function canRestoreFailedLastTurn(turn: ChatTurn): boolean {
611
+ if (!turn.user) return false;
612
+ if (!isLastUserTurn(turn)) return false;
613
+ if (!turnHasCodegenFailure(turn)) return false;
614
+ return conversationHasCommitReply();
615
+ }
616
+
617
+ function restoreTargetMessageId(turn: ChatTurn, commitReply: ChatMessage | null): string {
618
+ if (commitReply && canRestoreToMessage(commitReply)) return commitReply.id;
619
+ if (canRestoreFailedLastTurn(turn)) {
620
+ for (let i = chatTurns.length - 1; i >= 0; i--) {
621
+ if (chatTurns[i] === turn) continue;
622
+ const previous = getTurnCommitReply(chatTurns[i]);
623
+ if (previous) return previous.id;
624
+ if (chatTurns[i].user) return chatTurns[i].user!.id;
625
+ }
626
+ }
627
+ return turn.user!.id;
628
+ }
629
+
401
630
  function isCodegenStatusBubble(content?: string | null): boolean {
402
631
  const trimmed = (content || '').trim();
403
632
  return (
404
633
  /^Code generation completed/i.test(trimmed) ||
405
634
  /^Code saved/i.test(trimmed) ||
406
635
  /^Compile fix applied/i.test(trimmed) ||
407
- /^Preview recompiled/i.test(trimmed)
636
+ /^Preview recompiled/i.test(trimmed) ||
637
+ /^Restored from /i.test(trimmed)
408
638
  );
409
639
  }
410
640
 
@@ -421,7 +651,10 @@
421
651
  * Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
422
652
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
423
653
  function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
424
- return !!getTurnHeadOrCommitReply(turn) || canRestoreLegacyUserTurn(turn);
654
+ return !!getTurnHeadOrCommitReply(turn)
655
+ || canRestoreLegacyUserTurn(turn)
656
+ || canRestoreFailedLastTurn(turn)
657
+ || !!versionLabelFromPrompt(turn);
425
658
  }
426
659
 
427
660
  type ChatTurn = {
@@ -446,7 +679,23 @@
446
679
  }
447
680
  }
448
681
  if (current) turns.push(current);
449
- chatTurns = rebalancePreviewRecompiledAcrossTurns(turns);
682
+ void versionTimeline;
683
+ chatTurns = expandTurnsForSharedPrompts(
684
+ splitTurnsByCommit(rebalancePreviewRecompiledAcrossTurns(turns)),
685
+ );
686
+ });
687
+
688
+ /** Version dropdown changes which commit is "here" — bring that turn into view. */
689
+ $effect(() => {
690
+ const version = viewingVersion;
691
+ const sha = widgetHeadCommitSha;
692
+ if ((version == null && !sha) || !messagesContainer) return;
693
+ void tick().then(() => {
694
+ const here = messagesContainer?.querySelector('[data-you-are-here="true"]');
695
+ if (here && typeof here.scrollIntoView === 'function') {
696
+ here.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
697
+ }
698
+ });
450
699
  });
451
700
 
452
701
  function messageImpliesAttachedFile(content: string): boolean {
@@ -455,20 +704,23 @@
455
704
  );
456
705
  }
457
706
 
458
- function turnNeedsRetry(turn: ChatTurn): boolean {
707
+ function promptWasRetriedLater(turn: ChatTurn, turnIndex: number): boolean {
708
+ const key = versionPromptKey(turn.user?.messageContent);
709
+ if (!key) return false;
710
+ for (let index = turnIndex + 1; index < chatTurns.length; index++) {
711
+ if (versionPromptKey(chatTurns[index]?.user?.messageContent) === key) return true;
712
+ }
713
+ return false;
714
+ }
715
+
716
+ function turnNeedsRetry(turn: ChatTurn, turnIndex: number): boolean {
459
717
  // Never show Retry while a send/codegen is still running.
460
718
  if (isLoading || isGenerating) return false;
461
- if (turnHasCodegenFailure(turn)) return true;
462
719
  const userMsg = turn.user;
463
- if (!userMsg?.messageContent) return false;
464
- const noAttachments = !userMsg.attachments || userMsg.attachments.length === 0;
465
- if (noAttachments && messageImpliesAttachedFile(userMsg.messageContent) && !getTurnCommitReply(turn)) {
466
- return true;
467
- }
468
- // Stopped / incomplete last prompt only — not mid-flight before the first assistant reply.
469
- // Incomplete without failure/stop is handled by the host via lastGenerationFailed /
470
- // "Generation stopped by user" assistant text (turnHasCodegenFailure).
471
- return false;
720
+ if (!userMsg?.messageContent?.trim()) return false;
721
+ // The earlier copy of a prompt that was already run again stays without Retry.
722
+ if (promptWasRetriedLater(turn, turnIndex)) return false;
723
+ return true;
472
724
  }
473
725
 
474
726
  let visibleMessages = $derived(
@@ -886,21 +1138,33 @@
886
1138
  <!-- Conversation turns (user prompt + assistant status grouped) -->
887
1139
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
888
1140
  <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)}
1141
+ class:wc-chat-turn-head={isViewingTurn(turn)}
1142
+ data-you-are-here={isViewingTurn(turn) ? 'true' : undefined}
890
1143
  >
891
1144
  {#if turn.user}
892
1145
  {@const userMsg = turn.user}
1146
+ {@const shownAttachments = visibleUserAttachments(turn, turnIndex)}
893
1147
  {@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"
1148
+ <div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
895
1149
  class:opacity-75={userMsg._optimistic}
896
1150
  class:opacity-50={userMsg._failed}
897
- class:has-attachments={userMsg.attachments && userMsg.attachments.length > 0}
1151
+ class:has-attachments={shownAttachments.length > 0}
898
1152
  >
899
- <div
900
- class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text"
901
- class:p-3={!userMsg.attachments || userMsg.attachments.length === 0}
902
- class:p-0={userMsg.attachments && userMsg.attachments.length > 0}
903
- class:bubble-fit-content={userMsg.attachments && userMsg.attachments.length > 0}
1153
+ <div class="wc-user-bubble-row flex w-full items-start gap-2">
1154
+ {#if isViewingTurn(turn)}
1155
+ <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title="This is the version you are looking at">
1156
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1157
+ <path d="M20 6L9 17l-5-5"/>
1158
+ </svg>
1159
+ You are here
1160
+ <span class="wc-head-commit-arrow" aria-hidden="true">→</span>
1161
+ </div>
1162
+ {/if}
1163
+ <div
1164
+ class="message-bubble relative ml-auto w-fit max-w-[80%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
1165
+ class:p-3={shownAttachments.length === 0}
1166
+ class:p-0={shownAttachments.length > 0}
1167
+ class:bubble-fit-content={shownAttachments.length > 0}
904
1168
  style="background-color: {isCompleted ? MESSAGE_COLORS.USER_COMPLETED : MESSAGE_COLORS.USER_ACTIVE}; color: {MESSAGE_COLORS.USER_TEXT};"
905
1169
  use:bubbleScrollPadding
906
1170
  >
@@ -925,9 +1189,9 @@
925
1189
  <p class="whitespace-pre-wrap p-3">{userMsg.messageContent}</p>
926
1190
  {/if}
927
1191
  {/if}
928
- {#if userMsg.attachments && userMsg.attachments.length > 0}
1192
+ {#if shownAttachments.length > 0}
929
1193
  <div class="message-attachments-container">
930
- <AttachmentDisplay attachments={userMsg.attachments} variant="message" showPreview={true} />
1194
+ <AttachmentDisplay attachments={shownAttachments} variant="message" showPreview={true} />
931
1195
  </div>
932
1196
  {:else if userMsg.messageContent && messageImpliesAttachedFile(userMsg.messageContent)}
933
1197
  <div class="wc-missing-attachment-placeholder message-attachments-container flex flex-col items-center gap-1 px-3 pb-3">
@@ -941,12 +1205,13 @@
941
1205
  </div>
942
1206
  {/if}
943
1207
  </div>
944
- {#if turnNeedsRetry(turn) && !isLoading}
1208
+ </div>
1209
+ {#if turnNeedsRetry(turn, turnIndex) && !isLoading}
945
1210
  <div class="retry-codegen-row flex justify-end mt-1">
946
1211
  <button
947
1212
  class="retry-codegen-btn"
948
1213
  onclick={() => handleRetryTurn(turn, turnIndex)}
949
- title="Retry this prompt (same as Retry on the error below)"
1214
+ title="Run this prompt again as its own message. The sketch stays with the model, not on the bubble."
950
1215
  >
951
1216
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
952
1217
  <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
@@ -957,16 +1222,16 @@
957
1222
  </div>
958
1223
  {/if}
959
1224
  {#if showCommitMetaOnUserTurn(turn)}
1225
+ {@const commitTitle = getTurnCommitTitle(turn)}
1226
+ {#if showCommitMeta && commitTitle}
1227
+ <div class="wc-user-commit-title-row flex w-full min-w-0 mt-1">
1228
+ <span class="wc-user-commit-title text-xs text-gray-600" title={commitTitle}>
1229
+ {commitTitle}
1230
+ </span>
1231
+ </div>
1232
+ {/if}
960
1233
  <div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
961
1234
  <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
1235
  {#if getTurnVersionLabel(turn)}
971
1236
  <span class="wc-user-version-label text-xs text-gray-500">
972
1237
  {getTurnVersionLabel(turn)}
@@ -978,11 +1243,18 @@
978
1243
  </span>
979
1244
  {/if}
980
1245
  </div>
981
- {#if !isLoading && ((commitReply && canRestoreToMessage(commitReply)) || canRestoreLegacyUserTurn(turn))}
1246
+ {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreLegacyUserTurn(turn) || canRestoreFailedLastTurn(turn))}
1247
+ {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply))}
982
1248
  <button
983
1249
  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"
1250
+ disabled={restoreIsCurrentHead}
1251
+ onclick={() => {
1252
+ if (restoreIsCurrentHead) return;
1253
+ handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
1254
+ }}
1255
+ title={restoreIsCurrentHead
1256
+ ? 'This checkpoint is already HEAD'
1257
+ : 'Restore widget code to this prompt\'s commit'}
986
1258
  >
987
1259
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
988
1260
  <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
@@ -1048,7 +1320,7 @@
1048
1320
  </div>
1049
1321
  {/if}
1050
1322
 
1051
- {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && getRetryPromptForTurn(turn, turnIndex) && !isLoading}
1323
+ {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && turnNeedsRetry(turn, turnIndex)}
1052
1324
  <div class="retry-codegen-row flex justify-start mt-1">
1053
1325
  <button
1054
1326
  class="retry-codegen-btn"
@@ -1186,10 +1458,27 @@
1186
1458
  margin-bottom: 0;
1187
1459
  }
1188
1460
 
1461
+ .wc-head-commit-arrow {
1462
+ font-size: 11px;
1463
+ line-height: 1;
1464
+ font-weight: 700;
1465
+ margin-left: 2px;
1466
+ }
1467
+
1189
1468
  .wc-head-commit-meta-ct .wc-head-commit-label {
1190
1469
  margin-top: 0;
1191
1470
  }
1192
1471
 
1472
+ /* What the turn shipped, in the commit's own words. Truncated at the turn's
1473
+ width — the full subject stays in the tooltip — so a prompt-derived title
1474
+ cannot widen the bubble past its 80% cap. */
1475
+ .wc-user-commit-title {
1476
+ display: block;
1477
+ overflow: hidden;
1478
+ text-overflow: ellipsis;
1479
+ white-space: nowrap;
1480
+ }
1481
+
1193
1482
  .restore-checkpoint-row {
1194
1483
  margin-top: 4px;
1195
1484
  }
@@ -1221,6 +1510,12 @@
1221
1510
  color: #555;
1222
1511
  border-color: #bbb;
1223
1512
  }
1513
+
1514
+ .restore-checkpoint-btn:disabled {
1515
+ opacity: 0.45;
1516
+ cursor: not-allowed;
1517
+ pointer-events: none;
1518
+ }
1224
1519
 
1225
1520
  .retry-codegen-btn {
1226
1521
  color: #b91c1c;
@@ -30,6 +30,20 @@ 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
+ /**
36
+ * Every saved version for this widget. When one prompt produced two versions
37
+ * but the chat stored only one user message, the missing older version is
38
+ * shown as its own turn so "You are here" can land on it.
39
+ */
40
+ versionTimeline?: Array<{
41
+ version: number;
42
+ sha: string;
43
+ prompt: string;
44
+ }>;
45
+ /** Dropdown selection. The badge follows this version, not only a commit sha. */
46
+ viewingVersion?: number | null;
33
47
  /** When false, hide commit hashes next to the version label (user mode). */
34
48
  showCommitMeta?: boolean;
35
49
  /** 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.15",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",