@majapisoftwares/ui 6.6.0 → 6.8.0
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/AGENTS.md +2 -1
- package/docs/STANDARDS.md +17 -6
- package/package.json +6 -2
- package/scripts/check-standards.mjs +2 -2
- package/src/components/ui/code-block.tsx +246 -0
- package/src/components/ui/marker.tsx +72 -0
- package/src/components/ui/message-scroller.tsx +1 -1
- package/src/components/ui/snackbar.tsx +22 -70
- package/src/components/ui/sonner.tsx +36 -3
- package/src/components/ui/toast.tsx +250 -0
- package/src/hooks/use-highlighted-code.ts +77 -0
- package/src/lib/highlighter.tsx +124 -0
- package/src/lib/i18n.tsx +81 -0
- package/src/lib/utils.ts +16 -0
- package/src/patterns/chat-checkpoint.tsx +49 -0
- package/src/patterns/chat-citation.tsx +57 -0
- package/src/patterns/chat-context.tsx +82 -0
- package/src/patterns/chat-trace.tsx +739 -9
- package/src/patterns/chat.tsx +119 -4
- package/src/patterns/file-tree.tsx +122 -0
- package/src/patterns/model-selector.tsx +153 -0
- package/src/patterns/preferences.tsx +2 -2
- package/src/patterns/prompt-input.tsx +18 -0
package/src/patterns/chat.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type ComponentProps,
|
|
10
10
|
type ReactNode,
|
|
11
11
|
} from "react";
|
|
12
|
-
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
12
|
+
import { CheckIcon, CopyIcon, ReplyIcon, XIcon } from "lucide-react";
|
|
13
13
|
import { cn } from "../lib/utils";
|
|
14
14
|
import { useUiMessages } from "../lib/i18n";
|
|
15
15
|
import { Button } from "../components/ui/button";
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
MessageScrollerContent,
|
|
26
26
|
MessageScrollerProvider,
|
|
27
27
|
MessageScrollerViewport,
|
|
28
|
+
useMessageScroller,
|
|
28
29
|
useMessageScrollerGutterWidth,
|
|
29
30
|
} from "../components/ui/message-scroller";
|
|
30
31
|
import { Orb } from "../components/ui/orb";
|
|
@@ -98,7 +99,7 @@ export function ChatMessages({
|
|
|
98
99
|
<MessageScrollerViewport ref={viewportRef}>
|
|
99
100
|
<MessageScrollerContent
|
|
100
101
|
aria-busy={busy}
|
|
101
|
-
className="mx-auto w-full max-w-3xl pb-6"
|
|
102
|
+
className="mx-auto w-full max-w-3xl pt-6 pb-6"
|
|
102
103
|
>
|
|
103
104
|
{children}
|
|
104
105
|
</MessageScrollerContent>
|
|
@@ -139,6 +140,8 @@ export interface ChatMessageProps
|
|
|
139
140
|
from: "user" | "assistant";
|
|
140
141
|
/** Files or images sent with a person's message, above the bubble. */
|
|
141
142
|
attachments?: ReactNode;
|
|
143
|
+
/** The message this one replies to (a `ChatQuote`), above its text. */
|
|
144
|
+
quote?: ReactNode;
|
|
142
145
|
/** Actions or the time under the message. A person's footer shows on hover. */
|
|
143
146
|
footer?: ReactNode;
|
|
144
147
|
}
|
|
@@ -146,10 +149,13 @@ export interface ChatMessageProps
|
|
|
146
149
|
/**
|
|
147
150
|
* One turn. A person's text sits in a muted bubble on the end side; the
|
|
148
151
|
* agent's reply is unboxed so markdown, reasoning and tools read as a page.
|
|
152
|
+
* Either footer (actions, time) shows on hover or focus; on touch screens it
|
|
153
|
+
* stays visible.
|
|
149
154
|
*/
|
|
150
155
|
export function ChatMessage({
|
|
151
156
|
from,
|
|
152
157
|
attachments,
|
|
158
|
+
quote,
|
|
153
159
|
footer,
|
|
154
160
|
children,
|
|
155
161
|
...props
|
|
@@ -159,9 +165,12 @@ export function ChatMessage({
|
|
|
159
165
|
<Message align="end" data-from="user" {...props}>
|
|
160
166
|
<MessageContent>
|
|
161
167
|
{attachments}
|
|
162
|
-
{children ? (
|
|
168
|
+
{children || quote ? (
|
|
163
169
|
<Bubble align="end" variant="muted">
|
|
164
170
|
<BubbleContent className="whitespace-pre-wrap">
|
|
171
|
+
{quote ? (
|
|
172
|
+
<div className={cn("whitespace-normal", children ? "mb-1.5" : undefined)}>{quote}</div>
|
|
173
|
+
) : null}
|
|
165
174
|
{children}
|
|
166
175
|
</BubbleContent>
|
|
167
176
|
</Bubble>
|
|
@@ -178,8 +187,13 @@ export function ChatMessage({
|
|
|
178
187
|
return (
|
|
179
188
|
<Message data-from="assistant" {...props}>
|
|
180
189
|
<MessageContent>
|
|
190
|
+
{quote ? <div className="max-w-md">{quote}</div> : null}
|
|
181
191
|
{children}
|
|
182
|
-
{footer ?
|
|
192
|
+
{footer ? (
|
|
193
|
+
<MessageFooter className="px-0 transition-opacity md:opacity-0 md:group-hover/message:opacity-100 md:group-focus-within/message:opacity-100">
|
|
194
|
+
{footer}
|
|
195
|
+
</MessageFooter>
|
|
196
|
+
) : null}
|
|
183
197
|
</MessageContent>
|
|
184
198
|
</Message>
|
|
185
199
|
);
|
|
@@ -257,6 +271,107 @@ export function CopyMessageAction({ text }: { text: string }) {
|
|
|
257
271
|
);
|
|
258
272
|
}
|
|
259
273
|
|
|
274
|
+
/** Starts a reply to the message, as in messaging apps. */
|
|
275
|
+
export function ReplyMessageAction({ onReply }: { onReply: () => void }) {
|
|
276
|
+
const messages = useUiMessages();
|
|
277
|
+
return (
|
|
278
|
+
<MessageAction label={messages.reply} onClick={onReply}>
|
|
279
|
+
<ReplyIcon />
|
|
280
|
+
</MessageAction>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface ChatQuoteProps extends ComponentProps<"div"> {
|
|
285
|
+
/** Who wrote the quoted message. */
|
|
286
|
+
author: ReactNode;
|
|
287
|
+
/** In the transcript: selecting the quote scrolls to this message. */
|
|
288
|
+
messageId?: string;
|
|
289
|
+
/** In the composer: shows a button that cancels the reply. */
|
|
290
|
+
onDismiss?: () => void;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function QuoteBody({ author, children }: { author: ReactNode; children: ReactNode }) {
|
|
294
|
+
return (
|
|
295
|
+
<>
|
|
296
|
+
<span className="block truncate font-medium text-foreground">{author}</span>
|
|
297
|
+
<span className="line-clamp-2 break-words text-muted-foreground">
|
|
298
|
+
{children}
|
|
299
|
+
</span>
|
|
300
|
+
</>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function QuoteJump({
|
|
305
|
+
messageId,
|
|
306
|
+
author,
|
|
307
|
+
children,
|
|
308
|
+
}: {
|
|
309
|
+
messageId: string;
|
|
310
|
+
author: ReactNode;
|
|
311
|
+
children: ReactNode;
|
|
312
|
+
}) {
|
|
313
|
+
const { scrollToMessage } = useMessageScroller();
|
|
314
|
+
return (
|
|
315
|
+
<Button
|
|
316
|
+
type="button"
|
|
317
|
+
variant="ghost"
|
|
318
|
+
className="h-auto min-w-0 flex-1 flex-col items-stretch gap-0 rounded-[inherit] px-2.5 py-1.5 text-left text-xs font-normal whitespace-normal hover:bg-transparent"
|
|
319
|
+
onClick={() => scrollToMessage(messageId, { align: "center", behavior: "smooth" })}
|
|
320
|
+
>
|
|
321
|
+
<QuoteBody author={author}>{children}</QuoteBody>
|
|
322
|
+
</Button>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The message a reply refers to: its author and the start of its text. Pass
|
|
328
|
+
* it as `quote` to `ChatMessage` (with `messageId`, it jumps to the original)
|
|
329
|
+
* or to `PromptInput` while the person writes the reply (with `onDismiss`).
|
|
330
|
+
*/
|
|
331
|
+
export function ChatQuote({
|
|
332
|
+
author,
|
|
333
|
+
messageId,
|
|
334
|
+
onDismiss,
|
|
335
|
+
className,
|
|
336
|
+
children,
|
|
337
|
+
...props
|
|
338
|
+
}: ChatQuoteProps) {
|
|
339
|
+
const messages = useUiMessages();
|
|
340
|
+
return (
|
|
341
|
+
<div
|
|
342
|
+
data-slot="chat-quote"
|
|
343
|
+
className={cn(
|
|
344
|
+
"flex min-w-0 items-start rounded-lg border-l-2 border-primary bg-foreground/5 text-xs",
|
|
345
|
+
className,
|
|
346
|
+
)}
|
|
347
|
+
{...props}
|
|
348
|
+
>
|
|
349
|
+
{messageId ? (
|
|
350
|
+
<QuoteJump messageId={messageId} author={author}>
|
|
351
|
+
{children}
|
|
352
|
+
</QuoteJump>
|
|
353
|
+
) : (
|
|
354
|
+
<div className="min-w-0 flex-1 px-2.5 py-1.5">
|
|
355
|
+
<QuoteBody author={author}>{children}</QuoteBody>
|
|
356
|
+
</div>
|
|
357
|
+
)}
|
|
358
|
+
{onDismiss ? (
|
|
359
|
+
<Button
|
|
360
|
+
type="button"
|
|
361
|
+
variant="ghost"
|
|
362
|
+
size="icon-xs"
|
|
363
|
+
aria-label={messages.cancelReply}
|
|
364
|
+
className="m-1 size-11 shrink-0 text-muted-foreground md:size-6"
|
|
365
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
366
|
+
onClick={onDismiss}
|
|
367
|
+
>
|
|
368
|
+
<XIcon />
|
|
369
|
+
</Button>
|
|
370
|
+
) : null}
|
|
371
|
+
</div>
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
260
375
|
/** Shown while the agent works on a reply and nothing has streamed yet. */
|
|
261
376
|
export function TypingIndicator({
|
|
262
377
|
label,
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ChevronRightIcon, FileIcon, FolderIcon } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/utils";
|
|
5
|
+
import { Button } from "../components/ui/button";
|
|
6
|
+
import {
|
|
7
|
+
Collapsible,
|
|
8
|
+
CollapsibleContent,
|
|
9
|
+
CollapsibleTrigger,
|
|
10
|
+
} from "../components/ui/collapsible";
|
|
11
|
+
|
|
12
|
+
export type FileTreeNode =
|
|
13
|
+
| { type: "file"; name: string; path: string }
|
|
14
|
+
| { type: "folder"; name: string; path: string; children: FileTreeNode[] };
|
|
15
|
+
|
|
16
|
+
export interface FileTreeProps {
|
|
17
|
+
files: FileTreeNode[];
|
|
18
|
+
/** The selected file's path. */
|
|
19
|
+
selected?: string;
|
|
20
|
+
onSelect?: (path: string) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function Node({
|
|
24
|
+
node,
|
|
25
|
+
selected,
|
|
26
|
+
onSelect,
|
|
27
|
+
}: {
|
|
28
|
+
node: FileTreeNode;
|
|
29
|
+
selected?: string;
|
|
30
|
+
onSelect?: (path: string) => void;
|
|
31
|
+
}) {
|
|
32
|
+
if (node.type === "folder")
|
|
33
|
+
return (
|
|
34
|
+
<Collapsible defaultOpen>
|
|
35
|
+
<CollapsibleTrigger
|
|
36
|
+
render={
|
|
37
|
+
<Button
|
|
38
|
+
variant="ghost"
|
|
39
|
+
size="sm"
|
|
40
|
+
className="w-full justify-start font-normal aria-expanded:bg-transparent aria-expanded:hover:bg-muted dark:aria-expanded:hover:bg-muted/50"
|
|
41
|
+
/>
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
<ChevronRightIcon className="transition-transform group-data-panel-open/button:rotate-90" />
|
|
45
|
+
<FolderIcon />
|
|
46
|
+
{node.name}
|
|
47
|
+
</CollapsibleTrigger>
|
|
48
|
+
<CollapsibleContent>
|
|
49
|
+
<div className="ml-4 flex flex-col">
|
|
50
|
+
{node.children.map((child) => (
|
|
51
|
+
<Node
|
|
52
|
+
key={child.path}
|
|
53
|
+
node={child}
|
|
54
|
+
selected={selected}
|
|
55
|
+
onSelect={onSelect}
|
|
56
|
+
/>
|
|
57
|
+
))}
|
|
58
|
+
</div>
|
|
59
|
+
</CollapsibleContent>
|
|
60
|
+
</Collapsible>
|
|
61
|
+
);
|
|
62
|
+
return (
|
|
63
|
+
<Button
|
|
64
|
+
variant="ghost"
|
|
65
|
+
size="sm"
|
|
66
|
+
className={cn(
|
|
67
|
+
"w-full justify-start font-normal",
|
|
68
|
+
selected === node.path && "bg-accent text-accent-foreground",
|
|
69
|
+
)}
|
|
70
|
+
aria-current={selected === node.path ? "true" : undefined}
|
|
71
|
+
onClick={() => onSelect?.(node.path)}
|
|
72
|
+
>
|
|
73
|
+
<FileIcon />
|
|
74
|
+
{node.name}
|
|
75
|
+
</Button>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The files an agent changed, as folders that open and files to pick (shadcn
|
|
81
|
+
* AI Elements File Tree). For one file it read or edited, use a Tool line.
|
|
82
|
+
*/
|
|
83
|
+
export function FileTree({ files, selected, onSelect }: FileTreeProps) {
|
|
84
|
+
return (
|
|
85
|
+
<div className="flex w-full flex-col text-sm">
|
|
86
|
+
{files.map((node) => (
|
|
87
|
+
<Node
|
|
88
|
+
key={node.path}
|
|
89
|
+
node={node}
|
|
90
|
+
selected={selected}
|
|
91
|
+
onSelect={onSelect}
|
|
92
|
+
/>
|
|
93
|
+
))}
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Builds the tree from paths ("app/page.tsx", "app/layout.tsx" → app/ with two files). */
|
|
99
|
+
export function fileTree(paths: string[]): FileTreeNode[] {
|
|
100
|
+
const root: FileTreeNode[] = [];
|
|
101
|
+
for (const path of paths) {
|
|
102
|
+
const parts = path.split("/").filter(Boolean);
|
|
103
|
+
let level = root;
|
|
104
|
+
parts.forEach((name, index) => {
|
|
105
|
+
const at = parts.slice(0, index + 1).join("/");
|
|
106
|
+
if (index === parts.length - 1) {
|
|
107
|
+
level.push({ type: "file", name, path: at });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let folder = level.find(
|
|
111
|
+
(node): node is Extract<FileTreeNode, { type: "folder" }> =>
|
|
112
|
+
node.type === "folder" && node.path === at,
|
|
113
|
+
);
|
|
114
|
+
if (!folder) {
|
|
115
|
+
folder = { type: "folder", name, path: at, children: [] };
|
|
116
|
+
level.push(folder);
|
|
117
|
+
}
|
|
118
|
+
level = folder.children;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return root;
|
|
122
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
5
|
+
import { useUiMessages } from "../lib/i18n";
|
|
6
|
+
import {
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuGroup,
|
|
10
|
+
DropdownMenuLabel,
|
|
11
|
+
DropdownMenuRadioGroup,
|
|
12
|
+
DropdownMenuRadioItem,
|
|
13
|
+
DropdownMenuSeparator,
|
|
14
|
+
DropdownMenuTrigger,
|
|
15
|
+
} from "../components/ui/dropdown-menu";
|
|
16
|
+
import { InputGroupButton } from "../components/ui/input-group";
|
|
17
|
+
|
|
18
|
+
export interface ModelOption {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ModelProvider {
|
|
24
|
+
name: string;
|
|
25
|
+
models: ModelOption[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ModelSelectorProps {
|
|
29
|
+
providers: ModelProvider[];
|
|
30
|
+
/** The selected model's id. */
|
|
31
|
+
value: string;
|
|
32
|
+
onValueChange: (value: string) => void;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Picks the model for the next message (shadcn AI Elements Model Selector),
|
|
38
|
+
* grouped by provider. Put it in the prompt input's `actions`.
|
|
39
|
+
*/
|
|
40
|
+
export function ModelSelector({
|
|
41
|
+
providers,
|
|
42
|
+
value,
|
|
43
|
+
onValueChange,
|
|
44
|
+
disabled,
|
|
45
|
+
}: ModelSelectorProps) {
|
|
46
|
+
const messages = useUiMessages();
|
|
47
|
+
const current =
|
|
48
|
+
providers
|
|
49
|
+
.flatMap((provider) => provider.models)
|
|
50
|
+
.find((m) => m.id === value) ?? providers[0]?.models[0];
|
|
51
|
+
return (
|
|
52
|
+
<DropdownMenu>
|
|
53
|
+
<DropdownMenuTrigger
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
render={
|
|
56
|
+
<InputGroupButton
|
|
57
|
+
size="sm"
|
|
58
|
+
variant="outline"
|
|
59
|
+
className="h-11 rounded-full md:h-8"
|
|
60
|
+
aria-label={
|
|
61
|
+
current ? messages.modelIs(current.name) : messages.model
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
{current?.name ?? messages.model}
|
|
67
|
+
<ChevronDownIcon />
|
|
68
|
+
</DropdownMenuTrigger>
|
|
69
|
+
<DropdownMenuContent align="start" className="w-56">
|
|
70
|
+
<DropdownMenuRadioGroup
|
|
71
|
+
value={value}
|
|
72
|
+
onValueChange={(next) => onValueChange(String(next))}
|
|
73
|
+
>
|
|
74
|
+
{providers.map((provider, index) => (
|
|
75
|
+
<Fragment key={provider.name}>
|
|
76
|
+
{index > 0 ? <DropdownMenuSeparator /> : null}
|
|
77
|
+
<DropdownMenuGroup>
|
|
78
|
+
<DropdownMenuLabel>{provider.name}</DropdownMenuLabel>
|
|
79
|
+
{provider.models.map((model) => (
|
|
80
|
+
<DropdownMenuRadioItem
|
|
81
|
+
key={model.id}
|
|
82
|
+
value={model.id}
|
|
83
|
+
closeOnClick
|
|
84
|
+
>
|
|
85
|
+
{model.name}
|
|
86
|
+
</DropdownMenuRadioItem>
|
|
87
|
+
))}
|
|
88
|
+
</DropdownMenuGroup>
|
|
89
|
+
</Fragment>
|
|
90
|
+
))}
|
|
91
|
+
</DropdownMenuRadioGroup>
|
|
92
|
+
</DropdownMenuContent>
|
|
93
|
+
</DropdownMenu>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface EffortSelectorProps {
|
|
98
|
+
efforts: ModelOption[];
|
|
99
|
+
value: string;
|
|
100
|
+
onValueChange: (value: string) => void;
|
|
101
|
+
disabled?: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Picks how hard the model thinks (the Model Selector's effort menu). */
|
|
105
|
+
export function EffortSelector({
|
|
106
|
+
efforts,
|
|
107
|
+
value,
|
|
108
|
+
onValueChange,
|
|
109
|
+
disabled,
|
|
110
|
+
}: EffortSelectorProps) {
|
|
111
|
+
const messages = useUiMessages();
|
|
112
|
+
const current = efforts.find((effort) => effort.id === value) ?? efforts[0];
|
|
113
|
+
return (
|
|
114
|
+
<DropdownMenu>
|
|
115
|
+
<DropdownMenuTrigger
|
|
116
|
+
disabled={disabled}
|
|
117
|
+
render={
|
|
118
|
+
<InputGroupButton
|
|
119
|
+
size="sm"
|
|
120
|
+
variant="outline"
|
|
121
|
+
className="h-11 rounded-full md:h-8"
|
|
122
|
+
aria-label={
|
|
123
|
+
current ? messages.effortIs(current.name) : messages.effort
|
|
124
|
+
}
|
|
125
|
+
/>
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
<span className="text-muted-foreground">{messages.effort}</span>
|
|
129
|
+
{current?.name}
|
|
130
|
+
<ChevronDownIcon />
|
|
131
|
+
</DropdownMenuTrigger>
|
|
132
|
+
<DropdownMenuContent align="start" className="w-40">
|
|
133
|
+
<DropdownMenuGroup>
|
|
134
|
+
<DropdownMenuLabel>{messages.effort}</DropdownMenuLabel>
|
|
135
|
+
<DropdownMenuRadioGroup
|
|
136
|
+
value={value}
|
|
137
|
+
onValueChange={(next) => onValueChange(String(next))}
|
|
138
|
+
>
|
|
139
|
+
{efforts.map((effort) => (
|
|
140
|
+
<DropdownMenuRadioItem
|
|
141
|
+
key={effort.id}
|
|
142
|
+
value={effort.id}
|
|
143
|
+
closeOnClick
|
|
144
|
+
>
|
|
145
|
+
{effort.name}
|
|
146
|
+
</DropdownMenuRadioItem>
|
|
147
|
+
))}
|
|
148
|
+
</DropdownMenuRadioGroup>
|
|
149
|
+
</DropdownMenuGroup>
|
|
150
|
+
</DropdownMenuContent>
|
|
151
|
+
</DropdownMenu>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type Locale,
|
|
17
17
|
} from "../lib/i18n";
|
|
18
18
|
import { Button } from "../components/ui/button";
|
|
19
|
-
import {
|
|
19
|
+
import { Toaster } from "../components/ui/toast";
|
|
20
20
|
import {
|
|
21
21
|
DropdownMenu,
|
|
22
22
|
DropdownMenuContent,
|
|
@@ -131,7 +131,7 @@ export function Preferences({
|
|
|
131
131
|
<PreferencesReadyContext.Provider value={ready}>
|
|
132
132
|
<LocaleProvider locale={locale}>
|
|
133
133
|
{children}
|
|
134
|
-
<
|
|
134
|
+
<Toaster />
|
|
135
135
|
</LocaleProvider>
|
|
136
136
|
</PreferencesReadyContext.Provider>
|
|
137
137
|
</PreferencesContext.Provider>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
isValidElement,
|
|
4
5
|
useEffect,
|
|
5
6
|
useRef,
|
|
6
7
|
useState,
|
|
@@ -67,6 +68,11 @@ export interface PromptInputProps {
|
|
|
67
68
|
maxFiles?: number;
|
|
68
69
|
/** Extra controls in the bottom bar, before the send button (e.g. a model menu). */
|
|
69
70
|
actions?: ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* The message being replied to (a `ChatQuote` with `onDismiss`), above the
|
|
73
|
+
* field. The field takes focus when a quote appears or its `key` changes.
|
|
74
|
+
*/
|
|
75
|
+
quote?: ReactNode;
|
|
70
76
|
className?: string;
|
|
71
77
|
"aria-label"?: string;
|
|
72
78
|
}
|
|
@@ -136,6 +142,7 @@ export function PromptInput({
|
|
|
136
142
|
accept,
|
|
137
143
|
maxFiles,
|
|
138
144
|
actions,
|
|
145
|
+
quote,
|
|
139
146
|
className,
|
|
140
147
|
"aria-label": ariaLabel,
|
|
141
148
|
}: PromptInputProps) {
|
|
@@ -155,6 +162,12 @@ export function PromptInput({
|
|
|
155
162
|
filesRef.current = files;
|
|
156
163
|
}, [files]);
|
|
157
164
|
|
|
165
|
+
// Starting a reply (or replying to another message) puts the cursor in the field.
|
|
166
|
+
const quoteKey = quote ? (isValidElement(quote) && quote.key !== null ? quote.key : true) : null;
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (quoteKey !== null) textareaRef.current?.focus();
|
|
169
|
+
}, [quoteKey]);
|
|
170
|
+
|
|
158
171
|
// Release previews that are still attached when the composer unmounts.
|
|
159
172
|
useEffect(
|
|
160
173
|
() => () => {
|
|
@@ -267,6 +280,11 @@ export function PromptInput({
|
|
|
267
280
|
data-dragging={dragging || undefined}
|
|
268
281
|
className="data-dragging:border-ring data-dragging:ring-3 data-dragging:ring-ring/30"
|
|
269
282
|
>
|
|
283
|
+
{quote ? (
|
|
284
|
+
<InputGroupAddon align="block-start" className="cursor-default pb-0">
|
|
285
|
+
<div className="w-full min-w-0">{quote}</div>
|
|
286
|
+
</InputGroupAddon>
|
|
287
|
+
) : null}
|
|
270
288
|
{files.length > 0 ? (
|
|
271
289
|
<InputGroupAddon align="block-start" className="cursor-default">
|
|
272
290
|
<AttachmentGroup aria-label={messages.attachments} className="w-full">
|