@widgetic/chat 0.1.35 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -6
- package/dist/components/ActionBar.svelte +8 -0
- package/dist/components/Chat.svelte +87 -100
- package/dist/components/Chat.svelte.d.ts +19 -1
- package/dist/components/ChatComposer.svelte +156 -0
- package/dist/components/ChatComposer.svelte.d.ts +26 -0
- package/dist/components/ChatMessages.svelte +388 -385
- package/dist/components/ChatMessages.svelte.d.ts +14 -6
- package/dist/components/IconButton.svelte +125 -0
- package/dist/components/IconButton.svelte.d.ts +22 -0
- package/dist/components/MessageActions.svelte +48 -0
- package/dist/components/MessageActions.svelte.d.ts +13 -0
- package/dist/components/PanelChatHeader.svelte +44 -0
- package/dist/components/PanelChatHeader.svelte.d.ts +12 -0
- package/dist/components/SuggestionButtons.svelte +11 -163
- package/dist/i18n/messages.d.ts +40 -12
- package/dist/i18n/messages.js +40 -12
- package/dist/utils/generationActivity.d.ts +12 -0
- package/dist/utils/generationActivity.js +47 -0
- package/dist/utils/generationPlan.d.ts +32 -0
- package/dist/utils/generationPlan.js +89 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/messageActions.d.ts +54 -0
- package/dist/utils/messageActions.js +104 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -161,12 +161,30 @@ You can also use individual components:
|
|
|
161
161
|
/>
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
+
### The icons of the messages
|
|
165
|
+
|
|
166
|
+
Three kinds of icon sit around the messages. None of them is shown while something is being generated.
|
|
167
|
+
|
|
168
|
+
- **At the end of the last message**, one row of up to four icons: **copy** (the words the assistant said, else the title of the commit the turn
|
|
169
|
+
made; the icon says "Copied" for a moment), **regenerate** (runs the prompt of that turn again, through `onRetryMessage`; left out when the
|
|
170
|
+
prompt cannot be run again), and **thumbs up** and **thumbs down** (see [Rating a version](#rating-a-version)). An icon that has nothing to do
|
|
171
|
+
is left out, and the whole row with it.
|
|
172
|
+
- **On a message the person sent**, one **restore** icon ("Restore Checkpoint") at the end of the message, shown when the pointer is over the
|
|
173
|
+
message or the keyboard is on the icon (always shown on a screen with no hover). It puts the widget back to how it was **before that
|
|
174
|
+
message**: the chat asks the page, through `onRestoreCheckpointBackend`, to restore the version of the nearest earlier prompt that made one,
|
|
175
|
+
and then adds the restored prompt and "Restored from Version N" to the list. Only a message that made a version has the icon, and no icon is
|
|
176
|
+
drawn when the page gave no `onRestoreCheckpointBackend`. The first version has nothing before it: while the widget sits on it, its icon undoes
|
|
177
|
+
it (the page decides what that means); once later versions exist it has no icon. After a restore, the next message goes back to the restored version.
|
|
178
|
+
|
|
179
|
+
There is no "You are here" mark: the person is always at the end of the conversation. The `viewingVersion` prop of `Chat` is still accepted and
|
|
180
|
+
ignored, so a page that passes it keeps compiling.
|
|
181
|
+
|
|
164
182
|
### Rating a version
|
|
165
183
|
|
|
166
|
-
|
|
167
|
-
that version is good
|
|
168
|
-
|
|
169
|
-
`down`, or `none` (the person took their rating back).
|
|
184
|
+
At the end of the last message (the reply that announced a change of the widget) the chat can draw two thumbs, so a person can say whether
|
|
185
|
+
that version is good: a thumbs up helps the code generator learn what works, a thumbs down what does not. The thumbs are **opt-in**: give
|
|
186
|
+
`Chat` an `onRateVersion` callback and they appear, leave it out and the chat draws no thumbs. The chat keeps no rating of its own: the page
|
|
187
|
+
decides where a rating goes. A rating is one of three words: `up`, `down`, or `none` (the person took their rating back).
|
|
170
188
|
|
|
171
189
|
```svelte
|
|
172
190
|
<script lang="ts">
|
|
@@ -192,7 +210,7 @@ works as it always did. The chat keeps no rating of its own: the page decides wh
|
|
|
192
210
|
again. What the person pressed in this chat is shown over it. Without it, the thumbs start empty each time the chat opens.
|
|
193
211
|
- Only a version the backend saved can be rated: not a reply still on its way or one that failed, not the copy a restore appends, not the
|
|
194
212
|
stand-in the chat draws while the widget's head is ahead of every saved message, and not a version a restore undid. Nothing is drawn while
|
|
195
|
-
the chat is loading.
|
|
213
|
+
the chat is loading or generating, and the thumbs belong to the last message only.
|
|
196
214
|
- Words: `chat.messages.rateGroup`, `chat.messages.rateUp` and `chat.messages.rateDown` (see [Languages](#languages)).
|
|
197
215
|
|
|
198
216
|
## State Management
|
|
@@ -259,6 +277,16 @@ const customConfig = {
|
|
|
259
277
|
};
|
|
260
278
|
```
|
|
261
279
|
|
|
280
|
+
### Code generation activity (host-driven)
|
|
281
|
+
|
|
282
|
+
While the host runs widget codegen, pass **`isGenerating`**, and optionally **`generationThinking`**,
|
|
283
|
+
**`generationStream`**, and **`generationPlan`**: rolling tails from `operation.metadata.thinkingTail` /
|
|
284
|
+
`thinking_tail` and `streamTail` / `stream_tail`, plus the gateway build plan (`metadata.plan`; `null` hides the
|
|
285
|
+
card). The messages list shows a read-only **`PlanCard`** above one activity card — streamed reasoning first,
|
|
286
|
+
then live code in the same bubble. Parse wire data with **`readGenerationPlanFromMetadata`** from
|
|
287
|
+
`@widgetic/chat`. When **`features.screenshot`** is `false`, the action bar hides the screenshot control;
|
|
288
|
+
ordinary image upload and screen recording are unchanged.
|
|
289
|
+
|
|
262
290
|
## Languages
|
|
263
291
|
|
|
264
292
|
The chat shows English until it is told otherwise. Two props of `Chat` change that, and both can change while the chat
|
|
@@ -302,7 +330,7 @@ console.log(CHAT_MESSAGES['chat.attachment.more']); // '{count, plural, one {+#
|
|
|
302
330
|
| Keys start with | The words of |
|
|
303
331
|
| --- | --- |
|
|
304
332
|
| `chat.header.`, `chat.contextPreview.`, `chat.contextType.`, `chat.conversation.` | the header, the list of conversations, the collapsed chat, the name of what a chat is about ("frame", "text"), and the title of a new conversation |
|
|
305
|
-
| `chat.messages.` | the list of messages: the empty state, "thinking",
|
|
333
|
+
| `chat.messages.` | the list of messages: the empty state, "thinking", the icons (copy, regenerate, restore, thumbs), versions and commit ids |
|
|
306
334
|
| `chat.input.`, `chat.actions.` | the box you type in, and the screenshot, record, upload and "mark complete" buttons |
|
|
307
335
|
| `chat.suggestions.` | the ideas offered to start with (five for each kind of thing a chat is about) and their headings |
|
|
308
336
|
| `chat.attachment.`, `chat.size.` | attachments, and file sizes ("1.5 MB") |
|
|
@@ -247,6 +247,14 @@
|
|
|
247
247
|
pointer-events: none;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/*
|
|
251
|
+
* Nothing to hold: every button is off and the page's extras drew no control (the creator's extras are for debug only, and
|
|
252
|
+
* outside it they are an empty wrapper), so the bar is not drawn at all, instead of an empty strip above the composer.
|
|
253
|
+
*/
|
|
254
|
+
.action-bar:not(:has(button, label, input, select, textarea, a)) {
|
|
255
|
+
display: none;
|
|
256
|
+
}
|
|
257
|
+
|
|
250
258
|
.action-bar-extras {
|
|
251
259
|
display: contents;
|
|
252
260
|
}
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
12
12
|
import type { AttachmentInput, SelectedElementChatReference } from '../types/attachment.js';
|
|
13
13
|
import ChatMessages from './ChatMessages.svelte';
|
|
14
|
-
import
|
|
14
|
+
import ChatComposer, { type ComposerModelOption } from './ChatComposer.svelte';
|
|
15
|
+
import { Chip } from '@widgetic/design-system/components/chat/index';
|
|
15
16
|
import ActionBar from './ActionBar.svelte';
|
|
17
|
+
import PanelChatHeader from './PanelChatHeader.svelte';
|
|
16
18
|
import StatusIndicator from './StatusIndicator.svelte';
|
|
17
19
|
import { provideChatLanguage } from '../i18n/language.js';
|
|
18
20
|
import { actionFailureKey, contextTypeLabel } from '../i18n/labels.js';
|
|
@@ -117,6 +119,12 @@
|
|
|
117
119
|
options?: { onProgress?: (percentage: number) => void; source?: string },
|
|
118
120
|
) => Promise<{ id: string; url: string; fileType: string; fileName: string; fileSize: number }>;
|
|
119
121
|
showHeader?: boolean;
|
|
122
|
+
/** DS panel header (history, new chat, console). Used beside the canvas in the widget creator. */
|
|
123
|
+
showPanelHeader?: boolean;
|
|
124
|
+
/** When true with `onToggleConsole`, shows the debug console icon in the panel header. */
|
|
125
|
+
showConsoleControl?: boolean;
|
|
126
|
+
consoleOpen?: boolean;
|
|
127
|
+
onToggleConsole?: () => void;
|
|
120
128
|
/** Custom title displayed in the header. If empty/undefined, defaults to context.title or context.id. */
|
|
121
129
|
headerTitle?: string;
|
|
122
130
|
/** When false, hides the icon + type description row below the title, making the header compact. */
|
|
@@ -152,12 +160,19 @@
|
|
|
152
160
|
versionLabelByPrompt?: Record<string, string>;
|
|
153
161
|
/** Saved versions, so a prompt that produced two commits can show two turns. */
|
|
154
162
|
versionTimeline?: Array<{ version: number; sha: string; prompt: string }>;
|
|
155
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated The chat no longer marks one version as "you are here" (the person is always at the end of the conversation).
|
|
165
|
+
* Still accepted, so a host that passes it keeps compiling; it is ignored.
|
|
166
|
+
*/
|
|
156
167
|
viewingVersion?: number | null;
|
|
157
168
|
/** Host is running widget codegen — send button becomes stop. */
|
|
158
169
|
isGenerating?: boolean;
|
|
159
170
|
/** Tail of the model stream while codegen is in flight. */
|
|
160
171
|
generationStream?: string;
|
|
172
|
+
/** Rolling tail of streamed model reasoning while codegen is in flight. */
|
|
173
|
+
generationThinking?: string;
|
|
174
|
+
/** Gateway build plan (`operation.metadata.plan`), or `null` to hide the plan card. */
|
|
175
|
+
generationPlan?: import('../utils/generationPlan.js').GenerationPlanWire | null;
|
|
161
176
|
onStopGeneration?: () => void;
|
|
162
177
|
/**
|
|
163
178
|
* Renders the inline design-control card attached to an assistant reply
|
|
@@ -192,6 +207,10 @@
|
|
|
192
207
|
onRemoveSelectedElement?: (elementId: string) => void;
|
|
193
208
|
/** Fired when all selected widget elements should be cleared (e.g. after sending). */
|
|
194
209
|
onClearSelectedElements?: () => void;
|
|
210
|
+
/** Model list for the DS composer Assistant menu; hidden when empty. */
|
|
211
|
+
composerModels?: ComposerModelOption[];
|
|
212
|
+
selectedComposerModelId?: string | null;
|
|
213
|
+
onSelectComposerModel?: (modelId: string) => void;
|
|
195
214
|
}
|
|
196
215
|
|
|
197
216
|
// Expose methods to parent component
|
|
@@ -231,7 +250,7 @@
|
|
|
231
250
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
232
251
|
}
|
|
233
252
|
|
|
234
|
-
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, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [],
|
|
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();
|
|
235
254
|
|
|
236
255
|
// The words of everything inside the chat, in the language the page chose. The page can change the language while the
|
|
237
256
|
// chat is open: the settings are read again whenever they change (and setting the same language again does nothing).
|
|
@@ -271,7 +290,20 @@
|
|
|
271
290
|
}
|
|
272
291
|
|
|
273
292
|
const promptVersionLabels = $derived(versionLabelByPrompt ?? {});
|
|
274
|
-
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The action bar holds what the composer does not do itself: screenshot, recording, the element selector, completion and
|
|
296
|
+
* whatever the page adds. Attaching a file is the "+" of the composer (Figma), so a page that turns all of those off
|
|
297
|
+
* (the creator) has no bar above its composer.
|
|
298
|
+
*/
|
|
299
|
+
const showActionBar = $derived(
|
|
300
|
+
config?.features?.screenshot !== false ||
|
|
301
|
+
config?.features?.screenRecording !== false ||
|
|
302
|
+
!!showSelector ||
|
|
303
|
+
config?.features?.markComplete !== false ||
|
|
304
|
+
!!actionBarExtras ||
|
|
305
|
+
!!(replaceComplete && completeReplacement)
|
|
306
|
+
);
|
|
275
307
|
|
|
276
308
|
// Apply log suppression immediately
|
|
277
309
|
$effect(() => {
|
|
@@ -293,6 +325,12 @@
|
|
|
293
325
|
let localIsSending = $state(false);
|
|
294
326
|
let localIsUploading = $state(false);
|
|
295
327
|
|
|
328
|
+
// The host hears about the draft when the person types (the setter of the composer binding below), not from an
|
|
329
|
+
// effect: an effect would call the host's callback inside its own tracking, and every piece of host state the
|
|
330
|
+
// callback reads would become a dependency of this effect. The creator's callback reads and writes the panel
|
|
331
|
+
// snapshots, so that made an update loop that froze the page for seconds. A text the host sets itself
|
|
332
|
+
// (setDraftText) is not announced back to it, as before.
|
|
333
|
+
|
|
296
334
|
// Reactive state from store - using proper store subscription initialized synchronously
|
|
297
335
|
let chatState = $state<any>(getCurrentState());
|
|
298
336
|
let storeUnsubscribe: (() => void) | null = null;
|
|
@@ -337,20 +375,6 @@
|
|
|
337
375
|
return !!list && (list as { hasOlder?: boolean }).hasOlder === true;
|
|
338
376
|
}
|
|
339
377
|
|
|
340
|
-
function loadedMessagesCoverVersion(version: number): boolean {
|
|
341
|
-
const entry = (versionTimeline || []).find((row) => row.version === version);
|
|
342
|
-
if (!entry) return true;
|
|
343
|
-
const sha = (entry.sha || '').slice(0, 7).toLowerCase();
|
|
344
|
-
const prompt = (entry.prompt || '').trim();
|
|
345
|
-
if (!sha && !prompt) return true;
|
|
346
|
-
const list = currentConversationId ? getCurrentMessages(currentConversationId) : [];
|
|
347
|
-
return list.some((message) => {
|
|
348
|
-
const text = message.messageContent || '';
|
|
349
|
-
if (sha && text.toLowerCase().includes(sha)) return true;
|
|
350
|
-
return !!prompt && text.trim() === prompt;
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
378
|
async function loadOlderMessages(): Promise<boolean> {
|
|
355
379
|
if (!currentConversationId || !onLoadOlderMessages || loadingOlderMessages || !hasOlderMessages) return false;
|
|
356
380
|
loadingOlderMessages = true;
|
|
@@ -375,27 +399,6 @@
|
|
|
375
399
|
}
|
|
376
400
|
}
|
|
377
401
|
|
|
378
|
-
let versionPageToken = 0;
|
|
379
|
-
$effect(() => {
|
|
380
|
-
const version = selectedViewingVersion;
|
|
381
|
-
const id = currentConversationId;
|
|
382
|
-
if (version == null || !id || !hasOlderMessages) return;
|
|
383
|
-
if (loadedMessagesCoverVersion(version)) return;
|
|
384
|
-
const token = ++versionPageToken;
|
|
385
|
-
void (async () => {
|
|
386
|
-
let guard = 0;
|
|
387
|
-
while (
|
|
388
|
-
token === versionPageToken
|
|
389
|
-
&& guard < 20
|
|
390
|
-
&& hasOlderMessages
|
|
391
|
-
&& !loadedMessagesCoverVersion(version)
|
|
392
|
-
) {
|
|
393
|
-
guard += 1;
|
|
394
|
-
const loaded = await loadOlderMessages();
|
|
395
|
-
if (!loaded) break;
|
|
396
|
-
}
|
|
397
|
-
})();
|
|
398
|
-
});
|
|
399
402
|
let availableConversations = $derived(
|
|
400
403
|
context && conversations ? conversations.byContextId[context.id] || [] : []
|
|
401
404
|
);
|
|
@@ -1917,11 +1920,20 @@
|
|
|
1917
1920
|
|
|
1918
1921
|
<div
|
|
1919
1922
|
bind:this={chatContainer}
|
|
1920
|
-
class="{className ? className : 'prompt-chat-ct'} relative flex flex-col overflow-hidden
|
|
1923
|
+
class="{className ? className : 'prompt-chat-ct'} border-border bg-background relative flex h-full min-h-0 w-chat-panel max-w-full flex-col overflow-hidden border {className ? '' : 'rounded-panel'}"
|
|
1921
1924
|
dir={$textDirection}
|
|
1922
1925
|
style={style}
|
|
1923
1926
|
>
|
|
1924
|
-
{#if
|
|
1927
|
+
{#if showPanelHeader}
|
|
1928
|
+
<PanelChatHeader
|
|
1929
|
+
title={headerTitle || context.title || context.id}
|
|
1930
|
+
showConsole={showConsoleControl}
|
|
1931
|
+
{consoleOpen}
|
|
1932
|
+
onToggleConsole={onToggleConsole}
|
|
1933
|
+
onNewConversation={onCreateConversation || onLoadConversations ? () => void createNewConversation() : undefined}
|
|
1934
|
+
onOpenHistory={onLoadConversations ? () => void loadConversations() : undefined}
|
|
1935
|
+
/>
|
|
1936
|
+
{:else if showHeader}
|
|
1925
1937
|
<!-- Simple Chat Header -->
|
|
1926
1938
|
<div class="prompt-chat-header {showDescriptionHeader ? 'p-4' : 'px-4 py-2'} border-b border-gray-200 bg-gray-50">
|
|
1927
1939
|
<div class="flex items-center gap-3">
|
|
@@ -1972,14 +1984,15 @@
|
|
|
1972
1984
|
versionLabelByCommitSha={versionLabelByCommitSha}
|
|
1973
1985
|
versionLabelByPrompt={promptVersionLabels}
|
|
1974
1986
|
{versionTimeline}
|
|
1975
|
-
viewingVersion={selectedViewingVersion}
|
|
1976
1987
|
{hasOlderMessages}
|
|
1977
1988
|
onRequestOlderMessages={() => loadOlderMessages()}
|
|
1978
1989
|
showCommitMeta={showLogs}
|
|
1979
1990
|
isGenerating={isGenerating || isLoading}
|
|
1980
1991
|
generationStream={isGenerating ? generationStream : ''}
|
|
1992
|
+
generationThinking={isGenerating ? generationThinking : ''}
|
|
1993
|
+
generationPlan={isGenerating ? generationPlan : null}
|
|
1981
1994
|
onSuggestionSelected={handleSuggestionSelected}
|
|
1982
|
-
onRestoreCheckpoint={handleRestoreCheckpoint}
|
|
1995
|
+
onRestoreCheckpoint={onRestoreCheckpointBackend ? handleRestoreCheckpoint : undefined}
|
|
1983
1996
|
onRateVersion={onRateVersion ? handleRateVersion : undefined}
|
|
1984
1997
|
versionRatings={shownVersionRatings}
|
|
1985
1998
|
onRetryMessage={handleRetryMessage}
|
|
@@ -2005,6 +2018,7 @@
|
|
|
2005
2018
|
</div>
|
|
2006
2019
|
|
|
2007
2020
|
<div class="prompt-chat-footer-ct shrink-0 flex flex-col">
|
|
2021
|
+
{#if showActionBar}
|
|
2008
2022
|
<ActionBar
|
|
2009
2023
|
{context}
|
|
2010
2024
|
conversationId={currentConversationId}
|
|
@@ -2013,7 +2027,7 @@
|
|
|
2013
2027
|
disabled={isLoading}
|
|
2014
2028
|
showScreenshot={config?.features?.screenshot !== false}
|
|
2015
2029
|
showRecord={config?.features?.screenRecording !== false}
|
|
2016
|
-
showUpload={
|
|
2030
|
+
showUpload={false}
|
|
2017
2031
|
{showSelector}
|
|
2018
2032
|
{isSelectorActive}
|
|
2019
2033
|
showComplete={config?.features?.markComplete !== false}
|
|
@@ -2031,6 +2045,7 @@
|
|
|
2031
2045
|
{@render actionBarExtras()}
|
|
2032
2046
|
{/if}
|
|
2033
2047
|
</ActionBar>
|
|
2048
|
+
{/if}
|
|
2034
2049
|
{#if composerExtras}
|
|
2035
2050
|
<div class="prompt-chat-generation-options shrink-0 flex flex-col" bind:this={generationOptionsEl}>
|
|
2036
2051
|
{@render composerExtras()}
|
|
@@ -2043,44 +2058,22 @@
|
|
|
2043
2058
|
data-testid="chat-selected-elements-tray"
|
|
2044
2059
|
>
|
|
2045
2060
|
{#each selectedElements as item, index (item.id)}
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
{
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
<span class="text-gray-400">·</span>
|
|
2063
|
-
<span class="max-w-[180px] truncate text-[11px] text-gray-600">
|
|
2064
|
-
{item.textSnippet}
|
|
2065
|
-
</span>
|
|
2066
|
-
{:else if item.selector}
|
|
2067
|
-
<span class="text-gray-400">·</span>
|
|
2068
|
-
<span class="max-w-[160px] truncate font-mono text-[10px] text-gray-500">
|
|
2069
|
-
{item.selector}
|
|
2070
|
-
</span>
|
|
2071
|
-
{/if}
|
|
2072
|
-
{#if onRemoveSelectedElement}
|
|
2073
|
-
<button
|
|
2074
|
-
type="button"
|
|
2075
|
-
class="ms-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-gray-400 hover:bg-gray-200 hover:text-gray-700 cursor-pointer"
|
|
2076
|
-
onclick={() => onRemoveSelectedElement?.(item.id)}
|
|
2077
|
-
title={$t('chat.selector.removeElement')}
|
|
2078
|
-
aria-label={$t('chat.selector.removeElement')}
|
|
2079
|
-
>
|
|
2080
|
-
✕
|
|
2081
|
-
</button>
|
|
2082
|
-
{/if}
|
|
2083
|
-
</div>
|
|
2061
|
+
{@const chipLabel = `<${item.tagName}${item.idAttr ? `#${item.idAttr}` : ''}>${item.note?.trim() ? ` · ${item.note.trim()}` : item.textSnippet ? ` · ${item.textSnippet}` : item.selector ? ` · ${item.selector}` : ''}`}
|
|
2062
|
+
<span class="prompt-chat-selected-element-chip max-w-full" title={item.selector} data-testid="chat-selected-element-chip">
|
|
2063
|
+
<Chip
|
|
2064
|
+
class="max-w-full"
|
|
2065
|
+
label={chipLabel}
|
|
2066
|
+
showRemove={!!onRemoveSelectedElement}
|
|
2067
|
+
removeLabel={$t('chat.selector.removeElement')}
|
|
2068
|
+
onRemove={() => onRemoveSelectedElement?.(item.id)}
|
|
2069
|
+
>
|
|
2070
|
+
{#snippet leading()}
|
|
2071
|
+
<span class="bg-primary text-primary-foreground flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-[10px] font-bold">
|
|
2072
|
+
{index + 1}
|
|
2073
|
+
</span>
|
|
2074
|
+
{/snippet}
|
|
2075
|
+
</Chip>
|
|
2076
|
+
</span>
|
|
2084
2077
|
{/each}
|
|
2085
2078
|
{#if selectedElements.length > 1 && onClearSelectedElements}
|
|
2086
2079
|
<button
|
|
@@ -2137,31 +2130,25 @@
|
|
|
2137
2130
|
</div>
|
|
2138
2131
|
{/if}
|
|
2139
2132
|
|
|
2140
|
-
<
|
|
2141
|
-
value={localInputText
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2133
|
+
<ChatComposer
|
|
2134
|
+
bind:value={() => localInputText, (nextInputText) => {
|
|
2135
|
+
localInputText = nextInputText;
|
|
2136
|
+
notifyDraftChange();
|
|
2137
|
+
}}
|
|
2145
2138
|
isSending={localIsSending}
|
|
2146
|
-
isUploading={localIsUploading}
|
|
2147
2139
|
isGenerating={isGenerating || isLoading}
|
|
2140
|
+
models={composerModels}
|
|
2141
|
+
selectedModelId={selectedComposerModelId}
|
|
2142
|
+
onSelectModel={onSelectComposerModel}
|
|
2148
2143
|
onStop={() => onStopGeneration?.()}
|
|
2149
|
-
onSend={(content
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
onInputChange={(text) => {
|
|
2153
|
-
// chatLog('Input change for chat', context.id, ':', text);
|
|
2154
|
-
localInputText = text;
|
|
2155
|
-
notifyDraftChange();
|
|
2156
|
-
}}
|
|
2157
|
-
onAttachmentsChange={(attachments) => {
|
|
2158
|
-
// chatLog('Attachments change for chat', context.id, ':', attachments.length);
|
|
2159
|
-
localAttachments = attachments;
|
|
2160
|
-
notifyDraftChange();
|
|
2144
|
+
onSend={(content) => {
|
|
2145
|
+
const attachmentInputs = localAttachments.length > 0 ? localAttachments : undefined;
|
|
2146
|
+
void sendMessage(content, attachmentInputs);
|
|
2161
2147
|
}}
|
|
2162
2148
|
onFilesDropped={(files) => {
|
|
2163
2149
|
void addFilesAsAttachments(files);
|
|
2164
2150
|
}}
|
|
2151
|
+
onAttach={config?.features?.fileUpload !== false ? () => void handleUpload() : undefined}
|
|
2165
2152
|
canSendWithoutText={(selectedElements ?? []).some((element) => !!element.note?.trim())}
|
|
2166
2153
|
/>
|
|
2167
2154
|
</div>
|
|
@@ -3,6 +3,7 @@ import { type TextDirection } from '@widgetic/design-system/components/textDirec
|
|
|
3
3
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
4
4
|
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
5
5
|
import type { AttachmentInput, SelectedElementChatReference } from '../types/attachment.js';
|
|
6
|
+
import { type ComposerModelOption } from './ChatComposer.svelte';
|
|
6
7
|
interface ChatMethods {
|
|
7
8
|
sendMessage: (content: string, attachments?: Array<File | AttachmentInput>, options?: {
|
|
8
9
|
skipIntentGate?: boolean;
|
|
@@ -155,6 +156,12 @@ interface Props {
|
|
|
155
156
|
fileSize: number;
|
|
156
157
|
}>;
|
|
157
158
|
showHeader?: boolean;
|
|
159
|
+
/** DS panel header (history, new chat, console). Used beside the canvas in the widget creator. */
|
|
160
|
+
showPanelHeader?: boolean;
|
|
161
|
+
/** When true with `onToggleConsole`, shows the debug console icon in the panel header. */
|
|
162
|
+
showConsoleControl?: boolean;
|
|
163
|
+
consoleOpen?: boolean;
|
|
164
|
+
onToggleConsole?: () => void;
|
|
158
165
|
/** Custom title displayed in the header. If empty/undefined, defaults to context.title or context.id. */
|
|
159
166
|
headerTitle?: string;
|
|
160
167
|
/** When false, hides the icon + type description row below the title, making the header compact. */
|
|
@@ -194,12 +201,19 @@ interface Props {
|
|
|
194
201
|
sha: string;
|
|
195
202
|
prompt: string;
|
|
196
203
|
}>;
|
|
197
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* @deprecated The chat no longer marks one version as "you are here" (the person is always at the end of the conversation).
|
|
206
|
+
* Still accepted, so a host that passes it keeps compiling; it is ignored.
|
|
207
|
+
*/
|
|
198
208
|
viewingVersion?: number | null;
|
|
199
209
|
/** Host is running widget codegen — send button becomes stop. */
|
|
200
210
|
isGenerating?: boolean;
|
|
201
211
|
/** Tail of the model stream while codegen is in flight. */
|
|
202
212
|
generationStream?: string;
|
|
213
|
+
/** Rolling tail of streamed model reasoning while codegen is in flight. */
|
|
214
|
+
generationThinking?: string;
|
|
215
|
+
/** Gateway build plan (`operation.metadata.plan`), or `null` to hide the plan card. */
|
|
216
|
+
generationPlan?: import('../utils/generationPlan.js').GenerationPlanWire | null;
|
|
203
217
|
onStopGeneration?: () => void;
|
|
204
218
|
/**
|
|
205
219
|
* Renders the inline design-control card attached to an assistant reply
|
|
@@ -234,6 +248,10 @@ interface Props {
|
|
|
234
248
|
onRemoveSelectedElement?: (elementId: string) => void;
|
|
235
249
|
/** Fired when all selected widget elements should be cleared (e.g. after sending). */
|
|
236
250
|
onClearSelectedElements?: () => void;
|
|
251
|
+
/** Model list for the DS composer Assistant menu; hidden when empty. */
|
|
252
|
+
composerModels?: ComposerModelOption[];
|
|
253
|
+
selectedComposerModelId?: string | null;
|
|
254
|
+
onSelectComposerModel?: (modelId: string) => void;
|
|
237
255
|
}
|
|
238
256
|
declare const Chat: import("svelte").Component<Props, {}, "">;
|
|
239
257
|
type Chat = ReturnType<typeof Chat>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
3
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
4
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
5
|
+
import { Composer, IconButton } from '@widgetic/design-system/components/chat/index';
|
|
6
|
+
import { chatLog } from '../utils/logger.js';
|
|
7
|
+
|
|
8
|
+
const { t } = useChatLanguage();
|
|
9
|
+
const textDirection = useTextDirection();
|
|
10
|
+
|
|
11
|
+
export type ComposerModelOption = { id: string; label: string };
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
value?: string;
|
|
15
|
+
isSending?: boolean;
|
|
16
|
+
isGenerating?: boolean;
|
|
17
|
+
canSendWithoutText?: boolean;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
style?: string;
|
|
21
|
+
models?: ComposerModelOption[];
|
|
22
|
+
selectedModelId?: string | null;
|
|
23
|
+
onSelectModel?: (modelId: string) => void;
|
|
24
|
+
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
25
|
+
onStop?: () => void;
|
|
26
|
+
onInputChange?: (text: string) => void;
|
|
27
|
+
onFilesDropped?: (files: File[]) => void;
|
|
28
|
+
/** Opens the file picker. The "+" of the toolbar is drawn only when the page can attach files. */
|
|
29
|
+
onAttach?: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
value = $bindable(),
|
|
34
|
+
isSending = false,
|
|
35
|
+
isGenerating = false,
|
|
36
|
+
canSendWithoutText = false,
|
|
37
|
+
placeholder,
|
|
38
|
+
class: className = '',
|
|
39
|
+
style = '',
|
|
40
|
+
models = [],
|
|
41
|
+
selectedModelId = null,
|
|
42
|
+
onSelectModel,
|
|
43
|
+
onSend,
|
|
44
|
+
onStop,
|
|
45
|
+
onInputChange,
|
|
46
|
+
onFilesDropped,
|
|
47
|
+
onAttach
|
|
48
|
+
}: Props = $props();
|
|
49
|
+
|
|
50
|
+
let isFileDragOver = $state(false);
|
|
51
|
+
|
|
52
|
+
const busy = $derived(isGenerating || isSending);
|
|
53
|
+
const allowEmptySend = $derived(canSendWithoutText);
|
|
54
|
+
|
|
55
|
+
function isOsFileDrag(event: DragEvent): boolean {
|
|
56
|
+
return !!event.dataTransfer?.types?.includes('Files');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleFileDragEnter(event: DragEvent) {
|
|
60
|
+
if (!isOsFileDrag(event)) return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
isFileDragOver = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleFileDragOver(event: DragEvent) {
|
|
66
|
+
if (!isOsFileDrag(event)) return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
|
|
69
|
+
isFileDragOver = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleFileDragLeave(event: DragEvent) {
|
|
73
|
+
if (!isOsFileDrag(event)) return;
|
|
74
|
+
const related = event.relatedTarget as Node | null;
|
|
75
|
+
if (related && (event.currentTarget as HTMLElement).contains(related)) return;
|
|
76
|
+
isFileDragOver = false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function handleFileDrop(event: DragEvent) {
|
|
80
|
+
if (!isOsFileDrag(event)) return;
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
isFileDragOver = false;
|
|
84
|
+
const droppedFiles = Array.from(event.dataTransfer?.files || []).filter((file) => file && file.size > 0);
|
|
85
|
+
if (droppedFiles.length === 0) return;
|
|
86
|
+
chatLog('[ChatComposer] OS files dropped:', droppedFiles.length);
|
|
87
|
+
onFilesDropped?.(droppedFiles);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function handleComposerSend(text: string) {
|
|
91
|
+
const trimmed = text.trim();
|
|
92
|
+
if (!trimmed && !allowEmptySend) return;
|
|
93
|
+
if (isSending && !isGenerating) return;
|
|
94
|
+
onSend(trimmed, undefined);
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<!-- Figma: Composer toolbar, left side: attach ("+"), then the mode. -->
|
|
99
|
+
{#snippet attachControl()}
|
|
100
|
+
{#if onAttach}
|
|
101
|
+
<IconButton
|
|
102
|
+
variant="ghost"
|
|
103
|
+
label={$t('chat.actions.uploadLabel')}
|
|
104
|
+
disabled={isSending && !isGenerating}
|
|
105
|
+
onclick={() => onAttach?.()}
|
|
106
|
+
>
|
|
107
|
+
<svg
|
|
108
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
109
|
+
class="size-4 stroke-2"
|
|
110
|
+
viewBox="0 0 24 24"
|
|
111
|
+
fill="none"
|
|
112
|
+
stroke="currentColor"
|
|
113
|
+
stroke-linecap="round"
|
|
114
|
+
stroke-linejoin="round"
|
|
115
|
+
aria-hidden="true"
|
|
116
|
+
>
|
|
117
|
+
<path d="M12 5l0 14" />
|
|
118
|
+
<path d="M5 12l14 0" />
|
|
119
|
+
</svg>
|
|
120
|
+
</IconButton>
|
|
121
|
+
{/if}
|
|
122
|
+
{/snippet}
|
|
123
|
+
|
|
124
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
125
|
+
<div
|
|
126
|
+
class="chat-composer-shell border-border bg-background shrink-0 border-t {className} {isFileDragOver
|
|
127
|
+
? 'outline-primary outline-2 outline-dashed'
|
|
128
|
+
: ''}"
|
|
129
|
+
{style}
|
|
130
|
+
ondragenter={handleFileDragEnter}
|
|
131
|
+
ondragover={handleFileDragOver}
|
|
132
|
+
ondragleave={handleFileDragLeave}
|
|
133
|
+
ondrop={handleFileDrop}
|
|
134
|
+
>
|
|
135
|
+
<Composer
|
|
136
|
+
class="rounded-none border-0"
|
|
137
|
+
bind:value
|
|
138
|
+
busy={isGenerating}
|
|
139
|
+
disabled={isSending && !isGenerating}
|
|
140
|
+
allowEmpty={allowEmptySend}
|
|
141
|
+
placeholder={placeholder ?? $t('chat.input.placeholder')}
|
|
142
|
+
{models}
|
|
143
|
+
{selectedModelId}
|
|
144
|
+
onSelectModel={onSelectModel}
|
|
145
|
+
messages={{
|
|
146
|
+
send: $t('chat.input.send'),
|
|
147
|
+
stop: $t('chat.input.stop'),
|
|
148
|
+
attach: $t('chat.actions.upload'),
|
|
149
|
+
characterLimit: $t('chat.input.tooLong')
|
|
150
|
+
}}
|
|
151
|
+
assistantLabel={$t('chat.composer.assistant')}
|
|
152
|
+
onSend={handleComposerSend}
|
|
153
|
+
onStop={() => onStop?.()}
|
|
154
|
+
leading={attachControl}
|
|
155
|
+
/>
|
|
156
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
2
|
+
export type ComposerModelOption = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
interface Props {
|
|
7
|
+
value?: string;
|
|
8
|
+
isSending?: boolean;
|
|
9
|
+
isGenerating?: boolean;
|
|
10
|
+
canSendWithoutText?: boolean;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
style?: string;
|
|
14
|
+
models?: ComposerModelOption[];
|
|
15
|
+
selectedModelId?: string | null;
|
|
16
|
+
onSelectModel?: (modelId: string) => void;
|
|
17
|
+
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
18
|
+
onStop?: () => void;
|
|
19
|
+
onInputChange?: (text: string) => void;
|
|
20
|
+
onFilesDropped?: (files: File[]) => void;
|
|
21
|
+
/** Opens the file picker. The "+" of the toolbar is drawn only when the page can attach files. */
|
|
22
|
+
onAttach?: () => void;
|
|
23
|
+
}
|
|
24
|
+
declare const ChatComposer: import("svelte").Component<Props, {}, "value">;
|
|
25
|
+
type ChatComposer = ReturnType<typeof ChatComposer>;
|
|
26
|
+
export default ChatComposer;
|