@samanhappy/mcphub 1.0.5 → 1.0.7

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 (103) hide show
  1. package/dist/betterAuth.js +2 -2
  2. package/dist/betterAuth.js.map +1 -1
  3. package/dist/clients/openapi.js +98 -5
  4. package/dist/clients/openapi.js.map +1 -1
  5. package/dist/controllers/hostedInternalController.js +55 -0
  6. package/dist/controllers/hostedInternalController.js.map +1 -0
  7. package/dist/controllers/serverController.js +1 -1
  8. package/dist/controllers/serverController.js.map +1 -1
  9. package/dist/dao/ServerDao.js +24 -0
  10. package/dist/dao/ServerDao.js.map +1 -1
  11. package/dist/dao/ServerDaoDbImpl.js +11 -0
  12. package/dist/dao/ServerDaoDbImpl.js.map +1 -1
  13. package/dist/dao/UserDao.js +6 -1
  14. package/dist/dao/UserDao.js.map +1 -1
  15. package/dist/dao/UserDaoDbImpl.js +27 -6
  16. package/dist/dao/UserDaoDbImpl.js.map +1 -1
  17. package/dist/db/entities/User.js +4 -0
  18. package/dist/db/entities/User.js.map +1 -1
  19. package/dist/db/repositories/ServerRepository.js +16 -0
  20. package/dist/db/repositories/ServerRepository.js.map +1 -1
  21. package/dist/db/repositories/UserRepository.js +3 -0
  22. package/dist/db/repositories/UserRepository.js.map +1 -1
  23. package/dist/index.js +8 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/models/User.js +13 -1
  26. package/dist/models/User.js.map +1 -1
  27. package/dist/routes/index.js +5 -1
  28. package/dist/routes/index.js.map +1 -1
  29. package/dist/services/betterAuthConfig.js +146 -33
  30. package/dist/services/betterAuthConfig.js.map +1 -1
  31. package/dist/services/betterAuthSession.js +40 -13
  32. package/dist/services/betterAuthSession.js.map +1 -1
  33. package/dist/services/hostedAuthService.js +314 -0
  34. package/dist/services/hostedAuthService.js.map +1 -0
  35. package/dist/services/hostedControlPlaneClient.js +90 -0
  36. package/dist/services/hostedControlPlaneClient.js.map +1 -0
  37. package/dist/services/hostedEventSubscriber.js +206 -0
  38. package/dist/services/hostedEventSubscriber.js.map +1 -0
  39. package/dist/services/hostedInternalAuth.js +108 -0
  40. package/dist/services/hostedInternalAuth.js.map +1 -0
  41. package/dist/services/hostedMode.js +4 -0
  42. package/dist/services/hostedMode.js.map +1 -0
  43. package/dist/services/hostedNodeIdentity.js +8 -0
  44. package/dist/services/hostedNodeIdentity.js.map +1 -0
  45. package/dist/services/hostedRuntimeCatalogNames.js +7 -0
  46. package/dist/services/hostedRuntimeCatalogNames.js.map +1 -0
  47. package/dist/services/hostedRuntimeCatalogService.js +31 -0
  48. package/dist/services/hostedRuntimeCatalogService.js.map +1 -0
  49. package/dist/services/mcpService.js +84 -10
  50. package/dist/services/mcpService.js.map +1 -1
  51. package/dist/services/requestContextService.js +12 -0
  52. package/dist/services/requestContextService.js.map +1 -1
  53. package/dist/services/sseService.js +61 -10
  54. package/dist/services/sseService.js.map +1 -1
  55. package/dist/utils/migration.js +1 -0
  56. package/dist/utils/migration.js.map +1 -1
  57. package/dist/utils/rateLimit.js +4 -0
  58. package/dist/utils/rateLimit.js.map +1 -1
  59. package/frontend/dist/assets/{ActivityPage-Ccbl6DLW.js → ActivityPage-DDIl8rcq.js} +2 -2
  60. package/frontend/dist/assets/{ActivityPage-Ccbl6DLW.js.map → ActivityPage-DDIl8rcq.js.map} +1 -1
  61. package/frontend/dist/assets/{Dashboard-CPkAALtS.js → Dashboard-CZBclnD_.js} +2 -2
  62. package/frontend/dist/assets/{Dashboard-CPkAALtS.js.map → Dashboard-CZBclnD_.js.map} +1 -1
  63. package/frontend/dist/assets/{EndpointCopy-BYHUhlpW.js → EndpointCopy-C7kzq1Rv.js} +2 -2
  64. package/frontend/dist/assets/{EndpointCopy-BYHUhlpW.js.map → EndpointCopy-C7kzq1Rv.js.map} +1 -1
  65. package/frontend/dist/assets/{GroupsPage-CJI35G25.js → GroupsPage-D5J8mmwv.js} +2 -2
  66. package/frontend/dist/assets/{GroupsPage-CJI35G25.js.map → GroupsPage-D5J8mmwv.js.map} +1 -1
  67. package/frontend/dist/assets/{LoginPage-BZ0WR09v.js → LoginPage-BksVRHPq.js} +2 -2
  68. package/frontend/dist/assets/{LoginPage-BZ0WR09v.js.map → LoginPage-BksVRHPq.js.map} +1 -1
  69. package/frontend/dist/assets/{LogsPage-C_U-xXX0.js → LogsPage-VhqcvLlT.js} +2 -2
  70. package/frontend/dist/assets/{LogsPage-C_U-xXX0.js.map → LogsPage-VhqcvLlT.js.map} +1 -1
  71. package/frontend/dist/assets/{MarketPage-dyC4ocP6.js → MarketPage-Cr0ZJ-12.js} +2 -2
  72. package/frontend/dist/assets/{MarketPage-dyC4ocP6.js.map → MarketPage-Cr0ZJ-12.js.map} +1 -1
  73. package/frontend/dist/assets/{PromptsPage-gNHl5xn5.js → PromptsPage-BUFhppNh.js} +2 -2
  74. package/frontend/dist/assets/{PromptsPage-gNHl5xn5.js.map → PromptsPage-BUFhppNh.js.map} +1 -1
  75. package/frontend/dist/assets/{ResourcesPage-DvgjlTqh.js → ResourcesPage-CLUpqvNX.js} +2 -2
  76. package/frontend/dist/assets/{ResourcesPage-DvgjlTqh.js.map → ResourcesPage-CLUpqvNX.js.map} +1 -1
  77. package/frontend/dist/assets/ServersPage-BmDNiRbb.js +37 -0
  78. package/frontend/dist/assets/ServersPage-BmDNiRbb.js.map +1 -0
  79. package/frontend/dist/assets/{SettingsPage-D66oC6py.js → SettingsPage-DdMb9-RV.js} +2 -2
  80. package/frontend/dist/assets/{SettingsPage-D66oC6py.js.map → SettingsPage-DdMb9-RV.js.map} +1 -1
  81. package/frontend/dist/assets/{StatusDot-C7XhRfMO.js → StatusDot-DaXaKatw.js} +2 -2
  82. package/frontend/dist/assets/{StatusDot-C7XhRfMO.js.map → StatusDot-DaXaKatw.js.map} +1 -1
  83. package/frontend/dist/assets/{ToggleGroup-_MiJO3n_.js → ToggleGroup-C6hpbZ4n.js} +2 -2
  84. package/frontend/dist/assets/{ToggleGroup-_MiJO3n_.js.map → ToggleGroup-C6hpbZ4n.js.map} +1 -1
  85. package/frontend/dist/assets/{UsersPage-COmrRpdL.js → UsersPage-BtYXxXM3.js} +2 -2
  86. package/frontend/dist/assets/{UsersPage-COmrRpdL.js.map → UsersPage-BtYXxXM3.js.map} +1 -1
  87. package/frontend/dist/assets/{index-D82vzW6B.js → index-St_D2SAD.js} +3 -3
  88. package/frontend/dist/assets/{index-D82vzW6B.js.map → index-St_D2SAD.js.map} +1 -1
  89. package/frontend/dist/assets/{resourceService-D-fKBZtF.js → resourceService-CLgvzUQW.js} +2 -2
  90. package/frontend/dist/assets/{resourceService-D-fKBZtF.js.map → resourceService-CLgvzUQW.js.map} +1 -1
  91. package/frontend/dist/assets/{useServerData-DgGTUuZ8.js → useServerData-4qDtSQW3.js} +2 -2
  92. package/frontend/dist/assets/{useServerData-DgGTUuZ8.js.map → useServerData-4qDtSQW3.js.map} +1 -1
  93. package/frontend/dist/assets/useSettingsData-CSmSfVuv.js +2 -0
  94. package/frontend/dist/assets/{useSettingsData-B3CTLIUT.js.map → useSettingsData-CSmSfVuv.js.map} +1 -1
  95. package/frontend/dist/assets/variableDetection-GTKqOf1F.js +16 -0
  96. package/frontend/dist/assets/variableDetection-GTKqOf1F.js.map +1 -0
  97. package/frontend/dist/index.html +1 -1
  98. package/package.json +2 -1
  99. package/frontend/dist/assets/ServersPage-CKuVFL3O.js +0 -37
  100. package/frontend/dist/assets/ServersPage-CKuVFL3O.js.map +0 -1
  101. package/frontend/dist/assets/useSettingsData-B3CTLIUT.js +0 -2
  102. package/frontend/dist/assets/variableDetection-DsYuiOB_.js +0 -16
  103. package/frontend/dist/assets/variableDetection-DsYuiOB_.js.map +0 -1
@@ -1,3 +1,3 @@
1
- import{r,j as e,b as Ae,a as ls,h as os}from"./framework-vendor-BUhDPOUZ.js";import{j as Q,e as he,i as cs}from"./index-D82vzW6B.js";import{u as ne}from"./i18n-vendor-Kbr87Ofu.js";import{C as Me,Z as ze,Q as is,_ as ds,j as ms,X as us,w as hs,s as xs}from"./icons-vendor-CKgJB3SC.js";import{S as we,d as gs}from"./variableDetection-DsYuiOB_.js";import{u as fs}from"./useSettingsData-B3CTLIUT.js";import{P as ps}from"./Pagination-BFi-X7qY.js";const ys=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState([]),[l,w]=r.useState([]),[g,J]=r.useState(""),[_,D]=r.useState(""),[U,H]=r.useState(""),[B,P]=r.useState(!0),[O,C]=r.useState(null),[$,Y]=r.useState(null),[ee,A]=r.useState([]),[R,V]=r.useState(1),[T,se]=r.useState(9),[F,v]=r.useState(1),N=r.useCallback(async()=>{try{P(!0);const a=await Q("/market/servers");a&&a.success&&Array.isArray(a.data)?(u(a.data),M(a.data,R)):(console.error("Invalid market servers data format",{data:a}),C(s("market.fetchError")))}catch(a){console.error("Error fetching market servers",{err:a}),C(a instanceof Error?a.message:String(a))}finally{P(!1)}},[s]),M=r.useCallback((a,t,h=T)=>{const L=a.length,I=Math.ceil(L/h);v(I);const X=Math.max(1,Math.min(t,I));X!==t&&V(X);const ae=(X-1)*h,te=a.slice(ae,ae+h);b(te)},[T]),re=r.useCallback(a=>{V(a),M(i,a,T)},[i,M,T]),j=r.useCallback(async()=>{try{const a=await Q("/market/categories");a&&a.success&&Array.isArray(a.data)?c(a.data):console.error("Invalid categories data format",{data:a})}catch(a){console.error("Error fetching categories",{err:a})}},[]),S=r.useCallback(async()=>{try{const a=await Q("/market/tags");a&&a.success&&Array.isArray(a.data)?w(a.data):console.error("Invalid tags data format",{data:a})}catch(a){console.error("Error fetching tags",{err:a})}},[]),k=r.useCallback(async a=>{try{P(!0);const t=await Q(`/market/servers/${a}`);return t&&t.success&&t.data?(Y(t.data),t.data):(console.error("Invalid market server data format",{name:a,data:t}),C(s("market.serverNotFound")),null)}catch(t){return console.error("Error fetching market server",{name:a,err:t}),C(t instanceof Error?t.message:String(t)),null}finally{P(!1)}},[s]),z=r.useCallback(async a=>{try{if(P(!0),H(a),!a.trim()){N();return}const t=await Q(`/market/servers/search?query=${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market search results format",{query:a,data:t}),C(s("market.searchError")))}catch(t){console.error("Error searching market servers",{query:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,i,M,N]),d=r.useCallback(async a=>{try{if(P(!0),J(a),D(""),!a){N();return}const t=await Q(`/market/categories/${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market category filter results format",{category:a,data:t}),C(s("market.filterError")))}catch(t){console.error("Error filtering market servers by category",{category:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,N,M]),y=r.useCallback(async a=>{try{if(P(!0),D(a),J(""),!a){N();return}const t=await Q(`/market/tags/${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market tag filter results format",{tag:a,data:t}),C(s("market.tagFilterError")))}catch(t){console.error("Error filtering market servers by tag",{tag:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,N,M]),f=r.useCallback(async()=>{try{const a=await Q("/servers");if(a&&a.success&&Array.isArray(a.data)){const t=a.data.map(h=>h.name);A(t)}}catch(a){console.error("Error fetching installed servers",{err:a})}},[]),n=r.useCallback(a=>ee.includes(a),[ee]),o=r.useCallback(async(a,t)=>{var h,L;try{const I=(h=a.installations)!=null&&h.npm?"npm":Object.keys(a.installations||{}).length>0?Object.keys(a.installations)[0]:null;if(!I||!((L=a.installations)!=null&&L[I]))return C(s("market.noInstallationMethod")),!1;const X=a.installations[I],ae={name:a.name,config:t.type==="stdio"?{command:t.command||X.command||"",args:t.args||X.args||[],env:{...X.env,...t.env}}:t},te=await he("/servers",ae);if(!te.success)throw new Error(te.message||"Failed to install server");return await f(),!0}catch(I){return console.error("Error installing market server",{serverName:a.name,err:I}),C(I instanceof Error?I.message:String(I)),!1}},[s,f]),G=r.useCallback(a=>{se(a),V(1),M(i,1,a)},[i,M]);return r.useEffect(()=>{N(),j(),S(),f()},[N,j,S,f]),{servers:p,allServers:i,categories:m,tags:l,selectedCategory:g,selectedTag:_,searchQuery:U,loading:B,error:O,setError:C,currentServer:$,fetchMarketServers:N,fetchServerByName:k,searchServers:z,filterByCategory:d,filterByTag:y,installServer:o,currentPage:R,totalPages:F,serversPerPage:T,changePage:re,changeServersPerPage:G,isServerInstalled:n}},bs=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState([]),[l,w]=r.useState([]),[g,J]=r.useState(""),[_,D]=r.useState(""),[U,H]=r.useState(""),[B,P]=r.useState(!0),[O,C]=r.useState(null),[$,Y]=r.useState(null),[ee,A]=r.useState(1),[R,V]=r.useState(9),[T,se]=r.useState(1),F=r.useCallback(async()=>{try{P(!0);const n=await Q("/cloud/servers");n&&n.success&&Array.isArray(n.data)?(u(n.data),v(n.data,ee)):(console.error("Invalid cloud market servers data format",{data:n}),C(s("cloud.fetchError")))}catch(n){console.error("Error fetching cloud market servers",{err:n});const o=n instanceof Error?n.message:String(n);o==="MCPROUTER_API_KEY_NOT_CONFIGURED"||o.toLowerCase().includes("mcprouter api key not configured"),C(o)}finally{P(!1)}},[s]),v=r.useCallback((n,o,G=R)=>{const a=n.length,t=Math.ceil(a/G);se(t);const h=Math.max(1,Math.min(o,t));h!==o&&A(h);const L=(h-1)*G,I=n.slice(L,L+G);b(I)},[R]),N=r.useCallback(n=>{A(n),v(i,n,R)},[i,v,R]),M=r.useCallback(async()=>{try{const n=await Q("/cloud/categories");n&&n.success&&Array.isArray(n.data)?c(n.data):console.error("Invalid cloud market categories data format",{data:n})}catch(n){console.error("Error fetching cloud market categories",{err:n})}},[]),re=r.useCallback(async()=>{try{const n=await Q("/cloud/tags");n&&n.success&&Array.isArray(n.data)?w(n.data):console.error("Invalid cloud market tags data format",{data:n})}catch(n){console.error("Error fetching cloud market tags",{err:n})}},[]),j=r.useCallback(async n=>{try{P(!0);const o=await Q(`/cloud/servers/${n}`);return o&&o.success&&o.data?(Y(o.data),o.data):(console.error("Invalid cloud server data format",{name:n,data:o}),C(s("cloud.serverNotFound")),null)}catch(o){console.error("Error fetching cloud server",{name:n,err:o});const G=o instanceof Error?o.message:String(o);return G==="MCPROUTER_API_KEY_NOT_CONFIGURED"||G.toLowerCase().includes("mcprouter api key not configured"),C(G),null}finally{P(!1)}},[s]),S=r.useCallback(async n=>{try{if(P(!0),H(n),!n.trim()){F();return}const o=await Q(`/cloud/servers/search?query=${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud search results format",{query:n,data:o}),C(s("cloud.searchError")))}catch(o){console.error("Error searching cloud servers",{query:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,i,v,F]),k=r.useCallback(async n=>{try{if(P(!0),J(n),D(""),!n){F();return}const o=await Q(`/cloud/categories/${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud category filter results format",{category:n,data:o}),C(s("cloud.filterError")))}catch(o){console.error("Error filtering cloud servers by category",{category:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,F,v]),z=r.useCallback(async n=>{try{if(P(!0),D(n),J(""),!n){F();return}const o=await Q(`/cloud/tags/${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud tag filter results format",{tag:n,data:o}),C(s("cloud.tagFilterError")))}catch(o){console.error("Error filtering cloud servers by tag",{tag:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,F,v]),d=r.useCallback(async n=>{try{const o=await Q(`/cloud/servers/${n}/tools`);if(!o.success)throw console.error("Failed to fetch cloud server tools",{serverName:n,data:o}),new Error(o.message||"Failed to fetch cloud server tools");return o&&o.success&&Array.isArray(o.data)?o.data:(console.error("Invalid cloud server tools data format",{serverName:n,data:o}),[])}catch(o){console.error("Error fetching tools for cloud server",{serverName:n,err:o});const G=o instanceof Error?o.message:String(o);if(G==="MCPROUTER_API_KEY_NOT_CONFIGURED"||G.toLowerCase().includes("mcprouter api key not configured"))throw o;return[]}},[]),y=r.useCallback(async(n,o,G)=>{try{const a=await he(`/cloud/servers/${encodeURIComponent(n)}/tools/${encodeURIComponent(o)}/call`,{arguments:G});if(a&&a.success)return a.data;throw new Error(a.message||"Failed to call tool")}catch(a){throw console.error("Error calling tool on cloud server",{serverName:n,toolName:o,err:a}),a}},[]),f=r.useCallback(n=>{V(n),A(1),v(i,1,n)},[i,v]);return r.useEffect(()=>{F(),M(),re()},[F,M,re]),{servers:p,allServers:i,categories:m,tags:l,selectedCategory:g,selectedTag:_,searchQuery:U,loading:B,error:O,setError:C,currentServer:$,fetchCloudServers:F,fetchServerByName:j,searchServers:S,filterByCategory:k,filterByTag:z,fetchServerTools:d,callServerTool:y,currentPage:ee,totalPages:T,serversPerPage:R,changePage:N,changeServersPerPage:f}},vs=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState(!0),[l,w]=r.useState(null),[g,J]=r.useState(""),[_,D]=r.useState(1),[U,H]=r.useState(9),[B,P]=r.useState(null),[O,C]=r.useState(!1),[$,Y]=r.useState([]),[ee]=r.useState(1),A=r.useCallback(async(j,S)=>{try{c(!0),w(null);const k=new URLSearchParams;k.append("limit",U.toString()),j&&k.append("cursor",j);const z=S!==void 0?S:g;z.trim()&&k.append("search",z.trim());const d=await Q(`/registry/servers?${k.toString()}`);if(d&&d.success&&d.data){const y=d.data;if(y.servers&&Array.isArray(y.servers)){b(y.servers);const f=y.metadata.count===U&&!!y.metadata.nextCursor;C(f),P(y.metadata.nextCursor||null),u(j?n=>[...n,...y.servers]:y.servers)}else console.error("Invalid registry servers data format",{data:y}),w(s("registry.fetchError"))}else w(s("registry.fetchError"))}catch(k){console.error("Error fetching registry servers",{cursor:j,search:S,err:k});const z=k instanceof Error?k.message:String(k);w(z)}finally{c(!1)}},[s,U]),R=r.useCallback(async()=>{if(!O||!B)return;const j=$[$.length-1]||"";Y(S=>[...S,j]),D(S=>S+1),await A(B,g)},[O,B,$,g,A]),V=r.useCallback(async()=>{if(_<=1)return;const j=[...$];j.pop();const S=j[j.length-1];Y(j),D(k=>k-1),await A(S||void 0,g)},[_,$,g,A]),T=r.useCallback(async j=>{j!==_&&(j>_&&O?await R():j<_&&_>1&&await V())},[_,O,R,V]),se=r.useCallback(async j=>{H(j),D(1),Y([]),u([]),await A(void 0,g)},[g,A]),F=r.useCallback(async j=>{try{c(!0),w(null);const S=encodeURIComponent(j),k=await Q(`/registry/servers/versions?serverName=${S}`);if(k&&k.success&&k.data){const z=k.data;return z.servers&&Array.isArray(z.servers)&&z.servers.length>0?z.servers[0]:(console.error("Invalid registry server data format",{serverName:j,data:z}),w(s("registry.serverNotFound")),null)}else return w(s("registry.serverNotFound")),null}catch(S){console.error("Error fetching registry server",{serverName:j,err:S});const k=S instanceof Error?S.message:String(S);return w(k),null}finally{c(!1)}},[s]),v=r.useCallback(async j=>{try{w(null);const S=encodeURIComponent(j),k=await Q(`/registry/servers/versions?serverName=${S}`);if(k&&k.success&&k.data){const z=k.data;return z.servers&&Array.isArray(z.servers)?z.servers:(console.error("Invalid registry server versions data format",{serverName:j,data:z}),[])}else return[]}catch(S){console.error("Error fetching versions for registry server",{serverName:j,err:S});const k=S instanceof Error?S.message:String(S);return w(k),[]}},[]),N=r.useCallback(async(j,S)=>{try{w(null);const k=encodeURIComponent(j),z=encodeURIComponent(S),d=await Q(`/registry/servers/version?serverName=${k}&version=${z}`);if(d&&d.success&&d.data){const y=d.data;return y&&y.server?y:(console.error("Invalid registry server version data format",{serverName:j,version:S,data:y}),null)}else return null}catch(k){console.error("Error fetching specific registry server version",{serverName:j,version:S,err:k});const z=k instanceof Error?k.message:String(k);return w(z),null}},[]),M=r.useCallback(async j=>{console.log("Searching registry servers",{query:j}),J(j),D(1),Y([]),u([]),await A(void 0,j)},[A]),re=r.useCallback(async()=>{J(""),D(1),Y([]),u([]),await A(void 0,"")},[A]);return r.useEffect(()=>{A(void 0,g)},[]),{servers:p,allServers:i,loading:m,error:l,setError:w,searchQuery:g,searchServers:M,clearSearch:re,fetchServerByName:F,fetchServerVersions:v,fetchServerVersion:N,currentPage:_,totalPages:ee,hasNextPage:O,hasPreviousPage:_>1,changePage:T,goToNextPage:R,goToPreviousPage:V,serversPerPage:U,changeServersPerPage:se}},js=s=>s.split(" ").map(p=>p.charAt(0)).join("").toUpperCase().slice(0,2),Ns=({server:s,onClick:p})=>{var m,c,l;const{t:b}=ne(),i=(s.tags||[]).slice(0,3),u=(m=s.categories)==null?void 0:m[0];return e.jsxs("div",{className:"hub-card flex flex-col cursor-pointer transition-colors h-full overflow-hidden",onClick:()=>p(s),onMouseEnter:w=>w.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:w=>w.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:js(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(Me,{size:9,strokeWidth:2.5}),b("market.official")]})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:["@",((c=s.author)==null?void 0:c.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}),i.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:i.map(w=>e.jsxs("span",{className:"hub-tag",style:{background:"oklch(0.96 0.04 145)",color:"oklch(0.4 0.1 145)",border:0},children:["#",w]},w))})]}),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(ze,{size:11}),((l=s.tools)==null?void 0:l.length)??0," ",b("server.tools").toLowerCase()]}),u&&e.jsx("span",{className:"truncate",children:u})]})})]})},ks=({server:s,onBack:p,onInstall:b,installing:i=!1,isInstalled:u=!1})=>{var T,se,F;const{t:m}=ne(),[c,l]=r.useState(!1),[w,g]=r.useState(null),[J,_]=r.useState(!1),[D,U]=r.useState(null),[H,B]=r.useState([]),P=()=>u?{className:"bg-green-600 cursor-default px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:m("market.installed")}:i?{className:"bg-gray-400 cursor-not-allowed px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:m("market.installing")}:{className:"hub-btn primary",disabled:!1,text:m("market.install")},O=()=>{l(!c),g(null),_(!1),U(null)},C=async()=>{D&&(await $(D),_(!1),U(null))},$=async v=>{try{g(null),b(s,v.config),l(!1)}catch(N){console.error("Error installing server:",N),g(m("errors.serverInstall"))}},Y=()=>{u||O()},ee=()=>{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 v=Object.keys(s.installations);if(v.length>0)return s.installations[v[0]]},A=async v=>{try{const N=gs(v);N.length>0?(B(N),U(v),_(!0)):await $(v)}catch(N){console.error("Error processing server installation:",N),g(m("errors.serverInstall"))}},R=P(),V=ee();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"})}),m("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:[m("market.author"),": ",((T=s.author)==null?void 0:T.name)||m("market.unknown")," •"," ",m("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:m("market.repository")})]})]})}),e.jsxs("div",{className:"flex items-center",children:[s.is_official&&e.jsx("span",{className:"bg-blue-100 text-blue-800 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:m("market.official")}),e.jsx("button",{onClick:Y,disabled:R.disabled,className:R.className,children:R.text})]})]}),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:[m("market.categories")," & ",m("market.tags")]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(se=s.categories)==null?void 0:se.map((v,N)=>e.jsx("span",{className:"bg-gray-100 dark:bg-gray-800 text-gray-800 px-3 py-1 rounded",children:v},`cat-${N}`)),s.tags&&s.tags.map((v,N)=>e.jsxs("span",{className:"bg-gray-100 dark:bg-gray-800 text-green-700 px-2 py-1 rounded text-sm",children:["#",v]},`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:m("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:m("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:m("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:m("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:m("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(([v,N],M)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:v}),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})})]},M))})]})})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:m("market.tools")}),e.jsx("div",{className:"space-y-4",children:(F=s.tools)==null?void 0:F.map((v,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:[v.name,e.jsx("button",{type:"button",onClick:()=>{const M=document.getElementById(`schema-${N}`);M&&M.classList.toggle("hidden")},className:"text-sm text-blue-500 font-normal hover:underline focus:outline-none ml-2",children:m("market.viewSchema")})]}),e.jsx("p",{className:"text-gray-600 mb-2",children:v.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(v.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:m("market.examples")}),e.jsx("div",{className:"space-y-4",children:s.examples.map((v,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:v.title}),e.jsx("p",{className:"text-gray-600 mb-2",children:v.description}),e.jsx("pre",{className:"bg-gray-50 dark:bg-gray-800 p-3 rounded text-sm overflow-auto",children:v.prompt})]},N))})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("button",{onClick:Y,disabled:R.disabled,className:R.className,children:R.text})}),c&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(we,{onSubmit:A,onCancel:O,modalTitle:m("market.installServer",{name:s.display_name}),formError:w,initialData:{name:s.name,status:"disconnected",config:V?{command:V.command||"",args:V.args||[],env:V.env||{}}:void 0}})}),J&&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:m("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:m("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[m("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:H.map((v,N)=>e.jsxs("li",{className:"font-mono",children:["$",`{${v}}`]},N))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:m("market.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{_(!1),U(null)},className:"hub-btn",children:m("common.cancel")}),e.jsx("button",{onClick:C,className:"hub-btn primary",children:m("market.confirmAndInstall")})]})]})})]})},Ss=s=>{try{const p=new Date(s),b=p.getFullYear(),i=(p.getMonth()+1).toString().padStart(2,"0"),u=p.getDate().toString().padStart(2,"0");return`${b}/${i}/${u}`}catch{return""}},ws=({server:s,onClick:p})=>{const{t:b}=ne(),i=()=>{if(s.description&&s.description.length<=150)return s.description;if(s.content){const u=s.content.split(`
1
+ import{r,j as e,b as Ae,a as ls,h as os}from"./framework-vendor-BUhDPOUZ.js";import{j as Q,e as he,i as cs}from"./index-St_D2SAD.js";import{u as ne}from"./i18n-vendor-Kbr87Ofu.js";import{C as Me,Z as ze,Q as is,_ as ds,j as ms,X as us,w as hs,s as xs}from"./icons-vendor-CKgJB3SC.js";import{S as we,d as gs}from"./variableDetection-GTKqOf1F.js";import{u as fs}from"./useSettingsData-CSmSfVuv.js";import{P as ps}from"./Pagination-BFi-X7qY.js";const ys=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState([]),[l,w]=r.useState([]),[g,J]=r.useState(""),[_,D]=r.useState(""),[U,H]=r.useState(""),[B,P]=r.useState(!0),[O,C]=r.useState(null),[$,Y]=r.useState(null),[ee,A]=r.useState([]),[R,V]=r.useState(1),[T,se]=r.useState(9),[F,v]=r.useState(1),N=r.useCallback(async()=>{try{P(!0);const a=await Q("/market/servers");a&&a.success&&Array.isArray(a.data)?(u(a.data),M(a.data,R)):(console.error("Invalid market servers data format",{data:a}),C(s("market.fetchError")))}catch(a){console.error("Error fetching market servers",{err:a}),C(a instanceof Error?a.message:String(a))}finally{P(!1)}},[s]),M=r.useCallback((a,t,h=T)=>{const L=a.length,I=Math.ceil(L/h);v(I);const X=Math.max(1,Math.min(t,I));X!==t&&V(X);const ae=(X-1)*h,te=a.slice(ae,ae+h);b(te)},[T]),re=r.useCallback(a=>{V(a),M(i,a,T)},[i,M,T]),j=r.useCallback(async()=>{try{const a=await Q("/market/categories");a&&a.success&&Array.isArray(a.data)?c(a.data):console.error("Invalid categories data format",{data:a})}catch(a){console.error("Error fetching categories",{err:a})}},[]),S=r.useCallback(async()=>{try{const a=await Q("/market/tags");a&&a.success&&Array.isArray(a.data)?w(a.data):console.error("Invalid tags data format",{data:a})}catch(a){console.error("Error fetching tags",{err:a})}},[]),k=r.useCallback(async a=>{try{P(!0);const t=await Q(`/market/servers/${a}`);return t&&t.success&&t.data?(Y(t.data),t.data):(console.error("Invalid market server data format",{name:a,data:t}),C(s("market.serverNotFound")),null)}catch(t){return console.error("Error fetching market server",{name:a,err:t}),C(t instanceof Error?t.message:String(t)),null}finally{P(!1)}},[s]),z=r.useCallback(async a=>{try{if(P(!0),H(a),!a.trim()){N();return}const t=await Q(`/market/servers/search?query=${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market search results format",{query:a,data:t}),C(s("market.searchError")))}catch(t){console.error("Error searching market servers",{query:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,i,M,N]),d=r.useCallback(async a=>{try{if(P(!0),J(a),D(""),!a){N();return}const t=await Q(`/market/categories/${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market category filter results format",{category:a,data:t}),C(s("market.filterError")))}catch(t){console.error("Error filtering market servers by category",{category:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,N,M]),y=r.useCallback(async a=>{try{if(P(!0),D(a),J(""),!a){N();return}const t=await Q(`/market/tags/${encodeURIComponent(a)}`);t&&t.success&&Array.isArray(t.data)?(u(t.data),V(1),M(t.data,1)):(console.error("Invalid market tag filter results format",{tag:a,data:t}),C(s("market.tagFilterError")))}catch(t){console.error("Error filtering market servers by tag",{tag:a,err:t}),C(t instanceof Error?t.message:String(t))}finally{P(!1)}},[s,N,M]),f=r.useCallback(async()=>{try{const a=await Q("/servers");if(a&&a.success&&Array.isArray(a.data)){const t=a.data.map(h=>h.name);A(t)}}catch(a){console.error("Error fetching installed servers",{err:a})}},[]),n=r.useCallback(a=>ee.includes(a),[ee]),o=r.useCallback(async(a,t)=>{var h,L;try{const I=(h=a.installations)!=null&&h.npm?"npm":Object.keys(a.installations||{}).length>0?Object.keys(a.installations)[0]:null;if(!I||!((L=a.installations)!=null&&L[I]))return C(s("market.noInstallationMethod")),!1;const X=a.installations[I],ae={name:a.name,config:t.type==="stdio"?{command:t.command||X.command||"",args:t.args||X.args||[],env:{...X.env,...t.env}}:t},te=await he("/servers",ae);if(!te.success)throw new Error(te.message||"Failed to install server");return await f(),!0}catch(I){return console.error("Error installing market server",{serverName:a.name,err:I}),C(I instanceof Error?I.message:String(I)),!1}},[s,f]),G=r.useCallback(a=>{se(a),V(1),M(i,1,a)},[i,M]);return r.useEffect(()=>{N(),j(),S(),f()},[N,j,S,f]),{servers:p,allServers:i,categories:m,tags:l,selectedCategory:g,selectedTag:_,searchQuery:U,loading:B,error:O,setError:C,currentServer:$,fetchMarketServers:N,fetchServerByName:k,searchServers:z,filterByCategory:d,filterByTag:y,installServer:o,currentPage:R,totalPages:F,serversPerPage:T,changePage:re,changeServersPerPage:G,isServerInstalled:n}},bs=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState([]),[l,w]=r.useState([]),[g,J]=r.useState(""),[_,D]=r.useState(""),[U,H]=r.useState(""),[B,P]=r.useState(!0),[O,C]=r.useState(null),[$,Y]=r.useState(null),[ee,A]=r.useState(1),[R,V]=r.useState(9),[T,se]=r.useState(1),F=r.useCallback(async()=>{try{P(!0);const n=await Q("/cloud/servers");n&&n.success&&Array.isArray(n.data)?(u(n.data),v(n.data,ee)):(console.error("Invalid cloud market servers data format",{data:n}),C(s("cloud.fetchError")))}catch(n){console.error("Error fetching cloud market servers",{err:n});const o=n instanceof Error?n.message:String(n);o==="MCPROUTER_API_KEY_NOT_CONFIGURED"||o.toLowerCase().includes("mcprouter api key not configured"),C(o)}finally{P(!1)}},[s]),v=r.useCallback((n,o,G=R)=>{const a=n.length,t=Math.ceil(a/G);se(t);const h=Math.max(1,Math.min(o,t));h!==o&&A(h);const L=(h-1)*G,I=n.slice(L,L+G);b(I)},[R]),N=r.useCallback(n=>{A(n),v(i,n,R)},[i,v,R]),M=r.useCallback(async()=>{try{const n=await Q("/cloud/categories");n&&n.success&&Array.isArray(n.data)?c(n.data):console.error("Invalid cloud market categories data format",{data:n})}catch(n){console.error("Error fetching cloud market categories",{err:n})}},[]),re=r.useCallback(async()=>{try{const n=await Q("/cloud/tags");n&&n.success&&Array.isArray(n.data)?w(n.data):console.error("Invalid cloud market tags data format",{data:n})}catch(n){console.error("Error fetching cloud market tags",{err:n})}},[]),j=r.useCallback(async n=>{try{P(!0);const o=await Q(`/cloud/servers/${n}`);return o&&o.success&&o.data?(Y(o.data),o.data):(console.error("Invalid cloud server data format",{name:n,data:o}),C(s("cloud.serverNotFound")),null)}catch(o){console.error("Error fetching cloud server",{name:n,err:o});const G=o instanceof Error?o.message:String(o);return G==="MCPROUTER_API_KEY_NOT_CONFIGURED"||G.toLowerCase().includes("mcprouter api key not configured"),C(G),null}finally{P(!1)}},[s]),S=r.useCallback(async n=>{try{if(P(!0),H(n),!n.trim()){F();return}const o=await Q(`/cloud/servers/search?query=${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud search results format",{query:n,data:o}),C(s("cloud.searchError")))}catch(o){console.error("Error searching cloud servers",{query:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,i,v,F]),k=r.useCallback(async n=>{try{if(P(!0),J(n),D(""),!n){F();return}const o=await Q(`/cloud/categories/${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud category filter results format",{category:n,data:o}),C(s("cloud.filterError")))}catch(o){console.error("Error filtering cloud servers by category",{category:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,F,v]),z=r.useCallback(async n=>{try{if(P(!0),D(n),J(""),!n){F();return}const o=await Q(`/cloud/tags/${encodeURIComponent(n)}`);o&&o.success&&Array.isArray(o.data)?(u(o.data),A(1),v(o.data,1)):(console.error("Invalid cloud tag filter results format",{tag:n,data:o}),C(s("cloud.tagFilterError")))}catch(o){console.error("Error filtering cloud servers by tag",{tag:n,err:o}),C(o instanceof Error?o.message:String(o))}finally{P(!1)}},[s,F,v]),d=r.useCallback(async n=>{try{const o=await Q(`/cloud/servers/${n}/tools`);if(!o.success)throw console.error("Failed to fetch cloud server tools",{serverName:n,data:o}),new Error(o.message||"Failed to fetch cloud server tools");return o&&o.success&&Array.isArray(o.data)?o.data:(console.error("Invalid cloud server tools data format",{serverName:n,data:o}),[])}catch(o){console.error("Error fetching tools for cloud server",{serverName:n,err:o});const G=o instanceof Error?o.message:String(o);if(G==="MCPROUTER_API_KEY_NOT_CONFIGURED"||G.toLowerCase().includes("mcprouter api key not configured"))throw o;return[]}},[]),y=r.useCallback(async(n,o,G)=>{try{const a=await he(`/cloud/servers/${encodeURIComponent(n)}/tools/${encodeURIComponent(o)}/call`,{arguments:G});if(a&&a.success)return a.data;throw new Error(a.message||"Failed to call tool")}catch(a){throw console.error("Error calling tool on cloud server",{serverName:n,toolName:o,err:a}),a}},[]),f=r.useCallback(n=>{V(n),A(1),v(i,1,n)},[i,v]);return r.useEffect(()=>{F(),M(),re()},[F,M,re]),{servers:p,allServers:i,categories:m,tags:l,selectedCategory:g,selectedTag:_,searchQuery:U,loading:B,error:O,setError:C,currentServer:$,fetchCloudServers:F,fetchServerByName:j,searchServers:S,filterByCategory:k,filterByTag:z,fetchServerTools:d,callServerTool:y,currentPage:ee,totalPages:T,serversPerPage:R,changePage:N,changeServersPerPage:f}},vs=()=>{const{t:s}=ne(),[p,b]=r.useState([]),[i,u]=r.useState([]),[m,c]=r.useState(!0),[l,w]=r.useState(null),[g,J]=r.useState(""),[_,D]=r.useState(1),[U,H]=r.useState(9),[B,P]=r.useState(null),[O,C]=r.useState(!1),[$,Y]=r.useState([]),[ee]=r.useState(1),A=r.useCallback(async(j,S)=>{try{c(!0),w(null);const k=new URLSearchParams;k.append("limit",U.toString()),j&&k.append("cursor",j);const z=S!==void 0?S:g;z.trim()&&k.append("search",z.trim());const d=await Q(`/registry/servers?${k.toString()}`);if(d&&d.success&&d.data){const y=d.data;if(y.servers&&Array.isArray(y.servers)){b(y.servers);const f=y.metadata.count===U&&!!y.metadata.nextCursor;C(f),P(y.metadata.nextCursor||null),u(j?n=>[...n,...y.servers]:y.servers)}else console.error("Invalid registry servers data format",{data:y}),w(s("registry.fetchError"))}else w(s("registry.fetchError"))}catch(k){console.error("Error fetching registry servers",{cursor:j,search:S,err:k});const z=k instanceof Error?k.message:String(k);w(z)}finally{c(!1)}},[s,U]),R=r.useCallback(async()=>{if(!O||!B)return;const j=$[$.length-1]||"";Y(S=>[...S,j]),D(S=>S+1),await A(B,g)},[O,B,$,g,A]),V=r.useCallback(async()=>{if(_<=1)return;const j=[...$];j.pop();const S=j[j.length-1];Y(j),D(k=>k-1),await A(S||void 0,g)},[_,$,g,A]),T=r.useCallback(async j=>{j!==_&&(j>_&&O?await R():j<_&&_>1&&await V())},[_,O,R,V]),se=r.useCallback(async j=>{H(j),D(1),Y([]),u([]),await A(void 0,g)},[g,A]),F=r.useCallback(async j=>{try{c(!0),w(null);const S=encodeURIComponent(j),k=await Q(`/registry/servers/versions?serverName=${S}`);if(k&&k.success&&k.data){const z=k.data;return z.servers&&Array.isArray(z.servers)&&z.servers.length>0?z.servers[0]:(console.error("Invalid registry server data format",{serverName:j,data:z}),w(s("registry.serverNotFound")),null)}else return w(s("registry.serverNotFound")),null}catch(S){console.error("Error fetching registry server",{serverName:j,err:S});const k=S instanceof Error?S.message:String(S);return w(k),null}finally{c(!1)}},[s]),v=r.useCallback(async j=>{try{w(null);const S=encodeURIComponent(j),k=await Q(`/registry/servers/versions?serverName=${S}`);if(k&&k.success&&k.data){const z=k.data;return z.servers&&Array.isArray(z.servers)?z.servers:(console.error("Invalid registry server versions data format",{serverName:j,data:z}),[])}else return[]}catch(S){console.error("Error fetching versions for registry server",{serverName:j,err:S});const k=S instanceof Error?S.message:String(S);return w(k),[]}},[]),N=r.useCallback(async(j,S)=>{try{w(null);const k=encodeURIComponent(j),z=encodeURIComponent(S),d=await Q(`/registry/servers/version?serverName=${k}&version=${z}`);if(d&&d.success&&d.data){const y=d.data;return y&&y.server?y:(console.error("Invalid registry server version data format",{serverName:j,version:S,data:y}),null)}else return null}catch(k){console.error("Error fetching specific registry server version",{serverName:j,version:S,err:k});const z=k instanceof Error?k.message:String(k);return w(z),null}},[]),M=r.useCallback(async j=>{console.log("Searching registry servers",{query:j}),J(j),D(1),Y([]),u([]),await A(void 0,j)},[A]),re=r.useCallback(async()=>{J(""),D(1),Y([]),u([]),await A(void 0,"")},[A]);return r.useEffect(()=>{A(void 0,g)},[]),{servers:p,allServers:i,loading:m,error:l,setError:w,searchQuery:g,searchServers:M,clearSearch:re,fetchServerByName:F,fetchServerVersions:v,fetchServerVersion:N,currentPage:_,totalPages:ee,hasNextPage:O,hasPreviousPage:_>1,changePage:T,goToNextPage:R,goToPreviousPage:V,serversPerPage:U,changeServersPerPage:se}},js=s=>s.split(" ").map(p=>p.charAt(0)).join("").toUpperCase().slice(0,2),Ns=({server:s,onClick:p})=>{var m,c,l;const{t:b}=ne(),i=(s.tags||[]).slice(0,3),u=(m=s.categories)==null?void 0:m[0];return e.jsxs("div",{className:"hub-card flex flex-col cursor-pointer transition-colors h-full overflow-hidden",onClick:()=>p(s),onMouseEnter:w=>w.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:w=>w.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:js(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(Me,{size:9,strokeWidth:2.5}),b("market.official")]})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:["@",((c=s.author)==null?void 0:c.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}),i.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:i.map(w=>e.jsxs("span",{className:"hub-tag",style:{background:"oklch(0.96 0.04 145)",color:"oklch(0.4 0.1 145)",border:0},children:["#",w]},w))})]}),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(ze,{size:11}),((l=s.tools)==null?void 0:l.length)??0," ",b("server.tools").toLowerCase()]}),u&&e.jsx("span",{className:"truncate",children:u})]})})]})},ks=({server:s,onBack:p,onInstall:b,installing:i=!1,isInstalled:u=!1})=>{var T,se,F;const{t:m}=ne(),[c,l]=r.useState(!1),[w,g]=r.useState(null),[J,_]=r.useState(!1),[D,U]=r.useState(null),[H,B]=r.useState([]),P=()=>u?{className:"bg-green-600 cursor-default px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:m("market.installed")}:i?{className:"bg-gray-400 cursor-not-allowed px-4 py-2 rounded text-sm font-medium text-white",disabled:!0,text:m("market.installing")}:{className:"hub-btn primary",disabled:!1,text:m("market.install")},O=()=>{l(!c),g(null),_(!1),U(null)},C=async()=>{D&&(await $(D),_(!1),U(null))},$=async v=>{try{g(null),b(s,v.config),l(!1)}catch(N){console.error("Error installing server:",N),g(m("errors.serverInstall"))}},Y=()=>{u||O()},ee=()=>{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 v=Object.keys(s.installations);if(v.length>0)return s.installations[v[0]]},A=async v=>{try{const N=gs(v);N.length>0?(B(N),U(v),_(!0)):await $(v)}catch(N){console.error("Error processing server installation:",N),g(m("errors.serverInstall"))}},R=P(),V=ee();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"})}),m("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:[m("market.author"),": ",((T=s.author)==null?void 0:T.name)||m("market.unknown")," •"," ",m("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:m("market.repository")})]})]})}),e.jsxs("div",{className:"flex items-center",children:[s.is_official&&e.jsx("span",{className:"bg-blue-100 text-blue-800 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:m("market.official")}),e.jsx("button",{onClick:Y,disabled:R.disabled,className:R.className,children:R.text})]})]}),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:[m("market.categories")," & ",m("market.tags")]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(se=s.categories)==null?void 0:se.map((v,N)=>e.jsx("span",{className:"bg-gray-100 dark:bg-gray-800 text-gray-800 px-3 py-1 rounded",children:v},`cat-${N}`)),s.tags&&s.tags.map((v,N)=>e.jsxs("span",{className:"bg-gray-100 dark:bg-gray-800 text-green-700 px-2 py-1 rounded text-sm",children:["#",v]},`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:m("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:m("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:m("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:m("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:m("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(([v,N],M)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:v}),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})})]},M))})]})})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:m("market.tools")}),e.jsx("div",{className:"space-y-4",children:(F=s.tools)==null?void 0:F.map((v,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:[v.name,e.jsx("button",{type:"button",onClick:()=>{const M=document.getElementById(`schema-${N}`);M&&M.classList.toggle("hidden")},className:"text-sm text-blue-500 font-normal hover:underline focus:outline-none ml-2",children:m("market.viewSchema")})]}),e.jsx("p",{className:"text-gray-600 mb-2",children:v.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(v.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:m("market.examples")}),e.jsx("div",{className:"space-y-4",children:s.examples.map((v,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:v.title}),e.jsx("p",{className:"text-gray-600 mb-2",children:v.description}),e.jsx("pre",{className:"bg-gray-50 dark:bg-gray-800 p-3 rounded text-sm overflow-auto",children:v.prompt})]},N))})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("button",{onClick:Y,disabled:R.disabled,className:R.className,children:R.text})}),c&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(we,{onSubmit:A,onCancel:O,modalTitle:m("market.installServer",{name:s.display_name}),formError:w,initialData:{name:s.name,status:"disconnected",config:V?{command:V.command||"",args:V.args||[],env:V.env||{}}:void 0}})}),J&&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:m("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:m("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[m("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:H.map((v,N)=>e.jsxs("li",{className:"font-mono",children:["$",`{${v}}`]},N))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:m("market.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{_(!1),U(null)},className:"hub-btn",children:m("common.cancel")}),e.jsx("button",{onClick:C,className:"hub-btn primary",children:m("market.confirmAndInstall")})]})]})})]})},Ss=s=>{try{const p=new Date(s),b=p.getFullYear(),i=(p.getMonth()+1).toString().padStart(2,"0"),u=p.getDate().toString().padStart(2,"0");return`${b}/${i}/${u}`}catch{return""}},ws=({server:s,onClick:p})=>{const{t:b}=ne(),i=()=>{if(s.description&&s.description.length<=150)return s.description;if(s.content){const u=s.content.split(`
2
2
  `).filter(m=>m.trim());for(const m of u)if(m.length>50&&m.length<=150)return m}return s.description?s.description.slice(0,150)+"...":b("cloud.noDescription")};return e.jsxs("div",{className:"hub-card flex flex-col cursor-pointer transition-colors h-full overflow-hidden",onClick:()=>p(s),onMouseEnter:u=>u.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:u=>u.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:[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:(s.title||s.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:s.title||s.name}),e.jsx("span",{className:"hub-tag accent flex-shrink-0",style:{fontSize:10},children:"MCP"})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:["@",s.author_name]})]})]}),e.jsx("div",{className:"flex-1 line-clamp-2",style:{fontSize:12.5,color:"var(--hub-ink-2)",lineHeight:1.5},children:i()})]}),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:[s.tools&&s.tools.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ze,{size:11}),s.tools.length," ",b("server.tools").toLowerCase()]}),s.updated_at&&e.jsx("span",{children:Ss(s.updated_at)})]}),e.jsxs("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-accent)"},children:[b("cloud.viewDetails")," →"]})]})]})},Se=()=>{const{t:s}=ne(),p=Ae(),b=()=>{p("/settings")},i=()=>{window.open("https://mcprouter.co","_blank","noopener,noreferrer")};return e.jsx("div",{className:"bg-amber-50 border border-amber-200 dark:bg-amber-900/20 dark:border-amber-900/50 rounded-lg p-6 mb-6",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-amber-400 dark:text-amber-500",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 flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800 dark:text-amber-400",children:s("cloud.apiKeyNotConfigured")}),e.jsx("div",{className:"mt-2 text-sm text-amber-700 dark:text-amber-300",children:e.jsx("p",{children:s("cloud.apiKeyNotConfiguredDescription")})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:i,className:"hub-btn primary inline-flex items-center",children:[e.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("cloud.getApiKey")]}),e.jsxs("button",{onClick:b,className:"inline-flex items-center px-3 py-2 text-sm font-medium text-amber-800 dark:text-amber-400 bg-amber-100 border border-amber-300 dark:bg-amber-900/40 dark:border-amber-700 dark:text-amber-300 rounded-md hover:bg-amber-200 dark:hover:bg-amber-900/60 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-amber-500 dark:focus:ring-amber-400 transition-colors duration-200",children:[e.jsxs("svg",{className:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),s("cloud.configureInSettings")]})]})]})]})})},Cs=({serverName:s,onBack:p,onCallTool:b,fetchServerTools:i,onInstall:u,installing:m=!1,isInstalled:c=!1})=>{const{t:l}=ne(),{mcpRouterConfig:w}=fs(),[g,J]=r.useState(null),[_,D]=r.useState(!0),[U,H]=r.useState(null),[B,P]=r.useState([]),[O,C]=r.useState(!1),[$,Y]=r.useState(!1),[ee,A]=r.useState(null),[R,V]=r.useState({}),[T,se]=r.useState({}),[F,v]=r.useState({}),[N,M]=r.useState(!1),[re,j]=r.useState(null),S=t=>(console.error("Checking for MCPRouter API key error:",t),t==="MCPROUTER_API_KEY_NOT_CONFIGURED"||t.toLowerCase().includes("mcprouter api key not configured")),k=()=>c?{className:"hub-btn cursor-default",disabled:!0,text:l("market.installed")}:m?{className:"hub-btn cursor-not-allowed opacity-50",disabled:!0,text:l("market.installing")}:{className:"hub-btn primary",disabled:!1,text:l("market.install")},z=()=>{!c&&u&&(M(!0),j(null))},d=()=>{M(!1),j(null)},y=async t=>{try{if(!g||!u)return;j(null),u(g,t.config),M(!1)}catch(h){console.error("Error installing server:",h),j(l("errors.serverInstall"))}};r.useEffect(()=>{(async()=>{try{D(!0),H(null);const h=await Q(`/cloud/servers/${s}`);h&&h.success&&h.data?(J(h.data),P(h.data.tools||[])):H(l("cloud.serverNotFound"))}catch(h){console.error("Failed to load server details:",h),H(h instanceof Error?h.message:String(h))}finally{D(!1)}})()},[s,l]),r.useEffect(()=>{(async()=>{if(g&&(!g.tools||g.tools.length===0)&&i){C(!0),Y(!1);try{const h=await i(g.name);P(h)}catch(h){console.error("Failed to load tools:",h);const L=h instanceof Error?h.message:String(h);S(L)&&Y(!0)}finally{C(!1)}}})()},[g==null?void 0:g.name,g==null?void 0:g.tools,i]);const f=t=>{try{const h=new Date(t),L=h.getFullYear(),I=String(h.getMonth()+1).padStart(2,"0"),X=String(h.getDate()).padStart(2,"0"),ae=String(h.getHours()).padStart(2,"0"),te=String(h.getMinutes()).padStart(2,"0"),le=String(h.getSeconds()).padStart(2,"0");return`${L}-${I}-${X} ${ae}:${te}:${le}`}catch{return t}},n=(t,h,L)=>{se(I=>({...I,[t]:{...I[t],[h]:L}}))},o=async t=>{if(!(!b||!g)){A(t);try{const h=T[t]||{},L=await b(g.server_key,t,h);V(I=>({...I,[t]:L}))}catch(h){console.error("Tool call failed:",h);const L=h instanceof Error?h.message:String(h);V(I=>({...I,[t]:{error:L}}))}finally{A(null)}}},G=t=>{v(h=>({...h,[t]:!h[t]}))},a=(t,h,L)=>{var ae;const I=((ae=T[t.name])==null?void 0:ae[h])||"",X=te=>{let le=te.target.value;L.type==="number"||L.type==="integer"?le=le===""?void 0:Number(le):L.type==="boolean"&&(le=te.target.value==="true"),n(t.name,h,le)};return L.type==="boolean"?e.jsxs("select",{value:I===!0?"true":I===!1?"false":"",onChange:X,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",children:[e.jsx("option",{value:""}),e.jsx("option",{value:"true",children:l("common.true")}),e.jsx("option",{value:"false",children:l("common.false")})]}):L.type==="number"||L.type==="integer"?e.jsx("input",{type:"number",step:L.type==="integer"?"1":"any",value:I||"",onChange:X,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"}):e.jsx("input",{type:"text",value:I||"",onChange:X,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"})};return e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-md p-6",children:[e.jsx("div",{className:"mb-6",children:e.jsxs("button",{onClick:p,className:"inline-flex items-center text-gray-600 hover:text-gray-900 transition-colors group",children:[e.jsx("svg",{className:"h-5 w-5 mr-2 transform group-hover:-translate-x-1 transition-transform",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"})}),l("cloud.backToList")]})}),_?e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-12",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("svg",{className:"animate-spin h-12 w-12 text-blue-500 mb-4",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"})]}),e.jsx("p",{className:"text-gray-600 text-lg",children:l("app.loading")})]})}):U&&!S(U)?e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-6",children:e.jsx("div",{className:"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-red-400 dark:text-red-500 mr-3",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})}),e.jsx("p",{className:"text-red-700 dark:text-red-400",children:U})]})})}):g?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-gray-100 to-gray-200 dark:from-gray-800 dark:to-gray-700 px-6 py-4",children:e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-800 mb-2",children:g.title||g.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-gray-600",children:[e.jsx("span",{className:"text-sm bg-white/60 dark:bg-gray-800/60 text-gray-700 px-3 py-1 rounded-full",children:g.name}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("svg",{className:"h-4 w-4 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z",clipRule:"evenodd"})}),l("cloud.by")," ",g.author_name]})]})]}),e.jsxs("div",{className:"text-right flex flex-col items-end gap-3",children:[e.jsxs("div",{className:"text-xs text-gray-500",children:[l("cloud.updated"),": ",f(g.updated_at)]}),u&&!S(U||"")&&!$&&e.jsx("button",{onClick:z,disabled:k().disabled,className:k().className,children:k().text})]})]})})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-6",children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 mb-4 flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-500 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),l("cloud.description")]}),e.jsx("p",{className:"text-gray-700 leading-relaxed",children:g.description})]}),g.content&&e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-6",children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 mb-4 flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-500 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})}),l("cloud.details")]}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-4 overflow-auto",children:e.jsx("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:g.content})})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-6",children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 mb-4 flex items-center",children:[e.jsxs("svg",{className:"h-5 w-5 text-gray-500 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),l("cloud.tools"),B.length>0&&e.jsx("span",{className:"ml-2 bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300 text-sm font-medium px-2.5 py-0.5 rounded-full",children:B.length})]}),$&&e.jsx(Se,{}),O?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsxs("svg",{className:"animate-spin h-8 w-8 text-blue-500 mr-3",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"})]}),e.jsx("span",{className:"text-gray-600",children:l("cloud.loadingTools")})]}):B.length===0&&!$?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("svg",{className:"h-12 w-12 text-gray-400 mx-auto mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"})}),e.jsx("p",{className:"text-gray-600",children:l("cloud.noTools")})]}):B.length>0?e.jsx("div",{className:"space-y-4",children:B.map((t,h)=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-6 hover:border-gray-300 transition-colors",children:[e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 mb-2 flex items-center",children:[e.jsx("span",{className:"bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300 text-xs font-medium px-2 py-1 rounded mr-3",children:"TOOL"}),t.name]}),e.jsx("p",{className:"text-gray-600 leading-relaxed whitespace-pre-wrap",children:t.description})]}),b&&e.jsx("button",{onClick:()=>o(t.name),disabled:ee===t.name,className:"hub-btn primary ml-4 flex items-center min-w-[100px] justify-center",children:ee===t.name?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"})]}),l("cloud.calling")]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"h-4 w-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.828 14.828a4 4 0 01-5.656 0M9 10h6m2 8l4-4H7l4 4z"})}),l("cloud.callTool")]})})]}),t.inputSchema&&t.inputSchema.properties&&Object.keys(t.inputSchema.properties).length>0&&e.jsxs("div",{className:"border-t border-gray-100 dark:border-gray-700 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700",children:l("cloud.parameters")}),e.jsxs("button",{onClick:()=>G(t.name),className:"text-sm text-blue-600 hover:text-blue-800 focus:outline-none flex items-center gap-1 transition-colors",children:[l("cloud.viewSchema"),e.jsx("svg",{className:`h-3 w-3 transition-transform duration-200 ${F[t.name]?"rotate-90":"rotate-0"}`,xmlns:"http://www.w3.org/2000/svg",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"})})]})]}),F[t.name]&&e.jsx("div",{className:"mb-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-3 overflow-auto",children:e.jsx("pre",{className:"text-sm text-gray-800",children:JSON.stringify(t.inputSchema,null,2)})})}),e.jsx("div",{className:"space-y-4",children:Object.entries(t.inputSchema.properties).map(([L,I])=>{var X;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:[L,((X=t.inputSchema.required)==null?void 0:X.includes(L))&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),I.description&&e.jsx("p",{className:"text-xs text-gray-500",children:I.description}),a(t,L,I)]},L)})})]}),R[t.name]&&e.jsx("div",{className:"border-t border-gray-100 dark:border-gray-700 pt-4 mt-4",children:R[t.name].error?e.jsx(e.Fragment,{children:S(R[t.name].error)?e.jsx(Se,{}):e.jsxs(e.Fragment,{children:[e.jsxs("h4",{className:"text-sm font-medium text-red-600 mb-3 flex items-center",children:[e.jsx("svg",{className:"h-4 w-4 text-red-500 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})}),l("cloud.error")]}),e.jsx("div",{className:"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50 rounded-lg p-4",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap overflow-auto",children:R[t.name].error})})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("h4",{className:"text-sm font-medium text-gray-700 mb-3 flex items-center",children:[e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),l("cloud.result")]}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsx("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap overflow-auto",children:JSON.stringify(R[t.name],null,2)})})]})})]},h))}):null]})]}):e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm p-12",children:e.jsxs("div",{className:"text-center",children:[e.jsx("svg",{className:"h-12 w-12 text-gray-400 mx-auto mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M9.172 16.172a4 4 0 015.656 0M9 12h6m-6-4h6m2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})}),e.jsx("p",{className:"text-gray-600 text-lg",children:l("cloud.serverNotFound")})]})}),N&&g&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(we,{onSubmit:y,onCancel:d,modalTitle:l("cloud.installServer",{name:g.title||g.name}),formError:re,initialData:{name:g.name,status:"disconnected",config:{type:"streamable-http",url:g.server_url,headers:{Authorization:`Bearer ${w.apiKey||"<MCPROUTER_API_KEY>"}`,"HTTP-Referer":w.referer||"<YOUR_APP_URL>","X-Title":w.title||"<YOUR_APP_NAME>"}}}})})]})},Ps=s=>{if(!s)return"";try{const p=new Date(s),b=p.getFullYear(),i=(p.getMonth()+1).toString().padStart(2,"0"),u=p.getDate().toString().padStart(2,"0");return`${b}/${i}/${u}`}catch{return""}},Es=({serverEntry:s,onClick:p})=>{var U,H;const{t:b}=ne(),{server:i,_meta:u}=s,m=u==null?void 0:u["io.modelcontextprotocol.registry/official"],c=m==null?void 0:m.isLatest,l=m==null?void 0:m.publishedAt,w=m==null?void 0:m.updatedAt,g=((U=i.packages)==null?void 0:U.length)||0,J=((H=i.remotes)==null?void 0:H.length)||0,_=i.description?i.description.length<=150?i.description:i.description.slice(0,150)+"...":b("registry.noDescription"),D=i.icons&&i.icons.length>0?i.icons.find(P=>!P.theme||P.theme==="light")||i.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:B=>B.currentTarget.style.borderColor="var(--hub-ink-2)",onMouseLeave:B=>B.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:[D?e.jsx("img",{src:D.src,alt:i.title||i.name,className:"rounded-md object-cover flex-shrink-0",style:{width:28,height:28},onError:B=>{B.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:i.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:i.title||i.name}),c&&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(Me,{size:9,strokeWidth:2.5}),b("registry.latest")]})]}),e.jsxs("div",{className:"hub-mono truncate",style:{fontSize:11,color:"var(--hub-ink-3)"},children:[i.name," · v",i.version]})]})]}),e.jsx("div",{className:"flex-1 line-clamp-2",style:{fontSize:12.5,color:"var(--hub-ink-2)",lineHeight:1.5},children:_})]}),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:[g>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(is,{size:11}),g]}),J>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ds,{size:11}),J]}),(l||w)&&e.jsx("span",{children:Ps(w||l)})]}),e.jsxs("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-accent)"},children:[b("registry.viewDetails")," →"]})]})]})},Rs=({serverEntry:s,onBack:p,onInstall:b,installing:i=!1,isInstalled:u=!1,fetchVersions:m})=>{const{t:c}=ne(),{server:l,_meta:w}=s,[g,J]=r.useState(l.version),[_,D]=r.useState([]),[U,H]=r.useState(!1),[B,P]=r.useState(!1),[O,C]=r.useState(null),[$,Y]=r.useState(null),[ee,A]=r.useState(null),[R,V]=r.useState({packages:!0,remotes:!0,repository:!0}),T=w==null?void 0:w["io.modelcontextprotocol.registry/official"];r.useEffect(()=>{(async()=>{if(m){H(!0);try{const y=await m(l.name);D(y)}catch(y){console.error("Failed to load versions:",y)}finally{H(!1)}}})()},[l.name,m]);const F=l.icons&&l.icons.length>0?l.icons.find(y=>!y.theme||y.theme==="light")||l.icons[0]:null,v=d=>{if(!d)return"";try{return new Date(d).toLocaleDateString()}catch{return""}},N=d=>{V(y=>({...y,[d]:!y[d]}))},M=(d,y)=>{C(d),Y(y),A(null),P(!0)},re=()=>{P(!1),A(null)},j=async d=>{try{if(!b||!$||!O)return;A(null);const y=d.config;b(l,y),P(!1)}catch(y){console.error("Error installing server:",y),A(c("errors.serverInstall"))}},S=()=>{if(!$||!O)return null;if(console.log("Building initial form data for:",$),O==="package"&&"identifier"in $){const d=$,y={};d.environmentVariables&&d.environmentVariables.forEach(n=>{y[n.name]=n.default||""});const f=Ts(d.registryType);return{name:l.name,status:"disconnected",config:{type:"stdio",command:f,args:Ls(f,d),env:Object.keys(y).length>0?y:void 0}}}else if(O==="remote"&&"url"in $){const d=$,y={};d.headers&&d.headers.forEach(n=>{y[n.name]=n.default||n.value||""});const f=d.type==="sse"?"sse":"streamable-http";return{name:l.name,status:"disconnected",config:{type:f,url:d.url,headers:Object.keys(y).length>0?y:void 0}}}return null},k=(d,y)=>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:d.identifier}),d.version&&e.jsxs("p",{className:"text-sm text-gray-500",children:["Version: ",d.version]}),d.runtimeHint&&e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:d.runtimeHint})]}),e.jsx("button",{onClick:()=>M("package",d),disabled:u||i,className:`px-4 py-2 rounded text-sm font-medium transition-colors ${u?"hub-btn cursor-default":i?"hub-btn cursor-not-allowed opacity-50":"hub-btn primary"}`,children:c(u?"registry.installed":i?"registry.installing":"registry.install")})]}),d.registryType&&e.jsxs("div",{className:"text-sm text-gray-600 mb-2",children:[e.jsx("span",{className:"font-medium",children:"Registry:"})," ",d.registryType]}),d.transport&&e.jsxs("div",{className:"text-sm text-gray-600 mb-2",children:[e.jsx("span",{className:"font-medium",children:"Transport:"})," ",d.transport.type,d.transport.url&&e.jsxs("span",{className:"ml-2 text-gray-500",children:["(",d.transport.url,")"]})]}),d.environmentVariables&&d.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:[c("registry.environmentVariables"),":"]}),e.jsx("div",{className:"space-y-2",children:d.environmentVariables.map((f,n)=>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:f.name}),f.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:c("common.required")}),f.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:c("common.secret")})]}),f.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:f.description}),f.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.default})]})]},n))})]}),d.packageArguments&&d.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:[c("registry.packageArguments"),":"]}),e.jsx("div",{className:"space-y-2",children:d.packageArguments.map((f,n)=>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:f.name}),f.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:c("common.required")}),f.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:c("common.secret")}),f.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:c("common.repeated")})]}),f.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:f.description}),f.type&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.type"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.type})]}),f.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.default})]}),f.value&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.value"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.value})]}),f.valueHint&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.valueHint"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.valueHint})]}),f.choices&&f.choices.length>0&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.choices"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.choices.join(", ")})]})]},n))})]})]},y),z=(d,y)=>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:d.type}),e.jsx("p",{className:"text-sm text-gray-600 mt-1 break-all",children:d.url})]}),e.jsx("button",{onClick:()=>M("remote",d),disabled:u||i,className:`px-4 py-2 rounded text-sm font-medium transition-colors ${u?"hub-btn cursor-default":i?"hub-btn cursor-not-allowed opacity-50":"hub-btn primary"}`,children:c(u?"registry.installed":i?"registry.installing":"registry.install")})]}),d.headers&&d.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:[c("registry.headers"),":"]}),e.jsx("div",{className:"space-y-2",children:d.headers.map((f,n)=>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:f.name}),f.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:c("common.required")}),f.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:c("common.secret")})]}),f.description&&e.jsx("p",{className:"text-gray-600 mt-1",children:f.description}),f.value&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.value"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.value})]}),f.default&&e.jsxs("p",{className:"text-gray-500 mt-1",children:[e.jsxs("span",{className:"font-medium",children:[c("common.default"),":"]})," ",e.jsx("span",{className:"font-mono",children:f.default})]})]},n))})]})]},y);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"})}),c("registry.backToList")]}),e.jsxs("div",{className:"flex items-start space-x-4",children:[F?e.jsx("img",{src:F.src,alt:l.title,className:"w-20 h-20 rounded-lg object-cover flex-shrink-0",onError:d=>{d.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:l.name}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-3",children:[(T==null?void 0:T.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:c("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",l.version]}),(T==null?void 0:T.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:T.status}),e.jsxs("span",{className:"flex flex-wrap items-center gap-4 text-sm text-gray-600",children:[(T==null?void 0:T.publishedAt)&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[c("registry.published"),":"]})," ",v(T.publishedAt)]}),(T==null?void 0:T.updatedAt)&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[c("registry.updated"),":"]})," ",v(T.updatedAt)]})]})]})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-3",children:c("registry.description")}),e.jsx("p",{className:"text-gray-700 leading-relaxed whitespace-pre-wrap",children:l.description})]}),l.websiteUrl&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-3",children:c("registry.website")}),e.jsx("a",{href:l.websiteUrl,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline",children:l.websiteUrl})]}),l.packages&&l.packages.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>N("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:[c("registry.packages")," (",l.packages.length,")"]}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${R.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"})})]}),R.packages&&e.jsx("div",{className:"space-y-3",children:l.packages.map(k)})]}),l.remotes&&l.remotes.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>N("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:[c("registry.remotes")," (",l.remotes.length,")"]}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${R.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"})})]}),R.remotes&&e.jsx("div",{className:"space-y-3",children:l.remotes.map(z)})]}),l.repository&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>N("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:c("registry.repository")}),e.jsx("svg",{className:`w-5 h-5 transform transition-transform ${R.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"})})]}),R.repository&&e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[l.repository.url&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"URL:"})," ",e.jsx("a",{href:l.repository.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline break-all",children:l.repository.url})]}),l.repository.source&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"Source:"})," ",l.repository.source]}),l.repository.subfolder&&e.jsxs("div",{className:"mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"Subfolder:"})," ",l.repository.subfolder]}),l.repository.id&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"ID:"})," ",l.repository.id]})]})]}),B&&$&&O&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(we,{onSubmit:j,onCancel:re,modalTitle:c("registry.installServer",{name:l.title||l.name}),formError:ee,initialData:S()})})]})};function Ts(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 Ls(s,p){const b=[p.identifier+(p.version?`@${p.version}`:"")],i=[];switch(p.packageArguments&&p.packageArguments.length>0&&p.packageArguments.forEach(u=>{if(u.isRequired||u.default||u.value){const m=`--${u.name}`,c=u.value||u.default||`\${${u.name.toUpperCase()}}`;i.push(m,c)}}),s.toLowerCase()){case"uvx":return[...b,...i];case"npx":return[...b,...i];case"docker":{const u=[];return p.environmentVariables&&p.environmentVariables.forEach(m=>{u.push("-e",`${m.name}`)}),["run","-i","--rm",...u,...b,...i]}default:return[...b,...i]}}const Is=({currentPage:s,hasNextPage:p,hasPreviousPage:b,onNextPage:i,onPreviousPage:u})=>e.jsxs("div",{className:"flex items-center justify-center space-x-2 my-6",children:[e.jsxs("button",{onClick:u,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:i,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"})})]})]}),Us=()=>{const{t:s}=ne(),p=Ae(),{serverName:b}=ls(),{showToast:i}=cs(),[u,m]=os(),c=u.get("tab")||"cloud",{servers:l,allServers:w,categories:g,loading:J,error:_,setError:D,searchServers:U,filterByCategory:H,filterByTag:B,selectedCategory:P,selectedTag:O,installServer:C,fetchServerByName:$,isServerInstalled:Y,currentPage:ee,totalPages:A,changePage:R,serversPerPage:V,changeServersPerPage:T}=ys(),{servers:se,allServers:F,loading:v,error:N,setError:M,fetchServerTools:re,callServerTool:j,currentPage:S,totalPages:k,changePage:z,serversPerPage:d,changeServersPerPage:y}=bs(),{servers:f,allServers:n,loading:o,error:G,setError:a,searchServers:t,clearSearch:h,fetchServerByName:L,fetchServerVersions:I,currentPage:X,totalPages:ae,hasNextPage:te,hasPreviousPage:le,changePage:$e,goToNextPage:Be,goToPreviousPage:_e,serversPerPage:De,changeServersPerPage:Ue}=vs(),[xe,Ce]=r.useState(null),[ge,Pe]=r.useState(null),[fe,Ee]=r.useState(null),[pe,Re]=r.useState(""),[ye,Te]=r.useState(""),[be,de]=r.useState(!1),[Ve,Fe]=r.useState(new Set),[Oe,He]=r.useState(new Set);r.useEffect(()=>{(async()=>{if(b)if(c==="cloud"){const E=se.find(K=>K.name===b);E?Pe(E):p("/market?tab=cloud")}else if(c==="registry"){const E=await L(b);E?Ee(E):p("/market?tab=registry")}else{const E=await $(b);E?Ce(E):p("/market?tab=local")}else Ce(null),Pe(null),Ee(null)})()},[b,c,se,$,L,p]);const We=x=>{const E=new URLSearchParams(u);E.set("tab",x),m(E),b&&p("/market?"+E.toString())},Ke=x=>{x.preventDefault(),c==="local"?U(pe):c==="registry"&&t(ye)},Qe=x=>{c==="local"&&H(x)},Ye=()=>{c==="local"?(Re(""),H(""),B("")):c==="registry"&&(Te(""),h())},ve=x=>{var E;if(c==="cloud")p(`/market/${x.name}?tab=cloud`);else if(c==="registry"){const q=(E=x.server)==null?void 0:E.name;q&&p(`/market/${encodeURIComponent(q)}?tab=registry`)}else p(`/market/${x.name}?tab=local`)},je=()=>p(`/market?tab=${c}`),Ge=async(x,E)=>{try{de(!0),await C(x,E)&&i(s("market.installSuccess",{serverName:x.display_name}),"success")}finally{de(!1)}},qe=async(x,E)=>{try{de(!0);const K={name:x.name,config:E},q=await he("/servers",K);if(!q.success){i((q==null?void 0:q.message)||s("server.addError"),"error");return}Fe(me=>new Set(me).add(x.name)),i(s("cloud.installSuccess",{name:x.title||x.name}),"success")}catch(K){i(s("cloud.installError",{error:K instanceof Error?K.message:String(K)}),"error")}finally{de(!1)}},Je=async(x,E)=>{try{de(!0);const K={name:x.name,config:E},q=await he("/servers",K);if(!q.success){i((q==null?void 0:q.message)||s("server.addError"),"error");return}He(me=>new Set(me).add(x.name)),i(s("registry.installSuccess",{name:x.title||x.name}),"success")}catch(K){i(s("registry.installError",{error:K instanceof Error?K.message:String(K)}),"error")}finally{de(!1)}},Xe=async(x,E,K)=>{try{const q=await j(x,E,K);return i(s("cloud.toolCallSuccess",{toolName:E}),"success"),q}catch(q){const me=q instanceof Error?q.message:String(q);throw Le(me)||i(s("cloud.toolCallError",{toolName:E,error:me}),"error"),q}},Le=x=>x==="MCPROUTER_API_KEY_NOT_CONFIGURED"||x.toLowerCase().includes("mcprouter api key not configured"),Ze=x=>{c==="local"?R(x):c==="registry"?$e(x):z(x),window.scrollTo({top:0,behavior:"smooth"})},es=x=>{const E=parseInt(x.target.value,10);c==="local"?T(E):c==="registry"?Ue(E):y(E)};if(xe)return e.jsx(ks,{server:xe,onBack:je,onInstall:Ge,installing:be,isInstalled:Y(xe.name)});if(ge)return e.jsx(Cs,{serverName:ge.name,onBack:je,onCallTool:Xe,fetchServerTools:re,onInstall:qe,installing:be,isInstalled:Ve.has(ge.name)});if(fe)return e.jsx(Rs,{serverEntry:fe,onBack:je,onInstall:Je,installing:be,isInstalled:Oe.has(fe.server.name),fetchVersions:I});const W=c==="local",Z=c==="registry",Ne=W?l:Z?f:se,ue=W?w:Z?n:F,ss=W?g:[],rs=W?J:Z?o:v,ke=W?_:Z?G:N,ts=W?D:Z?a:M,ce=W?P:"",as=W?O:"",oe=W?ee:Z?X:S,ns=W?A:Z?ae:k,ie=W?V:Z?De:d,Ie=[{id:"cloud",label:s("cloud.title"),sourceLabel:"MCPRouter",sourceUrl:"https://mcprouter.co"},{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:Ie.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:Ie.map(x=>{const E=c===x.id;return e.jsxs("button",{onClick:()=>We(x.id),className:"py-2 px-3 transition-colors text-[14px]",style:{borderBottom:"2px solid "+(E?"var(--hub-ink)":"transparent"),color:E?"var(--hub-ink)":"var(--hub-ink-3)",fontWeight:E?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:K=>K.stopPropagation(),children:["(",x.sourceLabel,")"]})]},x.id)})})})}),ke&&e.jsx(e.Fragment,{children:!W&&Le(ke)?e.jsx(Se,{}):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(ms,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:ke})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>ts(null),children:e.jsx(us,{size:13})})]})}),(W||Z)&&e.jsxs("form",{onSubmit:Ke,className:"hub-card flex items-center gap-2 px-3 mb-5",style:{padding:6},children:[e.jsx(hs,{size:16,style:{color:"var(--hub-ink-3)",margin:"0 6px 0 6px"}}),e.jsx("input",{type:"text",value:Z?ye:pe,onChange:x=>{Z?Te(x.target.value):Re(x.target.value)},placeholder:s(Z?"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")}),(W&&(pe||ce||as)||Z&&ye)&&e.jsx("button",{type:"button",onClick:Ye,className:"hub-btn ghost",children:s("common.clear")})]}),e.jsxs("div",{className:W?"grid gap-5":"",style:W?{gridTemplateColumns:"180px 1fr"}:void 0,children:[W&&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:ce?"transparent":"var(--hub-surface)",color:ce?"var(--hub-ink-2)":"var(--hub-ink)",border:"1px solid "+(ce?"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:w.length})]}),ss.map(x=>e.jsx("button",{onClick:()=>Qe(x),className:"flex items-center justify-between transition-colors text-[13px]",style:{padding:"6px 10px",borderRadius:6,background:ce===x?"var(--hub-surface)":"transparent",color:ce===x?"var(--hub-ink)":"var(--hub-ink-2)",border:"1px solid "+(ce===x?"var(--hub-line)":"transparent")},children:e.jsx("span",{className:"truncate",children:x})},x))]})]}),e.jsx("div",{children:rs?e.jsx("div",{className:"hub-card p-6 text-center",style:{color:"var(--hub-ink-3)"},children:s("app.loading")}):Ne.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:s(W?"market.noServers":Z?"registry.noServers":"cloud.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:Ne.map((x,E)=>W?e.jsx(Ns,{server:x,onClick:ve},E):Z?e.jsx(Es,{serverEntry:x,onClick:ve},E):e.jsx(ws,{server:x,onClick:ve},E))}),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:W?s("market.showing",{from:(oe-1)*ie+1,to:Math.min(oe*ie,ue.length),total:ue.length}):Z?s("registry.showing",{from:(oe-1)*ie+1,to:(oe-1)*ie+Ne.length,total:ue.length+(te?"+":"")}):s("cloud.showing",{from:(oe-1)*ie+1,to:Math.min(oe*ie,ue.length),total:ue.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:Z?e.jsx(Is,{currentPage:oe,hasNextPage:te,hasPreviousPage:le,onNextPage:Be,onPreviousPage:_e}):e.jsx(ps,{currentPage:oe,totalPages:ns,onPageChange:Ze})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s(W?"market.perPage":Z?"registry.perPage":"cloud.perPage"),":"]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"perPage",value:ie,onChange:es,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(xs,{size:11,className:"absolute right-1.5 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"var(--hub-ink-3)"}})]})]})]})]})})]})]})};export{Us as default};
3
- //# sourceMappingURL=MarketPage-dyC4ocP6.js.map
3
+ //# sourceMappingURL=MarketPage-Cr0ZJ-12.js.map