@widgetic/chat 0.1.37 → 0.1.38
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/components/Chat.svelte +64 -16
- package/dist/components/Chat.svelte.d.ts +4 -0
- package/dist/components/ChatComposer.svelte +63 -0
- package/dist/components/ChatComposer.svelte.d.ts +2 -0
- package/dist/components/ChatMessages.svelte +29 -5
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/messages.d.ts +3 -0
- package/dist/i18n/messages.js +3 -0
- package/dist/i18n/publishNudgeLocales.d.ts +18 -0
- package/dist/i18n/publishNudgeLocales.js +17 -0
- package/dist/sendNudgeState.d.ts +5 -0
- package/dist/sendNudgeState.js +18 -0
- package/dist/types/attachment.d.ts +5 -0
- package/dist/utils/linkifyText.d.ts +16 -0
- package/dist/utils/linkifyText.js +57 -0
- package/package.json +1 -1
|
@@ -123,6 +123,8 @@
|
|
|
123
123
|
showPanelHeader?: boolean;
|
|
124
124
|
/** When true with `onToggleConsole`, shows the debug console icon in the panel header. */
|
|
125
125
|
showConsoleControl?: boolean;
|
|
126
|
+
/** Increment to bounce the Send button and show the publish-first tooltip (host-driven). */
|
|
127
|
+
sendNudgeToken?: number;
|
|
126
128
|
consoleOpen?: boolean;
|
|
127
129
|
onToggleConsole?: () => void;
|
|
128
130
|
/** Custom title displayed in the header. If empty/undefined, defaults to context.title or context.id. */
|
|
@@ -230,6 +232,8 @@
|
|
|
230
232
|
setDraftText: (text: string) => void;
|
|
231
233
|
/** Get attachment preview data URLs in current order. */
|
|
232
234
|
getAttachmentDataUrls: () => string[];
|
|
235
|
+
/** Attached pictures as `data:` URLs, the form the draft keeps so they are still attached after a refresh. */
|
|
236
|
+
getDraftAttachmentDataUrls: () => string[];
|
|
233
237
|
/** Get CDN upload row IDs for image attachments (codegen attachmentIds). */
|
|
234
238
|
getAttachmentUploadIds: () => string[];
|
|
235
239
|
/** Replace chat attachments from stored data URLs (restores draft attachments). */
|
|
@@ -250,7 +254,7 @@
|
|
|
250
254
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
251
255
|
}
|
|
252
256
|
|
|
253
|
-
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onRateVersion, versionRatings: ratingsFromHost = {}, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, showPanelHeader = false, showConsoleControl = false, consoleOpen = false, onToggleConsole, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], isGenerating = false, generationStream = '', generationThinking = '', generationPlan = null, onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel, composerModels = [], selectedComposerModelId = null, onSelectComposerModel }: Props = $props();
|
|
257
|
+
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onRateVersion, versionRatings: ratingsFromHost = {}, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, showPanelHeader = false, showConsoleControl = false, sendNudgeToken = 0, consoleOpen = false, onToggleConsole, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], isGenerating = false, generationStream = '', generationThinking = '', generationPlan = null, onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel, composerModels = [], selectedComposerModelId = null, onSelectComposerModel }: Props = $props();
|
|
254
258
|
|
|
255
259
|
// The words of everything inside the chat, in the language the page chose. The page can change the language while the
|
|
256
260
|
// chat is open: the settings are read again whenever they change (and setting the same language again does nothing).
|
|
@@ -1089,6 +1093,45 @@
|
|
|
1089
1093
|
|
|
1090
1094
|
let footerLightboxSrc: string | null = $state(null);
|
|
1091
1095
|
|
|
1096
|
+
/** Biggest image kept in the draft: a draft is written to the browser's storage on every change. */
|
|
1097
|
+
const MAX_PERSISTED_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
1098
|
+
|
|
1099
|
+
/** Reads an attached image into a `data:` URL for the draft; resolves to '' when it cannot or should not be kept. */
|
|
1100
|
+
function readImageAsDataUrl(file: File): Promise<string> {
|
|
1101
|
+
return new Promise((resolve) => {
|
|
1102
|
+
if (!file.type.startsWith('image/') || file.size > MAX_PERSISTED_IMAGE_BYTES) {
|
|
1103
|
+
resolve('');
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
try {
|
|
1107
|
+
const reader = new FileReader();
|
|
1108
|
+
reader.onload = () => resolve(typeof reader.result === 'string' ? reader.result : '');
|
|
1109
|
+
reader.onerror = () => {
|
|
1110
|
+
chatWarn('[Chat] Could not read the image for the draft:', file.name);
|
|
1111
|
+
resolve('');
|
|
1112
|
+
};
|
|
1113
|
+
reader.readAsDataURL(file);
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
chatWarn('[Chat] Could not read the image for the draft:', error);
|
|
1116
|
+
resolve('');
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/** Keeps an attached image in the draft, so it is still attached after a refresh. */
|
|
1122
|
+
async function rememberImageForDraft(entry: AttachmentInput): Promise<void> {
|
|
1123
|
+
const dataUrl = await readImageAsDataUrl(entry.file);
|
|
1124
|
+
if (!dataUrl) return;
|
|
1125
|
+
entry.persistedDataUrl = dataUrl;
|
|
1126
|
+
// The attachment may have been removed while the file was read: only a tray that still holds it is saved.
|
|
1127
|
+
// It is set on the object the tray holds now, not on a copy: the upload keeps writing to that object.
|
|
1128
|
+
const inTray = localAttachments.find((att) => att.file === entry.file);
|
|
1129
|
+
if (!inTray) return;
|
|
1130
|
+
inTray.persistedDataUrl = dataUrl;
|
|
1131
|
+
localAttachments = [...localAttachments];
|
|
1132
|
+
notifyDraftChange();
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1092
1135
|
async function addFilesAsAttachments(files: File[]) {
|
|
1093
1136
|
const usableFiles = (files || []).filter((file) => file && file.size > 0);
|
|
1094
1137
|
if (usableFiles.length === 0) return;
|
|
@@ -1110,6 +1153,8 @@
|
|
|
1110
1153
|
expandChatForAttachmentGrowth(previousCount);
|
|
1111
1154
|
chatStore.actions.updateUI({ errorMessage: null });
|
|
1112
1155
|
console.log('[Chat] attachments now', localAttachments.length);
|
|
1156
|
+
// The draft keeps each picture as it is attached, before the upload ends (a refresh can come at any time).
|
|
1157
|
+
for (const entry of newAttachments) void rememberImageForDraft(entry);
|
|
1113
1158
|
|
|
1114
1159
|
try {
|
|
1115
1160
|
localIsUploading = true;
|
|
@@ -1171,21 +1216,11 @@
|
|
|
1171
1216
|
showFailure(actionFailureKey(detail.type));
|
|
1172
1217
|
}
|
|
1173
1218
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1219
|
+
function handleSuggestionSelected(suggestion: string) {
|
|
1220
|
+
const trimmed = suggestion.trim();
|
|
1176
1221
|
if (!trimmed) return;
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
try {
|
|
1180
|
-
await sendMessage(trimmed, undefined, { skipIntentGate: true });
|
|
1181
|
-
} catch (err) {
|
|
1182
|
-
console.error('[Chat] Panel suggestion send failed:', err);
|
|
1183
|
-
showFailure('chat.error.sendSuggestion');
|
|
1184
|
-
}
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
// Autocomplete into input instead of sending immediately — lets user review,
|
|
1188
|
-
// edit, and attach an image before sending.
|
|
1222
|
+
// A suggestion (the empty-state cards and the "Try next" follow-ups of the panel alike) goes into the input and is
|
|
1223
|
+
// not sent: the person reviews it, edits it, attaches a picture, and presses Send.
|
|
1189
1224
|
setDraftText(trimmed);
|
|
1190
1225
|
}
|
|
1191
1226
|
|
|
@@ -1420,6 +1455,17 @@
|
|
|
1420
1455
|
.filter((url) => !!url);
|
|
1421
1456
|
}
|
|
1422
1457
|
|
|
1458
|
+
/**
|
|
1459
|
+
* The attached pictures in the one form a refresh can rebuild them from: `data:` URLs. This is what the draft keeps;
|
|
1460
|
+
* `getAttachmentDataUrls` stays the list of addresses to send with a message (a CDN address when the upload ended).
|
|
1461
|
+
*/
|
|
1462
|
+
function getDraftAttachmentDataUrls(): string[] {
|
|
1463
|
+
return localAttachments
|
|
1464
|
+
.filter((att) => att.type === 'image' || att.file?.type?.startsWith('image/'))
|
|
1465
|
+
.map((att) => att.persistedDataUrl || (att.preview?.startsWith('data:') ? att.preview : '') || '')
|
|
1466
|
+
.filter((url) => !!url);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1423
1469
|
function getAttachmentUploadIds(): string[] {
|
|
1424
1470
|
return localAttachments
|
|
1425
1471
|
.filter((att) => Boolean(att.uploadId))
|
|
@@ -1796,6 +1842,7 @@
|
|
|
1796
1842
|
getDraftText,
|
|
1797
1843
|
setDraftText,
|
|
1798
1844
|
getAttachmentDataUrls,
|
|
1845
|
+
getDraftAttachmentDataUrls,
|
|
1799
1846
|
getAttachmentUploadIds,
|
|
1800
1847
|
restoreAttachmentsFromDataUrls,
|
|
1801
1848
|
clearDraft,
|
|
@@ -1991,7 +2038,7 @@
|
|
|
1991
2038
|
messages={currentMessages || []}
|
|
1992
2039
|
isLoading={isLoading}
|
|
1993
2040
|
isInitialized={isInitialized}
|
|
1994
|
-
{showEmptyState}
|
|
2041
|
+
showEmptyState={showEmptyState && localAttachments.length === 0}
|
|
1995
2042
|
panelLayout={showPanelHeader}
|
|
1996
2043
|
{context}
|
|
1997
2044
|
isCompleted={isCompleted}
|
|
@@ -2152,6 +2199,7 @@
|
|
|
2152
2199
|
{/if}
|
|
2153
2200
|
|
|
2154
2201
|
<ChatComposer
|
|
2202
|
+
{sendNudgeToken}
|
|
2155
2203
|
panelLayout={showPanelHeader}
|
|
2156
2204
|
placeholder={showPanelHeader
|
|
2157
2205
|
? (currentMessages?.length ?? 0) > 0
|
|
@@ -29,6 +29,8 @@ interface ChatMethods {
|
|
|
29
29
|
setDraftText: (text: string) => void;
|
|
30
30
|
/** Get attachment preview data URLs in current order. */
|
|
31
31
|
getAttachmentDataUrls: () => string[];
|
|
32
|
+
/** Attached pictures as `data:` URLs, the form the draft keeps so they are still attached after a refresh. */
|
|
33
|
+
getDraftAttachmentDataUrls: () => string[];
|
|
32
34
|
/** Get CDN upload row IDs for image attachments (codegen attachmentIds). */
|
|
33
35
|
getAttachmentUploadIds: () => string[];
|
|
34
36
|
/** Replace chat attachments from stored data URLs (restores draft attachments). */
|
|
@@ -160,6 +162,8 @@ interface Props {
|
|
|
160
162
|
showPanelHeader?: boolean;
|
|
161
163
|
/** When true with `onToggleConsole`, shows the debug console icon in the panel header. */
|
|
162
164
|
showConsoleControl?: boolean;
|
|
165
|
+
/** Increment to bounce the Send button and show the publish-first tooltip (host-driven). */
|
|
166
|
+
sendNudgeToken?: number;
|
|
163
167
|
consoleOpen?: boolean;
|
|
164
168
|
onToggleConsole?: () => void;
|
|
165
169
|
/** Custom title displayed in the header. If empty/undefined, defaults to context.title or context.id. */
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
5
5
|
import { Composer, IconButton } from '@widgetic/design-system/components/chat/index';
|
|
6
6
|
import { chatLog } from '../utils/logger.js';
|
|
7
|
+
import { reduceSendNudge, SEND_NUDGE_VISIBLE_MS, type SendNudgePhase } from '../sendNudgeState.js';
|
|
7
8
|
|
|
8
9
|
const { t } = useChatLanguage();
|
|
9
10
|
const textDirection = useTextDirection();
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
panelLayout?: boolean;
|
|
32
33
|
/** Figma panel composer (65:31): arrow-up send icon instead of paper-plane. */
|
|
33
34
|
sendIcon?: 'send' | 'arrow-up';
|
|
35
|
+
/** Increment from the host to nudge Send before publish. */
|
|
36
|
+
sendNudgeToken?: number;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
let {
|
|
@@ -51,11 +54,65 @@
|
|
|
51
54
|
onAttach,
|
|
52
55
|
panelLayout = false,
|
|
53
56
|
sendIcon = 'send',
|
|
57
|
+
sendNudgeToken = 0,
|
|
54
58
|
}: Props = $props();
|
|
55
59
|
|
|
56
60
|
const composerSendIcon = $derived(panelLayout ? 'arrow-up' : sendIcon);
|
|
57
61
|
|
|
58
62
|
let isFileDragOver = $state(false);
|
|
63
|
+
let sendNudgePhase = $state<SendNudgePhase>('idle');
|
|
64
|
+
let sendNudgeBounce = $state(false);
|
|
65
|
+
let sendNudgeHideTimer: ReturnType<typeof setTimeout> | null = null;
|
|
66
|
+
let sendNudgeBounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
67
|
+
let lastNudgeToken = $state(0);
|
|
68
|
+
|
|
69
|
+
const publishNudgeText = $derived($t('chat.input.publishNudge'));
|
|
70
|
+
const sendAttention = $derived(
|
|
71
|
+
sendNudgePhase === 'active'
|
|
72
|
+
? {
|
|
73
|
+
bounce: sendNudgeBounce,
|
|
74
|
+
hintOpen: true,
|
|
75
|
+
hintText: publishNudgeText,
|
|
76
|
+
}
|
|
77
|
+
: sendNudgeBounce
|
|
78
|
+
? { bounce: true, hintOpen: false, hintText: '' }
|
|
79
|
+
: undefined,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
function clearSendNudgeTimers() {
|
|
83
|
+
if (sendNudgeHideTimer) {
|
|
84
|
+
clearTimeout(sendNudgeHideTimer);
|
|
85
|
+
sendNudgeHideTimer = null;
|
|
86
|
+
}
|
|
87
|
+
if (sendNudgeBounceTimer) {
|
|
88
|
+
clearTimeout(sendNudgeBounceTimer);
|
|
89
|
+
sendNudgeBounceTimer = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function armSendNudge() {
|
|
94
|
+
clearSendNudgeTimers();
|
|
95
|
+
sendNudgePhase = reduceSendNudge(sendNudgePhase, 'trigger');
|
|
96
|
+
const reducedMotion =
|
|
97
|
+
typeof window !== 'undefined' &&
|
|
98
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
99
|
+
sendNudgeBounce = !reducedMotion;
|
|
100
|
+
if (sendNudgeBounce) {
|
|
101
|
+
sendNudgeBounceTimer = setTimeout(() => {
|
|
102
|
+
sendNudgeBounce = false;
|
|
103
|
+
}, 750);
|
|
104
|
+
}
|
|
105
|
+
sendNudgeHideTimer = setTimeout(() => {
|
|
106
|
+
sendNudgePhase = reduceSendNudge(sendNudgePhase, 'autoHide');
|
|
107
|
+
}, SEND_NUDGE_VISIBLE_MS);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
$effect(() => {
|
|
111
|
+
if (sendNudgeToken > 0 && sendNudgeToken !== lastNudgeToken) {
|
|
112
|
+
lastNudgeToken = sendNudgeToken;
|
|
113
|
+
armSendNudge();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
59
116
|
|
|
60
117
|
const busy = $derived(isGenerating || isSending);
|
|
61
118
|
const allowEmptySend = $derived(canSendWithoutText);
|
|
@@ -99,6 +156,11 @@
|
|
|
99
156
|
const trimmed = text.trim();
|
|
100
157
|
if (!trimmed && !allowEmptySend) return;
|
|
101
158
|
if (isSending && !isGenerating) return;
|
|
159
|
+
if (sendNudgePhase === 'active') {
|
|
160
|
+
sendNudgePhase = reduceSendNudge(sendNudgePhase, 'userInteract');
|
|
161
|
+
clearSendNudgeTimers();
|
|
162
|
+
sendNudgeBounce = false;
|
|
163
|
+
}
|
|
102
164
|
onSend(trimmed, undefined);
|
|
103
165
|
}
|
|
104
166
|
</script>
|
|
@@ -162,5 +224,6 @@
|
|
|
162
224
|
onSend={handleComposerSend}
|
|
163
225
|
onStop={() => onStop?.()}
|
|
164
226
|
leading={attachControl}
|
|
227
|
+
{sendAttention}
|
|
165
228
|
/>
|
|
166
229
|
</div>
|
|
@@ -24,6 +24,8 @@ interface Props {
|
|
|
24
24
|
panelLayout?: boolean;
|
|
25
25
|
/** Figma panel composer (65:31): arrow-up send icon instead of paper-plane. */
|
|
26
26
|
sendIcon?: 'send' | 'arrow-up';
|
|
27
|
+
/** Increment from the host to nudge Send before publish. */
|
|
28
|
+
sendNudgeToken?: number;
|
|
27
29
|
}
|
|
28
30
|
declare const ChatComposer: import("svelte").Component<Props, {}, "value">;
|
|
29
31
|
type ChatComposer = ReturnType<typeof ChatComposer>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
4
4
|
import { MESSAGE_COLORS } from '../constants/colors.js';
|
|
5
5
|
import { chatLog } from '../utils/logger.js';
|
|
6
|
+
import { splitTextIntoLinks } from '../utils/linkifyText.js';
|
|
6
7
|
import { isRatableVersionReply, type VersionThumb } from '../utils/versionRatings.js';
|
|
7
8
|
import { isLocalMessageId, restoreBeforeTarget, textToCopy, type TurnRestorePoint } from '../utils/messageActions.js';
|
|
8
9
|
import { AttachmentDisplay, SuggestionButtons } from './index.js';
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
import { versionLabelText } from '../i18n/labels.js';
|
|
18
19
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
19
20
|
import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
|
|
21
|
+
import IconPlayerStop from '@tabler/icons-svelte/icons/player-stop';
|
|
20
22
|
import {
|
|
21
23
|
generationActivityAriaKey,
|
|
22
24
|
generationActivityPhase,
|
|
@@ -542,6 +544,12 @@
|
|
|
542
544
|
);
|
|
543
545
|
}
|
|
544
546
|
|
|
547
|
+
/** A build the person stopped: it says so in the panel as the command they gave, and does not read as a failure. */
|
|
548
|
+
function isStoppedByUser(message: ChatMessage): boolean {
|
|
549
|
+
if (message.messageType !== 'assistant' || !message.messageContent) return false;
|
|
550
|
+
return /^(⏹\s*)?Generation stopped/i.test(message.messageContent.trim());
|
|
551
|
+
}
|
|
552
|
+
|
|
545
553
|
function canUndoHeadUserTurn(turn: ChatTurn): boolean {
|
|
546
554
|
return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
|
|
547
555
|
}
|
|
@@ -1549,6 +1557,13 @@
|
|
|
1549
1557
|
}
|
|
1550
1558
|
</script>
|
|
1551
1559
|
|
|
1560
|
+
{#snippet linkified(text: string)}{#each splitTextIntoLinks(text) as segment, segmentIndex (segmentIndex)}{#if segment.type === 'link'}<a
|
|
1561
|
+
href={segment.href}
|
|
1562
|
+
target="_blank"
|
|
1563
|
+
rel="noopener noreferrer"
|
|
1564
|
+
class="wc-chat-link text-foreground hover:text-primary underline underline-offset-2 [overflow-wrap:anywhere]"
|
|
1565
|
+
data-testid="chat-message-link">{segment.text}</a>{:else}{segment.text}{/if}{/each}{/snippet}
|
|
1566
|
+
|
|
1552
1567
|
<div class="{panelLayout ? 'panel-messages-shell flex h-full min-h-0 w-full flex-1 flex-col' : 'contents'}">
|
|
1553
1568
|
<div
|
|
1554
1569
|
bind:this={messagesContainer}
|
|
@@ -1619,7 +1634,7 @@
|
|
|
1619
1634
|
<div class="message-content-mixed p-3">
|
|
1620
1635
|
{#each parseMessageContent(userMsg.messageContent) as part}
|
|
1621
1636
|
{#if part.type === 'text'}
|
|
1622
|
-
<p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{part.content}</p>
|
|
1637
|
+
<p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{@render linkified(part.content)}</p>
|
|
1623
1638
|
{:else if part.type === 'code'}
|
|
1624
1639
|
<div class="my-3 first:mt-0 last:mb-0">
|
|
1625
1640
|
<CodeBlock
|
|
@@ -1632,7 +1647,7 @@
|
|
|
1632
1647
|
{/each}
|
|
1633
1648
|
</div>
|
|
1634
1649
|
{:else}
|
|
1635
|
-
<p class="whitespace-pre-wrap {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
|
|
1650
|
+
<p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{@render linkified(userMsg.messageContent)}</p>
|
|
1636
1651
|
{/if}
|
|
1637
1652
|
{/if}
|
|
1638
1653
|
{#if shownAttachments.length > 0}
|
|
@@ -1691,7 +1706,16 @@
|
|
|
1691
1706
|
|
|
1692
1707
|
{#each turn.replies as reply (reply.id)}
|
|
1693
1708
|
{#if shouldShowAssistantReply(reply)}
|
|
1694
|
-
{#if panelLayout &&
|
|
1709
|
+
{#if panelLayout && isStoppedByUser(reply)}
|
|
1710
|
+
<!-- A stop is the person's own command: one quiet line, not the red "Could not build the widget" card. -->
|
|
1711
|
+
<p
|
|
1712
|
+
class="wc-chat-turn-reply wc-chat-stopped text-body text-muted-foreground flex items-center gap-2"
|
|
1713
|
+
data-testid="chat-stopped-notice"
|
|
1714
|
+
>
|
|
1715
|
+
<IconPlayerStop class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
1716
|
+
<span>{$t('chat.messages.stoppedByYou')}</span>
|
|
1717
|
+
</p>
|
|
1718
|
+
{:else if panelLayout && isCodegenFailure(reply)}
|
|
1695
1719
|
<!-- Figma Alert (526:3205): a failed reply in the docked panel is a card with a title, a line and "Try again",
|
|
1696
1720
|
not a red line of text. The button runs the prompt of this turn again, on the last failure of the turn only. -->
|
|
1697
1721
|
<ChatAlertCard
|
|
@@ -1721,7 +1745,7 @@
|
|
|
1721
1745
|
<div class="message-content-mixed">
|
|
1722
1746
|
{#each parseMessageContent(reply.messageContent) as part}
|
|
1723
1747
|
{#if part.type === 'text'}
|
|
1724
|
-
<p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{visibleMessageContent(part.content)}</p>
|
|
1748
|
+
<p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{@render linkified(visibleMessageContent(part.content))}</p>
|
|
1725
1749
|
{:else if part.type === 'code'}
|
|
1726
1750
|
<div class="my-3 first:mt-0 last:mb-0">
|
|
1727
1751
|
<CodeBlock
|
|
@@ -1734,7 +1758,7 @@
|
|
|
1734
1758
|
{/each}
|
|
1735
1759
|
</div>
|
|
1736
1760
|
{:else}
|
|
1737
|
-
<p class="whitespace-pre-wrap" dir={dirForUserText($textDirection)}>{visibleMessageContent(reply.messageContent)}</p>
|
|
1761
|
+
<p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere]" dir={dirForUserText($textDirection)}>{@render linkified(visibleMessageContent(reply.messageContent))}</p>
|
|
1738
1762
|
{/if}
|
|
1739
1763
|
{/if}
|
|
1740
1764
|
</div>
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CHAT_MESSAGES, type ChatMessageKey } from './messages.js';
|
|
2
|
+
export { PUBLISH_NUDGE_BY_LOCALE, PUBLISH_NUDGE_ENGLISH } from './publishNudgeLocales.js';
|
|
2
3
|
export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
|
|
3
4
|
export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
|
|
4
5
|
export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';
|
package/dist/i18n/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CHAT_MESSAGES } from './messages.js';
|
|
2
|
+
export { PUBLISH_NUDGE_BY_LOCALE, PUBLISH_NUDGE_ENGLISH } from './publishNudgeLocales.js';
|
|
2
3
|
export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
|
|
3
4
|
export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
|
|
4
5
|
export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export declare const CHAT_MESSAGES: {
|
|
|
72
72
|
readonly 'chat.messages.failedTitle': "Could not build the widget";
|
|
73
73
|
readonly 'chat.messages.failedHint': "The build did not finish. Your sketch is safe, so you can try again.";
|
|
74
74
|
readonly 'chat.messages.failedRetry': "Try again";
|
|
75
|
+
/** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
|
|
76
|
+
readonly 'chat.messages.stoppedByYou': "You stopped the build.";
|
|
75
77
|
readonly 'chat.messages.upgrade': "Upgrade";
|
|
76
78
|
readonly 'chat.messages.upgradeTitle': "Open plans and billing";
|
|
77
79
|
/** Under a prompt: the short id of the commit it made. */
|
|
@@ -141,6 +143,7 @@ export declare const CHAT_MESSAGES: {
|
|
|
141
143
|
readonly 'chat.input.sending': "Sending message...";
|
|
142
144
|
readonly 'chat.input.send': "Send message";
|
|
143
145
|
readonly 'chat.input.tooLong': "Message is too long";
|
|
146
|
+
readonly 'chat.input.publishNudge': "First generate your widget, then you can publish it.";
|
|
144
147
|
readonly 'chat.composer.assistant': "Assistant";
|
|
145
148
|
readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
|
|
146
149
|
readonly 'chat.messages.clarificationPrompt': "Which option fits best?";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -76,6 +76,8 @@ export const CHAT_MESSAGES = {
|
|
|
76
76
|
'chat.messages.failedTitle': 'Could not build the widget',
|
|
77
77
|
'chat.messages.failedHint': 'The build did not finish. Your sketch is safe, so you can try again.',
|
|
78
78
|
'chat.messages.failedRetry': 'Try again',
|
|
79
|
+
/** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
|
|
80
|
+
'chat.messages.stoppedByYou': 'You stopped the build.',
|
|
79
81
|
'chat.messages.upgrade': 'Upgrade',
|
|
80
82
|
'chat.messages.upgradeTitle': 'Open plans and billing',
|
|
81
83
|
/** Under a prompt: the short id of the commit it made. */
|
|
@@ -147,6 +149,7 @@ export const CHAT_MESSAGES = {
|
|
|
147
149
|
'chat.input.sending': 'Sending message...',
|
|
148
150
|
'chat.input.send': 'Send message',
|
|
149
151
|
'chat.input.tooLong': 'Message is too long',
|
|
152
|
+
'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
|
|
150
153
|
'chat.composer.assistant': 'Assistant',
|
|
151
154
|
'chat.messages.scrollToBottom': 'Scroll to latest messages',
|
|
152
155
|
'chat.messages.clarificationPrompt': 'Which option fits best?',
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Host-facing translations for `chat.input.publishNudge` (one row per ui-sdk module locale). */
|
|
2
|
+
export declare const PUBLISH_NUDGE_ENGLISH: "First generate your widget, then you can publish it.";
|
|
3
|
+
export declare const PUBLISH_NUDGE_BY_LOCALE: {
|
|
4
|
+
readonly en: "First generate your widget, then you can publish it.";
|
|
5
|
+
readonly ar: "أنشئ الويدجت أولاً، ثم يمكنك نشره.";
|
|
6
|
+
readonly da: "Generér din widget først, og udgiv den derefter.";
|
|
7
|
+
readonly de: "Erzeuge zuerst dein Widget, danach kannst du es veröffentlichen.";
|
|
8
|
+
readonly es: "Primero genera tu widget y luego podrás publicarlo.";
|
|
9
|
+
readonly fa: "اول ویجت را تولید کنید، بعد میتوانید آن را منتشر کنید.";
|
|
10
|
+
readonly fr: "Générez d'abord votre widget, puis vous pourrez le publier.";
|
|
11
|
+
readonly he: "תחילה צור את הווידג׳ט, ואז תוכל לפרסם אותו.";
|
|
12
|
+
readonly nl: "Genereer eerst je widget; daarna kun je publiceren.";
|
|
13
|
+
readonly 'pt-BR': "Primeiro gere o seu widget; depois você poderá publicá-lo.";
|
|
14
|
+
readonly sv: "Generera widgeten först, sedan kan du publicera den.";
|
|
15
|
+
readonly ur: "پہلے اپنا ویجٹ بنائیں، پھر آپ اسے شائع کر سکتے ہیں۔";
|
|
16
|
+
readonly 'zh-CN': "请先生成小组件,然后再发布。";
|
|
17
|
+
};
|
|
18
|
+
export type PublishNudgeLocale = keyof typeof PUBLISH_NUDGE_BY_LOCALE;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Host-facing translations for `chat.input.publishNudge` (one row per ui-sdk module locale). */
|
|
2
|
+
export const PUBLISH_NUDGE_ENGLISH = 'First generate your widget, then you can publish it.';
|
|
3
|
+
export const PUBLISH_NUDGE_BY_LOCALE = {
|
|
4
|
+
en: PUBLISH_NUDGE_ENGLISH,
|
|
5
|
+
ar: 'أنشئ الويدجت أولاً، ثم يمكنك نشره.',
|
|
6
|
+
da: 'Generér din widget først, og udgiv den derefter.',
|
|
7
|
+
de: 'Erzeuge zuerst dein Widget, danach kannst du es veröffentlichen.',
|
|
8
|
+
es: 'Primero genera tu widget y luego podrás publicarlo.',
|
|
9
|
+
fa: 'اول ویجت را تولید کنید، بعد میتوانید آن را منتشر کنید.',
|
|
10
|
+
fr: "Générez d'abord votre widget, puis vous pourrez le publier.",
|
|
11
|
+
he: 'תחילה צור את הווידג׳ט, ואז תוכל לפרסם אותו.',
|
|
12
|
+
nl: 'Genereer eerst je widget; daarna kun je publiceren.',
|
|
13
|
+
'pt-BR': 'Primeiro gere o seu widget; depois você poderá publicá-lo.',
|
|
14
|
+
sv: 'Generera widgeten först, sedan kan du publicera den.',
|
|
15
|
+
ur: 'پہلے اپنا ویجٹ بنائیں، پھر آپ اسے شائع کر سکتے ہیں۔',
|
|
16
|
+
'zh-CN': '请先生成小组件,然后再发布。',
|
|
17
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type SendNudgePhase = 'idle' | 'active' | 'cleared';
|
|
2
|
+
export type SendNudgeEvent = 'trigger' | 'autoHide' | 'userInteract' | 'reset';
|
|
3
|
+
/** Small state machine for the Send-button publish nudge (bounce + tooltip). */
|
|
4
|
+
export declare function reduceSendNudge(phase: SendNudgePhase, event: SendNudgeEvent): SendNudgePhase;
|
|
5
|
+
export declare const SEND_NUDGE_VISIBLE_MS = 4000;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Small state machine for the Send-button publish nudge (bounce + tooltip). */
|
|
2
|
+
export function reduceSendNudge(phase, event) {
|
|
3
|
+
switch (phase) {
|
|
4
|
+
case 'idle':
|
|
5
|
+
return event === 'trigger' ? 'active' : 'idle';
|
|
6
|
+
case 'active':
|
|
7
|
+
if (event === 'autoHide' || event === 'userInteract')
|
|
8
|
+
return 'cleared';
|
|
9
|
+
if (event === 'trigger')
|
|
10
|
+
return 'active';
|
|
11
|
+
return phase;
|
|
12
|
+
case 'cleared':
|
|
13
|
+
return event === 'reset' ? 'idle' : event === 'trigger' ? 'active' : 'cleared';
|
|
14
|
+
default:
|
|
15
|
+
return 'idle';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const SEND_NUDGE_VISIBLE_MS = 4000;
|
|
@@ -43,6 +43,11 @@ export interface AttachmentInput {
|
|
|
43
43
|
uploadedUrl?: string;
|
|
44
44
|
/** Widgetic uploads row id (for codegen attachmentIds) */
|
|
45
45
|
uploadId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* An image as a `data:` URL, read when it is attached. A `blob:` preview and a CDN address do not come back after a
|
|
48
|
+
* refresh (the first dies with the page, the second is not an image the draft can rebuild a File from), so the draft keeps this.
|
|
49
|
+
*/
|
|
50
|
+
persistedDataUrl?: string;
|
|
46
51
|
uploadProgress?: number;
|
|
47
52
|
}
|
|
48
53
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a line of chat text into plain text and web links, so a message can show an address as a link a person can
|
|
3
|
+
* click, and let the long address wrap inside the message instead of running out of the panel.
|
|
4
|
+
*
|
|
5
|
+
* Only `http://` and `https://` addresses become links: a `javascript:` or `data:` address in a message is plain text.
|
|
6
|
+
*/
|
|
7
|
+
export type LinkifiedSegment = {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'link';
|
|
12
|
+
text: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
/** The segments of `text` in order; joining their `text` gives `text` back. */
|
|
16
|
+
export declare function splitTextIntoLinks(text: string): LinkifiedSegment[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a line of chat text into plain text and web links, so a message can show an address as a link a person can
|
|
3
|
+
* click, and let the long address wrap inside the message instead of running out of the panel.
|
|
4
|
+
*
|
|
5
|
+
* Only `http://` and `https://` addresses become links: a `javascript:` or `data:` address in a message is plain text.
|
|
6
|
+
*/
|
|
7
|
+
/** An address runs until a space or a character that cannot be part of one in running text. */
|
|
8
|
+
const ADDRESS_PATTERN = /https?:\/\/[^\s<>"'`]+/gi;
|
|
9
|
+
/** Punctuation that ends a sentence rather than an address ("see https://a.com/x."). */
|
|
10
|
+
const SENTENCE_END = /[.,;:!?]+$/;
|
|
11
|
+
/**
|
|
12
|
+
* Where the address in `candidate` really ends: trailing sentence punctuation is not part of it, and neither is a closing
|
|
13
|
+
* bracket without an opening one inside the address ("(see https://a.com/x)").
|
|
14
|
+
*/
|
|
15
|
+
function trimAddressEnd(candidate) {
|
|
16
|
+
let address = candidate;
|
|
17
|
+
let changed = true;
|
|
18
|
+
while (changed && address.length > 0) {
|
|
19
|
+
changed = false;
|
|
20
|
+
const withoutPunctuation = address.replace(SENTENCE_END, '');
|
|
21
|
+
if (withoutPunctuation !== address) {
|
|
22
|
+
address = withoutPunctuation;
|
|
23
|
+
changed = true;
|
|
24
|
+
}
|
|
25
|
+
const last = address.at(-1);
|
|
26
|
+
const opener = last === ')' ? '(' : last === ']' ? '[' : last === '}' ? '{' : null;
|
|
27
|
+
if (opener && last) {
|
|
28
|
+
const opens = address.split(opener).length - 1;
|
|
29
|
+
const closes = address.split(last).length - 1;
|
|
30
|
+
if (closes > opens) {
|
|
31
|
+
address = address.slice(0, -1);
|
|
32
|
+
changed = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return address;
|
|
37
|
+
}
|
|
38
|
+
/** The segments of `text` in order; joining their `text` gives `text` back. */
|
|
39
|
+
export function splitTextIntoLinks(text) {
|
|
40
|
+
const source = String(text ?? '');
|
|
41
|
+
const segments = [];
|
|
42
|
+
let cursor = 0;
|
|
43
|
+
for (const match of source.matchAll(ADDRESS_PATTERN)) {
|
|
44
|
+
const start = match.index ?? 0;
|
|
45
|
+
const address = trimAddressEnd(match[0]);
|
|
46
|
+
// "https://" alone is not an address
|
|
47
|
+
if (!/^https?:\/\/[^\s/?#]+/i.test(address))
|
|
48
|
+
continue;
|
|
49
|
+
if (start > cursor)
|
|
50
|
+
segments.push({ type: 'text', text: source.slice(cursor, start) });
|
|
51
|
+
segments.push({ type: 'link', text: address, href: address });
|
|
52
|
+
cursor = start + address.length;
|
|
53
|
+
}
|
|
54
|
+
if (cursor < source.length)
|
|
55
|
+
segments.push({ type: 'text', text: source.slice(cursor) });
|
|
56
|
+
return segments;
|
|
57
|
+
}
|