dexto 1.1.11 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +220 -84
  2. package/dist/agents/agent-registry.json +9 -0
  3. package/dist/agents/agent-template.yml +1 -1
  4. package/dist/agents/coding-agent/README.md +188 -0
  5. package/dist/agents/coding-agent/coding-agent.yml +203 -0
  6. package/dist/agents/database-agent/database-agent.yml +41 -2
  7. package/dist/agents/default-agent.yml +37 -3
  8. package/dist/agents/github-agent/github-agent.yml +39 -0
  9. package/dist/agents/image-editor-agent/image-editor-agent.yml +6 -2
  10. package/dist/agents/music-agent/README.md +1 -1
  11. package/dist/agents/music-agent/music-agent.yml +33 -2
  12. package/dist/agents/nano-banana-agent/nano-banana-agent.yml +32 -1
  13. package/dist/agents/podcast-agent/README.md +1 -1
  14. package/dist/agents/podcast-agent/podcast-agent.yml +34 -3
  15. package/dist/agents/product-name-researcher/product-name-researcher.yml +34 -1
  16. package/dist/agents/sora-video-agent/README.md +122 -0
  17. package/dist/agents/sora-video-agent/sora-video-agent.yml +98 -0
  18. package/dist/agents/talk2pdf-agent/talk2pdf-agent.yml +14 -2
  19. package/dist/agents/triage-demo/README.md +6 -6
  20. package/dist/agents/triage-demo/billing-agent.yml +1 -1
  21. package/dist/agents/triage-demo/escalation-agent.yml +1 -1
  22. package/dist/agents/triage-demo/product-info-agent.yml +1 -1
  23. package/dist/agents/triage-demo/technical-support-agent.yml +1 -1
  24. package/dist/agents/triage-demo/triage-agent.yml +13 -1
  25. package/dist/analytics/wrapper.d.ts.map +1 -1
  26. package/dist/analytics/wrapper.js +5 -3
  27. package/dist/api/a2a.d.ts +2 -2
  28. package/dist/api/a2a.d.ts.map +1 -1
  29. package/dist/api/a2a.js +3 -2
  30. package/dist/api/mcp/mcp_handler.d.ts +3 -3
  31. package/dist/api/mcp/mcp_handler.d.ts.map +1 -1
  32. package/dist/api/mcp/mcp_handler.js +7 -4
  33. package/dist/api/memory/memory-handler.d.ts +4 -1
  34. package/dist/api/memory/memory-handler.d.ts.map +1 -1
  35. package/dist/api/memory/memory-handler.js +10 -2
  36. package/dist/api/middleware/errorHandler.d.ts.map +1 -1
  37. package/dist/api/middleware/errorHandler.js +2 -0
  38. package/dist/api/server.d.ts.map +1 -1
  39. package/dist/api/server.js +158 -42
  40. package/dist/api/websocket-subscriber.d.ts.map +1 -1
  41. package/dist/api/websocket-subscriber.js +6 -0
  42. package/dist/cli/commands/interactive-commands/model/model-commands.js +2 -2
  43. package/dist/cli/utils/options.js +2 -2
  44. package/dist/index.js +64 -18
  45. package/dist/webui/.next/standalone/.next/static/chunks/419-6d449dcb2b056299.js +1 -0
  46. package/dist/webui/.next/standalone/.next/static/chunks/614-3519f8a6051e0088.js +1 -0
  47. package/dist/webui/.next/standalone/.next/static/chunks/656-5a9f6405badf66a8.js +25 -0
  48. package/dist/webui/.next/standalone/.next/static/chunks/{711-76a7d2bf4d6f69e5.js → 765-755286dc586b1a51.js} +1 -1
  49. package/dist/webui/.next/standalone/.next/static/chunks/804-f40df92a3adffcc0.js +1 -0
  50. package/dist/webui/.next/standalone/.next/static/chunks/854-232126f3c77e6c0b.js +1 -0
  51. package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +1 -0
  52. package/dist/webui/.next/standalone/.next/static/chunks/app/page-d1f127a0cac96246.js +1 -0
  53. package/dist/webui/.next/standalone/.next/static/chunks/app/playground/page-6f8d2abe76e51dfc.js +1 -0
  54. package/dist/webui/.next/standalone/.next/static/chunks/main-7decd42f62688419.js +1 -0
  55. package/dist/webui/.next/standalone/.next/static/css/c3c26ec984df1deb.css +1 -0
  56. package/dist/webui/.next/standalone/.next/static/uqfH8SY_uhwdc0ZkpMwCO/_buildManifest.js +1 -0
  57. package/dist/webui/.next/standalone/package.json +1 -0
  58. package/dist/webui/.next/standalone/packages/webui/.next/BUILD_ID +1 -1
  59. package/dist/webui/.next/standalone/packages/webui/.next/app-build-manifest.json +18 -18
  60. package/dist/webui/.next/standalone/packages/webui/.next/build-manifest.json +4 -4
  61. package/dist/webui/.next/standalone/packages/webui/.next/prerender-manifest.json +3 -3
  62. package/dist/webui/.next/standalone/packages/webui/.next/required-server-files.json +1 -11
  63. package/dist/webui/.next/standalone/packages/webui/.next/routes-manifest.json +1 -7
  64. package/dist/webui/.next/standalone/packages/webui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  65. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js +1 -1
  66. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page.js.nft.json +1 -1
  67. package/dist/webui/.next/standalone/packages/webui/.next/server/app/chat/[sessionId]/page_client-reference-manifest.js +1 -1
  68. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js +1 -1
  69. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page.js.nft.json +1 -1
  70. package/dist/webui/.next/standalone/packages/webui/.next/server/app/page_client-reference-manifest.js +1 -1
  71. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js +4 -8
  72. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page.js.nft.json +1 -1
  73. package/dist/webui/.next/standalone/packages/webui/.next/server/app/playground/page_client-reference-manifest.js +1 -1
  74. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/1.js +5 -5
  75. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/102.js +25 -0
  76. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/383.js +1 -0
  77. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/43.js +1 -1
  78. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/985.js +5 -0
  79. package/dist/webui/.next/standalone/packages/webui/.next/server/middleware-build-manifest.js +1 -1
  80. package/dist/webui/.next/standalone/packages/webui/.next/server/pages/500.html +1 -1
  81. package/dist/webui/.next/standalone/packages/webui/.next/server/pages-manifest.json +1 -1
  82. package/dist/webui/.next/standalone/packages/webui/.next/server/server-reference-manifest.json +1 -1
  83. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-6d449dcb2b056299.js +1 -0
  84. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/614-3519f8a6051e0088.js +1 -0
  85. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/656-5a9f6405badf66a8.js +25 -0
  86. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/{711-76a7d2bf4d6f69e5.js → 765-755286dc586b1a51.js} +1 -1
  87. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/804-f40df92a3adffcc0.js +1 -0
  88. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-232126f3c77e6c0b.js +1 -0
  89. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +1 -0
  90. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +1 -0
  91. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/playground/page-6f8d2abe76e51dfc.js +1 -0
  92. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/main-7decd42f62688419.js +1 -0
  93. package/dist/webui/.next/standalone/packages/webui/.next/static/css/c3c26ec984df1deb.css +1 -0
  94. package/dist/webui/.next/standalone/packages/webui/.next/static/uqfH8SY_uhwdc0ZkpMwCO/_buildManifest.js +1 -0
  95. package/dist/webui/.next/standalone/packages/webui/package.json +5 -1
  96. package/dist/webui/.next/standalone/packages/webui/server.js +1 -1
  97. package/dist/webui/.next/static/chunks/419-6d449dcb2b056299.js +1 -0
  98. package/dist/webui/.next/static/chunks/614-3519f8a6051e0088.js +1 -0
  99. package/dist/webui/.next/static/chunks/656-5a9f6405badf66a8.js +25 -0
  100. package/dist/webui/.next/static/chunks/{711-76a7d2bf4d6f69e5.js → 765-755286dc586b1a51.js} +1 -1
  101. package/dist/webui/.next/static/chunks/804-f40df92a3adffcc0.js +1 -0
  102. package/dist/webui/.next/static/chunks/854-232126f3c77e6c0b.js +1 -0
  103. package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-a695b09e6bac5274.js +1 -0
  104. package/dist/webui/.next/static/chunks/app/page-d1f127a0cac96246.js +1 -0
  105. package/dist/webui/.next/static/chunks/app/playground/page-6f8d2abe76e51dfc.js +1 -0
  106. package/dist/webui/.next/static/chunks/main-7decd42f62688419.js +1 -0
  107. package/dist/webui/.next/static/css/c3c26ec984df1deb.css +1 -0
  108. package/dist/webui/.next/static/uqfH8SY_uhwdc0ZkpMwCO/_buildManifest.js +1 -0
  109. package/dist/webui/package.json +5 -1
  110. package/package.json +2 -2
  111. package/dist/webui/.next/standalone/.next/static/VoeDi3iuGmMdZu_kx-R2X/_buildManifest.js +0 -1
  112. package/dist/webui/.next/standalone/.next/static/chunks/419-5526a47c95a2fa60.js +0 -1
  113. package/dist/webui/.next/standalone/.next/static/chunks/429-838829c1391e496d.js +0 -25
  114. package/dist/webui/.next/standalone/.next/static/chunks/459-62011998b002cbf6.js +0 -1
  115. package/dist/webui/.next/standalone/.next/static/chunks/854-8cad9404fc78e0cc.js +0 -1
  116. package/dist/webui/.next/standalone/.next/static/chunks/935-07f9df196b13275e.js +0 -1
  117. package/dist/webui/.next/standalone/.next/static/chunks/app/chat/[sessionId]/page-b8acc47b0d8c5c0a.js +0 -1
  118. package/dist/webui/.next/standalone/.next/static/chunks/app/page-e117ae372850d25f.js +0 -1
  119. package/dist/webui/.next/standalone/.next/static/chunks/app/playground/page-09340fb6b3f4caa2.js +0 -1
  120. package/dist/webui/.next/standalone/.next/static/chunks/main-b65ece3506a2355c.js +0 -1
  121. package/dist/webui/.next/standalone/.next/static/css/21e6c142ca3cdc42.css +0 -1
  122. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/419.js +0 -25
  123. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/654.js +0 -1
  124. package/dist/webui/.next/standalone/packages/webui/.next/server/chunks/71.js +0 -5
  125. package/dist/webui/.next/standalone/packages/webui/.next/static/VoeDi3iuGmMdZu_kx-R2X/_buildManifest.js +0 -1
  126. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/419-5526a47c95a2fa60.js +0 -1
  127. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/429-838829c1391e496d.js +0 -25
  128. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/459-62011998b002cbf6.js +0 -1
  129. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/854-8cad9404fc78e0cc.js +0 -1
  130. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/935-07f9df196b13275e.js +0 -1
  131. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/chat/[sessionId]/page-b8acc47b0d8c5c0a.js +0 -1
  132. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/page-e117ae372850d25f.js +0 -1
  133. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/app/playground/page-09340fb6b3f4caa2.js +0 -1
  134. package/dist/webui/.next/standalone/packages/webui/.next/static/chunks/main-b65ece3506a2355c.js +0 -1
  135. package/dist/webui/.next/standalone/packages/webui/.next/static/css/21e6c142ca3cdc42.css +0 -1
  136. package/dist/webui/.next/static/VoeDi3iuGmMdZu_kx-R2X/_buildManifest.js +0 -1
  137. package/dist/webui/.next/static/chunks/419-5526a47c95a2fa60.js +0 -1
  138. package/dist/webui/.next/static/chunks/429-838829c1391e496d.js +0 -25
  139. package/dist/webui/.next/static/chunks/459-62011998b002cbf6.js +0 -1
  140. package/dist/webui/.next/static/chunks/854-8cad9404fc78e0cc.js +0 -1
  141. package/dist/webui/.next/static/chunks/935-07f9df196b13275e.js +0 -1
  142. package/dist/webui/.next/static/chunks/app/chat/[sessionId]/page-b8acc47b0d8c5c0a.js +0 -1
  143. package/dist/webui/.next/static/chunks/app/page-e117ae372850d25f.js +0 -1
  144. package/dist/webui/.next/static/chunks/app/playground/page-09340fb6b3f4caa2.js +0 -1
  145. package/dist/webui/.next/static/chunks/main-b65ece3506a2355c.js +0 -1
  146. package/dist/webui/.next/static/css/21e6c142ca3cdc42.css +0 -1
  147. /package/dist/webui/.next/standalone/.next/static/{VoeDi3iuGmMdZu_kx-R2X → uqfH8SY_uhwdc0ZkpMwCO}/_ssgManifest.js +0 -0
  148. /package/dist/webui/.next/standalone/packages/webui/.next/static/{VoeDi3iuGmMdZu_kx-R2X → uqfH8SY_uhwdc0ZkpMwCO}/_ssgManifest.js +0 -0
  149. /package/dist/webui/.next/static/{VoeDi3iuGmMdZu_kx-R2X → uqfH8SY_uhwdc0ZkpMwCO}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[419],{8992:(e,t,s)=>{"use strict";s.d(t,{default:()=>s0});var r,a=s(5801),n=s(5789),i=s(826),l=s(9854),o=s(6032),c=s(1236),d=s(9752),m=s(1295),u=s(7891),x=s(4590),h=s(1828),p=s(9198),f=s(8537),g=s(4398);function v(e){let{delayDuration:t=0,...s}=e;return(0,a.jsx)(g.Kq,{"data-slot":"tooltip-provider",delayDuration:t,...s})}function j(e){let{...t}=e;return(0,a.jsx)(v,{children:(0,a.jsx)(g.bL,{"data-slot":"tooltip",...t})})}function b(e){let{...t}=e;return(0,a.jsx)(g.l9,{"data-slot":"tooltip-trigger",...t})}function y(e){let{className:t,sideOffset:s=0,children:r,...n}=e;return(0,a.jsx)(g.ZL,{children:(0,a.jsxs)(g.UC,{"data-slot":"tooltip-content",sideOffset:s,className:(0,o.cn)("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",t),...n,children:[r,(0,a.jsx)(g.i3,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}var N=s(5315);let w=(0,n.forwardRef)((e,t)=>{let{children:s,tooltip:r,side:n="bottom",className:i,...l}=e;return(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)(N.$,{variant:"ghost",size:"icon",...l,className:(0,o.cn)("size-6 p-1",i),ref:t,children:[s,(0,a.jsx)("span",{className:"sr-only",children:r})]})}),(0,a.jsx)(y,{side:n,children:r})]})});function k(e){let{value:t,tooltip:s="Copy",copiedTooltip:r="Copied!",className:i,size:l=12}=e,[o,c]=(0,n.useState)(!1);return(0,a.jsx)(w,{tooltip:o?r:s,onClick:()=>{navigator.clipboard.writeText(t).then(()=>{c(!0),setTimeout(()=>c(!1),2e3)}).catch(()=>{})},className:i,children:o?(0,a.jsx)(p.A,{size:l}):(0,a.jsx)(f.A,{size:l})})}w.displayName="TooltipIconButton";var C=s(8559),S=s(7338);class A{get supported(){return"speechSynthesis"in window&&"SpeechSynthesisUtterance"in window}isSpeaking(){return this._speaking}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}subscribeVoices(e){return this.voiceSubscribers.add(e),()=>{this.voiceSubscribers.delete(e)}}notify(){for(let e of this.subscribers)try{e()}catch(e){}}stop(){if(this.supported){try{window.speechSynthesis.cancel()}catch(e){}this.utterance=null,this._speaking&&(this._speaking=!1,this.notify())}}speak(e,t){if(!this.supported||!e||!e.trim())return;this.stop();let s=new window.SpeechSynthesisUtterance(e);(null==t?void 0:t.rate)!=null&&(s.rate=t.rate),(null==t?void 0:t.pitch)!=null&&(s.pitch=t.pitch);let r=this.resolveVoice();if(r)try{s.voice=r,(null==t?void 0:t.lang)?s.lang=t.lang:r.lang&&(s.lang=r.lang)}catch(e){}else(null==t?void 0:t.lang)&&(s.lang=t.lang);s.onstart=()=>{this.utterance===s&&(this._speaking=!0,this.notify())};let a=()=>{this.utterance===s&&(this._speaking=!1,this.utterance=null,this.notify())};s.onend=a,s.onerror=a;try{this.utterance=s,window.speechSynthesis.speak(s),this._speaking||(this._speaking=!0,this.notify())}catch(e){a()}}getVoices(){return this.voices}setPreferredVoice(e){this.preferredVoiceName=e&&e.length?e:null;try{this.preferredVoiceName?window.localStorage.setItem("ttsVoiceName",this.preferredVoiceName):window.localStorage.removeItem("ttsVoiceName")}catch(e){}this.voiceSubscribers.forEach(e=>e())}getPreferredVoiceName(){return this.preferredVoiceName}resolveVoice(){if(!this.voices.length)return null;let e=this.preferredVoiceName?this.voices.find(e=>e.name===this.preferredVoiceName):null;if(e)return e;let t=this.voices.find(e=>{var t;return"google uk english female"===e.name.toLowerCase()||e.name.toLowerCase().includes("google uk english female")&&(null==(t=e.lang)?void 0:t.toLowerCase().startsWith("en-gb"))});if(t)return t;let s=e=>{var t;let s=e.name.toLowerCase(),r=(null!=(t=e.lang)?t:"").toLowerCase(),a=0;return("en"===r||r.startsWith("en-"))&&(a+=3),s.includes("google")&&(a+=5),(s.includes("microsoft")||s.includes("azure"))&&(a+=4),(s.includes("natural")||s.includes("neural")||s.includes("premium"))&&(a+=4),s.includes("siri")&&(a+=3),s.includes("female")&&(a+=1),a};return[...this.voices].sort((e,t)=>s(t)-s(e))[0]||this.voices[0]||null}constructor(){if(this._speaking=!1,this.subscribers=new Set,this.utterance=null,this.voices=[],this.voiceSubscribers=new Set,this.preferredVoiceName=null,this.supported){try{let e=window.localStorage.getItem("ttsVoiceName");this.preferredVoiceName=e&&e.length?e:null}catch(e){}let e=()=>{try{let e=window.speechSynthesis.getVoices()||[];(e.length!==this.voices.length||e.some((e,t)=>{var s;return e.name!==(null==(s=this.voices[t])?void 0:s.name)}))&&(this.voices=e,this.voiceSubscribers.forEach(e=>e()))}catch(e){}};e();try{window.speechSynthesis.addEventListener("voiceschanged",e)}catch(e){}}}}let E=globalThis,T=null!=(r=E.__speechController)?r:E.__speechController=new A;function I(e){let{value:t,tooltip:s="Speak",stopTooltip:r="Stop",className:i,rate:l=1,pitch:o=1,lang:c}=e,[d,m]=(0,n.useState)(!1),u=T.supported,x=(null!=t?t:"").trim().length>0;return(0,n.useEffect)(()=>(m(T.isSpeaking()),T.subscribe(()=>m(T.isSpeaking()))),[]),(0,a.jsx)(w,{tooltip:d?r:s,onClick:()=>{if(u&&x){if(d)return T.stop();T.speak(t,{rate:l,pitch:o,lang:c})}},className:i,disabled:!u||!x,children:d?(0,a.jsx)(C.A,{size:12}):(0,a.jsx)(S.A,{size:12})})}function O(e){var t;let{error:s,onDismiss:r}=e,[i,l]=(0,n.useState)(!1),o=null==(t=s.detailedIssues)?void 0:t[0],c=(null==o?void 0:o.context)&&"object"==typeof o.context&&"detailedIssues"in o.context?o.context.detailedIssues:[],d=c.length>0?"".concat(s.message,"\n\nDetails:\n").concat(c.map(e=>{let t=e.message;if(e.context){let s="string"==typeof e.context?e.context:JSON.stringify(e.context,null,2);t+="\nContext: ".concat(s)}return t}).join("\n\n")):s.message;return(0,a.jsx)("div",{className:"w-full rounded-lg p-4 mb-4 border shadow-sm bg-destructive/10 border-destructive/40",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(m.A,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"text-sm font-medium text-destructive",children:"Error"}),s.context&&(0,a.jsx)("span",{className:"text-xs bg-destructive/15 text-destructive px-2 py-0.5 rounded-full",children:s.context})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[c.length>0&&(0,a.jsx)("button",{onClick:()=>l(!i),className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:i?"Collapse":"Expand",children:i?(0,a.jsx)(u.A,{className:"h-4 w-4"}):(0,a.jsx)(x.A,{className:"h-4 w-4"})}),(0,a.jsx)(k,{value:d,tooltip:"Copy error",className:"p-1 hover:bg-destructive/15 rounded text-destructive",size:16}),(0,a.jsx)(I,{value:d,tooltip:"Read error",className:"p-1 hover:bg-destructive/15 rounded text-destructive"}),(0,a.jsx)("button",{onClick:r,className:"p-1 hover:bg-destructive/15 rounded text-destructive",title:"Dismiss",children:(0,a.jsx)(h.A,{className:"h-4 w-4"})})]})]}),(0,a.jsx)("div",{className:"mt-2 text-sm text-destructive",children:s.message}),i&&c.length>0&&(0,a.jsx)("div",{className:"mt-3",children:(0,a.jsx)("div",{className:"text-xs text-destructive bg-destructive/10 p-3 rounded border border-destructive/30 overflow-auto max-h-60",children:c.map((e,t)=>(0,a.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,a.jsx)("div",{className:"font-medium",children:e.message}),null!=e.context&&(0,a.jsx)("div",{className:"text-destructive/70 mt-1",children:"string"==typeof e.context?e.context:JSON.stringify(e.context,null,2)})]},t))})})]})]})})}var L=s(8667),R=s(8109),D=s(9597),F=s(732),P=s(5192),_=s(530),M=s(2913),z=s(8369),U=s(36),B=s(198),q=s(3801),W=s(2125),K=s(7564),$=s(2776),V=s(4439),Y=s(9196);function J(e,t){return RegExp("^data:".concat(t?"".concat(t,"/"):"[a-z0-9.+-]+/","[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$"),"i").test(e)}let G=(0,n.memo)(e=>{let{children:t}=e;return(0,a.jsx)("div",{className:"prose max-w-none dark:prose-invert [&>p]:my-5 [&>p]:leading-7 [&>p]:first:mt-0 [&>p]:last:mb-0 [&>h1]:mb-8 [&>h1]:text-4xl [&>h1]:font-extrabold [&>h1]:tracking-tight [&>h1]:last:mb-0 [&>h2]:mb-4 [&>h2]:mt-8 [&>h2]:text-3xl [&>h2]:font-semibold [&>h2]:tracking-tight [&>h2]:first:mt-0 [&>h2]:last:mb-0 [&>h3]:mb-4 [&>h3]:mt-6 [&>h3]:text-2xl [&>h3]:font-semibold [&>h3]:tracking-tight [&>h3]:first:mt-0 [&>h3]:last:mb-0 [&>h4]:mb-4 [&>h4]:mt-6 [&>h4]:text-xl [&>h4]:font-semibold [&>h4]:tracking-tight [&>h4]:first:mt-0 [&>h4]:last:mb-0 [&>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 [&>hr]:my-5 [&>hr]:border-b",children:(0,a.jsx)(V.oz,{remarkPlugins:[Y.A],skipHtml:!0,components:{a:e=>{let{href:t,children:s,...r}=e;return t&&null!==t.match(/\.(mp4|webm|mov|m4v|avi|mkv)(\?.*)?$/i)&&function(e,t){return!!(e.startsWith("blob:")||function(e){try{let t=new URL(e),s=t.hostname.toLowerCase();if("https:"!==t.protocol&&"http:"!==t.protocol||"localhost"===s||"::1"===s)return!1;let r=s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(r){let[,e,t,s,a]=r.map(Number);if(e>255||t>255||s>255||a>255||127===e||10===e||172===e&&t>=16&&t<=31||192===e&&168===t||169===e&&254===t||0===e&&0===t&&0===s&&0===a)return!1}if(s.includes(":")&&("::1"===s||"0:0:0:0:0:0:0:1"===s||s.startsWith("fc")||s.startsWith("fd")||s.startsWith("fe8")||s.startsWith("fe9")||s.startsWith("fea")||s.startsWith("feb")))return!1;return!0}catch(e){return!1}}(e))||!!e.startsWith("data:")&&(t?J(e,t):J(e))}(t,"video")?(0,a.jsx)("div",{className:"my-4",children:(0,a.jsxs)("video",{controls:!0,src:t,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:["Your browser does not support the video tag.",(0,a.jsx)("a",{href:t,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-words",children:s||"Open video"})]})}):(0,a.jsx)("a",{href:t,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-words",...r,children:s})},table:e=>{let{className:t,children:s,...r}=e;return(0,a.jsx)("div",{className:"my-4 overflow-x-auto -mx-1 px-1",children:(0,a.jsx)("table",{className:["w-full border-separate border-spacing-0",t].filter(Boolean).join(" "),...r,children:s})})},thead:e=>{let{className:t,...s}=e;return(0,a.jsx)("thead",{className:t,...s})},tr:e=>{let{className:t,...s}=e;return(0,a.jsx)("tr",{className:["m-0 border-b first:border-t","[&:last-child>td:first-child]:rounded-bl-lg [&:last-child>td:last-child]:rounded-br-lg",t].filter(Boolean).join(" "),...s})},th:e=>{let{className:t,...s}=e;return(0,a.jsx)("th",{className:["bg-muted text-left font-bold align-top","px-4 py-2 first:rounded-tl-lg last:rounded-tr-lg","[&[align=center]]:text-center [&[align=right]]:text-right",t].filter(Boolean).join(" "),...s})},td:e=>{let{className:t,...s}=e;return(0,a.jsx)("td",{className:["border-b border-l last:border-r text-left align-top","px-4 py-2 whitespace-normal break-words","[&[align=center]]:text-center [&[align=right]]:text-right",t].filter(Boolean).join(" "),...s})},code:e=>{let{className:t,children:s,...r}=e,[i,l]=(0,n.useState)(!1),o=String(null!=s?s:"").replace(/\n$/,"");return t?(0,a.jsxs)("div",{className:"relative group my-4",children:[(0,a.jsx)(w,{tooltip:i?"Copied!":"Copy code",onClick:()=>{navigator.clipboard.writeText(o).then(()=>{l(!0),setTimeout(()=>l(!1),2e3)}).catch(()=>{})},className:"absolute right-2 top-2 z-10 opacity-70 hover:opacity-100 transition-opacity bg-background/80 hover:bg-background",children:i?(0,a.jsx)(p.A,{size:14}):(0,a.jsx)(f.A,{size:14})}),(0,a.jsx)("pre",{className:"overflow-auto bg-muted p-3 rounded-lg text-sm",children:(0,a.jsx)("code",{className:t,children:o})})]}):(0,a.jsx)("code",{className:"text-xs px-1.5 py-0.5 bg-muted rounded font-mono",...r,children:s})}},children:t})})});function H(e){let t=(0,n.useMemo)(()=>{let t=new Set,s=[];for(let r of e){if(!r||"string"!=typeof r)continue;let e=r.trim();!e||t.has(e)||(t.add(e),s.push(e))}return s},[e.join("|")]),[s,r]=(0,n.useState)({}),a=(0,n.useRef)({}),i=(0,n.useRef)(new Set);return(0,n.useEffect)(()=>{a.current=s},[s]),(0,n.useEffect)(()=>{t.forEach(e=>{if(!e)return;let t=a.current[e];(!t||"error"===t.status)&&(i.current.has(e)||(i.current.add(e),r(t=>({...t,[e]:{status:"loading"}})),(async()=>{try{let t=await fetch("/api/resources/".concat(encodeURIComponent(e),"/content"));if(!t.ok)throw Error("HTTP ".concat(t.status));let s=await t.json(),a=null==s?void 0:s.content;if(!a)throw Error("No content returned for resource");let n=function(e,t){var s,r;let a=Array.isArray(null==t?void 0:t.contents)?t.contents:[],n=null!=(s=null==t?void 0:t._meta)?s:{},i=("string"==typeof n.originalName&&n.originalName.trim().length>0?n.originalName:void 0)||e,l=[];for(let e of a){if(!e||"object"!=typeof e)continue;if("string"==typeof e.text){l.push({kind:"text",text:e.text,mimeType:"string"==typeof e.mimeType?e.mimeType:void 0});continue}let t="string"==typeof e.blob?e.blob:void 0,s="string"==typeof e.data?e.data:void 0,a="string"==typeof e.mimeType?e.mimeType:void 0,n="string"==typeof e.filename?e.filename:void 0;if((t||s)&&a){let e=(r=null!=t?t:s,"data:".concat(a,";base64,").concat(r));a.startsWith("image/")?l.push({kind:"image",src:e,mimeType:a,alt:n||i}):a.startsWith("audio/")?l.push({kind:"audio",src:e,mimeType:a,filename:n||i}):a.startsWith("video/")?l.push({kind:"video",src:e,mimeType:a,filename:n||i}):l.push({kind:"file",src:e,mimeType:a,filename:n||i});continue}a&&a.startsWith("text/")&&"string"==typeof e.value&&l.push({kind:"text",text:e.value,mimeType:a})}return{uri:e,name:i,meta:n,items:l}}(e,a);r(t=>({...t,[e]:{status:"loaded",data:n}}))}catch(s){let t=s instanceof Error?s.message:String(s);r(s=>({...s,[e]:{status:"error",error:t}}))}finally{i.current.delete(e)}})()))})},[t]),s}let Q=null,Z=null,X=null;async function ee(){let e=await fetch("/api/resources");if(!e.ok){let t=await e.text().catch(()=>"");throw Error(t?"HTTP ".concat(e.status,": ").concat(t):"HTTP ".concat(e.status))}let t=await e.json();if(!t||!t.ok||!Array.isArray(t.resources))throw Error("Invalid response shape");return t.resources}async function et(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return(e&&(Q=null,Z=null),Q)?Q:(X||(X=ee().then(e=>(Q=e,Z=null,e)).catch(e=>{throw Z=e instanceof Error?e.message:String(e),e}).finally(()=>{X=null})),X)}function es(){let[e,t]=(0,n.useState)(()=>null!=Q?Q:[]),[s,r]=(0,n.useState)(()=>null===Q),[a,i]=(0,n.useState)(()=>Z);(0,n.useEffect)(()=>{let e=!1;return et().then(s=>{e||(t(s),i(null),r(!1))}).catch(t=>{e||(i(t instanceof Error?t.message:String(t)),r(!1))}),()=>{e=!0}},[]);let l=(0,n.useCallback)(async()=>{r(!0);try{let e=await et(!0);t(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);return(0,n.useEffect)(()=>{let e=e=>{console.log("\uD83D\uDCBE Resource cache invalidated:",(null==e?void 0:e.detail)||{}),l()},t=e=>{console.log("\uD83D\uDD01 Agent switched, refreshing resources:",(null==e?void 0:e.detail)||{}),Q=null,Z=null,X=null,l()};return window.addEventListener("dexto:resourceCacheInvalidated",e),window.addEventListener("dexto:agentSwitched",t),()=>{window.removeEventListener("dexto:resourceCacheInvalidated",e),window.removeEventListener("dexto:agentSwitched",t)}},[l]),{resources:e,loading:s,error:a,refresh:l}}var er=s(6284);function ea(e){if(!e.metadata||"object"!=typeof e.metadata)return null;let t=e.metadata;return t.schema&&t.prompt&&t.serverName?t:null}function en(e){let{approval:t,onApprove:s,onDeny:r}=e,[i,l]=(0,n.useState)({}),[o,c]=(0,n.useState)({}),[d,u]=(0,n.useState)(!1),x="elicitation"===t.type,h=(e,t)=>{l(s=>({...s,[e]:t})),o[e]&&c(t=>{let s={...t};return delete s[e],s})};return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,a.jsx)(m.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:x?"Information Request":"Approval Required"})]}),x?(()=>{let e=ea(t);return e?(0,a.jsxs)("div",{className:"space-y-4 min-w-0",children:[(0,a.jsxs)("div",{className:"bg-muted/50 p-3 rounded-md border border-border min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium mb-1 break-words",children:e.prompt}),(0,a.jsxs)("p",{className:"text-xs text-muted-foreground break-words",children:["From: ",e.serverName||"Dexto Agent"]})]}),(0,a.jsx)("div",{children:(()=>{let t=e.schema;if(!(null==t?void 0:t.properties)||"object"!=typeof t.properties)return(0,a.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid form schema"});let s=t.required||[],r=t.properties;return(0,a.jsx)("div",{className:"space-y-4",children:Object.entries(r).map(e=>{var t;let[r,n]=e,l=s.includes(r),c=n.type||"string",d=i[r],m=!!o[r];return"boolean"===c?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(er.S,{id:r,checked:!0===d,onCheckedChange:e=>h(r,!0===e)}),(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground ml-6",children:n.description})]},r):"number"===c||"integer"===c?(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsx)("input",{id:r,type:"number",step:"integer"===c?"1":"any",value:"number"==typeof d?d:"",onChange:e=>{let t=e.target.value;h(r,""===t?void 0:Number(t))},className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),placeholder:l?"Required":"Optional"}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r):n.enum&&Array.isArray(n.enum)?(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsxs)("select",{id:r,value:null!=d?String(d):"",onChange:e=>{var t;let s=e.target.value;if(""===s)return void h(r,void 0);let a=null==(t=n.enum)?void 0:t.find(e=>String(e)===s);h(r,null!=a?a:s)},className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),children:[(0,a.jsx)("option",{value:"",children:"Select an option..."}),null==(t=n.enum)?void 0:t.map(e=>(0,a.jsx)("option",{value:String(e),children:String(e)},String(e)))]}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r):(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:r,className:"text-sm font-medium block",children:[r,l&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),n.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n.description}),(0,a.jsx)("input",{id:r,type:"text",value:null!=d&&"object"!=typeof d?String(d):"",onChange:e=>h(r,e.target.value),className:"w-full px-3 py-2 border rounded-md text-sm bg-background ".concat(m?"border-red-500":"border-border"),placeholder:l?"Required":"Optional"}),m&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:o[r]})]},r)})})})()})]}):(0,a.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Invalid elicitation metadata"})})():"tool_confirmation"===t.type?(0,a.jsxs)("div",{className:"space-y-3 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(D.A,{className:"h-4 w-4 flex-shrink-0"}),(0,a.jsxs)("span",{className:"font-medium text-sm break-words min-w-0",children:["Tool: ",t.toolName]})]}),t.description&&(0,a.jsx)("p",{className:"text-sm break-words",children:t.description}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"font-medium text-sm block mb-2",children:"Arguments:"}),(0,a.jsx)("pre",{className:"bg-muted/50 p-3 rounded-md text-xs overflow-auto max-h-40 border border-border break-words whitespace-pre-wrap max-w-full",children:JSON.stringify(t.args,null,2)})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2 pt-2",children:[(0,a.jsx)(er.S,{id:"remember",checked:d,onCheckedChange:e=>u(!0===e)}),(0,a.jsx)("label",{htmlFor:"remember",className:"text-sm",children:"Remember this choice for this session"})]})]}):null,(0,a.jsxs)("div",{className:"flex gap-2 justify-end pt-3 border-t border-border",children:[(0,a.jsx)(N.$,{variant:"outline",onClick:r,size:"sm",children:x?"Decline":"Deny"}),(0,a.jsx)(N.$,{onClick:()=>{if(x){let e=ea(t);if(!e)return void console.error("Invalid elicitation metadata");let r=e.schema.required||[],a={};for(let e of r){let t=i[e],s="string"==typeof t&&""===t.trim();(null==t||s)&&(a[e]="This field is required")}if(Object.keys(a).length>0)return void c(a);s(i)}else s(void 0,d)},size:"sm",children:x?"Submit":"Approve"})]})]})}function ei(e,t){return RegExp("^data:".concat(t?"".concat(t,"/"):"[a-z0-9.+-]+/","[a-z0-9.+-]+;base64,[A-Za-z0-9+/]+={0,2}$"),"i").test(e)}function el(e,t){return!!(e.startsWith("blob:")||function(e){try{let t=new URL(e),s=t.hostname.toLowerCase();if("https:"!==t.protocol&&"http:"!==t.protocol||"localhost"===s||"::1"===s)return!1;let r=s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(r){let[,e,t,s,a]=r.map(Number);if(e>255||t>255||s>255||a>255||127===e||10===e||172===e&&t>=16&&t<=31||192===e&&168===t||169===e&&254===t||0===e&&0===t&&0===s&&0===a)return!1}if(s.includes(":")&&("::1"===s||"0:0:0:0:0:0:0:1"===s||s.startsWith("fc")||s.startsWith("fd")||s.startsWith("fe8")||s.startsWith("fe9")||s.startsWith("fea")||s.startsWith("feb")))return!1;return!0}catch(e){return!1}}(e))||!!e.startsWith("data:")&&(t?ei(e,t):ei(e))}function eo(e,t){var s,r,a,n,i,l,o,c,m,u,x,h,p,f,g,v,j;if(!e)return"";let b=null==e?void 0:e.mimeType,y="string"==typeof e?e:null!=(l=null!=(i=null!=(n=null!=(a=null!=(r=null!=(s=null==e?void 0:e.data)?s:null==e?void 0:e.base64)?r:null==e?void 0:e.image)?a:null==e?void 0:e.audio)?n:null==e?void 0:e.video)?i:null==e?void 0:e.uri)?l:null==e?void 0:e.url;if("string"==typeof y){if(y.startsWith("@blob:")){let s=y.substring(1);if(t&&s){let r=t[s];if(r&&"loaded"===r.status&&r.data){let t=[];if((null==e?void 0:e.type)==="image"&&t.push("image"),(null==e?void 0:e.type)==="file"){let s=(0,d.t)(e.mimeType);"audio"===s?t.push("audio"):"video"===s&&t.push("video")}(null==e||null==(o=e.mimeType)?void 0:o.startsWith("image/"))&&t.push("image"),(null==e||null==(c=e.mimeType)?void 0:c.startsWith("audio/"))&&t.push("audio"),(null==e||null==(m=e.mimeType)?void 0:m.startsWith("video/"))&&t.push("video");let s=null!=(p=null!=(h=null!=(x=null!=(u=r.data.items.find(e=>t.includes(e.kind)))?u:r.data.items.find(e=>"image"===e.kind))?x:r.data.items.find(e=>"video"===e.kind))?h:r.data.items.find(e=>"audio"===e.kind))?p:r.data.items[0];if(s&&"src"in s&&"string"==typeof s.src)return s.src}}return""}if(y.startsWith("data:"))return y;if(b&&!(!y||y.length<16||y.startsWith("http://")||y.startsWith("https://")||y.startsWith("data:")||y.startsWith("@blob:"))&&/^[A-Za-z0-9+/=\r\n]+$/.test(y))return"data:".concat(b,";base64,").concat(y);if(el(y))return y}let N=null!=(j=null!=(v=null!=(g=null!=(f=null==e?void 0:e.url)?f:null==e?void 0:e.image)?g:null==e?void 0:e.audio)?v:null==e?void 0:e.video)?j:null==e?void 0:e.uri;return"string"==typeof N?N:""}function ec(e,t){if(!e||"object"!=typeof e)return null;let s=e.mimeType||e.mediaType,r=e.filename||e.name,a="file"===e.type?(0,d.t)(e.mimeType):null;if(!((null==s?void 0:s.startsWith("video/"))||"video"===a||"video"===e.type||(null==r?void 0:r.match(/\.(mp4|webm|mov|m4v|avi|mkv)$/i))))return null;let n=eo(e,t);return n&&el(n,"video")?{src:n,filename:r,mimeType:s}:null}function ed(){return(0,a.jsx)("div",{className:"flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground",role:"status","aria-live":"polite",children:(0,a.jsxs)("span",{className:"flex items-center gap-1 uppercase tracking-wide text-muted-foreground/80",children:[(0,a.jsx)("span",{children:"Thinking"}),(0,a.jsx)("span",{className:"flex items-center gap-0.5",children:[0,1,2].map(e=>(0,a.jsx)("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-primary/60 animate-[pulse_1.2s_ease-in-out_infinite]",style:{animationDelay:"".concat(.18*e,"s")}},e))})]})})}function em(e){let{messages:t,activeError:s,onDismissError:r,outerRef:i,pendingApproval:l,onApprovalApprove:p,onApprovalDeny:f}=e,g=(0,n.useRef)(null),[v,N]=(0,n.useState)({}),[w,C]=(0,n.useState)({}),[A,E]=(0,n.useState)(null);(0,n.useRef)(null);let[T,$]=(0,n.useState)({isOpen:!1,src:"",alt:""}),{resources:V}=es(),Y=(0,n.useMemo)(()=>{let e={};for(let t of V)e[t.uri]={...t};return e},[V]),J=H((0,n.useMemo)(()=>{let e=new Set,s=t=>{if("string"!=typeof t)return;let s=t.startsWith("@")?t.substring(1):t;s.startsWith("blob:")&&e.add(s)},r=e=>{if(e){if("string"==typeof e)return void s(e);"object"==typeof e&&("string"==typeof e.image&&s(e.image),"string"==typeof e.data&&s(e.data),"string"==typeof e.url&&s(e.url),"string"==typeof e.audio&&s(e.audio),"string"==typeof e.video&&s(e.video))}};for(let s of t){let t=s.toolResult;if(t)if((0,c.P2)(t)){var a,n;null==(a=t.resources)||a.forEach(t=>{var s;(null==t||null==(s=t.uri)?void 0:s.startsWith("blob:"))&&e.add(t.uri)}),null==(n=t.content)||n.forEach(e=>r(e))}else(null==t?void 0:t.content)&&Array.isArray(t.content)&&t.content.forEach(e=>r(e))}return Array.from(e)},[t]));(0,n.useEffect)(()=>{let e=document.createElement("style");return e.textContent="\n .audio-controls-container audio {\n max-width: 100% !important;\n width: 100% !important;\n height: auto !important;\n min-height: 32px;\n }\n .audio-controls-container audio::-webkit-media-controls-panel {\n max-width: 100% !important;\n }\n .audio-controls-container audio::-webkit-media-controls-timeline {\n max-width: 100% !important;\n }\n ",document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let G=(e,t)=>{$({isOpen:!0,src:e,alt:t})};if(!t||0===t.length)return null;let Q=e=>"string"==typeof e.content?e.content:Array.isArray(e.content)?e.content.map(e=>(0,c.PI)(e)?e.text:"").filter(Boolean).join("\n"):e.content&&"object"==typeof e.content?JSON.stringify(e.content,null,2):"",Z=e=>e?(0,c.KU)(e)?"object"==typeof e.error?JSON.stringify(e.error,null,2):String(e.error):(0,c.P2)(e)?e.content.map(e=>(0,c.PI)(e)?e.text:"object"==typeof e?"":String(e)).filter(Boolean).join("\n"):"object"==typeof e?JSON.stringify(e,null,2):String(e):"";return(0,a.jsxs)("div",{id:"message-list-container",ref:i,className:"flex flex-col space-y-3 px-4 py-2",children:[t.map((e,n)=>{var i,l,h,p;let f=null!=(l=e.id)?l:"msg-".concat(n),g="user"===e.role,A="assistant"===e.role,E="system"===e.role,T=E&&"string"==typeof e.content&&e.content.trim().toLowerCase().startsWith("dexto is thinking"),$=n===t.length-1,V=!!(e.toolName&&e.toolArgs),H=!!(e.toolName&&e.toolResult),X=V||H,ee=X&&$||!!v[f],et=[],es=[],er=[];H&&e.toolResult&&(0,c.P2)(e.toolResult)&&e.toolResult.content.forEach((e,t)=>{var s;if((0,c.j0)(e)){let s=eo(e,J);s&&el(s,"image")&&et.push({src:s,alt:"Tool result image ".concat(t+1),index:t})}else if((0,c.kz)(e)){let s=eo(e,J);s&&el(s,"audio")&&es.push({src:s,filename:e.filename,index:t})}else if((0,c.EQ)(e)&&("audio"===(0,d.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))){let s=eo(e,J);s&&el(s,"audio")&&es.push({src:s,filename:e.filename,index:t})}else{let s=ec(e,J);s&&er.push({...s,index:t})}});let ea=g?L.A:R.A,en=(0,o.cn)(g?"grid w-full grid-cols-[1fr_auto] gap-x-2 items-start":"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start"),em=(0,o.cn)("tool"===e.role?"w-full text-muted-foreground/70 bg-secondary border border-muted/30 rounded-md text-base":g?"p-3 rounded-xl shadow-sm w-fit max-w-[75%] bg-primary text-primary-foreground rounded-br-none text-base break-normal hyphens-none":A?"p-3 rounded-xl shadow-sm w-fit max-w-[90%] bg-card text-card-foreground border border-border rounded-bl-none text-base break-normal hyphens-none":E?T?"p-1.5 shadow-none w-full bg-transparent text-xs text-muted-foreground text-center border-none":"p-3 shadow-none w-full bg-transparent text-xs text-muted-foreground italic text-center border-none":""),ex=new Date(e.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),eh=!!(s&&s.anchorMessageId===e.id);return(0,a.jsxs)("div",{className:"w-full","data-role":e.role,id:e.id?"message-".concat(e.id):void 0,children:[(0,a.jsxs)("div",{className:en,children:[A&&(0,a.jsx)(ea,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1"}),"tool"===e.role&&(0,a.jsx)(D.A,{className:"h-7 w-7 p-1 mt-1 rounded-full border border-border text-muted-foreground col-start-1"}),(0,a.jsxs)("div",{className:(0,o.cn)("flex flex-col group w-full",E?"col-span-2 items-center":g?"col-start-1 justify-self-end items-end":"col-start-2 justify-self-start items-start"),children:[(0,a.jsx)("div",{className:em,children:(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[A&&"string"==typeof e.reasoning&&e.reasoning.trim().length>0&&(0,a.jsxs)("div",{className:"mb-3 border border-orange-200/50 dark:border-orange-400/20 rounded-lg bg-gradient-to-br from-orange-50/30 to-amber-50/20 dark:from-orange-900/20 dark:to-amber-900/10",children:[(0,a.jsxs)("div",{className:"px-3 py-2 border-b border-orange-200/30 dark:border-orange-400/20 bg-orange-100/50 dark:bg-orange-900/30 rounded-t-lg flex items-center justify-between",children:[(0,a.jsxs)("button",{type:"button",className:"flex items-center gap-2 text-xs font-medium text-orange-700 dark:text-orange-300 hover:text-orange-800 dark:hover:text-orange-200 transition-colors group",onClick:()=>C(e=>{var t;return{...e,[f]:!(null==(t=e[f])||t)}}),children:[(0,a.jsx)(F.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:"AI Reasoning"}),null==(h=w[f])||h?(0,a.jsx)(u.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"}):(0,a.jsx)(x.A,{className:"h-3 w-3 group-hover:scale-110 transition-transform"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(k,{value:e.reasoning,tooltip:"Copy reasoning",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(I,{value:e.reasoning,tooltip:"Speak reasoning",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(null==(p=w[f])||p)&&(0,a.jsx)("div",{className:"px-3 py-2",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words text-xs text-orange-800/80 dark:text-orange-200/70 leading-relaxed font-mono",children:e.reasoning})})]}),e.toolName?(0,a.jsxs)("div",{className:"p-2 rounded border border-border bg-muted/30 hover:bg-muted/60 cursor-pointer w-full",onClick:()=>{X&&N(e=>({...e,[f]:!e[f]}))},children:[(0,a.jsxs)("div",{className:"flex items-center justify-between text-xs font-medium",children:[(0,a.jsxs)("span",{className:"flex items-center",children:[ee?(0,a.jsx)(u.A,{className:"h-4 w-4 mr-2 text-primary"}):(0,a.jsx)(P.A,{className:"h-4 w-4 mr-2 text-primary"}),"Tool: ",e.toolName]}),e.toolResult?(0,c.KU)(e.toolResult)?(0,a.jsx)(m.A,{className:"mx-2 h-4 w-4 text-red-500"}):(0,a.jsx)(_.A,{className:"mx-2 h-4 w-4 text-green-500"}):(0,a.jsx)(M.A,{className:"mx-2 h-4 w-4 animate-spin text-muted-foreground"})]}),ee&&(0,a.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-medium",children:"Arguments:"}),(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:JSON.stringify(e.toolArgs,null,2)})]}),e.toolResult&&(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"text-xs font-medium flex items-center justify-between",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("span",{children:"Result:"}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(k,{value:Z(e.toolResult),tooltip:"Copy result",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(I,{value:Z(e.toolResult),tooltip:"Speak result",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]}),(0,c.KU)(e.toolResult)?(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-red-100 text-red-700 p-2 rounded text-xs",children:"object"==typeof e.toolResult.error?JSON.stringify(e.toolResult.error,null,2):String(e.toolResult.error)}):(0,c.P2)(e.toolResult)?e.toolResult.content.map((e,t)=>{var s,r,n;let i=ec(e,J);if((0,c.j0)(e)||(0,c.kz)(e)||(0,c.EQ)(e)&&("audio"===(0,d.t)(e.mimeType)||(null==(s=e.mimeType)?void 0:s.startsWith("audio/")))||i)return null;if((0,c.PI)(e))return(0,a.jsx)(eu,{text:e.text,isUser:!1,onOpenImage:G,resourceSet:Y},"".concat(f,"-tool-text-").concat(t));if((0,c.EQ)(e)){let s=(0,d.t)(e.mimeType),i="audio"===s||(null==(r=e.mimeType)?void 0:r.startsWith("audio/")),l="video"===s||(null==(n=e.mimeType)?void 0:n.startsWith("video/"));return(0,a.jsxs)("div",{className:"my-1 flex items-center gap-2 p-2 rounded border border-border bg-muted/50",children:[i?(0,a.jsx)(z.A,{className:"h-4 w-4 text-muted-foreground"}):l?(0,a.jsx)(U.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(B.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:[e.filename||"File attachment"," (",e.mimeType,")"]})]},t)}return(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground my-1",children:"object"==typeof e?JSON.stringify(e,null,2):String(e)},t)}):(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:"string"==typeof e.toolResult&&e.toolResult.startsWith("data:image")?ei(e.toolResult,"image")?(0,a.jsx)("img",{src:e.toolResult,alt:"Tool result image",className:"my-1 max-h-48 w-auto rounded border border-border"}):"Invalid image data":"object"==typeof e.toolResult?JSON.stringify(e.toolResult,null,2):String(e.toolResult)})]})]})]}):(0,a.jsxs)(a.Fragment,{children:["string"==typeof e.content&&""!==e.content.trim()&&(0,a.jsx)("div",{className:"relative",children:T?(0,a.jsx)(ed,{}):(0,a.jsx)(eu,{text:e.content,isUser:g,onOpenImage:G,resourceSet:Y},"".concat(f,"-text-content"))}),e.content&&"object"==typeof e.content&&!Array.isArray(e.content)&&(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto bg-background/50 p-2 rounded text-xs text-muted-foreground",children:JSON.stringify(e.content,null,2)}),Array.isArray(e.content)&&e.content.map((e,t)=>{let s="".concat(f,"-part-").concat(t);if("text"===e.type)return(0,a.jsx)(eu,{text:e.text,isUser:g,onOpenImage:G,resourceSet:Y},s);if((0,c.j0)(e)){let t=eo(e);return t&&el(t,"image")?(0,a.jsx)("img",{src:t,alt:"Message attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain cursor-pointer",onClick:()=>G(t,"Message attachment")},s):null}let r=ec(e);if(r){let{src:e,filename:t,mimeType:n}=r;return(0,a.jsxs)("div",{className:"my-2 flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(U.A,{className:(0,o.cn)("h-4 w-4",g?void 0:"text-muted-foreground")}),(0,a.jsx)("span",{children:"Video attachment"})]}),(0,a.jsx)("div",{className:"w-full max-w-md",children:(0,a.jsx)("video",{controls:!0,src:e,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"})}),(t||n)&&(0,a.jsxs)("div",{className:"flex flex-col text-xs",children:[t&&(0,a.jsx)("span",{className:(0,o.cn)("truncate",g?"text-primary-foreground/80":"text-muted-foreground"),children:t}),n&&(0,a.jsx)("span",{className:(0,o.cn)(g?"text-primary-foreground/70":"text-muted-foreground/80"),children:n})]})]},s)}if((0,c.EQ)(e)){if(!e.mimeType.startsWith("audio/"))return(0,a.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(B.A,{className:(0,o.cn)("h-5 w-5",g?void 0:"text-muted-foreground")}),(0,a.jsx)("span",{className:(0,o.cn)("text-sm font-medium",void 0),children:e.filename||"".concat(e.mimeType," file")}),(0,a.jsx)("span",{className:(0,o.cn)("text-xs",g?"text-primary-foreground/70":"text-muted-foreground"),children:e.mimeType})]},s);{let t=eo(e);return(0,a.jsxs)("div",{className:"my-2 flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(z.A,{className:(0,o.cn)("h-5 w-5",g?void 0:"text-muted-foreground")}),(0,a.jsx)("audio",{controls:!0,src:t,className:"flex-1 h-8"}),e.filename&&(0,a.jsx)("span",{className:(0,o.cn)("text-sm truncate max-w-[120px]",g?"text-primary-foreground/80":"text-muted-foreground"),children:e.filename})]},s)}}return null}),E&&!e.content&&(0,a.jsx)("p",{className:"italic",children:"System message"})]}),e.imageData&&!Array.isArray(e.content)&&(()=>{let t="data:".concat(e.imageData.mimeType,";base64,").concat(e.imageData.base64);return ei(t,"image")?(0,a.jsx)("img",{src:t,alt:"attachment",className:"mt-2 max-h-60 w-full rounded-lg border border-border object-contain"}):null})(),e.fileData&&!Array.isArray(e.content)&&(0,a.jsx)("div",{className:"mt-2",children:e.fileData.mimeType.startsWith("video/")?(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-3 rounded-lg border border-border bg-muted/50 max-w-md",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(U.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Video attachment"})]}),(()=>{let t="data:".concat(e.fileData.mimeType,";base64,").concat(e.fileData.base64);return ei(t,"video")?(0,a.jsx)("video",{controls:!0,src:t,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}):(0,a.jsx)("div",{className:"text-xs text-red-500",children:"Invalid video data"})})(),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/90",children:[(0,a.jsx)("span",{className:"font-medium truncate",children:e.fileData.filename||"".concat(e.fileData.mimeType," file")}),(0,a.jsx)("span",{className:"opacity-70",children:e.fileData.mimeType})]})]}):e.fileData.mimeType.startsWith("audio/")?(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[(0,a.jsx)(z.A,{className:"h-4 w-4"}),(()=>{let t="data:".concat(e.fileData.mimeType,";base64,").concat(e.fileData.base64);return ei(t,"audio")?(0,a.jsx)("audio",{controls:!0,src:t,className:"h-8"}):(0,a.jsx)("span",{className:"text-xs text-red-500",children:"Invalid audio data"})})()]}):(0,a.jsxs)("div",{className:"flex items-center gap-2 p-3 rounded-lg border border-border bg-muted/50",children:[(0,a.jsx)(B.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{className:"text-sm font-medium",children:e.fileData.filename||"".concat(e.fileData.mimeType," file")}),(0,a.jsx)("span",{className:"text-xs text-primary-foreground/70",children:e.fileData.mimeType})]})})]})}),!E&&!X&&(0,a.jsxs)("div",{className:"text-xs text-muted-foreground mt-1 px-1 flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{children:ex}),A&&(null==(i=e.tokenUsage)?void 0:i.totalTokens)!==void 0&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-muted/50 text-xs cursor-default",children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.tokenUsage.totalTokens," tokens"]})}),(0,a.jsx)(y,{side:"bottom",children:(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[void 0!==e.tokenUsage.inputTokens&&(0,a.jsxs)("div",{children:["Input: ",e.tokenUsage.inputTokens]}),void 0!==e.tokenUsage.outputTokens&&(0,a.jsxs)("div",{children:["Output: ",e.tokenUsage.outputTokens]}),void 0!==e.tokenUsage.reasoningTokens&&(0,a.jsxs)("div",{children:["Reasoning: ",e.tokenUsage.reasoningTokens]}),(0,a.jsxs)("div",{className:"font-medium mt-0.5",children:["Total: ",e.tokenUsage.totalTokens]})]})})]}),A&&e.model&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{children:(0,a.jsx)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-muted/30 text-xs cursor-default",children:e.model})}),(0,a.jsx)(y,{side:"bottom",children:(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"font-medium",children:["Model: ",e.model]}),e.provider&&(0,a.jsxs)("div",{className:"font-medium",children:["Provider: ",e.provider]}),e.router&&(0,a.jsxs)("div",{className:"font-medium",children:["Router: ",e.router]})]})})]})]}),(A||g)&&(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(k,{value:Q(e),tooltip:"Copy message",copiedTooltip:"Copied!",className:"opacity-70 hover:opacity-100 transition-opacity"}),(0,a.jsx)(I,{value:Q(e),tooltip:"Speak",stopTooltip:"Stop",className:"opacity-70 hover:opacity-100 transition-opacity"})]})]})]}),g&&(0,a.jsx)(ea,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-2"})]}),et.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(q.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(q.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Image"})]}),(0,a.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>G(e.src,e.alt),children:[(0,a.jsx)("img",{src:e.src,alt:e.alt,className:"max-h-80 w-auto rounded border border-border object-contain transition-transform group-hover:scale-[1.02]"}),(0,a.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors rounded border border-border flex items-center justify-center",children:(0,a.jsx)(W.A,{className:"h-8 w-8 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow-lg"})})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:ex})})]})]})},"".concat(f,"-image-").concat(t))),er.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(K.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm overflow-hidden",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(K.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Video"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0",children:[(0,a.jsx)("video",{controls:!0,src:e.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata"}),(e.filename||e.mimeType)&&(0,a.jsxs)("div",{className:"flex flex-col text-xs text-muted-foreground",children:[e.filename&&(0,a.jsx)("span",{className:"truncate",children:e.filename}),e.mimeType&&(0,a.jsx)("span",{className:"opacity-70",children:e.mimeType})]})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:ex})})]})]})},"".concat(f,"-video-").concat(t))),es.map((e,t)=>(0,a.jsx)("div",{className:"w-full mt-2",children:(0,a.jsxs)("div",{className:"flex items-end w-full justify-start",children:[(0,a.jsx)(S.A,{className:"h-7 w-7 mr-2 mb-1 text-muted-foreground self-start flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm max-w-[75%] bg-card text-card-foreground border border-border rounded-bl-none text-sm overflow-hidden",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(S.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Tool Result Audio"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 p-2 rounded border border-border bg-muted/30 min-w-0 audio-controls-container",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(z.A,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,a.jsx)("audio",{controls:!0,src:e.src,className:"flex-1 min-w-0"})]}),e.filename&&(0,a.jsx)("div",{className:"flex items-center gap-2 min-w-0",children:(0,a.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.filename})})]})]})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1 px-1",children:(0,a.jsx)("span",{children:ex})})]})]})},"".concat(f,"-audio-").concat(t))),eh&&(0,a.jsx)("div",{className:"mt-2 ml-12 mr-4",children:(0,a.jsx)(O,{error:s,onDismiss:r||(()=>{})})})]},f)}),l&&p&&f&&(0,a.jsx)("div",{className:"w-full","data-role":"approval",children:(0,a.jsxs)("div",{className:"grid w-full grid-cols-[auto_1fr] gap-x-2 items-start",children:[(0,a.jsx)(R.A,{className:"h-7 w-7 mt-1 text-muted-foreground col-start-1 flex-shrink-0"}),(0,a.jsx)("div",{className:"flex flex-col group w-full col-start-2 justify-self-start items-start min-w-0",children:(0,a.jsx)("div",{className:"p-3 rounded-xl shadow-sm w-full max-w-[90%] bg-card text-card-foreground border border-border rounded-bl-none text-base min-w-0",children:(0,a.jsx)(en,{approval:l,onApprove:p,onDeny:f})})})]})}),(0,a.jsx)("div",{ref:g,className:"h-px"},"end-anchor"),T.isOpen&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh] bg-background rounded-lg shadow-2xl border border-border",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:"Tool Result Image"}),(0,a.jsx)("button",{onClick:()=>{$({isOpen:!1,src:"",alt:""})},className:"p-2 hover:bg-muted rounded-md transition-colors","aria-label":"Close modal",children:(0,a.jsx)(h.A,{className:"h-5 w-5"})})]}),(0,a.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,a.jsx)("img",{src:T.src,alt:T.alt,className:"max-w-full max-h-[70vh] object-contain rounded"})}),(0,a.jsx)("div",{className:"p-4 border-t border-border text-sm text-muted-foreground",children:(0,a.jsx)("p",{children:T.alt})})]})})]})}function eu(e){let{text:t,isUser:s,onOpenImage:r,resourceSet:i}=e,{cleanedText:l,uris:o}=(0,n.useMemo)(()=>(function(e,t){if(!e)return{cleanedText:"",uris:[]};let s=function(e,t){let s=e.map(e=>({...e}));for(let e of s)switch(e.type){case"uri":if(t[e.identifier])e.resourceUri=e.identifier;else{let s=function(e,t){var s,r;let a=t.trim().toLowerCase();for(let[t,r]of Object.entries(e)){let e="string"==typeof(null==(s=r.metadata)?void 0:s.originalUri)?r.metadata.originalUri:void 0;if(e&&e.toLowerCase()===a)return t}for(let[t,s]of Object.entries(e)){let e="string"==typeof(null==(r=s.metadata)?void 0:r.originalUri)?s.metadata.originalUri:void 0;if(e&&e.toLowerCase().includes(a))return t}}(t,e.identifier);s&&(e.resourceUri=s)}break;case"server-scoped":{let s=function(e,t,s){let r=s.trim().toLowerCase(),a=Object.entries(e).filter(e=>{let[,s]=e;return s.serverName===t});for(let[e,t]of a){if(!t.name)continue;let s=t.name.trim().toLowerCase();if(s===r||s.includes(r))return e}for(let[e,t]of a){var n;let s="string"==typeof(null==(n=t.metadata)?void 0:n.originalUri)?t.metadata.originalUri:void 0;if((null==s?void 0:s.toLowerCase().includes(r))||e.toLowerCase().includes(r))return e}}(t,e.serverName,e.identifier);s&&(e.resourceUri=s);break}case"name":{let s=function(e,t){let s=t.trim().toLowerCase();for(let[t,r]of Object.entries(e)){if(!r.name)continue;let e=r.name.trim().toLowerCase();if(e===s||e.includes(s))return t}for(let[t,a]of Object.entries(e)){var r;let e="string"==typeof(null==(r=a.metadata)?void 0:r.originalUri)?a.metadata.originalUri:void 0;if((null==e?void 0:e.toLowerCase().includes(s))||t.toLowerCase().includes(s))return t}}(t,e.identifier);s&&(e.resourceUri=s)}}return s}(function(e){let t,s=[],r=RegExp("(?:^|(?<=\\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])","g");for(;null!==(t=r.exec(e));){let[e,r,a,n,i]=t;r?s.push({originalRef:e,type:"uri",identifier:r.slice(1,-1)}):a&&n?s.push({originalRef:e,type:"server-scoped",serverName:a,identifier:n}):i&&s.push({originalRef:e,type:"name",identifier:i})}return s}(e),t),r=Array.from(new Set(s.filter(e=>e.resourceUri).map(e=>e.resourceUri))),a=e;for(let e of s)e.resourceUri&&(a=a.split(e.originalRef).join(""));return{cleanedText:a=a.replace(/\n{3,}/g,"\n\n").replace(/\s{2,}/g," ").trim(),uris:r}})(t,i),[t,i]),c=H(o),d=l.length>0;return(0,a.jsxs)("div",{className:"space-y-3",children:[d&&(0,a.jsx)("div",{className:"relative",children:s?(0,a.jsx)("p",{className:"text-base whitespace-pre-line break-normal",children:l}):(0,a.jsx)(G,{children:l})}),o.map(e=>(0,a.jsx)(ex,{uri:e,state:c[e],onOpenImage:r},e))]})}function ex(e){var t;let{uri:s,state:r,onOpenImage:n}=e;if(!r||"loading"===r.status)return(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(M.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,a.jsx)("span",{children:"Loading resource…"})]});if("error"===r.status)return(0,a.jsxs)("div",{className:"flex items-start gap-2 text-xs text-destructive",children:[(0,a.jsx)(m.A,{className:"mt-0.5 h-3.5 w-3.5"}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"font-medium",children:"Failed to load resource"}),(0,a.jsx)("p",{className:"break-all text-[11px] text-destructive/80",children:s}),(0,a.jsx)("p",{className:"text-[11px] text-destructive/70",children:r.error})]})]});let i=r.data;if(!i||0===i.items.length)return(0,a.jsxs)("div",{className:"text-xs text-muted-foreground",children:[(0,a.jsx)("p",{className:"font-medium",children:(null==i?void 0:i.name)||s}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground/80",children:"No previewable content."})]});let l=null==(t=i.items.find(e=>"mimeType"in e&&"string"==typeof e.mimeType))?void 0:t.mimeType;return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/80",children:[(0,a.jsx)($.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{className:"font-medium text-foreground",children:i.name||s}),l&&(0,a.jsx)("span",{className:"text-[10px]",children:l})]}),i.items.map((e,t)=>(function(e){let{item:t,index:s,onOpenImage:r}=e,n="resource-item-".concat(s);switch(t.kind){case"text":if(t.mimeType&&t.mimeType.includes("markdown"))return(0,a.jsx)("div",{className:"text-sm",children:(0,a.jsx)(G,{children:t.text})},n);return(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words rounded-md bg-background/60 p-2 text-sm text-foreground",children:t.text},n);case"image":if(!el(t.src))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported image source"},n);return(0,a.jsx)("img",{src:t.src,alt:t.alt||"Resource image",onClick:()=>r(t.src,t.alt||"Resource image"),className:"max-h-60 w-full cursor-zoom-in rounded-lg border border-border object-contain"},n);case"audio":if(!el(t.src,"audio"))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported audio source"},n);return(0,a.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-background/50 p-2",children:[(0,a.jsx)(z.A,{className:"h-4 w-4"}),(0,a.jsx)("audio",{controls:!0,src:t.src,className:"h-8 flex-1"}),t.filename&&(0,a.jsx)("span",{className:"max-w-[140px] truncate text-xs text-muted-foreground",children:t.filename})]},n);case"video":if(!el(t.src,"video"))return(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Unsupported video source"},n);return(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-border bg-background/50 p-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(U.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Video"}),t.filename&&(0,a.jsx)("span",{className:"truncate font-medium",children:t.filename})]}),(0,a.jsx)("video",{controls:!0,src:t.src,className:"w-full max-h-[360px] rounded-lg bg-black",preload:"metadata",children:"Your browser does not support the video tag."})]},n);case"file":return(0,a.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background/60 p-2",children:[(0,a.jsx)(B.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsxs)("div",{className:"flex flex-1 flex-col",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.filename||"Resource file"}),t.mimeType&&(0,a.jsx)("span",{className:"text-[11px] text-muted-foreground",children:t.mimeType})]}),t.src&&(0,a.jsx)("a",{href:t.src,download:t.filename||"resource.bin",className:"text-xs font-medium text-primary underline-offset-2 hover:underline",children:"Download"})]},n);default:return null}})({item:e,index:t,onOpenImage:n}))]})}var eh=s(7104),ep=s(7732);function ef(e){let{children:t,className:s}=e;return(0,a.jsx)("div",{className:(0,o.cn)("relative","w-full","flex flex-col overflow-visible","max-h-[max(35svh,5rem)]","border-2 border-border/50","bg-background","rounded-3xl shadow-sm","transition-all duration-200",s),children:t})}function eg(e){let{leftButtons:t,rightButtons:s,className:r}=e;return(0,a.jsxs)("div",{className:(0,o.cn)("flex items-center justify-between","h-12 px-2",r),children:[(0,a.jsx)("div",{className:"flex items-center gap-2",children:t}),(0,a.jsx)("div",{className:"flex items-center gap-2",children:s})]})}var ev=s(3511),ej=s(2744);let eb=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)(ej.bL,{className:(0,o.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...r,ref:t,children:(0,a.jsx)(ej.zi,{className:(0,o.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 ey(e){let{isStreaming:t,onStreamingChange:s,className:r}=e;return(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 cursor-pointer ".concat(r||""),children:[(0,a.jsx)(ev.A,{className:"h-3 w-3 ".concat(t?"text-blue-500":"text-muted-foreground")}),(0,a.jsx)(eb,{checked:t,onCheckedChange:s,className:"scale-75","aria-label":"Toggle streaming"})]})}),(0,a.jsxs)(y,{side:"bottom",children:[(0,a.jsx)("p",{children:t?"Streaming enabled":"Streaming disabled"}),(0,a.jsx)("p",{className:"text-xs opacity-75",children:t?"Responses will stream in real-time":"Responses will arrive all at once"})]})]})})}eb.displayName=ej.bL.displayName;var eN=s(7776),ew=s(6182);function ek(e){let{...t}=e;return(0,a.jsx)(ew.bL,{"data-slot":"popover",...t})}function eC(e){let{className:t,align:s="center",sideOffset:r=4,...n}=e;return(0,a.jsx)(ew.ZL,{children:(0,a.jsx)(ew.UC,{"data-slot":"popover-content",align:s,sideOffset:r,className:(0,o.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...n})})}let eS=e=>{let{children:t,...s}=e;return(0,a.jsx)(ek,{...s,children:t})},eA=function(e){let{...t}=e;return(0,a.jsx)(ew.l9,{"data-slot":"popover-trigger",...t})},eE=n.forwardRef((e,t)=>{let{className:s,align:r="end",sideOffset:n=4,...i}=e;return(0,a.jsx)(eC,{ref:t,align:r,sideOffset:n,className:(0,o.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...i})});eE.displayName="DropdownMenuContent";let eT=n.forwardRef((e,t)=>{let{className:s,disabled:r,...n}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",r&&"pointer-events-none opacity-50",!r&&"hover:bg-accent hover:text-accent-foreground cursor-pointer",s),...n})});eT.displayName="DropdownMenuItem";let eI=n.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("-mx-1 my-1 h-px bg-muted",s),...r})});function eO(e){let{onImageAttach:t,onPdfAttach:s,onAudioAttach:r,className:i,supports:l}=e,[o,c]=n.useState(!1),d=(null==l?void 0:l.image)!==!1,m=(null==l?void 0:l.pdf)!==!1,u=(null==l?void 0:l.audio)!==!1;return(0,a.jsxs)(eS,{open:o,onOpenChange:c,children:[(0,a.jsx)(eA,{asChild:!0,children:(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",className:"h-8 px-3 text-sm text-muted-foreground hover:text-foreground rounded-full ".concat(i||""),"aria-label":"Attach File",children:[(0,a.jsx)(eN.A,{className:"h-3 w-3 mr-1.5"}),"Attach"]})}),(0,a.jsxs)(eE,{side:"top",align:"start",children:[(0,a.jsx)(eT,{onClick:()=>{d&&(t(),c(!1))},className:d?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!d,children:(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(eN.A,{className:"h-4 w-4 mr-2"})," Image"]})}),!d&&(0,a.jsx)(y,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eT,{onClick:()=>{m&&(s(),c(!1))},className:m?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!m,children:(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(B.A,{className:"h-4 w-4 mr-2"})," PDF"]})}),!m&&(0,a.jsx)(y,{side:"bottom",children:"Unsupported for this model"})]})})}),(0,a.jsx)(eT,{onClick:()=>{u&&(r(),c(!1))},className:u?void 0:"opacity-50 cursor-not-allowed","aria-disabled":!u,children:(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(z.A,{className:"h-4 w-4 mr-2"})," Audio file"]})}),!u&&(0,a.jsx)(y,{side:"bottom",children:"Unsupported for this model"})]})})})]})]})}eI.displayName="DropdownMenuSeparator";var eL=s(3947),eR=s(3827);function eD(e){let{isRecording:t,onToggleRecording:s,className:r,disabled:n}=e,i=(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>{n||s()},className:"h-8 px-3 text-sm rounded-full ".concat(n?"opacity-50 cursor-not-allowed":"text-muted-foreground hover:text-foreground"," ").concat(r||""),"aria-label":t?"Stop recording":"Record audio","aria-disabled":!!n||void 0,children:[t?(0,a.jsx)(eL.A,{className:"h-3 w-3 mr-1.5 text-red-500"}):(0,a.jsx)(eR.A,{className:"h-3 w-3 mr-1.5"}),t?"Stop":"Record"]});return n?(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:i}),(0,a.jsx)(y,{side:"bottom",children:"Unsupported for this model"})]})}):i}var eF=s(4569),eP=s(3871),e_=s(531),eM=s(7159),ez=s(5195),eU=s(7397);function eB(e){let{open:t,onOpenChange:s,provider:r,primaryEnvVar:i,onSaved:l}=e,[o,c]=(0,n.useState)(""),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),h=async()=>{if(!o.trim())return void x("API key is required");m(!0),x(null);try{let e=await fetch("/api/llm/key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,apiKey:o})}),t=await e.json();if(!e.ok||"object"!=typeof t||null===t)throw Error("Failed to save API key");if(!t.ok||!t.provider||!t.envVar)throw Error("Unexpected response while saving API key");l({provider:t.provider,envVar:t.envVar}),s(!1),c("")}catch(e){x(e instanceof Error?e.message:"Failed to save API key")}finally{m(!1)}};return(0,a.jsx)(eP.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eP.Cf,{className:"max-w-md",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsxs)(eP.L3,{children:["Set ",r," API Key"]}),(0,a.jsxs)(eP.rr,{children:["This key will be stored in your .env (env var ",i,"). It is not shared with the client."]})]}),u&&(0,a.jsx)(eM.Fc,{variant:"destructive",children:(0,a.jsx)(eM.TN,{children:u})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"apiKey",children:"API Key"}),(0,a.jsx)(eU.p,{id:"apiKey",type:"password",value:o,onChange:e=>c(e.target.value),placeholder:"Enter ".concat(r," API key")})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>s(!1),disabled:d,children:"Cancel"}),(0,a.jsx)(N.$,{onClick:h,disabled:d,children:d?"Saving...":"Save"})]})]})})}var eq=s(8352),eW=s(4184),eK=s(395);function e$(e){let{value:t,onChange:s,placeholder:r="Search providers or models",autoFocus:i=!1}=e,l=(0,n.useRef)(null);return(0,n.useEffect)(()=>{i&&l.current&&setTimeout(()=>{var e;null==(e=l.current)||e.focus()},100)},[i]),(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,a.jsx)(eK.A,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsx)(eU.p,{ref:l,placeholder:r,value:t,onChange:e=>s(e.target.value),className:"focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0"})]})}var eV=s(5980),eY=s(3555),eJ=s(9355);let eG={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"},eH={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 eQ(e){if(!e)return[];let t="USD"===(e.currency||"USD")?"$":"",s=[];return s.push("Cost: ".concat(t).concat(e.inputPerM.toFixed(2)," in / ").concat(t).concat(e.outputPerM.toFixed(2)," out per 1M tokens")),null!=e.cacheReadPerM&&s.push("Cache read: ".concat(t).concat(e.cacheReadPerM.toFixed(2)," per 1M tokens")),null!=e.cacheWritePerM&&s.push("Cache write: ".concat(t).concat(e.cacheWritePerM.toFixed(2)," per 1M tokens")),s}let eZ=["google","cohere","anthropic"],eX=e=>!eZ.includes(e),e0={image:(0,a.jsx)("span",{className:"text-sm",children:"\uD83D\uDDBC️"}),audio:(0,a.jsx)("span",{className:"text-sm",children:"\uD83C\uDFB5"}),pdf:(0,a.jsx)("span",{className:"text-sm",children:"\uD83D\uDCC4"}),reasoning:(0,a.jsx)("span",{className:"text-sm",children:"\uD83E\uDDE0"}),experimental:(0,a.jsx)(eY.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-amber-500 transition-colors cursor-help"}),new:(0,a.jsx)(eJ.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-yellow-500 transition-colors cursor-help"}),realtime:(0,a.jsx)(ev.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-blue-500 transition-colors cursor-help"})};var e1=s(6083);function e2(e){let{supportedFileTypes:t,hasApiKey:s,className:r}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0 ".concat(r||""),children:[t.includes("pdf")&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e0.pdf})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:"PDF support"})})]}),t.includes("audio")&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e0.audio})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:"Audio support"})})]}),t.includes("image")&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:e0.image})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:"Image support"})})]}),!s&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{className:"transition-transform hover:scale-125",children:(0,a.jsx)(e1.A,{className:"h-3.5 w-3.5 text-amber-500 hover:text-amber-400 transition-colors cursor-help"})})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:"API key required"})})]})]})}function e4(e){let{providerId:t,provider:s,models:r,favorites:n,currentModel:i,onToggleFavorite:l,onUse:c}=e;return 0===r.length?null:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:eG[t]?(0,a.jsx)(eF.default,{src:eG[t],alt:"".concat(t," logo"),width:20,height:20,className:(0,o.cn)("object-contain",eX(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(eq.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,a.jsx)("span",{className:"text-base font-medium",children:s.name})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[s.supportedRouters.map(e=>(0,a.jsx)(eV.E,{variant:"outline",className:"capitalize text-xs",children:e},e)),s.supportsBaseURL&&(0,a.jsx)(eV.E,{variant:"secondary",className:"text-xs",children:"baseURL"}),!s.hasApiKey&&(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(eV.E,{variant:"destructive",className:"text-xs cursor-default",children:"API Key Required"})}),(0,a.jsxs)(y,{children:["Click any ",s.name," model to set up the API key"]})]})}),eH[t]&&(0,a.jsx)("a",{href:eH[t],target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:underline",title:"View provider pricing",children:"Pricing ↗"})]})]}),(0,a.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:r.map(e=>{let r,d,m=e.displayName||e.name,u=(r=e.name,(null==i?void 0:i.provider)===t&&(null==i?void 0:i.model)===r),x=(d=e.name,n.includes("".concat(t,"|").concat(d))),h=s.hasApiKey,p=eQ(e.pricing||void 0),f=["Max tokens: ".concat(e.maxInputTokens.toLocaleString()),e.supportedFileTypes.length>0&&"Supports: ".concat(e.supportedFileTypes.join(", ")),e.default&&"Default model",!h&&"⚠️ API key required",...p].filter(Boolean);return(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{onClick:()=>c(t,e),onKeyDown:s=>{let r=s.target;if(r&&r.closest("button"))return;let a="Enter"===s.key,n=" "===s.key||"Spacebar"===s.key||"Space"===s.code;n&&s.preventDefault(),(a||n)&&c(t,e)},className:(0,o.cn)("group relative flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-all duration-100 cursor-pointer outline-none","hover:bg-accent hover:border-accent-foreground/20 hover:shadow-sm","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",u&&"bg-accent border-accent-foreground/20 shadow-sm ring-1 ring-accent-foreground/10",!h&&"opacity-60"),role:"button",tabIndex:0,children:[(0,a.jsx)("div",{className:"flex-1 text-left",children:(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)("span",{className:"text-sm font-medium",children:m})})}),(0,a.jsx)(e2,{supportedFileTypes:e.supportedFileTypes,hasApiKey:h}),(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("button",{onKeyDown:e=>{let t=" "===e.key||"Spacebar"===e.key||"Space"===e.code;("Enter"===e.key||t)&&(e.stopPropagation(),t&&e.preventDefault())},onClick:s=>{s.stopPropagation(),l(t,e.name)},className:"flex-shrink-0 text-muted-foreground hover:text-foreground transition-colors","aria-label":x?"Remove from favorites":"Add to favorites",children:(0,a.jsx)(eW.A,{className:(0,o.cn)("h-4 w-4",x&&"fill-current text-yellow-500")})})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:x?"Remove from favorites":"Add to favorites"})})]})}),u&&(0,a.jsx)("div",{className:"absolute inset-y-0 left-0 w-0.5 bg-primary rounded-l-lg"})]})}),(0,a.jsx)(y,{side:"bottom",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:f.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})},e.name)})})]})}function e5(e,t){return"".concat(e,"|").concat(t)}let e3="dexto:modelFavorites";function e8(e){let{provider:t,model:s,providerInfo:r,isFavorite:n,isActive:i,onClick:l,onToggleFavorite:c}=e,d=s.displayName||s.name,m=r.hasApiKey,u=eQ(s.pricing||void 0),x=["Max tokens: ".concat(s.maxInputTokens.toLocaleString()),s.supportedFileTypes.length>0&&"Supports: ".concat(s.supportedFileTypes.join(", ")),!m&&"⚠️ API key required",...u].filter(Boolean);return(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("div",{onClick:l,className:(0,o.cn)("w-full flex items-center gap-4 px-4 py-3 rounded-xl transition-all duration-150 cursor-pointer group","hover:bg-accent/50 hover:shadow-md hover:scale-[1.01]",i&&"bg-primary/10 shadow-md ring-2 ring-primary/20 scale-[1.01]",!m&&"opacity-60"),role:"button",tabIndex:0,children:[(0,a.jsx)("div",{className:"w-6 h-6 flex-shrink-0 flex items-center justify-center",children:eG[t]?(0,a.jsx)(eF.default,{src:eG[t],alt:"".concat(t," logo"),width:24,height:24,className:(0,o.cn)("object-contain",eX(t)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(eq.A,{className:"h-5 w-5 text-muted-foreground"})}),(0,a.jsxs)("div",{className:"flex-1 text-left min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-semibold text-foreground truncate",children:d}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:t})]}),(0,a.jsx)(e2,{supportedFileTypes:s.supportedFileTypes,hasApiKey:m}),(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:(0,o.cn)("flex-shrink-0 transition-all duration-200","hover:scale-110 active:scale-95",n?"text-yellow-500 hover:text-yellow-400":"text-muted-foreground hover:text-yellow-500"),"aria-label":n?"Remove from favorites":"Add to favorites",children:(0,a.jsx)(eW.A,{className:(0,o.cn)("h-4 w-4",n&&"fill-current")})})}),(0,a.jsx)(y,{side:"top",children:(0,a.jsx)("span",{children:n?"Remove from favorites":"Add to favorites"})})]})})]})}),(0,a.jsx)(y,{side:"right",className:"max-w-xs",children:(0,a.jsx)("div",{className:"text-xs space-y-0.5",children:x.map((e,t)=>(0,a.jsx)("div",{children:e},t))})})]})})}function e6(){var e;let[t,s]=(0,n.useState)(!1),[r,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),[m,h]=(0,n.useState)({}),[p,f]=(0,n.useState)(""),[g,v]=(0,n.useState)(!1),[j,b]=(0,n.useState)(""),[y,w]=(0,n.useState)(""),[k,C]=(0,n.useState)(!1),[S,A]=(0,n.useState)(!1),[E,T]=(0,n.useState)(!1),[I,O]=(0,n.useState)(!1),[L,D]=(0,n.useState)(null),[F,P]=(0,n.useState)(null),{currentSessionId:_,currentLLM:z,refreshCurrentLLM:U}=(0,l.v)();(0,n.useEffect)(()=>{t&&z&&(b(z.router||"vercel"),w(z.baseURL||""))},[t,z]),(0,n.useEffect)(()=>{if(!t)return;let e=!1;return async function(){i(!0),d(null);try{let t=await fetch("/api/llm/catalog");if(!e&&t.ok){let e=await t.json();h(e.providers||{})}}catch(t){e||d("Failed to load catalog")}finally{e||i(!1)}}(),()=>{e=!0}},[t]);let[B,q]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(t)try{let e=localStorage.getItem(e3);q(e?JSON.parse(e):[])}catch(e){q([])}},[t]);let W=(0,n.useCallback)((e,t)=>{let s=e5(e,t);q(e=>{let t=e.includes(s)?e.filter(e=>e!==s):[...e,s];return localStorage.setItem(e3,JSON.stringify(t)),t})},[]);async function K(e,t,r){C(!0),d(null);try{var a,n;let i=function(e,t){var s,r,a;let n=(null==z?void 0:z.router)||"vercel",i=null!=(r=null==(s=m[e])?void 0:s.supportedRouters)?r:["vercel"],l=null!=(a=t.supportedRouters)?a:i,o=j||n;return l.includes(o)?o:l[0]||i[0]||"vercel"}(e,t),l={provider:e,model:t.name,router:i};r&&(null==(a=m[e])?void 0:a.supportsBaseURL)&&(l.baseURL=r),_&&(l.sessionId=_);let o=await fetch("/api/llm/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),c=await o.json().catch(()=>({}));if(!o.ok){let e=(null==c?void 0:c.issues)&&(null==(n=c.issues[0])?void 0:n.message)||"Failed to switch model";d(e);return}await U(),s(!1)}catch(e){d("Network error while switching")}finally{C(!1)}}function $(e,t){let s=m[e];if(s){if(s.supportsBaseURL&&y){let e=function(e){let t=e.trim();if(!t.length)return{isValid:!0};try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return{isValid:!1,error:"URL must use http:// or https://"};if(!e.pathname.includes("/v1"))return{isValid:!1,error:"URL must include /v1 for compatibility"};return{isValid:!0}}catch(e){return{isValid:!1,error:"Invalid URL format"}}}(y);if(!e.isValid)return void d(e.error||"Invalid base URL")}if(!s.hasApiKey){P({provider:e,model:t.name}),D(e),O(!0);return}K(e,t,y)}}let V=Object.keys(m),Y=(null==z?void 0:z.displayName)||(null==z?void 0:z.model)||"Choose Model",J=(0,n.useMemo)(()=>B.map(e=>{let[t,s]=e.split("|"),r=m[t],a=null==r?void 0:r.models.find(e=>e.name===s);return r&&a?{providerId:t,provider:r,model:a}:null}).filter(Boolean),[B,m]),G=(0,n.useMemo)(()=>{if(!p)return m;let e={};return V.forEach(t=>{let s=m[t].models.filter(e=>(function(e,t){var s,r,a,n;let i=p.trim().toLowerCase();return!i||t.name.toLowerCase().includes(i)||null!=(a=null==(s=t.displayName)?void 0:s.toLowerCase().includes(i))&&a||e.toLowerCase().includes(i)||null!=(n=null==(r=m[e])?void 0:r.name.toLowerCase().includes(i))&&n})(t,e));s.length>0&&(e[t]={...m[t],models:s})}),e},[m,p,V]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(eP.lG,{open:t,onOpenChange:s,children:[(0,a.jsx)(eP.zM,{asChild:!0,children:(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",className:"hidden lg:flex items-center gap-2 cursor-pointer",title:"Choose model",children:[(null==z?void 0:z.provider)&&eG[z.provider]?(0,a.jsx)(eF.default,{src:eG[z.provider],alt:"".concat(z.provider," logo"),width:16,height:16,className:(0,o.cn)("object-contain",eX(z.provider)&&"dark:invert dark:brightness-0 dark:contrast-200")}):(0,a.jsx)(R.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-sm",children:Y}),(0,a.jsx)(x.A,{className:"h-3 w-3"})]})}),(0,a.jsxs)(eP.Cf,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[(0,a.jsxs)(eP.c7,{className:"pb-4 flex-shrink-0",children:[(0,a.jsx)(eP.L3,{className:"text-xl",children:"Select Model"}),(0,a.jsx)(eP.rr,{className:"text-sm text-muted-foreground",children:"Choose from your favorite models or explore all available options"})]}),(0,a.jsxs)("div",{className:"flex flex-col min-h-0 flex-1 space-y-6",children:[(0,a.jsxs)("div",{className:"flex-shrink-0 space-y-4",children:[c&&(0,a.jsx)(eM.Fc,{variant:"destructive",children:(0,a.jsx)(eM.TN,{children:c})}),(0,a.jsx)(e$,{value:p,onChange:f,placeholder:"Search models, providers..."})]}),J.length>0&&!p&&(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>T(!E),className:"flex items-center justify-between w-full p-0 h-auto hover:bg-transparent",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(eW.A,{className:"h-4 w-4 text-yellow-500 fill-current"}),(0,a.jsx)("span",{className:"text-sm font-medium",children:"Favorites"}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",J.length,")"]})]}),E?(0,a.jsx)(x.A,{className:"h-4 w-4"}):(0,a.jsx)(u.A,{className:"h-4 w-4"})]}),!E&&(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"max-h-[280px] overflow-y-auto px-1 py-1 space-y-1",children:J.map(e=>{let t,{providerId:s,provider:r,model:n}=e;return(0,a.jsx)(e8,{provider:s,model:n,providerInfo:r,isFavorite:!0,isActive:(t=n.name,(null==z?void 0:z.provider)===s&&(null==z?void 0:z.model)===t),onClick:()=>$(s,n),onToggleFavorite:()=>W(s,n.name)},e5(s,n.name))})}),J.length>6&&(0,a.jsxs)("div",{className:"text-xs text-muted-foreground text-center",children:["Scroll to see all ",J.length," favorites"]})]})]}),!p&&(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>A(!S),className:"w-full justify-center gap-2",children:S?(0,a.jsxs)(a.Fragment,{children:["Hide All Models ",(0,a.jsx)(u.A,{className:"h-4 w-4"})]}):(0,a.jsxs)(a.Fragment,{children:["Show All Models ",(0,a.jsx)(x.A,{className:"h-4 w-4"})]})}),(S||p)&&(0,a.jsx)("div",{className:"flex-1 overflow-auto px-1 min-h-0",children:(0,a.jsx)("div",{className:"space-y-6 pb-2",children:r?(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,a.jsx)(M.A,{className:"h-4 w-4 animate-spin"})," Loading models..."]}):0===Object.keys(G).length?(0,a.jsx)("div",{className:"text-sm text-muted-foreground text-center py-8",children:p?"No models found matching your search":"No providers available"}):Object.entries(G).map(e=>{let[t,s]=e;return(0,a.jsx)(e4,{providerId:t,provider:s,models:s.models,favorites:B,currentModel:z||void 0,onToggleFavorite:W,onUse:$},t)})})})]}),(0,a.jsxs)("div",{className:"flex-shrink-0 space-y-3 border-t pt-4 mt-4",children:[(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>v(!g),className:"flex items-center justify-between w-full p-0 h-auto hover:bg-transparent",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:"Advanced Options"}),g?(0,a.jsx)(u.A,{className:"h-4 w-4"}):(0,a.jsx)(x.A,{className:"h-4 w-4"})]}),g&&(0,a.jsxs)("div",{className:"space-y-4 pl-4 border-l-2 border-muted",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{className:"text-sm font-medium",children:"Router"}),(0,a.jsxs)(ez.l6,{value:j,onValueChange:e=>b(e),children:[(0,a.jsx)(ez.bq,{children:(0,a.jsx)(ez.yv,{placeholder:"Select router"})}),(0,a.jsx)(ez.gC,{children:Array.from(new Set(V.flatMap(e=>m[e].supportedRouters))).map(e=>(0,a.jsx)(ez.eb,{value:e,children:(0,a.jsx)("span",{className:"capitalize",children:e})},e))})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{className:"text-sm font-medium",children:"Custom Base URL"}),(0,a.jsx)(eU.p,{value:y,onChange:e=>w(e.target.value),placeholder:"https://api.openai.com/v1",className:"text-sm"}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"Only used for providers that support baseURL."})]})]})]})]})]}),L&&(0,a.jsx)(eB,{open:I,onOpenChange:O,provider:L,primaryEnvVar:(null==(e=m[L])?void 0:e.primaryEnvVar)||"",onSaved:function(e){if(h(t=>({...t,[e.provider]:t[e.provider]?{...t[e.provider],hasApiKey:!0}:t[e.provider]})),O(!1),F){var t;let{provider:e,model:s}=F,r=null==(t=m[e])?void 0:t.models.find(e=>e.name===s);r&&K(e,r,y),P(null)}}})]})}var e9=s(7079),e7=s(649);function te(e){let{resources:t,query:s,selectedIndex:r,onSelect:i,onHoverIndex:l,loading:c}=e,d=n.useMemo(()=>(0,o.L)(t,s),[t,s]),m=H(n.useMemo(()=>d.filter(e=>(e.mimeType||"").startsWith("image/")).map(e=>e.uri),[d])),u=n.useRef([]);if(n.useEffect(()=>{let e=u.current[r];e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})},[r,d.length]),!s&&0===d.length&&!c)return(0,a.jsxs)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:[(0,a.jsx)("div",{children:"No resources available."}),(0,a.jsx)("div",{className:"text-xs mt-1 text-muted-foreground/80",children:"Connect an MCP server or enable internal resources to attach references."})]});let x=e=>"resource-option-".concat(btoa(e).replace(/[^a-zA-Z0-9]/g,"")),h=d[r]?x(d[r].uri):void 0;return c?(0,a.jsx)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Loading resources…"}):0===d.length?(0,a.jsxs)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:[(0,a.jsxs)("div",{children:['No resources match "',s,'"']}),(0,a.jsx)("div",{className:"text-xs mt-1 text-muted-foreground/80",children:"Tip: @ references only work at start or after spaces"})]}):(0,a.jsxs)("ul",{role:"listbox","aria-label":"Resource suggestions","aria-activedescendant":h,className:"py-1 text-sm max-h-64 overflow-y-auto",children:[(0,a.jsx)("li",{className:"px-3 py-1.5 text-xs text-muted-foreground/80 border-b border-border",children:"@ references files/resources • Works at start or after spaces"}),d.map((e,t)=>{let s=x(e.uri);return(0,a.jsxs)("li",{id:s,role:"option","aria-selected":t===r,ref:e=>{e&&(u.current[t]=e)},className:"px-3 py-2 cursor-pointer flex items-center gap-3 "+(t===r?"bg-accent text-accent-foreground":"hover:bg-accent hover:text-accent-foreground"),onMouseEnter:()=>null==l?void 0:l(t),onMouseDown:t=>{t.preventDefault(),i(e)},children:[(e.mimeType||"").startsWith("image/")&&(0,a.jsx)(tt,{resourceState:m[e.uri]}),(0,a.jsxs)("div",{className:"min-w-0 flex-1 mr-2",children:[(0,a.jsx)("div",{className:"truncate font-medium",children:e.name||e.uri.split("/").pop()||e.uri}),(0,a.jsx)("div",{className:"truncate text-xs text-muted-foreground",children:e.uri})]}),e.serverName&&(0,a.jsx)("span",{className:"ml-auto shrink-0 rounded bg-secondary px-2 py-0.5 text-xs text-secondary-foreground",children:e.serverName})]},e.uri)})]})}function tt(e){var t;let{resourceState:s}=e,r="w-10 h-10 rounded-md border border-border bg-muted/40 flex items-center justify-center overflow-hidden flex-shrink-0";if(!s)return(0,a.jsx)("div",{className:r,children:(0,a.jsx)(q.A,{className:"h-4 w-4 text-muted-foreground"})});if("loading"===s.status)return(0,a.jsx)("div",{className:r,children:(0,a.jsx)(M.A,{className:"h-4 w-4 animate-spin text-muted-foreground"})});if("error"===s.status)return(0,a.jsx)("div",{className:r,title:s.error,children:(0,a.jsx)(q.A,{className:"h-4 w-4 text-destructive"})});let n=null==(t=s.data)?void 0:t.items.find(e=>"image"===e.kind);return n&&"src"in n?(0,a.jsx)("div",{className:r,children:(0,a.jsx)("img",{src:n.src,alt:n.alt||"Resource preview",className:"w-full h-full object-cover"})}):(0,a.jsx)("div",{className:r,children:(0,a.jsx)(q.A,{className:"h-4 w-4 text-muted-foreground"})})}var ts=s(4580),tr=s(4957);let ta=e=>{let{prompt:t,isSelected:s,onClick:r,onMouseEnter:n,dataIndex:i}=e;return(0,a.jsx)("div",{className:"px-3 py-2 cursor-pointer transition-colors ".concat(s?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"),onClick:r,onMouseEnter:n,"data-index":i,children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:"mcp"===t.source?(0,a.jsx)(ev.A,{className:"h-3 w-3 text-blue-400"}):"starter"===t.source?(0,a.jsx)("span",{className:"text-xs",children:"\uD83D\uDE80"}):(0,a.jsx)(eJ.A,{className:"h-3 w-3 text-purple-400"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsxs)("span",{className:"font-medium text-xs text-foreground",children:["/",t.name]}),t.arguments&&t.arguments.length>0&&(0,a.jsx)("span",{className:"flex items-center gap-1",children:t.arguments.map((e,t)=>(0,a.jsxs)("span",{className:"group relative inline-block",title:e.description||e.name,children:[(0,a.jsxs)("span",{className:"text-xs text-muted-foreground/70 hover:text-muted-foreground cursor-help transition-colors",children:["<",e.name,e.required?"":"?",">"]}),e.description&&(0,a.jsx)("span",{className:"invisible group-hover:visible absolute left-0 top-full mt-1 z-50 px-2 py-1 text-[10px] bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-nowrap pointer-events-none",children:e.description})]},e.name))})]}),"mcp"===t.source&&(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"MCP"}),"file"===t.source&&(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4",children:"File"}),"custom"===t.source&&(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Custom"}),"starter"===t.source&&(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-1.5 py-0.5 h-4 bg-primary/10 text-primary border-primary/20",children:"Starter"})]}),t.title&&(0,a.jsx)("div",{className:"text-xs font-medium text-foreground/90 mb-0.5",children:t.title}),t.description&&t.description!==t.title&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5 line-clamp-2",children:t.description})]})]})})};function tn(e){let{isVisible:t,searchQuery:s,onSelectPrompt:r,onClose:i,onCreatePrompt:l,refreshKey:o}=e,[c,d]=(0,n.useState)([]),[m,u]=(0,n.useState)([]),[x,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(0),g=(0,n.useRef)(0),v=(0,n.useRef)(null),j=(0,n.useRef)(null),b=(0,n.useRef)(0);g.current=p;let y=n.useMemo(()=>{let e=s.trim();return!!e&&!!("/"===e||e.startsWith("/")&&0===m.length)},[s,m.length]),N=n.useMemo(()=>{let e=[];return y&&e.push({kind:"create"}),m.forEach(t=>e.push({kind:"prompt",prompt:t})),e},[y,m]);(0,n.useEffect)(()=>{if(!t)return;let e=!1;h(!0);let s=null!=o?o:0,r=s>0&&s!==b.current;return(0,tr.y)({forceRefresh:r}).then(t=>{e||(d(t),u(t),b.current=s)}).catch(()=>{e||(d([]),u([]))}).finally(()=>{e||h(!1)}),()=>{e=!0}},[t,o]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("✨ Prompts list changed:",(null==e?void 0:e.detail)||{}),h(!0),(0,tr.y)({forceRefresh:!0}).then(e=>{d(e),u(e)}).catch(()=>{d([]),u([])}).finally(()=>{h(!1)})};return window.addEventListener("dexto:mcpPromptsListChanged",e),()=>{window.removeEventListener("dexto:mcpPromptsListChanged",e)}},[t]),(0,n.useEffect)(()=>{if(!s.trim()||"/"===s){u(c),f(+("/"===s&&c.length>0));return}let e=(s.startsWith("/")?s.slice(1):s).split(/\s+/)[0]||"";u(c.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.description&&t.description.toLowerCase().includes(e.toLowerCase())||t.title&&t.title.toLowerCase().includes(e.toLowerCase()))),f(0)},[s,c]);let w=N.length;return((0,n.useEffect)(()=>{f(e=>0===w?0:e>=w?w-1:e)},[w]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{let t=()=>{e.preventDefault(),e.stopPropagation(),"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation()},a=(s.startsWith("/")?s.slice(1):s).split(/\s+/),n=a.length>1&&a.slice(1).some(e=>e.trim().length>0);switch(e.key){case"ArrowDown":if(0===N.length)return;t(),f(e=>(e+1)%N.length);break;case"ArrowUp":if(0===N.length)return;t(),f(e=>(e-1+N.length)%N.length);break;case"Enter":if(n)return;if(t(),0===N.length){null==l||l();return}{let e=N[g.current];"create"===e.kind?null==l||l():r(e.prompt)}break;case"Escape":t(),i();break;case"Tab":if(t(),0===N.length){null==l||l();return}{let e=N[g.current];"create"===e.kind?null==l||l():r(e.prompt)}}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t,N,r,i,l,s]),(0,n.useEffect)(()=>{if(!j.current)return;let e=j.current,t=e.querySelector('[data-index="'.concat(p,'"]'));if(t){let s=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=r.top<s.top,n=r.bottom>s.bottom;(a||n)&&t.scrollIntoView({behavior:"smooth",block:"nearest"})}},[p]),(0,n.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&i()};return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,i]),t)?(0,a.jsxs)("div",{ref:v,className:"absolute left-0 right-0 mb-2 bg-background border border-border rounded-lg shadow-lg max-h-96 overflow-hidden z-[9999]",style:{position:"absolute",bottom:"calc(100% + 0px)",left:0,right:0,borderRadius:"8px",maxHeight:"320px",overflow:"visible",zIndex:9999,minWidth:"400px",background:"linear-gradient(135deg, hsl(var(--background)) 0%, hsl(var(--muted)) 100%)",border:"1px solid hsl(var(--border) / 0.3)",backdropFilter:"blur(8px)",boxShadow:"0 8px 32px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05)"},children:[(0,a.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[(0,a.jsx)("span",{children:"Available Prompts (hover over arguments for more info)"}),(0,a.jsx)(eV.E,{variant:"secondary",className:"ml-auto text-xs px-2 py-0.5",children:c.length})]})}),(0,a.jsx)("div",{ref:j,className:"max-h-48 overflow-y-auto",children:x?(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"Loading prompts..."}):(0,a.jsxs)(a.Fragment,{children:[y&&(0,a.jsxs)("div",{className:"px-3 py-2 cursor-pointer transition-colors ".concat(0===p?"bg-primary/20 ring-1 ring-primary/40":"hover:bg-primary/10"),onClick:()=>null==l?void 0:l(),onMouseEnter:()=>f(0),"data-index":0,children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-foreground",children:[(0,a.jsx)(ts.A,{className:"h-3 w-3 text-primary"}),(0,a.jsx)("span",{children:"Create new prompt"})]}),(0,a.jsx)("div",{className:"text-[11px] text-muted-foreground mt-1",children:"Define a reusable prompt. Press Enter to continue."})]}),0===m.length?!y&&(0,a.jsx)("div",{className:"p-3 text-center text-xs text-muted-foreground",children:"No prompts available."}):m.map((e,t)=>{let s=y?t+1:t;return(0,a.jsx)(ta,{prompt:e,isSelected:s===p,onClick:()=>r(e),onMouseEnter:()=>f(s),dataIndex:s},e.name)})]})}),(0,a.jsx)("div",{className:"px-2 py-1.5 border-t border-border bg-muted/20 text-xs text-muted-foreground text-center",children:(0,a.jsx)("span",{children:"↑↓ Navigate • Tab/Enter Select • Esc Close"})})]}):null}var ti=s(449),tl=s(2166),to=s(113),tc=s(7785);function td(e){let{open:t,onClose:s,onCreated:r}=e,[i,l]=(0,n.useState)(""),[o,c]=(0,n.useState)(""),[d,m]=(0,n.useState)(""),[u,x]=(0,n.useState)(""),[h,p]=(0,n.useState)(null),[f,g]=(0,n.useState)(null),[v,j]=(0,n.useState)(null),[b,y]=(0,n.useState)(!1),[w,k]=(0,n.useState)(null),[C,S]=(0,n.useState)(!1);(0,n.useEffect)(()=>{t||(l(""),c(""),m(""),x(""),p(null),g(null),j(null),k(null),y(!1),S(!1))},[t]);let A=async e=>{try{var t;let s=await (t=e,new Promise((e,s)=>{let r=new FileReader;r.onload=()=>{let t=r.result;"string"==typeof t?e(t):s(Error("Failed to read file"))},r.onerror=e=>s(e),r.readAsDataURL(t)}));p({base64:s,mimeType:e.type||"application/octet-stream",filename:e.name}),g(s),j(e.name)}catch(e){console.error("Failed to read file:",e),k("Failed to read file. Please try a different file.")}},E=async e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s){p(null),g(null),j(null);return}await A(s)},T=async e=>{e.preventDefault(),S(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&await A(t[0])},I=async e=>{if(e.preventDefault(),!i.trim()||!u.trim())return void k("Name and content are required.");y(!0),k(null);let t={name:i.trim(),title:o.trim()||void 0,description:d.trim()||void 0,content:u,resource:h||void 0};try{let e=await fetch("/api/prompts/custom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok){let t=await e.json().catch(()=>({})),s=(null==t?void 0:t.message)||"Failed to create prompt.";throw Error(s)}let s=await e.json();(null==s?void 0:s.prompt)&&r({name:s.prompt.name})}catch(e){console.error("Failed to create prompt:",e),k(e instanceof Error?e.message:"Failed to create prompt. Please try again.")}finally{y(!1)}};return(0,a.jsx)(eP.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-3xl",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsx)(eP.L3,{children:"Create Custom Prompt"}),(0,a.jsx)(eP.rr,{children:"Define reusable prompt text and optionally attach a supporting resource file."})]}),(0,a.jsxs)("form",{onSubmit:I,className:"space-y-4",children:[w&&(0,a.jsx)(eM.Fc,{variant:"destructive",children:(0,a.jsx)(eM.TN,{children:w})}),(0,a.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"prompt-name",children:"Prompt Name"}),(0,a.jsx)(eU.p,{id:"prompt-name",value:i,onChange:e=>l(e.target.value),placeholder:"research-summary",required:!0}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Use lowercase letters, numbers, or hyphens. This becomes your /prompt command."})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"prompt-title",children:"Title"}),(0,a.jsx)(eU.p,{id:"prompt-title",value:o,onChange:e=>c(e.target.value),placeholder:"Research Summary"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"prompt-description",children:"Description"}),(0,a.jsx)(eU.p,{id:"prompt-description",value:d,onChange:e=>m(e.target.value),placeholder:"Summarize research papers with key findings"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"prompt-content",children:"Prompt Content"}),(0,a.jsx)(ti.T,{id:"prompt-content",value:u,onChange:e=>x(e.target.value),placeholder:"Write the instructions for this prompt...",className:"min-h-[160px]",required:!0})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)(e_.J,{children:"Attach resource (optional)"}),f?(0,a.jsxs)("div",{className:"flex items-center justify-between rounded-lg border border-dashed border-border/60 bg-muted/40 px-4 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center text-sm",children:[(0,a.jsx)(tl.A,{className:"h-4 w-4 mr-2 text-muted-foreground"}),(0,a.jsx)(eV.E,{variant:"secondary",className:"mr-2",children:"Resource"}),v||"Attached file"]}),(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>{p(null),g(null),j(null)},children:[(0,a.jsx)(to.A,{className:"h-4 w-4 mr-1"})," Remove"]})]}):(0,a.jsxs)("div",{className:"relative rounded-lg border-2 border-dashed transition-colors ".concat(C?"border-primary bg-primary/5":"border-border/60 hover:border-border/80"," px-6 py-8 text-center"),onDragOver:e=>{e.preventDefault(),S(!0)},onDragLeave:e=>{e.preventDefault(),S(!1)},onDrop:T,children:[(0,a.jsx)("input",{type:"file",onChange:E,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",accept:"*/*"}),(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center space-y-2",children:[(0,a.jsx)(tc.A,{className:"h-8 w-8 ".concat(C?"text-primary":"text-muted-foreground")}),(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("span",{className:"font-medium",children:C?"Drop file here":"Click to upload"}),(0,a.jsx)("span",{className:"text-muted-foreground",children:" or drag and drop"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Any file type supported"})]})]}),(0,a.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The resource will be stored securely and referenced when this prompt is used."})]}),(0,a.jsxs)(eP.Es,{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)(N.$,{type:"button",variant:"ghost",onClick:s,disabled:b,children:"Cancel"}),(0,a.jsx)(N.$,{type:"submit",disabled:b,children:b?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(M.A,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):"Save Prompt"})]})]})]})})}function tm(e){let{open:t,onClose:s,onSuccess:r}=e,[i,l]=(0,n.useState)(""),[o,c]=(0,n.useState)(""),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),h=async()=>{if(!i.trim())return void x("Memory content is required");m(!0),x(null);try{let e={content:i.trim(),...o.trim()&&{tags:o.split(",").map(e=>e.trim()).filter(Boolean)},metadata:{source:"user"}},t=await fetch("/api/memory",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to create memory")}l(""),c(""),null==r||r(),s()}catch(e){x(e instanceof Error?e.message:"Failed to create memory")}finally{m(!1)}},p=()=>{d||(l(""),c(""),x(null),s())};return(0,a.jsx)(eP.lG,{open:t,onOpenChange:p,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-[500px]",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsx)(eP.L3,{children:"Create Memory"}),(0,a.jsx)(eP.rr,{children:"Memories are automatically included in every conversation to help Dexto remember your preferences and important information."})]}),(0,a.jsxs)("div",{className:"grid gap-4 py-4",children:[u&&(0,a.jsxs)(eM.Fc,{variant:"destructive",children:[(0,a.jsx)(e9.A,{className:"h-4 w-4"}),(0,a.jsx)(eM.TN,{children:u})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(e_.J,{htmlFor:"memory-content",children:"Memory Content *"}),(0,a.jsx)(ti.T,{id:"memory-content",placeholder:"e.g., I prefer concise responses without explanations",value:i,onChange:e=>l(e.target.value),className:"min-h-[100px] resize-none",disabled:d,autoFocus:!0}),(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[i.length," / 10,000 characters"]})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(e_.J,{htmlFor:"memory-tags",children:"Tags (optional)"}),(0,a.jsx)(eU.p,{id:"memory-tags",placeholder:"e.g., preferences, work, coding-style",value:o,onChange:e=>c(e.target.value),disabled:d}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Comma-separated tags for organizing memories"})]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:p,disabled:d,children:"Cancel"}),(0,a.jsx)(N.$,{onClick:h,disabled:d||!i.trim(),children:d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(M.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Memory"})]})]})})}function tu(e){let{onSend:t,isSending:s,variant:r="chat"}=e,[i,c]=(0,n.useState)(""),d=(0,n.useRef)(null),[m,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(null),f=(0,n.useRef)(null),g=(0,n.useRef)(null),v=(0,n.useRef)(null),j=function(){let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if("undefined"==typeof document)return;let e=document;if(!e.fonts||!e.fonts.ready)return void t(!0);let s=!1;return e.fonts.ready.then(()=>{s||t(!0)}),()=>{s=!0}},[]),e}(),[b,y]=(0,n.useState)(!1),w=(0,n.useRef)(null),{currentSessionId:k,isStreaming:S,setStreaming:A,cancel:E,processing:T,currentLLM:I}=(0,l.v)(),[O,L]=(0,n.useState)(null),[R,D]=(0,n.useState)(!1),[P,_]=(0,n.useState)(null),[U,q]=(0,n.useState)(null),[W,K]=(0,n.useState)([]),{resources:$,loading:V,refresh:Y}=es(),[J,G]=(0,n.useState)(""),[H,Q]=(0,n.useState)(!1),[Z,X]=(0,n.useState)(0),[ee,et]=(0,n.useState)(null),er=(0,n.useMemo)(()=>(0,o.L)($,J),[$,J]),ea=(e,t)=>{for(let s=t-1;s>=0;s--){let t=e[s];if("@"===t){if(0===s)return s;let t=e[s-1];if(/\s/.test(t))return s;break}if(/\s/.test(t))break}return -1},en=[{name:"Claude 4 Sonnet",provider:"anthropic",model:"claude-sonnet-4-5-20250929"},{name:"GPT-4o",provider:"openai",model:"gpt-4o"},{name:"GPT-4.1 Mini",provider:"openai",model:"gpt-4.1-mini"},{name:"Gemini 2.5 Pro",provider:"google",model:"gemini-2.5-pro"}],[ei,el]=(0,n.useState)(!1),[eo,ec]=(0,n.useState)(!1),[ed,em]=(0,n.useState)(0),[eu,ex]=(0,n.useState)(!1),ev=e=>{q(e),setTimeout(()=>q(null),5e3)},ej=n.useCallback(()=>{el(!1),ec(!0)},[]),eb=n.useCallback(e=>{(0,tr.w)(),ec(!1),em(e=>e+1);let t="/".concat(e.name);c(t),d.current&&(d.current.focus(),d.current.setSelectionRange(t.length,t.length))},[]),eN=n.useCallback(()=>{ec(!1),"/"===i&&c("")},[i]);(0,n.useEffect)(()=>{(async()=>{try{let e=await fetch(k?"/api/llm/current?sessionId=".concat(k):"/api/llm/current");if(e.ok){let t=await e.json(),s=en.find(e=>e.model===t.config.model);s?L(s):L({name:"".concat(t.config.provider,"/").concat(t.config.model),provider:t.config.provider,model:t.config.model})}}catch(e){console.error("Failed to fetch current model:",e),L(null)}})()},[k]),(0,n.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/llm/catalog?mode=flat");if(!e.ok)return;let t=(await e.json()).models||[],s=null==I?void 0:I.provider,r=null==I?void 0:I.model;if(!s||!r)return;let a=t.find(e=>e.provider===s&&e.name===r);K((null==a?void 0:a.supportedFileTypes)||[])}catch(e){K([])}})()},[null==I?void 0:I.provider,null==I?void 0:I.model]);let ew=async()=>{let e=i.trim();if(e||m||x){if("/"===e)return void ej();if(e.startsWith("/")){let t=function(e){let t=e.trim();if(!t.startsWith("/"))return{isSlash:!1,command:"",argsArray:[],argsText:""};let s=function(e){let t=[],s="",r=!1,a="",n=0;for(;n<e.length;){let i=e[n],l=e[n+1];r||'"'!==i&&"'"!==i?r&&i===a?(r=!1,a=""):r||" "!==i?"\\"===i&&l?(s+=l,n++):s+=i:s&&(t.push(s),s=""):(r=!0,a=i),n++}return s&&t.push(s),t.filter(Boolean)}(t.slice(1)),r=s[0]||"",a=s.slice(1),n=a.join(" ");return{isSlash:!0,command:r,argsArray:a,argsText:n}}(e),s=t.command,r=e.slice(1+s.length).trimStart();if(s)try{let a=new URL("/api/prompts/".concat(encodeURIComponent(s),"/resolve"),window.location.origin);if(t.argsArray&&t.argsArray.length>0){let{keyValues:e,positional:s}=function(e){let t={},s=[];for(let r of e){let e=r.indexOf("=");if(e>0){let s=r.slice(0,e).trim(),a=r.slice(e+1);if(s.length>0){t[s]=a;continue}}s.push(r)}return{keyValues:t,positional:s}}(t.argsArray),r={...e};if(s.length>0&&(r._positional=s),Object.keys(r).length>0)try{a.searchParams.set("args",JSON.stringify(r))}catch(e){}}r&&a.searchParams.set("context",r);let n=new AbortController,i=setTimeout(()=>n.abort(),5e3);try{let t=await fetch(a.toString(),{signal:n.signal});if(clearTimeout(i),t.ok){let s=await t.json(),r="string"==typeof(null==s?void 0:s.text)?s.text:"";r.trim()&&(e=r)}}finally{clearTimeout(i)}}catch(e){}}t(e,null!=m?m:void 0,null!=x?x:void 0),c(""),u(null),p(null),el(!1)}},ek=(e,t)=>{var s;if(!t&&0===er.length)return;let r=null!=t?t:er[Math.max(0,Math.min(e,er.length-1))],a=d.current;if(!a)return;let n=null!=(s=a.selectionStart)?s:i.length,l=ea(i,n);if(-1===l)return;let o=i.slice(0,l),m=i.slice(n),u=r.name||r.uri.split("/").pop()||r.uri,x=r.serverName?"@".concat(r.serverName,":").concat(u):"@".concat(u);c(o+x+m),Q(!1),G(""),X(0),requestAnimationFrame(()=>{let e=(o+x).length;a.setSelectionRange(e,e),a.focus()})},eC=e=>{if(H){if("ArrowDown"===e.key){e.preventDefault(),X(e=>(e+1)%Math.max(1,er.length));return}if("ArrowUp"===e.key){e.preventDefault(),X(e=>(e-1+Math.max(1,er.length))%Math.max(1,er.length));return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),ek(Z);return}if("Escape"===e.key)return void Q(!1)}if(eS&&"Escape"===e.key){e.preventDefault(),eA(!1),c("");return}if("Enter"===e.key&&!e.shiftKey){if(e.preventDefault(),"#"===i.trim()){c(""),eA(!1),ex(!0);return}ew()}},[eS,eA]=(0,n.useState)(!1),[eE,eT]=(0,n.useState)(null),eI=e=>{let t=e.target.value;if(c(t),t.startsWith("/")&&!t.includes("\n")?el(!0):ei&&el(!1),"#"===t.trim()){eA(!0);let e=d.current;if(e){let t=e.getBoundingClientRect(),s=Math.max(8,t.left+window.scrollX+16),r=Math.max(280,t.width-32);eT({position:"fixed",left:s,bottom:Math.max(80,window.innerHeight-(t.bottom+window.scrollY)+64),width:r,zIndex:9999})}}else eA(!1),eT(null)};(0,n.useEffect)(()=>{var e;let t=d.current,s=t&&null!=(e=t.selectionStart)?e:i.length,r=ea(i,s);if(r>=0){G(i.slice(r+1,s)),Q(!0),X(0);let e=null==t?void 0:t.getBoundingClientRect();if(e){let t=Math.max(8,e.left+window.scrollX+16),s=Math.max(280,e.width-32);et({position:"fixed",left:t,bottom:Math.max(80,window.innerHeight-(e.bottom+window.scrollY)+64),width:s,zIndex:9999})}}else Q(!1),G(""),et(null)},[i]);let eL=n.useRef(!1);(0,n.useEffect)(()=>{H?eL.current||(eL.current=!0,Y()):eL.current=!1},[H,Y]);let eR=e=>{let t=e.clipboardData.getData("text/plain");if(t&&!(t.length<=2e4))if(e.preventDefault(),window.confirm("Large text detected. Attach as a file instead of inflating the input?\n(OK = attach as file, Cancel = paste truncated preview)"))p({base64:(e=>{try{return btoa(unescape(encodeURIComponent(e)))}catch(t){return btoa(e)}})(t),mimeType:"text/plain",filename:"pasted.txt"});else{let e=t.slice(0,2e4);c(t=>t+e)}},eF=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);w.current=t;let s=[];t.ondataavailable=e=>{e.data.size>0&&s.push(e.data)},t.onstop=()=>{let r=new Blob(s,{type:t.mimeType}),a=new FileReader;a.onloadend=()=>{try{let e=a.result,s=e.indexOf(","),r=e.substring(s+1),n=t.mimeType||"audio/webm",i={"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"}[n]||n.split("/")[1]||"webm";p({base64:r,mimeType:n,filename:"recording.".concat(i)})}catch(e){ev("Failed to process audio recording. Please try again."),p(null)}},a.readAsDataURL(r),e.getTracks().forEach(e=>e.stop())},t.start(),y(!0)}catch(e){ev("Failed to start audio recording. Please check microphone permissions.")}};return(0,n.useEffect)(()=>{i&&P&&_(null),i&&U&&q(null)},[i,P]),i.length,(0,a.jsxs)("div",{id:"input-area",className:"flex flex-col gap-2 w-full",children:[P&&(0,a.jsxs)(eM.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(e9.A,{className:"h-4 w-4"}),(0,a.jsxs)(eM.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:P}),(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>_(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(h.A,{className:"h-3 w-3"})})]})]}),U&&(0,a.jsxs)(eM.Fc,{variant:"destructive",className:"mb-2",children:[(0,a.jsx)(e9.A,{className:"h-4 w-4"}),(0,a.jsxs)(eM.TN,{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:U}),(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>q(null),className:"h-auto p-1 ml-2",children:(0,a.jsx)(h.A,{className:"h-3 w-3"})})]})]}),(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsx)("form",{onSubmit:e=>{e.preventDefault(),ew()},children:(0,a.jsxs)(ef,{children:[(m||x)&&(0,a.jsx)("div",{className:"px-4 pt-4",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[m&&(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-1 bg-muted/50 group",children:[(0,a.jsx)("img",{src:"data:".concat(m.mimeType,";base64,").concat(m.base64),alt:"preview",className:"h-12 w-auto rounded-md"}),(0,a.jsx)(N.$,{variant:"destructive",size:"icon",onClick:()=>u(null),className:"absolute -top-1 -right-1 h-4 w-4 rounded-full bg-destructive text-destructive-foreground opacity-100 group-hover:opacity-100 transition-opacity duration-150 shadow-md","aria-label":"Remove image",children:(0,a.jsx)(h.A,{className:"h-2 w-2"})})]}),x&&(0,a.jsxs)("div",{className:"relative w-fit border border-border rounded-lg p-2 bg-muted/50 flex items-center gap-2 group",children:[x.mimeType.startsWith("audio")?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(z.A,{className:"h-4 w-4"}),(0,a.jsx)("audio",{controls:!0,src:"data:".concat(x.mimeType,";base64,").concat(x.base64),className:"h-8"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(B.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"text-xs font-medium max-w-[160px] truncate",children:x.filename||"attachment"})]}),(0,a.jsx)(N.$,{variant:"destructive",size:"icon",onClick:()=>p(null),className:"absolute -top-1 -right-1 h-4 w-4 rounded-full bg-destructive text-destructive-foreground opacity-100 group-hover:opacity-100 transition-opacity duration-150 shadow-md","aria-label":"Remove attachment",children:(0,a.jsx)(h.A,{className:"h-2 w-2"})})]})]})}),(0,a.jsxs)("div",{className:"flex-auto overflow-y-auto relative",children:[j?(0,a.jsx)(ep.A,{ref:d,value:i,onChange:eI,onKeyDown:eC,onPaste:eR,placeholder:"Ask Dexto anything... Type @ for resources, / for prompts, # for memories",minRows:1,maxRows:8,className:"w-full px-4 pt-4 pb-1 text-lg leading-7 placeholder:text-lg bg-transparent border-none resize-none outline-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus:outline-none max-h-full"}):(0,a.jsx)("textarea",{ref:d,rows:1,value:i,onChange:eI,onKeyDown:eC,onPaste:eR,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"}),H&&ee&&eh.createPortal((0,a.jsx)("div",{style:ee,className:"max-h-64 overflow-y-auto rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:(0,a.jsx)(te,{resources:$,query:J,selectedIndex:Z,onHoverIndex:e=>X(e),onSelect:e=>ek(Z,e),loading:V})}),document.body),eS&&eE&&eh.createPortal((0,a.jsx)("div",{style:eE,className:"rounded-md border border-border bg-popover text-popover-foreground shadow-md",children:(0,a.jsxs)("div",{className:"p-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,a.jsx)(F.A,{className:"h-3.5 w-3.5"}),(0,a.jsxs)("span",{children:["Press ",(0,a.jsx)("kbd",{className:"px-1.5 py-0.5 text-xs bg-muted border border-border rounded",children:"Enter"})," to create a memory"]})]})}),document.body)]}),(0,a.jsx)(tn,{isVisible:ei,searchQuery:i,onSelectPrompt:e=>{let t="/".concat(e.name);c(t),el(!1),d.current&&(d.current.focus(),d.current.setSelectionRange(t.length,t.length))},onClose:()=>{el(!1)},onCreatePrompt:ej,refreshKey:ed}),(0,a.jsx)(eg,{leftButtons:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(eO,{onImageAttach:()=>{var e;return null==(e=f.current)?void 0:e.click()},onPdfAttach:()=>{var e;return null==(e=g.current)?void 0:e.click()},onAudioAttach:()=>{var e;return null==(e=v.current)?void 0:e.click()},supports:{image:W.length?W.includes("image"):void 0,pdf:W.length?W.includes("pdf"):void 0,audio:W.length?W.includes("audio"):void 0}}),(0,a.jsx)(eD,{isRecording:b,onToggleRecording:b?()=>{var e;null==(e=w.current)||e.stop(),y(!1)}:eF,disabled:!W.includes("audio")})]}),rightButtons:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ey,{isStreaming:S,onStreamingChange:A}),(0,a.jsx)(e6,{}),(0,a.jsx)(N.$,{type:T?"button":"submit",onClick:T?()=>E(k||void 0):void 0,disabled:!T&&(!i.trim()&&!m&&!x||s),className:(0,o.cn)("h-10 w-10 p-0 rounded-full transition-all duration-200",T?"bg-secondary/80 text-secondary-foreground hover:bg-secondary shadow-sm hover:shadow-md border border-border/50":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-lg"),"aria-label":T?"Stop":"Send message",title:T?"Stop":"Send",children:T?(0,a.jsx)(C.A,{className:"h-3.5 w-3.5 fill-current"}):s?(0,a.jsx)(M.A,{className:"h-4 w-4 animate-spin"}):(0,a.jsx)(e7.A,{className:"h-4 w-4"})})]})})]})}),(0,a.jsx)("input",{ref:f,type:"file",id:"image-upload",accept:"image/*",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("Image file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("image/")){ev("Please select a valid image file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(",");if(-1===t)throw Error("Invalid Data URL format");let a=e.substring(0,t),n=e.substring(t+1),i=a.match(/data:(.*);base64/),l=i?i[1]:s.type;if(!l)throw Error("Could not determine MIME type");u({base64:n,mimeType:l}),q(null)}catch(e){ev("Failed to process image file. Please try again."),u(null)}},r.onerror=e=>{ev("Failed to read image file. Please try again."),u(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:g,type:"file",id:"pdf-upload",accept:"application/pdf",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("PDF file too large. Maximum size is 64MB."),e.target.value="";return}if("application/pdf"!==s.type){ev("Please select a valid PDF file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(","),a=e.substring(t+1);p({base64:a,mimeType:"application/pdf",filename:s.name}),q(null)}catch(e){ev("Failed to process PDF file. Please try again."),p(null)}},r.onerror=e=>{ev("Failed to read PDF file. Please try again."),p(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)("input",{ref:v,type:"file",id:"audio-upload",accept:"audio/*",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>0x4000000){ev("Audio file too large. Maximum size is 64MB."),e.target.value="";return}if(!s.type.startsWith("audio/")){ev("Please select a valid audio file."),e.target.value="";return}let r=new FileReader;r.onloadend=()=>{try{let e=r.result,t=e.indexOf(","),a=e.substring(t+1);p({base64:a,mimeType:s.type,filename:s.name}),q(null)}catch(e){ev("Failed to process audio file. Please try again."),p(null)}},r.onerror=e=>{ev("Failed to read audio file. Please try again."),p(null)},r.readAsDataURL(s),e.target.value=""}}),(0,a.jsx)(td,{open:eo,onClose:eN,onCreated:eb}),(0,a.jsx)(tm,{open:eu,onClose:()=>ex(!1),onSuccess:()=>{}})]})]})}var tx=s(3504);let th=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"]}]');class tp{static normalizeId(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}static getInstance(){return tp.instance||(tp.instance=new tp),tp.instance}async initialize(){this.isInitialized||(this.registryEntries=this.getBuiltinEntries(),this.isInitialized=!0)}async getEntries(e){var t;await this.initialize();let s=[...this.registryEntries];if((null==e?void 0:e.category)&&(s=s.filter(t=>t.category===e.category)),(null==e||null==(t=e.tags)?void 0:t.length)&&(s=s.filter(t=>e.tags.some(e=>t.tags.includes(e)))),null==e?void 0:e.search){let t=e.search.toLowerCase();s=s.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.tags.some(e=>e.toLowerCase().includes(t)))}return(null==e?void 0:e.installed)!==void 0&&(s=s.filter(t=>t.isInstalled===e.installed)),(null==e?void 0:e.official)!==void 0&&(s=s.filter(t=>t.isOfficial===e.official)),s.sort((e,t)=>e.isInstalled!==t.isInstalled?e.isInstalled?-1:1:e.isOfficial!==t.isOfficial?e.isOfficial?-1:1:e.name.localeCompare(t.name))}async updateEntry(e,t){let s=this.registryEntries.findIndex(t=>t.id===e);return -1!==s&&(this.registryEntries[s]={...this.registryEntries[s],...t},!0)}async setInstalled(e,t){return this.updateEntry(e,{isInstalled:t})}async syncWithServerStatus(){try{if(await this.initialize(),0===this.registryEntries.length)return void console.warn("Registry entries not available for status sync");let e=new AbortController,t=setTimeout(()=>e.abort(),1e4),s=await fetch("/api/mcp/servers",{signal:e.signal});if(clearTimeout(t),!s.ok)return;let r=(await s.json()).servers||[],a=new Set;for(let e of(r.forEach(e=>{if(!(null==e?void 0:e.id)||"string"!=typeof e.id)return;let t=tp.normalizeId(e.id);a.add(t)}),this.registryEntries)){let t=[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>tp.normalizeId(String(e))).some(e=>a.has(e));e.isInstalled!==t&&(e.isInstalled=t)}}catch(e){console.warn("Failed to sync registry with server status:",e)}}async getServerConfig(e){return await this.initialize(),this.registryEntries.find(t=>t.id===e)||null}getBuiltinEntries(){return th}constructor(){this.registryEntries=[],this.isInitialized=!1}}let tf=tp.getInstance();function tg(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card",className:(0,o.cn)("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",t),...s})}function tv(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-header",className:(0,o.cn)("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",t),...s})}function tj(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-title",className:(0,o.cn)("leading-none font-semibold",t),...s})}function tb(e){let{className:t,...s}=e;return(0,a.jsx)("div",{"data-slot":"card-content",className:(0,o.cn)("px-6",t),...s})}var ty=s(7091),tN=s(2171),tw=s(8177),tk=s(1756),tC=s(976),tS=s(5582),tA=s(5160);function tE(e){let{isOpen:t,onClose:s,onInstallServer:r,onOpenConnectModal:i,refreshTrigger:l,disableClose:c=!1}=e,[d,m]=(0,n.useState)([]),[p,f]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1),[j,b]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[k,C]=(0,n.useState)({}),[S,A]=(0,n.useState)(""),[E,T]=(0,n.useState)("grid"),[I,O]=(0,n.useState)(null),L=(0,n.useRef)(null),R=(0,n.useRef)(!0),D=(0,n.useRef)(null);(0,n.useEffect)(()=>(R.current=!0,()=>{R.current=!1,L.current&&clearTimeout(L.current),D.current&&D.current.abort()}),[]),(0,n.useEffect)(()=>{t&&(async()=>{D.current&&D.current.abort();let e=new AbortController;if(D.current=e,R.current){v(!0),b(null);try{await tf.syncWithServerStatus();let t=await tf.getEntries();R.current&&!e.signal.aborted&&(m(t),f(t))}catch(t){R.current&&!e.signal.aborted&&b(t instanceof Error?t.message:"Failed to load server registry")}finally{R.current&&!e.signal.aborted&&v(!1)}}})()},[t,l]);let F=(0,n.useCallback)(async(e,t)=>{if(R.current)try{let s=await tf.getEntries({...e,search:t||void 0});R.current&&f(s)}catch(e){R.current&&b(e instanceof Error?e.message:"Failed to filter entries")}},[]);(0,n.useEffect)(()=>(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{F(k,S)},300),()=>{L.current&&clearTimeout(L.current)}),[k,S,d,F]);let P=async e=>{if(R.current){w(e.id);try{let t=await r(e);"connected"===t?(await tf.setInstalled(e.id,!0),R.current&&(m(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)),f(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!0}:t)))):R.current&&(m(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)),f(t=>t.map(t=>t.id===e.id?{...t,isInstalled:!1}:t)))}catch(e){R.current&&b(e instanceof Error?e.message:"Failed to install server")}finally{R.current&&w(null)}}},M=c||!!y,z=(0,n.useCallback)(e=>{e||M||s()},[M,s]),U=M?e=>{e.preventDefault()}:void 0;return(0,a.jsx)(eP.lG,{open:t,onOpenChange:z,children:(0,a.jsxs)(eP.Cf,{className:"!max-w-none w-[90vw] max-h-[85vh] overflow-hidden flex flex-col !sm:max-w-none p-0",hideCloseButton:!0,onEscapeKeyDown:M?e=>e.preventDefault():void 0,onInteractOutside:U,children:[(0,a.jsx)(eP.c7,{className:"pb-6 border-b px-6 pt-6",children:(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("div",{className:"p-2 rounded-lg bg-primary/10 border border-primary/20 flex-shrink-0",children:(0,a.jsx)(ty.A,{className:"h-5 w-5 text-primary"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(eP.L3,{className:"text-xl font-semibold leading-tight mb-1.5",children:"MCP Server Registry"}),(0,a.jsx)(eP.rr,{className:"text-sm text-muted-foreground leading-relaxed",children:"Discover and add powerful integrations to your AI assistant"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(N.$,{onClick:()=>{M||s(),null==i||i()},size:"sm",variant:"outline",className:"h-9 px-3 text-sm font-medium border-2 hover:bg-primary/10 hover:text-primary hover:border-primary/30 whitespace-nowrap",children:[(0,a.jsx)(tN.A,{className:"mr-2 h-4 w-4"}),"Connect Custom"]}),(0,a.jsxs)(N.$,{variant:"ghost",size:"icon",className:"h-9 w-9",onClick:()=>s(),disabled:M,children:[(0,a.jsx)(h.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}),(0,a.jsxs)("div",{className:"flex gap-3 mb-6 px-6 pt-6",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(eK.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none z-10"}),(0,a.jsx)(eU.p,{placeholder:"Search servers, integrations, and capabilities...",value:S,onChange:e=>A(e.target.value),className:"pl-10 h-10 border-border/40 focus:border-primary/50 bg-background shadow-sm"})]}),(0,a.jsxs)("div",{className:"flex bg-muted/80 rounded-lg p-1 border border-border/40",children:[(0,a.jsxs)(N.$,{variant:"grid"===E?"secondary":"ghost",size:"sm",onClick:()=>{T("grid"),O(null)},className:(0,o.cn)("h-8 px-3 rounded-md transition-all","grid"===E?"bg-background shadow-sm":"hover:bg-background/80"),children:[(0,a.jsx)(tw.A,{className:"h-4 w-4 mr-2"}),"Grid"]}),(0,a.jsxs)(N.$,{variant:"list"===E?"secondary":"ghost",size:"sm",onClick:()=>{T("list"),O(null)},className:(0,o.cn)("h-8 px-3 rounded-md transition-all","list"===E?"bg-background shadow-sm":"hover:bg-background/80"),children:[(0,a.jsx)(tk.A,{className:"h-4 w-4 mr-2"}),"List"]})]})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-6",children:[j&&(0,a.jsx)(eM.Fc,{variant:"destructive",className:"mb-6 border-red-200/50 bg-red-50/50",children:(0,a.jsx)(eM.TN,{className:"text-red-800",children:j})}),g?(0,a.jsx)("div",{className:"flex items-center justify-center py-20",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,a.jsx)("div",{className:"h-10 w-10 border-3 border-primary/20 border-t-primary rounded-full animate-spin"}),(0,a.jsx)("div",{className:"text-base text-muted-foreground font-medium",children:"Discovering servers..."}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground/70",children:"Loading registry entries"})]})}):0===p.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[(0,a.jsx)("div",{className:"p-4 rounded-2xl bg-muted/30 border border-border/20 mb-6",children:(0,a.jsx)(ty.A,{className:"h-12 w-12 text-muted-foreground/60 mx-auto"})}),(0,a.jsx)("div",{className:"text-lg font-medium text-muted-foreground mb-2",children:0===d.length?"No servers available in the registry":"No servers match your search"}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground/70 mb-4",children:0===d.length?"The registry is currently empty or failed to load":"Try adjusting your search terms or browse all categories"}),S&&(0,a.jsxs)(N.$,{variant:"outline",onClick:()=>A(""),className:"border-primary/20 hover:bg-primary/5",children:[(0,a.jsx)(eK.A,{className:"h-4 w-4 mr-2"}),"Clear search"]})]}):(0,a.jsx)("div",{className:(0,o.cn)("grid"===E?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4":"space-y-3"),children:p.map((e,t)=>{let s=I===e.id,r=e.description&&e.description.length>100;return"grid"===E?(0,a.jsx)(tg,{className:(0,o.cn)("group relative overflow-hidden transition-all duration-300 border-border/30 hover:border-primary/30 hover:shadow-lg bg-gradient-to-b from-card/90 to-card/50 backdrop-blur-sm flex flex-col",s&&"ring-2 ring-primary/20 border-primary/50 shadow-xl"),style:{animationDelay:"".concat(Math.min(30*t,300),"ms")},children:(0,a.jsxs)("div",{className:"cursor-pointer flex flex-col flex-1",onClick:()=>O(s?null:e.id),children:[(0,a.jsx)(tv,{className:"pb-4 flex-shrink-0",children:(0,a.jsx)("div",{className:"flex items-start justify-between",children:(0,a.jsxs)("div",{className:"flex items-center gap-4 flex-1",children:[(0,a.jsx)("div",{className:"text-3xl p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 border border-primary/20 group-hover:border-primary/30 transition-all",children:e.icon||"⚡"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)(tj,{className:"text-base font-semibold mb-2 group-hover:text-primary transition-colors leading-tight",children:e.name}),(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[e.isOfficial&&(0,a.jsxs)(eV.E,{className:"text-xs px-2 py-1 bg-blue-100 text-blue-700 border-blue-200",children:[(0,a.jsx)(eW.A,{className:"h-3 w-3 mr-1"}),"Official"]}),e.isInstalled&&(0,a.jsxs)(eV.E,{className:"text-xs px-2 py-1 bg-green-100 text-green-700 border-green-200",children:[(0,a.jsx)(_.A,{className:"h-3 w-3 mr-1"}),"Connected"]}),e.category&&(0,a.jsx)(eV.E,{variant:"outline",className:(0,o.cn)("text-xs px-2 py-1",(e=>{let t={productivity:"bg-blue-100 text-blue-800",development:"bg-green-100 text-green-800",research:"bg-purple-100 text-purple-800",creative:"bg-pink-100 text-pink-800",data:"bg-orange-100 text-orange-800",communication:"bg-indigo-100 text-indigo-800",custom:"bg-gray-100 text-gray-800"};return t[e]||t.custom})(e.category)),children:e.category})]})]})]})})}),(0,a.jsxs)(tb,{className:"pt-0 flex flex-col flex-1",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:(0,o.cn)("text-sm text-muted-foreground leading-relaxed mb-4 transition-all duration-300",s?"":"line-clamp-2"),children:e.description}),s&&(0,a.jsxs)("div",{className:"space-y-4 pt-4 border-t border-border/20 animate-in slide-in-from-top-1 duration-300",children:[(0,a.jsx)("div",{className:"grid grid-cols-2 gap-3 text-xs",children:e.author&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"p-1 rounded bg-muted/50",children:(0,a.jsx)(tC.A,{className:"h-3 w-3 text-muted-foreground"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-medium text-foreground",children:"Author"}),(0,a.jsx)("div",{className:"text-muted-foreground",children:e.author})]})]})}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs font-medium text-foreground mb-2",children:"Tags"}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.tags.slice(0,8).map(e=>(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-background/50",children:e},e)),e.tags.length>8&&(0,a.jsxs)(eV.E,{variant:"outline",className:"text-xs px-2 py-0.5 text-muted-foreground border-border/40 bg-background/50",children:["+",e.tags.length-8]})]})]}),e.homepage&&(0,a.jsx)("div",{className:"pt-2",children:(0,a.jsxs)("a",{href:e.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-primary hover:text-primary/80 transition-colors font-medium",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(tS.A,{className:"h-4 w-4"}),"View Documentation"]})})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between pt-4 flex-shrink-0",children:[r&&(0,a.jsx)(N.$,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground hover:text-primary p-0 h-auto",children:s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(u.A,{className:"h-3 w-3 mr-1"}),"Show less"]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(x.A,{className:"h-3 w-3 mr-1"}),"Show more"]})}),(0,a.jsx)("div",{className:"ml-auto",children:(0,a.jsx)(N.$,{onClick:t=>{t.stopPropagation(),P(e)},disabled:e.isInstalled||y===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,o.cn)("min-w-[75px] transition-all font-medium",y===e.id&&"opacity-70",!e.isInstalled&&"bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary shadow-md hover:shadow-lg"),children:y===e.id?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"Connecting"})]}):e.isInstalled?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(_.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Connected"})]}):(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ts.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Connect"})]})})})]})]})]})},e.id):(0,a.jsx)(tg,{className:(0,o.cn)("group transition-all duration-200 border-border/30 hover:border-primary/20 hover:shadow-md bg-card/50 hover:bg-card/80 cursor-pointer !py-0 !gap-0",s&&"border-primary/30 shadow-lg bg-card/90",r&&"hover:bg-card/85"),onClick:()=>O(s?null:e.id),children:(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)("div",{className:"flex items-start gap-4",children:[(0,a.jsx)("div",{className:"flex-shrink-0 w-10 h-10 rounded-xl bg-gradient-to-br from-primary/10 via-primary/5 to-transparent border border-primary/15 flex items-center justify-center text-lg font-medium",children:e.icon||"⚡"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0 space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,a.jsx)("h3",{className:"text-base font-medium text-foreground group-hover:text-primary transition-colors leading-tight",children:e.name}),r&&(0,a.jsx)(x.A,{className:(0,o.cn)("h-4 w-4 text-muted-foreground/60 transition-all duration-200 flex-shrink-0",s&&"rotate-180 text-muted-foreground")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.isOfficial&&(0,a.jsxs)(eV.E,{className:"text-xs font-medium px-2 py-0.5 bg-blue-50 text-blue-600 border-blue-100 hover:bg-blue-100",children:[(0,a.jsx)(eW.A,{className:"h-2.5 w-2.5 mr-1 fill-current"}),"Official"]}),e.isInstalled&&(0,a.jsxs)(eV.E,{className:"text-xs font-medium px-2 py-0.5 bg-green-50 text-green-600 border-green-100",children:[(0,a.jsx)(_.A,{className:"h-2.5 w-2.5 mr-1"}),"Connected"]}),(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs font-medium px-2 py-0.5 bg-background/50 text-muted-foreground border-border/40 capitalize",children:e.category})]})]}),(0,a.jsx)(N.$,{onClick:t=>{t.stopPropagation(),P(e)},disabled:e.isInstalled||y===e.id,size:"sm",variant:e.isInstalled?"outline":"default",className:(0,o.cn)("min-w-[80px] h-8 text-xs font-medium transition-all",y===e.id&&"opacity-70",!e.isInstalled&&"bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary shadow-sm hover:shadow-md"),children:y===e.id?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("div",{className:"h-3 w-3 border-2 border-current border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"Connecting..."})]}):e.isInstalled?(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(_.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Connected"})]}):(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(ts.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:"Connect"})]})})]}),(0,a.jsx)("div",{children:(0,a.jsx)("p",{className:(0,o.cn)("text-sm text-muted-foreground leading-relaxed transition-all duration-300",s?"":"line-clamp-2"),children:e.description})}),s&&(0,a.jsxs)("div",{className:"space-y-4 pt-4 border-t border-border/10 animate-in slide-in-from-top-2 duration-300",children:[e.author&&(0,a.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted/20 border border-border/10",children:[(0,a.jsx)("div",{className:"p-2 rounded-lg bg-primary/10",children:(0,a.jsx)(tC.A,{className:"h-4 w-4 text-primary"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Author"}),(0,a.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.author})]})]}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[(0,a.jsx)(tA.A,{className:"h-4 w-4 text-primary"}),"Tags"]}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:e.tags.map(e=>(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-3 py-1 text-muted-foreground border-border/40 bg-background/60 hover:bg-background/80 transition-colors",children:e},e))})]}),e.homepage&&(0,a.jsx)("div",{className:"pt-2",children:(0,a.jsxs)("a",{href:e.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-primary hover:text-primary/80 transition-colors font-medium px-4 py-2 rounded-lg border border-primary/20 hover:border-primary/40 bg-primary/5 hover:bg-primary/10",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(tS.A,{className:"h-4 w-4"}),"View Documentation"]})})]})]})]})})},e.id)})})]})]})})}var tT=s(7620),tI=s(5320),tO=s(5618);let tL=new Set(["placeholder","your-api-key","your_api_key","enter-your-token","xxx","...","todo"]),tR=["your-","your_","your ","enter-","enter_","enter ","placeholder","api_key","api-key","api key","secret","token","password","xxx","..."],tD=[/^your[\s_-]?/,/^enter[\s_-]?/];function tF(e){return Object.values(e).some(e=>{if(!e||""===e.trim())return!0;let t=e.trim().toLowerCase();return!!(tL.has(t)||tD.some(e=>e.test(t)))||tR.some(e=>t.includes(e))})}function tP(e){var t,s,r,a,n,i,l,o;let c=null!=(t=e.config.timeout)?t:3e4;switch(e.config.type){case"stdio":return{type:"stdio",command:null!=(s=e.config.command)?s:"",args:null!=(r=e.config.args)?r:[],env:null!=(a=e.config.env)?a:{},timeout:c,connectionMode:"lenient"};case"sse":return{type:"sse",url:null!=(n=e.config.url)?n:"",headers:null!=(i=e.config.headers)?i:{},timeout:c,connectionMode:"lenient"};default:return{type:"http",url:null!=(l=e.config.url)?l:"",headers:null!=(o=e.config.headers)?o:{},timeout:c,connectionMode:"lenient"}}}let t_="/api";function tM(e){let{isOpen:t,onClose:s,onOpenConnectModal:r,onOpenConnectWithPrefill:i,onServerConnected:l,variant:c="overlay",refreshTrigger:d}=e,[u,p]=(0,n.useState)([]),[f,g]=(0,n.useState)(null),[v,j]=(0,n.useState)([]),[b,y]=(0,n.useState)(!1),[w,k]=(0,n.useState)(!1),[C,S]=(0,n.useState)(null),[A,E]=(0,n.useState)(null),[T,I]=(0,n.useState)(!1),[O,L]=(0,n.useState)(null),[R,D]=(0,n.useState)(!1),[F,P]=(0,n.useState)(!1),_=(e,t)=>{console.error("ServersPanel Error (".concat(t,"):"),e),"servers"===t&&S(e),"tools"===t&&E(e)},M=(0,n.useCallback)(async e=>{y(!0),S(null),p([]),g(null),j([]),E(null);try{let t=await fetch("".concat(t_,"/mcp/servers"),e?{signal:e}:{});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to fetch servers"}));throw Error(e.message||e.error||"Server List: ".concat(t.statusText))}let s=(await t.json()).servers||[];if(p(s),s.length>0){let e=s.find(e=>"connected"===e.status);e?g(e.id):s.length>0&&g(s[0].id)}else console.log("No MCP servers found or returned from API.")}catch(e){"AbortError"!==e.name&&_(e.message,"servers")}finally{(null==e?void 0:e.aborted)||y(!1)}},[]),z=async e=>{let t=tP(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tF(t.env||{}),r=("sse"===t.type||"http"===t.type)&&Object.keys(t.headers||{}).length>0&&tF(t.headers||{});if(s||r)return"function"==typeof i&&i({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:()=>D(!1)}),"requires-input";try{P(!0);let s=await fetch("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,config:t,persistToAgent:!1})}),r=await s.json();if(!s.ok)throw Error(r.error||"Server returned status ".concat(s.status));await M();try{await tf.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry after server install:",e)}return D(!1),null==l||l(e.name),"connected"}catch(e){throw Error(e.message||"Failed to install server")}finally{P(!1)}},U=async e=>{let t=u.find(t=>t.id===e);if(t&&window.confirm('Are you sure you want to remove server "'.concat(t.name,'"?'))){L(e),S(null);try{let t=await fetch("".concat(t_,"/mcp/servers/").concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json().catch(()=>({error:"Failed to remove server"}));throw Error(e.message||e.error||"Server Removal: ".concat(t.statusText))}f===e&&(g(null),j([]));try{let t=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-"),s=t(e),r=(await tf.getEntries()).find(e=>[e.id,e.name,...e.matchIds||[]].filter(Boolean).map(e=>t(String(e))).includes(s));r&&await tf.setInstalled(r.id,!1)}catch(e){console.warn("Failed to update registry installed state on delete:",e)}await M(),(0,tr.w)();try{await tf.syncWithServerStatus()}catch(e){console.warn("Failed to sync registry status after server deletion:",e)}}catch(e){_(e.message,"servers")}finally{L(null)}}};(0,n.useEffect)(()=>{if(!t)return;let e=new AbortController;return M(e.signal),L(null),()=>{e.abort()}},[t,M]),(0,n.useEffect)(()=>{if(d&&t){let e=new AbortController;return M(e.signal),()=>{e.abort()}}},[d,t,M]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{console.log("\uD83D\uDD17 Server connected:",(null==e?void 0:e.detail)||{}),M()},s=e=>{let t=(null==e?void 0:e.detail)||{};if(console.log("\uD83D\uDCBE Resource cache invalidated for server panel:",t),f&&t.serverName){let e=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-");e(f)===e(t.serverName)&&B(f)}};return window.addEventListener("dexto:mcpServerConnected",e),window.addEventListener("dexto:resourceCacheInvalidated",s),()=>{window.removeEventListener("dexto:mcpServerConnected",e),window.removeEventListener("dexto:resourceCacheInvalidated",s)}},[t,M,f]);let B=(0,n.useCallback)(async(e,t)=>{let s=u.find(t=>t.id===e);if(j([]),E(null),!s||"connected"!==s.status)return void console.warn('Server "'.concat((null==s?void 0:s.name)||e,'" is not connected or not found. Cannot fetch tools.'));k(!0);try{let r=await fetch("".concat(t_,"/mcp/servers/").concat(e,"/tools"),t?{signal:t}:{});if(!r.ok){let e=await r.json().catch(()=>({error:"Failed to fetch tools for ".concat(s.name)}));throw Error(e.message||e.error||"Tool List (".concat(s.name,"): ").concat(r.statusText))}let a=await r.json();(null==t?void 0:t.aborted)||j(a.tools||[]),a.tools&&0!==a.tools.length||console.log('No tools found for server "'.concat(s.name,'".'))}catch(e){"AbortError"!==e.name&&_(e.message,"tools")}finally{(null==t?void 0:t.aborted)||k(!1)}},[u]);(0,n.useEffect)(()=>{if(!f)return;let e=new AbortController;return B(f,e.signal),()=>{e.abort()}},[f,B]);let q=u.find(e=>e.id===f);if("overlay"===c&&!t)return null;let W=(0,o.cn)("fixed top-0 right-0 z-40 h-screen w-80 bg-card border-l border-border shadow-xl transition-transform transform flex flex-col",t?"translate-x-0":"translate-x-full"),K=(0,o.cn)("h-full w-full flex flex-col bg-card");return(0,a.jsxs)("aside",{className:"overlay"===c?W:K,children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border/50 bg-card/50 backdrop-blur-sm",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Tools & Servers"}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>M(),disabled:b,className:"h-8 w-8 p-0",children:(0,a.jsx)(tT.A,{className:(0,o.cn)("h-3.5 w-3.5",b&&"animate-spin")})}),"overlay"===c&&(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:(0,a.jsx)(h.A,{className:"h-3.5 w-3.5"})})]})]}),(0,a.jsx)("div",{className:"px-4 py-3 space-y-2 border-b border-border/30",children:(0,a.jsxs)(N.$,{onClick:()=>D(!0),className:"w-full h-9 text-sm font-medium",size:"sm",children:[(0,a.jsx)(tI.A,{className:"mr-2 h-4 w-4"}),"Connect MCPs"]})}),(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsxs)("div",{className:"p-4 border-b border-border/30",children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,a.jsxs)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Connected Servers (",u.length,")"]})}),b&&(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tT.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading servers..."})]})}),C&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Connection Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:C})]})]})}),!b&&0===u.length&&!C&&(0,a.jsxs)("div",{className:"text-center py-8",children:[(0,a.jsx)(ty.A,{className:"h-8 w-8 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No servers connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Connect or browse the registry"})]}),u.map(e=>(0,a.jsx)("div",{onClick:()=>g(e.id),className:(0,o.cn)("p-3 rounded-lg border cursor-pointer transition-all duration-200 mb-2 last:mb-0",f===e.id?"bg-primary/5 border-primary/20 shadow-sm":"bg-background hover:bg-muted/50 border-border/50 hover:border-border"),children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:(0,o.cn)("w-2 h-2 rounded-full flex-shrink-0","connected"===e.status?"bg-green-500":"error"===e.status?"bg-red-500":"bg-yellow-500")}),(0,a.jsx)("h4",{className:"text-sm font-medium truncate",children:e.name})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1 capitalize",children:e.status})]}),O===e.id?(0,a.jsx)(tT.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}):(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),U(e.id)},className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",children:(0,a.jsx)(to.A,{className:"h-3.5 w-3.5"})})]})},e.id))]}),q&&(0,a.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,a.jsx)("div",{className:"px-4 py-3 border-b border-border/30",children:(0,a.jsxs)("button",{onClick:()=>I(!T),className:"flex items-center justify-between w-full text-left",children:[(0,a.jsx)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Available Tools"}),(0,a.jsx)(x.A,{className:(0,o.cn)("h-3.5 w-3.5 transition-transform text-muted-foreground",T&&"rotate-180")})]})}),T&&(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[w&&(0,a.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsx)(tT.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading tools..."})]})}),A&&(0,a.jsx)("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 mb-3",children:(0,a.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,a.jsx)(m.A,{className:"h-4 w-4 text-destructive flex-shrink-0 mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-destructive",children:"Tools Error"}),(0,a.jsx)("p",{className:"text-xs text-destructive/80 mt-1",children:A})]})]})}),!w&&0===v.length&&!A&&"connected"===q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(tO.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"No tools available"})]}),"connected"!==q.status&&(0,a.jsxs)("div",{className:"text-center py-6",children:[(0,a.jsx)(m.A,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Server not connected"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground/70 mt-1",children:"Tools unavailable"})]}),v.map(e=>{var t;return(0,a.jsxs)("div",{className:"p-3 rounded-lg border border-border/50 bg-background hover:bg-muted/30 transition-colors mb-2 last:mb-0",children:[(0,a.jsx)("h4",{className:"text-sm font-medium mb-1",children:e.name}),e.description&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2 mb-2",children:e.description}),(null==(t=e.inputSchema)?void 0:t.properties)&&(0,a.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[Object.keys(e.inputSchema.properties).slice(0,3).map(e=>(0,a.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-muted text-xs font-medium",children:e},e)),Object.keys(e.inputSchema.properties).length>3&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",Object.keys(e.inputSchema.properties).length-3," more"]})]})]},e.name)})]})]})]}),(0,a.jsx)(tE,{isOpen:R,onClose:()=>D(!1),onInstallServer:z,onOpenConnectModal:r,disableClose:F})]})}let tz=n.forwardRef((e,t)=>{let{className:s,children:r,...n}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("relative overflow-auto",s),...n,children:r})});tz.displayName="ScrollArea";var tU=s(2848);let tB=function(e){let{onClick:t,className:s,variant:r="outline",side:n="bottom"}=e;return(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:r,size:"sm",onClick:t,className:["h-8 w-8 p-0",s].filter(Boolean).join(" "),"aria-label":"New chat",children:(0,a.jsx)(ts.A,{className:"h-4 w-4"})})}),(0,a.jsx)(y,{side:n,children:"New Chat (⌘K)"})]})})};function tq(e){let{isOpen:t,onClose:s,currentSessionId:r,onSessionChange:i,returnToWelcome:l,variant:o="modal",onSearchOpen:c,onNewChat:d}=e,[u,x]=(0,n.useState)([]),[h,p]=(0,n.useState)(!1),[f,g]=(0,n.useState)(null),[w,k]=(0,n.useState)(!1),[C,S]=(0,n.useState)(""),[A,E]=(0,n.useState)(null),T=n.useRef(!1),I=n.useRef(0),O=n.useRef(null),[L,R]=(0,n.useState)(!1),[D,F]=(0,n.useState)(null),[P,_]=(0,n.useState)(!1),M=(0,n.useCallback)(async()=>{if(T.current)return;I.current+=1;let e=I.current;p(!0),g(null);try{let t,s=await fetch("/api/sessions");if(!s.ok)throw Error("Failed to fetch sessions");let r=await s.text();if(e!==I.current)return;if(!r.trim())return void x([]);try{t=JSON.parse(r)}catch(e){console.error("Failed to parse sessions response:",e),g("Failed to parse sessions data");return}let a=(t.sessions||[]).sort((e,t)=>{let s=e.lastActivity?new Date(e.lastActivity).getTime():0;return(t.lastActivity?new Date(t.lastActivity).getTime():0)-s});e===I.current&&x(a)}catch(t){e===I.current&&(console.error("Error fetching sessions:",t),g(t instanceof Error?t.message:"Failed to fetch sessions"))}finally{e===I.current&&p(!1)}},[]);(0,n.useEffect)(()=>{t&&M()},[t,M]);let z=(0,n.useCallback)(()=>{O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{M()},500)},[M]);(0,n.useEffect)(()=>{let e=e=>{z()},t=e=>{z()},s=e=>{M()};return window.addEventListener("dexto:message",e),window.addEventListener("dexto:response",t),window.addEventListener("dexto:sessionTitleUpdated",s),()=>{window.removeEventListener("dexto:message",e),window.removeEventListener("dexto:response",t),window.removeEventListener("dexto:sessionTitleUpdated",s),O.current&&clearTimeout(O.current)}},[M,z]);let U=async()=>{try{let e,t=await fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:C.trim()||void 0})});if(!t.ok){let e,s=await t.text();try{e=s?JSON.parse(s):{}}catch(t){e={error:"Failed to create session"}}throw Error(e.error||"Failed to create session")}let s=await t.text();if(!s.trim())throw Error("Empty response from session creation");try{e=JSON.parse(s)}catch(e){throw console.error("Failed to parse session creation response:",e),Error("Invalid response from session creation")}x(t=>[...t,e.session]),S(""),k(!1),i(e.session.id)}catch(e){console.error("Error creating session:",e),g(e instanceof Error?e.message:"Failed to create session")}},B=async e=>{let t=r===e;T.current=!0,E(e);try{let s=await fetch("/api/sessions/".concat(e),{method:"DELETE"});if(!s.ok){let e,t=await s.text();try{e=t?JSON.parse(t):{}}catch(t){e={error:"Failed to delete session"}}throw Error(e.error||"Failed to delete session")}x(t=>t.filter(t=>t.id!==e)),t&&l(),await new Promise(e=>setTimeout(e,100))}catch(e){console.error("Error deleting session:",e),g(e instanceof Error?e.message:"Failed to delete session")}finally{T.current=!1,E(null)}},q=async()=>{if(!D)return;let e=r===D;T.current=!0,_(!0);try{if(!(await fetch("/api/sessions/".concat(D),{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok)throw Error("Failed to delete conversation");x(e=>e.filter(e=>e.id!==D)),e&&l(),R(!1),F(null),await new Promise(e=>setTimeout(e,100))}catch(e){console.error("Error deleting conversation:",e),g(e instanceof Error?e.message:"Failed to delete conversation")}finally{T.current=!1,_(!1)}},W=(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:[(0,a.jsx)("div",{className:"flex items-center space-x-2",children:(0,a.jsx)("h2",{className:"text-base font-semibold",children:"Chat History"})}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[c&&(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"outline",size:"sm",onClick:c,className:"h-7 w-7 p-0","aria-label":"Search conversations",children:(0,a.jsx)(eK.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(y,{children:"Search conversations (⌘⇧S)"})]})}),d&&(0,a.jsx)(tB,{onClick:d,variant:"outline"})]})]}),f&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eM.Fc,{variant:"destructive",children:[(0,a.jsx)(m.A,{className:"h-4 w-4"}),(0,a.jsx)(eM.TN,{children:f})]})}),(0,a.jsx)(tz,{className:"flex-1",children:h?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tT.A,{className:"h-6 w-6 animate-spin"})}):0===u.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground px-4",children:[(0,a.jsx)(tU.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,a.jsx)("p",{children:"No chat history"}),(0,a.jsx)("p",{className:"text-sm",children:"Start a conversation to see it here"})]}):(0,a.jsx)("div",{className:"px-3 py-2 space-y-0.5",children:(0,a.jsx)(v,{children:u.map(e=>{let t=e.title&&e.title.trim().length>0?e.title:e.id,s=r===e.id;return(0,a.jsxs)(j,{delayDuration:150,children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{className:s?"group relative px-3 py-3 rounded-lg bg-muted/40 hover:bg-muted/60 transition-colors cursor-pointer":"group relative px-3 py-2.5 rounded-lg hover:bg-muted/30 transition-colors cursor-pointer",role:"button",tabIndex:0,"aria-current":s?"page":void 0,onClick:()=>i(e.id),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),i(e.id))},children:(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("div",{className:"flex items-center gap-2.5 flex-1 min-w-0",children:(0,a.jsx)("h3",{className:s?"font-semibold text-sm truncate":"font-normal text-sm truncate text-muted-foreground",children:t})}),(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:(e=>{if(!e)return"Unknown";let t=new Date(e),s=new Date().getTime()-t.getTime(),r=Math.floor(s/6e4),a=Math.floor(s/36e5),n=Math.floor(s/864e5);return r<1?"Just now":r<60?"".concat(r,"m ago"):a<24?"".concat(a,"h ago"):"".concat(n,"d ago")})(e.lastActivity)}),(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),e.messageCount>0?(F(e.id),R(!0)):B(e.id)},disabled:A===e.id,className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity","aria-label":e.messageCount>0?"Delete conversation":"Delete chat",title:"Delete",children:(0,a.jsx)(to.A,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-destructive"})})]})]})})}),(0,a.jsx)(y,{side:"right",align:"center",children:(0,a.jsxs)("div",{className:"text-xs space-y-1",children:[(0,a.jsx)("div",{className:"font-mono",children:e.id}),(0,a.jsxs)("div",{className:"text-muted-foreground",children:[e.messageCount," messages"]})]})})]},e.id)})})})}),(0,a.jsx)(eP.lG,{open:w,onOpenChange:k,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eP.c7,{children:(0,a.jsx)(eP.L3,{children:"Start New Chat"})}),(0,a.jsx)("div",{className:"space-y-4",children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"sessionId",children:"Chat ID"}),(0,a.jsx)(eU.p,{id:"sessionId",value:C,onChange:e=>S(e.target.value),placeholder:"e.g., user-123, project-alpha",className:"font-mono"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Leave empty to auto-generate a unique ID"})]})}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),(0,a.jsx)(N.$,{onClick:U,children:"Start Chat"})]})]})}),(0,a.jsx)(eP.lG,{open:L,onOpenChange:R,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsxs)(eP.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eP.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",D&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,a.jsx)("span",{className:"font-mono",children:D})]})]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>R(!1),children:"Cancel"}),(0,a.jsxs)(N.$,{variant:"destructive",onClick:q,disabled:P,className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:P?"Deleting...":"Delete Conversation"})]})]})]})})]});return"inline"===o?(0,a.jsx)("div",{className:"h-full",children:W}):(0,a.jsx)(eP.lG,{open:t,onOpenChange:s,children:(0,a.jsx)(eP.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:W})})}var tW=s(174);function tK(e){let{isOpen:t,onClose:s,variant:r="modal"}=e,[i,l]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[h,p]=(0,n.useState)(""),[f,g]=(0,n.useState)(null),[w,k]=(0,n.useState)(!1),[C,S]=(0,n.useState)(!1),[A,E]=(0,n.useState)(null),T=(0,n.useCallback)(async()=>{d(!0),x(null);try{let e=await fetch("/api/memory");if(!e.ok)throw Error("Failed to fetch memories");let t=await e.json();l(t.memories||[])}catch(e){console.error("Error fetching memories:",e),x(e instanceof Error?e.message:"Failed to fetch memories")}finally{d(!1)}},[]);(0,n.useEffect)(()=>{t&&T()},[t,T]);let I=async e=>{g(e);try{let t=await fetch("/api/memory/".concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to delete memory")}l(t=>t.filter(t=>t.id!==e)),S(!1),E(null)}catch(e){console.error("Error deleting memory:",e),x(e instanceof Error?e.message:"Failed to delete memory")}finally{g(null)}},O=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:120;return e.length<=t?e:e.slice(0,t)+"..."},L=i.filter(e=>{var t;if(!h.trim())return!0;let s=h.toLowerCase();return e.content.toLowerCase().includes(s)||(null==(t=e.tags)?void 0:t.some(e=>e.toLowerCase().includes(s)))}),R=(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsx)("div",{className:"flex items-center justify-between p-3 border-b border-border/50",children:(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(F.A,{className:"h-4 w-4"}),(0,a.jsx)("h2",{className:"text-base font-semibold",children:"Memories"}),(0,a.jsx)(eV.E,{variant:"secondary",className:"text-xs",children:i.length})]})}),(0,a.jsx)("div",{className:"p-3 border-b border-border/50",children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(eK.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,a.jsx)(eU.p,{placeholder:"Search memories...",value:h,onChange:e=>p(e.target.value),className:"pl-8 h-8 text-sm"})]}),(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"outline",size:"sm",onClick:()=>k(!0),className:"h-8 w-8 p-0 shrink-0","aria-label":"Create new memory",children:(0,a.jsx)(ts.A,{className:"h-4 w-4"})})}),(0,a.jsx)(y,{children:"Create Memory"})]})})]})}),u&&(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)(eM.Fc,{variant:"destructive",children:[(0,a.jsx)(m.A,{className:"h-4 w-4"}),(0,a.jsx)(eM.TN,{children:u})]})}),(0,a.jsx)(tz,{className:"flex-1 p-4",children:(0,a.jsx)("div",{className:"space-y-2",children:c?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(tT.A,{className:"h-6 w-6 animate-spin"})}):0===L.length?(0,a.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,a.jsx)(F.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),h.trim()?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"No memories found"}),(0,a.jsx)("p",{className:"text-sm",children:"Try a different search term"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"No memories yet"}),(0,a.jsx)("p",{className:"text-sm",children:"Type # in chat or use the + button above"})]})]}):L.map(e=>{var t,s,r;return(0,a.jsx)("div",{className:(0,o.cn)("group p-3 rounded-lg border border-border/50 bg-card hover:bg-muted/50 transition-all",(null==(t=e.metadata)?void 0:t.pinned)&&"ring-1 ring-primary/30 bg-primary/5"),children:(0,a.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0 space-y-2",children:[(0,a.jsx)("p",{className:"text-sm leading-relaxed",children:O(e.content)}),e.tags&&e.tags.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,a.jsx)(tA.A,{className:"h-3 w-3 text-muted-foreground"}),e.tags.map((e,t)=>(0,a.jsx)(eV.E,{variant:"outline",className:"text-xs px-1.5 py-0",children:e},t))]}),(0,a.jsxs)("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(tW.A,{className:"h-3 w-3"}),(0,a.jsx)("span",{children:(e=>{let t=new Date(e),s=new Date().getTime()-t.getTime(),r=Math.floor(s/6e4),a=Math.floor(s/36e5),n=Math.floor(s/864e5);return r<1?"Just now":r<60?"".concat(r,"m ago"):a<24?"".concat(a,"h ago"):"".concat(n,"d ago")})(e.updatedAt)})]}),(null==(s=e.metadata)?void 0:s.source)&&(0,a.jsx)(eV.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:e.metadata.source}),(null==(r=e.metadata)?void 0:r.pinned)&&(0,a.jsx)(eV.E,{variant:"secondary",className:"text-xs px-1.5 py-0",children:"Pinned"})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-1",children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>{E(e),S(!0)},className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete memory",children:(0,a.jsx)(to.A,{className:"h-3.5 w-3.5 text-destructive"})})})]})},e.id)})})}),(0,a.jsx)(tm,{open:w,onClose:()=>k(!1),onSuccess:()=>{T()}}),(0,a.jsx)(eP.lG,{open:C,onOpenChange:S,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsxs)(eP.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Memory"})]}),(0,a.jsxs)(eP.rr,{children:["This will permanently delete this memory. This action cannot be undone.",A&&(0,a.jsx)("span",{className:"block mt-2 text-sm font-medium max-h-20 overflow-y-auto",children:O(A.content,100)})]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>S(!1),children:"Cancel"}),(0,a.jsxs)(N.$,{variant:"destructive",onClick:()=>A&&I(A.id),disabled:f===(null==A?void 0:A.id),className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:f===(null==A?void 0:A.id)?"Deleting...":"Delete Memory"})]})]})]})})]});return"inline"===r?(0,a.jsx)("div",{className:"h-full",children:R}):(0,a.jsx)(eP.lG,{open:t,onOpenChange:s,children:(0,a.jsx)(eP.Cf,{className:"sm:max-w-lg h-[600px] flex flex-col p-0",children:R})})}function t$(e){let{websocket:t,onApprovalRequest:s,onApprove:r,onDeny:a,onHandlersReady:i}=e,[o,c]=(0,n.useState)(null),{currentSessionId:d}=(0,l.v)(),m=n.useRef([]);(0,n.useEffect)(()=>{null==s||s(o)},[o,s]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{try{let t=JSON.parse(e.data);if("approvalRequest"===t.event){let e;if(!(null==t?void 0:t.data)||"object"!=typeof t.data)return void console.error("[WebUI] Invalid approvalRequest: message.data is missing or not an object");let s=t.data.sessionId;if(s&&s!==d)return;let r=t.data.type;if("tool_confirmation"!==r&&"elicitation"!==r)return void console.debug("[WebUI] Ignoring unsupported approval type: ".concat(r));let a=t.data.approvalId,n=t.data.timestamp;if("string"!=typeof a||"string"!=typeof n)return void console.error("[WebUI] Invalid approvalRequest: approvalId and timestamp must be strings");if("tool_confirmation"===r){let s=t.data.metadata;if(!s||"object"!=typeof s)return void console.error("[WebUI] Invalid tool_confirmation: metadata is missing or not an object");let i=s.toolName,l=s.args;if("string"!=typeof i)return void console.error("[WebUI] Invalid tool_confirmation: metadata.toolName must be a string");if(!l||"object"!=typeof l)return void console.error("[WebUI] Invalid tool_confirmation: metadata.args must be an object");e={approvalId:a,type:r,toolName:i,args:l,description:"string"==typeof s.description?s.description:void 0,timestamp:n,sessionId:t.data.sessionId,metadata:s}}else e={approvalId:a,type:r,timestamp:n,sessionId:t.data.sessionId,metadata:t.data.metadata||{}};console.debug("[WebUI] Received approvalRequest: ".concat(JSON.stringify(e))),o?m.current.push(e):c(e)}}catch(e){console.error("[WebUI] Error handling approvalRequest message: ".concat(e instanceof Error?e.message:String(e)))}};return t.addEventListener("message",e),()=>{t.removeEventListener("message",e)}},[t,o,d]);let u=(0,n.useCallback)((e,s,r)=>{if(!o||!t)return;let a="elicitation"===o.type?e&&s?{formData:s}:void 0:{rememberChoice:null!=r&&r},n={type:"approvalResponse",data:{approvalId:o.approvalId,status:e?"approved":"denied",sessionId:o.sessionId,...a?{data:a}:{}}};if(console.debug("[WebUI] Sending approvalResponse: ".concat(JSON.stringify(n))),t.readyState!==WebSocket.OPEN)return void console.warn("[WebUI] WebSocket not open (readyState: ".concat(t.readyState,"), cannot send approval response for ").concat(o.approvalId));try{t.send(JSON.stringify(n))}catch(e){console.error("[WebUI] Failed to send approval response: ".concat(e instanceof Error?e.message:String(e)));return}if(c(null),m.current.length>0){let e=m.current.shift();setTimeout(()=>{c(e)},100)}},[o,t]),x=(0,n.useCallback)((e,t)=>{u(!0,e,t),null==r||r(e,t)},[u,r]),h=(0,n.useCallback)(()=>{u(!1),null==a||a()},[u,a]);return(0,n.useEffect)(()=>{i&&i({onApprove:x,onDeny:h})},[x,h,i]),null}var tV=s(3665),tY=s(8989);function tJ(e){let{isOpen:t,onClose:s,onNavigateToSession:r}=e,[i,l]=(0,n.useState)(""),[c,d]=(0,n.useState)([]),[m,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),[p,f]=(0,n.useState)(0),g=(0,n.useCallback)(async e=>{if(!e.trim()){d([]),h(null);return}u(!0),h(null);try{let t=new URLSearchParams({q:e,limit:"10",offset:"0"}),s=await fetch("/api/search/messages?".concat(t));if(!s.ok){let e=await s.text();throw Error("Search failed: ".concat(s.status," ").concat(e))}let r=await s.json();d(r.results),f(0)}catch(e){console.error("Search error:",e),d([]),h(e instanceof Error?e.message:"Search failed")}finally{u(!1)}},[]);(0,n.useEffect)(()=>{let e=setTimeout(()=>{g(i)},300);return()=>clearTimeout(e)},[i,g]),(0,n.useEffect)(()=>{t&&(l(""),d([]),h(null),f(0))},[t]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{if(t&&(!e.ctrlKey&&!e.metaKey||!e.shiftKey||"S"!==e.key))switch(e.key){case"ArrowDown":e.preventDefault(),e.stopPropagation(),f(e=>Math.min(e+1,c.length-1));break;case"ArrowUp":e.preventDefault(),e.stopPropagation(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),e.stopPropagation(),c[p]&&v(c[p]);break;case"Escape":e.preventDefault(),e.stopPropagation(),s()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,c,p,s]);let v=e=>{r(e.sessionId,e.messageIndex),s()};return(0,a.jsx)(eP.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eP.Cf,{className:"max-w-2xl p-0 top-[20%] transform translate-y-0",children:[(0,a.jsx)(eP.c7,{children:(0,a.jsx)(eP.L3,{className:"sr-only",children:"Search Conversations"})}),(0,a.jsxs)("div",{className:"flex flex-col max-h-[70vh]",children:[(0,a.jsx)("div",{className:"p-6 pb-4",children:(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(eK.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),(0,a.jsx)(eU.p,{placeholder:"Search conversations...",value:i,onChange:e=>l(e.target.value),className:"pl-12 text-lg border-0 shadow-none focus-visible:ring-0 bg-transparent",autoFocus:!0})]})}),(0,a.jsx)("div",{className:"flex-1 overflow-hidden border-t",children:m?(0,a.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,a.jsx)(tT.A,{className:"h-6 w-6 animate-spin mr-3"}),(0,a.jsx)("span",{className:"text-muted-foreground",children:"Searching..."})]}):x?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)(eK.A,{className:"w-12 h-12 mx-auto mb-4 text-destructive opacity-50"}),(0,a.jsx)("p",{className:"text-destructive font-medium",children:"Search Error"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:x}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"Try again or check your connection."})]})}):(0,a.jsx)(tz,{className:"h-full",children:(0,a.jsx)("div",{className:"p-2",children:c.length>0?(0,a.jsx)("div",{className:"space-y-1",children:c.map((e,t)=>(0,a.jsxs)("div",{className:(0,o.cn)("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-colors",t===p?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>v(e),children:[(0,a.jsx)("div",{className:"flex-shrink-0 mt-1",children:(0,a.jsx)(eV.E,{className:(0,o.cn)("text-xs",(e=>{switch(e){case"user":return"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";case"assistant":return"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200";case"system":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";default:return"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200"}})(e.message.role)),children:(e=>{switch(e){case"user":return(0,a.jsx)(L.A,{className:"w-4 h-4"});case"assistant":return(0,a.jsx)(R.A,{className:"w-4 h-4"});case"system":return(0,a.jsx)(tV.A,{className:"w-4 h-4"});default:return(0,a.jsx)(tY.A,{className:"w-4 h-4"})}})(e.message.role)})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:e.sessionId.length>20?"".concat(e.sessionId.slice(0,20),"..."):e.sessionId}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:e.message.role})]}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground line-clamp-2",children:((e,t)=>{if(!t)return e;let s=t.replace(/[.*+?^${}()|\[\]\\]/g,"\\$&"),r=RegExp("(".concat(s,")"),"gi");return e.split(r).map((e,t)=>r.test(e)?(0,a.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-800 font-medium rounded px-1",children:e},t):e)})(e.context,i)})]}),(0,a.jsx)(P.A,{className:"w-4 h-4 text-muted-foreground flex-shrink-0 mt-1"})]},t))}):i?(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(eK.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:"No messages found matching your search."}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Try different keywords."})]}):(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(eK.A,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground opacity-50"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:"Start typing to search your conversations."}),(0,a.jsxs)("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↑"}),(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"↓"}),(0,a.jsx)("span",{children:"to navigate"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Enter"}),(0,a.jsx)("span",{children:"to select"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("kbd",{className:"px-2 py-1 bg-muted rounded text-xs",children:"Esc"}),(0,a.jsx)("span",{children:"to close"})]})]})]})})})})]})]})})}var tG=s(7345),tH=s(9613);function tQ(e){let{value:t,onChange:s,onValidate:r,readOnly:i=!1,height:l="100%"}=e,o=(0,n.useRef)(null);return(0,n.useEffect)(()=>{o.current&&r&&o.current.getModel()},[r]),(0,a.jsx)(tH.Ay,{height:l,defaultLanguage:"yaml",value:t,onChange:e=>{void 0!==e&&s(e)},onMount:e=>{o.current=e,e.updateOptions({minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:"on",renderLineHighlight:"all",folding:!0,automaticLayout:!0})},theme:"vs-dark",options:{readOnly:i,wordWrap:"on",tabSize:2}})}function tZ(e){let{isValidating:t,isValid:s,errors:r,warnings:n,hasUnsavedChanges:i}=e;return(0,a.jsxs)("div",{className:"border-t border-border bg-background px-4 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,a.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:t?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:"Validating..."})]}):s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(_.A,{className:"h-4 w-4 text-green-500 flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Valid configuration",i&&" (unsaved changes)"]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e9.A,{className:"h-4 w-4 text-destructive flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-destructive",children:[r.length," ",1===r.length?"error":"errors"]})]})}),n.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(m.A,{className:"h-4 w-4 text-yellow-500 flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-sm text-yellow-500",children:[n.length," ",1===n.length?"warning":"warnings"]})]})]}),r.length>0&&(0,a.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:r.map((e,t)=>(0,a.jsxs)("div",{className:"text-xs bg-destructive/10 text-destructive rounded px-2 py-1.5 flex items-start gap-2",children:[(0,a.jsx)(e9.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[e.path&&(0,a.jsxs)("span",{className:"font-medium",children:[e.path,": "]}),e.message,e.line&&(0,a.jsxs)("span",{className:"text-muted-foreground ml-1",children:["(line ",e.line,e.column&&":".concat(e.column),")"]})]})]},t))}),n.length>0&&0===r.length&&(0,a.jsx)("div",{className:"mt-3 space-y-2 max-h-32 overflow-y-auto",children:n.map((e,t)=>(0,a.jsxs)("div",{className:"text-xs bg-yellow-500/10 text-yellow-600 dark:text-yellow-500 rounded px-2 py-1.5 flex items-start gap-2",children:[(0,a.jsx)(m.A,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("span",{className:"font-medium",children:[e.path,": "]}),e.message]})]},t))})]})}function tX(e){let{value:t,onChange:s,onValidate:r,isValidating:n=!1,isValid:i=!0,errors:l=[],warnings:o=[],hasUnsavedChanges:c=!1}=e;return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,a.jsx)(tQ,{value:t,onChange:s,onValidate:r,height:"100%"})}),(0,a.jsx)(tZ,{isValidating:n,isValid:i,errors:l,warnings:o,hasUnsavedChanges:c})]})}function t0(e){let{htmlFor:t,children:s,tooltip:r,className:n}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,a.jsx)(e_.J,{htmlFor:t,className:n,children:s}),r&&(0,a.jsx)(v,{delayDuration:200,children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"More information",children:(0,a.jsx)(eq.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(y,{side:"right",className:"max-w-xs",children:(0,a.jsx)("p",{className:"text-sm",children:r})})]})})]})}function t1(e){let{title:t,children:s,defaultOpen:r=!0,open:i,onOpenChange:l,errorCount:c=0,sectionErrors:d=[],className:m}=e,[u,h]=(0,n.useState)(r),p=void 0!==i,f=p?i:u;return(0,a.jsxs)("div",{className:(0,o.cn)("border border-border rounded-lg overflow-hidden",m),children:[(0,a.jsxs)("button",{onClick:()=>{let e=!f;p?null==l||l(e):h(e)},className:"w-full flex items-center justify-between px-4 py-3 bg-muted/50 hover:bg-muted transition-colors text-left",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:t}),c>0&&(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)("span",{className:"inline-flex items-center justify-center px-2 py-0.5 text-xs font-medium bg-destructive text-destructive-foreground rounded-full cursor-help",children:[c," ",1===c?"error":"errors"]})}),(0,a.jsx)(y,{side:"top",className:"max-w-sm",children:(0,a.jsx)("ul",{className:"space-y-1 text-left",children:d.map((e,t)=>(0,a.jsxs)("li",{children:["• ",e]},t))})})]})]}),(0,a.jsx)(x.A,{className:(0,o.cn)("h-4 w-4 transition-transform duration-200",f&&"transform rotate-180")})]}),f&&(0,a.jsx)("div",{className:"px-4 py-4 space-y-4",children:s})]})}var t2=s(2449),t4=s(3973);let t5=["openai","openai-compatible","anthropic","google","groq","xai","cohere"],t3=["vercel","in-built"];function t8(e){var t;let{value:s,onChange:r,errors:i={},open:l,onOpenChange:o,errorCount:c=0,sectionErrors:d=[]}=e,[m,u]=(0,n.useState)(!1),x=(e,t)=>{r({...s,[e]:t})};return(0,a.jsx)(t1,{title:"LLM Configuration",defaultOpen:!0,open:l,onOpenChange:o,errorCount:c,sectionErrors:d,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"provider",tooltip:"The LLM provider to use (e.g., OpenAI, Anthropic)",children:"Provider *"}),(0,a.jsxs)("select",{id:"provider",value:s.provider||"",onChange:e=>x("provider",e.target.value),"aria-invalid":!!i["llm.provider"],className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",children:[(0,a.jsx)("option",{value:"",children:"Select provider..."}),t5.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]}),i["llm.provider"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.provider"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"model",tooltip:"The specific model identifier (e.g., gpt-4, claude-3-opus)",children:"Model *"}),(0,a.jsx)(eU.p,{id:"model",value:s.model||"",onChange:e=>x("model",e.target.value),placeholder:"e.g., gpt-4, claude-3-opus-20240229","aria-invalid":!!i["llm.model"]}),i["llm.model"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.model"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"apiKey",tooltip:"Use $ENV_VAR for environment variables or enter the API key directly",children:"API Key *"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(eU.p,{id:"apiKey",type:m?"text":"password",value:null!=(t=s.apiKey)?t:"",onChange:e=>x("apiKey",e.target.value),placeholder:"$OPENAI_API_KEY or direct value","aria-invalid":!!i["llm.apiKey"],className:"pr-10"}),(0,a.jsx)("button",{type:"button",onClick:()=>u(!m),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-accent rounded transition-colors","aria-label":m?"Hide API key":"Show API key",children:m?(0,a.jsx)(t2.A,{className:"h-4 w-4 text-muted-foreground"}):(0,a.jsx)(t4.A,{className:"h-4 w-4 text-muted-foreground"})})]}),i["llm.apiKey"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.apiKey"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"router",tooltip:"LLM routing backend: 'vercel' uses Vercel AI SDK, 'in-built' uses provider-specific clients",children:"Router"}),(0,a.jsx)("select",{id:"router",value:s.router||"vercel",onChange:e=>x("router",e.target.value),"aria-invalid":!!i["llm.router"],className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",children:t3.map(e=>(0,a.jsx)("option",{value:e,children:e},e))}),i["llm.router"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.router"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"maxIterations",tooltip:"Maximum number of agent reasoning iterations per turn",children:"Max Iterations"}),(0,a.jsx)(eU.p,{id:"maxIterations",type:"number",value:void 0!==s.maxIterations?s.maxIterations:"",onChange:e=>{let t=e.target.value;if(""===t)x("maxIterations",void 0);else{let e=parseInt(t,10);isNaN(e)||x("maxIterations",e)}},min:"1",placeholder:"50","aria-invalid":!!i["llm.maxIterations"]}),i["llm.maxIterations"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxIterations"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"baseURL",tooltip:"Custom base URL for the LLM provider (optional, for proxies or custom endpoints)",children:"Base URL"}),(0,a.jsx)(eU.p,{id:"baseURL",value:s.baseURL||"",onChange:e=>x("baseURL",e.target.value||void 0),placeholder:"https://api.openai.com/v1","aria-invalid":!!i["llm.baseURL"]}),i["llm.baseURL"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.baseURL"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"temperature",tooltip:"Controls randomness in responses (0.0 = deterministic, 1.0 = creative)",children:"Temperature"}),(0,a.jsx)(eU.p,{id:"temperature",type:"number",value:void 0!==s.temperature?s.temperature:"",onChange:e=>x("temperature",e.target.value?parseFloat(e.target.value):void 0),min:"0",max:"1",step:"0.1",placeholder:"0.0 - 1.0","aria-invalid":!!i["llm.temperature"]}),i["llm.temperature"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.temperature"]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"maxInputTokens",tooltip:"Maximum input tokens to send to the model",children:"Max Input Tokens"}),(0,a.jsx)(eU.p,{id:"maxInputTokens",type:"number",value:s.maxInputTokens||"",onChange:e=>x("maxInputTokens",e.target.value?parseInt(e.target.value,10):void 0),min:"1",placeholder:"Optional","aria-invalid":!!i["llm.maxInputTokens"]}),i["llm.maxInputTokens"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxInputTokens"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"maxOutputTokens",tooltip:"Maximum output tokens the model can generate",children:"Max Output Tokens"}),(0,a.jsx)(eU.p,{id:"maxOutputTokens",type:"number",value:s.maxOutputTokens||"",onChange:e=>x("maxOutputTokens",e.target.value?parseInt(e.target.value,10):void 0),min:"1",placeholder:"Optional","aria-invalid":!!i["llm.maxOutputTokens"]}),i["llm.maxOutputTokens"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i["llm.maxOutputTokens"]})]})]})]})})}let t6=["dateTime","memorySummary","resources"];function t9(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:c=[]}=e,[d,m]=(0,n.useState)(new Set),[h,p]=(0,n.useState)({}),f=t.contributors||[],g=(e,t)=>{s({contributors:f.map(s=>{if(s.id===e){if(t.id&&t.id!==e&&m(s=>{let r=new Set(s);return r.has(e)&&(r.delete(e),r.add(t.id)),r}),t.type&&t.type!==s.type){let e={id:t.id||s.id,priority:void 0!==t.priority?t.priority:s.priority,enabled:void 0!==t.enabled?t.enabled:s.enabled};if("static"===t.type)return{...e,type:"static",content:""};if("dynamic"===t.type)return{...e,type:"dynamic",source:"dateTime"};if("file"===t.type)return{...e,type:"file",files:[]}}return{...s,...t}}return s})})};return(0,a.jsx)(t1,{title:"System Prompt",defaultOpen:!0,open:i,onOpenChange:l,errorCount:o,sectionErrors:c,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define how the agent should behave using multiple contributors with different priorities."}),0===f.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No contributors configured"}):f.map(e=>{var t,r,n,i,l,o,c,v,j;let b=d.has(e.id);return(0,a.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,a.jsxs)("button",{onClick:()=>{var t;return t=e.id,void m(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[b?(0,a.jsx)(u.A,{className:"h-4 w-4"}):(0,a.jsx)(x.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:e.id}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.type,", priority: ",e.priority,")"]}),!1===e.enabled&&(0,a.jsx)("span",{className:"text-xs text-destructive",children:"(disabled)"})]}),(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>{var t;return t=e.id,void(s({contributors:f.filter(e=>e.id!==t)}),m(e=>{let s=new Set(e);return s.delete(t),s}))},className:"h-7 w-7 p-0",children:(0,a.jsx)(to.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),b&&(0,a.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-id-".concat(e.id),tooltip:"Unique identifier for this contributor",children:"ID *"}),(0,a.jsx)(eU.p,{id:"contributor-id-".concat(e.id),value:e.id,onChange:t=>g(e.id,{id:t.target.value}),placeholder:"e.g., primary, dateTime"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-type-".concat(e.id),tooltip:"Type of contributor: static (fixed text), dynamic (runtime generated), or file (from files)",children:"Type *"}),(0,a.jsxs)("select",{id:"contributor-type-".concat(e.id),value:e.type,onChange:t=>g(e.id,{type:t.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:[(0,a.jsx)("option",{value:"static",children:"Static"}),(0,a.jsx)("option",{value:"dynamic",children:"Dynamic"}),(0,a.jsx)("option",{value:"file",children:"File"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-priority-".concat(e.id),tooltip:"Execution priority (lower numbers run first)",children:"Priority *"}),(0,a.jsx)(eU.p,{id:"contributor-priority-".concat(e.id),type:"number",value:e.priority,onChange:t=>{let s=Number.parseInt(t.target.value,10);g(e.id,{priority:Number.isNaN(s)?0:s})},placeholder:"0",min:"0"})]})]}),(0,a.jsx)("div",{children:(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:!1!==e.enabled,onChange:t=>g(e.id,{enabled:t.target.checked}),className:"rounded border-input"}),(0,a.jsx)("span",{children:"Enabled"})]})}),"static"===e.type&&(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-content-".concat(e.id),tooltip:"Static content for the system prompt",children:"Content *"}),(0,a.jsx)(ti.T,{id:"contributor-content-".concat(e.id),value:e.content,onChange:t=>g(e.id,{content:t.target.value}),placeholder:"You are a helpful assistant...",rows:8,className:"font-mono text-sm"})]}),"dynamic"===e.type&&(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-source-".concat(e.id),tooltip:"Source for dynamic content generation",children:"Source *"}),(0,a.jsx)("select",{id:"contributor-source-".concat(e.id),value:e.source,onChange:t=>g(e.id,{source:t.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:t6.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),"file"===e.type&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-files-".concat(e.id),tooltip:"File paths to include, comma-separated",children:"Files *"}),(0,a.jsx)(eU.p,{id:"contributor-files-".concat(e.id),value:(c=e.id,v=e.files,null!=(j=h[c])?j:v.join(", ")),onChange:t=>{var s,r;return s=e.id,r=t.target.value,void p(e=>({...e,[s]:r}))},onBlur:t=>((e,t)=>{p(t=>{let s={...t};return delete s[e],s});let s=t.split(",").map(e=>e.trim()).filter(Boolean);g(e,{files:s.length>0?s:[]})})(e.id,t.target.value),placeholder:"./commands/context.md, ./commands/rules.txt",className:"font-mono"})]}),(0,a.jsxs)("details",{className:"border border-border rounded-md p-2",children:[(0,a.jsx)("summary",{className:"text-sm font-medium cursor-pointer",children:"File Options"}),(0,a.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:(null==(t=e.options)?void 0:t.includeFilenames)!==!1,onChange:t=>g(e.id,{options:{...e.options,includeFilenames:t.target.checked}}),className:"rounded border-input"}),(0,a.jsx)("span",{children:"Include filenames as headers"})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:(null==(r=e.options)?void 0:r.includeMetadata)===!0,onChange:t=>g(e.id,{options:{...e.options,includeMetadata:t.target.checked}}),className:"rounded border-input"}),(0,a.jsx)("span",{children:"Include file metadata"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-separator-".concat(e.id),tooltip:"Separator between multiple files",children:"Separator"}),(0,a.jsx)(eU.p,{id:"contributor-separator-".concat(e.id),value:null!=(o=null==(n=e.options)?void 0:n.separator)?o:"\n\n---\n\n",onChange:t=>g(e.id,{options:{...e.options,separator:t.target.value}}),placeholder:"\\n\\n---\\n\\n"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-error-handling-".concat(e.id),tooltip:"How to handle missing or unreadable files",children:"Error Handling"}),(0,a.jsxs)("select",{id:"contributor-error-handling-".concat(e.id),value:(null==(i=e.options)?void 0:i.errorHandling)||"skip",onChange:t=>g(e.id,{options:{...e.options,errorHandling:t.target.value}}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:[(0,a.jsx)("option",{value:"skip",children:"Skip missing files"}),(0,a.jsx)("option",{value:"error",children:"Error on missing files"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"contributor-max-file-size-".concat(e.id),tooltip:"Maximum file size in bytes",children:"Max File Size (bytes)"}),(0,a.jsx)(eU.p,{id:"contributor-max-file-size-".concat(e.id),type:"number",value:(null==(l=e.options)?void 0:l.maxFileSize)||1e5,onChange:t=>{let s=Number.parseInt(t.target.value,10);g(e.id,{options:{...e.options,maxFileSize:Number.isNaN(s)?void 0:s}})},placeholder:"100000",min:"1"})]})]})]})]})]})]},e.id)}),(0,a.jsxs)(N.$,{onClick:()=>{let e="contributor-".concat(Date.now()),t={id:e,type:"static",priority:10*f.length,enabled:!0,content:""};s({contributors:[...f,t]}),m(t=>new Set(t).add(e))},variant:"outline",size:"sm",className:"w-full",children:[(0,a.jsx)(ts.A,{className:"h-4 w-4 mr-2"}),"Add Contributor"]}),r.systemPrompt&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r.systemPrompt})]})})}var t7=(e=>(e.SCHEMA_VALIDATION="mcp_schema_validation",e.COMMAND_MISSING="mcp_command_missing",e.DUPLICATE_NAME="mcp_duplicate_name",e.CONNECTION_FAILED="mcp_connection_failed",e.PROTOCOL_ERROR="mcp_protocol_error",e.TOOL_NOT_FOUND="mcp_tool_not_found",e.PROMPT_NOT_FOUND="mcp_prompt_not_found",e.RESOURCE_NOT_FOUND="mcp_resource_not_found",e))(t7||{}),se=(e=>(e.LLM="llm",e.AGENT="agent",e.CONFIG="config",e.CONTEXT="context",e.SESSION="session",e.MCP="mcp",e.TOOLS="tools",e.STORAGE="storage",e.SYSTEM_PROMPT="system_prompt",e.PREFERENCE="preference",e.AGENT_REGISTRY="agent_registry",e.RESOURCE="resource",e.PROMPT="prompt",e.MEMORY="memory",e.PLUGIN="plugin",e))(se||{}),st=(e=>(e.USER="user",e.NOT_FOUND="not_found",e.FORBIDDEN="forbidden",e.TIMEOUT="timeout",e.RATE_LIMIT="rate_limit",e.SYSTEM="system",e.THIRD_PARTY="third_party",e.UNKNOWN="unknown",e))(st||{}),ss=s(4536),sr=s(9246);ss.Yj().transform(e=>e.trim()).refine(e=>e.length>0,{message:"Required"}),ss.Yj().transform(e=>e.trim()).refine(e=>""===e||function(e){try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}}(e),{message:"Invalid URL"}).transform(e=>""===e?void 0:e).optional();let sa=e=>ss.Yj().transform(t=>{if("string"!=typeof t)return"";let s=null!=e?e:sr.env;return t.replace(/\$([A-Z_][A-Z0-9_]*)|\${([A-Z_][A-Z0-9_]*)}/gi,(e,t,r)=>{var a;return null!=(a=s[t||r])?a:""}).trim()}),sn=e=>sa(e).refine(e=>{try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}},{message:"Invalid URL"});var si=s(3292),sl=s(9246);let so=["stdio","sse","http"],sc=["strict","lenient"],sd="lenient",sm=ss.Ik({type:ss.eu("stdio"),command:sa().superRefine((e,t)=>{0===e.length&&t.addIssue({code:si.eq.custom,message:"Stdio server requires a non-empty command",params:{code:t7.COMMAND_MISSING,scope:se.MCP,type:st.USER}})}),args:ss.YO(sa()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),env:ss.g1(sa()).default({}).describe("Optional environment variables for the server process"),timeout:ss.au.number().int().positive().default(3e4),connectionMode:ss.k5(sc).default(sd)}).strict(),su=ss.Ik({type:ss.eu("sse"),url:sn(sl.env).describe("URL for the SSE server endpoint"),headers:ss.g1(sa()).default({}),timeout:ss.au.number().int().positive().default(3e4),connectionMode:ss.k5(sc).default(sd)}).strict(),sx=ss.Ik({type:ss.eu("http"),url:sn(sl.env).describe("URL for the HTTP server"),headers:ss.g1(sa()).default({}),timeout:ss.au.number().int().positive().default(3e4),connectionMode:ss.k5(sc).default(sd)}).strict(),sh=ss.gM("type",[sm,su,sx]).superRefine((e,t)=>{}).brand();function sp(e){let{value:t,onChange:s,errors:r={},open:i,onOpenChange:l,errorCount:o=0,sectionErrors:c=[]}=e,[d,m]=(0,n.useState)(new Set),[h,p]=(0,n.useState)({}),f=Object.entries(t||{}),g=(e,r)=>{let a=t[e],{name:n,...i}=r,l={...a,...i};if(n&&"string"==typeof n&&n!==e){if(t[n])return;let r={...t};delete r[e],r[n]=l,s(r),m(t=>{let s=new Set(t);return s.has(e)&&(s.delete(e),s.add(n)),s})}else s({...t,[e]:l})},v=(e,t,s)=>{var r;return null!=(r=h["".concat(e,":").concat(t)])?r:s},j=(e,t,s)=>{let r="".concat(e,":").concat(t);p(e=>({...e,[r]:s}))},b=(e,t)=>{let s="".concat(e,":").concat(t);p(e=>{let t={...e};return delete t[s],t})};return(0,a.jsx)(t1,{title:"MCP Servers",defaultOpen:!1,open:i,onOpenChange:l,errorCount:o,sectionErrors:c,children:(0,a.jsxs)("div",{className:"space-y-4",children:[0===f.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No MCP servers configured"}):f.map(e=>{let[n,i]=e,l=d.has(n);return(0,a.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/30",children:[(0,a.jsxs)("button",{onClick:()=>{m(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t})},className:"flex items-center gap-2 flex-1 text-left hover:text-foreground transition-colors",children:[l?(0,a.jsx)(u.A,{className:"h-4 w-4"}):(0,a.jsx)(x.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"font-medium text-sm",children:n}),"command"in i&&i.command&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:["(",i.command,")"]})]}),(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>(e=>{let r={...t};delete r[e],s(r),m(t=>{let s=new Set(t);return s.delete(e),s})})(n),className:"h-7 w-7 p-0",children:(0,a.jsx)(to.A,{className:"h-3.5 w-3.5 text-destructive"})})]}),l&&(0,a.jsxs)("div",{className:"px-3 py-3 space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-name-".concat(n),tooltip:"Unique identifier for this MCP server",children:"Server Name"}),(0,a.jsx)(eU.p,{id:"server-name-".concat(n),value:n,onChange:e=>g(n,{name:e.target.value}),placeholder:"e.g., filesystem"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-type-".concat(n),tooltip:"MCP server connection type",children:"Connection Type *"}),(0,a.jsx)("select",{id:"server-type-".concat(n),value:i.type||"stdio",onChange:e=>{let t=e.target.value;"stdio"===t?g(n,{type:"stdio",command:"",args:void 0,env:void 0}):g(n,{type:t,url:"",headers:void 0})},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:so.map(e=>(0,a.jsx)("option",{value:e,children:"stdio"===e?"Standard I/O (stdio)":"sse"===e?"Server-Sent Events (SSE)":"HTTP"},e))})]}),"stdio"===i.type&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-command-".concat(n),tooltip:"The command to execute (e.g., npx, node, python)",children:"Command *"}),(0,a.jsx)(eU.p,{id:"server-command-".concat(n),value:"command"in i?i.command:"",onChange:e=>g(n,{command:e.target.value}),placeholder:"e.g., npx, node, python","aria-invalid":!!r["mcpServers.".concat(n,".command")]}),r["mcpServers.".concat(n,".command")]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["mcpServers.".concat(n,".command")]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-args-".concat(n),tooltip:"Command arguments, comma-separated",children:"Arguments"}),(0,a.jsx)(eU.p,{id:"server-args-".concat(n),value:v(n,"args",("args"in i&&i.args?i.args:[]).join(", ")),onChange:e=>j(n,"args",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"args"),!t.trim())return void g(e,{args:void 0});let s=t.split(",").map(e=>e.trim()).filter(Boolean);g(e,{args:s.length>0?s:void 0})})(n,e.target.value),placeholder:"--port, 3000, --host, localhost",className:"font-mono"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-env-".concat(n),tooltip:"Environment variables in KEY=value format, one per line",children:"Environment Variables"}),(0,a.jsx)("textarea",{id:"server-env-".concat(n),value:v(n,"env",Object.entries("env"in i&&i.env||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>j(n,"env",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"env"),!t.trim())return void g(e,{env:void 0});let s={};t.split("\n").map(e=>e.trim()).filter(Boolean).forEach(e=>{let[t,...r]=e.split("=");t&&r.length>0&&(s[t.trim()]=r.join("=").trim())}),g(e,{env:Object.keys(s).length>0?s:void 0})})(n,e.target.value),placeholder:"API_KEY=$MY_API_KEY\nPORT=3000",rows:4,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 font-mono"})]})]}),("sse"===i.type||"http"===i.type)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-url-".concat(n),tooltip:"The URL endpoint for the MCP server",children:"URL *"}),(0,a.jsx)(eU.p,{id:"server-url-".concat(n),value:"url"in i?i.url:"",onChange:e=>g(n,{url:e.target.value}),placeholder:"https://example.com/mcp","aria-invalid":!!r["mcpServers.".concat(n,".url")]}),r["mcpServers.".concat(n,".url")]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["mcpServers.".concat(n,".url")]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-headers-".concat(n),tooltip:"HTTP headers in KEY=value format, one per line",children:"Headers"}),(0,a.jsx)("textarea",{id:"server-headers-".concat(n),value:v(n,"headers",Object.entries("headers"in i&&i.headers||{}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("\n")),onChange:e=>j(n,"headers",e.target.value),onBlur:e=>((e,t)=>{if(b(e,"headers"),!t.trim())return void g(e,{headers:void 0});let s={};t.split("\n").map(e=>e.trim()).filter(Boolean).forEach(e=>{let[t,...r]=e.split("=");t&&r.length>0&&(s[t.trim()]=r.join("=").trim())}),g(e,{headers:Object.keys(s).length>0?s:void 0})})(n,e.target.value),placeholder:"Authorization=Bearer token\nContent-Type=application/json",rows:4,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 font-mono"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"server-mode-".concat(n),tooltip:"Strict mode fails on any error; lenient mode continues despite errors",children:"Connection Mode"}),(0,a.jsx)("select",{id:"server-mode-".concat(n),value:i.connectionMode||sd,onChange:e=>g(n,{connectionMode:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sc.map(e=>(0,a.jsx)("option",{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]})]},n)}),(0,a.jsxs)(N.$,{onClick:()=>{let e="server-".concat(Object.keys(t||{}).length+1);s({...t,[e]:{type:"stdio",command:"",connectionMode:"strict"}}),m(t=>new Set(t).add(e))},variant:"outline",size:"sm",className:"w-full",children:[(0,a.jsx)(ts.A,{className:"h-4 w-4 mr-2"}),"Add MCP Server"]}),r.mcpServers&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r.mcpServers})]})})}ss.g1(sh).describe("A dictionary of server configurations, keyed by server name").brand();var sf=(e=>(e.MANAGER_NOT_INITIALIZED="storage_manager_not_initialized",e.MANAGER_NOT_CONNECTED="storage_manager_not_connected",e.CONNECTION_FAILED="storage_connection_failed",e.CONNECTION_CONFIG_MISSING="storage_connection_config_missing",e.READ_FAILED="storage_read_failed",e.WRITE_FAILED="storage_write_failed",e.DELETE_FAILED="storage_delete_failed",e.MIGRATION_FAILED="storage_migration_failed",e.BLOB_INVALID_CONFIG="BLOB_INVALID_CONFIG",e.BLOB_SIZE_EXCEEDED="BLOB_SIZE_EXCEEDED",e.BLOB_TOTAL_SIZE_EXCEEDED="BLOB_TOTAL_SIZE_EXCEEDED",e.BLOB_INVALID_INPUT="BLOB_INVALID_INPUT",e.BLOB_ENCODING_ERROR="BLOB_ENCODING_ERROR",e.BLOB_NOT_FOUND="BLOB_NOT_FOUND",e.BLOB_INVALID_REFERENCE="BLOB_INVALID_REFERENCE",e.BLOB_ACCESS_DENIED="BLOB_ACCESS_DENIED",e.BLOB_CORRUPTED="BLOB_CORRUPTED",e.BLOB_BACKEND_NOT_CONNECTED="BLOB_BACKEND_NOT_CONNECTED",e.BLOB_BACKEND_UNAVAILABLE="BLOB_BACKEND_UNAVAILABLE",e.BLOB_CLEANUP_FAILED="BLOB_CLEANUP_FAILED",e.BLOB_OPERATION_FAILED="BLOB_OPERATION_FAILED",e))(sf||{});let sg=["in-memory","redis"],sv=ss.Ik({maxConnections:ss.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:ss.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:ss.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:ss.g1(ss.bz()).optional().describe("Backend-specific options")}),sj=sv.extend({type:ss.eu("in-memory")}).strict(),sb=sv.extend({type:ss.eu("redis"),url:sa().optional().describe("Redis connection URL (redis://...)"),host:ss.Yj().optional().describe("Redis host"),port:ss.ai().int().positive().optional().describe("Redis port"),password:ss.Yj().optional().describe("Redis password"),database:ss.ai().int().nonnegative().optional().describe("Redis database number")}).strict();ss.gM("type",[sj,sb],{errorMap:(e,t)=>e.code===si.eq.invalid_union_discriminator?{message:"Invalid cache type. Expected 'in-memory' or 'redis'."}:{message:t.defaultError}}).describe("Cache configuration").superRefine((e,t)=>{"redis"!==e.type||e.url||e.host||t.addIssue({code:si.eq.custom,message:"Redis cache requires either 'url' or 'host' to be specified",path:["url"],params:{code:sf.CONNECTION_CONFIG_MISSING,scope:se.STORAGE,type:st.USER}})});let sy=["in-memory","sqlite","postgres"],sN=ss.Ik({maxConnections:ss.ai().int().positive().optional().describe("Maximum connections"),idleTimeoutMillis:ss.ai().int().positive().optional().describe("Idle timeout in milliseconds"),connectionTimeoutMillis:ss.ai().int().positive().optional().describe("Connection timeout in milliseconds"),options:ss.g1(ss.bz()).optional().describe("Backend-specific options")}),sw=sN.extend({type:ss.eu("in-memory")}).strict(),sk=sN.extend({type:ss.eu("sqlite"),path:ss.Yj().optional().describe("SQLite database file path (optional, will auto-detect using path resolver if not provided)"),database:ss.Yj().optional().describe("Database filename (default: dexto.db)")}).strict(),sC=sN.extend({type:ss.eu("postgres"),url:sa().optional().describe("PostgreSQL connection URL (postgresql://...)"),connectionString:sa().optional().describe("PostgreSQL connection string"),host:ss.Yj().optional().describe("PostgreSQL host"),port:ss.ai().int().positive().optional().describe("PostgreSQL port"),database:ss.Yj().optional().describe("PostgreSQL database name"),password:ss.Yj().optional().describe("PostgreSQL password")}).strict();function sS(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,c=e=>{s({...t,cache:{...t.cache,...e}})},d=e=>{s({...t,database:{...t.database,...e}})},m="redis"===t.cache.type,u="sqlite"===t.database.type||"postgres"===t.database.type;return(0,a.jsx)(t1,{title:"Storage Configuration",defaultOpen:!1,open:n,onOpenChange:i,errorCount:l,sectionErrors:o,children:(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("h4",{className:"text-sm font-medium",children:"Cache"}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"cache-type",tooltip:"Storage backend for caching data (in-memory or Redis)",children:"Cache Type"}),(0,a.jsx)("select",{id:"cache-type",value:t.cache.type,onChange:e=>c({type:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sg.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),m&&"url"in t.cache&&(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"cache-url",tooltip:"Redis connection URL (e.g., redis://localhost:6379)",children:"Redis URL"}),(0,a.jsx)(eU.p,{id:"cache-url",value:t.cache.url||"",onChange:e=>c({url:e.target.value||void 0}),placeholder:"redis://localhost:6379","aria-invalid":!!r["storage.cache.url"]}),r["storage.cache.url"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["storage.cache.url"]})]})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("h4",{className:"text-sm font-medium",children:"Database"}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"database-type",tooltip:"Storage backend for persistent data (in-memory, SQLite, or PostgreSQL)",children:"Database Type"}),(0,a.jsx)("select",{id:"database-type",value:t.database.type,onChange:e=>d({type:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sy.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),u&&(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"database-url",tooltip:"sqlite"===t.database.type?"File path for SQLite database":"PostgreSQL connection string",children:"sqlite"===t.database.type?"SQLite Path":"PostgreSQL URL"}),(0,a.jsx)(eU.p,{id:"database-url",value:"url"in t.database&&t.database.url||"path"in t.database&&t.database.path||"",onChange:e=>{"sqlite"===t.database.type?d({path:e.target.value||void 0}):d({url:e.target.value||void 0})},placeholder:"sqlite"===t.database.type?"./dexto.db":"postgresql://user:pass@localhost:5432/dexto","aria-invalid":!!(r["storage.database.url"]||r["storage.database.path"])}),(r["storage.database.url"]||r["storage.database.path"])&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["storage.database.url"]||r["storage.database.path"]})]})]})]})})}ss.gM("type",[sw,sk,sC],{errorMap:(e,t)=>e.code===si.eq.invalid_union_discriminator?{message:"Invalid database type. Expected 'in-memory', 'sqlite', or 'postgres'."}:{message:t.defaultError}}).describe("Database configuration").superRefine((e,t)=>{"postgres"!==e.type||e.url||e.connectionString||e.host||t.addIssue({code:si.eq.custom,message:"PostgreSQL database requires one of 'url', 'connectionString', or 'host' to be specified",path:["url"],params:{code:sf.CONNECTION_CONFIG_MISSING,scope:se.STORAGE,type:st.USER}})}),ss.Ik({query:ss.Yj().describe("The search query to find in conversation history"),mode:ss.k5(["messages","sessions"]).describe('Search mode: "messages" searches for individual messages, "sessions" finds sessions containing the query'),sessionId:ss.Yj().optional().describe('Optional: limit search to a specific session (only for mode="messages")'),role:ss.k5(["user","assistant","system","tool"]).optional().describe('Optional: filter by message role (only for mode="messages")'),limit:ss.ai().optional().default(20).describe('Optional: maximum number of results to return (default: 20, only for mode="messages")'),offset:ss.ai().optional().default(0).describe('Optional: offset for pagination (default: 0, only for mode="messages")')}),ss.Ik({question:ss.Yj().describe("The question or prompt to display to the user"),schema:ss.Ik({type:ss.eu("object"),properties:ss.g1(ss.L5()),required:ss.YO(ss.Yj()).optional()}).passthrough().describe('JSON Schema defining the form structure. Must be an object with "type": "object" and "properties" defining form fields. Use "enum" arrays for dropdowns, "boolean" for yes/no, "number"/"integer" for numeric inputs, "string" for text. Include "required" array for mandatory fields.')}).strict();let sA=["search_history","ask_user"],sE=["event-based","auto-approve","auto-deny"],sT=["memory","storage"],sI="event-based",sO="storage";function sL(e){let{value:t,onChange:s,errors:r={},open:n,onOpenChange:i,errorCount:l=0,sectionErrors:o=[]}=e,c=e=>{s({...t,...e})};return(0,a.jsx)(t1,{title:"Tool Confirmation",defaultOpen:!1,open:n,onOpenChange:i,errorCount:l,sectionErrors:o,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"confirmation-mode",tooltip:"How the agent handles tool execution requests",children:"Confirmation Mode"}),(0,a.jsx)("select",{id:"confirmation-mode",value:t.mode||sI,onChange:e=>c({mode:e.target.value}),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sE.map(e=>(0,a.jsx)("option",{value:e,children:"auto-approve"===e?"Auto-approve":"event-based"===e?"Event-based":"Auto-deny"},e))}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"event-based"===t.mode?"Require explicit approval before executing tools":"auto-deny"===t.mode?"Automatically deny all tool executions":"Automatically approve tool executions"})]}),"event-based"===t.mode&&(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"confirmation-timeout",tooltip:"How long to wait for approval before timing out",children:"Timeout (seconds)"}),(0,a.jsx)(eU.p,{id:"confirmation-timeout",type:"number",value:t.timeout||"",onChange:e=>c({timeout:e.target.value?parseInt(e.target.value,10):void 0}),min:"1",placeholder:"e.g., 60","aria-invalid":!!r["toolConfirmation.timeout"]}),r["toolConfirmation.timeout"]&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:r["toolConfirmation.timeout"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"allowed-tools-storage",tooltip:"Where to store the list of pre-approved tools (memory or persistent storage)",children:"Allowed Tools Storage"}),(0,a.jsx)("select",{id:"allowed-tools-storage",value:t.allowedToolsStorage||sO,onChange:e=>{var r;return r=e.target.value,void s({...t,allowedToolsStorage:r})},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:sT.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})]})})}function sR(e){var t;let{config:s,onChange:r,errors:i={}}=e,l=s.systemPrompt?"string"==typeof s.systemPrompt?{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:s.systemPrompt}]}:{contributors:s.systemPrompt.contributors||[]}:{contributors:[]},[o,c]=(0,n.useState)({basic:!0,llm:!1,systemPrompt:!1,mcpServers:!1,storage:!1,toolConfirmation:!1}),d=function(e){let t={basic:[],llm:[],systemPrompt:[],mcpServers:[],storage:[],toolConfirmation:[]};return Object.entries(e).forEach(e=>{let[s,r]=e;"greeting"===s?t.basic.push(r):s.startsWith("llm.")?t.llm.push(r):s.startsWith("systemPrompt")?t.systemPrompt.push(r):s.startsWith("mcpServers")?t.mcpServers.push(r):s.startsWith("storage.")?t.storage.push(r):s.startsWith("toolConfirmation.")&&t.toolConfirmation.push(r)}),t}(i);(0,n.useEffect)(()=>{let e=Object.keys(d).filter(e=>d[e].length>0);e.length>0&&c(t=>{let s={...t};return e.forEach(e=>{s[e]=!0}),s})},[i]);let m=e=>{c(t=>({...t,[e]:!t[e]}))},u=!!(t=s).sessions&&!!(Object.keys(t.sessions).length>0)||!!t.internalTools;return(0,a.jsxs)("div",{className:"flex flex-col h-full overflow-auto",children:[u&&(0,a.jsx)("div",{className:"mx-4 mt-4 p-3 bg-yellow-500/10 border border-yellow-500/20 rounded-lg",children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)(e9.A,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 mt-0.5 flex-shrink-0"}),(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-500",children:"Advanced Configuration Detected"}),(0,a.jsx)("p",{className:"text-xs text-yellow-600/80 dark:text-yellow-500/80 mt-1",children:"Some advanced features may not be editable in form mode. Switch to YAML editor for full control."})]})]})}),(0,a.jsxs)("div",{className:"flex-1 p-4 space-y-4",children:[(0,a.jsx)(t1,{title:"Basic Information",open:o.basic,onOpenChange:()=>m("basic"),errorCount:d.basic.length,sectionErrors:d.basic,children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(t0,{htmlFor:"agent-greeting",tooltip:"The initial message shown to users when they start a conversation",children:"Greeting Message"}),(0,a.jsx)(eU.p,{id:"agent-greeting",value:s.greeting||"",onChange:e=>r({...s,greeting:e.target.value}),placeholder:"Hello! How can I help you today?","aria-invalid":!!i.greeting}),i.greeting&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:i.greeting})]})}),(0,a.jsx)(t8,{value:s.llm,onChange:e=>{r({...s,llm:e})},errors:i,open:o.llm,onOpenChange:()=>m("llm"),errorCount:d.llm.length,sectionErrors:d.llm}),(0,a.jsx)(t9,{value:l,onChange:e=>{r({...s,systemPrompt:e})},errors:i,open:o.systemPrompt,onOpenChange:()=>m("systemPrompt"),errorCount:d.systemPrompt.length,sectionErrors:d.systemPrompt}),(0,a.jsx)(sp,{value:s.mcpServers||{},onChange:e=>{r({...s,mcpServers:e})},errors:i,open:o.mcpServers,onOpenChange:()=>m("mcpServers"),errorCount:d.mcpServers.length,sectionErrors:d.mcpServers}),(0,a.jsx)(sS,{value:s.storage||{cache:{type:"in-memory"},database:{type:"in-memory"}},onChange:e=>{r({...s,storage:e})},errors:i,open:o.storage,onOpenChange:()=>m("storage"),errorCount:d.storage.length,sectionErrors:d.storage}),(0,a.jsx)(sL,{value:s.toolConfirmation||{},onChange:e=>{r({...s,toolConfirmation:e})},errors:i,open:o.toolConfirmation,onOpenChange:()=>m("toolConfirmation"),errorCount:d.toolConfirmation.length,sectionErrors:d.toolConfirmation})]})]})}function sD(e){let{config:t,onChange:s,errors:r={}}=e;return(0,a.jsx)("div",{className:"flex flex-col h-full",children:(0,a.jsx)(sR,{config:t,onChange:s,errors:r})})}ss.YO(ss.k5(sA).describe("Available internal tool names")).default([]).describe("Array of internal tool names to enable. Empty array = disabled. Available tools: ".concat(sA.join(", "))),ss.Ik({mode:ss.k5(sE).default(sI).describe("Tool confirmation mode: event-based (interactive), auto-approve (all tools), auto-deny (no tools)"),timeout:ss.ai().int().positive().default(12e4).describe("Timeout for tool confirmation requests in milliseconds, defaults to 120000ms (2 mins)"),allowedToolsStorage:ss.k5(sT).default(sO).describe("Storage type for remembered tool approvals: memory (session-only) or storage (persistent)")}).strict().describe("Tool confirmation and approval configuration");var sF=s(3253);let sP="/api";function s_(e){let{isOpen:t,onClose:s,variant:r="overlay"}=e,[i,l]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[u,x]=(0,n.useState)(null),[p,f]=(0,n.useState)(null),[g,v]=(0,n.useState)(null),[w,k]=(0,n.useState)(""),[C,S]=(0,n.useState)("yaml"),[A,E]=(0,n.useState)(null),[T,I]=(0,n.useState)(!1),[O,L]=(0,n.useState)(!1),[R,D]=(0,n.useState)(null),[F,P]=(0,n.useState)(null),[M,z]=(0,n.useState)(!1),[U,B]=(0,n.useState)(""),[q,W]=(0,n.useState)(!1),[K,$]=(0,n.useState)(!0),[V,Y]=(0,n.useState)([]),[J,G]=(0,n.useState)([]),[H,Q]=(0,n.useState)(!1),[Z,X]=(0,n.useState)(!1),ee=(0,n.useRef)(null),et=(0,n.useRef)(0),es=(0,n.useCallback)(async()=>{I(!0),D(null);try{let e=await fetch("".concat(sP,"/agent/config"));if(!e.ok){let t=await e.json().catch(()=>({error:"Failed to load configuration"}));throw Error(t.message||t.error||"Load failed: ".concat(e.statusText))}let t=await e.json();l(t.yaml),d(t.yaml),k(t.relativePath),Q(!1);let{config:s,document:r}=ea(t.yaml);s&&r&&(x(s),f(s),v(r)),await er(t.yaml)}catch(t){let e=t instanceof Error?t.message:String(t);D(e),console.error("Error loading agent config: ".concat(e))}finally{I(!1)}},[]),er=async e=>{let t=et.current+1;et.current=t,W(!0);try{let s=await fetch("".concat(sP,"/agent/validate"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e})}),r=await s.json();et.current===t&&($(r.valid),Y(r.errors||[]),G(r.warnings||[]))}catch(e){console.error("Validation error: ".concat(e instanceof Error?e.message:String(e))),et.current===t&&($(!1),Y([{message:"Failed to validate configuration",code:"VALIDATION_ERROR"}]))}finally{et.current===t&&W(!1)}},ea=e=>{console.log("[parseYamlToConfig] Starting parse");try{let t=sF.Tp(e);if(console.log("[parseYamlToConfig] Document created:",t),t.errors&&t.errors.length>0){console.error("[parseYamlToConfig] Parse errors:",t.errors);let e=t.errors.map(e=>e.message).join("; ");return{config:null,document:null,error:e}}let s=t.toJS();return console.log("[parseYamlToConfig] Config parsed successfully:",s),{config:s,document:t,error:null}}catch(e){return console.error("[parseYamlToConfig] Exception:",e),{config:null,document:null,error:e instanceof Error?e.message:"Failed to parse YAML"}}},en=e=>{if(console.log("[handleModeSwitch] Called with newMode:",e,"current mode:",C),e===C)return void console.log("[handleModeSwitch] Same mode, returning");if("form"===e){console.log("[handleModeSwitch] Switching to form mode, parsing YAML...");let{config:e,document:t,error:s}=ea(i);if(console.log("[handleModeSwitch] Parse result:",{config:e,document:t,error:s}),s){console.error("[handleModeSwitch] Parse error, not switching:",s),E(s);return}console.log("[handleModeSwitch] Parse successful, setting state"),x(e),v(t),E(null)}console.log("[handleModeSwitch] Setting editor mode to:",e),S(e)},ei=async()=>{if(!K||V.length>0)return void P("Cannot save: configuration has errors");L(!0),P(null),z(!1),B("");try{let e=await fetch("".concat(sP,"/agent/config"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:i})});if(!e.ok){let t=await e.json().catch(()=>({error:"Failed to save configuration"}));throw Error(t.message||t.error||"Save failed: ".concat(e.statusText))}let t=await e.json();d(i),Q(!1),z(!0),t.restarted?B("Configuration applied successfully — ".concat(t.changesApplied.join(", ")," updated")):B("Configuration saved successfully (no changes detected)"),setTimeout(()=>{z(!1),B("")},5e3)}catch(t){let e=t instanceof Error?t.message:String(t);P(e),console.error("Error saving agent config: ".concat(e))}finally{L(!1)}},el=()=>{H?X(!0):s()};if((0,n.useEffect)(()=>{t&&es()},[t,es]),(0,n.useEffect)(()=>{if(!t)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),!O&&K&&ei()),"Escape"===e.key&&(e.preventDefault(),el())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,O,K,H]),!t)return null;let eo=(()=>{if(O)return null;if(!H)return"No changes to save";if(V.length>0){let e=V[0];return e.path?"Configuration error in ".concat(e.path,": ").concat(e.message):"Configuration error: ".concat(e.message)}return K?null:"Configuration has validation errors"})(),ec=!H||O||!K||V.length>0,ed=(0,a.jsxs)("div",{className:"flex flex-col h-full bg-background",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("div",{className:"flex items-center gap-3",children:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Customize Agent"}),(0,a.jsxs)("a",{href:"https://docs.dexto.ai/docs/guides/configuring-dexto/overview",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1",title:"View configuration documentation",children:["View docs",(0,a.jsx)(tS.A,{className:"h-3 w-3"})]})]}),w&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:w})]})}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1 bg-muted/50 rounded-md p-1",children:[(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"yaml"===C?"default":"ghost",size:"sm",onClick:()=>en("yaml"),className:"h-7 px-3",children:"YAML Editor"})}),(0,a.jsx)(y,{children:"Edit configuration in raw YAML format with full control"})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"form"===C?"default":"ghost",size:"sm",onClick:()=>en("form"),className:"h-7 px-3",children:"Form Editor"})}),(0,a.jsx)(y,{children:"Edit configuration using user-friendly forms"})]})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>{H?X(!0):es()},disabled:T,children:(0,a.jsx)(tT.A,{className:(0,o.cn)("h-4 w-4",T&&"animate-spin")})})}),(0,a.jsx)(y,{children:"Reload configuration"})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:el,children:(0,a.jsx)(h.A,{className:"h-4 w-4"})})}),(0,a.jsx)(y,{children:"Close (Esc)"})]})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:R?(0,a.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,a.jsxs)("div",{className:"text-center max-w-md",children:[(0,a.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,a.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Failed to load configuration"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:R}),(0,a.jsxs)(N.$,{onClick:es,variant:"outline",children:[(0,a.jsx)(tT.A,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):T?(0,a.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading configuration..."})]})}):A&&"form"===C?(0,a.jsx)("div",{className:"flex items-center justify-center h-full p-4",children:(0,a.jsxs)("div",{className:"text-center max-w-md",children:[(0,a.jsx)(m.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,a.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Cannot parse YAML"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:A}),(0,a.jsx)(N.$,{onClick:()=>S("yaml"),variant:"outline",children:"Switch to YAML Editor"})]})}):"yaml"===C?(0,a.jsx)(tX,{value:i,onChange:e=>{l(e),Q(e!==c),P(null),z(!1);let{config:t,document:s}=ea(e);t&&s&&(x(t),v(s)),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{er(e)},500)},isValidating:q,isValid:K,errors:V,warnings:J,hasUnsavedChanges:H}):u?(0,a.jsx)(sD,{config:u,onChange:e=>{if(console.log("[handleFormChange] Called with new config"),console.log("[handleFormChange] yamlDocument exists?",!!g),!g)return void console.error("[handleFormChange] No document available - this should not happen!");x(e);let t=((e,t)=>{console.log("[serializeConfigToYaml] Starting serialization"),console.log("[serializeConfigToYaml] Document:",t),console.log("[serializeConfigToYaml] Config:",e);let s=(e=>{let t=e=>!!(null==e||""===e||""===e||Array.isArray(e)&&0===e.length)||"object"==typeof e&&null!==e&&"[object Object]"===Object.prototype.toString.call(e)&&0===Object.keys(e).length,s=e=>{if(Array.isArray(e))return e.map(s).filter(e=>!t(e));if("object"==typeof e&&null!==e){let r={};for(let[a,n]of Object.entries(e))if(!t(n))if("object"==typeof n&&null!==n){let e=s(n);t(e)||(r[a]=e)}else r[a]=n;return r}return e};return s(e)})(e);console.log("[serializeConfigToYaml] Cleaned config:",s);let r=((e,t)=>{console.log("[updateYamlDocumentFromConfig] Starting update"),console.log("[updateYamlDocumentFromConfig] Document:",e),console.log("[updateYamlDocumentFromConfig] Config:",t);let s=(t,r)=>{if(null==r||Array.isArray(r))return e.createNode(r);if("object"==typeof r&&!Array.isArray(r)){if(!t||!t.items)return e.createNode(r);let a=new Set;for(let e of t.items){let t=e.key.value;a.add(t),t in r&&(e.value=s(e.value,r[t]))}for(let[s,n]of Object.entries(r))a.has(s)||t.items.push(e.createPair(s,n));return t.items=t.items.filter(e=>e.key.value in r),t}return e.createNode(r)};try{return e.contents=s(e.contents,t),console.log("[updateYamlDocumentFromConfig] Update successful"),e}catch(e){throw console.error("[updateYamlDocumentFromConfig] Update failed:",e),e}})(t,s).toString();return console.log("[serializeConfigToYaml] Serialized result length:",r.length),r})(e,g);l(t),Q(!(e===p||e&&p&&JSON.stringify(e)===JSON.stringify(p))),P(null),z(!1),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{er(t)},500)},errors:V.reduce((e,t)=>(t.path&&(e[t.path]=t.message),e),{})}):null}),!R&&!T&&(0,a.jsxs)("div",{className:"flex flex-col border-t border-border",children:[(M||F)&&(0,a.jsxs)("div",{className:"px-4 py-3 bg-muted/50 border-b border-border",children:[M&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-500",children:[(0,a.jsx)(_.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:U})]}),F&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[(0,a.jsx)(m.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:F})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsx)("div",{}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(N.$,{variant:"outline",size:"sm",onClick:el,children:"Close"}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)("div",{children:(0,a.jsx)(N.$,{variant:"default",size:"sm",onClick:ei,disabled:ec,children:O?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-background border-t-transparent mr-2"}),"Saving..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tG.A,{className:"h-4 w-4 mr-2"}),"Save"]})})})}),(0,a.jsx)(y,{children:eo||"Save configuration (⌘S)"})]})]})]})]}),(0,a.jsx)(eP.lG,{open:Z,onOpenChange:X,children:(0,a.jsxs)(eP.Cf,{children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsx)(eP.L3,{children:"Unsaved Changes"}),(0,a.jsx)(eP.rr,{children:"You have unsaved changes. Do you want to discard them?"})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>X(!1),children:"Cancel"}),(0,a.jsx)(N.$,{variant:"destructive",onClick:()=>{X(!1),l(c),Q(!1),es()},children:"Discard Changes"})]})]})})]});return"inline"===r?ed:(0,a.jsx)("div",{className:(0,o.cn)("fixed inset-y-0 right-0 z-50 w-full sm:w-[600px] md:w-[700px] lg:w-[800px] border-l border-border bg-background shadow-2xl transform transition-transform duration-300",t?"translate-x-0":"translate-x-full"),children:ed})}var sM=s(1740),sz=s(4119),sU=s(4619),sB=s(9040),sq=s(1601),sW=s(6529),sK=s(4454);function s$(){let{theme:e,toggleTheme:t}=function(){let[e,t]=(0,n.useState)(()=>"undefined"!=typeof document?document.documentElement.classList.contains("dark")?"dark":"light":"dark");return(0,n.useEffect)(()=>{if("undefined"!=typeof document){document.documentElement.classList.toggle("dark","dark"===e);try{var t;localStorage.setItem("theme",e);let s=(null==(t=window.location)?void 0:t.protocol)==="https:";document.cookie="theme=".concat(encodeURIComponent(e),"; path=/; max-age=31536000; SameSite=Lax").concat(s?"; Secure":"")}catch(e){}}},[e]),{theme:e,toggleTheme:e=>{t(e?"dark":"light")},hasMounted:!0}}(),[s,r]=(0,n.useState)(!1);(0,n.useEffect)(()=>{r(!0)},[]);let i="dark"===e;return s?(0,a.jsx)(v,{children:(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(ej.bL,{checked:i,onCheckedChange:t,className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full relative transition-colors flex items-center px-0.5","aria-label":"Toggle theme",children:(0,a.jsx)(ej.zi,{className:"\n w-5 h-5 rounded-full shadow flex items-center justify-center\n transition-transform transform\n translate-x-0.5 data-[state=checked]:translate-x-[1.375rem]\n bg-white dark:bg-gray-100\n ",children:i?(0,a.jsx)(sW.A,{className:"w-3.5 h-3.5 text-gray-700"}):(0,a.jsx)(sK.A,{className:"w-3.5 h-3.5 text-yellow-500"})})})}),(0,a.jsx)(y,{children:i?"Switch to light mode":"Switch to dark mode"})]})}):(0,a.jsx)("div",{className:"w-12 h-6 bg-gray-300 dark:bg-gray-700 rounded-full"})}function sV(e){let{active:t=!1}=e,{voices:s,selected:r,setSelected:i}=function(){let[e,t]=(0,n.useState)(T.getVoices()),[s,r]=(0,n.useState)(T.getPreferredVoiceName());return(0,n.useEffect)(()=>{let e=T.subscribeVoices(()=>{t(T.getVoices()),r(T.getPreferredVoiceName())});return()=>e()},[]),{voices:e,selected:s,setSelected:e=>{T.setPreferredVoice(e),r(T.getPreferredVoiceName())}}}(),[l,o]=(0,n.useState)(!1);return((0,n.useEffect)(()=>{if(!t)return void o(!1);let e=window.requestIdleCallback?window.requestIdleCallback(()=>o(!0)):setTimeout(()=>o(!0),0);return()=>{window.cancelIdleCallback&&"number"==typeof e?window.cancelIdleCallback(e):clearTimeout(e)}},[t]),t)?(0,a.jsxs)(ez.l6,{value:null!=r?r:"auto",onValueChange:e=>{i("auto"===e?null:e)},children:[(0,a.jsx)(ez.bq,{className:"h-8 w-[12rem] text-xs",children:(0,a.jsx)(ez.yv,{placeholder:"Voice"})}),(0,a.jsxs)(ez.gC,{children:[(0,a.jsx)(ez.eb,{value:"auto",children:"Auto (best available)"}),l&&s.map(e=>(0,a.jsxs)(ez.eb,{value:e.name,children:[e.name," (",e.lang,")"]},"".concat(e.name,"-").concat(e.lang)))]})]}):null}function sY(e){let{isOpen:t,onClose:s}=e;return(0,a.jsx)(eP.lG,{open:t,onOpenChange:e=>!e&&s(),children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-lg",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsx)(eP.L3,{children:"Settings"}),(0,a.jsx)(eP.rr,{children:"Configure preferences for speech and more."})]}),(0,a.jsx)("div",{className:"space-y-6 py-2",children:(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{className:"text-xs uppercase text-muted-foreground",children:"Voice"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Choose a preferred text-to-speech voice. “Auto” selects the best available voice on your device."}),(0,a.jsx)(sV,{active:t})]})})]})})}var sJ=s(798),sG=s(420);let sH={id:"",name:"",description:"",author:"",tags:""},sQ={llm:{provider:"openai",model:"gpt-5",apiKey:""},systemPrompt:{contributors:[{id:"primary",type:"static",priority:0,enabled:!0,content:""}]}};function sZ(e){let{open:t,onOpenChange:s,onAgentCreated:r}=e,[i,l]=(0,n.useState)(sH),[o,c]=(0,n.useState)(sQ),[d,m]=(0,n.useState)({}),[u,x]=(0,n.useState)(!1),[h,p]=(0,n.useState)(null),[f,g]=(0,n.useState)({basic:!0,llm:!0,systemPrompt:!0}),v=e=>{g(t=>({...t,[e]:!t[e]}))},j=(e,t)=>{l(s=>({...s,[e]:t})),d[e]&&m(t=>{let s={...t};return delete s[e],s})},b=async()=>{if((()=>{var e,t,s;let r={};i.id.trim()?/^[a-z0-9-]+$/.test(i.id)||(r.id="Agent ID must contain only lowercase letters, numbers, and hyphens"):r.id="Agent ID is required",i.name.trim()||(r.name="Agent name is required"),i.description.trim()||(r.description="Description is required"),(null==(e=o.llm)?void 0:e.provider)||(r["llm.provider"]="Provider is required"),(null==(s=o.llm)||null==(t=s.model)?void 0:t.trim())||(r["llm.model"]="Model is required");let a=o.systemPrompt;if(a&&"object"==typeof a&&"contributors"in a){let e=a.contributors;Array.isArray(e)&&(e.some(e=>!!("static"===e.type&&"string"==typeof e.content&&e.content.trim()))||(r.systemPrompt="At least one static contributor with content is required"))}else"string"!=typeof a||a.trim()||(r.systemPrompt="System prompt is required");return m(r),0===Object.keys(r).length})()){x(!0),p(null);try{var e,t,a,n,d;let u="";if(o.systemPrompt&&"object"==typeof o.systemPrompt&&"contributors"in o.systemPrompt){let e=o.systemPrompt.contributors;if(Array.isArray(e)){let t=e.find(e=>"static"===e.type&&e.content);t&&"content"in t&&"string"==typeof t.content&&(u=t.content.trim())}}else"string"==typeof o.systemPrompt&&(u=o.systemPrompt.trim());u||(u="You are a helpful AI assistant.");let x=await fetch("/api/agents/custom/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:i.id.trim(),name:i.name.trim(),description:i.description.trim(),author:i.author.trim()||void 0,tags:i.tags.split(",").map(e=>e.trim()).filter(Boolean),llm:{provider:null==(e=o.llm)?void 0:e.provider,model:null==(a=o.llm)||null==(t=a.model)?void 0:t.trim(),...(null==(d=o.llm)||null==(n=d.apiKey)?void 0:n.trim())&&{apiKey:o.llm.apiKey.trim()}},systemPrompt:u})});if(!x.ok){let e=await x.json().catch(()=>({error:"Failed to create agent"}));throw Error(e.message||e.error||"Creation failed: ".concat(x.statusText))}let h=await x.json();l(sH),c(sQ),m({}),s(!1),r&&h.id&&r(h.id)}catch(e){p(e instanceof Error?e.message:"An unexpected error occurred")}finally{x(!1)}}};return(0,a.jsx)(eP.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(eP.Cf,{className:"max-w-2xl max-h-[90vh] flex flex-col",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsx)(eP.L3,{children:"Create New Agent"}),(0,a.jsxs)(eP.rr,{children:["Create a custom agent with your own configuration.",(0,a.jsx)("br",{}),(0,a.jsx)("br",{}),"You can add more advanced configuration after creating the agent using the Edit Agent button."]})]}),h&&(0,a.jsxs)("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-3 flex items-start gap-2",children:[(0,a.jsx)(e9.A,{className:"h-4 w-4 text-destructive mt-0.5 flex-shrink-0"}),(0,a.jsx)("div",{className:"text-sm text-destructive",children:h})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4 pr-2",children:[(0,a.jsx)(t1,{title:"Basic Information",open:f.basic,onOpenChange:()=>v("basic"),children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"agent-id",tooltip:"Unique identifier for this agent (lowercase, no spaces, hyphens only)",children:"Agent ID *"}),(0,a.jsx)(eU.p,{id:"agent-id",value:i.id,onChange:e=>j("id",e.target.value),placeholder:"my-custom-agent","aria-invalid":!!d.id}),d.id&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:d.id})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"agent-name",tooltip:"Display name for this agent (shown in UI)",children:"Agent Name *"}),(0,a.jsx)(eU.p,{id:"agent-name",value:i.name,onChange:e=>j("name",e.target.value),placeholder:"My Custom Agent","aria-invalid":!!d.name}),d.name&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:d.name})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"agent-description",tooltip:"Brief description of what this agent does",children:"Description *"}),(0,a.jsx)(eU.p,{id:"agent-description",value:i.description,onChange:e=>j("description",e.target.value),placeholder:"A custom agent for specific tasks","aria-invalid":!!d.description}),d.description&&(0,a.jsx)("p",{className:"text-xs text-destructive mt-1",children:d.description})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"agent-author",tooltip:"Your name or organization",children:"Author"}),(0,a.jsx)(eU.p,{id:"agent-author",value:i.author,onChange:e=>j("author",e.target.value),placeholder:"Your Name"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(t0,{htmlFor:"agent-tags",tooltip:"Comma-separated tags for categorization",children:"Tags"}),(0,a.jsx)(eU.p,{id:"agent-tags",value:i.tags,onChange:e=>j("tags",e.target.value),placeholder:"coding, custom, specialized"})]})]})}),(0,a.jsx)(t8,{value:o.llm||{provider:"openai",model:"gpt-5",apiKey:""},onChange:e=>c(t=>({...t,llm:e})),errors:d,open:f.llm,onOpenChange:()=>v("llm"),errorCount:0,sectionErrors:[]}),(0,a.jsx)(t9,{value:"object"==typeof o.systemPrompt&&"contributors"in o.systemPrompt?{contributors:o.systemPrompt.contributors||[]}:{contributors:[]},onChange:e=>c(t=>({...t,systemPrompt:e})),errors:d,open:f.systemPrompt,onOpenChange:()=>v("systemPrompt"),errorCount:0,sectionErrors:[]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>{l(sH),c(sQ),m({}),p(null),s(!1)},disabled:u,children:"Cancel"}),(0,a.jsxs)(N.$,{onClick:b,disabled:u,children:[u&&(0,a.jsx)(M.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Agent"]})]})]})})}function sX(e){let{mode:t="default"}=e,{returnToWelcome:s}=(0,l.v)(),[r,i]=(0,n.useState)([]),[o,c]=(0,n.useState)([]),[d,m]=(0,n.useState)(null),[u,h]=(0,n.useState)(!1),[f,g]=(0,n.useState)(!1),[v,j]=(0,n.useState)(!1),[b,y]=(0,n.useState)(!1),w=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/agents");if(!e.ok)throw Error("Failed to fetch agents");let t=await e.json();return i(t.installed||[]),c(t.available||[]),m(t.current.id),t}catch(e){return console.error("AgentSelector load error: ".concat(e)),null}},[]);(0,n.useEffect)(()=>{h(!0),w().finally(()=>h(!1))},[w]);let k=(0,n.useCallback)(async e=>{try{g(!0);let t=r.find(t=>t.id===e);if(!t)throw console.error("Agent not found in installed list: ".concat(e)),Error("Agent '".concat(e,"' not found. Please refresh the agents list."));let a=await fetch("/api/agents/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!a.ok){let e=await a.json().catch(()=>({}));throw console.error("Agent switch failed: ".concat(JSON.stringify(e))),Error(e.error||e.message||"Switch failed: ".concat(a.status," ").concat(a.statusText))}m(e),j(!1);try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:t.name}}))}catch(e){}s()}catch(t){console.error("Switch agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to switch agent";alert("Failed to switch agent: ".concat(e))}finally{g(!1)}},[s,r]),C=(0,n.useCallback)(async e=>{try{g(!0);let t=await fetch("/api/agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||"Install failed: ".concat(t.status))}let r=await w();if(!r)throw Error("Failed to reload agents list after installation");let a=r.installed.find(t=>t.id===e);if(!a)throw console.error("Agent not found in fresh installed list: ".concat(e)),Error("Agent '".concat(e,"' not found after installation. Please refresh."));let n=await fetch("/api/agents/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!n.ok){let e=await n.json().catch(()=>({}));throw console.error("Agent switch failed: ".concat(JSON.stringify(e))),Error(e.error||e.message||"Switch failed: ".concat(n.status," ").concat(n.statusText))}m(e),j(!1);try{window.dispatchEvent(new CustomEvent("dexto:agentSwitched",{detail:{id:e,name:a.name}}))}catch(e){}s()}catch(t){console.error("Install agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to install agent";alert("Failed to install agent: ".concat(e))}finally{g(!1)}},[w,s]),S=(0,n.useCallback)(async(e,t)=>{if(t.stopPropagation(),confirm('Are you sure you want to delete the custom agent "'.concat(e.name,'"?')))try{g(!0);let t=await fetch("/api/agents/uninstall",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||"Delete failed: ".concat(t.status))}let s=await w();(null==s?void 0:s.current.id)===e.id&&m(null)}catch(t){console.error("Delete agent failed: ".concat(t instanceof Error?t.message:String(t)));let e=t instanceof Error?t.message:"Failed to delete agent";alert("Failed to delete agent: ".concat(e))}finally{g(!1)}},[d,w]),A=(0,n.useCallback)(async e=>{await new Promise(e=>setTimeout(e,1e3)),await w()},[w]),E=(0,n.useMemo)(()=>{var e;if(!d)return"Choose Agent";let t=r.find(e=>e.id===d)||o.find(e=>e.id===d);return null!=(e=null==t?void 0:t.name)?e:d},[o,d,r]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(eS,{open:v,onOpenChange:j,children:[(0,a.jsx)(eA,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"badge"===t?"outline":"default",size:"sm",className:(e=>{let t="transition-all duration-200 shadow-lg hover:shadow-xl font-semibold rounded-full";switch(e){case"badge":return"h-9 px-4 text-xs border border-teal-500 bg-teal-500/20 text-teal-600 hover:bg-teal-500/40 hover:border-teal-500 hover:text-teal-700 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 dark:hover:border-teal-300 min-w-[280px] ".concat(t);case"title":return"h-11 px-4 text-lg font-bold bg-gradient-to-r from-teal-500/30 to-teal-500/40 text-teal-600 hover:from-teal-500/50 hover:to-teal-500/60 hover:text-teal-700 focus-visible:ring-2 focus-visible:ring-teal-500/50 focus-visible:ring-offset-2 border border-teal-500/40 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 ".concat(t);default:return"h-10 px-3 text-sm bg-teal-500/40 text-teal-600 hover:bg-teal-500/50 hover:text-teal-700 focus-visible:ring-2 focus-visible:ring-teal-500/50 focus-visible:ring-offset-2 border border-teal-500/50 dark:text-teal-400 dark:hover:text-teal-300 dark:border-teal-400 ".concat(t)}})(t),disabled:f,children:(0,a.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,a.jsx)(eJ.A,{className:"w-4 h-4 mr-4 flex-shrink-0"}),(0,a.jsx)("span",{className:"flex-1 text-center",children:f?"Switching...":"title"===t?"Agent: ".concat(E):E}),(0,a.jsx)(x.A,{className:"w-4 h-4 ml-2 flex-shrink-0"})]})})}),(0,a.jsxs)(eE,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[u&&(0,a.jsx)(eT,{disabled:!0,className:"text-center text-muted-foreground",children:"Loading agents..."}),!u&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eT,{onClick:()=>{y(!0),j(!1)},disabled:f,className:"cursor-pointer py-3 bg-gradient-to-r from-purple-500/10 to-purple-500/5 hover:from-purple-500/20 hover:to-purple-500/10 border-b border-purple-500/20",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,a.jsx)(ts.A,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),(0,a.jsx)("span",{className:"font-semibold text-purple-600 dark:text-purple-400",children:"New Agent"})]})}),r.filter(e=>"custom"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"px-2 py-1.5 text-xs font-semibold text-purple-600 dark:text-purple-400 uppercase tracking-wider flex items-center gap-1",children:[(0,a.jsx)(sJ.A,{className:"w-3 h-3"}),"Custom Agents"]}),r.filter(e=>"custom"===e.type).map(e=>(0,a.jsx)(eT,{onClick:()=>k(e.id),disabled:f||e.id===d,className:"cursor-pointer py-3",children:(0,a.jsxs)("div",{className:"flex items-center justify-between w-full gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),e.id===d&&(0,a.jsx)(p.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]}),(0,a.jsx)("button",{onClick:t=>S(e,t),disabled:f,className:"p-1 hover:bg-red-100 dark:hover:bg-red-900/30 rounded transition-colors",title:"Delete custom agent",children:(0,a.jsx)(to.A,{className:"w-4 h-4 text-red-600 dark:text-red-400"})})]})},e.id))]}),r.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[r.filter(e=>"custom"===e.type).length>0&&(0,a.jsx)(eI,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Installed"}),r.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eT,{onClick:()=>k(e.id),disabled:f||e.id===d,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),e.id===d&&(0,a.jsx)(p.A,{className:"w-4 h-4 text-green-600 flex-shrink-0 animate-in fade-in duration-200"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]})})},e.id))]}),o.filter(e=>"builtin"===e.type).length>0&&(0,a.jsxs)(a.Fragment,{children:[r.length>0&&(0,a.jsx)(eI,{}),(0,a.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Available"}),o.filter(e=>"builtin"===e.type).map(e=>(0,a.jsx)(eT,{onClick:()=>C(e.id),disabled:f,className:"cursor-pointer py-3",children:(0,a.jsx)("div",{className:"flex items-center justify-between w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),(0,a.jsx)(sG.A,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.author&&(0,a.jsxs)("p",{className:"text-xs text-muted-foreground/80 mt-0.5",children:["by ",e.author]})]})})},e.id))]}),!u&&0===r.length&&0===o.length&&(0,a.jsx)(eT,{disabled:!0,className:"text-center text-muted-foreground",children:"No agents found"})]})]})]}),(0,a.jsx)(sZ,{open:b,onOpenChange:y,onAgentCreated:A})]})}function s0(){let{sessionId:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,i.useRouter)(),[s,r]=(0,n.useState)(!1),{messages:c,sendMessage:d,currentSessionId:u,switchSession:h,isWelcomeState:f,returnToWelcome:g,websocket:v,activeError:w,clearError:k,processing:C,cancel:S,greeting:A}=(0,l.v)(),[E,T]=(0,n.useState)(!1),[I,O]=(0,n.useState)(!1),[L,R]=(0,n.useState)(!1),[P,_]=(0,n.useState)(!1),[M,z]=(0,n.useState)(!1),U=n.useRef(!0),[B,q]=(0,n.useState)(!1),[W,K]=(0,n.useState)(!1),[$,V]=(0,n.useState)(!1),[Y,J]=(0,n.useState)(!1),[G,H]=(0,n.useState)(!1),[Q,Z]=(0,n.useState)("dexto-config"),[X,ee]=(0,n.useState)(null),[et,es]=(0,n.useState)(""),[er,ea]=(0,n.useState)(!1),[en,ei]=(0,n.useState)(null),[el,eo]=(0,n.useState)(!1),[ec,ed]=(0,n.useState)(!1),[eu,ex]=(0,n.useState)(null),[eh,ep]=(0,n.useState)(!1),[ef,eg]=(0,n.useState)(!1),[ev,ej]=(0,n.useState)(null),[eb,ey]=(0,n.useState)(null),[eN,ew]=(0,n.useState)([]),[ek,eC]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!f)return;let e=!1;return eC(!1),(0,tr.y)().then(t=>{e||(ew(t.filter(e=>"starter"===e.source)),eC(!0))}).catch(()=>{e||eC(!0)}),()=>{e=!0}},[f]);let eO=n.useRef(null),eL=n.useRef(null),[eR,eD]=(0,n.useState)(!0),[eF,ez]=(0,n.useState)(!1),[eB,eq]=(0,n.useState)(!1),eW=n.useRef(0),[eK,e$]=(0,n.useState)(!1),eJ=n.useRef(null),[eG,eH]=(0,n.useState)(0),[eQ,eZ]=(0,n.useState)(null),[eX,e0]=(0,n.useState)(!1);(0,n.useEffect)(()=>{"undefined"!=typeof navigator&&/Mac|iPod|iPhone|iPad/.test(navigator.platform)&&r(!0)},[]);let e1=(0,n.useCallback)(()=>{let e=eO.current;e&&eD(e.scrollHeight-e.scrollTop<=e.clientHeight+1)},[]),e2=(0,n.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auto",t=eO.current;t&&(ez(!0),t.scrollTo({top:t.scrollHeight,behavior:e}),requestAnimationFrame(()=>ez(!1)))},[]);(0,n.useEffect)(()=>{let e=eO.current;if(!e)return;let t=()=>{let t=eW.current,s=e.scrollTop;!eF&&eB&&s<t&&eq(!1),eW.current=s,e1(),e.scrollHeight-e.scrollTop<=e.clientHeight+1?(e$(!1),eJ.current&&(window.clearTimeout(eJ.current),eJ.current=null)):(e$(!1),eJ.current&&window.clearTimeout(eJ.current),eJ.current=window.setTimeout(()=>{e$(!0)},180))};return e.addEventListener("scroll",t),e1(),()=>e.removeEventListener("scroll",t)},[e1,eB,eF,f]),(0,n.useEffect)(()=>{let e=eL.current;if(!e)return;let t=new ResizeObserver(()=>{!eF&&(eB||eR)&&e2("auto")});return t.observe(e),()=>t.disconnect()},[eR,eF,eB,e2,f]),(0,n.useEffect)(()=>{eB&&e2("auto")},[eB,c,e2]);let e4=(0,n.useCallback)(()=>{let e=eO.current;if(!e)return;let t=e.querySelectorAll('[data-role="user"]'),s=t[t.length-1];if(!s)return void e2("auto");let r=e.getBoundingClientRect(),a=Math.max(s.getBoundingClientRect().top-r.top+e.scrollTop-16,0);ez(!0),e.scrollTo({top:a,behavior:"auto"}),requestAnimationFrame(()=>ez(!1))},[e2]);(0,n.useEffect)(()=>{W?fetch(u?"/api/agent/config/export?sessionId=".concat(u):"/api/agent/config/export").then(e=>{if(!e.ok)throw Error("Failed to fetch configuration");return e.text()}).then(e=>{es(e),ee(null)}).catch(e=>{console.error("Preview fetch failed:",e),ee(e instanceof Error?e.message:"Preview fetch failed")}):(es(""),ee(null),ea(!1))},[W,u]);let e5=(0,n.useCallback)(async()=>{try{let e=u?"/api/agent/config/export?sessionId=".concat(u):"/api/agent/config/export",t=await fetch(e);if(!t.ok)throw Error("Failed to fetch configuration");let s=await t.text(),r=new Blob([s],{type:"application/x-yaml"}),a=URL.createObjectURL(r),n=document.createElement("a");n.href=a,n.download=u?"".concat(Q,"-").concat(u,".yml"):"".concat(Q,".yml"),document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(a)}catch(e){console.error("Download failed:",e),ee(e instanceof Error?e.message:"Download failed")}},[Q,u]),e3=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(et),ea(!0),setTimeout(()=>ea(!1),2e3)}catch(e){console.error("Copy failed:",e),ee("Failed to copy to clipboard")}},[et]),e8=(0,n.useCallback)(async(e,t,s)=>{eo(!0),ex(null);try{await d(e,t,s),setTimeout(()=>{e4(),eq(!0)},0)}catch(e){console.error("Failed to send message:",e),ex(e instanceof Error?e.message:"Failed to send message"),setTimeout(()=>ex(null),5e3)}finally{eo(!1)}},[d,e4]);(0,n.useEffect)(()=>{let e=()=>eq(!0),t=()=>eq(!1);return window.addEventListener("dexto:message",e),window.addEventListener("dexto:response",t),()=>{window.removeEventListener("dexto:message",e),window.removeEventListener("dexto:response",t)}},[]);let e6=(0,n.useCallback)(e=>{eq(!1),e$(!1),t.push("/chat/".concat(e))},[t]),e9=(0,n.useCallback)(()=>{eq(!1),e$(!1),g(),t.push("/")},[t,g]);(0,n.useEffect)(()=>{z(!0),"true"===localStorage.getItem("sessionsPanelOpen")&&_(!0),setTimeout(()=>{U.current=!1},0)},[]),(0,n.useEffect)(()=>{M&&localStorage.setItem("sessionsPanelOpen",P.toString())},[P,M]),(0,n.useEffect)(()=>{e&&e!==u&&(eq(!1),e$(!1),h(e))},[e,u,h]),(0,n.useEffect)(()=>{e||f||g()},[e,f,g]);let e7=(0,n.useCallback)(async e=>{let t=tP(e),s="stdio"===t.type&&Object.keys(t.env||{}).length>0&&tF(t.env||{}),r=("sse"===t.type||"http"===t.type)&&"headers"in t&&Object.keys(t.headers||{}).length>0&&tF(t.headers||{});if(s||r){var a;return eZ({name:e.name,config:t,lockName:!0,registryEntryId:e.id,onCloseRegistryModal:null!=(a=e.onCloseRegistryModal)?a:()=>O(!1)}),T(!0),"requires-input"}try{e0(!0);let s=await fetch("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,config:t,persistToAgent:!1})}),r=await s.json();if(!s.ok)throw Error(r.error||"Server returned status ".concat(s.status));if(e.id)try{await tf.setInstalled(e.id,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}return eH(e=>e+1),ei("Added ".concat(e.name)),setTimeout(()=>ei(null),4e3),O(!1),"connected"}catch(e){throw Error(e instanceof Error?e.message:"Failed to install server")}finally{e0(!1)}},[O,T,eZ,eH,ei,e0]),te=(0,n.useCallback)(async()=>{if(u){eg(!0);try{if(!(await fetch("/api/sessions/".concat(u),{method:"DELETE"})).ok)throw Error("Failed to delete conversation");ep(!1),e9()}catch(e){console.error("Failed to delete conversation:",e),ex(e instanceof Error?e.message:"Failed to delete conversation"),setTimeout(()=>ex(null),5e3)}finally{eg(!1)}}},[u,e9]),tt=n.useMemo(()=>[{title:"Help me get started",description:"Show me what you can do",action:()=>e8("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:()=>e8("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:()=>R(!0),icon:"\uD83D\uDD27"},{title:"Demonstrate tools",description:"Show me your capabilities",action:()=>e8("Pick one of your most interesting tools and demonstrate it with a practical example. Show me what it can do."),icon:"⚡"}],[e8,R]),ts=n.useMemo(()=>{if(!ek)return tt.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));let e=eN.length>0?[]:tt.map(e=>({description:"".concat(e.icon," ").concat(e.title),tooltip:e.description,action:e.action}));return eN.forEach(t=>{let s=t.title||t.description||"Starter prompt",r=t.description;if((null==t?void 0:t.name)==="starter:connect-tools")e.push({description:s,tooltip:r,action:()=>R(!0)});else{var a;let n=(null==(a=t.metadata)?void 0:a.prompt)||"/".concat(t.name);e.push({description:s,tooltip:r,action:()=>e8(n)})}}),e},[eN,ek,tt,e8,R]);return(0,n.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"Backspace"===e.key&&u&&!f&&(e.preventDefault(),c.length>0?ep(!0):te()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"h"===e.key&&(e.preventDefault(),_(e=>!e)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"k"===e.key&&(e.preventDefault(),e9()),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"j"===e.key&&(e.preventDefault(),R(e=>!e)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"m"===e.key&&(e.preventDefault(),H(e=>!e)),(e.ctrlKey||e.metaKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),e.stopPropagation(),q(!0)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"l"===e.key&&(e.preventDefault(),window.open("/playground","_blank")),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"e"===e.key&&(e.preventDefault(),J(e=>!e)),(e.ctrlKey||e.metaKey)&&e.shiftKey&&"e"===e.key&&(e.preventDefault(),K(!0)),(e.ctrlKey||e.metaKey)&&!e.shiftKey&&"/"===e.key&&(e.preventDefault(),ed(!0)),"Escape"===e.key&&(Y?J(!1):L?R(!1):P?_(!1):G?H(!1):I?O(!1):W?K(!1):ec?ed(!1):eh?ep(!1):eu?ex(null):C&&S(u||void 0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Y,L,P,G,B,I,W,ec,eh,eu,q]),(0,a.jsxs)("div",{className:"flex h-screen bg-background",children:[(0,a.jsx)("div",{className:(0,o.cn)("shrink-0 border-r border-border/50 bg-card/50 backdrop-blur-sm",!U.current&&"transition-all duration-300 ease-in-out",P?"w-80":"w-0 overflow-hidden"),suppressHydrationWarning:!0,children:P&&(0,a.jsx)(tq,{isOpen:P,onClose:()=>_(!1),currentSessionId:u,onSessionChange:e6,returnToWelcome:e9,variant:"inline",onSearchOpen:()=>q(!0),onNewChat:e9})}),(0,a.jsxs)("main",{className:"flex-1 flex flex-col relative",style:{"--thread-max-width":"54rem"},children:[null,(0,a.jsx)("header",{className:"shrink-0 border-b border-border/50 bg-background/95 backdrop-blur-xl shadow-sm",children:(0,a.jsxs)("div",{className:"grid grid-cols-3 items-center px-4 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>_(!P),className:(0,o.cn)("h-8 w-8 p-0 transition-colors",P&&"bg-muted"),children:(0,a.jsx)(sM.A,{className:"h-4 w-4"})})}),(0,a.jsx)(y,{children:"Chat History (⌘H)"})]}),!P&&(0,a.jsx)(tB,{onClick:e9}),(0,a.jsxs)("a",{href:"https://dexto.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center space-x-3 hover:opacity-80 transition-opacity",children:[(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo_light.svg",alt:"Dexto",className:"h-12 w-auto dark:hidden"}),(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo.svg",alt:"Dexto",className:"h-12 w-auto hidden dark:block"}),(0,a.jsx)("span",{className:"sr-only",children:"Dexto"})]})]}),(0,a.jsx)("div",{className:"flex justify-center flex-1 max-w-2xl mx-auto",children:(0,a.jsx)(sX,{mode:"badge"})}),(0,a.jsxs)("div",{className:"flex items-center justify-end",children:[(0,a.jsx)("div",{className:"mr-4",children:(0,a.jsx)(s$,{})}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>J(!Y),className:(0,o.cn)("h-8 w-8 p-0",Y&&"bg-muted"),"aria-label":"Customize agent",children:(0,a.jsx)(sz.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(y,{children:"Customize Agent (⌘E)"})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",onClick:()=>V(!0),className:"h-8 w-8 p-0","aria-label":"Open settings",children:(0,a.jsx)(tV.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(y,{children:"Settings"})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>H(!G),className:(0,o.cn)("h-8 px-2 text-sm transition-colors",G&&"bg-muted"),children:[(0,a.jsx)(F.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{className:"hidden sm:inline ml-1.5",children:"Memories"})]})}),(0,a.jsx)(y,{children:"Toggle memories panel (⌘M)"})]}),(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:()=>R(!L),className:(0,o.cn)("h-8 px-2 text-sm transition-colors",L&&"bg-muted"),children:[(0,a.jsx)(D.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{className:"hidden sm:inline ml-1.5",children:"Tools"})]})}),(0,a.jsx)(y,{children:"Toggle tools panel (⌘J)"})]}),(0,a.jsxs)(eS,{children:[(0,a.jsx)(eA,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:(0,a.jsx)(sU.A,{className:"h-3.5 w-3.5"})})}),(0,a.jsxs)(eE,{align:"end",children:[(0,a.jsxs)(eT,{onClick:()=>O(!0),children:[(0,a.jsx)(ty.A,{className:"h-4 w-4 mr-2"}),"Connect MCPs"]}),(0,a.jsxs)(eT,{onClick:()=>window.open("/playground","_blank"),children:[(0,a.jsx)(eY.A,{className:"h-4 w-4 mr-2"}),"MCP Playground"]}),(0,a.jsxs)(eT,{onClick:()=>K(!0),children:[(0,a.jsx)(sB.A,{className:"h-4 w-4 mr-2"}),"Export Config"]}),(0,a.jsxs)(eT,{onClick:()=>ed(!0),children:[(0,a.jsx)(sq.A,{className:"h-4 w-4 mr-2"}),"Shortcuts"]}),u&&!f&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eI,{}),(0,a.jsxs)(eT,{onClick:()=>ep(!0),className:"text-destructive focus:text-destructive",children:[(0,a.jsx)(to.A,{className:"h-4 w-4 mr-2"}),"Delete Conversation"]})]})]})]})]})]})]})}),(0,a.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[en&&(0,a.jsxs)("div",{className:"fixed bottom-4 right-4 z-50 border border-border/60 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 text-foreground px-3 py-2 rounded-md shadow-md inline-flex items-center gap-2",children:[(0,a.jsx)(p.A,{className:"h-4 w-4 text-green-600"}),(0,a.jsx)("span",{className:"text-sm",children:en})]}),eu&&(0,a.jsx)("div",{className:"absolute top-4 right-4 z-50 bg-destructive text-destructive-foreground px-4 py-2 rounded-md shadow-lg",children:eu}),(0,a.jsx)("div",{className:"flex-1 flex flex-col min-h-0",children:f?(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center p-6 -mt-20",children:(0,a.jsxs)("div",{className:"w-full max-w-[var(--thread-max-width)] mx-auto space-y-6",children:[(0,a.jsxs)("div",{className:"text-center space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,a.jsx)("img",{src:"/logos/dexto/dexto_logo_icon.svg",alt:"Dexto",className:"h-12 w-auto"}),(0,a.jsx)("h2",{className:"text-2xl font-bold font-mono tracking-tight bg-gradient-to-r from-primary to-primary/70 bg-clip-text text-transparent",children:A||"Welcome to Dexto"})]}),(0,a.jsx)("p",{className:"text-base text-muted-foreground max-w-xl mx-auto leading-relaxed",children:"Your AI assistant with powerful tools. Ask anything or connect new capabilities."})]}),(0,a.jsx)("div",{className:"flex flex-wrap justify-center gap-2 max-w-[var(--thread-max-width)] mx-auto",children:ts.map((e,t)=>{let s=(0,a.jsx)("button",{onClick:e.action,className:"group px-3 py-2 text-left rounded-full bg-primary/5 hover:bg-primary/10 transition-all duration-200 hover:shadow-sm hover:scale-105",children:(0,a.jsx)("span",{className:"font-medium text-sm text-primary group-hover:text-primary/80 transition-colors",children:e.description})},t);return e.tooltip?(0,a.jsxs)(j,{children:[(0,a.jsx)(b,{asChild:!0,children:s}),(0,a.jsx)(y,{children:e.tooltip})]},t):s})}),(0,a.jsx)("div",{className:"max-w-[var(--thread-max-width)] mx-auto",children:(0,a.jsx)(tu,{onSend:e8,isSending:el,variant:"welcome"})}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground space-y-1 text-center",children:(0,a.jsxs)("p",{children:["\uD83D\uDCA1 Try",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘K"})," for new chat,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘J"})," for tools,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘L"})," for playground,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:s?"⌘⌫":"Ctrl+⌫"})," to delete session,",(0,a.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded text-xs ml-1",children:"⌘/"})," for shortcuts"]})})]})}):(0,a.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,a.jsx)("div",{ref:eO,className:"h-full overflow-y-auto overscroll-contain relative",children:(0,a.jsxs)("div",{className:"min-h-full grid grid-rows-[1fr_auto]",children:[(0,a.jsx)("div",{className:"w-full max-w-[var(--thread-max-width)] mx-auto",children:(0,a.jsx)(em,{messages:c,activeError:w,onDismissError:k,outerRef:eL,pendingApproval:ev,onApprovalApprove:null==eb?void 0:eb.onApprove,onApprovalDeny:null==eb?void 0:eb.onDeny})}),(0,a.jsxs)("div",{className:"sticky bottom-0 z-10 px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+16px)] bg-background relative",children:[eK&&(0,a.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 -top-3 z-20 pointer-events-none",children:(0,a.jsxs)("button",{onClick:()=>{e$(!1),e2("smooth")},className:"pointer-events-auto px-3 py-1.5 rounded-full shadow-sm bg-background/95 border border-border/60 backdrop-blur supports-[backdrop-filter]:bg-background/80 text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1.5",children:[(0,a.jsx)("span",{children:"Scroll to bottom"}),(0,a.jsx)(x.A,{className:"h-3.5 w-3.5"})]})}),(0,a.jsx)("div",{className:"w-full max-w-[var(--thread-max-width)] mx-auto pointer-events-auto",children:(0,a.jsx)(tu,{onSend:e8,isSending:el,variant:"chat"})})]})]})})})}),(0,a.jsx)("div",{className:(0,o.cn)("shrink-0 transition-all duration-300 ease-in-out border-l border-border/50 bg-card/50 backdrop-blur-sm",L?"w-80":"w-0 overflow-hidden"),children:L&&(0,a.jsx)(tM,{isOpen:L,onClose:()=>R(!1),onOpenConnectModal:()=>T(!0),onOpenConnectWithPrefill:e=>{eZ(e),T(!0)},onServerConnected:e=>{eH(e=>e+1),ei("Added ".concat(e)),setTimeout(()=>ei(null),4e3)},variant:"inline",refreshTrigger:eG})})]}),(0,a.jsx)(s_,{isOpen:Y,onClose:()=>J(!1),variant:"overlay"}),(0,a.jsx)(tx.A,{isOpen:E,onClose:()=>{T(!1),e0(!1),eZ(null)},onServerConnected:async()=>{var e;if(null==eQ?void 0:eQ.registryEntryId)try{await tf.setInstalled(eQ.registryEntryId,!0)}catch(e){console.warn("Failed to mark registry entry installed:",e)}eH(e=>e+1);let t=(null==eQ?void 0:eQ.name)||"Server";ei("Added ".concat(t)),setTimeout(()=>ei(null),4e3),null==eQ||null==(e=eQ.onCloseRegistryModal)||e.call(eQ),e0(!1),eZ(null)},initialName:null==eQ?void 0:eQ.name,initialConfig:null==eQ?void 0:eQ.config,lockName:null==eQ?void 0:eQ.lockName}),(0,a.jsx)(tE,{isOpen:I,onClose:()=>O(!1),onInstallServer:e7,onOpenConnectModal:()=>T(!0),refreshTrigger:eG,disableClose:eX}),(0,a.jsx)(eP.lG,{open:W,onOpenChange:K,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-2xl",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsxs)(eP.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(sB.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{children:"Export Configuration"})]}),(0,a.jsxs)(eP.rr,{children:["Download your tool configuration for Claude Desktop or other MCP clients",u&&(0,a.jsxs)("span",{className:"block mt-1 text-sm text-muted-foreground",children:["Including session-specific settings for: ",(0,a.jsx)("span",{className:"font-mono",children:u})]})]})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{htmlFor:"filename",children:"File name"}),(0,a.jsx)(eU.p,{id:"filename",value:Q,onChange:e=>Z(e.target.value),placeholder:"dexto-config",className:"font-mono"})]}),X&&(0,a.jsxs)(eM.Fc,{variant:"destructive",children:[(0,a.jsx)(m.A,{className:"h-4 w-4"}),(0,a.jsx)(eM.XL,{children:"Export Error"}),(0,a.jsx)(eM.TN,{children:X})]}),et&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(e_.J,{children:"Configuration Preview"}),(0,a.jsx)(ti.T,{value:et,readOnly:!0,className:"h-32 font-mono text-xs bg-muted/30"})]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:e3,className:"flex items-center space-x-2",children:(0,a.jsx)("span",{children:er?"Copied!":"Copy"})}),(0,a.jsxs)(N.$,{onClick:e5,className:"flex items-center space-x-2",children:[(0,a.jsx)(sB.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:"Download"})]})]})]})}),(0,a.jsx)(sY,{isOpen:$,onClose:()=>V(!1)}),(0,a.jsx)(tK,{isOpen:G,onClose:()=>H(!1),variant:"modal"}),(0,a.jsx)(eP.lG,{open:eh,onOpenChange:ep,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(eP.c7,{children:[(0,a.jsxs)(eP.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-5 w-5 text-destructive"}),(0,a.jsx)("span",{children:"Delete Conversation"})]}),(0,a.jsxs)(eP.rr,{children:["This will permanently delete this conversation and all its messages. This action cannot be undone.",u&&(0,a.jsxs)("span",{className:"block mt-2 font-medium",children:["Session: ",(0,a.jsx)("span",{className:"font-mono",children:u})]})]})]}),(0,a.jsxs)(eP.Es,{children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>ep(!1),children:"Cancel"}),(0,a.jsxs)(N.$,{variant:"destructive",onClick:te,disabled:ef,className:"flex items-center space-x-2",children:[(0,a.jsx)(to.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:ef?"Deleting...":"Delete Conversation"})]})]})]})}),(0,a.jsx)(eP.lG,{open:ec,onOpenChange:ed,children:(0,a.jsxs)(eP.Cf,{className:"sm:max-w-md",children:[(0,a.jsx)(eP.c7,{children:(0,a.jsxs)(eP.L3,{className:"flex items-center space-x-2",children:[(0,a.jsx)(sq.A,{className:"h-5 w-5"}),(0,a.jsx)("span",{children:"Keyboard Shortcuts"})]})}),(0,a.jsx)("div",{className:"space-y-3",children:[{key:"⌘H",desc:"Toggle chat history panel"},{key:"⌘K",desc:"Create new chat"},{key:"⌘J",desc:"Toggle tools panel"},{key:"⌘M",desc:"Toggle memories panel"},{key:"⌘E",desc:"Customize agent"},{key:"⌘⇧S",desc:"Search conversations"},{key:"⌘L",desc:"Open MCP playground"},{key:"⌘⇧E",desc:"Export config"},{key:"⌘/",desc:"Show shortcuts"},{key:s?"⌘⌫":"Ctrl+⌫",desc:"Delete current session"},{key:"Esc",desc:"Close panels"}].map((e,t)=>(0,a.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:e.desc}),(0,a.jsx)(eV.E,{variant:"outline",className:"font-mono text-xs",children:e.key})]},t))}),(0,a.jsx)(eP.Es,{children:(0,a.jsx)(eP.HM,{asChild:!0,children:(0,a.jsx)(N.$,{variant:"outline",children:"Close"})})})]})})]}),(0,a.jsx)(tJ,{isOpen:B,onClose:()=>q(!1),onNavigateToSession:(e,s)=>{t.push("/chat/".concat(e)),q(!1)}}),(0,a.jsx)(t$,{websocket:v,onApprovalRequest:ej,onHandlersReady:ey})]})}},9419:(e,t,s)=>{Promise.resolve().then(s.bind(s,8992))}}]);