@widgetic/chat 0.1.35 → 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.
- package/README.md +34 -6
- package/dist/components/ActionBar.svelte +8 -0
- package/dist/components/Chat.svelte +87 -100
- package/dist/components/Chat.svelte.d.ts +19 -1
- package/dist/components/ChatComposer.svelte +156 -0
- package/dist/components/ChatComposer.svelte.d.ts +26 -0
- package/dist/components/ChatMessages.svelte +388 -385
- package/dist/components/ChatMessages.svelte.d.ts +14 -6
- package/dist/components/IconButton.svelte +125 -0
- package/dist/components/IconButton.svelte.d.ts +22 -0
- package/dist/components/MessageActions.svelte +48 -0
- package/dist/components/MessageActions.svelte.d.ts +13 -0
- package/dist/components/PanelChatHeader.svelte +44 -0
- package/dist/components/PanelChatHeader.svelte.d.ts +12 -0
- package/dist/components/SuggestionButtons.svelte +11 -163
- package/dist/i18n/messages.d.ts +40 -12
- package/dist/i18n/messages.js +40 -12
- package/dist/utils/generationActivity.d.ts +12 -0
- package/dist/utils/generationActivity.js +47 -0
- package/dist/utils/generationPlan.d.ts +32 -0
- package/dist/utils/generationPlan.js +89 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/messageActions.d.ts +54 -0
- package/dist/utils/messageActions.js +104 -0
- package/package.json +3 -3
|
@@ -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 {
|
|
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();
|
|
@@ -59,22 +78,29 @@
|
|
|
59
78
|
/**
|
|
60
79
|
* Every saved version for this widget. When one prompt produced two versions
|
|
61
80
|
* but the chat stored only one user message, the missing older version is
|
|
62
|
-
* shown as its own turn so
|
|
81
|
+
* shown as its own turn, so each version has its own place in the list.
|
|
63
82
|
*/
|
|
64
83
|
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
84
|
/** When false, hide commit hashes next to the version label (user mode). */
|
|
68
85
|
showCommitMeta?: boolean;
|
|
69
|
-
/** True while codegen / send is in flight —
|
|
86
|
+
/** True while codegen / send is in flight — no icons are drawn under the last message and no restore is offered. */
|
|
70
87
|
isGenerating?: boolean;
|
|
71
88
|
/** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
|
|
72
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;
|
|
73
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
|
+
*/
|
|
74
100
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
75
101
|
/**
|
|
76
|
-
* Gives
|
|
77
|
-
* 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.
|
|
78
104
|
*/
|
|
79
105
|
onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
|
|
80
106
|
/** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
|
|
@@ -114,10 +140,11 @@
|
|
|
114
140
|
versionLabelByCommitSha = {},
|
|
115
141
|
versionLabelByPrompt = {},
|
|
116
142
|
versionTimeline = [],
|
|
117
|
-
viewingVersion = null,
|
|
118
143
|
showCommitMeta = true,
|
|
119
144
|
isGenerating = false,
|
|
120
145
|
generationStream = '',
|
|
146
|
+
generationThinking = '',
|
|
147
|
+
generationPlan = null,
|
|
121
148
|
onSuggestionSelected,
|
|
122
149
|
onRestoreCheckpoint,
|
|
123
150
|
onRateVersion,
|
|
@@ -291,9 +318,9 @@
|
|
|
291
318
|
|
|
292
319
|
/**
|
|
293
320
|
* A retry that reused one user bubble leaves two commits on that turn, so
|
|
294
|
-
* Version 7 and Version 8 share a message and
|
|
295
|
-
*
|
|
296
|
-
* 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.
|
|
297
324
|
*/
|
|
298
325
|
function splitTurnsByCommit(turns: ChatTurn[]): ChatTurn[] {
|
|
299
326
|
const split: ChatTurn[] = [];
|
|
@@ -323,8 +350,8 @@
|
|
|
323
350
|
|
|
324
351
|
/**
|
|
325
352
|
* 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
|
-
*
|
|
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.
|
|
328
355
|
*/
|
|
329
356
|
function expandTurnsForSharedPrompts(turns: ChatTurn[]): ChatTurn[] {
|
|
330
357
|
if (!versionTimeline.length) return turns;
|
|
@@ -500,18 +527,6 @@
|
|
|
500
527
|
);
|
|
501
528
|
}
|
|
502
529
|
|
|
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
530
|
function canUndoHeadUserTurn(turn: ChatTurn): boolean {
|
|
516
531
|
return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
|
|
517
532
|
}
|
|
@@ -610,16 +625,6 @@
|
|
|
610
625
|
);
|
|
611
626
|
}
|
|
612
627
|
|
|
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
628
|
function getTurnOwnCommitShort(turn: ChatTurn): string | null {
|
|
624
629
|
return extractCommitShort(getTurnCommitReply(turn)?.messageContent || '');
|
|
625
630
|
}
|
|
@@ -723,17 +728,31 @@
|
|
|
723
728
|
return conversationHasCommitReply();
|
|
724
729
|
}
|
|
725
730
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
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' };
|
|
735
748
|
}
|
|
736
|
-
return
|
|
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
|
+
};
|
|
737
756
|
}
|
|
738
757
|
|
|
739
758
|
function isCodegenStatusBubble(content?: string | null): boolean {
|
|
@@ -759,8 +778,8 @@
|
|
|
759
778
|
return !isGenerationSummary(reply);
|
|
760
779
|
}
|
|
761
780
|
|
|
762
|
-
/** Show commit chrome
|
|
763
|
-
* Previously this was gated to Debug OFF (assistant reply hidden), but we want
|
|
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
|
|
764
783
|
* available in Debug ON too — the assistant summary and the user-side chrome coexist. */
|
|
765
784
|
function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
|
|
766
785
|
return !!getTurnHeadOrCommitReply(turn)
|
|
@@ -814,71 +833,25 @@
|
|
|
814
833
|
);
|
|
815
834
|
});
|
|
816
835
|
|
|
817
|
-
/**
|
|
818
|
-
|
|
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
|
-
}
|
|
836
|
+
/** One entry per turn, in the order of `chatTurns`. */
|
|
837
|
+
const restorePoints = $derived(chatTurns.map(restorePointOf));
|
|
835
838
|
|
|
836
|
-
/**
|
|
837
|
-
|
|
838
|
-
* would hide it again whenever messages finish loading.
|
|
839
|
-
*/
|
|
840
|
-
function viewingTurnIndex(): number {
|
|
841
|
-
return chatTurns.findIndex((turn) => isViewingTurn(turn));
|
|
842
|
-
}
|
|
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);
|
|
843
841
|
|
|
844
842
|
function shouldPinChatToBottom(): boolean {
|
|
845
|
-
//
|
|
846
|
-
// 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.
|
|
847
844
|
if (isGenerating) return true;
|
|
848
|
-
if (viewingVersion != null) {
|
|
849
|
-
const hereIndex = viewingTurnIndex();
|
|
850
|
-
if (hereIndex < 0 || hereIndex < chatTurns.length - 1) return false;
|
|
851
|
-
}
|
|
852
845
|
return autoScroll;
|
|
853
846
|
}
|
|
854
847
|
|
|
855
848
|
function scrollGenerationTail(): void {
|
|
856
849
|
const tail = messagesContainer?.querySelector('.generation-stream');
|
|
857
850
|
if (tail) tail.scrollTop = tail.scrollHeight;
|
|
851
|
+
const thinking = messagesContainer?.querySelector('.generation-thinking-stream');
|
|
852
|
+
if (thinking) thinking.scrollTop = thinking.scrollHeight;
|
|
858
853
|
}
|
|
859
854
|
|
|
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
855
|
function messageImpliesAttachedFile(content: string): boolean {
|
|
883
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(
|
|
884
857
|
content,
|
|
@@ -943,6 +916,26 @@
|
|
|
943
916
|
/** The thinking line is up only while a generation is running. */
|
|
944
917
|
let thinkingHold = $state(false);
|
|
945
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
|
+
|
|
946
939
|
// The first paint is shorter than the loaded page. Scrolling then, or treating
|
|
947
940
|
// that short box as "the user is at the top", loads older pages and never
|
|
948
941
|
// lands on the newest message. Pin once, after this load has finished.
|
|
@@ -965,30 +958,75 @@
|
|
|
965
958
|
$effect(() => {
|
|
966
959
|
if (isGenerating && !generationWasRunning) {
|
|
967
960
|
keptGenerationText = '';
|
|
961
|
+
keptThinkingText = '';
|
|
968
962
|
shownGenerationCount = 0;
|
|
969
963
|
thinkingShownCount = 0;
|
|
970
964
|
thinkingHold = true;
|
|
965
|
+
thinkingStartedAtMs = Date.now();
|
|
966
|
+
codeStreamingStartedAtMs = null;
|
|
967
|
+
frozenThoughtSeconds = null;
|
|
968
|
+
thinkingExpanded = false;
|
|
969
|
+
generationAriaLine = '';
|
|
970
|
+
lastGenerationAriaKey = '';
|
|
971
971
|
}
|
|
972
972
|
if (!isGenerating && generationWasRunning) {
|
|
973
973
|
keptGenerationText = '';
|
|
974
|
+
keptThinkingText = '';
|
|
974
975
|
shownGenerationCount = 0;
|
|
975
976
|
thinkingShownCount = 0;
|
|
976
977
|
thinkingHold = false;
|
|
978
|
+
thinkingStartedAtMs = null;
|
|
979
|
+
codeStreamingStartedAtMs = null;
|
|
980
|
+
frozenThoughtSeconds = null;
|
|
981
|
+
thinkingExpanded = false;
|
|
977
982
|
}
|
|
978
983
|
generationWasRunning = isGenerating;
|
|
979
984
|
if (messages.length === 0 && !isGenerating) {
|
|
980
985
|
keptGenerationText = '';
|
|
986
|
+
keptThinkingText = '';
|
|
981
987
|
shownGenerationCount = 0;
|
|
982
988
|
thinkingShownCount = 0;
|
|
983
989
|
thinkingHold = false;
|
|
984
990
|
}
|
|
985
991
|
});
|
|
986
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
|
+
|
|
987
1000
|
$effect(() => {
|
|
988
1001
|
const incoming = generationStream;
|
|
989
1002
|
if (!incoming) return;
|
|
990
1003
|
const merged = mergeGenerationStream(keptGenerationText, incoming);
|
|
991
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
|
+
});
|
|
992
1030
|
});
|
|
993
1031
|
|
|
994
1032
|
// Reveal from the first character already on screen, then catch up to new tokens.
|
|
@@ -1160,6 +1198,21 @@
|
|
|
1160
1198
|
}
|
|
1161
1199
|
}
|
|
1162
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
|
+
|
|
1163
1216
|
function handleRestoreCheckpoint(messageId: string) {
|
|
1164
1217
|
// Find the index of the message to restore to
|
|
1165
1218
|
const messageIndex = messages.findIndex(msg => msg.id === messageId);
|
|
@@ -1467,15 +1520,26 @@
|
|
|
1467
1520
|
messages and found none. A generation in flight hides it too: the user
|
|
1468
1521
|
bubble lands a tick after send, so the list is briefly empty again. -->
|
|
1469
1522
|
{#if showEmptyState && !isLoading && !isGenerating}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
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
|
+
|
|
1476
1540
|
<!-- Contextual suggestions -->
|
|
1477
|
-
<SuggestionButtons
|
|
1478
|
-
{context}
|
|
1541
|
+
<SuggestionButtons
|
|
1542
|
+
{context}
|
|
1479
1543
|
visible={true}
|
|
1480
1544
|
on:suggestionSelected={handleSuggestionSelected}
|
|
1481
1545
|
/>
|
|
@@ -1484,35 +1548,20 @@
|
|
|
1484
1548
|
|
|
1485
1549
|
<!-- Conversation turns (user prompt + assistant status grouped) -->
|
|
1486
1550
|
{#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
|
-
>
|
|
1551
|
+
<div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5">
|
|
1491
1552
|
{#if turn.user}
|
|
1492
1553
|
{@const userMsg = turn.user}
|
|
1493
1554
|
{@const shownAttachments = visibleUserAttachments(turn, turnIndex)}
|
|
1494
|
-
{@const commitReply = getTurnHeadOrCommitReply(turn)}
|
|
1495
1555
|
<div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
|
|
1496
1556
|
class:opacity-75={userMsg._optimistic}
|
|
1497
1557
|
class:opacity-50={userMsg._failed}
|
|
1498
1558
|
class:has-attachments={shownAttachments.length > 0}
|
|
1499
1559
|
>
|
|
1500
|
-
<
|
|
1501
|
-
{#
|
|
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}
|
|
1560
|
+
<Message role="user" class="ms-auto w-full max-w-full">
|
|
1561
|
+
{#snippet children()}
|
|
1510
1562
|
<div
|
|
1511
|
-
class="message-bubble
|
|
1512
|
-
class:p-3={shownAttachments.length === 0}
|
|
1563
|
+
class="message-bubble-user w-full text-sm leading-relaxed select-text"
|
|
1513
1564
|
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
1565
|
use:bubbleScrollPadding
|
|
1517
1566
|
>
|
|
1518
1567
|
{#if userMsg.messageContent}
|
|
@@ -1552,22 +1601,8 @@
|
|
|
1552
1601
|
</div>
|
|
1553
1602
|
{/if}
|
|
1554
1603
|
</div>
|
|
1555
|
-
|
|
1556
|
-
|
|
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}
|
|
1604
|
+
{/snippet}
|
|
1605
|
+
</Message>
|
|
1571
1606
|
{#if showCommitMetaOnUserTurn(turn)}
|
|
1572
1607
|
{@const commitTitle = getTurnCommitTitle(turn)}
|
|
1573
1608
|
{@const versionLabel = getTurnVersionLabel(turn)}
|
|
@@ -1578,90 +1613,43 @@
|
|
|
1578
1613
|
</span>
|
|
1579
1614
|
</div>
|
|
1580
1615
|
{/if}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
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>
|
|
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
|
+
/>
|
|
1648
1638
|
{/if}
|
|
1649
1639
|
</div>
|
|
1650
1640
|
{/if}
|
|
1651
1641
|
|
|
1652
1642
|
{#each turn.replies as reply (reply.id)}
|
|
1653
1643
|
{#if shouldShowAssistantReply(reply)}
|
|
1654
|
-
<
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1644
|
+
<Message
|
|
1645
|
+
role="assistant"
|
|
1646
|
+
class="wc-chat-turn-reply max-w-full"
|
|
1647
|
+
error={isCodegenFailure(reply)}
|
|
1648
|
+
errorText={visibleMessageContent(reply.messageContent || '')}
|
|
1658
1649
|
>
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
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
|
-
>
|
|
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>
|
|
1665
1653
|
{#if reply.messageContent}
|
|
1666
1654
|
{#if hasCodeBlocks(reply.messageContent)}
|
|
1667
1655
|
<div class="message-content-mixed">
|
|
@@ -1684,6 +1672,9 @@
|
|
|
1684
1672
|
{/if}
|
|
1685
1673
|
{/if}
|
|
1686
1674
|
</div>
|
|
1675
|
+
{/if}
|
|
1676
|
+
{/snippet}
|
|
1677
|
+
</Message>
|
|
1687
1678
|
|
|
1688
1679
|
{#if reply.designControls && renderDesignControls}
|
|
1689
1680
|
<div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
|
|
@@ -1692,49 +1683,56 @@
|
|
|
1692
1683
|
{/if}
|
|
1693
1684
|
|
|
1694
1685
|
{#if reply.suggestions && reply.suggestions.length > 0}
|
|
1695
|
-
<
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
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
|
+
/>
|
|
1708
1699
|
{/if}
|
|
1709
1700
|
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
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">
|
|
1713
1704
|
<button
|
|
1714
|
-
|
|
1705
|
+
type="button"
|
|
1706
|
+
class="wc-upgrade-btn"
|
|
1715
1707
|
onclick={openUpgradePlans}
|
|
1716
1708
|
title={$t('chat.messages.upgradeTitle')}
|
|
1717
1709
|
>
|
|
1718
1710
|
{$t('chat.messages.upgrade')}
|
|
1719
1711
|
</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
1712
|
</div>
|
|
1734
1713
|
{/if}
|
|
1735
|
-
</div>
|
|
1736
1714
|
{/if}
|
|
1737
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}
|
|
1738
1736
|
</div>
|
|
1739
1737
|
{/each}
|
|
1740
1738
|
|
|
@@ -1749,19 +1747,96 @@
|
|
|
1749
1747
|
{/if}
|
|
1750
1748
|
{#if thinkingHold}
|
|
1751
1749
|
<div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
|
|
1752
|
-
|
|
1753
|
-
|
|
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}"
|
|
1754
1772
|
>
|
|
1755
|
-
|
|
1756
|
-
|
|
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}
|
|
1757
1823
|
</div>
|
|
1824
|
+
{#if generationAriaLine}
|
|
1825
|
+
<p class="sr-only" aria-live="polite">{generationAriaLine}</p>
|
|
1826
|
+
{/if}
|
|
1758
1827
|
</div>
|
|
1759
1828
|
{/if}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
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>
|
|
1765
1840
|
</div>
|
|
1766
1841
|
|
|
1767
1842
|
<style>
|
|
@@ -1780,6 +1855,22 @@
|
|
|
1780
1855
|
0% { background-position: 100% 0; }
|
|
1781
1856
|
100% { background-position: -100% 0; }
|
|
1782
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
|
+
}
|
|
1783
1874
|
.generation-stream {
|
|
1784
1875
|
scrollbar-width: thin;
|
|
1785
1876
|
scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
|
|
@@ -1851,33 +1942,11 @@
|
|
|
1851
1942
|
align-items: flex-start; /* Left align for assistant messages */
|
|
1852
1943
|
}
|
|
1853
1944
|
|
|
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
1945
|
.wc-codegen-failure {
|
|
1862
1946
|
border: 1px solid #fecaca;
|
|
1863
1947
|
background-color: #fef2f2 !important;
|
|
1864
1948
|
}
|
|
1865
1949
|
|
|
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
1950
|
/* What the turn shipped, in the commit's own words. Truncated at the turn's
|
|
1882
1951
|
width — the full subject stays in the tooltip — so a prompt-derived title
|
|
1883
1952
|
cannot widen the bubble past its 80% cap. */
|
|
@@ -1888,94 +1957,62 @@
|
|
|
1888
1957
|
white-space: nowrap;
|
|
1889
1958
|
}
|
|
1890
1959
|
|
|
1891
|
-
|
|
1892
|
-
|
|
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;
|
|
1893
1967
|
}
|
|
1894
1968
|
|
|
1895
|
-
.
|
|
1896
|
-
|
|
1969
|
+
.wc-chat-turn-user:hover .wc-restore-slot,
|
|
1970
|
+
.wc-restore-slot:has(:focus-visible) {
|
|
1971
|
+
opacity: 1;
|
|
1897
1972
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
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;
|
|
1973
|
+
|
|
1974
|
+
@media (hover: none) {
|
|
1975
|
+
.wc-restore-slot {
|
|
1976
|
+
opacity: 1;
|
|
1977
|
+
}
|
|
1914
1978
|
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
border-color: #bbb;
|
|
1979
|
+
|
|
1980
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1981
|
+
.wc-restore-slot {
|
|
1982
|
+
transition: none;
|
|
1983
|
+
}
|
|
1921
1984
|
}
|
|
1922
1985
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
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;
|
|
1927
1989
|
}
|
|
1928
1990
|
|
|
1929
|
-
|
|
1930
|
-
.wc-version-rating-btn {
|
|
1991
|
+
.wc-upgrade-btn {
|
|
1931
1992
|
display: inline-flex;
|
|
1932
1993
|
align-items: center;
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
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;
|
|
1941
2001
|
cursor: pointer;
|
|
1942
|
-
|
|
2002
|
+
white-space: nowrap;
|
|
2003
|
+
transition: background-color 0.15s ease, border-color 0.15s ease;
|
|
1943
2004
|
}
|
|
1944
2005
|
|
|
1945
|
-
.wc-
|
|
1946
|
-
background:
|
|
1947
|
-
color: #
|
|
2006
|
+
.wc-upgrade-btn:hover {
|
|
2007
|
+
background: #f3f4f6;
|
|
2008
|
+
border-color: #9ca3af;
|
|
1948
2009
|
}
|
|
1949
2010
|
|
|
1950
|
-
.wc-
|
|
2011
|
+
.wc-upgrade-btn:focus-visible {
|
|
1951
2012
|
outline: 2px solid #93c5fd;
|
|
1952
2013
|
outline-offset: 1px;
|
|
1953
2014
|
}
|
|
1954
2015
|
|
|
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
2016
|
/* Clarification-card suggestion chips — tap to send as the next user message */
|
|
1980
2017
|
.clarification-chip {
|
|
1981
2018
|
display: inline-flex;
|
|
@@ -2009,40 +2046,6 @@
|
|
|
2009
2046
|
cursor: default;
|
|
2010
2047
|
}
|
|
2011
2048
|
|
|
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
2049
|
/* Cap huge messages (legacy full-file dumps) so bubbles stay readable */
|
|
2047
2050
|
.message-bubble {
|
|
2048
2051
|
max-width: 100%;
|