@widgetic/chat 0.1.36 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,12 @@
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';
10
+ import PanelSuggestionButtons from './PanelSuggestionButtons.svelte';
11
+ import PanelFollowUpSuggestions from './PanelFollowUpSuggestions.svelte';
9
12
  import CodeBlock from './CodeBlock.svelte';
10
13
  import MessageActions from './MessageActions.svelte';
11
14
  import { onDestroy, onMount, tick } from 'svelte';
@@ -14,6 +17,8 @@
14
17
  import { CHAT_MESSAGES } from '../i18n/messages.js';
15
18
  import { versionLabelText } from '../i18n/labels.js';
16
19
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
20
+ import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
21
+ import IconPlayerStop from '@tabler/icons-svelte/icons/player-stop';
17
22
  import {
18
23
  generationActivityAriaKey,
19
24
  generationActivityPhase,
@@ -24,6 +29,7 @@
24
29
  // so a deep `.svelte` path types fine but cannot be resolved by Vite or Node.
25
30
  import {
26
31
  ActivityRow,
32
+ ChatAlertCard,
27
33
  Message,
28
34
  MessageCheckpointRow,
29
35
  PlanCard,
@@ -124,6 +130,8 @@
124
130
  hasOlderMessages?: boolean;
125
131
  /** Called when the list is scrolled to the top, so the host can prepend the previous page. */
126
132
  onRequestOlderMessages?: () => Promise<boolean | void>;
133
+ /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
134
+ panelLayout?: boolean;
127
135
  }
128
136
 
129
137
  let {
@@ -156,8 +164,10 @@
156
164
  storedLineLabel,
157
165
  hasOlderMessages = false,
158
166
  onRequestOlderMessages,
167
+ panelLayout = false,
159
168
  }: Props = $props();
160
169
 
170
+
161
171
  /** The property-edit sentence used to be stored with markdown the bubble does not render. */
162
172
  function readablePropertyEditLine(content: string): string {
163
173
  return content.replace(
@@ -185,6 +195,13 @@
185
195
  function detectMessagesScrollbar(node: HTMLElement) {
186
196
  function check() {
187
197
  messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
198
+ if (panelLayout) {
199
+ // The docked panel keeps Figma's 16px on both sides (set in the style of the list); with a scrollbar the bar
200
+ // takes the place of half of it.
201
+ if (messagesHasScrollbar) node.style.setProperty('padding-inline-end', '8px', 'important');
202
+ else node.style.removeProperty('padding-inline-end');
203
+ return;
204
+ }
188
205
  node.style.setProperty('padding-inline-end', messagesHasScrollbar ? '0px' : '12px', 'important');
189
206
  }
190
207
  const resizeObserver = new ResizeObserver(check);
@@ -527,6 +544,12 @@
527
544
  );
528
545
  }
529
546
 
547
+ /** A build the person stopped: it says so in the panel as the command they gave, and does not read as a failure. */
548
+ function isStoppedByUser(message: ChatMessage): boolean {
549
+ if (message.messageType !== 'assistant' || !message.messageContent) return false;
550
+ return /^(⏹\s*)?Generation stopped/i.test(message.messageContent.trim());
551
+ }
552
+
530
553
  function canUndoHeadUserTurn(turn: ChatTurn): boolean {
531
554
  return !!turn.user && !!getTurnCommitReply(turn) && isHeadCommitReply(getTurnCommitReply(turn)!);
532
555
  }
@@ -778,6 +801,22 @@
778
801
  return !isGenerationSummary(reply);
779
802
  }
780
803
 
804
+ /** Figma ready frame: follow-up cards sit above the composer, outside the scroll area. */
805
+ const panelAnchoredFollowUp = $derived.by((): { labels: string[] } | null => {
806
+ if (!panelLayout || showEmptyState) return null;
807
+ for (let ti = chatTurns.length - 1; ti >= 0; ti--) {
808
+ const turn = chatTurns[ti];
809
+ for (let ri = turn.replies.length - 1; ri >= 0; ri--) {
810
+ const reply = turn.replies[ri];
811
+ const meta = reply.metadata as { panelFollowUp?: boolean } | undefined;
812
+ if (!reply.suggestions?.length || meta?.panelFollowUp === false) continue;
813
+ if (!shouldShowAssistantReply(reply)) continue;
814
+ return { labels: reply.suggestions.map((s) => s.label) };
815
+ }
816
+ }
817
+ return null;
818
+ });
819
+
781
820
  /** Show the commit chrome (title, version label, the restore icon) on the user prompt whenever the turn has a commit.
782
821
  * Previously this was gated to Debug OFF (assistant reply hidden), but we want it
783
822
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
@@ -872,6 +911,16 @@
872
911
  return /credit balance|free trial|not available in your plan|not available on the free plan|upgrade your plan|upgrade to a solo/i.test(message);
873
912
  }
874
913
 
914
+ /** What the alert card of a failed reply says under its title: the server's own words when they tell something specific
915
+ * (the plan or the credits, too many requests, the service is unavailable, the run was stopped), otherwise Figma's line. */
916
+ function failureAlertDescription(message: ChatMessage): string {
917
+ const serverText = visibleMessageContent(message.messageContent || '').trim();
918
+ const isSpecificFailure =
919
+ isPlanLimitMessage(message.messageContent) ||
920
+ /Too many generation requests|temporarily unavailable|Generation stopped/i.test(serverText);
921
+ return isSpecificFailure && serverText ? serverText : $t('chat.messages.failedHint');
922
+ }
923
+
875
924
  function openUpgradePlans() {
876
925
  // A host that is a guest on somebody else's page decides what "upgrade" means there; the billing page of the
877
926
  // Widgetic site would take the visitor off the page they are on.
@@ -1508,11 +1557,19 @@
1508
1557
  }
1509
1558
  </script>
1510
1559
 
1560
+ {#snippet linkified(text: string)}{#each splitTextIntoLinks(text) as segment, segmentIndex (segmentIndex)}{#if segment.type === 'link'}<a
1561
+ href={segment.href}
1562
+ target="_blank"
1563
+ rel="noopener noreferrer"
1564
+ class="wc-chat-link text-foreground hover:text-primary underline underline-offset-2 [overflow-wrap:anywhere]"
1565
+ data-testid="chat-message-link">{segment.text}</a>{:else}{segment.text}{/if}{/each}{/snippet}
1566
+
1567
+ <div class="{panelLayout ? 'panel-messages-shell flex h-full min-h-0 w-full flex-1 flex-col' : 'contents'}">
1511
1568
  <div
1512
1569
  bind:this={messagesContainer}
1513
- class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4 pb-3"
1570
+ 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'}"
1514
1571
  class:loading={isLoading}
1515
- style="padding: 12px; overflow-anchor: none;"
1572
+ style={panelLayout ? 'padding: 8px 16px 0; overflow-anchor: none;' : 'padding: 8px 16px 12px; overflow-anchor: none;'}
1516
1573
  use:detectMessagesScrollbar
1517
1574
  onscroll={handleScroll}
1518
1575
  >
@@ -1524,12 +1581,10 @@
1524
1581
  middle of the messages, and the suggestions are pinned under it, above the composer. The block takes the
1525
1582
  free height with flex-1 (not min-h-full): the sticky scroll-to-bottom row below it needs its own room, and a
1526
1583
  block as tall as the whole area would push it out and make the list scroll. -->
1527
- <div class="empty-state-ct flex w-full flex-1 flex-col gap-4">
1584
+ <div class="empty-state-ct flex w-full flex-1 flex-col gap-4 {panelLayout ? 'min-h-0 pb-2' : ''}">
1528
1585
  <div class="empty-state-hero flex flex-1 flex-col items-center justify-center gap-3 px-2 text-center">
1529
1586
  <span class="empty-state-icon-circle bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-full" aria-hidden="true">
1530
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1531
- <path d="M16 18a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm0 -12a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm-7 12a6 6 0 0 1 6 -6a6 6 0 0 1 -6 -6a6 6 0 0 1 -6 6a6 6 0 0 1 6 6z" />
1532
- </svg>
1587
+ <IconSparkles class="size-4 stroke-2" />
1533
1588
  </span>
1534
1589
  <div class="flex flex-col gap-0.5">
1535
1590
  <h3 class="text-body-medium text-foreground">{$t('chat.messages.emptyTitle')}</h3>
@@ -1537,30 +1592,40 @@
1537
1592
  </div>
1538
1593
  </div>
1539
1594
 
1540
- <!-- Contextual suggestions -->
1541
- <SuggestionButtons
1542
- {context}
1543
- visible={true}
1544
- on:suggestionSelected={handleSuggestionSelected}
1545
- />
1595
+ {#if panelLayout}
1596
+ <PanelSuggestionButtons
1597
+ disabled={isGenerating}
1598
+ onPick={(text) => onSuggestionSelected?.(text)}
1599
+ />
1600
+ {:else}
1601
+ <SuggestionButtons
1602
+ {context}
1603
+ visible={true}
1604
+ on:suggestionSelected={handleSuggestionSelected}
1605
+ />
1606
+ {/if}
1546
1607
  </div>
1547
1608
  {/if}
1548
1609
 
1549
1610
  <!-- Conversation turns (user prompt + assistant status grouped) -->
1550
1611
  {#each chatTurns as turn, turnIndex (turn.user?.id ?? turn.replies[0]?.id ?? turnIndex)}
1551
- <div class="wc-chat-turn-ct space-y-1.5 rounded-lg border border-transparent p-0.5">
1612
+ <div class="wc-chat-turn-ct rounded-lg {panelLayout ? 'flex flex-col gap-[52px]' : 'space-y-1.5 border border-transparent p-0.5'}">
1552
1613
  {#if turn.user}
1553
1614
  {@const userMsg = turn.user}
1554
1615
  {@const shownAttachments = visibleUserAttachments(turn, turnIndex)}
1555
- <div class="message-container wc-chat-turn-user w-full flex flex-col items-stretch"
1616
+ <div class="message-container wc-chat-turn-user flex w-full flex-col {panelLayout ? 'items-end' : 'items-stretch'}"
1556
1617
  class:opacity-75={userMsg._optimistic}
1557
1618
  class:opacity-50={userMsg._failed}
1558
1619
  class:has-attachments={shownAttachments.length > 0}
1559
1620
  >
1560
- <Message role="user" class="ms-auto w-full max-w-full">
1621
+ <Message
1622
+ role="user"
1623
+ class="{panelLayout ? 'panel-layout-user-message ms-auto w-fit max-w-[85%]' : 'ms-auto w-full max-w-full'}"
1624
+ data-testid="chat-user-bubble"
1625
+ >
1561
1626
  {#snippet children()}
1562
1627
  <div
1563
- class="message-bubble-user w-full text-sm leading-relaxed select-text"
1628
+ class="message-bubble-user text-sm select-text {panelLayout ? 'w-auto max-w-full leading-5' : 'w-full leading-relaxed'}"
1564
1629
  class:p-0={shownAttachments.length > 0}
1565
1630
  use:bubbleScrollPadding
1566
1631
  >
@@ -1569,7 +1634,7 @@
1569
1634
  <div class="message-content-mixed p-3">
1570
1635
  {#each parseMessageContent(userMsg.messageContent) as part}
1571
1636
  {#if part.type === 'text'}
1572
- <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{part.content}</p>
1637
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{@render linkified(part.content)}</p>
1573
1638
  {:else if part.type === 'code'}
1574
1639
  <div class="my-3 first:mt-0 last:mb-0">
1575
1640
  <CodeBlock
@@ -1582,7 +1647,7 @@
1582
1647
  {/each}
1583
1648
  </div>
1584
1649
  {:else}
1585
- <p class="whitespace-pre-wrap p-3" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
1650
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] {panelLayout ? '' : 'p-3'}" dir={dirForUserText($textDirection)}>{@render linkified(userMsg.messageContent)}</p>
1586
1651
  {/if}
1587
1652
  {/if}
1588
1653
  {#if shownAttachments.length > 0}
@@ -1603,7 +1668,7 @@
1603
1668
  </div>
1604
1669
  {/snippet}
1605
1670
  </Message>
1606
- {#if showCommitMetaOnUserTurn(turn)}
1671
+ {#if showCommitMetaOnUserTurn(turn) && (!panelLayout || showCommitMeta)}
1607
1672
  {@const commitTitle = getTurnCommitTitle(turn)}
1608
1673
  {@const versionLabel = getTurnVersionLabel(turn)}
1609
1674
  {#if showCommitMeta && commitTitle}
@@ -1641,6 +1706,31 @@
1641
1706
 
1642
1707
  {#each turn.replies as reply (reply.id)}
1643
1708
  {#if shouldShowAssistantReply(reply)}
1709
+ {#if panelLayout && isStoppedByUser(reply)}
1710
+ <!-- A stop is the person's own command: one quiet line, not the red "Could not build the widget" card. -->
1711
+ <p
1712
+ class="wc-chat-turn-reply wc-chat-stopped text-body text-muted-foreground flex items-center gap-2"
1713
+ data-testid="chat-stopped-notice"
1714
+ >
1715
+ <IconPlayerStop class="size-4 shrink-0 stroke-2" aria-hidden="true" />
1716
+ <span>{$t('chat.messages.stoppedByYou')}</span>
1717
+ </p>
1718
+ {:else if panelLayout && isCodegenFailure(reply)}
1719
+ <!-- Figma Alert (526:3205): a failed reply in the docked panel is a card with a title, a line and "Try again",
1720
+ not a red line of text. The button runs the prompt of this turn again, on the last failure of the turn only. -->
1721
+ <ChatAlertCard
1722
+ class="wc-chat-turn-reply"
1723
+ title={$t('chat.messages.failedTitle')}
1724
+ description={failureAlertDescription(reply)}
1725
+ actionLabel={onRetryMessage &&
1726
+ isLastCodegenFailureInTurn(turn, reply) &&
1727
+ !isPlanLimitMessage(reply.messageContent) &&
1728
+ turnNeedsRetry(turn, turnIndex)
1729
+ ? $t('chat.messages.failedRetry')
1730
+ : ''}
1731
+ onAction={() => handleRetryTurn(turn, turnIndex)}
1732
+ />
1733
+ {:else}
1644
1734
  <Message
1645
1735
  role="assistant"
1646
1736
  class="wc-chat-turn-reply max-w-full"
@@ -1648,14 +1738,14 @@
1648
1738
  errorText={visibleMessageContent(reply.messageContent || '')}
1649
1739
  >
1650
1740
  {#snippet children()}
1651
- {#if reply.messageContent && !(reply.suggestions && reply.suggestions.length > 0)}
1741
+ {#if reply.messageContent && (panelLayout || !(reply.suggestions && reply.suggestions.length > 0))}
1652
1742
  <div class="message-content-assistant select-text text-sm leading-relaxed" use:bubbleScrollPadding>
1653
1743
  {#if reply.messageContent}
1654
1744
  {#if hasCodeBlocks(reply.messageContent)}
1655
1745
  <div class="message-content-mixed">
1656
1746
  {#each parseMessageContent(reply.messageContent) as part}
1657
1747
  {#if part.type === 'text'}
1658
- <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{visibleMessageContent(part.content)}</p>
1748
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere] mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{@render linkified(visibleMessageContent(part.content))}</p>
1659
1749
  {:else if part.type === 'code'}
1660
1750
  <div class="my-3 first:mt-0 last:mb-0">
1661
1751
  <CodeBlock
@@ -1668,13 +1758,14 @@
1668
1758
  {/each}
1669
1759
  </div>
1670
1760
  {:else}
1671
- <p class="whitespace-pre-wrap" dir={dirForUserText($textDirection)}>{visibleMessageContent(reply.messageContent)}</p>
1761
+ <p class="wc-chat-text whitespace-pre-wrap [overflow-wrap:anywhere]" dir={dirForUserText($textDirection)}>{@render linkified(visibleMessageContent(reply.messageContent))}</p>
1672
1762
  {/if}
1673
1763
  {/if}
1674
1764
  </div>
1675
1765
  {/if}
1676
1766
  {/snippet}
1677
1767
  </Message>
1768
+ {/if}
1678
1769
 
1679
1770
  {#if reply.designControls && renderDesignControls}
1680
1771
  <div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
@@ -1682,20 +1773,20 @@
1682
1773
  </div>
1683
1774
  {/if}
1684
1775
 
1685
- {#if reply.suggestions && reply.suggestions.length > 0}
1686
- <QuestionCard
1687
- class="mt-1.5 w-full max-w-full"
1688
- question={(visibleMessageContent(reply.messageContent || '') || $t('chat.messages.clarificationPrompt')).trim()}
1689
- options={reply.suggestions.map((suggestion, index) => ({
1690
- id: String(index),
1691
- label: suggestion.label
1692
- }))}
1693
- onSubmit={(selectedIds) => {
1694
- const picked = Number(selectedIds[0]);
1695
- const suggestion = reply.suggestions?.[picked];
1696
- if (suggestion) onClarificationSuggestionSelected?.(suggestion);
1697
- }}
1698
- />
1776
+ {#if reply.suggestions && reply.suggestions.length > 0 && !panelLayout}
1777
+ <QuestionCard
1778
+ class="mt-1.5 w-full max-w-full"
1779
+ question={(visibleMessageContent(reply.messageContent || '') || $t('chat.messages.clarificationPrompt')).trim()}
1780
+ options={reply.suggestions.map((suggestion, index) => ({
1781
+ id: String(index),
1782
+ label: suggestion.label
1783
+ }))}
1784
+ onSubmit={(selectedIds) => {
1785
+ const picked = Number(selectedIds[0]);
1786
+ const suggestion = reply.suggestions?.[picked];
1787
+ if (suggestion) onClarificationSuggestionSelected?.(suggestion);
1788
+ }}
1789
+ />
1699
1790
  {/if}
1700
1791
 
1701
1792
  <!-- A failure about the plan or the credits: the way out is to upgrade. Running the prompt again is the regenerate icon of the last message. -->
@@ -1714,8 +1805,9 @@
1714
1805
  {/if}
1715
1806
  {/each}
1716
1807
 
1717
- <!-- Copy, regenerate and the two thumbs: at the end of the last message only, and not while something is being generated. -->
1718
- {#if turnIndex === chatTurns.length - 1 && !isLoading && !isGenerating}
1808
+ <!-- Copy, regenerate and the two thumbs: at the end of the last message only, and not while something is being generated.
1809
+ Not in the panel either: the creator page's chat panel (Figma 526:2706, ready) draws no row of actions under the last message. -->
1810
+ {#if !panelLayout && turnIndex === chatTurns.length - 1 && !isLoading && !isGenerating}
1719
1811
  {@const copyText = textToCopy(
1720
1812
  turn.replies.filter(shouldShowAssistantReply).map((reply) => visibleMessageContent(reply.messageContent || '')),
1721
1813
  getTurnCommitTitle(turn),
@@ -1827,19 +1919,38 @@
1827
1919
  </div>
1828
1920
  {/if}
1829
1921
 
1830
- <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2">
1831
- <ScrollToBottom
1832
- visible={!autoScroll && messages.length > 0 && !isLoading}
1833
- label={$t('chat.messages.scrollToBottom')}
1834
- onScroll={() => {
1835
- autoScroll = true;
1836
- scrollMessagesToEnd();
1922
+ {#if !panelLayout}
1923
+ <div class="sticky bottom-2 z-10 flex justify-center pb-1 pt-2">
1924
+ <ScrollToBottom
1925
+ visible={!autoScroll && messages.length > 0 && !isLoading}
1926
+ label={$t('chat.messages.scrollToBottom')}
1927
+ onScroll={() => {
1928
+ autoScroll = true;
1929
+ scrollMessagesToEnd();
1930
+ }}
1931
+ />
1932
+ </div>
1933
+ {/if}
1934
+ </div>
1935
+ {#if panelLayout && panelAnchoredFollowUp}
1936
+ <div class="panel-anchored-followup ms-auto flex w-full max-w-full shrink-0 flex-col items-end px-4 pb-2">
1937
+ <PanelFollowUpSuggestions
1938
+ labels={panelAnchoredFollowUp.labels}
1939
+ disabled={isGenerating}
1940
+ onPick={(text) => {
1941
+ onSuggestionSelected?.(text);
1837
1942
  }}
1838
1943
  />
1839
1944
  </div>
1945
+ {/if}
1840
1946
  </div>
1841
1947
 
1842
1948
  <style>
1949
+ /* Figma panel: user bubble only — no hover action row consuming gap above the assistant text. */
1950
+ :global(.panel-layout-user-message > div.duration-fast) {
1951
+ display: none;
1952
+ min-height: 0;
1953
+ }
1843
1954
  .thinking-sizer {
1844
1955
  visibility: hidden;
1845
1956
  }
@@ -93,6 +93,8 @@ interface Props {
93
93
  hasOlderMessages?: boolean;
94
94
  /** Called when the list is scrolled to the top, so the host can prepend the previous page. */
95
95
  onRequestOlderMessages?: () => Promise<boolean | void>;
96
+ /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
97
+ panelLayout?: boolean;
96
98
  }
97
99
  declare const ChatMessages: import("svelte").Component<Props, {}, "">;
98
100
  type ChatMessages = ReturnType<typeof ChatMessages>;
@@ -1,15 +1,23 @@
1
1
  <script lang="ts">
2
- import { ChatHeader } from '@widgetic/design-system/components/chat/index';
2
+ import { ChatHeader, DropdownMenu } from '@widgetic/design-system/components';
3
3
  import { useChatLanguage } from '../i18n/language.js';
4
4
 
5
+ interface ConversationRow {
6
+ id?: string;
7
+ conversation_id?: string;
8
+ conversationId?: string;
9
+ title?: string;
10
+ }
11
+
5
12
  interface Props {
6
13
  title?: string;
7
14
  showConsole?: boolean;
8
15
  consoleOpen?: boolean;
9
16
  onToggleConsole?: () => void;
10
17
  onNewConversation?: () => void;
11
- onOpenHistory?: () => void;
12
- onTitleClick?: () => void;
18
+ conversations?: ConversationRow[];
19
+ currentConversationId?: string | null;
20
+ onSelectConversation?: (conversationId: string) => void;
13
21
  }
14
22
 
15
23
  let {
@@ -18,27 +26,54 @@
18
26
  consoleOpen = false,
19
27
  onToggleConsole,
20
28
  onNewConversation,
21
- onOpenHistory,
22
- onTitleClick
29
+ conversations = [],
30
+ currentConversationId = null,
31
+ onSelectConversation,
23
32
  }: Props = $props();
24
33
 
25
34
  const { t } = useChatLanguage();
35
+ let historyOpen = $state(false);
36
+
37
+ function conversationId(row: ConversationRow): string {
38
+ return String(row.id || row.conversation_id || row.conversationId || '');
39
+ }
40
+
41
+ const canSwitchConversations = $derived(
42
+ conversations.length > 0 && typeof onSelectConversation === 'function'
43
+ );
26
44
  </script>
27
45
 
28
46
  <ChatHeader
29
47
  layout="panel"
30
- class="border-border bg-background border-b"
31
- title={title}
48
+ data-testid="panel-chat-header"
49
+ class="panel-chat-header border-border bg-background"
50
+ {title}
32
51
  {showConsole}
33
52
  {consoleOpen}
34
53
  onToggleConsole={onToggleConsole}
35
54
  onNewChat={onNewConversation}
36
- onHistory={onOpenHistory}
37
- onTitleClick={onTitleClick}
55
+ onTitleClick={canSwitchConversations ? () => { historyOpen = !historyOpen; } : undefined}
38
56
  messages={{
39
57
  newChat: $t('chat.header.newConversationTitle'),
40
- history: $t('chat.header.switchConversation'),
41
58
  console: $t('chat.header.console'),
42
- openHistory: $t('chat.header.switchConversation')
59
+ openHistory: $t('chat.header.switchConversation'),
43
60
  }}
44
61
  />
62
+
63
+ {#if canSwitchConversations}
64
+ <DropdownMenu.Root bind:open={historyOpen}>
65
+ <DropdownMenu.Content align="start" class="max-h-64 w-64 overflow-y-auto">
66
+ {#each conversations as row (conversationId(row))}
67
+ {@const id = conversationId(row)}
68
+ <DropdownMenu.Item
69
+ class="justify-between gap-2"
70
+ onSelect={() => {
71
+ if (id && id !== currentConversationId) onSelectConversation?.(id);
72
+ }}
73
+ >
74
+ <span class="truncate">{row.title?.trim() || $t('chat.header.untitled')}</span>
75
+ </DropdownMenu.Item>
76
+ {/each}
77
+ </DropdownMenu.Content>
78
+ </DropdownMenu.Root>
79
+ {/if}
@@ -1,11 +1,18 @@
1
+ interface ConversationRow {
2
+ id?: string;
3
+ conversation_id?: string;
4
+ conversationId?: string;
5
+ title?: string;
6
+ }
1
7
  interface Props {
2
8
  title?: string;
3
9
  showConsole?: boolean;
4
10
  consoleOpen?: boolean;
5
11
  onToggleConsole?: () => void;
6
12
  onNewConversation?: () => void;
7
- onOpenHistory?: () => void;
8
- onTitleClick?: () => void;
13
+ conversations?: ConversationRow[];
14
+ currentConversationId?: string | null;
15
+ onSelectConversation?: (conversationId: string) => void;
9
16
  }
10
17
  declare const PanelChatHeader: import("svelte").Component<Props, {}, "">;
11
18
  type PanelChatHeader = ReturnType<typeof PanelChatHeader>;
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import IconClock from '@tabler/icons-svelte/icons/clock';
3
+ import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
4
+ import IconMessage from '@tabler/icons-svelte/icons/message';
5
+ import { SuggestionCard } from '@widgetic/design-system/components/chat/index';
6
+ import { useChatLanguage } from '../i18n/language.js';
7
+ import { panelFollowUpSuggestionTitleKey } from '../i18n/suggestions.js';
8
+
9
+ const { t } = useChatLanguage();
10
+
11
+ interface Props {
12
+ labels: string[];
13
+ onPick: (text: string) => void;
14
+ disabled?: boolean;
15
+ }
16
+
17
+ let { labels, onPick, disabled = false }: Props = $props();
18
+
19
+ const ICONS = [IconClock, IconSparkles, IconMessage];
20
+ </script>
21
+
22
+ <div class="panel-followup-suggestion-ct flex w-full max-w-full flex-col gap-1">
23
+ <h4 class="text-caption text-muted-foreground">{$t(panelFollowUpSuggestionTitleKey())}</h4>
24
+ <div class="flex w-full flex-col gap-1">
25
+ {#each labels as label, index (label + index)}
26
+ {@const Icon = ICONS[index % ICONS.length]}
27
+ <SuggestionCard title={label} {disabled} onclick={() => onPick(label)}>
28
+ {#snippet icon()}
29
+ <Icon class="size-4 stroke-2" aria-hidden="true" />
30
+ {/snippet}
31
+ </SuggestionCard>
32
+ {/each}
33
+ </div>
34
+ </div>
@@ -0,0 +1,8 @@
1
+ interface Props {
2
+ labels: string[];
3
+ onPick: (text: string) => void;
4
+ disabled?: boolean;
5
+ }
6
+ declare const PanelFollowUpSuggestions: import("svelte").Component<Props, {}, "">;
7
+ type PanelFollowUpSuggestions = ReturnType<typeof PanelFollowUpSuggestions>;
8
+ export default PanelFollowUpSuggestions;
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import IconClock from '@tabler/icons-svelte/icons/clock';
3
+ import IconMessage from '@tabler/icons-svelte/icons/message';
4
+ import IconPhoto from '@tabler/icons-svelte/icons/photo';
5
+ import IconArrowsMaximize from '@tabler/icons-svelte/icons/arrows-maximize';
6
+ import { SuggestionCard } from '@widgetic/design-system/components/chat/index';
7
+ import { useChatLanguage } from '../i18n/language.js';
8
+ import {
9
+ panelEmptySuggestionKeys,
10
+ panelEmptySuggestionTitleKey,
11
+ } from '../i18n/suggestions.js';
12
+ import type { ChatMessageKey } from '../i18n/messages.js';
13
+
14
+ const { t } = useChatLanguage();
15
+
16
+ interface Props {
17
+ onPick: (text: string) => void;
18
+ disabled?: boolean;
19
+ titleKey?: ChatMessageKey;
20
+ suggestionKeys?: readonly ChatMessageKey[];
21
+ }
22
+
23
+ let {
24
+ onPick,
25
+ disabled = false,
26
+ titleKey = panelEmptySuggestionTitleKey(),
27
+ suggestionKeys = panelEmptySuggestionKeys(),
28
+ }: Props = $props();
29
+
30
+ const ICON_BY_KEY: Partial<Record<ChatMessageKey, typeof IconClock>> = {
31
+ 'chat.suggestions.panel.countdown': IconClock,
32
+ 'chat.suggestions.panel.testimonials': IconMessage,
33
+ 'chat.suggestions.panel.gallery': IconPhoto,
34
+ 'chat.suggestions.panel.changeEndDate': IconClock,
35
+ 'chat.suggestions.panel.biggerButton': IconArrowsMaximize,
36
+ };
37
+
38
+ function iconForKey(key: ChatMessageKey) {
39
+ return ICON_BY_KEY[key] ?? IconMessage;
40
+ }
41
+ </script>
42
+
43
+ <div class="panel-suggestion-ct flex w-full max-w-full flex-col gap-1">
44
+ <h4 class="text-caption text-muted-foreground">{$t(titleKey)}</h4>
45
+ <div class="flex w-full flex-col gap-1">
46
+ {#each suggestionKeys as suggestionKey (suggestionKey)}
47
+ {@const label = $t(suggestionKey)}
48
+ {@const Icon = iconForKey(suggestionKey)}
49
+ <SuggestionCard
50
+ title={label}
51
+ disabled={disabled}
52
+ onclick={() => onPick(label)}
53
+ >
54
+ {#snippet icon()}
55
+ <Icon class="size-4 stroke-2" aria-hidden="true" />
56
+ {/snippet}
57
+ </SuggestionCard>
58
+ {/each}
59
+ </div>
60
+ </div>
@@ -0,0 +1,10 @@
1
+ import type { ChatMessageKey } from '../i18n/messages.js';
2
+ interface Props {
3
+ onPick: (text: string) => void;
4
+ disabled?: boolean;
5
+ titleKey?: ChatMessageKey;
6
+ suggestionKeys?: readonly ChatMessageKey[];
7
+ }
8
+ declare const PanelSuggestionButtons: import("svelte").Component<Props, {}, "">;
9
+ type PanelSuggestionButtons = ReturnType<typeof PanelSuggestionButtons>;
10
+ export default PanelSuggestionButtons;
@@ -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
- export { suggestionKeysFor, suggestionTitleKeyFor } from './suggestions.js';
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
- export { suggestionKeysFor, suggestionTitleKeyFor } from './suggestions.js';
5
+ export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';