@widgetic/chat 0.1.6 → 0.1.8
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 +26 -47
- package/dist/components/ActionBar.svelte.d.ts +13 -24
- package/dist/components/AttachmentDisplay.svelte +16 -5
- package/dist/components/Chat.svelte +525 -213
- package/dist/components/Chat.svelte.d.ts +10 -1
- package/dist/components/ChatInput.svelte +155 -26
- package/dist/components/ChatInput.svelte.d.ts +11 -0
- package/dist/components/ChatMessages.svelte +274 -113
- package/dist/components/ChatMessages.svelte.d.ts +7 -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/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,12 @@
|
|
|
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;
|
|
33
|
+
/** When false, hide commit hashes next to Head-at-commit (user mode). */
|
|
34
|
+
showCommitMeta?: boolean;
|
|
35
|
+
/** True while codegen / send is in flight — suppresses premature Retry. */
|
|
36
|
+
isGenerating?: boolean;
|
|
31
37
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
32
38
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
33
39
|
onRetryMessage?: (content: string) => void;
|
|
@@ -41,22 +47,88 @@
|
|
|
41
47
|
isCompleted = false,
|
|
42
48
|
enableAutoCodeDetection = false,
|
|
43
49
|
showGenerationSummaries = false,
|
|
50
|
+
widgetHeadCommitSha = null,
|
|
51
|
+
showCommitMeta = true,
|
|
52
|
+
isGenerating = false,
|
|
44
53
|
onSuggestionSelected,
|
|
45
54
|
onRestoreCheckpoint,
|
|
46
55
|
onRetryMessage,
|
|
47
56
|
}: Props = $props();
|
|
48
57
|
|
|
58
|
+
let messagesHasScrollbar = $state(false);
|
|
59
|
+
|
|
60
|
+
function detectMessagesScrollbar(node: HTMLElement) {
|
|
61
|
+
function check() {
|
|
62
|
+
messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
|
|
63
|
+
node.style.setProperty('padding-right', messagesHasScrollbar ? '0px' : '12px', 'important');
|
|
64
|
+
}
|
|
65
|
+
const resizeObserver = new ResizeObserver(check);
|
|
66
|
+
resizeObserver.observe(node);
|
|
67
|
+
const mutationObserver = new MutationObserver(check);
|
|
68
|
+
mutationObserver.observe(node, { childList: true, subtree: true });
|
|
69
|
+
check();
|
|
70
|
+
return {
|
|
71
|
+
destroy() {
|
|
72
|
+
resizeObserver.disconnect();
|
|
73
|
+
mutationObserver.disconnect();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function bubbleScrollPadding(node: HTMLElement) {
|
|
79
|
+
function check() {
|
|
80
|
+
const candidates = [node, ...Array.from(node.querySelectorAll('p, .message-content-mixed'))];
|
|
81
|
+
const hasScroll = candidates.some((el) => el.scrollHeight > el.clientHeight + 1);
|
|
82
|
+
node.classList.toggle('message-bubble-has-scroll', hasScroll);
|
|
83
|
+
if (hasScroll) {
|
|
84
|
+
node.style.setProperty('padding-right', '0px', 'important');
|
|
85
|
+
} else {
|
|
86
|
+
node.style.removeProperty('padding-right');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const resizeObserver = new ResizeObserver(check);
|
|
90
|
+
resizeObserver.observe(node);
|
|
91
|
+
const mutationObserver = new MutationObserver(check);
|
|
92
|
+
mutationObserver.observe(node, { childList: true, subtree: true });
|
|
93
|
+
check();
|
|
94
|
+
return {
|
|
95
|
+
destroy() {
|
|
96
|
+
resizeObserver.disconnect();
|
|
97
|
+
mutationObserver.disconnect();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
49
102
|
// Matches "Updated N file(s)[...]: ..." assistant summaries emitted by the
|
|
50
103
|
// widget codegen backend. Anchored to first line only — regular assistant
|
|
51
104
|
// chat replies that happen to contain this phrase mid-message are kept.
|
|
52
105
|
const GENERATION_SUMMARY_REGEX = /^Updated \d+ files?(?:\s*\([^)]*\))?:/;
|
|
53
106
|
|
|
107
|
+
function isCodegenProgressBubble(content?: string | null): boolean {
|
|
108
|
+
const trimmed = (content || '').trim();
|
|
109
|
+
if (!trimmed) return false;
|
|
110
|
+
return (
|
|
111
|
+
/^Code generation in progress/i.test(trimmed) ||
|
|
112
|
+
/^Generating code/i.test(trimmed) ||
|
|
113
|
+
/^Agent fixing/i.test(trimmed) ||
|
|
114
|
+
/^Building preview/i.test(trimmed) ||
|
|
115
|
+
/^Parsing generated/i.test(trimmed) ||
|
|
116
|
+
/^Planning/i.test(trimmed) ||
|
|
117
|
+
/^Preparing prompt/i.test(trimmed) ||
|
|
118
|
+
/^Reading existing code/i.test(trimmed) ||
|
|
119
|
+
/^Saving to repository/i.test(trimmed) ||
|
|
120
|
+
/^Retrying code format/i.test(trimmed)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
54
124
|
function isGenerationSummary(message: ChatMessage): boolean {
|
|
55
125
|
if (message.messageType !== 'assistant' || !message.messageContent) return false;
|
|
56
126
|
const trimmed = message.messageContent.trim();
|
|
57
127
|
if (/^Code generation failed/i.test(trimmed)) return false;
|
|
58
128
|
if (/^Code generation completed/i.test(trimmed)) return false;
|
|
59
129
|
if (/^Preview recompiled/i.test(trimmed)) return false;
|
|
130
|
+
if (/Generation stopped/i.test(trimmed)) return false;
|
|
131
|
+
if (isCodegenProgressBubble(trimmed)) return true;
|
|
60
132
|
return GENERATION_SUMMARY_REGEX.test(trimmed);
|
|
61
133
|
}
|
|
62
134
|
|
|
@@ -67,7 +139,7 @@
|
|
|
67
139
|
}
|
|
68
140
|
|
|
69
141
|
function extractCommitFromContent(content: string): string | null {
|
|
70
|
-
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|\(commit\s
|
|
142
|
+
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|\(commit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
|
|
71
143
|
return match?.[1]?.toLowerCase() ?? null;
|
|
72
144
|
}
|
|
73
145
|
|
|
@@ -82,11 +154,17 @@
|
|
|
82
154
|
const trimmed = message.messageContent.trim();
|
|
83
155
|
if (isCodegenFailure(message)) return false;
|
|
84
156
|
if (isPreviewRecompiledMessage(message) && /commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
85
|
-
return
|
|
157
|
+
return false;
|
|
86
158
|
}
|
|
87
159
|
if (/^Code generation completed/i.test(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
88
160
|
return true;
|
|
89
161
|
}
|
|
162
|
+
if (/^Compile fix applied/i.test(trimmed) && /Commit:?\s+[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (/^Code saved/i.test(trimmed) && /(?:Commit:?\s+|Code saved\s*\()[a-f0-9]{7,40}/i.test(trimmed)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
90
168
|
return isBackendCodegenSummary(trimmed);
|
|
91
169
|
}
|
|
92
170
|
|
|
@@ -143,6 +221,8 @@
|
|
|
143
221
|
}
|
|
144
222
|
if (!placed && i > 0) {
|
|
145
223
|
result[i - 1].replies.push(msg);
|
|
224
|
+
} else if (!placed) {
|
|
225
|
+
result[i].replies.push(msg);
|
|
146
226
|
}
|
|
147
227
|
}
|
|
148
228
|
}
|
|
@@ -150,8 +230,23 @@
|
|
|
150
230
|
return result;
|
|
151
231
|
}
|
|
152
232
|
|
|
233
|
+
function commitShaMatchesHead(content: string): boolean {
|
|
234
|
+
if (!widgetHeadCommitSha) return false;
|
|
235
|
+
const short = extractCommitShort(content);
|
|
236
|
+
if (!short) return false;
|
|
237
|
+
const head = widgetHeadCommitSha.toLowerCase();
|
|
238
|
+
const sha = short.toLowerCase();
|
|
239
|
+
return head.startsWith(sha) || sha.startsWith(head.slice(0, 7));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function isHeadCommitReply(reply: ChatMessage): boolean {
|
|
243
|
+
if (!messageHasCommit(reply) || isCodegenFailure(reply)) return false;
|
|
244
|
+
if (widgetHeadCommitSha) return commitShaMatchesHead(reply.messageContent || '');
|
|
245
|
+
return !!reply.isWidgetHead;
|
|
246
|
+
}
|
|
247
|
+
|
|
153
248
|
function turnHasWidgetHead(turn: ChatTurn): boolean {
|
|
154
|
-
return turn.replies.some((r) =>
|
|
249
|
+
return turn.replies.some((r) => isHeadCommitReply(r));
|
|
155
250
|
}
|
|
156
251
|
|
|
157
252
|
function isCodegenFailure(message: ChatMessage): boolean {
|
|
@@ -162,12 +257,13 @@
|
|
|
162
257
|
/^⚠️/.test(trimmed) ||
|
|
163
258
|
/Too many generation requests/i.test(trimmed) ||
|
|
164
259
|
/temporarily unavailable/i.test(trimmed) ||
|
|
165
|
-
/Generation Failed/i.test(trimmed)
|
|
260
|
+
/Generation Failed/i.test(trimmed) ||
|
|
261
|
+
/Generation stopped/i.test(trimmed)
|
|
166
262
|
);
|
|
167
263
|
}
|
|
168
264
|
|
|
169
265
|
function canRestoreToMessage(message: ChatMessage): boolean {
|
|
170
|
-
if (message
|
|
266
|
+
if (isHeadCommitReply(message)) return false;
|
|
171
267
|
if (!message.messageContent) return false;
|
|
172
268
|
const trimmed = message.messageContent.trim();
|
|
173
269
|
if (/^Preview recompiled/i.test(trimmed)) return false;
|
|
@@ -177,14 +273,25 @@
|
|
|
177
273
|
}
|
|
178
274
|
|
|
179
275
|
function canUndoHeadUserTurn(turn: ChatTurn): boolean {
|
|
180
|
-
return !!turn.user && !!getTurnCommitReply(turn)
|
|
276
|
+
return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
|
|
181
277
|
}
|
|
182
278
|
|
|
183
279
|
function extractCommitShort(content: string): string | null {
|
|
184
|
-
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s
|
|
280
|
+
const match = content.match(/(?:Commit:?\s+|\n\nCommit\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
|
|
185
281
|
return match?.[1]?.slice(0, 8) ?? null;
|
|
186
282
|
}
|
|
187
283
|
|
|
284
|
+
function getTurnCommitShort(turn: ChatTurn): string | null {
|
|
285
|
+
const commitReply = getTurnCommitReply(turn) || getFallbackHeadReply(turn);
|
|
286
|
+
const fromReply = extractCommitShort(commitReply?.messageContent || '');
|
|
287
|
+
if (fromReply) return fromReply;
|
|
288
|
+
for (const reply of turn.replies) {
|
|
289
|
+
const short = extractCommitShort(reply.messageContent || '');
|
|
290
|
+
if (short) return short;
|
|
291
|
+
}
|
|
292
|
+
return extractCommitShort(turn.user?.messageContent || '');
|
|
293
|
+
}
|
|
294
|
+
|
|
188
295
|
/** Assistant reply that carries the widget commit for this turn (if any). */
|
|
189
296
|
function getTurnCommitReply(turn: ChatTurn): ChatMessage | null {
|
|
190
297
|
for (const reply of turn.replies) {
|
|
@@ -193,12 +300,58 @@
|
|
|
193
300
|
return null;
|
|
194
301
|
}
|
|
195
302
|
|
|
303
|
+
function conversationHasCommitReply(): boolean {
|
|
304
|
+
return chatTurns.some((t) => !!getTurnCommitReply(t));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function isLastUserTurn(turn: ChatTurn): boolean {
|
|
308
|
+
for (let i = chatTurns.length - 1; i >= 0; i--) {
|
|
309
|
+
if (chatTurns[i].user) return chatTurns[i] === turn;
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** When DB history has only user prompts, still show Head on the latest turn. */
|
|
315
|
+
function getFallbackHeadReply(turn: ChatTurn): ChatMessage | null {
|
|
316
|
+
if (!widgetHeadCommitSha || !turn.user) return null;
|
|
317
|
+
if (getTurnCommitReply(turn)) return null;
|
|
318
|
+
if (!isLastUserTurn(turn)) return null;
|
|
319
|
+
if (conversationHasCommitReply()) return null;
|
|
320
|
+
const sha = widgetHeadCommitSha.slice(0, 8);
|
|
321
|
+
return {
|
|
322
|
+
...turn.user,
|
|
323
|
+
id: `fallback-head-${turn.user.id}`,
|
|
324
|
+
messageType: 'assistant',
|
|
325
|
+
messageContent: `Code generation completed! Commit: ${sha}`,
|
|
326
|
+
isWidgetHead: true,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Older user turns with no persisted assistant commit — Restore still uses the user message id. */
|
|
331
|
+
function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
|
|
332
|
+
if (!turn.user) return false;
|
|
333
|
+
if (getTurnCommitReply(turn)) return false;
|
|
334
|
+
if (turnHasWidgetHead(turn) || canUndoHeadUserTurn(turn)) return false;
|
|
335
|
+
if (isLastUserTurn(turn)) return false;
|
|
336
|
+
return conversationHasCommitReply();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function isCodegenStatusBubble(content?: string | null): boolean {
|
|
340
|
+
const trimmed = (content || '').trim();
|
|
341
|
+
return (
|
|
342
|
+
/^Code generation completed/i.test(trimmed) ||
|
|
343
|
+
/^Code saved/i.test(trimmed) ||
|
|
344
|
+
/^Compile fix applied/i.test(trimmed) ||
|
|
345
|
+
/^Preview recompiled/i.test(trimmed)
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
196
349
|
/** Whether this assistant bubble should render (vs commit chrome on user message). */
|
|
197
350
|
function shouldShowAssistantReply(reply: ChatMessage): boolean {
|
|
198
351
|
if (isCodegenFailure(reply)) return true;
|
|
199
352
|
if (showGenerationSummaries) return true;
|
|
200
|
-
if (
|
|
201
|
-
if (
|
|
353
|
+
if (isCodegenProgressBubble(reply.messageContent)) return false;
|
|
354
|
+
if (isCodegenStatusBubble(reply.messageContent)) return false;
|
|
202
355
|
return !isGenerationSummary(reply);
|
|
203
356
|
}
|
|
204
357
|
|
|
@@ -206,11 +359,7 @@
|
|
|
206
359
|
* Previously this was gated to Debug OFF (assistant reply hidden), but we want the buttons
|
|
207
360
|
* available in Debug ON too — the assistant summary and the user-side chrome coexist. */
|
|
208
361
|
function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
|
|
209
|
-
|
|
210
|
-
(r) => r.isWidgetHead && shouldShowAssistantReply(r) && messageHasCommit(r),
|
|
211
|
-
);
|
|
212
|
-
if (visibleHead) return false;
|
|
213
|
-
return !!getTurnCommitReply(turn);
|
|
362
|
+
return !!getTurnCommitReply(turn) || !!getFallbackHeadReply(turn) || canRestoreLegacyUserTurn(turn);
|
|
214
363
|
}
|
|
215
364
|
|
|
216
365
|
type ChatTurn = {
|
|
@@ -245,11 +394,19 @@
|
|
|
245
394
|
}
|
|
246
395
|
|
|
247
396
|
function turnNeedsRetry(turn: ChatTurn): boolean {
|
|
397
|
+
// Never show Retry while a send/codegen is still running.
|
|
398
|
+
if (isLoading || isGenerating) return false;
|
|
248
399
|
if (turnHasCodegenFailure(turn)) return true;
|
|
249
400
|
const userMsg = turn.user;
|
|
250
401
|
if (!userMsg?.messageContent) return false;
|
|
251
402
|
const noAttachments = !userMsg.attachments || userMsg.attachments.length === 0;
|
|
252
|
-
|
|
403
|
+
if (noAttachments && messageImpliesAttachedFile(userMsg.messageContent) && !getTurnCommitReply(turn)) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
// Stopped / incomplete last prompt only — not mid-flight before the first assistant reply.
|
|
407
|
+
// Incomplete without failure/stop is handled by the host via lastGenerationFailed /
|
|
408
|
+
// "Generation stopped by user" assistant text (turnHasCodegenFailure).
|
|
409
|
+
return false;
|
|
253
410
|
}
|
|
254
411
|
|
|
255
412
|
let visibleMessages = $derived(
|
|
@@ -300,7 +457,7 @@
|
|
|
300
457
|
|
|
301
458
|
function handleSuggestionSelected(event: CustomEvent) {
|
|
302
459
|
const suggestion = event.detail.suggestion;
|
|
303
|
-
chatLog('Suggestion selected in ChatMessages:', suggestion);
|
|
460
|
+
// chatLog('Suggestion selected in ChatMessages:', suggestion);
|
|
304
461
|
if (onSuggestionSelected) {
|
|
305
462
|
onSuggestionSelected(suggestion);
|
|
306
463
|
}
|
|
@@ -311,7 +468,7 @@
|
|
|
311
468
|
const messageIndex = messages.findIndex(msg => msg.id === messageId);
|
|
312
469
|
if (messageIndex === -1) return;
|
|
313
470
|
|
|
314
|
-
chatLog('Restore checkpoint requested for message:', messageId, 'at index:', messageIndex);
|
|
471
|
+
// chatLog('Restore checkpoint requested for message:', messageId, 'at index:', messageIndex);
|
|
315
472
|
|
|
316
473
|
// Call the prop callback if provided
|
|
317
474
|
if (onRestoreCheckpoint) {
|
|
@@ -337,7 +494,7 @@
|
|
|
337
494
|
function handleRetryTurn(turn: ChatTurn, turnIndex: number) {
|
|
338
495
|
const retryContent = getRetryPromptForTurn(turn, turnIndex);
|
|
339
496
|
if (!retryContent) return;
|
|
340
|
-
chatLog('Retry requested for failed codegen turn:', retryContent.slice(0, 80));
|
|
497
|
+
// chatLog('Retry requested for failed codegen turn:', retryContent.slice(0, 80));
|
|
341
498
|
onRetryMessage?.(retryContent);
|
|
342
499
|
}
|
|
343
500
|
|
|
@@ -603,9 +760,10 @@
|
|
|
603
760
|
|
|
604
761
|
<div
|
|
605
762
|
bind:this={messagesContainer}
|
|
606
|
-
class="{className ? className : 'prompt-chat-messages-ct'} flex flex-col overflow-y-auto
|
|
763
|
+
class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4"
|
|
607
764
|
class:loading={isLoading}
|
|
608
|
-
style="scroll-behavior: smooth;"
|
|
765
|
+
style="scroll-behavior: smooth; padding: 12px 0 12px 12px; padding-right: 12px;"
|
|
766
|
+
use:detectMessagesScrollbar
|
|
609
767
|
onscroll={handleScroll}
|
|
610
768
|
>
|
|
611
769
|
<!-- Empty state with suggestions -->
|
|
@@ -632,7 +790,8 @@
|
|
|
632
790
|
>
|
|
633
791
|
{#if turn.user}
|
|
634
792
|
{@const userMsg = turn.user}
|
|
635
|
-
|
|
793
|
+
{@const commitReply = getTurnCommitReply(turn) || getFallbackHeadReply(turn)}
|
|
794
|
+
<div class="message-container wc-chat-turn-user ml-auto w-fit max-w-[80%] flex flex-col items-stretch"
|
|
636
795
|
class:opacity-75={userMsg._optimistic}
|
|
637
796
|
class:opacity-50={userMsg._failed}
|
|
638
797
|
class:has-attachments={userMsg.attachments && userMsg.attachments.length > 0}
|
|
@@ -643,9 +802,28 @@
|
|
|
643
802
|
class:p-0={userMsg.attachments && userMsg.attachments.length > 0}
|
|
644
803
|
class:bubble-fit-content={userMsg.attachments && userMsg.attachments.length > 0}
|
|
645
804
|
style="background-color: {isCompleted ? MESSAGE_COLORS.USER_COMPLETED : MESSAGE_COLORS.USER_ACTIVE}; color: {MESSAGE_COLORS.USER_TEXT};"
|
|
805
|
+
use:bubbleScrollPadding
|
|
646
806
|
>
|
|
647
807
|
{#if userMsg.messageContent}
|
|
648
|
-
|
|
808
|
+
{#if hasCodeBlocks(userMsg.messageContent)}
|
|
809
|
+
<div class="message-content-mixed p-3">
|
|
810
|
+
{#each parseMessageContent(userMsg.messageContent) as part}
|
|
811
|
+
{#if part.type === 'text'}
|
|
812
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
813
|
+
{:else if part.type === 'code'}
|
|
814
|
+
<div class="my-3 first:mt-0 last:mb-0">
|
|
815
|
+
<CodeBlock
|
|
816
|
+
code={part.content}
|
|
817
|
+
language={part.language}
|
|
818
|
+
showLineNumbers={part.content.split('\n').length > 3}
|
|
819
|
+
/>
|
|
820
|
+
</div>
|
|
821
|
+
{/if}
|
|
822
|
+
{/each}
|
|
823
|
+
</div>
|
|
824
|
+
{:else}
|
|
825
|
+
<p class="whitespace-pre-wrap p-3">{userMsg.messageContent}</p>
|
|
826
|
+
{/if}
|
|
649
827
|
{/if}
|
|
650
828
|
{#if userMsg.attachments && userMsg.attachments.length > 0}
|
|
651
829
|
<div class="message-attachments-container">
|
|
@@ -678,43 +856,27 @@
|
|
|
678
856
|
</button>
|
|
679
857
|
</div>
|
|
680
858
|
{/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>
|
|
859
|
+
{#if showCommitMetaOnUserTurn(turn)}
|
|
860
|
+
<div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
|
|
861
|
+
<div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
|
|
862
|
+
{#if commitReply && isHeadCommitReply(commitReply)}
|
|
863
|
+
<div class="checkpoint-label wc-head-commit-label">
|
|
864
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
865
|
+
<path d="M20 6L9 17l-5-5"/>
|
|
866
|
+
</svg>
|
|
867
|
+
Head at commit
|
|
868
|
+
</div>
|
|
869
|
+
{/if}
|
|
870
|
+
{#if showCommitMeta && getTurnCommitShort(turn)}
|
|
871
|
+
<span class="wc-user-commit-sha font-mono text-xs text-gray-500">
|
|
872
|
+
Commit {getTurnCommitShort(turn)}
|
|
873
|
+
</span>
|
|
874
|
+
{/if}
|
|
712
875
|
</div>
|
|
713
|
-
|
|
714
|
-
<div class="restore-checkpoint-row flex justify-end">
|
|
876
|
+
{#if !isLoading && ((commitReply && canRestoreToMessage(commitReply)) || canRestoreLegacyUserTurn(turn))}
|
|
715
877
|
<button
|
|
716
|
-
class="restore-checkpoint-btn"
|
|
717
|
-
onclick={() => handleRestoreCheckpoint(commitReply.id)}
|
|
878
|
+
class="restore-checkpoint-btn shrink-0"
|
|
879
|
+
onclick={() => handleRestoreCheckpoint((commitReply && canRestoreToMessage(commitReply) ? commitReply.id : turn.user!.id))}
|
|
718
880
|
title="Restore widget code to this prompt's commit"
|
|
719
881
|
>
|
|
720
882
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
@@ -723,45 +885,48 @@
|
|
|
723
885
|
</svg>
|
|
724
886
|
Restore Checkpoint
|
|
725
887
|
</button>
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
888
|
+
{/if}
|
|
889
|
+
</div>
|
|
890
|
+
{/if}
|
|
891
|
+
</div>
|
|
730
892
|
{/if}
|
|
731
893
|
|
|
732
894
|
{#each turn.replies as reply (reply.id)}
|
|
733
895
|
{#if shouldShowAssistantReply(reply)}
|
|
734
|
-
<div class="message-container wc-chat-turn-reply mr-auto"
|
|
896
|
+
<div class="message-container wc-chat-turn-reply mr-auto w-fit max-w-[80%] flex flex-col items-stretch"
|
|
735
897
|
class:opacity-75={reply._optimistic}
|
|
736
898
|
class:opacity-50={reply._failed}
|
|
737
|
-
class:current-checkpoint={
|
|
899
|
+
class:current-checkpoint={isHeadCommitReply(reply)}
|
|
738
900
|
>
|
|
739
901
|
<div
|
|
740
902
|
class="message-bubble relative rounded-lg shadow-sm text-sm leading-relaxed select-text p-3"
|
|
741
903
|
class:wc-codegen-failure={isCodegenFailure(reply)}
|
|
742
|
-
style="background-color: {
|
|
904
|
+
style="background-color: {isHeadCommitReply(reply) ? '#e0f2fe' : MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT};{isHeadCommitReply(reply) ? ' border: 1.5px solid #7dd3fc;' : ''}"
|
|
905
|
+
use:bubbleScrollPadding
|
|
743
906
|
>
|
|
744
907
|
{#if reply.messageContent}
|
|
745
|
-
|
|
908
|
+
{#if hasCodeBlocks(reply.messageContent)}
|
|
909
|
+
<div class="message-content-mixed">
|
|
910
|
+
{#each parseMessageContent(reply.messageContent) as part}
|
|
911
|
+
{#if part.type === 'text'}
|
|
912
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
913
|
+
{:else if part.type === 'code'}
|
|
914
|
+
<div class="my-3 first:mt-0 last:mb-0">
|
|
915
|
+
<CodeBlock
|
|
916
|
+
code={part.content}
|
|
917
|
+
language={part.language}
|
|
918
|
+
showLineNumbers={part.content.split('\n').length > 3}
|
|
919
|
+
/>
|
|
920
|
+
</div>
|
|
921
|
+
{/if}
|
|
922
|
+
{/each}
|
|
923
|
+
</div>
|
|
924
|
+
{:else}
|
|
925
|
+
<p class="whitespace-pre-wrap">{reply.messageContent}</p>
|
|
926
|
+
{/if}
|
|
746
927
|
{/if}
|
|
747
928
|
</div>
|
|
748
929
|
|
|
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
930
|
{#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && getRetryPromptForTurn(turn, turnIndex) && !isLoading}
|
|
766
931
|
<div class="retry-codegen-row flex justify-start mt-1">
|
|
767
932
|
<button
|
|
@@ -777,36 +942,6 @@
|
|
|
777
942
|
</button>
|
|
778
943
|
</div>
|
|
779
944
|
{/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
945
|
</div>
|
|
811
946
|
{/if}
|
|
812
947
|
{/each}
|
|
@@ -835,7 +970,14 @@
|
|
|
835
970
|
{/if}
|
|
836
971
|
|
|
837
972
|
<!-- Loading indicator -->
|
|
838
|
-
{#if isLoading}
|
|
973
|
+
{#if messages.length === 0 && isLoading}
|
|
974
|
+
<div class="loading-history-ct flex flex-1 items-center justify-center p-8">
|
|
975
|
+
<div class="text-center">
|
|
976
|
+
<div class="w-6 h-6 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin mx-auto mb-2"></div>
|
|
977
|
+
<p class="text-gray-500 text-xs">Loading chat history...</p>
|
|
978
|
+
</div>
|
|
979
|
+
</div>
|
|
980
|
+
{:else if isLoading}
|
|
839
981
|
<div class="loading-indicator-ct flex items-center justify-start p-3">
|
|
840
982
|
<div class="rounded-lg shadow-sm text-sm leading-relaxed p-3"
|
|
841
983
|
style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
|
|
@@ -1035,6 +1177,9 @@
|
|
|
1035
1177
|
.message-bubble {
|
|
1036
1178
|
max-width: 100%;
|
|
1037
1179
|
}
|
|
1180
|
+
.message-bubble-has-scroll {
|
|
1181
|
+
padding-right: 0px !important;
|
|
1182
|
+
}
|
|
1038
1183
|
.message-bubble p,
|
|
1039
1184
|
.message-content-mixed {
|
|
1040
1185
|
max-height: 280px;
|
|
@@ -1046,4 +1191,20 @@
|
|
|
1046
1191
|
max-height: 240px;
|
|
1047
1192
|
overflow: auto;
|
|
1048
1193
|
}
|
|
1194
|
+
|
|
1195
|
+
.prompt-chat-messages-scroll {
|
|
1196
|
+
scrollbar-width: thin;
|
|
1197
|
+
scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
|
|
1198
|
+
}
|
|
1199
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar {
|
|
1200
|
+
width: 6px;
|
|
1201
|
+
background: transparent;
|
|
1202
|
+
}
|
|
1203
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar-track {
|
|
1204
|
+
background: transparent;
|
|
1205
|
+
}
|
|
1206
|
+
.prompt-chat-messages-scroll::-webkit-scrollbar-thumb {
|
|
1207
|
+
background: rgba(0, 0, 0, 0.2);
|
|
1208
|
+
border-radius: 4px;
|
|
1209
|
+
}
|
|
1049
1210
|
</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,12 @@ 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;
|
|
24
|
+
/** When false, hide commit hashes next to Head-at-commit (user mode). */
|
|
25
|
+
showCommitMeta?: boolean;
|
|
26
|
+
/** True while codegen / send is in flight — suppresses premature Retry. */
|
|
27
|
+
isGenerating?: boolean;
|
|
22
28
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
23
29
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
24
30
|
onRetryMessage?: (content: string) => void;
|