@widgetic/chat 0.1.17 → 0.1.19
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 +104 -0
- package/dist/components/ActionBar.svelte +19 -15
- package/dist/components/AttachmentDisplay.svelte +54 -26
- package/dist/components/Chat.svelte +106 -58
- package/dist/components/Chat.svelte.d.ts +29 -0
- package/dist/components/ChatHeader.svelte +21 -21
- package/dist/components/ChatInput.svelte +39 -18
- package/dist/components/ChatInput.svelte.d.ts +1 -0
- package/dist/components/ChatMessages.svelte +93 -36
- package/dist/components/ChatMessages.svelte.d.ts +8 -0
- package/dist/components/CodeBlock.svelte +14 -9
- package/dist/components/ContextPreview.svelte +8 -3
- package/dist/components/StatusIndicator.svelte +10 -5
- package/dist/components/SuggestionButtons.svelte +19 -64
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/labels.d.ts +31 -0
- package/dist/i18n/labels.js +69 -0
- package/dist/i18n/language.d.ts +22 -0
- package/dist/i18n/language.js +31 -0
- package/dist/i18n/messages.d.ts +173 -0
- package/dist/i18n/messages.js +182 -0
- package/dist/i18n/suggestions.d.ts +5 -0
- package/dist/i18n/suggestions.js +66 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +3 -1
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
import { onMount, onDestroy } from 'svelte';
|
|
3
3
|
import { chatLog } from '../utils/logger.js';
|
|
4
4
|
import type { AttachmentInput } from '../types/attachment.js';
|
|
5
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
6
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
7
|
+
|
|
8
|
+
// The words of the input, in the language of the chat above
|
|
9
|
+
const { t } = useChatLanguage();
|
|
10
|
+
|
|
11
|
+
// The way the screen is read: what a person types reads by its own first letter on a right to left screen.
|
|
12
|
+
const textDirection = useTextDirection();
|
|
5
13
|
|
|
6
14
|
interface Props {
|
|
7
15
|
value: string;
|
|
@@ -21,6 +29,7 @@
|
|
|
21
29
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
22
30
|
/** OS file drag-and-drop onto the input area (not attachment reorder). */
|
|
23
31
|
onFilesDropped?: (files: File[]) => void;
|
|
32
|
+
/** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
|
|
24
33
|
placeholder?: string;
|
|
25
34
|
class?: string;
|
|
26
35
|
style?: string;
|
|
@@ -39,13 +48,18 @@
|
|
|
39
48
|
onInputChange,
|
|
40
49
|
onAttachmentsChange,
|
|
41
50
|
onFilesDropped,
|
|
42
|
-
placeholder
|
|
51
|
+
placeholder,
|
|
43
52
|
class: className = '',
|
|
44
53
|
style = '',
|
|
45
54
|
}: Props = $props();
|
|
46
55
|
|
|
47
56
|
let isFileDragOver = $state(false);
|
|
48
57
|
|
|
58
|
+
// What the send button is called (and says in its tooltip): it turns into Stop while the assistant answers
|
|
59
|
+
let sendLabel = $derived(
|
|
60
|
+
isGenerating ? $t('chat.input.stop') : isSending ? $t('chat.input.sending') : $t('chat.input.send')
|
|
61
|
+
);
|
|
62
|
+
|
|
49
63
|
function isOsFileDrag(event: DragEvent): boolean {
|
|
50
64
|
return !!event.dataTransfer?.types?.includes('Files');
|
|
51
65
|
}
|
|
@@ -99,10 +113,10 @@
|
|
|
99
113
|
|
|
100
114
|
onSend(value.trim(), attachments.length > 0 ? attachments : undefined);
|
|
101
115
|
|
|
102
|
-
// Keep focus on textarea after sending
|
|
116
|
+
// Keep focus on textarea after sending (without scrolling the page the chat is on)
|
|
103
117
|
setTimeout(() => {
|
|
104
118
|
if (textArea) {
|
|
105
|
-
textArea.focus();
|
|
119
|
+
textArea.focus({ preventScroll: true });
|
|
106
120
|
}
|
|
107
121
|
}, 100);
|
|
108
122
|
}
|
|
@@ -223,10 +237,12 @@
|
|
|
223
237
|
textArea.style.height = Math.min(textArea.scrollHeight, maxH) + 'px';
|
|
224
238
|
|
|
225
239
|
// If value was cleared (after sending), refocus
|
|
226
|
-
|
|
240
|
+
// (Asked of the tree the text box is in: in a shadow root, on a partner's page, `document.activeElement` is the host element.)
|
|
241
|
+
if (value === '' && (textArea.getRootNode() as Document | ShadowRoot).activeElement !== textArea) {
|
|
227
242
|
setTimeout(() => {
|
|
228
243
|
if (textArea) {
|
|
229
|
-
|
|
244
|
+
// preventScroll: taking the focus back must not scroll the page the chat is on
|
|
245
|
+
textArea.focus({ preventScroll: true });
|
|
230
246
|
}
|
|
231
247
|
}, 50);
|
|
232
248
|
}
|
|
@@ -262,13 +278,13 @@
|
|
|
262
278
|
ondrop={(e) => handleAttachmentDrop(index, e)}
|
|
263
279
|
ondragend={handleAttachmentDragEnd}
|
|
264
280
|
>
|
|
265
|
-
<span class="attachment-index-badge absolute top-0.5
|
|
281
|
+
<span class="attachment-index-badge absolute top-0.5 start-0.5 z-10 w-4 h-4 flex items-center justify-center rounded-full bg-blue-600 text-white text-[9px] font-bold shadow">{index + 1}</span>
|
|
266
282
|
{#if isImageAttachment(attachment)}
|
|
267
283
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
268
284
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
269
285
|
<img
|
|
270
286
|
src={getAttachmentPreviewUrl(attachment)}
|
|
271
|
-
alt={attachment.file?.name || 'attachment'}
|
|
287
|
+
alt={attachment.file?.name || $t('chat.attachment.namelessAlt')}
|
|
272
288
|
class="image-preview-ct w-16 h-16 object-cover cursor-pointer"
|
|
273
289
|
onclick={() => openLightbox(attachment)}
|
|
274
290
|
/>
|
|
@@ -276,21 +292,21 @@
|
|
|
276
292
|
<!-- File Preview -->
|
|
277
293
|
<div class="file-preview-ct flex items-center gap-2 p-3 w-32">
|
|
278
294
|
<span class="text-lg">📄</span>
|
|
279
|
-
<span class="text-xs text-gray-600 dark:text-gray-300 truncate flex-1">{attachment.file?.name || 'attachment'}</span>
|
|
295
|
+
<span class="text-xs text-gray-600 dark:text-gray-300 truncate flex-1">{attachment.file?.name || $t('chat.attachment.namelessAlt')}</span>
|
|
280
296
|
</div>
|
|
281
297
|
{/if}
|
|
282
298
|
|
|
283
299
|
<!-- Remove Button -->
|
|
284
300
|
<button
|
|
285
|
-
class="remove-attachment-btn absolute top-1
|
|
301
|
+
class="remove-attachment-btn absolute top-1 end-1 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center text-xs hover:bg-red-600 cursor-pointer"
|
|
286
302
|
onclick={() => removeAttachment(index)}
|
|
287
|
-
aria-label=
|
|
303
|
+
aria-label={$t('chat.attachment.remove')}
|
|
288
304
|
>
|
|
289
305
|
✕
|
|
290
306
|
</button>
|
|
291
307
|
|
|
292
308
|
{#if attachment.uploadProgress && attachment.uploadProgress > 0}
|
|
293
|
-
<div class="absolute bottom-0
|
|
309
|
+
<div class="absolute bottom-0 start-0 end-0 h-1 bg-gray-200">
|
|
294
310
|
<div class="h-full bg-blue-500 transition-all duration-300" style="width: {attachment.uploadProgress}%"></div>
|
|
295
311
|
</div>
|
|
296
312
|
{/if}
|
|
@@ -307,7 +323,8 @@
|
|
|
307
323
|
value={value}
|
|
308
324
|
oninput={(e) => onInputChange((e.target as HTMLTextAreaElement).value)}
|
|
309
325
|
onkeydown={handleKeyDown}
|
|
310
|
-
{placeholder}
|
|
326
|
+
placeholder={placeholder ?? $t('chat.input.placeholder')}
|
|
327
|
+
dir={value ? dirForUserText($textDirection) : undefined}
|
|
311
328
|
class="flex-1 bg-transparent border-none outline-none resize-y text-sm placeholder-gray-500 dark:text-gray-100 dark:placeholder-gray-400"
|
|
312
329
|
style="min-height: 30px; max-height: 120px; overflow-y: auto;"
|
|
313
330
|
rows="1"
|
|
@@ -332,8 +349,8 @@
|
|
|
332
349
|
handleSubmit();
|
|
333
350
|
}}
|
|
334
351
|
disabled={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
|
|
335
|
-
aria-label={
|
|
336
|
-
title={
|
|
352
|
+
aria-label={sendLabel}
|
|
353
|
+
title={sendLabel}
|
|
337
354
|
>
|
|
338
355
|
{#if isGenerating}
|
|
339
356
|
<span class="block w-3 h-3 rounded-[2px] bg-white"></span>
|
|
@@ -343,7 +360,7 @@
|
|
|
343
360
|
<path d="M22 12a10 10 0 0 1-10 10" fill="none" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
344
361
|
</svg>
|
|
345
362
|
{:else}
|
|
346
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="white" class="w-4 h-4">
|
|
363
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="white" class="w-4 h-4 rtl:-scale-x-100">
|
|
347
364
|
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
348
365
|
</svg>
|
|
349
366
|
{/if}
|
|
@@ -358,11 +375,15 @@
|
|
|
358
375
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
359
376
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
360
377
|
<div class="input-lightbox-overlay" onclick={() => lightboxSrc = null}>
|
|
361
|
-
<button
|
|
378
|
+
<button
|
|
379
|
+
class="input-lightbox-close"
|
|
380
|
+
onclick={() => lightboxSrc = null}
|
|
381
|
+
title={$t('chat.attachment.close')}
|
|
382
|
+
aria-label={$t('chat.attachment.close')}>✕</button>
|
|
362
383
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
363
384
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
364
385
|
<div class="input-lightbox-content" onclick={(e) => e.stopPropagation()}>
|
|
365
|
-
<img src={lightboxSrc} alt=
|
|
386
|
+
<img src={lightboxSrc} alt={$t('chat.attachment.previewAlt')} class="input-lightbox-image" />
|
|
366
387
|
</div>
|
|
367
388
|
</div>
|
|
368
389
|
{/if}
|
|
@@ -387,7 +408,7 @@
|
|
|
387
408
|
.input-lightbox-close {
|
|
388
409
|
position: absolute;
|
|
389
410
|
top: 16px;
|
|
390
|
-
|
|
411
|
+
inset-inline-end: 16px;
|
|
391
412
|
width: 36px;
|
|
392
413
|
height: 36px;
|
|
393
414
|
border-radius: 50%;
|
|
@@ -17,6 +17,7 @@ interface Props {
|
|
|
17
17
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
18
18
|
/** OS file drag-and-drop onto the input area (not attachment reorder). */
|
|
19
19
|
onFilesDropped?: (files: File[]) => void;
|
|
20
|
+
/** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
|
|
20
21
|
placeholder?: string;
|
|
21
22
|
class?: string;
|
|
22
23
|
style?: string;
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
import LoadingIndicator from './LoadingIndicator.svelte';
|
|
9
9
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
10
10
|
import type { Snippet } from 'svelte';
|
|
11
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
12
|
+
import { contextTypeLabel, versionLabelText } from '../i18n/labels.js';
|
|
13
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
14
|
+
|
|
15
|
+
// The words of the messages area, in the language of the chat above
|
|
16
|
+
const { t } = useChatLanguage();
|
|
17
|
+
|
|
18
|
+
// The way the screen is read: what a person wrote reads by its own first letter on a right to left screen.
|
|
19
|
+
const textDirection = useTextDirection();
|
|
11
20
|
|
|
12
21
|
// Props
|
|
13
22
|
interface Props {
|
|
@@ -57,12 +66,20 @@
|
|
|
57
66
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
58
67
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
59
68
|
onRetryMessage?: (content: string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
|
|
71
|
+
* billing page of the Widgetic site. A host that is a guest on somebody else's page (the creator in a partner's
|
|
72
|
+
* page) gives its own function: the page it is on is not the chat's to navigate away from.
|
|
73
|
+
*/
|
|
74
|
+
onUpgradePlans?: () => void;
|
|
60
75
|
/** Tapping a clarification-card suggestion chip sends it as the next user message,
|
|
61
76
|
* carrying the chip's structured intent. Chips are disabled while the host
|
|
62
77
|
* runs widget codegen (`isGenerating`). */
|
|
63
78
|
onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
|
|
64
79
|
/** Host-rendered inline design-control card for messages carrying `designControls`. */
|
|
65
80
|
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
81
|
+
/** Host translation for lines saved in English (see Chat `storedLineLabel`). */
|
|
82
|
+
storedLineLabel?: (content: string) => string;
|
|
66
83
|
}
|
|
67
84
|
|
|
68
85
|
let {
|
|
@@ -84,16 +101,29 @@
|
|
|
84
101
|
onSuggestionSelected,
|
|
85
102
|
onRestoreCheckpoint,
|
|
86
103
|
onRetryMessage,
|
|
104
|
+
onUpgradePlans,
|
|
87
105
|
onClarificationSuggestionSelected,
|
|
88
106
|
renderDesignControls,
|
|
107
|
+
storedLineLabel,
|
|
89
108
|
}: Props = $props();
|
|
90
109
|
|
|
110
|
+
/** What a visitor reads for stored assistant/system lines; matching still uses the English stored text. */
|
|
111
|
+
function visibleMessageContent(content: string): string {
|
|
112
|
+
if (!storedLineLabel) return content;
|
|
113
|
+
try {
|
|
114
|
+
return storedLineLabel(content);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.warn('[Chat] storedLineLabel failed:', error);
|
|
117
|
+
return content;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
91
121
|
let messagesHasScrollbar = $state(false);
|
|
92
122
|
|
|
93
123
|
function detectMessagesScrollbar(node: HTMLElement) {
|
|
94
124
|
function check() {
|
|
95
125
|
messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
|
|
96
|
-
node.style.setProperty('padding-
|
|
126
|
+
node.style.setProperty('padding-inline-end', messagesHasScrollbar ? '0px' : '12px', 'important');
|
|
97
127
|
}
|
|
98
128
|
const resizeObserver = new ResizeObserver(check);
|
|
99
129
|
resizeObserver.observe(node);
|
|
@@ -114,9 +144,9 @@
|
|
|
114
144
|
const hasScroll = candidates.some((el) => el.scrollHeight > el.clientHeight + 1);
|
|
115
145
|
node.classList.toggle('message-bubble-has-scroll', hasScroll);
|
|
116
146
|
if (hasScroll) {
|
|
117
|
-
node.style.setProperty('padding-
|
|
147
|
+
node.style.setProperty('padding-inline-end', '0px', 'important');
|
|
118
148
|
} else {
|
|
119
|
-
node.style.removeProperty('padding-
|
|
149
|
+
node.style.removeProperty('padding-inline-end');
|
|
120
150
|
}
|
|
121
151
|
}
|
|
122
152
|
const resizeObserver = new ResizeObserver(check);
|
|
@@ -499,6 +529,8 @@
|
|
|
499
529
|
if (index < 0) return null;
|
|
500
530
|
const prev = [...numbered.slice(0, index)].reverse().find((row) => row.n != null);
|
|
501
531
|
const next = numbered.slice(index + 1).find((row) => row.n != null);
|
|
532
|
+
// A version the host gave no name for is named the way the host names them ("Version 4"): the number is read back out
|
|
533
|
+
// of these words, and `versionLabelText` says them in the page's language when they are drawn.
|
|
502
534
|
if (prev?.n != null && next?.n != null && next.n - prev.n === 2) return `Version ${prev.n + 1}`;
|
|
503
535
|
if (prev?.n != null && next == null) return `Version ${prev.n + 1}`;
|
|
504
536
|
if (prev == null && next?.n != null && next.n > 1) return `Version ${next.n - 1}`;
|
|
@@ -689,6 +721,25 @@
|
|
|
689
721
|
);
|
|
690
722
|
});
|
|
691
723
|
|
|
724
|
+
/**
|
|
725
|
+
* Brings `element` into view inside `container` the way `element.scrollIntoView({ block: 'nearest', behavior: 'smooth' })`
|
|
726
|
+
* does, but moves the container only. `scrollIntoView` scrolls every scrollable ancestor as well, and one of them is the
|
|
727
|
+
* page the chat is on (a partner's page, when the creator is mounted into it).
|
|
728
|
+
*/
|
|
729
|
+
function scrollIntoViewWithin(container: HTMLElement, element: Element) {
|
|
730
|
+
const containerBox = container.getBoundingClientRect();
|
|
731
|
+
const elementBox = element.getBoundingClientRect();
|
|
732
|
+
let distance = 0;
|
|
733
|
+
if (elementBox.top < containerBox.top) {
|
|
734
|
+
// It starts above the visible part: scroll up to its top.
|
|
735
|
+
distance = elementBox.top - containerBox.top;
|
|
736
|
+
} else if (elementBox.bottom > containerBox.bottom) {
|
|
737
|
+
// It ends below the visible part: scroll down just enough, but never past its own top (when it is taller than the container).
|
|
738
|
+
distance = Math.min(elementBox.bottom - containerBox.bottom, elementBox.top - containerBox.top);
|
|
739
|
+
}
|
|
740
|
+
if (distance !== 0) container.scrollBy({ top: distance, behavior: 'smooth' });
|
|
741
|
+
}
|
|
742
|
+
|
|
692
743
|
/** Version dropdown changes which commit is "here" — bring that turn into view. */
|
|
693
744
|
$effect(() => {
|
|
694
745
|
const version = viewingVersion;
|
|
@@ -696,8 +747,8 @@
|
|
|
696
747
|
if ((version == null && !sha) || !messagesContainer) return;
|
|
697
748
|
void tick().then(() => {
|
|
698
749
|
const here = messagesContainer?.querySelector('[data-you-are-here="true"]');
|
|
699
|
-
if (here &&
|
|
700
|
-
|
|
750
|
+
if (here && messagesContainer) {
|
|
751
|
+
scrollIntoViewWithin(messagesContainer, here);
|
|
701
752
|
}
|
|
702
753
|
});
|
|
703
754
|
});
|
|
@@ -723,6 +774,12 @@
|
|
|
723
774
|
}
|
|
724
775
|
|
|
725
776
|
function openUpgradePlans() {
|
|
777
|
+
// A host that is a guest on somebody else's page decides what "upgrade" means there; the billing page of the
|
|
778
|
+
// Widgetic site would take the visitor off the page they are on.
|
|
779
|
+
if (onUpgradePlans) {
|
|
780
|
+
onUpgradePlans();
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
726
783
|
window.location.assign('/workspaces/personal/settings/billing');
|
|
727
784
|
}
|
|
728
785
|
|
|
@@ -1124,7 +1181,7 @@
|
|
|
1124
1181
|
bind:this={messagesContainer}
|
|
1125
1182
|
class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4 pb-3"
|
|
1126
1183
|
class:loading={isLoading}
|
|
1127
|
-
style="scroll-behavior: smooth; padding: 12px
|
|
1184
|
+
style="scroll-behavior: smooth; padding: 12px;"
|
|
1128
1185
|
use:detectMessagesScrollbar
|
|
1129
1186
|
onscroll={handleScroll}
|
|
1130
1187
|
>
|
|
@@ -1134,9 +1191,9 @@
|
|
|
1134
1191
|
after send, so the list is briefly empty again). -->
|
|
1135
1192
|
{#if isInitialized && messages.length === 0 && !isLoading && !isGenerating}
|
|
1136
1193
|
<div class="empty-state-ct flex flex-col items-center justify-center text-center max-w-sm w-full" style="align-self: center;">
|
|
1137
|
-
<h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬
|
|
1194
|
+
<h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 {$t('chat.messages.startTitle')}</h3>
|
|
1138
1195
|
<p class="text-gray-600 dark:text-gray-400 text-sm mb-6">
|
|
1139
|
-
|
|
1196
|
+
{$t('chat.messages.startHint', { type: contextTypeLabel(context.type, $t) })}
|
|
1140
1197
|
</p>
|
|
1141
1198
|
|
|
1142
1199
|
<!-- Contextual suggestions -->
|
|
@@ -1165,16 +1222,16 @@
|
|
|
1165
1222
|
>
|
|
1166
1223
|
<div class="wc-user-bubble-row flex w-full items-start gap-2">
|
|
1167
1224
|
{#if isViewingTurn(turn)}
|
|
1168
|
-
<div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title=
|
|
1225
|
+
<div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title={$t('chat.messages.viewingTitle')}>
|
|
1169
1226
|
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
1170
1227
|
<path d="M20 6L9 17l-5-5"/>
|
|
1171
1228
|
</svg>
|
|
1172
|
-
|
|
1173
|
-
<span class="wc-head-commit-arrow" aria-hidden="true"
|
|
1229
|
+
{$t('chat.messages.viewing')}
|
|
1230
|
+
<span class="wc-head-commit-arrow" aria-hidden="true">{$textDirection === 'rtl' ? '←' : '→'}</span>
|
|
1174
1231
|
</div>
|
|
1175
1232
|
{/if}
|
|
1176
1233
|
<div
|
|
1177
|
-
class="message-bubble relative
|
|
1234
|
+
class="message-bubble relative ms-auto w-fit max-w-[94%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
|
|
1178
1235
|
class:p-3={shownAttachments.length === 0}
|
|
1179
1236
|
class:p-0={shownAttachments.length > 0}
|
|
1180
1237
|
class:bubble-fit-content={shownAttachments.length > 0}
|
|
@@ -1186,7 +1243,7 @@
|
|
|
1186
1243
|
<div class="message-content-mixed p-3">
|
|
1187
1244
|
{#each parseMessageContent(userMsg.messageContent) as part}
|
|
1188
1245
|
{#if part.type === 'text'}
|
|
1189
|
-
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
1246
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{part.content}</p>
|
|
1190
1247
|
{:else if part.type === 'code'}
|
|
1191
1248
|
<div class="my-3 first:mt-0 last:mb-0">
|
|
1192
1249
|
<CodeBlock
|
|
@@ -1199,7 +1256,7 @@
|
|
|
1199
1256
|
{/each}
|
|
1200
1257
|
</div>
|
|
1201
1258
|
{:else}
|
|
1202
|
-
<p class="whitespace-pre-wrap p-3">{userMsg.messageContent}</p>
|
|
1259
|
+
<p class="whitespace-pre-wrap p-3" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
|
|
1203
1260
|
{/if}
|
|
1204
1261
|
{/if}
|
|
1205
1262
|
{#if shownAttachments.length > 0}
|
|
@@ -1208,13 +1265,13 @@
|
|
|
1208
1265
|
</div>
|
|
1209
1266
|
{:else if userMsg.messageContent && messageImpliesAttachedFile(userMsg.messageContent)}
|
|
1210
1267
|
<div class="wc-missing-attachment-placeholder message-attachments-container flex flex-col items-center gap-1 px-3 pb-3">
|
|
1211
|
-
<div class="wc-missing-attachment-thumb flex h-20 w-28 flex-col items-center justify-center gap-1 rounded-md border border-dashed border-gray-300 bg-gray-100 text-gray-400" title=
|
|
1268
|
+
<div class="wc-missing-attachment-thumb flex h-20 w-28 flex-col items-center justify-center gap-1 rounded-md border border-dashed border-gray-300 bg-gray-100 text-gray-400" title={$t('chat.messages.attachmentMissingTitle')} aria-label={$t('chat.messages.attachmentMissingLabel')}>
|
|
1212
1269
|
<svg class="h-8 w-8 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
|
|
1213
1270
|
<rect x="3" y="5" width="18" height="14" rx="2" />
|
|
1214
1271
|
<path d="M4 4l16 16" stroke-linecap="round" />
|
|
1215
1272
|
</svg>
|
|
1216
1273
|
</div>
|
|
1217
|
-
<p class="wc-missing-attachment-caption max-w-[12rem] text-center text-xs text-gray-500">
|
|
1274
|
+
<p class="wc-missing-attachment-caption max-w-[12rem] text-center text-xs text-gray-500">{$t('chat.messages.attachmentMissingCaption')}</p>
|
|
1218
1275
|
</div>
|
|
1219
1276
|
{/if}
|
|
1220
1277
|
</div>
|
|
@@ -1224,13 +1281,13 @@
|
|
|
1224
1281
|
<button
|
|
1225
1282
|
class="retry-codegen-btn"
|
|
1226
1283
|
onclick={() => handleRetryTurn(turn, turnIndex)}
|
|
1227
|
-
title=
|
|
1284
|
+
title={$t('chat.messages.retryPromptTitle')}
|
|
1228
1285
|
>
|
|
1229
1286
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1230
1287
|
<path d="M21 12a9 9 0 1 1-2.64-6.36"/>
|
|
1231
1288
|
<path d="M21 3v6h-6"/>
|
|
1232
1289
|
</svg>
|
|
1233
|
-
|
|
1290
|
+
{$t('chat.messages.retry')}
|
|
1234
1291
|
</button>
|
|
1235
1292
|
</div>
|
|
1236
1293
|
{/if}
|
|
@@ -1247,12 +1304,12 @@
|
|
|
1247
1304
|
<div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
|
|
1248
1305
|
{#if getTurnVersionLabel(turn)}
|
|
1249
1306
|
<span class="wc-user-version-label text-xs text-gray-500">
|
|
1250
|
-
{getTurnVersionLabel(turn)}
|
|
1307
|
+
{versionLabelText(getTurnVersionLabel(turn), $t)}
|
|
1251
1308
|
</span>
|
|
1252
1309
|
{/if}
|
|
1253
1310
|
{#if showCommitMeta && getTurnCommitShort(turn)}
|
|
1254
1311
|
<span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
|
|
1255
|
-
(
|
|
1312
|
+
{$t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })}
|
|
1256
1313
|
</span>
|
|
1257
1314
|
{/if}
|
|
1258
1315
|
</div>
|
|
@@ -1266,14 +1323,14 @@
|
|
|
1266
1323
|
handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
|
|
1267
1324
|
}}
|
|
1268
1325
|
title={restoreIsCurrentHead
|
|
1269
|
-
? '
|
|
1270
|
-
: '
|
|
1326
|
+
? $t('chat.messages.alreadyHead')
|
|
1327
|
+
: $t('chat.messages.restoreTitle')}
|
|
1271
1328
|
>
|
|
1272
1329
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1273
1330
|
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
|
|
1274
1331
|
<path d="M3 3v5h5"/>
|
|
1275
1332
|
</svg>
|
|
1276
|
-
|
|
1333
|
+
{$t('chat.messages.restore')}
|
|
1277
1334
|
</button>
|
|
1278
1335
|
{/if}
|
|
1279
1336
|
</div>
|
|
@@ -1283,7 +1340,7 @@
|
|
|
1283
1340
|
|
|
1284
1341
|
{#each turn.replies as reply (reply.id)}
|
|
1285
1342
|
{#if shouldShowAssistantReply(reply)}
|
|
1286
|
-
<div class="message-container wc-chat-turn-reply
|
|
1343
|
+
<div class="message-container wc-chat-turn-reply me-auto w-fit max-w-[94%] flex flex-col items-stretch overflow-visible"
|
|
1287
1344
|
class:opacity-75={reply._optimistic}
|
|
1288
1345
|
class:opacity-50={reply._failed}
|
|
1289
1346
|
class:current-checkpoint={isHeadCommitReply(reply)}
|
|
@@ -1299,7 +1356,7 @@
|
|
|
1299
1356
|
<div class="message-content-mixed">
|
|
1300
1357
|
{#each parseMessageContent(reply.messageContent) as part}
|
|
1301
1358
|
{#if part.type === 'text'}
|
|
1302
|
-
<p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
|
|
1359
|
+
<p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{visibleMessageContent(part.content)}</p>
|
|
1303
1360
|
{:else if part.type === 'code'}
|
|
1304
1361
|
<div class="my-3 first:mt-0 last:mb-0">
|
|
1305
1362
|
<CodeBlock
|
|
@@ -1312,7 +1369,7 @@
|
|
|
1312
1369
|
{/each}
|
|
1313
1370
|
</div>
|
|
1314
1371
|
{:else}
|
|
1315
|
-
<p class="whitespace-pre-wrap">{reply.messageContent}</p>
|
|
1372
|
+
<p class="whitespace-pre-wrap" dir={dirForUserText($textDirection)}>{visibleMessageContent(reply.messageContent)}</p>
|
|
1316
1373
|
{/if}
|
|
1317
1374
|
{/if}
|
|
1318
1375
|
</div>
|
|
@@ -1345,21 +1402,21 @@
|
|
|
1345
1402
|
<button
|
|
1346
1403
|
class="retry-codegen-btn"
|
|
1347
1404
|
onclick={openUpgradePlans}
|
|
1348
|
-
title=
|
|
1405
|
+
title={$t('chat.messages.upgradeTitle')}
|
|
1349
1406
|
>
|
|
1350
|
-
|
|
1407
|
+
{$t('chat.messages.upgrade')}
|
|
1351
1408
|
</button>
|
|
1352
1409
|
{:else}
|
|
1353
1410
|
<button
|
|
1354
1411
|
class="retry-codegen-btn"
|
|
1355
1412
|
onclick={() => handleRetryTurn(turn, turnIndex)}
|
|
1356
|
-
title=
|
|
1413
|
+
title={$t('chat.messages.retryLastTitle')}
|
|
1357
1414
|
>
|
|
1358
1415
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1359
1416
|
<path d="M21 12a9 9 0 1 1-2.64-6.36"/>
|
|
1360
1417
|
<path d="M21 3v6h-6"/>
|
|
1361
1418
|
</svg>
|
|
1362
|
-
|
|
1419
|
+
{$t('chat.messages.retry')}
|
|
1363
1420
|
</button>
|
|
1364
1421
|
{/if}
|
|
1365
1422
|
</div>
|
|
@@ -1385,7 +1442,7 @@
|
|
|
1385
1442
|
class="suggestions-toggle-btn text-xs text-gray-400 hover:text-gray-600 px-3 py-1.5 rounded-full border border-gray-200 hover:border-gray-300 bg-white hover:bg-gray-50 transition-colors cursor-pointer"
|
|
1386
1443
|
onclick={() => { showSuggestionsInline = true; }}
|
|
1387
1444
|
>
|
|
1388
|
-
|
|
1445
|
+
{$t('chat.messages.showSuggestions')}
|
|
1389
1446
|
</button>
|
|
1390
1447
|
{/if}
|
|
1391
1448
|
</div>
|
|
@@ -1396,7 +1453,7 @@
|
|
|
1396
1453
|
<div class="loading-history-ct flex flex-1 items-center justify-center p-8">
|
|
1397
1454
|
<div class="text-center">
|
|
1398
1455
|
<div class="w-6 h-6 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin mx-auto mb-2"></div>
|
|
1399
|
-
<p class="text-gray-500 text-xs">
|
|
1456
|
+
<p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
|
|
1400
1457
|
</div>
|
|
1401
1458
|
</div>
|
|
1402
1459
|
{:else if isLoading}
|
|
@@ -1406,7 +1463,7 @@
|
|
|
1406
1463
|
>
|
|
1407
1464
|
<LoadingIndicator
|
|
1408
1465
|
type="thinking"
|
|
1409
|
-
text=
|
|
1466
|
+
text={$t('chat.messages.thinking')}
|
|
1410
1467
|
color="secondary"
|
|
1411
1468
|
size="md"
|
|
1412
1469
|
/>
|
|
@@ -1491,7 +1548,7 @@
|
|
|
1491
1548
|
font-size: 11px;
|
|
1492
1549
|
line-height: 1;
|
|
1493
1550
|
font-weight: 700;
|
|
1494
|
-
margin-
|
|
1551
|
+
margin-inline-start: 2px;
|
|
1495
1552
|
}
|
|
1496
1553
|
|
|
1497
1554
|
.wc-head-commit-meta-ct .wc-head-commit-label {
|
|
@@ -1571,7 +1628,7 @@
|
|
|
1571
1628
|
font-size: 12px;
|
|
1572
1629
|
font-weight: 500;
|
|
1573
1630
|
cursor: pointer;
|
|
1574
|
-
text-align:
|
|
1631
|
+
text-align: start;
|
|
1575
1632
|
overflow-wrap: anywhere;
|
|
1576
1633
|
white-space: normal;
|
|
1577
1634
|
transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
|
|
@@ -1630,7 +1687,7 @@
|
|
|
1630
1687
|
max-width: 100%;
|
|
1631
1688
|
}
|
|
1632
1689
|
.message-bubble-has-scroll {
|
|
1633
|
-
padding-
|
|
1690
|
+
padding-inline-end: 0px !important;
|
|
1634
1691
|
}
|
|
1635
1692
|
.message-bubble p,
|
|
1636
1693
|
.message-content-mixed {
|
|
@@ -52,12 +52,20 @@ interface Props {
|
|
|
52
52
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
53
53
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
54
54
|
onRetryMessage?: (content: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
|
|
57
|
+
* billing page of the Widgetic site. A host that is a guest on somebody else's page (the creator in a partner's
|
|
58
|
+
* page) gives its own function: the page it is on is not the chat's to navigate away from.
|
|
59
|
+
*/
|
|
60
|
+
onUpgradePlans?: () => void;
|
|
55
61
|
/** Tapping a clarification-card suggestion chip sends it as the next user message,
|
|
56
62
|
* carrying the chip's structured intent. Chips are disabled while the host
|
|
57
63
|
* runs widget codegen (`isGenerating`). */
|
|
58
64
|
onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
|
|
59
65
|
/** Host-rendered inline design-control card for messages carrying `designControls`. */
|
|
60
66
|
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
67
|
+
/** Host translation for lines saved in English (see Chat `storedLineLabel`). */
|
|
68
|
+
storedLineLabel?: (content: string) => string;
|
|
61
69
|
}
|
|
62
70
|
declare const ChatMessages: import("svelte").Component<Props, {}, "">;
|
|
63
71
|
type ChatMessages = ReturnType<typeof ChatMessages>;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import bash from 'highlight.js/lib/languages/bash';
|
|
11
11
|
import markdown from 'highlight.js/lib/languages/markdown';
|
|
12
12
|
import sql from 'highlight.js/lib/languages/sql';
|
|
13
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
13
14
|
|
|
14
15
|
// Register essential programming languages for code rendering
|
|
15
16
|
hljs.registerLanguage('javascript', javascript);
|
|
@@ -28,6 +29,9 @@
|
|
|
28
29
|
hljs.registerLanguage('markdown', markdown);
|
|
29
30
|
hljs.registerLanguage('md', markdown);
|
|
30
31
|
hljs.registerLanguage('sql', sql);
|
|
32
|
+
|
|
33
|
+
// The words of the copy button, in the language of the chat above
|
|
34
|
+
const { t } = useChatLanguage();
|
|
31
35
|
|
|
32
36
|
interface Props {
|
|
33
37
|
code: string;
|
|
@@ -110,7 +114,8 @@
|
|
|
110
114
|
}
|
|
111
115
|
</script>
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
<!-- Code is read left to right whatever the language of the screen, so the whole block (the line numbers, the text and the copy button) is a left to right island. -->
|
|
118
|
+
<div class="code-block" dir="ltr">
|
|
114
119
|
{#if title || language || copyable}
|
|
115
120
|
<div class="code-header">
|
|
116
121
|
<div class="code-info">
|
|
@@ -129,19 +134,19 @@
|
|
|
129
134
|
class="copy-button"
|
|
130
135
|
class:copied
|
|
131
136
|
onclick={copyToClipboard}
|
|
132
|
-
title={copied ? '
|
|
137
|
+
title={copied ? $t('chat.code.copied') : $t('chat.code.copyTitle')}
|
|
133
138
|
>
|
|
134
139
|
{#if copied}
|
|
135
140
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
136
141
|
<path d="M20 6L9 17l-5-5"/>
|
|
137
142
|
</svg>
|
|
138
|
-
|
|
143
|
+
{$t('chat.code.copied')}
|
|
139
144
|
{:else}
|
|
140
145
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
141
146
|
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
142
147
|
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
143
148
|
</svg>
|
|
144
|
-
|
|
149
|
+
{$t('chat.code.copy')}
|
|
145
150
|
{/if}
|
|
146
151
|
</button>
|
|
147
152
|
{/if}
|
|
@@ -254,22 +259,22 @@
|
|
|
254
259
|
|
|
255
260
|
/* Line numbers styling */
|
|
256
261
|
.with-line-numbers :global(.hljs) {
|
|
257
|
-
padding-left: 3em;
|
|
262
|
+
padding-left: 3em; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
|
|
258
263
|
position: relative;
|
|
259
264
|
}
|
|
260
265
|
|
|
261
266
|
.with-line-numbers :global(.hljs::before) {
|
|
262
267
|
content: counter(line);
|
|
263
268
|
position: absolute;
|
|
264
|
-
left: 0;
|
|
269
|
+
left: 0; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
|
|
265
270
|
top: 0;
|
|
266
271
|
bottom: 0;
|
|
267
272
|
width: 2.5em;
|
|
268
273
|
background: #f8f9fa;
|
|
269
|
-
border-right: 1px solid #e9ecef;
|
|
274
|
+
border-right: 1px solid #e9ecef; /* rtl-ok: the edge of the numbers that faces the code */
|
|
270
275
|
color: #6c757d;
|
|
271
|
-
text-align: right;
|
|
272
|
-
padding-right: 8px;
|
|
276
|
+
text-align: right; /* rtl-ok: the numbers are lined up against the code */
|
|
277
|
+
padding-right: 8px; /* rtl-ok: the space between the numbers and the code */
|
|
273
278
|
font-size: 12px;
|
|
274
279
|
line-height: inherit;
|
|
275
280
|
user-select: none;
|