@samanhappy/mcphub 1.1.12 → 1.1.14

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 (155) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/index.js.map +1 -1
  3. package/dist/controllers/bearerKeyController.js +33 -1
  4. package/dist/controllers/bearerKeyController.js.map +1 -1
  5. package/dist/controllers/configController.js +1 -0
  6. package/dist/controllers/configController.js.map +1 -1
  7. package/dist/controllers/credentialBindingController.js +35 -11
  8. package/dist/controllers/credentialBindingController.js.map +1 -1
  9. package/dist/controllers/serverController.js +29 -4
  10. package/dist/controllers/serverController.js.map +1 -1
  11. package/dist/dao/ActivityDao.js +2 -0
  12. package/dist/dao/ActivityDao.js.map +1 -1
  13. package/dist/dao/BearerKeyDaoDbImpl.js +3 -0
  14. package/dist/dao/BearerKeyDaoDbImpl.js.map +1 -1
  15. package/dist/dao/GroupDao.js +24 -0
  16. package/dist/dao/GroupDao.js.map +1 -1
  17. package/dist/dao/GroupDaoDbImpl.js +23 -0
  18. package/dist/dao/GroupDaoDbImpl.js.map +1 -1
  19. package/dist/dao/ServerDao.js +5 -0
  20. package/dist/dao/ServerDao.js.map +1 -1
  21. package/dist/dao/ServerDaoDbImpl.js +1 -0
  22. package/dist/dao/ServerDaoDbImpl.js.map +1 -1
  23. package/dist/dao/SystemConfigDao.js +5 -2
  24. package/dist/dao/SystemConfigDao.js.map +1 -1
  25. package/dist/dao/SystemConfigDaoDbImpl.js +11 -0
  26. package/dist/dao/SystemConfigDaoDbImpl.js.map +1 -1
  27. package/dist/dao/base/JsonFileBaseDao.js +17 -2
  28. package/dist/dao/base/JsonFileBaseDao.js.map +1 -1
  29. package/dist/db/entities/Activity.js +4 -0
  30. package/dist/db/entities/Activity.js.map +1 -1
  31. package/dist/db/entities/CredentialBindingImport.js +26 -0
  32. package/dist/db/entities/CredentialBindingImport.js.map +1 -0
  33. package/dist/db/entities/SystemConfig.js +8 -0
  34. package/dist/db/entities/SystemConfig.js.map +1 -1
  35. package/dist/db/entities/index.js +3 -1
  36. package/dist/db/entities/index.js.map +1 -1
  37. package/dist/db/repositories/GroupRepository.js +36 -0
  38. package/dist/db/repositories/GroupRepository.js.map +1 -1
  39. package/dist/db/repositories/ServerRepository.js.map +1 -1
  40. package/dist/db/repositories/VectorEmbeddingRepository.js +11 -1
  41. package/dist/db/repositories/VectorEmbeddingRepository.js.map +1 -1
  42. package/dist/routes/index.js +6 -2
  43. package/dist/routes/index.js.map +1 -1
  44. package/dist/server.js +2 -0
  45. package/dist/server.js.map +1 -1
  46. package/dist/services/activityLoggingService.js +1 -0
  47. package/dist/services/activityLoggingService.js.map +1 -1
  48. package/dist/services/contextCostService.js +2 -2
  49. package/dist/services/contextCostService.js.map +1 -1
  50. package/dist/services/groupService.js +6 -1
  51. package/dist/services/groupService.js.map +1 -1
  52. package/dist/services/mcpService.js +127 -4
  53. package/dist/services/mcpService.js.map +1 -1
  54. package/dist/services/principalRuntimeService.js +19 -0
  55. package/dist/services/principalRuntimeService.js.map +1 -1
  56. package/dist/services/smartRoutingService.js +20 -2
  57. package/dist/services/smartRoutingService.js.map +1 -1
  58. package/dist/services/toolPolicyDiagnostics.js +27 -0
  59. package/dist/services/toolPolicyDiagnostics.js.map +1 -0
  60. package/dist/services/toolPolicyService.js +41 -0
  61. package/dist/services/toolPolicyService.js.map +1 -0
  62. package/dist/services/vectorSearchService.js +117 -66
  63. package/dist/services/vectorSearchService.js.map +1 -1
  64. package/dist/types/toolPolicy.js +2 -0
  65. package/dist/types/toolPolicy.js.map +1 -0
  66. package/dist/utils/credentialBindingMigration.js +65 -0
  67. package/dist/utils/credentialBindingMigration.js.map +1 -0
  68. package/dist/utils/groupKeyScope.js +28 -0
  69. package/dist/utils/groupKeyScope.js.map +1 -0
  70. package/dist/utils/migration.js +10 -10
  71. package/dist/utils/migration.js.map +1 -1
  72. package/dist/utils/serverIdentity.js +7 -0
  73. package/dist/utils/serverIdentity.js.map +1 -0
  74. package/dist/utils/settingsSync.js +11 -1
  75. package/dist/utils/settingsSync.js.map +1 -1
  76. package/dist/utils/systemConfigCache.js +1 -1
  77. package/dist/utils/systemConfigCache.js.map +1 -1
  78. package/dist/utils/tokenCost.js +35 -3
  79. package/dist/utils/tokenCost.js.map +1 -1
  80. package/dist/utils/toolPolicy.js +42 -0
  81. package/dist/utils/toolPolicy.js.map +1 -0
  82. package/frontend/dist/assets/{ActivityPage-DWA-okla.js → ActivityPage-C8Zj4FeE.js} +2 -2
  83. package/frontend/dist/assets/{ActivityPage-DWA-okla.js.map → ActivityPage-C8Zj4FeE.js.map} +1 -1
  84. package/frontend/dist/assets/CredentialsPage-BnzqPYjg.js +2 -0
  85. package/frontend/dist/assets/CredentialsPage-BnzqPYjg.js.map +1 -0
  86. package/frontend/dist/assets/{Dashboard-Diql_Btr.js → Dashboard-CCiZcGi4.js} +2 -2
  87. package/frontend/dist/assets/{Dashboard-Diql_Btr.js.map → Dashboard-CCiZcGi4.js.map} +1 -1
  88. package/frontend/dist/assets/{EndpointCopy-0d-dK6uJ.js → EndpointCopy-CmKx4RVL.js} +2 -2
  89. package/frontend/dist/assets/{EndpointCopy-0d-dK6uJ.js.map → EndpointCopy-CmKx4RVL.js.map} +1 -1
  90. package/frontend/dist/assets/GroupsPage-DHgQeVHy.js +33 -0
  91. package/frontend/dist/assets/{GroupsPage-gZ0nnzCn.js.map → GroupsPage-DHgQeVHy.js.map} +1 -1
  92. package/frontend/dist/assets/LoginPage-Hn1uu0vB.js +2 -0
  93. package/frontend/dist/assets/LoginPage-Hn1uu0vB.js.map +1 -0
  94. package/frontend/dist/assets/{LogsPage-C7erxObE.js → LogsPage-JMCtTjCv.js} +2 -2
  95. package/frontend/dist/assets/LogsPage-JMCtTjCv.js.map +1 -0
  96. package/frontend/dist/assets/MarketPage-Bvi1KESo.js +2 -0
  97. package/frontend/dist/assets/{MarketPage-BZHQQB57.js.map → MarketPage-Bvi1KESo.js.map} +1 -1
  98. package/frontend/dist/assets/{OAuthConsentPage-Czhwhcx8.js → OAuthConsentPage-DofQEZAU.js} +2 -2
  99. package/frontend/dist/assets/{OAuthConsentPage-Czhwhcx8.js.map → OAuthConsentPage-DofQEZAU.js.map} +1 -1
  100. package/frontend/dist/assets/Pagination-D99WHhBx.js +2 -0
  101. package/frontend/dist/assets/Pagination-D99WHhBx.js.map +1 -0
  102. package/frontend/dist/assets/{PromptsPage-D0yHQbns.js → PromptsPage-B-8vczAR.js} +2 -2
  103. package/frontend/dist/assets/{PromptsPage-D0yHQbns.js.map → PromptsPage-B-8vczAR.js.map} +1 -1
  104. package/frontend/dist/assets/{ResourcesPage-BFoqAAq0.js → ResourcesPage-DLAIatoG.js} +2 -2
  105. package/frontend/dist/assets/{ResourcesPage-BFoqAAq0.js.map → ResourcesPage-DLAIatoG.js.map} +1 -1
  106. package/frontend/dist/assets/ServersPage-wVLsTL_f.js +39 -0
  107. package/frontend/dist/assets/ServersPage-wVLsTL_f.js.map +1 -0
  108. package/frontend/dist/assets/SettingsPage-DkfXDE5_.js +14 -0
  109. package/frontend/dist/assets/SettingsPage-DkfXDE5_.js.map +1 -0
  110. package/frontend/dist/assets/{StatusDot-BniiEZ-W.js → StatusDot-00-sTQKv.js} +2 -2
  111. package/frontend/dist/assets/{StatusDot-BniiEZ-W.js.map → StatusDot-00-sTQKv.js.map} +1 -1
  112. package/frontend/dist/assets/{ToggleGroup-Df-pFUN3.js → ToggleGroup-CtWBng3r.js} +2 -2
  113. package/frontend/dist/assets/{ToggleGroup-Df-pFUN3.js.map → ToggleGroup-CtWBng3r.js.map} +1 -1
  114. package/frontend/dist/assets/UsersPage-BtdFWcVD.js +2 -0
  115. package/frontend/dist/assets/UsersPage-BtdFWcVD.js.map +1 -0
  116. package/frontend/dist/assets/clipboard-2RRFM-q8.js +2 -0
  117. package/frontend/dist/assets/{clipboard-BrGjez3U.js.map → clipboard-2RRFM-q8.js.map} +1 -1
  118. package/frontend/dist/assets/{CopyClientConfigDialog-xeHg7JJj.js → costRevision-Ntl7VtWo.js} +4 -4
  119. package/frontend/dist/assets/costRevision-Ntl7VtWo.js.map +1 -0
  120. package/frontend/dist/assets/{icons-vendor-CkcU1LMA.js → icons-vendor-CyAS6fj0.js} +2 -2
  121. package/frontend/dist/assets/{icons-vendor-CkcU1LMA.js.map → icons-vendor-CyAS6fj0.js.map} +1 -1
  122. package/frontend/dist/assets/index-CkSmxNPW.js +3 -0
  123. package/frontend/dist/assets/index-CkSmxNPW.js.map +1 -0
  124. package/frontend/dist/assets/index-DrHctFvx.css +1 -0
  125. package/frontend/dist/assets/{resourceService-8K1eUH8N.js → resourceService-BB4UM6IQ.js} +2 -2
  126. package/frontend/dist/assets/{resourceService-8K1eUH8N.js.map → resourceService-BB4UM6IQ.js.map} +1 -1
  127. package/frontend/dist/assets/useCostData-C3XnQyUj.js +2 -0
  128. package/frontend/dist/assets/useCostData-C3XnQyUj.js.map +1 -0
  129. package/frontend/dist/assets/{variableDetection-Djnw5--_.js → variableDetection-BUXwrSop.js} +2 -2
  130. package/frontend/dist/assets/{variableDetection-Djnw5--_.js.map → variableDetection-BUXwrSop.js.map} +1 -1
  131. package/frontend/dist/index.html +3 -3
  132. package/mcp_settings.json +2 -0
  133. package/package.json +1 -1
  134. package/frontend/dist/assets/CopyClientConfigDialog-xeHg7JJj.js.map +0 -1
  135. package/frontend/dist/assets/CredentialsPage-D8mMIH5f.js +0 -2
  136. package/frontend/dist/assets/CredentialsPage-D8mMIH5f.js.map +0 -1
  137. package/frontend/dist/assets/GroupsPage-gZ0nnzCn.js +0 -33
  138. package/frontend/dist/assets/LoginPage-BRyFcGQ5.js +0 -2
  139. package/frontend/dist/assets/LoginPage-BRyFcGQ5.js.map +0 -1
  140. package/frontend/dist/assets/LogsPage-C7erxObE.js.map +0 -1
  141. package/frontend/dist/assets/MarketPage-BZHQQB57.js +0 -2
  142. package/frontend/dist/assets/Pagination-BRqqU5Ct.js +0 -2
  143. package/frontend/dist/assets/Pagination-BRqqU5Ct.js.map +0 -1
  144. package/frontend/dist/assets/ServersPage-CMG1tNig.js +0 -39
  145. package/frontend/dist/assets/ServersPage-CMG1tNig.js.map +0 -1
  146. package/frontend/dist/assets/SettingsPage-C6GAVHlw.js +0 -14
  147. package/frontend/dist/assets/SettingsPage-C6GAVHlw.js.map +0 -1
  148. package/frontend/dist/assets/UsersPage-je7LsHJG.js +0 -2
  149. package/frontend/dist/assets/UsersPage-je7LsHJG.js.map +0 -1
  150. package/frontend/dist/assets/clipboard-BrGjez3U.js +0 -2
  151. package/frontend/dist/assets/index-DL9uGzQF.js +0 -3
  152. package/frontend/dist/assets/index-DL9uGzQF.js.map +0 -1
  153. package/frontend/dist/assets/index-JDk4RjZI.css +0 -1
  154. package/frontend/dist/assets/useCostData-BuDleGRv.js +0 -2
  155. package/frontend/dist/assets/useCostData-BuDleGRv.js.map +0 -1
@@ -1,2 +0,0 @@
1
- import{r as t,j as e,d as He,b as We,i as _e}from"./framework-vendor-CQFm9vKd.js";import{f as J,k as ve,u as je,j as Fe}from"./index-DL9uGzQF.js";import{u as ne}from"./i18n-vendor-DVmjrzgW.js";import{g as Ne,a as ke,d as Oe,s as xe}from"./variableDetection-Djnw5--_.js";import{C as Se,$ as Qe,a5 as qe,a7 as Ge,l as Je,X as Xe,G as Ye,n as Ze}from"./icons-vendor-CkcU1LMA.js";import{P as Ke}from"./Pagination-BRqqU5Ct.js";import"./contextCost-CilWqGWT.js";const es=()=>{const{t:s}=ne(),[p,b]=t.useState([]),[d,m]=t.useState([]),[i,a]=t.useState([]),[A,f]=t.useState([]),[o,D]=t.useState(""),[P,U]=t.useState(""),[M,H]=t.useState(""),[I,C]=t.useState(!0),[F,S]=t.useState(null),[z,O]=t.useState(null),[V,T]=t.useState([]),[Q,$]=t.useState(1),[w,q]=t.useState(9),[k,K]=t.useState(1),B=t.useCallback(async()=>{try{C(!0);const r=await J("/market/servers");r&&r.success&&Array.isArray(r.data)?(m(r.data),E(r.data,Q)):(console.error("Invalid market servers data format",{data:r}),S(s("market.fetchError")))}catch(r){console.error("Error fetching market servers",{err:r}),S(r instanceof Error?r.message:String(r))}finally{C(!1)}},[s]),E=t.useCallback((r,l,G=w)=>{const se=r.length,_=Math.ceil(se/G);K(_);const Y=Math.max(1,Math.min(l,_));Y!==l&&$(Y);const ee=(Y-1)*G,re=r.slice(ee,ee+G);b(re)},[w]),y=t.useCallback(r=>{$(r),E(d,r,w)},[d,E,w]),n=t.useCallback(async()=>{try{const r=await J("/market/categories");r&&r.success&&Array.isArray(r.data)?a(r.data):console.error("Invalid categories data format",{data:r})}catch(r){console.error("Error fetching categories",{err:r})}},[]),h=t.useCallback(async()=>{try{const r=await J("/market/tags");r&&r.success&&Array.isArray(r.data)?f(r.data):console.error("Invalid tags data format",{data:r})}catch(r){console.error("Error fetching tags",{err:r})}},[]),g=t.useCallback(async r=>{try{C(!0);const l=await J(`/market/servers/${r}`);return l&&l.success&&l.data?(O(l.data),l.data):(console.error("Invalid market server data format",{name:r,data:l}),S(s("market.serverNotFound")),null)}catch(l){return console.error("Error fetching market server",{name:r,err:l}),S(l instanceof Error?l.message:String(l)),null}finally{C(!1)}},[s]),N=t.useCallback(async r=>{try{if(C(!0),H(r),!r.trim()){B();return}const l=await J(`/market/servers/search?query=${encodeURIComponent(r)}`);l&&l.success&&Array.isArray(l.data)?(m(l.data),$(1),E(l.data,1)):(console.error("Invalid market search results format",{query:r,data:l}),S(s("market.searchError")))}catch(l){console.error("Error searching market servers",{query:r,err:l}),S(l instanceof Error?l.message:String(l))}finally{C(!1)}},[s,d,E,B]),W=t.useCallback(async r=>{try{if(C(!0),D(r),U(""),!r){B();return}const l=await J(`/market/categories/${encodeURIComponent(r)}`);l&&l.success&&Array.isArray(l.data)?(m(l.data),$(1),E(l.data,1)):(console.error("Invalid market category filter results format",{category:r,data:l}),S(s("market.filterError")))}catch(l){console.error("Error filtering market servers by category",{category:r,err:l}),S(l instanceof Error?l.message:String(l))}finally{C(!1)}},[s,B,E]),R=t.useCallback(async r=>{try{if(C(!0),U(r),D(""),!r){B();return}const l=await J(`/market/tags/${encodeURIComponent(r)}`);l&&l.success&&Array.isArray(l.data)?(m(l.data),$(1),E(l.data,1)):(console.error("Invalid market tag filter results format",{tag:r,data:l}),S(s("market.tagFilterError")))}catch(l){console.error("Error filtering market servers by tag",{tag:r,err:l}),S(l instanceof Error?l.message:String(l))}finally{C(!1)}},[s,B,E]),X=t.useCallback(async()=>{try{const r=await J("/servers");if(r&&r.success&&Array.isArray(r.data)){const l=r.data.map(G=>G.name);T(l)}}catch(r){console.error("Error fetching installed servers",{err:r})}},[]),c=t.useCallback(r=>V.includes(r),[V]),v=t.useCallback(async(r,l)=>{var G,se;try{const _=(G=r.installations)!=null&&G.npm?"npm":Object.keys(r.installations||{}).length>0?Object.keys(r.installations)[0]:null;if(!_||!((se=r.installations)!=null&&se[_]))return S(s("market.noInstallationMethod")),!1;const Y=r.installations[_],ee={name:r.name,config:l.type==="stdio"?{command:l.command||Y.command||"",args:l.args||Y.args||[],env:{...Y.env,...l.env}}:l},re=await ve("/servers",ee);if(!re.success)throw new Error(re.message||"Failed to install server");return await X(),!0}catch(_){return console.error("Error installing market server",{serverName:r.name,err:_}),S(_ instanceof Error?_.message:String(_)),!1}},[s,X]),u=t.useCallback(r=>{q(r),$(1),E(d,1,r)},[d,E]);return t.useEffect(()=>{B(),n(),h(),X()},[B,n,h,X]),{servers:p,allServers:d,categories:i,tags:A,selectedCategory:o,selectedTag:P,searchQuery:M,loading:I,error:F,setError:S,currentServer:z,fetchMarketServers:B,fetchServerByName:g,searchServers:N,filterByCategory:W,filterByTag:R,installServer:v,currentPage:Q,totalPages:k,serversPerPage:w,changePage:y,changeServersPerPage:u,isServerInstalled:c}},ss=()=>{const{t:s}=ne(),[p,b]=t.useState([]),[d,m]=t.useState([]),[i,a]=t.useState(!0),[A,f]=t.useState(null),[o,D]=t.useState(""),[P,U]=t.useState(1),[M,H]=t.useState(9),[I,C]=t.useState(null),[F,S]=t.useState(!1),[z,O]=t.useState([]),[V]=t.useState(1),T=t.useCallback(async(n,h)=>{try{a(!0),f(null);const g=new URLSearchParams;g.append("limit",M.toString()),n&&g.append("cursor",n);const N=h!==void 0?h:o;N.trim()&&g.append("search",N.trim());const W=await J(`/registry/servers?${g.toString()}`);if(W&&W.success&&W.data){const R=W.data;if(R.servers&&Array.isArray(R.servers)){b(R.servers);const X=R.metadata.count===M&&!!R.metadata.nextCursor;S(X),C(R.metadata.nextCursor||null),m(n?c=>[...c,...R.servers]:R.servers)}else console.error("Invalid registry servers data format",{data:R}),f(s("registry.fetchError"))}else f(s("registry.fetchError"))}catch(g){console.error("Error fetching registry servers",{cursor:n,search:h,err:g});const N=g instanceof Error?g.message:String(g);f(N)}finally{a(!1)}},[s,M]),Q=t.useCallback(async()=>{if(!F||!I)return;const n=z[z.length-1]||"";O(h=>[...h,n]),U(h=>h+1),await T(I,o)},[F,I,z,o,T]),$=t.useCallback(async()=>{if(P<=1)return;const n=[...z];n.pop();const h=n[n.length-1];O(n),U(g=>g-1),await T(h||void 0,o)},[P,z,o,T]),w=t.useCallback(async n=>{n!==P&&(n>P&&F?await Q():n<P&&P>1&&await $())},[P,F,Q,$]),q=t.useCallback(async n=>{H(n),U(1),O([]),m([]),await T(void 0,o)},[o,T]),k=t.useCallback(async n=>{try{a(!0),f(null);const h=encodeURIComponent(n),g=await J(`/registry/servers/versions?serverName=${h}`);if(g&&g.success&&g.data){const N=g.data;return N.servers&&Array.isArray(N.servers)&&N.servers.length>0?N.servers[0]:(console.error("Invalid registry server data format",{serverName:n,data:N}),f(s("registry.serverNotFound")),null)}else return f(s("registry.serverNotFound")),null}catch(h){console.error("Error fetching registry server",{serverName:n,err:h});const g=h instanceof Error?h.message:String(h);return f(g),null}finally{a(!1)}},[s]),K=t.useCallback(async n=>{try{f(null);const h=encodeURIComponent(n),g=await J(`/registry/servers/versions?serverName=${h}`);if(g&&g.success&&g.data){const N=g.data;return N.servers&&Array.isArray(N.servers)?N.servers:(console.error("Invalid registry server versions data format",{serverName:n,data:N}),[])}else return[]}catch(h){console.error("Error fetching versions for registry server",{serverName:n,err:h});const g=h instanceof Error?h.message:String(h);return f(g),[]}},[]),B=t.useCallback(async(n,h)=>{try{f(null);const g=encodeURIComponent(n),N=encodeURIComponent(h),W=await J(`/registry/servers/version?serverName=${g}&version=${N}`);if(W&&W.success&&W.data){const R=W.data;return R&&R.server?R:(console.error("Invalid registry server version data format",{serverName:n,version:h,data:R}),null)}else return null}catch(g){console.error("Error fetching specific registry server version",{serverName:n,version:h,err:g});const N=g instanceof Error?g.message:String(g);return f(N),null}},[]),E=t.useCallback(async n=>{console.log("Searching registry servers",{query:n}),D(n),U(1),O([]),m([]),await T(void 0,n)},[T]),y=t.useCallback(async()=>{D(""),U(1),O([]),m([]),await T(void 0,"")},[T]);return t.useEffect(()=>{T(void 0,o)},[]),{servers:p,allServers:d,loading:i,error:A,setError:f,searchQuery:o,searchServers:E,clearSearch:y,fetchServerByName:k,fetchServerVersions:K,fetchServerVersion:B,currentPage:P,totalPages:V,hasNextPage:F,hasPreviousPage:P>1,changePage:w,goToNextPage:Q,goToPreviousPage:$,serversPerPage:M,changeServersPerPage:q}},rs=s=>s.split(" ").map(p=>p.charAt(0)).join("").toUpperCase().slice(0,2),ts=({server:s,onClick:p})=>{var i,a,A;const{t:b}=ne(),d=(s.tags||[]).slice(0,3),m=(i=s.categories)==null?void 0:i[0];return e.jsxs("div",{className:"hub-card flex flex-col cursor-pointer transition-colors h-full overflow-hidden",onClick:()=>p(s),onMouseEnter:f=>f.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:f=>f.currentTarget.style.borderColor="var(--hub-line)",children:[e.jsxs("div",{className:"p-3.5 flex-1 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"hub-mono",style:{width:28,height:28,borderRadius:7,background:"var(--hub-ink)",color:"var(--hub-bg)",display:"grid",placeItems:"center",fontWeight:600,fontSize:13,flexShrink:0},children:rs(s.display_name||s.name)[0]||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate",style:{fontSize:14,fontWeight:500,letterSpacing:"-0.01em"},children:s.display_name}),s.is_official&&e.jsxs("span",{className:"inline-flex items-center gap-0.5",style:{fontSize:10,color:"var(--hub-accent)",background:"var(--hub-accent-soft)",padding:"0 5px",height:16,borderRadius:3,fontWeight:500},children:[e.jsx(Se,{size:9,strokeWidth:2.5}),b("market.official")]})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:["@",((a=s.author)==null?void 0:a.name)||b("market.unknown")]})]})]}),e.jsx("div",{className:"flex-1 line-clamp-2",style:{fontSize:12.5,color:"var(--hub-ink-2)",lineHeight:1.5},children:s.description}),d.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:d.map(f=>e.jsxs("span",{className:"hub-tag",style:{background:"oklch(0.96 0.04 145)",color:"oklch(0.4 0.1 145)",border:0},children:["#",f]},f))})]}),e.jsx("div",{className:"flex items-center justify-between px-3.5 py-2",style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)"},children:e.jsxs("div",{className:"hub-mono flex items-center gap-3",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qe,{size:11}),((A=s.tools)==null?void 0:A.length)??0," ",b("server.tools").toLowerCase()]}),m&&e.jsx("span",{className:"truncate",children:m})]})})]})},as=({server:s,onBack:p,onInstall:b,installing:d=!1,isInstalled:m=!1})=>{var k,K,B,E;const{t:i}=ne(),{auth:a}=je(),A=Ne({type:"stdio"},(k=a.user)==null?void 0:k.isAdmin),[f,o]=t.useState(!1),[D,P]=t.useState(null),[U,M]=t.useState(!1),[H,I]=t.useState(null),[C,F]=t.useState([]),S=()=>m?{className:"bg-green-600 cursor-default px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:i("market.installed")}:d?{className:"bg-gray-400 cursor-not-allowed px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:i("market.installing")}:{className:`hub-btn primary ${A?"opacity-50 cursor-not-allowed":""}`,disabled:!!A,text:i("market.install")},z=()=>{o(!f),P(null),M(!1),I(null)},O=async()=>{H&&(await V(H),M(!1),I(null))},V=async y=>{try{P(null),b(s,y.config),o(!1)}catch(n){console.error("Error installing server:",n),P(i("errors.serverInstall"))}},T=()=>{!m&&!A&&z()},Q=()=>{if(!s.installations)return;if(s.installations.npm)return s.installations.npm;if(s.installations.uvx)return s.installations.uvx;if(s.installations.default)return s.installations.default;const y=Object.keys(s.installations);if(y.length>0)return s.installations[y[0]]},$=async y=>{try{const n=Oe(y);n.length>0?(F(n),I(y),M(!0)):await V(y)}catch(n){console.error("Error processing server installation:",n),P(i("errors.serverInstall"))}},w=S(),q=Q();return e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-md p-6",children:[e.jsx("div",{className:"mb-4",children:e.jsxs("button",{onClick:p,className:"text-gray-600 hover:text-gray-900 flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 mr-1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})}),i("market.backToList")]})}),e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsx("div",{children:e.jsxs("h2",{className:"text-2xl font-bold text-gray-900 flex items-center flex-wrap",children:[s.display_name,e.jsxs("span",{className:"text-sm font-normal text-gray-500 ml-2",children:["(",s.name,")"]}),e.jsxs("span",{className:"text-sm font-normal text-gray-600 ml-4",children:[i("market.author"),": ",((K=s.author)==null?void 0:K.name)||i("market.unknown")," •"," ",i("market.license"),": ",s.license," •",e.jsx("a",{href:s.repository.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:underline ml-1",children:i("market.repository")})]})]})}),e.jsxs("div",{className:"flex items-center",children:[s.is_official&&e.jsx("span",{className:"bg-blue-100 text-blue-800 dark:text-blue-300 dark:bg-blue-900/40 dark:text-blue-300 text-sm font-normal px-4 py-2 rounded mr-2 flex items-center label-primary",children:i("market.official")}),e.jsx("button",{onClick:T,disabled:w.disabled,className:w.className,children:w.text})]})]}),A&&e.jsx("p",{role:"status",className:"text-sm text-amber-700 dark:text-amber-300 mb-4",children:i(A)}),e.jsx("p",{className:"text-gray-700 mb-6",children:s.description}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-3",children:[i("market.categories")," & ",i("market.tags")]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(B=s.categories)==null?void 0:B.map((y,n)=>e.jsx("span",{className:"bg-gray-100 dark:bg-gray-800 text-gray-800 px-3 py-1 rounded",children:y},`cat-${n}`)),s.tags&&s.tags.map((y,n)=>e.jsxs("span",{className:"bg-gray-100 dark:bg-gray-800 text-green-700 dark:text-green-300 px-2 py-1 rounded text-sm",children:["#",y]},`tag-${n}`))]})]}),s.arguments&&Object.keys(s.arguments).length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:i("market.arguments")}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap",children:i("market.argumentName")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap",children:i("market.description")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap",children:i("market.required")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap",children:i("market.example")})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700",children:Object.entries(s.arguments).map(([y,n],h)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:y}),e.jsx("td",{className:"px-6 py-4 text-sm text-gray-500",children:n.description}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:n.required?e.jsx("span",{className:"text-green-600",children:"✓"}):e.jsx("span",{className:"text-gray-600",children:"✗"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded",children:n.example})})]},h))})]})})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:i("market.tools")}),e.jsx("div",{className:"space-y-4",children:(E=s.tools)==null?void 0:E.map((y,n)=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded p-4",children:[e.jsxs("h4",{className:"font-medium mb-2",children:[y.name,e.jsx("button",{type:"button",onClick:()=>{const h=document.getElementById(`schema-${n}`);h&&h.classList.toggle("hidden")},className:"text-sm text-blue-500 font-normal hover:underline focus:outline-none ml-2",children:i("market.viewSchema")})]}),e.jsx("p",{className:"text-gray-600 mb-2",children:y.description}),e.jsx("div",{className:"mt-2",children:e.jsx("pre",{id:`schema-${n}`,className:"hidden bg-gray-50 dark:bg-gray-800 p-3 rounded text-sm overflow-auto mt-2",children:JSON.stringify(y.inputSchema,null,2)})})]},n))})]}),s.examples&&s.examples.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:i("market.examples")}),e.jsx("div",{className:"space-y-4",children:s.examples.map((y,n)=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded p-4",children:[e.jsx("h4",{className:"font-medium mb-2",children:y.title}),e.jsx("p",{className:"text-gray-600 mb-2",children:y.description}),e.jsx("pre",{className:"bg-gray-50 dark:bg-gray-800 p-3 rounded text-sm overflow-auto",children:y.prompt})]},n))})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("button",{onClick:T,disabled:w.disabled,className:w.className,children:w.text})}),f&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(ke,{onSubmit:$,onCancel:z,modalTitle:i("market.installServer",{name:s.display_name}),formError:D,initialData:{name:s.name,status:"disconnected",config:q?{command:q.command||"",args:q.args||[],env:q.env||{}}:void 0}})}),U&&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:i("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:i("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:[i("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700 dark:text-yellow-300",children:C.map((y,n)=>e.jsxs("li",{className:"font-mono",children:["$",`{${y}}`]},n))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:i("market.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{M(!1),I(null)},className:"hub-btn",children:i("common.cancel")}),e.jsx("button",{onClick:O,className:"hub-btn primary",children:i("market.confirmAndInstall")})]})]})})]})},ns=s=>{if(!s)return"";try{const p=new Date(s),b=p.getFullYear(),d=(p.getMonth()+1).toString().padStart(2,"0"),m=p.getDate().toString().padStart(2,"0");return`${b}/${d}/${m}`}catch{return""}},ls=({serverEntry:s,onClick:p})=>{var M,H;const{t:b}=ne(),{server:d,_meta:m}=s,i=m==null?void 0:m["io.modelcontextprotocol.registry/official"],a=i==null?void 0:i.isLatest,A=i==null?void 0:i.publishedAt,f=i==null?void 0:i.updatedAt,o=((M=d.packages)==null?void 0:M.length)||0,D=((H=d.remotes)==null?void 0:H.length)||0,P=d.description?d.description.length<=150?d.description:d.description.slice(0,150)+"...":b("registry.noDescription"),U=d.icons&&d.icons.length>0?d.icons.find(C=>!C.theme||C.theme==="light")||d.icons[0]:null;return e.jsxs("div",{className:"hub-card flex flex-col cursor-pointer transition-colors h-full overflow-hidden",onClick:()=>p(s),onMouseEnter:I=>I.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:I=>I.currentTarget.style.borderColor="var(--hub-line)",children:[e.jsxs("div",{className:"p-3.5 flex-1 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[U?e.jsx("img",{src:U.src,alt:d.title||d.name,className:"rounded-md object-cover flex-shrink-0",style:{width:28,height:28},onError:I=>{I.currentTarget.style.display="none"}}):e.jsx("div",{className:"hub-mono flex-shrink-0",style:{width:28,height:28,borderRadius:7,background:"var(--hub-ink)",color:"var(--hub-bg)",display:"grid",placeItems:"center",fontWeight:600,fontSize:13},children:d.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate",style:{fontSize:14,fontWeight:500,letterSpacing:"-0.01em"},children:d.title||d.name}),a&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 flex-shrink-0",style:{fontSize:10,color:"oklch(0.4 0.13 145)",background:"oklch(0.95 0.05 145)",padding:"0 5px",height:16,borderRadius:3,fontWeight:500},children:[e.jsx(Se,{size:9,strokeWidth:2.5}),b("registry.latest")]})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:[d.name," · v",d.version]})]})]}),e.jsx("div",{className:"flex-1 line-clamp-2",style:{fontSize:12.5,color:"var(--hub-ink-2)",lineHeight:1.5},children:P})]}),e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-2",style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)"},children:[e.jsxs("div",{className:"hub-mono flex items-center gap-3",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:[o>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(qe,{size:11}),o]}),D>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ge,{size:11}),D]}),(A||f)&&e.jsx("span",{children:ns(f||A)})]}),e.jsxs("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-accent)"},children:[b("registry.viewDetails")," →"]})]})]})},os=({serverEntry:s,onBack:p,onInstall:b,installing:d=!1,isInstalled:m=!1,fetchVersions:i})=>{var X;const{t:a}=ne(),{auth:A}=je(),f=Ne({type:"stdio"},(X=A.user)==null?void 0:X.isAdmin),{server:o,_meta:D}=s,[P,U]=t.useState(o.version),[M,H]=t.useState([]),[I,C]=t.useState(!1),[F,S]=t.useState(!1),[z,O]=t.useState(null),[V,T]=t.useState(null),[Q,$]=t.useState(null),[w,q]=t.useState({packages:!0,remotes:!0,repository:!0}),k=D==null?void 0:D["io.modelcontextprotocol.registry/official"];t.useEffect(()=>{(async()=>{if(i){C(!0);try{const v=await i(o.name);H(v)}catch(v){console.error("Failed to load versions:",v)}finally{C(!1)}}})()},[o.name,i]);const B=o.icons&&o.icons.length>0?o.icons.find(v=>!v.theme||v.theme==="light")||o.icons[0]:null,E=c=>{if(!c)return"";try{return new Date(c).toLocaleDateString()}catch{return""}},y=c=>{q(v=>({...v,[c]:!v[c]}))},n=(c,v)=>{c==="package"&&f||(O(c),T(v),$(null),S(!0))},h=()=>{S(!1),$(null)},g=async c=>{try{if(!b||!V||!z)return;$(null);const v=c.config;b(o,v),S(!1)}catch(v){console.error("Error installing server:",v),$(a("errors.serverInstall"))}},N=()=>{if(!V||!z)return null;if(console.log("Building initial form data for:",V),z==="package"&&"identifier"in V){const c=V,v={};c.environmentVariables&&c.environmentVariables.forEach(r=>{v[r.name]=r.default||""});const u=is(c.registryType);return{name:xe(o.name),status:"disconnected",config:{type:"stdio",command:u,args:cs(u,c),env:Object.keys(v).length>0?v:void 0}}}else if(z==="remote"&&"url"in V){const c=V,v={};c.headers&&c.headers.forEach(r=>{v[r.name]=r.default||r.value||""});const u=c.type==="sse"?"sse":"streamable-http";return{name:xe(o.name),status:"disconnected",config:{type:u,url:c.url,headers:Object.keys(v).length>0?v:void 0}}}return null},W=(c,v)=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 mb-3 hover:border-blue-400 transition-colors",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:c.identifier}),c.version&&e.jsxs("p",{className:"text-sm text-gray-500",children:["Version: ",c.version]}),c.runtimeHint&&e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:c.runtimeHint})]}),e.jsx("button",{onClick:()=>n("package",c),disabled:m||d||!!f,className:`px-4 py-2 rounded text-sm font-medium transition-colors ${m?"hub-btn cursor-default":d||f?"hub-btn cursor-not-allowed opacity-50":"hub-btn primary"}`,children:a(m?"registry.installed":d?"registry.installing":"registry.install")})]}),f&&e.jsx("p",{role:"status",className:"text-sm text-amber-700 dark:text-amber-300 mb-3",children:a(f)}),c.registryType&&e.jsxs("div",{className:"text-sm text-gray-600 mb-2",children:[e.jsx("span",{className:"font-medium",children:"Registry:"})," ",c.registryType]}),c.transport&&e.jsxs("div",{className:"text-sm text-gray-600 mb-2",children:[e.jsx("span",{className:"font-medium",children:"Transport:"})," ",c.transport.type,c.transport.url&&e.jsxs("span",{className:"ml-2 text-gray-500",children:["(",c.transport.url,")"]})]}),c.environmentVariables&&c.environmentVariables.length>0&&e.jsxs("div",{className:"mt-3 border-t border-gray-200 dark:border-gray-700 pt-3",children:[e.jsxs("h5",{className:"text-sm font-medium text-gray-700 mb-2",children:[a("registry.environmentVariables"),":"]}),e.jsx("div",{className:"space-y-2",children:c.environmentVariables.map((u,r)=>e.jsxs("div",{className:"text-sm",children:[e.jsxs("div",{className:"flex items-start",children:[e.jsx("span",{className:"font-mono text-gray-900 font-medium",children:u.name}),u.isRequired&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800",children:a("common.required")}),u.isSecret&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:a("common.secret")})]}),u.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:u.description}),u.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.default})]})]},r))})]}),c.packageArguments&&c.packageArguments.length>0&&e.jsxs("div",{className:"mt-3 border-t border-gray-200 dark:border-gray-700 pt-3",children:[e.jsxs("h5",{className:"text-sm font-medium text-gray-700 mb-2",children:[a("registry.packageArguments"),":"]}),e.jsx("div",{className:"space-y-2",children:c.packageArguments.map((u,r)=>e.jsxs("div",{className:"text-sm",children:[e.jsxs("div",{className:"flex items-start",children:[e.jsx("span",{className:"font-mono text-gray-900 font-medium",children:u.name}),u.isRequired&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800",children:a("common.required")}),u.isSecret&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:a("common.secret")}),u.isRepeated&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/40 dark:text-purple-300",children:a("common.repeated")})]}),u.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:u.description}),u.type&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.type"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.type})]}),u.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.default})]}),u.value&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.value"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.value})]}),u.valueHint&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.valueHint"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.valueHint})]}),u.choices&&u.choices.length>0&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.choices"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.choices.join(", ")})]})]},r))})]})]},v),R=(c,v)=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 mb-3 hover:border-blue-400 transition-colors",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:c.type}),e.jsx("p",{className:"text-sm text-gray-600 mt-1 break-all",children:c.url})]}),e.jsx("button",{onClick:()=>n("remote",c),disabled:m||d,className:`px-4 py-2 rounded text-sm font-medium transition-colors ${m?"hub-btn cursor-default":d?"hub-btn cursor-not-allowed opacity-50":"hub-btn primary"}`,children:a(m?"registry.installed":d?"registry.installing":"registry.install")})]}),c.headers&&c.headers.length>0&&e.jsxs("div",{className:"mt-3 border-t border-gray-200 dark:border-gray-700 pt-3",children:[e.jsxs("h5",{className:"text-sm font-medium text-gray-700 mb-2",children:[a("registry.headers"),":"]}),e.jsx("div",{className:"space-y-2",children:c.headers.map((u,r)=>e.jsxs("div",{className:"text-sm",children:[e.jsxs("div",{className:"flex items-start",children:[e.jsx("span",{className:"font-mono text-gray-900 font-medium",children:u.name}),u.isRequired&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800",children:a("common.required")}),u.isSecret&&e.jsx("span",{className:"ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:a("common.secret")})]}),u.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:u.description}),u.value&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.value"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.value})]}),u.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[a("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:u.default})]})]},r))})]})]},v);return e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:p,className:"flex items-center text-blue-600 hover:text-blue-800 mb-4 transition-colors",children:[e.jsx("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),a("registry.backToList")]}),e.jsxs("div",{className:"flex items-start space-x-4",children:[B?e.jsx("img",{src:B.src,alt:o.title,className:"w-20 h-20 rounded-lg object-cover flex-shrink-0",onError:c=>{c.currentTarget.style.display="none"}}):e.jsx("div",{className:"w-20 h-20 bg-gradient-to-br from-blue-500 to-purple-600 rounded-lg flex items-center justify-center text-white text-3xl font-semibold flex-shrink-0",children:"M"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:o.name}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-3",children:[(k==null?void 0:k.isLatest)&&e.jsx("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800",children:a("registry.latest")}),e.jsxs("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300",children:["v",o.version]}),(k==null?void 0:k.status)&&e.jsx("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-gray-100 dark:bg-gray-800 text-gray-800",children:k.status}),e.jsxs("span",{className:"flex flex-wrap items-center gap-4 text-sm text-gray-600",children:[(k==null?void 0:k.publishedAt)&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[a("registry.published"),":"]})," ",E(k.publishedAt)]}),(k==null?void 0:k.updatedAt)&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[a("registry.updated"),":"]})," ",E(k.updatedAt)]})]})]})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-3",children:a("registry.description")}),e.jsx("p",{className:"text-gray-700 leading-relaxed whitespace-pre-wrap",children:o.description})]}),o.websiteUrl&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-3",children:a("registry.website")}),e.jsx("a",{href:o.websiteUrl,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline",children:o.websiteUrl})]}),o.packages&&o.packages.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>y("packages"),className:"flex items-center justify-between w-full text-xl font-semibold text-gray-900 mb-3 hover:text-blue-600 transition-colors",children:[e.jsxs("span",{children:[a("registry.packages")," (",o.packages.length,")"]}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${w.packages?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),w.packages&&e.jsx("div",{className:"space-y-3",children:o.packages.map(W)})]}),o.remotes&&o.remotes.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>y("remotes"),className:"flex items-center justify-between w-full text-xl font-semibold text-gray-900 mb-3 hover:text-blue-600 transition-colors",children:[e.jsxs("span",{children:[a("registry.remotes")," (",o.remotes.length,")"]}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${w.remotes?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),w.remotes&&e.jsx("div",{className:"space-y-3",children:o.remotes.map(R)})]}),o.repository&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>y("repository"),className:"flex items-center justify-between w-full text-xl font-semibold text-gray-900 mb-3 hover:text-blue-600 transition-colors",children:[e.jsx("span",{children:a("registry.repository")}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${w.repository?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),w.repository&&e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[o.repository.url&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"URL:"})," ",e.jsx("a",{href:o.repository.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline break-all",children:o.repository.url})]}),o.repository.source&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"Source:"})," ",o.repository.source]}),o.repository.subfolder&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"Subfolder:"})," ",o.repository.subfolder]}),o.repository.id&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"ID:"})," ",o.repository.id]})]})]}),F&&V&&z&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(ke,{onSubmit:g,onCancel:h,modalTitle:a("registry.installServer",{name:o.title||o.name}),formError:Q,initialData:N()})})]})};function is(s){switch(s.toLowerCase()){case"pypi":case"python":return"uvx";case"npm":case"node":return"npx";case"oci":case"docker":return"docker";default:return""}}function cs(s,p){const b=[p.identifier+(p.version?`@${p.version}`:"")],d=[];switch(p.packageArguments&&p.packageArguments.length>0&&p.packageArguments.forEach(m=>{if(m.isRequired||m.default||m.value){const i=`--${m.name}`,a=m.value||m.default||`\${${m.name.toUpperCase()}}`;d.push(i,a)}}),s.toLowerCase()){case"uvx":return[...b,...d];case"npx":return[...b,...d];case"docker":{const m=[];return p.environmentVariables&&p.environmentVariables.forEach(i=>{m.push("-e",`${i.name}`)}),["run","-i","--rm",...m,...b,...d]}default:return[...b,...d]}}const ds=({currentPage:s,hasNextPage:p,hasPreviousPage:b,onNextPage:d,onPreviousPage:m})=>e.jsxs("div",{className:"flex items-center justify-center space-x-2 my-6",children:[e.jsxs("button",{onClick:m,disabled:!b,className:`px-4 py-2 rounded transition-all duration-200 ${b?"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary":"bg-gray-100 text-gray-400 cursor-not-allowed"}`,children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5 inline-block mr-1",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})}),"Prev"]}),e.jsxs("span",{className:"px-4 py-2 bg-blue-500 text-white rounded btn-primary",children:["Page ",s]}),e.jsxs("button",{onClick:d,disabled:!p,className:`px-4 py-2 rounded transition-all duration-200 ${p?"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary":"bg-gray-100 text-gray-400 cursor-not-allowed"}`,children:["Next",e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5 inline-block ml-1",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})]})]}),ys=()=>{const{t:s}=ne(),p=He(),{serverName:b}=We(),{showToast:d}=Fe(),[m,i]=_e(),a=m.get("tab")==="registry"?"registry":"local",{servers:A,allServers:f,categories:o,loading:D,error:P,setError:U,searchServers:M,filterByCategory:H,filterByTag:I,selectedCategory:C,selectedTag:F,installServer:S,fetchServerByName:z,isServerInstalled:O,currentPage:V,totalPages:T,changePage:Q,serversPerPage:$,changeServersPerPage:w}=es(),{servers:q,allServers:k,loading:K,error:B,setError:E,searchServers:y,clearSearch:n,fetchServerByName:h,fetchServerVersions:g,currentPage:N,totalPages:W,hasNextPage:R,hasPreviousPage:X,changePage:c,goToNextPage:v,goToPreviousPage:u,serversPerPage:r,changeServersPerPage:l}=ss(),[G,se]=t.useState(null),[_,Y]=t.useState(null),[ee,re]=t.useState(""),[de,he]=t.useState(""),[ge,ce]=t.useState(!1),[we,Ce]=t.useState(new Set);t.useEffect(()=>{(async()=>{if(b)if(a==="registry"){const j=await h(b);j?Y(j):p("/market?tab=registry")}else{const j=await z(b);j?se(j):p("/market?tab=local")}else se(null),Y(null)})()},[b,a,z,h,p]);const Pe=x=>{const j=new URLSearchParams(m);j.set("tab",x),i(j),b&&p("/market?"+j.toString())},Ee=x=>{x.preventDefault(),a==="local"?M(ee):a==="registry"&&y(de)},Re=x=>{a==="local"&&H(x)},Ie=()=>{a==="local"?(re(""),H(""),I("")):a==="registry"&&(he(""),n())},pe=x=>{var j;if(a==="registry"){const ae=(j=x.server)==null?void 0:j.name;ae&&p(`/market/${encodeURIComponent(ae)}?tab=registry`)}else p(`/market/${x.name}?tab=local`)},fe=()=>p(`/market?tab=${a}`),Te=async(x,j)=>{try{ce(!0),await S(x,j)&&d(s("market.installSuccess",{serverName:x.display_name}),"success")}finally{ce(!1)}},Le=async(x,j)=>{try{ce(!0);const Z={name:xe(x.name),config:j},ae=await ve("/servers",Z);if(!ae.success){d((ae==null?void 0:ae.message)||s("server.addError"),"error");return}Ce(Ue=>new Set(Ue).add(x.name)),d(s("registry.installSuccess",{name:x.title||x.name}),"success")}catch(Z){d(s("registry.installError",{error:Z instanceof Error?Z.message:String(Z)}),"error")}finally{ce(!1)}},Ae=x=>{a==="local"?Q(x):c(x),window.scrollTo({top:0,behavior:"smooth"})},ze=x=>{const j=parseInt(x.target.value,10);a==="local"?w(j):l(j)};if(G)return e.jsx(as,{server:G,onBack:fe,onInstall:Te,installing:ge,isInstalled:O(G.name)});if(_)return e.jsx(os,{serverEntry:_,onBack:fe,onInstall:Le,installing:ge,isInstalled:we.has(_.server.name),fetchVersions:g});const L=a==="local",le=a==="registry",me=L?A:q,ue=L?f:k,$e=L?o:[],Be=L?D:K,ye=L?P:B,Ve=L?U:E,te=L?C:"",Me=L?F:"",oe=L?V:N,De=L?T:W,ie=L?$:r,be=[{id:"local",label:s("market.title"),sourceLabel:"MCPM",sourceUrl:"https://mcpm.sh"},{id:"registry",label:s("registry.title"),sourceLabel:s("registry.official"),sourceUrl:"https://registry.modelcontextprotocol.io"}];return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-end justify-between gap-4 mb-6",children:e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("nav.market")}),e.jsx("p",{className:"hub-sub",children:be.map(x=>x.label).join(" · ")})]})}),e.jsx("div",{className:"mb-5",children:e.jsx("div",{style:{borderBottom:"1px solid var(--hub-line)"},children:e.jsx("nav",{className:"flex -mb-px gap-1.5",children:be.map(x=>{const j=a===x.id;return e.jsxs("button",{onClick:()=>Pe(x.id),className:"py-2 px-3 transition-colors text-[14px]",style:{borderBottom:"2px solid "+(j?"var(--hub-ink)":"transparent"),color:j?"var(--hub-ink)":"var(--hub-ink-3)",fontWeight:j?500:400},children:[x.label,e.jsxs("a",{href:x.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"hub-mono ml-1.5",style:{fontSize:11,color:"var(--hub-ink-3)"},onClick:Z=>Z.stopPropagation(),children:["(",x.sourceLabel,")"]})]},x.id)})})})}),ye&&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(Je,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:ye})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>Ve(null),children:e.jsx(Xe,{size:13})})]}),(L||le)&&e.jsxs("form",{onSubmit:Ee,className:"hub-card flex items-center gap-2 px-3 mb-5",style:{padding:6},children:[e.jsx(Ye,{size:16,style:{color:"var(--hub-ink-3)",margin:"0 6px 0 6px"}}),e.jsx("input",{type:"text",value:le?de:ee,onChange:x=>{le?he(x.target.value):re(x.target.value)},placeholder:s(le?"registry.searchPlaceholder":"market.searchPlaceholder"),className:"flex-1 bg-transparent outline-none",style:{height:32,fontSize:14,color:"var(--hub-ink)"}}),e.jsx("button",{type:"submit",className:"hub-btn",children:s("common.search")}),(L&&(ee||te||Me)||le&&de)&&e.jsx("button",{type:"button",onClick:Ie,className:"hub-btn ghost",children:s("common.clear")})]}),e.jsxs("div",{className:L?"grid gap-5":"",style:L?{gridTemplateColumns:"180px 1fr"}:void 0,children:[L&&e.jsxs("div",{children:[e.jsx("h3",{className:"hub-sect mb-2",children:s("market.categories")}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("button",{onClick:()=>H(""),className:"flex items-center justify-between transition-colors text-[13px]",style:{padding:"6px 10px",borderRadius:6,background:te?"transparent":"var(--hub-surface)",color:te?"var(--hub-ink-2)":"var(--hub-ink)",border:"1px solid "+(te?"transparent":"var(--hub-line)")},children:[e.jsx("span",{children:s("common.all")}),e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:f.length})]}),$e.map(x=>e.jsx("button",{onClick:()=>Re(x),className:"flex items-center justify-between transition-colors text-[13px]",style:{padding:"6px 10px",borderRadius:6,background:te===x?"var(--hub-surface)":"transparent",color:te===x?"var(--hub-ink)":"var(--hub-ink-2)",border:"1px solid "+(te===x?"var(--hub-line)":"transparent")},children:e.jsx("span",{className:"truncate",children:x})},x))]})]}),e.jsx("div",{children:Be?e.jsx("div",{className:"hub-card p-6 text-center",style:{color:"var(--hub-ink-3)"},children:s("app.loading")}):me.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:s(L?"market.noServers":"registry.noServers")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:me.map((x,j)=>L?e.jsx(ts,{server:x,onClick:pe},j):e.jsx(ls,{serverEntry:x,onClick:pe},j))}),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:L?s("market.showing",{from:(oe-1)*ie+1,to:Math.min(oe*ie,ue.length),total:ue.length}):s("registry.showing",{from:(oe-1)*ie+1,to:(oe-1)*ie+me.length,total:ue.length+(R?"+":"")})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:le?e.jsx(ds,{currentPage:oe,hasNextPage:R,hasPreviousPage:X,onNextPage:v,onPreviousPage:u}):e.jsx(Ke,{currentPage:oe,totalPages:De,onPageChange:Ae})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s(L?"market.perPage":"registry.perPage"),":"]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"perPage",value:ie,onChange:ze,className:"hub-input pr-7",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:"6",children:"6"}),e.jsx("option",{value:"9",children:"9"}),e.jsx("option",{value:"12",children:"12"}),e.jsx("option",{value:"24",children:"24"})]}),e.jsx(Ze,{size:11,className:"absolute right-1.5 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"var(--hub-ink-3)"}})]})]})]})]})})]})]})};export{ys as default};
2
- //# sourceMappingURL=MarketPage-BZHQQB57.js.map
@@ -1,2 +0,0 @@
1
- import{j as t}from"./framework-vendor-CQFm9vKd.js";import{u as l}from"./i18n-vendor-DVmjrzgW.js";const c=({currentPage:s,totalPages:r,onPageChange:e,disabled:a=!1})=>{const{t:x}=l(),y=()=>{const n=[];n.push(t.jsx("button",{onClick:()=>e(1),className:`px-3 py-1 mx-1 rounded ${s===1?"bg-blue-500 text-white btn-primary":"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary"}`,children:"1"},"first"));const o=Math.max(2,s-Math.floor(5/2));o>2&&n.push(t.jsx("span",{className:"px-3 py-1",children:"..."},"ellipsis1"));for(let i=o;i<=Math.min(r-1,o+5-3);i++)n.push(t.jsx("button",{onClick:()=>e(i),className:`px-3 py-1 mx-1 rounded ${s===i?"bg-blue-500 text-white btn-primary":"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary"}`,children:i},i));return o+5-3<r-1&&n.push(t.jsx("span",{className:"px-3 py-1",children:"..."},"ellipsis2")),r>1&&n.push(t.jsx("button",{onClick:()=>e(r),className:`px-3 py-1 mx-1 rounded ${s===r?"bg-blue-500 text-white btn-primary":"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary"}`,children:r},"last")),n};return r<=1?null:t.jsxs("div",{className:"flex justify-center items-center my-6",children:[t.jsxs("button",{onClick:()=>e(Math.max(1,s-1)),disabled:a||s===1,className:`px-3 py-1 rounded mr-2 ${a||s===1?"bg-gray-100 text-gray-400 cursor-not-allowed":"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary"}`,children:["« ",x("common.previous")]}),t.jsx("div",{className:"flex",children:y()}),t.jsxs("button",{onClick:()=>e(Math.min(r,s+1)),disabled:a||s===r,className:`px-3 py-1 rounded ml-2 ${a||s===r?"bg-gray-100 text-gray-400 cursor-not-allowed":"bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary"}`,children:[x("common.next")," »"]})]})};export{c as P};
2
- //# sourceMappingURL=Pagination-BRqqU5Ct.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Pagination-BRqqU5Ct.js","sources":["../../src/components/ui/Pagination.tsx"],"sourcesContent":["import React from 'react';\nimport { useTranslation } from 'react-i18next';\n\ninterface PaginationProps {\n currentPage: number;\n totalPages: number;\n onPageChange: (page: number) => void;\n disabled?: boolean;\n}\n\nconst Pagination: React.FC<PaginationProps> = ({\n currentPage,\n totalPages,\n onPageChange,\n disabled = false\n}) => {\n const { t } = useTranslation();\n // Generate page buttons\n const getPageButtons = () => {\n const buttons = [];\n const maxDisplayedPages = 5; // Maximum number of page buttons to display\n\n // Always display first page\n buttons.push(\n <button\n key=\"first\"\n onClick={() => onPageChange(1)}\n className={`px-3 py-1 mx-1 rounded ${currentPage === 1\n ? 'bg-blue-500 text-white btn-primary'\n : 'bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary'\n }`}\n >\n 1\n </button>\n );\n\n // Start range\n const startPage = Math.max(2, currentPage - Math.floor(maxDisplayedPages / 2));\n\n // If we're showing ellipsis after first page\n if (startPage > 2) {\n buttons.push(\n <span key=\"ellipsis1\" className=\"px-3 py-1\">\n ...\n </span>\n );\n }\n\n // Middle pages\n for (let i = startPage; i <= Math.min(totalPages - 1, startPage + maxDisplayedPages - 3); i++) {\n buttons.push(\n <button\n key={i}\n onClick={() => onPageChange(i)}\n className={`px-3 py-1 mx-1 rounded ${currentPage === i\n ? 'bg-blue-500 text-white btn-primary'\n : 'bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary'\n }`}\n >\n {i}\n </button>\n );\n }\n\n // If we're showing ellipsis before last page\n if (startPage + maxDisplayedPages - 3 < totalPages - 1) {\n buttons.push(\n <span key=\"ellipsis2\" className=\"px-3 py-1\">\n ...\n </span>\n );\n }\n\n // Always display last page if there's more than one page\n if (totalPages > 1) {\n buttons.push(\n <button\n key=\"last\"\n onClick={() => onPageChange(totalPages)}\n className={`px-3 py-1 mx-1 rounded ${currentPage === totalPages\n ? 'bg-blue-500 text-white btn-primary'\n : 'bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary'\n }`}\n >\n {totalPages}\n </button>\n );\n }\n\n return buttons;\n };\n\n // If there's only one page, don't render pagination\n if (totalPages <= 1) {\n return null;\n }\n\n return (\n <div className=\"flex justify-center items-center my-6\">\n <button\n onClick={() => onPageChange(Math.max(1, currentPage - 1))}\n disabled={disabled || currentPage === 1}\n className={`px-3 py-1 rounded mr-2 ${disabled || currentPage === 1\n ? 'bg-gray-100 text-gray-400 cursor-not-allowed'\n : 'bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary'\n }`}\n >\n &laquo; {t('common.previous')}\n </button>\n\n <div className=\"flex\">{getPageButtons()}</div>\n\n <button\n onClick={() => onPageChange(Math.min(totalPages, currentPage + 1))}\n disabled={disabled || currentPage === totalPages}\n className={`px-3 py-1 rounded ml-2 ${disabled || currentPage === totalPages\n ? 'bg-gray-100 text-gray-400 cursor-not-allowed'\n : 'bg-gray-200 hover:bg-gray-300 text-gray-700 btn-secondary'\n }`}\n >\n {t('common.next')} &raquo;\n </button>\n </div>\n );\n};\n\nexport default Pagination;"],"names":["Pagination","currentPage","totalPages","onPageChange","disabled","t","useTranslation","getPageButtons","buttons","jsx","startPage","jsxs"],"mappings":"iGAUA,MAAMA,EAAwC,CAAC,CAC7C,YAAAC,EACA,WAAAC,EACA,aAAAC,EACA,SAAAC,EAAW,EACb,IAAM,CACJ,KAAM,CAAE,EAAAC,CAAA,EAAMC,EAAA,EAERC,EAAiB,IAAM,CAC3B,MAAMC,EAAU,CAAA,EAIhBA,EAAQ,KACNC,EAAAA,IAAC,SAAA,CAEC,QAAS,IAAMN,EAAa,CAAC,EAC7B,UAAW,0BAA0BF,IAAgB,EACjD,qCACA,2DACF,GACH,SAAA,GAAA,EANK,OAAA,CAQN,EAIF,MAAMS,EAAY,KAAK,IAAI,EAAGT,EAAc,KAAK,MAAM,EAAoB,CAAC,CAAC,EAGzES,EAAY,GACdF,EAAQ,KACNC,EAAAA,IAAC,OAAA,CAAqB,UAAU,YAAY,gBAAlC,WAEV,CAAA,EAKJ,QAAS,EAAIC,EAAW,GAAK,KAAK,IAAIR,EAAa,EAAGQ,EAAY,EAAoB,CAAC,EAAG,IACxFF,EAAQ,KACNC,EAAAA,IAAC,SAAA,CAEC,QAAS,IAAMN,EAAa,CAAC,EAC7B,UAAW,0BAA0BF,IAAgB,EACjD,qCACA,2DACF,GAED,SAAA,CAAA,EAPI,CAAA,CAQP,EAKJ,OAAIS,EAAY,EAAoB,EAAIR,EAAa,GACnDM,EAAQ,KACNC,EAAAA,IAAC,OAAA,CAAqB,UAAU,YAAY,gBAAlC,WAEV,CAAA,EAKAP,EAAa,GACfM,EAAQ,KACNC,EAAAA,IAAC,SAAA,CAEC,QAAS,IAAMN,EAAaD,CAAU,EACtC,UAAW,0BAA0BD,IAAgBC,EACjD,qCACA,2DACF,GAED,SAAAA,CAAA,EAPG,MAAA,CAQN,EAIGM,CACT,EAGA,OAAIN,GAAc,EACT,KAIPS,EAAAA,KAAC,MAAA,CAAI,UAAU,wCACb,SAAA,CAAAA,EAAAA,KAAC,SAAA,CACC,QAAS,IAAMR,EAAa,KAAK,IAAI,EAAGF,EAAc,CAAC,CAAC,EACxD,SAAUG,GAAYH,IAAgB,EACtC,UAAW,0BAA0BG,GAAYH,IAAgB,EAC7D,+CACA,2DACF,GACH,SAAA,CAAA,KACUI,EAAE,iBAAiB,CAAA,CAAA,CAAA,EAG9BI,EAAAA,IAAC,MAAA,CAAI,UAAU,OAAQ,aAAiB,EAExCE,EAAAA,KAAC,SAAA,CACC,QAAS,IAAMR,EAAa,KAAK,IAAID,EAAYD,EAAc,CAAC,CAAC,EACjE,SAAUG,GAAYH,IAAgBC,EACtC,UAAW,0BAA0BE,GAAYH,IAAgBC,EAC7D,+CACA,2DACF,GAED,SAAA,CAAAG,EAAE,aAAa,EAAE,IAAA,CAAA,CAAA,CACpB,EACF,CAEJ"}
@@ -1,39 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-8K1eUH8N.js","./index-DL9uGzQF.js","./framework-vendor-CQFm9vKd.js","./i18n-vendor-DVmjrzgW.js","./icons-vendor-CkcU1LMA.js","./index-JDk4RjZI.css"])))=>i.map(i=>d[i]);
2
- import{r as c,j as e,L as Ks,d as Gs}from"./framework-vendor-CQFm9vKd.js";import{j as we,f as bs,h as $e,k as ie,i as ve,u as Xs,_ as Ne,l as Ys,m as Zs}from"./index-DL9uGzQF.js";import{u as ae}from"./i18n-vendor-DVmjrzgW.js";import{n as ke,o as fs,p as gs,l as Ce,q as Qs,C as je,r as ye,s as Ie,t as ys,u as js,m as Se,W as et,g as st,F as tt,X as ze,R as be,v as rt,w as nt,x as at,y as ot,L as it,T as lt,P as ct,z as dt,D as ut,G as mt}from"./icons-vendor-CkcU1LMA.js";import{f as ce}from"./contextCost-CilWqGWT.js";import{S as pt}from"./StatusDot-BniiEZ-W.js";import{u as Pe,c as ls}from"./clipboard-BrGjez3U.js";import{S as Ee}from"./ToggleGroup-Df-pFUN3.js";import{g as ht,C as xt,t as bt}from"./CopyClientConfigDialog-xeHg7JJj.js";import{D as ft}from"./DeleteDialog-BaCsEkJA.js";import{C as Te}from"./ConfirmDialog-BYdfb115.js";import{c as gt,S as yt,a as vs,d as jt}from"./variableDetection-Djnw5--_.js";import{P as vt}from"./Pagination-BRqqU5Ct.js";import{u as Nt,a as wt}from"./useCostData-BuDleGRv.js";function kt({serverName:s,enabled:r=!0}){const{t}=ae(),{showToast:n}=we(),[m,l]=c.useState(!1),[a,j]=c.useState(),[x,E]=c.useState(!1),d=`/servers/${encodeURIComponent(s)}/oauth/personal`;c.useEffect(()=>{let v=!0;const C=()=>{bs(d).then(z=>{var _,A;v&&z.success&&(l(!!((_=z.data)!=null&&_.connected)),j((A=z.data)==null?void 0:A.authorizationUrl))}).catch(()=>{})};return C(),window.addEventListener("focus",C),()=>{v=!1,window.removeEventListener("focus",C)}},[d]);const f=async v=>{var z,_,A;const C=v?null:window.open("about:blank","_blank");C&&(C.opener=null),E(!0);try{const I=v?await $e(d):await ie(d,{});if(!I.success)throw new Error(I.message||t("server.oauth.personalError"));l(!!((z=I.data)!=null&&z.connected)),j((_=I.data)==null?void 0:_.authorizationUrl),(A=I.data)!=null&&A.authorizationUrl&&C?C.location.replace(I.data.authorizationUrl):C==null||C.close()}catch(I){C==null||C.close(),n(I instanceof Error?I.message:t("server.oauth.personalError"),"error")}finally{E(!1)}},o=t(r?m?"status.online":"status.oauthRequired":"server.disable"),h="hub-btn whitespace-nowrap",O="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:m?e.jsxs("details",{children:[e.jsxs("summary",{className:`${h} 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:O,disabled:x||!r,onClick:()=>void f(!1),children:t("server.oauth.personalReconnect")}),e.jsx("button",{className:O,disabled:x,onClick:()=>void f(!0),children:t("server.oauth.personalDisconnect")})]})]}):a&&r?e.jsx("a",{className:h,title:t("status.clickToAuthorize"),href:a,target:"_blank",rel:"noopener noreferrer",children:o}):e.jsx("button",{className:h,disabled:x||!r,title:t("server.oauth.personalConnect"),onClick:()=>void f(!1),children:o})})}const Ns=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await ie(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"}}},Ct=async(s,r,t)=>{try{const n=await ie(`/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"}}},ws=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ks=async(s,r,t)=>{var n;try{const m=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/hidden-params`,{hiddenParams:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:m.success,error:m.success?void 0:m.message,hiddenParams:(n=m.data)==null?void 0:n.hiddenParams}}catch(m){return console.error("Error updating tool hidden parameters",{serverName:s,toolName:r,error:m}),{success:!1,error:m instanceof Error?m.message:"Unknown error occurred"}}},Cs=async(s,r)=>{var t;try{const n=await $e(`/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"}}},St=Object.freeze(Object.defineProperty({__proto__:null,callTool:Ns,resetToolDescription:Cs,toggleTool:Ct,updateToolDescription:ws,updateToolHiddenParams:ks},Symbol.toStringTag,{value:"Module"})),Ss=({schema:s,onSubmit:r,onCancel:t,loading:n=!1,storageKey:m,title:l})=>{const{t:a}=ae(),[j,x]=c.useState({}),[E,d]=c.useState({}),[f,o]=c.useState(!1),[h,O]=c.useState(""),[v,C]=c.useState(""),z=c.useMemo(()=>(b=>{const S=u=>{if(typeof u=="object"&&u!==null){const g=u;return{type:g.type||"string",description:g.description,enum:g.enum,default:g.default,properties:g.properties?Object.fromEntries(Object.entries(g.properties).map(([p,w])=>[p,S(w)])):void 0,required:g.required,items:g.items?S(g.items):void 0}}return{type:"string"}};return{type:b.type,properties:b.properties?Object.fromEntries(Object.entries(b.properties).map(([u,g])=>[u,S(g)])):void 0,required:b.required}})(s),[s]);c.useEffect(()=>{const y=(S,u="")=>{const g={};return S.type==="object"&&S.properties&&Object.entries(S.properties).forEach(([p,w])=>{const $=u?`${u}.${p}`:p;w.default!==void 0?g[p]=w.default:w.type==="string"?g[p]="":w.type==="number"||w.type==="integer"?g[p]=0:w.type==="boolean"?g[p]=!1:w.type==="array"?g[p]=[]:w.type==="object"&&(w.properties?g[p]=y(w,$):g[p]={})}),g};let b=y(z);if(m)try{const S=localStorage.getItem(m);if(S){const u=JSON.parse(S);b={...b,...u}}}catch(S){console.warn("Failed to load saved form data:",S)}x(b)},[z,m]),c.useEffect(()=>{f&&Object.keys(j).length>0&&(O(JSON.stringify(j,null,2)),C(""))},[f,j]);const _=y=>{O(y),C("");try{const b=JSON.parse(y);if(x(b),m)try{localStorage.setItem(m,JSON.stringify(b))}catch(S){console.warn("Failed to save form data to localStorage:",S)}}catch{C(a("tool.invalidJsonFormat"))}},A=()=>{O(JSON.stringify(j,null,2)),C(""),o(!0)},I=()=>{if(h.trim())try{const y=JSON.parse(h);x(y),C(""),o(!1)}catch{C(a("tool.fixJsonBeforeSwitching"));return}else o(!1)},M=(y,b)=>{x(S=>{const u={...S},g=y.split(".");let p=u;for(let $=0;$<g.length-1;$++){const R=g[$];if(R==="__proto__"||R==="constructor"||R==="prototype")return S;p[R]||(p[R]={}),p=p[R]}const w=g[g.length-1];if(!w||w==="__proto__"||w==="constructor"||w==="prototype")return S;if(p[w]=b,m)try{localStorage.setItem(m,JSON.stringify(u))}catch($){console.warn("Failed to save form data to localStorage:",$)}return u}),E[y]&&d(S=>{const u={...S};return delete u[y],u})},q=()=>{const y={},b=(S,u,g="")=>{S.type==="object"&&S.properties&&Object.entries(S.properties).forEach(([p,w])=>{var W;const $=g?`${g}.${p}`:p,R=u==null?void 0:u[p];if((W=S.required)!=null&&W.includes(p)&&(R==null||R===""||Array.isArray(R)&&R.length===0)){y[$]=`${p} is required`;return}R!=null&&R!==""&&(w.type==="string"&&typeof R!="string"?y[$]=`${p} must be a string`:w.type==="number"&&typeof R!="number"?y[$]=`${p} must be a number`:w.type==="integer"&&(!Number.isInteger(R)||typeof R!="number")?y[$]=`${p} must be an integer`:w.type==="boolean"&&typeof R!="boolean"?y[$]=`${p} must be a boolean`:w.type==="array"&&Array.isArray(R)?w.items&&R.forEach((X,Y)=>{var Q;((Q=w.items)==null?void 0:Q.type)==="object"&&w.items.properties&&b(w.items,X,`${$}.${Y}`)}):w.type==="object"&&typeof R=="object"&&b(w,R,$))})};return b(z,j),d(y),Object.keys(y).length===0},T=y=>{y.preventDefault(),q()&&r(j)},V=(y,b)=>b.split(".").reduce((S,u)=>S==null?void 0:S[u],y),K=(y,b,S,u)=>{const g=S==null?void 0:S[y];return b.type==="string"?b.enum?e.jsxs("select",{value:g||"",onChange:p=>u(p.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")}),b.enum.map((p,w)=>e.jsx("option",{value:p,children:p},w))]}):e.jsx("input",{type:"text",value:g||"",onChange:p=>u(p.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:b.description||a("tool.enterKey",{key:y})}):b.type==="number"||b.type==="integer"?e.jsx("input",{type:"number",step:b.type==="integer"?"1":"any",value:g??"",onChange:p=>{const w=p.target.value===""?"":b.type==="integer"?parseInt(p.target.value):parseFloat(p.target.value);u(w)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):b.type==="boolean"?e.jsx("input",{type:"checkbox",checked:g||!1,onChange:p=>u(p.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:g||"",onChange:p=>u(p.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:b.description||a("tool.enterKey",{key:y})})},ee=(y,b,S="")=>{var w,$,R,W,X,Y,Q,k,L,re,ne,le,oe,J;const u=S?`${S}.${y}`:y,g=V(j,u),p=E[u];if(b.type==="array"){const F=V(j,u)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?($=(w=V(z,S))==null?void 0:w.required)==null?void 0:$.includes(y):(R=z.required)==null?void 0:R.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.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,se)=>{var pe,de,ue;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:se+1})}),e.jsx("button",{type:"button",onClick:()=>{const N=[...F];N.splice(se,1),M(u,N)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((pe=b.items)==null?void 0:pe.type)==="string"&&b.items.enum?e.jsxs("select",{value:H||"",onChange:N=>{const U=[...F];U[se]=N.target.value,M(u,U)},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")}),b.items.enum.map((N,U)=>e.jsx("option",{value:N,children:N},U))]}):((de=b.items)==null?void 0:de.type)==="object"&&b.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(b.items.properties).map(([N,U])=>{var Z,G;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[N,((G=(Z=b.items)==null?void 0:Z.required)==null?void 0:G.includes(N))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(N,U,H,ge=>{const he=[...F];he[se]={...he[se],[N]:ge},M(u,he)})]},N)})}):e.jsx("input",{type:"text",value:H||"",onChange:N=>{const U=[...F];U[se]=N.target.value,M(u,U)},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:((ue=b.items)==null?void 0:ue.type)||"value"})})]},se)}),e.jsx("button",{type:"button",onClick:()=>{var se;const H=((se=b.items)==null?void 0:se.type)==="object"?{}:"";M(u,[...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})})]}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u)}return b.type==="object"?b.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?(X=(W=V(z,S))==null?void 0:W.required)==null?void 0:X.includes(y):(Y=z.required)==null?void 0:Y.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.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(b.properties).map(([F,H])=>ee(F,H,u))}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?(k=(Q=V(z,S))==null?void 0:Q.required)==null?void 0:k.includes(y):(L=z.required)==null?void 0:L.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)"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("textarea",{value:typeof g=="object"?JSON.stringify(g,null,2):g||"{}",onChange:F=>{try{const H=JSON.parse(F.target.value);M(u,H)}catch{M(u,F.target.value)}},placeholder:`{
3
- "key": "value"
4
- }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${p?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):b.type==="string"?b.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?!1:(re=z.required)==null?void 0:re.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsxs("select",{value:g||"",onChange:F=>M(u,F.target.value),className:`w-full border rounded-md px-3 py-2 ${p?"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")}),b.enum.map((F,H)=>e.jsx("option",{value:F,children:F},H))]}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?!1:(ne=z.required)==null?void 0:ne.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"text",value:g||"",onChange:F=>M(u,F.target.value),className:`w-full border rounded-md px-3 py-2 ${p?"border-red":"border-gray-200"} focus:outline-none form-input`}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):b.type==="number"||b.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,(S?!1:(le=z.required)==null?void 0:le.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"number",step:b.type==="integer"?"1":"any",value:g??"",onChange:F=>{const H=F.target.value===""?"":b.type==="integer"?parseInt(F.target.value):parseFloat(F.target.value);M(u,H)},className:`w-full border rounded-md px-3 py-2 form-input ${p?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):b.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:g||!1,onChange:F=>M(u,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,(S?!1:(oe=z.required)==null?void 0:oe.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:b.description}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(S?!1:(J=z.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:["(",b.type,")"]})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"text",value:g||"",onChange:F=>M(u,F.target.value),placeholder:a("tool.enterValue",{type:b.type}),className:`w-full border rounded-md px-3 py-2 ${p?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),p&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:p})]},u)};return z.properties?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-3",children:[e.jsx("h6",{className:"text-md font-medium text-gray-900",children:l}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:I,className:`hub-btn sm ${f?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:A,className:`hub-btn sm ${f?"primary":""}`,children:a("tool.jsonMode")})]})]}),f?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:h,onChange:y=>_(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(h);r(y)}catch{C(a("tool.invalidJsonFormat"))}},disabled:n||!!v,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:T,className:"space-y-4",children:[Object.entries(z.properties||{}).map(([y,b])=>ee(y,b)),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")})]})]})},Pt=({result:s,onClose:r})=>{const{t}=ae(),n=s.content,m=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",l=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(h=>l(h));if(typeof d!="object")return[];const f=[];d.type==="image"&&d.data&&f.push({data:String(d.data),mimeType:m(d.mimeType||d.mime_type)});const o=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return o&&f.push({data:String(o),mimeType:m(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&f.push(...l(d.image)),Array.isArray(d.images)&&f.push(...l(d.images)),Array.isArray(d.content)&&f.push(...l(d.content)),f},a=d=>{const f=[];try{const O=JSON.parse(d);if(f.push(...l(O)),f.length>0)return f}catch{}const o=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let h;for(;(h=o.exec(d))!==null;){const O=`image/${h[1]==="jpg"?"jpeg":h[1]}`;f.push({data:h[2],mimeType:O})}return f},j=d=>{try{const f=JSON.parse(d),o=h=>{if(Array.isArray(h))return h.map(o);if(h&&typeof h=="object"){const O={};for(const[v,C]of Object.entries(h))typeof C=="string"&&v.toLowerCase().includes("base64")?O[v]="[base64 omitted]":O[v]=o(C);return O}return h};return JSON.stringify(o(f),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},x=d=>Array.isArray(d)?d.map((f,o)=>e.jsx("div",{className:"mb-3 last:mb-0",children:E(f)},o)):E(d),E=d=>{if(typeof d=="string"){const f=a(d),o=j(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const f=a(d.text),o=j(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(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 f=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(f,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(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{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")}),x(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 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")}),x(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")})})]})})]})},fe=({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(Qs,{size:14,className:n?"animate-spin":""})}),Et=(s,r,t,n,m)=>(t?s.filter(l=>l!==r):[...s,r]).filter(l=>n.includes(l)&&!m.includes(l));function Dt(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 zt=({tool:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:m,cost:l})=>{var de,ue;const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[E,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,C]=c.useState(null),[z,_]=c.useState(!1),[A,I]=c.useState(!1),[M,q]=c.useState(s.description||""),T=c.useRef(null),V=c.useRef(null),[K,ee]=c.useState(0),[y,b]=c.useState(!1),[S,u]=c.useState(s.hiddenParams||[]),[g,p]=c.useState(!1);c.useEffect(()=>{z&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[z,K]),c.useEffect(()=>{!z&&V.current&&ee(V.current.offsetWidth)},[z,M]),c.useEffect(()=>{q(s.description||"")},[s.description]),c.useEffect(()=>{u(s.hiddenParams||[])},[s.hiddenParams]);const w=Object.keys(((de=s.inputSchema)==null?void 0:de.properties)||{}),$=Array.isArray((ue=s.inputSchema)==null?void 0:ue.required)?s.inputSchema.required:[],R=async(N,U)=>{if(t)return;const Z=Et(S,N,U,w,$);p(!0);try{const G=await ks(r,s.name,Z);G.success?u(G.hiddenParams??Z):j(G.error||a("tool.hiddenParamsFailed"),"error")}finally{p(!1)}},W=s.name.replace(r+x,""),X=ht(s,a("tool.noDescription")),Y=X.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:X.defaultDescription}):void 0,Q=c.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),k=c.useCallback(()=>{localStorage.removeItem(Q())},[Q]),L=N=>{!t&&n&&n(s.name,N)},re=()=>{t||_(!0)},ne=async()=>{if(!t)try{const N=await ws(r,s.name,M);N.success?(_(!1),m&&m(s.name,M)):(q(s.description||""),console.error("Failed to update tool description:",N.error))}catch(N){console.error("Error updating tool description:",N),q(s.description||""),_(!1)}},le=N=>{q(N.target.value)},oe=async()=>{if(!t){I(!0);try{const N=await Cs(r,s.name);if(N.success){const U=N.description||"";q(U),_(!1),m==null||m(s.name,U,{restored:!0})}else j(N.error||a("tool.restoreDefaultFailed"),"error")}catch(N){console.error("Error resetting tool description:",N),j(a("tool.restoreDefaultFailed"),"error")}finally{I(!1)}}},J=N=>{N.key==="Enter"?ne():N.key==="Escape"&&(q(s.description||""),_(!1))},F=async N=>{N.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3)}catch(Z){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Z)}document.body.removeChild(U)}}catch(U){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},H=async N=>{O(!0);try{N=Object.fromEntries(Object.entries(N).filter(([Z,G])=>!Dt(G)));const U=await Ns({toolName:s.name,arguments:N},r);C(U)}catch(U){C({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{O(!1)}},se=()=>{o(!1),k(),C(null)},pe=()=>{C(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:N=>{N.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:W}),e.jsx("button",{className:"hub-icon-btn sm",onClick:F,title:a("common.copy"),children:y?e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:M,onChange:le,onKeyDown:J,onClick:N=>N.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:N=>{N.stopPropagation(),ne()},disabled:A,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:N=>{N.stopPropagation(),oe()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:V,title:Y,children:X.currentDescription}),X.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:Y,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:N=>{N.stopPropagation(),re()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:N=>{N.stopPropagation(),oe()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:N=>N.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled??!0,onCheckedChange:L,disabled:h||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${W}`})}),e.jsxs("button",{onClick:N=>{N.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"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:[X.hasDescriptionOverride&&X.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:X.defaultDescription})]}),!f&&w.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:4},children:a("tool.visibleParams")}),e.jsx("div",{style:{fontSize:11.5,color:"var(--hub-ink-3)",marginBottom:6},children:a("tool.visibleParamsHelp")}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 14px"},children:w.map(N=>{const U=$.includes(N);return e.jsxs("label",{className:"hub-mono",style:{fontSize:11.5,display:"flex",alignItems:"center",gap:5},title:U?a("tool.requiredParam"):void 0,children:[e.jsx("input",{type:"checkbox",checked:U||!S.includes(N),disabled:t||U||g,onChange:Z=>R(N,Z.target.checked)}),N,U&&" *"]},N)})})]}),!f&&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)})]}),f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:s.inputSchema||{type:"object"},onSubmit:H,onCancel:se,loading:h,storageKey:Q(),title:a("tool.runToolWithName",{name:W})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Pt,{result:v,onClose:pe})})]})]})]})},Tt=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",n=await ie(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"}}},Ps=async(s,r)=>{try{const t=await ie(`/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"}}},$t=async(s,r,t)=>{try{const n=await ie(`/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"}}},Es=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Ds=async(s,r)=>{var t;try{const n=await $e(`/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"}}},It=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:Tt,getPrompt:Ps,resetPromptDescription:Ds,togglePrompt:$t,updatePromptDescription:Es},Symbol.toStringTag,{value:"Module"})),cs=({result:s,onClose:r})=>{const{t}=ae(),n=m=>{if(typeof m=="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:m})});if(typeof m=="object"&&m!==null){if(m.description||m.messages)return e.jsxs("div",{className:"space-y-4",children:[m.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:m.description})})]}),m.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:m.messages.map((l,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:[l.role,":"]})}),typeof l.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content}):typeof l.content=="object"&&l.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(l.content,null,2)})]},a))})]})]});try{const l=typeof m=="string"?JSON.parse(m):m;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(l,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(m)})})}}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(m)})})};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(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{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")})})]})})]})},Rt=({prompt:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:m,cost:l})=>{const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[E,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,C]=c.useState(null),[z,_]=c.useState(!1),[A,I]=c.useState(!1),[M,q]=c.useState(s.description||""),T=c.useRef(null),V=c.useRef(null),[K,ee]=c.useState(0);c.useEffect(()=>{z&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[z,K]),c.useEffect(()=>{!z&&V.current&&ee(V.current.offsetWidth)},[z,M]),c.useEffect(()=>{q(s.description||"")},[s.description]);const y=c.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),b=c.useCallback(()=>{localStorage.removeItem(y())},[y]),S=k=>{!t&&n&&n(s.name,k)},u=()=>{t||_(!0)},g=async()=>{if(!t){_(!1);try{const k=await Es(r,s.name,M);k.success?m&&m(s.name,M):(j(k.error||a("prompt.descriptionUpdateFailed"),"error"),q(s.description||""))}catch(k){console.error("Error updating prompt description:",k),j(a("prompt.descriptionUpdateFailed"),"error"),q(s.description||"")}}},p=async()=>{if(!t){I(!0);try{const k=await Ds(r,s.name);if(k.success){const L=k.description||"";q(L),_(!1),m==null||m(s.name,L,{restored:!0})}else j(k.error||a("prompt.restoreDefaultFailed"),"error")}catch(k){console.error("Error resetting prompt description:",k),j(a("prompt.restoreDefaultFailed"),"error")}finally{I(!1)}}},w=k=>{q(k.target.value)},$=k=>{k.key==="Enter"?g():k.key==="Escape"&&(q(s.description||""),_(!1))},R=async k=>{O(!0);try{const L=await Ps({promptName:s.name,arguments:k},r);console.log("GetPrompt result:",L),C({success:L.success,data:L.data,error:L.error})}catch(L){C({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{O(!1)}},W=()=>{o(!1),b(),C(null)},X=()=>{C(null)},Y=s.name.replace(r+x,""),Q=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const k={},L=[];return s.arguments.forEach(re=>{k[re.name]={type:"string",description:re.description||""},re.required&&L.push(re.name)}),{type:"object",properties:k,required:L}};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:Y}),s.title&&e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.title}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:M,onChange:w,onKeyDown:$,onClick:k=>k.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:k=>{k.stopPropagation(),g()},disabled:A,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:k=>{k.stopPropagation(),p()},disabled:A,loading:A})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:V,children:M||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:k=>{k.stopPropagation(),u()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:k=>{k.stopPropagation(),p()},disabled:A,loading:A})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:k=>k.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ee,{checked:s.enabled,onCheckedChange:S,disabled:h||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${Y}`})}),e.jsxs("button",{onClick:k=>{k.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"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:[f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:Q(),onSubmit:R,onCancel:W,loading:h,storageKey:y(),title:a("prompt.runPromptWithName",{name:Y})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(cs,{result:v,onClose:X})})]}),!f&&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((k,L)=>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:k.name}),k.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),k.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:k.description})]}),k.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:k.title})]},L))})]}),!f&&v&&e.jsx("div",{children:e.jsx(cs,{result:v,onClose:X})})]})]})},Ft=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:n,cost:m})=>{const{t:l}=ae(),[a,j]=c.useState(!1),[x,E]=c.useState(!1),[d,f]=c.useState(!1),[o,h]=c.useState(s.description||""),O=c.useRef(null),v=c.useRef(null),[C,z]=c.useState(0);c.useEffect(()=>{x&&O.current&&(O.current.focus(),C>0&&(O.current.style.width=`${C+20}px`))},[x,C]),c.useEffect(()=>{!x&&v.current&&z(v.current.offsetWidth)},[x,o]),c.useEffect(()=>{h(s.description||"")},[s.description]);const _=s.name||s.uri,A=T=>{!r&&t&&t(s.uri,T)},I=async()=>{r||(E(!1),n&&await n(s.uri,o))},M=async()=>{if(!r){f(!0);try{await(n==null?void 0:n(s.uri,"",{restored:!0})),E(!1)}finally{f(!1)}}},q=T=>{T.key==="Enter"?I():T.key==="Escape"&&(h(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:_}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:x?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:O,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:C>0?`${C+20}px`:160,minWidth:80},value:o,onChange:T=>h(T.target.value),onKeyDown:q,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),I()},disabled:d,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),M()},disabled:d,loading:d})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:o||l("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),E(!0)},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),M()},disabled:d,loading:d})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[m!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:l("cost.estimate"),children:["Σ ",ce(m)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled!==!1,onCheckedChange:A,disabled:r,size:"card","aria-label":`${l(s.enabled!==!1?"server.disable":"server.enable")} ${_}`})}),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:[l("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},At={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)]"}},Re=s=>s==="public"||s==="group"?s:"private",Ot=(s,r)=>{const t=Re(r),n=At[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=Re(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},ds=({isLoading:s,children:r,className:t,overlayStyle:n,spinnerSize:m=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(be,{size:m,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),us=({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"})}),ms=(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,Mt="text/html;profile=mcp-app",ps=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Vt=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(n=>ps(n._meta))||(t=s.resources)!=null&&t.some(n=>{var m;return((m=n.uri)==null?void 0:m.startsWith("ui://"))||n.mimeType===Mt||ps(n._meta)}))},Ut=({server:s,cost:r,onRemove:t,onEdit:n,onDuplicate:m,isDuplicating:l=!1,onToggle:a,onVisibilityChange:j,onRefresh:x,onReload:E,onReinstall:d,onOAuthDisconnect:f})=>{var Ve,Ue,Be,Le,Je,We,qe,He,Ke,Ge,Xe,Ye,Ze,Qe,es,ss,ts,rs,ns,as,os,is;const{t:o}=ae(),{showToast:h}=we(),{exportMCPSettings:O,installConfig:v}=Pe(),{auth:C}=Xs(),z=((Ve=v==null?void 0:v.baseUrl)==null?void 0:Ve.replace(/\/+$/,""))||"",[_,A]=c.useState(!1),[I,M]=c.useState(null),[q,T]=c.useState(!1),[V,K]=c.useState(!1),[ee,y]=c.useState(!1),[b,S]=c.useState(null),[u,g]=c.useState(!1),[p,w]=c.useState(!1),[$,R]=c.useState(!1),[W,X]=c.useState(!1),[Y,Q]=c.useState(!1),[k,L]=c.useState(!1),[re,ne]=c.useState(!1),[le,oe]=c.useState(!1),J=c.useRef(null),F=c.useRef(null);c.useEffect(()=>{const i=D=>{J.current&&!J.current.contains(D.target)&&L(!1),F.current&&!F.current.contains(D.target)&&ne(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const H=((Ue=s.tools)==null?void 0:Ue.length)||0,se=((Be=s.tools)==null?void 0:Be.filter(i=>i.enabled!==!1).length)||0,pe=((Le=s.prompts)==null?void 0:Le.length)||0,de=((Je=s.prompts)==null?void 0:Je.filter(i=>i.enabled!==!1).length)||0,ue=((We=s.resources)==null?void 0:We.length)||0,N=((qe=s.resources)==null?void 0:qe.filter(i=>i.enabled!==!1).length)||0,U=Vt(s),Z=s.enabled!==!1,G=gt(s,C.user),ge=((He=s.config)==null?void 0:He.command)==="npx"||((Ke=s.config)==null?void 0:Ke.command)==="uvx",he=ge?s.packageVersion:void 0,De=he||s.version,zs=!!(((Xe=(Ge=s.config)==null?void 0:Ge.oauth)==null?void 0:Xe.identityMode)!=="personal"&&((Ye=s.oauth)!=null&&Ye.connected)&&f),Ts=async i=>{if(!(!G||u||!a)){g(!0);try{await a(s,i)}finally{g(!1)}}},$s=async i=>{if(i.stopPropagation(),L(!1),!(!G||$||!E)){R(!0);try{await E(s)?h(o("server.reloadSuccess")||"Server reloaded successfully","success"):h(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{R(!1)}}},Is=async()=>{if(L(!1),!(!G||W||!d)){X(!0);try{await d(s)?h(o("server.reinstallSuccess")||"Server reinstall initiated","success"):h(o("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{X(!1)}}},Rs=async()=>{if(L(!1),!(!G||Y||!f)){Q(!0);try{await f(s)?h(o("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):h(o("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{Q(!1)}}},Fs=async i=>{var P;if(i.stopPropagation(),!G||p||!j)return;const D=i.target.value;if(D!==Re(s.visibility??((P=s.config)==null?void 0:P.visibility))){w(!0);try{await j(s,D)}finally{w(!1)}}},As=async i=>{if(i.stopPropagation(),!s.error)return;await ls(s.error)?(oe(!0),h(o("common.copySuccess")||"Copied","success"),setTimeout(()=>oe(!1),1500)):h(o("common.copyFailed")||"Copy failed","error")},Os=async i=>{var D,P;if(i.stopPropagation(),L(!1),!!G)try{const B=await O(s.name),te=(P=(D=B==null?void 0:B.data)==null?void 0:D.mcpServers)==null?void 0:P[s.name];if(!B||!B.success||!te){h((B==null?void 0:B.message)||o("common.copyFailed")||"Copy failed","error");return}S(bt(s.name,te))}catch(B){console.error("Error copying server configuration:",B),h(o("common.copyFailed")||"Copy failed","error")}},_s=i=>{var D;if(i.stopPropagation(),(D=s.oauth)!=null&&D.authorizationUrl){const te=window.screen.width/2-300,me=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${te},top=${me}`),h(o("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&h(o("status.oauthClientIdHint"),"warning")}},Ms=async(i,D)=>{try{const{toggleTool:P}=await Ne(async()=>{const{toggleTool:te}=await Promise.resolve().then(()=>St);return{toggleTool:te}},void 0,import.meta.url),B=await P(s.name,i,D);B.success?(h(o(D?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(P){console.error(P),h(o("tool.toggleFailed"),"error")}},Vs=async(i,D)=>{try{const{togglePrompt:P}=await Ne(async()=>{const{togglePrompt:te}=await Promise.resolve().then(()=>It);return{togglePrompt:te}},void 0,import.meta.url),B=await P(s.name,i,D);B.success?(h(o(D?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(P){console.error(P),h(o("tool.toggleFailed"),"error")}},Us=async(i,D)=>{try{const{toggleResource:P}=await Ne(async()=>{const{toggleResource:te}=await import("./resourceService-8K1eUH8N.js");return{toggleResource:te}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),B=await P(s.name,i,D);B.success?(h(o(D?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(P){console.error(P),h(o("tool.toggleFailed"),"error")}},Bs=(i,D,P)=>{h(P!=null&&P.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),x==null||x()},Ls=(i,D,P)=>{h(P!=null&&P.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),x==null||x()},Js=async(i,D,P)=>{try{const{updateResourceDescription:B,resetResourceDescription:te}=await Ne(async()=>{const{updateResourceDescription:qs,resetResourceDescription:Hs}=await import("./resourceService-8K1eUH8N.js");return{updateResourceDescription:qs,resetResourceDescription:Hs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),me=P!=null&&P.restored?await te(s.name,i):await B(s.name,i,D);me.success?(h(P!=null&&P.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),x==null||x()):h(me.error||(P!=null&&P.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(B){console.error(B),h(P!=null&&P.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var P;const i=s.config;if(!i)return"";if(i.url)return i.url;const D=[];return i.command&&D.push(i.command),(P=i.args)!=null&&P.length&&D.push(...i.args),D.join(" ")})();const Fe=`${z}/mcp/${s.name}`,Ae=`${z}/api/${s.name}`,Oe=async i=>{const D=await ls(i);h(D?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",D?"success":"error")},_e=(i,D)=>o(i,D),xe=Ot(_e,s.visibility??((Ze=s.config)==null?void 0:Ze.visibility)),Ws=_t(_e,xe.value),Me=[{key:"tools",icon:et,total:H,enabled:se,label:o("server.tools")},{key:"prompts",icon:st,total:pe,enabled:de,label:o("server.prompts")},{key:"resources",icon:tt,total:ue,enabled:N,label:o("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>A(!_),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:_?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"hub-mono min-w-0 max-w-full truncate",title:s.name,style:{fontSize:13.5,color:Z?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),De&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o(he?"server.packageVersion":"server.reportedVersion")}: ${De}`,style:{fontSize:11},children:e.jsxs("span",{className:"truncate",children:["v",De]})}),ge&&s.updateAvailable&&s.latestVersion&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o("server.updateAvailable")}: ${s.latestVersion}`,style:{fontSize:11,color:"var(--hub-warn)"},children:e.jsxs("span",{className:"truncate",children:["↑ ",s.latestVersion]})}),U&&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(D=>!D)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ce,{size:14})}),re&&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:As,className:"hub-icon-btn sm",title:o("common.copy"),children:le?e.jsx(je,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>ne(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(ze,{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})})]})]})]}),!!((es=(Qe=s.config)==null?void 0:Qe.credentialTemplate)!=null&&es.length)&&e.jsxs(Ks,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[o("credentials.personalBadge")," · ",o("credentials.manage")]}),((ss=s.config)==null?void 0:ss.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.jsxs("div",{className:`hub-server-card-status-cell min-w-0${Z&&s.recovery?" hub-server-card-recovering":""}`,children:[((rs=(ts=s.config)==null?void 0:ts.oauth)==null?void 0:rs.identityMode)==="personal"?e.jsx(kt,{serverName:s.name,enabled:Z}):e.jsx(pt,{status:s.status,enabled:s.enabled,startOnDemand:((ns=s.config)==null?void 0:ns.startOnDemand)===!0,onAuthClick:_s,className:"hub-server-card-status"}),Z&&s.recovery&&e.jsxs("div",{className:"text-xs mt-1",style:{color:"var(--hub-ink-3)",maxWidth:160},children:[e.jsx("div",{children:s.recovery.nextAttemptAt?o("server.retryScheduled",{time:new Date(s.recovery.nextAttemptAt).toLocaleTimeString(void 0,{hour12:!1})}):o("server.reconnecting")}),s.recovery.lastAttemptAt&&e.jsx("div",{children:o("server.lastRetry",{count:s.recovery.attempts,time:new Date(s.recovery.lastAttemptAt).toLocaleTimeString(void 0,{hour12:!1})})})]})]}),e.jsxs("div",{className:"hub-server-card-transport-cell min-w-0",children:[(as=s.config)!=null&&as.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:ms(o,s.config.type)??void 0,children:ms(o,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"}),((os=s.config)==null?void 0:os.type)!=="openapi"&&e.jsxs("span",{className:"hub-server-card-protocol",title:o("server.protocolVersion"),children:["MCP"," ",Z&&s.status==="connected"&&s.protocolVersion?e.jsx("span",{className:"whitespace-nowrap",children:s.protocolVersion}):o("server.protocolVersionUnknown")]})]}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:i=>i.stopPropagation(),children:G&&j?e.jsx(ds,{isLoading:p,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:xe.value,onChange:Fs,disabled:p,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:xe.longLabel,children:Ws.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] ${xe.className}`,title:xe.longLabel,children:xe.shortLabel})}),Me.map(({key:i,icon:D,total:P,enabled:B,label:te})=>{const me=P===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${me?"is-empty":""}`,title:`${te}: ${B}/${P}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(us,{icon:D})}),e.jsx("span",{className:"hub-server-capability-value",children:me?"0":`${B}/${P}`})]},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(ds,{isLoading:u,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ee,{checked:Z,onCheckedChange:Ts,disabled:u||!G,size:"compact","aria-label":`${o(Z?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:J,children:[G&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),L(D=>!D)},"aria-label":"More","aria-busy":l,children:l?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(rt,{size:14})}),G&&k&&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(),L(!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(nt,{size:13})," ",o("server.edit")]}),m&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!l&&m(s)},disabled:l,"aria-busy":l,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:[l?e.jsx(be,{size:13,className:"animate-spin"}):e.jsx(at,{size:13})," ",o("server.duplicate")]}),e.jsxs("button",{onClick:Os,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),E&&e.jsxs("button",{onClick:$s,disabled:$||u||!Z,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(be,{size:13})," ",o("server.reload")]}),d&&ge&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!G||W||!Z)&&K(!0)},disabled:W||u||!Z,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(ot,{size:13})," ",o("server.reinstall")]}),zs&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!G||Y)&&y(!0)},disabled:Y,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(it,{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(),L(!1),T(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(lt,{size:13})," ",o("server.delete")]})]})]})]}),_&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[((is=s.config)==null?void 0:is.description)&&e.jsxs("section",{className:"mb-3","aria-labelledby":`server-about-${s.name}`,children:[e.jsx("h3",{id:`server-about-${s.name}`,className:"text-[11px] font-medium tracking-wide uppercase",style:{color:"var(--hub-ink-3)",marginBottom:6},children:o("server.description")}),e.jsx("p",{className:"text-[13px] leading-5 whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.config.description})]}),e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Me.map(i=>{const D=I===i.key,P=i.icon;return e.jsxs("button",{onClick:()=>M(D?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:D?"var(--hub-surface)":"transparent",border:"1px solid "+(D?"var(--hub-line)":"transparent"),color:D?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(us,{icon:P}),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: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.copyUrl"),children:e.jsx(ye,{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:Ae,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Ae)},title:o("common.copyOpenApiUrl"),children:e.jsx(ye,{size:12})})]})]})]}),I==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((i,D)=>D.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,D)=>{var P;return e.jsx(zt,{server:s.name,tool:i,readOnly:!G,onToggle:Ms,onDescriptionUpdate:Bs,cost:(P=r==null?void 0:r.items.find(B=>B.kind==="tool"&&B.name===i.name))==null?void 0:P.cost},D)})}),I==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,D)=>{var P;return e.jsx(Rt,{server:s.name,prompt:i,readOnly:!G,onToggle:Vs,onDescriptionUpdate:Ls,cost:(P=r==null?void 0:r.items.find(B=>B.kind==="prompt"&&B.name===i.name))==null?void 0:P.cost},D)})}),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,D)=>{var P;return e.jsx(Ft,{resource:i,readOnly:!G,onToggle:Us,onDescriptionUpdate:Js,cost:(P=r==null?void 0:r.items.find(B=>B.kind==="resource"&&B.name===i.uri))==null?void 0:P.cost},`${i.uri}-${D}`)})})})]})]}),e.jsx(xt,{isOpen:b!==null,target:b,onClose:()=>S(null)}),e.jsx(ft,{isOpen:q,onClose:()=>T(!1),onConfirm:()=>{t(s.name),T(!1)},serverName:s.name}),e.jsx(Te,{isOpen:V,onClose:()=>K(!1),onConfirm:()=>{K(!1),Is()},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(Te,{isOpen:ee,onClose:()=>y(!1),onConfirm:()=>{y(!1),Rs()},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"})]})},hs="-copy",Bt=s=>{const r=Math.max(yt-hs.length,0);return`${s.slice(0,r)}${hs}`},Lt=s=>{const{oauth:r,...t}=s.config??{},{accessToken:n,refreshToken:m,pendingAuthorization:l,...a}=r??{};return{name:Bt(s.name),status:"disconnected",config:{...t,...Object.keys(a).length>0?{oauth:a}:{}}}},Jt=(s,r)=>{if(s)return Object.fromEntries(Object.entries(s).map(([t,n])=>[r(t),n]))},Wt=(s,r,t={})=>{const n=r.config;if(!n)return s;const m=t.nameSeparator||"-",l=new Set((r.tools??[]).map(f=>f.name)),a=f=>`${s.name}${f.slice(r.name.length)}`,j=`${r.name}${m}`,x=n.tools?Object.fromEntries(Object.entries(n.tools).flatMap(([f,o])=>l.has(f)?[[a(f),o]]:f.startsWith(j)&&l.has(`${j}${f}`)?[[f,o]]:f.startsWith(j)?[]:[[f,o]])):void 0,E=Jt(n.prompts,f=>f.startsWith(j)?a(f):f),d={};return x&&Object.keys(x).length>0&&(d.tools=x),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}}},xs=(s,r)=>s===r?"commit":"stale",qt=({onAdd:s,duplicateSource:r=null,onDuplicateCancel:t})=>{const{t:n}=ae(),{nameSeparator:m}=Pe(),[l,a]=c.useState(!1),[j,x]=c.useState(null),[E,d]=c.useState(!1),[f,o]=c.useState(null),[h,O]=c.useState([]),v=c.useMemo(()=>r?Lt(r):null,[r]),C=l||r!==null,z=()=>{x(null),d(!1),o(null)},_=()=>{a(!1),z(),r&&(t==null||t())},A=()=>{if(C){_();return}a(!0),z()},I=async()=>{f&&(await M(f),d(!1),o(null))},M=async T=>{try{x(null);const V=await ie("/servers",T);if(!V.success){V&&V.message?x(V.message):x(n("server.addError"));return}_(),s()}catch(V){console.error("Error adding server:",V),navigator.onLine?V instanceof TypeError&&(V.message.includes("NetworkError")||V.message.includes("Failed to fetch"))?x(n("errors.serverConnection")):x(n("errors.serverAdd")):x(n("errors.network"))}},q=async T=>{try{const V=r?Wt(T,r,{nameSeparator:m}):T,K=jt(V);K.length>0?(O(K),o(V),d(!0)):await M(V)}catch(V){console.error("Error processing server submission:",V),x(n("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:A,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),n("server.add")]}),C&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(vs,{onSubmit:q,onCancel:_,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:h.map((T,V)=>e.jsxs("li",{className:"font-mono",children:["$",`{${T}}`]},V))})]})]})}),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")})]})]})})]})},Ht=({server:s,onEdit:r,onCancel:t})=>{const{t:n}=ae(),[m,l]=c.useState(null),a=async j=>{try{l(null);const x=encodeURIComponent(s.name),E=j.name&&j.name!==s.name,d={config:j.config,...E?{newName:j.name}:{}},f=await ve(`/servers/${x}`,d);if(!f.success){f&&f.message?l(f.message):l(n("server.updateError",{serverName:s.name}));return}r()}catch(x){console.error("Error updating server:",x),navigator.onLine?x instanceof TypeError&&(x.message.includes("NetworkError")||x.message.includes("Failed to fetch"))?l(n("errors.serverConnection")):l(n("errors.serverUpdate",{serverName:s.name})):l(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(vs,{onSubmit:a,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:m},s.name)})},Kt=({onSuccess:s,onCancel:r})=>{const{t}=ae(),[n,m]=c.useState(!1),[l,a]=c.useState(!1),[j,x]=c.useState(null),[E,d]=c.useState(null),[f,o]=c.useState(!1),[h,O]=c.useState(null),[v,C]=c.useState(""),[z,_]=c.useState(!1),[A,I]=c.useState(""),M=u=>{u.preventDefault(),m(!0)},q=u=>{u.preventDefault(),m(!1)},T=u=>{u.preventDefault(),m(!1);const g=u.dataTransfer.files;if(g.length>0){const p=g[0];p.name.endsWith(".mcpb")?(d(p),x(null)):x(t("mcpb.invalidFileType"))}},V=u=>{const g=u.target.files;if(g&&g.length>0){const p=g[0];p.name.endsWith(".mcpb")?(d(p),x(null)):x(t("mcpb.invalidFileType"))}},K=async()=>{if(!E){x(t("mcpb.noFileSelected"));return}a(!0),x(null);try{const u=new FormData;u.append("mcpbFile",E);const g=await Ys(Zs("/mcpb/upload"),{method:"POST",body:u}),p=await g.json();if(!g.ok)throw new Error(p.message||`HTTP error! Status: ${g.status}`);if(p.success&&p.data)O(p.data.manifest),C(p.data.extractDir),o(!0);else throw new Error(p.message||t("mcpb.uploadFailed"))}catch(u){console.error("MCPB upload error:",u),x(u instanceof Error?u.message:t("mcpb.uploadFailed"))}finally{a(!1)}},ee=async(u,g=!1)=>{var p;a(!0),x(null);try{const w=S(h,v,u);if(!g){const R=await bs("/servers");if(R.success&&((p=R.data)==null?void 0:p.find(X=>X.name===u))){I(u),_(!0),a(!1);return}}let $;if(g?$=await ve(`/servers/${encodeURIComponent(u)}`,{name:u,config:w}):$=await ie("/servers",{name:u,config:w}),$.success)s(w);else throw new Error($.message||t("mcpb.installFailed"))}catch(w){console.error("MCPB install error:",w),x(w instanceof Error?w.message:t("mcpb.installFailed")),a(!1)}},y=()=>{_(!1),A&&ee(A,!0)},b=()=>{_(!1),I(""),a(!1)},S=(u,g,p)=>{var R;const w=((R=u.server)==null?void 0:R.mcp_config)||{},$={type:"stdio",command:w.command||"node",args:(w.args||[]).map(W=>W.replace("${__dirname}",g))};return w.env&&Object.keys(w.env).length>0&&($.env={...w.env},Object.keys($.env).forEach(W=>{typeof $.env[W]=="string"&&($.env[W]=$.env[W].replace("${__dirname}",g))})),$};return f&&h?e.jsxs(e.Fragment,{children:[e.jsx(Te,{isOpen:z,onClose:b,onConfirm:y,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:A}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${z?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick: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"),":"]})," ",h.display_name||h.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",h.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",h.description]}),h.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",h.author.name]}),h.tools&&h.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:h.tools.map((u,g)=>e.jsxs("li",{children:[u.name," - ",u.description]},g))})]})]})]}),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:h.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:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const u=document.getElementById("serverName"),g=(u==null?void 0:u.value.trim())||h.name;ee(g)},disabled:l,className:"hub-btn primary",children:l?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:q,onDrop:T,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:V,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:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!E||l,className:"hub-btn primary flex items-center",children:l?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")})]})]})})},Gt=["sse","streamable-http"],Xt=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","protocolNegotiation","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),Yt=s=>{const r=[],t=[];for(const[n,m]of Object.entries(s.mcpServers)){const l=m??{},a={},j=Object.keys(l).filter(x=>!Xt.has(x));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(l.protocolNegotiation!==void 0){if(!["auto","legacy"].includes(l.protocolNegotiation)||l.protocolNegotiation==="auto"&&l.type!=="streamable-http"){t.push({name:n,message:"protocolNegotiation must be auto or legacy; auto requires streamable-http."});continue}a.protocolNegotiation=l.protocolNegotiation}if(l.type==="sse"||l.type==="streamable-http"){if(a.type=l.type,a.url=l.url,l.headers&&(a.headers=l.headers),l.oauth&&(a.oauth=l.oauth),!l.url){t.push({name:n,message:`"${l.type}" servers require a "url" field.`});continue}}else if(l.type==="openapi")a.type="openapi",a.openapi=l.openapi;else if(l.type===void 0||l.type==="stdio"){if(l.url&&!l.command){t.push({name:n,message:`has a "url" but type "${l.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(a.type="stdio",a.command=l.command,a.args=l.args||[],l.env&&(a.env=l.env),l.options&&(a.options=l.options),!l.command){t.push({name:n,message:'stdio servers require a "command" field.'});continue}}else{const x=Gt.includes(String(l.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:n,message:`unsupported type "${l.type}".${x}`});continue}r.push({name:n,config:a})}return{servers:r,issues:t}},Zt=({onSuccess:s,onCancel:r})=>{const{t}=ae(),[n,m]=c.useState(""),[l,a]=c.useState(null),[j,x]=c.useState(!1),[E,d]=c.useState(null),f=`{
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 C=JSON.parse(v.trim());return!C.mcpServers||typeof C.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):C}catch{return a(t("jsonImport.parseError")),null}},h=()=>{a(null);const v=o(n);if(!v)return;const{servers:C,issues:z}=Yt(v);if(z.length>0){const _=z.map(A=>`${A.name}: ${A.message}`).join(`
35
- `);if(a(t("jsonImport.validationErrors")+`
36
- `+_),C.length===0)return}d(C)},O=async()=>{if(E){x(!0),a(null);try{const v=await ie("/servers/batch",{servers:E});if(v.success&&v.data){const{successCount:C,failureCount:z,results:_}=v.data;if(z>0){const A=_.filter(I=>!I.success).map(I=>`${I.name}: ${I.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:C,total:E.length})+`
37
- `+A.join(`
38
- `))}C>0&&s()}else a(v.message||t("jsonImport.importFailed"))}catch(v){console.error("Import error:",v),a(t("jsonImport.importFailed"))}finally{x(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),l&&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:l})}),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,C)=>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(", ")]})]})]})})},C))})]}),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:O,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=>m(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:f}),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:h,disabled:!n.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Qt=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}),er=(s,r,t="")=>{const n=t.trim().toLowerCase();return s.filter(m=>{var a,j;return r==="online"&&m.status!=="connected"||r==="issues"&&(m.status==="connected"||m.enabled===!1)||r==="disabled"&&m.enabled!==!1?!1:n?(m.name+" "+(((a=m.config)==null?void 0:a.description)||"")+" "+(((j=m.tools)==null?void 0:j.map(x=>x.name).join(" "))||"")).toLowerCase().includes(n):!0})},sr=(s,r,t,n,m)=>{const l=er(s,r,t),a=l.length,j=Math.max(1,Math.ceil(a/m)),x=Math.min(Math.max(1,n),j),E=(x-1)*m;return{servers:l.slice(E,E+m),pagination:{page:x,limit:m,total:a,totalPages:j,hasNextPage:x<j,hasPrevPage:x>1}}},br=()=>{const{t:s}=ae(),r=Gs(),{servers:t,allServers:n,error:m,setError:l,isLoading:a,currentPage:j,serversPerPage:x,setCurrentPage:E,setServersPerPage:d,handleServerAdd:f,handleServerEdit:o,handleServerRemove:h,handleServerToggle:O,handleServerVisibilityChange:v,handleServerReload:C,handleServerReinstall:z,handleServerOAuthDisconnect:_,triggerRefresh:A}=Nt({refreshOnMount:!0}),{serverCosts:I,refetch:M}=wt();c.useEffect(()=>{M()},[t,M]);const[q,T]=c.useState(null),[V,K]=c.useState(null),[ee,y]=c.useState(null),[b,S]=c.useState(!1),[u,g]=c.useState(!1),[p,w]=c.useState(!1),[$,R]=c.useState("all"),[W,X]=c.useState(""),Y=c.useMemo(()=>Qt(n),[n]),{servers:Q,pagination:k}=c.useMemo(()=>sr(n,$,W,j,x),[n,$,W,j,x]);c.useEffect(()=>{k.page!==j&&E(k.page)},[k.page,j,E]);const L=c.useRef(0),re=async J=>{const F=++L.current,H=await o(J);F===L.current&&H&&T(H)},ne=c.useRef(0),le=async J=>{if(ee===J.name)return;const F=++ne.current;y(J.name);try{const H=await o(J);if(xs(F,ne.current)==="stale")return;H&&K(H)}finally{xs(F,ne.current)==="commit"&&y(null)}},oe=async()=>{S(!0);try{A(),await new Promise(J=>setTimeout(J,400))}finally{S(!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:Y.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:Y.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:Y.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(ct,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>w(!0),children:[e.jsx(dt,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>g(!0),children:[e.jsx(ut,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:oe,disabled:b,"aria-label":s("common.refresh"),children:[e.jsx(be,{size:13,className:b?"animate-spin":""}),s("common.refresh")]}),e.jsx(qt,{onAdd:f,duplicateSource:V,onDuplicateCancel:()=>K(null)})]})]}),m&&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:m})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>l(null),"aria-label":s("app.closeButton"),children:e.jsx(ze,{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",Y.all],["online",s("status.online"),Y.online],["issues",s("common.inactive")||"Issues",Y.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",Y.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(mt,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:W,onChange:J=>X(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:()=>X(""),className:"hub-icon-btn sm",children:e.jsx(ze,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[k.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(be,{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(Ut,{server:J,cost:I.find(F=>F.name===J.name),onRemove:h,onEdit:re,onDuplicate:le,isDuplicating:ee===J.name,onToggle:O,onVisibilityChange:v,onRefresh:A,onReload:C,onReinstall:z,onOAuthDisconnect:_},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:(k.page-1)*k.limit+1,end:Math.min(k.page*k.limit,k.total),total:k.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:k.totalPages>1&&e.jsx(vt,{currentPage:k.page,totalPages:k.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:x,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"})]})]})]})]}),q&&e.jsx(Ht,{server:q,onEdit:()=>{T(null),A()},onCancel:()=>T(null)}),u&&e.jsx(Kt,{onSuccess:()=>{g(!1),A()},onCancel:()=>g(!1)}),p&&e.jsx(Zt,{onSuccess:()=>{w(!1),A()},onCancel:()=>w(!1)})]})};export{br as default};
39
- //# sourceMappingURL=ServersPage-CMG1tNig.js.map