@samanhappy/mcphub 1.1.5 → 1.1.6

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 (106) hide show
  1. package/README.fr.md +2 -0
  2. package/README.md +2 -0
  3. package/README.zh.md +2 -0
  4. package/dist/config/DaoConfigService.js +2 -0
  5. package/dist/config/DaoConfigService.js.map +1 -1
  6. package/dist/config/index.js +3 -0
  7. package/dist/config/index.js.map +1 -1
  8. package/dist/controllers/configController.js +1 -0
  9. package/dist/controllers/configController.js.map +1 -1
  10. package/dist/controllers/groupController.js +4 -3
  11. package/dist/controllers/groupController.js.map +1 -1
  12. package/dist/controllers/oauthDynamicRegistrationController.js +7 -6
  13. package/dist/controllers/oauthDynamicRegistrationController.js.map +1 -1
  14. package/dist/dao/GroupDao.js +3 -0
  15. package/dist/dao/GroupDao.js.map +1 -1
  16. package/dist/dao/ServerDao.js +4 -0
  17. package/dist/dao/ServerDao.js.map +1 -1
  18. package/dist/dao/base/JsonFileBaseDao.js +2 -0
  19. package/dist/dao/base/JsonFileBaseDao.js.map +1 -1
  20. package/dist/db/repositories/GroupRepository.js +4 -0
  21. package/dist/db/repositories/GroupRepository.js.map +1 -1
  22. package/dist/db/repositories/ServerRepository.js +5 -0
  23. package/dist/db/repositories/ServerRepository.js.map +1 -1
  24. package/dist/server.js +20 -8
  25. package/dist/server.js.map +1 -1
  26. package/dist/services/changelogService.js +2 -1
  27. package/dist/services/changelogService.js.map +1 -1
  28. package/dist/services/sseService.js +4 -8
  29. package/dist/services/sseService.js.map +1 -1
  30. package/dist/utils/bearerAuth.js +9 -5
  31. package/dist/utils/bearerAuth.js.map +1 -1
  32. package/dist/utils/credentialTemplate.js +5 -1
  33. package/dist/utils/credentialTemplate.js.map +1 -1
  34. package/dist/utils/migration.js +3 -0
  35. package/dist/utils/migration.js.map +1 -1
  36. package/dist/utils/oauthBearer.js +2 -5
  37. package/dist/utils/oauthBearer.js.map +1 -1
  38. package/dist/utils/oauthConsentResource.js +15 -1
  39. package/dist/utils/oauthConsentResource.js.map +1 -1
  40. package/dist/utils/serverConfigPersistence.js +5 -0
  41. package/dist/utils/serverConfigPersistence.js.map +1 -1
  42. package/dist/utils/serverNameValidation.js +4 -0
  43. package/dist/utils/serverNameValidation.js.map +1 -1
  44. package/dist/utils/settingsSync.js +5 -0
  45. package/dist/utils/settingsSync.js.map +1 -1
  46. package/dist/utils/smartRoutingPath.js +44 -0
  47. package/dist/utils/smartRoutingPath.js.map +1 -0
  48. package/frontend/dist/assets/{ActivityPage-BLDzY9xr.js → ActivityPage-e2s2j32V.js} +2 -2
  49. package/frontend/dist/assets/{ActivityPage-BLDzY9xr.js.map → ActivityPage-e2s2j32V.js.map} +1 -1
  50. package/frontend/dist/assets/{CopyClientConfigDialog-gCW3MVjV.js → CopyClientConfigDialog-B71Cl89b.js} +2 -2
  51. package/frontend/dist/assets/{CopyClientConfigDialog-gCW3MVjV.js.map → CopyClientConfigDialog-B71Cl89b.js.map} +1 -1
  52. package/frontend/dist/assets/{CredentialsPage-Dty6-gb9.js → CredentialsPage-BnA17pRJ.js} +2 -2
  53. package/frontend/dist/assets/{CredentialsPage-Dty6-gb9.js.map → CredentialsPage-BnA17pRJ.js.map} +1 -1
  54. package/frontend/dist/assets/Dashboard-gC_Z286J.js +2 -0
  55. package/frontend/dist/assets/Dashboard-gC_Z286J.js.map +1 -0
  56. package/frontend/dist/assets/{EndpointCopy-ByVAj2YF.js → EndpointCopy-BjD8ehcn.js} +2 -2
  57. package/frontend/dist/assets/{EndpointCopy-ByVAj2YF.js.map → EndpointCopy-BjD8ehcn.js.map} +1 -1
  58. package/frontend/dist/assets/{GroupsPage-BQ0if-JQ.js → GroupsPage-DiT_skCf.js} +2 -2
  59. package/frontend/dist/assets/{GroupsPage-BQ0if-JQ.js.map → GroupsPage-DiT_skCf.js.map} +1 -1
  60. package/frontend/dist/assets/{LoginPage-D7HK95LF.js → LoginPage-DK3WmTV9.js} +2 -2
  61. package/frontend/dist/assets/{LoginPage-D7HK95LF.js.map → LoginPage-DK3WmTV9.js.map} +1 -1
  62. package/frontend/dist/assets/{LogsPage-BcIdaRgU.js → LogsPage-BzI3IAHO.js} +2 -2
  63. package/frontend/dist/assets/{LogsPage-BcIdaRgU.js.map → LogsPage-BzI3IAHO.js.map} +1 -1
  64. package/frontend/dist/assets/MarketPage-DVo32QTs.js +2 -0
  65. package/frontend/dist/assets/MarketPage-DVo32QTs.js.map +1 -0
  66. package/frontend/dist/assets/{OAuthConsentPage-3mefonjY.js → OAuthConsentPage-DUapnxQ9.js} +2 -2
  67. package/frontend/dist/assets/{OAuthConsentPage-3mefonjY.js.map → OAuthConsentPage-DUapnxQ9.js.map} +1 -1
  68. package/frontend/dist/assets/{PromptsPage-Bdb2xr1e.js → PromptsPage-BAqJay5m.js} +2 -2
  69. package/frontend/dist/assets/{PromptsPage-Bdb2xr1e.js.map → PromptsPage-BAqJay5m.js.map} +1 -1
  70. package/frontend/dist/assets/{ResourcesPage-CNLpuEQh.js → ResourcesPage-kIOm5X1A.js} +2 -2
  71. package/frontend/dist/assets/{ResourcesPage-CNLpuEQh.js.map → ResourcesPage-kIOm5X1A.js.map} +1 -1
  72. package/frontend/dist/assets/ServersPage-CkUdGq0R.js +39 -0
  73. package/frontend/dist/assets/ServersPage-CkUdGq0R.js.map +1 -0
  74. package/frontend/dist/assets/{SettingsPage-O4pB7hCL.js → SettingsPage-DkMmUgCh.js} +6 -6
  75. package/frontend/dist/assets/SettingsPage-DkMmUgCh.js.map +1 -0
  76. package/frontend/dist/assets/{StatusDot-CVsYfY8W.js → StatusDot-Bm_C7v3r.js} +2 -2
  77. package/frontend/dist/assets/{StatusDot-CVsYfY8W.js.map → StatusDot-Bm_C7v3r.js.map} +1 -1
  78. package/frontend/dist/assets/ToggleGroup-DcOtP3Gf.js +2 -0
  79. package/frontend/dist/assets/{ToggleGroup-DQNEO10y.js.map → ToggleGroup-DcOtP3Gf.js.map} +1 -1
  80. package/frontend/dist/assets/{UsersPage-DNPJIQt5.js → UsersPage-DpcbXD3K.js} +2 -2
  81. package/frontend/dist/assets/{UsersPage-DNPJIQt5.js.map → UsersPage-DpcbXD3K.js.map} +1 -1
  82. package/frontend/dist/assets/clipboard-CvokTzlX.js +2 -0
  83. package/frontend/dist/assets/{clipboard-CtMMKUq_.js.map → clipboard-CvokTzlX.js.map} +1 -1
  84. package/frontend/dist/assets/index-DkQidC_d.js +3 -0
  85. package/frontend/dist/assets/index-DkQidC_d.js.map +1 -0
  86. package/frontend/dist/assets/{resourceService-BTcWcm4-.js → resourceService-CbZwkCgS.js} +2 -2
  87. package/frontend/dist/assets/{resourceService-BTcWcm4-.js.map → resourceService-CbZwkCgS.js.map} +1 -1
  88. package/frontend/dist/assets/{useCostData-A1KGcEDJ.js → useCostData-DZ5NdhVp.js} +2 -2
  89. package/frontend/dist/assets/{useCostData-A1KGcEDJ.js.map → useCostData-DZ5NdhVp.js.map} +1 -1
  90. package/frontend/dist/assets/variableDetection-SMtrW-P5.js +16 -0
  91. package/frontend/dist/assets/variableDetection-SMtrW-P5.js.map +1 -0
  92. package/frontend/dist/index.html +1 -1
  93. package/package.json +1 -1
  94. package/frontend/dist/assets/Dashboard-Os03VW_9.js +0 -2
  95. package/frontend/dist/assets/Dashboard-Os03VW_9.js.map +0 -1
  96. package/frontend/dist/assets/MarketPage-C3mMsTyI.js +0 -2
  97. package/frontend/dist/assets/MarketPage-C3mMsTyI.js.map +0 -1
  98. package/frontend/dist/assets/ServersPage-CUbyxl2S.js +0 -39
  99. package/frontend/dist/assets/ServersPage-CUbyxl2S.js.map +0 -1
  100. package/frontend/dist/assets/SettingsPage-O4pB7hCL.js.map +0 -1
  101. package/frontend/dist/assets/ToggleGroup-DQNEO10y.js +0 -2
  102. package/frontend/dist/assets/clipboard-CtMMKUq_.js +0 -2
  103. package/frontend/dist/assets/index-D0MN2Xj2.js +0 -3
  104. package/frontend/dist/assets/index-D0MN2Xj2.js.map +0 -1
  105. package/frontend/dist/assets/variableDetection-BegSXlVi.js +0 -16
  106. package/frontend/dist/assets/variableDetection-BegSXlVi.js.map +0 -1
@@ -1,39 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-BTcWcm4-.js","./index-D0MN2Xj2.js","./framework-vendor-CQFm9vKd.js","./i18n-vendor-DVmjrzgW.js","./icons-vendor-CkcU1LMA.js","./index--NhF_yyy.css"])))=>i.map(i=>d[i]);
2
- import{r as c,j as e,L as Js,d as Ls}from"./framework-vendor-CQFm9vKd.js";import{i as Ne,e as ps,f as Te,j as le,h as we,u as Ws,_ as ve,k as qs,l as Ks}from"./index-D0MN2Xj2.js";import{u as re}from"./i18n-vendor-DVmjrzgW.js";import{n as ke,o as hs,p as xs,l as Ce,q as Hs,C as fe,r as be,s as $e,t as bs,u as fs,m as Se,W as Gs,g as Xs,F as Ys,X as De,R as me,v as Zs,w as Qs,x as et,y as st,L as tt,T as rt,P as nt,z as at,D as ot,G as it}from"./icons-vendor-CkcU1LMA.js";import{f as ce}from"./contextCost-CilWqGWT.js";import{S as lt}from"./StatusDot-CVsYfY8W.js";import{u as Ee,c as as}from"./clipboard-CtMMKUq_.js";import{S as Pe}from"./ToggleGroup-DQNEO10y.js";import{g as ct,C as dt,t as ut}from"./CopyClientConfigDialog-gCW3MVjV.js";import{D as mt}from"./DeleteDialog-BaCsEkJA.js";import{C as ze}from"./ConfirmDialog-BYdfb115.js";import{S as pt,a as gs,d as ht}from"./variableDetection-BegSXlVi.js";import{P as xt}from"./Pagination-BRqqU5Ct.js";import{u as bt,a as ft}from"./useCostData-A1KGcEDJ.js";function gt({serverName:s,enabled:r=!0}){const{t}=re(),{showToast:n}=Ne(),[b,u]=c.useState(!1),[a,j]=c.useState(),[h,E]=c.useState(!1),d=`/servers/${encodeURIComponent(s)}/oauth/personal`;c.useEffect(()=>{let v=!0;const w=()=>{ps(d).then(D=>{var A,O;v&&D.success&&(u(!!((A=D.data)!=null&&A.connected)),j((O=D.data)==null?void 0:O.authorizationUrl))}).catch(()=>{})};return w(),window.addEventListener("focus",w),()=>{v=!1,window.removeEventListener("focus",w)}},[d]);const g=async v=>{var D,A,O;const w=v?null:window.open("about:blank","_blank");w&&(w.opener=null),E(!0);try{const I=v?await Te(d):await le(d,{});if(!I.success)throw new Error(I.message||t("server.oauth.personalError"));u(!!((D=I.data)!=null&&D.connected)),j((A=I.data)==null?void 0:A.authorizationUrl),(O=I.data)!=null&&O.authorizationUrl&&w?w.location.replace(I.data.authorizationUrl):w==null||w.close()}catch(I){w==null||w.close(),n(I instanceof Error?I.message:t("server.oauth.personalError"),"error")}finally{E(!1)}},o=t(r?b?"status.online":"status.oauthRequired":"server.disable"),p="hub-btn whitespace-nowrap",_="block w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left whitespace-nowrap";return e.jsx("div",{className:"relative",onClick:v=>v.stopPropagation(),children:b?e.jsxs("details",{children:[e.jsxs("summary",{className:`${p} cursor-pointer list-none`,children:[o,e.jsx(ke,{size:12})]}),e.jsxs("div",{className:"absolute left-0 top-full mt-1 z-20 hub-card p-1",children:[e.jsx("button",{className:_,disabled:h||!r,onClick:()=>void g(!1),children:t("server.oauth.personalReconnect")}),e.jsx("button",{className:_,disabled:h,onClick:()=>void g(!0),children:t("server.oauth.personalDisconnect")})]})]}):a&&r?e.jsx("a",{className:p,title:t("status.clickToAuthorize"),href:a,target:"_blank",rel:"noopener noreferrer",children:o}):e.jsx("button",{className:p,disabled:h||!r,title:t("server.oauth.personalConnect"),onClick:()=>void g(!1),children:o})})}const ys=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await le(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return n.success===!1?{success:!1,error:n.message||"Tool call failed"}:{success:!0,content:(n==null?void 0:n.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},yt=async(s,r,t)=>{try{const n=await le(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},js=async(s,r,t)=>{try{const n=await we(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},vs=async(s,r)=>{var t;try{const n=await Te(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},jt=Object.freeze(Object.defineProperty({__proto__:null,callTool:ys,resetToolDescription:vs,toggleTool:yt,updateToolDescription:js},Symbol.toStringTag,{value:"Module"})),Ns=({schema:s,onSubmit:r,onCancel:t,loading:n=!1,storageKey:b,title:u})=>{const{t:a}=re(),[j,h]=c.useState({}),[E,d]=c.useState({}),[g,o]=c.useState(!1),[p,_]=c.useState(""),[v,w]=c.useState(""),D=c.useMemo(()=>(x=>{const C=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(([m,k])=>[m,C(k)])):void 0,required:f.required,items:f.items?C(f.items):void 0}}return{type:"string"}};return{type:x.type,properties:x.properties?Object.fromEntries(Object.entries(x.properties).map(([l,f])=>[l,C(f)])):void 0,required:x.required}})(s),[s]);c.useEffect(()=>{const y=(C,l="")=>{const f={};return C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,k])=>{const $=l?`${l}.${m}`:m;k.default!==void 0?f[m]=k.default:k.type==="string"?f[m]="":k.type==="number"||k.type==="integer"?f[m]=0:k.type==="boolean"?f[m]=!1:k.type==="array"?f[m]=[]:k.type==="object"&&(k.properties?f[m]=y(k,$):f[m]={})}),f};let x=y(D);if(b)try{const C=localStorage.getItem(b);if(C){const l=JSON.parse(C);x={...x,...l}}}catch(C){console.warn("Failed to load saved form data:",C)}h(x)},[D,b]),c.useEffect(()=>{g&&Object.keys(j).length>0&&(_(JSON.stringify(j,null,2)),w(""))},[g,j]);const A=y=>{_(y),w("");try{const x=JSON.parse(y);if(h(x),b)try{localStorage.setItem(b,JSON.stringify(x))}catch(C){console.warn("Failed to save form data to localStorage:",C)}}catch{w(a("tool.invalidJsonFormat"))}},O=()=>{_(JSON.stringify(j,null,2)),w(""),o(!0)},I=()=>{if(p.trim())try{const y=JSON.parse(p);h(y),w(""),o(!1)}catch{w(a("tool.fixJsonBeforeSwitching"));return}else o(!1)},M=(y,x)=>{h(C=>{const l={...C},f=y.split(".");let m=l;for(let $=0;$<f.length-1;$++){const R=f[$];if(R==="__proto__"||R==="constructor"||R==="prototype")return C;m[R]||(m[R]={}),m=m[R]}const k=f[f.length-1];if(!k||k==="__proto__"||k==="constructor"||k==="prototype")return C;if(m[k]=x,b)try{localStorage.setItem(b,JSON.stringify(l))}catch($){console.warn("Failed to save form data to localStorage:",$)}return l}),E[y]&&d(C=>{const l={...C};return delete l[y],l})},L=()=>{const y={},x=(C,l,f="")=>{C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,k])=>{var W;const $=f?`${f}.${m}`:m,R=l==null?void 0:l[m];if((W=C.required)!=null&&W.includes(m)&&(R==null||R===""||Array.isArray(R)&&R.length===0)){y[$]=`${m} is required`;return}R!=null&&R!==""&&(k.type==="string"&&typeof R!="string"?y[$]=`${m} must be a string`:k.type==="number"&&typeof R!="number"?y[$]=`${m} must be a number`:k.type==="integer"&&(!Number.isInteger(R)||typeof R!="number")?y[$]=`${m} must be an integer`:k.type==="boolean"&&typeof R!="boolean"?y[$]=`${m} must be a boolean`:k.type==="array"&&Array.isArray(R)?k.items&&R.forEach((Y,G)=>{var Q;((Q=k.items)==null?void 0:Q.type)==="object"&&k.items.properties&&x(k.items,Y,`${$}.${G}`)}):k.type==="object"&&typeof R=="object"&&x(k,R,$))})};return x(D,j),d(y),Object.keys(y).length===0},z=y=>{y.preventDefault(),L()&&r(j)},U=(y,x)=>x.split(".").reduce((C,l)=>C==null?void 0:C[l],y),q=(y,x,C,l)=>{const f=C==null?void 0:C[y];return x.type==="string"?x.enum?e.jsxs("select",{value:f||"",onChange:m=>l(m.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")}),x.enum.map((m,k)=>e.jsx("option",{value:m,children:m},k))]}):e.jsx("input",{type:"text",value:f||"",onChange:m=>l(m.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:x.description||a("tool.enterKey",{key:y})}):x.type==="number"||x.type==="integer"?e.jsx("input",{type:"number",step:x.type==="integer"?"1":"any",value:f??"",onChange:m=>{const k=m.target.value===""?"":x.type==="integer"?parseInt(m.target.value):parseFloat(m.target.value);l(k)},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"}):x.type==="boolean"?e.jsx("input",{type:"checkbox",checked:f||!1,onChange:m=>l(m.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:m=>l(m.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:x.description||a("tool.enterKey",{key:y})})},ee=(y,x,C="")=>{var k,$,R,W,Y,G,Q,N,B,te,ne,T,K,J;const l=C?`${C}.${y}`:y,f=U(j,l),m=E[l];if(x.type==="array"){const F=U(j,l)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?($=(k=U(D,C))==null?void 0:k.required)==null?void 0:$.includes(y):(R=D.required)==null?void 0:R.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.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:[F.map((H,ae)=>{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:ae+1})}),e.jsx("button",{type:"button",onClick:()=>{const Z=[...F];Z.splice(ae,1),M(l,Z)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((ge=x.items)==null?void 0:ge.type)==="string"&&x.items.enum?e.jsxs("select",{value:H||"",onChange:Z=>{const oe=[...F];oe[ae]=Z.target.value,M(l,oe)},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")}),x.items.enum.map((Z,oe)=>e.jsx("option",{value:Z,children:Z},oe))]}):((ye=x.items)==null?void 0:ye.type)==="object"&&x.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(x.items.properties).map(([Z,oe])=>{var ie,X;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[Z,((X=(ie=x.items)==null?void 0:ie.required)==null?void 0:X.includes(Z))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),q(Z,oe,H,he=>{const xe=[...F];xe[ae]={...xe[ae],[Z]:he},M(l,xe)})]},Z)})}):e.jsx("input",{type:"text",value:H||"",onChange:Z=>{const oe=[...F];oe[ae]=Z.target.value,M(l,oe)},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=x.items)==null?void 0:je.type)||"value"})})]},ae)}),e.jsx("button",{type:"button",onClick:()=>{var ae;const H=((ae=x.items)==null?void 0:ae.type)==="object"?{}:"";M(l,[...F,H])},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:y})})]}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l)}return x.type==="object"?x.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(Y=(W=U(D,C))==null?void 0:W.required)==null?void 0:Y.includes(y):(G=D.required)==null?void 0:G.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.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(x.properties).map(([F,H])=>ee(F,H,l))}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(N=(Q=U(D,C))==null?void 0:Q.required)==null?void 0:N.includes(y):(B=D.required)==null?void 0:B.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.description}),e.jsx("textarea",{value:typeof f=="object"?JSON.stringify(f,null,2):f||"{}",onChange:F=>{try{const H=JSON.parse(F.target.value);M(l,H)}catch{M(l,F.target.value)}},placeholder:`{
3
- "key": "value"
4
- }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):x.type==="string"?x.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(te=D.required)==null?void 0:te.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.description}),e.jsxs("select",{value:f||"",onChange:F=>M(l,F.target.value),className:`w-full border rounded-md px-3 py-2 ${m?"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")}),x.enum.map((F,H)=>e.jsx("option",{value:F,children:F},H))]}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(ne=D.required)==null?void 0:ne.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.description}),e.jsx("input",{type:"text",value:f||"",onChange:F=>M(l,F.target.value),className:`w-full border rounded-md px-3 py-2 ${m?"border-red":"border-gray-200"} focus:outline-none form-input`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):x.type==="number"||x.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(T=D.required)==null?void 0:T.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.description}),e.jsx("input",{type:"number",step:x.type==="integer"?"1":"any",value:f??"",onChange:F=>{const H=F.target.value===""?"":x.type==="integer"?parseInt(F.target.value):parseFloat(F.target.value);M(l,H)},className:`w-full border rounded-md px-3 py-2 form-input ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):x.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:F=>M(l,F.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:[y,(C?!1:(K=D.required)==null?void 0:K.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:x.description}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(J=D.required)==null?void 0:J.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",x.type,")"]})]}),x.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:x.description}),e.jsx("input",{type:"text",value:f||"",onChange:F=>M(l,F.target.value),placeholder:a("tool.enterValue",{type:x.type}),className:`w-full border rounded-md px-3 py-2 ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},l)};return D.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:u}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:I,className:`hub-btn sm ${g?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:O,className:`hub-btn sm ${g?"primary":""}`,children:a("tool.jsonMode")})]})]}),g?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:y=>A(y.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 ${v?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),v&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:v})]}),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 y=JSON.parse(p);r(y)}catch{w(a("tool.invalidJsonFormat"))}},disabled:n||!!v,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[Object.entries(D.properties||{}).map(([y,x])=>ee(y,x)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:n,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>r({}),disabled:n,className:"hub-btn primary",children:a(n?"tool.running":"tool.runTool")})]})]})},vt=({result:s,onClose:r})=>{const{t}=re(),n=s.content,b=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",u=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(p=>u(p));if(typeof d!="object")return[];const g=[];d.type==="image"&&d.data&&g.push({data:String(d.data),mimeType:b(d.mimeType||d.mime_type)});const o=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return o&&g.push({data:String(o),mimeType:b(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&g.push(...u(d.image)),Array.isArray(d.images)&&g.push(...u(d.images)),Array.isArray(d.content)&&g.push(...u(d.content)),g},a=d=>{const g=[];try{const _=JSON.parse(d);if(g.push(...u(_)),g.length>0)return g}catch{}const o=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let p;for(;(p=o.exec(d))!==null;){const _=`image/${p[1]==="jpg"?"jpeg":p[1]}`;g.push({data:p[2],mimeType:_})}return g},j=d=>{try{const g=JSON.parse(d),o=p=>{if(Array.isArray(p))return p.map(o);if(p&&typeof p=="object"){const _={};for(const[v,w]of Object.entries(p))typeof w=="string"&&v.toLowerCase().includes("base64")?_[v]="[base64 omitted]":_[v]=o(w);return _}return p};return JSON.stringify(o(g),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},h=d=>Array.isArray(d)?d.map((g,o)=>e.jsx("div",{className:"mb-3 last:mb-0",children:E(g)},o)):E(d),E=d=>{if(typeof d=="string"){const g=a(d),o=j(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[g.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:g.map((p,_)=>e.jsx("img",{src:`data:${p.mimeType||"image/png"};base64,${p.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},_))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const g=a(d.text),o=j(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[g.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:g.map((p,_)=>e.jsx("img",{src:`data:${p.mimeType||"image/png"};base64,${p.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},_))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(d.type==="image"&&d.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${d.mimeType||"image/png"};base64,${d.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const g=typeof d=="string"?JSON.parse(d):d;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(g,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})}}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(d)})})};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(hs,{size:20,className:"text-status-green"}):e.jsx(xs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),h(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 dark:text-red-300",children:t("tool.error")})]}),n&&n.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),h(n)]}):e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},pe=({title:s,onClick:r,disabled:t=!1,loading:n=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:r,disabled:t,title:s,"aria-label":s,children:e.jsx(Hs,{size:14,className:n?"animate-spin":""})});function Nt(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 wt=({tool:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:b,cost:u})=>{const{t:a}=re(),{showToast:j}=Ne(),{nameSeparator:h}=Ee(),[E,d]=c.useState(!1),[g,o]=c.useState(!1),[p,_]=c.useState(!1),[v,w]=c.useState(null),[D,A]=c.useState(!1),[O,I]=c.useState(!1),[M,L]=c.useState(s.description||""),z=c.useRef(null),U=c.useRef(null),[q,ee]=c.useState(0),[y,x]=c.useState(!1);c.useEffect(()=>{D&&z.current&&(z.current.focus(),q>0&&(z.current.style.width=`${q+20}px`))},[D,q]),c.useEffect(()=>{!D&&U.current&&ee(U.current.offsetWidth)},[D,M]),c.useEffect(()=>{L(s.description||"")},[s.description]);const C=s.name.replace(r+h,""),l=ct(s,a("tool.noDescription")),f=l.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:l.defaultDescription}):void 0,m=c.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),k=c.useCallback(()=>{localStorage.removeItem(m())},[m]),$=T=>{!t&&n&&n(s.name,T)},R=()=>{t||A(!0)},W=async()=>{if(!t)try{const T=await js(r,s.name,M);T.success?(A(!1),b&&b(s.name,M)):(L(s.description||""),console.error("Failed to update tool description:",T.error))}catch(T){console.error("Error updating tool description:",T),L(s.description||""),A(!1)}},Y=T=>{L(T.target.value)},G=async()=>{if(!t){I(!0);try{const T=await vs(r,s.name);if(T.success){const K=T.description||"";L(K),A(!1),b==null||b(s.name,K,{restored:!0})}else j(T.error||a("tool.restoreDefaultFailed"),"error")}catch(T){console.error("Error resetting tool description:",T),j(a("tool.restoreDefaultFailed"),"error")}finally{I(!1)}}},Q=T=>{T.key==="Enter"?W():T.key==="Escape"&&(L(s.description||""),A(!1))},N=async T=>{T.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),x(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>x(!1),2e3);else{const K=document.createElement("textarea");K.value=s.name,K.style.position="fixed",K.style.left="-9999px",document.body.appendChild(K),K.focus(),K.select();try{document.execCommand("copy"),x(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>x(!1),2e3)}catch(J){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",J)}document.body.removeChild(K)}}catch(K){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",K)}},B=async T=>{_(!0);try{T=Object.fromEntries(Object.entries(T).filter(([J,F])=>!Nt(F)));const K=await ys({toolName:s.name,arguments:T},r);w(K)}catch(K){w({success:!1,error:K instanceof Error?K.message:"Unknown error occurred"})}finally{_(!1)}},te=()=>{o(!1),k(),w(null)},ne=()=>{w(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:T=>{T.stopPropagation(),d(!E)},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:C}),e.jsx("button",{className:"hub-icon-btn sm",onClick:N,title:a("common.copy"),children:y?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:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:z,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:M,onChange:Y,onKeyDown:Q,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),W()},disabled:O,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:a("tool.restoreDefault"),onClick:T=>{T.stopPropagation(),G()},disabled:O,loading:O})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:U,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:T=>{T.stopPropagation(),R()},children:e.jsx($e,{size:12})}),e.jsx(pe,{title:a("tool.restoreDefault"),onClick:T=>{T.stopPropagation(),G()},disabled:O,loading:O})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[u!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(u)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(Pe,{checked:s.enabled??!0,onCheckedChange:$,disabled:p||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${C}`})}),e.jsxs("button",{onClick:T=>{T.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:p||!s.enabled,children:[p?e.jsx(bs,{size:12,className:"animate-spin"}):e.jsx(fs,{size:12}),e.jsx("span",{children:a(p?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:E?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),E&&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})]}),!g&&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)})]}),g&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ns,{schema:s.inputSchema||{type:"object"},onSubmit:B,onCancel:te,loading:p,storageKey:m(),title:a("tool.runToolWithName",{name:C})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(vt,{result:v,onClose:ne})})]})]})]})},kt=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",n=await le(t,{promptName:s.promptName,arguments:s.arguments});return n.success?{success:!0,data:n.data}:{success:!1,error:n.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},ws=async(s,r)=>{try{const t=await le(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ct=async(s,r,t)=>{try{const n=await le(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ks=async(s,r,t)=>{try{const n=await we(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Cs=async(s,r)=>{var t;try{const n=await Te(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},St=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:kt,getPrompt:ws,resetPromptDescription:Cs,togglePrompt:Ct,updatePromptDescription:ks},Symbol.toStringTag,{value:"Module"})),os=({result:s,onClose:r})=>{const{t}=re(),n=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((u,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:[u.role,":"]})}),typeof u.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:u.content}):typeof u.content=="object"&&u.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:u.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(u.content,null,2)})]},a))})]})]});try{const u=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(u,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(hs,{size:20,className:"text-status-green"}):e.jsx(xs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),n(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Et=({prompt:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:b,cost:u})=>{const{t:a}=re(),{showToast:j}=Ne(),{nameSeparator:h}=Ee(),[E,d]=c.useState(!1),[g,o]=c.useState(!1),[p,_]=c.useState(!1),[v,w]=c.useState(null),[D,A]=c.useState(!1),[O,I]=c.useState(!1),[M,L]=c.useState(s.description||""),z=c.useRef(null),U=c.useRef(null),[q,ee]=c.useState(0);c.useEffect(()=>{D&&z.current&&(z.current.focus(),q>0&&(z.current.style.width=`${q+20}px`))},[D,q]),c.useEffect(()=>{!D&&U.current&&ee(U.current.offsetWidth)},[D,M]),c.useEffect(()=>{L(s.description||"")},[s.description]);const y=c.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),x=c.useCallback(()=>{localStorage.removeItem(y())},[y]),C=N=>{!t&&n&&n(s.name,N)},l=()=>{t||A(!0)},f=async()=>{if(!t){A(!1);try{const N=await ks(r,s.name,M);N.success?b&&b(s.name,M):(j(N.error||a("prompt.descriptionUpdateFailed"),"error"),L(s.description||""))}catch(N){console.error("Error updating prompt description:",N),j(a("prompt.descriptionUpdateFailed"),"error"),L(s.description||"")}}},m=async()=>{if(!t){I(!0);try{const N=await Cs(r,s.name);if(N.success){const B=N.description||"";L(B),A(!1),b==null||b(s.name,B,{restored:!0})}else j(N.error||a("prompt.restoreDefaultFailed"),"error")}catch(N){console.error("Error resetting prompt description:",N),j(a("prompt.restoreDefaultFailed"),"error")}finally{I(!1)}}},k=N=>{L(N.target.value)},$=N=>{N.key==="Enter"?f():N.key==="Escape"&&(L(s.description||""),A(!1))},R=async N=>{_(!0);try{const B=await ws({promptName:s.name,arguments:N},r);console.log("GetPrompt result:",B),w({success:B.success,data:B.data,error:B.error})}catch(B){w({success:!1,error:B instanceof Error?B.message:"Unknown error occurred"})}finally{_(!1)}},W=()=>{o(!1),x(),w(null)},Y=()=>{w(null)},G=s.name.replace(r+h,""),Q=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const N={},B=[];return s.arguments.forEach(te=>{N[te.name]={type:"string",description:te.description||""},te.required&&B.push(te.name)}),{type:"object",properties:N,required:B}};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:()=>d(!E),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:G}),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:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:z,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:M,onChange:k,onKeyDown:$,onClick:N=>N.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:N=>{N.stopPropagation(),f()},disabled:O,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:a("prompt.restoreDefault"),onClick:N=>{N.stopPropagation(),m()},disabled:O,loading:O})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:U,children:M||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:N=>{N.stopPropagation(),l()},children:e.jsx($e,{size:12})}),e.jsx(pe,{title:a("prompt.restoreDefault"),onClick:N=>{N.stopPropagation(),m()},disabled:O,loading:O})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[u!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(u)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:N=>N.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Pe,{checked:s.enabled,onCheckedChange:C,disabled:p||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${G}`})}),e.jsxs("button",{onClick:N=>{N.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:p||!s.enabled,children:[p?e.jsx(bs,{size:12,className:"animate-spin"}):e.jsx(fs,{size:12}),e.jsx("span",{children:a(p?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:E?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),E&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[g&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ns,{schema:Q(),onSubmit:R,onCancel:W,loading:p,storageKey:y(),title:a("prompt.runPromptWithName",{name:G})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(os,{result:v,onClose:Y})})]}),!g&&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((N,B)=>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:N.name}),N.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),N.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:N.description})]}),N.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:N.title})]},B))})]}),!g&&v&&e.jsx("div",{children:e.jsx(os,{result:v,onClose:Y})})]})]})},Pt=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:n,cost:b})=>{const{t:u}=re(),[a,j]=c.useState(!1),[h,E]=c.useState(!1),[d,g]=c.useState(!1),[o,p]=c.useState(s.description||""),_=c.useRef(null),v=c.useRef(null),[w,D]=c.useState(0);c.useEffect(()=>{h&&_.current&&(_.current.focus(),w>0&&(_.current.style.width=`${w+20}px`))},[h,w]),c.useEffect(()=>{!h&&v.current&&D(v.current.offsetWidth)},[h,o]),c.useEffect(()=>{p(s.description||"")},[s.description]);const A=s.name||s.uri,O=z=>{!r&&t&&t(s.uri,z)},I=async()=>{r||(E(!1),n&&await n(s.uri,o))},M=async()=>{if(!r){g(!0);try{await(n==null?void 0:n(s.uri,"",{restored:!0})),E(!1)}finally{g(!1)}}},L=z=>{z.key==="Enter"?I():z.key==="Escape"&&(p(s.description||""),E(!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:()=>j(!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:A}),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:h?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:_,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:w>0?`${w+20}px`:160,minWidth:80},value:o,onChange:z=>p(z.target.value),onKeyDown:L,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),I()},disabled:d,children:e.jsx(fe,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(pe,{title:u("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),M()},disabled:d,loading:d})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:o||u("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),E(!0)},children:e.jsx($e,{size:12})}),e.jsx(pe,{title:u("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),M()},disabled:d,loading:d})]})]})})]}),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:u("cost.estimate"),children:["Σ ",ce(b)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:e.jsx(Pe,{checked:s.enabled!==!1,onCheckedChange:O,disabled:r,size:"card","aria-label":`${u(s.enabled!==!1?"server.disable":"server.enable")} ${A}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ke,{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:[u("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Dt=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,zt={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)]"}},Ie=s=>s==="public"||s==="group"?s:"private",Tt=(s,r)=>{const t=Ie(r),n=zt[t];return{value:t,shortLabel:s(n.shortKey,{defaultValue:n.shortFallback}),longLabel:s(n.longKey,{defaultValue:n.longFallback}),className:n.className}},$t=(s,r)=>{const t=Ie(r),n=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&n.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Shared"}),disabled:!0}),n.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),n},is=({isLoading:s,children:r,className:t,overlayStyle:n,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:r}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...n},children:e.jsx(me,{size:b,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),ls=({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"})}),cs=(s,r)=>r?r==="stdio"?s("server.typeStdio")||"stdio":r==="sse"?s("server.typeSse")||"sse":r==="streamable-http"?s("server.typeStreamableHttp")||"http":r==="openapi"?s("server.typeOpenapi")||"openapi":r:null,It="text/html;profile=mcp-app",ds=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Rt=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(n=>ds(n._meta))||(t=s.resources)!=null&&t.some(n=>{var b;return((b=n.uri)==null?void 0:b.startsWith("ui://"))||n.mimeType===It||ds(n._meta)}))},Ft=({server:s,cost:r,onRemove:t,onEdit:n,onDuplicate:b,isDuplicating:u=!1,onToggle:a,onVisibilityChange:j,onRefresh:h,onReload:E,onReinstall:d,onOAuthDisconnect:g})=>{var Me,Ue,Ve,Be,Je,Le,We,qe,Ke,He,Ge,Xe,Ye,Ze,Qe,es,ss,ts,rs,ns;const{t:o}=re(),{showToast:p}=Ne(),{exportMCPSettings:_,installConfig:v}=Ee(),{auth:w}=Ws(),D=((Me=v==null?void 0:v.baseUrl)==null?void 0:Me.replace(/\/+$/,""))||"",[A,O]=c.useState(!1),[I,M]=c.useState(null),[L,z]=c.useState(!1),[U,q]=c.useState(!1),[ee,y]=c.useState(!1),[x,C]=c.useState(null),[l,f]=c.useState(!1),[m,k]=c.useState(!1),[$,R]=c.useState(!1),[W,Y]=c.useState(!1),[G,Q]=c.useState(!1),[N,B]=c.useState(!1),[te,ne]=c.useState(!1),[T,K]=c.useState(!1),J=c.useRef(null),F=c.useRef(null);c.useEffect(()=>{const i=P=>{J.current&&!J.current.contains(P.target)&&B(!1),F.current&&!F.current.contains(P.target)&&ne(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const H=((Ue=s.tools)==null?void 0:Ue.length)||0,ae=((Ve=s.tools)==null?void 0:Ve.filter(i=>i.enabled!==!1).length)||0,ge=((Be=s.prompts)==null?void 0:Be.length)||0,ye=((Je=s.prompts)==null?void 0:Je.filter(i=>i.enabled!==!1).length)||0,je=((Le=s.resources)==null?void 0:Le.length)||0,Z=((We=s.resources)==null?void 0:We.filter(i=>i.enabled!==!1).length)||0,oe=Rt(s),ie=s.enabled!==!1,X=Dt(s,w.user),he=((qe=s.config)==null?void 0:qe.command)==="npx"||((Ke=s.config)==null?void 0:Ke.command)==="uvx",xe=!!(((Ge=(He=s.config)==null?void 0:He.oauth)==null?void 0:Ge.identityMode)!=="personal"&&((Xe=s.oauth)!=null&&Xe.connected)&&g),Ss=async i=>{if(!(!X||l||!a)){f(!0);try{await a(s,i)}finally{f(!1)}}},Es=async i=>{if(i.stopPropagation(),B(!1),!(!X||$||!E)){R(!0);try{await E(s)?p(o("server.reloadSuccess")||"Server reloaded successfully","success"):p(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{R(!1)}}},Ps=async()=>{if(B(!1),!(!X||W||!d)){Y(!0);try{await d(s)?p(o("server.reinstallSuccess")||"Server reinstall initiated","success"):p(o("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{Y(!1)}}},Ds=async()=>{if(B(!1),!(!X||G||!g)){Q(!0);try{await g(s)?p(o("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):p(o("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{Q(!1)}}},zs=async i=>{var S;if(i.stopPropagation(),!X||m||!j)return;const P=i.target.value;if(P!==Ie(s.visibility??((S=s.config)==null?void 0:S.visibility))){k(!0);try{await j(s,P)}finally{k(!1)}}},Ts=async i=>{if(i.stopPropagation(),!s.error)return;await as(s.error)?(K(!0),p(o("common.copySuccess")||"Copied","success"),setTimeout(()=>K(!1),1500)):p(o("common.copyFailed")||"Copy failed","error")},$s=async i=>{var P,S;if(i.stopPropagation(),B(!1),!!X)try{const V=await _(s.name),se=(S=(P=V==null?void 0:V.data)==null?void 0:P.mcpServers)==null?void 0:S[s.name];if(!V||!V.success||!se){p((V==null?void 0:V.message)||o("common.copyFailed")||"Copy failed","error");return}C(ut(s.name,se))}catch(V){console.error("Error copying server configuration:",V),p(o("common.copyFailed")||"Copy failed","error")}},Is=i=>{var P;if(i.stopPropagation(),(P=s.oauth)!=null&&P.authorizationUrl){const se=window.screen.width/2-300,de=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${se},top=${de}`),p(o("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&p(o("status.oauthClientIdHint"),"warning")}},Rs=async(i,P)=>{try{const{toggleTool:S}=await ve(async()=>{const{toggleTool:se}=await Promise.resolve().then(()=>jt);return{toggleTool:se}},void 0,import.meta.url),V=await S(s.name,i,P);V.success?(p(o(P?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),h==null||h()):p(V.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},Fs=async(i,P)=>{try{const{togglePrompt:S}=await ve(async()=>{const{togglePrompt:se}=await Promise.resolve().then(()=>St);return{togglePrompt:se}},void 0,import.meta.url),V=await S(s.name,i,P);V.success?(p(o(P?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),h==null||h()):p(V.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},Os=async(i,P)=>{try{const{toggleResource:S}=await ve(async()=>{const{toggleResource:se}=await import("./resourceService-BTcWcm4-.js");return{toggleResource:se}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),V=await S(s.name,i,P);V.success?(p(o(P?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),h==null||h()):p(V.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),p(o("tool.toggleFailed"),"error")}},_s=(i,P,S)=>{p(S!=null&&S.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),h==null||h()},As=(i,P,S)=>{p(S!=null&&S.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),h==null||h()},Ms=async(i,P,S)=>{try{const{updateResourceDescription:V,resetResourceDescription:se}=await ve(async()=>{const{updateResourceDescription:Vs,resetResourceDescription:Bs}=await import("./resourceService-BTcWcm4-.js");return{updateResourceDescription:Vs,resetResourceDescription:Bs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),de=S!=null&&S.restored?await se(s.name,i):await V(s.name,i,P);de.success?(p(S!=null&&S.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),h==null||h()):p(de.error||(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(V){console.error(V),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 P=[];return i.command&&P.push(i.command),(S=i.args)!=null&&S.length&&P.push(...i.args),P.join(" ")})();const Re=`${D}/mcp/${s.name}`,Fe=`${D}/api/${s.name}`,Oe=async i=>{const P=await as(i);p(P?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",P?"success":"error")},_e=(i,P)=>o(i,P),ue=Tt(_e,s.visibility??((Ye=s.config)==null?void 0:Ye.visibility)),Us=$t(_e,ue.value),Ae=[{key:"tools",icon:Gs,total:H,enabled:ae,label:o("server.tools")},{key:"prompts",icon:Xs,total:ge,enabled:ye,label:o("server.prompts")},{key:"resources",icon:Ys,total:je,enabled:Z,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:()=>O(!A),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:A?"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]}),oe&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:F,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),ne(P=>!P)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ce,{size:14})}),te&&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:Ts,className:"hub-icon-btn sm",title:o("common.copy"),children:T?e.jsx(fe,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(be,{size:12})})]}),e.jsx("button",{onClick:()=>ne(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(De,{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})})]})]})]}),!!((Qe=(Ze=s.config)==null?void 0:Ze.credentialTemplate)!=null&&Qe.length)&&e.jsxs(Js,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[o("credentials.personalBadge")," · ",o("credentials.manage")]}),((es=s.config)==null?void 0:es.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:((ts=(ss=s.config)==null?void 0:ss.oauth)==null?void 0:ts.identityMode)==="personal"?e.jsx(gt,{serverName:s.name,enabled:ie}):e.jsx(lt,{status:s.status,enabled:s.enabled,startOnDemand:((rs=s.config)==null?void 0:rs.startOnDemand)===!0,onAuthClick:Is,className:"hub-server-card-status"})}),e.jsx("div",{className:"hub-server-card-transport-cell min-w-0",children:(ns=s.config)!=null&&ns.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:cs(o,s.config.type)??void 0,children:cs(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:X&&j?e.jsx(is,{isLoading:m,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ue.value,onChange:zs,disabled:m,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:Us.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})}),Ae.map(({key:i,icon:P,total:S,enabled:V,label:se})=>{const de=S===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${de?"is-empty":""}`,title:`${se}: ${V}/${S}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(ls,{icon:P})}),e.jsx("span",{className:"hub-server-capability-value",children:de?"0":`${V}/${S}`})]},i)}),r&&r.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${r.exposed} / ${o("cost.gross")} ${r.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ce(r.exposed),"/",ce(r.gross)]})]}):r?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(is,{isLoading:l,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Pe,{checked:ie,onCheckedChange:Ss,disabled:l||!X,size:"compact","aria-label":`${o(ie?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:J,children:[X&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),B(P=>!P)},"aria-label":"More","aria-busy":u,children:u?e.jsx(me,{size:14,className:"animate-spin"}):e.jsx(Zs,{size:14})}),X&&N&&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(),B(!1),n(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(Qs,{size:13})," ",o("server.edit")]}),b&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),B(!1),!u&&b(s)},disabled:u,"aria-busy":u,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:[u?e.jsx(me,{size:13,className:"animate-spin"}):e.jsx(et,{size:13})," ",o("server.duplicate")]}),e.jsxs("button",{onClick:$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(be,{size:13})," ",o("server.copy")]}),E&&e.jsxs("button",{onClick:Es,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")]}),d&&he&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),B(!1),!(!X||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(st,{size:13})," ",o("server.reinstall")]}),xe&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),B(!1),!(!X||G)&&y(!0)},disabled:G,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(tt,{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(),B(!1),z(!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(rt,{size:13})," ",o("server.delete")]})]})]})]}),A&&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:[Ae.map(i=>{const P=I===i.key,S=i.icon;return e.jsxs("button",{onClick:()=>M(P?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:P?"var(--hub-surface)":"transparent",border:"1px solid "+(P?"var(--hub-line)":"transparent"),color:P?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(ls,{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)}),r&&r.connected&&e.jsxs("button",{onClick:()=>M(I==="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:I==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(I==="cost"?"var(--hub-line)":"transparent"),color:I==="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:[ce(r.exposed),"/",ce(r.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:Re,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Re)},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(),Oe(Fe)},title:o("common.copyOpenApiUrl"),children:e.jsx(be,{size:12})})]})]})]}),I==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((i,P)=>P.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:ce(i.cost)})]},`${i.kind}:${i.name}`))}),I==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,P)=>{var S;return e.jsx(wt,{server:s.name,tool:i,readOnly:!X,onToggle:Rs,onDescriptionUpdate:_s,cost:(S=r==null?void 0:r.items.find(V=>V.kind==="tool"&&V.name===i.name))==null?void 0:S.cost},P)})}),I==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,P)=>{var S;return e.jsx(Et,{server:s.name,prompt:i,readOnly:!X,onToggle:Fs,onDescriptionUpdate:As,cost:(S=r==null?void 0:r.items.find(V=>V.kind==="prompt"&&V.name===i.name))==null?void 0:S.cost},P)})}),I==="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,P)=>{var S;return e.jsx(Pt,{resource:i,readOnly:!X,onToggle:Os,onDescriptionUpdate:Ms,cost:(S=r==null?void 0:r.items.find(V=>V.kind==="resource"&&V.name===i.uri))==null?void 0:S.cost},`${i.uri}-${P}`)})})})]})]}),e.jsx(dt,{isOpen:x!==null,target:x,onClose:()=>C(null)}),e.jsx(mt,{isOpen:L,onClose:()=>z(!1),onConfirm:()=>{t(s.name),z(!1)},serverName:s.name}),e.jsx(ze,{isOpen:U,onClose:()=>q(!1),onConfirm:()=>{q(!1),Ps()},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(ze,{isOpen:ee,onClose:()=>y(!1),onConfirm:()=>{y(!1),Ds()},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"})]})},us="-copy",Ot=s=>{const r=Math.max(pt-us.length,0);return`${s.slice(0,r)}${us}`},_t=s=>{const{oauth:r,...t}=s.config??{},{accessToken:n,refreshToken:b,pendingAuthorization:u,...a}=r??{};return{name:Ot(s.name),status:"disconnected",config:{...t,...Object.keys(a).length>0?{oauth:a}:{}}}},At=(s,r)=>{if(s)return Object.fromEntries(Object.entries(s).map(([t,n])=>[r(t),n]))},Mt=(s,r,t={})=>{const n=r.config;if(!n)return s;const b=t.nameSeparator||"-",u=new Set((r.tools??[]).map(g=>g.name)),a=g=>`${s.name}${g.slice(r.name.length)}`,j=`${r.name}${b}`,h=n.tools?Object.fromEntries(Object.entries(n.tools).flatMap(([g,o])=>u.has(g)?[[a(g),o]]:g.startsWith(j)&&u.has(`${j}${g}`)?[[g,o]]:g.startsWith(j)?[]:[[g,o]])):void 0,E=At(n.prompts,g=>g.startsWith(j)?a(g):g),d={};return h&&Object.keys(h).length>0&&(d.tools=h),E&&Object.keys(E).length>0&&(d.prompts=E),n.resources&&Object.keys(n.resources).length>0&&(d.resources=n.resources),{...s,config:{...s.config,...d}}},ms=(s,r)=>s===r?"commit":"stale",Ut=({onAdd:s,duplicateSource:r=null,onDuplicateCancel:t})=>{const{t:n}=re(),{nameSeparator:b}=Ee(),[u,a]=c.useState(!1),[j,h]=c.useState(null),[E,d]=c.useState(!1),[g,o]=c.useState(null),[p,_]=c.useState([]),v=c.useMemo(()=>r?_t(r):null,[r]),w=u||r!==null,D=()=>{h(null),d(!1),o(null)},A=()=>{a(!1),D(),r&&(t==null||t())},O=()=>{if(w){A();return}a(!0),D()},I=async()=>{g&&(await M(g),d(!1),o(null))},M=async z=>{try{h(null);const U=await le("/servers",z);if(!U.success){U&&U.message?h(U.message):h(n("server.addError"));return}A(),s()}catch(U){console.error("Error adding server:",U),navigator.onLine?U instanceof TypeError&&(U.message.includes("NetworkError")||U.message.includes("Failed to fetch"))?h(n("errors.serverConnection")):h(n("errors.serverAdd")):h(n("errors.network"))}},L=async z=>{try{const U=r?Mt(z,r,{nameSeparator:b}):z,q=ht(U);q.length>0?(_(q),o(U),d(!0)):await M(U)}catch(U){console.error("Error processing server submission:",U),h(n("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:O,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"})}),n("server.add")]}),w&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(gs,{onSubmit:L,onCancel:A,initialData:v,mode:"create",shareCandidatesFrom:r==null?void 0:r.name,modalTitle:r?n("server.duplicateTitle",{serverName:r.name}):n("server.addServer"),formError:j},(r==null?void 0:r.name)??"add")}),E&&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:n("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:n("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700/60 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 dark:text-yellow-300",children:[n("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700 dark:text-yellow-300",children:p.map((z,U)=>e.jsxs("li",{className:"font-mono",children:["$",`{${z}}`]},U))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:n("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{d(!1),o(null)},className:"hub-btn",children:n("common.cancel")}),e.jsx("button",{onClick:I,className:"hub-btn primary",children:n("server.confirmAndAdd")})]})]})})]})},Vt=({server:s,onEdit:r,onCancel:t})=>{const{t:n}=re(),[b,u]=c.useState(null),a=async j=>{try{u(null);const h=encodeURIComponent(s.name),E=j.name&&j.name!==s.name,d={config:j.config,...E?{newName:j.name}:{}},g=await we(`/servers/${h}`,d);if(!g.success){g&&g.message?u(g.message):u(n("server.updateError",{serverName:s.name}));return}r()}catch(h){console.error("Error updating server:",h),navigator.onLine?h instanceof TypeError&&(h.message.includes("NetworkError")||h.message.includes("Failed to fetch"))?u(n("errors.serverConnection")):u(n("errors.serverUpdate",{serverName:s.name})):u(n("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(gs,{onSubmit:a,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:b},s.name)})},Bt=({onSuccess:s,onCancel:r})=>{const{t}=re(),[n,b]=c.useState(!1),[u,a]=c.useState(!1),[j,h]=c.useState(null),[E,d]=c.useState(null),[g,o]=c.useState(!1),[p,_]=c.useState(null),[v,w]=c.useState(""),[D,A]=c.useState(!1),[O,I]=c.useState(""),M=l=>{l.preventDefault(),b(!0)},L=l=>{l.preventDefault(),b(!1)},z=l=>{l.preventDefault(),b(!1);const f=l.dataTransfer.files;if(f.length>0){const m=f[0];m.name.endsWith(".mcpb")?(d(m),h(null)):h(t("mcpb.invalidFileType"))}},U=l=>{const f=l.target.files;if(f&&f.length>0){const m=f[0];m.name.endsWith(".mcpb")?(d(m),h(null)):h(t("mcpb.invalidFileType"))}},q=async()=>{if(!E){h(t("mcpb.noFileSelected"));return}a(!0),h(null);try{const l=new FormData;l.append("mcpbFile",E);const f=await qs(Ks("/mcpb/upload"),{method:"POST",body:l}),m=await f.json();if(!f.ok)throw new Error(m.message||`HTTP error! Status: ${f.status}`);if(m.success&&m.data)_(m.data.manifest),w(m.data.extractDir),o(!0);else throw new Error(m.message||t("mcpb.uploadFailed"))}catch(l){console.error("MCPB upload error:",l),h(l instanceof Error?l.message:t("mcpb.uploadFailed"))}finally{a(!1)}},ee=async(l,f=!1)=>{var m;a(!0),h(null);try{const k=C(p,v,l);if(!f){const R=await ps("/servers");if(R.success&&((m=R.data)==null?void 0:m.find(Y=>Y.name===l))){I(l),A(!0),a(!1);return}}let $;if(f?$=await we(`/servers/${encodeURIComponent(l)}`,{name:l,config:k}):$=await le("/servers",{name:l,config:k}),$.success)s(k);else throw new Error($.message||t("mcpb.installFailed"))}catch(k){console.error("MCPB install error:",k),h(k instanceof Error?k.message:t("mcpb.installFailed")),a(!1)}},y=()=>{A(!1),O&&ee(O,!0)},x=()=>{A(!1),I(""),a(!1)},C=(l,f,m)=>{var R;const k=((R=l.server)==null?void 0:R.mcp_config)||{},$={type:"stdio",command:k.command||"node",args:(k.args||[]).map(W=>W.replace("${__dirname}",f))};return k.env&&Object.keys(k.env).length>0&&($.env={...k.env},Object.keys($.env).forEach(W=>{typeof $.env[W]=="string"&&($.env[W]=$.env[W].replace("${__dirname}",f))})),$};return g&&p?e.jsxs(e.Fragment,{children:[e.jsx(ze,{isOpen:D,onClose:x,onConfirm:y,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:O}),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 ${D?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),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:r,disabled:u,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;ee(f)},disabled:u,className:"hub-btn primary",children:u?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${n?"border-blue-500 bg-blue-50 dark:bg-blue-900/20":E?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:M,onDragLeave:L,onDrop:z,children:[E?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:E.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(E.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:U,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:u,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:q,disabled:!E||u,className:"hub-btn primary flex items-center",children:u?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")})]})]})})},Jt=["sse","streamable-http"],Lt=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),Wt=s=>{const r=[],t=[];for(const[n,b]of Object.entries(s.mcpServers)){const u=b??{},a={},j=Object.keys(u).filter(h=>!Lt.has(h));if(j.length>0){t.push({name:n,message:`unknown field(s) "${j.join('", "')}" — not part of the mcphub server schema. For OAuth, use an "oauth" object (e.g. {"scopes":["email"]}).`});continue}if(u.type==="sse"||u.type==="streamable-http"){if(a.type=u.type,a.url=u.url,u.headers&&(a.headers=u.headers),u.oauth&&(a.oauth=u.oauth),!u.url){t.push({name:n,message:`"${u.type}" servers require a "url" field.`});continue}}else if(u.type==="openapi")a.type="openapi",a.openapi=u.openapi;else if(u.type===void 0||u.type==="stdio"){if(u.url&&!u.command){t.push({name:n,message:`has a "url" but type "${u.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(a.type="stdio",a.command=u.command,a.args=u.args||[],u.env&&(a.env=u.env),u.options&&(a.options=u.options),!u.command){t.push({name:n,message:'stdio servers require a "command" field.'});continue}}else{const h=Jt.includes(String(u.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:n,message:`unsupported type "${u.type}".${h}`});continue}r.push({name:n,config:a})}return{servers:r,issues:t}},qt=({onSuccess:s,onCancel:r})=>{const{t}=re(),[n,b]=c.useState(""),[u,a]=c.useState(null),[j,h]=c.useState(!1),[E,d]=c.useState(null),g=`{
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=v=>{try{const w=JSON.parse(v.trim());return!w.mcpServers||typeof w.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):w}catch{return a(t("jsonImport.parseError")),null}},p=()=>{a(null);const v=o(n);if(!v)return;const{servers:w,issues:D}=Wt(v);if(D.length>0){const A=D.map(O=>`${O.name}: ${O.message}`).join(`
35
- `);if(a(t("jsonImport.validationErrors")+`
36
- `+A),w.length===0)return}d(w)},_=async()=>{if(E){h(!0),a(null);try{const v=await le("/servers/batch",{servers:E});if(v.success&&v.data){const{successCount:w,failureCount:D,results:A}=v.data;if(D>0){const O=A.filter(I=>!I.success).map(I=>`${I.name}: ${I.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:w,total:E.length})+`
37
- `+O.join(`
38
- `))}w>0&&s()}else a(v.message||t("jsonImport.importFailed"))}catch(v){console.error("Import error:",v),a(t("jsonImport.importFailed"))}finally{h(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),u&&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:u})}),E?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:E.map((v,w)=>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:v.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"),":"]})," ",v.config.type||"stdio"]}),v.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",v.config.command]}),v.config.args&&v.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",v.config.args.join(" ")]}),v.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",v.config.url]}),v.config.env&&Object.keys(v.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(v.config.env).join(", ")]}),v.config.headers&&Object.keys(v.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(v.config.headers).join(", ")]})]})]})})},w))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>d(null),disabled:j,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:_,disabled:j,className:"hub-btn primary",children:j?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:n,onChange:v=>b(v.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:g}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:p,disabled:!n.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Kt=s=>({all:s.length,online:s.filter(r=>r.status==="connected").length,issues:s.filter(r=>r.status!=="connected"&&r.enabled!==!1).length,disabled:s.filter(r=>r.enabled===!1).length}),Ht=(s,r,t="")=>{const n=t.trim().toLowerCase();return s.filter(b=>{var a,j;return r==="online"&&b.status!=="connected"||r==="issues"&&(b.status==="connected"||b.enabled===!1)||r==="disabled"&&b.enabled!==!1?!1:n?(b.name+" "+(((a=b.config)==null?void 0:a.description)||"")+" "+(((j=b.tools)==null?void 0:j.map(h=>h.name).join(" "))||"")).toLowerCase().includes(n):!0})},Gt=(s,r,t,n,b)=>{const u=Ht(s,r,t),a=u.length,j=Math.max(1,Math.ceil(a/b)),h=Math.min(Math.max(1,n),j),E=(h-1)*b;return{servers:u.slice(E,E+b),pagination:{page:h,limit:b,total:a,totalPages:j,hasNextPage:h<j,hasPrevPage:h>1}}},dr=()=>{const{t:s}=re(),r=Ls(),{servers:t,allServers:n,error:b,setError:u,isLoading:a,currentPage:j,serversPerPage:h,setCurrentPage:E,setServersPerPage:d,handleServerAdd:g,handleServerEdit:o,handleServerRemove:p,handleServerToggle:_,handleServerVisibilityChange:v,handleServerReload:w,handleServerReinstall:D,handleServerOAuthDisconnect:A,triggerRefresh:O}=bt({refreshOnMount:!0}),{serverCosts:I,refetch:M}=ft();c.useEffect(()=>{M()},[t,M]);const[L,z]=c.useState(null),[U,q]=c.useState(null),[ee,y]=c.useState(null),[x,C]=c.useState(!1),[l,f]=c.useState(!1),[m,k]=c.useState(!1),[$,R]=c.useState("all"),[W,Y]=c.useState(""),G=c.useMemo(()=>Kt(n),[n]),{servers:Q,pagination:N}=c.useMemo(()=>Gt(n,$,W,j,h),[n,$,W,j,h]);c.useEffect(()=>{N.page!==j&&E(N.page)},[N.page,j,E]);const B=c.useRef(0),te=async J=>{const F=++B.current,H=await o(J);F===B.current&&H&&z(H)},ne=c.useRef(0),T=async J=>{if(ee===J.name)return;const F=++ne.current;y(J.name);try{const H=await o(J);if(ms(F,ne.current)==="stale")return;H&&q(H)}finally{ms(F,ne.current)==="commit"&&y(null)}},K=async()=>{C(!0);try{O(),await new Promise(J=>setTimeout(J,400))}finally{C(!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:G.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:G.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:G.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>r("/market"),children:[e.jsx(nt,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>k(!0),children:[e.jsx(at,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>f(!0),children:[e.jsx(ot,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:K,disabled:x,"aria-label":s("common.refresh"),children:[e.jsx(me,{size:13,className:x?"animate-spin":""}),s("common.refresh")]}),e.jsx(Ut,{onAdd:g,duplicateSource:U,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:()=>u(null),"aria-label":s("app.closeButton"),children:e.jsx(De,{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",G.all],["online",s("status.online"),G.online],["issues",s("common.inactive")||"Issues",G.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",G.disabled]].map(([J,F,H])=>e.jsxs("button",{onClick:()=>R(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:[F,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:H})]},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(it,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:W,onChange:J=>Y(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:()=>Y(""),className:"hub-icon-btn sm",children:e.jsx(De,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[N.total,"/",n.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")})]})}):Q.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:Q.map(J=>e.jsx(Ft,{server:J,cost:I.find(F=>F.name===J.name),onRemove:p,onEdit:te,onDuplicate:T,isDuplicating:ee===J.name,onToggle:_,onVisibilityChange:v,onRefresh:O,onReload:w,onReinstall:D,onOAuthDisconnect:A},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:(N.page-1)*N.limit+1,end:Math.min(N.page*N.limit,N.total),total:N.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:N.totalPages>1&&e.jsx(xt,{currentPage:N.page,totalPages:N.totalPages,onPageChange:E,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:h,onChange:J=>d(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(Vt,{server:L,onEdit:()=>{z(null),O()},onCancel:()=>z(null)}),l&&e.jsx(Bt,{onSuccess:()=>{f(!1),O()},onCancel:()=>f(!1)}),m&&e.jsx(qt,{onSuccess:()=>{k(!1),O()},onCancel:()=>k(!1)})]})};export{dr as default};
39
- //# sourceMappingURL=ServersPage-CUbyxl2S.js.map