@widgetic/chat 0.1.5 → 0.1.7
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/dist/adapters/widgeticAdapter.js +2 -5
- package/dist/components/ActionBar.svelte +6 -6
- package/dist/components/AttachmentDisplay.svelte +16 -5
- package/dist/components/Chat.svelte +375 -209
- package/dist/components/Chat.svelte.d.ts +14 -2
- package/dist/components/ChatInput.svelte +71 -17
- package/dist/components/ChatInput.svelte.d.ts +2 -0
- package/dist/components/ChatMessages.svelte +267 -113
- package/dist/components/ChatMessages.svelte.d.ts +3 -1
- package/dist/components/CodeBlock.svelte +146 -19
- package/dist/components/SuggestionButtons.svelte +1 -1
- package/dist/services/chatService.js +11 -11
- package/dist/stores/chatStore.js +4 -6
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.js +1 -1
- package/dist/utils/logger.js +2 -3
- package/package.json +7 -6
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
// Props
|
|
11
11
|
interface Props {
|
|
12
|
-
|
|
12
|
+
class?: string;
|
|
13
13
|
messages: ChatMessage[];
|
|
14
14
|
isLoading?: boolean;
|
|
15
15
|
context: ChatContext;
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
* false — noisy for end users. Typically bound to `debugMode` by hosts.
|
|
29
29
|
*/
|
|
30
30
|
showGenerationSummaries?: boolean;
|
|
31
|
+
/** Host widget HEAD sha — Head chrome when assistant commit bubbles are missing. */
|
|
32
|
+
widgetHeadCommitSha?: string | null;
|
|
31
33
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
32
34
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
33
35
|
onRetryMessage?: (content: string) => void;
|
|
@@ -41,22 +43,86 @@
|
|
|
41
43
|
isCompleted = false,
|
|
42
44
|
enableAutoCodeDetection = false,
|
|
43
45
|
showGenerationSummaries = false,
|
|
46
|
+
widgetHeadCommitSha = null,
|
|
44
47
|
onSuggestionSelected,
|
|
45
48
|
onRestoreCheckpoint,
|
|
46
49
|
onRetryMessage,
|
|
47
50
|
}: Props = $props();
|
|
48
51
|
|
|
52
|
+
let messagesHasScrollbar = $state(false);
|
|
53
|
+
|
|
54
|
+
function detectMessagesScrollbar(node: HTMLElement) {
|
|
55
|
+
function check() {
|
|
56
|
+
messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
|
|
57
|
+
node.style.setProperty('padding-right', messagesHasScrollbar ? '0px' : '12px', 'important');
|
|
58
|
+
}
|
|
59
|
+
const resizeObserver = new ResizeObserver(check);
|
|
60
|
+
resizeObserver.observe(node);
|
|
61
|
+
const mutationObserver = new MutationObserver(check);
|
|
62
|
+
mutationObserver.observe(node, { childList: true, subtree: true });
|
|
63
|
+
check();
|
|
64
|
+
return {
|
|
65
|
+
destroy() {
|
|
66
|
+
resizeObserver.disconnect();
|
|
67
|
+
mutationObserver.disconnect();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function bubbleScrollPadding(node: HTMLElement) {
|
|
73
|
+
function check() {
|
|
74
|
+
const candidates = [node, ...Array.from(node.querySelectorAll('p, .message-content-mixed'))];
|
|
75
|
+
const hasScroll = candidates.some((el) => el.scrollHeight > el.clientHeight + 1);
|
|
76
|
+
node.classList.toggle('message-bubble-has-scroll', hasScroll);
|
|
77
|
+
if (hasScroll) {
|
|
78
|
+
node.style.setProperty('padding-right', '0px', 'important');
|
|
79
|
+
} else {
|
|
80
|
+
node.style.removeProperty('padding-right');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const resizeObserver = new ResizeObserver(check);
|
|
84
|
+
resizeObserver.observe(node);
|
|
85
|
+
const mutationObserver = new MutationObserver(check);
|
|
86
|
+
mutationObserver.observe(node, { childList: true, subtree: true });
|
|
87
|
+
check();
|
|
88
|
+
return {
|
|
89
|
+
destroy() {
|
|
90
|
+
resizeObserver.disconnect();
|
|
91
|
+
mutationObserver.disconnect();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
49
96
|
// Matches "Updated N file(s)[...]: ..." assistant summaries emitted by the
|
|
50
97
|
// widget codegen backend. Anchored to first line only — regular assistant
|
|
51
98
|
// chat replies that happen to contain this phrase mid-message are kept.
|
|
52
99
|
const GENERATION_SUMMARY_REGEX = /^Updated \d+ files?(?:\s*\([^)]*\))?:/;
|
|
53
100
|
|
|
101
|
+
function isCodegenProgressBubble(content?: string | null): boolean {
|
|
102
|
+
const trimmed = (content || '').trim();
|
|
103
|
+
if (!trimmed) return false;
|
|
104
|
+
return (
|
|
105
|
+
/^Code generation in progress/i.test(trimmed) ||
|
|
106
|
+
/^Generating code/i.test(trimmed) ||
|
|
107
|
+
/^Agent fixing/i.test(trimmed) ||
|
|
108
|
+
/^Building preview/i.test(trimmed) ||
|
|
109
|
+
/^Parsing generated/i.test(trimmed) ||
|
|
110
|
+
/^Planning/i.test(trimmed) ||
|
|
111
|
+
/^Preparing prompt/i.test(trimmed) ||
|
|
112
|
+
/^Reading existing code/i.test(trimmed) ||
|
|
113
|
+
/^Saving to repository/i.test(trimmed) ||
|
|
114
|
+
/^Retrying code format/i.test(trimmed)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
54
118
|
function isGenerationSummary(message: ChatMessage): boolean {
|
|
55
119
|
if (message.messageType !== 'assistant' || !message.messageContent) return false;
|
|
56
120
|
const trimmed = message.messageContent.trim();
|
|
57
121
|
if (/^Code generation failed/i.test(trimmed)) return false;
|
|
58
122
|
if (/^Code generation completed/i.test(trimmed)) return false;
|
|
59
123
|
if (/^Preview recompiled/i.test(trimmed)) return false;
|
|
124
|
+
if (/Generation stopped/i.test(trimmed)) return false;
|
|
125
|
+
if (isCodegenProgressBubble(trimmed)) return true;
|
|
60
126
|
return GENERATION_SUMMARY_REGEX.test(trimmed);
|
|
61
127
|
}
|
|
62
128
|
|
|
@@ -67,7 +133,7 @@
|
|
|
67
133
|
}
|
|
68
134
|
|
|
69
135
|
function extractCommitFromContent(content: string): string | null {
|
|
70
|
-
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|\(commit\s
|
|
136
|
+
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|\(commit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
|
|
71
137
|
return match?.[1]?.toLowerCase() ?? null;
|
|
72
138
|
}
|
|
73
139
|
|
|
@@ -82,11 +148,17 @@
|
|
|
82
148
|
const trimmed = message.messageContent.trim();
|
|
83
149
|
if (isCodegenFailure(message)) return false;
|
|
84
150
|
if (isPreviewRecompiledMessage(message) && /commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
85
|
-
return
|
|
151
|
+
return false;
|
|
86
152
|
}
|
|
87
153
|
if (/^Code generation completed/i.test(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
88
154
|
return true;
|
|
89
155
|
}
|
|
156
|
+
if (/^Compile fix applied/i.test(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (/^Code saved/i.test(trimmed) && /(?:Commit:?\s+|Code saved\s*\()[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
90
162
|
return isBackendCodegenSummary(trimmed);
|
|
91
163
|
}
|
|
92
164
|
|
|
@@ -143,6 +215,8 @@
|
|
|
143
215
|
}
|
|
144
216
|
if (!placed && i > 0) {
|
|
145
217
|
result[i - 1].replies.push(msg);
|
|
218
|
+
} else if (!placed) {
|
|
219
|
+
result[i].replies.push(msg);
|
|
146
220
|
}
|
|
147
221
|
}
|
|
148
222
|
}
|
|
@@ -150,8 +224,23 @@
|
|
|
150
224
|
return result;
|
|
151
225
|
}
|
|
152
226
|
|
|
227
|
+
function commitShaMatchesHead(content: string): boolean {
|
|
228
|
+
if (!widgetHeadCommitSha) return false;
|
|
229
|
+
const short = extractCommitShort(content);
|
|
230
|
+
if (!short) return false;
|
|
231
|
+
const head = widgetHeadCommitSha.toLowerCase();
|
|
232
|
+
const sha = short.toLowerCase();
|
|
233
|
+
return head.startsWith(sha) || sha.startsWith(head.slice(0, 7));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function isHeadCommitReply(reply: ChatMessage): boolean {
|
|
237
|
+
if (!messageHasCommit(reply) || isCodegenFailure(reply)) return false;
|
|
238
|
+
if (widgetHeadCommitSha) return commitShaMatchesHead(reply.messageContent || '');
|
|
239
|
+
return !!reply.isWidgetHead;
|
|
240
|
+
}
|
|
241
|
+
|
|
153
242
|
function turnHasWidgetHead(turn: ChatTurn): boolean {
|
|
154
|
-
return turn.replies.some((r) =>
|
|
243
|
+
return turn.replies.some((r) => isHeadCommitReply(r));
|
|
155
244
|
}
|
|
156
245
|
|
|
157
246
|
function isCodegenFailure(message: ChatMessage): boolean {
|
|
@@ -162,12 +251,13 @@
|
|
|
162
251
|
/^⚠️/.test(trimmed) ||
|
|
163
252
|
/Too many generation requests/i.test(trimmed) ||
|
|
164
253
|
/temporarily unavailable/i.test(trimmed) ||
|
|
165
|
-
/Generation Failed/i.test(trimmed)
|
|
254
|
+
/Generation Failed/i.test(trimmed) ||
|
|
255
|
+
/Generation stopped/i.test(trimmed)
|
|
166
256
|
);
|
|
167
257
|
}
|
|
168
258
|
|
|
169
259
|
function canRestoreToMessage(message: ChatMessage): boolean {
|
|
170
|
-
if (message
|
|
260
|
+
if (isHeadCommitReply(message)) return false;
|
|
171
261
|
if (!message.messageContent) return false;
|
|
172
262
|
const trimmed = message.messageContent.trim();
|
|
173
263
|
if (/^Preview recompiled/i.test(trimmed)) return false;
|
|
@@ -177,14 +267,25 @@
|
|
|
177
267
|
}
|
|
178
268
|
|
|
179
269
|
function canUndoHeadUserTurn(turn: ChatTurn): boolean {
|
|
180
|
-
return !!turn.user && !!getTurnCommitReply(turn)
|
|
270
|
+
return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
|
|
181
271
|
}
|
|
182
272
|
|
|
183
273
|
function extractCommitShort(content: string): string | null {
|
|
184
|
-
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s
|
|
274
|
+
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
|
|
185
275
|
return match?.[1]?.slice(0, 8) ?? null;
|
|
186
276
|
}
|
|
187
277
|
|
|
278
|
+
function getTurnCommitShort(turn: ChatTurn): string | null {
|
|
279
|
+
const commitReply = getTurnCommitReply(turn) || getFallbackHeadReply(turn);
|
|
280
|
+
const fromReply = extractCommitShort(commitReply?.messageContent || '');
|
|
281
|
+
if (fromReply) return fromReply;
|
|
282
|
+
for (const reply of turn.replies) {
|
|
283
|
+
const short = extractCommitShort(reply.messageContent || '');
|
|
284
|
+
if (short) return short;
|
|
285
|
+
}
|
|
286
|
+
return extractCommitShort(turn.user?.messageContent || '');
|
|
287
|
+
}
|
|
288
|
+
|
|
188
289
|
/** Assistant reply that carries the widget commit for this turn (if any). */
|
|
189
290
|
function getTurnCommitReply(turn: ChatTurn): ChatMessage | null {
|
|
190
291
|
for (const reply of turn.replies) {
|
|
@@ -193,12 +294,58 @@
|
|
|
193
294
|
return null;
|
|
194
295
|
}
|
|
195
296
|
|
|
297
|
+
function conversationHasCommitReply(): boolean {
|
|
298
|
+
return chatTurns.some((t) => !!getTurnCommitReply(t));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isLastUserTurn(turn: ChatTurn): boolean {
|
|
302
|
+
for (let i = chatTurns.length - 1; i >= 0; i--) {
|
|
303
|
+
if (chatTurns[i].user) return chatTurns[i] === turn;
|
|
304
|
+
}
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** When DB history has only user prompts, still show Head on the latest turn. */
|
|
309
|
+
function getFallbackHeadReply(turn: ChatTurn): ChatMessage | null {
|
|
310
|
+
if (!widgetHeadCommitSha || !turn.user) return null;
|
|
311
|
+
if (getTurnCommitReply(turn)) return null;
|
|
312
|
+
if (!isLastUserTurn(turn)) return null;
|
|
313
|
+
if (conversationHasCommitReply()) return null;
|
|
314
|
+
const sha = widgetHeadCommitSha.slice(0, 8);
|
|
315
|
+
return {
|
|
316
|
+
...turn.user,
|
|
317
|
+
id: `fallback-head-${turn.user.id}`,
|
|
318
|
+
messageType: 'assistant',
|
|
319
|
+
messageContent: `Code generation completed! Commit: ${sha}`,
|
|
320
|
+
isWidgetHead: true,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Older user turns with no persisted assistant commit — Restore still uses the user message id. */
|
|
325
|
+
function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
|
|
326
|
+
if (!turn.user) return false;
|
|
327
|
+
if (getTurnCommitReply(turn)) return false;
|
|
328
|
+
if (turnHasWidgetHead(turn) || canUndoHeadUserTurn(turn)) return false;
|
|
329
|
+
if (isLastUserTurn(turn)) return false;
|
|
330
|
+
return conversationHasCommitReply();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function isCodegenStatusBubble(content?: string | null): boolean {
|
|
334
|
+
const trimmed = (content || '').trim();
|
|
335
|
+
return (
|
|
336
|
+
/^Code generation completed/i.test(trimmed) ||
|
|
337
|
+
/^Code saved/i.test(trimmed) ||
|
|
338
|
+
/^Compile fix applied/i.test(trimmed) ||
|
|
339
|
+
/^Preview recompiled/i.test(trimmed)
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
196
343
|
/** Whether this assistant bubble should render (vs commit chrome on user message). */
|
|
197
344
|
function shouldShowAssistantReply(reply: ChatMessage): boolean {
|
|
198
345
|
if (isCodegenFailure(reply)) return true;
|
|
199
346
|
if (showGenerationSummaries) return true;
|
|
200
|
-
if (
|
|
201
|
-
if (
|
|
347
|
+
if (isCodegenProgressBubble(reply.messageContent)) return false;
|
|
348
|
+
if (isCodegenStatusBubble(reply.messageContent)) return false;
|
|
202
349
|
return !isGenerationSummary(reply);
|
|
203
350
|
}
|
|
204
351
|
|
|
@@ -206,11 +353,7 @@
|
|
|
206
353
|
* Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
|
|
207
354
|
* available in Debug ON too — the assistant summary and the user-side chrome coexist. */
|
|
208
355
|
function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
|
|
209
|
-
|
|
210
|
-
(r) => r.isWidgetHead && shouldShowAssistantReply(r) && messageHasCommit(r),
|
|
211
|
-
);
|
|
212
|
-
if (visibleHead) return false;
|
|
213
|
-
return !!getTurnCommitReply(turn);
|
|
356
|
+
return !!getTurnCommitReply(turn) || !!getFallbackHeadReply(turn) || canRestoreLegacyUserTurn(turn);
|
|
214
357
|
}
|
|
215
358
|
|
|
216
359
|
type ChatTurn = {
|
|
@@ -249,7 +392,14 @@
|
|
|
249
392
|
const userMsg = turn.user;
|
|
250
393
|
if (!userMsg?.messageContent) return false;
|
|
251
394
|
const noAttachments = !userMsg.attachments || userMsg.attachments.length === 0;
|
|
252
|
-
|
|
395
|
+
if (noAttachments && messageImpliesAttachedFile(userMsg.messageContent) && !getTurnCommitReply(turn)) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
// Stopped / incomplete last prompt: progress bubbles are hidden when Debug is off.
|
|
399
|
+
return isLastUserTurn(turn)
|
|
400
|
+
&& !isLoading
|
|
401
|
+
&& !getTurnCommitReply(turn)
|
|
402
|
+
&& !getFallbackHeadReply(turn);
|
|
253
403
|
}
|
|
254
404
|
|
|
255
405
|
let visibleMessages = $derived(
|
|
@@ -300,7 +450,7 @@
|
|
|
300
450
|
|
|
301
451
|
function handleSuggestionSelected(event: CustomEvent) {
|
|
302
452
|
const suggestion = event.detail.suggestion;
|
|
303
|
-
chatLog('Suggestion selected in ChatMessages:', suggestion);
|
|
453
|
+
// chatLog('Suggestion selected in ChatMessages:', suggestion);
|
|
304
454
|
if (onSuggestionSelected) {
|
|
305
455
|
onSuggestionSelected(suggestion);
|
|
306
456
|
}
|
|
@@ -311,7 +461,7 @@
|
|
|
311
461
|
const messageIndex = messages.findIndex(msg => msg.id === messageId);
|
|
312
462
|
if (messageIndex === -1) return;
|
|
313
463
|
|
|
314
|
-
chatLog('Restore checkpoint requested for message:', messageId, 'at index:', messageIndex);
|
|
464
|
+
// chatLog('Restore checkpoint requested for message:', messageId, 'at index:', messageIndex);
|
|
315
465
|
|
|
316
466
|
// Call the prop callback if provided
|
|
317
467
|
if (onRestoreCheckpoint) {
|
|
@@ -337,7 +487,7 @@
|
|
|
337
487
|
function handleRetryTurn(turn: ChatTurn, turnIndex: number) {
|
|
338
488
|
const retryContent = getRetryPromptForTurn(turn, turnIndex);
|
|
339
489
|
if (!retryContent) return;
|
|
340
|
-
chatLog('Retry requested for failed codegen turn:', retryContent.slice(0, 80));
|
|
490
|
+
// chatLog('Retry requested for failed codegen turn:', retryContent.slice(0, 80));
|
|
341
491
|
onRetryMessage?.(retryContent);
|
|
342
492
|
}
|
|
343
493
|
|
|
@@ -603,9 +753,10 @@
|
|
|
603
753
|
|
|
604
754
|
<div
|
|
605
755
|
bind:this={messagesContainer}
|
|
606
|
-
class="{className ? className : 'prompt-chat-messages-ct'} flex flex-col overflow-y-auto
|
|
756
|
+
class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4"
|
|
607
757
|
class:loading={isLoading}
|
|
608
|
-
style="scroll-behavior: smooth;"
|
|
758
|
+
style="scroll-behavior: smooth; padding: 12px 0 12px 12px; padding-right: 12px;"
|
|
759
|
+
use:detectMessagesScrollbar
|
|
609
760
|
onscroll={handleScroll}
|
|
610
761
|
>
|
|
611
762
|
<!-- Empty state with suggestions -->
|
|
@@ -632,7 +783,8 @@
|
|
|
632
783
|
>
|
|
633
784
|
{#if turn.user}
|
|
634
785
|
{@const userMsg = turn.user}
|
|
635
|
-
|
|
786
|
+
{@const commitReply = getTurnCommitReply(turn) || getFallbackHeadReply(turn)}
|
|
787
|
+
<div class="message-container wc-chat-turn-user ml-auto w-fit max-w-[80%] flex flex-col items-stretch"
|
|
636
788
|
class:opacity-75={userMsg._optimistic}
|
|
637
789
|
class:opacity-50={userMsg._failed}
|
|
638
790
|
class:has-attachments={userMsg.attachments && userMsg.attachments.length > 0}
|
|
@@ -643,9 +795,28 @@
|
|
|
643
795
|
class:p-0={userMsg.attachments && userMsg.attachments.length > 0}
|
|
644
796
|
class:bubble-fit-content={userMsg.attachments && userMsg.attachments.length > 0}
|
|
645
797
|
style="background-color: {isCompleted ? MESSAGE_COLORS.USER_COMPLETED : MESSAGE_COLORS.USER_ACTIVE}; color: {MESSAGE_COLORS.USER_TEXT};"
|
|
798
|
+
use:bubbleScrollPadding
|
|
646
799
|
>
|
|
647
800
|
{#if userMsg.messageContent}
|
|
648
|
-
|
|
801
|
+
{#if hasCodeBlocks(userMsg.messageContent)}
|
|
802
|
+
<div class="message-content-mixed p-3">
|
|
803
|
+
{#each parseMessageContent(userMsg.messageContent) as part}
|
|
804
|
+
{#if part.type === 'text'}
|
|
805
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
806
|
+
{:else if part.type === 'code'}
|
|
807
|
+
<div class="my-3 first:mt-0 last:mb-0">
|
|
808
|
+
<CodeBlock
|
|
809
|
+
code={part.content}
|
|
810
|
+
language={part.language}
|
|
811
|
+
showLineNumbers={part.content.split('\n').length > 3}
|
|
812
|
+
/>
|
|
813
|
+
</div>
|
|
814
|
+
{/if}
|
|
815
|
+
{/each}
|
|
816
|
+
</div>
|
|
817
|
+
{:else}
|
|
818
|
+
<p class="whitespace-pre-wrap p-3">{userMsg.messageContent}</p>
|
|
819
|
+
{/if}
|
|
649
820
|
{/if}
|
|
650
821
|
{#if userMsg.attachments && userMsg.attachments.length > 0}
|
|
651
822
|
<div class="message-attachments-container">
|
|
@@ -678,43 +849,27 @@
|
|
|
678
849
|
</button>
|
|
679
850
|
</div>
|
|
680
851
|
{/if}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
</span>
|
|
698
|
-
{/if}
|
|
699
|
-
{#if turn.user && canUndoHeadUserTurn(turn) && !isLoading}
|
|
700
|
-
<div class="restore-checkpoint-row flex justify-end">
|
|
701
|
-
<button
|
|
702
|
-
class="restore-checkpoint-btn wc-undo-head-btn"
|
|
703
|
-
onclick={() => handleRestoreCheckpoint(turn.user!.id)}
|
|
704
|
-
title="Undo this prompt and revert code to the previous commit"
|
|
705
|
-
>
|
|
706
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
707
|
-
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
|
|
708
|
-
<path d="M3 3v5h5"/>
|
|
709
|
-
</svg>
|
|
710
|
-
Undo last change
|
|
711
|
-
</button>
|
|
852
|
+
{#if showCommitMetaOnUserTurn(turn)}
|
|
853
|
+
<div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
|
|
854
|
+
<div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
|
|
855
|
+
{#if commitReply && isHeadCommitReply(commitReply)}
|
|
856
|
+
<div class="checkpoint-label wc-head-commit-label">
|
|
857
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
858
|
+
<path d="M20 6L9 17l-5-5"/>
|
|
859
|
+
</svg>
|
|
860
|
+
Head at commit
|
|
861
|
+
</div>
|
|
862
|
+
{/if}
|
|
863
|
+
{#if getTurnCommitShort(turn)}
|
|
864
|
+
<span class="wc-user-commit-sha font-mono text-xs text-gray-500">
|
|
865
|
+
Commit {getTurnCommitShort(turn)}
|
|
866
|
+
</span>
|
|
867
|
+
{/if}
|
|
712
868
|
</div>
|
|
713
|
-
|
|
714
|
-
<div class="restore-checkpoint-row flex justify-end">
|
|
869
|
+
{#if !isLoading && ((commitReply && canRestoreToMessage(commitReply)) || canRestoreLegacyUserTurn(turn))}
|
|
715
870
|
<button
|
|
716
|
-
class="restore-checkpoint-btn"
|
|
717
|
-
onclick={() => handleRestoreCheckpoint(commitReply.id)}
|
|
871
|
+
class="restore-checkpoint-btn shrink-0"
|
|
872
|
+
onclick={() => handleRestoreCheckpoint((commitReply && canRestoreToMessage(commitReply) ? commitReply.id : turn.user!.id))}
|
|
718
873
|
title="Restore widget code to this prompt's commit"
|
|
719
874
|
>
|
|
720
875
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
@@ -723,45 +878,48 @@
|
|
|
723
878
|
</svg>
|
|
724
879
|
Restore Checkpoint
|
|
725
880
|
</button>
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
881
|
+
{/if}
|
|
882
|
+
</div>
|
|
883
|
+
{/if}
|
|
884
|
+
</div>
|
|
730
885
|
{/if}
|
|
731
886
|
|
|
732
887
|
{#each turn.replies as reply (reply.id)}
|
|
733
888
|
{#if shouldShowAssistantReply(reply)}
|
|
734
|
-
<div class="message-container wc-chat-turn-reply mr-auto"
|
|
889
|
+
<div class="message-container wc-chat-turn-reply mr-auto w-fit max-w-[80%] flex flex-col items-stretch"
|
|
735
890
|
class:opacity-75={reply._optimistic}
|
|
736
891
|
class:opacity-50={reply._failed}
|
|
737
|
-
class:current-checkpoint={
|
|
892
|
+
class:current-checkpoint={isHeadCommitReply(reply)}
|
|
738
893
|
>
|
|
739
894
|
<div
|
|
740
895
|
class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text p-3"
|
|
741
896
|
class:wc-codegen-failure={isCodegenFailure(reply)}
|
|
742
|
-
style="background-color: {
|
|
897
|
+
style="background-color: {isHeadCommitReply(reply) ? '#e0f2fe' : MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT};{isHeadCommitReply(reply) ? ' border: 1.5px solid #7dd3fc;' : ''}"
|
|
898
|
+
use:bubbleScrollPadding
|
|
743
899
|
>
|
|
744
900
|
{#if reply.messageContent}
|
|
745
|
-
|
|
901
|
+
{#if hasCodeBlocks(reply.messageContent)}
|
|
902
|
+
<div class="message-content-mixed">
|
|
903
|
+
{#each parseMessageContent(reply.messageContent) as part}
|
|
904
|
+
{#if part.type === 'text'}
|
|
905
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
906
|
+
{:else if part.type === 'code'}
|
|
907
|
+
<div class="my-3 first:mt-0 last:mb-0">
|
|
908
|
+
<CodeBlock
|
|
909
|
+
code={part.content}
|
|
910
|
+
language={part.language}
|
|
911
|
+
showLineNumbers={part.content.split('\n').length > 3}
|
|
912
|
+
/>
|
|
913
|
+
</div>
|
|
914
|
+
{/if}
|
|
915
|
+
{/each}
|
|
916
|
+
</div>
|
|
917
|
+
{:else}
|
|
918
|
+
<p class="whitespace-pre-wrap">{reply.messageContent}</p>
|
|
919
|
+
{/if}
|
|
746
920
|
{/if}
|
|
747
921
|
</div>
|
|
748
922
|
|
|
749
|
-
{#if reply.isWidgetHead && messageHasCommit(reply)}
|
|
750
|
-
<div class="wc-head-commit-meta-ct flex flex-col items-start gap-0.5 mt-1">
|
|
751
|
-
<div class="checkpoint-label wc-head-commit-label">
|
|
752
|
-
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
753
|
-
<path d="M20 6L9 17l-5-5"/>
|
|
754
|
-
</svg>
|
|
755
|
-
Head at commit
|
|
756
|
-
</div>
|
|
757
|
-
{#if extractCommitShort(reply.messageContent || '')}
|
|
758
|
-
<span class="wc-assistant-commit-sha font-mono text-xs text-gray-500">
|
|
759
|
-
Commit {extractCommitShort(reply.messageContent || '')}
|
|
760
|
-
</span>
|
|
761
|
-
{/if}
|
|
762
|
-
</div>
|
|
763
|
-
{/if}
|
|
764
|
-
|
|
765
923
|
{#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && getRetryPromptForTurn(turn, turnIndex) && !isLoading}
|
|
766
924
|
<div class="retry-codegen-row flex justify-start mt-1">
|
|
767
925
|
<button
|
|
@@ -777,36 +935,6 @@
|
|
|
777
935
|
</button>
|
|
778
936
|
</div>
|
|
779
937
|
{/if}
|
|
780
|
-
|
|
781
|
-
{#if reply.isWidgetHead && messageHasCommit(reply) && !isLoading}
|
|
782
|
-
<div class="restore-checkpoint-row flex justify-start mt-1">
|
|
783
|
-
<button
|
|
784
|
-
class="restore-checkpoint-btn wc-undo-head-btn"
|
|
785
|
-
onclick={() => handleRestoreCheckpoint(turn.user?.id ?? reply.id)}
|
|
786
|
-
title="Undo this prompt and revert code to the previous commit"
|
|
787
|
-
>
|
|
788
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
789
|
-
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
|
|
790
|
-
<path d="M3 3v5h5"/>
|
|
791
|
-
</svg>
|
|
792
|
-
Undo last change
|
|
793
|
-
</button>
|
|
794
|
-
</div>
|
|
795
|
-
{:else if canRestoreToMessage(reply) && !isLoading}
|
|
796
|
-
<div class="restore-checkpoint-row flex justify-start mt-1">
|
|
797
|
-
<button
|
|
798
|
-
class="restore-checkpoint-btn"
|
|
799
|
-
onclick={() => handleRestoreCheckpoint(reply.id)}
|
|
800
|
-
title="Restore widget code to this prompt's commit"
|
|
801
|
-
>
|
|
802
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
803
|
-
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
|
|
804
|
-
<path d="M3 3v5h5"/>
|
|
805
|
-
</svg>
|
|
806
|
-
Restore Checkpoint
|
|
807
|
-
</button>
|
|
808
|
-
</div>
|
|
809
|
-
{/if}
|
|
810
938
|
</div>
|
|
811
939
|
{/if}
|
|
812
940
|
{/each}
|
|
@@ -835,7 +963,14 @@
|
|
|
835
963
|
{/if}
|
|
836
964
|
|
|
837
965
|
<!-- Loading indicator -->
|
|
838
|
-
{#if isLoading}
|
|
966
|
+
{#if messages.length === 0 && isLoading}
|
|
967
|
+
<div class="loading-history-ct flex flex-1 items-center justify-center p-8">
|
|
968
|
+
<div class="text-center">
|
|
969
|
+
<div class="w-6 h-6 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin mx-auto mb-2"></div>
|
|
970
|
+
<p class="text-gray-500 text-xs">Loading chat history...</p>
|
|
971
|
+
</div>
|
|
972
|
+
</div>
|
|
973
|
+
{:else if isLoading}
|
|
839
974
|
<div class="loading-indicator-ct flex items-center justify-start p-3">
|
|
840
975
|
<div class="rounded-lg shadow-sm text-sm leading-relaxed p-3"
|
|
841
976
|
style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
|
|
@@ -1035,6 +1170,9 @@
|
|
|
1035
1170
|
.message-bubble {
|
|
1036
1171
|
max-width: 100%;
|
|
1037
1172
|
}
|
|
1173
|
+
.message-bubble-has-scroll {
|
|
1174
|
+
padding-right: 0px !important;
|
|
1175
|
+
}
|
|
1038
1176
|
.message-bubble p,
|
|
1039
1177
|
.message-content-mixed {
|
|
1040
1178
|
max-height: 280px;
|
|
@@ -1046,4 +1184,20 @@
|
|
|
1046
1184
|
max-height: 240px;
|
|
1047
1185
|
overflow: auto;
|
|
1048
1186
|
}
|
|
1187
|
+
|
|
1188
|
+
.prompt-chat-messages-scroll {
|
|
1189
|
+
scrollbar-width: thin;
|
|
1190
|
+
scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
|
|
1191
|
+
}
|
|
1192
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar {
|
|
1193
|
+
width: 6px;
|
|
1194
|
+
background: transparent;
|
|
1195
|
+
}
|
|
1196
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar-track {
|
|
1197
|
+
background: transparent;
|
|
1198
|
+
}
|
|
1199
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar-thumb {
|
|
1200
|
+
background: rgba(0, 0, 0, 0.2);
|
|
1201
|
+
border-radius: 4px;
|
|
1202
|
+
}
|
|
1049
1203
|
</style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
2
2
|
interface Props {
|
|
3
|
-
|
|
3
|
+
class?: string;
|
|
4
4
|
messages: ChatMessage[];
|
|
5
5
|
isLoading?: boolean;
|
|
6
6
|
context: ChatContext;
|
|
@@ -19,6 +19,8 @@ interface Props {
|
|
|
19
19
|
* false — noisy for end users. Typically bound to `debugMode` by hosts.
|
|
20
20
|
*/
|
|
21
21
|
showGenerationSummaries?: boolean;
|
|
22
|
+
/** Host widget HEAD sha — Head chrome when assistant commit bubbles are missing. */
|
|
23
|
+
widgetHeadCommitSha?: string | null;
|
|
22
24
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
23
25
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
24
26
|
onRetryMessage?: (content: string) => void;
|