better-cmdk 0.0.21 → 0.0.22

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/dist/index.d.ts CHANGED
@@ -565,13 +565,6 @@ interface CommandAction {
565
565
  disabled?: boolean;
566
566
  /** Called when the action is selected directly */
567
567
  onSelect?: () => void;
568
- /**
569
- * Structured input schema for argument-requiring actions.
570
- * Actions without `inputSchema` are treated as command-like.
571
- */
572
- inputSchema?: Partial<Record<string, CommandActionOption>>;
573
- /** Whether this action requires approval before execution. */
574
- approvalRequired?: boolean;
575
568
  /** Action execution callback. */
576
569
  execute: CommandActionExecuteHandler<Record<string, unknown>>;
577
570
  }
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,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{useChat as N}from"@ai-sdk/react";import{DefaultChatTransport as ee}from"ai";import{BrowserClient as P,Scope as F,dedupeIntegration as I,defaultStackParser as L,linkedErrorsIntegration as te,makeFetchTransport as ne}from"@sentry/browser";import{motion as re}from"motion/react";const R=a(null);function z(){let e=c(R);if(!e)throw Error(`Confirmation components must be used within Confirmation`);return e}function ie({approval:t,state:n,style:r,...i}){return!t||n===`input-streaming`||n===`input-available`?null:h(R.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 ae(e){return h(`p`,{id:`confirmation-title`,"data-slot":`confirmation-title`,className:`text-sm font-medium`,...e})}function oe({children:e}){let{state:t}=z();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function se({children:e}){let{approval:t,state:n}=z();return!t?.approved||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-accepted`,children:e})}function ce({children:e}){let{approval:t,state:n}=z();return t?.approved!==!1||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-rejected`,children:e})}function le(e){let{state:t}=z();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-actions`,className:`flex items-center justify-end gap-2 self-end`,...e}):null}function ue({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 B(e){e.stopPropagation()}function de({element:t,children:n,onAction:r}){let{id:i=`form`,title:a,submitLabel:o=`Submit`}=t.props??{},s=e=>{e.preventDefault();let t=new FormData(e.currentTarget),n={};t.forEach((e,t)=>{typeof e==`string`&&(n[t]=e)}),r?.({name:`submit`,params:{formId:i,data:n}})};return g(`div`,{"data-slot":`form-card`,className:e(`w-full rounded-lg border bg-card text-card-foreground shadow-sm`),children:[a&&h(`div`,{className:`flex flex-col space-y-1.5 p-4 pb-3`,children:h(`h3`,{className:`text-base font-semibold leading-none tracking-tight`,children:a})}),h(`div`,{className:e(`p-4`,a?``:`pt-4`),children:g(`form`,{onSubmit:s,className:`space-y-4`,children:[n,g(`div`,{className:`flex justify-end gap-2 pt-2`,children:[h(`button`,{type:`button`,className:e(`inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors`,`hover:bg-accent hover:text-accent-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r?.({name:`cancel`,params:{formId:i}}),children:`Cancel`}),h(`button`,{type:`submit`,className:e(`inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow transition-colors`,`hover:bg-primary/90`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),children:o})]})]})})]})}function fe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{id:n,name:n,type:`text`,placeholder:i,required:a,defaultValue:o,autoComplete:`off`,onKeyDown:B,onKeyUp:B,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function pe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o,rows:s=3}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`textarea`,{id:n,name:n,placeholder:i,required:a,defaultValue:o,rows:s,onKeyDown:B,onKeyUp:B,className:e(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function me({element:t}){let{name:n=`date`,label:r=`Date`,required:i,defaultValue:a,min:o,max:s}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,i&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{type:`date`,id:n,name:n,required:i,defaultValue:a,min:o,max:s,onKeyDown:B,onKeyUp:B,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 he={Form:de,TextField:fe,TextArea:pe,DateField:me},ge=p.object({formId:p.string(),data:p.record(p.string(),p.string())}),_e=p.object({formId:p.string()});function ve({ui:e,context:r,onSubmit:i,onCancel:a,registry:o=he}){let c=s(e=>{let t=ge.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=_e.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 ye({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 be({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 xe=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 Se({...e}){return h(T.Root,{"data-slot":`collapsible`,...e})}function Ce({...e}){return h(T.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function we({...e}){return h(T.CollapsibleContent,{"data-slot":`collapsible-content`,...e})}function Te({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 Ee({children:e,...t}){return h(`div`,{"data-slot":`task-item`,className:`text-sm text-muted-foreground`,...t,children:e})}function De({defaultOpen:e=!0,...t}){return h(Se,{"data-slot":`task`,defaultOpen:e,...t})}function Oe({children:e,title:t,icon:n,...r}){return h(Ce,{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 ke({children:t,...n}){return h(we,{"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 Ae=p.object({name:p.string(),options:p.record(p.string(),p.unknown()).optional()}),je=p.object({actions:p.array(Ae).optional()}),Me=p.object({id:p.string(),approved:p.boolean().optional()}),Ne=p.object({type:p.string(),props:p.record(p.string(),p.unknown()).default({}),children:p.array(p.string()).optional(),parentKey:p.string().nullable().optional()}),Pe=p.object({ui:p.object({elements:p.record(p.string(),Ne)}),context:p.record(p.string(),p.unknown()).optional()});function Fe(e){return e.name}function Ie({messages:e,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r=Fe}){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(ye,{from:e.role,children:h(be,{children:e.parts.map((i,a)=>h(Le,{part:i,messageId:e.id,partIndex:a,isLastMessage:o,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r},`${e.id}-${a}`))})},e.id)})})}function Le({part:e,messageId:t,partIndex:n,isLastMessage:r,sendMessage:i,addToolApprovalResponse:a,getActionDescription:o}){if(e.type===`text`)return h(xe,{children:e.text});if(e.type===`tool-performActions`){let r=`input`in e?e.input:void 0,i=je.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=Me.safeParse(u),f=d.success?d.data:void 0;return f&&l?g(ie,{state:l,approval:f,children:[h(ae,{children:c===1?`Confirm action`:`Confirm ${c} actions`}),h(oe,{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(se,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action approved`:`${c} actions approved`})}),h(ce,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action cancelled`:`${c} actions cancelled`})}),g(le,{children:[h(ue,{variant:`outline`,onClick:()=>a({id:f.id,approved:!1}),children:`Deny`}),h(ue,{onClick:()=>a({id:f.id,approved:!0}),children:`Approve`})]})]}):g(De,{defaultOpen:!1,children:[h(Oe,{title:c===1?`Performing 1 action`:`Performing ${c} actions`}),h(ke,{children:s.map((e,r)=>h(Ee,{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(Re,{output:e.output,sendMessage:i}):null}function Re({output:e,sendMessage:t}){let n=i.useMemo(()=>{let t=Pe.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(ve,{ui:n.ui,context:n.context,onSubmit:a,onCancel:o}):null}const ze=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 Be({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(ze({variant:n,size:r,className:t})),...a})}function Ve({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 He({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 Ue({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 We=1,Ge=.9,Ke=.8,qe=.17,Je=.1,Ye=.999,Xe=.9999,Ze=.99,Qe=/[\\\/_+.#"@\[\(\{&]/,$e=/[\\\/_+.#"@\[\(\{&]/g,et=/[\s-]/,tt=/[\s-]/g;function nt(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?We:Ze;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=nt(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=We:Qe.test(e.charAt(l-1))?(d*=Ke,p=e.slice(i,l-1).match($e),p&&i>0&&(d*=Ye**+p.length)):et.test(e.charAt(l-1))?(d*=Ge,m=e.slice(i,l-1).match(tt),m&&i>0&&(d*=Ye**+m.length)):(d*=qe,i>0&&(d*=Ye**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Xe)),(d<Je&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=nt(e,t,n,r,l+1,a+2,o),f*Je>d&&(d=f*Je)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function rt(e){return e.toLowerCase().replace(tt,` `)}function it(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,nt(e,t,rt(e),rt(t),0,0,{})}const V=`[cmdk-group=""]`,at=`[cmdk-group-items=""]`,ot=`[cmdk-item=""]`,st=`${ot}:not([aria-disabled="true"])`,ct=`cmdk-item-select`,H=`data-value`,lt=(e,t,n)=>it(e,t,n),ut=i.createContext(void 0),U=()=>{let e=i.useContext(ut);if(!e)throw Error(`CommandContext is missing a provider`);return e},dt=i.createContext(void 0),ft=()=>{let e=i.useContext(dt);if(!e)throw Error(`StoreContext is missing a provider`);return e},pt=i.createContext(void 0),mt=i.forwardRef((e,t)=>{let n=K(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=K(()=>new Set),a=K(()=>new Map),o=K(()=>new Map),s=K(()=>new Set),c=Tt(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=Dt();G(()=>{if(d!==void 0){let e=d.trim();n.current.value=e,E.emit()}},[d]),G(()=>{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??lt;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(at);if(t){let n=e.parentElement===t?e:e.closest(`${at} > *`);n&&t.appendChild(n)}else{if(!r)return;let t=e.parentElement===r?e:e.closest(`${at} > *`);t&&r.appendChild(t)}}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=w.current?.querySelector(`${V}[cmdk-group-id="${e[0]}"]`);t?.parentElement&&t.parentElement.appendChild(t)});let i=new Set(t.map(e=>e[0]));w.current?.querySelectorAll(`${V}[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(H);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(V)?.querySelector(`[cmdk-group-heading=""]`)?.scrollIntoView({block:`nearest`}),e.scrollIntoView({block:`nearest`}))}function P(){return w.current?.querySelector(`${ot}[aria-selected="true"]`)}function F(){return Array.from(w.current?.querySelectorAll(st)||[])}function I(e){let t=F()[e];t&&E.setState(`value`,t.getAttribute(H)??``)}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(H)??``)}function te(e){let t=P()?.closest(V),n;for(;t&&!n;)t=e>0?Ct(t,V):wt(t,V),n=t?.querySelector(st);n?E.setState(`value`,n.getAttribute(H)??``):L(e)}let ne=()=>I(F().length-1),re=e=>{e.preventDefault(),e.metaKey?ne():e.altKey?te(1):L(1)},R=e=>{e.preventDefault(),e.metaKey?I(0):e.altKey?te(-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&&re(e);break;case`ArrowDown`:re(e);break;case`p`:case`k`:y&&e.ctrlKey&&R(e);break;case`ArrowUp`:R(e);break;case`Home`:e.preventDefault(),I(0);break;case`End`:e.preventDefault(),ne();break;case`Enter`:{e.preventDefault();let t=P();if(t){let e=new Event(ct);t.dispatchEvent(e)}}}},children:[h(`label`,{"cmdk-label":``,htmlFor:D.inputId,id:D.labelId,style:kt,children:l}),J(e,e=>h(dt.Provider,{value:E,children:h(ut.Provider,{value:D,children:e})}))]})}),ht=i.forwardRef((e,t)=>{let n=j(),r=i.useRef(null),a=i.useContext(pt),o=U(),s=Tt(e),c=s.current?.forceMount??a?.forceMount;G(()=>o.item(n,a?.id),[c]);let l=Et(n,r,[e.value,e.children,r],e.keywords),u=ft(),d=q(e=>e.value&&e.value===l.current),f=q(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(ct,p),()=>t.removeEventListener(ct,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})}),gt=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=U(),f=q(e=>a||d.filter()===!1?!0:e.search?e.filtered.groups.has(s):!0);G(()=>d.group(s),[]),Et(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}),J(e,e=>h(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?u:void 0,children:h(pt.Provider,{value:p,children:e})}))]})}),_t=i.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,a=i.useRef(null),o=q(e=>!e.search);return!n&&!o?null:h(A.div,{ref:M(a,t),...r,"cmdk-separator":``,role:`separator`})}),vt=i.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,a=e.value!=null,o=ft(),s=q(e=>e.search),c=q(e=>e.selectedItemId),l=U();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)}})}),yt=i.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...a}=e,o=i.useRef(null),s=i.useRef(null),c=q(e=>e.selectedItemId),l=U();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:J(e,e=>h(`div`,{ref:M(s,l.listInnerRef),"cmdk-list-sizer":``,children:e}))})}),bt=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(mt,{ref:t,...s})})]})})}),xt=i.forwardRef((e,t)=>q(e=>e.filtered.count===0)?h(A.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),St=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:J(e,e=>h(`div`,{"aria-hidden":!0,children:e}))})}),W=Object.assign(mt,{List:yt,Item:ht,Input:vt,Group:gt,Separator:_t,Dialog:bt,Empty:xt,Loading:St});function Ct(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wt(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Tt(e){let t=i.useRef(e);return G(()=>{t.current=e}),t}const G=typeof window>`u`?i.useEffect:i.useLayoutEffect;function K(e){let t=i.useRef(void 0);return t.current===void 0&&(t.current=e()),t}function q(e){let t=ft(),n=()=>e(t.snapshot());return i.useSyncExternalStore(t.subscribe,n,n)}function Et(e,t,n,r=[]){let a=i.useRef(``),o=U();return G(()=>{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(H,i),a.current=i}),a}const Dt=()=>{let[e,t]=i.useState(),n=K(()=>new Map);return G(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Ot(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function J({asChild:e,children:t},n){if(e&&i.isValidElement(t)){let e=t;return i.cloneElement(Ot(e),{ref:e.ref},n(e.props.children))}return n(t)}const kt={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function At(){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 Mt(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function Nt({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=Mt(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(At())},[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 Y=null,X=null;function Pt(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function Ft(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 It(){typeof window>`u`||Y===null&&(Pt()||(Y=new P({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:ne,stackParser:L,integrations:[I(),te()],beforeSend:Ft,sendDefaultPii:!1,tracesSampleRate:1}),X=new F,X.setClient(Y),Y.init()))}function Lt(e,t){!X||!Y||(t?X.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):X.captureException(e))}function Rt(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 zt(e,t,n){if(!X||!Y)return n();let r=Date.now()/1e3,i=Rt(32),a=Rt(16),o=`ok`,s=()=>{let n=Date.now()/1e3;X.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 Bt=i.createContext(null),Vt=[],Ht=`https://better-cmdk.com/api/chat`;function Ut({children:e,chatEndpoint:t=Ht,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(()=>{It()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new ee({api:t})},[t,v]),b=N(i.useMemo(()=>y?{transport:y,onError:e=>{Lt(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&&zt(`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 zt(`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 Lt(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??Vt,A=n?.setMessages??b.setMessages,j=n?.addToolApprovalResponse,M=n?.actions,P=Nt({storageKey:o,maxConversations:s,messages:k,setMessages:A}),F=i.useCallback(e=>{P.loadConversation(e),C(`chat`)},[P.loadConversation,C]),I=i.useRef(f);i.useEffect(()=>{let e=I.current;I.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&P.saveCurrentConversation()},[f,k.length,P.saveCurrentConversation]);let L=i.useCallback(()=>{a?.(!1)},[a]),te=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,actions:M,requestClose:L,conversations:P.conversations,currentConversationId:P.currentConversationId,startNewChat:P.startNewChat,loadConversation:F}),[c,C,u,t,f,m,T,E,k,D,O,w,j,M,L,P.conversations,P.currentConversationId,P.startNewChat,F]);return h(Bt.Provider,{value:te,children:e})}function Z(){let e=i.useContext(Bt);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}function Wt({...e}){return h(D.Root,{"data-slot":`dialog`,...e})}function Gt({...e}){return h(D.Trigger,{"data-slot":`dialog-trigger`,...e})}function Kt({...e}){return h(D.Portal,{"data-slot":`dialog-portal`,...e})}function qt({...e}){return h(D.Close,{"data-slot":`dialog-close`,...e})}function Jt({className:t,style:n,...r}){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),style:{position:`fixed`,inset:0,zIndex:50,backgroundColor:`rgb(0 0 0 / 0.5)`,...n},...r})}function Yt({className:t,children:n,showCloseButton:r=!0,...i}){return h(Kt,{"data-slot":`dialog-portal`,children:g(`div`,{className:`bcmdk-root`,children:[h(Jt,{}),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 Xt({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 Zt({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(Be,{variant:`outline`,children:`Close`})})]})}function Qt({className:t,...n}){return h(D.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function $t({className:t,...n}){return h(D.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function en({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 tn({className:t,...n}){return h(`kbd`,{"data-slot":`kbd-group`,className:e(`inline-flex items-center gap-1`,t),...n})}function nn({className:t,...n}){return h(W,{"data-slot":`command`,className:e(`bcmdk-root text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md`,t),...n})}function rn({className:t,children:n,...r}){return h(Kt,{"data-slot":`dialog-portal`,children:h(`div`,{className:`bcmdk-root`,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, oklch(var(--bcmdk-background)) 95%, transparent)`},...r,children:n})})})}function an({className:t,...n}){return h(W.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function Q({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, oklch(var(--bcmdk-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(W.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 on({className:t,...n}){return h(W.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function sn({className:t,style:n,onSelect:r,closeOnSelect:a=!0,...o}){let s=i.useContext(Bt),c=i.useCallback(e=>{r?.(e),a&&s?.requestClose?.()},[r,a,s]);return h(W.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},onSelect:c,...o})}function cn({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(en,{children:e},t)):n})}var ln=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){Lt(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};function un(e){return e instanceof Element?!!e.closest(`input, textarea, select, button, a, [contenteditable='true'], [contenteditable=''], [data-cmdk-mobile-gesture-ignore]`):!1}function dn(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 fn({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.useRef({applied:!1,touchCallout:``,webkitUserSelect:``,userSelect:``});i.useEffect(()=>{g.current=a},[a]);let v=i.useCallback(()=>{if(typeof document>`u`||_.current.applied)return;let{style:e}=document.documentElement;_.current={applied:!0,touchCallout:e.getPropertyValue(`-webkit-touch-callout`),webkitUserSelect:e.getPropertyValue(`-webkit-user-select`),userSelect:e.getPropertyValue(`user-select`)},e.setProperty(`-webkit-touch-callout`,`none`),e.setProperty(`-webkit-user-select`,`none`),e.setProperty(`user-select`,`none`)},[]),y=i.useCallback(()=>{if(typeof document>`u`)return;let e=_.current;if(!e.applied)return;let{style:t}=document.documentElement;e.touchCallout?t.setProperty(`-webkit-touch-callout`,e.touchCallout):t.removeProperty(`-webkit-touch-callout`),e.webkitUserSelect?t.setProperty(`-webkit-user-select`,e.webkitUserSelect):t.removeProperty(`-webkit-user-select`),e.userSelect?t.setProperty(`user-select`,e.userSelect):t.removeProperty(`user-select`),_.current={applied:!1,touchCallout:``,webkitUserSelect:``,userSelect:``}},[]),b=i.useCallback(()=>{let e=m.current;e?.timer!=null&&window.clearTimeout(e.timer),m.current=null,p(!1),y()},[y]);return i.useEffect(()=>{if(!e||t||typeof window>`u`){b();return}let i=e=>{if(e.touches.length!==1||un(e.target))return;let t=e.touches[0];if(!t||!dn(t.clientX,t.clientY,c,l,u,d))return;h.current=Date.now(),v();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){b();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&&b();return}if(e.cancelable&&e.preventDefault(),Math.abs(i)>s){b();return}a<=-r&&(b(),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(14),g.current())},f=()=>{b()},_=()=>{b()},y=e=>{let t=m.current!==null,r=Date.now()-h.current<n+1200,i=dn(e.clientX,e.clientY,c,l,u,d);if(t||r&&i){if(!t&&un(e.target))return;e.preventDefault(),e.stopPropagation()}};return document.addEventListener(`touchstart`,i,{passive:!1}),document.addEventListener(`touchmove`,a,{passive:!1}),document.addEventListener(`touchend`,f,{passive:!0}),document.addEventListener(`touchcancel`,_,{passive:!0}),document.addEventListener(`contextmenu`,y,!0),()=>{document.removeEventListener(`touchstart`,i),document.removeEventListener(`touchmove`,a),document.removeEventListener(`touchend`,f),document.removeEventListener(`touchcancel`,_),document.removeEventListener(`contextmenu`,y,!0),b()}},[e,t,n,r,o,s,c,l,u,d,b,v]),{showHint:f}}function pn(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 mn=e=>{},hn={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},gn={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},_n=i.createContext({isMobile:!1,layout:`keyboard-last`,keyboardInset:0,showQuickActions:!1,quickActionsCount:4});function vn(){return i.useContext(_n)}function yn(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 bn(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 xn(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 Sn({className:t,children:n,corners:r=`xl`,borderColor:a,isMobile:o,keyboardInset:s,onRequestClose:c,onInteractOutside:l,...u}){let d=i.useRef(null),f=i.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(e instanceof HTMLElement&&e.hasAttribute(`cmdk-input`)){e.blur();return}c?.()},[c]),p=e=>{if(e.touches.length!==1)return;let t=e.touches[0];t&&(d.current={x:t.clientX,y:t.clientY})},m=e=>{let t=d.current;if(d.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&&f()},_=e=>{if(l?.(e),e.defaultPrevented)return;let t=e.target;t instanceof HTMLElement&&t.closest(`[data-cmdk-powered-link]`)&&e.preventDefault()};return h(Kt,{"data-slot":`dialog-portal`,children:g(`div`,{className:`bcmdk-root`,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`,style:{position:`fixed`,inset:0,zIndex:40,backgroundColor:`rgb(0 0 0 / 0.35)`,backdropFilter:`blur(1px)`,WebkitBackdropFilter:`blur(1px)`}}),g(`div`,{className:e(`fixed z-50 w-full max-w-[calc(100%-2rem)]`,o?`inset-x-0 bottom-0 max-w-none px-0`:`top-1/3 left-[50%] translate-x-[-50%] translate-y-[-50%]`),style:o?{left:0,right:0,bottom:0,maxWidth:`none`,paddingLeft:0,paddingRight: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`:hn[r],t),style:{"--cmdk-radius":gn[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:gn[r],borderTopRightRadius:gn[r],borderBottomLeftRadius:`0px`,borderBottomRightRadius:`0px`}:{},backgroundColor:`color-mix(in oklch, oklch(var(--bcmdk-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}:{}},...u,onInteractOutside:_,children:[o&&h(`div`,{className:`flex justify-center py-2`,"data-cmdk-mobile-gesture-ignore":!0,onTouchStart:p,onTouchEnd:m,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 pointer-events-auto`,o&&`hidden`),children:h(`a`,{"data-cmdk-powered-link":!0,href:`https://better-cmdk.com`,target:`_blank`,rel:`noopener noreferrer`,className:`pointer-events-auto inline-flex items-center border-2 border-input bg-background px-2 py-0.5 font-mono text-[11px] font-bold uppercase tracking-[0.14em] text-foreground no-underline transition-colors hover:bg-foreground hover:text-background hover:no-underline`,style:{borderRadius:`0 0 0.25rem 0.25rem`,marginRight:`1rem`},children:`BETTER-CMDK`})})]})]})})}const Cn=g(m,{children:[h(En,{placeholder:`Search for actions or ask AI...`,showSendButton:!0}),h(Nn,{children:h($,{})})]});function wn({title:t=`Command Palette`,description:n=`Search for an action to run...`,children:r,className:a,corners:o=`xl`,borderColor:s,actions:c,actionsPlaceholder:l=`Search for actions or ask AI...`,actionsAskAILabel:u=`Ask AI`,mobile:d,...f}){let{mode:p,status:_,switchToCommand:y,messages:b,isEnabled:x,setInputValue:S,inputValue:C}=Z(),w=i.useMemo(()=>yn(d),[d]),T=bn(w.breakpoint,w.enabled),E=w.enabled&&T,D=pn(E&&!!f.open),O=i.useCallback(e=>{e&&S(``),f.onOpenChange?.(e)},[f.onOpenChange,S]),k=i.useCallback(()=>{O(!0)},[O]),A=fn({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(Mn,{actions:c,placeholder:l,askAILabel:u}):typeof r==`function`?r({mode:p,messages:b,status:_,isEnabled:x}):r??Cn,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(Wt,{...f,onOpenChange:O,children:g(Sn,{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(Xt,{className:`sr-only`,children:[h(Qt,{children:t}),h($t,{children:n})]}),h(_n.Provider,{value:j,children:h(W,{"data-slot":`command`,className:e(`bcmdk-root **: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 Tn({chatEndpoint:e=Ht,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,actions:o,actionsPlaceholder:s,actionsAskAILabel:c,mobile:l,...u}){return h(Ut,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(ln,{children:h(wn,{onOpenChange:r,actions:o,actionsPlaceholder:s,actionsAskAILabel:c,mobile:l,...u})})})}function En({className:t,showSendButton:n=!1,...r}){let{mode:a,inputValue:o,setInputValue:s,sendMessage:c,isLoading:l,switchToChat:u,startNewChat:d}=Z(),{isMobile:f,layout:p,keyboardInset:m}=vn(),[_,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(W.Input,{"data-slot":`command-input`,ref:x,value:o,onValueChange:s,onKeyDown:C,className:e(`placeholder:text-muted-foreground flex h-10 w-full appearance-none border-0 bg-transparent py-3 text-sm shadow-none 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}=Z(),{isMobile:u}=vn(),d=q(e=>e.filtered.count),f=()=>{if(c)if(i.trim()){let e=lt(`ask-ai`,i.trim())>0;d===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(W.Group,{forceMount:!0,children:g(W.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(en,{children:`⌘`}),h(en,{children:`↵`})]})]})}):h(W.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function Dn(e){return e.inputSchema==null}function On(e){return e.label??e.name}function kn(e){let t=[...e.keywords??[]];return e.label&&e.label!==e.name&&t.push(e.label),e.description&&t.push(e.description),t.length>0?t:void 0}function An(){let{sendMessage:e,startNewChat:t,switchToChat:n}=Z();return i.useCallback(r=>{let i=()=>{t(),n(),e(On(r))};if(!Dn(r)){i();return}if(r.onSelect){r.onSelect();return}r.execute({})},[e,t,n])}function jn(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 Mn({actions:t,placeholder:n,askAILabel:r}){let{inputValue:a,mode:o}=Z(),s=An(),{isMobile:c,layout:l,showQuickActions:u,quickActionsCount:d}=vn(),f=jn(t),p=c&&l===`keyboard-last`&&u&&o===`command`&&a.length===0,_=p?t.filter(e=>Dn(e)&&!e.disabled).slice(0,d):[],v=new Set(_.map(e=>e.name)),y=t=>{let n=On(t);return g(sn,{value:t.name,keywords:kn(t),disabled:t.disabled,onSelect:()=>s(t),className:e(c&&`min-h-12 py-3`),children:[t.icon,n,t.shortcut&&!c&&h(cn,{children:t.shortcut})]},t.name)};return g(m,{children:[h(En,{placeholder:n,showSendButton:!0}),g(Nn,{children:[p&&_.length>0&&h(Q,{heading:`Quick Actions`,children:_.map(e=>y(e))}),f.map((e,t)=>{let n=p?e.items.filter(e=>!v.has(e.name)):e.items;if(n.length===0)return null;let r=n.map(e=>y(e));return e.heading?h(Q,{heading:e.heading,children:r},e.heading):h(i.Fragment,{children:r},`__ungrouped_${t}`)}),h($,{label:r})]})]})}function Nn({className:t,children:n,actions:r,actionsHeading:a=`Actions`,style:o,...s}){let{mode:c,status:l,messages:u,sendMessage:d,addToolApprovalResponse:f,actions:p,conversations:m,loadConversation:_,inputValue:v}=Z(),{isMobile:y,layout:b,keyboardInset:x}=vn(),C=An(),w=i.useCallback(e=>d(e.text),[d]),T=f??mn;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`,y&&`px-2`,t),children:u.length===0?h(Ue,{}):g(Ve,{style:{flex:`1 1 0%`,minHeight:0},children:[h(`div`,{className:`px-3 py-2 space-y-4`,children:h(Ie,{messages:u,sendMessage:w,addToolApprovalResponse:T})}),l===`streaming`&&h(He,{})]})});let E=i.Children.toArray(n),D=[],O=[];E.forEach(e=>{i.isValidElement(e)&&(e.type===$||e.type.displayName===`CommandEmpty`)?D.push(e):i.isValidElement(e)&&e.type===an||O.push(e)});let k=r??p,A=v.length>0||y&&b===`keyboard-last`,j=y?`calc(100% - var(--cmdk-input-row-height, 3.5rem))`:`calc(45vh - 2.75rem)`,M={overscrollBehavior:`contain`,paddingBottom:x>0?`${x+8}px`:y?`env(safe-area-inset-bottom)`:void 0,...o};return h(re.div,{initial:!1,animate:{height:A?j:0},transition:{type:`spring`,duration:.25,bounce:0},className:e(`order-1 min-h-0 overflow-hidden px-3`,y&&`px-2`),children:g(W.List,{"data-slot":`command-list`,className:e(`overflow-x-hidden overflow-y-auto overscroll-contain pt-2 h-full`,y&&`pt-1`,t),style:M,...s,children:[O,m.length>0&&h(Q,{heading:`Recent Chats`,children:m.slice(0,5).map(t=>g(sn,{value:`chat-history-${t.id}`,keywords:[t.title],onSelect:()=>_(t.id),className:e(y&&`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:xn(t.updatedAt)})]},t.id))}),k&&k.length>0&&h(Q,{heading:a,children:k.map(t=>g(sn,{value:On(t),keywords:kn(t),disabled:t.disabled,onSelect:()=>C(t),className:e(y&&`min-h-12 py-3`),children:[t.icon,On(t),t.shortcut&&!y&&h(cn,{children:t.shortcut})]},t.name))}),D]})})}$.displayName=`CommandEmpty`;export{ve as AssistantFormRenderer,Ie as AssistantMessages,Be as Button,Ue as ChatEmpty,He as ChatLoading,Ve as ChatMessageList,Se as Collapsible,we as CollapsibleContent,Ce as CollapsibleTrigger,nn as Command,Sn as CommandContent,Tn as CommandDialog,Tn as CommandMenu,rn as CommandDialogContent,$ as CommandEmpty,Q as CommandGroup,En as CommandInput,sn as CommandItem,Nn as CommandList,Bt as CommandMenuContext,Ut as CommandMenuProvider,on as CommandSeparator,cn as CommandShortcut,ie as Confirmation,se as ConfirmationAccepted,ue as ConfirmationAction,le as ConfirmationActions,ce as ConfirmationRejected,oe as ConfirmationRequest,ae as ConfirmationTitle,Wt as Dialog,qt as DialogClose,Yt as DialogContent,$t as DialogDescription,Zt as DialogFooter,Xt as DialogHeader,Jt as DialogOverlay,Kt as DialogPortal,Qt as DialogTitle,Gt as DialogTrigger,en as Kbd,tn as KbdGroup,ye as Message,be as MessageContent,xe as MessageResponse,De as Task,ke as TaskContent,Ee as TaskItem,Te as TaskItemFile,Oe as TaskTrigger,ze as buttonVariants,e as cn,he as defaultFormRegistry,Nt as useChatHistory,Z 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{useChat as N}from"@ai-sdk/react";import{DefaultChatTransport as ee}from"ai";import{BrowserClient as P,Scope as F,dedupeIntegration as I,defaultStackParser as L,linkedErrorsIntegration as te,makeFetchTransport as ne}from"@sentry/browser";import{motion as re}from"motion/react";const R=a(null);function z(){let e=c(R);if(!e)throw Error(`Confirmation components must be used within Confirmation`);return e}function ie({approval:t,state:n,style:r,...i}){return!t||n===`input-streaming`||n===`input-available`?null:h(R.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 ae(e){return h(`p`,{id:`confirmation-title`,"data-slot":`confirmation-title`,className:`text-sm font-medium`,...e})}function oe({children:e}){let{state:t}=z();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-request`,children:e}):null}function se({children:e}){let{approval:t,state:n}=z();return!t?.approved||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-accepted`,children:e})}function ce({children:e}){let{approval:t,state:n}=z();return t?.approved!==!1||n!==`approval-responded`&&n!==`output-denied`&&n!==`output-available`?null:h(`div`,{"data-slot":`confirmation-rejected`,children:e})}function le(e){let{state:t}=z();return t===`approval-requested`?h(`div`,{"data-slot":`confirmation-actions`,className:`flex items-center justify-end gap-2 self-end`,...e}):null}function ue({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 B(e){e.stopPropagation()}function de({element:t,children:n,onAction:r}){let{id:i=`form`,title:a,submitLabel:o=`Submit`}=t.props??{},s=e=>{e.preventDefault();let t=new FormData(e.currentTarget),n={};t.forEach((e,t)=>{typeof e==`string`&&(n[t]=e)}),r?.({name:`submit`,params:{formId:i,data:n}})};return g(`div`,{"data-slot":`form-card`,className:e(`w-full rounded-lg border bg-card text-card-foreground shadow-sm`),children:[a&&h(`div`,{className:`flex flex-col space-y-1.5 p-4 pb-3`,children:h(`h3`,{className:`text-base font-semibold leading-none tracking-tight`,children:a})}),h(`div`,{className:e(`p-4`,a?``:`pt-4`),children:g(`form`,{onSubmit:s,className:`space-y-4`,children:[n,g(`div`,{className:`flex justify-end gap-2 pt-2`,children:[h(`button`,{type:`button`,className:e(`inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors`,`hover:bg-accent hover:text-accent-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r?.({name:`cancel`,params:{formId:i}}),children:`Cancel`}),h(`button`,{type:`submit`,className:e(`inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow transition-colors`,`hover:bg-primary/90`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:pointer-events-none disabled:opacity-50`),children:o})]})]})})]})}function fe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{id:n,name:n,type:`text`,placeholder:i,required:a,defaultValue:o,autoComplete:`off`,onKeyDown:B,onKeyUp:B,className:e(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function pe({element:t}){let{name:n=`field`,label:r=`Field`,placeholder:i,required:a,defaultValue:o,rows:s=3}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,a&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`textarea`,{id:n,name:n,placeholder:i,required:a,defaultValue:o,rows:s,onKeyDown:B,onKeyUp:B,className:e(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`disabled:cursor-not-allowed disabled:opacity-50`)})]})}function me({element:t}){let{name:n=`date`,label:r=`Date`,required:i,defaultValue:a,min:o,max:s}=t.props??{};return g(`div`,{className:`space-y-1.5`,children:[g(`label`,{htmlFor:n,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[r,i&&h(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),h(`input`,{type:`date`,id:n,name:n,required:i,defaultValue:a,min:o,max:s,onKeyDown:B,onKeyUp:B,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 he={Form:de,TextField:fe,TextArea:pe,DateField:me},ge=p.object({formId:p.string(),data:p.record(p.string(),p.string())}),_e=p.object({formId:p.string()});function ve({ui:e,context:r,onSubmit:i,onCancel:a,registry:o=he}){let c=s(e=>{let t=ge.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=_e.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 ye({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 be({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 xe=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 Se({...e}){return h(T.Root,{"data-slot":`collapsible`,...e})}function Ce({...e}){return h(T.CollapsibleTrigger,{"data-slot":`collapsible-trigger`,...e})}function we({...e}){return h(T.CollapsibleContent,{"data-slot":`collapsible-content`,...e})}function Te({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 Ee({children:e,...t}){return h(`div`,{"data-slot":`task-item`,className:`text-sm text-muted-foreground`,...t,children:e})}function De({defaultOpen:e=!0,...t}){return h(Se,{"data-slot":`task`,defaultOpen:e,...t})}function Oe({children:e,title:t,icon:n,...r}){return h(Ce,{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 ke({children:t,...n}){return h(we,{"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 Ae=p.object({name:p.string(),options:p.record(p.string(),p.unknown()).optional()}),je=p.object({actions:p.array(Ae).optional()}),Me=p.object({id:p.string(),approved:p.boolean().optional()}),Ne=p.object({type:p.string(),props:p.record(p.string(),p.unknown()).default({}),children:p.array(p.string()).optional(),parentKey:p.string().nullable().optional()}),Pe=p.object({ui:p.object({elements:p.record(p.string(),Ne)}),context:p.record(p.string(),p.unknown()).optional()});function Fe(e){return e.name}function Ie({messages:e,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r=Fe}){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(ye,{from:e.role,children:h(be,{children:e.parts.map((i,a)=>h(Le,{part:i,messageId:e.id,partIndex:a,isLastMessage:o,sendMessage:t,addToolApprovalResponse:n,getActionDescription:r},`${e.id}-${a}`))})},e.id)})})}function Le({part:e,messageId:t,partIndex:n,isLastMessage:r,sendMessage:i,addToolApprovalResponse:a,getActionDescription:o}){if(e.type===`text`)return h(xe,{children:e.text});if(e.type===`tool-performActions`){let r=`input`in e?e.input:void 0,i=je.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=Me.safeParse(u),f=d.success?d.data:void 0;return f&&l?g(ie,{state:l,approval:f,children:[h(ae,{children:c===1?`Confirm action`:`Confirm ${c} actions`}),h(oe,{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(se,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action approved`:`${c} actions approved`})}),h(ce,{children:h(`span`,{className:`text-sm text-muted-foreground`,children:c===1?`Action cancelled`:`${c} actions cancelled`})}),g(le,{children:[h(ue,{variant:`outline`,onClick:()=>a({id:f.id,approved:!1}),children:`Deny`}),h(ue,{onClick:()=>a({id:f.id,approved:!0}),children:`Approve`})]})]}):g(De,{defaultOpen:!1,children:[h(Oe,{title:c===1?`Performing 1 action`:`Performing ${c} actions`}),h(ke,{children:s.map((e,r)=>h(Ee,{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(Re,{output:e.output,sendMessage:i}):null}function Re({output:e,sendMessage:t}){let n=i.useMemo(()=>{let t=Pe.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(ve,{ui:n.ui,context:n.context,onSubmit:a,onCancel:o}):null}const ze=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 Be({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(ze({variant:n,size:r,className:t})),...a})}function Ve({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 He({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 Ue({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 We=1,Ge=.9,Ke=.8,qe=.17,Je=.1,Ye=.999,Xe=.9999,Ze=.99,Qe=/[\\\/_+.#"@\[\(\{&]/,$e=/[\\\/_+.#"@\[\(\{&]/g,et=/[\s-]/,tt=/[\s-]/g;function nt(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?We:Ze;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=nt(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=We:Qe.test(e.charAt(l-1))?(d*=Ke,p=e.slice(i,l-1).match($e),p&&i>0&&(d*=Ye**+p.length)):et.test(e.charAt(l-1))?(d*=Ge,m=e.slice(i,l-1).match(tt),m&&i>0&&(d*=Ye**+m.length)):(d*=qe,i>0&&(d*=Ye**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Xe)),(d<Je&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=nt(e,t,n,r,l+1,a+2,o),f*Je>d&&(d=f*Je)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function rt(e){return e.toLowerCase().replace(tt,` `)}function it(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,nt(e,t,rt(e),rt(t),0,0,{})}const V=`[cmdk-group=""]`,at=`[cmdk-group-items=""]`,ot=`[cmdk-item=""]`,st=`${ot}:not([aria-disabled="true"])`,ct=`cmdk-item-select`,H=`data-value`,lt=(e,t,n)=>it(e,t,n),ut=i.createContext(void 0),U=()=>{let e=i.useContext(ut);if(!e)throw Error(`CommandContext is missing a provider`);return e},dt=i.createContext(void 0),ft=()=>{let e=i.useContext(dt);if(!e)throw Error(`StoreContext is missing a provider`);return e},pt=i.createContext(void 0),mt=i.forwardRef((e,t)=>{let n=K(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=K(()=>new Set),a=K(()=>new Map),o=K(()=>new Map),s=K(()=>new Set),c=Tt(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=Dt();G(()=>{if(d!==void 0){let e=d.trim();n.current.value=e,E.emit()}},[d]),G(()=>{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??lt;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(at);if(t){let n=e.parentElement===t?e:e.closest(`${at} > *`);n&&t.appendChild(n)}else{if(!r)return;let t=e.parentElement===r?e:e.closest(`${at} > *`);t&&r.appendChild(t)}}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=w.current?.querySelector(`${V}[cmdk-group-id="${e[0]}"]`);t?.parentElement&&t.parentElement.appendChild(t)});let i=new Set(t.map(e=>e[0]));w.current?.querySelectorAll(`${V}[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(H);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(V)?.querySelector(`[cmdk-group-heading=""]`)?.scrollIntoView({block:`nearest`}),e.scrollIntoView({block:`nearest`}))}function P(){return w.current?.querySelector(`${ot}[aria-selected="true"]`)}function F(){return Array.from(w.current?.querySelectorAll(st)||[])}function I(e){let t=F()[e];t&&E.setState(`value`,t.getAttribute(H)??``)}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(H)??``)}function te(e){let t=P()?.closest(V),n;for(;t&&!n;)t=e>0?Ct(t,V):wt(t,V),n=t?.querySelector(st);n?E.setState(`value`,n.getAttribute(H)??``):L(e)}let ne=()=>I(F().length-1),re=e=>{e.preventDefault(),e.metaKey?ne():e.altKey?te(1):L(1)},R=e=>{e.preventDefault(),e.metaKey?I(0):e.altKey?te(-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&&re(e);break;case`ArrowDown`:re(e);break;case`p`:case`k`:y&&e.ctrlKey&&R(e);break;case`ArrowUp`:R(e);break;case`Home`:e.preventDefault(),I(0);break;case`End`:e.preventDefault(),ne();break;case`Enter`:{e.preventDefault();let t=P();if(t){let e=new Event(ct);t.dispatchEvent(e)}}}},children:[h(`label`,{"cmdk-label":``,htmlFor:D.inputId,id:D.labelId,style:kt,children:l}),J(e,e=>h(dt.Provider,{value:E,children:h(ut.Provider,{value:D,children:e})}))]})}),ht=i.forwardRef((e,t)=>{let n=j(),r=i.useRef(null),a=i.useContext(pt),o=U(),s=Tt(e),c=s.current?.forceMount??a?.forceMount;G(()=>o.item(n,a?.id),[c]);let l=Et(n,r,[e.value,e.children,r],e.keywords),u=ft(),d=q(e=>e.value&&e.value===l.current),f=q(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(ct,p),()=>t.removeEventListener(ct,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})}),gt=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=U(),f=q(e=>a||d.filter()===!1?!0:e.search?e.filtered.groups.has(s):!0);G(()=>d.group(s),[]),Et(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}),J(e,e=>h(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?u:void 0,children:h(pt.Provider,{value:p,children:e})}))]})}),_t=i.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,a=i.useRef(null),o=q(e=>!e.search);return!n&&!o?null:h(A.div,{ref:M(a,t),...r,"cmdk-separator":``,role:`separator`})}),vt=i.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,a=e.value!=null,o=ft(),s=q(e=>e.search),c=q(e=>e.selectedItemId),l=U();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)}})}),yt=i.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...a}=e,o=i.useRef(null),s=i.useRef(null),c=q(e=>e.selectedItemId),l=U();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:J(e,e=>h(`div`,{ref:M(s,l.listInnerRef),"cmdk-list-sizer":``,children:e}))})}),bt=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(mt,{ref:t,...s})})]})})}),xt=i.forwardRef((e,t)=>q(e=>e.filtered.count===0)?h(A.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),St=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:J(e,e=>h(`div`,{"aria-hidden":!0,children:e}))})}),W=Object.assign(mt,{List:yt,Item:ht,Input:vt,Group:gt,Separator:_t,Dialog:bt,Empty:xt,Loading:St});function Ct(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wt(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Tt(e){let t=i.useRef(e);return G(()=>{t.current=e}),t}const G=typeof window>`u`?i.useEffect:i.useLayoutEffect;function K(e){let t=i.useRef(void 0);return t.current===void 0&&(t.current=e()),t}function q(e){let t=ft(),n=()=>e(t.snapshot());return i.useSyncExternalStore(t.subscribe,n,n)}function Et(e,t,n,r=[]){let a=i.useRef(``),o=U();return G(()=>{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(H,i),a.current=i}),a}const Dt=()=>{let[e,t]=i.useState(),n=K(()=>new Map);return G(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Ot(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function J({asChild:e,children:t},n){if(e&&i.isValidElement(t)){let e=t;return i.cloneElement(Ot(e),{ref:e.ref},n(e.props.children))}return n(t)}const kt={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function At(){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 Mt(e){return typeof e!=`object`||!e||!(`version`in e)||e.version!==1||!(`conversations`in e)||!Array.isArray(e.conversations)?null:e}function Nt({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=Mt(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(At())},[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 Y=null,X=null;function Pt(){try{return typeof process<`u`&&process.env?.BETTER_CMDK_TELEMETRY_DISABLED===`1`}catch{return!1}}function Ft(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 It(){typeof window>`u`||Y===null&&(Pt()||(Y=new P({dsn:`https://7d9fc7e14e8769805297d46569e33c05@o4510706172755968.ingest.us.sentry.io/4510846832017408`,transport:ne,stackParser:L,integrations:[I(),te()],beforeSend:Ft,sendDefaultPii:!1,tracesSampleRate:1}),X=new F,X.setClient(Y),Y.init()))}function Lt(e,t){!X||!Y||(t?X.captureException(e,{captureContext:e=>(e.setExtras(t),e)}):X.captureException(e))}function Rt(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 zt(e,t,n){if(!X||!Y)return n();let r=Date.now()/1e3,i=Rt(32),a=Rt(16),o=`ok`,s=()=>{let n=Date.now()/1e3;X.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 Bt=i.createContext(null),Vt=[],Ht=`https://better-cmdk.com/api/chat`;function Ut({children:e,chatEndpoint:t=Ht,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(()=>{It()},[]);let y=i.useMemo(()=>{if(!(v||!t))return new ee({api:t})},[t,v]),b=N(i.useMemo(()=>y?{transport:y,onError:e=>{Lt(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&&zt(`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 zt(`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 Lt(e,{source:`sendMessage`}),e}})},[b,y]),O=f===`submitted`||f===`streaming`,k=n?n.messages:b.messages??Vt,A=n?.setMessages??b.setMessages,j=n?.addToolApprovalResponse,M=n?.actions,P=Nt({storageKey:o,maxConversations:s,messages:k,setMessages:A}),F=i.useCallback(e=>{P.loadConversation(e),C(`chat`)},[P.loadConversation,C]),I=i.useRef(f);i.useEffect(()=>{let e=I.current;I.current=f,(e===`streaming`||e===`submitted`)&&f===`idle`&&k.length>0&&P.saveCurrentConversation()},[f,k.length,P.saveCurrentConversation]);let L=i.useCallback(()=>{a?.(!1)},[a]),te=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,actions:M,requestClose:L,conversations:P.conversations,currentConversationId:P.currentConversationId,startNewChat:P.startNewChat,loadConversation:F}),[c,C,u,t,f,m,T,E,k,D,O,w,j,M,L,P.conversations,P.currentConversationId,P.startNewChat,F]);return h(Bt.Provider,{value:te,children:e})}function Z(){let e=i.useContext(Bt);if(!e)throw Error(`useCommandMenuContext must be used within a CommandMenuProvider`);return e}function Wt({...e}){return h(D.Root,{"data-slot":`dialog`,...e})}function Gt({...e}){return h(D.Trigger,{"data-slot":`dialog-trigger`,...e})}function Kt({...e}){return h(D.Portal,{"data-slot":`dialog-portal`,...e})}function qt({...e}){return h(D.Close,{"data-slot":`dialog-close`,...e})}function Jt({className:t,style:n,...r}){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),style:{position:`fixed`,inset:0,zIndex:50,backgroundColor:`rgb(0 0 0 / 0.5)`,...n},...r})}function Yt({className:t,children:n,showCloseButton:r=!0,...i}){return h(Kt,{"data-slot":`dialog-portal`,children:g(`div`,{className:`bcmdk-root`,children:[h(Jt,{}),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 Xt({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 Zt({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(Be,{variant:`outline`,children:`Close`})})]})}function Qt({className:t,...n}){return h(D.Title,{"data-slot":`dialog-title`,className:e(`text-lg leading-none font-semibold`,t),...n})}function $t({className:t,...n}){return h(D.Description,{"data-slot":`dialog-description`,className:e(`text-muted-foreground text-sm`,t),...n})}function en({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 tn({className:t,...n}){return h(`kbd`,{"data-slot":`kbd-group`,className:e(`inline-flex items-center gap-1`,t),...n})}function nn({className:t,...n}){return h(W,{"data-slot":`command`,className:e(`bcmdk-root text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md`,t),...n})}function rn({className:t,children:n,...r}){return h(Kt,{"data-slot":`dialog-portal`,children:h(`div`,{className:`bcmdk-root`,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, oklch(var(--bcmdk-background)) 95%, transparent)`},...r,children:n})})})}function an({className:t,...n}){return h(W.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,t),...n})}function Q({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, oklch(var(--bcmdk-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(W.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 on({className:t,...n}){return h(W.Separator,{"data-slot":`command-separator`,className:e(`bg-border -mx-1 h-px`,t),...n})}function sn({className:t,style:n,onSelect:r,closeOnSelect:a=!0,...o}){let s=i.useContext(Bt),c=i.useCallback(e=>{r?.(e),a&&s?.requestClose?.()},[r,a,s]);return h(W.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},onSelect:c,...o})}function cn({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(en,{children:e},t)):n})}var ln=class extends i.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){Lt(e,{componentStack:t.componentStack??void 0})}render(){return this.state.hasError?null:this.props.children}};function un(e){return e instanceof Element?!!e.closest(`input, textarea, select, button, a, [contenteditable='true'], [contenteditable=''], [data-cmdk-mobile-gesture-ignore]`):!1}function dn(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 fn({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.useRef({applied:!1,touchCallout:``,webkitUserSelect:``,userSelect:``});i.useEffect(()=>{g.current=a},[a]);let v=i.useCallback(()=>{if(typeof document>`u`||_.current.applied)return;let{style:e}=document.documentElement;_.current={applied:!0,touchCallout:e.getPropertyValue(`-webkit-touch-callout`),webkitUserSelect:e.getPropertyValue(`-webkit-user-select`),userSelect:e.getPropertyValue(`user-select`)},e.setProperty(`-webkit-touch-callout`,`none`),e.setProperty(`-webkit-user-select`,`none`),e.setProperty(`user-select`,`none`)},[]),y=i.useCallback(()=>{if(typeof document>`u`)return;let e=_.current;if(!e.applied)return;let{style:t}=document.documentElement;e.touchCallout?t.setProperty(`-webkit-touch-callout`,e.touchCallout):t.removeProperty(`-webkit-touch-callout`),e.webkitUserSelect?t.setProperty(`-webkit-user-select`,e.webkitUserSelect):t.removeProperty(`-webkit-user-select`),e.userSelect?t.setProperty(`user-select`,e.userSelect):t.removeProperty(`user-select`),_.current={applied:!1,touchCallout:``,webkitUserSelect:``,userSelect:``}},[]),b=i.useCallback(()=>{let e=m.current;e?.timer!=null&&window.clearTimeout(e.timer),m.current=null,p(!1),y()},[y]);return i.useEffect(()=>{if(!e||t||typeof window>`u`){b();return}let i=e=>{if(e.touches.length!==1||un(e.target))return;let t=e.touches[0];if(!t||!dn(t.clientX,t.clientY,c,l,u,d))return;h.current=Date.now(),v();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){b();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&&b();return}if(e.cancelable&&e.preventDefault(),Math.abs(i)>s){b();return}a<=-r&&(b(),typeof navigator<`u`&&`vibrate`in navigator&&navigator.vibrate(14),g.current())},f=()=>{b()},_=()=>{b()},y=e=>{let t=m.current!==null,r=Date.now()-h.current<n+1200,i=dn(e.clientX,e.clientY,c,l,u,d);if(t||r&&i){if(!t&&un(e.target))return;e.preventDefault(),e.stopPropagation()}};return document.addEventListener(`touchstart`,i,{passive:!1}),document.addEventListener(`touchmove`,a,{passive:!1}),document.addEventListener(`touchend`,f,{passive:!0}),document.addEventListener(`touchcancel`,_,{passive:!0}),document.addEventListener(`contextmenu`,y,!0),()=>{document.removeEventListener(`touchstart`,i),document.removeEventListener(`touchmove`,a),document.removeEventListener(`touchend`,f),document.removeEventListener(`touchcancel`,_),document.removeEventListener(`contextmenu`,y,!0),b()}},[e,t,n,r,o,s,c,l,u,d,b,v]),{showHint:f}}function pn(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 mn=e=>{},hn={none:`rounded-none`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`},gn={none:`0px`,sm:`0.125rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},_n=i.createContext({isMobile:!1,layout:`keyboard-last`,keyboardInset:0,showQuickActions:!1,quickActionsCount:4});function vn(){return i.useContext(_n)}function yn(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 bn(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 xn(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 Sn({className:t,children:n,corners:r=`xl`,borderColor:a,isMobile:o,keyboardInset:s,onRequestClose:c,onInteractOutside:l,...u}){let d=i.useRef(null),f=i.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(e instanceof HTMLElement&&e.hasAttribute(`cmdk-input`)){e.blur();return}c?.()},[c]),p=e=>{if(e.touches.length!==1)return;let t=e.touches[0];t&&(d.current={x:t.clientX,y:t.clientY})},m=e=>{let t=d.current;if(d.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&&f()},_=e=>{if(l?.(e),e.defaultPrevented)return;let t=e.target;t instanceof HTMLElement&&t.closest(`[data-cmdk-powered-link]`)&&e.preventDefault()};return h(Kt,{"data-slot":`dialog-portal`,children:g(`div`,{className:`bcmdk-root`,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`,style:{position:`fixed`,inset:0,zIndex:40,backgroundColor:`rgb(0 0 0 / 0.35)`,backdropFilter:`blur(1px)`,WebkitBackdropFilter:`blur(1px)`}}),g(`div`,{className:e(`fixed z-50 w-full max-w-[calc(100%-2rem)]`,o?`inset-x-0 bottom-0 max-w-none px-0`:`top-1/3 left-[50%] translate-x-[-50%] translate-y-[-50%]`),style:o?{left:0,right:0,bottom:0,maxWidth:`none`,paddingLeft:0,paddingRight: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`:hn[r],t),style:{"--cmdk-radius":gn[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:gn[r],borderTopRightRadius:gn[r],borderBottomLeftRadius:`0px`,borderBottomRightRadius:`0px`}:{},backgroundColor:`color-mix(in oklch, oklch(var(--bcmdk-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}:{}},...u,onInteractOutside:_,children:[o&&h(`div`,{className:`flex justify-center py-2`,"data-cmdk-mobile-gesture-ignore":!0,onTouchStart:p,onTouchEnd:m,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 pointer-events-auto`,o&&`hidden`),children:h(`a`,{"data-cmdk-powered-link":!0,href:`https://better-cmdk.com`,target:`_blank`,rel:`noopener noreferrer`,className:`pointer-events-auto inline-flex items-center border-2 border-input bg-background px-2 py-0.5 font-mono text-[11px] font-bold uppercase tracking-[0.14em] text-foreground no-underline transition-colors hover:bg-foreground hover:text-background hover:no-underline`,style:{borderRadius:`0 0 0.25rem 0.25rem`,marginRight:`1rem`},children:`BETTER-CMDK`})})]})]})})}const Cn=g(m,{children:[h(En,{placeholder:`Search for actions or ask AI...`,showSendButton:!0}),h(Nn,{children:h($,{})})]});function wn({title:t=`Command Palette`,description:n=`Search for an action to run...`,children:r,className:a,corners:o=`xl`,borderColor:s,actions:c,actionsPlaceholder:l=`Search for actions or ask AI...`,actionsAskAILabel:u=`Ask AI`,mobile:d,...f}){let{mode:p,status:_,switchToCommand:y,messages:b,isEnabled:x,setInputValue:S,inputValue:C}=Z(),w=i.useMemo(()=>yn(d),[d]),T=bn(w.breakpoint,w.enabled),E=w.enabled&&T,D=pn(E&&!!f.open),O=i.useCallback(e=>{e&&S(``),f.onOpenChange?.(e)},[f.onOpenChange,S]),k=i.useCallback(()=>{O(!0)},[O]),A=fn({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(Mn,{actions:c,placeholder:l,askAILabel:u}):typeof r==`function`?r({mode:p,messages:b,status:_,isEnabled:x}):r??Cn,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(Wt,{...f,onOpenChange:O,children:g(Sn,{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(Xt,{className:`sr-only`,children:[h(Qt,{children:t}),h($t,{children:n})]}),h(_n.Provider,{value:j,children:h(W,{"data-slot":`command`,className:e(`bcmdk-root **: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 Tn({chatEndpoint:e=Ht,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,actions:o,actionsPlaceholder:s,actionsAskAILabel:c,mobile:l,...u}){return h(Ut,{chatEndpoint:e,chat:t,onModeChange:n,onOpenChange:r,historyStorageKey:i,maxConversations:a,children:h(ln,{children:h(wn,{onOpenChange:r,actions:o,actionsPlaceholder:s,actionsAskAILabel:c,mobile:l,...u})})})}function En({className:t,showSendButton:n=!1,...r}){let{mode:a,inputValue:o,setInputValue:s,sendMessage:c,isLoading:l,switchToChat:u,startNewChat:d}=Z(),{isMobile:f,layout:p,keyboardInset:m}=vn(),[_,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(W.Input,{"data-slot":`command-input`,ref:x,value:o,onValueChange:s,onKeyDown:C,className:e(`placeholder:text-muted-foreground flex h-10 w-full appearance-none border-0 bg-transparent py-3 text-sm shadow-none 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}=Z(),{isMobile:u}=vn(),d=q(e=>e.filtered.count),f=()=>{if(c)if(i.trim()){let e=lt(`ask-ai`,i.trim())>0;d===0&&!e?(l(),o(),s(i)):(o(),a(``))}else o()};return c?h(W.Group,{forceMount:!0,children:g(W.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(en,{children:`⌘`}),h(en,{children:`↵`})]})]})}):h(W.Empty,{"data-slot":`command-empty`,className:e(`text-muted-foreground py-6 text-center text-sm`,n),children:`No results found.`})}function Dn(e){return!(`inputSchema`in e)}function On(e){return e.label??e.name}function kn(e){let t=[...e.keywords??[]];return e.label&&e.label!==e.name&&t.push(e.label),e.description&&t.push(e.description),t.length>0?t:void 0}function An(){let{sendMessage:e,startNewChat:t,switchToChat:n}=Z();return i.useCallback(r=>{let i=Dn(r),a=()=>{t(),n(),e(On(r))};if(!i){a();return}if(r.onSelect){r.onSelect();return}r.execute({})},[e,t,n])}function jn(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 Mn({actions:t,placeholder:n,askAILabel:r}){let{inputValue:a,mode:o}=Z(),s=An(),{isMobile:c,layout:l,showQuickActions:u,quickActionsCount:d}=vn(),f=jn(t),p=c&&l===`keyboard-last`&&u&&o===`command`&&a.length===0,_=p?t.filter(e=>Dn(e)&&!e.disabled).slice(0,d):[],v=new Set(_.map(e=>e.name)),y=t=>{let n=On(t),r=Dn(t);return g(sn,{value:t.name,keywords:kn(t),disabled:t.disabled,closeOnSelect:r,onSelect:()=>s(t),className:e(c&&`min-h-12 py-3`),children:[t.icon,n,t.shortcut&&!c&&h(cn,{children:t.shortcut})]},t.name)};return g(m,{children:[h(En,{placeholder:n,showSendButton:!0}),g(Nn,{children:[p&&_.length>0&&h(Q,{heading:`Quick Actions`,children:_.map(e=>y(e))}),f.map((e,t)=>{let n=p?e.items.filter(e=>!v.has(e.name)):e.items;if(n.length===0)return null;let r=n.map(e=>y(e));return e.heading?h(Q,{heading:e.heading,children:r},e.heading):h(i.Fragment,{children:r},`__ungrouped_${t}`)}),h($,{label:r})]})]})}function Nn({className:t,children:n,actions:r,actionsHeading:a=`Actions`,style:o,...s}){let{mode:c,status:l,messages:u,sendMessage:d,addToolApprovalResponse:f,conversations:p,loadConversation:m,inputValue:_}=Z(),{isMobile:v,layout:y,keyboardInset:b}=vn(),x=An(),C=i.useCallback(e=>d(e.text),[d]),w=f??mn;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`,v&&`px-2`,t),children:u.length===0?h(Ue,{}):g(Ve,{style:{flex:`1 1 0%`,minHeight:0},children:[h(`div`,{className:`px-3 py-2 space-y-4`,children:h(Ie,{messages:u,sendMessage:C,addToolApprovalResponse:w})}),l===`streaming`&&h(He,{})]})});let T=i.Children.toArray(n),E=[],D=[];T.forEach(e=>{i.isValidElement(e)&&(e.type===$||e.type.displayName===`CommandEmpty`)?E.push(e):i.isValidElement(e)&&e.type===an||D.push(e)});let O=r,k=_.length>0||v&&y===`keyboard-last`,A=v?`calc(100% - var(--cmdk-input-row-height, 3.5rem))`:`calc(45vh - 2.75rem)`,j={overscrollBehavior:`contain`,paddingBottom:b>0?`${b+8}px`:v?`env(safe-area-inset-bottom)`:void 0,...o};return h(re.div,{initial:!1,animate:{height:k?A:0},transition:{type:`spring`,duration:.25,bounce:0},className:e(`order-1 min-h-0 overflow-hidden px-3`,v&&`px-2`),children:g(W.List,{"data-slot":`command-list`,className:e(`overflow-x-hidden overflow-y-auto overscroll-contain pt-2 h-full`,v&&`pt-1`,t),style:j,...s,children:[D,p.length>0&&h(Q,{heading:`Recent Chats`,children:p.slice(0,5).map(t=>g(sn,{value:`chat-history-${t.id}`,keywords:[t.title],onSelect:()=>m(t.id),closeOnSelect:!1,className:e(v&&`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:xn(t.updatedAt)})]},t.id))}),O&&O.length>0&&h(Q,{heading:a,children:O.map(t=>g(sn,{value:On(t),keywords:kn(t),disabled:t.disabled,closeOnSelect:Dn(t),onSelect:()=>x(t),className:e(v&&`min-h-12 py-3`),children:[t.icon,On(t),t.shortcut&&!v&&h(cn,{children:t.shortcut})]},t.name))}),E]})})}$.displayName=`CommandEmpty`;export{ve as AssistantFormRenderer,Ie as AssistantMessages,Be as Button,Ue as ChatEmpty,He as ChatLoading,Ve as ChatMessageList,Se as Collapsible,we as CollapsibleContent,Ce as CollapsibleTrigger,nn as Command,Sn as CommandContent,Tn as CommandDialog,Tn as CommandMenu,rn as CommandDialogContent,$ as CommandEmpty,Q as CommandGroup,En as CommandInput,sn as CommandItem,Nn as CommandList,Bt as CommandMenuContext,Ut as CommandMenuProvider,on as CommandSeparator,cn as CommandShortcut,ie as Confirmation,se as ConfirmationAccepted,ue as ConfirmationAction,le as ConfirmationActions,ce as ConfirmationRejected,oe as ConfirmationRequest,ae as ConfirmationTitle,Wt as Dialog,qt as DialogClose,Yt as DialogContent,$t as DialogDescription,Zt as DialogFooter,Xt as DialogHeader,Jt as DialogOverlay,Kt as DialogPortal,Qt as DialogTitle,Gt as DialogTrigger,en as Kbd,tn as KbdGroup,ye as Message,be as MessageContent,xe as MessageResponse,De as Task,ke as TaskContent,Ee as TaskItem,Te as TaskItemFile,Oe as TaskTrigger,ze as buttonVariants,e as cn,he as defaultFormRegistry,Nt as useChatHistory,Z as useCommandMenuContext};
@@ -170,6 +170,15 @@ Unused fields are safe: each library should ignore values it doesn't need.
170
170
 
171
171
  **Coverage first, count second.** Many non-trivial apps should land in the 10-30+ no-argument command-action range. If you have fewer than 8, you likely missed meaningful command flows.
172
172
 
173
+ ### Label distinctiveness for mixed arrays
174
+
175
+ When navigation and data actions share the same domain concept, make labels clearly distinct:
176
+
177
+ - Navigation: "Out of Office" (navigates to the page)
178
+ - Data: "Create Out of Office Entry" (creates via API)
179
+
180
+ Prefix data-action labels with their verb ("Create …", "Update …", "Delete …") to disambiguate from navigation labels.
181
+
173
182
  ---
174
183
 
175
184
  ## Step 5: Create the component
@@ -334,6 +343,7 @@ const assistant = useAssistant({
334
343
  actions,
335
344
  getContext: () => ({
336
345
  currentPage: window.location.pathname,
346
+ currentDateTime: new Date().toISOString(),
337
347
  }),
338
348
  })
339
349
 
@@ -170,6 +170,15 @@ Unused fields are safe: each library should ignore values it doesn't need.
170
170
 
171
171
  **Coverage first, count second.** Many non-trivial apps should land in the 10-30+ no-argument command-action range. If you have fewer than 8, you likely missed meaningful command flows.
172
172
 
173
+ ### Label distinctiveness for mixed arrays
174
+
175
+ When navigation and data actions share the same domain concept, make labels clearly distinct:
176
+
177
+ - Navigation: "Out of Office" (navigates to the page)
178
+ - Data: "Create Out of Office Entry" (creates via API)
179
+
180
+ Prefix data-action labels with their verb ("Create …", "Update …", "Delete …") to disambiguate from navigation labels.
181
+
173
182
  ---
174
183
 
175
184
  ## Step 5: Create the component
@@ -332,6 +341,7 @@ const assistant = useAssistant({
332
341
  actions,
333
342
  getContext: () => ({
334
343
  currentPage: window.location.pathname,
344
+ currentDateTime: new Date().toISOString(),
335
345
  }),
336
346
  })
337
347
 
@@ -170,6 +170,15 @@ Unused fields are safe: each library should ignore values it doesn't need.
170
170
 
171
171
  **Coverage first, count second.** Many non-trivial apps should land in the 10-30+ no-argument command-action range. If you have fewer than 8, you likely missed meaningful command flows.
172
172
 
173
+ ### Label distinctiveness for mixed arrays
174
+
175
+ When navigation and data actions share the same domain concept, make labels clearly distinct:
176
+
177
+ - Navigation: "Out of Office" (navigates to the page)
178
+ - Data: "Create Out of Office Entry" (creates via API)
179
+
180
+ Prefix data-action labels with their verb ("Create …", "Update …", "Delete …") to disambiguate from navigation labels.
181
+
173
182
  ---
174
183
 
175
184
  ## Step 5: Create the component
@@ -334,6 +343,7 @@ const assistant = useAssistant({
334
343
  actions,
335
344
  getContext: () => ({
336
345
  currentPage: window.location.pathname,
346
+ currentDateTime: new Date().toISOString(),
337
347
  }),
338
348
  })
339
349
 
@@ -170,6 +170,15 @@ Unused fields are safe: each library should ignore values it doesn't need.
170
170
 
171
171
  **Coverage first, count second.** Many non-trivial apps should land in the 10-30+ no-argument command-action range. If you have fewer than 8, you likely missed meaningful command flows.
172
172
 
173
+ ### Label distinctiveness for mixed arrays
174
+
175
+ When navigation and data actions share the same domain concept, make labels clearly distinct:
176
+
177
+ - Navigation: "Out of Office" (navigates to the page)
178
+ - Data: "Create Out of Office Entry" (creates via API)
179
+
180
+ Prefix data-action labels with their verb ("Create …", "Update …", "Delete …") to disambiguate from navigation labels.
181
+
173
182
  ---
174
183
 
175
184
  ## Step 5: Create the component
@@ -333,6 +342,7 @@ const assistant = useAssistant({
333
342
  actions,
334
343
  getContext: () => ({
335
344
  currentPage: window.location.pathname,
345
+ currentDateTime: new Date().toISOString(),
336
346
  }),
337
347
  })
338
348
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-cmdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",