@widgetic/chat 0.1.44 → 0.1.47

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 (75) hide show
  1. package/README.md +162 -20
  2. package/dist/components/ActionBar.svelte +14 -1
  3. package/dist/components/ActionBar.svelte.d.ts +6 -0
  4. package/dist/components/AttachmentDisplay.svelte +22 -130
  5. package/dist/components/AttachmentPreviewDialog.svelte +428 -0
  6. package/dist/components/AttachmentPreviewDialog.svelte.d.ts +14 -0
  7. package/dist/components/Chat.svelte +556 -121
  8. package/dist/components/Chat.svelte.d.ts +15 -2
  9. package/dist/components/ChatComposer.svelte +63 -69
  10. package/dist/components/ChatComposer.svelte.d.ts +8 -3
  11. package/dist/components/ChatDropOverlay.svelte +58 -0
  12. package/dist/components/ChatDropOverlay.svelte.d.ts +8 -0
  13. package/dist/components/ChatMessages.svelte +322 -98
  14. package/dist/components/ChatMessages.svelte.d.ts +11 -2
  15. package/dist/components/ComposerAttachmentsTray.svelte +144 -56
  16. package/dist/components/ComposerAttachmentsTray.svelte.d.ts +11 -1
  17. package/dist/components/FileGlyphIcon.svelte +34 -0
  18. package/dist/components/FileGlyphIcon.svelte.d.ts +8 -0
  19. package/dist/components/PanelSuggestionButtons.svelte +67 -19
  20. package/dist/components/PanelSuggestionButtons.svelte.d.ts +3 -1
  21. package/dist/components/RestoreCheckpointDialog.svelte +66 -0
  22. package/dist/components/RestoreCheckpointDialog.svelte.d.ts +11 -0
  23. package/dist/components/SentAttachments.svelte +118 -0
  24. package/dist/components/SentAttachments.svelte.d.ts +12 -0
  25. package/dist/components/agent/AgentTurn.svelte +17 -2
  26. package/dist/components/agent/CodeCard.svelte +9 -3
  27. package/dist/i18n/index.d.ts +1 -1
  28. package/dist/i18n/index.js +1 -1
  29. package/dist/i18n/messages.d.ts +52 -4
  30. package/dist/i18n/messages.js +58 -6
  31. package/dist/i18n/suggestions.d.ts +17 -2
  32. package/dist/i18n/suggestions.js +11 -12
  33. package/dist/services/index.d.ts +4 -2
  34. package/dist/services/index.js +2 -1
  35. package/dist/services/limitRefusal.d.ts +42 -0
  36. package/dist/services/limitRefusal.js +60 -0
  37. package/dist/services/sketchAssistantClient.d.ts +11 -3
  38. package/dist/services/sketchAssistantClient.js +37 -10
  39. package/dist/services/sketchAssistantErrors.d.ts +16 -1
  40. package/dist/services/sketchAssistantErrors.js +25 -4
  41. package/dist/services/sketchAssistantOrchestrator.d.ts +7 -1
  42. package/dist/services/sketchAssistantOrchestrator.js +2 -2
  43. package/dist/types/attachment.d.ts +11 -0
  44. package/dist/utils/agentTurn.d.ts +32 -1
  45. package/dist/utils/agentTurn.js +46 -3
  46. package/dist/utils/attachmentDuplicates.d.ts +48 -0
  47. package/dist/utils/attachmentDuplicates.js +70 -0
  48. package/dist/utils/attachmentPolicy.d.ts +88 -0
  49. package/dist/utils/attachmentPolicy.js +135 -0
  50. package/dist/utils/attachmentPreview.d.ts +146 -0
  51. package/dist/utils/attachmentPreview.js +224 -0
  52. package/dist/utils/attachmentTray.d.ts +35 -0
  53. package/dist/utils/attachmentTray.js +27 -0
  54. package/dist/utils/chatFileDrag.d.ts +39 -0
  55. package/dist/utils/chatFileDrag.js +29 -0
  56. package/dist/utils/composerPreview.d.ts +33 -0
  57. package/dist/utils/composerPreview.js +31 -0
  58. package/dist/utils/generationArchiveStore.d.ts +5 -1
  59. package/dist/utils/generationArchiveStore.js +9 -4
  60. package/dist/utils/index.d.ts +1 -1
  61. package/dist/utils/index.js +1 -1
  62. package/dist/utils/limitFailureLine.d.ts +20 -0
  63. package/dist/utils/limitFailureLine.js +40 -0
  64. package/dist/utils/panelListPadding.d.ts +20 -0
  65. package/dist/utils/panelListPadding.js +31 -0
  66. package/dist/utils/pasteInsertion.d.ts +43 -0
  67. package/dist/utils/pasteInsertion.js +94 -0
  68. package/dist/utils/pastedContent.d.ts +13 -0
  69. package/dist/utils/pastedContent.js +18 -1
  70. package/dist/utils/referenceItems.js +11 -3
  71. package/dist/utils/sentAttachments.d.ts +43 -0
  72. package/dist/utils/sentAttachments.js +38 -0
  73. package/dist/utils/sentReferenceBadges.d.ts +11 -1
  74. package/dist/utils/sentReferenceBadges.js +47 -2
  75. package/package.json +3 -3
@@ -0,0 +1,118 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The files of a sent message, above its bubble and at its end (Figma: Chat states, "Thread"): the files that are not pictures first,
4
+ * each as a chip with the glyph of its kind, and the pictures after them as the same small thumbnails the message box shows, one
5
+ * after the other. They are the same arrangement the person saw while they attached the files, so a message does not change what
6
+ * its files look like when it is sent. A bubble holds words only.
7
+ *
8
+ * A thumbnail or a chip of a file that has a preview opens it (the page hears of it through `onOpenPreview` and shows the card);
9
+ * a chip of a file that has none only names it. Which files are drawn, and in which row, is `arrangeSentAttachments`'s rule.
10
+ */
11
+ import { Chip } from '@widgetic/design-system/components/chat/index';
12
+ import { useChatLanguage } from '../i18n/language.js';
13
+ import { fileGlyphOf, previewGroupOf, type PreviewableFile } from '../utils/attachmentPreview.js';
14
+ import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
15
+ import { sentAttachmentsInDrawnOrder, type SentArrangement, type SentEntry } from '../utils/sentAttachments.js';
16
+ import { chatLog } from '../utils/logger.js';
17
+ import FileGlyphIcon from './FileGlyphIcon.svelte';
18
+
19
+ interface Props {
20
+ /** The files of the message as they are drawn: the chips, then the pictures (see `arrangeSentAttachments`). */
21
+ arrangement: SentArrangement;
22
+ /** A file was pressed: the page opens the preview over `files` (the files that have one, in the order they are drawn) at `openIndex`. */
23
+ onOpenPreview?: (files: PreviewableFile[], openIndex: number) => void;
24
+ class?: string;
25
+ }
26
+
27
+ let { arrangement, onOpenPreview, class: className = '' }: Props = $props();
28
+
29
+ const { t } = useChatLanguage();
30
+
31
+ /** The side of a thumbnail in CSS px: the same 56 px as a thumbnail in the message box. */
32
+ const THUMBNAIL_CSS_PX = 56;
33
+
34
+ // The files the preview steps through, in the order the screen draws them (the right arrow goes to the file drawn after this one)
35
+ const previewGroup = $derived(previewGroupOf(sentAttachmentsInDrawnOrder(arrangement)));
36
+
37
+ /**
38
+ * What tells one file from the others while the rows are drawn. A saved message brings the id of its row; a file that was just
39
+ * sent has none, and the name, the address and the place tell two of them apart (two screenshots are both "image.png").
40
+ */
41
+ function entryKey(entry: SentEntry): string {
42
+ const { attachment, index } = entry;
43
+ return attachment.id || `${attachment.file_name ?? ''}|${attachment.url ?? ''}|${index}`;
44
+ }
45
+
46
+ /** The name a file is shown by: the one it was saved under, or a word for a file that has none. */
47
+ function nameOf(entry: SentEntry): string {
48
+ return entry.attachment.file_name?.trim() || $t('chat.attachment.untitled');
49
+ }
50
+
51
+ /** Opens the preview of the file of an entry, when it has one. */
52
+ function openPreviewOf(entry: SentEntry): void {
53
+ const openIndex = previewGroup.indexOf(entry.attachment);
54
+ if (openIndex < 0) return;
55
+ chatLog('[SentAttachments] A file of a sent message was opened:', entry.attachment.file_name);
56
+ onOpenPreview?.(previewGroup.files, openIndex);
57
+ }
58
+ </script>
59
+
60
+ <!-- The chip of a file: the glyph of its kind, then its name. The chip cuts a long name with an ellipsis, and the name in full is the title over it. -->
61
+ {#snippet fileChip(entry: SentEntry, name: string)}
62
+ <Chip label={name}>
63
+ {#snippet leading()}
64
+ <FileGlyphIcon glyph={fileGlyphOf({ url: entry.attachment.url, name: entry.attachment.file_name, type: entry.attachment.file_type })} />
65
+ {/snippet}
66
+ </Chip>
67
+ {/snippet}
68
+
69
+ <div class="sent-attachments flex w-full min-w-0 flex-col items-end gap-2 {className}" data-testid="chat-sent-attachments">
70
+ {#if arrangement.chips.length > 0}
71
+ <div class="flex max-w-full min-w-0 flex-wrap justify-end gap-2" role="group" aria-label={$t('chat.attachment.sentFiles')} data-testid="chat-sent-files">
72
+ {#each arrangement.chips as entry (entryKey(entry))}
73
+ {@const name = nameOf(entry)}
74
+ {#if previewGroup.indexOf(entry.attachment) >= 0}
75
+ <button
76
+ type="button"
77
+ class="focus-visible:ring-ring inline-flex max-w-full min-w-0 cursor-pointer rounded-lg focus-visible:ring-2 focus-visible:outline-none"
78
+ title={name}
79
+ aria-label={$t('chat.attachment.view', { name })}
80
+ onclick={() => openPreviewOf(entry)}
81
+ data-testid="chat-sent-file"
82
+ >
83
+ {@render fileChip(entry, name)}
84
+ </button>
85
+ {:else}
86
+ <span class="inline-flex max-w-full min-w-0" title={name} data-testid="chat-sent-file">
87
+ {@render fileChip(entry, name)}
88
+ </span>
89
+ {/if}
90
+ {/each}
91
+ </div>
92
+ {/if}
93
+
94
+ {#if arrangement.pictures.length > 0}
95
+ <div class="flex max-w-full min-w-0 flex-wrap justify-end gap-2" role="group" aria-label={$t('chat.attachment.sentPictures')} data-testid="chat-sent-pictures">
96
+ {#each arrangement.pictures as entry (entryKey(entry))}
97
+ {@const name = nameOf(entry)}
98
+ <button
99
+ type="button"
100
+ class="border-border bg-muted focus-visible:ring-ring block size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-lg border focus-visible:ring-2 focus-visible:outline-none"
101
+ title={name}
102
+ aria-label={$t('chat.attachment.view', { name })}
103
+ onclick={() => openPreviewOf(entry)}
104
+ data-testid="chat-sent-picture"
105
+ >
106
+ <img
107
+ src={buildImageThumbnailUrl(entry.attachment.url, THUMBNAIL_CSS_PX) || entry.attachment.url}
108
+ alt=""
109
+ class="size-full object-cover"
110
+ draggable="false"
111
+ loading="lazy"
112
+ decoding="async"
113
+ />
114
+ </button>
115
+ {/each}
116
+ </div>
117
+ {/if}
118
+ </div>
@@ -0,0 +1,12 @@
1
+ import { type PreviewableFile } from '../utils/attachmentPreview.js';
2
+ import { type SentArrangement } from '../utils/sentAttachments.js';
3
+ interface Props {
4
+ /** The files of the message as they are drawn: the chips, then the pictures (see `arrangeSentAttachments`). */
5
+ arrangement: SentArrangement;
6
+ /** A file was pressed: the page opens the preview over `files` (the files that have one, in the order they are drawn) at `openIndex`. */
7
+ onOpenPreview?: (files: PreviewableFile[], openIndex: number) => void;
8
+ class?: string;
9
+ }
10
+ declare const SentAttachments: import("svelte").Component<Props, {}, "">;
11
+ type SentAttachments = ReturnType<typeof SentAttachments>;
12
+ export default SentAttachments;
@@ -39,6 +39,18 @@
39
39
  class: className = '',
40
40
  children
41
41
  }: Props = $props();
42
+
43
+ /**
44
+ * The empty room the page's drawing (the Scribble Mascot) keeps around its figure, which the avatar's box counts as its own:
45
+ * the small figure is 15 px wide in its 28 px square (6 px to spare at each side), and the large one starts at the left edge of
46
+ * its square and has about 8 px to spare at the right. That room made the face sit further from the edge of the chat and from
47
+ * the words than the spacing says. The column of the face hands it back to the row (a negative margin of the same width), so the
48
+ * face starts where the message box under the chat starts and the words sit at the gap the spacing says: 8 px. The plain avatar
49
+ * fills its square and keeps its box. The margin moves with the same ease as the glide of the avatar's size (see `AgentAvatar`).
50
+ */
51
+ const faceColumnMarginClasses = $derived(
52
+ !renderAgentAvatar ? '' : look.size === 'small' ? '-ms-1.5 -me-1.5' : '-me-2'
53
+ );
42
54
  </script>
43
55
 
44
56
  <!--
@@ -47,14 +59,17 @@
47
59
  with the top of the avatar.
48
60
  -->
49
61
  <div
50
- class="agent-turn flex w-full items-start gap-3 {className}"
62
+ class="agent-turn flex w-full items-start gap-2 {className}"
51
63
  data-testid="agent-turn"
52
64
  data-agent-turn-state={look.state}
53
65
  data-agent-turn-size={look.size}
54
66
  >
55
67
  <!-- A flex box, not a block: the avatar is an inline box, and in a block the line it sits on is taller than it (the strut of the
56
68
  line height hangs under it), which made this column a few pixels taller than the avatar and its middle fall below its own. -->
57
- <div class="flex shrink-0 self-start">
69
+ <div
70
+ class="flex shrink-0 self-start transition-[margin] duration-[420ms] ease-out motion-reduce:transition-none {faceColumnMarginClasses}"
71
+ data-testid="agent-turn-face"
72
+ >
58
73
  <AgentAvatar avatarState={look.state} size={look.size} live={look.live} {startSize} {startState} {renderAgentAvatar} />
59
74
  </div>
60
75
 
@@ -271,10 +271,12 @@
271
271
  ></pre>
272
272
  {/snippet}
273
273
 
274
+ <!-- A closed card is drawn like a chip: grey while the pointer is over it (`hover:bg-accent`, as the design system's Chip), and the whole of its
275
+ surface is the button that opens it (see the toggle below) -->
274
276
  <div
275
- class="rounded-card border-border bg-background flex w-full max-w-full min-w-0 flex-col border {isOpen
277
+ class="rounded-card border-border bg-background flex w-full max-w-full min-w-0 flex-col border relative transition-colors duration-fast {isOpen
276
278
  ? 'gap-3 p-4'
277
- : 'px-4 py-2'} {className}"
279
+ : 'hover:bg-accent px-4 py-2'} {className}"
278
280
  data-testid="code-card"
279
281
  data-open={isOpen}
280
282
  data-streaming={streaming}
@@ -282,9 +284,13 @@
282
284
  data-view={view}
283
285
  >
284
286
  <header class="flex min-w-0 items-center gap-2">
287
+ <!-- While the card is closed, the button stretches over the whole card (its `::after` covers the card, which is `relative`), so a press
288
+ anywhere on the card opens it and the pointer says so; open, it is only the title row -->
285
289
  <button
286
290
  type="button"
287
- class="text-foreground focus-visible:ring-ring flex min-h-7 min-w-0 flex-1 items-center gap-2 rounded-sm text-start focus-visible:ring-2 focus-visible:outline-none"
291
+ class="text-foreground focus-visible:ring-ring flex min-h-7 min-w-0 flex-1 items-center gap-2 rounded-sm text-start focus-visible:ring-2 focus-visible:outline-none {isOpen
292
+ ? ''
293
+ : 'cursor-pointer after:absolute after:inset-0'}"
288
294
  aria-expanded={isOpen}
289
295
  aria-controls={bodyId}
290
296
  onclick={toggleOpen}
@@ -3,4 +3,4 @@ export { PUBLISH_NUDGE_BY_LOCALE, PUBLISH_NUDGE_ENGLISH } from './publishNudgeLo
3
3
  export { CHAT_SKETCH_LOCALE_MESSAGES } from './sketchLocales.js';
4
4
  export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
5
5
  export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
6
- export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';
6
+ export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestions, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, type PanelStarterSuggestion, } from './suggestions.js';
@@ -3,4 +3,4 @@ export { PUBLISH_NUDGE_BY_LOCALE, PUBLISH_NUDGE_ENGLISH } from './publishNudgeLo
3
3
  export { CHAT_SKETCH_LOCALE_MESSAGES } from './sketchLocales.js';
4
4
  export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
5
5
  export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
6
- export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';
6
+ export { suggestionKeysFor, suggestionTitleKeyFor, panelEmptySuggestions, panelEmptySuggestionKeys, panelEmptySuggestionTitleKey, } from './suggestions.js';
@@ -137,12 +137,20 @@ export declare const CHAT_MESSAGES: {
137
137
  readonly 'chat.suggestions.title.document': "Suggested document actions";
138
138
  readonly 'chat.suggestions.title.other': "Suggested questions";
139
139
  readonly 'chat.suggestions.hide': "Hide suggestions";
140
- /** The ideas for a widget: tapping one sends it as the person's own message. */
140
+ /** The ideas for a widget: the few words a card shows. A click puts the whole request (the `…Request` message of the idea) in the message box; nothing is sent. */
141
141
  readonly 'chat.suggestions.panel.countdown': "A countdown to a sale";
142
142
  readonly 'chat.suggestions.panel.testimonials': "Customer testimonials";
143
143
  readonly 'chat.suggestions.panel.gallery': "A before and after gallery";
144
144
  readonly 'chat.suggestions.panel.changeEndDate': "Change the end date";
145
145
  readonly 'chat.suggestions.panel.biggerButton': "Make the button bigger";
146
+ /**
147
+ * The whole request behind each of the three ideas an empty chat offers to start a widget with. The card shows only the few words above;
148
+ * its tooltip (after the pointer rests on it, or the keyboard is on it) shows this, and a click puts exactly this in the message box.
149
+ * A request is written to be sent as it is: it says what to build and what it shows, and leaves the look to the person.
150
+ */
151
+ readonly 'chat.suggestions.panel.countdownRequest': "Create a countdown to a big sale. Show a bold headline, days, hours, minutes and seconds ticking down to an end date I can change, and a \"Shop now\" button underneath.";
152
+ readonly 'chat.suggestions.panel.testimonialsRequest': "Create a customer testimonials slider. Each slide shows a short quote, the name and photo of the customer and a star rating. The slides change on their own, with dots to move between them.";
153
+ readonly 'chat.suggestions.panel.galleryRequest': "Create a before and after gallery. Each item compares two versions of the same photo with a draggable divider, and visitors can flip through several photos.";
146
154
  /**
147
155
  * The follow-up card under the last reply (ideas for what to improve next, as small pills). The cross of a pill takes it out of
148
156
  * the card: `{title}` is the few words the pill shows ("Add a sale banner"). The heading of the card is `chat.suggestions.title.tryNext`.
@@ -205,7 +213,6 @@ export declare const CHAT_MESSAGES: {
205
213
  readonly 'chat.queue.sendNowTimeout': "The agent did not stop in time, so the message stays in the queue.";
206
214
  readonly 'chat.input.completionHint': "Tab to accept";
207
215
  readonly 'chat.input.completionHintTouch': "Tap the suggestion to accept";
208
- readonly 'chat.input.referenceHint': "Type # to reference an attached file";
209
216
  readonly 'chat.input.referenceMenuLabel': "Attached files";
210
217
  readonly 'chat.input.referenceRemove': "Remove {name}";
211
218
  readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
@@ -232,6 +239,11 @@ export declare const CHAT_MESSAGES: {
232
239
  readonly 'chat.checkpoint.version': "Version {n}";
233
240
  readonly 'chat.checkpoint.redo': "Redo";
234
241
  readonly 'chat.checkpoint.restored': "Restored to version {n}";
242
+ /** The question before the widget goes back to an earlier checkpoint: what is asked, what it costs, and the two buttons. */
243
+ readonly 'chat.checkpoint.confirmTitle': "Restore this checkpoint?";
244
+ readonly 'chat.checkpoint.confirmMessage': "You will lose the changes made after this checkpoint.";
245
+ readonly 'chat.checkpoint.confirmRestore': "Restore";
246
+ readonly 'chat.checkpoint.confirmCancel': "Cancel";
235
247
  readonly 'chat.actions.screenshot': "Screenshot";
236
248
  readonly 'chat.actions.screenshotTitle': "Take Screenshot";
237
249
  readonly 'chat.actions.screenshotLabel': "Take screenshot of current content";
@@ -244,6 +256,11 @@ export declare const CHAT_MESSAGES: {
244
256
  readonly 'chat.actions.upload': "Upload";
245
257
  readonly 'chat.actions.uploadTitle': "Upload File";
246
258
  readonly 'chat.actions.uploadLabel': "Upload file";
259
+ /**
260
+ * The tooltip of the "+" of the message box, after the pointer rests on it: what it adds. The box takes video and PDF too (they
261
+ * are kept with the message), but the builder reads only pictures, CSV and text, so the tooltip does not promise more.
262
+ */
263
+ readonly 'chat.actions.uploadTooltip': "Add images, CSV or text files. The builder does not read video or PDF yet.";
247
264
  readonly 'chat.actions.selector': "Selector";
248
265
  readonly 'chat.actions.selectorTitle': "Select a specific part of the widget to reference in chat";
249
266
  readonly 'chat.actions.selectorActiveTitle': "Disable widget element selector";
@@ -276,7 +293,6 @@ export declare const CHAT_MESSAGES: {
276
293
  /** What a picture of a typed message is called when its file has no name. */
277
294
  readonly 'chat.attachment.namelessAlt': "attachment";
278
295
  readonly 'chat.attachment.previewAlt': "Attachment preview";
279
- readonly 'chat.attachment.pdfTitle': "PDF Document";
280
296
  readonly 'chat.attachment.noVideo': "Your browser does not support video playback.";
281
297
  readonly 'chat.attachment.view': "Click to view {name}";
282
298
  readonly 'chat.attachment.viewFile': "Click to view file";
@@ -285,6 +301,36 @@ export declare const CHAT_MESSAGES: {
285
301
  /** What a screen reader says for a file chip while its file goes up: `{percent}` is the share sent, from 1 to 99. */
286
302
  readonly 'chat.attachment.uploadProgress': "Uploading, {percent}%";
287
303
  readonly 'chat.attachment.close': "Close";
304
+ /** The name of the group of files (and the group of pictures) a person sent with a message, for screen readers. */
305
+ readonly 'chat.attachment.sentFiles': "Files sent with this message";
306
+ readonly 'chat.attachment.sentPictures': "Pictures sent with this message";
307
+ /** The preview that opens from a file of the message box or of a sent message (the look of the File Browser's preview). */
308
+ readonly 'chat.preview.previous': "Previous file";
309
+ readonly 'chat.preview.next': "Next file";
310
+ readonly 'chat.preview.loading': "Loading preview";
311
+ readonly 'chat.preview.failed': "This file could not be loaded.";
312
+ readonly 'chat.preview.unavailable': "This kind of file has no preview.";
313
+ readonly 'chat.preview.truncated': "The rest of this file is not shown.";
314
+ /** The words of the PDF viewer inside that preview (`{page}` and `{total}` are the number of the page and of the pages). */
315
+ readonly 'chat.preview.pdfLoading': "Loading PDF…";
316
+ readonly 'chat.preview.pdfFailed': "Failed to load PDF";
317
+ readonly 'chat.preview.pdfPage': "Page {page} of {total}";
318
+ readonly 'chat.preview.pdfPreviousPage': "Previous page";
319
+ readonly 'chat.preview.pdfNextPage': "Next page";
320
+ /**
321
+ * What the whole chat says while files are dragged over it (Figma: Chat / Drop files, Chat / Drop not allowed). The kinds named
322
+ * are the ones the builder reads, as the tooltip of the "+" says (`chat.actions.uploadTooltip`).
323
+ */
324
+ readonly 'chat.drop.title': "Drop to attach";
325
+ readonly 'chat.drop.hint': "Images, CSV or text files";
326
+ readonly 'chat.drop.refusedTitle': "This file type is not supported";
327
+ readonly 'chat.drop.refusedHint': "Use images, CSV or text files";
328
+ /** Toasts for files that were dropped, picked or pasted and left out. `{name}` is the file's name, `{limit}` its kind's size limit ("10 MB"), `{count}` how many. */
329
+ readonly 'chat.attachment.refusedTypeOne': "“{name}” can’t be attached. Use images, video, PDF, CSV or text files.";
330
+ readonly 'chat.attachment.refusedTypeMany': "{count} files can’t be attached. Use images, video, PDF, CSV or text files.";
331
+ readonly 'chat.attachment.refusedSizeOne': "“{name}” is too large to attach. The limit is {limit}.";
332
+ readonly 'chat.attachment.refusedSizeMany': "{count} files are too large to attach.";
333
+ readonly 'chat.attachment.refusedFolder': "Folders can’t be attached. Drop the files inside them instead.";
288
334
  /** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
289
335
  readonly 'chat.size.bytes': "{size} B";
290
336
  readonly 'chat.size.kb': "{size} KB";
@@ -358,7 +404,9 @@ export declare const CHAT_MESSAGES: {
358
404
  readonly 'chat.sketch.failed': "Could not update the sketch. Please try again.";
359
405
  readonly 'chat.sketch.failedUnknown': "Could not update the sketch.";
360
406
  readonly 'chat.sketch.stepCap': "Sketch assistant stopped after too many steps.";
361
- readonly 'chat.sketch.noCredits': "You are out of credits, so I cannot draw right now. Add credits and ask me again.";
407
+ readonly 'chat.sketch.noCredits': "You're out of credits.";
408
+ readonly 'chat.sketch.planRequired': "Your plan doesn't include this.";
409
+ readonly 'chat.sketch.limitReached': "You've reached a usage limit.";
362
410
  readonly 'chat.sketch.busy': "A sketch is already being drawn, or you have sent too many requests. Try again in a moment.";
363
411
  readonly 'chat.sketch.unavailable': "The sketch assistant is not available right now. Please try again in a moment.";
364
412
  readonly 'chat.sketch.stopped': "Stopped drawing.";
@@ -142,12 +142,20 @@ export const CHAT_MESSAGES = {
142
142
  'chat.suggestions.title.document': 'Suggested document actions',
143
143
  'chat.suggestions.title.other': 'Suggested questions',
144
144
  'chat.suggestions.hide': 'Hide suggestions',
145
- /** The ideas for a widget: tapping one sends it as the person's own message. */
145
+ /** The ideas for a widget: the few words a card shows. A click puts the whole request (the `…Request` message of the idea) in the message box; nothing is sent. */
146
146
  'chat.suggestions.panel.countdown': 'A countdown to a sale',
147
147
  'chat.suggestions.panel.testimonials': 'Customer testimonials',
148
148
  'chat.suggestions.panel.gallery': 'A before and after gallery',
149
149
  'chat.suggestions.panel.changeEndDate': 'Change the end date',
150
150
  'chat.suggestions.panel.biggerButton': 'Make the button bigger',
151
+ /**
152
+ * The whole request behind each of the three ideas an empty chat offers to start a widget with. The card shows only the few words above;
153
+ * its tooltip (after the pointer rests on it, or the keyboard is on it) shows this, and a click puts exactly this in the message box.
154
+ * A request is written to be sent as it is: it says what to build and what it shows, and leaves the look to the person.
155
+ */
156
+ 'chat.suggestions.panel.countdownRequest': 'Create a countdown to a big sale. Show a bold headline, days, hours, minutes and seconds ticking down to an end date I can change, and a "Shop now" button underneath.',
157
+ 'chat.suggestions.panel.testimonialsRequest': 'Create a customer testimonials slider. Each slide shows a short quote, the name and photo of the customer and a star rating. The slides change on their own, with dots to move between them.',
158
+ 'chat.suggestions.panel.galleryRequest': 'Create a before and after gallery. Each item compares two versions of the same photo with a draggable divider, and visitors can flip through several photos.',
151
159
  /**
152
160
  * The follow-up card under the last reply (ideas for what to improve next, as small pills). The cross of a pill takes it out of
153
161
  * the card: `{title}` is the few words the pill shows ("Add a sale banner"). The heading of the card is `chat.suggestions.title.tryNext`.
@@ -213,9 +221,9 @@ export const CHAT_MESSAGES = {
213
221
  // What to do with the grey suggestion after the caret: shown in the toolbar while one shows, and said to a screen reader with it
214
222
  'chat.input.completionHint': 'Tab to accept',
215
223
  'chat.input.completionHintTouch': 'Tap the suggestion to accept',
216
- // Referring to an attached file with # in the message: the line under the box while a file is attached, the name a screen reader
217
- // gives the list of files that # opens, and the name of the X of a badge in the text ({name} is the file's own name)
218
- 'chat.input.referenceHint': 'Type # to reference an attached file',
224
+ // Referring to an attached file with # in the message: the name a screen reader gives the list of files that # opens, and the name
225
+ // of the X of a badge in the text ({name} is the file's own name). There is no line of help about it: nothing under the box, and
226
+ // nothing told to a screen reader either.
219
227
  'chat.input.referenceMenuLabel': 'Attached files',
220
228
  'chat.input.referenceRemove': 'Remove {name}',
221
229
  'chat.messages.scrollToBottom': 'Scroll to latest messages',
@@ -242,6 +250,11 @@ export const CHAT_MESSAGES = {
242
250
  'chat.checkpoint.version': 'Version {n}',
243
251
  'chat.checkpoint.redo': 'Redo',
244
252
  'chat.checkpoint.restored': 'Restored to version {n}',
253
+ /** The question before the widget goes back to an earlier checkpoint: what is asked, what it costs, and the two buttons. */
254
+ 'chat.checkpoint.confirmTitle': 'Restore this checkpoint?',
255
+ 'chat.checkpoint.confirmMessage': 'You will lose the changes made after this checkpoint.',
256
+ 'chat.checkpoint.confirmRestore': 'Restore',
257
+ 'chat.checkpoint.confirmCancel': 'Cancel',
245
258
  // ===== The buttons under the messages =====
246
259
  'chat.actions.screenshot': 'Screenshot',
247
260
  'chat.actions.screenshotTitle': 'Take Screenshot',
@@ -255,6 +268,11 @@ export const CHAT_MESSAGES = {
255
268
  'chat.actions.upload': 'Upload',
256
269
  'chat.actions.uploadTitle': 'Upload File',
257
270
  'chat.actions.uploadLabel': 'Upload file',
271
+ /**
272
+ * The tooltip of the "+" of the message box, after the pointer rests on it: what it adds. The box takes video and PDF too (they
273
+ * are kept with the message), but the builder reads only pictures, CSV and text, so the tooltip does not promise more.
274
+ */
275
+ 'chat.actions.uploadTooltip': 'Add images, CSV or text files. The builder does not read video or PDF yet.',
258
276
  'chat.actions.selector': 'Selector',
259
277
  'chat.actions.selectorTitle': 'Select a specific part of the widget to reference in chat',
260
278
  'chat.actions.selectorActiveTitle': 'Disable widget element selector',
@@ -289,7 +307,6 @@ export const CHAT_MESSAGES = {
289
307
  /** What a picture of a typed message is called when its file has no name. */
290
308
  'chat.attachment.namelessAlt': 'attachment',
291
309
  'chat.attachment.previewAlt': 'Attachment preview',
292
- 'chat.attachment.pdfTitle': 'PDF Document',
293
310
  'chat.attachment.noVideo': 'Your browser does not support video playback.',
294
311
  'chat.attachment.view': 'Click to view {name}',
295
312
  'chat.attachment.viewFile': 'Click to view file',
@@ -298,6 +315,36 @@ export const CHAT_MESSAGES = {
298
315
  /** What a screen reader says for a file chip while its file goes up: `{percent}` is the share sent, from 1 to 99. */
299
316
  'chat.attachment.uploadProgress': 'Uploading, {percent}%',
300
317
  'chat.attachment.close': 'Close',
318
+ /** The name of the group of files (and the group of pictures) a person sent with a message, for screen readers. */
319
+ 'chat.attachment.sentFiles': 'Files sent with this message',
320
+ 'chat.attachment.sentPictures': 'Pictures sent with this message',
321
+ /** The preview that opens from a file of the message box or of a sent message (the look of the File Browser's preview). */
322
+ 'chat.preview.previous': 'Previous file',
323
+ 'chat.preview.next': 'Next file',
324
+ 'chat.preview.loading': 'Loading preview',
325
+ 'chat.preview.failed': 'This file could not be loaded.',
326
+ 'chat.preview.unavailable': 'This kind of file has no preview.',
327
+ 'chat.preview.truncated': 'The rest of this file is not shown.',
328
+ /** The words of the PDF viewer inside that preview (`{page}` and `{total}` are the number of the page and of the pages). */
329
+ 'chat.preview.pdfLoading': 'Loading PDF…',
330
+ 'chat.preview.pdfFailed': 'Failed to load PDF',
331
+ 'chat.preview.pdfPage': 'Page {page} of {total}',
332
+ 'chat.preview.pdfPreviousPage': 'Previous page',
333
+ 'chat.preview.pdfNextPage': 'Next page',
334
+ /**
335
+ * What the whole chat says while files are dragged over it (Figma: Chat / Drop files, Chat / Drop not allowed). The kinds named
336
+ * are the ones the builder reads, as the tooltip of the "+" says (`chat.actions.uploadTooltip`).
337
+ */
338
+ 'chat.drop.title': 'Drop to attach',
339
+ 'chat.drop.hint': 'Images, CSV or text files',
340
+ 'chat.drop.refusedTitle': 'This file type is not supported',
341
+ 'chat.drop.refusedHint': 'Use images, CSV or text files',
342
+ /** Toasts for files that were dropped, picked or pasted and left out. `{name}` is the file's name, `{limit}` its kind's size limit ("10 MB"), `{count}` how many. */
343
+ 'chat.attachment.refusedTypeOne': '“{name}” can’t be attached. Use images, video, PDF, CSV or text files.',
344
+ 'chat.attachment.refusedTypeMany': '{count} files can’t be attached. Use images, video, PDF, CSV or text files.',
345
+ 'chat.attachment.refusedSizeOne': '“{name}” is too large to attach. The limit is {limit}.',
346
+ 'chat.attachment.refusedSizeMany': '{count} files are too large to attach.',
347
+ 'chat.attachment.refusedFolder': 'Folders can’t be attached. Drop the files inside them instead.',
301
348
  /** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
302
349
  'chat.size.bytes': '{size} B',
303
350
  'chat.size.kb': '{size} KB',
@@ -376,7 +423,12 @@ export const CHAT_MESSAGES = {
376
423
  'chat.sketch.failed': 'Could not update the sketch. Please try again.',
377
424
  'chat.sketch.failedUnknown': 'Could not update the sketch.',
378
425
  'chat.sketch.stepCap': 'Sketch assistant stopped after too many steps.',
379
- 'chat.sketch.noCredits': 'You are out of credits, so I cannot draw right now. Add credits and ask me again.',
426
+ // The three sentences for a refusal because of money. The chat knows them by their exact words (to draw "Upgrade" under them),
427
+ // so each is one whole sentence that no reply of the model is likely to be. The widget creator says the first two the same way.
428
+ 'chat.sketch.noCredits': "You're out of credits.",
429
+ 'chat.sketch.planRequired': "Your plan doesn't include this.",
430
+ // For the visitor of a page that is not their own: they have no credits or plan to name
431
+ 'chat.sketch.limitReached': "You've reached a usage limit.",
380
432
  'chat.sketch.busy': 'A sketch is already being drawn, or you have sent too many requests. Try again in a moment.',
381
433
  'chat.sketch.unavailable': 'The sketch assistant is not available right now. Please try again in a moment.',
382
434
  'chat.sketch.stopped': 'Stopped drawing.',
@@ -1,11 +1,26 @@
1
1
  import type { ChatMessageKey } from './messages.js';
2
+ /**
3
+ * The ideas the chat offers to start with, and the heading over them, for each kind of thing a chat can be about. They
4
+ * are message keys, so the words follow the language of the page, and a key (not the text) is what tells two ideas apart
5
+ * in a list: two ideas that a language happens to say with the same words are still two.
6
+ */
7
+ /**
8
+ * One starter idea of the empty docked chat. The card shows the few words (`titleKey`); the whole request (`requestKey`) is what
9
+ * the tooltip of the card shows and what a click puts in the message box, so the person reads what will be sent before picking it.
10
+ */
11
+ export interface PanelStarterSuggestion {
12
+ titleKey: ChatMessageKey;
13
+ requestKey: ChatMessageKey;
14
+ }
2
15
  /** The messages of the ideas offered for a kind of thing, in the order they are shown. */
3
16
  export declare function suggestionKeysFor(type: string): readonly ChatMessageKey[];
4
17
  /** The message of the heading over the ideas offered for a kind of thing. */
5
18
  export declare function suggestionTitleKeyFor(type: string): ChatMessageKey;
6
- /** Empty side-panel suggestions (creator dock), in display order. */
19
+ /** Empty side-panel suggestions (creator dock), in display order: the words of each card and the request behind it. */
20
+ export declare function panelEmptySuggestions(): readonly PanelStarterSuggestion[];
21
+ /** The few words of each empty side-panel suggestion, in display order (the cards' own words, without their requests). */
7
22
  export declare function panelEmptySuggestionKeys(): readonly ChatMessageKey[];
8
- /** Heading over the empty side-panel suggestions. */
23
+ /** Heading over the cards of the empty side-panel suggestions. */
9
24
  export declare function panelEmptySuggestionTitleKey(): ChatMessageKey;
10
25
  export declare function panelFollowUpSuggestionKeys(): readonly ChatMessageKey[];
11
26
  export declare function panelFollowUpSuggestionTitleKey(): ChatMessageKey;
@@ -1,13 +1,8 @@
1
- /**
2
- * The ideas the chat offers to start with, and the heading over them, for each kind of thing a chat can be about. They
3
- * are message keys, so the words follow the language of the page, and a key (not the text) is what tells two ideas apart
4
- * in a list: two ideas that a language happens to say with the same words are still two.
5
- */
6
1
  /** Figma side-panel empty state (widget creator): three starter ideas with icons. */
7
- const PANEL_EMPTY_SUGGESTION_KEYS = [
8
- 'chat.suggestions.panel.countdown',
9
- 'chat.suggestions.panel.testimonials',
10
- 'chat.suggestions.panel.gallery',
2
+ const PANEL_EMPTY_SUGGESTIONS = [
3
+ { titleKey: 'chat.suggestions.panel.countdown', requestKey: 'chat.suggestions.panel.countdownRequest' },
4
+ { titleKey: 'chat.suggestions.panel.testimonials', requestKey: 'chat.suggestions.panel.testimonialsRequest' },
5
+ { titleKey: 'chat.suggestions.panel.gallery', requestKey: 'chat.suggestions.panel.galleryRequest' },
11
6
  ];
12
7
  const PANEL_FOLLOW_UP_SUGGESTION_KEYS = [
13
8
  'chat.suggestions.panel.changeEndDate',
@@ -74,11 +69,15 @@ export function suggestionKeysFor(type) {
74
69
  export function suggestionTitleKeyFor(type) {
75
70
  return TITLE_KEYS[groupOf(type)];
76
71
  }
77
- /** Empty side-panel suggestions (creator dock), in display order. */
72
+ /** Empty side-panel suggestions (creator dock), in display order: the words of each card and the request behind it. */
73
+ export function panelEmptySuggestions() {
74
+ return PANEL_EMPTY_SUGGESTIONS;
75
+ }
76
+ /** The few words of each empty side-panel suggestion, in display order (the cards' own words, without their requests). */
78
77
  export function panelEmptySuggestionKeys() {
79
- return PANEL_EMPTY_SUGGESTION_KEYS;
78
+ return PANEL_EMPTY_SUGGESTIONS.map((suggestion) => suggestion.titleKey);
80
79
  }
81
- /** Heading over the empty side-panel suggestions. */
80
+ /** Heading over the cards of the empty side-panel suggestions. */
82
81
  export function panelEmptySuggestionTitleKey() {
83
82
  return 'chat.suggestions.title.panelEmpty';
84
83
  }
@@ -2,6 +2,8 @@ export { WidgeticChatService, createChatService } from './chatService.js';
2
2
  export type { ChatService, ChatInstance, ChatFactory } from '../types/index.js';
3
3
  export { startSketchAssistantRequest, sketchAssistantStepRequest, SketchAssistantRequestError } from './sketchAssistantClient.js';
4
4
  export type { SketchToolCall, SketchAssistantStartResponse, SketchSceneSummary, SketchAssistantContext } from './sketchAssistantClient.js';
5
- export { runSketchAssistantLoop, describeSketchRequestFailure } from './sketchAssistantOrchestrator.js';
6
- export type { CanvasSketchExecutor, SketchAssistantLoopResult } from './sketchAssistantOrchestrator.js';
5
+ export { runSketchAssistantLoop, describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantOrchestrator.js';
6
+ export type { CanvasSketchExecutor, SketchAssistantLoopResult, SketchFailureWording } from './sketchAssistantOrchestrator.js';
7
+ export { limitFailureKindOfRefusal } from './limitRefusal.js';
8
+ export type { LimitFailureKind, RefusalFacts } from './limitRefusal.js';
7
9
  export { buildSketchAssistantReply } from './sketchAssistantReply.js';
@@ -1,5 +1,6 @@
1
1
  // Chat Service
2
2
  export { WidgeticChatService, createChatService } from './chatService.js';
3
3
  export { startSketchAssistantRequest, sketchAssistantStepRequest, SketchAssistantRequestError } from './sketchAssistantClient.js';
4
- export { runSketchAssistantLoop, describeSketchRequestFailure } from './sketchAssistantOrchestrator.js';
4
+ export { runSketchAssistantLoop, describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantOrchestrator.js';
5
+ export { limitFailureKindOfRefusal } from './limitRefusal.js';
5
6
  export { buildSketchAssistantReply } from './sketchAssistantReply.js';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What a refusal of the gateway says about money.
3
+ *
4
+ * A request can be refused because the credits are used up, or because the plan does not include what was asked (a free
5
+ * trial that ended, an account that is not subscribed). Both end the same way for the person: nothing is wrong with the
6
+ * request, and the way out is to upgrade. Every other refusal (busy, down, a bad request) is not that, and is worded
7
+ * elsewhere. This file decides which is which, from what the gateway answered, in one place.
8
+ *
9
+ * What the gateway sends for each, as of this writing:
10
+ *
11
+ * - 402 `BILLING_INSUFFICIENT_CREDITS`: the credits are used up. Two other 402s are NOT a shortage and must never say so:
12
+ * "Could not read your credit balance. Please try again in a moment." (a lookup that failed) and "Credits are only
13
+ * supported for user accounts." (this kind of account holds none).
14
+ * - 403 `AUTHZ_PLAN_RESTRICTION`: the plan lacks the feature. The same refusal also arrives as a plain 403 whose only
15
+ * mark is its sentence ("…free trial has ended, so widget generation is not available in your plan…"), so the
16
+ * sentence is read for those.
17
+ * - An editor session (a partner's visitor) is refused with `error.details.limit` set to `credits` or `plan`.
18
+ *
19
+ * A 403 is also what an ordinary refusal looks like (a route a session may not use), so a 403 with none of those marks
20
+ * is not a limit.
21
+ *
22
+ * The widget creator keeps the same rules for its own failures (`host/limitRefusal.ts` and `errors/toUserFriendlyError.ts`
23
+ * there): the two packages are published apart, so each holds its copy, and each is tested against the words above.
24
+ */
25
+ /** Which limit refused the request. */
26
+ export type LimitFailureKind = 'credits' | 'plan';
27
+ /** What the gateway answered when it did not take a request. */
28
+ export interface RefusalFacts {
29
+ /** The HTTP status. */
30
+ status: number;
31
+ /** The code of the error envelope (for example `BILLING_INSUFFICIENT_CREDITS`). */
32
+ code?: string | null;
33
+ /** The gateway's own sentence. */
34
+ message?: string | null;
35
+ /** The `error.details` of the envelope; an editor session's refusal marks `limit` in it. */
36
+ details?: unknown;
37
+ }
38
+ /**
39
+ * Which limit refused a request, or `null` when the refusal is not about credits or the plan.
40
+ * Pure: nothing is logged here, so a caller can ask as often as it likes.
41
+ */
42
+ export declare function limitFailureKindOfRefusal(refusal: RefusalFacts): LimitFailureKind | null;