better-cmdk 0.0.4 → 0.0.6
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 +4 -0
- package/dist/index.d.ts +165 -8
- 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
|
@@ -192,6 +192,10 @@ Enable the built-in AI chat by providing either a `chatEndpoint` or an external
|
|
|
192
192
|
|
|
193
193
|
Users can switch to chat mode via `⌘ Enter` or by selecting the "Ask AI" item.
|
|
194
194
|
|
|
195
|
+
### AI Actions
|
|
196
|
+
|
|
197
|
+
When you connect an external chat provider like [modifywithai](https://modifywithai.com), the AI agent can invoke actions on behalf of the user — with approval gates so users stay in control. You define actions through your provider's SDK and pass them via the `chat` prop. See the [modifywithai docs](https://modifywithai.com/docs/concepts/actions) for setup.
|
|
198
|
+
|
|
195
199
|
## Advanced: Custom Children
|
|
196
200
|
|
|
197
201
|
For full control over the command list rendering, you can pass children instead of `commands`. This approach is compatible with shadcn/ui patterns if you're migrating from an existing setup.
|
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,
|
|
@@ -295,10 +450,12 @@ declare function CommandContent({
|
|
|
295
450
|
children,
|
|
296
451
|
corners,
|
|
297
452
|
borderColor,
|
|
453
|
+
expanded,
|
|
298
454
|
...props
|
|
299
455
|
}: React$2.ComponentProps<typeof Dialog$1.Content> & {
|
|
300
456
|
corners?: CommandMenuCorners;
|
|
301
457
|
borderColor?: string;
|
|
458
|
+
expanded?: boolean;
|
|
302
459
|
}): react_jsx_runtime0.JSX.Element;
|
|
303
460
|
declare function CommandMenu({
|
|
304
461
|
chatEndpoint,
|
|
@@ -312,7 +469,7 @@ declare function CommandMenu({
|
|
|
312
469
|
commandsAskAILabel,
|
|
313
470
|
...props
|
|
314
471
|
}: CommandMenuProps): react_jsx_runtime0.JSX.Element;
|
|
315
|
-
interface CommandInputProps extends Omit<React$2.ComponentProps<typeof
|
|
472
|
+
interface CommandInputProps extends Omit<React$2.ComponentProps<typeof pkg.Input>, "value" | "onValueChange"> {
|
|
316
473
|
showSendButton?: boolean;
|
|
317
474
|
}
|
|
318
475
|
declare function CommandInput({
|
|
@@ -320,7 +477,7 @@ declare function CommandInput({
|
|
|
320
477
|
showSendButton,
|
|
321
478
|
...props
|
|
322
479
|
}: CommandInputProps): react_jsx_runtime0.JSX.Element;
|
|
323
|
-
interface CommandEmptyProps extends React$2.ComponentProps<typeof
|
|
480
|
+
interface CommandEmptyProps extends React$2.ComponentProps<typeof pkg.Item> {
|
|
324
481
|
label?: string;
|
|
325
482
|
description?: string;
|
|
326
483
|
}
|
|
@@ -373,7 +530,7 @@ interface CommandDefinition {
|
|
|
373
530
|
/** Called when the command is selected */
|
|
374
531
|
onSelect?: () => void;
|
|
375
532
|
}
|
|
376
|
-
interface CommandListProps extends React$2.ComponentProps<typeof
|
|
533
|
+
interface CommandListProps extends React$2.ComponentProps<typeof pkg.List> {
|
|
377
534
|
/** Actions to render as CommandItems. Compatible with ActionDefinition[]. */
|
|
378
535
|
actions?: CommandAction[];
|
|
379
536
|
/** Heading for the auto-rendered actions group */
|
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,LoaderIcon as b,MessageCircleIcon as x,SearchIcon as S,XIcon as C}from"lucide-react";import*as w from"@radix-ui/react-collapsible";import{cva as T}from"class-variance-authority";import{Dialog as E,Slot as D}from"radix-ui";import*as O from"@radix-ui/react-dialog";import{Primitive as k}from"@radix-ui/react-primitive";import{useId as A}from"@radix-ui/react-id";import{composeRefs as j}from"@radix-ui/react-compose-refs";import{motion as M}from"motion/react";import{useChat as ee}from"@ai-sdk/react";import{DefaultChatTransport as te}from"ai";import{BrowserClient as N,Scope as P,dedupeIntegration as F,defaultStackParser as I,linkedErrorsIntegration as ne,makeFetchTransport as re}from"@sentry/browser";const ie=a(null);function L(){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}=L();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function ce({children:e}){let{approval:t,state:n}=L();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}=L();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}=L();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-actions`,className:`flex items-center justify-end gap-2 self-end`,...e}):null}function de({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 fe({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 pe({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 me({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 he({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 ge={Form:fe,TextField:pe,TextArea:me,DateField:he},_e=p.object({formId:p.string(),data:p.record(p.string(),p.string())}),ve=p.object({formId:p.string()});function ye({ui:e,context:r,onSubmit:i,onCancel:a,registry:o=ge}){let c=s(e=>{let t=_e.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=ve.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 be({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 xe({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 Se=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 Ce({...e}){return h(w.Root,{"data-slot":`collapsible`,...e})}function we({...e}){return h(w.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function Te({...e}){return h(w.CollapsibleContent,{"data-slot":`collapsible-content`,...e})}function Ee({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 De({children:e,...t}){return h(`div`,{"data-slot":`task-item`,className:`text-sm text-muted-foreground`,...t,children:e})}function Oe({defaultOpen:e=!0,...t}){return h(Ce,{"data-slot":`task`,defaultOpen:e,...t})}function ke({children:e,title:t,icon:n,...r}){return h(we,{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(y,{className:`size-4 transition-transform group-data-[state=open]:rotate-180`})]})})}function Ae({children:t,...n}){return h(Te,{"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 je=p.object({name:p.string(),options:p.record(p.string(),p.unknown()).optional()}),Me=p.object({actions:p.array(je).optional()}),Ne=p.object({id:p.string(),approved:p.boolean().optional()}),Pe=p.object({type:p.string(),props:p.record(p.string(),p.unknown()).default({}),children:p.array(p.string()).optional(),parentKey:p.string().nullable().optional()}),Fe=p.object({ui:p.object({elements:p.record(p.string(),Pe)}),context:p.record(p.string(),p.unknown()).optional()});function Ie(e){return e.name}function Le({messages:e,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r=Ie}){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(be,{from:e.role,children:h(xe,{children:e.parts.map((i,a)=>h(Re,{part:i,messageId:e.id,partIndex:a,isLastMessage:o,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r},`${e.id}-${a}`))})},e.id)})})}function Re({part:e,messageId:t,partIndex:n,isLastMessage:r,sendMessage:i,addToolApprovalResponse:a,getActionDescription:o}){if(e.type===`text`)return h(Se,{children:e.text});if(e.type===`tool-performActions`){let r=`input`in e?e.input:void 0,i=Me.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=Ne.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(de,{variant:`outline`,onClick:()=>a({id:f.id,approved:!1}),children:`Deny`}),h(de,{onClick:()=>a({id:f.id,approved:!0}),children:`Approve`})]})]}):g(Oe,{defaultOpen:!1,children:[h(ke,{title:c===1?`Performing 1 action`:`Performing ${c} actions`}),h(Ae,{children:s.map((e,r)=>h(De,{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(ze,{output:e.output,sendMessage:i}):null}function ze({output:e,sendMessage:t}){let n=i.useMemo(()=>{let t=Fe.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(ye,{ui:n.ui,context:n.context,onSubmit:a,onCancel:o}):null}const Be=T(`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 Ve({className:t,variant:n=`default`,size:r=`default`,asChild:i=!1,...a}){return h(i?D.Root:`button`,{"data-slot":`button`,"data-variant":n,"data-size":r,className:e(Be({variant:n,size:r,className:t})),...a})}function He({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 Ue({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 We({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 Ge=1,Ke=.9,qe=.8,Je=.17,Ye=.1,Xe=.999,Ze=.9999,Qe=.99,$e=/[\\\/_+.#"@\[\(\{&]/,et=/[\\\/_+.#"@\[\(\{&]/g,tt=/[\s-]/,nt=/[\s-]/g;function rt(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Ge:Qe;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=rt(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Ge:$e.test(e.charAt(l-1))?(d*=qe,p=e.slice(i,l-1).match(et),p&&i>0&&(d*=Xe**+p.length)):tt.test(e.charAt(l-1))?(d*=Ke,m=e.slice(i,l-1).match(nt),m&&i>0&&(d*=Xe**+m.length)):(d*=Je,i>0&&(d*=Xe**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Ze)),(d<Ye&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=rt(e,t,n,r,l+1,a+2,o),f*Ye>d&&(d=f*Ye)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function it(e){return e.toLowerCase().replace(nt,` `)}function at(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,rt(e,t,it(e),it(t),0,0,{})}const z=`[cmdk-group=""]`,ot=`[cmdk-group-items=""]`,st=`[cmdk-item=""]`,ct=`${st}:not([aria-disabled="true"])`,lt=`cmdk-item-select`,B=`data-value`,ut=(e,t,n)=>at(e,t,n),dt=i.createContext(void 0),V=()=>i.useContext(dt),ft=i.createContext(void 0),pt=()=>i.useContext(ft),mt=i.createContext(void 0),ht=i.forwardRef((e,t)=>{let n=W(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=W(()=>new Set),a=W(()=>new Map),o=W(()=>new Map),s=W(()=>new Set),c=Et(e),{label:l,children:u,value:d,onValueChange:f,filter:p,shouldFilter:m,loop:_,disablePointerSelection:v=!1,vimBindings:y=!0,...b}=e,x=A(),S=A(),C=A(),w=i.useRef(null),T=Ot();U(()=>{if(d!==void 0){let e=d.trim();n.current.value=e,E.emit()}},[d]),U(()=>{T(6,te)},[]);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`)ee(),j(),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=N()?.id,E.emit()}),r||T(5,te),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,()=>{j(),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,()=>{ee(),j(),n.current.value||M(),E.emit()}),()=>{o.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=N();T(4,()=>{ee(),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??ut;return e?r(e,n.current.search,t):0}function j(){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;P().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(ot);t?t.appendChild(e.parentElement===t?e:e.closest(`${ot} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${ot} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=w.current?.querySelector(`${z}[cmdk-group-id="${e[0]}"]`);t?.parentElement.appendChild(t)});let i=new Set(t.map(e=>e[0]));w.current?.querySelectorAll(`${z}[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=P().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(B);E.setState(`value`,e||void 0)}function ee(){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 te(){let e=N();e&&(e.parentElement?.firstChild===e&&e.closest(z)?.querySelector(`[cmdk-group-heading=""]`)?.scrollIntoView({block:`nearest`}),e.scrollIntoView({block:`nearest`}))}function N(){return w.current?.querySelector(`${st}[aria-selected="true"]`)}function P(){return Array.from(w.current?.querySelectorAll(ct)||[])}function F(e){let t=P()[e];t&&E.setState(`value`,t.getAttribute(B))}function I(e){let t=N(),n=P(),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(B))}function ne(e){let t=N()?.closest(z),n;for(;t&&!n;)t=e>0?wt(t,z):Tt(t,z),n=t?.querySelector(ct);n?E.setState(`value`,n.getAttribute(B)):I(e)}let re=()=>F(P().length-1),ie=e=>{e.preventDefault(),e.metaKey?re():e.altKey?ne(1):I(1)},L=e=>{e.preventDefault(),e.metaKey?F(0):e.altKey?ne(-1):I(-1)};return g(k.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&&ie(e);break;case`ArrowDown`:ie(e);break;case`p`:case`k`:y&&e.ctrlKey&&L(e);break;case`ArrowUp`:L(e);break;case`Home`:e.preventDefault(),F(0);break;case`End`:e.preventDefault(),re();break;case`Enter`:{e.preventDefault();let t=N();if(t){let e=new Event(lt);t.dispatchEvent(e)}}}},children:[h(`label`,{"cmdk-label":``,htmlFor:D.inputId,id:D.labelId,style:At,children:l}),K(e,e=>h(ft.Provider,{value:E,children:h(dt.Provider,{value:D,children:e})}))]})}),gt=i.forwardRef((e,t)=>{let n=A(),r=i.useRef(null),a=i.useContext(mt),o=V(),s=Et(e),c=s.current?.forceMount??a?.forceMount;U(()=>o.item(n,a?.id),[c]);let l=Dt(n,r,[e.value,e.children,r],e.keywords),u=pt(),d=G(e=>e.value&&e.value===l.current),f=G(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(lt,p),()=>t.removeEventListener(lt,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(k.div,{ref:j(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})}),_t=i.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:a,...o}=e,s=A(),c=i.useRef(null),l=i.useRef(null),u=A(),d=V(),f=G(e=>a||d.filter()===!1?!0:e.search?e.filtered.groups.has(s):!0);U(()=>d.group(s),[]),Dt(s,c,[e.value,e.heading,l]);let p=i.useMemo(()=>({id:s,forceMount:a}),[a]);return g(k.div,{ref:j(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}),K(e,e=>h(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?u:void 0,children:h(mt.Provider,{value:p,children:e})}))]})}),vt=i.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,a=i.useRef(null),o=G(e=>!e.search);return!n&&!o?null:h(k.div,{ref:j(a,t),...r,"cmdk-separator":``,role:`separator`})}),yt=i.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,a=e.value!=null,o=pt(),s=G(e=>e.search),c=G(e=>e.selectedItemId),l=V();return i.useEffect(()=>{e.value!=null&&o.setState(`search`,e.value)},[e.value]),h(k.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)}})}),bt=i.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...a}=e,o=i.useRef(null),s=i.useRef(null),c=G(e=>e.selectedItemId),l=V();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(k.div,{ref:j(o,t),...a,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":c,"aria-label":r,id:l.listId,children:K(e,e=>h(`div`,{ref:j(s,l.listInnerRef),"cmdk-list-sizer":``,children:e}))})}),xt=i.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return h(O.Root,{open:n,onOpenChange:r,children:g(O.Portal,{container:o,children:[h(O.Overlay,{"cmdk-overlay":``,className:i}),h(O.Content,{"aria-label":e.label,"cmdk-dialog":``,className:a,children:h(ht,{ref:t,...s})})]})})}),St=i.forwardRef((e,t)=>G(e=>e.filtered.count===0)?h(k.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),Ct=i.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return h(k.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,children:K(e,e=>h(`div`,{"aria-hidden":!0,children:e}))})}),H=Object.assign(ht,{List:bt,Item:gt,Input:yt,Group:_t,Separator:vt,Dialog:xt,Empty:St,Loading:Ct});function wt(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Tt(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Et(e){let t=i.useRef(e);return U(()=>{t.current=e}),t}const U=typeof window>`u`?i.useEffect:i.useLayoutEffect;function W(e){let t=i.useRef();return t.current===void 0&&(t.current=e()),t}function G(e){let t=pt(),n=()=>e(t.snapshot());return i.useSyncExternalStore(t.subscribe,n,n)}function Dt(e,t,n,r=[]){let a=i.useRef(),o=V();return U(()=>{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(B,i),a.current=i}),a}const Ot=()=>{let[e,t]=i.useState(),n=W(()=>new Map);return U(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function kt(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function K({asChild:e,children:t},n){return e&&i.isValidElement(t)?i.cloneElement(kt(t),{ref:t.ref},n(t.props.children)):n(t)}const At={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function jt({...e}){return h(E.Root,{"data-slot":`dialog`,...e})}function Mt({...e}){return h(E.Trigger,{"data-slot":`dialog-trigger`,...e})}function Nt({...e}){return h(E.Portal,{"data-slot":`dialog-portal`,...e})}function Pt({...e}){return h(E.Close,{"data-slot":`dialog-close`,...e})}function Ft({className:t,...n}){return h(E.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 It({className:t,children:n,showCloseButton:r=!0,...i}){return g(Nt,{"data-slot":`dialog-portal`,children:[h(Ft,{}),g(E.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(E.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(C,{}),h(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Lt({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 Rt({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(E.Close,{asChild:!0,children:h(Ve,{variant:`outline`,children:`Close`})})]})}function zt({className:t,...n}){return h(E.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function Bt({className:t,...n}){return h(E.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function q({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(H,{"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(Nt,{"data-slot":`dialog-portal`,children:h(E.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(H.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function J({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(H.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(H.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function Y({className:t,style:n,...r}){return h(H.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 Kt({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(q,{children:e},t)):n})}function qt(){return crypto.randomUUID()}function Jt(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 Yt(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function Xt({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=Yt(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:Jt(e),updatedAt:i}:t):[{id:n,title:Jt(e),messages:e,createdAt:i,updatedAt:i},...r].slice(0,t)})},[t]),b=s(()=>{v.current&&h.current.length>0&&y(),g.current?.([]),c(qt())},[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 Zt(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function Qt(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 $t(){typeof window>`u`||X===null&&(Zt()||(X=new N({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:re,stackParser:I,integrations:[F(),ne()],beforeSend:Qt,sendDefaultPii:!1,tracesSampleRate:1}),Z=new P,Z.setClient(X),X.init()))}function en(e,t){!Z||!X||(t?Z.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):Z.captureException(e))}function tn(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 nn(e,t,n){if(!Z||!X)return n();let r=Date.now()/1e3,i=tn(32),a=tn(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 rn=i.createContext(null),an=[];function on({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(()=>{$t()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new te({api:t})},[t,v]),b=ee(i.useMemo(()=>y?{transport:y,onError:e=>{en(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&&nn(`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 nn(`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 en(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??an,A=n?.setMessages??b.setMessages,j=n?.addToolApprovalResponse,M=n?.agenticActions,N=Xt({storageKey:o,maxConversations:s,messages:k,setMessages:A}),P=i.useCallback(e=>{N.loadConversation(e),C(`chat`)},[N.loadConversation,C]),F=i.useRef(f);i.useEffect(()=>{let e=F.current;F.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&N.saveCurrentConversation()},[f,k.length,N.saveCurrentConversation]);let I=i.useCallback(()=>{a?.(!1)},[a]),ne=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:I,conversations:N.conversations,currentConversationId:N.currentConversationId,startNewChat:N.startNewChat,loadConversation:P}),[c,C,u,t,f,m,T,E,k,D,O,w,j,M,I,N.conversations,N.currentConversationId,N.startNewChat,P]);return h(rn.Provider,{value:ne,children:e})}function Q(){let e=i.useContext(rn);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}var sn=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){en(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};const cn=e=>{},ln={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},un={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`};function dn(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 fn({className:t,children:n,corners:r=`xl`,borderColor:i,expanded:a,...o}){return h(Nt,{"data-slot":`dialog-portal`,children:g(`div`,{className:`fixed top-1/3 left-[50%] z-50 w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%]`,style:{maxWidth:`45vw`},children:[h(E.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`,ln[r],t),style:{"--cmdk-radius":un[r],maxHeight:`45vh`,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)`,...i?{"--tw-ring-color":i}:{}},...o,children:n}),h(`div`,{className:`flex justify-end select-none`,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 pn=g(m,{children:[h(gn,{placeholder:`Search for commands or ask AI...`,showSendButton:!0}),h(yn,{children:h($,{})})]});function mn({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`,...d}){let{mode:f,status:p,switchToCommand:m,messages:_,isEnabled:v,sendMessage:y,addToolApprovalResponse:b,setInputValue:x,inputValue:S}=Q(),C=f===`chat`||S.length>0,w=i.useCallback(e=>{e&&x(``),d.onOpenChange?.(e)},[d.onOpenChange,x]),T=()=>c&&c.length>0?h(vn,{commands:c,placeholder:l,askAILabel:u}):typeof r==`function`?r({mode:f,messages:_,status:p,isEnabled:v}):r??pn,E=e=>{f===`chat`&&(e.preventDefault(),m())};return i.useEffect(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),w(!1))};if(d.open)return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[d.open,w]),h(jt,{...d,onOpenChange:w,children:g(fn,{className:a,corners:o,borderColor:s,expanded:C,onEscapeKeyDown:E,children:[g(Lt,{className:`sr-only`,children:[h(zt,{children:t}),h(Bt,{children:n})]}),h(H,{"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 **: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)`},children:T()})]})})}function hn({chatEndpoint:e=null,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,...l}){return h(on,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(sn,{children:h(mn,{onOpenChange:r,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,...l})})})}function gn({className:t,showSendButton:n=!1,...r}){let{mode:i,inputValue:a,setInputValue:o,sendMessage:s,isLoading:c,switchToChat:l,startNewChat:u}=Q(),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}},p=i===`chat`||a.length>0;return g(`div`,{"data-slot":`command-input-wrapper`,className:e(`order-2 flex h-11 items-center gap-2 px-6 transition-[margin,border-color] duration-200`,p?`border-t border-input mt-0`:`border-t border-transparent mt-0`),children:[h(H.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 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(),u=G(e=>e.filtered.count),d=()=>{if(c)if(i.trim()){let e=ut(`ask-ai`,i.trim())>0;u===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(H.Group,{forceMount:!0,children:g(H.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(x,{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(q,{children:`⌘`}),h(q,{children:`↵`})]})]})}):h(H.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function _n(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 vn({commands:e,placeholder:t,askAILabel:n}){let r=_n(e);return g(m,{children:[h(gn,{placeholder:t,showSendButton:!0}),g(yn,{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(Y,{value:e.name,keywords:n.length>0?n:void 0,disabled:e.disabled,onSelect:()=>e.onSelect?.(),children:[e.icon,t,e.shortcut&&h(Kt,{children:e.shortcut})]},e.name)});return e.heading?h(J,{heading:e.heading,children:n},e.heading):h(i.Fragment,{children:n},`__ungrouped_${t}`)}),h($,{label:n})]})]})}function yn({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,inputValue:b}=Q(),S=i.useCallback(e=>u(e.text),[u]),C=d??cn;if(s===`chat`)return h(`div`,{"data-slot":`command-list`,className:e(`order-1 min-h-0 flex-1 overflow-hidden px-3 flex flex-col`,t),children:l.length===0?h(We,{}):g(He,{style:{flex:`1 1 0%`,minHeight:0},children:[h(`div`,{className:`px-3 py-2 space-y-4`,children:h(Le,{messages:l,sendMessage:S,addToolApprovalResponse:C})}),c===`streaming`&&h(Ue,{})]})});let w=i.Children.toArray(n),T=[],E=[];w.forEach(e=>{i.isValidElement(e)&&(e.type===$||e.type.displayName===`CommandEmpty`)?T.push(e):i.isValidElement(e)&&e.type===Wt||E.push(e)});let D=(r??f)?.filter(e=>e.execute),O=e=>{let t=e.label??e.name;_(),m(),u(t)},k=b.length>0;return h(M.div,{initial:!1,animate:{height:k?`calc(45vh - 2.75rem)`:0},transition:{type:`spring`,duration:.25,bounce:0},className:`order-1 min-h-0 overflow-hidden px-3`,children:g(H.List,{"data-slot":`command-list`,className:e(`overflow-x-hidden overflow-y-auto overscroll-contain pt-2 h-full`,t),style:{overscrollBehavior:`contain`},...o,children:[E,v.length>0&&h(J,{heading:`Recent Chats`,children:v.slice(0,5).map(e=>g(Y,{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:dn(e.updatedAt)})]},e.id))}),D&&D.length>0&&h(J,{heading:a,children:D.map(e=>h(Y,{value:e.label??e.name,onSelect:()=>O(e),children:e.label??e.name},e.name))}),T]})})}$.displayName=`CommandEmpty`;export{ye as AssistantFormRenderer,Le as AssistantMessages,Ve as Button,We as ChatEmpty,Ue as ChatLoading,He as ChatMessageList,Ce as Collapsible,Te as CollapsibleContent,we as CollapsibleTrigger,Ht as Command,fn as CommandContent,hn as CommandDialog,hn as CommandMenu,Ut as CommandDialogContent,$ as CommandEmpty,J as CommandGroup,gn as CommandInput,Y as CommandItem,yn as CommandList,rn as CommandMenuContext,on as CommandMenuProvider,Gt as CommandSeparator,Kt as CommandShortcut,ae as Confirmation,ce as ConfirmationAccepted,de as ConfirmationAction,ue as ConfirmationActions,le as ConfirmationRejected,se as ConfirmationRequest,oe as ConfirmationTitle,jt as Dialog,Pt as DialogClose,It as DialogContent,Bt as DialogDescription,Rt as DialogFooter,Lt as DialogHeader,Ft as DialogOverlay,Nt as DialogPortal,zt as DialogTitle,Mt as DialogTrigger,q as Kbd,Vt as KbdGroup,be as Message,xe as MessageContent,Se as MessageResponse,Oe as Task,Ae as TaskContent,De as TaskItem,Ee as TaskItemFile,ke as TaskTrigger,Be as buttonVariants,e as cn,ge as defaultFormRegistry,Xt as useChatHistory,Q as useCommandMenuContext};
|