dexto 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/agents/coding-agent/coding-agent.yml +23 -15
  2. package/dist/agents/database-agent/database-agent.yml +15 -7
  3. package/dist/agents/default-agent.yml +23 -15
  4. package/dist/agents/github-agent/github-agent.yml +14 -6
  5. package/dist/agents/music-agent/music-agent.yml +15 -7
  6. package/dist/agents/nano-banana-agent/nano-banana-agent.yml +15 -7
  7. package/dist/agents/podcast-agent/podcast-agent.yml +15 -7
  8. package/dist/agents/product-name-researcher/product-name-researcher.yml +18 -8
  9. package/dist/agents/sora-video-agent/sora-video-agent.yml +15 -7
  10. package/dist/cli/commands/interactive-commands/prompt-commands.d.ts.map +1 -1
  11. package/dist/cli/commands/interactive-commands/prompt-commands.js +9 -37
  12. package/dist/webui/.next/standalone/.next/static/chunks/620-be2122f1db014716.js +1 -0
  13. package/dist/webui/.next/standalone/packages/webui/.next/BUILD_ID +1 -1
  14. package/dist/webui/.next/standalone/packages/webui/.next/app-build-manifest.json +2 -2
  15. package/dist/webui/.next/standalone/packages/webui/.next/build-manifest.json +2 -2
  16. package/dist/webui/.next/standalone/packages/webui/.next/prerender-manifest.json +3 -3
  17. package/dist/webui/.next/standalone/packages/webui/.next/required-server-files.json +1 -1
  18. package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  19. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page_client-reference-manifest.js +1 -1
  20. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page_client-reference-manifest.js +1 -1
  21. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page_client-reference-manifest.js +1 -1
  22. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/21.js +2 -2
  23. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/487.js +1 -1
  24. package/dist/webui/.next/standalone/packages/webui/.next/server/pages/500.html +1 -1
  25. package/dist/webui/.next/standalone/packages/webui/.next/server/server-reference-manifest.json +1 -1
  26. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/620-be2122f1db014716.js +1 -0
  27. package/dist/webui/.next/standalone/packages/webui/package.json +1 -1
  28. package/dist/webui/.next/standalone/packages/webui/server.js +1 -1
  29. package/dist/webui/.next/static/chunks/620-be2122f1db014716.js +1 -0
  30. package/dist/webui/package.json +1 -1
  31. package/package.json +5 -5
  32. package/dist/webui/.next/standalone/.next/static/chunks/620-849d0ea03f0e25d2.js +0 -1
  33. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/620-849d0ea03f0e25d2.js +0 -1
  34. package/dist/webui/.next/static/chunks/620-849d0ea03f0e25d2.js +0 -1
  35. /package/dist/webui/.next/standalone/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_buildManifest.js +0 -0
  36. /package/dist/webui/.next/standalone/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_ssgManifest.js +0 -0
  37. /package/dist/webui/.next/standalone/packages/webui/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_buildManifest.js +0 -0
  38. /package/dist/webui/.next/standalone/packages/webui/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_ssgManifest.js +0 -0
  39. /package/dist/webui/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_buildManifest.js +0 -0
  40. /package/dist/webui/.next/static/{EvtxRtNp0iL3eeD0UnMCl → I8HCRtl1KN0zLK8CwW1y3}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[620],{2620:(e,t,s)=>{Promise.resolve().then(s.bind(s,5613))},5613:(e,t,s)=>{"use strict";s.d(t,{default:()=>rf});var r,a=s(7136),n=s(3916),i=s(2265),l=s(2977),o=s(4779),d=s(23);function c(){let[e,t]=(0,n.useState)(()=>"undefined"!=typeof document?document.documentElement.classList.contains("dark")?"dark":"light":"dark");return(0,n.useEffect)(()=>{if("undefined"!=typeof document){document.documentElement.classList.toggle("dark","dark"===e);try{var t;localStorage.setItem("theme",e);let s=(null==(t=window.location)?void 0:t.protocol)==="https:";document.cookie="theme=".concat(encodeURIComponent(e),"; path=/; max-age=31536000; SameSite=Lax").concat(s?"; Secure":"")}catch(e){}}},[e]),{theme:e,toggleTheme:e=>{t(e?"dark":"light")},hasMounted:!0}}var m=s(350),u=s(1834),x=s(365),h=s(2852);function p(e){return(0,m.I)({queryKey:x.l.prompts.all,queryFn:async()=>{let e=await h.S.api.prompts.$get();return(await e.json()).prompts},staleTime:3e5,gcTime:18e5,...e})}function f(){return(0,u.n)({mutationFn:async e=>{let{name:t,...s}=e,r=await h.S.api.prompts[":name"].resolve.$get({param:{name:encodeURIComponent(t)},query:s});if(!r.ok)throw Error("Failed to resolve prompt: ".concat(r.status));return await r.json()}})}function g(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let{sessionId:t}=e;await h.S.api.sessions[":sessionId"].$delete({param:{sessionId:t}})},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.sessions.all})}})}var v=s(5080),j=s(4768),b=s(3862),y=s(3576),N=s(9391),w=s(7075),k=s(7102),C=s(9428),A=s(3336),S=s(4969),E=s(3982);function I(e){let{delayDuration:t=0,...s}=e;return(0,a.jsx)(E.Kq,{"data-slot":"tooltip-provider",delayDuration:t,...s})}function T(e){let{...t}=e;return(0,a.jsx)(I,{children:(0,a.jsx)(E.bL,{"data-slot":"tooltip",...t})})}function L(e){let{...t}=e;return(0,a.jsx)(E.l9,{"data-slot":"tooltip-trigger",...t})}function O(e){let{className:t,sideOffset:s=0,children:r,...n}=e;return(0,a.jsx)(E.ZL,{children:(0,a.jsxs)(E.UC,{"data-slot":"tooltip-content",sideOffset:s,className:(0,j.cn)("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",t),...n,children:[r,(0,a.jsx)(E.i3,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}var R=s(7603);let D=(0,n.forwardRef)((e,t)=>{let{children:s,tooltip:r,side:n="bottom",className:i,...l}=e;return(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)(R.$,{variant:"ghost",size:"icon",...l,className:(0,j.cn)("size-6 p-1",i),ref:t,children:[s,(0,a.jsx)("span",{className:"sr-only",children:r})]})}),(0,a.jsx)(O,{side:n,children:r})]})});function F(e){let{value:t,tooltip:s="Copy",copiedTooltip:r="Copied!",className:i,size:l=12}=e,[o,d]=(0,n.useState)(!1);return(0,a.jsx)(D,{tooltip:o?r:s,onClick:()=>{navigator.clipboard.writeText(t).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)}).catch(()=>{})},className:i,children:o?(0,a.jsx)(A.A,{size:l}):(0,a.jsx)(S.A,{size:l})})}D.displayName="TooltipIconButton";var _=s(1007),P=s(6765);class M{get supported(){return"speechSynthesis"in window&&"SpeechSynthesisUtterance"in window}isSpeaking(){return this._speaking}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}subscribeVoices(e){return this.voiceSubscribers.add(e),()=>{this.voiceSubscribers.delete(e)}}notify(){for(let e of this.subscribers)try{e()}catch(e){}}stop(){if(this.supported){try{window.speechSynthesis.cancel()}catch(e){}this.utterance=null,this._speaking&&(this._speaking=!1,this.notify())}}speak(e,t){if(!this.supported||!e||!e.trim())return;this.stop();let s=new window.SpeechSynthesisUtterance(e);(null==t?void 0:t.rate)!=null&&(s.rate=t.rate),(null==t?void 0:t.pitch)!=null&&(s.pitch=t.pitch);let r=this.resolveVoice();if(r)try{s.voice=r,(null==t?void 0:t.lang)?s.lang=t.lang:r.lang&&(s.lang=r.lang)}catch(e){}else(null==t?void 0:t.lang)&&(s.lang=t.lang);s.onstart=()=>{this.utterance===s&&(this._speaking=!0,this.notify())};let a=()=>{this.utterance===s&&(this._speaking=!1,this.utterance=null,this.notify())};s.onend=a,s.onerror=a;try{this.utterance=s,window.speechSynthesis.speak(s),this._speaking||(this._speaking=!0,this.notify())}catch(e){a()}}getVoices(){return this.voices}setPreferredVoice(e){this.preferredVoiceName=e&&e.length?e:null;try{this.preferredVoiceName?window.localStorage.setItem("ttsVoiceName",this.preferredVoiceName):window.localStorage.removeItem("ttsVoiceName")}catch(e){}this.voiceSubscribers.forEach(e=>e())}getPreferredVoiceName(){return this.preferredVoiceName}resolveVoice(){if(!this.voices.length)return null;let e=this.preferredVoiceName?this.voices.find(e=>e.name===this.preferredVoiceName):null;if(e)return e;let t=this.voices.find(e=>{var t;return"google uk english female"===e.name.toLowerCase()||e.name.toLowerCase().includes("google uk english female")&&(null==(t=e.lang)?void 0:t.toLowerCase().startsWith("en-gb"))});if(t)return t;let s=e=>{var t;let s=e.name.toLowerCase(),r=(null!=(t=e.lang)?t:"").toLowerCase(),a=0;return("en"===r||r.startsWith("en-"))&&(a+=3),s.includes("google")&&(a+=5),(s.includes("microsoft")||s.includes("azure"))&&(a+=4),(s.includes("natural")||s.includes("neural")||s.includes("premium"))&&(a+=4),s.includes("siri")&&(a+=3),s.includes("female")&&(a+=1),a};return[...this.voices].sort((e,t)=>s(t)-s(e))[0]||this.voices[0]||null}constructor(){if(this._speaking=!1,this.subscribers=new Set,this.utterance=null,this.voices=[],this.voiceSubscribers=new Set,this.preferredVoiceName=null,this.supported){try{let e=window.localStorage.getItem("ttsVoiceName");this.preferredVoiceName=e&&e.length?e:null}catch(e){}let e=()=>{try{let e=window.speechSynthesis.getVoices()||[];(e.length!==this.voices.length||e.some((e,t)=>{var s;return e.name!==(null==(s=this.voices[t])?void 0:s.name)}))&&(this.voices=e,this.voiceSubscribers.forEach(e=>e()))}catch(e){}};e();try{window.speechSynthesis.addEventListener("voiceschanged",e)}catch(e){}}}}let z=globalThis,U=null!=(r=z.__speechController)?r:z.__speechController=new M;function q(e){let{value:t,tooltip:s="Speak",stopTooltip:r="Stop",className:i,rate:l=1,pitch:o=1,lang:d}=e,[c,m]=(0,n.useState)(!1),u=U.supported,x=(null!=t?t:"").trim().length>0;return(0,n.useEffect)(()=>(m(U.isSpeaking()),U.subscribe(()=>m(U.isSpeaking()))),[]),(0,a.jsx)(D,{tooltip:c?r:s,onClick:()=>{if(u&&x){if(c)return U.stop();U.speak(t,{rate:l,pitch:o,lang:d})}},className:i,disabled:!u||!x,children:c?(0,a.jsx)(_.A,{size:12}):(0,a.jsx)(P.A,{size:12})})}function B(e){var t;let{error:s,onDismiss:r}=e,[i,l]=(0,n.useState)(!1),o=null==(t=s.detailedIssues)?void 0:t[0],d=(null==o?void 0:o.context)&&"object"==typeof o.context&&"detailedIssues"in o.context?o.context.detailedIssues:[],c=d.length>0?"".concat(s.message,"\n\nDetails:\n").concat(d.map(e=>{let t=e.message;if(e.context){let s="string"==typeof e.context?e.context:JSON.stringify(e.context,null,2);t+="\nContext: ".concat(s)}return t}).join("\n\n")):s.message;return(0,a.jsx)("div",{className:"w-full rounded-lg p-4 mb-4 border shadow-sm bg-destructive/10 border-destructive/40",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(N.A,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"text-sm font-medium text-destructive",children:"Error"}),s.context&&(0,a.jsx)("span",{className:"text-xs bg-destructive/15 text-destructive px-2 py-0.5 rounded-full",children:s.context})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[d.length>0&&(0,a.jsx)("button",{onClick:()=>l(!i),className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:i?"Collapse":"Expand",children:i?(0,a.jsx)(w.A,{className:"h-4 w-4"}):(0,a.jsx)(k.A,{className:"h-4 w-4"})}),(0,a.jsx)(F,{value:c,tooltip:"Copy error",className:"p-1 hover:bg-destructive/15 rounded text-destructive",size:16}),(0,a.jsx)(q,{value:c,tooltip:"Read error",className:"p-1 hover:bg-destructive/15 rounded text-destructive"}),(0,a.jsx)("button",{onClick:r,className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:"Dismiss",children:(0,a.jsx)(C.A,{className:"h-4 w-4"})})]})]}),(0,a.jsx)("div",{className:"mt-2 text-sm text-destructive",children:s.message}),i&&d.length>0&&(0,a.jsx)("div",{className:"mt-3",children:(0,a.jsx)("div",{className:"text-xs text-destructive bg-destructive/10 p-3 rounded border border-destructive/30 overflow-auto max-h-60",children:d.map((e,t)=>(0,a.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,a.jsx)("div",{className:"font-medium",children:e.message}),null!=e.context&&(0,a.jsx)("div",{className:"text-destructive/70 mt-1",children:"string"==typeof e.context?e.context:JSON.stringify(e.context,null,2)})]},t))})})]})]})})}var $=s(7179),W=s(1821),K=s(5501),V=s(6652),Y=s(4744),G=s(3458),Q=s(1982),H=s(9889),J=s(5268),Z=s(518),X=s(8633),ee=s(1405),et=s(2815),es=s(440),er=s(6988),ea=s(2139),en=s(6990);function ei(e,t){return RegExp("^data:".concat(t?"".concat(t,"/"):"[a-z0-9.+-]+/","[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$"),"i").test(e)}function el(e){try{let t=new URL(e),s=t.hostname.toLowerCase();if("https:"!==t.protocol&&"http:"!==t.protocol||"localhost"===s||"::1"===s)return!1;let r=s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(r){let[,e,t,s,a]=r.map(Number);if(e>255||t>255||s>255||a>255||127===e||10===e||172===e&&t>=16&&t<=31||192===e&&168===t||169===e&&254===t||0===e&&0===t&&0===s&&0===a)return!1}if(s.includes(":")&&("::1"===s||"0:0:0:0:0:0:0:1"===s||s.startsWith("fc")||s.startsWith("fd")||s.startsWith("fe8")||s.startsWith("fe9")||s.startsWith("fea")||s.startsWith("feb")))return!1;return!0}catch(e){return!1}}function eo(e,t){return!!(e.startsWith("blob:")||el(e))||!!e.startsWith("data:")&&(t?ei(e,t):ei(e))}let ed=e=>{let{className:t,children:s,...r}=e,[i,l]=(0,n.useState)(!1),o=String(null!=s?s:"").replace(/\n$/,"");return t?(0,a.jsxs)("div",{className:"relative group my-4 min-w-0 max-w-full",children:[(0,a.jsx)(D,{tooltip:i?"Copied!":"Copy code",onClick:()=>{navigator.clipboard.writeText(o).then(()=>{l(!0),setTimeout(()=>l(!1),2e3)}).catch(()=>{})},className:"absolute right-2 top-2 z-10 opacity-70 hover:opacity-100 transition-opacity bg-background/80 hover:bg-background",children:i?(0,a.jsx)(A.A,{size:14}):(0,a.jsx)(S.A,{size:14})}),(0,a.jsx)("pre",{className:"overflow-auto bg-muted p-3 rounded-lg text-sm max-w-full",children:(0,a.jsx)("code",{className:t,children:o})})]}):(0,a.jsx)("code",{className:"text-xs px-1.5 py-0.5 bg-muted rounded font-mono break-all overflow-wrap-anywhere",...r,children:s})},ec=(0,n.memo)(e=>{let{children:t}=e,s=n.useRef(new Set);return n.useEffect(()=>{let e=s.current;return()=>{e.forEach(e=>{try{URL.revokeObjectURL(e)}catch(e){}})}},[]),(0,a.jsx)("div",{className:"prose max-w-none dark:prose-invert min-w-0 overflow-hidden break-words overflow-wrap-anywhere [&>p]:my-5 [&>p]:leading-7 [&>p]:first:mt-0 [&>p]:last:mb-0 [&>p]:break-words [&>p]:overflow-wrap-anywhere [&>h1]:mb-8 [&>h1]:text-4xl [&>h1]:font-extrabold [&>h1]:tracking-tight [&>h1]:last:mb-0 [&>h1]:break-words [&>h2]:mb-4 [&>h2]:mt-8 [&>h2]:text-3xl [&>h2]:font-semibold [&>h2]:tracking-tight [&>h2]:first:mt-0 [&>h2]:last:mb-0 [&>h2]:break-words [&>h3]:mb-4 [&>h3]:mt-6 [&>h3]:text-2xl [&>h3]:font-semibold [&>h3]:tracking-tight [&>h3]:first:mt-0 [&>h3]:last:mb-0 [&>h3]:break-words [&>h4]:mb-4 [&>h4]:mt-6 [&>h4]:text-xl [&>h4]:font-semibold [&>h4]:tracking-tight [&>h4]:first:mt-0 [&>h4]:last:mb-0 [&>h4]:break-words [&>ul]:my-5 [&>ul]:ml-6 [&>ul]:list-disc [&>ul>li]:mt-2 [&>ol]:my-5 [&>ol]:ml-6 [&>ol]:list-decimal [&>ol>li]:mt-2 [&_ul]:my-5 [&_ul]:ml-6 [&_ul]:list-disc [&_ul>li]:mt-2 [&_ol]:my-5 [&_ol]:ml-6 [&_ol]:list-decimal [&_ol>li]:mt-2 [&>blockquote]:border-l-2 [&>blockquote]:pl-6 [&>blockquote]:italic [&>blockquote]:break-words [&>hr]:my-5 [&>hr]:border-b",children:(0,a.jsx)(er.oz,{remarkPlugins:[ea.A,en.A],skipHtml:!0,components:{a:e=>{let{href:t,children:s,...r}=e,n=null!=t?t:"";return/^https?:\/\//i.test(n)&&el(n)?(0,a.jsx)("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 underline-offset-2 hover:underline hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 font-medium break-all overflow-wrap-anywhere max-w-full inline",title:n,style:{wordBreak:"break-word",overflowWrap:"anywhere"},...r,children:s}):(0,a.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",...r,children:s})},img:e=>{let{src:t,alt:r,...n}=e;if(!t)return(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"No media source provided"});let i=null;if("string"==typeof t)i=t;else if(t instanceof Blob||t instanceof File)try{let e=URL.createObjectURL(t);i=e,s.current.add(e)}catch(e){i=null}else if("object"==typeof t&&null!==t&&t instanceof MediaSource)try{let e=URL.createObjectURL(t);i=e,s.current.add(e)}catch(e){i=null}else i=null;return i?function(e){return!!(e.match(/\.(mp4|webm|mov|m4v|avi|mkv)(\?.*)?$/i)||e.includes("/video/")||e.includes("video_"))}(i)&&eo(i,"video")?(0,a.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,a.jsx)("video",{controls:!0,src:i,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."}),r&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:r})]}):function(e){return!!(e.match(/\.(mp3|wav|ogg|m4a|aac|flac|wma)(\?.*)?$/i)||e.includes("/audio/")||e.includes("audio_"))}(i)&&eo(i,"audio")?(0,a.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,a.jsx)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-muted/30",children:(0,a.jsx)("audio",{controls:!0,src:i,className:"flex-1 min-w-0 h-10",children:"Your browser does not support the audio tag."})}),r&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:r})]}):eo(i,"image")?(0,a.jsx)("img",{src:i,alt:r||"Image",className:"max-w-full max-h-[500px] object-contain rounded-lg border border-border my-4",loading:"lazy",...n}):(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"}):(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"})},p:e=>{let{children:t,...s}=e;return"string"==typeof t?(0,a.jsx)("p",{...s,children:function(e){let t=/(https?:\/\/[^\s<]+)/g;return e.split(t).map((e,s)=>e.match(t)?el(e)?(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 underline-offset-2 hover:underline hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 font-medium break-all overflow-wrap-anywhere max-w-full inline",title:e,style:{wordBreak:"break-word",overflowWrap:"anywhere"},children:e},s):(0,a.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",title:"Unsafe URL",children:e},s):e)}(t)}):(0,a.jsx)("p",{...s,children:t})},table:e=>{let{className:t,children:s,...r}=e;return(0,a.jsx)("div",{className:"my-4 overflow-x-auto -mx-1 px-1",children:(0,a.jsx)("table",{className:["w-full border-separate border-spacing-0",t].filter(Boolean).join(" "),...r,children:s})})},thead:e=>{let{className:t,...s}=e;return(0,a.jsx)("thead",{className:t,...s})},tr:e=>{let{className:t,...s}=e;return(0,a.jsx)("tr",{className:["m-0 border-b first:border-t","[&:last-child>td:first-child]:rounded-bl-lg [&:last-child>td:last-child]:rounded-br-lg",t].filter(Boolean).join(" "),...s})},th:e=>{let{className:t,...s}=e;return(0,a.jsx)("th",{className:["bg-muted text-left font-bold align-top","px-4 py-2 first:rounded-tl-lg last:rounded-tr-lg","[&[align=center]]:text-center [&[align=right]]:text-right",t].filter(Boolean).join(" "),...s})},td:e=>{let{className:t,...s}=e;return(0,a.jsx)("td",{className:["border-b border-l last:border-r text-left align-top","px-4 py-2 whitespace-normal break-words","[&[align=center]]:text-center [&[align=right]]:text-right",t].filter(Boolean).join(" "),...s})},code:ed},children:t})})});var em=s(3816);async function eu(e){let t=await h.S.api.resources[":resourceId"].content.$get({param:{resourceId:encodeURIComponent(e)}}),s=await t.json(),r=null==s?void 0:s.content;if(!r)throw Error("No content returned for resource");return function(e,t){var s,r;let a=Array.isArray(null==t?void 0:t.contents)?t.contents:[],n=null!=(s=null==t?void 0:t._meta)?s:{},i=("string"==typeof n.originalName&&n.originalName.trim().length>0?n.originalName:void 0)||e,l=[];for(let e of a){if(!e||"object"!=typeof e)continue;if("string"==typeof e.text){l.push({kind:"text",text:e.text,mimeType:"string"==typeof e.mimeType?e.mimeType:void 0});continue}let t="string"==typeof e.blob?e.blob:void 0,s="string"==typeof e.data?e.data:void 0,a="string"==typeof e.mimeType?e.mimeType:void 0,n="string"==typeof e.filename?e.filename:void 0;if((t||s)&&a){let e=(r=null!=t?t:s,"data:".concat(a,";base64,").concat(r));a.startsWith("image/")?l.push({kind:"image",src:e,mimeType:a,alt:n||i}):a.startsWith("audio/")?l.push({kind:"audio",src:e,mimeType:a,filename:n||i}):a.startsWith("video/")?l.push({kind:"video",src:e,mimeType:a,filename:n||i}):l.push({kind:"file",src:e,mimeType:a,filename:n||i});continue}a&&a.startsWith("text/")&&"string"==typeof e.value&&l.push({kind:"text",text:e.value,mimeType:a})}return{uri:e,name:i,meta:n,items:l}}(e,r)}function ex(e){let t=e.join("|"),s=(0,n.useMemo)(()=>{let t=new Set,s=[];for(let r of e){if(!r||"string"!=typeof r)continue;let e=r.trim();!e||t.has(e)||(t.add(e),s.push(e))}return s},[t]),r=(0,em.E)({queries:s.map(e=>({queryKey:["resourceContent",e],queryFn:()=>eu(e),enabled:!!e,retry:!1}))});return(0,n.useMemo)(()=>{let e={};return r.forEach((t,r)=>{let a=s[r];a&&(t.isLoading?e[a]={status:"loading"}:t.error?e[a]={status:"error",error:t.error instanceof Error?t.error.message:String(t.error)}:t.data&&(e[a]={status:"loaded",data:t.data}))}),e},[r,s])}async function eh(){let e=await h.S.api.resources.$get(),t=await e.json();if(!t.ok||!Array.isArray(t.resources))throw Error("Invalid response shape");return t.resources}function ep(){var e;let t=(0,l.jE)(),{data:s=[],isLoading:r,error:a,refetch:i}=(0,m.I)({queryKey:x.l.resources.all,queryFn:eh});return(0,n.useEffect)(()=>{let e=e=>{console.log("\uD83D\uDCBE Resource cache invalidated:",(null==e?void 0:e.detail)||{}),t.invalidateQueries({queryKey:x.l.resources.all})},s=e=>{console.log("\uD83D\uDD01 Agent switched, refreshing resources:",(null==e?void 0:e.detail)||{}),t.invalidateQueries({queryKey:x.l.resources.all})};return window.addEventListener("resource:cache-invalidated",e),window.addEventListener("dexto:agentSwitched",s),()=>{window.removeEventListener("resource:cache-invalidated",e),window.removeEventListener("dexto:agentSwitched",s)}},[t]),{resources:s,loading:r,error:null!=(e=null==a?void 0:a.message)?e:null,refresh:async()=>{await i()}}}var ef=s(5676);function eg(e){if(!e.metadata||"object"!=typeof e.metadata)return null;let t=e.metadata;return t.schema&&t.prompt&&t.serverName?t:null}function ev(e){let{approval:t,onApprove:s,onDeny:r}=e,[i,l]=(0,n.useState)({}),[o,d]=(0,n.useState)({}),[c,m]=(0,n.useState)(!1),u="elicitation"===t.type,x="command_confirmation"===t.type,h=(e,t)=>{l(s=>({...s,[e]:t})),o[e]&&d(t=>{let s={...t};return delete s[e],s})};return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,a.jsx)(N.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:u?"Information Request":"Approval Required"})]}),x?(0,a.jsxs)("div",{className:"space-y-3 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(K.A,{className:"h-4 w-4 flex-shrink-0"}),(0,a.jsxs)("span",{className:"font-medium text-sm break-words min-w-0",children:["Tool: ",t.toolName]})]}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"font-medium text-sm block mb-2",children:"Command:"}),(0,a.jsx)("pre",{className:"bg-muted/50 p-3 rounded-md text-xs overflow-auto max-h-40 border border-border break-words whitespace-pre-wrap max-w-full text-red-600 dark:text-red-400",children:t.command})]}),t.originalCommand&&t.originalCommand!==t.command&&(0,a.jsx)("div",{className:"min-w-0",children:(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Original: ",t.originalCommand]})}),(0,a.jsx)("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 p-3 rounded-md border border-yellow-200 dark:border-yellow-800",children:(0,a.jsx)("p",{className:"text-xs text-yellow-800 dark:text-yellow-200",children:"⚠️ This command requires approval because it may modify your system."})})]}):u?(()=>{let e=eg(t);return e?(0,a.jsxs)("div",{className:"space-y-4 min-w-0",children:[(0,a.jsxs)("div",{className:"bg-muted/50 p-3 rounded-md border border-border min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium mb-1 break-words",children:e.prompt}),(0,a.jsxs)("p",{className:"text-xs text-muted-foreground break-words",children:["From: ",e.serverName||"Dexto Agent"]})]}),(0,a.jsx)("div",{children:(()=>{let t=e.schema;if(!(null==t?void 0:t.properties)||"object"!=typeof t.properties)return(0,a.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid form schema"});let s=t.required||[],r=t.properties;return(0,a.jsx)("div",{className:"space-y-4",children:Object.entries(r).map(e=>{var t;let[r,n]=e,l=s.includes(r),d=n.type||"string",c=i[r],m=!!o[r];return"boolean"===d?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(ef.S,{id:r,checked:!0===c,onCheckedChange:e=>h(r,!0===e)}),(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground ml-6",children:n.description})]},r):"number"===d||"integer"===d?(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsx)("input",{id:r,type:"number",step:"integer"===d?"1":"any",value:"number"==typeof c?c:"",onChange:e=>{let t=e.target.value;h(r,""===t?void 0:Number(t))},className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),placeholder:l?"Required":"Optional"}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r):n.enum&&Array.isArray(n.enum)?(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsxs)("select",{id:r,value:null!=c?String(c):"",onChange:e=>{var t;let s=e.target.value;if(""===s)return void h(r,void 0);let a=null==(t=n.enum)?void 0:t.find(e=>String(e)===s);h(r,null!=a?a:s)},className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),children:[(0,a.jsx)("option",{value:"",children:"Select an option..."}),null==(t=n.enum)?void 0:t.map(e=>(0,a.jsx)("option",{value:String(e),children:String(e)},String(e)))]}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r):(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsx)("input",{id:r,type:"text",value:null!=c&&"object"!=typeof c?String(c):"",onChange:e=>h(r,e.target.value),className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),placeholder:l?"Required":"Optional"}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r)})})})()})]}):(0,a.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid elicitation metadata"})})():"tool_confirmation"===t.type?(0,a.jsxs)("div",{className:"space-y-3 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(K.A,{className:"h-4 w-4 flex-shrink-0"}),(0,a.jsxs)("span",{className:"font-medium text-sm break-words min-w-0",children:["Tool: ",t.toolName]})]}),t.description&&(0,a.jsx)("p",{className:"text-sm break-words",children:t.description}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"font-medium text-sm block mb-2",children:"Arguments:"}),(0,a.jsx)("pre",{className:"bg-muted/50 p-3 rounded-md text-xs overflow-auto max-h-40 border border-border break-words whitespace-pre-wrap max-w-full",children:JSON.stringify(t.args,null,2)})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2 pt-2",children:[(0,a.jsx)(ef.S,{id:"remember",checked:c,onCheckedChange:e=>m(!0===e)}),(0,a.jsx)("label",{htmlFor:"remember",className:"text-sm",children:"Remember this choice for this session"})]})]}):null,(0,a.jsxs)("div",{className:"flex gap-2 justify-end pt-3 border-t border-border",children:[(0,a.jsx)(R.$,{variant:"outline",onClick:r,size:"sm",children:u?"Decline":"Deny"}),(0,a.jsx)(R.$,{onClick:()=>{if(u){let e=eg(t);if(!e)return void console.error("Invalid elicitation metadata");let r=e.schema.required||[],a={};for(let e of r){let t=i[e],s="string"==typeof t&&""===t.trim();(null==t||s)&&(a[e]="This field is required")}if(Object.keys(a).length>0)return void d(a);s(i)}else s(void 0,c)},size:"sm",children:u?"Submit":"Approve"})]})]})}function ej(e,t){return RegExp("^data:".concat(t?"".concat(t,"/"):"[a-z0-9.+-]+/","[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$"),"i").test(e)}function eb(e,t){return!!(e.startsWith("blob:")||function(e){try{let t=new URL(e),s=t.hostname.toLowerCase();if("https:"!==t.protocol&&"http:"!==t.protocol||"localhost"===s||"::1"===s)return!1;let r=s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(r){let[,e,t,s,a]=r.map(Number);if(e>255||t>255||s>255||a>255||127===e||10===e||172===e&&t>=16&&t<=31||192===e&&168===t||169===e&&254===t||0===e&&0===t&&0===s&&0===a)return!1}if(s.includes(":")&&("::1"===s||"0:0:0:0:0:0:0:1"===s||s.startsWith("fc")||s.startsWith("fd")||s.startsWith("fe8")||s.startsWith("fe9")||s.startsWith("fea")||s.startsWith("feb")))return!1;return!0}catch(e){return!1}}(e))||!!e.startsWith("data:")&&(t?ej(e,t):ej(e))}function ey(e,t){var s,r,a,n,i,l,o,d,c,m,u,x,h,p,f,g,v;if(!e)return"";let j=null==e?void 0:e.mimeType,b="string"==typeof e?e:null!=(l=null!=(i=null!=(n=null!=(a=null!=(r=null!=(s=null==e?void 0:e.data)?s:null==e?void 0:e.base64)?r:null==e?void 0:e.image)?a:null==e?void 0:e.audio)?n:null==e?void 0:e.video)?i:null==e?void 0:e.uri)?l:null==e?void 0:e.url;if("string"==typeof b){if(b.startsWith("@blob:")){let s=b.substring(1);if(t&&s){let r=t[s];if(r&&"loaded"===r.status&&r.data){let t=[];if((null==e?void 0:e.type)==="image"&&t.push("image"),(null==e?void 0:e.type)==="file"){let s=(0,y.t)(e.mimeType);"audio"===s?t.push("audio"):"video"===s&&t.push("video")}(null==e||null==(o=e.mimeType)?void 0:o.startsWith("image/"))&&t.push("image"),(null==e||null==(d=e.mimeType)?void 0:d.startsWith("audio/"))&&t.push("audio"),(null==e||null==(c=e.mimeType)?void 0:c.startsWith("video/"))&&t.push("video");let s=null!=(h=null!=(x=null!=(u=null!=(m=r.data.items.find(e=>t.includes(e.kind)))?m:r.data.items.find(e=>"image"===e.kind))?u:r.data.items.find(e=>"video"===e.kind))?x:r.data.items.find(e=>"audio"===e.kind))?h:r.data.items[0];if(s&&"src"in s&&"string"==typeof s.src)return s.src}}return""}if(b.startsWith("data:"))return b;if(j&&!(!b||b.length<16||b.startsWith("http://")||b.startsWith("https://")||b.startsWith("data:")||b.startsWith("@blob:"))&&/^[A-Za-z0-9+/=\r\n]+$/.test(b))return"data:".concat(j,";base64,").concat(b);if(eb(b))return b}let N=null!=(v=null!=(g=null!=(f=null!=(p=null==e?void 0:e.url)?p:null==e?void 0:e.image)?f:null==e?void 0:e.audio)?g:null==e?void 0:e.video)?v:null==e?void 0:e.uri;return"string"==typeof N?N:""}function eN(e,t){if(!e||"object"!=typeof e)return null;let s=e.mimeType||e.mediaType,r=e.filename||e.name,a="file"===e.type?(0,y.t)(e.mimeType):null;if(!((null==s?void 0:s.startsWith("video/"))||"video"===a||"video"===e.type||(null==r?void 0:r.match(/\.(mp4|webm|mov|m4v|avi|mkv)$/i))))return null;let n=ey(e,t);return n&&eb(n,"video")?{src:n,filename:r,mimeType:s}:null}function ew(){return(0,a.jsx)("div",{className:"flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground",role:"status","aria-live":"polite",children:(0,a.jsxs)("span",{className:"flex items-center gap-1 uppercase tracking-wide text-muted-foreground/80",children:[(0,a.jsx)("span",{children:"Thinking"}),(0,a.jsx)("span",{className:"flex items-center gap-0.5",children:[0,1,2].map(e=>(0,a.jsx)("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-primary/60 animate-[pulse_1.2s_ease-in-out_infinite]",style:{animationDelay:"".concat(.18*e,"s")}},e))})]})})}function ek(e){let{messages:t,processing:s=!1,activeError:r,onDismissError:i,outerRef:l,pendingApproval:o,onApprovalApprove:d,onApprovalDeny:c}=e,m=(0,n.useRef)(null),[u,x]=(0,n.useState)({}),[h,p]=(0,n.useState)({}),[f,g]=(0,n.useState)(null);(0,n.useRef)(null);let[v,A]=(0,n.useState)({isOpen:!1,src:"",alt:""}),{resources:S}=ep(),E=(0,n.useMemo)(()=>{let e={};for(let t of S)e[t.uri]={...t};return e},[S]),I=ex((0,n.useMemo)(()=>{let e=new Set,s=t=>{if("string"!=typeof t)return;let s=t.startsWith("@")?t.substring(1):t;s.startsWith("blob:")&&e.add(s)},r=e=>{if(e){if("string"==typeof e)return void s(e);"object"==typeof e&&("string"==typeof e.image&&s(e.image),"string"==typeof e.data&&s(e.data),"string"==typeof e.url&&s(e.url),"string"==typeof e.audio&&s(e.audio),"string"==typeof e.video&&s(e.video))}};for(let s of t){let t=s.toolResult;if(t)if((0,b.P2)(t)){var a,n;null==(a=t.resources)||a.forEach(t=>{var s;(null==t||null==(s=t.uri)?void 0:s.startsWith("blob:"))&&e.add(t.uri)}),null==(n=t.content)||n.forEach(e=>r(e))}else(null==t?void 0:t.content)&&Array.isArray(t.content)&&t.content.forEach(e=>r(e))}return Array.from(e)},[t]));(0,n.useEffect)(()=>{let e=document.createElement("style");return e.textContent="\n .audio-controls-container audio {\n max-width: 100% !important;\n width: 100% !important;\n height: auto !important;\n min-height: 32px;\n }\n .audio-controls-container audio::-webkit-media-controls-panel {\n max-width: 100% !important;\n }\n .audio-controls-container audio::-webkit-media-controls-timeline {\n max-width: 100% !important;\n }\n ",document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let R=(e,t)=>{A({isOpen:!0,src:e,alt:t})};if(!t||0===t.length)return null;let D=e=>"string"==typeof e.content?e.content:Array.isArray(e.content)?e.content.map(e=>(0,b.PI)(e)?e.text:"").filter(Boolean).join("\n"):e.content&&"object"==typeof e.content?JSON.stringify(e.content,null,2):"",_=e=>e?(0,b.KU)(e)?"object"==typeof e.error?JSON.stringify(e.error,null,2):String(e.error):(0,b.P2)(e)?e.content.map(e=>(0,b.PI)(e)?e.text:"object"==typeof e?"":String(e)).filter(Boolean).join("\n"):"object"==typeof e?JSON.stringify(e,null,2):String(e):"";return(0,a.jsxs)("div",{id:"message-list-container",ref:l,className:"flex flex-col space-y-3 px-3 sm:px-4 py-2 min-w-0 w-full",children:[t.map((e,l)=>{var o,d,c,m;let f=null!=(d=e.id)?d:"msg-".concat(l),g="user"===e.role,v="assistant"===e.role,C="system"===e.role,A=l===t.length-1,S=!!(e.toolName&&e.toolArgs),M=!!(e.toolName&&e.toolResult),z=S||M,U=z&&A||!!u[f],es=[],er=[],ea=[];M&&e.toolResult&&(0,b.P2)(e.toolResult)&&e.toolResult.content.forEach((e,t)=>{var s;if((0,b.j0)(e)){let s=ey(e,I);s&&eb(s,"image")&&es.push({src:s,alt:"Tool result image ".concat(t+1),index:t})}else if((0,b.kz)(e)){let s=ey(e,I);s&&eb(s,"audio")&&er.push({src:s,filename:e.filename,index:t})}else if((0,b.EQ)(e)&&("audio"===(0,y.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))){let s=ey(e,I);s&&eb(s,"audio")&&er.push({src:s,filename:e.filename,index:t})}else{let s=eN(e,I);s&&ea.push({...s,index:t})}});let en=g?$.A:W.A,ei=(0,j.cn)(g?"grid w-full grid-cols-[1fr_auto] gap-x-2 items-start":"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start"),el=(0,j.cn)("tool"===e.role?"w-fit max-w-[90%] text-muted-foreground/70 bg-secondary border border-muted/30 rounded-md text-base overflow-hidden":g?"p-3 rounded-xl shadow-sm w-fit max-w-[75%] bg-primary text-primary-foreground rounded-br-none text-base break-words overflow-wrap-anywhere overflow-hidden":v?"p-3 rounded-xl shadow-sm w-fit max-w-[min(90%,calc(100vw-6rem))] bg-card text-card-foreground border border-border rounded-bl-none text-base break-normal hyphens-none":C?"p-3 shadow-none w-full bg-transparent text-xs text-muted-foreground italic text-center border-none":""),eo=new Date(e.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),ed=!!(r&&r.anchorMessageId===e.id),ec=g&&A;return(0,a.jsxs)(n.Fragment,{children:[(0,a.jsxs)("div",{className:"w-full","data-role":e.role,id:e.id?"message-".concat(e.id):void 0,children:[(0,a.jsxs)("div",{className:ei,children:[v&&(0,a.jsx)(en,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1"}),"tool"===e.role&&(0,a.jsx)(K.A,{className:"h-7 w-7 p-1 mt-1 rounded-full border border-border text-muted-foreground col-start-1"}),(0,a.jsxs)("div",{className:(0,j.cn)("flex flex-col group w-full min-w-0",C?"col-span-2 items-center":g?"col-start-1 justify-self-end items-end":"col-start-2 justify-self-start items-start"),children:[(0,a.jsx)("div",{className:(0,j.cn)(el,"min-w-0"),children:(0,a.jsxs)("div",{className:(0,j.cn)("flex flex-col gap-2","min-w-0"),children:[v&&"string"==typeof e.reasoning&&e.reasoning.trim().length>0&&(0,a.jsxs)("div",{className:"mb-3 border border-orange-200/50 dark:border-orange-400/20 rounded-lg bg-gradient-to-br from-orange-50/30 to-amber-50/20 dark:from-orange-900/20 dark:to-amber-900/10",children:[(0,a.jsxs)("div",{className:"px-3 py-2 border-b border-orange-200/30 dark:border-orange-400/20 bg-orange-100/50 dark:bg-orange-900/30 rounded-t-lg flex items-center justify-between",children:[(0,a.jsxs)("button",{type:"button",className:"flex items-center gap-2 text-xs font-medium text-orange-700 dark:text-orange-300 hover:text-orange-800 dark:hover:text-orange-200 transition-colors group",onClick:()=>p(e=>{var t;return{...e,[f]:!(null==(t=e[f])||t)}}),children:[(0,a.jsx)(V.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"AI Reasoning"}),null==(c=h[f])||c?(0,a.jsx)(w.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"}):(0,a.jsx)(k.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(F,{value:e.reasoning,tooltip:"Copy reasoning",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(q,{value:e.reasoning,tooltip:"Speak reasoning",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(null==(m=h[f])||m)&&(0,a.jsx)("div",{className:"px-3 py-2",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words text-xs text-orange-800/80 dark:text-orange-200/70 leading-relaxed font-mono",children:e.reasoning})})]}),e.toolName?(0,a.jsxs)("div",{className:"p-2 rounded border border-border bg-muted/30 hover:bg-muted/60 cursor-pointer",onClick:()=>{z&&x(e=>({...e,[f]:!e[f]}))},children:[(0,a.jsxs)("div",{className:"flex items-center justify-between text-xs font-medium",children:[(0,a.jsxs)("span",{className:"flex items-center",children:[U?(0,a.jsx)(w.A,{className:"h-4 w-4 mr-2 text-primary"}):(0,a.jsx)(Y.A,{className:"h-4 w-4 mr-2 text-primary"}),"Tool: ",e.toolName]}),e.toolResult?(0,b.KU)(e.toolResult)||!1===e.toolResultSuccess?(0,a.jsx)(N.A,{className:"mx-2 h-4 w-4 text-red-500"}):(0,a.jsx)(G.A,{className:"mx-2 h-4 w-4 text-green-500"}):(0,a.jsx)(Q.A,{className:"mx-2 h-4 w-4 animate-spin text-muted-foreground"})]}),U&&(0,a.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-medium",children:"Arguments:"}),(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:JSON.stringify(e.toolArgs,null,2)})]}),e.toolResult&&(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"text-xs font-medium flex items-center justify-between",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("span",{children:"Result:"}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(F,{value:_(e.toolResult),tooltip:"Copy result",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(q,{value:_(e.toolResult),tooltip:"Speak result",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(0,b.KU)(e.toolResult)?(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-red-100 text-red-700 p-2 rounded text-xs",children:"object"==typeof e.toolResult.error?JSON.stringify(e.toolResult.error,null,2):String(e.toolResult.error)}):(0,b.P2)(e.toolResult)?e.toolResult.content.map((e,t)=>{var s,r,n;let i=eN(e,I);if((0,b.j0)(e)||(0,b.kz)(e)||(0,b.EQ)(e)&&("audio"===(0,y.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))||i)return null;if((0,b.PI)(e))return(0,a.jsx)(eC,{text:e.text,isUser:!1,onOpenImage:R,resourceSet:E},"".concat(f,"-tool-text-").concat(t));if((0,b.EQ)(e)){let s=(0,y.t)(e.mimeType),i="audio"===s||(null==(r=e.mimeType)?void 0:r.startsWith("audio/")),l="video"===s||(null==(n=e.mimeType)?void 0:n.startsWith("video/"));return(0,a.jsxs)("div",{className:"my-1 flex items-center gap-2 p-2 rounded border border-border bg-muted/50",children:[i?(0,a.jsx)(H.A,{className:"h-4 w-4 text-muted-foreground"}):l?(0,a.jsx)(J.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(Z.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:[e.filename||"File attachment"," ","(",e.mimeType,")"]})]},t)}return(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground my-1",children:"object"==typeof e?JSON.stringify(e,null,2):String(e)},t)}):(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:"string"==typeof e.toolResult&&e.toolResult.startsWith("data:image")?ej(e.toolResult,"image")?(0,a.jsx)("img",{src:e.toolResult,alt:"Tool result image",className:"my-1 max-h-48 w-auto rounded border border-border"}):"Invalid image data":"object"==typeof e.toolResult?JSON.stringify(e.toolResult,null,2):String(e.toolResult)})]})]})]}):(0,a.jsxs)(a.Fragment,{children:["string"==typeof e.content&&""!==e.content.trim()&&(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(eC,{text:e.content,isUser:g,onOpenImage:R,resourceSet:E},"".concat(f,"-text-content"))}),e.content&&"object"==typeof e.content&&!Array.isArray(e.content)&&(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:JSON.stringify(e.content,null,2)}),Array.isArray(e.content)&&e.content.map((e,t)=>{let s="".concat(f,"-part-").concat(t);if("text"===e.type)return(0,a.jsx)(eC,{text:e.text,isUser:g,onOpenImage:R,resourceSet:E},s);if((0,b.j0)(e)){let t=ey(e);return t&&eb(t,"image")?(0,a.jsx)("img",{src:t,alt:"Message attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain cursor-pointer",onClick:()=>R(t,"Message attachment")},s):null}let r=eN(e);if(r){let{src:e,filename:t,mimeType:n}=r;return(0,a.jsxs)("div",{className:"my-2 flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(J.A,{className:(0,j.cn)("h-4 w-4",g?void 0:"text-muted-foreground")}),(0,a.jsx)("span",{children:"Video attachment"})]}),(0,a.jsx)("div",{className:"w-full max-w-md",children:(0,a.jsx)("video",{controls:!0,src:e,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"})}),(t||n)&&(0,a.jsxs)("div",{className:"flex flex-col text-xs",children:[t&&(0,a.jsx)("span",{className:(0,j.cn)("truncate",g?"text-primary-foreground/80":"text-muted-foreground"),children:t}),n&&(0,a.jsx)("span",{className:(0,j.cn)(g?"text-primary-foreground/70":"text-muted-foreground/80"),children:n})]})]},s)}if((0,b.EQ)(e)){if(!e.mimeType.startsWith("audio/"))return(0,a.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(Z.A,{className:(0,j.cn)("h-5 w-5",g?void 0:"text-muted-foreground")}),(0,a.jsx)("span",{className:(0,j.cn)("text-sm font-medium",void 0),children:e.filename||"".concat(e.mimeType," file")}),(0,a.jsx)("span",{className:(0,j.cn)("text-xs",g?"text-primary-foreground/70":"text-muted-foreground"),children:e.mimeType})]},s);{let t=ey(e);return(0,a.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(H.A,{className:(0,j.cn)("h-5 w-5",g?void 0:"text-muted-foreground")}),(0,a.jsx)("audio",{controls:!0,src:t,className:"flex-1 h-8"}),e.filename&&(0,a.jsx)("span",{className:(0,j.cn)("text-sm truncate max-w-[120px]",g?"text-primary-foreground/80":"text-muted-foreground"),children:e.filename})]},s)}}return null}),C&&!e.content&&(0,a.jsx)("p",{className:"italic",children:"System message"})]}),e.imageData&&!Array.isArray(e.content)&&(()=>{let t="data:".concat(e.imageData.mimeType,";base64,").concat(e.imageData.base64);return ej(t,"image")?(0,a.jsx)("img",{src:t,alt:"attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain"}):null})(),e.fileData&&!Array.isArray(e.content)&&(0,a.jsx)("div",{className:"mt-2",children:e.fileData.mimeType.startsWith("video/")?(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50 max-w-md",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(J.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Video attachment"})]}),(()=>{let t="data:".concat(e.fileData.mimeType,";base64,").concat(e.fileData.base64);return ej(t,"video")?(0,a.jsx)("video",{controls:!0,src:t,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}):(0,a.jsx)("div",{className:"text-xs text-red-500",children:"Invalid video data"})})(),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/90",children:[(0,a.jsx)("span",{className:"font-medium truncate",children:e.fileData.filename||"".concat(e.fileData.mimeType," file")}),(0,a.jsx)("span",{className:"opacity-70",children:e.fileData.mimeType})]})]}):e.fileData.mimeType.startsWith("audio/")?(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[(0,a.jsx)(H.A,{className:"h-4 w-4"}),(()=>{let t="data:".concat(e.fileData.mimeType,";base64,").concat(e.fileData.base64);return ej(t,"audio")?(0,a.jsx)("audio",{controls:!0,src:t,className:"h-8"}):(0,a.jsx)("span",{className:"text-xs text-red-500",children:"Invalid audio data"})})()]}):(0,a.jsxs)("div",{className:"flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(Z.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{className:"text-sm font-medium",children:e.fileData.filename||"".concat(e.fileData.mimeType," file")}),(0,a.jsx)("span",{className:"text-xs text-primary-foreground/70",children:e.fileData.mimeType})]})})]})}),!C&&!z&&(0,a.jsxs)("div",{className:"text-xs text-muted-foreground mt-1 px-1 flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{children:eo}),v&&(null==(o=e.tokenUsage)?void 0:o.totalTokens)!==void 0&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-muted/50 text-xs cursor-default",children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.tokenUsage.totalTokens," ","tokens"]})}),(0,a.jsx)(O,{side:"bottom",children:(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[void 0!==e.tokenUsage.inputTokens&&(0,a.jsxs)("div",{children:["Input:"," ",e.tokenUsage.inputTokens]}),void 0!==e.tokenUsage.outputTokens&&(0,a.jsxs)("div",{children:["Output:"," ",e.tokenUsage.outputTokens]}),void 0!==e.tokenUsage.reasoningTokens&&(0,a.jsxs)("div",{children:["Reasoning:"," ",e.tokenUsage.reasoningTokens]}),(0,a.jsxs)("div",{className:"font-medium mt-0.5",children:["Total:"," ",e.tokenUsage.totalTokens]})]})})]}),v&&e.model&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{children:(0,a.jsx)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-muted/30 text-xs cursor-default",children:e.model})}),(0,a.jsx)(O,{side:"bottom",children:(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"font-medium",children:["Model: ",e.model]}),e.provider&&(0,a.jsxs)("div",{className:"font-medium",children:["Provider: ",e.provider]}),e.router&&(0,a.jsxs)("div",{className:"font-medium",children:["Router: ",e.router]})]})})]})]}),(v||g)&&(0,a.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,a.jsx)(F,{value:D(e),tooltip:"Copy message",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(q,{value:D(e),tooltip:"Speak",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]})]}),g&&(0,a.jsx)(en,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-2"})]}),es.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(X.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(X.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Image"})]}),(0,a.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>R(e.src,e.alt),children:[(0,a.jsx)("img",{src:e.src,alt:e.alt,className:"max-h-80 w-auto rounded border border-border object-contain transition-transform group-hover:scale-[1.02]"}),(0,a.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors rounded border border-border flex items-center justify-center",children:(0,a.jsx)(ee.A,{className:"h-8 w-8 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow-lg"})})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:eo})})]})]})},"".concat(f,"-image-").concat(t))),ea.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(et.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm overflow-hidden",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(et.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Video"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0",children:[(0,a.jsx)("video",{controls:!0,src:e.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}),(e.filename||e.mimeType)&&(0,a.jsxs)("div",{className:"flex flex-col text-xs text-muted-foreground",children:[e.filename&&(0,a.jsx)("span",{className:"truncate",children:e.filename}),e.mimeType&&(0,a.jsx)("span",{className:"opacity-70",children:e.mimeType})]})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:eo})})]})]})},"".concat(f,"-video-").concat(t))),er.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(P.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm overflow-hidden",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(P.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Audio"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0 audio-controls-container",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(H.A,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,a.jsx)("audio",{controls:!0,src:e.src,className:"flex-1 min-w-0"})]}),e.filename&&(0,a.jsx)("div",{className:"flex items-center gap-2 min-w-0",children:(0,a.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.filename})})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:eo})})]})]})},"".concat(f,"-audio-").concat(t))),ed&&(0,a.jsx)("div",{className:"mt-2 ml-12 mr-4",children:(0,a.jsx)(B,{error:r,onDismiss:i||(()=>{})})})]}),s&&ec&&(0,a.jsx)(ew,{})]},f)}),o&&d&&c&&(0,a.jsx)("div",{className:"w-full","data-role":"approval",children:(0,a.jsxs)("div",{className:"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start",children:[(0,a.jsx)(W.A,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1 flex-shrink-0"}),(0,a.jsx)("div",{className:"flex flex-col group w-full col-start-2 justify-self-start items-start min-w-0",children:(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm w-full max-w-[90%] bg-card text-card-foreground border border-border rounded-bl-none text-base min-w-0",children:(0,a.jsx)(ev,{approval:o,onApprove:d,onDeny:c})})})]})}),(0,a.jsx)("div",{ref:m,className:"h-px"},"end-anchor"),v.isOpen&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh] bg-background rounded-lg shadow-2xl border border-border",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:"Tool Result Image"}),(0,a.jsx)("button",{onClick:()=>{A({isOpen:!1,src:"",alt:""})},className:"p-2 hover:bg-muted rounded-md transition-colors","aria-label":"Close modal",children:(0,a.jsx)(C.A,{className:"h-5 w-5"})})]}),(0,a.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,a.jsx)("img",{src:v.src,alt:v.alt,className:"max-w-full max-h-[70vh] object-contain rounded"})}),(0,a.jsx)("div",{className:"p-4 border-t border-border text-sm text-muted-foreground",children:(0,a.jsx)("p",{children:v.alt})})]})})]})}function eC(e){let{text:t,isUser:s,onOpenImage:r,resourceSet:i}=e,{cleanedText:l,uris:o}=(0,n.useMemo)(()=>(function(e,t){if(!e)return{cleanedText:"",uris:[]};let s=function(e,t){let s=e.map(e=>({...e}));for(let e of s)switch(e.type){case"uri":if(t[e.identifier])e.resourceUri=e.identifier;else{let s=function(e,t){var s,r;let a=t.trim().toLowerCase();for(let[t,r]of Object.entries(e)){let e="string"==typeof(null==(s=r.metadata)?void 0:s.originalUri)?r.metadata.originalUri:void 0;if(e&&e.toLowerCase()===a)return t}for(let[t,s]of Object.entries(e)){let e="string"==typeof(null==(r=s.metadata)?void 0:r.originalUri)?s.metadata.originalUri:void 0;if(e&&e.toLowerCase().includes(a))return t}}(t,e.identifier);s&&(e.resourceUri=s)}break;case"server-scoped":{let s=function(e,t,s){let r=s.trim().toLowerCase(),a=Object.entries(e).filter(e=>{let[,s]=e;return s.serverName===t});for(let[e,t]of a){if(!t.name)continue;let s=t.name.trim().toLowerCase();if(s===r||s.includes(r))return e}for(let[e,t]of a){var n;let s="string"==typeof(null==(n=t.metadata)?void 0:n.originalUri)?t.metadata.originalUri:void 0;if((null==s?void 0:s.toLowerCase().includes(r))||e.toLowerCase().includes(r))return e}}(t,e.serverName,e.identifier);s&&(e.resourceUri=s);break}case"name":{let s=function(e,t){let s=t.trim().toLowerCase();for(let[t,r]of Object.entries(e)){if(!r.name)continue;let e=r.name.trim().toLowerCase();if(e===s||e.includes(s))return t}for(let[t,a]of Object.entries(e)){var r;let e="string"==typeof(null==(r=a.metadata)?void 0:r.originalUri)?a.metadata.originalUri:void 0;if((null==e?void 0:e.toLowerCase().includes(s))||t.toLowerCase().includes(s))return t}}(t,e.identifier);s&&(e.resourceUri=s)}}return s}(function(e){let t,s=[],r=RegExp("(?:^|(?<=\\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])","g");for(;null!==(t=r.exec(e));){let[e,r,a,n,i]=t;r?s.push({originalRef:e,type:"uri",identifier:r.slice(1,-1)}):a&&n?s.push({originalRef:e,type:"server-scoped",serverName:a,identifier:n}):i&&s.push({originalRef:e,type:"name",identifier:i})}return s}(e),t),r=Array.from(new Set(s.filter(e=>e.resourceUri).map(e=>e.resourceUri))),a=e;for(let e of s)e.resourceUri&&(a=a.split(e.originalRef).join(""));return{cleanedText:a=(a=a.replace(/\\n/g,"\n").replace(/\\t/g," ")).replace(/\n{3,}/g,"\n\n").replace(/[ \t]{2,}/g," ").trim(),uris:r}})(t,i),[t,i]),d=ex(o),c=l.length>0;return(0,a.jsxs)("div",{className:"space-y-3",children:[c&&(0,a.jsx)("div",{className:"relative min-w-0 overflow-hidden",children:s?(0,a.jsx)("p",{className:"text-base whitespace-pre-line break-words overflow-wrap-anywhere",children:l}):(0,a.jsx)(ec,{children:l})}),o.map(e=>(0,a.jsx)(eA,{uri:e,state:d[e],onOpenImage:r},e))]})}function eA(e){var t;let{uri:s,state:r,onOpenImage:n}=e;if(!r||"loading"===r.status)return(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(Q.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,a.jsx)("span",{children:"Loading resource…"})]});if("error"===r.status)return(0,a.jsxs)("div",{className:"flex items-start gap-2 text-xs text-destructive",children:[(0,a.jsx)(N.A,{className:"mt-0.5 h-3.5 w-3.5"}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"font-medium",children:"Failed to load resource"}),(0,a.jsx)("p",{className:"break-all text-[11px] text-destructive/80",children:s}),(0,a.jsx)("p",{className:"text-[11px] text-destructive/70",children:r.error})]})]});let i=r.data;if(!i||0===i.items.length)return(0,a.jsxs)("div",{className:"text-xs text-muted-foreground",children:[(0,a.jsx)("p",{className:"font-medium",children:(null==i?void 0:i.name)||s}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground/80",children:"No previewable content."})]});let l=null==(t=i.items.find(e=>"mimeType"in e&&"string"==typeof e.mimeType))?void 0:t.mimeType;return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/80",children:[(0,a.jsx)(es.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{className:"font-medium text-foreground",children:i.name||s}),l&&(0,a.jsx)("span",{className:"text-[10px]",children:l})]}),i.items.map((e,t)=>(function(e){let{item:t,index:s,onOpenImage:r}=e,n="resource-item-".concat(s);switch(t.kind){case"text":if(t.mimeType&&t.mimeType.includes("markdown"))return(0,a.jsx)("div",{className:"text-sm",children:(0,a.jsx)(ec,{children:t.text})},n);return(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words rounded-md bg-background/60 p-2 text-sm text-foreground",children:t.text},n);case"image":if(!eb(t.src))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported image source"},n);return(0,a.jsx)("img",{src:t.src,alt:t.alt||"Resource image",onClick:()=>r(t.src,t.alt||"Resource image"),className:"max-h-60 w-full cursor-zoom-in rounded-lg border border-border object-contain"},n);case"audio":if(!eb(t.src,"audio"))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported audio source"},n);return(0,a.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-background/50 p-2",children:[(0,a.jsx)(H.A,{className:"h-4 w-4"}),(0,a.jsx)("audio",{controls:!0,src:t.src,className:"h-8 flex-1"}),t.filename&&(0,a.jsx)("span",{className:"max-w-[140px] truncate text-xs text-muted-foreground",children:t.filename})]},n);case"video":if(!eb(t.src,"video"))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported video source"},n);return(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-border bg-background/50 p-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(J.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Video"}),t.filename&&(0,a.jsx)("span",{className:"truncate font-medium",children:t.filename})]}),(0,a.jsx)("video",{controls:!0,src:t.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."})]},n);case"file":return(0,a.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background/60 p-2",children:[(0,a.jsx)(Z.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsxs)("div",{className:"flex flex-1 flex-col",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.filename||"Resource file"}),t.mimeType&&(0,a.jsx)("span",{className:"text-[11px] text-muted-foreground",children:t.mimeType})]}),t.src&&(0,a.jsx)("a",{href:t.src,download:t.filename||"resource.bin",className:"text-xs font-medium text-primary underline-offset-2 hover:underline",children:"Download"})]},n);default:return null}})({item:e,index:t,onOpenImage:n}))]})}var eS=s(3597),eE=s(3988);function eI(e){let{children:t,className:s}=e;return(0,a.jsx)("div",{className:(0,j.cn)("relative","w-full","flex flex-col overflow-visible","max-h-[max(35svh,5rem)]","border-2 border-border/50","bg-background","rounded-3xl shadow-sm","transition-all duration-200",s),children:t})}function eT(e){let{leftButtons:t,rightButtons:s,className:r}=e;return(0,a.jsxs)("div",{className:(0,j.cn)("flex items-center justify-between","h-12 px-3 pr-4",r),children:[(0,a.jsx)("div",{className:"flex items-center gap-2",children:t}),(0,a.jsx)("div",{className:"flex items-center gap-2",children:s})]})}var eL=s(7847),eO=s(9160);let eR=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)(eO.bL,{className:(0,j.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...r,ref:t,children:(0,a.jsx)(eO.zi,{className:(0,j.cn)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})})});function eD(e){let{isStreaming:t,onStreamingChange:s,className:r}=e;return(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 cursor-pointer ".concat(r||""),children:[(0,a.jsx)(eL.A,{className:"h-3 w-3 ".concat(t?"text-blue-500":"text-muted-foreground")}),(0,a.jsx)(eR,{checked:t,onCheckedChange:s,className:"scale-75","aria-label":"Toggle streaming"})]})}),(0,a.jsxs)(O,{side:"bottom",children:[(0,a.jsx)("p",{children:t?"Streaming enabled":"Streaming disabled"}),(0,a.jsx)("p",{className:"text-xs opacity-75",children:t?"Responses will stream in real-time":"Responses will arrive all at once"})]})]})})}eR.displayName=eO.bL.displayName;var eF=s(9152),e_=s(9606);function eP(e){let{...t}=e;return(0,a.jsx)(e_.bL,{"data-slot":"popover",...t})}function eM(e){let{className:t,align:s="center",sideOffset:r=4,...n}=e;return(0,a.jsx)(e_.ZL,{children:(0,a.jsx)(e_.UC,{"data-slot":"popover-content",align:s,sideOffset:r,className:(0,j.cn)("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 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...n})})}let ez=e=>{let{children:t,...s}=e;return(0,a.jsx)(eP,{...s,children:t})},eU=function(e){let{...t}=e;return(0,a.jsx)(e_.l9,{"data-slot":"popover-trigger",...t})},eq=n.forwardRef((e,t)=>{let{className:s,align:r="end",sideOffset:n=4,...i}=e;return(0,a.jsx)(eM,{ref:t,align:r,sideOffset:n,className:(0,j.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","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",s),...i})});eq.displayName="DropdownMenuContent";let eB=n.forwardRef((e,t)=>{let{className:s,disabled:r,...n}=e;return(0,a.jsx)("div",{ref:t,className:(0,j.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",r&&"pointer-events-none opacity-50",!r&&"hover:bg-accent hover:text-accent-foreground cursor-pointer",s),...n})});eB.displayName="DropdownMenuItem";let e$=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,j.cn)("-mx-1 my-1 h-px bg-muted",s),...r})});function eW(e){let{onImageAttach:t,onPdfAttach:s,onAudioAttach:r,className:i,supports:l}=e,[o,d]=n.useState(!1),c=(null==l?void 0:l.image)!==!1,m=(null==l?void 0:l.pdf)!==!1,u=(null==l?void 0:l.audio)!==!1;return(0,a.jsxs)(ez,{open:o,onOpenChange:d,children:[(0,a.jsx)(eU,{asChild:!0,children:(0,a.jsxs)(R.$,{variant:"ghost",size:"sm",className:"h-8 px-2 md:px-3 text-sm text-muted-foreground hover:text-foreground rounded-full ".concat(i||""),"aria-label":"Attach File",children:[(0,a.jsx)(eF.A,{className:"h-3 w-3 md:mr-1.5"}),(0,a.jsx)("span",{className:"hidden md:inline",children:"Attach"})]})}),(0,a.jsxs)(eq,{side:"top",align:"start",children:[(0,a.jsx)(eB,{onClick:()=>{c&&(t(),d(!1))},className:c?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!c,children:(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(eF.A,{className:"h-4 w-4 mr-2"})," Image"]})}),!c&&(0,a.jsx)(O,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eB,{onClick:()=>{m&&(s(),d(!1))},className:m?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!m,children:(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(Z.A,{className:"h-4 w-4 mr-2"})," PDF"]})}),!m&&(0,a.jsx)(O,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eB,{onClick:()=>{u&&(r(),d(!1))},className:u?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!u,children:(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(H.A,{className:"h-4 w-4 mr-2"})," Audio file"]})}),!u&&(0,a.jsx)(O,{side:"bottom",children:"Unsupported for this model"})]})})})]})]})}e$.displayName="DropdownMenuSeparator";var eK=s(587),eV=s(6067);function eY(e){let{isRecording:t,onToggleRecording:s,className:r,disabled:n}=e,i=(0,a.jsxs)(R.$,{variant:"ghost",size:"sm",onClick:()=>{n||s()},className:"h-8 px-2 md:px-3 text-sm rounded-full ".concat(n?"opacity-50 cursor-not-allowed":"text-muted-foreground hover:text-foreground"," ").concat(r||""),"aria-label":t?"Stop recording":"Record audio","aria-disabled":!!n||void 0,children:[t?(0,a.jsx)(eK.A,{className:"h-3 w-3 md:mr-1.5 text-red-500"}):(0,a.jsx)(eV.A,{className:"h-3 w-3 md:mr-1.5"}),(0,a.jsx)("span",{className:"hidden md:inline",children:t?"Stop":"Record"})]});return n?(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:i}),(0,a.jsx)(O,{side:"bottom",children:"Unsupported for this model"})]})}):i}function eG(e){var t,s;let r=null!=(t=null==e?void 0:e.mode)?t:"grouped";return(0,m.I)({queryKey:[...x.l.llm.catalog,r],queryFn:async()=>{let e=await h.S.api.llm.catalog.$get({query:{mode:r}});if(!e.ok)throw Error("Failed to fetch LLM catalog: ".concat(e.status));return await e.json()},enabled:null==(s=null==e?void 0:e.enabled)||s})}var eQ=s(6938),eH=s(895),eJ=s(5911),eZ=s(8485),eX=s(7699);function e0(e){let{open:t,onOpenChange:s,provider:r,primaryEnvVar:i,onSaved:o}=e,[d,c]=(0,n.useState)(""),[m,p]=(0,n.useState)(null),f=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.llm.key.$post({json:e});if(!t.ok)throw Error("Failed to save API key: ".concat(t.status));return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.llm.catalog})}})}();return(0,a.jsx)(eH.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eH.Cf,{className:"max-w-md",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsxs)(eH.L3,{children:["Set ",r," API Key"]}),(0,a.jsxs)(eH.rr,{children:["This key will be stored in your .env (env var ",i,"). It is not shared with the client."]})]}),m&&(0,a.jsx)(eJ.Fc,{variant:"destructive",children:(0,a.jsx)(eJ.TN,{children:m})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"apiKey",children:"API Key"}),(0,a.jsx)(eZ.p,{id:"apiKey",type:"password",value:d,onChange:e=>c(e.target.value),placeholder:"Enter ".concat(r," API key")})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>s(!1),disabled:f.isPending,children:"Cancel"}),(0,a.jsx)(R.$,{onClick:()=>{if(!d.trim())return void p("API key is required");p(null),f.mutate({provider:r,apiKey:d},{onSuccess:e=>{o({provider:e.provider,envVar:e.envVar}),s(!1),c(""),p(null)},onError:e=>{p(e.message||"Failed to save API key")}})},disabled:f.isPending,children:f.isPending?"Saving...":"Save"})]})]})})}var e1=s(2480),e2=s(4024),e5=s(6580),e4=s(312);function e3(e){let{value:t,onChange:s,placeholder:r="Search providers or models",autoFocus:i=!1}=e,l=(0,n.useRef)(null);return(0,n.useEffect)(()=>{i&&l.current&&setTimeout(()=>{var e;null==(e=l.current)||e.focus()},100)},[i]),(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,a.jsx)(e4.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsx)(eZ.p,{ref:l,placeholder:r,value:t,onChange:e=>s(e.target.value),className:"focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0"})]})}var e8=s(3087),e6=s(9139),e7=s(4443);let e9={openai:"/logos/openai.svg",anthropic:"/logos/claude-color.svg",google:"/logos/gemini-color.svg",groq:"/logos/groq.svg",xai:"/logos/grok.svg","openai-compatible":"/logos/openai.svg",cohere:"/logos/cohere-color.svg"},te={openai:"https://platform.openai.com/docs/pricing",anthropic:"https://www.anthropic.com/pricing#api",google:"https://ai.google.dev/gemini-api/docs/pricing",groq:"https://groq.com/pricing/",xai:"https://docs.x.ai/docs/models",cohere:"https://cohere.com/pricing"};function tt(e){if(!e)return[];let t="USD"===(e.currency||"USD")?"$":"",s=[];return s.push("Cost: ".concat(t).concat(e.inputPerM.toFixed(2)," in / ").concat(t).concat(e.outputPerM.toFixed(2)," out per 1M tokens")),null!=e.cacheReadPerM&&s.push("Cache read: ".concat(t).concat(e.cacheReadPerM.toFixed(2)," per 1M tokens")),null!=e.cacheWritePerM&&s.push("Cache write: ".concat(t).concat(e.cacheWritePerM.toFixed(2)," per 1M tokens")),s}let ts=["google","cohere","anthropic"],tr=e=>!ts.includes(e),ta={image:(0,a.jsx)("span",{className:"text-sm",children:"\uD83D\uDDBC️"}),audio:(0,a.jsx)("span",{className:"text-sm",children:"\uD83C\uDFB5"}),pdf:(0,a.jsx)("span",{className:"text-sm",children:"\uD83D\uDCC4"}),reasoning:(0,a.jsx)("span",{className:"text-sm",children:"\uD83E\uDDE0"}),experimental:(0,a.jsx)(e6.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-amber-500 transition-colors cursor-help"}),new:(0,a.jsx)(e7.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-yellow-500 transition-colors cursor-help"}),realtime:(0,a.jsx)(eL.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-blue-500 transition-colors cursor-help"})};var tn=s(6291);function ti(e){let{supportedFileTypes:t,hasApiKey:s,className:r}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0 ".concat(r||""),children:[t.includes("pdf")&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:ta.pdf})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:"PDF support"})})]}),t.includes("audio")&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:ta.audio})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:"Audio support"})})]}),t.includes("image")&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:ta.image})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:"Image support"})})]}),!s&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:(0,a.jsx)(tn.A,{className:"h-3.5 w-3.5 text-amber-500 hover:text-amber-400 transition-colors cursor-help"})})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:"API key required"})})]})]})}function tl(e){let{providerId:t,provider:s,models:r,favorites:n,currentModel:i,onToggleFavorite:l,onUse:o}=e;return 0===r.length?null:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:e9[t]?(0,a.jsx)(eQ.default,{src:e9[t],alt:"".concat(t," logo"),width:20,height:20,className:(0,j.cn)("object-contain",tr(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(e1.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,a.jsx)("span",{className:"text-base font-medium",children:s.name})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[s.supportsBaseURL&&(0,a.jsx)(e8.E,{variant:"secondary",className:"text-xs",children:"baseURL"}),!s.hasApiKey&&(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(e8.E,{variant:"destructive",className:"text-xs cursor-default",children:"API Key Required"})}),(0,a.jsxs)(O,{children:["Click any ",s.name," model to set up the API key"]})]})}),te[t]&&(0,a.jsx)("a",{href:te[t],target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:underline",title:"View provider pricing",children:"Pricing ↗"})]})]}),(0,a.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:r.map(e=>{let r,d,c=e.displayName||e.name,m=(r=e.name,(null==i?void 0:i.provider)===t&&(null==i?void 0:i.model)===r),u=(d=e.name,n.includes("".concat(t,"|").concat(d))),x=s.hasApiKey,h=tt(e.pricing||void 0),p=["Max tokens: ".concat(e.maxInputTokens.toLocaleString()),e.supportedFileTypes.length>0&&"Supports: ".concat(e.supportedFileTypes.join(", ")),e.default&&"Default model",!x&&"⚠️ API key required",...h].filter(Boolean);return(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{onClick:()=>o(t,e),onKeyDown:s=>{let r=s.target;if(r&&r.closest("button"))return;let a="Enter"===s.key,n=" "===s.key||"Spacebar"===s.key||"Space"===s.code;n&&s.preventDefault(),(a||n)&&o(t,e)},className:(0,j.cn)("group relative flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-all duration-100 cursor-pointer outline-none","hover:bg-accent hover:border-accent-foreground/20 hover:shadow-sm","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",m&&"bg-accent border-accent-foreground/20 shadow-sm ring-1 ring-accent-foreground/10",!x&&"opacity-60"),role:"button",tabIndex:0,children:[(0,a.jsx)("div",{className:"flex-1 text-left",children:(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)("span",{className:"text-sm font-medium",children:c})})}),(0,a.jsx)(ti,{supportedFileTypes:e.supportedFileTypes,hasApiKey:x}),(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("button",{onKeyDown:e=>{let t=" "===e.key||"Spacebar"===e.key||"Space"===e.code;("Enter"===e.key||t)&&(e.stopPropagation(),t&&e.preventDefault())},onClick:s=>{s.stopPropagation(),l(t,e.name)},className:"flex-shrink-0 text-muted-foreground hover:text-foreground transition-colors","aria-label":u?"Remove from favorites":"Add to favorites",children:(0,a.jsx)(e2.A,{className:(0,j.cn)("h-4 w-4",u&&"fill-current text-yellow-500")})})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:u?"Remove from favorites":"Add to favorites"})})]})}),m&&(0,a.jsx)("div",{className:"absolute inset-y-0 left-0 w-0.5 bg-primary rounded-l-lg"})]})}),(0,a.jsx)(O,{side:"bottom",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:p.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})},e.name)})})]})}function to(e,t){return"".concat(e,"|").concat(t)}function td(e){let t=e.trim();if(!t.length)return{isValid:!0};try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return{isValid:!1,error:"URL must use http:// or https://"};if(!e.pathname.includes("/v1"))return{isValid:!1,error:"URL must include /v1 for compatibility"};return{isValid:!0}}catch(e){return{isValid:!1,error:"Invalid URL format"}}}let tc="dexto:modelFavorites",tm="dexto:customModels";function tu(e){let{htmlFor:t,children:s,tooltip:r,className:n}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,a.jsx)(eX.J,{htmlFor:t,className:n,children:s}),r&&(0,a.jsx)(I,{delayDuration:200,children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"More information",children:(0,a.jsx)(e1.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{side:"right",className:"max-w-xs",children:(0,a.jsx)("p",{className:"text-sm",children:r})})]})})]})}let tx=["openai","openai-compatible","anthropic","google","groq","xai","cohere"],th=["vercel","in-built"];var tp=s(8922);function tf(e){let{provider:t,model:s,providerInfo:r,isFavorite:n,isActive:i,onClick:l,onToggleFavorite:o}=e,d=s.displayName||s.name,c=r.hasApiKey,m=tt(s.pricing||void 0),u=["Max tokens: ".concat(s.maxInputTokens.toLocaleString()),s.supportedFileTypes.length>0&&"Supports: ".concat(s.supportedFileTypes.join(", ")),!c&&"⚠️ API key required",...m].filter(Boolean);return(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("div",{onClick:l,onKeyDown:e=>{let t=e.target;if(t&&t.closest("button"))return;let s="Enter"===e.key,r=" "===e.key||"Spacebar"===e.key||"Space"===e.code;(s||r)&&(r&&e.preventDefault(),l())},className:(0,j.cn)("w-full flex items-center gap-4 px-4 py-3 rounded-xl transition-all duration-150 cursor-pointer group","hover:bg-accent/50 hover:shadow-md hover:scale-[1.01]",i&&"bg-primary/10 shadow-md ring-2 ring-primary/20 scale-[1.01]",!c&&"opacity-60"),role:"button",tabIndex:0,children:[(0,a.jsx)("div",{className:"w-6 h-6 flex-shrink-0 flex items-center justify-center",children:e9[t]?(0,a.jsx)(eQ.default,{src:e9[t],alt:"".concat(t," logo"),width:24,height:24,className:(0,j.cn)("object-contain",tr(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(e1.A,{className:"h-5 w-5 text-muted-foreground"})}),(0,a.jsxs)("div",{className:"flex-1 text-left min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:d}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:t})]}),(0,a.jsx)(ti,{supportedFileTypes:s.supportedFileTypes,hasApiKey:c}),(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),o()},className:(0,j.cn)("flex-shrink-0 transition-all duration-200","hover:scale-110 active:scale-95",n?"text-yellow-500 hover:text-yellow-400":"text-muted-foreground hover:text-yellow-500"),"aria-label":n?"Remove from favorites":"Add to favorites",children:(0,a.jsx)(e2.A,{className:(0,j.cn)("h-4 w-4",n&&"fill-current")})})}),(0,a.jsx)(O,{side:"top",children:(0,a.jsx)("span",{children:n?"Remove from favorites":"Add to favorites"})})]})})]})}),(0,a.jsx)(O,{side:"right",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:u.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})})}function tg(){var e;let[t,s]=(0,n.useState)(!1),[r,i]=(0,n.useState)({}),[o,c]=(0,n.useState)(""),[m,p]=(0,n.useState)(!1),[f,g]=(0,n.useState)(""),[v,b]=(0,n.useState)(""),[y,N]=(0,n.useState)("favorites"),[C,A]=(0,n.useState)(null),[S,E]=(0,n.useState)([]),[I,T]=(0,n.useState)({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),[L,O]=(0,n.useState)(!1),[D,F]=(0,n.useState)(!1),[_,P]=(0,n.useState)(null),[M,z]=(0,n.useState)(null),{currentSessionId:U,currentLLM:q,refreshCurrentLLM:B}=(0,d.v)();(0,l.jE)();let $=(0,tp.st)(),K=(0,n.useRef)($);(0,n.useEffect)(()=>{K.current=$},[$]);let{data:V,isLoading:Y,error:G}=eG({enabled:t});(0,n.useEffect)(()=>{V&&"providers"in V&&i(V.providers)},[V]),(0,n.useEffect)(()=>{t&&q&&(g(q.router||"vercel"),b(q.baseURL||""))},[t,q]);let[H,J]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(t)try{let e=localStorage.getItem(tc),t=e?JSON.parse(e):[];J(t);let s=localStorage.getItem(tm),r=s?JSON.parse(s):[];E(r),t.length>0?N("favorites"):r.length>0?N("custom"):N("all")}catch(e){J([]),E([]),N("all")}},[t]);let Z=(0,n.useCallback)((e,t)=>{let s=to(e,t);J(e=>{let t=e.includes(s)?e.filter(e=>e!==s):[...e,s];return localStorage.setItem(tc,JSON.stringify(t)),t})},[]),X=(0,n.useCallback)(()=>{let{name:e,baseURL:t,maxInputTokens:s,maxOutputTokens:r}=I;if(!e.trim()||!t.trim())return void A("Model name and Base URL are required");let a=td(t);if(!a.isValid)return void A(a.error||"Invalid Base URL");let n=[...S,{name:e.trim(),baseURL:t.trim(),maxInputTokens:s?(()=>{let e=parseInt(s,10);return isNaN(e)?void 0:e})():void 0,maxOutputTokens:r?(()=>{let e=parseInt(r,10);return isNaN(e)?void 0:e})():void 0}];E(n),localStorage.setItem(tm,JSON.stringify(n)),T({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),O(!1),A(null)},[I,S]),ee=(0,n.useCallback)(e=>{let t=S.filter(t=>t.name!==e);E(t),localStorage.setItem(tm,JSON.stringify(t))},[S]),et=(0,n.useCallback)((e,t)=>{var s,a,n,i;let l=o.trim().toLowerCase();return!l||t.name.toLowerCase().includes(l)||null!=(n=null==(s=t.displayName)?void 0:s.toLowerCase().includes(l))&&n||e.toLowerCase().includes(l)||null!=(i=null==(a=r[e])?void 0:a.name.toLowerCase().includes(l))&&i},[o,r]),es=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.llm.switch.$post({json:e});if(!t.ok)throw Error("Failed to switch LLM: ".concat(t.status));return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.llm.catalog})}})}();function er(e,t,a){var n;let i=r[e],l=a||v,o=null!=(n=null==i?void 0:i.supportsBaseURL)?n:!!l;if(o&&l){let e=td(l);if(!e.isValid)return void A(e.error||"Invalid base URL")}if(i&&!i.hasApiKey){z({provider:e,model:t.name}),P(e),F(!0);return}let d=function(e,t){var s,a,n;let i=(null==q?void 0:q.router)||"vercel",l=null!=(a=null==(s=r[e])?void 0:s.supportedRouters)?a:["vercel"],o=null!=(n=t.supportedRouters)?n:l,d=f||i;return o.includes(d)?d:o[0]||l[0]||"vercel"}(e,t),c={provider:e,model:t.name,router:d,...o&&l&&{baseURL:l},...U&&{sessionId:U}};es.mutate(c,{onSuccess:async()=>{await B(),q&&K.current.trackLLMSwitched({fromProvider:q.provider,fromModel:q.model,toProvider:e,toModel:t.name,sessionId:U||void 0,trigger:"user_action"}),s(!1),A(null)},onError:e=>{A(e.message)}})}let ea=(null==q?void 0:q.displayName)||(null==q?void 0:q.model)||"Choose Model",en=(0,n.useMemo)(()=>H.map(e=>{let[t,s]=e.split("|");if(!tx.includes(t))return null;let a=r[t],n=null==a?void 0:a.models.find(e=>e.name===s);return a&&n?{providerId:t,provider:a,model:n}:null}).filter(Boolean),[H,r]),ei=(0,n.useMemo)(()=>{if(!o)return r;let e={};for(let t of tx){let s=r[t];if(!s)continue;let a=s.models.filter(e=>et(t,e));a.length>0&&(e[t]={...s,models:a})}return e},[r,o,et]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(eH.lG,{open:t,onOpenChange:s,children:[(0,a.jsx)(eH.zM,{asChild:!0,children:(0,a.jsxs)(R.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 cursor-pointer",title:"Choose model",children:[(null==q?void 0:q.provider)&&e9[q.provider]?(0,a.jsx)(eQ.default,{src:e9[q.provider],alt:"".concat(q.provider," logo"),width:16,height:16,className:(0,j.cn)("object-contain",tr(q.provider)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(W.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-sm",children:ea}),(0,a.jsx)(k.A,{className:"h-3 w-3"})]})}),(0,a.jsxs)(eH.Cf,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[(0,a.jsxs)(eH.c7,{className:"pb-4 flex-shrink-0",children:[(0,a.jsx)(eH.L3,{className:"text-xl",children:"Select Model"}),(0,a.jsx)(eH.rr,{className:"text-sm text-muted-foreground",children:"Choose your favorite model, check all models, or add your own model"})]}),(0,a.jsxs)("div",{className:"flex flex-col min-h-0 flex-1 space-y-4",children:[(0,a.jsxs)("div",{className:"flex-shrink-0 space-y-4",children:[(C||G)&&(0,a.jsx)(eJ.Fc,{variant:"destructive",children:(0,a.jsx)(eJ.TN,{children:C||(null==G?void 0:G.message)})}),(0,a.jsx)(e3,{value:o,onChange:c,placeholder:"Search models, providers..."})]}),!o&&(0,a.jsxs)("div",{className:"flex gap-2 border-b border-border pb-2",children:[(0,a.jsxs)("button",{onClick:()=>N("favorites"),className:(0,j.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","favorites"===y?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(e2.A,{className:(0,j.cn)("h-4 w-4","favorites"===y&&"fill-current")}),"Favorites",en.length>0&&(0,a.jsxs)("span",{className:"text-xs opacity-70",children:["(",en.length,")"]})]}),(0,a.jsxs)("button",{onClick:()=>N("all"),className:(0,j.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","all"===y?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(W.A,{className:"h-4 w-4"}),"All Models"]}),(0,a.jsxs)("button",{onClick:()=>N("custom"),className:(0,j.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","custom"===y?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(e5.A,{className:"h-4 w-4"}),"Custom",S.length>0&&(0,a.jsxs)("span",{className:"text-xs opacity-70",children:["(",S.length,")"]})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-auto px-1 min-h-0",children:Y?(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground justify-center py-8",children:[(0,a.jsx)(Q.A,{className:"h-4 w-4 animate-spin"})," Loading models..."]}):o?(0,a.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(ei).length?(0,a.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No models found matching your search"}):tx.map(e=>{let t=ei[e];return t?(0,a.jsx)(tl,{providerId:e,provider:t,models:t.models,favorites:H,currentModel:q||void 0,onToggleFavorite:Z,onUse:er},e):null})}):"favorites"===y?0===en.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center space-y-3",children:[(0,a.jsx)(e2.A,{className:"h-12 w-12 text-muted-foreground/40"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:"No favorites yet"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"Star models to add them to your favorites"})]})]}):(0,a.jsx)("div",{className:"space-y-2 pb-2",children:en.map(e=>{let t,{providerId:s,provider:r,model:n}=e;return(0,a.jsx)(tf,{provider:s,model:n,providerInfo:r,isFavorite:!0,isActive:(t=n.name,(null==q?void 0:q.provider)===s&&(null==q?void 0:q.model)===t),onClick:()=>er(s,n),onToggleFavorite:()=>Z(s,n.name)},to(s,n.name))})}):"custom"===y?(0,a.jsxs)("div",{className:"space-y-4 pb-2",children:[S.length>0&&(0,a.jsx)("div",{className:"space-y-2",children:S.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:e.name}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"openai-compatible"})]}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:e.baseURL})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 ml-2",children:[(0,a.jsx)(R.$,{size:"sm",variant:"ghost",onClick:()=>{er("openai-compatible",{name:e.name,displayName:e.name,maxInputTokens:e.maxInputTokens||128e3,supportedFileTypes:["pdf","image","audio"],supportedRouters:["vercel","in-built"]},e.baseURL)},className:"h-8 px-3",children:"Use"}),(0,a.jsx)(R.$,{size:"sm",variant:"ghost",onClick:()=>ee(e.name),className:"h-8 w-8 p-0 text-destructive hover:text-destructive","aria-label":"Delete custom model ".concat(e.name),children:"\xd7"})]})]},e.name))}),(0,a.jsxs)("div",{className:"space-y-3 pt-4 border-t border-border",children:[(0,a.jsxs)(R.$,{variant:"ghost",size:"sm",onClick:()=>O(!L),className:"flex items-center justify-between w-full p-0 h-auto hover:bg-transparent",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:0===S.length?"Add your first custom model":"Add another model"}),L?(0,a.jsx)(w.A,{className:"h-4 w-4"}):(0,a.jsx)(k.A,{className:"h-4 w-4"})]}),L&&(0,a.jsxs)("div",{className:"space-y-4 pl-4 border-l-2 border-muted",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tu,{htmlFor:"custom-model-name",tooltip:"Model identifier (e.g., llama3, mixtral, gpt-5)",children:"Model Name *"}),(0,a.jsx)(eZ.p,{id:"custom-model-name",value:I.name,onChange:e=>T(t=>({...t,name:e.target.value})),placeholder:"e.g., llama3",className:"text-sm"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tu,{htmlFor:"custom-base-url",tooltip:"OpenAI-compatible endpoint URL. Must include /v1 path (e.g., http://localhost:1234/v1)",children:"Base URL *"}),(0,a.jsx)(eZ.p,{id:"custom-base-url",value:I.baseURL,onChange:e=>T(t=>({...t,baseURL:e.target.value})),placeholder:"http://localhost:1234/v1",className:"text-sm"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tu,{htmlFor:"custom-max-input",tooltip:"Maximum input tokens to send to the model. Defaults to 128,000 if not specified",children:"Max Input Tokens"}),(0,a.jsx)(eZ.p,{id:"custom-max-input",type:"number",value:I.maxInputTokens,onChange:e=>T(t=>({...t,maxInputTokens:e.target.value})),placeholder:"128000",className:"text-sm",min:"1"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tu,{htmlFor:"custom-max-output",tooltip:"Maximum output tokens the model can generate. Uses provider's default if not specified",children:"Max Output Tokens"}),(0,a.jsx)(eZ.p,{id:"custom-max-output",type:"number",value:I.maxOutputTokens,onChange:e=>T(t=>({...t,maxOutputTokens:e.target.value})),placeholder:"Auto",className:"text-sm",min:"1"})]})]}),(0,a.jsx)(R.$,{onClick:X,size:"sm",className:"w-full",children:"Add Model"})]})]})]}):(0,a.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(r).length?(0,a.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No providers available"}):tx.map(e=>{let t=r[e];return t?(0,a.jsx)(tl,{providerId:e,provider:t,models:t.models,favorites:H,currentModel:q||void 0,onToggleFavorite:Z,onUse:er},e):null})})})]})]})]}),_&&(0,a.jsx)(e0,{open:D,onOpenChange:F,provider:_,primaryEnvVar:(null==(e=r[_])?void 0:e.primaryEnvVar)||"",onSaved:function(e){let t=e.provider;if(i(e=>({...e,[t]:e[t]?{...e[t],hasApiKey:!0}:e[t]})),F(!1),M){var s;let{provider:e,model:t}=M,a=null==(s=r[e])?void 0:s.models.find(e=>e.name===t);a&&er(e,a),z(null)}}})]})}var tv=s(5639),tj=s(57);function tb(e){let{resources:t,query:s,selectedIndex:r,onSelect:i,onHoverIndex:l,loading:o}=e,d=n.useMemo(()=>(0,j.L)(t,s),[t,s]),c=ex(n.useMemo(()=>d.filter(e=>(e.mimeType||"").startsWith("image/")).map(e=>e.uri),[d])),m=n.useRef([]);if(n.useEffect(()=>{let e=m.current[r];e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})},[r,d.length]),!s&&0===d.length&&!o)return(0,a.jsxs)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:[(0,a.jsx)("div",{children:"No resources available."}),(0,a.jsx)("div",{className:"text-xs mt-1 text-muted-foreground/80",children:"Connect an MCP server or enable internal resources to attach references."})]});let u=e=>"resource-option-".concat(btoa(e).replace(/[^a-zA-Z0-9]/g,"")),x=d[r]?u(d[r].uri):void 0;return o?(0,a.jsx)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Loading resources…"}):0===d.length?(0,a.jsxs)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:[(0,a.jsxs)("div",{children:['No resources match "',s,'"']}),(0,a.jsx)("div",{className:"text-xs mt-1 text-muted-foreground/80",children:"Tip: @ references only work at start or after spaces"})]}):(0,a.jsxs)("ul",{role:"listbox","aria-label":"Resource suggestions","aria-activedescendant":x,className:"py-1 text-sm max-h-64 overflow-y-auto",children:[(0,a.jsx)("li",{className:"px-3 py-1.5 text-xs text-muted-foreground/80 border-b border-border",children:"@ references files/resources • Works at start or after spaces"}),d.map((e,t)=>{let s=u(e.uri);return(0,a.jsxs)("li",{id:s,role:"option","aria-selected":t===r,ref:e=>{e&&(m.current[t]=e)},className:"px-3 py-2 cursor-pointer flex items-center gap-3 "+(t===r?"bg-accent text-accent-foreground":"hover:bg-accent hover:text-accent-foreground"),onMouseEnter:()=>null==l?void 0:l(t),onMouseDown:t=>{t.preventDefault(),i(e)},children:[(e.mimeType||"").startsWith("image/")&&(0,a.jsx)(ty,{resourceState:c[e.uri]}),(0,a.jsxs)("div",{className:"min-w-0 flex-1 mr-2",children:[(0,a.jsx)("div",{className:"truncate font-medium",children:e.name||e.uri.split("/").pop()||e.uri}),(0,a.jsx)("div",{className:"truncate text-xs text-muted-foreground",children:e.uri})]}),e.serverName&&(0,a.jsx)("span",{className:"ml-auto shrink-0 rounded bg-secondary px-2 py-0.5 text-xs text-secondary-foreground",children:e.serverName})]},e.uri)})]})}function ty(e){var t;let{resourceState:s}=e,r="w-10 h-10 rounded-md border border-border bg-muted/40 flex items-center justify-center overflow-hidden flex-shrink-0";if(!s)return(0,a.jsx)("div",{className:r,children:(0,a.jsx)(X.A,{className:"h-4 w-4 text-muted-foreground"})});if("loading"===s.status)return(0,a.jsx)("div",{className:r,children:(0,a.jsx)(Q.A,{className:"h-4 w-4 animate-spin text-muted-foreground"})});if("error"===s.status)return(0,a.jsx)("div",{className:r,title:s.error,children:(0,a.jsx)(X.A,{className:"h-4 w-4 text-destructive"})});let n=null==(t=s.data)?void 0:t.items.find(e=>"image"===e.kind);return n&&"src"in n?(0,a.jsx)("div",{className:r,children:(0,a.jsx)("img",{src:n.src,alt:n.alt||"Resource preview",className:"w-full h-full object-cover"})}):(0,a.jsx)("div",{className:r,children:(0,a.jsx)(X.A,{className:"h-4 w-4 text-muted-foreground"})})}let tN=e=>{let{prompt:t,isSelected:s,onClick:r,onMouseEnter:n,dataIndex:i}=e;return(0,a.jsx)("div",{className:"px-3 py-2 cursor-pointer transition-colors ".concat(s?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"),onClick:r,onMouseEnter:n,"data-index":i,children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:"mcp"===t.source?(0,a.jsx)(eL.A,{className:"h-3 w-3 text-blue-400"}):"config"===t.source?(0,a.jsx)("span",{className:"text-xs",children:"\uD83D\uDCCB"}):(0,a.jsx)(e7.A,{className:"h-3 w-3 text-purple-400"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsxs)("span",{className:"font-medium text-xs text-foreground",children:["/",t.name]}),t.arguments&&t.arguments.length>0&&(0,a.jsx)("span",{className:"flex items-center gap-1",children:t.arguments.map((e,t)=>(0,a.jsxs)("span",{className:"group relative inline-block",title:e.description||e.name,children:[(0,a.jsxs)("span",{className:"text-xs text-muted-foreground/70 hover:text-muted-foreground cursor-help transition-colors",children:["<",e.name,e.required?"":"?",">"]}),e.description&&(0,a.jsx)("span",{className:"invisible group-hover:visible absolute left-0 top-full mt-1 z-50 px-2 py-1 text-[10px] bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-nowrap pointer-events-none",children:e.description})]},e.name))})]}),"mcp"===t.source&&(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"MCP"}),"config"===t.source&&(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"Config"}),"custom"===t.source&&(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Custom"})]}),t.title&&(0,a.jsx)("div",{className:"text-xs font-medium text-foreground/90 mb-0.5",children:t.title}),t.description&&t.description!==t.title&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5 line-clamp-2",children:t.description})]})]})})};function tw(e){let{isVisible:t,searchQuery:s,onSelectPrompt:r,onClose:i,onCreatePrompt:l,refreshKey:o}=e,[d,c]=(0,n.useState)(0),m=(0,n.useRef)(0),u=(0,n.useRef)(null),x=(0,n.useRef)(null),h=(0,n.useRef)(0),{data:f=[],isLoading:g,refetch:v}=p({enabled:t});m.current=d,(0,n.useEffect)(()=>{if(!t)return;let e=null!=o?o:0;e>0&&e!==h.current&&(v(),h.current=e)},[t,o,v]);let j=n.useMemo(()=>{if(!s.trim()||"/"===s)return f;let e=(s.startsWith("/")?s.slice(1):s).split(/\s+/)[0]||"";return f.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.description&&t.description.toLowerCase().includes(e.toLowerCase())||t.title&&t.title.toLowerCase().includes(e.toLowerCase()))},[s,f]),b=n.useMemo(()=>{let e=s.trim();return!!e&&!!("/"===e||e.startsWith("/")&&0===j.length)},[s,j.length]),y=n.useMemo(()=>{let e=[];return b&&e.push({kind:"create"}),j.forEach(t=>e.push({kind:"prompt",prompt:t})),e},[b,j]);(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("✨ Prompts list changed:",(null==e?void 0:e.detail)||{}),v()};return window.addEventListener("mcp:prompts-list-changed",e),()=>{window.removeEventListener("mcp:prompts-list-changed",e)}},[t,v]),(0,n.useEffect)(()=>{c(+("/"===s&&j.length>0))},[s,j.length]);let N=y.length;return((0,n.useEffect)(()=>{c(e=>0===N?0:e>=N?N-1:e)},[N]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{let t=()=>{e.preventDefault(),e.stopPropagation(),"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation()},a=(s.startsWith("/")?s.slice(1):s).split(/\s+/),n=a.length>1&&a.slice(1).some(e=>e.trim().length>0);switch(e.key){case"ArrowDown":if(0===y.length)return;t(),c(e=>(e+1)%y.length);break;case"ArrowUp":if(0===y.length)return;t(),c(e=>(e-1+y.length)%y.length);break;case"Enter":if(n)return;if(t(),0===y.length){null==l||l();return}{let e=y[m.current];"create"===e.kind?null==l||l():r(e.prompt)}break;case"Escape":t(),i();break;case"Tab":if(t(),0===y.length){null==l||l();return}{let e=y[m.current];"create"===e.kind?null==l||l():r(e.prompt)}}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t,y,r,i,l,s]),(0,n.useEffect)(()=>{if(!x.current)return;let e=x.current,t=e.querySelector('[data-index="'.concat(d,'"]'));if(t){let s=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=r.top<s.top,n=r.bottom>s.bottom;(a||n)&&t.scrollIntoView({behavior:"smooth",block:"nearest"})}},[d]),(0,n.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&i()};return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,i]),t)?(0,a.jsxs)("div",{ref:u,className:"absolute left-0 right-0 mb-2 bg-background border border-border rounded-lg shadow-lg max-h-96 overflow-hidden z-[9999]",style:{position:"absolute",bottom:"calc(100% + 0px)",left:0,right:0,borderRadius:"8px",maxHeight:"320px",overflow:"visible",zIndex:9999,minWidth:"400px",background:"linear-gradient(135deg, hsl(var(--background)) 0%, hsl(var(--muted)) 100%)",border:"1px solid hsl(var(--border) / 0.3)",backdropFilter:"blur(8px)",boxShadow:"0 8px 32px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05)"},children:[(0,a.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[(0,a.jsx)("span",{children:"Available Prompts (hover over arguments for more info)"}),(0,a.jsx)(e8.E,{variant:"secondary",className:"ml-auto text-xs px-2 py-0.5",children:f.length})]})}),(0,a.jsx)("div",{ref:x,className:"max-h-48 overflow-y-auto",children:g?(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"Loading prompts..."}):(0,a.jsxs)(a.Fragment,{children:[b&&(0,a.jsxs)("div",{className:"px-3 py-2 cursor-pointer transition-colors ".concat(0===d?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"),onClick:()=>null==l?void 0:l(),onMouseEnter:()=>c(0),"data-index":0,children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-foreground",children:[(0,a.jsx)(e5.A,{className:"h-3 w-3 text-primary"}),(0,a.jsx)("span",{children:"Create new prompt"})]}),(0,a.jsx)("div",{className:"text-[11px] text-muted-foreground mt-1",children:"Define a reusable prompt. Press Enter to continue."})]}),0===j.length?!b&&(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"No prompts available."}):j.map((e,t)=>{let s=b?t+1:t;return(0,a.jsx)(tN,{prompt:e,isSelected:s===d,onClick:()=>r(e),onMouseEnter:()=>c(s),dataIndex:s},e.name)})]})}),(0,a.jsx)("div",{className:"px-2 py-1.5 border-t border-border bg-muted/20 text-xs text-muted-foreground text-center",children:(0,a.jsx)("span",{children:"↑↓ Navigate • Tab/Enter Select • Esc Close"})})]}):null}var tk=s(1073),tC=s(5254),tA=s(9377),tS=s(5433);function tE(e){let{open:t,onClose:s,onCreated:r}=e,[i,o]=(0,n.useState)(""),[d,c]=(0,n.useState)(""),[m,p]=(0,n.useState)(""),[f,g]=(0,n.useState)(""),[v,j]=(0,n.useState)(null),[b,y]=(0,n.useState)(null),[N,w]=(0,n.useState)(null),[k,C]=(0,n.useState)(!1),A=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.prompts.custom.$post({json:e});if(!t.ok)throw Error("Failed to create prompt: ".concat(t.status));return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.prompts.all})}})}();(0,n.useEffect)(()=>{t&&(o(""),c(""),p(""),g(""),j(null),y(null),w(null),C(!1),A.reset())},[t]);let S=async e=>{try{var t;let s=await (t=e,new Promise((e,s)=>{let r=new FileReader;r.onload=()=>{let t=r.result;"string"==typeof t?e(t):s(Error("Failed to read file"))},r.onerror=e=>s(e),r.readAsDataURL(t)}));j({base64:s,mimeType:e.type||"application/octet-stream",filename:e.name}),y(s),w(e.name)}catch(e){console.error("Failed to read file:",e)}},E=async e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s){j(null),y(null),w(null);return}await S(s)},I=async e=>{e.preventDefault(),C(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&await S(t[0])},T=async e=>{if(e.preventDefault(),!i.trim()||!f.trim())return;let t={name:i.trim(),title:d.trim()||void 0,description:m.trim()||void 0,content:f,resource:v||void 0};A.mutate(t,{onSuccess:e=>{(null==e?void 0:e.prompt)&&r({name:e.prompt.name}),s()}})};return(0,a.jsx)(eH.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-3xl",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsx)(eH.L3,{children:"Create Custom Prompt"}),(0,a.jsx)(eH.rr,{children:"Define reusable prompt text and optionally attach a supporting resource file."})]}),(0,a.jsxs)("form",{onSubmit:T,className:"space-y-4",children:[A.error&&(0,a.jsx)(eJ.Fc,{variant:"destructive",children:(0,a.jsx)(eJ.TN,{children:A.error instanceof Error?A.error.message:"Failed to create prompt"})}),(0,a.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"prompt-name",children:"Prompt Name"}),(0,a.jsx)(eZ.p,{id:"prompt-name",value:i,onChange:e=>o(e.target.value),placeholder:"research-summary",required:!0}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Use lowercase letters, numbers, or hyphens. This becomes your /prompt command."})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"prompt-title",children:"Title"}),(0,a.jsx)(eZ.p,{id:"prompt-title",value:d,onChange:e=>c(e.target.value),placeholder:"Research Summary"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"prompt-description",children:"Description"}),(0,a.jsx)(eZ.p,{id:"prompt-description",value:m,onChange:e=>p(e.target.value),placeholder:"Summarize research papers with key findings"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"prompt-content",children:"Prompt Content"}),(0,a.jsx)(tk.T,{id:"prompt-content",value:f,onChange:e=>g(e.target.value),placeholder:"Write the instructions for this prompt...",className:"min-h-[160px]",required:!0})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)(eX.J,{children:"Attach resource (optional)"}),b?(0,a.jsxs)("div",{className:"flex items-center justify-between rounded-lg border border-dashed border-border/60 bg-muted/40 px-4 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center text-sm",children:[(0,a.jsx)(tC.A,{className:"h-4 w-4 mr-2 text-muted-foreground"}),(0,a.jsx)(e8.E,{variant:"secondary",className:"mr-2",children:"Resource"}),N||"Attached file"]}),(0,a.jsxs)(R.$,{variant:"ghost",size:"sm",onClick:()=>{j(null),y(null),w(null)},children:[(0,a.jsx)(tA.A,{className:"h-4 w-4 mr-1"})," Remove"]})]}):(0,a.jsxs)("div",{className:"relative rounded-lg border-2 border-dashed transition-colors ".concat(k?"border-primary bg-primary/5":"border-border/60 hover:border-border/80"," px-6 py-8 text-center"),onDragOver:e=>{e.preventDefault(),C(!0)},onDragLeave:e=>{e.preventDefault(),C(!1)},onDrop:I,children:[(0,a.jsx)("input",{type:"file",onChange:E,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",accept:"*/*"}),(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center space-y-2",children:[(0,a.jsx)(tS.A,{className:"h-8 w-8 ".concat(k?"text-primary":"text-muted-foreground")}),(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("span",{className:"font-medium",children:k?"Drop file here":"Click to upload"}),(0,a.jsxs)("span",{className:"text-muted-foreground",children:[" ","or drag and drop"]})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Any file type supported"})]})]}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The resource will be stored securely and referenced when this prompt is used."})]}),(0,a.jsxs)(eH.Es,{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)(R.$,{type:"button",variant:"ghost",onClick:s,disabled:A.isPending,children:"Cancel"}),(0,a.jsx)(R.$,{type:"submit",disabled:A.isPending,children:A.isPending?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Q.A,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):"Save Prompt"})]})]})]})})}function tI(e){let{open:t,onClose:s}=e,[r,i]=(0,n.useState)(""),[o,d]=(0,n.useState)(""),c=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.memory.$post({json:e});return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.memories.all})}})}(),m=()=>{i(""),d(""),s()},p=async()=>{if(!r.trim())return;let e={content:r.trim(),...o.trim()&&{tags:o.split(",").map(e=>e.trim()).filter(Boolean)},metadata:{source:"user"}};c.mutate(e,{onSuccess:m})},f=()=>{c.isPending||(i(""),d(""),c.reset(),s())};return(0,a.jsx)(eH.lG,{open:t,onOpenChange:e=>{e||f()},children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-[500px]",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsx)(eH.L3,{children:"Create Memory"}),(0,a.jsx)(eH.rr,{children:"Memories are automatically included in every conversation to help Dexto remember your preferences and important information."})]}),(0,a.jsxs)("div",{className:"grid gap-4 py-4",children:[c.error&&(0,a.jsxs)(eJ.Fc,{variant:"destructive",children:[(0,a.jsx)(tv.A,{className:"h-4 w-4"}),(0,a.jsx)(eJ.TN,{children:c.error instanceof Error?c.error.message:"Failed to create memory"})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(eX.J,{htmlFor:"memory-content",children:"Memory Content *"}),(0,a.jsx)(tk.T,{id:"memory-content",placeholder:"e.g., I prefer concise responses without explanations",value:r,onChange:e=>i(e.target.value),className:"min-h-[100px] resize-none",disabled:c.isPending,autoFocus:!0}),(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[r.length," / 10,000 characters"]})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(eX.J,{htmlFor:"memory-tags",children:"Tags (optional)"}),(0,a.jsx)(eZ.p,{id:"memory-tags",placeholder:"e.g., preferences, work, coding-style",value:o,onChange:e=>d(e.target.value),disabled:c.isPending}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Comma-separated tags for organizing memories"})]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:f,disabled:c.isPending,children:"Cancel"}),(0,a.jsx)(R.$,{onClick:p,disabled:c.isPending||!r.trim(),children:c.isPending?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Q.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Memory"})]})]})})}function tT(e){let{onSend:t,isSending:s,variant:r="chat"}=e,i=(0,l.jE)(),[o,c]=(0,n.useState)(""),m=(0,n.useRef)(null),[u,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),v=(0,n.useRef)(null),b=(0,n.useRef)(null),y=(0,n.useRef)(null),N=function(){let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if("undefined"==typeof document)return;let e=document;if(!e.fonts||!e.fonts.ready)return void t(!0);let s=!1;return e.fonts.ready.then(()=>{s||t(!0)}),()=>{s=!0}},[]),e}(),[w,k]=(0,n.useState)(!1),A=(0,n.useRef)(null),{currentSessionId:S,isStreaming:E,setStreaming:I,cancel:T,processing:L,currentLLM:O}=(0,d.v)(),D=(0,tp.st)(),F=(0,n.useRef)(D);(0,n.useEffect)(()=>{F.current=D},[D]);let[P,M]=(0,n.useState)(!1),[z,U]=(0,n.useState)(null),[q,B]=(0,n.useState)(null),[$,W]=(0,n.useState)([]),{resources:K,loading:Y,refresh:G}=ep(),[J,X]=(0,n.useState)(""),[ee,et]=(0,n.useState)(!1),[es,er]=(0,n.useState)(0),[ea,en]=(0,n.useState)(null),ei=(0,n.useMemo)(()=>(0,j.L)(K,J),[K,J]),el=(e,t)=>{for(let s=t-1;s>=0;s--){let t=e[s];if("@"===t){if(0===s)return s;let t=e[s-1];if(/\s/.test(t))return s;break}if(/\s/.test(t))break}return -1},[eo,ed]=(0,n.useState)(!1),[ec,em]=(0,n.useState)(!1),[eu,ex]=(0,n.useState)(0),[eh,ef]=(0,n.useState)(!1),eg=f(),ev=e=>{B(e),setTimeout(()=>B(null),5e3)},ej=n.useCallback(()=>{ed(!1),em(!0)},[]),eb=n.useCallback(e=>{i.invalidateQueries({queryKey:x.l.prompts.all}),em(!1),ex(e=>e+1);let t="/".concat(e.name);c(t),m.current&&(m.current.focus(),m.current.setSelectionRange(t.length,t.length))},[i]),ey=n.useCallback(()=>{em(!1),"/"===o&&c("")},[o]),{data:eN}=eG({mode:"flat"});(0,n.useEffect)(()=>{let e=null==O?void 0:O.provider,t=null==O?void 0:O.model;if(!e||!t||!eN||!("models"in eN))return void W([]);let s=eN.models.find(s=>s.provider===e&&s.name===t);W((null==s?void 0:s.supportedFileTypes)||[])},[null==O?void 0:O.provider,null==O?void 0:O.model,eN]);let ew=async()=>{let e=o.trim();if(e||u||p){if("/"===e)return void ej();if(e.startsWith("/")){let t=function(e){let t=e.trim();if(!t.startsWith("/"))return{isSlash:!1,command:"",argsArray:[],argsText:""};let s=function(e){let t=[],s="",r=!1,a="",n=0;for(;n<e.length;){let i=e[n],l=e[n+1];r||'"'!==i&&"'"!==i?r&&i===a?(r=!1,a=""):r||" "!==i?"\\"===i&&l?(s+=l,n++):s+=i:s&&(t.push(s),s=""):(r=!0,a=i),n++}return s&&t.push(s),t.filter(Boolean)}(t.slice(1)),r=s[0]||"",a=s.slice(1),n=a.join(" ");return{isSlash:!0,command:r,argsArray:a,argsText:n}}(e),s=t.command,r=e.slice(1+s.length).trimStart();if(s)try{let a=await eg.mutateAsync({name:s,context:r||void 0,args:t.argsArray&&t.argsArray.length>0?(()=>{let{keyValues:e,positional:s}=function(e){let t={},s=[];for(let r of e){let e=r.indexOf("=");if(e>0){let s=r.slice(0,e).trim(),a=r.slice(e+1);if(s.length>0){t[s]=a;continue}}s.push(r)}return{keyValues:t,positional:s}}(t.argsArray),r={...e};return s.length>0&&(r._positional=s),Object.keys(r).length>0?JSON.stringify(r):void 0})():void 0});a.text.trim()&&(e=a.text)}catch(e){}}t(e,null!=u?u:void 0,null!=p?p:void 0),c(""),h(null),g(null),ed(!1)}},ek=(e,t)=>{var s;if(!t&&0===ei.length)return;let r=null!=t?t:ei[Math.max(0,Math.min(e,ei.length-1))],a=m.current;if(!a)return;let n=null!=(s=a.selectionStart)?s:o.length,i=el(o,n);if(-1===i)return;let l=o.slice(0,i),d=o.slice(n),u=r.name||r.uri.split("/").pop()||r.uri,x=r.serverName?"@".concat(r.serverName,":").concat(u):"@".concat(u);c(l+x+d),et(!1),X(""),er(0),requestAnimationFrame(()=>{let e=(l+x).length;a.setSelectionRange(e,e),a.focus()})},eC=e=>{if(ee){if("ArrowDown"===e.key){e.preventDefault(),er(e=>(e+1)%Math.max(1,ei.length));return}if("ArrowUp"===e.key){e.preventDefault(),er(e=>(e-1+Math.max(1,ei.length))%Math.max(1,ei.length));return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),ek(es);return}if("Escape"===e.key)return void et(!1)}if(eA&&"Escape"===e.key){e.preventDefault(),eL(!1),c("");return}if("Enter"===e.key&&!e.shiftKey){if(e.preventDefault(),"#"===o.trim()){c(""),eL(!1),ef(!0);return}ew()}},[eA,eL]=(0,n.useState)(!1),[eO,eR]=(0,n.useState)(null),eF=e=>{let t=e.target.value;if(c(t),t.startsWith("/")&&!t.includes("\n")?ed(!0):eo&&ed(!1),"#"===t.trim()){eL(!0);let e=m.current;if(e){let t=e.getBoundingClientRect(),s=Math.max(8,t.left+window.scrollX+16),r=Math.max(280,t.width-32);eR({position:"fixed",left:s,bottom:Math.max(80,window.innerHeight-(t.bottom+window.scrollY)+64),width:r,zIndex:9999})}}else eL(!1),eR(null)};(0,n.useEffect)(()=>{var e;let t=m.current,s=t&&null!=(e=t.selectionStart)?e:o.length,r=el(o,s);if(r>=0){X(o.slice(r+1,s)),et(!0),er(0);let e=null==t?void 0:t.getBoundingClientRect();if(e){let t=Math.max(8,e.left+window.scrollX+16),s=Math.max(280,e.width-32);en({position:"fixed",left:t,bottom:Math.max(80,window.innerHeight-(e.bottom+window.scrollY)+64),width:s,zIndex:9999})}}else et(!1),X(""),en(null)},[o]);let e_=n.useRef(!1);(0,n.useEffect)(()=>{ee?e_.current||(e_.current=!0,G()):e_.current=!1},[ee,G]);let eP=e=>{let t=e.clipboardData.getData("text/plain");if(t&&!(t.length<=2e4))if(e.preventDefault(),window.confirm("Large text detected. Attach as a file instead of inflating the input?\n(OK = attach as file, Cancel = paste truncated preview)"))g({base64:(e=>{try{return btoa(unescape(encodeURIComponent(e)))}catch(t){return btoa(e)}})(t),mimeType:"text/plain",filename:"pasted.txt"});else{let e=t.slice(0,2e4);c(t=>t+e)}},eM=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);A.current=t;let s=[];t.ondataavailable=e=>{e.data.size>0&&s.push(e.data)},t.onstop=()=>{let r=new Blob(s,{type:t.mimeType}),a=new FileReader;a.onloadend=()=>{try{let e=a.result,s=e.indexOf(","),n=e.substring(s+1),i=t.mimeType||"audio/webm",l={"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"}[i]||i.split("/")[1]||"webm";g({base64:n,mimeType:i,filename:"recording.".concat(l)}),S&&F.current.trackFileUploaded({fileType:i,fileSizeBytes:r.size,sessionId:S})}catch(e){ev("Failed to process audio recording. Please try again."),g(null)}},a.readAsDataURL(r),e.getTracks().forEach(e=>e.stop())},t.start(),k(!0)}catch(e){ev("Failed to start audio recording. Please check microphone permissions.")}};return(0,n.useEffect)(()=>{o&&z&&U(null),o&&q&&B(null)},[o,z,q]),o.length,(0,a.jsxs)("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[z&&(0,a.jsxs)(eJ.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(tv.A,{className:"h-4 w-4"}),(0,a.jsxs)(eJ.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:z}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>U(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(C.A,{className:"h-3 w-3"})})]})]}),q&&(0,a.jsxs)(eJ.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(tv.A,{className:"h-4 w-4"}),(0,a.jsxs)(eJ.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:q}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>B(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(C.A,{className:"h-3 w-3"})})]})]}),(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsx)("form",{onSubmit:e=>{e.preventDefault(),ew()},children:(0,a.jsxs)(eI,{children:[(u||p)&&(0,a.jsx)("div",{className:"px-4 pt-4",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[u&&(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-1 bg-muted/50 group",children:[(0,a.jsx)("img",{src:"data:".concat(u.mimeType,";base64,").concat(u.base64),alt:"preview",className:"h-12 w-auto rounded-md"}),(0,a.jsx)(R.$,{variant:"destructive",size:"icon",onClick:()=>h(null),className:"absolute -top-1 -right-1 h-4 w-4 rounded-full bg-destructive text-destructive-foreground opacity-100 group-hover:opacity-100 transition-opacity duration-150 shadow-md","aria-label":"Remove image",children:(0,a.jsx)(C.A,{className:"h-2 w-2"})})]}),p&&(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[p.mimeType.startsWith("audio")?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(H.A,{className:"h-4 w-4"}),(0,a.jsx)("audio",{controls:!0,src:"data:".concat(p.mimeType,";base64,").concat(p.base64),className:"h-8"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Z.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-xs font-medium max-w-[160px] truncate",children:p.filename||"attachment"})]}),(0,a.jsx)(R.$,{variant:"destructive",size:"icon",onClick:()=>g(null),className:"absolute -top-1 -right-1 h-4 w-4 rounded-full bg-destructive text-destructive-foreground opacity-100 group-hover:opacity-100 transition-opacity duration-150 shadow-md","aria-label":"Remove attachment",children:(0,a.jsx)(C.A,{className:"h-2 w-2"})})]})]})}),(0,a.jsxs)("div",{className:"flex-auto overflow-y-auto relative",children:[N?(0,a.jsx)(eE.A,{ref:m,value:o,onChange:eF,onKeyDown:eC,onPaste:eP,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"}):(0,a.jsx)("textarea",{ref:m,rows:1,value:o,onChange:eF,onKeyDown:eC,onPaste:eP,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"}),ee&&ea&&eS.createPortal((0,a.jsx)("div",{style:ea,className:"max-h-64 overflow-y-auto rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:(0,a.jsx)(tb,{resources:K,query:J,selectedIndex:es,onHoverIndex:e=>er(e),onSelect:e=>ek(es,e),loading:Y})}),document.body),eA&&eO&&eS.createPortal((0,a.jsx)("div",{style:eO,className:"rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:(0,a.jsxs)("div",{className:"p-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,a.jsx)(V.A,{className:"h-3.5 w-3.5"}),(0,a.jsxs)("span",{children:["Press"," ",(0,a.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)]}),(0,a.jsx)(tw,{isVisible:eo,searchQuery:o,onSelectPrompt:e=>{let t="/".concat(e.name);c(t),ed(!1),m.current&&(m.current.focus(),m.current.setSelectionRange(t.length,t.length))},onClose:()=>{ed(!1)},onCreatePrompt:ej,refreshKey:eu}),(0,a.jsx)(eT,{leftButtons:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(eW,{onImageAttach:()=>{var e;return null==(e=v.current)?void 0:e.click()},onPdfAttach:()=>{var e;return null==(e=b.current)?void 0:e.click()},onAudioAttach:()=>{var e;return null==(e=y.current)?void 0:e.click()},supports:{image:$.length?$.includes("image"):void 0,pdf:$.length?$.includes("pdf"):void 0,audio:$.length?$.includes("audio"):void 0}}),(0,a.jsx)(eY,{isRecording:w,onToggleRecording:w?()=>{var e;null==(e=A.current)||e.stop(),k(!1)}:eM,disabled:$.length>0&&!$.includes("audio")})]}),rightButtons:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"hidden md:block",children:(0,a.jsx)(eD,{isStreaming:E,onStreamingChange:I})}),(0,a.jsx)(tg,{}),(0,a.jsx)(R.$,{type:L?"button":"submit",onClick:L?()=>T(S||void 0):void 0,disabled:!L&&(!o.trim()&&!u&&!p||s),className:(0,j.cn)("h-10 w-10 p-0 rounded-full transition-all duration-200",L?"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":L?"Stop":"Send message",title:L?"Stop":"Send",children:L?(0,a.jsx)(_.A,{className:"h-3.5 w-3.5 fill-current"}):s?(0,a.jsx)(Q.A,{className:"h-4 w-4 animate-spin"}):(0,a.jsx)(tj.A,{className:"h-4 w-4"})})]})})]})}),(0,a.jsx)("input",{ref:v,type:"file",id:"image-upload",accept:"image/*",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("Image file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("image/")){ev("Please select a valid image file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(",");if(-1===t)throw Error("Invalid Data URL format");let a=e.substring(0,t),n=e.substring(t+1),i=a.match(/data:(.*);base64/),l=i?i[1]:s.type;if(!l)throw Error("Could not determine MIME type");h({base64:n,mimeType:l}),B(null),S&&F.current.trackImageUploaded({imageType:l,imageSizeBytes:s.size,sessionId:S})}catch(e){ev("Failed to process image file. Please try again."),h(null)}},r.onerror=e=>{ev("Failed to read image file. Please try again."),h(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:b,type:"file",id:"pdf-upload",accept:"application/pdf",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("PDF file too large. Maximum size is 64MB."),e.target.value="";return}if("application/pdf"!==s.type){ev("Please select a valid PDF file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(","),a=e.substring(t+1);g({base64:a,mimeType:"application/pdf",filename:s.name}),B(null),S&&F.current.trackFileUploaded({fileType:"application/pdf",fileSizeBytes:s.size,sessionId:S})}catch(e){ev("Failed to process PDF file. Please try again."),g(null)}},r.onerror=e=>{ev("Failed to read PDF file. Please try again."),g(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:y,type:"file",id:"audio-upload",accept:"audio/*",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("Audio file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("audio/")){ev("Please select a valid audio file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(","),a=e.substring(t+1);g({base64:a,mimeType:s.type,filename:s.name}),B(null),S&&F.current.trackFileUploaded({fileType:s.type,fileSizeBytes:s.size,sessionId:S})}catch(e){ev("Failed to process audio file. Please try again."),g(null)}},r.onerror=e=>{ev("Failed to read audio file. Please try again."),g(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)(tE,{open:ec,onClose:ey,onCreated:eb}),(0,a.jsx)(tI,{open:eh,onClose:()=>ef(!1)})]})]})}var tL=s(4454);let tO=JSON.parse('[{"id":"filesystem","name":"Filesystem","description":"Secure file operations with configurable access controls for reading and writing files","category":"productivity","icon":"\uD83D\uDCC1","config":{"type":"stdio","command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","."],"timeout":30000},"tags":["file","directory","filesystem","io"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDDBC️","config":{"type":"stdio","command":"npx","args":["-y","meme-mcp"],"env":{"IMGFLIP_USERNAME":"","IMGFLIP_PASSWORD":""},"timeout":30000},"tags":["meme","image","creative"],"isOfficial":false,"isInstalled":false,"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":"\uD83D\uDD0E","config":{"type":"stdio","command":"npx","args":["-y","@truffle-ai/product-name-scout-mcp"],"timeout":30000},"tags":["research","naming","brand"],"isOfficial":true,"isInstalled":false,"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":"\uD83E\uDD86","config":{"type":"stdio","command":"uvx","args":["duckduckgo-mcp-server"],"timeout":30000},"tags":["search","web","research"],"isOfficial":false,"isInstalled":false,"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":"\uD83C\uDF10","config":{"type":"stdio","command":"uvx","args":["truffle-ai-domain-checker-mcp"],"timeout":30000},"tags":["domains","availability","research"],"isOfficial":true,"isInstalled":false,"requirements":{"platform":"all","python":">=3.10"},"author":"Truffle AI","homepage":"https://github.com/truffle-ai/mcp-servers","matchIds":["domain-checker"]},{"id":"linear","name":"Linear","description":"Manage Linear issues, projects, and workflows","category":"productivity","icon":"\uD83D\uDCCB","config":{"type":"stdio","command":"npx","args":["-y","mcp-remote","https://mcp.linear.app/sse"],"timeout":30000},"tags":["linear","tasks","projects"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD8C️","config":{"type":"stdio","command":"uvx","args":["truffle-ai-image-editor-mcp"],"timeout":30000},"tags":["image","edit","opencv","pillow"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDFB5","config":{"type":"stdio","command":"uvx","args":["truffle-ai-music-creator-mcp"],"timeout":30000},"tags":["audio","music","effects"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDFA4","config":{"type":"stdio","command":"uvx","args":["elevenlabs-mcp"],"env":{"ELEVENLABS_API_KEY":""},"timeout":30000},"tags":["tts","voice","audio","synthesis"],"isOfficial":true,"isInstalled":false,"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":"\uD83E\uDD17","config":{"type":"stdio","command":"npx","args":["-y","@llmindset/mcp-hfspace"],"timeout":30000},"tags":["huggingface","models","ai","ml"],"isOfficial":false,"isInstalled":false,"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":"\uD83D\uDD0D","config":{"type":"stdio","command":"npx","args":["-y","tavily-mcp@0.1.3"],"env":{"TAVILY_API_KEY":""},"timeout":30000},"tags":["search","web","research","ai"],"isOfficial":false,"isInstalled":false,"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":"\uD83C\uDF10","config":{"type":"stdio","command":"npx","args":["-y","@truffle-ai/puppeteer-server"],"timeout":30000},"tags":["browser","automation","web","puppeteer"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDF99️","config":{"type":"stdio","command":"npx","args":["-y","@truffle-ai/gemini-tts-server"],"env":{"GEMINI_API_KEY":""},"timeout":60000},"tags":["tts","speech","voice","audio","gemini","multi-speaker"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDF4C","config":{"type":"stdio","command":"npx","args":["-y","@truffle-ai/nano-banana-server@0.1.2"],"env":{"GEMINI_API_KEY":""},"timeout":60000},"tags":["image","generation","editing","ai","gemini","nano-banana"],"isOfficial":true,"isInstalled":false,"requirements":{"platform":"all","node":">=18.0.0"},"author":"Truffle AI","homepage":"https://github.com/truffle-ai/mcp-servers","matchIds":["nano-banana","nano_banana"]},{"id":"heygen","name":"HeyGen","description":"Generate realistic human-like audio using HeyGen","category":"creative","icon":"\uD83C\uDFA4","config":{"type":"stdio","command":"uvx","args":["heygen-mcp"],"env":{"HEYGEN_API_KEY":""},"timeout":30000},"tags":["audio","voice","synthesis","heygen"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDFAC","config":{"type":"stdio","command":"npx","args":["mcp-remote","https://mcp.runway.team","--header","Authorization: Bearer ${RUNWAY_API_KEY}"],"env":{"RUNWAY_API_KEY":""},"timeout":60000},"tags":["runway","video","generation","ai","creative"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD0D","config":{"type":"stdio","command":"npx","args":["-y","@perplexity-ai/mcp-server"],"env":{"PERPLEXITY_API_KEY":"","PERPLEXITY_TIMEOUT_MS":"600000"},"timeout":600000},"tags":["search","web","research","ai"],"isOfficial":true,"isInstalled":false,"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":"\uD83C\uDFAC","config":{"type":"stdio","command":"npx","args":["-y","@truffle-ai/sora-video-server"],"env":{"OPENAI_API_KEY":""},"timeout":60000},"tags":["video","generation","ai","creative"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDCCA","config":{"type":"stdio","command":"npx","args":["-y","@ax-crew/chartjs-mcp-server"],"timeout":30000},"tags":["chart","visualization","data","chartjs"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD0D","config":{"type":"stdio","command":"npx","args":["-y","raglite-mcp"],"timeout":30000},"tags":["rag","data","ai"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD0D","config":{"type":"http","url":"https://mcp.exa.ai/mcp","headers":{}},"tags":["rag","data","ai"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD0D","config":{"type":"stdio","command":"npx","args":["-y","firecrawl-mcp"],"env":{"FIRECRAWL_API_KEY":""},"timeout":30000},"tags":["search","web","research","ai"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDD8C️","config":{"type":"stdio","command":"npx","args":["shadcn@latest","mcp"],"timeout":30000},"tags":["shadcn","ui","components","mcp"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDCB0","config":{"type":"http","url":"https://mcp.kite.trade/mcp","headers":{}},"tags":["kite","trade","data","ai"],"isOfficial":true,"isInstalled":false,"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":"\uD83D\uDCB0","config":{"type":"http","url":"https://mcp.api.coingecko.com/mcp","headers":{}},"tags":["coingecko","data","ai"],"isOfficial":true,"isInstalled":false,"requirements":{"platform":"all","node":">=18.0.0"},"author":"CoinGecko","homepage":"https://docs.coingecko.com/docs/mcp-server","matchIds":["coingecko"]}]');class tR{static normalizeId(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return tR.instance||(tR.instance=new tR),tR.instance}async initialize(){this.isInitialized||(this.registryEntries=this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(e){var t;await this.initialize();let s=[...this.registryEntries];if((null==e?void 0:e.category)&&(s=s.filter(t=>t.category===e.category)),(null==e||null==(t=e.tags)?void 0:t.length)&&(s=s.filter(t=>e.tags.some(e=>t.tags.includes(e)))),null==e?void 0:e.search){let t=e.search.toLowerCase();s=s.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.tags.some(e=>e.toLowerCase().includes(t)))}return(null==e?void 0:e.installed)!==void 0&&(s=s.filter(t=>t.isInstalled===e.installed)),(null==e?void 0:e.official)!==void 0&&(s=s.filter(t=>t.isOfficial===e.official)),s.sort((e,t)=>e.isInstalled!==t.isInstalled?e.isInstalled?-1:1:e.isOfficial!==t.isOfficial?e.isOfficial?-1:1:e.name.localeCompare(t.name))}async updateEntry(e,t){let s=this.registryEntries.findIndex(t=>t.id===e);return -1!==s&&(this.registryEntries[s]={...this.registryEntries[s],...t},!0)}async setInstalled(e,t){return this.updateEntry(e,{isInstalled:t})}async syncWithServerStatus(){try{if(await this.initialize(),0===this.registryEntries.length)return void console.warn("Registry entries not available for status sync");let e=await h.S.api.mcp.servers.$get();if(!e.ok)throw Error("Failed to fetch servers: ".concat(e.status));let t=(await e.json()).servers||[],s=new Set;for(let e of(t.forEach(e=>{if(!(null==e?void 0:e.id)||"string"!=typeof e.id)return;let t=tR.normalizeId(e.id);s.add(t)}),this.registryEntries)){let t=[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>tR.normalizeId(String(e))).some(e=>s.has(e));e.isInstalled!==t&&(e.isInstalled=t)}}catch(e){console.warn("Failed to sync registry with server status:",e)}}async getServerConfig(e){return await this.initialize(),this.registryEntries.find(t=>t.id===e)||null}getBuiltinEntries(){return tO}constructor(){this.registryEntries=[],this.isInitialized=!1}}let tD=tR.getInstance();function tF(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card",className:(0,j.cn)("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",t),...s})}function t_(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-header",className:(0,j.cn)("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",t),...s})}function tP(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-title",className:(0,j.cn)("leading-none font-semibold",t),...s})}function tM(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-content",className:(0,j.cn)("px-6",t),...s})}var tz=s(3507),tU=s(5387),tq=s(6865),tB=s(7244),t$=s(4512),tW=s(2814);function tK(e){let{isOpen:t,onClose:s,onInstallServer:r,onOpenConnectModal:i,refreshTrigger:l,disableClose:o=!1}=e,[d,c]=(0,n.useState)([]),[m,u]=(0,n.useState)([]),[x,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(null),[g,v]=(0,n.useState)(null),[b,y]=(0,n.useState)({}),[N,A]=(0,n.useState)(""),[S,E]=(0,n.useState)("grid"),[I,T]=(0,n.useState)(null),L=(0,n.useRef)(null),O=(0,n.useRef)(!0),D=(0,n.useRef)(null);(0,n.useEffect)(()=>(O.current=!0,()=>{O.current=!1,L.current&&clearTimeout(L.current),D.current&&D.current.abort()}),[]),(0,n.useEffect)(()=>{t&&(async()=>{D.current&&D.current.abort();let e=new AbortController;if(D.current=e,O.current){h(!0),f(null);try{await tD.syncWithServerStatus();let t=await tD.getEntries();O.current&&!e.signal.aborted&&(c(t),u(t))}catch(t){O.current&&!e.signal.aborted&&f(t instanceof Error?t.message:"Failed to load server registry")}finally{O.current&&!e.signal.aborted&&h(!1)}}})()},[t,l]);let F=(0,n.useCallback)(async(e,t)=>{if(O.current)try{let s=await tD.getEntries({...e,search:t||void 0});O.current&&u(s)}catch(e){O.current&&f(e instanceof Error?e.message:"Failed to filter entries")}},[]);(0,n.useEffect)(()=>(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{F(b,N)},300),()=>{L.current&&clearTimeout(L.current)}),[b,N,d,F]);let _=async e=>{if(O.current){v(e.id);try{let t=await r(e);"connected"===t?(await tD.setInstalled(e.id,!0),O.current&&(c(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)),u(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)))):O.current&&(c(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)),u(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)))}catch(e){O.current&&f(e instanceof Error?e.message:"Failed to install server")}finally{O.current&&v(null)}}},P=e=>{let t={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 t[e]||t.custom},M=o||!!g,z=(0,n.useCallback)(e=>{e||M||s()},[M,s]),U=M?e=>{e.preventDefault()}:void 0;return(0,a.jsx)(eH.lG,{open:t,onOpenChange:z,children:(0,a.jsxs)(eH.Cf,{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:M?e=>e.preventDefault():void 0,onInteractOutside:U,children:[(0,a.jsx)(eH.c7,{className:"pb-4 border-b px-6 pt-5 bg-gradient-to-r from-muted/30 via-transparent to-transparent",children:(0,a.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:(0,a.jsx)(tz.A,{className:"h-5 w-5 text-primary"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(eH.L3,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),(0,a.jsx)(eH.rr,{className:"text-sm text-muted-foreground",children:"Discover and add integrations to your AI assistant"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(R.$,{onClick:()=>{M||s(),null==i||i()},size:"sm",variant:"outline",className:"h-8 px-3 text-sm font-medium hover:bg-muted whitespace-nowrap",children:[(0,a.jsx)(tU.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),(0,a.jsxs)(R.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>s(),disabled:M,children:[(0,a.jsx)(C.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}),(0,a.jsxs)("div",{className:"flex gap-3 mb-5 px-6 pt-5",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(e4.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60 pointer-events-none z-10"}),(0,a.jsx)(eZ.p,{placeholder:"Search servers and integrations...",value:N,onChange:e=>A(e.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"})]}),(0,a.jsxs)("div",{className:"flex bg-muted/50 rounded-md p-1 border",children:[(0,a.jsxs)(R.$,{variant:"grid"===S?"secondary":"ghost",size:"sm",onClick:()=>{E("grid"),T(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","grid"===S?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,a.jsx)(tq.A,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),(0,a.jsxs)(R.$,{variant:"list"===S?"secondary":"ghost",size:"sm",onClick:()=>{E("list"),T(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","list"===S?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,a.jsx)(tB.A,{className:"h-3.5 w-3.5 mr-1.5"}),"List"]})]})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:[p&&(0,a.jsx)(eJ.Fc,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:(0,a.jsx)(eJ.TN,{className:"text-red-800 font-medium",children:p})}),x?(0,a.jsx)("div",{className:"flex items-center justify-center py-24",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-5",children:[(0,a.jsx)("div",{className:"h-12 w-12 border-4 border-primary/30 border-t-primary rounded-full animate-spin"}),(0,a.jsx)("div",{className:"text-lg text-foreground font-semibold",children:"Discovering servers..."}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading registry entries"})]})}):0===m.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[(0,a.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:(0,a.jsx)(tz.A,{className:"h-14 w-14 text-muted-foreground/60 mx-auto"})}),(0,a.jsx)("div",{className:"text-xl font-bold text-foreground mb-3",children:0===d.length?"No servers available in the registry":"No servers match your search"}),(0,a.jsx)("div",{className:"text-base text-muted-foreground/80 mb-6 max-w-md",children:0===d.length?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),N&&(0,a.jsxs)(R.$,{variant:"outline",onClick:()=>A(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[(0,a.jsx)(e4.A,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):(0,a.jsx)("div",{className:(0,j.cn)("grid"===S?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:m.map((e,t)=>{let s=I===e.id,r=e.description&&e.description.length>100;return"grid"===S?(0,a.jsx)(tF,{className:(0,j.cn)("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",s&&"ring-1 ring-primary/20 border-primary/40 shadow-lg -translate-y-0.5"),style:{animationDelay:"".concat(Math.min(30*t,300),"ms")},children:(0,a.jsxs)("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>T(s?null:e.id),children:[(0,a.jsx)(t_,{className:"pb-3 flex-shrink-0",children:(0,a.jsxs)("div",{className:"flex items-start gap-3 mb-3",children:[(0,a.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,a.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:e.icon||"⚡"}),e.isInstalled&&(0,a.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:(0,a.jsx)(G.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(tP,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-snug line-clamp-2",children:e.name}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.isOfficial&&(0,a.jsxs)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[(0,a.jsx)(e2.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),e.category&&(0,a.jsx)(e8.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",P(e.category)),children:e.category})]})]})]})}),(0,a.jsxs)(tM,{className:"pt-0 flex flex-col flex-1",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",s?"":"line-clamp-3"),children:e.description}),s&&(0,a.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:[e.author&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,a.jsx)(t$.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("span",{className:"text-muted-foreground/70",children:["by"," "]}),(0,a.jsx)("span",{className:"font-medium text-foreground",children:e.author})]})]}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.tags.slice(0,6).map(e=>(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:e},e)),e.tags.length>6&&(0,a.jsxs)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20",children:["+",e.tags.length-6]})]}),e.homepage&&(0,a.jsxs)("a",{href:e.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:e=>e.stopPropagation(),children:[(0,a.jsx)(tW.A,{className:"h-3 w-3"}),"Documentation"]})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border/30 flex-shrink-0 mt-auto",children:[r&&(0,a.jsx)(R.$,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-foreground p-0 h-auto font-medium -ml-1",children:s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(w.A,{className:"h-3 w-3 mr-1"}),"Less"]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.A,{className:"h-3 w-3 mr-1"}),"More"]})}),(0,a.jsx)("div",{className:"ml-auto",children:(0,a.jsx)(R.$,{onClick:t=>{t.stopPropagation(),_(e)},disabled:e.isInstalled||g===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 transition-all font-semibold text-sm shadow-sm",g===e.id&&"opacity-70",e.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!e.isInstalled&&"bg-primary hover:bg-primary/90"),children:g===e.id?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"Adding"})]}):e.isInstalled?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(G.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"Added"})]}):(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(e5.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"Add"})]})})})]})]})]})},e.id):(0,a.jsx)(tF,{className:(0,j.cn)("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",s&&"border-primary/40 shadow-md -translate-y-0.5"),onClick:()=>T(s?null:e.id),children:(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)("div",{className:"flex items-start gap-4",children:[(0,a.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,a.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:e.icon||"⚡"}),e.isInstalled&&(0,a.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:(0,a.jsx)(G.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0 space-y-2.5",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,a.jsx)("h3",{className:"text-base font-semibold text-foreground group-hover:text-primary transition-colors leading-snug",children:e.name}),r&&(0,a.jsx)(k.A,{className:(0,j.cn)("h-3.5 w-3.5 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",s&&"rotate-180 text-muted-foreground")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.isOfficial&&(0,a.jsxs)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 border-blue-200/60 font-medium",children:[(0,a.jsx)(e2.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),e.category&&(0,a.jsx)(e8.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",P(e.category)),children:e.category})]})]}),(0,a.jsx)(R.$,{onClick:t=>{t.stopPropagation(),_(e)},disabled:e.isInstalled||g===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",g===e.id&&"opacity-70",e.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!e.isInstalled&&"bg-primary hover:bg-primary/90"),children:g===e.id?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"Adding"})]}):e.isInstalled?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(G.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"Added"})]}):(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(e5.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"Add"})]})})]}),(0,a.jsx)("div",{children:(0,a.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",s?"":"line-clamp-2"),children:e.description})}),s&&(0,a.jsxs)("div",{className:"space-y-3 pt-3 border-t border-border/30 animate-in slide-in-from-top-2 duration-200",children:[e.author&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,a.jsx)(t$.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("span",{className:"text-muted-foreground/70",children:["by"," "]}),(0,a.jsx)("span",{className:"font-medium text-foreground",children:e.author})]})]}),e.tags&&e.tags.length>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5",children:e.tags.map(e=>(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:e},e))}),e.homepage&&(0,a.jsxs)("a",{href:e.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:e=>e.stopPropagation(),children:[(0,a.jsx)(tW.A,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},e.id)})})]})]})})}var tV=s(7028),tY=s(520),tG=s(2431),tQ=s(5858);let tH=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),tJ=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],tZ=[/^your[\s_-]?/,/^enter[\s_-]?/];function tX(e){return Object.values(e).some(e=>{if(!e||""===e.trim())return!0;let t=e.trim().toLowerCase();return!!(tH.has(t)||tZ.some(e=>e.test(t)))||tJ.some(e=>t.includes(e))})}function t0(e){var t,s,r,a,n,i,l,o;let d=null!=(t=e.config.timeout)?t:3e4;switch(e.config.type){case"stdio":return{type:"stdio",command:null!=(s=e.config.command)?s:"",args:null!=(r=e.config.args)?r:[],env:null!=(a=e.config.env)?a:{},timeout:d,connectionMode:"lenient"};case"sse":return{type:"sse",url:null!=(n=e.config.url)?n:"",headers:null!=(i=e.config.headers)?i:{},timeout:d,connectionMode:"lenient"};default:return{type:"http",url:null!=(l=e.config.url)?l:"",headers:null!=(o=e.config.headers)?o:{},timeout:d,connectionMode:"lenient"}}}function t1(e){let{isOpen:t,onClose:s,onOpenConnectModal:r,onOpenConnectWithPrefill:i,onServerConnected:l,variant:o,refreshTrigger:d}=e,c=(0,tp.st)(),[m,u]=(0,n.useState)(null),[x,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(!1),[g,b]=(0,n.useState)(!1),{data:y=[],isLoading:w,error:A,refetch:S}=(0,v.QF)(t),{data:E=[],isLoading:I,error:D}=(0,v.OV)(m,t&&!!m),F=(0,v.Mb)(),_=(0,v.KC)(),P=(0,v.Ix)();(0,n.useEffect)(()=>{if(y.length>0&&!m){let e=y.find(e=>"connected"===e.status);u((null==e?void 0:e.id)||y[0].id)}},[y,m]);let M=async e=>{let t=t0(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tX(t.env||{}),r=("sse"===t.type||"http"===t.type)&&Object.keys(t.headers||{}).length>0&&tX(t.headers||{});if(s||r)return"function"==typeof i&&i({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:()=>f(!1)}),"requires-input";try{b(!0),await F.mutateAsync({name:e.name,config:t,persistToAgent:!1});try{await tD.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry after server install:",e)}return c.trackMCPServerConnected({serverName:e.name,transportType:t.type}),f(!1),null==l||l(e.name),"connected"}catch(e){throw Error(e.message||"Failed to install server")}finally{b(!1)}},z=async e=>{let t=y.find(t=>t.id===e);if(t&&window.confirm('Are you sure you want to remove server "'.concat(t.name,'"?')))try{m===e&&u(null),await _.mutateAsync(e);try{let t=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-"),s=t(e),r=(await tD.getEntries()).find(e=>[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>t(String(e))).includes(s));r&&await tD.setInstalled(r.id,!1)}catch(e){console.warn("Failed to update registry installed state on delete:",e)}try{await tD.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry status after server deletion:",e)}}catch(e){console.error("Delete server error:",e)}},U=async e=>{let t=y.find(t=>t.id===e);if(t&&window.confirm('Restart server "'.concat(t.name,'"?')))try{await P.mutateAsync(e);try{await tD.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry status after server restart:",e)}}catch(e){console.error("Restart server error:",e)}};(0,n.useEffect)(()=>{d&&t&&S()},[d,t,S]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("\uD83D\uDD17 Server connected:",(null==e?void 0:e.detail)||{}),S()},s=e=>{console.log("\uD83D\uDCBE Resource cache invalidated for server panel:",(null==e?void 0:e.detail)||{})};return window.addEventListener("mcp:server-connected",e),window.addEventListener("resource:cache-invalidated",s),()=>{window.removeEventListener("mcp:server-connected",e),window.removeEventListener("resource:cache-invalidated",s)}},[t,S]);let q=y.find(e=>e.id===m);return"inline"===(null!=o?o:"overlay")?(0,a.jsxs)("aside",{className:"h-full w-full flex flex-col bg-card",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border/50 bg-card/50 backdrop-blur-sm",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,a.jsx)("div",{className:"flex items-center space-x-1",children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>S(),disabled:w,className:"h-8 w-8 p-0",children:(0,a.jsx)(tV.A,{className:(0,j.cn)("h-3.5 w-3.5",w&&"animate-spin")})})})]}),(0,a.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,a.jsxs)(R.$,{onClick:()=>f(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,a.jsx)(tY.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,a.jsxs)(R.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,a.jsx)(e6.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,a.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",y.length,")"]})}),w&&(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tV.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),A&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(N.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:(null==A?void 0:A.message)||"Failed to load servers"})]})]})}),!w&&0===y.length&&!A&&(0,a.jsxs)("div",{className:"text-center py-8",children:[(0,a.jsx)(tz.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),y.map(e=>(0,a.jsx)("div",{onClick:()=>u(e.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",m===e.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===e.status?"bg-green-500":"error"===e.status?"bg-red-500":"bg-yellow-500")}),(0,a.jsx)("h4",{className:"text-sm font-medium truncate",children:e.name})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:e.status})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[P.isPending&&P.variables===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Restarting ".concat(e.name,"…")})}):(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),U(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":"Restart server ".concat(e.name),disabled:_.isPending&&_.variables===e.id,children:(0,a.jsx)(tG.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{side:"top",children:"Restart server"})]}),_.isPending&&_.variables===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Removing ".concat(e.name,"…")})}):(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),z(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":"Remove server ".concat(e.name),disabled:P.isPending&&P.variables===e.id,children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{side:"top",children:"Remove server"})]})]})]})},e.id))]}),q&&(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,a.jsxs)("button",{onClick:()=>h(!x),className:"flex items-center justify-between w-full text-left",children:[(0,a.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Available Tools ",E.length>0&&"(".concat(E.length,")")]}),(0,a.jsx)(k.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",x&&"rotate-180")})]})}),x&&(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[I&&(0,a.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),D&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(N.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:(null==D?void 0:D.message)||"Failed to load tools"})]})]})}),!I&&0===E.length&&!D&&"connected"===q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(tQ.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(N.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),E.map(e=>{var t;return(0,a.jsxs)("div",{className:"p-3 rounded-lg border border-border/50 bg-background hover:bg-muted/30 transition-colors mb-2 last:mb-0",children:[(0,a.jsx)("h4",{className:"text-sm font-medium mb-1",children:e.name}),e.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:e.description}),(null==(t=e.inputSchema)?void 0:t.properties)&&(0,a.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(e.inputSchema.properties).slice(0,3).map(e=>(0,a.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:e},e)),Object.keys(e.inputSchema.properties).length>3&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(e.inputSchema.properties).length-3," ","more"]})]})]},e.name)})]})]})]}),(0,a.jsx)(tK,{isOpen:p,onClose:()=>f(!1),onInstallServer:M,onOpenConnectModal:r,disableClose:g})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",t?"opacity-100":"opacity-0 pointer-events-none"),onClick:s}),(0,a.jsxs)("aside",{className:(0,j.cn)("fixed top-0 right-0 z-40 h-screen w-80 bg-card border-l border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",t?"translate-x-0":"translate-x-full"),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border/50 bg-card/50 backdrop-blur-sm",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>S(),disabled:w,className:"h-8 w-8 p-0",children:(0,a.jsx)(tV.A,{className:(0,j.cn)("h-3.5 w-3.5",w&&"animate-spin")})}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:(0,a.jsx)(C.A,{className:"h-3.5 w-3.5"})})]})]}),(0,a.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,a.jsxs)(R.$,{onClick:()=>f(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,a.jsx)(tY.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,a.jsxs)(R.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,a.jsx)(e6.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,a.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",y.length,")"]})}),w&&(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tV.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),A&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(N.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:(null==A?void 0:A.message)||"Failed to load servers"})]})]})}),!w&&0===y.length&&!A&&(0,a.jsxs)("div",{className:"text-center py-8",children:[(0,a.jsx)(tz.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),y.map(e=>(0,a.jsx)("div",{onClick:()=>u(e.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",m===e.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===e.status?"bg-green-500":"error"===e.status?"bg-red-500":"bg-yellow-500")}),(0,a.jsx)("h4",{className:"text-sm font-medium truncate",children:e.name})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:e.status})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[P.isPending&&P.variables===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Restarting ".concat(e.name,"…")})}):(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),U(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":"Restart server ".concat(e.name),disabled:_.isPending&&_.variables===e.id,children:(0,a.jsx)(tG.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{side:"top",children:"Restart server"})]}),_.isPending&&_.variables===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Removing ".concat(e.name,"…")})}):(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),z(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":"Remove server ".concat(e.name),disabled:P.isPending&&P.variables===e.id,children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{side:"top",children:"Remove server"})]})]})]})},e.id))]}),q&&(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,a.jsxs)("button",{onClick:()=>h(!x),className:"flex items-center justify-between w-full text-left",children:[(0,a.jsx)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Available Tools"}),(0,a.jsx)(k.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",x&&"rotate-180")})]})}),x&&(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[I&&(0,a.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tV.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),D&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(N.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:(null==D?void 0:D.message)||"Failed to load tools"})]})]})}),!I&&0===E.length&&!D&&"connected"===q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(tQ.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(N.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),E.map(e=>{var t;return(0,a.jsxs)("div",{className:"p-3 rounded-lg border border-border/50 bg-background hover:bg-muted/30 transition-colors mb-2 last:mb-0",children:[(0,a.jsx)("h4",{className:"text-sm font-medium mb-1",children:e.name}),e.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:e.description}),(null==(t=e.inputSchema)?void 0:t.properties)&&(0,a.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(e.inputSchema.properties).slice(0,3).map(e=>(0,a.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:e},e)),Object.keys(e.inputSchema.properties).length>3&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(e.inputSchema.properties).length-3," ","more"]})]})]},e.name)})]})]})]}),(0,a.jsx)(tK,{isOpen:p,onClose:()=>f(!1),onInstallServer:M,onOpenConnectModal:r,disableClose:g})]})]})}var t2=s(282),t5=s(32);let t4=function(e){let{onClick:t,className:s,variant:r="outline",side:n="bottom"}=e;return(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:r,size:"sm",onClick:t,className:["h-8 w-8 p-0",s].filter(Boolean).join(" "),"aria-label":"New chat",children:(0,a.jsx)(e5.A,{className:"h-4 w-4"})})}),(0,a.jsx)(O,{side:n,children:"New Chat (⌘K)"})]})})};function t3(e){return e.sort((e,t)=>{let s=e.lastActivity?new Date(e.lastActivity).getTime():0;return(t.lastActivity?new Date(t.lastActivity).getTime():0)-s})}function t8(e){var t,s;let{isOpen:r,onClose:i,currentSessionId:o,onSessionChange:d,returnToWelcome:c,variant:p="overlay",onSearchOpen:f,onNewChat:v}=e,b=(0,l.jE)(),[y,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)(""),[S,E]=(0,n.useState)(!1),[D,F]=(0,n.useState)(null),{data:_=[],isLoading:P,error:M}=function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];return(0,m.I)({queryKey:x.l.sessions.all,queryFn:async()=>{let e=await h.S.api.sessions.$get();return(await e.json()).sessions},enabled:e})}(r),z=t3([..._]),U=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let{sessionId:t}=e,s=await h.S.api.sessions.$post({json:{sessionId:(null==t?void 0:t.trim())||void 0}});return(await s.json()).session},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.sessions.all})}})}(),q=g();(0,n.useEffect)(()=>{let e=()=>{b.invalidateQueries({queryKey:x.l.sessions.all})},t=e=>{var t;let s=null==(t=e.detail)?void 0:t.sessionId;s&&b.setQueryData(x.l.sessions.all,function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.some(e=>e.id===s)?t3(e.map(e=>e.id===s?{...e,messageCount:e.messageCount+1,lastActivity:Date.now()}:e)):t3([{id:s,createdAt:Date.now(),lastActivity:Date.now(),messageCount:1,title:null},...e])})},s=e=>{var t;let s=null==(t=e.detail)?void 0:t.sessionId;s&&b.setQueryData(x.l.sessions.all,function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return t3(e.map(e=>e.id===s?{...e,messageCount:e.messageCount+1,lastActivity:Date.now()}:e))})},r=e=>{var t,s;let r=null==(t=e.detail)?void 0:t.sessionId,a=null==(s=e.detail)?void 0:s.title;r&&a&&b.setQueryData(x.l.sessions.all,function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.map(e=>e.id===r?{...e,title:a}:e)})};return window.addEventListener("dexto:message",t),window.addEventListener("dexto:response",s),window.addEventListener("session:title-updated",r),window.addEventListener("dexto:agentSwitched",e),()=>{window.removeEventListener("dexto:message",t),window.removeEventListener("dexto:response",s),window.removeEventListener("session:title-updated",r),window.removeEventListener("dexto:agentSwitched",e)}},[b,o]);let B=async()=>{let e=await U.mutateAsync({sessionId:k.trim()||void 0});A(""),w(!1),d(e.id)},$=async e=>{await q.mutateAsync({sessionId:e}),o===e&&c()},W=async()=>{D&&(await q.mutateAsync({sessionId:D}),o===D&&c(),E(!1),F(null))},K=(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:[(0,a.jsx)("div",{className:"flex items-center space-x-2",children:(0,a.jsx)("h2",{id:"sessionpanel-title",className:"text-base font-semibold",children:"Chat History"})}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[f&&(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"outline",size:"sm",onClick:f,className:"h-7 w-7 p-0","aria-label":"Search conversations",children:(0,a.jsx)(e4.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{children:"Search conversations (⌘⇧S)"})]})}),v&&(0,a.jsx)(t4,{onClick:v,variant:"outline"}),"overlay"===p&&(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:i,className:"h-7 w-7 p-0","aria-label":"Close panel",children:(0,a.jsx)(C.A,{className:"h-3.5 w-3.5"})})]})]}),M&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eJ.Fc,{variant:"destructive",children:[(0,a.jsx)(N.A,{className:"h-4 w-4"}),(0,a.jsx)(eJ.TN,{children:M.message})]})}),(0,a.jsx)(t2.F,{className:"flex-1",children:P?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tV.A,{className:"h-6 w-6 animate-spin"})}):0===z.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground px-4",children:[(0,a.jsx)(t5.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,a.jsx)("p",{children:"No chat history"}),(0,a.jsx)("p",{className:"text-sm",children:"Start a conversation to see it here"})]}):(0,a.jsx)("div",{className:"px-3 py-2 space-y-0.5",children:(0,a.jsx)(I,{children:z.map(e=>{var t;let s=e.title&&e.title.trim().length>0?e.title:e.id,r=o===e.id;return(0,a.jsxs)(T,{delayDuration:150,children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{className:r?"group relative px-3 py-3 rounded-lg bg-muted/40 hover:bg-muted/60 transition-colors cursor-pointer":"group relative px-3 py-2.5 rounded-lg hover:bg-muted/30 transition-colors cursor-pointer",role:"button",tabIndex:0,"aria-current":r?"page":void 0,onClick:()=>d(e.id),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),d(e.id))},children:(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("div",{className:"flex items-center gap-2.5 flex-1 min-w-0",children:(0,a.jsx)("h3",{className:r?"font-semibold text-sm truncate":"font-normal text-sm truncate text-muted-foreground",children:s})}),(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:(e=>{if(!e)return"Unknown";let t=Date.now()-e,s=Math.floor(t/6e4),r=Math.floor(t/36e5),a=Math.floor(t/864e5);return s<1?"Just now":s<60?"".concat(s,"m ago"):r<24?"".concat(r,"h ago"):"".concat(a,"d ago")})(e.lastActivity)}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),e.messageCount>0?(F(e.id),E(!0)):$(e.id)},disabled:q.isPending&&(null==(t=q.variables)?void 0:t.sessionId)===e.id,className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":e.messageCount>0?"Delete conversation":"Delete chat",title:"Delete",children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"})})]})]})})}),(0,a.jsx)(O,{side:"right",align:"center",children:(0,a.jsxs)("div",{className:"text-xs space-y-1",children:[(0,a.jsx)("div",{className:"font-mono",children:e.id}),(0,a.jsxs)("div",{className:"text-muted-foreground",children:[e.messageCount," messages"]})]})})]},e.id)})})})}),(0,a.jsx)(eH.lG,{open:y,onOpenChange:w,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eH.c7,{children:(0,a.jsx)(eH.L3,{children:"Start New Chat"})}),(0,a.jsx)("div",{className:"space-y-4",children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"sessionId",children:"Chat ID"}),(0,a.jsx)(eZ.p,{id:"sessionId",value:k,onChange:e=>A(e.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),(0,a.jsx)(R.$,{onClick:B,children:"Start Chat"})]})]})}),(0,a.jsx)(eH.lG,{open:S,onOpenChange:E,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsxs)(eH.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eH.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",D&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session:"," ",(0,a.jsx)("span",{className:"font-mono",children:D})]})]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>E(!1),children:"Cancel"}),(0,a.jsxs)(R.$,{variant:"destructive",onClick:W,disabled:q.isPending&&(null==(t=q.variables)?void 0:t.sessionId)===D,className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:q.isPending&&(null==(s=q.variables)?void 0:s.sessionId)===D?"Deleting...":"Delete Conversation"})]})]})]})})]});return"inline"===p?(0,a.jsx)("div",{className:"h-full w-full flex flex-col bg-card",children:K}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",r?"opacity-100":"opacity-0 pointer-events-none"),onClick:i}),(0,a.jsx)("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:(0,j.cn)("fixed top-0 left-0 z-40 h-screen w-80 bg-card border-r border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",r?"translate-x-0":"-translate-x-full"),children:K})]})}var t6=s(2776),t7=s(7278);function t9(e){let{isOpen:t,onClose:s,variant:r="modal"}=e,[i,o]=(0,n.useState)(""),[d,c]=(0,n.useState)(!1),[p,f]=(0,n.useState)(!1),[g,v]=(0,n.useState)(null),{data:b=[],isLoading:y,error:w}=function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];return(0,m.I)({queryKey:x.l.memories.all,queryFn:async()=>{let e=await h.S.api.memory.$get({query:{}});return(await e.json()).memories},enabled:e})}(t),k=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let{memoryId:t}=e;return await h.S.api.memory[":id"].$delete({param:{id:t}}),t},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.memories.all})}})}(),C=async e=>{await k.mutateAsync({memoryId:e}),f(!1),v(null)},A=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:120;return e.length<=t?e:e.slice(0,t)+"..."},S=b.filter(e=>{var t;if(!i.trim())return!0;let s=i.toLowerCase();return e.content.toLowerCase().includes(s)||(null==(t=e.tags)?void 0:t.some(e=>e.toLowerCase().includes(s)))}),E=(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsx)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(V.A,{className:"h-4 w-4"}),(0,a.jsx)("h2",{className:"text-base font-semibold",children:"Memories"}),(0,a.jsx)(e8.E,{variant:"secondary",className:"text-xs",children:b.length})]})}),(0,a.jsx)("div",{className:"p-3 border-b border-border/50",children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(e4.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,a.jsx)(eZ.p,{placeholder:"Search memories...",value:i,onChange:e=>o(e.target.value),className:"pl-8 h-8 text-sm"})]}),(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"outline",size:"sm",onClick:()=>c(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:(0,a.jsx)(e5.A,{className:"h-4 w-4"})})}),(0,a.jsx)(O,{children:"Create Memory"})]})})]})}),w&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eJ.Fc,{variant:"destructive",children:[(0,a.jsx)(N.A,{className:"h-4 w-4"}),(0,a.jsx)(eJ.TN,{children:w.message})]})}),(0,a.jsx)(t2.F,{className:"flex-1 p-4",children:(0,a.jsx)("div",{className:"space-y-2",children:y?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tV.A,{className:"h-6 w-6 animate-spin"})}):0===S.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,a.jsx)(V.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),i.trim()?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"No memories found"}),(0,a.jsx)("p",{className:"text-sm",children:"Try a different search term"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"No memories yet"}),(0,a.jsx)("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):S.map(e=>{var t,s,r;return(0,a.jsx)("div",{className:(0,j.cn)("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",(null==(t=e.metadata)?void 0:t.pinned)&&"ring-1 ring-primary/30 bg-primary/5"),children:(0,a.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0 space-y-2",children:[(0,a.jsx)("p",{className:"text-sm leading-relaxed",children:A(e.content)}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,a.jsx)(t6.A,{className:"h-3 w-3 text-muted-foreground"}),e.tags.map((e,t)=>(0,a.jsx)(e8.E,{variant:"outline",className:"text-xs px-1.5 py-0",children:e},t))]}),(0,a.jsxs)("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(t7.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:function(e){let t,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en",a=e-Date.now(),n=Math.abs(a);return n<6e4?(t=Math.round(a/1e3),s="second"):n<36e5?(t=Math.round(a/6e4),s="minute"):n<864e5?(t=Math.round(a/36e5),s="hour"):n<6048e5?(t=Math.round(a/864e5),s="day"):n<2592e6?(t=Math.round(a/6048e5),s="week"):n<31536e6?(t=Math.round(a/2592e6),s="month"):(t=Math.round(a/31536e6),s="year"),new Intl.RelativeTimeFormat(r,{numeric:"auto"}).format(t,s)}(e.updatedAt)})]}),(null==(s=e.metadata)?void 0:s.source)&&(0,a.jsx)(e8.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:e.metadata.source}),(null==(r=e.metadata)?void 0:r.pinned)&&(0,a.jsx)(e8.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-1",children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>{v(e),f(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5 text-destructive"})})})]})},e.id)})})}),(0,a.jsx)(tI,{open:d,onClose:()=>c(!1)}),(0,a.jsx)(eH.lG,{open:p,onOpenChange:f,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsxs)(eH.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Memory"})]}),(0,a.jsxs)(eH.rr,{children:["This will permanently delete this memory. This action cannot be undone.",g&&(0,a.jsx)("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:A(g.content,100)})]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>f(!1),children:"Cancel"}),(0,a.jsxs)(R.$,{variant:"destructive",onClick:()=>g&&C(g.id),disabled:k.isPending,className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:k.isPending?"Deleting...":"Delete Memory"})]})]})]})})]});return"inline"===r?(0,a.jsx)("div",{className:"h-full",children:E}):(0,a.jsx)(eH.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[(0,a.jsx)(eH.c7,{className:"sr-only",children:(0,a.jsx)(eH.L3,{children:"Memories"})}),E]})})}var se=(e=>(e.TOOL_CONFIRMATION="tool_confirmation",e.COMMAND_CONFIRMATION="command_confirmation",e.ELICITATION="elicitation",e.CUSTOM="custom",e))(se||{}),st=(e=>(e.APPROVED="approved",e.DENIED="denied",e.CANCELLED="cancelled",e))(st||{}),ss=(e=>(e.USER_DENIED="user_denied",e.SYSTEM_DENIED="system_denied",e.TIMEOUT="timeout",e.USER_CANCELLED="user_cancelled",e.SYSTEM_CANCELLED="system_cancelled",e.VALIDATION_FAILED="validation_failed",e.ELICITATION_DISABLED="elicitation_disabled",e))(ss||{});function sr(e){let{onApprovalRequest:t,onApprove:s,onDeny:r,onHandlersReady:a}=e,[i,l]=(0,n.useState)(null),{currentSessionId:o}=(0,d.v)(),{mutateAsync:c}=(0,u.n)({mutationFn:async e=>{let{approvalId:t,...s}=e,r=await h.S.api.approvals[":approvalId"].$post({param:{approvalId:t},json:s,header:{}});return await r.json()}}),m=n.useRef([]);(0,n.useEffect)(()=>{null==t||t(i)},[i,t]),(0,n.useEffect)(()=>{let e=e=>{try{let t,s=e.detail;if(!s)return void console.error("[WebUI] Invalid approval request event: missing detail");if(s.sessionId&&o&&s.sessionId!==o)return;let{approvalId:r,type:a,timestamp:n,metadata:d={},sessionId:c}=s;t="tool_confirmation"===a?{approvalId:r,type:a,toolName:d.toolName||"unknown",args:d.args||{},description:d.description,timestamp:n||new Date().toISOString(),sessionId:c,metadata:d}:"command_confirmation"===a?{approvalId:r,type:a,toolName:d.toolName||"unknown",command:d.command||"",originalCommand:d.originalCommand,timestamp:n||new Date().toISOString(),sessionId:c,metadata:d}:{approvalId:r,type:a||"elicitation",timestamp:n||new Date().toISOString(),sessionId:c,metadata:d},console.debug("[WebUI] Received approvalRequest via Event: ".concat(JSON.stringify(t))),i?m.current.push(t):l(t)}catch(e){console.error("[WebUI] Error handling approval request event:",e)}};return window.addEventListener("approval:request",e),()=>{window.removeEventListener("approval:request",e)}},[i,o]),(0,n.useEffect)(()=>{let e=e=>{try{let t=e.detail;if(!t||!t.approvalId)return void console.error("[WebUI] Invalid approval response event: missing detail");if(t.sessionId&&o&&t.sessionId!==o)return;if(console.debug("[WebUI] Received approvalResponse: ".concat(t.approvalId,", status: ").concat(t.status,", reason: ").concat(t.reason)),i&&i.approvalId===t.approvalId&&"cancelled"===t.status&&(console.info("[WebUI] Approval ".concat(t.approvalId," timed out or was cancelled (").concat(t.reason,")")),l(null),m.current.length>0)){let e=m.current.shift();setTimeout(()=>{l(e)},100)}}catch(e){console.error("[WebUI] Error handling approval response event:",e)}};return window.addEventListener("approval:response",e),()=>{window.removeEventListener("approval:response",e)}},[i,o]);let x=(0,n.useCallback)(async(e,t,s)=>{if(!i)return;let{approvalId:r}=i;console.debug("[WebUI] Sending approval response for ".concat(r,": ").concat(e?"approved":"denied"));try{await c({approvalId:r,status:e?st.APPROVED:st.DENIED,...e&&t?{formData:t}:{},...e&&void 0!==s?{rememberChoice:s}:{}})}catch(e){console.error("[WebUI] Failed to send approval response: ".concat(e instanceof Error?e.message:String(e)));return}if(l(null),m.current.length>0){let e=m.current.shift();setTimeout(()=>{l(e)},100)}},[i,c]),p=(0,n.useCallback)((e,t)=>{x(!0,e,t),null==s||s(e,t)},[x,s]),f=(0,n.useCallback)(()=>{x(!1),null==r||r()},[x,r]);return(0,n.useEffect)(()=>{a&&a({onApprove:p,onDeny:f})},[p,f,a]),null}var sa=s(6676),sn=s(929),si=s(3885);function sl(e){var t;let{isOpen:s,onClose:r,onNavigateToSession:l}=e,[o,d]=(0,n.useState)(""),[c]=(0,sa.d7)(o,300),[u,p]=(0,n.useState)(0),{data:f,isLoading:g,error:v}=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:50,r=!(arguments.length>3)||void 0===arguments[3]||arguments[3];return(0,m.I)({queryKey:x.l.search.messages(e,t,s),queryFn:async()=>{let r=await h.S.api.search.messages.$get({query:{q:e,limit:s,...t&&{sessionId:t}}});return await r.json()},enabled:r&&e.trim().length>0,staleTime:3e4})}(c,void 0,10,s),b=(null==f?void 0:f.results)||[],y=null!=(t=null==v?void 0:v.message)?t:null;(0,n.useEffect)(()=>{u>=b.length&&b.length>0?p(b.length-1):0===b.length&&p(0)},[b.length,u]);let N=(0,n.useCallback)(e=>{l(e.sessionId,e.messageIndex),r()},[l,r]);return(0,n.useEffect)(()=>{s&&(d(""),p(0))},[s]),(0,i.vC)("down",()=>{p(e=>Math.min(e+1,b.length-1))},{enabled:s,preventDefault:!0},[s,b.length]),(0,i.vC)("up",()=>{p(e=>Math.max(e-1,0))},{enabled:s,preventDefault:!0},[s]),(0,i.vC)("enter",()=>{b[u]&&(N(b[u]),p(0))},{enabled:s,preventDefault:!0},[s,b,u,N]),(0,i.vC)("escape",()=>{r()},{enabled:s,preventDefault:!0},[s,r]),(0,a.jsx)(eH.lG,{open:s,onOpenChange:e=>!e&&r(),children:(0,a.jsxs)(eH.Cf,{className:"max-w-2xl p-0 top-[20%] transform translate-y-0",children:[(0,a.jsx)(eH.c7,{children:(0,a.jsx)(eH.L3,{className:"sr-only",children:"Search Conversations"})}),(0,a.jsxs)("div",{className:"flex flex-col max-h-[70vh]",children:[(0,a.jsx)("div",{className:"p-6 pb-4",children:(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(e4.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),(0,a.jsx)(eZ.p,{placeholder:"Search conversations...",value:o,onChange:e=>d(e.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),(0,a.jsx)("div",{className:"flex-1 overflow-hidden border-t",children:g?(0,a.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,a.jsx)(tV.A,{className:"h-6 w-6 animate-spin mr-3"}),(0,a.jsx)("span",{className:"text-muted-foreground",children:"Searching..."})]}):v?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)(e4.A,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),(0,a.jsx)("p",{className:"text-destructive font-medium",children:"Search Error"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:y}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):(0,a.jsx)(t2.F,{className:"h-full",children:(0,a.jsx)("div",{className:"p-2",children:b.length>0?(0,a.jsx)("div",{className:"space-y-1",children:b.map((e,t)=>(0,a.jsxs)("div",{className:(0,j.cn)("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",t===u?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>N(e),children:[(0,a.jsx)("div",{className:"flex-shrink-0 mt-1",children:(0,a.jsx)(e8.E,{className:(0,j.cn)("text-xs",(e=>{switch(e){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"}})(e.message.role)),children:(e=>{switch(e){case"user":return(0,a.jsx)($.A,{className:"w-4 h-4"});case"assistant":return(0,a.jsx)(W.A,{className:"w-4 h-4"});case"system":return(0,a.jsx)(sn.A,{className:"w-4 h-4"});default:return(0,a.jsx)(si.A,{className:"w-4 h-4"})}})(e.message.role)})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:e.sessionId.length>20?"".concat(e.sessionId.slice(0,20),"..."):e.sessionId}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:e.message.role})]}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground line-clamp-2",children:((e,t)=>{if(!t)return e;let s=t.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),r=RegExp("(".concat(s,")"),"gi");return e.split(r).map((e,s)=>e.toLowerCase()===t.toLowerCase()?(0,a.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:e},s):e)})(e.context,c)})]}),(0,a.jsx)(Y.A,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},t))}):c?(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(e4.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(e4.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),(0,a.jsxs)("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↑"}),(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↓"}),(0,a.jsx)("span",{children:"to navigate"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Enter"}),(0,a.jsx)("span",{children:"to select"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Esc"}),(0,a.jsx)("span",{children:"to close"})]})]})]})})})})]})]})})}var so=s(8977),sd=s(4558);function sc(e){let{value:t,onChange:s,onValidate:r,readOnly:i=!1,height:l="100%"}=e,o=(0,n.useRef)(null);return(0,n.useEffect)(()=>{o.current&&r&&o.current.getModel()},[r]),(0,a.jsx)(sd.Ay,{height:l,defaultLanguage:"yaml",value:t,onChange:e=>{void 0!==e&&s(e)},onMount:e=>{o.current=e,e.updateOptions({minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:"on",renderLineHighlight:"all",folding:!0,automaticLayout:!0})},theme:"vs-dark",options:{readOnly:i,wordWrap:"on",tabSize:2}})}function sm(e){let{isValidating:t,isValid:s,errors:r,warnings:n,hasUnsavedChanges:i}=e;return(0,a.jsxs)("div",{className:"border-t border-border bg-background px-4 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,a.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:t?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:"Validating..."})]}):s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(G.A,{className:"h-4 w-4 text-green-500 flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Valid configuration",i&&" (unsaved changes)"]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tv.A,{className:"h-4 w-4 text-destructive flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-destructive",children:[r.length," ",1===r.length?"error":"errors"]})]})}),n.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(N.A,{className:"h-4 w-4 text-yellow-500 flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-yellow-500",children:[n.length," ",1===n.length?"warning":"warnings"]})]})]}),r.length>0&&(0,a.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:r.map((e,t)=>(0,a.jsxs)("div",{className:"text-xs bg-destructive/10 text-destructive rounded px-2 py-1.5 flex items-start gap-2",children:[(0,a.jsx)(tv.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[e.path&&(0,a.jsxs)("span",{className:"font-medium",children:[e.path,": "]}),e.message,e.line&&(0,a.jsxs)("span",{className:"text-muted-foreground ml-1",children:["(line ",e.line,e.column&&":".concat(e.column),")"]})]})]},t))}),n.length>0&&0===r.length&&(0,a.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:n.map((e,t)=>(0,a.jsxs)("div",{className:"text-xs bg-yellow-500/10 text-yellow-600 dark:text-yellow-500 rounded px-2 py-1.5 flex items-start gap-2",children:[(0,a.jsx)(N.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("span",{className:"font-medium",children:[e.path,": "]}),e.message]})]},t))})]})}function su(e){let{value:t,onChange:s,onValidate:r,isValidating:n=!1,isValid:i=!0,errors:l=[],warnings:o=[],hasUnsavedChanges:d=!1}=e;return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,a.jsx)(sc,{value:t,onChange:s,onValidate:r,height:"100%"})}),(0,a.jsx)(sm,{isValidating:n,isValid:i,errors:l,warnings:o,hasUnsavedChanges:d})]})}function sx(e){let{title:t,children:s,defaultOpen:r=!0,open:i,onOpenChange:l,errorCount:o=0,sectionErrors:d=[],className:c}=e,[m,u]=(0,n.useState)(r),x=void 0!==i,h=x?i:m;return(0,a.jsxs)("div",{className:(0,j.cn)("border border-border rounded-lg overflow-hidden",c),children:[(0,a.jsxs)("button",{onClick:()=>{let e=!h;x?null==l||l(e):u(e)},className:"w-full flex items-center justify-between px-4 py-3 bg-muted/50 hover:bg-muted transition-colors text-left",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:t}),o>0&&(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsxs)("span",{className:"inline-flex items-center justify-center px-2 py-0.5 text-xs font-medium bg-destructive text-destructive-foreground rounded-full cursor-help",children:[o," ",1===o?"error":"errors"]})}),(0,a.jsx)(O,{side:"top",className:"max-w-sm",children:(0,a.jsx)("ul",{className:"space-y-1 text-left",children:d.map((e,t)=>(0,a.jsxs)("li",{children:["• ",e]},t))})})]})]}),(0,a.jsx)(k.A,{className:(0,j.cn)("h-4 w-4 transition-transform duration-200",h&&"transform rotate-180")})]}),h&&(0,a.jsx)("div",{className:"px-4 py-4 space-y-4",children:s})]})}var sh=s(1889),sp=s(6613);function sf(e){var t;let{value:s,onChange:r,errors:i={},open:l,onOpenChange:o,errorCount:d=0,sectionErrors:c=[]}=e,[m,u]=(0,n.useState)(!1),x=(e,t)=>{r({...s,[e]:t})};return(0,a.jsx)(sx,{title:"LLM Configuration",defaultOpen:!0,open:l,onOpenChange:o,errorCount:d,sectionErrors:c,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"provider",tooltip:"The LLM provider to use (e.g., OpenAI, Anthropic)",children:"Provider *"}),(0,a.jsxs)("select",{id:"provider",value:s.provider||"",onChange:e=>x("provider",e.target.value),"aria-invalid":!!i["llm.provider"],className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",children:[(0,a.jsx)("option",{value:"",children:"Select provider..."}),tx.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]}),i["llm.provider"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.provider"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"model",tooltip:"The specific model identifier (e.g., gpt-5, claude-sonnet-4-5-20250929)",children:"Model *"}),(0,a.jsx)(eZ.p,{id:"model",value:s.model||"",onChange:e=>x("model",e.target.value),placeholder:"e.g., gpt-5, claude-sonnet-4-5-20250929","aria-invalid":!!i["llm.model"]}),i["llm.model"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.model"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"apiKey",tooltip:"Use $ENV_VAR for environment variables or enter the API key directly",children:"API Key *"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(eZ.p,{id:"apiKey",type:m?"text":"password",value:null!=(t=s.apiKey)?t:"",onChange:e=>x("apiKey",e.target.value),placeholder:"$OPENAI_API_KEY or direct value","aria-invalid":!!i["llm.apiKey"],className:"pr-10"}),(0,a.jsx)("button",{type:"button",onClick:()=>u(!m),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-accent rounded transition-colors","aria-label":m?"Hide API key":"Show API key",children:m?(0,a.jsx)(sh.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(sp.A,{className:"h-4 w-4 text-muted-foreground"})})]}),i["llm.apiKey"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.apiKey"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"router",tooltip:"LLM routing backend: 'vercel' uses Vercel AI SDK, 'in-built' uses provider-specific clients",children:"Router"}),(0,a.jsx)("select",{id:"router",value:s.router||"vercel",onChange:e=>x("router",e.target.value),"aria-invalid":!!i["llm.router"],className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",children:th.map(e=>(0,a.jsx)("option",{value:e,children:e},e))}),i["llm.router"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.router"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"maxIterations",tooltip:"Maximum number of agent reasoning iterations per turn",children:"Max Iterations"}),(0,a.jsx)(eZ.p,{id:"maxIterations",type:"number",value:void 0!==s.maxIterations?s.maxIterations:"",onChange:e=>{let t=e.target.value;if(""===t)x("maxIterations",void 0);else{let e=parseInt(t,10);isNaN(e)||x("maxIterations",e)}},min:"1",placeholder:"50","aria-invalid":!!i["llm.maxIterations"]}),i["llm.maxIterations"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxIterations"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"baseURL",tooltip:"Custom base URL for the LLM provider (optional, for proxies or custom endpoints)",children:"Base URL"}),(0,a.jsx)(eZ.p,{id:"baseURL",value:s.baseURL||"",onChange:e=>x("baseURL",e.target.value||void 0),placeholder:"https://api.openai.com/v1","aria-invalid":!!i["llm.baseURL"]}),i["llm.baseURL"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.baseURL"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"temperature",tooltip:"Controls randomness in responses (0.0 = deterministic, 1.0 = creative)",children:"Temperature"}),(0,a.jsx)(eZ.p,{id:"temperature",type:"number",value:void 0!==s.temperature?s.temperature:"",onChange:e=>x("temperature",e.target.value?parseFloat(e.target.value):void 0),min:"0",max:"1",step:"0.1",placeholder:"0.0 - 1.0","aria-invalid":!!i["llm.temperature"]}),i["llm.temperature"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.temperature"]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"maxInputTokens",tooltip:"Maximum input tokens to send to the model. If not specified, defaults to model's limit from registry, or 128,000 tokens for custom endpoints",children:"Max Input Tokens"}),(0,a.jsx)(eZ.p,{id:"maxInputTokens",type:"number",value:s.maxInputTokens||"",onChange:e=>x("maxInputTokens",e.target.value?parseInt(e.target.value,10):void 0),min:"1",placeholder:"Auto (128k fallback)","aria-invalid":!!i["llm.maxInputTokens"]}),i["llm.maxInputTokens"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxInputTokens"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"maxOutputTokens",tooltip:"Maximum output tokens the model can generate. If not specified, uses provider's default (typically 4,096 tokens)",children:"Max Output Tokens"}),(0,a.jsx)(eZ.p,{id:"maxOutputTokens",type:"number",value:s.maxOutputTokens||"",onChange:e=>x("maxOutputTokens",e.target.value?parseInt(e.target.value,10):void 0),min:"1",placeholder:"Auto (provider default)","aria-invalid":!!i["llm.maxOutputTokens"]}),i["llm.maxOutputTokens"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxOutputTokens"]})]})]})]})})}let sg=["dateTime","resources"];function sv(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:d=[]}=e,[c,m]=(0,n.useState)(new Set),[u,x]=(0,n.useState)({}),h=t.contributors||[],p=(e,t)=>{s({contributors:h.map(s=>{if(s.id===e){if(t.id&&t.id!==e&&m(s=>{let r=new Set(s);return r.has(e)&&(r.delete(e),r.add(t.id)),r}),t.type&&t.type!==s.type){let e={id:t.id||s.id,priority:void 0!==t.priority?t.priority:s.priority,enabled:void 0!==t.enabled?t.enabled:s.enabled};if("static"===t.type)return{...e,type:"static",content:""};if("dynamic"===t.type)return{...e,type:"dynamic",source:"dateTime"};if("file"===t.type)return{...e,type:"file",files:[]}}return{...s,...t}}return s})})};return(0,a.jsx)(sx,{title:"System Prompt",defaultOpen:!0,open:i,onOpenChange:l,errorCount:o,sectionErrors:d,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define how the agent should behave using multiple contributors with different priorities."}),0===h.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No contributors configured"}):h.map(e=>{var t,r,n,i,l,o,d,f,g;let v=c.has(e.id);return(0,a.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,a.jsxs)("button",{onClick:()=>{var t;return t=e.id,void m(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[v?(0,a.jsx)(w.A,{className:"h-4 w-4"}):(0,a.jsx)(k.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:e.id}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.type,", priority: ",e.priority,")"]}),!1===e.enabled&&(0,a.jsx)("span",{className:"text-xs text-destructive",children:"(disabled)"})]}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>{var t;return t=e.id,void(s({contributors:h.filter(e=>e.id!==t)}),m(e=>{let s=new Set(e);return s.delete(t),s}))},className:"h-7 w-7 p-0",children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),v&&(0,a.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-id-".concat(e.id),tooltip:"Unique identifier for this contributor",children:"ID *"}),(0,a.jsx)(eZ.p,{id:"contributor-id-".concat(e.id),value:e.id,onChange:t=>p(e.id,{id:t.target.value}),placeholder:"e.g., primary, dateTime"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-type-".concat(e.id),tooltip:"Type of contributor: static (fixed text), dynamic (runtime generated), or file (from files)",children:"Type *"}),(0,a.jsxs)("select",{id:"contributor-type-".concat(e.id),value:e.type,onChange:t=>p(e.id,{type:t.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:[(0,a.jsx)("option",{value:"static",children:"Static"}),(0,a.jsx)("option",{value:"dynamic",children:"Dynamic"}),(0,a.jsx)("option",{value:"file",children:"File"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-priority-".concat(e.id),tooltip:"Execution priority (lower numbers run first)",children:"Priority *"}),(0,a.jsx)(eZ.p,{id:"contributor-priority-".concat(e.id),type:"number",value:e.priority,onChange:t=>{let s=Number.parseInt(t.target.value,10);p(e.id,{priority:Number.isNaN(s)?0:s})},placeholder:"0",min:"0"})]})]}),(0,a.jsx)("div",{children:(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:!1!==e.enabled,onChange:t=>p(e.id,{enabled:t.target.checked}),className:"rounded border-input"}),(0,a.jsx)("span",{children:"Enabled"})]})}),"static"===e.type&&(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-content-".concat(e.id),tooltip:"Static content for the system prompt",children:"Content *"}),(0,a.jsx)(tk.T,{id:"contributor-content-".concat(e.id),value:e.content,onChange:t=>p(e.id,{content:t.target.value}),placeholder:"You are a helpful assistant...",rows:8,className:"font-mono text-sm"})]}),"dynamic"===e.type&&(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-source-".concat(e.id),tooltip:"Source for dynamic content generation",children:"Source *"}),(0,a.jsx)("select",{id:"contributor-source-".concat(e.id),value:e.source,onChange:t=>p(e.id,{source:t.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sg.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),"file"===e.type&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-files-".concat(e.id),tooltip:"File paths to include, comma-separated",children:"Files *"}),(0,a.jsx)(eZ.p,{id:"contributor-files-".concat(e.id),value:(d=e.id,f=e.files,null!=(g=u[d])?g:f.join(", ")),onChange:t=>{var s,r;return s=e.id,r=t.target.value,void x(e=>({...e,[s]:r}))},onBlur:t=>((e,t)=>{x(t=>{let s={...t};return delete s[e],s});let s=t.split(",").map(e=>e.trim()).filter(Boolean);p(e,{files:s.length>0?s:[]})})(e.id,t.target.value),placeholder:"./commands/context.md, ./commands/rules.txt",className:"font-mono"})]}),(0,a.jsxs)("details",{className:"border border-border rounded-md p-2",children:[(0,a.jsx)("summary",{className:"text-sm font-medium cursor-pointer",children:"File Options"}),(0,a.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:(null==(t=e.options)?void 0:t.includeFilenames)!==!1,onChange:t=>{var s;return p(e.id,{options:{...null!=(s=e.options)?s:{},includeFilenames:t.target.checked}})},className:"rounded border-input"}),(0,a.jsx)("span",{children:"Include filenames as headers"})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:(null==(r=e.options)?void 0:r.includeMetadata)===!0,onChange:t=>{var s;return p(e.id,{options:{...null!=(s=e.options)?s:{},includeMetadata:t.target.checked}})},className:"rounded border-input"}),(0,a.jsx)("span",{children:"Include file metadata"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-separator-".concat(e.id),tooltip:"Separator between multiple files",children:"Separator"}),(0,a.jsx)(eZ.p,{id:"contributor-separator-".concat(e.id),value:null!=(o=null==(n=e.options)?void 0:n.separator)?o:"\n\n---\n\n",onChange:t=>{var s;return p(e.id,{options:{...null!=(s=e.options)?s:{},separator:t.target.value}})},placeholder:"\\n\\n---\\n\\n"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-error-handling-".concat(e.id),tooltip:"How to handle missing or unreadable files",children:"Error Handling"}),(0,a.jsxs)("select",{id:"contributor-error-handling-".concat(e.id),value:(null==(i=e.options)?void 0:i.errorHandling)||"skip",onChange:t=>{var s;return p(e.id,{options:{...null!=(s=e.options)?s:{},errorHandling:t.target.value}})},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:[(0,a.jsx)("option",{value:"skip",children:"Skip missing files"}),(0,a.jsx)("option",{value:"error",children:"Error on missing files"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"contributor-max-file-size-".concat(e.id),tooltip:"Maximum file size in bytes",children:"Max File Size (bytes)"}),(0,a.jsx)(eZ.p,{id:"contributor-max-file-size-".concat(e.id),type:"number",value:(null==(l=e.options)?void 0:l.maxFileSize)||1e5,onChange:t=>{var s;let r=Number.parseInt(t.target.value,10);p(e.id,{options:{...null!=(s=e.options)?s:{},maxFileSize:Number.isNaN(r)?void 0:r}})},placeholder:"100000",min:"1"})]})]})]})]})]})]},e.id)}),(0,a.jsxs)(R.$,{onClick:()=>{let e="contributor-".concat(Date.now()),t={id:e,type:"static",priority:10*h.length,enabled:!0,content:""};s({contributors:[...h,t]}),m(t=>new Set(t).add(e))},variant:"outline",size:"sm",className:"w-full",children:[(0,a.jsx)(e5.A,{className:"h-4 w-4 mr-2"}),"Add Contributor"]}),r.systemPrompt&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r.systemPrompt})]})})}var sj=(e=>(e.SCHEMA_VALIDATION="mcp_schema_validation",e.COMMAND_MISSING="mcp_command_missing",e.DUPLICATE_NAME="mcp_duplicate_name",e.CONNECTION_FAILED="mcp_connection_failed",e.PROTOCOL_ERROR="mcp_protocol_error",e.SERVER_NOT_FOUND="mcp_server_not_found",e.TOOL_NOT_FOUND="mcp_tool_not_found",e.PROMPT_NOT_FOUND="mcp_prompt_not_found",e.RESOURCE_NOT_FOUND="mcp_resource_not_found",e))(sj||{}),sb=(e=>(e.LLM="llm",e.AGENT="agent",e.CONFIG="config",e.CONTEXT="context",e.SESSION="session",e.MCP="mcp",e.TOOLS="tools",e.STORAGE="storage",e.LOGGER="logger",e.SYSTEM_PROMPT="system_prompt",e.RESOURCE="resource",e.PROMPT="prompt",e.MEMORY="memory",e.PLUGIN="plugin",e.FILESYSTEM="filesystem",e.PROCESS="process",e))(sb||{}),sy=(e=>(e.USER="user",e.NOT_FOUND="not_found",e.FORBIDDEN="forbidden",e.TIMEOUT="timeout",e.CONFLICT="conflict",e.RATE_LIMIT="rate_limit",e.SYSTEM="system",e.THIRD_PARTY="third_party",e.UNKNOWN="unknown",e))(sy||{}),sN=s(3654),sw=s(8257);sN.Yj().transform(e=>e.trim()).refine(e=>e.length>0,{message:"Required"}),sN.Yj().transform(e=>e.trim()).refine(e=>""===e||function(e){try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}}(e),{message:"Invalid URL"}).transform(e=>""===e?void 0:e).optional();let sk=e=>sN.Yj().transform(t=>{if("string"!=typeof t)return"";let s=null!=e?e:sw.env;return t.replace(/\$([A-Z_][A-Z0-9_]*)|\${([A-Z_][A-Z0-9_]*)}/gi,(e,t,r)=>{var a;return null!=(a=s[t||r])?a:""}).trim()}),sC=e=>sk(e).refine(e=>{try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}},{message:"Invalid URL"});var sA=s(2332),sS=s(8257);let sE=["stdio","sse","http"],sI=["strict","lenient"],sT="lenient",sL=sN.Ik({type:sN.eu("stdio"),command:sk().superRefine((e,t)=>{0===e.length&&t.addIssue({code:sA.eq.custom,message:"Stdio server requires a non-empty command",params:{code:sj.COMMAND_MISSING,scope:sb.MCP,type:sy.USER}})}),args:sN.YO(sk()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),env:sN.g1(sk()).default({}).describe("Optional environment variables for the server process"),timeout:sN.au.number().int().positive().default(3e4),connectionMode:sN.k5(sI).default(sT)}).strict(),sO=sN.Ik({type:sN.eu("sse"),url:sC(sS.env).describe("URL for the SSE server endpoint"),headers:sN.g1(sk()).default({}),timeout:sN.au.number().int().positive().default(3e4),connectionMode:sN.k5(sI).default(sT)}).strict(),sR=sN.Ik({type:sN.eu("http"),url:sC(sS.env).describe("URL for the HTTP server"),headers:sN.g1(sk()).default({}),timeout:sN.au.number().int().positive().default(3e4),connectionMode:sN.k5(sI).default(sT)}).strict(),sD=sN.gM("type",[sL,sO,sR]).superRefine((e,t)=>{}).brand();function sF(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:d=[]}=e,[c,m]=(0,n.useState)(new Set),[u,x]=(0,n.useState)({}),h=Object.entries(t||{}),p=(e,r)=>{let a=t[e],{name:n,...i}=r,l={...a,...i};if(n&&"string"==typeof n&&n!==e){if(t[n])return;let r={...t};delete r[e],r[n]=l,s(r),m(t=>{let s=new Set(t);return s.has(e)&&(s.delete(e),s.add(n)),s})}else s({...t,[e]:l})},f=(e,t,s)=>{var r;return null!=(r=u["".concat(e,":").concat(t)])?r:s},g=(e,t,s)=>{let r="".concat(e,":").concat(t);x(e=>({...e,[r]:s}))},v=(e,t)=>{let s="".concat(e,":").concat(t);x(e=>{let t={...e};return delete t[s],t})};return(0,a.jsx)(sx,{title:"MCP Servers",defaultOpen:!1,open:i,onOpenChange:l,errorCount:o,sectionErrors:d,children:(0,a.jsxs)("div",{className:"space-y-4",children:[0===h.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No MCP servers configured"}):h.map(e=>{let[n,i]=e,l=c.has(n);return(0,a.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,a.jsxs)("button",{onClick:()=>{m(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[l?(0,a.jsx)(w.A,{className:"h-4 w-4"}):(0,a.jsx)(k.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:n}),"command"in i&&i.command&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:["(",i.command,")"]})]}),(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>(e=>{let r={...t};delete r[e],s(r),m(t=>{let s=new Set(t);return s.delete(e),s})})(n),className:"h-7 w-7 p-0",children:(0,a.jsx)(tA.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),l&&(0,a.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-name-".concat(n),tooltip:"Unique identifier for this MCP server",children:"Server Name"}),(0,a.jsx)(eZ.p,{id:"server-name-".concat(n),value:n,onChange:e=>p(n,{name:e.target.value}),placeholder:"e.g., filesystem"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-type-".concat(n),tooltip:"MCP server connection type",children:"Connection Type *"}),(0,a.jsx)("select",{id:"server-type-".concat(n),value:i.type||"stdio",onChange:e=>{let t=e.target.value;"stdio"===t?p(n,{type:"stdio",command:"",args:void 0,env:void 0}):p(n,{type:t,url:"",headers:void 0})},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sE.map(e=>(0,a.jsx)("option",{value:e,children:"stdio"===e?"Standard I/O (stdio)":"sse"===e?"Server-Sent Events (SSE)":"HTTP"},e))})]}),"stdio"===i.type&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-command-".concat(n),tooltip:"The command to execute (e.g., npx, node, python)",children:"Command *"}),(0,a.jsx)(eZ.p,{id:"server-command-".concat(n),value:"command"in i?i.command:"",onChange:e=>p(n,{command:e.target.value}),placeholder:"e.g., npx, node, python","aria-invalid":!!r["mcpServers.".concat(n,".command")]}),r["mcpServers.".concat(n,".command")]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["mcpServers.".concat(n,".command")]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-args-".concat(n),tooltip:"Command arguments, comma-separated",children:"Arguments"}),(0,a.jsx)(eZ.p,{id:"server-args-".concat(n),value:f(n,"args",("args"in i&&i.args?i.args:[]).join(", ")),onChange:e=>g(n,"args",e.target.value),onBlur:e=>((e,t)=>{if(v(e,"args"),!t.trim())return void p(e,{args:void 0});let s=t.split(",").map(e=>e.trim()).filter(Boolean);p(e,{args:s.length>0?s:void 0})})(n,e.target.value),placeholder:"--port, 3000, --host, localhost",className:"font-mono"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-env-".concat(n),tooltip:"Environment variables in KEY=value format, one per line",children:"Environment Variables"}),(0,a.jsx)("textarea",{id:"server-env-".concat(n),value:f(n,"env",Object.entries("env"in i&&i.env||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>g(n,"env",e.target.value),onBlur:e=>((e,t)=>{if(v(e,"env"),!t.trim())return void p(e,{env:void 0});let s={};t.split("\n").map(e=>e.trim()).filter(Boolean).forEach(e=>{let[t,...r]=e.split("=");t&&r.length>0&&(s[t.trim()]=r.join("=").trim())}),p(e,{env:Object.keys(s).length>0?s:void 0})})(n,e.target.value),placeholder:"API_KEY=$MY_API_KEY\nPORT=3000",rows:4,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 font-mono"})]})]}),("sse"===i.type||"http"===i.type)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-url-".concat(n),tooltip:"The URL endpoint for the MCP server",children:"URL *"}),(0,a.jsx)(eZ.p,{id:"server-url-".concat(n),value:"url"in i?i.url:"",onChange:e=>p(n,{url:e.target.value}),placeholder:"https://example.com/mcp","aria-invalid":!!r["mcpServers.".concat(n,".url")]}),r["mcpServers.".concat(n,".url")]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["mcpServers.".concat(n,".url")]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-headers-".concat(n),tooltip:"HTTP headers in KEY=value format, one per line",children:"Headers"}),(0,a.jsx)("textarea",{id:"server-headers-".concat(n),value:f(n,"headers",Object.entries("headers"in i&&i.headers||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>g(n,"headers",e.target.value),onBlur:e=>((e,t)=>{if(v(e,"headers"),!t.trim())return void p(e,{headers:void 0});let s={};t.split("\n").map(e=>e.trim()).filter(Boolean).forEach(e=>{let[t,...r]=e.split("=");t&&r.length>0&&(s[t.trim()]=r.join("=").trim())}),p(e,{headers:Object.keys(s).length>0?s:void 0})})(n,e.target.value),placeholder:"Authorization=Bearer token\nContent-Type=application/json",rows:4,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 font-mono"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"server-mode-".concat(n),tooltip:"Strict mode fails on any error; lenient mode continues despite errors",children:"Connection Mode"}),(0,a.jsx)("select",{id:"server-mode-".concat(n),value:i.connectionMode||sT,onChange:e=>p(n,{connectionMode:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sI.map(e=>(0,a.jsx)("option",{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]})]},n)}),(0,a.jsxs)(R.$,{onClick:()=>{let e="server-".concat(Object.keys(t||{}).length+1);s({...t,[e]:{type:"stdio",command:"",connectionMode:"strict"}}),m(t=>new Set(t).add(e))},variant:"outline",size:"sm",className:"w-full",children:[(0,a.jsx)(e5.A,{className:"h-4 w-4 mr-2"}),"Add MCP Server"]}),r.mcpServers&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r.mcpServers})]})})}sN.g1(sD).describe("A dictionary of server configurations, keyed by server name").brand();var s_=(e=>(e.MANAGER_NOT_INITIALIZED="storage_manager_not_initialized",e.MANAGER_NOT_CONNECTED="storage_manager_not_connected",e.CONNECTION_FAILED="storage_connection_failed",e.CONNECTION_CONFIG_MISSING="storage_connection_config_missing",e.READ_FAILED="storage_read_failed",e.WRITE_FAILED="storage_write_failed",e.DELETE_FAILED="storage_delete_failed",e.MIGRATION_FAILED="storage_migration_failed",e.DATABASE_INVALID_CONFIG="storage_database_invalid_config",e.BLOB_INVALID_CONFIG="BLOB_INVALID_CONFIG",e.BLOB_SIZE_EXCEEDED="BLOB_SIZE_EXCEEDED",e.BLOB_TOTAL_SIZE_EXCEEDED="BLOB_TOTAL_SIZE_EXCEEDED",e.BLOB_INVALID_INPUT="BLOB_INVALID_INPUT",e.BLOB_ENCODING_ERROR="BLOB_ENCODING_ERROR",e.BLOB_NOT_FOUND="BLOB_NOT_FOUND",e.BLOB_INVALID_REFERENCE="BLOB_INVALID_REFERENCE",e.BLOB_ACCESS_DENIED="BLOB_ACCESS_DENIED",e.BLOB_CORRUPTED="BLOB_CORRUPTED",e.BLOB_BACKEND_NOT_CONNECTED="BLOB_BACKEND_NOT_CONNECTED",e.BLOB_BACKEND_UNAVAILABLE="BLOB_BACKEND_UNAVAILABLE",e.BLOB_CLEANUP_FAILED="BLOB_CLEANUP_FAILED",e.BLOB_OPERATION_FAILED="BLOB_OPERATION_FAILED",e))(s_||{});let sP=["in-memory","redis"],sM=sN.Ik({maxConnections:sN.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:sN.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:sN.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:sN.g1(sN.bz()).optional().describe("Backend-specific options")}),sz=sM.extend({type:sN.eu("in-memory")}).strict(),sU=sM.extend({type:sN.eu("redis"),url:sk().optional().describe("Redis connection URL (redis://...)"),host:sN.Yj().optional().describe("Redis host"),port:sN.ai().int().positive().optional().describe("Redis port"),password:sN.Yj().optional().describe("Redis password"),database:sN.ai().int().nonnegative().optional().describe("Redis database number")}).strict();sN.gM("type",[sz,sU],{errorMap:(e,t)=>e.code===sA.eq.invalid_union_discriminator?{message:"Invalid cache type. Expected 'in-memory' or 'redis'."}:{message:t.defaultError}}).describe("Cache configuration").superRefine((e,t)=>{"redis"!==e.type||e.url||e.host||t.addIssue({code:sA.eq.custom,message:"Redis cache requires either 'url' or 'host' to be specified",path:["url"],params:{code:s_.CONNECTION_CONFIG_MISSING,scope:sb.STORAGE,type:sy.USER}})});let sq=["in-memory","sqlite","postgres"],sB=sN.Ik({maxConnections:sN.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:sN.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:sN.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:sN.g1(sN.bz()).optional().describe("Backend-specific options")}),s$=sB.extend({type:sN.eu("in-memory")}).strict(),sW=sB.extend({type:sN.eu("sqlite"),path:sN.Yj().describe("SQLite database file path (required for SQLite - CLI enrichment provides per-agent path)")}).strict(),sK=sB.extend({type:sN.eu("postgres"),url:sk().optional().describe("PostgreSQL connection URL (postgresql://...)"),connectionString:sk().optional().describe("PostgreSQL connection string"),host:sN.Yj().optional().describe("PostgreSQL host"),port:sN.ai().int().positive().optional().describe("PostgreSQL port"),database:sN.Yj().optional().describe("PostgreSQL database name"),password:sN.Yj().optional().describe("PostgreSQL password")}).strict();function sV(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,d=e=>{s({...t,cache:{...t.cache,...e}})},c=e=>{s({...t,database:{...t.database,...e}})},m="redis"===t.cache.type,u="sqlite"===t.database.type||"postgres"===t.database.type;return(0,a.jsx)(sx,{title:"Storage Configuration",defaultOpen:!1,open:n,onOpenChange:i,errorCount:l,sectionErrors:o,children:(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("h4",{className:"text-sm font-medium",children:"Cache"}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"cache-type",tooltip:"Storage backend for caching data (in-memory or Redis)",children:"Cache Type"}),(0,a.jsx)("select",{id:"cache-type",value:t.cache.type,onChange:e=>d({type:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sP.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),m&&"url"in t.cache&&(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"cache-url",tooltip:"Redis connection URL (e.g., redis://localhost:6379)",children:"Redis URL"}),(0,a.jsx)(eZ.p,{id:"cache-url",value:t.cache.url||"",onChange:e=>d({url:e.target.value||void 0}),placeholder:"redis://localhost:6379","aria-invalid":!!r["storage.cache.url"]}),r["storage.cache.url"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["storage.cache.url"]})]})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("h4",{className:"text-sm font-medium",children:"Database"}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"database-type",tooltip:"Storage backend for persistent data (in-memory, SQLite, or PostgreSQL)",children:"Database Type"}),(0,a.jsx)("select",{id:"database-type",value:t.database.type,onChange:e=>c({type:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sq.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),u&&(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"database-url",tooltip:"sqlite"===t.database.type?"File path for SQLite database":"PostgreSQL connection string",children:"sqlite"===t.database.type?"SQLite Path":"PostgreSQL URL"}),(0,a.jsx)(eZ.p,{id:"database-url",value:"url"in t.database&&t.database.url||"path"in t.database&&t.database.path||"",onChange:e=>{"sqlite"===t.database.type?c({path:e.target.value||void 0}):c({url:e.target.value||void 0})},placeholder:"sqlite"===t.database.type?"./dexto.db":"postgresql://user:pass@localhost:5432/dexto","aria-invalid":!!(r["storage.database.url"]||r["storage.database.path"])}),(r["storage.database.url"]||r["storage.database.path"])&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["storage.database.url"]||r["storage.database.path"]})]})]})]})})}sN.gM("type",[s$,sW,sK],{errorMap:(e,t)=>e.code===sA.eq.invalid_union_discriminator?{message:"Invalid database type. Expected 'in-memory', 'sqlite', or 'postgres'."}:{message:t.defaultError}}).describe("Database configuration").superRefine((e,t)=>{"postgres"!==e.type||e.url||e.connectionString||e.host||t.addIssue({code:sA.eq.custom,message:"PostgreSQL database requires one of 'url', 'connectionString', or 'host' to be specified",path:["url"],params:{code:s_.CONNECTION_CONFIG_MISSING,scope:sb.STORAGE,type:sy.USER}})});let sY=["search_history","ask_user","read_file","glob_files","grep_content","write_file","edit_file","bash_exec","bash_output","kill_process","delegate_to_url"],sG=["manual","auto-approve","auto-deny"],sQ=["memory","storage"],sH="auto-approve",sJ="storage";sN.YO(sN.k5(sY).describe("Available internal tool names")).default([]).describe("Array of internal tool names to enable. Empty array = disabled. Available tools: ".concat(sY.join(", ")));let sZ=sN.Ik({alwaysAllow:sN.YO(sN.Yj()).default([]).describe('Tools that never require approval (low-risk). Use full qualified names (e.g., "internal--ask_user", "mcp--filesystem--read_file")'),alwaysDeny:sN.YO(sN.Yj()).default([]).describe('Tools that are always denied (high-risk). Takes precedence over alwaysAllow. Use full qualified names (e.g., "mcp--filesystem--delete_file")')}).strict().default({alwaysAllow:[],alwaysDeny:[]}).describe("Static tool policies for allow/deny lists");function sX(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,d=e=>{s({...t,...e})};return(0,a.jsx)(sx,{title:"Tool Confirmation",defaultOpen:!1,open:n,onOpenChange:i,errorCount:l,sectionErrors:o,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"confirmation-mode",tooltip:"How the agent handles tool execution requests",children:"Confirmation Mode"}),(0,a.jsx)("select",{id:"confirmation-mode",value:t.mode||sH,onChange:e=>d({mode:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sG.map(e=>(0,a.jsx)("option",{value:e,children:"auto-approve"===e?"Auto-approve":"manual"===e?"Manual":"Auto-deny"},e))}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"manual"===t.mode?"Require explicit approval before executing tools":"auto-deny"===t.mode?"Automatically deny all tool executions":"Automatically approve tool executions"})]}),"manual"===t.mode&&(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"confirmation-timeout",tooltip:"How long to wait for approval before timing out",children:"Timeout (seconds)"}),(0,a.jsx)(eZ.p,{id:"confirmation-timeout",type:"number",value:t.timeout||"",onChange:e=>d({timeout:e.target.value?parseInt(e.target.value,10):void 0}),min:"1",placeholder:"e.g., 60","aria-invalid":!!r["toolConfirmation.timeout"]}),r["toolConfirmation.timeout"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["toolConfirmation.timeout"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"allowed-tools-storage",tooltip:"Where to store the list of pre-approved tools (memory or persistent storage)",children:"Allowed Tools Storage"}),(0,a.jsx)("select",{id:"allowed-tools-storage",value:t.allowedToolsStorage||sJ,onChange:e=>{var r;return r=e.target.value,void s({...t,allowedToolsStorage:r})},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sQ.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})]})})}function s0(e){var t;let{config:s,onChange:r,errors:i={}}=e,l=s.systemPrompt?"string"==typeof s.systemPrompt?{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:s.systemPrompt}]}:{contributors:s.systemPrompt.contributors||[]}:{contributors:[]},[o,d]=(0,n.useState)({basic:!0,llm:!1,systemPrompt:!1,mcpServers:!1,storage:!1,toolConfirmation:!1}),c=s1(i);(0,n.useEffect)(()=>{let e=s1(i),t=Object.keys(e).filter(t=>e[t].length>0);t.length>0&&d(e=>{let s={...e};return t.forEach(e=>{s[e]=!0}),s})},[i]);let m=e=>{d(t=>({...t,[e]:!t[e]}))},u=!!(t=s).sessions&&!!(Object.keys(t.sessions).length>0)||!!t.internalTools;return(0,a.jsxs)("div",{className:"flex flex-col h-full overflow-auto",children:[u&&(0,a.jsx)("div",{className:"mx-4 mt-4 p-3 bg-yellow-500/10 border border-yellow-500/20 rounded-lg",children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)(tv.A,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-500",children:"Advanced Configuration Detected"}),(0,a.jsx)("p",{className:"text-xs text-yellow-600/80 dark:text-yellow-500/80 mt-1",children:"Some advanced features may not be editable in form mode. Switch to YAML editor for full control."})]})]})}),(0,a.jsxs)("div",{className:"flex-1 p-4 space-y-4",children:[(0,a.jsx)(sx,{title:"Basic Information",open:o.basic,onOpenChange:()=>m("basic"),errorCount:c.basic.length,sectionErrors:c.basic,children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tu,{htmlFor:"agent-greeting",tooltip:"The initial message shown to users when they start a conversation",children:"Greeting Message"}),(0,a.jsx)(eZ.p,{id:"agent-greeting",value:s.greeting||"",onChange:e=>r({...s,greeting:e.target.value}),placeholder:"Hello! How can I help you today?","aria-invalid":!!i.greeting}),i.greeting&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i.greeting})]})}),(0,a.jsx)(sf,{value:s.llm,onChange:e=>{r({...s,llm:e})},errors:i,open:o.llm,onOpenChange:()=>m("llm"),errorCount:c.llm.length,sectionErrors:c.llm}),(0,a.jsx)(sv,{value:l,onChange:e=>{r({...s,systemPrompt:e})},errors:i,open:o.systemPrompt,onOpenChange:()=>m("systemPrompt"),errorCount:c.systemPrompt.length,sectionErrors:c.systemPrompt}),(0,a.jsx)(sF,{value:s.mcpServers||{},onChange:e=>{r({...s,mcpServers:e})},errors:i,open:o.mcpServers,onOpenChange:()=>m("mcpServers"),errorCount:c.mcpServers.length,sectionErrors:c.mcpServers}),(0,a.jsx)(sV,{value:s.storage||{cache:{type:"in-memory"},database:{type:"in-memory"},blob:{type:"local",storePath:"/tmp/dexto-blobs"}},onChange:e=>{r({...s,storage:e})},errors:i,open:o.storage,onOpenChange:()=>m("storage"),errorCount:c.storage.length,sectionErrors:c.storage}),(0,a.jsx)(sX,{value:s.toolConfirmation||{},onChange:e=>{r({...s,toolConfirmation:e})},errors:i,open:o.toolConfirmation,onOpenChange:()=>m("toolConfirmation"),errorCount:c.toolConfirmation.length,sectionErrors:c.toolConfirmation})]})]})}function s1(e){let t={basic:[],llm:[],systemPrompt:[],mcpServers:[],storage:[],toolConfirmation:[]};return Object.entries(e).forEach(e=>{let[s,r]=e;"greeting"===s?t.basic.push(r):s.startsWith("llm.")?t.llm.push(r):s.startsWith("systemPrompt")?t.systemPrompt.push(r):s.startsWith("mcpServers")?t.mcpServers.push(r):s.startsWith("storage.")?t.storage.push(r):s.startsWith("toolConfirmation.")&&t.toolConfirmation.push(r)}),t}function s2(e){let{config:t,onChange:s,errors:r={}}=e;return(0,a.jsx)("div",{className:"flex flex-col h-full",children:(0,a.jsx)(s0,{config:t,onChange:s,errors:r})})}sN.Ik({mode:sN.k5(sG).default(sH).describe("Tool confirmation mode: manual (interactive), auto-approve (all tools), auto-deny (no tools)"),timeout:sN.ai().int().positive().default(12e4).describe("Timeout for tool confirmation requests in milliseconds, defaults to 120000ms (2 mins)"),allowedToolsStorage:sN.k5(sQ).default(sJ).describe("Storage type for remembered tool approvals: memory (session-only) or storage (persistent)"),toolPolicies:sZ.describe("Static tool policies for fine-grained allow/deny control. Deny list takes precedence over allow list.")}).strict().describe("Tool confirmation and approval configuration"),sN.Ik({enabled:sN.zM().default(!0).describe("Enable elicitation support (ask_user tool and MCP server elicitations). When disabled, elicitation requests will be rejected."),timeout:sN.ai().int().positive().default(12e4).describe("Timeout for elicitation requests in milliseconds, defaults to 120000ms (2 mins)")}).strict().describe("Elicitation configuration for user input requests. Independent from tool confirmation mode, allowing auto-approve for tools while still supporting elicitation.");var s5=s(4169);function s4(e){let{isOpen:t,onClose:s,variant:r="overlay"}=e,{data:i,isLoading:o,error:d,refetch:c}=function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];return(0,m.I)({queryKey:x.l.agent.config,queryFn:async()=>{let e=await h.S.api.agent.config.$get();return await e.json()},enabled:e,staleTime:3e4})}(t),p=(0,u.n)({mutationFn:async e=>{let{yaml:t}=e,s=await h.S.api.agent.validate.$post({json:{yaml:t}});return await s.json()}}),f=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let{yaml:t}=e,s=await h.S.api.agent.config.$post({json:{yaml:t}});return await s.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.agent.config})}})}(),[g,v]=(0,n.useState)(""),[b,y]=(0,n.useState)(""),[w,k]=(0,n.useState)(null),[A,S]=(0,n.useState)(null),[E,I]=(0,n.useState)(null),[D,F]=(0,n.useState)(""),[_,P]=(0,n.useState)("yaml"),[M,z]=(0,n.useState)(null),[U,q]=(0,n.useState)(!0),[B,$]=(0,n.useState)([]),[W,K]=(0,n.useState)([]),[V,Y]=(0,n.useState)(!1),[Q,H]=(0,n.useState)(!1),[J,Z]=(0,n.useState)(!1),[X,ee]=(0,n.useState)(""),[et]=(0,sa.d7)(g,500),es=(0,n.useRef)(0),er=(0,n.useCallback)(async e=>{let t=es.current+1;es.current=t;try{let s=await p.mutateAsync({yaml:e});es.current===t&&(q(s.valid),$(s.errors||[]),K(s.warnings||[]))}catch(e){console.warn("Validation error: ".concat(e instanceof Error?e.message:String(e))),es.current===t&&(q(!1),$([{message:"Failed to validate configuration",code:"VALIDATION_ERROR"}]))}},[p.mutateAsync]);(0,n.useEffect)(()=>{if(i&&t){v(i.yaml),y(i.yaml),F(i.relativePath),Y(!1);let{config:e,document:t}=ea(i.yaml);e&&t&&(k(e),S(e),I(t)),er(i.yaml)}},[i,t,er]);let ea=e=>{console.log("[parseYamlToConfig] Starting parse");try{let t=s5.Tp(e);if(console.log("[parseYamlToConfig] Document created:",t),t.errors&&t.errors.length>0){console.debug("[parseYamlToConfig] Parse errors:",t.errors);let e=t.errors.map(e=>e.message).join("; ");return{config:null,document:null,error:e}}let s=t.toJS();return console.log("[parseYamlToConfig] Config parsed successfully:",s),{config:s,document:t,error:null}}catch(e){return console.debug("[parseYamlToConfig] Exception:",e),{config:null,document:null,error:e instanceof Error?e.message:"Failed to parse YAML"}}},en=e=>{if(console.log("[handleModeSwitch] Called with newMode:",e,"current mode:",_),e===_)return void console.log("[handleModeSwitch] Same mode, returning");if("form"===e){console.log("[handleModeSwitch] Switching to form mode, parsing YAML...");let{config:e,document:t,error:s}=ea(g);if(console.log("[handleModeSwitch] Parse result:",{config:e,document:t,error:s}),s){console.error("[handleModeSwitch] Parse error, not switching:",s),z(s);return}console.log("[handleModeSwitch] Parse successful, setting state"),k(e),I(t),z(null)}console.log("[handleModeSwitch] Setting editor mode to:",e),P(e)},ei=(0,n.useCallback)(async()=>{if(U&&!(B.length>0)){Z(!1),ee("");try{let e=await f.mutateAsync({yaml:g});y(g),Y(!1),Z(!0),e.restarted?ee("Configuration applied successfully — ".concat(e.changesApplied.join(", ")," updated")):ee("Configuration saved successfully (no changes detected)"),setTimeout(()=>{Z(!1),ee("")},5e3)}catch(t){let e=t instanceof Error?t.message:String(t);console.error("Error saving agent config: ".concat(e))}}},[U,B,f,g]),el=(0,n.useCallback)(()=>{V?H(!0):s()},[V,s]);if((0,n.useEffect)(()=>{t&&er(et)},[et,t,er]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),!f.isPending&&U&&ei()),"Escape"===e.key&&(e.preventDefault(),el())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,f.isPending,U,V,ei,el]),!t)return null;let eo=(()=>{if(f.isPending)return null;if(!V)return"No changes to save";if(B.length>0){let e=B[0];return e.path?"Configuration error in ".concat(e.path,": ").concat(e.message):"Configuration error: ".concat(e.message)}return U?null:"Configuration has validation errors"})(),ed=!V||f.isPending||!U||B.length>0,ec=(0,a.jsxs)("div",{className:"flex flex-col h-full bg-background",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("div",{className:"flex items-center gap-3",children:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Customize Agent"}),(0,a.jsxs)("a",{href:"https://docs.dexto.ai/docs/guides/configuring-dexto/overview",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1",title:"View configuration documentation",children:["View docs",(0,a.jsx)(tW.A,{className:"h-3 w-3"})]})]}),D&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:D})]})}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1 bg-muted/50 rounded-md p-1",children:[(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"yaml"===_?"default":"ghost",size:"sm",onClick:()=>en("yaml"),className:"h-7 px-3",children:"YAML Editor"})}),(0,a.jsx)(O,{children:"Edit configuration in raw YAML format with full control"})]}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"form"===_?"default":"ghost",size:"sm",onClick:()=>en("form"),className:"h-7 px-3",children:"Form Editor"})}),(0,a.jsx)(O,{children:"Edit configuration using user-friendly forms"})]})]}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>{V?H(!0):c()},disabled:o,children:(0,a.jsx)(tV.A,{className:(0,j.cn)("h-4 w-4",o&&"animate-spin")})})}),(0,a.jsx)(O,{children:"Reload configuration"})]}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:el,children:(0,a.jsx)(C.A,{className:"h-4 w-4"})})}),(0,a.jsx)(O,{children:"Close (Esc)"})]})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:d?(0,a.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,a.jsxs)("div",{className:"text-center max-w-md",children:[(0,a.jsx)(N.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,a.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Failed to load configuration"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:(null==d?void 0:d.message)||"Unknown error"}),(0,a.jsxs)(R.$,{onClick:()=>c(),variant:"outline",children:[(0,a.jsx)(tV.A,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):o?(0,a.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading configuration..."})]})}):M&&"form"===_?(0,a.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,a.jsxs)("div",{className:"text-center max-w-md",children:[(0,a.jsx)(N.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,a.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Cannot parse YAML"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:M}),(0,a.jsx)(R.$,{onClick:()=>P("yaml"),variant:"outline",children:"Switch to YAML Editor"})]})}):"yaml"===_?(0,a.jsx)(su,{value:g,onChange:e=>{v(e),Y(e!==b),Z(!1);let{config:t,document:s}=ea(e);t&&s&&(k(t),I(s))},isValidating:p.isPending,isValid:U,errors:B,warnings:W,hasUnsavedChanges:V}):w?(0,a.jsx)(s2,{config:w,onChange:e=>{if(console.log("[handleFormChange] Called with new config"),console.log("[handleFormChange] yamlDocument exists?",!!E),!E)return void console.error("[handleFormChange] No document available - this should not happen!");k(e),v(((e,t)=>{console.log("[serializeConfigToYaml] Starting serialization"),console.log("[serializeConfigToYaml] Document:",t),console.log("[serializeConfigToYaml] Config:",e);let s=(e=>{let t=e=>!!(null==e||""===e||Array.isArray(e)&&0===e.length)||"object"==typeof e&&null!==e&&"[object Object]"===Object.prototype.toString.call(e)&&0===Object.keys(e).length,s=e=>{if(Array.isArray(e))return e.map(s).filter(e=>!t(e));if("object"==typeof e&&null!==e){let r={};for(let[a,n]of Object.entries(e))if(!t(n))if("object"==typeof n&&null!==n){let e=s(n);t(e)||(r[a]=e)}else r[a]=n;return r}return e};return s(e)})(e);console.log("[serializeConfigToYaml] Cleaned config:",s);let r=((e,t)=>{console.log("[updateYamlDocumentFromConfig] Starting update"),console.log("[updateYamlDocumentFromConfig] Document:",e),console.log("[updateYamlDocumentFromConfig] Config:",t);let s=(t,r)=>{if(null==r||Array.isArray(r))return e.createNode(r);if("object"==typeof r&&!Array.isArray(r)){if(!t||!t.items)return e.createNode(r);let a=new Set;for(let e of t.items){let t=e.key.value;a.add(t),t in r&&(e.value=s(e.value,r[t]))}for(let[s,n]of Object.entries(r))a.has(s)||t.items.push(e.createPair(s,n));return t.items=t.items.filter(e=>e.key.value in r),t}return e.createNode(r)};try{return e.contents=s(e.contents,t),console.log("[updateYamlDocumentFromConfig] Update successful"),e}catch(e){throw console.error("[updateYamlDocumentFromConfig] Update failed:",e),e}})(t,s).toString();return console.log("[serializeConfigToYaml] Serialized result length:",r.length),r})(e,E)),Y(!(e===A||e&&A&&JSON.stringify(e)===JSON.stringify(A))),Z(!1)},errors:B.reduce((e,t)=>(t.path&&(e[t.path]=t.message),e),{})}):null}),!d&&!o&&(0,a.jsxs)("div",{className:"flex flex-col border-t border-border",children:[(J||f.error)&&(0,a.jsxs)("div",{className:"px-4 py-3 bg-muted/50 border-b border-border",children:[J&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-500",children:[(0,a.jsx)(G.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:X})]}),f.error&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[(0,a.jsx)(N.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:f.error.message})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsx)("div",{}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(R.$,{variant:"outline",size:"sm",onClick:el,children:"Close"}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)("div",{children:(0,a.jsx)(R.$,{variant:"default",size:"sm",onClick:ei,disabled:ed,children:f.isPending?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-background border-t-transparent mr-2"}),"Saving..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(so.A,{className:"h-4 w-4 mr-2"}),"Save"]})})})}),(0,a.jsx)(O,{children:eo||"Save configuration (⌘S)"})]})]})]})]}),(0,a.jsx)(eH.lG,{open:Q,onOpenChange:H,children:(0,a.jsxs)(eH.Cf,{children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsx)(eH.L3,{children:"Unsaved Changes"}),(0,a.jsx)(eH.rr,{children:"You have unsaved changes. Do you want to discard them?"})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>H(!1),children:"Cancel"}),(0,a.jsx)(R.$,{variant:"destructive",onClick:()=>{H(!1),v(b),Y(!1),c()},children:"Discard Changes"})]})]})})]});return"inline"===r?ec:(0,a.jsx)("div",{className:(0,j.cn)("fixed inset-y-0 right-0 z-50 w-full sm:w-[600px] md:w-[700px] lg:w-[800px] border-l border-border bg-background shadow-2xl transform transition-transform duration-300",t?"translate-x-0":"translate-x-full"),children:ec})}var s3=s(7340),s8=s(756),s6=s(7723),s7=s(0),s9=s(7201),re=s(6923),rt=s(3073),rs=s(1430);function rr(){let{theme:e,toggleTheme:t}=c(),[s,r]=(0,n.useState)(!1);(0,n.useEffect)(()=>{r(!0)},[]);let i="dark"===e;return s?(0,a.jsx)(I,{children:(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(eO.bL,{checked:i,onCheckedChange:t,className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full relative transition-colors flex items-center px-0.5","aria-label":"Toggle theme",children:(0,a.jsx)(eO.zi,{className:"\n w-5 h-5 rounded-full shadow flex items-center justify-center\n transition-transform transform\n translate-x-0.5 data-[state=checked]:translate-x-[1.375rem]\n bg-white dark:bg-gray-100\n ",children:i?(0,a.jsx)(rt.A,{className:"w-3.5 h-3.5 text-gray-700"}):(0,a.jsx)(rs.A,{className:"w-3.5 h-3.5 text-yellow-500"})})})}),(0,a.jsx)(O,{children:i?"Switch to light mode":"Switch to dark mode"})]})}):(0,a.jsx)("div",{className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full"})}var ra=s(8491);function rn(e){let{active:t=!1}=e,{voices:s,selected:r,setSelected:i}=function(){let[e,t]=(0,n.useState)(U.getVoices()),[s,r]=(0,n.useState)(U.getPreferredVoiceName());return(0,n.useEffect)(()=>{let e=U.subscribeVoices(()=>{t(U.getVoices()),r(U.getPreferredVoiceName())});return()=>e()},[]),{voices:e,selected:s,setSelected:e=>{U.setPreferredVoice(e),r(U.getPreferredVoiceName())}}}(),[l,o]=(0,n.useState)(!1);return((0,n.useEffect)(()=>{if(!t)return void o(!1);let e=window.requestIdleCallback?window.requestIdleCallback(()=>o(!0)):setTimeout(()=>o(!0),0);return()=>{window.cancelIdleCallback&&"number"==typeof e?window.cancelIdleCallback(e):clearTimeout(e)}},[t]),t)?(0,a.jsxs)(ra.l6,{value:null!=r?r:"auto",onValueChange:e=>{i("auto"===e?null:e)},children:[(0,a.jsx)(ra.bq,{className:"h-8 w-[12rem] text-xs",children:(0,a.jsx)(ra.yv,{placeholder:"Voice"})}),(0,a.jsxs)(ra.gC,{children:[(0,a.jsx)(ra.eb,{value:"auto",children:"Auto (best available)"}),l&&s.map(e=>(0,a.jsxs)(ra.eb,{value:e.name,children:[e.name," (",e.lang,")"]},"".concat(e.name,"-").concat(e.lang)))]})]}):null}function ri(e){let{isOpen:t,onClose:s}=e;return(0,a.jsx)(eH.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-lg",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsx)(eH.L3,{children:"Settings"}),(0,a.jsx)(eH.rr,{children:"Configure preferences for speech and more."})]}),(0,a.jsx)("div",{className:"space-y-6 py-2",children:(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{className:"text-xs uppercase text-muted-foreground",children:"Voice"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Choose a preferred text-to-speech voice. “Auto” selects the best available voice on your device."}),(0,a.jsx)(rn,{active:t})]})})]})})}var rl=s(825),ro=s(9850);let rd=(0,rl.v)()((0,ro.Zr)(e=>({recentAgents:[],addRecentAgent:t=>e(e=>{let s=e.recentAgents.filter(e=>e.path!==t.path);return{recentAgents:[{...t,lastUsed:Date.now()},...s].slice(0,5)}}),clearRecentAgents:()=>e({recentAgents:[]})}),{name:"dexto:recentAgents"}));var rc=s(1182),rm=s(4884);let ru={id:"",name:"",description:"",author:"",tags:""},rx={llm:{provider:"openai",model:"gpt-5",apiKey:""},systemPrompt:{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:""}]}};function rh(e){let{open:t,onOpenChange:s,onAgentCreated:r}=e,[i,o]=(0,n.useState)(ru),[d,c]=(0,n.useState)(rx),[m,p]=(0,n.useState)({}),[f,g]=(0,n.useState)(null),v=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.agents.custom.create.$post({json:e});return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.agents.all})}})}(),j=v.isPending,[b,y]=(0,n.useState)({basic:!0,llm:!0,systemPrompt:!0}),N=e=>{y(t=>({...t,[e]:!t[e]}))},w=(e,t)=>{o(s=>({...s,[e]:t})),m[e]&&p(t=>{let s={...t};return delete s[e],s})},k=async()=>{(()=>{var e,t,s;let r={};i.id.trim()?/^[a-z0-9-]+$/.test(i.id)||(r.id="Agent ID must contain only lowercase letters, numbers, and hyphens"):r.id="Agent ID is required",i.name.trim()||(r.name="Agent name is required"),i.description.trim()||(r.description="Description is required"),(null==(e=d.llm)?void 0:e.provider)||(r["llm.provider"]="Provider is required"),(null==(s=d.llm)||null==(t=s.model)?void 0:t.trim())||(r["llm.model"]="Model is required");let a=d.systemPrompt;if(a&&"object"==typeof a&&"contributors"in a){let e=a.contributors;Array.isArray(e)&&(e.some(e=>!!("static"===e.type&&"string"==typeof e.content&&e.content.trim()))||(r.systemPrompt="At least one static contributor with content is required"))}else"string"!=typeof a||a.trim()||(r.systemPrompt="System prompt is required");return p(r),0===Object.keys(r).length})()&&(g(null),v.mutate({id:i.id.trim(),name:i.name.trim(),description:i.description.trim(),author:i.author.trim()||void 0,tags:i.tags.split(",").map(e=>e.trim()).filter(Boolean),config:d},{onSuccess:e=>{o(ru),c(rx),p({}),s(!1),r&&e.id&&r(e.id)},onError:e=>{g(e.message)}}))};return(0,a.jsx)(eH.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eH.Cf,{className:"max-w-2xl max-h-[90vh] flex flex-col",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsx)(eH.L3,{children:"Create New Agent"}),(0,a.jsxs)(eH.rr,{children:["Create a custom agent with your own configuration.",(0,a.jsx)("br",{}),(0,a.jsx)("br",{}),"You can add more advanced configuration after creating the agent using the Edit Agent button."]})]}),f&&(0,a.jsxs)("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-3 flex items-start gap-2",children:[(0,a.jsx)(tv.A,{className:"h-4 w-4 text-destructive mt-0.5 flex-shrink-0"}),(0,a.jsx)("div",{className:"text-sm text-destructive",children:f})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4 pr-2",children:[(0,a.jsx)(sx,{title:"Basic Information",open:b.basic,onOpenChange:()=>N("basic"),children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"agent-id",tooltip:"Unique identifier for this agent (lowercase, no spaces, hyphens only)",children:"Agent ID *"}),(0,a.jsx)(eZ.p,{id:"agent-id",value:i.id,onChange:e=>w("id",e.target.value),placeholder:"my-custom-agent","aria-invalid":!!m.id}),m.id&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:m.id})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"agent-name",tooltip:"Display name for this agent (shown in UI)",children:"Agent Name *"}),(0,a.jsx)(eZ.p,{id:"agent-name",value:i.name,onChange:e=>w("name",e.target.value),placeholder:"My Custom Agent","aria-invalid":!!m.name}),m.name&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:m.name})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"agent-description",tooltip:"Brief description of what this agent does",children:"Description *"}),(0,a.jsx)(eZ.p,{id:"agent-description",value:i.description,onChange:e=>w("description",e.target.value),placeholder:"A custom agent for specific tasks","aria-invalid":!!m.description}),m.description&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:m.description})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"agent-author",tooltip:"Your name or organization",children:"Author"}),(0,a.jsx)(eZ.p,{id:"agent-author",value:i.author,onChange:e=>w("author",e.target.value),placeholder:"Your Name"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(tu,{htmlFor:"agent-tags",tooltip:"Comma-separated tags for categorization",children:"Tags"}),(0,a.jsx)(eZ.p,{id:"agent-tags",value:i.tags,onChange:e=>w("tags",e.target.value),placeholder:"coding, custom, specialized"})]})]})}),(0,a.jsx)(sf,{value:d.llm||{provider:"openai",model:"gpt-5",apiKey:""},onChange:e=>c(t=>({...t,llm:e})),errors:m,open:b.llm,onOpenChange:()=>N("llm"),errorCount:0,sectionErrors:[]}),(0,a.jsx)(sv,{value:"object"==typeof d.systemPrompt&&"contributors"in d.systemPrompt?{contributors:d.systemPrompt.contributors||[]}:{contributors:[]},onChange:e=>c(t=>({...t,systemPrompt:e})),errors:m,open:b.systemPrompt,onOpenChange:()=>N("systemPrompt"),errorCount:0,sectionErrors:[]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>{o(ru),c(rx),p({}),g(null),s(!1)},disabled:j,children:"Cancel"}),(0,a.jsxs)(R.$,{onClick:k,disabled:j,children:[j&&(0,a.jsx)(Q.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Agent"]})]})]})})}function rp(e){let{mode:t="default"}=e,s=(0,o.useRouter)(),{currentLLM:r,currentSessionId:i}=(0,d.v)(),c=(0,tp.st)(),p=(0,n.useRef)(c),f=rd(e=>e.recentAgents),g=rd(e=>e.addRecentAgent),[v,j]=(0,n.useState)(!1),[b,y]=(0,n.useState)(!1),[N,w]=(0,n.useState)(!1);(0,n.useEffect)(()=>{p.current=c},[c]);let C=(0,l.jE)(),S=(0,n.useCallback)(e=>{let t=e.replace(/\\/g,"/").split("/").filter(Boolean).findIndex(e=>".dexto"===e);return t>=0&&t<=3},[]),{data:E,isLoading:I,refetch:T}=(0,m.I)({queryKey:x.l.agents.all,queryFn:async()=>{let e=await h.S.api.agents.$get();return await e.json()}}),{data:L}=(0,m.I)({queryKey:x.l.agents.path,queryFn:async()=>{let e=await h.S.api.agent.path.$get();return await e.json()},retry:!1}),O=(0,n.useMemo)(()=>(null==E?void 0:E.installed)||[],[null==E?void 0:E.installed]),D=(0,n.useMemo)(()=>(null==E?void 0:E.available)||[],[null==E?void 0:E.available]),F=(null==E?void 0:E.current.id)||null,_=null!=L?L:null,P=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.agents.switch.$post({json:e});return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.agents.all}),e.invalidateQueries({queryKey:x.l.agents.path})}})}(),M=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.agents.install.$post({json:e});return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.agents.all})}})}(),z=function(){let e=(0,l.jE)();return(0,u.n)({mutationFn:async e=>{let t=await h.S.api.agents.uninstall.$post({json:e});return await t.json()},onSuccess:()=>{e.invalidateQueries({queryKey:x.l.agents.all}),e.invalidateQueries({queryKey:x.l.agents.path})}})}();(0,n.useEffect)(()=>{(null==_?void 0:_.path)&&(null==_?void 0:_.name)&&g({id:_.name,name:_.name,path:_.path})},[_,g]);let U=(0,n.useCallback)(async e=>{try{j(!0);let t=O.find(t=>t.id===e);if(!t)throw console.error("Agent not found in installed list: ".concat(e)),Error("Agent '".concat(e,"' not found. Please refresh the agents list."));await P.mutateAsync({id:e}),y(!1),p.current.trackAgentSwitched({fromAgentId:F,toAgentId:e,toAgentName:t.name,sessionId:i||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:t.name}}))}catch(e){}s.push("/")}catch(t){console.error("Switch agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to switch agent";alert("Failed to switch agent: ".concat(e))}finally{j(!1)}},[O,s,F,i,P]),q=(0,n.useCallback)(async e=>{try{j(!0),await P.mutateAsync({id:e.id,path:e.path}),y(!1),g(e),p.current.trackAgentSwitched({fromAgentId:F,toAgentId:e.id,toAgentName:e.name,sessionId:i||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e.id,name:e.name}}))}catch(e){}s.push("/")}catch(t){console.error("Switch agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to switch agent";alert("Failed to switch agent: ".concat(e))}finally{j(!1)}},[g,s,F,i,P]),B=(0,n.useCallback)(async e=>{try{j(!0),await M.mutateAsync({id:e}),await C.refetchQueries({queryKey:x.l.agents.all});let t=C.getQueryData(x.l.agents.all),r=null==t?void 0:t.installed.find(t=>t.id===e);if(!r)throw Error("Agent '".concat(e,"' not found after installation. Please refresh."));await P.mutateAsync({id:e}),y(!1),p.current.trackAgentSwitched({fromAgentId:F,toAgentId:e,toAgentName:r.name,sessionId:i||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:r.name}}))}catch(e){}s.push("/")}catch(t){console.error("Install/switch agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to install/switch agent";alert("Failed to install/switch agent: ".concat(e))}finally{j(!1)}},[s,F,i,C,p,M,P]),$=(0,n.useCallback)(async(e,t)=>{if(t.stopPropagation(),confirm('Are you sure you want to delete the custom agent "'.concat(e.name,'"?')))try{j(!0),await z.mutateAsync({id:e.id})}catch(t){console.error("Delete agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to delete agent";alert("Failed to delete agent: ".concat(e))}finally{j(!1)}},[z]),W=(0,n.useMemo)(()=>{var e;if(!F)return"Choose Agent";let t=O.find(e=>e.id===F)||D.find(e=>e.id===F);return null!=(e=null==t?void 0:t.name)?e:F},[D,F,O]),K=(0,n.useCallback)(async e=>{await T()},[T]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(ez,{open:b,onOpenChange:y,children:[(0,a.jsx)(eU,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"badge"===t?"outline":"default",size:"sm",className:(e=>{let t="transition-all duration-200 shadow-lg hover:shadow-xl font-semibold rounded-full";switch(e){case"badge":return"h-9 px-4 text-xs border border-teal-500 bg-teal-500/20 text-teal-600 hover:bg-teal-500/40 hover:border-teal-500 hover:text-teal-700 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 dark:hover:border-teal-300 min-w-[100px] max-w-[140px] md:min-w-[140px] md:max-w-[240px] lg:max-w-[400px] xl:max-w-[500px] ".concat(t);case"title":return"h-11 px-4 text-lg font-bold bg-gradient-to-r from-teal-500/30 to-teal-500/40 text-teal-600 hover:from-teal-500/50 hover:to-teal-500/60 hover:text-teal-700 focus-visible:ring-2 focus-visible:ring-teal-500/50 focus-visible:ring-offset-2 border border-teal-500/40 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 ".concat(t);default:return"h-10 px-3 text-sm bg-teal-500/40 text-teal-600 hover:bg-teal-500/50 hover:text-teal-700 focus-visible:ring-2 focus-visible:ring-teal-500/50 focus-visible:ring-offset-2 border border-teal-500/50 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 ".concat(t)}})(t),disabled:v,children:(0,a.jsxs)("div",{className:"flex items-center justify-between w-full min-w-0",children:[(0,a.jsx)(e7.A,{className:"w-4 h-4 mr-2 flex-shrink-0"}),(0,a.jsx)("span",{className:"flex-1 text-center truncate min-w-0 px-1",children:v?"Switching...":"title"===t?"Agent: ".concat(W):W}),(0,a.jsx)(k.A,{className:"w-4 h-4 ml-2 flex-shrink-0"})]})})}),(0,a.jsxs)(eq,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[I&&(0,a.jsx)(eB,{disabled:!0,className:"text-center text-muted-foreground",children:"Loading agents..."}),!I&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eB,{onClick:()=>{w(!0),y(!1)},disabled:v,className:"cursor-pointer py-3 bg-gradient-to-r from-purple-500/10 to-purple-500/5 hover:from-purple-500/20 hover:to-purple-500/10 border-b border-purple-500/20",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,a.jsx)(e5.A,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),(0,a.jsx)("span",{className:"font-semibold text-purple-600 dark:text-purple-400",children:"New Agent"})]})}),_&&!O.some(e=>e.id===_.name)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-teal-600 dark:text-teal-400 uppercase tracking-wider",children:"Currently Active"}),(0,a.jsx)(eB,{onClick:()=>q({id:_.name,name:_.name,path:_.path}),disabled:v||F===_.name,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:_.name}),F===_.name&&(0,a.jsx)(A.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:"Loaded from file"})]})})}),(0,a.jsx)(e$,{})]}),f.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Recent"}),f.filter(e=>!O.some(t=>t.id===e.id)&&e.id!==(null==_?void 0:_.name)&&!S(e.path)).slice(0,3).map(e=>(0,a.jsx)(eB,{onClick:()=>q(e),disabled:v||e.id===F,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),e.id===F&&(0,a.jsx)(A.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",title:e.path,children:e.path})]})})},e.path)),(0,a.jsx)(e$,{})]}),O.filter(e=>"custom"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"px-2 py-1.5 text-xs font-semibold text-purple-600 dark:text-purple-400 uppercase tracking-wider flex items-center gap-1",children:[(0,a.jsx)(rc.A,{className:"w-3 h-3"}),"Custom Agents"]}),O.filter(e=>"custom"===e.type).map(e=>(0,a.jsx)(eB,{onClick:()=>U(e.id),disabled:v||e.id===F,className:"cursor-pointer py-3",children:(0,a.jsxs)("div",{className:"flex items-center justify-between w-full gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),e.id===F&&(0,a.jsx)(A.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]}),(0,a.jsx)("button",{onClick:t=>$(e,t),disabled:v,className:"p-1 hover:bg-red-100 dark:hover:bg-red-900/30 rounded transition-colors",title:"Delete custom agent",children:(0,a.jsx)(tA.A,{className:"w-4 h-4 text-red-600 dark:text-red-400"})})]})},e.id))]}),O.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[O.filter(e=>"custom"===e.type).length>0&&(0,a.jsx)(e$,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Installed"}),O.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eB,{onClick:()=>U(e.id),disabled:v||e.id===F,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),e.id===F&&(0,a.jsx)(A.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]})})},e.id))]}),D.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[O.length>0&&(0,a.jsx)(e$,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Available"}),D.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eB,{onClick:()=>B(e.id),disabled:v,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),(0,a.jsx)(rm.A,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]})})},e.id))]}),!I&&0===O.length&&0===D.length&&(0,a.jsx)(eB,{disabled:!0,className:"text-center text-muted-foreground",children:"No agents found"})]})]})]}),(0,a.jsx)(rh,{open:N,onOpenChange:w,onAgentCreated:K})]})}function rf(){let{sessionId:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,o.useRouter)(),{messages:s,sendMessage:r,currentSessionId:m,switchSession:u,isWelcomeState:b,returnToWelcome:y,activeError:w,clearError:C,processing:S,cancel:E,greeting:I,isStreaming:D,setStreaming:F}=(0,d.v)(),{theme:_,toggleTheme:P}=c(),{mutateAsync:M}=(0,v.Mb)(),{mutateAsync:z}=f(),[U,q]=(0,n.useState)(!1),[B,$]=(0,n.useState)(!1),[W,Y]=(0,n.useState)(!1),[G,Q]=(0,n.useState)(!1),[H,J]=(0,n.useState)(!1),Z=n.useRef(!0),[X,ee]=(0,n.useState)(!1),[et,es]=(0,n.useState)(!1),[er,ea]=(0,n.useState)(!1),[en,ei]=(0,n.useState)(!1),[el,eo]=(0,n.useState)(!1),[ed,ec]=(0,n.useState)("dexto-config"),[em,eu]=(0,n.useState)(null),[ex,eh]=(0,n.useState)(""),[ep,ef]=(0,n.useState)(!1),[eg,ev]=(0,n.useState)(null),[ej,eb]=(0,n.useState)(!1),[ey,eN]=(0,n.useState)(!1),[ew,eC]=(0,n.useState)(!1),[eA,eS]=(0,n.useState)(null),[eE,eI]=(0,n.useState)(!1),[eT,eO]=(0,n.useState)(null),[eD,eF]=(0,n.useState)(null),e_=(0,l.jE)(),eP=g(),{data:eM=[],isLoading:eW}=p({enabled:b}),eK=eM.filter(e=>{var t;return(null==(t=e.metadata)?void 0:t.showInStarters)===!0}),eV=!eW;(0,n.useEffect)(()=>{let e=()=>{e_.invalidateQueries({queryKey:x.l.prompts.all})};return window.addEventListener("dexto:agentSwitched",e),()=>{window.removeEventListener("dexto:agentSwitched",e)}},[e_]);let eY=n.useRef(null),eG=n.useRef(null),[eQ,e0]=(0,n.useState)(!0),[e1,e2]=(0,n.useState)(!1),[e5,e4]=(0,n.useState)(!1),e3=n.useRef(0),[e7,e9]=(0,n.useState)(!1),te=n.useRef(null),[tt,ts]=(0,n.useState)(0),[tr,ta]=(0,n.useState)(null),[tn,ti]=(0,n.useState)(!1);(0,n.useEffect)(()=>{var e;let t=()=>{var e,t;if("undefined"==typeof document)return;let s=null!=(t=null==(e=window.visualViewport)?void 0:e.height)?t:window.innerHeight;document.documentElement.style.setProperty("--app-viewport-height","".concat(s,"px"))};return t(),window.addEventListener("resize",t),window.addEventListener("orientationchange",t),null==(e=window.visualViewport)||e.addEventListener("resize",t),()=>{var e;window.removeEventListener("resize",t),window.removeEventListener("orientationchange",t),null==(e=window.visualViewport)||e.removeEventListener("resize",t)}},[]);let tl=(0,n.useCallback)(()=>{let e=eY.current;e&&e0(e.scrollHeight-e.scrollTop<=e.clientHeight+1)},[]),to=(0,n.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auto",t=eY.current;t&&(e2(!0),t.scrollTo({top:t.scrollHeight,behavior:e}),requestAnimationFrame(()=>e2(!1)))},[]);(0,n.useEffect)(()=>{let e=eY.current;if(!e)return;let t=()=>{let t=e3.current,s=e.scrollTop;!e1&&e5&&s<t&&e4(!1),e3.current=s,tl(),e.scrollHeight-e.scrollTop<=e.clientHeight+1?(e9(!1),te.current&&(window.clearTimeout(te.current),te.current=null)):(e9(!1),te.current&&window.clearTimeout(te.current),te.current=window.setTimeout(()=>{e9(!0)},180))};return e.addEventListener("scroll",t),tl(),()=>e.removeEventListener("scroll",t)},[tl,e5,e1,b]),(0,n.useEffect)(()=>{let e=eG.current;if(!e)return;let t=new ResizeObserver(()=>{!e1&&(e5||eQ)&&to("auto")});return t.observe(e),()=>t.disconnect()},[eQ,e1,e5,to,b]),(0,n.useEffect)(()=>{e5&&to("auto")},[e5,s,to]);let td=(0,n.useCallback)(()=>{let e=eY.current;if(!e)return;let t=e.querySelectorAll('[data-role="user"]'),s=t[t.length-1];if(!s)return void to("auto");let r=e.getBoundingClientRect(),a=Math.max(s.getBoundingClientRect().top-r.top+e.scrollTop-16,0);e2(!0),e.scrollTo({top:a,behavior:"auto"}),requestAnimationFrame(()=>e2(!1))},[to]);(0,n.useEffect)(()=>{et?(async()=>{try{let e=await h.S.api.agent.config.export.$get({query:m?{sessionId:m}:{}});if(!e.ok)throw Error("Failed to fetch configuration");let t=await e.text();eh(t),eu(null)}catch(e){console.error("Preview fetch failed:",e),eu(e instanceof Error?e.message:"Preview fetch failed")}})():(eh(""),eu(null),ef(!1))},[et,m]);let tc=(0,n.useCallback)(async()=>{try{let e=await h.S.api.agent.config.export.$get({query:m?{sessionId:m}:{}});if(!e.ok)throw Error("Failed to fetch configuration");let t=await e.text(),s=new Blob([t],{type:"application/x-yaml"}),r=URL.createObjectURL(s),a=document.createElement("a");a.href=r,a.download=m?"".concat(ed,"-").concat(m,".yml"):"".concat(ed,".yml"),document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r)}catch(e){console.error("Download failed:",e),eu(e instanceof Error?e.message:"Download failed")}},[ed,m]),tm=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(ex),ef(!0),setTimeout(()=>ef(!1),2e3)}catch(e){console.error("Copy failed:",e),eu("Failed to copy to clipboard")}},[ex]),tu=(0,n.useCallback)(async(e,t,s)=>{eN(!0),eS(null);try{await r(e,t,s),setTimeout(()=>{td(),e4(!0)},0)}catch(e){console.error("Failed to send message:",e),eS(e instanceof Error?e.message:"Failed to send message"),setTimeout(()=>eS(null),5e3)}finally{eN(!1)}},[r,td]);(0,n.useEffect)(()=>{let e=()=>e4(!0),t=()=>e4(!1);return window.addEventListener("dexto:message",e),window.addEventListener("dexto:response",t),()=>{window.removeEventListener("dexto:message",e),window.removeEventListener("dexto:response",t)}},[]);let tx=(0,n.useCallback)(e=>{e4(!1),e9(!1),t.push("/chat/".concat(e))},[t]),th=(0,n.useCallback)(()=>{e4(!1),e9(!1),y(),t.push("/")},[t,y]);(0,n.useEffect)(()=>{J(!0),"true"===localStorage.getItem("sessionsPanelOpen")&&Q(!0),setTimeout(()=>{Z.current=!1},0)},[]),(0,n.useEffect)(()=>{H&&localStorage.setItem("sessionsPanelOpen",G.toString())},[G,H]),(0,n.useEffect)(()=>{e&&e!==m&&(e4(!1),e9(!1),u(e))},[e,m,u]),(0,n.useEffect)(()=>{e||b||y()},[e,b,y]);let tp=(0,n.useCallback)(async e=>{let t=t0(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tX(t.env||{}),r=("sse"===t.type||"http"===t.type)&&"headers"in t&&Object.keys(t.headers||{}).length>0&&tX(t.headers||{});if(s||r){var a;return ta({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:null!=(a=e.onCloseRegistryModal)?a:()=>$(!1)}),q(!0),"requires-input"}try{if(ti(!0),await M({name:e.name,config:t,persistToAgent:!1}),e.id)try{await tD.setInstalled(e.id,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}return ts(e=>e+1),ev("Added ".concat(e.name)),setTimeout(()=>ev(null),4e3),$(!1),"connected"}catch(e){throw Error(e instanceof Error?e.message:"Failed to install server")}finally{ti(!1)}},[M,$,q,ta,ts,ev,ti]),tf=(0,n.useCallback)(()=>{window.innerWidth<768&&W&&Y(!1),Q(!G)},[G,W]),tg=(0,n.useCallback)(()=>{window.innerWidth<768&&G&&Q(!1),Y(!W)},[W,G]),tv=(0,n.useCallback)(async()=>{if(m)try{await eP.mutateAsync({sessionId:m}),eI(!1),th()}catch(e){console.error("Failed to delete conversation:",e),eS(e instanceof Error?e.message:"Failed to delete conversation"),setTimeout(()=>eS(null),5e3)}},[m,th]),tj=n.useMemo(()=>[{title:"Help me get started",description:"Show me what you can do",action:()=>tu("I'm new to Dexto. Can you show me your capabilities and help me understand how to work with you effectively?"),icon:"\uD83D\uDE80"},{title:"Create Snake Game",description:"Build a game and open it",action:()=>tu("Create a snake game in a new directory with HTML, CSS, and JavaScript, then open it in the browser for me to play."),icon:"\uD83D\uDC0D"},{title:"Connect new tools",description:"Browse and add MCP servers",action:()=>Y(!0),icon:"\uD83D\uDD27"},{title:"Demonstrate tools",description:"Show me your capabilities",action:()=>tu("Pick one of your most interesting tools and demonstrate it with a practical example. Show me what it can do."),icon:"⚡"}],[tu,Y]),tb=n.useMemo(()=>{if(!eV)return tj.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));let e=eK.length>0?[]:tj.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));return eK.forEach(t=>{let s=t.title||t.description||"Starter prompt",r=t.description;(null==t?void 0:t.name)==="starter:connect-tools"?e.push({description:s,tooltip:r,action:()=>Y(!0)}):e.push({description:s,tooltip:r,action:async()=>{try{let e=await z({name:t.name});e.text.trim()?tu(e.text.trim()):tu("/".concat(t.name))}catch(e){console.error("Failed to resolve starter prompt ".concat(t.name,":"),e),tu("/".concat(t.name))}}})}),e},[eK,eV,tj,tu,Y,z]);return(0,i.vC)("mod+backspace",()=>{m&&!b&&(s.length>0?eI(!0):tv())},{preventDefault:!0},[m,b,s.length,tv]),(0,i.vC)("mod+h",tf,{preventDefault:!0},[tf]),(0,i.vC)("mod+k",th,{preventDefault:!0},[th]),(0,i.vC)("mod+j",tg,{preventDefault:!0},[tg]),(0,i.vC)("mod+m",()=>eo(e=>!e),{preventDefault:!0}),(0,i.vC)("mod+shift+s",()=>ee(!0),{preventDefault:!0}),(0,i.vC)("mod+l",()=>window.open("/playground","_blank"),{preventDefault:!0}),(0,i.vC)("mod+e",()=>ei(e=>!e),{preventDefault:!0}),(0,i.vC)("mod+shift+e",()=>es(!0),{preventDefault:!0}),(0,i.vC)("mod+slash",()=>eC(!0),{preventDefault:!0}),(0,i.vC)("escape",()=>{en?ei(!1):W?Y(!1):G?Q(!1):el?eo(!1):B?$(!1):et?es(!1):ew?eC(!1):eE?eI(!1):eA?eS(null):S&&E(m||void 0)},[en,W,G,el,B,et,ew,eE,eA,S,E,m]),(0,a.jsxs)("div",{className:"flex w-full bg-background",style:{height:"var(--app-viewport-height, 100vh)",minHeight:"var(--app-viewport-height, 100vh)"},children:[(0,a.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 border-r border-border/50 bg-card/50 backdrop-blur-sm",!Z.current&&"transition-all duration-300 ease-in-out",G?"w-80":"w-0 overflow-hidden"),suppressHydrationWarning:!0,children:G&&(0,a.jsx)(t8,{isOpen:G,onClose:()=>Q(!1),currentSessionId:m,onSessionChange:tx,returnToWelcome:th,variant:"inline",onSearchOpen:()=>ee(!0),onNewChat:th})}),(0,a.jsx)("div",{className:"md:hidden",children:(0,a.jsx)(t8,{isOpen:G,onClose:()=>Q(!1),currentSessionId:m,onSessionChange:tx,returnToWelcome:th,variant:"overlay",onSearchOpen:()=>ee(!0),onNewChat:th})}),(0,a.jsxs)("main",{className:"flex-1 flex flex-col relative min-w-0",style:{"--thread-max-width":"54rem"},children:[null,(0,a.jsxs)("header",{className:"shrink-0 border-b border-border/50 bg-background/95 backdrop-blur-xl shadow-sm relative",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:tf,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",G&&"bg-muted"),children:(0,a.jsx)(s3.A,{className:"h-4 w-4"})})}),(0,a.jsx)(O,{children:"Chat History (⌘H)"})]}),!G&&(0,a.jsx)("div",{className:"hidden md:block",children:(0,a.jsx)(t4,{onClick:th})}),(0,a.jsxs)("a",{href:"https://dexto.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center hover:opacity-80 transition-opacity shrink-0",children:[(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-9 w-9 md:hidden"}),(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-11 w-auto hidden md:block dark:md:hidden"}),(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-11 w-auto hidden dark:md:block"}),(0,a.jsx)("span",{className:"sr-only",children:"Dexto"})]})]}),(0,a.jsxs)("div",{className:"hidden md:flex items-center gap-2",children:[(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>ei(!en),className:(0,j.cn)("h-8 w-8 p-0",en&&"bg-muted"),"aria-label":"Customize agent",children:(0,a.jsx)(s8.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{children:"Customize Agent (⌘E)"})]}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:tg,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",W&&"bg-muted"),"aria-label":"Toggle tools panel",children:(0,a.jsx)(K.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{children:"Toggle tools panel (⌘J)"})]}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>eo(!el),className:(0,j.cn)("h-8 w-8 p-0 transition-colors",el&&"bg-muted"),"aria-label":"Toggle memories panel",children:(0,a.jsx)(V.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{children:"Toggle memories panel (⌘M)"})]}),(0,a.jsx)(rr,{}),(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",onClick:()=>ea(!0),className:"h-8 w-8 p-0","aria-label":"Open settings",children:(0,a.jsx)(sn.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(O,{children:"Settings"})]}),(0,a.jsxs)(ez,{children:[(0,a.jsx)(eU,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:(0,a.jsx)(s6.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsxs)(eq,{align:"end",children:[(0,a.jsxs)(eB,{onClick:()=>$(!0),children:[(0,a.jsx)(tz.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,a.jsxs)(eB,{onClick:()=>window.open("/playground","_blank"),children:[(0,a.jsx)(e6.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,a.jsxs)(eB,{onClick:()=>es(!0),children:[(0,a.jsx)(s7.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,a.jsxs)(eB,{onClick:()=>eC(!0),children:[(0,a.jsx)(s9.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),m&&!b&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e$,{}),(0,a.jsxs)(eB,{onClick:()=>eI(!0),className:"text-destructive focus:text-destructive",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})]}),(0,a.jsx)("div",{className:"flex md:hidden",children:(0,a.jsxs)(ez,{open:ej,onOpenChange:eb,children:[(0,a.jsx)(eU,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Open menu",children:(0,a.jsx)(re.A,{className:"h-4 w-4"})})}),(0,a.jsxs)(eq,{align:"end",children:[(0,a.jsxs)(eB,{onClick:()=>{ei(!en),eb(!1)},children:[(0,a.jsx)(s8.A,{className:"h-4 w-4 mr-2"}),"Customize Agent"]}),(0,a.jsxs)(eB,{onClick:()=>{tg(),eb(!1)},children:[(0,a.jsx)(K.A,{className:"h-4 w-4 mr-2"}),"Tools"]}),(0,a.jsxs)(eB,{onClick:()=>{eo(!el),eb(!1)},children:[(0,a.jsx)(V.A,{className:"h-4 w-4 mr-2"}),"Memories"]}),(0,a.jsxs)(eB,{onClick:()=>{P("light"===_),eb(!1)},children:[(0,a.jsx)("span",{className:"h-4 w-4 mr-2",children:"\uD83C\uDF19"}),"Toggle Theme"]}),(0,a.jsxs)(eB,{onClick:()=>{ea(!0),eb(!1)},children:[(0,a.jsx)(sn.A,{className:"h-4 w-4 mr-2"}),"Settings"]}),(0,a.jsxs)(eB,{onClick:e=>{e.preventDefault(),F(!D)},className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(eL.A,{className:"h-4 w-4 mr-2"}),"Streaming"]}),(0,a.jsx)(eR,{checked:D,onCheckedChange:F,onClick:e=>e.stopPropagation()})]}),(0,a.jsx)(e$,{}),(0,a.jsxs)(eB,{onClick:()=>{$(!0),eb(!1)},children:[(0,a.jsx)(tz.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,a.jsxs)(eB,{onClick:()=>{window.open("/playground","_blank"),eb(!1)},children:[(0,a.jsx)(e6.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,a.jsxs)(eB,{onClick:()=>{es(!0),eb(!1)},children:[(0,a.jsx)(s7.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,a.jsxs)(eB,{onClick:()=>{eC(!0),eb(!1)},children:[(0,a.jsx)(s9.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),m&&!b&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e$,{}),(0,a.jsxs)(eB,{onClick:()=>{eI(!0),eb(!1)},className:"text-destructive focus:text-destructive",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})})]}),(0,a.jsx)("div",{className:"absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2",children:(0,a.jsx)("div",{className:"w-full max-w-[180px] md:max-w-[260px]",children:(0,a.jsx)(rp,{mode:"badge"})})})]}),(0,a.jsxs)("div",{className:"flex-1 flex overflow-hidden min-w-0",children:[eg&&(0,a.jsxs)("div",{className:"fixed bottom-4 right-4 z-50 border border-border/60 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 text-foreground px-3 py-2 rounded-md shadow-md inline-flex items-center gap-2",children:[(0,a.jsx)(A.A,{className:"h-4 w-4 text-green-600"}),(0,a.jsx)("span",{className:"text-sm",children:eg})]}),eA&&(0,a.jsx)("div",{className:"absolute top-4 right-4 z-50 bg-destructive text-destructive-foreground px-4 py-2 rounded-md shadow-lg",children:eA}),(0,a.jsx)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:b?(0,a.jsx)("div",{className:"flex-1 flex flex-col justify-end sm:justify-center p-6 sm:-mt-20",children:(0,a.jsxs)("div",{className:"w-full max-w-full sm:max-w-[var(--thread-max-width)] mx-auto space-y-6 pb-safe",children:[(0,a.jsxs)("div",{className:"text-center space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-12 w-auto"}),(0,a.jsx)("h2",{className:"text-2xl font-bold font-mono tracking-tight bg-gradient-to-r from-primary to-primary/70 bg-clip-text",children:I||"Welcome to Dexto"})]}),(0,a.jsx)("p",{className:"text-base text-muted-foreground max-w-xl mx-auto leading-relaxed",children:"Your AI assistant with powerful tools. Ask anything or connect new capabilities."})]}),(0,a.jsx)("div",{className:"flex flex-wrap justify-center gap-2 max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:tb.map((e,t)=>{let s=(0,a.jsx)("button",{onClick:e.action,className:"group px-3 py-2 text-left rounded-full bg-primary/5 hover:bg-primary/10 transition-all duration-200 hover:shadow-sm hover:scale-105",children:(0,a.jsx)("span",{className:"font-medium text-sm text-primary group-hover:text-primary/80 transition-colors",children:e.description})},t);return e.tooltip?(0,a.jsxs)(T,{children:[(0,a.jsx)(L,{asChild:!0,children:s}),(0,a.jsx)(O,{children:e.tooltip})]},t):s})}),(0,a.jsx)("div",{className:"max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:(0,a.jsx)(tT,{onSend:tu,isSending:ey,variant:"welcome"})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground space-y-1 text-center",children:(0,a.jsxs)("p",{children:["\uD83D\uDCA1 Try",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘K"})," ","for new chat,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘J"})," ","for tools,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘L"})," ","for playground,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘⌫"})," ","to delete session,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘/"})," ","for shortcuts"]})})]})}):(0,a.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden min-w-0",children:(0,a.jsx)("div",{ref:eY,className:"h-full overflow-y-auto overflow-x-hidden overscroll-contain relative min-w-0",children:(0,a.jsxs)("div",{className:"min-h-full grid grid-cols-1 grid-rows-[1fr_auto] min-w-0",children:[(0,a.jsx)("div",{className:"w-full max-w-full sm:max-w-[var(--thread-max-width)] mx-0 sm:mx-auto min-w-0",children:(0,a.jsx)(ek,{messages:s,processing:S,activeError:w,onDismissError:C,outerRef:eG,pendingApproval:eT,onApprovalApprove:null==eD?void 0:eD.onApprove,onApprovalDeny:null==eD?void 0:eD.onDeny})}),(0,a.jsxs)("div",{className:"sticky bottom-0 z-10 px-0 sm:px-4 pt-2 pb-2 bg-background relative",style:{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 0.5rem)",marginBottom:"calc(env(safe-area-inset-bottom, 0px) * -1)"},children:[e7&&(0,a.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 -top-3 z-20 pointer-events-none",children:(0,a.jsxs)("button",{onClick:()=>{e9(!1),to("smooth")},className:"pointer-events-auto px-3 py-1.5 rounded-full shadow-sm bg-background/95 border border-border/60 backdrop-blur supports-[backdrop-filter]:bg-background/80 text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1.5",children:[(0,a.jsx)("span",{children:"Scroll to bottom"}),(0,a.jsx)(k.A,{className:"h-3.5 w-3.5"})]})}),(0,a.jsx)("div",{className:"w-full max-w-full sm:max-w-[var(--thread-max-width)] mx-0 sm:mx-auto pointer-events-auto",children:(0,a.jsx)(tT,{onSend:tu,isSending:ey,variant:"chat"})})]})]})})})}),(0,a.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 transition-all duration-300 ease-in-out border-l border-border/50 bg-card/50 backdrop-blur-sm",W?"w-80":"w-0 overflow-hidden"),children:W&&(0,a.jsx)(t1,{isOpen:W,onClose:()=>Y(!1),onOpenConnectModal:()=>q(!0),onOpenConnectWithPrefill:e=>{ta(e),q(!0)},onServerConnected:e=>{ts(e=>e+1),ev("Added ".concat(e)),setTimeout(()=>ev(null),4e3)},variant:"inline",refreshTrigger:tt})}),(0,a.jsx)("div",{className:"md:hidden",children:(0,a.jsx)(t1,{isOpen:W,onClose:()=>Y(!1),onOpenConnectModal:()=>q(!0),onOpenConnectWithPrefill:e=>{ta(e),q(!0)},onServerConnected:e=>{ts(e=>e+1),ev("Added ".concat(e)),setTimeout(()=>ev(null),4e3)},variant:"overlay",refreshTrigger:tt})})]}),(0,a.jsx)(s4,{isOpen:en,onClose:()=>ei(!1),variant:"overlay"}),(0,a.jsx)(tL.A,{isOpen:U,onClose:()=>{q(!1),ti(!1),ta(null)},onServerConnected:async()=>{var e;if(null==tr?void 0:tr.registryEntryId)try{await tD.setInstalled(tr.registryEntryId,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}ts(e=>e+1);let t=(null==tr?void 0:tr.name)||"Server";ev("Added ".concat(t)),setTimeout(()=>ev(null),4e3),null==tr||null==(e=tr.onCloseRegistryModal)||e.call(tr),ti(!1),ta(null)},initialName:null==tr?void 0:tr.name,initialConfig:null==tr?void 0:tr.config,lockName:null==tr?void 0:tr.lockName}),(0,a.jsx)(tK,{isOpen:B,onClose:()=>$(!1),onInstallServer:tp,onOpenConnectModal:()=>q(!0),refreshTrigger:tt,disableClose:tn}),(0,a.jsx)(eH.lG,{open:et,onOpenChange:es,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-2xl",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsxs)(eH.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(s7.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{children:"Export Configuration"})]}),(0,a.jsxs)(eH.rr,{children:["Download your tool configuration for Claude Desktop or other MCP clients",m&&(0,a.jsxs)("span",{className:"block mt-1 text-sm text-muted-foreground",children:["Including session-specific settings for:"," ",(0,a.jsx)("span",{className:"font-mono",children:m})]})]})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{htmlFor:"filename",children:"File name"}),(0,a.jsx)(eZ.p,{id:"filename",value:ed,onChange:e=>ec(e.target.value),placeholder:"dexto-config",className:"font-mono"})]}),em&&(0,a.jsxs)(eJ.Fc,{variant:"destructive",children:[(0,a.jsx)(N.A,{className:"h-4 w-4"}),(0,a.jsx)(eJ.XL,{children:"Export Error"}),(0,a.jsx)(eJ.TN,{children:em})]}),ex&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eX.J,{children:"Configuration Preview"}),(0,a.jsx)(tk.T,{value:ex,readOnly:!0,className:"h-32 font-mono text-xs bg-muted/30"})]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:tm,className:"flex items-center space-x-2",children:(0,a.jsx)("span",{children:ep?"Copied!":"Copy"})}),(0,a.jsxs)(R.$,{onClick:tc,className:"flex items-center space-x-2",children:[(0,a.jsx)(s7.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Download"})]})]})]})}),(0,a.jsx)(ri,{isOpen:er,onClose:()=>ea(!1)}),(0,a.jsx)(t9,{isOpen:el,onClose:()=>eo(!1),variant:"modal"}),(0,a.jsx)(eH.lG,{open:eE,onOpenChange:eI,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eH.c7,{children:[(0,a.jsxs)(eH.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eH.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",m&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session:"," ",(0,a.jsx)("span",{className:"font-mono",children:m})]})]})]}),(0,a.jsxs)(eH.Es,{children:[(0,a.jsx)(R.$,{variant:"outline",onClick:()=>eI(!1),children:"Cancel"}),(0,a.jsxs)(R.$,{variant:"destructive",onClick:tv,disabled:eP.isPending,className:"flex items-center space-x-2",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:eP.isPending?"Deleting...":"Delete Conversation"})]})]})]})}),(0,a.jsx)(eH.lG,{open:ew,onOpenChange:eC,children:(0,a.jsxs)(eH.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eH.c7,{children:(0,a.jsxs)(eH.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(s9.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{children:"Keyboard Shortcuts"})]})}),(0,a.jsx)("div",{className:"space-y-3",children:[{key:"⌘H",desc:"Toggle chat history panel"},{key:"⌘K",desc:"Create new chat"},{key:"⌘J",desc:"Toggle tools panel"},{key:"⌘M",desc:"Toggle memories panel"},{key:"⌘E",desc:"Customize agent"},{key:"⌘⇧S",desc:"Search conversations"},{key:"⌘L",desc:"Open MCP playground"},{key:"⌘⇧E",desc:"Export config"},{key:"⌘/",desc:"Show shortcuts"},{key:"⌘⌫",desc:"Delete current session"},{key:"Esc",desc:"Close panels"}].map((e,t)=>(0,a.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:e.desc}),(0,a.jsx)(e8.E,{variant:"outline",className:"font-mono text-xs",children:e.key})]},t))}),(0,a.jsx)(eH.Es,{children:(0,a.jsx)(eH.HM,{asChild:!0,children:(0,a.jsx)(R.$,{variant:"outline",children:"Close"})})})]})})]}),(0,a.jsx)(sl,{isOpen:X,onClose:()=>ee(!1),onNavigateToSession:(e,s)=>{t.push("/chat/".concat(e)),ee(!1)}}),(0,a.jsx)(sr,{onApprovalRequest:eO,onHandlersReady:eF})]})}}}]);