@bkm016/basalt 0.1.15 → 0.1.16

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 (179) hide show
  1. package/{chunk-mfb3dgs8.js → chunk-1c9nr9rs.js} +1 -1
  2. package/{chunk-z9p6s986.js → chunk-4hf0r9hv.js} +3 -3
  3. package/{chunk-p886jr17.js → chunk-6ae9810t.js} +2 -2
  4. package/{chunk-6hx9y86d.js → chunk-6exa9fp7.js} +1 -1
  5. package/{chunk-tszctb17.js → chunk-8jn0yax5.js} +26 -26
  6. package/{chunk-xq74x4gc.js → chunk-8r4baw9e.js} +1 -1
  7. package/{chunk-5n1qra6k.js → chunk-9ymm1gge.js} +158 -149
  8. package/{chunk-qjnx4fsn.js → chunk-b350b01x.js} +3 -3
  9. package/{chunk-59hg9a84.js → chunk-bv96b8q7.js} +1 -1
  10. package/{chunk-343jsm46.js → chunk-e8x8zwkg.js} +1 -1
  11. package/{chunk-k38jaz6c.js → chunk-ehnc8g6v.js} +2 -2
  12. package/{chunk-kcn05erf.js → chunk-fzftb4n2.js} +3 -3
  13. package/{chunk-0rasqm8y.js → chunk-nrdszs0g.js} +2 -2
  14. package/{chunk-qs161f2q.js → chunk-p78wde92.js} +1 -1
  15. package/{chunk-39mh7h58.js → chunk-pna1wh02.js} +1 -1
  16. package/{chunk-edcf97ka.js → chunk-q6tgpaf3.js} +1 -1
  17. package/{chunk-qe76naq9.js → chunk-rqn67tm8.js} +1 -1
  18. package/{chunk-en7z6ne5.js → chunk-v9ttcf6r.js} +1 -1
  19. package/{chunk-9v3b7jjv.js → chunk-vv9csar7.js} +1 -1
  20. package/{chunk-81x8r8w4.js → chunk-xba6fr5v.js} +1 -1
  21. package/{chunk-03wzwnn6.js → chunk-ypxs8djn.js} +1 -1
  22. package/compiled.js +4 -4
  23. package/package.json +1 -1
  24. package/ui-test-worker.js +2 -2
  25. package/web/{chunk-ymtq18z6.js → chunk-0qnetvsc.js} +4 -4
  26. package/web/{chunk-p1bb9xp8.js → chunk-0zb330w3.js} +4 -4
  27. package/web/{chunk-zf4b8jb9.js → chunk-0zyekjym.js} +1 -1
  28. package/web/chunk-11byy7vm.js +1 -0
  29. package/web/chunk-160x5pv7.js +1 -0
  30. package/web/{chunk-jca9xbe0.js → chunk-19g09ekr.js} +5 -5
  31. package/web/chunk-1gzprnyd.js +1 -0
  32. package/web/{chunk-7wzszsf5.js → chunk-1hx4xtdk.js} +2 -2
  33. package/web/{chunk-50vgq2nk.js → chunk-1je4p601.js} +4 -4
  34. package/web/{chunk-jx3z63tq.js → chunk-1np2aamb.js} +3 -3
  35. package/web/{chunk-ed5xfgxb.js → chunk-1rjtqf8h.js} +2 -2
  36. package/web/{chunk-62gj74fq.js → chunk-23258z1r.js} +1 -1
  37. package/web/{chunk-1bhpfsvr.js → chunk-27592nd8.js} +3 -3
  38. package/web/chunk-27tchdxd.js +2 -0
  39. package/web/{chunk-pdmcr6d4.js → chunk-2hqmdqn3.js} +1 -1
  40. package/web/chunk-2q79n966.js +2 -0
  41. package/web/{chunk-djnq1w1e.js → chunk-2ws74tfa.js} +10 -10
  42. package/web/{chunk-vypfy030.js → chunk-2z8epr8f.js} +7 -7
  43. package/web/{chunk-k4qrqmdk.js → chunk-36e78034.js} +2 -2
  44. package/web/{chunk-27cntdyk.js → chunk-3gj2t10x.js} +8 -8
  45. package/web/{chunk-tvaxyhh0.js → chunk-444xfger.js} +4 -4
  46. package/web/{chunk-z5h046zm.js → chunk-4k62e61g.js} +5 -5
  47. package/web/{chunk-phj4pcx4.js → chunk-4z6wma3s.js} +2 -2
  48. package/web/{chunk-251yw6f2.js → chunk-5sss3r97.js} +1 -1
  49. package/web/chunk-5wkqqa59.js +1 -0
  50. package/web/{chunk-qdsg8wp0.js → chunk-5yczs6sb.js} +1 -1
  51. package/web/chunk-5yn7mwvt.js +1 -0
  52. package/web/{chunk-pa82db2e.js → chunk-6ty9vw27.js} +3 -3
  53. package/web/chunk-705tkt2r.js +1 -0
  54. package/web/{chunk-t72z2ww3.js → chunk-753qp8sa.js} +2 -2
  55. package/web/{chunk-7frnjms9.js → chunk-75kzvpf3.js} +8 -8
  56. package/web/{chunk-hdtvrh0f.js → chunk-75meb0dh.js} +2 -2
  57. package/web/{chunk-66164wmv.js → chunk-76e3npmd.js} +1 -1
  58. package/web/chunk-7p04dn0k.js +1 -0
  59. package/web/chunk-7rb3v8gy.js +1 -0
  60. package/web/{chunk-65ay0j1t.js → chunk-7yz88k97.js} +3 -3
  61. package/web/{chunk-yeh77fvq.js → chunk-85d7jkp0.js} +1 -1
  62. package/web/chunk-90kgn35s.js +1 -0
  63. package/web/chunk-931y1g0h.js +1 -0
  64. package/web/{chunk-jy448465.js → chunk-bcp6na49.js} +104 -101
  65. package/web/chunk-bz1q7qdd.js +8 -0
  66. package/web/chunk-c0evk1xy.js +1 -0
  67. package/web/{chunk-8qzsxg1q.js → chunk-c0hdp2zj.js} +1 -1
  68. package/web/{chunk-25sn840r.js → chunk-c1z290wm.js} +2 -2
  69. package/web/{chunk-01nbc18z.js → chunk-cge0cjfm.js} +1 -1
  70. package/web/{chunk-3zs2v6b4.js → chunk-chh8bg2h.js} +11 -11
  71. package/web/{chunk-7zfqppsx.js → chunk-ctmxm4qd.js} +2 -2
  72. package/web/{chunk-hbwxtbq3.js → chunk-e229cr90.js} +1 -1
  73. package/web/{chunk-pma5pats.js → chunk-e9mmkrc3.js} +5 -5
  74. package/web/{chunk-yzmrbssn.js → chunk-ef03t1mb.js} +5 -5
  75. package/web/{chunk-ehz9m6g4.js → chunk-f8nnrk6y.js} +4 -4
  76. package/web/{chunk-mss6eg27.js → chunk-fcrswzgm.js} +3 -3
  77. package/web/{chunk-1v6hhgc6.js → chunk-ffn1a0zw.js} +1 -1
  78. package/web/chunk-fw4fa7j6.js +1 -0
  79. package/web/chunk-fx8hheqz.js +1 -0
  80. package/web/{chunk-937ndmh1.js → chunk-g8wy9sa6.js} +11 -11
  81. package/web/{chunk-pafw34vg.js → chunk-gaf9brzv.js} +2 -2
  82. package/web/{chunk-bcx7xges.js → chunk-gj16e7z0.js} +1 -1
  83. package/web/{chunk-6x1hfjb9.js → chunk-gjchc4kg.js} +1 -1
  84. package/web/chunk-h1y8y203.js +1 -0
  85. package/web/{chunk-6s1vjny7.js → chunk-h6vy008x.js} +1 -1
  86. package/web/{chunk-t5ke9cyg.js → chunk-h8mhnze5.js} +55 -55
  87. package/web/{chunk-s6bc73n3.js → chunk-hhnhgthx.js} +2 -2
  88. package/web/{chunk-4m9mgdaa.js → chunk-j27mtdr2.js} +1 -1
  89. package/web/chunk-jys02310.js +1 -0
  90. package/web/chunk-kew13yzg.js +1 -0
  91. package/web/{chunk-43194184.js → chunk-kx5r8nf2.js} +1 -1
  92. package/web/{chunk-3hy2gsgf.js → chunk-m7c0xk69.js} +1 -1
  93. package/web/{chunk-n0ezfa12.js → chunk-madrcnm1.js} +2 -2
  94. package/web/{chunk-vwv6pqy7.js → chunk-mcm3t5wr.js} +1 -1
  95. package/web/{chunk-q6j2e8a1.js → chunk-mrnx4f74.js} +2 -2
  96. package/web/chunk-mtdsrtc5.js +1 -0
  97. package/web/{chunk-te15yhn5.js → chunk-mv5axm2y.js} +4 -4
  98. package/web/{chunk-t78qm9gs.js → chunk-n3f5a91k.js} +1 -1
  99. package/web/{chunk-ksnsfqrn.js → chunk-n3spc397.js} +1 -1
  100. package/web/{chunk-dde64qjd.js → chunk-nhc280n0.js} +1 -1
  101. package/web/chunk-nx1bcekh.js +2 -0
  102. package/web/{chunk-wfgrdabk.js → chunk-p0jghn6b.js} +1 -1
  103. package/web/chunk-p8t7s4z4.js +1 -0
  104. package/web/chunk-pgh1cx6w.js +1 -0
  105. package/web/{chunk-mv9q8jrm.js → chunk-ps489yjy.js} +1 -1
  106. package/web/{chunk-2tm4xe0j.js → chunk-qbhv18t0.js} +2 -2
  107. package/web/{chunk-cq1f20k6.js → chunk-qgzn0ha5.js} +1 -1
  108. package/web/{chunk-aw6wg8fe.js → chunk-qtwxq6hj.js} +3 -3
  109. package/web/chunk-qwp3dhmf.js +1 -0
  110. package/web/{chunk-t2v01k4z.js → chunk-qwwqdmhv.js} +1 -1
  111. package/web/{chunk-43bczb21.js → chunk-rjh54ygb.js} +5 -5
  112. package/web/chunk-ryh8jdzy.js +1 -0
  113. package/web/chunk-s3t8dkkz.js +1 -0
  114. package/web/chunk-sk1w7f7h.js +1 -0
  115. package/web/chunk-smkrxjm5.js +1 -0
  116. package/web/{chunk-ppfhtyxt.js → chunk-sv5ph7fa.js} +1 -1
  117. package/web/{chunk-4q2jtvwn.js → chunk-t89tfrpj.js} +8 -8
  118. package/web/{chunk-qv1w36ja.js → chunk-t9pg7qf8.js} +2 -2
  119. package/web/{chunk-qdn3hmfy.js → chunk-t9twxmsg.js} +1 -1
  120. package/web/{chunk-pmghe7rh.js → chunk-tfdchqn4.js} +1 -1
  121. package/web/{chunk-dgepxev9.js → chunk-tfsrk2rc.js} +24 -24
  122. package/web/{chunk-5rwg3qqd.js → chunk-tvvggvjt.js} +8 -8
  123. package/web/chunk-ty87gdvr.js +1 -0
  124. package/web/{chunk-b323qea5.js → chunk-v16s0x7c.js} +1 -1
  125. package/web/{chunk-6xfbh4z5.js → chunk-vb2z2azk.js} +10 -10
  126. package/web/{chunk-ea6b8b50.js → chunk-vcnsvj49.js} +9 -9
  127. package/web/{chunk-8nm0mghm.js → chunk-vgyp8wa2.js} +2 -2
  128. package/web/chunk-vh8pkcem.css +1 -0
  129. package/web/{chunk-17wwzrp4.js → chunk-vjnvfb8z.js} +1 -1
  130. package/web/{chunk-qf2kb7zj.js → chunk-vphzndz8.js} +1 -1
  131. package/web/{chunk-fttdbcqv.js → chunk-w60dxtyz.js} +1 -1
  132. package/web/{chunk-1zwc09e8.js → chunk-wcj3bxdf.js} +2 -2
  133. package/web/{chunk-kxr473dw.js → chunk-wgmwgaw4.js} +5 -5
  134. package/web/{chunk-k3ah0513.js → chunk-wvt76598.js} +1 -1
  135. package/web/chunk-y0mef85j.js +1 -0
  136. package/web/{chunk-5fzmk43v.js → chunk-y2ykn1gm.js} +1 -1
  137. package/web/{chunk-jdx7qp2w.js → chunk-ybqt106a.js} +2 -2
  138. package/web/{chunk-m5psa69k.js → chunk-ym9qfsjs.js} +4 -4
  139. package/web/{chunk-w9nkvcjr.js → chunk-ypdptddq.js} +1 -1
  140. package/web/{chunk-3f8fjee5.js → chunk-z08c63ph.js} +2 -2
  141. package/web/{chunk-bzdn9sxz.js → chunk-z2hvvkf5.js} +2 -2
  142. package/web/chunk-z6x74qfh.js +1 -0
  143. package/web/{chunk-57b8j192.js → chunk-z86pjpqp.js} +1 -1
  144. package/web/{chunk-4tbhxtnm.js → chunk-zh0vjc6g.js} +1 -1
  145. package/web/chunk-zns9wmab.js +1 -0
  146. package/web/index.html +1 -1
  147. package/web/chunk-00swes3c.js +0 -1
  148. package/web/chunk-0e995hjg.js +0 -1
  149. package/web/chunk-3egthz5k.js +0 -2
  150. package/web/chunk-3fjzgpaw.js +0 -1
  151. package/web/chunk-3mgzqbc8.js +0 -1
  152. package/web/chunk-3yvanftw.js +0 -1
  153. package/web/chunk-64h7k870.js +0 -1
  154. package/web/chunk-6ehecat3.js +0 -1
  155. package/web/chunk-73941p08.js +0 -1
  156. package/web/chunk-7jh6zxg3.js +0 -1
  157. package/web/chunk-7mgwejn4.js +0 -1
  158. package/web/chunk-8zg89764.js +0 -1
  159. package/web/chunk-95gbcs8j.js +0 -1
  160. package/web/chunk-evp6t44y.js +0 -8
  161. package/web/chunk-eyg28s83.js +0 -1
  162. package/web/chunk-g7bcntpm.js +0 -1
  163. package/web/chunk-g9bqacq1.js +0 -1
  164. package/web/chunk-gh8kjzdj.js +0 -1
  165. package/web/chunk-j031r08w.js +0 -1
  166. package/web/chunk-jab2p5zv.js +0 -2
  167. package/web/chunk-jpf8x9tm.js +0 -1
  168. package/web/chunk-jy8zat04.js +0 -1
  169. package/web/chunk-k8s7kye3.js +0 -1
  170. package/web/chunk-k9zn1n6d.js +0 -1
  171. package/web/chunk-md9j949p.js +0 -1
  172. package/web/chunk-npyrdsf8.css +0 -1
  173. package/web/chunk-pze2v3v1.js +0 -2
  174. package/web/chunk-q6jf3zc1.js +0 -1
  175. package/web/chunk-sdtesqbb.js +0 -1
  176. package/web/chunk-t0z8ygx4.js +0 -1
  177. package/web/chunk-w7cyrbk2.js +0 -1
  178. package/web/chunk-x2f8bwd2.js +0 -1
  179. package/web/chunk-xq8x7dvr.js +0 -1
@@ -1 +1 @@
1
- import{h,o,i,r,m,e,n,y,s,te,lt,Te,oe,ne,je,Ke,Q,Z}from"./chunk-jy448465.js";import{Fr,zr,Ur}from"./chunk-2tm4xe0j.js";var ke=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],ye=s("rotate-cw",ke);function Ce(t){let p=[],g="",S,v=!1;for(let f=0;f<t.length;f++){let c=t.charAt(f);if(S)if(c===S)S=void 0;else if(c==="\\"&&S==='"'&&f+1<t.length)g+=t[++f];else g+=c;else if(c==='"'||c==="'")S=c,v=!0;else if(c==="\\"&&f+1<t.length)g+=t[++f],v=!0;else if(/\s/.test(c)){if(v||g)p.push(g);g="",v=!1}else g+=c,v=!0}if(v||g)p.push(g);return p}function fe(t){return t.map((p)=>p===""||/[\s"'\\]/.test(p)?`"${p.replace(/(["\\])/g,"\\$1")}"`:p).join(" ")}var $e={connected:{label:"已连接",dot:"bg-success"},idle:{label:"待连接",dot:"bg-faint"},disabled:{label:"已停用",dot:"bg-faint"},failed:{label:"连接失败",dot:"bg-danger"},needs_auth:{label:"需要认证",dot:"bg-warning"}};function ge(t){if(t==="project")return"项目";if(t==="file")return".mcp.json";return"全局"}function pe(t){return t.type==="local"?fe(t.command):t.url}function he({info:t,tools:p=!1}){let g=$e[t.status.status];return n("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-xs text-dim",children:[e("span",{"aria-hidden":!0,className:`size-1.5 shrink-0 rounded-full ${g.dot}`}),e("span",{className:p?void 0:"hidden @md/panel:inline",children:g.label}),p&&t.status.status==="connected"&&n("span",{className:"text-faint",children:[t.toolCount," 个工具"]})]})}function xe(t){let{Button:p,CopyButton:g,DetailChip:S,DetailList:v,DetailRow:f,DetailTitle:c,Dialog:D,Switch:M,Tooltip:V,cn:d,confirm:Y,useTheme:I}=y();I();let{info:u,connection:E}=t,k=t.projectID?`?projectID=${encodeURIComponent(t.projectID)}`:"",[B,ee]=r(),[le,F]=r(),[T,P]=r(!1),J=u.status.status==="connected",j=u.status.status==="needs_auth",U=u.status.status==="failed",L=u.config.type==="remote"&&Boolean(u.config.oauth),R=u.scope==="file";o(()=>{function l(N){if(N&&N!==u.name)return;E.request(`/api/mcp/${encodeURIComponent(u.name)}/connect${k}`,{method:"POST"}).then((re)=>t.onChanged(re)).catch(()=>{})}function ie(N){if(N.data?.type==="mcp-oauth-success")l(N.data.name)}function de(N){if(N.key==="basalt-mcp-oauth-event"&&N.newValue)try{let re=JSON.parse(N.newValue);l(re.name)}catch(re){}}window.addEventListener("message",ie),window.addEventListener("storage",de);let q;if("BroadcastChannel"in window)q=new BroadcastChannel("basalt-mcp-oauth"),q.onmessage=(N)=>{if(N.data?.type==="mcp-oauth-success")l(N.data.name)};return()=>{window.removeEventListener("message",ie),window.removeEventListener("storage",de),q?.close()}},[E,u.name,k,t]),o(()=>{if(u.status.status!=="connected")return;E.request(`/api/mcp/${encodeURIComponent(u.name)}/tools${k}`).then((l)=>{if(Array.isArray(l))ee(l),F(void 0)}).catch((l)=>{F(l instanceof Error?l.message:"获取工具失败")})},[E,u.name,k,u.status.status]);async function ae(l){P(!0);try{let ie=await E.request(`/api/mcp/${encodeURIComponent(u.name)}/${l}${k}`,{method:"POST"});t.onChanged(ie)}catch{}finally{P(!1)}}async function se(){P(!0);try{let l=u.status.status==="needs_auth"?u.status.authorizationUrl:void 0;if(!l)l=(await E.request(`/api/mcp/${encodeURIComponent(u.name)}/oauth/authorize${k}`,{method:"POST"})).authorizationUrl;if(l)window.open(l,"_blank","width=600,height=700")}catch(l){F(l instanceof Error?l.message:"获取授权链接失败")}finally{P(!1)}}async function _(){P(!0);try{let l=await E.request(`/api/mcp/${encodeURIComponent(u.name)}/oauth/clear${k}`,{method:"POST"});t.onChanged(l)}finally{P(!1)}}async function a(){if(!await Y({title:`删除 ${u.name}?`,description:"删除后将断开连接并不再向会话提供其工具。",action:"删除",danger:!0}))return;P(!0);try{await E.request(`/api/mcp/${encodeURIComponent(u.name)}${k}`,{method:"DELETE"}),t.onChanged(),t.onClose()}finally{P(!1)}}let C=u.config,x=pe(C),W="error"in u.status?u.status.error:void 0,z=C.enabled===!1,ce=!z&&!j;return e(D,{open:!0,onOpenChange:(l)=>{if(!l&&!T)t.onClose()},title:e(c,{icon:C.type==="local"?e(Ke,{}):e(Te,{}),name:u.name,meta:[C.type==="local"?"本地命令":"远程服务",ge(u.scope),L&&"OAuth 2.0"]}),size:"lg",footer:n("div",{className:"flex w-full items-center justify-between gap-2 max-sm:[&>*]:flex-none",children:[n("div",{className:"inline-flex items-center gap-2.5 text-[13px] text-dim",children:[!R&&e(M,{label:`启用 ${u.name}`,checked:!z,disabled:T||t.toggling,onCheckedChange:t.onToggle}),e(he,{info:u,tools:!0})]}),n("div",{className:"flex items-center gap-1.5",children:[L&&e(p,{type:"button",variant:"ghost",size:"sm",onClick:_,disabled:T,children:"清除凭据"}),!R&&e(V,{label:"删除服务器",children:e(p,{type:"button",variant:"danger-ghost",size:"icon","aria-label":"删除服务器",onClick:a,disabled:T,children:e(Q,{className:"size-4"})})}),ce&&e(V,{label:"终止服务进程并重新启动,让更新后的代码生效",children:e(p,{type:"button",variant:"ghost",size:"icon","aria-label":"重启",onClick:()=>ae("restart"),disabled:T,children:e(ye,{className:d("size-4",T&&"animate-spin")})})}),ce&&e(p,{type:"button",size:"sm",onClick:()=>ae(J?"disconnect":"connect"),disabled:T,children:J?"断开连接":"连接"}),!R&&n(p,{type:"button",size:"sm",onClick:t.onEdit,disabled:T,children:[e(je,{className:"size-3.5"}),e("span",{children:"编辑配置"})]})]})]}),children:n(v,{children:[n(f,{label:C.type==="local"?"命令":"地址",children:[e("span",{className:"min-w-0 font-mono text-[12px] text-dim leading-5.5 [overflow-wrap:anywhere]",children:x}),e(g,{text:x,label:"复制",size:"icon-xs",className:"shrink-0 text-faint hover:text-ink"})]}),j&&n(f,{label:"授权",children:[e("span",{className:"text-dim leading-7",children:"需要完成 OAuth 授权后才能使用,令牌会自动保存。"}),e(p,{type:"button",variant:"primary",size:"sm",onClick:se,disabled:T,children:"前往授权"})]}),U&&e(f,{label:"错误",children:e("p",{className:"min-w-0 font-mono text-[11.5px] text-danger leading-5 [overflow-wrap:anywhere]",children:W})}),e(f,{label:"工具",children:le?e("span",{className:"text-danger",children:le}):!J?e("span",{className:"text-faint",children:"连接后列出工具"}):!B?e("span",{role:"status",className:"text-faint",children:"正在获取"}):B.length===0?e("span",{className:"text-faint",children:"服务器没有声明任何工具"}):B.map((l)=>e(S,{mono:!0,title:l.description,children:l.name},l.name))})]})})}var Pe=/^[A-Za-z0-9_-]{1,64}$/;function K(t){return e("span",{className:"truncate text-xs text-faint",children:t.children})}function Ne(t){let{pairs:p,onChange:g,InputComponent:S}=t,v=(f,c)=>g(p.map((D,M)=>M===f?{...D,...c}:D));return n("div",{className:"space-y-2",children:[n("div",{className:"flex min-h-7 items-center gap-2",children:[e("span",{className:"shrink-0 text-[13px] font-medium text-dim",children:t.label}),e(K,{children:t.tip}),n("button",{type:"button",className:"ml-auto inline-flex h-7 shrink-0 cursor-pointer items-center gap-1 rounded-lg px-2 text-xs font-medium text-dim transition-colors hover:bg-raised hover:text-ink",onClick:()=>g([...p,{key:"",value:"",saved:!1}]),children:[e(oe,{className:"size-3.5"}),"添加"]})]}),p.map((f,c)=>n("div",{className:"flex min-w-0 items-center gap-1.5",children:[e(S,{"aria-label":`${t.keyLabel} ${c+1}`,placeholder:t.keyLabel,value:f.key,readOnly:f.saved,onChange:(D)=>v(c,{key:D.target.value}),className:"min-w-0 flex-[2] font-mono text-xs"}),e(S,{"aria-label":`${t.keyLabel} ${f.key||c+1} 的值`,type:"password",autoComplete:"off",placeholder:f.saved?"已保存,留空保持不变":"值",value:f.value,onChange:(D)=>v(c,{value:D.target.value}),className:"min-w-0 flex-[3] font-mono text-xs"}),e("button",{type:"button","aria-label":`删除 ${f.key||"该项"}`,className:"flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg text-faint transition-colors hover:bg-danger/10 hover:text-danger",onClick:()=>g(p.filter((D,M)=>M!==c)),children:e(Z,{className:"size-4"})})]},c))]})}function we(t){return Object.keys(t??{}).map((p)=>({key:p,value:"",saved:!0}))}function Ie(t){let{Button:p,Segmented:g,Dialog:S,Form:v,Field:f,Input:c,Switch:D,style:M,useTheme:V}=y();V();let{existing:d}=t,[Y,I]=r(d?.config.type??"local"),[u,E]=r(d?.name??""),[k,B]=r(d?.config.type==="local"?fe(d.config.command):""),[ee,le]=r(d?.config.type==="remote"?d.config.url:""),[F,T]=r(we(d?.config.type==="local"?d.config.environment:void 0)),[P,J]=r(we(d?.config.type==="remote"?d.config.headers:void 0)),j=d?.config.type==="remote"?d.config.oauth:void 0,[U,L]=r(Boolean(j)),[R,ae]=r(typeof j==="object"&&j.clientId?j.clientId:""),[se,_]=r(""),[a,C]=r(typeof j==="object"&&j.scope?j.scope:""),[x,W]=r(d?.config.defer??"default"),[z,ce]=r(d?.config.timeout!==void 0?String(d.config.timeout):""),[l,ie]=r(d?.config.defer!==void 0||d?.config.timeout!==void 0),[de,q]=r(),[N,re]=r(!1);async function Se(b){b.preventDefault(),q(void 0);let w=u.trim();if(!d&&!Pe.test(w)){q("名称只能包含英文字母、数字、下划线与中划线,长度 1-64");return}if(!d&&t.taken.includes(w)){q("同名服务器已存在");return}let ue=z.trim()?Number.parseInt(z.trim(),10):void 0;if(ue!==void 0&&(!Number.isFinite(ue)||ue<=0)){q("超时时间须为大于 0 的毫秒数");return}let be;if(Y==="local"){let H=Ce(k.trim());if(!H.length){q("请输入启动命令");return}let G={};for(let A of F){let O=A.key.trim();if(!O)continue;if(!A.saved||A.value)G[O]=A.value}be={type:"local",command:H,environment:Object.keys(G).length?G:void 0,enabled:d?d.config.enabled:!0,defer:x==="default"?void 0:x,timeout:ue}}else{let H=ee.trim();try{let O=new URL(H);if(O.protocol!=="http:"&&O.protocol!=="https:")throw Error("bad protocol")}catch{q("请输入合法的 HTTP 或 HTTPS 地址");return}let G={};for(let O of P){let me=O.key.trim();if(!me)continue;if(!O.saved||O.value)G[me]=O.value}let A;if(U){let O=R.trim(),me=se.trim(),ve=a.trim();if(O||me||ve)A={clientId:O||void 0,clientSecret:me||void 0,scope:ve||void 0};else A=!0}else A=!1;be={type:"remote",url:H,headers:Object.keys(G).length?G:void 0,oauth:A,enabled:d?d.config.enabled:!0,defer:x==="default"?void 0:x,timeout:ue}}re(!0);try{let H=d?.name??w,G=d?d.projectID:t.projectID,A=G?`?projectID=${encodeURIComponent(G)}`:"";await t.connection.request(`/api/mcp/${encodeURIComponent(H)}${A}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(be)}),t.onSaved()}catch(H){q(H instanceof Error?H.message:"保存失败")}finally{re(!1)}}return e(S,{open:!0,onOpenChange:(b)=>{if(!b&&!N)t.onClose()},title:d?`编辑 ${d.name}`:"添加 MCP 服务器",size:"lg",footer:n("div",{className:"flex w-full justify-end gap-2.5",children:[e(p,{type:"button",variant:"ghost",onClick:t.onClose,disabled:N,className:"min-w-20",children:"取消"}),e(p,{type:"submit",form:"mcp-server-form",variant:"primary",disabled:N,className:"min-w-24",children:N?"保存中...":"保存"})]}),children:n(v,{id:"mcp-server-form",onSubmit:Se,children:[e(g,{value:Y,onChange:(b)=>I(b),className:"w-full [&>button]:flex-1",options:[{value:"local",label:"本地(标准输入输出)"},{value:"remote",label:"远程(HTTP / SSE)"}]}),!d&&e(f,{label:"名称",aside:e(K,{children:"唯一标识,如 postgres"}),children:(b)=>e(c,{id:b,value:u,onChange:(w)=>E(w.target.value),placeholder:"postgres",className:"font-mono text-xs"})}),Y==="local"?n(m,{children:[e(f,{label:"启动命令",aside:e(K,{children:"完整命令及参数"}),children:(b)=>e(c,{id:b,value:k,onChange:(w)=>B(w.target.value),placeholder:"npx -y @modelcontextprotocol/server-postgres ...",className:"font-mono text-xs"})}),e(Ne,{label:"环境变量",tip:"启动进程时注入",keyLabel:"变量名",pairs:F,onChange:T,InputComponent:c})]}):n(m,{children:[e(f,{label:"服务地址",aside:e(K,{children:"HTTP / HTTPS 端点"}),children:(b)=>e(c,{id:b,value:ee,onChange:(w)=>le(w.target.value),placeholder:"https://example.com/mcp",className:"font-mono text-xs"})}),e(Ne,{label:"请求头",tip:"随每次请求发送",keyLabel:"头字段",pairs:P,onChange:J,InputComponent:c}),n("div",{className:"flex items-center justify-between gap-4",children:[n("div",{className:"min-w-0",children:[e("span",{className:"block text-[13px] font-medium text-dim",children:"OAuth 2.0 认证"}),e("span",{className:"block truncate text-xs text-faint",children:"自动发现授权端点,使用 PKCE 并刷新令牌"})]}),e(D,{checked:U,onCheckedChange:L,label:"启用 OAuth 2.0"})]}),U&&n(m,{children:[e(f,{label:"Client ID",aside:e(K,{children:"留空自动动态注册(DCR)"}),children:(b)=>e(c,{id:b,value:R,onChange:(w)=>ae(w.target.value),placeholder:"留空自动动态注册",className:"font-mono text-xs"})}),e(f,{label:"Client Secret",aside:e(K,{children:"留空保持不变"}),children:(b)=>e(c,{id:b,type:"password",autoComplete:"off",value:se,onChange:(w)=>_(w.target.value),placeholder:"••••••••",className:"font-mono text-xs"})}),e(f,{label:"Scope",aside:e(K,{children:"选填授权范围"}),children:(b)=>e(c,{id:b,value:a,onChange:(w)=>C(w.target.value),placeholder:"repo read:org",className:"font-mono text-xs"})})]})]}),n("div",{className:"space-y-3 border-t border-line/60 pt-3",children:[n("button",{type:"button","aria-expanded":l,className:"flex w-full cursor-pointer items-center gap-1.5 text-[13px] font-medium text-dim transition-colors hover:text-ink",onClick:()=>ie(!l),children:[e(lt,{className:`size-3.5 transition-transform ${l?"rotate-90":""}`}),"高级设置",e("span",{className:"truncate text-xs font-normal text-faint",children:"加载时机、超时"})]}),l&&n("div",{className:"grid grid-cols-2 gap-3 max-sm:grid-cols-1",children:[e(f,{label:"加载时机",aside:e(K,{children:"延迟 = 按需加载"}),children:()=>e(g,{value:x,onChange:(b)=>W(b),className:"w-full [&>button]:flex-1",options:[{value:"default",label:"默认"},{value:"defer",label:"延迟"},{value:"always",label:"常驻"}]})}),e(f,{label:"超时(毫秒)",aside:e(K,{children:"留空用默认"}),children:(b)=>e(c,{id:b,value:z,onChange:(w)=>ce(w.target.value),placeholder:"默认",className:"font-mono text-xs"})})]})]}),de&&n("div",{role:"alert",className:M("callout.base",M("callout.danger"),"px-3 py-2.5 text-xs"),children:[e(te,{className:"mt-0.5 size-3.5 shrink-0"}),e("span",{className:"min-w-0 break-words",children:de})]})]})})}var X="global";function at({connection:t}){let{Button:p,Select:g,CatalogRow:S,style:v,useTheme:f}=y();f();let[c,D]=r(""),[M,V]=r(),[d,Y]=r([]),[I,u]=r(X),[E,k]=r(),[B,ee]=r(!1),[le,F]=r(),[T,P]=r(!1),J=i(!1),[j,U]=r(),L=i(0),R=h(async()=>{let a=++L.current;ee(!0);try{let C=I===X?"":`?projectID=${encodeURIComponent(I)}`,[x,W]=await Promise.all([t.request(`/api/mcp${C}`),t.request("/api/mcp/projects")]);if(a!==L.current)return;if(V(x),Y(W),I!==X&&!W.some((z)=>z.id===I))u(X);k(void 0)}catch(C){if(a===L.current)k(C instanceof Error?C.message:"读取失败")}finally{if(a===L.current)ee(!1)}},[t,I]);o(()=>(R(),()=>{L.current++}),[R]);async function ae(a,C){if(J.current)return;J.current=!0,P(!0);let x=L.current;try{let W=a.projectID?`?projectID=${encodeURIComponent(a.projectID)}`:"",z=await t.request(`/api/mcp/${encodeURIComponent(a.name)}${W}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({...a.config,enabled:C})});if(x===L.current)V((ce)=>ce?.map((l)=>l.name===z.name&&l.projectID===z.projectID?z:l))}finally{J.current=!1,P(!1)}}let se=M?.filter((a)=>`${a.name} ${pe(a.config)}`.toLowerCase().includes(c.trim().toLowerCase())),_=M?.find((a)=>a.name===le);return n("div",{className:"min-w-0 space-y-6",children:[n("section",{className:"min-w-0",children:[n("div",{className:"mb-2.5 flex flex-wrap items-end justify-between gap-3 px-0.5",children:[n("div",{className:"min-w-0 flex-1 basis-48",children:[e("h2",{className:v("settings.groupTitle"),children:"MCP 服务器"}),e("p",{className:v("settings.groupDesc"),children:"外部工具与数据源管理"})]}),n("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e(g,{value:I,disabled:B,onValueChange:(a)=>{F(void 0),U(void 0),V(void 0),u(a)},groups:[{options:[{value:X,label:"全局"}]},...Fr(d)],className:"w-44"}),e(p,{variant:"ghost",disabled:B,onClick:R,className:"h-9 px-2.5 text-xs",children:e(ne,{className:`size-3.5 ${B?"animate-spin":""}`})}),n(p,{variant:"secondary",onClick:()=>U({}),className:"h-9 px-2.5 text-xs",children:[e(oe,{className:"size-3.5 mr-1"}),"添加服务器"]})]})]}),E&&n("div",{role:"alert",className:v("callout.base",v("callout.danger"),"mb-3 flex-wrap items-center justify-between"),children:[n("p",{className:"min-w-0 flex-1 break-words text-sm text-danger",children:["无法读取 MCP 服务器:",E]}),e(p,{disabled:B,onClick:R,children:"重试"})]}),e(zr,{label:"搜索 MCP 服务器",placeholder:"搜索服务器",value:c,onChange:D}),e("div",{className:v("settings.groupBox"),children:!M?e(Ur,{}):se?.length===0?e("p",{className:"p-4 text-sm text-dim",children:"没有匹配的 MCP 服务器"}):e("ul",{className:"divide-y divide-line",children:se?.map((a)=>{let C=a.config.enabled===!1,x=a.scope==="file";return e("li",{children:e(S,{name:a.name,selectLabel:`查看 ${a.name}`,onSelect:()=>F(a.name),title:x?"来自项目的 .mcp.json,配置只读,可查看工具与重启":void 0,description:e("span",{className:"font-mono text-[11px]",children:pe(a.config)}),icon:a.config.type==="local"?e(Ke,{}):e(Te,{}),inactive:C,aside:n(m,{children:[e("span",{className:v("control.badge"),children:ge(a.scope)}),e(he,{info:a})]}),toggle:x?void 0:{checked:!C,label:`启用服务器 ${a.name}`,disabled:T||B,onCheckedChange:(W)=>ae(a,W)}})},a.name)})})})]}),_&&!j&&e(xe,{connection:t,info:_,toggling:T,onToggle:(a)=>ae(_,a),projectID:I===X?void 0:I,onClose:()=>F(void 0),onEdit:()=>U({info:_}),onChanged:(a)=>a?V((C)=>C?.map((x)=>x.name===a.name?a:x)):R()},`${_.projectID}:${_.name}`),j&&e(Ie,{connection:t,projectID:I===X?void 0:I,existing:j.info,taken:(M??[]).filter((a)=>a.scope===(I===X?"global":"project")).map((a)=>a.name),onClose:()=>U(void 0),onSaved:()=>{U(void 0),R()}})]})}export{at as McpSection};
1
+ import{h,o,i,r,m,e,n,y,s,te,lt,Te,oe,re,je,Qe,Q,X}from"./chunk-bcp6na49.js";import{zr,Ur,jr}from"./chunk-qbhv18t0.js";var ke=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],ye=s("rotate-cw",ke);function Ce(t){let p=[],g="",S,v=!1;for(let f=0;f<t.length;f++){let c=t.charAt(f);if(S)if(c===S)S=void 0;else if(c==="\\"&&S==='"'&&f+1<t.length)g+=t[++f];else g+=c;else if(c==='"'||c==="'")S=c,v=!0;else if(c==="\\"&&f+1<t.length)g+=t[++f],v=!0;else if(/\s/.test(c)){if(v||g)p.push(g);g="",v=!1}else g+=c,v=!0}if(v||g)p.push(g);return p}function fe(t){return t.map((p)=>p===""||/[\s"'\\]/.test(p)?`"${p.replace(/(["\\])/g,"\\$1")}"`:p).join(" ")}var $e={connected:{label:"已连接",dot:"bg-success"},idle:{label:"待连接",dot:"bg-faint"},disabled:{label:"已停用",dot:"bg-faint"},failed:{label:"连接失败",dot:"bg-danger"},needs_auth:{label:"需要认证",dot:"bg-warning"}};function ge(t){if(t==="project")return"项目";if(t==="file")return".mcp.json";return"全局"}function pe(t){return t.type==="local"?fe(t.command):t.url}function he({info:t,tools:p=!1}){let g=$e[t.status.status];return n("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-xs text-dim",children:[e("span",{"aria-hidden":!0,className:`size-1.5 shrink-0 rounded-full ${g.dot}`}),e("span",{className:p?void 0:"hidden @md/panel:inline",children:g.label}),p&&t.status.status==="connected"&&n("span",{className:"text-faint",children:[t.toolCount," 个工具"]})]})}function xe(t){let{Button:p,CopyButton:g,DetailChip:S,DetailList:v,DetailRow:f,DetailTitle:c,Dialog:D,Switch:M,Tooltip:V,cn:d,confirm:Y,useTheme:I}=y();I();let{info:u,connection:E}=t,k=t.projectID?`?projectID=${encodeURIComponent(t.projectID)}`:"",[B,ee]=r(),[le,F]=r(),[T,P]=r(!1),J=u.status.status==="connected",j=u.status.status==="needs_auth",U=u.status.status==="failed",L=u.config.type==="remote"&&Boolean(u.config.oauth),R=u.scope==="file";o(()=>{function l(N){if(N&&N!==u.name)return;E.request(`/api/mcp/${encodeURIComponent(u.name)}/connect${k}`,{method:"POST"}).then((ie)=>t.onChanged(ie)).catch(()=>{})}function se(N){if(N.data?.type==="mcp-oauth-success")l(N.data.name)}function de(N){if(N.key==="basalt-mcp-oauth-event"&&N.newValue)try{let ie=JSON.parse(N.newValue);l(ie.name)}catch(ie){}}window.addEventListener("message",se),window.addEventListener("storage",de);let q;if("BroadcastChannel"in window)q=new BroadcastChannel("basalt-mcp-oauth"),q.onmessage=(N)=>{if(N.data?.type==="mcp-oauth-success")l(N.data.name)};return()=>{window.removeEventListener("message",se),window.removeEventListener("storage",de),q?.close()}},[E,u.name,k,t]),o(()=>{if(u.status.status!=="connected")return;E.request(`/api/mcp/${encodeURIComponent(u.name)}/tools${k}`).then((l)=>{if(Array.isArray(l))ee(l),F(void 0)}).catch((l)=>{F(l instanceof Error?l.message:"获取工具失败")})},[E,u.name,k,u.status.status]);async function ne(l){P(!0);try{let se=await E.request(`/api/mcp/${encodeURIComponent(u.name)}/${l}${k}`,{method:"POST"});t.onChanged(se)}catch{}finally{P(!1)}}async function ae(){P(!0);try{let l=u.status.status==="needs_auth"?u.status.authorizationUrl:void 0;if(!l)l=(await E.request(`/api/mcp/${encodeURIComponent(u.name)}/oauth/authorize${k}`,{method:"POST"})).authorizationUrl;if(l)window.open(l,"_blank","width=600,height=700")}catch(l){F(l instanceof Error?l.message:"获取授权链接失败")}finally{P(!1)}}async function _(){P(!0);try{let l=await E.request(`/api/mcp/${encodeURIComponent(u.name)}/oauth/clear${k}`,{method:"POST"});t.onChanged(l)}finally{P(!1)}}async function a(){if(!await Y({title:`删除 ${u.name}?`,description:"删除后将断开连接并不再向会话提供其工具。",action:"删除",danger:!0}))return;P(!0);try{await E.request(`/api/mcp/${encodeURIComponent(u.name)}${k}`,{method:"DELETE"}),t.onChanged(),t.onClose()}finally{P(!1)}}let C=u.config,x=pe(C),W="error"in u.status?u.status.error:void 0,z=C.enabled===!1,ce=!z&&!j;return e(D,{open:!0,onOpenChange:(l)=>{if(!l&&!T)t.onClose()},title:e(c,{icon:C.type==="local"?e(Qe,{}):e(Te,{}),name:u.name,meta:[C.type==="local"?"本地命令":"远程服务",ge(u.scope),L&&"OAuth 2.0"]}),size:"lg",footer:n("div",{className:"flex w-full items-center justify-between gap-2 max-sm:[&>*]:flex-none",children:[n("div",{className:"inline-flex items-center gap-2.5 text-[13px] text-dim",children:[!R&&e(M,{label:`启用 ${u.name}`,checked:!z,disabled:T||t.toggling,onCheckedChange:t.onToggle}),e(he,{info:u,tools:!0})]}),n("div",{className:"flex items-center gap-1.5",children:[L&&e(p,{type:"button",variant:"ghost",size:"sm",onClick:_,disabled:T,children:"清除凭据"}),!R&&e(V,{label:"删除服务器",children:e(p,{type:"button",variant:"danger-ghost",size:"icon","aria-label":"删除服务器",onClick:a,disabled:T,children:e(Q,{className:"size-4"})})}),ce&&e(V,{label:"终止服务进程并重新启动,让更新后的代码生效",children:e(p,{type:"button",variant:"ghost",size:"icon","aria-label":"重启",onClick:()=>ne("restart"),disabled:T,children:e(ye,{className:d("size-4",T&&"animate-spin")})})}),ce&&e(p,{type:"button",size:"sm",onClick:()=>ne(J?"disconnect":"connect"),disabled:T,children:J?"断开连接":"连接"}),!R&&n(p,{type:"button",size:"sm",onClick:t.onEdit,disabled:T,children:[e(je,{className:"size-3.5"}),e("span",{children:"编辑配置"})]})]})]}),children:n(v,{children:[n(f,{label:C.type==="local"?"命令":"地址",children:[e("span",{className:"min-w-0 font-mono text-[12px] text-dim leading-5.5 [overflow-wrap:anywhere]",children:x}),e(g,{text:x,label:"复制",size:"icon-xs",className:"shrink-0 text-faint hover:text-ink"})]}),j&&n(f,{label:"授权",children:[e("span",{className:"text-dim leading-7",children:"需要完成 OAuth 授权后才能使用,令牌会自动保存。"}),e(p,{type:"button",variant:"primary",size:"sm",onClick:ae,disabled:T,children:"前往授权"})]}),U&&e(f,{label:"错误",children:e("p",{className:"min-w-0 font-mono text-[11.5px] text-danger leading-5 [overflow-wrap:anywhere]",children:W})}),e(f,{label:"工具",children:le?e("span",{className:"text-danger",children:le}):!J?e("span",{className:"text-faint",children:"连接后列出工具"}):!B?e("span",{role:"status",className:"text-faint",children:"正在获取"}):B.length===0?e("span",{className:"text-faint",children:"服务器没有声明任何工具"}):B.map((l)=>e(S,{mono:!0,title:l.description,children:l.name},l.name))})]})})}var Pe=/^[A-Za-z0-9_-]{1,64}$/;function K(t){return e("span",{className:"truncate text-xs text-faint",children:t.children})}function Ne(t){let{pairs:p,onChange:g,InputComponent:S}=t,v=(f,c)=>g(p.map((D,M)=>M===f?{...D,...c}:D));return n("div",{className:"space-y-2",children:[n("div",{className:"flex min-h-7 items-center gap-2",children:[e("span",{className:"shrink-0 text-[13px] font-medium text-dim",children:t.label}),e(K,{children:t.tip}),n("button",{type:"button",className:"ml-auto inline-flex h-7 shrink-0 cursor-pointer items-center gap-1 rounded-lg px-2 text-xs font-medium text-dim transition-colors hover:bg-raised hover:text-ink",onClick:()=>g([...p,{key:"",value:"",saved:!1}]),children:[e(oe,{className:"size-3.5"}),"添加"]})]}),p.map((f,c)=>n("div",{className:"flex min-w-0 items-center gap-1.5",children:[e(S,{"aria-label":`${t.keyLabel} ${c+1}`,placeholder:t.keyLabel,value:f.key,readOnly:f.saved,onChange:(D)=>v(c,{key:D.target.value}),className:"min-w-0 flex-[2] font-mono text-xs"}),e(S,{"aria-label":`${t.keyLabel} ${f.key||c+1} 的值`,type:"password",autoComplete:"off",placeholder:f.saved?"已保存,留空保持不变":"值",value:f.value,onChange:(D)=>v(c,{value:D.target.value}),className:"min-w-0 flex-[3] font-mono text-xs"}),e("button",{type:"button","aria-label":`删除 ${f.key||"该项"}`,className:"flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg text-faint transition-colors hover:bg-danger/10 hover:text-danger",onClick:()=>g(p.filter((D,M)=>M!==c)),children:e(X,{className:"size-4"})})]},c))]})}function we(t){return Object.keys(t??{}).map((p)=>({key:p,value:"",saved:!0}))}function Ie(t){let{Button:p,Segmented:g,Dialog:S,Form:v,Field:f,Input:c,Switch:D,style:M,useTheme:V}=y();V();let{existing:d}=t,[Y,I]=r(d?.config.type??"local"),[u,E]=r(d?.name??""),[k,B]=r(d?.config.type==="local"?fe(d.config.command):""),[ee,le]=r(d?.config.type==="remote"?d.config.url:""),[F,T]=r(we(d?.config.type==="local"?d.config.environment:void 0)),[P,J]=r(we(d?.config.type==="remote"?d.config.headers:void 0)),j=d?.config.type==="remote"?d.config.oauth:void 0,[U,L]=r(Boolean(j)),[R,ne]=r(typeof j==="object"&&j.clientId?j.clientId:""),[ae,_]=r(""),[a,C]=r(typeof j==="object"&&j.scope?j.scope:""),[x,W]=r(d?.config.defer??"default"),[z,ce]=r(d?.config.timeout!==void 0?String(d.config.timeout):""),[l,se]=r(d?.config.defer!==void 0||d?.config.timeout!==void 0),[de,q]=r(),[N,ie]=r(!1);async function Se(b){b.preventDefault(),q(void 0);let w=u.trim();if(!d&&!Pe.test(w)){q("名称只能包含英文字母、数字、下划线与中划线,长度 1-64");return}if(!d&&t.taken.includes(w)){q("同名服务器已存在");return}let ue=z.trim()?Number.parseInt(z.trim(),10):void 0;if(ue!==void 0&&(!Number.isFinite(ue)||ue<=0)){q("超时时间须为大于 0 的毫秒数");return}let be;if(Y==="local"){let H=Ce(k.trim());if(!H.length){q("请输入启动命令");return}let G={};for(let A of F){let O=A.key.trim();if(!O)continue;if(!A.saved||A.value)G[O]=A.value}be={type:"local",command:H,environment:Object.keys(G).length?G:void 0,enabled:d?d.config.enabled:!0,defer:x==="default"?void 0:x,timeout:ue}}else{let H=ee.trim();try{let O=new URL(H);if(O.protocol!=="http:"&&O.protocol!=="https:")throw Error("bad protocol")}catch{q("请输入合法的 HTTP 或 HTTPS 地址");return}let G={};for(let O of P){let me=O.key.trim();if(!me)continue;if(!O.saved||O.value)G[me]=O.value}let A;if(U){let O=R.trim(),me=ae.trim(),ve=a.trim();if(O||me||ve)A={clientId:O||void 0,clientSecret:me||void 0,scope:ve||void 0};else A=!0}else A=!1;be={type:"remote",url:H,headers:Object.keys(G).length?G:void 0,oauth:A,enabled:d?d.config.enabled:!0,defer:x==="default"?void 0:x,timeout:ue}}ie(!0);try{let H=d?.name??w,G=d?d.projectID:t.projectID,A=G?`?projectID=${encodeURIComponent(G)}`:"";await t.connection.request(`/api/mcp/${encodeURIComponent(H)}${A}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(be)}),t.onSaved()}catch(H){q(H instanceof Error?H.message:"保存失败")}finally{ie(!1)}}return e(S,{open:!0,onOpenChange:(b)=>{if(!b&&!N)t.onClose()},title:d?`编辑 ${d.name}`:"添加 MCP 服务器",size:"lg",footer:n("div",{className:"flex w-full justify-end gap-2.5",children:[e(p,{type:"button",variant:"ghost",onClick:t.onClose,disabled:N,className:"min-w-20",children:"取消"}),e(p,{type:"submit",form:"mcp-server-form",variant:"primary",disabled:N,className:"min-w-24",children:N?"保存中...":"保存"})]}),children:n(v,{id:"mcp-server-form",onSubmit:Se,children:[e(g,{value:Y,onChange:(b)=>I(b),className:"w-full [&>button]:flex-1",options:[{value:"local",label:"本地(标准输入输出)"},{value:"remote",label:"远程(HTTP / SSE)"}]}),!d&&e(f,{label:"名称",aside:e(K,{children:"唯一标识,如 postgres"}),children:(b)=>e(c,{id:b,value:u,onChange:(w)=>E(w.target.value),placeholder:"postgres",className:"font-mono text-xs"})}),Y==="local"?n(m,{children:[e(f,{label:"启动命令",aside:e(K,{children:"完整命令及参数"}),children:(b)=>e(c,{id:b,value:k,onChange:(w)=>B(w.target.value),placeholder:"npx -y @modelcontextprotocol/server-postgres ...",className:"font-mono text-xs"})}),e(Ne,{label:"环境变量",tip:"启动进程时注入",keyLabel:"变量名",pairs:F,onChange:T,InputComponent:c})]}):n(m,{children:[e(f,{label:"服务地址",aside:e(K,{children:"HTTP / HTTPS 端点"}),children:(b)=>e(c,{id:b,value:ee,onChange:(w)=>le(w.target.value),placeholder:"https://example.com/mcp",className:"font-mono text-xs"})}),e(Ne,{label:"请求头",tip:"随每次请求发送",keyLabel:"头字段",pairs:P,onChange:J,InputComponent:c}),n("div",{className:"flex items-center justify-between gap-4",children:[n("div",{className:"min-w-0",children:[e("span",{className:"block text-[13px] font-medium text-dim",children:"OAuth 2.0 认证"}),e("span",{className:"block truncate text-xs text-faint",children:"自动发现授权端点,使用 PKCE 并刷新令牌"})]}),e(D,{checked:U,onCheckedChange:L,label:"启用 OAuth 2.0"})]}),U&&n(m,{children:[e(f,{label:"Client ID",aside:e(K,{children:"留空自动动态注册(DCR)"}),children:(b)=>e(c,{id:b,value:R,onChange:(w)=>ne(w.target.value),placeholder:"留空自动动态注册",className:"font-mono text-xs"})}),e(f,{label:"Client Secret",aside:e(K,{children:"留空保持不变"}),children:(b)=>e(c,{id:b,type:"password",autoComplete:"off",value:ae,onChange:(w)=>_(w.target.value),placeholder:"••••••••",className:"font-mono text-xs"})}),e(f,{label:"Scope",aside:e(K,{children:"选填授权范围"}),children:(b)=>e(c,{id:b,value:a,onChange:(w)=>C(w.target.value),placeholder:"repo read:org",className:"font-mono text-xs"})})]})]}),n("div",{className:"space-y-3 border-t border-line/60 pt-3",children:[n("button",{type:"button","aria-expanded":l,className:"flex w-full cursor-pointer items-center gap-1.5 text-[13px] font-medium text-dim transition-colors hover:text-ink",onClick:()=>se(!l),children:[e(lt,{className:`size-3.5 transition-transform ${l?"rotate-90":""}`}),"高级设置",e("span",{className:"truncate text-xs font-normal text-faint",children:"加载时机、超时"})]}),l&&n("div",{className:"grid grid-cols-2 gap-3 max-sm:grid-cols-1",children:[e(f,{label:"加载时机",aside:e(K,{children:"延迟 = 按需加载"}),children:()=>e(g,{value:x,onChange:(b)=>W(b),className:"w-full [&>button]:flex-1",options:[{value:"default",label:"默认"},{value:"defer",label:"延迟"},{value:"always",label:"常驻"}]})}),e(f,{label:"超时(毫秒)",aside:e(K,{children:"留空用默认"}),children:(b)=>e(c,{id:b,value:z,onChange:(w)=>ce(w.target.value),placeholder:"默认",className:"font-mono text-xs"})})]})]}),de&&n("div",{role:"alert",className:M("callout.base",M("callout.danger"),"px-3 py-2.5 text-xs"),children:[e(te,{className:"mt-0.5 size-3.5 shrink-0"}),e("span",{className:"min-w-0 break-words",children:de})]})]})})}var Z="global";function at({connection:t}){let{Button:p,Select:g,CatalogRow:S,style:v,useTheme:f}=y();f();let[c,D]=r(""),[M,V]=r(),[d,Y]=r([]),[I,u]=r(Z),[E,k]=r(),[B,ee]=r(!1),[le,F]=r(),[T,P]=r(!1),J=i(!1),[j,U]=r(),L=i(0),R=h(async()=>{let a=++L.current;ee(!0);try{let C=I===Z?"":`?projectID=${encodeURIComponent(I)}`,[x,W]=await Promise.all([t.request(`/api/mcp${C}`),t.request("/api/mcp/projects")]);if(a!==L.current)return;if(V(x),Y(W),I!==Z&&!W.some((z)=>z.id===I))u(Z);k(void 0)}catch(C){if(a===L.current)k(C instanceof Error?C.message:"读取失败")}finally{if(a===L.current)ee(!1)}},[t,I]);o(()=>(R(),()=>{L.current++}),[R]);async function ne(a,C){if(J.current)return;J.current=!0,P(!0);let x=L.current;try{let W=a.projectID?`?projectID=${encodeURIComponent(a.projectID)}`:"",z=await t.request(`/api/mcp/${encodeURIComponent(a.name)}${W}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({...a.config,enabled:C})});if(x===L.current)V((ce)=>ce?.map((l)=>l.name===z.name&&l.projectID===z.projectID?z:l))}finally{J.current=!1,P(!1)}}let ae=M?.filter((a)=>`${a.name} ${pe(a.config)}`.toLowerCase().includes(c.trim().toLowerCase())),_=M?.find((a)=>a.name===le);return n("div",{className:"min-w-0 space-y-6",children:[n("section",{className:"min-w-0",children:[n("div",{className:"mb-2.5 flex flex-wrap items-end justify-between gap-3 px-0.5",children:[n("div",{className:"min-w-0 flex-1 basis-48",children:[e("h2",{className:v("settings.groupTitle"),children:"MCP 服务器"}),e("p",{className:v("settings.groupDesc"),children:"外部工具与数据源管理"})]}),n("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e(g,{value:I,disabled:B,onValueChange:(a)=>{F(void 0),U(void 0),V(void 0),u(a)},groups:[{options:[{value:Z,label:"全局"}]},...zr(d)],className:"w-44"}),e(p,{variant:"ghost",disabled:B,onClick:R,className:"h-9 px-2.5 text-xs",children:e(re,{className:`size-3.5 ${B?"animate-spin":""}`})}),n(p,{variant:"secondary",onClick:()=>U({}),className:"h-9 px-2.5 text-xs",children:[e(oe,{className:"size-3.5 mr-1"}),"添加服务器"]})]})]}),E&&n("div",{role:"alert",className:v("callout.base",v("callout.danger"),"mb-3 flex-wrap items-center justify-between"),children:[n("p",{className:"min-w-0 flex-1 break-words text-sm text-danger",children:["无法读取 MCP 服务器:",E]}),e(p,{disabled:B,onClick:R,children:"重试"})]}),e(Ur,{label:"搜索 MCP 服务器",placeholder:"搜索服务器",value:c,onChange:D}),e("div",{className:v("settings.groupBox"),children:!M?e(jr,{}):ae?.length===0?e("p",{className:"p-4 text-sm text-dim",children:"没有匹配的 MCP 服务器"}):e("ul",{className:"divide-y divide-line",children:ae?.map((a)=>{let C=a.config.enabled===!1,x=a.scope==="file";return e("li",{children:e(S,{name:a.name,selectLabel:`查看 ${a.name}`,onSelect:()=>F(a.name),title:x?"来自项目的 .mcp.json,配置只读,可查看工具与重启":void 0,description:e("span",{className:"font-mono text-[11px]",children:pe(a.config)}),icon:a.config.type==="local"?e(Qe,{}):e(Te,{}),inactive:C,aside:n(m,{children:[e("span",{className:v("control.badge"),children:ge(a.scope)}),e(he,{info:a})]}),toggle:x?void 0:{checked:!C,label:`启用服务器 ${a.name}`,disabled:T||B,onCheckedChange:(W)=>ne(a,W)}})},a.name)})})})]}),_&&!j&&e(xe,{connection:t,info:_,toggling:T,onToggle:(a)=>ne(_,a),projectID:I===Z?void 0:I,onClose:()=>F(void 0),onEdit:()=>U({info:_}),onChanged:(a)=>a?V((C)=>C?.map((x)=>x.name===a.name?a:x)):R()},`${_.projectID}:${_.name}`),j&&e(Ie,{connection:t,projectID:I===Z?void 0:I,existing:j.info,taken:(M??[]).filter((a)=>a.scope===(I===Z?"global":"project")).map((a)=>a.name),onClose:()=>U(void 0),onSaved:()=>{U(void 0),R()}})]})}export{at as McpSection};