dexto 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics/index.js +1 -2
- package/dist/webui/.next/{static/chunks/656-5a9f6405badf66a8.js → standalone/.next/static/chunks/369-7a58b346e80ec351.js} +2 -2
- package/dist/webui/.next/standalone/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
- package/dist/webui/.next/standalone/.next/static/chunks/560-551d60414365cdc4.js +1 -0
- package/dist/webui/.next/standalone/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
- package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
- package/dist/webui/.next/standalone/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
- package/dist/webui/.next/standalone/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
- package/dist/webui/.next/standalone/package.json +3 -2
- package/dist/webui/.next/standalone/packages/webui/.next/BUILD_ID +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/app-build-manifest.json +13 -10
- package/dist/webui/.next/standalone/packages/webui/.next/build-manifest.json +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/prerender-manifest.json +3 -3
- package/dist/webui/.next/standalone/packages/webui/.next/required-server-files.json +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page.js +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js.nft.json +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page_client-reference-manifest.js +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js.nft.json +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js +3 -3
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js.nft.json +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page_client-reference-manifest.js +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/1.js +4 -4
- package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/695.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/{426.js → 710.js} +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/server/pages/500.html +1 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/server-reference-manifest.json +1 -1
- package/dist/webui/.next/standalone/{.next/static/chunks/656-5a9f6405badf66a8.js → packages/webui/.next/static/chunks/369-7a58b346e80ec351.js} +2 -2
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/560-551d60414365cdc4.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
- package/dist/webui/.next/standalone/packages/webui/package.json +3 -1
- package/dist/webui/.next/standalone/packages/webui/server.js +1 -1
- package/dist/webui/.next/{standalone/packages/webui/.next/static/chunks/656-5a9f6405badf66a8.js → static/chunks/369-7a58b346e80ec351.js} +2 -2
- package/dist/webui/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
- package/dist/webui/.next/static/chunks/560-551d60414365cdc4.js +1 -0
- package/dist/webui/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
- package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
- package/dist/webui/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
- package/dist/webui/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
- package/dist/webui/package.json +3 -1
- package/package.json +3 -3
- package/dist/webui/.next/standalone/.next/static/chunks/419-6d449dcb2b056299.js +0 -1
- package/dist/webui/.next/standalone/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
- package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
- package/dist/webui/.next/standalone/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
- package/dist/webui/.next/standalone/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/43.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-6d449dcb2b056299.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
- package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
- package/dist/webui/.next/static/chunks/419-6d449dcb2b056299.js +0 -1
- package/dist/webui/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
- package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
- package/dist/webui/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
- package/dist/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
- /package/dist/webui/.next/standalone/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
- /package/dist/webui/.next/standalone/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
- /package/dist/webui/.next/standalone/packages/webui/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
- /package/dist/webui/.next/standalone/packages/webui/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
- /package/dist/webui/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
- /package/dist/webui/.next/static/{uqfH8SY_uhwdc0ZkpMwCO → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[419],{5034:(e,t,s)=>{"use strict";s.d(t,{default:()=>rt});var r,a=s(5801),n=s(5789),i=s(9401),l=s(826),o=s(9854),c=s(6032),d=s(1236),m=s(9752),u=s(1295),x=s(7891),h=s(4590),p=s(1828),f=s(9198),g=s(8537),v=s(4398);function j(e){let{delayDuration:t=0,...s}=e;return(0,a.jsx)(v.Kq,{"data-slot":"tooltip-provider",delayDuration:t,...s})}function b(e){let{...t}=e;return(0,a.jsx)(j,{children:(0,a.jsx)(v.bL,{"data-slot":"tooltip",...t})})}function y(e){let{...t}=e;return(0,a.jsx)(v.l9,{"data-slot":"tooltip-trigger",...t})}function N(e){let{className:t,sideOffset:s=0,children:r,...n}=e;return(0,a.jsx)(v.ZL,{children:(0,a.jsxs)(v.UC,{"data-slot":"tooltip-content",sideOffset:s,className:(0,c.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)(v.i3,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}var w=s(5315);let k=(0,n.forwardRef)((e,t)=>{let{children:s,tooltip:r,side:n="bottom",className:i,...l}=e;return(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)(w.$,{variant:"ghost",size:"icon",...l,className:(0,c.cn)("size-6 p-1",i),ref:t,children:[s,(0,a.jsx)("span",{className:"sr-only",children:r})]})}),(0,a.jsx)(N,{side:n,children:r})]})});function C(e){let{value:t,tooltip:s="Copy",copiedTooltip:r="Copied!",className:i,size:l=12}=e,[o,c]=(0,n.useState)(!1);return(0,a.jsx)(k,{tooltip:o?r:s,onClick:()=>{navigator.clipboard.writeText(t).then(()=>{c(!0),setTimeout(()=>c(!1),2e3)}).catch(()=>{})},className:i,children:o?(0,a.jsx)(f.A,{size:l}):(0,a.jsx)(g.A,{size:l})})}k.displayName="TooltipIconButton";var S=s(8559),A=s(7338);class E{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 I=globalThis,T=null!=(r=I.__speechController)?r:I.__speechController=new E;function O(e){let{value:t,tooltip:s="Speak",stopTooltip:r="Stop",className:i,rate:l=1,pitch:o=1,lang:c}=e,[d,m]=(0,n.useState)(!1),u=T.supported,x=(null!=t?t:"").trim().length>0;return(0,n.useEffect)(()=>(m(T.isSpeaking()),T.subscribe(()=>m(T.isSpeaking()))),[]),(0,a.jsx)(k,{tooltip:d?r:s,onClick:()=>{if(u&&x){if(d)return T.stop();T.speak(t,{rate:l,pitch:o,lang:c})}},className:i,disabled:!u||!x,children:d?(0,a.jsx)(S.A,{size:12}):(0,a.jsx)(A.A,{size:12})})}function L(e){var t;let{error:s,onDismiss:r}=e,[i,l]=(0,n.useState)(!1),o=null==(t=s.detailedIssues)?void 0:t[0],c=(null==o?void 0:o.context)&&"object"==typeof o.context&&"detailedIssues"in o.context?o.context.detailedIssues:[],d=c.length>0?"".concat(s.message,"\n\nDetails:\n").concat(c.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)(u.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:[c.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)(x.A,{className:"h-4 w-4"}):(0,a.jsx)(h.A,{className:"h-4 w-4"})}),(0,a.jsx)(C,{value:d,tooltip:"Copy error",className:"p-1 hover:bg-destructive/15 rounded text-destructive",size:16}),(0,a.jsx)(O,{value:d,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)(p.A,{className:"h-4 w-4"})})]})]}),(0,a.jsx)("div",{className:"mt-2 text-sm text-destructive",children:s.message}),i&&c.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:c.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 R=s(8667),F=s(8109),P=s(9597),D=s(732),_=s(5192),M=s(530),z=s(2913),U=s(8369),B=s(36),q=s(198),$=s(3801),W=s(2125),K=s(7564),V=s(395),Y=s(4439),J=s(5107),G=s(4881);function H(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 Z(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 Q(e,t){return!!(e.startsWith("blob:")||Z(e))||!!e.startsWith("data:")&&(t?H(e,t):H(e))}let X=(0,n.memo)(e=>{let{children:t}=e,s=n.useRef(new Set);return n.useEffect(()=>()=>{s.current.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)(Y.oz,{remarkPlugins:[J.A,G.A],skipHtml:!0,components:{a:e=>{let{href:t,children:s,...r}=e,n=null!=t?t:"";return/^https?:\/\//i.test(n)&&Z(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)&&Q(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)&&Q(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})]}):Q(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)?Z(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: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)(k,{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)(f.A,{size:14}):(0,a.jsx)(g.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})}},children:t})})});function ee(e){let t=(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},[e.join("|")]),[s,r]=(0,n.useState)({}),a=(0,n.useRef)({}),l=(0,n.useRef)(new Set);return(0,n.useEffect)(()=>{a.current=s},[s]),(0,n.useEffect)(()=>{t.forEach(e=>{if(!e)return;let t=a.current[e];(!t||"error"===t.status)&&(l.current.has(e)||(l.current.add(e),r(t=>({...t,[e]:{status:"loading"}})),(async()=>{try{let t=await fetch("".concat((0,i.e)(),"/api/resources/").concat(encodeURIComponent(e),"/content"));if(!t.ok)throw Error("HTTP ".concat(t.status));let s=await t.json(),a=null==s?void 0:s.content;if(!a)throw Error("No content returned for resource");let n=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,a);r(t=>({...t,[e]:{status:"loaded",data:n}}))}catch(s){let t=s instanceof Error?s.message:String(s);r(s=>({...s,[e]:{status:"error",error:t}}))}finally{l.current.delete(e)}})()))})},[t]),s}let et=null,es=null,er=null;async function ea(){let e=await fetch("".concat((0,i.e)(),"/api/resources"));if(!e.ok){let t=await e.text().catch(()=>"");throw Error(t?"HTTP ".concat(e.status,": ").concat(t):"HTTP ".concat(e.status))}let t=await e.json();if(!t||!t.ok||!Array.isArray(t.resources))throw Error("Invalid response shape");return t.resources}async function en(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return(e&&(et=null,es=null),et)?et:(er||(er=ea().then(e=>(et=e,es=null,e)).catch(e=>{throw es=e instanceof Error?e.message:String(e),e}).finally(()=>{er=null})),er)}function ei(){let[e,t]=(0,n.useState)(()=>null!=et?et:[]),[s,r]=(0,n.useState)(()=>null===et),[a,i]=(0,n.useState)(()=>es);(0,n.useEffect)(()=>{let e=!1;return en().then(s=>{e||(t(s),i(null),r(!1))}).catch(t=>{e||(i(t instanceof Error?t.message:String(t)),r(!1))}),()=>{e=!0}},[]);let l=(0,n.useCallback)(async()=>{r(!0);try{let e=await en(!0);t(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);return(0,n.useEffect)(()=>{let e=e=>{console.log("\uD83D\uDCBE Resource cache invalidated:",(null==e?void 0:e.detail)||{}),l()},t=e=>{console.log("\uD83D\uDD01 Agent switched, refreshing resources:",(null==e?void 0:e.detail)||{}),et=null,es=null,er=null,l()};return window.addEventListener("dexto:resourceCacheInvalidated",e),window.addEventListener("dexto:agentSwitched",t),()=>{window.removeEventListener("dexto:resourceCacheInvalidated",e),window.removeEventListener("dexto:agentSwitched",t)}},[l]),{resources:e,loading:s,error:a,refresh:l}}var el=s(6284);function eo(e){if(!e.metadata||"object"!=typeof e.metadata)return null;let t=e.metadata;return t.schema&&t.prompt&&t.serverName?t:null}function ec(e){let{approval:t,onApprove:s,onDeny:r}=e,[i,l]=(0,n.useState)({}),[o,c]=(0,n.useState)({}),[d,m]=(0,n.useState)(!1),x="elicitation"===t.type,h=(e,t)=>{l(s=>({...s,[e]:t})),o[e]&&c(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)(u.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:x?"Information Request":"Approval Required"})]}),x?(()=>{let e=eo(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),c=n.type||"string",d=i[r],m=!!o[r];return"boolean"===c?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(el.S,{id:r,checked:!0===d,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"===c||"integer"===c?(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"===c?"1":"any",value:"number"==typeof d?d:"",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!=d?String(d):"",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!=d&&"object"!=typeof d?String(d):"",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)(P.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)(el.S,{id:"remember",checked:d,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)(w.$,{variant:"outline",onClick:r,size:"sm",children:x?"Decline":"Deny"}),(0,a.jsx)(w.$,{onClick:()=>{if(x){let e=eo(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 c(a);s(i)}else s(void 0,d)},size:"sm",children:x?"Submit":"Approve"})]})]})}function ed(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 em(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?ed(e,t):ed(e))}function eu(e,t){var s,r,a,n,i,l,o,c,d,u,x,h,p,f,g,v,j;if(!e)return"";let b=null==e?void 0:e.mimeType,y="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 y){if(y.startsWith("@blob:")){let s=y.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,m.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==(c=e.mimeType)?void 0:c.startsWith("audio/"))&&t.push("audio"),(null==e||null==(d=e.mimeType)?void 0:d.startsWith("video/"))&&t.push("video");let s=null!=(p=null!=(h=null!=(x=null!=(u=r.data.items.find(e=>t.includes(e.kind)))?u:r.data.items.find(e=>"image"===e.kind))?x:r.data.items.find(e=>"video"===e.kind))?h:r.data.items.find(e=>"audio"===e.kind))?p:r.data.items[0];if(s&&"src"in s&&"string"==typeof s.src)return s.src}}return""}if(y.startsWith("data:"))return y;if(b&&!(!y||y.length<16||y.startsWith("http://")||y.startsWith("https://")||y.startsWith("data:")||y.startsWith("@blob:"))&&/^[A-Za-z0-9+/=\r\n]+$/.test(y))return"data:".concat(b,";base64,").concat(y);if(em(y))return y}let N=null!=(j=null!=(v=null!=(g=null!=(f=null==e?void 0:e.url)?f:null==e?void 0:e.image)?g:null==e?void 0:e.audio)?v:null==e?void 0:e.video)?j:null==e?void 0:e.uri;return"string"==typeof N?N:""}function ex(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,m.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=eu(e,t);return n&&em(n,"video")?{src:n,filename:r,mimeType:s}:null}function eh(){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 ep(e){let{messages:t,processing:s=!1,activeError:r,onDismissError:i,outerRef:l,pendingApproval:o,onApprovalApprove:f,onApprovalDeny:g}=e,v=(0,n.useRef)(null),[j,w]=(0,n.useState)({}),[k,S]=(0,n.useState)({}),[E,I]=(0,n.useState)(null);(0,n.useRef)(null);let[T,V]=(0,n.useState)({isOpen:!1,src:"",alt:""}),{resources:Y}=ei(),J=(0,n.useMemo)(()=>{let e={};for(let t of Y)e[t.uri]={...t};return e},[Y]),G=ee((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,d.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 H=(e,t)=>{V({isOpen:!0,src:e,alt:t})};if(!t||0===t.length)return null;let Z=e=>"string"==typeof e.content?e.content:Array.isArray(e.content)?e.content.map(e=>(0,d.PI)(e)?e.text:"").filter(Boolean).join("\n"):e.content&&"object"==typeof e.content?JSON.stringify(e.content,null,2):"",Q=e=>e?(0,d.KU)(e)?"object"==typeof e.error?JSON.stringify(e.error,null,2):String(e.error):(0,d.P2)(e)?e.content.map(e=>(0,d.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,p,f,g;let v=null!=(p=e.id)?p:"msg-".concat(l),E="user"===e.role,I="assistant"===e.role,T="system"===e.role,V=l===t.length-1,Y=!!(e.toolName&&e.toolArgs),X=!!(e.toolName&&e.toolResult),ee=Y||X,et=ee&&V||!!j[v],es=[],er=[],ea=[];X&&e.toolResult&&(0,d.P2)(e.toolResult)&&e.toolResult.content.forEach((e,t)=>{var s;if((0,d.j0)(e)){let s=eu(e,G);s&&em(s,"image")&&es.push({src:s,alt:"Tool result image ".concat(t+1),index:t})}else if((0,d.kz)(e)){let s=eu(e,G);s&&em(s,"audio")&&er.push({src:s,filename:e.filename,index:t})}else if((0,d.EQ)(e)&&("audio"===(0,m.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))){let s=eu(e,G);s&&em(s,"audio")&&er.push({src:s,filename:e.filename,index:t})}else{let s=ex(e,G);s&&ea.push({...s,index:t})}});let en=E?R.A:F.A,ei=(0,c.cn)(E?"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,c.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":E?"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":I?"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":T?"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"}),ec=!!(r&&r.anchorMessageId===e.id),ep=E&&V;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:[I&&(0,a.jsx)(en,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1"}),"tool"===e.role&&(0,a.jsx)(P.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,c.cn)("flex flex-col group w-full min-w-0",T?"col-span-2 items-center":E?"col-start-1 justify-self-end items-end":"col-start-2 justify-self-start items-start"),children:[(0,a.jsx)("div",{className:(0,c.cn)(el,"min-w-0"),children:(0,a.jsxs)("div",{className:(0,c.cn)("flex flex-col gap-2","min-w-0"),children:[I&&"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:()=>S(e=>{var t;return{...e,[v]:!(null==(t=e[v])||t)}}),children:[(0,a.jsx)(D.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"AI Reasoning"}),null==(f=k[v])||f?(0,a.jsx)(x.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"}):(0,a.jsx)(h.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)(C,{value:e.reasoning,tooltip:"Copy reasoning",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(O,{value:e.reasoning,tooltip:"Speak reasoning",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(null==(g=k[v])||g)&&(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:()=>{ee&&w(e=>({...e,[v]:!e[v]}))},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:[et?(0,a.jsx)(x.A,{className:"h-4 w-4 mr-2 text-primary"}):(0,a.jsx)(_.A,{className:"h-4 w-4 mr-2 text-primary"}),"Tool: ",e.toolName]}),e.toolResult?(0,d.KU)(e.toolResult)?(0,a.jsx)(u.A,{className:"mx-2 h-4 w-4 text-red-500"}):(0,a.jsx)(M.A,{className:"mx-2 h-4 w-4 text-green-500"}):(0,a.jsx)(z.A,{className:"mx-2 h-4 w-4 animate-spin text-muted-foreground"})]}),et&&(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)(C,{value:Q(e.toolResult),tooltip:"Copy result",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(O,{value:Q(e.toolResult),tooltip:"Speak result",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(0,d.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,d.P2)(e.toolResult)?e.toolResult.content.map((e,t)=>{var s,r,n;let i=ex(e,G);if((0,d.j0)(e)||(0,d.kz)(e)||(0,d.EQ)(e)&&("audio"===(0,m.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))||i)return null;if((0,d.PI)(e))return(0,a.jsx)(ef,{text:e.text,isUser:!1,onOpenImage:H,resourceSet:J},"".concat(v,"-tool-text-").concat(t));if((0,d.EQ)(e)){let s=(0,m.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)(U.A,{className:"h-4 w-4 text-muted-foreground"}):l?(0,a.jsx)(B.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(q.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")?ed(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)(ef,{text:e.content,isUser:E,onOpenImage:H,resourceSet:J},"".concat(v,"-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(v,"-part-").concat(t);if("text"===e.type)return(0,a.jsx)(ef,{text:e.text,isUser:E,onOpenImage:H,resourceSet:J},s);if((0,d.j0)(e)){let t=eu(e);return t&&em(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:()=>H(t,"Message attachment")},s):null}let r=ex(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)(B.A,{className:(0,c.cn)("h-4 w-4",E?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,c.cn)("truncate",E?"text-primary-foreground/80":"text-muted-foreground"),children:t}),n&&(0,a.jsx)("span",{className:(0,c.cn)(E?"text-primary-foreground/70":"text-muted-foreground/80"),children:n})]})]},s)}if((0,d.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)(q.A,{className:(0,c.cn)("h-5 w-5",E?void 0:"text-muted-foreground")}),(0,a.jsx)("span",{className:(0,c.cn)("text-sm font-medium",void 0),children:e.filename||"".concat(e.mimeType," file")}),(0,a.jsx)("span",{className:(0,c.cn)("text-xs",E?"text-primary-foreground/70":"text-muted-foreground"),children:e.mimeType})]},s);{let t=eu(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)(U.A,{className:(0,c.cn)("h-5 w-5",E?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,c.cn)("text-sm truncate max-w-[120px]",E?"text-primary-foreground/80":"text-muted-foreground"),children:e.filename})]},s)}}return null}),T&&!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 ed(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)(B.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 ed(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)(U.A,{className:"h-4 w-4"}),(()=>{let t="data:".concat(e.fileData.mimeType,";base64,").concat(e.fileData.base64);return ed(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)(q.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})]})})]})}),!T&&!ee&&(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}),I&&(null==(o=e.tokenUsage)?void 0:o.totalTokens)!==void 0&&(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{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)(N,{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]})]})})]}),I&&e.model&&(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{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)(N,{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]})]})})]})]}),(I||E)&&(0,a.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,a.jsx)(C,{value:Z(e),tooltip:"Copy message",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(O,{value:Z(e),tooltip:"Speak",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]})]}),E&&(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)($.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)($.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Image"})]}),(0,a.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>H(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)(W.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(v,"-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)(K.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)(K.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(v,"-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)(A.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)(A.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)(U.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(v,"-audio-").concat(t))),ec&&(0,a.jsx)("div",{className:"mt-2 ml-12 mr-4",children:(0,a.jsx)(L,{error:r,onDismiss:i||(()=>{})})})]}),s&&ep&&(0,a.jsx)(eh,{})]},v)}),o&&f&&g&&(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)(F.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)(ec,{approval:o,onApprove:f,onDeny:g})})})]})}),(0,a.jsx)("div",{ref:v,className:"h-px"},"end-anchor"),T.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:()=>{V({isOpen:!1,src:"",alt:""})},className:"p-2 hover:bg-muted rounded-md transition-colors","aria-label":"Close modal",children:(0,a.jsx)(p.A,{className:"h-5 w-5"})})]}),(0,a.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,a.jsx)("img",{src:T.src,alt:T.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:T.alt})})]})})]})}function ef(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]),c=ee(o),d=l.length>0;return(0,a.jsxs)("div",{className:"space-y-3",children:[d&&(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)(X,{children:l})}),o.map(e=>(0,a.jsx)(eg,{uri:e,state:c[e],onOpenImage:r},e))]})}function eg(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)(z.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)(u.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)(V.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)(X,{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(!em(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(!em(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)(U.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(!em(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)(B.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)(q.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 ev=s(7104),ej=s(7732);function eb(e){let{children:t,className:s}=e;return(0,a.jsx)("div",{className:(0,c.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 ey(e){let{leftButtons:t,rightButtons:s,className:r}=e;return(0,a.jsxs)("div",{className:(0,c.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 eN=s(3511),ew=s(2744);let ek=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)(ew.bL,{className:(0,c.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)(ew.zi,{className:(0,c.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 eC(e){let{isStreaming:t,onStreamingChange:s,className:r}=e;return(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 cursor-pointer ".concat(r||""),children:[(0,a.jsx)(eN.A,{className:"h-3 w-3 ".concat(t?"text-blue-500":"text-muted-foreground")}),(0,a.jsx)(ek,{checked:t,onCheckedChange:s,className:"scale-75","aria-label":"Toggle streaming"})]})}),(0,a.jsxs)(N,{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"})]})]})})}ek.displayName=ew.bL.displayName;var eS=s(7776),eA=s(6182);function eE(e){let{...t}=e;return(0,a.jsx)(eA.bL,{"data-slot":"popover",...t})}function eI(e){let{className:t,align:s="center",sideOffset:r=4,...n}=e;return(0,a.jsx)(eA.ZL,{children:(0,a.jsx)(eA.UC,{"data-slot":"popover-content",align:s,sideOffset:r,className:(0,c.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 eT=e=>{let{children:t,...s}=e;return(0,a.jsx)(eE,{...s,children:t})},eO=function(e){let{...t}=e;return(0,a.jsx)(eA.l9,{"data-slot":"popover-trigger",...t})},eL=n.forwardRef((e,t)=>{let{className:s,align:r="end",sideOffset:n=4,...i}=e;return(0,a.jsx)(eI,{ref:t,align:r,sideOffset:n,className:(0,c.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})});eL.displayName="DropdownMenuContent";let eR=n.forwardRef((e,t)=>{let{className:s,disabled:r,...n}=e;return(0,a.jsx)("div",{ref:t,className:(0,c.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})});eR.displayName="DropdownMenuItem";let eF=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,c.cn)("-mx-1 my-1 h-px bg-muted",s),...r})});function eP(e){let{onImageAttach:t,onPdfAttach:s,onAudioAttach:r,className:i,supports:l}=e,[o,c]=n.useState(!1),d=(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)(eT,{open:o,onOpenChange:c,children:[(0,a.jsx)(eO,{asChild:!0,children:(0,a.jsxs)(w.$,{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)(eS.A,{className:"h-3 w-3 md:mr-1.5"}),(0,a.jsx)("span",{className:"hidden md:inline",children:"Attach"})]})}),(0,a.jsxs)(eL,{side:"top",align:"start",children:[(0,a.jsx)(eR,{onClick:()=>{d&&(t(),c(!1))},className:d?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!d,children:(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(eS.A,{className:"h-4 w-4 mr-2"})," Image"]})}),!d&&(0,a.jsx)(N,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eR,{onClick:()=>{m&&(s(),c(!1))},className:m?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!m,children:(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(q.A,{className:"h-4 w-4 mr-2"})," PDF"]})}),!m&&(0,a.jsx)(N,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eR,{onClick:()=>{u&&(r(),c(!1))},className:u?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!u,children:(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(U.A,{className:"h-4 w-4 mr-2"})," Audio file"]})}),!u&&(0,a.jsx)(N,{side:"bottom",children:"Unsupported for this model"})]})})})]})]})}eF.displayName="DropdownMenuSeparator";var eD=s(3947),e_=s(3827);function eM(e){let{isRecording:t,onToggleRecording:s,className:r,disabled:n}=e,i=(0,a.jsxs)(w.$,{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)(eD.A,{className:"h-3 w-3 md:mr-1.5 text-red-500"}):(0,a.jsx)(e_.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)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:i}),(0,a.jsx)(N,{side:"bottom",children:"Unsupported for this model"})]})}):i}var ez=s(4569),eU=s(3871),eB=s(7159),eq=s(7397),e$=s(531);function eW(e){let{open:t,onOpenChange:s,provider:r,primaryEnvVar:l,onSaved:o}=e,[c,d]=(0,n.useState)(""),[m,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),p=async()=>{if(!c.trim())return void h("API key is required");u(!0),h(null);try{let e=await fetch("".concat((0,i.e)(),"/api/llm/key"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,apiKey:c})}),t=await e.json();if(!e.ok||"object"!=typeof t||null===t)throw Error("Failed to save API key");if(!t.ok||!t.provider||!t.envVar)throw Error("Unexpected response while saving API key");o({provider:t.provider,envVar:t.envVar}),s(!1),d("")}catch(e){h(e instanceof Error?e.message:"Failed to save API key")}finally{u(!1)}};return(0,a.jsx)(eU.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eU.Cf,{className:"max-w-md",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsxs)(eU.L3,{children:["Set ",r," API Key"]}),(0,a.jsxs)(eU.rr,{children:["This key will be stored in your .env (env var ",l,"). It is not shared with the client."]})]}),x&&(0,a.jsx)(eB.Fc,{variant:"destructive",children:(0,a.jsx)(eB.TN,{children:x})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e$.J,{htmlFor:"apiKey",children:"API Key"}),(0,a.jsx)(eq.p,{id:"apiKey",type:"password",value:c,onChange:e=>d(e.target.value),placeholder:"Enter ".concat(r," API key")})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>s(!1),disabled:m,children:"Cancel"}),(0,a.jsx)(w.$,{onClick:p,disabled:m,children:m?"Saving...":"Save"})]})]})})}var eK=s(8352),eV=s(4184),eY=s(4580),eJ=s(2776);function eG(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)(eJ.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsx)(eq.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 eH=s(5980),eZ=s(3555),eQ=s(9355);let eX={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"},e0={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 e1(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 e2=["google","cohere","anthropic"],e5=e=>!e2.includes(e),e4={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)(eZ.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-amber-500 transition-colors cursor-help"}),new:(0,a.jsx)(eQ.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-yellow-500 transition-colors cursor-help"}),realtime:(0,a.jsx)(eN.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-blue-500 transition-colors cursor-help"})};var e3=s(6083);function e8(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)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e4.pdf})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:"PDF support"})})]}),t.includes("audio")&&(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e4.audio})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:"Audio support"})})]}),t.includes("image")&&(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e4.image})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:"Image support"})})]}),!s&&(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:(0,a.jsx)(e3.A,{className:"h-3.5 w-3.5 text-amber-500 hover:text-amber-400 transition-colors cursor-help"})})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:"API key required"})})]})]})}function e6(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:eX[t]?(0,a.jsx)(ez.default,{src:eX[t],alt:"".concat(t," logo"),width:20,height:20,className:(0,c.cn)("object-contain",e5(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(eK.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)(eH.E,{variant:"secondary",className:"text-xs",children:"baseURL"}),!s.hasApiKey&&(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(eH.E,{variant:"destructive",className:"text-xs cursor-default",children:"API Key Required"})}),(0,a.jsxs)(N,{children:["Click any ",s.name," model to set up the API key"]})]})}),e0[t]&&(0,a.jsx)("a",{href:e0[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,m=e.displayName||e.name,u=(r=e.name,(null==i?void 0:i.provider)===t&&(null==i?void 0:i.model)===r),x=(d=e.name,n.includes("".concat(t,"|").concat(d))),h=s.hasApiKey,p=e1(e.pricing||void 0),f=["Max tokens: ".concat(e.maxInputTokens.toLocaleString()),e.supportedFileTypes.length>0&&"Supports: ".concat(e.supportedFileTypes.join(", ")),e.default&&"Default model",!h&&"⚠️ API key required",...p].filter(Boolean);return(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{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,c.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",u&&"bg-accent border-accent-foreground/20 shadow-sm ring-1 ring-accent-foreground/10",!h&&"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:m})})}),(0,a.jsx)(e8,{supportedFileTypes:e.supportedFileTypes,hasApiKey:h}),(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{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":x?"Remove from favorites":"Add to favorites",children:(0,a.jsx)(eV.A,{className:(0,c.cn)("h-4 w-4",x&&"fill-current text-yellow-500")})})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:x?"Remove from favorites":"Add to favorites"})})]})}),u&&(0,a.jsx)("div",{className:"absolute inset-y-0 left-0 w-0.5 bg-primary rounded-l-lg"})]})}),(0,a.jsx)(N,{side:"bottom",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:f.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})},e.name)})})]})}function e7(e,t){return"".concat(e,"|").concat(t)}function e9(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 te="dexto:modelFavorites",tt="dexto:customModels";function ts(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)(e$.J,{htmlFor:t,className:n,children:s}),r&&(0,a.jsx)(j,{delayDuration:200,children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{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)(eK.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{side:"right",className:"max-w-xs",children:(0,a.jsx)("p",{className:"text-sm",children:r})})]})})]})}var tr=s(1754);function ta(e){let{provider:t,model:s,providerInfo:r,isFavorite:n,isActive:i,onClick:l,onToggleFavorite:o}=e,d=s.displayName||s.name,m=r.hasApiKey,u=e1(s.pricing||void 0),x=["Max tokens: ".concat(s.maxInputTokens.toLocaleString()),s.supportedFileTypes.length>0&&"Supports: ".concat(s.supportedFileTypes.join(", ")),!m&&"⚠️ API key required",...u].filter(Boolean);return(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsxs)("div",{onClick:l,className:(0,c.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]",!m&&"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:eX[t]?(0,a.jsx)(ez.default,{src:eX[t],alt:"".concat(t," logo"),width:24,height:24,className:(0,c.cn)("object-contain",e5(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(eK.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)(e8,{supportedFileTypes:s.supportedFileTypes,hasApiKey:m}),(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),o()},className:(0,c.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)(eV.A,{className:(0,c.cn)("h-4 w-4",n&&"fill-current")})})}),(0,a.jsx)(N,{side:"top",children:(0,a.jsx)("span",{children:n?"Remove from favorites":"Add to favorites"})})]})})]})}),(0,a.jsx)(N,{side:"right",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:x.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})})}function tn(){var e;let[t,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(!1),[d,m]=(0,n.useState)(null),[u,p]=(0,n.useState)({}),[f,g]=(0,n.useState)(""),[v,j]=(0,n.useState)(!1),[b,y]=(0,n.useState)(""),[N,k]=(0,n.useState)(""),[C,S]=(0,n.useState)(!1),[A,E]=(0,n.useState)("favorites"),[I,T]=(0,n.useState)([]),[O,L]=(0,n.useState)({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),[R,P]=(0,n.useState)(!1),[D,_]=(0,n.useState)(!1),[M,U]=(0,n.useState)(null),[B,q]=(0,n.useState)(null),{currentSessionId:$,currentLLM:W,refreshCurrentLLM:K}=(0,o.v)(),V=(0,tr.st)(),Y=(0,n.useRef)(V);(0,n.useEffect)(()=>{Y.current=V},[V]),(0,n.useEffect)(()=>{t&&W&&(y(W.router||"vercel"),k(W.baseURL||""))},[t,W]),(0,n.useEffect)(()=>{if(!t)return;let e=!1;return async function(){l(!0),m(null);try{let t=await fetch("".concat((0,i.e)(),"/api/llm/catalog"));if(!e&&t.ok){let e=await t.json();p(e.providers||{})}}catch(t){e||m("Failed to load catalog")}finally{e||l(!1)}}(),()=>{e=!0}},[t]);let[J,G]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(t)try{let e=localStorage.getItem(te),t=e?JSON.parse(e):[];G(t);let s=localStorage.getItem(tt),r=s?JSON.parse(s):[];T(r),t.length>0?E("favorites"):r.length>0?E("custom"):E("all")}catch(e){G([]),T([]),E("all")}},[t]);let H=(0,n.useCallback)((e,t)=>{let s=e7(e,t);G(e=>{let t=e.includes(s)?e.filter(e=>e!==s):[...e,s];return localStorage.setItem(te,JSON.stringify(t)),t})},[]),Z=(0,n.useCallback)(()=>{let{name:e,baseURL:t,maxInputTokens:s,maxOutputTokens:r}=O;if(!e.trim()||!t.trim())return void m("Model name and Base URL are required");let a=e9(t);if(!a.isValid)return void m(a.error||"Invalid Base URL");let n=[...I,{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}];T(n),localStorage.setItem(tt,JSON.stringify(n)),L({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),P(!1),m(null)},[O,I]),Q=(0,n.useCallback)(e=>{let t=I.filter(t=>t.name!==e);T(t),localStorage.setItem(tt,JSON.stringify(t))},[I]);async function X(e,t,r){S(!0),m(null);try{var a,n;let l=function(e,t){var s,r,a;let n=(null==W?void 0:W.router)||"vercel",i=null!=(r=null==(s=u[e])?void 0:s.supportedRouters)?r:["vercel"],l=null!=(a=t.supportedRouters)?a:i,o=b||n;return l.includes(o)?o:l[0]||i[0]||"vercel"}(e,t),o={provider:e,model:t.name,router:l};r&&(null==(a=u[e])?void 0:a.supportsBaseURL)&&(o.baseURL=r),$&&(o.sessionId=$);let c=await fetch("".concat((0,i.e)(),"/api/llm/switch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),d=await c.json().catch(()=>({}));if(!c.ok){let e=(null==d?void 0:d.issues)&&(null==(n=d.issues[0])?void 0:n.message)||"Failed to switch model";m(e);return}await K(),W&&Y.current.trackLLMSwitched({fromProvider:W.provider,fromModel:W.model,toProvider:e,toModel:t.name,sessionId:$||void 0,trigger:"user_action"}),s(!1)}catch(e){m("Network error while switching")}finally{S(!1)}}function ee(e,t,s){let r=u[e];if(!r)return;let a=s||N;if(r.supportsBaseURL&&a){let e=e9(a);if(!e.isValid)return void m(e.error||"Invalid base URL")}if(!r.hasApiKey){q({provider:e,model:t.name}),U(e),_(!0);return}X(e,t,a)}let et=Object.keys(u),es=(null==W?void 0:W.displayName)||(null==W?void 0:W.model)||"Choose Model",er=(0,n.useMemo)(()=>J.map(e=>{let[t,s]=e.split("|"),r=u[t],a=null==r?void 0:r.models.find(e=>e.name===s);return r&&a?{providerId:t,provider:r,model:a}:null}).filter(Boolean),[J,u]),ea=(0,n.useMemo)(()=>{if(!f)return u;let e={};return et.forEach(t=>{let s=u[t].models.filter(e=>(function(e,t){var s,r,a,n;let i=f.trim().toLowerCase();return!i||t.name.toLowerCase().includes(i)||null!=(a=null==(s=t.displayName)?void 0:s.toLowerCase().includes(i))&&a||e.toLowerCase().includes(i)||null!=(n=null==(r=u[e])?void 0:r.name.toLowerCase().includes(i))&&n})(t,e));s.length>0&&(e[t]={...u[t],models:s})}),e},[u,f,et]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(eU.lG,{open:t,onOpenChange:s,children:[(0,a.jsx)(eU.zM,{asChild:!0,children:(0,a.jsxs)(w.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 cursor-pointer",title:"Choose model",children:[(null==W?void 0:W.provider)&&eX[W.provider]?(0,a.jsx)(ez.default,{src:eX[W.provider],alt:"".concat(W.provider," logo"),width:16,height:16,className:(0,c.cn)("object-contain",e5(W.provider)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(F.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-sm",children:es}),(0,a.jsx)(h.A,{className:"h-3 w-3"})]})}),(0,a.jsxs)(eU.Cf,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[(0,a.jsxs)(eU.c7,{className:"pb-4 flex-shrink-0",children:[(0,a.jsx)(eU.L3,{className:"text-xl",children:"Select Model"}),(0,a.jsx)(eU.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:[d&&(0,a.jsx)(eB.Fc,{variant:"destructive",children:(0,a.jsx)(eB.TN,{children:d})}),(0,a.jsx)(eG,{value:f,onChange:g,placeholder:"Search models, providers..."})]}),!f&&(0,a.jsxs)("div",{className:"flex gap-2 border-b border-border pb-2",children:[(0,a.jsxs)("button",{onClick:()=>E("favorites"),className:(0,c.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","favorites"===A?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(eV.A,{className:(0,c.cn)("h-4 w-4","favorites"===A&&"fill-current")}),"Favorites",er.length>0&&(0,a.jsxs)("span",{className:"text-xs opacity-70",children:["(",er.length,")"]})]}),(0,a.jsxs)("button",{onClick:()=>E("all"),className:(0,c.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","all"===A?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(F.A,{className:"h-4 w-4"}),"All Models"]}),(0,a.jsxs)("button",{onClick:()=>E("custom"),className:(0,c.cn)("flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-t-lg transition-colors","custom"===A?"bg-primary/10 text-primary border-b-2 border-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:[(0,a.jsx)(eY.A,{className:"h-4 w-4"}),"Custom",I.length>0&&(0,a.jsxs)("span",{className:"text-xs opacity-70",children:["(",I.length,")"]})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-auto px-1 min-h-0",children:r?(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground justify-center py-8",children:[(0,a.jsx)(z.A,{className:"h-4 w-4 animate-spin"})," Loading models..."]}):f?(0,a.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(ea).length?(0,a.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No models found matching your search"}):Object.entries(ea).map(e=>{let[t,s]=e;return(0,a.jsx)(e6,{providerId:t,provider:s,models:s.models,favorites:J,currentModel:W||void 0,onToggleFavorite:H,onUse:ee},t)})}):"favorites"===A?0===er.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center space-y-3",children:[(0,a.jsx)(eV.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:er.map(e=>{let t,{providerId:s,provider:r,model:n}=e;return(0,a.jsx)(ta,{provider:s,model:n,providerInfo:r,isFavorite:!0,isActive:(t=n.name,(null==W?void 0:W.provider)===s&&(null==W?void 0:W.model)===t),onClick:()=>ee(s,n),onToggleFavorite:()=>H(s,n.name)},e7(s,n.name))})}):"custom"===A?(0,a.jsxs)("div",{className:"space-y-4 pb-2",children:[I.length>0&&(0,a.jsx)("div",{className:"space-y-2",children:I.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)(w.$,{size:"sm",variant:"ghost",onClick:()=>{ee("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)(w.$,{size:"sm",variant:"ghost",onClick:()=>Q(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)(w.$,{variant:"ghost",size:"sm",onClick:()=>P(!R),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===I.length?"Add your first custom model":"Add another model"}),R?(0,a.jsx)(x.A,{className:"h-4 w-4"}):(0,a.jsx)(h.A,{className:"h-4 w-4"})]}),R&&(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)(ts,{htmlFor:"custom-model-name",tooltip:"Model identifier (e.g., llama3, mixtral, gpt-5)",children:"Model Name *"}),(0,a.jsx)(eq.p,{id:"custom-model-name",value:O.name,onChange:e=>L(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)(ts,{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)(eq.p,{id:"custom-base-url",value:O.baseURL,onChange:e=>L(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)(ts,{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)(eq.p,{id:"custom-max-input",type:"number",value:O.maxInputTokens,onChange:e=>L(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)(ts,{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)(eq.p,{id:"custom-max-output",type:"number",value:O.maxOutputTokens,onChange:e=>L(t=>({...t,maxOutputTokens:e.target.value})),placeholder:"Auto",className:"text-sm",min:"1"})]})]}),(0,a.jsx)(w.$,{onClick:Z,size:"sm",className:"w-full",children:"Add Model"})]})]})]}):(0,a.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(u).length?(0,a.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No providers available"}):Object.entries(u).map(e=>{let[t,s]=e;return(0,a.jsx)(e6,{providerId:t,provider:s,models:s.models,favorites:J,currentModel:W||void 0,onToggleFavorite:H,onUse:ee},t)})})})]})]})]}),M&&(0,a.jsx)(eW,{open:D,onOpenChange:_,provider:M,primaryEnvVar:(null==(e=u[M])?void 0:e.primaryEnvVar)||"",onSaved:function(e){if(p(t=>({...t,[e.provider]:t[e.provider]?{...t[e.provider],hasApiKey:!0}:t[e.provider]})),_(!1),B){var t;let{provider:e,model:s}=B,r=null==(t=u[e])?void 0:t.models.find(e=>e.name===s);r&&X(e,r,N),q(null)}}})]})}var ti=s(7079),tl=s(649);function to(e){let{resources:t,query:s,selectedIndex:r,onSelect:i,onHoverIndex:l,loading:o}=e,d=n.useMemo(()=>(0,c.L)(t,s),[t,s]),m=ee(n.useMemo(()=>d.filter(e=>(e.mimeType||"").startsWith("image/")).map(e=>e.uri),[d])),u=n.useRef([]);if(n.useEffect(()=>{let e=u.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 x=e=>"resource-option-".concat(btoa(e).replace(/[^a-zA-Z0-9]/g,"")),h=d[r]?x(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":h,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=x(e.uri);return(0,a.jsxs)("li",{id:s,role:"option","aria-selected":t===r,ref:e=>{e&&(u.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)(tc,{resourceState:m[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 tc(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)($.A,{className:"h-4 w-4 text-muted-foreground"})});if("loading"===s.status)return(0,a.jsx)("div",{className:r,children:(0,a.jsx)(z.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)($.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)($.A,{className:"h-4 w-4 text-muted-foreground"})})}var td=s(4957);let tm=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)(eN.A,{className:"h-3 w-3 text-blue-400"}):"starter"===t.source?(0,a.jsx)("span",{className:"text-xs",children:"\uD83D\uDE80"}):(0,a.jsx)(eQ.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)(eH.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"MCP"}),"file"===t.source&&(0,a.jsx)(eH.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"File"}),"custom"===t.source&&(0,a.jsx)(eH.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Custom"}),"starter"===t.source&&(0,a.jsx)(eH.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Starter"})]}),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 tu(e){let{isVisible:t,searchQuery:s,onSelectPrompt:r,onClose:i,onCreatePrompt:l,refreshKey:o}=e,[c,d]=(0,n.useState)([]),[m,u]=(0,n.useState)([]),[x,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(0),g=(0,n.useRef)(0),v=(0,n.useRef)(null),j=(0,n.useRef)(null),b=(0,n.useRef)(0);g.current=p;let y=n.useMemo(()=>{let e=s.trim();return!!e&&!!("/"===e||e.startsWith("/")&&0===m.length)},[s,m.length]),N=n.useMemo(()=>{let e=[];return y&&e.push({kind:"create"}),m.forEach(t=>e.push({kind:"prompt",prompt:t})),e},[y,m]);(0,n.useEffect)(()=>{if(!t)return;let e=!1;h(!0);let s=null!=o?o:0,r=s>0&&s!==b.current;return(0,td.y)({forceRefresh:r}).then(t=>{e||(d(t),u(t),b.current=s)}).catch(()=>{e||(d([]),u([]))}).finally(()=>{e||h(!1)}),()=>{e=!0}},[t,o]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("✨ Prompts list changed:",(null==e?void 0:e.detail)||{}),h(!0),(0,td.y)({forceRefresh:!0}).then(e=>{d(e),u(e)}).catch(()=>{d([]),u([])}).finally(()=>{h(!1)})};return window.addEventListener("dexto:mcpPromptsListChanged",e),()=>{window.removeEventListener("dexto:mcpPromptsListChanged",e)}},[t]),(0,n.useEffect)(()=>{if(!s.trim()||"/"===s){u(c),f(+("/"===s&&c.length>0));return}let e=(s.startsWith("/")?s.slice(1):s).split(/\s+/)[0]||"";u(c.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.description&&t.description.toLowerCase().includes(e.toLowerCase())||t.title&&t.title.toLowerCase().includes(e.toLowerCase()))),f(0)},[s,c]);let w=N.length;return((0,n.useEffect)(()=>{f(e=>0===w?0:e>=w?w-1:e)},[w]),(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===N.length)return;t(),f(e=>(e+1)%N.length);break;case"ArrowUp":if(0===N.length)return;t(),f(e=>(e-1+N.length)%N.length);break;case"Enter":if(n)return;if(t(),0===N.length){null==l||l();return}{let e=N[g.current];"create"===e.kind?null==l||l():r(e.prompt)}break;case"Escape":t(),i();break;case"Tab":if(t(),0===N.length){null==l||l();return}{let e=N[g.current];"create"===e.kind?null==l||l():r(e.prompt)}}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t,N,r,i,l,s]),(0,n.useEffect)(()=>{if(!j.current)return;let e=j.current,t=e.querySelector('[data-index="'.concat(p,'"]'));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"})}},[p]),(0,n.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&i()};return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,i]),t)?(0,a.jsxs)("div",{ref:v,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)(eH.E,{variant:"secondary",className:"ml-auto text-xs px-2 py-0.5",children:c.length})]})}),(0,a.jsx)("div",{ref:j,className:"max-h-48 overflow-y-auto",children:x?(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"Loading prompts..."}):(0,a.jsxs)(a.Fragment,{children:[y&&(0,a.jsxs)("div",{className:"px-3 py-2 cursor-pointer transition-colors ".concat(0===p?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"),onClick:()=>null==l?void 0:l(),onMouseEnter:()=>f(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)(eY.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===m.length?!y&&(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"No prompts available."}):m.map((e,t)=>{let s=y?t+1:t;return(0,a.jsx)(tm,{prompt:e,isSelected:s===p,onClick:()=>r(e),onMouseEnter:()=>f(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 tx=s(449),th=s(2166),tp=s(113),tf=s(7785);function tg(e){let{open:t,onClose:s,onCreated:r}=e,[l,o]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,u]=(0,n.useState)(""),[x,h]=(0,n.useState)(""),[p,f]=(0,n.useState)(null),[g,v]=(0,n.useState)(null),[j,b]=(0,n.useState)(null),[y,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(null),[S,A]=(0,n.useState)(!1);(0,n.useEffect)(()=>{t||(o(""),d(""),u(""),h(""),f(null),v(null),b(null),C(null),N(!1),A(!1))},[t]);let E=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)}));f({base64:s,mimeType:e.type||"application/octet-stream",filename:e.name}),v(s),b(e.name)}catch(e){console.error("Failed to read file:",e),C("Failed to read file. Please try a different file.")}},I=async e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s){f(null),v(null),b(null);return}await E(s)},T=async e=>{e.preventDefault(),A(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&await E(t[0])},O=async e=>{if(e.preventDefault(),!l.trim()||!x.trim())return void C("Name and content are required.");N(!0),C(null);let t={name:l.trim(),title:c.trim()||void 0,description:m.trim()||void 0,content:x,resource:p||void 0};try{let e=await fetch("".concat((0,i.e)(),"/api/prompts/custom"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok){let t=await e.json().catch(()=>({})),s=(null==t?void 0:t.message)||"Failed to create prompt.";throw Error(s)}let s=await e.json();(null==s?void 0:s.prompt)&&r({name:s.prompt.name})}catch(e){console.error("Failed to create prompt:",e),C(e instanceof Error?e.message:"Failed to create prompt. Please try again.")}finally{N(!1)}};return(0,a.jsx)(eU.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-3xl",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsx)(eU.L3,{children:"Create Custom Prompt"}),(0,a.jsx)(eU.rr,{children:"Define reusable prompt text and optionally attach a supporting resource file."})]}),(0,a.jsxs)("form",{onSubmit:O,className:"space-y-4",children:[k&&(0,a.jsx)(eB.Fc,{variant:"destructive",children:(0,a.jsx)(eB.TN,{children:k})}),(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)(e$.J,{htmlFor:"prompt-name",children:"Prompt Name"}),(0,a.jsx)(eq.p,{id:"prompt-name",value:l,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)(e$.J,{htmlFor:"prompt-title",children:"Title"}),(0,a.jsx)(eq.p,{id:"prompt-title",value:c,onChange:e=>d(e.target.value),placeholder:"Research Summary"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e$.J,{htmlFor:"prompt-description",children:"Description"}),(0,a.jsx)(eq.p,{id:"prompt-description",value:m,onChange:e=>u(e.target.value),placeholder:"Summarize research papers with key findings"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e$.J,{htmlFor:"prompt-content",children:"Prompt Content"}),(0,a.jsx)(tx.T,{id:"prompt-content",value:x,onChange:e=>h(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)(e$.J,{children:"Attach resource (optional)"}),g?(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)(th.A,{className:"h-4 w-4 mr-2 text-muted-foreground"}),(0,a.jsx)(eH.E,{variant:"secondary",className:"mr-2",children:"Resource"}),j||"Attached file"]}),(0,a.jsxs)(w.$,{variant:"ghost",size:"sm",onClick:()=>{f(null),v(null),b(null)},children:[(0,a.jsx)(tp.A,{className:"h-4 w-4 mr-1"})," Remove"]})]}):(0,a.jsxs)("div",{className:"relative rounded-lg border-2 border-dashed transition-colors ".concat(S?"border-primary bg-primary/5":"border-border/60 hover:border-border/80"," px-6 py-8 text-center"),onDragOver:e=>{e.preventDefault(),A(!0)},onDragLeave:e=>{e.preventDefault(),A(!1)},onDrop:T,children:[(0,a.jsx)("input",{type:"file",onChange:I,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)(tf.A,{className:"h-8 w-8 ".concat(S?"text-primary":"text-muted-foreground")}),(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("span",{className:"font-medium",children:S?"Drop file here":"Click to upload"}),(0,a.jsx)("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)(eU.Es,{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)(w.$,{type:"button",variant:"ghost",onClick:s,disabled:y,children:"Cancel"}),(0,a.jsx)(w.$,{type:"submit",disabled:y,children:y?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(z.A,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):"Save Prompt"})]})]})]})})}function tv(e){let{open:t,onClose:s,onSuccess:r}=e,[l,o]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),p=async()=>{if(!l.trim())return void h("Memory content is required");u(!0),h(null);try{let e={content:l.trim(),...c.trim()&&{tags:c.split(",").map(e=>e.trim()).filter(Boolean)},metadata:{source:"user"}},t=await fetch("".concat((0,i.e)(),"/api/memory"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to create memory")}o(""),d(""),null==r||r(),s()}catch(e){h(e instanceof Error?e.message:"Failed to create memory")}finally{u(!1)}},f=()=>{m||(o(""),d(""),h(null),s())};return(0,a.jsx)(eU.lG,{open:t,onOpenChange:f,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-[500px]",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsx)(eU.L3,{children:"Create Memory"}),(0,a.jsx)(eU.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:[x&&(0,a.jsxs)(eB.Fc,{variant:"destructive",children:[(0,a.jsx)(ti.A,{className:"h-4 w-4"}),(0,a.jsx)(eB.TN,{children:x})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(e$.J,{htmlFor:"memory-content",children:"Memory Content *"}),(0,a.jsx)(tx.T,{id:"memory-content",placeholder:"e.g., I prefer concise responses without explanations",value:l,onChange:e=>o(e.target.value),className:"min-h-[100px] resize-none",disabled:m,autoFocus:!0}),(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[l.length," / 10,000 characters"]})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(e$.J,{htmlFor:"memory-tags",children:"Tags (optional)"}),(0,a.jsx)(eq.p,{id:"memory-tags",placeholder:"e.g., preferences, work, coding-style",value:c,onChange:e=>d(e.target.value),disabled:m}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Comma-separated tags for organizing memories"})]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:f,disabled:m,children:"Cancel"}),(0,a.jsx)(w.$,{onClick:p,disabled:m||!l.trim(),children:m?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(z.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Memory"})]})]})})}function tj(e){let{onSend:t,isSending:s,variant:r="chat"}=e,[l,d]=(0,n.useState)(""),m=(0,n.useRef)(null),[u,x]=(0,n.useState)(null),[h,f]=(0,n.useState)(null),g=(0,n.useRef)(null),v=(0,n.useRef)(null),j=(0,n.useRef)(null),b=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}(),[y,N]=(0,n.useState)(!1),k=(0,n.useRef)(null),{currentSessionId:C,isStreaming:A,setStreaming:E,cancel:I,processing:T,currentLLM:O}=(0,o.v)(),L=(0,tr.st)(),R=(0,n.useRef)(L);(0,n.useEffect)(()=>{R.current=L},[L]);let[F,P]=(0,n.useState)(null),[_,M]=(0,n.useState)(!1),[B,$]=(0,n.useState)(null),[W,K]=(0,n.useState)(null),[V,Y]=(0,n.useState)([]),{resources:J,loading:G,refresh:H}=ei(),[Z,Q]=(0,n.useState)(""),[X,ee]=(0,n.useState)(!1),[et,es]=(0,n.useState)(0),[er,ea]=(0,n.useState)(null),en=(0,n.useMemo)(()=>(0,c.L)(J,Z),[J,Z]),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=[{name:"Claude 4.5 Sonnet",provider:"anthropic",model:"claude-sonnet-4-5-20250929"},{name:"GPT-5",provider:"openai",model:"gpt-5"},{name:"GPT-5 Mini",provider:"openai",model:"gpt-5-mini"},{name:"Gemini 2.5 Pro",provider:"google",model:"gemini-2.5-pro"}],[ec,ed]=(0,n.useState)(!1),[em,eu]=(0,n.useState)(!1),[ex,eh]=(0,n.useState)(0),[ep,ef]=(0,n.useState)(!1),eg=e=>{K(e),setTimeout(()=>K(null),5e3)},eN=n.useCallback(()=>{ed(!1),eu(!0)},[]),ew=n.useCallback(e=>{(0,td.w)(),eu(!1),eh(e=>e+1);let t="/".concat(e.name);d(t),m.current&&(m.current.focus(),m.current.setSelectionRange(t.length,t.length))},[]),ek=n.useCallback(()=>{eu(!1),"/"===l&&d("")},[l]);(0,n.useEffect)(()=>{(async()=>{try{let e=C?"".concat((0,i.e)(),"/api/llm/current?sessionId=").concat(C):"".concat((0,i.e)(),"/api/llm/current"),t=await fetch(e);if(t.ok){let e=await t.json(),s=eo.find(t=>t.model===e.config.model);s?P(s):P({name:"".concat(e.config.provider,"/").concat(e.config.model),provider:e.config.provider,model:e.config.model})}}catch(e){console.error("Failed to fetch current model:",e),P(null)}})()},[C]),(0,n.useEffect)(()=>{(async()=>{try{let e=await fetch("".concat((0,i.e)(),"/api/llm/catalog?mode=flat"));if(!e.ok)return;let t=(await e.json()).models||[],s=null==O?void 0:O.provider,r=null==O?void 0:O.model;if(!s||!r)return;let a=t.find(e=>e.provider===s&&e.name===r);Y((null==a?void 0:a.supportedFileTypes)||[])}catch(e){Y([])}})()},[null==O?void 0:O.provider,null==O?void 0:O.model]);let eS=async()=>{let e=l.trim();if(e||u||h){if("/"===e)return void eN();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=new URL("/api/prompts/".concat(encodeURIComponent(s),"/resolve"),(0,i.e)());if(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};if(s.length>0&&(r._positional=s),Object.keys(r).length>0)try{a.searchParams.set("args",JSON.stringify(r))}catch(e){}}r&&a.searchParams.set("context",r);let n=new AbortController,l=setTimeout(()=>n.abort(),5e3);try{let t=await fetch(a.toString(),{signal:n.signal});if(clearTimeout(l),t.ok){let s=await t.json(),r="string"==typeof(null==s?void 0:s.text)?s.text:"";r.trim()&&(e=r)}}finally{clearTimeout(l)}}catch(e){}}t(e,null!=u?u:void 0,null!=h?h:void 0),d(""),x(null),f(null),ed(!1)}},eA=(e,t)=>{var s;if(!t&&0===en.length)return;let r=null!=t?t:en[Math.max(0,Math.min(e,en.length-1))],a=m.current;if(!a)return;let n=null!=(s=a.selectionStart)?s:l.length,i=el(l,n);if(-1===i)return;let o=l.slice(0,i),c=l.slice(n),u=r.name||r.uri.split("/").pop()||r.uri,x=r.serverName?"@".concat(r.serverName,":").concat(u):"@".concat(u);d(o+x+c),ee(!1),Q(""),es(0),requestAnimationFrame(()=>{let e=(o+x).length;a.setSelectionRange(e,e),a.focus()})},eE=e=>{if(X){if("ArrowDown"===e.key){e.preventDefault(),es(e=>(e+1)%Math.max(1,en.length));return}if("ArrowUp"===e.key){e.preventDefault(),es(e=>(e-1+Math.max(1,en.length))%Math.max(1,en.length));return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),eA(et);return}if("Escape"===e.key)return void ee(!1)}if(eI&&"Escape"===e.key){e.preventDefault(),eT(!1),d("");return}if("Enter"===e.key&&!e.shiftKey){if(e.preventDefault(),"#"===l.trim()){d(""),eT(!1),ef(!0);return}eS()}},[eI,eT]=(0,n.useState)(!1),[eO,eL]=(0,n.useState)(null),eR=e=>{let t=e.target.value;if(d(t),t.startsWith("/")&&!t.includes("\n")?ed(!0):ec&&ed(!1),"#"===t.trim()){eT(!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);eL({position:"fixed",left:s,bottom:Math.max(80,window.innerHeight-(t.bottom+window.scrollY)+64),width:r,zIndex:9999})}}else eT(!1),eL(null)};(0,n.useEffect)(()=>{var e;let t=m.current,s=t&&null!=(e=t.selectionStart)?e:l.length,r=el(l,s);if(r>=0){Q(l.slice(r+1,s)),ee(!0),es(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);ea({position:"fixed",left:t,bottom:Math.max(80,window.innerHeight-(e.bottom+window.scrollY)+64),width:s,zIndex:9999})}}else ee(!1),Q(""),ea(null)},[l]);let eF=n.useRef(!1);(0,n.useEffect)(()=>{X?eF.current||(eF.current=!0,H()):eF.current=!1},[X,H]);let eD=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)"))f({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);d(t=>t+e)}},e_=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);k.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";f({base64:n,mimeType:i,filename:"recording.".concat(l)}),C&&R.current.trackFileUploaded({fileType:i,fileSizeBytes:r.size,sessionId:C})}catch(e){eg("Failed to process audio recording. Please try again."),f(null)}},a.readAsDataURL(r),e.getTracks().forEach(e=>e.stop())},t.start(),N(!0)}catch(e){eg("Failed to start audio recording. Please check microphone permissions.")}};return(0,n.useEffect)(()=>{l&&B&&$(null),l&&W&&K(null)},[l,B]),l.length,(0,a.jsxs)("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[B&&(0,a.jsxs)(eB.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(ti.A,{className:"h-4 w-4"}),(0,a.jsxs)(eB.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:B}),(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>$(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(p.A,{className:"h-3 w-3"})})]})]}),W&&(0,a.jsxs)(eB.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(ti.A,{className:"h-4 w-4"}),(0,a.jsxs)(eB.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:W}),(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>K(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(p.A,{className:"h-3 w-3"})})]})]}),(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsx)("form",{onSubmit:e=>{e.preventDefault(),eS()},children:(0,a.jsxs)(eb,{children:[(u||h)&&(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)(w.$,{variant:"destructive",size:"icon",onClick:()=>x(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)(p.A,{className:"h-2 w-2"})})]}),h&&(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:[h.mimeType.startsWith("audio")?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(U.A,{className:"h-4 w-4"}),(0,a.jsx)("audio",{controls:!0,src:"data:".concat(h.mimeType,";base64,").concat(h.base64),className:"h-8"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(q.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-xs font-medium max-w-[160px] truncate",children:h.filename||"attachment"})]}),(0,a.jsx)(w.$,{variant:"destructive",size:"icon",onClick:()=>f(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)(p.A,{className:"h-2 w-2"})})]})]})}),(0,a.jsxs)("div",{className:"flex-auto overflow-y-auto relative",children:[b?(0,a.jsx)(ej.A,{ref:m,value:l,onChange:eR,onKeyDown:eE,onPaste:eD,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:l,onChange:eR,onKeyDown:eE,onPaste:eD,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"}),X&&er&&ev.createPortal((0,a.jsx)("div",{style:er,className:"max-h-64 overflow-y-auto rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:(0,a.jsx)(to,{resources:J,query:Z,selectedIndex:et,onHoverIndex:e=>es(e),onSelect:e=>eA(et,e),loading:G})}),document.body),eI&&eO&&ev.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)(D.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)(tu,{isVisible:ec,searchQuery:l,onSelectPrompt:e=>{let t="/".concat(e.name);d(t),ed(!1),m.current&&(m.current.focus(),m.current.setSelectionRange(t.length,t.length))},onClose:()=>{ed(!1)},onCreatePrompt:eN,refreshKey:ex}),(0,a.jsx)(ey,{leftButtons:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(eP,{onImageAttach:()=>{var e;return null==(e=g.current)?void 0:e.click()},onPdfAttach:()=>{var e;return null==(e=v.current)?void 0:e.click()},onAudioAttach:()=>{var e;return null==(e=j.current)?void 0:e.click()},supports:{image:V.length?V.includes("image"):void 0,pdf:V.length?V.includes("pdf"):void 0,audio:V.length?V.includes("audio"):void 0}}),(0,a.jsx)(eM,{isRecording:y,onToggleRecording:y?()=>{var e;null==(e=k.current)||e.stop(),N(!1)}:e_,disabled:!V.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)(eC,{isStreaming:A,onStreamingChange:E})}),(0,a.jsx)(tn,{}),(0,a.jsx)(w.$,{type:T?"button":"submit",onClick:T?()=>I(C||void 0):void 0,disabled:!T&&(!l.trim()&&!u&&!h||s),className:(0,c.cn)("h-10 w-10 p-0 rounded-full transition-all duration-200",T?"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":T?"Stop":"Send message",title:T?"Stop":"Send",children:T?(0,a.jsx)(S.A,{className:"h-3.5 w-3.5 fill-current"}):s?(0,a.jsx)(z.A,{className:"h-4 w-4 animate-spin"}):(0,a.jsx)(tl.A,{className:"h-4 w-4"})})]})})]})}),(0,a.jsx)("input",{ref:g,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){eg("Image file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("image/")){eg("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");x({base64:n,mimeType:l}),K(null),C&&R.current.trackImageUploaded({imageType:l,imageSizeBytes:s.size,sessionId:C})}catch(e){eg("Failed to process image file. Please try again."),x(null)}},r.onerror=e=>{eg("Failed to read image file. Please try again."),x(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:v,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){eg("PDF file too large. Maximum size is 64MB."),e.target.value="";return}if("application/pdf"!==s.type){eg("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);f({base64:a,mimeType:"application/pdf",filename:s.name}),K(null),C&&R.current.trackFileUploaded({fileType:"application/pdf",fileSizeBytes:s.size,sessionId:C})}catch(e){eg("Failed to process PDF file. Please try again."),f(null)}},r.onerror=e=>{eg("Failed to read PDF file. Please try again."),f(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:j,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){eg("Audio file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("audio/")){eg("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);f({base64:a,mimeType:s.type,filename:s.name}),K(null),C&&R.current.trackFileUploaded({fileType:s.type,fileSizeBytes:s.size,sessionId:C})}catch(e){eg("Failed to process audio file. Please try again."),f(null)}},r.onerror=e=>{eg("Failed to read audio file. Please try again."),f(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)(tg,{open:em,onClose:ek,onCreated:ew}),(0,a.jsx)(tv,{open:ep,onClose:()=>ef(!1),onSuccess:()=>{}})]})]})}var tb=s(3504);let ty=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 tN{static normalizeId(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return tN.instance||(tN.instance=new tN),tN.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=new AbortController,t=setTimeout(()=>e.abort(),1e4),s=await fetch("".concat((0,i.e)(),"/api/mcp/servers"),{signal:e.signal});if(clearTimeout(t),!s.ok)return;let r=(await s.json()).servers||[],a=new Set;for(let e of(r.forEach(e=>{if(!(null==e?void 0:e.id)||"string"!=typeof e.id)return;let t=tN.normalizeId(e.id);a.add(t)}),this.registryEntries)){let t=[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>tN.normalizeId(String(e))).some(e=>a.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 ty}constructor(){this.registryEntries=[],this.isInitialized=!1}}let tw=tN.getInstance();function tk(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card",className:(0,c.cn)("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",t),...s})}function tC(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-header",className:(0,c.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 tS(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-title",className:(0,c.cn)("leading-none font-semibold",t),...s})}function tA(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-content",className:(0,c.cn)("px-6",t),...s})}var tE=s(7091),tI=s(2171),tT=s(8177),tO=s(1756),tL=s(976),tR=s(5582);function tF(e){let{isOpen:t,onClose:s,onInstallServer:r,onOpenConnectModal:i,refreshTrigger:l,disableClose:o=!1}=e,[d,m]=(0,n.useState)([]),[u,f]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1),[j,b]=(0,n.useState)(null),[y,N]=(0,n.useState)(null),[k,C]=(0,n.useState)({}),[S,A]=(0,n.useState)(""),[E,I]=(0,n.useState)("grid"),[T,O]=(0,n.useState)(null),L=(0,n.useRef)(null),R=(0,n.useRef)(!0),F=(0,n.useRef)(null);(0,n.useEffect)(()=>(R.current=!0,()=>{R.current=!1,L.current&&clearTimeout(L.current),F.current&&F.current.abort()}),[]),(0,n.useEffect)(()=>{t&&(async()=>{F.current&&F.current.abort();let e=new AbortController;if(F.current=e,R.current){v(!0),b(null);try{await tw.syncWithServerStatus();let t=await tw.getEntries();R.current&&!e.signal.aborted&&(m(t),f(t))}catch(t){R.current&&!e.signal.aborted&&b(t instanceof Error?t.message:"Failed to load server registry")}finally{R.current&&!e.signal.aborted&&v(!1)}}})()},[t,l]);let P=(0,n.useCallback)(async(e,t)=>{if(R.current)try{let s=await tw.getEntries({...e,search:t||void 0});R.current&&f(s)}catch(e){R.current&&b(e instanceof Error?e.message:"Failed to filter entries")}},[]);(0,n.useEffect)(()=>(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{P(k,S)},300),()=>{L.current&&clearTimeout(L.current)}),[k,S,d,P]);let D=async e=>{if(R.current){N(e.id);try{let t=await r(e);"connected"===t?(await tw.setInstalled(e.id,!0),R.current&&(m(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)),f(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)))):R.current&&(m(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)),f(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)))}catch(e){R.current&&b(e instanceof Error?e.message:"Failed to install server")}finally{R.current&&N(null)}}},_=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},z=o||!!y,U=(0,n.useCallback)(e=>{e||z||s()},[z,s]),B=z?e=>{e.preventDefault()}:void 0;return(0,a.jsx)(eU.lG,{open:t,onOpenChange:U,children:(0,a.jsxs)(eU.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:z?e=>e.preventDefault():void 0,onInteractOutside:B,children:[(0,a.jsx)(eU.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)(tE.A,{className:"h-5 w-5 text-primary"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(eU.L3,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),(0,a.jsx)(eU.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)(w.$,{onClick:()=>{z||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)(tI.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),(0,a.jsxs)(w.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>s(),disabled:z,children:[(0,a.jsx)(p.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)(eJ.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)(eq.p,{placeholder:"Search servers and integrations...",value:S,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)(w.$,{variant:"grid"===E?"secondary":"ghost",size:"sm",onClick:()=>{I("grid"),O(null)},className:(0,c.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","grid"===E?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,a.jsx)(tT.A,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),(0,a.jsxs)(w.$,{variant:"list"===E?"secondary":"ghost",size:"sm",onClick:()=>{I("list"),O(null)},className:(0,c.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","list"===E?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,a.jsx)(tO.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:[j&&(0,a.jsx)(eB.Fc,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:(0,a.jsx)(eB.TN,{className:"text-red-800 font-medium",children:j})}),g?(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===u.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)(tE.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"}),S&&(0,a.jsxs)(w.$,{variant:"outline",onClick:()=>A(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[(0,a.jsx)(eJ.A,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):(0,a.jsx)("div",{className:(0,c.cn)("grid"===E?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:u.map((e,t)=>{let s=T===e.id,r=e.description&&e.description.length>100;return"grid"===E?(0,a.jsx)(tk,{className:(0,c.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:()=>O(s?null:e.id),children:[(0,a.jsx)(tC,{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)(M.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(tS,{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)(eH.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)(eV.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),e.category&&(0,a.jsx)(eH.E,{variant:"outline",className:(0,c.cn)("text-xs px-1.5 py-0 font-medium capitalize",_(e.category)),children:e.category})]})]})]})}),(0,a.jsxs)(tA,{className:"pt-0 flex flex-col flex-1",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:(0,c.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)(tL.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("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)(eH.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)(eH.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)(tR.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)(w.$,{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)(x.A,{className:"h-3 w-3 mr-1"}),"Less"]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(h.A,{className:"h-3 w-3 mr-1"}),"More"]})}),(0,a.jsx)("div",{className:"ml-auto",children:(0,a.jsx)(w.$,{onClick:t=>{t.stopPropagation(),D(e)},disabled:e.isInstalled||y===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,c.cn)("h-8 px-4 transition-all font-semibold text-sm shadow-sm",y===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:y===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)(M.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)(eY.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"Add"})]})})})]})]})]})},e.id):(0,a.jsx)(tk,{className:(0,c.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:()=>O(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)(M.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)(h.A,{className:(0,c.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)(eH.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)(eV.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),e.category&&(0,a.jsx)(eH.E,{variant:"outline",className:(0,c.cn)("text-xs px-1.5 py-0 font-medium capitalize",_(e.category)),children:e.category})]})]}),(0,a.jsx)(w.$,{onClick:t=>{t.stopPropagation(),D(e)},disabled:e.isInstalled||y===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,c.cn)("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",y===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:y===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)(M.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)(eY.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,c.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)(tL.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("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)(eH.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)(tR.A,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},e.id)})})]})]})})}var tP=s(7620),tD=s(5320),t_=s(3084),tM=s(5618);let tz=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),tU=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],tB=[/^your[\s_-]?/,/^enter[\s_-]?/];function tq(e){return Object.values(e).some(e=>{if(!e||""===e.trim())return!0;let t=e.trim().toLowerCase();return!!(tz.has(t)||tB.some(e=>e.test(t)))||tU.some(e=>t.includes(e))})}function t$(e){var t,s,r,a,n,i,l,o;let c=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:c,connectionMode:"lenient"};case"sse":return{type:"sse",url:null!=(n=e.config.url)?n:"",headers:null!=(i=e.config.headers)?i:{},timeout:c,connectionMode:"lenient"};default:return{type:"http",url:null!=(l=e.config.url)?l:"",headers:null!=(o=e.config.headers)?o:{},timeout:c,connectionMode:"lenient"}}}let tW="".concat((0,i.e)(),"/api");function tK(e){let{isOpen:t,onClose:s,onOpenConnectModal:r,onOpenConnectWithPrefill:l,onServerConnected:o,variant:d,refreshTrigger:m}=e,x=(0,tr.st)(),[f,g]=(0,n.useState)([]),[v,j]=(0,n.useState)(null),[k,C]=(0,n.useState)([]),[S,A]=(0,n.useState)(!1),[E,I]=(0,n.useState)(!1),[T,O]=(0,n.useState)(null),[L,R]=(0,n.useState)(null),[F,P]=(0,n.useState)(!1),[D,_]=(0,n.useState)(null),[M,z]=(0,n.useState)(null),[U,B]=(0,n.useState)(!1),[q,$]=(0,n.useState)(!1),W=(e,t)=>{console.error("ServersPanel Error (".concat(t,"):"),e),"servers"===t&&O(e),"tools"===t&&R(e)},K=(0,n.useCallback)(async e=>{A(!0),O(null),g([]),j(null),C([]),R(null);try{let t=await fetch("".concat(tW,"/mcp/servers"),e?{signal:e}:{});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to fetch servers"}));throw Error(e.message||e.error||"Server List: ".concat(t.statusText))}let s=(await t.json()).servers||[];if(g(s),s.length>0){let e=s.find(e=>"connected"===e.status);e?j(e.id):s.length>0&&j(s[0].id)}else console.log("No MCP servers found or returned from API.")}catch(e){"AbortError"!==e.name&&W(e.message,"servers")}finally{(null==e?void 0:e.aborted)||A(!1)}},[]),V=async e=>{let t=t$(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tq(t.env||{}),r=("sse"===t.type||"http"===t.type)&&Object.keys(t.headers||{}).length>0&&tq(t.headers||{});if(s||r)return"function"==typeof l&&l({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:()=>B(!1)}),"requires-input";try{$(!0);let s=await fetch("".concat((0,i.e)(),"/api/mcp/servers"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,config:t,persistToAgent:!1})}),r=await s.json();if(!s.ok)throw Error(r.error||"Server returned status ".concat(s.status));await K();try{await tw.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry after server install:",e)}return x.trackMCPServerConnected({serverName:e.name,transportType:t.type}),B(!1),null==o||o(e.name),"connected"}catch(e){throw Error(e.message||"Failed to install server")}finally{$(!1)}},Y=async e=>{let t=f.find(t=>t.id===e);if(t&&window.confirm('Are you sure you want to remove server "'.concat(t.name,'"?'))){_(e),O(null);try{let t=await fetch("".concat(tW,"/mcp/servers/").concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to remove server"}));throw Error(e.message||e.error||"Server Removal: ".concat(t.statusText))}v===e&&(j(null),C([]));try{let t=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-"),s=t(e),r=(await tw.getEntries()).find(e=>[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>t(String(e))).includes(s));r&&await tw.setInstalled(r.id,!1)}catch(e){console.warn("Failed to update registry installed state on delete:",e)}await K(),(0,td.w)();try{await tw.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry status after server deletion:",e)}}catch(e){W(e.message,"servers")}finally{_(null)}}},J=async e=>{let t=f.find(t=>t.id===e);if(t&&window.confirm('Restart server "'.concat(t.name,'"?'))){z(e),O(null);try{let t=await fetch("".concat(tW,"/mcp/servers/").concat(e,"/restart"),{method:"POST"});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to restart server"}));throw Error(e.message||e.error||"Server Restart: ".concat(t.statusText))}await K(),(0,td.w)();try{await tw.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry status after server restart:",e)}}catch(e){W(e.message,"servers")}finally{z(null)}}};(0,n.useEffect)(()=>{if(!t)return;let e=new AbortController;return K(e.signal),_(null),()=>{e.abort()}},[t,K]),(0,n.useEffect)(()=>{if(m&&t){let e=new AbortController;return K(e.signal),()=>{e.abort()}}},[m,t,K]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("\uD83D\uDD17 Server connected:",(null==e?void 0:e.detail)||{}),K()},s=e=>{let t=(null==e?void 0:e.detail)||{};if(console.log("\uD83D\uDCBE Resource cache invalidated for server panel:",t),v&&t.serverName){let e=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-");e(v)===e(t.serverName)&&G(v)}};return window.addEventListener("dexto:mcpServerConnected",e),window.addEventListener("dexto:resourceCacheInvalidated",s),()=>{window.removeEventListener("dexto:mcpServerConnected",e),window.removeEventListener("dexto:resourceCacheInvalidated",s)}},[t,K,v]);let G=(0,n.useCallback)(async(e,t)=>{let s=f.find(t=>t.id===e);if(C([]),R(null),!s||"connected"!==s.status)return void console.warn('Server "'.concat((null==s?void 0:s.name)||e,'" is not connected or not found. Cannot fetch tools.'));I(!0);try{let r=await fetch("".concat(tW,"/mcp/servers/").concat(e,"/tools"),t?{signal:t}:{});if(!r.ok){let e=await r.json().catch(()=>({error:"Failed to fetch tools for ".concat(s.name)}));throw Error(e.message||e.error||"Tool List (".concat(s.name,"): ").concat(r.statusText))}let a=await r.json();(null==t?void 0:t.aborted)||C(a.tools||[]),a.tools&&0!==a.tools.length||console.log('No tools found for server "'.concat(s.name,'".'))}catch(e){"AbortError"!==e.name&&W(e.message,"tools")}finally{(null==t?void 0:t.aborted)||I(!1)}},[f]);(0,n.useEffect)(()=>{if(!v)return;let e=new AbortController;return G(v,e.signal),()=>{e.abort()}},[v,G]);let H=f.find(e=>e.id===v);return"inline"===(null!=d?d:"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)(w.$,{variant:"ghost",size:"sm",onClick:()=>K(),disabled:S,className:"h-8 w-8 p-0",children:(0,a.jsx)(tP.A,{className:(0,c.cn)("h-3.5 w-3.5",S&&"animate-spin")})})})]}),(0,a.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,a.jsxs)(w.$,{onClick:()=>B(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,a.jsx)(tD.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,a.jsxs)(w.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,a.jsx)(eZ.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 (",f.length,")"]})}),S&&(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)(tP.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),T&&(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)(u.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:T})]})]})}),!S&&0===f.length&&!T&&(0,a.jsxs)("div",{className:"text-center py-8",children:[(0,a.jsx)(tE.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"})]}),f.map(e=>(0,a.jsx)("div",{onClick:()=>j(e.id),className:(0,c.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",v===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,c.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:[M===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Restarting ".concat(e.name,"…")})}):(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),J(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":"Restart server ".concat(e.name),disabled:D===e.id,children:(0,a.jsx)(t_.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{side:"top",children:"Restart server"})]}),D===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Removing ".concat(e.name,"…")})}):(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),Y(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":"Remove server ".concat(e.name),disabled:M===e.id,children:(0,a.jsx)(tp.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{side:"top",children:"Remove server"})]})]})]})},e.id))]}),H&&(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:()=>P(!F),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 ",k.length>0&&"(".concat(k.length,")")]}),(0,a.jsx)(h.A,{className:(0,c.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",F&&"rotate-180")})]})}),F&&(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[E&&(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)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),L&&(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)(u.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:L})]})]})}),!E&&0===k.length&&!L&&"connected"===H.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(tM.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"!==H.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(u.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"})]}),k.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)(tF,{isOpen:U,onClose:()=>B(!1),onInstallServer:V,onOpenConnectModal:r,disableClose:q})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:(0,c.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,c.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)(w.$,{variant:"ghost",size:"sm",onClick:()=>K(),disabled:S,className:"h-8 w-8 p-0",children:(0,a.jsx)(tP.A,{className:(0,c.cn)("h-3.5 w-3.5",S&&"animate-spin")})}),(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:(0,a.jsx)(p.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)(w.$,{onClick:()=>B(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,a.jsx)(tD.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,a.jsxs)(w.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,a.jsx)(eZ.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 (",f.length,")"]})}),S&&(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)(tP.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),T&&(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)(u.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:T})]})]})}),!S&&0===f.length&&!T&&(0,a.jsxs)("div",{className:"text-center py-8",children:[(0,a.jsx)(tE.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"})]}),f.map(e=>(0,a.jsx)("div",{onClick:()=>j(e.id),className:(0,c.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",v===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,c.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:[M===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Restarting ".concat(e.name,"…")})}):(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),J(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":"Restart server ".concat(e.name),disabled:D===e.id,children:(0,a.jsx)(t_.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{side:"top",children:"Restart server"})]}),D===e.id?(0,a.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,a.jsx)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":"Removing ".concat(e.name,"…")})}):(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),Y(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":"Remove server ".concat(e.name),disabled:M===e.id,children:(0,a.jsx)(tp.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{side:"top",children:"Remove server"})]})]})]})},e.id))]}),H&&(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:()=>P(!F),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)(h.A,{className:(0,c.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",F&&"rotate-180")})]})}),F&&(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[E&&(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)(tP.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),L&&(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)(u.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:L})]})]})}),!E&&0===k.length&&!L&&"connected"===H.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(tM.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"!==H.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(u.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"})]}),k.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)(tF,{isOpen:U,onClose:()=>B(!1),onInstallServer:V,onOpenConnectModal:r,disableClose:q})]})]})}var tV=s(2682),tY=s(2848);let tJ=function(e){let{onClick:t,className:s,variant:r="outline",side:n="bottom"}=e;return(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{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)(eY.A,{className:"h-4 w-4"})})}),(0,a.jsx)(N,{side:n,children:"New Chat (⌘K)"})]})})};function tG(e){let{isOpen:t,onClose:s,currentSessionId:r,onSessionChange:l,returnToWelcome:o,variant:d="overlay",onSearchOpen:m,onNewChat:x}=e,[h,f]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1),[k,C]=(0,n.useState)(null),[S,A]=(0,n.useState)(!1),[E,I]=(0,n.useState)(""),[T,O]=(0,n.useState)(null),L=n.useRef(!1),R=n.useRef(0),F=n.useRef(!1),[P,D]=(0,n.useState)(!1),[_,M]=(0,n.useState)(null),[z,U]=(0,n.useState)(!1),B=(0,n.useCallback)(async()=>{if(L.current)return;R.current+=1;let e=R.current;F.current||v(!0),C(null);try{let t,s=await fetch("".concat((0,i.e)(),"/api/sessions"));if(!s.ok)throw Error("Failed to fetch sessions");let r=await s.text();if(e!==R.current)return;if(!r.trim())return void f([]);try{t=JSON.parse(r)}catch(e){console.error("Failed to parse sessions response:",e),C("Failed to parse sessions data");return}let a=(t.sessions||[]).sort((e,t)=>{let s=e.lastActivity?new Date(e.lastActivity).getTime():0;return(t.lastActivity?new Date(t.lastActivity).getTime():0)-s});e===R.current&&(f(a),F.current=!0)}catch(t){e===R.current&&(console.error("Error fetching sessions:",t),C(t instanceof Error?t.message:"Failed to fetch sessions"))}finally{e===R.current&&(v(!1),F.current=!0)}},[]);(0,n.useEffect)(()=>{t&&!F.current&&B()},[t,B]),(0,n.useEffect)(()=>{let e=()=>{F.current=!1,B()},t=e=>{var t;let s=null==(t=e.detail)?void 0:t.sessionId;s&&f(e=>e.some(e=>e.id===s)?e.map(e=>e.id===s?{...e,messageCount:e.messageCount+1,lastActivity:new Date().toISOString()}:e):[{id:s,createdAt:new Date().toISOString(),lastActivity:new Date().toISOString(),messageCount:1,title:null},...e])},s=e=>{var t;let s=null==(t=e.detail)?void 0:t.sessionId;s&&f(e=>e.map(e=>e.id===s?{...e,messageCount:e.messageCount+1,lastActivity:new Date().toISOString()}: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&&f(e=>e.map(e=>e.id===r?{...e,title:a}:e))};return window.addEventListener("dexto:message",t),window.addEventListener("dexto:response",s),window.addEventListener("dexto:sessionTitleUpdated",r),window.addEventListener("dexto:agentSwitched",e),()=>{window.removeEventListener("dexto:message",t),window.removeEventListener("dexto:response",s),window.removeEventListener("dexto:sessionTitleUpdated",r),window.removeEventListener("dexto:agentSwitched",e)}},[B]);let q=async()=>{try{let e,t=await fetch("".concat((0,i.e)(),"/api/sessions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:E.trim()||void 0})});if(!t.ok){let e,s=await t.text();try{e=s?JSON.parse(s):{}}catch(t){e={error:"Failed to create session"}}throw Error(e.error||"Failed to create session")}let s=await t.text();if(!s.trim())throw Error("Empty response from session creation");try{e=JSON.parse(s)}catch(e){throw console.error("Failed to parse session creation response:",e),Error("Invalid response from session creation")}f(t=>[...t,e.session]),I(""),A(!1),l(e.session.id)}catch(e){console.error("Error creating session:",e),C(e instanceof Error?e.message:"Failed to create session")}},$=async e=>{let t=r===e;L.current=!0,O(e);try{let s=await fetch("".concat((0,i.e)(),"/api/sessions/").concat(e),{method:"DELETE"});if(!s.ok){let e,t=await s.text();try{e=t?JSON.parse(t):{}}catch(t){e={error:"Failed to delete session"}}throw Error(e.error||"Failed to delete session")}f(t=>t.filter(t=>t.id!==e)),t&&o(),await new Promise(e=>setTimeout(e,100))}catch(e){console.error("Error deleting session:",e),C(e instanceof Error?e.message:"Failed to delete session")}finally{L.current=!1,O(null)}},W=async()=>{if(!_)return;let e=r===_;L.current=!0,U(!0);try{if(!(await fetch("".concat((0,i.e)(),"/api/sessions/").concat(_),{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok)throw Error("Failed to delete conversation");f(e=>e.filter(e=>e.id!==_)),e&&o(),D(!1),M(null),await new Promise(e=>setTimeout(e,100))}catch(e){console.error("Error deleting conversation:",e),C(e instanceof Error?e.message:"Failed to delete conversation")}finally{L.current=!1,U(!1)}},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:[m&&(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"outline",size:"sm",onClick:m,className:"h-7 w-7 p-0","aria-label":"Search conversations",children:(0,a.jsx)(eJ.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{children:"Search conversations (⌘⇧S)"})]})}),x&&(0,a.jsx)(tJ,{onClick:x,variant:"outline"}),"overlay"===d&&(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:s,className:"h-7 w-7 p-0","aria-label":"Close panel",children:(0,a.jsx)(p.A,{className:"h-3.5 w-3.5"})})]})]}),k&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eB.Fc,{variant:"destructive",children:[(0,a.jsx)(u.A,{className:"h-4 w-4"}),(0,a.jsx)(eB.TN,{children:k})]})}),(0,a.jsx)(tV.F,{className:"flex-1",children:g?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tP.A,{className:"h-6 w-6 animate-spin"})}):0===h.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground px-4",children:[(0,a.jsx)(tY.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)(j,{children:h.map(e=>{let t=e.title&&e.title.trim().length>0?e.title:e.id,s=r===e.id;return(0,a.jsxs)(b,{delayDuration:150,children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{className:s?"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":s?"page":void 0,onClick:()=>l(e.id),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),l(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:s?"font-semibold text-sm truncate":"font-normal text-sm truncate text-muted-foreground",children:t})}),(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=new Date(e),s=new Date().getTime()-t.getTime(),r=Math.floor(s/6e4),a=Math.floor(s/36e5),n=Math.floor(s/864e5);return r<1?"Just now":r<60?"".concat(r,"m ago"):a<24?"".concat(a,"h ago"):"".concat(n,"d ago")})(e.lastActivity)}),(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),e.messageCount>0?(M(e.id),D(!0)):$(e.id)},disabled:T===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)(tp.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"})})]})]})})}),(0,a.jsx)(N,{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)(eU.lG,{open:S,onOpenChange:A,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eU.c7,{children:(0,a.jsx)(eU.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)(e$.J,{htmlFor:"sessionId",children:"Chat ID"}),(0,a.jsx)(eq.p,{id:"sessionId",value:E,onChange:e=>I(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)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),(0,a.jsx)(w.$,{onClick:q,children:"Start Chat"})]})]})}),(0,a.jsx)(eU.lG,{open:P,onOpenChange:D,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsxs)(eU.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eU.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",_&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,a.jsx)("span",{className:"font-mono",children:_})]})]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>D(!1),children:"Cancel"}),(0,a.jsxs)(w.$,{variant:"destructive",onClick:W,disabled:z,className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:z?"Deleting...":"Delete Conversation"})]})]})]})})]});return"inline"===d?(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,c.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.jsx)("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:(0,c.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",t?"translate-x-0":"-translate-x-full"),children:K})]})}var tH=s(5160),tZ=s(174);function tQ(e){let{isOpen:t,onClose:s,variant:r="modal"}=e,[l,o]=(0,n.useState)([]),[d,m]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),[p,f]=(0,n.useState)(""),[g,v]=(0,n.useState)(null),[k,C]=(0,n.useState)(!1),[S,A]=(0,n.useState)(!1),[E,I]=(0,n.useState)(null),T=(0,n.useCallback)(async()=>{m(!0),h(null);try{let e=await fetch("".concat((0,i.e)(),"/api/memory"));if(!e.ok)throw Error("Failed to fetch memories");let t=await e.json();o(t.memories||[])}catch(e){console.error("Error fetching memories:",e),h(e instanceof Error?e.message:"Failed to fetch memories")}finally{m(!1)}},[]);(0,n.useEffect)(()=>{t&&T()},[t,T]);let O=async e=>{v(e);try{let t=await fetch("".concat((0,i.e)(),"/api/memory/").concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to delete memory")}o(t=>t.filter(t=>t.id!==e)),A(!1),I(null)}catch(e){console.error("Error deleting memory:",e),h(e instanceof Error?e.message:"Failed to delete memory")}finally{v(null)}},L=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:120;return e.length<=t?e:e.slice(0,t)+"..."},R=l.filter(e=>{var t;if(!p.trim())return!0;let s=p.toLowerCase();return e.content.toLowerCase().includes(s)||(null==(t=e.tags)?void 0:t.some(e=>e.toLowerCase().includes(s)))}),F=(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)(D.A,{className:"h-4 w-4"}),(0,a.jsx)("h2",{className:"text-base font-semibold",children:"Memories"}),(0,a.jsx)(eH.E,{variant:"secondary",className:"text-xs",children:l.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)(eJ.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,a.jsx)(eq.p,{placeholder:"Search memories...",value:p,onChange:e=>f(e.target.value),className:"pl-8 h-8 text-sm"})]}),(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{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)(eY.A,{className:"h-4 w-4"})})}),(0,a.jsx)(N,{children:"Create Memory"})]})})]})}),x&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eB.Fc,{variant:"destructive",children:[(0,a.jsx)(u.A,{className:"h-4 w-4"}),(0,a.jsx)(eB.TN,{children:x})]})}),(0,a.jsx)(tV.F,{className:"flex-1 p-4",children:(0,a.jsx)("div",{className:"space-y-2",children:d?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tP.A,{className:"h-6 w-6 animate-spin"})}):0===R.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,a.jsx)(D.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),p.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"})]})]}):R.map(e=>{var t,s,r;return(0,a.jsx)("div",{className:(0,c.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:L(e.content)}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,a.jsx)(tH.A,{className:"h-3 w-3 text-muted-foreground"}),e.tags.map((e,t)=>(0,a.jsx)(eH.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)(tZ.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:(e=>{let t=new Date(e),s=new Date().getTime()-t.getTime(),r=Math.floor(s/6e4),a=Math.floor(s/36e5),n=Math.floor(s/864e5);return r<1?"Just now":r<60?"".concat(r,"m ago"):a<24?"".concat(a,"h ago"):"".concat(n,"d ago")})(e.updatedAt)})]}),(null==(s=e.metadata)?void 0:s.source)&&(0,a.jsx)(eH.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)(eH.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)(w.$,{variant:"ghost",size:"sm",onClick:()=>{I(e),A(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:(0,a.jsx)(tp.A,{className:"h-3.5 w-3.5 text-destructive"})})})]})},e.id)})})}),(0,a.jsx)(tv,{open:k,onClose:()=>C(!1),onSuccess:()=>{T()}}),(0,a.jsx)(eU.lG,{open:S,onOpenChange:A,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsxs)(eU.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Memory"})]}),(0,a.jsxs)(eU.rr,{children:["This will permanently delete this memory. This action cannot be undone.",E&&(0,a.jsx)("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:L(E.content,100)})]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),(0,a.jsxs)(w.$,{variant:"destructive",onClick:()=>E&&O(E.id),disabled:g===(null==E?void 0:E.id),className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:g===(null==E?void 0:E.id)?"Deleting...":"Delete Memory"})]})]})]})})]});return"inline"===r?(0,a.jsx)("div",{className:"h-full",children:F}):(0,a.jsx)(eU.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[(0,a.jsx)(eU.c7,{className:"sr-only",children:(0,a.jsx)(eU.L3,{children:"Memories"})}),F]})})}function tX(e){let{websocket:t,onApprovalRequest:s,onApprove:r,onDeny:a,onHandlersReady:i}=e,[l,c]=(0,n.useState)(null),{currentSessionId:d}=(0,o.v)(),m=n.useRef([]);(0,n.useEffect)(()=>{null==s||s(l)},[l,s]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{try{let t=JSON.parse(e.data);if("approvalRequest"===t.event){let e;if(!(null==t?void 0:t.data)||"object"!=typeof t.data)return void console.error("[WebUI] Invalid approvalRequest: message.data is missing or not an object");let s=t.data.sessionId;if(s&&s!==d)return;let r=t.data.type;if("tool_confirmation"!==r&&"elicitation"!==r)return void console.debug("[WebUI] Ignoring unsupported approval type: ".concat(r));let a=t.data.approvalId,n=t.data.timestamp;if("string"!=typeof a||"string"!=typeof n)return void console.error("[WebUI] Invalid approvalRequest: approvalId and timestamp must be strings");if("tool_confirmation"===r){let s=t.data.metadata;if(!s||"object"!=typeof s)return void console.error("[WebUI] Invalid tool_confirmation: metadata is missing or not an object");let i=s.toolName,l=s.args;if("string"!=typeof i)return void console.error("[WebUI] Invalid tool_confirmation: metadata.toolName must be a string");if(!l||"object"!=typeof l)return void console.error("[WebUI] Invalid tool_confirmation: metadata.args must be an object");e={approvalId:a,type:r,toolName:i,args:l,description:"string"==typeof s.description?s.description:void 0,timestamp:n,sessionId:t.data.sessionId,metadata:s}}else e={approvalId:a,type:r,timestamp:n,sessionId:t.data.sessionId,metadata:t.data.metadata||{}};console.debug("[WebUI] Received approvalRequest: ".concat(JSON.stringify(e))),l?m.current.push(e):c(e)}}catch(e){console.error("[WebUI] Error handling approvalRequest message: ".concat(e instanceof Error?e.message:String(e)))}};return t.addEventListener("message",e),()=>{t.removeEventListener("message",e)}},[t,l,d]);let u=(0,n.useCallback)((e,s,r)=>{if(!l||!t)return;let a="elicitation"===l.type?e&&s?{formData:s}:void 0:{rememberChoice:null!=r&&r},n={type:"approvalResponse",data:{approvalId:l.approvalId,status:e?"approved":"denied",sessionId:l.sessionId,...a?{data:a}:{}}};if(console.debug("[WebUI] Sending approvalResponse: ".concat(JSON.stringify(n))),t.readyState!==WebSocket.OPEN)return void console.warn("[WebUI] WebSocket not open (readyState: ".concat(t.readyState,"), cannot send approval response for ").concat(l.approvalId));try{t.send(JSON.stringify(n))}catch(e){console.error("[WebUI] Failed to send approval response: ".concat(e instanceof Error?e.message:String(e)));return}if(c(null),m.current.length>0){let e=m.current.shift();setTimeout(()=>{c(e)},100)}},[l,t]),x=(0,n.useCallback)((e,t)=>{u(!0,e,t),null==r||r(e,t)},[u,r]),h=(0,n.useCallback)(()=>{u(!1),null==a||a()},[u,a]);return(0,n.useEffect)(()=>{i&&i({onApprove:x,onDeny:h})},[x,h,i]),null}var t0=s(3665),t1=s(8989);function t2(e){let{isOpen:t,onClose:s,onNavigateToSession:r}=e,[l,o]=(0,n.useState)(""),[d,m]=(0,n.useState)([]),[u,x]=(0,n.useState)(!1),[h,p]=(0,n.useState)(null),[f,g]=(0,n.useState)(0),v=(0,n.useCallback)(async e=>{if(!e.trim()){m([]),p(null);return}x(!0),p(null);try{let t=new URLSearchParams({q:e,limit:"10",offset:"0"}),s=await fetch("".concat((0,i.e)(),"/api/search/messages?").concat(t));if(!s.ok){let e=await s.text();throw Error("Search failed: ".concat(s.status," ").concat(e))}let r=await s.json();m(r.results),g(0)}catch(e){console.error("Search error:",e),m([]),p(e instanceof Error?e.message:"Search failed")}finally{x(!1)}},[]);(0,n.useEffect)(()=>{let e=setTimeout(()=>{v(l)},300);return()=>clearTimeout(e)},[l,v]),(0,n.useEffect)(()=>{t&&(o(""),m([]),p(null),g(0))},[t]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{if(t&&(!e.ctrlKey&&!e.metaKey||!e.shiftKey||"S"!==e.key))switch(e.key){case"ArrowDown":e.preventDefault(),e.stopPropagation(),g(e=>Math.min(e+1,d.length-1));break;case"ArrowUp":e.preventDefault(),e.stopPropagation(),g(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),e.stopPropagation(),d[f]&&j(d[f]);break;case"Escape":e.preventDefault(),e.stopPropagation(),s()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,d,f,s]);let j=e=>{r(e.sessionId,e.messageIndex),s()};return(0,a.jsx)(eU.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eU.Cf,{className:"max-w-2xl p-0 top-[20%] transform translate-y-0",children:[(0,a.jsx)(eU.c7,{children:(0,a.jsx)(eU.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)(eJ.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),(0,a.jsx)(eq.p,{placeholder:"Search conversations...",value:l,onChange:e=>o(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:u?(0,a.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,a.jsx)(tP.A,{className:"h-6 w-6 animate-spin mr-3"}),(0,a.jsx)("span",{className:"text-muted-foreground",children:"Searching..."})]}):h?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)(eJ.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:h}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):(0,a.jsx)(tV.F,{className:"h-full",children:(0,a.jsx)("div",{className:"p-2",children:d.length>0?(0,a.jsx)("div",{className:"space-y-1",children:d.map((e,t)=>(0,a.jsxs)("div",{className:(0,c.cn)("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",t===f?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>j(e),children:[(0,a.jsx)("div",{className:"flex-shrink-0 mt-1",children:(0,a.jsx)(eH.E,{className:(0,c.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)(R.A,{className:"w-4 h-4"});case"assistant":return(0,a.jsx)(F.A,{className:"w-4 h-4"});case"system":return(0,a.jsx)(t0.A,{className:"w-4 h-4"});default:return(0,a.jsx)(t1.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,t)=>r.test(e)?(0,a.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:e},t):e)})(e.context,l)})]}),(0,a.jsx)(_.A,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},t))}):l?(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(eJ.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)(eJ.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 t5=s(7345),t4=s(9613);function t3(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)(t4.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 t8(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)(M.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)(ti.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)(u.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)(ti.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)(u.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 t6(e){let{value:t,onChange:s,onValidate:r,isValidating:n=!1,isValid:i=!0,errors:l=[],warnings:o=[],hasUnsavedChanges:c=!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)(t3,{value:t,onChange:s,onValidate:r,height:"100%"})}),(0,a.jsx)(t8,{isValidating:n,isValid:i,errors:l,warnings:o,hasUnsavedChanges:c})]})}function t7(e){let{title:t,children:s,defaultOpen:r=!0,open:i,onOpenChange:l,errorCount:o=0,sectionErrors:d=[],className:m}=e,[u,x]=(0,n.useState)(r),p=void 0!==i,f=p?i:u;return(0,a.jsxs)("div",{className:(0,c.cn)("border border-border rounded-lg overflow-hidden",m),children:[(0,a.jsxs)("button",{onClick:()=>{let e=!f;p?null==l||l(e):x(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)(b,{children:[(0,a.jsx)(y,{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)(N,{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)(h.A,{className:(0,c.cn)("h-4 w-4 transition-transform duration-200",f&&"transform rotate-180")})]}),f&&(0,a.jsx)("div",{className:"px-4 py-4 space-y-4",children:s})]})}var t9=s(2449),se=s(3973);let st=["openai","openai-compatible","anthropic","google","groq","xai","cohere"],ss=["vercel","in-built"];function sr(e){var t;let{value:s,onChange:r,errors:i={},open:l,onOpenChange:o,errorCount:c=0,sectionErrors:d=[]}=e,[m,u]=(0,n.useState)(!1),x=(e,t)=>{r({...s,[e]:t})};return(0,a.jsx)(t7,{title:"LLM Configuration",defaultOpen:!0,open:l,onOpenChange:o,errorCount:c,sectionErrors:d,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{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..."}),st.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)(ts,{htmlFor:"model",tooltip:"The specific model identifier (e.g., gpt-5, claude-sonnet-4-5-20250929)",children:"Model *"}),(0,a.jsx)(eq.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)(ts,{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)(eq.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)(t9.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(se.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)(ts,{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:ss.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)(ts,{htmlFor:"maxIterations",tooltip:"Maximum number of agent reasoning iterations per turn",children:"Max Iterations"}),(0,a.jsx)(eq.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)(ts,{htmlFor:"baseURL",tooltip:"Custom base URL for the LLM provider (optional, for proxies or custom endpoints)",children:"Base URL"}),(0,a.jsx)(eq.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)(ts,{htmlFor:"temperature",tooltip:"Controls randomness in responses (0.0 = deterministic, 1.0 = creative)",children:"Temperature"}),(0,a.jsx)(eq.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)(ts,{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)(eq.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)(ts,{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)(eq.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 sa=["dateTime","memorySummary","resources"];function sn(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:c=[]}=e,[d,m]=(0,n.useState)(new Set),[u,p]=(0,n.useState)({}),f=t.contributors||[],g=(e,t)=>{s({contributors:f.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)(t7,{title:"System Prompt",defaultOpen:!0,open:i,onOpenChange:l,errorCount:o,sectionErrors:c,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===f.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No contributors configured"}):f.map(e=>{var t,r,n,i,l,o,c,v,j;let b=d.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:[b?(0,a.jsx)(x.A,{className:"h-4 w-4"}):(0,a.jsx)(h.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)(w.$,{variant:"ghost",size:"sm",onClick:()=>{var t;return t=e.id,void(s({contributors:f.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)(tp.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),b&&(0,a.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"contributor-id-".concat(e.id),tooltip:"Unique identifier for this contributor",children:"ID *"}),(0,a.jsx)(eq.p,{id:"contributor-id-".concat(e.id),value:e.id,onChange:t=>g(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)(ts,{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=>g(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)(ts,{htmlFor:"contributor-priority-".concat(e.id),tooltip:"Execution priority (lower numbers run first)",children:"Priority *"}),(0,a.jsx)(eq.p,{id:"contributor-priority-".concat(e.id),type:"number",value:e.priority,onChange:t=>{let s=Number.parseInt(t.target.value,10);g(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=>g(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)(ts,{htmlFor:"contributor-content-".concat(e.id),tooltip:"Static content for the system prompt",children:"Content *"}),(0,a.jsx)(tx.T,{id:"contributor-content-".concat(e.id),value:e.content,onChange:t=>g(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)(ts,{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=>g(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:sa.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)(ts,{htmlFor:"contributor-files-".concat(e.id),tooltip:"File paths to include, comma-separated",children:"Files *"}),(0,a.jsx)(eq.p,{id:"contributor-files-".concat(e.id),value:(c=e.id,v=e.files,null!=(j=u[c])?j:v.join(", ")),onChange:t=>{var s,r;return s=e.id,r=t.target.value,void p(e=>({...e,[s]:r}))},onBlur:t=>((e,t)=>{p(t=>{let s={...t};return delete s[e],s});let s=t.split(",").map(e=>e.trim()).filter(Boolean);g(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=>g(e.id,{options:{...e.options,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=>g(e.id,{options:{...e.options,includeMetadata:t.target.checked}}),className:"rounded border-input"}),(0,a.jsx)("span",{children:"Include file metadata"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"contributor-separator-".concat(e.id),tooltip:"Separator between multiple files",children:"Separator"}),(0,a.jsx)(eq.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=>g(e.id,{options:{...e.options,separator:t.target.value}}),placeholder:"\\n\\n---\\n\\n"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{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=>g(e.id,{options:{...e.options,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)(ts,{htmlFor:"contributor-max-file-size-".concat(e.id),tooltip:"Maximum file size in bytes",children:"Max File Size (bytes)"}),(0,a.jsx)(eq.p,{id:"contributor-max-file-size-".concat(e.id),type:"number",value:(null==(l=e.options)?void 0:l.maxFileSize)||1e5,onChange:t=>{let s=Number.parseInt(t.target.value,10);g(e.id,{options:{...e.options,maxFileSize:Number.isNaN(s)?void 0:s}})},placeholder:"100000",min:"1"})]})]})]})]})]})]},e.id)}),(0,a.jsxs)(w.$,{onClick:()=>{let e="contributor-".concat(Date.now()),t={id:e,type:"static",priority:10*f.length,enabled:!0,content:""};s({contributors:[...f,t]}),m(t=>new Set(t).add(e))},variant:"outline",size:"sm",className:"w-full",children:[(0,a.jsx)(eY.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 si=(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))(si||{}),sl=(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.SYSTEM_PROMPT="system_prompt",e.PREFERENCE="preference",e.AGENT_REGISTRY="agent_registry",e.RESOURCE="resource",e.PROMPT="prompt",e.MEMORY="memory",e.PLUGIN="plugin",e.FILESYSTEM="filesystem",e.PROCESS="process",e))(sl||{}),so=(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))(so||{}),sc=s(4536),sd=s(9246);sc.Yj().transform(e=>e.trim()).refine(e=>e.length>0,{message:"Required"}),sc.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 sm=e=>sc.Yj().transform(t=>{if("string"!=typeof t)return"";let s=null!=e?e:sd.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()}),su=e=>sm(e).refine(e=>{try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}},{message:"Invalid URL"});var sx=s(3292),sh=s(9246);let sp=["stdio","sse","http"],sf=["strict","lenient"],sg="lenient",sv=sc.Ik({type:sc.eu("stdio"),command:sm().superRefine((e,t)=>{0===e.length&&t.addIssue({code:sx.eq.custom,message:"Stdio server requires a non-empty command",params:{code:si.COMMAND_MISSING,scope:sl.MCP,type:so.USER}})}),args:sc.YO(sm()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),env:sc.g1(sm()).default({}).describe("Optional environment variables for the server process"),timeout:sc.au.number().int().positive().default(3e4),connectionMode:sc.k5(sf).default(sg)}).strict(),sj=sc.Ik({type:sc.eu("sse"),url:su(sh.env).describe("URL for the SSE server endpoint"),headers:sc.g1(sm()).default({}),timeout:sc.au.number().int().positive().default(3e4),connectionMode:sc.k5(sf).default(sg)}).strict(),sb=sc.Ik({type:sc.eu("http"),url:su(sh.env).describe("URL for the HTTP server"),headers:sc.g1(sm()).default({}),timeout:sc.au.number().int().positive().default(3e4),connectionMode:sc.k5(sf).default(sg)}).strict(),sy=sc.gM("type",[sv,sj,sb]).superRefine((e,t)=>{}).brand();function sN(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:c=[]}=e,[d,m]=(0,n.useState)(new Set),[u,p]=(0,n.useState)({}),f=Object.entries(t||{}),g=(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})},v=(e,t,s)=>{var r;return null!=(r=u["".concat(e,":").concat(t)])?r:s},j=(e,t,s)=>{let r="".concat(e,":").concat(t);p(e=>({...e,[r]:s}))},b=(e,t)=>{let s="".concat(e,":").concat(t);p(e=>{let t={...e};return delete t[s],t})};return(0,a.jsx)(t7,{title:"MCP Servers",defaultOpen:!1,open:i,onOpenChange:l,errorCount:o,sectionErrors:c,children:(0,a.jsxs)("div",{className:"space-y-4",children:[0===f.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No MCP servers configured"}):f.map(e=>{let[n,i]=e,l=d.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)(x.A,{className:"h-4 w-4"}):(0,a.jsx)(h.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)(w.$,{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)(tp.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)(ts,{htmlFor:"server-name-".concat(n),tooltip:"Unique identifier for this MCP server",children:"Server Name"}),(0,a.jsx)(eq.p,{id:"server-name-".concat(n),value:n,onChange:e=>g(n,{name:e.target.value}),placeholder:"e.g., filesystem"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{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?g(n,{type:"stdio",command:"",args:void 0,env:void 0}):g(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:sp.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)(ts,{htmlFor:"server-command-".concat(n),tooltip:"The command to execute (e.g., npx, node, python)",children:"Command *"}),(0,a.jsx)(eq.p,{id:"server-command-".concat(n),value:"command"in i?i.command:"",onChange:e=>g(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)(ts,{htmlFor:"server-args-".concat(n),tooltip:"Command arguments, comma-separated",children:"Arguments"}),(0,a.jsx)(eq.p,{id:"server-args-".concat(n),value:v(n,"args",("args"in i&&i.args?i.args:[]).join(", ")),onChange:e=>j(n,"args",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"args"),!t.trim())return void g(e,{args:void 0});let s=t.split(",").map(e=>e.trim()).filter(Boolean);g(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)(ts,{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:v(n,"env",Object.entries("env"in i&&i.env||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>j(n,"env",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"env"),!t.trim())return void g(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())}),g(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)(ts,{htmlFor:"server-url-".concat(n),tooltip:"The URL endpoint for the MCP server",children:"URL *"}),(0,a.jsx)(eq.p,{id:"server-url-".concat(n),value:"url"in i?i.url:"",onChange:e=>g(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)(ts,{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:v(n,"headers",Object.entries("headers"in i&&i.headers||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>j(n,"headers",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"headers"),!t.trim())return void g(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())}),g(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)(ts,{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||sg,onChange:e=>g(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:sf.map(e=>(0,a.jsx)("option",{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]})]},n)}),(0,a.jsxs)(w.$,{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)(eY.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})]})})}sc.g1(sy).describe("A dictionary of server configurations, keyed by server name").brand();var sw=(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))(sw||{});let sk=["in-memory","redis"],sC=sc.Ik({maxConnections:sc.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:sc.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:sc.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:sc.g1(sc.bz()).optional().describe("Backend-specific options")}),sS=sC.extend({type:sc.eu("in-memory")}).strict(),sA=sC.extend({type:sc.eu("redis"),url:sm().optional().describe("Redis connection URL (redis://...)"),host:sc.Yj().optional().describe("Redis host"),port:sc.ai().int().positive().optional().describe("Redis port"),password:sc.Yj().optional().describe("Redis password"),database:sc.ai().int().nonnegative().optional().describe("Redis database number")}).strict();sc.gM("type",[sS,sA],{errorMap:(e,t)=>e.code===sx.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:sx.eq.custom,message:"Redis cache requires either 'url' or 'host' to be specified",path:["url"],params:{code:sw.CONNECTION_CONFIG_MISSING,scope:sl.STORAGE,type:so.USER}})});let sE=["in-memory","sqlite","postgres"],sI=sc.Ik({maxConnections:sc.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:sc.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:sc.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:sc.g1(sc.bz()).optional().describe("Backend-specific options")}),sT=sI.extend({type:sc.eu("in-memory")}).strict(),sO=sI.extend({type:sc.eu("sqlite"),path:sc.Yj().optional().describe("SQLite database file path (optional, will auto-detect using path resolver if not provided)"),database:sc.Yj().optional().describe("Database filename (default: <agent-id>.db)")}).strict(),sL=sI.extend({type:sc.eu("postgres"),url:sm().optional().describe("PostgreSQL connection URL (postgresql://...)"),connectionString:sm().optional().describe("PostgreSQL connection string"),host:sc.Yj().optional().describe("PostgreSQL host"),port:sc.ai().int().positive().optional().describe("PostgreSQL port"),database:sc.Yj().optional().describe("PostgreSQL database name"),password:sc.Yj().optional().describe("PostgreSQL password")}).strict();function sR(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,c=e=>{s({...t,cache:{...t.cache,...e}})},d=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)(t7,{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)(ts,{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=>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:sk.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),m&&"url"in t.cache&&(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"cache-url",tooltip:"Redis connection URL (e.g., redis://localhost:6379)",children:"Redis URL"}),(0,a.jsx)(eq.p,{id:"cache-url",value:t.cache.url||"",onChange:e=>c({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)(ts,{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=>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:sE.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),u&&(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{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)(eq.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?d({path:e.target.value||void 0}):d({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"]})]})]})]})})}sc.gM("type",[sT,sO,sL],{errorMap:(e,t)=>e.code===sx.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:sx.eq.custom,message:"PostgreSQL database requires one of 'url', 'connectionString', or 'host' to be specified",path:["url"],params:{code:sw.CONNECTION_CONFIG_MISSING,scope:sl.STORAGE,type:so.USER}})});let sF=["search_history","ask_user","read_file","glob_files","grep_content","write_file","edit_file","bash_exec","bash_output","kill_process"],sP=["event-based","auto-approve","auto-deny"],sD=["memory","storage"],s_="event-based",sM="storage";sc.YO(sc.k5(sF).describe("Available internal tool names")).default([]).describe("Array of internal tool names to enable. Empty array = disabled. Available tools: ".concat(sF.join(", ")));let sz=sc.Ik({alwaysAllow:sc.YO(sc.Yj()).default([]).describe('Tools that never require approval (low-risk). Use full qualified names (e.g., "internal--ask_user", "mcp--filesystem--read_file")'),alwaysDeny:sc.YO(sc.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 sU(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,c=e=>{s({...t,...e})};return(0,a.jsx)(t7,{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)(ts,{htmlFor:"confirmation-mode",tooltip:"How the agent handles tool execution requests",children:"Confirmation Mode"}),(0,a.jsx)("select",{id:"confirmation-mode",value:t.mode||s_,onChange:e=>c({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:sP.map(e=>(0,a.jsx)("option",{value:e,children:"auto-approve"===e?"Auto-approve":"event-based"===e?"Event-based":"Auto-deny"},e))}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"event-based"===t.mode?"Require explicit approval before executing tools":"auto-deny"===t.mode?"Automatically deny all tool executions":"Automatically approve tool executions"})]}),"event-based"===t.mode&&(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"confirmation-timeout",tooltip:"How long to wait for approval before timing out",children:"Timeout (seconds)"}),(0,a.jsx)(eq.p,{id:"confirmation-timeout",type:"number",value:t.timeout||"",onChange:e=>c({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)(ts,{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||sM,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:sD.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})]})})}function sB(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,c]=(0,n.useState)({basic:!0,llm:!1,systemPrompt:!1,mcpServers:!1,storage:!1,toolConfirmation:!1}),d=function(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}(i);(0,n.useEffect)(()=>{let e=Object.keys(d).filter(e=>d[e].length>0);e.length>0&&c(t=>{let s={...t};return e.forEach(e=>{s[e]=!0}),s})},[i]);let m=e=>{c(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)(ti.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)(t7,{title:"Basic Information",open:o.basic,onOpenChange:()=>m("basic"),errorCount:d.basic.length,sectionErrors:d.basic,children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(ts,{htmlFor:"agent-greeting",tooltip:"The initial message shown to users when they start a conversation",children:"Greeting Message"}),(0,a.jsx)(eq.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)(sr,{value:s.llm,onChange:e=>{r({...s,llm:e})},errors:i,open:o.llm,onOpenChange:()=>m("llm"),errorCount:d.llm.length,sectionErrors:d.llm}),(0,a.jsx)(sn,{value:l,onChange:e=>{r({...s,systemPrompt:e})},errors:i,open:o.systemPrompt,onOpenChange:()=>m("systemPrompt"),errorCount:d.systemPrompt.length,sectionErrors:d.systemPrompt}),(0,a.jsx)(sN,{value:s.mcpServers||{},onChange:e=>{r({...s,mcpServers:e})},errors:i,open:o.mcpServers,onOpenChange:()=>m("mcpServers"),errorCount:d.mcpServers.length,sectionErrors:d.mcpServers}),(0,a.jsx)(sR,{value:s.storage||{cache:{type:"in-memory"},database:{type:"in-memory"}},onChange:e=>{r({...s,storage:e})},errors:i,open:o.storage,onOpenChange:()=>m("storage"),errorCount:d.storage.length,sectionErrors:d.storage}),(0,a.jsx)(sU,{value:s.toolConfirmation||{},onChange:e=>{r({...s,toolConfirmation:e})},errors:i,open:o.toolConfirmation,onOpenChange:()=>m("toolConfirmation"),errorCount:d.toolConfirmation.length,sectionErrors:d.toolConfirmation})]})]})}function sq(e){let{config:t,onChange:s,errors:r={}}=e;return(0,a.jsx)("div",{className:"flex flex-col h-full",children:(0,a.jsx)(sB,{config:t,onChange:s,errors:r})})}sc.Ik({mode:sc.k5(sP).default(s_).describe("Tool confirmation mode: event-based (interactive), auto-approve (all tools), auto-deny (no tools)"),timeout:sc.ai().int().positive().default(12e4).describe("Timeout for tool confirmation requests in milliseconds, defaults to 120000ms (2 mins)"),allowedToolsStorage:sc.k5(sD).default(sM).describe("Storage type for remembered tool approvals: memory (session-only) or storage (persistent)"),toolPolicies:sz.optional().describe("Static tool policies for fine-grained allow/deny control. Deny list takes precedence over allow list.")}).strict().describe("Tool confirmation and approval configuration");var s$=s(3253);let sW="".concat((0,i.e)(),"/api");function sK(e){let{isOpen:t,onClose:s,variant:r="overlay"}=e,[i,l]=(0,n.useState)(""),[o,d]=(0,n.useState)(""),[m,x]=(0,n.useState)(null),[h,f]=(0,n.useState)(null),[g,v]=(0,n.useState)(null),[j,k]=(0,n.useState)(""),[C,S]=(0,n.useState)("yaml"),[A,E]=(0,n.useState)(null),[I,T]=(0,n.useState)(!1),[O,L]=(0,n.useState)(!1),[R,F]=(0,n.useState)(null),[P,D]=(0,n.useState)(null),[_,z]=(0,n.useState)(!1),[U,B]=(0,n.useState)(""),[q,$]=(0,n.useState)(!1),[W,K]=(0,n.useState)(!0),[V,Y]=(0,n.useState)([]),[J,G]=(0,n.useState)([]),[H,Z]=(0,n.useState)(!1),[Q,X]=(0,n.useState)(!1),ee=(0,n.useRef)(null),et=(0,n.useRef)(0),es=(0,n.useCallback)(async()=>{T(!0),F(null);try{let e=await fetch("".concat(sW,"/agent/config"));if(!e.ok){let t=await e.json().catch(()=>({error:"Failed to load configuration"}));throw Error(t.message||t.error||"Load failed: ".concat(e.statusText))}let t=await e.json();l(t.yaml),d(t.yaml),k(t.relativePath),Z(!1);let{config:s,document:r}=ea(t.yaml);s&&r&&(x(s),f(s),v(r)),await er(t.yaml)}catch(t){let e=t instanceof Error?t.message:String(t);F(e),console.error("Error loading agent config: ".concat(e))}finally{T(!1)}},[]),er=async e=>{let t=et.current+1;et.current=t,$(!0);try{let s=await fetch("".concat(sW,"/agent/validate"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e})}),r=await s.json();et.current===t&&(K(r.valid),Y(r.errors||[]),G(r.warnings||[]))}catch(e){console.error("Validation error: ".concat(e instanceof Error?e.message:String(e))),et.current===t&&(K(!1),Y([{message:"Failed to validate configuration",code:"VALIDATION_ERROR"}]))}finally{et.current===t&&$(!1)}},ea=e=>{console.log("[parseYamlToConfig] Starting parse");try{let t=s$.Tp(e);if(console.log("[parseYamlToConfig] Document created:",t),t.errors&&t.errors.length>0){console.error("[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.error("[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:",C),e===C)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(i);if(console.log("[handleModeSwitch] Parse result:",{config:e,document:t,error:s}),s){console.error("[handleModeSwitch] Parse error, not switching:",s),E(s);return}console.log("[handleModeSwitch] Parse successful, setting state"),x(e),v(t),E(null)}console.log("[handleModeSwitch] Setting editor mode to:",e),S(e)},ei=async()=>{if(!W||V.length>0)return void D("Cannot save: configuration has errors");L(!0),D(null),z(!1),B("");try{let e=await fetch("".concat(sW,"/agent/config"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:i})});if(!e.ok){let t=await e.json().catch(()=>({error:"Failed to save configuration"}));throw Error(t.message||t.error||"Save failed: ".concat(e.statusText))}let t=await e.json();d(i),Z(!1),z(!0),t.restarted?B("Configuration applied successfully — ".concat(t.changesApplied.join(", ")," updated")):B("Configuration saved successfully (no changes detected)"),setTimeout(()=>{z(!1),B("")},5e3)}catch(t){let e=t instanceof Error?t.message:String(t);D(e),console.error("Error saving agent config: ".concat(e))}finally{L(!1)}},el=()=>{H?X(!0):s()};if((0,n.useEffect)(()=>{t&&es()},[t,es]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),!O&&W&&ei()),"Escape"===e.key&&(e.preventDefault(),el())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,O,W,H]),!t)return null;let eo=(()=>{if(O)return null;if(!H)return"No changes to save";if(V.length>0){let e=V[0];return e.path?"Configuration error in ".concat(e.path,": ").concat(e.message):"Configuration error: ".concat(e.message)}return W?null:"Configuration has validation errors"})(),ec=!H||O||!W||V.length>0,ed=(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)(tR.A,{className:"h-3 w-3"})]})]}),j&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:j})]})}),(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)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"yaml"===C?"default":"ghost",size:"sm",onClick:()=>en("yaml"),className:"h-7 px-3",children:"YAML Editor"})}),(0,a.jsx)(N,{children:"Edit configuration in raw YAML format with full control"})]}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"form"===C?"default":"ghost",size:"sm",onClick:()=>en("form"),className:"h-7 px-3",children:"Form Editor"})}),(0,a.jsx)(N,{children:"Edit configuration using user-friendly forms"})]})]}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>{H?X(!0):es()},disabled:I,children:(0,a.jsx)(tP.A,{className:(0,c.cn)("h-4 w-4",I&&"animate-spin")})})}),(0,a.jsx)(N,{children:"Reload configuration"})]}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:el,children:(0,a.jsx)(p.A,{className:"h-4 w-4"})})}),(0,a.jsx)(N,{children:"Close (Esc)"})]})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:R?(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)(u.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:R}),(0,a.jsxs)(w.$,{onClick:es,variant:"outline",children:[(0,a.jsx)(tP.A,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):I?(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..."})]})}):A&&"form"===C?(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)(u.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:A}),(0,a.jsx)(w.$,{onClick:()=>S("yaml"),variant:"outline",children:"Switch to YAML Editor"})]})}):"yaml"===C?(0,a.jsx)(t6,{value:i,onChange:e=>{l(e),Z(e!==o),D(null),z(!1);let{config:t,document:s}=ea(e);t&&s&&(x(t),v(s)),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{er(e)},500)},isValidating:q,isValid:W,errors:V,warnings:J,hasUnsavedChanges:H}):m?(0,a.jsx)(sq,{config:m,onChange:e=>{if(console.log("[handleFormChange] Called with new config"),console.log("[handleFormChange] yamlDocument exists?",!!g),!g)return void console.error("[handleFormChange] No document available - this should not happen!");x(e);let t=((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||""===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,g);l(t),Z(!(e===h||e&&h&&JSON.stringify(e)===JSON.stringify(h))),D(null),z(!1),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{er(t)},500)},errors:V.reduce((e,t)=>(t.path&&(e[t.path]=t.message),e),{})}):null}),!R&&!I&&(0,a.jsxs)("div",{className:"flex flex-col border-t border-border",children:[(_||P)&&(0,a.jsxs)("div",{className:"px-4 py-3 bg-muted/50 border-b border-border",children:[_&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-500",children:[(0,a.jsx)(M.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:U})]}),P&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[(0,a.jsx)(u.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:P})]})]}),(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)(w.$,{variant:"outline",size:"sm",onClick:el,children:"Close"}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)("div",{children:(0,a.jsx)(w.$,{variant:"default",size:"sm",onClick:ei,disabled:ec,children:O?(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)(t5.A,{className:"h-4 w-4 mr-2"}),"Save"]})})})}),(0,a.jsx)(N,{children:eo||"Save configuration (⌘S)"})]})]})]})]}),(0,a.jsx)(eU.lG,{open:Q,onOpenChange:X,children:(0,a.jsxs)(eU.Cf,{children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsx)(eU.L3,{children:"Unsaved Changes"}),(0,a.jsx)(eU.rr,{children:"You have unsaved changes. Do you want to discard them?"})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>X(!1),children:"Cancel"}),(0,a.jsx)(w.$,{variant:"destructive",onClick:()=>{X(!1),l(o),Z(!1),es()},children:"Discard Changes"})]})]})})]});return"inline"===r?ed:(0,a.jsx)("div",{className:(0,c.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:ed})}var sV=s(1740),sY=s(4119),sJ=s(4619),sG=s(9040),sH=s(1601),sZ=s(9339),sQ=s(6529),sX=s(4454);function s0(){let{theme:e,toggleTheme:t}=function(){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}}(),[s,r]=(0,n.useState)(!1);(0,n.useEffect)(()=>{r(!0)},[]);let i="dark"===e;return s?(0,a.jsx)(j,{children:(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(ew.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)(ew.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)(sQ.A,{className:"w-3.5 h-3.5 text-gray-700"}):(0,a.jsx)(sX.A,{className:"w-3.5 h-3.5 text-yellow-500"})})})}),(0,a.jsx)(N,{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 s1=s(5195);function s2(e){let{active:t=!1}=e,{voices:s,selected:r,setSelected:i}=function(){let[e,t]=(0,n.useState)(T.getVoices()),[s,r]=(0,n.useState)(T.getPreferredVoiceName());return(0,n.useEffect)(()=>{let e=T.subscribeVoices(()=>{t(T.getVoices()),r(T.getPreferredVoiceName())});return()=>e()},[]),{voices:e,selected:s,setSelected:e=>{T.setPreferredVoice(e),r(T.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)(s1.l6,{value:null!=r?r:"auto",onValueChange:e=>{i("auto"===e?null:e)},children:[(0,a.jsx)(s1.bq,{className:"h-8 w-[12rem] text-xs",children:(0,a.jsx)(s1.yv,{placeholder:"Voice"})}),(0,a.jsxs)(s1.gC,{children:[(0,a.jsx)(s1.eb,{value:"auto",children:"Auto (best available)"}),l&&s.map(e=>(0,a.jsxs)(s1.eb,{value:e.name,children:[e.name," (",e.lang,")"]},"".concat(e.name,"-").concat(e.lang)))]})]}):null}function s5(e){let{isOpen:t,onClose:s}=e;return(0,a.jsx)(eU.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-lg",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsx)(eU.L3,{children:"Settings"}),(0,a.jsx)(eU.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)(e$.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)(s2,{active:t})]})})]})})}var s4=s(798),s3=s(420);let s8={id:"",name:"",description:"",author:"",tags:""},s6={llm:{provider:"openai",model:"gpt-5",apiKey:""},systemPrompt:{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:""}]}};function s7(e){let{open:t,onOpenChange:s,onAgentCreated:r}=e,[l,o]=(0,n.useState)(s8),[c,d]=(0,n.useState)(s6),[m,u]=(0,n.useState)({}),[x,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(null),[g,v]=(0,n.useState)({basic:!0,llm:!0,systemPrompt:!0}),j=e=>{v(t=>({...t,[e]:!t[e]}))},b=(e,t)=>{o(s=>({...s,[e]:t})),m[e]&&u(t=>{let s={...t};return delete s[e],s})},y=async()=>{if((()=>{var e,t,s;let r={};l.id.trim()?/^[a-z0-9-]+$/.test(l.id)||(r.id="Agent ID must contain only lowercase letters, numbers, and hyphens"):r.id="Agent ID is required",l.name.trim()||(r.name="Agent name is required"),l.description.trim()||(r.description="Description is required"),(null==(e=c.llm)?void 0:e.provider)||(r["llm.provider"]="Provider is required"),(null==(s=c.llm)||null==(t=s.model)?void 0:t.trim())||(r["llm.model"]="Model is required");let a=c.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 u(r),0===Object.keys(r).length})()){h(!0),f(null);try{var e,t,a,n,m;let x="";if(c.systemPrompt&&"object"==typeof c.systemPrompt&&"contributors"in c.systemPrompt){let e=c.systemPrompt.contributors;if(Array.isArray(e)){let t=e.find(e=>"static"===e.type&&e.content);t&&"content"in t&&"string"==typeof t.content&&(x=t.content.trim())}}else"string"==typeof c.systemPrompt&&(x=c.systemPrompt.trim());x||(x="You are a helpful AI assistant.");let h=await fetch("".concat((0,i.e)(),"/api/agents/custom/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id.trim(),name:l.name.trim(),description:l.description.trim(),author:l.author.trim()||void 0,tags:l.tags.split(",").map(e=>e.trim()).filter(Boolean),llm:{provider:null==(e=c.llm)?void 0:e.provider,model:null==(a=c.llm)||null==(t=a.model)?void 0:t.trim(),...(null==(m=c.llm)||null==(n=m.apiKey)?void 0:n.trim())&&{apiKey:c.llm.apiKey.trim()}},systemPrompt:x})});if(!h.ok){let e=await h.json().catch(()=>({error:"Failed to create agent"}));throw Error(e.message||e.error||"Creation failed: ".concat(h.statusText))}let p=await h.json();o(s8),d(s6),u({}),s(!1),r&&p.id&&r(p.id)}catch(e){f(e instanceof Error?e.message:"An unexpected error occurred")}finally{h(!1)}}};return(0,a.jsx)(eU.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eU.Cf,{className:"max-w-2xl max-h-[90vh] flex flex-col",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsx)(eU.L3,{children:"Create New Agent"}),(0,a.jsxs)(eU.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."]})]}),p&&(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)(ti.A,{className:"h-4 w-4 text-destructive mt-0.5 flex-shrink-0"}),(0,a.jsx)("div",{className:"text-sm text-destructive",children:p})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4 pr-2",children:[(0,a.jsx)(t7,{title:"Basic Information",open:g.basic,onOpenChange:()=>j("basic"),children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"agent-id",tooltip:"Unique identifier for this agent (lowercase, no spaces, hyphens only)",children:"Agent ID *"}),(0,a.jsx)(eq.p,{id:"agent-id",value:l.id,onChange:e=>b("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)(ts,{htmlFor:"agent-name",tooltip:"Display name for this agent (shown in UI)",children:"Agent Name *"}),(0,a.jsx)(eq.p,{id:"agent-name",value:l.name,onChange:e=>b("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)(ts,{htmlFor:"agent-description",tooltip:"Brief description of what this agent does",children:"Description *"}),(0,a.jsx)(eq.p,{id:"agent-description",value:l.description,onChange:e=>b("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)(ts,{htmlFor:"agent-author",tooltip:"Your name or organization",children:"Author"}),(0,a.jsx)(eq.p,{id:"agent-author",value:l.author,onChange:e=>b("author",e.target.value),placeholder:"Your Name"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(ts,{htmlFor:"agent-tags",tooltip:"Comma-separated tags for categorization",children:"Tags"}),(0,a.jsx)(eq.p,{id:"agent-tags",value:l.tags,onChange:e=>b("tags",e.target.value),placeholder:"coding, custom, specialized"})]})]})}),(0,a.jsx)(sr,{value:c.llm||{provider:"openai",model:"gpt-5",apiKey:""},onChange:e=>d(t=>({...t,llm:e})),errors:m,open:g.llm,onOpenChange:()=>j("llm"),errorCount:0,sectionErrors:[]}),(0,a.jsx)(sn,{value:"object"==typeof c.systemPrompt&&"contributors"in c.systemPrompt?{contributors:c.systemPrompt.contributors||[]}:{contributors:[]},onChange:e=>d(t=>({...t,systemPrompt:e})),errors:m,open:g.systemPrompt,onOpenChange:()=>j("systemPrompt"),errorCount:0,sectionErrors:[]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>{o(s8),d(s6),u({}),f(null),s(!1)},disabled:x,children:"Cancel"}),(0,a.jsxs)(w.$,{onClick:y,disabled:x,children:[x&&(0,a.jsx)(z.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Agent"]})]})]})})}let s9="dexto:recentAgents";function re(e){let{mode:t="default"}=e,s=(0,l.useRouter)(),{returnToWelcome:r,currentLLM:c,currentSessionId:d}=(0,o.v)(),m=(0,tr.st)(),u=(0,n.useRef)(m),[x,p]=(0,n.useState)([]),[g,v]=(0,n.useState)([]),[j,b]=(0,n.useState)(null),[y,N]=(0,n.useState)(null),[k,C]=(0,n.useState)([]),[S,A]=(0,n.useState)(!1),[E,I]=(0,n.useState)(!1),[T,O]=(0,n.useState)(!1),[L,R]=(0,n.useState)(!1);(0,n.useEffect)(()=>{u.current=m},[m]);let F=(0,n.useCallback)(()=>{try{let e=localStorage.getItem(s9);if(!e)return[];return JSON.parse(e).sort((e,t)=>t.lastUsed-e.lastUsed).slice(0,5)}catch(e){return console.error("Failed to load recent agents:",e),localStorage.removeItem(s9),[]}},[]),P=(0,n.useCallback)(e=>{try{let t=F().filter(t=>t.path!==e.path),s=[{...e,lastUsed:Date.now()},...t].slice(0,5);localStorage.setItem(s9,JSON.stringify(s)),C(s)}catch(e){console.error("Failed to save recent agent:",e)}},[F]),D=(0,n.useCallback)(async()=>{try{let e=await fetch("".concat((0,i.e)(),"/api/agents"));if(!e.ok)throw Error("Failed to fetch agents");let t=await e.json();p(t.installed||[]),v(t.available||[]),b(t.current.id);try{let e=await fetch("".concat((0,i.e)(),"/api/agent/path"));if(e.ok){let t=await e.json();N(t),t.path&&t.name&&P({id:t.name,name:t.name,path:t.path})}}catch(e){console.error("Failed to fetch agent path:",e)}return t}catch(e){return console.error("AgentSelector load error: ".concat(e)),null}},[P]);(0,n.useEffect)(()=>{A(!0),C(F()),D().finally(()=>A(!1))},[D,F]);let _=(0,n.useCallback)(async e=>{try{I(!0);let t=x.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."));let a=await fetch("".concat((0,i.e)(),"/api/agents/switch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!a.ok){let e=await a.json().catch(()=>({}));throw console.error("Agent switch failed: ".concat(JSON.stringify(e))),Error(e.error||e.message||"Switch failed: ".concat(a.status," ").concat(a.statusText))}b(e),O(!1),await D(),u.current.trackAgentSwitched({fromAgentId:j,toAgentId:e,toAgentName:t.name,sessionId:d||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:t.name}}))}catch(e){}r(),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{I(!1)}},[r,x,D,s,j,d]),M=(0,n.useCallback)(async e=>{try{I(!0);let t=await fetch("".concat((0,i.e)(),"/api/agents/switch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,path:e.path})});if(!t.ok){let e=await t.json().catch(()=>({}));throw console.error("Agent switch failed: ".concat(JSON.stringify(e))),Error(e.error||e.message||"Switch failed: ".concat(t.status," ").concat(t.statusText))}b(e.id),O(!1),await D(),P(e),u.current.trackAgentSwitched({fromAgentId:j,toAgentId:e.id,toAgentName:e.name,sessionId:d||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e.id,name:e.name}}))}catch(e){}r(),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{I(!1)}},[r,P,D,s,j,d]),z=(0,n.useCallback)(async e=>{try{I(!0);let t=await fetch("".concat((0,i.e)(),"/api/agents/install"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||"Install failed: ".concat(t.status))}let s=await D();if(!s)throw Error("Failed to reload agents list after installation");let a=s.installed.find(t=>t.id===e);if(!a)throw console.error("Agent not found in fresh installed list: ".concat(e)),Error("Agent '".concat(e,"' not found after installation. Please refresh."));let n=await fetch("".concat((0,i.e)(),"/api/agents/switch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!n.ok){let e=await n.json().catch(()=>({}));throw console.error("Agent switch failed: ".concat(JSON.stringify(e))),Error(e.error||e.message||"Switch failed: ".concat(n.status," ").concat(n.statusText))}b(e),O(!1),u.current.trackAgentSwitched({fromAgentId:j,toAgentId:e,toAgentName:a.name,sessionId:d||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:a.name}}))}catch(e){}r()}catch(t){console.error("Install agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to install agent";alert("Failed to install agent: ".concat(e))}finally{I(!1)}},[D,r,j,d]),U=(0,n.useCallback)(async(e,t)=>{if(t.stopPropagation(),confirm('Are you sure you want to delete the custom agent "'.concat(e.name,'"?')))try{I(!0);let t=await fetch("".concat((0,i.e)(),"/api/agents/uninstall"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||"Delete failed: ".concat(t.status))}let s=await D();(null==s?void 0:s.current.id)===e.id&&b(null)}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{I(!1)}},[j,D]),B=(0,n.useCallback)(async e=>{await new Promise(e=>setTimeout(e,1e3)),await D()},[D]),q=(0,n.useMemo)(()=>{var e;if(!j)return"Choose Agent";let t=x.find(e=>e.id===j)||g.find(e=>e.id===j);return null!=(e=null==t?void 0:t.name)?e:j},[g,j,x]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(eT,{open:T,onOpenChange:O,children:[(0,a.jsx)(eO,{asChild:!0,children:(0,a.jsx)(w.$,{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:E,children:(0,a.jsxs)("div",{className:"flex items-center justify-between w-full min-w-0",children:[(0,a.jsx)(eQ.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:E?"Switching...":"title"===t?"Agent: ".concat(q):q}),(0,a.jsx)(h.A,{className:"w-4 h-4 ml-2 flex-shrink-0"})]})})}),(0,a.jsxs)(eL,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[S&&(0,a.jsx)(eR,{disabled:!0,className:"text-center text-muted-foreground",children:"Loading agents..."}),!S&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eR,{onClick:()=>{R(!0),O(!1)},disabled:E,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)(eY.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"})]})}),y&&!x.some(e=>e.id===y.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)(eR,{onClick:()=>M({id:y.name,name:y.name,path:y.path}),disabled:E||j===y.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:y.name}),j===y.name&&(0,a.jsx)(f.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)(eF,{})]}),k.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"}),k.filter(e=>!x.some(t=>t.id===e.id)&&e.id!==(null==y?void 0:y.name)&&!e.path.includes("/.dexto/")).slice(0,3).map(e=>(0,a.jsx)(eR,{onClick:()=>M(e),disabled:E||e.id===j,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===j&&(0,a.jsx)(f.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)(eF,{})]}),x.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)(s4.A,{className:"w-3 h-3"}),"Custom Agents"]}),x.filter(e=>"custom"===e.type).map(e=>(0,a.jsx)(eR,{onClick:()=>_(e.id),disabled:E||e.id===j,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===j&&(0,a.jsx)(f.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=>U(e,t),disabled:E,className:"p-1 hover:bg-red-100 dark:hover:bg-red-900/30 rounded transition-colors",title:"Delete custom agent",children:(0,a.jsx)(tp.A,{className:"w-4 h-4 text-red-600 dark:text-red-400"})})]})},e.id))]}),x.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[x.filter(e=>"custom"===e.type).length>0&&(0,a.jsx)(eF,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Installed"}),x.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eR,{onClick:()=>_(e.id),disabled:E||e.id===j,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===j&&(0,a.jsx)(f.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))]}),g.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[x.length>0&&(0,a.jsx)(eF,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Available"}),g.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eR,{onClick:()=>z(e.id),disabled:E,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)(s3.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))]}),!S&&0===x.length&&0===g.length&&(0,a.jsx)(eR,{disabled:!0,className:"text-center text-muted-foreground",children:"No agents found"})]})]})]}),(0,a.jsx)(s7,{open:L,onOpenChange:R,onAgentCreated:B})]})}function rt(){let{sessionId:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,l.useRouter)(),[s,r]=(0,n.useState)(!1),{messages:d,sendMessage:m,currentSessionId:x,switchSession:p,isWelcomeState:g,returnToWelcome:v,websocket:j,activeError:k,clearError:C,processing:S,cancel:A,greeting:E,isStreaming:I,setStreaming:T}=(0,o.v)(),[O,L]=(0,n.useState)(!1),[R,F]=(0,n.useState)(!1),[_,M]=(0,n.useState)(!1),[z,U]=(0,n.useState)(!1),[B,q]=(0,n.useState)(!1),$=n.useRef(!0),[W,K]=(0,n.useState)(!1),[V,Y]=(0,n.useState)(!1),[J,G]=(0,n.useState)(!1),[H,Z]=(0,n.useState)(!1),[Q,X]=(0,n.useState)(!1),[ee,et]=(0,n.useState)("dexto-config"),[es,er]=(0,n.useState)(null),[ea,en]=(0,n.useState)(""),[ei,el]=(0,n.useState)(!1),[eo,ec]=(0,n.useState)(null),[ed,em]=(0,n.useState)(!1),[eu,ex]=(0,n.useState)(!1),[eh,ef]=(0,n.useState)(!1),[eg,ev]=(0,n.useState)(null),[ej,eb]=(0,n.useState)(!1),[ey,ew]=(0,n.useState)(!1),[eC,eS]=(0,n.useState)(null),[eA,eE]=(0,n.useState)(null),[eI,eP]=(0,n.useState)([]),[eD,e_]=(0,n.useState)(!1),[eM,ez]=(0,n.useState)(0);(0,n.useEffect)(()=>{let e=()=>{(0,td.w)(),ez(e=>e+1)};return window.addEventListener("dexto:agentSwitched",e),()=>{window.removeEventListener("dexto:agentSwitched",e)}},[]),(0,n.useEffect)(()=>{if(!g)return;let e=!1;return e_(!1),(0,td.y)().then(t=>{e||(eP(t.filter(e=>"starter"===e.source)),e_(!0))}).catch(()=>{e||e_(!0)}),()=>{e=!0}},[g,eM]);let eW=n.useRef(null),eK=n.useRef(null),[eV,eY]=(0,n.useState)(!0),[eJ,eG]=(0,n.useState)(!1),[eQ,eX]=(0,n.useState)(!1),e0=n.useRef(0),[e1,e2]=(0,n.useState)(!1),e5=n.useRef(null),[e4,e3]=(0,n.useState)(0),[e8,e6]=(0,n.useState)(null),[e7,e9]=(0,n.useState)(!1);(0,n.useEffect)(()=>{var e;"undefined"!=typeof navigator&&/Mac|iPod|iPhone|iPad/.test(navigator.platform)&&r(!0);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 te=(0,n.useCallback)(()=>{let e=eW.current;e&&eY(e.scrollHeight-e.scrollTop<=e.clientHeight+1)},[]),tt=(0,n.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auto",t=eW.current;t&&(eG(!0),t.scrollTo({top:t.scrollHeight,behavior:e}),requestAnimationFrame(()=>eG(!1)))},[]);(0,n.useEffect)(()=>{let e=eW.current;if(!e)return;let t=()=>{let t=e0.current,s=e.scrollTop;!eJ&&eQ&&s<t&&eX(!1),e0.current=s,te(),e.scrollHeight-e.scrollTop<=e.clientHeight+1?(e2(!1),e5.current&&(window.clearTimeout(e5.current),e5.current=null)):(e2(!1),e5.current&&window.clearTimeout(e5.current),e5.current=window.setTimeout(()=>{e2(!0)},180))};return e.addEventListener("scroll",t),te(),()=>e.removeEventListener("scroll",t)},[te,eQ,eJ,g]),(0,n.useEffect)(()=>{let e=eK.current;if(!e)return;let t=new ResizeObserver(()=>{!eJ&&(eQ||eV)&&tt("auto")});return t.observe(e),()=>t.disconnect()},[eV,eJ,eQ,tt,g]),(0,n.useEffect)(()=>{eQ&&tt("auto")},[eQ,d,tt]);let ts=(0,n.useCallback)(()=>{let e=eW.current;if(!e)return;let t=e.querySelectorAll('[data-role="user"]'),s=t[t.length-1];if(!s)return void tt("auto");let r=e.getBoundingClientRect(),a=Math.max(s.getBoundingClientRect().top-r.top+e.scrollTop-16,0);eG(!0),e.scrollTo({top:a,behavior:"auto"}),requestAnimationFrame(()=>eG(!1))},[tt]);(0,n.useEffect)(()=>{V?fetch(x?"".concat((0,i.e)(),"/api/agent/config/export?sessionId=").concat(x):"".concat((0,i.e)(),"/api/agent/config/export")).then(e=>{if(!e.ok)throw Error("Failed to fetch configuration");return e.text()}).then(e=>{en(e),er(null)}).catch(e=>{console.error("Preview fetch failed:",e),er(e instanceof Error?e.message:"Preview fetch failed")}):(en(""),er(null),el(!1))},[V,x]);let tr=(0,n.useCallback)(async()=>{try{let e=x?"".concat((0,i.e)(),"/api/agent/config/export?sessionId=").concat(x):"".concat((0,i.e)(),"/api/agent/config/export"),t=await fetch(e);if(!t.ok)throw Error("Failed to fetch configuration");let s=await t.text(),r=new Blob([s],{type:"application/x-yaml"}),a=URL.createObjectURL(r),n=document.createElement("a");n.href=a,n.download=x?"".concat(ee,"-").concat(x,".yml"):"".concat(ee,".yml"),document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(a)}catch(e){console.error("Download failed:",e),er(e instanceof Error?e.message:"Download failed")}},[ee,x]),ta=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(ea),el(!0),setTimeout(()=>el(!1),2e3)}catch(e){console.error("Copy failed:",e),er("Failed to copy to clipboard")}},[ea]),tn=(0,n.useCallback)(async(e,t,s)=>{ex(!0),ev(null);try{await m(e,t,s),setTimeout(()=>{ts(),eX(!0)},0)}catch(e){console.error("Failed to send message:",e),ev(e instanceof Error?e.message:"Failed to send message"),setTimeout(()=>ev(null),5e3)}finally{ex(!1)}},[m,ts]);(0,n.useEffect)(()=>{let e=()=>eX(!0),t=()=>eX(!1);return window.addEventListener("dexto:message",e),window.addEventListener("dexto:response",t),()=>{window.removeEventListener("dexto:message",e),window.removeEventListener("dexto:response",t)}},[]);let ti=(0,n.useCallback)(e=>{eX(!1),e2(!1),t.push("/chat/".concat(e))},[t]),tl=(0,n.useCallback)(()=>{eX(!1),e2(!1),v(),t.push("/")},[t,v]);(0,n.useEffect)(()=>{q(!0),"true"===localStorage.getItem("sessionsPanelOpen")&&U(!0),setTimeout(()=>{$.current=!1},0)},[]),(0,n.useEffect)(()=>{B&&localStorage.setItem("sessionsPanelOpen",z.toString())},[z,B]),(0,n.useEffect)(()=>{e&&e!==x&&(eX(!1),e2(!1),p(e))},[e,x,p]),(0,n.useEffect)(()=>{e||g||v()},[e,g,v]);let to=(0,n.useCallback)(async e=>{let t=t$(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tq(t.env||{}),r=("sse"===t.type||"http"===t.type)&&"headers"in t&&Object.keys(t.headers||{}).length>0&&tq(t.headers||{});if(s||r){var a;return e6({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:null!=(a=e.onCloseRegistryModal)?a:()=>F(!1)}),L(!0),"requires-input"}try{e9(!0);let s=await fetch("".concat((0,i.e)(),"/api/mcp/servers"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,config:t,persistToAgent:!1})}),r=await s.json();if(!s.ok)throw Error(r.error||"Server returned status ".concat(s.status));if(e.id)try{await tw.setInstalled(e.id,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}return e3(e=>e+1),ec("Added ".concat(e.name)),setTimeout(()=>ec(null),4e3),F(!1),"connected"}catch(e){throw Error(e instanceof Error?e.message:"Failed to install server")}finally{e9(!1)}},[F,L,e6,e3,ec,e9]),tc=(0,n.useCallback)(()=>{window.innerWidth<768&&_&&M(!1),U(!z)},[z,_]),tm=(0,n.useCallback)(()=>{window.innerWidth<768&&z&&U(!1),M(!_)},[_,z]),tu=(0,n.useCallback)(async()=>{if(x){ew(!0);try{if(!(await fetch("".concat((0,i.e)(),"/api/sessions/").concat(x),{method:"DELETE"})).ok)throw Error("Failed to delete conversation");eb(!1),tl()}catch(e){console.error("Failed to delete conversation:",e),ev(e instanceof Error?e.message:"Failed to delete conversation"),setTimeout(()=>ev(null),5e3)}finally{ew(!1)}}},[x,tl]),th=n.useMemo(()=>[{title:"Help me get started",description:"Show me what you can do",action:()=>tn("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:()=>tn("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:()=>M(!0),icon:"\uD83D\uDD27"},{title:"Demonstrate tools",description:"Show me your capabilities",action:()=>tn("Pick one of your most interesting tools and demonstrate it with a practical example. Show me what it can do."),icon:"⚡"}],[tn,M]),tf=n.useMemo(()=>{if(!eD)return th.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));let e=eI.length>0?[]:th.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));return eI.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:()=>M(!0)}):e.push({description:s,tooltip:r,action:async()=>{try{let e=new URL("".concat((0,i.e)(),"/api/prompts/").concat(encodeURIComponent(t.name),"/resolve")),s=await fetch(e.toString());if(s.ok){let e=await s.json(),r="string"==typeof(null==e?void 0:e.text)?e.text:"";r.trim()?tn(r.trim()):tn("/".concat(t.name))}else tn("/".concat(t.name))}catch(e){console.error("Failed to resolve starter prompt ".concat(t.name,":"),e),tn("/".concat(t.name))}}})}),e},[eI,eD,th,tn,M]);return(0,n.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"Backspace"===e.key&&x&&!g&&(e.preventDefault(),d.length>0?eb(!0):tu()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"h"===e.key&&(e.preventDefault(),tc()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"k"===e.key&&(e.preventDefault(),tl()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"j"===e.key&&(e.preventDefault(),tm()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"m"===e.key&&(e.preventDefault(),X(e=>!e)),(e.ctrlKey||e.metaKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),e.stopPropagation(),K(!0)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"l"===e.key&&(e.preventDefault(),window.open("/playground","_blank")),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"e"===e.key&&(e.preventDefault(),Z(e=>!e)),(e.ctrlKey||e.metaKey)&&e.shiftKey&&"e"===e.key&&(e.preventDefault(),Y(!0)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"/"===e.key&&(e.preventDefault(),ef(!0)),"Escape"===e.key&&(H?Z(!1):_?M(!1):z?U(!1):Q?X(!1):R?F(!1):V?Y(!1):eh?ef(!1):ej?eb(!1):eg?ev(null):S&&A(x||void 0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[H,_,z,Q,W,R,V,eh,ej,eg,K,tc,tm,tl,tu,S,A,x]),(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,c.cn)("hidden md:block shrink-0 border-r border-border/50 bg-card/50 backdrop-blur-sm",!$.current&&"transition-all duration-300 ease-in-out",z?"w-80":"w-0 overflow-hidden"),suppressHydrationWarning:!0,children:z&&(0,a.jsx)(tG,{isOpen:z,onClose:()=>U(!1),currentSessionId:x,onSessionChange:ti,returnToWelcome:tl,variant:"inline",onSearchOpen:()=>K(!0),onNewChat:tl})}),(0,a.jsx)("div",{className:"md:hidden",children:(0,a.jsx)(tG,{isOpen:z,onClose:()=>U(!1),currentSessionId:x,onSessionChange:ti,returnToWelcome:tl,variant:"overlay",onSearchOpen:()=>K(!0),onNewChat:tl})}),(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)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:tc,className:(0,c.cn)("h-8 w-8 p-0 transition-colors",z&&"bg-muted"),children:(0,a.jsx)(sV.A,{className:"h-4 w-4"})})}),(0,a.jsx)(N,{children:"Chat History (⌘H)"})]}),!z&&(0,a.jsx)("div",{className:"hidden md:block",children:(0,a.jsx)(tJ,{onClick:tl})}),(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)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>Z(!H),className:(0,c.cn)("h-8 w-8 p-0",H&&"bg-muted"),"aria-label":"Customize agent",children:(0,a.jsx)(sY.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{children:"Customize Agent (⌘E)"})]}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:tm,className:(0,c.cn)("h-8 w-8 p-0 transition-colors",_&&"bg-muted"),"aria-label":"Toggle tools panel",children:(0,a.jsx)(P.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{children:"Toggle tools panel (⌘J)"})]}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>X(!Q),className:(0,c.cn)("h-8 w-8 p-0 transition-colors",Q&&"bg-muted"),"aria-label":"Toggle memories panel",children:(0,a.jsx)(D.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{children:"Toggle memories panel (⌘M)"})]}),(0,a.jsx)(s0,{}),(0,a.jsxs)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",onClick:()=>G(!0),className:"h-8 w-8 p-0","aria-label":"Open settings",children:(0,a.jsx)(t0.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(N,{children:"Settings"})]}),(0,a.jsxs)(eT,{children:[(0,a.jsx)(eO,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:(0,a.jsx)(sJ.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsxs)(eL,{align:"end",children:[(0,a.jsxs)(eR,{onClick:()=>F(!0),children:[(0,a.jsx)(tE.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,a.jsxs)(eR,{onClick:()=>window.open("/playground","_blank"),children:[(0,a.jsx)(eZ.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,a.jsxs)(eR,{onClick:()=>Y(!0),children:[(0,a.jsx)(sG.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,a.jsxs)(eR,{onClick:()=>ef(!0),children:[(0,a.jsx)(sH.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),x&&!g&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eF,{}),(0,a.jsxs)(eR,{onClick:()=>eb(!0),className:"text-destructive focus:text-destructive",children:[(0,a.jsx)(tp.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})]}),(0,a.jsx)("div",{className:"flex md:hidden",children:(0,a.jsxs)(eT,{open:ed,onOpenChange:em,children:[(0,a.jsx)(eO,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Open menu",children:(0,a.jsx)(sZ.A,{className:"h-4 w-4"})})}),(0,a.jsxs)(eL,{align:"end",children:[(0,a.jsxs)(eR,{onClick:()=>{Z(!H),em(!1)},children:[(0,a.jsx)(sY.A,{className:"h-4 w-4 mr-2"}),"Customize Agent"]}),(0,a.jsxs)(eR,{onClick:()=>{tm(),em(!1)},children:[(0,a.jsx)(P.A,{className:"h-4 w-4 mr-2"}),"Tools"]}),(0,a.jsxs)(eR,{onClick:()=>{X(!Q),em(!1)},children:[(0,a.jsx)(D.A,{className:"h-4 w-4 mr-2"}),"Memories"]}),(0,a.jsxs)(eR,{onClick:()=>{let e=document.documentElement.classList.contains("dark")?"light":"dark";document.documentElement.classList.toggle("dark","dark"===e),localStorage.setItem("theme",e),document.cookie="theme=".concat(e,"; Path=/; Max-Age=31536000; SameSite=Lax"),em(!1)},children:[(0,a.jsx)("span",{className:"h-4 w-4 mr-2",children:"\uD83C\uDF19"}),"Toggle Theme"]}),(0,a.jsxs)(eR,{onClick:()=>{G(!0),em(!1)},children:[(0,a.jsx)(t0.A,{className:"h-4 w-4 mr-2"}),"Settings"]}),(0,a.jsxs)(eR,{onClick:e=>{e.preventDefault(),T(!I)},className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(eN.A,{className:"h-4 w-4 mr-2"}),"Streaming"]}),(0,a.jsx)(ek,{checked:I,onCheckedChange:T,onClick:e=>e.stopPropagation()})]}),(0,a.jsx)(eF,{}),(0,a.jsxs)(eR,{onClick:()=>{F(!0),em(!1)},children:[(0,a.jsx)(tE.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,a.jsxs)(eR,{onClick:()=>{window.open("/playground","_blank"),em(!1)},children:[(0,a.jsx)(eZ.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,a.jsxs)(eR,{onClick:()=>{Y(!0),em(!1)},children:[(0,a.jsx)(sG.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,a.jsxs)(eR,{onClick:()=>{ef(!0),em(!1)},children:[(0,a.jsx)(sH.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),x&&!g&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eF,{}),(0,a.jsxs)(eR,{onClick:()=>{eb(!0),em(!1)},className:"text-destructive focus:text-destructive",children:[(0,a.jsx)(tp.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)(re,{mode:"badge"})})})]}),(0,a.jsxs)("div",{className:"flex-1 flex overflow-hidden min-w-0",children:[eo&&(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)(f.A,{className:"h-4 w-4 text-green-600"}),(0,a.jsx)("span",{className:"text-sm",children:eo})]}),eg&&(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:eg}),(0,a.jsx)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:g?(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:E||"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:tf.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)(b,{children:[(0,a.jsx)(y,{asChild:!0,children:s}),(0,a.jsx)(N,{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)(tj,{onSend:tn,isSending:eu,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:s?"⌘⌫":"Ctrl+⌫"})," 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:eW,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)(ep,{messages:d,processing:S,activeError:k,onDismissError:C,outerRef:eK,pendingApproval:eC,onApprovalApprove:null==eA?void 0:eA.onApprove,onApprovalDeny:null==eA?void 0:eA.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:[e1&&(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:()=>{e2(!1),tt("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)(h.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)(tj,{onSend:tn,isSending:eu,variant:"chat"})})]})]})})})}),(0,a.jsx)("div",{className:(0,c.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-80":"w-0 overflow-hidden"),children:_&&(0,a.jsx)(tK,{isOpen:_,onClose:()=>M(!1),onOpenConnectModal:()=>L(!0),onOpenConnectWithPrefill:e=>{e6(e),L(!0)},onServerConnected:e=>{e3(e=>e+1),ec("Added ".concat(e)),setTimeout(()=>ec(null),4e3)},variant:"inline",refreshTrigger:e4})}),(0,a.jsx)("div",{className:"md:hidden",children:(0,a.jsx)(tK,{isOpen:_,onClose:()=>M(!1),onOpenConnectModal:()=>L(!0),onOpenConnectWithPrefill:e=>{e6(e),L(!0)},onServerConnected:e=>{e3(e=>e+1),ec("Added ".concat(e)),setTimeout(()=>ec(null),4e3)},variant:"overlay",refreshTrigger:e4})})]}),(0,a.jsx)(sK,{isOpen:H,onClose:()=>Z(!1),variant:"overlay"}),(0,a.jsx)(tb.A,{isOpen:O,onClose:()=>{L(!1),e9(!1),e6(null)},onServerConnected:async()=>{var e;if(null==e8?void 0:e8.registryEntryId)try{await tw.setInstalled(e8.registryEntryId,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}e3(e=>e+1);let t=(null==e8?void 0:e8.name)||"Server";ec("Added ".concat(t)),setTimeout(()=>ec(null),4e3),null==e8||null==(e=e8.onCloseRegistryModal)||e.call(e8),e9(!1),e6(null)},initialName:null==e8?void 0:e8.name,initialConfig:null==e8?void 0:e8.config,lockName:null==e8?void 0:e8.lockName}),(0,a.jsx)(tF,{isOpen:R,onClose:()=>F(!1),onInstallServer:to,onOpenConnectModal:()=>L(!0),refreshTrigger:e4,disableClose:e7}),(0,a.jsx)(eU.lG,{open:V,onOpenChange:Y,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-2xl",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsxs)(eU.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(sG.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{children:"Export Configuration"})]}),(0,a.jsxs)(eU.rr,{children:["Download your tool configuration for Claude Desktop or other MCP clients",x&&(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:x})]})]})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e$.J,{htmlFor:"filename",children:"File name"}),(0,a.jsx)(eq.p,{id:"filename",value:ee,onChange:e=>et(e.target.value),placeholder:"dexto-config",className:"font-mono"})]}),es&&(0,a.jsxs)(eB.Fc,{variant:"destructive",children:[(0,a.jsx)(u.A,{className:"h-4 w-4"}),(0,a.jsx)(eB.XL,{children:"Export Error"}),(0,a.jsx)(eB.TN,{children:es})]}),ea&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e$.J,{children:"Configuration Preview"}),(0,a.jsx)(tx.T,{value:ea,readOnly:!0,className:"h-32 font-mono text-xs bg-muted/30"})]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:ta,className:"flex items-center space-x-2",children:(0,a.jsx)("span",{children:ei?"Copied!":"Copy"})}),(0,a.jsxs)(w.$,{onClick:tr,className:"flex items-center space-x-2",children:[(0,a.jsx)(sG.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Download"})]})]})]})}),(0,a.jsx)(s5,{isOpen:J,onClose:()=>G(!1)}),(0,a.jsx)(tQ,{isOpen:Q,onClose:()=>X(!1),variant:"modal"}),(0,a.jsx)(eU.lG,{open:ej,onOpenChange:eb,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eU.c7,{children:[(0,a.jsxs)(eU.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eU.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",x&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,a.jsx)("span",{className:"font-mono",children:x})]})]})]}),(0,a.jsxs)(eU.Es,{children:[(0,a.jsx)(w.$,{variant:"outline",onClick:()=>eb(!1),children:"Cancel"}),(0,a.jsxs)(w.$,{variant:"destructive",onClick:tu,disabled:ey,className:"flex items-center space-x-2",children:[(0,a.jsx)(tp.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:ey?"Deleting...":"Delete Conversation"})]})]})]})}),(0,a.jsx)(eU.lG,{open:eh,onOpenChange:ef,children:(0,a.jsxs)(eU.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eU.c7,{children:(0,a.jsxs)(eU.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(sH.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:s?"⌘⌫":"Ctrl+⌫",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)(eH.E,{variant:"outline",className:"font-mono text-xs",children:e.key})]},t))}),(0,a.jsx)(eU.Es,{children:(0,a.jsx)(eU.HM,{asChild:!0,children:(0,a.jsx)(w.$,{variant:"outline",children:"Close"})})})]})})]}),(0,a.jsx)(t2,{isOpen:W,onClose:()=>K(!1),onNavigateToSession:(e,s)=>{t.push("/chat/".concat(e)),K(!1)}}),(0,a.jsx)(tX,{websocket:j,onApprovalRequest:eS,onHandlersReady:eE})]})}},9419:(e,t,s)=>{Promise.resolve().then(s.bind(s,5034))}}]);
|