@majapisoftwares/ui 6.2.2 → 6.4.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 +27 -27
- package/README.md +79 -79
- package/THIRD_PARTY_NOTICES.md +39 -39
- package/components.json +25 -25
- package/docs/MIGRATION-0.2.md +20 -20
- package/docs/MIGRATION-6.0.md +33 -33
- package/docs/NEXT-STARTER-VALIDATION.md +14 -14
- package/docs/STANDARDS.md +65 -43
- package/docs/VALIDATION.md +11 -11
- package/docs/VERSIONING.md +32 -28
- package/docs/validation/preference-titles.md +22 -22
- package/package.json +91 -88
- package/scripts/check-standards.mjs +41 -41
- package/src/components/ui/accordion.tsx +82 -82
- package/src/components/ui/alert-dialog.tsx +187 -187
- package/src/components/ui/alert.tsx +77 -77
- package/src/components/ui/attachment.tsx +209 -0
- package/src/components/ui/avatar.tsx +108 -108
- package/src/components/ui/badge.tsx +55 -55
- package/src/components/ui/breadcrumb.tsx +125 -125
- package/src/components/ui/bubble.tsx +129 -0
- package/src/components/ui/button-group.tsx +89 -89
- package/src/components/ui/button.tsx +59 -59
- package/src/components/ui/card.tsx +101 -101
- package/src/components/ui/checkbox.tsx +27 -27
- package/src/components/ui/collapsible.tsx +21 -21
- package/src/components/ui/context-menu.tsx +271 -271
- package/src/components/ui/dialog.tsx +161 -161
- package/src/components/ui/dropdown-menu.tsx +271 -271
- package/src/components/ui/empty.tsx +105 -105
- package/src/components/ui/field.tsx +238 -238
- package/src/components/ui/hover-card.tsx +50 -50
- package/src/components/ui/input-group.tsx +155 -155
- package/src/components/ui/input.tsx +21 -21
- package/src/components/ui/item.tsx +203 -0
- package/src/components/ui/kbd.tsx +28 -28
- package/src/components/ui/label.tsx +19 -19
- package/src/components/ui/message-scroller.tsx +166 -0
- package/src/components/ui/message.tsx +93 -0
- package/src/components/ui/orb.css +1002 -1002
- package/src/components/ui/orb.tsx +752 -752
- package/src/components/ui/popover.tsx +89 -89
- package/src/components/ui/progress.tsx +82 -82
- package/src/components/ui/radio-group.tsx +37 -37
- package/src/components/ui/scroll-area.tsx +54 -54
- package/src/components/ui/select.tsx +204 -204
- package/src/components/ui/separator.tsx +24 -24
- package/src/components/ui/sheet.tsx +139 -139
- package/src/components/ui/sidebar.tsx +1048 -1044
- package/src/components/ui/skeleton.tsx +15 -15
- package/src/components/ui/slider.tsx +53 -53
- package/src/components/ui/sonner.tsx +44 -44
- package/src/components/ui/spinner.tsx +32 -32
- package/src/components/ui/switch.tsx +31 -31
- package/src/components/ui/table.tsx +121 -121
- package/src/components/ui/tabs.tsx +81 -81
- package/src/components/ui/textarea.tsx +19 -19
- package/src/components/ui/toggle-group.tsx +89 -89
- package/src/components/ui/toggle.tsx +44 -44
- package/src/components/ui/tooltip.tsx +65 -65
- package/src/components/ui/trace.tsx +163 -0
- package/src/hooks/use-mobile.ts +20 -20
- package/src/hooks/use-streamed-text.ts +64 -0
- package/src/lib/i18n.tsx +151 -109
- package/src/lib/utils.ts +1 -1
- package/src/patterns/app-shell.tsx +237 -177
- package/src/patterns/chat-markdown.tsx +72 -0
- package/src/patterns/chat-trace.tsx +200 -0
- package/src/patterns/chat.tsx +317 -0
- package/src/patterns/data-table.tsx +2492 -2486
- package/src/patterns/filter-tabs.tsx +53 -53
- package/src/patterns/majapi-logo.tsx +32 -32
- package/src/patterns/page-header.tsx +62 -62
- package/src/patterns/prompt-input.tsx +364 -0
- package/src/patterns/status-badge.tsx +24 -24
- package/src/patterns/user-menu.tsx +218 -218
- package/src/patterns/workspace-switcher.tsx +176 -176
- package/src/styles.css +170 -165
- package/src/templates/admin-dashboard.tsx +44 -44
- package/src/templates/auth-layout.tsx +30 -30
- package/src/templates/signup-form.tsx +177 -177
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import { BrainIcon, WrenchIcon } from "lucide-react";
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
import { useUiMessages } from "../lib/i18n";
|
|
7
|
+
import { Button } from "../components/ui/button";
|
|
8
|
+
import {
|
|
9
|
+
Item,
|
|
10
|
+
ItemActions,
|
|
11
|
+
ItemContent,
|
|
12
|
+
ItemDescription,
|
|
13
|
+
ItemMedia,
|
|
14
|
+
ItemTitle,
|
|
15
|
+
} from "../components/ui/item";
|
|
16
|
+
import { Orb } from "../components/ui/orb";
|
|
17
|
+
import {
|
|
18
|
+
Trace,
|
|
19
|
+
TraceCollapsible,
|
|
20
|
+
TraceCollapsibleContent,
|
|
21
|
+
TraceCollapsibleTrigger,
|
|
22
|
+
TraceDescription,
|
|
23
|
+
TraceIcon,
|
|
24
|
+
TraceLine,
|
|
25
|
+
TraceTitle,
|
|
26
|
+
} from "../components/ui/trace";
|
|
27
|
+
|
|
28
|
+
/** Groups the agent's reasoning and tool lines of one reply. */
|
|
29
|
+
export const ChatTrace = Trace;
|
|
30
|
+
|
|
31
|
+
export interface ReasoningProps {
|
|
32
|
+
/** Thinking text (or steps). Without it the line has nothing to open. */
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
/** True while the model thinks: the line opens and its title shimmers. */
|
|
35
|
+
running?: boolean;
|
|
36
|
+
/** Seconds spent thinking, measured by the server. */
|
|
37
|
+
duration?: number;
|
|
38
|
+
/** Overrides "Thinking"/"Thought", e.g. a step title. */
|
|
39
|
+
title?: ReactNode;
|
|
40
|
+
/** Lets the app load the trace lazily when it is opened. */
|
|
41
|
+
onOpenChange?: (open: boolean) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One reasoning line (shadcn AI Elements Reasoning). Opens while running and
|
|
46
|
+
* closes when done, unless the person toggled it. Several steps (as in Numa's
|
|
47
|
+
* reasoning panel) are several lines in the same `ChatTrace`.
|
|
48
|
+
*/
|
|
49
|
+
export function Reasoning({
|
|
50
|
+
children,
|
|
51
|
+
running = false,
|
|
52
|
+
duration,
|
|
53
|
+
title,
|
|
54
|
+
onOpenChange,
|
|
55
|
+
}: ReasoningProps) {
|
|
56
|
+
const messages = useUiMessages();
|
|
57
|
+
const [open, setOpen] = useState<boolean>();
|
|
58
|
+
const line = (
|
|
59
|
+
<TraceLine status={running ? "running" : undefined}>
|
|
60
|
+
<TraceIcon>
|
|
61
|
+
{running ? <Orb size={16} variant="B1" /> : <BrainIcon />}
|
|
62
|
+
</TraceIcon>
|
|
63
|
+
<TraceTitle>
|
|
64
|
+
{title ??
|
|
65
|
+
(running
|
|
66
|
+
? messages.thinking
|
|
67
|
+
: duration === undefined
|
|
68
|
+
? messages.thought
|
|
69
|
+
: messages.thoughtFor(duration))}
|
|
70
|
+
</TraceTitle>
|
|
71
|
+
</TraceLine>
|
|
72
|
+
);
|
|
73
|
+
if (!children) return line;
|
|
74
|
+
return (
|
|
75
|
+
<TraceCollapsible
|
|
76
|
+
open={open ?? running}
|
|
77
|
+
onOpenChange={(next) => {
|
|
78
|
+
setOpen(next);
|
|
79
|
+
onOpenChange?.(next);
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<TraceCollapsibleTrigger>{line}</TraceCollapsibleTrigger>
|
|
83
|
+
<TraceCollapsibleContent
|
|
84
|
+
className={cn(typeof children === "string" && "whitespace-pre-wrap")}
|
|
85
|
+
>
|
|
86
|
+
{children}
|
|
87
|
+
</TraceCollapsibleContent>
|
|
88
|
+
</TraceCollapsible>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type ToolStatus = "pending" | "running" | "done" | "error" | "denied";
|
|
93
|
+
|
|
94
|
+
export interface ToolProps {
|
|
95
|
+
/** What the tool did, e.g. "Ran git status" or "Failed to run git status". */
|
|
96
|
+
title: ReactNode;
|
|
97
|
+
status?: ToolStatus;
|
|
98
|
+
icon?: ReactNode;
|
|
99
|
+
/** Short metadata after the title, e.g. a duration. */
|
|
100
|
+
description?: ReactNode;
|
|
101
|
+
/** Output shown when opened; strings render as preformatted text. */
|
|
102
|
+
children?: ReactNode;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** One tool call (shadcn AI Elements Tool) with its output on demand. */
|
|
106
|
+
export function Tool({
|
|
107
|
+
title,
|
|
108
|
+
status = "done",
|
|
109
|
+
icon,
|
|
110
|
+
description,
|
|
111
|
+
children,
|
|
112
|
+
}: ToolProps) {
|
|
113
|
+
const line = (
|
|
114
|
+
<TraceLine
|
|
115
|
+
status={
|
|
116
|
+
status === "running" || status === "error" || status === "pending"
|
|
117
|
+
? status
|
|
118
|
+
: undefined
|
|
119
|
+
}
|
|
120
|
+
>
|
|
121
|
+
<TraceIcon>{icon ?? <WrenchIcon />}</TraceIcon>
|
|
122
|
+
<TraceTitle>{title}</TraceTitle>
|
|
123
|
+
{description ? <TraceDescription>{description}</TraceDescription> : null}
|
|
124
|
+
</TraceLine>
|
|
125
|
+
);
|
|
126
|
+
if (!children || status === "running" || status === "pending") return line;
|
|
127
|
+
return (
|
|
128
|
+
<TraceCollapsible>
|
|
129
|
+
<TraceCollapsibleTrigger>{line}</TraceCollapsibleTrigger>
|
|
130
|
+
<TraceCollapsibleContent>
|
|
131
|
+
{typeof children === "string" ? (
|
|
132
|
+
<pre className="max-h-64 overflow-auto rounded-xl bg-muted px-3 py-2 font-mono text-xs whitespace-pre-wrap text-foreground">
|
|
133
|
+
{children}
|
|
134
|
+
</pre>
|
|
135
|
+
) : (
|
|
136
|
+
children
|
|
137
|
+
)}
|
|
138
|
+
</TraceCollapsibleContent>
|
|
139
|
+
</TraceCollapsible>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface ConfirmationProps {
|
|
144
|
+
/** The question, e.g. "Run rm -rf dist?". */
|
|
145
|
+
title: ReactNode;
|
|
146
|
+
description?: ReactNode;
|
|
147
|
+
icon?: ReactNode;
|
|
148
|
+
onApprove: () => void;
|
|
149
|
+
onDeny: () => void;
|
|
150
|
+
approveLabel?: string;
|
|
151
|
+
denyLabel?: string;
|
|
152
|
+
disabled?: boolean;
|
|
153
|
+
className?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Asks the person to approve a tool call (shadcn AI Elements Confirmation).
|
|
158
|
+
* Once answered, render the call as a `Tool` line instead.
|
|
159
|
+
*/
|
|
160
|
+
export function Confirmation({
|
|
161
|
+
title,
|
|
162
|
+
description,
|
|
163
|
+
icon,
|
|
164
|
+
onApprove,
|
|
165
|
+
onDeny,
|
|
166
|
+
approveLabel,
|
|
167
|
+
denyLabel,
|
|
168
|
+
disabled = false,
|
|
169
|
+
className,
|
|
170
|
+
}: ConfirmationProps) {
|
|
171
|
+
const messages = useUiMessages();
|
|
172
|
+
return (
|
|
173
|
+
<Item variant="outline" size="sm" role="group" className={className}>
|
|
174
|
+
<ItemMedia variant="icon">{icon ?? <WrenchIcon />}</ItemMedia>
|
|
175
|
+
<ItemContent>
|
|
176
|
+
<ItemTitle>{title}</ItemTitle>
|
|
177
|
+
{description ? <ItemDescription>{description}</ItemDescription> : null}
|
|
178
|
+
</ItemContent>
|
|
179
|
+
<ItemActions>
|
|
180
|
+
<Button
|
|
181
|
+
size="sm"
|
|
182
|
+
variant="outline"
|
|
183
|
+
className="h-11 md:h-8"
|
|
184
|
+
disabled={disabled}
|
|
185
|
+
onClick={onDeny}
|
|
186
|
+
>
|
|
187
|
+
{denyLabel ?? messages.deny}
|
|
188
|
+
</Button>
|
|
189
|
+
<Button
|
|
190
|
+
size="sm"
|
|
191
|
+
className="h-11 md:h-8"
|
|
192
|
+
disabled={disabled}
|
|
193
|
+
onClick={onApprove}
|
|
194
|
+
>
|
|
195
|
+
{approveLabel ?? messages.approve}
|
|
196
|
+
</Button>
|
|
197
|
+
</ItemActions>
|
|
198
|
+
</Item>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type ComponentProps,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
13
|
+
import { cn } from "../lib/utils";
|
|
14
|
+
import { useUiMessages } from "../lib/i18n";
|
|
15
|
+
import { Button } from "../components/ui/button";
|
|
16
|
+
import { Bubble, BubbleContent } from "../components/ui/bubble";
|
|
17
|
+
import {
|
|
18
|
+
Message,
|
|
19
|
+
MessageContent,
|
|
20
|
+
MessageFooter,
|
|
21
|
+
} from "../components/ui/message";
|
|
22
|
+
import {
|
|
23
|
+
MessageScroller,
|
|
24
|
+
MessageScrollerButton,
|
|
25
|
+
MessageScrollerContent,
|
|
26
|
+
MessageScrollerProvider,
|
|
27
|
+
MessageScrollerViewport,
|
|
28
|
+
useMessageScrollerGutterWidth,
|
|
29
|
+
} from "../components/ui/message-scroller";
|
|
30
|
+
import { Orb } from "../components/ui/orb";
|
|
31
|
+
import {
|
|
32
|
+
Tooltip,
|
|
33
|
+
TooltipContent,
|
|
34
|
+
TooltipProvider,
|
|
35
|
+
TooltipTrigger,
|
|
36
|
+
} from "../components/ui/tooltip";
|
|
37
|
+
|
|
38
|
+
const GutterContext = createContext<{
|
|
39
|
+
gutter: number;
|
|
40
|
+
setGutter: (width: number) => void;
|
|
41
|
+
} | null>(null);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Agent chat layout: a transcript that fills the space and a composer below
|
|
45
|
+
* it. Place it in `AppShell fillHeight` (or any height-constrained parent).
|
|
46
|
+
*/
|
|
47
|
+
export function Chat({ className, children, ...props }: ComponentProps<"div">) {
|
|
48
|
+
const [gutter, setGutter] = useState(0);
|
|
49
|
+
return (
|
|
50
|
+
<GutterContext.Provider value={{ gutter, setGutter }}>
|
|
51
|
+
<TooltipProvider>
|
|
52
|
+
<div
|
|
53
|
+
data-slot="chat"
|
|
54
|
+
className={cn("relative flex min-h-0 flex-1 flex-col", className)}
|
|
55
|
+
{...props}
|
|
56
|
+
>
|
|
57
|
+
{children}
|
|
58
|
+
</div>
|
|
59
|
+
</TooltipProvider>
|
|
60
|
+
</GutterContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ChatMessagesProps
|
|
65
|
+
extends Omit<ComponentProps<typeof MessageScrollerProvider>, "children"> {
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
/** True while a reply streams; screen readers wait for the finished row. */
|
|
68
|
+
busy?: boolean;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The transcript (shadcn Message Scroller). Follows the reply while the
|
|
74
|
+
* reader stays at the live edge and opens at the last turn. Wrap each row in
|
|
75
|
+
* `MessageScrollerItem` and mark the person's turns with `scrollAnchor`.
|
|
76
|
+
*/
|
|
77
|
+
export function ChatMessages({
|
|
78
|
+
children,
|
|
79
|
+
busy,
|
|
80
|
+
className,
|
|
81
|
+
autoScroll = true,
|
|
82
|
+
defaultScrollPosition = "last-anchor",
|
|
83
|
+
...props
|
|
84
|
+
}: ChatMessagesProps) {
|
|
85
|
+
const viewportRef = useRef<HTMLDivElement>(null);
|
|
86
|
+
const gutter = useMessageScrollerGutterWidth(viewportRef);
|
|
87
|
+
const setGutter = useContext(GutterContext)?.setGutter;
|
|
88
|
+
|
|
89
|
+
useEffect(() => setGutter?.(gutter), [gutter, setGutter]);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<MessageScrollerProvider
|
|
93
|
+
autoScroll={autoScroll}
|
|
94
|
+
defaultScrollPosition={defaultScrollPosition}
|
|
95
|
+
{...props}
|
|
96
|
+
>
|
|
97
|
+
<MessageScroller className={cn("min-h-0 flex-1", className)}>
|
|
98
|
+
<MessageScrollerViewport ref={viewportRef}>
|
|
99
|
+
<MessageScrollerContent
|
|
100
|
+
aria-busy={busy}
|
|
101
|
+
className="mx-auto w-full max-w-3xl pb-6"
|
|
102
|
+
>
|
|
103
|
+
{children}
|
|
104
|
+
</MessageScrollerContent>
|
|
105
|
+
</MessageScrollerViewport>
|
|
106
|
+
<MessageScrollerButton />
|
|
107
|
+
</MessageScroller>
|
|
108
|
+
</MessageScrollerProvider>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Holds the prompt input (and suggestions) under the transcript, aligned
|
|
114
|
+
* with it even when the transcript reserves a scrollbar gutter.
|
|
115
|
+
*/
|
|
116
|
+
export function ChatComposer({
|
|
117
|
+
className,
|
|
118
|
+
children,
|
|
119
|
+
style,
|
|
120
|
+
...props
|
|
121
|
+
}: ComponentProps<"div">) {
|
|
122
|
+
const gutter = useContext(GutterContext)?.gutter ?? 0;
|
|
123
|
+
return (
|
|
124
|
+
<div
|
|
125
|
+
data-slot="chat-composer"
|
|
126
|
+
className={cn("shrink-0 pb-[env(safe-area-inset-bottom)]", className)}
|
|
127
|
+
style={{ paddingInlineEnd: gutter, ...style }}
|
|
128
|
+
{...props}
|
|
129
|
+
>
|
|
130
|
+
<div className="mx-auto flex w-full max-w-3xl flex-col gap-3 px-2">
|
|
131
|
+
{children}
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ChatMessageProps
|
|
138
|
+
extends Omit<ComponentProps<typeof Message>, "align"> {
|
|
139
|
+
from: "user" | "assistant";
|
|
140
|
+
/** Files or images sent with a person's message, above the bubble. */
|
|
141
|
+
attachments?: ReactNode;
|
|
142
|
+
/** Actions or the time under the message. A person's footer shows on hover. */
|
|
143
|
+
footer?: ReactNode;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* One turn. A person's text sits in a muted bubble on the end side; the
|
|
148
|
+
* agent's reply is unboxed so markdown, reasoning and tools read as a page.
|
|
149
|
+
*/
|
|
150
|
+
export function ChatMessage({
|
|
151
|
+
from,
|
|
152
|
+
attachments,
|
|
153
|
+
footer,
|
|
154
|
+
children,
|
|
155
|
+
...props
|
|
156
|
+
}: ChatMessageProps) {
|
|
157
|
+
if (from === "user") {
|
|
158
|
+
return (
|
|
159
|
+
<Message align="end" data-from="user" {...props}>
|
|
160
|
+
<MessageContent>
|
|
161
|
+
{attachments}
|
|
162
|
+
{children ? (
|
|
163
|
+
<Bubble align="end" variant="muted">
|
|
164
|
+
<BubbleContent className="whitespace-pre-wrap">
|
|
165
|
+
{children}
|
|
166
|
+
</BubbleContent>
|
|
167
|
+
</Bubble>
|
|
168
|
+
) : null}
|
|
169
|
+
{footer ? (
|
|
170
|
+
<MessageFooter className="transition-opacity md:opacity-0 md:group-hover/message:opacity-100 md:group-focus-within/message:opacity-100">
|
|
171
|
+
{footer}
|
|
172
|
+
</MessageFooter>
|
|
173
|
+
) : null}
|
|
174
|
+
</MessageContent>
|
|
175
|
+
</Message>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return (
|
|
179
|
+
<Message data-from="assistant" {...props}>
|
|
180
|
+
<MessageContent>
|
|
181
|
+
{children}
|
|
182
|
+
{footer ? <MessageFooter className="px-0">{footer}</MessageFooter> : null}
|
|
183
|
+
</MessageContent>
|
|
184
|
+
</Message>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Row of message actions (copy, feedback, retry) and metadata. */
|
|
189
|
+
export function MessageActions({
|
|
190
|
+
className,
|
|
191
|
+
...props
|
|
192
|
+
}: ComponentProps<"div">) {
|
|
193
|
+
return (
|
|
194
|
+
<div
|
|
195
|
+
data-slot="message-actions"
|
|
196
|
+
className={cn("-mx-2 flex min-w-0 items-center gap-0.5", className)}
|
|
197
|
+
{...props}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface MessageActionProps extends ComponentProps<typeof Button> {
|
|
203
|
+
/** Accessible name and tooltip. */
|
|
204
|
+
label: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Icon button with a tooltip. Use `aria-pressed` for toggles like feedback. */
|
|
208
|
+
export function MessageAction({
|
|
209
|
+
label,
|
|
210
|
+
className,
|
|
211
|
+
children,
|
|
212
|
+
...props
|
|
213
|
+
}: MessageActionProps) {
|
|
214
|
+
return (
|
|
215
|
+
<Tooltip>
|
|
216
|
+
<TooltipTrigger
|
|
217
|
+
render={
|
|
218
|
+
<Button
|
|
219
|
+
variant="ghost"
|
|
220
|
+
size="icon-sm"
|
|
221
|
+
aria-label={label}
|
|
222
|
+
className={cn(
|
|
223
|
+
"size-11 text-muted-foreground hover:text-foreground aria-pressed:text-foreground md:size-8",
|
|
224
|
+
className,
|
|
225
|
+
)}
|
|
226
|
+
{...props}
|
|
227
|
+
/>
|
|
228
|
+
}
|
|
229
|
+
>
|
|
230
|
+
{children}
|
|
231
|
+
</TooltipTrigger>
|
|
232
|
+
<TooltipContent>{label}</TooltipContent>
|
|
233
|
+
</Tooltip>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Copies the message text and confirms for two seconds. */
|
|
238
|
+
export function CopyMessageAction({ text }: { text: string }) {
|
|
239
|
+
const messages = useUiMessages();
|
|
240
|
+
const [copied, setCopied] = useState(false);
|
|
241
|
+
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
if (!copied) return;
|
|
244
|
+
const timeout = setTimeout(() => setCopied(false), 2000);
|
|
245
|
+
return () => clearTimeout(timeout);
|
|
246
|
+
}, [copied]);
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<MessageAction
|
|
250
|
+
label={copied ? messages.copied : messages.copy}
|
|
251
|
+
onClick={() =>
|
|
252
|
+
navigator.clipboard.writeText(text).then(() => setCopied(true))
|
|
253
|
+
}
|
|
254
|
+
>
|
|
255
|
+
{copied ? <CheckIcon /> : <CopyIcon />}
|
|
256
|
+
</MessageAction>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Shown while the agent works on a reply and nothing has streamed yet. */
|
|
261
|
+
export function TypingIndicator({
|
|
262
|
+
label,
|
|
263
|
+
className,
|
|
264
|
+
}: {
|
|
265
|
+
label?: string;
|
|
266
|
+
className?: string;
|
|
267
|
+
}) {
|
|
268
|
+
const messages = useUiMessages();
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
data-slot="typing-indicator"
|
|
272
|
+
role="status"
|
|
273
|
+
aria-live="polite"
|
|
274
|
+
className={cn("flex", className)}
|
|
275
|
+
>
|
|
276
|
+
<Orb pill label={label ?? `${messages.responding}…`} />
|
|
277
|
+
</div>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface SuggestionsProps {
|
|
282
|
+
suggestions: string[];
|
|
283
|
+
onSelect: (suggestion: string) => void;
|
|
284
|
+
className?: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Prompt suggestions above the prompt input; each label is sent as-is. */
|
|
288
|
+
export function Suggestions({
|
|
289
|
+
suggestions,
|
|
290
|
+
onSelect,
|
|
291
|
+
className,
|
|
292
|
+
}: SuggestionsProps) {
|
|
293
|
+
const messages = useUiMessages();
|
|
294
|
+
if (suggestions.length === 0) return null;
|
|
295
|
+
return (
|
|
296
|
+
<div
|
|
297
|
+
role="group"
|
|
298
|
+
aria-label={messages.suggestions}
|
|
299
|
+
className={cn(
|
|
300
|
+
"no-scrollbar flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain",
|
|
301
|
+
className,
|
|
302
|
+
)}
|
|
303
|
+
>
|
|
304
|
+
{suggestions.map((suggestion) => (
|
|
305
|
+
<Button
|
|
306
|
+
key={suggestion}
|
|
307
|
+
variant="outline"
|
|
308
|
+
size="sm"
|
|
309
|
+
className="h-11 shrink-0 md:h-8"
|
|
310
|
+
onClick={() => onSelect(suggestion)}
|
|
311
|
+
>
|
|
312
|
+
{suggestion}
|
|
313
|
+
</Button>
|
|
314
|
+
))}
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
}
|