dexto 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1504,7 +1504,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
1504
1504
  `),ce=he.content.filter(Eb),Ie=he.content.filter(Db),qe=[...ce.map(Ke=>({id:Jp(),type:"image",data:Ke.image,mimeType:Ke.mimeType??"image/jpeg",size:UM(Ke.image),source:"button"})),...Ie.map(Ke=>({id:Jp(),type:"file",data:Ke.data,mimeType:Ke.mimeType,filename:Ke.filename,size:UM(Ke.data),source:"button"}))];s(Ae),d(qe),j({sessionId:D,messageId:he.id}),o.current?.focus()},[D,j]),Nr=b.useCallback(()=>{if($.length===0)return!1;const he=$[$.length-1];return he?(er(he),!0):!1},[$,er]),Tr=he=>{if(de){if(he.key==="ArrowDown"){he.preventDefault(),Be(Ae=>(Ae+1)%Math.max(1,xt.length));return}if(he.key==="ArrowUp"){he.preventDefault(),Be(Ae=>(Ae-1+Math.max(1,xt.length))%Math.max(1,xt.length));return}if(he.key==="Enter"){he.preventDefault(),Ti(Ve);return}if(he.key==="Tab"){he.preventDefault(),Ti(Ve);return}if(he.key==="Escape"){fe(!1);return}}if(he.key==="ArrowUp"&&!he.altKey&&!he.ctrlKey&&!he.metaKey){const Ae=o.current?.selectionStart??0;if(!i.slice(0,Ae).includes(`
1505
1505
  `)){if(he.preventDefault(),$.length>0){Nr();return}const qe=U(i);qe!==null&&(s(qe),requestAnimationFrame(()=>{const Ke=qe.length;o.current?.setSelectionRange(Ke,Ke)}));return}}if(he.key==="ArrowDown"&&!he.altKey&&!he.ctrlKey&&!he.metaKey&&B){he.preventDefault();const Ae=G();Ae!==null&&(s(Ae),requestAnimationFrame(()=>{const ce=Ae.length;o.current?.setSelectionRange(ce,ce)}));return}if(tr&&he.key==="Escape"){he.preventDefault(),H(!1),s("");return}if(he.key==="Enter"&&!he.shiftKey){if(he.preventDefault(),i.trim()==="#"){s(""),H(!1),Re(!0);return}Sn(Gie({processing:E,queueFollowUpShortcut:he.altKey}))}},[tr,H]=b.useState(!1),[ye,Fe]=b.useState(null),Z=he=>{const Ae=he.target.value;if(s(Ae),Y(),Ae.startsWith("/")&&!Ae.includes(`
1506
1506
  `)?Ee(!0):st&&Ee(!1),Ae.trim()==="#"){H(!0);const ce=o.current;if(ce){const Ie=ce.getBoundingClientRect(),qe=16,Ke=Math.max(8,Ie.left+window.scrollX+qe),Mt=Math.max(280,Ie.width-qe*2),vt=Math.max(80,window.innerHeight-(Ie.bottom+window.scrollY)+64);Fe({position:"fixed",left:Ke,bottom:vt,width:Mt,zIndex:9999})}}else H(!1),Fe(null)},ue=he=>{const Ae=`/${he.name}`;s(Ae),Ee(!1),o.current&&(o.current.focus(),o.current.setSelectionRange(Ae.length,Ae.length))},Te=()=>{Ee(!1)};b.useEffect(()=>{const he=o.current,Ae=he?he.selectionStart??i.length:i.length,ce=$e(i,Ae);if(ce>=0){const Ie=i.slice(ce+1,Ae);J(Ie),fe(!0),Be(0);const qe=he?.getBoundingClientRect();if(qe){const Mt=Math.max(8,qe.left+window.scrollX+16),ot=Math.max(280,qe.width-32),Qt=Math.max(80,window.innerHeight-(qe.bottom+window.scrollY)+64);bt({position:"fixed",left:Mt,bottom:Qt,width:ot,zIndex:9999})}}else fe(!1),J(""),bt(null)},[i]);const xe=dt.useRef(!1);b.useEffect(()=>{de?xe.current||(xe.current=!0,me()):xe.current=!1},[de,me]);const ke=2e4,je=he=>{try{return btoa(unescape(encodeURIComponent(he)))}catch{return btoa(he)}},Je=async(he,Ae)=>{if(he.length===0)return;const ce=[];if(c.length+he.length>Ur.MAX_COUNT){gt(`Cannot add ${he.length} file(s). Maximum ${Ur.MAX_COUNT} attachments allowed (currently ${c.length}).`);return}const Ie=c.reduce((ot,vt)=>ot+vt.size,0),qe=he.reduce((ot,vt)=>ot+vt.size,0);if(Ie+qe>Ur.MAX_TOTAL_SIZE){gt(`Total size would exceed ${zr(Ur.MAX_TOTAL_SIZE)}. Current: ${zr(Ie)}, Adding: ${zr(qe)}.`);return}const Ke=[],Mt=[];for(const ot of he){if(ot.size>Ur.MAX_FILE_SIZE){Mt.push({file:ot,reason:"size_limit"}),ce.push({filename:ot.name,reason:`File too large (${zr(ot.size)}). Maximum ${zr(Ur.MAX_FILE_SIZE)} per file.`});continue}if(c.some(bn=>bn.filename===ot.name&&bn.size===ot.size)){Mt.push({file:ot,reason:"duplicate"}),ce.push({filename:ot.name,reason:"File already attached (duplicate name and size)."});continue}const Qt=O9(ot.type,ot.name);if(!(Qt!=="other"&&qie.includes(Qt))){Mt.push({file:ot,reason:"type_unsupported"}),ce.push({filename:ot.name,reason:"File type not supported. Only images, PDFs, audio, video, and document files are allowed."});continue}if(Ce!==null&&!Ce.includes(Qt)){Mt.push({file:ot,reason:"type_unsupported"});const _r=[];if(K&&"models"in K){const Oa=K.models;for(const ls of Oa)ls.supportedFileTypes?.includes(Qt)&&_r.push(`${ls.provider}/${ls.name}`)}ce.push({filename:ot.name,reason:`File type not supported by current model (${R?.provider}/${R?.model}).`,compatibleModels:_r.length>0?_r.slice(0,3):void 0});continue}Ke.push(ot)}if(D)for(const ot of Mt)Q.current.trackFileRejected({reason:ot.reason,fileType:ot.file.type,fileSizeBytes:ot.file.size,sessionId:D});if(Ke.length>0)try{const ot=await Promise.all(Ke.map(vt=>sn(vt,Ae)));if(d(vt=>[...vt,...ot]),D)for(const vt of ot)si(vt)}catch(ot){gt(`Failed to process ${Ke.length} file(s). Please try again.`),console.error("File processing error:",ot)}ce.length>0&&Ue(ce.length===1?`${ce[0].filename}: ${ce[0].reason}${ce[0].compatibleModels?` Try: ${ce[0].compatibleModels.join(", ")}`:""}`:`${ce.length} file(s) rejected. Check file types and sizes.`)},Rt=async he=>{const Ae=he.clipboardData,ce=Array.from(Ae.files);if(ce.length>0){he.preventDefault(),await Je(ce,"paste");return}const qe=Array.from(Ae.items).filter(ot=>ot.type.startsWith("image/"));if(qe.length>0){he.preventDefault();const ot=qe.map(vt=>vt.getAsFile()).filter(vt=>vt!==null);ot.length>0&&await Je(ot,"paste");return}const Ke=Ae.getData("text/plain");if(!Ke||Ke.length<=ke)return;if(he.preventDefault(),window.confirm(`Large text detected. Attach as a file instead of inflating the input?
1507
- (OK = attach as file, Cancel = paste truncated preview)`)){const vt=new TextEncoder().encode(Ke).length;if(c.length>=Ur.MAX_COUNT){gt(`Cannot attach pasted text. Maximum ${Ur.MAX_COUNT} attachments allowed (currently ${c.length}).`);return}if(vt>Ur.MAX_FILE_SIZE){gt(`Pasted text is too large (${zr(vt)}). Maximum ${zr(Ur.MAX_FILE_SIZE)} per file.`);return}const Qt=c.reduce((bn,_r)=>bn+_r.size,0);if(Qt+vt>Ur.MAX_TOTAL_SIZE){gt(`Total size would exceed ${zr(Ur.MAX_TOTAL_SIZE)}. Current: ${zr(Qt)}, Adding: ${zr(vt)}.`);return}const Fn={id:Jp(),type:"file",data:je(Ke),mimeType:"text/plain",filename:"pasted.txt",size:vt,source:"paste"};d(bn=>[...bn,Fn])}else{const ot=Ke.slice(0,ke);s(vt=>vt+ot)}},sn=async(he,Ae)=>new Promise((ce,Ie)=>{const qe=new FileReader;qe.onloadend=()=>{try{const Ke=qe.result;if(typeof Ke!="string"){Ie(new Error("Malformed data URL: FileReader result is not a string"));return}const Mt=Ke.indexOf(",");if(Mt===-1){Ie(new Error("Malformed data URL: missing comma separator"));return}const ot=Ke.substring(Mt+1),vt={id:Jp(),type:he.type.startsWith("image/")?"image":"file",data:ot,mimeType:he.type,filename:he.name,size:he.size,source:Ae};ce(vt)}catch(Ke){Ie(Ke)}},qe.onerror=()=>Ie(new Error("Failed to read file")),qe.readAsDataURL(he)}),pr=he=>{d(Ae=>Ae.filter(ce=>ce.id!==he))},si=he=>{D&&(he.type==="image"?Q.current.trackImageAttached({imageType:he.mimeType,imageSizeBytes:he.size,sessionId:D}):Q.current.trackFileAttached({fileType:he.mimeType,fileSizeBytes:he.size,sessionId:D}))},Or=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},dr=async()=>{try{const he=await navigator.mediaDevices.getUserMedia({audio:!0}),Ae=new MediaRecorder(he);w.current=Ae;const ce=[];Ae.ondataavailable=Ie=>{Ie.data.size>0&&ce.push(Ie.data)},Ae.onstop=()=>{const Ie=new Blob(ce,{type:Ae.mimeType}),qe=new FileReader;qe.onloadend=()=>{try{const Ke=qe.result,Mt=Ke.indexOf(","),ot=Ke.substring(Mt+1),vt=Ae.mimeType||"audio/webm",Fn=(_r=>({"audio/mp3":"mp3","audio/mpeg":"mp3","audio/wav":"wav","audio/x-wav":"wav","audio/wave":"wav","audio/webm":"webm","audio/ogg":"ogg","audio/m4a":"m4a","audio/aac":"aac"})[_r]||_r.split("/")[1]||"webm")(vt),bn={id:Jp(),type:"file",data:ot,mimeType:vt,filename:`recording.${Fn}`,size:Ie.size,source:"button"};d(_r=>[..._r,bn]),si(bn)}catch{gt("Failed to process audio recording. Please try again.")}},qe.readAsDataURL(Ie),he.getTracks().forEach(Ke=>Ke.stop())},Ae.start(),S(!0)}catch{gt("Failed to start audio recording. Please check microphone permissions.")}},Kn=()=>{w.current?.stop(),S(!1)},mr=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},_i=()=>m.current?.click(),Ne=()=>f.current?.click(),De=()=>g.current?.click(),yn=()=>y.current?.click(),fr=()=>x.current?.click();b.useEffect(()=>{i&&ne&&O(null),i&&be&&Ue(null)},[i,ne,be]);const Yt=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},On=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},Ra=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},Vo=he=>{he.preventDefault(),he.stopPropagation(),P.current++,he.dataTransfer.types.includes("Files")&&M(!0)},Zl=he=>{he.preventDefault(),he.stopPropagation()},Kc=he=>{he.preventDefault(),he.stopPropagation(),P.current--,P.current===0&&M(!1)},Aa=async he=>{he.preventDefault(),he.stopPropagation(),M(!1),P.current=0;const Ae=Array.from(he.dataTransfer.files);Ae.length>0&&await Je(Ae,"drop")};return l.jsxs("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[ne&&l.jsxs(ri,{variant:"destructive",className:"mb-2",children:[l.jsx(Na,{className:"h-4 w-4"}),l.jsxs(ii,{className:"flex items-center justify-between",children:[l.jsx("span",{children:ne}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>O(null),className:"h-auto p-1 ml-2",children:l.jsx(Cn,{className:"h-3 w-3"})})]})]}),be&&l.jsxs(ri,{variant:"destructive",className:"mb-2",children:[l.jsx(Na,{className:"h-4 w-4"}),l.jsxs(ii,{className:"flex items-center justify-between",children:[l.jsx("span",{children:be}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>Ue(null),className:"h-auto p-1 ml-2",children:l.jsx(Cn,{className:"h-3 w-3"})})]})]}),l.jsxs("div",{className:"w-full",children:[l.jsx("form",{onSubmit:he=>{he.preventDefault(),Sn()},children:l.jsx("div",{role:"region","aria-label":"Message input area with file drop zone",className:se("relative transition-all duration-200",N&&"ring-2 ring-primary ring-offset-2 rounded-lg"),onDragEnter:Vo,onDragOver:Zl,onDragLeave:Kc,onDrop:Aa,children:l.jsxs(ane,{children:[N&&l.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 rounded-lg pointer-events-none",children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-4xl mb-2",children:"📎"}),l.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files to attach"}),l.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Up to ",Ur.MAX_COUNT," files,"," ",zr(Ur.MAX_FILE_SIZE)," each"]})]})}),$.length>0&&l.jsx(Bie,{messages:$,onEditMessage:er,onRemoveMessage:he=>{D&&j({sessionId:D,messageId:he})}}),c.length>0&&l.jsxs("div",{className:"px-4 pt-4",children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsxs("div",{className:"text-xs text-muted-foreground",children:[c.length," / ",Ur.MAX_COUNT," ","files (",zr(gn)," /"," ",zr(Ur.MAX_TOTAL_SIZE),")"]}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>d([]),className:"h-6 text-xs text-muted-foreground hover:text-destructive",children:"Clear all"})]}),l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:c.map(he=>l.jsx(Tie,{attachment:he,onRemove:()=>pr(he.id)},he.id))})]}),l.jsxs("div",{className:"flex-auto overflow-y-auto relative",children:[k?l.jsx(sne,{ref:o,value:i,onChange:Z,onKeyDown:Tr,onPaste:Rt,placeholder:"Ask Dexto anything... Type @ for resources, / for prompts, # for memories",minRows:1,maxRows:8,className:"w-full px-4 pt-4 pb-1 text-lg leading-7 placeholder:text-lg bg-transparent border-none resize-none outline-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus:outline-none max-h-full"}):l.jsx("textarea",{ref:o,rows:1,value:i,onChange:Z,onKeyDown:Tr,onPaste:Rt,placeholder:"Ask Dexto anything... Type @ for resources, / for prompts, # for memories",className:"w-full px-4 pt-4 pb-1 text-lg leading-7 placeholder:text-lg bg-transparent border-none resize-none outline-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus:outline-none"}),de&&ut&&typeof window<"u"&&Ov.createPortal(l.jsx("div",{style:ut,className:"max-h-64 overflow-y-auto rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:l.jsx(kie,{resources:ze,query:pe,selectedIndex:Ve,onHoverIndex:he=>Be(he),onSelect:he=>Ti(Ve,he),loading:lt})}),document.body),tr&&ye&&typeof window<"u"&&Ov.createPortal(l.jsx("div",{style:ye,className:"rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:l.jsxs("div",{className:"p-2 flex items-center gap-2 text-sm text-muted-foreground",children:[l.jsx(Ro,{className:"h-3.5 w-3.5"}),l.jsxs("span",{children:["Press"," ",l.jsx("kbd",{className:"px-1.5 py-0.5 text-xs bg-muted border border-border rounded",children:"Enter"})," ","to create a memory"]})]})}),document.body)]}),l.jsx(Nie,{isVisible:st,searchQuery:i,onSelectPrompt:ue,onClose:Te,onCreatePrompt:An,refreshKey:wt}),l.jsx(one,{leftButtons:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(vre,{onImageAttach:_i,onPdfAttach:Ne,onAudioAttach:De,onVideoAttach:yn,onDocumentAttach:fr,supports:{image:Ce===null?void 0:Ce.includes("image"),pdf:Ce===null?void 0:Ce.includes("pdf"),audio:Ce===null?void 0:Ce.includes("audio"),video:Ce===null?void 0:Ce.includes("video"),document:Ce===null?void 0:Ce.includes("document")},useLargeBreakpoint:n}),l.jsx(bre,{isRecording:T,onToggleRecording:T?Kn:dr,disabled:Ce!==null&&!Ce.includes("audio"),useLargeBreakpoint:n})]}),rightButtons:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(bie,{}),l.jsx(Pe,{type:E?"button":"submit",onClick:E?()=>I(D||void 0):void 0,disabled:E?!1:!i.trim()&&c.length===0||t,className:se("h-10 w-10 p-0 rounded-full transition-all duration-200",E?"bg-secondary/80 text-secondary-foreground hover:bg-secondary shadow-sm hover:shadow-md border border-border/50":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-lg"),"aria-label":E?"Stop":"Send message",title:E?"Stop":"Send",children:E?l.jsx(qE,{className:"h-3.5 w-3.5 fill-current"}):t?l.jsx(vr,{className:"h-4 w-4 animate-spin"}):l.jsx(jq,{className:"h-4 w-4"})})]})})]})})}),l.jsx("input",{ref:m,type:"file",id:"image-upload",accept:"image/*",multiple:!0,className:"hidden",onChange:mr}),l.jsx("input",{ref:f,type:"file",id:"pdf-upload",accept:"application/pdf",multiple:!0,className:"hidden",onChange:Or}),l.jsx("input",{ref:g,type:"file",id:"audio-upload",accept:"audio/*",multiple:!0,className:"hidden",onChange:Yt}),l.jsx("input",{ref:y,type:"file",id:"video-upload",accept:"video/*",multiple:!0,className:"hidden",onChange:On}),l.jsx("input",{ref:x,type:"file",id:"document-upload",accept:".txt,.md,.json,.html,.xml,.doc,.docx,.rtf,.odt,.ppt,.pptx,.csv,.tsv,.xls,.xlsx,.iif,text/*,application/json,application/xml,text/xml,text/csv,text/tab-separated-values,application/msword,application/rtf,text/rtf,application/vnd.oasis.opendocument.text,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",multiple:!0,className:"hidden",onChange:Ra}),l.jsx(Pie,{open:at,onClose:qn,onCreated:br}),l.jsx(A4,{open:Me,onClose:()=>Re(!1)})]})]})}function GP(e,[t,n]){return Math.min(n,Math.max(t,e))}function Hie(e){const t=e+"CollectionProvider",[n,r]=$o(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=T=>{const{scope:S,children:w}=T,N=dt.useRef(null),M=dt.useRef(new Map).current;return l.jsx(i,{scope:S,itemMap:M,collectionRef:N,children:w})};o.displayName=t;const c=e+"CollectionSlot",d=Dl(c),m=dt.forwardRef((T,S)=>{const{scope:w,children:N}=T,M=s(c,w),P=ln(S,M.collectionRef);return l.jsx(d,{ref:P,children:N})});m.displayName=c;const f=e+"CollectionItemSlot",g="data-radix-collection-item",y=Dl(f),x=dt.forwardRef((T,S)=>{const{scope:w,children:N,...M}=T,P=dt.useRef(null),D=ln(S,P),E=s(f,w);return dt.useEffect(()=>(E.itemMap.set(P,{ref:P,...M}),()=>{E.itemMap.delete(P)})),l.jsx(y,{[g]:"",ref:D,children:N})});x.displayName=f;function k(T){const S=s(e+"CollectionConsumer",T);return dt.useCallback(()=>{const N=S.collectionRef.current;if(!N)return[];const M=Array.from(N.querySelectorAll(`[${g}]`));return Array.from(S.itemMap.values()).sort((E,I)=>M.indexOf(E.ref.current)-M.indexOf(I.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:o,Slot:m,ItemSlot:x},k,r]}var Vie=b.createContext(void 0);function Kie(e){const t=b.useContext(Vie);return e||t||"ltr"}var Wie=[" ","Enter","ArrowUp","ArrowDown"],Zie=[" ","Enter"],Ul="Select",[Wg,Zg,Yie]=Hie(Ul),[$c]=$o(Ul,[Yie,Fc]),Yg=Fc(),[Qie,Go]=$c(Ul),[Xie,Jie]=$c(Ul),O4=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:c,onValueChange:d,dir:m,name:f,autoComplete:g,disabled:y,required:x,form:k}=e,T=Yg(t),[S,w]=b.useState(null),[N,M]=b.useState(null),[P,D]=b.useState(!1),E=Kie(m),[I,R]=Rl({prop:r,defaultProp:i??!1,onChange:s,caller:Ul}),[K,L]=Rl({prop:o,defaultProp:c,onChange:d,caller:Ul}),U=b.useRef(null),G=S?k||!!S.closest("form"):!0,[Y,B]=b.useState(new Set),q=Array.from(Y).map(j=>j.props.value).join(";");return l.jsx(f2,{...T,children:l.jsxs(Qie,{required:x,scope:t,trigger:S,onTriggerChange:w,valueNode:N,onValueNodeChange:M,valueNodeHasChildren:P,onValueNodeHasChildrenChange:D,contentId:No(),value:K,onValueChange:L,open:I,onOpenChange:R,dir:E,triggerPointerDownPosRef:U,disabled:y,children:[l.jsx(Wg.Provider,{scope:t,children:l.jsx(Xie,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(j=>{B(W=>new Set(W).add(j))},[]),onNativeOptionRemove:b.useCallback(j=>{B(W=>{const z=new Set(W);return z.delete(j),z})},[]),children:n})}),G?l.jsxs(iI,{"aria-hidden":!0,required:x,tabIndex:-1,name:f,autoComplete:g,value:K,onChange:j=>L(j.target.value),disabled:y,form:k,children:[K===void 0?l.jsx("option",{value:""}):null,Array.from(Y)]},q):null]})})};O4.displayName=Ul;var F4="SelectTrigger",U4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Yg(n),o=Go(F4,n),c=o.disabled||r,d=ln(t,o.onTriggerChange),m=Zg(n),f=b.useRef("touch"),[g,y,x]=aI(T=>{const S=m().filter(M=>!M.disabled),w=S.find(M=>M.value===o.value),N=oI(S,T,w);N!==void 0&&o.onValueChange(N.value)}),k=T=>{c||(o.onOpenChange(!0),x()),T&&(o.triggerPointerDownPosRef.current={x:Math.round(T.pageX),y:Math.round(T.pageY)})};return l.jsx(Dg,{asChild:!0,...s,children:l.jsx($t.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:c,"data-disabled":c?"":void 0,"data-placeholder":sI(o.value)?"":void 0,...i,ref:d,onClick:jt(i.onClick,T=>{T.currentTarget.focus(),f.current!=="mouse"&&k(T)}),onPointerDown:jt(i.onPointerDown,T=>{f.current=T.pointerType;const S=T.target;S.hasPointerCapture(T.pointerId)&&S.releasePointerCapture(T.pointerId),T.button===0&&T.ctrlKey===!1&&T.pointerType==="mouse"&&(k(T),T.preventDefault())}),onKeyDown:jt(i.onKeyDown,T=>{const S=g.current!=="";!(T.ctrlKey||T.altKey||T.metaKey)&&T.key.length===1&&y(T.key),!(S&&T.key===" ")&&Wie.includes(T.key)&&(k(),T.preventDefault())})})})});U4.displayName=F4;var L4="SelectValue",z4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...c}=e,d=Go(L4,n),{onValueNodeHasChildrenChange:m}=d,f=s!==void 0,g=ln(t,d.onValueNodeChange);return Vr(()=>{m(f)},[m,f]),l.jsx($t.span,{...c,ref:g,style:{pointerEvents:"none"},children:sI(d.value)?l.jsx(l.Fragment,{children:o}):s})});z4.displayName=L4;var ese="SelectIcon",$4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return l.jsx($t.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});$4.displayName=ese;var tse="SelectPortal",B4=e=>l.jsx(mm,{asChild:!0,...e});B4.displayName=tse;var Ll="SelectContent",q4=b.forwardRef((e,t)=>{const n=Go(Ll,e.__scopeSelect),[r,i]=b.useState();if(Vr(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?fg.createPortal(l.jsx(G4,{scope:e.__scopeSelect,children:l.jsx(Wg.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(H4,{...e,ref:t})});q4.displayName=Ll;var xs=10,[G4,Ho]=$c(Ll),nse="SelectContentImpl",rse=Dl("SelectContent.RemoveScroll"),H4=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:c,sideOffset:d,align:m,alignOffset:f,arrowPadding:g,collisionBoundary:y,collisionPadding:x,sticky:k,hideWhenDetached:T,avoidCollisions:S,...w}=e,N=Go(Ll,n),[M,P]=b.useState(null),[D,E]=b.useState(null),I=ln(t,ae=>P(ae)),[R,K]=b.useState(null),[L,U]=b.useState(null),G=Zg(n),[Y,B]=b.useState(!1),q=b.useRef(!1);b.useEffect(()=>{if(M)return Y2(M)},[M]),Z2();const j=b.useCallback(ae=>{const[ze,...lt]=G().map(J=>J.ref.current),[me]=lt.slice(-1),pe=document.activeElement;for(const J of ae)if(J===pe||(J?.scrollIntoView({block:"nearest"}),J===ze&&D&&(D.scrollTop=0),J===me&&D&&(D.scrollTop=D.scrollHeight),J?.focus(),document.activeElement!==pe))return},[G,D]),W=b.useCallback(()=>j([R,M]),[j,R,M]);b.useEffect(()=>{Y&&W()},[Y,W]);const{onOpenChange:z,triggerPointerDownPosRef:$}=N;b.useEffect(()=>{if(M){let ae={x:0,y:0};const ze=me=>{ae={x:Math.abs(Math.round(me.pageX)-($.current?.x??0)),y:Math.abs(Math.round(me.pageY)-($.current?.y??0))}},lt=me=>{ae.x<=10&&ae.y<=10?me.preventDefault():M.contains(me.target)||z(!1),document.removeEventListener("pointermove",ze),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",ze),document.addEventListener("pointerup",lt,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ze),document.removeEventListener("pointerup",lt,{capture:!0})}}},[M,z,$]),b.useEffect(()=>{const ae=()=>z(!1);return window.addEventListener("blur",ae),window.addEventListener("resize",ae),()=>{window.removeEventListener("blur",ae),window.removeEventListener("resize",ae)}},[z]);const[A,Q]=aI(ae=>{const ze=G().filter(pe=>!pe.disabled),lt=ze.find(pe=>pe.ref.current===document.activeElement),me=oI(ze,ae,lt);me&&setTimeout(()=>me.ref.current.focus())}),ne=b.useCallback((ae,ze,lt)=>{const me=!q.current&&!lt;(N.value!==void 0&&N.value===ze||me)&&(K(ae),me&&(q.current=!0))},[N.value]),O=b.useCallback(()=>M?.focus(),[M]),be=b.useCallback((ae,ze,lt)=>{const me=!q.current&&!lt;(N.value!==void 0&&N.value===ze||me)&&U(ae)},[N.value]),Ue=r==="popper"?l1:V4,Ce=Ue===l1?{side:c,sideOffset:d,align:m,alignOffset:f,arrowPadding:g,collisionBoundary:y,collisionPadding:x,sticky:k,hideWhenDetached:T,avoidCollisions:S}:{};return l.jsx(G4,{scope:n,content:M,viewport:D,onViewportChange:E,itemRefCallback:ne,selectedItem:R,onItemLeave:O,itemTextRefCallback:be,focusSelectedItem:W,selectedItemText:L,position:r,isPositioned:Y,searchRef:A,children:l.jsx(qg,{as:rse,allowPinchZoom:!0,children:l.jsx($g,{asChild:!0,trapped:N.open,onMountAutoFocus:ae=>{ae.preventDefault()},onUnmountAutoFocus:jt(i,ae=>{N.trigger?.focus({preventScroll:!0}),ae.preventDefault()}),children:l.jsx(pm,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ae=>ae.preventDefault(),onDismiss:()=>N.onOpenChange(!1),children:l.jsx(Ue,{role:"listbox",id:N.contentId,"data-state":N.open?"open":"closed",dir:N.dir,onContextMenu:ae=>ae.preventDefault(),...w,...Ce,onPlaced:()=>B(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...w.style},onKeyDown:jt(w.onKeyDown,ae=>{const ze=ae.ctrlKey||ae.altKey||ae.metaKey;if(ae.key==="Tab"&&ae.preventDefault(),!ze&&ae.key.length===1&&Q(ae.key),["ArrowUp","ArrowDown","Home","End"].includes(ae.key)){let me=G().filter(pe=>!pe.disabled).map(pe=>pe.ref.current);if(["ArrowUp","End"].includes(ae.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(ae.key)){const pe=ae.target,J=me.indexOf(pe);me=me.slice(J+1)}setTimeout(()=>j(me)),ae.preventDefault()}})})})})})})});H4.displayName=nse;var ise="SelectItemAlignedPosition",V4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Go(Ll,n),o=Ho(Ll,n),[c,d]=b.useState(null),[m,f]=b.useState(null),g=ln(t,I=>f(I)),y=Zg(n),x=b.useRef(!1),k=b.useRef(!0),{viewport:T,selectedItem:S,selectedItemText:w,focusSelectedItem:N}=o,M=b.useCallback(()=>{if(s.trigger&&s.valueNode&&c&&m&&T&&S&&w){const I=s.trigger.getBoundingClientRect(),R=m.getBoundingClientRect(),K=s.valueNode.getBoundingClientRect(),L=w.getBoundingClientRect();if(s.dir!=="rtl"){const pe=L.left-R.left,J=K.left-pe,de=I.left-J,fe=I.width+de,Ve=Math.max(fe,R.width),Be=window.innerWidth-xs,ut=GP(J,[xs,Math.max(xs,Be-Ve)]);c.style.minWidth=fe+"px",c.style.left=ut+"px"}else{const pe=R.right-L.right,J=window.innerWidth-K.right-pe,de=window.innerWidth-I.right-J,fe=I.width+de,Ve=Math.max(fe,R.width),Be=window.innerWidth-xs,ut=GP(J,[xs,Math.max(xs,Be-Ve)]);c.style.minWidth=fe+"px",c.style.right=ut+"px"}const U=y(),G=window.innerHeight-xs*2,Y=T.scrollHeight,B=window.getComputedStyle(m),q=parseInt(B.borderTopWidth,10),j=parseInt(B.paddingTop,10),W=parseInt(B.borderBottomWidth,10),z=parseInt(B.paddingBottom,10),$=q+j+Y+z+W,A=Math.min(S.offsetHeight*5,$),Q=window.getComputedStyle(T),ne=parseInt(Q.paddingTop,10),O=parseInt(Q.paddingBottom,10),be=I.top+I.height/2-xs,Ue=G-be,Ce=S.offsetHeight/2,ae=S.offsetTop+Ce,ze=q+j+ae,lt=$-ze;if(ze<=be){const pe=U.length>0&&S===U[U.length-1].ref.current;c.style.bottom="0px";const J=m.clientHeight-T.offsetTop-T.offsetHeight,de=Math.max(Ue,Ce+(pe?O:0)+J+W),fe=ze+de;c.style.height=fe+"px"}else{const pe=U.length>0&&S===U[0].ref.current;c.style.top="0px";const de=Math.max(be,q+T.offsetTop+(pe?ne:0)+Ce)+lt;c.style.height=de+"px",T.scrollTop=ze-be+T.offsetTop}c.style.margin=`${xs}px 0`,c.style.minHeight=A+"px",c.style.maxHeight=G+"px",r?.(),requestAnimationFrame(()=>x.current=!0)}},[y,s.trigger,s.valueNode,c,m,T,S,w,s.dir,r]);Vr(()=>M(),[M]);const[P,D]=b.useState();Vr(()=>{m&&D(window.getComputedStyle(m).zIndex)},[m]);const E=b.useCallback(I=>{I&&k.current===!0&&(M(),N?.(),k.current=!1)},[M,N]);return l.jsx(ase,{scope:n,contentWrapper:c,shouldExpandOnScrollRef:x,onScrollButtonChange:E,children:l.jsx("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:P},children:l.jsx($t.div,{...i,ref:g,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});V4.displayName=ise;var sse="SelectPopperPosition",l1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=xs,...s}=e,o=Yg(n);return l.jsx(h2,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});l1.displayName=sse;var[ase,rT]=$c(Ll,{}),u1="SelectViewport",K4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=Ho(u1,n),o=rT(u1,n),c=ln(t,s.onViewportChange),d=b.useRef(0);return l.jsxs(l.Fragment,{children:[l.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),l.jsx(Wg.Slot,{scope:n,children:l.jsx($t.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:c,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:jt(i.onScroll,m=>{const f=m.currentTarget,{contentWrapper:g,shouldExpandOnScrollRef:y}=o;if(y?.current&&g){const x=Math.abs(d.current-f.scrollTop);if(x>0){const k=window.innerHeight-xs*2,T=parseFloat(g.style.minHeight),S=parseFloat(g.style.height),w=Math.max(T,S);if(w<k){const N=w+x,M=Math.min(k,N),P=N-M;g.style.height=M+"px",g.style.bottom==="0px"&&(f.scrollTop=P>0?P:0,g.style.justifyContent="flex-end")}}}d.current=f.scrollTop})})})]})});K4.displayName=u1;var W4="SelectGroup",[ose,lse]=$c(W4),use=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=No();return l.jsx(ose,{scope:n,id:i,children:l.jsx($t.div,{role:"group","aria-labelledby":i,...r,ref:t})})});use.displayName=W4;var Z4="SelectLabel",cse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=lse(Z4,n);return l.jsx($t.div,{id:i.id,...r,ref:t})});cse.displayName=Z4;var lg="SelectItem",[pse,Y4]=$c(lg),Q4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,c=Go(lg,n),d=Ho(lg,n),m=c.value===r,[f,g]=b.useState(s??""),[y,x]=b.useState(!1),k=ln(t,N=>d.itemRefCallback?.(N,r,i)),T=No(),S=b.useRef("touch"),w=()=>{i||(c.onValueChange(r),c.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return l.jsx(pse,{scope:n,value:r,disabled:i,textId:T,isSelected:m,onItemTextChange:b.useCallback(N=>{g(M=>M||(N?.textContent??"").trim())},[]),children:l.jsx(Wg.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:l.jsx($t.div,{role:"option","aria-labelledby":T,"data-highlighted":y?"":void 0,"aria-selected":m&&y,"data-state":m?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:k,onFocus:jt(o.onFocus,()=>x(!0)),onBlur:jt(o.onBlur,()=>x(!1)),onClick:jt(o.onClick,()=>{S.current!=="mouse"&&w()}),onPointerUp:jt(o.onPointerUp,()=>{S.current==="mouse"&&w()}),onPointerDown:jt(o.onPointerDown,N=>{S.current=N.pointerType}),onPointerMove:jt(o.onPointerMove,N=>{S.current=N.pointerType,i?d.onItemLeave?.():S.current==="mouse"&&N.currentTarget.focus({preventScroll:!0})}),onPointerLeave:jt(o.onPointerLeave,N=>{N.currentTarget===document.activeElement&&d.onItemLeave?.()}),onKeyDown:jt(o.onKeyDown,N=>{d.searchRef?.current!==""&&N.key===" "||(Zie.includes(N.key)&&w(),N.key===" "&&N.preventDefault())})})})})});Q4.displayName=lg;var Td="SelectItemText",X4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Go(Td,n),c=Ho(Td,n),d=Y4(Td,n),m=Jie(Td,n),[f,g]=b.useState(null),y=ln(t,w=>g(w),d.onItemTextChange,w=>c.itemTextRefCallback?.(w,d.value,d.disabled)),x=f?.textContent,k=b.useMemo(()=>l.jsx("option",{value:d.value,disabled:d.disabled,children:x},d.value),[d.disabled,d.value,x]),{onNativeOptionAdd:T,onNativeOptionRemove:S}=m;return Vr(()=>(T(k),()=>S(k)),[T,S,k]),l.jsxs(l.Fragment,{children:[l.jsx($t.span,{id:d.textId,...s,ref:y}),d.isSelected&&o.valueNode&&!o.valueNodeHasChildren?fg.createPortal(s.children,o.valueNode):null]})});X4.displayName=Td;var J4="SelectItemIndicator",eI=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Y4(J4,n).isSelected?l.jsx($t.span,{"aria-hidden":!0,...r,ref:t}):null});eI.displayName=J4;var c1="SelectScrollUpButton",tI=b.forwardRef((e,t)=>{const n=Ho(c1,e.__scopeSelect),r=rT(c1,e.__scopeSelect),[i,s]=b.useState(!1),o=ln(t,r.onScrollButtonChange);return Vr(()=>{if(n.viewport&&n.isPositioned){let c=function(){const m=d.scrollTop>0;s(m)};const d=n.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[n.viewport,n.isPositioned]),i?l.jsx(rI,{...e,ref:o,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=n;c&&d&&(c.scrollTop=c.scrollTop-d.offsetHeight)}}):null});tI.displayName=c1;var p1="SelectScrollDownButton",nI=b.forwardRef((e,t)=>{const n=Ho(p1,e.__scopeSelect),r=rT(p1,e.__scopeSelect),[i,s]=b.useState(!1),o=ln(t,r.onScrollButtonChange);return Vr(()=>{if(n.viewport&&n.isPositioned){let c=function(){const m=d.scrollHeight-d.clientHeight,f=Math.ceil(d.scrollTop)<m;s(f)};const d=n.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[n.viewport,n.isPositioned]),i?l.jsx(rI,{...e,ref:o,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=n;c&&d&&(c.scrollTop=c.scrollTop+d.offsetHeight)}}):null});nI.displayName=p1;var rI=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=Ho("SelectScrollButton",n),o=b.useRef(null),c=Zg(n),d=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>d(),[d]),Vr(()=>{c().find(f=>f.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[c]),l.jsx($t.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:jt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:jt(i.onPointerMove,()=>{s.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:jt(i.onPointerLeave,()=>{d()})})}),dse="SelectSeparator",mse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx($t.div,{"aria-hidden":!0,...r,ref:t})});mse.displayName=dse;var d1="SelectArrow",fse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Yg(n),s=Go(d1,n),o=Ho(d1,n);return s.open&&o.position==="popper"?l.jsx(g2,{...i,...r,ref:t}):null});fse.displayName=d1;var hse="SelectBubbleInput",iI=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=ln(r,i),o=W2(t);return b.useEffect(()=>{const c=i.current;if(!c)return;const d=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(d,"value").set;if(o!==t&&f){const g=new Event("change",{bubbles:!0});f.call(c,t),c.dispatchEvent(g)}},[o,t]),l.jsx($t.select,{...n,style:{...LD,...n.style},ref:s,defaultValue:t})});iI.displayName=hse;function sI(e){return e===""||e===void 0}function aI(e){const t=jl(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const c=n.current+o;t(c),(function d(m){n.current=m,window.clearTimeout(r.current),m!==""&&(r.current=window.setTimeout(()=>d(""),1e3))})(c)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function oI(e,t,n){const i=t.length>1&&Array.from(t).every(m=>m===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=gse(e,Math.max(s,0));i.length===1&&(o=o.filter(m=>m!==n));const d=o.find(m=>m.textValue.toLowerCase().startsWith(i.toLowerCase()));return d!==n?d:void 0}function gse(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var yse=O4,xse=U4,vse=z4,bse=$4,Tse=B4,_se=q4,kse=K4,wse=Q4,Sse=X4,Mse=eI,Nse=tI,Pse=nI;function zl({...e}){return l.jsx(yse,{"data-slot":"select",...e})}function $l({...e}){return l.jsx(vse,{"data-slot":"select-value",...e})}function Bl({className:e,size:t="default",children:n,...r}){return l.jsxs(xse,{"data-slot":"select-trigger","data-size":t,className:se("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r,children:[n,l.jsx(bse,{asChild:!0,children:l.jsx(Ir,{className:"size-4 opacity-50"})})]})}function ql({className:e,children:t,position:n="popper",...r}){return l.jsx(Tse,{children:l.jsxs(_se,{"data-slot":"select-content",className:se("bg-popover text-popover-foreground 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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[l.jsx(Cse,{}),l.jsx(kse,{className:se("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),l.jsx(Ese,{})]})})}function qs({className:e,children:t,...n}){return l.jsxs(wse,{"data-slot":"select-item",className:se("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[l.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:l.jsx(Mse,{children:l.jsx(ur,{className:"size-4"})})}),l.jsx(Sse,{children:t})]})}function Cse({className:e,...t}){return l.jsx(Nse,{"data-slot":"select-scroll-up-button",className:se("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Sg,{className:"size-4"})})}function Ese({className:e,...t}){return l.jsx(Pse,{"data-slot":"select-scroll-down-button",className:se("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Ir,{className:"size-4"})})}const Dse=[/\bapi[_-]?key\b/i,/\bapikey\b/i,/\bsecret\b/i,/\btoken\b/i,/\bpassword\b/i,/\bauthorization\b/i,/\bauth[_-]?token\b/i,/\bbearer\b/i,/\bcredential\b/i,/\bclient[_-]?secret\b/i];function bv({label:e="Key-Value Pairs",placeholder:t={key:"Key",value:"Value"},pairs:n,onChange:r,disabled:i=!1,className:s="",keyLabel:o="Key",valueLabel:c="Value",maskSensitiveValues:d=!0}){const[m,f]=b.useState(new Set),g=S=>!d||!S?!1:Dse.some(w=>w.test(S)),y=S=>{f(w=>{const N=new Set(w);return N.has(S)?N.delete(S):N.add(S),N})},x=()=>{const S={key:"",value:"",id:`kv-${Date.now()}-${Math.random().toString(36).substring(2,11)}`};r([...n,S])},k=S=>{const w=n.filter(N=>N.id!==S);r(w)},T=(S,w,N)=>{r(n.map(M=>M.id===S?{...M,[w]:N}:M))};return l.jsxs("div",{className:`space-y-3 ${s}`,children:[e&&l.jsx(fn,{className:"text-sm font-medium",children:e}),l.jsxs("div",{className:"space-y-2",children:[n.length>0&&l.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center text-xs text-muted-foreground",children:[l.jsx("div",{className:"col-span-5",children:o}),l.jsx("div",{className:"col-span-6",children:c}),l.jsx("div",{className:"col-span-1"})]}),n.map(S=>{const w=g(S.key),N=m.has(S.id);return l.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center",children:[l.jsx(ct,{placeholder:t.key,value:S.key,onChange:M=>T(S.id,"key",M.target.value),disabled:i,className:"col-span-5"}),l.jsxs("div",{className:"col-span-6 relative",children:[l.jsx(ct,{type:w&&!N?"password":"text",placeholder:t.value,value:S.value,onChange:M=>T(S.id,"value",M.target.value),disabled:i,className:"pr-10"}),w&&S.value&&l.jsx(Pe,{type:"button",variant:"ghost",size:"sm",onClick:()=>y(S.id),disabled:i,className:"absolute right-0 top-0 h-full w-10 p-0 hover:bg-transparent","aria-label":N?"Hide value":"Show value",children:N?l.jsx(cm,{className:"h-4 w-4 text-muted-foreground"}):l.jsx(jc,{className:"h-4 w-4 text-muted-foreground"})})]}),l.jsx(Pe,{type:"button",variant:"ghost",size:"sm",onClick:()=>k(S.id),disabled:i,className:"col-span-1 h-8 w-8 p-0",children:l.jsx(Ar,{className:"h-4 w-4"})})]},S.id)})]}),l.jsxs(Pe,{type:"button",variant:"outline",size:"sm",onClick:x,disabled:i,className:"w-full mt-2",children:[l.jsx(xi,{className:"h-4 w-4 mr-2"}),"Add ",o]})]})}var Qg="Checkbox",[jse]=$o(Qg),[Ise,iT]=jse(Qg);function Rse(e){const{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:s,form:o,name:c,onCheckedChange:d,required:m,value:f="on",internal_do_not_use_render:g}=e,[y,x]=Rl({prop:n,defaultProp:i??!1,onChange:d,caller:Qg}),[k,T]=b.useState(null),[S,w]=b.useState(null),N=b.useRef(!1),M=k?!!o||!!k.closest("form"):!0,P={checked:y,disabled:s,setChecked:x,control:k,setControl:T,name:c,form:o,value:f,hasConsumerStoppedPropagationRef:N,required:m,defaultChecked:Po(i)?!1:i,isFormControl:M,bubbleInput:S,setBubbleInput:w};return l.jsx(Ise,{scope:t,...P,children:Ase(g)?g(P):r})}var lI="CheckboxTrigger",uI=b.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i)=>{const{control:s,value:o,disabled:c,checked:d,required:m,setControl:f,setChecked:g,hasConsumerStoppedPropagationRef:y,isFormControl:x,bubbleInput:k}=iT(lI,e),T=ln(i,f),S=b.useRef(d);return b.useEffect(()=>{const w=s?.form;if(w){const N=()=>g(S.current);return w.addEventListener("reset",N),()=>w.removeEventListener("reset",N)}},[s,g]),l.jsx($t.button,{type:"button",role:"checkbox","aria-checked":Po(d)?"mixed":d,"aria-required":m,"data-state":hI(d),"data-disabled":c?"":void 0,disabled:c,value:o,...r,ref:T,onKeyDown:jt(t,w=>{w.key==="Enter"&&w.preventDefault()}),onClick:jt(n,w=>{g(N=>Po(N)?!0:!N),k&&x&&(y.current=w.isPropagationStopped(),y.current||w.stopPropagation())})})});uI.displayName=lI;var cI=b.forwardRef((e,t)=>{const{__scopeCheckbox:n,name:r,checked:i,defaultChecked:s,required:o,disabled:c,value:d,onCheckedChange:m,form:f,...g}=e;return l.jsx(Rse,{__scopeCheckbox:n,checked:i,defaultChecked:s,disabled:c,required:o,onCheckedChange:m,name:r,form:f,value:d,internal_do_not_use_render:({isFormControl:y})=>l.jsxs(l.Fragment,{children:[l.jsx(uI,{...g,ref:t,__scopeCheckbox:n}),y&&l.jsx(fI,{__scopeCheckbox:n})]})})});cI.displayName=Qg;var pI="CheckboxIndicator",dI=b.forwardRef((e,t)=>{const{__scopeCheckbox:n,forceMount:r,...i}=e,s=iT(pI,n);return l.jsx(ja,{present:r||Po(s.checked)||s.checked===!0,children:l.jsx($t.span,{"data-state":hI(s.checked),"data-disabled":s.disabled?"":void 0,...i,ref:t,style:{pointerEvents:"none",...e.style}})})});dI.displayName=pI;var mI="CheckboxBubbleInput",fI=b.forwardRef(({__scopeCheckbox:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:s,defaultChecked:o,required:c,disabled:d,name:m,value:f,form:g,bubbleInput:y,setBubbleInput:x}=iT(mI,e),k=ln(n,x),T=W2(s),S=p2(r);b.useEffect(()=>{const N=y;if(!N)return;const M=window.HTMLInputElement.prototype,D=Object.getOwnPropertyDescriptor(M,"checked").set,E=!i.current;if(T!==s&&D){const I=new Event("click",{bubbles:E});N.indeterminate=Po(s),D.call(N,Po(s)?!1:s),N.dispatchEvent(I)}},[y,T,s,i]);const w=b.useRef(Po(s)?!1:s);return l.jsx($t.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??w.current,required:c,disabled:d,name:m,value:f,form:g,...t,tabIndex:-1,ref:k,style:{...t.style,...S,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});fI.displayName=mI;function Ase(e){return typeof e=="function"}function Po(e){return e==="indeterminate"}function hI(e){return Po(e)?"indeterminate":e?"checked":"unchecked"}function gI({className:e,...t}){return l.jsx(cI,{"data-slot":"checkbox",className:se("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:l.jsx(dI,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:l.jsx(ur,{className:"size-3.5"})})})}function yI({isOpen:e,onClose:t,onServerConnected:n,initialName:r,initialConfig:i,lockName:s}){const o=i2(),[c,d]=b.useState(""),[m,f]=b.useState("stdio"),[g,y]=b.useState(""),[x,k]=b.useState(""),[T,S]=b.useState(""),[w,N]=b.useState([]),[M,P]=b.useState([]),[D,E]=b.useState(null),[I,R]=b.useState(!1),[K,L]=b.useState(!1),U=j=>{const W={};return j.forEach(z=>{z.key.trim()&&z.value.trim()&&(W[z.key.trim()]=z.value.trim())}),W},G=j=>{const W={};for(const{key:z,value:$}of j){const A=z.trim(),Q=$.trim();A&&Q&&(W[A]=Q)}return W},Y=j=>{const W=["api_key","secret","token","password","key"],z={};for(const[$,A]of Object.entries(j)){const Q=W.some(ne=>$.toLowerCase().includes(ne));z[$]=Q?"***masked***":A}return z},B=j=>{const W=["authorization","proxy-authorization","api-key","x-api-key","token","cookie","set-cookie"],z={};for(const[$,A]of Object.entries(j)){const Q=$.toLowerCase(),ne=W.some(O=>Q===O||Q.includes(O));z[$]=ne?"***masked***":A}return z};b.useEffect(()=>{if(!e){const j=setTimeout(()=>{d(""),f("stdio"),y(""),k(""),S(""),N([]),P([]),E(null),R(!1)},300);return()=>clearTimeout(j)}},[e]),b.useEffect(()=>{if(!e)return;d(r??"");const j=i?.type??"stdio";if(f(j),j==="stdio"){const W=i??{};y(typeof W.command=="string"?W.command:""),k(Array.isArray(W.args)?W.args.join(", "):"");const z=Object.entries(W.env??{});P(z.map(([$,A],Q)=>({key:$,value:String(A??""),id:`env-${Q}`}))),S(""),N([])}else{const W=i??{};S(typeof W.url=="string"?W.url:"");const z=Object.entries(W.headers??{});N(z.map(([$,A],Q)=>({key:$,value:String(A??""),id:`hdr-${Q}`}))),y(""),k(""),P([])}},[e,r,i]);const q=async j=>{if(j.preventDefault(),E(null),R(!0),!c.trim()){E("Server name is required."),R(!1);return}if(m==="stdio"){if(!g.trim()){E("Command is required for stdio servers."),R(!1);return}const z=M.map($=>$.key.trim()).filter(Boolean);if(z.length){const $=z.filter((Q,ne)=>z.indexOf(Q)!==ne);if($.length){E(`Duplicate environment variables: ${Array.from(new Set($)).join(", ")}`),R(!1);return}const A=M.filter(Q=>Q.key.trim()&&!Q.value.trim()).map(Q=>Q.key.trim());if(A.length){E(`Please set required environment variables: ${A.join(", ")}`),R(!1);return}}}else{if(!T.trim()){E(`URL is required for ${m.toUpperCase()} servers.`),R(!1);return}try{new URL(T.trim())}catch{E(`Invalid URL format for ${m.toUpperCase()} server.`),R(!1);return}}let W;m==="stdio"?W={type:"stdio",command:g.trim(),args:x.split(",").map(z=>z.trim()).filter(Boolean),env:G(M),timeout:3e4,connectionMode:"lenient"}:m==="sse"?W={type:"sse",url:T.trim(),headers:w.length?U(w):{},timeout:3e4,connectionMode:"lenient"}:W={type:"http",url:T.trim(),headers:w.length?U(w):{},timeout:3e4,connectionMode:"lenient"};try{await o.mutateAsync({name:c.trim(),config:W,persistToAgent:K}),n?.(),t()}catch(z){let $="Failed to connect server";z instanceof Error?$=z.message||$:typeof z=="string"&&($=z),o.reset(),E($)}finally{R(!1)}};return l.jsx(qr,{open:e,onOpenChange:j=>!j&&t(),children:l.jsxs(Gr,{className:"sm:max-w-[480px]",children:[l.jsxs(ti,{children:[l.jsx(Hr,{children:"Connect New MCP Server"}),l.jsx(is,{children:"Configure connection details for a new MCP server (stdio, SSE, or HTTP)."})]}),l.jsxs("form",{id:"connectServerForm",onSubmit:q,className:"grid gap-4 py-4",children:[D&&l.jsx(ri,{variant:"destructive",children:l.jsx(ii,{children:D})}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"serverName",className:"text-right",children:"Server Name"}),l.jsx(ct,{id:"serverName",value:c,onChange:j=>d(j.target.value),className:"col-span-3",placeholder:"e.g., My Local Tools",required:!0,disabled:I||!!s})]}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"serverType",className:"text-right",children:"Server Type"}),l.jsxs(zl,{value:m,onValueChange:j=>f(j),disabled:I,children:[l.jsx(Bl,{id:"serverType",className:"col-span-3",children:l.jsx($l,{placeholder:"Select type"})}),l.jsxs(ql,{children:[l.jsx(qs,{value:"stdio",children:"stdio"}),l.jsx(qs,{value:"sse",children:"sse"}),l.jsx(qs,{value:"http",children:"http"})]})]})]}),m==="stdio"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"command",className:"text-right",children:"Command"}),l.jsx(ct,{id:"command",value:g,onChange:j=>y(j.target.value),className:"col-span-3",placeholder:"e.g., /path/to/executable or python",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"args",className:"text-right",children:"Arguments"}),l.jsx(ct,{id:"args",value:x,onChange:j=>k(j.target.value),className:"col-span-3",placeholder:"Comma-separated, e.g., -m,script.py,--port,8080",disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Environment"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:M,onChange:P,placeholder:{key:"API_KEY",value:"your-secret-key"},disabled:I,keyLabel:"Variable",valueLabel:"Value"})})]})]}):m==="sse"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"url",className:"text-right",children:"URL"}),l.jsx(ct,{id:"url",type:"url",value:T,onChange:j=>S(j.target.value),className:"col-span-3",placeholder:"e.g., http://localhost:8000/events",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Headers"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:w,onChange:N,placeholder:{key:"Authorization",value:"Bearer your-token"},disabled:I,keyLabel:"Header",valueLabel:"Value"})})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"url",className:"text-right",children:"URL"}),l.jsx(ct,{id:"url",type:"url",value:T,onChange:j=>S(j.target.value),className:"col-span-3",placeholder:"e.g., http://localhost:8080",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Headers"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:w,onChange:N,placeholder:{key:"Authorization",value:"Bearer your-token"},disabled:I,keyLabel:"Header",valueLabel:"Value"})})]})]}),l.jsxs("div",{className:"flex items-center space-x-2 pt-2",children:[l.jsx(gI,{id:"persistToAgent",checked:K,onCheckedChange:j=>L(j===!0),disabled:I}),l.jsx(fn,{htmlFor:"persistToAgent",className:"text-sm font-normal cursor-pointer",children:"Save to agent configuration file"})]})]}),l.jsxs(Ui,{children:[l.jsx(D4,{asChild:!0,children:l.jsx(Pe,{type:"button",variant:"outline",disabled:I,children:"Cancel"})}),l.jsx(Pe,{type:"submit",form:"connectServerForm",disabled:I,children:I?"Connecting...":"Connect"})]})]})})}var Ose=[{id:"filesystem",name:"Filesystem",description:"Secure file operations with configurable access controls for reading and writing files",category:"productivity",icon:"📁",config:{type:"stdio",command:"npx",args:["-y","@modelcontextprotocol/server-filesystem","."],timeout:3e4},tags:["file","directory","filesystem","io"],isOfficial:!0,isInstalled:!1,author:"Anthropic",homepage:"https://github.com/modelcontextprotocol/servers",matchIds:["filesystem"]},{id:"meme-mcp",name:"Meme Generator",description:"Create memes using Imgflip templates",category:"creative",icon:"🖼️",config:{type:"stdio",command:"npx",args:["-y","meme-mcp"],env:{IMGFLIP_USERNAME:"",IMGFLIP_PASSWORD:""},timeout:3e4},tags:["meme","image","creative"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Community",homepage:"https://www.npmjs.com/package/meme-mcp",matchIds:["meme-mcp"]},{id:"product-name-scout",name:"Product Name Scout",description:"SERP analysis, autocomplete, dev collisions, and scoring for product names",category:"research",icon:"🔎",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/product-name-scout-mcp"],timeout:3e4},tags:["research","naming","brand"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["product-name-scout"]},{id:"duckduckgo",name:"DuckDuckGo Search",description:"Search the web using DuckDuckGo",category:"research",icon:"🦆",config:{type:"stdio",command:"uvx",args:["duckduckgo-mcp-server"],timeout:3e4},tags:["search","web","research"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",python:">=3.10",dependencies:["uv"]},author:"Community",homepage:"https://github.com/duckduckgo/mcp-server",matchIds:["duckduckgo","ddg"]},{id:"domain-checker",name:"Domain Checker",description:"Check domain availability across TLDs",category:"research",icon:"🌐",config:{type:"stdio",command:"uvx",args:["truffle-ai-domain-checker-mcp"],timeout:3e4},tags:["domains","availability","research"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["domain-checker"]},{id:"swiggy-food",name:"Swiggy Food",description:"Order food with restaurant search, menus, cart management, and checkout",category:"productivity",icon:"🍔",config:{type:"http",url:"https://mcp.swiggy.com/food",timeout:3e4},tags:["swiggy","food","delivery","ordering"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-food","swiggy_food"]},{id:"swiggy-instamart",name:"Swiggy Instamart",description:"Shop groceries with product search, cart management, and checkout",category:"productivity",icon:"🛒",config:{type:"http",url:"https://mcp.swiggy.com/im",timeout:3e4},tags:["swiggy","instamart","groceries","delivery"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-instamart","swiggy_instamart"]},{id:"swiggy-dineout",name:"Swiggy Dineout",description:"Find restaurants, check availability, and book tables",category:"productivity",icon:"🍽️",config:{type:"http",url:"https://mcp.swiggy.com/dineout",timeout:3e4},tags:["swiggy","dineout","reservations","restaurants"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-dineout","swiggy_dineout"]},{id:"linear",name:"Linear",description:"Manage Linear issues, projects, and workflows",category:"productivity",icon:"📋",config:{type:"stdio",command:"npx",args:["-y","mcp-remote","https://mcp.linear.app/sse"],timeout:3e4},tags:["linear","tasks","projects"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Linear",homepage:"https://mcp.linear.app",matchIds:["linear"]},{id:"image-editor",name:"Image Editor",description:"Comprehensive image processing and manipulation tools",category:"creative",icon:"🖌️",config:{type:"stdio",command:"uvx",args:["truffle-ai-image-editor-mcp"],timeout:3e4},tags:["image","edit","opencv","pillow"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["image_editor","image-editor"]},{id:"music-creator",name:"Music Creator",description:"Create, analyze, and transform music and audio",category:"creative",icon:"🎵",config:{type:"stdio",command:"uvx",args:["truffle-ai-music-creator-mcp"],timeout:3e4},tags:["audio","music","effects"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["music_creator","music-creator"]},{id:"elevenlabs",name:"ElevenLabs",description:"Text-to-speech and voice synthesis using ElevenLabs API",category:"creative",icon:"🎤",config:{type:"stdio",command:"uvx",args:["elevenlabs-mcp"],env:{ELEVENLABS_API_KEY:""},timeout:3e4},tags:["tts","voice","audio","synthesis"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"ElevenLabs",homepage:"https://github.com/elevenlabs/elevenlabs-mcp",matchIds:["elevenlabs"]},{id:"hf",name:"Hugging Face",description:"Access Hugging Face models and datasets",category:"development",icon:"🤗",config:{type:"stdio",command:"npx",args:["-y","@llmindset/mcp-hfspace"],timeout:3e4},tags:["huggingface","models","ai","ml"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"LLMindset",homepage:"https://github.com/llmindset/mcp-hfspace",matchIds:["hf","huggingface"]},{id:"tavily",name:"Tavily Search",description:"Web search and research using Tavily AI search engine",category:"research",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","tavily-mcp@0.1.3"],env:{TAVILY_API_KEY:""},timeout:3e4},tags:["search","web","research","ai"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Tavily AI",homepage:"https://www.npmjs.com/package/tavily-mcp",matchIds:["tavily"]},{id:"puppeteer",name:"Puppeteer",description:"Browser automation and web interaction tools",category:"productivity",icon:"🌐",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/puppeteer-server"],timeout:3e4},tags:["browser","automation","web","puppeteer"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["puppeteer"]},{id:"gemini-tts",name:"Gemini TTS",description:"Google Gemini Text-to-Speech with 30 prebuilt voices and multi-speaker conversation support",category:"creative",icon:"🎙️",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/gemini-tts-server"],env:{GEMINI_API_KEY:""},timeout:6e4},tags:["tts","speech","voice","audio","gemini","multi-speaker"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["gemini-tts","gemini_tts"]},{id:"nano-banana",name:"Nano Banana",description:"Google Gemini 2.5 Flash Image for advanced image generation, editing, and manipulation",category:"creative",icon:"🍌",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/nano-banana-server@0.1.2"],env:{GEMINI_API_KEY:""},timeout:6e4},tags:["image","generation","editing","ai","gemini","nano-banana"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["nano-banana","nano_banana"]},{id:"openai-image",name:"OpenAI Image",description:"OpenAI's image generation and editing API with GPT Image models and DALL-E support",category:"creative",icon:"🎨",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/openai-image-server"],env:{OPENAI_API_KEY:""},timeout:6e4},tags:["image","generation","editing","ai","openai","dall-e","gpt-image"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers/tree/main/src/openai-image",matchIds:["openai-image","openai_image"]},{id:"heygen",name:"HeyGen",description:"Generate realistic human-like audio using HeyGen",category:"creative",icon:"🎤",config:{type:"stdio",command:"uvx",args:["heygen-mcp"],env:{HEYGEN_API_KEY:""},timeout:3e4},tags:["audio","voice","synthesis","heygen"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"HeyGen",homepage:"https://github.com/heygen-com/heygen-mcp",matchIds:["heygen"]},{id:"runway",name:"Runway",description:"AI-powered creative suite for video and image generation",category:"creative",icon:"🎬",config:{type:"stdio",command:"npx",args:["mcp-remote","https://mcp.runway.team","--header","Authorization: Bearer ${RUNWAY_API_KEY}"],env:{RUNWAY_API_KEY:""},timeout:6e4},tags:["runway","video","generation","ai","creative"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Runway",homepage:"https://docs.runway.team/api/runway-mcp-server",matchIds:["runway"]},{id:"perplexity",name:"Perplexity",description:"AI-powered search engine for real-time web search and research",category:"research",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","@perplexity-ai/mcp-server"],env:{PERPLEXITY_API_KEY:"",PERPLEXITY_TIMEOUT_MS:"600000"},timeout:6e5},tags:["search","web","research","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Perplexity AI",homepage:"https://github.com/perplexityai/modelcontextprotocol/tree/main",matchIds:["perplexity"]},{id:"sora",name:"Sora",description:"AI-powered video generation using OpenAI's Sora technology",category:"creative",icon:"🎬",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/sora-video-server"],env:{OPENAI_API_KEY:""},timeout:6e4},tags:["video","generation","ai","creative"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["sora","sora_video"]},{id:"chartjs",name:"ChartJS",description:"Charting and visualization tool using ChartJS",category:"data",icon:"📊",config:{type:"stdio",command:"npx",args:["-y","@ax-crew/chartjs-mcp-server"],timeout:3e4},tags:["chart","visualization","data","chartjs"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"ax-crew",homepage:"https://github.com/ax-crew/chartjs-mcp-server",matchIds:["chartjs"]},{id:"rag-lite-ts",name:"Rag-lite TS",description:"A local-first TypeScript retrieval engine for semantic search over static documents.",category:"data",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","raglite-mcp"],timeout:3e4},tags:["rag","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"FrugalX",homepage:"https://github.com/raglite/rag-lite-ts",matchIds:["rag-lite-ts"]},{id:"exa",name:"Exa",description:"AI-powered web search and research API with semantic search capabilities.",category:"data",icon:"🔍",config:{type:"http",url:"https://mcp.exa.ai/mcp",headers:{}},tags:["rag","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Exa",homepage:"https://docs.exa.ai/reference/exa-mcp",matchIds:["exa"]},{id:"firecrawl",name:"Firecrawl",description:"AI-powered web search and research API that performs semantic search across web sources, aggregates and ranks results for relevance, and returns contextual summaries with citations",category:"data",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","firecrawl-mcp"],env:{FIRECRAWL_API_KEY:""},timeout:3e4},tags:["search","web","research","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Firecrawl",homepage:"https://docs.firecrawl.dev/mcp-server",matchIds:["firecrawl"]},{id:"shadcn",name:"Shadcn",description:"Shadcn UI components for MCP servers",category:"development",icon:"🖌️",config:{type:"stdio",command:"npx",args:["shadcn@latest","mcp"],timeout:3e4},tags:["shadcn","ui","components","mcp"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Shadcn",homepage:"https://ui.shadcn.com/docs/mcp#configuration",matchIds:["shadcn"]},{id:"kite-trade",name:"Kite",description:"Zerodha Kite API MCP server",category:"data",icon:"💰",config:{type:"http",url:"https://mcp.kite.trade/mcp",headers:{}},tags:["kite","trade","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Zerodha",homepage:"https://github.com/zerodha/kite-mcp-server",matchIds:["kite-trade"]},{id:"coingecko",name:"CoinGecko",description:"CoinGecko API MCP server",category:"data",icon:"💰",config:{type:"http",url:"https://mcp.api.coingecko.com/mcp",headers:{}},tags:["coingecko","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"CoinGecko",homepage:"https://docs.coingecko.com/docs/mcp-server",matchIds:["coingecko"]}];function HP(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}var Fse=class _d{static instance;registryEntries=[];isInitialized=!1;constructor(){}static getInstance(){return _d.instance||(_d.instance=new _d),_d.instance}async initialize(){this.isInitialized||(this.registryEntries=Ose,this.isInitialized=!0)}async getEntries(t){await this.initialize();let n=[...this.registryEntries];if(t?.category&&(n=n.filter(r=>r.category===t.category)),t?.tags?.length&&(n=n.filter(r=>t.tags.some(i=>r.tags.includes(i)))),t?.search){const r=t.search.toLowerCase();n=n.filter(i=>i.name.toLowerCase().includes(r)||i.description.toLowerCase().includes(r)||i.tags.some(s=>s.toLowerCase().includes(r)))}return t?.installed!==void 0&&(n=n.filter(r=>r.isInstalled===t.installed)),t?.official!==void 0&&(n=n.filter(r=>r.isOfficial===t.official)),n.sort((r,i)=>r.isInstalled!==i.isInstalled?r.isInstalled?-1:1:r.isOfficial!==i.isOfficial?r.isOfficial?-1:1:r.name.localeCompare(i.name))}async updateEntry(t,n){await this.initialize();const r=this.registryEntries.find(i=>i.id===t);return r?(Object.assign(r,n),!0):!1}async setInstalled(t,n){return this.updateEntry(t,{isInstalled:n})}async syncInstalledStatus(t){await this.initialize();const n=new Set(t.map(HP));for(const r of this.registryEntries){const s=[r.id,r.name,...r.matchIds||[]].filter(Boolean).map(o=>HP(String(o))).some(o=>n.has(o));r.isInstalled!==s&&(r.isInstalled=s)}}async getServerConfig(t){return await this.initialize(),this.registryEntries.find(n=>n.id===t)||null}async getCategories(){await this.initialize();const t=new Set(this.registryEntries.map(n=>n.category));return Array.from(t).sort()}async getTags(){await this.initialize();const t=new Set(this.registryEntries.flatMap(n=>n.tags));return Array.from(t).sort()}},Use=Fse.getInstance();class xo{constructor(){this.registryEntries=[],this.isInitialized=!1}static normalizeId(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return xo.instance||(xo.instance=new xo),xo.instance}async initialize(){this.isInitialized||(this.registryEntries=await this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(t){await this.initialize();let n=[...this.registryEntries];if(t?.category&&(n=n.filter(r=>r.category===t.category)),t?.tags?.length&&(n=n.filter(r=>t.tags.some(i=>r.tags.includes(i)))),t?.search){const r=t.search.toLowerCase();n=n.filter(i=>i.name.toLowerCase().includes(r)||i.description.toLowerCase().includes(r)||i.tags.some(s=>s.toLowerCase().includes(r)))}return t?.installed!==void 0&&(n=n.filter(r=>r.isInstalled===t.installed)),t?.official!==void 0&&(n=n.filter(r=>r.isOfficial===t.official)),n.sort((r,i)=>r.isInstalled!==i.isInstalled?r.isInstalled?-1:1:r.isOfficial!==i.isOfficial?r.isOfficial?-1:1:r.name.localeCompare(i.name))}async updateEntry(t,n){const r=this.registryEntries.findIndex(i=>i.id===t);return r===-1?!1:(this.registryEntries[r]={...this.registryEntries[r],...n},!0)}async setInstalled(t,n){return this.updateEntry(t,{isInstalled:n})}async syncWithServerStatus(){try{if(await this.initialize(),this.registryEntries.length===0){console.warn("Registry entries not available for status sync");return}const t=await Xe.api.mcp.servers.$get();if(!t.ok)throw new Error(`Failed to fetch servers: ${t.status}`);const r=(await t.json()).servers||[],i=new Set;r.forEach(s=>{if(!s?.id||typeof s.id!="string")return;const o=xo.normalizeId(s.id);i.add(o)});for(const s of this.registryEntries){const d=[s.id,s.name,...s.matchIds||[]].filter(Boolean).map(m=>xo.normalizeId(String(m))).some(m=>i.has(m));s.isInstalled!==d&&(s.isInstalled=d)}}catch(t){console.warn("Failed to sync registry with server status:",t)}}async getServerConfig(t){return await this.initialize(),this.registryEntries.find(n=>n.id===t)||null}async getBuiltinEntries(){return Use.getEntries()}}const Ts=xo.getInstance();function m1({isOpen:e,onClose:t,onInstallServer:n,onOpenConnectModal:r,refreshTrigger:i,disableClose:s=!1}){const[o,c]=b.useState([]),[d,m]=b.useState([]),[f,g]=b.useState(!1),[y,x]=b.useState(null),[k,T]=b.useState(null),[S]=b.useState({}),[w,N]=b.useState(""),[M,P]=b.useState("grid"),[D,E]=b.useState(null),I=b.useRef(null),R=b.useRef(!0),K=b.useRef(null);b.useEffect(()=>(R.current=!0,()=>{R.current=!1,I.current&&clearTimeout(I.current),K.current&&K.current.abort()}),[]),b.useEffect(()=>{if(!e)return;(async()=>{K.current&&K.current.abort();const W=new AbortController;if(K.current=W,!!R.current){g(!0),x(null);try{await Ts.syncWithServerStatus();const z=await Ts.getEntries();R.current&&!W.signal.aborted&&(c(z),m(z))}catch(z){if(R.current&&!W.signal.aborted){const $=z instanceof Error?z.message:"Failed to load server registry";x($)}}finally{R.current&&!W.signal.aborted&&g(!1)}}})()},[e,i]);const L=b.useCallback(async(j,W)=>{if(R.current)try{const z=await Ts.getEntries({...j,search:W||void 0});R.current&&m(z)}catch(z){if(R.current){const $=z instanceof Error?z.message:"Failed to filter entries";x($)}}},[]);b.useEffect(()=>(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{L(S,w)},300),()=>{I.current&&clearTimeout(I.current)}),[S,w,o,L]);const U=async j=>{if(R.current){T(j.id);try{await n(j)==="connected"?(await Ts.setInstalled(j.id,!0),R.current&&(c(z=>z.map($=>$.id===j.id?{...$,isInstalled:!0}:$)),m(z=>z.map($=>$.id===j.id?{...$,isInstalled:!0}:$)))):R.current&&(c(z=>z.map($=>$.id===j.id?{...$,isInstalled:!1}:$)),m(z=>z.map($=>$.id===j.id?{...$,isInstalled:!1}:$)))}catch(W){if(R.current){const z=W instanceof Error?W.message:"Failed to install server";x(z)}}finally{R.current&&T(null)}}},G=j=>{const W={productivity:"bg-blue-50 text-blue-700 border-blue-200/60",development:"bg-emerald-50 text-emerald-700 border-emerald-200/60",research:"bg-purple-50 text-purple-700 border-purple-200/60",creative:"bg-pink-50 text-pink-700 border-pink-200/60",data:"bg-amber-50 text-amber-700 border-amber-200/60",communication:"bg-indigo-50 text-indigo-700 border-indigo-200/60",custom:"bg-slate-50 text-slate-700 border-slate-200/60"};return W[j]||W.custom},Y=s||!!k,B=b.useCallback(j=>{!j&&!Y&&t()},[Y,t]),q=Y?j=>{j.preventDefault()}:void 0;return l.jsx(qr,{open:e,onOpenChange:B,children:l.jsxs(Gr,{className:"!max-w-none w-[90vw] max-h-[85vh] overflow-hidden flex flex-col !sm:max-w-none p-0 bg-gradient-to-b from-background via-background to-muted/20",hideCloseButton:!0,onEscapeKeyDown:Y?j=>j.preventDefault():void 0,onInteractOutside:q,children:[l.jsx(ti,{className:"pb-4 border-b px-6 pt-5 bg-gradient-to-r from-muted/30 via-transparent to-transparent",children:l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:l.jsx(So,{className:"h-5 w-5 text-primary"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx(Hr,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),l.jsx(is,{className:"text-sm text-muted-foreground",children:"Discover and add integrations to your AI assistant"})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Pe,{onClick:()=>{Y||t(),r?.()},size:"sm",variant:"outline",className:"h-8 px-3 text-sm font-medium hover:bg-muted whitespace-nowrap",children:[l.jsx(kB,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),l.jsxs(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>t(),disabled:Y,children:[l.jsx(Cn,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}),l.jsxs("div",{className:"flex gap-3 mb-5 px-6 pt-5",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60 pointer-events-none z-10"}),l.jsx(ct,{placeholder:"Search servers and integrations...",value:w,onChange:j=>N(j.target.value),className:"pl-10 h-10 border focus:border-primary/40 bg-background text-sm placeholder:text-muted-foreground/50 focus:ring-1 focus:ring-primary/20 transition-all"})]}),l.jsxs("div",{className:"flex bg-muted/50 rounded-md p-1 border",children:[l.jsxs(Pe,{variant:M==="grid"?"secondary":"ghost",size:"sm",onClick:()=>{P("grid"),E(null)},className:se("h-8 px-3 rounded-sm transition-all text-sm font-medium",M==="grid"?"bg-background shadow-sm":"hover:bg-background/50"),children:[l.jsx(QB,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),l.jsxs(Pe,{variant:M==="list"?"secondary":"ghost",size:"sm",onClick:()=>{P("list"),E(null)},className:se("h-8 px-3 rounded-sm transition-all text-sm font-medium",M==="list"?"bg-background shadow-sm":"hover:bg-background/50"),children:[l.jsx(oq,{className:"h-3.5 w-3.5 mr-1.5"}),"List"]})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:[y&&l.jsx(ri,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:l.jsx(ii,{className:"text-red-800 font-medium",children:y})}),f?l.jsx("div",{className:"flex items-center justify-center py-24",children:l.jsxs("div",{className:"flex flex-col items-center space-y-5",children:[l.jsx("div",{className:"h-12 w-12 border-4 border-primary/30 border-t-primary rounded-full animate-spin"}),l.jsx("div",{className:"text-lg text-foreground font-semibold",children:"Discovering servers..."}),l.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading registry entries"})]})}):d.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[l.jsx("div",{className:"p-6 rounded-2xl bg-gradient-to-br from-muted/50 to-muted/30 border-2 border-border/30 mb-6 shadow-sm",children:l.jsx(So,{className:"h-14 w-14 text-muted-foreground/60 mx-auto"})}),l.jsx("div",{className:"text-xl font-bold text-foreground mb-3",children:o.length===0?"No servers available in the registry":"No servers match your search"}),l.jsx("div",{className:"text-base text-muted-foreground/80 mb-6 max-w-md",children:o.length===0?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),w&&l.jsxs(Pe,{variant:"outline",onClick:()=>N(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[l.jsx(Rr,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):l.jsx("div",{className:se(M==="grid"?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:d.map((j,W)=>{const z=D===j.id,$=j.description&&j.description.length>100;return M==="grid"?l.jsx(n1,{className:se("group relative overflow-hidden transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-lg hover:border-primary/30 flex flex-col",z&&"ring-1 ring-primary/20 border-primary/40 shadow-lg -translate-y-0.5"),style:{animationDelay:`${Math.min(W*30,300)}ms`},children:l.jsxs("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>E(z?null:j.id),children:[l.jsx(Cte,{className:"pb-3 flex-shrink-0",children:l.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsx("div",{className:"text-2xl w-12 h-12 flex items-center justify-center rounded-lg bg-gradient-to-br from-primary/15 to-primary/5 border border-primary/20 group-hover:border-primary/30 transition-all duration-200",children:j.icon||"⚡"}),j.isInstalled&&l.jsx("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-emerald-500 rounded-full border-2 border-card flex items-center justify-center",children:l.jsx(Ls,{className:"h-2.5 w-2.5 text-white"})})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx(Ete,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-snug line-clamp-2",children:j.name}),l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[j.isOfficial&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[l.jsx(Sb,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),j.category&&l.jsx(Qn,{variant:"outline",className:se("text-xs px-1.5 py-0 font-medium capitalize",G(j.category)),children:j.category})]})]})]})}),l.jsxs(Dte,{className:"pt-0 flex flex-col flex-1",children:[l.jsxs("div",{className:"flex-1",children:[l.jsx("p",{className:se("text-sm text-muted-foreground leading-relaxed transition-all duration-200",z?"":"line-clamp-3"),children:j.description}),z&&l.jsxs("div",{className:"space-y-3 pt-3 mt-3 border-t border-border/30 animate-in slide-in-from-top-1 duration-200",children:[j.author&&l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("div",{className:"p-1 rounded bg-muted/40",children:l.jsx(YM,{className:"h-3 w-3 text-muted-foreground"})}),l.jsxs("div",{children:[l.jsxs("span",{className:"text-muted-foreground/70",children:["by"," "]}),l.jsx("span",{className:"font-medium text-foreground",children:j.author})]})]}),j.tags&&j.tags.length>0&&l.jsxs("div",{className:"flex flex-wrap gap-1",children:[j.tags.slice(0,6).map(A=>l.jsx(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:A},A)),j.tags.length>6&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20",children:["+",j.tags.length-6]})]}),j.homepage&&l.jsxs("a",{href:j.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:A=>A.stopPropagation(),children:[l.jsx(yc,{className:"h-3 w-3"}),"Documentation"]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-border/30 flex-shrink-0 mt-auto",children:[$&&l.jsx(Pe,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-foreground p-0 h-auto font-medium -ml-1",children:z?l.jsxs(l.Fragment,{children:[l.jsx(Sg,{className:"h-3 w-3 mr-1"}),"Less"]}):l.jsxs(l.Fragment,{children:[l.jsx(Ir,{className:"h-3 w-3 mr-1"}),"More"]})}),l.jsx("div",{className:"ml-auto",children:l.jsx(Pe,{onClick:A=>{A.stopPropagation(),U(j)},disabled:j.isInstalled||k===j.id,size:"sm",variant:j.isInstalled?"outline":"default",className:se("h-8 px-4 transition-all font-semibold text-sm shadow-sm",k===j.id&&"opacity-70",j.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!j.isInstalled&&"bg-primary hover:bg-primary/90"),children:k===j.id?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),l.jsx("span",{children:"Adding"})]}):j.isInstalled?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ls,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Added"})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xi,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Add"})]})})})]})]})]})},j.id):l.jsx(n1,{className:se("group transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-md hover:border-primary/30 cursor-pointer !py-0 !gap-0",z&&"border-primary/40 shadow-md -translate-y-0.5"),onClick:()=>E(z?null:j.id),children:l.jsx("div",{className:"p-4",children:l.jsxs("div",{className:"flex items-start gap-4",children:[l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsx("div",{className:"w-12 h-12 rounded-lg bg-gradient-to-br from-primary/15 to-primary/5 border border-primary/20 group-hover:border-primary/30 flex items-center justify-center text-2xl transition-all duration-200",children:j.icon||"⚡"}),j.isInstalled&&l.jsx("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-emerald-500 rounded-full border-2 border-card flex items-center justify-center",children:l.jsx(Ls,{className:"h-2.5 w-2.5 text-white"})})]}),l.jsxs("div",{className:"flex-1 min-w-0 space-y-2.5",children:[l.jsxs("div",{className:"flex items-start justify-between gap-4",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[l.jsx("h3",{className:"text-base font-semibold text-foreground group-hover:text-primary transition-colors leading-snug",children:j.name}),$&&l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",z&&"rotate-180 text-muted-foreground")})]}),l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[j.isOfficial&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[l.jsx(Sb,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),j.category&&l.jsx(Qn,{variant:"outline",className:se("text-xs px-1.5 py-0 font-medium capitalize",G(j.category)),children:j.category})]})]}),l.jsx(Pe,{onClick:A=>{A.stopPropagation(),U(j)},disabled:j.isInstalled||k===j.id,size:"sm",variant:j.isInstalled?"outline":"default",className:se("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",k===j.id&&"opacity-70",j.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!j.isInstalled&&"bg-primary hover:bg-primary/90"),children:k===j.id?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),l.jsx("span",{children:"Adding"})]}):j.isInstalled?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ls,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Added"})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xi,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Add"})]})})]}),l.jsx("div",{children:l.jsx("p",{className:se("text-sm text-muted-foreground leading-relaxed transition-all duration-200",z?"":"line-clamp-2"),children:j.description})}),z&&l.jsxs("div",{className:"space-y-3 pt-3 border-t border-border/30 animate-in slide-in-from-top-2 duration-200",children:[j.author&&l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("div",{className:"p-1 rounded bg-muted/40",children:l.jsx(YM,{className:"h-3 w-3 text-muted-foreground"})}),l.jsxs("div",{children:[l.jsxs("span",{className:"text-muted-foreground/70",children:["by"," "]}),l.jsx("span",{className:"font-medium text-foreground",children:j.author})]})]}),j.tags&&j.tags.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:j.tags.map(A=>l.jsx(Qn,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:A},A))}),j.homepage&&l.jsxs("a",{href:j.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:A=>A.stopPropagation(),children:[l.jsx(yc,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},j.id)})})]})]})})}const Lse=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),zse=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],$se=[/^your[\s_-]?/,/^enter[\s_-]?/];function ug(e){return Object.values(e).some(t=>{if(!t||t.trim()==="")return!0;const n=t.trim().toLowerCase();return Lse.has(n)||$se.some(r=>r.test(n))?!0:zse.some(r=>n.includes(r))})}function xI(e){const t=e.config.timeout??3e4;switch(e.config.type){case"stdio":return{type:"stdio",command:e.config.command??"",args:e.config.args??[],env:e.config.env??{},timeout:t,connectionMode:"lenient"};case"sse":return{type:"sse",url:e.config.url??"",headers:e.config.headers??{},timeout:t,connectionMode:"lenient"};default:return{type:"http",url:e.config.url??"",headers:e.config.headers??{},timeout:t,connectionMode:"lenient"}}}function Bse(e=!0){return Dn({queryKey:Ge.tools.all,queryFn:async()=>{const t=await Xe.api.tools.$get();if(!t.ok)throw new Error("Failed to fetch tools");return await t.json()},enabled:e})}function qse(){return Dn({queryKey:Ge.agents.all,queryFn:async()=>{const e=await Xe.api.agents.$get();if(!e.ok)throw new Error(`Failed to fetch agents: ${e.status}`);return await e.json()},staleTime:300*1e3})}function vI(){return Dn({queryKey:Ge.agents.path,queryFn:async()=>{const e=await Xe.api.agent.path.$get();if(!e.ok)throw new Error(`Failed to fetch agent path: ${e.status}`);return await e.json()},retry:!1,staleTime:300*1e3})}function Gse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.switch.$post({json:t});if(!n.ok)throw new Error(`Failed to switch agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all}),e.invalidateQueries({queryKey:Ge.agents.path})}})}function Hse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.install.$post({json:t});if(!n.ok)throw new Error(`Failed to install agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all})}})}function Vse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.uninstall.$post({json:t});if(!n.ok)throw new Error(`Failed to uninstall agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all}),e.invalidateQueries({queryKey:Ge.agents.path})}})}function Kse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.custom.create.$post({json:t});if(!n.ok)throw new Error(`Failed to create agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all})}})}function VP(e,t){if(t!=="mcp"||!e.startsWith("mcp--"))return e;const n=e.substring(5),r=n.split("--");return r.length>=2?r.slice(1).join("--"):n}function KP({isOpen:e,onClose:t,onOpenConnectModal:n,onOpenConnectWithPrefill:r,onServerConnected:i,variant:s,refreshTrigger:o}){const c=s??"overlay",d=Cc(),[m,f]=b.useState(!1),[g,y]=b.useState(!1),[x,k]=b.useState(""),[T,S]=b.useState(null),[w,N]=b.useState(new Set),{data:M=[],isLoading:P,refetch:D}=mD(e),E=i2(),I=dH(),R=mH(),{data:K,isLoading:L,refetch:U}=Bse(e),{data:G}=vI(),Y=b.useCallback(()=>{D(),U()},[D,U]),B=b.useCallback(Q=>{N(ne=>{const O=new Set(ne);return O.has(Q)?O.delete(Q):O.add(Q),O})},[]),q=b.useMemo(()=>{if(!K)return{local:[],mcp:new Map};const Q=[],ne=new Map;return K.tools.forEach(O=>{if(O.source==="local")Q.push(O);else if(O.source==="mcp"&&O.serverName){const be=ne.get(O.serverName)||{tools:[],server:null};if(be.tools.push(O),!be.server){const Ue=M.find(Ce=>Ce.name===O.serverName);be.server=Ue||null}ne.set(O.serverName,be)}}),{local:Q,mcp:ne}},[K,M]),j=b.useMemo(()=>{const Q=[],ne=x.toLowerCase();if(q.local.length>0){const O=x?q.local.filter(be=>be.name.toLowerCase().includes(ne)||be.description?.toLowerCase().includes(ne)):q.local;O.length>0&&Q.push({title:"Local",tools:O,type:"local"})}return q.mcp.forEach(({tools:O,server:be},Ue)=>{const Ce=Ue.toLowerCase().includes(ne),ae=x?Ce?O:O.filter(ze=>ze.name.toLowerCase().includes(ne)||ze.description?.toLowerCase().includes(ne)):O;ae.length>0&&Q.push({title:Ue,tools:ae,type:"mcp",server:be})}),Q},[q,x]),W=K?.totalCount||0,z=async Q=>{const ne=xI(Q),O=ne.type==="stdio"&&Object.keys(ne.env||{}).length>0&&ug(ne.env||{}),be=(ne.type==="sse"||ne.type==="http")&&Object.keys(ne.headers||{}).length>0&&ug(ne.headers||{});if(O||be)return typeof r=="function"&&r({name:Q.name,config:ne,lockName:!0,registryEntryId:Q.id,onCloseRegistryModal:()=>f(!1)}),"requires-input";try{y(!0),await E.mutateAsync({name:Q.name,config:ne,persistToAgent:!1});try{await Ts.syncWithServerStatus()}catch(Ue){console.warn("Failed to sync registry after server install:",Ue)}return d.trackMCPServerConnected({serverName:Q.name,transportType:ne.type}),f(!1),i?.(Q.name),"connected"}catch(Ue){throw new Error(Ue.message||"Failed to install server")}finally{y(!1)}},$=async Q=>{const ne=M.find(O=>O.id===Q);if(ne&&window.confirm(`Are you sure you want to remove server "${ne.name}"?`))try{await I.mutateAsync(Q);try{const O=ae=>ae.toLowerCase().replace(/[^a-z0-9]+/g,"-"),be=O(Q),Ce=(await Ts.getEntries()).find(ae=>[ae.id,ae.name,...ae.matchIds||[]].filter(Boolean).map(lt=>O(String(lt))).includes(be));Ce&&await Ts.setInstalled(Ce.id,!1)}catch(O){console.warn("Failed to update registry installed state on delete:",O)}try{await Ts.syncWithServerStatus()}catch(O){console.warn("Failed to sync registry status after server deletion:",O)}}catch(O){console.error("Delete server error:",O)}},A=async Q=>{const ne=M.find(O=>O.id===Q);if(ne&&window.confirm(`Restart server "${ne.name}"?`))try{await R.mutateAsync(Q);try{await Ts.syncWithServerStatus()}catch(O){console.warn("Failed to sync registry status after server restart:",O)}}catch(O){console.error("Restart server error:",O)}};return b.useEffect(()=>{e&&Y()},[e,G,o,Y]),c==="inline"?l.jsxs("aside",{className:"h-full w-full flex flex-col bg-card/30",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 shrink-0 border-b border-border/30",children:[l.jsxs("button",{onClick:t,className:"flex items-center gap-2 group",children:[l.jsx("h2",{className:"text-xs font-bold text-foreground/80 tracking-wider uppercase group-hover:text-foreground transition-colors",children:"Tools & Servers"}),l.jsx(Ir,{className:"h-3.5 w-3.5 text-muted-foreground/50 -rotate-90 transition-transform group-hover:text-foreground/70"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{side:"left",children:"Connect MCP servers"})]}),l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:Y,disabled:P||L,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Qi,{className:se("h-4 w-4",(P||L)&&"animate-spin")})})}),l.jsx(Vt,{side:"left",children:"Refresh"})]})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col",children:[l.jsx("div",{className:"px-4 pt-4 pb-3 border-b border-border/20",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/50 pointer-events-none"}),l.jsx("input",{type:"text",value:x,onChange:Q=>k(Q.target.value),placeholder:"Search tools...",className:"w-full pl-9 pr-3 py-2 text-sm bg-background/50 border border-border/40 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all placeholder:text-muted-foreground/40"}),x&&l.jsx("button",{onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-muted/50 rounded transition-colors",children:l.jsx(Cn,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-4",children:[L&&l.jsx("div",{className:"flex items-center justify-center py-16",children:l.jsxs("div",{className:"flex flex-col items-center space-y-3",children:[l.jsxs("div",{className:"relative",children:[l.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/20"}),l.jsx("div",{className:"absolute inset-0 h-8 w-8 rounded-full border-2 border-primary border-t-transparent animate-spin"})]}),l.jsx("span",{className:"text-xs font-medium text-muted-foreground/70",children:"Loading tools..."})]})}),!L&&W===0&&l.jsxs("div",{className:"text-center py-16",children:[l.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-full bg-muted/30 mb-4",children:l.jsx(VM,{className:"h-6 w-6 text-muted-foreground/40"})}),l.jsx("p",{className:"text-sm font-medium text-foreground/70 mb-1",children:"No tools available"}),l.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Connect an MCP server to get started"})]}),!L&&W>0&&j.length===0&&l.jsxs("div",{className:"text-center py-16",children:[l.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-full bg-muted/30 mb-4",children:l.jsx(Rr,{className:"h-6 w-6 text-muted-foreground/40"})}),l.jsx("p",{className:"text-sm font-medium text-foreground/70 mb-1",children:"No tools match your search"}),l.jsx("p",{className:"text-xs text-muted-foreground/60 mb-3",children:"Try a different search term"}),l.jsx("button",{onClick:()=>k(""),className:"text-xs font-medium text-primary hover:text-primary/80 transition-colors",children:"Clear search"})]}),j.map(Q=>{const ne=w.has(Q.title);return l.jsxs("div",{className:"mb-4 last:mb-0",children:[l.jsxs("div",{className:"w-full flex items-center justify-between gap-2 mb-3 px-1 group transition-all duration-150",children:[l.jsxs("button",{onClick:()=>B(Q.title),className:"flex items-center gap-2.5 flex-1 min-w-0 pb-2 border-b border-border/40 text-left",children:[l.jsx(Ir,{className:se("h-4 w-4 text-muted-foreground/50 shrink-0 transition-transform duration-200",ne&&"-rotate-90")}),l.jsxs("h4",{className:"text-base font-semibold text-foreground tracking-tight flex items-center gap-2.5",children:[l.jsx("span",{className:"tracking-normal",children:Q.title}),Q.type==="mcp"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px] font-semibold uppercase tracking-wider",children:"MCP"}),Q.server&&l.jsx("span",{className:se("inline-flex items-center justify-center w-5 h-5 rounded-full",Q.server.status==="connected"?"bg-green-500/10":"bg-red-500/10"),children:l.jsx("span",{className:se("w-2 h-2 rounded-full",Q.server.status==="connected"?"bg-green-600 dark:bg-green-400":"bg-red-600 dark:bg-red-400")})})]})]}),l.jsx("span",{className:"text-xs text-muted-foreground/50 font-medium",children:Q.tools.length})]}),Q.type==="mcp"&&Q.server&&l.jsxs("div",{className:"flex items-center gap-0.5",children:[R.isPending&&R.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>A(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-primary hover:bg-muted/50",disabled:I.isPending&&I.variables===Q.server.id,children:l.jsx(ZM,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Restart"})]}),I.isPending&&I.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>$(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-destructive hover:bg-muted/50",disabled:R.isPending&&R.variables===Q.server.id,children:l.jsx(Ar,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Remove"})]})]})]}),!ne&&l.jsx("div",{className:"space-y-0.5 ml-2",children:Q.tools.map(O=>{const be=O.id,Ue=T===be;return l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>S(Ue?null:be),className:"w-full px-3 py-2 rounded-md text-left hover:bg-muted/30 transition-all duration-150 group flex items-center justify-between gap-2",children:[l.jsx("span",{className:"text-sm text-foreground/90 truncate font-medium",children:VP(O.name,Q.type)}),l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/40 shrink-0 transition-transform duration-200",Ue&&"rotate-180")})]}),Ue&&l.jsxs("div",{className:"px-3 py-2.5 mb-1 bg-muted/15 rounded-md ml-2",children:[O.description&&l.jsx("p",{className:"text-xs text-muted-foreground/70 mb-2.5 leading-relaxed",children:O.description}),O.inputSchema?.properties&&Object.keys(O.inputSchema.properties).length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-[10px] text-muted-foreground/50 uppercase tracking-wider font-semibold",children:"Parameters"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.keys(O.inputSchema.properties).map(Ce=>l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded bg-muted/50 text-[10px] font-mono text-foreground/60 border border-border/20",children:Ce},Ce))})]})]})]},be)})})]},Q.title)})]})]}),l.jsx(m1,{isOpen:m,onClose:()=>f(!1),onInstallServer:z,onOpenConnectModal:n,disableClose:g})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:se("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",e?"opacity-100":"opacity-0 pointer-events-none"),onClick:t}),l.jsxs("aside",{className:se("fixed top-0 right-0 z-40 h-screen w-80 bg-card/95 backdrop-blur-xl border-l border-border/40 shadow-xl transition-transform duration-300 ease-in-out flex flex-col",e?"translate-x-0":"translate-x-full"),children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 shrink-0",children:[l.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{side:"left",children:"Connect MCP servers"})]}),l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:Y,disabled:P||L,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Qi,{className:se("h-4 w-4",(P||L)&&"animate-spin")})})}),l.jsx(Vt,{side:"left",children:"Refresh"})]}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:t,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Cn,{className:"h-4 w-4"})})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col",children:[l.jsx("div",{className:"px-4 pt-3 pb-2 border-b border-border/20",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/50 pointer-events-none"}),l.jsx("input",{type:"text",value:x,onChange:Q=>k(Q.target.value),placeholder:"Search tools...",className:"w-full pl-9 pr-3 py-2 text-sm bg-background/50 border border-border/40 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all placeholder:text-muted-foreground/40"}),x&&l.jsx("button",{onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-muted/50 rounded transition-colors",children:l.jsx(Cn,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[L&&l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[l.jsx(Qi,{className:"h-5 w-5 animate-spin text-muted-foreground/50"}),l.jsx("span",{className:"text-xs text-muted-foreground/70",children:"Loading tools..."})]})}),!L&&W===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(VM,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-muted-foreground/70",children:"No tools available"}),l.jsx("p",{className:"text-xs text-muted-foreground/50 mt-1",children:"Connect an MCP server to get started"})]}),!L&&W>0&&j.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-muted-foreground/70",children:"No tools match your search"}),l.jsx("button",{onClick:()=>k(""),className:"mt-2 text-xs text-primary hover:text-primary/80 transition-colors",children:"Clear search"})]}),j.map(Q=>{const ne=w.has(Q.title);return l.jsxs("div",{className:"mb-4 last:mb-0",children:[l.jsxs("div",{className:"w-full flex items-center justify-between gap-2 mb-3 px-1 group transition-all duration-150",children:[l.jsxs("button",{onClick:()=>B(Q.title),className:"flex items-center gap-2.5 flex-1 min-w-0 pb-2 border-b border-border/40 text-left",children:[l.jsx(Ir,{className:se("h-4 w-4 text-muted-foreground/50 shrink-0 transition-transform duration-200",ne&&"-rotate-90")}),l.jsxs("h4",{className:"text-base font-semibold text-foreground tracking-tight flex items-center gap-2.5",children:[l.jsx("span",{className:"tracking-normal",children:Q.title}),Q.type==="mcp"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px] font-semibold uppercase tracking-wider",children:"MCP"}),Q.server&&l.jsx("span",{className:se("inline-flex items-center justify-center w-5 h-5 rounded-full",Q.server.status==="connected"?"bg-green-500/10":"bg-red-500/10"),children:l.jsx("span",{className:se("w-2 h-2 rounded-full",Q.server.status==="connected"?"bg-green-600 dark:bg-green-400":"bg-red-600 dark:bg-red-400")})})]})]}),l.jsx("span",{className:"text-xs text-muted-foreground/50 font-medium",children:Q.tools.length})]}),Q.type==="mcp"&&Q.server&&l.jsxs("div",{className:"flex items-center gap-0.5",children:[R.isPending&&R.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>A(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-primary hover:bg-muted/50",disabled:I.isPending&&I.variables===Q.server.id,children:l.jsx(ZM,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Restart"})]}),I.isPending&&I.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>$(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-destructive hover:bg-muted/50",disabled:R.isPending&&R.variables===Q.server.id,children:l.jsx(Ar,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Remove"})]})]})]}),!ne&&l.jsx("div",{className:"space-y-0.5 ml-2",children:Q.tools.map(O=>{const be=O.id,Ue=T===be;return l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>S(Ue?null:be),className:"w-full px-3 py-2 rounded-md text-left hover:bg-muted/30 transition-all duration-150 group flex items-center justify-between gap-2",children:[l.jsx("span",{className:"text-sm text-foreground/90 truncate font-medium",children:VP(O.name,Q.type)}),l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/40 shrink-0 transition-transform duration-200",Ue&&"rotate-180")})]}),Ue&&l.jsxs("div",{className:"px-3 py-2.5 mb-1 bg-muted/15 rounded-md ml-2",children:[O.description&&l.jsx("p",{className:"text-xs text-muted-foreground/70 mb-2.5 leading-relaxed",children:O.description}),O.inputSchema?.properties&&Object.keys(O.inputSchema.properties).length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-[10px] text-muted-foreground/50 uppercase tracking-wider font-semibold",children:"Parameters"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.keys(O.inputSchema.properties).map(Ce=>l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded bg-muted/50 text-[10px] font-mono text-foreground/60 border border-border/20",children:Ce},Ce))})]})]})]},be)})})]},Q.title)})]})]}),l.jsx(m1,{isOpen:m,onClose:()=>f(!1),onInstallServer:z,onOpenConnectModal:n,disableClose:g})]})]})}const vm=b.forwardRef(({className:e,children:t,...n},r)=>l.jsx("div",{ref:r,className:se("relative overflow-auto",e),...n,children:t}));vm.displayName="ScrollArea";function Wse(e){return e.sort((t,n)=>{const r=t.lastActivity?new Date(t.lastActivity).getTime():0;return(n.lastActivity?new Date(n.lastActivity).getTime():0)-r})}function WP({isOpen:e,onClose:t,onExpand:n,currentSessionId:r,onSessionChange:i,returnToWelcome:s,variant:o="overlay",onSearchOpen:c,onNewChat:d,onSettingsOpen:m,onPlaygroundOpen:f,onThemeToggle:g,theme:y}){const[x,k]=b.useState(!1),[T,S]=b.useState(""),[w,N]=b.useState(!1),[M,P]=b.useState(null),[D,E]=b.useState(!1),[I,R]=b.useState(""),[K,L]=b.useState(null),{data:U=[],isLoading:G,error:Y}=lH(e),B=Wse([...U]),q=uH(),j=dD(),W=cH(),z=async()=>{const ae=await q.mutateAsync({sessionId:T.trim()||void 0});S(""),k(!1),i(ae.id)},$=async ae=>{await j.mutateAsync({sessionId:ae}),r===ae&&s()},A=async()=>{if(!M)return;await j.mutateAsync({sessionId:M}),r===M&&s(),N(!1),P(null)},Q=(ae,ze)=>{P(ae),R(ze||""),E(!0)},ne=async()=>{if(!(!M||!I.trim()))try{await W.mutateAsync({sessionId:M,title:I.trim()}),E(!1),P(null),R("")}catch(ae){console.error(`Failed to rename session: ${ae}`)}},O=async ae=>{try{await navigator.clipboard.writeText(ae),L(ae)}catch(ze){console.error(`Failed to copy session ID: ${ze}`)}};b.useEffect(()=>{if(K){const ae=setTimeout(()=>L(null),2e3);return()=>clearTimeout(ae)}},[K]);const be=ae=>{if(!ae)return"Unknown";const lt=Date.now()-ae,me=Math.floor(lt/6e4),pe=Math.floor(lt/36e5),J=Math.floor(lt/864e5);return me<1?"Just now":me<60?`${me}m ago`:pe<24?`${pe}h ago`:`${J}d ago`},Ue=l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"px-4 py-5",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{id:"sessionpanel-title",className:"flex items-center px-2",children:[l.jsx("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-6 w-auto dark:hidden"}),l.jsx("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-6 w-auto hidden dark:block"})]}),l.jsx("button",{onClick:t,className:"flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Collapse panel",children:l.jsx(fB,{className:"h-5 w-5"})})]})}),Y&&l.jsx("div",{className:"p-4",children:l.jsxs(ri,{variant:"destructive",children:[l.jsx(ns,{className:"h-4 w-4"}),l.jsx(ii,{children:Y.message})]})}),l.jsxs(vm,{className:"flex-1 scrollbar-thin",children:[l.jsxs("div",{className:"px-3 pt-2 pb-1 space-y-0.5",children:[d&&l.jsxs("button",{onClick:d,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(xi,{className:"h-4 w-4"}),l.jsx("span",{children:"New Chat"})]}),c&&l.jsxs("button",{onClick:c,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(Rr,{className:"h-4 w-4"}),l.jsx("span",{children:"Search"})]})]}),(d||c)&&l.jsx("div",{className:"h-2"}),!G&&B.length>0&&l.jsx("div",{className:"px-4 py-2",children:l.jsx("h2",{className:"text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider",children:"History"})}),G?l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsx(Qi,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):B.length===0?l.jsxs("div",{className:"text-center py-12 px-6",children:[l.jsx(UE,{className:"h-10 w-10 mx-auto mb-3 text-muted-foreground/30"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"No conversations yet"}),l.jsx("p",{className:"text-xs text-muted-foreground/60 mt-1",children:"Start chatting to see your history"})]}):l.jsx("div",{className:"px-3 py-2 space-y-0.5",children:B.map(ae=>{const ze=ae.title&&ae.title.trim().length>0?ae.title:ae.id,lt=r===ae.id;return l.jsx("div",{className:se("group relative px-3 py-1.5 rounded-lg transition-all cursor-pointer",lt?"bg-primary/5 before:absolute before:left-0 before:top-1.5 before:bottom-1.5 before:w-0.5 before:bg-primary before:rounded-full":"hover:bg-muted/40"),role:"button",tabIndex:0,"aria-current":lt?"page":void 0,onClick:()=>i(ae.id),onKeyDown:me=>{me.target===me.currentTarget&&(me.key==="Enter"||me.key===" ")&&(me.preventDefault(),i(ae.id))},children:l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("h3",{className:se("text-sm truncate flex-1 min-w-0",lt?"font-medium text-foreground":"text-muted-foreground"),children:ze}),l.jsx("span",{className:"text-[10px] text-muted-foreground/50 shrink-0 group-hover:opacity-0 transition-opacity",children:be(ae.lastActivity)}),l.jsxs(kc,{children:[l.jsx(wc,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:me=>me.stopPropagation(),className:"h-7 w-7 p-0 absolute right-2 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":"Session options",children:l.jsx(OE,{className:"h-4 w-4 text-muted-foreground"})})}),l.jsxs(Ol,{align:"end",className:"w-48",onClick:me=>me.stopPropagation(),children:[l.jsxs(Zt,{onClick:()=>Q(ae.id,ae.title??null),children:[l.jsx(wb,{className:"h-4 w-4 mr-2"}),"Rename"]}),l.jsxs(Zt,{onClick:()=>O(ae.id),children:[K===ae.id?l.jsx(ur,{className:"h-4 w-4 mr-2 text-green-500"}):l.jsx(Ao,{className:"h-4 w-4 mr-2"}),K===ae.id?"Copied!":"Copy Session ID"]}),l.jsx(ka,{}),l.jsxs(Zt,{onClick:()=>{ae.messageCount>0?(P(ae.id),N(!0)):$(ae.id)},className:"text-destructive focus:text-destructive",children:[l.jsx(Ar,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})]})},ae.id)})})]}),l.jsxs("div",{className:"border-t border-border/30 p-3 space-y-1",children:[f&&l.jsxs("button",{onClick:f,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(_b,{className:"h-4 w-4"}),l.jsx("span",{children:"MCP Playground"})]}),f&&(g||m)&&l.jsx("div",{className:"h-px bg-border/30 my-1"}),g&&l.jsxs("button",{onClick:g,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[y==="dark"?l.jsx(Mb,{className:"h-4 w-4 transition-transform duration-200 hover:rotate-180"}):l.jsx(kb,{className:"h-4 w-4 transition-transform duration-200 hover:rotate-12"}),l.jsx("span",{children:y==="dark"?"Light Mode":"Dark Mode"})]}),m&&l.jsxs("button",{onClick:m,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(Yd,{className:"h-4 w-4"}),l.jsx("span",{children:"Settings"})]})]}),l.jsx(qr,{open:x,onOpenChange:k,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsx(ti,{children:l.jsx(Hr,{children:"Start New Chat"})}),l.jsx("div",{className:"space-y-4",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(fn,{htmlFor:"sessionId",children:"Chat ID"}),l.jsx(ct,{id:"sessionId",value:T,onChange:ae=>S(ae.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),l.jsx(Pe,{onClick:z,children:"Start Chat"})]})]})}),l.jsx(qr,{open:w,onOpenChange:N,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-5 w-5 text-destructive"}),l.jsx("span",{children:"Delete Conversation"})]}),l.jsxs(is,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",M&&l.jsxs("span",{className:"block mt-2 font-medium",children:["Session:"," ",l.jsx("span",{className:"font-mono",children:M})]})]})]}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>N(!1),children:"Cancel"}),l.jsxs(Pe,{variant:"destructive",onClick:A,disabled:j.isPending&&j.variables?.sessionId===M,className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-4 w-4"}),l.jsx("span",{children:j.isPending&&j.variables?.sessionId===M?"Deleting...":"Delete Conversation"})]})]})]})}),l.jsx(qr,{open:D,onOpenChange:E,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(wb,{className:"h-5 w-5"}),l.jsx("span",{children:"Rename Chat"})]}),l.jsx(is,{children:"Enter a new name for this conversation."})]}),l.jsx("div",{className:"space-y-4",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(fn,{htmlFor:"renameTitle",children:"Chat Name"}),l.jsx(ct,{id:"renameTitle",value:I,onChange:ae=>R(ae.target.value),placeholder:"Enter chat name...",onKeyDown:ae=>{ae.key==="Enter"&&I.trim()&&ne()},autoFocus:!0})]})}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>E(!1),children:"Cancel"}),l.jsx(Pe,{onClick:ne,disabled:!I.trim()||W.isPending,children:W.isPending?"Saving...":"Save"})]})]})})]}),Ce=l.jsxs("div",{className:"flex flex-col h-full py-3 px-2 items-center",children:[l.jsx("button",{onClick:n,className:"flex items-center justify-center w-10 h-10 rounded-lg hover:bg-muted/40 transition-colors mb-3","aria-label":"Expand panel",children:l.jsx("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-7 w-7"})}),l.jsxs("div",{className:"flex flex-col gap-1 flex-1",children:[d&&l.jsx("button",{onClick:d,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"New chat",children:l.jsx(xi,{className:"h-5 w-5"})}),c&&l.jsx("button",{onClick:c,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Search",children:l.jsx(Rr,{className:"h-5 w-5"})})]}),l.jsxs("div",{className:"flex flex-col gap-1 pt-2 border-t border-border/30",children:[f&&l.jsx("button",{onClick:f,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"MCP Playground",children:l.jsx(_b,{className:"h-5 w-5"})}),g&&l.jsx("button",{onClick:g,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":y==="dark"?"Light mode":"Dark mode",children:y==="dark"?l.jsx(Mb,{className:"h-5 w-5"}):l.jsx(kb,{className:"h-5 w-5"})}),m&&l.jsx("button",{onClick:m,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Settings",children:l.jsx(Yd,{className:"h-5 w-5"})})]})]});return o==="inline"?e?l.jsx("div",{className:"h-full w-full flex flex-col bg-card",children:Ue}):l.jsx("div",{className:"h-full flex flex-col bg-card border-r border-border/30",children:Ce}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:se("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",e?"opacity-100":"opacity-0 pointer-events-none"),onClick:t}),l.jsx("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:se("fixed top-0 left-0 z-40 h-screen w-72 bg-card border-r border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",e?"translate-x-0":"-translate-x-full"),children:Ue})]})}function Zse(e,t="en"){const n=Date.now(),r=e-n,i=Math.abs(r),s=60*1e3,o=60*s,c=24*o,d=7*c,m=30*c,f=365*c;let g,y;return i<s?(g=Math.round(r/1e3),y="second"):i<o?(g=Math.round(r/s),y="minute"):i<c?(g=Math.round(r/o),y="hour"):i<d?(g=Math.round(r/c),y="day"):i<m?(g=Math.round(r/d),y="week"):i<f?(g=Math.round(r/m),y="month"):(g=Math.round(r/f),y="year"),new Intl.RelativeTimeFormat(t,{numeric:"auto"}).format(g,y)}function Yse({isOpen:e,onClose:t,variant:n="modal"}){const[r,i]=b.useState(""),[s,o]=b.useState(!1),[c,d]=b.useState(!1),[m,f]=b.useState(null),{data:g=[],isLoading:y,error:x}=Eie(e),k=Die(),T=async M=>{await k.mutateAsync({memoryId:M}),d(!1),f(null)},S=(M,P=120)=>M.length<=P?M:M.slice(0,P)+"...",w=g.filter(M=>{if(!r.trim())return!0;const P=r.toLowerCase();return M.content.toLowerCase().includes(P)||M.tags?.some(D=>D.toLowerCase().includes(P))}),N=l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Ro,{className:"h-4 w-4"}),l.jsx("h2",{className:"text-base font-semibold",children:"Memories"}),l.jsx(Qn,{variant:"secondary",className:"text-xs",children:g.length})]})}),l.jsx("div",{className:"p-3 border-b border-border/50",children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(Rr,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),l.jsx(ct,{placeholder:"Search memories...",value:r,onChange:M=>i(M.target.value),className:"pl-8 h-8 text-sm"})]}),l.jsx(va,{children:l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"outline",size:"sm",onClick:()=>o(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{children:"Create Memory"})]})})]})}),x&&l.jsx("div",{className:"p-4",children:l.jsxs(ri,{variant:"destructive",children:[l.jsx(ns,{className:"h-4 w-4"}),l.jsx(ii,{children:x.message})]})}),l.jsx(vm,{className:"flex-1 p-4",children:l.jsx("div",{className:"space-y-2",children:y?l.jsx("div",{className:"flex items-center justify-center py-8",children:l.jsx(Qi,{className:"h-6 w-6 animate-spin"})}):w.length===0?l.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[l.jsx(Ro,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),r.trim()?l.jsxs(l.Fragment,{children:[l.jsx("p",{children:"No memories found"}),l.jsx("p",{className:"text-sm",children:"Try a different search term"})]}):l.jsxs(l.Fragment,{children:[l.jsx("p",{children:"No memories yet"}),l.jsx("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):w.map(M=>l.jsx("div",{className:se("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",M.metadata?.pinned&&"ring-1 ring-primary/30 bg-primary/5"),children:l.jsxs("div",{className:"flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[l.jsx("p",{className:"text-sm leading-relaxed",children:S(M.content)}),M.tags&&M.tags.length>0&&l.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[l.jsx(Gq,{className:"h-3 w-3 text-muted-foreground"}),M.tags.map((P,D)=>l.jsx(Qn,{variant:"outline",className:"text-xs px-1.5 py-0",children:P},D))]}),l.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(cB,{className:"h-3 w-3"}),l.jsx("span",{children:Zse(M.updatedAt)})]}),M.metadata?.source&&l.jsx(Qn,{variant:"secondary",className:"text-xs px-1.5 py-0",children:M.metadata.source}),M.metadata?.pinned&&l.jsx(Qn,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),l.jsx("div",{className:"flex items-center gap-1",children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>{f(M),d(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:l.jsx(Ar,{className:"h-3.5 w-3.5 text-destructive"})})})]})},M.id))})}),l.jsx(A4,{open:s,onClose:()=>o(!1)}),l.jsx(qr,{open:c,onOpenChange:d,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-5 w-5 text-destructive"}),l.jsx("span",{children:"Delete Memory"})]}),l.jsxs(is,{children:["This will permanently delete this memory. This action cannot be undone.",m&&l.jsx("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:S(m.content,100)})]})]}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),l.jsxs(Pe,{variant:"destructive",onClick:()=>m&&T(m.id),disabled:k.isPending,className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-4 w-4"}),l.jsx("span",{children:k.isPending?"Deleting...":"Delete Memory"})]})]})]})})]});return n==="inline"?l.jsx("div",{className:"h-full",children:N}):l.jsx(qr,{open:e,onOpenChange:t,children:l.jsxs(Gr,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[l.jsx(ti,{className:"sr-only",children:l.jsx(Hr,{children:"Memories"})}),N]})})}function Qse({onApprove:e,onDeny:t,onHandlersReady:n}){const r=Ma(g=>g.currentSessionId),i=V1(g=>g.pendingApproval),{ensureSessionEventStream:s}=Q1(),{mutateAsync:o}=z9(),c=i&&(!i.sessionId||!r||i.sessionId===r)?i:null,d=b.useCallback(async(g,y,x)=>{if(!c)return;const{approvalId:k}=c;console.debug(`[WebUI] Sending approval response for ${k}: ${g?"approved":"denied"}`);const T=c.sessionId||r;if(!T){console.error("[WebUI] Cannot submit approval without sessionId");return}try{await s(T),await o({approvalId:k,sessionId:T,status:g?Pd.APPROVED:Pd.DENIED,...g&&y?{formData:y}:{},...g&&x!==void 0?{rememberChoice:x}:{}})}catch(S){const w=S instanceof Error?S.message:String(S);console.error(`[WebUI] Failed to send approval response: ${w}`);return}},[c,r,o,s]),m=b.useCallback((g,y)=>{d(!0,g,y),e?.(g,y)},[d,e]),f=b.useCallback(()=>{d(!1),t?.()},[d,t]);return b.useEffect(()=>{n&&n({onApprove:m,onDeny:f})},[m,f,n]),null}function Xse(e,t,n,r){var i=this,s=b.useRef(null),o=b.useRef(0),c=b.useRef(0),d=b.useRef(null),m=b.useRef([]),f=b.useRef(),g=b.useRef(),y=b.useRef(e),x=b.useRef(!0);y.current=e;var k=typeof window<"u",T=!t&&t!==0&&k;if(typeof e!="function")throw new TypeError("Expected a function");t=+t||0;var S=!!(n=n||{}).leading,w=!("trailing"in n)||!!n.trailing,N="maxWait"in n,M="debounceOnServer"in n&&!!n.debounceOnServer,P=N?Math.max(+n.maxWait||0,t):null;b.useEffect(function(){return x.current=!0,function(){x.current=!1}},[]);var D=b.useMemo(function(){var E=function(Y){var B=m.current,q=f.current;return m.current=f.current=null,o.current=Y,c.current=c.current||Y,g.current=y.current.apply(q,B)},I=function(Y,B){T&&cancelAnimationFrame(d.current),d.current=T?requestAnimationFrame(Y):setTimeout(Y,B)},R=function(Y){if(!x.current)return!1;var B=Y-s.current;return!s.current||B>=t||B<0||N&&Y-o.current>=P},K=function(Y){return d.current=null,w&&m.current?E(Y):(m.current=f.current=null,g.current)},L=function Y(){var B=Date.now();if(S&&c.current===o.current&&U(),R(B))return K(B);if(x.current){var q=t-(B-s.current),j=N?Math.min(q,P-(B-o.current)):q;I(Y,j)}},U=function(){r&&r({})},G=function(){if(k||M){var Y=Date.now(),B=R(Y);if(m.current=[].slice.call(arguments),f.current=i,s.current=Y,B){if(!d.current&&x.current)return o.current=s.current,I(L,t),S?E(s.current):g.current;if(N)return I(L,t),E(s.current)}return d.current||I(L,t),g.current}};return G.cancel=function(){var Y=d.current;Y&&(T?cancelAnimationFrame(d.current):clearTimeout(d.current)),o.current=0,m.current=s.current=f.current=d.current=null,Y&&r&&r({})},G.isPending=function(){return!!d.current},G.flush=function(){return d.current?K(Date.now()):g.current},G},[S,N,t,P,w,T,k,M,r]);return D}function Jse(e,t){return e===t}function bI(e,t,n){var r=Jse,i=b.useRef(e),s=b.useState({})[1],o=Xse(b.useCallback(function(d){i.current=d,s({})},[s]),t,n,s),c=b.useRef(e);return r(c.current,e)||(o(e),c.current=e),[i.current,o]}function eae(e,t,n=50,r=!0){return Dn({queryKey:Ge.search.messages(e,t,n),queryFn:async()=>await os(Xe.api.search.messages.$get({query:{q:e,limit:n,...t}}),"Failed to search messages"),enabled:r&&e.trim().length>0,staleTime:3e4})}function tae({isOpen:e,onClose:t,onNavigateToSession:n}){const[r,i]=b.useState(""),[s]=bI(r,300),[o,c]=b.useState(0),{data:d,isLoading:m,error:f}=eae(s,void 0,10,e),g=d?.results||[],y=f?.message??null;b.useEffect(()=>{o>=g.length&&g.length>0?c(g.length-1):g.length===0&&c(0)},[g.length,o]);const x=b.useCallback(w=>{n(w.sessionId,w.messageIndex),t()},[n,t]);b.useEffect(()=>{e&&(i(""),c(0))},[e]),Xr("down",()=>{c(w=>Math.min(w+1,g.length-1))},{enabled:e,preventDefault:!0},[e,g.length]),Xr("up",()=>{c(w=>Math.max(w-1,0))},{enabled:e,preventDefault:!0},[e]),Xr("enter",()=>{g[o]&&(x(g[o]),c(0))},{enabled:e,preventDefault:!0},[e,g,o,x]),Xr("escape",()=>{t()},{enabled:e,preventDefault:!0},[e,t]);const k=w=>{switch(w){case"user":return l.jsx(Xq,{className:"w-4 h-4"});case"assistant":return l.jsx(Tb,{className:"w-4 h-4"});case"system":return l.jsx(Yd,{className:"w-4 h-4"});default:return l.jsx(hq,{className:"w-4 h-4"})}},T=w=>{switch(w){case"user":return"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";case"assistant":return"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200";case"system":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";default:return"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200"}},S=(w,N)=>{if(!N)return w;const M=N.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),P=new RegExp(`(${M})`,"gi");return w.split(P).map((E,I)=>E.toLowerCase()===N.toLowerCase()?l.jsx("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:E},I):E)};return e?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 z-40 bg-black/10 backdrop-blur-[2px]",onClick:t}),l.jsx("div",{className:"fixed left-1/2 top-[15%] -translate-x-1/2 z-50 w-full max-w-2xl bg-popover/70 backdrop-blur-xl border border-border/30 rounded-xl shadow-2xl overflow-hidden",children:l.jsxs("div",{className:"flex flex-col max-h-[70vh]",children:[l.jsx("div",{className:"p-4 border-b border-border/30",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),l.jsx(ct,{placeholder:"Search conversations...",value:r,onChange:w=>i(w.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),l.jsx("div",{className:"flex-1 overflow-hidden",children:m?l.jsxs("div",{className:"flex items-center justify-center py-12",children:[l.jsx(Qi,{className:"h-6 w-6 animate-spin mr-3"}),l.jsx("span",{className:"text-muted-foreground",children:"Searching..."})]}):f?l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsxs("div",{className:"text-center",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),l.jsx("p",{className:"text-destructive font-medium",children:"Search Error"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:y}),l.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):l.jsx(vm,{className:"h-full max-h-[calc(70vh-80px)]",children:l.jsx("div",{className:"p-2",children:g.length>0?l.jsx("div",{className:"space-y-1",children:g.map((w,N)=>l.jsxs("div",{className:se("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",N===o?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>x(w),children:[l.jsx("div",{className:"flex-shrink-0 mt-1",children:l.jsx(Qn,{className:se("text-xs",T(w.message.role)),children:k(w.message.role)})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"text-sm font-medium",children:w.sessionId.length>20?`${w.sessionId.slice(0,20)}...`:w.sessionId}),l.jsx("span",{className:"text-xs text-muted-foreground",children:w.message.role})]}),l.jsx("div",{className:"text-sm text-muted-foreground line-clamp-2",children:S(w.context,s)})]}),l.jsx(X1,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},N))}):s?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),l.jsx("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),l.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),l.jsx("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),l.jsxs("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"↑"}),l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"↓"}),l.jsx("span",{children:"to navigate"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"Enter"}),l.jsx("span",{children:"to select"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"Esc"}),l.jsx("span",{children:"to close"})]})]})]})})})})]})})]}):null}function nae(e=!0){return Dn({queryKey:Ge.agent.config,queryFn:async()=>await os(Xe.api.agent.config.$get(),"Failed to load agent config"),enabled:e,staleTime:3e4})}function rae(){return nn({mutationFn:async({yaml:e})=>await os(Xe.api.agent.validate.$post({json:{yaml:e}}),"Failed to validate agent config")})}function iae(){const e=un();return nn({mutationFn:async({yaml:t})=>await os(Xe.api.agent.config.$post({json:{yaml:t}}),"Failed to save agent config"),onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agent.config})}})}function sae(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ZP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function YP(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?ZP(Object(n),!0).forEach(function(r){sae(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ZP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function aae(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,s;for(s=0;s<r.length;s++)i=r[s],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function oae(e,t){if(e==null)return{};var n=aae(e,t),r,i;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(i=0;i<s.length;i++)r=s[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function lae(e,t){return uae(e)||cae(e,t)||pae(e,t)||dae()}function uae(e){if(Array.isArray(e))return e}function cae(e,t){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(e)))){var n=[],r=!0,i=!1,s=void 0;try{for(var o=e[Symbol.iterator](),c;!(r=(c=o.next()).done)&&(n.push(c.value),!(t&&n.length===t));r=!0);}catch(d){i=!0,s=d}finally{try{!r&&o.return!=null&&o.return()}finally{if(i)throw s}}return n}}function pae(e,t){if(e){if(typeof e=="string")return QP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return QP(e,t)}}function QP(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function dae(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1507
+ (OK = attach as file, Cancel = paste truncated preview)`)){const vt=new TextEncoder().encode(Ke).length;if(c.length>=Ur.MAX_COUNT){gt(`Cannot attach pasted text. Maximum ${Ur.MAX_COUNT} attachments allowed (currently ${c.length}).`);return}if(vt>Ur.MAX_FILE_SIZE){gt(`Pasted text is too large (${zr(vt)}). Maximum ${zr(Ur.MAX_FILE_SIZE)} per file.`);return}const Qt=c.reduce((bn,_r)=>bn+_r.size,0);if(Qt+vt>Ur.MAX_TOTAL_SIZE){gt(`Total size would exceed ${zr(Ur.MAX_TOTAL_SIZE)}. Current: ${zr(Qt)}, Adding: ${zr(vt)}.`);return}const Fn={id:Jp(),type:"file",data:je(Ke),mimeType:"text/plain",filename:"pasted.txt",size:vt,source:"paste"};d(bn=>[...bn,Fn])}else{const ot=Ke.slice(0,ke);s(vt=>vt+ot)}},sn=async(he,Ae)=>new Promise((ce,Ie)=>{const qe=new FileReader;qe.onloadend=()=>{try{const Ke=qe.result;if(typeof Ke!="string"){Ie(new Error("Malformed data URL: FileReader result is not a string"));return}const Mt=Ke.indexOf(",");if(Mt===-1){Ie(new Error("Malformed data URL: missing comma separator"));return}const ot=Ke.substring(Mt+1),vt={id:Jp(),type:he.type.startsWith("image/")?"image":"file",data:ot,mimeType:he.type,filename:he.name,size:he.size,source:Ae};ce(vt)}catch(Ke){Ie(Ke)}},qe.onerror=()=>Ie(new Error("Failed to read file")),qe.readAsDataURL(he)}),pr=he=>{d(Ae=>Ae.filter(ce=>ce.id!==he))},si=he=>{D&&(he.type==="image"?Q.current.trackImageAttached({imageType:he.mimeType,imageSizeBytes:he.size,sessionId:D}):Q.current.trackFileAttached({fileType:he.mimeType,fileSizeBytes:he.size,sessionId:D}))},Or=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},dr=async()=>{try{const he=await navigator.mediaDevices.getUserMedia({audio:!0}),Ae=new MediaRecorder(he);w.current=Ae;const ce=[];Ae.ondataavailable=Ie=>{Ie.data.size>0&&ce.push(Ie.data)},Ae.onstop=()=>{const Ie=new Blob(ce,{type:Ae.mimeType}),qe=new FileReader;qe.onloadend=()=>{try{const Ke=qe.result,Mt=Ke.indexOf(","),ot=Ke.substring(Mt+1),vt=Ae.mimeType||"audio/webm",Fn=(_r=>({"audio/mp3":"mp3","audio/mpeg":"mp3","audio/wav":"wav","audio/x-wav":"wav","audio/wave":"wav","audio/webm":"webm","audio/ogg":"ogg","audio/m4a":"m4a","audio/aac":"aac"})[_r]||_r.split("/")[1]||"webm")(vt),bn={id:Jp(),type:"file",data:ot,mimeType:vt,filename:`recording.${Fn}`,size:Ie.size,source:"button"};d(_r=>[..._r,bn]),si(bn)}catch{gt("Failed to process audio recording. Please try again.")}},qe.readAsDataURL(Ie),he.getTracks().forEach(Ke=>Ke.stop())},Ae.start(),S(!0)}catch{gt("Failed to start audio recording. Please check microphone permissions.")}},Kn=()=>{w.current?.stop(),S(!1)},mr=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},_i=()=>m.current?.click(),Ne=()=>f.current?.click(),De=()=>g.current?.click(),yn=()=>y.current?.click(),fr=()=>x.current?.click();b.useEffect(()=>{i&&ne&&O(null),i&&be&&Ue(null)},[i,ne,be]);const Yt=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},On=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},Ra=async he=>{const Ae=Array.from(he.target.files||[]);Ae.length!==0&&(await Je(Ae,"button"),he.target.value="")},Vo=he=>{he.preventDefault(),he.stopPropagation(),P.current++,he.dataTransfer.types.includes("Files")&&M(!0)},Zl=he=>{he.preventDefault(),he.stopPropagation()},Kc=he=>{he.preventDefault(),he.stopPropagation(),P.current--,P.current===0&&M(!1)},Aa=async he=>{he.preventDefault(),he.stopPropagation(),M(!1),P.current=0;const Ae=Array.from(he.dataTransfer.files);Ae.length>0&&await Je(Ae,"drop")};return l.jsxs("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[ne&&l.jsxs(ri,{variant:"destructive",className:"mb-2",children:[l.jsx(Na,{className:"h-4 w-4"}),l.jsxs(ii,{className:"flex items-center justify-between",children:[l.jsx("span",{children:ne}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>O(null),className:"h-auto p-1 ml-2",children:l.jsx(Cn,{className:"h-3 w-3"})})]})]}),be&&l.jsxs(ri,{variant:"destructive",className:"mb-2",children:[l.jsx(Na,{className:"h-4 w-4"}),l.jsxs(ii,{className:"flex items-center justify-between",children:[l.jsx("span",{children:be}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>Ue(null),className:"h-auto p-1 ml-2",children:l.jsx(Cn,{className:"h-3 w-3"})})]})]}),l.jsxs("div",{className:"w-full",children:[l.jsx("form",{onSubmit:he=>{he.preventDefault(),Sn()},children:l.jsx("div",{role:"region","aria-label":"Message input area with file drop zone",className:se("relative transition-all duration-200",N&&"ring-2 ring-primary ring-offset-2 rounded-lg"),onDragEnter:Vo,onDragOver:Zl,onDragLeave:Kc,onDrop:Aa,children:l.jsxs(ane,{children:[N&&l.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 rounded-lg pointer-events-none",children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-4xl mb-2",children:"📎"}),l.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files to attach"}),l.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Up to ",Ur.MAX_COUNT," files,"," ",zr(Ur.MAX_FILE_SIZE)," each"]})]})}),$.length>0&&l.jsx(Bie,{messages:$,onEditMessage:er,onRemoveMessage:he=>{D&&j({sessionId:D,messageId:he})}}),c.length>0&&l.jsxs("div",{className:"px-4 pt-4",children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsxs("div",{className:"text-xs text-muted-foreground",children:[c.length," / ",Ur.MAX_COUNT," ","files (",zr(gn)," /"," ",zr(Ur.MAX_TOTAL_SIZE),")"]}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>d([]),className:"h-6 text-xs text-muted-foreground hover:text-destructive",children:"Clear all"})]}),l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:c.map(he=>l.jsx(Tie,{attachment:he,onRemove:()=>pr(he.id)},he.id))})]}),l.jsxs("div",{className:"flex-auto overflow-y-auto relative",children:[k?l.jsx(sne,{ref:o,value:i,onChange:Z,onKeyDown:Tr,onPaste:Rt,placeholder:"Ask Dexto anything... Type @ for resources, / for prompts, # for memories",minRows:1,maxRows:8,className:"w-full px-4 pt-4 pb-1 text-lg leading-7 placeholder:text-lg bg-transparent border-none resize-none outline-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus:outline-none max-h-full"}):l.jsx("textarea",{ref:o,rows:1,value:i,onChange:Z,onKeyDown:Tr,onPaste:Rt,placeholder:"Ask Dexto anything... Type @ for resources, / for prompts, # for memories",className:"w-full px-4 pt-4 pb-1 text-lg leading-7 placeholder:text-lg bg-transparent border-none resize-none outline-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus:outline-none"}),de&&ut&&typeof window<"u"&&Ov.createPortal(l.jsx("div",{style:ut,className:"max-h-64 overflow-y-auto rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:l.jsx(kie,{resources:ze,query:pe,selectedIndex:Ve,onHoverIndex:he=>Be(he),onSelect:he=>Ti(Ve,he),loading:lt})}),document.body),tr&&ye&&typeof window<"u"&&Ov.createPortal(l.jsx("div",{style:ye,className:"rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:l.jsxs("div",{className:"p-2 flex items-center gap-2 text-sm text-muted-foreground",children:[l.jsx(Ro,{className:"h-3.5 w-3.5"}),l.jsxs("span",{children:["Press"," ",l.jsx("kbd",{className:"px-1.5 py-0.5 text-xs bg-muted border border-border rounded",children:"Enter"})," ","to create a memory"]})]})}),document.body)]}),l.jsx(Nie,{isVisible:st,searchQuery:i,onSelectPrompt:ue,onClose:Te,onCreatePrompt:An,refreshKey:wt}),l.jsx(one,{leftButtons:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(vre,{onImageAttach:_i,onPdfAttach:Ne,onAudioAttach:De,onVideoAttach:yn,onDocumentAttach:fr,supports:{image:Ce===null?void 0:Ce.includes("image"),pdf:Ce===null?void 0:Ce.includes("pdf"),audio:Ce===null?void 0:Ce.includes("audio"),video:Ce===null?void 0:Ce.includes("video"),document:Ce===null?void 0:Ce.includes("document")},useLargeBreakpoint:n}),l.jsx(bre,{isRecording:T,onToggleRecording:T?Kn:dr,disabled:Ce!==null&&!Ce.includes("audio"),useLargeBreakpoint:n})]}),rightButtons:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(bie,{}),l.jsx(Pe,{type:E?"button":"submit",onClick:E?()=>I(D||void 0):void 0,disabled:E?!1:!i.trim()&&c.length===0||t,className:se("h-10 w-10 p-0 rounded-full transition-all duration-200",E?"bg-secondary/80 text-secondary-foreground hover:bg-secondary shadow-sm hover:shadow-md border border-border/50":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-lg"),"aria-label":E?"Stop":"Send message",title:E?"Stop":"Send",children:E?l.jsx(qE,{className:"h-3.5 w-3.5 fill-current"}):t?l.jsx(vr,{className:"h-4 w-4 animate-spin"}):l.jsx(jq,{className:"h-4 w-4"})})]})})]})})}),l.jsx("input",{ref:m,type:"file",id:"image-upload",accept:"image/*",multiple:!0,className:"hidden",onChange:mr}),l.jsx("input",{ref:f,type:"file",id:"pdf-upload",accept:"application/pdf",multiple:!0,className:"hidden",onChange:Or}),l.jsx("input",{ref:g,type:"file",id:"audio-upload",accept:"audio/*",multiple:!0,className:"hidden",onChange:Yt}),l.jsx("input",{ref:y,type:"file",id:"video-upload",accept:"video/*",multiple:!0,className:"hidden",onChange:On}),l.jsx("input",{ref:x,type:"file",id:"document-upload",accept:".txt,.md,.json,.html,.xml,.doc,.docx,.rtf,.odt,.ppt,.pptx,.csv,.tsv,.xls,.xlsx,.iif,text/*,application/json,application/xml,text/xml,text/csv,text/tab-separated-values,application/msword,application/rtf,text/rtf,application/vnd.oasis.opendocument.text,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",multiple:!0,className:"hidden",onChange:Ra}),l.jsx(Pie,{open:at,onClose:qn,onCreated:br}),l.jsx(A4,{open:Me,onClose:()=>Re(!1)})]})]})}function GP(e,[t,n]){return Math.min(n,Math.max(t,e))}function Hie(e){const t=e+"CollectionProvider",[n,r]=$o(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=T=>{const{scope:S,children:w}=T,N=dt.useRef(null),M=dt.useRef(new Map).current;return l.jsx(i,{scope:S,itemMap:M,collectionRef:N,children:w})};o.displayName=t;const c=e+"CollectionSlot",d=Dl(c),m=dt.forwardRef((T,S)=>{const{scope:w,children:N}=T,M=s(c,w),P=ln(S,M.collectionRef);return l.jsx(d,{ref:P,children:N})});m.displayName=c;const f=e+"CollectionItemSlot",g="data-radix-collection-item",y=Dl(f),x=dt.forwardRef((T,S)=>{const{scope:w,children:N,...M}=T,P=dt.useRef(null),D=ln(S,P),E=s(f,w);return dt.useEffect(()=>(E.itemMap.set(P,{ref:P,...M}),()=>{E.itemMap.delete(P)})),l.jsx(y,{[g]:"",ref:D,children:N})});x.displayName=f;function k(T){const S=s(e+"CollectionConsumer",T);return dt.useCallback(()=>{const N=S.collectionRef.current;if(!N)return[];const M=Array.from(N.querySelectorAll(`[${g}]`));return Array.from(S.itemMap.values()).sort((E,I)=>M.indexOf(E.ref.current)-M.indexOf(I.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:o,Slot:m,ItemSlot:x},k,r]}var Vie=b.createContext(void 0);function Kie(e){const t=b.useContext(Vie);return e||t||"ltr"}var Wie=[" ","Enter","ArrowUp","ArrowDown"],Zie=[" ","Enter"],Ul="Select",[Wg,Zg,Yie]=Hie(Ul),[$c]=$o(Ul,[Yie,Fc]),Yg=Fc(),[Qie,Go]=$c(Ul),[Xie,Jie]=$c(Ul),O4=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:c,onValueChange:d,dir:m,name:f,autoComplete:g,disabled:y,required:x,form:k}=e,T=Yg(t),[S,w]=b.useState(null),[N,M]=b.useState(null),[P,D]=b.useState(!1),E=Kie(m),[I,R]=Rl({prop:r,defaultProp:i??!1,onChange:s,caller:Ul}),[K,L]=Rl({prop:o,defaultProp:c,onChange:d,caller:Ul}),U=b.useRef(null),G=S?k||!!S.closest("form"):!0,[Y,B]=b.useState(new Set),q=Array.from(Y).map(j=>j.props.value).join(";");return l.jsx(f2,{...T,children:l.jsxs(Qie,{required:x,scope:t,trigger:S,onTriggerChange:w,valueNode:N,onValueNodeChange:M,valueNodeHasChildren:P,onValueNodeHasChildrenChange:D,contentId:No(),value:K,onValueChange:L,open:I,onOpenChange:R,dir:E,triggerPointerDownPosRef:U,disabled:y,children:[l.jsx(Wg.Provider,{scope:t,children:l.jsx(Xie,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(j=>{B(W=>new Set(W).add(j))},[]),onNativeOptionRemove:b.useCallback(j=>{B(W=>{const z=new Set(W);return z.delete(j),z})},[]),children:n})}),G?l.jsxs(iI,{"aria-hidden":!0,required:x,tabIndex:-1,name:f,autoComplete:g,value:K,onChange:j=>L(j.target.value),disabled:y,form:k,children:[K===void 0?l.jsx("option",{value:""}):null,Array.from(Y)]},q):null]})})};O4.displayName=Ul;var F4="SelectTrigger",U4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Yg(n),o=Go(F4,n),c=o.disabled||r,d=ln(t,o.onTriggerChange),m=Zg(n),f=b.useRef("touch"),[g,y,x]=aI(T=>{const S=m().filter(M=>!M.disabled),w=S.find(M=>M.value===o.value),N=oI(S,T,w);N!==void 0&&o.onValueChange(N.value)}),k=T=>{c||(o.onOpenChange(!0),x()),T&&(o.triggerPointerDownPosRef.current={x:Math.round(T.pageX),y:Math.round(T.pageY)})};return l.jsx(Dg,{asChild:!0,...s,children:l.jsx($t.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:c,"data-disabled":c?"":void 0,"data-placeholder":sI(o.value)?"":void 0,...i,ref:d,onClick:jt(i.onClick,T=>{T.currentTarget.focus(),f.current!=="mouse"&&k(T)}),onPointerDown:jt(i.onPointerDown,T=>{f.current=T.pointerType;const S=T.target;S.hasPointerCapture(T.pointerId)&&S.releasePointerCapture(T.pointerId),T.button===0&&T.ctrlKey===!1&&T.pointerType==="mouse"&&(k(T),T.preventDefault())}),onKeyDown:jt(i.onKeyDown,T=>{const S=g.current!=="";!(T.ctrlKey||T.altKey||T.metaKey)&&T.key.length===1&&y(T.key),!(S&&T.key===" ")&&Wie.includes(T.key)&&(k(),T.preventDefault())})})})});U4.displayName=F4;var L4="SelectValue",z4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...c}=e,d=Go(L4,n),{onValueNodeHasChildrenChange:m}=d,f=s!==void 0,g=ln(t,d.onValueNodeChange);return Vr(()=>{m(f)},[m,f]),l.jsx($t.span,{...c,ref:g,style:{pointerEvents:"none"},children:sI(d.value)?l.jsx(l.Fragment,{children:o}):s})});z4.displayName=L4;var ese="SelectIcon",$4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return l.jsx($t.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});$4.displayName=ese;var tse="SelectPortal",B4=e=>l.jsx(mm,{asChild:!0,...e});B4.displayName=tse;var Ll="SelectContent",q4=b.forwardRef((e,t)=>{const n=Go(Ll,e.__scopeSelect),[r,i]=b.useState();if(Vr(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?fg.createPortal(l.jsx(G4,{scope:e.__scopeSelect,children:l.jsx(Wg.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(H4,{...e,ref:t})});q4.displayName=Ll;var xs=10,[G4,Ho]=$c(Ll),nse="SelectContentImpl",rse=Dl("SelectContent.RemoveScroll"),H4=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:c,sideOffset:d,align:m,alignOffset:f,arrowPadding:g,collisionBoundary:y,collisionPadding:x,sticky:k,hideWhenDetached:T,avoidCollisions:S,...w}=e,N=Go(Ll,n),[M,P]=b.useState(null),[D,E]=b.useState(null),I=ln(t,ae=>P(ae)),[R,K]=b.useState(null),[L,U]=b.useState(null),G=Zg(n),[Y,B]=b.useState(!1),q=b.useRef(!1);b.useEffect(()=>{if(M)return Y2(M)},[M]),Z2();const j=b.useCallback(ae=>{const[ze,...lt]=G().map(J=>J.ref.current),[me]=lt.slice(-1),pe=document.activeElement;for(const J of ae)if(J===pe||(J?.scrollIntoView({block:"nearest"}),J===ze&&D&&(D.scrollTop=0),J===me&&D&&(D.scrollTop=D.scrollHeight),J?.focus(),document.activeElement!==pe))return},[G,D]),W=b.useCallback(()=>j([R,M]),[j,R,M]);b.useEffect(()=>{Y&&W()},[Y,W]);const{onOpenChange:z,triggerPointerDownPosRef:$}=N;b.useEffect(()=>{if(M){let ae={x:0,y:0};const ze=me=>{ae={x:Math.abs(Math.round(me.pageX)-($.current?.x??0)),y:Math.abs(Math.round(me.pageY)-($.current?.y??0))}},lt=me=>{ae.x<=10&&ae.y<=10?me.preventDefault():M.contains(me.target)||z(!1),document.removeEventListener("pointermove",ze),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",ze),document.addEventListener("pointerup",lt,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ze),document.removeEventListener("pointerup",lt,{capture:!0})}}},[M,z,$]),b.useEffect(()=>{const ae=()=>z(!1);return window.addEventListener("blur",ae),window.addEventListener("resize",ae),()=>{window.removeEventListener("blur",ae),window.removeEventListener("resize",ae)}},[z]);const[A,Q]=aI(ae=>{const ze=G().filter(pe=>!pe.disabled),lt=ze.find(pe=>pe.ref.current===document.activeElement),me=oI(ze,ae,lt);me&&setTimeout(()=>me.ref.current.focus())}),ne=b.useCallback((ae,ze,lt)=>{const me=!q.current&&!lt;(N.value!==void 0&&N.value===ze||me)&&(K(ae),me&&(q.current=!0))},[N.value]),O=b.useCallback(()=>M?.focus(),[M]),be=b.useCallback((ae,ze,lt)=>{const me=!q.current&&!lt;(N.value!==void 0&&N.value===ze||me)&&U(ae)},[N.value]),Ue=r==="popper"?l1:V4,Ce=Ue===l1?{side:c,sideOffset:d,align:m,alignOffset:f,arrowPadding:g,collisionBoundary:y,collisionPadding:x,sticky:k,hideWhenDetached:T,avoidCollisions:S}:{};return l.jsx(G4,{scope:n,content:M,viewport:D,onViewportChange:E,itemRefCallback:ne,selectedItem:R,onItemLeave:O,itemTextRefCallback:be,focusSelectedItem:W,selectedItemText:L,position:r,isPositioned:Y,searchRef:A,children:l.jsx(qg,{as:rse,allowPinchZoom:!0,children:l.jsx($g,{asChild:!0,trapped:N.open,onMountAutoFocus:ae=>{ae.preventDefault()},onUnmountAutoFocus:jt(i,ae=>{N.trigger?.focus({preventScroll:!0}),ae.preventDefault()}),children:l.jsx(pm,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ae=>ae.preventDefault(),onDismiss:()=>N.onOpenChange(!1),children:l.jsx(Ue,{role:"listbox",id:N.contentId,"data-state":N.open?"open":"closed",dir:N.dir,onContextMenu:ae=>ae.preventDefault(),...w,...Ce,onPlaced:()=>B(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...w.style},onKeyDown:jt(w.onKeyDown,ae=>{const ze=ae.ctrlKey||ae.altKey||ae.metaKey;if(ae.key==="Tab"&&ae.preventDefault(),!ze&&ae.key.length===1&&Q(ae.key),["ArrowUp","ArrowDown","Home","End"].includes(ae.key)){let me=G().filter(pe=>!pe.disabled).map(pe=>pe.ref.current);if(["ArrowUp","End"].includes(ae.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(ae.key)){const pe=ae.target,J=me.indexOf(pe);me=me.slice(J+1)}setTimeout(()=>j(me)),ae.preventDefault()}})})})})})})});H4.displayName=nse;var ise="SelectItemAlignedPosition",V4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Go(Ll,n),o=Ho(Ll,n),[c,d]=b.useState(null),[m,f]=b.useState(null),g=ln(t,I=>f(I)),y=Zg(n),x=b.useRef(!1),k=b.useRef(!0),{viewport:T,selectedItem:S,selectedItemText:w,focusSelectedItem:N}=o,M=b.useCallback(()=>{if(s.trigger&&s.valueNode&&c&&m&&T&&S&&w){const I=s.trigger.getBoundingClientRect(),R=m.getBoundingClientRect(),K=s.valueNode.getBoundingClientRect(),L=w.getBoundingClientRect();if(s.dir!=="rtl"){const pe=L.left-R.left,J=K.left-pe,de=I.left-J,fe=I.width+de,Ve=Math.max(fe,R.width),Be=window.innerWidth-xs,ut=GP(J,[xs,Math.max(xs,Be-Ve)]);c.style.minWidth=fe+"px",c.style.left=ut+"px"}else{const pe=R.right-L.right,J=window.innerWidth-K.right-pe,de=window.innerWidth-I.right-J,fe=I.width+de,Ve=Math.max(fe,R.width),Be=window.innerWidth-xs,ut=GP(J,[xs,Math.max(xs,Be-Ve)]);c.style.minWidth=fe+"px",c.style.right=ut+"px"}const U=y(),G=window.innerHeight-xs*2,Y=T.scrollHeight,B=window.getComputedStyle(m),q=parseInt(B.borderTopWidth,10),j=parseInt(B.paddingTop,10),W=parseInt(B.borderBottomWidth,10),z=parseInt(B.paddingBottom,10),$=q+j+Y+z+W,A=Math.min(S.offsetHeight*5,$),Q=window.getComputedStyle(T),ne=parseInt(Q.paddingTop,10),O=parseInt(Q.paddingBottom,10),be=I.top+I.height/2-xs,Ue=G-be,Ce=S.offsetHeight/2,ae=S.offsetTop+Ce,ze=q+j+ae,lt=$-ze;if(ze<=be){const pe=U.length>0&&S===U[U.length-1].ref.current;c.style.bottom="0px";const J=m.clientHeight-T.offsetTop-T.offsetHeight,de=Math.max(Ue,Ce+(pe?O:0)+J+W),fe=ze+de;c.style.height=fe+"px"}else{const pe=U.length>0&&S===U[0].ref.current;c.style.top="0px";const de=Math.max(be,q+T.offsetTop+(pe?ne:0)+Ce)+lt;c.style.height=de+"px",T.scrollTop=ze-be+T.offsetTop}c.style.margin=`${xs}px 0`,c.style.minHeight=A+"px",c.style.maxHeight=G+"px",r?.(),requestAnimationFrame(()=>x.current=!0)}},[y,s.trigger,s.valueNode,c,m,T,S,w,s.dir,r]);Vr(()=>M(),[M]);const[P,D]=b.useState();Vr(()=>{m&&D(window.getComputedStyle(m).zIndex)},[m]);const E=b.useCallback(I=>{I&&k.current===!0&&(M(),N?.(),k.current=!1)},[M,N]);return l.jsx(ase,{scope:n,contentWrapper:c,shouldExpandOnScrollRef:x,onScrollButtonChange:E,children:l.jsx("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:P},children:l.jsx($t.div,{...i,ref:g,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});V4.displayName=ise;var sse="SelectPopperPosition",l1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=xs,...s}=e,o=Yg(n);return l.jsx(h2,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});l1.displayName=sse;var[ase,rT]=$c(Ll,{}),u1="SelectViewport",K4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=Ho(u1,n),o=rT(u1,n),c=ln(t,s.onViewportChange),d=b.useRef(0);return l.jsxs(l.Fragment,{children:[l.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),l.jsx(Wg.Slot,{scope:n,children:l.jsx($t.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:c,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:jt(i.onScroll,m=>{const f=m.currentTarget,{contentWrapper:g,shouldExpandOnScrollRef:y}=o;if(y?.current&&g){const x=Math.abs(d.current-f.scrollTop);if(x>0){const k=window.innerHeight-xs*2,T=parseFloat(g.style.minHeight),S=parseFloat(g.style.height),w=Math.max(T,S);if(w<k){const N=w+x,M=Math.min(k,N),P=N-M;g.style.height=M+"px",g.style.bottom==="0px"&&(f.scrollTop=P>0?P:0,g.style.justifyContent="flex-end")}}}d.current=f.scrollTop})})})]})});K4.displayName=u1;var W4="SelectGroup",[ose,lse]=$c(W4),use=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=No();return l.jsx(ose,{scope:n,id:i,children:l.jsx($t.div,{role:"group","aria-labelledby":i,...r,ref:t})})});use.displayName=W4;var Z4="SelectLabel",cse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=lse(Z4,n);return l.jsx($t.div,{id:i.id,...r,ref:t})});cse.displayName=Z4;var lg="SelectItem",[pse,Y4]=$c(lg),Q4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,c=Go(lg,n),d=Ho(lg,n),m=c.value===r,[f,g]=b.useState(s??""),[y,x]=b.useState(!1),k=ln(t,N=>d.itemRefCallback?.(N,r,i)),T=No(),S=b.useRef("touch"),w=()=>{i||(c.onValueChange(r),c.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return l.jsx(pse,{scope:n,value:r,disabled:i,textId:T,isSelected:m,onItemTextChange:b.useCallback(N=>{g(M=>M||(N?.textContent??"").trim())},[]),children:l.jsx(Wg.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:l.jsx($t.div,{role:"option","aria-labelledby":T,"data-highlighted":y?"":void 0,"aria-selected":m&&y,"data-state":m?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:k,onFocus:jt(o.onFocus,()=>x(!0)),onBlur:jt(o.onBlur,()=>x(!1)),onClick:jt(o.onClick,()=>{S.current!=="mouse"&&w()}),onPointerUp:jt(o.onPointerUp,()=>{S.current==="mouse"&&w()}),onPointerDown:jt(o.onPointerDown,N=>{S.current=N.pointerType}),onPointerMove:jt(o.onPointerMove,N=>{S.current=N.pointerType,i?d.onItemLeave?.():S.current==="mouse"&&N.currentTarget.focus({preventScroll:!0})}),onPointerLeave:jt(o.onPointerLeave,N=>{N.currentTarget===document.activeElement&&d.onItemLeave?.()}),onKeyDown:jt(o.onKeyDown,N=>{d.searchRef?.current!==""&&N.key===" "||(Zie.includes(N.key)&&w(),N.key===" "&&N.preventDefault())})})})})});Q4.displayName=lg;var Td="SelectItemText",X4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Go(Td,n),c=Ho(Td,n),d=Y4(Td,n),m=Jie(Td,n),[f,g]=b.useState(null),y=ln(t,w=>g(w),d.onItemTextChange,w=>c.itemTextRefCallback?.(w,d.value,d.disabled)),x=f?.textContent,k=b.useMemo(()=>l.jsx("option",{value:d.value,disabled:d.disabled,children:x},d.value),[d.disabled,d.value,x]),{onNativeOptionAdd:T,onNativeOptionRemove:S}=m;return Vr(()=>(T(k),()=>S(k)),[T,S,k]),l.jsxs(l.Fragment,{children:[l.jsx($t.span,{id:d.textId,...s,ref:y}),d.isSelected&&o.valueNode&&!o.valueNodeHasChildren?fg.createPortal(s.children,o.valueNode):null]})});X4.displayName=Td;var J4="SelectItemIndicator",eI=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Y4(J4,n).isSelected?l.jsx($t.span,{"aria-hidden":!0,...r,ref:t}):null});eI.displayName=J4;var c1="SelectScrollUpButton",tI=b.forwardRef((e,t)=>{const n=Ho(c1,e.__scopeSelect),r=rT(c1,e.__scopeSelect),[i,s]=b.useState(!1),o=ln(t,r.onScrollButtonChange);return Vr(()=>{if(n.viewport&&n.isPositioned){let c=function(){const m=d.scrollTop>0;s(m)};const d=n.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[n.viewport,n.isPositioned]),i?l.jsx(rI,{...e,ref:o,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=n;c&&d&&(c.scrollTop=c.scrollTop-d.offsetHeight)}}):null});tI.displayName=c1;var p1="SelectScrollDownButton",nI=b.forwardRef((e,t)=>{const n=Ho(p1,e.__scopeSelect),r=rT(p1,e.__scopeSelect),[i,s]=b.useState(!1),o=ln(t,r.onScrollButtonChange);return Vr(()=>{if(n.viewport&&n.isPositioned){let c=function(){const m=d.scrollHeight-d.clientHeight,f=Math.ceil(d.scrollTop)<m;s(f)};const d=n.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[n.viewport,n.isPositioned]),i?l.jsx(rI,{...e,ref:o,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=n;c&&d&&(c.scrollTop=c.scrollTop+d.offsetHeight)}}):null});nI.displayName=p1;var rI=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=Ho("SelectScrollButton",n),o=b.useRef(null),c=Zg(n),d=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>d(),[d]),Vr(()=>{c().find(f=>f.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[c]),l.jsx($t.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:jt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:jt(i.onPointerMove,()=>{s.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:jt(i.onPointerLeave,()=>{d()})})}),dse="SelectSeparator",mse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx($t.div,{"aria-hidden":!0,...r,ref:t})});mse.displayName=dse;var d1="SelectArrow",fse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Yg(n),s=Go(d1,n),o=Ho(d1,n);return s.open&&o.position==="popper"?l.jsx(g2,{...i,...r,ref:t}):null});fse.displayName=d1;var hse="SelectBubbleInput",iI=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=ln(r,i),o=W2(t);return b.useEffect(()=>{const c=i.current;if(!c)return;const d=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(d,"value").set;if(o!==t&&f){const g=new Event("change",{bubbles:!0});f.call(c,t),c.dispatchEvent(g)}},[o,t]),l.jsx($t.select,{...n,style:{...LD,...n.style},ref:s,defaultValue:t})});iI.displayName=hse;function sI(e){return e===""||e===void 0}function aI(e){const t=jl(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const c=n.current+o;t(c),(function d(m){n.current=m,window.clearTimeout(r.current),m!==""&&(r.current=window.setTimeout(()=>d(""),1e3))})(c)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function oI(e,t,n){const i=t.length>1&&Array.from(t).every(m=>m===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=gse(e,Math.max(s,0));i.length===1&&(o=o.filter(m=>m!==n));const d=o.find(m=>m.textValue.toLowerCase().startsWith(i.toLowerCase()));return d!==n?d:void 0}function gse(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var yse=O4,xse=U4,vse=z4,bse=$4,Tse=B4,_se=q4,kse=K4,wse=Q4,Sse=X4,Mse=eI,Nse=tI,Pse=nI;function zl({...e}){return l.jsx(yse,{"data-slot":"select",...e})}function $l({...e}){return l.jsx(vse,{"data-slot":"select-value",...e})}function Bl({className:e,size:t="default",children:n,...r}){return l.jsxs(xse,{"data-slot":"select-trigger","data-size":t,className:se("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r,children:[n,l.jsx(bse,{asChild:!0,children:l.jsx(Ir,{className:"size-4 opacity-50"})})]})}function ql({className:e,children:t,position:n="popper",...r}){return l.jsx(Tse,{children:l.jsxs(_se,{"data-slot":"select-content",className:se("bg-popover text-popover-foreground 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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[l.jsx(Cse,{}),l.jsx(kse,{className:se("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),l.jsx(Ese,{})]})})}function qs({className:e,children:t,...n}){return l.jsxs(wse,{"data-slot":"select-item",className:se("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[l.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:l.jsx(Mse,{children:l.jsx(ur,{className:"size-4"})})}),l.jsx(Sse,{children:t})]})}function Cse({className:e,...t}){return l.jsx(Nse,{"data-slot":"select-scroll-up-button",className:se("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Sg,{className:"size-4"})})}function Ese({className:e,...t}){return l.jsx(Pse,{"data-slot":"select-scroll-down-button",className:se("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Ir,{className:"size-4"})})}const Dse=[/\bapi[_-]?key\b/i,/\bapikey\b/i,/\bsecret\b/i,/\btoken\b/i,/\bpassword\b/i,/\bauthorization\b/i,/\bauth[_-]?token\b/i,/\bbearer\b/i,/\bcredential\b/i,/\bclient[_-]?secret\b/i];function bv({label:e="Key-Value Pairs",placeholder:t={key:"Key",value:"Value"},pairs:n,onChange:r,disabled:i=!1,className:s="",keyLabel:o="Key",valueLabel:c="Value",maskSensitiveValues:d=!0}){const[m,f]=b.useState(new Set),g=S=>!d||!S?!1:Dse.some(w=>w.test(S)),y=S=>{f(w=>{const N=new Set(w);return N.has(S)?N.delete(S):N.add(S),N})},x=()=>{const S={key:"",value:"",id:`kv-${Date.now()}-${Math.random().toString(36).substring(2,11)}`};r([...n,S])},k=S=>{const w=n.filter(N=>N.id!==S);r(w)},T=(S,w,N)=>{r(n.map(M=>M.id===S?{...M,[w]:N}:M))};return l.jsxs("div",{className:`space-y-3 ${s}`,children:[e&&l.jsx(fn,{className:"text-sm font-medium",children:e}),l.jsxs("div",{className:"space-y-2",children:[n.length>0&&l.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center text-xs text-muted-foreground",children:[l.jsx("div",{className:"col-span-5",children:o}),l.jsx("div",{className:"col-span-6",children:c}),l.jsx("div",{className:"col-span-1"})]}),n.map(S=>{const w=g(S.key),N=m.has(S.id);return l.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center",children:[l.jsx(ct,{placeholder:t.key,value:S.key,onChange:M=>T(S.id,"key",M.target.value),disabled:i,className:"col-span-5"}),l.jsxs("div",{className:"col-span-6 relative",children:[l.jsx(ct,{type:w&&!N?"password":"text",placeholder:t.value,value:S.value,onChange:M=>T(S.id,"value",M.target.value),disabled:i,className:"pr-10"}),w&&S.value&&l.jsx(Pe,{type:"button",variant:"ghost",size:"sm",onClick:()=>y(S.id),disabled:i,className:"absolute right-0 top-0 h-full w-10 p-0 hover:bg-transparent","aria-label":N?"Hide value":"Show value",children:N?l.jsx(cm,{className:"h-4 w-4 text-muted-foreground"}):l.jsx(jc,{className:"h-4 w-4 text-muted-foreground"})})]}),l.jsx(Pe,{type:"button",variant:"ghost",size:"sm",onClick:()=>k(S.id),disabled:i,className:"col-span-1 h-8 w-8 p-0",children:l.jsx(Ar,{className:"h-4 w-4"})})]},S.id)})]}),l.jsxs(Pe,{type:"button",variant:"outline",size:"sm",onClick:x,disabled:i,className:"w-full mt-2",children:[l.jsx(xi,{className:"h-4 w-4 mr-2"}),"Add ",o]})]})}var Qg="Checkbox",[jse]=$o(Qg),[Ise,iT]=jse(Qg);function Rse(e){const{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:s,form:o,name:c,onCheckedChange:d,required:m,value:f="on",internal_do_not_use_render:g}=e,[y,x]=Rl({prop:n,defaultProp:i??!1,onChange:d,caller:Qg}),[k,T]=b.useState(null),[S,w]=b.useState(null),N=b.useRef(!1),M=k?!!o||!!k.closest("form"):!0,P={checked:y,disabled:s,setChecked:x,control:k,setControl:T,name:c,form:o,value:f,hasConsumerStoppedPropagationRef:N,required:m,defaultChecked:Po(i)?!1:i,isFormControl:M,bubbleInput:S,setBubbleInput:w};return l.jsx(Ise,{scope:t,...P,children:Ase(g)?g(P):r})}var lI="CheckboxTrigger",uI=b.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i)=>{const{control:s,value:o,disabled:c,checked:d,required:m,setControl:f,setChecked:g,hasConsumerStoppedPropagationRef:y,isFormControl:x,bubbleInput:k}=iT(lI,e),T=ln(i,f),S=b.useRef(d);return b.useEffect(()=>{const w=s?.form;if(w){const N=()=>g(S.current);return w.addEventListener("reset",N),()=>w.removeEventListener("reset",N)}},[s,g]),l.jsx($t.button,{type:"button",role:"checkbox","aria-checked":Po(d)?"mixed":d,"aria-required":m,"data-state":hI(d),"data-disabled":c?"":void 0,disabled:c,value:o,...r,ref:T,onKeyDown:jt(t,w=>{w.key==="Enter"&&w.preventDefault()}),onClick:jt(n,w=>{g(N=>Po(N)?!0:!N),k&&x&&(y.current=w.isPropagationStopped(),y.current||w.stopPropagation())})})});uI.displayName=lI;var cI=b.forwardRef((e,t)=>{const{__scopeCheckbox:n,name:r,checked:i,defaultChecked:s,required:o,disabled:c,value:d,onCheckedChange:m,form:f,...g}=e;return l.jsx(Rse,{__scopeCheckbox:n,checked:i,defaultChecked:s,disabled:c,required:o,onCheckedChange:m,name:r,form:f,value:d,internal_do_not_use_render:({isFormControl:y})=>l.jsxs(l.Fragment,{children:[l.jsx(uI,{...g,ref:t,__scopeCheckbox:n}),y&&l.jsx(fI,{__scopeCheckbox:n})]})})});cI.displayName=Qg;var pI="CheckboxIndicator",dI=b.forwardRef((e,t)=>{const{__scopeCheckbox:n,forceMount:r,...i}=e,s=iT(pI,n);return l.jsx(ja,{present:r||Po(s.checked)||s.checked===!0,children:l.jsx($t.span,{"data-state":hI(s.checked),"data-disabled":s.disabled?"":void 0,...i,ref:t,style:{pointerEvents:"none",...e.style}})})});dI.displayName=pI;var mI="CheckboxBubbleInput",fI=b.forwardRef(({__scopeCheckbox:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:s,defaultChecked:o,required:c,disabled:d,name:m,value:f,form:g,bubbleInput:y,setBubbleInput:x}=iT(mI,e),k=ln(n,x),T=W2(s),S=p2(r);b.useEffect(()=>{const N=y;if(!N)return;const M=window.HTMLInputElement.prototype,D=Object.getOwnPropertyDescriptor(M,"checked").set,E=!i.current;if(T!==s&&D){const I=new Event("click",{bubbles:E});N.indeterminate=Po(s),D.call(N,Po(s)?!1:s),N.dispatchEvent(I)}},[y,T,s,i]);const w=b.useRef(Po(s)?!1:s);return l.jsx($t.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??w.current,required:c,disabled:d,name:m,value:f,form:g,...t,tabIndex:-1,ref:k,style:{...t.style,...S,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});fI.displayName=mI;function Ase(e){return typeof e=="function"}function Po(e){return e==="indeterminate"}function hI(e){return Po(e)?"indeterminate":e?"checked":"unchecked"}function gI({className:e,...t}){return l.jsx(cI,{"data-slot":"checkbox",className:se("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:l.jsx(dI,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:l.jsx(ur,{className:"size-3.5"})})})}function yI({isOpen:e,onClose:t,onServerConnected:n,initialName:r,initialConfig:i,lockName:s}){const o=i2(),[c,d]=b.useState(""),[m,f]=b.useState("stdio"),[g,y]=b.useState(""),[x,k]=b.useState(""),[T,S]=b.useState(""),[w,N]=b.useState([]),[M,P]=b.useState([]),[D,E]=b.useState(null),[I,R]=b.useState(!1),[K,L]=b.useState(!1),U=j=>{const W={};return j.forEach(z=>{z.key.trim()&&z.value.trim()&&(W[z.key.trim()]=z.value.trim())}),W},G=j=>{const W={};for(const{key:z,value:$}of j){const A=z.trim(),Q=$.trim();A&&Q&&(W[A]=Q)}return W},Y=j=>{const W=["api_key","secret","token","password","key"],z={};for(const[$,A]of Object.entries(j)){const Q=W.some(ne=>$.toLowerCase().includes(ne));z[$]=Q?"***masked***":A}return z},B=j=>{const W=["authorization","proxy-authorization","api-key","x-api-key","token","cookie","set-cookie"],z={};for(const[$,A]of Object.entries(j)){const Q=$.toLowerCase(),ne=W.some(O=>Q===O||Q.includes(O));z[$]=ne?"***masked***":A}return z};b.useEffect(()=>{if(!e){const j=setTimeout(()=>{d(""),f("stdio"),y(""),k(""),S(""),N([]),P([]),E(null),R(!1)},300);return()=>clearTimeout(j)}},[e]),b.useEffect(()=>{if(!e)return;d(r??"");const j=i?.type??"stdio";if(f(j),j==="stdio"){const W=i??{};y(typeof W.command=="string"?W.command:""),k(Array.isArray(W.args)?W.args.join(", "):"");const z=Object.entries(W.env??{});P(z.map(([$,A],Q)=>({key:$,value:String(A??""),id:`env-${Q}`}))),S(""),N([])}else{const W=i??{};S(typeof W.url=="string"?W.url:"");const z=Object.entries(W.headers??{});N(z.map(([$,A],Q)=>({key:$,value:String(A??""),id:`hdr-${Q}`}))),y(""),k(""),P([])}},[e,r,i]);const q=async j=>{if(j.preventDefault(),E(null),R(!0),!c.trim()){E("Server name is required."),R(!1);return}if(m==="stdio"){if(!g.trim()){E("Command is required for stdio servers."),R(!1);return}const z=M.map($=>$.key.trim()).filter(Boolean);if(z.length){const $=z.filter((Q,ne)=>z.indexOf(Q)!==ne);if($.length){E(`Duplicate environment variables: ${Array.from(new Set($)).join(", ")}`),R(!1);return}const A=M.filter(Q=>Q.key.trim()&&!Q.value.trim()).map(Q=>Q.key.trim());if(A.length){E(`Please set required environment variables: ${A.join(", ")}`),R(!1);return}}}else{if(!T.trim()){E(`URL is required for ${m.toUpperCase()} servers.`),R(!1);return}try{new URL(T.trim())}catch{E(`Invalid URL format for ${m.toUpperCase()} server.`),R(!1);return}}let W;m==="stdio"?W={type:"stdio",command:g.trim(),args:x.split(",").map(z=>z.trim()).filter(Boolean),env:G(M),timeout:3e4,connectionMode:"lenient"}:m==="sse"?W={type:"sse",url:T.trim(),headers:w.length?U(w):{},timeout:3e4,connectionMode:"lenient"}:W={type:"http",url:T.trim(),headers:w.length?U(w):{},timeout:3e4,connectionMode:"lenient"};try{await o.mutateAsync({name:c.trim(),config:W,persistToAgent:K}),n?.(),t()}catch(z){let $="Failed to connect server";z instanceof Error?$=z.message||$:typeof z=="string"&&($=z),o.reset(),E($)}finally{R(!1)}};return l.jsx(qr,{open:e,onOpenChange:j=>!j&&t(),children:l.jsxs(Gr,{className:"sm:max-w-[480px]",children:[l.jsxs(ti,{children:[l.jsx(Hr,{children:"Connect New MCP Server"}),l.jsx(is,{children:"Configure connection details for a new MCP server (stdio, SSE, or HTTP)."})]}),l.jsxs("form",{id:"connectServerForm",onSubmit:q,className:"grid gap-4 py-4",children:[D&&l.jsx(ri,{variant:"destructive",children:l.jsx(ii,{children:D})}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"serverName",className:"text-right",children:"Server Name"}),l.jsx(ct,{id:"serverName",value:c,onChange:j=>d(j.target.value),className:"col-span-3",placeholder:"e.g., My Local Tools",required:!0,disabled:I||!!s})]}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"serverType",className:"text-right",children:"Server Type"}),l.jsxs(zl,{value:m,onValueChange:j=>f(j),disabled:I,children:[l.jsx(Bl,{id:"serverType",className:"col-span-3",children:l.jsx($l,{placeholder:"Select type"})}),l.jsxs(ql,{children:[l.jsx(qs,{value:"stdio",children:"stdio"}),l.jsx(qs,{value:"sse",children:"sse"}),l.jsx(qs,{value:"http",children:"http"})]})]})]}),m==="stdio"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"command",className:"text-right",children:"Command"}),l.jsx(ct,{id:"command",value:g,onChange:j=>y(j.target.value),className:"col-span-3",placeholder:"e.g., /path/to/executable or python",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"args",className:"text-right",children:"Arguments"}),l.jsx(ct,{id:"args",value:x,onChange:j=>k(j.target.value),className:"col-span-3",placeholder:"Comma-separated, e.g., -m,script.py,--port,8080",disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Environment"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:M,onChange:P,placeholder:{key:"API_KEY",value:"your-secret-key"},disabled:I,keyLabel:"Variable",valueLabel:"Value"})})]})]}):m==="sse"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"url",className:"text-right",children:"URL"}),l.jsx(ct,{id:"url",type:"url",value:T,onChange:j=>S(j.target.value),className:"col-span-3",placeholder:"e.g., http://localhost:8000/events",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Headers"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:w,onChange:N,placeholder:{key:"Authorization",value:"Bearer your-token"},disabled:I,keyLabel:"Header",valueLabel:"Value"})})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[l.jsx(fn,{htmlFor:"url",className:"text-right",children:"URL"}),l.jsx(ct,{id:"url",type:"url",value:T,onChange:j=>S(j.target.value),className:"col-span-3",placeholder:"e.g., http://localhost:8080",required:!0,disabled:I})]}),l.jsxs("div",{className:"grid grid-cols-4 items-start gap-4",children:[l.jsx(fn,{className:"text-right mt-2",children:"Headers"}),l.jsx("div",{className:"col-span-3",children:l.jsx(bv,{pairs:w,onChange:N,placeholder:{key:"Authorization",value:"Bearer your-token"},disabled:I,keyLabel:"Header",valueLabel:"Value"})})]})]}),l.jsxs("div",{className:"flex items-center space-x-2 pt-2",children:[l.jsx(gI,{id:"persistToAgent",checked:K,onCheckedChange:j=>L(j===!0),disabled:I}),l.jsx(fn,{htmlFor:"persistToAgent",className:"text-sm font-normal cursor-pointer",children:"Save to agent configuration file"})]})]}),l.jsxs(Ui,{children:[l.jsx(D4,{asChild:!0,children:l.jsx(Pe,{type:"button",variant:"outline",disabled:I,children:"Cancel"})}),l.jsx(Pe,{type:"submit",form:"connectServerForm",disabled:I,children:I?"Connecting...":"Connect"})]})]})})}var Ose=[{id:"filesystem",name:"Filesystem",description:"Secure file operations with configurable access controls for reading and writing files",category:"productivity",icon:"📁",config:{type:"stdio",command:"npx",args:["-y","@modelcontextprotocol/server-filesystem","."],timeout:3e4},tags:["file","directory","filesystem","io"],isOfficial:!0,isInstalled:!1,author:"Anthropic",homepage:"https://github.com/modelcontextprotocol/servers",matchIds:["filesystem"]},{id:"meme-mcp",name:"Meme Generator",description:"Create memes using Imgflip templates",category:"creative",icon:"🖼️",config:{type:"stdio",command:"npx",args:["-y","meme-mcp"],env:{IMGFLIP_USERNAME:"",IMGFLIP_PASSWORD:""},timeout:3e4},tags:["meme","image","creative"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Community",homepage:"https://www.npmjs.com/package/meme-mcp",matchIds:["meme-mcp"]},{id:"product-name-scout",name:"Product Name Scout",description:"SERP analysis, autocomplete, dev collisions, and scoring for product names",category:"research",icon:"🔎",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/product-name-scout-mcp"],timeout:3e4},tags:["research","naming","brand"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["product-name-scout"]},{id:"duckduckgo",name:"DuckDuckGo Search",description:"Search the web using DuckDuckGo",category:"research",icon:"🦆",config:{type:"stdio",command:"uvx",args:["duckduckgo-mcp-server"],timeout:3e4},tags:["search","web","research"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",python:">=3.10",dependencies:["uv"]},author:"Community",homepage:"https://github.com/duckduckgo/mcp-server",matchIds:["duckduckgo","ddg"]},{id:"domain-checker",name:"Domain Checker",description:"Check domain availability across TLDs",category:"research",icon:"🌐",config:{type:"stdio",command:"uvx",args:["truffle-ai-domain-checker-mcp"],timeout:3e4},tags:["domains","availability","research"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["domain-checker"]},{id:"swiggy-food",name:"Swiggy Food",description:"Order food with restaurant search, menus, cart management, and checkout",category:"productivity",icon:"🍔",config:{type:"http",url:"https://mcp.swiggy.com/food",timeout:3e4},tags:["swiggy","food","delivery","ordering"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-food","swiggy_food"]},{id:"swiggy-instamart",name:"Swiggy Instamart",description:"Shop groceries with product search, cart management, and checkout",category:"productivity",icon:"🛒",config:{type:"http",url:"https://mcp.swiggy.com/im",timeout:3e4},tags:["swiggy","instamart","groceries","delivery"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-instamart","swiggy_instamart"]},{id:"swiggy-dineout",name:"Swiggy Dineout",description:"Find restaurants, check availability, and book tables",category:"productivity",icon:"🍽️",config:{type:"http",url:"https://mcp.swiggy.com/dineout",timeout:3e4},tags:["swiggy","dineout","reservations","restaurants"],isOfficial:!0,isInstalled:!1,author:"Swiggy",homepage:"https://github.com/Swiggy/swiggy-mcp-server-manifest",matchIds:["swiggy-dineout","swiggy_dineout"]},{id:"linear",name:"Linear",description:"Manage Linear issues, projects, and workflows",category:"productivity",icon:"📋",config:{type:"stdio",command:"npx",args:["-y","mcp-remote","https://mcp.linear.app/sse"],timeout:3e4},tags:["linear","tasks","projects"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Linear",homepage:"https://mcp.linear.app",matchIds:["linear"]},{id:"image-editor",name:"Image Editor",description:"Comprehensive image processing and manipulation tools",category:"creative",icon:"🖌️",config:{type:"stdio",command:"uvx",args:["truffle-ai-image-editor-mcp"],timeout:3e4},tags:["image","edit","opencv","pillow"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["image_editor","image-editor"]},{id:"music-creator",name:"Music Creator",description:"Create, analyze, and transform music and audio",category:"creative",icon:"🎵",config:{type:"stdio",command:"uvx",args:["truffle-ai-music-creator-mcp"],timeout:3e4},tags:["audio","music","effects"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["music_creator","music-creator"]},{id:"elevenlabs",name:"ElevenLabs",description:"Text-to-speech and voice synthesis using ElevenLabs API",category:"creative",icon:"🎤",config:{type:"stdio",command:"uvx",args:["elevenlabs-mcp"],env:{ELEVENLABS_API_KEY:""},timeout:3e4},tags:["tts","voice","audio","synthesis"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"ElevenLabs",homepage:"https://github.com/elevenlabs/elevenlabs-mcp",matchIds:["elevenlabs"]},{id:"hf",name:"Hugging Face",description:"Access Hugging Face models and datasets",category:"development",icon:"🤗",config:{type:"stdio",command:"npx",args:["-y","@llmindset/mcp-hfspace"],timeout:3e4},tags:["huggingface","models","ai","ml"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"LLMindset",homepage:"https://github.com/llmindset/mcp-hfspace",matchIds:["hf","huggingface"]},{id:"parallel-search",name:"Parallel Search",description:"Search the web and retrieve relevant content with source citations",category:"research",icon:"🔍",config:{type:"http",url:"https://search.parallel.ai/mcp",headers:{},timeout:3e4},tags:["search","web","research","citations"],isOfficial:!0,isInstalled:!1,author:"Parallel",homepage:"https://parallel.ai",matchIds:["parallel-search","parallel_search","parallel"]},{id:"tavily",name:"Tavily Search",description:"Web search and research using Tavily AI search engine",category:"research",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","tavily-mcp@0.1.3"],env:{TAVILY_API_KEY:""},timeout:3e4},tags:["search","web","research","ai"],isOfficial:!1,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Tavily AI",homepage:"https://www.npmjs.com/package/tavily-mcp",matchIds:["tavily"]},{id:"puppeteer",name:"Puppeteer",description:"Browser automation and web interaction tools",category:"productivity",icon:"🌐",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/puppeteer-server"],timeout:3e4},tags:["browser","automation","web","puppeteer"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["puppeteer"]},{id:"gemini-tts",name:"Gemini TTS",description:"Google Gemini Text-to-Speech with 30 prebuilt voices and multi-speaker conversation support",category:"creative",icon:"🎙️",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/gemini-tts-server"],env:{GEMINI_API_KEY:""},timeout:6e4},tags:["tts","speech","voice","audio","gemini","multi-speaker"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["gemini-tts","gemini_tts"]},{id:"nano-banana",name:"Nano Banana",description:"Google Gemini 2.5 Flash Image for advanced image generation, editing, and manipulation",category:"creative",icon:"🍌",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/nano-banana-server@0.1.2"],env:{GEMINI_API_KEY:""},timeout:6e4},tags:["image","generation","editing","ai","gemini","nano-banana"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["nano-banana","nano_banana"]},{id:"openai-image",name:"OpenAI Image",description:"OpenAI's image generation and editing API with GPT Image models and DALL-E support",category:"creative",icon:"🎨",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/openai-image-server"],env:{OPENAI_API_KEY:""},timeout:6e4},tags:["image","generation","editing","ai","openai","dall-e","gpt-image"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers/tree/main/src/openai-image",matchIds:["openai-image","openai_image"]},{id:"heygen",name:"HeyGen",description:"Generate realistic human-like audio using HeyGen",category:"creative",icon:"🎤",config:{type:"stdio",command:"uvx",args:["heygen-mcp"],env:{HEYGEN_API_KEY:""},timeout:3e4},tags:["audio","voice","synthesis","heygen"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",python:">=3.10"},author:"HeyGen",homepage:"https://github.com/heygen-com/heygen-mcp",matchIds:["heygen"]},{id:"runway",name:"Runway",description:"AI-powered creative suite for video and image generation",category:"creative",icon:"🎬",config:{type:"stdio",command:"npx",args:["mcp-remote","https://mcp.runway.team","--header","Authorization: Bearer ${RUNWAY_API_KEY}"],env:{RUNWAY_API_KEY:""},timeout:6e4},tags:["runway","video","generation","ai","creative"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Runway",homepage:"https://docs.runway.team/api/runway-mcp-server",matchIds:["runway"]},{id:"perplexity",name:"Perplexity",description:"AI-powered search engine for real-time web search and research",category:"research",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","@perplexity-ai/mcp-server"],env:{PERPLEXITY_API_KEY:"",PERPLEXITY_TIMEOUT_MS:"600000"},timeout:6e5},tags:["search","web","research","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Perplexity AI",homepage:"https://github.com/perplexityai/modelcontextprotocol/tree/main",matchIds:["perplexity"]},{id:"sora",name:"Sora",description:"AI-powered video generation using OpenAI's Sora technology",category:"creative",icon:"🎬",config:{type:"stdio",command:"npx",args:["-y","@truffle-ai/sora-video-server"],env:{OPENAI_API_KEY:""},timeout:6e4},tags:["video","generation","ai","creative"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Truffle AI",homepage:"https://github.com/truffle-ai/mcp-servers",matchIds:["sora","sora_video"]},{id:"chartjs",name:"ChartJS",description:"Charting and visualization tool using ChartJS",category:"data",icon:"📊",config:{type:"stdio",command:"npx",args:["-y","@ax-crew/chartjs-mcp-server"],timeout:3e4},tags:["chart","visualization","data","chartjs"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"ax-crew",homepage:"https://github.com/ax-crew/chartjs-mcp-server",matchIds:["chartjs"]},{id:"rag-lite-ts",name:"Rag-lite TS",description:"A local-first TypeScript retrieval engine for semantic search over static documents.",category:"data",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","raglite-mcp"],timeout:3e4},tags:["rag","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"FrugalX",homepage:"https://github.com/raglite/rag-lite-ts",matchIds:["rag-lite-ts"]},{id:"exa",name:"Exa",description:"AI-powered web search and research API with semantic search capabilities.",category:"data",icon:"🔍",config:{type:"http",url:"https://mcp.exa.ai/mcp",headers:{}},tags:["rag","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Exa",homepage:"https://docs.exa.ai/reference/exa-mcp",matchIds:["exa"]},{id:"firecrawl",name:"Firecrawl",description:"AI-powered web search and research API that performs semantic search across web sources, aggregates and ranks results for relevance, and returns contextual summaries with citations",category:"data",icon:"🔍",config:{type:"stdio",command:"npx",args:["-y","firecrawl-mcp"],env:{FIRECRAWL_API_KEY:""},timeout:3e4},tags:["search","web","research","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Firecrawl",homepage:"https://docs.firecrawl.dev/mcp-server",matchIds:["firecrawl"]},{id:"shadcn",name:"Shadcn",description:"Shadcn UI components for MCP servers",category:"development",icon:"🖌️",config:{type:"stdio",command:"npx",args:["shadcn@latest","mcp"],timeout:3e4},tags:["shadcn","ui","components","mcp"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Shadcn",homepage:"https://ui.shadcn.com/docs/mcp#configuration",matchIds:["shadcn"]},{id:"kite-trade",name:"Kite",description:"Zerodha Kite API MCP server",category:"data",icon:"💰",config:{type:"http",url:"https://mcp.kite.trade/mcp",headers:{}},tags:["kite","trade","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"Zerodha",homepage:"https://github.com/zerodha/kite-mcp-server",matchIds:["kite-trade"]},{id:"coingecko",name:"CoinGecko",description:"CoinGecko API MCP server",category:"data",icon:"💰",config:{type:"http",url:"https://mcp.api.coingecko.com/mcp",headers:{}},tags:["coingecko","data","ai"],isOfficial:!0,isInstalled:!1,requirements:{platform:"all",node:">=18.0.0"},author:"CoinGecko",homepage:"https://docs.coingecko.com/docs/mcp-server",matchIds:["coingecko"]}];function HP(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}var Fse=class _d{static instance;registryEntries=[];isInitialized=!1;constructor(){}static getInstance(){return _d.instance||(_d.instance=new _d),_d.instance}async initialize(){this.isInitialized||(this.registryEntries=Ose,this.isInitialized=!0)}async getEntries(t){await this.initialize();let n=[...this.registryEntries];if(t?.category&&(n=n.filter(r=>r.category===t.category)),t?.tags?.length&&(n=n.filter(r=>t.tags.some(i=>r.tags.includes(i)))),t?.search){const r=t.search.toLowerCase();n=n.filter(i=>i.name.toLowerCase().includes(r)||i.description.toLowerCase().includes(r)||i.tags.some(s=>s.toLowerCase().includes(r)))}return t?.installed!==void 0&&(n=n.filter(r=>r.isInstalled===t.installed)),t?.official!==void 0&&(n=n.filter(r=>r.isOfficial===t.official)),n.sort((r,i)=>r.isInstalled!==i.isInstalled?r.isInstalled?-1:1:r.isOfficial!==i.isOfficial?r.isOfficial?-1:1:r.name.localeCompare(i.name))}async updateEntry(t,n){await this.initialize();const r=this.registryEntries.find(i=>i.id===t);return r?(Object.assign(r,n),!0):!1}async setInstalled(t,n){return this.updateEntry(t,{isInstalled:n})}async syncInstalledStatus(t){await this.initialize();const n=new Set(t.map(HP));for(const r of this.registryEntries){const s=[r.id,r.name,...r.matchIds||[]].filter(Boolean).map(o=>HP(String(o))).some(o=>n.has(o));r.isInstalled!==s&&(r.isInstalled=s)}}async getServerConfig(t){return await this.initialize(),this.registryEntries.find(n=>n.id===t)||null}async getCategories(){await this.initialize();const t=new Set(this.registryEntries.map(n=>n.category));return Array.from(t).sort()}async getTags(){await this.initialize();const t=new Set(this.registryEntries.flatMap(n=>n.tags));return Array.from(t).sort()}},Use=Fse.getInstance();class xo{constructor(){this.registryEntries=[],this.isInitialized=!1}static normalizeId(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return xo.instance||(xo.instance=new xo),xo.instance}async initialize(){this.isInitialized||(this.registryEntries=await this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(t){await this.initialize();let n=[...this.registryEntries];if(t?.category&&(n=n.filter(r=>r.category===t.category)),t?.tags?.length&&(n=n.filter(r=>t.tags.some(i=>r.tags.includes(i)))),t?.search){const r=t.search.toLowerCase();n=n.filter(i=>i.name.toLowerCase().includes(r)||i.description.toLowerCase().includes(r)||i.tags.some(s=>s.toLowerCase().includes(r)))}return t?.installed!==void 0&&(n=n.filter(r=>r.isInstalled===t.installed)),t?.official!==void 0&&(n=n.filter(r=>r.isOfficial===t.official)),n.sort((r,i)=>r.isInstalled!==i.isInstalled?r.isInstalled?-1:1:r.isOfficial!==i.isOfficial?r.isOfficial?-1:1:r.name.localeCompare(i.name))}async updateEntry(t,n){const r=this.registryEntries.findIndex(i=>i.id===t);return r===-1?!1:(this.registryEntries[r]={...this.registryEntries[r],...n},!0)}async setInstalled(t,n){return this.updateEntry(t,{isInstalled:n})}async syncWithServerStatus(){try{if(await this.initialize(),this.registryEntries.length===0){console.warn("Registry entries not available for status sync");return}const t=await Xe.api.mcp.servers.$get();if(!t.ok)throw new Error(`Failed to fetch servers: ${t.status}`);const r=(await t.json()).servers||[],i=new Set;r.forEach(s=>{if(!s?.id||typeof s.id!="string")return;const o=xo.normalizeId(s.id);i.add(o)});for(const s of this.registryEntries){const d=[s.id,s.name,...s.matchIds||[]].filter(Boolean).map(m=>xo.normalizeId(String(m))).some(m=>i.has(m));s.isInstalled!==d&&(s.isInstalled=d)}}catch(t){console.warn("Failed to sync registry with server status:",t)}}async getServerConfig(t){return await this.initialize(),this.registryEntries.find(n=>n.id===t)||null}async getBuiltinEntries(){return Use.getEntries()}}const Ts=xo.getInstance();function m1({isOpen:e,onClose:t,onInstallServer:n,onOpenConnectModal:r,refreshTrigger:i,disableClose:s=!1}){const[o,c]=b.useState([]),[d,m]=b.useState([]),[f,g]=b.useState(!1),[y,x]=b.useState(null),[k,T]=b.useState(null),[S]=b.useState({}),[w,N]=b.useState(""),[M,P]=b.useState("grid"),[D,E]=b.useState(null),I=b.useRef(null),R=b.useRef(!0),K=b.useRef(null);b.useEffect(()=>(R.current=!0,()=>{R.current=!1,I.current&&clearTimeout(I.current),K.current&&K.current.abort()}),[]),b.useEffect(()=>{if(!e)return;(async()=>{K.current&&K.current.abort();const W=new AbortController;if(K.current=W,!!R.current){g(!0),x(null);try{await Ts.syncWithServerStatus();const z=await Ts.getEntries();R.current&&!W.signal.aborted&&(c(z),m(z))}catch(z){if(R.current&&!W.signal.aborted){const $=z instanceof Error?z.message:"Failed to load server registry";x($)}}finally{R.current&&!W.signal.aborted&&g(!1)}}})()},[e,i]);const L=b.useCallback(async(j,W)=>{if(R.current)try{const z=await Ts.getEntries({...j,search:W||void 0});R.current&&m(z)}catch(z){if(R.current){const $=z instanceof Error?z.message:"Failed to filter entries";x($)}}},[]);b.useEffect(()=>(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{L(S,w)},300),()=>{I.current&&clearTimeout(I.current)}),[S,w,o,L]);const U=async j=>{if(R.current){T(j.id);try{await n(j)==="connected"?(await Ts.setInstalled(j.id,!0),R.current&&(c(z=>z.map($=>$.id===j.id?{...$,isInstalled:!0}:$)),m(z=>z.map($=>$.id===j.id?{...$,isInstalled:!0}:$)))):R.current&&(c(z=>z.map($=>$.id===j.id?{...$,isInstalled:!1}:$)),m(z=>z.map($=>$.id===j.id?{...$,isInstalled:!1}:$)))}catch(W){if(R.current){const z=W instanceof Error?W.message:"Failed to install server";x(z)}}finally{R.current&&T(null)}}},G=j=>{const W={productivity:"bg-blue-50 text-blue-700 border-blue-200/60",development:"bg-emerald-50 text-emerald-700 border-emerald-200/60",research:"bg-purple-50 text-purple-700 border-purple-200/60",creative:"bg-pink-50 text-pink-700 border-pink-200/60",data:"bg-amber-50 text-amber-700 border-amber-200/60",communication:"bg-indigo-50 text-indigo-700 border-indigo-200/60",custom:"bg-slate-50 text-slate-700 border-slate-200/60"};return W[j]||W.custom},Y=s||!!k,B=b.useCallback(j=>{!j&&!Y&&t()},[Y,t]),q=Y?j=>{j.preventDefault()}:void 0;return l.jsx(qr,{open:e,onOpenChange:B,children:l.jsxs(Gr,{className:"!max-w-none w-[90vw] max-h-[85vh] overflow-hidden flex flex-col !sm:max-w-none p-0 bg-gradient-to-b from-background via-background to-muted/20",hideCloseButton:!0,onEscapeKeyDown:Y?j=>j.preventDefault():void 0,onInteractOutside:q,children:[l.jsx(ti,{className:"pb-4 border-b px-6 pt-5 bg-gradient-to-r from-muted/30 via-transparent to-transparent",children:l.jsxs("div",{className:"flex items-center justify-between gap-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:l.jsx(So,{className:"h-5 w-5 text-primary"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx(Hr,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),l.jsx(is,{className:"text-sm text-muted-foreground",children:"Discover and add integrations to your AI assistant"})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Pe,{onClick:()=>{Y||t(),r?.()},size:"sm",variant:"outline",className:"h-8 px-3 text-sm font-medium hover:bg-muted whitespace-nowrap",children:[l.jsx(kB,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),l.jsxs(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>t(),disabled:Y,children:[l.jsx(Cn,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}),l.jsxs("div",{className:"flex gap-3 mb-5 px-6 pt-5",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60 pointer-events-none z-10"}),l.jsx(ct,{placeholder:"Search servers and integrations...",value:w,onChange:j=>N(j.target.value),className:"pl-10 h-10 border focus:border-primary/40 bg-background text-sm placeholder:text-muted-foreground/50 focus:ring-1 focus:ring-primary/20 transition-all"})]}),l.jsxs("div",{className:"flex bg-muted/50 rounded-md p-1 border",children:[l.jsxs(Pe,{variant:M==="grid"?"secondary":"ghost",size:"sm",onClick:()=>{P("grid"),E(null)},className:se("h-8 px-3 rounded-sm transition-all text-sm font-medium",M==="grid"?"bg-background shadow-sm":"hover:bg-background/50"),children:[l.jsx(QB,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),l.jsxs(Pe,{variant:M==="list"?"secondary":"ghost",size:"sm",onClick:()=>{P("list"),E(null)},className:se("h-8 px-3 rounded-sm transition-all text-sm font-medium",M==="list"?"bg-background shadow-sm":"hover:bg-background/50"),children:[l.jsx(oq,{className:"h-3.5 w-3.5 mr-1.5"}),"List"]})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:[y&&l.jsx(ri,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:l.jsx(ii,{className:"text-red-800 font-medium",children:y})}),f?l.jsx("div",{className:"flex items-center justify-center py-24",children:l.jsxs("div",{className:"flex flex-col items-center space-y-5",children:[l.jsx("div",{className:"h-12 w-12 border-4 border-primary/30 border-t-primary rounded-full animate-spin"}),l.jsx("div",{className:"text-lg text-foreground font-semibold",children:"Discovering servers..."}),l.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading registry entries"})]})}):d.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[l.jsx("div",{className:"p-6 rounded-2xl bg-gradient-to-br from-muted/50 to-muted/30 border-2 border-border/30 mb-6 shadow-sm",children:l.jsx(So,{className:"h-14 w-14 text-muted-foreground/60 mx-auto"})}),l.jsx("div",{className:"text-xl font-bold text-foreground mb-3",children:o.length===0?"No servers available in the registry":"No servers match your search"}),l.jsx("div",{className:"text-base text-muted-foreground/80 mb-6 max-w-md",children:o.length===0?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),w&&l.jsxs(Pe,{variant:"outline",onClick:()=>N(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[l.jsx(Rr,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):l.jsx("div",{className:se(M==="grid"?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:d.map((j,W)=>{const z=D===j.id,$=j.description&&j.description.length>100;return M==="grid"?l.jsx(n1,{className:se("group relative overflow-hidden transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-lg hover:border-primary/30 flex flex-col",z&&"ring-1 ring-primary/20 border-primary/40 shadow-lg -translate-y-0.5"),style:{animationDelay:`${Math.min(W*30,300)}ms`},children:l.jsxs("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>E(z?null:j.id),children:[l.jsx(Cte,{className:"pb-3 flex-shrink-0",children:l.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsx("div",{className:"text-2xl w-12 h-12 flex items-center justify-center rounded-lg bg-gradient-to-br from-primary/15 to-primary/5 border border-primary/20 group-hover:border-primary/30 transition-all duration-200",children:j.icon||"⚡"}),j.isInstalled&&l.jsx("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-emerald-500 rounded-full border-2 border-card flex items-center justify-center",children:l.jsx(Ls,{className:"h-2.5 w-2.5 text-white"})})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx(Ete,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-snug line-clamp-2",children:j.name}),l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[j.isOfficial&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[l.jsx(Sb,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),j.category&&l.jsx(Qn,{variant:"outline",className:se("text-xs px-1.5 py-0 font-medium capitalize",G(j.category)),children:j.category})]})]})]})}),l.jsxs(Dte,{className:"pt-0 flex flex-col flex-1",children:[l.jsxs("div",{className:"flex-1",children:[l.jsx("p",{className:se("text-sm text-muted-foreground leading-relaxed transition-all duration-200",z?"":"line-clamp-3"),children:j.description}),z&&l.jsxs("div",{className:"space-y-3 pt-3 mt-3 border-t border-border/30 animate-in slide-in-from-top-1 duration-200",children:[j.author&&l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("div",{className:"p-1 rounded bg-muted/40",children:l.jsx(YM,{className:"h-3 w-3 text-muted-foreground"})}),l.jsxs("div",{children:[l.jsxs("span",{className:"text-muted-foreground/70",children:["by"," "]}),l.jsx("span",{className:"font-medium text-foreground",children:j.author})]})]}),j.tags&&j.tags.length>0&&l.jsxs("div",{className:"flex flex-wrap gap-1",children:[j.tags.slice(0,6).map(A=>l.jsx(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:A},A)),j.tags.length>6&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20",children:["+",j.tags.length-6]})]}),j.homepage&&l.jsxs("a",{href:j.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:A=>A.stopPropagation(),children:[l.jsx(yc,{className:"h-3 w-3"}),"Documentation"]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-border/30 flex-shrink-0 mt-auto",children:[$&&l.jsx(Pe,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-foreground p-0 h-auto font-medium -ml-1",children:z?l.jsxs(l.Fragment,{children:[l.jsx(Sg,{className:"h-3 w-3 mr-1"}),"Less"]}):l.jsxs(l.Fragment,{children:[l.jsx(Ir,{className:"h-3 w-3 mr-1"}),"More"]})}),l.jsx("div",{className:"ml-auto",children:l.jsx(Pe,{onClick:A=>{A.stopPropagation(),U(j)},disabled:j.isInstalled||k===j.id,size:"sm",variant:j.isInstalled?"outline":"default",className:se("h-8 px-4 transition-all font-semibold text-sm shadow-sm",k===j.id&&"opacity-70",j.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!j.isInstalled&&"bg-primary hover:bg-primary/90"),children:k===j.id?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),l.jsx("span",{children:"Adding"})]}):j.isInstalled?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ls,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Added"})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xi,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Add"})]})})})]})]})]})},j.id):l.jsx(n1,{className:se("group transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-md hover:border-primary/30 cursor-pointer !py-0 !gap-0",z&&"border-primary/40 shadow-md -translate-y-0.5"),onClick:()=>E(z?null:j.id),children:l.jsx("div",{className:"p-4",children:l.jsxs("div",{className:"flex items-start gap-4",children:[l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsx("div",{className:"w-12 h-12 rounded-lg bg-gradient-to-br from-primary/15 to-primary/5 border border-primary/20 group-hover:border-primary/30 flex items-center justify-center text-2xl transition-all duration-200",children:j.icon||"⚡"}),j.isInstalled&&l.jsx("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-emerald-500 rounded-full border-2 border-card flex items-center justify-center",children:l.jsx(Ls,{className:"h-2.5 w-2.5 text-white"})})]}),l.jsxs("div",{className:"flex-1 min-w-0 space-y-2.5",children:[l.jsxs("div",{className:"flex items-start justify-between gap-4",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[l.jsx("h3",{className:"text-base font-semibold text-foreground group-hover:text-primary transition-colors leading-snug",children:j.name}),$&&l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",z&&"rotate-180 text-muted-foreground")})]}),l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[j.isOfficial&&l.jsxs(Qn,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[l.jsx(Sb,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),j.category&&l.jsx(Qn,{variant:"outline",className:se("text-xs px-1.5 py-0 font-medium capitalize",G(j.category)),children:j.category})]})]}),l.jsx(Pe,{onClick:A=>{A.stopPropagation(),U(j)},disabled:j.isInstalled||k===j.id,size:"sm",variant:j.isInstalled?"outline":"default",className:se("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",k===j.id&&"opacity-70",j.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!j.isInstalled&&"bg-primary hover:bg-primary/90"),children:k===j.id?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),l.jsx("span",{children:"Adding"})]}):j.isInstalled?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ls,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Added"})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xi,{className:"h-3.5 w-3.5"}),l.jsx("span",{children:"Add"})]})})]}),l.jsx("div",{children:l.jsx("p",{className:se("text-sm text-muted-foreground leading-relaxed transition-all duration-200",z?"":"line-clamp-2"),children:j.description})}),z&&l.jsxs("div",{className:"space-y-3 pt-3 border-t border-border/30 animate-in slide-in-from-top-2 duration-200",children:[j.author&&l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("div",{className:"p-1 rounded bg-muted/40",children:l.jsx(YM,{className:"h-3 w-3 text-muted-foreground"})}),l.jsxs("div",{children:[l.jsxs("span",{className:"text-muted-foreground/70",children:["by"," "]}),l.jsx("span",{className:"font-medium text-foreground",children:j.author})]})]}),j.tags&&j.tags.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:j.tags.map(A=>l.jsx(Qn,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:A},A))}),j.homepage&&l.jsxs("a",{href:j.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:A=>A.stopPropagation(),children:[l.jsx(yc,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},j.id)})})]})]})})}const Lse=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),zse=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],$se=[/^your[\s_-]?/,/^enter[\s_-]?/];function ug(e){return Object.values(e).some(t=>{if(!t||t.trim()==="")return!0;const n=t.trim().toLowerCase();return Lse.has(n)||$se.some(r=>r.test(n))?!0:zse.some(r=>n.includes(r))})}function xI(e){const t=e.config.timeout??3e4;switch(e.config.type){case"stdio":return{type:"stdio",command:e.config.command??"",args:e.config.args??[],env:e.config.env??{},timeout:t,connectionMode:"lenient"};case"sse":return{type:"sse",url:e.config.url??"",headers:e.config.headers??{},timeout:t,connectionMode:"lenient"};default:return{type:"http",url:e.config.url??"",headers:e.config.headers??{},timeout:t,connectionMode:"lenient"}}}function Bse(e=!0){return Dn({queryKey:Ge.tools.all,queryFn:async()=>{const t=await Xe.api.tools.$get();if(!t.ok)throw new Error("Failed to fetch tools");return await t.json()},enabled:e})}function qse(){return Dn({queryKey:Ge.agents.all,queryFn:async()=>{const e=await Xe.api.agents.$get();if(!e.ok)throw new Error(`Failed to fetch agents: ${e.status}`);return await e.json()},staleTime:300*1e3})}function vI(){return Dn({queryKey:Ge.agents.path,queryFn:async()=>{const e=await Xe.api.agent.path.$get();if(!e.ok)throw new Error(`Failed to fetch agent path: ${e.status}`);return await e.json()},retry:!1,staleTime:300*1e3})}function Gse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.switch.$post({json:t});if(!n.ok)throw new Error(`Failed to switch agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all}),e.invalidateQueries({queryKey:Ge.agents.path})}})}function Hse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.install.$post({json:t});if(!n.ok)throw new Error(`Failed to install agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all})}})}function Vse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.uninstall.$post({json:t});if(!n.ok)throw new Error(`Failed to uninstall agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all}),e.invalidateQueries({queryKey:Ge.agents.path})}})}function Kse(){const e=un();return nn({mutationFn:async t=>{const n=await Xe.api.agents.custom.create.$post({json:t});if(!n.ok)throw new Error(`Failed to create agent: ${n.status}`);return await n.json()},onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agents.all})}})}function VP(e,t){if(t!=="mcp"||!e.startsWith("mcp--"))return e;const n=e.substring(5),r=n.split("--");return r.length>=2?r.slice(1).join("--"):n}function KP({isOpen:e,onClose:t,onOpenConnectModal:n,onOpenConnectWithPrefill:r,onServerConnected:i,variant:s,refreshTrigger:o}){const c=s??"overlay",d=Cc(),[m,f]=b.useState(!1),[g,y]=b.useState(!1),[x,k]=b.useState(""),[T,S]=b.useState(null),[w,N]=b.useState(new Set),{data:M=[],isLoading:P,refetch:D}=mD(e),E=i2(),I=dH(),R=mH(),{data:K,isLoading:L,refetch:U}=Bse(e),{data:G}=vI(),Y=b.useCallback(()=>{D(),U()},[D,U]),B=b.useCallback(Q=>{N(ne=>{const O=new Set(ne);return O.has(Q)?O.delete(Q):O.add(Q),O})},[]),q=b.useMemo(()=>{if(!K)return{local:[],mcp:new Map};const Q=[],ne=new Map;return K.tools.forEach(O=>{if(O.source==="local")Q.push(O);else if(O.source==="mcp"&&O.serverName){const be=ne.get(O.serverName)||{tools:[],server:null};if(be.tools.push(O),!be.server){const Ue=M.find(Ce=>Ce.name===O.serverName);be.server=Ue||null}ne.set(O.serverName,be)}}),{local:Q,mcp:ne}},[K,M]),j=b.useMemo(()=>{const Q=[],ne=x.toLowerCase();if(q.local.length>0){const O=x?q.local.filter(be=>be.name.toLowerCase().includes(ne)||be.description?.toLowerCase().includes(ne)):q.local;O.length>0&&Q.push({title:"Local",tools:O,type:"local"})}return q.mcp.forEach(({tools:O,server:be},Ue)=>{const Ce=Ue.toLowerCase().includes(ne),ae=x?Ce?O:O.filter(ze=>ze.name.toLowerCase().includes(ne)||ze.description?.toLowerCase().includes(ne)):O;ae.length>0&&Q.push({title:Ue,tools:ae,type:"mcp",server:be})}),Q},[q,x]),W=K?.totalCount||0,z=async Q=>{const ne=xI(Q),O=ne.type==="stdio"&&Object.keys(ne.env||{}).length>0&&ug(ne.env||{}),be=(ne.type==="sse"||ne.type==="http")&&Object.keys(ne.headers||{}).length>0&&ug(ne.headers||{});if(O||be)return typeof r=="function"&&r({name:Q.name,config:ne,lockName:!0,registryEntryId:Q.id,onCloseRegistryModal:()=>f(!1)}),"requires-input";try{y(!0),await E.mutateAsync({name:Q.name,config:ne,persistToAgent:!1});try{await Ts.syncWithServerStatus()}catch(Ue){console.warn("Failed to sync registry after server install:",Ue)}return d.trackMCPServerConnected({serverName:Q.name,transportType:ne.type}),f(!1),i?.(Q.name),"connected"}catch(Ue){throw new Error(Ue.message||"Failed to install server")}finally{y(!1)}},$=async Q=>{const ne=M.find(O=>O.id===Q);if(ne&&window.confirm(`Are you sure you want to remove server "${ne.name}"?`))try{await I.mutateAsync(Q);try{const O=ae=>ae.toLowerCase().replace(/[^a-z0-9]+/g,"-"),be=O(Q),Ce=(await Ts.getEntries()).find(ae=>[ae.id,ae.name,...ae.matchIds||[]].filter(Boolean).map(lt=>O(String(lt))).includes(be));Ce&&await Ts.setInstalled(Ce.id,!1)}catch(O){console.warn("Failed to update registry installed state on delete:",O)}try{await Ts.syncWithServerStatus()}catch(O){console.warn("Failed to sync registry status after server deletion:",O)}}catch(O){console.error("Delete server error:",O)}},A=async Q=>{const ne=M.find(O=>O.id===Q);if(ne&&window.confirm(`Restart server "${ne.name}"?`))try{await R.mutateAsync(Q);try{await Ts.syncWithServerStatus()}catch(O){console.warn("Failed to sync registry status after server restart:",O)}}catch(O){console.error("Restart server error:",O)}};return b.useEffect(()=>{e&&Y()},[e,G,o,Y]),c==="inline"?l.jsxs("aside",{className:"h-full w-full flex flex-col bg-card/30",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 shrink-0 border-b border-border/30",children:[l.jsxs("button",{onClick:t,className:"flex items-center gap-2 group",children:[l.jsx("h2",{className:"text-xs font-bold text-foreground/80 tracking-wider uppercase group-hover:text-foreground transition-colors",children:"Tools & Servers"}),l.jsx(Ir,{className:"h-3.5 w-3.5 text-muted-foreground/50 -rotate-90 transition-transform group-hover:text-foreground/70"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{side:"left",children:"Connect MCP servers"})]}),l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:Y,disabled:P||L,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Qi,{className:se("h-4 w-4",(P||L)&&"animate-spin")})})}),l.jsx(Vt,{side:"left",children:"Refresh"})]})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col",children:[l.jsx("div",{className:"px-4 pt-4 pb-3 border-b border-border/20",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/50 pointer-events-none"}),l.jsx("input",{type:"text",value:x,onChange:Q=>k(Q.target.value),placeholder:"Search tools...",className:"w-full pl-9 pr-3 py-2 text-sm bg-background/50 border border-border/40 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all placeholder:text-muted-foreground/40"}),x&&l.jsx("button",{onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-muted/50 rounded transition-colors",children:l.jsx(Cn,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-4",children:[L&&l.jsx("div",{className:"flex items-center justify-center py-16",children:l.jsxs("div",{className:"flex flex-col items-center space-y-3",children:[l.jsxs("div",{className:"relative",children:[l.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/20"}),l.jsx("div",{className:"absolute inset-0 h-8 w-8 rounded-full border-2 border-primary border-t-transparent animate-spin"})]}),l.jsx("span",{className:"text-xs font-medium text-muted-foreground/70",children:"Loading tools..."})]})}),!L&&W===0&&l.jsxs("div",{className:"text-center py-16",children:[l.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-full bg-muted/30 mb-4",children:l.jsx(VM,{className:"h-6 w-6 text-muted-foreground/40"})}),l.jsx("p",{className:"text-sm font-medium text-foreground/70 mb-1",children:"No tools available"}),l.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Connect an MCP server to get started"})]}),!L&&W>0&&j.length===0&&l.jsxs("div",{className:"text-center py-16",children:[l.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-full bg-muted/30 mb-4",children:l.jsx(Rr,{className:"h-6 w-6 text-muted-foreground/40"})}),l.jsx("p",{className:"text-sm font-medium text-foreground/70 mb-1",children:"No tools match your search"}),l.jsx("p",{className:"text-xs text-muted-foreground/60 mb-3",children:"Try a different search term"}),l.jsx("button",{onClick:()=>k(""),className:"text-xs font-medium text-primary hover:text-primary/80 transition-colors",children:"Clear search"})]}),j.map(Q=>{const ne=w.has(Q.title);return l.jsxs("div",{className:"mb-4 last:mb-0",children:[l.jsxs("div",{className:"w-full flex items-center justify-between gap-2 mb-3 px-1 group transition-all duration-150",children:[l.jsxs("button",{onClick:()=>B(Q.title),className:"flex items-center gap-2.5 flex-1 min-w-0 pb-2 border-b border-border/40 text-left",children:[l.jsx(Ir,{className:se("h-4 w-4 text-muted-foreground/50 shrink-0 transition-transform duration-200",ne&&"-rotate-90")}),l.jsxs("h4",{className:"text-base font-semibold text-foreground tracking-tight flex items-center gap-2.5",children:[l.jsx("span",{className:"tracking-normal",children:Q.title}),Q.type==="mcp"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px] font-semibold uppercase tracking-wider",children:"MCP"}),Q.server&&l.jsx("span",{className:se("inline-flex items-center justify-center w-5 h-5 rounded-full",Q.server.status==="connected"?"bg-green-500/10":"bg-red-500/10"),children:l.jsx("span",{className:se("w-2 h-2 rounded-full",Q.server.status==="connected"?"bg-green-600 dark:bg-green-400":"bg-red-600 dark:bg-red-400")})})]})]}),l.jsx("span",{className:"text-xs text-muted-foreground/50 font-medium",children:Q.tools.length})]}),Q.type==="mcp"&&Q.server&&l.jsxs("div",{className:"flex items-center gap-0.5",children:[R.isPending&&R.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>A(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-primary hover:bg-muted/50",disabled:I.isPending&&I.variables===Q.server.id,children:l.jsx(ZM,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Restart"})]}),I.isPending&&I.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>$(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-destructive hover:bg-muted/50",disabled:R.isPending&&R.variables===Q.server.id,children:l.jsx(Ar,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Remove"})]})]})]}),!ne&&l.jsx("div",{className:"space-y-0.5 ml-2",children:Q.tools.map(O=>{const be=O.id,Ue=T===be;return l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>S(Ue?null:be),className:"w-full px-3 py-2 rounded-md text-left hover:bg-muted/30 transition-all duration-150 group flex items-center justify-between gap-2",children:[l.jsx("span",{className:"text-sm text-foreground/90 truncate font-medium",children:VP(O.name,Q.type)}),l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/40 shrink-0 transition-transform duration-200",Ue&&"rotate-180")})]}),Ue&&l.jsxs("div",{className:"px-3 py-2.5 mb-1 bg-muted/15 rounded-md ml-2",children:[O.description&&l.jsx("p",{className:"text-xs text-muted-foreground/70 mb-2.5 leading-relaxed",children:O.description}),O.inputSchema?.properties&&Object.keys(O.inputSchema.properties).length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-[10px] text-muted-foreground/50 uppercase tracking-wider font-semibold",children:"Parameters"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.keys(O.inputSchema.properties).map(Ce=>l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded bg-muted/50 text-[10px] font-mono text-foreground/60 border border-border/20",children:Ce},Ce))})]})]})]},be)})})]},Q.title)})]})]}),l.jsx(m1,{isOpen:m,onClose:()=>f(!1),onInstallServer:z,onOpenConnectModal:n,disableClose:g})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:se("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",e?"opacity-100":"opacity-0 pointer-events-none"),onClick:t}),l.jsxs("aside",{className:se("fixed top-0 right-0 z-40 h-screen w-80 bg-card/95 backdrop-blur-xl border-l border-border/40 shadow-xl transition-transform duration-300 ease-in-out flex flex-col",e?"translate-x-0":"translate-x-full"),children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3.5 shrink-0",children:[l.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{side:"left",children:"Connect MCP servers"})]}),l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:Y,disabled:P||L,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Qi,{className:se("h-4 w-4",(P||L)&&"animate-spin")})})}),l.jsx(Vt,{side:"left",children:"Refresh"})]}),l.jsx(Pe,{variant:"ghost",size:"sm",onClick:t,className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground hover:bg-muted/40",children:l.jsx(Cn,{className:"h-4 w-4"})})]})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto flex flex-col",children:[l.jsx("div",{className:"px-4 pt-3 pb-2 border-b border-border/20",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/50 pointer-events-none"}),l.jsx("input",{type:"text",value:x,onChange:Q=>k(Q.target.value),placeholder:"Search tools...",className:"w-full pl-9 pr-3 py-2 text-sm bg-background/50 border border-border/40 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all placeholder:text-muted-foreground/40"}),x&&l.jsx("button",{onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-muted/50 rounded transition-colors",children:l.jsx(Cn,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}),l.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[L&&l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[l.jsx(Qi,{className:"h-5 w-5 animate-spin text-muted-foreground/50"}),l.jsx("span",{className:"text-xs text-muted-foreground/70",children:"Loading tools..."})]})}),!L&&W===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(VM,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-muted-foreground/70",children:"No tools available"}),l.jsx("p",{className:"text-xs text-muted-foreground/50 mt-1",children:"Connect an MCP server to get started"})]}),!L&&W>0&&j.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-muted-foreground/70",children:"No tools match your search"}),l.jsx("button",{onClick:()=>k(""),className:"mt-2 text-xs text-primary hover:text-primary/80 transition-colors",children:"Clear search"})]}),j.map(Q=>{const ne=w.has(Q.title);return l.jsxs("div",{className:"mb-4 last:mb-0",children:[l.jsxs("div",{className:"w-full flex items-center justify-between gap-2 mb-3 px-1 group transition-all duration-150",children:[l.jsxs("button",{onClick:()=>B(Q.title),className:"flex items-center gap-2.5 flex-1 min-w-0 pb-2 border-b border-border/40 text-left",children:[l.jsx(Ir,{className:se("h-4 w-4 text-muted-foreground/50 shrink-0 transition-transform duration-200",ne&&"-rotate-90")}),l.jsxs("h4",{className:"text-base font-semibold text-foreground tracking-tight flex items-center gap-2.5",children:[l.jsx("span",{className:"tracking-normal",children:Q.title}),Q.type==="mcp"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px] font-semibold uppercase tracking-wider",children:"MCP"}),Q.server&&l.jsx("span",{className:se("inline-flex items-center justify-center w-5 h-5 rounded-full",Q.server.status==="connected"?"bg-green-500/10":"bg-red-500/10"),children:l.jsx("span",{className:se("w-2 h-2 rounded-full",Q.server.status==="connected"?"bg-green-600 dark:bg-green-400":"bg-red-600 dark:bg-red-400")})})]})]}),l.jsx("span",{className:"text-xs text-muted-foreground/50 font-medium",children:Q.tools.length})]}),Q.type==="mcp"&&Q.server&&l.jsxs("div",{className:"flex items-center gap-0.5",children:[R.isPending&&R.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>A(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-primary hover:bg-muted/50",disabled:I.isPending&&I.variables===Q.server.id,children:l.jsx(ZM,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Restart"})]}),I.isPending&&I.variables===Q.server.id?l.jsx("div",{className:"h-6 w-6 flex items-center justify-center",children:l.jsx(Qi,{className:"h-3 w-3 animate-spin text-muted-foreground"})}):l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>$(Q.server.id),className:"h-6 w-6 p-0 text-muted-foreground/60 hover:text-destructive hover:bg-muted/50",disabled:R.isPending&&R.variables===Q.server.id,children:l.jsx(Ar,{className:"h-3 w-3"})})}),l.jsx(Vt,{side:"left",children:"Remove"})]})]})]}),!ne&&l.jsx("div",{className:"space-y-0.5 ml-2",children:Q.tools.map(O=>{const be=O.id,Ue=T===be;return l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>S(Ue?null:be),className:"w-full px-3 py-2 rounded-md text-left hover:bg-muted/30 transition-all duration-150 group flex items-center justify-between gap-2",children:[l.jsx("span",{className:"text-sm text-foreground/90 truncate font-medium",children:VP(O.name,Q.type)}),l.jsx(Ir,{className:se("h-3.5 w-3.5 text-muted-foreground/40 shrink-0 transition-transform duration-200",Ue&&"rotate-180")})]}),Ue&&l.jsxs("div",{className:"px-3 py-2.5 mb-1 bg-muted/15 rounded-md ml-2",children:[O.description&&l.jsx("p",{className:"text-xs text-muted-foreground/70 mb-2.5 leading-relaxed",children:O.description}),O.inputSchema?.properties&&Object.keys(O.inputSchema.properties).length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-[10px] text-muted-foreground/50 uppercase tracking-wider font-semibold",children:"Parameters"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.keys(O.inputSchema.properties).map(Ce=>l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded bg-muted/50 text-[10px] font-mono text-foreground/60 border border-border/20",children:Ce},Ce))})]})]})]},be)})})]},Q.title)})]})]}),l.jsx(m1,{isOpen:m,onClose:()=>f(!1),onInstallServer:z,onOpenConnectModal:n,disableClose:g})]})]})}const vm=b.forwardRef(({className:e,children:t,...n},r)=>l.jsx("div",{ref:r,className:se("relative overflow-auto",e),...n,children:t}));vm.displayName="ScrollArea";function Wse(e){return e.sort((t,n)=>{const r=t.lastActivity?new Date(t.lastActivity).getTime():0;return(n.lastActivity?new Date(n.lastActivity).getTime():0)-r})}function WP({isOpen:e,onClose:t,onExpand:n,currentSessionId:r,onSessionChange:i,returnToWelcome:s,variant:o="overlay",onSearchOpen:c,onNewChat:d,onSettingsOpen:m,onPlaygroundOpen:f,onThemeToggle:g,theme:y}){const[x,k]=b.useState(!1),[T,S]=b.useState(""),[w,N]=b.useState(!1),[M,P]=b.useState(null),[D,E]=b.useState(!1),[I,R]=b.useState(""),[K,L]=b.useState(null),{data:U=[],isLoading:G,error:Y}=lH(e),B=Wse([...U]),q=uH(),j=dD(),W=cH(),z=async()=>{const ae=await q.mutateAsync({sessionId:T.trim()||void 0});S(""),k(!1),i(ae.id)},$=async ae=>{await j.mutateAsync({sessionId:ae}),r===ae&&s()},A=async()=>{if(!M)return;await j.mutateAsync({sessionId:M}),r===M&&s(),N(!1),P(null)},Q=(ae,ze)=>{P(ae),R(ze||""),E(!0)},ne=async()=>{if(!(!M||!I.trim()))try{await W.mutateAsync({sessionId:M,title:I.trim()}),E(!1),P(null),R("")}catch(ae){console.error(`Failed to rename session: ${ae}`)}},O=async ae=>{try{await navigator.clipboard.writeText(ae),L(ae)}catch(ze){console.error(`Failed to copy session ID: ${ze}`)}};b.useEffect(()=>{if(K){const ae=setTimeout(()=>L(null),2e3);return()=>clearTimeout(ae)}},[K]);const be=ae=>{if(!ae)return"Unknown";const lt=Date.now()-ae,me=Math.floor(lt/6e4),pe=Math.floor(lt/36e5),J=Math.floor(lt/864e5);return me<1?"Just now":me<60?`${me}m ago`:pe<24?`${pe}h ago`:`${J}d ago`},Ue=l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"px-4 py-5",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{id:"sessionpanel-title",className:"flex items-center px-2",children:[l.jsx("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-6 w-auto dark:hidden"}),l.jsx("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-6 w-auto hidden dark:block"})]}),l.jsx("button",{onClick:t,className:"flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Collapse panel",children:l.jsx(fB,{className:"h-5 w-5"})})]})}),Y&&l.jsx("div",{className:"p-4",children:l.jsxs(ri,{variant:"destructive",children:[l.jsx(ns,{className:"h-4 w-4"}),l.jsx(ii,{children:Y.message})]})}),l.jsxs(vm,{className:"flex-1 scrollbar-thin",children:[l.jsxs("div",{className:"px-3 pt-2 pb-1 space-y-0.5",children:[d&&l.jsxs("button",{onClick:d,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(xi,{className:"h-4 w-4"}),l.jsx("span",{children:"New Chat"})]}),c&&l.jsxs("button",{onClick:c,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(Rr,{className:"h-4 w-4"}),l.jsx("span",{children:"Search"})]})]}),(d||c)&&l.jsx("div",{className:"h-2"}),!G&&B.length>0&&l.jsx("div",{className:"px-4 py-2",children:l.jsx("h2",{className:"text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider",children:"History"})}),G?l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsx(Qi,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):B.length===0?l.jsxs("div",{className:"text-center py-12 px-6",children:[l.jsx(UE,{className:"h-10 w-10 mx-auto mb-3 text-muted-foreground/30"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"No conversations yet"}),l.jsx("p",{className:"text-xs text-muted-foreground/60 mt-1",children:"Start chatting to see your history"})]}):l.jsx("div",{className:"px-3 py-2 space-y-0.5",children:B.map(ae=>{const ze=ae.title&&ae.title.trim().length>0?ae.title:ae.id,lt=r===ae.id;return l.jsx("div",{className:se("group relative px-3 py-1.5 rounded-lg transition-all cursor-pointer",lt?"bg-primary/5 before:absolute before:left-0 before:top-1.5 before:bottom-1.5 before:w-0.5 before:bg-primary before:rounded-full":"hover:bg-muted/40"),role:"button",tabIndex:0,"aria-current":lt?"page":void 0,onClick:()=>i(ae.id),onKeyDown:me=>{me.target===me.currentTarget&&(me.key==="Enter"||me.key===" ")&&(me.preventDefault(),i(ae.id))},children:l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("h3",{className:se("text-sm truncate flex-1 min-w-0",lt?"font-medium text-foreground":"text-muted-foreground"),children:ze}),l.jsx("span",{className:"text-[10px] text-muted-foreground/50 shrink-0 group-hover:opacity-0 transition-opacity",children:be(ae.lastActivity)}),l.jsxs(kc,{children:[l.jsx(wc,{asChild:!0,children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:me=>me.stopPropagation(),className:"h-7 w-7 p-0 absolute right-2 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":"Session options",children:l.jsx(OE,{className:"h-4 w-4 text-muted-foreground"})})}),l.jsxs(Ol,{align:"end",className:"w-48",onClick:me=>me.stopPropagation(),children:[l.jsxs(Zt,{onClick:()=>Q(ae.id,ae.title??null),children:[l.jsx(wb,{className:"h-4 w-4 mr-2"}),"Rename"]}),l.jsxs(Zt,{onClick:()=>O(ae.id),children:[K===ae.id?l.jsx(ur,{className:"h-4 w-4 mr-2 text-green-500"}):l.jsx(Ao,{className:"h-4 w-4 mr-2"}),K===ae.id?"Copied!":"Copy Session ID"]}),l.jsx(ka,{}),l.jsxs(Zt,{onClick:()=>{ae.messageCount>0?(P(ae.id),N(!0)):$(ae.id)},className:"text-destructive focus:text-destructive",children:[l.jsx(Ar,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})]})},ae.id)})})]}),l.jsxs("div",{className:"border-t border-border/30 p-3 space-y-1",children:[f&&l.jsxs("button",{onClick:f,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(_b,{className:"h-4 w-4"}),l.jsx("span",{children:"MCP Playground"})]}),f&&(g||m)&&l.jsx("div",{className:"h-px bg-border/30 my-1"}),g&&l.jsxs("button",{onClick:g,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[y==="dark"?l.jsx(Mb,{className:"h-4 w-4 transition-transform duration-200 hover:rotate-180"}):l.jsx(kb,{className:"h-4 w-4 transition-transform duration-200 hover:rotate-12"}),l.jsx("span",{children:y==="dark"?"Light Mode":"Dark Mode"})]}),m&&l.jsxs("button",{onClick:m,className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors",children:[l.jsx(Yd,{className:"h-4 w-4"}),l.jsx("span",{children:"Settings"})]})]}),l.jsx(qr,{open:x,onOpenChange:k,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsx(ti,{children:l.jsx(Hr,{children:"Start New Chat"})}),l.jsx("div",{className:"space-y-4",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(fn,{htmlFor:"sessionId",children:"Chat ID"}),l.jsx(ct,{id:"sessionId",value:T,onChange:ae=>S(ae.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),l.jsx(Pe,{onClick:z,children:"Start Chat"})]})]})}),l.jsx(qr,{open:w,onOpenChange:N,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-5 w-5 text-destructive"}),l.jsx("span",{children:"Delete Conversation"})]}),l.jsxs(is,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",M&&l.jsxs("span",{className:"block mt-2 font-medium",children:["Session:"," ",l.jsx("span",{className:"font-mono",children:M})]})]})]}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>N(!1),children:"Cancel"}),l.jsxs(Pe,{variant:"destructive",onClick:A,disabled:j.isPending&&j.variables?.sessionId===M,className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-4 w-4"}),l.jsx("span",{children:j.isPending&&j.variables?.sessionId===M?"Deleting...":"Delete Conversation"})]})]})]})}),l.jsx(qr,{open:D,onOpenChange:E,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(wb,{className:"h-5 w-5"}),l.jsx("span",{children:"Rename Chat"})]}),l.jsx(is,{children:"Enter a new name for this conversation."})]}),l.jsx("div",{className:"space-y-4",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(fn,{htmlFor:"renameTitle",children:"Chat Name"}),l.jsx(ct,{id:"renameTitle",value:I,onChange:ae=>R(ae.target.value),placeholder:"Enter chat name...",onKeyDown:ae=>{ae.key==="Enter"&&I.trim()&&ne()},autoFocus:!0})]})}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>E(!1),children:"Cancel"}),l.jsx(Pe,{onClick:ne,disabled:!I.trim()||W.isPending,children:W.isPending?"Saving...":"Save"})]})]})})]}),Ce=l.jsxs("div",{className:"flex flex-col h-full py-3 px-2 items-center",children:[l.jsx("button",{onClick:n,className:"flex items-center justify-center w-10 h-10 rounded-lg hover:bg-muted/40 transition-colors mb-3","aria-label":"Expand panel",children:l.jsx("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-7 w-7"})}),l.jsxs("div",{className:"flex flex-col gap-1 flex-1",children:[d&&l.jsx("button",{onClick:d,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"New chat",children:l.jsx(xi,{className:"h-5 w-5"})}),c&&l.jsx("button",{onClick:c,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Search",children:l.jsx(Rr,{className:"h-5 w-5"})})]}),l.jsxs("div",{className:"flex flex-col gap-1 pt-2 border-t border-border/30",children:[f&&l.jsx("button",{onClick:f,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"MCP Playground",children:l.jsx(_b,{className:"h-5 w-5"})}),g&&l.jsx("button",{onClick:g,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":y==="dark"?"Light mode":"Dark mode",children:y==="dark"?l.jsx(Mb,{className:"h-5 w-5"}):l.jsx(kb,{className:"h-5 w-5"})}),m&&l.jsx("button",{onClick:m,className:"flex items-center justify-center w-10 h-10 rounded-lg text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-colors","aria-label":"Settings",children:l.jsx(Yd,{className:"h-5 w-5"})})]})]});return o==="inline"?e?l.jsx("div",{className:"h-full w-full flex flex-col bg-card",children:Ue}):l.jsx("div",{className:"h-full flex flex-col bg-card border-r border-border/30",children:Ce}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:se("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",e?"opacity-100":"opacity-0 pointer-events-none"),onClick:t}),l.jsx("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:se("fixed top-0 left-0 z-40 h-screen w-72 bg-card border-r border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",e?"translate-x-0":"-translate-x-full"),children:Ue})]})}function Zse(e,t="en"){const n=Date.now(),r=e-n,i=Math.abs(r),s=60*1e3,o=60*s,c=24*o,d=7*c,m=30*c,f=365*c;let g,y;return i<s?(g=Math.round(r/1e3),y="second"):i<o?(g=Math.round(r/s),y="minute"):i<c?(g=Math.round(r/o),y="hour"):i<d?(g=Math.round(r/c),y="day"):i<m?(g=Math.round(r/d),y="week"):i<f?(g=Math.round(r/m),y="month"):(g=Math.round(r/f),y="year"),new Intl.RelativeTimeFormat(t,{numeric:"auto"}).format(g,y)}function Yse({isOpen:e,onClose:t,variant:n="modal"}){const[r,i]=b.useState(""),[s,o]=b.useState(!1),[c,d]=b.useState(!1),[m,f]=b.useState(null),{data:g=[],isLoading:y,error:x}=Eie(e),k=Die(),T=async M=>{await k.mutateAsync({memoryId:M}),d(!1),f(null)},S=(M,P=120)=>M.length<=P?M:M.slice(0,P)+"...",w=g.filter(M=>{if(!r.trim())return!0;const P=r.toLowerCase();return M.content.toLowerCase().includes(P)||M.tags?.some(D=>D.toLowerCase().includes(P))}),N=l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Ro,{className:"h-4 w-4"}),l.jsx("h2",{className:"text-base font-semibold",children:"Memories"}),l.jsx(Qn,{variant:"secondary",className:"text-xs",children:g.length})]})}),l.jsx("div",{className:"p-3 border-b border-border/50",children:l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(Rr,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),l.jsx(ct,{placeholder:"Search memories...",value:r,onChange:M=>i(M.target.value),className:"pl-8 h-8 text-sm"})]}),l.jsx(va,{children:l.jsxs(Gt,{children:[l.jsx(Ht,{asChild:!0,children:l.jsx(Pe,{variant:"outline",size:"sm",onClick:()=>o(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:l.jsx(xi,{className:"h-4 w-4"})})}),l.jsx(Vt,{children:"Create Memory"})]})})]})}),x&&l.jsx("div",{className:"p-4",children:l.jsxs(ri,{variant:"destructive",children:[l.jsx(ns,{className:"h-4 w-4"}),l.jsx(ii,{children:x.message})]})}),l.jsx(vm,{className:"flex-1 p-4",children:l.jsx("div",{className:"space-y-2",children:y?l.jsx("div",{className:"flex items-center justify-center py-8",children:l.jsx(Qi,{className:"h-6 w-6 animate-spin"})}):w.length===0?l.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[l.jsx(Ro,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),r.trim()?l.jsxs(l.Fragment,{children:[l.jsx("p",{children:"No memories found"}),l.jsx("p",{className:"text-sm",children:"Try a different search term"})]}):l.jsxs(l.Fragment,{children:[l.jsx("p",{children:"No memories yet"}),l.jsx("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):w.map(M=>l.jsx("div",{className:se("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",M.metadata?.pinned&&"ring-1 ring-primary/30 bg-primary/5"),children:l.jsxs("div",{className:"flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[l.jsx("p",{className:"text-sm leading-relaxed",children:S(M.content)}),M.tags&&M.tags.length>0&&l.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[l.jsx(Gq,{className:"h-3 w-3 text-muted-foreground"}),M.tags.map((P,D)=>l.jsx(Qn,{variant:"outline",className:"text-xs px-1.5 py-0",children:P},D))]}),l.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(cB,{className:"h-3 w-3"}),l.jsx("span",{children:Zse(M.updatedAt)})]}),M.metadata?.source&&l.jsx(Qn,{variant:"secondary",className:"text-xs px-1.5 py-0",children:M.metadata.source}),M.metadata?.pinned&&l.jsx(Qn,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),l.jsx("div",{className:"flex items-center gap-1",children:l.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>{f(M),d(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:l.jsx(Ar,{className:"h-3.5 w-3.5 text-destructive"})})})]})},M.id))})}),l.jsx(A4,{open:s,onClose:()=>o(!1)}),l.jsx(qr,{open:c,onOpenChange:d,children:l.jsxs(Gr,{className:"sm:max-w-md",children:[l.jsxs(ti,{children:[l.jsxs(Hr,{className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-5 w-5 text-destructive"}),l.jsx("span",{children:"Delete Memory"})]}),l.jsxs(is,{children:["This will permanently delete this memory. This action cannot be undone.",m&&l.jsx("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:S(m.content,100)})]})]}),l.jsxs(Ui,{children:[l.jsx(Pe,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),l.jsxs(Pe,{variant:"destructive",onClick:()=>m&&T(m.id),disabled:k.isPending,className:"flex items-center space-x-2",children:[l.jsx(Ar,{className:"h-4 w-4"}),l.jsx("span",{children:k.isPending?"Deleting...":"Delete Memory"})]})]})]})})]});return n==="inline"?l.jsx("div",{className:"h-full",children:N}):l.jsx(qr,{open:e,onOpenChange:t,children:l.jsxs(Gr,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[l.jsx(ti,{className:"sr-only",children:l.jsx(Hr,{children:"Memories"})}),N]})})}function Qse({onApprove:e,onDeny:t,onHandlersReady:n}){const r=Ma(g=>g.currentSessionId),i=V1(g=>g.pendingApproval),{ensureSessionEventStream:s}=Q1(),{mutateAsync:o}=z9(),c=i&&(!i.sessionId||!r||i.sessionId===r)?i:null,d=b.useCallback(async(g,y,x)=>{if(!c)return;const{approvalId:k}=c;console.debug(`[WebUI] Sending approval response for ${k}: ${g?"approved":"denied"}`);const T=c.sessionId||r;if(!T){console.error("[WebUI] Cannot submit approval without sessionId");return}try{await s(T),await o({approvalId:k,sessionId:T,status:g?Pd.APPROVED:Pd.DENIED,...g&&y?{formData:y}:{},...g&&x!==void 0?{rememberChoice:x}:{}})}catch(S){const w=S instanceof Error?S.message:String(S);console.error(`[WebUI] Failed to send approval response: ${w}`);return}},[c,r,o,s]),m=b.useCallback((g,y)=>{d(!0,g,y),e?.(g,y)},[d,e]),f=b.useCallback(()=>{d(!1),t?.()},[d,t]);return b.useEffect(()=>{n&&n({onApprove:m,onDeny:f})},[m,f,n]),null}function Xse(e,t,n,r){var i=this,s=b.useRef(null),o=b.useRef(0),c=b.useRef(0),d=b.useRef(null),m=b.useRef([]),f=b.useRef(),g=b.useRef(),y=b.useRef(e),x=b.useRef(!0);y.current=e;var k=typeof window<"u",T=!t&&t!==0&&k;if(typeof e!="function")throw new TypeError("Expected a function");t=+t||0;var S=!!(n=n||{}).leading,w=!("trailing"in n)||!!n.trailing,N="maxWait"in n,M="debounceOnServer"in n&&!!n.debounceOnServer,P=N?Math.max(+n.maxWait||0,t):null;b.useEffect(function(){return x.current=!0,function(){x.current=!1}},[]);var D=b.useMemo(function(){var E=function(Y){var B=m.current,q=f.current;return m.current=f.current=null,o.current=Y,c.current=c.current||Y,g.current=y.current.apply(q,B)},I=function(Y,B){T&&cancelAnimationFrame(d.current),d.current=T?requestAnimationFrame(Y):setTimeout(Y,B)},R=function(Y){if(!x.current)return!1;var B=Y-s.current;return!s.current||B>=t||B<0||N&&Y-o.current>=P},K=function(Y){return d.current=null,w&&m.current?E(Y):(m.current=f.current=null,g.current)},L=function Y(){var B=Date.now();if(S&&c.current===o.current&&U(),R(B))return K(B);if(x.current){var q=t-(B-s.current),j=N?Math.min(q,P-(B-o.current)):q;I(Y,j)}},U=function(){r&&r({})},G=function(){if(k||M){var Y=Date.now(),B=R(Y);if(m.current=[].slice.call(arguments),f.current=i,s.current=Y,B){if(!d.current&&x.current)return o.current=s.current,I(L,t),S?E(s.current):g.current;if(N)return I(L,t),E(s.current)}return d.current||I(L,t),g.current}};return G.cancel=function(){var Y=d.current;Y&&(T?cancelAnimationFrame(d.current):clearTimeout(d.current)),o.current=0,m.current=s.current=f.current=d.current=null,Y&&r&&r({})},G.isPending=function(){return!!d.current},G.flush=function(){return d.current?K(Date.now()):g.current},G},[S,N,t,P,w,T,k,M,r]);return D}function Jse(e,t){return e===t}function bI(e,t,n){var r=Jse,i=b.useRef(e),s=b.useState({})[1],o=Xse(b.useCallback(function(d){i.current=d,s({})},[s]),t,n,s),c=b.useRef(e);return r(c.current,e)||(o(e),c.current=e),[i.current,o]}function eae(e,t,n=50,r=!0){return Dn({queryKey:Ge.search.messages(e,t,n),queryFn:async()=>await os(Xe.api.search.messages.$get({query:{q:e,limit:n,...t}}),"Failed to search messages"),enabled:r&&e.trim().length>0,staleTime:3e4})}function tae({isOpen:e,onClose:t,onNavigateToSession:n}){const[r,i]=b.useState(""),[s]=bI(r,300),[o,c]=b.useState(0),{data:d,isLoading:m,error:f}=eae(s,void 0,10,e),g=d?.results||[],y=f?.message??null;b.useEffect(()=>{o>=g.length&&g.length>0?c(g.length-1):g.length===0&&c(0)},[g.length,o]);const x=b.useCallback(w=>{n(w.sessionId,w.messageIndex),t()},[n,t]);b.useEffect(()=>{e&&(i(""),c(0))},[e]),Xr("down",()=>{c(w=>Math.min(w+1,g.length-1))},{enabled:e,preventDefault:!0},[e,g.length]),Xr("up",()=>{c(w=>Math.max(w-1,0))},{enabled:e,preventDefault:!0},[e]),Xr("enter",()=>{g[o]&&(x(g[o]),c(0))},{enabled:e,preventDefault:!0},[e,g,o,x]),Xr("escape",()=>{t()},{enabled:e,preventDefault:!0},[e,t]);const k=w=>{switch(w){case"user":return l.jsx(Xq,{className:"w-4 h-4"});case"assistant":return l.jsx(Tb,{className:"w-4 h-4"});case"system":return l.jsx(Yd,{className:"w-4 h-4"});default:return l.jsx(hq,{className:"w-4 h-4"})}},T=w=>{switch(w){case"user":return"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";case"assistant":return"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200";case"system":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";default:return"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200"}},S=(w,N)=>{if(!N)return w;const M=N.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),P=new RegExp(`(${M})`,"gi");return w.split(P).map((E,I)=>E.toLowerCase()===N.toLowerCase()?l.jsx("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:E},I):E)};return e?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 z-40 bg-black/10 backdrop-blur-[2px]",onClick:t}),l.jsx("div",{className:"fixed left-1/2 top-[15%] -translate-x-1/2 z-50 w-full max-w-2xl bg-popover/70 backdrop-blur-xl border border-border/30 rounded-xl shadow-2xl overflow-hidden",children:l.jsxs("div",{className:"flex flex-col max-h-[70vh]",children:[l.jsx("div",{className:"p-4 border-b border-border/30",children:l.jsxs("div",{className:"relative",children:[l.jsx(Rr,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),l.jsx(ct,{placeholder:"Search conversations...",value:r,onChange:w=>i(w.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),l.jsx("div",{className:"flex-1 overflow-hidden",children:m?l.jsxs("div",{className:"flex items-center justify-center py-12",children:[l.jsx(Qi,{className:"h-6 w-6 animate-spin mr-3"}),l.jsx("span",{className:"text-muted-foreground",children:"Searching..."})]}):f?l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsxs("div",{className:"text-center",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),l.jsx("p",{className:"text-destructive font-medium",children:"Search Error"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:y}),l.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):l.jsx(vm,{className:"h-full max-h-[calc(70vh-80px)]",children:l.jsx("div",{className:"p-2",children:g.length>0?l.jsx("div",{className:"space-y-1",children:g.map((w,N)=>l.jsxs("div",{className:se("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",N===o?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>x(w),children:[l.jsx("div",{className:"flex-shrink-0 mt-1",children:l.jsx(Qn,{className:se("text-xs",T(w.message.role)),children:k(w.message.role)})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"text-sm font-medium",children:w.sessionId.length>20?`${w.sessionId.slice(0,20)}...`:w.sessionId}),l.jsx("span",{className:"text-xs text-muted-foreground",children:w.message.role})]}),l.jsx("div",{className:"text-sm text-muted-foreground line-clamp-2",children:S(w.context,s)})]}),l.jsx(X1,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},N))}):s?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),l.jsx("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),l.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Rr,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),l.jsx("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),l.jsxs("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"↑"}),l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"↓"}),l.jsx("span",{children:"to navigate"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"Enter"}),l.jsx("span",{children:"to select"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("kbd",{className:"px-2 py-1 bg-muted/50 rounded text-xs",children:"Esc"}),l.jsx("span",{children:"to close"})]})]})]})})})})]})})]}):null}function nae(e=!0){return Dn({queryKey:Ge.agent.config,queryFn:async()=>await os(Xe.api.agent.config.$get(),"Failed to load agent config"),enabled:e,staleTime:3e4})}function rae(){return nn({mutationFn:async({yaml:e})=>await os(Xe.api.agent.validate.$post({json:{yaml:e}}),"Failed to validate agent config")})}function iae(){const e=un();return nn({mutationFn:async({yaml:t})=>await os(Xe.api.agent.config.$post({json:{yaml:t}}),"Failed to save agent config"),onSuccess:()=>{e.invalidateQueries({queryKey:Ge.agent.config})}})}function sae(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ZP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function YP(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?ZP(Object(n),!0).forEach(function(r){sae(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ZP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function aae(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,s;for(s=0;s<r.length;s++)i=r[s],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function oae(e,t){if(e==null)return{};var n=aae(e,t),r,i;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(i=0;i<s.length;i++)r=s[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function lae(e,t){return uae(e)||cae(e,t)||pae(e,t)||dae()}function uae(e){if(Array.isArray(e))return e}function cae(e,t){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(e)))){var n=[],r=!0,i=!1,s=void 0;try{for(var o=e[Symbol.iterator](),c;!(r=(c=o.next()).done)&&(n.push(c.value),!(t&&n.length===t));r=!0);}catch(d){i=!0,s=d}finally{try{!r&&o.return!=null&&o.return()}finally{if(i)throw s}}return n}}function pae(e,t){if(e){if(typeof e=="string")return QP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return QP(e,t)}}function QP(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function dae(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1508
1508
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function mae(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function XP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function JP(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?XP(Object(n),!0).forEach(function(r){mae(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):XP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function fae(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(r){return t.reduceRight(function(i,s){return s(i)},r)}}function kd(e){return function t(){for(var n=this,r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];return i.length>=e.length?e.apply(this,i):function(){for(var o=arguments.length,c=new Array(o),d=0;d<o;d++)c[d]=arguments[d];return t.apply(n,[].concat(i,c))}}}function cg(e){return{}.toString.call(e).includes("Object")}function hae(e){return!Object.keys(e).length}function rm(e){return typeof e=="function"}function gae(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function yae(e,t){return cg(t)||Co("changeType"),Object.keys(t).some(function(n){return!gae(e,n)})&&Co("changeField"),t}function xae(e){rm(e)||Co("selectorType")}function vae(e){rm(e)||cg(e)||Co("handlerType"),cg(e)&&Object.values(e).some(function(t){return!rm(t)})&&Co("handlersType")}function bae(e){e||Co("initialIsRequired"),cg(e)||Co("initialType"),hae(e)&&Co("initialContent")}function Tae(e,t){throw new Error(e[t]||e.default)}var _ae={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},Co=kd(Tae)(_ae),uh={changes:yae,selector:xae,handler:vae,initial:bae};function kae(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};uh.initial(e),uh.handler(t);var n={current:e},r=kd(Mae)(n,t),i=kd(Sae)(n),s=kd(uh.changes)(e),o=kd(wae)(n);function c(){var m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(f){return f};return uh.selector(m),m(n.current)}function d(m){fae(r,i,s,o)(m)}return[c,d]}function wae(e,t){return rm(t)?t(e.current):t}function Sae(e,t){return e.current=JP(JP({},e.current),t),t}function Mae(e,t,n){return rm(t)?t(e.current):Object.keys(n).forEach(function(r){var i;return(i=t[r])===null||i===void 0?void 0:i.call(t,e.current[r])}),n}var Nae={create:kae},Pae={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs"}};function Cae(e){return function t(){for(var n=this,r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];return i.length>=e.length?e.apply(this,i):function(){for(var o=arguments.length,c=new Array(o),d=0;d<o;d++)c[d]=arguments[d];return t.apply(n,[].concat(i,c))}}}function Eae(e){return{}.toString.call(e).includes("Object")}function Dae(e){return e||eC("configIsRequired"),Eae(e)||eC("configType"),e.urls?(jae(),{paths:{vs:e.urls.monacoBase}}):e}function jae(){console.warn(TI.deprecation)}function Iae(e,t){throw new Error(e[t]||e.default)}var TI={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
1509
1509
  You are using deprecated way of configuration.
1510
1510