@widgetic/chat 0.1.35 → 0.1.37

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 (35) hide show
  1. package/README.md +34 -6
  2. package/dist/components/ActionBar.svelte +8 -0
  3. package/dist/components/Chat.svelte +120 -106
  4. package/dist/components/Chat.svelte.d.ts +19 -1
  5. package/dist/components/ChatComposer.svelte +166 -0
  6. package/dist/components/ChatComposer.svelte.d.ts +30 -0
  7. package/dist/components/ChatMessages.svelte +483 -393
  8. package/dist/components/ChatMessages.svelte.d.ts +16 -6
  9. package/dist/components/IconButton.svelte +125 -0
  10. package/dist/components/IconButton.svelte.d.ts +22 -0
  11. package/dist/components/MessageActions.svelte +48 -0
  12. package/dist/components/MessageActions.svelte.d.ts +13 -0
  13. package/dist/components/PanelChatHeader.svelte +79 -0
  14. package/dist/components/PanelChatHeader.svelte.d.ts +19 -0
  15. package/dist/components/PanelFollowUpSuggestions.svelte +34 -0
  16. package/dist/components/PanelFollowUpSuggestions.svelte.d.ts +8 -0
  17. package/dist/components/PanelSuggestionButtons.svelte +60 -0
  18. package/dist/components/PanelSuggestionButtons.svelte.d.ts +10 -0
  19. package/dist/components/SuggestionButtons.svelte +11 -163
  20. package/dist/i18n/index.d.ts +1 -1
  21. package/dist/i18n/index.js +1 -1
  22. package/dist/i18n/messages.d.ts +54 -13
  23. package/dist/i18n/messages.js +54 -13
  24. package/dist/i18n/suggestions.d.ts +6 -0
  25. package/dist/i18n/suggestions.js +24 -0
  26. package/dist/types/message.d.ts +7 -0
  27. package/dist/utils/generationActivity.d.ts +12 -0
  28. package/dist/utils/generationActivity.js +47 -0
  29. package/dist/utils/generationPlan.d.ts +32 -0
  30. package/dist/utils/generationPlan.js +89 -0
  31. package/dist/utils/index.d.ts +4 -0
  32. package/dist/utils/index.js +2 -0
  33. package/dist/utils/messageActions.d.ts +54 -0
  34. package/dist/utils/messageActions.js +104 -0
  35. package/package.json +3 -3
@@ -2,6 +2,7 @@ import type { ChatMessage, ChatContext } from '../types/index.js';
2
2
  import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
3
3
  import { type VersionThumb } from '../utils/versionRatings.js';
4
4
  import type { Snippet } from 'svelte';
5
+ import { type GenerationPlanWire } from '../utils/generationPlan.js';
5
6
  interface Props {
6
7
  class?: string;
7
8
  messages: ChatMessage[];
@@ -42,26 +43,33 @@ interface Props {
42
43
  /**
43
44
  * Every saved version for this widget. When one prompt produced two versions
44
45
  * but the chat stored only one user message, the missing older version is
45
- * shown as its own turn so "You are here" can land on it.
46
+ * shown as its own turn, so each version has its own place in the list.
46
47
  */
47
48
  versionTimeline?: Array<{
48
49
  version: number;
49
50
  sha: string;
50
51
  prompt: string;
51
52
  }>;
52
- /** Dropdown selection. The badge follows this version, not only a commit sha. */
53
- viewingVersion?: number | null;
54
53
  /** When false, hide commit hashes next to the version label (user mode). */
55
54
  showCommitMeta?: boolean;
56
- /** True while codegen / send is in flight — suppresses premature Retry. */
55
+ /** True while codegen / send is in flight — no icons are drawn under the last message and no restore is offered. */
57
56
  isGenerating?: boolean;
58
57
  /** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
59
58
  generationStream?: string;
59
+ /** Rolling tail of streamed model reasoning during codegen. */
60
+ generationThinking?: string;
61
+ /** Gateway build plan while codegen runs; `null` hides the card. */
62
+ generationPlan?: GenerationPlanWire | null;
60
63
  onSuggestionSelected?: (suggestion: string) => void;
64
+ /**
65
+ * Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
66
+ * put the widget back to how it was BEFORE that message: called with the id of the saved reply that stands for that earlier state
67
+ * and its place in `messages`. Without it no restore icon is drawn.
68
+ */
61
69
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
62
70
  /**
63
- * Gives each version a thumbs up and a thumbs down next to its name. Called with the id of the assistant message that
64
- * announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
71
+ * Gives the last message a thumbs up and a thumbs down (next to copy and regenerate). Called with the id of the assistant message
72
+ * that announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
65
73
  */
66
74
  onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
67
75
  /** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
@@ -85,6 +93,8 @@ interface Props {
85
93
  hasOlderMessages?: boolean;
86
94
  /** Called when the list is scrolled to the top, so the host can prepend the previous page. */
87
95
  onRequestOlderMessages?: () => Promise<boolean | void>;
96
+ /** Widget creator side panel: Figma empty / follow-up suggestion cards. */
97
+ panelLayout?: boolean;
88
98
  }
89
99
  declare const ChatMessages: import("svelte").Component<Props, {}, "">;
90
100
  type ChatMessages = ReturnType<typeof ChatMessages>;
@@ -0,0 +1,125 @@
1
+ <script lang="ts">
2
+ /**
3
+ * One small icon button of the chat's message rows: copy, regenerate, the two thumbs and the restore icon. It is the only place
4
+ * these icons get their look, so the five can never drift apart.
5
+ *
6
+ * The button names itself (`label`) for a screen reader and shows the same words as a tooltip, above the button (a row of icons) or
7
+ * on the side the line starts (an icon at the end of a row, where a tooltip above would cover the message it belongs to).
8
+ * The label is already in the language of the chat: the parent asks the catalog for it.
9
+ */
10
+ import type { Snippet } from 'svelte';
11
+
12
+ interface Props {
13
+ /** What the button does: its accessible name and its tooltip. */
14
+ label: string;
15
+ onclick: (event: MouseEvent) => void;
16
+ /** Where the tooltip opens. `start` is the side the line starts on, so it turns around on a right to left screen. */
17
+ tooltipSide?: 'above' | 'start';
18
+ /** For a toggle (a thumb): whether it is chosen. Left out, the button is a plain button. */
19
+ pressed?: boolean;
20
+ children: Snippet;
21
+ }
22
+
23
+ let { label, onclick, tooltipSide = 'above', pressed = undefined, children }: Props = $props();
24
+ </script>
25
+
26
+ <button
27
+ type="button"
28
+ class={['wc-icon-btn', { 'wc-icon-btn-tip-start': tooltipSide === 'start' }]}
29
+ aria-label={label}
30
+ aria-pressed={pressed}
31
+ data-tooltip={label}
32
+ {onclick}
33
+ >
34
+ {@render children()}
35
+ </button>
36
+
37
+ <style>
38
+ .wc-icon-btn {
39
+ position: relative;
40
+ display: inline-flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ width: 28px;
44
+ height: 28px;
45
+ padding: 0;
46
+ border: 0;
47
+ border-radius: 8px;
48
+ background: transparent;
49
+ color: #6b7280;
50
+ cursor: pointer;
51
+ transition: background-color 0.15s ease, color 0.15s ease;
52
+ }
53
+
54
+ .wc-icon-btn:hover {
55
+ background: rgba(107, 114, 128, 0.16);
56
+ color: #111827;
57
+ }
58
+
59
+ .wc-icon-btn:focus-visible {
60
+ outline: 2px solid #93c5fd;
61
+ outline-offset: 1px;
62
+ }
63
+
64
+ /* A chosen thumb: the icon is filled by its own markup, and the button reads darker. */
65
+ .wc-icon-btn[aria-pressed='true'] {
66
+ color: #111827;
67
+ }
68
+
69
+ /* The tooltip: the button's own words, a moment after the pointer rests on it (or at once for the keyboard). */
70
+ .wc-icon-btn::after {
71
+ content: attr(data-tooltip);
72
+ position: absolute;
73
+ z-index: 20;
74
+ bottom: calc(100% + 6px);
75
+ left: 50%;
76
+ transform: translateX(-50%);
77
+ padding: 4px 8px;
78
+ border: 1px solid #e5e7eb;
79
+ border-radius: 8px;
80
+ background: #ffffff;
81
+ color: #111827;
82
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
83
+ font-size: 11px;
84
+ font-weight: 500;
85
+ line-height: 1.2;
86
+ white-space: nowrap;
87
+ pointer-events: none;
88
+ opacity: 0;
89
+ visibility: hidden;
90
+ transition: opacity 0.1s ease;
91
+ }
92
+
93
+ .wc-icon-btn:hover::after {
94
+ opacity: 1;
95
+ visibility: visible;
96
+ transition-delay: 0.3s;
97
+ }
98
+
99
+ .wc-icon-btn:focus-visible::after {
100
+ opacity: 1;
101
+ visibility: visible;
102
+ }
103
+
104
+ .wc-icon-btn-tip-start::after {
105
+ top: 50%;
106
+ bottom: auto;
107
+ left: auto;
108
+ inset-inline-end: calc(100% + 6px);
109
+ transform: translateY(-50%);
110
+ }
111
+
112
+ /* A finger has no hover: no tooltip is left behind after a tap. */
113
+ @media (hover: none) {
114
+ .wc-icon-btn::after {
115
+ display: none;
116
+ }
117
+ }
118
+
119
+ @media (prefers-reduced-motion: reduce) {
120
+ .wc-icon-btn,
121
+ .wc-icon-btn::after {
122
+ transition: none;
123
+ }
124
+ }
125
+ </style>
@@ -0,0 +1,22 @@
1
+ /**
2
+ * One small icon button of the chat's message rows: copy, regenerate, the two thumbs and the restore icon. It is the only place
3
+ * these icons get their look, so the five can never drift apart.
4
+ *
5
+ * The button names itself (`label`) for a screen reader and shows the same words as a tooltip, above the button (a row of icons) or
6
+ * on the side the line starts (an icon at the end of a row, where a tooltip above would cover the message it belongs to).
7
+ * The label is already in the language of the chat: the parent asks the catalog for it.
8
+ */
9
+ import type { Snippet } from 'svelte';
10
+ interface Props {
11
+ /** What the button does: its accessible name and its tooltip. */
12
+ label: string;
13
+ onclick: (event: MouseEvent) => void;
14
+ /** Where the tooltip opens. `start` is the side the line starts on, so it turns around on a right to left screen. */
15
+ tooltipSide?: 'above' | 'start';
16
+ /** For a toggle (a thumb): whether it is chosen. Left out, the button is a plain button. */
17
+ pressed?: boolean;
18
+ children: Snippet;
19
+ }
20
+ declare const IconButton: import("svelte").Component<Props, {}, "">;
21
+ type IconButton = ReturnType<typeof IconButton>;
22
+ export default IconButton;
@@ -0,0 +1,48 @@
1
+ <script lang="ts">
2
+ import type { VersionRating } from '../types/message.js';
3
+ import { useChatLanguage } from '../i18n/language.js';
4
+ import { copyTextToClipboard } from '../utils/messageActions.js';
5
+ import type { VersionThumb } from '../utils/versionRatings.js';
6
+ import { MessageRatingActions } from '@widgetic/design-system/components/chat/index';
7
+
8
+ const { t } = useChatLanguage();
9
+
10
+ interface Props {
11
+ copyText: string;
12
+ canRegenerate: boolean;
13
+ onRegenerate: () => void;
14
+ ratedMessageId: string | null;
15
+ rating?: VersionRating;
16
+ onRate: (messageId: string, pressed: VersionThumb) => void;
17
+ }
18
+
19
+ let { copyText, canRegenerate, onRegenerate, ratedMessageId, rating = 'none', onRate }: Props = $props();
20
+
21
+ async function handleCopy() {
22
+ try {
23
+ await copyTextToClipboard(copyText);
24
+ } catch (error) {
25
+ console.warn('[Chat] Copy of the message failed:', error);
26
+ }
27
+ }
28
+ </script>
29
+
30
+ <div role="group" aria-label={$t('chat.messages.actions')}>
31
+ <MessageRatingActions
32
+ {copyText}
33
+ {canRegenerate}
34
+ {ratedMessageId}
35
+ {rating}
36
+ onCopy={copyText !== '' ? handleCopy : undefined}
37
+ onRegenerate={canRegenerate ? onRegenerate : undefined}
38
+ onRate={ratedMessageId ? onRate : undefined}
39
+ messages={{
40
+ copy: $t('chat.messages.copy'),
41
+ copied: $t('chat.messages.copied'),
42
+ regenerate: $t('chat.messages.regenerate'),
43
+ rateGroup: $t('chat.messages.rateGroup'),
44
+ rateUp: $t('chat.messages.rateUp'),
45
+ rateDown: $t('chat.messages.rateDown')
46
+ }}
47
+ />
48
+ </div>
@@ -0,0 +1,13 @@
1
+ import type { VersionRating } from '../types/message.js';
2
+ import type { VersionThumb } from '../utils/versionRatings.js';
3
+ interface Props {
4
+ copyText: string;
5
+ canRegenerate: boolean;
6
+ onRegenerate: () => void;
7
+ ratedMessageId: string | null;
8
+ rating?: VersionRating;
9
+ onRate: (messageId: string, pressed: VersionThumb) => void;
10
+ }
11
+ declare const MessageActions: import("svelte").Component<Props, {}, "">;
12
+ type MessageActions = ReturnType<typeof MessageActions>;
13
+ export default MessageActions;
@@ -0,0 +1,79 @@
1
+ <script lang="ts">
2
+ import { ChatHeader, DropdownMenu } from '@widgetic/design-system/components';
3
+ import { useChatLanguage } from '../i18n/language.js';
4
+
5
+ interface ConversationRow {
6
+ id?: string;
7
+ conversation_id?: string;
8
+ conversationId?: string;
9
+ title?: string;
10
+ }
11
+
12
+ interface Props {
13
+ title?: string;
14
+ showConsole?: boolean;
15
+ consoleOpen?: boolean;
16
+ onToggleConsole?: () => void;
17
+ onNewConversation?: () => void;
18
+ conversations?: ConversationRow[];
19
+ currentConversationId?: string | null;
20
+ onSelectConversation?: (conversationId: string) => void;
21
+ }
22
+
23
+ let {
24
+ title = '',
25
+ showConsole = false,
26
+ consoleOpen = false,
27
+ onToggleConsole,
28
+ onNewConversation,
29
+ conversations = [],
30
+ currentConversationId = null,
31
+ onSelectConversation,
32
+ }: Props = $props();
33
+
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
+ );
44
+ </script>
45
+
46
+ <ChatHeader
47
+ layout="panel"
48
+ data-testid="panel-chat-header"
49
+ class="panel-chat-header border-border bg-background"
50
+ {title}
51
+ {showConsole}
52
+ {consoleOpen}
53
+ onToggleConsole={onToggleConsole}
54
+ onNewChat={onNewConversation}
55
+ onTitleClick={canSwitchConversations ? () => { historyOpen = !historyOpen; } : undefined}
56
+ messages={{
57
+ newChat: $t('chat.header.newConversationTitle'),
58
+ console: $t('chat.header.console'),
59
+ openHistory: $t('chat.header.switchConversation'),
60
+ }}
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}
@@ -0,0 +1,19 @@
1
+ interface ConversationRow {
2
+ id?: string;
3
+ conversation_id?: string;
4
+ conversationId?: string;
5
+ title?: string;
6
+ }
7
+ interface Props {
8
+ title?: string;
9
+ showConsole?: boolean;
10
+ consoleOpen?: boolean;
11
+ onToggleConsole?: () => void;
12
+ onNewConversation?: () => void;
13
+ conversations?: ConversationRow[];
14
+ currentConversationId?: string | null;
15
+ onSelectConversation?: (conversationId: string) => void;
16
+ }
17
+ declare const PanelChatHeader: import("svelte").Component<Props, {}, "">;
18
+ type PanelChatHeader = ReturnType<typeof PanelChatHeader>;
19
+ export default 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;