@samanhappy/mcphub 1.0.39 → 1.0.41

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 (140) hide show
  1. package/dist/betterAuth.js +23 -0
  2. package/dist/betterAuth.js.map +1 -1
  3. package/dist/controllers/mcpbController.js +8 -0
  4. package/dist/controllers/mcpbController.js.map +1 -1
  5. package/dist/controllers/oauthCallbackController.js +85 -43
  6. package/dist/controllers/oauthCallbackController.js.map +1 -1
  7. package/dist/controllers/serverController.js +52 -7
  8. package/dist/controllers/serverController.js.map +1 -1
  9. package/dist/controllers/smartRoutingController.js +408 -0
  10. package/dist/controllers/smartRoutingController.js.map +1 -0
  11. package/dist/dao/CredentialBindingDao.js +5 -0
  12. package/dist/dao/CredentialBindingDao.js.map +1 -1
  13. package/dist/dao/CredentialBindingDaoDbImpl.js +7 -0
  14. package/dist/dao/CredentialBindingDaoDbImpl.js.map +1 -1
  15. package/dist/db/connection.js +38 -11
  16. package/dist/db/connection.js.map +1 -1
  17. package/dist/db/groupSchema.js +2 -2
  18. package/dist/db/groupSchema.js.map +1 -1
  19. package/dist/db/repositories/ActivityRepository.js +2 -2
  20. package/dist/db/repositories/ActivityRepository.js.map +1 -1
  21. package/dist/db/repositories/BaseRepository.js +4 -1
  22. package/dist/db/repositories/BaseRepository.js.map +1 -1
  23. package/dist/db/repositories/BearerKeyRepository.js +3 -1
  24. package/dist/db/repositories/BearerKeyRepository.js.map +1 -1
  25. package/dist/db/repositories/BuiltinPromptRepository.js +2 -2
  26. package/dist/db/repositories/BuiltinPromptRepository.js.map +1 -1
  27. package/dist/db/repositories/BuiltinResourceRepository.js +2 -2
  28. package/dist/db/repositories/BuiltinResourceRepository.js.map +1 -1
  29. package/dist/db/repositories/GroupRepository.js +2 -2
  30. package/dist/db/repositories/GroupRepository.js.map +1 -1
  31. package/dist/db/repositories/OAuthClientRepository.js +2 -2
  32. package/dist/db/repositories/OAuthClientRepository.js.map +1 -1
  33. package/dist/db/repositories/OAuthTokenRepository.js +3 -1
  34. package/dist/db/repositories/OAuthTokenRepository.js.map +1 -1
  35. package/dist/db/repositories/ServerRepository.js +2 -2
  36. package/dist/db/repositories/ServerRepository.js.map +1 -1
  37. package/dist/db/repositories/UserConfigRepository.js +2 -2
  38. package/dist/db/repositories/UserConfigRepository.js.map +1 -1
  39. package/dist/db/repositories/UserRepository.js +3 -1
  40. package/dist/db/repositories/UserRepository.js.map +1 -1
  41. package/dist/middlewares/auth.js +1 -1
  42. package/dist/middlewares/auth.js.map +1 -1
  43. package/dist/middlewares/index.js +18 -8
  44. package/dist/middlewares/index.js.map +1 -1
  45. package/dist/routes/index.js +12 -2
  46. package/dist/routes/index.js.map +1 -1
  47. package/dist/services/betterAuthConfig.js +19 -0
  48. package/dist/services/betterAuthConfig.js.map +1 -1
  49. package/dist/services/mcpOAuthProvider.js +7 -0
  50. package/dist/services/mcpOAuthProvider.js.map +1 -1
  51. package/dist/services/mcpService.js +99 -18
  52. package/dist/services/mcpService.js.map +1 -1
  53. package/dist/services/principalRuntimeService.js +1 -3
  54. package/dist/services/principalRuntimeService.js.map +1 -1
  55. package/dist/services/vectorSearchService.js +40 -17
  56. package/dist/services/vectorSearchService.js.map +1 -1
  57. package/dist/utils/oauthIssuer.js +15 -1
  58. package/dist/utils/oauthIssuer.js.map +1 -1
  59. package/dist/utils/rateLimit.js +20 -2
  60. package/dist/utils/rateLimit.js.map +1 -1
  61. package/dist/utils/requireAdmin.js +8 -0
  62. package/dist/utils/requireAdmin.js.map +1 -1
  63. package/dist/utils/serialization.js +14 -2
  64. package/dist/utils/serialization.js.map +1 -1
  65. package/dist/utils/serverConfigPersistence.js +12 -0
  66. package/dist/utils/serverConfigPersistence.js.map +1 -1
  67. package/dist/utils/smartRouting.js +69 -27
  68. package/dist/utils/smartRouting.js.map +1 -1
  69. package/dist/utils/upstreamError.js +60 -0
  70. package/dist/utils/upstreamError.js.map +1 -0
  71. package/dist/utils/withTimeout.js +25 -0
  72. package/dist/utils/withTimeout.js.map +1 -0
  73. package/frontend/dist/assets/{ActivityPage-CDKSVr2I.js → ActivityPage-adLbSuxT.js} +2 -2
  74. package/frontend/dist/assets/{ActivityPage-CDKSVr2I.js.map → ActivityPage-adLbSuxT.js.map} +1 -1
  75. package/frontend/dist/assets/CopyClientConfigDialog-hRNdG_Hz.js +4 -0
  76. package/frontend/dist/assets/CopyClientConfigDialog-hRNdG_Hz.js.map +1 -0
  77. package/frontend/dist/assets/{CredentialsPage-DMJE4uT2.js → CredentialsPage-BSogppb6.js} +2 -2
  78. package/frontend/dist/assets/{CredentialsPage-DMJE4uT2.js.map → CredentialsPage-BSogppb6.js.map} +1 -1
  79. package/frontend/dist/assets/Dashboard-BttcAnP2.js +2 -0
  80. package/frontend/dist/assets/{Dashboard-Dh_39img.js.map → Dashboard-BttcAnP2.js.map} +1 -1
  81. package/frontend/dist/assets/{EndpointCopy-CQmwGXbD.js → EndpointCopy-CNhtxQdx.js} +2 -2
  82. package/frontend/dist/assets/{EndpointCopy-CQmwGXbD.js.map → EndpointCopy-CNhtxQdx.js.map} +1 -1
  83. package/frontend/dist/assets/GroupsPage-CQA7x2cz.js +33 -0
  84. package/frontend/dist/assets/{GroupsPage-BqscWSfR.js.map → GroupsPage-CQA7x2cz.js.map} +1 -1
  85. package/frontend/dist/assets/{LoginPage-DcrwvgS6.js → LoginPage-C4qBJzYk.js} +2 -2
  86. package/frontend/dist/assets/{LoginPage-DcrwvgS6.js.map → LoginPage-C4qBJzYk.js.map} +1 -1
  87. package/frontend/dist/assets/{LogsPage--Blkr-Ni.js → LogsPage-BXHqsBa0.js} +2 -2
  88. package/frontend/dist/assets/{LogsPage--Blkr-Ni.js.map → LogsPage-BXHqsBa0.js.map} +1 -1
  89. package/frontend/dist/assets/MarketPage-C2q7W2an.js +2 -0
  90. package/frontend/dist/assets/MarketPage-C2q7W2an.js.map +1 -0
  91. package/frontend/dist/assets/{OAuthConsentPage-DCKZIMzE.js → OAuthConsentPage-D-UU5XNF.js} +2 -2
  92. package/frontend/dist/assets/{OAuthConsentPage-DCKZIMzE.js.map → OAuthConsentPage-D-UU5XNF.js.map} +1 -1
  93. package/frontend/dist/assets/{PromptsPage-DoVmnVnp.js → PromptsPage-2BBvSosU.js} +2 -2
  94. package/frontend/dist/assets/{PromptsPage-DoVmnVnp.js.map → PromptsPage-2BBvSosU.js.map} +1 -1
  95. package/frontend/dist/assets/{ResourcesPage-B8udCQQR.js → ResourcesPage-DLVYyIm0.js} +2 -2
  96. package/frontend/dist/assets/{ResourcesPage-B8udCQQR.js.map → ResourcesPage-DLVYyIm0.js.map} +1 -1
  97. package/frontend/dist/assets/ServersPage-Cx9zIvKw.js +39 -0
  98. package/frontend/dist/assets/ServersPage-Cx9zIvKw.js.map +1 -0
  99. package/frontend/dist/assets/SettingsPage-pZCOi8NF.js +12 -0
  100. package/frontend/dist/assets/SettingsPage-pZCOi8NF.js.map +1 -0
  101. package/frontend/dist/assets/{StatusDot-DgDU3plH.js → StatusDot-CAv_zsld.js} +2 -2
  102. package/frontend/dist/assets/{StatusDot-DgDU3plH.js.map → StatusDot-CAv_zsld.js.map} +1 -1
  103. package/frontend/dist/assets/{ToggleGroup-11yhmcwY.js → ToggleGroup-ffEOMWal.js} +2 -2
  104. package/frontend/dist/assets/{ToggleGroup-11yhmcwY.js.map → ToggleGroup-ffEOMWal.js.map} +1 -1
  105. package/frontend/dist/assets/{UsersPage-BqPEkoIX.js → UsersPage-Cx6EDM_s.js} +2 -2
  106. package/frontend/dist/assets/{UsersPage-BqPEkoIX.js.map → UsersPage-Cx6EDM_s.js.map} +1 -1
  107. package/frontend/dist/assets/clipboard-_snued0J.js +2 -0
  108. package/frontend/dist/assets/clipboard-_snued0J.js.map +1 -0
  109. package/frontend/dist/assets/{icons-vendor-Bk5sng-h.js → icons-vendor-CNEaJWqW.js} +78 -63
  110. package/frontend/dist/assets/icons-vendor-CNEaJWqW.js.map +1 -0
  111. package/frontend/dist/assets/index-Dt8f_hd5.js +3 -0
  112. package/frontend/dist/assets/index-Dt8f_hd5.js.map +1 -0
  113. package/frontend/dist/assets/index-ru-OAIcF.css +1 -0
  114. package/frontend/dist/assets/{resourceService-D-PRt7tB.js → resourceService-BCl2XrNf.js} +2 -2
  115. package/frontend/dist/assets/{resourceService-D-PRt7tB.js.map → resourceService-BCl2XrNf.js.map} +1 -1
  116. package/frontend/dist/assets/{useCostData-B-uSfiuA.js → useCostData-D3JNFGsT.js} +2 -2
  117. package/frontend/dist/assets/{useCostData-B-uSfiuA.js.map → useCostData-D3JNFGsT.js.map} +1 -1
  118. package/frontend/dist/assets/{variableDetection-B7Ko56CL.js → variableDetection-CGuC1br1.js} +3 -3
  119. package/frontend/dist/assets/variableDetection-CGuC1br1.js.map +1 -0
  120. package/frontend/dist/index.html +3 -3
  121. package/package.json +4 -1
  122. package/frontend/dist/assets/CopyClientConfigDialog-DYiucK0d.js +0 -4
  123. package/frontend/dist/assets/CopyClientConfigDialog-DYiucK0d.js.map +0 -1
  124. package/frontend/dist/assets/Dashboard-Dh_39img.js +0 -2
  125. package/frontend/dist/assets/GroupsPage-BqscWSfR.js +0 -33
  126. package/frontend/dist/assets/MarketPage-DWv18j4V.js +0 -3
  127. package/frontend/dist/assets/MarketPage-DWv18j4V.js.map +0 -1
  128. package/frontend/dist/assets/ServersPage-OLpH1K1I.js +0 -39
  129. package/frontend/dist/assets/ServersPage-OLpH1K1I.js.map +0 -1
  130. package/frontend/dist/assets/SettingsPage-DlK0Jcta.js +0 -12
  131. package/frontend/dist/assets/SettingsPage-DlK0Jcta.js.map +0 -1
  132. package/frontend/dist/assets/clipboard-BukcCPLt.js +0 -2
  133. package/frontend/dist/assets/clipboard-BukcCPLt.js.map +0 -1
  134. package/frontend/dist/assets/icons-vendor-Bk5sng-h.js.map +0 -1
  135. package/frontend/dist/assets/index-D4Vy78bV.css +0 -1
  136. package/frontend/dist/assets/index-DhzWX9nb.js +0 -3
  137. package/frontend/dist/assets/index-DhzWX9nb.js.map +0 -1
  138. package/frontend/dist/assets/useSettingsData-Bk1AwN5F.js +0 -2
  139. package/frontend/dist/assets/useSettingsData-Bk1AwN5F.js.map +0 -1
  140. package/frontend/dist/assets/variableDetection-B7Ko56CL.js.map +0 -1
@@ -1,39 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-D-PRt7tB.js","./index-DhzWX9nb.js","./framework-vendor-_YL27Pfc.js","./i18n-vendor-BMaj5qV8.js","./icons-vendor-Bk5sng-h.js","./index-D4Vy78bV.css"])))=>i.map(i=>d[i]);
2
- import{r as d,j as e,L as _s,d as As}from"./framework-vendor-_YL27Pfc.js";import{i as ce,f as is,h as Ne,j as De,u as Ms,_ as ve,e as Vs,k as Us,l as Bs}from"./index-DhzWX9nb.js";import{f as le}from"./contextCost-CilWqGWT.js";import{S as Js}from"./StatusDot-DgDU3plH.js";import{u as we}from"./useSettingsData-Bk1AwN5F.js";import{S as ke}from"./ToggleGroup-11yhmcwY.js";import{u as re}from"./i18n-vendor-BMaj5qV8.js";import{n as ls,o as cs,l as Ce,p as Ls,C as fe,q as be,r as Te,s as ds,t as us,u as ze,m as Se,W as Ws,g as qs,F as Ks,X as Ee,R as me,v as Hs,w as Gs,x as Xs,y as Ys,L as Zs,T as Qs,P as et,z as st,D as tt,G as rt}from"./icons-vendor-Bk5sng-h.js";import{g as nt,C as at,t as ot}from"./CopyClientConfigDialog-DYiucK0d.js";import{D as it}from"./DeleteDialog-BYhrMGZo.js";import{C as Pe}from"./ConfirmDialog-uWBwm8J1.js";import{c as es}from"./clipboard-BukcCPLt.js";import{S as lt,a as ms,d as ct}from"./variableDetection-B7Ko56CL.js";import{P as dt}from"./Pagination-CLUvn47x.js";import{u as ut,a as mt}from"./useCostData-B-uSfiuA.js";const ps=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await ce(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},pt=async(s,n,t)=>{try{const r=await ce(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},hs=async(s,n,t)=>{try{const r=await Ne(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},xs=async(s,n)=>{var t;try{const r=await is(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ht=Object.freeze(Object.defineProperty({__proto__:null,callTool:ps,resetToolDescription:xs,toggleTool:pt,updateToolDescription:hs},Symbol.toStringTag,{value:"Module"})),bs=({schema:s,onSubmit:n,onCancel:t,loading:r=!1,storageKey:b,title:m})=>{const{t:a}=re(),[N,x]=d.useState({}),[P,c]=d.useState({}),[y,o]=d.useState(!1),[p,O]=d.useState(""),[C,D]=d.useState(""),z=d.useMemo(()=>(h=>{const k=l=>{if(typeof l=="object"&&l!==null){const f=l;return{type:f.type||"string",description:f.description,enum:f.enum,default:f.default,properties:f.properties?Object.fromEntries(Object.entries(f.properties).map(([u,w])=>[u,k(w)])):void 0,required:f.required,items:f.items?k(f.items):void 0}}return{type:"string"}};return{type:h.type,properties:h.properties?Object.fromEntries(Object.entries(h.properties).map(([l,f])=>[l,k(f)])):void 0,required:h.required}})(s),[s]);d.useEffect(()=>{const g=(k,l="")=>{const f={};return k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([u,w])=>{const $=l?`${l}.${u}`:u;w.default!==void 0?f[u]=w.default:w.type==="string"?f[u]="":w.type==="number"||w.type==="integer"?f[u]=0:w.type==="boolean"?f[u]=!1:w.type==="array"?f[u]=[]:w.type==="object"&&(w.properties?f[u]=g(w,$):f[u]={})}),f};let h=g(z);if(b)try{const k=localStorage.getItem(b);if(k){const l=JSON.parse(k);h={...h,...l}}}catch(k){console.warn("Failed to load saved form data:",k)}x(h)},[z,b]),d.useEffect(()=>{y&&Object.keys(N).length>0&&(O(JSON.stringify(N,null,2)),D(""))},[y,N]);const V=g=>{O(g),D("");try{const h=JSON.parse(g);if(x(h),b)try{localStorage.setItem(b,JSON.stringify(h))}catch(k){console.warn("Failed to save form data to localStorage:",k)}}catch{D(a("tool.invalidJsonFormat"))}},A=()=>{O(JSON.stringify(N,null,2)),D(""),o(!0)},B=()=>{if(p.trim())try{const g=JSON.parse(p);x(g),D(""),o(!1)}catch{D(a("tool.fixJsonBeforeSwitching"));return}else o(!1)},F=(g,h)=>{x(k=>{const l={...k},f=g.split(".");let u=l;for(let $=0;$<f.length-1;$++){const I=f[$];if(I==="__proto__"||I==="constructor"||I==="prototype")return k;u[I]||(u[I]={}),u=u[I]}const w=f[f.length-1];if(!w||w==="__proto__"||w==="constructor"||w==="prototype")return k;if(u[w]=h,b)try{localStorage.setItem(b,JSON.stringify(l))}catch($){console.warn("Failed to save form data to localStorage:",$)}return l}),P[g]&&c(k=>{const l={...k};return delete l[g],l})},L=()=>{const g={},h=(k,l,f="")=>{k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([u,w])=>{var W;const $=f?`${f}.${u}`:u,I=l==null?void 0:l[u];if((W=k.required)!=null&&W.includes(u)&&(I==null||I===""||Array.isArray(I)&&I.length===0)){g[$]=`${u} is required`;return}I!=null&&I!==""&&(w.type==="string"&&typeof I!="string"?g[$]=`${u} must be a string`:w.type==="number"&&typeof I!="number"?g[$]=`${u} must be a number`:w.type==="integer"&&(!Number.isInteger(I)||typeof I!="number")?g[$]=`${u} must be an integer`:w.type==="boolean"&&typeof I!="boolean"?g[$]=`${u} must be a boolean`:w.type==="array"&&Array.isArray(I)?w.items&&I.forEach((G,K)=>{var Z;((Z=w.items)==null?void 0:Z.type)==="object"&&w.items.properties&&h(w.items,G,`${$}.${K}`)}):w.type==="object"&&typeof I=="object"&&h(w,I,$))})};return h(z,N),c(g),Object.keys(g).length===0},T=g=>{g.preventDefault(),L()&&n(N)},R=(g,h)=>h.split(".").reduce((k,l)=>k==null?void 0:k[l],g),q=(g,h,k,l)=>{const f=k==null?void 0:k[g];return h.type==="string"?h.enum?e.jsxs("select",{value:f||"",onChange:u=>l(u.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")}),h.enum.map((u,w)=>e.jsx("option",{value:u,children:u},w))]}):e.jsx("input",{type:"text",value:f||"",onChange:u=>l(u.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:h.description||a("tool.enterKey",{key:g})}):h.type==="number"||h.type==="integer"?e.jsx("input",{type:"number",step:h.type==="integer"?"1":"any",value:f??"",onChange:u=>{const w=u.target.value===""?"":h.type==="integer"?parseInt(u.target.value):parseFloat(u.target.value);l(w)},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"}):h.type==="boolean"?e.jsx("input",{type:"checkbox",checked:f||!1,onChange:u=>l(u.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:f||"",onChange:u=>l(u.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:h.description||a("tool.enterKey",{key:g})})},Q=(g,h,k="")=>{var w,$,I,W,G,K,Z,v,M,se,oe,j,U,ne;const l=k?`${k}.${g}`:g,f=R(N,l),u=P[l];if(h.type==="array"){const J=R(N,l)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?($=(w=R(z,k))==null?void 0:w.required)==null?void 0:$.includes(g):(I=z.required)==null?void 0:I.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.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:[J.map((Y,te)=>{var ge,ye,je;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:te+1})}),e.jsx("button",{type:"button",onClick:()=>{const X=[...J];X.splice(te,1),F(l,X)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((ge=h.items)==null?void 0:ge.type)==="string"&&h.items.enum?e.jsxs("select",{value:Y||"",onChange:X=>{const ae=[...J];ae[te]=X.target.value,F(l,ae)},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")}),h.items.enum.map((X,ae)=>e.jsx("option",{value:X,children:X},ae))]}):((ye=h.items)==null?void 0:ye.type)==="object"&&h.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(h.items.properties).map(([X,ae])=>{var ie,H;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[X,((H=(ie=h.items)==null?void 0:ie.required)==null?void 0:H.includes(X))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),q(X,ae,Y,he=>{const xe=[...J];xe[te]={...xe[te],[X]:he},F(l,xe)})]},X)})}):e.jsx("input",{type:"text",value:Y||"",onChange:X=>{const ae=[...J];ae[te]=X.target.value,F(l,ae)},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:((je=h.items)==null?void 0:je.type)||"value"})})]},te)}),e.jsx("button",{type:"button",onClick:()=>{var te;const Y=((te=h.items)==null?void 0:te.type)==="object"?{}:"";F(l,[...J,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:g})})]}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l)}return h.type==="object"?h.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?(G=(W=R(z,k))==null?void 0:W.required)==null?void 0:G.includes(g):(K=z.required)==null?void 0:K.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.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(h.properties).map(([J,Y])=>Q(J,Y,l))}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?(v=(Z=R(z,k))==null?void 0:Z.required)==null?void 0:v.includes(g):(M=z.required)==null?void 0:M.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.description}),e.jsx("textarea",{value:typeof f=="object"?JSON.stringify(f,null,2):f||"{}",onChange:J=>{try{const Y=JSON.parse(J.target.value);F(l,Y)}catch{F(l,J.target.value)}},placeholder:`{
3
- "key": "value"
4
- }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${u?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):h.type==="string"?h.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?!1:(se=z.required)==null?void 0:se.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.description}),e.jsxs("select",{value:f||"",onChange:J=>F(l,J.target.value),className:`w-full border rounded-md px-3 py-2 ${u?"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")}),h.enum.map((J,Y)=>e.jsx("option",{value:J,children:J},Y))]}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?!1:(oe=z.required)==null?void 0:oe.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.description}),e.jsx("input",{type:"text",value:f||"",onChange:J=>F(l,J.target.value),className:`w-full border rounded-md px-3 py-2 ${u?"border-red":"border-gray-200"} focus:outline-none form-input`}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):h.type==="number"||h.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?!1:(j=z.required)==null?void 0:j.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.description}),e.jsx("input",{type:"number",step:h.type==="integer"?"1":"any",value:f??"",onChange:J=>{const Y=J.target.value===""?"":h.type==="integer"?parseInt(J.target.value):parseFloat(J.target.value);F(l,Y)},className:`w-full border rounded-md px-3 py-2 form-input ${u?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):h.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:f||!1,onChange:J=>F(l,J.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:[g,(k?!1:(U=z.required)==null?void 0:U.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:h.description}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[g,(k?!1:(ne=z.required)==null?void 0:ne.includes(g))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",h.type,")"]})]}),h.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:h.description}),e.jsx("input",{type:"text",value:f||"",onChange:J=>F(l,J.target.value),placeholder:a("tool.enterValue",{type:h.type}),className:`w-full border rounded-md px-3 py-2 ${u?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),u&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:u})]},l)};return z.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:m}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:B,className:`hub-btn sm ${y?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:A,className:`hub-btn sm ${y?"primary":""}`,children:a("tool.jsonMode")})]})]}),y?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:p,onChange:g=>V(g.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 ${C?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),C&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:C})]}),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 g=JSON.parse(p);n(g)}catch{D(a("tool.invalidJsonFormat"))}},disabled:r||!!C,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:T,className:"space-y-4",children:[Object.entries(z.properties||{}).map(([g,h])=>Q(g,h)),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:r,className:"hub-btn sm primary",children:a(r?"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:()=>n({}),disabled:r,className:"hub-btn primary",children:a(r?"tool.running":"tool.runTool")})]})]})},xt=({result:s,onClose:n})=>{const{t}=re(),r=s.content,b=c=>c?c.startsWith("image/")?c:`image/${c}`:"image/png",m=c=>{if(!c)return[];if(Array.isArray(c))return c.flatMap(p=>m(p));if(typeof c!="object")return[];const y=[];c.type==="image"&&c.data&&y.push({data:String(c.data),mimeType:b(c.mimeType||c.mime_type)});const o=c.image_base64||c.imageBase64||c.image_data||c.imageData||c.base64;return o&&y.push({data:String(o),mimeType:b(c.image_mimeType||c.image_mime_type||c.mimeType||c.mime_type)}),c.image&&typeof c.image=="object"&&y.push(...m(c.image)),Array.isArray(c.images)&&y.push(...m(c.images)),Array.isArray(c.content)&&y.push(...m(c.content)),y},a=c=>{const y=[];try{const O=JSON.parse(c);if(y.push(...m(O)),y.length>0)return y}catch{}const o=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let p;for(;(p=o.exec(c))!==null;){const O=`image/${p[1]==="jpg"?"jpeg":p[1]}`;y.push({data:p[2],mimeType:O})}return y},N=c=>{try{const y=JSON.parse(c),o=p=>{if(Array.isArray(p))return p.map(o);if(p&&typeof p=="object"){const O={};for(const[C,D]of Object.entries(p))typeof D=="string"&&C.toLowerCase().includes("base64")?O[C]="[base64 omitted]":O[C]=o(D);return O}return p};return JSON.stringify(o(y),null,2)}catch{return c.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},x=c=>Array.isArray(c)?c.map((y,o)=>e.jsx("div",{className:"mb-3 last:mb-0",children:P(y)},o)):P(c),P=c=>{if(typeof c=="string"){const y=a(c),o=N(c);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[y.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:y.map((p,O)=>e.jsx("img",{src:`data:${p.mimeType||"image/png"};base64,${p.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(typeof c=="object"&&c!==null){if(c.type==="text"&&c.text){const y=a(c.text),o=N(c.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[y.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:y.map((p,O)=>e.jsx("img",{src:`data:${p.mimeType||"image/png"};base64,${p.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(c.type==="image"&&c.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${c.mimeType||"image/png"};base64,${c.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const y=typeof c=="string"?JSON.parse(c):c;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(y,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(c)})})}}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(c)})})};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(ls,{size:20,className:"text-status-green"}):e.jsx(cs,{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:n,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")}),x(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(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),x(r)]}):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")})})]})})]})},pe=({title:s,onClick:n,disabled:t=!1,loading:r=!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:n,disabled:t,title:s,"aria-label":s,children:e.jsx(Ls,{size:14,className:r?"animate-spin":""})});function bt(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 ft=({tool:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:b,cost:m})=>{const{t:a}=re(),{showToast:N}=De(),{nameSeparator:x}=we(),[P,c]=d.useState(!1),[y,o]=d.useState(!1),[p,O]=d.useState(!1),[C,D]=d.useState(null),[z,V]=d.useState(!1),[A,B]=d.useState(!1),[F,L]=d.useState(s.description||""),T=d.useRef(null),R=d.useRef(null),[q,Q]=d.useState(0),[g,h]=d.useState(!1);d.useEffect(()=>{z&&T.current&&(T.current.focus(),q>0&&(T.current.style.width=`${q+20}px`))},[z,q]),d.useEffect(()=>{!z&&R.current&&Q(R.current.offsetWidth)},[z,F]),d.useEffect(()=>{L(s.description||"")},[s.description]);const k=s.name.replace(n+x,""),l=nt(s,a("tool.noDescription")),f=l.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:l.defaultDescription}):void 0,u=d.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),w=d.useCallback(()=>{localStorage.removeItem(u())},[u]),$=j=>{!t&&r&&r(s.name,j)},I=()=>{t||V(!0)},W=async()=>{if(!t)try{const j=await hs(n,s.name,F);j.success?(V(!1),b&&b(s.name,F)):(L(s.description||""),console.error("Failed to update tool description:",j.error))}catch(j){console.error("Error updating tool description:",j),L(s.description||""),V(!1)}},G=j=>{L(j.target.value)},K=async()=>{if(!t){B(!0);try{const j=await xs(n,s.name);if(j.success){const U=j.description||"";L(U),V(!1),b==null||b(s.name,U,{restored:!0})}else N(j.error||a("tool.restoreDefaultFailed"),"error")}catch(j){console.error("Error resetting tool description:",j),N(a("tool.restoreDefaultFailed"),"error")}finally{B(!1)}}},Z=j=>{j.key==="Enter"?W():j.key==="Escape"&&(L(s.description||""),V(!1))},v=async j=>{j.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),h(!0),N(a("common.copySuccess"),"success"),setTimeout(()=>h(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),h(!0),N(a("common.copySuccess"),"success"),setTimeout(()=>h(!1),2e3)}catch(ne){N(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",ne)}document.body.removeChild(U)}}catch(U){N(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},M=async j=>{O(!0);try{j=Object.fromEntries(Object.entries(j).filter(([ne,J])=>!bt(J)));const U=await ps({toolName:s.name,arguments:j},n);D(U)}catch(U){D({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{O(!1)}},se=()=>{o(!1),w(),D(null)},oe=()=>{D(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:j=>{j.stopPropagation(),c(!P)},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:k}),e.jsx("button",{className:"hub-icon-btn sm",onClick:v,title:a("common.copy"),children:g?e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(be,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:F,onChange:G,onKeyDown:Z,onClick:j=>j.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:j=>{j.stopPropagation(),W()},disabled:A,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:a("tool.restoreDefault"),onClick:j=>{j.stopPropagation(),K()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:R,title:f,children:l.currentDescription}),l.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:f,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:j=>{j.stopPropagation(),I()},children:e.jsx(Te,{size:12})}),e.jsx(pe,{title:a("tool.restoreDefault"),onClick:j=>{j.stopPropagation(),K()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[m!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",le(m)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:j=>j.stopPropagation(),children:e.jsx(ke,{checked:s.enabled??!0,onCheckedChange:$,disabled:p||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${k}`})}),e.jsxs("button",{onClick:j=>{j.stopPropagation(),c(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:p||!s.enabled,children:[p?e.jsx(ds,{size:12,className:"animate-spin"}):e.jsx(us,{size:12}),e.jsx("span",{children:a(p?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ze,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[l.hasDescriptionOverride&&l.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:l.defaultDescription})]}),!y&&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)})]}),y&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(bs,{schema:s.inputSchema||{type:"object"},onSubmit:M,onCancel:se,loading:p,storageKey:u(),title:a("tool.runToolWithName",{name:k})}),C&&e.jsx("div",{style:{marginTop:12},children:e.jsx(xt,{result:C,onClose:oe})})]})]})]})},gt=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",r=await ce(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},fs=async(s,n)=>{try{const t=await ce(`/mcp/${encodeURIComponent(n||"")}/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:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},yt=async(s,n,t)=>{try{const r=await ce(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},gs=async(s,n,t)=>{try{const r=await Ne(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ys=async(s,n)=>{var t;try{const r=await is(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},jt=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:gt,getPrompt:fs,resetPromptDescription:ys,togglePrompt:yt,updatePromptDescription:gs},Symbol.toStringTag,{value:"Module"})),ss=({result:s,onClose:n})=>{const{t}=re(),r=b=>{if(typeof b=="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:b})});if(typeof b=="object"&&b!==null){if(b.description||b.messages)return e.jsxs("div",{className:"space-y-4",children:[b.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:b.description})})]}),b.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:b.messages.map((m,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:[m.role,":"]})}),typeof m.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:m.content}):typeof m.content=="object"&&m.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:m.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(m.content,null,2)})]},a))})]})]});try{const m=typeof b=="string"?JSON.parse(b):b;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(m,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(b)})})}}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(b)})})};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(ls,{size:20,className:"text-status-green"}):e.jsx(cs,{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:n,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")}),r(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(Ce,{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")})})]})})]})},vt=({prompt:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:b,cost:m})=>{const{t:a}=re(),{showToast:N}=De(),{nameSeparator:x}=we(),[P,c]=d.useState(!1),[y,o]=d.useState(!1),[p,O]=d.useState(!1),[C,D]=d.useState(null),[z,V]=d.useState(!1),[A,B]=d.useState(!1),[F,L]=d.useState(s.description||""),T=d.useRef(null),R=d.useRef(null),[q,Q]=d.useState(0);d.useEffect(()=>{z&&T.current&&(T.current.focus(),q>0&&(T.current.style.width=`${q+20}px`))},[z,q]),d.useEffect(()=>{!z&&R.current&&Q(R.current.offsetWidth)},[z,F]),d.useEffect(()=>{L(s.description||"")},[s.description]);const g=d.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),h=d.useCallback(()=>{localStorage.removeItem(g())},[g]),k=v=>{!t&&r&&r(s.name,v)},l=()=>{t||V(!0)},f=async()=>{if(!t){V(!1);try{const v=await gs(n,s.name,F);v.success?b&&b(s.name,F):(N(v.error||a("prompt.descriptionUpdateFailed"),"error"),L(s.description||""))}catch(v){console.error("Error updating prompt description:",v),N(a("prompt.descriptionUpdateFailed"),"error"),L(s.description||"")}}},u=async()=>{if(!t){B(!0);try{const v=await ys(n,s.name);if(v.success){const M=v.description||"";L(M),V(!1),b==null||b(s.name,M,{restored:!0})}else N(v.error||a("prompt.restoreDefaultFailed"),"error")}catch(v){console.error("Error resetting prompt description:",v),N(a("prompt.restoreDefaultFailed"),"error")}finally{B(!1)}}},w=v=>{L(v.target.value)},$=v=>{v.key==="Enter"?f():v.key==="Escape"&&(L(s.description||""),V(!1))},I=async v=>{O(!0);try{const M=await fs({promptName:s.name,arguments:v},n);console.log("GetPrompt result:",M),D({success:M.success,data:M.data,error:M.error})}catch(M){D({success:!1,error:M instanceof Error?M.message:"Unknown error occurred"})}finally{O(!1)}},W=()=>{o(!1),h(),D(null)},G=()=>{D(null)},K=s.name.replace(n+x,""),Z=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const v={},M=[];return s.arguments.forEach(se=>{v[se.name]={type:"string",description:se.description||""},se.required&&M.push(se.name)}),{type:"object",properties:v,required:M}};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:()=>c(!P),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:K}),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:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:F,onChange:w,onKeyDown:$,onClick:v=>v.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:v=>{v.stopPropagation(),f()},disabled:A,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:a("prompt.restoreDefault"),onClick:v=>{v.stopPropagation(),u()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:R,children:F||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:v=>{v.stopPropagation(),l()},children:e.jsx(Te,{size:12})}),e.jsx(pe,{title:a("prompt.restoreDefault"),onClick:v=>{v.stopPropagation(),u()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[m!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",le(m)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:v=>v.stopPropagation(),children:s.enabled!==void 0&&e.jsx(ke,{checked:s.enabled,onCheckedChange:k,disabled:p||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${K}`})}),e.jsxs("button",{onClick:v=>{v.stopPropagation(),c(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:p||!s.enabled,children:[p?e.jsx(ds,{size:12,className:"animate-spin"}):e.jsx(us,{size:12}),e.jsx("span",{children:a(p?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ze,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[y&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(bs,{schema:Z(),onSubmit:I,onCancel:W,loading:p,storageKey:g(),title:a("prompt.runPromptWithName",{name:K})}),C&&e.jsx("div",{style:{marginTop:12},children:e.jsx(ss,{result:C,onClose:G})})]}),!y&&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((v,M)=>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:v.name}),v.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),v.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:v.description})]}),v.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:v.title})]},M))})]}),!y&&C&&e.jsx("div",{children:e.jsx(ss,{result:C,onClose:G})})]})]})},Nt=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:r,cost:b})=>{const{t:m}=re(),[a,N]=d.useState(!1),[x,P]=d.useState(!1),[c,y]=d.useState(!1),[o,p]=d.useState(s.description||""),O=d.useRef(null),C=d.useRef(null),[D,z]=d.useState(0);d.useEffect(()=>{x&&O.current&&(O.current.focus(),D>0&&(O.current.style.width=`${D+20}px`))},[x,D]),d.useEffect(()=>{!x&&C.current&&z(C.current.offsetWidth)},[x,o]),d.useEffect(()=>{p(s.description||"")},[s.description]);const V=s.name||s.uri,A=T=>{!n&&t&&t(s.uri,T)},B=async()=>{n||(P(!1),r&&await r(s.uri,o))},F=async()=>{if(!n){y(!0);try{await(r==null?void 0:r(s.uri,"",{restored:!0})),P(!1)}finally{y(!1)}}},L=T=>{T.key==="Enter"?B():T.key==="Escape"&&(p(s.description||""),P(!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:()=>N(!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:x?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:O,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:D>0?`${D+20}px`:160,minWidth:80},value:o,onChange:T=>p(T.target.value),onKeyDown:L,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),B()},disabled:c,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:m("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),F()},disabled:c,loading:c})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:C,children:o||m("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),P(!0)},children:e.jsx(Te,{size:12})}),e.jsx(pe,{title:m("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),F()},disabled:c,loading:c})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[b!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:m("cost.estimate"),children:["Σ ",le(b)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(ke,{checked:s.enabled!==!1,onCheckedChange:A,disabled:n,size:"card","aria-label":`${m(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(Se,{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:[m("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},wt=(s,n)=>n?n.isAdmin?!0:!!(s.owner&&s.owner===n.username):!1,kt={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:"Shared",longKey:"server.visibilityGroup",longFallback:"Shared — selected users only",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)]"}},$e=s=>s==="public"||s==="group"?s:"private",Ct=(s,n)=>{const t=$e(n),r=kt[t];return{value:t,shortLabel:s(r.shortKey,{defaultValue:r.shortFallback}),longLabel:s(r.longKey,{defaultValue:r.longFallback}),className:r.className}},St=(s,n)=>{const t=$e(n),r=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&r.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Shared"}),disabled:!0}),r.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),r},ts=({isLoading:s,children:n,className:t,overlayStyle:r,spinnerSize:b=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:n}),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,...r},children:e.jsx(me,{size:b,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),rs=({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"})}),ns=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,Et="text/html;profile=mcp-app",as=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Pt=s=>{var n,t;return!!((n=s.tools)!=null&&n.some(r=>as(r._meta))||(t=s.resources)!=null&&t.some(r=>{var b;return((b=r.uri)==null?void 0:b.startsWith("ui://"))||r.mimeType===Et||as(r._meta)}))},Dt=({server:s,cost:n,onRemove:t,onEdit:r,onDuplicate:b,isDuplicating:m=!1,onToggle:a,onVisibilityChange:N,onRefresh:x,onReload:P,onReinstall:c,onOAuthDisconnect:y})=>{var Ae,Me,Ve,Ue,Be,Je,Le,We,qe,Ke,He,Ge,Xe,Ye,Ze,Qe;const{t:o}=re(),{showToast:p}=De(),{exportMCPSettings:O,installConfig:C}=we(),{auth:D}=Ms(),z=((Ae=C==null?void 0:C.baseUrl)==null?void 0:Ae.replace(/\/+$/,""))||"",[V,A]=d.useState(!1),[B,F]=d.useState(null),[L,T]=d.useState(!1),[R,q]=d.useState(!1),[Q,g]=d.useState(!1),[h,k]=d.useState(null),[l,f]=d.useState(!1),[u,w]=d.useState(!1),[$,I]=d.useState(!1),[W,G]=d.useState(!1),[K,Z]=d.useState(!1),[v,M]=d.useState(!1),[se,oe]=d.useState(!1),[j,U]=d.useState(!1),ne=d.useRef(null),J=d.useRef(null);d.useEffect(()=>{const i=E=>{ne.current&&!ne.current.contains(E.target)&&M(!1),J.current&&!J.current.contains(E.target)&&oe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const Y=((Me=s.tools)==null?void 0:Me.length)||0,te=((Ve=s.tools)==null?void 0:Ve.filter(i=>i.enabled!==!1).length)||0,ge=((Ue=s.prompts)==null?void 0:Ue.length)||0,ye=((Be=s.prompts)==null?void 0:Be.filter(i=>i.enabled!==!1).length)||0,je=((Je=s.resources)==null?void 0:Je.length)||0,X=((Le=s.resources)==null?void 0:Le.filter(i=>i.enabled!==!1).length)||0,ae=Pt(s),ie=s.enabled!==!1,H=wt(s,D.user),he=((We=s.config)==null?void 0:We.command)==="npx"||((qe=s.config)==null?void 0:qe.command)==="uvx",xe=!!((Ke=s.oauth)!=null&&Ke.connected&&y),js=async i=>{if(!(!H||l||!a)){f(!0);try{await a(s,i)}finally{f(!1)}}},vs=async i=>{if(i.stopPropagation(),M(!1),!(!H||$||!P)){I(!0);try{await P(s)?p(o("server.reloadSuccess")||"Server reloaded successfully","success"):p(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{I(!1)}}},Ns=async()=>{if(M(!1),!(!H||W||!c)){G(!0);try{await c(s)?p(o("server.reinstallSuccess")||"Server reinstall initiated","success"):p(o("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{G(!1)}}},ws=async()=>{if(M(!1),!(!H||K||!y)){Z(!0);try{await y(s)?p(o("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):p(o("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{Z(!1)}}},ks=async i=>{var S;if(i.stopPropagation(),!H||u||!N)return;const E=i.target.value;if(E!==$e(s.visibility??((S=s.config)==null?void 0:S.visibility))){w(!0);try{await N(s,E)}finally{w(!1)}}},Cs=async i=>{if(i.stopPropagation(),!s.error)return;await es(s.error)?(U(!0),p(o("common.copySuccess")||"Copied","success"),setTimeout(()=>U(!1),1500)):p(o("common.copyFailed")||"Copy failed","error")},Ss=async i=>{var E,S;if(i.stopPropagation(),M(!1),!!H)try{const _=await O(s.name),ee=(S=(E=_==null?void 0:_.data)==null?void 0:E.mcpServers)==null?void 0:S[s.name];if(!_||!_.success||!ee){p((_==null?void 0:_.message)||o("common.copyFailed")||"Copy failed","error");return}k(ot(s.name,ee))}catch(_){console.error("Error copying server configuration:",_),p(o("common.copyFailed")||"Copy failed","error")}},Es=i=>{var E;if(i.stopPropagation(),(E=s.oauth)!=null&&E.authorizationUrl){const ee=window.screen.width/2-300,de=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ee},top=${de}`),p(o("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&p(o("status.oauthClientIdHint"),"warning")}},Ps=async(i,E)=>{try{const{toggleTool:S}=await ve(async()=>{const{toggleTool:ee}=await Promise.resolve().then(()=>ht);return{toggleTool:ee}},void 0,import.meta.url),_=await S(s.name,i,E);_.success?(p(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):p(_.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},Ds=async(i,E)=>{try{const{togglePrompt:S}=await ve(async()=>{const{togglePrompt:ee}=await Promise.resolve().then(()=>jt);return{togglePrompt:ee}},void 0,import.meta.url),_=await S(s.name,i,E);_.success?(p(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):p(_.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},Ts=async(i,E)=>{try{const{toggleResource:S}=await ve(async()=>{const{toggleResource:ee}=await import("./resourceService-D-PRt7tB.js");return{toggleResource:ee}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),_=await S(s.name,i,E);_.success?(p(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):p(_.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},zs=(i,E,S)=>{p(S!=null&&S.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),x==null||x()},$s=(i,E,S)=>{p(S!=null&&S.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),x==null||x()},Is=async(i,E,S)=>{try{const{updateResourceDescription:_,resetResourceDescription:ee}=await ve(async()=>{const{updateResourceDescription:Rs,resetResourceDescription:Os}=await import("./resourceService-D-PRt7tB.js");return{updateResourceDescription:Rs,resetResourceDescription:Os}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),de=S!=null&&S.restored?await ee(s.name,i):await _(s.name,i,E);de.success?(p(S!=null&&S.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),x==null||x()):p(de.error||(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(_){console.error(_),p(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var S;const i=s.config;if(!i)return"";if(i.url)return i.url;const E=[];return i.command&&E.push(i.command),(S=i.args)!=null&&S.length&&E.push(...i.args),E.join(" ")})();const Ie=`${z}/mcp/${s.name}`,Fe=`${z}/api/${s.name}`,Re=async i=>{const E=await es(i);p(E?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",E?"success":"error")},Oe=(i,E)=>o(i,E),ue=Ct(Oe,s.visibility??((He=s.config)==null?void 0:He.visibility)),Fs=St(Oe,ue.value),_e=[{key:"tools",icon:Ws,total:Y,enabled:te,label:o("server.tools")},{key:"prompts",icon:qs,total:ge,enabled:ye,label:o("server.prompts")},{key:"resources",icon:Ks,total:je,enabled:X,label:o("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:()=>A(!V),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(Se,{size:12,style:{color:"var(--hub-ink-3)",transform:V?"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:ie?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),he&&s.packageVersion&&e.jsxs("span",{className:"hub-tag flex-shrink-0",title:o("server.packageVersion"),style:{fontSize:11},children:["v",s.packageVersion]}),he&&s.updateAvailable&&s.latestVersion&&e.jsxs("span",{className:"hub-tag flex-shrink-0",title:o("server.updateAvailable"),style:{fontSize:11,color:"var(--hub-warn)"},children:["↑ ",s.latestVersion]}),ae&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:J,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),oe(E=>!E)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ce,{size:14})}),se&&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:i=>i.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:o("server.errorDetails")}),e.jsx("button",{onClick:Cs,className:"hub-icon-btn sm",title:o("common.copy"),children:j?e.jsx(fe,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(be,{size:12})})]}),e.jsx("button",{onClick:()=>oe(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(Ee,{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})})]})]})]}),!!((Xe=(Ge=s.config)==null?void 0:Ge.credentialTemplate)!=null&&Xe.length)&&e.jsxs(_s,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[o("credentials.personalBadge")," · ",o("credentials.manage")]}),((Ye=s.config)==null?void 0:Ye.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:"hub-server-card-status-cell min-w-0",children:e.jsx(Js,{status:s.status,enabled:s.enabled,startOnDemand:((Ze=s.config)==null?void 0:Ze.startOnDemand)===!0,onAuthClick:Es,className:"hub-server-card-status"})}),e.jsx("div",{className:"hub-server-card-transport-cell min-w-0",children:(Qe=s.config)!=null&&Qe.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:ns(o,s.config.type)??void 0,children:ns(o,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:i=>i.stopPropagation(),children:H&&N?e.jsx(ts,{isLoading:u,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ue.value,onChange:ks,disabled:u,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":o("server.visibility","Visibility"),title:ue.longLabel,children:Fs.map(i=>e.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.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] ${ue.className}`,title:ue.longLabel,children:ue.shortLabel})}),_e.map(({key:i,icon:E,total:S,enabled:_,label:ee})=>{const de=S===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${de?"is-empty":""}`,title:`${ee}: ${_}/${S}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(rs,{icon:E})}),e.jsx("span",{className:"hub-server-capability-value",children:de?"0":`${_}/${S}`})]},i)}),n&&n.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${n.exposed} / ${o("cost.gross")} ${n.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[le(n.exposed),"/",le(n.gross)]})]}):n?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:o("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:i=>i.stopPropagation(),children:e.jsx(ts,{isLoading:l,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(ke,{checked:ie,onCheckedChange:js,disabled:l||!H,size:"compact","aria-label":`${o(ie?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:ne,children:[H&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),M(E=>!E)},"aria-label":"More","aria-busy":m,children:m?e.jsx(me,{size:14,className:"animate-spin"}):e.jsx(Hs,{size:14})}),H&&v&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:i=>i.stopPropagation(),children:[e.jsxs("button",{onClick:i=>{i.stopPropagation(),M(!1),r(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(Gs,{size:13})," ",o("server.edit")]}),b&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),M(!1),!m&&b(s)},disabled:m,"aria-busy":m,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:[m?e.jsx(me,{size:13,className:"animate-spin"}):e.jsx(Xs,{size:13})," ",o("server.duplicate")]}),e.jsxs("button",{onClick:Ss,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(be,{size:13})," ",o("server.copy")]}),P&&e.jsxs("button",{onClick:vs,disabled:$||l||!ie,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(me,{size:13})," ",o("server.reload")]}),c&&he&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),M(!1),!(!H||W||!ie)&&q(!0)},disabled:W||l||!ie,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(Ys,{size:13})," ",o("server.reinstall")]}),xe&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),M(!1),!(!H||K)&&g(!0)},disabled:K,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(Zs,{size:13})," ",o("server.disconnectOAuth")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),M(!1),T(!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(Qs,{size:13})," ",o("server.delete")]})]})]})]}),V&&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:[_e.map(i=>{const E=B===i.key,S=i.icon;return e.jsxs("button",{onClick:()=>F(E?null:i.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:E?"var(--hub-surface)":"transparent",border:"1px solid "+(E?"var(--hub-line)":"transparent"),color:E?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(rs,{icon:S}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),n&&n.connected&&e.jsxs("button",{onClick:()=>F(B==="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:B==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(B==="cost"?"var(--hub-line)":"transparent"),color:B==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:o("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:o("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[le(n.exposed),"/",le(n.gross)]})]}),e.jsxs("div",{className:"ml-auto max-w-full flex-shrink-0 flex items-center justify-end gap-1.5 flex-wrap",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:Ie,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Re(Ie)},title:o("common.copyUrl"),children:e.jsx(be,{size:12})})]}),e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/api/"}),e.jsx("div",{className:"hub-endpoint-url",title:Fe,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Re(Fe)},title:o("common.copyOpenApiUrl"),children:e.jsx(be,{size:12})})]})]})]}),B==="cost"&&(n==null?void 0:n.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...n.items].sort((i,E)=>E.cost-i.cost).map(i=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:i.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:i.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:le(i.cost)})]},`${i.kind}:${i.name}`))}),B==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,E)=>{var S;return e.jsx(ft,{server:s.name,tool:i,readOnly:!H,onToggle:Ps,onDescriptionUpdate:zs,cost:(S=n==null?void 0:n.items.find(_=>_.kind==="tool"&&_.name===i.name))==null?void 0:S.cost},E)})}),B==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,E)=>{var S;return e.jsx(vt,{server:s.name,prompt:i,readOnly:!H,onToggle:Ds,onDescriptionUpdate:$s,cost:(S=n==null?void 0:n.items.find(_=>_.kind==="prompt"&&_.name===i.name))==null?void 0:S.cost},E)})}),B==="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:o("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,E)=>{var S;return e.jsx(Nt,{resource:i,readOnly:!H,onToggle:Ts,onDescriptionUpdate:Is,cost:(S=n==null?void 0:n.items.find(_=>_.kind==="resource"&&_.name===i.uri))==null?void 0:S.cost},`${i.uri}-${E}`)})})})]})]}),e.jsx(at,{isOpen:h!==null,target:h,onClose:()=>k(null)}),e.jsx(it,{isOpen:L,onClose:()=>T(!1),onConfirm:()=>{t(s.name),T(!1)},serverName:s.name}),e.jsx(Pe,{isOpen:R,onClose:()=>q(!1),onConfirm:()=>{q(!1),Ns()},title:o("server.reinstall"),message:o("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:o("server.reinstall"),variant:"warning"}),e.jsx(Pe,{isOpen:Q,onClose:()=>g(!1),onConfirm:()=>{g(!1),ws()},title:o("server.disconnectOAuth"),message:o("server.disconnectOAuthConfirm")||"This will revoke stored OAuth credentials where supported and require authorization again.",confirmText:o("server.disconnectOAuth"),variant:"warning"})]})},os="-copy",Tt=s=>{const n=Math.max(lt-os.length,0);return`${s.slice(0,n)}${os}`},zt=s=>{const{oauth:n,...t}=s.config??{},{accessToken:r,refreshToken:b,pendingAuthorization:m,...a}=n??{};return{name:Tt(s.name),status:"disconnected",config:{...t,...Object.keys(a).length>0?{oauth:a}:{}}}},$t=(s,n)=>{if(s)return Object.fromEntries(Object.entries(s).map(([t,r])=>[n(t),r]))},It=(s,n,t={})=>{const r=n.config;if(!r)return s;const b=t.nameSeparator||"-",m=new Set((n.tools??[]).map(y=>y.name)),a=y=>`${s.name}${y.slice(n.name.length)}`,N=`${n.name}${b}`,x=r.tools?Object.fromEntries(Object.entries(r.tools).flatMap(([y,o])=>m.has(y)?[[a(y),o]]:y.startsWith(N)?[]:[[y,o]])):void 0,P=$t(r.prompts,y=>y.startsWith(N)?a(y):y),c={};return x&&Object.keys(x).length>0&&(c.tools=x),P&&Object.keys(P).length>0&&(c.prompts=P),r.resources&&Object.keys(r.resources).length>0&&(c.resources=r.resources),{...s,config:{...s.config,...c}}},Ft=({onAdd:s,duplicateSource:n=null,onDuplicateCancel:t})=>{const{t:r}=re(),{nameSeparator:b}=we(),[m,a]=d.useState(!1),[N,x]=d.useState(null),[P,c]=d.useState(!1),[y,o]=d.useState(null),[p,O]=d.useState([]),C=d.useMemo(()=>n?zt(n):null,[n]),D=m||n!==null,z=()=>{x(null),c(!1),o(null)},V=()=>{a(!1),z(),n&&(t==null||t())},A=()=>{if(D){V();return}a(!0),z()},B=async()=>{y&&(await F(y),c(!1),o(null))},F=async T=>{try{x(null);const R=await ce("/servers",T);if(!R.success){R&&R.message?x(R.message):x(r("server.addError"));return}V(),s()}catch(R){console.error("Error adding server:",R),navigator.onLine?R instanceof TypeError&&(R.message.includes("NetworkError")||R.message.includes("Failed to fetch"))?x(r("errors.serverConnection")):x(r("errors.serverAdd")):x(r("errors.network"))}},L=async T=>{try{const R=n?It(T,n,{nameSeparator:b}):T,q=ct(R);q.length>0?(O(q),o(R),c(!0)):await F(R)}catch(R){console.error("Error processing server submission:",R),x(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:A,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")]}),D&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(ms,{onSubmit:L,onCancel:V,initialData:C,mode:"create",shareCandidatesFrom:n==null?void 0:n.name,modalTitle:n?r("server.duplicateTitle",{serverName:n.name}):r("server.addServer"),formError:N})}),P&&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:p.map((T,R)=>e.jsxs("li",{className:"font-mono",children:["$",`{${T}}`]},R))})]})]})}),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:()=>{c(!1),o(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:B,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},Rt=({server:s,onEdit:n,onCancel:t})=>{const{t:r}=re(),[b,m]=d.useState(null),a=async N=>{try{m(null);const x=encodeURIComponent(s.name),P=N.name&&N.name!==s.name,c={config:N.config,...P?{newName:N.name}:{}},y=await Ne(`/servers/${x}`,c);if(!y.success){y&&y.message?m(y.message):m(r("server.updateError",{serverName:s.name}));return}n()}catch(x){console.error("Error updating server:",x),navigator.onLine?x instanceof TypeError&&(x.message.includes("NetworkError")||x.message.includes("Failed to fetch"))?m(r("errors.serverConnection")):m(r("errors.serverUpdate",{serverName:s.name})):m(r("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(ms,{onSubmit:a,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:b})})},Ot=({onSuccess:s,onCancel:n})=>{const{t}=re(),[r,b]=d.useState(!1),[m,a]=d.useState(!1),[N,x]=d.useState(null),[P,c]=d.useState(null),[y,o]=d.useState(!1),[p,O]=d.useState(null),[C,D]=d.useState(""),[z,V]=d.useState(!1),[A,B]=d.useState(""),F=l=>{l.preventDefault(),b(!0)},L=l=>{l.preventDefault(),b(!1)},T=l=>{l.preventDefault(),b(!1);const f=l.dataTransfer.files;if(f.length>0){const u=f[0];u.name.endsWith(".mcpb")?(c(u),x(null)):x(t("mcpb.invalidFileType"))}},R=l=>{const f=l.target.files;if(f&&f.length>0){const u=f[0];u.name.endsWith(".mcpb")?(c(u),x(null)):x(t("mcpb.invalidFileType"))}},q=async()=>{if(!P){x(t("mcpb.noFileSelected"));return}a(!0),x(null);try{const l=new FormData;l.append("mcpbFile",P);const f=await Us(Bs("/mcpb/upload"),{method:"POST",body:l}),u=await f.json();if(!f.ok)throw new Error(u.message||`HTTP error! Status: ${f.status}`);if(u.success&&u.data)O(u.data.manifest),D(u.data.extractDir),o(!0);else throw new Error(u.message||t("mcpb.uploadFailed"))}catch(l){console.error("MCPB upload error:",l),x(l instanceof Error?l.message:t("mcpb.uploadFailed"))}finally{a(!1)}},Q=async(l,f=!1)=>{var u;a(!0),x(null);try{const w=k(p,C,l);if(!f){const I=await Vs("/servers");if(I.success&&((u=I.data)==null?void 0:u.find(G=>G.name===l))){B(l),V(!0),a(!1);return}}let $;if(f?$=await Ne(`/servers/${encodeURIComponent(l)}`,{name:l,config:w}):$=await ce("/servers",{name:l,config:w}),$.success)s(w);else throw new Error($.message||t("mcpb.installFailed"))}catch(w){console.error("MCPB install error:",w),x(w instanceof Error?w.message:t("mcpb.installFailed")),a(!1)}},g=()=>{V(!1),A&&Q(A,!0)},h=()=>{V(!1),B(""),a(!1)},k=(l,f,u)=>{var I;const w=((I=l.server)==null?void 0:I.mcp_config)||{},$={type:"stdio",command:w.command||"node",args:(w.args||[]).map(W=>W.replace("${__dirname}",f))};return w.env&&Object.keys(w.env).length>0&&($.env={...w.env},Object.keys($.env).forEach(W=>{typeof $.env[W]=="string"&&($.env[W]=$.env[W].replace("${__dirname}",f))})),$};return y&&p?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{isOpen:z,onClose:h,onConfirm:g,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 ${z?"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:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),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"),":"]})," ",p.display_name||p.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",p.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",p.description]}),p.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",p.author.name]}),p.tools&&p.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:p.tools.map((l,f)=>e.jsxs("li",{children:[l.name," - ",l.description]},f))})]})]})]}),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:p.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:n,disabled:m,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const l=document.getElementById("serverName"),f=(l==null?void 0:l.value.trim())||p.name;Q(f)},disabled:m,className:"hub-btn primary",children:m?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:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${r?"border-blue-500 bg-blue-50":P?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:F,onDragLeave:L,onDrop:T,children:[P?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:P.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(P.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:R,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:n,disabled:m,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:q,disabled:!P||m,className:"hub-btn primary flex items-center",children:m?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")})]})]})})},_t=["sse","streamable-http"],At=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),Mt=s=>{const n=[],t=[];for(const[r,b]of Object.entries(s.mcpServers)){const m=b??{},a={},N=Object.keys(m).filter(x=>!At.has(x));if(N.length>0){t.push({name:r,message:`unknown field(s) "${N.join('", "')}" — not part of the mcphub server schema. For OAuth, use an "oauth" object (e.g. {"scopes":["email"]}).`});continue}if(m.type==="sse"||m.type==="streamable-http"){if(a.type=m.type,a.url=m.url,m.headers&&(a.headers=m.headers),m.oauth&&(a.oauth=m.oauth),!m.url){t.push({name:r,message:`"${m.type}" servers require a "url" field.`});continue}}else if(m.type==="openapi")a.type="openapi",a.openapi=m.openapi;else if(m.type===void 0||m.type==="stdio"){if(m.url&&!m.command){t.push({name:r,message:`has a "url" but type "${m.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(a.type="stdio",a.command=m.command,a.args=m.args||[],m.env&&(a.env=m.env),m.options&&(a.options=m.options),!m.command){t.push({name:r,message:'stdio servers require a "command" field.'});continue}}else{const x=_t.includes(String(m.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:r,message:`unsupported type "${m.type}".${x}`});continue}n.push({name:r,config:a})}return{servers:n,issues:t}},Vt=({onSuccess:s,onCancel:n})=>{const{t}=re(),[r,b]=d.useState(""),[m,a]=d.useState(null),[N,x]=d.useState(!1),[P,c]=d.useState(null),y=`{
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.`,o=C=>{try{const D=JSON.parse(C.trim());return!D.mcpServers||typeof D.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):D}catch{return a(t("jsonImport.parseError")),null}},p=()=>{a(null);const C=o(r);if(!C)return;const{servers:D,issues:z}=Mt(C);if(z.length>0){const V=z.map(A=>`${A.name}: ${A.message}`).join(`
35
- `);if(a(t("jsonImport.validationErrors")+`
36
- `+V),D.length===0)return}c(D)},O=async()=>{if(P){x(!0),a(null);try{const C=await ce("/servers/batch",{servers:P});if(C.success&&C.data){const{successCount:D,failureCount:z,results:V}=C.data;if(z>0){const A=V.filter(B=>!B.success).map(B=>`${B.name}: ${B.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:D,total:P.length})+`
37
- `+A.join(`
38
- `))}D>0&&s()}else a(C.message||t("jsonImport.importFailed"))}catch(C){console.error("Import error:",C),a(t("jsonImport.importFailed"))}finally{x(!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:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),m&&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:m})}),P?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:P.map((C,D)=>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:C.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"),":"]})," ",C.config.type||"stdio"]}),C.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",C.config.command]}),C.config.args&&C.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",C.config.args.join(" ")]}),C.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",C.config.url]}),C.config.env&&Object.keys(C.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(C.config.env).join(", ")]}),C.config.headers&&Object.keys(C.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(C.config.headers).join(", ")]})]})]})})},D))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>c(null),disabled:N,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:O,disabled:N,className:"hub-btn primary",children:N?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:r,onChange:C=>b(C.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:y}),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:n,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:p,disabled:!r.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Ut=s=>({all:s.length,online:s.filter(n=>n.status==="connected").length,issues:s.filter(n=>n.status!=="connected"&&n.enabled!==!1).length,disabled:s.filter(n=>n.enabled===!1).length}),Bt=(s,n,t="")=>{const r=t.trim().toLowerCase();return s.filter(b=>{var a,N;return n==="online"&&b.status!=="connected"||n==="issues"&&(b.status==="connected"||b.enabled===!1)||n==="disabled"&&b.enabled!==!1?!1:r?(b.name+" "+(((a=b.config)==null?void 0:a.description)||"")+" "+(((N=b.tools)==null?void 0:N.map(x=>x.name).join(" "))||"")).toLowerCase().includes(r):!0})},Jt=(s,n,t,r,b)=>{const m=Bt(s,n,t),a=m.length,N=Math.max(1,Math.ceil(a/b)),x=Math.min(Math.max(1,r),N),P=(x-1)*b;return{servers:m.slice(P,P+b),pagination:{page:x,limit:b,total:a,totalPages:N,hasNextPage:x<N,hasPrevPage:x>1}}},ar=()=>{const{t:s}=re(),n=As(),{servers:t,allServers:r,error:b,setError:m,isLoading:a,currentPage:N,serversPerPage:x,setCurrentPage:P,setServersPerPage:c,handleServerAdd:y,handleServerEdit:o,handleServerRemove:p,handleServerToggle:O,handleServerVisibilityChange:C,handleServerReload:D,handleServerReinstall:z,handleServerOAuthDisconnect:V,triggerRefresh:A}=ut({refreshOnMount:!0}),{serverCosts:B,refetch:F}=mt();d.useEffect(()=>{F()},[t,F]);const[L,T]=d.useState(null),[R,q]=d.useState(null),[Q,g]=d.useState(null),[h,k]=d.useState(!1),[l,f]=d.useState(!1),[u,w]=d.useState(!1),[$,I]=d.useState("all"),[W,G]=d.useState(""),K=d.useMemo(()=>Ut(r),[r]),{servers:Z,pagination:v}=d.useMemo(()=>Jt(r,$,W,N,x),[r,$,W,N,x]);d.useEffect(()=>{v.page!==N&&P(v.page)},[v.page,N,P]);const M=async j=>{const U=await o(j);U&&T(U)},se=async j=>{if(Q!==j.name){g(j.name);try{const U=await o(j);U&&q(U)}finally{g(null)}}},oe=async()=>{k(!0);try{A(),await new Promise(j=>setTimeout(j,400))}finally{k(!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:K.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:K.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:K.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>n("/market"),children:[e.jsx(et,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>w(!0),children:[e.jsx(st,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>f(!0),children:[e.jsx(tt,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:oe,disabled:h,"aria-label":s("common.refresh"),children:[e.jsx(me,{size:13,className:h?"animate-spin":""}),s("common.refresh")]}),e.jsx(Ft,{onAdd:y,duplicateSource:R,onDuplicateCancel:()=>q(null)})]})]}),b&&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(Ce,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:b})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>m(null),"aria-label":s("app.closeButton"),children:e.jsx(Ee,{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",K.all],["online",s("status.online"),K.online],["issues",s("common.inactive")||"Issues",K.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",K.disabled]].map(([j,U,ne])=>e.jsxs("button",{onClick:()=>I(j),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:$===j?"var(--hub-bg-2)":"transparent",color:$===j?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+($===j?"var(--hub-line)":"transparent")},children:[U,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:ne})]},j))}),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(rt,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:W,onChange:j=>G(j.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),W&&e.jsx("button",{onClick:()=>G(""),className:"hub-icon-btn sm",children:e.jsx(Ee,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[v.total,"/",r.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(me,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):Z.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:Z.map(j=>e.jsx(Dt,{server:j,cost:B.find(U=>U.name===j.name),onRemove:p,onEdit:M,onDuplicate:se,isDuplicating:Q===j.name,onToggle:O,onVisibilityChange:C,onRefresh:A,onReload:D,onReinstall:z,onOAuthDisconnect:V},j.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:s("common.showing",{start:(v.page-1)*v.limit+1,end:Math.min(v.page*v.limit,v.total),total:v.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:v.totalPages>1&&e.jsx(dt,{currentPage:v.page,totalPages:v.totalPages,onPageChange:P,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:x,onChange:j=>c(Number(j.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"})]})]})]})]}),L&&e.jsx(Rt,{server:L,onEdit:()=>{T(null),A()},onCancel:()=>T(null)}),l&&e.jsx(Ot,{onSuccess:()=>{f(!1),A()},onCancel:()=>f(!1)}),u&&e.jsx(Vt,{onSuccess:()=>{w(!1),A()},onCancel:()=>w(!1)})]})};export{ar as default};
39
- //# sourceMappingURL=ServersPage-OLpH1K1I.js.map