@widgetic/chat 0.1.45 → 0.1.48

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 (69) hide show
  1. package/README.md +148 -20
  2. package/dist/components/AttachmentDisplay.svelte +22 -130
  3. package/dist/components/AttachmentPreviewDialog.svelte +428 -0
  4. package/dist/components/AttachmentPreviewDialog.svelte.d.ts +14 -0
  5. package/dist/components/Chat.svelte +514 -94
  6. package/dist/components/Chat.svelte.d.ts +19 -2
  7. package/dist/components/ChatComposer.svelte +126 -72
  8. package/dist/components/ChatComposer.svelte.d.ts +13 -3
  9. package/dist/components/ChatDropOverlay.svelte +58 -0
  10. package/dist/components/ChatDropOverlay.svelte.d.ts +8 -0
  11. package/dist/components/ChatInput.svelte +42 -1
  12. package/dist/components/ChatInput.svelte.d.ts +2 -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/RestoreCheckpointDialog.svelte +66 -0
  20. package/dist/components/RestoreCheckpointDialog.svelte.d.ts +11 -0
  21. package/dist/components/SentAttachments.svelte +118 -0
  22. package/dist/components/SentAttachments.svelte.d.ts +12 -0
  23. package/dist/components/agent/AgentTurn.svelte +17 -2
  24. package/dist/components/agent/CodeCard.svelte +9 -3
  25. package/dist/i18n/messages.d.ts +45 -3
  26. package/dist/i18n/messages.js +51 -5
  27. package/dist/services/index.d.ts +4 -2
  28. package/dist/services/index.js +2 -1
  29. package/dist/services/limitRefusal.d.ts +42 -0
  30. package/dist/services/limitRefusal.js +60 -0
  31. package/dist/services/sketchAssistantClient.d.ts +11 -3
  32. package/dist/services/sketchAssistantClient.js +37 -10
  33. package/dist/services/sketchAssistantErrors.d.ts +16 -1
  34. package/dist/services/sketchAssistantErrors.js +25 -4
  35. package/dist/services/sketchAssistantOrchestrator.d.ts +7 -1
  36. package/dist/services/sketchAssistantOrchestrator.js +2 -2
  37. package/dist/types/attachment.d.ts +11 -0
  38. package/dist/utils/agentTurn.d.ts +32 -1
  39. package/dist/utils/agentTurn.js +46 -3
  40. package/dist/utils/attachmentDuplicates.d.ts +48 -0
  41. package/dist/utils/attachmentDuplicates.js +70 -0
  42. package/dist/utils/attachmentPolicy.d.ts +88 -0
  43. package/dist/utils/attachmentPolicy.js +135 -0
  44. package/dist/utils/attachmentPreview.d.ts +146 -0
  45. package/dist/utils/attachmentPreview.js +224 -0
  46. package/dist/utils/attachmentTray.d.ts +35 -0
  47. package/dist/utils/attachmentTray.js +27 -0
  48. package/dist/utils/chatFileDrag.d.ts +39 -0
  49. package/dist/utils/chatFileDrag.js +29 -0
  50. package/dist/utils/composerPreview.d.ts +33 -0
  51. package/dist/utils/composerPreview.js +31 -0
  52. package/dist/utils/generationArchiveStore.d.ts +5 -1
  53. package/dist/utils/generationArchiveStore.js +9 -4
  54. package/dist/utils/index.d.ts +1 -1
  55. package/dist/utils/index.js +1 -1
  56. package/dist/utils/limitFailureLine.d.ts +20 -0
  57. package/dist/utils/limitFailureLine.js +40 -0
  58. package/dist/utils/panelListPadding.d.ts +20 -0
  59. package/dist/utils/panelListPadding.js +31 -0
  60. package/dist/utils/pasteInsertion.d.ts +43 -0
  61. package/dist/utils/pasteInsertion.js +94 -0
  62. package/dist/utils/pastedContent.d.ts +13 -0
  63. package/dist/utils/pastedContent.js +18 -1
  64. package/dist/utils/referenceItems.js +11 -3
  65. package/dist/utils/sentAttachments.d.ts +43 -0
  66. package/dist/utils/sentAttachments.js +38 -0
  67. package/dist/utils/sentReferenceBadges.d.ts +11 -1
  68. package/dist/utils/sentReferenceBadges.js +47 -2
  69. package/package.json +3 -3
@@ -75,6 +75,14 @@ interface Props {
75
75
  * began, so a host that forgets to clear it never shows a run the changes of the run before.
76
76
  */
77
77
  generationChanges?: CodeChanges | null;
78
+ /**
79
+ * The agent's own words about what the last run changed, from the host (the gateway sends them with the completed operation,
80
+ * as `metadata.summary`). The conclusion under the run says them instead of "Done. Your changes are ready.". Give it when the
81
+ * operation completes (before or after `isGenerating` turns false: a value that comes after goes into the work of the run that
82
+ * just ended), and clear it when the next run starts; like the changes, the chat ignores the very value it held when a run began.
83
+ * Without it the conclusion keeps its catalog sentence.
84
+ */
85
+ generationSummary?: string | null;
78
86
  onSuggestionSelected?: (suggestion: string) => void;
79
87
  /**
80
88
  * What is in the message box now. The follow-up card under the last reply (ideas for what to improve next, as small pills)
@@ -85,9 +93,10 @@ interface Props {
85
93
  /**
86
94
  * Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
87
95
  * 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
88
- * and its place in `messages`. Without it no restore icon is drawn.
96
+ * and its place in `messages`. Without it no restore icon is drawn. The third word says whether it is a restore (which throws away
97
+ * what came after the checkpoint, so the chat asks to confirm it) or a redo (which brings that work back).
89
98
  */
90
- onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
99
+ onRestoreCheckpoint?: (messageId: string, messageIndex: number, kind?: 'restore' | 'redo') => void;
91
100
  /**
92
101
  * Gives the last message a thumbs up and a thumbs down (next to copy and regenerate). Called with the id of the assistant message
93
102
  * that announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
@@ -4,93 +4,181 @@
4
4
  import IconX from '@tabler/icons-svelte/icons/x';
5
5
  import { useChatLanguage } from '../i18n/language.js';
6
6
  import { attachmentChipProgress } from '../utils/attachmentProgress.js';
7
+ import { arrangeTrayAttachments, type TrayEntry } from '../utils/attachmentTray.js';
7
8
  import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
9
+ import { fileGlyphOf, previewKindOf, type FileGlyph } from '../utils/attachmentPreview.js';
8
10
  import { isHighlightedAttachment } from '../utils/referenceItems.js';
11
+ import FileGlyphIcon from './FileGlyphIcon.svelte';
9
12
 
10
13
  interface Props {
11
14
  attachments: AttachmentInput[];
12
15
  previewUrl: (attachment: AttachmentInput) => string;
13
16
  isImage: (attachment: AttachmentInput) => boolean;
17
+ /** Removes a file. The index is the file's place in `attachments` (the list as it was given, not as it is drawn). */
14
18
  onRemove: (index: number) => void;
15
- onOpenPreview?: (url: string) => void;
19
+ /**
20
+ * A picture, or a chip of a file that has a preview, was pressed: the page opens the file in its preview card. The page knows the
21
+ * files of the box, so it can give the card the arrows to the next one.
22
+ */
23
+ onOpenPreview?: (attachment: AttachmentInput) => void;
16
24
  /**
17
25
  * The label of the file a badge in the message or a row of the `#` menu is on: the tile of that file is ringed, so the person
18
26
  * sees which attachment the word stands for. Null (or a label no file has) rings nothing.
19
27
  */
20
28
  highlightedLabel?: string | null;
29
+ /**
30
+ * The files the person tried to attach again (they were in the tray already): their tiles are ringed for a moment, so the
31
+ * person sees that they are there and that they were not added a second time. None rings nothing.
32
+ */
33
+ flashedAttachmentIds?: readonly string[];
21
34
  }
22
35
 
23
- let { attachments, previewUrl, isImage, onRemove, onOpenPreview, highlightedLabel = null }: Props = $props();
36
+ let {
37
+ attachments,
38
+ previewUrl,
39
+ isImage,
40
+ onRemove,
41
+ onOpenPreview,
42
+ highlightedLabel = null,
43
+ flashedAttachmentIds = [],
44
+ }: Props = $props();
24
45
  const { t } = useChatLanguage();
25
46
 
26
47
  const IMAGE_PREVIEW_CSS_PX = 56;
27
48
 
49
+ // The files that are not pictures come first, each as a chip, and the pictures follow them below, whatever order they were added in.
50
+ // A text that was pasted has no tile here: it is a badge in the words of the message.
51
+ const arrangement = $derived(arrangeTrayAttachments(attachments, isImage));
52
+
53
+ /** What tells one tile from the others while the tray draws them (the id; two screenshots are both "image.png"). */
54
+ function tileKey(entry: TrayEntry): string | number {
55
+ const { attachment, index } = entry;
56
+ return attachment.id || attachment.preview || attachment.uploadedUrl || attachment.file?.name || index;
57
+ }
58
+
59
+ /** Whether the file of a chip can be opened in the preview card: its kind says so (the address is not needed: a text opens from the file). */
60
+ function isPreviewable(attachment: AttachmentInput): boolean {
61
+ return (
62
+ previewKindOf({ url: previewUrl(attachment), name: attachment.file?.name, type: attachment.file?.type }) !== null
63
+ );
64
+ }
65
+
66
+ /** The glyph in front of the name of a chip: what kind of file it is. */
67
+ function glyphOf(attachment: AttachmentInput): FileGlyph {
68
+ return fileGlyphOf({ url: previewUrl(attachment), name: attachment.file?.name, type: attachment.file?.type });
69
+ }
70
+
71
+ /** Whether a tile is ringed: the file a badge is on, or a file that was tried a second time. */
72
+ function isTileRinged(attachment: AttachmentInput): boolean {
73
+ return (
74
+ isHighlightedAttachment(attachment, highlightedLabel) ||
75
+ (!!attachment.id && flashedAttachmentIds.includes(attachment.id))
76
+ );
77
+ }
78
+
28
79
  /**
29
80
  * What a file chip is given while its file goes up: the share sent, which the chip draws as its own background, and how a
30
81
  * screen reader says it. Nothing while the file is not going up. The props go in as a spread because a design system older
31
- * than the one that brought `progress` does not know them and simply draws the chip without a fill.
82
+ * than the one that brought `progress` does not know them and simply draws the chip without a fill. (A picture shows no
83
+ * progress at all: its thumbnail is there, and that is all a person needs to see of it.)
32
84
  */
33
85
  function chipProgressProps(attachment: AttachmentInput): Record<string, unknown> {
34
86
  const shareSent = attachmentChipProgress(attachment.uploadProgress);
35
87
  if (shareSent === undefined) return {};
36
88
  return {
37
89
  progress: shareSent,
38
- progressLabel: $t('chat.attachment.uploadProgress', { percent: Math.round(shareSent) })
90
+ progressLabel: $t('chat.attachment.uploadProgress', { percent: Math.round(shareSent) }),
39
91
  };
40
92
  }
41
93
  </script>
42
94
 
43
- <div class="composer-attachments-tray flex flex-wrap gap-2 pb-2" data-testid="composer-attachments-tray">
44
- {#each attachments as attachment, index (attachment.id || attachment.preview || attachment.uploadedUrl || attachment.file?.name || index)}
45
- {@const rawUrl = previewUrl(attachment)}
46
- {@const highlighted = isHighlightedAttachment(attachment, highlightedLabel)}
47
- {#if isImage(attachment)}
48
- <div
49
- class="relative size-14 shrink-0 overflow-hidden rounded-lg border border-border bg-muted {highlighted ? 'ring-ring ring-2' : ''}"
50
- data-testid="composer-image-preview"
51
- data-label={attachment.referenceLabel}
52
- data-highlighted={highlighted ? 'true' : undefined}
53
- >
54
- <!-- svelte-ignore a11y_click_events_have_key_events -->
55
- <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
56
- <img
57
- src={buildImageThumbnailUrl(rawUrl, IMAGE_PREVIEW_CSS_PX) || rawUrl}
58
- alt={attachment.file?.name || $t('chat.attachment.namelessAlt')}
59
- class="size-full object-cover"
60
- onclick={() => rawUrl && onOpenPreview?.(rawUrl)}
61
- />
62
- <button
63
- type="button"
64
- class="absolute end-0.5 top-0.5 flex size-5 items-center justify-center rounded-full bg-background/90 text-muted-foreground shadow-sm hover:text-foreground"
65
- aria-label={$t('chat.attachment.remove')}
66
- onclick={() => onRemove(index)}
95
+ <!--
96
+ The files of the message, inside the message box over the text: the chips first, then the pictures as small thumbnails below them.
97
+ The box grows with them (its text scrolls when it has more than fits), so this has no height of its own.
98
+ -->
99
+ <div class="composer-attachments-tray flex w-full min-w-0 flex-col gap-2" data-testid="composer-attachments-tray">
100
+ {#if arrangement.chips.length > 0}
101
+ <div class="composer-attachment-chips flex min-w-0 flex-wrap gap-1.5 p-0.5" data-testid="composer-attachment-chips">
102
+ {#each arrangement.chips as entry (tileKey(entry))}
103
+ {@const ringed = isTileRinged(entry.attachment)}
104
+ {@const canPreview = isPreviewable(entry.attachment)}
105
+ <!-- A file that is not a picture is ringed through the box around its chip (the chip draws no ring of its own). The chip is a
106
+ label with an x, so a file that has a preview gets a button laid over the chip except over the x: pressing the name opens
107
+ the preview, pressing the x removes the file, and neither button is inside the other. -->
108
+ <span
109
+ class="group/chip relative inline-flex max-w-full rounded-lg {ringed ? 'ring-ring ring-2' : ''} has-[[data-chip-open]:focus-visible]:ring-ring has-[[data-chip-open]:focus-visible]:ring-2"
110
+ data-label={entry.attachment.referenceLabel}
111
+ data-highlighted={ringed ? 'true' : undefined}
112
+ >
113
+ <Chip
114
+ class={canPreview ? 'group-hover/chip:bg-accent' : ''}
115
+ label={entry.attachment.label || entry.attachment.file?.name || $t('chat.attachment.namelessAlt')}
116
+ showRemove={true}
117
+ removeLabel={$t('chat.attachment.remove')}
118
+ onRemove={() => onRemove(entry.index)}
119
+ {...chipProgressProps(entry.attachment)}
120
+ >
121
+ <!-- The glyph of the chip: what kind of file it is -->
122
+ {#snippet leading()}
123
+ <FileGlyphIcon glyph={glyphOf(entry.attachment)} />
124
+ {/snippet}
125
+ </Chip>
126
+ {#if canPreview}
127
+ <button
128
+ type="button"
129
+ class="absolute inset-y-0 start-0 end-7 cursor-pointer rounded-s-lg focus-visible:outline-none"
130
+ aria-label={$t('chat.attachment.view', { name: entry.attachment.label || entry.attachment.file?.name || $t('chat.attachment.namelessAlt') })}
131
+ onclick={() => onOpenPreview?.(entry.attachment)}
132
+ data-chip-open
133
+ data-testid="composer-file-preview"
134
+ ></button>
135
+ {/if}
136
+ </span>
137
+ {/each}
138
+ </div>
139
+ {/if}
140
+
141
+ {#if arrangement.pictures.length > 0}
142
+ <!-- The room above and at the end is for the cross of a thumbnail, which sits on its outer corner, and the room around is for the
143
+ ring of a thumbnail (the wrapper the box puts around this clips what leaves it). -->
144
+ <div class="composer-attachment-pictures flex min-w-0 flex-wrap gap-2 pb-0.5 ps-0.5 pe-1.5 pt-1.5" data-testid="composer-attachment-pictures">
145
+ {#each arrangement.pictures as entry (tileKey(entry))}
146
+ {@const rawUrl = previewUrl(entry.attachment)}
147
+ {@const ringed = isTileRinged(entry.attachment)}
148
+ <div
149
+ class="group relative size-14 shrink-0 rounded-lg {ringed ? 'ring-ring ring-2' : ''}"
150
+ data-testid="composer-image-preview"
151
+ data-label={entry.attachment.referenceLabel}
152
+ data-highlighted={ringed ? 'true' : undefined}
67
153
  >
68
- <IconX class="size-3.5 stroke-2" aria-hidden="true" />
69
- </button>
70
- {#if attachment.uploadProgress && attachment.uploadProgress > 0 && attachment.uploadProgress < 100}
71
- <div class="absolute inset-x-0 bottom-0 h-0.5 bg-border">
72
- <div
73
- class="bg-primary h-full transition-all duration-300"
74
- style="width: {attachment.uploadProgress}%"
75
- ></div>
76
- </div>
77
- {/if}
78
- </div>
79
- {:else}
80
- <!-- A file that is not a picture is ringed through the box around its chip (the chip draws no ring of its own). -->
81
- <span
82
- class="inline-flex rounded-full {highlighted ? 'ring-ring ring-2' : ''}"
83
- data-label={attachment.referenceLabel}
84
- data-highlighted={highlighted ? 'true' : undefined}
85
- >
86
- <Chip
87
- label={attachment.label || attachment.file?.name || $t('chat.attachment.namelessAlt')}
88
- showRemove={true}
89
- removeLabel={$t('chat.attachment.remove')}
90
- onRemove={() => onRemove(index)}
91
- {...chipProgressProps(attachment)}
92
- />
93
- </span>
94
- {/if}
95
- {/each}
154
+ <button
155
+ type="button"
156
+ class="border-border bg-muted block size-full cursor-zoom-in overflow-hidden rounded-lg border"
157
+ aria-label={entry.attachment.file?.name || $t('chat.attachment.namelessAlt')}
158
+ onclick={() => rawUrl && onOpenPreview?.(entry.attachment)}
159
+ >
160
+ <img
161
+ src={buildImageThumbnailUrl(rawUrl, IMAGE_PREVIEW_CSS_PX) || rawUrl}
162
+ alt=""
163
+ class="size-full object-cover"
164
+ draggable="false"
165
+ />
166
+ </button>
167
+ <!--
168
+ The cross shows only while the pointer (or the keyboard) is on the thumbnail, on its outer top-right corner and in the
169
+ dark colours of the interface. A touch screen has no hover, so there it stays.
170
+ -->
171
+ <button
172
+ type="button"
173
+ class="bg-inverse text-inverse-foreground hover:bg-inverse/90 focus-visible:ring-ring absolute -end-1.5 -top-1.5 flex size-5 cursor-pointer items-center justify-center rounded-full opacity-0 shadow-sm transition-opacity duration-150 group-focus-within:opacity-100 group-hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 pointer-coarse:opacity-100 motion-reduce:transition-none"
174
+ data-testid="composer-image-remove"
175
+ aria-label={$t('chat.attachment.remove')}
176
+ onclick={() => onRemove(entry.index)}
177
+ >
178
+ <IconX class="size-3 stroke-[2.5]" aria-hidden="true" />
179
+ </button>
180
+ </div>
181
+ {/each}
182
+ </div>
183
+ {/if}
96
184
  </div>
@@ -3,13 +3,23 @@ interface Props {
3
3
  attachments: AttachmentInput[];
4
4
  previewUrl: (attachment: AttachmentInput) => string;
5
5
  isImage: (attachment: AttachmentInput) => boolean;
6
+ /** Removes a file. The index is the file's place in `attachments` (the list as it was given, not as it is drawn). */
6
7
  onRemove: (index: number) => void;
7
- onOpenPreview?: (url: string) => void;
8
+ /**
9
+ * A picture, or a chip of a file that has a preview, was pressed: the page opens the file in its preview card. The page knows the
10
+ * files of the box, so it can give the card the arrows to the next one.
11
+ */
12
+ onOpenPreview?: (attachment: AttachmentInput) => void;
8
13
  /**
9
14
  * The label of the file a badge in the message or a row of the `#` menu is on: the tile of that file is ringed, so the person
10
15
  * sees which attachment the word stands for. Null (or a label no file has) rings nothing.
11
16
  */
12
17
  highlightedLabel?: string | null;
18
+ /**
19
+ * The files the person tried to attach again (they were in the tray already): their tiles are ringed for a moment, so the
20
+ * person sees that they are there and that they were not added a second time. None rings nothing.
21
+ */
22
+ flashedAttachmentIds?: readonly string[];
13
23
  }
14
24
  declare const ComposerAttachmentsTray: import("svelte").Component<Props, {}, "">;
15
25
  type ComposerAttachmentsTray = ReturnType<typeof ComposerAttachmentsTray>;
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The small glyph in front of the name of a file chip (in the message box and in a sent message): it says at a glance what the file
4
+ * is, a PDF, a video, a sheet, a text, or any other file. Which glyph a file gets is `fileGlyphOf`'s rule (`utils/attachmentPreview.ts`).
5
+ */
6
+ import IconFile from '@tabler/icons-svelte/icons/file';
7
+ import IconFileSpreadsheet from '@tabler/icons-svelte/icons/file-spreadsheet';
8
+ import IconFileText from '@tabler/icons-svelte/icons/file-text';
9
+ import IconFileTypePdf from '@tabler/icons-svelte/icons/file-type-pdf';
10
+ import IconVideo from '@tabler/icons-svelte/icons/video';
11
+ import type { FileGlyph } from '../utils/attachmentPreview.js';
12
+
13
+ interface Props {
14
+ glyph: FileGlyph;
15
+ class?: string;
16
+ }
17
+
18
+ let { glyph, class: className = '' }: Props = $props();
19
+
20
+ /** The look every glyph shares: 16 px, the muted colour of the words around it (the chip's name is the foreground colour). */
21
+ const glyphClasses = $derived(`text-muted-foreground size-4 shrink-0 stroke-2 ${className}`);
22
+ </script>
23
+
24
+ {#if glyph === 'pdf'}
25
+ <IconFileTypePdf class={glyphClasses} aria-hidden="true" data-testid="file-glyph-pdf" />
26
+ {:else if glyph === 'video'}
27
+ <IconVideo class={glyphClasses} aria-hidden="true" data-testid="file-glyph-video" />
28
+ {:else if glyph === 'sheet'}
29
+ <IconFileSpreadsheet class={glyphClasses} aria-hidden="true" data-testid="file-glyph-sheet" />
30
+ {:else if glyph === 'text'}
31
+ <IconFileText class={glyphClasses} aria-hidden="true" data-testid="file-glyph-text" />
32
+ {:else}
33
+ <IconFile class={glyphClasses} aria-hidden="true" data-testid="file-glyph-file" />
34
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { FileGlyph } from '../utils/attachmentPreview.js';
2
+ interface Props {
3
+ glyph: FileGlyph;
4
+ class?: string;
5
+ }
6
+ declare const FileGlyphIcon: import("svelte").Component<Props, {}, "">;
7
+ type FileGlyphIcon = ReturnType<typeof FileGlyphIcon>;
8
+ export default FileGlyphIcon;
@@ -0,0 +1,66 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The question a person is asked before the widget goes back to an earlier checkpoint: a restore throws away what came after the
4
+ * checkpoint, and the button that does it sits right under a message, where a click can happen by mistake. The question is the
5
+ * design system's action modal (the same card, motion and buttons as every other confirmation of the product); it says what is lost
6
+ * and keeps the destructive look on the button that confirms.
7
+ *
8
+ * The chat asks the question and the page does the restore: this component only tells which button was pressed.
9
+ */
10
+ import { ActionModal } from '@widgetic/design-system/components';
11
+ import { useChatLanguage } from '../i18n/language.js';
12
+ import { chatLog, chatWarn } from '../utils/logger.js';
13
+
14
+ interface Props {
15
+ /** Whether the question is open. */
16
+ open: boolean;
17
+ /** The person confirmed: the restore goes ahead. */
18
+ onConfirm: () => void;
19
+ /** The question was closed (the cancel button, the cross, Escape or a click beside the card): nothing changes. */
20
+ onCancel: () => void;
21
+ }
22
+
23
+ let { open, onConfirm, onCancel }: Props = $props();
24
+
25
+ const { t } = useChatLanguage();
26
+
27
+ /** The confirm button was pressed: the restore goes ahead (an error of the page must not leave the question open). */
28
+ async function handleConfirm(): Promise<void> {
29
+ try {
30
+ chatLog('[RestoreCheckpointDialog] The restore was confirmed.');
31
+ onConfirm();
32
+ } catch (error) {
33
+ chatWarn('[RestoreCheckpointDialog] The restore of the checkpoint failed:', error);
34
+ }
35
+ }
36
+
37
+ /** The question was closed without a confirmation. */
38
+ function handleCancel(): void {
39
+ chatLog('[RestoreCheckpointDialog] The restore was cancelled.');
40
+ onCancel();
41
+ }
42
+ </script>
43
+
44
+ <!--
45
+ The card is as tall as its words (`height="auto"`, like the product's other confirmations that say more than a line). The action
46
+ modal's own default is a fixed 168 px card, sized for a one-line message: this message takes two lines (and a translation may
47
+ take three), so in the fixed card the buttons sat on the bottom edge, with none of the padding the card has everywhere else.
48
+ -->
49
+ {#if open}
50
+ <ActionModal
51
+ isOpen={true}
52
+ title={$t('chat.checkpoint.confirmTitle')}
53
+ message={$t('chat.checkpoint.confirmMessage')}
54
+ confirmLabel={$t('chat.checkpoint.confirmRestore')}
55
+ cancelLabel={$t('chat.checkpoint.confirmCancel')}
56
+ closeLabel={$t('chat.attachment.close')}
57
+ width="450px"
58
+ height="auto"
59
+ confirmVariant="attention"
60
+ actionType="restoreCheckpoint"
61
+ modalType="restoreCheckpointConfirmation"
62
+ target="chat-restore-checkpoint-modal"
63
+ onConfirm={handleConfirm}
64
+ onCancel={handleCancel}
65
+ />
66
+ {/if}
@@ -0,0 +1,11 @@
1
+ interface Props {
2
+ /** Whether the question is open. */
3
+ open: boolean;
4
+ /** The person confirmed: the restore goes ahead. */
5
+ onConfirm: () => void;
6
+ /** The question was closed (the cancel button, the cross, Escape or a click beside the card): nothing changes. */
7
+ onCancel: () => void;
8
+ }
9
+ declare const RestoreCheckpointDialog: import("svelte").Component<Props, {}, "">;
10
+ type RestoreCheckpointDialog = ReturnType<typeof RestoreCheckpointDialog>;
11
+ export default RestoreCheckpointDialog;
@@ -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}