@samanhappy/mcphub 1.0.16 → 1.0.18

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 (92) hide show
  1. package/dist/betterAuth.js +2 -2
  2. package/dist/betterAuth.js.map +1 -1
  3. package/dist/cli/commands/cache.js +39 -0
  4. package/dist/cli/commands/cache.js.map +1 -0
  5. package/dist/cli/commands/servers.js +14 -0
  6. package/dist/cli/commands/servers.js.map +1 -1
  7. package/dist/cli/help.js +11 -2
  8. package/dist/cli/help.js.map +1 -1
  9. package/dist/cli/main.js +1 -0
  10. package/dist/cli/main.js.map +1 -1
  11. package/dist/controllers/groupController.js +66 -2
  12. package/dist/controllers/groupController.js.map +1 -1
  13. package/dist/controllers/serverController.js +62 -1
  14. package/dist/controllers/serverController.js.map +1 -1
  15. package/dist/db/entities/Group.js.map +1 -1
  16. package/dist/middlewares/auth.js +20 -7
  17. package/dist/middlewares/auth.js.map +1 -1
  18. package/dist/routes/index.js +3 -1
  19. package/dist/routes/index.js.map +1 -1
  20. package/dist/services/groupService.js +25 -0
  21. package/dist/services/groupService.js.map +1 -1
  22. package/dist/services/mcpService.js +270 -25
  23. package/dist/services/mcpService.js.map +1 -1
  24. package/dist/services/smartRoutingService.js +63 -12
  25. package/dist/services/smartRoutingService.js.map +1 -1
  26. package/dist/utils/cacheUtils.js +110 -0
  27. package/dist/utils/cacheUtils.js.map +1 -0
  28. package/frontend/dist/assets/{ActivityPage-BYPkr9n2.js → ActivityPage-C36IBbnj.js} +2 -2
  29. package/frontend/dist/assets/{ActivityPage-BYPkr9n2.js.map → ActivityPage-C36IBbnj.js.map} +1 -1
  30. package/frontend/dist/assets/{ConfirmDialog-Cag_haxr.js → ConfirmDialog-BKNVI65J.js} +2 -2
  31. package/frontend/dist/assets/{ConfirmDialog-Cag_haxr.js.map → ConfirmDialog-BKNVI65J.js.map} +1 -1
  32. package/frontend/dist/assets/{Dashboard-BbGvQMHv.js → Dashboard-BsUNNsqb.js} +2 -2
  33. package/frontend/dist/assets/{Dashboard-BbGvQMHv.js.map → Dashboard-BsUNNsqb.js.map} +1 -1
  34. package/frontend/dist/assets/{DeleteDialog-BBfJpiiD.js → DeleteDialog-7NPk3Hro.js} +2 -2
  35. package/frontend/dist/assets/{DeleteDialog-BBfJpiiD.js.map → DeleteDialog-7NPk3Hro.js.map} +1 -1
  36. package/frontend/dist/assets/{EndpointCopy-DhPgdjmi.js → EndpointCopy-eF3xFbaZ.js} +2 -2
  37. package/frontend/dist/assets/{EndpointCopy-DhPgdjmi.js.map → EndpointCopy-eF3xFbaZ.js.map} +1 -1
  38. package/frontend/dist/assets/GroupsPage-Dp-NU5wZ.js +33 -0
  39. package/frontend/dist/assets/GroupsPage-Dp-NU5wZ.js.map +1 -0
  40. package/frontend/dist/assets/{LoginPage-2PH92kBp.js → LoginPage-9PIMlvGe.js} +2 -2
  41. package/frontend/dist/assets/{LoginPage-2PH92kBp.js.map → LoginPage-9PIMlvGe.js.map} +1 -1
  42. package/frontend/dist/assets/{LogsPage-D8ws1iFm.js → LogsPage-C8WS43Dw.js} +2 -2
  43. package/frontend/dist/assets/{LogsPage-D8ws1iFm.js.map → LogsPage-C8WS43Dw.js.map} +1 -1
  44. package/frontend/dist/assets/{MarketPage-BL9qUEMR.js → MarketPage-Cyl5VvwI.js} +2 -2
  45. package/frontend/dist/assets/{MarketPage-BL9qUEMR.js.map → MarketPage-Cyl5VvwI.js.map} +1 -1
  46. package/frontend/dist/assets/{Pagination-DBAu79mv.js → Pagination-DAcOi8eq.js} +2 -2
  47. package/frontend/dist/assets/{Pagination-DBAu79mv.js.map → Pagination-DAcOi8eq.js.map} +1 -1
  48. package/frontend/dist/assets/{PromptsPage-CtXO4diZ.js → PromptsPage-CqxKWAR9.js} +2 -2
  49. package/frontend/dist/assets/{PromptsPage-CtXO4diZ.js.map → PromptsPage-CqxKWAR9.js.map} +1 -1
  50. package/frontend/dist/assets/{ResourcesPage-GD-T8LpP.js → ResourcesPage-Dq7Grza0.js} +2 -2
  51. package/frontend/dist/assets/{ResourcesPage-GD-T8LpP.js.map → ResourcesPage-Dq7Grza0.js.map} +1 -1
  52. package/frontend/dist/assets/ServersPage-xt7QkwjZ.js +37 -0
  53. package/frontend/dist/assets/ServersPage-xt7QkwjZ.js.map +1 -0
  54. package/frontend/dist/assets/SettingsPage-Cn5Krvgb.js +12 -0
  55. package/frontend/dist/assets/SettingsPage-Cn5Krvgb.js.map +1 -0
  56. package/frontend/dist/assets/{StatusDot-Bp40buM9.js → StatusDot-DAStUyI3.js} +2 -2
  57. package/frontend/dist/assets/{StatusDot-Bp40buM9.js.map → StatusDot-DAStUyI3.js.map} +1 -1
  58. package/frontend/dist/assets/{ToggleGroup-B15lxnw6.js → ToggleGroup-CQvqGQLA.js} +2 -2
  59. package/frontend/dist/assets/{ToggleGroup-B15lxnw6.js.map → ToggleGroup-CQvqGQLA.js.map} +1 -1
  60. package/frontend/dist/assets/{UsersPage-Cv80MtZ4.js → UsersPage-Bsa2NGcJ.js} +2 -2
  61. package/frontend/dist/assets/{UsersPage-Cv80MtZ4.js.map → UsersPage-Bsa2NGcJ.js.map} +1 -1
  62. package/frontend/dist/assets/{contextCost-DldRDO4O.js → contextCost-DrQqHXcP.js} +2 -2
  63. package/frontend/dist/assets/{contextCost-DldRDO4O.js.map → contextCost-DrQqHXcP.js.map} +1 -1
  64. package/frontend/dist/assets/framework-vendor-X-WP1v0m.js +61 -0
  65. package/frontend/dist/assets/framework-vendor-X-WP1v0m.js.map +1 -0
  66. package/frontend/dist/assets/{i18n-vendor-DP1IRITP.js → i18n-vendor-BLr2MLKp.js} +2 -2
  67. package/frontend/dist/assets/{i18n-vendor-DP1IRITP.js.map → i18n-vendor-BLr2MLKp.js.map} +1 -1
  68. package/frontend/dist/assets/{icons-vendor-BTEm6PQs.js → icons-vendor-DMtsx1SI.js} +63 -58
  69. package/frontend/dist/assets/icons-vendor-DMtsx1SI.js.map +1 -0
  70. package/frontend/dist/assets/{index-D1-Bdpe1.css → index-BlTPJflb.css} +1 -1
  71. package/frontend/dist/assets/index-BsgjLwhT.js +3 -0
  72. package/frontend/dist/assets/index-BsgjLwhT.js.map +1 -0
  73. package/frontend/dist/assets/{resourceService-CN0gM37U.js → resourceService-Bg941cnv.js} +2 -2
  74. package/frontend/dist/assets/{resourceService-CN0gM37U.js.map → resourceService-Bg941cnv.js.map} +1 -1
  75. package/frontend/dist/assets/useSettingsData-BwKohDXD.js +2 -0
  76. package/frontend/dist/assets/{useSettingsData-DewLOhzu.js.map → useSettingsData-BwKohDXD.js.map} +1 -1
  77. package/frontend/dist/assets/{variableDetection-hIevXYOZ.js → variableDetection-Bp_stsiy.js} +2 -2
  78. package/frontend/dist/assets/{variableDetection-hIevXYOZ.js.map → variableDetection-Bp_stsiy.js.map} +1 -1
  79. package/frontend/dist/index.html +5 -5
  80. package/package.json +13 -12
  81. package/frontend/dist/assets/GroupsPage-BC9FlhX4.js +0 -33
  82. package/frontend/dist/assets/GroupsPage-BC9FlhX4.js.map +0 -1
  83. package/frontend/dist/assets/ServersPage-CXUBWjQO.js +0 -37
  84. package/frontend/dist/assets/ServersPage-CXUBWjQO.js.map +0 -1
  85. package/frontend/dist/assets/SettingsPage-C5tAS-rd.js +0 -12
  86. package/frontend/dist/assets/SettingsPage-C5tAS-rd.js.map +0 -1
  87. package/frontend/dist/assets/framework-vendor-DeqnZ0v6.js +0 -61
  88. package/frontend/dist/assets/framework-vendor-DeqnZ0v6.js.map +0 -1
  89. package/frontend/dist/assets/icons-vendor-BTEm6PQs.js.map +0 -1
  90. package/frontend/dist/assets/index-OwXusZPZ.js +0 -3
  91. package/frontend/dist/assets/index-OwXusZPZ.js.map +0 -1
  92. package/frontend/dist/assets/useSettingsData-DewLOhzu.js +0 -2
@@ -0,0 +1,37 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-Bg941cnv.js","./index-BsgjLwhT.js","./framework-vendor-X-WP1v0m.js","./i18n-vendor-BLr2MLKp.js","./icons-vendor-DMtsx1SI.js","./index-BlTPJflb.css"])))=>i.map(i=>d[i]);
2
+ import{r as u,j as e,d as ys}from"./framework-vendor-X-WP1v0m.js";import{e as oe,f as Ze,h as ve,i as Ee,u as js,_ as ge,j as vs,k as Ns,l as ws}from"./index-BsgjLwhT.js";import{f as ae,u as ks,a as Cs}from"./contextCost-DrQqHXcP.js";import{S as Ss}from"./StatusDot-DAStUyI3.js";import{u as De}from"./useSettingsData-BwKohDXD.js";import{S as Ne}from"./ToggleGroup-CQvqGQLA.js";import{u as se}from"./i18n-vendor-BLr2MLKp.js";import{n as Qe,o as es,l as we,p as Es,C as me,q as ye,r as Pe,s as ss,t as ts,u as ze,m as ke,W as Ds,g as Ps,F as zs,X as Se,E as Ts,v as $s,R as je,w as Fs,T as Is,P as Rs,x as _s,y as Os,z as As}from"./icons-vendor-DMtsx1SI.js";import{g as Ms}from"./toolDescription-Dw3sa28K.js";import{D as Vs}from"./DeleteDialog-7NPk3Hro.js";import{C as rs}from"./ConfirmDialog-BKNVI65J.js";import{S as ns,d as Js}from"./variableDetection-Bp_stsiy.js";import{P as Us}from"./Pagination-DAcOi8eq.js";const as=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await oe(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return n.success===!1?{success:!1,error:n.message||"Tool call failed"}:{success:!0,content:(n==null?void 0:n.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Bs=async(s,r,t)=>{try{const n=await oe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},os=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},is=async(s,r)=>{var t;try{const n=await Ze(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Ls=Object.freeze(Object.defineProperty({__proto__:null,callTool:as,resetToolDescription:is,toggleTool:Bs,updateToolDescription:os},Symbol.toStringTag,{value:"Module"})),ls=({schema:s,onSubmit:r,onCancel:t,loading:n=!1,storageKey:h,title:g})=>{const{t:a}=se(),[y,D]=u.useState({}),[l,o]=u.useState({}),[C,z]=u.useState(!1),[j,I]=u.useState(""),[w,E]=u.useState(""),f=u.useMemo(()=>(m=>{const N=i=>{if(typeof i=="object"&&i!==null){const p=i;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([d,v])=>[d,N(v)])):void 0,required:p.required,items:p.items?N(p.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([i,p])=>[i,N(p)])):void 0,required:m.required}})(s),[s]);u.useEffect(()=>{const x=(N,i="")=>{const p={};return N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([d,v])=>{const F=i?`${i}.${d}`:d;v.default!==void 0?p[d]=v.default:v.type==="string"?p[d]="":v.type==="number"||v.type==="integer"?p[d]=0:v.type==="boolean"?p[d]=!1:v.type==="array"?p[d]=[]:v.type==="object"&&(v.properties?p[d]=x(v,F):p[d]={})}),p};let m=x(f);if(h)try{const N=localStorage.getItem(h);if(N){const i=JSON.parse(N);m={...m,...i}}}catch(N){console.warn("Failed to load saved form data:",N)}D(m)},[f,h]),u.useEffect(()=>{C&&Object.keys(y).length>0&&(I(JSON.stringify(y,null,2)),E(""))},[C,y]);const V=x=>{I(x),E("");try{const m=JSON.parse(x);if(D(m),h)try{localStorage.setItem(h,JSON.stringify(m))}catch(N){console.warn("Failed to save form data to localStorage:",N)}}catch{E(a("tool.invalidJsonFormat"))}},A=()=>{I(JSON.stringify(y,null,2)),E(""),z(!0)},U=()=>{if(j.trim())try{const x=JSON.parse(j);D(x),E(""),z(!1)}catch{E(a("tool.fixJsonBeforeSwitching"));return}else z(!1)},_=(x,m)=>{D(N=>{const i={...N},p=x.split(".");let d=i;for(let v=0;v<p.length-1;v++)d[p[v]]||(d[p[v]]={}),d=d[p[v]];if(d[p[p.length-1]]=m,h)try{localStorage.setItem(h,JSON.stringify(i))}catch(v){console.warn("Failed to save form data to localStorage:",v)}return i}),l[x]&&o(N=>{const i={...N};return delete i[x],i})},J=()=>{const x={},m=(N,i,p="")=>{N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([d,v])=>{var L;const F=p?`${p}.${d}`:d,R=i==null?void 0:i[d];if((L=N.required)!=null&&L.includes(d)&&(R==null||R===""||Array.isArray(R)&&R.length===0)){x[F]=`${d} is required`;return}R!=null&&R!==""&&(v.type==="string"&&typeof R!="string"?x[F]=`${d} must be a string`:v.type==="number"&&typeof R!="number"?x[F]=`${d} must be a number`:v.type==="integer"&&(!Number.isInteger(R)||typeof R!="number")?x[F]=`${d} must be an integer`:v.type==="boolean"&&typeof R!="boolean"?x[F]=`${d} must be a boolean`:v.type==="array"&&Array.isArray(R)?v.items&&R.forEach((X,O)=>{var G;((G=v.items)==null?void 0:G.type)==="object"&&v.items.properties&&m(v.items,X,`${F}.${O}`)}):v.type==="object"&&typeof R=="object"&&m(v,R,F))})};return m(f,y),o(x),Object.keys(x).length===0},T=x=>{x.preventDefault(),J()&&r(y)},H=(x,m)=>m.split(".").reduce((N,i)=>N==null?void 0:N[i],x),B=(x,m,N,i)=>{const p=N==null?void 0:N[x];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",onChange:d=>i(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.enum.map((d,v)=>e.jsx("option",{value:d,children:d},v))]}):e.jsx("input",{type:"text",value:p||"",onChange:d=>i(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||a("tool.enterKey",{key:x})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:d=>{const v=d.target.value===""?"":m.type==="integer"?parseInt(d.target.value):parseFloat(d.target.value);i(v)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):m.type==="boolean"?e.jsx("input",{type:"checkbox",checked:p||!1,onChange:d=>i(d.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:p||"",onChange:d=>i(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||a("tool.enterKey",{key:x})})},Z=(x,m,N="")=>{var v,F,R,L,X,O,G,S,W,te,le,P,q,Q;const i=N?`${N}.${x}`:x,p=H(y,i),d=l[i];if(m.type==="array"){const $=H(y,i)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?(F=(v=H(f,N))==null?void 0:v.required)==null?void 0:F.includes(x):(R=f.required)==null?void 0:R.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[$.map((Y,ee)=>{var pe,xe,he;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a("tool.item",{index:ee+1})}),e.jsx("button",{type:"button",onClick:()=>{const K=[...$];K.splice(ee,1),_(i,K)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((pe=m.items)==null?void 0:pe.type)==="string"&&m.items.enum?e.jsxs("select",{value:Y||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(i,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.items.enum.map((K,re)=>e.jsx("option",{value:K,children:K},re))]}):((xe=m.items)==null?void 0:xe.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([K,re])=>{var be,fe;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[K,((fe=(be=m.items)==null?void 0:be.required)==null?void 0:fe.includes(K))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),B(K,re,Y,Ce=>{const ue=[...$];ue[ee]={...ue[ee],[K]:Ce},_(i,ue)})]},K)})}):e.jsx("input",{type:"text",value:Y||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(i,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:a("tool.enterValue",{type:((he=m.items)==null?void 0:he.type)||"value"})})]},ee)}),e.jsx("button",{type:"button",onClick:()=>{var ee;const Y=((ee=m.items)==null?void 0:ee.type)==="object"?{}:"";_(i,[...$,Y])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:a("tool.addItem",{key:x})})]}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i)}return m.type==="object"?m.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?(X=(L=H(f,N))==null?void 0:L.required)==null?void 0:X.includes(x):(O=f.required)==null?void 0:O.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(m.properties).map(([$,Y])=>Z($,Y,i))}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?(S=(G=H(f,N))==null?void 0:G.required)==null?void 0:S.includes(x):(W=f.required)==null?void 0:W.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("textarea",{value:typeof p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:$=>{try{const Y=JSON.parse($.target.value);_(i,Y)}catch{_(i,$.target.value)}},placeholder:`{
3
+ "key": "value"
4
+ }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):m.type==="string"?m.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(te=f.required)==null?void 0:te.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("select",{value:p||"",onChange:$=>_(i,$.target.value),className:`w-full border rounded-md px-3 py-2 ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.enum.map(($,Y)=>e.jsx("option",{value:$,children:$},Y))]}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(le=f.required)==null?void 0:le.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:p||"",onChange:$=>_(i,$.target.value),className:`w-full border rounded-md px-3 py-2 ${d?"border-red":"border-gray-200"} focus:outline-none form-input`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):m.type==="number"||m.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(P=f.required)==null?void 0:P.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:$=>{const Y=$.target.value===""?"":m.type==="integer"?parseInt($.target.value):parseFloat($.target.value);_(i,Y)},className:`w-full border rounded-md px-3 py-2 form-input ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):m.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:p||!1,onChange:$=>_(i,$.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[x,(N?!1:(q=f.required)==null?void 0:q.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:m.description}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(Q=f.required)==null?void 0:Q.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",m.type,")"]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:p||"",onChange:$=>_(i,$.target.value),placeholder:a("tool.enterValue",{type:m.type}),className:`w-full border rounded-md px-3 py-2 ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},i)};return f.properties?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-3",children:[e.jsx("h6",{className:"text-md font-medium text-gray-900",children:g}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:U,className:`hub-btn sm ${C?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:A,className:`hub-btn sm ${C?"primary":""}`,children:a("tool.jsonMode")})]})]}),C?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("tool.jsonConfiguration")}),e.jsx("textarea",{value:j,onChange:x=>V(x.target.value),placeholder:`{
5
+ "key": "value"
6
+ }`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${w?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),w&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:w})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const x=JSON.parse(j);r(x)}catch{E(a("tool.invalidJsonFormat"))}},disabled:n||!!w,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:T,className:"space-y-4",children:[Object.entries(f.properties||{}).map(([x,m])=>Z(x,m)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:n,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>r({}),disabled:n,className:"hub-btn primary",children:a(n?"tool.running":"tool.runTool")})]})]})},Ws=({result:s,onClose:r})=>{const{t}=se(),n=s.content,h=o=>o?o.startsWith("image/")?o:`image/${o}`:"image/png",g=o=>{if(!o)return[];if(Array.isArray(o))return o.flatMap(j=>g(j));if(typeof o!="object")return[];const C=[];o.type==="image"&&o.data&&C.push({data:String(o.data),mimeType:h(o.mimeType||o.mime_type)});const z=o.image_base64||o.imageBase64||o.image_data||o.imageData||o.base64;return z&&C.push({data:String(z),mimeType:h(o.image_mimeType||o.image_mime_type||o.mimeType||o.mime_type)}),o.image&&typeof o.image=="object"&&C.push(...g(o.image)),Array.isArray(o.images)&&C.push(...g(o.images)),Array.isArray(o.content)&&C.push(...g(o.content)),C},a=o=>{const C=[];try{const I=JSON.parse(o);if(C.push(...g(I)),C.length>0)return C}catch{}const z=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let j;for(;(j=z.exec(o))!==null;){const I=`image/${j[1]==="jpg"?"jpeg":j[1]}`;C.push({data:j[2],mimeType:I})}return C},y=o=>{try{const C=JSON.parse(o),z=j=>{if(Array.isArray(j))return j.map(z);if(j&&typeof j=="object"){const I={};for(const[w,E]of Object.entries(j))typeof E=="string"&&w.toLowerCase().includes("base64")?I[w]="[base64 omitted]":I[w]=z(E);return I}return j};return JSON.stringify(z(C),null,2)}catch{return o.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},D=o=>Array.isArray(o)?o.map((C,z)=>e.jsx("div",{className:"mb-3 last:mb-0",children:l(C)},z)):l(o),l=o=>{if(typeof o=="string"){const C=a(o),z=y(o);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[C.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:C.map((j,I)=>e.jsx("img",{src:`data:${j.mimeType||"image/png"};base64,${j.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:z})]})}if(typeof o=="object"&&o!==null){if(o.type==="text"&&o.text){const C=a(o.text),z=y(o.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[C.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:C.map((j,I)=>e.jsx("img",{src:`data:${j.mimeType||"image/png"};base64,${j.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:z})]})}if(o.type==="image"&&o.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${o.mimeType||"image/png"};base64,${o.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const C=typeof o=="string"?JSON.parse(o):o;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(C,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(o)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(o)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),D(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),n&&n.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),D(n)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},de=({title:s,onClick:r,disabled:t=!1,loading:n=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:r,disabled:t,title:s,"aria-label":s,children:e.jsx(Es,{size:14,className:n?"animate-spin":""})});function qs(s){return s==null?!0:typeof s=="string"?s.trim()==="":Array.isArray(s)?s.length===0:typeof s=="object"?Object.keys(s).length===0:!1}const Hs=({tool:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:g})=>{const{t:a}=se(),{showToast:y}=Ee(),{nameSeparator:D}=De(),[l,o]=u.useState(!1),[C,z]=u.useState(!1),[j,I]=u.useState(!1),[w,E]=u.useState(null),[f,V]=u.useState(!1),[A,U]=u.useState(!1),[_,J]=u.useState(s.description||""),T=u.useRef(null),H=u.useRef(null),[B,Z]=u.useState(0),[x,m]=u.useState(!1);u.useEffect(()=>{f&&T.current&&(T.current.focus(),B>0&&(T.current.style.width=`${B+20}px`))},[f,B]),u.useEffect(()=>{!f&&H.current&&Z(H.current.offsetWidth)},[f,_]),u.useEffect(()=>{J(s.description||"")},[s.description]);const N=s.name.replace(r+D,""),i=Ms(s,a("tool.noDescription")),p=i.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:i.defaultDescription}):void 0,d=u.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),v=u.useCallback(()=>{localStorage.removeItem(d())},[d]),F=P=>{!t&&n&&n(s.name,P)},R=()=>{t||V(!0)},L=async()=>{if(!t)try{const P=await os(r,s.name,_);P.success?(V(!1),h&&h(s.name,_)):(J(s.description||""),console.error("Failed to update tool description:",P.error))}catch(P){console.error("Error updating tool description:",P),J(s.description||""),V(!1)}},X=P=>{J(P.target.value)},O=async()=>{if(!t){U(!0);try{const P=await is(r,s.name);if(P.success){const q=P.description||"";J(q),V(!1),h==null||h(s.name,q,{restored:!0})}else y(P.error||a("tool.restoreDefaultFailed"),"error")}catch(P){console.error("Error resetting tool description:",P),y(a("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},G=P=>{P.key==="Enter"?L():P.key==="Escape"&&(J(s.description||""),V(!1))},S=async P=>{P.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),y(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const q=document.createElement("textarea");q.value=s.name,q.style.position="fixed",q.style.left="-9999px",document.body.appendChild(q),q.focus(),q.select();try{document.execCommand("copy"),m(!0),y(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(Q){y(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Q)}document.body.removeChild(q)}}catch(q){y(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",q)}},W=async P=>{I(!0);try{P=Object.fromEntries(Object.entries(P).filter(([Q,$])=>!qs($)));const q=await as({toolName:s.name,arguments:P},r);E(q)}catch(q){E({success:!1,error:q instanceof Error?q.message:"Unknown error occurred"})}finally{I(!1)}},te=()=>{z(!1),v(),E(null)},le=()=>{E(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:P=>{P.stopPropagation(),o(!l)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:N}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S,title:a("common.copy"),children:x?e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:f?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:_,onChange:X,onKeyDown:G,onClick:P=>P.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),L()},disabled:A,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),O()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,title:p,children:i.currentDescription}),i.hasDescriptionOverride&&e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{color:"var(--hub-accent)",borderColor:"var(--hub-line)",background:"var(--hub-bg-2)"},title:p,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),R()},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),O()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ae(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:P=>P.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:F,disabled:j||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${N}`})}),e.jsxs("button",{onClick:P=>{P.stopPropagation(),o(!0),z(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:a(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:l?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),l&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[i.hasDescriptionOverride&&i.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:a("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:i.defaultDescription})]}),!C&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),C&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:s.inputSchema||{type:"object"},onSubmit:W,onCancel:te,loading:j,storageKey:d(),title:a("tool.runToolWithName",{name:N})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ws,{result:w,onClose:le})})]})]})]})},Ks=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",n=await oe(t,{promptName:s.promptName,arguments:s.arguments});return n.success?{success:!0,data:n.data}:{success:!1,error:n.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},cs=async(s,r)=>{try{const t=await oe(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Gs=async(s,r,t)=>{try{const n=await oe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ds=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},us=async(s,r)=>{var t;try{const n=await Ze(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Xs=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:Ks,getPrompt:cs,resetPromptDescription:us,togglePrompt:Gs,updatePromptDescription:ds},Symbol.toStringTag,{value:"Module"})),He=({result:s,onClose:r})=>{const{t}=se(),n=h=>{if(typeof h=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:h})});if(typeof h=="object"&&h!==null){if(h.description||h.messages)return e.jsxs("div",{className:"space-y-4",children:[h.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:h.description})})]}),h.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:h.messages.map((g,a)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"flex items-center mb-2",children:e.jsxs("span",{className:"inline-block w-16 text-xs font-medium text-gray-500",children:[g.role,":"]})}),typeof g.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content}):typeof g.content=="object"&&g.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g.content,null,2)})]},a))})]})]});try{const g=typeof h=="string"?JSON.parse(h):h;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(h)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(h)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),n(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Ys=({prompt:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:g})=>{const{t:a}=se(),{showToast:y}=Ee(),{nameSeparator:D}=De(),[l,o]=u.useState(!1),[C,z]=u.useState(!1),[j,I]=u.useState(!1),[w,E]=u.useState(null),[f,V]=u.useState(!1),[A,U]=u.useState(!1),[_,J]=u.useState(s.description||""),T=u.useRef(null),H=u.useRef(null),[B,Z]=u.useState(0);u.useEffect(()=>{f&&T.current&&(T.current.focus(),B>0&&(T.current.style.width=`${B+20}px`))},[f,B]),u.useEffect(()=>{!f&&H.current&&Z(H.current.offsetWidth)},[f,_]),u.useEffect(()=>{J(s.description||"")},[s.description]);const x=u.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),m=u.useCallback(()=>{localStorage.removeItem(x())},[x]),N=S=>{!t&&n&&n(s.name,S)},i=()=>{t||V(!0)},p=async()=>{if(!t){V(!1);try{const S=await ds(r,s.name,_);S.success?h&&h(s.name,_):(y(S.error||a("prompt.descriptionUpdateFailed"),"error"),J(s.description||""))}catch(S){console.error("Error updating prompt description:",S),y(a("prompt.descriptionUpdateFailed"),"error"),J(s.description||"")}}},d=async()=>{if(!t){U(!0);try{const S=await us(r,s.name);if(S.success){const W=S.description||"";J(W),V(!1),h==null||h(s.name,W,{restored:!0})}else y(S.error||a("prompt.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting prompt description:",S),y(a("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},v=S=>{J(S.target.value)},F=S=>{S.key==="Enter"?p():S.key==="Escape"&&(J(s.description||""),V(!1))},R=async S=>{I(!0);try{const W=await cs({promptName:s.name,arguments:S},r);console.log("GetPrompt result:",W),E({success:W.success,data:W.data,error:W.error})}catch(W){E({success:!1,error:W instanceof Error?W.message:"Unknown error occurred"})}finally{I(!1)}},L=()=>{z(!1),m(),E(null)},X=()=>{E(null)},O=s.name.replace(r+D,""),G=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const S={},W=[];return s.arguments.forEach(te=>{S[te.name]={type:"string",description:te.description||""},te.required&&W.push(te.name)}),{type:"object",properties:S,required:W}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>o(!l),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:O}),s.title&&e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.title}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:f?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:_,onChange:v,onKeyDown:F,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),p()},disabled:A,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),d()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,children:_||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),i()},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),d()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ae(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:S=>S.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ne,{checked:s.enabled,onCheckedChange:N,disabled:j||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${O}`})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),o(!0),z(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:a(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:l?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),l&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[C&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:G(),onSubmit:R,onCancel:L,loading:j,storageKey:x(),title:a("prompt.runPromptWithName",{name:O})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(He,{result:w,onClose:X})})]}),!C&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((S,W)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:S.name}),S.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),S.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:S.description})]}),S.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:S.title})]},W))})]}),!C&&w&&e.jsx("div",{children:e.jsx(He,{result:w,onClose:X})})]})]})},Zs=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:n,cost:h})=>{const{t:g}=se(),[a,y]=u.useState(!1),[D,l]=u.useState(!1),[o,C]=u.useState(!1),[z,j]=u.useState(s.description||""),I=u.useRef(null),w=u.useRef(null),[E,f]=u.useState(0);u.useEffect(()=>{D&&I.current&&(I.current.focus(),E>0&&(I.current.style.width=`${E+20}px`))},[D,E]),u.useEffect(()=>{!D&&w.current&&f(w.current.offsetWidth)},[D,z]),u.useEffect(()=>{j(s.description||"")},[s.description]);const V=s.name||s.uri,A=T=>{!r&&t&&t(s.uri,T)},U=async()=>{r||(l(!1),n&&await n(s.uri,z))},_=async()=>{if(!r){C(!0);try{await(n==null?void 0:n(s.uri,"",{restored:!0})),l(!1)}finally{C(!1)}}},J=T=>{T.key==="Enter"?U():T.key==="Escape"&&(j(s.description||""),l(!1))};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>y(!a),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:V}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:E>0?`${E+20}px`:160,minWidth:80},value:z,onChange:T=>j(T.target.value),onKeyDown:J,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),U()},disabled:o,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),_()},disabled:o,loading:o})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:w,children:z||g("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),l(!0)},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),_()},disabled:o,loading:o})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[h!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:g("cost.estimate"),children:["Σ ",ae(h)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled!==!1,onCheckedChange:A,disabled:r,size:"card","aria-label":`${g(s.enabled!==!1?"server.disable":"server.enable")} ${V}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),a&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[g("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Qs=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,et={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Te=s=>s==="public"||s==="group"?s:"private",st=(s,r)=>{const t=Te(r),n=et[t];return{value:t,shortLabel:s(n.shortKey,{defaultValue:n.shortFallback}),longLabel:s(n.longKey,{defaultValue:n.longFallback}),className:n.className}},tt=(s,r)=>{const t=Te(r),n=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&n.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),n.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),n},Ke=({isLoading:s,children:r,className:t,overlayStyle:n,spinnerSize:h=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:r}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...n},children:e.jsx(je,{size:h,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),Ge=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),Xe=(s,r)=>r?r==="stdio"?s("server.typeStdio")||"stdio":r==="sse"?s("server.typeSse")||"sse":r==="streamable-http"?s("server.typeStreamableHttp")||"http":r==="openapi"?s("server.typeOpenapi")||"openapi":r:null,rt="text/html;profile=mcp-app",Ye=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,nt=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(n=>Ye(n._meta))||(t=s.resources)!=null&&t.some(n=>{var h;return((h=n.uri)==null?void 0:h.startsWith("ui://"))||n.mimeType===rt||Ye(n._meta)}))},at=({server:s,cost:r,onRemove:t,onEdit:n,onToggle:h,onVisibilityChange:g,onRefresh:a,onReload:y,onReinstall:D})=>{var Re,_e,Oe,Ae,Me,Ve,Je,Ue,Be,Le,We,qe;const{t:l}=se(),{showToast:o}=Ee(),{exportMCPSettings:C,installConfig:z}=De(),{auth:j}=js(),I=((Re=z==null?void 0:z.baseUrl)==null?void 0:Re.replace(/\/+$/,""))||"",[w,E]=u.useState(!1),[f,V]=u.useState(null),[A,U]=u.useState(!1),[_,J]=u.useState(!1),[T,H]=u.useState(!1),[B,Z]=u.useState(!1),[x,m]=u.useState(!1),[N,i]=u.useState(!1),[p,d]=u.useState(!1),[v,F]=u.useState(!1),[R,L]=u.useState(!1),X=u.useRef(null),O=u.useRef(null);u.useEffect(()=>{const c=b=>{X.current&&!X.current.contains(b.target)&&d(!1),O.current&&!O.current.contains(b.target)&&F(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]);const G=((_e=s.tools)==null?void 0:_e.length)||0,S=((Oe=s.tools)==null?void 0:Oe.filter(c=>c.enabled!==!1).length)||0,W=((Ae=s.prompts)==null?void 0:Ae.length)||0,te=((Me=s.prompts)==null?void 0:Me.filter(c=>c.enabled!==!1).length)||0,le=((Ve=s.resources)==null?void 0:Ve.length)||0,P=((Je=s.resources)==null?void 0:Je.filter(c=>c.enabled!==!1).length)||0,q=nt(s),Q=s.enabled!==!1,$=Qs(s,j.user),Y=((Ue=s.config)==null?void 0:Ue.command)==="npx"||((Be=s.config)==null?void 0:Be.command)==="uvx",ee=async c=>{if(!(!$||T||!h)){H(!0);try{await h(s,c)}finally{H(!1)}}},pe=async c=>{if(c.stopPropagation(),d(!1),!(!$||x||!y)){m(!0);try{await y(s)?o(l("server.reloadSuccess")||"Server reloaded successfully","success"):o(l("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{m(!1)}}},xe=async()=>{if(d(!1),!(!$||N||!D)){i(!0);try{await D(s)?o(l("server.reinstallSuccess")||"Server reinstall initiated","success"):o(l("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{i(!1)}}},he=async c=>{var k;if(c.stopPropagation(),!$||B||!g)return;const b=c.target.value;if(b!==Te(s.visibility??((k=s.config)==null?void 0:k.visibility))){Z(!0);try{await g(s,b)}finally{Z(!1)}}},K=async c=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(c),!0}catch{}try{const b=document.createElement("textarea");b.value=c,b.style.position="fixed",b.style.left="-9999px",document.body.appendChild(b),b.focus(),b.select();const k=document.execCommand("copy");return document.body.removeChild(b),k}catch{return!1}},re=async c=>{if(c.stopPropagation(),!s.error)return;await K(s.error)?(L(!0),o(l("common.copySuccess")||"Copied","success"),setTimeout(()=>L(!1),1500)):o(l("common.copyFailed")||"Copy failed","error")},be=async c=>{if(c.stopPropagation(),d(!1),!!$)try{const b=await C(s.name);if(!b||!b.success||!b.data){o((b==null?void 0:b.message)||l("common.copyFailed")||"Copy failed","error");return}const k=JSON.stringify(b.data,null,2),M=await K(k);o(M?l("common.copySuccess")||"Copied":l("common.copyFailed")||"Copy failed",M?"success":"error")}catch(b){console.error("Error copying server configuration:",b),o(l("common.copyFailed")||"Copy failed","error")}},fe=c=>{var b;if(c.stopPropagation(),(b=s.oauth)!=null&&b.authorizationUrl){const ne=window.screen.width/2-300,ie=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ne},top=${ie}`),o(l("status.oauthWindowOpened"),"info")}},Ce=async(c,b)=>{try{const{toggleTool:k}=await ge(async()=>{const{toggleTool:ne}=await Promise.resolve().then(()=>Ls);return{toggleTool:ne}},void 0,import.meta.url),M=await k(s.name,c,b);M.success?(o(l(b?"tool.enableSuccess":"tool.disableSuccess",{name:c}),"success"),a==null||a()):o(M.error||l("tool.toggleFailed"),"error")}catch(k){console.error(k),o(l("tool.toggleFailed"),"error")}},ue=async(c,b)=>{try{const{togglePrompt:k}=await ge(async()=>{const{togglePrompt:ne}=await Promise.resolve().then(()=>Xs);return{togglePrompt:ne}},void 0,import.meta.url),M=await k(s.name,c,b);M.success?(o(l(b?"tool.enableSuccess":"tool.disableSuccess",{name:c}),"success"),a==null||a()):o(M.error||l("tool.toggleFailed"),"error")}catch(k){console.error(k),o(l("tool.toggleFailed"),"error")}},ms=async(c,b)=>{try{const{toggleResource:k}=await ge(async()=>{const{toggleResource:ne}=await import("./resourceService-Bg941cnv.js");return{toggleResource:ne}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),M=await k(s.name,c,b);M.success?(o(l(b?"tool.enableSuccess":"tool.disableSuccess",{name:c}),"success"),a==null||a()):o(M.error||l("tool.toggleFailed"),"error")}catch(k){console.error(k),o(l("tool.toggleFailed"),"error")}},ps=(c,b,k)=>{o(k!=null&&k.restored?l("tool.restoreDefaultSuccess"):l("tool.descriptionUpdateSuccess"),"success"),a==null||a()},xs=(c,b,k)=>{o(k!=null&&k.restored?l("prompt.restoreDefaultSuccess"):l("prompt.descriptionUpdateSuccess"),"success"),a==null||a()},hs=async(c,b,k)=>{try{const{updateResourceDescription:M,resetResourceDescription:ne}=await ge(async()=>{const{updateResourceDescription:fs,resetResourceDescription:gs}=await import("./resourceService-Bg941cnv.js");return{updateResourceDescription:fs,resetResourceDescription:gs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ie=k!=null&&k.restored?await ne(s.name,c):await M(s.name,c,b);ie.success?(o(k!=null&&k.restored?l("builtinResources.restoreDefaultSuccess"):l("builtinResources.descriptionUpdateSuccess"),"success"),a==null||a()):o(ie.error||(k!=null&&k.restored?l("builtinResources.restoreDefaultFailed"):l("builtinResources.descriptionUpdateFailed")),"error")}catch(M){console.error(M),o(k!=null&&k.restored?l("builtinResources.restoreDefaultFailed"):l("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var k;const c=s.config;if(!c)return"";if(c.url)return c.url;const b=[];return c.command&&b.push(c.command),(k=c.args)!=null&&k.length&&b.push(...c.args),b.join(" ")})();const $e=`${I}/mcp/${s.name}`,Fe=(c,b)=>l(c,b),ce=st(Fe,s.visibility??((Le=s.config)==null?void 0:Le.visibility)),bs=tt(Fe,ce.value),Ie=[{key:"tools",icon:Ds,total:G,enabled:S,label:l("server.tools")},{key:"prompts",icon:Ps,total:W,enabled:te,label:l("server.prompts")},{key:"resources",icon:zs,total:le,enabled:P,label:l("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>E(!w),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ke,{size:12,style:{color:"var(--hub-ink-3)",transform:w?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"hub-mono truncate",style:{fontSize:13.5,color:Q?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),q&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:l("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:O,children:[e.jsx("button",{onClick:c=>{c.stopPropagation(),F(b=>!b)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":l("server.viewErrorDetails"),children:e.jsx(we,{size:14})}),v&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:l("server.errorDetails")}),e.jsx("button",{onClick:re,className:"hub-icon-btn sm",title:l("common.copy"),children:R?e.jsx(me,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>F(!1),className:"hub-icon-btn sm","aria-label":l("app.closeButton"),children:e.jsx(Se,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),((We=s.config)==null?void 0:We.description)&&e.jsx("div",{className:"text-[11.5px] truncate",style:{color:"var(--hub-ink-3)",marginTop:1},title:s.config.description,children:s.config.description})]})]}),e.jsx("div",{className:"min-w-0",children:e.jsx(Ss,{status:s.status,enabled:s.enabled,onAuthClick:fe,className:"hub-server-card-status"})}),e.jsx("div",{className:"min-w-0",children:(qe=s.config)!=null&&qe.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Xe(l,s.config.type)??void 0,children:Xe(l,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:c=>c.stopPropagation(),children:$&&g?e.jsx(Ke,{isLoading:B,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ce.value,onChange:he,disabled:B,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":l("server.visibility","Visibility"),title:ce.longLabel,children:bs.map(c=>e.jsx("option",{value:c.value,disabled:c.disabled,children:c.label},c.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${ce.className}`,title:ce.longLabel,children:ce.shortLabel})}),Ie.map(({key:c,icon:b,total:k,enabled:M,label:ne})=>{const ie=k===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${ie?"is-empty":""}`,title:`${ne}: ${M}/${k}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(Ge,{icon:b})}),e.jsx("span",{className:"hub-server-capability-value",children:ie?"0":`${M}/${k}`})]},c)}),r&&r.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${l("cost.exposed")} ${r.exposed} / ${l("cost.gross")} ${r.gross} · ${l("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ae(r.exposed),"/",ae(r.gross)]})]}):r?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:l("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:c=>c.stopPropagation(),children:e.jsx(Ke,{isLoading:T,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ne,{checked:Q,onCheckedChange:ee,disabled:T||!$,size:"compact","aria-label":`${l(Q?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:X,children:[$&&e.jsx("button",{className:"hub-icon-btn",onClick:c=>{c.stopPropagation(),d(b=>!b)},"aria-label":"More",children:e.jsx(Ts,{size:14})}),$&&p&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:c=>c.stopPropagation(),children:[e.jsxs("button",{onClick:c=>{c.stopPropagation(),d(!1),n(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx($s,{size:13})," ",l("server.edit")]}),e.jsxs("button",{onClick:be,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",l("server.copy")]}),y&&e.jsxs("button",{onClick:pe,disabled:x||T||!Q,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(je,{size:13})," ",l("server.reload")]}),D&&Y&&e.jsxs("button",{onClick:c=>{c.stopPropagation(),d(!1),!(!$||N||!Q)&&J(!0)},disabled:N||T||!Q,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(Fs,{size:13})," ",l("server.reinstall")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:c=>{c.stopPropagation(),d(!1),U(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(Is,{size:13})," ",l("server.delete")]})]})]})]}),w&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Ie.map(c=>{const b=f===c.key,k=c.icon;return e.jsxs("button",{onClick:()=>V(b?null:c.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:b?"var(--hub-surface)":"transparent",border:"1px solid "+(b?"var(--hub-line)":"transparent"),color:b?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(Ge,{icon:k}),e.jsx("span",{children:c.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:c.total===0?"0":`${c.enabled}/${c.total}`})]},c.key)}),r&&r.connected&&e.jsxs("button",{onClick:()=>V(f==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:f==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(f==="cost"?"var(--hub-line)":"transparent"),color:f==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:l("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:l("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ae(r.exposed),"/",ae(r.gross)]})]}),e.jsx("div",{className:"ml-auto max-w-full flex-shrink-0",children:e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:$e,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async c=>{c.stopPropagation();const b=await K($e);o(b?l("common.copySuccess")||"Copied":l("common.copyFailed")||"Failed",b?"success":"error")},title:l("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),f==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((c,b)=>b.cost-c.cost).map(c=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:c.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:c.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ae(c.cost)})]},`${c.kind}:${c.name}`))}),f==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((c,b)=>{var k;return e.jsx(Hs,{server:s.name,tool:c,readOnly:!$,onToggle:Ce,onDescriptionUpdate:ps,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="tool"&&M.name===c.name))==null?void 0:k.cost},b)})}),f==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((c,b)=>{var k;return e.jsx(Ys,{server:s.name,prompt:c,readOnly:!$,onToggle:ue,onDescriptionUpdate:xs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="prompt"&&M.name===c.name))==null?void 0:k.cost},b)})}),f==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:l("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((c,b)=>{var k;return e.jsx(Zs,{resource:c,readOnly:!$,onToggle:ms,onDescriptionUpdate:hs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="resource"&&M.name===c.uri))==null?void 0:k.cost},`${c.uri}-${b}`)})})})]})]}),e.jsx(Vs,{isOpen:A,onClose:()=>U(!1),onConfirm:()=>{t(s.name),U(!1)},serverName:s.name}),e.jsx(rs,{isOpen:_,onClose:()=>J(!1),onConfirm:()=>{J(!1),xe()},title:l("server.reinstall"),message:l("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:l("server.reinstall"),variant:"warning"})]})},ot=({onAdd:s})=>{const{t:r}=se(),[t,n]=u.useState(!1),[h,g]=u.useState(null),[a,y]=u.useState(!1),[D,l]=u.useState(null),[o,C]=u.useState([]),z=()=>{n(!t),g(null),y(!1),l(null)},j=async()=>{D&&(await I(D),y(!1),l(null))},I=async E=>{try{g(null);const f=await oe("/servers",E);if(!f.success){f&&f.message?g(f.message):g(r("server.addError"));return}n(!1),s()}catch(f){console.error("Error adding server:",f),navigator.onLine?f instanceof TypeError&&(f.message.includes("NetworkError")||f.message.includes("Failed to fetch"))?g(r("errors.serverConnection")):g(r("errors.serverAdd")):g(r("errors.network"))}},w=async E=>{try{const f=Js(E);f.length>0?(C(f),l(E),y(!0)):await I(E)}catch(f){console.error("Error processing server submission:",f),g(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:z,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(ns,{onSubmit:w,onCancel:z,modalTitle:r("server.addServer"),formError:h})}),a&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:o.map((E,f)=>e.jsxs("li",{className:"font-mono",children:["$",`{${E}}`]},f))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{y(!1),l(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:j,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},it=({server:s,onEdit:r,onCancel:t})=>{const{t:n}=se(),[h,g]=u.useState(null),a=async y=>{try{g(null);const D=encodeURIComponent(s.name),l=y.name&&y.name!==s.name,o={config:y.config,...l?{newName:y.name}:{}},C=await ve(`/servers/${D}`,o);if(!C.success){C&&C.message?g(C.message):g(n("server.updateError",{serverName:s.name}));return}r()}catch(D){console.error("Error updating server:",D),navigator.onLine?D instanceof TypeError&&(D.message.includes("NetworkError")||D.message.includes("Failed to fetch"))?g(n("errors.serverConnection")):g(n("errors.serverUpdate",{serverName:s.name})):g(n("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(ns,{onSubmit:a,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:h})})},lt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[n,h]=u.useState(!1),[g,a]=u.useState(!1),[y,D]=u.useState(null),[l,o]=u.useState(null),[C,z]=u.useState(!1),[j,I]=u.useState(null),[w,E]=u.useState(""),[f,V]=u.useState(!1),[A,U]=u.useState(""),_=i=>{i.preventDefault(),h(!0)},J=i=>{i.preventDefault(),h(!1)},T=i=>{i.preventDefault(),h(!1);const p=i.dataTransfer.files;if(p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),D(null)):D(t("mcpb.invalidFileType"))}},H=i=>{const p=i.target.files;if(p&&p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),D(null)):D(t("mcpb.invalidFileType"))}},B=async()=>{if(!l){D(t("mcpb.noFileSelected"));return}a(!0),D(null);try{const i=new FormData;i.append("mcpbFile",l);const p=await Ns(ws("/mcpb/upload"),{method:"POST",body:i}),d=await p.json();if(!p.ok)throw new Error(d.message||`HTTP error! Status: ${p.status}`);if(d.success&&d.data)I(d.data.manifest),E(d.data.extractDir),z(!0);else throw new Error(d.message||t("mcpb.uploadFailed"))}catch(i){console.error("MCPB upload error:",i),D(i instanceof Error?i.message:t("mcpb.uploadFailed"))}finally{a(!1)}},Z=async(i,p=!1)=>{var d;a(!0),D(null);try{const v=N(j,w,i);if(!p){const R=await vs("/servers");if(R.success&&((d=R.data)==null?void 0:d.find(X=>X.name===i))){U(i),V(!0),a(!1);return}}let F;if(p?F=await ve(`/servers/${encodeURIComponent(i)}`,{name:i,config:v}):F=await oe("/servers",{name:i,config:v}),F.success)s(v);else throw new Error(F.message||t("mcpb.installFailed"))}catch(v){console.error("MCPB install error:",v),D(v instanceof Error?v.message:t("mcpb.installFailed")),a(!1)}},x=()=>{V(!1),A&&Z(A,!0)},m=()=>{V(!1),U(""),a(!1)},N=(i,p,d)=>{var R;const v=((R=i.server)==null?void 0:R.mcp_config)||{},F={type:"stdio",command:v.command||"node",args:(v.args||[]).map(L=>L.replace("${__dirname}",p))};return v.env&&Object.keys(v.env).length>0&&(F.env={...v.env},Object.keys(F.env).forEach(L=>{typeof F.env[L]=="string"&&(F.env[L]=F.env[L].replace("${__dirname}",p))})),F};return C&&j?e.jsxs(e.Fragment,{children:[e.jsx(rs,{isOpen:f,onClose:m,onConfirm:x,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:A}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${f?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),y&&e.jsx("div",{className:"mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700",children:y})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg",children:[e.jsx("h3",{className:"font-medium text-gray-900 mb-2",children:t("mcpb.extensionInfo")}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.name"),":"]})," ",j.display_name||j.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",j.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",j.description]}),j.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",j.author.name]}),j.tools&&j.tools.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.tools"),":"]}),e.jsx("ul",{className:"list-disc list-inside ml-4",children:j.tools.map((i,p)=>e.jsxs("li",{children:[i.name," - ",i.description]},p))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:j.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const i=document.getElementById("serverName"),p=(i==null?void 0:i.value.trim())||j.name;Z(p)},disabled:g,className:"hub-btn primary",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),y&&e.jsx("div",{className:"mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700",children:y})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${n?"border-blue-500 bg-blue-50":l?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:_,onDragLeave:J,onDrop:T,children:[l?e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-green-200",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm text-gray-900 font-medium",children:l.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(l.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:H,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:B,disabled:!l||g,className:"hub-btn primary flex items-center",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},ct=s=>Object.entries(s.mcpServers).map(([r,t])=>{const n={};return t.type==="sse"||t.type==="streamable-http"?(n.type=t.type,n.url=t.url,t.headers&&(n.headers=t.headers)):t.type==="openapi"?(n.type="openapi",n.openapi=t.openapi):(n.type="stdio",n.command=t.command,n.args=t.args||[],t.env&&(n.env=t.env),t.options&&(n.options=t.options)),{name:r,config:n}}),dt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[n,h]=u.useState(""),[g,a]=u.useState(null),[y,D]=u.useState(!1),[l,o]=u.useState(null),C=`{
7
+ "mcpServers": {
8
+ "stdio-server-example": {
9
+ "command": "npx",
10
+ "args": ["-y", "mcp-server-example"]
11
+ },
12
+ "sse-server-example": {
13
+ "type": "sse",
14
+ "url": "http://localhost:3000"
15
+ },
16
+ "http-server-example": {
17
+ "type": "streamable-http",
18
+ "url": "http://localhost:3001",
19
+ "headers": {
20
+ "Content-Type": "application/json",
21
+ "Authorization": "Bearer your-token"
22
+ }
23
+ },
24
+ "openapi-server-example": {
25
+ "type": "openapi",
26
+ "openapi": {
27
+ "url": "https://petstore.swagger.io/v2/swagger.json"
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ Supports: STDIO, SSE, HTTP (streamable-http), OpenAPI
34
+ All servers will be imported in a single efficient batch operation.`,z=w=>{try{const E=JSON.parse(w.trim());return!E.mcpServers||typeof E.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):E}catch{return a(t("jsonImport.parseError")),null}},j=()=>{a(null);const w=z(n);w&&o(ct(w))},I=async()=>{if(l){D(!0),a(null);try{const w=await oe("/servers/batch",{servers:l});if(w.success&&w.data){const{successCount:E,failureCount:f,results:V}=w.data;if(f>0){const A=V.filter(U=>!U.success).map(U=>`${U.name}: ${U.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:E,total:l.length})+`
35
+ `+A.join(`
36
+ `))}E>0&&s()}else a(w.message||t("jsonImport.importFailed"))}catch(w){console.error("Import error:",w),a(t("jsonImport.importFailed"))}finally{D(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),g&&e.jsx("div",{className:"mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 whitespace-pre-wrap",children:g})}),l?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-3",children:t("jsonImport.previewTitle")}),e.jsx("div",{className:"space-y-3",children:l.map((w,E)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:w.name}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm text-gray-600",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.type"),":"]})," ",w.config.type||"stdio"]}),w.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",w.config.command]}),w.config.args&&w.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",w.config.args.join(" ")]}),w.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",w.config.url]}),w.config.env&&Object.keys(w.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(w.config.env).join(", ")]}),w.config.headers&&Object.keys(w.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(w.config.headers).join(", ")]})]})]})})},E))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>o(null),disabled:y,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:I,disabled:y,className:"hub-btn primary",children:y?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:n,onChange:w=>h(w.target.value),className:"w-full h-96 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-sm",placeholder:C}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:j,disabled:!n.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},ut=s=>({all:s.length,online:s.filter(r=>r.status==="connected").length,issues:s.filter(r=>r.status!=="connected"&&r.enabled!==!1).length,disabled:s.filter(r=>r.enabled===!1).length}),mt=(s,r,t="")=>{const n=t.trim().toLowerCase();return s.filter(h=>{var a,y;return r==="online"&&h.status!=="connected"||r==="issues"&&(h.status==="connected"||h.enabled===!1)||r==="disabled"&&h.enabled!==!1?!1:n?(h.name+" "+(((a=h.config)==null?void 0:a.description)||"")+" "+(((y=h.tools)==null?void 0:y.map(D=>D.name).join(" "))||"")).toLowerCase().includes(n):!0})},St=()=>{const{t:s}=se(),r=ys(),{servers:t,allServers:n,error:h,setError:g,isLoading:a,pagination:y,currentPage:D,serversPerPage:l,setCurrentPage:o,setServersPerPage:C,handleServerAdd:z,handleServerEdit:j,handleServerRemove:I,handleServerToggle:w,handleServerVisibilityChange:E,handleServerReload:f,handleServerReinstall:V,triggerRefresh:A}=ks({refreshOnMount:!0}),{serverCosts:U,refetch:_}=Cs();u.useEffect(()=>{_()},[t,_]);const[J,T]=u.useState(null),[H,B]=u.useState(!1),[Z,x]=u.useState(!1),[m,N]=u.useState(!1),[i,p]=u.useState("all"),[d,v]=u.useState(""),F=u.useMemo(()=>ut(n),[n]),R=u.useMemo(()=>mt(t,i,d),[t,i,d]),L=async O=>{const G=await j(O);G&&T(G)},X=async()=>{B(!0);try{A(),await new Promise(O=>setTimeout(O,400))}finally{B(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("pages.servers.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:F.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:F.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:F.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>r("/market"),children:[e.jsx(Rs,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>N(!0),children:[e.jsx(_s,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>x(!0),children:[e.jsx(Os,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:X,disabled:H,"aria-label":s("common.refresh"),children:[e.jsx(je,{size:13,className:H?"animate-spin":""}),s("common.refresh")]}),e.jsx(ot,{onAdd:z})]})]}),h&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(we,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:h})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>g(null),"aria-label":s("app.closeButton"),children:e.jsx(Se,{size:13})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-4 flex-wrap",children:[e.jsx("div",{className:"hub-card flex items-center",style:{padding:2,borderRadius:7,background:"var(--hub-surface)"},children:[["all",s("common.all")||"All",F.all],["online",s("status.online"),F.online],["issues",s("common.inactive")||"Issues",F.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",F.disabled]].map(([O,G,S])=>e.jsxs("button",{onClick:()=>p(O),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:i===O?"var(--hub-bg-2)":"transparent",color:i===O?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(i===O?"var(--hub-line)":"transparent")},children:[G,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:S})]},O))}),e.jsxs("div",{className:"hub-card flex items-center gap-2 px-2.5 flex-1",style:{height:30,background:"var(--hub-surface)",maxWidth:360},children:[e.jsx(As,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:d,onChange:O=>v(O.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),d&&e.jsx("button",{onClick:()=>v(""),className:"hub-icon-btn sm",children:e.jsx(Se,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[R.length,"/",t.length]})]}),a&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(je,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):R.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:e.jsx("p",{children:t.length===0?s("app.noServers"):s("market.noServers")})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col",children:R.map(O=>e.jsx(at,{server:O,cost:U.find(G=>G.name===O.name),onRemove:I,onEdit:L,onToggle:w,onVisibilityChange:E,onRefresh:A,onReload:f,onReinstall:V},O.name))}),e.jsxs("div",{className:"flex items-center mt-4 text-[12px]",style:{color:"var(--hub-ink-3)"},children:[e.jsx("div",{className:"flex-[2]",children:y?s("common.showing",{start:(y.page-1)*y.limit+1,end:Math.min(y.page*y.limit,y.total),total:y.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:y&&y.totalPages>1&&e.jsx(Us,{currentPage:D,totalPages:y.totalPages,onPageChange:o,disabled:a})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s("common.itemsPerPage"),":"]}),e.jsxs("select",{id:"perPage",value:l,onChange:O=>C(Number(O.target.value)),disabled:a,className:"hub-input",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})]}),J&&e.jsx(it,{server:J,onEdit:()=>{T(null),A()},onCancel:()=>T(null)}),Z&&e.jsx(lt,{onSuccess:()=>{x(!1),A()},onCancel:()=>x(!1)}),m&&e.jsx(dt,{onSuccess:()=>{N(!1),A()},onCancel:()=>N(!1)})]})};export{St as default};
37
+ //# sourceMappingURL=ServersPage-xt7QkwjZ.js.map