better-cmdk 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -167,6 +167,34 @@ Each command in the `commands` array supports:
167
167
  | `onModeChange` | `(mode: CommandMenuMode) => void` | — | Fires when switching between command/chat |
168
168
  | `historyStorageKey` | `string` | — | localStorage key for chat history |
169
169
  | `maxConversations` | `number` | — | Max saved chat conversations |
170
+ | `mobile` | `CommandMenuMobileOptions` | mobile defaults enabled | Mobile sheet/gesture behavior configuration |
171
+
172
+ ### Mobile Configuration
173
+
174
+ `CommandMenu` now includes a mobile-first sheet mode:
175
+
176
+ - Long-press (`~350ms`) in the lower-right viewport shows a hint: `Swipe up for Command Menu`
177
+ - Swipe up opens the menu
178
+ - Keyboard-last flow on mobile (sheet opens without forcing keyboard)
179
+ - Keyboard-aware input/list insets via `visualViewport`
180
+
181
+ ```tsx
182
+ <CommandMenu
183
+ open={open}
184
+ onOpenChange={setOpen}
185
+ commands={commands}
186
+ mobile={{
187
+ enabled: true,
188
+ layout: "keyboard-last",
189
+ gesture: {
190
+ holdMs: 350,
191
+ swipeUpPx: 56,
192
+ },
193
+ showQuickActions: true,
194
+ quickActionsCount: 4,
195
+ }}
196
+ />
197
+ ```
170
198
 
171
199
  ### AI Chat
172
200
 
package/dist/index.d.ts CHANGED
@@ -420,6 +420,29 @@ declare function useCommandMenuContext(): CommandMenuContextValue;
420
420
  //#endregion
421
421
  //#region components/ui/command-menu.d.ts
422
422
  type CommandMenuCorners = "none" | "sm" | "md" | "lg" | "xl";
423
+ type CommandMenuMobileLayout = "keyboard-last";
424
+ interface CommandMenuMobileGesture {
425
+ /** Enables/disables the long-press gesture trigger. */
426
+ enabled?: boolean;
427
+ /** Hold duration before showing the swipe-up hint. */
428
+ holdMs?: number;
429
+ /** Upward drag distance required to open the menu. */
430
+ swipeUpPx?: number;
431
+ }
432
+ interface CommandMenuMobileOptions {
433
+ /** Enable mobile command-sheet behavior. Defaults to true. */
434
+ enabled?: boolean;
435
+ /** Viewport width threshold used for mobile layout detection. */
436
+ breakpoint?: number;
437
+ /** Mobile interaction layout. */
438
+ layout?: CommandMenuMobileLayout;
439
+ /** Gesture trigger settings. Set false to fully disable. */
440
+ gesture?: CommandMenuMobileGesture | false;
441
+ /** Show quick actions when query is empty. */
442
+ showQuickActions?: boolean;
443
+ /** Maximum quick actions to show. */
444
+ quickActionsCount?: number;
445
+ }
423
446
  interface CommandMenuProps extends Omit<React$2.ComponentProps<typeof Dialog>, "children"> {
424
447
  title?: string;
425
448
  description?: string;
@@ -432,6 +455,8 @@ interface CommandMenuProps extends Omit<React$2.ComponentProps<typeof Dialog>, "
432
455
  onModeChange?: (mode: CommandMenuMode) => void;
433
456
  historyStorageKey?: string;
434
457
  maxConversations?: number;
458
+ /** Mobile-specific interaction + layout settings. */
459
+ mobile?: CommandMenuMobileOptions;
435
460
  /** Declarative command definitions. Mutually exclusive with children. */
436
461
  commands?: CommandDefinition[];
437
462
  /** Placeholder for the command input when using `commands` prop. */
@@ -450,12 +475,16 @@ declare function CommandContent({
450
475
  children,
451
476
  corners,
452
477
  borderColor,
453
- expanded,
478
+ isMobile,
479
+ keyboardInset,
480
+ onRequestClose,
454
481
  ...props
455
482
  }: React$2.ComponentProps<typeof Dialog$1.Content> & {
456
483
  corners?: CommandMenuCorners;
457
484
  borderColor?: string;
458
- expanded?: boolean;
485
+ isMobile?: boolean;
486
+ keyboardInset?: number;
487
+ onRequestClose?: () => void;
459
488
  }): react_jsx_runtime0.JSX.Element;
460
489
  declare function CommandMenu({
461
490
  chatEndpoint,
@@ -467,6 +496,7 @@ declare function CommandMenu({
467
496
  commands,
468
497
  commandsPlaceholder,
469
498
  commandsAskAILabel,
499
+ mobile,
470
500
  ...props
471
501
  }: CommandMenuProps): react_jsx_runtime0.JSX.Element;
472
502
  interface CommandInputProps extends Omit<React$2.ComponentProps<typeof pkg.Input>, "value" | "onValueChange"> {
@@ -541,6 +571,7 @@ declare function CommandList({
541
571
  children,
542
572
  actions,
543
573
  actionsHeading,
574
+ style,
544
575
  ...props
545
576
  }: CommandListProps): react_jsx_runtime0.JSX.Element;
546
577
  //#endregion
@@ -679,4 +710,4 @@ declare function TaskContent({
679
710
  ...props
680
711
  }: TaskContentProps): react_jsx_runtime0.JSX.Element;
681
712
  //#endregion
682
- export { AssistantFormRenderer, type AssistantFormRendererProps, AssistantMessages, type AssistantMessagesProps, Button, type ChatConversation, ChatEmpty, type ChatEmptyProps, ChatLoading, type ChatLoadingProps, ChatMessageList, type ChatMessageListProps, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, type CommandAction, type CommandActionOption, CommandContent, type CommandDefinition, CommandMenu as CommandDialog, CommandMenu, CommandDialogContent, CommandEmpty, type CommandEmptyProps, CommandGroup, CommandInput, type CommandInputProps, CommandItem, CommandList, type CommandListProps, CommandMenuContext, type CommandMenuContextValue, type CommandMenuCorners, type CommandMenuMode, type CommandMenuProps, CommandMenuProvider, type CommandMenuProviderProps, type CommandMenuStatus, CommandSeparator, CommandShortcut, Confirmation, ConfirmationAccepted, type ConfirmationAcceptedProps, ConfirmationAction, type ConfirmationActionProps, ConfirmationActions, type ConfirmationActionsProps, type ConfirmationProps, ConfirmationRejected, type ConfirmationRejectedProps, ConfirmationRequest, type ConfirmationRequestProps, ConfirmationTitle, type ConfirmationTitleProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, type ExternalChat, Kbd, KbdGroup, Message, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, Task, TaskContent, type TaskContentProps, TaskItem, TaskItemFile, type TaskItemFileProps, type TaskItemProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type ToolUIPartApproval, type UseChatHistoryOptions, type UseChatHistoryReturn, buttonVariants, cn, defaultFormRegistry, useChatHistory, useCommandMenuContext };
713
+ export { AssistantFormRenderer, type AssistantFormRendererProps, AssistantMessages, type AssistantMessagesProps, Button, type ChatConversation, ChatEmpty, type ChatEmptyProps, ChatLoading, type ChatLoadingProps, ChatMessageList, type ChatMessageListProps, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, type CommandAction, type CommandActionOption, CommandContent, type CommandDefinition, CommandMenu as CommandDialog, CommandMenu, CommandDialogContent, CommandEmpty, type CommandEmptyProps, CommandGroup, CommandInput, type CommandInputProps, CommandItem, CommandList, type CommandListProps, CommandMenuContext, type CommandMenuContextValue, type CommandMenuCorners, type CommandMenuMobileGesture, type CommandMenuMobileLayout, type CommandMenuMobileOptions, type CommandMenuMode, type CommandMenuProps, CommandMenuProvider, type CommandMenuProviderProps, type CommandMenuStatus, CommandSeparator, CommandShortcut, Confirmation, ConfirmationAccepted, type ConfirmationAcceptedProps, ConfirmationAction, type ConfirmationActionProps, ConfirmationActions, type ConfirmationActionsProps, type ConfirmationProps, ConfirmationRejected, type ConfirmationRejectedProps, ConfirmationRequest, type ConfirmationRequestProps, ConfirmationTitle, type ConfirmationTitleProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, type ExternalChat, Kbd, KbdGroup, Message, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, Task, TaskContent, type TaskContentProps, TaskItem, TaskItemFile, type TaskItemFileProps, type TaskItemProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type ToolUIPartApproval, type UseChatHistoryOptions, type UseChatHistoryReturn, buttonVariants, cn, defaultFormRegistry, useChatHistory, useCommandMenuContext };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{cn as e}from"./lib/utils.js";import{JSONUIProvider as t,Renderer as n,flatToTree as r}from"@json-render/react";import*as i from"react";import{createContext as a,memo as o,useCallback as s,useContext as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{z as p}from"zod";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";import{Streamdown as _}from"streamdown";import{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};
1
+ import{cn as e}from"./lib/utils.js";import{JSONUIProvider as t,Renderer as n,flatToTree as r}from"@json-render/react";import*as i from"react";import{createContext as a,memo as o,useCallback as s,useContext as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{z as p}from"zod";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";import{Streamdown as _}from"streamdown";import{ArrowUpIcon as v,ChevronDownIcon as y,KeyboardIcon as b,LoaderIcon as x,MessageCircleIcon as S,SearchIcon as C,XIcon as w}from"lucide-react";import*as T from"@radix-ui/react-collapsible";import{cva as E}from"class-variance-authority";import{Dialog as D,Slot as O}from"radix-ui";import*as k from"@radix-ui/react-dialog";import{Primitive as A}from"@radix-ui/react-primitive";import{useId as j}from"@radix-ui/react-id";import{composeRefs as M}from"@radix-ui/react-compose-refs";import{motion as N}from"motion/react";import{useChat as ee}from"@ai-sdk/react";import{DefaultChatTransport as P}from"ai";import{BrowserClient as F,Scope as I,dedupeIntegration as L,defaultStackParser as R,linkedErrorsIntegration as te,makeFetchTransport as ne}from"@sentry/browser";const re=a(null);function ie(){let e=c(re);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(re.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}=ie();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function ce({children:e}){let{approval:t,state:n}=ie();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}=ie();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}=ie();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 z(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:z,onKeyUp:z,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:z,onKeyUp:z,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:z,onKeyUp:z,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(T.Root,{"data-slot":`collapsible`,...e})}function we({...e}){return h(T.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function Te({...e}){return h(T.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(C,{className:`size-4`}),h(`p`,{className:`text-sm`,children:t}),h(y,{className:`size-4 transition-transform group-data-[state=open]:rotate-180`})]})})}function 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=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 Ve({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(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(x,{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 B=`[cmdk-group=""]`,ot=`[cmdk-group-items=""]`,st=`[cmdk-item=""]`,ct=`${st}:not([aria-disabled="true"])`,lt=`cmdk-item-select`,V=`data-value`,ut=(e,t,n)=>at(e,t,n),dt=i.createContext(void 0),H=()=>{let e=i.useContext(dt);if(!e)throw Error(`CommandContext is missing a provider`);return e},ft=i.createContext(void 0),pt=()=>{let e=i.useContext(ft);if(!e)throw Error(`StoreContext is missing a provider`);return e},mt=i.createContext(void 0),ht=i.forwardRef((e,t)=>{let n=G(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=G(()=>new Set),a=G(()=>new Map),o=G(()=>new Map),s=G(()=>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=j(),S=j(),C=j(),w=i.useRef(null),T=Ot();W(()=>{if(d!==void 0){let e=d.trim();n.current.value=e,E.emit()}},[d]),W(()=>{T(6,ee)},[]);let E=i.useMemo(()=>({subscribe:e=>(s.current.add(e),()=>s.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)N(),k(),T(1,M);else if(e===`value`){let e=document.activeElement;if(e instanceof HTMLElement&&(e.hasAttribute(`cmdk-input`)||e.hasAttribute(`cmdk-root`))){let e=document.getElementById(C);e?e.focus():document.getElementById(x)?.focus()}if(T(7,()=>{n.current.selectedItemId=P()?.id,E.emit()}),r||T(5,ee),c.current?.value!==void 0){let e=t??``;c.current.onValueChange?.(e);return}}E.emit()}},emit:()=>{s.current.forEach(e=>e())}}),[]),D=i.useMemo(()=>({value:(e,t,r)=>{t!==o.current.get(e)?.value&&(o.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,O(t,r)),T(2,()=>{k(),E.emit()}))},item:(e,t)=>{if(r.current.add(e),t)if(!a.current.has(t))a.current.set(t,new Set([e]));else{let n=a.current.get(t);n?n.add(e):a.current.set(t,new Set([e]))}return T(3,()=>{N(),k(),n.current.value||M(),E.emit()}),()=>{o.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=P();T(4,()=>{N(),t?.getAttribute(`id`)===e&&M(),E.emit()})}},group:e=>(a.current.has(e)||a.current.set(e,new Set),()=>{o.current.delete(e),a.current.delete(e)}),filter:()=>c.current.shouldFilter!==!1,label:l||e[`aria-label`]||`Command Menu`,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 k(){if(!n.current.search||c.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=a.current.get(n);if(!r){t.push([n,0]);return}let i=0;r.forEach(t=>{let n=e.get(t)??0;i=Math.max(n,i)}),t.push([n,i])});let r=w.current;F().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);if(t){let n=e.parentElement===t?e:e.closest(`${ot} > *`);n&&t.appendChild(n)}else{if(!r)return;let t=e.parentElement===r?e:e.closest(`${ot} > *`);t&&r.appendChild(t)}}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=w.current?.querySelector(`${B}[cmdk-group-id="${e[0]}"]`);t?.parentElement&&t.parentElement.appendChild(t)});let i=new Set(t.map(e=>e[0]));w.current?.querySelectorAll(`${B}[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=F().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(V);E.setState(`value`,e??``)}function N(){if(!n.current.search||c.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=O(o.current.get(t)?.value??``,o.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of a.current)for(let r of t)if((n.current.filtered.items.get(r)??0)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function ee(){let e=P();e&&(e.parentElement?.firstChild===e&&e.closest(B)?.querySelector(`[cmdk-group-heading=""]`)?.scrollIntoView({block:`nearest`}),e.scrollIntoView({block:`nearest`}))}function P(){return w.current?.querySelector(`${st}[aria-selected="true"]`)}function F(){return Array.from(w.current?.querySelectorAll(ct)||[])}function I(e){let t=F()[e];t&&E.setState(`value`,t.getAttribute(V)??``)}function L(e){let t=P(),n=F(),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(V)??``)}function R(e){let t=P()?.closest(B),n;for(;t&&!n;)t=e>0?wt(t,B):Tt(t,B),n=t?.querySelector(ct);n?E.setState(`value`,n.getAttribute(V)??``):L(e)}let te=()=>I(F().length-1),ne=e=>{e.preventDefault(),e.metaKey?te():e.altKey?R(1):L(1)},re=e=>{e.preventDefault(),e.metaKey?I(0):e.altKey?R(-1):L(-1)};return g(A.div,{ref:t,tabIndex:-1,...b,"cmdk-root":``,onKeyDown:e=>{b.onKeyDown?.(e);let t=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||t))switch(e.key){case`n`:case`j`:y&&e.ctrlKey&&ne(e);break;case`ArrowDown`:ne(e);break;case`p`:case`k`:y&&e.ctrlKey&&re(e);break;case`ArrowUp`:re(e);break;case`Home`:e.preventDefault(),I(0);break;case`End`:e.preventDefault(),te();break;case`Enter`:{e.preventDefault();let t=P();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}),q(e,e=>h(ft.Provider,{value:E,children:h(dt.Provider,{value:D,children:e})}))]})}),gt=i.forwardRef((e,t)=>{let n=j(),r=i.useRef(null),a=i.useContext(mt),o=H(),s=Et(e),c=s.current?.forceMount??a?.forceMount;W(()=>o.item(n,a?.id),[c]);let l=Dt(n,r,[e.value,e.children,r],e.keywords),u=pt(),d=K(e=>e.value&&e.value===l.current),f=K(e=>c||o.filter()===!1?!0:e.search?(e.filtered.items.get(n)??0)>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(A.div,{ref:M(r,t),...x,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!g,"aria-selected":!!d,"data-disabled":!!g,"data-selected":!!d,onPointerMove:g||o.getDisablePointerSelection()?void 0:m,onClick:g?void 0:p,children:e.children})}),_t=i.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:a,...o}=e,s=j(),c=i.useRef(null),l=i.useRef(null),u=j(),d=H(),f=K(e=>a||d.filter()===!1?!0:e.search?e.filtered.groups.has(s):!0);W(()=>d.group(s),[]),Dt(s,c,[e.value,e.heading,l]);let p=i.useMemo(()=>({id:s,forceMount:a}),[a]);return g(A.div,{ref:M(c,t),...o,"cmdk-group":``,"cmdk-group-id":s,role:`presentation`,hidden:f?void 0:!0,children:[n&&h(`div`,{ref:l,"cmdk-group-heading":``,"aria-hidden":!0,id:u,children:n}),q(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=K(e=>!e.search);return!n&&!o?null:h(A.div,{ref:M(a,t),...r,"cmdk-separator":``,role:`separator`})}),yt=i.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,a=e.value!=null,o=pt(),s=K(e=>e.search),c=K(e=>e.selectedItemId),l=H();return i.useEffect(()=>{e.value!=null&&o.setState(`search`,e.value)},[e.value]),h(A.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":c,id:l.inputId,type:`text`,value:a?e.value:s,onChange:e=>{a||o.setState(`search`,e.target.value),n?.(e.target.value)}})}),bt=i.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...a}=e,o=i.useRef(null),s=i.useRef(null),c=K(e=>e.selectedItemId),l=H();return i.useEffect(()=>{if(s.current&&o.current){let e=s.current,t=o.current,n=null,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{n!==null&&cancelAnimationFrame(n),r.unobserve(e)}}},[]),h(A.div,{ref:M(o,t),...a,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":c,"aria-label":r,id:l.listId,children:q(e,e=>h(`div`,{ref:M(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(k.Root,{open:n,onOpenChange:r,children:g(k.Portal,{container:o,children:[h(k.Overlay,{"cmdk-overlay":``,className:i}),h(k.Content,{"aria-label":e.label,"cmdk-dialog":``,className:a,children:h(ht,{ref:t,...s})})]})})}),St=i.forwardRef((e,t)=>K(e=>e.filtered.count===0)?h(A.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(A.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,children:q(e,e=>h(`div`,{"aria-hidden":!0,children:e}))})}),U=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 W(()=>{t.current=e}),t}const W=typeof window>`u`?i.useEffect:i.useLayoutEffect;function G(e){let t=i.useRef(void 0);return t.current===void 0&&(t.current=e()),t}function K(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=H();return W(()=>{let i=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&e&&`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(V,i),a.current=i}),a}const Ot=()=>{let[e,t]=i.useState(),n=G(()=>new Map);return W(()=>{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 q({asChild:e,children:t},n){if(e&&i.isValidElement(t)){let e=t;return i.cloneElement(kt(e),{ref:e.ref},n(e.props.children))}return 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(D.Root,{"data-slot":`dialog`,...e})}function Mt({...e}){return h(D.Trigger,{"data-slot":`dialog-trigger`,...e})}function J({...e}){return h(D.Portal,{"data-slot":`dialog-portal`,...e})}function Nt({...e}){return h(D.Close,{"data-slot":`dialog-close`,...e})}function Pt({className:t,...n}){return h(D.Overlay,{"data-slot":`dialog-overlay`,className:e(`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50`,t),...n})}function Ft({className:t,children:n,showCloseButton:r=!0,...i}){return g(J,{"data-slot":`dialog-portal`,children:[h(Pt,{}),g(D.Content,{"data-slot":`dialog-content`,className:e(`bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg`,t),...i,children:[n,r&&g(D.Close,{"data-slot":`dialog-close`,className:`ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[h(w,{}),h(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function It({className:t,...n}){return h(`div`,{"data-slot":`dialog-header`,className:e(`flex flex-col gap-2 text-center sm:text-left`,t),...n})}function Lt({className:t,showCloseButton:n=!1,children:r,...i}){return g(`div`,{"data-slot":`dialog-footer`,className:e(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,t),...i,children:[r,n&&h(D.Close,{asChild:!0,children:h(Ve,{variant:`outline`,children:`Close`})})]})}function Rt({className:t,...n}){return h(D.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function zt({className:t,...n}){return h(D.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function Bt({className:t,...n}){return h(`kbd`,{"data-slot":`kbd`,className:e(`bg-muted text-muted-foreground pointer-events-none inline-grid w-fit min-w-5 place-items-center gap-1 rounded px-1.5 py-0.5 font-sans text-xs font-medium select-none leading-[1]`,`[&_svg:not([class*='size-'])]:size-3`,`[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10`,t),...n})}function Vt({className:t,...n}){return h(`kbd`,{"data-slot":`kbd-group`,className:e(`inline-flex items-center gap-1`,t),...n})}function Ht({className:t,...n}){return h(U,{"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(J,{"data-slot":`dialog-portal`,children:h(D.Content,{"data-slot":`dialog-content`,className:e(`backdrop-blur-xl fixed top-1/3 left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] overflow-hidden rounded-xl border-none p-2 shadow-2xl ring-0 duration-200 outline-none sm:max-w-lg`,t),style:{backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`},...r,children:n})})}function Wt({className:t,...n}){return h(U.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function Y({className:t,ref:n,...r}){let a=i.useCallback(e=>{if(e){let t=e.querySelector(`[cmdk-group-heading]`);t instanceof HTMLElement&&(t.style.position=`sticky`,t.style.top=`0`,t.style.zIndex=`10`,t.style.width=`fit-content`,t.style.backdropFilter=`blur(24px)`,t.style.setProperty(`-webkit-backdrop-filter`,`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(U.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(U.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function Kt({className:t,style:n,...r}){return h(U.Item,{"data-slot":`command-item`,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 [&_svg:not([class*='text-'])]:text-muted-foreground relative flex h-[var(--cmdk-item-height,2.25rem)] cursor-default items-center gap-2 border border-transparent px-3 text-sm font-medium outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,t),style:{borderRadius:`var(--cmdk-radius, 0.375rem)`,...n},...r})}function qt({className:t,children:n,...r}){let i=typeof n==`string`?[...n]:null;return h(`span`,{"data-slot":`command-shortcut`,className:e(`ml-auto flex items-center gap-1`,t),...r,children:i?i.map((e,t)=>h(Bt,{children:e},t)):n})}function Jt(){return crypto.randomUUID()}function Yt(e){let t=e.find(e=>e.role===`user`);if(!t)return`New conversation`;let n=t.parts?.filter(e=>e.type===`text`).map(e=>e.text).join(` `)||`New conversation`;return n.length>50?n.slice(0,50)+`...`:n}function Xt(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function Zt({storageKey:e=`cmdk-chat-history`,maxConversations:t=50,messages:n,setMessages:r}){let[i,a]=f([]),[o,c]=f(null),[p,m]=f(!1),h=d(n);h.current=n;let g=d(r);g.current=r;let _=d(i);_.current=i;let v=d(o);v.current=o,l(()=>{try{let t=localStorage.getItem(e);if(t){let n=Xt(JSON.parse(t));n?a(n.conversations):(console.warn(`Chat history: stored data failed validation. Discarding.`),localStorage.removeItem(e))}}catch(e){console.error(`Failed to load chat history:`,e)}finally{m(!0)}},[e]),l(()=>{if(p)try{let t={version:1,conversations:i};localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(`Failed to save chat history:`,e)}},[i,e,p]);let y=s(()=>{let e=h.current,n=v.current;!n||e.length===0||a(r=>{let i=Date.now();return r.find(e=>e.id===n)?r.map(t=>t.id===n?{...t,messages:e,title:Yt(e),updatedAt:i}:t):[{id:n,title:Yt(e),messages:e,createdAt:i,updatedAt:i},...r].slice(0,t)})},[t]),b=s(()=>{v.current&&h.current.length>0&&y(),g.current?.([]),c(Jt())},[y]),x=s(e=>{v.current&&h.current.length>0&&y();let t=_.current.find(t=>t.id===e);t&&(g.current?.(t.messages),c(e))},[y]);return u(()=>({conversations:i,currentConversationId:o,startNewChat:b,loadConversation:x,saveCurrentConversation:y}),[i,o,b,x,y])}let X=null,Z=null;function Qt(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function $t(e,t){return delete e.user,delete e.server_name,e.request&&(delete e.request.cookies,delete e.request.headers,delete e.request.env,delete e.request.data),e.breadcrumbs=[],e}function en(){typeof window>`u`||X===null&&(Qt()||(X=new F({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:ne,stackParser:R,integrations:[L(),te()],beforeSend:$t,sendDefaultPii:!1,tracesSampleRate:1}),Z=new I,Z.setClient(X),X.init()))}function tn(e,t){!Z||!X||(t?Z.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):Z.captureException(e))}function nn(e){try{let t=new Uint8Array(e/2);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}catch{let t=``;for(let n=0;n<e;n++)t+=Math.floor(Math.random()*16).toString(16);return t}}function rn(e,t,n){if(!Z||!X)return n();let r=Date.now()/1e3,i=nn(32),a=nn(16),o=`ok`,s=()=>{let n=Date.now()/1e3;Z.captureEvent({type:`transaction`,transaction:e,start_timestamp:r,timestamp:n,contexts:{trace:{trace_id:i,span_id:a,op:t,status:o}}})};try{let e=n();return e instanceof Promise?e.then(e=>(s(),e),e=>{throw o=`internal_error`,s(),e}):(s(),e)}catch(e){throw o=`internal_error`,s(),e}}const an=i.createContext(null),on=[];function sn({children:e,chatEndpoint:t=null,chat:n,onModeChange:r,onOpenChange:a,historyStorageKey:o,maxConversations:s}){let[c,l]=i.useState(`command`),[u,d]=i.useState(``),[f,p]=i.useState(`idle`),[m,g]=i.useState(null),_=i.useRef(n);_.current=n;let v=!!n;i.useEffect(()=>{en()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new P({api:t})},[t,v]),b=ee(i.useMemo(()=>y?{transport:y,onError:e=>{tn(e,{source:`internalChat.onError`}),p(`error`),g(e)}}:{},[y])),x=n?.status,S=n?.error??null;i.useEffect(()=>{if(v)x===`ready`?p(`idle`):x===`streaming`?p(`streaming`):x===`submitted`?p(`submitted`):x===`error`&&p(`error`),g(S);else{let e=b.status;e===`streaming`?p(`streaming`):e===`submitted`?p(`submitted`):e===`error`?p(`error`):e===`ready`&&p(`idle`)}},[x,S,b.status,v]);let C=i.useCallback(e=>{l(e),r?.(e)},[r]),w=!!(n||t),T=i.useCallback(e=>{w&&rn(`switchToChat`,`ui.action`,()=>{C(`chat`),e&&d(e)})},[w,C]),E=i.useCallback(()=>{C(`command`),d(``),p(`idle`),g(null)},[C]),D=i.useCallback(async e=>{e.trim()&&await rn(`sendMessage`,`function`,async()=>{try{let t=_.current;if(t){d(``),t.sendMessage({text:e.trim()});return}if(!y)return;p(`submitted`),d(``),await b.sendMessage({text:e.trim()})}catch(e){throw tn(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??on,A=n?.setMessages??b.setMessages,j=n?.addToolApprovalResponse,M=n?.agenticActions,N=Zt({storageKey:o,maxConversations:s,messages:k,setMessages:A}),F=i.useCallback(e=>{N.loadConversation(e),C(`chat`)},[N.loadConversation,C]),I=i.useRef(f);i.useEffect(()=>{let e=I.current;I.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&N.saveCurrentConversation()},[f,k.length,N.saveCurrentConversation]);let L=i.useCallback(()=>{a?.(!1)},[a]),R=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:L,conversations:N.conversations,currentConversationId:N.currentConversationId,startNewChat:N.startNewChat,loadConversation:F}),[c,C,u,t,f,m,T,E,k,D,O,w,j,M,L,N.conversations,N.currentConversationId,N.startNewChat,F]);return h(an.Provider,{value:R,children:e})}function Q(){let e=i.useContext(an);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}var cn=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){tn(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};function ln(e){return e instanceof Element?!!e.closest(`input, textarea, select, button, a, [contenteditable='true'], [contenteditable=''], [data-cmdk-mobile-gesture-ignore]`):!1}function un(e,t,n,r,i,a){let o=window.innerWidth,s=window.innerHeight,c=o*n,l=o-a,u=Math.max(0,l-c),d=s*(1-r),f=s-i;return e>=u&&e<=l&&t>=d&&t<=f}function dn({enabled:e,open:t,holdMs:n,swipeUpPx:r,onTrigger:a,movementTolerancePx:o=10,horizontalCancelPx:s=24,activationZoneWidthPercent:c=.4,activationZoneHeightPercent:l=.4,bottomExclusionPx:u=8,rightExclusionPx:d=0}){let[f,p]=i.useState(!1),m=i.useRef(null),h=i.useRef(0),g=i.useRef(a);i.useEffect(()=>{g.current=a},[a]);let _=i.useCallback(()=>{let e=m.current;e?.timer!=null&&window.clearTimeout(e.timer),m.current=null,p(!1)},[]);return i.useEffect(()=>{if(!e||t||typeof window>`u`){_();return}let i=e=>{if(e.touches.length!==1||ln(e.target))return;let t=e.touches[0];if(!t||!un(t.clientX,t.clientY,c,l,u,d))return;h.current=Date.now();let r=window.setTimeout(()=>{let e=m.current;e&&(e.armed=!0,p(!0),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(6))},n);m.current={startX:t.clientX,startY:t.clientY,armed:!1,timer:r}},a=e=>{if(e.touches.length!==1){_();return}let t=m.current;if(!t)return;let n=e.touches[0];if(!n)return;let i=n.clientX-t.startX,a=n.clientY-t.startY;if(!t.armed){Math.hypot(i,a)>o&&_();return}if(Math.abs(i)>s){_();return}a<=-r&&(_(),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(14),g.current())},f=()=>{_()},v=()=>{_()},y=e=>{let t=m.current!==null,r=Date.now()-h.current<n+1200;if(t||r){if(!t&&ln(e.target))return;e.preventDefault()}};return document.addEventListener(`touchstart`,i,{passive:!0}),document.addEventListener(`touchmove`,a,{passive:!0}),document.addEventListener(`touchend`,f,{passive:!0}),document.addEventListener(`touchcancel`,v,{passive:!0}),document.addEventListener(`contextmenu`,y),()=>{document.removeEventListener(`touchstart`,i),document.removeEventListener(`touchmove`,a),document.removeEventListener(`touchend`,f),document.removeEventListener(`touchcancel`,v),document.removeEventListener(`contextmenu`,y),_()}},[e,t,n,r,o,s,c,l,u,d,_]),{showHint:f}}function fn(e){let[t,n]=i.useState(0);return i.useEffect(()=>{if(!e||typeof window>`u`){n(0);return}let t=window.visualViewport;if(!t){n(0);return}let r=()=>{let e=Math.max(0,Math.round(window.innerHeight-t.height-t.offsetTop));n(t=>t===e?t:e)};return r(),t.addEventListener(`resize`,r),t.addEventListener(`scroll`,r),window.addEventListener(`orientationchange`,r),()=>{t.removeEventListener(`resize`,r),t.removeEventListener(`scroll`,r),window.removeEventListener(`orientationchange`,r)}},[e]),t}const pn=e=>{},mn={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},hn={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},gn=i.createContext({isMobile:!1,layout:`keyboard-last`,keyboardInset:0,showQuickActions:!1,quickActionsCount:4});function _n(){return i.useContext(gn)}function vn(e){let t=e?.gesture!==!1,n=e?.gesture===!1?void 0:e?.gesture;return{enabled:e?.enabled??!0,breakpoint:e?.breakpoint??900,layout:e?.layout??`keyboard-last`,gesture:{enabled:t?n?.enabled??!0:!1,holdMs:t?n?.holdMs??350:350,swipeUpPx:t?n?.swipeUpPx??56:56},showQuickActions:e?.showQuickActions??!0,quickActionsCount:e?.quickActionsCount??4}}function yn(e,t){let[n,r]=i.useState(!1);return i.useEffect(()=>{if(!t||typeof window>`u`){r(!1);return}let n=window.matchMedia(`(max-width: ${e}px)`),i=window.matchMedia(`(pointer: coarse)`),a=()=>{r(n.matches||i.matches)};return a(),n.addEventListener(`change`,a),i.addEventListener(`change`,a),window.addEventListener(`orientationchange`,a),()=>{n.removeEventListener(`change`,a),i.removeEventListener(`change`,a),window.removeEventListener(`orientationchange`,a)}},[e,t]),n}function bn(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 xn({className:t,children:n,corners:r=`xl`,borderColor:a,isMobile:o,keyboardInset:s,onRequestClose:c,...l}){let u=i.useRef(null),d=i.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(e instanceof HTMLElement&&e.hasAttribute(`cmdk-input`)){e.blur();return}c?.()},[c]),f=e=>{if(e.touches.length!==1)return;let t=e.touches[0];t&&(u.current={x:t.clientX,y:t.clientY})},p=e=>{let t=u.current;if(u.current=null,!t||e.changedTouches.length===0)return;let n=e.changedTouches[0];if(!n)return;let r=n.clientX-t.x;n.clientY-t.y>56&&Math.abs(r)<42&&d()};return g(J,{"data-slot":`dialog-portal`,children:[o&&h(D.Overlay,{className:`fixed inset-0 z-40 bg-black/35 backdrop-blur-[1px] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),g(`div`,{className:e(`fixed z-50 w-full max-w-[calc(100%-2rem)]`,o?`inset-x-0 bottom-0 max-w-none px-0`:`top-1/3 left-[50%] translate-x-[-50%] translate-y-[-50%]`),style:o?void 0:{maxWidth:`45vw`},children:[g(D.Content,{"data-slot":`dialog-content`,className:e(`backdrop-blur-xl flex flex-col w-full overflow-hidden border border-input p-0 ring-0 outline-none`,o?`border-x-0 border-b-0 will-change-transform 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]:slide-out-to-bottom-8 data-[state=open]:slide-in-from-bottom-8 data-[state=open]:duration-300 data-[state=closed]:duration-200`:mn[r],t),style:{"--cmdk-radius":hn[r],"--cmdk-mobile-keyboard-inset":`${s??0}px`,"--cmdk-mobile-sheet-top-inset":`max(11rem, calc(env(safe-area-inset-top) + 8rem))`,maxHeight:o?`calc(100dvh - var(--cmdk-mobile-sheet-top-inset))`:`45vh`,height:o?`calc(100dvh - var(--cmdk-mobile-sheet-top-inset))`:void 0,...o?{borderTopLeftRadius:hn[r],borderTopRightRadius:hn[r],borderBottomLeftRadius:`0px`,borderBottomRightRadius:`0px`}:{},backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`,boxShadow:`4px 4px 12px -2px rgba(0,0,0,0.12), -4px 4px 12px -2px rgba(0,0,0,0.12), 0 8px 16px -4px rgba(0,0,0,0.1)`,...a?{"--tw-ring-color":a}:{}},...l,children:[o&&h(`div`,{className:`flex justify-center py-2`,"data-cmdk-mobile-gesture-ignore":!0,onTouchStart:f,onTouchEnd:p,children:h(`div`,{className:`h-1.5 w-11 rounded-full bg-muted-foreground/35`})}),n]}),h(`div`,{className:e(`flex justify-end select-none`,o&&`hidden`),children:h(`a`,{href:`https://better-cmdk.com`,target:`_blank`,rel:`noopener noreferrer`,className:`text-xs text-muted-foreground font-medium px-2 py-0.5 hover:text-foreground transition-colors`,style:{borderRadius:`0 0 0.375rem 0.375rem`,marginRight:`1rem`,backgroundColor:`color-mix(in oklch, var(--background) 95%, transparent)`,backdropFilter:`blur(24px)`,WebkitBackdropFilter:`blur(24px)`,borderLeft:`1px solid var(--color-input)`,borderRight:`1px solid var(--color-input)`,borderBottom:`1px solid var(--color-input)`,boxShadow:`4px 4px 12px -2px rgba(0,0,0,0.12), -4px 4px 12px -2px rgba(0,0,0,0.12), 0 8px 16px -4px rgba(0,0,0,0.1)`},children:`powered by better-cmdk`})})]})]})}const Sn=g(m,{children:[h(Tn,{placeholder:`Search for commands or ask AI...`,showSendButton:!0}),h(On,{children:h($,{})})]});function Cn({title:t=`Command Palette`,description:n=`Search for a command to run...`,children:r,className:a,corners:o=`xl`,borderColor:s,commands:c,commandsPlaceholder:l=`Search for commands or ask AI...`,commandsAskAILabel:u=`Ask AI`,mobile:d,...f}){let{mode:p,status:_,switchToCommand:y,messages:b,isEnabled:x,setInputValue:S,inputValue:C}=Q(),w=i.useMemo(()=>vn(d),[d]),T=yn(w.breakpoint,w.enabled),E=w.enabled&&T,D=fn(E&&!!f.open),O=i.useCallback(e=>{e&&S(``),f.onOpenChange?.(e)},[f.onOpenChange,S]),k=i.useCallback(()=>{O(!0)},[O]),A=dn({enabled:E&&!f.open&&!!f.onOpenChange&&w.gesture.enabled,open:!!f.open,holdMs:w.gesture.holdMs,swipeUpPx:w.gesture.swipeUpPx,onTrigger:k}),j=i.useMemo(()=>({isMobile:E,layout:w.layout,keyboardInset:D,showQuickActions:w.showQuickActions,quickActionsCount:w.quickActionsCount}),[E,w.layout,D,w.showQuickActions,w.quickActionsCount]),M=()=>c&&c.length>0?h(Dn,{commands:c,placeholder:l,askAILabel:u}):typeof r==`function`?r({mode:p,messages:b,status:_,isEnabled:x}):r??Sn,N=e=>{p===`chat`&&(e.preventDefault(),y())};return i.useEffect(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),O(!1))};if(f.open)return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[f.open,O]),g(m,{children:[h(jt,{...f,onOpenChange:O,children:g(xn,{className:a,corners:o,borderColor:s,isMobile:E,keyboardInset:D,onRequestClose:()=>O(!1),onEscapeKeyDown:N,onOpenAutoFocus:e=>{E&&w.layout===`keyboard-last`&&e.preventDefault()},children:[g(It,{className:`sr-only`,children:[h(Rt,{children:t}),h(zt,{children:n})]}),h(gn.Provider,{value:j,children:h(U,{"data-slot":`command`,className:e(`**:data-[slot=command-input-wrapper]:bg-transparent rounded-none bg-transparent **:data-[slot=command-input]:!h-11 **:data-[slot=command-input]:py-0 **:data-[slot=command-input-wrapper]:mb-0`,E?`**:data-[slot=command-input-wrapper]:!h-[var(--cmdk-input-row-height)] pb-[env(safe-area-inset-bottom)]`:`**:data-[slot=command-input-wrapper]:!h-11`,`text-popover-foreground flex h-full min-h-0 w-full flex-col overflow-hidden`),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`,"--cmdk-item-height":E?`3.125rem`:`2.25rem`,"--cmdk-input-row-height":E?`3.5rem`:`2.75rem`},children:M()})})]})}),A.showHint&&g(`div`,{className:`fixed left-1/2 z-50 flex -translate-x-1/2 items-center gap-2 rounded-full border border-input bg-background/95 px-3 py-1.5 text-xs font-medium text-foreground shadow-sm backdrop-blur-md`,style:{bottom:`calc(env(safe-area-inset-bottom) + 2rem)`},"data-cmdk-mobile-gesture-ignore":!0,children:[h(v,{className:`size-3.5`}),`Swipe up for Command Menu`]})]})}function wn({chatEndpoint:e=null,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,mobile:l,...u}){return h(sn,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(cn,{children:h(Cn,{onOpenChange:r,commands:o,commandsPlaceholder:s,commandsAskAILabel:c,mobile:l,...u})})})}function Tn({className:t,showSendButton:n=!1,...r}){let{mode:a,inputValue:o,setInputValue:s,sendMessage:c,isLoading:l,switchToChat:u,startNewChat:d}=Q(),{isMobile:f,layout:p,keyboardInset:m}=_n(),[_,y]=i.useState(!1),x=i.useRef(null),S=()=>{o.trim()&&a===`chat`&&c(o)},C=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`Enter`){e.preventDefault(),a===`command`&&o.trim()?(d(),u(),c(o)):a===`chat`&&o.trim()&&c(o);return}if(a===`chat`&&e.key===`Enter`&&!e.shiftKey){e.preventDefault(),o.trim()&&c(o);return}},w=a===`chat`||o.length>0||f&&p===`keyboard-last`,T=f&&p===`keyboard-last`&&!_&&a===`command`,E=e=>{y(!0),r.onFocus?.(e)},D=e=>{y(!1),r.onBlur?.(e)},O=f?{marginBottom:m>0?`${m}px`:void 0}:void 0,k={...r,onFocus:E,onBlur:D};return g(`div`,{"data-slot":`command-input-wrapper`,className:e(`order-2 flex h-[var(--cmdk-input-row-height,2.75rem)] items-center gap-2 px-6 transition-[margin,border-color] duration-200`,f&&`px-4`,w?`border-t border-input mt-0`:`border-t border-transparent mt-0`),style:O,children:[h(U.Input,{"data-slot":`command-input`,ref:x,value:o,onValueChange:s,onKeyDown:C,className:e(`placeholder:text-muted-foreground flex h-10 w-full bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50`,t),...k,placeholder:a===`chat`?`Ask AI...`:r.placeholder}),T&&h(`button`,{type:`button`,onClick:()=>x.current?.focus(),className:`flex items-center justify-center size-7 shrink-0 border border-input bg-background text-muted-foreground hover:text-foreground transition-colors`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},"aria-label":`Type a command`,"data-cmdk-mobile-gesture-ignore":!0,children:h(b,{className:`size-4`})}),n&&a===`chat`&&h(`button`,{type:`button`,onClick:S,disabled:!o.trim()||l,className:`flex items-center justify-center size-6 shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},children:h(v,{className:`size-3`})})]})}function $({label:t=`Ask AI`,className:n,...r}){let{inputValue:i,setInputValue:a,switchToChat:o,sendMessage:s,isEnabled:c,startNewChat:l}=Q(),{isMobile:u}=_n(),d=K(e=>e.filtered.count),f=()=>{if(c)if(i.trim()){let e=ut(`ask-ai`,i.trim())>0;d===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(U.Group,{forceMount:!0,children:g(U.Item,{"data-slot":`command-item`,value:`ask-ai`,onSelect:f,className:e(`data-[selected=true]:border-input data-[selected=true]:bg-input/50 relative flex cursor-default items-center gap-3 border border-transparent px-3 py-2 text-sm outline-hidden select-none`,u&&`min-h-12 py-3`,n),style:{borderRadius:`var(--cmdk-radius, 0.75rem)`},...r,children:[h(S,{className:`size-4 shrink-0 text-primary`}),h(`div`,{className:`flex flex-col items-start gap-0.5`,children:h(`span`,{className:`font-medium`,children:t})}),!u&&g(`span`,{className:`ml-auto flex items-center gap-1`,children:[h(Bt,{children:`⌘`}),h(Bt,{children:`↵`})]})]})}):h(U.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function En(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 Dn({commands:t,placeholder:n,askAILabel:r}){let{inputValue:a,mode:o}=Q(),{isMobile:s,layout:c,showQuickActions:l,quickActionsCount:u}=_n(),d=En(t),f=s&&c===`keyboard-last`&&l&&o===`command`&&a.length===0,p=f?t.filter(e=>!e.disabled).slice(0,u):[],_=new Set(p.map(e=>e.name)),v=t=>{let n=t.label??t.name,r=[...t.keywords??[]];return t.label&&t.label!==t.name&&r.push(t.label),g(Kt,{value:t.name,keywords:r.length>0?r:void 0,disabled:t.disabled,onSelect:()=>t.onSelect?.(),className:e(s&&`min-h-12 py-3`),children:[t.icon,n,t.shortcut&&!s&&h(qt,{children:t.shortcut})]},t.name)};return g(m,{children:[h(Tn,{placeholder:n,showSendButton:!0}),g(On,{children:[f&&p.length>0&&h(Y,{heading:`Quick Actions`,children:p.map(e=>v(e))}),d.map((e,t)=>{let n=f?e.items.filter(e=>!_.has(e.name)):e.items;if(n.length===0)return null;let r=n.map(e=>v(e));return e.heading?h(Y,{heading:e.heading,children:r},e.heading):h(i.Fragment,{children:r},`__ungrouped_${t}`)}),h($,{label:r})]})]})}function On({className:t,children:n,actions:r,actionsHeading:a=`Actions`,style:o,...s}){let{mode:c,status:l,messages:u,sendMessage:d,addToolApprovalResponse:f,agenticActions:p,switchToChat:m,startNewChat:_,conversations:v,loadConversation:y,inputValue:b}=Q(),{isMobile:x,layout:C,keyboardInset:w}=_n(),T=i.useCallback(e=>d(e.text),[d]),E=f??pn;if(c===`chat`)return h(`div`,{"data-slot":`command-list`,className:e(`order-1 min-h-0 flex-1 overflow-hidden px-3 flex flex-col`,x&&`px-2`,t),children:u.length===0?h(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:u,sendMessage:T,addToolApprovalResponse:E})}),l===`streaming`&&h(Ue,{})]})});let D=i.Children.toArray(n),O=[],k=[];D.forEach(e=>{i.isValidElement(e)&&(e.type===$||e.type.displayName===`CommandEmpty`)?O.push(e):i.isValidElement(e)&&e.type===Wt||k.push(e)});let A=(r??p)?.filter(e=>e.execute),j=e=>{let t=e.label??e.name;_(),m(),d(t)},M=b.length>0||x&&C===`keyboard-last`,ee=x?`calc(100% - var(--cmdk-input-row-height, 3.5rem))`:`calc(45vh - 2.75rem)`,P={overscrollBehavior:`contain`,paddingBottom:w>0?`${w+8}px`:x?`env(safe-area-inset-bottom)`:void 0,...o};return h(N.div,{initial:!1,animate:{height:M?ee:0},transition:{type:`spring`,duration:.25,bounce:0},className:e(`order-1 min-h-0 overflow-hidden px-3`,x&&`px-2`),children:g(U.List,{"data-slot":`command-list`,className:e(`overflow-x-hidden overflow-y-auto overscroll-contain pt-2 h-full`,x&&`pt-1`,t),style:P,...s,children:[k,v.length>0&&h(Y,{heading:`Recent Chats`,children:v.slice(0,5).map(t=>g(Kt,{value:`chat-history-${t.id}`,keywords:[t.title],onSelect:()=>y(t.id),className:e(x&&`min-h-12 py-3`),children:[h(S,{className:`size-4`}),h(`span`,{className:`truncate`,children:t.title}),h(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:bn(t.updatedAt)})]},t.id))}),A&&A.length>0&&h(Y,{heading:a,children:A.map(t=>h(Kt,{value:t.label??t.name,onSelect:()=>j(t),className:e(x&&`min-h-12 py-3`),children:t.label??t.name},t.name))}),O]})})}$.displayName=`CommandEmpty`;export{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,xn as CommandContent,wn as CommandDialog,wn as CommandMenu,Ut as CommandDialogContent,$ as CommandEmpty,Y as CommandGroup,Tn as CommandInput,Kt as CommandItem,On as CommandList,an as CommandMenuContext,sn as CommandMenuProvider,Gt as CommandSeparator,qt 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,Nt as DialogClose,Ft as DialogContent,zt as DialogDescription,Lt as DialogFooter,It as DialogHeader,Pt as DialogOverlay,J as DialogPortal,Rt as DialogTitle,Mt as DialogTrigger,Bt 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,Zt as useChatHistory,Q as useCommandMenuContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-cmdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "types": "./index.ts",
6
6
  "exports": {