better-cmdk 0.0.5 → 0.0.7
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 +8 -0
- package/README.md +28 -0
- package/dist/index.d.ts +197 -9
- package/dist/index.js +1 -1
- package/dist/nextjs/AGENTS.md +358 -0
- package/dist/remix/AGENTS.md +356 -0
- package/dist/tanstack-start/AGENTS.md +359 -0
- package/dist/vite/AGENTS.md +356 -0
- package/package.json +11 -4
package/AGENTS.md
ADDED
package/README.md
CHANGED
|
@@ -167,6 +167,34 @@ Each command in the `commands` array supports:
|
|
|
167
167
|
| `onModeChange` | `(mode: CommandMenuMode) => void` | — | Fires when switching between command/chat |
|
|
168
168
|
| `historyStorageKey` | `string` | — | localStorage key for chat history |
|
|
169
169
|
| `maxConversations` | `number` | — | Max saved chat conversations |
|
|
170
|
+
| `mobile` | `CommandMenuMobileOptions` | mobile defaults enabled | Mobile sheet/gesture behavior configuration |
|
|
171
|
+
|
|
172
|
+
### Mobile Configuration
|
|
173
|
+
|
|
174
|
+
`CommandMenu` now includes a mobile-first sheet mode:
|
|
175
|
+
|
|
176
|
+
- Long-press (`~350ms`) in the lower-middle viewport shows a hint: `Swipe up for Command Menu`
|
|
177
|
+
- Swipe up opens the menu
|
|
178
|
+
- Keyboard-last flow on mobile (sheet opens without forcing keyboard)
|
|
179
|
+
- Keyboard-aware input/list insets via `visualViewport`
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
<CommandMenu
|
|
183
|
+
open={open}
|
|
184
|
+
onOpenChange={setOpen}
|
|
185
|
+
commands={commands}
|
|
186
|
+
mobile={{
|
|
187
|
+
enabled: true,
|
|
188
|
+
layout: "keyboard-last",
|
|
189
|
+
gesture: {
|
|
190
|
+
holdMs: 350,
|
|
191
|
+
swipeUpPx: 56,
|
|
192
|
+
},
|
|
193
|
+
showQuickActions: true,
|
|
194
|
+
quickActionsCount: 4,
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
170
198
|
|
|
171
199
|
### AI Chat
|
|
172
200
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Streamdown } from "streamdown";
|
|
|
8
8
|
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
9
9
|
import { VariantProps } from "class-variance-authority";
|
|
10
10
|
import { Dialog as Dialog$1 } from "radix-ui";
|
|
11
|
-
import
|
|
11
|
+
import * as RadixDialog from "@radix-ui/react-dialog";
|
|
12
12
|
import { ToolUIPart, UIMessage } from "ai";
|
|
13
13
|
import * as class_variance_authority_types0 from "class-variance-authority/types";
|
|
14
14
|
import { UITree } from "@json-render/core";
|
|
@@ -97,6 +97,160 @@ declare function CollapsibleContent({
|
|
|
97
97
|
...props
|
|
98
98
|
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>): react_jsx_runtime0.JSX.Element;
|
|
99
99
|
//#endregion
|
|
100
|
+
//#region lib/cmdk/index.d.ts
|
|
101
|
+
type Children = {
|
|
102
|
+
children?: React$2.ReactNode;
|
|
103
|
+
};
|
|
104
|
+
type CommandFilter = (value: string, search: string, keywords?: string[]) => number;
|
|
105
|
+
declare const pkg: React$2.ForwardRefExoticComponent<Children & Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
106
|
+
asChild?: boolean;
|
|
107
|
+
}, "ref"> & {
|
|
108
|
+
/**
|
|
109
|
+
* Accessible label for this command menu. Not shown visibly.
|
|
110
|
+
*/
|
|
111
|
+
label?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Optionally set to `false` to turn off the automatic filtering and sorting.
|
|
114
|
+
* If `false`, you must conditionally render valid items based on the search query yourself.
|
|
115
|
+
*/
|
|
116
|
+
shouldFilter?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Custom filter function for whether each command menu item should matches the given search query.
|
|
119
|
+
* It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely.
|
|
120
|
+
* By default, uses the `command-score` library.
|
|
121
|
+
*/
|
|
122
|
+
filter?: CommandFilter;
|
|
123
|
+
/**
|
|
124
|
+
* Optional default item value when it is initially rendered.
|
|
125
|
+
*/
|
|
126
|
+
defaultValue?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Optional controlled state of the selected command menu item.
|
|
129
|
+
*/
|
|
130
|
+
value?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Event handler called when the selected item of the menu changes.
|
|
133
|
+
*/
|
|
134
|
+
onValueChange?: (value: string) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Optionally set to `true` to turn on looping around when using the arrow keys.
|
|
137
|
+
*/
|
|
138
|
+
loop?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Optionally set to `true` to disable selection via pointer events.
|
|
141
|
+
*/
|
|
142
|
+
disablePointerSelection?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Set to `false` to disable ctrl+n/j/p/k shortcuts. Defaults to `true`.
|
|
145
|
+
*/
|
|
146
|
+
vimBindings?: boolean;
|
|
147
|
+
} & React$2.RefAttributes<HTMLDivElement>> & {
|
|
148
|
+
List: React$2.ForwardRefExoticComponent<Children & Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
149
|
+
asChild?: boolean;
|
|
150
|
+
}, "ref"> & {
|
|
151
|
+
/**
|
|
152
|
+
* Accessible label for this List of suggestions. Not shown visibly.
|
|
153
|
+
*/
|
|
154
|
+
label?: string;
|
|
155
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
156
|
+
Item: React$2.ForwardRefExoticComponent<Children & Omit<Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
157
|
+
asChild?: boolean;
|
|
158
|
+
}, "ref">, "value" | "onSelect" | "disabled"> & {
|
|
159
|
+
/** Whether this item is currently disabled. */disabled?: boolean; /** Event handler for when this item is selected, either via click or keyboard selection. */
|
|
160
|
+
onSelect?: (value: string) => void;
|
|
161
|
+
/**
|
|
162
|
+
* A unique value for this item.
|
|
163
|
+
* If no value is provided, it will be inferred from `children` or the rendered `textContent`. If your `textContent` changes between renders, you _must_ provide a stable, unique `value`.
|
|
164
|
+
*/
|
|
165
|
+
value?: string; /** Optional keywords to match against when filtering. */
|
|
166
|
+
keywords?: string[]; /** Whether this item is forcibly rendered regardless of filtering. */
|
|
167
|
+
forceMount?: boolean;
|
|
168
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
169
|
+
Input: React$2.ForwardRefExoticComponent<Omit<Omit<React$2.ClassAttributes<HTMLInputElement> & React$2.InputHTMLAttributes<HTMLInputElement> & {
|
|
170
|
+
asChild?: boolean;
|
|
171
|
+
}, "ref">, "value" | "type" | "onChange"> & {
|
|
172
|
+
/**
|
|
173
|
+
* Optional controlled state for the value of the search input.
|
|
174
|
+
*/
|
|
175
|
+
value?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Event handler called when the search value changes.
|
|
178
|
+
*/
|
|
179
|
+
onValueChange?: (search: string) => void;
|
|
180
|
+
} & React$2.RefAttributes<HTMLInputElement>>;
|
|
181
|
+
Group: React$2.ForwardRefExoticComponent<Children & Omit<Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
182
|
+
asChild?: boolean;
|
|
183
|
+
}, "ref">, "value" | "heading"> & {
|
|
184
|
+
/** Optional heading to render for this group. */heading?: React$2.ReactNode; /** If no heading is provided, you must provide a value that is unique for this group. */
|
|
185
|
+
value?: string; /** Whether this group is forcibly rendered regardless of filtering. */
|
|
186
|
+
forceMount?: boolean;
|
|
187
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
188
|
+
Separator: React$2.ForwardRefExoticComponent<Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
189
|
+
asChild?: boolean;
|
|
190
|
+
}, "ref"> & {
|
|
191
|
+
/** Whether this separator should always be rendered. Useful if you disable automatic filtering. */alwaysRender?: boolean;
|
|
192
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
193
|
+
Dialog: React$2.ForwardRefExoticComponent<RadixDialog.DialogProps & Children & Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
194
|
+
asChild?: boolean;
|
|
195
|
+
}, "ref"> & {
|
|
196
|
+
/**
|
|
197
|
+
* Accessible label for this command menu. Not shown visibly.
|
|
198
|
+
*/
|
|
199
|
+
label?: string;
|
|
200
|
+
/**
|
|
201
|
+
* Optionally set to `false` to turn off the automatic filtering and sorting.
|
|
202
|
+
* If `false`, you must conditionally render valid items based on the search query yourself.
|
|
203
|
+
*/
|
|
204
|
+
shouldFilter?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Custom filter function for whether each command menu item should matches the given search query.
|
|
207
|
+
* It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely.
|
|
208
|
+
* By default, uses the `command-score` library.
|
|
209
|
+
*/
|
|
210
|
+
filter?: CommandFilter;
|
|
211
|
+
/**
|
|
212
|
+
* Optional default item value when it is initially rendered.
|
|
213
|
+
*/
|
|
214
|
+
defaultValue?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Optional controlled state of the selected command menu item.
|
|
217
|
+
*/
|
|
218
|
+
value?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Event handler called when the selected item of the menu changes.
|
|
221
|
+
*/
|
|
222
|
+
onValueChange?: (value: string) => void;
|
|
223
|
+
/**
|
|
224
|
+
* Optionally set to `true` to turn on looping around when using the arrow keys.
|
|
225
|
+
*/
|
|
226
|
+
loop?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Optionally set to `true` to disable selection via pointer events.
|
|
229
|
+
*/
|
|
230
|
+
disablePointerSelection?: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Set to `false` to disable ctrl+n/j/p/k shortcuts. Defaults to `true`.
|
|
233
|
+
*/
|
|
234
|
+
vimBindings?: boolean;
|
|
235
|
+
} & {
|
|
236
|
+
/** Provide a className to the Dialog overlay. */overlayClassName?: string; /** Provide a className to the Dialog content. */
|
|
237
|
+
contentClassName?: string; /** Provide a custom element the Dialog should portal into. */
|
|
238
|
+
container?: HTMLElement;
|
|
239
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
240
|
+
Empty: React$2.ForwardRefExoticComponent<Children & Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
241
|
+
asChild?: boolean;
|
|
242
|
+
}, "ref"> & React$2.RefAttributes<HTMLDivElement>>;
|
|
243
|
+
Loading: React$2.ForwardRefExoticComponent<Children & Omit<React$2.ClassAttributes<HTMLDivElement> & React$2.HTMLAttributes<HTMLDivElement> & {
|
|
244
|
+
asChild?: boolean;
|
|
245
|
+
}, "ref"> & {
|
|
246
|
+
/** Estimated progress of loading asynchronous options. */progress?: number;
|
|
247
|
+
/**
|
|
248
|
+
* Accessible label for this loading progressbar. Not shown visibly.
|
|
249
|
+
*/
|
|
250
|
+
label?: string;
|
|
251
|
+
} & React$2.RefAttributes<HTMLDivElement>>;
|
|
252
|
+
};
|
|
253
|
+
//#endregion
|
|
100
254
|
//#region components/ui/dialog.d.ts
|
|
101
255
|
declare function Dialog({
|
|
102
256
|
...props
|
|
@@ -147,7 +301,7 @@ declare function DialogDescription({
|
|
|
147
301
|
declare function Command({
|
|
148
302
|
className,
|
|
149
303
|
...props
|
|
150
|
-
}: React$2.ComponentProps<typeof
|
|
304
|
+
}: React$2.ComponentProps<typeof pkg>): react_jsx_runtime0.JSX.Element;
|
|
151
305
|
declare function CommandDialogContent({
|
|
152
306
|
className,
|
|
153
307
|
children,
|
|
@@ -155,17 +309,18 @@ declare function CommandDialogContent({
|
|
|
155
309
|
}: React$2.ComponentProps<typeof Dialog$1.Content>): react_jsx_runtime0.JSX.Element;
|
|
156
310
|
declare function CommandGroup({
|
|
157
311
|
className,
|
|
312
|
+
ref,
|
|
158
313
|
...props
|
|
159
|
-
}: React$2.ComponentProps<typeof
|
|
314
|
+
}: React$2.ComponentProps<typeof pkg.Group>): react_jsx_runtime0.JSX.Element;
|
|
160
315
|
declare function CommandSeparator({
|
|
161
316
|
className,
|
|
162
317
|
...props
|
|
163
|
-
}: React$2.ComponentProps<typeof
|
|
318
|
+
}: React$2.ComponentProps<typeof pkg.Separator>): react_jsx_runtime0.JSX.Element;
|
|
164
319
|
declare function CommandItem({
|
|
165
320
|
className,
|
|
166
321
|
style,
|
|
167
322
|
...props
|
|
168
|
-
}: React$2.ComponentProps<typeof
|
|
323
|
+
}: React$2.ComponentProps<typeof pkg.Item>): react_jsx_runtime0.JSX.Element;
|
|
169
324
|
declare function CommandShortcut({
|
|
170
325
|
className,
|
|
171
326
|
children,
|
|
@@ -265,6 +420,29 @@ declare function useCommandMenuContext(): CommandMenuContextValue;
|
|
|
265
420
|
//#endregion
|
|
266
421
|
//#region components/ui/command-menu.d.ts
|
|
267
422
|
type CommandMenuCorners = "none" | "sm" | "md" | "lg" | "xl";
|
|
423
|
+
type CommandMenuMobileLayout = "keyboard-last";
|
|
424
|
+
interface CommandMenuMobileGesture {
|
|
425
|
+
/** Enables/disables the long-press gesture trigger. */
|
|
426
|
+
enabled?: boolean;
|
|
427
|
+
/** Hold duration before showing the swipe-up hint. */
|
|
428
|
+
holdMs?: number;
|
|
429
|
+
/** Upward drag distance required to open the menu. */
|
|
430
|
+
swipeUpPx?: number;
|
|
431
|
+
}
|
|
432
|
+
interface CommandMenuMobileOptions {
|
|
433
|
+
/** Enable mobile command-sheet behavior. Defaults to true. */
|
|
434
|
+
enabled?: boolean;
|
|
435
|
+
/** Viewport width threshold used for mobile layout detection. */
|
|
436
|
+
breakpoint?: number;
|
|
437
|
+
/** Mobile interaction layout. */
|
|
438
|
+
layout?: CommandMenuMobileLayout;
|
|
439
|
+
/** Gesture trigger settings. Set false to fully disable. */
|
|
440
|
+
gesture?: CommandMenuMobileGesture | false;
|
|
441
|
+
/** Show quick actions when query is empty. */
|
|
442
|
+
showQuickActions?: boolean;
|
|
443
|
+
/** Maximum quick actions to show. */
|
|
444
|
+
quickActionsCount?: number;
|
|
445
|
+
}
|
|
268
446
|
interface CommandMenuProps extends Omit<React$2.ComponentProps<typeof Dialog>, "children"> {
|
|
269
447
|
title?: string;
|
|
270
448
|
description?: string;
|
|
@@ -277,6 +455,8 @@ interface CommandMenuProps extends Omit<React$2.ComponentProps<typeof Dialog>, "
|
|
|
277
455
|
onModeChange?: (mode: CommandMenuMode) => void;
|
|
278
456
|
historyStorageKey?: string;
|
|
279
457
|
maxConversations?: number;
|
|
458
|
+
/** Mobile-specific interaction + layout settings. */
|
|
459
|
+
mobile?: CommandMenuMobileOptions;
|
|
280
460
|
/** Declarative command definitions. Mutually exclusive with children. */
|
|
281
461
|
commands?: CommandDefinition[];
|
|
282
462
|
/** Placeholder for the command input when using `commands` prop. */
|
|
@@ -295,10 +475,16 @@ declare function CommandContent({
|
|
|
295
475
|
children,
|
|
296
476
|
corners,
|
|
297
477
|
borderColor,
|
|
478
|
+
isMobile,
|
|
479
|
+
keyboardInset,
|
|
480
|
+
onRequestClose,
|
|
298
481
|
...props
|
|
299
482
|
}: React$2.ComponentProps<typeof Dialog$1.Content> & {
|
|
300
483
|
corners?: CommandMenuCorners;
|
|
301
484
|
borderColor?: string;
|
|
485
|
+
isMobile?: boolean;
|
|
486
|
+
keyboardInset?: number;
|
|
487
|
+
onRequestClose?: () => void;
|
|
302
488
|
}): react_jsx_runtime0.JSX.Element;
|
|
303
489
|
declare function CommandMenu({
|
|
304
490
|
chatEndpoint,
|
|
@@ -310,9 +496,10 @@ declare function CommandMenu({
|
|
|
310
496
|
commands,
|
|
311
497
|
commandsPlaceholder,
|
|
312
498
|
commandsAskAILabel,
|
|
499
|
+
mobile,
|
|
313
500
|
...props
|
|
314
501
|
}: CommandMenuProps): react_jsx_runtime0.JSX.Element;
|
|
315
|
-
interface CommandInputProps extends Omit<React$2.ComponentProps<typeof
|
|
502
|
+
interface CommandInputProps extends Omit<React$2.ComponentProps<typeof pkg.Input>, "value" | "onValueChange"> {
|
|
316
503
|
showSendButton?: boolean;
|
|
317
504
|
}
|
|
318
505
|
declare function CommandInput({
|
|
@@ -320,7 +507,7 @@ declare function CommandInput({
|
|
|
320
507
|
showSendButton,
|
|
321
508
|
...props
|
|
322
509
|
}: CommandInputProps): react_jsx_runtime0.JSX.Element;
|
|
323
|
-
interface CommandEmptyProps extends React$2.ComponentProps<typeof
|
|
510
|
+
interface CommandEmptyProps extends React$2.ComponentProps<typeof pkg.Item> {
|
|
324
511
|
label?: string;
|
|
325
512
|
description?: string;
|
|
326
513
|
}
|
|
@@ -373,7 +560,7 @@ interface CommandDefinition {
|
|
|
373
560
|
/** Called when the command is selected */
|
|
374
561
|
onSelect?: () => void;
|
|
375
562
|
}
|
|
376
|
-
interface CommandListProps extends React$2.ComponentProps<typeof
|
|
563
|
+
interface CommandListProps extends React$2.ComponentProps<typeof pkg.List> {
|
|
377
564
|
/** Actions to render as CommandItems. Compatible with ActionDefinition[]. */
|
|
378
565
|
actions?: CommandAction[];
|
|
379
566
|
/** Heading for the auto-rendered actions group */
|
|
@@ -384,6 +571,7 @@ declare function CommandList({
|
|
|
384
571
|
children,
|
|
385
572
|
actions,
|
|
386
573
|
actionsHeading,
|
|
574
|
+
style,
|
|
387
575
|
...props
|
|
388
576
|
}: CommandListProps): react_jsx_runtime0.JSX.Element;
|
|
389
577
|
//#endregion
|
|
@@ -522,4 +710,4 @@ declare function TaskContent({
|
|
|
522
710
|
...props
|
|
523
711
|
}: TaskContentProps): react_jsx_runtime0.JSX.Element;
|
|
524
712
|
//#endregion
|
|
525
|
-
export { AssistantFormRenderer, type AssistantFormRendererProps, AssistantMessages, type AssistantMessagesProps, Button, type ChatConversation, ChatEmpty, type ChatEmptyProps, ChatLoading, type ChatLoadingProps, ChatMessageList, type ChatMessageListProps, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, type CommandAction, type CommandActionOption, CommandContent, type CommandDefinition, CommandMenu as CommandDialog, CommandMenu, CommandDialogContent, CommandEmpty, type CommandEmptyProps, CommandGroup, CommandInput, type CommandInputProps, CommandItem, CommandList, type CommandListProps, CommandMenuContext, type CommandMenuContextValue, type CommandMenuCorners, type CommandMenuMode, type CommandMenuProps, CommandMenuProvider, type CommandMenuProviderProps, type CommandMenuStatus, CommandSeparator, CommandShortcut, Confirmation, ConfirmationAccepted, type ConfirmationAcceptedProps, ConfirmationAction, type ConfirmationActionProps, ConfirmationActions, type ConfirmationActionsProps, type ConfirmationProps, ConfirmationRejected, type ConfirmationRejectedProps, ConfirmationRequest, type ConfirmationRequestProps, ConfirmationTitle, type ConfirmationTitleProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, type ExternalChat, Kbd, KbdGroup, Message, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, Task, TaskContent, type TaskContentProps, TaskItem, TaskItemFile, type TaskItemFileProps, type TaskItemProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type ToolUIPartApproval, type UseChatHistoryOptions, type UseChatHistoryReturn, buttonVariants, cn, defaultFormRegistry, useChatHistory, useCommandMenuContext };
|
|
713
|
+
export { AssistantFormRenderer, type AssistantFormRendererProps, AssistantMessages, type AssistantMessagesProps, Button, type ChatConversation, ChatEmpty, type ChatEmptyProps, ChatLoading, type ChatLoadingProps, ChatMessageList, type ChatMessageListProps, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, type CommandAction, type CommandActionOption, CommandContent, type CommandDefinition, CommandMenu as CommandDialog, CommandMenu, CommandDialogContent, CommandEmpty, type CommandEmptyProps, CommandGroup, CommandInput, type CommandInputProps, CommandItem, CommandList, type CommandListProps, CommandMenuContext, type CommandMenuContextValue, type CommandMenuCorners, type CommandMenuMobileGesture, type CommandMenuMobileLayout, type CommandMenuMobileOptions, type CommandMenuMode, type CommandMenuProps, CommandMenuProvider, type CommandMenuProviderProps, type CommandMenuStatus, CommandSeparator, CommandShortcut, Confirmation, ConfirmationAccepted, type ConfirmationAcceptedProps, ConfirmationAction, type ConfirmationActionProps, ConfirmationActions, type ConfirmationActionsProps, type ConfirmationProps, ConfirmationRejected, type ConfirmationRejectedProps, ConfirmationRequest, type ConfirmationRequestProps, ConfirmationTitle, type ConfirmationTitleProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, type ExternalChat, Kbd, KbdGroup, Message, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, Task, TaskContent, type TaskContentProps, TaskItem, TaskItemFile, type TaskItemFileProps, type TaskItemProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type ToolUIPartApproval, type UseChatHistoryOptions, type UseChatHistoryReturn, buttonVariants, cn, defaultFormRegistry, useChatHistory, useCommandMenuContext };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cn as e}from"./lib/utils.js";import{JSONUIProvider as t,Renderer as n,flatToTree as r}from"@json-render/react";import*as i from"react";import{createContext as a,memo as o,useCallback as s,useContext as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{z as p}from"zod";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";import{Streamdown as _}from"streamdown";import{ChevronDownIcon as v,CornerDownLeftIcon as y,LoaderIcon as b,MessageCircleIcon as x,SearchIcon as S,SparklesIcon as C,XIcon as w}from"lucide-react";import*as T from"@radix-ui/react-collapsible";import{cva as E}from"class-variance-authority";import{Dialog as D,Slot as O}from"radix-ui";import{Command as k,defaultFilter as ee,useCommandState as A}from"cmdk";import{useChat as te}from"@ai-sdk/react";import{DefaultChatTransport as ne}from"ai";import{BrowserClient as j,Scope as M,dedupeIntegration as N,defaultStackParser as P,linkedErrorsIntegration as F,makeFetchTransport as re}from"@sentry/browser";const ie=a(null);function I(){let e=c(ie);if(!e)throw Error(`Confirmation components must be used within Confirmation`);return e}function ae({approval:t,state:n,style:r,...i}){return!t||n===`input-streaming`||n===`input-available`?null:h(ie.Provider,{value:{approval:t,state:n},children:h(`div`,{"data-slot":`confirmation`,"data-state":n,"data-approved":t?.approved,role:`alertdialog`,"aria-labelledby":`confirmation-title`,style:{borderRadius:`var(--cmdk-radius, 0.5rem)`,...r},className:e(`flex flex-col gap-2 border p-4`,`data-[state=approval-requested]:border-amber-500/50 data-[state=approval-requested]:bg-amber-50/50 dark:data-[state=approval-requested]:bg-amber-950/20`,`data-[approved=true]:border-green-500/50 data-[approved=true]:bg-green-50/50 dark:data-[approved=true]:bg-green-950/20`,`data-[approved=false]:border-red-500/50 data-[approved=false]:bg-red-50/50 dark:data-[approved=false]:bg-red-950/20`),...i})})}function oe(e){return h(`p`,{id:`confirmation-title`,"data-slot":`confirmation-title`,className:`text-sm font-medium`,...e})}function se({children:e}){let{state:t}=I();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function ce({children:e}){let{approval:t,state:n}=I();return!t?.approved||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-accepted`,children:e})}function le({children:e}){let{approval:t,state:n}=I();return t?.approved!==!1||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-rejected`,children:e})}function ue(e){let{state:t}=I();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-actions`,className:`flex items-center justify-end gap-2 self-end`,...e}):null}function L({variant:t=`default`,style:n,...r}){return h(`button`,{"data-slot":`confirmation-action`,"data-variant":t,type:`button`,className:e(`inline-flex h-8 items-center justify-center gap-2 whitespace-nowrap px-3 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`,t===`default`&&`bg-primary text-primary-foreground shadow hover:bg-primary/90`,t===`outline`&&`border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground`,t===`destructive`&&`bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90`),style:{borderRadius:`var(--cmdk-radius, 0.375rem)`,...n},...r})}function R(e){e.stopPropagation()}function de({element:t,children:n,onAction:r}){let{id:i=`form`,title:a,submitLabel:o=`Submit`}=t.props??{},s=e=>{e.preventDefault();let t=new FormData(e.currentTarget),n={};t.forEach((e,t)=>{typeof e==`string`&&(n[t]=e)}),r?.({name:`submit`,params:{formId:i,data:n}})};return g(`div`,{"data-slot":`form-card`,className:e(`w-full rounded-lg border bg-card text-card-foreground shadow-sm`),children:[a&&h(`div`,{className:`flex flex-col space-y-1.5 p-4 pb-3`,children:h(`h3`,{className:`text-base font-semibold leading-none tracking-tight`,children:a})}),h(`div`,{className:e(`p-4`,a?``:`pt-4`),children:g(`form`,{onSubmit:s,className:`space-y-4`,children:[n,g(`div`,{className:`flex justify-end gap-2 pt-2`,children:[h(`button`,{type:`button`,className:e(`inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors`,`hover:bg-accent hover:text-accent-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r?.({name:`cancel`,params:{formId:i}}),children:`Cancel`}),h(`button`,{type:`submit`,className:e(`inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow transition-colors`,`hover:bg-primary/90`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),children:o})]})]})})]})}function fe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{id:n,name:n,type:`text`,placeholder:i,required:a,defaultValue:o,autoComplete:`off`,onKeyDown:R,onKeyUp:R,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function pe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o,rows:s=3}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`textarea`,{id:n,name:n,placeholder:i,required:a,defaultValue:o,rows:s,onKeyDown:R,onKeyUp:R,className:e(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function me({element:t}){let{name:n=`date`,label:r=`Date`,required:i,defaultValue:a,min:o,max:s}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,i&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{type:`date`,id:n,name:n,required:i,defaultValue:a,min:o,max:s,onKeyDown:R,onKeyUp:R,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}const z={Form:de,TextField:fe,TextArea:pe,DateField:me},he=p.object({formId:p.string(),data:p.record(p.string(),p.string())}),ge=p.object({formId:p.string()});function B({ui:e,context:r,onSubmit:i,onCancel:a,registry:o=z}){let c=s(e=>{let t=he.safeParse(e);t.success?i(t.data.formId,t.data.data):console.warn(`Form submit: Invalid params`,t.error.flatten())},[i]),l=s(e=>{let t=ge.safeParse(e);t.success?a?.(t.data.formId):console.warn(`Form cancel: Invalid params`,t.error.flatten())},[a]);return h(t,{registry:o,initialData:r,actionHandlers:u(()=>({submit:c,cancel:l}),[c,l]),children:h(n,{tree:e,registry:o})})}function _e({from:t,...n}){return h(`div`,{"data-slot":`message`,"data-from":t,className:e(`group flex w-full max-w-[95%] flex-col gap-2`,t===`user`?`is-user ml-auto justify-end`:`is-assistant`),...n})}function ve({children:t,style:n,...r}){return h(`div`,{"data-slot":`message-content`,className:e(`flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm`,`group-[.is-user]:ml-auto group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground`,`group-[.is-assistant]:text-foreground`),style:{borderRadius:`var(--cmdk-radius, 0.5rem)`,...n},...r,children:t})}const ye=o(function(e){return h(_,{"data-slot":`message-response`,className:`size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0`,...e})},(e,t)=>e.children===t.children);function be({...e}){return h(T.Root,{"data-slot":`collapsible`,...e})}function xe({...e}){return h(T.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function Se({...e}){return h(T.CollapsibleContent,{"data-slot":`collapsible-content`,...e})}function Ce({children:e,...t}){return h(`div`,{"data-slot":`task-item-file`,className:`inline-flex items-center gap-1 rounded-md border bg-secondary px-1.5 py-0.5 text-xs text-foreground`,...t,children:e})}function we({children:e,...t}){return h(`div`,{"data-slot":`task-item`,className:`text-sm text-muted-foreground`,...t,children:e})}function Te({defaultOpen:e=!0,...t}){return h(be,{"data-slot":`task`,defaultOpen:e,...t})}function Ee({children:e,title:t,icon:n,...r}){return h(xe,{asChild:!0,className:`group`,...r,children:e??g(`div`,{className:`flex w-full cursor-pointer items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[n??h(S,{className:`size-4`}),h(`p`,{className:`text-sm`,children:t}),h(v,{className:`size-4 transition-transform group-data-[state=open]:rotate-180`})]})})}function De({children:t,...n}){return h(Se,{"data-slot":`task-content`,className:e(`text-popover-foreground outline-none`,`data-[state=closed]:animate-out data-[state=open]:animate-in`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2`),...n,children:h(`div`,{className:`mt-4 space-y-2 border-l-2 border-muted pl-4`,children:t})})}const Oe=p.object({name:p.string(),options:p.record(p.string(),p.unknown()).optional()}),ke=p.object({actions:p.array(Oe).optional()}),Ae=p.object({id:p.string(),approved:p.boolean().optional()}),je=p.object({type:p.string(),props:p.record(p.string(),p.unknown()).default({}),children:p.array(p.string()).optional(),parentKey:p.string().nullable().optional()}),Me=p.object({ui:p.object({elements:p.record(p.string(),je)}),context:p.record(p.string(),p.unknown()).optional()});function Ne(e){return e.name}function Pe({messages:e,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r=Ne}){let i=e.filter(e=>e.role===`user`||e.role===`assistant`);return h(m,{children:i.map((e,a)=>{let o=a===i.length-1;return h(_e,{from:e.role,children:h(ve,{children:e.parts.map((i,a)=>h(Fe,{part:i,messageId:e.id,partIndex:a,isLastMessage:o,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r},`${e.id}-${a}`))})},e.id)})})}function Fe({part:e,messageId:t,partIndex:n,isLastMessage:r,sendMessage:i,addToolApprovalResponse:a,getActionDescription:o}){if(e.type===`text`)return h(ye,{children:e.text});if(e.type===`tool-performActions`){let r=`input`in e?e.input:void 0,i=ke.safeParse(r),s=i.success?i.data.actions??[]:[];if(s.length===0)return null;let c=s.length,l=`state`in e?e.state:void 0,u=`approval`in e?e.approval:void 0,d=Ae.safeParse(u),f=d.success?d.data:void 0;return f&&l?g(ae,{state:l,approval:f,children:[h(oe,{children:c===1?`Confirm action`:`Confirm ${c} actions`}),h(se,{children:h(`ul`,{className:`list-disc list-inside text-sm text-muted-foreground mt-2`,children:s.map((e,r)=>h(`li`,{children:o(e)},`${t}-${n}-${r}`))})}),h(ce,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action approved`:`${c} actions approved`})}),h(le,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action cancelled`:`${c} actions cancelled`})}),g(ue,{children:[h(L,{variant:`outline`,onClick:()=>a({id:f.id,approved:!1}),children:`Deny`}),h(L,{onClick:()=>a({id:f.id,approved:!0}),children:`Approve`})]})]}):g(Te,{defaultOpen:!1,children:[h(Ee,{title:c===1?`Performing 1 action`:`Performing ${c} actions`}),h(De,{children:s.map((e,r)=>h(we,{children:o(e)},`${t}-${n}-${r}`))})]})}return e.type===`tool-renderUI`&&r&&(`state`in e?e.state:void 0)===`output-available`&&`output`in e?h(Ie,{output:e.output,sendMessage:i}):null}function Ie({output:e,sendMessage:t}){let n=i.useMemo(()=>{let t=Me.safeParse(e);return t.success?{ui:r(Object.entries(t.data.ui.elements).map(([e,t])=>({...t,key:e}))),context:t.data.context}:null},[e]),a=i.useCallback((e,n)=>{t({text:`[Form:${e}] ${JSON.stringify(n)}`})},[t]),o=i.useCallback(e=>{t({text:`[Form:${e}] cancelled`})},[t]);return n?h(B,{ui:n.ui,context:n.context,onSubmit:a,onCancel:o}):null}const Le=E(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function Re({className:t,variant:n=`default`,size:r=`default`,asChild:i=!1,...a}){return h(i?O.Root:`button`,{"data-slot":`button`,"data-variant":n,"data-size":r,className:e(Le({variant:n,size:r,className:t})),...a})}function ze({children:t,className:n,...r}){let a=i.useRef(null);return i.useEffect(()=>{a.current&&(a.current.scrollTop=a.current.scrollHeight)},[t]),h(`div`,{ref:a,"data-slot":`chat-message-list`,className:e(`flex flex-col overflow-y-auto scroll-smooth`,n),...r,children:t})}function Be({text:t=`AI is thinking...`,className:n,...r}){return g(`div`,{"data-slot":`chat-loading`,className:e(`flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground`,n),...r,children:[h(b,{className:`size-4 animate-spin`}),h(`span`,{children:t})]})}function Ve({title:t=`Start a conversation`,description:n=`Ask a question or describe what you need help with.`,className:r,...i}){return h(`div`,{"data-slot":`chat-empty`,className:e(`flex flex-col items-center justify-center gap-2 py-8 text-center`,r),...i,children:g(`div`,{className:`space-y-1`,children:[h(`h3`,{className:`text-sm font-medium`,children:t}),h(`p`,{className:`text-xs text-muted-foreground`,children:n})]})})}function He({...e}){return h(D.Root,{"data-slot":`dialog`,...e})}function Ue({...e}){return h(D.Trigger,{"data-slot":`dialog-trigger`,...e})}function V({...e}){return h(D.Portal,{"data-slot":`dialog-portal`,...e})}function We({...e}){return h(D.Close,{"data-slot":`dialog-close`,...e})}function Ge({className:t,...n}){return h(D.Overlay,{"data-slot":`dialog-overlay`,className:e(`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50`,t),...n})}function Ke({className:t,children:n,showCloseButton:r=!0,...i}){return g(V,{"data-slot":`dialog-portal`,children:[h(Ge,{}),g(D.Content,{"data-slot":`dialog-content`,className:e(`bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg`,t),...i,children:[n,r&&g(D.Close,{"data-slot":`dialog-close`,className:`ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[h(w,{}),h(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function qe({className:t,...n}){return h(`div`,{"data-slot":`dialog-header`,className:e(`flex flex-col gap-2 text-center sm:text-left`,t),...n})}function Je({className:t,showCloseButton:n=!1,children:r,...i}){return g(`div`,{"data-slot":`dialog-footer`,className:e(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,t),...i,children:[r,n&&h(D.Close,{asChild:!0,children:h(Re,{variant:`outline`,children:`Close`})})]})}function Ye({className:t,...n}){return h(D.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function Xe({className:t,...n}){return h(D.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function H({className:t,...n}){return h(`kbd`,{"data-slot":`kbd`,className:e(`bg-muted text-muted-foreground pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium select-none`,`[&_svg:not([class*='size-'])]:size-3`,`[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10`,t),...n})}function Ze({className:t,...n}){return h(`kbd`,{"data-slot":`kbd-group`,className:e(`inline-flex items-center gap-1`,t),...n})}function Qe({className:t,...n}){return h(k,{"data-slot":`command`,className:e(`bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md`,t),...n})}function $e({className:t,children:n,...r}){return h(V,{"data-slot":`dialog-portal`,children:h(D.Content,{"data-slot":`dialog-content`,className:e(`bg-background fixed top-1/3 left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] overflow-hidden rounded-xl border-none p-2 shadow-2xl ring-4 ring-neutral-200/80 duration-200 outline-none sm:max-w-lg dark:bg-neutral-900 dark:ring-neutral-800`,t),...r,children:n})})}function et({className:t,...n}){return h(k.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function U({className:t,...n}){return h(k.Group,{"data-slot":`command-group`,className:e(`text-foreground !p-0 [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden [&_[cmdk-group-heading]]:scroll-mt-16 [&_[cmdk-group-heading]]:pt-0! [&_[cmdk-group-heading]]:!p-3 [&_[cmdk-group-heading]]:!pb-1 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium`,t),...n})}function tt({className:t,...n}){return h(k.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function W({className:t,style:n,...r}){return h(k.Item,{"data-slot":`command-item`,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 [&_svg:not([class*='text-'])]:text-muted-foreground relative flex h-9 cursor-default items-center gap-2 border border-transparent px-3 text-sm font-medium outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,t),style:{borderRadius:`var(--cmdk-radius, 0.375rem)`,...n},...r})}function nt({className:t,children:n,...r}){let i=typeof n==`string`?[...n]:null;return h(`span`,{"data-slot":`command-shortcut`,className:e(`ml-auto flex items-center gap-1`,t),...r,children:i?i.map((e,t)=>h(H,{children:e},t)):n})}function rt(){return crypto.randomUUID()}function it(e){let t=e.find(e=>e.role===`user`);if(!t)return`New conversation`;let n=t.parts?.filter(e=>e.type===`text`).map(e=>e.text).join(` `)||`New conversation`;return n.length>50?n.slice(0,50)+`...`:n}function at(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function ot({storageKey:e=`cmdk-chat-history`,maxConversations:t=50,messages:n,setMessages:r}){let[i,a]=f([]),[o,c]=f(null),[p,m]=f(!1),h=d(n);h.current=n;let g=d(r);g.current=r;let _=d(i);_.current=i;let v=d(o);v.current=o,l(()=>{try{let t=localStorage.getItem(e);if(t){let n=at(JSON.parse(t));n?a(n.conversations):(console.warn(`Chat history: stored data failed validation. Discarding.`),localStorage.removeItem(e))}}catch(e){console.error(`Failed to load chat history:`,e)}finally{m(!0)}},[e]),l(()=>{if(p)try{let t={version:1,conversations:i};localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(`Failed to save chat history:`,e)}},[i,e,p]);let y=s(()=>{let e=h.current,n=v.current;!n||e.length===0||a(r=>{let i=Date.now();return r.find(e=>e.id===n)?r.map(t=>t.id===n?{...t,messages:e,title:it(e),updatedAt:i}:t):[{id:n,title:it(e),messages:e,createdAt:i,updatedAt:i},...r].slice(0,t)})},[t]),b=s(()=>{v.current&&h.current.length>0&&y(),g.current?.([]),c(rt())},[y]),x=s(e=>{v.current&&h.current.length>0&&y();let t=_.current.find(t=>t.id===e);t&&(g.current?.(t.messages),c(e))},[y]);return u(()=>({conversations:i,currentConversationId:o,startNewChat:b,loadConversation:x,saveCurrentConversation:y}),[i,o,b,x,y])}let G=null,K=null;function st(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function ct(e,t){return delete e.user,delete e.server_name,e.request&&(delete e.request.cookies,delete e.request.headers,delete e.request.env,delete e.request.data),e.breadcrumbs=[],e}function lt(){typeof window>`u`||G===null&&(st()||(G=new j({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:re,stackParser:P,integrations:[N(),F()],beforeSend:ct,sendDefaultPii:!1,tracesSampleRate:1}),K=new M,K.setClient(G),G.init()))}function q(e,t){!K||!G||(t?K.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):K.captureException(e))}function J(e){try{let t=new Uint8Array(e/2);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}catch{let t=``;for(let n=0;n<e;n++)t+=Math.floor(Math.random()*16).toString(16);return t}}function ut(e,t,n){if(!K||!G)return n();let r=Date.now()/1e3,i=J(32),a=J(16),o=`ok`,s=()=>{let n=Date.now()/1e3;K.captureEvent({type:`transaction`,transaction:e,start_timestamp:r,timestamp:n,contexts:{trace:{trace_id:i,span_id:a,op:t,status:o}}})};try{let e=n();return e instanceof Promise?e.then(e=>(s(),e),e=>{throw o=`internal_error`,s(),e}):(s(),e)}catch(e){throw o=`internal_error`,s(),e}}const Y=i.createContext(null),dt=[];function ft({children:e,chatEndpoint:t=null,chat:n,onModeChange:r,onOpenChange:a,historyStorageKey:o,maxConversations:s}){let[c,l]=i.useState(`command`),[u,d]=i.useState(``),[f,p]=i.useState(`idle`),[m,g]=i.useState(null),_=i.useRef(n);_.current=n;let v=!!n;i.useEffect(()=>{lt()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new ne({api:t})},[t,v]),b=te(i.useMemo(()=>y?{transport:y,onError:e=>{q(e,{source:`internalChat.onError`}),p(`error`),g(e)}}:{},[y])),x=n?.status,S=n?.error??null;i.useEffect(()=>{if(v)x===`ready`?p(`idle`):x===`streaming`?p(`streaming`):x===`submitted`?p(`submitted`):x===`error`&&p(`error`),g(S);else{let e=b.status;e===`streaming`?p(`streaming`):e===`submitted`?p(`submitted`):e===`error`?p(`error`):e===`ready`&&p(`idle`)}},[x,S,b.status,v]);let C=i.useCallback(e=>{l(e),r?.(e)},[r]),w=!!(n||t),T=i.useCallback(e=>{w&&ut(`switchToChat`,`ui.action`,()=>{C(`chat`),e&&d(e)})},[w,C]),E=i.useCallback(()=>{C(`command`),d(``),p(`idle`),g(null)},[C]),D=i.useCallback(async e=>{e.trim()&&await ut(`sendMessage`,`function`,async()=>{try{let t=_.current;if(t){d(``),t.sendMessage({text:e.trim()});return}if(!y)return;p(`submitted`),d(``),await b.sendMessage({text:e.trim()})}catch(e){throw q(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??dt,ee=n?.setMessages??b.setMessages,A=n?.addToolApprovalResponse,j=n?.agenticActions,M=ot({storageKey:o,maxConversations:s,messages:k,setMessages:ee}),N=i.useCallback(e=>{M.loadConversation(e),C(`chat`)},[M.loadConversation,C]),P=i.useRef(f);i.useEffect(()=>{let e=P.current;P.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&M.saveCurrentConversation()},[f,k.length,M.saveCurrentConversation]);let F=i.useCallback(()=>{a?.(!1)},[a]),re=i.useMemo(()=>({mode:c,setMode:C,inputValue:u,setInputValue:d,chatEndpoint:t,status:f,error:m,switchToChat:T,switchToCommand:E,messages:k,sendMessage:D,isLoading:O,isEnabled:w,addToolApprovalResponse:A,agenticActions:j,requestClose:F,conversations:M.conversations,currentConversationId:M.currentConversationId,startNewChat:M.startNewChat,loadConversation:N}),[c,C,u,t,f,m,T,E,k,D,O,w,A,j,F,M.conversations,M.currentConversationId,M.startNewChat,N]);return h(Y.Provider,{value:re,children:e})}function X(){let e=i.useContext(Y);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}var pt=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){q(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};const mt=e=>{},ht={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},gt={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`};function _t(e){let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function vt({className:t,children:n,corners:r=`xl`,borderColor:i,...a}){return h(V,{"data-slot":`dialog-portal`,children:h(D.Content,{"data-slot":`dialog-content`,className:e(`bg-background fixed top-1/3 left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] overflow-hidden border-none p-2 shadow-2xl ring-4 ring-neutral-200/80 duration-200 outline-none sm:max-w-lg dark:bg-neutral-900 dark:ring-neutral-800`,ht[r],t),style:{"--cmdk-radius":gt[r],...i?{"--tw-ring-color":i}:{}},...a,children:n})})}const yt=g(m,{children:[h(Z,{placeholder:`Search or ask AI...`,showSendButton:!0}),h($,{children:h(Q,{})})]});function bt({title:t=`Command Palette`,description:n=`Search for a command to run...`,children:r,className:i,corners:a=`xl`,borderColor:o,commands:s,commandsPlaceholder:c=`Search or ask AI...`,commandsAskAILabel:l=`Ask AI`,...u}){let{mode:d,status:f,switchToCommand:p,messages:m,isEnabled:_,sendMessage:v,addToolApprovalResponse:y}=X(),b=()=>s&&s.length>0?h(Ct,{commands:s,placeholder:c,askAILabel:l}):typeof r==`function`?r({mode:d,messages:m,status:f,isEnabled:_}):r??yt,x=e=>{d===`chat`&&(e.preventDefault(),p())};return h(He,{...u,children:g(vt,{className:i,corners:a,borderColor:o,onEscapeKeyDown:x,children:[g(qe,{className:`sr-only`,children:[h(Ye,{children:t}),h(Xe,{children:n})]}),h(k,{"data-slot":`command`,className:e(`**:data-[slot=command-input-wrapper]:bg-input/50 **:data-[slot=command-input-wrapper]:border-input rounded-none bg-transparent **:data-[slot=command-input]:!h-9 **:data-[slot=command-input]:py-0 **:data-[slot=command-input-wrapper]:mb-0 **:data-[slot=command-input-wrapper]:!h-9 **:data-[slot=command-input-wrapper]:border`,`bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden`),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},children:b()})]})})}function xt({chatEndpoint:e=null,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,...l}){return h(ft,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(pt,{children:h(bt,{onOpenChange:r,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,...l})})})}function Z({className:t,showSendButton:n=!1,...r}){let{mode:i,inputValue:a,setInputValue:o,sendMessage:s,isLoading:c,switchToChat:l,startNewChat:u}=X(),d=()=>{a.trim()&&i===`chat`&&s(a)},f=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`Enter`){e.preventDefault(),i===`command`&&a.trim()?(u(),l(),s(a)):i===`chat`&&a.trim()&&s(a);return}if(i===`chat`&&e.key===`Enter`&&!e.shiftKey){e.preventDefault(),a.trim()&&s(a);return}};return g(`div`,{"data-slot":`command-input-wrapper`,className:`order-2 flex h-9 items-center gap-2 border-t px-3 mt-2`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},children:[i===`command`?h(S,{className:`size-4 shrink-0 opacity-50`}):h(C,{className:`size-4 shrink-0 text-primary`}),h(k.Input,{"data-slot":`command-input`,value:a,onValueChange:o,onKeyDown:f,className:e(`placeholder:text-muted-foreground flex h-10 w-full bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50`,t),...r,placeholder:i===`chat`?`Ask AI...`:r.placeholder}),n&&i===`chat`&&h(`button`,{type:`button`,onClick:d,disabled:!a.trim()||c,className:`flex items-center justify-center size-6 bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},children:h(y,{className:`size-3`})})]})}function Q({label:t=`Ask AI`,className:n,...r}){let{inputValue:i,setInputValue:a,switchToChat:o,sendMessage:s,isEnabled:c,startNewChat:l}=X(),u=A(e=>e.filtered.count),d=()=>{if(c)if(i.trim()){let e=ee(`ask-ai`,i.trim())>0;u===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(k.Group,{forceMount:!0,children:g(k.Item,{"data-slot":`command-item`,value:`ask-ai`,onSelect:d,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 relative flex cursor-default items-center gap-3 border border-transparent px-3 py-2 text-sm outline-hidden select-none`,n),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},...r,children:[h(C,{className:`size-4 shrink-0 text-primary`}),h(`div`,{className:`flex flex-col items-start gap-0.5`,children:h(`span`,{className:`font-medium`,children:t})}),g(`span`,{className:`ml-auto flex items-center gap-1`,children:[h(H,{children:`⌘`}),h(H,{children:`↵`})]})]})}):h(k.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function St(e){let t=[],n=new Map;for(let r of e){let e=r.group,i=n.get(e);i===void 0?(n.set(e,t.length),t.push({heading:e,items:[r]})):t[i].items.push(r)}let r=t.findIndex(e=>e.heading===void 0);if(r>0){let e=t.splice(r,1)[0];t.unshift(e)}return t}function Ct({commands:e,placeholder:t,askAILabel:n}){let r=St(e);return g(m,{children:[h(Z,{placeholder:t,showSendButton:!0}),g($,{children:[r.map((e,t)=>{let n=e.items.map(e=>{let t=e.label??e.name,n=[...e.keywords??[]];return e.label&&e.label!==e.name&&n.push(e.label),g(W,{value:e.name,keywords:n.length>0?n:void 0,disabled:e.disabled,onSelect:()=>e.onSelect?.(),children:[e.icon,t,e.shortcut&&h(nt,{children:e.shortcut})]},e.name)});return e.heading?h(U,{heading:e.heading,children:n},e.heading):h(i.Fragment,{children:n},`__ungrouped_${t}`)}),h(Q,{label:n})]})]})}function $({className:t,children:n,actions:r,actionsHeading:a=`Actions`,...o}){let{mode:s,status:c,messages:l,sendMessage:u,addToolApprovalResponse:d,agenticActions:f,requestClose:p,switchToChat:m,startNewChat:_,conversations:v,loadConversation:y}=X(),b=i.useCallback(e=>u(e.text),[u]),S=d??mt;if(s===`chat`)return h(`div`,{"data-slot":`command-list`,className:e(`order-1 max-h-[300px] min-h-0 flex-1 overflow-hidden`,t),children:l.length===0?h(Ve,{}):g(ze,{className:`max-h-[300px]`,children:[h(`div`,{className:`px-3 py-2 space-y-4`,children:h(Pe,{messages:l,sendMessage:b,addToolApprovalResponse:S})}),c===`streaming`&&h(Be,{})]})});let C=i.Children.toArray(n),w=[],T=[];C.forEach(e=>{i.isValidElement(e)&&(e.type===Q||e.type.displayName===`CommandEmpty`)?w.push(e):i.isValidElement(e)&&e.type===et||T.push(e)});let E=(r??f)?.filter(e=>e.execute),D=e=>{let t=e.label??e.name;_(),m(),u(t)};return g(k.List,{"data-slot":`command-list`,className:e(`order-1 max-h-[300px] min-h-0 flex-1 overflow-x-hidden overflow-y-auto`,t),...o,children:[T,v.length>0&&h(U,{heading:`Recent Chats`,children:v.slice(0,5).map(e=>g(W,{value:`chat-history-${e.id}`,keywords:[e.title],onSelect:()=>y(e.id),children:[h(x,{className:`size-4`}),h(`span`,{className:`truncate`,children:e.title}),h(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:_t(e.updatedAt)})]},e.id))}),E&&E.length>0&&h(U,{heading:a,children:E.map(e=>h(W,{value:e.label??e.name,onSelect:()=>D(e),children:e.label??e.name},e.name))}),w]})}Q.displayName=`CommandEmpty`;export{B as AssistantFormRenderer,Pe as AssistantMessages,Re as Button,Ve as ChatEmpty,Be as ChatLoading,ze as ChatMessageList,be as Collapsible,Se as CollapsibleContent,xe as CollapsibleTrigger,Qe as Command,vt as CommandContent,xt as CommandDialog,xt as CommandMenu,$e as CommandDialogContent,Q as CommandEmpty,U as CommandGroup,Z as CommandInput,W as CommandItem,$ as CommandList,Y as CommandMenuContext,ft as CommandMenuProvider,tt as CommandSeparator,nt as CommandShortcut,ae as Confirmation,ce as ConfirmationAccepted,L as ConfirmationAction,ue as ConfirmationActions,le as ConfirmationRejected,se as ConfirmationRequest,oe as ConfirmationTitle,He as Dialog,We as DialogClose,Ke as DialogContent,Xe as DialogDescription,Je as DialogFooter,qe as DialogHeader,Ge as DialogOverlay,V as DialogPortal,Ye as DialogTitle,Ue as DialogTrigger,H as Kbd,Ze as KbdGroup,_e as Message,ve as MessageContent,ye as MessageResponse,Te as Task,De as TaskContent,we as TaskItem,Ce as TaskItemFile,Ee as TaskTrigger,Le as buttonVariants,e as cn,z as defaultFormRegistry,ot as useChatHistory,X as useCommandMenuContext};
|
|
1
|
+
import{cn as e}from"./lib/utils.js";import{JSONUIProvider as t,Renderer as n,flatToTree as r}from"@json-render/react";import*as i from"react";import{createContext as a,memo as o,useCallback as s,useContext as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{z as p}from"zod";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";import{Streamdown as _}from"streamdown";import{ArrowUpIcon as v,ChevronDownIcon as y,KeyboardIcon as b,LoaderIcon as x,MessageCircleIcon as S,SearchIcon as C,XIcon as w}from"lucide-react";import*as T from"@radix-ui/react-collapsible";import{cva as E}from"class-variance-authority";import{Dialog as D,Slot as O}from"radix-ui";import*as k from"@radix-ui/react-dialog";import{Primitive as A}from"@radix-ui/react-primitive";import{useId as j}from"@radix-ui/react-id";import{composeRefs as M}from"@radix-ui/react-compose-refs";import{motion as N}from"motion/react";import{useChat as P}from"@ai-sdk/react";import{DefaultChatTransport as F}from"ai";import{BrowserClient as I,Scope as L,dedupeIntegration as R,defaultStackParser as ee,linkedErrorsIntegration as te,makeFetchTransport as ne}from"@sentry/browser";const z=a(null);function B(){let e=c(z);if(!e)throw Error(`Confirmation components must be used within Confirmation`);return e}function re({approval:t,state:n,style:r,...i}){return!t||n===`input-streaming`||n===`input-available`?null:h(z.Provider,{value:{approval:t,state:n},children:h(`div`,{"data-slot":`confirmation`,"data-state":n,"data-approved":t?.approved,role:`alertdialog`,"aria-labelledby":`confirmation-title`,style:{borderRadius:`var(--cmdk-radius, 0.5rem)`,...r},className:e(`flex flex-col gap-2 border p-4`,`data-[state=approval-requested]:border-amber-500/50 data-[state=approval-requested]:bg-amber-50/50 dark:data-[state=approval-requested]:bg-amber-950/20`,`data-[approved=true]:border-green-500/50 data-[approved=true]:bg-green-50/50 dark:data-[approved=true]:bg-green-950/20`,`data-[approved=false]:border-red-500/50 data-[approved=false]:bg-red-50/50 dark:data-[approved=false]:bg-red-950/20`),...i})})}function ie(e){return h(`p`,{id:`confirmation-title`,"data-slot":`confirmation-title`,className:`text-sm font-medium`,...e})}function ae({children:e}){let{state:t}=B();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function oe({children:e}){let{approval:t,state:n}=B();return!t?.approved||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-accepted`,children:e})}function se({children:e}){let{approval:t,state:n}=B();return t?.approved!==!1||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-rejected`,children:e})}function ce(e){let{state:t}=B();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-actions`,className:`flex items-center justify-end gap-2 self-end`,...e}):null}function le({variant:t=`default`,style:n,...r}){return h(`button`,{"data-slot":`confirmation-action`,"data-variant":t,type:`button`,className:e(`inline-flex h-8 items-center justify-center gap-2 whitespace-nowrap px-3 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`,t===`default`&&`bg-primary text-primary-foreground shadow hover:bg-primary/90`,t===`outline`&&`border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground`,t===`destructive`&&`bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90`),style:{borderRadius:`var(--cmdk-radius, 0.375rem)`,...n},...r})}function V(e){e.stopPropagation()}function ue({element:t,children:n,onAction:r}){let{id:i=`form`,title:a,submitLabel:o=`Submit`}=t.props??{},s=e=>{e.preventDefault();let t=new FormData(e.currentTarget),n={};t.forEach((e,t)=>{typeof e==`string`&&(n[t]=e)}),r?.({name:`submit`,params:{formId:i,data:n}})};return g(`div`,{"data-slot":`form-card`,className:e(`w-full rounded-lg border bg-card text-card-foreground shadow-sm`),children:[a&&h(`div`,{className:`flex flex-col space-y-1.5 p-4 pb-3`,children:h(`h3`,{className:`text-base font-semibold leading-none tracking-tight`,children:a})}),h(`div`,{className:e(`p-4`,a?``:`pt-4`),children:g(`form`,{onSubmit:s,className:`space-y-4`,children:[n,g(`div`,{className:`flex justify-end gap-2 pt-2`,children:[h(`button`,{type:`button`,className:e(`inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors`,`hover:bg-accent hover:text-accent-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r?.({name:`cancel`,params:{formId:i}}),children:`Cancel`}),h(`button`,{type:`submit`,className:e(`inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow transition-colors`,`hover:bg-primary/90`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),children:o})]})]})})]})}function de({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{id:n,name:n,type:`text`,placeholder:i,required:a,defaultValue:o,autoComplete:`off`,onKeyDown:V,onKeyUp:V,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function fe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o,rows:s=3}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`textarea`,{id:n,name:n,placeholder:i,required:a,defaultValue:o,rows:s,onKeyDown:V,onKeyUp:V,className:e(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function pe({element:t}){let{name:n=`date`,label:r=`Date`,required:i,defaultValue:a,min:o,max:s}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,i&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{type:`date`,id:n,name:n,required:i,defaultValue:a,min:o,max:s,onKeyDown:V,onKeyUp:V,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}const me={Form:ue,TextField:de,TextArea:fe,DateField:pe},he=p.object({formId:p.string(),data:p.record(p.string(),p.string())}),ge=p.object({formId:p.string()});function _e({ui:e,context:r,onSubmit:i,onCancel:a,registry:o=me}){let c=s(e=>{let t=he.safeParse(e);t.success?i(t.data.formId,t.data.data):console.warn(`Form submit: Invalid params`,t.error.flatten())},[i]),l=s(e=>{let t=ge.safeParse(e);t.success?a?.(t.data.formId):console.warn(`Form cancel: Invalid params`,t.error.flatten())},[a]);return h(t,{registry:o,initialData:r,actionHandlers:u(()=>({submit:c,cancel:l}),[c,l]),children:h(n,{tree:e,registry:o})})}function ve({from:t,...n}){return h(`div`,{"data-slot":`message`,"data-from":t,className:e(`group flex w-full max-w-[95%] flex-col gap-2`,t===`user`?`is-user ml-auto justify-end`:`is-assistant`),...n})}function ye({children:t,style:n,...r}){return h(`div`,{"data-slot":`message-content`,className:e(`flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm`,`group-[.is-user]:ml-auto group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground`,`group-[.is-assistant]:text-foreground`),style:{borderRadius:`var(--cmdk-radius, 0.5rem)`,...n},...r,children:t})}const be=o(function(e){return h(_,{"data-slot":`message-response`,className:`size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0`,...e})},(e,t)=>e.children===t.children);function xe({...e}){return h(T.Root,{"data-slot":`collapsible`,...e})}function Se({...e}){return h(T.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function Ce({...e}){return h(T.CollapsibleContent,{"data-slot":`collapsible-content`,...e})}function we({children:e,...t}){return h(`div`,{"data-slot":`task-item-file`,className:`inline-flex items-center gap-1 rounded-md border bg-secondary px-1.5 py-0.5 text-xs text-foreground`,...t,children:e})}function Te({children:e,...t}){return h(`div`,{"data-slot":`task-item`,className:`text-sm text-muted-foreground`,...t,children:e})}function Ee({defaultOpen:e=!0,...t}){return h(xe,{"data-slot":`task`,defaultOpen:e,...t})}function De({children:e,title:t,icon:n,...r}){return h(Se,{asChild:!0,className:`group`,...r,children:e??g(`div`,{className:`flex w-full cursor-pointer items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[n??h(C,{className:`size-4`}),h(`p`,{className:`text-sm`,children:t}),h(y,{className:`size-4 transition-transform group-data-[state=open]:rotate-180`})]})})}function Oe({children:t,...n}){return h(Ce,{"data-slot":`task-content`,className:e(`text-popover-foreground outline-none`,`data-[state=closed]:animate-out data-[state=open]:animate-in`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2`),...n,children:h(`div`,{className:`mt-4 space-y-2 border-l-2 border-muted pl-4`,children:t})})}const ke=p.object({name:p.string(),options:p.record(p.string(),p.unknown()).optional()}),Ae=p.object({actions:p.array(ke).optional()}),je=p.object({id:p.string(),approved:p.boolean().optional()}),Me=p.object({type:p.string(),props:p.record(p.string(),p.unknown()).default({}),children:p.array(p.string()).optional(),parentKey:p.string().nullable().optional()}),Ne=p.object({ui:p.object({elements:p.record(p.string(),Me)}),context:p.record(p.string(),p.unknown()).optional()});function Pe(e){return e.name}function Fe({messages:e,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r=Pe}){let i=e.filter(e=>e.role===`user`||e.role===`assistant`);return h(m,{children:i.map((e,a)=>{let o=a===i.length-1;return h(ve,{from:e.role,children:h(ye,{children:e.parts.map((i,a)=>h(Ie,{part:i,messageId:e.id,partIndex:a,isLastMessage:o,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r},`${e.id}-${a}`))})},e.id)})})}function Ie({part:e,messageId:t,partIndex:n,isLastMessage:r,sendMessage:i,addToolApprovalResponse:a,getActionDescription:o}){if(e.type===`text`)return h(be,{children:e.text});if(e.type===`tool-performActions`){let r=`input`in e?e.input:void 0,i=Ae.safeParse(r),s=i.success?i.data.actions??[]:[];if(s.length===0)return null;let c=s.length,l=`state`in e?e.state:void 0,u=`approval`in e?e.approval:void 0,d=je.safeParse(u),f=d.success?d.data:void 0;return f&&l?g(re,{state:l,approval:f,children:[h(ie,{children:c===1?`Confirm action`:`Confirm ${c} actions`}),h(ae,{children:h(`ul`,{className:`list-disc list-inside text-sm text-muted-foreground mt-2`,children:s.map((e,r)=>h(`li`,{children:o(e)},`${t}-${n}-${r}`))})}),h(oe,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action approved`:`${c} actions approved`})}),h(se,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action cancelled`:`${c} actions cancelled`})}),g(ce,{children:[h(le,{variant:`outline`,onClick:()=>a({id:f.id,approved:!1}),children:`Deny`}),h(le,{onClick:()=>a({id:f.id,approved:!0}),children:`Approve`})]})]}):g(Ee,{defaultOpen:!1,children:[h(De,{title:c===1?`Performing 1 action`:`Performing ${c} actions`}),h(Oe,{children:s.map((e,r)=>h(Te,{children:o(e)},`${t}-${n}-${r}`))})]})}return e.type===`tool-renderUI`&&r&&(`state`in e?e.state:void 0)===`output-available`&&`output`in e?h(Le,{output:e.output,sendMessage:i}):null}function Le({output:e,sendMessage:t}){let n=i.useMemo(()=>{let t=Ne.safeParse(e);return t.success?{ui:r(Object.entries(t.data.ui.elements).map(([e,t])=>({...t,key:e}))),context:t.data.context}:null},[e]),a=i.useCallback((e,n)=>{t({text:`[Form:${e}] ${JSON.stringify(n)}`})},[t]),o=i.useCallback(e=>{t({text:`[Form:${e}] cancelled`})},[t]);return n?h(_e,{ui:n.ui,context:n.context,onSubmit:a,onCancel:o}):null}const Re=E(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function ze({className:t,variant:n=`default`,size:r=`default`,asChild:i=!1,...a}){return h(i?O.Root:`button`,{"data-slot":`button`,"data-variant":n,"data-size":r,className:e(Re({variant:n,size:r,className:t})),...a})}function Be({children:t,className:n,...r}){let a=i.useRef(null);return i.useEffect(()=>{a.current&&(a.current.scrollTop=a.current.scrollHeight)},[t]),h(`div`,{ref:a,"data-slot":`chat-message-list`,className:e(`flex flex-col overflow-y-auto scroll-smooth`,n),...r,children:t})}function Ve({text:t=`AI is thinking...`,className:n,...r}){return g(`div`,{"data-slot":`chat-loading`,className:e(`flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground`,n),...r,children:[h(x,{className:`size-4 animate-spin`}),h(`span`,{children:t})]})}function He({title:t=`Start a conversation`,description:n=`Ask a question or describe what you need help with.`,className:r,...i}){return h(`div`,{"data-slot":`chat-empty`,className:e(`flex flex-col items-center justify-center gap-2 py-8 text-center`,r),...i,children:g(`div`,{className:`space-y-1`,children:[h(`h3`,{className:`text-sm font-medium`,children:t}),h(`p`,{className:`text-xs text-muted-foreground`,children:n})]})})}var Ue=1,We=.9,Ge=.8,Ke=.17,qe=.1,Je=.999,Ye=.9999,Xe=.99,Ze=/[\\\/_+.#"@\[\(\{&]/,Qe=/[\\\/_+.#"@\[\(\{&]/g,$e=/[\s-]/,et=/[\s-]/g;function tt(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Ue:Xe;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=tt(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Ue:Ze.test(e.charAt(l-1))?(d*=Ge,p=e.slice(i,l-1).match(Qe),p&&i>0&&(d*=Je**+p.length)):$e.test(e.charAt(l-1))?(d*=We,m=e.slice(i,l-1).match(et),m&&i>0&&(d*=Je**+m.length)):(d*=Ke,i>0&&(d*=Je**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Ye)),(d<qe&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=tt(e,t,n,r,l+1,a+2,o),f*qe>d&&(d=f*qe)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function nt(e){return e.toLowerCase().replace(et,` `)}function rt(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,tt(e,t,nt(e),nt(t),0,0,{})}const H=`[cmdk-group=""]`,it=`[cmdk-group-items=""]`,at=`[cmdk-item=""]`,ot=`${at}:not([aria-disabled="true"])`,st=`cmdk-item-select`,U=`data-value`,ct=(e,t,n)=>rt(e,t,n),lt=i.createContext(void 0),W=()=>i.useContext(lt),ut=i.createContext(void 0),dt=()=>i.useContext(ut),ft=i.createContext(void 0),pt=i.forwardRef((e,t)=>{let n=q(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=q(()=>new Set),a=q(()=>new Map),o=q(()=>new Map),s=q(()=>new Set),c=wt(e),{label:l,children:u,value:d,onValueChange:f,filter:p,shouldFilter:m,loop:_,disablePointerSelection:v=!1,vimBindings:y=!0,...b}=e,x=j(),S=j(),C=j(),w=i.useRef(null),T=Et();K(()=>{if(d!==void 0){let e=d.trim();n.current.value=e,E.emit()}},[d]),K(()=>{T(6,P)},[]);let E=i.useMemo(()=>({subscribe:e=>(s.current.add(e),()=>s.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)N(),k(),T(1,M);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(C);e?e.focus():document.getElementById(x)?.focus()}if(T(7,()=>{n.current.selectedItemId=F()?.id,E.emit()}),r||T(5,P),c.current?.value!==void 0){let e=t??``;c.current.onValueChange?.(e);return}}E.emit()}},emit:()=>{s.current.forEach(e=>e())}}),[]),D=i.useMemo(()=>({value:(e,t,r)=>{t!==o.current.get(e)?.value&&(o.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,O(t,r)),T(2,()=>{k(),E.emit()}))},item:(e,t)=>(r.current.add(e),t&&(a.current.has(t)?a.current.get(t).add(e):a.current.set(t,new Set([e]))),T(3,()=>{N(),k(),n.current.value||M(),E.emit()}),()=>{o.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=F();T(4,()=>{N(),t?.getAttribute(`id`)===e&&M(),E.emit()})}),group:e=>(a.current.has(e)||a.current.set(e,new Set),()=>{o.current.delete(e),a.current.delete(e)}),filter:()=>c.current.shouldFilter,label:l||e[`aria-label`],getDisablePointerSelection:()=>c.current.disablePointerSelection,listId:x,inputId:C,labelId:S,listInnerRef:w}),[]);function O(e,t){let r=c.current?.filter??ct;return e?r(e,n.current.search,t):0}function k(){if(!n.current.search||c.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=a.current.get(n),i=0;r.forEach(t=>{let n=e.get(t);i=Math.max(n,i)}),t.push([n,i])});let r=w.current;I().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(it);t?t.appendChild(e.parentElement===t?e:e.closest(`${it} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${it} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=w.current?.querySelector(`${H}[cmdk-group-id="${e[0]}"]`);t?.parentElement.appendChild(t)});let i=new Set(t.map(e=>e[0]));w.current?.querySelectorAll(`${H}[cmdk-group-id]`)?.forEach(e=>{let t=e.getAttribute(`cmdk-group-id`);t&&!i.has(t)&&e.parentElement?.appendChild(e)});let o=w.current?.closest(`[cmdk-list]`);o&&(o.scrollTop=0)}function M(){let e=I().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(U);E.setState(`value`,e||void 0)}function N(){if(!n.current.search||c.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=O(o.current.get(t)?.value??``,o.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of a.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function P(){let e=F();e&&(e.parentElement?.firstChild===e&&e.closest(H)?.querySelector(`[cmdk-group-heading=""]`)?.scrollIntoView({block:`nearest`}),e.scrollIntoView({block:`nearest`}))}function F(){return w.current?.querySelector(`${at}[aria-selected="true"]`)}function I(){return Array.from(w.current?.querySelectorAll(ot)||[])}function L(e){let t=I()[e];t&&E.setState(`value`,t.getAttribute(U))}function R(e){let t=F(),n=I(),r=n.findIndex(e=>e===t),i=n[r+e];c.current?.loop&&(i=r+e<0?n[n.length-1]:r+e===n.length?n[0]:n[r+e]),i&&E.setState(`value`,i.getAttribute(U))}function ee(e){let t=F()?.closest(H),n;for(;t&&!n;)t=e>0?St(t,H):Ct(t,H),n=t?.querySelector(ot);n?E.setState(`value`,n.getAttribute(U)):R(e)}let te=()=>L(I().length-1),ne=e=>{e.preventDefault(),e.metaKey?te():e.altKey?ee(1):R(1)},z=e=>{e.preventDefault(),e.metaKey?L(0):e.altKey?ee(-1):R(-1)};return g(A.div,{ref:t,tabIndex:-1,...b,"cmdk-root":``,onKeyDown:e=>{b.onKeyDown?.(e);let t=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||t))switch(e.key){case`n`:case`j`:y&&e.ctrlKey&&ne(e);break;case`ArrowDown`:ne(e);break;case`p`:case`k`:y&&e.ctrlKey&&z(e);break;case`ArrowUp`:z(e);break;case`Home`:e.preventDefault(),L(0);break;case`End`:e.preventDefault(),te();break;case`Enter`:{e.preventDefault();let t=F();if(t){let e=new Event(st);t.dispatchEvent(e)}}}},children:[h(`label`,{"cmdk-label":``,htmlFor:D.inputId,id:D.labelId,style:kt,children:l}),Ot(e,e=>h(ut.Provider,{value:E,children:h(lt.Provider,{value:D,children:e})}))]})}),mt=i.forwardRef((e,t)=>{let n=j(),r=i.useRef(null),a=i.useContext(ft),o=W(),s=wt(e),c=s.current?.forceMount??a?.forceMount;K(()=>o.item(n,a?.id),[c]);let l=Tt(n,r,[e.value,e.children,r],e.keywords),u=dt(),d=J(e=>e.value&&e.value===l.current),f=J(e=>c||o.filter()===!1?!0:e.search?e.filtered.items.get(n)>0:!0);i.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(st,p),()=>t.removeEventListener(st,p)},[f,e.onSelect,e.disabled]);function p(){m(),s.current.onSelect?.(l.current)}function m(){u.setState(`value`,l.current,!0)}if(!f)return null;let{disabled:g,value:_,onSelect:v,forceMount:y,keywords:b,...x}=e;return h(A.div,{ref:M(r,t),...x,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!g,"aria-selected":!!d,"data-disabled":!!g,"data-selected":!!d,onPointerMove:g||o.getDisablePointerSelection()?void 0:m,onClick:g?void 0:p,children:e.children})}),ht=i.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:a,...o}=e,s=j(),c=i.useRef(null),l=i.useRef(null),u=j(),d=W(),f=J(e=>a||d.filter()===!1?!0:e.search?e.filtered.groups.has(s):!0);K(()=>d.group(s),[]),Tt(s,c,[e.value,e.heading,l]);let p=i.useMemo(()=>({id:s,forceMount:a}),[a]);return g(A.div,{ref:M(c,t),...o,"cmdk-group":``,"cmdk-group-id":s,role:`presentation`,hidden:f?void 0:!0,children:[n&&h(`div`,{ref:l,"cmdk-group-heading":``,"aria-hidden":!0,id:u,children:n}),Ot(e,e=>h(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?u:void 0,children:h(ft.Provider,{value:p,children:e})}))]})}),gt=i.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,a=i.useRef(null),o=J(e=>!e.search);return!n&&!o?null:h(A.div,{ref:M(a,t),...r,"cmdk-separator":``,role:`separator`})}),_t=i.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,a=e.value!=null,o=dt(),s=J(e=>e.search),c=J(e=>e.selectedItemId),l=W();return i.useEffect(()=>{e.value!=null&&o.setState(`search`,e.value)},[e.value]),h(A.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":c,id:l.inputId,type:`text`,value:a?e.value:s,onChange:e=>{a||o.setState(`search`,e.target.value),n?.(e.target.value)}})}),vt=i.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...a}=e,o=i.useRef(null),s=i.useRef(null),c=J(e=>e.selectedItemId),l=W();return i.useEffect(()=>{if(s.current&&o.current){let e=s.current,t=o.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),h(A.div,{ref:M(o,t),...a,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":c,"aria-label":r,id:l.listId,children:Ot(e,e=>h(`div`,{ref:M(s,l.listInnerRef),"cmdk-list-sizer":``,children:e}))})}),yt=i.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return h(k.Root,{open:n,onOpenChange:r,children:g(k.Portal,{container:o,children:[h(k.Overlay,{"cmdk-overlay":``,className:i}),h(k.Content,{"aria-label":e.label,"cmdk-dialog":``,className:a,children:h(pt,{ref:t,...s})})]})})}),bt=i.forwardRef((e,t)=>J(e=>e.filtered.count===0)?h(A.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),xt=i.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return h(A.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,children:Ot(e,e=>h(`div`,{"aria-hidden":!0,children:e}))})}),G=Object.assign(pt,{List:vt,Item:mt,Input:_t,Group:ht,Separator:gt,Dialog:yt,Empty:bt,Loading:xt});function St(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Ct(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function wt(e){let t=i.useRef(e);return K(()=>{t.current=e}),t}const K=typeof window>`u`?i.useEffect:i.useLayoutEffect;function q(e){let t=i.useRef();return t.current===void 0&&(t.current=e()),t}function J(e){let t=dt(),n=()=>e(t.snapshot());return i.useSyncExternalStore(t.subscribe,n,n)}function Tt(e,t,n,r=[]){let a=i.useRef(),o=W();return K(()=>{let i=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():a.current}})(),s=r.map(e=>e.trim());o.value(e,i,s),t.current?.setAttribute(U,i),a.current=i}),a}const Et=()=>{let[e,t]=i.useState(),n=q(()=>new Map);return K(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Dt(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function Ot({asChild:e,children:t},n){return e&&i.isValidElement(t)?i.cloneElement(Dt(t),{ref:t.ref},n(t.props.children)):n(t)}const kt={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function At({...e}){return h(D.Root,{"data-slot":`dialog`,...e})}function jt({...e}){return h(D.Trigger,{"data-slot":`dialog-trigger`,...e})}function Mt({...e}){return h(D.Portal,{"data-slot":`dialog-portal`,...e})}function Nt({...e}){return h(D.Close,{"data-slot":`dialog-close`,...e})}function Pt({className:t,...n}){return h(D.Overlay,{"data-slot":`dialog-overlay`,className:e(`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50`,t),...n})}function Ft({className:t,children:n,showCloseButton:r=!0,...i}){return g(Mt,{"data-slot":`dialog-portal`,children:[h(Pt,{}),g(D.Content,{"data-slot":`dialog-content`,className:e(`bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg`,t),...i,children:[n,r&&g(D.Close,{"data-slot":`dialog-close`,className:`ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[h(w,{}),h(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function It({className:t,...n}){return h(`div`,{"data-slot":`dialog-header`,className:e(`flex flex-col gap-2 text-center sm:text-left`,t),...n})}function Lt({className:t,showCloseButton:n=!1,children:r,...i}){return g(`div`,{"data-slot":`dialog-footer`,className:e(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,t),...i,children:[r,n&&h(D.Close,{asChild:!0,children:h(ze,{variant:`outline`,children:`Close`})})]})}function Rt({className:t,...n}){return h(D.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function zt({className:t,...n}){return h(D.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function Bt({className:t,...n}){return h(`kbd`,{"data-slot":`kbd`,className:e(`bg-muted text-muted-foreground pointer-events-none inline-grid w-fit min-w-5 place-items-center gap-1 rounded px-1.5 py-0.5 font-sans text-xs font-medium select-none leading-[1]`,`[&_svg:not([class*='size-'])]:size-3`,`[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10`,t),...n})}function Vt({className:t,...n}){return h(`kbd`,{"data-slot":`kbd-group`,className:e(`inline-flex items-center gap-1`,t),...n})}function Ht({className:t,...n}){return h(G,{"data-slot":`command`,className:e(`text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md`,t),...n})}function Ut({className:t,children:n,...r}){return h(Mt,{"data-slot":`dialog-portal`,children:h(D.Content,{"data-slot":`dialog-content`,className:e(`backdrop-blur-xl fixed top-1/3 left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] overflow-hidden rounded-xl border-none p-2 shadow-2xl ring-0 duration-200 outline-none sm:max-w-lg`,t),style:{backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`},...r,children:n})})}function Wt({className:t,...n}){return h(G.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function Y({className:t,ref:n,...r}){let a=i.useCallback(e=>{if(e){let t=e.querySelector(`[cmdk-group-heading]`);t instanceof HTMLElement&&(t.style.position=`sticky`,t.style.top=`0`,t.style.zIndex=`10`,t.style.width=`fit-content`,t.style.backdropFilter=`blur(24px)`,t.style.WebkitBackdropFilter=`blur(24px)`,t.style.backgroundColor=`color-mix(in oklch, var(--background) 95%, transparent)`,t.style.borderRadius=`6px`,t.style.setProperty(`padding-top`,`4px`,`important`),t.style.setProperty(`padding-bottom`,`4px`,`important`))}typeof n==`function`?n(e):n&&(n.current=e)},[n]);return h(G.Group,{ref:a,"data-slot":`command-group`,className:e(`text-foreground !p-0 [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:scroll-mt-16 [&_[cmdk-group-heading]]:pt-0! [&_[cmdk-group-heading]]:!p-3 [&_[cmdk-group-heading]]:!pb-1 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium`,t),...r})}function Gt({className:t,...n}){return h(G.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function Kt({className:t,style:n,...r}){return h(G.Item,{"data-slot":`command-item`,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 [&_svg:not([class*='text-'])]:text-muted-foreground relative flex h-[var(--cmdk-item-height,2.25rem)] cursor-default items-center gap-2 border border-transparent px-3 text-sm font-medium outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,t),style:{borderRadius:`var(--cmdk-radius, 0.375rem)`,...n},...r})}function qt({className:t,children:n,...r}){let i=typeof n==`string`?[...n]:null;return h(`span`,{"data-slot":`command-shortcut`,className:e(`ml-auto flex items-center gap-1`,t),...r,children:i?i.map((e,t)=>h(Bt,{children:e},t)):n})}function Jt(){return crypto.randomUUID()}function Yt(e){let t=e.find(e=>e.role===`user`);if(!t)return`New conversation`;let n=t.parts?.filter(e=>e.type===`text`).map(e=>e.text).join(` `)||`New conversation`;return n.length>50?n.slice(0,50)+`...`:n}function Xt(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function Zt({storageKey:e=`cmdk-chat-history`,maxConversations:t=50,messages:n,setMessages:r}){let[i,a]=f([]),[o,c]=f(null),[p,m]=f(!1),h=d(n);h.current=n;let g=d(r);g.current=r;let _=d(i);_.current=i;let v=d(o);v.current=o,l(()=>{try{let t=localStorage.getItem(e);if(t){let n=Xt(JSON.parse(t));n?a(n.conversations):(console.warn(`Chat history: stored data failed validation. Discarding.`),localStorage.removeItem(e))}}catch(e){console.error(`Failed to load chat history:`,e)}finally{m(!0)}},[e]),l(()=>{if(p)try{let t={version:1,conversations:i};localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(`Failed to save chat history:`,e)}},[i,e,p]);let y=s(()=>{let e=h.current,n=v.current;!n||e.length===0||a(r=>{let i=Date.now();return r.find(e=>e.id===n)?r.map(t=>t.id===n?{...t,messages:e,title:Yt(e),updatedAt:i}:t):[{id:n,title:Yt(e),messages:e,createdAt:i,updatedAt:i},...r].slice(0,t)})},[t]),b=s(()=>{v.current&&h.current.length>0&&y(),g.current?.([]),c(Jt())},[y]),x=s(e=>{v.current&&h.current.length>0&&y();let t=_.current.find(t=>t.id===e);t&&(g.current?.(t.messages),c(e))},[y]);return u(()=>({conversations:i,currentConversationId:o,startNewChat:b,loadConversation:x,saveCurrentConversation:y}),[i,o,b,x,y])}let X=null,Z=null;function Qt(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function $t(e,t){return delete e.user,delete e.server_name,e.request&&(delete e.request.cookies,delete e.request.headers,delete e.request.env,delete e.request.data),e.breadcrumbs=[],e}function en(){typeof window>`u`||X===null&&(Qt()||(X=new I({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:ne,stackParser:ee,integrations:[R(),te()],beforeSend:$t,sendDefaultPii:!1,tracesSampleRate:1}),Z=new L,Z.setClient(X),X.init()))}function tn(e,t){!Z||!X||(t?Z.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):Z.captureException(e))}function nn(e){try{let t=new Uint8Array(e/2);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}catch{let t=``;for(let n=0;n<e;n++)t+=Math.floor(Math.random()*16).toString(16);return t}}function rn(e,t,n){if(!Z||!X)return n();let r=Date.now()/1e3,i=nn(32),a=nn(16),o=`ok`,s=()=>{let n=Date.now()/1e3;Z.captureEvent({type:`transaction`,transaction:e,start_timestamp:r,timestamp:n,contexts:{trace:{trace_id:i,span_id:a,op:t,status:o}}})};try{let e=n();return e instanceof Promise?e.then(e=>(s(),e),e=>{throw o=`internal_error`,s(),e}):(s(),e)}catch(e){throw o=`internal_error`,s(),e}}const an=i.createContext(null),on=[];function sn({children:e,chatEndpoint:t=null,chat:n,onModeChange:r,onOpenChange:a,historyStorageKey:o,maxConversations:s}){let[c,l]=i.useState(`command`),[u,d]=i.useState(``),[f,p]=i.useState(`idle`),[m,g]=i.useState(null),_=i.useRef(n);_.current=n;let v=!!n;i.useEffect(()=>{en()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new F({api:t})},[t,v]),b=P(i.useMemo(()=>y?{transport:y,onError:e=>{tn(e,{source:`internalChat.onError`}),p(`error`),g(e)}}:{},[y])),x=n?.status,S=n?.error??null;i.useEffect(()=>{if(v)x===`ready`?p(`idle`):x===`streaming`?p(`streaming`):x===`submitted`?p(`submitted`):x===`error`&&p(`error`),g(S);else{let e=b.status;e===`streaming`?p(`streaming`):e===`submitted`?p(`submitted`):e===`error`?p(`error`):e===`ready`&&p(`idle`)}},[x,S,b.status,v]);let C=i.useCallback(e=>{l(e),r?.(e)},[r]),w=!!(n||t),T=i.useCallback(e=>{w&&rn(`switchToChat`,`ui.action`,()=>{C(`chat`),e&&d(e)})},[w,C]),E=i.useCallback(()=>{C(`command`),d(``),p(`idle`),g(null)},[C]),D=i.useCallback(async e=>{e.trim()&&await rn(`sendMessage`,`function`,async()=>{try{let t=_.current;if(t){d(``),t.sendMessage({text:e.trim()});return}if(!y)return;p(`submitted`),d(``),await b.sendMessage({text:e.trim()})}catch(e){throw tn(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??on,A=n?.setMessages??b.setMessages,j=n?.addToolApprovalResponse,M=n?.agenticActions,N=Zt({storageKey:o,maxConversations:s,messages:k,setMessages:A}),I=i.useCallback(e=>{N.loadConversation(e),C(`chat`)},[N.loadConversation,C]),L=i.useRef(f);i.useEffect(()=>{let e=L.current;L.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&N.saveCurrentConversation()},[f,k.length,N.saveCurrentConversation]);let R=i.useCallback(()=>{a?.(!1)},[a]),ee=i.useMemo(()=>({mode:c,setMode:C,inputValue:u,setInputValue:d,chatEndpoint:t,status:f,error:m,switchToChat:T,switchToCommand:E,messages:k,sendMessage:D,isLoading:O,isEnabled:w,addToolApprovalResponse:j,agenticActions:M,requestClose:R,conversations:N.conversations,currentConversationId:N.currentConversationId,startNewChat:N.startNewChat,loadConversation:I}),[c,C,u,t,f,m,T,E,k,D,O,w,j,M,R,N.conversations,N.currentConversationId,N.startNewChat,I]);return h(an.Provider,{value:ee,children:e})}function Q(){let e=i.useContext(an);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}var cn=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){tn(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};function ln(e){return e instanceof Element?!!e.closest(`input, textarea, select, button, a, [contenteditable='true'], [contenteditable=''], [data-cmdk-mobile-gesture-ignore]`):!1}function un({enabled:e,open:t,holdMs:n,swipeUpPx:r,onTrigger:a,movementTolerancePx:o=10,horizontalCancelPx:s=24,activationZoneWidthPercent:c=.6,activationZoneHeightPercent:l=.35,bottomExclusionPx:u=24}){let[d,f]=i.useState(!1),p=i.useRef(null),m=i.useCallback(()=>{let e=p.current;e?.timer!=null&&window.clearTimeout(e.timer),p.current=null,f(!1)},[]);return i.useEffect(()=>{if(!e||t||typeof window>`u`){m();return}let i=e=>{if(e.touches.length!==1||ln(e.target))return;let t=e.touches[0];if(!t)return;let r=window.innerWidth,i=window.innerHeight,a=r*c,o=(r-a)/2,s=o+a,d=i*(1-l),m=i-u;if(t.clientX<o||t.clientX>s||t.clientY<d||t.clientY>m)return;let h=window.setTimeout(()=>{let e=p.current;e&&(e.armed=!0,f(!0),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(6))},n);p.current={startX:t.clientX,startY:t.clientY,armed:!1,timer:h}},d=e=>{if(e.touches.length!==1){m();return}let t=p.current;if(!t)return;let n=e.touches[0];if(!n)return;let i=n.clientX-t.startX,c=n.clientY-t.startY;if(!t.armed){Math.hypot(i,c)>o&&m();return}if(Math.abs(i)>s){m();return}c<=-r&&(m(),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(14),a())},h=()=>{m()},g=()=>{m()};return document.addEventListener(`touchstart`,i,{passive:!0}),document.addEventListener(`touchmove`,d,{passive:!0}),document.addEventListener(`touchend`,h,{passive:!0}),document.addEventListener(`touchcancel`,g,{passive:!0}),()=>{document.removeEventListener(`touchstart`,i),document.removeEventListener(`touchmove`,d),document.removeEventListener(`touchend`,h),document.removeEventListener(`touchcancel`,g),m()}},[e,t,n,r,a,o,s,c,l,u,m]),{showHint:d}}function dn(e){let[t,n]=i.useState(0);return i.useEffect(()=>{if(!e||typeof window>`u`){n(0);return}let t=window.visualViewport;if(!t){n(0);return}let r=()=>{let e=Math.max(0,Math.round(window.innerHeight-t.height-t.offsetTop));n(t=>t===e?t:e)};return r(),t.addEventListener(`resize`,r),t.addEventListener(`scroll`,r),window.addEventListener(`orientationchange`,r),()=>{t.removeEventListener(`resize`,r),t.removeEventListener(`scroll`,r),window.removeEventListener(`orientationchange`,r)}},[e]),t}const fn=e=>{},pn={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},mn={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},hn=i.createContext({isMobile:!1,layout:`keyboard-last`,keyboardInset:0,showQuickActions:!1,quickActionsCount:4});function gn(){return i.useContext(hn)}function _n(e){let t=e?.gesture!==!1;return{enabled:e?.enabled??!0,breakpoint:e?.breakpoint??900,layout:e?.layout??`keyboard-last`,gesture:{enabled:t?e?.gesture?.enabled??!0:!1,holdMs:t?e?.gesture?.holdMs??350:350,swipeUpPx:t?e?.gesture?.swipeUpPx??56:56},showQuickActions:e?.showQuickActions??!0,quickActionsCount:e?.quickActionsCount??4}}function vn(e,t){let[n,r]=i.useState(!1);return i.useEffect(()=>{if(!t||typeof window>`u`){r(!1);return}let n=window.matchMedia(`(max-width: ${e}px)`),i=window.matchMedia(`(pointer: coarse)`),a=()=>{r(n.matches||i.matches)};return a(),n.addEventListener(`change`,a),i.addEventListener(`change`,a),window.addEventListener(`orientationchange`,a),()=>{n.removeEventListener(`change`,a),i.removeEventListener(`change`,a),window.removeEventListener(`orientationchange`,a)}},[e,t]),n}function yn(e){let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function bn({className:t,children:n,corners:r=`xl`,borderColor:a,isMobile:o,keyboardInset:s,onRequestClose:c,...l}){let u=i.useRef(null),d=i.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(e instanceof HTMLElement&&e.hasAttribute(`cmdk-input`)){e.blur();return}c?.()},[c]),f=e=>{if(e.touches.length!==1)return;let t=e.touches[0];t&&(u.current={x:t.clientX,y:t.clientY})},p=e=>{let t=u.current;if(u.current=null,!t||e.changedTouches.length===0)return;let n=e.changedTouches[0];if(!n)return;let r=n.clientX-t.x;n.clientY-t.y>56&&Math.abs(r)<42&&d()};return g(Mt,{"data-slot":`dialog-portal`,children:[o&&h(D.Overlay,{className:`fixed inset-0 z-40 bg-black/35 backdrop-blur-[1px]`}),g(`div`,{className:e(`fixed z-50 w-full max-w-[calc(100%-2rem)]`,o?`inset-x-0 bottom-0 max-w-none px-0`:`top-1/3 left-[50%] translate-x-[-50%] translate-y-[-50%]`),style:o?void 0:{maxWidth:`45vw`},children:[g(D.Content,{"data-slot":`dialog-content`,className:e(`backdrop-blur-xl flex flex-col w-full overflow-hidden border border-input p-0 ring-0 outline-none`,o?`rounded-none rounded-t-2xl border-x-0 border-b-0`:pn[r],t),style:{"--cmdk-radius":mn[r],"--cmdk-mobile-keyboard-inset":`${s??0}px`,maxHeight:o?`95vh`:`45vh`,height:o?`min(95vh, calc(100dvh - 0.5rem))`:void 0,backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`,boxShadow:`4px 4px 12px -2px rgba(0,0,0,0.12), -4px 4px 12px -2px rgba(0,0,0,0.12), 0 8px 16px -4px rgba(0,0,0,0.1)`,...a?{"--tw-ring-color":a}:{}},...l,children:[o&&h(`div`,{className:`flex justify-center py-2`,"data-cmdk-mobile-gesture-ignore":!0,onTouchStart:f,onTouchEnd:p,children:h(`div`,{className:`h-1.5 w-11 rounded-full bg-muted-foreground/35`})}),n]}),h(`div`,{className:e(`flex justify-end select-none`,o&&`hidden`),children:h(`a`,{href:`https://better-cmdk.com`,target:`_blank`,rel:`noopener noreferrer`,className:`text-xs text-muted-foreground font-medium px-2 py-0.5 hover:text-foreground transition-colors`,style:{borderRadius:`0 0 0.375rem 0.375rem`,marginRight:`1rem`,backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,borderLeft:`1px solid var(--color-input)`,borderRight:`1px solid var(--color-input)`,borderBottom:`1px solid var(--color-input)`,boxShadow:`4px 4px 12px -2px rgba(0,0,0,0.12), -4px 4px 12px -2px rgba(0,0,0,0.12), 0 8px 16px -4px rgba(0,0,0,0.1)`},children:`powered by better-cmdk`})})]})]})}const xn=g(m,{children:[h(wn,{placeholder:`Search for commands or ask AI...`,showSendButton:!0}),h(Dn,{children:h($,{})})]});function Sn({title:t=`Command Palette`,description:n=`Search for a command to run...`,children:r,className:a,corners:o=`xl`,borderColor:s,commands:c,commandsPlaceholder:l=`Search for commands or ask AI...`,commandsAskAILabel:u=`Ask AI`,mobile:d,...f}){let{mode:p,status:_,switchToCommand:y,messages:b,isEnabled:x,setInputValue:S,inputValue:C}=Q(),w=i.useMemo(()=>_n(d),[d]),T=vn(w.breakpoint,w.enabled),E=w.enabled&&T,D=dn(E&&!!f.open),O=i.useCallback(e=>{e&&S(``),f.onOpenChange?.(e)},[f.onOpenChange,S]),k=un({enabled:E&&!f.open&&!!f.onOpenChange&&w.gesture.enabled,open:!!f.open,holdMs:w.gesture.holdMs,swipeUpPx:w.gesture.swipeUpPx,onTrigger:()=>O(!0)}),A=i.useMemo(()=>({isMobile:E,layout:w.layout,keyboardInset:D,showQuickActions:w.showQuickActions,quickActionsCount:w.quickActionsCount}),[E,w.layout,D,w.showQuickActions,w.quickActionsCount]),j=()=>c&&c.length>0?h(En,{commands:c,placeholder:l,askAILabel:u}):typeof r==`function`?r({mode:p,messages:b,status:_,isEnabled:x}):r??xn,M=e=>{p===`chat`&&(e.preventDefault(),y())};return i.useEffect(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),O(!1))};if(f.open)return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[f.open,O]),g(m,{children:[h(At,{...f,onOpenChange:O,children:g(bn,{className:a,corners:o,borderColor:s,isMobile:E,keyboardInset:D,onRequestClose:()=>O(!1),onEscapeKeyDown:M,onOpenAutoFocus:e=>{E&&w.layout===`keyboard-last`&&e.preventDefault()},children:[g(It,{className:`sr-only`,children:[h(Rt,{children:t}),h(zt,{children:n})]}),h(hn.Provider,{value:A,children:h(G,{"data-slot":`command`,className:e(`**:data-[slot=command-input-wrapper]:bg-transparent rounded-none bg-transparent **:data-[slot=command-input]:!h-11 **:data-[slot=command-input]:py-0 **:data-[slot=command-input-wrapper]:mb-0`,E?`**:data-[slot=command-input-wrapper]:!h-[var(--cmdk-input-row-height)] pb-[env(safe-area-inset-bottom)]`:`**:data-[slot=command-input-wrapper]:!h-11`,`text-popover-foreground flex h-full min-h-0 w-full flex-col overflow-hidden`),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`,"--cmdk-item-height":E?`3.125rem`:`2.25rem`,"--cmdk-input-row-height":E?`3.5rem`:`2.75rem`},children:j()})})]})}),k.showHint&&g(`div`,{className:`fixed left-1/2 z-50 flex -translate-x-1/2 items-center gap-2 rounded-full border border-input bg-background/95 px-3 py-1.5 text-xs font-medium text-foreground shadow-sm backdrop-blur-md`,style:{bottom:`calc(env(safe-area-inset-bottom) + 2rem)`},"data-cmdk-mobile-gesture-ignore":!0,children:[h(v,{className:`size-3.5`}),`Swipe up for Command Menu`]})]})}function Cn({chatEndpoint:e=null,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,mobile:l,...u}){return h(sn,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(cn,{children:h(Sn,{onOpenChange:r,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,mobile:l,...u})})})}function wn({className:t,showSendButton:n=!1,...r}){let{mode:a,inputValue:o,setInputValue:s,sendMessage:c,isLoading:l,switchToChat:u,startNewChat:d}=Q(),{isMobile:f,layout:p,keyboardInset:m}=gn(),[_,y]=i.useState(!1),x=i.useRef(null),S=()=>{o.trim()&&a===`chat`&&c(o)},C=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`Enter`){e.preventDefault(),a===`command`&&o.trim()?(d(),u(),c(o)):a===`chat`&&o.trim()&&c(o);return}if(a===`chat`&&e.key===`Enter`&&!e.shiftKey){e.preventDefault(),o.trim()&&c(o);return}},w=a===`chat`||o.length>0||f&&p===`keyboard-last`,T=f&&p===`keyboard-last`&&!_&&a===`command`,E=e=>{y(!0),r.onFocus?.(e)},D=e=>{y(!1),r.onBlur?.(e)},O=f?{marginBottom:m>0?`${m}px`:void 0}:void 0,k={...r,onFocus:E,onBlur:D};return g(`div`,{"data-slot":`command-input-wrapper`,className:e(`order-2 flex h-[var(--cmdk-input-row-height,2.75rem)] items-center gap-2 px-6 transition-[margin,border-color] duration-200`,f&&`px-4`,w?`border-t border-input mt-0`:`border-t border-transparent mt-0`),style:O,children:[h(G.Input,{"data-slot":`command-input`,ref:x,value:o,onValueChange:s,onKeyDown:C,className:e(`placeholder:text-muted-foreground flex h-10 w-full bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50`,t),...k,placeholder:a===`chat`?`Ask AI...`:r.placeholder}),T&&h(`button`,{type:`button`,onClick:()=>x.current?.focus(),className:`flex items-center justify-center size-7 shrink-0 border border-input bg-background text-muted-foreground hover:text-foreground transition-colors`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},"aria-label":`Type a command`,"data-cmdk-mobile-gesture-ignore":!0,children:h(b,{className:`size-4`})}),n&&a===`chat`&&h(`button`,{type:`button`,onClick:S,disabled:!o.trim()||l,className:`flex items-center justify-center size-6 shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},children:h(v,{className:`size-3`})})]})}function $({label:t=`Ask AI`,className:n,...r}){let{inputValue:i,setInputValue:a,switchToChat:o,sendMessage:s,isEnabled:c,startNewChat:l}=Q(),{isMobile:u}=gn(),d=J(e=>e.filtered.count),f=()=>{if(c)if(i.trim()){let e=ct(`ask-ai`,i.trim())>0;d===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(G.Group,{forceMount:!0,children:g(G.Item,{"data-slot":`command-item`,value:`ask-ai`,onSelect:f,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 relative flex cursor-default items-center gap-3 border border-transparent px-3 py-2 text-sm outline-hidden select-none`,u&&`min-h-12 py-3`,n),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},...r,children:[h(S,{className:`size-4 shrink-0 text-primary`}),h(`div`,{className:`flex flex-col items-start gap-0.5`,children:h(`span`,{className:`font-medium`,children:t})}),!u&&g(`span`,{className:`ml-auto flex items-center gap-1`,children:[h(Bt,{children:`⌘`}),h(Bt,{children:`↵`})]})]})}):h(G.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function Tn(e){let t=[],n=new Map;for(let r of e){let e=r.group,i=n.get(e);i===void 0?(n.set(e,t.length),t.push({heading:e,items:[r]})):t[i].items.push(r)}let r=t.findIndex(e=>e.heading===void 0);if(r>0){let e=t.splice(r,1)[0];t.unshift(e)}return t}function En({commands:t,placeholder:n,askAILabel:r}){let{inputValue:a,mode:o}=Q(),{isMobile:s,layout:c,showQuickActions:l,quickActionsCount:u}=gn(),d=Tn(t),f=s&&c===`keyboard-last`&&l&&o===`command`&&a.length===0,p=f?t.filter(e=>!e.disabled).slice(0,u):[],_=new Set(p.map(e=>e.name)),v=t=>{let n=t.label??t.name,r=[...t.keywords??[]];return t.label&&t.label!==t.name&&r.push(t.label),g(Kt,{value:t.name,keywords:r.length>0?r:void 0,disabled:t.disabled,onSelect:()=>t.onSelect?.(),className:e(s&&`min-h-12 py-3`),children:[t.icon,n,t.shortcut&&!s&&h(qt,{children:t.shortcut})]},t.name)};return g(m,{children:[h(wn,{placeholder:n,showSendButton:!0}),g(Dn,{children:[f&&p.length>0&&h(Y,{heading:`Quick Actions`,children:p.map(e=>v(e))}),d.map((e,t)=>{let n=f?e.items.filter(e=>!_.has(e.name)):e.items;if(n.length===0)return null;let r=n.map(e=>v(e));return e.heading?h(Y,{heading:e.heading,children:r},e.heading):h(i.Fragment,{children:r},`__ungrouped_${t}`)}),h($,{label:r})]})]})}function Dn({className:t,children:n,actions:r,actionsHeading:a=`Actions`,style:o,...s}){let{mode:c,status:l,messages:u,sendMessage:d,addToolApprovalResponse:f,agenticActions:p,switchToChat:m,startNewChat:_,conversations:v,loadConversation:y,inputValue:b}=Q(),{isMobile:x,layout:C,keyboardInset:w}=gn(),T=i.useCallback(e=>d(e.text),[d]),E=f??fn;if(c===`chat`)return h(`div`,{"data-slot":`command-list`,className:e(`order-1 min-h-0 flex-1 overflow-hidden px-3 flex flex-col`,x&&`px-2`,t),children:u.length===0?h(He,{}):g(Be,{style:{flex:`1 1 0%`,minHeight:0},children:[h(`div`,{className:`px-3 py-2 space-y-4`,children:h(Fe,{messages:u,sendMessage:T,addToolApprovalResponse:E})}),l===`streaming`&&h(Ve,{})]})});let D=i.Children.toArray(n),O=[],k=[];D.forEach(e=>{i.isValidElement(e)&&(e.type===$||e.type.displayName===`CommandEmpty`)?O.push(e):i.isValidElement(e)&&e.type===Wt||k.push(e)});let A=(r??p)?.filter(e=>e.execute),j=e=>{let t=e.label??e.name;_(),m(),d(t)},M=b.length>0||x&&C===`keyboard-last`,P=x?`calc(100% - var(--cmdk-input-row-height, 3.5rem))`:`calc(45vh - 2.75rem)`,F={overscrollBehavior:`contain`,paddingBottom:w>0?`${w+8}px`:x?`env(safe-area-inset-bottom)`:void 0,...o};return h(N.div,{initial:!1,animate:{height:M?P:0},transition:{type:`spring`,duration:.25,bounce:0},className:e(`order-1 min-h-0 overflow-hidden px-3`,x&&`px-2`),children:g(G.List,{"data-slot":`command-list`,className:e(`overflow-x-hidden overflow-y-auto overscroll-contain pt-2 h-full`,x&&`pt-1`,t),style:F,...s,children:[k,v.length>0&&h(Y,{heading:`Recent Chats`,children:v.slice(0,5).map(t=>g(Kt,{value:`chat-history-${t.id}`,keywords:[t.title],onSelect:()=>y(t.id),className:e(x&&`min-h-12 py-3`),children:[h(S,{className:`size-4`}),h(`span`,{className:`truncate`,children:t.title}),h(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:yn(t.updatedAt)})]},t.id))}),A&&A.length>0&&h(Y,{heading:a,children:A.map(t=>h(Kt,{value:t.label??t.name,onSelect:()=>j(t),className:e(x&&`min-h-12 py-3`),children:t.label??t.name},t.name))}),O]})})}$.displayName=`CommandEmpty`;export{_e as AssistantFormRenderer,Fe as AssistantMessages,ze as Button,He as ChatEmpty,Ve as ChatLoading,Be as ChatMessageList,xe as Collapsible,Ce as CollapsibleContent,Se as CollapsibleTrigger,Ht as Command,bn as CommandContent,Cn as CommandDialog,Cn as CommandMenu,Ut as CommandDialogContent,$ as CommandEmpty,Y as CommandGroup,wn as CommandInput,Kt as CommandItem,Dn as CommandList,an as CommandMenuContext,sn as CommandMenuProvider,Gt as CommandSeparator,qt as CommandShortcut,re as Confirmation,oe as ConfirmationAccepted,le as ConfirmationAction,ce as ConfirmationActions,se as ConfirmationRejected,ae as ConfirmationRequest,ie as ConfirmationTitle,At as Dialog,Nt as DialogClose,Ft as DialogContent,zt as DialogDescription,Lt as DialogFooter,It as DialogHeader,Pt as DialogOverlay,Mt as DialogPortal,Rt as DialogTitle,jt as DialogTrigger,Bt as Kbd,Vt as KbdGroup,ve as Message,ye as MessageContent,be as MessageResponse,Ee as Task,Oe as TaskContent,Te as TaskItem,we as TaskItemFile,De as TaskTrigger,Re as buttonVariants,e as cn,me as defaultFormRegistry,Zt as useChatHistory,Q as useCommandMenuContext};
|