@widgetic/chat 0.1.35 → 0.1.37

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.
Files changed (35) hide show
  1. package/README.md +34 -6
  2. package/dist/components/ActionBar.svelte +8 -0
  3. package/dist/components/Chat.svelte +120 -106
  4. package/dist/components/Chat.svelte.d.ts +19 -1
  5. package/dist/components/ChatComposer.svelte +166 -0
  6. package/dist/components/ChatComposer.svelte.d.ts +30 -0
  7. package/dist/components/ChatMessages.svelte +483 -393
  8. package/dist/components/ChatMessages.svelte.d.ts +16 -6
  9. package/dist/components/IconButton.svelte +125 -0
  10. package/dist/components/IconButton.svelte.d.ts +22 -0
  11. package/dist/components/MessageActions.svelte +48 -0
  12. package/dist/components/MessageActions.svelte.d.ts +13 -0
  13. package/dist/components/PanelChatHeader.svelte +79 -0
  14. package/dist/components/PanelChatHeader.svelte.d.ts +19 -0
  15. package/dist/components/PanelFollowUpSuggestions.svelte +34 -0
  16. package/dist/components/PanelFollowUpSuggestions.svelte.d.ts +8 -0
  17. package/dist/components/PanelSuggestionButtons.svelte +60 -0
  18. package/dist/components/PanelSuggestionButtons.svelte.d.ts +10 -0
  19. package/dist/components/SuggestionButtons.svelte +11 -163
  20. package/dist/i18n/index.d.ts +1 -1
  21. package/dist/i18n/index.js +1 -1
  22. package/dist/i18n/messages.d.ts +54 -13
  23. package/dist/i18n/messages.js +54 -13
  24. package/dist/i18n/suggestions.d.ts +6 -0
  25. package/dist/i18n/suggestions.js +24 -0
  26. package/dist/types/message.d.ts +7 -0
  27. package/dist/utils/generationActivity.d.ts +12 -0
  28. package/dist/utils/generationActivity.js +47 -0
  29. package/dist/utils/generationPlan.d.ts +32 -0
  30. package/dist/utils/generationPlan.js +89 -0
  31. package/dist/utils/index.d.ts +4 -0
  32. package/dist/utils/index.js +2 -0
  33. package/dist/utils/messageActions.d.ts +54 -0
  34. package/dist/utils/messageActions.js +104 -0
  35. package/package.json +3 -3
@@ -4,13 +4,36 @@
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';
9
+ import PanelSuggestionButtons from './PanelSuggestionButtons.svelte';
10
+ import PanelFollowUpSuggestions from './PanelFollowUpSuggestions.svelte';
8
11
  import CodeBlock from './CodeBlock.svelte';
12
+ import MessageActions from './MessageActions.svelte';
9
13
  import { onDestroy, onMount, tick } from 'svelte';
10
14
  import type { Snippet } from 'svelte';
11
15
  import { useChatLanguage } from '../i18n/language.js';
12
- import { contextTypeLabel, versionLabelText } from '../i18n/labels.js';
16
+ import { CHAT_MESSAGES } from '../i18n/messages.js';
17
+ import { versionLabelText } from '../i18n/labels.js';
13
18
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
19
+ import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
20
+ import {
21
+ generationActivityAriaKey,
22
+ generationActivityPhase,
23
+ thoughtDurationSeconds,
24
+ } from '../utils/generationActivity.js';
25
+ import { mapWidgetPlanToPlanCard, type GenerationPlanWire } from '../utils/generationPlan.js';
26
+ // The chat barrel of the design system: its export map resolves `components/<name>` to `<name>.js` only,
27
+ // so a deep `.svelte` path types fine but cannot be resolved by Vite or Node.
28
+ import {
29
+ ActivityRow,
30
+ ChatAlertCard,
31
+ Message,
32
+ MessageCheckpointRow,
33
+ PlanCard,
34
+ QuestionCard,
35
+ ScrollToBottom
36
+ } from '@widgetic/design-system/components/chat/index';
14
37
 
15
38
  // The words of the messages area, in the language of the chat above
16
39
  const { t } = useChatLanguage();
@@ -59,22 +82,29 @@
59
82
  /**
60
83
  * Every saved version for this widget. When one prompt produced two versions
61
84
  * but the chat stored only one user message, the missing older version is
62
- * shown as its own turn so "You are here" can land on it.
85
+ * shown as its own turn, so each version has its own place in the list.
63
86
  */
64
87
  versionTimeline?: Array<{ version: number; sha: string; prompt: string }>;
65
- /** Dropdown selection. The badge follows this version, not only a commit sha. */
66
- viewingVersion?: number | null;
67
88
  /** When false, hide commit hashes next to the version label (user mode). */
68
89
  showCommitMeta?: boolean;
69
- /** True while codegen / send is in flight — suppresses premature Retry. */
90
+ /** True while codegen / send is in flight — no icons are drawn under the last message and no restore is offered. */
70
91
  isGenerating?: boolean;
71
92
  /** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
72
93
  generationStream?: string;
94
+ /** Rolling tail of streamed model reasoning during codegen. */
95
+ generationThinking?: string;
96
+ /** Gateway build plan while codegen runs; `null` hides the card. */
97
+ generationPlan?: GenerationPlanWire | null;
73
98
  onSuggestionSelected?: (suggestion: string) => void;
99
+ /**
100
+ * Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
101
+ * 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
102
+ * and its place in `messages`. Without it no restore icon is drawn.
103
+ */
74
104
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
75
105
  /**
76
- * Gives each version a thumbs up and a thumbs down next to its name. Called with the id of the assistant message that
77
- * announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
106
+ * Gives the last message a thumbs up and a thumbs down (next to copy and regenerate). Called with the id of the assistant message
107
+ * that announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
78
108
  */
79
109
  onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
80
110
  /** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
@@ -98,6 +128,8 @@
98
128
  hasOlderMessages?: boolean;
99
129
  /** Called when the list is scrolled to the top, so the host can prepend the previous page. */
100
130
  onRequestOlderMessages?: () => Promise<boolean | void>;
131
+ /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
132
+ panelLayout?: boolean;
101
133
  }
102
134
 
103
135
  let {
@@ -114,10 +146,11 @@
114
146
  versionLabelByCommitSha = {},
115
147
  versionLabelByPrompt = {},
116
148
  versionTimeline = [],
117
- viewingVersion = null,
118
149
  showCommitMeta = true,
119
150
  isGenerating = false,
120
151
  generationStream = '',
152
+ generationThinking = '',
153
+ generationPlan = null,
121
154
  onSuggestionSelected,
122
155
  onRestoreCheckpoint,
123
156
  onRateVersion,
@@ -129,8 +162,10 @@
129
162
  storedLineLabel,
130
163
  hasOlderMessages = false,
131
164
  onRequestOlderMessages,
165
+ panelLayout = false,
132
166
  }: Props = $props();
133
167
 
168
+
134
169
  /** The property-edit sentence used to be stored with markdown the bubble does not render. */
135
170
  function readablePropertyEditLine(content: string): string {
136
171
  return content.replace(
@@ -158,6 +193,13 @@
158
193
  function detectMessagesScrollbar(node: HTMLElement) {
159
194
  function check() {
160
195
  messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
196
+ if (panelLayout) {
197
+ // The docked panel keeps Figma's 16px on both sides (set in the style of the list); with a scrollbar the bar
198
+ // takes the place of half of it.
199
+ if (messagesHasScrollbar) node.style.setProperty('padding-inline-end', '8px', 'important');
200
+ else node.style.removeProperty('padding-inline-end');
201
+ return;
202
+ }
161
203
  node.style.setProperty('padding-inline-end', messagesHasScrollbar ? '0px' : '12px', 'important');
162
204
  }
163
205
  const resizeObserver = new ResizeObserver(check);
@@ -291,9 +333,9 @@
291
333
 
292
334
  /**
293
335
  * A retry that reused one user bubble leaves two commits on that turn, so
294
- * Version 7 and Version 8 share a message and "You are here" cannot land on
295
- * the older one. Split at each new commit. Later copies keep the prompt text
296
- * and drop attachments — the sketch stays on the turn that originally had it.
336
+ * Version 7 and Version 8 share a message and the older one has no turn (and
337
+ * no version label) of its own. Split at each new commit. Later copies keep the
338
+ * prompt text and drop attachments — the sketch stays on the turn that originally had it.
297
339
  */
298
340
  function splitTurnsByCommit(turns: ChatTurn[]): ChatTurn[] {
299
341
  const split: ChatTurn[] = [];
@@ -323,8 +365,8 @@
323
365
 
324
366
  /**
325
367
  * One user row can carry only the newest commit after a retry. Older versions
326
- * of that same prompt still exist in history. Give each of them a turn so
327
- * selecting Version 7 has a place to show "You are here".
368
+ * of that same prompt still exist in history. Give each of them a turn, so
369
+ * Version 7 is on the list with its own version label.
328
370
  */
329
371
  function expandTurnsForSharedPrompts(turns: ChatTurn[]): ChatTurn[] {
330
372
  if (!versionTimeline.length) return turns;
@@ -500,18 +542,6 @@
500
542
  );
501
543
  }
502
544
 
503
- function canRestoreToMessage(message: ChatMessage): boolean {
504
- if (message.id?.startsWith('version-fork-')) return false;
505
- if (isRestoreForkContent(message.messageContent)) return false;
506
- if (isHeadCommitReply(message)) return false;
507
- if (!message.messageContent) return false;
508
- const trimmed = message.messageContent.trim();
509
- if (/^Preview recompiled/i.test(trimmed)) return false;
510
- return message.messageType === 'assistant'
511
- && messageHasCommit(message)
512
- && !isCodegenFailure(message);
513
- }
514
-
515
545
  function canUndoHeadUserTurn(turn: ChatTurn): boolean {
516
546
  return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
517
547
  }
@@ -610,16 +640,6 @@
610
640
  );
611
641
  }
612
642
 
613
- /** The dropdown's version, else the commit sha, decides which turn is current. */
614
- function isViewingTurn(turn: ChatTurn): boolean {
615
- if (viewingVersion != null) {
616
- const versionNumber = versionNumberFromLabel(getTurnVersionLabel(turn));
617
- if (versionNumber != null) return versionNumber === Number(viewingVersion);
618
- }
619
- const reply = getTurnHeadOrCommitReply(turn);
620
- return !!(reply && isHeadCommitReply(reply));
621
- }
622
-
623
643
  function getTurnOwnCommitShort(turn: ChatTurn): string | null {
624
644
  return extractCommitShort(getTurnCommitReply(turn)?.messageContent || '');
625
645
  }
@@ -723,17 +743,31 @@
723
743
  return conversationHasCommitReply();
724
744
  }
725
745
 
726
- function restoreTargetMessageId(turn: ChatTurn, commitReply: ChatMessage | null): string {
727
- if (commitReply && canRestoreToMessage(commitReply)) return commitReply.id;
728
- if (canRestoreFailedLastTurn(turn)) {
729
- for (let i = chatTurns.length - 1; i >= 0; i--) {
730
- if (chatTurns[i] === turn) continue;
731
- const previous = getTurnCommitReply(chatTurns[i]);
732
- if (previous) return previous.id;
733
- if (chatTurns[i].user) return chatTurns[i].user!.id;
734
- }
746
+ /**
747
+ * What this turn is as a place to go back to (see `TurnRestorePoint`): a turn whose saved reply announced a commit is a version.
748
+ * The ids the host's backend cannot be asked for are `blocked`, and nothing is offered past them: older versions the chat only lists
749
+ * (they have no saved reply of their own), versions a restore has already undone, and messages the host has not saved yet.
750
+ */
751
+ function restorePointOf(turn: ChatTurn): TurnRestorePoint {
752
+ const reply = getTurnCommitReply(turn);
753
+ if (!turn.user || !reply) return { kind: 'none' };
754
+ if (
755
+ turn.user.id.startsWith('version-fork-')
756
+ || reply.id.startsWith('version-fork-')
757
+ || !!turn.user.rolledBackAt
758
+ || !!reply.rolledBackAt
759
+ || isLocalMessageId(turn.user.id)
760
+ || isLocalMessageId(reply.id)
761
+ ) {
762
+ return { kind: 'blocked' };
735
763
  }
736
- return turn.user!.id;
764
+ return {
765
+ kind: 'version',
766
+ replyId: reply.id,
767
+ // The copy a restore appends is a place to go back to, but not a message of the person's to go back before
768
+ wearsIcon: !turnIsRestoreEcho(turn),
769
+ isLatest: isHeadCommitReply(reply),
770
+ };
737
771
  }
738
772
 
739
773
  function isCodegenStatusBubble(content?: string | null): boolean {
@@ -759,8 +793,24 @@
759
793
  return !isGenerationSummary(reply);
760
794
  }
761
795
 
762
- /** Show commit chrome + Restore Checkpoint on the user prompt whenever the turn has a commit.
763
- * Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
796
+ /** Figma ready frame: follow-up cards sit above the composer, outside the scroll area. */
797
+ const panelAnchoredFollowUp = $derived.by((): { labels: string[] } | null => {
798
+ if (!panelLayout || showEmptyState) return null;
799
+ for (let ti = chatTurns.length - 1; ti >= 0; ti--) {
800
+ const turn = chatTurns[ti];
801
+ for (let ri = turn.replies.length - 1; ri >= 0; ri--) {
802
+ const reply = turn.replies[ri];
803
+ const meta = reply.metadata as { panelFollowUp?: boolean } | undefined;
804
+ if (!reply.suggestions?.length || meta?.panelFollowUp === false) continue;
805
+ if (!shouldShowAssistantReply(reply)) continue;
806
+ return { labels: reply.suggestions.map((s) => s.label) };
807
+ }
808
+ }
809
+ return null;
810
+ });
811
+
812
+ /** Show the commit chrome (title, version label, the restore icon) on the user prompt whenever the turn has a commit.
813
+ * Previously this was gated to Debug OFF (assistant reply hidden), but we want it
764
814
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
765
815
  function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
766
816
  return !!getTurnHeadOrCommitReply(turn)
@@ -814,71 +864,25 @@
814
864
  );
815
865
  });
816
866
 
817
- /**
818
- * Brings `element` into view inside `container` the way `element.scrollIntoView({ block: 'nearest', behavior: 'smooth' })`
819
- * does, but moves the container only. `scrollIntoView` scrolls every scrollable ancestor as well, and one of them is the
820
- * page the chat is on (a partner's page, when the creator is mounted into it).
821
- */
822
- function scrollIntoViewWithin(container: HTMLElement, element: Element) {
823
- const containerBox = container.getBoundingClientRect();
824
- const elementBox = element.getBoundingClientRect();
825
- let distance = 0;
826
- if (elementBox.top < containerBox.top) {
827
- // It starts above the visible part: scroll up to its top.
828
- distance = elementBox.top - containerBox.top;
829
- } else if (elementBox.bottom > containerBox.bottom) {
830
- // It ends below the visible part: scroll down just enough, but never past its own top (when it is taller than the container).
831
- distance = Math.min(elementBox.bottom - containerBox.bottom, elementBox.top - containerBox.top);
832
- }
833
- if (distance !== 0) container.scrollBy({ top: distance, behavior: 'smooth' });
834
- }
867
+ /** One entry per turn, in the order of `chatTurns`. */
868
+ const restorePoints = $derived(chatTurns.map(restorePointOf));
835
869
 
836
- /**
837
- * The selected version's turn is current. Pinning the list to the bottom
838
- * would hide it again whenever messages finish loading.
839
- */
840
- function viewingTurnIndex(): number {
841
- return chatTurns.findIndex((turn) => isViewingTurn(turn));
842
- }
870
+ /** Nothing is restored while something runs: the gateway holds the widget's repository for a generation and refuses the restore. */
871
+ const canOfferRestore = $derived(!!onRestoreCheckpoint && !isLoading && !isGenerating);
843
872
 
844
873
  function shouldPinChatToBottom(): boolean {
845
- // A live generation grows under the list. Stay on that tail even when an
846
- // older version is the one marked "you are here".
874
+ // The person is always at the end of the conversation: a live generation grows under the list, and so does a new message.
847
875
  if (isGenerating) return true;
848
- if (viewingVersion != null) {
849
- const hereIndex = viewingTurnIndex();
850
- if (hereIndex < 0 || hereIndex < chatTurns.length - 1) return false;
851
- }
852
876
  return autoScroll;
853
877
  }
854
878
 
855
879
  function scrollGenerationTail(): void {
856
880
  const tail = messagesContainer?.querySelector('.generation-stream');
857
881
  if (tail) tail.scrollTop = tail.scrollHeight;
882
+ const thinking = messagesContainer?.querySelector('.generation-thinking-stream');
883
+ if (thinking) thinking.scrollTop = thinking.scrollHeight;
858
884
  }
859
885
 
860
- /**
861
- * Scroll to the selected version only when that selection changes.
862
- * A page of older messages must not pull the list back to the latest turn.
863
- */
864
- let scrolledViewKey = '';
865
- $effect(() => {
866
- const version = viewingVersion;
867
- const sha = widgetHeadCommitSha ?? '';
868
- const key = `${version ?? ''}|${sha}`;
869
- const turnCount = chatTurns.length;
870
- const generating = isGenerating;
871
- if (generating || (version == null && !sha) || !messagesContainer || turnCount === 0) return;
872
- if (key === scrolledViewKey || pendingOlderScroll) return;
873
- void tick().then(() => {
874
- if (!messagesContainer || pendingOlderScroll || isGenerating) return;
875
- const here = messagesContainer.querySelector('[data-you-are-here="true"]');
876
- if (!here) return;
877
- scrollIntoViewWithin(messagesContainer, here);
878
- scrolledViewKey = key;
879
- });
880
- });
881
-
882
886
  function messageImpliesAttachedFile(content: string): boolean {
883
887
  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(
884
888
  content,
@@ -899,6 +903,16 @@
899
903
  return /credit balance|free trial|not available in your plan|not available on the free plan|upgrade your plan|upgrade to a solo/i.test(message);
900
904
  }
901
905
 
906
+ /** What the alert card of a failed reply says under its title: the server's own words when they tell something specific
907
+ * (the plan or the credits, too many requests, the service is unavailable, the run was stopped), otherwise Figma's line. */
908
+ function failureAlertDescription(message: ChatMessage): string {
909
+ const serverText = visibleMessageContent(message.messageContent || '').trim();
910
+ const isSpecificFailure =
911
+ isPlanLimitMessage(message.messageContent) ||
912
+ /Too many generation requests|temporarily unavailable|Generation stopped/i.test(serverText);
913
+ return isSpecificFailure && serverText ? serverText : $t('chat.messages.failedHint');
914
+ }
915
+
902
916
  function openUpgradePlans() {
903
917
  // A host that is a guest on somebody else's page decides what "upgrade" means there; the billing page of the
904
918
  // Widgetic site would take the visitor off the page they are on.
@@ -943,6 +957,26 @@
943
957
  /** The thinking line is up only while a generation is running. */
944
958
  let thinkingHold = $state(false);
945
959
  let generationWasRunning = false;
960
+ let keptThinkingText = $state('');
961
+ let thinkingStartedAtMs = $state<number | null>(null);
962
+ let codeStreamingStartedAtMs = $state<number | null>(null);
963
+ let frozenThoughtSeconds = $state<number | null>(null);
964
+ let thinkingExpanded = $state(false);
965
+ let generationAriaLine = $state('');
966
+ let lastGenerationAriaKey = '';
967
+ let thinkingStreamEl = $state<HTMLDivElement | null>(null);
968
+
969
+ const planCardView = $derived(
970
+ isGenerating && generationPlan
971
+ ? mapWidgetPlanToPlanCard(generationPlan, $t('chat.plan.title'))
972
+ : null,
973
+ );
974
+ const planCardMessages = $derived({
975
+ progress: $t('chat.plan.progress', { current: '{current}', total: '{total}' }),
976
+ showMoreTasks: $t('chat.plan.showMoreTasks', { count: '{count}' }),
977
+ showFewerTasks: $t('chat.plan.showFewerTasks'),
978
+ });
979
+
946
980
  // The first paint is shorter than the loaded page. Scrolling then, or treating
947
981
  // that short box as "the user is at the top", loads older pages and never
948
982
  // lands on the newest message. Pin once, after this load has finished.
@@ -965,30 +999,75 @@
965
999
  $effect(() => {
966
1000
  if (isGenerating && !generationWasRunning) {
967
1001
  keptGenerationText = '';
1002
+ keptThinkingText = '';
968
1003
  shownGenerationCount = 0;
969
1004
  thinkingShownCount = 0;
970
1005
  thinkingHold = true;
1006
+ thinkingStartedAtMs = Date.now();
1007
+ codeStreamingStartedAtMs = null;
1008
+ frozenThoughtSeconds = null;
1009
+ thinkingExpanded = false;
1010
+ generationAriaLine = '';
1011
+ lastGenerationAriaKey = '';
971
1012
  }
972
1013
  if (!isGenerating && generationWasRunning) {
973
1014
  keptGenerationText = '';
1015
+ keptThinkingText = '';
974
1016
  shownGenerationCount = 0;
975
1017
  thinkingShownCount = 0;
976
1018
  thinkingHold = false;
1019
+ thinkingStartedAtMs = null;
1020
+ codeStreamingStartedAtMs = null;
1021
+ frozenThoughtSeconds = null;
1022
+ thinkingExpanded = false;
977
1023
  }
978
1024
  generationWasRunning = isGenerating;
979
1025
  if (messages.length === 0 && !isGenerating) {
980
1026
  keptGenerationText = '';
1027
+ keptThinkingText = '';
981
1028
  shownGenerationCount = 0;
982
1029
  thinkingShownCount = 0;
983
1030
  thinkingHold = false;
984
1031
  }
985
1032
  });
986
1033
 
1034
+ $effect(() => {
1035
+ const incoming = generationThinking;
1036
+ if (!incoming) return;
1037
+ const merged = mergeGenerationStream(keptThinkingText, incoming);
1038
+ if (merged !== keptThinkingText) keptThinkingText = merged;
1039
+ });
1040
+
987
1041
  $effect(() => {
988
1042
  const incoming = generationStream;
989
1043
  if (!incoming) return;
990
1044
  const merged = mergeGenerationStream(keptGenerationText, incoming);
991
1045
  if (merged !== keptGenerationText) keptGenerationText = merged;
1046
+ if (!codeStreamingStartedAtMs) {
1047
+ codeStreamingStartedAtMs = Date.now();
1048
+ frozenThoughtSeconds = thoughtDurationSeconds(thinkingStartedAtMs, codeStreamingStartedAtMs);
1049
+ }
1050
+ });
1051
+
1052
+ const activityPhase = $derived(
1053
+ generationActivityPhase(isGenerating, keptThinkingText, keptGenerationText),
1054
+ );
1055
+
1056
+ $effect(() => {
1057
+ const key = generationActivityAriaKey(activityPhase) ?? '';
1058
+ if (!key || key === lastGenerationAriaKey) return;
1059
+ lastGenerationAriaKey = key;
1060
+ generationAriaLine = $t(key);
1061
+ });
1062
+
1063
+ $effect(() => {
1064
+ if (!isGenerating || !thinkingStreamEl) return;
1065
+ const length = keptThinkingText.length;
1066
+ if (length === 0) return;
1067
+ tick().then(() => {
1068
+ if (!thinkingStreamEl) return;
1069
+ thinkingStreamEl.scrollTop = thinkingStreamEl.scrollHeight;
1070
+ });
992
1071
  });
993
1072
 
994
1073
  // Reveal from the first character already on screen, then catch up to new tokens.
@@ -1160,6 +1239,21 @@
1160
1239
  }
1161
1240
  }
1162
1241
 
1242
+ function headCommitRestoreTargetId(): string | null {
1243
+ for (let index = chatTurns.length - 1; index >= 0; index--) {
1244
+ const reply = getTurnCommitReply(chatTurns[index]);
1245
+ if (reply && isHeadCommitReply(reply)) return reply.id;
1246
+ }
1247
+ return null;
1248
+ }
1249
+
1250
+ function restoredVersionFromTurn(turn: ChatTurn): string | null {
1251
+ const fork = turn.replies.map((reply) => restoreForkLabel(reply.messageContent)).find(Boolean);
1252
+ if (!fork) return null;
1253
+ const match = /Version\s+(\d+)/i.exec(fork);
1254
+ return match?.[1] ?? null;
1255
+ }
1256
+
1163
1257
  function handleRestoreCheckpoint(messageId: string) {
1164
1258
  // Find the index of the message to restore to
1165
1259
  const messageIndex = messages.findIndex(msg => msg.id === messageId);
@@ -1455,11 +1549,12 @@
1455
1549
  }
1456
1550
  </script>
1457
1551
 
1552
+ <div class="{panelLayout ? 'panel-messages-shell flex h-full min-h-0 w-full flex-1 flex-col' : 'contents'}">
1458
1553
  <div
1459
1554
  bind:this={messagesContainer}
1460
- class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4 pb-3"
1555
+ class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto {panelLayout ? 'min-h-0 flex-1 gap-4 pb-1' : 'space-y-4 pb-3'}"
1461
1556
  class:loading={isLoading}
1462
- style="padding: 12px; overflow-anchor: none;"
1557
+ style={panelLayout ? 'padding: 8px 16px 0; overflow-anchor: none;' : 'padding: 8px 16px 12px; overflow-anchor: none;'}
1463
1558
  use:detectMessagesScrollbar
1464
1559
  onscroll={handleScroll}
1465
1560
  >
@@ -1467,52 +1562,56 @@
1467
1562
  messages and found none. A generation in flight hides it too: the user
1468
1563
  bubble lands a tick after send, so the list is briefly empty again. -->
1469
1564
  {#if showEmptyState && !isLoading && !isGenerating}
1470
- <div class="empty-state-ct flex flex-col items-center justify-center text-center max-w-sm w-full" style="align-self: center;">
1471
- <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 {$t('chat.messages.startTitle')}</h3>
1472
- <p class="text-gray-600 dark:text-gray-400 text-sm mb-6">
1473
- {$t('chat.messages.startHint', { type: contextTypeLabel(context.type, $t) })}
1474
- </p>
1475
-
1476
- <!-- Contextual suggestions -->
1477
- <SuggestionButtons
1478
- {context}
1479
- visible={true}
1480
- on:suggestionSelected={handleSuggestionSelected}
1481
- />
1565
+ <!-- Figma: Chat / Empty. The hero (a circle with the sparkles icon, the title and a line under it) sits in the
1566
+ middle of the messages, and the suggestions are pinned under it, above the composer. The block takes the
1567
+ free height with flex-1 (not min-h-full): the sticky scroll-to-bottom row below it needs its own room, and a
1568
+ block as tall as the whole area would push it out and make the list scroll. -->
1569
+ <div class="empty-state-ct flex w-full flex-1 flex-col gap-4 {panelLayout ? 'min-h-0 pb-2' : ''}">
1570
+ <div class="empty-state-hero flex flex-1 flex-col items-center justify-center gap-3 px-2 text-center">
1571
+ <span class="empty-state-icon-circle bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-full" aria-hidden="true">
1572
+ <IconSparkles class="size-4 stroke-2" />
1573
+ </span>
1574
+ <div class="flex flex-col gap-0.5">
1575
+ <h3 class="text-body-medium text-foreground">{$t('chat.messages.emptyTitle')}</h3>
1576
+ <p class="text-body text-muted-foreground">{$t('chat.messages.emptyHint')}</p>
1577
+ </div>
1578
+ </div>
1579
+
1580
+ {#if panelLayout}
1581
+ <PanelSuggestionButtons
1582
+ disabled={isGenerating}
1583
+ onPick={(text) => onSuggestionSelected?.(text)}
1584
+ />
1585
+ {:else}
1586
+ <SuggestionButtons
1587
+ {context}
1588
+ visible={true}
1589
+ on:suggestionSelected={handleSuggestionSelected}
1590
+ />
1591
+ {/if}
1482
1592
  </div>
1483
1593
  {/if}
1484
1594
 
1485
1595
  <!-- Conversation turns (user prompt + assistant status grouped) -->
1486
1596
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
1487
- <div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5"
1488
- class:wc-chat-turn-head={isViewingTurn(turn)}
1489
- data-you-are-here={isViewingTurn(turn) ? 'true' : undefined}
1490
- >
1597
+ <div class="wc-chat-turn-ct rounded-lg {panelLayout ? 'flex flex-col gap-[52px]' : 'space-y-1.5 border border-transparent p-0.5'}">
1491
1598
  {#if turn.user}
1492
1599
  {@const userMsg = turn.user}
1493
1600
  {@const shownAttachments = visibleUserAttachments(turn, turnIndex)}
1494
- {@const commitReply = getTurnHeadOrCommitReply(turn)}
1495
- <div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
1601
+ <div class="message-container wc-chat-turn-user flex w-full flex-col {panelLayout ? 'items-end' : 'items-stretch'}"
1496
1602
  class:opacity-75={userMsg._optimistic}
1497
1603
  class:opacity-50={userMsg._failed}
1498
1604
  class:has-attachments={shownAttachments.length > 0}
1499
1605
  >
1500
- <div class="wc-user-bubble-row flex w-full items-start gap-2">
1501
- {#if isViewingTurn(turn)}
1502
- <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title={$t('chat.messages.viewingTitle')}>
1503
- <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1504
- <path d="M20 6L9 17l-5-5"/>
1505
- </svg>
1506
- {$t('chat.messages.viewing')}
1507
- <span class="wc-head-commit-arrow" aria-hidden="true">{$textDirection === 'rtl' ? '←' : '→'}</span>
1508
- </div>
1509
- {/if}
1606
+ <Message
1607
+ role="user"
1608
+ class="{panelLayout ? 'panel-layout-user-message ms-auto w-fit max-w-[85%]' : 'ms-auto w-full max-w-full'}"
1609
+ data-testid="chat-user-bubble"
1610
+ >
1611
+ {#snippet children()}
1510
1612
  <div
1511
- class="message-bubble relative ms-auto w-fit max-w-[94%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
1512
- class:p-3={shownAttachments.length === 0}
1613
+ class="message-bubble-user text-sm select-text {panelLayout ? 'w-auto max-w-full leading-5' : 'w-full leading-relaxed'}"
1513
1614
  class:p-0={shownAttachments.length > 0}
1514
- class:bubble-fit-content={shownAttachments.length > 0}
1515
- style="background-color: {isCompleted ? MESSAGE_COLORS.USER_COMPLETED : MESSAGE_COLORS.USER_ACTIVE}; color: {MESSAGE_COLORS.USER_TEXT};"
1516
1615
  use:bubbleScrollPadding
1517
1616
  >
1518
1617
  {#if userMsg.messageContent}
@@ -1533,7 +1632,7 @@
1533
1632
  {/each}
1534
1633
  </div>
1535
1634
  {:else}
1536
- <p class="whitespace-pre-wrap p-3" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
1635
+ <p class="whitespace-pre-wrap {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
1537
1636
  {/if}
1538
1637
  {/if}
1539
1638
  {#if shownAttachments.length > 0}
@@ -1552,23 +1651,9 @@
1552
1651
  </div>
1553
1652
  {/if}
1554
1653
  </div>
1555
- </div>
1556
- {#if turnNeedsRetry(turn, turnIndex) && !isLoading}
1557
- <div class="retry-codegen-row flex justify-end mt-1">
1558
- <button
1559
- class="retry-codegen-btn"
1560
- onclick={() => handleRetryTurn(turn, turnIndex)}
1561
- title={$t('chat.messages.retryPromptTitle')}
1562
- >
1563
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1564
- <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1565
- <path d="M21 3v6h-6"/>
1566
- </svg>
1567
- {$t('chat.messages.retry')}
1568
- </button>
1569
- </div>
1570
- {/if}
1571
- {#if showCommitMetaOnUserTurn(turn)}
1654
+ {/snippet}
1655
+ </Message>
1656
+ {#if showCommitMetaOnUserTurn(turn) && (!panelLayout || showCommitMeta)}
1572
1657
  {@const commitTitle = getTurnCommitTitle(turn)}
1573
1658
  {@const versionLabel = getTurnVersionLabel(turn)}
1574
1659
  {#if showCommitMeta && commitTitle}
@@ -1578,90 +1663,59 @@
1578
1663
  </span>
1579
1664
  </div>
1580
1665
  {/if}
1581
- <div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
1582
- <div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
1583
- <!-- Version 1 is the sketch turn. The words read as a second message, so they stay off. Restore stays. -->
1584
- {#if versionLabel && versionNumberFromLabel(versionLabel) !== 1}
1585
- <span class="wc-user-version-label text-xs text-gray-500">
1586
- {versionLabelText(versionLabel, $t)}
1587
- </span>
1588
- {/if}
1589
- {#if onRateVersion && !isLoading}
1590
- {@const ratedMessageId = ratableVersionReplyId(turn)}
1591
- {#if ratedMessageId}
1592
- {@const givenRating = versionRatings[ratedMessageId]}
1593
- <span class="wc-version-rating inline-flex items-center gap-1" role="group" aria-label={$t('chat.messages.rateGroup')}>
1594
- <button
1595
- type="button"
1596
- class="wc-version-rating-btn wc-version-rating-up"
1597
- aria-pressed={givenRating === 'up'}
1598
- aria-label={$t('chat.messages.rateUp')}
1599
- title={$t('chat.messages.rateUp')}
1600
- onclick={() => onRateVersion?.(ratedMessageId, 'up')}
1601
- >
1602
- <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">
1603
- <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" />
1604
- </svg>
1605
- </button>
1606
- <button
1607
- type="button"
1608
- class="wc-version-rating-btn wc-version-rating-down"
1609
- aria-pressed={givenRating === 'down'}
1610
- aria-label={$t('chat.messages.rateDown')}
1611
- title={$t('chat.messages.rateDown')}
1612
- onclick={() => onRateVersion?.(ratedMessageId, 'down')}
1613
- >
1614
- <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">
1615
- <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" />
1616
- </svg>
1617
- </button>
1618
- </span>
1619
- {/if}
1620
- {/if}
1621
- {#if showCommitMeta && getTurnCommitShort(turn)}
1622
- <span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
1623
- {$t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })}
1624
- </span>
1625
- {/if}
1626
- </div>
1627
- {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
1628
- {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(versionLabel) !== 1)}
1629
- <button
1630
- class="restore-checkpoint-btn shrink-0"
1631
- disabled={restoreIsCurrentHead}
1632
- onclick={() => {
1633
- if (restoreIsCurrentHead) return;
1634
- handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
1635
- }}
1636
- title={restoreIsCurrentHead
1637
- ? $t('chat.messages.alreadyHead')
1638
- : $t('chat.messages.restoreTitle')}
1639
- >
1640
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1641
- <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
1642
- <path d="M3 3v5h5"/>
1643
- </svg>
1644
- {$t('chat.messages.restore')}
1645
- </button>
1646
- {/if}
1647
- </div>
1666
+ {@const restoreTargetId = canOfferRestore ? restoreBeforeTarget(restorePoints, turnIndex) : null}
1667
+ {@const restoredVersion = restoredVersionFromTurn(turn)}
1668
+ {@const headRedoId = turnIsRestoreEcho(turn) ? headCommitRestoreTargetId() : null}
1669
+ <MessageCheckpointRow
1670
+ class="wc-user-commit-meta-ct mt-1"
1671
+ versionLabel={versionLabel && versionNumberFromLabel(versionLabel) !== 1
1672
+ ? versionLabelText(versionLabel, $t)
1673
+ : showCommitMeta && getTurnCommitShort(turn)
1674
+ ? $t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })
1675
+ : null}
1676
+ showRestore={!!restoreTargetId}
1677
+ showRedo={!!headRedoId}
1678
+ restoredToVersion={restoredVersion}
1679
+ onRestore={restoreTargetId ? () => handleRestoreCheckpoint(restoreTargetId) : undefined}
1680
+ onRedo={headRedoId ? () => handleRestoreCheckpoint(headRedoId) : undefined}
1681
+ messages={{
1682
+ version: CHAT_MESSAGES['chat.checkpoint.version'],
1683
+ restored: CHAT_MESSAGES['chat.checkpoint.restored'],
1684
+ restore: $t('chat.messages.restore'),
1685
+ redo: $t('chat.checkpoint.redo')
1686
+ }}
1687
+ />
1648
1688
  {/if}
1649
1689
  </div>
1650
1690
  {/if}
1651
1691
 
1652
1692
  {#each turn.replies as reply (reply.id)}
1653
1693
  {#if shouldShowAssistantReply(reply)}
1654
- <div class="message-container wc-chat-turn-reply me-auto w-fit max-w-[94%] flex flex-col items-stretch overflow-visible"
1655
- class:opacity-75={reply._optimistic}
1656
- class:opacity-50={reply._failed}
1657
- class:current-checkpoint={isHeadCommitReply(reply)}
1694
+ {#if panelLayout && isCodegenFailure(reply)}
1695
+ <!-- Figma Alert (526:3205): a failed reply in the docked panel is a card with a title, a line and "Try again",
1696
+ not a red line of text. The button runs the prompt of this turn again, on the last failure of the turn only. -->
1697
+ <ChatAlertCard
1698
+ class="wc-chat-turn-reply"
1699
+ title={$t('chat.messages.failedTitle')}
1700
+ description={failureAlertDescription(reply)}
1701
+ actionLabel={onRetryMessage &&
1702
+ isLastCodegenFailureInTurn(turn, reply) &&
1703
+ !isPlanLimitMessage(reply.messageContent) &&
1704
+ turnNeedsRetry(turn, turnIndex)
1705
+ ? $t('chat.messages.failedRetry')
1706
+ : ''}
1707
+ onAction={() => handleRetryTurn(turn, turnIndex)}
1708
+ />
1709
+ {:else}
1710
+ <Message
1711
+ role="assistant"
1712
+ class="wc-chat-turn-reply max-w-full"
1713
+ error={isCodegenFailure(reply)}
1714
+ errorText={visibleMessageContent(reply.messageContent || '')}
1658
1715
  >
1659
- <div
1660
- class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text p-3"
1661
- class:wc-codegen-failure={isCodegenFailure(reply)}
1662
- style="background-color: {isHeadCommitReply(reply) ? '#e0f2fe' : MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT};{isHeadCommitReply(reply) ? ' border: 1.5px solid #7dd3fc;' : ''}"
1663
- use:bubbleScrollPadding
1664
- >
1716
+ {#snippet children()}
1717
+ {#if reply.messageContent && (panelLayout || !(reply.suggestions && reply.suggestions.length > 0))}
1718
+ <div class="message-content-assistant select-text text-sm leading-relaxed" use:bubbleScrollPadding>
1665
1719
  {#if reply.messageContent}
1666
1720
  {#if hasCodeBlocks(reply.messageContent)}
1667
1721
  <div class="message-content-mixed">
@@ -1684,6 +1738,10 @@
1684
1738
  {/if}
1685
1739
  {/if}
1686
1740
  </div>
1741
+ {/if}
1742
+ {/snippet}
1743
+ </Message>
1744
+ {/if}
1687
1745
 
1688
1746
  {#if reply.designControls && renderDesignControls}
1689
1747
  <div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
@@ -1691,50 +1749,58 @@
1691
1749
  </div>
1692
1750
  {/if}
1693
1751
 
1694
- {#if reply.suggestions && reply.suggestions.length > 0}
1695
- <div class="clarification-suggestions flex flex-wrap gap-1.5 mt-1.5">
1696
- {#each reply.suggestions as suggestion, i (i)}
1697
- <button
1698
- type="button"
1699
- class="clarification-chip"
1700
- disabled={!onClarificationSuggestionSelected || isLoading || isGenerating}
1701
- onclick={() => onClarificationSuggestionSelected?.(suggestion)}
1702
- title={suggestion.label}
1703
- >
1704
- {suggestion.label}
1705
- </button>
1706
- {/each}
1707
- </div>
1752
+ {#if reply.suggestions && reply.suggestions.length > 0 && !panelLayout}
1753
+ <QuestionCard
1754
+ class="mt-1.5 w-full max-w-full"
1755
+ question={(visibleMessageContent(reply.messageContent || '') || $t('chat.messages.clarificationPrompt')).trim()}
1756
+ options={reply.suggestions.map((suggestion, index) => ({
1757
+ id: String(index),
1758
+ label: suggestion.label
1759
+ }))}
1760
+ onSubmit={(selectedIds) => {
1761
+ const picked = Number(selectedIds[0]);
1762
+ const suggestion = reply.suggestions?.[picked];
1763
+ if (suggestion) onClarificationSuggestionSelected?.(suggestion);
1764
+ }}
1765
+ />
1708
1766
  {/if}
1709
1767
 
1710
- {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && turnNeedsRetry(turn, turnIndex)}
1711
- <div class="retry-codegen-row flex justify-start mt-1">
1712
- {#if isPlanLimitMessage(reply.messageContent)}
1768
+ <!-- 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. -->
1769
+ {#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && isPlanLimitMessage(reply.messageContent) && turnNeedsRetry(turn, turnIndex)}
1770
+ <div class="wc-upgrade-row flex justify-start">
1713
1771
  <button
1714
- class="retry-codegen-btn"
1772
+ type="button"
1773
+ class="wc-upgrade-btn"
1715
1774
  onclick={openUpgradePlans}
1716
1775
  title={$t('chat.messages.upgradeTitle')}
1717
1776
  >
1718
1777
  {$t('chat.messages.upgrade')}
1719
1778
  </button>
1720
- {:else}
1721
- <button
1722
- class="retry-codegen-btn"
1723
- onclick={() => handleRetryTurn(turn, turnIndex)}
1724
- title={$t('chat.messages.retryLastTitle')}
1725
- >
1726
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1727
- <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1728
- <path d="M21 3v6h-6"/>
1729
- </svg>
1730
- {$t('chat.messages.retry')}
1731
- </button>
1732
- {/if}
1733
1779
  </div>
1734
1780
  {/if}
1735
- </div>
1736
1781
  {/if}
1737
1782
  {/each}
1783
+
1784
+ <!-- Copy, regenerate and the two thumbs: at the end of the last message only, and not while something is being generated.
1785
+ Not in the panel either: the creator page's chat panel (Figma 526:2706, ready) draws no row of actions under the last message. -->
1786
+ {#if !panelLayout && turnIndex === chatTurns.length - 1 && !isLoading && !isGenerating}
1787
+ {@const copyText = textToCopy(
1788
+ turn.replies.filter(shouldShowAssistantReply).map((reply) => visibleMessageContent(reply.messageContent || '')),
1789
+ getTurnCommitTitle(turn),
1790
+ )}
1791
+ {@const canRegenerate = !!onRetryMessage && turnNeedsRetry(turn, turnIndex)}
1792
+ {@const ratedMessageId = onRateVersion ? ratableVersionReplyId(turn) : null}
1793
+ {#if copyText !== '' || canRegenerate || ratedMessageId}
1794
+ <MessageActions
1795
+ {copyText}
1796
+ {canRegenerate}
1797
+ onRegenerate={() => handleRetryTurn(turn, turnIndex)}
1798
+ {ratedMessageId}
1799
+ rating={ratedMessageId ? versionRatings[ratedMessageId] : 'none'}
1800
+ onRate={(messageId, pressed) => onRateVersion?.(messageId, pressed)}
1801
+ />
1802
+ {/if}
1803
+ {/if}
1738
1804
  </div>
1739
1805
  {/each}
1740
1806
 
@@ -1749,22 +1815,118 @@
1749
1815
  {/if}
1750
1816
  {#if thinkingHold}
1751
1817
  <div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
1752
- <div class="thinking-bubble relative inline-block whitespace-nowrap rounded-lg p-3 text-sm leading-relaxed shadow-sm"
1753
- style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
1818
+ {#if planCardView}
1819
+ <PlanCard
1820
+ class="w-full"
1821
+ dir="auto"
1822
+ role="region"
1823
+ aria-label={$t('chat.plan.regionLabel')}
1824
+ title={planCardView.title}
1825
+ tasks={planCardView.tasks}
1826
+ progressCurrent={planCardView.progressCurrent}
1827
+ progressTotal={planCardView.progressTotal}
1828
+ visibleTaskCount={4}
1829
+ messages={planCardMessages}
1830
+ />
1831
+ {/if}
1832
+ <ActivityRow
1833
+ class="w-full"
1834
+ label={shownThinkingLabel || $t('chat.generation.thinking')}
1835
+ status={activityPhase === 'code-only' || activityPhase === 'thinking-and-code' ? 'running' : 'pending'}
1836
+ />
1837
+ <div
1838
+ class="generation-activity-card w-full max-w-full rounded-lg p-3 text-sm leading-relaxed shadow-sm"
1839
+ style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
1754
1840
  >
1755
- <span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
1756
- <span class="thinking-reveal absolute inset-0 flex items-center px-3">{shownThinkingLabel}</span>
1841
+ {#if activityPhase === 'shimmer-only'}
1842
+ <div class="thinking-bubble relative inline-block whitespace-nowrap">
1843
+ <span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
1844
+ <span class="thinking-reveal absolute inset-0 flex items-center">{shownThinkingLabel}</span>
1845
+ </div>
1846
+ {:else}
1847
+ {#if activityPhase === 'thinking-stream'}
1848
+ <div class="mb-2 flex items-center gap-2 font-medium">
1849
+ <div class="h-4 w-4 shrink-0 rounded-full border-2 border-gray-400 border-t-transparent animate-spin" aria-hidden="true"></div>
1850
+ <span class="thinking-reveal-inline">{$t('chat.generation.thinking')}</span>
1851
+ </div>
1852
+ <div
1853
+ bind:this={thinkingStreamEl}
1854
+ class="generation-thinking-stream max-h-32 w-full overflow-auto whitespace-pre-wrap break-words text-xs text-gray-600"
1855
+ dir="auto"
1856
+ >{keptThinkingText}</div>
1857
+ {:else if activityPhase === 'thinking-and-code' || activityPhase === 'code-only'}
1858
+ {#if keptThinkingText.trim().length > 0}
1859
+ <button
1860
+ type="button"
1861
+ 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"
1862
+ aria-expanded={thinkingExpanded}
1863
+ onclick={() => { thinkingExpanded = !thinkingExpanded; }}
1864
+ >
1865
+ <span>
1866
+ {#if frozenThoughtSeconds != null}
1867
+ {$t('chat.generation.thoughtFor', { seconds: String(frozenThoughtSeconds) })}
1868
+ {:else}
1869
+ {$t('chat.generation.thinking')}
1870
+ {/if}
1871
+ </span>
1872
+ <span class="sr-only">
1873
+ {thinkingExpanded ? $t('chat.generation.collapseThought') : $t('chat.generation.expandThought')}
1874
+ </span>
1875
+ </button>
1876
+ {#if thinkingExpanded}
1877
+ <div
1878
+ class="generation-thinking-stream mb-2 max-h-24 w-full overflow-auto whitespace-pre-wrap break-words text-xs text-gray-600"
1879
+ dir="auto"
1880
+ >{keptThinkingText}</div>
1881
+ {/if}
1882
+ {/if}
1883
+ {#if shownGenerationText}
1884
+ <div class="mb-1 text-xs font-medium text-gray-800">
1885
+ <span>{$t('chat.generation.writingCode')}</span>
1886
+ </div>
1887
+ <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>
1888
+ {/if}
1889
+ {/if}
1890
+ {/if}
1757
1891
  </div>
1892
+ {#if generationAriaLine}
1893
+ <p class="sr-only" aria-live="polite">{generationAriaLine}</p>
1894
+ {/if}
1758
1895
  </div>
1759
1896
  {/if}
1760
- {#if shownGenerationText}
1761
- <div class="generation-stream-ct flex flex-col items-start gap-2 px-3 pb-3">
1762
- <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>
1897
+
1898
+ {#if !panelLayout}
1899
+ <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2">
1900
+ <ScrollToBottom
1901
+ visible={!autoScroll && messages.length > 0 && !isLoading}
1902
+ label={$t('chat.messages.scrollToBottom')}
1903
+ onScroll={() => {
1904
+ autoScroll = true;
1905
+ scrollMessagesToEnd();
1906
+ }}
1907
+ />
1763
1908
  </div>
1764
1909
  {/if}
1765
1910
  </div>
1911
+ {#if panelLayout && panelAnchoredFollowUp}
1912
+ <div class="panel-anchored-followup ms-auto flex w-full max-w-full shrink-0 flex-col items-end px-4 pb-2">
1913
+ <PanelFollowUpSuggestions
1914
+ labels={panelAnchoredFollowUp.labels}
1915
+ disabled={isGenerating}
1916
+ onPick={(text) => {
1917
+ onSuggestionSelected?.(text);
1918
+ }}
1919
+ />
1920
+ </div>
1921
+ {/if}
1922
+ </div>
1766
1923
 
1767
1924
  <style>
1925
+ /* Figma panel: user bubble only — no hover action row consuming gap above the assistant text. */
1926
+ :global(.panel-layout-user-message > div.duration-fast) {
1927
+ display: none;
1928
+ min-height: 0;
1929
+ }
1768
1930
  .thinking-sizer {
1769
1931
  visibility: hidden;
1770
1932
  }
@@ -1780,6 +1942,22 @@
1780
1942
  0% { background-position: 100% 0; }
1781
1943
  100% { background-position: -100% 0; }
1782
1944
  }
1945
+ .thinking-reveal-inline {
1946
+ background-image: linear-gradient(100deg, #1f2937 35%, #ffffff 50%, #1f2937 65%);
1947
+ background-size: 200% 100%;
1948
+ -webkit-background-clip: text;
1949
+ background-clip: text;
1950
+ color: transparent;
1951
+ animation: thinking-shine 1.6s linear infinite;
1952
+ }
1953
+ @media (prefers-reduced-motion: reduce) {
1954
+ .thinking-reveal,
1955
+ .thinking-reveal-inline {
1956
+ animation: none;
1957
+ color: inherit;
1958
+ background-image: none;
1959
+ }
1960
+ }
1783
1961
  .generation-stream {
1784
1962
  scrollbar-width: thin;
1785
1963
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
@@ -1851,33 +2029,11 @@
1851
2029
  align-items: flex-start; /* Left align for assistant messages */
1852
2030
  }
1853
2031
 
1854
- /* Restore checkpoint — always visible below user messages */
1855
- .wc-chat-turn-head {
1856
- border-color: #bae6fd;
1857
- background-color: #f8fcff;
1858
- padding: 6px;
1859
- }
1860
-
1861
2032
  .wc-codegen-failure {
1862
2033
  border: 1px solid #fecaca;
1863
2034
  background-color: #fef2f2 !important;
1864
2035
  }
1865
2036
 
1866
- .wc-head-commit-label {
1867
- margin-bottom: 0;
1868
- }
1869
-
1870
- .wc-head-commit-arrow {
1871
- font-size: 11px;
1872
- line-height: 1;
1873
- font-weight: 700;
1874
- margin-inline-start: 2px;
1875
- }
1876
-
1877
- .wc-head-commit-meta-ct .wc-head-commit-label {
1878
- margin-top: 0;
1879
- }
1880
-
1881
2037
  /* What the turn shipped, in the commit's own words. Truncated at the turn's
1882
2038
  width — the full subject stays in the tooltip — so a prompt-derived title
1883
2039
  cannot widen the bubble past its 80% cap. */
@@ -1888,94 +2044,62 @@
1888
2044
  white-space: nowrap;
1889
2045
  }
1890
2046
 
1891
- .restore-checkpoint-row {
1892
- margin-top: 4px;
2047
+ /* 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
2048
+ 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. */
2049
+ .wc-restore-slot {
2050
+ margin-inline-start: auto;
2051
+ flex-shrink: 0;
2052
+ opacity: 0;
2053
+ transition: opacity 0.15s ease;
1893
2054
  }
1894
2055
 
1895
- .retry-codegen-row {
1896
- margin-top: 4px;
2056
+ .wc-chat-turn-user:hover .wc-restore-slot,
2057
+ .wc-restore-slot:has(:focus-visible) {
2058
+ opacity: 1;
1897
2059
  }
1898
-
1899
- .restore-checkpoint-btn,
1900
- .retry-codegen-btn {
1901
- display: inline-flex;
1902
- align-items: center;
1903
- gap: 4px;
1904
- padding: 3px 10px;
1905
- background: transparent;
1906
- color: #888;
1907
- border: 1px solid #ddd;
1908
- border-radius: 12px;
1909
- font-size: 11px;
1910
- font-weight: 500;
1911
- cursor: pointer;
1912
- transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
1913
- white-space: nowrap;
2060
+
2061
+ @media (hover: none) {
2062
+ .wc-restore-slot {
2063
+ opacity: 1;
2064
+ }
1914
2065
  }
1915
-
1916
- .restore-checkpoint-btn:hover,
1917
- .retry-codegen-btn:hover {
1918
- background: rgba(0, 0, 0, 0.06);
1919
- color: #555;
1920
- border-color: #bbb;
2066
+
2067
+ @media (prefers-reduced-motion: reduce) {
2068
+ .wc-restore-slot {
2069
+ transition: none;
2070
+ }
1921
2071
  }
1922
2072
 
1923
- .restore-checkpoint-btn:disabled {
1924
- opacity: 0.45;
1925
- cursor: not-allowed;
1926
- pointer-events: none;
2073
+ /* "Upgrade" under a failure about the plan or the credits: a plain button, because the failure itself is already said above it. */
2074
+ .wc-upgrade-row {
2075
+ margin-top: 4px;
1927
2076
  }
1928
2077
 
1929
- /* The thumbs next to a version's name. A pressed thumb is filled and takes the colour of what it says. */
1930
- .wc-version-rating-btn {
2078
+ .wc-upgrade-btn {
1931
2079
  display: inline-flex;
1932
2080
  align-items: center;
1933
- justify-content: center;
1934
- width: 22px;
1935
- height: 22px;
1936
- padding: 0;
1937
- background: transparent;
1938
- color: #9ca3af;
1939
- border: 1px solid transparent;
1940
- border-radius: 6px;
2081
+ padding: 4px 12px;
2082
+ background: #ffffff;
2083
+ color: #111827;
2084
+ border: 1px solid #d1d5db;
2085
+ border-radius: 8px;
2086
+ font-size: 12px;
2087
+ font-weight: 500;
1941
2088
  cursor: pointer;
1942
- transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
2089
+ white-space: nowrap;
2090
+ transition: background-color 0.15s ease, border-color 0.15s ease;
1943
2091
  }
1944
2092
 
1945
- .wc-version-rating-btn:hover {
1946
- background: rgba(0, 0, 0, 0.06);
1947
- color: #555;
2093
+ .wc-upgrade-btn:hover {
2094
+ background: #f3f4f6;
2095
+ border-color: #9ca3af;
1948
2096
  }
1949
2097
 
1950
- .wc-version-rating-btn:focus-visible {
2098
+ .wc-upgrade-btn:focus-visible {
1951
2099
  outline: 2px solid #93c5fd;
1952
2100
  outline-offset: 1px;
1953
2101
  }
1954
2102
 
1955
- .wc-version-rating-btn[aria-pressed='true'].wc-version-rating-up {
1956
- color: #15803d;
1957
- background: #f0fdf4;
1958
- border-color: #bbf7d0;
1959
- }
1960
-
1961
- .wc-version-rating-btn[aria-pressed='true'].wc-version-rating-down {
1962
- color: #b91c1c;
1963
- background: #fef2f2;
1964
- border-color: #fecaca;
1965
- }
1966
-
1967
- .retry-codegen-btn {
1968
- color: #b91c1c;
1969
- border-color: #fecaca;
1970
- background: #fff7f7;
1971
- }
1972
-
1973
- .retry-codegen-btn:hover {
1974
- background: #fee2e2;
1975
- color: #991b1b;
1976
- border-color: #fca5a5;
1977
- }
1978
-
1979
2103
  /* Clarification-card suggestion chips — tap to send as the next user message */
1980
2104
  .clarification-chip {
1981
2105
  display: inline-flex;
@@ -2009,40 +2133,6 @@
2009
2133
  cursor: default;
2010
2134
  }
2011
2135
 
2012
- .restore-checkpoint-btn svg,
2013
- .retry-codegen-btn svg {
2014
- flex-shrink: 0;
2015
- }
2016
-
2017
- /* Checkpoint label — shown above the restored message */
2018
- .checkpoint-label {
2019
- display: inline-flex;
2020
- align-items: center;
2021
- gap: 4px;
2022
- padding: 2px 8px;
2023
- background: #0ea5e9;
2024
- color: white;
2025
- border-radius: 8px;
2026
- font-size: 10px;
2027
- font-weight: 600;
2028
- letter-spacing: 0.02em;
2029
- margin-bottom: 4px;
2030
- align-self: flex-end;
2031
- }
2032
-
2033
- /* Restored button state */
2034
- .restore-checkpoint-btn.restored {
2035
- opacity: 0.5;
2036
- cursor: default;
2037
- border-color: #7dd3fc;
2038
- color: #0ea5e9;
2039
- }
2040
- .restore-checkpoint-btn.restored:hover {
2041
- background: transparent;
2042
- color: #0ea5e9;
2043
- border-color: #7dd3fc;
2044
- }
2045
-
2046
2136
  /* Cap huge messages (legacy full-file dumps) so bubbles stay readable */
2047
2137
  .message-bubble {
2048
2138
  max-width: 100%;