@widgetic/chat 0.1.37 → 0.1.39

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.
Files changed (36) hide show
  1. package/dist/components/AttachmentDisplay.svelte +14 -4
  2. package/dist/components/Chat.svelte +155 -116
  3. package/dist/components/Chat.svelte.d.ts +4 -0
  4. package/dist/components/ChatComposer.svelte +63 -0
  5. package/dist/components/ChatComposer.svelte.d.ts +2 -0
  6. package/dist/components/ChatMessages.svelte +129 -20
  7. package/dist/components/ChatMessages.svelte.d.ts +2 -0
  8. package/dist/components/CodeBlock.svelte +9 -1
  9. package/dist/components/ComposerAttachmentsTray.svelte +64 -0
  10. package/dist/components/ComposerAttachmentsTray.svelte.d.ts +11 -0
  11. package/dist/components/PanelChatHeader.svelte +26 -6
  12. package/dist/components/PanelChatHeader.svelte.d.ts +1 -0
  13. package/dist/components/PanelFollowUpSuggestions.svelte +2 -2
  14. package/dist/components/PanelSuggestionButtons.svelte +2 -1
  15. package/dist/i18n/index.d.ts +1 -0
  16. package/dist/i18n/index.js +1 -0
  17. package/dist/i18n/messages.d.ts +4 -1
  18. package/dist/i18n/messages.js +4 -1
  19. package/dist/i18n/publishNudgeLocales.d.ts +18 -0
  20. package/dist/i18n/publishNudgeLocales.js +17 -0
  21. package/dist/sendNudgeState.d.ts +5 -0
  22. package/dist/sendNudgeState.js +18 -0
  23. package/dist/types/attachment.d.ts +5 -0
  24. package/dist/utils/attachmentPreviewUrl.d.ts +21 -0
  25. package/dist/utils/attachmentPreviewUrl.js +39 -0
  26. package/dist/utils/chatImageUploadPrep.d.ts +22 -0
  27. package/dist/utils/chatImageUploadPrep.js +90 -0
  28. package/dist/utils/generationArchiveStore.d.ts +10 -0
  29. package/dist/utils/generationArchiveStore.js +88 -0
  30. package/dist/utils/imageTransform.d.ts +12 -0
  31. package/dist/utils/imageTransform.js +45 -0
  32. package/dist/utils/linkifyText.d.ts +16 -0
  33. package/dist/utils/linkifyText.js +57 -0
  34. package/dist/utils/suggestionDraft.d.ts +5 -0
  35. package/dist/utils/suggestionDraft.js +15 -0
  36. package/package.json +3 -3
@@ -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,12 +18,20 @@
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,
23
25
  thoughtDurationSeconds,
26
+ readThinkingTail,
27
+ readCodegenStreamTail,
24
28
  } from '../utils/generationActivity.js';
25
29
  import { mapWidgetPlanToPlanCard, type GenerationPlanWire } from '../utils/generationPlan.js';
30
+ import {
31
+ clearGenerationArchive,
32
+ loadGenerationArchive,
33
+ saveGenerationArchive,
34
+ } from '../utils/generationArchiveStore.js';
26
35
  // The chat barrel of the design system: its export map resolves `components/<name>` to `<name>.js` only,
27
36
  // so a deep `.svelte` path types fine but cannot be resolved by Vite or Node.
28
37
  import {
@@ -130,6 +139,8 @@
130
139
  onRequestOlderMessages?: () => Promise<boolean | void>;
131
140
  /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
132
141
  panelLayout?: boolean;
142
+ /** Active conversation id — persists generation archive in IndexedDB across reload. */
143
+ conversationId?: string | null;
133
144
  }
134
145
 
135
146
  let {
@@ -163,6 +174,7 @@
163
174
  hasOlderMessages = false,
164
175
  onRequestOlderMessages,
165
176
  panelLayout = false,
177
+ conversationId = null,
166
178
  }: Props = $props();
167
179
 
168
180
 
@@ -192,12 +204,16 @@
192
204
 
193
205
  function detectMessagesScrollbar(node: HTMLElement) {
194
206
  function check() {
195
- messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
207
+ messagesHasScrollbar = node.scrollHeight > node.clientHeight + 4;
196
208
  if (panelLayout) {
197
209
  // The docked panel keeps Figma's 16px on both sides (set in the style of the list); with a scrollbar the bar
198
210
  // takes the place of half of it.
199
211
  if (messagesHasScrollbar) node.style.setProperty('padding-inline-end', '8px', 'important');
200
- else node.style.removeProperty('padding-inline-end');
212
+ else {
213
+ node.style.removeProperty('padding-inline-end');
214
+ node.style.setProperty('padding-inline-start', '16px', 'important');
215
+ node.style.setProperty('padding-inline-end', '16px', 'important');
216
+ }
201
217
  return;
202
218
  }
203
219
  node.style.setProperty('padding-inline-end', messagesHasScrollbar ? '0px' : '12px', 'important');
@@ -542,6 +558,12 @@
542
558
  );
543
559
  }
544
560
 
561
+ /** A build the person stopped: it says so in the panel as the command they gave, and does not read as a failure. */
562
+ function isStoppedByUser(message: ChatMessage): boolean {
563
+ if (message.messageType !== 'assistant' || !message.messageContent) return false;
564
+ return /^(⏹\s*)?Generation stopped/i.test(message.messageContent.trim());
565
+ }
566
+
545
567
  function canUndoHeadUserTurn(turn: ChatTurn): boolean {
546
568
  return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
547
569
  }
@@ -803,7 +825,12 @@
803
825
  const meta = reply.metadata as { panelFollowUp?: boolean } | undefined;
804
826
  if (!reply.suggestions?.length || meta?.panelFollowUp === false) continue;
805
827
  if (!shouldShowAssistantReply(reply)) continue;
806
- return { labels: reply.suggestions.map((s) => s.label) };
828
+ // A suggestion without a text label would give the keyed list a NaN key and stop the whole panel from rendering.
829
+ const suggestionLabels = reply.suggestions
830
+ .map((suggestion) => suggestion?.label)
831
+ .filter((label): label is string => typeof label === 'string' && label.trim().length > 0);
832
+ if (suggestionLabels.length === 0) continue;
833
+ return { labels: suggestionLabels };
807
834
  }
808
835
  }
809
836
  return null;
@@ -958,6 +985,20 @@
958
985
  let thinkingHold = $state(false);
959
986
  let generationWasRunning = false;
960
987
  let keptThinkingText = $state('');
988
+ $effect(() => {
989
+ const id = conversationId?.trim() ?? '';
990
+ void messages.length;
991
+ if (!id || isGenerating) return;
992
+ void loadGenerationArchive(id).then((record) => {
993
+ if (record) archivedGeneration = record;
994
+ });
995
+ });
996
+
997
+ let archivedGeneration = $state<{
998
+ thinking: string;
999
+ code: string;
1000
+ thoughtSeconds: number | null;
1001
+ } | null>(null);
961
1002
  let thinkingStartedAtMs = $state<number | null>(null);
962
1003
  let codeStreamingStartedAtMs = $state<number | null>(null);
963
1004
  let frozenThoughtSeconds = $state<number | null>(null);
@@ -998,6 +1039,7 @@
998
1039
  // A new send starts a fresh transcript. An empty thread drops the previous one.
999
1040
  $effect(() => {
1000
1041
  if (isGenerating && !generationWasRunning) {
1042
+ archivedGeneration = null;
1001
1043
  keptGenerationText = '';
1002
1044
  keptThinkingText = '';
1003
1045
  shownGenerationCount = 0;
@@ -1011,18 +1053,31 @@
1011
1053
  lastGenerationAriaKey = '';
1012
1054
  }
1013
1055
  if (!isGenerating && generationWasRunning) {
1014
- keptGenerationText = '';
1015
- keptThinkingText = '';
1016
- shownGenerationCount = 0;
1017
- thinkingShownCount = 0;
1056
+ if (keptThinkingText.trim() || keptGenerationText.trim()) {
1057
+ archivedGeneration = {
1058
+ thinking: keptThinkingText,
1059
+ code: keptGenerationText,
1060
+ thoughtSeconds: frozenThoughtSeconds,
1061
+ };
1062
+ void saveGenerationArchive(conversationId, archivedGeneration);
1063
+ }
1018
1064
  thinkingHold = false;
1065
+ shownGenerationCount = keptGenerationText.length;
1066
+ thinkingShownCount = $t('chat.messages.thinking').length;
1019
1067
  thinkingStartedAtMs = null;
1020
1068
  codeStreamingStartedAtMs = null;
1021
1069
  frozenThoughtSeconds = null;
1022
1070
  thinkingExpanded = false;
1023
1071
  }
1024
1072
  generationWasRunning = isGenerating;
1025
- if (messages.length === 0 && !isGenerating) {
1073
+ });
1074
+
1075
+ // Drop the local transcript only after init finished and history is truly empty — not while the thread hydrates on reload.
1076
+ $effect(() => {
1077
+ void messages.length;
1078
+ if (!isInitialized || isLoading || isGenerating) return;
1079
+ if (messages.length === 0) {
1080
+ void clearGenerationArchive(conversationId);
1026
1081
  keptGenerationText = '';
1027
1082
  keptThinkingText = '';
1028
1083
  shownGenerationCount = 0;
@@ -1549,12 +1604,21 @@
1549
1604
  }
1550
1605
  </script>
1551
1606
 
1607
+ {#snippet linkified(text: string)}{#each splitTextIntoLinks(text) as segment, segmentIndex (segmentIndex)}{#if segment.type === 'link'}<a
1608
+ href={segment.href}
1609
+ target="_blank"
1610
+ rel="noopener noreferrer"
1611
+ class="wc-chat-link text-foreground hover:text-primary underline underline-offset-2 [overflow-wrap:anywhere]"
1612
+ data-testid="chat-message-link">{segment.text}</a>{:else}{segment.text}{/if}{/each}{/snippet}
1613
+
1552
1614
  <div class="{panelLayout ? 'panel-messages-shell flex h-full min-h-0 w-full flex-1 flex-col' : 'contents'}">
1553
1615
  <div
1554
1616
  bind:this={messagesContainer}
1555
- class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto {panelLayout ? 'min-h-0 flex-1 gap-4 pb-1' : 'space-y-4 pb-3'}"
1617
+ class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col {panelLayout && showEmptyState && !isLoading && !isGenerating ? 'overflow-y-hidden pb-0' : 'overflow-y-auto'} {panelLayout ? (showEmptyState && !isLoading && !isGenerating ? 'min-h-0 flex-1' : 'min-h-0 flex-1 pb-4') : 'space-y-4 pb-3'}"
1556
1618
  class:loading={isLoading}
1557
- style={panelLayout ? 'padding: 8px 16px 0; overflow-anchor: none;' : 'padding: 8px 16px 12px; overflow-anchor: none;'}
1619
+ style={panelLayout
1620
+ ? `padding: 8px 16px ${showEmptyState && !isLoading && !isGenerating ? 0 : 16}px; overflow-anchor: none;`
1621
+ : 'padding: 8px 16px 12px; overflow-anchor: none;'}
1558
1622
  use:detectMessagesScrollbar
1559
1623
  onscroll={handleScroll}
1560
1624
  >
@@ -1566,8 +1630,8 @@
1566
1630
  middle of the messages, and the suggestions are pinned under it, above the composer. The block takes the
1567
1631
  free height with flex-1 (not min-h-full): the sticky scroll-to-bottom row below it needs its own room, and a
1568
1632
  block as tall as the whole area would push it out and make the list scroll. -->
1569
- <div class="empty-state-ct flex w-full flex-1 flex-col gap-4 {panelLayout ? 'min-h-0 pb-2' : ''}">
1570
- <div class="empty-state-hero flex flex-1 flex-col items-center justify-center gap-3 px-2 text-center">
1633
+ <div class="empty-state-ct flex w-full flex-col gap-4 {panelLayout ? 'shrink-0' : 'flex-1'}">
1634
+ <div class="empty-state-hero flex shrink-0 flex-col items-center justify-center gap-3 text-center {panelLayout ? 'h-[508px]' : 'min-h-0 flex-1 px-2'}">
1571
1635
  <span class="empty-state-icon-circle bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-full" aria-hidden="true">
1572
1636
  <IconSparkles class="size-4 stroke-2" />
1573
1637
  </span>
@@ -1592,6 +1656,8 @@
1592
1656
  </div>
1593
1657
  {/if}
1594
1658
 
1659
+ <div class="{panelLayout && chatTurns.length > 0 ? 'flex min-h-full flex-col' : 'contents'}">
1660
+ <div class="{panelLayout && chatTurns.length > 0 ? 'mt-auto flex w-full flex-col gap-4' : 'contents'}">
1595
1661
  <!-- Conversation turns (user prompt + assistant status grouped) -->
1596
1662
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
1597
1663
  <div class="wc-chat-turn-ct rounded-lg {panelLayout ? 'flex flex-col gap-[52px]' : 'space-y-1.5 border border-transparent p-0.5'}">
@@ -1619,7 +1685,7 @@
1619
1685
  <div class="message-content-mixed p-3">
1620
1686
  {#each parseMessageContent(userMsg.messageContent) as part}
1621
1687
  {#if part.type === 'text'}
1622
- <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{part.content}</p>
1688
+ <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
1689
  {:else if part.type === 'code'}
1624
1690
  <div class="my-3 first:mt-0 last:mb-0">
1625
1691
  <CodeBlock
@@ -1632,7 +1698,7 @@
1632
1698
  {/each}
1633
1699
  </div>
1634
1700
  {:else}
1635
- <p class="whitespace-pre-wrap {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
1701
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{@render linkified(userMsg.messageContent)}</p>
1636
1702
  {/if}
1637
1703
  {/if}
1638
1704
  {#if shownAttachments.length > 0}
@@ -1691,7 +1757,16 @@
1691
1757
 
1692
1758
  {#each turn.replies as reply (reply.id)}
1693
1759
  {#if shouldShowAssistantReply(reply)}
1694
- {#if panelLayout && isCodegenFailure(reply)}
1760
+ {#if panelLayout && isStoppedByUser(reply)}
1761
+ <!-- A stop is the person's own command: one quiet line, not the red "Could not build the widget" card. -->
1762
+ <p
1763
+ class="wc-chat-turn-reply wc-chat-stopped text-body text-muted-foreground flex items-center gap-2"
1764
+ data-testid="chat-stopped-notice"
1765
+ >
1766
+ <IconPlayerStop class="size-4 shrink-0 stroke-2" aria-hidden="true" />
1767
+ <span>{$t('chat.messages.stoppedByYou')}</span>
1768
+ </p>
1769
+ {:else if panelLayout && isCodegenFailure(reply)}
1695
1770
  <!-- Figma Alert (526:3205): a failed reply in the docked panel is a card with a title, a line and "Try again",
1696
1771
  not a red line of text. The button runs the prompt of this turn again, on the last failure of the turn only. -->
1697
1772
  <ChatAlertCard
@@ -1721,7 +1796,7 @@
1721
1796
  <div class="message-content-mixed">
1722
1797
  {#each parseMessageContent(reply.messageContent) as part}
1723
1798
  {#if part.type === 'text'}
1724
- <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{visibleMessageContent(part.content)}</p>
1799
+ <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
1800
  {:else if part.type === 'code'}
1726
1801
  <div class="my-3 first:mt-0 last:mb-0">
1727
1802
  <CodeBlock
@@ -1734,7 +1809,7 @@
1734
1809
  {/each}
1735
1810
  </div>
1736
1811
  {:else}
1737
- <p class="whitespace-pre-wrap" dir={dirForUserText($textDirection)}>{visibleMessageContent(reply.messageContent)}</p>
1812
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere]" dir={dirForUserText($textDirection)}>{@render linkified(visibleMessageContent(reply.messageContent))}</p>
1738
1813
  {/if}
1739
1814
  {/if}
1740
1815
  </div>
@@ -1804,6 +1879,40 @@
1804
1879
  </div>
1805
1880
  {/each}
1806
1881
 
1882
+ {#if panelLayout && archivedGeneration && !isGenerating && !thinkingHold}
1883
+ <div
1884
+ class="generation-archive-card w-full max-w-full rounded-lg border border-border bg-muted/40 p-3 text-sm"
1885
+ data-testid="generation-archive"
1886
+ >
1887
+ {#if archivedGeneration.thinking.trim()}
1888
+ <button
1889
+ type="button"
1890
+ class="text-muted-foreground hover:text-foreground mb-2 flex w-full items-center gap-2 text-start text-xs underline-offset-2 hover:underline"
1891
+ aria-expanded={thinkingExpanded}
1892
+ onclick={() => { thinkingExpanded = !thinkingExpanded; }}
1893
+ >
1894
+ <span>
1895
+ {#if archivedGeneration.thoughtSeconds != null}
1896
+ {$t('chat.generation.thoughtFor', { seconds: String(archivedGeneration.thoughtSeconds) })}
1897
+ {:else}
1898
+ {$t('chat.generation.thinking')}
1899
+ {/if}
1900
+ </span>
1901
+ </button>
1902
+ {#if thinkingExpanded}
1903
+ <div class="text-muted-foreground mb-2 max-h-24 overflow-auto whitespace-pre-wrap break-words text-xs">
1904
+ {archivedGeneration.thinking}
1905
+ </div>
1906
+ {/if}
1907
+ {/if}
1908
+ {#if archivedGeneration.code.trim()}
1909
+ <CodeBlock code={archivedGeneration.code} language="typescript" />
1910
+ {/if}
1911
+ </div>
1912
+ {/if}
1913
+ </div>
1914
+ </div>
1915
+
1807
1916
  <!-- Loading indicator -->
1808
1917
  {#if messages.length === 0 && isLoading}
1809
1918
  <div class="loading-history-ct flex flex-1 items-center justify-center p-8">
@@ -1895,10 +2004,10 @@
1895
2004
  </div>
1896
2005
  {/if}
1897
2006
 
1898
- {#if !panelLayout}
1899
- <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2">
2007
+ {#if !autoScroll && messages.length > 0 && !isLoading}
2008
+ <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2 pointer-events-none [&_button]:pointer-events-auto">
1900
2009
  <ScrollToBottom
1901
- visible={!autoScroll && messages.length > 0 && !isLoading}
2010
+ visible={true}
1902
2011
  label={$t('chat.messages.scrollToBottom')}
1903
2012
  onScroll={() => {
1904
2013
  autoScroll = true;
@@ -95,6 +95,8 @@ interface Props {
95
95
  onRequestOlderMessages?: () => Promise<boolean | void>;
96
96
  /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
97
97
  panelLayout?: boolean;
98
+ /** Active conversation id — persists generation archive in IndexedDB across reload. */
99
+ conversationId?: string | null;
98
100
  }
99
101
  declare const ChatMessages: import("svelte").Component<Props, {}, "">;
100
102
  type ChatMessages = ReturnType<typeof ChatMessages>;
@@ -259,7 +259,6 @@
259
259
 
260
260
  /* Line numbers styling */
261
261
  .with-line-numbers :global(.hljs) {
262
- padding-left: 3em; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
263
262
  position: relative;
264
263
  }
265
264
 
@@ -286,6 +285,15 @@
286
285
  padding: 0;
287
286
  }
288
287
 
288
+ /* The numbers are drawn over the left edge of the code, so the code keeps the room for them. This rule has to come after
289
+ the reset above: both have the same weight, and the reset would otherwise take the room back and hide the first
290
+ characters of every line under the numbers. The code is a block: the padding of an inline element only reaches the
291
+ first line, so the other lines would still start under the numbers. */
292
+ .code-pre.with-line-numbers :global(.hljs) {
293
+ display: block;
294
+ padding-left: 3em; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
295
+ }
296
+
289
297
  /* Embedded highlight.js GitHub Light theme tokens */
290
298
  :global(.hljs) {
291
299
  color: #24292e;
@@ -0,0 +1,64 @@
1
+ <script lang="ts">
2
+ import type { AttachmentInput } from '../types/attachment.js';
3
+ import { Chip } from '@widgetic/design-system/components/chat/index';
4
+ import IconX from '@tabler/icons-svelte/icons/x';
5
+ import { useChatLanguage } from '../i18n/language.js';
6
+ import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
7
+
8
+ interface Props {
9
+ attachments: AttachmentInput[];
10
+ previewUrl: (attachment: AttachmentInput) => string;
11
+ isImage: (attachment: AttachmentInput) => boolean;
12
+ onRemove: (index: number) => void;
13
+ onOpenPreview?: (url: string) => void;
14
+ }
15
+
16
+ let { attachments, previewUrl, isImage, onRemove, onOpenPreview }: Props = $props();
17
+ const { t } = useChatLanguage();
18
+
19
+ const IMAGE_PREVIEW_CSS_PX = 56;
20
+ </script>
21
+
22
+ <div class="composer-attachments-tray flex flex-wrap gap-2 pb-2" data-testid="composer-attachments-tray">
23
+ {#each attachments as attachment, index (attachment.preview || attachment.uploadedUrl || attachment.file?.name || index)}
24
+ {@const rawUrl = previewUrl(attachment)}
25
+ {#if isImage(attachment)}
26
+ <div
27
+ class="relative size-14 shrink-0 overflow-hidden rounded-lg border border-border bg-muted"
28
+ data-testid="composer-image-preview"
29
+ >
30
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
31
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
32
+ <img
33
+ src={buildImageThumbnailUrl(rawUrl, IMAGE_PREVIEW_CSS_PX) || rawUrl}
34
+ alt={attachment.file?.name || $t('chat.attachment.namelessAlt')}
35
+ class="size-full object-cover"
36
+ onclick={() => rawUrl && onOpenPreview?.(rawUrl)}
37
+ />
38
+ <button
39
+ type="button"
40
+ class="absolute end-0.5 top-0.5 flex size-5 items-center justify-center rounded-full bg-background/90 text-muted-foreground shadow-sm hover:text-foreground"
41
+ aria-label={$t('chat.attachment.remove')}
42
+ onclick={() => onRemove(index)}
43
+ >
44
+ <IconX class="size-3.5 stroke-2" aria-hidden="true" />
45
+ </button>
46
+ {#if attachment.uploadProgress && attachment.uploadProgress > 0 && attachment.uploadProgress < 100}
47
+ <div class="absolute inset-x-0 bottom-0 h-0.5 bg-border">
48
+ <div
49
+ class="bg-primary h-full transition-all duration-300"
50
+ style="width: {attachment.uploadProgress}%"
51
+ ></div>
52
+ </div>
53
+ {/if}
54
+ </div>
55
+ {:else}
56
+ <Chip
57
+ label={attachment.file?.name || $t('chat.attachment.namelessAlt')}
58
+ showRemove={true}
59
+ removeLabel={$t('chat.attachment.remove')}
60
+ onRemove={() => onRemove(index)}
61
+ />
62
+ {/if}
63
+ {/each}
64
+ </div>
@@ -0,0 +1,11 @@
1
+ import type { AttachmentInput } from '../types/attachment.js';
2
+ interface Props {
3
+ attachments: AttachmentInput[];
4
+ previewUrl: (attachment: AttachmentInput) => string;
5
+ isImage: (attachment: AttachmentInput) => boolean;
6
+ onRemove: (index: number) => void;
7
+ onOpenPreview?: (url: string) => void;
8
+ }
9
+ declare const ComposerAttachmentsTray: import("svelte").Component<Props, {}, "">;
10
+ type ComposerAttachmentsTray = ReturnType<typeof ComposerAttachmentsTray>;
11
+ export default ComposerAttachmentsTray;
@@ -18,6 +18,7 @@
18
18
  conversations?: ConversationRow[];
19
19
  currentConversationId?: string | null;
20
20
  onSelectConversation?: (conversationId: string) => void;
21
+ isGenerating?: boolean;
21
22
  }
22
23
 
23
24
  let {
@@ -29,6 +30,7 @@
29
30
  conversations = [],
30
31
  currentConversationId = null,
31
32
  onSelectConversation,
33
+ isGenerating = false,
32
34
  }: Props = $props();
33
35
 
34
36
  const { t } = useChatLanguage();
@@ -38,8 +40,8 @@
38
40
  return String(row.id || row.conversation_id || row.conversationId || '');
39
41
  }
40
42
 
41
- const canSwitchConversations = $derived(
42
- conversations.length > 0 && typeof onSelectConversation === 'function'
43
+ const historyEnabled = $derived(
44
+ typeof onSelectConversation === 'function' && typeof onNewConversation === 'function'
43
45
  );
44
46
  </script>
45
47
 
@@ -51,8 +53,8 @@
51
53
  {showConsole}
52
54
  {consoleOpen}
53
55
  onToggleConsole={onToggleConsole}
54
- onNewChat={onNewConversation}
55
- onTitleClick={canSwitchConversations ? () => { historyOpen = !historyOpen; } : undefined}
56
+ onNewChat={historyEnabled && !isGenerating ? onNewConversation : undefined}
57
+ onTitleClick={historyEnabled ? () => { historyOpen = !historyOpen; } : undefined}
56
58
  messages={{
57
59
  newChat: $t('chat.header.newConversationTitle'),
58
60
  console: $t('chat.header.console'),
@@ -60,20 +62,38 @@
60
62
  }}
61
63
  />
62
64
 
63
- {#if canSwitchConversations}
65
+ {#if historyEnabled}
64
66
  <DropdownMenu.Root bind:open={historyOpen}>
65
- <DropdownMenu.Content align="start" class="max-h-64 w-64 overflow-y-auto">
67
+ <DropdownMenu.Content align="start" class="max-h-64 w-72 overflow-y-auto">
68
+ <DropdownMenu.Item
69
+ class="gap-2 font-medium"
70
+ disabled={isGenerating}
71
+ onSelect={() => {
72
+ historyOpen = false;
73
+ onNewConversation?.();
74
+ }}
75
+ >
76
+ {$t('chat.header.newConversationTitle')}
77
+ </DropdownMenu.Item>
78
+ <DropdownMenu.Separator />
66
79
  {#each conversations as row (conversationId(row))}
67
80
  {@const id = conversationId(row)}
68
81
  <DropdownMenu.Item
69
82
  class="justify-between gap-2"
83
+ data-active={id === currentConversationId ? true : undefined}
70
84
  onSelect={() => {
85
+ historyOpen = false;
71
86
  if (id && id !== currentConversationId) onSelectConversation?.(id);
72
87
  }}
73
88
  >
74
89
  <span class="truncate">{row.title?.trim() || $t('chat.header.untitled')}</span>
75
90
  </DropdownMenu.Item>
76
91
  {/each}
92
+ {#if conversations.length === 0}
93
+ <DropdownMenu.Item disabled class="text-muted-foreground text-caption">
94
+ {$t('chat.header.noPastChats')}
95
+ </DropdownMenu.Item>
96
+ {/if}
77
97
  </DropdownMenu.Content>
78
98
  </DropdownMenu.Root>
79
99
  {/if}
@@ -13,6 +13,7 @@ interface Props {
13
13
  conversations?: ConversationRow[];
14
14
  currentConversationId?: string | null;
15
15
  onSelectConversation?: (conversationId: string) => void;
16
+ isGenerating?: boolean;
16
17
  }
17
18
  declare const PanelChatHeader: import("svelte").Component<Props, {}, "">;
18
19
  type PanelChatHeader = ReturnType<typeof PanelChatHeader>;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import IconClock from '@tabler/icons-svelte/icons/clock';
3
- import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
3
+ import IconWand from '@tabler/icons-svelte/icons/wand';
4
4
  import IconMessage from '@tabler/icons-svelte/icons/message';
5
5
  import { SuggestionCard } from '@widgetic/design-system/components/chat/index';
6
6
  import { useChatLanguage } from '../i18n/language.js';
@@ -16,7 +16,7 @@
16
16
 
17
17
  let { labels, onPick, disabled = false }: Props = $props();
18
18
 
19
- const ICONS = [IconClock, IconSparkles, IconMessage];
19
+ const ICONS = [IconClock, IconWand, IconMessage];
20
20
  </script>
21
21
 
22
22
  <div class="panel-followup-suggestion-ct flex w-full max-w-full flex-col gap-1">
@@ -40,7 +40,7 @@
40
40
  }
41
41
  </script>
42
42
 
43
- <div class="panel-suggestion-ct flex w-full max-w-full flex-col gap-1">
43
+ <div class="panel-suggestion-ct flex w-full max-w-full flex-col gap-1 pb-2">
44
44
  <h4 class="text-caption text-muted-foreground">{$t(titleKey)}</h4>
45
45
  <div class="flex w-full flex-col gap-1">
46
46
  {#each suggestionKeys as suggestionKey (suggestionKey)}
@@ -49,6 +49,7 @@
49
49
  <SuggestionCard
50
50
  title={label}
51
51
  disabled={disabled}
52
+ class="min-h-11"
52
53
  onclick={() => onPick(label)}
53
54
  >
54
55
  {#snippet icon()}
@@ -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';
@@ -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';
@@ -32,6 +32,7 @@ export declare const CHAT_MESSAGES: {
32
32
  /** The name of a conversation that has none. */
33
33
  readonly 'chat.header.untitled': "Untitled";
34
34
  readonly 'chat.header.newConversationTitle': "New chat";
35
+ readonly 'chat.header.noPastChats': "No previous chats yet";
35
36
  readonly 'chat.header.newConversation': "Start new conversation";
36
37
  /** Label for the debug console icon in the panel chat header. */
37
38
  readonly 'chat.header.console': "Console";
@@ -72,6 +73,8 @@ export declare const CHAT_MESSAGES: {
72
73
  readonly 'chat.messages.failedTitle': "Could not build the widget";
73
74
  readonly 'chat.messages.failedHint': "The build did not finish. Your sketch is safe, so you can try again.";
74
75
  readonly 'chat.messages.failedRetry': "Try again";
76
+ /** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
77
+ readonly 'chat.messages.stoppedByYou': "You stopped the build.";
75
78
  readonly 'chat.messages.upgrade': "Upgrade";
76
79
  readonly 'chat.messages.upgradeTitle': "Open plans and billing";
77
80
  /** Under a prompt: the short id of the commit it made. */
@@ -141,6 +144,7 @@ export declare const CHAT_MESSAGES: {
141
144
  readonly 'chat.input.sending': "Sending message...";
142
145
  readonly 'chat.input.send': "Send message";
143
146
  readonly 'chat.input.tooLong': "Message is too long";
147
+ readonly 'chat.input.publishNudge': "First generate your widget, then you can publish it.";
144
148
  readonly 'chat.composer.assistant': "Assistant";
145
149
  readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
146
150
  readonly 'chat.messages.clarificationPrompt': "Which option fits best?";
@@ -208,7 +212,6 @@ export declare const CHAT_MESSAGES: {
208
212
  readonly 'chat.error.loadConversations': "Failed to load conversations.";
209
213
  readonly 'chat.error.loadConversation': "Failed to load conversation.";
210
214
  readonly 'chat.error.sendMessage': "Failed to send message. Please try again.";
211
- readonly 'chat.error.sendSuggestion': "Failed to send the selected suggestion. Please try again.";
212
215
  readonly 'chat.error.screenshotUnavailable': "Screenshot capture failed — no preview available.";
213
216
  readonly 'chat.error.screenshotFailed': "Failed to capture screenshot";
214
217
  readonly 'chat.error.screenshotActionFailed': "Screenshot action failed. Please try again.";
@@ -34,6 +34,7 @@ export const CHAT_MESSAGES = {
34
34
  /** The name of a conversation that has none. */
35
35
  'chat.header.untitled': 'Untitled',
36
36
  'chat.header.newConversationTitle': 'New chat',
37
+ 'chat.header.noPastChats': 'No previous chats yet',
37
38
  'chat.header.newConversation': 'Start new conversation',
38
39
  /** Label for the debug console icon in the panel chat header. */
39
40
  'chat.header.console': 'Console',
@@ -76,6 +77,8 @@ export const CHAT_MESSAGES = {
76
77
  'chat.messages.failedTitle': 'Could not build the widget',
77
78
  'chat.messages.failedHint': 'The build did not finish. Your sketch is safe, so you can try again.',
78
79
  'chat.messages.failedRetry': 'Try again',
80
+ /** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
81
+ 'chat.messages.stoppedByYou': 'You stopped the build.',
79
82
  'chat.messages.upgrade': 'Upgrade',
80
83
  'chat.messages.upgradeTitle': 'Open plans and billing',
81
84
  /** Under a prompt: the short id of the commit it made. */
@@ -147,6 +150,7 @@ export const CHAT_MESSAGES = {
147
150
  'chat.input.sending': 'Sending message...',
148
151
  'chat.input.send': 'Send message',
149
152
  'chat.input.tooLong': 'Message is too long',
153
+ 'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
150
154
  'chat.composer.assistant': 'Assistant',
151
155
  'chat.messages.scrollToBottom': 'Scroll to latest messages',
152
156
  'chat.messages.clarificationPrompt': 'Which option fits best?',
@@ -219,7 +223,6 @@ export const CHAT_MESSAGES = {
219
223
  'chat.error.loadConversations': 'Failed to load conversations.',
220
224
  'chat.error.loadConversation': 'Failed to load conversation.',
221
225
  'chat.error.sendMessage': 'Failed to send message. Please try again.',
222
- 'chat.error.sendSuggestion': 'Failed to send the selected suggestion. Please try again.',
223
226
  'chat.error.screenshotUnavailable': 'Screenshot capture failed — no preview available.',
224
227
  'chat.error.screenshotFailed': 'Failed to capture screenshot',
225
228
  'chat.error.screenshotActionFailed': 'Screenshot action failed. Please try again.',
@@ -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;