@widgetic/chat 0.1.34 → 0.1.36

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.
@@ -4,13 +4,32 @@
4
4
  import { MESSAGE_COLORS } from '../constants/colors.js';
5
5
  import { chatLog } from '../utils/logger.js';
6
6
  import { isRatableVersionReply, type VersionThumb } from '../utils/versionRatings.js';
7
+ import { isLocalMessageId, restoreBeforeTarget, textToCopy, type TurnRestorePoint } from '../utils/messageActions.js';
7
8
  import { AttachmentDisplay, SuggestionButtons } from './index.js';
8
9
  import CodeBlock from './CodeBlock.svelte';
10
+ import MessageActions from './MessageActions.svelte';
9
11
  import { onDestroy, onMount, tick } from 'svelte';
10
12
  import type { Snippet } from 'svelte';
11
13
  import { useChatLanguage } from '../i18n/language.js';
12
- import { contextTypeLabel, versionLabelText } from '../i18n/labels.js';
14
+ import { CHAT_MESSAGES } from '../i18n/messages.js';
15
+ import { versionLabelText } from '../i18n/labels.js';
13
16
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
17
+ import {
18
+ generationActivityAriaKey,
19
+ generationActivityPhase,
20
+ thoughtDurationSeconds,
21
+ } from '../utils/generationActivity.js';
22
+ import { mapWidgetPlanToPlanCard, type GenerationPlanWire } from '../utils/generationPlan.js';
23
+ // The chat barrel of the design system: its export map resolves `components/<name>` to `<name>.js` only,
24
+ // so a deep `.svelte` path types fine but cannot be resolved by Vite or Node.
25
+ import {
26
+ ActivityRow,
27
+ Message,
28
+ MessageCheckpointRow,
29
+ PlanCard,
30
+ QuestionCard,
31
+ ScrollToBottom
32
+ } from '@widgetic/design-system/components/chat/index';
14
33
 
15
34
  // The words of the messages area, in the language of the chat above
16
35
  const { t } = useChatLanguage();
@@ -23,8 +42,13 @@
23
42
  class?: string;
24
43
  messages: ChatMessage[];
25
44
  isLoading?: boolean;
26
- /** True after the conversation list/messages finished initializing — gates the empty state so suggestions never flash at mount. */
45
+ /** True after the conversation list/messages finished initializing. */
27
46
  isInitialized?: boolean;
47
+ /**
48
+ * The empty-state suggestions. Stays false from the first paint.
49
+ * The parent sets it only after the message read, and only when that read was empty.
50
+ */
51
+ showEmptyState?: boolean;
28
52
  context: ChatContext;
29
53
  isCompleted?: boolean;
30
54
  /**
@@ -54,22 +78,29 @@
54
78
  /**
55
79
  * Every saved version for this widget. When one prompt produced two versions
56
80
  * but the chat stored only one user message, the missing older version is
57
- * shown as its own turn so "You are here" can land on it.
81
+ * shown as its own turn, so each version has its own place in the list.
58
82
  */
59
83
  versionTimeline?: Array<{ version: number; sha: string; prompt: string }>;
60
- /** Dropdown selection. The badge follows this version, not only a commit sha. */
61
- viewingVersion?: number | null;
62
84
  /** When false, hide commit hashes next to the version label (user mode). */
63
85
  showCommitMeta?: boolean;
64
- /** True while codegen / send is in flight — suppresses premature Retry. */
86
+ /** True while codegen / send is in flight — no icons are drawn under the last message and no restore is offered. */
65
87
  isGenerating?: boolean;
66
88
  /** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
67
89
  generationStream?: string;
90
+ /** Rolling tail of streamed model reasoning during codegen. */
91
+ generationThinking?: string;
92
+ /** Gateway build plan while codegen runs; `null` hides the card. */
93
+ generationPlan?: GenerationPlanWire | null;
68
94
  onSuggestionSelected?: (suggestion: string) => void;
95
+ /**
96
+ * Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
97
+ * put the widget back to how it was BEFORE that message: called with the id of the saved reply that stands for that earlier state
98
+ * and its place in `messages`. Without it no restore icon is drawn.
99
+ */
69
100
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
70
101
  /**
71
- * Gives each version a thumbs up and a thumbs down next to its name. Called with the id of the assistant message that
72
- * announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
102
+ * Gives the last message a thumbs up and a thumbs down (next to copy and regenerate). Called with the id of the assistant message
103
+ * that announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
73
104
  */
74
105
  onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
75
106
  /** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
@@ -99,7 +130,8 @@
99
130
  class: className = '',
100
131
  messages,
101
132
  isLoading = false,
102
- isInitialized = true,
133
+ isInitialized = false,
134
+ showEmptyState = false,
103
135
  context,
104
136
  isCompleted = false,
105
137
  enableAutoCodeDetection = false,
@@ -108,10 +140,11 @@
108
140
  versionLabelByCommitSha = {},
109
141
  versionLabelByPrompt = {},
110
142
  versionTimeline = [],
111
- viewingVersion = null,
112
143
  showCommitMeta = true,
113
144
  isGenerating = false,
114
145
  generationStream = '',
146
+ generationThinking = '',
147
+ generationPlan = null,
115
148
  onSuggestionSelected,
116
149
  onRestoreCheckpoint,
117
150
  onRateVersion,
@@ -285,9 +318,9 @@
285
318
 
286
319
  /**
287
320
  * A retry that reused one user bubble leaves two commits on that turn, so
288
- * Version 7 and Version 8 share a message and "You are here" cannot land on
289
- * the older one. Split at each new commit. Later copies keep the prompt text
290
- * and drop attachments — the sketch stays on the turn that originally had it.
321
+ * Version 7 and Version 8 share a message and the older one has no turn (and
322
+ * no version label) of its own. Split at each new commit. Later copies keep the
323
+ * prompt text and drop attachments — the sketch stays on the turn that originally had it.
291
324
  */
292
325
  function splitTurnsByCommit(turns: ChatTurn[]): ChatTurn[] {
293
326
  const split: ChatTurn[] = [];
@@ -317,8 +350,8 @@
317
350
 
318
351
  /**
319
352
  * One user row can carry only the newest commit after a retry. Older versions
320
- * of that same prompt still exist in history. Give each of them a turn so
321
- * selecting Version 7 has a place to show "You are here".
353
+ * of that same prompt still exist in history. Give each of them a turn, so
354
+ * Version 7 is on the list with its own version label.
322
355
  */
323
356
  function expandTurnsForSharedPrompts(turns: ChatTurn[]): ChatTurn[] {
324
357
  if (!versionTimeline.length) return turns;
@@ -494,18 +527,6 @@
494
527
  );
495
528
  }
496
529
 
497
- function canRestoreToMessage(message: ChatMessage): boolean {
498
- if (message.id?.startsWith('version-fork-')) return false;
499
- if (isRestoreForkContent(message.messageContent)) return false;
500
- if (isHeadCommitReply(message)) return false;
501
- if (!message.messageContent) return false;
502
- const trimmed = message.messageContent.trim();
503
- if (/^Preview recompiled/i.test(trimmed)) return false;
504
- return message.messageType === 'assistant'
505
- && messageHasCommit(message)
506
- && !isCodegenFailure(message);
507
- }
508
-
509
530
  function canUndoHeadUserTurn(turn: ChatTurn): boolean {
510
531
  return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
511
532
  }
@@ -604,16 +625,6 @@
604
625
  );
605
626
  }
606
627
 
607
- /** The dropdown's version, else the commit sha, decides which turn is current. */
608
- function isViewingTurn(turn: ChatTurn): boolean {
609
- if (viewingVersion != null) {
610
- const versionNumber = versionNumberFromLabel(getTurnVersionLabel(turn));
611
- if (versionNumber != null) return versionNumber === Number(viewingVersion);
612
- }
613
- const reply = getTurnHeadOrCommitReply(turn);
614
- return !!(reply && isHeadCommitReply(reply));
615
- }
616
-
617
628
  function getTurnOwnCommitShort(turn: ChatTurn): string | null {
618
629
  return extractCommitShort(getTurnCommitReply(turn)?.messageContent || '');
619
630
  }
@@ -717,17 +728,31 @@
717
728
  return conversationHasCommitReply();
718
729
  }
719
730
 
720
- function restoreTargetMessageId(turn: ChatTurn, commitReply: ChatMessage | null): string {
721
- if (commitReply && canRestoreToMessage(commitReply)) return commitReply.id;
722
- if (canRestoreFailedLastTurn(turn)) {
723
- for (let i = chatTurns.length - 1; i >= 0; i--) {
724
- if (chatTurns[i] === turn) continue;
725
- const previous = getTurnCommitReply(chatTurns[i]);
726
- if (previous) return previous.id;
727
- if (chatTurns[i].user) return chatTurns[i].user!.id;
728
- }
731
+ /**
732
+ * What this turn is as a place to go back to (see `TurnRestorePoint`): a turn whose saved reply announced a commit is a version.
733
+ * The ids the host's backend cannot be asked for are `blocked`, and nothing is offered past them: older versions the chat only lists
734
+ * (they have no saved reply of their own), versions a restore has already undone, and messages the host has not saved yet.
735
+ */
736
+ function restorePointOf(turn: ChatTurn): TurnRestorePoint {
737
+ const reply = getTurnCommitReply(turn);
738
+ if (!turn.user || !reply) return { kind: 'none' };
739
+ if (
740
+ turn.user.id.startsWith('version-fork-')
741
+ || reply.id.startsWith('version-fork-')
742
+ || !!turn.user.rolledBackAt
743
+ || !!reply.rolledBackAt
744
+ || isLocalMessageId(turn.user.id)
745
+ || isLocalMessageId(reply.id)
746
+ ) {
747
+ return { kind: 'blocked' };
729
748
  }
730
- return turn.user!.id;
749
+ return {
750
+ kind: 'version',
751
+ replyId: reply.id,
752
+ // The copy a restore appends is a place to go back to, but not a message of the person's to go back before
753
+ wearsIcon: !turnIsRestoreEcho(turn),
754
+ isLatest: isHeadCommitReply(reply),
755
+ };
731
756
  }
732
757
 
733
758
  function isCodegenStatusBubble(content?: string | null): boolean {
@@ -753,8 +778,8 @@
753
778
  return !isGenerationSummary(reply);
754
779
  }
755
780
 
756
- /** Show commit chrome + Restore Checkpoint on the user prompt whenever the turn has a commit.
757
- * Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
781
+ /** Show the commit chrome (title, version label, the restore icon) on the user prompt whenever the turn has a commit.
782
+ * Previously this was gated to Debug OFF (assistant reply hidden), but we want it
758
783
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
759
784
  function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
760
785
  return !!getTurnHeadOrCommitReply(turn)
@@ -808,71 +833,25 @@
808
833
  );
809
834
  });
810
835
 
811
- /**
812
- * Brings `element` into view inside `container` the way `element.scrollIntoView({ block: 'nearest', behavior: 'smooth' })`
813
- * does, but moves the container only. `scrollIntoView` scrolls every scrollable ancestor as well, and one of them is the
814
- * page the chat is on (a partner's page, when the creator is mounted into it).
815
- */
816
- function scrollIntoViewWithin(container: HTMLElement, element: Element) {
817
- const containerBox = container.getBoundingClientRect();
818
- const elementBox = element.getBoundingClientRect();
819
- let distance = 0;
820
- if (elementBox.top < containerBox.top) {
821
- // It starts above the visible part: scroll up to its top.
822
- distance = elementBox.top - containerBox.top;
823
- } else if (elementBox.bottom > containerBox.bottom) {
824
- // It ends below the visible part: scroll down just enough, but never past its own top (when it is taller than the container).
825
- distance = Math.min(elementBox.bottom - containerBox.bottom, elementBox.top - containerBox.top);
826
- }
827
- if (distance !== 0) container.scrollBy({ top: distance, behavior: 'smooth' });
828
- }
836
+ /** One entry per turn, in the order of `chatTurns`. */
837
+ const restorePoints = $derived(chatTurns.map(restorePointOf));
829
838
 
830
- /**
831
- * The selected version's turn is current. Pinning the list to the bottom
832
- * would hide it again whenever messages finish loading.
833
- */
834
- function viewingTurnIndex(): number {
835
- return chatTurns.findIndex((turn) => isViewingTurn(turn));
836
- }
839
+ /** Nothing is restored while something runs: the gateway holds the widget's repository for a generation and refuses the restore. */
840
+ const canOfferRestore = $derived(!!onRestoreCheckpoint && !isLoading && !isGenerating);
837
841
 
838
842
  function shouldPinChatToBottom(): boolean {
839
- // A live generation grows under the list. Stay on that tail even when an
840
- // older version is the one marked "you are here".
843
+ // The person is always at the end of the conversation: a live generation grows under the list, and so does a new message.
841
844
  if (isGenerating) return true;
842
- if (viewingVersion != null) {
843
- const hereIndex = viewingTurnIndex();
844
- if (hereIndex < 0 || hereIndex < chatTurns.length - 1) return false;
845
- }
846
845
  return autoScroll;
847
846
  }
848
847
 
849
848
  function scrollGenerationTail(): void {
850
849
  const tail = messagesContainer?.querySelector('.generation-stream');
851
850
  if (tail) tail.scrollTop = tail.scrollHeight;
851
+ const thinking = messagesContainer?.querySelector('.generation-thinking-stream');
852
+ if (thinking) thinking.scrollTop = thinking.scrollHeight;
852
853
  }
853
854
 
854
- /**
855
- * Scroll to the selected version only when that selection changes.
856
- * A page of older messages must not pull the list back to the latest turn.
857
- */
858
- let scrolledViewKey = '';
859
- $effect(() => {
860
- const version = viewingVersion;
861
- const sha = widgetHeadCommitSha ?? '';
862
- const key = `${version ?? ''}|${sha}`;
863
- const turnCount = chatTurns.length;
864
- const generating = isGenerating;
865
- if (generating || (version == null && !sha) || !messagesContainer || turnCount === 0) return;
866
- if (key === scrolledViewKey || pendingOlderScroll) return;
867
- void tick().then(() => {
868
- if (!messagesContainer || pendingOlderScroll || isGenerating) return;
869
- const here = messagesContainer.querySelector('[data-you-are-here="true"]');
870
- if (!here) return;
871
- scrollIntoViewWithin(messagesContainer, here);
872
- scrolledViewKey = key;
873
- });
874
- });
875
-
876
855
  function messageImpliesAttachedFile(content: string): boolean {
877
856
  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(
878
857
  content,
@@ -937,6 +916,26 @@
937
916
  /** The thinking line is up only while a generation is running. */
938
917
  let thinkingHold = $state(false);
939
918
  let generationWasRunning = false;
919
+ let keptThinkingText = $state('');
920
+ let thinkingStartedAtMs = $state<number | null>(null);
921
+ let codeStreamingStartedAtMs = $state<number | null>(null);
922
+ let frozenThoughtSeconds = $state<number | null>(null);
923
+ let thinkingExpanded = $state(false);
924
+ let generationAriaLine = $state('');
925
+ let lastGenerationAriaKey = '';
926
+ let thinkingStreamEl = $state<HTMLDivElement | null>(null);
927
+
928
+ const planCardView = $derived(
929
+ isGenerating && generationPlan
930
+ ? mapWidgetPlanToPlanCard(generationPlan, $t('chat.plan.title'))
931
+ : null,
932
+ );
933
+ const planCardMessages = $derived({
934
+ progress: $t('chat.plan.progress', { current: '{current}', total: '{total}' }),
935
+ showMoreTasks: $t('chat.plan.showMoreTasks', { count: '{count}' }),
936
+ showFewerTasks: $t('chat.plan.showFewerTasks'),
937
+ });
938
+
940
939
  // The first paint is shorter than the loaded page. Scrolling then, or treating
941
940
  // that short box as "the user is at the top", loads older pages and never
942
941
  // lands on the newest message. Pin once, after this load has finished.
@@ -959,30 +958,75 @@
959
958
  $effect(() => {
960
959
  if (isGenerating && !generationWasRunning) {
961
960
  keptGenerationText = '';
961
+ keptThinkingText = '';
962
962
  shownGenerationCount = 0;
963
963
  thinkingShownCount = 0;
964
964
  thinkingHold = true;
965
+ thinkingStartedAtMs = Date.now();
966
+ codeStreamingStartedAtMs = null;
967
+ frozenThoughtSeconds = null;
968
+ thinkingExpanded = false;
969
+ generationAriaLine = '';
970
+ lastGenerationAriaKey = '';
965
971
  }
966
972
  if (!isGenerating && generationWasRunning) {
967
973
  keptGenerationText = '';
974
+ keptThinkingText = '';
968
975
  shownGenerationCount = 0;
969
976
  thinkingShownCount = 0;
970
977
  thinkingHold = false;
978
+ thinkingStartedAtMs = null;
979
+ codeStreamingStartedAtMs = null;
980
+ frozenThoughtSeconds = null;
981
+ thinkingExpanded = false;
971
982
  }
972
983
  generationWasRunning = isGenerating;
973
984
  if (messages.length === 0 && !isGenerating) {
974
985
  keptGenerationText = '';
986
+ keptThinkingText = '';
975
987
  shownGenerationCount = 0;
976
988
  thinkingShownCount = 0;
977
989
  thinkingHold = false;
978
990
  }
979
991
  });
980
992
 
993
+ $effect(() => {
994
+ const incoming = generationThinking;
995
+ if (!incoming) return;
996
+ const merged = mergeGenerationStream(keptThinkingText, incoming);
997
+ if (merged !== keptThinkingText) keptThinkingText = merged;
998
+ });
999
+
981
1000
  $effect(() => {
982
1001
  const incoming = generationStream;
983
1002
  if (!incoming) return;
984
1003
  const merged = mergeGenerationStream(keptGenerationText, incoming);
985
1004
  if (merged !== keptGenerationText) keptGenerationText = merged;
1005
+ if (!codeStreamingStartedAtMs) {
1006
+ codeStreamingStartedAtMs = Date.now();
1007
+ frozenThoughtSeconds = thoughtDurationSeconds(thinkingStartedAtMs, codeStreamingStartedAtMs);
1008
+ }
1009
+ });
1010
+
1011
+ const activityPhase = $derived(
1012
+ generationActivityPhase(isGenerating, keptThinkingText, keptGenerationText),
1013
+ );
1014
+
1015
+ $effect(() => {
1016
+ const key = generationActivityAriaKey(activityPhase) ?? '';
1017
+ if (!key || key === lastGenerationAriaKey) return;
1018
+ lastGenerationAriaKey = key;
1019
+ generationAriaLine = $t(key);
1020
+ });
1021
+
1022
+ $effect(() => {
1023
+ if (!isGenerating || !thinkingStreamEl) return;
1024
+ const length = keptThinkingText.length;
1025
+ if (length === 0) return;
1026
+ tick().then(() => {
1027
+ if (!thinkingStreamEl) return;
1028
+ thinkingStreamEl.scrollTop = thinkingStreamEl.scrollHeight;
1029
+ });
986
1030
  });
987
1031
 
988
1032
  // Reveal from the first character already on screen, then catch up to new tokens.
@@ -1154,6 +1198,21 @@
1154
1198
  }
1155
1199
  }
1156
1200
 
1201
+ function headCommitRestoreTargetId(): string | null {
1202
+ for (let index = chatTurns.length - 1; index >= 0; index--) {
1203
+ const reply = getTurnCommitReply(chatTurns[index]);
1204
+ if (reply && isHeadCommitReply(reply)) return reply.id;
1205
+ }
1206
+ return null;
1207
+ }
1208
+
1209
+ function restoredVersionFromTurn(turn: ChatTurn): string | null {
1210
+ const fork = turn.replies.map((reply) => restoreForkLabel(reply.messageContent)).find(Boolean);
1211
+ if (!fork) return null;
1212
+ const match = /Version\s+(\d+)/i.exec(fork);
1213
+ return match?.[1] ?? null;
1214
+ }
1215
+
1157
1216
  function handleRestoreCheckpoint(messageId: string) {
1158
1217
  // Find the index of the message to restore to
1159
1218
  const messageIndex = messages.findIndex(msg => msg.id === messageId);
@@ -1457,20 +1516,30 @@
1457
1516
  use:detectMessagesScrollbar
1458
1517
  onscroll={handleScroll}
1459
1518
  >
1460
- <!-- Empty state with suggestions — hidden until initialization completes so
1461
- suggestions never flash before the loaded messages arrive, and hidden
1462
- while a generation is in flight (the optimistic user bubble lands a tick
1463
- after send, so the list is briefly empty again). -->
1464
- {#if isInitialized && messages.length === 0 && !isLoading && !isGenerating}
1465
- <div class="empty-state-ct flex flex-col items-center justify-center text-center max-w-sm w-full" style="align-self: center;">
1466
- <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 {$t('chat.messages.startTitle')}</h3>
1467
- <p class="text-gray-600 dark:text-gray-400 text-sm mb-6">
1468
- {$t('chat.messages.startHint', { type: contextTypeLabel(context.type, $t) })}
1469
- </p>
1470
-
1519
+ <!-- Empty state stays out of the document until the parent has finished reading
1520
+ messages and found none. A generation in flight hides it too: the user
1521
+ bubble lands a tick after send, so the list is briefly empty again. -->
1522
+ {#if showEmptyState && !isLoading && !isGenerating}
1523
+ <!-- Figma: Chat / Empty. The hero (a circle with the sparkles icon, the title and a line under it) sits in the
1524
+ middle of the messages, and the suggestions are pinned under it, above the composer. The block takes the
1525
+ free height with flex-1 (not min-h-full): the sticky scroll-to-bottom row below it needs its own room, and a
1526
+ block as tall as the whole area would push it out and make the list scroll. -->
1527
+ <div class="empty-state-ct flex w-full flex-1 flex-col gap-4">
1528
+ <div class="empty-state-hero flex flex-1 flex-col items-center justify-center gap-3 px-2 text-center">
1529
+ <span class="empty-state-icon-circle bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-full" aria-hidden="true">
1530
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1531
+ <path d="M16 18a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm0 -12a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm-7 12a6 6 0 0 1 6 -6a6 6 0 0 1 -6 -6a6 6 0 0 1 -6 6a6 6 0 0 1 6 6z" />
1532
+ </svg>
1533
+ </span>
1534
+ <div class="flex flex-col gap-0.5">
1535
+ <h3 class="text-body-medium text-foreground">{$t('chat.messages.emptyTitle')}</h3>
1536
+ <p class="text-body text-muted-foreground">{$t('chat.messages.emptyHint')}</p>
1537
+ </div>
1538
+ </div>
1539
+
1471
1540
  <!-- Contextual suggestions -->
1472
- <SuggestionButtons
1473
- {context}
1541
+ <SuggestionButtons
1542
+ {context}
1474
1543
  visible={true}
1475
1544
  on:suggestionSelected={handleSuggestionSelected}
1476
1545
  />
@@ -1479,35 +1548,20 @@
1479
1548
 
1480
1549
  <!-- Conversation turns (user prompt + assistant status grouped) -->
1481
1550
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
1482
- <div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5"
1483
- class:wc-chat-turn-head={isViewingTurn(turn)}
1484
- data-you-are-here={isViewingTurn(turn) ? 'true' : undefined}
1485
- >
1551
+ <div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5">
1486
1552
  {#if turn.user}
1487
1553
  {@const userMsg = turn.user}
1488
1554
  {@const shownAttachments = visibleUserAttachments(turn, turnIndex)}
1489
- {@const commitReply = getTurnHeadOrCommitReply(turn)}
1490
1555
  <div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
1491
1556
  class:opacity-75={userMsg._optimistic}
1492
1557
  class:opacity-50={userMsg._failed}
1493
1558
  class:has-attachments={shownAttachments.length > 0}
1494
1559
  >
1495
- <div class="wc-user-bubble-row flex w-full items-start gap-2">
1496
- {#if isViewingTurn(turn)}
1497
- <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title={$t('chat.messages.viewingTitle')}>
1498
- <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1499
- <path d="M20 6L9 17l-5-5"/>
1500
- </svg>
1501
- {$t('chat.messages.viewing')}
1502
- <span class="wc-head-commit-arrow" aria-hidden="true">{$textDirection === 'rtl' ? '←' : '→'}</span>
1503
- </div>
1504
- {/if}
1560
+ <Message role="user" class="ms-auto w-full max-w-full">
1561
+ {#snippet children()}
1505
1562
  <div
1506
- class="message-bubble relative ms-auto w-fit max-w-[94%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
1507
- class:p-3={shownAttachments.length === 0}
1563
+ class="message-bubble-user w-full text-sm leading-relaxed select-text"
1508
1564
  class:p-0={shownAttachments.length > 0}
1509
- class:bubble-fit-content={shownAttachments.length > 0}
1510
- style="background-color: {isCompleted ? MESSAGE_COLORS.USER_COMPLETED : MESSAGE_COLORS.USER_ACTIVE}; color: {MESSAGE_COLORS.USER_TEXT};"
1511
1565
  use:bubbleScrollPadding
1512
1566
  >
1513
1567
  {#if userMsg.messageContent}
@@ -1547,22 +1601,8 @@
1547
1601
  </div>
1548
1602
  {/if}
1549
1603
  </div>
1550
- </div>
1551
- {#if turnNeedsRetry(turn, turnIndex) && !isLoading}
1552
- <div class="retry-codegen-row flex justify-end mt-1">
1553
- <button
1554
- class="retry-codegen-btn"
1555
- onclick={() => handleRetryTurn(turn, turnIndex)}
1556
- title={$t('chat.messages.retryPromptTitle')}
1557
- >
1558
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1559
- <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1560
- <path d="M21 3v6h-6"/>
1561
- </svg>
1562
- {$t('chat.messages.retry')}
1563
- </button>
1564
- </div>
1565
- {/if}
1604
+ {/snippet}
1605
+ </Message>
1566
1606
  {#if showCommitMetaOnUserTurn(turn)}
1567
1607
  {@const commitTitle = getTurnCommitTitle(turn)}
1568
1608
  {@const versionLabel = getTurnVersionLabel(turn)}
@@ -1573,90 +1613,43 @@
1573
1613
  </span>
1574
1614
  </div>
1575
1615
  {/if}
1576
- <div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
1577
- <div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
1578
- <!-- Version 1 is the sketch turn. The words read as a second message, so they stay off. Restore stays. -->
1579
- {#if versionLabel && versionNumberFromLabel(versionLabel) !== 1}
1580
- <span class="wc-user-version-label text-xs text-gray-500">
1581
- {versionLabelText(versionLabel, $t)}
1582
- </span>
1583
- {/if}
1584
- {#if onRateVersion && !isLoading}
1585
- {@const ratedMessageId = ratableVersionReplyId(turn)}
1586
- {#if ratedMessageId}
1587
- {@const givenRating = versionRatings[ratedMessageId]}
1588
- <span class="wc-version-rating inline-flex items-center gap-1" role="group" aria-label={$t('chat.messages.rateGroup')}>
1589
- <button
1590
- type="button"
1591
- class="wc-version-rating-btn wc-version-rating-up"
1592
- aria-pressed={givenRating === 'up'}
1593
- aria-label={$t('chat.messages.rateUp')}
1594
- title={$t('chat.messages.rateUp')}
1595
- onclick={() => onRateVersion?.(ratedMessageId, 'up')}
1596
- >
1597
- <svg width="14" height="14" viewBox="0 0 24 24" fill={givenRating === 'up' ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
1598
- <path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" />
1599
- </svg>
1600
- </button>
1601
- <button
1602
- type="button"
1603
- class="wc-version-rating-btn wc-version-rating-down"
1604
- aria-pressed={givenRating === 'down'}
1605
- aria-label={$t('chat.messages.rateDown')}
1606
- title={$t('chat.messages.rateDown')}
1607
- onclick={() => onRateVersion?.(ratedMessageId, 'down')}
1608
- >
1609
- <svg width="14" height="14" viewBox="0 0 24 24" fill={givenRating === 'down' ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
1610
- <path d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17" />
1611
- </svg>
1612
- </button>
1613
- </span>
1614
- {/if}
1615
- {/if}
1616
- {#if showCommitMeta && getTurnCommitShort(turn)}
1617
- <span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
1618
- {$t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })}
1619
- </span>
1620
- {/if}
1621
- </div>
1622
- {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
1623
- {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(versionLabel) !== 1)}
1624
- <button
1625
- class="restore-checkpoint-btn shrink-0"
1626
- disabled={restoreIsCurrentHead}
1627
- onclick={() => {
1628
- if (restoreIsCurrentHead) return;
1629
- handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
1630
- }}
1631
- title={restoreIsCurrentHead
1632
- ? $t('chat.messages.alreadyHead')
1633
- : $t('chat.messages.restoreTitle')}
1634
- >
1635
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1636
- <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
1637
- <path d="M3 3v5h5"/>
1638
- </svg>
1639
- {$t('chat.messages.restore')}
1640
- </button>
1641
- {/if}
1642
- </div>
1616
+ {@const restoreTargetId = canOfferRestore ? restoreBeforeTarget(restorePoints, turnIndex) : null}
1617
+ {@const restoredVersion = restoredVersionFromTurn(turn)}
1618
+ {@const headRedoId = turnIsRestoreEcho(turn) ? headCommitRestoreTargetId() : null}
1619
+ <MessageCheckpointRow
1620
+ class="wc-user-commit-meta-ct mt-1"
1621
+ versionLabel={versionLabel && versionNumberFromLabel(versionLabel) !== 1
1622
+ ? versionLabelText(versionLabel, $t)
1623
+ : showCommitMeta && getTurnCommitShort(turn)
1624
+ ? $t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })
1625
+ : null}
1626
+ showRestore={!!restoreTargetId}
1627
+ showRedo={!!headRedoId}
1628
+ restoredToVersion={restoredVersion}
1629
+ onRestore={restoreTargetId ? () => handleRestoreCheckpoint(restoreTargetId) : undefined}
1630
+ onRedo={headRedoId ? () => handleRestoreCheckpoint(headRedoId) : undefined}
1631
+ messages={{
1632
+ version: CHAT_MESSAGES['chat.checkpoint.version'],
1633
+ restored: CHAT_MESSAGES['chat.checkpoint.restored'],
1634
+ restore: $t('chat.messages.restore'),
1635
+ redo: $t('chat.checkpoint.redo')
1636
+ }}
1637
+ />
1643
1638
  {/if}
1644
1639
  </div>
1645
1640
  {/if}
1646
1641
 
1647
1642
  {#each turn.replies as reply (reply.id)}
1648
1643
  {#if shouldShowAssistantReply(reply)}
1649
- <div class="message-container wc-chat-turn-reply me-auto w-fit max-w-[94%] flex flex-col items-stretch overflow-visible"
1650
- class:opacity-75={reply._optimistic}
1651
- class:opacity-50={reply._failed}
1652
- class:current-checkpoint={isHeadCommitReply(reply)}
1644
+ <Message
1645
+ role="assistant"
1646
+ class="wc-chat-turn-reply max-w-full"
1647
+ error={isCodegenFailure(reply)}
1648
+ errorText={visibleMessageContent(reply.messageContent || '')}
1653
1649
  >
1654
- <div
1655
- class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text p-3"
1656
- class:wc-codegen-failure={isCodegenFailure(reply)}
1657
- style="background-color: {isHeadCommitReply(reply) ? '#e0f2fe' : MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT};{isHeadCommitReply(reply) ? ' border: 1.5px solid #7dd3fc;' : ''}"
1658
- use:bubbleScrollPadding
1659
- >
1650
+ {#snippet children()}
1651
+ {#if reply.messageContent && !(reply.suggestions && reply.suggestions.length > 0)}
1652
+ <div class="message-content-assistant select-text text-sm leading-relaxed" use:bubbleScrollPadding>
1660
1653
  {#if reply.messageContent}
1661
1654
  {#if hasCodeBlocks(reply.messageContent)}
1662
1655
  <div class="message-content-mixed">
@@ -1679,6 +1672,9 @@
1679
1672
  {/if}
1680
1673
  {/if}
1681
1674
  </div>
1675
+ {/if}
1676
+ {/snippet}
1677
+ </Message>
1682
1678
 
1683
1679
  {#if reply.designControls && renderDesignControls}
1684
1680
  <div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
@@ -1687,49 +1683,56 @@
1687
1683
  {/if}
1688
1684
 
1689
1685
  {#if reply.suggestions && reply.suggestions.length > 0}
1690
- <div class="clarification-suggestions flex flex-wrap gap-1.5 mt-1.5">
1691
- {#each reply.suggestions as suggestion, i (i)}
1692
- <button
1693
- type="button"
1694
- class="clarification-chip"
1695
- disabled={!onClarificationSuggestionSelected || isLoading || isGenerating}
1696
- onclick={() => onClarificationSuggestionSelected?.(suggestion)}
1697
- title={suggestion.label}
1698
- >
1699
- {suggestion.label}
1700
- </button>
1701
- {/each}
1702
- </div>
1686
+ <QuestionCard
1687
+ class="mt-1.5 w-full max-w-full"
1688
+ question={(visibleMessageContent(reply.messageContent || '') || $t('chat.messages.clarificationPrompt')).trim()}
1689
+ options={reply.suggestions.map((suggestion, index) => ({
1690
+ id: String(index),
1691
+ label: suggestion.label
1692
+ }))}
1693
+ onSubmit={(selectedIds) => {
1694
+ const picked = Number(selectedIds[0]);
1695
+ const suggestion = reply.suggestions?.[picked];
1696
+ if (suggestion) onClarificationSuggestionSelected?.(suggestion);
1697
+ }}
1698
+ />
1703
1699
  {/if}
1704
1700
 
1705
- {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && turnNeedsRetry(turn, turnIndex)}
1706
- <div class="retry-codegen-row flex justify-start mt-1">
1707
- {#if isPlanLimitMessage(reply.messageContent)}
1701
+ <!-- A failure about the plan or the credits: the way out is to upgrade. Running the prompt again is the regenerate icon of the last message. -->
1702
+ {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && isPlanLimitMessage(reply.messageContent) && turnNeedsRetry(turn, turnIndex)}
1703
+ <div class="wc-upgrade-row flex justify-start">
1708
1704
  <button
1709
- class="retry-codegen-btn"
1705
+ type="button"
1706
+ class="wc-upgrade-btn"
1710
1707
  onclick={openUpgradePlans}
1711
1708
  title={$t('chat.messages.upgradeTitle')}
1712
1709
  >
1713
1710
  {$t('chat.messages.upgrade')}
1714
1711
  </button>
1715
- {:else}
1716
- <button
1717
- class="retry-codegen-btn"
1718
- onclick={() => handleRetryTurn(turn, turnIndex)}
1719
- title={$t('chat.messages.retryLastTitle')}
1720
- >
1721
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1722
- <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1723
- <path d="M21 3v6h-6"/>
1724
- </svg>
1725
- {$t('chat.messages.retry')}
1726
- </button>
1727
- {/if}
1728
1712
  </div>
1729
1713
  {/if}
1730
- </div>
1731
1714
  {/if}
1732
1715
  {/each}
1716
+
1717
+ <!-- Copy, regenerate and the two thumbs: at the end of the last message only, and not while something is being generated. -->
1718
+ {#if turnIndex === chatTurns.length - 1 && !isLoading && !isGenerating}
1719
+ {@const copyText = textToCopy(
1720
+ turn.replies.filter(shouldShowAssistantReply).map((reply) => visibleMessageContent(reply.messageContent || '')),
1721
+ getTurnCommitTitle(turn),
1722
+ )}
1723
+ {@const canRegenerate = !!onRetryMessage && turnNeedsRetry(turn, turnIndex)}
1724
+ {@const ratedMessageId = onRateVersion ? ratableVersionReplyId(turn) : null}
1725
+ {#if copyText !== '' || canRegenerate || ratedMessageId}
1726
+ <MessageActions
1727
+ {copyText}
1728
+ {canRegenerate}
1729
+ onRegenerate={() => handleRetryTurn(turn, turnIndex)}
1730
+ {ratedMessageId}
1731
+ rating={ratedMessageId ? versionRatings[ratedMessageId] : 'none'}
1732
+ onRate={(messageId, pressed) => onRateVersion?.(messageId, pressed)}
1733
+ />
1734
+ {/if}
1735
+ {/if}
1733
1736
  </div>
1734
1737
  {/each}
1735
1738
 
@@ -1744,19 +1747,96 @@
1744
1747
  {/if}
1745
1748
  {#if thinkingHold}
1746
1749
  <div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
1747
- <div class="thinking-bubble relative inline-block whitespace-nowrap rounded-lg p-3 text-sm leading-relaxed shadow-sm"
1748
- style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
1750
+ {#if planCardView}
1751
+ <PlanCard
1752
+ class="w-full"
1753
+ dir="auto"
1754
+ role="region"
1755
+ aria-label={$t('chat.plan.regionLabel')}
1756
+ title={planCardView.title}
1757
+ tasks={planCardView.tasks}
1758
+ progressCurrent={planCardView.progressCurrent}
1759
+ progressTotal={planCardView.progressTotal}
1760
+ visibleTaskCount={4}
1761
+ messages={planCardMessages}
1762
+ />
1763
+ {/if}
1764
+ <ActivityRow
1765
+ class="w-full"
1766
+ label={shownThinkingLabel || $t('chat.generation.thinking')}
1767
+ status={activityPhase === 'code-only' || activityPhase === 'thinking-and-code' ? 'running' : 'pending'}
1768
+ />
1769
+ <div
1770
+ class="generation-activity-card w-full max-w-full rounded-lg p-3 text-sm leading-relaxed shadow-sm"
1771
+ style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
1749
1772
  >
1750
- <span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
1751
- <span class="thinking-reveal absolute inset-0 flex items-center px-3">{shownThinkingLabel}</span>
1773
+ {#if activityPhase === 'shimmer-only'}
1774
+ <div class="thinking-bubble relative inline-block whitespace-nowrap">
1775
+ <span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
1776
+ <span class="thinking-reveal absolute inset-0 flex items-center">{shownThinkingLabel}</span>
1777
+ </div>
1778
+ {:else}
1779
+ {#if activityPhase === 'thinking-stream'}
1780
+ <div class="mb-2 flex items-center gap-2 font-medium">
1781
+ <div class="h-4 w-4 shrink-0 rounded-full border-2 border-gray-400 border-t-transparent animate-spin" aria-hidden="true"></div>
1782
+ <span class="thinking-reveal-inline">{$t('chat.generation.thinking')}</span>
1783
+ </div>
1784
+ <div
1785
+ bind:this={thinkingStreamEl}
1786
+ class="generation-thinking-stream max-h-32 w-full overflow-auto whitespace-pre-wrap break-words text-xs text-gray-600"
1787
+ dir="auto"
1788
+ >{keptThinkingText}</div>
1789
+ {:else if activityPhase === 'thinking-and-code' || activityPhase === 'code-only'}
1790
+ {#if keptThinkingText.trim().length > 0}
1791
+ <button
1792
+ type="button"
1793
+ class="thought-summary-btn mb-2 flex w-full items-center gap-2 text-start text-xs text-gray-600 underline-offset-2 hover:underline"
1794
+ aria-expanded={thinkingExpanded}
1795
+ onclick={() => { thinkingExpanded = !thinkingExpanded; }}
1796
+ >
1797
+ <span>
1798
+ {#if frozenThoughtSeconds != null}
1799
+ {$t('chat.generation.thoughtFor', { seconds: String(frozenThoughtSeconds) })}
1800
+ {:else}
1801
+ {$t('chat.generation.thinking')}
1802
+ {/if}
1803
+ </span>
1804
+ <span class="sr-only">
1805
+ {thinkingExpanded ? $t('chat.generation.collapseThought') : $t('chat.generation.expandThought')}
1806
+ </span>
1807
+ </button>
1808
+ {#if thinkingExpanded}
1809
+ <div
1810
+ class="generation-thinking-stream mb-2 max-h-24 w-full overflow-auto whitespace-pre-wrap break-words text-xs text-gray-600"
1811
+ dir="auto"
1812
+ >{keptThinkingText}</div>
1813
+ {/if}
1814
+ {/if}
1815
+ {#if shownGenerationText}
1816
+ <div class="mb-1 text-xs font-medium text-gray-800">
1817
+ <span>{$t('chat.generation.writingCode')}</span>
1818
+ </div>
1819
+ <pre class="generation-stream m-0 max-h-40 w-full overflow-auto whitespace-pre-wrap break-words rounded-lg bg-gray-900 p-3 font-mono text-[11px] leading-relaxed text-gray-100" dir="ltr">{shownGenerationText}</pre>
1820
+ {/if}
1821
+ {/if}
1822
+ {/if}
1752
1823
  </div>
1824
+ {#if generationAriaLine}
1825
+ <p class="sr-only" aria-live="polite">{generationAriaLine}</p>
1826
+ {/if}
1753
1827
  </div>
1754
1828
  {/if}
1755
- {#if shownGenerationText}
1756
- <div class="generation-stream-ct flex flex-col items-start gap-2 px-3 pb-3">
1757
- <pre class="generation-stream m-0 max-h-40 w-full overflow-auto whitespace-pre-wrap break-words rounded-lg bg-gray-900 p-3 font-mono text-[11px] leading-relaxed text-gray-100">{shownGenerationText}</pre>
1758
- </div>
1759
- {/if}
1829
+
1830
+ <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2">
1831
+ <ScrollToBottom
1832
+ visible={!autoScroll && messages.length > 0 && !isLoading}
1833
+ label={$t('chat.messages.scrollToBottom')}
1834
+ onScroll={() => {
1835
+ autoScroll = true;
1836
+ scrollMessagesToEnd();
1837
+ }}
1838
+ />
1839
+ </div>
1760
1840
  </div>
1761
1841
 
1762
1842
  <style>
@@ -1775,6 +1855,22 @@
1775
1855
  0% { background-position: 100% 0; }
1776
1856
  100% { background-position: -100% 0; }
1777
1857
  }
1858
+ .thinking-reveal-inline {
1859
+ background-image: linear-gradient(100deg, #1f2937 35%, #ffffff 50%, #1f2937 65%);
1860
+ background-size: 200% 100%;
1861
+ -webkit-background-clip: text;
1862
+ background-clip: text;
1863
+ color: transparent;
1864
+ animation: thinking-shine 1.6s linear infinite;
1865
+ }
1866
+ @media (prefers-reduced-motion: reduce) {
1867
+ .thinking-reveal,
1868
+ .thinking-reveal-inline {
1869
+ animation: none;
1870
+ color: inherit;
1871
+ background-image: none;
1872
+ }
1873
+ }
1778
1874
  .generation-stream {
1779
1875
  scrollbar-width: thin;
1780
1876
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
@@ -1846,33 +1942,11 @@
1846
1942
  align-items: flex-start; /* Left align for assistant messages */
1847
1943
  }
1848
1944
 
1849
- /* Restore checkpoint — always visible below user messages */
1850
- .wc-chat-turn-head {
1851
- border-color: #bae6fd;
1852
- background-color: #f8fcff;
1853
- padding: 6px;
1854
- }
1855
-
1856
1945
  .wc-codegen-failure {
1857
1946
  border: 1px solid #fecaca;
1858
1947
  background-color: #fef2f2 !important;
1859
1948
  }
1860
1949
 
1861
- .wc-head-commit-label {
1862
- margin-bottom: 0;
1863
- }
1864
-
1865
- .wc-head-commit-arrow {
1866
- font-size: 11px;
1867
- line-height: 1;
1868
- font-weight: 700;
1869
- margin-inline-start: 2px;
1870
- }
1871
-
1872
- .wc-head-commit-meta-ct .wc-head-commit-label {
1873
- margin-top: 0;
1874
- }
1875
-
1876
1950
  /* What the turn shipped, in the commit's own words. Truncated at the turn's
1877
1951
  width — the full subject stays in the tooltip — so a prompt-derived title
1878
1952
  cannot widen the bubble past its 80% cap. */
@@ -1883,94 +1957,62 @@
1883
1957
  white-space: nowrap;
1884
1958
  }
1885
1959
 
1886
- .restore-checkpoint-row {
1887
- margin-top: 4px;
1960
+ /* The restore icon at the end of a message the person sent. Out of sight until the pointer is on the message (or the keyboard is on
1961
+ the icon), then it fades in. It keeps its place while hidden, so the rows below do not move. A screen with no hover shows it always. */
1962
+ .wc-restore-slot {
1963
+ margin-inline-start: auto;
1964
+ flex-shrink: 0;
1965
+ opacity: 0;
1966
+ transition: opacity 0.15s ease;
1888
1967
  }
1889
1968
 
1890
- .retry-codegen-row {
1891
- margin-top: 4px;
1969
+ .wc-chat-turn-user:hover .wc-restore-slot,
1970
+ .wc-restore-slot:has(:focus-visible) {
1971
+ opacity: 1;
1892
1972
  }
1893
-
1894
- .restore-checkpoint-btn,
1895
- .retry-codegen-btn {
1896
- display: inline-flex;
1897
- align-items: center;
1898
- gap: 4px;
1899
- padding: 3px 10px;
1900
- background: transparent;
1901
- color: #888;
1902
- border: 1px solid #ddd;
1903
- border-radius: 12px;
1904
- font-size: 11px;
1905
- font-weight: 500;
1906
- cursor: pointer;
1907
- transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
1908
- white-space: nowrap;
1973
+
1974
+ @media (hover: none) {
1975
+ .wc-restore-slot {
1976
+ opacity: 1;
1977
+ }
1909
1978
  }
1910
-
1911
- .restore-checkpoint-btn:hover,
1912
- .retry-codegen-btn:hover {
1913
- background: rgba(0, 0, 0, 0.06);
1914
- color: #555;
1915
- border-color: #bbb;
1979
+
1980
+ @media (prefers-reduced-motion: reduce) {
1981
+ .wc-restore-slot {
1982
+ transition: none;
1983
+ }
1916
1984
  }
1917
1985
 
1918
- .restore-checkpoint-btn:disabled {
1919
- opacity: 0.45;
1920
- cursor: not-allowed;
1921
- pointer-events: none;
1986
+ /* "Upgrade" under a failure about the plan or the credits: a plain button, because the failure itself is already said above it. */
1987
+ .wc-upgrade-row {
1988
+ margin-top: 4px;
1922
1989
  }
1923
1990
 
1924
- /* The thumbs next to a version's name. A pressed thumb is filled and takes the colour of what it says. */
1925
- .wc-version-rating-btn {
1991
+ .wc-upgrade-btn {
1926
1992
  display: inline-flex;
1927
1993
  align-items: center;
1928
- justify-content: center;
1929
- width: 22px;
1930
- height: 22px;
1931
- padding: 0;
1932
- background: transparent;
1933
- color: #9ca3af;
1934
- border: 1px solid transparent;
1935
- border-radius: 6px;
1994
+ padding: 4px 12px;
1995
+ background: #ffffff;
1996
+ color: #111827;
1997
+ border: 1px solid #d1d5db;
1998
+ border-radius: 8px;
1999
+ font-size: 12px;
2000
+ font-weight: 500;
1936
2001
  cursor: pointer;
1937
- transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
2002
+ white-space: nowrap;
2003
+ transition: background-color 0.15s ease, border-color 0.15s ease;
1938
2004
  }
1939
2005
 
1940
- .wc-version-rating-btn:hover {
1941
- background: rgba(0, 0, 0, 0.06);
1942
- color: #555;
2006
+ .wc-upgrade-btn:hover {
2007
+ background: #f3f4f6;
2008
+ border-color: #9ca3af;
1943
2009
  }
1944
2010
 
1945
- .wc-version-rating-btn:focus-visible {
2011
+ .wc-upgrade-btn:focus-visible {
1946
2012
  outline: 2px solid #93c5fd;
1947
2013
  outline-offset: 1px;
1948
2014
  }
1949
2015
 
1950
- .wc-version-rating-btn[aria-pressed='true'].wc-version-rating-up {
1951
- color: #15803d;
1952
- background: #f0fdf4;
1953
- border-color: #bbf7d0;
1954
- }
1955
-
1956
- .wc-version-rating-btn[aria-pressed='true'].wc-version-rating-down {
1957
- color: #b91c1c;
1958
- background: #fef2f2;
1959
- border-color: #fecaca;
1960
- }
1961
-
1962
- .retry-codegen-btn {
1963
- color: #b91c1c;
1964
- border-color: #fecaca;
1965
- background: #fff7f7;
1966
- }
1967
-
1968
- .retry-codegen-btn:hover {
1969
- background: #fee2e2;
1970
- color: #991b1b;
1971
- border-color: #fca5a5;
1972
- }
1973
-
1974
2016
  /* Clarification-card suggestion chips — tap to send as the next user message */
1975
2017
  .clarification-chip {
1976
2018
  display: inline-flex;
@@ -2004,40 +2046,6 @@
2004
2046
  cursor: default;
2005
2047
  }
2006
2048
 
2007
- .restore-checkpoint-btn svg,
2008
- .retry-codegen-btn svg {
2009
- flex-shrink: 0;
2010
- }
2011
-
2012
- /* Checkpoint label — shown above the restored message */
2013
- .checkpoint-label {
2014
- display: inline-flex;
2015
- align-items: center;
2016
- gap: 4px;
2017
- padding: 2px 8px;
2018
- background: #0ea5e9;
2019
- color: white;
2020
- border-radius: 8px;
2021
- font-size: 10px;
2022
- font-weight: 600;
2023
- letter-spacing: 0.02em;
2024
- margin-bottom: 4px;
2025
- align-self: flex-end;
2026
- }
2027
-
2028
- /* Restored button state */
2029
- .restore-checkpoint-btn.restored {
2030
- opacity: 0.5;
2031
- cursor: default;
2032
- border-color: #7dd3fc;
2033
- color: #0ea5e9;
2034
- }
2035
- .restore-checkpoint-btn.restored:hover {
2036
- background: transparent;
2037
- color: #0ea5e9;
2038
- border-color: #7dd3fc;
2039
- }
2040
-
2041
2049
  /* Cap huge messages (legacy full-file dumps) so bubbles stay readable */
2042
2050
  .message-bubble {
2043
2051
  max-width: 100%;