@widgetic/chat 0.1.34 → 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 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
- Next to the name of each version (the reply that announced a change of the widget) the chat can draw two thumbs, so a person can say whether
167
- that version is good. The thumbs are **opt-in**: give `Chat` an `onRateVersion` callback and they appear, leave it out and the chat looks and
168
- works as it always did. The chat keeps no rating of its own: the page decides where a rating goes. A rating is one of three words: `up`,
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", checkpoints, "You are here", versions and commit ids |
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 ChatInput from './ChatInput.svelte';
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
- /** Version selected in the dropdown. You-are-here follows this number. */
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 = [], viewingVersion = null, isGenerating = false, generationStream = '', onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel }: Props = $props();
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
- const selectedViewingVersion = $derived(viewingVersion ?? null);
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(() => {
@@ -281,6 +313,8 @@
281
313
  // Local state
282
314
  let chatContainer: HTMLElement;
283
315
  let isInitialized = $state(false);
316
+ /** Suggestions stay hidden from the first paint. Turned on only after the message read, and only when it was empty. */
317
+ let showEmptyState = $state(false);
284
318
  let chatService = $state(createChatService());
285
319
  let currentConversationId = $state<string | null>(null);
286
320
 
@@ -291,6 +325,12 @@
291
325
  let localIsSending = $state(false);
292
326
  let localIsUploading = $state(false);
293
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
+
294
334
  // Reactive state from store - using proper store subscription initialized synchronously
295
335
  let chatState = $state<any>(getCurrentState());
296
336
  let storeUnsubscribe: (() => void) | null = null;
@@ -335,20 +375,6 @@
335
375
  return !!list && (list as { hasOlder?: boolean }).hasOlder === true;
336
376
  }
337
377
 
338
- function loadedMessagesCoverVersion(version: number): boolean {
339
- const entry = (versionTimeline || []).find((row) => row.version === version);
340
- if (!entry) return true;
341
- const sha = (entry.sha || '').slice(0, 7).toLowerCase();
342
- const prompt = (entry.prompt || '').trim();
343
- if (!sha && !prompt) return true;
344
- const list = currentConversationId ? getCurrentMessages(currentConversationId) : [];
345
- return list.some((message) => {
346
- const text = message.messageContent || '';
347
- if (sha && text.toLowerCase().includes(sha)) return true;
348
- return !!prompt && text.trim() === prompt;
349
- });
350
- }
351
-
352
378
  async function loadOlderMessages(): Promise<boolean> {
353
379
  if (!currentConversationId || !onLoadOlderMessages || loadingOlderMessages || !hasOlderMessages) return false;
354
380
  loadingOlderMessages = true;
@@ -373,27 +399,6 @@
373
399
  }
374
400
  }
375
401
 
376
- let versionPageToken = 0;
377
- $effect(() => {
378
- const version = selectedViewingVersion;
379
- const id = currentConversationId;
380
- if (version == null || !id || !hasOlderMessages) return;
381
- if (loadedMessagesCoverVersion(version)) return;
382
- const token = ++versionPageToken;
383
- void (async () => {
384
- let guard = 0;
385
- while (
386
- token === versionPageToken
387
- && guard < 20
388
- && hasOlderMessages
389
- && !loadedMessagesCoverVersion(version)
390
- ) {
391
- guard += 1;
392
- const loaded = await loadOlderMessages();
393
- if (!loaded) break;
394
- }
395
- })();
396
- });
397
402
  let availableConversations = $derived(
398
403
  context && conversations ? conversations.byContextId[context.id] || [] : []
399
404
  );
@@ -452,27 +457,43 @@
452
457
  }
453
458
 
454
459
  let lastLoadedContextId = $state('');
460
+ let contextInitToken = 0;
455
461
 
456
462
  async function initializeForContext(contextId: string) {
457
463
  if (!contextId) return;
464
+ const token = ++contextInitToken;
458
465
  lastLoadedContextId = contextId;
459
- // chatLog('[Chat] Initializing with context:', contextId);
460
- chatStore.actions.setActiveContext(contextId, true);
466
+ // Hidden until this read finishes, so suggestion chips do not flash over a conversation that has messages.
467
+ isInitialized = false;
468
+ showEmptyState = false;
469
+ let conversationWasRead = false;
470
+ try {
471
+ // chatLog('[Chat] Initializing with context:', contextId);
472
+ chatStore.actions.setActiveContext(contextId, true);
461
473
 
462
- const loaded = await loadConversations();
463
- if (loaded === null) {
464
- showLoadFailure('chat.error.loadHistory');
465
- return;
466
- }
474
+ const loaded = await loadConversations();
475
+ if (token !== contextInitToken) return;
476
+ if (loaded === null) {
477
+ showLoadFailure('chat.error.loadHistory');
478
+ return;
479
+ }
467
480
 
468
- if (loaded.length === 0) {
469
- // chatLog('[Chat] No existing conversations, creating new one');
470
- await createNewConversation();
471
- } else {
472
- // chatLog('[Chat] Selecting from', loaded.length, 'conversation(s)');
473
- await activateBestConversation(loaded);
481
+ if (loaded.length === 0) {
482
+ // chatLog('[Chat] No existing conversations, creating new one');
483
+ await createNewConversation();
484
+ } else {
485
+ // chatLog('[Chat] Selecting from', loaded.length, 'conversation(s)');
486
+ await activateBestConversation(loaded);
487
+ }
488
+ conversationWasRead = true;
489
+ // chatLog('[Chat] Initialized successfully');
490
+ } finally {
491
+ if (token !== contextInitToken) return;
492
+ const loadedMessages = currentConversationId ? (getCurrentMessages(currentConversationId) ?? []) : [];
493
+ // Only the read that just finished may show suggestions, and only when it stored no messages.
494
+ showEmptyState = conversationWasRead && loadedMessages.length === 0;
495
+ isInitialized = true;
474
496
  }
475
- // chatLog('[Chat] Initialized successfully');
476
497
  }
477
498
 
478
499
  async function retryLoadHistory() {
@@ -1680,6 +1701,8 @@
1680
1701
  /** Reload messages from backend and re-mark widget HEAD (picks up server-persisted summaries). */
1681
1702
  async function reloadConversationMessages() {
1682
1703
  if (!currentConversationId || !onLoadMessages) return;
1704
+ const conversationId = currentConversationId;
1705
+ showEmptyState = false;
1683
1706
  try {
1684
1707
  const localMsgs = getCurrentMessages(currentConversationId);
1685
1708
  const localHasHead = localMsgs.some((m) => m.isWidgetHead || messageHasWidgetCommit(m.messageContent));
@@ -1713,6 +1736,10 @@
1713
1736
  // chatLog('[Chat] Reloaded conversation messages:', loaded?.length ?? 0);
1714
1737
  } catch (err) {
1715
1738
  chatWarn('[Chat] Failed to reload conversation messages:', err);
1739
+ } finally {
1740
+ if (currentConversationId !== conversationId) return;
1741
+ const loadedCount = getCurrentMessages(conversationId)?.length ?? 0;
1742
+ showEmptyState = loadedCount === 0;
1716
1743
  }
1717
1744
  }
1718
1745
 
@@ -1893,11 +1920,20 @@
1893
1920
 
1894
1921
  <div
1895
1922
  bind:this={chatContainer}
1896
- class="{className ? className : 'prompt-chat-ct'} relative flex flex-col overflow-hidden bg-white border border-gray-300 {className ? '' : 'rounded-medium'} h-full min-h-0"
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'}"
1897
1924
  dir={$textDirection}
1898
1925
  style={style}
1899
1926
  >
1900
- {#if showHeader}
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}
1901
1937
  <!-- Simple Chat Header -->
1902
1938
  <div class="prompt-chat-header {showDescriptionHeader ? 'p-4' : 'px-4 py-2'} border-b border-gray-200 bg-gray-50">
1903
1939
  <div class="flex items-center gap-3">
@@ -1939,6 +1975,7 @@
1939
1975
  messages={currentMessages || []}
1940
1976
  isLoading={isLoading}
1941
1977
  isInitialized={isInitialized}
1978
+ {showEmptyState}
1942
1979
  {context}
1943
1980
  isCompleted={isCompleted}
1944
1981
  enableAutoCodeDetection={config?.features?.autoCodeDetection === true}
@@ -1947,14 +1984,15 @@
1947
1984
  versionLabelByCommitSha={versionLabelByCommitSha}
1948
1985
  versionLabelByPrompt={promptVersionLabels}
1949
1986
  {versionTimeline}
1950
- viewingVersion={selectedViewingVersion}
1951
1987
  {hasOlderMessages}
1952
1988
  onRequestOlderMessages={() => loadOlderMessages()}
1953
1989
  showCommitMeta={showLogs}
1954
1990
  isGenerating={isGenerating || isLoading}
1955
1991
  generationStream={isGenerating ? generationStream : ''}
1992
+ generationThinking={isGenerating ? generationThinking : ''}
1993
+ generationPlan={isGenerating ? generationPlan : null}
1956
1994
  onSuggestionSelected={handleSuggestionSelected}
1957
- onRestoreCheckpoint={handleRestoreCheckpoint}
1995
+ onRestoreCheckpoint={onRestoreCheckpointBackend ? handleRestoreCheckpoint : undefined}
1958
1996
  onRateVersion={onRateVersion ? handleRateVersion : undefined}
1959
1997
  versionRatings={shownVersionRatings}
1960
1998
  onRetryMessage={handleRetryMessage}
@@ -1980,6 +2018,7 @@
1980
2018
  </div>
1981
2019
 
1982
2020
  <div class="prompt-chat-footer-ct shrink-0 flex flex-col">
2021
+ {#if showActionBar}
1983
2022
  <ActionBar
1984
2023
  {context}
1985
2024
  conversationId={currentConversationId}
@@ -1988,7 +2027,7 @@
1988
2027
  disabled={isLoading}
1989
2028
  showScreenshot={config?.features?.screenshot !== false}
1990
2029
  showRecord={config?.features?.screenRecording !== false}
1991
- showUpload={config?.features?.fileUpload !== false}
2030
+ showUpload={false}
1992
2031
  {showSelector}
1993
2032
  {isSelectorActive}
1994
2033
  showComplete={config?.features?.markComplete !== false}
@@ -2006,6 +2045,7 @@
2006
2045
  {@render actionBarExtras()}
2007
2046
  {/if}
2008
2047
  </ActionBar>
2048
+ {/if}
2009
2049
  {#if composerExtras}
2010
2050
  <div class="prompt-chat-generation-options shrink-0 flex flex-col" bind:this={generationOptionsEl}>
2011
2051
  {@render composerExtras()}
@@ -2018,44 +2058,22 @@
2018
2058
  data-testid="chat-selected-elements-tray"
2019
2059
  >
2020
2060
  {#each selectedElements as item, index (item.id)}
2021
- <div
2022
- class="prompt-chat-selected-element-chip inline-flex max-w-full items-center gap-1.5 rounded-md border border-[#7BA668]/45 bg-white px-2 py-1 text-xs text-gray-800 shadow-xs"
2023
- title={item.selector}
2024
- >
2025
- <span class="flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-[#6D9A59] font-sans text-[10px] font-bold text-white">
2026
- {index + 1}
2027
- </span>
2028
- <span class="rounded bg-[#7BA668]/15 px-1 py-0.5 font-mono text-[11px] font-medium text-[#3C632C]">
2029
- &lt;{item.tagName}{item.idAttr ? `#${item.idAttr}` : ''}&gt;
2030
- </span>
2031
- {#if item.note?.trim()}
2032
- <span class="text-gray-400">·</span>
2033
- <span class="max-w-[220px] truncate text-[11px] text-[#3C632C]" title={item.note}>
2034
- {item.note.trim()}
2035
- </span>
2036
- {:else if item.textSnippet}
2037
- <span class="text-gray-400">·</span>
2038
- <span class="max-w-[180px] truncate text-[11px] text-gray-600">
2039
- {item.textSnippet}
2040
- </span>
2041
- {:else if item.selector}
2042
- <span class="text-gray-400">·</span>
2043
- <span class="max-w-[160px] truncate font-mono text-[10px] text-gray-500">
2044
- {item.selector}
2045
- </span>
2046
- {/if}
2047
- {#if onRemoveSelectedElement}
2048
- <button
2049
- type="button"
2050
- 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"
2051
- onclick={() => onRemoveSelectedElement?.(item.id)}
2052
- title={$t('chat.selector.removeElement')}
2053
- aria-label={$t('chat.selector.removeElement')}
2054
- >
2055
- ✕
2056
- </button>
2057
- {/if}
2058
- </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>
2059
2077
  {/each}
2060
2078
  {#if selectedElements.length > 1 && onClearSelectedElements}
2061
2079
  <button
@@ -2112,31 +2130,25 @@
2112
2130
  </div>
2113
2131
  {/if}
2114
2132
 
2115
- <ChatInput
2116
- value={localInputText}
2117
- attachments={localAttachments}
2118
- showAttachmentsTray={false}
2119
- isRecording={localIsRecording}
2133
+ <ChatComposer
2134
+ bind:value={() => localInputText, (nextInputText) => {
2135
+ localInputText = nextInputText;
2136
+ notifyDraftChange();
2137
+ }}
2120
2138
  isSending={localIsSending}
2121
- isUploading={localIsUploading}
2122
2139
  isGenerating={isGenerating || isLoading}
2140
+ models={composerModels}
2141
+ selectedModelId={selectedComposerModelId}
2142
+ onSelectModel={onSelectComposerModel}
2123
2143
  onStop={() => onStopGeneration?.()}
2124
- onSend={(content, attachmentInputs) => {
2125
- sendMessage(content, attachmentInputs);
2126
- }}
2127
- onInputChange={(text) => {
2128
- // chatLog('Input change for chat', context.id, ':', text);
2129
- localInputText = text;
2130
- notifyDraftChange();
2131
- }}
2132
- onAttachmentsChange={(attachments) => {
2133
- // chatLog('Attachments change for chat', context.id, ':', attachments.length);
2134
- localAttachments = attachments;
2135
- notifyDraftChange();
2144
+ onSend={(content) => {
2145
+ const attachmentInputs = localAttachments.length > 0 ? localAttachments : undefined;
2146
+ void sendMessage(content, attachmentInputs);
2136
2147
  }}
2137
2148
  onFilesDropped={(files) => {
2138
2149
  void addFilesAsAttachments(files);
2139
2150
  }}
2151
+ onAttach={config?.features?.fileUpload !== false ? () => void handleUpload() : undefined}
2140
2152
  canSendWithoutText={(selectedElements ?? []).some((element) => !!element.note?.trim())}
2141
2153
  />
2142
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
- /** Version selected in the dropdown. You-are-here follows this number. */
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>;