@widgetic/chat 0.1.41 → 0.1.43
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.
- package/README.md +461 -6
- package/dist/components/Chat.svelte +1117 -119
- package/dist/components/Chat.svelte.d.ts +112 -2
- package/dist/components/ChatComposer.svelte +389 -8
- package/dist/components/ChatComposer.svelte.d.ts +71 -2
- package/dist/components/ChatMessageQueue.svelte +56 -0
- package/dist/components/ChatMessageQueue.svelte.d.ts +20 -0
- package/dist/components/ChatMessages.svelte +477 -46
- package/dist/components/ChatMessages.svelte.d.ts +45 -2
- package/dist/components/ComposerAttachmentsTray.svelte +42 -10
- package/dist/components/ComposerAttachmentsTray.svelte.d.ts +5 -0
- package/dist/components/ComposerMentionChips.svelte +53 -0
- package/dist/components/ComposerMentionChips.svelte.d.ts +15 -0
- package/dist/components/FollowUpCard.svelte +134 -0
- package/dist/components/FollowUpCard.svelte.d.ts +17 -0
- package/dist/components/MentionChip.svelte +41 -0
- package/dist/components/MentionChip.svelte.d.ts +12 -0
- package/dist/components/MentionMenu.svelte +114 -0
- package/dist/components/MentionMenu.svelte.d.ts +19 -0
- package/dist/components/SelectedElementChip.svelte +73 -0
- package/dist/components/SelectedElementChip.svelte.d.ts +20 -0
- package/dist/components/agent/AgentAvatar.svelte +6 -4
- package/dist/components/agent/AgentAvatar.svelte.d.ts +1 -1
- package/dist/components/agent/CodeCard.svelte +122 -27
- package/dist/components/agent/CodeCard.svelte.d.ts +3 -0
- package/dist/components/agent/CodeDiff.svelte +180 -0
- package/dist/components/agent/CodeDiff.svelte.d.ts +10 -0
- package/dist/components/agent/GenerationModule.svelte +13 -2
- package/dist/components/agent/GenerationModule.svelte.d.ts +3 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +12 -0
- package/dist/errors/logTechnicalUserError.d.ts +1 -0
- package/dist/errors/logTechnicalUserError.js +37 -0
- package/dist/i18n/messages.d.ts +106 -1
- package/dist/i18n/messages.js +112 -1
- package/dist/i18n/sketchLocales.js +8 -8
- package/dist/messageQueue.d.ts +83 -0
- package/dist/messageQueue.js +84 -0
- package/dist/services/sketchAssistantClient.js +6 -2
- package/dist/services/sketchAssistantErrors.d.ts +4 -0
- package/dist/services/sketchAssistantErrors.js +22 -0
- package/dist/services/sketchAssistantOrchestrator.d.ts +1 -6
- package/dist/services/sketchAssistantOrchestrator.js +10 -24
- package/dist/services/sketchAssistantReply.js +3 -1
- package/dist/stores/chatStore.d.ts +5 -0
- package/dist/stores/chatStore.js +21 -0
- package/dist/types/agent.d.ts +4 -3
- package/dist/types/attachment.d.ts +16 -0
- package/dist/types/config.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/mention.d.ts +40 -0
- package/dist/types/mention.js +8 -0
- package/dist/types/message.d.ts +60 -1
- package/dist/utils/agentTurn.d.ts +40 -9
- package/dist/utils/agentTurn.js +43 -11
- package/dist/utils/attachmentProgress.d.ts +12 -0
- package/dist/utils/attachmentProgress.js +18 -0
- package/dist/utils/bubbleRichFit.d.ts +68 -0
- package/dist/utils/bubbleRichFit.js +45 -0
- package/dist/utils/bubbleShrinkWrap.d.ts +8 -1
- package/dist/utils/bubbleShrinkWrap.js +113 -17
- package/dist/utils/codeChanges.d.ts +103 -0
- package/dist/utils/codeChanges.js +226 -0
- package/dist/utils/codeHighlight.js +1 -0
- package/dist/utils/codeStreamFormat.d.ts +5 -2
- package/dist/utils/composerMentions.d.ts +96 -0
- package/dist/utils/composerMentions.js +217 -0
- package/dist/utils/followUps.d.ts +74 -0
- package/dist/utils/followUps.js +116 -0
- package/dist/utils/generationArchiveStore.d.ts +6 -0
- package/dist/utils/generationArchiveStore.js +11 -3
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/orderedLine.d.ts +29 -0
- package/dist/utils/orderedLine.js +17 -0
- package/dist/utils/pastedContent.d.ts +99 -0
- package/dist/utils/pastedContent.js +258 -0
- package/dist/utils/questionCards.d.ts +131 -0
- package/dist/utils/questionCards.js +287 -0
- package/dist/utils/referenceItems.d.ts +36 -0
- package/dist/utils/referenceItems.js +56 -0
- package/dist/utils/selectedElementChip.d.ts +47 -0
- package/dist/utils/selectedElementChip.js +73 -0
- package/dist/utils/sentReferenceBadges.d.ts +26 -0
- package/dist/utils/sentReferenceBadges.js +32 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
2
|
-
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
2
|
+
import type { ClarificationSuggestion, DesignControlRequest, QuestionCardAnswer, VersionRating } from '../types/message.js';
|
|
3
3
|
import type { AgentAvatarRenderer, AgentSoundPlayer, ChatMember } from '../types/agent.js';
|
|
4
|
+
import type { CodeChanges } from '../utils/codeChanges.js';
|
|
4
5
|
import { type VersionThumb } from '../utils/versionRatings.js';
|
|
5
6
|
import type { Snippet } from 'svelte';
|
|
6
7
|
import { type GenerationPlanWire } from '../utils/generationPlan.js';
|
|
@@ -59,9 +60,28 @@ interface Props {
|
|
|
59
60
|
generationStream?: string;
|
|
60
61
|
/** Rolling tail of streamed model reasoning during codegen. */
|
|
61
62
|
generationThinking?: string;
|
|
62
|
-
/** Gateway build plan while codegen runs; `null` hides the card. */
|
|
63
|
+
/** Gateway build plan while codegen runs; `null` hides the card (unless `generationPlanPending` shows it closed). */
|
|
63
64
|
generationPlan?: GenerationPlanWire | null;
|
|
65
|
+
/**
|
|
66
|
+
* The host asked for a plan and it has not arrived: the plan card shows closed, saying "Planning" in a shimmer, and opens when the
|
|
67
|
+
* plan comes. It ends by itself once code streams (the plan comes before the build). Default false: no card until the plan arrives.
|
|
68
|
+
*/
|
|
69
|
+
generationPlanPending?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* What the last run changed in the widget's files, from the host (the gateway works it out: see `readCodeChangesFromMetadata`).
|
|
72
|
+
* The chat keeps it with the work of that run and draws it as the "Changes" view of the code card under the conclusion.
|
|
73
|
+
* Give it when the operation completes (before or after `isGenerating` turns false: a value that comes after goes into the work
|
|
74
|
+
* of the run that just ended), and clear it when the next run starts; the chat also ignores the very value it held when a run
|
|
75
|
+
* began, so a host that forgets to clear it never shows a run the changes of the run before.
|
|
76
|
+
*/
|
|
77
|
+
generationChanges?: CodeChanges | null;
|
|
64
78
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
79
|
+
/**
|
|
80
|
+
* What is in the message box now. The follow-up card under the last reply (ideas for what to improve next, as small pills)
|
|
81
|
+
* shows a pill checked for as long as its request is in the box, and does not let the same request be added twice. Without
|
|
82
|
+
* it no pill is ever checked. Default: nothing.
|
|
83
|
+
*/
|
|
84
|
+
draftText?: string;
|
|
65
85
|
/**
|
|
66
86
|
* Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
|
|
67
87
|
* 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
|
|
@@ -86,6 +106,23 @@ interface Props {
|
|
|
86
106
|
* carrying the chip's structured intent. Chips are disabled while the host
|
|
87
107
|
* runs widget codegen (`isGenerating`). */
|
|
88
108
|
onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
|
|
109
|
+
/**
|
|
110
|
+
* The person pressed Skip on a question card (the id of the reply that asked it). The card has already gone and nothing was
|
|
111
|
+
* sent: the question stays in the conversation as a plain message. `Chat` uses this to put the cursor back in the message box.
|
|
112
|
+
*/
|
|
113
|
+
onQuestionSkipped?: (replyId: string) => void;
|
|
114
|
+
/**
|
|
115
|
+
* The person answered the card of questions of a reply (`ChatMessage.questionCard`) in the card itself: Submit on the last
|
|
116
|
+
* question, or Skip. `answers` is one answer for each question in the card's order (an empty answer is a question that was
|
|
117
|
+
* skipped: Next with nothing picked, or Skip), and `skippedAll` is true when none of them has a pick. `Chat` keeps the answers
|
|
118
|
+
* on the message, so the card is drawn closed, and tells its host. A card that is left by writing in the chat does not come
|
|
119
|
+
* through here: that message is sent with the skipped questions (`Chat` does it).
|
|
120
|
+
*/
|
|
121
|
+
onQuestionCardAnswered?: (detail: {
|
|
122
|
+
messageId: string;
|
|
123
|
+
answers: QuestionCardAnswer[];
|
|
124
|
+
skippedAll: boolean;
|
|
125
|
+
}) => void;
|
|
89
126
|
/** Host-rendered inline design-control card for messages carrying `designControls`. */
|
|
90
127
|
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
91
128
|
/** Host translation for lines saved in English (see Chat `storedLineLabel`). */
|
|
@@ -113,6 +150,12 @@ interface Props {
|
|
|
113
150
|
* does not wrap, and a message with code blocks, keep the width CSS gives them. On by default; pass `false` for CSS's widths.
|
|
114
151
|
*/
|
|
115
152
|
tightBubbles?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Draws a file badge (the picture and `#name`, without an X) for each word of a sent message that names a file attached to it,
|
|
155
|
+
* as the message box drew it while the message was written. The words are matched with the names of the message's pictures, and
|
|
156
|
+
* a word that cannot be matched for sure stays plain text. On by default; pass `false` for the text as it was sent.
|
|
157
|
+
*/
|
|
158
|
+
referenceBadges?: boolean;
|
|
116
159
|
/** Active conversation id — persists generation archive in IndexedDB across reload. */
|
|
117
160
|
conversationId?: string | null;
|
|
118
161
|
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
import { Chip } from '@widgetic/design-system/components/chat/index';
|
|
4
4
|
import IconX from '@tabler/icons-svelte/icons/x';
|
|
5
5
|
import { useChatLanguage } from '../i18n/language.js';
|
|
6
|
+
import { attachmentChipProgress } from '../utils/attachmentProgress.js';
|
|
6
7
|
import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
|
|
8
|
+
import { isHighlightedAttachment } from '../utils/referenceItems.js';
|
|
7
9
|
|
|
8
10
|
interface Props {
|
|
9
11
|
attachments: AttachmentInput[];
|
|
@@ -11,21 +13,43 @@
|
|
|
11
13
|
isImage: (attachment: AttachmentInput) => boolean;
|
|
12
14
|
onRemove: (index: number) => void;
|
|
13
15
|
onOpenPreview?: (url: string) => void;
|
|
16
|
+
/**
|
|
17
|
+
* 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
|
+
* sees which attachment the word stands for. Null (or a label no file has) rings nothing.
|
|
19
|
+
*/
|
|
20
|
+
highlightedLabel?: string | null;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
let { attachments, previewUrl, isImage, onRemove, onOpenPreview }: Props = $props();
|
|
23
|
+
let { attachments, previewUrl, isImage, onRemove, onOpenPreview, highlightedLabel = null }: Props = $props();
|
|
17
24
|
const { t } = useChatLanguage();
|
|
18
25
|
|
|
19
26
|
const IMAGE_PREVIEW_CSS_PX = 56;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 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
|
+
* 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.
|
|
32
|
+
*/
|
|
33
|
+
function chipProgressProps(attachment: AttachmentInput): Record<string, unknown> {
|
|
34
|
+
const shareSent = attachmentChipProgress(attachment.uploadProgress);
|
|
35
|
+
if (shareSent === undefined) return {};
|
|
36
|
+
return {
|
|
37
|
+
progress: shareSent,
|
|
38
|
+
progressLabel: $t('chat.attachment.uploadProgress', { percent: Math.round(shareSent) })
|
|
39
|
+
};
|
|
40
|
+
}
|
|
20
41
|
</script>
|
|
21
42
|
|
|
22
43
|
<div class="composer-attachments-tray flex flex-wrap gap-2 pb-2" data-testid="composer-attachments-tray">
|
|
23
|
-
{#each attachments as attachment, index (attachment.preview || attachment.uploadedUrl || attachment.file?.name || index)}
|
|
44
|
+
{#each attachments as attachment, index (attachment.id || attachment.preview || attachment.uploadedUrl || attachment.file?.name || index)}
|
|
24
45
|
{@const rawUrl = previewUrl(attachment)}
|
|
46
|
+
{@const highlighted = isHighlightedAttachment(attachment, highlightedLabel)}
|
|
25
47
|
{#if isImage(attachment)}
|
|
26
48
|
<div
|
|
27
|
-
class="relative size-14 shrink-0 overflow-hidden rounded-lg border border-border bg-muted"
|
|
49
|
+
class="relative size-14 shrink-0 overflow-hidden rounded-lg border border-border bg-muted {highlighted ? 'ring-ring ring-2' : ''}"
|
|
28
50
|
data-testid="composer-image-preview"
|
|
51
|
+
data-label={attachment.referenceLabel}
|
|
52
|
+
data-highlighted={highlighted ? 'true' : undefined}
|
|
29
53
|
>
|
|
30
54
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
31
55
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
@@ -53,12 +77,20 @@
|
|
|
53
77
|
{/if}
|
|
54
78
|
</div>
|
|
55
79
|
{:else}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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>
|
|
62
94
|
{/if}
|
|
63
95
|
{/each}
|
|
64
|
-
</div>
|
|
96
|
+
</div>
|
|
@@ -5,6 +5,11 @@ interface Props {
|
|
|
5
5
|
isImage: (attachment: AttachmentInput) => boolean;
|
|
6
6
|
onRemove: (index: number) => void;
|
|
7
7
|
onOpenPreview?: (url: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 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
|
+
* sees which attachment the word stands for. Null (or a label no file has) rings nothing.
|
|
11
|
+
*/
|
|
12
|
+
highlightedLabel?: string | null;
|
|
8
13
|
}
|
|
9
14
|
declare const ComposerAttachmentsTray: import("svelte").Component<Props, {}, "">;
|
|
10
15
|
type ComposerAttachmentsTray = ReturnType<typeof ComposerAttachmentsTray>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What the message mentions, inside the message box beside the chips of the parts picked on the preview: a chip for each pick,
|
|
3
|
+
then, for a link in the text that one of the page's lists is made for, a button that offers it ("Read this link with Figma").
|
|
4
|
+
A tap on that button is a pick like any other: it adds the chip and writes nothing into the text. Nothing is read or sent until
|
|
5
|
+
the message is sent.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import IconAt from '@tabler/icons-svelte/icons/at';
|
|
9
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
10
|
+
import type { ComposerMention } from '../types/mention.js';
|
|
11
|
+
import { mentionKey, type MentionLinkHint } from '../utils/composerMentions.js';
|
|
12
|
+
import MentionChip from './MentionChip.svelte';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
/** The picks of the message, in the order they were made. */
|
|
16
|
+
mentions: readonly ComposerMention[];
|
|
17
|
+
/** The links of the text that one of the lists is made for, to be offered as a pick. */
|
|
18
|
+
hints?: readonly MentionLinkHint[];
|
|
19
|
+
/** The cross of a chip was clicked. */
|
|
20
|
+
onRemove: (mention: ComposerMention) => void;
|
|
21
|
+
/** An offer was tapped. */
|
|
22
|
+
onPickHint: (hint: MentionLinkHint) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let { mentions, hints = [], onRemove, onPickHint }: Props = $props();
|
|
26
|
+
|
|
27
|
+
const { t } = useChatLanguage();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<div
|
|
31
|
+
class="prompt-chat-mentions-tray flex w-full min-w-0 flex-wrap items-center gap-1.5"
|
|
32
|
+
role="group"
|
|
33
|
+
aria-label={$t('chat.mentions.chipsLabel')}
|
|
34
|
+
data-testid="chat-mentions-tray"
|
|
35
|
+
>
|
|
36
|
+
{#each mentions as mention (mentionKey(mention.kind, mention.id))}
|
|
37
|
+
<MentionChip label={mention.name} removeLabel={$t('chat.mentions.remove', { name: mention.name })} onRemove={() => onRemove(mention)} />
|
|
38
|
+
{/each}
|
|
39
|
+
{#each hints as hint (hint.key)}
|
|
40
|
+
<!-- The mouse leaves the focus in the text box (a pick does not take the person out of what they are writing) -->
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
class="text-label-small text-muted-foreground hover:text-foreground hover:bg-accent border-border duration-fast focus-visible:ring-ring inline-flex h-7 max-w-full min-w-0 cursor-pointer items-center gap-1.5 rounded-lg border border-dashed px-2 transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
|
44
|
+
data-testid="chat-mention-link-hint"
|
|
45
|
+
title={hint.host}
|
|
46
|
+
onmousedown={(event) => event.preventDefault()}
|
|
47
|
+
onclick={() => onPickHint(hint)}
|
|
48
|
+
>
|
|
49
|
+
<IconAt class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
50
|
+
<span class="truncate" dir="auto">{$t('chat.mentions.linkHint', { name: hint.name })}</span>
|
|
51
|
+
</button>
|
|
52
|
+
{/each}
|
|
53
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComposerMention } from '../types/mention.js';
|
|
2
|
+
import { type MentionLinkHint } from '../utils/composerMentions.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The picks of the message, in the order they were made. */
|
|
5
|
+
mentions: readonly ComposerMention[];
|
|
6
|
+
/** The links of the text that one of the lists is made for, to be offered as a pick. */
|
|
7
|
+
hints?: readonly MentionLinkHint[];
|
|
8
|
+
/** The cross of a chip was clicked. */
|
|
9
|
+
onRemove: (mention: ComposerMention) => void;
|
|
10
|
+
/** An offer was tapped. */
|
|
11
|
+
onPickHint: (hint: MentionLinkHint) => void;
|
|
12
|
+
}
|
|
13
|
+
declare const ComposerMentionChips: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type ComposerMentionChips = ReturnType<typeof ComposerMentionChips>;
|
|
15
|
+
export default ComposerMentionChips;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The follow-up card: ideas for what to improve next on the widget the chat just built, as small pills under the last reply
|
|
4
|
+
* (Figma: Chat cards, "Follow-ups"; the component "Follow-up Card"). It is neither the starting suggestions nor a question:
|
|
5
|
+
* nothing is asked and nothing is chosen between, so the card has no "recommended" pill and no submit button.
|
|
6
|
+
*
|
|
7
|
+
* - A click puts the whole request in the message box (the host does that, through `onPick`). The pill then shows checked for
|
|
8
|
+
* as long as its words are in the box, and a checked pill is not picked a second time. Delete the words and it is ready again.
|
|
9
|
+
* "Checked" is read from the message box (`draftText`), never remembered here.
|
|
10
|
+
* - The cross takes a pill out of the card (`onDismiss`); words already in the box stay. The card goes with its last pill.
|
|
11
|
+
* - The tooltip shows the whole request while the pointer rests on a pill or the keyboard is on it.
|
|
12
|
+
*
|
|
13
|
+
* `Tooltip` comes from the components barrel of the design system, as `MemberAvatar`'s does: its export map has no path to it
|
|
14
|
+
* anywhere else. It shows no word of its own, only the request it is given. The pill is drawn here and not with the design
|
|
15
|
+
* system's `Chip` because the label of a `Chip` is not a button; the classes are the Chip's own, so both look the same.
|
|
16
|
+
*/
|
|
17
|
+
import { Tooltip } from '@widgetic/design-system/components';
|
|
18
|
+
import IconCheck from '@tabler/icons-svelte/icons/check';
|
|
19
|
+
import IconX from '@tabler/icons-svelte/icons/x';
|
|
20
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
21
|
+
import { panelFollowUpSuggestionTitleKey } from '../i18n/suggestions.js';
|
|
22
|
+
import { isRequestInDraft, type FollowUpPill } from '../utils/followUps.js';
|
|
23
|
+
|
|
24
|
+
// The words of the card, in the language of the chat above
|
|
25
|
+
const { t } = useChatLanguage();
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
/** The pills to draw, in order. */
|
|
29
|
+
pills: FollowUpPill[];
|
|
30
|
+
/** What is in the message box now: a pill whose request is in it shows checked. */
|
|
31
|
+
draftText?: string;
|
|
32
|
+
/** True while the chat cannot take a request (a run is going): the pills are drawn, and none can be picked or removed. */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** A pill was clicked. Never called for a pill that is checked. */
|
|
35
|
+
onPick: (pill: FollowUpPill) => void;
|
|
36
|
+
/** The cross of a pill was pressed. */
|
|
37
|
+
onDismiss: (pill: FollowUpPill) => void;
|
|
38
|
+
class?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let { pills, draftText = '', disabled = false, onPick, onDismiss, class: className = '' }: Props = $props();
|
|
42
|
+
|
|
43
|
+
// The heading names the list for a screen reader
|
|
44
|
+
const headingId = $props.id();
|
|
45
|
+
|
|
46
|
+
type TriggerProps = Record<string, unknown>;
|
|
47
|
+
|
|
48
|
+
/** The click of a pill: the tooltip's own handler first (it closes the tooltip), then the pick of the request. */
|
|
49
|
+
function handleLabelClick(triggerProps: TriggerProps, event: MouseEvent, pill: FollowUpPill, checked: boolean) {
|
|
50
|
+
try {
|
|
51
|
+
const closeTooltip = triggerProps.onclick;
|
|
52
|
+
if (typeof closeTooltip === 'function') closeTooltip(event);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.warn('[Chat] The follow-up tooltip could not be closed:', error);
|
|
55
|
+
}
|
|
56
|
+
// A checked pill already has its words in the box, and nothing is picked while the chat is busy
|
|
57
|
+
if (checked || disabled) return;
|
|
58
|
+
try {
|
|
59
|
+
onPick(pill);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('[Chat] A follow-up pill could not be picked:', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The cross of a pill: takes it out of the card. */
|
|
66
|
+
function handleRemoveClick(pill: FollowUpPill) {
|
|
67
|
+
if (disabled) return;
|
|
68
|
+
try {
|
|
69
|
+
onDismiss(pill);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('[Chat] A follow-up pill could not be removed:', error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<section
|
|
77
|
+
class="follow-up-card-ct rounded-card border-border bg-background flex w-full max-w-full flex-col gap-3 border p-4 {className}"
|
|
78
|
+
aria-labelledby={headingId}
|
|
79
|
+
data-testid="follow-up-card"
|
|
80
|
+
>
|
|
81
|
+
<p id={headingId} class="text-caption-medium text-muted-foreground">{$t(panelFollowUpSuggestionTitleKey())}</p>
|
|
82
|
+
<Tooltip.Provider delayDuration={200}>
|
|
83
|
+
<ul class="flex flex-wrap items-start gap-2">
|
|
84
|
+
{#each pills as pill (pill.id)}
|
|
85
|
+
{@const checked = isRequestInDraft(draftText, pill.request)}
|
|
86
|
+
<li class="flex max-w-full min-w-0" data-testid="follow-up-pill" data-checked={checked ? 'true' : 'false'}>
|
|
87
|
+
<!-- The pill: the same box as the design system's Chip (28 high, radius 8, a border), with the label as a button and the cross as another.
|
|
88
|
+
The focus ring is drawn around the whole pill when either of them is reached with the keyboard. -->
|
|
89
|
+
<div
|
|
90
|
+
class="border-border text-label-small duration-fast ring-offset-background has-[:focus-visible]:ring-ring inline-flex h-7 max-w-full min-w-0 items-center gap-1.5 rounded-lg border px-2 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-2 {checked
|
|
91
|
+
? 'bg-accent text-muted-foreground'
|
|
92
|
+
: 'text-foreground hover:bg-accent bg-transparent'} {disabled ? 'opacity-50' : ''}"
|
|
93
|
+
>
|
|
94
|
+
<Tooltip.Root>
|
|
95
|
+
<Tooltip.Trigger>
|
|
96
|
+
{#snippet child({ props }: { props: TriggerProps })}
|
|
97
|
+
<button
|
|
98
|
+
{...props}
|
|
99
|
+
type="button"
|
|
100
|
+
class="flex h-full min-w-0 items-center gap-1.5 focus-visible:outline-hidden {checked || disabled ? 'cursor-default' : 'cursor-pointer'}"
|
|
101
|
+
aria-pressed={checked}
|
|
102
|
+
{disabled}
|
|
103
|
+
data-testid="follow-up-pill-pick"
|
|
104
|
+
onclick={(event) => handleLabelClick(props, event, pill, checked)}
|
|
105
|
+
>
|
|
106
|
+
{#if checked}
|
|
107
|
+
<IconCheck class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
108
|
+
{/if}
|
|
109
|
+
<span class="truncate">{pill.title}</span>
|
|
110
|
+
</button>
|
|
111
|
+
{/snippet}
|
|
112
|
+
</Tooltip.Trigger>
|
|
113
|
+
<Tooltip.Portal>
|
|
114
|
+
<Tooltip.Content side="top" align="center" collisionPadding={8} data-testid="follow-up-tooltip">
|
|
115
|
+
{pill.request}
|
|
116
|
+
</Tooltip.Content>
|
|
117
|
+
</Tooltip.Portal>
|
|
118
|
+
</Tooltip.Root>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
class="text-muted-foreground hover:text-foreground inline-flex size-4 shrink-0 items-center justify-center focus-visible:outline-hidden"
|
|
122
|
+
aria-label={$t('chat.followUp.remove', { title: pill.title })}
|
|
123
|
+
{disabled}
|
|
124
|
+
data-testid="follow-up-pill-remove"
|
|
125
|
+
onclick={() => handleRemoveClick(pill)}
|
|
126
|
+
>
|
|
127
|
+
<IconX class="size-4 stroke-2" aria-hidden="true" />
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
</li>
|
|
131
|
+
{/each}
|
|
132
|
+
</ul>
|
|
133
|
+
</Tooltip.Provider>
|
|
134
|
+
</section>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FollowUpPill } from '../utils/followUps.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The pills to draw, in order. */
|
|
4
|
+
pills: FollowUpPill[];
|
|
5
|
+
/** What is in the message box now: a pill whose request is in it shows checked. */
|
|
6
|
+
draftText?: string;
|
|
7
|
+
/** True while the chat cannot take a request (a run is going): the pills are drawn, and none can be picked or removed. */
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** A pill was clicked. Never called for a pill that is checked. */
|
|
10
|
+
onPick: (pill: FollowUpPill) => void;
|
|
11
|
+
/** The cross of a pill was pressed. */
|
|
12
|
+
onDismiss: (pill: FollowUpPill) => void;
|
|
13
|
+
class?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const FollowUpCard: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type FollowUpCard = ReturnType<typeof FollowUpCard>;
|
|
17
|
+
export default FollowUpCard;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One pick of the `@` menu, as a chip in the message box: the name of what was picked, and a cross that takes the pick out of the
|
|
3
|
+
message. A chip is only a pick. Nothing is read or sent because of it until the message is sent, and the cross takes it back.
|
|
4
|
+
It looks like the chip of a part picked on the preview (`SelectedElementChip`), with an @ where that one has its number.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import IconAt from '@tabler/icons-svelte/icons/at';
|
|
8
|
+
import IconX from '@tabler/icons-svelte/icons/x';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
/** What the chip says: the name of what was picked. */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Name of the cross, for screen readers and its tooltip. */
|
|
14
|
+
removeLabel?: string;
|
|
15
|
+
/** The cross was clicked: take the pick out of the message. Left out, the chip has no cross. */
|
|
16
|
+
onRemove?: () => void;
|
|
17
|
+
class?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { label, removeLabel = 'Remove', onRemove, class: className = '' }: Props = $props();
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div
|
|
24
|
+
class="prompt-chat-mention-chip text-label-small text-foreground border-border bg-background duration-fast inline-flex h-7 max-w-full min-w-0 items-center gap-1.5 rounded-lg border ps-2 pe-1.5 transition-colors {className}"
|
|
25
|
+
title={label}
|
|
26
|
+
data-testid="chat-mention-chip"
|
|
27
|
+
>
|
|
28
|
+
<IconAt class="text-muted-foreground size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
29
|
+
<span class="truncate" dir="auto">{label}</span>
|
|
30
|
+
{#if onRemove}
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
class="text-muted-foreground hover:text-foreground focus-visible:ring-ring inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm focus-visible:ring-2 focus-visible:outline-hidden"
|
|
34
|
+
aria-label={removeLabel}
|
|
35
|
+
title={removeLabel}
|
|
36
|
+
onclick={() => onRemove?.()}
|
|
37
|
+
>
|
|
38
|
+
<IconX class="size-4 stroke-2" aria-hidden="true" />
|
|
39
|
+
</button>
|
|
40
|
+
{/if}
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** What the chip says: the name of what was picked. */
|
|
3
|
+
label: string;
|
|
4
|
+
/** Name of the cross, for screen readers and its tooltip. */
|
|
5
|
+
removeLabel?: string;
|
|
6
|
+
/** The cross was clicked: take the pick out of the message. Left out, the chip has no cross. */
|
|
7
|
+
onRemove?: () => void;
|
|
8
|
+
class?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const MentionChip: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type MentionChip = ReturnType<typeof MentionChip>;
|
|
12
|
+
export default MentionChip;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The menu that opens over the message box while the person types `@`: the rows of the lists the page gave (`mentionSources` of
|
|
3
|
+
`Chat`), the highlighted one picked with Enter or Tab, or with a tap. A row that cannot be picked is shown dimmed, with the reason in
|
|
4
|
+
place of its second line, and the arrow keys pass over it. The groups are labelled only when rows of two kinds are shown.
|
|
5
|
+
|
|
6
|
+
The text box keeps the focus the whole time: the keys it hears drive the menu, and a press on a row does not move the focus
|
|
7
|
+
(that is what the `mousedown` is for). Put it inside a box that is `relative`: it opens upward from the top edge of that box.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import IconAt from '@tabler/icons-svelte/icons/at';
|
|
11
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
12
|
+
import { mentionOptionId, mentionRowsHaveSeveralKinds, type MentionRow } from '../utils/composerMentions.js';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
/** The rows to show, in order (`buildMentionRows`). */
|
|
16
|
+
rows: readonly MentionRow[];
|
|
17
|
+
/** The place of the highlighted row in `rows`. */
|
|
18
|
+
highlightIndex: number;
|
|
19
|
+
/** The most picks a message holds, said on the rows that wait for room. */
|
|
20
|
+
limit: number;
|
|
21
|
+
/** Gives the list and its rows ids, so the text box can say which row is highlighted (`aria-activedescendant`). */
|
|
22
|
+
listId: string;
|
|
23
|
+
/** A row that can be picked was chosen. */
|
|
24
|
+
onSelect: (row: MentionRow) => void;
|
|
25
|
+
/** The pointer moved onto a row that can be picked. */
|
|
26
|
+
onHighlight?: (index: number) => void;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface MentionGroup {
|
|
31
|
+
kind: string;
|
|
32
|
+
label: string;
|
|
33
|
+
rows: Array<{ row: MentionRow; index: number }>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let { rows, highlightIndex, limit, listId, onSelect, onHighlight, class: className = '' }: Props = $props();
|
|
37
|
+
|
|
38
|
+
const { t } = useChatLanguage();
|
|
39
|
+
|
|
40
|
+
// The rows in groups, each row with its place in the whole list, which the highlight is counted in.
|
|
41
|
+
const groups = $derived.by(() => {
|
|
42
|
+
const grouped: MentionGroup[] = [];
|
|
43
|
+
rows.forEach((row, index) => {
|
|
44
|
+
const last = grouped[grouped.length - 1];
|
|
45
|
+
if (last && last.kind === row.kind) last.rows.push({ row, index });
|
|
46
|
+
else grouped.push({ kind: row.kind, label: row.groupLabel, rows: [{ row, index }] });
|
|
47
|
+
});
|
|
48
|
+
return grouped;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// One group needs no label: the person sees one kind of thing and knows what it is.
|
|
52
|
+
const labelsGroups = $derived(mentionRowsHaveSeveralKinds(rows));
|
|
53
|
+
|
|
54
|
+
/** The second line of a row: why it cannot be picked, or else what the page said under its name. */
|
|
55
|
+
function captionOf(row: MentionRow): string {
|
|
56
|
+
if (row.unavailable === 'limit') return $t('chat.mentions.limitReached', { count: limit });
|
|
57
|
+
if (row.unavailable === 'source') return row.item.unavailableReason?.trim() || row.item.caption || '';
|
|
58
|
+
return row.item.caption ?? '';
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<!-- A press anywhere on the menu (its scroll bar too) leaves the focus in the text box: the list is never in the tab order (`tabindex="-1"`) -->
|
|
63
|
+
<div
|
|
64
|
+
class="border-border bg-popover absolute start-2 end-2 bottom-full z-20 mb-1 max-h-64 max-w-sm overflow-auto rounded-xl border p-1 shadow-md {className}"
|
|
65
|
+
role="listbox"
|
|
66
|
+
tabindex="-1"
|
|
67
|
+
aria-label={$t('chat.mentions.menuLabel')}
|
|
68
|
+
id={listId}
|
|
69
|
+
data-testid="chat-mention-menu"
|
|
70
|
+
onmousedown={(event) => event.preventDefault()}
|
|
71
|
+
>
|
|
72
|
+
<div class="flex flex-col gap-0.5">
|
|
73
|
+
<!-- Keyed by the first row, which is different for every row: two lists of one kind that are not next to each other are two groups -->
|
|
74
|
+
{#each groups as group (group.rows[0].row.key)}
|
|
75
|
+
<div role="group" aria-label={group.label || undefined} class="flex flex-col gap-0.5">
|
|
76
|
+
{#if labelsGroups}
|
|
77
|
+
<p class="text-caption text-muted-foreground px-2 pt-1.5" aria-hidden="true">{group.label}</p>
|
|
78
|
+
{/if}
|
|
79
|
+
{#each group.rows as entry (entry.row.key)}
|
|
80
|
+
{@const selectable = entry.row.selectable}
|
|
81
|
+
{@const highlighted = selectable && entry.index === highlightIndex}
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
role="option"
|
|
85
|
+
tabindex="-1"
|
|
86
|
+
id={mentionOptionId(listId, entry.index)}
|
|
87
|
+
aria-selected={highlighted}
|
|
88
|
+
aria-disabled={!selectable}
|
|
89
|
+
class="text-body text-foreground flex w-full min-w-0 items-center gap-3 rounded-lg px-2 py-1.5 text-start transition-colors {selectable
|
|
90
|
+
? 'hover:bg-accent cursor-pointer'
|
|
91
|
+
: 'cursor-not-allowed opacity-60'} {highlighted ? 'bg-accent' : ''}"
|
|
92
|
+
data-testid="chat-mention-option"
|
|
93
|
+
onmouseenter={() => {
|
|
94
|
+
if (selectable) onHighlight?.(entry.index);
|
|
95
|
+
}}
|
|
96
|
+
onclick={() => {
|
|
97
|
+
if (selectable) onSelect(entry.row);
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<span class="bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-lg">
|
|
101
|
+
<IconAt class="size-4 stroke-2" aria-hidden="true" />
|
|
102
|
+
</span>
|
|
103
|
+
<span class="flex min-w-0 flex-1 flex-col text-start">
|
|
104
|
+
<span class="text-body-medium truncate" dir="auto">{entry.row.item.name}</span>
|
|
105
|
+
{#if captionOf(entry.row)}
|
|
106
|
+
<span class="text-caption text-muted-foreground truncate" dir="auto">{captionOf(entry.row)}</span>
|
|
107
|
+
{/if}
|
|
108
|
+
</span>
|
|
109
|
+
</button>
|
|
110
|
+
{/each}
|
|
111
|
+
</div>
|
|
112
|
+
{/each}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MentionRow } from '../utils/composerMentions.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The rows to show, in order (`buildMentionRows`). */
|
|
4
|
+
rows: readonly MentionRow[];
|
|
5
|
+
/** The place of the highlighted row in `rows`. */
|
|
6
|
+
highlightIndex: number;
|
|
7
|
+
/** The most picks a message holds, said on the rows that wait for room. */
|
|
8
|
+
limit: number;
|
|
9
|
+
/** Gives the list and its rows ids, so the text box can say which row is highlighted (`aria-activedescendant`). */
|
|
10
|
+
listId: string;
|
|
11
|
+
/** A row that can be picked was chosen. */
|
|
12
|
+
onSelect: (row: MentionRow) => void;
|
|
13
|
+
/** The pointer moved onto a row that can be picked. */
|
|
14
|
+
onHighlight?: (index: number) => void;
|
|
15
|
+
class?: string;
|
|
16
|
+
}
|
|
17
|
+
declare const MentionMenu: import("svelte").Component<Props, {}, "">;
|
|
18
|
+
type MentionMenu = ReturnType<typeof MentionMenu>;
|
|
19
|
+
export default MentionMenu;
|