dexto 1.2.1 → 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.
Files changed (72) hide show
  1. package/dist/analytics/index.d.ts.map +1 -1
  2. package/dist/analytics/index.js +1 -2
  3. package/dist/webui/.next/standalone/{packages/webui/.next/static/chunks/656-5a9f6405badf66a8.js → .next/static/chunks/369-7a58b346e80ec351.js} +2 -2
  4. package/dist/webui/.next/standalone/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
  5. package/dist/webui/.next/standalone/.next/static/chunks/560-551d60414365cdc4.js +1 -0
  6. package/dist/webui/.next/standalone/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
  7. package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
  8. package/dist/webui/.next/standalone/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
  9. package/dist/webui/.next/standalone/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
  10. package/dist/webui/.next/standalone/package.json +3 -2
  11. package/dist/webui/.next/standalone/packages/webui/.next/BUILD_ID +1 -1
  12. package/dist/webui/.next/standalone/packages/webui/.next/app-build-manifest.json +13 -10
  13. package/dist/webui/.next/standalone/packages/webui/.next/build-manifest.json +2 -2
  14. package/dist/webui/.next/standalone/packages/webui/.next/prerender-manifest.json +3 -3
  15. package/dist/webui/.next/standalone/packages/webui/.next/required-server-files.json +1 -1
  16. package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page.js +2 -2
  17. package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page.js.nft.json +1 -1
  18. package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  19. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js +2 -2
  20. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js.nft.json +1 -1
  21. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page_client-reference-manifest.js +1 -1
  22. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js +2 -2
  23. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js.nft.json +1 -1
  24. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page_client-reference-manifest.js +1 -1
  25. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js +3 -3
  26. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js.nft.json +1 -1
  27. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page_client-reference-manifest.js +1 -1
  28. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/1.js +4 -4
  29. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/695.js +1 -0
  30. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/{426.js → 710.js} +2 -2
  31. package/dist/webui/.next/standalone/packages/webui/.next/server/pages/500.html +1 -1
  32. package/dist/webui/.next/standalone/packages/webui/.next/server/server-reference-manifest.json +1 -1
  33. package/dist/webui/.next/{static/chunks/656-5a9f6405badf66a8.js → standalone/packages/webui/.next/static/chunks/369-7a58b346e80ec351.js} +2 -2
  34. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
  35. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/560-551d60414365cdc4.js +1 -0
  36. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
  37. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
  38. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
  39. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
  40. package/dist/webui/.next/standalone/packages/webui/package.json +3 -1
  41. package/dist/webui/.next/standalone/packages/webui/server.js +1 -1
  42. package/dist/webui/.next/{standalone/.next/static/chunks/656-5a9f6405badf66a8.js → static/chunks/369-7a58b346e80ec351.js} +2 -2
  43. package/dist/webui/.next/static/chunks/419-6d7f485f58886e5b.js +1 -0
  44. package/dist/webui/.next/static/chunks/560-551d60414365cdc4.js +1 -0
  45. package/dist/webui/.next/static/chunks/854-7ae94d6609222f8e.js +1 -0
  46. package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-df2b9ed4c466c348.js +1 -0
  47. package/dist/webui/.next/static/chunks/app/layout-f4d136d139162fab.js +1 -0
  48. package/dist/webui/.next/static/chunks/app/page-d0ab5e22f0d14271.js +1 -0
  49. package/dist/webui/package.json +3 -1
  50. package/package.json +3 -3
  51. package/dist/webui/.next/standalone/.next/static/chunks/419-a07413b585273a24.js +0 -1
  52. package/dist/webui/.next/standalone/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
  53. package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
  54. package/dist/webui/.next/standalone/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
  55. package/dist/webui/.next/standalone/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
  56. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/43.js +0 -1
  57. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-a07413b585273a24.js +0 -1
  58. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
  59. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
  60. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
  61. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
  62. package/dist/webui/.next/static/chunks/419-a07413b585273a24.js +0 -1
  63. package/dist/webui/.next/static/chunks/854-232126f3c77e6c0b.js +0 -1
  64. package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +0 -1
  65. package/dist/webui/.next/static/chunks/app/layout-f4a6ee5a028899d1.js +0 -1
  66. package/dist/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +0 -1
  67. /package/dist/webui/.next/standalone/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
  68. /package/dist/webui/.next/standalone/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
  69. /package/dist/webui/.next/standalone/packages/webui/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
  70. /package/dist/webui/.next/standalone/packages/webui/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
  71. /package/dist/webui/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_buildManifest.js +0 -0
  72. /package/dist/webui/.next/static/{b_pyEEg2sitTwMzZWW7vE → IXh4cVyOAx6rg0D8ivJp6}/_ssgManifest.js +0 -0
@@ -1,12 +1,12 @@
1
- exports.id=1,exports.ids=[1],exports.modules={49977:(a,b,c)=>{"use strict";c.d(b,{default:()=>c3});var d=c(35270),e=c(4039),f=c.n(e),g=c(33671),h=c(76112),i=c(64516),j=c(34306),k=c(70702),l=c(77836),m=c(45019),n=c(20675),o=c(55994),p=c(41810),q=c(8822),r=c(37545),s=c(84994);function t({delayDuration:a=0,...b}){return(0,d.jsx)(s.Kq,{"data-slot":"tooltip-provider",delayDuration:a,...b})}function u({...a}){return(0,d.jsx)(t,{children:(0,d.jsx)(s.bL,{"data-slot":"tooltip",...a})})}function v({...a}){return(0,d.jsx)(s.l9,{"data-slot":"tooltip-trigger",...a})}function w({className:a,sideOffset:b=0,children:c,...e}){return(0,d.jsx)(s.ZL,{children:(0,d.jsxs)(s.UC,{"data-slot":"tooltip-content",sideOffset:b,className:(0,j.cn)("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...e,children:[c,(0,d.jsx)(s.i3,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}var x=c(4409);let y=(0,e.forwardRef)(({children:a,tooltip:b,side:c="bottom",className:e,...f},g)=>(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"icon",...f,className:(0,j.cn)("size-6 p-1",e),ref:g,children:[a,(0,d.jsx)("span",{className:"sr-only",children:b})]})}),(0,d.jsx)(w,{side:c,children:b})]}));function z({value:a,tooltip:b="Copy",copiedTooltip:c="Copied!",className:f,size:g=12}){let[h,i]=(0,e.useState)(!1);return(0,d.jsx)(y,{tooltip:h?c:b,onClick:()=>{navigator.clipboard.writeText(a).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},className:f,children:h?(0,d.jsx)(q.A,{size:g}):(0,d.jsx)(r.A,{size:g})})}y.displayName="TooltipIconButton";var A=c(18755),B=c(73093);class C{get supported(){return!1}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 a=window.localStorage.getItem("ttsVoiceName");this.preferredVoiceName=a&&a.length?a:null}catch{}let a=()=>{try{let a=window.speechSynthesis.getVoices()||[];(a.length!==this.voices.length||a.some((a,b)=>a.name!==this.voices[b]?.name))&&(this.voices=a,this.voiceSubscribers.forEach(a=>a()))}catch{}};a();try{window.speechSynthesis.addEventListener("voiceschanged",a)}catch{}}}isSpeaking(){return this._speaking}subscribe(a){return this.subscribers.add(a),()=>{this.subscribers.delete(a)}}subscribeVoices(a){return this.voiceSubscribers.add(a),()=>{this.voiceSubscribers.delete(a)}}notify(){for(let a of this.subscribers)try{a()}catch{}}stop(){if(this.supported){try{window.speechSynthesis.cancel()}catch{}this.utterance=null,this._speaking&&(this._speaking=!1,this.notify())}}speak(a,b){if(!this.supported||!a||!a.trim())return;this.stop();let c=new window.SpeechSynthesisUtterance(a);b?.rate!=null&&(c.rate=b.rate),b?.pitch!=null&&(c.pitch=b.pitch);let d=this.resolveVoice();if(d)try{c.voice=d,b?.lang?c.lang=b.lang:d.lang&&(c.lang=d.lang)}catch{}else b?.lang&&(c.lang=b.lang);c.onstart=()=>{this.utterance===c&&(this._speaking=!0,this.notify())};let e=()=>{this.utterance===c&&(this._speaking=!1,this.utterance=null,this.notify())};c.onend=e,c.onerror=e;try{this.utterance=c,window.speechSynthesis.speak(c),this._speaking||(this._speaking=!0,this.notify())}catch{e()}}getVoices(){return this.voices}setPreferredVoice(a){this.preferredVoiceName=a&&a.length?a:null;try{this.preferredVoiceName?window.localStorage.setItem("ttsVoiceName",this.preferredVoiceName):window.localStorage.removeItem("ttsVoiceName")}catch{}this.voiceSubscribers.forEach(a=>a())}getPreferredVoiceName(){return this.preferredVoiceName}resolveVoice(){if(!this.voices.length)return null;let a=this.preferredVoiceName?this.voices.find(a=>a.name===this.preferredVoiceName):null;if(a)return a;let b=this.voices.find(a=>"google uk english female"===a.name.toLowerCase()||a.name.toLowerCase().includes("google uk english female")&&a.lang?.toLowerCase().startsWith("en-gb"));if(b)return b;let c=a=>{let b=a.name.toLowerCase(),c=(a.lang??"").toLowerCase(),d=0;return("en"===c||c.startsWith("en-"))&&(d+=3),b.includes("google")&&(d+=5),(b.includes("microsoft")||b.includes("azure"))&&(d+=4),(b.includes("natural")||b.includes("neural")||b.includes("premium"))&&(d+=4),b.includes("siri")&&(d+=3),b.includes("female")&&(d+=1),d};return[...this.voices].sort((a,b)=>c(b)-c(a))[0]||this.voices[0]||null}}let D=globalThis,E=D.__speechController??(D.__speechController=new C);function F({value:a,tooltip:b="Speak",stopTooltip:c="Stop",className:f,rate:g=1,pitch:h=1,lang:i}){let[j,k]=(0,e.useState)(!1),l=E.supported,m=(a??"").trim().length>0;return(0,d.jsx)(y,{tooltip:j?c:b,onClick:()=>{if(l&&m){if(j)return E.stop();E.speak(a,{rate:g,pitch:h,lang:i})}},className:f,disabled:!l||!m,children:j?(0,d.jsx)(A.A,{size:12}):(0,d.jsx)(B.A,{size:12})})}function G({error:a,onDismiss:b}){let[c,f]=(0,e.useState)(!1),g=a.detailedIssues?.[0],h=g?.context&&"object"==typeof g.context&&"detailedIssues"in g.context?g.context.detailedIssues:[],i=h.length>0?`${a.message}
1
+ exports.id=1,exports.ids=[1],exports.modules={49977:(a,b,c)=>{"use strict";c.d(b,{default:()=>c4});var d=c(35270),e=c(4039),f=c.n(e),g=c(33671),h=c(76112),i=c(64516),j=c(34306),k=c(70702),l=c(77836),m=c(45019),n=c(20675),o=c(55994),p=c(41810),q=c(8822),r=c(37545),s=c(84994);function t({delayDuration:a=0,...b}){return(0,d.jsx)(s.Kq,{"data-slot":"tooltip-provider",delayDuration:a,...b})}function u({...a}){return(0,d.jsx)(t,{children:(0,d.jsx)(s.bL,{"data-slot":"tooltip",...a})})}function v({...a}){return(0,d.jsx)(s.l9,{"data-slot":"tooltip-trigger",...a})}function w({className:a,sideOffset:b=0,children:c,...e}){return(0,d.jsx)(s.ZL,{children:(0,d.jsxs)(s.UC,{"data-slot":"tooltip-content",sideOffset:b,className:(0,j.cn)("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...e,children:[c,(0,d.jsx)(s.i3,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}var x=c(4409);let y=(0,e.forwardRef)(({children:a,tooltip:b,side:c="bottom",className:e,...f},g)=>(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"icon",...f,className:(0,j.cn)("size-6 p-1",e),ref:g,children:[a,(0,d.jsx)("span",{className:"sr-only",children:b})]})}),(0,d.jsx)(w,{side:c,children:b})]}));function z({value:a,tooltip:b="Copy",copiedTooltip:c="Copied!",className:f,size:g=12}){let[h,i]=(0,e.useState)(!1);return(0,d.jsx)(y,{tooltip:h?c:b,onClick:()=>{navigator.clipboard.writeText(a).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},className:f,children:h?(0,d.jsx)(q.A,{size:g}):(0,d.jsx)(r.A,{size:g})})}y.displayName="TooltipIconButton";var A=c(18755),B=c(73093);class C{get supported(){return!1}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 a=window.localStorage.getItem("ttsVoiceName");this.preferredVoiceName=a&&a.length?a:null}catch{}let a=()=>{try{let a=window.speechSynthesis.getVoices()||[];(a.length!==this.voices.length||a.some((a,b)=>a.name!==this.voices[b]?.name))&&(this.voices=a,this.voiceSubscribers.forEach(a=>a()))}catch{}};a();try{window.speechSynthesis.addEventListener("voiceschanged",a)}catch{}}}isSpeaking(){return this._speaking}subscribe(a){return this.subscribers.add(a),()=>{this.subscribers.delete(a)}}subscribeVoices(a){return this.voiceSubscribers.add(a),()=>{this.voiceSubscribers.delete(a)}}notify(){for(let a of this.subscribers)try{a()}catch{}}stop(){if(this.supported){try{window.speechSynthesis.cancel()}catch{}this.utterance=null,this._speaking&&(this._speaking=!1,this.notify())}}speak(a,b){if(!this.supported||!a||!a.trim())return;this.stop();let c=new window.SpeechSynthesisUtterance(a);b?.rate!=null&&(c.rate=b.rate),b?.pitch!=null&&(c.pitch=b.pitch);let d=this.resolveVoice();if(d)try{c.voice=d,b?.lang?c.lang=b.lang:d.lang&&(c.lang=d.lang)}catch{}else b?.lang&&(c.lang=b.lang);c.onstart=()=>{this.utterance===c&&(this._speaking=!0,this.notify())};let e=()=>{this.utterance===c&&(this._speaking=!1,this.utterance=null,this.notify())};c.onend=e,c.onerror=e;try{this.utterance=c,window.speechSynthesis.speak(c),this._speaking||(this._speaking=!0,this.notify())}catch{e()}}getVoices(){return this.voices}setPreferredVoice(a){this.preferredVoiceName=a&&a.length?a:null;try{this.preferredVoiceName?window.localStorage.setItem("ttsVoiceName",this.preferredVoiceName):window.localStorage.removeItem("ttsVoiceName")}catch{}this.voiceSubscribers.forEach(a=>a())}getPreferredVoiceName(){return this.preferredVoiceName}resolveVoice(){if(!this.voices.length)return null;let a=this.preferredVoiceName?this.voices.find(a=>a.name===this.preferredVoiceName):null;if(a)return a;let b=this.voices.find(a=>"google uk english female"===a.name.toLowerCase()||a.name.toLowerCase().includes("google uk english female")&&a.lang?.toLowerCase().startsWith("en-gb"));if(b)return b;let c=a=>{let b=a.name.toLowerCase(),c=(a.lang??"").toLowerCase(),d=0;return("en"===c||c.startsWith("en-"))&&(d+=3),b.includes("google")&&(d+=5),(b.includes("microsoft")||b.includes("azure"))&&(d+=4),(b.includes("natural")||b.includes("neural")||b.includes("premium"))&&(d+=4),b.includes("siri")&&(d+=3),b.includes("female")&&(d+=1),d};return[...this.voices].sort((a,b)=>c(b)-c(a))[0]||this.voices[0]||null}}let D=globalThis,E=D.__speechController??(D.__speechController=new C);function F({value:a,tooltip:b="Speak",stopTooltip:c="Stop",className:f,rate:g=1,pitch:h=1,lang:i}){let[j,k]=(0,e.useState)(!1),l=E.supported,m=(a??"").trim().length>0;return(0,d.jsx)(y,{tooltip:j?c:b,onClick:()=>{if(l&&m){if(j)return E.stop();E.speak(a,{rate:g,pitch:h,lang:i})}},className:f,disabled:!l||!m,children:j?(0,d.jsx)(A.A,{size:12}):(0,d.jsx)(B.A,{size:12})})}function G({error:a,onDismiss:b}){let[c,f]=(0,e.useState)(!1),g=a.detailedIssues?.[0],h=g?.context&&"object"==typeof g.context&&"detailedIssues"in g.context?g.context.detailedIssues:[],i=h.length>0?`${a.message}
2
2
 
3
3
  Details:
4
4
  ${h.map(a=>{let b=a.message;if(a.context){let c="string"==typeof a.context?a.context:JSON.stringify(a.context,null,2);b+=`
5
- Context: ${c}`}return b}).join("\n\n")}`:a.message;return(0,d.jsx)("div",{className:"w-full rounded-lg p-4 mb-4 border shadow-sm bg-destructive/10 border-destructive/40",children:(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)(m.A,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("h3",{className:"text-sm font-medium text-destructive",children:"Error"}),a.context&&(0,d.jsx)("span",{className:"text-xs bg-destructive/15 text-destructive px-2 py-0.5 rounded-full",children:a.context})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[h.length>0&&(0,d.jsx)("button",{onClick:()=>f(!c),className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:c?"Collapse":"Expand",children:c?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"})}),(0,d.jsx)(z,{value:i,tooltip:"Copy error",className:"p-1 hover:bg-destructive/15 rounded text-destructive",size:16}),(0,d.jsx)(F,{value:i,tooltip:"Read error",className:"p-1 hover:bg-destructive/15 rounded text-destructive"}),(0,d.jsx)("button",{onClick:b,className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:"Dismiss",children:(0,d.jsx)(p.A,{className:"h-4 w-4"})})]})]}),(0,d.jsx)("div",{className:"mt-2 text-sm text-destructive",children:a.message}),c&&h.length>0&&(0,d.jsx)("div",{className:"mt-3",children:(0,d.jsx)("div",{className:"text-xs text-destructive bg-destructive/10 p-3 rounded border border-destructive/30 overflow-auto max-h-60",children:h.map((a,b)=>(0,d.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,d.jsx)("div",{className:"font-medium",children:a.message}),null!=a.context&&(0,d.jsx)("div",{className:"text-destructive/70 mt-1",children:"string"==typeof a.context?a.context:JSON.stringify(a.context,null,2)})]},b))})})]})]})})}var H=c(92231),I=c(22759),J=c(82801),K=c(73002),L=c(49650),M=c(61346),N=c(62e3),O=c(857),P=c(64212),Q=c(16686),R=c(351),S=c(97831),T=c(24349),U=c(59336),V=c(89376),W=c(29951),X=c(71317);function Y(a,b){let c=b?`${b}/`:"[a-z0-9.+-]+/";return RegExp(`^data:${c}[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$`,"i").test(a)}function Z(a){try{let b=new URL(a),c=b.hostname.toLowerCase();if("https:"!==b.protocol&&"http:"!==b.protocol||"localhost"===c||"::1"===c)return!1;let d=c.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(d){let[,a,b,c,e]=d.map(Number);if(a>255||b>255||c>255||e>255||127===a||10===a||172===a&&b>=16&&b<=31||192===a&&168===b||169===a&&254===b||0===a&&0===b&&0===c&&0===e)return!1}if(c.includes(":")&&("::1"===c||"0:0:0:0:0:0:0:1"===c||c.startsWith("fc")||c.startsWith("fd")||c.startsWith("fe8")||c.startsWith("fe9")||c.startsWith("fea")||c.startsWith("feb")))return!1;return!0}catch{return!1}}function $(a,b){return!!(a.startsWith("blob:")||Z(a))||!!a.startsWith("data:")&&(b?Y(a,b):Y(a))}let _=(0,e.memo)(({children:a})=>{let b=f().useRef(new Set);return f().useEffect(()=>()=>{b.current.forEach(a=>{try{URL.revokeObjectURL(a)}catch{}})},[]),(0,d.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,d.jsx)(V.oz,{remarkPlugins:[W.A,X.A],skipHtml:!0,components:{a:({href:a,children:b,...c})=>{let e=a??"";return/^https?:\/\//i.test(e)&&Z(e)?(0,d.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"},...c,children:b}):(0,d.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",...c,children:b})},img:({src:a,alt:c,...e})=>{if(!a)return(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"No media source provided"});let f=null;if("string"==typeof a)f=a;else if(a instanceof Blob||a instanceof File)try{let c=URL.createObjectURL(a);f=c,b.current.add(c)}catch(a){f=null}else if("object"==typeof a&&null!==a&&a instanceof MediaSource)try{let c=URL.createObjectURL(a);f=c,b.current.add(c)}catch(a){f=null}else f=null;return f?function(a){return!!(a.match(/\.(mp4|webm|mov|m4v|avi|mkv)(\?.*)?$/i)||a.includes("/video/")||a.includes("video_"))}(f)&&$(f,"video")?(0,d.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,d.jsx)("video",{controls:!0,src:f,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."}),c&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:c})]}):function(a){return!!(a.match(/\.(mp3|wav|ogg|m4a|aac|flac|wma)(\?.*)?$/i)||a.includes("/audio/")||a.includes("audio_"))}(f)&&$(f,"audio")?(0,d.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,d.jsx)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-muted/30",children:(0,d.jsx)("audio",{controls:!0,src:f,className:"flex-1 min-w-0 h-10",children:"Your browser does not support the audio tag."})}),c&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:c})]}):$(f,"image")?(0,d.jsx)("img",{src:f,alt:c||"Image",className:"max-w-full max-h-[500px] object-contain rounded-lg border border-border my-4",loading:"lazy",...e}):(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"}):(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"})},p:({children:a,...b})=>"string"==typeof a?(0,d.jsx)("p",{...b,children:function(a){let b=/(https?:\/\/[^\s<]+)/g;return a.split(b).map((a,c)=>a.match(b)?Z(a)?(0,d.jsx)("a",{href:a,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:a,style:{wordBreak:"break-word",overflowWrap:"anywhere"},children:a},c):(0,d.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",title:"Unsafe URL",children:a},c):a)}(a)}):(0,d.jsx)("p",{...b,children:a}),table:({className:a,children:b,...c})=>(0,d.jsx)("div",{className:"my-4 overflow-x-auto -mx-1 px-1",children:(0,d.jsx)("table",{className:["w-full border-separate border-spacing-0",a].filter(Boolean).join(" "),...c,children:b})}),thead:({className:a,...b})=>(0,d.jsx)("thead",{className:a,...b}),tr:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),th:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),td:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),code:({className:a,children:b,...c})=>{let[f,g]=(0,e.useState)(!1),h=String(b??"").replace(/\n$/,"");return a?(0,d.jsxs)("div",{className:"relative group my-4 min-w-0 max-w-full",children:[(0,d.jsx)(y,{tooltip:f?"Copied!":"Copy code",onClick:()=>{navigator.clipboard.writeText(h).then(()=>{g(!0),setTimeout(()=>g(!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:f?(0,d.jsx)(q.A,{size:14}):(0,d.jsx)(r.A,{size:14})}),(0,d.jsx)("pre",{className:"overflow-auto bg-muted p-3 rounded-lg text-sm max-w-full",children:(0,d.jsx)("code",{className:a,children:h})})]}):(0,d.jsx)("code",{className:"text-xs px-1.5 py-0.5 bg-muted rounded font-mono break-all overflow-wrap-anywhere",...c,children:b})}},children:a})})});function aa(a){(0,e.useMemo)(()=>{let b=new Set,c=[];for(let d of a){if(!d||"string"!=typeof d)continue;let a=d.trim();!a||b.has(a)||(b.add(a),c.push(a))}return c},[a.join("|")]);let[b,c]=(0,e.useState)({});return(0,e.useRef)({}),(0,e.useRef)(new Set),b}let ab=null,ac=null,ad=null;async function ae(){let a=await fetch(`${(0,g.e)()}/api/resources`);if(!a.ok){let b=await a.text().catch(()=>"");throw Error(b?`HTTP ${a.status}: ${b}`:`HTTP ${a.status}`)}let b=await a.json();if(!b||!b.ok||!Array.isArray(b.resources))throw Error("Invalid response shape");return b.resources}async function af(a=!1){return(a&&(ab=null,ac=null),ab)?ab:(ad||(ad=ae().then(a=>(ab=a,ac=null,a)).catch(a=>{throw ac=a instanceof Error?a.message:String(a),a}).finally(()=>{ad=null})),ad)}function ag(){let[a,b]=(0,e.useState)(()=>ab??[]),[c,d]=(0,e.useState)(()=>null===ab),[f,g]=(0,e.useState)(()=>ac);return{resources:a,loading:c,error:f,refresh:(0,e.useCallback)(async()=>{d(!0);try{let a=await af(!0);b(a),g(null)}catch(a){g(a instanceof Error?a.message:String(a))}finally{d(!1)}},[])}}var ah=c(47030);function ai(a){if(!a.metadata||"object"!=typeof a.metadata)return null;let b=a.metadata;return b.schema&&b.prompt&&b.serverName?b:null}function aj({approval:a,onApprove:b,onDeny:c}){let[f,g]=(0,e.useState)({}),[h,i]=(0,e.useState)({}),[j,k]=(0,e.useState)(!1),l="elicitation"===a.type,n=(a,b)=>{g(c=>({...c,[a]:b})),h[a]&&i(b=>{let c={...b};return delete c[a],c})};return(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:l?"Information Request":"Approval Required"})]}),l?(()=>{let b=ai(a);return b?(0,d.jsxs)("div",{className:"space-y-4 min-w-0",children:[(0,d.jsxs)("div",{className:"bg-muted/50 p-3 rounded-md border border-border min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium mb-1 break-words",children:b.prompt}),(0,d.jsxs)("p",{className:"text-xs text-muted-foreground break-words",children:["From: ",b.serverName||"Dexto Agent"]})]}),(0,d.jsx)("div",{children:(()=>{let a=b.schema;if(!a?.properties||"object"!=typeof a.properties)return(0,d.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid form schema"});let c=a.required||[],e=a.properties;return(0,d.jsx)("div",{className:"space-y-4",children:Object.entries(e).map(([a,b])=>{let e=c.includes(a),g=b.type||"string",i=f[a],j=!!h[a];return"boolean"===g?(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)(ah.S,{id:a,checked:!0===i,onCheckedChange:b=>n(a,!0===b)}),(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground ml-6",children:b.description})]},a):"number"===g||"integer"===g?(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsx)("input",{id:a,type:"number",step:"integer"===g?"1":"any",value:"number"==typeof i?i:"",onChange:b=>{let c=b.target.value;n(a,""===c?void 0:Number(c))},className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,placeholder:e?"Required":"Optional"}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a):b.enum&&Array.isArray(b.enum)?(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsxs)("select",{id:a,value:null!=i?String(i):"",onChange:c=>{let d=c.target.value;if(""===d)return void n(a,void 0);n(a,b.enum?.find(a=>String(a)===d)??d)},className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,children:[(0,d.jsx)("option",{value:"",children:"Select an option..."}),b.enum?.map(a=>(0,d.jsx)("option",{value:String(a),children:String(a)},String(a)))]}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a):(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsx)("input",{id:a,type:"text",value:null!=i&&"object"!=typeof i?String(i):"",onChange:b=>n(a,b.target.value),className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,placeholder:e?"Required":"Optional"}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a)})})})()})]}):(0,d.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid elicitation metadata"})})():"tool_confirmation"===a.type?(0,d.jsxs)("div",{className:"space-y-3 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,d.jsx)(J.A,{className:"h-4 w-4 flex-shrink-0"}),(0,d.jsxs)("span",{className:"font-medium text-sm break-words min-w-0",children:["Tool: ",a.toolName]})]}),a.description&&(0,d.jsx)("p",{className:"text-sm break-words",children:a.description}),(0,d.jsxs)("div",{className:"min-w-0",children:[(0,d.jsx)("span",{className:"font-medium text-sm block mb-2",children:"Arguments:"}),(0,d.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(a.args,null,2)})]}),(0,d.jsxs)("div",{className:"flex items-center space-x-2 pt-2",children:[(0,d.jsx)(ah.S,{id:"remember",checked:j,onCheckedChange:a=>k(!0===a)}),(0,d.jsx)("label",{htmlFor:"remember",className:"text-sm",children:"Remember this choice for this session"})]})]}):null,(0,d.jsxs)("div",{className:"flex gap-2 justify-end pt-3 border-t border-border",children:[(0,d.jsx)(x.$,{variant:"outline",onClick:c,size:"sm",children:l?"Decline":"Deny"}),(0,d.jsx)(x.$,{onClick:()=>{if(l){let c=ai(a);if(!c)return void console.error("Invalid elicitation metadata");let d=c.schema.required||[],e={};for(let a of d){let b=f[a],c="string"==typeof b&&""===b.trim();(null==b||c)&&(e[a]="This field is required")}if(Object.keys(e).length>0)return void i(e);b(f)}else b(void 0,j)},size:"sm",children:l?"Submit":"Approve"})]})]})}function ak(a,b){let c=b?`${b}/`:"[a-z0-9.+-]+/";return RegExp(`^data:${c}[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$`,"i").test(a)}function al(a,b){return!!(a.startsWith("blob:")||function(a){try{let b=new URL(a),c=b.hostname.toLowerCase();if("https:"!==b.protocol&&"http:"!==b.protocol||"localhost"===c||"::1"===c)return!1;let d=c.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(d){let[,a,b,c,e]=d.map(Number);if(a>255||b>255||c>255||e>255||127===a||10===a||172===a&&b>=16&&b<=31||192===a&&168===b||169===a&&254===b||0===a&&0===b&&0===c&&0===e)return!1}if(c.includes(":")&&("::1"===c||"0:0:0:0:0:0:0:1"===c||c.startsWith("fc")||c.startsWith("fd")||c.startsWith("fe8")||c.startsWith("fe9")||c.startsWith("fea")||c.startsWith("feb")))return!1;return!0}catch{return!1}}(a))||!!a.startsWith("data:")&&(b?ak(a,b):ak(a))}function am(a,b){if(!a)return"";let c=a?.mimeType,d="string"==typeof a?a:a?.data??a?.base64??a?.image??a?.audio??a?.video??a?.uri??a?.url;if("string"==typeof d){if(d.startsWith("@blob:")){let c=d.substring(1);if(b&&c){let d=b[c];if(d&&"loaded"===d.status&&d.data){let b=[];if(a?.type==="image"&&b.push("image"),a?.type==="file"){let c=(0,l.t)(a.mimeType);"audio"===c?b.push("audio"):"video"===c&&b.push("video")}a?.mimeType?.startsWith("image/")&&b.push("image"),a?.mimeType?.startsWith("audio/")&&b.push("audio"),a?.mimeType?.startsWith("video/")&&b.push("video");let c=d.data.items.find(a=>b.includes(a.kind))??d.data.items.find(a=>"image"===a.kind)??d.data.items.find(a=>"video"===a.kind)??d.data.items.find(a=>"audio"===a.kind)??d.data.items[0];if(c&&"src"in c&&"string"==typeof c.src)return c.src}}return""}if(d.startsWith("data:"))return d;if(c&&!(!d||d.length<16||d.startsWith("http://")||d.startsWith("https://")||d.startsWith("data:")||d.startsWith("@blob:"))&&/^[A-Za-z0-9+/=\r\n]+$/.test(d))return`data:${c};base64,${d}`;if(al(d))return d}let e=a?.url??a?.image??a?.audio??a?.video??a?.uri;return"string"==typeof e?e:""}function an(a,b){if(!a||"object"!=typeof a)return null;let c=a.mimeType||a.mediaType,d=a.filename||a.name,e="file"===a.type?(0,l.t)(a.mimeType):null;if(!(c?.startsWith("video/")||"video"===e||"video"===a.type||d?.match(/\.(mp4|webm|mov|m4v|avi|mkv)$/i)))return null;let f=am(a,b);return f&&al(f,"video")?{src:f,filename:d,mimeType:c}:null}function ao(){return(0,d.jsx)("div",{className:"flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground",role:"status","aria-live":"polite",children:(0,d.jsxs)("span",{className:"flex items-center gap-1 uppercase tracking-wide text-muted-foreground/80",children:[(0,d.jsx)("span",{children:"Thinking"}),(0,d.jsx)("span",{className:"flex items-center gap-0.5",children:[0,1,2].map(a=>(0,d.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:`${.18*a}s`}},a))})]})})}function ap({messages:a,processing:b=!1,activeError:c,onDismissError:g,outerRef:h,pendingApproval:i,onApprovalApprove:q,onApprovalDeny:r}){let s=(0,e.useRef)(null),[t,x]=(0,e.useState)({}),[y,A]=(0,e.useState)({}),[C,D]=(0,e.useState)(null);(0,e.useRef)(null);let[E,U]=(0,e.useState)({isOpen:!1,src:"",alt:""}),{resources:V}=ag(),W=(0,e.useMemo)(()=>{let a={};for(let b of V)a[b.uri]={...b};return a},[V]),X=aa((0,e.useMemo)(()=>{let b=new Set,c=a=>{if("string"!=typeof a)return;let c=a.startsWith("@")?a.substring(1):a;c.startsWith("blob:")&&b.add(c)},d=a=>{if(a){if("string"==typeof a)return void c(a);"object"==typeof a&&("string"==typeof a.image&&c(a.image),"string"==typeof a.data&&c(a.data),"string"==typeof a.url&&c(a.url),"string"==typeof a.audio&&c(a.audio),"string"==typeof a.video&&c(a.video))}};for(let c of a){let a=c.toolResult;a&&((0,k.P2)(a)?(a.resources?.forEach(a=>{a?.uri?.startsWith("blob:")&&b.add(a.uri)}),a.content?.forEach(a=>d(a))):a?.content&&Array.isArray(a.content)&&a.content.forEach(a=>d(a)))}return Array.from(b)},[a])),Y=(a,b)=>{U({isOpen:!0,src:a,alt:b})};if(!a||0===a.length)return null;let Z=a=>"string"==typeof a.content?a.content:Array.isArray(a.content)?a.content.map(a=>(0,k.PI)(a)?a.text:"").filter(Boolean).join("\n"):a.content&&"object"==typeof a.content?JSON.stringify(a.content,null,2):"",$=a=>a?(0,k.KU)(a)?"object"==typeof a.error?JSON.stringify(a.error,null,2):String(a.error):(0,k.P2)(a)?a.content.map(a=>(0,k.PI)(a)?a.text:"object"==typeof a?"":String(a)).filter(Boolean).join("\n"):"object"==typeof a?JSON.stringify(a,null,2):String(a):"";return(0,d.jsxs)("div",{id:"message-list-container",ref:h,className:"flex flex-col space-y-3 px-3 sm:px-4 py-2 min-w-0 w-full",children:[a.map((e,h)=>{let i=e.id??`msg-${h}`,p="user"===e.role,q="assistant"===e.role,r="system"===e.role,s=h===a.length-1,C=!!(e.toolName&&e.toolArgs),D=!!(e.toolName&&e.toolResult),E=C||D,U=E&&s||!!t[i],V=[],_=[],aa=[];D&&e.toolResult&&(0,k.P2)(e.toolResult)&&e.toolResult.content.forEach((a,b)=>{if((0,k.j0)(a)){let c=am(a,X);c&&al(c,"image")&&V.push({src:c,alt:`Tool result image ${b+1}`,index:b})}else if((0,k.kz)(a)){let c=am(a,X);c&&al(c,"audio")&&_.push({src:c,filename:a.filename,index:b})}else if((0,k.EQ)(a)&&("audio"===(0,l.t)(a.mimeType)||a.mimeType?.startsWith("audio/"))){let c=am(a,X);c&&al(c,"audio")&&_.push({src:c,filename:a.filename,index:b})}else{let c=an(a,X);c&&aa.push({...c,index:b})}});let ab=p?H.A:I.A,ac=(0,j.cn)(p?"grid w-full grid-cols-[1fr_auto] gap-x-2 items-start":"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start"),ad=(0,j.cn)("tool"===e.role?"w-fit max-w-[90%] text-muted-foreground/70 bg-secondary border border-muted/30 rounded-md text-base overflow-hidden":p?"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":q?"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":r?"p-3 shadow-none w-full bg-transparent text-xs text-muted-foreground italic text-center border-none":""),ae=new Date(e.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),af=!!(c&&c.anchorMessageId===e.id),ag=p&&s;return(0,d.jsxs)(f().Fragment,{children:[(0,d.jsxs)("div",{className:"w-full","data-role":e.role,id:e.id?`message-${e.id}`:void 0,children:[(0,d.jsxs)("div",{className:ac,children:[q&&(0,d.jsx)(ab,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1"}),"tool"===e.role&&(0,d.jsx)(J.A,{className:"h-7 w-7 p-1 mt-1 rounded-full border border-border text-muted-foreground col-start-1"}),(0,d.jsxs)("div",{className:(0,j.cn)("flex flex-col group w-full min-w-0",r?"col-span-2 items-center":p?"col-start-1 justify-self-end items-end":"col-start-2 justify-self-start items-start"),children:[(0,d.jsx)("div",{className:(0,j.cn)(ad,"min-w-0"),children:(0,d.jsxs)("div",{className:(0,j.cn)("flex flex-col gap-2","min-w-0"),children:[q&&"string"==typeof e.reasoning&&e.reasoning.trim().length>0&&(0,d.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,d.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,d.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:()=>A(a=>({...a,[i]:!(a[i]??!0)})),children:[(0,d.jsx)(K.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"AI Reasoning"}),y[i]??!0?(0,d.jsx)(n.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"}):(0,d.jsx)(o.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(z,{value:e.reasoning,tooltip:"Copy reasoning",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:e.reasoning,tooltip:"Speak reasoning",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(y[i]??!0)&&(0,d.jsx)("div",{className:"px-3 py-2",children:(0,d.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,d.jsxs)("div",{className:"p-2 rounded border border-border bg-muted/30 hover:bg-muted/60 cursor-pointer",onClick:()=>{E&&x(a=>({...a,[i]:!a[i]}))},children:[(0,d.jsxs)("div",{className:"flex items-center justify-between text-xs font-medium",children:[(0,d.jsxs)("span",{className:"flex items-center",children:[U?(0,d.jsx)(n.A,{className:"h-4 w-4 mr-2 text-primary"}):(0,d.jsx)(L.A,{className:"h-4 w-4 mr-2 text-primary"}),"Tool: ",e.toolName]}),e.toolResult?(0,k.KU)(e.toolResult)?(0,d.jsx)(m.A,{className:"mx-2 h-4 w-4 text-red-500"}):(0,d.jsx)(M.A,{className:"mx-2 h-4 w-4 text-green-500"}):(0,d.jsx)(N.A,{className:"mx-2 h-4 w-4 animate-spin text-muted-foreground"})]}),U&&(0,d.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{className:"text-xs font-medium",children:"Arguments:"}),(0,d.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,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"text-xs font-medium flex items-center justify-between",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)("span",{children:"Result:"}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(z,{value:$(e.toolResult),tooltip:"Copy result",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:$(e.toolResult),tooltip:"Speak result",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(0,k.KU)(e.toolResult)?(0,d.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,k.P2)(e.toolResult)?e.toolResult.content.map((a,b)=>{let c=an(a,X);if((0,k.j0)(a)||(0,k.kz)(a)||(0,k.EQ)(a)&&("audio"===(0,l.t)(a.mimeType)||a.mimeType?.startsWith("audio/"))||c)return null;if((0,k.PI)(a))return(0,d.jsx)(aq,{text:a.text,isUser:!1,onOpenImage:Y,resourceSet:W},`${i}-tool-text-${b}`);if((0,k.EQ)(a)){let c=(0,l.t)(a.mimeType),e="audio"===c||a.mimeType?.startsWith("audio/"),f="video"===c||a.mimeType?.startsWith("video/");return(0,d.jsxs)("div",{className:"my-1 flex items-center gap-2 p-2 rounded border border-border bg-muted/50",children:[e?(0,d.jsx)(O.A,{className:"h-4 w-4 text-muted-foreground"}):f?(0,d.jsx)(P.A,{className:"h-4 w-4 text-muted-foreground"}):(0,d.jsx)(Q.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a.filename||"File attachment"," (",a.mimeType,")"]})]},b)}return(0,d.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 a?JSON.stringify(a,null,2):String(a)},b)}):(0,d.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")?ak(e.toolResult,"image")?(0,d.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,d.jsxs)(d.Fragment,{children:["string"==typeof e.content&&""!==e.content.trim()&&(0,d.jsx)("div",{className:"relative",children:(0,d.jsx)(aq,{text:e.content,isUser:p,onOpenImage:Y,resourceSet:W},`${i}-text-content`)}),e.content&&"object"==typeof e.content&&!Array.isArray(e.content)&&(0,d.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((a,b)=>{let c=`${i}-part-${b}`;if("text"===a.type)return(0,d.jsx)(aq,{text:a.text,isUser:p,onOpenImage:Y,resourceSet:W},c);if((0,k.j0)(a)){let b=am(a);return b&&al(b,"image")?(0,d.jsx)("img",{src:b,alt:"Message attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain cursor-pointer",onClick:()=>Y(b,"Message attachment")},c):null}let e=an(a);if(e){let{src:a,filename:b,mimeType:f}=e;return(0,d.jsxs)("div",{className:"my-2 flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:(0,j.cn)("h-4 w-4",p?void 0:"text-muted-foreground")}),(0,d.jsx)("span",{children:"Video attachment"})]}),(0,d.jsx)("div",{className:"w-full max-w-md",children:(0,d.jsx)("video",{controls:!0,src:a,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"})}),(b||f)&&(0,d.jsxs)("div",{className:"flex flex-col text-xs",children:[b&&(0,d.jsx)("span",{className:(0,j.cn)("truncate",p?"text-primary-foreground/80":"text-muted-foreground"),children:b}),f&&(0,d.jsx)("span",{className:(0,j.cn)(p?"text-primary-foreground/70":"text-muted-foreground/80"),children:f})]})]},c)}if((0,k.EQ)(a)){if(!a.mimeType.startsWith("audio/"))return(0,d.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(Q.A,{className:(0,j.cn)("h-5 w-5",p?void 0:"text-muted-foreground")}),(0,d.jsx)("span",{className:(0,j.cn)("text-sm font-medium",void 0),children:a.filename||`${a.mimeType} file`}),(0,d.jsx)("span",{className:(0,j.cn)("text-xs",p?"text-primary-foreground/70":"text-muted-foreground"),children:a.mimeType})]},c);{let b=am(a);return(0,d.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(O.A,{className:(0,j.cn)("h-5 w-5",p?void 0:"text-muted-foreground")}),(0,d.jsx)("audio",{controls:!0,src:b,className:"flex-1 h-8"}),a.filename&&(0,d.jsx)("span",{className:(0,j.cn)("text-sm truncate max-w-[120px]",p?"text-primary-foreground/80":"text-muted-foreground"),children:a.filename})]},c)}}return null}),r&&!e.content&&(0,d.jsx)("p",{className:"italic",children:"System message"})]}),e.imageData&&!Array.isArray(e.content)&&(()=>{let a=`data:${e.imageData.mimeType};base64,${e.imageData.base64}`;return ak(a,"image")?(0,d.jsx)("img",{src:a,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,d.jsx)("div",{className:"mt-2",children:e.fileData.mimeType.startsWith("video/")?(0,d.jsxs)("div",{className:"flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50 max-w-md",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Video attachment"})]}),(()=>{let a=`data:${e.fileData.mimeType};base64,${e.fileData.base64}`;return ak(a,"video")?(0,d.jsx)("video",{controls:!0,src:a,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}):(0,d.jsx)("div",{className:"text-xs text-red-500",children:"Invalid video data"})})(),(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/90",children:[(0,d.jsx)("span",{className:"font-medium truncate",children:e.fileData.filename||`${e.fileData.mimeType} file`}),(0,d.jsx)("span",{className:"opacity-70",children:e.fileData.mimeType})]})]}):e.fileData.mimeType.startsWith("audio/")?(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(()=>{let a=`data:${e.fileData.mimeType};base64,${e.fileData.base64}`;return ak(a,"audio")?(0,d.jsx)("audio",{controls:!0,src:a,className:"h-8"}):(0,d.jsx)("span",{className:"text-xs text-red-500",children:"Invalid audio data"})})()]}):(0,d.jsxs)("div",{className:"flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(Q.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{className:"text-sm font-medium",children:e.fileData.filename||`${e.fileData.mimeType} file`}),(0,d.jsx)("span",{className:"text-xs text-primary-foreground/70",children:e.fileData.mimeType})]})})]})}),!r&&!E&&(0,d.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,d.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,d.jsx)("span",{children:ae}),q&&e.tokenUsage?.totalTokens!==void 0&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.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,d.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.tokenUsage.totalTokens," tokens"]})}),(0,d.jsx)(w,{side:"bottom",children:(0,d.jsxs)("div",{className:"flex flex-col gap-0.5",children:[void 0!==e.tokenUsage.inputTokens&&(0,d.jsxs)("div",{children:["Input: ",e.tokenUsage.inputTokens]}),void 0!==e.tokenUsage.outputTokens&&(0,d.jsxs)("div",{children:["Output: ",e.tokenUsage.outputTokens]}),void 0!==e.tokenUsage.reasoningTokens&&(0,d.jsxs)("div",{children:["Reasoning: ",e.tokenUsage.reasoningTokens]}),(0,d.jsxs)("div",{className:"font-medium mt-0.5",children:["Total: ",e.tokenUsage.totalTokens]})]})})]}),q&&e.model&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{children:(0,d.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,d.jsx)(w,{side:"bottom",children:(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("div",{className:"font-medium",children:["Model: ",e.model]}),e.provider&&(0,d.jsxs)("div",{className:"font-medium",children:["Provider: ",e.provider]}),e.router&&(0,d.jsxs)("div",{className:"font-medium",children:["Router: ",e.router]})]})})]})]}),(q||p)&&(0,d.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,d.jsx)(z,{value:Z(e),tooltip:"Copy message",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:Z(e),tooltip:"Speak",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]})]}),p&&(0,d.jsx)(ab,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-2"})]}),V.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(R.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(R.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Image"})]}),(0,d.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>Y(a.src,a.alt),children:[(0,d.jsx)("img",{src:a.src,alt:a.alt,className:"max-h-80 w-auto rounded border border-border object-contain transition-transform group-hover:scale-[1.02]"}),(0,d.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,d.jsx)(S.A,{className:"h-8 w-8 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow-lg"})})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-image-${b}`)),aa.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(T.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(T.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Video"})]}),(0,d.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0",children:[(0,d.jsx)("video",{controls:!0,src:a.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}),(a.filename||a.mimeType)&&(0,d.jsxs)("div",{className:"flex flex-col text-xs text-muted-foreground",children:[a.filename&&(0,d.jsx)("span",{className:"truncate",children:a.filename}),a.mimeType&&(0,d.jsx)("span",{className:"opacity-70",children:a.mimeType})]})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-video-${b}`)),_.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(B.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(B.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Audio"})]}),(0,d.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,d.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,d.jsx)(O.A,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,d.jsx)("audio",{controls:!0,src:a.src,className:"flex-1 min-w-0"})]}),a.filename&&(0,d.jsx)("div",{className:"flex items-center gap-2 min-w-0",children:(0,d.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:a.filename})})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-audio-${b}`)),af&&(0,d.jsx)("div",{className:"mt-2 ml-12 mr-4",children:(0,d.jsx)(G,{error:c,onDismiss:g||(()=>{})})})]}),b&&ag&&(0,d.jsx)(ao,{})]},i)}),i&&q&&r&&(0,d.jsx)("div",{className:"w-full","data-role":"approval",children:(0,d.jsxs)("div",{className:"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start",children:[(0,d.jsx)(I.A,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1 flex-shrink-0"}),(0,d.jsx)("div",{className:"flex flex-col group w-full col-start-2 justify-self-start items-start min-w-0",children:(0,d.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,d.jsx)(aj,{approval:i,onApprove:q,onDeny:r})})})]})}),(0,d.jsx)("div",{ref:s,className:"h-px"},"end-anchor"),E.isOpen&&(0,d.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm",children:(0,d.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh] bg-background rounded-lg shadow-2xl border border-border",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,d.jsx)("h3",{className:"text-lg font-semibold",children:"Tool Result Image"}),(0,d.jsx)("button",{onClick:()=>{U({isOpen:!1,src:"",alt:""})},className:"p-2 hover:bg-muted rounded-md transition-colors","aria-label":"Close modal",children:(0,d.jsx)(p.A,{className:"h-5 w-5"})})]}),(0,d.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,d.jsx)("img",{src:E.src,alt:E.alt,className:"max-w-full max-h-[70vh] object-contain rounded"})}),(0,d.jsx)("div",{className:"p-4 border-t border-border text-sm text-muted-foreground",children:(0,d.jsx)("p",{children:E.alt})})]})})]})}function aq({text:a,isUser:b,onOpenImage:c,resourceSet:f}){let{cleanedText:g,uris:h}=(0,e.useMemo)(()=>(function(a,b){if(!a)return{cleanedText:"",uris:[]};let c=function(a,b){let c=a.map(a=>({...a}));for(let a of c)switch(a.type){case"uri":if(b[a.identifier])a.resourceUri=a.identifier;else{let c=function(a,b){let c=b.trim().toLowerCase();for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a&&a.toLowerCase()===c)return b}for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a&&a.toLowerCase().includes(c))return b}}(b,a.identifier);c&&(a.resourceUri=c)}break;case"server-scoped":{let c=function(a,b,c){let d=c.trim().toLowerCase(),e=Object.entries(a).filter(([,a])=>a.serverName===b);for(let[a,b]of e){if(!b.name)continue;let c=b.name.trim().toLowerCase();if(c===d||c.includes(d))return a}for(let[a,b]of e){let c="string"==typeof b.metadata?.originalUri?b.metadata.originalUri:void 0;if(c?.toLowerCase().includes(d)||a.toLowerCase().includes(d))return a}}(b,a.serverName,a.identifier);c&&(a.resourceUri=c);break}case"name":{let c=function(a,b){let c=b.trim().toLowerCase();for(let[b,d]of Object.entries(a)){if(!d.name)continue;let a=d.name.trim().toLowerCase();if(a===c||a.includes(c))return b}for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a?.toLowerCase().includes(c)||b.toLowerCase().includes(c))return b}}(b,a.identifier);c&&(a.resourceUri=c)}}return c}(function(a){let b,c=[],d=/(?:^|(?<=\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])/g;for(;null!==(b=d.exec(a));){let[a,d,e,f,g]=b;d?c.push({originalRef:a,type:"uri",identifier:d.slice(1,-1)}):e&&f?c.push({originalRef:a,type:"server-scoped",serverName:e,identifier:f}):g&&c.push({originalRef:a,type:"name",identifier:g})}return c}(a),b),d=Array.from(new Set(c.filter(a=>a.resourceUri).map(a=>a.resourceUri))),e=a;for(let a of c)a.resourceUri&&(e=e.split(a.originalRef).join(""));return{cleanedText:e=(e=e.replace(/\\n/g,"\n").replace(/\\t/g," ")).replace(/\n{3,}/g,"\n\n").replace(/[ \t]{2,}/g," ").trim(),uris:d}})(a,f),[a,f]),i=aa(h),j=g.length>0;return(0,d.jsxs)("div",{className:"space-y-3",children:[j&&(0,d.jsx)("div",{className:"relative min-w-0 overflow-hidden",children:b?(0,d.jsx)("p",{className:"text-base whitespace-pre-line break-words overflow-wrap-anywhere",children:g}):(0,d.jsx)(_,{children:g})}),h.map(a=>(0,d.jsx)(ar,{uri:a,state:i[a],onOpenImage:c},a))]})}function ar({uri:a,state:b,onOpenImage:c}){if(!b||"loading"===b.status)return(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(N.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,d.jsx)("span",{children:"Loading resource…"})]});if("error"===b.status)return(0,d.jsxs)("div",{className:"flex items-start gap-2 text-xs text-destructive",children:[(0,d.jsx)(m.A,{className:"mt-0.5 h-3.5 w-3.5"}),(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsx)("p",{className:"font-medium",children:"Failed to load resource"}),(0,d.jsx)("p",{className:"break-all text-[11px] text-destructive/80",children:a}),(0,d.jsx)("p",{className:"text-[11px] text-destructive/70",children:b.error})]})]});let e=b.data;if(!e||0===e.items.length)return(0,d.jsxs)("div",{className:"text-xs text-muted-foreground",children:[(0,d.jsx)("p",{className:"font-medium",children:e?.name||a}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground/80",children:"No previewable content."})]});let f=e.items.find(a=>"mimeType"in a&&"string"==typeof a.mimeType)?.mimeType;return(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/80",children:[(0,d.jsx)(U.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:e.name||a}),f&&(0,d.jsx)("span",{className:"text-[10px]",children:f})]}),e.items.map((a,b)=>(function({item:a,index:b,onOpenImage:c}){let e=`resource-item-${b}`;switch(a.kind){case"text":if(a.mimeType&&a.mimeType.includes("markdown"))return(0,d.jsx)("div",{className:"text-sm",children:(0,d.jsx)(_,{children:a.text})},e);return(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words rounded-md bg-background/60 p-2 text-sm text-foreground",children:a.text},e);case"image":if(!al(a.src))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported image source"},e);return(0,d.jsx)("img",{src:a.src,alt:a.alt||"Resource image",onClick:()=>c(a.src,a.alt||"Resource image"),className:"max-h-60 w-full cursor-zoom-in rounded-lg border border-border object-contain"},e);case"audio":if(!al(a.src,"audio"))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported audio source"},e);return(0,d.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-background/50 p-2",children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(0,d.jsx)("audio",{controls:!0,src:a.src,className:"h-8 flex-1"}),a.filename&&(0,d.jsx)("span",{className:"max-w-[140px] truncate text-xs text-muted-foreground",children:a.filename})]},e);case"video":if(!al(a.src,"video"))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported video source"},e);return(0,d.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-border bg-background/50 p-3",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Video"}),a.filename&&(0,d.jsx)("span",{className:"truncate font-medium",children:a.filename})]}),(0,d.jsx)("video",{controls:!0,src:a.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."})]},e);case"file":return(0,d.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background/60 p-2",children:[(0,d.jsx)(Q.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsxs)("div",{className:"flex flex-1 flex-col",children:[(0,d.jsx)("span",{className:"text-sm font-medium text-foreground",children:a.filename||"Resource file"}),a.mimeType&&(0,d.jsx)("span",{className:"text-[11px] text-muted-foreground",children:a.mimeType})]}),a.src&&(0,d.jsx)("a",{href:a.src,download:a.filename||"resource.bin",className:"text-xs font-medium text-primary underline-offset-2 hover:underline",children:"Download"})]},e);default:return null}})({item:a,index:b,onOpenImage:c}))]})}c(16942);var as=c(9864);function at({children:a,className:b}){return(0,d.jsx)("div",{className:(0,j.cn)("relative","w-full","flex flex-col overflow-visible","max-h-[max(35svh,5rem)]","border-2 border-border/50","bg-background","rounded-3xl shadow-sm","transition-all duration-200",b),children:a})}function au({leftButtons:a,rightButtons:b,className:c}){return(0,d.jsxs)("div",{className:(0,j.cn)("flex items-center justify-between","h-12 px-3 pr-4",c),children:[(0,d.jsx)("div",{className:"flex items-center gap-2",children:a}),(0,d.jsx)("div",{className:"flex items-center gap-2",children:b})]})}var av=c(36377),aw=c(12366);let ax=e.forwardRef(({className:a,...b},c)=>(0,d.jsx)(aw.bL,{className:(0,j.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",a),...b,ref:c,children:(0,d.jsx)(aw.zi,{className:(0,j.cn)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));function ay({isStreaming:a,onStreamingChange:b,className:c}){return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:`flex items-center gap-1.5 cursor-pointer ${c||""}`,children:[(0,d.jsx)(av.A,{className:`h-3 w-3 ${a?"text-blue-500":"text-muted-foreground"}`}),(0,d.jsx)(ax,{checked:a,onCheckedChange:b,className:"scale-75","aria-label":"Toggle streaming"})]})}),(0,d.jsxs)(w,{side:"bottom",children:[(0,d.jsx)("p",{children:a?"Streaming enabled":"Streaming disabled"}),(0,d.jsx)("p",{className:"text-xs opacity-75",children:a?"Responses will stream in real-time":"Responses will arrive all at once"})]})]})})}ax.displayName=aw.bL.displayName;var az=c(67162),aA=c(84234);function aB({...a}){return(0,d.jsx)(aA.bL,{"data-slot":"popover",...a})}function aC({className:a,align:b="center",sideOffset:c=4,...e}){return(0,d.jsx)(aA.ZL,{children:(0,d.jsx)(aA.UC,{"data-slot":"popover-content",align:b,sideOffset:c,className:(0,j.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",a),...e})})}let aD=({children:a,...b})=>(0,d.jsx)(aB,{...b,children:a}),aE=function({...a}){return(0,d.jsx)(aA.l9,{"data-slot":"popover-trigger",...a})},aF=e.forwardRef(({className:a,align:b="end",sideOffset:c=4,...e},f)=>(0,d.jsx)(aC,{ref:f,align:b,sideOffset:c,className:(0,j.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...e}));aF.displayName="DropdownMenuContent";let aG=e.forwardRef(({className:a,disabled:b,...c},e)=>(0,d.jsx)("div",{ref:e,className:(0,j.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",b&&"pointer-events-none opacity-50",!b&&"hover:bg-accent hover:text-accent-foreground cursor-pointer",a),...c}));aG.displayName="DropdownMenuItem";let aH=e.forwardRef(({className:a,...b},c)=>(0,d.jsx)("div",{ref:c,className:(0,j.cn)("-mx-1 my-1 h-px bg-muted",a),...b}));function aI({onImageAttach:a,onPdfAttach:b,onAudioAttach:c,className:e,supports:g}){let[h,i]=f().useState(!1),j=g?.image!==!1,k=g?.pdf!==!1,l=g?.audio!==!1;return(0,d.jsxs)(aD,{open:h,onOpenChange:i,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",className:`h-8 px-2 md:px-3 text-sm text-muted-foreground hover:text-foreground rounded-full ${e||""}`,"aria-label":"Attach File",children:[(0,d.jsx)(az.A,{className:"h-3 w-3 md:mr-1.5"}),(0,d.jsx)("span",{className:"hidden md:inline",children:"Attach"})]})}),(0,d.jsxs)(aF,{side:"top",align:"start",children:[(0,d.jsx)(aG,{onClick:()=>{j&&(a(),i(!1))},className:j?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!j,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(az.A,{className:"h-4 w-4 mr-2"})," Image"]})}),!j&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,d.jsx)(aG,{onClick:()=>{k&&(b(),i(!1))},className:k?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!k,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(Q.A,{className:"h-4 w-4 mr-2"})," PDF"]})}),!k&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,d.jsx)(aG,{onClick:()=>{l&&(c(),i(!1))},className:l?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!l,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(O.A,{className:"h-4 w-4 mr-2"})," Audio file"]})}),!l&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})})]})]})}aH.displayName="DropdownMenuSeparator";var aJ=c(93049),aK=c(59245);function aL({isRecording:a,onToggleRecording:b,className:c,disabled:e}){let f=(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>{e||b()},className:`h-8 px-2 md:px-3 text-sm rounded-full ${e?"opacity-50 cursor-not-allowed":"text-muted-foreground hover:text-foreground"} ${c||""}`,"aria-label":a?"Stop recording":"Record audio","aria-disabled":!!e||void 0,children:[a?(0,d.jsx)(aJ.A,{className:"h-3 w-3 md:mr-1.5 text-red-500"}):(0,d.jsx)(aK.A,{className:"h-3 w-3 md:mr-1.5"}),(0,d.jsx)("span",{className:"hidden md:inline",children:a?"Stop":"Record"})]});return e?(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:f}),(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})}):f}var aM=c(71061),aN=c(95409),aO=c(79487),aP=c(20773),aQ=c(98023);function aR({open:a,onOpenChange:b,provider:c,primaryEnvVar:f,onSaved:h}){let[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)(null),o=async()=>{if(!i.trim())return void n("API key is required");l(!0),n(null);try{let a=await fetch(`${(0,g.e)()}/api/llm/key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,apiKey:i})}),d=await a.json();if(!a.ok||"object"!=typeof d||null===d)throw Error("Failed to save API key");if(!d.ok||!d.provider||!d.envVar)throw Error("Unexpected response while saving API key");h({provider:d.provider,envVar:d.envVar}),b(!1),j("")}catch(a){n(a instanceof Error?a.message:"Failed to save API key")}finally{l(!1)}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{children:["Set ",c," API Key"]}),(0,d.jsxs)(aN.rr,{children:["This key will be stored in your .env (env var ",f,"). It is not shared with the client."]})]}),m&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:m})}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"apiKey",children:"API Key"}),(0,d.jsx)(aP.p,{id:"apiKey",type:"password",value:i,onChange:a=>j(a.target.value),placeholder:`Enter ${c} API key`})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>b(!1),disabled:k,children:"Cancel"}),(0,d.jsx)(x.$,{onClick:o,disabled:k,children:k?"Saving...":"Save"})]})]})})}var aS=c(67478),aT=c(63472),aU=c(66696),aV=c(38988);function aW({value:a,onChange:b,placeholder:c="Search providers or models",autoFocus:f=!1}){let g=(0,e.useRef)(null);return(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(aV.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsx)(aP.p,{ref:g,placeholder:c,value:a,onChange:a=>b(a.target.value),className:"focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0"})]})}var aX=c(94504),aY=c(15029),aZ=c(65151);let a$={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"},a_={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 a0(a){if(!a)return[];let b="USD"===(a.currency||"USD")?"$":"",c=[];return c.push(`Cost: ${b}${a.inputPerM.toFixed(2)} in / ${b}${a.outputPerM.toFixed(2)} out per 1M tokens`),null!=a.cacheReadPerM&&c.push(`Cache read: ${b}${a.cacheReadPerM.toFixed(2)} per 1M tokens`),null!=a.cacheWritePerM&&c.push(`Cache write: ${b}${a.cacheWritePerM.toFixed(2)} per 1M tokens`),c}let a1=["google","cohere","anthropic"],a2=a=>!a1.includes(a),a3={image:(0,d.jsx)("span",{className:"text-sm",children:"\uD83D\uDDBC️"}),audio:(0,d.jsx)("span",{className:"text-sm",children:"\uD83C\uDFB5"}),pdf:(0,d.jsx)("span",{className:"text-sm",children:"\uD83D\uDCC4"}),reasoning:(0,d.jsx)("span",{className:"text-sm",children:"\uD83E\uDDE0"}),experimental:(0,d.jsx)(aY.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-amber-500 transition-colors cursor-help"}),new:(0,d.jsx)(aZ.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-yellow-500 transition-colors cursor-help"}),realtime:(0,d.jsx)(av.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-blue-500 transition-colors cursor-help"})};var a4=c(88595);function a5({supportedFileTypes:a,hasApiKey:b,className:c}){return(0,d.jsxs)("div",{className:`flex items-center gap-1.5 flex-shrink-0 ${c||""}`,children:[a.includes("pdf")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.pdf})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"PDF support"})})]}),a.includes("audio")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.audio})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"Audio support"})})]}),a.includes("image")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.image})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"Image support"})})]}),!b&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:(0,d.jsx)(a4.A,{className:"h-3.5 w-3.5 text-amber-500 hover:text-amber-400 transition-colors cursor-help"})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"API key required"})})]})]})}function a6({providerId:a,provider:b,models:c,favorites:e,currentModel:f,onToggleFavorite:g,onUse:h}){return 0===c.length?null:(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:a$[a]?(0,d.jsx)(aM.default,{src:a$[a],alt:`${a} logo`,width:20,height:20,className:(0,j.cn)("object-contain",a2(a)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(aS.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,d.jsx)("span",{className:"text-base font-medium",children:b.name})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[b.supportsBaseURL&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs",children:"baseURL"}),!b.hasApiKey&&(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(aX.E,{variant:"destructive",className:"text-xs cursor-default",children:"API Key Required"})}),(0,d.jsxs)(w,{children:["Click any ",b.name," model to set up the API key"]})]})}),a_[a]&&(0,d.jsx)("a",{href:a_[a],target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:underline",title:"View provider pricing",children:"Pricing ↗"})]})]}),(0,d.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:c.map(c=>{let i,k,l=c.displayName||c.name,m=(i=c.name,f?.provider===a&&f?.model===i),n=(k=c.name,e.includes(`${a}|${k}`)),o=b.hasApiKey,p=a0(c.pricing||void 0),q=[`Max tokens: ${c.maxInputTokens.toLocaleString()}`,c.supportedFileTypes.length>0&&`Supports: ${c.supportedFileTypes.join(", ")}`,c.default&&"Default model",!o&&"⚠️ API key required",...p].filter(Boolean);return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{onClick:()=>h(a,c),onKeyDown:b=>{let d=b.target;if(d&&d.closest("button"))return;let e="Enter"===b.key,f=" "===b.key||"Spacebar"===b.key||"Space"===b.code;f&&b.preventDefault(),(e||f)&&h(a,c)},className:(0,j.cn)("group relative flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-all duration-100 cursor-pointer outline-none","hover:bg-accent hover:border-accent-foreground/20 hover:shadow-sm","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",m&&"bg-accent border-accent-foreground/20 shadow-sm ring-1 ring-accent-foreground/10",!o&&"opacity-60"),role:"button",tabIndex:0,children:[(0,d.jsx)("div",{className:"flex-1 text-left",children:(0,d.jsx)("div",{className:"flex items-center gap-2",children:(0,d.jsx)("span",{className:"text-sm font-medium",children:l})})}),(0,d.jsx)(a5,{supportedFileTypes:c.supportedFileTypes,hasApiKey:o}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{onKeyDown:a=>{let b=" "===a.key||"Spacebar"===a.key||"Space"===a.code;("Enter"===a.key||b)&&(a.stopPropagation(),b&&a.preventDefault())},onClick:b=>{b.stopPropagation(),g(a,c.name)},className:"flex-shrink-0 text-muted-foreground hover:text-foreground transition-colors","aria-label":n?"Remove from favorites":"Add to favorites",children:(0,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4",n&&"fill-current text-yellow-500")})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:n?"Remove from favorites":"Add to favorites"})})]})}),m&&(0,d.jsx)("div",{className:"absolute inset-y-0 left-0 w-0.5 bg-primary rounded-l-lg"})]})}),(0,d.jsx)(w,{side:"bottom",className:"max-w-xs",children:(0,d.jsx)("div",{className:"text-xs space-y-0.5",children:q.map((a,b)=>(0,d.jsx)("div",{children:a},b))})})]})},c.name)})})]})}function a7(a){let b=a.trim();if(!b.length)return{isValid:!0};try{let a=new URL(b);if(!["http:","https:"].includes(a.protocol))return{isValid:!1,error:"URL must use http:// or https://"};if(!a.pathname.includes("/v1"))return{isValid:!1,error:"URL must include /v1 for compatibility"};return{isValid:!0}}catch{return{isValid:!1,error:"Invalid URL format"}}}let a8="dexto:customModels";function a9({htmlFor:a,children:b,tooltip:c,className:e}){return(0,d.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,d.jsx)(aQ.J,{htmlFor:a,className:e,children:b}),c&&(0,d.jsx)(t,{delayDuration:200,children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"More information",children:(0,d.jsx)(aS.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"right",className:"max-w-xs",children:(0,d.jsx)("p",{className:"text-sm",children:c})})]})})]})}function ba({provider:a,model:b,providerInfo:c,isFavorite:e,isActive:f,onClick:g,onToggleFavorite:h}){let i=b.displayName||b.name,k=c.hasApiKey,l=a0(b.pricing||void 0),m=[`Max tokens: ${b.maxInputTokens.toLocaleString()}`,b.supportedFileTypes.length>0&&`Supports: ${b.supportedFileTypes.join(", ")}`,!k&&"⚠️ API key required",...l].filter(Boolean);return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{onClick:g,className:(0,j.cn)("w-full flex items-center gap-4 px-4 py-3 rounded-xl transition-all duration-150 cursor-pointer group","hover:bg-accent/50 hover:shadow-md hover:scale-[1.01]",f&&"bg-primary/10 shadow-md ring-2 ring-primary/20 scale-[1.01]",!k&&"opacity-60"),role:"button",tabIndex:0,children:[(0,d.jsx)("div",{className:"w-6 h-6 flex-shrink-0 flex items-center justify-center",children:a$[a]?(0,d.jsx)(aM.default,{src:a$[a],alt:`${a} logo`,width:24,height:24,className:(0,j.cn)("object-contain",a2(a)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(aS.A,{className:"h-5 w-5 text-muted-foreground"})}),(0,d.jsxs)("div",{className:"flex-1 text-left min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:i}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:a})]}),(0,d.jsx)(a5,{supportedFileTypes:b.supportedFileTypes,hasApiKey:k}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{onClick:a=>{a.stopPropagation(),h()},className:(0,j.cn)("flex-shrink-0 transition-all duration-200","hover:scale-110 active:scale-95",e?"text-yellow-500 hover:text-yellow-400":"text-muted-foreground hover:text-yellow-500"),"aria-label":e?"Remove from favorites":"Add to favorites",children:(0,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4",e&&"fill-current")})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:e?"Remove from favorites":"Add to favorites"})})]})})]})}),(0,d.jsx)(w,{side:"right",className:"max-w-xs",children:(0,d.jsx)("div",{className:"text-xs space-y-0.5",children:m.map((a,b)=>(0,d.jsx)("div",{children:a},b))})})]})})}function bb(){let[a,b]=(0,e.useState)(!1),[c,f]=(0,e.useState)(!1),[h,k]=(0,e.useState)(null),[l,m]=(0,e.useState)({}),[p,q]=(0,e.useState)(""),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(""),[v,w]=(0,e.useState)(""),[y,z]=(0,e.useState)(!1),[A,B]=(0,e.useState)("favorites"),[C,D]=(0,e.useState)([]),[E,F]=(0,e.useState)({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),[G,H]=(0,e.useState)(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),[O,P]=(0,e.useState)(null),{currentSessionId:Q,currentLLM:R,refreshCurrentLLM:S}=(0,i.v)(),[T,U]=(0,e.useState)([]),V=(0,e.useCallback)((a,b)=>{let c=`${a}|${b}`;U(a=>{let b=a.includes(c)?a.filter(a=>a!==c):[...a,c];return localStorage.setItem("dexto:modelFavorites",JSON.stringify(b)),b})},[]),W=(0,e.useCallback)(()=>{let{name:a,baseURL:b,maxInputTokens:c,maxOutputTokens:d}=E;if(!a.trim()||!b.trim())return void k("Model name and Base URL are required");let e=a7(b);if(!e.isValid)return void k(e.error||"Invalid Base URL");let f=[...C,{name:a.trim(),baseURL:b.trim(),maxInputTokens:c?(()=>{let a=parseInt(c,10);return isNaN(a)?void 0:a})():void 0,maxOutputTokens:d?(()=>{let a=parseInt(d,10);return isNaN(a)?void 0:a})():void 0}];D(f),localStorage.setItem(a8,JSON.stringify(f)),F({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),H(!1),k(null)},[E,C]),X=(0,e.useCallback)(a=>{let b=C.filter(b=>b.name!==a);D(b),localStorage.setItem(a8,JSON.stringify(b))},[C]);async function Y(a,c,d){z(!0),k(null);try{let e=function(a,b){let c=R?.router||"vercel",d=l[a]?.supportedRouters??["vercel"],e=b.supportedRouters??d,f=t||c;return e.includes(f)?f:e[0]||d[0]||"vercel"}(a,c),f={provider:a,model:c.name,router:e};d&&l[a]?.supportsBaseURL&&(f.baseURL=d),Q&&(f.sessionId=Q);let h=await fetch(`${(0,g.e)()}/api/llm/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)}),i=await h.json().catch(()=>({}));if(!h.ok){let a=i?.issues&&i.issues[0]?.message||"Failed to switch model";k(a);return}await S(),b(!1)}catch{k("Network error while switching")}finally{z(!1)}}function Z(a,b,c){let d=l[a];if(!d)return;let e=c||v;if(d.supportsBaseURL&&e){let a=a7(e);if(!a.isValid)return void k(a.error||"Invalid base URL")}if(!d.hasApiKey){P({provider:a,model:b.name}),M(a),K(!0);return}Y(a,b,e)}let $=Object.keys(l),_=R?.displayName||R?.model||"Choose Model",aa=(0,e.useMemo)(()=>T.map(a=>{let[b,c]=a.split("|"),d=l[b],e=d?.models.find(a=>a.name===c);return d&&e?{providerId:b,provider:d,model:e}:null}).filter(Boolean),[T,l]),ab=(0,e.useMemo)(()=>{if(!p)return l;let a={};return $.forEach(b=>{let c=l[b].models.filter(a=>(function(a,b){let c=p.trim().toLowerCase();return!c||b.name.toLowerCase().includes(c)||(b.displayName?.toLowerCase().includes(c)??!1)||a.toLowerCase().includes(c)||(l[a]?.name.toLowerCase().includes(c)??!1)})(b,a));c.length>0&&(a[b]={...l[b],models:c})}),a},[l,p,$]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aN.lG,{open:a,onOpenChange:b,children:[(0,d.jsx)(aN.zM,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 cursor-pointer",title:"Choose model",children:[R?.provider&&a$[R.provider]?(0,d.jsx)(aM.default,{src:a$[R.provider],alt:`${R.provider} logo`,width:16,height:16,className:(0,j.cn)("object-contain",a2(R.provider)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(I.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"text-sm",children:_}),(0,d.jsx)(o.A,{className:"h-3 w-3"})]})}),(0,d.jsxs)(aN.Cf,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[(0,d.jsxs)(aN.c7,{className:"pb-4 flex-shrink-0",children:[(0,d.jsx)(aN.L3,{className:"text-xl",children:"Select Model"}),(0,d.jsx)(aN.rr,{className:"text-sm text-muted-foreground",children:"Choose your favorite model, check all models, or add your own model"})]}),(0,d.jsxs)("div",{className:"flex flex-col min-h-0 flex-1 space-y-4",children:[(0,d.jsxs)("div",{className:"flex-shrink-0 space-y-4",children:[h&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:h})}),(0,d.jsx)(aW,{value:p,onChange:q,placeholder:"Search models, providers..."})]}),!p&&(0,d.jsxs)("div",{className:"flex gap-2 border-b border-border pb-2",children:[(0,d.jsxs)("button",{onClick:()=>B("favorites"),className:(0,j.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,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4","favorites"===A&&"fill-current")}),"Favorites",aa.length>0&&(0,d.jsxs)("span",{className:"text-xs opacity-70",children:["(",aa.length,")"]})]}),(0,d.jsxs)("button",{onClick:()=>B("all"),className:(0,j.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,d.jsx)(I.A,{className:"h-4 w-4"}),"All Models"]}),(0,d.jsxs)("button",{onClick:()=>B("custom"),className:(0,j.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,d.jsx)(aU.A,{className:"h-4 w-4"}),"Custom",C.length>0&&(0,d.jsxs)("span",{className:"text-xs opacity-70",children:["(",C.length,")"]})]})]}),(0,d.jsx)("div",{className:"flex-1 overflow-auto px-1 min-h-0",children:c?(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground justify-center py-8",children:[(0,d.jsx)(N.A,{className:"h-4 w-4 animate-spin"})," Loading models..."]}):p?(0,d.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(ab).length?(0,d.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No models found matching your search"}):Object.entries(ab).map(([a,b])=>(0,d.jsx)(a6,{providerId:a,provider:b,models:b.models,favorites:T,currentModel:R||void 0,onToggleFavorite:V,onUse:Z},a))}):"favorites"===A?0===aa.length?(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center space-y-3",children:[(0,d.jsx)(aT.A,{className:"h-12 w-12 text-muted-foreground/40"}),(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:"No favorites yet"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"Star models to add them to your favorites"})]})]}):(0,d.jsx)("div",{className:"space-y-2 pb-2",children:aa.map(({providerId:a,provider:b,model:c})=>{var e;let f;return(0,d.jsx)(ba,{provider:a,model:c,providerInfo:b,isFavorite:!0,isActive:(f=c.name,R?.provider===a&&R?.model===f),onClick:()=>Z(a,c),onToggleFavorite:()=>V(a,c.name)},(e=c.name,`${a}|${e}`))})}):"custom"===A?(0,d.jsxs)("div",{className:"space-y-4 pb-2",children:[C.length>0&&(0,d.jsx)("div",{className:"space-y-2",children:C.map(a=>(0,d.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"text-sm font-medium",children:a.name}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"openai-compatible"})]}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:a.baseURL})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 ml-2",children:[(0,d.jsx)(x.$,{size:"sm",variant:"ghost",onClick:()=>{Z("openai-compatible",{name:a.name,displayName:a.name,maxInputTokens:a.maxInputTokens||128e3,supportedFileTypes:["pdf","image","audio"],supportedRouters:["vercel","in-built"]},a.baseURL)},className:"h-8 px-3",children:"Use"}),(0,d.jsx)(x.$,{size:"sm",variant:"ghost",onClick:()=>X(a.name),className:"h-8 w-8 p-0 text-destructive hover:text-destructive","aria-label":`Delete custom model ${a.name}`,children:"\xd7"})]})]},a.name))}),(0,d.jsxs)("div",{className:"space-y-3 pt-4 border-t border-border",children:[(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>H(!G),className:"flex items-center justify-between w-full p-0 h-auto hover:bg-transparent",children:[(0,d.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:0===C.length?"Add your first custom model":"Add another model"}),G?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"})]}),G&&(0,d.jsxs)("div",{className:"space-y-4 pl-4 border-l-2 border-muted",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-model-name",tooltip:"Model identifier (e.g., llama3, mixtral, gpt-5)",children:"Model Name *"}),(0,d.jsx)(aP.p,{id:"custom-model-name",value:E.name,onChange:a=>F(b=>({...b,name:a.target.value})),placeholder:"e.g., llama3",className:"text-sm"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-base-url",tooltip:"OpenAI-compatible endpoint URL. Must include /v1 path (e.g., http://localhost:1234/v1)",children:"Base URL *"}),(0,d.jsx)(aP.p,{id:"custom-base-url",value:E.baseURL,onChange:a=>F(b=>({...b,baseURL:a.target.value})),placeholder:"http://localhost:1234/v1",className:"text-sm"})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"custom-max-input",type:"number",value:E.maxInputTokens,onChange:a=>F(b=>({...b,maxInputTokens:a.target.value})),placeholder:"128000",className:"text-sm",min:"1"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-max-output",tooltip:"Maximum output tokens the model can generate. Uses provider's default if not specified",children:"Max Output Tokens"}),(0,d.jsx)(aP.p,{id:"custom-max-output",type:"number",value:E.maxOutputTokens,onChange:a=>F(b=>({...b,maxOutputTokens:a.target.value})),placeholder:"Auto",className:"text-sm",min:"1"})]})]}),(0,d.jsx)(x.$,{onClick:W,size:"sm",className:"w-full",children:"Add Model"})]})]})]}):(0,d.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(l).length?(0,d.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No providers available"}):Object.entries(l).map(([a,b])=>(0,d.jsx)(a6,{providerId:a,provider:b,models:b.models,favorites:T,currentModel:R||void 0,onToggleFavorite:V,onUse:Z},a))})})]})]})]}),L&&(0,d.jsx)(aR,{open:J,onOpenChange:K,provider:L,primaryEnvVar:l[L]?.primaryEnvVar||"",onSaved:function(a){if(m(b=>({...b,[a.provider]:b[a.provider]?{...b[a.provider],hasApiKey:!0}:b[a.provider]})),K(!1),O){let{provider:a,model:b}=O,c=l[a]?.models.find(a=>a.name===b);c&&Y(a,c,v),P(null)}}})]})}var bc=c(71335),bd=c(35887),be=c(89615);let bf=({prompt:a,isSelected:b,onClick:c,onMouseEnter:e,dataIndex:f})=>(0,d.jsx)("div",{className:`px-3 py-2 cursor-pointer transition-colors ${b?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"}`,onClick:c,onMouseEnter:e,"data-index":f,children:(0,d.jsxs)("div",{className:"flex items-start gap-2",children:[(0,d.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:"mcp"===a.source?(0,d.jsx)(av.A,{className:"h-3 w-3 text-blue-400"}):"starter"===a.source?(0,d.jsx)("span",{className:"text-xs",children:"\uD83D\uDE80"}):(0,d.jsx)(aZ.A,{className:"h-3 w-3 text-purple-400"})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsxs)("span",{className:"font-medium text-xs text-foreground",children:["/",a.name]}),a.arguments&&a.arguments.length>0&&(0,d.jsx)("span",{className:"flex items-center gap-1",children:a.arguments.map((a,b)=>(0,d.jsxs)("span",{className:"group relative inline-block",title:a.description||a.name,children:[(0,d.jsxs)("span",{className:"text-xs text-muted-foreground/70 hover:text-muted-foreground cursor-help transition-colors",children:["<",a.name,a.required?"":"?",">"]}),a.description&&(0,d.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:a.description})]},a.name))})]}),"mcp"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"MCP"}),"file"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"File"}),"custom"===a.source&&(0,d.jsx)(aX.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"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Starter"})]}),a.title&&(0,d.jsx)("div",{className:"text-xs font-medium text-foreground/90 mb-0.5",children:a.title}),a.description&&a.description!==a.title&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5 line-clamp-2",children:a.description})]})]})});function bg({isVisible:a,searchQuery:b,onSelectPrompt:c,onClose:g,onCreatePrompt:h,refreshKey:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)([]),[n,o]=(0,e.useState)(!1),[p,q]=(0,e.useState)(0),r=(0,e.useRef)(0),s=(0,e.useRef)(null),t=(0,e.useRef)(null);(0,e.useRef)(0),r.current=p;let u=f().useMemo(()=>{let a=b.trim();return!!a&&!!("/"===a||a.startsWith("/")&&0===l.length)},[b,l.length]);return(f().useMemo(()=>{let a=[];return u&&a.push({kind:"create"}),l.forEach(b=>a.push({kind:"prompt",prompt:b})),a},[u,l]).length,a)?(0,d.jsxs)("div",{ref:s,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,d.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50",children:(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[(0,d.jsx)("span",{children:"Available Prompts (hover over arguments for more info)"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"ml-auto text-xs px-2 py-0.5",children:j.length})]})}),(0,d.jsx)("div",{ref:t,className:"max-h-48 overflow-y-auto",children:n?(0,d.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"Loading prompts..."}):(0,d.jsxs)(d.Fragment,{children:[u&&(0,d.jsxs)("div",{className:`px-3 py-2 cursor-pointer transition-colors ${0===p?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"}`,onClick:()=>h?.(),onMouseEnter:()=>q(0),"data-index":0,children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-foreground",children:[(0,d.jsx)(aU.A,{className:"h-3 w-3 text-primary"}),(0,d.jsx)("span",{children:"Create new prompt"})]}),(0,d.jsx)("div",{className:"text-[11px] text-muted-foreground mt-1",children:"Define a reusable prompt. Press Enter to continue."})]}),0===l.length?!u&&(0,d.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"No prompts available."}):l.map((a,b)=>{let e=u?b+1:b;return(0,d.jsx)(bf,{prompt:a,isSelected:e===p,onClick:()=>c(a),onMouseEnter:()=>q(e),dataIndex:e},a.name)})]})}),(0,d.jsx)("div",{className:"px-2 py-1.5 border-t border-border bg-muted/20 text-xs text-muted-foreground text-center",children:(0,d.jsx)("span",{children:"↑↓ Navigate • Tab/Enter Select • Esc Close"})})]}):null}var bh=c(61295),bi=c(57752),bj=c(50803),bk=c(57045);function bl({open:a,onClose:b,onCreated:c}){let[f,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(!1),B=async a=>{try{var b;let c=await (b=a,new Promise((a,c)=>{let d=new FileReader;d.onload=()=>{let b=d.result;"string"==typeof b?a(b):c(Error("Failed to read file"))},d.onerror=a=>c(a),d.readAsDataURL(b)}));p({base64:c,mimeType:a.type||"application/octet-stream",filename:a.name}),r(c),t(a.name)}catch(a){console.error("Failed to read file:",a),y("Failed to read file. Please try a different file.")}},C=async a=>{let b=a.target.files?.[0];if(!b){p(null),r(null),t(null);return}await B(b)},D=async a=>{a.preventDefault(),A(!1);let b=Array.from(a.dataTransfer.files);b.length>0&&await B(b[0])},E=async a=>{if(a.preventDefault(),!f.trim()||!m.trim())return void y("Name and content are required.");v(!0),y(null);let b={name:f.trim(),title:i.trim()||void 0,description:k.trim()||void 0,content:m,resource:o||void 0};try{let a=await fetch(`${(0,g.e)()}/api/prompts/custom`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(!a.ok){let b=await a.json().catch(()=>({})),c=b?.message||"Failed to create prompt.";throw Error(c)}let d=await a.json();d?.prompt&&c({name:d.prompt.name})}catch(a){console.error("Failed to create prompt:",a),y(a instanceof Error?a.message:"Failed to create prompt. Please try again.")}finally{v(!1)}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-3xl",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create Custom Prompt"}),(0,d.jsx)(aN.rr,{children:"Define reusable prompt text and optionally attach a supporting resource file."})]}),(0,d.jsxs)("form",{onSubmit:E,className:"space-y-4",children:[w&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:w})}),(0,d.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-name",children:"Prompt Name"}),(0,d.jsx)(aP.p,{id:"prompt-name",value:f,onChange:a=>h(a.target.value),placeholder:"research-summary",required:!0}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Use lowercase letters, numbers, or hyphens. This becomes your /prompt command."})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-title",children:"Title"}),(0,d.jsx)(aP.p,{id:"prompt-title",value:i,onChange:a=>j(a.target.value),placeholder:"Research Summary"})]})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-description",children:"Description"}),(0,d.jsx)(aP.p,{id:"prompt-description",value:k,onChange:a=>l(a.target.value),placeholder:"Summarize research papers with key findings"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-content",children:"Prompt Content"}),(0,d.jsx)(bh.T,{id:"prompt-content",value:m,onChange:a=>n(a.target.value),placeholder:"Write the instructions for this prompt...",className:"min-h-[160px]",required:!0})]}),(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)(aQ.J,{children:"Attach resource (optional)"}),q?(0,d.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,d.jsxs)("div",{className:"flex items-center text-sm",children:[(0,d.jsx)(bi.A,{className:"h-4 w-4 mr-2 text-muted-foreground"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"mr-2",children:"Resource"}),s||"Attached file"]}),(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>{p(null),r(null),t(null)},children:[(0,d.jsx)(bj.A,{className:"h-4 w-4 mr-1"})," Remove"]})]}):(0,d.jsxs)("div",{className:`relative rounded-lg border-2 border-dashed transition-colors ${z?"border-primary bg-primary/5":"border-border/60 hover:border-border/80"} px-6 py-8 text-center`,onDragOver:a=>{a.preventDefault(),A(!0)},onDragLeave:a=>{a.preventDefault(),A(!1)},onDrop:D,children:[(0,d.jsx)("input",{type:"file",onChange:C,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",accept:"*/*"}),(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center space-y-2",children:[(0,d.jsx)(bk.A,{className:`h-8 w-8 ${z?"text-primary":"text-muted-foreground"}`}),(0,d.jsxs)("div",{className:"text-sm",children:[(0,d.jsx)("span",{className:"font-medium",children:z?"Drop file here":"Click to upload"}),(0,d.jsx)("span",{className:"text-muted-foreground",children:" or drag and drop"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Any file type supported"})]})]}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The resource will be stored securely and referenced when this prompt is used."})]}),(0,d.jsxs)(aN.Es,{className:"flex items-center justify-between gap-2",children:[(0,d.jsx)(x.$,{type:"button",variant:"ghost",onClick:b,disabled:u,children:"Cancel"}),(0,d.jsx)(x.$,{type:"submit",disabled:u,children:u?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.A,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):"Save Prompt"})]})]})]})})}function bm({open:a,onClose:b,onSuccess:c}){let[f,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)(null),o=async()=>{if(!f.trim())return void n("Memory content is required");l(!0),n(null);try{let a={content:f.trim(),...i.trim()&&{tags:i.split(",").map(a=>a.trim()).filter(Boolean)},metadata:{source:"user"}},d=await fetch(`${(0,g.e)()}/api/memory`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){let a=await d.json();throw Error(a.error||"Failed to create memory")}h(""),j(""),c?.(),b()}catch(a){n(a instanceof Error?a.message:"Failed to create memory")}finally{l(!1)}},p=()=>{k||(h(""),j(""),n(null),b())};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:p,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-[500px]",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create Memory"}),(0,d.jsx)(aN.rr,{children:"Memories are automatically included in every conversation to help Dexto remember your preferences and important information."})]}),(0,d.jsxs)("div",{className:"grid gap-4 py-4",children:[m&&(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(bc.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:m})]}),(0,d.jsxs)("div",{className:"grid gap-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"memory-content",children:"Memory Content *"}),(0,d.jsx)(bh.T,{id:"memory-content",placeholder:"e.g., I prefer concise responses without explanations",value:f,onChange:a=>h(a.target.value),className:"min-h-[100px] resize-none",disabled:k,autoFocus:!0}),(0,d.jsxs)("p",{className:"text-sm text-muted-foreground",children:[f.length," / 10,000 characters"]})]}),(0,d.jsxs)("div",{className:"grid gap-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"memory-tags",children:"Tags (optional)"}),(0,d.jsx)(aP.p,{id:"memory-tags",placeholder:"e.g., preferences, work, coding-style",value:i,onChange:a=>j(a.target.value),disabled:k}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Comma-separated tags for organizing memories"})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:p,disabled:k,children:"Cancel"}),(0,d.jsx)(x.$,{onClick:o,disabled:k||!f.trim(),children:k?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Memory"})]})]})})}function bn({onSend:a,isSending:b,variant:c="chat"}){let[h,k]=(0,e.useState)(""),l=(0,e.useRef)(null),[m,n]=(0,e.useState)(null),[o,q]=(0,e.useState)(null),r=(0,e.useRef)(null),s=(0,e.useRef)(null),t=(0,e.useRef)(null),u=function(){let[a,b]=(0,e.useState)(!1);return a}(),[v,w]=(0,e.useState)(!1),y=(0,e.useRef)(null),{currentSessionId:z,isStreaming:B,setStreaming:C,cancel:D,processing:E,currentLLM:F}=(0,i.v)(),[G,H]=(0,e.useState)(null),[I,J]=(0,e.useState)(!1),[K,L]=(0,e.useState)(null),[M,P]=(0,e.useState)(null),[R,S]=(0,e.useState)([]),{resources:T,loading:U,refresh:V}=ag(),[W,X]=(0,e.useState)(""),[Y,Z]=(0,e.useState)(!1),[$,_]=(0,e.useState)(0),[aa,ab]=(0,e.useState)(null),ac=(0,e.useMemo)(()=>(0,j.L)(T,W),[T,W]),[ad,ae]=(0,e.useState)(!1),[af,ah]=(0,e.useState)(!1),[ai,aj]=(0,e.useState)(0),[ak,al]=(0,e.useState)(!1),am=a=>{P(a),setTimeout(()=>P(null),5e3)},an=f().useCallback(()=>{ae(!1),ah(!0)},[]),ao=f().useCallback(a=>{(0,be.w)(),ah(!1),aj(a=>a+1);let b=`/${a.name}`;k(b),l.current&&(l.current.focus(),l.current.setSelectionRange(b.length,b.length))},[]),ap=f().useCallback(()=>{ah(!1),"/"===h&&k("")},[h]),aq=async()=>{let b=h.trim();if(b||m||o){if("/"===b)return void an();if(b.startsWith("/")){let a=function(a){let b=a.trim();if(!b.startsWith("/"))return{isSlash:!1,command:"",argsArray:[],argsText:""};let c=function(a){let b=[],c="",d=!1,e="",f=0;for(;f<a.length;){let g=a[f],h=a[f+1];d||'"'!==g&&"'"!==g?d&&g===e?(d=!1,e=""):d||" "!==g?"\\"===g&&h?(c+=h,f++):c+=g:c&&(b.push(c),c=""):(d=!0,e=g),f++}return c&&b.push(c),b.filter(Boolean)}(b.slice(1)),d=c[0]||"",e=c.slice(1),f=e.join(" ");return{isSlash:!0,command:d,argsArray:e,argsText:f}}(b),c=a.command,d=b.slice(1+c.length).trimStart();if(c)try{let e=new URL(`/api/prompts/${encodeURIComponent(c)}/resolve`,(0,g.e)());if(a.argsArray&&a.argsArray.length>0){let{keyValues:b,positional:c}=function(a){let b={},c=[];for(let d of a){let a=d.indexOf("=");if(a>0){let c=d.slice(0,a).trim(),e=d.slice(a+1);if(c.length>0){b[c]=e;continue}}c.push(d)}return{keyValues:b,positional:c}}(a.argsArray),d={...b};if(c.length>0&&(d._positional=c),Object.keys(d).length>0)try{e.searchParams.set("args",JSON.stringify(d))}catch{}}d&&e.searchParams.set("context",d);let f=new AbortController,h=setTimeout(()=>f.abort(),5e3);try{let a=await fetch(e.toString(),{signal:f.signal});if(clearTimeout(h),a.ok){let c=await a.json(),d="string"==typeof c?.text?c.text:"";d.trim()&&(b=d)}}finally{clearTimeout(h)}}catch{}}a(b,m??void 0,o??void 0),k(""),n(null),q(null),ae(!1)}},ar=a=>{if(Y){if("ArrowDown"===a.key){a.preventDefault(),_(a=>(a+1)%Math.max(1,ac.length));return}if("ArrowUp"===a.key){a.preventDefault(),_(a=>(a-1+Math.max(1,ac.length))%Math.max(1,ac.length));return}if("Enter"===a.key||"Tab"===a.key){a.preventDefault(),((a,b)=>{if(0===ac.length)return;let c=b??ac[Math.max(0,Math.min(a,ac.length-1))],d=l.current;if(!d)return;let e=d.selectionStart??h.length,f=((a,b)=>{for(let c=b-1;c>=0;c--){let b=a[c];if("@"===b){if(0===c)return c;let b=a[c-1];if(/\s/.test(b))return c;break}if(/\s/.test(b))break}return -1})(h,e);if(-1===f)return;let g=h.slice(0,f),i=h.slice(e),j=c.name||c.uri.split("/").pop()||c.uri,m=c.serverName?`@${c.serverName}:${j}`:`@${j}`;k(g+m+i),Z(!1),X(""),_(0),requestAnimationFrame(()=>{let a=(g+m).length;d.setSelectionRange(a,a),d.focus()})})($);return}if("Escape"===a.key)return void Z(!1)}if(av&&"Escape"===a.key){a.preventDefault(),aw(!1),k("");return}if("Enter"===a.key&&!a.shiftKey){if(a.preventDefault(),"#"===h.trim()){k(""),aw(!1),al(!0);return}aq()}},[av,aw]=(0,e.useState)(!1),[ax,az]=(0,e.useState)(null),aA=a=>{let b=a.target.value;if(k(b),b.startsWith("/")&&!b.includes("\n")?ae(!0):ad&&ae(!1),"#"===b.trim()){aw(!0);let a=l.current;if(a){let b=a.getBoundingClientRect(),c=Math.max(8,b.left+window.scrollX+16),d=Math.max(280,b.width-32);az({position:"fixed",left:c,bottom:Math.max(80,window.innerHeight-(b.bottom+window.scrollY)+64),width:d,zIndex:9999})}}else aw(!1),az(null)};f().useRef(!1);let aB=a=>{let b=a.clipboardData.getData("text/plain");if(b&&!(b.length<=2e4))if(a.preventDefault(),window.confirm("Large text detected. Attach as a file instead of inflating the input?\n(OK = attach as file, Cancel = paste truncated preview)"))q({base64:(a=>{try{return btoa(unescape(encodeURIComponent(a)))}catch{return btoa(a)}})(b),mimeType:"text/plain",filename:"pasted.txt"});else{let a=b.slice(0,2e4);k(b=>b+a)}},aC=async()=>{try{let a=await navigator.mediaDevices.getUserMedia({audio:!0}),b=new MediaRecorder(a);y.current=b;let c=[];b.ondataavailable=a=>{a.data.size>0&&c.push(a.data)},b.onstop=()=>{let d=new Blob(c,{type:b.mimeType}),e=new FileReader;e.onloadend=()=>{try{let a=e.result,c=a.indexOf(","),d=a.substring(c+1),f=b.mimeType||"audio/webm",g={"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"}[f]||f.split("/")[1]||"webm";q({base64:d,mimeType:f,filename:`recording.${g}`})}catch(a){am("Failed to process audio recording. Please try again."),q(null)}},e.readAsDataURL(d),a.getTracks().forEach(a=>a.stop())},b.start(),w(!0)}catch(a){am("Failed to start audio recording. Please check microphone permissions.")}};return h.length,(0,d.jsxs)("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[K&&(0,d.jsxs)(aO.Fc,{variant:"destructive",className:"mb-2",children:[(0,d.jsx)(bc.A,{className:"h-4 w-4"}),(0,d.jsxs)(aO.TN,{className:"flex items-center justify-between",children:[(0,d.jsx)("span",{children:K}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>L(null),className:"h-auto p-1 ml-2",children:(0,d.jsx)(p.A,{className:"h-3 w-3"})})]})]}),M&&(0,d.jsxs)(aO.Fc,{variant:"destructive",className:"mb-2",children:[(0,d.jsx)(bc.A,{className:"h-4 w-4"}),(0,d.jsxs)(aO.TN,{className:"flex items-center justify-between",children:[(0,d.jsx)("span",{children:M}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>P(null),className:"h-auto p-1 ml-2",children:(0,d.jsx)(p.A,{className:"h-3 w-3"})})]})]}),(0,d.jsxs)("div",{className:"w-full",children:[(0,d.jsx)("form",{onSubmit:a=>{a.preventDefault(),aq()},children:(0,d.jsxs)(at,{children:[(m||o)&&(0,d.jsx)("div",{className:"px-4 pt-4",children:(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[m&&(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-1 bg-muted/50 group",children:[(0,d.jsx)("img",{src:`data:${m.mimeType};base64,${m.base64}`,alt:"preview",className:"h-12 w-auto rounded-md"}),(0,d.jsx)(x.$,{variant:"destructive",size:"icon",onClick:()=>n(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,d.jsx)(p.A,{className:"h-2 w-2"})})]}),o&&(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[o.mimeType.startsWith("audio")?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(0,d.jsx)("audio",{controls:!0,src:`data:${o.mimeType};base64,${o.base64}`,className:"h-8"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Q.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"text-xs font-medium max-w-[160px] truncate",children:o.filename||"attachment"})]}),(0,d.jsx)(x.$,{variant:"destructive",size:"icon",onClick:()=>q(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,d.jsx)(p.A,{className:"h-2 w-2"})})]})]})}),(0,d.jsxs)("div",{className:"flex-auto overflow-y-auto relative",children:[u?(0,d.jsx)(as.A,{ref:l,value:h,onChange:aA,onKeyDown:ar,onPaste:aB,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,d.jsx)("textarea",{ref:l,rows:1,value:h,onChange:aA,onKeyDown:ar,onPaste:aB,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"}),Y&&aa&&!1,av&&ax&&!1]}),(0,d.jsx)(bg,{isVisible:ad,searchQuery:h,onSelectPrompt:a=>{let b=`/${a.name}`;k(b),ae(!1),l.current&&(l.current.focus(),l.current.setSelectionRange(b.length,b.length))},onClose:()=>{ae(!1)},onCreatePrompt:an,refreshKey:ai}),(0,d.jsx)(au,{leftButtons:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(aI,{onImageAttach:()=>r.current?.click(),onPdfAttach:()=>s.current?.click(),onAudioAttach:()=>t.current?.click(),supports:{image:R.length?R.includes("image"):void 0,pdf:R.length?R.includes("pdf"):void 0,audio:R.length?R.includes("audio"):void 0}}),(0,d.jsx)(aL,{isRecording:v,onToggleRecording:v?()=>{y.current?.stop(),w(!1)}:aC,disabled:!R.includes("audio")})]}),rightButtons:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("div",{className:"hidden md:block",children:(0,d.jsx)(ay,{isStreaming:B,onStreamingChange:C})}),(0,d.jsx)(bb,{}),(0,d.jsx)(x.$,{type:E?"button":"submit",onClick:E?()=>D(z||void 0):void 0,disabled:!E&&(!h.trim()&&!m&&!o||b),className:(0,j.cn)("h-10 w-10 p-0 rounded-full transition-all duration-200",E?"bg-secondary/80 text-secondary-foreground hover:bg-secondary shadow-sm hover:shadow-md border border-border/50":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-lg"),"aria-label":E?"Stop":"Send message",title:E?"Stop":"Send",children:E?(0,d.jsx)(A.A,{className:"h-3.5 w-3.5 fill-current"}):b?(0,d.jsx)(N.A,{className:"h-4 w-4 animate-spin"}):(0,d.jsx)(bd.A,{className:"h-4 w-4"})})]})})]})}),(0,d.jsx)("input",{ref:r,type:"file",id:"image-upload",accept:"image/*",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){am("Image file too large. Maximum size is 64MB."),a.target.value="";return}if(!b.type.startsWith("image/")){am("Please select a valid image file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(",");if(-1===d)throw Error("Invalid Data URL format");let e=a.substring(0,d),f=a.substring(d+1),g=e.match(/data:(.*);base64/),h=g?g[1]:b.type;if(!h)throw Error("Could not determine MIME type");n({base64:f,mimeType:h}),P(null)}catch(a){am("Failed to process image file. Please try again."),n(null)}},c.onerror=a=>{am("Failed to read image file. Please try again."),n(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)("input",{ref:s,type:"file",id:"pdf-upload",accept:"application/pdf",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){am("PDF file too large. Maximum size is 64MB."),a.target.value="";return}if("application/pdf"!==b.type){am("Please select a valid PDF file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(","),e=a.substring(d+1);q({base64:e,mimeType:"application/pdf",filename:b.name}),P(null)}catch(a){am("Failed to process PDF file. Please try again."),q(null)}},c.onerror=a=>{am("Failed to read PDF file. Please try again."),q(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)("input",{ref:t,type:"file",id:"audio-upload",accept:"audio/*",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){am("Audio file too large. Maximum size is 64MB."),a.target.value="";return}if(!b.type.startsWith("audio/")){am("Please select a valid audio file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(","),e=a.substring(d+1);q({base64:e,mimeType:b.type,filename:b.name}),P(null)}catch(a){am("Failed to process audio file. Please try again."),q(null)}},c.onerror=a=>{am("Failed to read audio file. Please try again."),q(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)(bl,{open:af,onClose:ap,onCreated:ao}),(0,d.jsx)(bm,{open:ak,onClose:()=>al(!1),onSuccess:()=>{}})]})]})}var bo=c(24617);let bp=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"]}]');class bq{constructor(){this.registryEntries=[],this.isInitialized=!1}static normalizeId(a){return a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return bq.instance||(bq.instance=new bq),bq.instance}async initialize(){this.isInitialized||(this.registryEntries=this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(a){await this.initialize();let b=[...this.registryEntries];if(a?.category&&(b=b.filter(b=>b.category===a.category)),a?.tags?.length&&(b=b.filter(b=>a.tags.some(a=>b.tags.includes(a)))),a?.search){let c=a.search.toLowerCase();b=b.filter(a=>a.name.toLowerCase().includes(c)||a.description.toLowerCase().includes(c)||a.tags.some(a=>a.toLowerCase().includes(c)))}return a?.installed!==void 0&&(b=b.filter(b=>b.isInstalled===a.installed)),a?.official!==void 0&&(b=b.filter(b=>b.isOfficial===a.official)),b.sort((a,b)=>a.isInstalled!==b.isInstalled?a.isInstalled?-1:1:a.isOfficial!==b.isOfficial?a.isOfficial?-1:1:a.name.localeCompare(b.name))}async updateEntry(a,b){let c=this.registryEntries.findIndex(b=>b.id===a);return -1!==c&&(this.registryEntries[c]={...this.registryEntries[c],...b},!0)}async setInstalled(a,b){return this.updateEntry(a,{isInstalled:b})}async syncWithServerStatus(){try{if(await this.initialize(),0===this.registryEntries.length)return void console.warn("Registry entries not available for status sync");let a=new AbortController,b=setTimeout(()=>a.abort(),1e4),c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{signal:a.signal});if(clearTimeout(b),!c.ok)return;let d=(await c.json()).servers||[],e=new Set;for(let a of(d.forEach(a=>{if(!a?.id||"string"!=typeof a.id)return;let b=bq.normalizeId(a.id);e.add(b)}),this.registryEntries)){let b=[a.id,a.name,...a.matchIds||[]].filter(Boolean).map(a=>bq.normalizeId(String(a))).some(a=>e.has(a));a.isInstalled!==b&&(a.isInstalled=b)}}catch(a){console.warn("Failed to sync registry with server status:",a)}}async getServerConfig(a){return await this.initialize(),this.registryEntries.find(b=>b.id===a)||null}getBuiltinEntries(){return bp}}let br=bq.getInstance();function bs({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card",className:(0,j.cn)("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...b})}function bt({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-header",className:(0,j.cn)("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...b})}function bu({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-title",className:(0,j.cn)("leading-none font-semibold",a),...b})}function bv({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-content",className:(0,j.cn)("px-6",a),...b})}var bw=c(52679),bx=c(76021),by=c(53801),bz=c(75116),bA=c(10362),bB=c(39612);function bC({isOpen:a,onClose:b,onInstallServer:c,onOpenConnectModal:f,refreshTrigger:g,disableClose:h=!1}){let[i,k]=(0,e.useState)([]),[l,m]=(0,e.useState)([]),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(null),[w,y]=(0,e.useState)({}),[z,A]=(0,e.useState)(""),[B,C]=(0,e.useState)("grid"),[D,E]=(0,e.useState)(null);(0,e.useRef)(null);let F=(0,e.useRef)(!0);(0,e.useRef)(null),(0,e.useCallback)(async(a,b)=>{if(F.current)try{let c=await br.getEntries({...a,search:b||void 0});F.current&&m(c)}catch(a){F.current&&t(a instanceof Error?a.message:"Failed to filter entries")}},[]);let G=async a=>{if(F.current){v(a.id);try{let b=await c(a);"connected"===b?(await br.setInstalled(a.id,!0),F.current&&(k(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!0}:b)),m(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!0}:b)))):F.current&&(k(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!1}:b)),m(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!1}:b)))}catch(a){F.current&&t(a instanceof Error?a.message:"Failed to install server")}finally{F.current&&v(null)}}},H=a=>{let b={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 b[a]||b.custom},I=h||!!u,J=(0,e.useCallback)(a=>{a||I||b()},[I,b]),K=I?a=>{a.preventDefault()}:void 0;return(0,d.jsx)(aN.lG,{open:a,onOpenChange:J,children:(0,d.jsxs)(aN.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:I?a=>a.preventDefault():void 0,onInteractOutside:K,children:[(0,d.jsx)(aN.c7,{className:"pb-4 border-b px-6 pt-5 bg-gradient-to-r from-muted/30 via-transparent to-transparent",children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:(0,d.jsx)(bw.A,{className:"h-5 w-5 text-primary"})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)(aN.L3,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),(0,d.jsx)(aN.rr,{className:"text-sm text-muted-foreground",children:"Discover and add integrations to your AI assistant"})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)(x.$,{onClick:()=>{I||b(),f?.()},size:"sm",variant:"outline",className:"h-8 px-3 text-sm font-medium hover:bg-muted whitespace-nowrap",children:[(0,d.jsx)(bx.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),(0,d.jsxs)(x.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(),disabled:I,children:[(0,d.jsx)(p.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}),(0,d.jsxs)("div",{className:"flex gap-3 mb-5 px-6 pt-5",children:[(0,d.jsxs)("div",{className:"relative flex-1",children:[(0,d.jsx)(aV.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,d.jsx)(aP.p,{placeholder:"Search servers and integrations...",value:z,onChange:a=>A(a.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,d.jsxs)("div",{className:"flex bg-muted/50 rounded-md p-1 border",children:[(0,d.jsxs)(x.$,{variant:"grid"===B?"secondary":"ghost",size:"sm",onClick:()=>{C("grid"),E(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","grid"===B?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,d.jsx)(by.A,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),(0,d.jsxs)(x.$,{variant:"list"===B?"secondary":"ghost",size:"sm",onClick:()=>{C("list"),E(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","list"===B?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,d.jsx)(bz.A,{className:"h-3.5 w-3.5 mr-1.5"}),"List"]})]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:[s&&(0,d.jsx)(aO.Fc,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:(0,d.jsx)(aO.TN,{className:"text-red-800 font-medium",children:s})}),q?(0,d.jsx)("div",{className:"flex items-center justify-center py-24",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-5",children:[(0,d.jsx)("div",{className:"h-12 w-12 border-4 border-primary/30 border-t-primary rounded-full animate-spin"}),(0,d.jsx)("div",{className:"text-lg text-foreground font-semibold",children:"Discovering servers..."}),(0,d.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading registry entries"})]})}):0===l.length?(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[(0,d.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,d.jsx)(bw.A,{className:"h-14 w-14 text-muted-foreground/60 mx-auto"})}),(0,d.jsx)("div",{className:"text-xl font-bold text-foreground mb-3",children:0===i.length?"No servers available in the registry":"No servers match your search"}),(0,d.jsx)("div",{className:"text-base text-muted-foreground/80 mb-6 max-w-md",children:0===i.length?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),z&&(0,d.jsxs)(x.$,{variant:"outline",onClick:()=>A(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[(0,d.jsx)(aV.A,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):(0,d.jsx)("div",{className:(0,j.cn)("grid"===B?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:l.map((a,b)=>{let c=D===a.id,e=a.description&&a.description.length>100;return"grid"===B?(0,d.jsx)(bs,{className:(0,j.cn)("group relative overflow-hidden transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-lg hover:border-primary/30 flex flex-col",c&&"ring-1 ring-primary/20 border-primary/40 shadow-lg -translate-y-0.5"),style:{animationDelay:`${Math.min(30*b,300)}ms`},children:(0,d.jsxs)("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>E(c?null:a.id),children:[(0,d.jsx)(bt,{className:"pb-3 flex-shrink-0",children:(0,d.jsxs)("div",{className:"flex items-start gap-3 mb-3",children:[(0,d.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,d.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:a.icon||"⚡"}),a.isInstalled&&(0,d.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,d.jsx)(M.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)(bu,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-snug line-clamp-2",children:a.name}),(0,d.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.isOfficial&&(0,d.jsxs)(aX.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,d.jsx)(aT.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),a.category&&(0,d.jsx)(aX.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",H(a.category)),children:a.category})]})]})]})}),(0,d.jsxs)(bv,{className:"pt-0 flex flex-col flex-1",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",c?"":"line-clamp-3"),children:a.description}),c&&(0,d.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:[a.author&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,d.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,d.jsx)(bA.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,d.jsxs)("div",{children:[(0,d.jsx)("span",{className:"text-muted-foreground/70",children:"by "}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:a.author})]})]}),a.tags&&a.tags.length>0&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,6).map(a=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:a},a)),a.tags.length>6&&(0,d.jsxs)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20",children:["+",a.tags.length-6]})]}),a.homepage&&(0,d.jsxs)("a",{href:a.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)(bB.A,{className:"h-3 w-3"}),"Documentation"]})]})]}),(0,d.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border/30 flex-shrink-0 mt-auto",children:[e&&(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-foreground p-0 h-auto font-medium -ml-1",children:c?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(n.A,{className:"h-3 w-3 mr-1"}),"Less"]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.A,{className:"h-3 w-3 mr-1"}),"More"]})}),(0,d.jsx)("div",{className:"ml-auto",children:(0,d.jsx)(x.$,{onClick:b=>{b.stopPropagation(),G(a)},disabled:a.isInstalled||u===a.id,size:"sm",variant:a.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 transition-all font-semibold text-sm shadow-sm",u===a.id&&"opacity-70",a.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!a.isInstalled&&"bg-primary hover:bg-primary/90"),children:u===a.id?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,d.jsx)("span",{children:"Adding"})]}):a.isInstalled?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(M.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Added"})]}):(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(aU.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Add"})]})})})]})]})]})},a.id):(0,d.jsx)(bs,{className:(0,j.cn)("group transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-md hover:border-primary/30 cursor-pointer !py-0 !gap-0",c&&"border-primary/40 shadow-md -translate-y-0.5"),onClick:()=>E(c?null:a.id),children:(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)("div",{className:"flex items-start gap-4",children:[(0,d.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,d.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:a.icon||"⚡"}),a.isInstalled&&(0,d.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,d.jsx)(M.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-0 space-y-2.5",children:[(0,d.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,d.jsx)("h3",{className:"text-base font-semibold text-foreground group-hover:text-primary transition-colors leading-snug",children:a.name}),e&&(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",c&&"rotate-180 text-muted-foreground")})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.isOfficial&&(0,d.jsxs)(aX.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,d.jsx)(aT.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),a.category&&(0,d.jsx)(aX.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",H(a.category)),children:a.category})]})]}),(0,d.jsx)(x.$,{onClick:b=>{b.stopPropagation(),G(a)},disabled:a.isInstalled||u===a.id,size:"sm",variant:a.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",u===a.id&&"opacity-70",a.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!a.isInstalled&&"bg-primary hover:bg-primary/90"),children:u===a.id?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,d.jsx)("span",{children:"Adding"})]}):a.isInstalled?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(M.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Added"})]}):(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(aU.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Add"})]})})]}),(0,d.jsx)("div",{children:(0,d.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",c?"":"line-clamp-2"),children:a.description})}),c&&(0,d.jsxs)("div",{className:"space-y-3 pt-3 border-t border-border/30 animate-in slide-in-from-top-2 duration-200",children:[a.author&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,d.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,d.jsx)(bA.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,d.jsxs)("div",{children:[(0,d.jsx)("span",{className:"text-muted-foreground/70",children:"by "}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:a.author})]})]}),a.tags&&a.tags.length>0&&(0,d.jsx)("div",{className:"flex flex-wrap gap-1.5",children:a.tags.map(a=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:a},a))}),a.homepage&&(0,d.jsxs)("a",{href:a.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)(bB.A,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},a.id)})})]})]})})}var bD=c(66180),bE=c(81202),bF=c(99330),bG=c(41508);let bH=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),bI=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],bJ=[/^your[\s_-]?/,/^enter[\s_-]?/];function bK(a){return Object.values(a).some(a=>{if(!a||""===a.trim())return!0;let b=a.trim().toLowerCase();return!!(bH.has(b)||bJ.some(a=>a.test(b)))||bI.some(a=>b.includes(a))})}function bL(a){let b=a.config.timeout??3e4;switch(a.config.type){case"stdio":return{type:"stdio",command:a.config.command??"",args:a.config.args??[],env:a.config.env??{},timeout:b,connectionMode:"lenient"};case"sse":return{type:"sse",url:a.config.url??"",headers:a.config.headers??{},timeout:b,connectionMode:"lenient"};default:return{type:"http",url:a.config.url??"",headers:a.config.headers??{},timeout:b,connectionMode:"lenient"}}}let bM=`${(0,g.e)()}/api`;function bN({isOpen:a,onClose:b,onOpenConnectModal:c,onOpenConnectWithPrefill:f,onServerConnected:h,variant:i,refreshTrigger:k}){let[l,n]=(0,e.useState)([]),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[y,z]=(0,e.useState)(!1),[A,B]=(0,e.useState)(!1),[C,D]=(0,e.useState)(null),[E,F]=(0,e.useState)(null),[G,H]=(0,e.useState)(!1),[I,J]=(0,e.useState)(null),[K,L]=(0,e.useState)(null),[M,N]=(0,e.useState)(!1),[O,P]=(0,e.useState)(!1),Q=(a,b)=>{console.error(`ServersPanel Error (${b}):`,a),"servers"===b&&D(a),"tools"===b&&F(a)},R=(0,e.useCallback)(async a=>{z(!0),D(null),n([]),r(null),t([]),F(null);try{let b=await fetch(`${bM}/mcp/servers`,a?{signal:a}:{});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to fetch servers"}));throw Error(a.message||a.error||`Server List: ${b.statusText}`)}let c=(await b.json()).servers||[];if(n(c),c.length>0){let a=c.find(a=>"connected"===a.status);a?r(a.id):c.length>0&&r(c[0].id)}else console.log("No MCP servers found or returned from API.")}catch(a){"AbortError"!==a.name&&Q(a.message,"servers")}finally{a?.aborted||z(!1)}},[]),S=async a=>{let b=bL(a),c="stdio"===b.type&&Object.keys(b.env||{}).length>0&&bK(b.env||{}),d=("sse"===b.type||"http"===b.type)&&Object.keys(b.headers||{}).length>0&&bK(b.headers||{});if(c||d)return"function"==typeof f&&f({name:a.name,config:b,lockName:!0,registryEntryId:a.id,onCloseRegistryModal:()=>N(!1)}),"requires-input";try{P(!0);let c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,config:b,persistToAgent:!1})}),d=await c.json();if(!c.ok)throw Error(d.error||`Server returned status ${c.status}`);await R();try{await br.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry after server install:",a)}return N(!1),h?.(a.name),"connected"}catch(a){throw Error(a.message||"Failed to install server")}finally{P(!1)}},T=async a=>{let b=l.find(b=>b.id===a);if(b&&window.confirm(`Are you sure you want to remove server "${b.name}"?`)){J(a),D(null);try{let b=await fetch(`${bM}/mcp/servers/${a}`,{method:"DELETE"});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to remove server"}));throw Error(a.message||a.error||`Server Removal: ${b.statusText}`)}q===a&&(r(null),t([]));try{let b=a=>a.toLowerCase().replace(/[^a-z0-9]+/g,"-"),c=b(a),d=(await br.getEntries()).find(a=>[a.id,a.name,...a.matchIds||[]].filter(Boolean).map(a=>b(String(a))).includes(c));d&&await br.setInstalled(d.id,!1)}catch(a){console.warn("Failed to update registry installed state on delete:",a)}await R(),(0,be.w)();try{await br.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry status after server deletion:",a)}}catch(a){Q(a.message,"servers")}finally{J(null)}}},U=async a=>{let b=l.find(b=>b.id===a);if(b&&window.confirm(`Restart server "${b.name}"?`)){L(a),D(null);try{let b=await fetch(`${bM}/mcp/servers/${a}/restart`,{method:"POST"});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to restart server"}));throw Error(a.message||a.error||`Server Restart: ${b.statusText}`)}await R(),(0,be.w)();try{await br.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry status after server restart:",a)}}catch(a){Q(a.message,"servers")}finally{L(null)}}};(0,e.useCallback)(async(a,b)=>{let c=l.find(b=>b.id===a);if(t([]),F(null),!c||"connected"!==c.status)return void console.warn(`Server "${c?.name||a}" is not connected or not found. Cannot fetch tools.`);B(!0);try{let d=await fetch(`${bM}/mcp/servers/${a}/tools`,b?{signal:b}:{});if(!d.ok){let a=await d.json().catch(()=>({error:`Failed to fetch tools for ${c.name}`}));throw Error(a.message||a.error||`Tool List (${c.name}): ${d.statusText}`)}let e=await d.json();b?.aborted||t(e.tools||[]),e.tools&&0!==e.tools.length||console.log(`No tools found for server "${c.name}".`)}catch(a){"AbortError"!==a.name&&Q(a.message,"tools")}finally{b?.aborted||B(!1)}},[l]);let V=l.find(a=>a.id===q);return"inline"===(i??"overlay")?(0,d.jsxs)("aside",{className:"h-full w-full flex flex-col bg-card",children:[(0,d.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,d.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,d.jsx)("div",{className:"flex items-center space-x-1",children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>R(),disabled:y,className:"h-8 w-8 p-0",children:(0,d.jsx)(bD.A,{className:(0,j.cn)("h-3.5 w-3.5",y&&"animate-spin")})})})]}),(0,d.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,d.jsxs)(x.$,{onClick:()=>N(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,d.jsx)(bE.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,d.jsxs)(x.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,d.jsx)(aY.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,d.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",l.length,")"]})}),y&&(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bD.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),C&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:C})]})]})}),!y&&0===l.length&&!C&&(0,d.jsxs)("div",{className:"text-center py-8",children:[(0,d.jsx)(bw.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),l.map(a=>(0,d.jsx)("div",{onClick:()=>r(a.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",q===a.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===a.status?"bg-green-500":"error"===a.status?"bg-red-500":"bg-yellow-500")}),(0,d.jsx)("h4",{className:"text-sm font-medium truncate",children:a.name})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:a.status})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[K===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Restarting ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),U(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":`Restart server ${a.name}`,disabled:I===a.id,children:(0,d.jsx)(bF.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Restart server"})]}),I===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Removing ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),T(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":`Remove server ${a.name}`,disabled:K===a.id,children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Remove server"})]})]})]})},a.id))]}),V&&(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,d.jsxs)("button",{onClick:()=>H(!G),className:"flex items-center justify-between w-full text-left",children:[(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Available Tools ",s.length>0&&`(${s.length})`]}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",G&&"rotate-180")})]})}),G&&(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[A&&(0,d.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),E&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:E})]})]})}),!A&&0===s.length&&!E&&"connected"===V.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(bG.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==V.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(m.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),s.map(a=>(0,d.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,d.jsx)("h4",{className:"text-sm font-medium mb-1",children:a.name}),a.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:a.description}),a.inputSchema?.properties&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(a.inputSchema.properties).slice(0,3).map(a=>(0,d.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:a},a)),Object.keys(a.inputSchema.properties).length>3&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(a.inputSchema.properties).length-3," more"]})]})]},a.name))]})]})]}),(0,d.jsx)(bC,{isOpen:M,onClose:()=>N(!1),onInstallServer:S,onOpenConnectModal:c,disableClose:O})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",a?"opacity-100":"opacity-0 pointer-events-none"),onClick:b}),(0,d.jsxs)("aside",{className:(0,j.cn)("fixed top-0 right-0 z-40 h-screen w-80 bg-card border-l border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",a?"translate-x-0":"translate-x-full"),children:[(0,d.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,d.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,d.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>R(),disabled:y,className:"h-8 w-8 p-0",children:(0,d.jsx)(bD.A,{className:(0,j.cn)("h-3.5 w-3.5",y&&"animate-spin")})}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b,className:"h-8 w-8 p-0",children:(0,d.jsx)(p.A,{className:"h-3.5 w-3.5"})})]})]}),(0,d.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,d.jsxs)(x.$,{onClick:()=>N(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,d.jsx)(bE.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,d.jsxs)(x.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,d.jsx)(aY.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,d.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",l.length,")"]})}),y&&(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bD.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),C&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:C})]})]})}),!y&&0===l.length&&!C&&(0,d.jsxs)("div",{className:"text-center py-8",children:[(0,d.jsx)(bw.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),l.map(a=>(0,d.jsx)("div",{onClick:()=>r(a.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",q===a.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===a.status?"bg-green-500":"error"===a.status?"bg-red-500":"bg-yellow-500")}),(0,d.jsx)("h4",{className:"text-sm font-medium truncate",children:a.name})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:a.status})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[K===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Restarting ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),U(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":`Restart server ${a.name}`,disabled:I===a.id,children:(0,d.jsx)(bF.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Restart server"})]}),I===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Removing ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),T(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":`Remove server ${a.name}`,disabled:K===a.id,children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Remove server"})]})]})]})},a.id))]}),V&&(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,d.jsxs)("button",{onClick:()=>H(!G),className:"flex items-center justify-between w-full text-left",children:[(0,d.jsx)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Available Tools"}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",G&&"rotate-180")})]})}),G&&(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[A&&(0,d.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bD.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),E&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:E})]})]})}),!A&&0===s.length&&!E&&"connected"===V.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(bG.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==V.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(m.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),s.map(a=>(0,d.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,d.jsx)("h4",{className:"text-sm font-medium mb-1",children:a.name}),a.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:a.description}),a.inputSchema?.properties&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(a.inputSchema.properties).slice(0,3).map(a=>(0,d.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:a},a)),Object.keys(a.inputSchema.properties).length>3&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(a.inputSchema.properties).length-3," more"]})]})]},a.name))]})]})]}),(0,d.jsx)(bC,{isOpen:M,onClose:()=>N(!1),onInstallServer:S,onOpenConnectModal:c,disableClose:O})]})]})}var bO=c(32542),bP=c(35966);let bQ=function({onClick:a,className:b,variant:c="outline",side:e="bottom"}){return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:c,size:"sm",onClick:a,className:["h-8 w-8 p-0",b].filter(Boolean).join(" "),"aria-label":"New chat",children:(0,d.jsx)(aU.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{side:e,children:"New Chat (⌘K)"})]})})};function bR({isOpen:a,onClose:b,currentSessionId:c,onSessionChange:h,returnToWelcome:i,variant:k="overlay",onSearchOpen:l,onNewChat:n}){let[o,q]=(0,e.useState)([]),[r,s]=(0,e.useState)(!1),[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(!1),[C,D]=(0,e.useState)(""),[E,F]=(0,e.useState)(null),G=f().useRef(!1),H=f().useRef(0),I=f().useRef(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),[N,O]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{if(G.current)return;H.current+=1;let a=H.current;I.current||s(!0),z(null);try{let b,c=await fetch(`${(0,g.e)()}/api/sessions`);if(!c.ok)throw Error("Failed to fetch sessions");let d=await c.text();if(a!==H.current)return;if(!d.trim())return void q([]);try{b=JSON.parse(d)}catch(a){console.error("Failed to parse sessions response:",a),z("Failed to parse sessions data");return}let e=(b.sessions||[]).sort((a,b)=>{let c=a.lastActivity?new Date(a.lastActivity).getTime():0;return(b.lastActivity?new Date(b.lastActivity).getTime():0)-c});a===H.current&&(q(e),I.current=!0)}catch(b){a===H.current&&(console.error("Error fetching sessions:",b),z(b instanceof Error?b.message:"Failed to fetch sessions"))}finally{a===H.current&&(s(!1),I.current=!0)}},[]);let P=async()=>{try{let a,b=await fetch(`${(0,g.e)()}/api/sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:C.trim()||void 0})});if(!b.ok){let a,c=await b.text();try{a=c?JSON.parse(c):{}}catch{a={error:"Failed to create session"}}throw Error(a.error||"Failed to create session")}let c=await b.text();if(!c.trim())throw Error("Empty response from session creation");try{a=JSON.parse(c)}catch(a){throw console.error("Failed to parse session creation response:",a),Error("Invalid response from session creation")}q(b=>[...b,a.session]),D(""),B(!1),h(a.session.id)}catch(a){console.error("Error creating session:",a),z(a instanceof Error?a.message:"Failed to create session")}},Q=async a=>{let b=c===a;G.current=!0,F(a);try{let c=await fetch(`${(0,g.e)()}/api/sessions/${a}`,{method:"DELETE"});if(!c.ok){let a,b=await c.text();try{a=b?JSON.parse(b):{}}catch{a={error:"Failed to delete session"}}throw Error(a.error||"Failed to delete session")}q(b=>b.filter(b=>b.id!==a)),b&&i(),await new Promise(a=>setTimeout(a,100))}catch(a){console.error("Error deleting session:",a),z(a instanceof Error?a.message:"Failed to delete session")}finally{G.current=!1,F(null)}},R=async()=>{if(!L)return;let a=c===L;G.current=!0,O(!0);try{if(!(await fetch(`${(0,g.e)()}/api/sessions/${L}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok)throw Error("Failed to delete conversation");q(a=>a.filter(a=>a.id!==L)),a&&i(),K(!1),M(null),await new Promise(a=>setTimeout(a,100))}catch(a){console.error("Error deleting conversation:",a),z(a instanceof Error?a.message:"Failed to delete conversation")}finally{G.current=!1,O(!1)}},S=(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:[(0,d.jsx)("div",{className:"flex items-center space-x-2",children:(0,d.jsx)("h2",{id:"sessionpanel-title",className:"text-base font-semibold",children:"Chat History"})}),(0,d.jsxs)("div",{className:"flex items-center space-x-1",children:[l&&(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:l,className:"h-7 w-7 p-0","aria-label":"Search conversations",children:(0,d.jsx)(aV.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Search conversations (⌘⇧S)"})]})}),n&&(0,d.jsx)(bQ,{onClick:n,variant:"outline"}),"overlay"===k&&(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b,className:"h-7 w-7 p-0","aria-label":"Close panel",children:(0,d.jsx)(p.A,{className:"h-3.5 w-3.5"})})]})]}),y&&(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:y})]})}),(0,d.jsx)(bO.F,{className:"flex-1",children:r?(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsx)(bD.A,{className:"h-6 w-6 animate-spin"})}):0===o.length?(0,d.jsxs)("div",{className:"text-center py-8 text-muted-foreground px-4",children:[(0,d.jsx)(bP.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,d.jsx)("p",{children:"No chat history"}),(0,d.jsx)("p",{className:"text-sm",children:"Start a conversation to see it here"})]}):(0,d.jsx)("div",{className:"px-3 py-2 space-y-0.5",children:(0,d.jsx)(t,{children:o.map(a=>{let b=a.title&&a.title.trim().length>0?a.title:a.id,e=c===a.id;return(0,d.jsxs)(u,{delayDuration:150,children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:e?"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":e?"page":void 0,onClick:()=>h(a.id),onKeyDown:b=>{("Enter"===b.key||" "===b.key)&&(b.preventDefault(),h(a.id))},children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,d.jsx)("div",{className:"flex items-center gap-2.5 flex-1 min-w-0",children:(0,d.jsx)("h3",{className:e?"font-semibold text-sm truncate":"font-normal text-sm truncate text-muted-foreground",children:b})}),(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:(a=>{if(!a)return"Unknown";let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"Just now":d<60?`${d}m ago`:e<24?`${e}h ago`:`${f}d ago`})(a.lastActivity)}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),a.messageCount>0?(M(a.id),K(!0)):Q(a.id)},disabled:E===a.id,className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":a.messageCount>0?"Delete conversation":"Delete chat",title:"Delete",children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"})})]})]})})}),(0,d.jsx)(w,{side:"right",align:"center",children:(0,d.jsxs)("div",{className:"text-xs space-y-1",children:[(0,d.jsx)("div",{className:"font-mono",children:a.id}),(0,d.jsxs)("div",{className:"text-muted-foreground",children:[a.messageCount," messages"]})]})})]},a.id)})})})}),(0,d.jsx)(aN.lG,{open:A,onOpenChange:B,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsx)(aN.L3,{children:"Start New Chat"})}),(0,d.jsx)("div",{className:"space-y-4",children:(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"sessionId",children:"Chat ID"}),(0,d.jsx)(aP.p,{id:"sessionId",value:C,onChange:a=>D(a.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>B(!1),children:"Cancel"}),(0,d.jsx)(x.$,{onClick:P,children:"Start Chat"})]})]})}),(0,d.jsx)(aN.lG,{open:J,onOpenChange:K,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Conversation"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",L&&(0,d.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,d.jsx)("span",{className:"font-mono",children:L})]})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>K(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:R,disabled:N,className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:N?"Deleting...":"Delete Conversation"})]})]})]})})]});return"inline"===k?(0,d.jsx)("div",{className:"h-full w-full flex flex-col bg-card",children:S}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",a?"opacity-100":"opacity-0 pointer-events-none"),onClick:b}),(0,d.jsx)("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:(0,j.cn)("fixed top-0 left-0 z-40 h-screen w-80 bg-card border-r border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",a?"translate-x-0":"-translate-x-full"),children:S})]})}var bS=c(26178),bT=c(10194);function bU({isOpen:a,onClose:b,variant:c="modal"}){let[f,h]=(0,e.useState)([]),[i,k]=(0,e.useState)(!1),[l,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(null),[s,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(!1),[B,C]=(0,e.useState)(null),D=(0,e.useCallback)(async()=>{k(!0),n(null);try{let a=await fetch(`${(0,g.e)()}/api/memory`);if(!a.ok)throw Error("Failed to fetch memories");let b=await a.json();h(b.memories||[])}catch(a){console.error("Error fetching memories:",a),n(a instanceof Error?a.message:"Failed to fetch memories")}finally{k(!1)}},[]),E=async a=>{r(a);try{let b=await fetch(`${(0,g.e)()}/api/memory/${a}`,{method:"DELETE"});if(!b.ok){let a=await b.json();throw Error(a.error||"Failed to delete memory")}h(b=>b.filter(b=>b.id!==a)),A(!1),C(null)}catch(a){console.error("Error deleting memory:",a),n(a instanceof Error?a.message:"Failed to delete memory")}finally{r(null)}},F=(a,b=120)=>a.length<=b?a:a.slice(0,b)+"...",G=f.filter(a=>{if(!o.trim())return!0;let b=o.toLowerCase();return a.content.toLowerCase().includes(b)||a.tags?.some(a=>a.toLowerCase().includes(b))}),H=(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsx)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)(K.A,{className:"h-4 w-4"}),(0,d.jsx)("h2",{className:"text-base font-semibold",children:"Memories"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs",children:f.length})]})}),(0,d.jsx)("div",{className:"p-3 border-b border-border/50",children:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)("div",{className:"relative flex-1",children:[(0,d.jsx)(aV.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,d.jsx)(aP.p,{placeholder:"Search memories...",value:o,onChange:a=>p(a.target.value),className:"pl-8 h-8 text-sm"})]}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:()=>y(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:(0,d.jsx)(aU.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Create Memory"})]})})]})}),l&&(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:l})]})}),(0,d.jsx)(bO.F,{className:"flex-1 p-4",children:(0,d.jsx)("div",{className:"space-y-2",children:i?(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsx)(bD.A,{className:"h-6 w-6 animate-spin"})}):0===G.length?(0,d.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,d.jsx)(K.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),o.trim()?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("p",{children:"No memories found"}),(0,d.jsx)("p",{className:"text-sm",children:"Try a different search term"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("p",{children:"No memories yet"}),(0,d.jsx)("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):G.map(a=>(0,d.jsx)("div",{className:(0,j.cn)("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",a.metadata?.pinned&&"ring-1 ring-primary/30 bg-primary/5"),children:(0,d.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0 space-y-2",children:[(0,d.jsx)("p",{className:"text-sm leading-relaxed",children:F(a.content)}),a.tags&&a.tags.length>0&&(0,d.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,d.jsx)(bS.A,{className:"h-3 w-3 text-muted-foreground"}),a.tags.map((a,b)=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0",children:a},b))]}),(0,d.jsxs)("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(bT.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:(a=>{let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"Just now":d<60?`${d}m ago`:e<24?`${e}h ago`:`${f}d ago`})(a.updatedAt)})]}),a.metadata?.source&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:a.metadata.source}),a.metadata?.pinned&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),(0,d.jsx)("div",{className:"flex items-center gap-1",children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{C(a),A(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5 text-destructive"})})})]})},a.id))})}),(0,d.jsx)(bm,{open:s,onClose:()=>y(!1),onSuccess:()=>{D()}}),(0,d.jsx)(aN.lG,{open:z,onOpenChange:A,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Memory"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this memory. This action cannot be undone.",B&&(0,d.jsx)("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:F(B.content,100)})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:()=>B&&E(B.id),disabled:q===B?.id,className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:q===B?.id?"Deleting...":"Delete Memory"})]})]})]})})]});return"inline"===c?(0,d.jsx)("div",{className:"h-full",children:H}):(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[(0,d.jsx)(aN.c7,{className:"sr-only",children:(0,d.jsx)(aN.L3,{children:"Memories"})}),H]})})}function bV({websocket:a,onApprovalRequest:b,onApprove:c,onDeny:d,onHandlersReady:g}){let[h,j]=(0,e.useState)(null),{currentSessionId:k}=(0,i.v)(),l=f().useRef([]),m=(0,e.useCallback)((b,c,d)=>{if(!h||!a)return;let e="elicitation"===h.type?b&&c?{formData:c}:void 0:{rememberChoice:d??!1},f={type:"approvalResponse",data:{approvalId:h.approvalId,status:b?"approved":"denied",sessionId:h.sessionId,...e?{data:e}:{}}};if(console.debug(`[WebUI] Sending approvalResponse: ${JSON.stringify(f)}`),a.readyState!==WebSocket.OPEN)return void console.warn(`[WebUI] WebSocket not open (readyState: ${a.readyState}), cannot send approval response for ${h.approvalId}`);try{a.send(JSON.stringify(f))}catch(a){console.error(`[WebUI] Failed to send approval response: ${a instanceof Error?a.message:String(a)}`);return}if(j(null),l.current.length>0){let a=l.current.shift();setTimeout(()=>{j(a)},100)}},[h,a]);return(0,e.useCallback)((a,b)=>{m(!0,a,b),c?.(a,b)},[m,c]),(0,e.useCallback)(()=>{m(!1),d?.()},[m,d]),null}var bW=c(92829),bX=c(46309);function bY({isOpen:a,onClose:b,onNavigateToSession:c}){let[f,h]=(0,e.useState)(""),[i,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(!1),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(0);return(0,e.useCallback)(async a=>{if(!a.trim()){k([]),o(null);return}m(!0),o(null);try{let b=new URLSearchParams({q:a,limit:"10",offset:"0"}),c=await fetch(`${(0,g.e)()}/api/search/messages?${b}`);if(!c.ok){let a=await c.text();throw Error(`Search failed: ${c.status} ${a}`)}let d=await c.json();k(d.results),q(0)}catch(a){console.error("Search error:",a),k([]),o(a instanceof Error?a.message:"Search failed")}finally{m(!1)}},[]),(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"max-w-2xl p-0 top-[20%] transform translate-y-0",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsx)(aN.L3,{className:"sr-only",children:"Search Conversations"})}),(0,d.jsxs)("div",{className:"flex flex-col max-h-[70vh]",children:[(0,d.jsx)("div",{className:"p-6 pb-4",children:(0,d.jsxs)("div",{className:"relative",children:[(0,d.jsx)(aV.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),(0,d.jsx)(aP.p,{placeholder:"Search conversations...",value:f,onChange:a=>h(a.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),(0,d.jsx)("div",{className:"flex-1 overflow-hidden border-t",children:l?(0,d.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,d.jsx)(bD.A,{className:"h-6 w-6 animate-spin mr-3"}),(0,d.jsx)("span",{className:"text-muted-foreground",children:"Searching..."})]}):n?(0,d.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,d.jsxs)("div",{className:"text-center",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),(0,d.jsx)("p",{className:"text-destructive font-medium",children:"Search Error"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:n}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):(0,d.jsx)(bO.F,{className:"h-full",children:(0,d.jsx)("div",{className:"p-2",children:i.length>0?(0,d.jsx)("div",{className:"space-y-1",children:i.map((a,e)=>(0,d.jsxs)("div",{className:(0,j.cn)("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",e===p?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>{c(a.sessionId,a.messageIndex),b()},children:[(0,d.jsx)("div",{className:"flex-shrink-0 mt-1",children:(0,d.jsx)(aX.E,{className:(0,j.cn)("text-xs",(a=>{switch(a){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"}})(a.message.role)),children:(a=>{switch(a){case"user":return(0,d.jsx)(H.A,{className:"w-4 h-4"});case"assistant":return(0,d.jsx)(I.A,{className:"w-4 h-4"});case"system":return(0,d.jsx)(bW.A,{className:"w-4 h-4"});default:return(0,d.jsx)(bX.A,{className:"w-4 h-4"})}})(a.message.role)})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,d.jsx)("span",{className:"text-sm font-medium",children:a.sessionId.length>20?`${a.sessionId.slice(0,20)}...`:a.sessionId}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:a.message.role})]}),(0,d.jsx)("div",{className:"text-sm text-muted-foreground line-clamp-2",children:((a,b)=>{if(!b)return a;let c=b.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),e=RegExp(`(${c})`,"gi");return a.split(e).map((a,b)=>e.test(a)?(0,d.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:a},b):a)})(a.context,f)})]}),(0,d.jsx)(L.A,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},e))}):f?(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,d.jsx)("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,d.jsx)("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),(0,d.jsxs)("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↑"}),(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↓"}),(0,d.jsx)("span",{children:"to navigate"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Enter"}),(0,d.jsx)("span",{children:"to select"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Esc"}),(0,d.jsx)("span",{children:"to close"})]})]})]})})})})]})]})})}var bZ=c(47149),b$=c(24863);function b_({value:a,onChange:b,onValidate:c,readOnly:f=!1,height:g="100%"}){let h=(0,e.useRef)(null);return(0,d.jsx)(b$.Ay,{height:g,defaultLanguage:"yaml",value:a,onChange:a=>{void 0!==a&&b(a)},onMount:a=>{h.current=a,a.updateOptions({minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:"on",renderLineHighlight:"all",folding:!0,automaticLayout:!0})},theme:"vs-dark",options:{readOnly:f,wordWrap:"on",tabSize:2}})}function b0({isValidating:a,isValid:b,errors:c,warnings:e,hasUnsavedChanges:f}){return(0,d.jsxs)("div",{className:"border-t border-border bg-background px-4 py-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,d.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:a?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}),(0,d.jsx)("span",{className:"text-sm text-muted-foreground",children:"Validating..."})]}):b?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(M.A,{className:"h-4 w-4 text-green-500 flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Valid configuration",f&&" (unsaved changes)"]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(bc.A,{className:"h-4 w-4 text-destructive flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-destructive",children:[c.length," ",1===c.length?"error":"errors"]})]})}),e.length>0&&(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-yellow-500 flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-yellow-500",children:[e.length," ",1===e.length?"warning":"warnings"]})]})]}),c.length>0&&(0,d.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:c.map((a,b)=>(0,d.jsxs)("div",{className:"text-xs bg-destructive/10 text-destructive rounded px-2 py-1.5 flex items-start gap-2",children:[(0,d.jsx)(bc.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[a.path&&(0,d.jsxs)("span",{className:"font-medium",children:[a.path,": "]}),a.message,a.line&&(0,d.jsxs)("span",{className:"text-muted-foreground ml-1",children:["(line ",a.line,a.column&&`:${a.column}`,")"]})]})]},b))}),e.length>0&&0===c.length&&(0,d.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:e.map((a,b)=>(0,d.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,d.jsx)(m.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("span",{className:"font-medium",children:[a.path,": "]}),a.message]})]},b))})]})}function b1({value:a,onChange:b,onValidate:c,isValidating:e=!1,isValid:f=!0,errors:g=[],warnings:h=[],hasUnsavedChanges:i=!1}){return(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,d.jsx)(b_,{value:a,onChange:b,onValidate:c,height:"100%"})}),(0,d.jsx)(b0,{isValidating:e,isValid:f,errors:g,warnings:h,hasUnsavedChanges:i})]})}function b2({title:a,children:b,defaultOpen:c=!0,open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[],className:k}){let[l,m]=(0,e.useState)(c),n=void 0!==f,p=n?f:l;return(0,d.jsxs)("div",{className:(0,j.cn)("border border-border rounded-lg overflow-hidden",k),children:[(0,d.jsxs)("button",{onClick:()=>{let a=!p;n?g?.(a):m(a)},className:"w-full flex items-center justify-between px-4 py-3 bg-muted/50 hover:bg-muted transition-colors text-left",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium",children:a}),h>0&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.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:[h," ",1===h?"error":"errors"]})}),(0,d.jsx)(w,{side:"top",className:"max-w-sm",children:(0,d.jsx)("ul",{className:"space-y-1 text-left",children:i.map((a,b)=>(0,d.jsxs)("li",{children:["• ",a]},b))})})]})]}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-4 w-4 transition-transform duration-200",p&&"transform rotate-180")})]}),p&&(0,d.jsx)("div",{className:"px-4 py-4 space-y-4",children:b})]})}var b3=c(87431),b4=c(6515);let b5=["openai","openai-compatible","anthropic","google","groq","xai","cohere"],b6=["vercel","in-built"];function b7({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(!1),l=(c,d)=>{b({...a,[c]:d})};return(0,d.jsx)(b2,{title:"LLM Configuration",defaultOpen:!0,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"provider",tooltip:"The LLM provider to use (e.g., OpenAI, Anthropic)",children:"Provider *"}),(0,d.jsxs)("select",{id:"provider",value:a.provider||"",onChange:a=>l("provider",a.target.value),"aria-invalid":!!c["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,d.jsx)("option",{value:"",children:"Select provider..."}),b5.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]}),c["llm.provider"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.provider"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"model",tooltip:"The specific model identifier (e.g., gpt-5, claude-sonnet-4-5-20250929)",children:"Model *"}),(0,d.jsx)(aP.p,{id:"model",value:a.model||"",onChange:a=>l("model",a.target.value),placeholder:"e.g., gpt-5, claude-sonnet-4-5-20250929","aria-invalid":!!c["llm.model"]}),c["llm.model"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.model"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"apiKey",tooltip:"Use $ENV_VAR for environment variables or enter the API key directly",children:"API Key *"}),(0,d.jsxs)("div",{className:"relative",children:[(0,d.jsx)(aP.p,{id:"apiKey",type:j?"text":"password",value:a.apiKey??"",onChange:a=>l("apiKey",a.target.value),placeholder:"$OPENAI_API_KEY or direct value","aria-invalid":!!c["llm.apiKey"],className:"pr-10"}),(0,d.jsx)("button",{type:"button",onClick:()=>k(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-accent rounded transition-colors","aria-label":j?"Hide API key":"Show API key",children:j?(0,d.jsx)(b3.A,{className:"h-4 w-4 text-muted-foreground"}):(0,d.jsx)(b4.A,{className:"h-4 w-4 text-muted-foreground"})})]}),c["llm.apiKey"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.apiKey"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"router",tooltip:"LLM routing backend: 'vercel' uses Vercel AI SDK, 'in-built' uses provider-specific clients",children:"Router"}),(0,d.jsx)("select",{id:"router",value:a.router||"vercel",onChange:a=>l("router",a.target.value),"aria-invalid":!!c["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:b6.map(a=>(0,d.jsx)("option",{value:a,children:a},a))}),c["llm.router"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.router"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"maxIterations",tooltip:"Maximum number of agent reasoning iterations per turn",children:"Max Iterations"}),(0,d.jsx)(aP.p,{id:"maxIterations",type:"number",value:void 0!==a.maxIterations?a.maxIterations:"",onChange:a=>{let b=a.target.value;if(""===b)l("maxIterations",void 0);else{let a=parseInt(b,10);isNaN(a)||l("maxIterations",a)}},min:"1",placeholder:"50","aria-invalid":!!c["llm.maxIterations"]}),c["llm.maxIterations"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxIterations"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"baseURL",tooltip:"Custom base URL for the LLM provider (optional, for proxies or custom endpoints)",children:"Base URL"}),(0,d.jsx)(aP.p,{id:"baseURL",value:a.baseURL||"",onChange:a=>l("baseURL",a.target.value||void 0),placeholder:"https://api.openai.com/v1","aria-invalid":!!c["llm.baseURL"]}),c["llm.baseURL"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.baseURL"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"temperature",tooltip:"Controls randomness in responses (0.0 = deterministic, 1.0 = creative)",children:"Temperature"}),(0,d.jsx)(aP.p,{id:"temperature",type:"number",value:void 0!==a.temperature?a.temperature:"",onChange:a=>l("temperature",a.target.value?parseFloat(a.target.value):void 0),min:"0",max:"1",step:"0.1",placeholder:"0.0 - 1.0","aria-invalid":!!c["llm.temperature"]}),c["llm.temperature"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.temperature"]})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"maxInputTokens",type:"number",value:a.maxInputTokens||"",onChange:a=>l("maxInputTokens",a.target.value?parseInt(a.target.value,10):void 0),min:"1",placeholder:"Auto (128k fallback)","aria-invalid":!!c["llm.maxInputTokens"]}),c["llm.maxInputTokens"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxInputTokens"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"maxOutputTokens",type:"number",value:a.maxOutputTokens||"",onChange:a=>l("maxOutputTokens",a.target.value?parseInt(a.target.value,10):void 0),min:"1",placeholder:"Auto (provider default)","aria-invalid":!!c["llm.maxOutputTokens"]}),c["llm.maxOutputTokens"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxOutputTokens"]})]})]})]})})}let b8=["dateTime","memorySummary","resources"];function b9({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(new Set),[l,m]=(0,e.useState)({}),p=a.contributors||[],q=(a,c)=>{b({contributors:p.map(b=>{if(b.id===a){if(c.id&&c.id!==a&&k(b=>{let d=new Set(b);return d.has(a)&&(d.delete(a),d.add(c.id)),d}),c.type&&c.type!==b.type){let a={id:c.id||b.id,priority:void 0!==c.priority?c.priority:b.priority,enabled:void 0!==c.enabled?c.enabled:b.enabled};if("static"===c.type)return{...a,type:"static",content:""};if("dynamic"===c.type)return{...a,type:"dynamic",source:"dateTime"};if("file"===c.type)return{...a,type:"file",files:[]}}return{...b,...c}}return b})})};return(0,d.jsx)(b2,{title:"System Prompt",defaultOpen:!0,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define how the agent should behave using multiple contributors with different priorities."}),0===p.length?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"No contributors configured"}):p.map(a=>{let c,e,f=j.has(a.id);return(0,d.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,d.jsxs)("button",{onClick:()=>{var b;return b=a.id,void k(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[f?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:a.id}),(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a.type,", priority: ",a.priority,")"]}),!1===a.enabled&&(0,d.jsx)("span",{className:"text-xs text-destructive",children:"(disabled)"})]}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{var c;return c=a.id,void(b({contributors:p.filter(a=>a.id!==c)}),k(a=>{let b=new Set(a);return b.delete(c),b}))},className:"h-7 w-7 p-0",children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),f&&(0,d.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-id-${a.id}`,tooltip:"Unique identifier for this contributor",children:"ID *"}),(0,d.jsx)(aP.p,{id:`contributor-id-${a.id}`,value:a.id,onChange:b=>q(a.id,{id:b.target.value}),placeholder:"e.g., primary, dateTime"})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-type-${a.id}`,tooltip:"Type of contributor: static (fixed text), dynamic (runtime generated), or file (from files)",children:"Type *"}),(0,d.jsxs)("select",{id:`contributor-type-${a.id}`,value:a.type,onChange:b=>q(a.id,{type:b.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,d.jsx)("option",{value:"static",children:"Static"}),(0,d.jsx)("option",{value:"dynamic",children:"Dynamic"}),(0,d.jsx)("option",{value:"file",children:"File"})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-priority-${a.id}`,tooltip:"Execution priority (lower numbers run first)",children:"Priority *"}),(0,d.jsx)(aP.p,{id:`contributor-priority-${a.id}`,type:"number",value:a.priority,onChange:b=>{let c=Number.parseInt(b.target.value,10);q(a.id,{priority:Number.isNaN(c)?0:c})},placeholder:"0",min:"0"})]})]}),(0,d.jsx)("div",{children:(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:!1!==a.enabled,onChange:b=>q(a.id,{enabled:b.target.checked}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Enabled"})]})}),"static"===a.type&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-content-${a.id}`,tooltip:"Static content for the system prompt",children:"Content *"}),(0,d.jsx)(bh.T,{id:`contributor-content-${a.id}`,value:a.content,onChange:b=>q(a.id,{content:b.target.value}),placeholder:"You are a helpful assistant...",rows:8,className:"font-mono text-sm"})]}),"dynamic"===a.type&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-source-${a.id}`,tooltip:"Source for dynamic content generation",children:"Source *"}),(0,d.jsx)("select",{id:`contributor-source-${a.id}`,value:a.source,onChange:b=>q(a.id,{source:b.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:b8.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),"file"===a.type&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-files-${a.id}`,tooltip:"File paths to include, comma-separated",children:"Files *"}),(0,d.jsx)(aP.p,{id:`contributor-files-${a.id}`,value:(c=a.id,e=a.files,l[c]??e.join(", ")),onChange:b=>{var c,d;return c=a.id,d=b.target.value,void m(a=>({...a,[c]:d}))},onBlur:b=>((a,b)=>{m(b=>{let c={...b};return delete c[a],c});let c=b.split(",").map(a=>a.trim()).filter(Boolean);q(a,{files:c.length>0?c:[]})})(a.id,b.target.value),placeholder:"./commands/context.md, ./commands/rules.txt",className:"font-mono"})]}),(0,d.jsxs)("details",{className:"border border-border rounded-md p-2",children:[(0,d.jsx)("summary",{className:"text-sm font-medium cursor-pointer",children:"File Options"}),(0,d.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:a.options?.includeFilenames!==!1,onChange:b=>q(a.id,{options:{...a.options,includeFilenames:b.target.checked}}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Include filenames as headers"})]}),(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:a.options?.includeMetadata===!0,onChange:b=>q(a.id,{options:{...a.options,includeMetadata:b.target.checked}}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Include file metadata"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-separator-${a.id}`,tooltip:"Separator between multiple files",children:"Separator"}),(0,d.jsx)(aP.p,{id:`contributor-separator-${a.id}`,value:a.options?.separator??"\n\n---\n\n",onChange:b=>q(a.id,{options:{...a.options,separator:b.target.value}}),placeholder:"\\n\\n---\\n\\n"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-error-handling-${a.id}`,tooltip:"How to handle missing or unreadable files",children:"Error Handling"}),(0,d.jsxs)("select",{id:`contributor-error-handling-${a.id}`,value:a.options?.errorHandling||"skip",onChange:b=>q(a.id,{options:{...a.options,errorHandling:b.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,d.jsx)("option",{value:"skip",children:"Skip missing files"}),(0,d.jsx)("option",{value:"error",children:"Error on missing files"})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-max-file-size-${a.id}`,tooltip:"Maximum file size in bytes",children:"Max File Size (bytes)"}),(0,d.jsx)(aP.p,{id:`contributor-max-file-size-${a.id}`,type:"number",value:a.options?.maxFileSize||1e5,onChange:b=>{let c=Number.parseInt(b.target.value,10);q(a.id,{options:{...a.options,maxFileSize:Number.isNaN(c)?void 0:c}})},placeholder:"100000",min:"1"})]})]})]})]})]})]},a.id)}),(0,d.jsxs)(x.$,{onClick:()=>{let a=`contributor-${Date.now()}`,c={id:a,type:"static",priority:10*p.length,enabled:!0,content:""};b({contributors:[...p,c]}),k(b=>new Set(b).add(a))},variant:"outline",size:"sm",className:"w-full",children:[(0,d.jsx)(aU.A,{className:"h-4 w-4 mr-2"}),"Add Contributor"]}),c.systemPrompt&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.systemPrompt})]})})}var ca=(a=>(a.SCHEMA_VALIDATION="mcp_schema_validation",a.COMMAND_MISSING="mcp_command_missing",a.DUPLICATE_NAME="mcp_duplicate_name",a.CONNECTION_FAILED="mcp_connection_failed",a.PROTOCOL_ERROR="mcp_protocol_error",a.SERVER_NOT_FOUND="mcp_server_not_found",a.TOOL_NOT_FOUND="mcp_tool_not_found",a.PROMPT_NOT_FOUND="mcp_prompt_not_found",a.RESOURCE_NOT_FOUND="mcp_resource_not_found",a))(ca||{}),cb=(a=>(a.LLM="llm",a.AGENT="agent",a.CONFIG="config",a.CONTEXT="context",a.SESSION="session",a.MCP="mcp",a.TOOLS="tools",a.STORAGE="storage",a.SYSTEM_PROMPT="system_prompt",a.PREFERENCE="preference",a.AGENT_REGISTRY="agent_registry",a.RESOURCE="resource",a.PROMPT="prompt",a.MEMORY="memory",a.PLUGIN="plugin",a.FILESYSTEM="filesystem",a.PROCESS="process",a))(cb||{}),cc=(a=>(a.USER="user",a.NOT_FOUND="not_found",a.FORBIDDEN="forbidden",a.TIMEOUT="timeout",a.CONFLICT="conflict",a.RATE_LIMIT="rate_limit",a.SYSTEM="system",a.THIRD_PARTY="third_party",a.UNKNOWN="unknown",a))(cc||{}),cd=c(61804);cd.Yj().transform(a=>a.trim()).refine(a=>a.length>0,{message:"Required"}),cd.Yj().transform(a=>a.trim()).refine(a=>""===a||function(a){try{let b=new URL(a);return"http:"===b.protocol||"https:"===b.protocol}catch{return!1}}(a),{message:"Invalid URL"}).transform(a=>""===a?void 0:a).optional();let ce=a=>cd.Yj().transform(b=>{if("string"!=typeof b)return"";let c=a??process.env;return b.replace(/\$([A-Z_][A-Z0-9_]*)|\${([A-Z_][A-Z0-9_]*)}/gi,(a,b,d)=>c[b||d]??"").trim()}),cf=a=>ce(a).refine(a=>{try{let b=new URL(a);return"http:"===b.protocol||"https:"===b.protocol}catch{return!1}},{message:"Invalid URL"});var cg=c(2946);let ch=["stdio","sse","http"],ci=["strict","lenient"],cj="lenient",ck=cd.Ik({type:cd.eu("stdio"),command:ce().superRefine((a,b)=>{0===a.length&&b.addIssue({code:cg.eq.custom,message:"Stdio server requires a non-empty command",params:{code:ca.COMMAND_MISSING,scope:cb.MCP,type:cc.USER}})}),args:cd.YO(ce()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),env:cd.g1(ce()).default({}).describe("Optional environment variables for the server process"),timeout:cd.au.number().int().positive().default(3e4),connectionMode:cd.k5(ci).default(cj)}).strict(),cl=cd.Ik({type:cd.eu("sse"),url:cf(process.env).describe("URL for the SSE server endpoint"),headers:cd.g1(ce()).default({}),timeout:cd.au.number().int().positive().default(3e4),connectionMode:cd.k5(ci).default(cj)}).strict(),cm=cd.Ik({type:cd.eu("http"),url:cf(process.env).describe("URL for the HTTP server"),headers:cd.g1(ce()).default({}),timeout:cd.au.number().int().positive().default(3e4),connectionMode:cd.k5(ci).default(cj)}).strict(),cn=cd.gM("type",[ck,cl,cm]).superRefine((a,b)=>{}).brand();function co({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(new Set),[l,m]=(0,e.useState)({}),p=Object.entries(a||{}),q=(c,d)=>{let e=a[c],{name:f,...g}=d,h={...e,...g};if(f&&"string"==typeof f&&f!==c){if(a[f])return;let d={...a};delete d[c],d[f]=h,b(d),k(a=>{let b=new Set(a);return b.has(c)&&(b.delete(c),b.add(f)),b})}else b({...a,[c]:h})},r=(a,b,c)=>l[`${a}:${b}`]??c,s=(a,b,c)=>{let d=`${a}:${b}`;m(a=>({...a,[d]:c}))},t=(a,b)=>{let c=`${a}:${b}`;m(a=>{let b={...a};return delete b[c],b})};return(0,d.jsx)(b2,{title:"MCP Servers",defaultOpen:!1,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[0===p.length?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"No MCP servers configured"}):p.map(([e,f])=>{let g=j.has(e);return(0,d.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,d.jsxs)("button",{onClick:()=>{k(a=>{let b=new Set(a);return b.has(e)?b.delete(e):b.add(e),b})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[g?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:e}),"command"in f&&f.command&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:["(",f.command,")"]})]}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>(c=>{let d={...a};delete d[c],b(d),k(a=>{let b=new Set(a);return b.delete(c),b})})(e),className:"h-7 w-7 p-0",children:(0,d.jsx)(bj.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),g&&(0,d.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-name-${e}`,tooltip:"Unique identifier for this MCP server",children:"Server Name"}),(0,d.jsx)(aP.p,{id:`server-name-${e}`,value:e,onChange:a=>q(e,{name:a.target.value}),placeholder:"e.g., filesystem"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-type-${e}`,tooltip:"MCP server connection type",children:"Connection Type *"}),(0,d.jsx)("select",{id:`server-type-${e}`,value:f.type||"stdio",onChange:a=>{let b=a.target.value;"stdio"===b?q(e,{type:"stdio",command:"",args:void 0,env:void 0}):q(e,{type:b,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:ch.map(a=>(0,d.jsx)("option",{value:a,children:"stdio"===a?"Standard I/O (stdio)":"sse"===a?"Server-Sent Events (SSE)":"HTTP"},a))})]}),"stdio"===f.type&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-command-${e}`,tooltip:"The command to execute (e.g., npx, node, python)",children:"Command *"}),(0,d.jsx)(aP.p,{id:`server-command-${e}`,value:"command"in f?f.command:"",onChange:a=>q(e,{command:a.target.value}),placeholder:"e.g., npx, node, python","aria-invalid":!!c[`mcpServers.${e}.command`]}),c[`mcpServers.${e}.command`]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c[`mcpServers.${e}.command`]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-args-${e}`,tooltip:"Command arguments, comma-separated",children:"Arguments"}),(0,d.jsx)(aP.p,{id:`server-args-${e}`,value:r(e,"args",("args"in f&&f.args?f.args:[]).join(", ")),onChange:a=>s(e,"args",a.target.value),onBlur:a=>((a,b)=>{if(t(a,"args"),!b.trim())return void q(a,{args:void 0});let c=b.split(",").map(a=>a.trim()).filter(Boolean);q(a,{args:c.length>0?c:void 0})})(e,a.target.value),placeholder:"--port, 3000, --host, localhost",className:"font-mono"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-env-${e}`,tooltip:"Environment variables in KEY=value format, one per line",children:"Environment Variables"}),(0,d.jsx)("textarea",{id:`server-env-${e}`,value:r(e,"env",Object.entries("env"in f&&f.env||{}).map(([a,b])=>`${a}=${b}`).join("\n")),onChange:a=>s(e,"env",a.target.value),onBlur:a=>((a,b)=>{if(t(a,"env"),!b.trim())return void q(a,{env:void 0});let c={};b.split("\n").map(a=>a.trim()).filter(Boolean).forEach(a=>{let[b,...d]=a.split("=");b&&d.length>0&&(c[b.trim()]=d.join("=").trim())}),q(a,{env:Object.keys(c).length>0?c:void 0})})(e,a.target.value),placeholder:`API_KEY=$MY_API_KEY
5
+ Context: ${c}`}return b}).join("\n\n")}`:a.message;return(0,d.jsx)("div",{className:"w-full rounded-lg p-4 mb-4 border shadow-sm bg-destructive/10 border-destructive/40",children:(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)(m.A,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("h3",{className:"text-sm font-medium text-destructive",children:"Error"}),a.context&&(0,d.jsx)("span",{className:"text-xs bg-destructive/15 text-destructive px-2 py-0.5 rounded-full",children:a.context})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[h.length>0&&(0,d.jsx)("button",{onClick:()=>f(!c),className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:c?"Collapse":"Expand",children:c?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"})}),(0,d.jsx)(z,{value:i,tooltip:"Copy error",className:"p-1 hover:bg-destructive/15 rounded text-destructive",size:16}),(0,d.jsx)(F,{value:i,tooltip:"Read error",className:"p-1 hover:bg-destructive/15 rounded text-destructive"}),(0,d.jsx)("button",{onClick:b,className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:"Dismiss",children:(0,d.jsx)(p.A,{className:"h-4 w-4"})})]})]}),(0,d.jsx)("div",{className:"mt-2 text-sm text-destructive",children:a.message}),c&&h.length>0&&(0,d.jsx)("div",{className:"mt-3",children:(0,d.jsx)("div",{className:"text-xs text-destructive bg-destructive/10 p-3 rounded border border-destructive/30 overflow-auto max-h-60",children:h.map((a,b)=>(0,d.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,d.jsx)("div",{className:"font-medium",children:a.message}),null!=a.context&&(0,d.jsx)("div",{className:"text-destructive/70 mt-1",children:"string"==typeof a.context?a.context:JSON.stringify(a.context,null,2)})]},b))})})]})]})})}var H=c(92231),I=c(22759),J=c(82801),K=c(73002),L=c(49650),M=c(61346),N=c(62e3),O=c(857),P=c(64212),Q=c(16686),R=c(351),S=c(97831),T=c(24349),U=c(59336),V=c(89376),W=c(29951),X=c(71317);function Y(a,b){let c=b?`${b}/`:"[a-z0-9.+-]+/";return RegExp(`^data:${c}[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$`,"i").test(a)}function Z(a){try{let b=new URL(a),c=b.hostname.toLowerCase();if("https:"!==b.protocol&&"http:"!==b.protocol||"localhost"===c||"::1"===c)return!1;let d=c.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(d){let[,a,b,c,e]=d.map(Number);if(a>255||b>255||c>255||e>255||127===a||10===a||172===a&&b>=16&&b<=31||192===a&&168===b||169===a&&254===b||0===a&&0===b&&0===c&&0===e)return!1}if(c.includes(":")&&("::1"===c||"0:0:0:0:0:0:0:1"===c||c.startsWith("fc")||c.startsWith("fd")||c.startsWith("fe8")||c.startsWith("fe9")||c.startsWith("fea")||c.startsWith("feb")))return!1;return!0}catch{return!1}}function $(a,b){return!!(a.startsWith("blob:")||Z(a))||!!a.startsWith("data:")&&(b?Y(a,b):Y(a))}let _=(0,e.memo)(({children:a})=>{let b=f().useRef(new Set);return f().useEffect(()=>()=>{b.current.forEach(a=>{try{URL.revokeObjectURL(a)}catch{}})},[]),(0,d.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,d.jsx)(V.oz,{remarkPlugins:[W.A,X.A],skipHtml:!0,components:{a:({href:a,children:b,...c})=>{let e=a??"";return/^https?:\/\//i.test(e)&&Z(e)?(0,d.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"},...c,children:b}):(0,d.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",...c,children:b})},img:({src:a,alt:c,...e})=>{if(!a)return(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"No media source provided"});let f=null;if("string"==typeof a)f=a;else if(a instanceof Blob||a instanceof File)try{let c=URL.createObjectURL(a);f=c,b.current.add(c)}catch(a){f=null}else if("object"==typeof a&&null!==a&&a instanceof MediaSource)try{let c=URL.createObjectURL(a);f=c,b.current.add(c)}catch(a){f=null}else f=null;return f?function(a){return!!(a.match(/\.(mp4|webm|mov|m4v|avi|mkv)(\?.*)?$/i)||a.includes("/video/")||a.includes("video_"))}(f)&&$(f,"video")?(0,d.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,d.jsx)("video",{controls:!0,src:f,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."}),c&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:c})]}):function(a){return!!(a.match(/\.(mp3|wav|ogg|m4a|aac|flac|wma)(\?.*)?$/i)||a.includes("/audio/")||a.includes("audio_"))}(f)&&$(f,"audio")?(0,d.jsxs)("div",{className:"my-4 max-w-full overflow-hidden",children:[(0,d.jsx)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-muted/30",children:(0,d.jsx)("audio",{controls:!0,src:f,className:"flex-1 min-w-0 h-10",children:"Your browser does not support the audio tag."})}),c&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:c})]}):$(f,"image")?(0,d.jsx)("img",{src:f,alt:c||"Image",className:"max-w-full max-h-[500px] object-contain rounded-lg border border-border my-4",loading:"lazy",...e}):(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"}):(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Invalid or unsafe media source"})},p:({children:a,...b})=>"string"==typeof a?(0,d.jsx)("p",{...b,children:function(a){let b=/(https?:\/\/[^\s<]+)/g;return a.split(b).map((a,c)=>a.match(b)?Z(a)?(0,d.jsx)("a",{href:a,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:a,style:{wordBreak:"break-word",overflowWrap:"anywhere"},children:a},c):(0,d.jsx)("span",{className:"text-muted-foreground underline decoration-dotted",title:"Unsafe URL",children:a},c):a)}(a)}):(0,d.jsx)("p",{...b,children:a}),table:({className:a,children:b,...c})=>(0,d.jsx)("div",{className:"my-4 overflow-x-auto -mx-1 px-1",children:(0,d.jsx)("table",{className:["w-full border-separate border-spacing-0",a].filter(Boolean).join(" "),...c,children:b})}),thead:({className:a,...b})=>(0,d.jsx)("thead",{className:a,...b}),tr:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),th:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),td:({className:a,...b})=>(0,d.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",a].filter(Boolean).join(" "),...b}),code:({className:a,children:b,...c})=>{let[f,g]=(0,e.useState)(!1),h=String(b??"").replace(/\n$/,"");return a?(0,d.jsxs)("div",{className:"relative group my-4 min-w-0 max-w-full",children:[(0,d.jsx)(y,{tooltip:f?"Copied!":"Copy code",onClick:()=>{navigator.clipboard.writeText(h).then(()=>{g(!0),setTimeout(()=>g(!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:f?(0,d.jsx)(q.A,{size:14}):(0,d.jsx)(r.A,{size:14})}),(0,d.jsx)("pre",{className:"overflow-auto bg-muted p-3 rounded-lg text-sm max-w-full",children:(0,d.jsx)("code",{className:a,children:h})})]}):(0,d.jsx)("code",{className:"text-xs px-1.5 py-0.5 bg-muted rounded font-mono break-all overflow-wrap-anywhere",...c,children:b})}},children:a})})});function aa(a){(0,e.useMemo)(()=>{let b=new Set,c=[];for(let d of a){if(!d||"string"!=typeof d)continue;let a=d.trim();!a||b.has(a)||(b.add(a),c.push(a))}return c},[a.join("|")]);let[b,c]=(0,e.useState)({});return(0,e.useRef)({}),(0,e.useRef)(new Set),b}let ab=null,ac=null,ad=null;async function ae(){let a=await fetch(`${(0,g.e)()}/api/resources`);if(!a.ok){let b=await a.text().catch(()=>"");throw Error(b?`HTTP ${a.status}: ${b}`:`HTTP ${a.status}`)}let b=await a.json();if(!b||!b.ok||!Array.isArray(b.resources))throw Error("Invalid response shape");return b.resources}async function af(a=!1){return(a&&(ab=null,ac=null),ab)?ab:(ad||(ad=ae().then(a=>(ab=a,ac=null,a)).catch(a=>{throw ac=a instanceof Error?a.message:String(a),a}).finally(()=>{ad=null})),ad)}function ag(){let[a,b]=(0,e.useState)(()=>ab??[]),[c,d]=(0,e.useState)(()=>null===ab),[f,g]=(0,e.useState)(()=>ac);return{resources:a,loading:c,error:f,refresh:(0,e.useCallback)(async()=>{d(!0);try{let a=await af(!0);b(a),g(null)}catch(a){g(a instanceof Error?a.message:String(a))}finally{d(!1)}},[])}}var ah=c(47030);function ai(a){if(!a.metadata||"object"!=typeof a.metadata)return null;let b=a.metadata;return b.schema&&b.prompt&&b.serverName?b:null}function aj({approval:a,onApprove:b,onDeny:c}){let[f,g]=(0,e.useState)({}),[h,i]=(0,e.useState)({}),[j,k]=(0,e.useState)(!1),l="elicitation"===a.type,n=(a,b)=>{g(c=>({...c,[a]:b})),h[a]&&i(b=>{let c={...b};return delete c[a],c})};return(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:l?"Information Request":"Approval Required"})]}),l?(()=>{let b=ai(a);return b?(0,d.jsxs)("div",{className:"space-y-4 min-w-0",children:[(0,d.jsxs)("div",{className:"bg-muted/50 p-3 rounded-md border border-border min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium mb-1 break-words",children:b.prompt}),(0,d.jsxs)("p",{className:"text-xs text-muted-foreground break-words",children:["From: ",b.serverName||"Dexto Agent"]})]}),(0,d.jsx)("div",{children:(()=>{let a=b.schema;if(!a?.properties||"object"!=typeof a.properties)return(0,d.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid form schema"});let c=a.required||[],e=a.properties;return(0,d.jsx)("div",{className:"space-y-4",children:Object.entries(e).map(([a,b])=>{let e=c.includes(a),g=b.type||"string",i=f[a],j=!!h[a];return"boolean"===g?(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)(ah.S,{id:a,checked:!0===i,onCheckedChange:b=>n(a,!0===b)}),(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground ml-6",children:b.description})]},a):"number"===g||"integer"===g?(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsx)("input",{id:a,type:"number",step:"integer"===g?"1":"any",value:"number"==typeof i?i:"",onChange:b=>{let c=b.target.value;n(a,""===c?void 0:Number(c))},className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,placeholder:e?"Required":"Optional"}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a):b.enum&&Array.isArray(b.enum)?(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsxs)("select",{id:a,value:null!=i?String(i):"",onChange:c=>{let d=c.target.value;if(""===d)return void n(a,void 0);n(a,b.enum?.find(a=>String(a)===d)??d)},className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,children:[(0,d.jsx)("option",{value:"",children:"Select an option..."}),b.enum?.map(a=>(0,d.jsx)("option",{value:String(a),children:String(a)},String(a)))]}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a):(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("label",{htmlFor:a,className:"text-sm font-medium block",children:[a,e&&(0,d.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),b.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:b.description}),(0,d.jsx)("input",{id:a,type:"text",value:null!=i&&"object"!=typeof i?String(i):"",onChange:b=>n(a,b.target.value),className:`w-full px-3 py-2 border rounded-md text-sm bg-background ${j?"border-red-500":"border-border"}`,placeholder:e?"Required":"Optional"}),j&&(0,d.jsx)("p",{className:"text-xs text-red-500",children:h[a]})]},a)})})})()})]}):(0,d.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid elicitation metadata"})})():"tool_confirmation"===a.type?(0,d.jsxs)("div",{className:"space-y-3 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,d.jsx)(J.A,{className:"h-4 w-4 flex-shrink-0"}),(0,d.jsxs)("span",{className:"font-medium text-sm break-words min-w-0",children:["Tool: ",a.toolName]})]}),a.description&&(0,d.jsx)("p",{className:"text-sm break-words",children:a.description}),(0,d.jsxs)("div",{className:"min-w-0",children:[(0,d.jsx)("span",{className:"font-medium text-sm block mb-2",children:"Arguments:"}),(0,d.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(a.args,null,2)})]}),(0,d.jsxs)("div",{className:"flex items-center space-x-2 pt-2",children:[(0,d.jsx)(ah.S,{id:"remember",checked:j,onCheckedChange:a=>k(!0===a)}),(0,d.jsx)("label",{htmlFor:"remember",className:"text-sm",children:"Remember this choice for this session"})]})]}):null,(0,d.jsxs)("div",{className:"flex gap-2 justify-end pt-3 border-t border-border",children:[(0,d.jsx)(x.$,{variant:"outline",onClick:c,size:"sm",children:l?"Decline":"Deny"}),(0,d.jsx)(x.$,{onClick:()=>{if(l){let c=ai(a);if(!c)return void console.error("Invalid elicitation metadata");let d=c.schema.required||[],e={};for(let a of d){let b=f[a],c="string"==typeof b&&""===b.trim();(null==b||c)&&(e[a]="This field is required")}if(Object.keys(e).length>0)return void i(e);b(f)}else b(void 0,j)},size:"sm",children:l?"Submit":"Approve"})]})]})}function ak(a,b){let c=b?`${b}/`:"[a-z0-9.+-]+/";return RegExp(`^data:${c}[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$`,"i").test(a)}function al(a,b){return!!(a.startsWith("blob:")||function(a){try{let b=new URL(a),c=b.hostname.toLowerCase();if("https:"!==b.protocol&&"http:"!==b.protocol||"localhost"===c||"::1"===c)return!1;let d=c.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(d){let[,a,b,c,e]=d.map(Number);if(a>255||b>255||c>255||e>255||127===a||10===a||172===a&&b>=16&&b<=31||192===a&&168===b||169===a&&254===b||0===a&&0===b&&0===c&&0===e)return!1}if(c.includes(":")&&("::1"===c||"0:0:0:0:0:0:0:1"===c||c.startsWith("fc")||c.startsWith("fd")||c.startsWith("fe8")||c.startsWith("fe9")||c.startsWith("fea")||c.startsWith("feb")))return!1;return!0}catch{return!1}}(a))||!!a.startsWith("data:")&&(b?ak(a,b):ak(a))}function am(a,b){if(!a)return"";let c=a?.mimeType,d="string"==typeof a?a:a?.data??a?.base64??a?.image??a?.audio??a?.video??a?.uri??a?.url;if("string"==typeof d){if(d.startsWith("@blob:")){let c=d.substring(1);if(b&&c){let d=b[c];if(d&&"loaded"===d.status&&d.data){let b=[];if(a?.type==="image"&&b.push("image"),a?.type==="file"){let c=(0,l.t)(a.mimeType);"audio"===c?b.push("audio"):"video"===c&&b.push("video")}a?.mimeType?.startsWith("image/")&&b.push("image"),a?.mimeType?.startsWith("audio/")&&b.push("audio"),a?.mimeType?.startsWith("video/")&&b.push("video");let c=d.data.items.find(a=>b.includes(a.kind))??d.data.items.find(a=>"image"===a.kind)??d.data.items.find(a=>"video"===a.kind)??d.data.items.find(a=>"audio"===a.kind)??d.data.items[0];if(c&&"src"in c&&"string"==typeof c.src)return c.src}}return""}if(d.startsWith("data:"))return d;if(c&&!(!d||d.length<16||d.startsWith("http://")||d.startsWith("https://")||d.startsWith("data:")||d.startsWith("@blob:"))&&/^[A-Za-z0-9+/=\r\n]+$/.test(d))return`data:${c};base64,${d}`;if(al(d))return d}let e=a?.url??a?.image??a?.audio??a?.video??a?.uri;return"string"==typeof e?e:""}function an(a,b){if(!a||"object"!=typeof a)return null;let c=a.mimeType||a.mediaType,d=a.filename||a.name,e="file"===a.type?(0,l.t)(a.mimeType):null;if(!(c?.startsWith("video/")||"video"===e||"video"===a.type||d?.match(/\.(mp4|webm|mov|m4v|avi|mkv)$/i)))return null;let f=am(a,b);return f&&al(f,"video")?{src:f,filename:d,mimeType:c}:null}function ao(){return(0,d.jsx)("div",{className:"flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground",role:"status","aria-live":"polite",children:(0,d.jsxs)("span",{className:"flex items-center gap-1 uppercase tracking-wide text-muted-foreground/80",children:[(0,d.jsx)("span",{children:"Thinking"}),(0,d.jsx)("span",{className:"flex items-center gap-0.5",children:[0,1,2].map(a=>(0,d.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:`${.18*a}s`}},a))})]})})}function ap({messages:a,processing:b=!1,activeError:c,onDismissError:g,outerRef:h,pendingApproval:i,onApprovalApprove:q,onApprovalDeny:r}){let s=(0,e.useRef)(null),[t,x]=(0,e.useState)({}),[y,A]=(0,e.useState)({}),[C,D]=(0,e.useState)(null);(0,e.useRef)(null);let[E,U]=(0,e.useState)({isOpen:!1,src:"",alt:""}),{resources:V}=ag(),W=(0,e.useMemo)(()=>{let a={};for(let b of V)a[b.uri]={...b};return a},[V]),X=aa((0,e.useMemo)(()=>{let b=new Set,c=a=>{if("string"!=typeof a)return;let c=a.startsWith("@")?a.substring(1):a;c.startsWith("blob:")&&b.add(c)},d=a=>{if(a){if("string"==typeof a)return void c(a);"object"==typeof a&&("string"==typeof a.image&&c(a.image),"string"==typeof a.data&&c(a.data),"string"==typeof a.url&&c(a.url),"string"==typeof a.audio&&c(a.audio),"string"==typeof a.video&&c(a.video))}};for(let c of a){let a=c.toolResult;a&&((0,k.P2)(a)?(a.resources?.forEach(a=>{a?.uri?.startsWith("blob:")&&b.add(a.uri)}),a.content?.forEach(a=>d(a))):a?.content&&Array.isArray(a.content)&&a.content.forEach(a=>d(a)))}return Array.from(b)},[a])),Y=(a,b)=>{U({isOpen:!0,src:a,alt:b})};if(!a||0===a.length)return null;let Z=a=>"string"==typeof a.content?a.content:Array.isArray(a.content)?a.content.map(a=>(0,k.PI)(a)?a.text:"").filter(Boolean).join("\n"):a.content&&"object"==typeof a.content?JSON.stringify(a.content,null,2):"",$=a=>a?(0,k.KU)(a)?"object"==typeof a.error?JSON.stringify(a.error,null,2):String(a.error):(0,k.P2)(a)?a.content.map(a=>(0,k.PI)(a)?a.text:"object"==typeof a?"":String(a)).filter(Boolean).join("\n"):"object"==typeof a?JSON.stringify(a,null,2):String(a):"";return(0,d.jsxs)("div",{id:"message-list-container",ref:h,className:"flex flex-col space-y-3 px-3 sm:px-4 py-2 min-w-0 w-full",children:[a.map((e,h)=>{let i=e.id??`msg-${h}`,p="user"===e.role,q="assistant"===e.role,r="system"===e.role,s=h===a.length-1,C=!!(e.toolName&&e.toolArgs),D=!!(e.toolName&&e.toolResult),E=C||D,U=E&&s||!!t[i],V=[],_=[],aa=[];D&&e.toolResult&&(0,k.P2)(e.toolResult)&&e.toolResult.content.forEach((a,b)=>{if((0,k.j0)(a)){let c=am(a,X);c&&al(c,"image")&&V.push({src:c,alt:`Tool result image ${b+1}`,index:b})}else if((0,k.kz)(a)){let c=am(a,X);c&&al(c,"audio")&&_.push({src:c,filename:a.filename,index:b})}else if((0,k.EQ)(a)&&("audio"===(0,l.t)(a.mimeType)||a.mimeType?.startsWith("audio/"))){let c=am(a,X);c&&al(c,"audio")&&_.push({src:c,filename:a.filename,index:b})}else{let c=an(a,X);c&&aa.push({...c,index:b})}});let ab=p?H.A:I.A,ac=(0,j.cn)(p?"grid w-full grid-cols-[1fr_auto] gap-x-2 items-start":"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start"),ad=(0,j.cn)("tool"===e.role?"w-fit max-w-[90%] text-muted-foreground/70 bg-secondary border border-muted/30 rounded-md text-base overflow-hidden":p?"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":q?"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":r?"p-3 shadow-none w-full bg-transparent text-xs text-muted-foreground italic text-center border-none":""),ae=new Date(e.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),af=!!(c&&c.anchorMessageId===e.id),ag=p&&s;return(0,d.jsxs)(f().Fragment,{children:[(0,d.jsxs)("div",{className:"w-full","data-role":e.role,id:e.id?`message-${e.id}`:void 0,children:[(0,d.jsxs)("div",{className:ac,children:[q&&(0,d.jsx)(ab,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1"}),"tool"===e.role&&(0,d.jsx)(J.A,{className:"h-7 w-7 p-1 mt-1 rounded-full border border-border text-muted-foreground col-start-1"}),(0,d.jsxs)("div",{className:(0,j.cn)("flex flex-col group w-full min-w-0",r?"col-span-2 items-center":p?"col-start-1 justify-self-end items-end":"col-start-2 justify-self-start items-start"),children:[(0,d.jsx)("div",{className:(0,j.cn)(ad,"min-w-0"),children:(0,d.jsxs)("div",{className:(0,j.cn)("flex flex-col gap-2","min-w-0"),children:[q&&"string"==typeof e.reasoning&&e.reasoning.trim().length>0&&(0,d.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,d.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,d.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:()=>A(a=>({...a,[i]:!(a[i]??!0)})),children:[(0,d.jsx)(K.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"AI Reasoning"}),y[i]??!0?(0,d.jsx)(n.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"}):(0,d.jsx)(o.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(z,{value:e.reasoning,tooltip:"Copy reasoning",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:e.reasoning,tooltip:"Speak reasoning",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(y[i]??!0)&&(0,d.jsx)("div",{className:"px-3 py-2",children:(0,d.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,d.jsxs)("div",{className:"p-2 rounded border border-border bg-muted/30 hover:bg-muted/60 cursor-pointer",onClick:()=>{E&&x(a=>({...a,[i]:!a[i]}))},children:[(0,d.jsxs)("div",{className:"flex items-center justify-between text-xs font-medium",children:[(0,d.jsxs)("span",{className:"flex items-center",children:[U?(0,d.jsx)(n.A,{className:"h-4 w-4 mr-2 text-primary"}):(0,d.jsx)(L.A,{className:"h-4 w-4 mr-2 text-primary"}),"Tool: ",e.toolName]}),e.toolResult?(0,k.KU)(e.toolResult)?(0,d.jsx)(m.A,{className:"mx-2 h-4 w-4 text-red-500"}):(0,d.jsx)(M.A,{className:"mx-2 h-4 w-4 text-green-500"}):(0,d.jsx)(N.A,{className:"mx-2 h-4 w-4 animate-spin text-muted-foreground"})]}),U&&(0,d.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{className:"text-xs font-medium",children:"Arguments:"}),(0,d.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,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"text-xs font-medium flex items-center justify-between",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)("span",{children:"Result:"}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(z,{value:$(e.toolResult),tooltip:"Copy result",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:$(e.toolResult),tooltip:"Speak result",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(0,k.KU)(e.toolResult)?(0,d.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,k.P2)(e.toolResult)?e.toolResult.content.map((a,b)=>{let c=an(a,X);if((0,k.j0)(a)||(0,k.kz)(a)||(0,k.EQ)(a)&&("audio"===(0,l.t)(a.mimeType)||a.mimeType?.startsWith("audio/"))||c)return null;if((0,k.PI)(a))return(0,d.jsx)(aq,{text:a.text,isUser:!1,onOpenImage:Y,resourceSet:W},`${i}-tool-text-${b}`);if((0,k.EQ)(a)){let c=(0,l.t)(a.mimeType),e="audio"===c||a.mimeType?.startsWith("audio/"),f="video"===c||a.mimeType?.startsWith("video/");return(0,d.jsxs)("div",{className:"my-1 flex items-center gap-2 p-2 rounded border border-border bg-muted/50",children:[e?(0,d.jsx)(O.A,{className:"h-4 w-4 text-muted-foreground"}):f?(0,d.jsx)(P.A,{className:"h-4 w-4 text-muted-foreground"}):(0,d.jsx)(Q.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a.filename||"File attachment"," (",a.mimeType,")"]})]},b)}return(0,d.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 a?JSON.stringify(a,null,2):String(a)},b)}):(0,d.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")?ak(e.toolResult,"image")?(0,d.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,d.jsxs)(d.Fragment,{children:["string"==typeof e.content&&""!==e.content.trim()&&(0,d.jsx)("div",{className:"relative",children:(0,d.jsx)(aq,{text:e.content,isUser:p,onOpenImage:Y,resourceSet:W},`${i}-text-content`)}),e.content&&"object"==typeof e.content&&!Array.isArray(e.content)&&(0,d.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((a,b)=>{let c=`${i}-part-${b}`;if("text"===a.type)return(0,d.jsx)(aq,{text:a.text,isUser:p,onOpenImage:Y,resourceSet:W},c);if((0,k.j0)(a)){let b=am(a);return b&&al(b,"image")?(0,d.jsx)("img",{src:b,alt:"Message attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain cursor-pointer",onClick:()=>Y(b,"Message attachment")},c):null}let e=an(a);if(e){let{src:a,filename:b,mimeType:f}=e;return(0,d.jsxs)("div",{className:"my-2 flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:(0,j.cn)("h-4 w-4",p?void 0:"text-muted-foreground")}),(0,d.jsx)("span",{children:"Video attachment"})]}),(0,d.jsx)("div",{className:"w-full max-w-md",children:(0,d.jsx)("video",{controls:!0,src:a,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"})}),(b||f)&&(0,d.jsxs)("div",{className:"flex flex-col text-xs",children:[b&&(0,d.jsx)("span",{className:(0,j.cn)("truncate",p?"text-primary-foreground/80":"text-muted-foreground"),children:b}),f&&(0,d.jsx)("span",{className:(0,j.cn)(p?"text-primary-foreground/70":"text-muted-foreground/80"),children:f})]})]},c)}if((0,k.EQ)(a)){if(!a.mimeType.startsWith("audio/"))return(0,d.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(Q.A,{className:(0,j.cn)("h-5 w-5",p?void 0:"text-muted-foreground")}),(0,d.jsx)("span",{className:(0,j.cn)("text-sm font-medium",void 0),children:a.filename||`${a.mimeType} file`}),(0,d.jsx)("span",{className:(0,j.cn)("text-xs",p?"text-primary-foreground/70":"text-muted-foreground"),children:a.mimeType})]},c);{let b=am(a);return(0,d.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(O.A,{className:(0,j.cn)("h-5 w-5",p?void 0:"text-muted-foreground")}),(0,d.jsx)("audio",{controls:!0,src:b,className:"flex-1 h-8"}),a.filename&&(0,d.jsx)("span",{className:(0,j.cn)("text-sm truncate max-w-[120px]",p?"text-primary-foreground/80":"text-muted-foreground"),children:a.filename})]},c)}}return null}),r&&!e.content&&(0,d.jsx)("p",{className:"italic",children:"System message"})]}),e.imageData&&!Array.isArray(e.content)&&(()=>{let a=`data:${e.imageData.mimeType};base64,${e.imageData.base64}`;return ak(a,"image")?(0,d.jsx)("img",{src:a,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,d.jsx)("div",{className:"mt-2",children:e.fileData.mimeType.startsWith("video/")?(0,d.jsxs)("div",{className:"flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50 max-w-md",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Video attachment"})]}),(()=>{let a=`data:${e.fileData.mimeType};base64,${e.fileData.base64}`;return ak(a,"video")?(0,d.jsx)("video",{controls:!0,src:a,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}):(0,d.jsx)("div",{className:"text-xs text-red-500",children:"Invalid video data"})})(),(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/90",children:[(0,d.jsx)("span",{className:"font-medium truncate",children:e.fileData.filename||`${e.fileData.mimeType} file`}),(0,d.jsx)("span",{className:"opacity-70",children:e.fileData.mimeType})]})]}):e.fileData.mimeType.startsWith("audio/")?(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(()=>{let a=`data:${e.fileData.mimeType};base64,${e.fileData.base64}`;return ak(a,"audio")?(0,d.jsx)("audio",{controls:!0,src:a,className:"h-8"}):(0,d.jsx)("span",{className:"text-xs text-red-500",children:"Invalid audio data"})})()]}):(0,d.jsxs)("div",{className:"flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,d.jsx)(Q.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{className:"text-sm font-medium",children:e.fileData.filename||`${e.fileData.mimeType} file`}),(0,d.jsx)("span",{className:"text-xs text-primary-foreground/70",children:e.fileData.mimeType})]})})]})}),!r&&!E&&(0,d.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,d.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,d.jsx)("span",{children:ae}),q&&e.tokenUsage?.totalTokens!==void 0&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.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,d.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.tokenUsage.totalTokens," tokens"]})}),(0,d.jsx)(w,{side:"bottom",children:(0,d.jsxs)("div",{className:"flex flex-col gap-0.5",children:[void 0!==e.tokenUsage.inputTokens&&(0,d.jsxs)("div",{children:["Input: ",e.tokenUsage.inputTokens]}),void 0!==e.tokenUsage.outputTokens&&(0,d.jsxs)("div",{children:["Output: ",e.tokenUsage.outputTokens]}),void 0!==e.tokenUsage.reasoningTokens&&(0,d.jsxs)("div",{children:["Reasoning: ",e.tokenUsage.reasoningTokens]}),(0,d.jsxs)("div",{className:"font-medium mt-0.5",children:["Total: ",e.tokenUsage.totalTokens]})]})})]}),q&&e.model&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{children:(0,d.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,d.jsx)(w,{side:"bottom",children:(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsxs)("div",{className:"font-medium",children:["Model: ",e.model]}),e.provider&&(0,d.jsxs)("div",{className:"font-medium",children:["Provider: ",e.provider]}),e.router&&(0,d.jsxs)("div",{className:"font-medium",children:["Router: ",e.router]})]})})]})]}),(q||p)&&(0,d.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,d.jsx)(z,{value:Z(e),tooltip:"Copy message",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,d.jsx)(F,{value:Z(e),tooltip:"Speak",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]})]}),p&&(0,d.jsx)(ab,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-2"})]}),V.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(R.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(R.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Image"})]}),(0,d.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>Y(a.src,a.alt),children:[(0,d.jsx)("img",{src:a.src,alt:a.alt,className:"max-h-80 w-auto rounded border border-border object-contain transition-transform group-hover:scale-[1.02]"}),(0,d.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,d.jsx)(S.A,{className:"h-8 w-8 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow-lg"})})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-image-${b}`)),aa.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(T.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(T.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Video"})]}),(0,d.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0",children:[(0,d.jsx)("video",{controls:!0,src:a.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}),(a.filename||a.mimeType)&&(0,d.jsxs)("div",{className:"flex flex-col text-xs text-muted-foreground",children:[a.filename&&(0,d.jsx)("span",{className:"truncate",children:a.filename}),a.mimeType&&(0,d.jsx)("span",{className:"opacity-70",children:a.mimeType})]})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-video-${b}`)),_.map((a,b)=>(0,d.jsx)("div",{className:"w-full mt-2",children:(0,d.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,d.jsx)(B.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex flex-col items-start",children:[(0,d.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,d.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(B.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:"Tool Result Audio"})]}),(0,d.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,d.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,d.jsx)(O.A,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,d.jsx)("audio",{controls:!0,src:a.src,className:"flex-1 min-w-0"})]}),a.filename&&(0,d.jsx)("div",{className:"flex items-center gap-2 min-w-0",children:(0,d.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:a.filename})})]})]})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,d.jsx)("span",{children:ae})})]})]})},`${i}-audio-${b}`)),af&&(0,d.jsx)("div",{className:"mt-2 ml-12 mr-4",children:(0,d.jsx)(G,{error:c,onDismiss:g||(()=>{})})})]}),b&&ag&&(0,d.jsx)(ao,{})]},i)}),i&&q&&r&&(0,d.jsx)("div",{className:"w-full","data-role":"approval",children:(0,d.jsxs)("div",{className:"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start",children:[(0,d.jsx)(I.A,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1 flex-shrink-0"}),(0,d.jsx)("div",{className:"flex flex-col group w-full col-start-2 justify-self-start items-start min-w-0",children:(0,d.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,d.jsx)(aj,{approval:i,onApprove:q,onDeny:r})})})]})}),(0,d.jsx)("div",{ref:s,className:"h-px"},"end-anchor"),E.isOpen&&(0,d.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm",children:(0,d.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh] bg-background rounded-lg shadow-2xl border border-border",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,d.jsx)("h3",{className:"text-lg font-semibold",children:"Tool Result Image"}),(0,d.jsx)("button",{onClick:()=>{U({isOpen:!1,src:"",alt:""})},className:"p-2 hover:bg-muted rounded-md transition-colors","aria-label":"Close modal",children:(0,d.jsx)(p.A,{className:"h-5 w-5"})})]}),(0,d.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,d.jsx)("img",{src:E.src,alt:E.alt,className:"max-w-full max-h-[70vh] object-contain rounded"})}),(0,d.jsx)("div",{className:"p-4 border-t border-border text-sm text-muted-foreground",children:(0,d.jsx)("p",{children:E.alt})})]})})]})}function aq({text:a,isUser:b,onOpenImage:c,resourceSet:f}){let{cleanedText:g,uris:h}=(0,e.useMemo)(()=>(function(a,b){if(!a)return{cleanedText:"",uris:[]};let c=function(a,b){let c=a.map(a=>({...a}));for(let a of c)switch(a.type){case"uri":if(b[a.identifier])a.resourceUri=a.identifier;else{let c=function(a,b){let c=b.trim().toLowerCase();for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a&&a.toLowerCase()===c)return b}for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a&&a.toLowerCase().includes(c))return b}}(b,a.identifier);c&&(a.resourceUri=c)}break;case"server-scoped":{let c=function(a,b,c){let d=c.trim().toLowerCase(),e=Object.entries(a).filter(([,a])=>a.serverName===b);for(let[a,b]of e){if(!b.name)continue;let c=b.name.trim().toLowerCase();if(c===d||c.includes(d))return a}for(let[a,b]of e){let c="string"==typeof b.metadata?.originalUri?b.metadata.originalUri:void 0;if(c?.toLowerCase().includes(d)||a.toLowerCase().includes(d))return a}}(b,a.serverName,a.identifier);c&&(a.resourceUri=c);break}case"name":{let c=function(a,b){let c=b.trim().toLowerCase();for(let[b,d]of Object.entries(a)){if(!d.name)continue;let a=d.name.trim().toLowerCase();if(a===c||a.includes(c))return b}for(let[b,d]of Object.entries(a)){let a="string"==typeof d.metadata?.originalUri?d.metadata.originalUri:void 0;if(a?.toLowerCase().includes(c)||b.toLowerCase().includes(c))return b}}(b,a.identifier);c&&(a.resourceUri=c)}}return c}(function(a){let b,c=[],d=/(?:^|(?<=\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])/g;for(;null!==(b=d.exec(a));){let[a,d,e,f,g]=b;d?c.push({originalRef:a,type:"uri",identifier:d.slice(1,-1)}):e&&f?c.push({originalRef:a,type:"server-scoped",serverName:e,identifier:f}):g&&c.push({originalRef:a,type:"name",identifier:g})}return c}(a),b),d=Array.from(new Set(c.filter(a=>a.resourceUri).map(a=>a.resourceUri))),e=a;for(let a of c)a.resourceUri&&(e=e.split(a.originalRef).join(""));return{cleanedText:e=(e=e.replace(/\\n/g,"\n").replace(/\\t/g," ")).replace(/\n{3,}/g,"\n\n").replace(/[ \t]{2,}/g," ").trim(),uris:d}})(a,f),[a,f]),i=aa(h),j=g.length>0;return(0,d.jsxs)("div",{className:"space-y-3",children:[j&&(0,d.jsx)("div",{className:"relative min-w-0 overflow-hidden",children:b?(0,d.jsx)("p",{className:"text-base whitespace-pre-line break-words overflow-wrap-anywhere",children:g}):(0,d.jsx)(_,{children:g})}),h.map(a=>(0,d.jsx)(ar,{uri:a,state:i[a],onOpenImage:c},a))]})}function ar({uri:a,state:b,onOpenImage:c}){if(!b||"loading"===b.status)return(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(N.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,d.jsx)("span",{children:"Loading resource…"})]});if("error"===b.status)return(0,d.jsxs)("div",{className:"flex items-start gap-2 text-xs text-destructive",children:[(0,d.jsx)(m.A,{className:"mt-0.5 h-3.5 w-3.5"}),(0,d.jsxs)("div",{className:"space-y-1",children:[(0,d.jsx)("p",{className:"font-medium",children:"Failed to load resource"}),(0,d.jsx)("p",{className:"break-all text-[11px] text-destructive/80",children:a}),(0,d.jsx)("p",{className:"text-[11px] text-destructive/70",children:b.error})]})]});let e=b.data;if(!e||0===e.items.length)return(0,d.jsxs)("div",{className:"text-xs text-muted-foreground",children:[(0,d.jsx)("p",{className:"font-medium",children:e?.name||a}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground/80",children:"No previewable content."})]});let f=e.items.find(a=>"mimeType"in a&&"string"==typeof a.mimeType)?.mimeType;return(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/80",children:[(0,d.jsx)(U.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:e.name||a}),f&&(0,d.jsx)("span",{className:"text-[10px]",children:f})]}),e.items.map((a,b)=>(function({item:a,index:b,onOpenImage:c}){let e=`resource-item-${b}`;switch(a.kind){case"text":if(a.mimeType&&a.mimeType.includes("markdown"))return(0,d.jsx)("div",{className:"text-sm",children:(0,d.jsx)(_,{children:a.text})},e);return(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words rounded-md bg-background/60 p-2 text-sm text-foreground",children:a.text},e);case"image":if(!al(a.src))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported image source"},e);return(0,d.jsx)("img",{src:a.src,alt:a.alt||"Resource image",onClick:()=>c(a.src,a.alt||"Resource image"),className:"max-h-60 w-full cursor-zoom-in rounded-lg border border-border object-contain"},e);case"audio":if(!al(a.src,"audio"))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported audio source"},e);return(0,d.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-background/50 p-2",children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(0,d.jsx)("audio",{controls:!0,src:a.src,className:"h-8 flex-1"}),a.filename&&(0,d.jsx)("span",{className:"max-w-[140px] truncate text-xs text-muted-foreground",children:a.filename})]},e);case"video":if(!al(a.src,"video"))return(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported video source"},e);return(0,d.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-border bg-background/50 p-3",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,d.jsx)(P.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Video"}),a.filename&&(0,d.jsx)("span",{className:"truncate font-medium",children:a.filename})]}),(0,d.jsx)("video",{controls:!0,src:a.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."})]},e);case"file":return(0,d.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background/60 p-2",children:[(0,d.jsx)(Q.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsxs)("div",{className:"flex flex-1 flex-col",children:[(0,d.jsx)("span",{className:"text-sm font-medium text-foreground",children:a.filename||"Resource file"}),a.mimeType&&(0,d.jsx)("span",{className:"text-[11px] text-muted-foreground",children:a.mimeType})]}),a.src&&(0,d.jsx)("a",{href:a.src,download:a.filename||"resource.bin",className:"text-xs font-medium text-primary underline-offset-2 hover:underline",children:"Download"})]},e);default:return null}})({item:a,index:b,onOpenImage:c}))]})}c(16942);var as=c(9864);function at({children:a,className:b}){return(0,d.jsx)("div",{className:(0,j.cn)("relative","w-full","flex flex-col overflow-visible","max-h-[max(35svh,5rem)]","border-2 border-border/50","bg-background","rounded-3xl shadow-sm","transition-all duration-200",b),children:a})}function au({leftButtons:a,rightButtons:b,className:c}){return(0,d.jsxs)("div",{className:(0,j.cn)("flex items-center justify-between","h-12 px-3 pr-4",c),children:[(0,d.jsx)("div",{className:"flex items-center gap-2",children:a}),(0,d.jsx)("div",{className:"flex items-center gap-2",children:b})]})}var av=c(36377),aw=c(12366);let ax=e.forwardRef(({className:a,...b},c)=>(0,d.jsx)(aw.bL,{className:(0,j.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",a),...b,ref:c,children:(0,d.jsx)(aw.zi,{className:(0,j.cn)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));function ay({isStreaming:a,onStreamingChange:b,className:c}){return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:`flex items-center gap-1.5 cursor-pointer ${c||""}`,children:[(0,d.jsx)(av.A,{className:`h-3 w-3 ${a?"text-blue-500":"text-muted-foreground"}`}),(0,d.jsx)(ax,{checked:a,onCheckedChange:b,className:"scale-75","aria-label":"Toggle streaming"})]})}),(0,d.jsxs)(w,{side:"bottom",children:[(0,d.jsx)("p",{children:a?"Streaming enabled":"Streaming disabled"}),(0,d.jsx)("p",{className:"text-xs opacity-75",children:a?"Responses will stream in real-time":"Responses will arrive all at once"})]})]})})}ax.displayName=aw.bL.displayName;var az=c(67162),aA=c(84234);function aB({...a}){return(0,d.jsx)(aA.bL,{"data-slot":"popover",...a})}function aC({className:a,align:b="center",sideOffset:c=4,...e}){return(0,d.jsx)(aA.ZL,{children:(0,d.jsx)(aA.UC,{"data-slot":"popover-content",align:b,sideOffset:c,className:(0,j.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",a),...e})})}let aD=({children:a,...b})=>(0,d.jsx)(aB,{...b,children:a}),aE=function({...a}){return(0,d.jsx)(aA.l9,{"data-slot":"popover-trigger",...a})},aF=e.forwardRef(({className:a,align:b="end",sideOffset:c=4,...e},f)=>(0,d.jsx)(aC,{ref:f,align:b,sideOffset:c,className:(0,j.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...e}));aF.displayName="DropdownMenuContent";let aG=e.forwardRef(({className:a,disabled:b,...c},e)=>(0,d.jsx)("div",{ref:e,className:(0,j.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",b&&"pointer-events-none opacity-50",!b&&"hover:bg-accent hover:text-accent-foreground cursor-pointer",a),...c}));aG.displayName="DropdownMenuItem";let aH=e.forwardRef(({className:a,...b},c)=>(0,d.jsx)("div",{ref:c,className:(0,j.cn)("-mx-1 my-1 h-px bg-muted",a),...b}));function aI({onImageAttach:a,onPdfAttach:b,onAudioAttach:c,className:e,supports:g}){let[h,i]=f().useState(!1),j=g?.image!==!1,k=g?.pdf!==!1,l=g?.audio!==!1;return(0,d.jsxs)(aD,{open:h,onOpenChange:i,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",className:`h-8 px-2 md:px-3 text-sm text-muted-foreground hover:text-foreground rounded-full ${e||""}`,"aria-label":"Attach File",children:[(0,d.jsx)(az.A,{className:"h-3 w-3 md:mr-1.5"}),(0,d.jsx)("span",{className:"hidden md:inline",children:"Attach"})]})}),(0,d.jsxs)(aF,{side:"top",align:"start",children:[(0,d.jsx)(aG,{onClick:()=>{j&&(a(),i(!1))},className:j?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!j,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(az.A,{className:"h-4 w-4 mr-2"})," Image"]})}),!j&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,d.jsx)(aG,{onClick:()=>{k&&(b(),i(!1))},className:k?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!k,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(Q.A,{className:"h-4 w-4 mr-2"})," PDF"]})}),!k&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,d.jsx)(aG,{onClick:()=>{l&&(c(),i(!1))},className:l?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!l,children:(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(O.A,{className:"h-4 w-4 mr-2"})," Audio file"]})}),!l&&(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})})})]})]})}aH.displayName="DropdownMenuSeparator";var aJ=c(93049),aK=c(59245);function aL({isRecording:a,onToggleRecording:b,className:c,disabled:e}){let f=(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>{e||b()},className:`h-8 px-2 md:px-3 text-sm rounded-full ${e?"opacity-50 cursor-not-allowed":"text-muted-foreground hover:text-foreground"} ${c||""}`,"aria-label":a?"Stop recording":"Record audio","aria-disabled":!!e||void 0,children:[a?(0,d.jsx)(aJ.A,{className:"h-3 w-3 md:mr-1.5 text-red-500"}):(0,d.jsx)(aK.A,{className:"h-3 w-3 md:mr-1.5"}),(0,d.jsx)("span",{className:"hidden md:inline",children:a?"Stop":"Record"})]});return e?(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:f}),(0,d.jsx)(w,{side:"bottom",children:"Unsupported for this model"})]})}):f}var aM=c(71061),aN=c(95409),aO=c(79487),aP=c(20773),aQ=c(98023);function aR({open:a,onOpenChange:b,provider:c,primaryEnvVar:f,onSaved:h}){let[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)(null),o=async()=>{if(!i.trim())return void n("API key is required");l(!0),n(null);try{let a=await fetch(`${(0,g.e)()}/api/llm/key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,apiKey:i})}),d=await a.json();if(!a.ok||"object"!=typeof d||null===d)throw Error("Failed to save API key");if(!d.ok||!d.provider||!d.envVar)throw Error("Unexpected response while saving API key");h({provider:d.provider,envVar:d.envVar}),b(!1),j("")}catch(a){n(a instanceof Error?a.message:"Failed to save API key")}finally{l(!1)}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{children:["Set ",c," API Key"]}),(0,d.jsxs)(aN.rr,{children:["This key will be stored in your .env (env var ",f,"). It is not shared with the client."]})]}),m&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:m})}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"apiKey",children:"API Key"}),(0,d.jsx)(aP.p,{id:"apiKey",type:"password",value:i,onChange:a=>j(a.target.value),placeholder:`Enter ${c} API key`})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>b(!1),disabled:k,children:"Cancel"}),(0,d.jsx)(x.$,{onClick:o,disabled:k,children:k?"Saving...":"Save"})]})]})})}var aS=c(67478),aT=c(63472),aU=c(66696),aV=c(38988);function aW({value:a,onChange:b,placeholder:c="Search providers or models",autoFocus:f=!1}){let g=(0,e.useRef)(null);return(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(aV.A,{className:"h-4 w-4 text-muted-foreground"}),(0,d.jsx)(aP.p,{ref:g,placeholder:c,value:a,onChange:a=>b(a.target.value),className:"focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0"})]})}var aX=c(94504),aY=c(15029),aZ=c(65151);let a$={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"},a_={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 a0(a){if(!a)return[];let b="USD"===(a.currency||"USD")?"$":"",c=[];return c.push(`Cost: ${b}${a.inputPerM.toFixed(2)} in / ${b}${a.outputPerM.toFixed(2)} out per 1M tokens`),null!=a.cacheReadPerM&&c.push(`Cache read: ${b}${a.cacheReadPerM.toFixed(2)} per 1M tokens`),null!=a.cacheWritePerM&&c.push(`Cache write: ${b}${a.cacheWritePerM.toFixed(2)} per 1M tokens`),c}let a1=["google","cohere","anthropic"],a2=a=>!a1.includes(a),a3={image:(0,d.jsx)("span",{className:"text-sm",children:"\uD83D\uDDBC️"}),audio:(0,d.jsx)("span",{className:"text-sm",children:"\uD83C\uDFB5"}),pdf:(0,d.jsx)("span",{className:"text-sm",children:"\uD83D\uDCC4"}),reasoning:(0,d.jsx)("span",{className:"text-sm",children:"\uD83E\uDDE0"}),experimental:(0,d.jsx)(aY.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-amber-500 transition-colors cursor-help"}),new:(0,d.jsx)(aZ.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-yellow-500 transition-colors cursor-help"}),realtime:(0,d.jsx)(av.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-blue-500 transition-colors cursor-help"})};var a4=c(88595);function a5({supportedFileTypes:a,hasApiKey:b,className:c}){return(0,d.jsxs)("div",{className:`flex items-center gap-1.5 flex-shrink-0 ${c||""}`,children:[a.includes("pdf")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.pdf})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"PDF support"})})]}),a.includes("audio")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.audio})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"Audio support"})})]}),a.includes("image")&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:a3.image})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"Image support"})})]}),!b&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:"transition-transform hover:scale-125",children:(0,d.jsx)(a4.A,{className:"h-3.5 w-3.5 text-amber-500 hover:text-amber-400 transition-colors cursor-help"})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:"API key required"})})]})]})}function a6({providerId:a,provider:b,models:c,favorites:e,currentModel:f,onToggleFavorite:g,onUse:h}){return 0===c.length?null:(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:a$[a]?(0,d.jsx)(aM.default,{src:a$[a],alt:`${a} logo`,width:20,height:20,className:(0,j.cn)("object-contain",a2(a)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(aS.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,d.jsx)("span",{className:"text-base font-medium",children:b.name})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[b.supportsBaseURL&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs",children:"baseURL"}),!b.hasApiKey&&(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(aX.E,{variant:"destructive",className:"text-xs cursor-default",children:"API Key Required"})}),(0,d.jsxs)(w,{children:["Click any ",b.name," model to set up the API key"]})]})}),a_[a]&&(0,d.jsx)("a",{href:a_[a],target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:underline",title:"View provider pricing",children:"Pricing ↗"})]})]}),(0,d.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:c.map(c=>{let i,k,l=c.displayName||c.name,m=(i=c.name,f?.provider===a&&f?.model===i),n=(k=c.name,e.includes(`${a}|${k}`)),o=b.hasApiKey,p=a0(c.pricing||void 0),q=[`Max tokens: ${c.maxInputTokens.toLocaleString()}`,c.supportedFileTypes.length>0&&`Supports: ${c.supportedFileTypes.join(", ")}`,c.default&&"Default model",!o&&"⚠️ API key required",...p].filter(Boolean);return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{onClick:()=>h(a,c),onKeyDown:b=>{let d=b.target;if(d&&d.closest("button"))return;let e="Enter"===b.key,f=" "===b.key||"Spacebar"===b.key||"Space"===b.code;f&&b.preventDefault(),(e||f)&&h(a,c)},className:(0,j.cn)("group relative flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-all duration-100 cursor-pointer outline-none","hover:bg-accent hover:border-accent-foreground/20 hover:shadow-sm","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",m&&"bg-accent border-accent-foreground/20 shadow-sm ring-1 ring-accent-foreground/10",!o&&"opacity-60"),role:"button",tabIndex:0,children:[(0,d.jsx)("div",{className:"flex-1 text-left",children:(0,d.jsx)("div",{className:"flex items-center gap-2",children:(0,d.jsx)("span",{className:"text-sm font-medium",children:l})})}),(0,d.jsx)(a5,{supportedFileTypes:c.supportedFileTypes,hasApiKey:o}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{onKeyDown:a=>{let b=" "===a.key||"Spacebar"===a.key||"Space"===a.code;("Enter"===a.key||b)&&(a.stopPropagation(),b&&a.preventDefault())},onClick:b=>{b.stopPropagation(),g(a,c.name)},className:"flex-shrink-0 text-muted-foreground hover:text-foreground transition-colors","aria-label":n?"Remove from favorites":"Add to favorites",children:(0,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4",n&&"fill-current text-yellow-500")})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:n?"Remove from favorites":"Add to favorites"})})]})}),m&&(0,d.jsx)("div",{className:"absolute inset-y-0 left-0 w-0.5 bg-primary rounded-l-lg"})]})}),(0,d.jsx)(w,{side:"bottom",className:"max-w-xs",children:(0,d.jsx)("div",{className:"text-xs space-y-0.5",children:q.map((a,b)=>(0,d.jsx)("div",{children:a},b))})})]})},c.name)})})]})}function a7(a){let b=a.trim();if(!b.length)return{isValid:!0};try{let a=new URL(b);if(!["http:","https:"].includes(a.protocol))return{isValid:!1,error:"URL must use http:// or https://"};if(!a.pathname.includes("/v1"))return{isValid:!1,error:"URL must include /v1 for compatibility"};return{isValid:!0}}catch{return{isValid:!1,error:"Invalid URL format"}}}let a8="dexto:customModels";function a9({htmlFor:a,children:b,tooltip:c,className:e}){return(0,d.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,d.jsx)(aQ.J,{htmlFor:a,className:e,children:b}),c&&(0,d.jsx)(t,{delayDuration:200,children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"More information",children:(0,d.jsx)(aS.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"right",className:"max-w-xs",children:(0,d.jsx)("p",{className:"text-sm",children:c})})]})})]})}var ba=c(73148);function bb({provider:a,model:b,providerInfo:c,isFavorite:e,isActive:f,onClick:g,onToggleFavorite:h}){let i=b.displayName||b.name,k=c.hasApiKey,l=a0(b.pricing||void 0),m=[`Max tokens: ${b.maxInputTokens.toLocaleString()}`,b.supportedFileTypes.length>0&&`Supports: ${b.supportedFileTypes.join(", ")}`,!k&&"⚠️ API key required",...l].filter(Boolean);return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsxs)("div",{onClick:g,className:(0,j.cn)("w-full flex items-center gap-4 px-4 py-3 rounded-xl transition-all duration-150 cursor-pointer group","hover:bg-accent/50 hover:shadow-md hover:scale-[1.01]",f&&"bg-primary/10 shadow-md ring-2 ring-primary/20 scale-[1.01]",!k&&"opacity-60"),role:"button",tabIndex:0,children:[(0,d.jsx)("div",{className:"w-6 h-6 flex-shrink-0 flex items-center justify-center",children:a$[a]?(0,d.jsx)(aM.default,{src:a$[a],alt:`${a} logo`,width:24,height:24,className:(0,j.cn)("object-contain",a2(a)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(aS.A,{className:"h-5 w-5 text-muted-foreground"})}),(0,d.jsxs)("div",{className:"flex-1 text-left min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:i}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:a})]}),(0,d.jsx)(a5,{supportedFileTypes:b.supportedFileTypes,hasApiKey:k}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("button",{onClick:a=>{a.stopPropagation(),h()},className:(0,j.cn)("flex-shrink-0 transition-all duration-200","hover:scale-110 active:scale-95",e?"text-yellow-500 hover:text-yellow-400":"text-muted-foreground hover:text-yellow-500"),"aria-label":e?"Remove from favorites":"Add to favorites",children:(0,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4",e&&"fill-current")})})}),(0,d.jsx)(w,{side:"top",children:(0,d.jsx)("span",{children:e?"Remove from favorites":"Add to favorites"})})]})})]})}),(0,d.jsx)(w,{side:"right",className:"max-w-xs",children:(0,d.jsx)("div",{className:"text-xs space-y-0.5",children:m.map((a,b)=>(0,d.jsx)("div",{children:a},b))})})]})})}function bc(){let[a,b]=(0,e.useState)(!1),[c,f]=(0,e.useState)(!1),[h,k]=(0,e.useState)(null),[l,m]=(0,e.useState)({}),[p,q]=(0,e.useState)(""),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(""),[v,w]=(0,e.useState)(""),[y,z]=(0,e.useState)(!1),[A,B]=(0,e.useState)("favorites"),[C,D]=(0,e.useState)([]),[E,F]=(0,e.useState)({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),[G,H]=(0,e.useState)(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),[O,P]=(0,e.useState)(null),{currentSessionId:Q,currentLLM:R,refreshCurrentLLM:S}=(0,i.v)(),T=(0,ba.st)(),U=(0,e.useRef)(T),[V,W]=(0,e.useState)([]),X=(0,e.useCallback)((a,b)=>{let c=`${a}|${b}`;W(a=>{let b=a.includes(c)?a.filter(a=>a!==c):[...a,c];return localStorage.setItem("dexto:modelFavorites",JSON.stringify(b)),b})},[]),Y=(0,e.useCallback)(()=>{let{name:a,baseURL:b,maxInputTokens:c,maxOutputTokens:d}=E;if(!a.trim()||!b.trim())return void k("Model name and Base URL are required");let e=a7(b);if(!e.isValid)return void k(e.error||"Invalid Base URL");let f=[...C,{name:a.trim(),baseURL:b.trim(),maxInputTokens:c?(()=>{let a=parseInt(c,10);return isNaN(a)?void 0:a})():void 0,maxOutputTokens:d?(()=>{let a=parseInt(d,10);return isNaN(a)?void 0:a})():void 0}];D(f),localStorage.setItem(a8,JSON.stringify(f)),F({name:"",baseURL:"",maxInputTokens:"",maxOutputTokens:""}),H(!1),k(null)},[E,C]),Z=(0,e.useCallback)(a=>{let b=C.filter(b=>b.name!==a);D(b),localStorage.setItem(a8,JSON.stringify(b))},[C]);async function $(a,c,d){z(!0),k(null);try{let e=function(a,b){let c=R?.router||"vercel",d=l[a]?.supportedRouters??["vercel"],e=b.supportedRouters??d,f=t||c;return e.includes(f)?f:e[0]||d[0]||"vercel"}(a,c),f={provider:a,model:c.name,router:e};d&&l[a]?.supportsBaseURL&&(f.baseURL=d),Q&&(f.sessionId=Q);let h=await fetch(`${(0,g.e)()}/api/llm/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)}),i=await h.json().catch(()=>({}));if(!h.ok){let a=i?.issues&&i.issues[0]?.message||"Failed to switch model";k(a);return}await S(),R&&U.current.trackLLMSwitched({fromProvider:R.provider,fromModel:R.model,toProvider:a,toModel:c.name,sessionId:Q||void 0,trigger:"user_action"}),b(!1)}catch{k("Network error while switching")}finally{z(!1)}}function _(a,b,c){let d=l[a];if(!d)return;let e=c||v;if(d.supportsBaseURL&&e){let a=a7(e);if(!a.isValid)return void k(a.error||"Invalid base URL")}if(!d.hasApiKey){P({provider:a,model:b.name}),M(a),K(!0);return}$(a,b,e)}let aa=Object.keys(l),ab=R?.displayName||R?.model||"Choose Model",ac=(0,e.useMemo)(()=>V.map(a=>{let[b,c]=a.split("|"),d=l[b],e=d?.models.find(a=>a.name===c);return d&&e?{providerId:b,provider:d,model:e}:null}).filter(Boolean),[V,l]),ad=(0,e.useMemo)(()=>{if(!p)return l;let a={};return aa.forEach(b=>{let c=l[b].models.filter(a=>(function(a,b){let c=p.trim().toLowerCase();return!c||b.name.toLowerCase().includes(c)||(b.displayName?.toLowerCase().includes(c)??!1)||a.toLowerCase().includes(c)||(l[a]?.name.toLowerCase().includes(c)??!1)})(b,a));c.length>0&&(a[b]={...l[b],models:c})}),a},[l,p,aa]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aN.lG,{open:a,onOpenChange:b,children:[(0,d.jsx)(aN.zM,{asChild:!0,children:(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 cursor-pointer",title:"Choose model",children:[R?.provider&&a$[R.provider]?(0,d.jsx)(aM.default,{src:a$[R.provider],alt:`${R.provider} logo`,width:16,height:16,className:(0,j.cn)("object-contain",a2(R.provider)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,d.jsx)(I.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"text-sm",children:ab}),(0,d.jsx)(o.A,{className:"h-3 w-3"})]})}),(0,d.jsxs)(aN.Cf,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[(0,d.jsxs)(aN.c7,{className:"pb-4 flex-shrink-0",children:[(0,d.jsx)(aN.L3,{className:"text-xl",children:"Select Model"}),(0,d.jsx)(aN.rr,{className:"text-sm text-muted-foreground",children:"Choose your favorite model, check all models, or add your own model"})]}),(0,d.jsxs)("div",{className:"flex flex-col min-h-0 flex-1 space-y-4",children:[(0,d.jsxs)("div",{className:"flex-shrink-0 space-y-4",children:[h&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:h})}),(0,d.jsx)(aW,{value:p,onChange:q,placeholder:"Search models, providers..."})]}),!p&&(0,d.jsxs)("div",{className:"flex gap-2 border-b border-border pb-2",children:[(0,d.jsxs)("button",{onClick:()=>B("favorites"),className:(0,j.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,d.jsx)(aT.A,{className:(0,j.cn)("h-4 w-4","favorites"===A&&"fill-current")}),"Favorites",ac.length>0&&(0,d.jsxs)("span",{className:"text-xs opacity-70",children:["(",ac.length,")"]})]}),(0,d.jsxs)("button",{onClick:()=>B("all"),className:(0,j.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,d.jsx)(I.A,{className:"h-4 w-4"}),"All Models"]}),(0,d.jsxs)("button",{onClick:()=>B("custom"),className:(0,j.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,d.jsx)(aU.A,{className:"h-4 w-4"}),"Custom",C.length>0&&(0,d.jsxs)("span",{className:"text-xs opacity-70",children:["(",C.length,")"]})]})]}),(0,d.jsx)("div",{className:"flex-1 overflow-auto px-1 min-h-0",children:c?(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground justify-center py-8",children:[(0,d.jsx)(N.A,{className:"h-4 w-4 animate-spin"})," Loading models..."]}):p?(0,d.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(ad).length?(0,d.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No models found matching your search"}):Object.entries(ad).map(([a,b])=>(0,d.jsx)(a6,{providerId:a,provider:b,models:b.models,favorites:V,currentModel:R||void 0,onToggleFavorite:X,onUse:_},a))}):"favorites"===A?0===ac.length?(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center space-y-3",children:[(0,d.jsx)(aT.A,{className:"h-12 w-12 text-muted-foreground/40"}),(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:"No favorites yet"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"Star models to add them to your favorites"})]})]}):(0,d.jsx)("div",{className:"space-y-2 pb-2",children:ac.map(({providerId:a,provider:b,model:c})=>{var e;let f;return(0,d.jsx)(bb,{provider:a,model:c,providerInfo:b,isFavorite:!0,isActive:(f=c.name,R?.provider===a&&R?.model===f),onClick:()=>_(a,c),onToggleFavorite:()=>X(a,c.name)},(e=c.name,`${a}|${e}`))})}):"custom"===A?(0,d.jsxs)("div",{className:"space-y-4 pb-2",children:[C.length>0&&(0,d.jsx)("div",{className:"space-y-2",children:C.map(a=>(0,d.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"text-sm font-medium",children:a.name}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"openai-compatible"})]}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:a.baseURL})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 ml-2",children:[(0,d.jsx)(x.$,{size:"sm",variant:"ghost",onClick:()=>{_("openai-compatible",{name:a.name,displayName:a.name,maxInputTokens:a.maxInputTokens||128e3,supportedFileTypes:["pdf","image","audio"],supportedRouters:["vercel","in-built"]},a.baseURL)},className:"h-8 px-3",children:"Use"}),(0,d.jsx)(x.$,{size:"sm",variant:"ghost",onClick:()=>Z(a.name),className:"h-8 w-8 p-0 text-destructive hover:text-destructive","aria-label":`Delete custom model ${a.name}`,children:"\xd7"})]})]},a.name))}),(0,d.jsxs)("div",{className:"space-y-3 pt-4 border-t border-border",children:[(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>H(!G),className:"flex items-center justify-between w-full p-0 h-auto hover:bg-transparent",children:[(0,d.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:0===C.length?"Add your first custom model":"Add another model"}),G?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"})]}),G&&(0,d.jsxs)("div",{className:"space-y-4 pl-4 border-l-2 border-muted",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-model-name",tooltip:"Model identifier (e.g., llama3, mixtral, gpt-5)",children:"Model Name *"}),(0,d.jsx)(aP.p,{id:"custom-model-name",value:E.name,onChange:a=>F(b=>({...b,name:a.target.value})),placeholder:"e.g., llama3",className:"text-sm"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-base-url",tooltip:"OpenAI-compatible endpoint URL. Must include /v1 path (e.g., http://localhost:1234/v1)",children:"Base URL *"}),(0,d.jsx)(aP.p,{id:"custom-base-url",value:E.baseURL,onChange:a=>F(b=>({...b,baseURL:a.target.value})),placeholder:"http://localhost:1234/v1",className:"text-sm"})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"custom-max-input",type:"number",value:E.maxInputTokens,onChange:a=>F(b=>({...b,maxInputTokens:a.target.value})),placeholder:"128000",className:"text-sm",min:"1"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"custom-max-output",tooltip:"Maximum output tokens the model can generate. Uses provider's default if not specified",children:"Max Output Tokens"}),(0,d.jsx)(aP.p,{id:"custom-max-output",type:"number",value:E.maxOutputTokens,onChange:a=>F(b=>({...b,maxOutputTokens:a.target.value})),placeholder:"Auto",className:"text-sm",min:"1"})]})]}),(0,d.jsx)(x.$,{onClick:Y,size:"sm",className:"w-full",children:"Add Model"})]})]})]}):(0,d.jsx)("div",{className:"space-y-6 pb-2",children:0===Object.keys(l).length?(0,d.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No providers available"}):Object.entries(l).map(([a,b])=>(0,d.jsx)(a6,{providerId:a,provider:b,models:b.models,favorites:V,currentModel:R||void 0,onToggleFavorite:X,onUse:_},a))})})]})]})]}),L&&(0,d.jsx)(aR,{open:J,onOpenChange:K,provider:L,primaryEnvVar:l[L]?.primaryEnvVar||"",onSaved:function(a){if(m(b=>({...b,[a.provider]:b[a.provider]?{...b[a.provider],hasApiKey:!0}:b[a.provider]})),K(!1),O){let{provider:a,model:b}=O,c=l[a]?.models.find(a=>a.name===b);c&&$(a,c,v),P(null)}}})]})}var bd=c(71335),be=c(35887),bf=c(89615);let bg=({prompt:a,isSelected:b,onClick:c,onMouseEnter:e,dataIndex:f})=>(0,d.jsx)("div",{className:`px-3 py-2 cursor-pointer transition-colors ${b?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"}`,onClick:c,onMouseEnter:e,"data-index":f,children:(0,d.jsxs)("div",{className:"flex items-start gap-2",children:[(0,d.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:"mcp"===a.source?(0,d.jsx)(av.A,{className:"h-3 w-3 text-blue-400"}):"starter"===a.source?(0,d.jsx)("span",{className:"text-xs",children:"\uD83D\uDE80"}):(0,d.jsx)(aZ.A,{className:"h-3 w-3 text-purple-400"})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsxs)("span",{className:"font-medium text-xs text-foreground",children:["/",a.name]}),a.arguments&&a.arguments.length>0&&(0,d.jsx)("span",{className:"flex items-center gap-1",children:a.arguments.map((a,b)=>(0,d.jsxs)("span",{className:"group relative inline-block",title:a.description||a.name,children:[(0,d.jsxs)("span",{className:"text-xs text-muted-foreground/70 hover:text-muted-foreground cursor-help transition-colors",children:["<",a.name,a.required?"":"?",">"]}),a.description&&(0,d.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:a.description})]},a.name))})]}),"mcp"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"MCP"}),"file"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"File"}),"custom"===a.source&&(0,d.jsx)(aX.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"===a.source&&(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Starter"})]}),a.title&&(0,d.jsx)("div",{className:"text-xs font-medium text-foreground/90 mb-0.5",children:a.title}),a.description&&a.description!==a.title&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5 line-clamp-2",children:a.description})]})]})});function bh({isVisible:a,searchQuery:b,onSelectPrompt:c,onClose:g,onCreatePrompt:h,refreshKey:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)([]),[n,o]=(0,e.useState)(!1),[p,q]=(0,e.useState)(0),r=(0,e.useRef)(0),s=(0,e.useRef)(null),t=(0,e.useRef)(null);(0,e.useRef)(0),r.current=p;let u=f().useMemo(()=>{let a=b.trim();return!!a&&!!("/"===a||a.startsWith("/")&&0===l.length)},[b,l.length]);return(f().useMemo(()=>{let a=[];return u&&a.push({kind:"create"}),l.forEach(b=>a.push({kind:"prompt",prompt:b})),a},[u,l]).length,a)?(0,d.jsxs)("div",{ref:s,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,d.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50",children:(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[(0,d.jsx)("span",{children:"Available Prompts (hover over arguments for more info)"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"ml-auto text-xs px-2 py-0.5",children:j.length})]})}),(0,d.jsx)("div",{ref:t,className:"max-h-48 overflow-y-auto",children:n?(0,d.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"Loading prompts..."}):(0,d.jsxs)(d.Fragment,{children:[u&&(0,d.jsxs)("div",{className:`px-3 py-2 cursor-pointer transition-colors ${0===p?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"}`,onClick:()=>h?.(),onMouseEnter:()=>q(0),"data-index":0,children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-foreground",children:[(0,d.jsx)(aU.A,{className:"h-3 w-3 text-primary"}),(0,d.jsx)("span",{children:"Create new prompt"})]}),(0,d.jsx)("div",{className:"text-[11px] text-muted-foreground mt-1",children:"Define a reusable prompt. Press Enter to continue."})]}),0===l.length?!u&&(0,d.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"No prompts available."}):l.map((a,b)=>{let e=u?b+1:b;return(0,d.jsx)(bg,{prompt:a,isSelected:e===p,onClick:()=>c(a),onMouseEnter:()=>q(e),dataIndex:e},a.name)})]})}),(0,d.jsx)("div",{className:"px-2 py-1.5 border-t border-border bg-muted/20 text-xs text-muted-foreground text-center",children:(0,d.jsx)("span",{children:"↑↓ Navigate • Tab/Enter Select • Esc Close"})})]}):null}var bi=c(61295),bj=c(57752),bk=c(50803),bl=c(57045);function bm({open:a,onClose:b,onCreated:c}){let[f,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(!1),B=async a=>{try{var b;let c=await (b=a,new Promise((a,c)=>{let d=new FileReader;d.onload=()=>{let b=d.result;"string"==typeof b?a(b):c(Error("Failed to read file"))},d.onerror=a=>c(a),d.readAsDataURL(b)}));p({base64:c,mimeType:a.type||"application/octet-stream",filename:a.name}),r(c),t(a.name)}catch(a){console.error("Failed to read file:",a),y("Failed to read file. Please try a different file.")}},C=async a=>{let b=a.target.files?.[0];if(!b){p(null),r(null),t(null);return}await B(b)},D=async a=>{a.preventDefault(),A(!1);let b=Array.from(a.dataTransfer.files);b.length>0&&await B(b[0])},E=async a=>{if(a.preventDefault(),!f.trim()||!m.trim())return void y("Name and content are required.");v(!0),y(null);let b={name:f.trim(),title:i.trim()||void 0,description:k.trim()||void 0,content:m,resource:o||void 0};try{let a=await fetch(`${(0,g.e)()}/api/prompts/custom`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(!a.ok){let b=await a.json().catch(()=>({})),c=b?.message||"Failed to create prompt.";throw Error(c)}let d=await a.json();d?.prompt&&c({name:d.prompt.name})}catch(a){console.error("Failed to create prompt:",a),y(a instanceof Error?a.message:"Failed to create prompt. Please try again.")}finally{v(!1)}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-3xl",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create Custom Prompt"}),(0,d.jsx)(aN.rr,{children:"Define reusable prompt text and optionally attach a supporting resource file."})]}),(0,d.jsxs)("form",{onSubmit:E,className:"space-y-4",children:[w&&(0,d.jsx)(aO.Fc,{variant:"destructive",children:(0,d.jsx)(aO.TN,{children:w})}),(0,d.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-name",children:"Prompt Name"}),(0,d.jsx)(aP.p,{id:"prompt-name",value:f,onChange:a=>h(a.target.value),placeholder:"research-summary",required:!0}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Use lowercase letters, numbers, or hyphens. This becomes your /prompt command."})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-title",children:"Title"}),(0,d.jsx)(aP.p,{id:"prompt-title",value:i,onChange:a=>j(a.target.value),placeholder:"Research Summary"})]})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-description",children:"Description"}),(0,d.jsx)(aP.p,{id:"prompt-description",value:k,onChange:a=>l(a.target.value),placeholder:"Summarize research papers with key findings"})]}),(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"prompt-content",children:"Prompt Content"}),(0,d.jsx)(bi.T,{id:"prompt-content",value:m,onChange:a=>n(a.target.value),placeholder:"Write the instructions for this prompt...",className:"min-h-[160px]",required:!0})]}),(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)(aQ.J,{children:"Attach resource (optional)"}),q?(0,d.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,d.jsxs)("div",{className:"flex items-center text-sm",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4 mr-2 text-muted-foreground"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"mr-2",children:"Resource"}),s||"Attached file"]}),(0,d.jsxs)(x.$,{variant:"ghost",size:"sm",onClick:()=>{p(null),r(null),t(null)},children:[(0,d.jsx)(bk.A,{className:"h-4 w-4 mr-1"})," Remove"]})]}):(0,d.jsxs)("div",{className:`relative rounded-lg border-2 border-dashed transition-colors ${z?"border-primary bg-primary/5":"border-border/60 hover:border-border/80"} px-6 py-8 text-center`,onDragOver:a=>{a.preventDefault(),A(!0)},onDragLeave:a=>{a.preventDefault(),A(!1)},onDrop:D,children:[(0,d.jsx)("input",{type:"file",onChange:C,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",accept:"*/*"}),(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center space-y-2",children:[(0,d.jsx)(bl.A,{className:`h-8 w-8 ${z?"text-primary":"text-muted-foreground"}`}),(0,d.jsxs)("div",{className:"text-sm",children:[(0,d.jsx)("span",{className:"font-medium",children:z?"Drop file here":"Click to upload"}),(0,d.jsx)("span",{className:"text-muted-foreground",children:" or drag and drop"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Any file type supported"})]})]}),(0,d.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The resource will be stored securely and referenced when this prompt is used."})]}),(0,d.jsxs)(aN.Es,{className:"flex items-center justify-between gap-2",children:[(0,d.jsx)(x.$,{type:"button",variant:"ghost",onClick:b,disabled:u,children:"Cancel"}),(0,d.jsx)(x.$,{type:"submit",disabled:u,children:u?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.A,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):"Save Prompt"})]})]})]})})}function bn({open:a,onClose:b,onSuccess:c}){let[f,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(""),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)(null),o=async()=>{if(!f.trim())return void n("Memory content is required");l(!0),n(null);try{let a={content:f.trim(),...i.trim()&&{tags:i.split(",").map(a=>a.trim()).filter(Boolean)},metadata:{source:"user"}},d=await fetch(`${(0,g.e)()}/api/memory`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){let a=await d.json();throw Error(a.error||"Failed to create memory")}h(""),j(""),c?.(),b()}catch(a){n(a instanceof Error?a.message:"Failed to create memory")}finally{l(!1)}},p=()=>{k||(h(""),j(""),n(null),b())};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:p,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-[500px]",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create Memory"}),(0,d.jsx)(aN.rr,{children:"Memories are automatically included in every conversation to help Dexto remember your preferences and important information."})]}),(0,d.jsxs)("div",{className:"grid gap-4 py-4",children:[m&&(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(bd.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:m})]}),(0,d.jsxs)("div",{className:"grid gap-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"memory-content",children:"Memory Content *"}),(0,d.jsx)(bi.T,{id:"memory-content",placeholder:"e.g., I prefer concise responses without explanations",value:f,onChange:a=>h(a.target.value),className:"min-h-[100px] resize-none",disabled:k,autoFocus:!0}),(0,d.jsxs)("p",{className:"text-sm text-muted-foreground",children:[f.length," / 10,000 characters"]})]}),(0,d.jsxs)("div",{className:"grid gap-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"memory-tags",children:"Tags (optional)"}),(0,d.jsx)(aP.p,{id:"memory-tags",placeholder:"e.g., preferences, work, coding-style",value:i,onChange:a=>j(a.target.value),disabled:k}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Comma-separated tags for organizing memories"})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:p,disabled:k,children:"Cancel"}),(0,d.jsx)(x.$,{onClick:o,disabled:k||!f.trim(),children:k?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Memory"})]})]})})}function bo({onSend:a,isSending:b,variant:c="chat"}){let[h,k]=(0,e.useState)(""),l=(0,e.useRef)(null),[m,n]=(0,e.useState)(null),[o,q]=(0,e.useState)(null),r=(0,e.useRef)(null),s=(0,e.useRef)(null),t=(0,e.useRef)(null),u=function(){let[a,b]=(0,e.useState)(!1);return a}(),[v,w]=(0,e.useState)(!1),y=(0,e.useRef)(null),{currentSessionId:z,isStreaming:B,setStreaming:C,cancel:D,processing:E,currentLLM:F}=(0,i.v)(),G=(0,ba.st)(),H=(0,e.useRef)(G),[I,J]=(0,e.useState)(null),[K,L]=(0,e.useState)(!1),[M,P]=(0,e.useState)(null),[R,S]=(0,e.useState)(null),[T,U]=(0,e.useState)([]),{resources:V,loading:W,refresh:X}=ag(),[Y,Z]=(0,e.useState)(""),[$,_]=(0,e.useState)(!1),[aa,ab]=(0,e.useState)(0),[ac,ad]=(0,e.useState)(null),ae=(0,e.useMemo)(()=>(0,j.L)(V,Y),[V,Y]),[af,ah]=(0,e.useState)(!1),[ai,aj]=(0,e.useState)(!1),[ak,al]=(0,e.useState)(0),[am,an]=(0,e.useState)(!1),ao=a=>{S(a),setTimeout(()=>S(null),5e3)},ap=f().useCallback(()=>{ah(!1),aj(!0)},[]),aq=f().useCallback(a=>{(0,bf.w)(),aj(!1),al(a=>a+1);let b=`/${a.name}`;k(b),l.current&&(l.current.focus(),l.current.setSelectionRange(b.length,b.length))},[]),ar=f().useCallback(()=>{aj(!1),"/"===h&&k("")},[h]),av=async()=>{let b=h.trim();if(b||m||o){if("/"===b)return void ap();if(b.startsWith("/")){let a=function(a){let b=a.trim();if(!b.startsWith("/"))return{isSlash:!1,command:"",argsArray:[],argsText:""};let c=function(a){let b=[],c="",d=!1,e="",f=0;for(;f<a.length;){let g=a[f],h=a[f+1];d||'"'!==g&&"'"!==g?d&&g===e?(d=!1,e=""):d||" "!==g?"\\"===g&&h?(c+=h,f++):c+=g:c&&(b.push(c),c=""):(d=!0,e=g),f++}return c&&b.push(c),b.filter(Boolean)}(b.slice(1)),d=c[0]||"",e=c.slice(1),f=e.join(" ");return{isSlash:!0,command:d,argsArray:e,argsText:f}}(b),c=a.command,d=b.slice(1+c.length).trimStart();if(c)try{let e=new URL(`/api/prompts/${encodeURIComponent(c)}/resolve`,(0,g.e)());if(a.argsArray&&a.argsArray.length>0){let{keyValues:b,positional:c}=function(a){let b={},c=[];for(let d of a){let a=d.indexOf("=");if(a>0){let c=d.slice(0,a).trim(),e=d.slice(a+1);if(c.length>0){b[c]=e;continue}}c.push(d)}return{keyValues:b,positional:c}}(a.argsArray),d={...b};if(c.length>0&&(d._positional=c),Object.keys(d).length>0)try{e.searchParams.set("args",JSON.stringify(d))}catch{}}d&&e.searchParams.set("context",d);let f=new AbortController,h=setTimeout(()=>f.abort(),5e3);try{let a=await fetch(e.toString(),{signal:f.signal});if(clearTimeout(h),a.ok){let c=await a.json(),d="string"==typeof c?.text?c.text:"";d.trim()&&(b=d)}}finally{clearTimeout(h)}}catch{}}a(b,m??void 0,o??void 0),k(""),n(null),q(null),ah(!1)}},aw=a=>{if($){if("ArrowDown"===a.key){a.preventDefault(),ab(a=>(a+1)%Math.max(1,ae.length));return}if("ArrowUp"===a.key){a.preventDefault(),ab(a=>(a-1+Math.max(1,ae.length))%Math.max(1,ae.length));return}if("Enter"===a.key||"Tab"===a.key){a.preventDefault(),((a,b)=>{if(0===ae.length)return;let c=b??ae[Math.max(0,Math.min(a,ae.length-1))],d=l.current;if(!d)return;let e=d.selectionStart??h.length,f=((a,b)=>{for(let c=b-1;c>=0;c--){let b=a[c];if("@"===b){if(0===c)return c;let b=a[c-1];if(/\s/.test(b))return c;break}if(/\s/.test(b))break}return -1})(h,e);if(-1===f)return;let g=h.slice(0,f),i=h.slice(e),j=c.name||c.uri.split("/").pop()||c.uri,m=c.serverName?`@${c.serverName}:${j}`:`@${j}`;k(g+m+i),_(!1),Z(""),ab(0),requestAnimationFrame(()=>{let a=(g+m).length;d.setSelectionRange(a,a),d.focus()})})(aa);return}if("Escape"===a.key)return void _(!1)}if(ax&&"Escape"===a.key){a.preventDefault(),az(!1),k("");return}if("Enter"===a.key&&!a.shiftKey){if(a.preventDefault(),"#"===h.trim()){k(""),az(!1),an(!0);return}av()}},[ax,az]=(0,e.useState)(!1),[aA,aB]=(0,e.useState)(null),aC=a=>{let b=a.target.value;if(k(b),b.startsWith("/")&&!b.includes("\n")?ah(!0):af&&ah(!1),"#"===b.trim()){az(!0);let a=l.current;if(a){let b=a.getBoundingClientRect(),c=Math.max(8,b.left+window.scrollX+16),d=Math.max(280,b.width-32);aB({position:"fixed",left:c,bottom:Math.max(80,window.innerHeight-(b.bottom+window.scrollY)+64),width:d,zIndex:9999})}}else az(!1),aB(null)};f().useRef(!1);let aD=a=>{let b=a.clipboardData.getData("text/plain");if(b&&!(b.length<=2e4))if(a.preventDefault(),window.confirm("Large text detected. Attach as a file instead of inflating the input?\n(OK = attach as file, Cancel = paste truncated preview)"))q({base64:(a=>{try{return btoa(unescape(encodeURIComponent(a)))}catch{return btoa(a)}})(b),mimeType:"text/plain",filename:"pasted.txt"});else{let a=b.slice(0,2e4);k(b=>b+a)}},aE=async()=>{try{let a=await navigator.mediaDevices.getUserMedia({audio:!0}),b=new MediaRecorder(a);y.current=b;let c=[];b.ondataavailable=a=>{a.data.size>0&&c.push(a.data)},b.onstop=()=>{let d=new Blob(c,{type:b.mimeType}),e=new FileReader;e.onloadend=()=>{try{let a=e.result,c=a.indexOf(","),f=a.substring(c+1),g=b.mimeType||"audio/webm",h={"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"}[g]||g.split("/")[1]||"webm";q({base64:f,mimeType:g,filename:`recording.${h}`}),z&&H.current.trackFileUploaded({fileType:g,fileSizeBytes:d.size,sessionId:z})}catch(a){ao("Failed to process audio recording. Please try again."),q(null)}},e.readAsDataURL(d),a.getTracks().forEach(a=>a.stop())},b.start(),w(!0)}catch(a){ao("Failed to start audio recording. Please check microphone permissions.")}};return h.length,(0,d.jsxs)("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[M&&(0,d.jsxs)(aO.Fc,{variant:"destructive",className:"mb-2",children:[(0,d.jsx)(bd.A,{className:"h-4 w-4"}),(0,d.jsxs)(aO.TN,{className:"flex items-center justify-between",children:[(0,d.jsx)("span",{children:M}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>P(null),className:"h-auto p-1 ml-2",children:(0,d.jsx)(p.A,{className:"h-3 w-3"})})]})]}),R&&(0,d.jsxs)(aO.Fc,{variant:"destructive",className:"mb-2",children:[(0,d.jsx)(bd.A,{className:"h-4 w-4"}),(0,d.jsxs)(aO.TN,{className:"flex items-center justify-between",children:[(0,d.jsx)("span",{children:R}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>S(null),className:"h-auto p-1 ml-2",children:(0,d.jsx)(p.A,{className:"h-3 w-3"})})]})]}),(0,d.jsxs)("div",{className:"w-full",children:[(0,d.jsx)("form",{onSubmit:a=>{a.preventDefault(),av()},children:(0,d.jsxs)(at,{children:[(m||o)&&(0,d.jsx)("div",{className:"px-4 pt-4",children:(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[m&&(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-1 bg-muted/50 group",children:[(0,d.jsx)("img",{src:`data:${m.mimeType};base64,${m.base64}`,alt:"preview",className:"h-12 w-auto rounded-md"}),(0,d.jsx)(x.$,{variant:"destructive",size:"icon",onClick:()=>n(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,d.jsx)(p.A,{className:"h-2 w-2"})})]}),o&&(0,d.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[o.mimeType.startsWith("audio")?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(O.A,{className:"h-4 w-4"}),(0,d.jsx)("audio",{controls:!0,src:`data:${o.mimeType};base64,${o.base64}`,className:"h-8"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Q.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"text-xs font-medium max-w-[160px] truncate",children:o.filename||"attachment"})]}),(0,d.jsx)(x.$,{variant:"destructive",size:"icon",onClick:()=>q(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,d.jsx)(p.A,{className:"h-2 w-2"})})]})]})}),(0,d.jsxs)("div",{className:"flex-auto overflow-y-auto relative",children:[u?(0,d.jsx)(as.A,{ref:l,value:h,onChange:aC,onKeyDown:aw,onPaste:aD,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,d.jsx)("textarea",{ref:l,rows:1,value:h,onChange:aC,onKeyDown:aw,onPaste:aD,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"}),$&&ac&&!1,ax&&aA&&!1]}),(0,d.jsx)(bh,{isVisible:af,searchQuery:h,onSelectPrompt:a=>{let b=`/${a.name}`;k(b),ah(!1),l.current&&(l.current.focus(),l.current.setSelectionRange(b.length,b.length))},onClose:()=>{ah(!1)},onCreatePrompt:ap,refreshKey:ak}),(0,d.jsx)(au,{leftButtons:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(aI,{onImageAttach:()=>r.current?.click(),onPdfAttach:()=>s.current?.click(),onAudioAttach:()=>t.current?.click(),supports:{image:T.length?T.includes("image"):void 0,pdf:T.length?T.includes("pdf"):void 0,audio:T.length?T.includes("audio"):void 0}}),(0,d.jsx)(aL,{isRecording:v,onToggleRecording:v?()=>{y.current?.stop(),w(!1)}:aE,disabled:!T.includes("audio")})]}),rightButtons:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("div",{className:"hidden md:block",children:(0,d.jsx)(ay,{isStreaming:B,onStreamingChange:C})}),(0,d.jsx)(bc,{}),(0,d.jsx)(x.$,{type:E?"button":"submit",onClick:E?()=>D(z||void 0):void 0,disabled:!E&&(!h.trim()&&!m&&!o||b),className:(0,j.cn)("h-10 w-10 p-0 rounded-full transition-all duration-200",E?"bg-secondary/80 text-secondary-foreground hover:bg-secondary shadow-sm hover:shadow-md border border-border/50":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-lg"),"aria-label":E?"Stop":"Send message",title:E?"Stop":"Send",children:E?(0,d.jsx)(A.A,{className:"h-3.5 w-3.5 fill-current"}):b?(0,d.jsx)(N.A,{className:"h-4 w-4 animate-spin"}):(0,d.jsx)(be.A,{className:"h-4 w-4"})})]})})]})}),(0,d.jsx)("input",{ref:r,type:"file",id:"image-upload",accept:"image/*",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){ao("Image file too large. Maximum size is 64MB."),a.target.value="";return}if(!b.type.startsWith("image/")){ao("Please select a valid image file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(",");if(-1===d)throw Error("Invalid Data URL format");let e=a.substring(0,d),f=a.substring(d+1),g=e.match(/data:(.*);base64/),h=g?g[1]:b.type;if(!h)throw Error("Could not determine MIME type");n({base64:f,mimeType:h}),S(null),z&&H.current.trackImageUploaded({imageType:h,imageSizeBytes:b.size,sessionId:z})}catch(a){ao("Failed to process image file. Please try again."),n(null)}},c.onerror=a=>{ao("Failed to read image file. Please try again."),n(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)("input",{ref:s,type:"file",id:"pdf-upload",accept:"application/pdf",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){ao("PDF file too large. Maximum size is 64MB."),a.target.value="";return}if("application/pdf"!==b.type){ao("Please select a valid PDF file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(","),e=a.substring(d+1);q({base64:e,mimeType:"application/pdf",filename:b.name}),S(null),z&&H.current.trackFileUploaded({fileType:"application/pdf",fileSizeBytes:b.size,sessionId:z})}catch(a){ao("Failed to process PDF file. Please try again."),q(null)}},c.onerror=a=>{ao("Failed to read PDF file. Please try again."),q(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)("input",{ref:t,type:"file",id:"audio-upload",accept:"audio/*",className:"hidden",onChange:a=>{let b=a.target.files?.[0];if(!b)return;if(b.size>0x4000000){ao("Audio file too large. Maximum size is 64MB."),a.target.value="";return}if(!b.type.startsWith("audio/")){ao("Please select a valid audio file."),a.target.value="";return}let c=new FileReader;c.onloadend=()=>{try{let a=c.result,d=a.indexOf(","),e=a.substring(d+1);q({base64:e,mimeType:b.type,filename:b.name}),S(null),z&&H.current.trackFileUploaded({fileType:b.type,fileSizeBytes:b.size,sessionId:z})}catch(a){ao("Failed to process audio file. Please try again."),q(null)}},c.onerror=a=>{ao("Failed to read audio file. Please try again."),q(null)},c.readAsDataURL(b),a.target.value=""}}),(0,d.jsx)(bm,{open:ai,onClose:ar,onCreated:aq}),(0,d.jsx)(bn,{open:am,onClose:()=>an(!1),onSuccess:()=>{}})]})]})}var bp=c(24617);let bq=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 br{constructor(){this.registryEntries=[],this.isInitialized=!1}static normalizeId(a){return a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return br.instance||(br.instance=new br),br.instance}async initialize(){this.isInitialized||(this.registryEntries=this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(a){await this.initialize();let b=[...this.registryEntries];if(a?.category&&(b=b.filter(b=>b.category===a.category)),a?.tags?.length&&(b=b.filter(b=>a.tags.some(a=>b.tags.includes(a)))),a?.search){let c=a.search.toLowerCase();b=b.filter(a=>a.name.toLowerCase().includes(c)||a.description.toLowerCase().includes(c)||a.tags.some(a=>a.toLowerCase().includes(c)))}return a?.installed!==void 0&&(b=b.filter(b=>b.isInstalled===a.installed)),a?.official!==void 0&&(b=b.filter(b=>b.isOfficial===a.official)),b.sort((a,b)=>a.isInstalled!==b.isInstalled?a.isInstalled?-1:1:a.isOfficial!==b.isOfficial?a.isOfficial?-1:1:a.name.localeCompare(b.name))}async updateEntry(a,b){let c=this.registryEntries.findIndex(b=>b.id===a);return -1!==c&&(this.registryEntries[c]={...this.registryEntries[c],...b},!0)}async setInstalled(a,b){return this.updateEntry(a,{isInstalled:b})}async syncWithServerStatus(){try{if(await this.initialize(),0===this.registryEntries.length)return void console.warn("Registry entries not available for status sync");let a=new AbortController,b=setTimeout(()=>a.abort(),1e4),c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{signal:a.signal});if(clearTimeout(b),!c.ok)return;let d=(await c.json()).servers||[],e=new Set;for(let a of(d.forEach(a=>{if(!a?.id||"string"!=typeof a.id)return;let b=br.normalizeId(a.id);e.add(b)}),this.registryEntries)){let b=[a.id,a.name,...a.matchIds||[]].filter(Boolean).map(a=>br.normalizeId(String(a))).some(a=>e.has(a));a.isInstalled!==b&&(a.isInstalled=b)}}catch(a){console.warn("Failed to sync registry with server status:",a)}}async getServerConfig(a){return await this.initialize(),this.registryEntries.find(b=>b.id===a)||null}getBuiltinEntries(){return bq}}let bs=br.getInstance();function bt({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card",className:(0,j.cn)("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...b})}function bu({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-header",className:(0,j.cn)("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...b})}function bv({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-title",className:(0,j.cn)("leading-none font-semibold",a),...b})}function bw({className:a,...b}){return(0,d.jsx)("div",{"data-slot":"card-content",className:(0,j.cn)("px-6",a),...b})}var bx=c(52679),by=c(76021),bz=c(53801),bA=c(75116),bB=c(10362),bC=c(39612);function bD({isOpen:a,onClose:b,onInstallServer:c,onOpenConnectModal:f,refreshTrigger:g,disableClose:h=!1}){let[i,k]=(0,e.useState)([]),[l,m]=(0,e.useState)([]),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(null),[w,y]=(0,e.useState)({}),[z,A]=(0,e.useState)(""),[B,C]=(0,e.useState)("grid"),[D,E]=(0,e.useState)(null);(0,e.useRef)(null);let F=(0,e.useRef)(!0);(0,e.useRef)(null),(0,e.useCallback)(async(a,b)=>{if(F.current)try{let c=await bs.getEntries({...a,search:b||void 0});F.current&&m(c)}catch(a){F.current&&t(a instanceof Error?a.message:"Failed to filter entries")}},[]);let G=async a=>{if(F.current){v(a.id);try{let b=await c(a);"connected"===b?(await bs.setInstalled(a.id,!0),F.current&&(k(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!0}:b)),m(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!0}:b)))):F.current&&(k(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!1}:b)),m(b=>b.map(b=>b.id===a.id?{...b,isInstalled:!1}:b)))}catch(a){F.current&&t(a instanceof Error?a.message:"Failed to install server")}finally{F.current&&v(null)}}},H=a=>{let b={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 b[a]||b.custom},I=h||!!u,J=(0,e.useCallback)(a=>{a||I||b()},[I,b]),K=I?a=>{a.preventDefault()}:void 0;return(0,d.jsx)(aN.lG,{open:a,onOpenChange:J,children:(0,d.jsxs)(aN.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:I?a=>a.preventDefault():void 0,onInteractOutside:K,children:[(0,d.jsx)(aN.c7,{className:"pb-4 border-b px-6 pt-5 bg-gradient-to-r from-muted/30 via-transparent to-transparent",children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:(0,d.jsx)(bx.A,{className:"h-5 w-5 text-primary"})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)(aN.L3,{className:"text-lg font-semibold leading-tight mb-1",children:"MCP Server Registry"}),(0,d.jsx)(aN.rr,{className:"text-sm text-muted-foreground",children:"Discover and add integrations to your AI assistant"})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)(x.$,{onClick:()=>{I||b(),f?.()},size:"sm",variant:"outline",className:"h-8 px-3 text-sm font-medium hover:bg-muted whitespace-nowrap",children:[(0,d.jsx)(by.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Connect Custom"]}),(0,d.jsxs)(x.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(),disabled:I,children:[(0,d.jsx)(p.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}),(0,d.jsxs)("div",{className:"flex gap-3 mb-5 px-6 pt-5",children:[(0,d.jsxs)("div",{className:"relative flex-1",children:[(0,d.jsx)(aV.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,d.jsx)(aP.p,{placeholder:"Search servers and integrations...",value:z,onChange:a=>A(a.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,d.jsxs)("div",{className:"flex bg-muted/50 rounded-md p-1 border",children:[(0,d.jsxs)(x.$,{variant:"grid"===B?"secondary":"ghost",size:"sm",onClick:()=>{C("grid"),E(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","grid"===B?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,d.jsx)(bz.A,{className:"h-3.5 w-3.5 mr-1.5"}),"Grid"]}),(0,d.jsxs)(x.$,{variant:"list"===B?"secondary":"ghost",size:"sm",onClick:()=>{C("list"),E(null)},className:(0,j.cn)("h-8 px-3 rounded-sm transition-all text-sm font-medium","list"===B?"bg-background shadow-sm":"hover:bg-background/50"),children:[(0,d.jsx)(bA.A,{className:"h-3.5 w-3.5 mr-1.5"}),"List"]})]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:[s&&(0,d.jsx)(aO.Fc,{variant:"destructive",className:"mb-6 border-2 border-red-300 bg-red-50 shadow-md",children:(0,d.jsx)(aO.TN,{className:"text-red-800 font-medium",children:s})}),q?(0,d.jsx)("div",{className:"flex items-center justify-center py-24",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-5",children:[(0,d.jsx)("div",{className:"h-12 w-12 border-4 border-primary/30 border-t-primary rounded-full animate-spin"}),(0,d.jsx)("div",{className:"text-lg text-foreground font-semibold",children:"Discovering servers..."}),(0,d.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading registry entries"})]})}):0===l.length?(0,d.jsxs)("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[(0,d.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,d.jsx)(bx.A,{className:"h-14 w-14 text-muted-foreground/60 mx-auto"})}),(0,d.jsx)("div",{className:"text-xl font-bold text-foreground mb-3",children:0===i.length?"No servers available in the registry":"No servers match your search"}),(0,d.jsx)("div",{className:"text-base text-muted-foreground/80 mb-6 max-w-md",children:0===i.length?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),z&&(0,d.jsxs)(x.$,{variant:"outline",onClick:()=>A(""),className:"border-2 border-primary/30 hover:bg-primary/10 hover:border-primary/50 font-semibold",children:[(0,d.jsx)(aV.A,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):(0,d.jsx)("div",{className:(0,j.cn)("grid"===B?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6":"space-y-3"),children:l.map((a,b)=>{let c=D===a.id,e=a.description&&a.description.length>100;return"grid"===B?(0,d.jsx)(bt,{className:(0,j.cn)("group relative overflow-hidden transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-lg hover:border-primary/30 flex flex-col",c&&"ring-1 ring-primary/20 border-primary/40 shadow-lg -translate-y-0.5"),style:{animationDelay:`${Math.min(30*b,300)}ms`},children:(0,d.jsxs)("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>E(c?null:a.id),children:[(0,d.jsx)(bu,{className:"pb-3 flex-shrink-0",children:(0,d.jsxs)("div",{className:"flex items-start gap-3 mb-3",children:[(0,d.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,d.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:a.icon||"⚡"}),a.isInstalled&&(0,d.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,d.jsx)(M.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)(bv,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-snug line-clamp-2",children:a.name}),(0,d.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.isOfficial&&(0,d.jsxs)(aX.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,d.jsx)(aT.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),a.category&&(0,d.jsx)(aX.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",H(a.category)),children:a.category})]})]})]})}),(0,d.jsxs)(bw,{className:"pt-0 flex flex-col flex-1",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",c?"":"line-clamp-3"),children:a.description}),c&&(0,d.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:[a.author&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,d.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,d.jsx)(bB.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,d.jsxs)("div",{children:[(0,d.jsx)("span",{className:"text-muted-foreground/70",children:"by "}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:a.author})]})]}),a.tags&&a.tags.length>0&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,6).map(a=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:a},a)),a.tags.length>6&&(0,d.jsxs)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0 text-muted-foreground border-border/40 bg-muted/20",children:["+",a.tags.length-6]})]}),a.homepage&&(0,d.jsxs)("a",{href:a.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)(bC.A,{className:"h-3 w-3"}),"Documentation"]})]})]}),(0,d.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border/30 flex-shrink-0 mt-auto",children:[e&&(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-foreground p-0 h-auto font-medium -ml-1",children:c?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(n.A,{className:"h-3 w-3 mr-1"}),"Less"]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.A,{className:"h-3 w-3 mr-1"}),"More"]})}),(0,d.jsx)("div",{className:"ml-auto",children:(0,d.jsx)(x.$,{onClick:b=>{b.stopPropagation(),G(a)},disabled:a.isInstalled||u===a.id,size:"sm",variant:a.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 transition-all font-semibold text-sm shadow-sm",u===a.id&&"opacity-70",a.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!a.isInstalled&&"bg-primary hover:bg-primary/90"),children:u===a.id?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,d.jsx)("span",{children:"Adding"})]}):a.isInstalled?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(M.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Added"})]}):(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(aU.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Add"})]})})})]})]})]})},a.id):(0,d.jsx)(bt,{className:(0,j.cn)("group transition-all duration-200 hover:-translate-y-0.5 border bg-card shadow-sm hover:shadow-md hover:border-primary/30 cursor-pointer !py-0 !gap-0",c&&"border-primary/40 shadow-md -translate-y-0.5"),onClick:()=>E(c?null:a.id),children:(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)("div",{className:"flex items-start gap-4",children:[(0,d.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,d.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:a.icon||"⚡"}),a.isInstalled&&(0,d.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,d.jsx)(M.A,{className:"h-2.5 w-2.5 text-white"})})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-0 space-y-2.5",children:[(0,d.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,d.jsx)("h3",{className:"text-base font-semibold text-foreground group-hover:text-primary transition-colors leading-snug",children:a.name}),e&&(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",c&&"rotate-180 text-muted-foreground")})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.isOfficial&&(0,d.jsxs)(aX.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,d.jsx)(aT.A,{className:"h-2.5 w-2.5 mr-1 fill-blue-400 text-blue-400"}),"Official"]}),a.category&&(0,d.jsx)(aX.E,{variant:"outline",className:(0,j.cn)("text-xs px-1.5 py-0 font-medium capitalize",H(a.category)),children:a.category})]})]}),(0,d.jsx)(x.$,{onClick:b=>{b.stopPropagation(),G(a)},disabled:a.isInstalled||u===a.id,size:"sm",variant:a.isInstalled?"outline":"default",className:(0,j.cn)("h-8 px-4 text-sm font-semibold transition-all flex-shrink-0 shadow-sm",u===a.id&&"opacity-70",a.isInstalled&&"border bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",!a.isInstalled&&"bg-primary hover:bg-primary/90"),children:u===a.id?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,d.jsx)("span",{children:"Adding"})]}):a.isInstalled?(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(M.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Added"})]}):(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,d.jsx)(aU.A,{className:"h-3.5 w-3.5"}),(0,d.jsx)("span",{children:"Add"})]})})]}),(0,d.jsx)("div",{children:(0,d.jsx)("p",{className:(0,j.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-200",c?"":"line-clamp-2"),children:a.description})}),c&&(0,d.jsxs)("div",{className:"space-y-3 pt-3 border-t border-border/30 animate-in slide-in-from-top-2 duration-200",children:[a.author&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,d.jsx)("div",{className:"p-1 rounded bg-muted/40",children:(0,d.jsx)(bB.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,d.jsxs)("div",{children:[(0,d.jsx)("span",{className:"text-muted-foreground/70",children:"by "}),(0,d.jsx)("span",{className:"font-medium text-foreground",children:a.author})]})]}),a.tags&&a.tags.length>0&&(0,d.jsx)("div",{className:"flex flex-wrap gap-1.5",children:a.tags.map(a=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-muted/20 font-normal",children:a},a))}),a.homepage&&(0,d.jsxs)("a",{href:a.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors font-medium",onClick:a=>a.stopPropagation(),children:[(0,d.jsx)(bC.A,{className:"h-3 w-3"}),"Documentation"]})]})]})]})})},a.id)})})]})]})})}var bE=c(66180),bF=c(81202),bG=c(99330),bH=c(41508);let bI=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),bJ=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],bK=[/^your[\s_-]?/,/^enter[\s_-]?/];function bL(a){return Object.values(a).some(a=>{if(!a||""===a.trim())return!0;let b=a.trim().toLowerCase();return!!(bI.has(b)||bK.some(a=>a.test(b)))||bJ.some(a=>b.includes(a))})}function bM(a){let b=a.config.timeout??3e4;switch(a.config.type){case"stdio":return{type:"stdio",command:a.config.command??"",args:a.config.args??[],env:a.config.env??{},timeout:b,connectionMode:"lenient"};case"sse":return{type:"sse",url:a.config.url??"",headers:a.config.headers??{},timeout:b,connectionMode:"lenient"};default:return{type:"http",url:a.config.url??"",headers:a.config.headers??{},timeout:b,connectionMode:"lenient"}}}let bN=`${(0,g.e)()}/api`;function bO({isOpen:a,onClose:b,onOpenConnectModal:c,onOpenConnectWithPrefill:f,onServerConnected:h,variant:i,refreshTrigger:k}){let l=(0,ba.st)(),[n,q]=(0,e.useState)([]),[r,s]=(0,e.useState)(null),[t,y]=(0,e.useState)([]),[z,A]=(0,e.useState)(!1),[B,C]=(0,e.useState)(!1),[D,E]=(0,e.useState)(null),[F,G]=(0,e.useState)(null),[H,I]=(0,e.useState)(!1),[J,K]=(0,e.useState)(null),[L,M]=(0,e.useState)(null),[N,O]=(0,e.useState)(!1),[P,Q]=(0,e.useState)(!1),R=(a,b)=>{console.error(`ServersPanel Error (${b}):`,a),"servers"===b&&E(a),"tools"===b&&G(a)},S=(0,e.useCallback)(async a=>{A(!0),E(null),q([]),s(null),y([]),G(null);try{let b=await fetch(`${bN}/mcp/servers`,a?{signal:a}:{});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to fetch servers"}));throw Error(a.message||a.error||`Server List: ${b.statusText}`)}let c=(await b.json()).servers||[];if(q(c),c.length>0){let a=c.find(a=>"connected"===a.status);a?s(a.id):c.length>0&&s(c[0].id)}else console.log("No MCP servers found or returned from API.")}catch(a){"AbortError"!==a.name&&R(a.message,"servers")}finally{a?.aborted||A(!1)}},[]),T=async a=>{let b=bM(a),c="stdio"===b.type&&Object.keys(b.env||{}).length>0&&bL(b.env||{}),d=("sse"===b.type||"http"===b.type)&&Object.keys(b.headers||{}).length>0&&bL(b.headers||{});if(c||d)return"function"==typeof f&&f({name:a.name,config:b,lockName:!0,registryEntryId:a.id,onCloseRegistryModal:()=>O(!1)}),"requires-input";try{Q(!0);let c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,config:b,persistToAgent:!1})}),d=await c.json();if(!c.ok)throw Error(d.error||`Server returned status ${c.status}`);await S();try{await bs.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry after server install:",a)}return l.trackMCPServerConnected({serverName:a.name,transportType:b.type}),O(!1),h?.(a.name),"connected"}catch(a){throw Error(a.message||"Failed to install server")}finally{Q(!1)}},U=async a=>{let b=n.find(b=>b.id===a);if(b&&window.confirm(`Are you sure you want to remove server "${b.name}"?`)){K(a),E(null);try{let b=await fetch(`${bN}/mcp/servers/${a}`,{method:"DELETE"});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to remove server"}));throw Error(a.message||a.error||`Server Removal: ${b.statusText}`)}r===a&&(s(null),y([]));try{let b=a=>a.toLowerCase().replace(/[^a-z0-9]+/g,"-"),c=b(a),d=(await bs.getEntries()).find(a=>[a.id,a.name,...a.matchIds||[]].filter(Boolean).map(a=>b(String(a))).includes(c));d&&await bs.setInstalled(d.id,!1)}catch(a){console.warn("Failed to update registry installed state on delete:",a)}await S(),(0,bf.w)();try{await bs.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry status after server deletion:",a)}}catch(a){R(a.message,"servers")}finally{K(null)}}},V=async a=>{let b=n.find(b=>b.id===a);if(b&&window.confirm(`Restart server "${b.name}"?`)){M(a),E(null);try{let b=await fetch(`${bN}/mcp/servers/${a}/restart`,{method:"POST"});if(!b.ok){let a=await b.json().catch(()=>({error:"Failed to restart server"}));throw Error(a.message||a.error||`Server Restart: ${b.statusText}`)}await S(),(0,bf.w)();try{await bs.syncWithServerStatus()}catch(a){console.warn("Failed to sync registry status after server restart:",a)}}catch(a){R(a.message,"servers")}finally{M(null)}}};(0,e.useCallback)(async(a,b)=>{let c=n.find(b=>b.id===a);if(y([]),G(null),!c||"connected"!==c.status)return void console.warn(`Server "${c?.name||a}" is not connected or not found. Cannot fetch tools.`);C(!0);try{let d=await fetch(`${bN}/mcp/servers/${a}/tools`,b?{signal:b}:{});if(!d.ok){let a=await d.json().catch(()=>({error:`Failed to fetch tools for ${c.name}`}));throw Error(a.message||a.error||`Tool List (${c.name}): ${d.statusText}`)}let e=await d.json();b?.aborted||y(e.tools||[]),e.tools&&0!==e.tools.length||console.log(`No tools found for server "${c.name}".`)}catch(a){"AbortError"!==a.name&&R(a.message,"tools")}finally{b?.aborted||C(!1)}},[n]);let W=n.find(a=>a.id===r);return"inline"===(i??"overlay")?(0,d.jsxs)("aside",{className:"h-full w-full flex flex-col bg-card",children:[(0,d.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,d.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,d.jsx)("div",{className:"flex items-center space-x-1",children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>S(),disabled:z,className:"h-8 w-8 p-0",children:(0,d.jsx)(bE.A,{className:(0,j.cn)("h-3.5 w-3.5",z&&"animate-spin")})})})]}),(0,d.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,d.jsxs)(x.$,{onClick:()=>O(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,d.jsx)(bF.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,d.jsxs)(x.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,d.jsx)(aY.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,d.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",n.length,")"]})}),z&&(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bE.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),D&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:D})]})]})}),!z&&0===n.length&&!D&&(0,d.jsxs)("div",{className:"text-center py-8",children:[(0,d.jsx)(bx.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),n.map(a=>(0,d.jsx)("div",{onClick:()=>s(a.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",r===a.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===a.status?"bg-green-500":"error"===a.status?"bg-red-500":"bg-yellow-500")}),(0,d.jsx)("h4",{className:"text-sm font-medium truncate",children:a.name})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:a.status})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[L===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Restarting ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),V(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":`Restart server ${a.name}`,disabled:J===a.id,children:(0,d.jsx)(bG.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Restart server"})]}),J===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Removing ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),U(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":`Remove server ${a.name}`,disabled:L===a.id,children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Remove server"})]})]})]})},a.id))]}),W&&(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,d.jsxs)("button",{onClick:()=>I(!H),className:"flex items-center justify-between w-full text-left",children:[(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Available Tools ",t.length>0&&`(${t.length})`]}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",H&&"rotate-180")})]})}),H&&(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[B&&(0,d.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),F&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:F})]})]})}),!B&&0===t.length&&!F&&"connected"===W.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(bH.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==W.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(m.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),t.map(a=>(0,d.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,d.jsx)("h4",{className:"text-sm font-medium mb-1",children:a.name}),a.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:a.description}),a.inputSchema?.properties&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(a.inputSchema.properties).slice(0,3).map(a=>(0,d.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:a},a)),Object.keys(a.inputSchema.properties).length>3&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(a.inputSchema.properties).length-3," more"]})]})]},a.name))]})]})]}),(0,d.jsx)(bD,{isOpen:N,onClose:()=>O(!1),onInstallServer:T,onOpenConnectModal:c,disableClose:P})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",a?"opacity-100":"opacity-0 pointer-events-none"),onClick:b}),(0,d.jsxs)("aside",{className:(0,j.cn)("fixed top-0 right-0 z-40 h-screen w-80 bg-card border-l border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",a?"translate-x-0":"translate-x-full"),children:[(0,d.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,d.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,d.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>S(),disabled:z,className:"h-8 w-8 p-0",children:(0,d.jsx)(bE.A,{className:(0,j.cn)("h-3.5 w-3.5",z&&"animate-spin")})}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b,className:"h-8 w-8 p-0",children:(0,d.jsx)(p.A,{className:"h-3.5 w-3.5"})})]})]}),(0,d.jsxs)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:[(0,d.jsxs)(x.$,{onClick:()=>O(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,d.jsx)(bF.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]}),(0,d.jsxs)(x.$,{onClick:()=>window.open("/playground","_blank"),className:"w-full h-9 text-sm font-medium",size:"sm",variant:"outline",children:[(0,d.jsx)(aY.A,{className:"mr-2 h-4 w-4"}),"MCP Playground"]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,d.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,d.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",n.length,")"]})}),z&&(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bE.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),D&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:D})]})]})}),!z&&0===n.length&&!D&&(0,d.jsxs)("div",{className:"text-center py-8",children:[(0,d.jsx)(bx.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),n.map(a=>(0,d.jsx)("div",{onClick:()=>s(a.id),className:(0,j.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",r===a.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)("div",{className:(0,j.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===a.status?"bg-green-500":"error"===a.status?"bg-red-500":"bg-yellow-500")}),(0,d.jsx)("h4",{className:"text-sm font-medium truncate",children:a.name})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:a.status})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[L===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Restarting ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),V(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-primary","aria-label":`Restart server ${a.name}`,disabled:J===a.id,children:(0,d.jsx)(bG.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Restart server"})]}),J===a.id?(0,d.jsx)("div",{className:"h-8 w-8 flex items-center justify-center",children:(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground",role:"status","aria-label":`Removing ${a.name}…`})}):(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),U(a.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive","aria-label":`Remove server ${a.name}`,disabled:L===a.id,children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{side:"top",children:"Remove server"})]})]})]})},a.id))]}),W&&(0,d.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,d.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,d.jsxs)("button",{onClick:()=>I(!H),className:"flex items-center justify-between w-full text-left",children:[(0,d.jsx)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Available Tools"}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",H&&"rotate-180")})]})}),H&&(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[B&&(0,d.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,d.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,d.jsx)(bE.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),F&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,d.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,d.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:F})]})]})}),!B&&0===t.length&&!F&&"connected"===W.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(bH.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==W.status&&(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)(m.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),t.map(a=>(0,d.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,d.jsx)("h4",{className:"text-sm font-medium mb-1",children:a.name}),a.description&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:a.description}),a.inputSchema?.properties&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(a.inputSchema.properties).slice(0,3).map(a=>(0,d.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:a},a)),Object.keys(a.inputSchema.properties).length>3&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(a.inputSchema.properties).length-3," more"]})]})]},a.name))]})]})]}),(0,d.jsx)(bD,{isOpen:N,onClose:()=>O(!1),onInstallServer:T,onOpenConnectModal:c,disableClose:P})]})]})}var bP=c(32542),bQ=c(35966);let bR=function({onClick:a,className:b,variant:c="outline",side:e="bottom"}){return(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:c,size:"sm",onClick:a,className:["h-8 w-8 p-0",b].filter(Boolean).join(" "),"aria-label":"New chat",children:(0,d.jsx)(aU.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{side:e,children:"New Chat (⌘K)"})]})})};function bS({isOpen:a,onClose:b,currentSessionId:c,onSessionChange:h,returnToWelcome:i,variant:k="overlay",onSearchOpen:l,onNewChat:n}){let[o,q]=(0,e.useState)([]),[r,s]=(0,e.useState)(!1),[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(!1),[C,D]=(0,e.useState)(""),[E,F]=(0,e.useState)(null),G=f().useRef(!1),H=f().useRef(0),I=f().useRef(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),[N,O]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{if(G.current)return;H.current+=1;let a=H.current;I.current||s(!0),z(null);try{let b,c=await fetch(`${(0,g.e)()}/api/sessions`);if(!c.ok)throw Error("Failed to fetch sessions");let d=await c.text();if(a!==H.current)return;if(!d.trim())return void q([]);try{b=JSON.parse(d)}catch(a){console.error("Failed to parse sessions response:",a),z("Failed to parse sessions data");return}let e=(b.sessions||[]).sort((a,b)=>{let c=a.lastActivity?new Date(a.lastActivity).getTime():0;return(b.lastActivity?new Date(b.lastActivity).getTime():0)-c});a===H.current&&(q(e),I.current=!0)}catch(b){a===H.current&&(console.error("Error fetching sessions:",b),z(b instanceof Error?b.message:"Failed to fetch sessions"))}finally{a===H.current&&(s(!1),I.current=!0)}},[]);let P=async()=>{try{let a,b=await fetch(`${(0,g.e)()}/api/sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:C.trim()||void 0})});if(!b.ok){let a,c=await b.text();try{a=c?JSON.parse(c):{}}catch{a={error:"Failed to create session"}}throw Error(a.error||"Failed to create session")}let c=await b.text();if(!c.trim())throw Error("Empty response from session creation");try{a=JSON.parse(c)}catch(a){throw console.error("Failed to parse session creation response:",a),Error("Invalid response from session creation")}q(b=>[...b,a.session]),D(""),B(!1),h(a.session.id)}catch(a){console.error("Error creating session:",a),z(a instanceof Error?a.message:"Failed to create session")}},Q=async a=>{let b=c===a;G.current=!0,F(a);try{let c=await fetch(`${(0,g.e)()}/api/sessions/${a}`,{method:"DELETE"});if(!c.ok){let a,b=await c.text();try{a=b?JSON.parse(b):{}}catch{a={error:"Failed to delete session"}}throw Error(a.error||"Failed to delete session")}q(b=>b.filter(b=>b.id!==a)),b&&i(),await new Promise(a=>setTimeout(a,100))}catch(a){console.error("Error deleting session:",a),z(a instanceof Error?a.message:"Failed to delete session")}finally{G.current=!1,F(null)}},R=async()=>{if(!L)return;let a=c===L;G.current=!0,O(!0);try{if(!(await fetch(`${(0,g.e)()}/api/sessions/${L}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok)throw Error("Failed to delete conversation");q(a=>a.filter(a=>a.id!==L)),a&&i(),K(!1),M(null),await new Promise(a=>setTimeout(a,100))}catch(a){console.error("Error deleting conversation:",a),z(a instanceof Error?a.message:"Failed to delete conversation")}finally{G.current=!1,O(!1)}},S=(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:[(0,d.jsx)("div",{className:"flex items-center space-x-2",children:(0,d.jsx)("h2",{id:"sessionpanel-title",className:"text-base font-semibold",children:"Chat History"})}),(0,d.jsxs)("div",{className:"flex items-center space-x-1",children:[l&&(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:l,className:"h-7 w-7 p-0","aria-label":"Search conversations",children:(0,d.jsx)(aV.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Search conversations (⌘⇧S)"})]})}),n&&(0,d.jsx)(bR,{onClick:n,variant:"outline"}),"overlay"===k&&(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b,className:"h-7 w-7 p-0","aria-label":"Close panel",children:(0,d.jsx)(p.A,{className:"h-3.5 w-3.5"})})]})]}),y&&(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:y})]})}),(0,d.jsx)(bP.F,{className:"flex-1",children:r?(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsx)(bE.A,{className:"h-6 w-6 animate-spin"})}):0===o.length?(0,d.jsxs)("div",{className:"text-center py-8 text-muted-foreground px-4",children:[(0,d.jsx)(bQ.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,d.jsx)("p",{children:"No chat history"}),(0,d.jsx)("p",{className:"text-sm",children:"Start a conversation to see it here"})]}):(0,d.jsx)("div",{className:"px-3 py-2 space-y-0.5",children:(0,d.jsx)(t,{children:o.map(a=>{let b=a.title&&a.title.trim().length>0?a.title:a.id,e=c===a.id;return(0,d.jsxs)(u,{delayDuration:150,children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{className:e?"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":e?"page":void 0,onClick:()=>h(a.id),onKeyDown:b=>{("Enter"===b.key||" "===b.key)&&(b.preventDefault(),h(a.id))},children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,d.jsx)("div",{className:"flex items-center gap-2.5 flex-1 min-w-0",children:(0,d.jsx)("h3",{className:e?"font-semibold text-sm truncate":"font-normal text-sm truncate text-muted-foreground",children:b})}),(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:(a=>{if(!a)return"Unknown";let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"Just now":d<60?`${d}m ago`:e<24?`${e}h ago`:`${f}d ago`})(a.lastActivity)}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),a.messageCount>0?(M(a.id),K(!0)):Q(a.id)},disabled:E===a.id,className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":a.messageCount>0?"Delete conversation":"Delete chat",title:"Delete",children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"})})]})]})})}),(0,d.jsx)(w,{side:"right",align:"center",children:(0,d.jsxs)("div",{className:"text-xs space-y-1",children:[(0,d.jsx)("div",{className:"font-mono",children:a.id}),(0,d.jsxs)("div",{className:"text-muted-foreground",children:[a.messageCount," messages"]})]})})]},a.id)})})})}),(0,d.jsx)(aN.lG,{open:A,onOpenChange:B,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsx)(aN.L3,{children:"Start New Chat"})}),(0,d.jsx)("div",{className:"space-y-4",children:(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"sessionId",children:"Chat ID"}),(0,d.jsx)(aP.p,{id:"sessionId",value:C,onChange:a=>D(a.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>B(!1),children:"Cancel"}),(0,d.jsx)(x.$,{onClick:P,children:"Start Chat"})]})]})}),(0,d.jsx)(aN.lG,{open:J,onOpenChange:K,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Conversation"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",L&&(0,d.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,d.jsx)("span",{className:"font-mono",children:L})]})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>K(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:R,disabled:N,className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:N?"Deleting...":"Delete Conversation"})]})]})]})})]});return"inline"===k?(0,d.jsx)("div",{className:"h-full w-full flex flex-col bg-card",children:S}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-0 bg-black/50 z-30 transition-opacity duration-300",a?"opacity-100":"opacity-0 pointer-events-none"),onClick:b}),(0,d.jsx)("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"sessionpanel-title",tabIndex:-1,className:(0,j.cn)("fixed top-0 left-0 z-40 h-screen w-80 bg-card border-r border-border shadow-xl transition-transform duration-300 ease-in-out flex flex-col",a?"translate-x-0":"-translate-x-full"),children:S})]})}var bT=c(26178),bU=c(10194);function bV({isOpen:a,onClose:b,variant:c="modal"}){let[f,h]=(0,e.useState)([]),[i,k]=(0,e.useState)(!1),[l,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(null),[s,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(!1),[B,C]=(0,e.useState)(null),D=(0,e.useCallback)(async()=>{k(!0),n(null);try{let a=await fetch(`${(0,g.e)()}/api/memory`);if(!a.ok)throw Error("Failed to fetch memories");let b=await a.json();h(b.memories||[])}catch(a){console.error("Error fetching memories:",a),n(a instanceof Error?a.message:"Failed to fetch memories")}finally{k(!1)}},[]),E=async a=>{r(a);try{let b=await fetch(`${(0,g.e)()}/api/memory/${a}`,{method:"DELETE"});if(!b.ok){let a=await b.json();throw Error(a.error||"Failed to delete memory")}h(b=>b.filter(b=>b.id!==a)),A(!1),C(null)}catch(a){console.error("Error deleting memory:",a),n(a instanceof Error?a.message:"Failed to delete memory")}finally{r(null)}},F=(a,b=120)=>a.length<=b?a:a.slice(0,b)+"...",G=f.filter(a=>{if(!o.trim())return!0;let b=o.toLowerCase();return a.content.toLowerCase().includes(b)||a.tags?.some(a=>a.toLowerCase().includes(b))}),H=(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsx)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:(0,d.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,d.jsx)(K.A,{className:"h-4 w-4"}),(0,d.jsx)("h2",{className:"text-base font-semibold",children:"Memories"}),(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs",children:f.length})]})}),(0,d.jsx)("div",{className:"p-3 border-b border-border/50",children:(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)("div",{className:"relative flex-1",children:[(0,d.jsx)(aV.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,d.jsx)(aP.p,{placeholder:"Search memories...",value:o,onChange:a=>p(a.target.value),className:"pl-8 h-8 text-sm"})]}),(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:()=>y(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:(0,d.jsx)(aU.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Create Memory"})]})})]})}),l&&(0,d.jsx)("div",{className:"p-4",children:(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.TN,{children:l})]})}),(0,d.jsx)(bP.F,{className:"flex-1 p-4",children:(0,d.jsx)("div",{className:"space-y-2",children:i?(0,d.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,d.jsx)(bE.A,{className:"h-6 w-6 animate-spin"})}):0===G.length?(0,d.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,d.jsx)(K.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),o.trim()?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("p",{children:"No memories found"}),(0,d.jsx)("p",{className:"text-sm",children:"Try a different search term"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("p",{children:"No memories yet"}),(0,d.jsx)("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):G.map(a=>(0,d.jsx)("div",{className:(0,j.cn)("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",a.metadata?.pinned&&"ring-1 ring-primary/30 bg-primary/5"),children:(0,d.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0 space-y-2",children:[(0,d.jsx)("p",{className:"text-sm leading-relaxed",children:F(a.content)}),a.tags&&a.tags.length>0&&(0,d.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,d.jsx)(bT.A,{className:"h-3 w-3 text-muted-foreground"}),a.tags.map((a,b)=>(0,d.jsx)(aX.E,{variant:"outline",className:"text-xs px-1.5 py-0",children:a},b))]}),(0,d.jsxs)("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)(bU.A,{className:"h-3 w-3"}),(0,d.jsx)("span",{children:(a=>{let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"Just now":d<60?`${d}m ago`:e<24?`${e}h ago`:`${f}d ago`})(a.updatedAt)})]}),a.metadata?.source&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:a.metadata.source}),a.metadata?.pinned&&(0,d.jsx)(aX.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),(0,d.jsx)("div",{className:"flex items-center gap-1",children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{C(a),A(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5 text-destructive"})})})]})},a.id))})}),(0,d.jsx)(bn,{open:s,onClose:()=>y(!1),onSuccess:()=>{D()}}),(0,d.jsx)(aN.lG,{open:z,onOpenChange:A,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Memory"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this memory. This action cannot be undone.",B&&(0,d.jsx)("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:F(B.content,100)})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:()=>B&&E(B.id),disabled:q===B?.id,className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:q===B?.id?"Deleting...":"Delete Memory"})]})]})]})})]});return"inline"===c?(0,d.jsx)("div",{className:"h-full",children:H}):(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:[(0,d.jsx)(aN.c7,{className:"sr-only",children:(0,d.jsx)(aN.L3,{children:"Memories"})}),H]})})}function bW({websocket:a,onApprovalRequest:b,onApprove:c,onDeny:d,onHandlersReady:g}){let[h,j]=(0,e.useState)(null),{currentSessionId:k}=(0,i.v)(),l=f().useRef([]),m=(0,e.useCallback)((b,c,d)=>{if(!h||!a)return;let e="elicitation"===h.type?b&&c?{formData:c}:void 0:{rememberChoice:d??!1},f={type:"approvalResponse",data:{approvalId:h.approvalId,status:b?"approved":"denied",sessionId:h.sessionId,...e?{data:e}:{}}};if(console.debug(`[WebUI] Sending approvalResponse: ${JSON.stringify(f)}`),a.readyState!==WebSocket.OPEN)return void console.warn(`[WebUI] WebSocket not open (readyState: ${a.readyState}), cannot send approval response for ${h.approvalId}`);try{a.send(JSON.stringify(f))}catch(a){console.error(`[WebUI] Failed to send approval response: ${a instanceof Error?a.message:String(a)}`);return}if(j(null),l.current.length>0){let a=l.current.shift();setTimeout(()=>{j(a)},100)}},[h,a]);return(0,e.useCallback)((a,b)=>{m(!0,a,b),c?.(a,b)},[m,c]),(0,e.useCallback)(()=>{m(!1),d?.()},[m,d]),null}var bX=c(92829),bY=c(46309);function bZ({isOpen:a,onClose:b,onNavigateToSession:c}){let[f,h]=(0,e.useState)(""),[i,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(!1),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(0);return(0,e.useCallback)(async a=>{if(!a.trim()){k([]),o(null);return}m(!0),o(null);try{let b=new URLSearchParams({q:a,limit:"10",offset:"0"}),c=await fetch(`${(0,g.e)()}/api/search/messages?${b}`);if(!c.ok){let a=await c.text();throw Error(`Search failed: ${c.status} ${a}`)}let d=await c.json();k(d.results),q(0)}catch(a){console.error("Search error:",a),k([]),o(a instanceof Error?a.message:"Search failed")}finally{m(!1)}},[]),(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"max-w-2xl p-0 top-[20%] transform translate-y-0",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsx)(aN.L3,{className:"sr-only",children:"Search Conversations"})}),(0,d.jsxs)("div",{className:"flex flex-col max-h-[70vh]",children:[(0,d.jsx)("div",{className:"p-6 pb-4",children:(0,d.jsxs)("div",{className:"relative",children:[(0,d.jsx)(aV.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),(0,d.jsx)(aP.p,{placeholder:"Search conversations...",value:f,onChange:a=>h(a.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),(0,d.jsx)("div",{className:"flex-1 overflow-hidden border-t",children:l?(0,d.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,d.jsx)(bE.A,{className:"h-6 w-6 animate-spin mr-3"}),(0,d.jsx)("span",{className:"text-muted-foreground",children:"Searching..."})]}):n?(0,d.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,d.jsxs)("div",{className:"text-center",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),(0,d.jsx)("p",{className:"text-destructive font-medium",children:"Search Error"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:n}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):(0,d.jsx)(bP.F,{className:"h-full",children:(0,d.jsx)("div",{className:"p-2",children:i.length>0?(0,d.jsx)("div",{className:"space-y-1",children:i.map((a,e)=>(0,d.jsxs)("div",{className:(0,j.cn)("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",e===p?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>{c(a.sessionId,a.messageIndex),b()},children:[(0,d.jsx)("div",{className:"flex-shrink-0 mt-1",children:(0,d.jsx)(aX.E,{className:(0,j.cn)("text-xs",(a=>{switch(a){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"}})(a.message.role)),children:(a=>{switch(a){case"user":return(0,d.jsx)(H.A,{className:"w-4 h-4"});case"assistant":return(0,d.jsx)(I.A,{className:"w-4 h-4"});case"system":return(0,d.jsx)(bX.A,{className:"w-4 h-4"});default:return(0,d.jsx)(bY.A,{className:"w-4 h-4"})}})(a.message.role)})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,d.jsx)("span",{className:"text-sm font-medium",children:a.sessionId.length>20?`${a.sessionId.slice(0,20)}...`:a.sessionId}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground",children:a.message.role})]}),(0,d.jsx)("div",{className:"text-sm text-muted-foreground line-clamp-2",children:((a,b)=>{if(!b)return a;let c=b.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),e=RegExp(`(${c})`,"gi");return a.split(e).map((a,b)=>e.test(a)?(0,d.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:a},b):a)})(a.context,f)})]}),(0,d.jsx)(L.A,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},e))}):f?(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,d.jsx)("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)(aV.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,d.jsx)("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),(0,d.jsxs)("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↑"}),(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↓"}),(0,d.jsx)("span",{children:"to navigate"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Enter"}),(0,d.jsx)("span",{children:"to select"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Esc"}),(0,d.jsx)("span",{children:"to close"})]})]})]})})})})]})]})})}var b$=c(47149),b_=c(24863);function b0({value:a,onChange:b,onValidate:c,readOnly:f=!1,height:g="100%"}){let h=(0,e.useRef)(null);return(0,d.jsx)(b_.Ay,{height:g,defaultLanguage:"yaml",value:a,onChange:a=>{void 0!==a&&b(a)},onMount:a=>{h.current=a,a.updateOptions({minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:"on",renderLineHighlight:"all",folding:!0,automaticLayout:!0})},theme:"vs-dark",options:{readOnly:f,wordWrap:"on",tabSize:2}})}function b1({isValidating:a,isValid:b,errors:c,warnings:e,hasUnsavedChanges:f}){return(0,d.jsxs)("div",{className:"border-t border-border bg-background px-4 py-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,d.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:a?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}),(0,d.jsx)("span",{className:"text-sm text-muted-foreground",children:"Validating..."})]}):b?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(M.A,{className:"h-4 w-4 text-green-500 flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Valid configuration",f&&" (unsaved changes)"]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(bd.A,{className:"h-4 w-4 text-destructive flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-destructive",children:[c.length," ",1===c.length?"error":"errors"]})]})}),e.length>0&&(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(m.A,{className:"h-4 w-4 text-yellow-500 flex-shrink-0"}),(0,d.jsxs)("span",{className:"text-sm text-yellow-500",children:[e.length," ",1===e.length?"warning":"warnings"]})]})]}),c.length>0&&(0,d.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:c.map((a,b)=>(0,d.jsxs)("div",{className:"text-xs bg-destructive/10 text-destructive rounded px-2 py-1.5 flex items-start gap-2",children:[(0,d.jsx)(bd.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[a.path&&(0,d.jsxs)("span",{className:"font-medium",children:[a.path,": "]}),a.message,a.line&&(0,d.jsxs)("span",{className:"text-muted-foreground ml-1",children:["(line ",a.line,a.column&&`:${a.column}`,")"]})]})]},b))}),e.length>0&&0===c.length&&(0,d.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:e.map((a,b)=>(0,d.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,d.jsx)(m.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("span",{className:"font-medium",children:[a.path,": "]}),a.message]})]},b))})]})}function b2({value:a,onChange:b,onValidate:c,isValidating:e=!1,isValid:f=!0,errors:g=[],warnings:h=[],hasUnsavedChanges:i=!1}){return(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,d.jsx)(b0,{value:a,onChange:b,onValidate:c,height:"100%"})}),(0,d.jsx)(b1,{isValidating:e,isValid:f,errors:g,warnings:h,hasUnsavedChanges:i})]})}function b3({title:a,children:b,defaultOpen:c=!0,open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[],className:k}){let[l,m]=(0,e.useState)(c),n=void 0!==f,p=n?f:l;return(0,d.jsxs)("div",{className:(0,j.cn)("border border-border rounded-lg overflow-hidden",k),children:[(0,d.jsxs)("button",{onClick:()=>{let a=!p;n?g?.(a):m(a)},className:"w-full flex items-center justify-between px-4 py-3 bg-muted/50 hover:bg-muted transition-colors text-left",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium",children:a}),h>0&&(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.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:[h," ",1===h?"error":"errors"]})}),(0,d.jsx)(w,{side:"top",className:"max-w-sm",children:(0,d.jsx)("ul",{className:"space-y-1 text-left",children:i.map((a,b)=>(0,d.jsxs)("li",{children:["• ",a]},b))})})]})]}),(0,d.jsx)(o.A,{className:(0,j.cn)("h-4 w-4 transition-transform duration-200",p&&"transform rotate-180")})]}),p&&(0,d.jsx)("div",{className:"px-4 py-4 space-y-4",children:b})]})}var b4=c(87431),b5=c(6515);let b6=["openai","openai-compatible","anthropic","google","groq","xai","cohere"],b7=["vercel","in-built"];function b8({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(!1),l=(c,d)=>{b({...a,[c]:d})};return(0,d.jsx)(b3,{title:"LLM Configuration",defaultOpen:!0,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"provider",tooltip:"The LLM provider to use (e.g., OpenAI, Anthropic)",children:"Provider *"}),(0,d.jsxs)("select",{id:"provider",value:a.provider||"",onChange:a=>l("provider",a.target.value),"aria-invalid":!!c["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,d.jsx)("option",{value:"",children:"Select provider..."}),b6.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]}),c["llm.provider"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.provider"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"model",tooltip:"The specific model identifier (e.g., gpt-5, claude-sonnet-4-5-20250929)",children:"Model *"}),(0,d.jsx)(aP.p,{id:"model",value:a.model||"",onChange:a=>l("model",a.target.value),placeholder:"e.g., gpt-5, claude-sonnet-4-5-20250929","aria-invalid":!!c["llm.model"]}),c["llm.model"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.model"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"apiKey",tooltip:"Use $ENV_VAR for environment variables or enter the API key directly",children:"API Key *"}),(0,d.jsxs)("div",{className:"relative",children:[(0,d.jsx)(aP.p,{id:"apiKey",type:j?"text":"password",value:a.apiKey??"",onChange:a=>l("apiKey",a.target.value),placeholder:"$OPENAI_API_KEY or direct value","aria-invalid":!!c["llm.apiKey"],className:"pr-10"}),(0,d.jsx)("button",{type:"button",onClick:()=>k(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-accent rounded transition-colors","aria-label":j?"Hide API key":"Show API key",children:j?(0,d.jsx)(b4.A,{className:"h-4 w-4 text-muted-foreground"}):(0,d.jsx)(b5.A,{className:"h-4 w-4 text-muted-foreground"})})]}),c["llm.apiKey"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.apiKey"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"router",tooltip:"LLM routing backend: 'vercel' uses Vercel AI SDK, 'in-built' uses provider-specific clients",children:"Router"}),(0,d.jsx)("select",{id:"router",value:a.router||"vercel",onChange:a=>l("router",a.target.value),"aria-invalid":!!c["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:b7.map(a=>(0,d.jsx)("option",{value:a,children:a},a))}),c["llm.router"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.router"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"maxIterations",tooltip:"Maximum number of agent reasoning iterations per turn",children:"Max Iterations"}),(0,d.jsx)(aP.p,{id:"maxIterations",type:"number",value:void 0!==a.maxIterations?a.maxIterations:"",onChange:a=>{let b=a.target.value;if(""===b)l("maxIterations",void 0);else{let a=parseInt(b,10);isNaN(a)||l("maxIterations",a)}},min:"1",placeholder:"50","aria-invalid":!!c["llm.maxIterations"]}),c["llm.maxIterations"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxIterations"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"baseURL",tooltip:"Custom base URL for the LLM provider (optional, for proxies or custom endpoints)",children:"Base URL"}),(0,d.jsx)(aP.p,{id:"baseURL",value:a.baseURL||"",onChange:a=>l("baseURL",a.target.value||void 0),placeholder:"https://api.openai.com/v1","aria-invalid":!!c["llm.baseURL"]}),c["llm.baseURL"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.baseURL"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"temperature",tooltip:"Controls randomness in responses (0.0 = deterministic, 1.0 = creative)",children:"Temperature"}),(0,d.jsx)(aP.p,{id:"temperature",type:"number",value:void 0!==a.temperature?a.temperature:"",onChange:a=>l("temperature",a.target.value?parseFloat(a.target.value):void 0),min:"0",max:"1",step:"0.1",placeholder:"0.0 - 1.0","aria-invalid":!!c["llm.temperature"]}),c["llm.temperature"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.temperature"]})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"maxInputTokens",type:"number",value:a.maxInputTokens||"",onChange:a=>l("maxInputTokens",a.target.value?parseInt(a.target.value,10):void 0),min:"1",placeholder:"Auto (128k fallback)","aria-invalid":!!c["llm.maxInputTokens"]}),c["llm.maxInputTokens"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxInputTokens"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{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,d.jsx)(aP.p,{id:"maxOutputTokens",type:"number",value:a.maxOutputTokens||"",onChange:a=>l("maxOutputTokens",a.target.value?parseInt(a.target.value,10):void 0),min:"1",placeholder:"Auto (provider default)","aria-invalid":!!c["llm.maxOutputTokens"]}),c["llm.maxOutputTokens"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["llm.maxOutputTokens"]})]})]})]})})}let b9=["dateTime","memorySummary","resources"];function ca({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(new Set),[l,m]=(0,e.useState)({}),p=a.contributors||[],q=(a,c)=>{b({contributors:p.map(b=>{if(b.id===a){if(c.id&&c.id!==a&&k(b=>{let d=new Set(b);return d.has(a)&&(d.delete(a),d.add(c.id)),d}),c.type&&c.type!==b.type){let a={id:c.id||b.id,priority:void 0!==c.priority?c.priority:b.priority,enabled:void 0!==c.enabled?c.enabled:b.enabled};if("static"===c.type)return{...a,type:"static",content:""};if("dynamic"===c.type)return{...a,type:"dynamic",source:"dateTime"};if("file"===c.type)return{...a,type:"file",files:[]}}return{...b,...c}}return b})})};return(0,d.jsx)(b3,{title:"System Prompt",defaultOpen:!0,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define how the agent should behave using multiple contributors with different priorities."}),0===p.length?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"No contributors configured"}):p.map(a=>{let c,e,f=j.has(a.id);return(0,d.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,d.jsxs)("button",{onClick:()=>{var b;return b=a.id,void k(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[f?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:a.id}),(0,d.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a.type,", priority: ",a.priority,")"]}),!1===a.enabled&&(0,d.jsx)("span",{className:"text-xs text-destructive",children:"(disabled)"})]}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{var c;return c=a.id,void(b({contributors:p.filter(a=>a.id!==c)}),k(a=>{let b=new Set(a);return b.delete(c),b}))},className:"h-7 w-7 p-0",children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),f&&(0,d.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-id-${a.id}`,tooltip:"Unique identifier for this contributor",children:"ID *"}),(0,d.jsx)(aP.p,{id:`contributor-id-${a.id}`,value:a.id,onChange:b=>q(a.id,{id:b.target.value}),placeholder:"e.g., primary, dateTime"})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-type-${a.id}`,tooltip:"Type of contributor: static (fixed text), dynamic (runtime generated), or file (from files)",children:"Type *"}),(0,d.jsxs)("select",{id:`contributor-type-${a.id}`,value:a.type,onChange:b=>q(a.id,{type:b.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,d.jsx)("option",{value:"static",children:"Static"}),(0,d.jsx)("option",{value:"dynamic",children:"Dynamic"}),(0,d.jsx)("option",{value:"file",children:"File"})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-priority-${a.id}`,tooltip:"Execution priority (lower numbers run first)",children:"Priority *"}),(0,d.jsx)(aP.p,{id:`contributor-priority-${a.id}`,type:"number",value:a.priority,onChange:b=>{let c=Number.parseInt(b.target.value,10);q(a.id,{priority:Number.isNaN(c)?0:c})},placeholder:"0",min:"0"})]})]}),(0,d.jsx)("div",{children:(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:!1!==a.enabled,onChange:b=>q(a.id,{enabled:b.target.checked}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Enabled"})]})}),"static"===a.type&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-content-${a.id}`,tooltip:"Static content for the system prompt",children:"Content *"}),(0,d.jsx)(bi.T,{id:`contributor-content-${a.id}`,value:a.content,onChange:b=>q(a.id,{content:b.target.value}),placeholder:"You are a helpful assistant...",rows:8,className:"font-mono text-sm"})]}),"dynamic"===a.type&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-source-${a.id}`,tooltip:"Source for dynamic content generation",children:"Source *"}),(0,d.jsx)("select",{id:`contributor-source-${a.id}`,value:a.source,onChange:b=>q(a.id,{source:b.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:b9.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),"file"===a.type&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-files-${a.id}`,tooltip:"File paths to include, comma-separated",children:"Files *"}),(0,d.jsx)(aP.p,{id:`contributor-files-${a.id}`,value:(c=a.id,e=a.files,l[c]??e.join(", ")),onChange:b=>{var c,d;return c=a.id,d=b.target.value,void m(a=>({...a,[c]:d}))},onBlur:b=>((a,b)=>{m(b=>{let c={...b};return delete c[a],c});let c=b.split(",").map(a=>a.trim()).filter(Boolean);q(a,{files:c.length>0?c:[]})})(a.id,b.target.value),placeholder:"./commands/context.md, ./commands/rules.txt",className:"font-mono"})]}),(0,d.jsxs)("details",{className:"border border-border rounded-md p-2",children:[(0,d.jsx)("summary",{className:"text-sm font-medium cursor-pointer",children:"File Options"}),(0,d.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:a.options?.includeFilenames!==!1,onChange:b=>q(a.id,{options:{...a.options,includeFilenames:b.target.checked}}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Include filenames as headers"})]}),(0,d.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,d.jsx)("input",{type:"checkbox",checked:a.options?.includeMetadata===!0,onChange:b=>q(a.id,{options:{...a.options,includeMetadata:b.target.checked}}),className:"rounded border-input"}),(0,d.jsx)("span",{children:"Include file metadata"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-separator-${a.id}`,tooltip:"Separator between multiple files",children:"Separator"}),(0,d.jsx)(aP.p,{id:`contributor-separator-${a.id}`,value:a.options?.separator??"\n\n---\n\n",onChange:b=>q(a.id,{options:{...a.options,separator:b.target.value}}),placeholder:"\\n\\n---\\n\\n"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-error-handling-${a.id}`,tooltip:"How to handle missing or unreadable files",children:"Error Handling"}),(0,d.jsxs)("select",{id:`contributor-error-handling-${a.id}`,value:a.options?.errorHandling||"skip",onChange:b=>q(a.id,{options:{...a.options,errorHandling:b.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,d.jsx)("option",{value:"skip",children:"Skip missing files"}),(0,d.jsx)("option",{value:"error",children:"Error on missing files"})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`contributor-max-file-size-${a.id}`,tooltip:"Maximum file size in bytes",children:"Max File Size (bytes)"}),(0,d.jsx)(aP.p,{id:`contributor-max-file-size-${a.id}`,type:"number",value:a.options?.maxFileSize||1e5,onChange:b=>{let c=Number.parseInt(b.target.value,10);q(a.id,{options:{...a.options,maxFileSize:Number.isNaN(c)?void 0:c}})},placeholder:"100000",min:"1"})]})]})]})]})]})]},a.id)}),(0,d.jsxs)(x.$,{onClick:()=>{let a=`contributor-${Date.now()}`,c={id:a,type:"static",priority:10*p.length,enabled:!0,content:""};b({contributors:[...p,c]}),k(b=>new Set(b).add(a))},variant:"outline",size:"sm",className:"w-full",children:[(0,d.jsx)(aU.A,{className:"h-4 w-4 mr-2"}),"Add Contributor"]}),c.systemPrompt&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.systemPrompt})]})})}var cb=(a=>(a.SCHEMA_VALIDATION="mcp_schema_validation",a.COMMAND_MISSING="mcp_command_missing",a.DUPLICATE_NAME="mcp_duplicate_name",a.CONNECTION_FAILED="mcp_connection_failed",a.PROTOCOL_ERROR="mcp_protocol_error",a.SERVER_NOT_FOUND="mcp_server_not_found",a.TOOL_NOT_FOUND="mcp_tool_not_found",a.PROMPT_NOT_FOUND="mcp_prompt_not_found",a.RESOURCE_NOT_FOUND="mcp_resource_not_found",a))(cb||{}),cc=(a=>(a.LLM="llm",a.AGENT="agent",a.CONFIG="config",a.CONTEXT="context",a.SESSION="session",a.MCP="mcp",a.TOOLS="tools",a.STORAGE="storage",a.SYSTEM_PROMPT="system_prompt",a.PREFERENCE="preference",a.AGENT_REGISTRY="agent_registry",a.RESOURCE="resource",a.PROMPT="prompt",a.MEMORY="memory",a.PLUGIN="plugin",a.FILESYSTEM="filesystem",a.PROCESS="process",a))(cc||{}),cd=(a=>(a.USER="user",a.NOT_FOUND="not_found",a.FORBIDDEN="forbidden",a.TIMEOUT="timeout",a.CONFLICT="conflict",a.RATE_LIMIT="rate_limit",a.SYSTEM="system",a.THIRD_PARTY="third_party",a.UNKNOWN="unknown",a))(cd||{}),ce=c(61804);ce.Yj().transform(a=>a.trim()).refine(a=>a.length>0,{message:"Required"}),ce.Yj().transform(a=>a.trim()).refine(a=>""===a||function(a){try{let b=new URL(a);return"http:"===b.protocol||"https:"===b.protocol}catch{return!1}}(a),{message:"Invalid URL"}).transform(a=>""===a?void 0:a).optional();let cf=a=>ce.Yj().transform(b=>{if("string"!=typeof b)return"";let c=a??process.env;return b.replace(/\$([A-Z_][A-Z0-9_]*)|\${([A-Z_][A-Z0-9_]*)}/gi,(a,b,d)=>c[b||d]??"").trim()}),cg=a=>cf(a).refine(a=>{try{let b=new URL(a);return"http:"===b.protocol||"https:"===b.protocol}catch{return!1}},{message:"Invalid URL"});var ch=c(2946);let ci=["stdio","sse","http"],cj=["strict","lenient"],ck="lenient",cl=ce.Ik({type:ce.eu("stdio"),command:cf().superRefine((a,b)=>{0===a.length&&b.addIssue({code:ch.eq.custom,message:"Stdio server requires a non-empty command",params:{code:cb.COMMAND_MISSING,scope:cc.MCP,type:cd.USER}})}),args:ce.YO(cf()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),env:ce.g1(cf()).default({}).describe("Optional environment variables for the server process"),timeout:ce.au.number().int().positive().default(3e4),connectionMode:ce.k5(cj).default(ck)}).strict(),cm=ce.Ik({type:ce.eu("sse"),url:cg(process.env).describe("URL for the SSE server endpoint"),headers:ce.g1(cf()).default({}),timeout:ce.au.number().int().positive().default(3e4),connectionMode:ce.k5(cj).default(ck)}).strict(),cn=ce.Ik({type:ce.eu("http"),url:cg(process.env).describe("URL for the HTTP server"),headers:ce.g1(cf()).default({}),timeout:ce.au.number().int().positive().default(3e4),connectionMode:ce.k5(cj).default(ck)}).strict(),co=ce.gM("type",[cl,cm,cn]).superRefine((a,b)=>{}).brand();function cp({value:a,onChange:b,errors:c={},open:f,onOpenChange:g,errorCount:h=0,sectionErrors:i=[]}){let[j,k]=(0,e.useState)(new Set),[l,m]=(0,e.useState)({}),p=Object.entries(a||{}),q=(c,d)=>{let e=a[c],{name:f,...g}=d,h={...e,...g};if(f&&"string"==typeof f&&f!==c){if(a[f])return;let d={...a};delete d[c],d[f]=h,b(d),k(a=>{let b=new Set(a);return b.has(c)&&(b.delete(c),b.add(f)),b})}else b({...a,[c]:h})},r=(a,b,c)=>l[`${a}:${b}`]??c,s=(a,b,c)=>{let d=`${a}:${b}`;m(a=>({...a,[d]:c}))},t=(a,b)=>{let c=`${a}:${b}`;m(a=>{let b={...a};return delete b[c],b})};return(0,d.jsx)(b3,{title:"MCP Servers",defaultOpen:!1,open:f,onOpenChange:g,errorCount:h,sectionErrors:i,children:(0,d.jsxs)("div",{className:"space-y-4",children:[0===p.length?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"No MCP servers configured"}):p.map(([e,f])=>{let g=j.has(e);return(0,d.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,d.jsxs)("button",{onClick:()=>{k(a=>{let b=new Set(a);return b.has(e)?b.delete(e):b.add(e),b})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[g?(0,d.jsx)(n.A,{className:"h-4 w-4"}):(0,d.jsx)(o.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{className:"font-medium text-sm",children:e}),"command"in f&&f.command&&(0,d.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:["(",f.command,")"]})]}),(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>(c=>{let d={...a};delete d[c],b(d),k(a=>{let b=new Set(a);return b.delete(c),b})})(e),className:"h-7 w-7 p-0",children:(0,d.jsx)(bk.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),g&&(0,d.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-name-${e}`,tooltip:"Unique identifier for this MCP server",children:"Server Name"}),(0,d.jsx)(aP.p,{id:`server-name-${e}`,value:e,onChange:a=>q(e,{name:a.target.value}),placeholder:"e.g., filesystem"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-type-${e}`,tooltip:"MCP server connection type",children:"Connection Type *"}),(0,d.jsx)("select",{id:`server-type-${e}`,value:f.type||"stdio",onChange:a=>{let b=a.target.value;"stdio"===b?q(e,{type:"stdio",command:"",args:void 0,env:void 0}):q(e,{type:b,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:ci.map(a=>(0,d.jsx)("option",{value:a,children:"stdio"===a?"Standard I/O (stdio)":"sse"===a?"Server-Sent Events (SSE)":"HTTP"},a))})]}),"stdio"===f.type&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-command-${e}`,tooltip:"The command to execute (e.g., npx, node, python)",children:"Command *"}),(0,d.jsx)(aP.p,{id:`server-command-${e}`,value:"command"in f?f.command:"",onChange:a=>q(e,{command:a.target.value}),placeholder:"e.g., npx, node, python","aria-invalid":!!c[`mcpServers.${e}.command`]}),c[`mcpServers.${e}.command`]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c[`mcpServers.${e}.command`]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-args-${e}`,tooltip:"Command arguments, comma-separated",children:"Arguments"}),(0,d.jsx)(aP.p,{id:`server-args-${e}`,value:r(e,"args",("args"in f&&f.args?f.args:[]).join(", ")),onChange:a=>s(e,"args",a.target.value),onBlur:a=>((a,b)=>{if(t(a,"args"),!b.trim())return void q(a,{args:void 0});let c=b.split(",").map(a=>a.trim()).filter(Boolean);q(a,{args:c.length>0?c:void 0})})(e,a.target.value),placeholder:"--port, 3000, --host, localhost",className:"font-mono"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-env-${e}`,tooltip:"Environment variables in KEY=value format, one per line",children:"Environment Variables"}),(0,d.jsx)("textarea",{id:`server-env-${e}`,value:r(e,"env",Object.entries("env"in f&&f.env||{}).map(([a,b])=>`${a}=${b}`).join("\n")),onChange:a=>s(e,"env",a.target.value),onBlur:a=>((a,b)=>{if(t(a,"env"),!b.trim())return void q(a,{env:void 0});let c={};b.split("\n").map(a=>a.trim()).filter(Boolean).forEach(a=>{let[b,...d]=a.split("=");b&&d.length>0&&(c[b.trim()]=d.join("=").trim())}),q(a,{env:Object.keys(c).length>0?c:void 0})})(e,a.target.value),placeholder:`API_KEY=$MY_API_KEY
6
6
  PORT=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"===f.type||"http"===f.type)&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-url-${e}`,tooltip:"The URL endpoint for the MCP server",children:"URL *"}),(0,d.jsx)(aP.p,{id:`server-url-${e}`,value:"url"in f?f.url:"",onChange:a=>q(e,{url:a.target.value}),placeholder:"https://example.com/mcp","aria-invalid":!!c[`mcpServers.${e}.url`]}),c[`mcpServers.${e}.url`]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c[`mcpServers.${e}.url`]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-headers-${e}`,tooltip:"HTTP headers in KEY=value format, one per line",children:"Headers"}),(0,d.jsx)("textarea",{id:`server-headers-${e}`,value:r(e,"headers",Object.entries("headers"in f&&f.headers||{}).map(([a,b])=>`${a}=${b}`).join("\n")),onChange:a=>s(e,"headers",a.target.value),onBlur:a=>((a,b)=>{if(t(a,"headers"),!b.trim())return void q(a,{headers:void 0});let c={};b.split("\n").map(a=>a.trim()).filter(Boolean).forEach(a=>{let[b,...d]=a.split("=");b&&d.length>0&&(c[b.trim()]=d.join("=").trim())}),q(a,{headers:Object.keys(c).length>0?c:void 0})})(e,a.target.value),placeholder:`Authorization=Bearer token
7
- Content-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,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-mode-${e}`,tooltip:"Strict mode fails on any error; lenient mode continues despite errors",children:"Connection Mode"}),(0,d.jsx)("select",{id:`server-mode-${e}`,value:f.connectionMode||cj,onChange:a=>q(e,{connectionMode:a.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:ci.map(a=>(0,d.jsx)("option",{value:a,children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]})]},e)}),(0,d.jsxs)(x.$,{onClick:()=>{let c=`server-${Object.keys(a||{}).length+1}`;b({...a,[c]:{type:"stdio",command:"",connectionMode:"strict"}}),k(a=>new Set(a).add(c))},variant:"outline",size:"sm",className:"w-full",children:[(0,d.jsx)(aU.A,{className:"h-4 w-4 mr-2"}),"Add MCP Server"]}),c.mcpServers&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.mcpServers})]})})}cd.g1(cn).describe("A dictionary of server configurations, keyed by server name").brand();var cp=(a=>(a.MANAGER_NOT_INITIALIZED="storage_manager_not_initialized",a.MANAGER_NOT_CONNECTED="storage_manager_not_connected",a.CONNECTION_FAILED="storage_connection_failed",a.CONNECTION_CONFIG_MISSING="storage_connection_config_missing",a.READ_FAILED="storage_read_failed",a.WRITE_FAILED="storage_write_failed",a.DELETE_FAILED="storage_delete_failed",a.MIGRATION_FAILED="storage_migration_failed",a.DATABASE_INVALID_CONFIG="storage_database_invalid_config",a.BLOB_INVALID_CONFIG="BLOB_INVALID_CONFIG",a.BLOB_SIZE_EXCEEDED="BLOB_SIZE_EXCEEDED",a.BLOB_TOTAL_SIZE_EXCEEDED="BLOB_TOTAL_SIZE_EXCEEDED",a.BLOB_INVALID_INPUT="BLOB_INVALID_INPUT",a.BLOB_ENCODING_ERROR="BLOB_ENCODING_ERROR",a.BLOB_NOT_FOUND="BLOB_NOT_FOUND",a.BLOB_INVALID_REFERENCE="BLOB_INVALID_REFERENCE",a.BLOB_ACCESS_DENIED="BLOB_ACCESS_DENIED",a.BLOB_CORRUPTED="BLOB_CORRUPTED",a.BLOB_BACKEND_NOT_CONNECTED="BLOB_BACKEND_NOT_CONNECTED",a.BLOB_BACKEND_UNAVAILABLE="BLOB_BACKEND_UNAVAILABLE",a.BLOB_CLEANUP_FAILED="BLOB_CLEANUP_FAILED",a.BLOB_OPERATION_FAILED="BLOB_OPERATION_FAILED",a))(cp||{});let cq=["in-memory","redis"],cr=cd.Ik({maxConnections:cd.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:cd.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:cd.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:cd.g1(cd.bz()).optional().describe("Backend-specific options")}),cs=cr.extend({type:cd.eu("in-memory")}).strict(),ct=cr.extend({type:cd.eu("redis"),url:ce().optional().describe("Redis connection URL (redis://...)"),host:cd.Yj().optional().describe("Redis host"),port:cd.ai().int().positive().optional().describe("Redis port"),password:cd.Yj().optional().describe("Redis password"),database:cd.ai().int().nonnegative().optional().describe("Redis database number")}).strict();cd.gM("type",[cs,ct],{errorMap:(a,b)=>a.code===cg.eq.invalid_union_discriminator?{message:"Invalid cache type. Expected 'in-memory' or 'redis'."}:{message:b.defaultError}}).describe("Cache configuration").superRefine((a,b)=>{"redis"!==a.type||a.url||a.host||b.addIssue({code:cg.eq.custom,message:"Redis cache requires either 'url' or 'host' to be specified",path:["url"],params:{code:cp.CONNECTION_CONFIG_MISSING,scope:cb.STORAGE,type:cc.USER}})});let cu=["in-memory","sqlite","postgres"],cv=cd.Ik({maxConnections:cd.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:cd.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:cd.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:cd.g1(cd.bz()).optional().describe("Backend-specific options")}),cw=cv.extend({type:cd.eu("in-memory")}).strict(),cx=cv.extend({type:cd.eu("sqlite"),path:cd.Yj().optional().describe("SQLite database file path (optional, will auto-detect using path resolver if not provided)"),database:cd.Yj().optional().describe("Database filename (default: <agent-id>.db)")}).strict(),cy=cv.extend({type:cd.eu("postgres"),url:ce().optional().describe("PostgreSQL connection URL (postgresql://...)"),connectionString:ce().optional().describe("PostgreSQL connection string"),host:cd.Yj().optional().describe("PostgreSQL host"),port:cd.ai().int().positive().optional().describe("PostgreSQL port"),database:cd.Yj().optional().describe("PostgreSQL database name"),password:cd.Yj().optional().describe("PostgreSQL password")}).strict();function cz({value:a,onChange:b,errors:c={},open:e,onOpenChange:f,errorCount:g=0,sectionErrors:h=[]}){let i=c=>{b({...a,cache:{...a.cache,...c}})},j=c=>{b({...a,database:{...a.database,...c}})},k="redis"===a.cache.type,l="sqlite"===a.database.type||"postgres"===a.database.type;return(0,d.jsx)(b2,{title:"Storage Configuration",defaultOpen:!1,open:e,onOpenChange:f,errorCount:g,sectionErrors:h,children:(0,d.jsxs)("div",{className:"space-y-6",children:[(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)("h4",{className:"text-sm font-medium",children:"Cache"}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"cache-type",tooltip:"Storage backend for caching data (in-memory or Redis)",children:"Cache Type"}),(0,d.jsx)("select",{id:"cache-type",value:a.cache.type,onChange:a=>i({type:a.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:cq.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),k&&"url"in a.cache&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"cache-url",tooltip:"Redis connection URL (e.g., redis://localhost:6379)",children:"Redis URL"}),(0,d.jsx)(aP.p,{id:"cache-url",value:a.cache.url||"",onChange:a=>i({url:a.target.value||void 0}),placeholder:"redis://localhost:6379","aria-invalid":!!c["storage.cache.url"]}),c["storage.cache.url"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["storage.cache.url"]})]})]}),(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)("h4",{className:"text-sm font-medium",children:"Database"}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"database-type",tooltip:"Storage backend for persistent data (in-memory, SQLite, or PostgreSQL)",children:"Database Type"}),(0,d.jsx)("select",{id:"database-type",value:a.database.type,onChange:a=>j({type:a.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:cu.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),l&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"database-url",tooltip:"sqlite"===a.database.type?"File path for SQLite database":"PostgreSQL connection string",children:"sqlite"===a.database.type?"SQLite Path":"PostgreSQL URL"}),(0,d.jsx)(aP.p,{id:"database-url",value:"url"in a.database&&a.database.url||"path"in a.database&&a.database.path||"",onChange:b=>{"sqlite"===a.database.type?j({path:b.target.value||void 0}):j({url:b.target.value||void 0})},placeholder:"sqlite"===a.database.type?"./dexto.db":"postgresql://user:pass@localhost:5432/dexto","aria-invalid":!!(c["storage.database.url"]||c["storage.database.path"])}),(c["storage.database.url"]||c["storage.database.path"])&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["storage.database.url"]||c["storage.database.path"]})]})]})]})})}cd.gM("type",[cw,cx,cy],{errorMap:(a,b)=>a.code===cg.eq.invalid_union_discriminator?{message:"Invalid database type. Expected 'in-memory', 'sqlite', or 'postgres'."}:{message:b.defaultError}}).describe("Database configuration").superRefine((a,b)=>{"postgres"!==a.type||a.url||a.connectionString||a.host||b.addIssue({code:cg.eq.custom,message:"PostgreSQL database requires one of 'url', 'connectionString', or 'host' to be specified",path:["url"],params:{code:cp.CONNECTION_CONFIG_MISSING,scope:cb.STORAGE,type:cc.USER}})});let cA=["search_history","ask_user","read_file","glob_files","grep_content","write_file","edit_file","bash_exec","bash_output","kill_process"],cB=["event-based","auto-approve","auto-deny"],cC=["memory","storage"],cD="event-based",cE="storage";cd.YO(cd.k5(cA).describe("Available internal tool names")).default([]).describe(`Array of internal tool names to enable. Empty array = disabled. Available tools: ${cA.join(", ")}`);let cF=cd.Ik({alwaysAllow:cd.YO(cd.Yj()).default([]).describe('Tools that never require approval (low-risk). Use full qualified names (e.g., "internal--ask_user", "mcp--filesystem--read_file")'),alwaysDeny:cd.YO(cd.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 cG({value:a,onChange:b,errors:c={},open:e,onOpenChange:f,errorCount:g=0,sectionErrors:h=[]}){let i=c=>{b({...a,...c})};return(0,d.jsx)(b2,{title:"Tool Confirmation",defaultOpen:!1,open:e,onOpenChange:f,errorCount:g,sectionErrors:h,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"confirmation-mode",tooltip:"How the agent handles tool execution requests",children:"Confirmation Mode"}),(0,d.jsx)("select",{id:"confirmation-mode",value:a.mode||cD,onChange:a=>i({mode:a.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:cB.map(a=>(0,d.jsx)("option",{value:a,children:"auto-approve"===a?"Auto-approve":"event-based"===a?"Event-based":"Auto-deny"},a))}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"event-based"===a.mode?"Require explicit approval before executing tools":"auto-deny"===a.mode?"Automatically deny all tool executions":"Automatically approve tool executions"})]}),"event-based"===a.mode&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"confirmation-timeout",tooltip:"How long to wait for approval before timing out",children:"Timeout (seconds)"}),(0,d.jsx)(aP.p,{id:"confirmation-timeout",type:"number",value:a.timeout||"",onChange:a=>i({timeout:a.target.value?parseInt(a.target.value,10):void 0}),min:"1",placeholder:"e.g., 60","aria-invalid":!!c["toolConfirmation.timeout"]}),c["toolConfirmation.timeout"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["toolConfirmation.timeout"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"allowed-tools-storage",tooltip:"Where to store the list of pre-approved tools (memory or persistent storage)",children:"Allowed Tools Storage"}),(0,d.jsx)("select",{id:"allowed-tools-storage",value:a.allowedToolsStorage||cE,onChange:c=>{var d;return d=c.target.value,void b({...a,allowedToolsStorage:d})},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:cC.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]})]})})}function cH({config:a,onChange:b,errors:c={}}){var f;let g=a.systemPrompt?"string"==typeof a.systemPrompt?{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:a.systemPrompt}]}:{contributors:a.systemPrompt.contributors||[]}:{contributors:[]},[h,i]=(0,e.useState)({basic:!0,llm:!1,systemPrompt:!1,mcpServers:!1,storage:!1,toolConfirmation:!1}),j=function(a){let b={basic:[],llm:[],systemPrompt:[],mcpServers:[],storage:[],toolConfirmation:[]};return Object.entries(a).forEach(([a,c])=>{"greeting"===a?b.basic.push(c):a.startsWith("llm.")?b.llm.push(c):a.startsWith("systemPrompt")?b.systemPrompt.push(c):a.startsWith("mcpServers")?b.mcpServers.push(c):a.startsWith("storage.")?b.storage.push(c):a.startsWith("toolConfirmation.")&&b.toolConfirmation.push(c)}),b}(c),k=a=>{i(b=>({...b,[a]:!b[a]}))},l=!!(f=a).sessions&&!!(Object.keys(f.sessions).length>0)||!!f.internalTools;return(0,d.jsxs)("div",{className:"flex flex-col h-full overflow-auto",children:[l&&(0,d.jsx)("div",{className:"mx-4 mt-4 p-3 bg-yellow-500/10 border border-yellow-500/20 rounded-lg",children:(0,d.jsxs)("div",{className:"flex items-start gap-2",children:[(0,d.jsx)(bc.A,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"text-sm",children:[(0,d.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-500",children:"Advanced Configuration Detected"}),(0,d.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,d.jsxs)("div",{className:"flex-1 p-4 space-y-4",children:[(0,d.jsx)(b2,{title:"Basic Information",open:h.basic,onOpenChange:()=>k("basic"),errorCount:j.basic.length,sectionErrors:j.basic,children:(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"agent-greeting",tooltip:"The initial message shown to users when they start a conversation",children:"Greeting Message"}),(0,d.jsx)(aP.p,{id:"agent-greeting",value:a.greeting||"",onChange:c=>b({...a,greeting:c.target.value}),placeholder:"Hello! How can I help you today?","aria-invalid":!!c.greeting}),c.greeting&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.greeting})]})}),(0,d.jsx)(b7,{value:a.llm,onChange:c=>{b({...a,llm:c})},errors:c,open:h.llm,onOpenChange:()=>k("llm"),errorCount:j.llm.length,sectionErrors:j.llm}),(0,d.jsx)(b9,{value:g,onChange:c=>{b({...a,systemPrompt:c})},errors:c,open:h.systemPrompt,onOpenChange:()=>k("systemPrompt"),errorCount:j.systemPrompt.length,sectionErrors:j.systemPrompt}),(0,d.jsx)(co,{value:a.mcpServers||{},onChange:c=>{b({...a,mcpServers:c})},errors:c,open:h.mcpServers,onOpenChange:()=>k("mcpServers"),errorCount:j.mcpServers.length,sectionErrors:j.mcpServers}),(0,d.jsx)(cz,{value:a.storage||{cache:{type:"in-memory"},database:{type:"in-memory"}},onChange:c=>{b({...a,storage:c})},errors:c,open:h.storage,onOpenChange:()=>k("storage"),errorCount:j.storage.length,sectionErrors:j.storage}),(0,d.jsx)(cG,{value:a.toolConfirmation||{},onChange:c=>{b({...a,toolConfirmation:c})},errors:c,open:h.toolConfirmation,onOpenChange:()=>k("toolConfirmation"),errorCount:j.toolConfirmation.length,sectionErrors:j.toolConfirmation})]})]})}function cI({config:a,onChange:b,errors:c={}}){return(0,d.jsx)("div",{className:"flex flex-col h-full",children:(0,d.jsx)(cH,{config:a,onChange:b,errors:c})})}cd.Ik({mode:cd.k5(cB).default(cD).describe("Tool confirmation mode: event-based (interactive), auto-approve (all tools), auto-deny (no tools)"),timeout:cd.ai().int().positive().default(12e4).describe("Timeout for tool confirmation requests in milliseconds, defaults to 120000ms (2 mins)"),allowedToolsStorage:cd.k5(cC).default(cE).describe("Storage type for remembered tool approvals: memory (session-only) or storage (persistent)"),toolPolicies:cF.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 cJ=c(94428);let cK=`${(0,g.e)()}/api`;function cL({isOpen:a,onClose:b,variant:c="overlay"}){let[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(""),[k,l]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(""),[y,z]=(0,e.useState)("yaml"),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(!1),[E,F]=(0,e.useState)(!1),[G,H]=(0,e.useState)(null),[I,J]=(0,e.useState)(null),[K,L]=(0,e.useState)(!1),[N,O]=(0,e.useState)(""),[P,Q]=(0,e.useState)(!1),[R,S]=(0,e.useState)(!0),[T,U]=(0,e.useState)([]),[V,W]=(0,e.useState)([]),[X,Y]=(0,e.useState)(!1),[Z,$]=(0,e.useState)(!1),_=(0,e.useRef)(null),aa=(0,e.useRef)(0),ab=(0,e.useCallback)(async()=>{D(!0),H(null);try{let a=await fetch(`${cK}/agent/config`);if(!a.ok){let b=await a.json().catch(()=>({error:"Failed to load configuration"}));throw Error(b.message||b.error||`Load failed: ${a.statusText}`)}let b=await a.json();g(b.yaml),i(b.yaml),t(b.relativePath),Y(!1);let{config:c,document:d}=ad(b.yaml);c&&d&&(l(c),o(c),r(d)),await ac(b.yaml)}catch(b){let a=b instanceof Error?b.message:String(b);H(a),console.error(`Error loading agent config: ${a}`)}finally{D(!1)}},[]),ac=async a=>{let b=aa.current+1;aa.current=b,Q(!0);try{let c=await fetch(`${cK}/agent/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:a})}),d=await c.json();aa.current===b&&(S(d.valid),U(d.errors||[]),W(d.warnings||[]))}catch(a){console.error(`Validation error: ${a instanceof Error?a.message:String(a)}`),aa.current===b&&(S(!1),U([{message:"Failed to validate configuration",code:"VALIDATION_ERROR"}]))}finally{aa.current===b&&Q(!1)}},ad=a=>{console.log("[parseYamlToConfig] Starting parse");try{let b=cJ.Tp(a);if(console.log("[parseYamlToConfig] Document created:",b),b.errors&&b.errors.length>0){console.error("[parseYamlToConfig] Parse errors:",b.errors);let a=b.errors.map(a=>a.message).join("; ");return{config:null,document:null,error:a}}let c=b.toJS();return console.log("[parseYamlToConfig] Config parsed successfully:",c),{config:c,document:b,error:null}}catch(a){return console.error("[parseYamlToConfig] Exception:",a),{config:null,document:null,error:a instanceof Error?a.message:"Failed to parse YAML"}}},ae=a=>{if(console.log("[handleModeSwitch] Called with newMode:",a,"current mode:",y),a===y)return void console.log("[handleModeSwitch] Same mode, returning");if("form"===a){console.log("[handleModeSwitch] Switching to form mode, parsing YAML...");let{config:a,document:b,error:c}=ad(f);if(console.log("[handleModeSwitch] Parse result:",{config:a,document:b,error:c}),c){console.error("[handleModeSwitch] Parse error, not switching:",c),B(c);return}console.log("[handleModeSwitch] Parse successful, setting state"),l(a),r(b),B(null)}console.log("[handleModeSwitch] Setting editor mode to:",a),z(a)},af=async()=>{if(!R||T.length>0)return void J("Cannot save: configuration has errors");F(!0),J(null),L(!1),O("");try{let a=await fetch(`${cK}/agent/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:f})});if(!a.ok){let b=await a.json().catch(()=>({error:"Failed to save configuration"}));throw Error(b.message||b.error||`Save failed: ${a.statusText}`)}let b=await a.json();i(f),Y(!1),L(!0),b.restarted?O(`Configuration applied successfully — ${b.changesApplied.join(", ")} updated`):O("Configuration saved successfully (no changes detected)"),setTimeout(()=>{L(!1),O("")},5e3)}catch(b){let a=b instanceof Error?b.message:String(b);J(a),console.error(`Error saving agent config: ${a}`)}finally{F(!1)}},ag=()=>{X?$(!0):b()};if(!a)return null;let ah=(()=>{if(E)return null;if(!X)return"No changes to save";if(T.length>0){let a=T[0];return a.path?`Configuration error in ${a.path}: ${a.message}`:`Configuration error: ${a.message}`}return R?null:"Configuration has validation errors"})(),ai=!X||E||!R||T.length>0,aj=(0,d.jsxs)("div",{className:"flex flex-col h-full bg-background",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,d.jsx)("div",{className:"flex items-center gap-3",children:(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:"Customize Agent"}),(0,d.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,d.jsx)(bB.A,{className:"h-3 w-3"})]})]}),s&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:s})]})}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1 bg-muted/50 rounded-md p-1",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"yaml"===y?"default":"ghost",size:"sm",onClick:()=>ae("yaml"),className:"h-7 px-3",children:"YAML Editor"})}),(0,d.jsx)(w,{children:"Edit configuration in raw YAML format with full control"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"form"===y?"default":"ghost",size:"sm",onClick:()=>ae("form"),className:"h-7 px-3",children:"Form Editor"})}),(0,d.jsx)(w,{children:"Edit configuration using user-friendly forms"})]})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{X?$(!0):ab()},disabled:C,children:(0,d.jsx)(bD.A,{className:(0,j.cn)("h-4 w-4",C&&"animate-spin")})})}),(0,d.jsx)(w,{children:"Reload configuration"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:ag,children:(0,d.jsx)(p.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Close (Esc)"})]})]})]}),(0,d.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:G?(0,d.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,d.jsxs)("div",{className:"text-center max-w-md",children:[(0,d.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,d.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Failed to load configuration"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:G}),(0,d.jsxs)(x.$,{onClick:ab,variant:"outline",children:[(0,d.jsx)(bD.A,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):C?(0,d.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,d.jsxs)("div",{className:"text-center",children:[(0,d.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading configuration..."})]})}):A&&"form"===y?(0,d.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,d.jsxs)("div",{className:"text-center max-w-md",children:[(0,d.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,d.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Cannot parse YAML"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:A}),(0,d.jsx)(x.$,{onClick:()=>z("yaml"),variant:"outline",children:"Switch to YAML Editor"})]})}):"yaml"===y?(0,d.jsx)(b1,{value:f,onChange:a=>{g(a),Y(a!==h),J(null),L(!1);let{config:b,document:c}=ad(a);b&&c&&(l(b),r(c)),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{ac(a)},500)},isValidating:P,isValid:R,errors:T,warnings:V,hasUnsavedChanges:X}):k?(0,d.jsx)(cI,{config:k,onChange:a=>{if(console.log("[handleFormChange] Called with new config"),console.log("[handleFormChange] yamlDocument exists?",!!q),!q)return void console.error("[handleFormChange] No document available - this should not happen!");l(a);let b=((a,b)=>{console.log("[serializeConfigToYaml] Starting serialization"),console.log("[serializeConfigToYaml] Document:",b),console.log("[serializeConfigToYaml] Config:",a);let c=(a=>{let b=a=>!!(null==a||""===a||""===a||Array.isArray(a)&&0===a.length)||"object"==typeof a&&null!==a&&"[object Object]"===Object.prototype.toString.call(a)&&0===Object.keys(a).length,c=a=>{if(Array.isArray(a))return a.map(c).filter(a=>!b(a));if("object"==typeof a&&null!==a){let d={};for(let[e,f]of Object.entries(a))if(!b(f))if("object"==typeof f&&null!==f){let a=c(f);b(a)||(d[e]=a)}else d[e]=f;return d}return a};return c(a)})(a);console.log("[serializeConfigToYaml] Cleaned config:",c);let d=((a,b)=>{console.log("[updateYamlDocumentFromConfig] Starting update"),console.log("[updateYamlDocumentFromConfig] Document:",a),console.log("[updateYamlDocumentFromConfig] Config:",b);let c=(b,d)=>{if(null==d||Array.isArray(d))return a.createNode(d);if("object"==typeof d&&!Array.isArray(d)){if(!b||!b.items)return a.createNode(d);let e=new Set;for(let a of b.items){let b=a.key.value;e.add(b),b in d&&(a.value=c(a.value,d[b]))}for(let[c,f]of Object.entries(d))e.has(c)||b.items.push(a.createPair(c,f));return b.items=b.items.filter(a=>a.key.value in d),b}return a.createNode(d)};try{return a.contents=c(a.contents,b),console.log("[updateYamlDocumentFromConfig] Update successful"),a}catch(a){throw console.error("[updateYamlDocumentFromConfig] Update failed:",a),a}})(b,c).toString();return console.log("[serializeConfigToYaml] Serialized result length:",d.length),d})(a,q);g(b),Y(!(a===n||a&&n&&JSON.stringify(a)===JSON.stringify(n))),J(null),L(!1),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{ac(b)},500)},errors:T.reduce((a,b)=>(b.path&&(a[b.path]=b.message),a),{})}):null}),!G&&!C&&(0,d.jsxs)("div",{className:"flex flex-col border-t border-border",children:[(K||I)&&(0,d.jsxs)("div",{className:"px-4 py-3 bg-muted/50 border-b border-border",children:[K&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-500",children:[(0,d.jsx)(M.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:N})]}),I&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:I})]})]}),(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3",children:[(0,d.jsx)("div",{}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:ag,children:"Close"}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{children:(0,d.jsx)(x.$,{variant:"default",size:"sm",onClick:af,disabled:ai,children:E?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-background border-t-transparent mr-2"}),"Saving..."]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(bZ.A,{className:"h-4 w-4 mr-2"}),"Save"]})})})}),(0,d.jsx)(w,{children:ah||"Save configuration (⌘S)"})]})]})]})]}),(0,d.jsx)(aN.lG,{open:Z,onOpenChange:$,children:(0,d.jsxs)(aN.Cf,{children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Unsaved Changes"}),(0,d.jsx)(aN.rr,{children:"You have unsaved changes. Do you want to discard them?"})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>$(!1),children:"Cancel"}),(0,d.jsx)(x.$,{variant:"destructive",onClick:()=>{$(!1),g(h),Y(!1),ab()},children:"Discard Changes"})]})]})})]});return"inline"===c?aj:(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-y-0 right-0 z-50 w-full sm:w-[600px] md:w-[700px] lg:w-[800px] border-l border-border bg-background shadow-2xl transform transition-transform duration-300",a?"translate-x-0":"translate-x-full"),children:aj})}var cM=c(41936),cN=c(18580),cO=c(48351),cP=c(40888),cQ=c(3785),cR=c(77851),cS=c(94073),cT=c(58068);function cU(){let{theme:a,toggleTheme:b}=function(){let[a,b]=(0,e.useState)(()=>"undefined"!=typeof document?document.documentElement.classList.contains("dark")?"dark":"light":"dark");return{theme:a,toggleTheme:a=>{b(a?"dark":"light")},hasMounted:!0}}(),[c,f]=(0,e.useState)(!1),g="dark"===a;return c?(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(aw.bL,{checked:g,onCheckedChange:b,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,d.jsx)(aw.zi,{className:`
7
+ Content-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,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:`server-mode-${e}`,tooltip:"Strict mode fails on any error; lenient mode continues despite errors",children:"Connection Mode"}),(0,d.jsx)("select",{id:`server-mode-${e}`,value:f.connectionMode||ck,onChange:a=>q(e,{connectionMode:a.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:cj.map(a=>(0,d.jsx)("option",{value:a,children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]})]},e)}),(0,d.jsxs)(x.$,{onClick:()=>{let c=`server-${Object.keys(a||{}).length+1}`;b({...a,[c]:{type:"stdio",command:"",connectionMode:"strict"}}),k(a=>new Set(a).add(c))},variant:"outline",size:"sm",className:"w-full",children:[(0,d.jsx)(aU.A,{className:"h-4 w-4 mr-2"}),"Add MCP Server"]}),c.mcpServers&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.mcpServers})]})})}ce.g1(co).describe("A dictionary of server configurations, keyed by server name").brand();var cq=(a=>(a.MANAGER_NOT_INITIALIZED="storage_manager_not_initialized",a.MANAGER_NOT_CONNECTED="storage_manager_not_connected",a.CONNECTION_FAILED="storage_connection_failed",a.CONNECTION_CONFIG_MISSING="storage_connection_config_missing",a.READ_FAILED="storage_read_failed",a.WRITE_FAILED="storage_write_failed",a.DELETE_FAILED="storage_delete_failed",a.MIGRATION_FAILED="storage_migration_failed",a.DATABASE_INVALID_CONFIG="storage_database_invalid_config",a.BLOB_INVALID_CONFIG="BLOB_INVALID_CONFIG",a.BLOB_SIZE_EXCEEDED="BLOB_SIZE_EXCEEDED",a.BLOB_TOTAL_SIZE_EXCEEDED="BLOB_TOTAL_SIZE_EXCEEDED",a.BLOB_INVALID_INPUT="BLOB_INVALID_INPUT",a.BLOB_ENCODING_ERROR="BLOB_ENCODING_ERROR",a.BLOB_NOT_FOUND="BLOB_NOT_FOUND",a.BLOB_INVALID_REFERENCE="BLOB_INVALID_REFERENCE",a.BLOB_ACCESS_DENIED="BLOB_ACCESS_DENIED",a.BLOB_CORRUPTED="BLOB_CORRUPTED",a.BLOB_BACKEND_NOT_CONNECTED="BLOB_BACKEND_NOT_CONNECTED",a.BLOB_BACKEND_UNAVAILABLE="BLOB_BACKEND_UNAVAILABLE",a.BLOB_CLEANUP_FAILED="BLOB_CLEANUP_FAILED",a.BLOB_OPERATION_FAILED="BLOB_OPERATION_FAILED",a))(cq||{});let cr=["in-memory","redis"],cs=ce.Ik({maxConnections:ce.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:ce.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:ce.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:ce.g1(ce.bz()).optional().describe("Backend-specific options")}),ct=cs.extend({type:ce.eu("in-memory")}).strict(),cu=cs.extend({type:ce.eu("redis"),url:cf().optional().describe("Redis connection URL (redis://...)"),host:ce.Yj().optional().describe("Redis host"),port:ce.ai().int().positive().optional().describe("Redis port"),password:ce.Yj().optional().describe("Redis password"),database:ce.ai().int().nonnegative().optional().describe("Redis database number")}).strict();ce.gM("type",[ct,cu],{errorMap:(a,b)=>a.code===ch.eq.invalid_union_discriminator?{message:"Invalid cache type. Expected 'in-memory' or 'redis'."}:{message:b.defaultError}}).describe("Cache configuration").superRefine((a,b)=>{"redis"!==a.type||a.url||a.host||b.addIssue({code:ch.eq.custom,message:"Redis cache requires either 'url' or 'host' to be specified",path:["url"],params:{code:cq.CONNECTION_CONFIG_MISSING,scope:cc.STORAGE,type:cd.USER}})});let cv=["in-memory","sqlite","postgres"],cw=ce.Ik({maxConnections:ce.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:ce.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:ce.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:ce.g1(ce.bz()).optional().describe("Backend-specific options")}),cx=cw.extend({type:ce.eu("in-memory")}).strict(),cy=cw.extend({type:ce.eu("sqlite"),path:ce.Yj().optional().describe("SQLite database file path (optional, will auto-detect using path resolver if not provided)"),database:ce.Yj().optional().describe("Database filename (default: <agent-id>.db)")}).strict(),cz=cw.extend({type:ce.eu("postgres"),url:cf().optional().describe("PostgreSQL connection URL (postgresql://...)"),connectionString:cf().optional().describe("PostgreSQL connection string"),host:ce.Yj().optional().describe("PostgreSQL host"),port:ce.ai().int().positive().optional().describe("PostgreSQL port"),database:ce.Yj().optional().describe("PostgreSQL database name"),password:ce.Yj().optional().describe("PostgreSQL password")}).strict();function cA({value:a,onChange:b,errors:c={},open:e,onOpenChange:f,errorCount:g=0,sectionErrors:h=[]}){let i=c=>{b({...a,cache:{...a.cache,...c}})},j=c=>{b({...a,database:{...a.database,...c}})},k="redis"===a.cache.type,l="sqlite"===a.database.type||"postgres"===a.database.type;return(0,d.jsx)(b3,{title:"Storage Configuration",defaultOpen:!1,open:e,onOpenChange:f,errorCount:g,sectionErrors:h,children:(0,d.jsxs)("div",{className:"space-y-6",children:[(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)("h4",{className:"text-sm font-medium",children:"Cache"}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"cache-type",tooltip:"Storage backend for caching data (in-memory or Redis)",children:"Cache Type"}),(0,d.jsx)("select",{id:"cache-type",value:a.cache.type,onChange:a=>i({type:a.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:cr.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),k&&"url"in a.cache&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"cache-url",tooltip:"Redis connection URL (e.g., redis://localhost:6379)",children:"Redis URL"}),(0,d.jsx)(aP.p,{id:"cache-url",value:a.cache.url||"",onChange:a=>i({url:a.target.value||void 0}),placeholder:"redis://localhost:6379","aria-invalid":!!c["storage.cache.url"]}),c["storage.cache.url"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["storage.cache.url"]})]})]}),(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsx)("h4",{className:"text-sm font-medium",children:"Database"}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"database-type",tooltip:"Storage backend for persistent data (in-memory, SQLite, or PostgreSQL)",children:"Database Type"}),(0,d.jsx)("select",{id:"database-type",value:a.database.type,onChange:a=>j({type:a.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:cv.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]}),l&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"database-url",tooltip:"sqlite"===a.database.type?"File path for SQLite database":"PostgreSQL connection string",children:"sqlite"===a.database.type?"SQLite Path":"PostgreSQL URL"}),(0,d.jsx)(aP.p,{id:"database-url",value:"url"in a.database&&a.database.url||"path"in a.database&&a.database.path||"",onChange:b=>{"sqlite"===a.database.type?j({path:b.target.value||void 0}):j({url:b.target.value||void 0})},placeholder:"sqlite"===a.database.type?"./dexto.db":"postgresql://user:pass@localhost:5432/dexto","aria-invalid":!!(c["storage.database.url"]||c["storage.database.path"])}),(c["storage.database.url"]||c["storage.database.path"])&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["storage.database.url"]||c["storage.database.path"]})]})]})]})})}ce.gM("type",[cx,cy,cz],{errorMap:(a,b)=>a.code===ch.eq.invalid_union_discriminator?{message:"Invalid database type. Expected 'in-memory', 'sqlite', or 'postgres'."}:{message:b.defaultError}}).describe("Database configuration").superRefine((a,b)=>{"postgres"!==a.type||a.url||a.connectionString||a.host||b.addIssue({code:ch.eq.custom,message:"PostgreSQL database requires one of 'url', 'connectionString', or 'host' to be specified",path:["url"],params:{code:cq.CONNECTION_CONFIG_MISSING,scope:cc.STORAGE,type:cd.USER}})});let cB=["search_history","ask_user","read_file","glob_files","grep_content","write_file","edit_file","bash_exec","bash_output","kill_process"],cC=["event-based","auto-approve","auto-deny"],cD=["memory","storage"],cE="event-based",cF="storage";ce.YO(ce.k5(cB).describe("Available internal tool names")).default([]).describe(`Array of internal tool names to enable. Empty array = disabled. Available tools: ${cB.join(", ")}`);let cG=ce.Ik({alwaysAllow:ce.YO(ce.Yj()).default([]).describe('Tools that never require approval (low-risk). Use full qualified names (e.g., "internal--ask_user", "mcp--filesystem--read_file")'),alwaysDeny:ce.YO(ce.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 cH({value:a,onChange:b,errors:c={},open:e,onOpenChange:f,errorCount:g=0,sectionErrors:h=[]}){let i=c=>{b({...a,...c})};return(0,d.jsx)(b3,{title:"Tool Confirmation",defaultOpen:!1,open:e,onOpenChange:f,errorCount:g,sectionErrors:h,children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"confirmation-mode",tooltip:"How the agent handles tool execution requests",children:"Confirmation Mode"}),(0,d.jsx)("select",{id:"confirmation-mode",value:a.mode||cE,onChange:a=>i({mode:a.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:cC.map(a=>(0,d.jsx)("option",{value:a,children:"auto-approve"===a?"Auto-approve":"event-based"===a?"Event-based":"Auto-deny"},a))}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"event-based"===a.mode?"Require explicit approval before executing tools":"auto-deny"===a.mode?"Automatically deny all tool executions":"Automatically approve tool executions"})]}),"event-based"===a.mode&&(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"confirmation-timeout",tooltip:"How long to wait for approval before timing out",children:"Timeout (seconds)"}),(0,d.jsx)(aP.p,{id:"confirmation-timeout",type:"number",value:a.timeout||"",onChange:a=>i({timeout:a.target.value?parseInt(a.target.value,10):void 0}),min:"1",placeholder:"e.g., 60","aria-invalid":!!c["toolConfirmation.timeout"]}),c["toolConfirmation.timeout"]&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c["toolConfirmation.timeout"]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"allowed-tools-storage",tooltip:"Where to store the list of pre-approved tools (memory or persistent storage)",children:"Allowed Tools Storage"}),(0,d.jsx)("select",{id:"allowed-tools-storage",value:a.allowedToolsStorage||cF,onChange:c=>{var d;return d=c.target.value,void b({...a,allowedToolsStorage:d})},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:cD.map(a=>(0,d.jsx)("option",{value:a,children:a},a))})]})]})})}function cI({config:a,onChange:b,errors:c={}}){var f;let g=a.systemPrompt?"string"==typeof a.systemPrompt?{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:a.systemPrompt}]}:{contributors:a.systemPrompt.contributors||[]}:{contributors:[]},[h,i]=(0,e.useState)({basic:!0,llm:!1,systemPrompt:!1,mcpServers:!1,storage:!1,toolConfirmation:!1}),j=function(a){let b={basic:[],llm:[],systemPrompt:[],mcpServers:[],storage:[],toolConfirmation:[]};return Object.entries(a).forEach(([a,c])=>{"greeting"===a?b.basic.push(c):a.startsWith("llm.")?b.llm.push(c):a.startsWith("systemPrompt")?b.systemPrompt.push(c):a.startsWith("mcpServers")?b.mcpServers.push(c):a.startsWith("storage.")?b.storage.push(c):a.startsWith("toolConfirmation.")&&b.toolConfirmation.push(c)}),b}(c),k=a=>{i(b=>({...b,[a]:!b[a]}))},l=!!(f=a).sessions&&!!(Object.keys(f.sessions).length>0)||!!f.internalTools;return(0,d.jsxs)("div",{className:"flex flex-col h-full overflow-auto",children:[l&&(0,d.jsx)("div",{className:"mx-4 mt-4 p-3 bg-yellow-500/10 border border-yellow-500/20 rounded-lg",children:(0,d.jsxs)("div",{className:"flex items-start gap-2",children:[(0,d.jsx)(bd.A,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 mt-0.5 flex-shrink-0"}),(0,d.jsxs)("div",{className:"text-sm",children:[(0,d.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-500",children:"Advanced Configuration Detected"}),(0,d.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,d.jsxs)("div",{className:"flex-1 p-4 space-y-4",children:[(0,d.jsx)(b3,{title:"Basic Information",open:h.basic,onOpenChange:()=>k("basic"),errorCount:j.basic.length,sectionErrors:j.basic,children:(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(a9,{htmlFor:"agent-greeting",tooltip:"The initial message shown to users when they start a conversation",children:"Greeting Message"}),(0,d.jsx)(aP.p,{id:"agent-greeting",value:a.greeting||"",onChange:c=>b({...a,greeting:c.target.value}),placeholder:"Hello! How can I help you today?","aria-invalid":!!c.greeting}),c.greeting&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:c.greeting})]})}),(0,d.jsx)(b8,{value:a.llm,onChange:c=>{b({...a,llm:c})},errors:c,open:h.llm,onOpenChange:()=>k("llm"),errorCount:j.llm.length,sectionErrors:j.llm}),(0,d.jsx)(ca,{value:g,onChange:c=>{b({...a,systemPrompt:c})},errors:c,open:h.systemPrompt,onOpenChange:()=>k("systemPrompt"),errorCount:j.systemPrompt.length,sectionErrors:j.systemPrompt}),(0,d.jsx)(cp,{value:a.mcpServers||{},onChange:c=>{b({...a,mcpServers:c})},errors:c,open:h.mcpServers,onOpenChange:()=>k("mcpServers"),errorCount:j.mcpServers.length,sectionErrors:j.mcpServers}),(0,d.jsx)(cA,{value:a.storage||{cache:{type:"in-memory"},database:{type:"in-memory"}},onChange:c=>{b({...a,storage:c})},errors:c,open:h.storage,onOpenChange:()=>k("storage"),errorCount:j.storage.length,sectionErrors:j.storage}),(0,d.jsx)(cH,{value:a.toolConfirmation||{},onChange:c=>{b({...a,toolConfirmation:c})},errors:c,open:h.toolConfirmation,onOpenChange:()=>k("toolConfirmation"),errorCount:j.toolConfirmation.length,sectionErrors:j.toolConfirmation})]})]})}function cJ({config:a,onChange:b,errors:c={}}){return(0,d.jsx)("div",{className:"flex flex-col h-full",children:(0,d.jsx)(cI,{config:a,onChange:b,errors:c})})}ce.Ik({mode:ce.k5(cC).default(cE).describe("Tool confirmation mode: event-based (interactive), auto-approve (all tools), auto-deny (no tools)"),timeout:ce.ai().int().positive().default(12e4).describe("Timeout for tool confirmation requests in milliseconds, defaults to 120000ms (2 mins)"),allowedToolsStorage:ce.k5(cD).default(cF).describe("Storage type for remembered tool approvals: memory (session-only) or storage (persistent)"),toolPolicies:cG.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 cK=c(94428);let cL=`${(0,g.e)()}/api`;function cM({isOpen:a,onClose:b,variant:c="overlay"}){let[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(""),[k,l]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(""),[y,z]=(0,e.useState)("yaml"),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(!1),[E,F]=(0,e.useState)(!1),[G,H]=(0,e.useState)(null),[I,J]=(0,e.useState)(null),[K,L]=(0,e.useState)(!1),[N,O]=(0,e.useState)(""),[P,Q]=(0,e.useState)(!1),[R,S]=(0,e.useState)(!0),[T,U]=(0,e.useState)([]),[V,W]=(0,e.useState)([]),[X,Y]=(0,e.useState)(!1),[Z,$]=(0,e.useState)(!1),_=(0,e.useRef)(null),aa=(0,e.useRef)(0),ab=(0,e.useCallback)(async()=>{D(!0),H(null);try{let a=await fetch(`${cL}/agent/config`);if(!a.ok){let b=await a.json().catch(()=>({error:"Failed to load configuration"}));throw Error(b.message||b.error||`Load failed: ${a.statusText}`)}let b=await a.json();g(b.yaml),i(b.yaml),t(b.relativePath),Y(!1);let{config:c,document:d}=ad(b.yaml);c&&d&&(l(c),o(c),r(d)),await ac(b.yaml)}catch(b){let a=b instanceof Error?b.message:String(b);H(a),console.error(`Error loading agent config: ${a}`)}finally{D(!1)}},[]),ac=async a=>{let b=aa.current+1;aa.current=b,Q(!0);try{let c=await fetch(`${cL}/agent/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:a})}),d=await c.json();aa.current===b&&(S(d.valid),U(d.errors||[]),W(d.warnings||[]))}catch(a){console.error(`Validation error: ${a instanceof Error?a.message:String(a)}`),aa.current===b&&(S(!1),U([{message:"Failed to validate configuration",code:"VALIDATION_ERROR"}]))}finally{aa.current===b&&Q(!1)}},ad=a=>{console.log("[parseYamlToConfig] Starting parse");try{let b=cK.Tp(a);if(console.log("[parseYamlToConfig] Document created:",b),b.errors&&b.errors.length>0){console.error("[parseYamlToConfig] Parse errors:",b.errors);let a=b.errors.map(a=>a.message).join("; ");return{config:null,document:null,error:a}}let c=b.toJS();return console.log("[parseYamlToConfig] Config parsed successfully:",c),{config:c,document:b,error:null}}catch(a){return console.error("[parseYamlToConfig] Exception:",a),{config:null,document:null,error:a instanceof Error?a.message:"Failed to parse YAML"}}},ae=a=>{if(console.log("[handleModeSwitch] Called with newMode:",a,"current mode:",y),a===y)return void console.log("[handleModeSwitch] Same mode, returning");if("form"===a){console.log("[handleModeSwitch] Switching to form mode, parsing YAML...");let{config:a,document:b,error:c}=ad(f);if(console.log("[handleModeSwitch] Parse result:",{config:a,document:b,error:c}),c){console.error("[handleModeSwitch] Parse error, not switching:",c),B(c);return}console.log("[handleModeSwitch] Parse successful, setting state"),l(a),r(b),B(null)}console.log("[handleModeSwitch] Setting editor mode to:",a),z(a)},af=async()=>{if(!R||T.length>0)return void J("Cannot save: configuration has errors");F(!0),J(null),L(!1),O("");try{let a=await fetch(`${cL}/agent/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:f})});if(!a.ok){let b=await a.json().catch(()=>({error:"Failed to save configuration"}));throw Error(b.message||b.error||`Save failed: ${a.statusText}`)}let b=await a.json();i(f),Y(!1),L(!0),b.restarted?O(`Configuration applied successfully — ${b.changesApplied.join(", ")} updated`):O("Configuration saved successfully (no changes detected)"),setTimeout(()=>{L(!1),O("")},5e3)}catch(b){let a=b instanceof Error?b.message:String(b);J(a),console.error(`Error saving agent config: ${a}`)}finally{F(!1)}},ag=()=>{X?$(!0):b()};if(!a)return null;let ah=(()=>{if(E)return null;if(!X)return"No changes to save";if(T.length>0){let a=T[0];return a.path?`Configuration error in ${a.path}: ${a.message}`:`Configuration error: ${a.message}`}return R?null:"Configuration has validation errors"})(),ai=!X||E||!R||T.length>0,aj=(0,d.jsxs)("div",{className:"flex flex-col h-full bg-background",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,d.jsx)("div",{className:"flex items-center gap-3",children:(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:"Customize Agent"}),(0,d.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,d.jsx)(bC.A,{className:"h-3 w-3"})]})]}),s&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:s})]})}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1 bg-muted/50 rounded-md p-1",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"yaml"===y?"default":"ghost",size:"sm",onClick:()=>ae("yaml"),className:"h-7 px-3",children:"YAML Editor"})}),(0,d.jsx)(w,{children:"Edit configuration in raw YAML format with full control"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"form"===y?"default":"ghost",size:"sm",onClick:()=>ae("form"),className:"h-7 px-3",children:"Form Editor"})}),(0,d.jsx)(w,{children:"Edit configuration using user-friendly forms"})]})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>{X?$(!0):ab()},disabled:C,children:(0,d.jsx)(bE.A,{className:(0,j.cn)("h-4 w-4",C&&"animate-spin")})})}),(0,d.jsx)(w,{children:"Reload configuration"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:ag,children:(0,d.jsx)(p.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Close (Esc)"})]})]})]}),(0,d.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:G?(0,d.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,d.jsxs)("div",{className:"text-center max-w-md",children:[(0,d.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,d.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Failed to load configuration"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:G}),(0,d.jsxs)(x.$,{onClick:ab,variant:"outline",children:[(0,d.jsx)(bE.A,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):C?(0,d.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,d.jsxs)("div",{className:"text-center",children:[(0,d.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading configuration..."})]})}):A&&"form"===y?(0,d.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,d.jsxs)("div",{className:"text-center max-w-md",children:[(0,d.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,d.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Cannot parse YAML"}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:A}),(0,d.jsx)(x.$,{onClick:()=>z("yaml"),variant:"outline",children:"Switch to YAML Editor"})]})}):"yaml"===y?(0,d.jsx)(b2,{value:f,onChange:a=>{g(a),Y(a!==h),J(null),L(!1);let{config:b,document:c}=ad(a);b&&c&&(l(b),r(c)),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{ac(a)},500)},isValidating:P,isValid:R,errors:T,warnings:V,hasUnsavedChanges:X}):k?(0,d.jsx)(cJ,{config:k,onChange:a=>{if(console.log("[handleFormChange] Called with new config"),console.log("[handleFormChange] yamlDocument exists?",!!q),!q)return void console.error("[handleFormChange] No document available - this should not happen!");l(a);let b=((a,b)=>{console.log("[serializeConfigToYaml] Starting serialization"),console.log("[serializeConfigToYaml] Document:",b),console.log("[serializeConfigToYaml] Config:",a);let c=(a=>{let b=a=>!!(null==a||""===a||""===a||Array.isArray(a)&&0===a.length)||"object"==typeof a&&null!==a&&"[object Object]"===Object.prototype.toString.call(a)&&0===Object.keys(a).length,c=a=>{if(Array.isArray(a))return a.map(c).filter(a=>!b(a));if("object"==typeof a&&null!==a){let d={};for(let[e,f]of Object.entries(a))if(!b(f))if("object"==typeof f&&null!==f){let a=c(f);b(a)||(d[e]=a)}else d[e]=f;return d}return a};return c(a)})(a);console.log("[serializeConfigToYaml] Cleaned config:",c);let d=((a,b)=>{console.log("[updateYamlDocumentFromConfig] Starting update"),console.log("[updateYamlDocumentFromConfig] Document:",a),console.log("[updateYamlDocumentFromConfig] Config:",b);let c=(b,d)=>{if(null==d||Array.isArray(d))return a.createNode(d);if("object"==typeof d&&!Array.isArray(d)){if(!b||!b.items)return a.createNode(d);let e=new Set;for(let a of b.items){let b=a.key.value;e.add(b),b in d&&(a.value=c(a.value,d[b]))}for(let[c,f]of Object.entries(d))e.has(c)||b.items.push(a.createPair(c,f));return b.items=b.items.filter(a=>a.key.value in d),b}return a.createNode(d)};try{return a.contents=c(a.contents,b),console.log("[updateYamlDocumentFromConfig] Update successful"),a}catch(a){throw console.error("[updateYamlDocumentFromConfig] Update failed:",a),a}})(b,c).toString();return console.log("[serializeConfigToYaml] Serialized result length:",d.length),d})(a,q);g(b),Y(!(a===n||a&&n&&JSON.stringify(a)===JSON.stringify(n))),J(null),L(!1),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{ac(b)},500)},errors:T.reduce((a,b)=>(b.path&&(a[b.path]=b.message),a),{})}):null}),!G&&!C&&(0,d.jsxs)("div",{className:"flex flex-col border-t border-border",children:[(K||I)&&(0,d.jsxs)("div",{className:"px-4 py-3 bg-muted/50 border-b border-border",children:[K&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-500",children:[(0,d.jsx)(M.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:N})]}),I&&(0,d.jsxs)("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:I})]})]}),(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3",children:[(0,d.jsx)("div",{}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(x.$,{variant:"outline",size:"sm",onClick:ag,children:"Close"}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)("div",{children:(0,d.jsx)(x.$,{variant:"default",size:"sm",onClick:af,disabled:ai,children:E?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-background border-t-transparent mr-2"}),"Saving..."]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(b$.A,{className:"h-4 w-4 mr-2"}),"Save"]})})})}),(0,d.jsx)(w,{children:ah||"Save configuration (⌘S)"})]})]})]})]}),(0,d.jsx)(aN.lG,{open:Z,onOpenChange:$,children:(0,d.jsxs)(aN.Cf,{children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Unsaved Changes"}),(0,d.jsx)(aN.rr,{children:"You have unsaved changes. Do you want to discard them?"})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>$(!1),children:"Cancel"}),(0,d.jsx)(x.$,{variant:"destructive",onClick:()=>{$(!1),g(h),Y(!1),ab()},children:"Discard Changes"})]})]})})]});return"inline"===c?aj:(0,d.jsx)("div",{className:(0,j.cn)("fixed inset-y-0 right-0 z-50 w-full sm:w-[600px] md:w-[700px] lg:w-[800px] border-l border-border bg-background shadow-2xl transform transition-transform duration-300",a?"translate-x-0":"translate-x-full"),children:aj})}var cN=c(41936),cO=c(18580),cP=c(48351),cQ=c(40888),cR=c(3785),cS=c(77851),cT=c(94073),cU=c(58068);function cV(){let{theme:a,toggleTheme:b}=function(){let[a,b]=(0,e.useState)(()=>"undefined"!=typeof document?document.documentElement.classList.contains("dark")?"dark":"light":"dark");return{theme:a,toggleTheme:a=>{b(a?"dark":"light")},hasMounted:!0}}(),[c,f]=(0,e.useState)(!1),g="dark"===a;return c?(0,d.jsx)(t,{children:(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(aw.bL,{checked:g,onCheckedChange:b,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,d.jsx)(aw.zi,{className:`
8
8
  w-5 h-5 rounded-full shadow flex items-center justify-center
9
9
  transition-transform transform
10
10
  translate-x-0.5 data-[state=checked]:translate-x-[1.375rem]
11
11
  bg-white dark:bg-gray-100
12
- `,children:g?(0,d.jsx)(cS.A,{className:"w-3.5 h-3.5 text-gray-700"}):(0,d.jsx)(cT.A,{className:"w-3.5 h-3.5 text-yellow-500"})})})}),(0,d.jsx)(w,{children:g?"Switch to light mode":"Switch to dark mode"})]})}):(0,d.jsx)("div",{className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full"})}var cV=c(74985);function cW({active:a=!1}){let{voices:b,selected:c,setSelected:f}=function(){let[a,b]=(0,e.useState)(E.getVoices()),[c,d]=(0,e.useState)(E.getPreferredVoiceName());return{voices:a,selected:c,setSelected:a=>{E.setPreferredVoice(a),d(E.getPreferredVoiceName())}}}(),[g,h]=(0,e.useState)(!1);return a?(0,d.jsxs)(cV.l6,{value:c??"auto",onValueChange:a=>{f("auto"===a?null:a)},children:[(0,d.jsx)(cV.bq,{className:"h-8 w-[12rem] text-xs",children:(0,d.jsx)(cV.yv,{placeholder:"Voice"})}),(0,d.jsxs)(cV.gC,{children:[(0,d.jsx)(cV.eb,{value:"auto",children:"Auto (best available)"}),g&&b.map(a=>(0,d.jsxs)(cV.eb,{value:a.name,children:[a.name," (",a.lang,")"]},`${a.name}-${a.lang}`))]})]}):null}function cX({isOpen:a,onClose:b}){return(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-lg",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Settings"}),(0,d.jsx)(aN.rr,{children:"Configure preferences for speech and more."})]}),(0,d.jsx)("div",{className:"space-y-6 py-2",children:(0,d.jsxs)("section",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{className:"text-xs uppercase text-muted-foreground",children:"Voice"}),(0,d.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,d.jsx)(cW,{active:a})]})})]})})}var cY=c(26960),cZ=c(71436);let c$={id:"",name:"",description:"",author:"",tags:""},c_={llm:{provider:"openai",model:"gpt-5",apiKey:""},systemPrompt:{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:""}]}};function c0({open:a,onOpenChange:b,onAgentCreated:c}){let[f,h]=(0,e.useState)(c$),[i,j]=(0,e.useState)(c_),[k,l]=(0,e.useState)({}),[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)({basic:!0,llm:!0,systemPrompt:!0}),s=a=>{r(b=>({...b,[a]:!b[a]}))},t=(a,b)=>{h(c=>({...c,[a]:b})),k[a]&&l(b=>{let c={...b};return delete c[a],c})},u=async()=>{if((()=>{let a={};f.id.trim()?/^[a-z0-9-]+$/.test(f.id)||(a.id="Agent ID must contain only lowercase letters, numbers, and hyphens"):a.id="Agent ID is required",f.name.trim()||(a.name="Agent name is required"),f.description.trim()||(a.description="Description is required"),i.llm?.provider||(a["llm.provider"]="Provider is required"),i.llm?.model?.trim()||(a["llm.model"]="Model is required");let b=i.systemPrompt;if(b&&"object"==typeof b&&"contributors"in b){let c=b.contributors;Array.isArray(c)&&(c.some(a=>!!("static"===a.type&&"string"==typeof a.content&&a.content.trim()))||(a.systemPrompt="At least one static contributor with content is required"))}else"string"!=typeof b||b.trim()||(a.systemPrompt="System prompt is required");return l(a),0===Object.keys(a).length})()){n(!0),p(null);try{let a="";if(i.systemPrompt&&"object"==typeof i.systemPrompt&&"contributors"in i.systemPrompt){let b=i.systemPrompt.contributors;if(Array.isArray(b)){let c=b.find(a=>"static"===a.type&&a.content);c&&"content"in c&&"string"==typeof c.content&&(a=c.content.trim())}}else"string"==typeof i.systemPrompt&&(a=i.systemPrompt.trim());a||(a="You are a helpful AI assistant.");let d=await fetch(`${(0,g.e)()}/api/agents/custom/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:f.id.trim(),name:f.name.trim(),description:f.description.trim(),author:f.author.trim()||void 0,tags:f.tags.split(",").map(a=>a.trim()).filter(Boolean),llm:{provider:i.llm?.provider,model:i.llm?.model?.trim(),...i.llm?.apiKey?.trim()&&{apiKey:i.llm.apiKey.trim()}},systemPrompt:a})});if(!d.ok){let a=await d.json().catch(()=>({error:"Failed to create agent"}));throw Error(a.message||a.error||`Creation failed: ${d.statusText}`)}let e=await d.json();h(c$),j(c_),l({}),b(!1),c&&e.id&&c(e.id)}catch(a){p(a instanceof Error?a.message:"An unexpected error occurred")}finally{n(!1)}}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"max-w-2xl max-h-[90vh] flex flex-col",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create New Agent"}),(0,d.jsxs)(aN.rr,{children:["Create a custom agent with your own configuration.",(0,d.jsx)("br",{}),(0,d.jsx)("br",{}),"You can add more advanced configuration after creating the agent using the Edit Agent button."]})]}),o&&(0,d.jsxs)("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-3 flex items-start gap-2",children:[(0,d.jsx)(bc.A,{className:"h-4 w-4 text-destructive mt-0.5 flex-shrink-0"}),(0,d.jsx)("div",{className:"text-sm text-destructive",children:o})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4 pr-2",children:[(0,d.jsx)(b2,{title:"Basic Information",open:q.basic,onOpenChange:()=>s("basic"),children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-id",tooltip:"Unique identifier for this agent (lowercase, no spaces, hyphens only)",children:"Agent ID *"}),(0,d.jsx)(aP.p,{id:"agent-id",value:f.id,onChange:a=>t("id",a.target.value),placeholder:"my-custom-agent","aria-invalid":!!k.id}),k.id&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.id})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-name",tooltip:"Display name for this agent (shown in UI)",children:"Agent Name *"}),(0,d.jsx)(aP.p,{id:"agent-name",value:f.name,onChange:a=>t("name",a.target.value),placeholder:"My Custom Agent","aria-invalid":!!k.name}),k.name&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.name})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-description",tooltip:"Brief description of what this agent does",children:"Description *"}),(0,d.jsx)(aP.p,{id:"agent-description",value:f.description,onChange:a=>t("description",a.target.value),placeholder:"A custom agent for specific tasks","aria-invalid":!!k.description}),k.description&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.description})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-author",tooltip:"Your name or organization",children:"Author"}),(0,d.jsx)(aP.p,{id:"agent-author",value:f.author,onChange:a=>t("author",a.target.value),placeholder:"Your Name"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-tags",tooltip:"Comma-separated tags for categorization",children:"Tags"}),(0,d.jsx)(aP.p,{id:"agent-tags",value:f.tags,onChange:a=>t("tags",a.target.value),placeholder:"coding, custom, specialized"})]})]})}),(0,d.jsx)(b7,{value:i.llm||{provider:"openai",model:"gpt-5",apiKey:""},onChange:a=>j(b=>({...b,llm:a})),errors:k,open:q.llm,onOpenChange:()=>s("llm"),errorCount:0,sectionErrors:[]}),(0,d.jsx)(b9,{value:"object"==typeof i.systemPrompt&&"contributors"in i.systemPrompt?{contributors:i.systemPrompt.contributors||[]}:{contributors:[]},onChange:a=>j(b=>({...b,systemPrompt:a})),errors:k,open:q.systemPrompt,onOpenChange:()=>s("systemPrompt"),errorCount:0,sectionErrors:[]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>{h(c$),j(c_),l({}),p(null),b(!1)},disabled:m,children:"Cancel"}),(0,d.jsxs)(x.$,{onClick:u,disabled:m,children:[m&&(0,d.jsx)(N.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Agent"]})]})]})})}let c1="dexto:recentAgents";function c2({mode:a="default"}){let b=(0,h.useRouter)(),{returnToWelcome:c}=(0,i.v)(),[f,j]=(0,e.useState)([]),[k,l]=(0,e.useState)([]),[m,n]=(0,e.useState)(null),[p,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)(!1),[w,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(!1),[B,C]=(0,e.useState)(!1),D=(0,e.useCallback)(()=>{try{let a=localStorage.getItem(c1);if(!a)return[];return JSON.parse(a).sort((a,b)=>b.lastUsed-a.lastUsed).slice(0,5)}catch(a){return console.error("Failed to load recent agents:",a),localStorage.removeItem(c1),[]}},[]),E=(0,e.useCallback)(a=>{try{let b=D().filter(b=>b.path!==a.path),c=[{...a,lastUsed:Date.now()},...b].slice(0,5);localStorage.setItem(c1,JSON.stringify(c)),t(c)}catch(a){console.error("Failed to save recent agent:",a)}},[D]),F=(0,e.useCallback)(async()=>{try{let a=await fetch(`${(0,g.e)()}/api/agents`);if(!a.ok)throw Error("Failed to fetch agents");let b=await a.json();j(b.installed||[]),l(b.available||[]),n(b.current.id);try{let a=await fetch(`${(0,g.e)()}/api/agent/path`);if(a.ok){let b=await a.json();r(b),b.path&&b.name&&E({id:b.name,name:b.name,path:b.path})}}catch(a){console.error("Failed to fetch agent path:",a)}return b}catch(a){return console.error(`AgentSelector load error: ${a}`),null}},[E]),G=(0,e.useCallback)(async a=>{try{y(!0);let d=f.find(b=>b.id===a);if(!d)throw console.error(`Agent not found in installed list: ${a}`),Error(`Agent '${a}' not found. Please refresh the agents list.`);let e=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!e.ok){let a=await e.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${e.status} ${e.statusText}`)}n(a),A(!1),await F();try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a,name:d.name}}))}catch{}c(),b.push("/")}catch(b){console.error(`Switch agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to switch agent";alert(`Failed to switch agent: ${a}`)}finally{y(!1)}},[c,f,F,b]),H=(0,e.useCallback)(async a=>{try{y(!0);let d=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a.id,path:a.path})});if(!d.ok){let a=await d.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${d.status} ${d.statusText}`)}n(a.id),A(!1),await F(),E(a);try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a.id,name:a.name}}))}catch{}c(),b.push("/")}catch(b){console.error(`Switch agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to switch agent";alert(`Failed to switch agent: ${a}`)}finally{y(!1)}},[c,E,F,b]),I=(0,e.useCallback)(async a=>{try{y(!0);let b=await fetch(`${(0,g.e)()}/api/agents/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!b.ok){let a=await b.json().catch(()=>({}));throw Error(a.error||`Install failed: ${b.status}`)}let d=await F();if(!d)throw Error("Failed to reload agents list after installation");let e=d.installed.find(b=>b.id===a);if(!e)throw console.error(`Agent not found in fresh installed list: ${a}`),Error(`Agent '${a}' not found after installation. Please refresh.`);let f=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!f.ok){let a=await f.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${f.status} ${f.statusText}`)}n(a),A(!1);try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a,name:e.name}}))}catch{}c()}catch(b){console.error(`Install agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to install agent";alert(`Failed to install agent: ${a}`)}finally{y(!1)}},[F,c]),J=(0,e.useCallback)(async(a,b)=>{if(b.stopPropagation(),confirm(`Are you sure you want to delete the custom agent "${a.name}"?`))try{y(!0);let b=await fetch(`${(0,g.e)()}/api/agents/uninstall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a.id})});if(!b.ok){let a=await b.json().catch(()=>({}));throw Error(a.error||`Delete failed: ${b.status}`)}let c=await F();c?.current.id===a.id&&n(null)}catch(b){console.error(`Delete agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to delete agent";alert(`Failed to delete agent: ${a}`)}finally{y(!1)}},[m,F]),K=(0,e.useCallback)(async a=>{await new Promise(a=>setTimeout(a,1e3)),await F()},[F]),L=(0,e.useMemo)(()=>{if(!m)return"Choose Agent";let a=f.find(a=>a.id===m)||k.find(a=>a.id===m);return a?.name??m},[k,m,f]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aD,{open:z,onOpenChange:A,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"badge"===a?"outline":"default",size:"sm",className:(a=>{let b="transition-all duration-200 shadow-lg hover:shadow-xl font-semibold rounded-full";switch(a){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] ${b}`;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 ${b}`;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 ${b}`}})(a),disabled:w,children:(0,d.jsxs)("div",{className:"flex items-center justify-between w-full min-w-0",children:[(0,d.jsx)(aZ.A,{className:"w-4 h-4 mr-2 flex-shrink-0"}),(0,d.jsx)("span",{className:"flex-1 text-center truncate min-w-0 px-1",children:w?"Switching...":"title"===a?`Agent: ${L}`:L}),(0,d.jsx)(o.A,{className:"w-4 h-4 ml-2 flex-shrink-0"})]})})}),(0,d.jsxs)(aF,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[u&&(0,d.jsx)(aG,{disabled:!0,className:"text-center text-muted-foreground",children:"Loading agents..."}),!u&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aG,{onClick:()=>{C(!0),A(!1)},disabled:w,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,d.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,d.jsx)(aU.A,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),(0,d.jsx)("span",{className:"font-semibold text-purple-600 dark:text-purple-400",children:"New Agent"})]})}),p&&!f.some(a=>a.id===p.name)&&(0,d.jsxs)(d.Fragment,{children:[(0,d.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,d.jsx)(aG,{onClick:()=>H({id:p.name,name:p.name,path:p.path}),disabled:w||m===p.name,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:p.name}),m===p.name&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:"Loaded from file"})]})})}),(0,d.jsx)(aH,{})]}),s.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Recent"}),s.filter(a=>!f.some(b=>b.id===a.id)&&a.id!==p?.name&&!a.path.includes("/.dexto/")).slice(0,3).map(a=>(0,d.jsx)(aG,{onClick:()=>H(a),disabled:w||a.id===m,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===m&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",title:a.path,children:a.path})]})})},a.path)),(0,d.jsx)(aH,{})]}),f.filter(a=>"custom"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.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,d.jsx)(cY.A,{className:"w-3 h-3"}),"Custom Agents"]}),f.filter(a=>"custom"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>G(a.id),disabled:w||a.id===m,className:"cursor-pointer py-3",children:(0,d.jsxs)("div",{className:"flex items-center justify-between w-full gap-2",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===m&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]}),(0,d.jsx)("button",{onClick:b=>J(a,b),disabled:w,className:"p-1 hover:bg-red-100 dark:hover:bg-red-900/30 rounded transition-colors",title:"Delete custom agent",children:(0,d.jsx)(bj.A,{className:"w-4 h-4 text-red-600 dark:text-red-400"})})]})},a.id))]}),f.filter(a=>"builtin"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[f.filter(a=>"custom"===a.type).length>0&&(0,d.jsx)(aH,{}),(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Installed"}),f.filter(a=>"builtin"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>G(a.id),disabled:w||a.id===m,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===m&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]})})},a.id))]}),k.filter(a=>"builtin"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[f.length>0&&(0,d.jsx)(aH,{}),(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Available"}),k.filter(a=>"builtin"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>I(a.id),disabled:w,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),(0,d.jsx)(cZ.A,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]})})},a.id))]}),!u&&0===f.length&&0===k.length&&(0,d.jsx)(aG,{disabled:!0,className:"text-center text-muted-foreground",children:"No agents found"})]})]})]}),(0,d.jsx)(c0,{open:B,onOpenChange:C,onAgentCreated:K})]})}function c3({sessionId:a}={}){let b=(0,h.useRouter)(),[c,k]=(0,e.useState)(!1),{messages:l,sendMessage:n,currentSessionId:p,switchSession:r,isWelcomeState:s,returnToWelcome:t,websocket:y,activeError:z,clearError:A,processing:B,cancel:C,greeting:D,isStreaming:E,setStreaming:F}=(0,i.v)(),[G,H]=(0,e.useState)(!1),[I,L]=(0,e.useState)(!1),[M,N]=(0,e.useState)(!1),[O,P]=(0,e.useState)(!1),[Q,R]=(0,e.useState)(!1),S=f().useRef(!0),[T,U]=(0,e.useState)(!1),[V,W]=(0,e.useState)(!1),[X,Y]=(0,e.useState)(!1),[Z,$]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(!1),[ab,ac]=(0,e.useState)("dexto-config"),[ad,ae]=(0,e.useState)(null),[af,ag]=(0,e.useState)(""),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(null),[al,am]=(0,e.useState)(!1),[an,ao]=(0,e.useState)(!1),[aq,ar]=(0,e.useState)(!1),[as,at]=(0,e.useState)(null),[au,aw]=(0,e.useState)(!1),[ay,az]=(0,e.useState)(!1),[aA,aB]=(0,e.useState)(null),[aC,aI]=(0,e.useState)(null),[aJ,aK]=(0,e.useState)([]),[aL,aM]=(0,e.useState)(!1),[aR,aS]=(0,e.useState)(0),aT=f().useRef(null),aU=f().useRef(null),[aV,aW]=(0,e.useState)(!0),[aZ,a$]=(0,e.useState)(!1),[a_,a0]=(0,e.useState)(!1);f().useRef(0);let[a1,a2]=(0,e.useState)(!1);f().useRef(null);let[a3,a4]=(0,e.useState)(0),[a5,a6]=(0,e.useState)(null),[a7,a8]=(0,e.useState)(!1);(0,e.useCallback)(()=>{let a=aT.current;a&&aW(a.scrollHeight-a.scrollTop<=a.clientHeight+1)},[]);let a9=(0,e.useCallback)((a="auto")=>{let b=aT.current;b&&(a$(!0),b.scrollTo({top:b.scrollHeight,behavior:a}),requestAnimationFrame(()=>a$(!1)))},[]),ba=(0,e.useCallback)(()=>{let a=aT.current;if(!a)return;let b=a.querySelectorAll('[data-role="user"]'),c=b[b.length-1];if(!c)return void a9("auto");let d=a.getBoundingClientRect(),e=Math.max(c.getBoundingClientRect().top-d.top+a.scrollTop-16,0);a$(!0),a.scrollTo({top:e,behavior:"auto"}),requestAnimationFrame(()=>a$(!1))},[a9]),bb=(0,e.useCallback)(async()=>{try{let a=p?`${(0,g.e)()}/api/agent/config/export?sessionId=${p}`:`${(0,g.e)()}/api/agent/config/export`,b=await fetch(a);if(!b.ok)throw Error("Failed to fetch configuration");let c=await b.text(),d=new Blob([c],{type:"application/x-yaml"}),e=URL.createObjectURL(d),f=document.createElement("a");f.href=e,f.download=p?`${ab}-${p}.yml`:`${ab}.yml`,document.body.appendChild(f),f.click(),document.body.removeChild(f),URL.revokeObjectURL(e)}catch(a){console.error("Download failed:",a),ae(a instanceof Error?a.message:"Download failed")}},[ab,p]),bc=(0,e.useCallback)(async()=>{try{await navigator.clipboard.writeText(af),ai(!0),setTimeout(()=>ai(!1),2e3)}catch(a){console.error("Copy failed:",a),ae("Failed to copy to clipboard")}},[af]),bd=(0,e.useCallback)(async(a,b,c)=>{ao(!0),at(null);try{await n(a,b,c),setTimeout(()=>{ba(),a0(!0)},0)}catch(a){console.error("Failed to send message:",a),at(a instanceof Error?a.message:"Failed to send message"),setTimeout(()=>at(null),5e3)}finally{ao(!1)}},[n,ba]),be=(0,e.useCallback)(a=>{a0(!1),a2(!1),b.push(`/chat/${a}`)},[b]),bf=(0,e.useCallback)(()=>{a0(!1),a2(!1),t(),b.push("/")},[b,t]),bg=(0,e.useCallback)(async a=>{let b=bL(a),c="stdio"===b.type&&Object.keys(b.env||{}).length>0&&bK(b.env||{}),d=("sse"===b.type||"http"===b.type)&&"headers"in b&&Object.keys(b.headers||{}).length>0&&bK(b.headers||{});if(c||d)return a6({name:a.name,config:b,lockName:!0,registryEntryId:a.id,onCloseRegistryModal:a.onCloseRegistryModal??(()=>L(!1))}),H(!0),"requires-input";try{a8(!0);let c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,config:b,persistToAgent:!1})}),d=await c.json();if(!c.ok)throw Error(d.error||`Server returned status ${c.status}`);if(a.id)try{await br.setInstalled(a.id,!0)}catch(a){console.warn("Failed to mark registry entry installed:",a)}return a4(a=>a+1),ak(`Added ${a.name}`),setTimeout(()=>ak(null),4e3),L(!1),"connected"}catch(a){throw Error(a instanceof Error?a.message:"Failed to install server")}finally{a8(!1)}},[L,H,a6,a4,ak,a8]),bi=(0,e.useCallback)(()=>{P(!O)},[O,M]),bk=(0,e.useCallback)(()=>{N(!M)},[M,O]),bl=(0,e.useCallback)(async()=>{if(p){az(!0);try{if(!(await fetch(`${(0,g.e)()}/api/sessions/${p}`,{method:"DELETE"})).ok)throw Error("Failed to delete conversation");aw(!1),bf()}catch(a){console.error("Failed to delete conversation:",a),at(a instanceof Error?a.message:"Failed to delete conversation"),setTimeout(()=>at(null),5e3)}finally{az(!1)}}},[p,bf]),bm=f().useMemo(()=>[{title:"Help me get started",description:"Show me what you can do",action:()=>bd("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:()=>bd("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:()=>N(!0),icon:"\uD83D\uDD27"},{title:"Demonstrate tools",description:"Show me your capabilities",action:()=>bd("Pick one of your most interesting tools and demonstrate it with a practical example. Show me what it can do."),icon:"⚡"}],[bd,N]),bp=f().useMemo(()=>{if(!aL)return bm.map(a=>({description:`${a.icon} ${a.title}`,tooltip:a.description,action:a.action}));let a=aJ.length>0?[]:bm.map(a=>({description:`${a.icon} ${a.title}`,tooltip:a.description,action:a.action}));return aJ.forEach(b=>{let c=b.title||b.description||"Starter prompt",d=b.description;b?.name==="starter:connect-tools"?a.push({description:c,tooltip:d,action:()=>N(!0)}):a.push({description:c,tooltip:d,action:async()=>{try{let a=new URL(`${(0,g.e)()}/api/prompts/${encodeURIComponent(b.name)}/resolve`),c=await fetch(a.toString());if(c.ok){let a=await c.json(),d="string"==typeof a?.text?a.text:"";d.trim()?bd(d.trim()):bd(`/${b.name}`)}else bd(`/${b.name}`)}catch(a){console.error(`Failed to resolve starter prompt ${b.name}:`,a),bd(`/${b.name}`)}}})}),a},[aJ,aL,bm,bd,N]);return(0,d.jsxs)("div",{className:"flex w-full bg-background",style:{height:"var(--app-viewport-height, 100vh)",minHeight:"var(--app-viewport-height, 100vh)"},children:[(0,d.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 border-r border-border/50 bg-card/50 backdrop-blur-sm",!S.current&&"transition-all duration-300 ease-in-out",O?"w-80":"w-0 overflow-hidden"),suppressHydrationWarning:!0,children:O&&(0,d.jsx)(bR,{isOpen:O,onClose:()=>P(!1),currentSessionId:p,onSessionChange:be,returnToWelcome:bf,variant:"inline",onSearchOpen:()=>U(!0),onNewChat:bf})}),(0,d.jsx)("div",{className:"md:hidden",children:(0,d.jsx)(bR,{isOpen:O,onClose:()=>P(!1),currentSessionId:p,onSessionChange:be,returnToWelcome:bf,variant:"overlay",onSearchOpen:()=>U(!0),onNewChat:bf})}),(0,d.jsxs)("main",{className:"flex-1 flex flex-col relative min-w-0",style:{"--thread-max-width":"54rem"},children:[null,(0,d.jsxs)("header",{className:"shrink-0 border-b border-border/50 bg-background/95 backdrop-blur-xl shadow-sm relative",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 gap-3",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:bi,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",O&&"bg-muted"),children:(0,d.jsx)(cM.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Chat History (⌘H)"})]}),!O&&(0,d.jsx)("div",{className:"hidden md:block",children:(0,d.jsx)(bQ,{onClick:bf})}),(0,d.jsxs)("a",{href:"https://dexto.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center hover:opacity-80 transition-opacity shrink-0",children:[(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-9 w-9 md:hidden"}),(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-11 w-auto hidden md:block dark:md:hidden"}),(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-11 w-auto hidden dark:md:block"}),(0,d.jsx)("span",{className:"sr-only",children:"Dexto"})]})]}),(0,d.jsxs)("div",{className:"hidden md:flex items-center gap-2",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>$(!Z),className:(0,j.cn)("h-8 w-8 p-0",Z&&"bg-muted"),"aria-label":"Customize agent",children:(0,d.jsx)(cN.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Customize Agent (⌘E)"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:bk,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",M&&"bg-muted"),"aria-label":"Toggle tools panel",children:(0,d.jsx)(J.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Toggle tools panel (⌘J)"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>aa(!_),className:(0,j.cn)("h-8 w-8 p-0 transition-colors",_&&"bg-muted"),"aria-label":"Toggle memories panel",children:(0,d.jsx)(K.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Toggle memories panel (⌘M)"})]}),(0,d.jsx)(cU,{}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>Y(!0),className:"h-8 w-8 p-0","aria-label":"Open settings",children:(0,d.jsx)(bW.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Settings"})]}),(0,d.jsxs)(aD,{children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:(0,d.jsx)(cO.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsxs)(aF,{align:"end",children:[(0,d.jsxs)(aG,{onClick:()=>L(!0),children:[(0,d.jsx)(bw.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,d.jsxs)(aG,{onClick:()=>window.open("/playground","_blank"),children:[(0,d.jsx)(aY.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,d.jsxs)(aG,{onClick:()=>W(!0),children:[(0,d.jsx)(cP.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,d.jsxs)(aG,{onClick:()=>ar(!0),children:[(0,d.jsx)(cQ.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),p&&!s&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>aw(!0),className:"text-destructive focus:text-destructive",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})]}),(0,d.jsx)("div",{className:"flex md:hidden",children:(0,d.jsxs)(aD,{open:al,onOpenChange:am,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Open menu",children:(0,d.jsx)(cR.A,{className:"h-4 w-4"})})}),(0,d.jsxs)(aF,{align:"end",children:[(0,d.jsxs)(aG,{onClick:()=>{$(!Z),am(!1)},children:[(0,d.jsx)(cN.A,{className:"h-4 w-4 mr-2"}),"Customize Agent"]}),(0,d.jsxs)(aG,{onClick:()=>{bk(),am(!1)},children:[(0,d.jsx)(J.A,{className:"h-4 w-4 mr-2"}),"Tools"]}),(0,d.jsxs)(aG,{onClick:()=>{aa(!_),am(!1)},children:[(0,d.jsx)(K.A,{className:"h-4 w-4 mr-2"}),"Memories"]}),(0,d.jsxs)(aG,{onClick:()=>{let a=document.documentElement.classList.contains("dark")?"light":"dark";document.documentElement.classList.toggle("dark","dark"===a),localStorage.setItem("theme",a),document.cookie=`theme=${a}; Path=/; Max-Age=31536000; SameSite=Lax`,am(!1)},children:[(0,d.jsx)("span",{className:"h-4 w-4 mr-2",children:"\uD83C\uDF19"}),"Toggle Theme"]}),(0,d.jsxs)(aG,{onClick:()=>{Y(!0),am(!1)},children:[(0,d.jsx)(bW.A,{className:"h-4 w-4 mr-2"}),"Settings"]}),(0,d.jsxs)(aG,{onClick:a=>{a.preventDefault(),F(!E)},className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(av.A,{className:"h-4 w-4 mr-2"}),"Streaming"]}),(0,d.jsx)(ax,{checked:E,onCheckedChange:F,onClick:a=>a.stopPropagation()})]}),(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>{L(!0),am(!1)},children:[(0,d.jsx)(bw.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,d.jsxs)(aG,{onClick:()=>{window.open("/playground","_blank"),am(!1)},children:[(0,d.jsx)(aY.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,d.jsxs)(aG,{onClick:()=>{W(!0),am(!1)},children:[(0,d.jsx)(cP.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,d.jsxs)(aG,{onClick:()=>{ar(!0),am(!1)},children:[(0,d.jsx)(cQ.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),p&&!s&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>{aw(!0),am(!1)},className:"text-destructive focus:text-destructive",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})})]}),(0,d.jsx)("div",{className:"absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2",children:(0,d.jsx)("div",{className:"w-full max-w-[180px] md:max-w-[260px]",children:(0,d.jsx)(c2,{mode:"badge"})})})]}),(0,d.jsxs)("div",{className:"flex-1 flex overflow-hidden min-w-0",children:[aj&&(0,d.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,d.jsx)(q.A,{className:"h-4 w-4 text-green-600"}),(0,d.jsx)("span",{className:"text-sm",children:aj})]}),as&&(0,d.jsx)("div",{className:"absolute top-4 right-4 z-50 bg-destructive text-destructive-foreground px-4 py-2 rounded-md shadow-lg",children:as}),(0,d.jsx)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:s?(0,d.jsx)("div",{className:"flex-1 flex flex-col justify-end sm:justify-center p-6 sm:-mt-20",children:(0,d.jsxs)("div",{className:"w-full max-w-full sm:max-w-[var(--thread-max-width)] mx-auto space-y-6 pb-safe",children:[(0,d.jsxs)("div",{className:"text-center space-y-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-12 w-auto"}),(0,d.jsx)("h2",{className:"text-2xl font-bold font-mono tracking-tight bg-gradient-to-r from-primary to-primary/70 bg-clip-text",children:D||"Welcome to Dexto"})]}),(0,d.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,d.jsx)("div",{className:"flex flex-wrap justify-center gap-2 max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:bp.map((a,b)=>{let c=(0,d.jsx)("button",{onClick:a.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,d.jsx)("span",{className:"font-medium text-sm text-primary group-hover:text-primary/80 transition-colors",children:a.description})},b);return a.tooltip?(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:c}),(0,d.jsx)(w,{children:a.tooltip})]},b):c})}),(0,d.jsx)("div",{className:"max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:(0,d.jsx)(bn,{onSend:bd,isSending:an,variant:"welcome"})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground space-y-1 text-center",children:(0,d.jsxs)("p",{children:["\uD83D\uDCA1 Try",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘K"})," for new chat,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘J"})," for tools,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘L"})," for playground,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:c?"⌘⌫":"Ctrl+⌫"})," to delete session,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘/"})," for shortcuts"]})})]})}):(0,d.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden min-w-0",children:(0,d.jsx)("div",{ref:aT,className:"h-full overflow-y-auto overflow-x-hidden overscroll-contain relative min-w-0",children:(0,d.jsxs)("div",{className:"min-h-full grid grid-cols-1 grid-rows-[1fr_auto] min-w-0",children:[(0,d.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,d.jsx)(ap,{messages:l,processing:B,activeError:z,onDismissError:A,outerRef:aU,pendingApproval:aA,onApprovalApprove:aC?.onApprove,onApprovalDeny:aC?.onDeny})}),(0,d.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:[a1&&(0,d.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 -top-3 z-20 pointer-events-none",children:(0,d.jsxs)("button",{onClick:()=>{a2(!1),a9("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,d.jsx)("span",{children:"Scroll to bottom"}),(0,d.jsx)(o.A,{className:"h-3.5 w-3.5"})]})}),(0,d.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,d.jsx)(bn,{onSend:bd,isSending:an,variant:"chat"})})]})]})})})}),(0,d.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 transition-all duration-300 ease-in-out border-l border-border/50 bg-card/50 backdrop-blur-sm",M?"w-80":"w-0 overflow-hidden"),children:M&&(0,d.jsx)(bN,{isOpen:M,onClose:()=>N(!1),onOpenConnectModal:()=>H(!0),onOpenConnectWithPrefill:a=>{a6(a),H(!0)},onServerConnected:a=>{a4(a=>a+1),ak(`Added ${a}`),setTimeout(()=>ak(null),4e3)},variant:"inline",refreshTrigger:a3})}),(0,d.jsx)("div",{className:"md:hidden",children:(0,d.jsx)(bN,{isOpen:M,onClose:()=>N(!1),onOpenConnectModal:()=>H(!0),onOpenConnectWithPrefill:a=>{a6(a),H(!0)},onServerConnected:a=>{a4(a=>a+1),ak(`Added ${a}`),setTimeout(()=>ak(null),4e3)},variant:"overlay",refreshTrigger:a3})})]}),(0,d.jsx)(cL,{isOpen:Z,onClose:()=>$(!1),variant:"overlay"}),(0,d.jsx)(bo.A,{isOpen:G,onClose:()=>{H(!1),a8(!1),a6(null)},onServerConnected:async()=>{if(a5?.registryEntryId)try{await br.setInstalled(a5.registryEntryId,!0)}catch(a){console.warn("Failed to mark registry entry installed:",a)}a4(a=>a+1);let a=a5?.name||"Server";ak(`Added ${a}`),setTimeout(()=>ak(null),4e3),a5?.onCloseRegistryModal?.(),a8(!1),a6(null)},initialName:a5?.name,initialConfig:a5?.config,lockName:a5?.lockName}),(0,d.jsx)(bC,{isOpen:I,onClose:()=>L(!1),onInstallServer:bg,onOpenConnectModal:()=>H(!0),refreshTrigger:a3,disableClose:a7}),(0,d.jsx)(aN.lG,{open:V,onOpenChange:W,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-2xl",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(cP.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{children:"Export Configuration"})]}),(0,d.jsxs)(aN.rr,{children:["Download your tool configuration for Claude Desktop or other MCP clients",p&&(0,d.jsxs)("span",{className:"block mt-1 text-sm text-muted-foreground",children:["Including session-specific settings for: ",(0,d.jsx)("span",{className:"font-mono",children:p})]})]})]}),(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"filename",children:"File name"}),(0,d.jsx)(aP.p,{id:"filename",value:ab,onChange:a=>ac(a.target.value),placeholder:"dexto-config",className:"font-mono"})]}),ad&&(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.XL,{children:"Export Error"}),(0,d.jsx)(aO.TN,{children:ad})]}),af&&(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{children:"Configuration Preview"}),(0,d.jsx)(bh.T,{value:af,readOnly:!0,className:"h-32 font-mono text-xs bg-muted/30"})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:bc,className:"flex items-center space-x-2",children:(0,d.jsx)("span",{children:ah?"Copied!":"Copy"})}),(0,d.jsxs)(x.$,{onClick:bb,className:"flex items-center space-x-2",children:[(0,d.jsx)(cP.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Download"})]})]})]})}),(0,d.jsx)(cX,{isOpen:X,onClose:()=>Y(!1)}),(0,d.jsx)(bU,{isOpen:_,onClose:()=>aa(!1),variant:"modal"}),(0,d.jsx)(aN.lG,{open:au,onOpenChange:aw,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Conversation"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",p&&(0,d.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,d.jsx)("span",{className:"font-mono",children:p})]})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>aw(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:bl,disabled:ay,className:"flex items-center space-x-2",children:[(0,d.jsx)(bj.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:ay?"Deleting...":"Delete Conversation"})]})]})]})}),(0,d.jsx)(aN.lG,{open:aq,onOpenChange:ar,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(cQ.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{children:"Keyboard Shortcuts"})]})}),(0,d.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:c?"⌘⌫":"Ctrl+⌫",desc:"Delete current session"},{key:"Esc",desc:"Close panels"}].map((a,b)=>(0,d.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,d.jsx)("span",{className:"text-sm text-muted-foreground",children:a.desc}),(0,d.jsx)(aX.E,{variant:"outline",className:"font-mono text-xs",children:a.key})]},b))}),(0,d.jsx)(aN.Es,{children:(0,d.jsx)(aN.HM,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",children:"Close"})})})]})})]}),(0,d.jsx)(bY,{isOpen:T,onClose:()=>U(!1),onNavigateToSession:(a,c)=>{b.push(`/chat/${a}`),U(!1)}}),(0,d.jsx)(bV,{websocket:y,onApprovalRequest:aB,onHandlersReady:aI})]})}},62973:(a,b,c)=>{Promise.resolve().then(c.bind(c,49977))},70253:(a,b,c)=>{"use strict";c.d(b,{default:()=>d});let d=(0,c(95364).registerClientReference)(function(){throw Error("Attempted to call the default export of \"/home/runner/work/dexto/dexto/packages/webui/components/ChatApp.tsx\" from the server, but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/home/runner/work/dexto/dexto/packages/webui/components/ChatApp.tsx","default")},76477:(a,b,c)=>{Promise.resolve().then(c.bind(c,70253))}};
12
+ `,children:g?(0,d.jsx)(cT.A,{className:"w-3.5 h-3.5 text-gray-700"}):(0,d.jsx)(cU.A,{className:"w-3.5 h-3.5 text-yellow-500"})})})}),(0,d.jsx)(w,{children:g?"Switch to light mode":"Switch to dark mode"})]})}):(0,d.jsx)("div",{className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full"})}var cW=c(74985);function cX({active:a=!1}){let{voices:b,selected:c,setSelected:f}=function(){let[a,b]=(0,e.useState)(E.getVoices()),[c,d]=(0,e.useState)(E.getPreferredVoiceName());return{voices:a,selected:c,setSelected:a=>{E.setPreferredVoice(a),d(E.getPreferredVoiceName())}}}(),[g,h]=(0,e.useState)(!1);return a?(0,d.jsxs)(cW.l6,{value:c??"auto",onValueChange:a=>{f("auto"===a?null:a)},children:[(0,d.jsx)(cW.bq,{className:"h-8 w-[12rem] text-xs",children:(0,d.jsx)(cW.yv,{placeholder:"Voice"})}),(0,d.jsxs)(cW.gC,{children:[(0,d.jsx)(cW.eb,{value:"auto",children:"Auto (best available)"}),g&&b.map(a=>(0,d.jsxs)(cW.eb,{value:a.name,children:[a.name," (",a.lang,")"]},`${a.name}-${a.lang}`))]})]}):null}function cY({isOpen:a,onClose:b}){return(0,d.jsx)(aN.lG,{open:a,onOpenChange:a=>!a&&b(),children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-lg",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Settings"}),(0,d.jsx)(aN.rr,{children:"Configure preferences for speech and more."})]}),(0,d.jsx)("div",{className:"space-y-6 py-2",children:(0,d.jsxs)("section",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{className:"text-xs uppercase text-muted-foreground",children:"Voice"}),(0,d.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,d.jsx)(cX,{active:a})]})})]})})}var cZ=c(26960),c$=c(71436);let c_={id:"",name:"",description:"",author:"",tags:""},c0={llm:{provider:"openai",model:"gpt-5",apiKey:""},systemPrompt:{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:""}]}};function c1({open:a,onOpenChange:b,onAgentCreated:c}){let[f,h]=(0,e.useState)(c_),[i,j]=(0,e.useState)(c0),[k,l]=(0,e.useState)({}),[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)({basic:!0,llm:!0,systemPrompt:!0}),s=a=>{r(b=>({...b,[a]:!b[a]}))},t=(a,b)=>{h(c=>({...c,[a]:b})),k[a]&&l(b=>{let c={...b};return delete c[a],c})},u=async()=>{if((()=>{let a={};f.id.trim()?/^[a-z0-9-]+$/.test(f.id)||(a.id="Agent ID must contain only lowercase letters, numbers, and hyphens"):a.id="Agent ID is required",f.name.trim()||(a.name="Agent name is required"),f.description.trim()||(a.description="Description is required"),i.llm?.provider||(a["llm.provider"]="Provider is required"),i.llm?.model?.trim()||(a["llm.model"]="Model is required");let b=i.systemPrompt;if(b&&"object"==typeof b&&"contributors"in b){let c=b.contributors;Array.isArray(c)&&(c.some(a=>!!("static"===a.type&&"string"==typeof a.content&&a.content.trim()))||(a.systemPrompt="At least one static contributor with content is required"))}else"string"!=typeof b||b.trim()||(a.systemPrompt="System prompt is required");return l(a),0===Object.keys(a).length})()){n(!0),p(null);try{let a="";if(i.systemPrompt&&"object"==typeof i.systemPrompt&&"contributors"in i.systemPrompt){let b=i.systemPrompt.contributors;if(Array.isArray(b)){let c=b.find(a=>"static"===a.type&&a.content);c&&"content"in c&&"string"==typeof c.content&&(a=c.content.trim())}}else"string"==typeof i.systemPrompt&&(a=i.systemPrompt.trim());a||(a="You are a helpful AI assistant.");let d=await fetch(`${(0,g.e)()}/api/agents/custom/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:f.id.trim(),name:f.name.trim(),description:f.description.trim(),author:f.author.trim()||void 0,tags:f.tags.split(",").map(a=>a.trim()).filter(Boolean),llm:{provider:i.llm?.provider,model:i.llm?.model?.trim(),...i.llm?.apiKey?.trim()&&{apiKey:i.llm.apiKey.trim()}},systemPrompt:a})});if(!d.ok){let a=await d.json().catch(()=>({error:"Failed to create agent"}));throw Error(a.message||a.error||`Creation failed: ${d.statusText}`)}let e=await d.json();h(c_),j(c0),l({}),b(!1),c&&e.id&&c(e.id)}catch(a){p(a instanceof Error?a.message:"An unexpected error occurred")}finally{n(!1)}}};return(0,d.jsx)(aN.lG,{open:a,onOpenChange:b,children:(0,d.jsxs)(aN.Cf,{className:"max-w-2xl max-h-[90vh] flex flex-col",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsx)(aN.L3,{children:"Create New Agent"}),(0,d.jsxs)(aN.rr,{children:["Create a custom agent with your own configuration.",(0,d.jsx)("br",{}),(0,d.jsx)("br",{}),"You can add more advanced configuration after creating the agent using the Edit Agent button."]})]}),o&&(0,d.jsxs)("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-3 flex items-start gap-2",children:[(0,d.jsx)(bd.A,{className:"h-4 w-4 text-destructive mt-0.5 flex-shrink-0"}),(0,d.jsx)("div",{className:"text-sm text-destructive",children:o})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4 pr-2",children:[(0,d.jsx)(b3,{title:"Basic Information",open:q.basic,onOpenChange:()=>s("basic"),children:(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-id",tooltip:"Unique identifier for this agent (lowercase, no spaces, hyphens only)",children:"Agent ID *"}),(0,d.jsx)(aP.p,{id:"agent-id",value:f.id,onChange:a=>t("id",a.target.value),placeholder:"my-custom-agent","aria-invalid":!!k.id}),k.id&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.id})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-name",tooltip:"Display name for this agent (shown in UI)",children:"Agent Name *"}),(0,d.jsx)(aP.p,{id:"agent-name",value:f.name,onChange:a=>t("name",a.target.value),placeholder:"My Custom Agent","aria-invalid":!!k.name}),k.name&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.name})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-description",tooltip:"Brief description of what this agent does",children:"Description *"}),(0,d.jsx)(aP.p,{id:"agent-description",value:f.description,onChange:a=>t("description",a.target.value),placeholder:"A custom agent for specific tasks","aria-invalid":!!k.description}),k.description&&(0,d.jsx)("p",{className:"text-xs text-destructive mt-1",children:k.description})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-author",tooltip:"Your name or organization",children:"Author"}),(0,d.jsx)(aP.p,{id:"agent-author",value:f.author,onChange:a=>t("author",a.target.value),placeholder:"Your Name"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(a9,{htmlFor:"agent-tags",tooltip:"Comma-separated tags for categorization",children:"Tags"}),(0,d.jsx)(aP.p,{id:"agent-tags",value:f.tags,onChange:a=>t("tags",a.target.value),placeholder:"coding, custom, specialized"})]})]})}),(0,d.jsx)(b8,{value:i.llm||{provider:"openai",model:"gpt-5",apiKey:""},onChange:a=>j(b=>({...b,llm:a})),errors:k,open:q.llm,onOpenChange:()=>s("llm"),errorCount:0,sectionErrors:[]}),(0,d.jsx)(ca,{value:"object"==typeof i.systemPrompt&&"contributors"in i.systemPrompt?{contributors:i.systemPrompt.contributors||[]}:{contributors:[]},onChange:a=>j(b=>({...b,systemPrompt:a})),errors:k,open:q.systemPrompt,onOpenChange:()=>s("systemPrompt"),errorCount:0,sectionErrors:[]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>{h(c_),j(c0),l({}),p(null),b(!1)},disabled:m,children:"Cancel"}),(0,d.jsxs)(x.$,{onClick:u,disabled:m,children:[m&&(0,d.jsx)(N.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Agent"]})]})]})})}let c2="dexto:recentAgents";function c3({mode:a="default"}){let b=(0,h.useRouter)(),{returnToWelcome:c,currentLLM:f,currentSessionId:j}=(0,i.v)(),k=(0,ba.st)(),l=(0,e.useRef)(k),[m,n]=(0,e.useState)([]),[p,r]=(0,e.useState)([]),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(null),[w,y]=(0,e.useState)([]),[z,A]=(0,e.useState)(!1),[B,C]=(0,e.useState)(!1),[D,E]=(0,e.useState)(!1),[F,G]=(0,e.useState)(!1),H=(0,e.useCallback)(()=>{try{let a=localStorage.getItem(c2);if(!a)return[];return JSON.parse(a).sort((a,b)=>b.lastUsed-a.lastUsed).slice(0,5)}catch(a){return console.error("Failed to load recent agents:",a),localStorage.removeItem(c2),[]}},[]),I=(0,e.useCallback)(a=>{try{let b=H().filter(b=>b.path!==a.path),c=[{...a,lastUsed:Date.now()},...b].slice(0,5);localStorage.setItem(c2,JSON.stringify(c)),y(c)}catch(a){console.error("Failed to save recent agent:",a)}},[H]),J=(0,e.useCallback)(async()=>{try{let a=await fetch(`${(0,g.e)()}/api/agents`);if(!a.ok)throw Error("Failed to fetch agents");let b=await a.json();n(b.installed||[]),r(b.available||[]),t(b.current.id);try{let a=await fetch(`${(0,g.e)()}/api/agent/path`);if(a.ok){let b=await a.json();v(b),b.path&&b.name&&I({id:b.name,name:b.name,path:b.path})}}catch(a){console.error("Failed to fetch agent path:",a)}return b}catch(a){return console.error(`AgentSelector load error: ${a}`),null}},[I]),K=(0,e.useCallback)(async a=>{try{C(!0);let d=m.find(b=>b.id===a);if(!d)throw console.error(`Agent not found in installed list: ${a}`),Error(`Agent '${a}' not found. Please refresh the agents list.`);let e=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!e.ok){let a=await e.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${e.status} ${e.statusText}`)}t(a),E(!1),await J(),l.current.trackAgentSwitched({fromAgentId:s,toAgentId:a,toAgentName:d.name,sessionId:j||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a,name:d.name}}))}catch{}c(),b.push("/")}catch(b){console.error(`Switch agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to switch agent";alert(`Failed to switch agent: ${a}`)}finally{C(!1)}},[c,m,J,b,s,j]),L=(0,e.useCallback)(async a=>{try{C(!0);let d=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a.id,path:a.path})});if(!d.ok){let a=await d.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${d.status} ${d.statusText}`)}t(a.id),E(!1),await J(),I(a),l.current.trackAgentSwitched({fromAgentId:s,toAgentId:a.id,toAgentName:a.name,sessionId:j||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a.id,name:a.name}}))}catch{}c(),b.push("/")}catch(b){console.error(`Switch agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to switch agent";alert(`Failed to switch agent: ${a}`)}finally{C(!1)}},[c,I,J,b,s,j]),M=(0,e.useCallback)(async a=>{try{C(!0);let b=await fetch(`${(0,g.e)()}/api/agents/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!b.ok){let a=await b.json().catch(()=>({}));throw Error(a.error||`Install failed: ${b.status}`)}let d=await J();if(!d)throw Error("Failed to reload agents list after installation");let e=d.installed.find(b=>b.id===a);if(!e)throw console.error(`Agent not found in fresh installed list: ${a}`),Error(`Agent '${a}' not found after installation. Please refresh.`);let f=await fetch(`${(0,g.e)()}/api/agents/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a})});if(!f.ok){let a=await f.json().catch(()=>({}));throw console.error(`Agent switch failed: ${JSON.stringify(a)}`),Error(a.error||a.message||`Switch failed: ${f.status} ${f.statusText}`)}t(a),E(!1),l.current.trackAgentSwitched({fromAgentId:s,toAgentId:a,toAgentName:e.name,sessionId:j||void 0});try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:a,name:e.name}}))}catch{}c()}catch(b){console.error(`Install agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to install agent";alert(`Failed to install agent: ${a}`)}finally{C(!1)}},[J,c,s,j]),N=(0,e.useCallback)(async(a,b)=>{if(b.stopPropagation(),confirm(`Are you sure you want to delete the custom agent "${a.name}"?`))try{C(!0);let b=await fetch(`${(0,g.e)()}/api/agents/uninstall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a.id})});if(!b.ok){let a=await b.json().catch(()=>({}));throw Error(a.error||`Delete failed: ${b.status}`)}let c=await J();c?.current.id===a.id&&t(null)}catch(b){console.error(`Delete agent failed: ${b instanceof Error?b.message:String(b)}`);let a=b instanceof Error?b.message:"Failed to delete agent";alert(`Failed to delete agent: ${a}`)}finally{C(!1)}},[s,J]),O=(0,e.useCallback)(async a=>{await new Promise(a=>setTimeout(a,1e3)),await J()},[J]),P=(0,e.useMemo)(()=>{if(!s)return"Choose Agent";let a=m.find(a=>a.id===s)||p.find(a=>a.id===s);return a?.name??s},[p,s,m]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aD,{open:D,onOpenChange:E,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"badge"===a?"outline":"default",size:"sm",className:(a=>{let b="transition-all duration-200 shadow-lg hover:shadow-xl font-semibold rounded-full";switch(a){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] ${b}`;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 ${b}`;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 ${b}`}})(a),disabled:B,children:(0,d.jsxs)("div",{className:"flex items-center justify-between w-full min-w-0",children:[(0,d.jsx)(aZ.A,{className:"w-4 h-4 mr-2 flex-shrink-0"}),(0,d.jsx)("span",{className:"flex-1 text-center truncate min-w-0 px-1",children:B?"Switching...":"title"===a?`Agent: ${P}`:P}),(0,d.jsx)(o.A,{className:"w-4 h-4 ml-2 flex-shrink-0"})]})})}),(0,d.jsxs)(aF,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[z&&(0,d.jsx)(aG,{disabled:!0,className:"text-center text-muted-foreground",children:"Loading agents..."}),!z&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aG,{onClick:()=>{G(!0),E(!1)},disabled:B,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,d.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,d.jsx)(aU.A,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),(0,d.jsx)("span",{className:"font-semibold text-purple-600 dark:text-purple-400",children:"New Agent"})]})}),u&&!m.some(a=>a.id===u.name)&&(0,d.jsxs)(d.Fragment,{children:[(0,d.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,d.jsx)(aG,{onClick:()=>L({id:u.name,name:u.name,path:u.path}),disabled:B||s===u.name,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:u.name}),s===u.name&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:"Loaded from file"})]})})}),(0,d.jsx)(aH,{})]}),w.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Recent"}),w.filter(a=>!m.some(b=>b.id===a.id)&&a.id!==u?.name&&!a.path.includes("/.dexto/")).slice(0,3).map(a=>(0,d.jsx)(aG,{onClick:()=>L(a),disabled:B||a.id===s,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===s&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",title:a.path,children:a.path})]})})},a.path)),(0,d.jsx)(aH,{})]}),m.filter(a=>"custom"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.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,d.jsx)(cZ.A,{className:"w-3 h-3"}),"Custom Agents"]}),m.filter(a=>"custom"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>K(a.id),disabled:B||a.id===s,className:"cursor-pointer py-3",children:(0,d.jsxs)("div",{className:"flex items-center justify-between w-full gap-2",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===s&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]}),(0,d.jsx)("button",{onClick:b=>N(a,b),disabled:B,className:"p-1 hover:bg-red-100 dark:hover:bg-red-900/30 rounded transition-colors",title:"Delete custom agent",children:(0,d.jsx)(bk.A,{className:"w-4 h-4 text-red-600 dark:text-red-400"})})]})},a.id))]}),m.filter(a=>"builtin"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[m.filter(a=>"custom"===a.type).length>0&&(0,d.jsx)(aH,{}),(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Installed"}),m.filter(a=>"builtin"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>K(a.id),disabled:B||a.id===s,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),a.id===s&&(0,d.jsx)(q.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]})})},a.id))]}),p.filter(a=>"builtin"===a.type).length>0&&(0,d.jsxs)(d.Fragment,{children:[m.length>0&&(0,d.jsx)(aH,{}),(0,d.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Available"}),p.filter(a=>"builtin"===a.type).map(a=>(0,d.jsx)(aG,{onClick:()=>M(a.id),disabled:B,className:"cursor-pointer py-3",children:(0,d.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"font-medium text-sm truncate",children:a.name}),(0,d.jsx)(c$.A,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description}),a.author&&(0,d.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",a.author]})]})})},a.id))]}),!z&&0===m.length&&0===p.length&&(0,d.jsx)(aG,{disabled:!0,className:"text-center text-muted-foreground",children:"No agents found"})]})]})]}),(0,d.jsx)(c1,{open:F,onOpenChange:G,onAgentCreated:O})]})}function c4({sessionId:a}={}){let b=(0,h.useRouter)(),[c,k]=(0,e.useState)(!1),{messages:l,sendMessage:n,currentSessionId:p,switchSession:r,isWelcomeState:s,returnToWelcome:t,websocket:y,activeError:z,clearError:A,processing:B,cancel:C,greeting:D,isStreaming:E,setStreaming:F}=(0,i.v)(),[G,H]=(0,e.useState)(!1),[I,L]=(0,e.useState)(!1),[M,N]=(0,e.useState)(!1),[O,P]=(0,e.useState)(!1),[Q,R]=(0,e.useState)(!1),S=f().useRef(!0),[T,U]=(0,e.useState)(!1),[V,W]=(0,e.useState)(!1),[X,Y]=(0,e.useState)(!1),[Z,$]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(!1),[ab,ac]=(0,e.useState)("dexto-config"),[ad,ae]=(0,e.useState)(null),[af,ag]=(0,e.useState)(""),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(null),[al,am]=(0,e.useState)(!1),[an,ao]=(0,e.useState)(!1),[aq,ar]=(0,e.useState)(!1),[as,at]=(0,e.useState)(null),[au,aw]=(0,e.useState)(!1),[ay,az]=(0,e.useState)(!1),[aA,aB]=(0,e.useState)(null),[aC,aI]=(0,e.useState)(null),[aJ,aK]=(0,e.useState)([]),[aL,aM]=(0,e.useState)(!1),[aR,aS]=(0,e.useState)(0),aT=f().useRef(null),aU=f().useRef(null),[aV,aW]=(0,e.useState)(!0),[aZ,a$]=(0,e.useState)(!1),[a_,a0]=(0,e.useState)(!1);f().useRef(0);let[a1,a2]=(0,e.useState)(!1);f().useRef(null);let[a3,a4]=(0,e.useState)(0),[a5,a6]=(0,e.useState)(null),[a7,a8]=(0,e.useState)(!1);(0,e.useCallback)(()=>{let a=aT.current;a&&aW(a.scrollHeight-a.scrollTop<=a.clientHeight+1)},[]);let a9=(0,e.useCallback)((a="auto")=>{let b=aT.current;b&&(a$(!0),b.scrollTo({top:b.scrollHeight,behavior:a}),requestAnimationFrame(()=>a$(!1)))},[]),ba=(0,e.useCallback)(()=>{let a=aT.current;if(!a)return;let b=a.querySelectorAll('[data-role="user"]'),c=b[b.length-1];if(!c)return void a9("auto");let d=a.getBoundingClientRect(),e=Math.max(c.getBoundingClientRect().top-d.top+a.scrollTop-16,0);a$(!0),a.scrollTo({top:e,behavior:"auto"}),requestAnimationFrame(()=>a$(!1))},[a9]),bb=(0,e.useCallback)(async()=>{try{let a=p?`${(0,g.e)()}/api/agent/config/export?sessionId=${p}`:`${(0,g.e)()}/api/agent/config/export`,b=await fetch(a);if(!b.ok)throw Error("Failed to fetch configuration");let c=await b.text(),d=new Blob([c],{type:"application/x-yaml"}),e=URL.createObjectURL(d),f=document.createElement("a");f.href=e,f.download=p?`${ab}-${p}.yml`:`${ab}.yml`,document.body.appendChild(f),f.click(),document.body.removeChild(f),URL.revokeObjectURL(e)}catch(a){console.error("Download failed:",a),ae(a instanceof Error?a.message:"Download failed")}},[ab,p]),bc=(0,e.useCallback)(async()=>{try{await navigator.clipboard.writeText(af),ai(!0),setTimeout(()=>ai(!1),2e3)}catch(a){console.error("Copy failed:",a),ae("Failed to copy to clipboard")}},[af]),bd=(0,e.useCallback)(async(a,b,c)=>{ao(!0),at(null);try{await n(a,b,c),setTimeout(()=>{ba(),a0(!0)},0)}catch(a){console.error("Failed to send message:",a),at(a instanceof Error?a.message:"Failed to send message"),setTimeout(()=>at(null),5e3)}finally{ao(!1)}},[n,ba]),be=(0,e.useCallback)(a=>{a0(!1),a2(!1),b.push(`/chat/${a}`)},[b]),bf=(0,e.useCallback)(()=>{a0(!1),a2(!1),t(),b.push("/")},[b,t]),bg=(0,e.useCallback)(async a=>{let b=bM(a),c="stdio"===b.type&&Object.keys(b.env||{}).length>0&&bL(b.env||{}),d=("sse"===b.type||"http"===b.type)&&"headers"in b&&Object.keys(b.headers||{}).length>0&&bL(b.headers||{});if(c||d)return a6({name:a.name,config:b,lockName:!0,registryEntryId:a.id,onCloseRegistryModal:a.onCloseRegistryModal??(()=>L(!1))}),H(!0),"requires-input";try{a8(!0);let c=await fetch(`${(0,g.e)()}/api/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,config:b,persistToAgent:!1})}),d=await c.json();if(!c.ok)throw Error(d.error||`Server returned status ${c.status}`);if(a.id)try{await bs.setInstalled(a.id,!0)}catch(a){console.warn("Failed to mark registry entry installed:",a)}return a4(a=>a+1),ak(`Added ${a.name}`),setTimeout(()=>ak(null),4e3),L(!1),"connected"}catch(a){throw Error(a instanceof Error?a.message:"Failed to install server")}finally{a8(!1)}},[L,H,a6,a4,ak,a8]),bh=(0,e.useCallback)(()=>{P(!O)},[O,M]),bj=(0,e.useCallback)(()=>{N(!M)},[M,O]),bl=(0,e.useCallback)(async()=>{if(p){az(!0);try{if(!(await fetch(`${(0,g.e)()}/api/sessions/${p}`,{method:"DELETE"})).ok)throw Error("Failed to delete conversation");aw(!1),bf()}catch(a){console.error("Failed to delete conversation:",a),at(a instanceof Error?a.message:"Failed to delete conversation"),setTimeout(()=>at(null),5e3)}finally{az(!1)}}},[p,bf]),bm=f().useMemo(()=>[{title:"Help me get started",description:"Show me what you can do",action:()=>bd("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:()=>bd("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:()=>N(!0),icon:"\uD83D\uDD27"},{title:"Demonstrate tools",description:"Show me your capabilities",action:()=>bd("Pick one of your most interesting tools and demonstrate it with a practical example. Show me what it can do."),icon:"⚡"}],[bd,N]),bn=f().useMemo(()=>{if(!aL)return bm.map(a=>({description:`${a.icon} ${a.title}`,tooltip:a.description,action:a.action}));let a=aJ.length>0?[]:bm.map(a=>({description:`${a.icon} ${a.title}`,tooltip:a.description,action:a.action}));return aJ.forEach(b=>{let c=b.title||b.description||"Starter prompt",d=b.description;b?.name==="starter:connect-tools"?a.push({description:c,tooltip:d,action:()=>N(!0)}):a.push({description:c,tooltip:d,action:async()=>{try{let a=new URL(`${(0,g.e)()}/api/prompts/${encodeURIComponent(b.name)}/resolve`),c=await fetch(a.toString());if(c.ok){let a=await c.json(),d="string"==typeof a?.text?a.text:"";d.trim()?bd(d.trim()):bd(`/${b.name}`)}else bd(`/${b.name}`)}catch(a){console.error(`Failed to resolve starter prompt ${b.name}:`,a),bd(`/${b.name}`)}}})}),a},[aJ,aL,bm,bd,N]);return(0,d.jsxs)("div",{className:"flex w-full bg-background",style:{height:"var(--app-viewport-height, 100vh)",minHeight:"var(--app-viewport-height, 100vh)"},children:[(0,d.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 border-r border-border/50 bg-card/50 backdrop-blur-sm",!S.current&&"transition-all duration-300 ease-in-out",O?"w-80":"w-0 overflow-hidden"),suppressHydrationWarning:!0,children:O&&(0,d.jsx)(bS,{isOpen:O,onClose:()=>P(!1),currentSessionId:p,onSessionChange:be,returnToWelcome:bf,variant:"inline",onSearchOpen:()=>U(!0),onNewChat:bf})}),(0,d.jsx)("div",{className:"md:hidden",children:(0,d.jsx)(bS,{isOpen:O,onClose:()=>P(!1),currentSessionId:p,onSessionChange:be,returnToWelcome:bf,variant:"overlay",onSearchOpen:()=>U(!0),onNewChat:bf})}),(0,d.jsxs)("main",{className:"flex-1 flex flex-col relative min-w-0",style:{"--thread-max-width":"54rem"},children:[null,(0,d.jsxs)("header",{className:"shrink-0 border-b border-border/50 bg-background/95 backdrop-blur-xl shadow-sm relative",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 gap-3",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:bh,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",O&&"bg-muted"),children:(0,d.jsx)(cN.A,{className:"h-4 w-4"})})}),(0,d.jsx)(w,{children:"Chat History (⌘H)"})]}),!O&&(0,d.jsx)("div",{className:"hidden md:block",children:(0,d.jsx)(bR,{onClick:bf})}),(0,d.jsxs)("a",{href:"https://dexto.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center hover:opacity-80 transition-opacity shrink-0",children:[(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-9 w-9 md:hidden"}),(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-11 w-auto hidden md:block dark:md:hidden"}),(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-11 w-auto hidden dark:md:block"}),(0,d.jsx)("span",{className:"sr-only",children:"Dexto"})]})]}),(0,d.jsxs)("div",{className:"hidden md:flex items-center gap-2",children:[(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>$(!Z),className:(0,j.cn)("h-8 w-8 p-0",Z&&"bg-muted"),"aria-label":"Customize agent",children:(0,d.jsx)(cO.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Customize Agent (⌘E)"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:bj,className:(0,j.cn)("h-8 w-8 p-0 transition-colors",M&&"bg-muted"),"aria-label":"Toggle tools panel",children:(0,d.jsx)(J.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Toggle tools panel (⌘J)"})]}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>aa(!_),className:(0,j.cn)("h-8 w-8 p-0 transition-colors",_&&"bg-muted"),"aria-label":"Toggle memories panel",children:(0,d.jsx)(K.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Toggle memories panel (⌘M)"})]}),(0,d.jsx)(cV,{}),(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",onClick:()=>Y(!0),className:"h-8 w-8 p-0","aria-label":"Open settings",children:(0,d.jsx)(bX.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsx)(w,{children:"Settings"})]}),(0,d.jsxs)(aD,{children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:(0,d.jsx)(cP.A,{className:"h-3.5 w-3.5"})})}),(0,d.jsxs)(aF,{align:"end",children:[(0,d.jsxs)(aG,{onClick:()=>L(!0),children:[(0,d.jsx)(bx.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,d.jsxs)(aG,{onClick:()=>window.open("/playground","_blank"),children:[(0,d.jsx)(aY.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,d.jsxs)(aG,{onClick:()=>W(!0),children:[(0,d.jsx)(cQ.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,d.jsxs)(aG,{onClick:()=>ar(!0),children:[(0,d.jsx)(cR.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),p&&!s&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>aw(!0),className:"text-destructive focus:text-destructive",children:[(0,d.jsx)(bk.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})]}),(0,d.jsx)("div",{className:"flex md:hidden",children:(0,d.jsxs)(aD,{open:al,onOpenChange:am,children:[(0,d.jsx)(aE,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Open menu",children:(0,d.jsx)(cS.A,{className:"h-4 w-4"})})}),(0,d.jsxs)(aF,{align:"end",children:[(0,d.jsxs)(aG,{onClick:()=>{$(!Z),am(!1)},children:[(0,d.jsx)(cO.A,{className:"h-4 w-4 mr-2"}),"Customize Agent"]}),(0,d.jsxs)(aG,{onClick:()=>{bj(),am(!1)},children:[(0,d.jsx)(J.A,{className:"h-4 w-4 mr-2"}),"Tools"]}),(0,d.jsxs)(aG,{onClick:()=>{aa(!_),am(!1)},children:[(0,d.jsx)(K.A,{className:"h-4 w-4 mr-2"}),"Memories"]}),(0,d.jsxs)(aG,{onClick:()=>{let a=document.documentElement.classList.contains("dark")?"light":"dark";document.documentElement.classList.toggle("dark","dark"===a),localStorage.setItem("theme",a),document.cookie=`theme=${a}; Path=/; Max-Age=31536000; SameSite=Lax`,am(!1)},children:[(0,d.jsx)("span",{className:"h-4 w-4 mr-2",children:"\uD83C\uDF19"}),"Toggle Theme"]}),(0,d.jsxs)(aG,{onClick:()=>{Y(!0),am(!1)},children:[(0,d.jsx)(bX.A,{className:"h-4 w-4 mr-2"}),"Settings"]}),(0,d.jsxs)(aG,{onClick:a=>{a.preventDefault(),F(!E)},className:"flex items-center justify-between",children:[(0,d.jsxs)("div",{className:"flex items-center",children:[(0,d.jsx)(av.A,{className:"h-4 w-4 mr-2"}),"Streaming"]}),(0,d.jsx)(ax,{checked:E,onCheckedChange:F,onClick:a=>a.stopPropagation()})]}),(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>{L(!0),am(!1)},children:[(0,d.jsx)(bx.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,d.jsxs)(aG,{onClick:()=>{window.open("/playground","_blank"),am(!1)},children:[(0,d.jsx)(aY.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,d.jsxs)(aG,{onClick:()=>{W(!0),am(!1)},children:[(0,d.jsx)(cQ.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,d.jsxs)(aG,{onClick:()=>{ar(!0),am(!1)},children:[(0,d.jsx)(cR.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),p&&!s&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aH,{}),(0,d.jsxs)(aG,{onClick:()=>{aw(!0),am(!1)},className:"text-destructive focus:text-destructive",children:[(0,d.jsx)(bk.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})})]}),(0,d.jsx)("div",{className:"absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2",children:(0,d.jsx)("div",{className:"w-full max-w-[180px] md:max-w-[260px]",children:(0,d.jsx)(c3,{mode:"badge"})})})]}),(0,d.jsxs)("div",{className:"flex-1 flex overflow-hidden min-w-0",children:[aj&&(0,d.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,d.jsx)(q.A,{className:"h-4 w-4 text-green-600"}),(0,d.jsx)("span",{className:"text-sm",children:aj})]}),as&&(0,d.jsx)("div",{className:"absolute top-4 right-4 z-50 bg-destructive text-destructive-foreground px-4 py-2 rounded-md shadow-lg",children:as}),(0,d.jsx)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:s?(0,d.jsx)("div",{className:"flex-1 flex flex-col justify-end sm:justify-center p-6 sm:-mt-20",children:(0,d.jsxs)("div",{className:"w-full max-w-full sm:max-w-[var(--thread-max-width)] mx-auto space-y-6 pb-safe",children:[(0,d.jsxs)("div",{className:"text-center space-y-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,d.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-12 w-auto"}),(0,d.jsx)("h2",{className:"text-2xl font-bold font-mono tracking-tight bg-gradient-to-r from-primary to-primary/70 bg-clip-text",children:D||"Welcome to Dexto"})]}),(0,d.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,d.jsx)("div",{className:"flex flex-wrap justify-center gap-2 max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:bn.map((a,b)=>{let c=(0,d.jsx)("button",{onClick:a.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,d.jsx)("span",{className:"font-medium text-sm text-primary group-hover:text-primary/80 transition-colors",children:a.description})},b);return a.tooltip?(0,d.jsxs)(u,{children:[(0,d.jsx)(v,{asChild:!0,children:c}),(0,d.jsx)(w,{children:a.tooltip})]},b):c})}),(0,d.jsx)("div",{className:"max-w-full sm:max-w-[var(--thread-max-width)] mx-auto",children:(0,d.jsx)(bo,{onSend:bd,isSending:an,variant:"welcome"})}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground space-y-1 text-center",children:(0,d.jsxs)("p",{children:["\uD83D\uDCA1 Try",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘K"})," for new chat,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘J"})," for tools,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘L"})," for playground,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:c?"⌘⌫":"Ctrl+⌫"})," to delete session,",(0,d.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘/"})," for shortcuts"]})})]})}):(0,d.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden min-w-0",children:(0,d.jsx)("div",{ref:aT,className:"h-full overflow-y-auto overflow-x-hidden overscroll-contain relative min-w-0",children:(0,d.jsxs)("div",{className:"min-h-full grid grid-cols-1 grid-rows-[1fr_auto] min-w-0",children:[(0,d.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,d.jsx)(ap,{messages:l,processing:B,activeError:z,onDismissError:A,outerRef:aU,pendingApproval:aA,onApprovalApprove:aC?.onApprove,onApprovalDeny:aC?.onDeny})}),(0,d.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:[a1&&(0,d.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 -top-3 z-20 pointer-events-none",children:(0,d.jsxs)("button",{onClick:()=>{a2(!1),a9("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,d.jsx)("span",{children:"Scroll to bottom"}),(0,d.jsx)(o.A,{className:"h-3.5 w-3.5"})]})}),(0,d.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,d.jsx)(bo,{onSend:bd,isSending:an,variant:"chat"})})]})]})})})}),(0,d.jsx)("div",{className:(0,j.cn)("hidden md:block shrink-0 transition-all duration-300 ease-in-out border-l border-border/50 bg-card/50 backdrop-blur-sm",M?"w-80":"w-0 overflow-hidden"),children:M&&(0,d.jsx)(bO,{isOpen:M,onClose:()=>N(!1),onOpenConnectModal:()=>H(!0),onOpenConnectWithPrefill:a=>{a6(a),H(!0)},onServerConnected:a=>{a4(a=>a+1),ak(`Added ${a}`),setTimeout(()=>ak(null),4e3)},variant:"inline",refreshTrigger:a3})}),(0,d.jsx)("div",{className:"md:hidden",children:(0,d.jsx)(bO,{isOpen:M,onClose:()=>N(!1),onOpenConnectModal:()=>H(!0),onOpenConnectWithPrefill:a=>{a6(a),H(!0)},onServerConnected:a=>{a4(a=>a+1),ak(`Added ${a}`),setTimeout(()=>ak(null),4e3)},variant:"overlay",refreshTrigger:a3})})]}),(0,d.jsx)(cM,{isOpen:Z,onClose:()=>$(!1),variant:"overlay"}),(0,d.jsx)(bp.A,{isOpen:G,onClose:()=>{H(!1),a8(!1),a6(null)},onServerConnected:async()=>{if(a5?.registryEntryId)try{await bs.setInstalled(a5.registryEntryId,!0)}catch(a){console.warn("Failed to mark registry entry installed:",a)}a4(a=>a+1);let a=a5?.name||"Server";ak(`Added ${a}`),setTimeout(()=>ak(null),4e3),a5?.onCloseRegistryModal?.(),a8(!1),a6(null)},initialName:a5?.name,initialConfig:a5?.config,lockName:a5?.lockName}),(0,d.jsx)(bD,{isOpen:I,onClose:()=>L(!1),onInstallServer:bg,onOpenConnectModal:()=>H(!0),refreshTrigger:a3,disableClose:a7}),(0,d.jsx)(aN.lG,{open:V,onOpenChange:W,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-2xl",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(cQ.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{children:"Export Configuration"})]}),(0,d.jsxs)(aN.rr,{children:["Download your tool configuration for Claude Desktop or other MCP clients",p&&(0,d.jsxs)("span",{className:"block mt-1 text-sm text-muted-foreground",children:["Including session-specific settings for: ",(0,d.jsx)("span",{className:"font-mono",children:p})]})]})]}),(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{htmlFor:"filename",children:"File name"}),(0,d.jsx)(aP.p,{id:"filename",value:ab,onChange:a=>ac(a.target.value),placeholder:"dexto-config",className:"font-mono"})]}),ad&&(0,d.jsxs)(aO.Fc,{variant:"destructive",children:[(0,d.jsx)(m.A,{className:"h-4 w-4"}),(0,d.jsx)(aO.XL,{children:"Export Error"}),(0,d.jsx)(aO.TN,{children:ad})]}),af&&(0,d.jsxs)("div",{className:"space-y-2",children:[(0,d.jsx)(aQ.J,{children:"Configuration Preview"}),(0,d.jsx)(bi.T,{value:af,readOnly:!0,className:"h-32 font-mono text-xs bg-muted/30"})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:bc,className:"flex items-center space-x-2",children:(0,d.jsx)("span",{children:ah?"Copied!":"Copy"})}),(0,d.jsxs)(x.$,{onClick:bb,className:"flex items-center space-x-2",children:[(0,d.jsx)(cQ.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:"Download"})]})]})]})}),(0,d.jsx)(cY,{isOpen:X,onClose:()=>Y(!1)}),(0,d.jsx)(bV,{isOpen:_,onClose:()=>aa(!1),variant:"modal"}),(0,d.jsx)(aN.lG,{open:au,onOpenChange:aw,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsxs)(aN.c7,{children:[(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-5 w-5 text-destructive"}),(0,d.jsx)("span",{children:"Delete Conversation"})]}),(0,d.jsxs)(aN.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",p&&(0,d.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,d.jsx)("span",{className:"font-mono",children:p})]})]})]}),(0,d.jsxs)(aN.Es,{children:[(0,d.jsx)(x.$,{variant:"outline",onClick:()=>aw(!1),children:"Cancel"}),(0,d.jsxs)(x.$,{variant:"destructive",onClick:bl,disabled:ay,className:"flex items-center space-x-2",children:[(0,d.jsx)(bk.A,{className:"h-4 w-4"}),(0,d.jsx)("span",{children:ay?"Deleting...":"Delete Conversation"})]})]})]})}),(0,d.jsx)(aN.lG,{open:aq,onOpenChange:ar,children:(0,d.jsxs)(aN.Cf,{className:"sm:max-w-md",children:[(0,d.jsx)(aN.c7,{children:(0,d.jsxs)(aN.L3,{className:"flex items-center space-x-2",children:[(0,d.jsx)(cR.A,{className:"h-5 w-5"}),(0,d.jsx)("span",{children:"Keyboard Shortcuts"})]})}),(0,d.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:c?"⌘⌫":"Ctrl+⌫",desc:"Delete current session"},{key:"Esc",desc:"Close panels"}].map((a,b)=>(0,d.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,d.jsx)("span",{className:"text-sm text-muted-foreground",children:a.desc}),(0,d.jsx)(aX.E,{variant:"outline",className:"font-mono text-xs",children:a.key})]},b))}),(0,d.jsx)(aN.Es,{children:(0,d.jsx)(aN.HM,{asChild:!0,children:(0,d.jsx)(x.$,{variant:"outline",children:"Close"})})})]})})]}),(0,d.jsx)(bZ,{isOpen:T,onClose:()=>U(!1),onNavigateToSession:(a,c)=>{b.push(`/chat/${a}`),U(!1)}}),(0,d.jsx)(bW,{websocket:y,onApprovalRequest:aB,onHandlersReady:aI})]})}},62973:(a,b,c)=>{Promise.resolve().then(c.bind(c,49977))},70253:(a,b,c)=>{"use strict";c.d(b,{default:()=>d});let d=(0,c(95364).registerClientReference)(function(){throw Error("Attempted to call the default export of \"/home/runner/work/dexto/dexto/packages/webui/components/ChatApp.tsx\" from the server, but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/home/runner/work/dexto/dexto/packages/webui/components/ChatApp.tsx","default")},76477:(a,b,c)=>{Promise.resolve().then(c.bind(c,70253))}};