blade-code 0.10.3 → 0.10.4

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 (55) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-r4pz99sy.js → chunk-1ndryz4h.js} +1 -1
  3. package/dist/{chunk-xdbg7cn3.js → chunk-5t0vs4hz.js} +1 -1
  4. package/dist/{chunk-c05t8207.js → chunk-5ze48kg7.js} +1 -1
  5. package/dist/{chunk-9yytfg19.js → chunk-90fnvvcf.js} +1 -1
  6. package/dist/{chunk-3wp3h373.js → chunk-9kwt0w46.js} +1 -1
  7. package/dist/{chunk-c45y8tx1.js → chunk-a7a74pza.js} +74 -74
  8. package/dist/{chunk-bfw2p0x8.js → chunk-age5tc86.js} +3 -3
  9. package/dist/{chunk-7hqbwpt5.js → chunk-b9v7waxf.js} +1 -1
  10. package/dist/{chunk-bn148dr5.js → chunk-csr5vppa.js} +8 -8
  11. package/dist/{chunk-p5tpzh6f.js → chunk-d4zw0xxe.js} +1 -1
  12. package/dist/chunk-d5a66cgn.js +160 -0
  13. package/dist/{chunk-5fxc90rb.js → chunk-d7xb0vp1.js} +1 -1
  14. package/dist/{chunk-vmg5n0zv.js → chunk-f647z66n.js} +1 -1
  15. package/dist/{chunk-eezg6pee.js → chunk-ffp3ypbb.js} +1 -1
  16. package/dist/{chunk-7089z4e1.js → chunk-fx87s3mb.js} +1 -1
  17. package/dist/chunk-g6h6h8xr.js +1 -0
  18. package/dist/chunk-jbnrscvz.js +1 -0
  19. package/dist/{chunk-aa0ffw17.js → chunk-kkd7mm55.js} +1 -1
  20. package/dist/{chunk-wje6bck2.js → chunk-mxqpg4gy.js} +1 -1
  21. package/dist/{chunk-zq9r0jx3.js → chunk-n2s54h1r.js} +1 -1
  22. package/dist/{chunk-jqwntnp1.js → chunk-nr53mq0k.js} +1 -1
  23. package/dist/{chunk-8th744ef.js → chunk-pehpndk9.js} +1 -1
  24. package/dist/{chunk-s95rgkd8.js → chunk-rv80ak15.js} +1 -1
  25. package/dist/{chunk-1g5qc1qx.js → chunk-scq3ns6v.js} +1 -1
  26. package/dist/{chunk-1cx96gx1.js → chunk-tx8f345j.js} +1 -1
  27. package/dist/{chunk-nxj1638n.js → chunk-v8kp3ep9.js} +1 -1
  28. package/dist/{chunk-rcdynprn.js → chunk-ve9cke2g.js} +2 -2
  29. package/dist/{chunk-vwq9s5nj.js → chunk-vxymgh8e.js} +4 -4
  30. package/dist/{chunk-da1jvzbz.js → chunk-wdbmbk6h.js} +1 -1
  31. package/dist/{chunk-pnrx3spk.js → chunk-xkzy5wbm.js} +1 -1
  32. package/dist/{chunk-grp43mdb.js → chunk-xq8vf15n.js} +1 -1
  33. package/dist/chunk-ys8bp9jm.js +1 -0
  34. package/dist/chunk-zswrw5f9.js +3 -0
  35. package/dist/web/assets/{ChatView-Pqa25Vua.js → ChatView-iK7ff8qU.js} +2 -2
  36. package/dist/web/assets/{CodeBlockHighlighter-Dxt-FWJk.js → CodeBlockHighlighter-BoJp_Xb0.js} +1 -1
  37. package/dist/web/assets/{FilePreview-Dj2yppPn.js → FilePreview-Bi1HWOvY.js} +2 -2
  38. package/dist/web/assets/{MarkdownRenderer-BI2xpTV2.js → MarkdownRenderer-DMW1pg5N.js} +12 -12
  39. package/dist/web/assets/{McpModal-COw0BcHJ.js → McpModal-CHUqitJ6.js} +1 -1
  40. package/dist/web/assets/SettingsModal-zsS9O6SW.js +1 -0
  41. package/dist/web/assets/{SkillsModal-CTZTu9xg.js → SkillsModal-C2oTDXoy.js} +1 -1
  42. package/dist/web/assets/{TaskSwitcher-DPXkV-qb.js → TaskSwitcher-CncVasNA.js} +1 -1
  43. package/dist/web/assets/{TerminalPanel-tpUxwaCh.js → TerminalPanel-CBi2mUxx.js} +1 -1
  44. package/dist/web/assets/index-B7etZcne.css +1 -0
  45. package/dist/web/assets/index-DvDtvgA4.js +32 -0
  46. package/dist/web/index.html +2 -2
  47. package/package.json +1 -1
  48. package/dist/chunk-8thp1nep.js +0 -1
  49. package/dist/chunk-9p5f3ryf.js +0 -1
  50. package/dist/chunk-mgwny24b.js +0 -160
  51. package/dist/chunk-n3y9ytvg.js +0 -3
  52. package/dist/chunk-r4j5ca1h.js +0 -1
  53. package/dist/web/assets/SettingsModal-h4AxN730.js +0 -1
  54. package/dist/web/assets/index-Dep3eEsS.css +0 -1
  55. package/dist/web/assets/index-bjyn3NHs.js +0 -32
@@ -1,4 +1,4 @@
1
- import{r,j as e}from"./vendor-react-DG5dkZ_t.js";import{_ as $,n as P,o as Se,p as Fe,q as se}from"./vendor-radix-DBy9B2DN.js";import{i as Ze,a as Xe,d as Me,u as $e,b as ze,c as et,e as de,f as oe,g as tt}from"./useRequest-BvqVDnKl.js";import{b as at,D as he,e as be,F as nt,g as ge,j as w,x as L,y as rt}from"./index-bjyn3NHs.js";import{a as Be,i as st,X as ve,f as De,L as le,k as ot,Z as Te,C as lt,D as dt}from"./vendor-icons-D_AkWmWB.js";function ie(n,s){if(Ze){if(!n)return s;var o;return Xe(n)?o=n():"current"in n?o=n.current:o=n,o}}var it=function(n){var s=function(o,u,f){var x=r.useRef(!1),c=r.useRef([]),p=r.useRef([]),h=r.useRef(void 0);n(function(){var b,S=Array.isArray(f)?f:[f],g=S.map(function(j){return ie(j)});if(!x.current){x.current=!0,c.current=g,p.current=u,h.current=o();return}(g.length!==c.current.length||!Me(c.current,g)||!Me(p.current,u))&&((b=h.current)===null||b===void 0||b.call(h),c.current=g,p.current=u,h.current=o())}),$e(function(){var b;(b=h.current)===null||b===void 0||b.call(h),x.current=!1})};return s},ct=it(r.useEffect);function xt(){var n=(typeof global>"u"?"undefined":typeof global)=="object"&&global&&global.Object===Object&&global,s=typeof self=="object"&&self&&self.Object===Object&&self;return n||s}xt()||(global.Date=Date);function mt(n,s){var o,u=ze(n),f=(o=s==null?void 0:s.wait)!==null&&o!==void 0?o:1e3,x=r.useMemo(function(){return et(function(){for(var c=[],p=0;p<arguments.length;p++)c[p]=arguments[p];return u.current.apply(u,$([],P(c),!1))},f,s)},[]);return $e(function(){x.cancel()}),{run:x,cancel:x.cancel,flush:x.flush}}function ut(n,s,o){o===void 0&&(o={});var u=o.enable,f=u===void 0?!0:u,x=ze(s);ct(function(){if(f){var c=ie(o.target,window);if(c!=null&&c.addEventListener){var p=function(b){return x.current(b)},h=Array.isArray(n)?n:[n];return h.forEach(function(b){c.addEventListener(b,p,{capture:o.capture,once:o.once,passive:o.passive})}),function(){h.forEach(function(b){c.removeEventListener(b,p,{capture:o.capture})})}}}},[n,o.capture,o.once,o.passive,f],o.target)}var ft=function(n){return n===document||n===document.documentElement||n===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):n.scrollTop},Pe=function(n){return n.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},pt=function(n){return n.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},ht=function(n,s){s===void 0&&(s={});var o=s.target,u=s.isNoMore,f=s.threshold,x=f===void 0?100:f,c=s.direction,p=c===void 0?"bottom":c,h=s.reloadDeps,b=h===void 0?[]:h,S=s.manual,g=s.onBefore,j=s.onSuccess,C=s.onError,d=s.onFinally,F=P(r.useState(),2),M=F[0],O=F[1],N=P(r.useState(!1),2),z=N[0],R=N[1],U=p==="top",D=r.useRef(void 0),_=r.useRef(0),H=r.useMemo(function(){return u?u(M):!1},[M]),I=de(function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,n(m)];case 1:return v=k.sent(),[2,{currentData:v,lastData:m}]}})})},{manual:S,onFinally:function(m,v,k){R(!1),d==null||d(v==null?void 0:v.currentData,k)},onBefore:function(){return g==null?void 0:g()},onSuccess:function(m){var v,k,E;m.lastData?O(se(se({},m.currentData),{list:U?$($([],P(m.currentData.list),!1),P((k=m.lastData.list)!==null&&k!==void 0?k:[]),!1):$($([],P((E=m.lastData.list)!==null&&E!==void 0?E:[]),!1),P(m.currentData.list),!1)})):O(se(se({},m.currentData),{list:$([],P((v=m.currentData.list)!==null&&v!==void 0?v:[]),!1)})),setTimeout(function(){requestAnimationFrame(function(){if(U){var y=ie(o);if(y=y===document?document.documentElement:y,y){var ee=Pe(y);y.scrollTo(0,ee-_.current)}}else W()})}),j==null||j(m.currentData)},onError:function(m){return C==null?void 0:C(m)}}),Y=I.loading,J=I.error,K=I.run,q=I.runAsync,ce=I.cancel,Q=oe(function(){H||(R(!0),K(M))}),Z=function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,q(m)];case 1:return v=k.sent(),[2,v.currentData]}})})},xe=oe(function(){return H?Promise.reject():(R(!0),Z(M))}),me=function(){return R(!1),K()},X=function(){return R(!1),Z()},W=function(){var m=ie(o);if(m){var v=m===document?document.documentElement:m,k=ft(v),E=Pe(v),y=pt(v);U?(D.current!==void 0&&D.current>k&&k<=x&&Q(),D.current=k,_.current=E-k):E-k<=y+x&&Q()}};return ut("scroll",function(){Y||z||W()},{target:o}),tt(function(){K()},$([],P(b),!1)),{data:M,loading:!z&&Y,error:J,loadingMore:z,noMore:H,loadMore:Q,loadMoreAsync:xe,reload:oe(me),reloadAsync:oe(X),mutate:O,cancel:ce}};const Le={connected:"text-[#16A34A] dark:text-[#22C55E]",connecting:"text-[#2563eb] dark:text-[#3b82f6]",reconnecting:"text-[#2563eb] dark:text-[#60a5fa]",offline:"text-[#f59e0b]",error:"text-[#ef4444]"},bt={connected:"Connected",connecting:"Connecting...",reconnecting:"Recovering...",offline:"Offline",error:"Error"},gt={disabled:"Not configured",unavailable:"Unavailable in this runtime",unauthenticated:"Authorization required",authorizing:"Waiting for authorization...",authenticated:"Authorized",error:"Authorization failed"},Oe=20,vt=["debug","info","notice","warning","error","critical","alert","emergency"],Re=n=>n.status!=="reconnecting"||!n.recovery?bt[n.status]:`Recovering ${n.recovery.attempt}/${n.recovery.maxAttempts}`,kt=async()=>L("/mcp"),Et=async n=>L(`/mcp/${encodeURIComponent(n)}/logs?limit=20`),jt="mcp server @modelcontextprotocol",Nt=3,Ue=n=>{var s;return((s=n.split("/").pop())==null?void 0:s.replace(/^server-/,""))||n},Ct=async(n,s)=>{const o=n&&n.length>=Nt?n:jt,u=`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(o)}&size=${Oe}&from=${s}`,f=await L(u);return{list:f.objects.map(x=>x.package),total:f.total,hasMore:s+Oe<f.total}};function Dt(){const{isMcpOpen:n,toggleMcp:s}=at(),[o,u]=r.useState("installed"),[f,x]=r.useState(!1),[c,p]=r.useState(null),[h,b]=r.useState(""),[S,g]=r.useState(null),[j,C]=r.useState(null),[d,F]=r.useState(null),[M,O]=r.useState(null),[N,z]=r.useState(null),[R,U]=r.useState(""),[D,_]=r.useState(null),[H,I]=r.useState(!1),[Y,J]=r.useState(null),[K,q]=r.useState(null),[ce,Q]=r.useState(""),[Z,xe]=r.useState(""),[me,X]=r.useState(null),[W,m]=r.useState(null),v=r.useRef(null),{run:k}=mt(t=>{xe(t)},{wait:500}),{data:E=[],loading:y,error:ee,run:ke,runAsync:G}=de(kt,{refreshDeps:[n],ready:n,onSuccess:t=>{t.length>0&&!c&&p(t[0].id)}}),{data:ae,loading:ue,error:Ee,runAsync:ne}=de(Et,{manual:!0}),{data:A,loading:He,loadingMore:Je,noMore:qe,error:je,reload:Ne}=ht(async t=>{var l;const i=((l=t==null?void 0:t.list)==null?void 0:l.length)??0;return Ct(Z,i)},{target:v,isNoMore:t=>!(t!=null&&t.hasMore),reloadDeps:[Z],manual:!n||o!=="catalog"}),{runAsync:Ce,loading:ye,error:V}=de(async t=>{await L("/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,config:t})})},{manual:!0,onSuccess:()=>{G(),x(!1),m(null),X(null)},onError:()=>{X(null)}}),te=r.useMemo(()=>{const t=h.trim().toLowerCase();return t?E.filter(i=>[i.name,i.endpoint,i.description].some(l=>l.toLowerCase().includes(t))):E},[h,E]),a=r.useMemo(()=>te.find(t=>t.id===c)??te[0],[te,c]),re=r.useMemo(()=>{if(!a)return[];const t=(a.prompts??[]).flatMap(l=>l.arguments.map(B=>({key:`prompt:${l.name}:${B.name}`,label:`${l.name}.${B.name}`,reference:{type:"prompt",name:l.name},argument:B.name}))),i=(a.resourceTemplates??[]).flatMap(l=>(l.variables??[]).map(B=>({key:`resource:${l.uriTemplate}:${B}`,label:`${l.uriTemplate} · ${B}`,reference:{type:"resource",uri:l.uriTemplate},argument:B})));return[...t,...i]},[a]),T=re.find(t=>t.key===N)??re[0];r.useEffect(()=>{if(!n||!E.some(i=>i.oauthStatus==="authorizing"||i.status==="connecting"||i.status==="reconnecting"))return;const t=window.setInterval(()=>{G()},1e3);return()=>window.clearInterval(t)},[n,G,E]),r.useEffect(()=>{j&&E.some(t=>t.name===j.serverName&&(t.oauthStatus==="authenticated"||t.oauthStatus==="disabled"||t.oauthStatus==="unavailable"))&&C(null)},[j,E]),r.useEffect(()=>{!n||o!=="installed"||!a||ne(a.name).catch(()=>{})},[n,ne,a,o]);const fe=async(t,i)=>{F({type:t,name:i}),g(null);try{const l=t==="delete"?"":`/${t}`;await L(`/mcp/${encodeURIComponent(i)}${l}`,{method:t==="delete"?"DELETE":"POST"}),await G(),t==="delete"&&(q(null),p(null))}catch(l){g(l instanceof Error?l.message:`Failed to ${t} server`)}finally{F(null)}},pe=async(t,i)=>{F({type:t,name:i.name}),g(null);try{if(t==="login"){const l=await L(`/mcp/${encodeURIComponent(i.name)}/oauth/login`,{method:"POST"});C({serverName:i.name,url:l.authorizationUrl})}else await L(`/mcp/${encodeURIComponent(i.name)}/oauth/logout`,{method:"POST"}),C(null);await G()}catch(l){g(l instanceof Error?l.message:`Failed to ${t} MCP OAuth`)}finally{F(null)}},We=async(t,i)=>{O(i),g(null);try{await L(`/mcp/${encodeURIComponent(t.name)}/logging-level`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:i})}),await G(),ne(t.name).catch(()=>{})}catch(l){g(l instanceof Error?l.message:"Failed to set MCP logging level")}finally{O(null)}},Ge=async t=>{if(T){I(!0),J(null),_(null);try{const i=await L(`/mcp/${encodeURIComponent(t.name)}/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reference:T.reference,argument:{name:T.argument,value:R}})});_(i)}catch(i){J(i instanceof Error?i.message:"MCP completion failed")}finally{I(!1)}}},Ve=r.useMemo(()=>new Set(E.map(t=>t.name.toLowerCase())),[E]),Ye=t=>{m(t)},Ke=t=>t.startsWith("@modelcontextprotocol/"),Qe=t=>Ke(t.name)?"Official":"Community";return e.jsxs(e.Fragment,{children:[e.jsx(he,{open:n,onOpenChange:s,children:e.jsxs(be,{onCloseAutoFocus:nt,className:"flex h-[min(680px,calc(100dvh-24px))] flex-col gap-0 overflow-hidden rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[900px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(ge,{className:"sr-only",children:"MCP"}),e.jsx("div",{className:"flex flex-1 min-h-0",children:e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-4 p-4 min-h-0 sm:gap-5 sm:p-8",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"MCP"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:ke,"aria-label":"Refresh MCP servers",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",disabled:y,children:e.jsx(Be,{className:w("h-4 w-4",y&&"animate-spin")})}),e.jsxs("button",{"data-mcp-add-server-trigger":!0,onClick:()=>x(!0),className:"h-8 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-xs font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a]",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Add server"]}),e.jsx("button",{onClick:s,"aria-label":"Close MCP",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit shrink-0",children:[e.jsxs(Ie,{active:o==="installed",onClick:()=>u("installed"),children:["Installed (",E.length,")"]}),e.jsx(Ie,{active:o==="catalog",onClick:()=>{u("catalog"),A||Ne()},children:"Catalog"})]}),S&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(De,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0",children:S}),e.jsx("button",{type:"button",onClick:()=>g(null),className:"underline shrink-0",children:"Dismiss"})]}),o==="installed"?e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-3 min-h-0 sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex h-[180px] w-full shrink-0 flex-col gap-3 overflow-hidden sm:h-auto sm:w-[220px]",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Servers"}),e.jsx("input",{type:"search","aria-label":"Search installed MCP servers",value:h,onChange:t=>b(t.target.value),placeholder:"Search servers...",className:"h-8 shrink-0 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[12px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-2 pr-1 min-h-0",children:[y&&E.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(le,{className:"w-4 h-4 animate-spin"}),"Loading servers..."]}),ee&&!y&&e.jsxs("div",{role:"alert",className:"flex flex-col gap-2 items-center py-6 font-mono text-xs text-center text-red-600 dark:text-red-400",children:[e.jsx("span",{children:ee.message}),e.jsx("button",{type:"button",onClick:ke,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!ee&&!y&&te.length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:h?"No servers match your search":"No MCP servers configured"}),te.map(t=>e.jsxs("button",{onClick:()=>{p(t.id),q(null),g(null),z(null),U(""),_(null),J(null)},className:w("text-left rounded-lg px-3 py-2 flex flex-col gap-1 transition-colors shrink-0",t.id===(a==null?void 0:a.id)?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:w("text-[11px] font-mono font-semibold",Le[t.status]),children:Re(t)})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] truncate",children:t.endpoint})]},t.id))]})]}),a?e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-3 pr-2 min-h-0",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsx("span",{className:w("text-xs font-mono font-semibold",Le[a.status]),children:Re(a)})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:a.description}),a.error&&e.jsxs("p",{className:"text-[12px] font-mono text-[#ef4444]",children:["Error: ",a.error]}),a.instructions&&e.jsxs("div",{className:"rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Server instructions"}),e.jsxs("span",{className:"truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",a.instructions.sha256]})]}),e.jsx("pre",{className:"mt-1 max-h-36 overflow-y-auto whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:a.instructions.text??"[details omitted by runtime policy]"}),(a.instructions.truncated||a.instructions.detailsOmitted)&&e.jsx("span",{className:"mt-1 block text-[9px] font-mono text-amber-600 dark:text-amber-400",children:a.instructions.detailsOmitted?"Details omitted":"Truncated to the safe display budget"})]}),a.tasks&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Experimental MCP Tasks"}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:a.tasks.enabled?`${a.tasks.maxTasksPerSession} per Session · ${a.tasks.pollIntervalMs}ms poll`:"Disabled by default"})]}),e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",a.tasks.enabled?"text-[#16A34A] dark:text-[#22C55E]":"text-[#9CA3AF] dark:text-[#71717a]"),children:a.tasks.enabled?"Enabled":"Disabled"})]}),a.oauthEnabled&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"OAuth"}),e.jsx("span",{role:a.oauthStatus==="authorizing"?"status":void 0,className:w("text-[11px] font-mono",a.oauthStatus==="authenticated"?"text-[#16A34A] dark:text-[#22C55E]":a.oauthStatus==="error"?"text-[#ef4444]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:gt[a.oauthStatus]})]}),a.oauthStatus==="authenticated"?e.jsx("button",{type:"button",onClick:()=>void pe("logout",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:(d==null?void 0:d.type)==="logout"?"Signing out...":"Sign out"}):a.oauthStatus==="authorizing"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-3.5 w-3.5 animate-spin text-[#2563eb]","aria-hidden":"true"}),(j==null?void 0:j.serverName)===a.name?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex h-7 items-center rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white dark:bg-[#3b82f6]",children:"Continue authorization"}):e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:"Resume authorization"})]}):a.oauthStatus==="unavailable"?null:e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:(d==null?void 0:d.type)==="login"?"Opening...":"Authorize"})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[a.status==="connected"||a.status==="reconnecting"?e.jsx("button",{onClick:()=>void fe("disconnect",a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="disconnect"&&d.name===a.name?"Disconnecting...":a.status==="reconnecting"?"Stop recovery":"Disconnect"}):e.jsx("button",{onClick:()=>void fe("connect",a.name),disabled:d!==null||a.oauthEnabled&&a.oauthStatus!=="authenticated",className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="connect"&&d.name===a.name?"Connecting...":a.oauthEnabled&&a.oauthStatus!=="authenticated"?"Authorize first":"Connect"}),e.jsx("button",{onClick:()=>q(a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold",children:"Delete"})]}),K===a.name&&e.jsxs("div",{role:"alertdialog","aria-label":`Delete ${a.name}`,className:"flex flex-wrap gap-2 justify-between items-center px-3 py-2 bg-red-50 rounded-md border border-red-200 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:"Remove this server and its saved configuration?"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{type:"button",onClick:()=>q(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>void fe("delete",a.name),disabled:d!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(d==null?void 0:d.type)==="delete"?"Deleting...":"Delete server"})]})]}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Tools (",a.tools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.tools.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No tools available"}):a.tools.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))}),e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Argument completion"}),a.status!=="connected"?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Connect the server to request suggestions"}):a.completionSupported?re.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No completable prompt arguments or template variables"}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{"aria-label":"MCP completion target",className:"flex max-h-20 flex-wrap gap-1 overflow-y-auto",children:re.map(t=>e.jsx("button",{type:"button","aria-pressed":(T==null?void 0:T.key)===t.key,onClick:()=>{z(t.key),_(null),J(null)},className:w("max-w-full truncate rounded px-2 py-1 text-[10px] font-mono",(T==null?void 0:T.key)===t.key?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] dark:bg-[#18181b] dark:text-[#a1a1aa]"),children:t.label},t.key))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text","aria-label":"MCP completion partial value",value:R,onChange:t=>U(t.target.value),placeholder:"Partial value",className:"h-8 min-w-0 flex-1 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[11px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsx("button",{type:"button",onClick:()=>void Ge(a),disabled:H,className:"h-8 shrink-0 rounded-md bg-[#2563eb] px-3 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:H?"Completing...":"Complete"})]}),Y&&e.jsx("span",{role:"alert",className:"text-[11px] font-mono text-red-600 dark:text-red-400",children:Y}),D&&e.jsxs("div",{"aria-label":"MCP completion suggestions",className:"rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:D.values.length>0?D.values.map(t=>e.jsx("span",{className:"rounded bg-white px-2 py-1 text-[10px] font-mono text-[#111827] dark:bg-[#0C0C0C] dark:text-[#E5E5E5]",children:t||"[empty]"},t)):e.jsx("span",{className:"text-[10px] font-mono text-[#9CA3AF]",children:"No suggestions"})}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",D.sha256,D.truncated?" · truncated":""]})]})]}):e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Server does not advertise MCP completions"}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Diagnostics"}),e.jsx("button",{type:"button","aria-label":`Refresh ${a.name} MCP logs`,onClick:()=>void ne(a.name),disabled:ue,className:"flex h-7 w-7 items-center justify-center rounded-md text-[#9CA3AF] transition-colors hover:bg-[#E5E7EB] hover:text-[#111827] disabled:opacity-50 dark:text-[#71717a] dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:e.jsx(Be,{className:w("h-3.5 w-3.5",ue&&"animate-spin")})})]}),e.jsx("div",{"aria-label":"MCP logging level",className:"flex flex-wrap gap-1",children:vt.map(t=>{var i,l;return e.jsx("button",{type:"button",onClick:()=>void We(a,t),disabled:a.status!=="connected"||M!==null,"aria-pressed":(((i=a.logging)==null?void 0:i.level)??"warning")===t,className:w("rounded px-2 py-1 text-[10px] font-mono transition-colors disabled:opacity-40",(((l=a.logging)==null?void 0:l.level)??"warning")===t?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] hover:text-[#111827] dark:bg-[#18181b] dark:text-[#a1a1aa] dark:hover:text-[#E5E5E5]"),children:M===t?"Setting...":t},t)})}),Ee?e.jsx("div",{role:"alert",className:"rounded-md bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:bg-red-950/30 dark:text-red-300",children:Ee.message}):ae!=null&&ae.entries.length?e.jsx("div",{"aria-label":`${a.name} MCP logs`,className:"flex max-h-52 flex-col gap-1.5 overflow-y-auto rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:ae.entries.map(t=>e.jsxs("div",{className:"rounded bg-white px-2.5 py-2 dark:bg-[#0C0C0C]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",["error","critical","alert","emergency"].includes(t.level)?"text-red-600 dark:text-red-400":t.level==="warning"?"text-amber-600 dark:text-amber-400":"text-[#2563eb] dark:text-[#60a5fa]"),children:t.level}),e.jsxs("span",{className:"truncate text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[t.logger||a.name," · r",t.revision]})]}),e.jsx("pre",{className:"mt-1 whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:t.message}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",t.dataSha256,t.truncated?" · truncated":"",t.detailsOmitted?" · details omitted":""]})]},t.revision))}):e.jsx("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:ue?"Loading logs...":"No logs captured"})]}):e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"Select a server to view details"})})]}):e.jsxs("div",{className:"flex flex-col flex-1 gap-4 min-h-0",children:[e.jsx("div",{className:"flex gap-3 items-center shrink-0",children:e.jsxs("div",{className:"flex-1 h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] flex items-center px-3 gap-2",children:[e.jsx(ot,{className:"h-3.5 w-3.5 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("input",{type:"text","aria-label":"Search MCP server catalog",value:ce,onChange:t=>{Q(t.target.value),k(t.target.value)},placeholder:"Search MCP servers on npm (min 3 chars)...",className:"flex-1 bg-transparent text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none"})]})}),e.jsxs("div",{ref:v,className:"overflow-y-auto flex-1 min-h-0",children:[je?e.jsxs("div",{role:"alert",className:"flex flex-col gap-3 items-center py-12 font-mono text-center",children:[e.jsx(De,{className:"w-6 h-6 text-red-500"}),e.jsx("span",{className:"text-xs text-red-600 dark:text-red-400",children:je.message}),e.jsx("button",{type:"button",onClick:Ne,className:"rounded-md border border-[#E5E7EB] px-3 py-1.5 text-[11px] text-[#6B7280] dark:border-[#27272a] dark:text-[#a1a1aa]",children:"Retry catalog"})]}):He&&!A?e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsx(le,{className:"h-6 w-6 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}):e.jsxs("div",{className:"grid grid-cols-1 gap-3 pb-4 sm:grid-cols-2",children:[A==null?void 0:A.list.map(t=>{var we,Ae;const i=Ve.has(Ue(t.name).toLowerCase()),l=me===t.name,B=Qe(t);return e.jsxs("div",{className:"rounded-lg bg-white dark:bg-[#0C0C0C] p-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2 justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name}),e.jsx("span",{className:w("text-[10px] font-mono px-2 py-0.5 rounded shrink-0",B==="Official"?"bg-[#16A34A]/20 dark:bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:B})]}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] line-clamp-2",children:t.description||"No description"}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsxs("span",{children:["v",t.version]}),((we=t.publisher)==null?void 0:we.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",t.publisher.username]})]})]}),e.jsxs("div",{className:"flex justify-between items-center pt-2 mt-auto",children:[e.jsxs("a",{href:((Ae=t.links)==null?void 0:Ae.npm)||`https://www.npmjs.com/package/${t.name}`,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5] flex items-center gap-1",children:[e.jsx(Te,{className:"w-3 h-3"}),"npm"]}),i?e.jsxs("span",{className:"text-[11px] font-mono text-[#16A34A] dark:text-[#22C55E] flex items-center gap-1",children:[e.jsx(lt,{className:"w-3 h-3"}),"Installed"]}):e.jsxs("button",{onClick:()=>Ye(t),disabled:l,className:"h-6 px-2 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[10px] font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a] disabled:opacity-50",children:[e.jsx(dt,{className:w("h-3 w-3",l&&"animate-pulse")}),l?"Installing...":"Install"]})]})]},t.name)}),(A==null?void 0:A.list.length)===0&&e.jsx("div",{className:"col-span-full py-12 text-center text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No packages found"})]}),Je&&e.jsx("div",{className:"flex justify-center items-center py-4",children:e.jsx(le,{className:"h-5 w-5 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}),qe&&A&&A.list.length>0&&e.jsx("div",{className:"text-center py-4 text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No more packages"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-[#E5E7EB] dark:border-[#1f2937] shrink-0",children:[e.jsxs("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[(A==null?void 0:A.total)??0," packages found"]}),e.jsxs("a",{href:"https://glama.ai/mcp/servers",target:"_blank",rel:"noopener noreferrer",className:"text-[11px] font-mono text-[#3b82f6] hover:underline flex items-center gap-1",children:["Browse more on Glama",e.jsx(Te,{className:"w-3 h-3"})]})]})]})]})})]})}),e.jsx(yt,{open:f,onOpenChange:x,onAdd:Ce,saving:ye,error:(V==null?void 0:V.message)??null}),W&&e.jsx(wt,{pkg:W,onClose:()=>m(null),installing:ye,error:(V==null?void 0:V.message)??null,onInstall:t=>(X(W.name),Ce(t))})]})}function Ie({active:n,children:s,onClick:o}){return e.jsx("button",{onClick:o,className:w("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:s})}function yt({open:n,onOpenChange:s,onAdd:o,saving:u,error:f}){const[x,c]=r.useState("form"),[p,h]=r.useState(""),[b,S]=r.useState(""),[g,j]=r.useState(""),[C,d]=r.useState(null),[F,M]=r.useState(`{
1
+ import{r,j as e}from"./vendor-react-DG5dkZ_t.js";import{_ as $,n as P,o as Se,p as Fe,q as se}from"./vendor-radix-DBy9B2DN.js";import{i as Ze,a as Xe,d as Me,u as $e,b as ze,c as et,e as de,f as oe,g as tt}from"./useRequest-BvqVDnKl.js";import{b as at,D as he,e as be,G as nt,g as ge,j as w,x as L,y as rt}from"./index-DvDtvgA4.js";import{a as Be,i as st,X as ve,f as De,L as le,k as ot,Z as Te,C as lt,D as dt}from"./vendor-icons-D_AkWmWB.js";function ie(n,s){if(Ze){if(!n)return s;var o;return Xe(n)?o=n():"current"in n?o=n.current:o=n,o}}var it=function(n){var s=function(o,u,f){var x=r.useRef(!1),c=r.useRef([]),p=r.useRef([]),h=r.useRef(void 0);n(function(){var b,S=Array.isArray(f)?f:[f],g=S.map(function(j){return ie(j)});if(!x.current){x.current=!0,c.current=g,p.current=u,h.current=o();return}(g.length!==c.current.length||!Me(c.current,g)||!Me(p.current,u))&&((b=h.current)===null||b===void 0||b.call(h),c.current=g,p.current=u,h.current=o())}),$e(function(){var b;(b=h.current)===null||b===void 0||b.call(h),x.current=!1})};return s},ct=it(r.useEffect);function xt(){var n=(typeof global>"u"?"undefined":typeof global)=="object"&&global&&global.Object===Object&&global,s=typeof self=="object"&&self&&self.Object===Object&&self;return n||s}xt()||(global.Date=Date);function mt(n,s){var o,u=ze(n),f=(o=s==null?void 0:s.wait)!==null&&o!==void 0?o:1e3,x=r.useMemo(function(){return et(function(){for(var c=[],p=0;p<arguments.length;p++)c[p]=arguments[p];return u.current.apply(u,$([],P(c),!1))},f,s)},[]);return $e(function(){x.cancel()}),{run:x,cancel:x.cancel,flush:x.flush}}function ut(n,s,o){o===void 0&&(o={});var u=o.enable,f=u===void 0?!0:u,x=ze(s);ct(function(){if(f){var c=ie(o.target,window);if(c!=null&&c.addEventListener){var p=function(b){return x.current(b)},h=Array.isArray(n)?n:[n];return h.forEach(function(b){c.addEventListener(b,p,{capture:o.capture,once:o.once,passive:o.passive})}),function(){h.forEach(function(b){c.removeEventListener(b,p,{capture:o.capture})})}}}},[n,o.capture,o.once,o.passive,f],o.target)}var ft=function(n){return n===document||n===document.documentElement||n===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):n.scrollTop},Pe=function(n){return n.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},pt=function(n){return n.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},ht=function(n,s){s===void 0&&(s={});var o=s.target,u=s.isNoMore,f=s.threshold,x=f===void 0?100:f,c=s.direction,p=c===void 0?"bottom":c,h=s.reloadDeps,b=h===void 0?[]:h,S=s.manual,g=s.onBefore,j=s.onSuccess,C=s.onError,d=s.onFinally,F=P(r.useState(),2),M=F[0],O=F[1],N=P(r.useState(!1),2),z=N[0],R=N[1],U=p==="top",D=r.useRef(void 0),_=r.useRef(0),H=r.useMemo(function(){return u?u(M):!1},[M]),I=de(function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,n(m)];case 1:return v=k.sent(),[2,{currentData:v,lastData:m}]}})})},{manual:S,onFinally:function(m,v,k){R(!1),d==null||d(v==null?void 0:v.currentData,k)},onBefore:function(){return g==null?void 0:g()},onSuccess:function(m){var v,k,E;m.lastData?O(se(se({},m.currentData),{list:U?$($([],P(m.currentData.list),!1),P((k=m.lastData.list)!==null&&k!==void 0?k:[]),!1):$($([],P((E=m.lastData.list)!==null&&E!==void 0?E:[]),!1),P(m.currentData.list),!1)})):O(se(se({},m.currentData),{list:$([],P((v=m.currentData.list)!==null&&v!==void 0?v:[]),!1)})),setTimeout(function(){requestAnimationFrame(function(){if(U){var y=ie(o);if(y=y===document?document.documentElement:y,y){var ee=Pe(y);y.scrollTo(0,ee-_.current)}}else G()})}),j==null||j(m.currentData)},onError:function(m){return C==null?void 0:C(m)}}),Y=I.loading,J=I.error,K=I.run,q=I.runAsync,ce=I.cancel,Q=oe(function(){H||(R(!0),K(M))}),Z=function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,q(m)];case 1:return v=k.sent(),[2,v.currentData]}})})},xe=oe(function(){return H?Promise.reject():(R(!0),Z(M))}),me=function(){return R(!1),K()},X=function(){return R(!1),Z()},G=function(){var m=ie(o);if(m){var v=m===document?document.documentElement:m,k=ft(v),E=Pe(v),y=pt(v);U?(D.current!==void 0&&D.current>k&&k<=x&&Q(),D.current=k,_.current=E-k):E-k<=y+x&&Q()}};return ut("scroll",function(){Y||z||G()},{target:o}),tt(function(){K()},$([],P(b),!1)),{data:M,loading:!z&&Y,error:J,loadingMore:z,noMore:H,loadMore:Q,loadMoreAsync:xe,reload:oe(me),reloadAsync:oe(X),mutate:O,cancel:ce}};const Le={connected:"text-[#16A34A] dark:text-[#22C55E]",connecting:"text-[#2563eb] dark:text-[#3b82f6]",reconnecting:"text-[#2563eb] dark:text-[#60a5fa]",offline:"text-[#f59e0b]",error:"text-[#ef4444]"},bt={connected:"Connected",connecting:"Connecting...",reconnecting:"Recovering...",offline:"Offline",error:"Error"},gt={disabled:"Not configured",unavailable:"Unavailable in this runtime",unauthenticated:"Authorization required",authorizing:"Waiting for authorization...",authenticated:"Authorized",error:"Authorization failed"},Oe=20,vt=["debug","info","notice","warning","error","critical","alert","emergency"],Re=n=>n.status!=="reconnecting"||!n.recovery?bt[n.status]:`Recovering ${n.recovery.attempt}/${n.recovery.maxAttempts}`,kt=async()=>L("/mcp"),Et=async n=>L(`/mcp/${encodeURIComponent(n)}/logs?limit=20`),jt="mcp server @modelcontextprotocol",Nt=3,Ue=n=>{var s;return((s=n.split("/").pop())==null?void 0:s.replace(/^server-/,""))||n},Ct=async(n,s)=>{const o=n&&n.length>=Nt?n:jt,u=`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(o)}&size=${Oe}&from=${s}`,f=await L(u);return{list:f.objects.map(x=>x.package),total:f.total,hasMore:s+Oe<f.total}};function Dt(){const{isMcpOpen:n,toggleMcp:s}=at(),[o,u]=r.useState("installed"),[f,x]=r.useState(!1),[c,p]=r.useState(null),[h,b]=r.useState(""),[S,g]=r.useState(null),[j,C]=r.useState(null),[d,F]=r.useState(null),[M,O]=r.useState(null),[N,z]=r.useState(null),[R,U]=r.useState(""),[D,_]=r.useState(null),[H,I]=r.useState(!1),[Y,J]=r.useState(null),[K,q]=r.useState(null),[ce,Q]=r.useState(""),[Z,xe]=r.useState(""),[me,X]=r.useState(null),[G,m]=r.useState(null),v=r.useRef(null),{run:k}=mt(t=>{xe(t)},{wait:500}),{data:E=[],loading:y,error:ee,run:ke,runAsync:W}=de(kt,{refreshDeps:[n],ready:n,onSuccess:t=>{t.length>0&&!c&&p(t[0].id)}}),{data:ae,loading:ue,error:Ee,runAsync:ne}=de(Et,{manual:!0}),{data:A,loading:He,loadingMore:Je,noMore:qe,error:je,reload:Ne}=ht(async t=>{var l;const i=((l=t==null?void 0:t.list)==null?void 0:l.length)??0;return Ct(Z,i)},{target:v,isNoMore:t=>!(t!=null&&t.hasMore),reloadDeps:[Z],manual:!n||o!=="catalog"}),{runAsync:Ce,loading:ye,error:V}=de(async t=>{await L("/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,config:t})})},{manual:!0,onSuccess:()=>{W(),x(!1),m(null),X(null)},onError:()=>{X(null)}}),te=r.useMemo(()=>{const t=h.trim().toLowerCase();return t?E.filter(i=>[i.name,i.endpoint,i.description].some(l=>l.toLowerCase().includes(t))):E},[h,E]),a=r.useMemo(()=>te.find(t=>t.id===c)??te[0],[te,c]),re=r.useMemo(()=>{if(!a)return[];const t=(a.prompts??[]).flatMap(l=>l.arguments.map(B=>({key:`prompt:${l.name}:${B.name}`,label:`${l.name}.${B.name}`,reference:{type:"prompt",name:l.name},argument:B.name}))),i=(a.resourceTemplates??[]).flatMap(l=>(l.variables??[]).map(B=>({key:`resource:${l.uriTemplate}:${B}`,label:`${l.uriTemplate} · ${B}`,reference:{type:"resource",uri:l.uriTemplate},argument:B})));return[...t,...i]},[a]),T=re.find(t=>t.key===N)??re[0];r.useEffect(()=>{if(!n||!E.some(i=>i.oauthStatus==="authorizing"||i.status==="connecting"||i.status==="reconnecting"))return;const t=window.setInterval(()=>{W()},1e3);return()=>window.clearInterval(t)},[n,W,E]),r.useEffect(()=>{j&&E.some(t=>t.name===j.serverName&&(t.oauthStatus==="authenticated"||t.oauthStatus==="disabled"||t.oauthStatus==="unavailable"))&&C(null)},[j,E]),r.useEffect(()=>{!n||o!=="installed"||!a||ne(a.name).catch(()=>{})},[n,ne,a,o]);const fe=async(t,i)=>{F({type:t,name:i}),g(null);try{const l=t==="delete"?"":`/${t}`;await L(`/mcp/${encodeURIComponent(i)}${l}`,{method:t==="delete"?"DELETE":"POST"}),await W(),t==="delete"&&(q(null),p(null))}catch(l){g(l instanceof Error?l.message:`Failed to ${t} server`)}finally{F(null)}},pe=async(t,i)=>{F({type:t,name:i.name}),g(null);try{if(t==="login"){const l=await L(`/mcp/${encodeURIComponent(i.name)}/oauth/login`,{method:"POST"});C({serverName:i.name,url:l.authorizationUrl})}else await L(`/mcp/${encodeURIComponent(i.name)}/oauth/logout`,{method:"POST"}),C(null);await W()}catch(l){g(l instanceof Error?l.message:`Failed to ${t} MCP OAuth`)}finally{F(null)}},Ge=async(t,i)=>{O(i),g(null);try{await L(`/mcp/${encodeURIComponent(t.name)}/logging-level`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:i})}),await W(),ne(t.name).catch(()=>{})}catch(l){g(l instanceof Error?l.message:"Failed to set MCP logging level")}finally{O(null)}},We=async t=>{if(T){I(!0),J(null),_(null);try{const i=await L(`/mcp/${encodeURIComponent(t.name)}/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reference:T.reference,argument:{name:T.argument,value:R}})});_(i)}catch(i){J(i instanceof Error?i.message:"MCP completion failed")}finally{I(!1)}}},Ve=r.useMemo(()=>new Set(E.map(t=>t.name.toLowerCase())),[E]),Ye=t=>{m(t)},Ke=t=>t.startsWith("@modelcontextprotocol/"),Qe=t=>Ke(t.name)?"Official":"Community";return e.jsxs(e.Fragment,{children:[e.jsx(he,{open:n,onOpenChange:s,children:e.jsxs(be,{onCloseAutoFocus:nt,className:"flex h-[min(680px,calc(100dvh-24px))] flex-col gap-0 overflow-hidden rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[900px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(ge,{className:"sr-only",children:"MCP"}),e.jsx("div",{className:"flex flex-1 min-h-0",children:e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-4 p-4 min-h-0 sm:gap-5 sm:p-8",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"MCP"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:ke,"aria-label":"Refresh MCP servers",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",disabled:y,children:e.jsx(Be,{className:w("h-4 w-4",y&&"animate-spin")})}),e.jsxs("button",{"data-mcp-add-server-trigger":!0,onClick:()=>x(!0),className:"h-8 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-xs font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a]",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Add server"]}),e.jsx("button",{onClick:s,"aria-label":"Close MCP",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit shrink-0",children:[e.jsxs(Ie,{active:o==="installed",onClick:()=>u("installed"),children:["Installed (",E.length,")"]}),e.jsx(Ie,{active:o==="catalog",onClick:()=>{u("catalog"),A||Ne()},children:"Catalog"})]}),S&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(De,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0",children:S}),e.jsx("button",{type:"button",onClick:()=>g(null),className:"underline shrink-0",children:"Dismiss"})]}),o==="installed"?e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-3 min-h-0 sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex h-[180px] w-full shrink-0 flex-col gap-3 overflow-hidden sm:h-auto sm:w-[220px]",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Servers"}),e.jsx("input",{type:"search","aria-label":"Search installed MCP servers",value:h,onChange:t=>b(t.target.value),placeholder:"Search servers...",className:"h-8 shrink-0 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[12px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-2 pr-1 min-h-0",children:[y&&E.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(le,{className:"w-4 h-4 animate-spin"}),"Loading servers..."]}),ee&&!y&&e.jsxs("div",{role:"alert",className:"flex flex-col gap-2 items-center py-6 font-mono text-xs text-center text-red-600 dark:text-red-400",children:[e.jsx("span",{children:ee.message}),e.jsx("button",{type:"button",onClick:ke,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!ee&&!y&&te.length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:h?"No servers match your search":"No MCP servers configured"}),te.map(t=>e.jsxs("button",{onClick:()=>{p(t.id),q(null),g(null),z(null),U(""),_(null),J(null)},className:w("text-left rounded-lg px-3 py-2 flex flex-col gap-1 transition-colors shrink-0",t.id===(a==null?void 0:a.id)?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:w("text-[11px] font-mono font-semibold",Le[t.status]),children:Re(t)})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] truncate",children:t.endpoint})]},t.id))]})]}),a?e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-3 pr-2 min-h-0",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsx("span",{className:w("text-xs font-mono font-semibold",Le[a.status]),children:Re(a)})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:a.description}),a.error&&e.jsxs("p",{className:"text-[12px] font-mono text-[#ef4444]",children:["Error: ",a.error]}),a.instructions&&e.jsxs("div",{className:"rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Server instructions"}),e.jsxs("span",{className:"truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",a.instructions.sha256]})]}),e.jsx("pre",{className:"mt-1 max-h-36 overflow-y-auto whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:a.instructions.text??"[details omitted by runtime policy]"}),(a.instructions.truncated||a.instructions.detailsOmitted)&&e.jsx("span",{className:"mt-1 block text-[9px] font-mono text-amber-600 dark:text-amber-400",children:a.instructions.detailsOmitted?"Details omitted":"Truncated to the safe display budget"})]}),a.tasks&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Experimental MCP Tasks"}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:a.tasks.enabled?`${a.tasks.maxTasksPerSession} per Session · ${a.tasks.pollIntervalMs}ms poll`:"Disabled by default"})]}),e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",a.tasks.enabled?"text-[#16A34A] dark:text-[#22C55E]":"text-[#9CA3AF] dark:text-[#71717a]"),children:a.tasks.enabled?"Enabled":"Disabled"})]}),a.oauthEnabled&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"OAuth"}),e.jsx("span",{role:a.oauthStatus==="authorizing"?"status":void 0,className:w("text-[11px] font-mono",a.oauthStatus==="authenticated"?"text-[#16A34A] dark:text-[#22C55E]":a.oauthStatus==="error"?"text-[#ef4444]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:gt[a.oauthStatus]})]}),a.oauthStatus==="authenticated"?e.jsx("button",{type:"button",onClick:()=>void pe("logout",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:(d==null?void 0:d.type)==="logout"?"Signing out...":"Sign out"}):a.oauthStatus==="authorizing"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-3.5 w-3.5 animate-spin text-[#2563eb]","aria-hidden":"true"}),(j==null?void 0:j.serverName)===a.name?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex h-7 items-center rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white dark:bg-[#3b82f6]",children:"Continue authorization"}):e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:"Resume authorization"})]}):a.oauthStatus==="unavailable"?null:e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:(d==null?void 0:d.type)==="login"?"Opening...":"Authorize"})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[a.status==="connected"||a.status==="reconnecting"?e.jsx("button",{onClick:()=>void fe("disconnect",a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="disconnect"&&d.name===a.name?"Disconnecting...":a.status==="reconnecting"?"Stop recovery":"Disconnect"}):e.jsx("button",{onClick:()=>void fe("connect",a.name),disabled:d!==null||a.oauthEnabled&&a.oauthStatus!=="authenticated",className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="connect"&&d.name===a.name?"Connecting...":a.oauthEnabled&&a.oauthStatus!=="authenticated"?"Authorize first":"Connect"}),e.jsx("button",{onClick:()=>q(a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold",children:"Delete"})]}),K===a.name&&e.jsxs("div",{role:"alertdialog","aria-label":`Delete ${a.name}`,className:"flex flex-wrap gap-2 justify-between items-center px-3 py-2 bg-red-50 rounded-md border border-red-200 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:"Remove this server and its saved configuration?"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{type:"button",onClick:()=>q(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>void fe("delete",a.name),disabled:d!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(d==null?void 0:d.type)==="delete"?"Deleting...":"Delete server"})]})]}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Tools (",a.tools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.tools.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No tools available"}):a.tools.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))}),e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Argument completion"}),a.status!=="connected"?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Connect the server to request suggestions"}):a.completionSupported?re.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No completable prompt arguments or template variables"}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{"aria-label":"MCP completion target",className:"flex max-h-20 flex-wrap gap-1 overflow-y-auto",children:re.map(t=>e.jsx("button",{type:"button","aria-pressed":(T==null?void 0:T.key)===t.key,onClick:()=>{z(t.key),_(null),J(null)},className:w("max-w-full truncate rounded px-2 py-1 text-[10px] font-mono",(T==null?void 0:T.key)===t.key?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] dark:bg-[#18181b] dark:text-[#a1a1aa]"),children:t.label},t.key))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text","aria-label":"MCP completion partial value",value:R,onChange:t=>U(t.target.value),placeholder:"Partial value",className:"h-8 min-w-0 flex-1 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[11px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsx("button",{type:"button",onClick:()=>void We(a),disabled:H,className:"h-8 shrink-0 rounded-md bg-[#2563eb] px-3 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:H?"Completing...":"Complete"})]}),Y&&e.jsx("span",{role:"alert",className:"text-[11px] font-mono text-red-600 dark:text-red-400",children:Y}),D&&e.jsxs("div",{"aria-label":"MCP completion suggestions",className:"rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:D.values.length>0?D.values.map(t=>e.jsx("span",{className:"rounded bg-white px-2 py-1 text-[10px] font-mono text-[#111827] dark:bg-[#0C0C0C] dark:text-[#E5E5E5]",children:t||"[empty]"},t)):e.jsx("span",{className:"text-[10px] font-mono text-[#9CA3AF]",children:"No suggestions"})}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",D.sha256,D.truncated?" · truncated":""]})]})]}):e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Server does not advertise MCP completions"}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Diagnostics"}),e.jsx("button",{type:"button","aria-label":`Refresh ${a.name} MCP logs`,onClick:()=>void ne(a.name),disabled:ue,className:"flex h-7 w-7 items-center justify-center rounded-md text-[#9CA3AF] transition-colors hover:bg-[#E5E7EB] hover:text-[#111827] disabled:opacity-50 dark:text-[#71717a] dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:e.jsx(Be,{className:w("h-3.5 w-3.5",ue&&"animate-spin")})})]}),e.jsx("div",{"aria-label":"MCP logging level",className:"flex flex-wrap gap-1",children:vt.map(t=>{var i,l;return e.jsx("button",{type:"button",onClick:()=>void Ge(a,t),disabled:a.status!=="connected"||M!==null,"aria-pressed":(((i=a.logging)==null?void 0:i.level)??"warning")===t,className:w("rounded px-2 py-1 text-[10px] font-mono transition-colors disabled:opacity-40",(((l=a.logging)==null?void 0:l.level)??"warning")===t?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] hover:text-[#111827] dark:bg-[#18181b] dark:text-[#a1a1aa] dark:hover:text-[#E5E5E5]"),children:M===t?"Setting...":t},t)})}),Ee?e.jsx("div",{role:"alert",className:"rounded-md bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:bg-red-950/30 dark:text-red-300",children:Ee.message}):ae!=null&&ae.entries.length?e.jsx("div",{"aria-label":`${a.name} MCP logs`,className:"flex max-h-52 flex-col gap-1.5 overflow-y-auto rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:ae.entries.map(t=>e.jsxs("div",{className:"rounded bg-white px-2.5 py-2 dark:bg-[#0C0C0C]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",["error","critical","alert","emergency"].includes(t.level)?"text-red-600 dark:text-red-400":t.level==="warning"?"text-amber-600 dark:text-amber-400":"text-[#2563eb] dark:text-[#60a5fa]"),children:t.level}),e.jsxs("span",{className:"truncate text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[t.logger||a.name," · r",t.revision]})]}),e.jsx("pre",{className:"mt-1 whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:t.message}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",t.dataSha256,t.truncated?" · truncated":"",t.detailsOmitted?" · details omitted":""]})]},t.revision))}):e.jsx("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:ue?"Loading logs...":"No logs captured"})]}):e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"Select a server to view details"})})]}):e.jsxs("div",{className:"flex flex-col flex-1 gap-4 min-h-0",children:[e.jsx("div",{className:"flex gap-3 items-center shrink-0",children:e.jsxs("div",{className:"flex-1 h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] flex items-center px-3 gap-2",children:[e.jsx(ot,{className:"h-3.5 w-3.5 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("input",{type:"text","aria-label":"Search MCP server catalog",value:ce,onChange:t=>{Q(t.target.value),k(t.target.value)},placeholder:"Search MCP servers on npm (min 3 chars)...",className:"flex-1 bg-transparent text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none"})]})}),e.jsxs("div",{ref:v,className:"overflow-y-auto flex-1 min-h-0",children:[je?e.jsxs("div",{role:"alert",className:"flex flex-col gap-3 items-center py-12 font-mono text-center",children:[e.jsx(De,{className:"w-6 h-6 text-red-500"}),e.jsx("span",{className:"text-xs text-red-600 dark:text-red-400",children:je.message}),e.jsx("button",{type:"button",onClick:Ne,className:"rounded-md border border-[#E5E7EB] px-3 py-1.5 text-[11px] text-[#6B7280] dark:border-[#27272a] dark:text-[#a1a1aa]",children:"Retry catalog"})]}):He&&!A?e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsx(le,{className:"h-6 w-6 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}):e.jsxs("div",{className:"grid grid-cols-1 gap-3 pb-4 sm:grid-cols-2",children:[A==null?void 0:A.list.map(t=>{var we,Ae;const i=Ve.has(Ue(t.name).toLowerCase()),l=me===t.name,B=Qe(t);return e.jsxs("div",{className:"rounded-lg bg-white dark:bg-[#0C0C0C] p-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2 justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name}),e.jsx("span",{className:w("text-[10px] font-mono px-2 py-0.5 rounded shrink-0",B==="Official"?"bg-[#16A34A]/20 dark:bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:B})]}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] line-clamp-2",children:t.description||"No description"}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsxs("span",{children:["v",t.version]}),((we=t.publisher)==null?void 0:we.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",t.publisher.username]})]})]}),e.jsxs("div",{className:"flex justify-between items-center pt-2 mt-auto",children:[e.jsxs("a",{href:((Ae=t.links)==null?void 0:Ae.npm)||`https://www.npmjs.com/package/${t.name}`,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5] flex items-center gap-1",children:[e.jsx(Te,{className:"w-3 h-3"}),"npm"]}),i?e.jsxs("span",{className:"text-[11px] font-mono text-[#16A34A] dark:text-[#22C55E] flex items-center gap-1",children:[e.jsx(lt,{className:"w-3 h-3"}),"Installed"]}):e.jsxs("button",{onClick:()=>Ye(t),disabled:l,className:"h-6 px-2 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[10px] font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a] disabled:opacity-50",children:[e.jsx(dt,{className:w("h-3 w-3",l&&"animate-pulse")}),l?"Installing...":"Install"]})]})]},t.name)}),(A==null?void 0:A.list.length)===0&&e.jsx("div",{className:"col-span-full py-12 text-center text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No packages found"})]}),Je&&e.jsx("div",{className:"flex justify-center items-center py-4",children:e.jsx(le,{className:"h-5 w-5 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}),qe&&A&&A.list.length>0&&e.jsx("div",{className:"text-center py-4 text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No more packages"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-[#E5E7EB] dark:border-[#1f2937] shrink-0",children:[e.jsxs("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[(A==null?void 0:A.total)??0," packages found"]}),e.jsxs("a",{href:"https://glama.ai/mcp/servers",target:"_blank",rel:"noopener noreferrer",className:"text-[11px] font-mono text-[#3b82f6] hover:underline flex items-center gap-1",children:["Browse more on Glama",e.jsx(Te,{className:"w-3 h-3"})]})]})]})]})})]})}),e.jsx(yt,{open:f,onOpenChange:x,onAdd:Ce,saving:ye,error:(V==null?void 0:V.message)??null}),G&&e.jsx(wt,{pkg:G,onClose:()=>m(null),installing:ye,error:(V==null?void 0:V.message)??null,onInstall:t=>(X(G.name),Ce(t))})]})}function Ie({active:n,children:s,onClick:o}){return e.jsx("button",{onClick:o,className:w("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:s})}function yt({open:n,onOpenChange:s,onAdd:o,saving:u,error:f}){const[x,c]=r.useState("form"),[p,h]=r.useState(""),[b,S]=r.useState(""),[g,j]=r.useState(""),[C,d]=r.useState(null),[F,M]=r.useState(`{
2
2
  "name": "my-server",
3
3
  "command": "npx",
4
4
  "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
@@ -0,0 +1 @@
1
+ import{r as n,j as e}from"./vendor-react-DG5dkZ_t.js";import{P as We,v as Ye,j as T,w as Qe,S as Ve,u as ce,x as $,D as Ne,e as Ee,y as we,g as Se,a as be,z as Xe,b as ve,A as Ze,E as et,K as tt,F as st}from"./index-DvDtvgA4.js";import{y as Le,C as at,X as Ce,f as ke,a7 as nt,a8 as lt,L as Z,u as Ae,Y as Oe,a as fe,N as rt,D as Te,T as ye,a9 as ot,i as it,aa as dt,ab as ct,P as De}from"./vendor-icons-D_AkWmWB.js";import"./vendor-radix-DBy9B2DN.js";function de({value:t,onChange:g,options:k,placeholder:b="Select...",disabled:l=!1,className:U,"aria-label":L}){const[D,y]=n.useState(!1),[i,M]=n.useState(-1),o=n.useRef(null),f=k.find(c=>c.value===t);n.useEffect(()=>{if(D){const c=k.findIndex(E=>E.value===t);M(c>=0?c:0)}},[D,k,t]);const R=c=>{if(!l){if(!D){(c.key==="Enter"||c.key===" "||c.key==="ArrowDown")&&(c.preventDefault(),y(!0));return}switch(c.key){case"ArrowDown":c.preventDefault(),M(E=>Math.min(E+1,k.length-1));break;case"ArrowUp":c.preventDefault(),M(E=>Math.max(E-1,0));break;case"Enter":case" ":c.preventDefault(),i>=0&&i<k.length&&(g(k[i].value),y(!1));break;case"Escape":c.preventDefault(),y(!1);break}}};return n.useEffect(()=>{var E;if(!D||i<0)return;const c=(E=o.current)==null?void 0:E.children[i];c==null||c.scrollIntoView({block:"nearest"})},[i,D]),e.jsxs(We,{open:D,onOpenChange:y,children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{type:"button",role:"combobox","aria-expanded":D,"aria-haspopup":"listbox","aria-label":L,disabled:l,onKeyDown:R,className:T("field flex items-center justify-between gap-2 text-left",!f&&"text-zinc-400 dark:text-zinc-500",l&&"cursor-not-allowed opacity-50",U),children:[e.jsx("span",{className:"truncate",children:f?f.label:b}),e.jsx(Le,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),e.jsx(Qe,{align:"start",sideOffset:4,onKeyDown:R,className:"w-[var(--radix-popover-trigger-width)] max-h-[240px] p-1 overflow-hidden",children:e.jsx(Ve,{className:"max-h-[232px]",children:e.jsx("div",{ref:o,role:"listbox",children:k.map((c,E)=>e.jsxs("button",{type:"button",role:"option","aria-selected":c.value===t,"data-value":c.value,"data-highlighted":E===i||void 0,onClick:()=>{g(c.value),y(!1)},onMouseEnter:()=>M(E),className:T("flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left font-mono text-[13px] outline-none transition-colors",E===i&&"bg-zinc-100 dark:bg-zinc-800",c.value===t&&"text-zinc-900 dark:text-zinc-50 font-medium"),children:[e.jsx(at,{className:T("h-3.5 w-3.5 shrink-0",c.value===t?"opacity-100":"opacity-0")}),e.jsx("span",{className:"truncate",children:c.label})]},c.value))})})})]})}const xt=[{id:"auto",name:"Auto",description:"Use the Blade default communication style",source:"built-in"},{id:"pragmatic",name:"Pragmatic",description:"Direct, factual, concise, and action-oriented",source:"built-in"},{id:"friendly",name:"Friendly",description:"Warm, collaborative, and task-focused",source:"built-in"},{id:"explanatory",name:"Explanatory",description:"Explain codebase-specific choices and tradeoffs",source:"built-in"}],mt=/^[a-z][a-z0-9._-]{0,63}$/;function ut({open:t,onOpenChange:g,onSave:k,saveError:b}){const l=ce(),[U,L]=n.useState([]),[D,y]=n.useState([]),[i,M]=n.useState(),[o,f]=n.useState(),[R,c]=n.useState(""),[E,m]=n.useState(""),[N,K]=n.useState(""),[h,x]=n.useState(""),[O,A]=n.useState(""),[I,P]=n.useState(""),[r,u]=n.useState(!1),[Y,z]=n.useState(!1),[Q,G]=n.useState(!1),[_,J]=n.useState(!1),[w,S]=n.useState(null);n.useEffect(()=>{if(!t)return;let d=!0;return y([]),M(void 0),f(void 0),c(""),m(""),K(""),x(""),A(""),P(""),u(!1),S(null),z(!0),$("/providers").then(F=>{d&&L(F)}).catch(F=>{d&&S(F instanceof Error?F.message:l("settings.models.addModal.loadProvidersError"))}).finally(()=>{d&&z(!1)}),()=>{d=!1}},[t,l]),n.useEffect(()=>{if(!i)return;let d=!0;return y([]),f(void 0),S(null),i.factoryWireApi||i.custom?(G(!1),()=>{d=!1}):(G(!0),$(`/providers/${i.id}/models`).then(F=>{d&&y(F)}).catch(F=>{d&&S(F instanceof Error?F.message:l("settings.models.addModal.loadModelsError"))}).finally(()=>{d&&G(!1)}),()=>{d=!1})},[i,l]);const B=i==null?void 0:i.factoryWireApi,V=!!(B||i!=null&&i.custom),q=V?h.trim():o==null?void 0:o.id,le=async()=>{if(!i||!q||!i.configured&&!I)return;if(B){if(!mt.test(E.trim())){S(l("settings.models.addModal.channelIdError"));return}let se;try{se=new URL(O.trim())}catch{S(l("settings.models.addModal.invalidBaseUrl"));return}if(!["http:","https:"].includes(se.protocol)){S(l("settings.models.addModal.invalidBaseUrl"));return}}J(!0);const d=B?E.trim():i.id,F=await k({provider:d,model:q,displayName:R||(V?q:(o==null?void 0:o.name)??""),apiKey:I||void 0,...B?{modelProvider:{id:d,name:N.trim()||d,baseUrl:O.trim(),wireApi:B}}:{}});J(!1),F&&g(!1)};return e.jsx(Ne,{open:t,onOpenChange:g,children:e.jsxs(Ee,{onCloseAutoFocus:d=>we("[data-add-model-trigger]",d),onEscapeKeyDown:d=>{d.preventDefault(),g(!1)},onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),d.stopPropagation(),g(!1))},className:"gap-0 overflow-y-auto rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[480px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(Se,{className:"sr-only",children:l("settings.models.addModal.title")}),e.jsxs("div",{className:"flex flex-col gap-5 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"font-mono text-base font-semibold",children:l("settings.models.addModal.title")}),e.jsx("button",{type:"button",onClick:()=>g(!1),"aria-label":l("settings.models.addModal.close"),className:"flex h-8 w-8 items-center justify-center rounded-md",children:e.jsx(Ce,{className:"h-4 w-4"})})]}),(w||b)&&e.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(ke,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:w||b})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.provider"),e.jsx(de,{"aria-label":l("settings.models.addModal.provider"),value:(i==null?void 0:i.id)??"",disabled:Y,onChange:d=>{M(U.find(F=>F.id===d)),c(""),m(""),K(""),x(""),A("")},placeholder:l(Y?"settings.models.addModal.loadingProviders":"settings.models.addModal.selectProvider"),options:U.map(d=>{const F=d.factoryWireApi==="openai-completions"?l("settings.models.addModal.customOpenAI"):d.factoryWireApi==="anthropic-messages"?l("settings.models.addModal.customAnthropic"):d.name;return{value:d.id,label:`${F} (${d.modelCount})${d.configured?l("settings.models.addModal.configuredSuffix"):""}`}})})]}),V?e.jsxs(e.Fragment,{children:[B&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.channelId"),e.jsx("input",{"aria-label":l("settings.models.addModal.channelId"),value:E,onChange:d=>{m(d.target.value),S(null)},placeholder:"team-gateway",autoComplete:"off",spellCheck:!1,className:"field"}),e.jsx("span",{className:"text-[11px] text-zinc-400",children:l("settings.models.addModal.channelIdHint")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.channelName"),e.jsx("input",{"aria-label":l("settings.models.addModal.channelName"),value:N,onChange:d=>K(d.target.value),placeholder:"Team Gateway",className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.baseUrl"),e.jsx("input",{"aria-label":l("settings.models.addModal.baseUrl"),value:O,onChange:d=>{A(d.target.value),S(null)},placeholder:B==="anthropic-messages"?"https://gateway.example.com":"https://gateway.example.com/v1",className:"field"}),e.jsx("span",{className:"text-[11px] text-zinc-400",children:l(B==="anthropic-messages"?"settings.models.addModal.anthropicProtocol":"settings.models.addModal.openaiProtocol")})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.modelId"),e.jsx("input",{"aria-label":l("settings.models.addModal.modelId"),value:h,onChange:d=>{x(d.target.value),S(null)},placeholder:"vendor-model-2026",className:"field"})]})]}):e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.model"),e.jsx(de,{"aria-label":l("settings.models.addModal.model"),value:(o==null?void 0:o.id)??"",disabled:!i||Q,onChange:d=>{const F=D.find(se=>se.id===d);f(F),F&&c(F.name)},placeholder:l(Q?"settings.models.addModal.loadingModels":"settings.models.addModal.selectModel"),options:D.map(d=>({value:d.id,label:`${d.name} - ${Math.round(d.contextWindow/1e3)}K${d.reasoning?l("settings.models.addModal.reasoningSuffix"):""}${d.input.includes("image")?l("settings.models.addModal.visionSuffix"):""}`}))})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.displayName"),e.jsx("input",{value:R,onChange:d=>c(d.target.value),placeholder:(o==null?void 0:o.name)??l("settings.models.addModal.displayNamePlaceholder"),className:"field"})]}),(i==null?void 0:i.supportsApiKey)&&!i.configured&&e.jsxs("label",{className:"flex flex-col gap-2 text-[13px] font-mono text-zinc-500",children:[l("settings.models.addModal.apiKey"),e.jsxs("span",{className:"relative",children:[e.jsx("input",{"aria-label":l("settings.models.addModal.apiKeyAria"),type:r?"text":"password",value:I,onChange:d=>P(d.target.value),className:"field w-full pr-10",placeholder:l("settings.models.addModal.apiKeyPlaceholder")}),e.jsx("button",{type:"button",onClick:()=>u(!r),"aria-label":l(r?"settings.models.addModal.hideApiKey":"settings.models.addModal.showApiKey"),className:"absolute right-2 top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded",children:r?e.jsx(nt,{className:"h-4 w-4"}):e.jsx(lt,{className:"h-4 w-4"})})]})]}),i&&!i.configured&&!i.supportsApiKey&&e.jsx("p",{className:"font-mono text-sm text-amber-600",children:l("settings.models.addModal.oauthNote")}),e.jsxs("button",{type:"button",disabled:_||!i||!q||B&&(!E.trim()||!O.trim())||!i.configured&&(!i.supportsApiKey||I.trim().length===0),onClick:()=>void le(),className:"flex min-h-9 items-center justify-center gap-2 rounded-md bg-green-600 px-4 py-2 font-mono text-sm font-semibold text-white disabled:opacity-50",children:[_&&e.jsx(Z,{className:"h-4 w-4 animate-spin"}),l(_?"settings.models.addModal.saving":"settings.models.addModal.saveModel")]})]})]})})}function pt(t){const g=ce(),[k,b]=n.useState(""),[l,U]=n.useState(""),[L,D]=n.useState(""),[y,i]=n.useState(""),[M,o]=n.useState(!1),[f,R]=n.useState(null);n.useEffect(()=>{var m,N,K,h,x;b(((m=t.model)==null?void 0:m.displayName)??""),U(((K=(N=t.model)==null?void 0:N.overrides)==null?void 0:K.baseUrl)??""),D(((x=(h=t.model)==null?void 0:h.overrides)==null?void 0:x.streamIdleTimeout)!==void 0?String(t.model.overrides.streamIdleTimeout):""),i(""),R(null)},[t.model]);const c=async()=>{if(!t.model)return;R(null);const m=L.trim()?Number(L):void 0;if(m!==void 0&&(!Number.isFinite(m)||m<1e3)){R(g("settings.models.editModal.streamIdleTimeoutError"));return}o(!0);try{y.trim()&&await $(`/providers/${t.model.provider}/credential`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:y.trim()})});const N={...t.model.overrides};l.trim()?N.baseUrl=l.trim():delete N.baseUrl,m!==void 0?N.streamIdleTimeout=m:delete N.streamIdleTimeout,await t.onSave(t.model.id,{displayName:k||void 0,overrides:Object.keys(N).length>0?N:void 0})&&t.onOpenChange(!1)}catch(N){R(N instanceof Error?N.message:g("settings.models.editModal.credentialError"))}finally{o(!1)}},E=t.model?`[data-edit-model-trigger="${t.model.id.replace(/"/g,'\\"')}"]`:"[data-edit-model-trigger]";return e.jsx(Ne,{open:t.open,onOpenChange:t.onOpenChange,children:e.jsxs(Ee,{onCloseAutoFocus:m=>we(E,m),onEscapeKeyDown:m=>{m.preventDefault(),t.onOpenChange(!1)},onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),t.onOpenChange(!1))},className:"gap-4 overflow-y-auto bg-white p-4 dark:bg-[#09090b] sm:max-w-[480px] sm:p-6","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(Se,{className:"sr-only",children:g("settings.models.editModal.srTitle")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"font-mono font-semibold",children:g("settings.models.editModal.title")}),e.jsx("button",{type:"button",onClick:()=>t.onOpenChange(!1),"aria-label":g("settings.models.editModal.close"),className:"flex h-8 w-8 items-center justify-center rounded-md",children:e.jsx(Ce,{className:"h-4 w-4"})})]}),(f||t.saveError)&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:f||t.saveError}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[g("settings.models.editModal.displayName"),e.jsx("input",{value:k,onChange:m=>b(m.target.value),className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[g("settings.models.editModal.replaceApiKey"),e.jsx("input",{type:"password",value:y,onChange:m=>i(m.target.value),placeholder:g("settings.models.editModal.replaceApiKeyPlaceholder"),className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[g("settings.models.editModal.baseUrlOverride"),e.jsx("input",{value:l,onChange:m=>U(m.target.value),placeholder:g("settings.models.editModal.baseUrlPlaceholder"),className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[g("settings.models.editModal.streamIdleTimeout"),e.jsx("input",{type:"number",min:1e3,step:1e3,value:L,onChange:m=>D(m.target.value),placeholder:"300000",className:"field"})]}),e.jsxs("button",{type:"button",onClick:()=>void c(),disabled:M,className:"flex min-h-9 items-center justify-center gap-2 rounded-md bg-green-600 px-4 py-2 text-white disabled:opacity-60",children:[M&&e.jsx(Z,{className:"h-4 w-4 animate-spin"}),g(M?"settings.models.editModal.saving":"settings.models.editModal.save")]})]})})}function gt({provider:t,onOpenChange:g,onSave:k,saveError:b}){const l=ce(),[U,L]=n.useState(t.name),[D,y]=n.useState(t.defaultBaseUrl??""),[i,M]=n.useState(t.wireApi??"openai-completions"),[o,f]=n.useState(t.apiKeyEnv??""),[R,c]=n.useState(""),[E,m]=n.useState(null),[N,K]=n.useState(!1);n.useEffect(()=>{L(t.name),y(t.defaultBaseUrl??""),M(t.wireApi??"openai-completions"),f(t.apiKeyEnv??""),c(""),m(null)},[t]);const h=async()=>{if(!U.trim()){m(l("settings.models.editProvider.channelNameRequired"));return}try{const x=new URL(D.trim());if(!["http:","https:"].includes(x.protocol))throw new Error}catch{m(l("settings.models.editProvider.invalidBaseUrl"));return}K(!0),m(null);try{await k(t.id,{name:U.trim(),baseUrl:D.trim(),wireApi:i,apiKeyEnv:o.trim()||null,...R.trim()?{apiKey:R.trim()}:{}})&&g(!1)}finally{K(!1)}};return e.jsx(Ne,{open:!0,onOpenChange:g,children:e.jsxs(Ee,{onCloseAutoFocus:x=>we(`[data-edit-provider-trigger="${t.id.replace(/"/g,'\\"')}"]`,x),onEscapeKeyDown:x=>{x.preventDefault(),g(!1)},onKeyDown:x=>{x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),g(!1))},className:"gap-4 overflow-y-auto bg-white p-4 dark:bg-[#09090b] sm:max-w-[480px] sm:p-6","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(Se,{className:"sr-only",children:l("settings.models.editProvider.title")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-mono font-semibold",children:l("settings.models.editProvider.title")}),e.jsx("p",{className:"mt-1 font-mono text-[11px] text-zinc-400",children:t.id})]}),e.jsx("button",{type:"button",onClick:()=>g(!1),"aria-label":l("settings.models.editProvider.close"),className:"flex h-8 w-8 items-center justify-center rounded-md",children:e.jsx(Ce,{className:"h-4 w-4"})})]}),(E||b)&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:E||b}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[l("settings.models.editProvider.channelName"),e.jsx("input",{"aria-label":l("settings.models.editProvider.channelName"),value:U,onChange:x=>L(x.target.value),className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[l("settings.models.editProvider.wireApi"),e.jsx(de,{"aria-label":l("settings.models.editProvider.wireApi"),value:i,onChange:x=>M(x),options:[{value:"openai-completions",label:"OpenAI Chat Completions"},{value:"anthropic-messages",label:"Anthropic Messages"}]})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[l("settings.models.editProvider.baseUrl"),e.jsx("input",{"aria-label":l("settings.models.editProvider.baseUrlAria"),value:D,onChange:x=>{y(x.target.value),m(null)},className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[l("settings.models.editProvider.apiKeyEnv"),e.jsx("input",{"aria-label":l("settings.models.editProvider.apiKeyEnv"),value:o,onChange:x=>f(x.target.value),placeholder:l("settings.models.editProvider.apiKeyEnvPlaceholder"),autoComplete:"off",spellCheck:!1,className:"field"})]}),e.jsxs("label",{className:"flex flex-col gap-2 font-mono text-sm",children:[l("settings.models.editProvider.replaceApiKey"),e.jsx("input",{"aria-label":l("settings.models.editProvider.apiKeyAria"),type:"password",value:R,onChange:x=>c(x.target.value),placeholder:l("settings.models.editProvider.apiKeyPlaceholder"),className:"field"})]}),e.jsxs("button",{type:"button",onClick:()=>void h(),disabled:N,className:"flex min-h-9 items-center justify-center gap-2 rounded-md bg-green-600 px-4 py-2 text-white disabled:opacity-60",children:[N&&e.jsx(Z,{className:"h-4 w-4 animate-spin"}),l(N?"settings.models.editProvider.saving":"settings.models.editProvider.save")]})]})})}const ht={disabled:"settings.hooks.state.disabled",not_required:"settings.hooks.state.notRequired",untrusted:"settings.hooks.state.review",trusted:"settings.hooks.state.trusted",modified:"settings.hooks.state.modified",error:"settings.hooks.state.error"};function bt(){const t=ce(),g=be(w=>w.currentSessionRef),k=g==null?void 0:g.projectPath,b=g==null?void 0:g.sessionId,l=n.useMemo(()=>k??new URLSearchParams(window.location.search).get("project")??"",[k]),[U,L]=n.useState(null),[D,y]=n.useState(null),[i,M]=n.useState(""),[o,f]=n.useState(""),[R,c]=n.useState(!1),[E,m]=n.useState(null),[N,K]=n.useState(null),[h,x]=n.useState(null),O=n.useRef(0),A=n.useRef(l);A.current=l;const I=b?`${l}\0${b}`:"",P=n.useRef(I);P.current=I;const r=i===l?U:null,u=o===I?D:null,Y=n.useCallback(async()=>{const w=++O.current;if(!l){L(null),y(null),M(""),f(""),x(null);return}c(!0),x(null);try{const S=await $(`/hooks/trust?projectPath=${encodeURIComponent(l)}`);if(w!==O.current)return;const B=b?await $(`/hooks/session?projectPath=${encodeURIComponent(l)}&sessionId=${encodeURIComponent(b)}`):null;if(w!==O.current)return;L(S),y(B),M(l),f(B?I:"")}catch(S){if(w!==O.current)return;x(S instanceof Error?S.message:t("settings.hooks.loadFailed"))}finally{w===O.current&&c(!1)}},[l,b,I,t]);n.useEffect(()=>(K(null),Y(),()=>{O.current+=1}),[Y]);const z=async w=>{if(!r)return;const S=l;m(w),x(null);try{const B=await $("/hooks/trust",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:l,action:w,...w==="trust"&&r.currentDigest?{expectedDigest:r.currentDigest}:{}})});A.current===S&&(L(B),M(S),K(null))}catch(B){A.current===S&&x(B instanceof Error?B.message:t("settings.hooks.updateFailed"))}finally{m(null)}},Q=async w=>{if(!b||!u)return;const S=I;m("session"),x(null);try{const B=await $("/hooks/session",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:l,sessionId:b,enabled:w})});P.current===S&&(y(B),f(S))}catch(B){P.current===S&&x(B instanceof Error?B.message:t("settings.hooks.sessionUpdateFailed"))}finally{m(null)}};if(!l)return e.jsx("div",{className:"font-mono text-[12px] text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.hooks.selectSession")});const G=(r==null?void 0:r.state)==="trusted",_=(r==null?void 0:r.state)==="untrusted"||(r==null?void 0:r.state)==="modified",J=u!==null&&!u.enabled&&!u.paused;return e.jsxs("div",{className:"flex min-h-0 flex-col gap-3 font-mono",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-md border border-[#E5E7EB] bg-[#F9FAFB] p-3 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[G?e.jsx(Ae,{className:"h-4 w-4 text-emerald-600"}):e.jsx(Oe,{className:T("h-4 w-4",_?"text-amber-600":"text-[#71717a]")}),e.jsx("span",{className:"text-[13px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t(r?ht[r.state]:"settings.hooks.heading")}),R&&e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"})]}),e.jsx("p",{className:"mt-1 break-all text-[10.5px] text-[#71717a]",children:l}),(r==null?void 0:r.currentDigest)&&e.jsx("p",{className:"mt-1 text-[10px] text-[#9CA3AF]",children:r.currentDigest})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>void Y(),disabled:R||E!==null,"aria-label":t("settings.hooks.reloadAria"),className:"inline-flex h-8 items-center gap-1 rounded-md border border-[#E5E7EB] px-2 text-[11px] text-[#6B7280] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#a1a1aa]",children:[e.jsx(fe,{className:"h-3.5 w-3.5"}),t("settings.common.reload")]}),G?e.jsx("button",{type:"button",onClick:()=>K("revoke"),disabled:E!==null,className:"h-8 rounded-md border border-red-200 px-2.5 text-[11px] text-red-600 disabled:opacity-50 dark:border-red-900 dark:text-red-400",children:t("settings.hooks.revoke")}):e.jsx("button",{type:"button",onClick:()=>K("trust"),disabled:E!==null||!(r!=null&&r.currentDigest)||r.state==="error",className:"h-8 rounded-md bg-emerald-600 px-2.5 text-[11px] font-semibold text-white disabled:opacity-50",children:t("settings.hooks.trustDigest")})]})]}),h&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:h}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-md border border-[#E5E7EB] px-3 py-2 dark:border-[#27272a]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t("settings.hooks.currentSession")}),e.jsx("div",{className:"mt-0.5 text-[9.5px] text-[#9CA3AF]",children:b?u?u.paused?t("settings.hooks.session.paused"):u.enabled?t("settings.hooks.session.active"):u.configEnabled?t("settings.hooks.session.unavailable"):t("settings.hooks.session.disabled"):t("settings.hooks.session.loading"):t("settings.hooks.session.open")})]}),e.jsx("button",{type:"button",role:"switch","aria-label":u!=null&&u.paused?t("settings.hooks.session.enableAria"):u!=null&&u.enabled?t("settings.hooks.session.pauseAria"):t("settings.hooks.session.unavailableAria"),"aria-checked":(u==null?void 0:u.enabled)??!1,disabled:!u||E!==null||J,onClick:()=>void Q((u==null?void 0:u.paused)===!0),className:T("flex h-6 w-11 items-center rounded-full px-1 transition-colors disabled:opacity-40",u!=null&&u.enabled?"bg-emerald-500":"bg-[#E5E7EB] dark:bg-[#27272a]"),children:e.jsx("span",{className:T("h-4 w-4 rounded-full bg-white transition-transform",u!=null&&u.enabled?"translate-x-5":"translate-x-0")})})]}),N&&r&&e.jsxs("div",{role:"alertdialog","aria-label":t(N==="trust"?"settings.hooks.confirmTrustAria":"settings.hooks.confirmRevokeAria"),className:"flex flex-wrap items-center justify-between gap-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 dark:border-amber-900/70 dark:bg-amber-950/30",children:[e.jsx("span",{className:"max-w-[620px] text-[11px] text-amber-900 dark:text-amber-200",children:N==="trust"?t("settings.hooks.confirmTrust",{count:r.configuredHooks}):t("settings.hooks.confirmRevoke")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>K(null),className:"h-7 rounded px-2 text-[11px] text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.common.cancel")}),e.jsx("button",{type:"button",onClick:()=>void z(N),disabled:E!==null,className:T("h-7 rounded px-2.5 text-[11px] font-semibold text-white disabled:opacity-50",N==="trust"?"bg-emerald-600":"bg-red-600"),children:t(E?"settings.hooks.saving":N==="trust"?"settings.hooks.trustReviewed":"settings.hooks.revokeTrust")})]})]}),e.jsxs("div",{className:"min-h-0 overflow-y-auto rounded-md border border-[#E5E7EB] dark:border-[#27272a]",children:[((r==null?void 0:r.definitions)??[]).map((w,S)=>e.jsxs("div",{className:"border-b border-[#E5E7EB] px-3 py-2 last:border-b-0 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"font-semibold text-[#111827] dark:text-[#E5E5E5]",children:w.event}),e.jsx("span",{className:"rounded bg-[#E5E7EB] px-1.5 py-0.5 text-[9px] uppercase text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",children:w.type}),w.name&&e.jsx("span",{className:"text-[#71717a]",children:w.name}),w.pluginName&&e.jsxs("span",{className:"rounded bg-violet-100 px-1.5 py-0.5 text-[9px] text-violet-700 dark:bg-violet-950/50 dark:text-violet-300",children:[w.pluginName," · ",w.pluginSource]})]}),w.matcher&&e.jsx("div",{className:"mt-1 break-all text-[9.5px] text-[#9CA3AF]",children:w.matcher}),e.jsx("pre",{className:"mt-1.5 whitespace-pre-wrap break-all text-[10.5px] text-[#374151] dark:text-[#d4d4d8]",children:w.target})]},`${w.event}-${w.type}-${S}`)),r&&r.definitions.length===0&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-[#9CA3AF]",children:t("settings.hooks.empty")})]})]})}const ft={restrictToAllowedSources:!1,requireGitCommitSha:!1,allowedGitHosts:[],allowedMarketplaces:[],allowedLocalRoots:[]},yt=[{value:"local",labelKey:"settings.plugins.scope.local",descriptionKey:"settings.plugins.scope.localDesc"},{value:"project",labelKey:"settings.plugins.scope.project",descriptionKey:"settings.plugins.scope.projectDesc"},{value:"global",labelKey:"settings.plugins.scope.global",descriptionKey:"settings.plugins.scope.globalDesc"}],Re={local:"settings.plugins.scope.local",project:"settings.plugins.scope.project",global:"settings.plugins.scope.global",invocation:"settings.plugins.scope.invocation",default:"settings.plugins.scope.default"};function jt(){const t=ce(),g=be(a=>{var v;return(v=a.currentSessionRef)==null?void 0:v.projectPath}),k=be(a=>a.selectedProjectPath),b=n.useMemo(()=>g??k??new URLSearchParams(window.location.search).get("project")??"",[k,g]),[l,U]=n.useState([]),[L,D]=n.useState([]),[y,i]=n.useState(ft),[M,o]=n.useState(!1),[f,R]=n.useState(""),[c,E]=n.useState(""),[m,N]=n.useState(""),[K,h]=n.useState(""),[x,O]=n.useState(!1),[A,I]=n.useState(null),[P,r]=n.useState(null),[u,Y]=n.useState(""),[z,Q]=n.useState(""),[G,_]=n.useState(!1),[J,w]=n.useState(null),[S,B]=n.useState("local"),V=n.useRef(0),q=n.useRef(b);q.current=b;const le=K===b?l:[],d=K===b?L:[],F=n.useCallback(async()=>{const a=++V.current;if(!b){U([]),h(""),r(null);return}O(!0),r(null);try{const[v,X,H]=await Promise.all([$(`/plugins?projectPath=${encodeURIComponent(b)}`),$(`/plugins/catalog?projectPath=${encodeURIComponent(b)}`),$(`/plugins/policy?projectPath=${encodeURIComponent(b)}`)]);if(a!==V.current)return;U(v),D(X),i(H.policy),o(H.environmentRequiresSha),R(H.policy.allowedGitHosts.join(", ")),E(H.policy.allowedMarketplaces.join(", ")),N(H.policy.allowedLocalRoots.join(", ")),h(b)}catch(v){if(a!==V.current)return;r(v instanceof Error?v.message:t("settings.plugins.loadFailed"))}finally{a===V.current&&O(!1)}},[b,t]);n.useEffect(()=>(F(),()=>{V.current+=1}),[F]);const se=async(a,v)=>{const X=b;I(a.name),r(null);try{await $(`/plugins/${encodeURIComponent(a.name)}/state`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:X,enabled:v,scope:S})}),q.current===X&&await F()}catch(H){q.current===X&&r(H instanceof Error?H.message:t("settings.plugins.updateFailed"))}finally{I(null)}},xe=a=>[...new Set(a.split(",").map(v=>v.trim()).filter(Boolean))],pe=async()=>{await ee("policy:save",()=>$("/plugins/policy",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,scope:"local",policy:{...y,allowedGitHosts:xe(f),allowedMarketplaces:xe(c),allowedLocalRoots:xe(m)}})}))},ee=async(a,v,X)=>{const H=b;I(a),r(null);try{await v(),q.current===H&&(X==null||X(),w(null),await F())}catch(oe){q.current===H&&r(oe instanceof Error?oe.message:t("settings.plugins.actionFailed"))}finally{I(null)}},me=async()=>{const a=u.trim();!a||!G||await ee("install",()=>$("/plugins/install",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,source:a,trust:!0})}),()=>{Y(""),_(!1)})},je=async a=>{const v=`update:${a.name}`;if(J!==v){w(v);return}await ee(v,()=>$(`/plugins/${encodeURIComponent(a.name)}/update`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,trust:!0})}))},ae=async a=>{const v=`uninstall:${a.name}`;if(J!==v){w(v);return}await ee(v,()=>$(`/plugins/${encodeURIComponent(a.name)}/uninstall`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,confirm:!0})}))},Pe=async()=>{const a=z.trim();a&&await ee("marketplace:add",()=>$("/plugins/marketplaces",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,source:a})}),()=>Q(""))},ge=async a=>{await ee(`marketplace:refresh:${a.name}`,()=>$(`/plugins/marketplaces/${encodeURIComponent(a.name)}/refresh`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b})}))},re=async a=>{const v=`marketplace:remove:${a.name}`;if(J!==v){w(v);return}await ee(v,()=>$(`/plugins/marketplaces/${encodeURIComponent(a.name)}/remove`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:b,confirm:!0})}))};return b?e.jsxs("div",{className:"flex min-h-0 flex-col gap-3 font-mono",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:[e.jsx(rt,{className:"h-4 w-4"}),t("settings.plugins.heading"),x&&e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"})]}),e.jsx("p",{className:"mt-1 break-all text-[10.5px] text-[#71717a]",children:b}),e.jsx("p",{className:"mt-1 text-[10px] text-[#9CA3AF]",children:t("settings.plugins.changesNote")})]}),e.jsxs("button",{type:"button",onClick:()=>void F(),disabled:x||A!==null,"aria-label":t("settings.plugins.reloadAria"),className:"inline-flex h-8 items-center gap-1 rounded-md border border-[#E5E7EB] px-2 text-[11px] text-[#6B7280] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#a1a1aa]",children:[e.jsx(fe,{className:"h-3.5 w-3.5"}),t("settings.common.reload")]})]}),P&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:P}),e.jsxs("div",{className:"rounded-md border border-[#E5E7EB] p-3 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:[e.jsx(Ae,{className:"h-3.5 w-3.5"}),t("settings.plugins.sourcePolicy")]}),e.jsx("button",{type:"button","aria-label":t("settings.plugins.savePolicyAria"),onClick:()=>void pe(),disabled:A!==null,className:"rounded-md border border-[#D1D5DB] px-2 py-1 text-[9.5px] text-[#6B7280] disabled:opacity-40 dark:border-[#3f3f46] dark:text-[#a1a1aa]",children:t(A==="policy:save"?"settings.plugins.saving":"settings.plugins.saveForProject")})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-2",children:[e.jsxs("button",{type:"button",role:"switch","aria-label":t("settings.plugins.restrictAria"),"aria-checked":y.restrictToAllowedSources,onClick:()=>i(a=>({...a,restrictToAllowedSources:!a.restrictToAllowedSources})),className:"flex items-center gap-2 text-[9.5px] text-[#6B7280] dark:text-[#a1a1aa]",children:[e.jsx("span",{className:T("h-3.5 w-6 rounded-full p-0.5",y.restrictToAllowedSources?"bg-amber-500":"bg-[#D1D5DB] dark:bg-[#3f3f46]"),children:e.jsx("span",{className:T("block h-2.5 w-2.5 rounded-full bg-white transition-transform",y.restrictToAllowedSources&&"translate-x-2.5")})}),t("settings.plugins.restrictAllowlists")]}),e.jsxs("button",{type:"button",role:"switch","aria-label":t("settings.plugins.requireShaAria"),"aria-checked":y.requireGitCommitSha,disabled:M,onClick:()=>i(a=>({...a,requireGitCommitSha:!a.requireGitCommitSha})),className:"flex items-center gap-2 text-[9.5px] text-[#6B7280] disabled:opacity-50 dark:text-[#a1a1aa]",children:[e.jsx("span",{className:T("h-3.5 w-6 rounded-full p-0.5",y.requireGitCommitSha?"bg-emerald-500":"bg-[#D1D5DB] dark:bg-[#3f3f46]"),children:e.jsx("span",{className:T("block h-2.5 w-2.5 rounded-full bg-white transition-transform",y.requireGitCommitSha&&"translate-x-2.5")})}),t("settings.plugins.requireSha"),M?t("settings.plugins.environmentLocked"):""]})]}),e.jsxs("div",{className:"mt-2 grid gap-1.5 sm:grid-cols-3",children:[e.jsx("input",{"aria-label":t("settings.plugins.gitHostsAria"),value:f,onChange:a=>R(a.target.value),placeholder:"github.com, *.corp.test",className:"field h-7 px-2 text-[9.5px]"}),e.jsx("input",{"aria-label":t("settings.plugins.marketplacesAria"),value:c,onChange:a=>E(a.target.value),placeholder:"team-market, official",className:"field h-7 px-2 text-[9.5px]"}),e.jsx("input",{"aria-label":t("settings.plugins.localRootsAria"),value:m,onChange:a=>N(a.target.value),placeholder:"/opt/approved/plugins",className:"field h-7 px-2 text-[9.5px]"})]}),y.restrictToAllowedSources&&!f.trim()&&!c.trim()&&!m.trim()&&e.jsx("p",{className:"mt-1.5 text-[9px] text-amber-700 dark:text-amber-400",children:t("settings.plugins.emptyAllowlists")})]}),e.jsxs("div",{className:"rounded-md border border-[#E5E7EB] p-3 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),t("settings.plugins.installHeading")]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("input",{"aria-label":t("settings.plugins.sourceAria"),value:u,onChange:a=>Y(a.target.value),placeholder:"plugin@marketplace, owner/repo, or ./path",disabled:A!==null,className:"field h-8 min-w-0 flex-1 px-2 text-[10.5px]"}),e.jsxs("button",{type:"button",onClick:()=>void me(),disabled:!u.trim()||!G||A!==null,className:"inline-flex h-8 items-center gap-1 rounded-md bg-[#111827] px-3 text-[10.5px] text-white disabled:opacity-40 dark:bg-[#E5E5E5] dark:text-[#18181b]",children:[A==="install"?e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Te,{className:"h-3.5 w-3.5"}),t("settings.plugins.install")]})]}),e.jsxs("button",{type:"button",role:"checkbox","aria-checked":G,onClick:()=>_(a=>!a),className:"mt-2 flex items-center gap-2 text-left text-[9.5px] text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:T("flex h-3.5 w-3.5 items-center justify-center rounded-sm border",G?"border-amber-600 bg-amber-600 text-white":"border-[#D1D5DB] dark:border-[#52525b]"),children:G?"✓":""}),t("settings.plugins.trustSource")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-md border border-[#E5E7EB] px-3 py-2 dark:border-[#27272a]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t("settings.plugins.activationScope")}),e.jsx("div",{className:"mt-0.5 text-[9px] text-[#9CA3AF]",children:t("settings.plugins.activationScopeHint")})]}),e.jsx("div",{role:"radiogroup","aria-label":t("settings.plugins.scopeAria"),className:"flex rounded-md bg-[#F3F4F6] p-0.5 dark:bg-[#18181b]",children:yt.map(a=>e.jsx("button",{type:"button",role:"radio","aria-checked":S===a.value,title:t(a.descriptionKey),onClick:()=>B(a.value),className:T("rounded px-2 py-1 text-[9.5px] transition-colors",S===a.value?"bg-white font-semibold text-[#111827] shadow-sm dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#71717a] hover:text-[#374151] dark:hover:text-[#d4d4d8]"),children:t(a.labelKey)},a.value))})]}),e.jsxs("div",{className:"min-h-0 overflow-y-auto rounded-md border border-[#E5E7EB] dark:border-[#27272a]",children:[le.map(a=>{var oe;const v=A===a.name,X=[a.commands?t("settings.plugins.capability.commands",{count:a.commands}):"",a.skills?t("settings.plugins.capability.skills",{count:a.skills}):"",a.agents?t("settings.plugins.capability.agents",{count:a.agents}):"",a.hooks?t("settings.plugins.capability.hooks",{count:a.hooks}):"",a.mcpServers?t("settings.plugins.capability.mcp",{count:a.mcpServers}):""].filter(Boolean),H=["global","project","local","invocation"].filter(te=>{var he;return((he=a.settingLayers)==null?void 0:he[te])!==void 0}).map(te=>`${t(Re[te])} ${t(a.settingLayers[te]?"settings.plugins.layer.on":"settings.plugins.layer.off")}`);return e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-[#E5E7EB] px-3 py-2.5 last:border-b-0 dark:border-[#27272a]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsxs("span",{className:"text-[9.5px] text-[#9CA3AF]",children:["v",a.version]}),e.jsx("span",{className:"rounded bg-[#E5E7EB] px-1.5 py-0.5 text-[9px] uppercase text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",children:a.source}),e.jsx("span",{className:"rounded bg-sky-50 px-1.5 py-0.5 text-[9px] text-sky-700 dark:bg-sky-950/40 dark:text-sky-300",children:t("settings.plugins.effective",{scope:t(Re[a.effectiveScope])})})]}),e.jsx("p",{className:"mt-1 text-[10.5px] text-[#6B7280] dark:text-[#a1a1aa]",children:a.description}),e.jsx("p",{className:"mt-1 text-[9.5px] text-[#9CA3AF]",children:X.join(" · ")||t("settings.plugins.noResources")}),H.length>0&&e.jsx("p",{className:"mt-1 text-[9px] text-[#9CA3AF]",children:H.join(" · ")}),a.managed&&e.jsxs("p",{className:"mt-1 text-[9px] text-[#9CA3AF]",children:[t("settings.plugins.managed"),a.marketplace?` · ${a.marketplace}`:"",a.revision?` · ${a.revision.slice(0,12)}`:""]}),!a.configurable&&e.jsx("p",{className:"mt-1 text-[9.5px] text-amber-600 dark:text-amber-400",children:t("settings.plugins.invocationScoped")}),(oe=a.compatibilityIssues)==null?void 0:oe.map(te=>e.jsx("p",{className:"mt-1 text-[9.5px] text-red-600 dark:text-red-400",children:te.message},`${te.code}:${te.message}`))]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1.5",children:[e.jsx("button",{type:"button",role:"switch","aria-label":a.status==="error"?t("settings.plugins.unavailableAria",{name:a.name}):a.enabled?t("settings.plugins.disableAria",{name:a.name}):t("settings.plugins.enableAria",{name:a.name}),"aria-checked":a.enabled,disabled:a.status==="error"||!a.configurable||v||A!==null,onClick:()=>void se(a,!a.enabled),className:T("flex h-6 w-11 items-center rounded-full px-1 transition-colors disabled:opacity-40",a.enabled?"bg-emerald-500":"bg-[#E5E7EB] dark:bg-[#27272a]"),children:e.jsx("span",{className:T("h-4 w-4 rounded-full bg-white transition-transform",a.enabled?"translate-x-5":"translate-x-0")})}),a.managed&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button","aria-label":t("settings.plugins.updateAria",{name:a.name}),onClick:()=>void je(a),disabled:A!==null,className:T("rounded px-1.5 py-1 text-[9px] disabled:opacity-40",J===`update:${a.name}`?"bg-amber-100 text-amber-800 dark:bg-amber-950/50 dark:text-amber-300":"text-[#6B7280] hover:bg-[#F3F4F6] dark:text-[#a1a1aa] dark:hover:bg-[#27272a]"),children:A===`update:${a.name}`?e.jsx(Z,{className:"h-3 w-3 animate-spin"}):J===`update:${a.name}`?t("settings.plugins.confirmUpdate"):t("settings.plugins.update")}),e.jsx("button",{type:"button","aria-label":t("settings.plugins.uninstallAria",{name:a.name}),onClick:()=>void ae(a),disabled:A!==null,className:T("rounded px-1.5 py-1 text-[9px] disabled:opacity-40",J===`uninstall:${a.name}`?"bg-red-100 text-red-700 dark:bg-red-950/50 dark:text-red-300":"text-[#9CA3AF] hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-950/30"),children:A===`uninstall:${a.name}`?e.jsx(Z,{className:"h-3 w-3 animate-spin"}):J===`uninstall:${a.name}`?t("settings.plugins.confirmRemove"):e.jsx(ye,{className:"h-3 w-3"})})]})]})]},a.name)}),!x&&le.length===0&&!P&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-[#9CA3AF]",children:t("settings.plugins.empty")})]}),e.jsxs("div",{className:"rounded-md border border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[#E5E7EB] px-3 py-2 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),t("settings.plugins.marketplaces")]}),e.jsx("span",{className:"text-[9px] text-[#9CA3AF]",children:t("settings.plugins.configuredCount",{count:d.length})})]}),e.jsxs("div",{className:"flex gap-2 border-b border-[#E5E7EB] p-2 dark:border-[#27272a]",children:[e.jsx("input",{"aria-label":t("settings.plugins.marketplaceSourceAria"),value:z,onChange:a=>Q(a.target.value),placeholder:"owner/repo, HTTPS Git URL, or ./path",disabled:A!==null,className:"field h-7 min-w-0 flex-1 px-2 text-[10px]"}),e.jsxs("button",{type:"button","aria-label":t("settings.plugins.addMarketplaceAria"),onClick:()=>void Pe(),disabled:!z.trim()||A!==null,className:"inline-flex h-7 items-center gap-1 rounded-md border border-[#D1D5DB] px-2 text-[9.5px] text-[#6B7280] disabled:opacity-40 dark:border-[#3f3f46] dark:text-[#a1a1aa]",children:[A==="marketplace:add"?e.jsx(Z,{className:"h-3 w-3 animate-spin"}):e.jsx(it,{className:"h-3 w-3"}),t("settings.plugins.add")]})]}),d.map(a=>e.jsxs("div",{className:"border-b border-[#E5E7EB] px-3 py-2 last:border-b-0 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-[10.5px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:[a.name,e.jsxs("span",{className:"ml-2 font-normal text-[#9CA3AF]",children:[a.sourceType," · ",a.revision.slice(0,12)]})]}),e.jsx("p",{className:"mt-0.5 text-[9.5px] text-[#6B7280] dark:text-[#a1a1aa]",children:a.description||t("settings.plugins.noDescription")})]}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx("button",{type:"button","aria-label":t("settings.plugins.refreshMarketplaceAria",{name:a.name}),disabled:A!==null,onClick:()=>void ge(a),className:"rounded p-1 text-[#9CA3AF] hover:bg-[#F3F4F6] disabled:opacity-40 dark:hover:bg-[#27272a]",children:A===`marketplace:refresh:${a.name}`?e.jsx(Z,{className:"h-3 w-3 animate-spin"}):e.jsx(fe,{className:"h-3 w-3"})}),e.jsx("button",{type:"button","aria-label":t("settings.plugins.removeMarketplaceAria",{name:a.name}),disabled:A!==null,onClick:()=>void re(a),className:T("rounded p-1 text-[#9CA3AF] disabled:opacity-40",J===`marketplace:remove:${a.name}`?"bg-red-100 text-red-700 dark:bg-red-950/50 dark:text-red-300":"hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-950/30"),children:J===`marketplace:remove:${a.name}`?e.jsx("span",{className:"px-1 text-[8.5px]",children:t("settings.plugins.confirm")}):e.jsx(ye,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1",children:[a.plugins.slice(0,12).map(v=>e.jsxs("button",{type:"button",disabled:v.installed||A!==null,onClick:()=>{Y(`${v.name}@${a.name}`),_(!1)},title:v.description,className:"rounded bg-[#F3F4F6] px-1.5 py-0.5 text-[8.5px] text-[#6B7280] disabled:opacity-40 dark:bg-[#27272a] dark:text-[#a1a1aa]",children:[v.name,v.installed?t("settings.plugins.installedSuffix"):""]},v.name)),a.plugins.length>12&&e.jsxs("span",{className:"px-1 py-0.5 text-[8.5px] text-[#9CA3AF]",children:["+",a.plugins.length-12]})]})]},a.name)),!x&&d.length===0&&e.jsx("div",{className:"px-3 py-4 text-center text-[10px] text-[#9CA3AF]",children:t("settings.plugins.marketplaceEmpty")})]})]}):e.jsx("div",{className:"font-mono text-[12px] text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.plugins.selectProject")})}const vt={not_required:"settings.trust.state.notRequired",trusted:"settings.trust.state.trusted",untrusted:"settings.trust.state.review",error:"settings.trust.state.error"};function kt(){const t=ce(),g=be(P=>{var r;return(r=P.currentSessionRef)==null?void 0:r.projectPath}),k=n.useMemo(()=>g??new URLSearchParams(window.location.search).get("project")??"",[g]),[b,l]=n.useState(null),[U,L]=n.useState(""),[D,y]=n.useState(!1),[i,M]=n.useState(null),[o,f]=n.useState(null),[R,c]=n.useState(null),[E,m]=n.useState(!1),N=n.useRef(0),K=n.useRef(k);K.current=k;const h=U===k?b:null,x=n.useCallback(async()=>{const P=++N.current;if(!k){l(null),L(""),c(null);return}y(!0),c(null);try{const r=await $(`/workspace-trust?projectPath=${encodeURIComponent(k)}`);if(P!==N.current)return;l(r),L(k)}catch(r){if(P!==N.current)return;c(r instanceof Error?r.message:t("settings.trust.loadFailed"))}finally{P===N.current&&y(!1)}},[k,t]);n.useEffect(()=>(f(null),m(!1),x(),()=>{N.current+=1}),[x]);const O=async P=>{if(!h)return;const r=k;M(P),c(null);try{const u=await $("/workspace-trust",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({projectPath:r,action:P})});K.current===r&&(l(u),L(r),f(null),m(u.reloadRequired===!0))}catch(u){K.current===r&&c(u instanceof Error?u.message:t("settings.trust.updateFailed"))}finally{M(null)}};if(!k)return e.jsx("div",{className:"font-mono text-[12px] text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.trust.selectSession")});const A=(h==null?void 0:h.state)==="trusted",I=(h==null?void 0:h.state)==="untrusted";return e.jsxs("div",{className:"flex min-h-0 flex-col gap-3 font-mono",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-md border border-[#E5E7EB] bg-[#F9FAFB] p-3 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[A?e.jsx(Ae,{className:"h-4 w-4 text-emerald-600"}):e.jsx(Oe,{className:T("h-4 w-4",I?"text-amber-600":"text-[#71717a]")}),e.jsx("span",{className:"text-[13px] font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t(h?vt[h.state]:"settings.trust.heading")}),D&&e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"})]}),e.jsx("p",{className:"mt-1 break-all text-[10.5px] text-[#71717a]",children:k}),h&&e.jsxs("p",{className:"mt-1 break-all text-[10px] text-[#9CA3AF]",children:[h.decision,h.inheritedFrom?t("settings.trust.inheritedFrom",{source:h.inheritedFrom}):""]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>void x(),disabled:D||i!==null,"aria-label":t("settings.trust.reloadAria"),className:"inline-flex h-8 items-center gap-1 rounded-md border border-[#E5E7EB] px-2 text-[11px] text-[#6B7280] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#a1a1aa]",children:[e.jsx(fe,{className:"h-3.5 w-3.5"}),t("settings.common.reload")]}),A?e.jsx("button",{type:"button",onClick:()=>f("revoke"),disabled:i!==null,className:"h-8 rounded-md border border-red-200 px-2.5 text-[11px] text-red-600 disabled:opacity-50 dark:border-red-900 dark:text-red-400",children:t("settings.trust.revoke")}):e.jsx("button",{type:"button",onClick:()=>f("trust"),disabled:i!==null||(h==null?void 0:h.state)==="error"||!h||h.sensitiveSources===0,className:"h-8 rounded-md bg-emerald-600 px-2.5 text-[11px] font-semibold text-white disabled:opacity-50",children:t("settings.trust.trustWorkspace")})]})]}),(R||(h==null?void 0:h.error))&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:R||(h==null?void 0:h.error)}),E&&e.jsx("div",{role:"status",className:"rounded-md border border-blue-200 bg-blue-50 px-3 py-2 text-[11px] text-blue-700 dark:border-blue-900/60 dark:bg-blue-950/30 dark:text-blue-300",children:t("settings.trust.restartNotice")}),o&&h&&e.jsxs("div",{role:"alertdialog","aria-label":t(o==="trust"?"settings.trust.trustWorkspace":"settings.trust.revokeAria"),className:"flex flex-wrap items-center justify-between gap-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 dark:border-amber-900/70 dark:bg-amber-950/30",children:[e.jsx("span",{className:"max-w-[620px] text-[11px] text-amber-900 dark:text-amber-200",children:o==="trust"?t("settings.trust.confirmTrust",{count:h.sensitiveSources}):t("settings.trust.confirmRevoke")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(null),className:"h-7 rounded px-2 text-[11px] text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.common.cancel")}),e.jsx("button",{type:"button",onClick:()=>void O(o),disabled:i!==null,className:T("h-7 rounded px-2.5 text-[11px] font-semibold text-white disabled:opacity-50",o==="trust"?"bg-emerald-600":"bg-red-600"),children:t(i?"settings.trust.saving":o==="trust"?"settings.trust.trustReviewed":"settings.trust.revokeTrust")})]})]}),e.jsxs("div",{className:"min-h-0 overflow-y-auto rounded-md border border-[#E5E7EB] dark:border-[#27272a]",children:[((h==null?void 0:h.sources)??[]).map(P=>e.jsxs("div",{className:"border-b border-[#E5E7EB] px-3 py-2 last:border-b-0 dark:border-[#27272a]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"font-semibold text-[#111827] dark:text-[#E5E5E5]",children:P.path}),e.jsx("span",{className:"rounded bg-[#E5E7EB] px-1.5 py-0.5 text-[9px] uppercase text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",children:P.kind})]}),P.warning&&e.jsx("p",{className:"mt-1 text-[10px] text-amber-700 dark:text-amber-300",children:P.warning}),e.jsx("div",{className:"mt-1.5 flex flex-col gap-1",children:P.effects.map((r,u)=>e.jsxs("div",{className:"break-all text-[10.5px] text-[#374151] dark:text-[#d4d4d8]",children:[e.jsx("span",{className:"text-[#9CA3AF]",children:r.kind})," · ",r.name,r.target?` → ${r.target}`:""]},`${r.kind}-${r.name}-${u}`))})]},`${P.kind}-${P.path}`)),h&&h.sources.length===0&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-[#9CA3AF]",children:t("settings.trust.empty")})]})]})}const Nt={anthropic:{bg:"#d97757",label:"A"},gemini:{bg:"#4285f4",label:"G"},"azure-openai":{bg:"#0078d4",label:"Az"},"gpt-openai-platform":{bg:"#10a37f",label:"GP"}},Et={searchTasks:"settings.shortcuts.action.searchTasks",openCommands:"settings.shortcuts.action.openCommands",newTask:"settings.shortcuts.action.newTask",focusComposer:"settings.shortcuts.action.focusComposer",toggleSidebar:"settings.shortcuts.action.toggleSidebar"},Ke={auto:"settings.style.auto",pragmatic:"settings.style.pragmatic",friendly:"settings.style.friendly",explanatory:"settings.style.explanatory"},$e={Global:"settings.shortcuts.scope.global",Chat:"settings.shortcuts.scope.chat",Layout:"settings.shortcuts.scope.layout"};function Pt(){var Be,Me;const t=ce(),{locale:g}=Xe(),{isSettingsOpen:k,settingsSection:b,toggleSettings:l,isSidebarOpen:U,setSidebarOpen:L}=ve(),{configuredModels:D,loadModels:y,isLoading:i,error:M}=Ze(),o=et(),[f,R]=n.useState("general"),[c,E]=n.useState(!1),[m,N]=n.useState(null),[K,h]=n.useState(null),[x,O]=n.useState(null),[A,I]=n.useState([]),[P,r]=n.useState(null),[u,Y]=n.useState(null),[z,Q]=n.useState(null),[G,_]=n.useState(null),[J,w]=n.useState({}),[S,B]=n.useState(null),[V,q]=n.useState(null),[le,d]=n.useState(""),[F,se]=n.useState("all"),xe=n.useRef(null),pe=n.useRef(null),ee=n.useRef(0),[me,je]=n.useState(typeof Notification>"u"?"unsupported":Notification.permission),ae=[{value:"general",label:t("settings.tab.general"),category:t("settings.category.settings")},{value:"trust",label:t("settings.tab.trust"),category:t("settings.category.settings")},{value:"models",label:t("settings.tab.models"),category:t("settings.category.settings")},{value:"shortcuts",label:t("settings.tab.shortcuts"),category:t("settings.category.settings")},{value:"mcp",label:t("settings.tab.mcp"),category:t("settings.category.integrations")},{value:"skills",label:t("settings.tab.skills"),category:t("settings.category.integrations")},{value:"plugins",label:t("settings.tab.plugins"),category:t("settings.category.integrations")},{value:"hooks",label:t("settings.tab.hooks"),category:t("settings.category.integrations")}],ge=n.useMemo(()=>tt.map(s=>({action:t(Et[s.id]),combo:st(s),scope:s.scope})),[g]).filter(s=>{const p=s.action.toLowerCase().includes(le.toLowerCase()),j=F==="all"||s.scope.toLowerCase()===F;return p&&j}),re=D.reduce((s,p)=>{const j=p.provider||"unknown";return s[j]||(s[j]=[]),s[j].push(p),s},{}),a=new Map(A.map(s=>[s.id,s]));for(const s of A)s.custom&&!re[s.id]&&(re[s.id]=[]);const v=n.useCallback(async()=>{try{I(await $("/providers")),_(null)}catch(s){_(s instanceof Error?s.message:t("settings.models.loadChannelsFailed"))}},[t]);n.useEffect(()=>{k&&(R(b),y(),v(),o.loadSettings())},[k,y,v,o.loadSettings,b]);const X=()=>{const s=pe.current,p=s!=null&&s.isConnected?s:document.querySelector("[data-settings-trigger]");p==null||p.focus({preventScroll:!0})},H=()=>{l(),requestAnimationFrame(X)};n.useLayoutEffect(()=>{if(!k)return;const s=document.activeElement instanceof HTMLElement?document.activeElement:null;s&&s!==document.body&&s!==document.documentElement&&!s.closest("[data-settings-panel]")&&(pe.current=s);const p=requestAnimationFrame(()=>{var j;(j=xe.current)==null||j.focus({preventScroll:!0})});return()=>{cancelAnimationFrame(p),requestAnimationFrame(X)}},[k]);const oe=async s=>{B("save"),q(null);try{return await $("/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:s.provider,displayName:s.displayName,model:s.model,apiKey:s.apiKey,modelProvider:s.modelProvider,overrides:s.overrides})}),await y(),await v(),!0}catch(p){return q(p instanceof Error?p.message:t("settings.models.saveFailed")),!1}finally{B(null)}},te=async()=>{typeof Notification>"u"||je(await Notification.requestPermission())},he=async s=>{B("delete"),q(null);try{await $(`/models/${s}`,{method:"DELETE"}),await y(),O(null)}catch(p){q(p instanceof Error?p.message:t("settings.models.deleteFailed"))}finally{B(null)}},Ue=async(s,p)=>{B("update"),q(null);try{return await $(`/models/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)}),await y(),!0}catch(j){return q(j instanceof Error?j.message:t("settings.models.updateFailed")),!1}finally{B(null)}},Ie=async(s,p)=>{Q({providerId:s,type:"update"}),_(null);try{return await $(`/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)}),await Promise.all([y(),v()]),!0}catch(j){return _(j instanceof Error?j.message:t("settings.models.updateChannelFailed")),!1}finally{Q(null)}},ze=async(s,p)=>{Q({providerId:s.id,type:"probe"}),_(null);try{const j=await $(`/providers/${s.id}/probe`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modelId:p})});w(C=>({...C,[s.id]:j}))}catch(j){_(j instanceof Error?j.message:t("settings.models.probeFailed"))}finally{Q(null)}},_e=async s=>{Q({providerId:s.id,type:"delete"}),_(null);try{await $(`/providers/${s.id}?removeModels=true`,{method:"DELETE"}),Y(null),N(null),w(p=>{const j={...p};return delete j[s.id],j}),await Promise.all([y(),v()])}catch(p){_(p instanceof Error?p.message:t("settings.models.deleteChannelFailed"))}finally{Q(null)}},qe=(s,p)=>{var ue,ne;const j=s.key==="ArrowRight"||s.key==="ArrowDown"?1:s.key==="ArrowLeft"||s.key==="ArrowUp"?-1:0;if(j===0&&s.key!=="Home"&&s.key!=="End")return;s.preventDefault();const C=s.key==="Home"?0:s.key==="End"?ae.length-1:(p+j+ae.length)%ae.length;R(ae[C].value),(ne=(ue=s.currentTarget.closest('[role="tablist"]'))==null?void 0:ue.querySelectorAll('[role="tab"]')[C])==null||ne.focus()},He=s=>{N(m===s?null:s)},Ge=s=>{if(!k||s.key!=="Escape"||!(s.target instanceof Node)||!s.currentTarget.contains(s.target)||c||K||P||Date.now()-ee.current<250)return;const p=s.target instanceof Element?s.target:null;if(!(s.defaultPrevented||p!=null&&p.closest('[role="dialog"]'))){if(s.preventDefault(),x){O(null);return}if(u){Y(null);return}H()}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-settings-panel":!0,onKeyDown:Ge,className:"flex h-full min-h-0 bg-white dark:bg-[#09090b]",children:[e.jsxs("nav",{role:"tablist","aria-label":t("settings.nav.aria"),className:"flex h-full w-[220px] shrink-0 flex-col border-r border-[#E5E7EB] bg-[#F9FAFB] dark:border-zinc-800 dark:bg-[#111113]",children:[e.jsx("div",{className:"shrink-0 p-4",children:e.jsxs("button",{ref:xe,type:"button",onClick:H,className:"inline-flex items-center gap-1.5 rounded-md px-2 py-1.5 text-[12px] font-mono text-[#6B7280] transition-colors hover:bg-[#E5E7EB] hover:text-[#111827] dark:text-[#a1a1aa] dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:[e.jsx(dt,{className:"h-3.5 w-3.5"}),t("settings.action.back")]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-3 pb-4",children:Object.entries(ae.reduce((s,p)=>(s[p.category]||(s[p.category]=[]),s[p.category].push(p),s),{})).map(([s,p])=>e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"mb-1 px-3 text-[10px] font-semibold uppercase tracking-wider text-[#9CA3AF] dark:text-[#71717a]",children:s}),p.map(j=>e.jsx("button",{onClick:()=>R(j.value),onKeyDown:C=>qe(C,ae.indexOf(j)),role:"tab",id:`settings-tab-${j.value}`,"aria-controls":`settings-panel-${j.value}`,"aria-selected":f===j.value,tabIndex:f===j.value?0:-1,className:T("w-full rounded-md px-3 py-1.5 text-left text-[13px] transition-colors",f===j.value?"bg-[#E5E7EB] font-medium text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] hover:bg-[#E5E7EB]/60 hover:text-[#111827] dark:text-[#a1a1aa] dark:hover:bg-[#27272a]/50 dark:hover:text-[#E5E5E5]"),children:j.label},j.value))]},s))})]}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 overflow-y-auto p-6 sm:p-10",children:e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx("h1",{className:"mb-6 text-xl font-semibold text-[#111827] dark:text-[#E5E5E5]",children:((Be=ae.find(s=>s.value===f))==null?void 0:Be.label)??t("settings.title")}),o.isLoading&&f==="general"&&e.jsxs("div",{role:"status",className:"flex shrink-0 items-center gap-2 text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"}),t("settings.general.loading")]}),o.error&&f==="general"&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(ke,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:o.error}),e.jsx("button",{type:"button",onClick:()=>void o.loadSettings(),className:"shrink-0 underline",children:t("settings.common.retry")})]}),f==="models"&&e.jsxs("div",{id:"settings-panel-models",role:"tabpanel","aria-labelledby":"settings-tab-models",className:"flex flex-col gap-6 flex-1 min-h-0 overflow-hidden",children:[e.jsx("p",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono shrink-0",children:t("settings.models.description")}),(M||V||G)&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(ke,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:G||V||M}),e.jsx("button",{type:"button",onClick:()=>{q(null),_(null),M&&y()},className:"shrink-0 underline",children:t(M?"settings.common.retry":"settings.common.dismiss")})]}),x&&e.jsxs("div",{role:"alertdialog","aria-label":t("settings.models.deleteModelAria",{name:x.displayName||x.model}),className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:t("settings.models.deleteModelPrompt",{name:x.displayName||x.model})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>O(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.common.cancel")}),e.jsx("button",{type:"button",onClick:()=>void he(x.id),disabled:S!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:t(S==="delete"?"settings.models.deleting":"settings.models.deleteModel")})]})]}),u&&e.jsxs("div",{role:"alertdialog","aria-label":t("settings.models.deleteChannelAria",{name:u.name}),className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:t("settings.models.deleteChannelPrompt",{name:u.name,count:((Me=re[u.id])==null?void 0:Me.length)??0})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Y(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:t("settings.common.cancel")}),e.jsx("button",{type:"button",onClick:()=>void _e(u),disabled:z!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(z==null?void 0:z.type)==="delete"?t("settings.models.deleting"):t("settings.models.deleteChannel")})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:e.jsxs("div",{className:"flex flex-col gap-2 pr-2",children:[i&&D.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(Z,{className:"h-4 w-4 animate-spin"}),t("settings.models.loading")]}),Object.entries(re).map(([s,p])=>{const j=Nt[s]||{bg:"#71717a",label:"?"},C=a.get(s),ue=m===s,ne=J[s],Je=(z==null?void 0:z.providerId)===s&&z.type==="probe";return e.jsxs("div",{className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs("button",{onClick:()=>He(s),className:"flex min-w-0 flex-1 items-center justify-between p-4 text-left transition-colors hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded text-xs font-bold text-white",style:{backgroundColor:j.bg},children:j.label}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5 text-left",children:[e.jsx("span",{className:"truncate text-sm font-semibold font-mono text-[#111827] dark:text-[#E5E5E5]",children:(C==null?void 0:C.name)??s.replace(/-/g," ")}),e.jsxs("span",{className:"truncate text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[p.length===1?t("settings.models.modelCountOne",{count:p.length}):t("settings.models.modelCountMany",{count:p.length}),C!=null&&C.custom?` · ${C.wireApi}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[e.jsxs("span",{className:T("text-xs font-mono",(C==null?void 0:C.configured)===!1?"text-amber-600":"text-[#16A34A]"),children:["●"," ",(C==null?void 0:C.configured)===!1?t("settings.models.missingCredential"):t("settings.models.configured")]}),e.jsx(Le,{className:T("h-4 w-4 text-[#9CA3AF] transition-transform dark:text-[#71717a]",ue&&"rotate-180")})]})]}),(C==null?void 0:C.custom)&&e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pr-3",children:[e.jsx("button",{type:"button",onClick:()=>{var W;return void ze(C,(W=p[0])==null?void 0:W.id)},disabled:z!==null||p.length===0,"aria-label":t("settings.models.testChannelAria",{name:C.name}),className:"rounded p-1.5 text-[#71717a] hover:bg-[#E5E7EB] hover:text-[#111827] disabled:opacity-50 dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:Je?e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ct,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","data-edit-provider-trigger":C.id,onClick:()=>{_(null),r(C)},disabled:z!==null,"aria-label":t("settings.models.editChannelAria",{name:C.name}),className:"rounded p-1.5 text-[#71717a] hover:bg-[#E5E7EB] hover:text-[#111827] disabled:opacity-50 dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:e.jsx(De,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>Y(C),disabled:z!==null,"aria-label":t("settings.models.deleteChannelActionAria",{name:C.name}),className:"rounded p-1.5 text-[#71717a] hover:bg-[#E5E7EB] hover:text-red-500 disabled:opacity-50 dark:hover:bg-[#27272a] dark:hover:text-red-400",children:e.jsx(ye,{className:"h-3.5 w-3.5"})})]})]}),ne&&e.jsxs("div",{role:"status",className:T("border-t px-4 py-2 font-mono text-[11px]",ne.ok?"border-green-200 bg-green-50 text-green-700 dark:border-green-900/60 dark:bg-green-950/20 dark:text-green-300":"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/20 dark:text-amber-300"),children:[ne.message," · ",ne.latencyMs,"ms · ",ne.wireApi]}),ue&&e.jsxs("div",{className:"border-t border-[#E5E7EB] dark:border-zinc-800",children:[(C==null?void 0:C.custom)&&e.jsxs("div",{className:"border-b border-[#E5E7EB] px-4 py-2 font-mono text-[11px] text-[#71717a] dark:border-zinc-800",children:[e.jsx("span",{className:"font-semibold",children:C.id})," ","· ",C.defaultBaseUrl]}),p.map(W=>{var Fe;return e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23] group",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-[#111827] dark:text-[#E5E5E5] font-mono truncate",children:W.displayName||W.model}),e.jsxs("span",{className:"text-xs text-[#9CA3AF] dark:text-[#71717a] font-mono truncate",children:[W.displayName&&`${W.model} · `,((Fe=W.overrides)==null?void 0:Fe.baseUrl)||t("settings.models.defaultEndpoint")]})]}),e.jsxs("div",{className:"flex items-center gap-2 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:[e.jsx("button",{"data-edit-model-trigger":W.id,onClick:()=>{q(null),h(W)},disabled:S!==null,"aria-label":t("settings.models.editModelAria",{name:W.displayName||W.model}),className:"p-1.5 text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(De,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>O(W),disabled:S!==null,"aria-label":t("settings.models.deleteModelAria",{name:W.displayName||W.model}),className:"p-1.5 text-[#9CA3AF] hover:text-red-500 hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-red-400 dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(ye,{className:"h-3.5 w-3.5"})})]})]},W.id)})]})]},s)}),!i&&!M&&Object.keys(re).length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:t("settings.models.empty")})]})}),e.jsx("button",{"data-add-model-trigger":!0,onClick:()=>{q(null),E(!0)},disabled:S!==null,className:"w-full py-3 rounded-md text-[#6B7280] dark:text-[#a1a1aa] text-[13px] font-mono hover:bg-[#F3F4F6] dark:bg-[#18181b] transition-colors shrink-0",children:t("settings.models.add")})]}),f==="general"&&e.jsxs("div",{id:"settings-panel-general",role:"tabpanel","aria-labelledby":"settings-tab-general","aria-busy":o.isLoading,className:"flex flex-col gap-6 overflow-x-hidden overflow-y-auto pr-2 [&>div>div.flex]:flex-wrap [&>div>div.flex]:gap-2 [&_select]:max-w-full",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:t("settings.tab.general")}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.general.responseLanguage")}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:t("settings.general.responseLanguageHint")})]}),e.jsx(de,{"aria-label":t("settings.general.responseLanguage"),value:o.language,onChange:s=>o.updateSettings({language:s}),className:"h-8 w-auto min-w-[140px] text-[12px]",options:[{value:"en-US",label:"English (US)"},{value:"zh-CN",label:"简体中文"},{value:"zh-TW",label:"繁體中文"},{value:"ja-JP",label:"日本語"},{value:"ko-KR",label:"한국어"},{value:"es-ES",label:"Español"},{value:"fr-FR",label:"Français"},{value:"de-DE",label:"Deutsch"},{value:"pt-BR",label:"Português (BR)"},{value:"ru-RU",label:"Русский"}]})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.general.autoSave")}),e.jsx(ie,{label:t("settings.general.autoSave"),enabled:o.autoSaveSessions,onChange:s=>o.updateSettings({autoSaveSessions:s})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.general.communicationStyle")}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:t("settings.general.communicationStyleHint")})]}),e.jsx(de,{"aria-label":t("settings.general.communicationStyle"),value:o.communicationStyle??"auto",onChange:s=>o.updateSettings({communicationStyle:s}),className:"h-8 w-auto min-w-[140px] text-[12px]",options:xt.map(s=>({value:s.id,label:Ke[s.id]?t(Ke[s.id]):s.name}))})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:t("settings.appearance.heading")}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.appearance.theme")}),e.jsx("div",{className:"flex items-center gap-2 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md p-1",children:["dark","light","system"].map(s=>e.jsx("button",{onClick:()=>o.updateSettings({uiTheme:s}),className:T("px-3 py-1 rounded text-[12px] font-mono transition-colors",o.uiTheme===s?"bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5]":"text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5]"),children:t(s==="dark"?"settings.appearance.theme.dark":s==="light"?"settings.appearance.theme.light":"settings.appearance.theme.system")},s))})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.appearance.compactSidebar")}),e.jsx(ie,{label:t("settings.appearance.compactSidebar"),enabled:!U,onChange:s=>L(!s)})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.appearance.codeTheme")}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:t("settings.appearance.codeThemeHint")})]}),e.jsx(de,{"aria-label":t("settings.appearance.codeTheme"),value:o.theme,onChange:s=>o.updateSettings({theme:s}),className:"h-8 w-auto min-w-[140px] text-[12px]",options:[{value:"dracula",label:"Dracula"},{value:"monokai",label:"Monokai"},{value:"nord",label:"Nord"},{value:"tokyo-night",label:"Tokyo Night"},{value:"one-dark",label:"One Dark"},{value:"catppuccin",label:"Catppuccin"},{value:"gruvbox",label:"Gruvbox"},{value:"github",label:"GitHub"},{value:"solarized-light",label:"Solarized Light"},{value:"solarized-dark",label:"Solarized Dark"},{value:"ayu-dark",label:"Ayu Dark"},{value:"rose-pine",label:"Rose Pine"},{value:"kanagawa",label:"Kanagawa"}]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:t("settings.notifications.heading")}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.notifications.buildFinished")}),e.jsx(ie,{label:t("settings.notifications.buildFinished"),enabled:o.notifyBuild,onChange:s=>o.updateSettings({notifyBuild:s})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.notifications.errorsOnly")}),e.jsx(ie,{label:t("settings.notifications.errorsOnly"),enabled:o.notifyErrors,onChange:s=>o.updateSettings({notifyErrors:s})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.notifications.systemSounds")}),e.jsx(ie,{label:t("settings.notifications.systemSounds"),enabled:o.notifySounds,onChange:s=>o.updateSettings({notifySounds:s})})]}),(o.notifyBuild||o.notifyErrors)&&me!=="granted"&&e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-md border border-[#E5E7EB] bg-[#F9FAFB] px-3 py-2 dark:border-[#27272a] dark:bg-[#18181b]",children:[e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:t(me==="denied"?"settings.notifications.blocked":me==="unsupported"?"settings.notifications.unavailable":"settings.notifications.enablePrompt")}),me==="default"&&e.jsx("button",{type:"button",onClick:()=>void te(),className:"shrink-0 rounded-md bg-[#111827] px-2.5 py-1.5 text-[10px] font-mono text-white hover:bg-[#374151] dark:bg-[#E5E5E5] dark:text-[#111827]",children:t("settings.common.enable")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:t("settings.privacy.heading")}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.privacy.telemetry")}),e.jsx(ie,{label:t("settings.privacy.telemetry"),enabled:o.privacyTelemetry,onChange:s=>o.updateSettings({privacyTelemetry:s})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:t("settings.privacy.crash")}),e.jsx(ie,{label:t("settings.privacy.crash"),enabled:o.privacyCrash,onChange:s=>o.updateSettings({privacyCrash:s})})]})]})]}),f==="shortcuts"&&e.jsxs("div",{id:"settings-panel-shortcuts",role:"tabpanel","aria-labelledby":"settings-tab-shortcuts",className:"flex flex-col gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 sm:flex-row sm:items-center sm:gap-3",children:[e.jsx("input",{"aria-label":t("settings.shortcuts.searchPlaceholder"),value:le,onChange:s=>d(s.target.value),placeholder:t("settings.shortcuts.searchPlaceholder"),className:"field flex-1 text-[12px]"}),e.jsx(de,{"aria-label":t("settings.shortcuts.col.scope"),value:F,onChange:s=>se(s),className:"w-auto min-w-[120px] text-[12px]",options:[{value:"all",label:t("settings.shortcuts.scope.all")},{value:"global",label:t("settings.shortcuts.scope.global")},{value:"chat",label:t("settings.shortcuts.scope.chat")},{value:"layout",label:t("settings.shortcuts.scope.layout")}]}),e.jsx("button",{onClick:()=>{d(""),se("all")},className:"h-9 px-3 rounded-md bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:t("settings.shortcuts.reset")})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto border border-[#E5E7EB] dark:border-[#27272a] rounded-lg bg-[#E5E7EB] dark:bg-[#111827]",children:[e.jsxs("div",{className:"grid min-w-[520px] grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 bg-white dark:bg-[#0C0C0C] text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono font-semibold",children:[e.jsx("span",{children:t("settings.shortcuts.col.action")}),e.jsx("span",{children:t("settings.shortcuts.col.shortcut")}),e.jsx("span",{children:t("settings.shortcuts.col.scope")})]}),ge.map((s,p)=>e.jsxs("div",{className:T("grid min-w-[520px] grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 text-[13px] font-mono",p%2===0?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C]"),children:[e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5]",children:s.action}),e.jsx("div",{className:"flex items-center gap-1",children:s.combo.map(j=>e.jsx("span",{className:"px-2 py-0.5 rounded bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:j},j))}),e.jsx("span",{className:"text-[#6B7280] dark:text-[#94a3b8] text-[12px]",children:$e[s.scope]?t($e[s.scope]):s.scope})]},`${s.action}-${s.scope}`)),ge.length===0&&e.jsx("div",{className:"px-3 py-6 text-center text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono",children:t("settings.shortcuts.empty")})]})]}),f==="mcp"&&e.jsxs("div",{id:"settings-panel-mcp",role:"tabpanel","aria-labelledby":"settings-tab-mcp",className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa]",children:[e.jsx("p",{children:t("settings.mcp.description")}),e.jsx("button",{type:"button",onClick:()=>{ve.getState().toggleMcp()},className:"mt-3 inline-flex h-8 items-center gap-1.5 rounded-md border border-[#E5E7EB] px-3 text-[12px] font-medium text-[#111827] transition-colors hover:bg-[#F3F4F6] dark:border-zinc-700 dark:text-[#E5E5E5] dark:hover:bg-[#27272a]",children:t("settings.mcp.open")})]}),f==="skills"&&e.jsxs("div",{id:"settings-panel-skills",role:"tabpanel","aria-labelledby":"settings-tab-skills",className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa]",children:[e.jsx("p",{children:t("settings.skills.description")}),e.jsx("button",{type:"button",onClick:()=>{ve.getState().toggleSkills()},className:"mt-3 inline-flex h-8 items-center gap-1.5 rounded-md border border-[#E5E7EB] px-3 text-[12px] font-medium text-[#111827] transition-colors hover:bg-[#F3F4F6] dark:border-zinc-700 dark:text-[#E5E5E5] dark:hover:bg-[#27272a]",children:t("settings.skills.open")})]}),f==="hooks"&&e.jsx("div",{id:"settings-panel-hooks",role:"tabpanel","aria-labelledby":"settings-tab-hooks",className:"min-h-0 flex-1",children:e.jsx(bt,{})}),f==="plugins"&&e.jsx("div",{id:"settings-panel-plugins",role:"tabpanel","aria-labelledby":"settings-tab-plugins",className:"min-h-0 flex-1",children:e.jsx(jt,{})}),f==="trust"&&e.jsx("div",{id:"settings-panel-trust",role:"tabpanel","aria-labelledby":"settings-tab-trust",className:"min-h-0 flex-1",children:e.jsx(kt,{})})]})})})]}),c&&e.jsx(ut,{open:!0,onOpenChange:s=>{s||(ee.current=Date.now()),E(s)},onSave:oe,saveError:V}),K&&e.jsx(pt,{open:!0,onOpenChange:s=>{s||(ee.current=Date.now(),h(null))},model:K,onSave:Ue,saveError:V}),P&&e.jsx(gt,{provider:P,onOpenChange:s=>{s||(ee.current=Date.now(),r(null))},onSave:Ie,saveError:G})]})}function ie({label:t,enabled:g,onChange:k}){return e.jsx("button",{type:"button",role:"switch","aria-label":t,"aria-checked":g,onClick:()=>k(!g),className:T("flex h-6 w-11 items-center rounded-full px-1 transition-colors",g?"bg-[#22C55E]":"bg-[#E5E7EB] dark:bg-[#27272a]"),children:e.jsx("span",{className:T("h-4 w-4 rounded-full transition-transform",g?"translate-x-5 bg-white":"translate-x-0 bg-white dark:bg-[#a1a1aa]")})})}export{Pt as SettingsModal};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./vendor-react-DG5dkZ_t.js";import{e as G}from"./useRequest-BvqVDnKl.js";import{b as ee,a as te,D as U,e as P,F as se,g as M,j as g,x as F,y as ae}from"./index-bjyn3NHs.js";import{i as le,a as ne,X as Q,f as oe,L as W,T as re}from"./vendor-icons-D_AkWmWB.js";import"./vendor-radix-DBy9B2DN.js";const O=n=>n?{"x-blade-directory":n}:void 0,de=async n=>F("/skills",{headers:O(n)}),ie=async()=>F("/skills/catalog");function ue(){const{isSkillsOpen:n,toggleSkills:d}=ee(),i=te(t=>{var j,y;return((j=t.currentSessionRef)==null?void 0:j.projectPath)??t.selectedProjectPath??((y=t.taskWorkspaceInfo)==null?void 0:y.cwd)??null}),[x,f]=l.useState(null),[c,h]=l.useState(""),[w,o]=l.useState(null),[r,N]=l.useState(null),[A,m]=l.useState(null),[S,p]=l.useState(!1),[B,b]=l.useState(!1),[I,k]=l.useState("confirm"),[D,v]=l.useState(null),[C,a]=l.useState(null),{data:u=[],loading:E,error:R,run:q,runAsync:$}=G(()=>de(i),{refreshDeps:[n,i],ready:n,onSuccess:t=>{t.length>0&&!x&&f(t[0].id)}}),{data:X=[],loading:K,error:T,run:V}=G(ie,{refreshDeps:[n],ready:n}),z=u.filter(t=>t.name.toLowerCase().includes(c.toLowerCase())),s=l.useMemo(()=>u.find(t=>t.id===x)??u[0],[u,x]),H=async(t,j,y)=>{N({type:t,name:j.name}),o(null);try{await F(t==="delete"?`/skills/${encodeURIComponent(j.name)}`:`/skills/${encodeURIComponent(j.name)}/toggle`,{method:t==="delete"?"DELETE":"POST",headers:{...O(i),...t==="toggle"?{"Content-Type":"application/json"}:{}},body:t==="toggle"?JSON.stringify({enabled:y}):void 0}),await $(),t==="delete"&&(m(null),f(null))}catch(J){o(J instanceof Error?J.message:`Failed to ${t} skill`)}finally{N(null)}},Y=()=>{p(!0)},Z=t=>{a(t),v(null),k("confirm"),b(!0)},_=async()=>{if(C){k("installing"),v(null);try{const t=await F("/skills/install",{method:"POST",headers:{"Content-Type":"application/json",...O(i)},body:JSON.stringify(C)});if(t.success===!1)throw new Error(t.error||"Failed to install skill");await $(),b(!1),p(!1)}catch(t){v(t instanceof Error?t.message:"Failed to install skill"),k("failed")}}};return e.jsxs(l.Fragment,{children:[e.jsx(U,{open:n,onOpenChange:d,children:e.jsxs(P,{onCloseAutoFocus:se,className:"flex h-[min(620px,calc(100dvh-24px))] flex-col gap-0 overflow-hidden rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[820px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Skills"}),e.jsx("div",{className:"flex h-full min-h-0 min-w-0",children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 p-4 sm:gap-5 sm:p-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Skills"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{"data-skill-install-trigger":!0,onClick:Y,className:"h-8 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-xs font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a]",children:[e.jsx(le,{className:"h-3.5 w-3.5"}),"Install skill"]}),e.jsx("button",{onClick:q,"aria-label":"Refresh skills",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",disabled:E,children:e.jsx(ne,{className:g("h-4 w-4",E&&"animate-spin")})}),e.jsx("button",{onClick:d,"aria-label":"Close skills",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(Q,{className:"h-4 w-4"})})]})]}),w&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(oe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:w}),e.jsx("button",{type:"button",onClick:()=>o(null),className:"shrink-0 underline",children:"Dismiss"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-hidden sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex h-[180px] w-full shrink-0 flex-col gap-3 overflow-hidden sm:h-auto sm:w-[220px]",children:[e.jsx("div",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Installed"}),e.jsx("input",{type:"search","aria-label":"Search installed skills",value:c,onChange:t=>h(t.target.value),placeholder:"Search skills...",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a] shrink-0"}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-y-auto flex-1 min-h-0 pr-1",children:[E&&u.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Loading skills..."]}),R&&!E&&e.jsxs("div",{role:"alert",className:"flex flex-col items-center gap-2 py-6 text-center text-xs font-mono text-red-600 dark:text-red-400",children:[e.jsx("span",{children:R.message}),e.jsx("button",{type:"button",onClick:q,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!R&&z.length===0&&!E&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:c?"No skills match your search":"No skills installed"}),z.map(t=>e.jsxs("button",{onClick:()=>{f(t.id),m(null),o(null)},className:g("flex w-full min-w-0 flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",t.id===x?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:g("text-[11px] font-mono font-semibold",t.enabled?"text-[#16A34A] dark:text-[#22C55E]":"text-[#f59e0b]"),children:t.enabled?"Enabled":"Disabled"})]}),e.jsx("span",{className:"block w-full min-w-0 truncate text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:t.description||"No description"})]},t.id))]})]}),s?e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-y-auto pr-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:s.name}),e.jsxs("span",{className:"text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["v",s.version]})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:s.description||"No description available"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void H("toggle",s,!s.enabled),disabled:r!==null,className:g("h-7 px-3 rounded-md text-[11px] font-mono font-semibold",s.enabled?"bg-[#E5E7EB] text-[#111827] hover:bg-[#D1D5DB] dark:bg-[#27272a] dark:text-[#E5E5E5] dark:hover:bg-[#32323a]":"bg-[#16A34A] text-white hover:bg-[#15803D] dark:bg-[#22C55E] dark:text-[#0C0C0C] dark:hover:bg-[#1ea34b]",r&&"opacity-60 cursor-not-allowed"),children:(r==null?void 0:r.type)==="toggle"&&r.name===s.name?"Saving...":s.enabled?"Disable":"Enable"}),e.jsxs("button",{onClick:()=>m(s.name),disabled:!s.removable||r!==null,title:s.removable?void 0:"Only Blade user skills can be uninstalled",className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold flex items-center gap-1 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(re,{className:"h-3 w-3"}),s.removable?"Uninstall":"Managed"]})]}),A===s.name&&e.jsxs("div",{role:"alertdialog","aria-label":`Uninstall ${s.name}`,className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:"Remove this skill from ~/.blade/skills?"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>m(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>void H("delete",s),disabled:r!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(r==null?void 0:r.type)==="delete"?"Uninstalling...":"Uninstall skill"})]})]}),e.jsx("div",{className:"h-px bg-[#E5E7EB] dark:bg-[#1f2937]"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-[12px] font-mono",children:[e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a]",children:"Provider"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5]",children:s.provider}),e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a]",children:"Location"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5] truncate",children:s.location})]})]}),s.capabilities.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Capabilities"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.capabilities.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))})]}),s.allowedTools.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Allowed Tools (",s.allowedTools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.allowedTools.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"Select a skill to view details"})})]})]})})]})}),e.jsx(xe,{open:S,catalog:X,installed:u.map(t=>t.name),catalogLoading:K,catalogError:(T==null?void 0:T.message)??null,onRetryCatalog:V,onOpenChange:p,onInstall:Z}),e.jsx(ce,{open:B,status:I,error:D,onCancel:()=>b(!1),onConfirm:_,onRetry:()=>k("confirm")})]})}function L({active:n,children:d,onClick:i}){return e.jsx("button",{onClick:i,className:g("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:d})}function xe({open:n,onOpenChange:d,onInstall:i,catalog:x,installed:f,catalogLoading:c,catalogError:h,onRetryCatalog:w}){const[o,r]=l.useState("catalog"),[N,A]=l.useState(""),[m,S]=l.useState(null),[p,B]=l.useState(""),[b,I]=l.useState(""),k=x.filter(a=>a.name.toLowerCase().includes(N.toLowerCase())),D=()=>{if(o==="catalog"){if(!m)return;i({source:"catalog",name:m});return}if(o==="repo"){if(!p)return;i({source:"repo",url:p});return}b&&i({source:"local",path:b})},v=m?f.includes(m):!1,C=o==="catalog"&&(!m||v||c||!!h)||o==="repo"&&!p||o==="local"&&!b;return e.jsx(U,{open:n,onOpenChange:d,children:e.jsxs(P,{onCloseAutoFocus:a=>ae("[data-skill-install-trigger]",a),className:"gap-0 overflow-y-auto rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[540px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Install Skill"}),e.jsxs("div",{className:"flex flex-col gap-4 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Install Skill"}),e.jsx("button",{onClick:()=>d(!1),"aria-label":"Close skill installation",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(Q,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit",children:[e.jsx(L,{active:o==="catalog",onClick:()=>r("catalog"),children:"Catalog"}),e.jsx(L,{active:o==="repo",onClick:()=>r("repo"),children:"Repo"}),e.jsx(L,{active:o==="local",onClick:()=>r("local"),children:"Local"})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[o==="catalog"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{"aria-label":"Search skill catalog",value:N,onChange:a=>A(a.target.value),placeholder:"Search catalog...",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"}),e.jsxs("div",{className:"flex max-h-[min(240px,30dvh)] flex-col gap-2 overflow-y-auto",children:[c&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-6 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Loading catalog..."]}),h&&!c&&e.jsxs("div",{role:"alert",className:"flex flex-col items-center gap-2 py-6 text-center text-xs font-mono text-red-600 dark:text-red-400",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",onClick:w,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!c&&!h&&k.length===0&&e.jsx("div",{className:"text-center py-6 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No skills found"}),!c&&!h&&k.map(a=>{const u=f.includes(a.name),E=m===a.name;return e.jsxs("button",{onClick:()=>S(a.name),className:g("rounded-lg px-3 py-2 flex flex-col gap-1 text-left transition-colors",E?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsx("span",{className:g("text-[10px] font-mono px-2 py-0.5 rounded",a.tag==="Official"?"bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:a.tag})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:a.description}),e.jsxs("span",{className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["by ",a.author]}),u&&e.jsx("span",{className:"text-[10px] font-mono text-[#16A34A] dark:text-[#22C55E]",children:"Installed"})]},a.name)})]})]}),o==="repo"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"GitHub URL"}),e.jsx("input",{"aria-label":"Skill repository URL",value:p,onChange:a=>B(a.target.value),placeholder:"https://github.com/org/skill",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"}),e.jsx("span",{className:"inline-flex w-fit px-2 py-0.5 rounded bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Uses Git credentials available to the Blade process"})]}),o==="local"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Local path"}),e.jsx("input",{"aria-label":"Local skill path",value:b,onChange:a=>I(a.target.value),placeholder:"/Users/bytedance/skills/my-skill",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:()=>d(!1),className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:D,disabled:C,className:g("h-7 px-3 rounded-md text-[11px] font-mono font-semibold",C?"bg-[#E5E7EB] text-[#9CA3AF] cursor-not-allowed dark:bg-[#27272a] dark:text-[#71717a]":"bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C]"),children:"Install"})]})]})]})})}function ce({open:n,status:d,error:i,onCancel:x,onConfirm:f,onRetry:c}){return e.jsx(U,{open:n,onOpenChange:h=>!h&&x(),children:e.jsxs(P,{className:"sm:max-w-[320px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Install Status"}),e.jsxs("div",{className:"p-5 flex flex-col gap-3",children:[d==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Confirm Install"}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Install selected skill?"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:x,className:"h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:f,className:"h-6 px-2.5 rounded-md bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Install"})]})]}),d==="installing"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Installing"}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Downloading and verifying…"}),e.jsx("div",{className:"h-1.5 rounded-full bg-[#E5E7EB] dark:bg-[#18181b] overflow-hidden",children:e.jsx("div",{className:"h-full w-[45%] bg-[#16A34A] dark:bg-[#22C55E]"})}),e.jsx("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"~35%"}),e.jsx("button",{onClick:x,className:"self-end h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Hide"})]}),d==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Install Failed"}),e.jsx("p",{className:"text-[12px] font-mono text-[#f87171]",children:i||"Installation failed."}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Check access and try again."}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:x,className:"h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Close"}),e.jsx("button",{onClick:c,className:"h-6 px-2.5 rounded-md bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Retry"})]})]})]})]})})}export{ue as SkillsModal};
1
+ import{r as l,j as e}from"./vendor-react-DG5dkZ_t.js";import{e as J}from"./useRequest-BvqVDnKl.js";import{b as ee,a as te,D as U,e as P,G as se,g as M,j as g,x as F,y as ae}from"./index-DvDtvgA4.js";import{i as le,a as ne,X as Q,f as oe,L as W,T as re}from"./vendor-icons-D_AkWmWB.js";import"./vendor-radix-DBy9B2DN.js";const O=n=>n?{"x-blade-directory":n}:void 0,de=async n=>F("/skills",{headers:O(n)}),ie=async()=>F("/skills/catalog");function ue(){const{isSkillsOpen:n,toggleSkills:d}=ee(),i=te(t=>{var j,y;return((j=t.currentSessionRef)==null?void 0:j.projectPath)??t.selectedProjectPath??((y=t.taskWorkspaceInfo)==null?void 0:y.cwd)??null}),[x,f]=l.useState(null),[c,h]=l.useState(""),[w,o]=l.useState(null),[r,N]=l.useState(null),[A,m]=l.useState(null),[S,p]=l.useState(!1),[B,b]=l.useState(!1),[I,k]=l.useState("confirm"),[D,v]=l.useState(null),[C,a]=l.useState(null),{data:u=[],loading:E,error:R,run:q,runAsync:$}=J(()=>de(i),{refreshDeps:[n,i],ready:n,onSuccess:t=>{t.length>0&&!x&&f(t[0].id)}}),{data:X=[],loading:K,error:T,run:V}=J(ie,{refreshDeps:[n],ready:n}),z=u.filter(t=>t.name.toLowerCase().includes(c.toLowerCase())),s=l.useMemo(()=>u.find(t=>t.id===x)??u[0],[u,x]),G=async(t,j,y)=>{N({type:t,name:j.name}),o(null);try{await F(t==="delete"?`/skills/${encodeURIComponent(j.name)}`:`/skills/${encodeURIComponent(j.name)}/toggle`,{method:t==="delete"?"DELETE":"POST",headers:{...O(i),...t==="toggle"?{"Content-Type":"application/json"}:{}},body:t==="toggle"?JSON.stringify({enabled:y}):void 0}),await $(),t==="delete"&&(m(null),f(null))}catch(H){o(H instanceof Error?H.message:`Failed to ${t} skill`)}finally{N(null)}},Y=()=>{p(!0)},Z=t=>{a(t),v(null),k("confirm"),b(!0)},_=async()=>{if(C){k("installing"),v(null);try{const t=await F("/skills/install",{method:"POST",headers:{"Content-Type":"application/json",...O(i)},body:JSON.stringify(C)});if(t.success===!1)throw new Error(t.error||"Failed to install skill");await $(),b(!1),p(!1)}catch(t){v(t instanceof Error?t.message:"Failed to install skill"),k("failed")}}};return e.jsxs(l.Fragment,{children:[e.jsx(U,{open:n,onOpenChange:d,children:e.jsxs(P,{onCloseAutoFocus:se,className:"flex h-[min(620px,calc(100dvh-24px))] flex-col gap-0 overflow-hidden rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[820px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Skills"}),e.jsx("div",{className:"flex h-full min-h-0 min-w-0",children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 p-4 sm:gap-5 sm:p-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Skills"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{"data-skill-install-trigger":!0,onClick:Y,className:"h-8 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-xs font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a]",children:[e.jsx(le,{className:"h-3.5 w-3.5"}),"Install skill"]}),e.jsx("button",{onClick:q,"aria-label":"Refresh skills",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",disabled:E,children:e.jsx(ne,{className:g("h-4 w-4",E&&"animate-spin")})}),e.jsx("button",{onClick:d,"aria-label":"Close skills",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(Q,{className:"h-4 w-4"})})]})]}),w&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(oe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:w}),e.jsx("button",{type:"button",onClick:()=>o(null),className:"shrink-0 underline",children:"Dismiss"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-hidden sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex h-[180px] w-full shrink-0 flex-col gap-3 overflow-hidden sm:h-auto sm:w-[220px]",children:[e.jsx("div",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Installed"}),e.jsx("input",{type:"search","aria-label":"Search installed skills",value:c,onChange:t=>h(t.target.value),placeholder:"Search skills...",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a] shrink-0"}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-y-auto flex-1 min-h-0 pr-1",children:[E&&u.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Loading skills..."]}),R&&!E&&e.jsxs("div",{role:"alert",className:"flex flex-col items-center gap-2 py-6 text-center text-xs font-mono text-red-600 dark:text-red-400",children:[e.jsx("span",{children:R.message}),e.jsx("button",{type:"button",onClick:q,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!R&&z.length===0&&!E&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:c?"No skills match your search":"No skills installed"}),z.map(t=>e.jsxs("button",{onClick:()=>{f(t.id),m(null),o(null)},className:g("flex w-full min-w-0 flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",t.id===x?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:g("text-[11px] font-mono font-semibold",t.enabled?"text-[#16A34A] dark:text-[#22C55E]":"text-[#f59e0b]"),children:t.enabled?"Enabled":"Disabled"})]}),e.jsx("span",{className:"block w-full min-w-0 truncate text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:t.description||"No description"})]},t.id))]})]}),s?e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-y-auto pr-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:s.name}),e.jsxs("span",{className:"text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["v",s.version]})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:s.description||"No description available"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void G("toggle",s,!s.enabled),disabled:r!==null,className:g("h-7 px-3 rounded-md text-[11px] font-mono font-semibold",s.enabled?"bg-[#E5E7EB] text-[#111827] hover:bg-[#D1D5DB] dark:bg-[#27272a] dark:text-[#E5E5E5] dark:hover:bg-[#32323a]":"bg-[#16A34A] text-white hover:bg-[#15803D] dark:bg-[#22C55E] dark:text-[#0C0C0C] dark:hover:bg-[#1ea34b]",r&&"opacity-60 cursor-not-allowed"),children:(r==null?void 0:r.type)==="toggle"&&r.name===s.name?"Saving...":s.enabled?"Disable":"Enable"}),e.jsxs("button",{onClick:()=>m(s.name),disabled:!s.removable||r!==null,title:s.removable?void 0:"Only Blade user skills can be uninstalled",className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold flex items-center gap-1 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(re,{className:"h-3 w-3"}),s.removable?"Uninstall":"Managed"]})]}),A===s.name&&e.jsxs("div",{role:"alertdialog","aria-label":`Uninstall ${s.name}`,className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:"Remove this skill from ~/.blade/skills?"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>m(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>void G("delete",s),disabled:r!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(r==null?void 0:r.type)==="delete"?"Uninstalling...":"Uninstall skill"})]})]}),e.jsx("div",{className:"h-px bg-[#E5E7EB] dark:bg-[#1f2937]"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-[12px] font-mono",children:[e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a]",children:"Provider"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5]",children:s.provider}),e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a]",children:"Location"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5] truncate",children:s.location})]})]}),s.capabilities.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Capabilities"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.capabilities.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))})]}),s.allowedTools.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Allowed Tools (",s.allowedTools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.allowedTools.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"Select a skill to view details"})})]})]})})]})}),e.jsx(xe,{open:S,catalog:X,installed:u.map(t=>t.name),catalogLoading:K,catalogError:(T==null?void 0:T.message)??null,onRetryCatalog:V,onOpenChange:p,onInstall:Z}),e.jsx(ce,{open:B,status:I,error:D,onCancel:()=>b(!1),onConfirm:_,onRetry:()=>k("confirm")})]})}function L({active:n,children:d,onClick:i}){return e.jsx("button",{onClick:i,className:g("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:d})}function xe({open:n,onOpenChange:d,onInstall:i,catalog:x,installed:f,catalogLoading:c,catalogError:h,onRetryCatalog:w}){const[o,r]=l.useState("catalog"),[N,A]=l.useState(""),[m,S]=l.useState(null),[p,B]=l.useState(""),[b,I]=l.useState(""),k=x.filter(a=>a.name.toLowerCase().includes(N.toLowerCase())),D=()=>{if(o==="catalog"){if(!m)return;i({source:"catalog",name:m});return}if(o==="repo"){if(!p)return;i({source:"repo",url:p});return}b&&i({source:"local",path:b})},v=m?f.includes(m):!1,C=o==="catalog"&&(!m||v||c||!!h)||o==="repo"&&!p||o==="local"&&!b;return e.jsx(U,{open:n,onOpenChange:d,children:e.jsxs(P,{onCloseAutoFocus:a=>ae("[data-skill-install-trigger]",a),className:"gap-0 overflow-y-auto rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[540px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Install Skill"}),e.jsxs("div",{className:"flex flex-col gap-4 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Install Skill"}),e.jsx("button",{onClick:()=>d(!1),"aria-label":"Close skill installation",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(Q,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit",children:[e.jsx(L,{active:o==="catalog",onClick:()=>r("catalog"),children:"Catalog"}),e.jsx(L,{active:o==="repo",onClick:()=>r("repo"),children:"Repo"}),e.jsx(L,{active:o==="local",onClick:()=>r("local"),children:"Local"})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[o==="catalog"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{"aria-label":"Search skill catalog",value:N,onChange:a=>A(a.target.value),placeholder:"Search catalog...",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"}),e.jsxs("div",{className:"flex max-h-[min(240px,30dvh)] flex-col gap-2 overflow-y-auto",children:[c&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-6 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Loading catalog..."]}),h&&!c&&e.jsxs("div",{role:"alert",className:"flex flex-col items-center gap-2 py-6 text-center text-xs font-mono text-red-600 dark:text-red-400",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",onClick:w,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!c&&!h&&k.length===0&&e.jsx("div",{className:"text-center py-6 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No skills found"}),!c&&!h&&k.map(a=>{const u=f.includes(a.name),E=m===a.name;return e.jsxs("button",{onClick:()=>S(a.name),className:g("rounded-lg px-3 py-2 flex flex-col gap-1 text-left transition-colors",E?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsx("span",{className:g("text-[10px] font-mono px-2 py-0.5 rounded",a.tag==="Official"?"bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:a.tag})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:a.description}),e.jsxs("span",{className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["by ",a.author]}),u&&e.jsx("span",{className:"text-[10px] font-mono text-[#16A34A] dark:text-[#22C55E]",children:"Installed"})]},a.name)})]})]}),o==="repo"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"GitHub URL"}),e.jsx("input",{"aria-label":"Skill repository URL",value:p,onChange:a=>B(a.target.value),placeholder:"https://github.com/org/skill",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"}),e.jsx("span",{className:"inline-flex w-fit px-2 py-0.5 rounded bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Uses Git credentials available to the Blade process"})]}),o==="local"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Local path"}),e.jsx("input",{"aria-label":"Local skill path",value:b,onChange:a=>I(a.target.value),placeholder:"/Users/bytedance/skills/my-skill",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:focus:border-[#27272a]"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:()=>d(!1),className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:D,disabled:C,className:g("h-7 px-3 rounded-md text-[11px] font-mono font-semibold",C?"bg-[#E5E7EB] text-[#9CA3AF] cursor-not-allowed dark:bg-[#27272a] dark:text-[#71717a]":"bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C]"),children:"Install"})]})]})]})})}function ce({open:n,status:d,error:i,onCancel:x,onConfirm:f,onRetry:c}){return e.jsx(U,{open:n,onOpenChange:h=>!h&&x(),children:e.jsxs(P,{className:"sm:max-w-[320px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(M,{className:"sr-only",children:"Install Status"}),e.jsxs("div",{className:"p-5 flex flex-col gap-3",children:[d==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Confirm Install"}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Install selected skill?"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:x,className:"h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:f,className:"h-6 px-2.5 rounded-md bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Install"})]})]}),d==="installing"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Installing"}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Downloading and verifying…"}),e.jsx("div",{className:"h-1.5 rounded-full bg-[#E5E7EB] dark:bg-[#18181b] overflow-hidden",children:e.jsx("div",{className:"h-full w-[45%] bg-[#16A34A] dark:bg-[#22C55E]"})}),e.jsx("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"~35%"}),e.jsx("button",{onClick:x,className:"self-end h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Hide"})]}),d==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Install Failed"}),e.jsx("p",{className:"text-[12px] font-mono text-[#f87171]",children:i||"Installation failed."}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:"Check access and try again."}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:x,className:"h-6 px-2.5 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Close"}),e.jsx("button",{onClick:c,className:"h-6 px-2.5 rounded-md bg-[#16A34A] text-white dark:bg-[#22C55E] dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Retry"})]})]})]})]})})}export{ue as SkillsModal};