@samanhappy/mcphub 1.1.15 → 1.2.0

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 (120) hide show
  1. package/README.fr.md +1 -0
  2. package/README.md +1 -0
  3. package/README.zh.md +1 -0
  4. package/dist/clients/openapi.js +3 -2
  5. package/dist/clients/openapi.js.map +1 -1
  6. package/dist/controllers/credentialBindingController.js +1 -1
  7. package/dist/controllers/credentialBindingController.js.map +1 -1
  8. package/dist/controllers/healthController.js +23 -1
  9. package/dist/controllers/healthController.js.map +1 -1
  10. package/dist/controllers/metricsController.js +9 -1
  11. package/dist/controllers/metricsController.js.map +1 -1
  12. package/dist/controllers/oauthDynamicRegistrationController.js +5 -5
  13. package/dist/controllers/oauthDynamicRegistrationController.js.map +1 -1
  14. package/dist/db/connection.js +6 -2
  15. package/dist/db/connection.js.map +1 -1
  16. package/dist/db/entities/OAuthState.js +43 -0
  17. package/dist/db/entities/OAuthState.js.map +1 -0
  18. package/dist/db/entities/index.js +3 -1
  19. package/dist/db/entities/index.js.map +1 -1
  20. package/dist/db/replicaSchema.js +40 -0
  21. package/dist/db/replicaSchema.js.map +1 -0
  22. package/dist/db/setup.js +25 -0
  23. package/dist/db/setup.js.map +1 -0
  24. package/dist/db/transactionContext.js +21 -0
  25. package/dist/db/transactionContext.js.map +1 -0
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/middlewares/replicaConfig.js +134 -0
  29. package/dist/middlewares/replicaConfig.js.map +1 -0
  30. package/dist/middlewares/userContext.js +1 -1
  31. package/dist/middlewares/userContext.js.map +1 -1
  32. package/dist/models/OAuth.js +57 -7
  33. package/dist/models/OAuth.js.map +1 -1
  34. package/dist/routes/index.js +14 -1
  35. package/dist/routes/index.js.map +1 -1
  36. package/dist/server.js +13 -4
  37. package/dist/server.js.map +1 -1
  38. package/dist/services/credentialBindingService.js +5 -1
  39. package/dist/services/credentialBindingService.js.map +1 -1
  40. package/dist/services/mcpOAuthProvider.js +91 -5
  41. package/dist/services/mcpOAuthProvider.js.map +1 -1
  42. package/dist/services/mcpService.js +110 -7
  43. package/dist/services/mcpService.js.map +1 -1
  44. package/dist/services/metricsService.js +4 -0
  45. package/dist/services/metricsService.js.map +1 -1
  46. package/dist/services/oauthClientRegistration.js +21 -1
  47. package/dist/services/oauthClientRegistration.js.map +1 -1
  48. package/dist/services/oauthServerService.js +5 -6
  49. package/dist/services/oauthServerService.js.map +1 -1
  50. package/dist/services/oauthSettingsStore.js +21 -0
  51. package/dist/services/oauthSettingsStore.js.map +1 -1
  52. package/dist/services/personalOAuthService.js +40 -2
  53. package/dist/services/personalOAuthService.js.map +1 -1
  54. package/dist/services/replicaLock.js +30 -0
  55. package/dist/services/replicaLock.js.map +1 -0
  56. package/dist/services/replicaService.js +111 -0
  57. package/dist/services/replicaService.js.map +1 -0
  58. package/dist/services/sseService.js +3 -2
  59. package/dist/services/sseService.js.map +1 -1
  60. package/dist/utils/logger.js +7 -0
  61. package/dist/utils/logger.js.map +1 -1
  62. package/dist/utils/migration.js +3 -0
  63. package/dist/utils/migration.js.map +1 -1
  64. package/dist/utils/replicaLogContext.js +3 -0
  65. package/dist/utils/replicaLogContext.js.map +1 -0
  66. package/dist/utils/replicaMode.js +17 -0
  67. package/dist/utils/replicaMode.js.map +1 -0
  68. package/dist/utils/serverConfigPersistence.js +4 -0
  69. package/dist/utils/serverConfigPersistence.js.map +1 -1
  70. package/dist/utils/settingsSync.js +1 -0
  71. package/dist/utils/settingsSync.js.map +1 -1
  72. package/frontend/dist/assets/{ActivityPage-Bi-TjKez.js → ActivityPage-CSXEpl6y.js} +2 -2
  73. package/frontend/dist/assets/{ActivityPage-Bi-TjKez.js.map → ActivityPage-CSXEpl6y.js.map} +1 -1
  74. package/frontend/dist/assets/{CredentialsPage-C4Ucer3d.js → CredentialsPage-CPxOHQUZ.js} +2 -2
  75. package/frontend/dist/assets/{CredentialsPage-C4Ucer3d.js.map → CredentialsPage-CPxOHQUZ.js.map} +1 -1
  76. package/frontend/dist/assets/{Dashboard-C_2KkuoD.js → Dashboard-Da-YT_l_.js} +2 -2
  77. package/frontend/dist/assets/{Dashboard-C_2KkuoD.js.map → Dashboard-Da-YT_l_.js.map} +1 -1
  78. package/frontend/dist/assets/{EndpointCopy-DITVC2YQ.js → EndpointCopy-CZOjiFAH.js} +2 -2
  79. package/frontend/dist/assets/{EndpointCopy-DITVC2YQ.js.map → EndpointCopy-CZOjiFAH.js.map} +1 -1
  80. package/frontend/dist/assets/{GroupsPage-sE6YJyuK.js → GroupsPage-CSA5G9_H.js} +2 -2
  81. package/frontend/dist/assets/{GroupsPage-sE6YJyuK.js.map → GroupsPage-CSA5G9_H.js.map} +1 -1
  82. package/frontend/dist/assets/{LoginPage-CFsd_nY-.js → LoginPage-7RswUPtG.js} +2 -2
  83. package/frontend/dist/assets/{LoginPage-CFsd_nY-.js.map → LoginPage-7RswUPtG.js.map} +1 -1
  84. package/frontend/dist/assets/{LogsPage-BxZuGDuc.js → LogsPage-Dbef_68F.js} +2 -2
  85. package/frontend/dist/assets/{LogsPage-BxZuGDuc.js.map → LogsPage-Dbef_68F.js.map} +1 -1
  86. package/frontend/dist/assets/{MarketPage-CDBs4vMb.js → MarketPage-rSBdHZxo.js} +2 -2
  87. package/frontend/dist/assets/{MarketPage-CDBs4vMb.js.map → MarketPage-rSBdHZxo.js.map} +1 -1
  88. package/frontend/dist/assets/{OAuthConsentPage-BN_ucViM.js → OAuthConsentPage-BH9O7bk3.js} +2 -2
  89. package/frontend/dist/assets/{OAuthConsentPage-BN_ucViM.js.map → OAuthConsentPage-BH9O7bk3.js.map} +1 -1
  90. package/frontend/dist/assets/{PromptsPage-Bl3ySXGK.js → PromptsPage-B558MhVU.js} +2 -2
  91. package/frontend/dist/assets/{PromptsPage-Bl3ySXGK.js.map → PromptsPage-B558MhVU.js.map} +1 -1
  92. package/frontend/dist/assets/{ResourcesPage-BOzQkQ92.js → ResourcesPage-DQpy8B9L.js} +2 -2
  93. package/frontend/dist/assets/{ResourcesPage-BOzQkQ92.js.map → ResourcesPage-DQpy8B9L.js.map} +1 -1
  94. package/frontend/dist/assets/{ServersPage-DHYwQ5AM.js → ServersPage-DBcC8pG2.js} +4 -4
  95. package/frontend/dist/assets/ServersPage-DBcC8pG2.js.map +1 -0
  96. package/frontend/dist/assets/{SettingsPage-CSJ35jlM.js → SettingsPage-BcpeHFR3.js} +2 -2
  97. package/frontend/dist/assets/{SettingsPage-CSJ35jlM.js.map → SettingsPage-BcpeHFR3.js.map} +1 -1
  98. package/frontend/dist/assets/{StatusDot-NSjojGCy.js → StatusDot-CLxRrJ5l.js} +2 -2
  99. package/frontend/dist/assets/{StatusDot-NSjojGCy.js.map → StatusDot-CLxRrJ5l.js.map} +1 -1
  100. package/frontend/dist/assets/{ToggleGroup-BIZWpNzm.js → ToggleGroup-DuWJZU41.js} +2 -2
  101. package/frontend/dist/assets/{ToggleGroup-BIZWpNzm.js.map → ToggleGroup-DuWJZU41.js.map} +1 -1
  102. package/frontend/dist/assets/{UsersPage-DC51v2b8.js → UsersPage-B158Bofs.js} +2 -2
  103. package/frontend/dist/assets/{UsersPage-DC51v2b8.js.map → UsersPage-B158Bofs.js.map} +1 -1
  104. package/frontend/dist/assets/{clipboard-ik5YV95M.js → clipboard-BLr_gbf8.js} +2 -2
  105. package/frontend/dist/assets/{clipboard-ik5YV95M.js.map → clipboard-BLr_gbf8.js.map} +1 -1
  106. package/frontend/dist/assets/{costRevision-Bxov9_vH.js → costRevision-Dzec2k_b.js} +2 -2
  107. package/frontend/dist/assets/{costRevision-Bxov9_vH.js.map → costRevision-Dzec2k_b.js.map} +1 -1
  108. package/frontend/dist/assets/index-CGRjM_NC.js +3 -0
  109. package/frontend/dist/assets/index-CGRjM_NC.js.map +1 -0
  110. package/frontend/dist/assets/{resourceService-DMzCAZ0B.js → resourceService-BNH7uNar.js} +2 -2
  111. package/frontend/dist/assets/{resourceService-DMzCAZ0B.js.map → resourceService-BNH7uNar.js.map} +1 -1
  112. package/frontend/dist/assets/{useCostData-CcFSYViI.js → useCostData-B2d2eLCD.js} +2 -2
  113. package/frontend/dist/assets/{useCostData-CcFSYViI.js.map → useCostData-B2d2eLCD.js.map} +1 -1
  114. package/frontend/dist/assets/{variableDetection-CbYSa1ka.js → variableDetection-DRdE941j.js} +14 -14
  115. package/frontend/dist/assets/{variableDetection-CbYSa1ka.js.map → variableDetection-DRdE941j.js.map} +1 -1
  116. package/frontend/dist/index.html +1 -1
  117. package/package.json +3 -1
  118. package/frontend/dist/assets/ServersPage-DHYwQ5AM.js.map +0 -1
  119. package/frontend/dist/assets/index-6AyPtx0A.js +0 -3
  120. package/frontend/dist/assets/index-6AyPtx0A.js.map +0 -1
@@ -1,9 +1,9 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-DMzCAZ0B.js","./index-6AyPtx0A.js","./framework-vendor-D0S_ys6r.js","./i18n-vendor-COTriSc6.js","./icons-vendor-DZjjGrOu.js","./index-DrHctFvx.css"])))=>i.map(i=>d[i]);
2
- import{r as c,j as e,L as Ks,d as Gs}from"./framework-vendor-D0S_ys6r.js";import{k as we,h as bs,i as $e,l as ie,j as ve,a as Xs,_ as Ne,m as Ys,n as Zs}from"./index-6AyPtx0A.js";import{u as ae}from"./i18n-vendor-COTriSc6.js";import{n as ke,o as fs,p as gs,l as Ce,q as Qs,C as je,r as ye,s as Ie,t as ys,u as js,m as Se,W as et,g as st,F as tt,X as ze,R as be,v as rt,w as nt,x as at,y as ot,L as it,T as lt,P as ct,z as dt,D as ut,G as mt}from"./icons-vendor-DZjjGrOu.js";import{f as ce}from"./contextCost-CilWqGWT.js";import{S as pt}from"./StatusDot-NSjojGCy.js";import{u as Pe,c as ls}from"./clipboard-ik5YV95M.js";import{S as Ee}from"./ToggleGroup-BIZWpNzm.js";import{g as ht,C as xt,t as bt,s as ft}from"./costRevision-Bxov9_vH.js";import{D as gt}from"./DeleteDialog-BoMYLx3J.js";import{C as Te}from"./ConfirmDialog-BJpzQmMw.js";import{c as yt,S as jt,a as vs,d as vt}from"./variableDetection-CbYSa1ka.js";import{P as Nt}from"./Pagination-S-7lzy59.js";import{u as wt,a as kt}from"./useCostData-CcFSYViI.js";import"./UserGroupSelection-CN0weGXJ.js";function Ct({serverName:s,enabled:n=!0}){const{t}=ae(),{showToast:r}=we(),[p,l]=c.useState(!1),[a,j]=c.useState(),[x,P]=c.useState(!1),d=`/servers/${encodeURIComponent(s)}/oauth/personal`;c.useEffect(()=>{let v=!0;const k=()=>{bs(d).then(D=>{var _,R;v&&D.success&&(l(!!((_=D.data)!=null&&_.connected)),j((R=D.data)==null?void 0:R.authorizationUrl))}).catch(()=>{})};return k(),window.addEventListener("focus",k),()=>{v=!1,window.removeEventListener("focus",k)}},[d]);const f=async v=>{var D,_,R;const k=v?null:window.open("about:blank","_blank");k&&(k.opener=null),P(!0);try{const I=v?await $e(d):await ie(d,{});if(!I.success)throw new Error(I.message||t("server.oauth.personalError"));l(!!((D=I.data)!=null&&D.connected)),j((_=I.data)==null?void 0:_.authorizationUrl),(R=I.data)!=null&&R.authorizationUrl&&k?k.location.replace(I.data.authorizationUrl):k==null||k.close()}catch(I){k==null||k.close(),r(I instanceof Error?I.message:t("server.oauth.personalError"),"error")}finally{P(!1)}},o=t(n?p?"status.online":"status.oauthRequired":"server.disable"),h="hub-btn whitespace-nowrap",O="block w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left whitespace-nowrap";return e.jsx("div",{className:"relative",onClick:v=>v.stopPropagation(),children:p?e.jsxs("details",{children:[e.jsxs("summary",{className:`${h} cursor-pointer list-none`,children:[o,e.jsx(ke,{size:12})]}),e.jsxs("div",{className:"absolute left-0 top-full mt-1 z-20 hub-card p-1",children:[e.jsx("button",{className:O,disabled:x||!n,onClick:()=>void f(!1),children:t("server.oauth.personalReconnect")}),e.jsx("button",{className:O,disabled:x,onClick:()=>void f(!0),children:t("server.oauth.personalDisconnect")})]})]}):a&&n?e.jsx("a",{className:h,title:t("status.clickToAuthorize"),href:a,target:"_blank",rel:"noopener noreferrer",children:o}):e.jsx("button",{className:h,disabled:x||!n,title:t("server.oauth.personalConnect"),onClick:()=>void f(!1),children:o})})}const Ns=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await ie(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},St=async(s,n,t)=>{try{const r=await ie(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ws=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ks=async(s,n,t)=>{var r;try{const p=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/hidden-params`,{hiddenParams:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:p.success,error:p.success?void 0:p.message,hiddenParams:(r=p.data)==null?void 0:r.hiddenParams}}catch(p){return console.error("Error updating tool hidden parameters",{serverName:s,toolName:n,error:p}),{success:!1,error:p instanceof Error?p.message:"Unknown error occurred"}}},Cs=async(s,n)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Pt=Object.freeze(Object.defineProperty({__proto__:null,callTool:Ns,resetToolDescription:Cs,toggleTool:St,updateToolDescription:ws,updateToolHiddenParams:ks},Symbol.toStringTag,{value:"Module"})),Ss=({schema:s,onSubmit:n,onCancel:t,loading:r=!1,storageKey:p,title:l})=>{const{t:a}=ae(),[j,x]=c.useState({}),[P,d]=c.useState({}),[f,o]=c.useState(!1),[h,O]=c.useState(""),[v,k]=c.useState(""),D=c.useMemo(()=>(b=>{const C=u=>{if(typeof u=="object"&&u!==null){const g=u;return{type:g.type||"string",description:g.description,enum:g.enum,default:g.default,properties:g.properties?Object.fromEntries(Object.entries(g.properties).map(([m,N])=>[m,C(N)])):void 0,required:g.required,items:g.items?C(g.items):void 0}}return{type:"string"}};return{type:b.type,properties:b.properties?Object.fromEntries(Object.entries(b.properties).map(([u,g])=>[u,C(g)])):void 0,required:b.required}})(s),[s]);c.useEffect(()=>{const y=(C,u="")=>{const g={};return C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,N])=>{const F=u?`${u}.${m}`:m;N.default!==void 0?g[m]=N.default:N.type==="string"?g[m]="":N.type==="number"||N.type==="integer"?g[m]=0:N.type==="boolean"?g[m]=!1:N.type==="array"?g[m]=[]:N.type==="object"&&(N.properties?g[m]=y(N,F):g[m]={})}),g};let b=y(D);if(p)try{const C=localStorage.getItem(p);if(C){const u=JSON.parse(C);b={...b,...u}}}catch(C){console.warn("Failed to load saved form data:",C)}x(b)},[D,p]),c.useEffect(()=>{f&&Object.keys(j).length>0&&(O(JSON.stringify(j,null,2)),k(""))},[f,j]);const _=y=>{O(y),k("");try{const b=JSON.parse(y);if(x(b),p)try{localStorage.setItem(p,JSON.stringify(b))}catch(C){console.warn("Failed to save form data to localStorage:",C)}}catch{k(a("tool.invalidJsonFormat"))}},R=()=>{O(JSON.stringify(j,null,2)),k(""),o(!0)},I=()=>{if(h.trim())try{const y=JSON.parse(h);x(y),k(""),o(!1)}catch{k(a("tool.fixJsonBeforeSwitching"));return}else o(!1)},V=(y,b)=>{x(C=>{const u={...C},g=y.split(".");let m=u;for(let F=0;F<g.length-1;F++){const $=g[F];if($==="__proto__"||$==="constructor"||$==="prototype")return C;m[$]||(m[$]={}),m=m[$]}const N=g[g.length-1];if(!N||N==="__proto__"||N==="constructor"||N==="prototype")return C;if(m[N]=b,p)try{localStorage.setItem(p,JSON.stringify(u))}catch(F){console.warn("Failed to save form data to localStorage:",F)}return u}),P[y]&&d(C=>{const u={...C};return delete u[y],u})},H=()=>{const y={},b=(C,u,g="")=>{C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,N])=>{var G;const F=g?`${g}.${m}`:m,$=u==null?void 0:u[m];if((G=C.required)!=null&&G.includes(m)&&($==null||$===""||Array.isArray($)&&$.length===0)){y[F]=`${m} is required`;return}$!=null&&$!==""&&(N.type==="string"&&typeof $!="string"?y[F]=`${m} must be a string`:N.type==="number"&&typeof $!="number"?y[F]=`${m} must be a number`:N.type==="integer"&&(!Number.isInteger($)||typeof $!="number")?y[F]=`${m} must be an integer`:N.type==="boolean"&&typeof $!="boolean"?y[F]=`${m} must be a boolean`:N.type==="array"&&Array.isArray($)?N.items&&$.forEach((W,Z)=>{var q;((q=N.items)==null?void 0:q.type)==="object"&&N.items.properties&&b(N.items,W,`${F}.${Z}`)}):N.type==="object"&&typeof $=="object"&&b(N,$,F))})};return b(D,j),d(y),Object.keys(y).length===0},T=y=>{y.preventDefault(),H()&&n(j)},M=(y,b)=>b.split(".").reduce((C,u)=>C==null?void 0:C[u],y),K=(y,b,C,u)=>{const g=C==null?void 0:C[y];return b.type==="string"?b.enum?e.jsxs("select",{value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),b.enum.map((m,N)=>e.jsx("option",{value:m,children:m},N))]}):e.jsx("input",{type:"text",value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:b.description||a("tool.enterKey",{key:y})}):b.type==="number"||b.type==="integer"?e.jsx("input",{type:"number",step:b.type==="integer"?"1":"any",value:g??"",onChange:m=>{const N=m.target.value===""?"":b.type==="integer"?parseInt(m.target.value):parseFloat(m.target.value);u(N)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):b.type==="boolean"?e.jsx("input",{type:"checkbox",checked:g||!1,onChange:m=>u(m.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:b.description||a("tool.enterKey",{key:y})})},te=(y,b,C="")=>{var N,F,$,G,W,Z,q,z,L,se,oe,le,J,ee;const u=C?`${C}.${y}`:y,g=M(j,u),m=P[u];if(b.type==="array"){const A=M(j,u)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(F=(N=M(D,C))==null?void 0:N.required)==null?void 0:F.includes(y):($=D.required)==null?void 0:$.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[A.map((Q,re)=>{var pe,de,ue;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a("tool.item",{index:re+1})}),e.jsx("button",{type:"button",onClick:()=>{const w=[...A];w.splice(re,1),V(u,w)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((pe=b.items)==null?void 0:pe.type)==="string"&&b.items.enum?e.jsxs("select",{value:Q||"",onChange:w=>{const U=[...A];U[re]=w.target.value,V(u,U)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),b.items.enum.map((w,U)=>e.jsx("option",{value:w,children:w},U))]}):((de=b.items)==null?void 0:de.type)==="object"&&b.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(b.items.properties).map(([w,U])=>{var Y,X;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[w,((X=(Y=b.items)==null?void 0:Y.required)==null?void 0:X.includes(w))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(w,U,Q,ge=>{const he=[...A];he[re]={...he[re],[w]:ge},V(u,he)})]},w)})}):e.jsx("input",{type:"text",value:Q||"",onChange:w=>{const U=[...A];U[re]=w.target.value,V(u,U)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:a("tool.enterValue",{type:((ue=b.items)==null?void 0:ue.type)||"value"})})]},re)}),e.jsx("button",{type:"button",onClick:()=>{var re;const Q=((re=b.items)==null?void 0:re.type)==="object"?{}:"";V(u,[...A,Q])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:a("tool.addItem",{key:y})})]}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u)}return b.type==="object"?b.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(W=(G=M(D,C))==null?void 0:G.required)==null?void 0:W.includes(y):(Z=D.required)==null?void 0:Z.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(b.properties).map(([A,Q])=>te(A,Q,u))}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(z=(q=M(D,C))==null?void 0:q.required)==null?void 0:z.includes(y):(L=D.required)==null?void 0:L.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("textarea",{value:typeof g=="object"?JSON.stringify(g,null,2):g||"{}",onChange:A=>{try{const Q=JSON.parse(A.target.value);V(u,Q)}catch{V(u,A.target.value)}},placeholder:`{
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-BNH7uNar.js","./index-CGRjM_NC.js","./framework-vendor-D0S_ys6r.js","./i18n-vendor-COTriSc6.js","./icons-vendor-DZjjGrOu.js","./index-DrHctFvx.css"])))=>i.map(i=>d[i]);
2
+ import{r as c,j as e,L as Ks,d as Gs}from"./framework-vendor-D0S_ys6r.js";import{k as we,h as bs,i as $e,l as ie,j as ve,a as Xs,_ as Ne,m as Ys,n as Zs}from"./index-CGRjM_NC.js";import{u as ae}from"./i18n-vendor-COTriSc6.js";import{n as ke,o as fs,p as gs,l as Ce,q as Qs,C as je,r as ye,s as Ie,t as ys,u as js,m as Se,W as et,g as st,F as tt,X as ze,R as be,v as rt,w as nt,x as at,y as ot,L as it,T as lt,P as ct,z as dt,D as ut,G as mt}from"./icons-vendor-DZjjGrOu.js";import{f as ce}from"./contextCost-CilWqGWT.js";import{S as pt}from"./StatusDot-CLxRrJ5l.js";import{u as Pe,c as ls}from"./clipboard-BLr_gbf8.js";import{S as Ee}from"./ToggleGroup-DuWJZU41.js";import{g as ht,C as xt,t as bt,s as ft}from"./costRevision-Dzec2k_b.js";import{D as gt}from"./DeleteDialog-BoMYLx3J.js";import{C as Te}from"./ConfirmDialog-BJpzQmMw.js";import{c as yt,S as jt,a as vs,d as vt}from"./variableDetection-DRdE941j.js";import{P as Nt}from"./Pagination-S-7lzy59.js";import{u as wt,a as kt}from"./useCostData-B2d2eLCD.js";import"./UserGroupSelection-CN0weGXJ.js";function Ct({serverName:s,enabled:n=!0}){const{t}=ae(),{showToast:r}=we(),[p,l]=c.useState(!1),[a,j]=c.useState(),[x,P]=c.useState(!1),d=`/servers/${encodeURIComponent(s)}/oauth/personal`;c.useEffect(()=>{let v=!0;const k=()=>{bs(d).then(D=>{var _,R;v&&D.success&&(l(!!((_=D.data)!=null&&_.connected)),j((R=D.data)==null?void 0:R.authorizationUrl))}).catch(()=>{})};return k(),window.addEventListener("focus",k),()=>{v=!1,window.removeEventListener("focus",k)}},[d]);const f=async v=>{var D,_,R;const k=v?null:window.open("about:blank","_blank");k&&(k.opener=null),P(!0);try{const I=v?await $e(d):await ie(d,{});if(!I.success)throw new Error(I.message||t("server.oauth.personalError"));l(!!((D=I.data)!=null&&D.connected)),j((_=I.data)==null?void 0:_.authorizationUrl),(R=I.data)!=null&&R.authorizationUrl&&k?k.location.replace(I.data.authorizationUrl):k==null||k.close()}catch(I){k==null||k.close(),r(I instanceof Error?I.message:t("server.oauth.personalError"),"error")}finally{P(!1)}},o=t(n?p?"status.online":"status.oauthRequired":"server.disable"),h="hub-btn whitespace-nowrap",O="block w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left whitespace-nowrap";return e.jsx("div",{className:"relative",onClick:v=>v.stopPropagation(),children:p?e.jsxs("details",{children:[e.jsxs("summary",{className:`${h} cursor-pointer list-none`,children:[o,e.jsx(ke,{size:12})]}),e.jsxs("div",{className:"absolute left-0 top-full mt-1 z-20 hub-card p-1",children:[e.jsx("button",{className:O,disabled:x||!n,onClick:()=>void f(!1),children:t("server.oauth.personalReconnect")}),e.jsx("button",{className:O,disabled:x,onClick:()=>void f(!0),children:t("server.oauth.personalDisconnect")})]})]}):a&&n?e.jsx("a",{className:h,title:t("status.clickToAuthorize"),href:a,target:"_blank",rel:"noopener noreferrer",children:o}):e.jsx("button",{className:h,disabled:x||!n,title:t("server.oauth.personalConnect"),onClick:()=>void f(!1),children:o})})}const Ns=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await ie(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},St=async(s,n,t)=>{try{const r=await ie(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ws=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ks=async(s,n,t)=>{var r;try{const p=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/hidden-params`,{hiddenParams:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:p.success,error:p.success?void 0:p.message,hiddenParams:(r=p.data)==null?void 0:r.hiddenParams}}catch(p){return console.error("Error updating tool hidden parameters",{serverName:s,toolName:n,error:p}),{success:!1,error:p instanceof Error?p.message:"Unknown error occurred"}}},Cs=async(s,n)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Pt=Object.freeze(Object.defineProperty({__proto__:null,callTool:Ns,resetToolDescription:Cs,toggleTool:St,updateToolDescription:ws,updateToolHiddenParams:ks},Symbol.toStringTag,{value:"Module"})),Ss=({schema:s,onSubmit:n,onCancel:t,loading:r=!1,storageKey:p,title:l})=>{const{t:a}=ae(),[j,x]=c.useState({}),[P,d]=c.useState({}),[f,o]=c.useState(!1),[h,O]=c.useState(""),[v,k]=c.useState(""),D=c.useMemo(()=>(b=>{const C=u=>{if(typeof u=="object"&&u!==null){const g=u;return{type:g.type||"string",description:g.description,enum:g.enum,default:g.default,properties:g.properties?Object.fromEntries(Object.entries(g.properties).map(([m,N])=>[m,C(N)])):void 0,required:g.required,items:g.items?C(g.items):void 0}}return{type:"string"}};return{type:b.type,properties:b.properties?Object.fromEntries(Object.entries(b.properties).map(([u,g])=>[u,C(g)])):void 0,required:b.required}})(s),[s]);c.useEffect(()=>{const y=(C,u="")=>{const g={};return C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,N])=>{const F=u?`${u}.${m}`:m;N.default!==void 0?g[m]=N.default:N.type==="string"?g[m]="":N.type==="number"||N.type==="integer"?g[m]=0:N.type==="boolean"?g[m]=!1:N.type==="array"?g[m]=[]:N.type==="object"&&(N.properties?g[m]=y(N,F):g[m]={})}),g};let b=y(D);if(p)try{const C=localStorage.getItem(p);if(C){const u=JSON.parse(C);b={...b,...u}}}catch(C){console.warn("Failed to load saved form data:",C)}x(b)},[D,p]),c.useEffect(()=>{f&&Object.keys(j).length>0&&(O(JSON.stringify(j,null,2)),k(""))},[f,j]);const _=y=>{O(y),k("");try{const b=JSON.parse(y);if(x(b),p)try{localStorage.setItem(p,JSON.stringify(b))}catch(C){console.warn("Failed to save form data to localStorage:",C)}}catch{k(a("tool.invalidJsonFormat"))}},R=()=>{O(JSON.stringify(j,null,2)),k(""),o(!0)},I=()=>{if(h.trim())try{const y=JSON.parse(h);x(y),k(""),o(!1)}catch{k(a("tool.fixJsonBeforeSwitching"));return}else o(!1)},V=(y,b)=>{x(C=>{const u={...C},g=y.split(".");let m=u;for(let F=0;F<g.length-1;F++){const $=g[F];if($==="__proto__"||$==="constructor"||$==="prototype")return C;m[$]||(m[$]={}),m=m[$]}const N=g[g.length-1];if(!N||N==="__proto__"||N==="constructor"||N==="prototype")return C;if(m[N]=b,p)try{localStorage.setItem(p,JSON.stringify(u))}catch(F){console.warn("Failed to save form data to localStorage:",F)}return u}),P[y]&&d(C=>{const u={...C};return delete u[y],u})},H=()=>{const y={},b=(C,u,g="")=>{C.type==="object"&&C.properties&&Object.entries(C.properties).forEach(([m,N])=>{var G;const F=g?`${g}.${m}`:m,$=u==null?void 0:u[m];if((G=C.required)!=null&&G.includes(m)&&($==null||$===""||Array.isArray($)&&$.length===0)){y[F]=`${m} is required`;return}$!=null&&$!==""&&(N.type==="string"&&typeof $!="string"?y[F]=`${m} must be a string`:N.type==="number"&&typeof $!="number"?y[F]=`${m} must be a number`:N.type==="integer"&&(!Number.isInteger($)||typeof $!="number")?y[F]=`${m} must be an integer`:N.type==="boolean"&&typeof $!="boolean"?y[F]=`${m} must be a boolean`:N.type==="array"&&Array.isArray($)?N.items&&$.forEach((W,Z)=>{var q;((q=N.items)==null?void 0:q.type)==="object"&&N.items.properties&&b(N.items,W,`${F}.${Z}`)}):N.type==="object"&&typeof $=="object"&&b(N,$,F))})};return b(D,j),d(y),Object.keys(y).length===0},T=y=>{y.preventDefault(),H()&&n(j)},M=(y,b)=>b.split(".").reduce((C,u)=>C==null?void 0:C[u],y),K=(y,b,C,u)=>{const g=C==null?void 0:C[y];return b.type==="string"?b.enum?e.jsxs("select",{value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),b.enum.map((m,N)=>e.jsx("option",{value:m,children:m},N))]}):e.jsx("input",{type:"text",value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:b.description||a("tool.enterKey",{key:y})}):b.type==="number"||b.type==="integer"?e.jsx("input",{type:"number",step:b.type==="integer"?"1":"any",value:g??"",onChange:m=>{const N=m.target.value===""?"":b.type==="integer"?parseInt(m.target.value):parseFloat(m.target.value);u(N)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):b.type==="boolean"?e.jsx("input",{type:"checkbox",checked:g||!1,onChange:m=>u(m.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:g||"",onChange:m=>u(m.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:b.description||a("tool.enterKey",{key:y})})},te=(y,b,C="")=>{var N,F,$,G,W,Z,q,z,L,se,oe,le,J,ee;const u=C?`${C}.${y}`:y,g=M(j,u),m=P[u];if(b.type==="array"){const A=M(j,u)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(F=(N=M(D,C))==null?void 0:N.required)==null?void 0:F.includes(y):($=D.required)==null?void 0:$.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[A.map((Q,re)=>{var pe,de,ue;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a("tool.item",{index:re+1})}),e.jsx("button",{type:"button",onClick:()=>{const w=[...A];w.splice(re,1),V(u,w)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((pe=b.items)==null?void 0:pe.type)==="string"&&b.items.enum?e.jsxs("select",{value:Q||"",onChange:w=>{const U=[...A];U[re]=w.target.value,V(u,U)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),b.items.enum.map((w,U)=>e.jsx("option",{value:w,children:w},U))]}):((de=b.items)==null?void 0:de.type)==="object"&&b.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(b.items.properties).map(([w,U])=>{var Y,X;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[w,((X=(Y=b.items)==null?void 0:Y.required)==null?void 0:X.includes(w))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(w,U,Q,ge=>{const he=[...A];he[re]={...he[re],[w]:ge},V(u,he)})]},w)})}):e.jsx("input",{type:"text",value:Q||"",onChange:w=>{const U=[...A];U[re]=w.target.value,V(u,U)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:a("tool.enterValue",{type:((ue=b.items)==null?void 0:ue.type)||"value"})})]},re)}),e.jsx("button",{type:"button",onClick:()=>{var re;const Q=((re=b.items)==null?void 0:re.type)==="object"?{}:"";V(u,[...A,Q])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:a("tool.addItem",{key:y})})]}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u)}return b.type==="object"?b.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(W=(G=M(D,C))==null?void 0:G.required)==null?void 0:W.includes(y):(Z=D.required)==null?void 0:Z.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(b.properties).map(([A,Q])=>te(A,Q,u))}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?(z=(q=M(D,C))==null?void 0:q.required)==null?void 0:z.includes(y):(L=D.required)==null?void 0:L.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("textarea",{value:typeof g=="object"?JSON.stringify(g,null,2):g||"{}",onChange:A=>{try{const Q=JSON.parse(A.target.value);V(u,Q)}catch{V(u,A.target.value)}},placeholder:`{
3
3
  "key": "value"
4
4
  }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):b.type==="string"?b.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(se=D.required)==null?void 0:se.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsxs("select",{value:g||"",onChange:A=>V(u,A.target.value),className:`w-full border rounded-md px-3 py-2 ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),b.enum.map((A,Q)=>e.jsx("option",{value:A,children:A},Q))]}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(oe=D.required)==null?void 0:oe.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"text",value:g||"",onChange:A=>V(u,A.target.value),className:`w-full border rounded-md px-3 py-2 ${m?"border-red":"border-gray-200"} focus:outline-none form-input`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):b.type==="number"||b.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(le=D.required)==null?void 0:le.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"number",step:b.type==="integer"?"1":"any",value:g??"",onChange:A=>{const Q=A.target.value===""?"":b.type==="integer"?parseInt(A.target.value):parseFloat(A.target.value);V(u,Q)},className:`w-full border rounded-md px-3 py-2 form-input ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):b.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:g||!1,onChange:A=>V(u,A.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[y,(C?!1:(J=D.required)==null?void 0:J.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:b.description}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[y,(C?!1:(ee=D.required)==null?void 0:ee.includes(y))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",b.type,")"]})]}),b.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:b.description}),e.jsx("input",{type:"text",value:g||"",onChange:A=>V(u,A.target.value),placeholder:a("tool.enterValue",{type:b.type}),className:`w-full border rounded-md px-3 py-2 ${m?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),m&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:m})]},u)};return D.properties?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-3",children:[e.jsx("h6",{className:"text-md font-medium text-gray-900",children:l}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:I,className:`hub-btn sm ${f?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:R,className:`hub-btn sm ${f?"primary":""}`,children:a("tool.jsonMode")})]})]}),f?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("tool.jsonConfiguration")}),e.jsx("textarea",{value:h,onChange:y=>_(y.target.value),placeholder:`{
5
5
  "key": "value"
6
- }`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${v?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),v&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:v})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const y=JSON.parse(h);n(y)}catch{k(a("tool.invalidJsonFormat"))}},disabled:r||!!v,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:T,className:"space-y-4",children:[Object.entries(D.properties||{}).map(([y,b])=>te(y,b)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:r,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>n({}),disabled:r,className:"hub-btn primary",children:a(r?"tool.running":"tool.runTool")})]})]})},Et=({result:s,onClose:n})=>{const{t}=ae(),r=s.content,p=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",l=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(h=>l(h));if(typeof d!="object")return[];const f=[];d.type==="image"&&d.data&&f.push({data:String(d.data),mimeType:p(d.mimeType||d.mime_type)});const o=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return o&&f.push({data:String(o),mimeType:p(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&f.push(...l(d.image)),Array.isArray(d.images)&&f.push(...l(d.images)),Array.isArray(d.content)&&f.push(...l(d.content)),f},a=d=>{const f=[];try{const O=JSON.parse(d);if(f.push(...l(O)),f.length>0)return f}catch{}const o=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let h;for(;(h=o.exec(d))!==null;){const O=`image/${h[1]==="jpg"?"jpeg":h[1]}`;f.push({data:h[2],mimeType:O})}return f},j=d=>{try{const f=JSON.parse(d),o=h=>{if(Array.isArray(h))return h.map(o);if(h&&typeof h=="object"){const O={};for(const[v,k]of Object.entries(h))typeof k=="string"&&v.toLowerCase().includes("base64")?O[v]="[base64 omitted]":O[v]=o(k);return O}return h};return JSON.stringify(o(f),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},x=d=>Array.isArray(d)?d.map((f,o)=>e.jsx("div",{className:"mb-3 last:mb-0",children:P(f)},o)):P(d),P=d=>{if(typeof d=="string"){const f=a(d),o=j(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const f=a(d.text),o=j(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(d.type==="image"&&d.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${d.mimeType||"image/png"};base64,${d.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const f=typeof d=="string"?JSON.parse(d):d;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),x(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),x(r)]}):e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},fe=({title:s,onClick:n,disabled:t=!1,loading:r=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:n,disabled:t,title:s,"aria-label":s,children:e.jsx(Qs,{size:14,className:r?"animate-spin":""})}),Dt=(s,n,t,r,p)=>(t?s.filter(l=>l!==n):[...s,n]).filter(l=>r.includes(l)&&!p.includes(l));function zt(s){return s==null?!0:typeof s=="string"?s.trim()==="":Array.isArray(s)?s.length===0:typeof s=="object"?Object.keys(s).length===0:!1}const Tt=({tool:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:p,cost:l})=>{var de,ue;const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[P,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,k]=c.useState(null),[D,_]=c.useState(!1),[R,I]=c.useState(!1),[V,H]=c.useState(s.description||""),T=c.useRef(null),M=c.useRef(null),[K,te]=c.useState(0),[y,b]=c.useState(!1),[C,u]=c.useState(s.hiddenParams||[]),[g,m]=c.useState(!1);c.useEffect(()=>{D&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[D,K]),c.useEffect(()=>{!D&&M.current&&te(M.current.offsetWidth)},[D,V]),c.useEffect(()=>{H(s.description||"")},[s.description]),c.useEffect(()=>{u(s.hiddenParams||[])},[s.hiddenParams]);const N=Object.keys(((de=s.inputSchema)==null?void 0:de.properties)||{}),F=Array.isArray((ue=s.inputSchema)==null?void 0:ue.required)?s.inputSchema.required:[],$=async(w,U)=>{if(t)return;const Y=Dt(C,w,U,N,F);m(!0);try{const X=await ks(n,s.name,Y);X.success?u(X.hiddenParams??Y):j(X.error||a("tool.hiddenParamsFailed"),"error")}finally{m(!1)}},G=s.name.replace(n+x,""),W=ht(s,a("tool.noDescription")),Z=W.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:W.defaultDescription}):void 0,q=c.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),z=c.useCallback(()=>{localStorage.removeItem(q())},[q]),L=w=>{!t&&r&&r(s.name,w)},se=()=>{t||_(!0)},oe=async()=>{if(!t)try{const w=await ws(n,s.name,V);w.success?(_(!1),p&&p(s.name,V)):(H(s.description||""),console.error("Failed to update tool description:",w.error))}catch(w){console.error("Error updating tool description:",w),H(s.description||""),_(!1)}},le=w=>{H(w.target.value)},J=async()=>{if(!t){I(!0);try{const w=await Cs(n,s.name);if(w.success){const U=w.description||"";H(U),_(!1),p==null||p(s.name,U,{restored:!0})}else j(w.error||a("tool.restoreDefaultFailed"),"error")}catch(w){console.error("Error resetting tool description:",w),j(a("tool.restoreDefaultFailed"),"error")}finally{I(!1)}}},ee=w=>{w.key==="Enter"?oe():w.key==="Escape"&&(H(s.description||""),_(!1))},A=async w=>{w.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3)}catch(Y){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Y)}document.body.removeChild(U)}}catch(U){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},Q=async w=>{O(!0);try{w=Object.fromEntries(Object.entries(w).filter(([Y,X])=>!zt(X)));const U=await Ns({toolName:s.name,arguments:w},n);k(U)}catch(U){k({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{O(!1)}},re=()=>{o(!1),z(),k(null)},pe=()=>{k(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:w=>{w.stopPropagation(),d(!P)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:G}),e.jsx("button",{className:"hub-icon-btn sm",onClick:A,title:a("common.copy"),children:y?e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:V,onChange:le,onKeyDown:ee,onClick:w=>w.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),oe()},disabled:R,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),J()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:M,title:Z,children:W.currentDescription}),W.hasDescriptionOverride&&e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{color:"var(--hub-accent)",borderColor:"var(--hub-line)",background:"var(--hub-bg-2)"},title:Z,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),se()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),J()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:w=>w.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled??!0,onCheckedChange:L,disabled:h||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${G}`})}),e.jsxs("button",{onClick:w=>{w.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[W.hasDescriptionOverride&&W.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:a("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:W.defaultDescription})]}),!f&&N.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:4},children:a("tool.visibleParams")}),e.jsx("div",{style:{fontSize:11.5,color:"var(--hub-ink-3)",marginBottom:6},children:a("tool.visibleParamsHelp")}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 14px"},children:N.map(w=>{const U=F.includes(w);return e.jsxs("label",{className:"hub-mono",style:{fontSize:11.5,display:"flex",alignItems:"center",gap:5},title:U?a("tool.requiredParam"):void 0,children:[e.jsx("input",{type:"checkbox",checked:U||!C.includes(w),disabled:t||U||g,onChange:Y=>$(w,Y.target.checked)}),w,U&&" *"]},w)})})]}),!f&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:s.inputSchema||{type:"object"},onSubmit:Q,onCancel:re,loading:h,storageKey:q(),title:a("tool.runToolWithName",{name:G})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Et,{result:v,onClose:pe})})]})]})]})},$t=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",r=await ie(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ps=async(s,n)=>{try{const t=await ie(`/mcp/${encodeURIComponent(n||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},It=async(s,n,t)=>{try{const r=await ie(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Es=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ds=async(s,n)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Rt=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:$t,getPrompt:Ps,resetPromptDescription:Ds,togglePrompt:It,updatePromptDescription:Es},Symbol.toStringTag,{value:"Module"})),cs=({result:s,onClose:n})=>{const{t}=ae(),r=p=>{if(typeof p=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:p})});if(typeof p=="object"&&p!==null){if(p.description||p.messages)return e.jsxs("div",{className:"space-y-4",children:[p.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:p.description})})]}),p.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:p.messages.map((l,a)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"flex items-center mb-2",children:e.jsxs("span",{className:"inline-block w-16 text-xs font-medium text-gray-500",children:[l.role,":"]})}),typeof l.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content}):typeof l.content=="object"&&l.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(l.content,null,2)})]},a))})]})]});try{const l=typeof p=="string"?JSON.parse(p):p;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(l,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(p)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(p)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),r(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Ft=({prompt:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:p,cost:l})=>{const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[P,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,k]=c.useState(null),[D,_]=c.useState(!1),[R,I]=c.useState(!1),[V,H]=c.useState(s.description||""),T=c.useRef(null),M=c.useRef(null),[K,te]=c.useState(0);c.useEffect(()=>{D&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[D,K]),c.useEffect(()=>{!D&&M.current&&te(M.current.offsetWidth)},[D,V]),c.useEffect(()=>{H(s.description||"")},[s.description]);const y=c.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),b=c.useCallback(()=>{localStorage.removeItem(y())},[y]),C=z=>{!t&&r&&r(s.name,z)},u=()=>{t||_(!0)},g=async()=>{if(!t){_(!1);try{const z=await Es(n,s.name,V);z.success?p&&p(s.name,V):(j(z.error||a("prompt.descriptionUpdateFailed"),"error"),H(s.description||""))}catch(z){console.error("Error updating prompt description:",z),j(a("prompt.descriptionUpdateFailed"),"error"),H(s.description||"")}}},m=async()=>{if(!t){I(!0);try{const z=await Ds(n,s.name);if(z.success){const L=z.description||"";H(L),_(!1),p==null||p(s.name,L,{restored:!0})}else j(z.error||a("prompt.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting prompt description:",z),j(a("prompt.restoreDefaultFailed"),"error")}finally{I(!1)}}},N=z=>{H(z.target.value)},F=z=>{z.key==="Enter"?g():z.key==="Escape"&&(H(s.description||""),_(!1))},$=async z=>{O(!0);try{const L=await Ps({promptName:s.name,arguments:z},n);console.log("GetPrompt result:",L),k({success:L.success,data:L.data,error:L.error})}catch(L){k({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{O(!1)}},G=()=>{o(!1),b(),k(null)},W=()=>{k(null)},Z=s.name.replace(n+x,""),q=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const z={},L=[];return s.arguments.forEach(se=>{z[se.name]={type:"string",description:se.description||""},se.required&&L.push(se.name)}),{type:"object",properties:z,required:L}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>d(!P),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:Z}),s.title&&e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.title}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:V,onChange:N,onKeyDown:F,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),g()},disabled:R,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),m()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:M,children:V||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),u()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),m()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ee,{checked:s.enabled,onCheckedChange:C,disabled:h||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${Z}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:q(),onSubmit:$,onCancel:G,loading:h,storageKey:y(),title:a("prompt.runPromptWithName",{name:Z})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(cs,{result:v,onClose:W})})]}),!f&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((z,L)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:z.name}),z.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),z.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:z.description})]}),z.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:z.title})]},L))})]}),!f&&v&&e.jsx("div",{children:e.jsx(cs,{result:v,onClose:W})})]})]})},At=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:r,cost:p})=>{const{t:l}=ae(),[a,j]=c.useState(!1),[x,P]=c.useState(!1),[d,f]=c.useState(!1),[o,h]=c.useState(s.description||""),O=c.useRef(null),v=c.useRef(null),[k,D]=c.useState(0);c.useEffect(()=>{x&&O.current&&(O.current.focus(),k>0&&(O.current.style.width=`${k+20}px`))},[x,k]),c.useEffect(()=>{!x&&v.current&&D(v.current.offsetWidth)},[x,o]),c.useEffect(()=>{h(s.description||"")},[s.description]);const _=s.name||s.uri,R=T=>{!n&&t&&t(s.uri,T)},I=async()=>{n||(P(!1),r&&await r(s.uri,o))},V=async()=>{if(!n){f(!0);try{await(r==null?void 0:r(s.uri,"",{restored:!0})),P(!1)}finally{f(!1)}}},H=T=>{T.key==="Enter"?I():T.key==="Escape"&&(h(s.description||""),P(!1))};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>j(!a),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:_}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:x?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:O,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:k>0?`${k+20}px`:160,minWidth:80},value:o,onChange:T=>h(T.target.value),onKeyDown:H,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),I()},disabled:d,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),V()},disabled:d,loading:d})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:o||l("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),P(!0)},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),V()},disabled:d,loading:d})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[p!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:l("cost.estimate"),children:["Σ ",ce(p)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled!==!1,onCheckedChange:R,disabled:n,size:"card","aria-label":`${l(s.enabled!==!1?"server.disable":"server.enable")} ${_}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),a&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[l("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Ot={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Shared",longKey:"server.visibilityGroup",longFallback:"Shared — selected users only",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Re=s=>s==="public"||s==="group"?s:"private",_t=(s,n)=>{const t=Re(n),r=Ot[t];return{value:t,shortLabel:s(r.shortKey,{defaultValue:r.shortFallback}),longLabel:s(r.longKey,{defaultValue:r.longFallback}),className:r.className}},Mt=(s,n)=>{const t=Re(n),r=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&r.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Shared"}),disabled:!0}),r.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),r},ds=({isLoading:s,children:n,className:t,overlayStyle:r,spinnerSize:p=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:n}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...r},children:e.jsx(be,{size:p,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),us=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),ms=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,Vt="text/html;profile=mcp-app",ps=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Ut=s=>{var n,t;return!!((n=s.tools)!=null&&n.some(r=>ps(r._meta))||(t=s.resources)!=null&&t.some(r=>{var p;return((p=r.uri)==null?void 0:p.startsWith("ui://"))||r.mimeType===Vt||ps(r._meta)}))},Bt=({server:s,cost:n,onRemove:t,onEdit:r,onDuplicate:p,isDuplicating:l=!1,onToggle:a,onVisibilityChange:j,onRefresh:x,onReload:P,onReinstall:d,onOAuthDisconnect:f})=>{var Ve,Ue,Be,Le,Je,We,qe,He,Ke,Ge,Xe,Ye,Ze,Qe,es,ss,ts,rs,ns,as,os,is;const{t:o}=ae(),{showToast:h}=we(),{exportMCPSettings:O,installConfig:v}=Pe(),{auth:k}=Xs(),D=((Ve=v==null?void 0:v.baseUrl)==null?void 0:Ve.replace(/\/+$/,""))||"",[_,R]=c.useState(!1),[I,V]=c.useState(null),[H,T]=c.useState(!1),[M,K]=c.useState(!1),[te,y]=c.useState(!1),[b,C]=c.useState(null),[u,g]=c.useState(!1),[m,N]=c.useState(!1),[F,$]=c.useState(!1),[G,W]=c.useState(!1),[Z,q]=c.useState(!1),[z,L]=c.useState(!1),[se,oe]=c.useState(!1),[le,J]=c.useState(!1),ee=c.useRef(null),A=c.useRef(null);c.useEffect(()=>{const i=E=>{ee.current&&!ee.current.contains(E.target)&&L(!1),A.current&&!A.current.contains(E.target)&&oe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const Q=((Ue=s.tools)==null?void 0:Ue.length)||0,re=((Be=s.tools)==null?void 0:Be.filter(i=>i.enabled!==!1).length)||0,pe=((Le=s.prompts)==null?void 0:Le.length)||0,de=((Je=s.prompts)==null?void 0:Je.filter(i=>i.enabled!==!1).length)||0,ue=((We=s.resources)==null?void 0:We.length)||0,w=((qe=s.resources)==null?void 0:qe.filter(i=>i.enabled!==!1).length)||0,U=Ut(s),Y=s.enabled!==!1,X=yt(s,k.user),ge=((He=s.config)==null?void 0:He.command)==="npx"||((Ke=s.config)==null?void 0:Ke.command)==="uvx",he=ge?s.packageVersion:void 0,De=he||s.version,zs=!!(((Xe=(Ge=s.config)==null?void 0:Ge.oauth)==null?void 0:Xe.identityMode)!=="personal"&&((Ye=s.oauth)!=null&&Ye.connected)&&f),Ts=async i=>{if(!(!X||u||!a)){g(!0);try{await a(s,i)}finally{g(!1)}}},$s=async i=>{if(i.stopPropagation(),L(!1),!(!X||F||!P)){$(!0);try{await P(s)?h(o("server.reloadSuccess")||"Server reloaded successfully","success"):h(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{$(!1)}}},Is=async()=>{if(L(!1),!(!X||G||!d)){W(!0);try{await d(s)?h(o("server.reinstallSuccess")||"Server reinstall initiated","success"):h(o("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{W(!1)}}},Rs=async()=>{if(L(!1),!(!X||Z||!f)){q(!0);try{await f(s)?h(o("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):h(o("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{q(!1)}}},Fs=async i=>{var S;if(i.stopPropagation(),!X||m||!j)return;const E=i.target.value;if(E!==Re(s.visibility??((S=s.config)==null?void 0:S.visibility))){N(!0);try{await j(s,E)}finally{N(!1)}}},As=async i=>{if(i.stopPropagation(),!s.error)return;await ls(s.error)?(J(!0),h(o("common.copySuccess")||"Copied","success"),setTimeout(()=>J(!1),1500)):h(o("common.copyFailed")||"Copy failed","error")},Os=async i=>{var E,S;if(i.stopPropagation(),L(!1),!!X)try{const B=await O(s.name),ne=(S=(E=B==null?void 0:B.data)==null?void 0:E.mcpServers)==null?void 0:S[s.name];if(!B||!B.success||!ne){h((B==null?void 0:B.message)||o("common.copyFailed")||"Copy failed","error");return}C(bt(s.name,ne))}catch(B){console.error("Error copying server configuration:",B),h(o("common.copyFailed")||"Copy failed","error")}},_s=i=>{var E;if(i.stopPropagation(),(E=s.oauth)!=null&&E.authorizationUrl){const ne=window.screen.width/2-300,me=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ne},top=${me}`),h(o("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&h(o("status.oauthClientIdHint"),"warning")}},Ms=async(i,E)=>{try{const{toggleTool:S}=await Ne(async()=>{const{toggleTool:ne}=await Promise.resolve().then(()=>Pt);return{toggleTool:ne}},void 0,import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Vs=async(i,E)=>{try{const{togglePrompt:S}=await Ne(async()=>{const{togglePrompt:ne}=await Promise.resolve().then(()=>Rt);return{togglePrompt:ne}},void 0,import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Us=async(i,E)=>{try{const{toggleResource:S}=await Ne(async()=>{const{toggleResource:ne}=await import("./resourceService-DMzCAZ0B.js");return{toggleResource:ne}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Bs=(i,E,S)=>{h(S!=null&&S.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),x==null||x()},Ls=(i,E,S)=>{h(S!=null&&S.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),x==null||x()},Js=async(i,E,S)=>{try{const{updateResourceDescription:B,resetResourceDescription:ne}=await Ne(async()=>{const{updateResourceDescription:qs,resetResourceDescription:Hs}=await import("./resourceService-DMzCAZ0B.js");return{updateResourceDescription:qs,resetResourceDescription:Hs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),me=S!=null&&S.restored?await ne(s.name,i):await B(s.name,i,E);me.success?(h(S!=null&&S.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),x==null||x()):h(me.error||(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(B){console.error(B),h(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var S;const i=s.config;if(!i)return"";if(i.url)return i.url;const E=[];return i.command&&E.push(i.command),(S=i.args)!=null&&S.length&&E.push(...i.args),E.join(" ")})();const Fe=`${D}/mcp/${s.name}`,Ae=`${D}/api/${s.name}`,Oe=async i=>{const E=await ls(i);h(E?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",E?"success":"error")},_e=(i,E)=>o(i,E),xe=_t(_e,s.visibility??((Ze=s.config)==null?void 0:Ze.visibility)),Ws=Mt(_e,xe.value),Me=[{key:"tools",icon:et,total:Q,enabled:re,label:o("server.tools")},{key:"prompts",icon:st,total:pe,enabled:de,label:o("server.prompts")},{key:"resources",icon:tt,total:ue,enabled:w,label:o("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>R(!_),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(Se,{size:12,style:{color:"var(--hub-ink-3)",transform:_?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"hub-mono min-w-0 max-w-full truncate",title:s.name,style:{fontSize:13.5,color:Y?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),De&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o(he?"server.packageVersion":"server.reportedVersion")}: ${De}`,style:{fontSize:11},children:e.jsxs("span",{className:"truncate",children:["v",De]})}),ge&&s.updateAvailable&&s.latestVersion&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o("server.updateAvailable")}: ${s.latestVersion}`,style:{fontSize:11,color:"var(--hub-warn)"},children:e.jsxs("span",{className:"truncate",children:["↑ ",s.latestVersion]})}),U&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:A,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),oe(E=>!E)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ce,{size:14})}),se&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:o("server.errorDetails")}),e.jsx("button",{onClick:As,className:"hub-icon-btn sm",title:o("common.copy"),children:le?e.jsx(je,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>oe(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(ze,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),!!((es=(Qe=s.config)==null?void 0:Qe.credentialTemplate)!=null&&es.length)&&e.jsxs(Ks,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[o("credentials.personalBadge")," · ",o("credentials.manage")]}),((ss=s.config)==null?void 0:ss.description)&&e.jsx("div",{className:"text-[11.5px] truncate",style:{color:"var(--hub-ink-3)",marginTop:1},title:s.config.description,children:s.config.description})]})]}),e.jsxs("div",{className:`hub-server-card-status-cell min-w-0${Y&&s.recovery?" hub-server-card-recovering":""}`,children:[((rs=(ts=s.config)==null?void 0:ts.oauth)==null?void 0:rs.identityMode)==="personal"?e.jsx(Ct,{serverName:s.name,enabled:Y}):e.jsx(pt,{status:s.status,enabled:s.enabled,startOnDemand:((ns=s.config)==null?void 0:ns.startOnDemand)===!0,onAuthClick:_s,className:"hub-server-card-status"}),Y&&s.recovery&&e.jsxs("div",{className:"text-xs mt-1",style:{color:"var(--hub-ink-3)",maxWidth:160},children:[e.jsx("div",{children:s.recovery.nextAttemptAt?o("server.retryScheduled",{time:new Date(s.recovery.nextAttemptAt).toLocaleTimeString(void 0,{hour12:!1})}):o("server.reconnecting")}),s.recovery.lastAttemptAt&&e.jsx("div",{children:o("server.lastRetry",{count:s.recovery.attempts,time:new Date(s.recovery.lastAttemptAt).toLocaleTimeString(void 0,{hour12:!1})})})]})]}),e.jsxs("div",{className:"hub-server-card-transport-cell min-w-0",children:[(as=s.config)!=null&&as.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:ms(o,s.config.type)??void 0,children:ms(o,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"}),((os=s.config)==null?void 0:os.type)!=="openapi"&&e.jsxs("span",{className:"hub-server-card-protocol",title:o("server.protocolVersion"),children:["MCP"," ",Y&&s.status==="connected"&&s.protocolVersion?e.jsx("span",{className:"whitespace-nowrap",children:s.protocolVersion}):o("server.protocolVersionUnknown")]})]}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:i=>i.stopPropagation(),children:X&&j?e.jsx(ds,{isLoading:m,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:xe.value,onChange:Fs,disabled:m,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":o("server.visibility","Visibility"),title:xe.longLabel,children:Ws.map(i=>e.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${xe.className}`,title:xe.longLabel,children:xe.shortLabel})}),Me.map(({key:i,icon:E,total:S,enabled:B,label:ne})=>{const me=S===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${me?"is-empty":""}`,title:`${ne}: ${B}/${S}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(us,{icon:E})}),e.jsx("span",{className:"hub-server-capability-value",children:me?"0":`${B}/${S}`})]},i)}),n&&n.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${n.exposed} / ${o("cost.gross")} ${n.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ce(n.exposed),"/",ce(n.gross)]})]}):n?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:o("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:i=>i.stopPropagation(),children:e.jsx(ds,{isLoading:u,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ee,{checked:Y,onCheckedChange:Ts,disabled:u||!X,size:"compact","aria-label":`${o(Y?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:ee,children:[X&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),L(E=>!E)},"aria-label":"More","aria-busy":l,children:l?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(rt,{size:14})}),X&&z&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:i=>i.stopPropagation(),children:[e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),r(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(nt,{size:13})," ",o("server.edit")]}),p&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!l&&p(s)},disabled:l,"aria-busy":l,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[l?e.jsx(be,{size:13,className:"animate-spin"}):e.jsx(at,{size:13})," ",o("server.duplicate")]}),e.jsxs("button",{onClick:Os,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),P&&e.jsxs("button",{onClick:$s,disabled:F||u||!Y,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(be,{size:13})," ",o("server.reload")]}),d&&ge&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!X||G||!Y)&&K(!0)},disabled:G||u||!Y,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(ot,{size:13})," ",o("server.reinstall")]}),zs&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!X||Z)&&y(!0)},disabled:Z,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(it,{size:13})," ",o("server.disconnectOAuth")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),T(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(lt,{size:13})," ",o("server.delete")]})]})]})]}),_&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[((is=s.config)==null?void 0:is.description)&&e.jsxs("section",{className:"mb-3","aria-labelledby":`server-about-${s.name}`,children:[e.jsx("h3",{id:`server-about-${s.name}`,className:"text-[11px] font-medium tracking-wide uppercase",style:{color:"var(--hub-ink-3)",marginBottom:6},children:o("server.description")}),e.jsx("p",{className:"text-[13px] leading-5 whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.config.description})]}),e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Me.map(i=>{const E=I===i.key,S=i.icon;return e.jsxs("button",{onClick:()=>V(E?null:i.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:E?"var(--hub-surface)":"transparent",border:"1px solid "+(E?"var(--hub-line)":"transparent"),color:E?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(us,{icon:S}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),n&&n.connected&&e.jsxs("button",{onClick:()=>V(I==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:I==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(I==="cost"?"var(--hub-line)":"transparent"),color:I==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:o("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:o("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ce(n.exposed),"/",ce(n.gross)]})]}),e.jsxs("div",{className:"ml-auto max-w-full flex-shrink-0 flex items-center justify-end gap-1.5 flex-wrap",children:[e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:Fe,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Fe)},title:o("common.copyUrl"),children:e.jsx(ye,{size:12})})]}),e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/api/"}),e.jsx("div",{className:"hub-endpoint-url",title:Ae,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Ae)},title:o("common.copyOpenApiUrl"),children:e.jsx(ye,{size:12})})]})]})]}),I==="cost"&&(n==null?void 0:n.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...n.items].sort((i,E)=>E.cost-i.cost).map(i=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:i.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:i.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ce(i.cost)})]},`${i.kind}:${i.name}`))}),I==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,E)=>{var S;return e.jsx(Tt,{server:s.name,tool:i,readOnly:!X,onToggle:Ms,onDescriptionUpdate:Bs,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="tool"&&B.name===i.name))==null?void 0:S.cost},E)})}),I==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,E)=>{var S;return e.jsx(Ft,{server:s.name,prompt:i,readOnly:!X,onToggle:Vs,onDescriptionUpdate:Ls,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="prompt"&&B.name===i.name))==null?void 0:S.cost},E)})}),I==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:o("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,E)=>{var S;return e.jsx(At,{resource:i,readOnly:!X,onToggle:Us,onDescriptionUpdate:Js,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="resource"&&B.name===i.uri))==null?void 0:S.cost},`${i.uri}-${E}`)})})})]})]}),e.jsx(xt,{isOpen:b!==null,target:b,onClose:()=>C(null)}),e.jsx(gt,{isOpen:H,onClose:()=>T(!1),onConfirm:()=>{t(s.name),T(!1)},serverName:s.name}),e.jsx(Te,{isOpen:M,onClose:()=>K(!1),onConfirm:()=>{K(!1),Is()},title:o("server.reinstall"),message:o("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:o("server.reinstall"),variant:"warning"}),e.jsx(Te,{isOpen:te,onClose:()=>y(!1),onConfirm:()=>{y(!1),Rs()},title:o("server.disconnectOAuth"),message:o("server.disconnectOAuthConfirm")||"This will revoke stored OAuth credentials where supported and require authorization again.",confirmText:o("server.disconnectOAuth"),variant:"warning"})]})},hs="-copy",Lt=s=>{const n=Math.max(jt-hs.length,0);return`${s.slice(0,n)}${hs}`},Jt=s=>{const{oauth:n,...t}=s.config??{},{accessToken:r,refreshToken:p,pendingAuthorization:l,...a}=n??{};return{name:Lt(s.name),status:"disconnected",config:{...t,...Object.keys(a).length>0?{oauth:a}:{}}}},Wt=(s,n)=>{if(s)return Object.fromEntries(Object.entries(s).map(([t,r])=>[n(t),r]))},qt=(s,n,t={})=>{const r=n.config;if(!r)return s;const p=t.nameSeparator||"-",l=new Set((n.tools??[]).map(f=>f.name)),a=f=>`${s.name}${f.slice(n.name.length)}`,j=`${n.name}${p}`,x=r.tools?Object.fromEntries(Object.entries(r.tools).flatMap(([f,o])=>l.has(f)?[[a(f),o]]:f.startsWith(j)&&l.has(`${j}${f}`)?[[f,o]]:f.startsWith(j)?[]:[[f,o]])):void 0,P=Wt(r.prompts,f=>f.startsWith(j)?a(f):f),d={};return x&&Object.keys(x).length>0&&(d.tools=x),P&&Object.keys(P).length>0&&(d.prompts=P),r.resources&&Object.keys(r.resources).length>0&&(d.resources=r.resources),{...s,config:{...s.config,...d}}},xs=(s,n)=>s===n?"commit":"stale",Ht=({onAdd:s,duplicateSource:n=null,onDuplicateCancel:t})=>{const{t:r}=ae(),{nameSeparator:p}=Pe(),[l,a]=c.useState(!1),[j,x]=c.useState(null),[P,d]=c.useState(!1),[f,o]=c.useState(null),[h,O]=c.useState([]),v=c.useMemo(()=>n?Jt(n):null,[n]),k=l||n!==null,D=()=>{x(null),d(!1),o(null)},_=()=>{a(!1),D(),n&&(t==null||t())},R=()=>{if(k){_();return}a(!0),D()},I=async()=>{f&&(await V(f),d(!1),o(null))},V=async T=>{try{x(null);const M=await ie("/servers",T);if(!M.success){M&&M.message?x(M.message):x(r("server.addError"));return}_(),s()}catch(M){console.error("Error adding server:",M),navigator.onLine?M instanceof TypeError&&(M.message.includes("NetworkError")||M.message.includes("Failed to fetch"))?x(r("errors.serverConnection")):x(r("errors.serverAdd")):x(r("errors.network"))}},H=async T=>{try{const M=n?qt(T,n,{nameSeparator:p}):T,K=vt(M);K.length>0?(O(K),o(M),d(!0)):await V(M)}catch(M){console.error("Error processing server submission:",M),x(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:R,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),k&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(vs,{onSubmit:H,onCancel:_,initialData:v,mode:"create",shareCandidatesFrom:n==null?void 0:n.name,modalTitle:n?r("server.duplicateTitle",{serverName:n.name}):r("server.addServer"),formError:j},(n==null?void 0:n.name)??"add")}),P&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700/60 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800 dark:text-yellow-300",children:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700 dark:text-yellow-300",children:h.map((T,M)=>e.jsxs("li",{className:"font-mono",children:["$",`{${T}}`]},M))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{d(!1),o(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:I,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},Kt=({server:s,onEdit:n,onCancel:t})=>{const{t:r}=ae(),[p,l]=c.useState(null),a=async j=>{try{l(null);const x=encodeURIComponent(s.name),P=j.name&&j.name!==s.name,d={config:j.config,...P?{newName:j.name}:{}},f=await ve(`/servers/${x}`,d);if(!f.success){f&&f.message?l(f.message):l(r("server.updateError",{serverName:s.name}));return}n()}catch(x){console.error("Error updating server:",x),navigator.onLine?x instanceof TypeError&&(x.message.includes("NetworkError")||x.message.includes("Failed to fetch"))?l(r("errors.serverConnection")):l(r("errors.serverUpdate",{serverName:s.name})):l(r("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(vs,{onSubmit:a,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:p},s.name)})},Gt=({onSuccess:s,onCancel:n})=>{const{t}=ae(),[r,p]=c.useState(!1),[l,a]=c.useState(!1),[j,x]=c.useState(null),[P,d]=c.useState(null),[f,o]=c.useState(!1),[h,O]=c.useState(null),[v,k]=c.useState(""),[D,_]=c.useState(!1),[R,I]=c.useState(""),V=u=>{u.preventDefault(),p(!0)},H=u=>{u.preventDefault(),p(!1)},T=u=>{u.preventDefault(),p(!1);const g=u.dataTransfer.files;if(g.length>0){const m=g[0];m.name.endsWith(".mcpb")?(d(m),x(null)):x(t("mcpb.invalidFileType"))}},M=u=>{const g=u.target.files;if(g&&g.length>0){const m=g[0];m.name.endsWith(".mcpb")?(d(m),x(null)):x(t("mcpb.invalidFileType"))}},K=async()=>{if(!P){x(t("mcpb.noFileSelected"));return}a(!0),x(null);try{const u=new FormData;u.append("mcpbFile",P);const g=await Ys(Zs("/mcpb/upload"),{method:"POST",body:u}),m=await g.json();if(!g.ok)throw new Error(m.message||`HTTP error! Status: ${g.status}`);if(m.success&&m.data)O(m.data.manifest),k(m.data.extractDir),o(!0);else throw new Error(m.message||t("mcpb.uploadFailed"))}catch(u){console.error("MCPB upload error:",u),x(u instanceof Error?u.message:t("mcpb.uploadFailed"))}finally{a(!1)}},te=async(u,g=!1)=>{var m;a(!0),x(null);try{const N=C(h,v,u);if(!g){const $=await bs("/servers");if($.success&&((m=$.data)==null?void 0:m.find(W=>W.name===u))){I(u),_(!0),a(!1);return}}let F;if(g?F=await ve(`/servers/${encodeURIComponent(u)}`,{name:u,config:N}):F=await ie("/servers",{name:u,config:N}),F.success)s(N);else throw new Error(F.message||t("mcpb.installFailed"))}catch(N){console.error("MCPB install error:",N),x(N instanceof Error?N.message:t("mcpb.installFailed")),a(!1)}},y=()=>{_(!1),R&&te(R,!0)},b=()=>{_(!1),I(""),a(!1)},C=(u,g,m)=>{var $;const N=(($=u.server)==null?void 0:$.mcp_config)||{},F={type:"stdio",command:N.command||"node",args:(N.args||[]).map(G=>G.replace("${__dirname}",g))};return N.env&&Object.keys(N.env).length>0&&(F.env={...N.env},Object.keys(F.env).forEach(G=>{typeof F.env[G]=="string"&&(F.env[G]=F.env[G].replace("${__dirname}",g))})),F};return f&&h?e.jsxs(e.Fragment,{children:[e.jsx(Te,{isOpen:D,onClose:b,onConfirm:y,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:R}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${D?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg",children:[e.jsx("h3",{className:"font-medium text-gray-900 mb-2",children:t("mcpb.extensionInfo")}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.name"),":"]})," ",h.display_name||h.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",h.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",h.description]}),h.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",h.author.name]}),h.tools&&h.tools.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.tools"),":"]}),e.jsx("ul",{className:"list-disc list-inside ml-4",children:h.tools.map((u,g)=>e.jsxs("li",{children:[u.name," - ",u.description]},g))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:h.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const u=document.getElementById("serverName"),g=(u==null?void 0:u.value.trim())||h.name;te(g)},disabled:l,className:"hub-btn primary",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${r?"border-blue-500 bg-blue-50 dark:bg-blue-900/20":P?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:V,onDragLeave:H,onDrop:T,children:[P?e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-green-200",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm text-gray-900 font-medium",children:P.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(P.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:M,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!P||l,className:"hub-btn primary flex items-center",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Xt=["sse","streamable-http"],Yt=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","protocolNegotiation","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),Zt=s=>{const n=[],t=[];for(const[r,p]of Object.entries(s.mcpServers)){const l=p??{},a={},j=Object.keys(l).filter(x=>!Yt.has(x));if(j.length>0){t.push({name:r,message:`unknown field(s) "${j.join('", "')}" — not part of the mcphub server schema. For OAuth, use an "oauth" object (e.g. {"scopes":["email"]}).`});continue}if(l.protocolNegotiation!==void 0){if(!["auto","legacy"].includes(l.protocolNegotiation)||l.protocolNegotiation==="auto"&&l.type!=="streamable-http"){t.push({name:r,message:"protocolNegotiation must be auto or legacy; auto requires streamable-http."});continue}a.protocolNegotiation=l.protocolNegotiation}if(l.type==="sse"||l.type==="streamable-http"){if(a.type=l.type,a.url=l.url,l.headers&&(a.headers=l.headers),l.oauth&&(a.oauth=l.oauth),!l.url){t.push({name:r,message:`"${l.type}" servers require a "url" field.`});continue}}else if(l.type==="openapi")a.type="openapi",a.openapi=l.openapi;else if(l.type===void 0||l.type==="stdio"){if(l.url&&!l.command){t.push({name:r,message:`has a "url" but type "${l.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(a.type="stdio",a.command=l.command,a.args=l.args||[],l.env&&(a.env=l.env),l.options&&(a.options=l.options),!l.command){t.push({name:r,message:'stdio servers require a "command" field.'});continue}}else{const x=Xt.includes(String(l.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:r,message:`unsupported type "${l.type}".${x}`});continue}n.push({name:r,config:a})}return{servers:n,issues:t}},Qt=({onSuccess:s,onCancel:n})=>{const{t}=ae(),[r,p]=c.useState(""),[l,a]=c.useState(null),[j,x]=c.useState(!1),[P,d]=c.useState(null),f=`{
6
+ }`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${v?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),v&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:v})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const y=JSON.parse(h);n(y)}catch{k(a("tool.invalidJsonFormat"))}},disabled:r||!!v,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:T,className:"space-y-4",children:[Object.entries(D.properties||{}).map(([y,b])=>te(y,b)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:r,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>n({}),disabled:r,className:"hub-btn primary",children:a(r?"tool.running":"tool.runTool")})]})]})},Et=({result:s,onClose:n})=>{const{t}=ae(),r=s.content,p=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",l=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(h=>l(h));if(typeof d!="object")return[];const f=[];d.type==="image"&&d.data&&f.push({data:String(d.data),mimeType:p(d.mimeType||d.mime_type)});const o=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return o&&f.push({data:String(o),mimeType:p(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&f.push(...l(d.image)),Array.isArray(d.images)&&f.push(...l(d.images)),Array.isArray(d.content)&&f.push(...l(d.content)),f},a=d=>{const f=[];try{const O=JSON.parse(d);if(f.push(...l(O)),f.length>0)return f}catch{}const o=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let h;for(;(h=o.exec(d))!==null;){const O=`image/${h[1]==="jpg"?"jpeg":h[1]}`;f.push({data:h[2],mimeType:O})}return f},j=d=>{try{const f=JSON.parse(d),o=h=>{if(Array.isArray(h))return h.map(o);if(h&&typeof h=="object"){const O={};for(const[v,k]of Object.entries(h))typeof k=="string"&&v.toLowerCase().includes("base64")?O[v]="[base64 omitted]":O[v]=o(k);return O}return h};return JSON.stringify(o(f),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},x=d=>Array.isArray(d)?d.map((f,o)=>e.jsx("div",{className:"mb-3 last:mb-0",children:P(f)},o)):P(d),P=d=>{if(typeof d=="string"){const f=a(d),o=j(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const f=a(d.text),o=j(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[f.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:f.map((h,O)=>e.jsx("img",{src:`data:${h.mimeType||"image/png"};base64,${h.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},O))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:o})]})}if(d.type==="image"&&d.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${d.mimeType||"image/png"};base64,${d.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const f=typeof d=="string"?JSON.parse(d):d;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),x(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),x(r)]}):e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},fe=({title:s,onClick:n,disabled:t=!1,loading:r=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:n,disabled:t,title:s,"aria-label":s,children:e.jsx(Qs,{size:14,className:r?"animate-spin":""})}),Dt=(s,n,t,r,p)=>(t?s.filter(l=>l!==n):[...s,n]).filter(l=>r.includes(l)&&!p.includes(l));function zt(s){return s==null?!0:typeof s=="string"?s.trim()==="":Array.isArray(s)?s.length===0:typeof s=="object"?Object.keys(s).length===0:!1}const Tt=({tool:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:p,cost:l})=>{var de,ue;const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[P,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,k]=c.useState(null),[D,_]=c.useState(!1),[R,I]=c.useState(!1),[V,H]=c.useState(s.description||""),T=c.useRef(null),M=c.useRef(null),[K,te]=c.useState(0),[y,b]=c.useState(!1),[C,u]=c.useState(s.hiddenParams||[]),[g,m]=c.useState(!1);c.useEffect(()=>{D&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[D,K]),c.useEffect(()=>{!D&&M.current&&te(M.current.offsetWidth)},[D,V]),c.useEffect(()=>{H(s.description||"")},[s.description]),c.useEffect(()=>{u(s.hiddenParams||[])},[s.hiddenParams]);const N=Object.keys(((de=s.inputSchema)==null?void 0:de.properties)||{}),F=Array.isArray((ue=s.inputSchema)==null?void 0:ue.required)?s.inputSchema.required:[],$=async(w,U)=>{if(t)return;const Y=Dt(C,w,U,N,F);m(!0);try{const X=await ks(n,s.name,Y);X.success?u(X.hiddenParams??Y):j(X.error||a("tool.hiddenParamsFailed"),"error")}finally{m(!1)}},G=s.name.replace(n+x,""),W=ht(s,a("tool.noDescription")),Z=W.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:W.defaultDescription}):void 0,q=c.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),z=c.useCallback(()=>{localStorage.removeItem(q())},[q]),L=w=>{!t&&r&&r(s.name,w)},se=()=>{t||_(!0)},oe=async()=>{if(!t)try{const w=await ws(n,s.name,V);w.success?(_(!1),p&&p(s.name,V)):(H(s.description||""),console.error("Failed to update tool description:",w.error))}catch(w){console.error("Error updating tool description:",w),H(s.description||""),_(!1)}},le=w=>{H(w.target.value)},J=async()=>{if(!t){I(!0);try{const w=await Cs(n,s.name);if(w.success){const U=w.description||"";H(U),_(!1),p==null||p(s.name,U,{restored:!0})}else j(w.error||a("tool.restoreDefaultFailed"),"error")}catch(w){console.error("Error resetting tool description:",w),j(a("tool.restoreDefaultFailed"),"error")}finally{I(!1)}}},ee=w=>{w.key==="Enter"?oe():w.key==="Escape"&&(H(s.description||""),_(!1))},A=async w=>{w.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),b(!0),j(a("common.copySuccess"),"success"),setTimeout(()=>b(!1),2e3)}catch(Y){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Y)}document.body.removeChild(U)}}catch(U){j(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},Q=async w=>{O(!0);try{w=Object.fromEntries(Object.entries(w).filter(([Y,X])=>!zt(X)));const U=await Ns({toolName:s.name,arguments:w},n);k(U)}catch(U){k({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{O(!1)}},re=()=>{o(!1),z(),k(null)},pe=()=>{k(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:w=>{w.stopPropagation(),d(!P)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:G}),e.jsx("button",{className:"hub-icon-btn sm",onClick:A,title:a("common.copy"),children:y?e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:V,onChange:le,onKeyDown:ee,onClick:w=>w.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),oe()},disabled:R,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),J()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:M,title:Z,children:W.currentDescription}),W.hasDescriptionOverride&&e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{color:"var(--hub-accent)",borderColor:"var(--hub-line)",background:"var(--hub-bg-2)"},title:Z,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),se()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),J()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:w=>w.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled??!0,onCheckedChange:L,disabled:h||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${G}`})}),e.jsxs("button",{onClick:w=>{w.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[W.hasDescriptionOverride&&W.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:a("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:W.defaultDescription})]}),!f&&N.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:4},children:a("tool.visibleParams")}),e.jsx("div",{style:{fontSize:11.5,color:"var(--hub-ink-3)",marginBottom:6},children:a("tool.visibleParamsHelp")}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 14px"},children:N.map(w=>{const U=F.includes(w);return e.jsxs("label",{className:"hub-mono",style:{fontSize:11.5,display:"flex",alignItems:"center",gap:5},title:U?a("tool.requiredParam"):void 0,children:[e.jsx("input",{type:"checkbox",checked:U||!C.includes(w),disabled:t||U||g,onChange:Y=>$(w,Y.target.checked)}),w,U&&" *"]},w)})})]}),!f&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:s.inputSchema||{type:"object"},onSubmit:Q,onCancel:re,loading:h,storageKey:q(),title:a("tool.runToolWithName",{name:G})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Et,{result:v,onClose:pe})})]})]})]})},$t=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",r=await ie(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ps=async(s,n)=>{try{const t=await ie(`/mcp/${encodeURIComponent(n||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},It=async(s,n,t)=>{try{const r=await ie(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Es=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ds=async(s,n)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Rt=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:$t,getPrompt:Ps,resetPromptDescription:Ds,togglePrompt:It,updatePromptDescription:Es},Symbol.toStringTag,{value:"Module"})),cs=({result:s,onClose:n})=>{const{t}=ae(),r=p=>{if(typeof p=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:p})});if(typeof p=="object"&&p!==null){if(p.description||p.messages)return e.jsxs("div",{className:"space-y-4",children:[p.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:p.description})})]}),p.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:p.messages.map((l,a)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"flex items-center mb-2",children:e.jsxs("span",{className:"inline-block w-16 text-xs font-medium text-gray-500",children:[l.role,":"]})}),typeof l.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content}):typeof l.content=="object"&&l.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:l.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(l.content,null,2)})]},a))})]})]});try{const l=typeof p=="string"?JSON.parse(p):p;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(l,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(p)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(p)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(fs,{size:20,className:"text-status-green"}):e.jsx(gs,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),r(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ce,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700/60 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 dark:text-red-300 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Ft=({prompt:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:p,cost:l})=>{const{t:a}=ae(),{showToast:j}=we(),{nameSeparator:x}=Pe(),[P,d]=c.useState(!1),[f,o]=c.useState(!1),[h,O]=c.useState(!1),[v,k]=c.useState(null),[D,_]=c.useState(!1),[R,I]=c.useState(!1),[V,H]=c.useState(s.description||""),T=c.useRef(null),M=c.useRef(null),[K,te]=c.useState(0);c.useEffect(()=>{D&&T.current&&(T.current.focus(),K>0&&(T.current.style.width=`${K+20}px`))},[D,K]),c.useEffect(()=>{!D&&M.current&&te(M.current.offsetWidth)},[D,V]),c.useEffect(()=>{H(s.description||"")},[s.description]);const y=c.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),b=c.useCallback(()=>{localStorage.removeItem(y())},[y]),C=z=>{!t&&r&&r(s.name,z)},u=()=>{t||_(!0)},g=async()=>{if(!t){_(!1);try{const z=await Es(n,s.name,V);z.success?p&&p(s.name,V):(j(z.error||a("prompt.descriptionUpdateFailed"),"error"),H(s.description||""))}catch(z){console.error("Error updating prompt description:",z),j(a("prompt.descriptionUpdateFailed"),"error"),H(s.description||"")}}},m=async()=>{if(!t){I(!0);try{const z=await Ds(n,s.name);if(z.success){const L=z.description||"";H(L),_(!1),p==null||p(s.name,L,{restored:!0})}else j(z.error||a("prompt.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting prompt description:",z),j(a("prompt.restoreDefaultFailed"),"error")}finally{I(!1)}}},N=z=>{H(z.target.value)},F=z=>{z.key==="Enter"?g():z.key==="Escape"&&(H(s.description||""),_(!1))},$=async z=>{O(!0);try{const L=await Ps({promptName:s.name,arguments:z},n);console.log("GetPrompt result:",L),k({success:L.success,data:L.data,error:L.error})}catch(L){k({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{O(!1)}},G=()=>{o(!1),b(),k(null)},W=()=>{k(null)},Z=s.name.replace(n+x,""),q=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const z={},L=[];return s.arguments.forEach(se=>{z[se.name]={type:"string",description:se.description||""},se.required&&L.push(se.name)}),{type:"object",properties:z,required:L}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>d(!P),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:Z}),s.title&&e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.title}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:D?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:V,onChange:N,onKeyDown:F,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),g()},disabled:R,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),m()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:M,children:V||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),u()},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),m()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[l!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ce(l)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ee,{checked:s.enabled,onCheckedChange:C,disabled:h||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${Z}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),d(!0),o(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:h||!s.enabled,children:[h?e.jsx(ys,{size:12,className:"animate-spin"}):e.jsx(js,{size:12}),e.jsx("span",{children:a(h?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:P?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),P&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[f&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ss,{schema:q(),onSubmit:$,onCancel:G,loading:h,storageKey:y(),title:a("prompt.runPromptWithName",{name:Z})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(cs,{result:v,onClose:W})})]}),!f&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((z,L)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:z.name}),z.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),z.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:z.description})]}),z.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:z.title})]},L))})]}),!f&&v&&e.jsx("div",{children:e.jsx(cs,{result:v,onClose:W})})]})]})},At=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:r,cost:p})=>{const{t:l}=ae(),[a,j]=c.useState(!1),[x,P]=c.useState(!1),[d,f]=c.useState(!1),[o,h]=c.useState(s.description||""),O=c.useRef(null),v=c.useRef(null),[k,D]=c.useState(0);c.useEffect(()=>{x&&O.current&&(O.current.focus(),k>0&&(O.current.style.width=`${k+20}px`))},[x,k]),c.useEffect(()=>{!x&&v.current&&D(v.current.offsetWidth)},[x,o]),c.useEffect(()=>{h(s.description||"")},[s.description]);const _=s.name||s.uri,R=T=>{!n&&t&&t(s.uri,T)},I=async()=>{n||(P(!1),r&&await r(s.uri,o))},V=async()=>{if(!n){f(!0);try{await(r==null?void 0:r(s.uri,"",{restored:!0})),P(!1)}finally{f(!1)}}},H=T=>{T.key==="Enter"?I():T.key==="Escape"&&(h(s.description||""),P(!1))};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>j(!a),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:_}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:x?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:O,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:k>0?`${k+20}px`:160,minWidth:80},value:o,onChange:T=>h(T.target.value),onKeyDown:H,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),I()},disabled:d,children:e.jsx(je,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),V()},disabled:d,loading:d})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:o||l("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),P(!0)},children:e.jsx(Ie,{size:12})}),e.jsx(fe,{title:l("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),V()},disabled:d,loading:d})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[p!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:l("cost.estimate"),children:["Σ ",ce(p)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:T=>T.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled!==!1,onCheckedChange:R,disabled:n,size:"card","aria-label":`${l(s.enabled!==!1?"server.disable":"server.enable")} ${_}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ke,{size:14}):e.jsx(Se,{size:14})})]})]}),a&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[l("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Ot={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Shared",longKey:"server.visibilityGroup",longFallback:"Shared — selected users only",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Re=s=>s==="public"||s==="group"?s:"private",_t=(s,n)=>{const t=Re(n),r=Ot[t];return{value:t,shortLabel:s(r.shortKey,{defaultValue:r.shortFallback}),longLabel:s(r.longKey,{defaultValue:r.longFallback}),className:r.className}},Mt=(s,n)=>{const t=Re(n),r=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&r.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Shared"}),disabled:!0}),r.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),r},ds=({isLoading:s,children:n,className:t,overlayStyle:r,spinnerSize:p=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:n}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...r},children:e.jsx(be,{size:p,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),us=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),ms=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,Vt="text/html;profile=mcp-app",ps=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Ut=s=>{var n,t;return!!((n=s.tools)!=null&&n.some(r=>ps(r._meta))||(t=s.resources)!=null&&t.some(r=>{var p;return((p=r.uri)==null?void 0:p.startsWith("ui://"))||r.mimeType===Vt||ps(r._meta)}))},Bt=({server:s,cost:n,onRemove:t,onEdit:r,onDuplicate:p,isDuplicating:l=!1,onToggle:a,onVisibilityChange:j,onRefresh:x,onReload:P,onReinstall:d,onOAuthDisconnect:f})=>{var Ve,Ue,Be,Le,Je,We,qe,He,Ke,Ge,Xe,Ye,Ze,Qe,es,ss,ts,rs,ns,as,os,is;const{t:o}=ae(),{showToast:h}=we(),{exportMCPSettings:O,installConfig:v}=Pe(),{auth:k}=Xs(),D=((Ve=v==null?void 0:v.baseUrl)==null?void 0:Ve.replace(/\/+$/,""))||"",[_,R]=c.useState(!1),[I,V]=c.useState(null),[H,T]=c.useState(!1),[M,K]=c.useState(!1),[te,y]=c.useState(!1),[b,C]=c.useState(null),[u,g]=c.useState(!1),[m,N]=c.useState(!1),[F,$]=c.useState(!1),[G,W]=c.useState(!1),[Z,q]=c.useState(!1),[z,L]=c.useState(!1),[se,oe]=c.useState(!1),[le,J]=c.useState(!1),ee=c.useRef(null),A=c.useRef(null);c.useEffect(()=>{const i=E=>{ee.current&&!ee.current.contains(E.target)&&L(!1),A.current&&!A.current.contains(E.target)&&oe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const Q=((Ue=s.tools)==null?void 0:Ue.length)||0,re=((Be=s.tools)==null?void 0:Be.filter(i=>i.enabled!==!1).length)||0,pe=((Le=s.prompts)==null?void 0:Le.length)||0,de=((Je=s.prompts)==null?void 0:Je.filter(i=>i.enabled!==!1).length)||0,ue=((We=s.resources)==null?void 0:We.length)||0,w=((qe=s.resources)==null?void 0:qe.filter(i=>i.enabled!==!1).length)||0,U=Ut(s),Y=s.enabled!==!1,X=yt(s,k.user),ge=((He=s.config)==null?void 0:He.command)==="npx"||((Ke=s.config)==null?void 0:Ke.command)==="uvx",he=ge?s.packageVersion:void 0,De=he||s.version,zs=!!(((Xe=(Ge=s.config)==null?void 0:Ge.oauth)==null?void 0:Xe.identityMode)!=="personal"&&((Ye=s.oauth)!=null&&Ye.connected)&&f),Ts=async i=>{if(!(!X||u||!a)){g(!0);try{await a(s,i)}finally{g(!1)}}},$s=async i=>{if(i.stopPropagation(),L(!1),!(!X||F||!P)){$(!0);try{await P(s)?h(o("server.reloadSuccess")||"Server reloaded successfully","success"):h(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{$(!1)}}},Is=async()=>{if(L(!1),!(!X||G||!d)){W(!0);try{await d(s)?h(o("server.reinstallSuccess")||"Server reinstall initiated","success"):h(o("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{W(!1)}}},Rs=async()=>{if(L(!1),!(!X||Z||!f)){q(!0);try{await f(s)?h(o("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):h(o("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{q(!1)}}},Fs=async i=>{var S;if(i.stopPropagation(),!X||m||!j)return;const E=i.target.value;if(E!==Re(s.visibility??((S=s.config)==null?void 0:S.visibility))){N(!0);try{await j(s,E)}finally{N(!1)}}},As=async i=>{if(i.stopPropagation(),!s.error)return;await ls(s.error)?(J(!0),h(o("common.copySuccess")||"Copied","success"),setTimeout(()=>J(!1),1500)):h(o("common.copyFailed")||"Copy failed","error")},Os=async i=>{var E,S;if(i.stopPropagation(),L(!1),!!X)try{const B=await O(s.name),ne=(S=(E=B==null?void 0:B.data)==null?void 0:E.mcpServers)==null?void 0:S[s.name];if(!B||!B.success||!ne){h((B==null?void 0:B.message)||o("common.copyFailed")||"Copy failed","error");return}C(bt(s.name,ne))}catch(B){console.error("Error copying server configuration:",B),h(o("common.copyFailed")||"Copy failed","error")}},_s=i=>{var E;if(i.stopPropagation(),(E=s.oauth)!=null&&E.authorizationUrl){const ne=window.screen.width/2-300,me=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ne},top=${me}`),h(o("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&h(o("status.oauthClientIdHint"),"warning")}},Ms=async(i,E)=>{try{const{toggleTool:S}=await Ne(async()=>{const{toggleTool:ne}=await Promise.resolve().then(()=>Pt);return{toggleTool:ne}},void 0,import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Vs=async(i,E)=>{try{const{togglePrompt:S}=await Ne(async()=>{const{togglePrompt:ne}=await Promise.resolve().then(()=>Rt);return{togglePrompt:ne}},void 0,import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Us=async(i,E)=>{try{const{toggleResource:S}=await Ne(async()=>{const{toggleResource:ne}=await import("./resourceService-BNH7uNar.js");return{toggleResource:ne}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),B=await S(s.name,i,E);B.success?(h(o(E?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),x==null||x()):h(B.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),h(o("tool.toggleFailed"),"error")}},Bs=(i,E,S)=>{h(S!=null&&S.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),x==null||x()},Ls=(i,E,S)=>{h(S!=null&&S.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),x==null||x()},Js=async(i,E,S)=>{try{const{updateResourceDescription:B,resetResourceDescription:ne}=await Ne(async()=>{const{updateResourceDescription:qs,resetResourceDescription:Hs}=await import("./resourceService-BNH7uNar.js");return{updateResourceDescription:qs,resetResourceDescription:Hs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),me=S!=null&&S.restored?await ne(s.name,i):await B(s.name,i,E);me.success?(h(S!=null&&S.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),x==null||x()):h(me.error||(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(B){console.error(B),h(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var S;const i=s.config;if(!i)return"";if(i.url)return i.url;const E=[];return i.command&&E.push(i.command),(S=i.args)!=null&&S.length&&E.push(...i.args),E.join(" ")})();const Fe=`${D}/mcp/${s.name}`,Ae=`${D}/api/${s.name}`,Oe=async i=>{const E=await ls(i);h(E?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",E?"success":"error")},_e=(i,E)=>o(i,E),xe=_t(_e,s.visibility??((Ze=s.config)==null?void 0:Ze.visibility)),Ws=Mt(_e,xe.value),Me=[{key:"tools",icon:et,total:Q,enabled:re,label:o("server.tools")},{key:"prompts",icon:st,total:pe,enabled:de,label:o("server.prompts")},{key:"resources",icon:tt,total:ue,enabled:w,label:o("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>R(!_),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(Se,{size:12,style:{color:"var(--hub-ink-3)",transform:_?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"hub-mono min-w-0 max-w-full truncate",title:s.name,style:{fontSize:13.5,color:Y?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),De&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o(he?"server.packageVersion":"server.reportedVersion")}: ${De}`,style:{fontSize:11},children:e.jsxs("span",{className:"truncate",children:["v",De]})}),ge&&s.updateAvailable&&s.latestVersion&&e.jsx("span",{className:"hub-tag min-w-0",title:`${o("server.updateAvailable")}: ${s.latestVersion}`,style:{fontSize:11,color:"var(--hub-warn)"},children:e.jsxs("span",{className:"truncate",children:["↑ ",s.latestVersion]})}),U&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:A,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),oe(E=>!E)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ce,{size:14})}),se&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:o("server.errorDetails")}),e.jsx("button",{onClick:As,className:"hub-icon-btn sm",title:o("common.copy"),children:le?e.jsx(je,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>oe(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(ze,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),!!((es=(Qe=s.config)==null?void 0:Qe.credentialTemplate)!=null&&es.length)&&e.jsxs(Ks,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[o("credentials.personalBadge")," · ",o("credentials.manage")]}),((ss=s.config)==null?void 0:ss.description)&&e.jsx("div",{className:"text-[11.5px] truncate",style:{color:"var(--hub-ink-3)",marginTop:1},title:s.config.description,children:s.config.description})]})]}),e.jsxs("div",{className:`hub-server-card-status-cell min-w-0${Y&&s.recovery?" hub-server-card-recovering":""}`,children:[((rs=(ts=s.config)==null?void 0:ts.oauth)==null?void 0:rs.identityMode)==="personal"?e.jsx(Ct,{serverName:s.name,enabled:Y}):e.jsx(pt,{status:s.status,enabled:s.enabled,startOnDemand:((ns=s.config)==null?void 0:ns.startOnDemand)===!0,onAuthClick:_s,className:"hub-server-card-status"}),Y&&s.recovery&&e.jsxs("div",{className:"text-xs mt-1",style:{color:"var(--hub-ink-3)",maxWidth:160},children:[e.jsx("div",{children:s.recovery.nextAttemptAt?o("server.retryScheduled",{time:new Date(s.recovery.nextAttemptAt).toLocaleTimeString(void 0,{hour12:!1})}):o("server.reconnecting")}),s.recovery.lastAttemptAt&&e.jsx("div",{children:o("server.lastRetry",{count:s.recovery.attempts,time:new Date(s.recovery.lastAttemptAt).toLocaleTimeString(void 0,{hour12:!1})})})]})]}),e.jsxs("div",{className:"hub-server-card-transport-cell min-w-0",children:[(as=s.config)!=null&&as.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:ms(o,s.config.type)??void 0,children:ms(o,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"}),((os=s.config)==null?void 0:os.type)!=="openapi"&&e.jsxs("span",{className:"hub-server-card-protocol",title:o("server.protocolVersion"),children:["MCP"," ",Y&&s.status==="connected"&&s.protocolVersion?e.jsx("span",{className:"whitespace-nowrap",children:s.protocolVersion}):o("server.protocolVersionUnknown")]})]}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:i=>i.stopPropagation(),children:X&&j?e.jsx(ds,{isLoading:m,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:xe.value,onChange:Fs,disabled:m,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":o("server.visibility","Visibility"),title:xe.longLabel,children:Ws.map(i=>e.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${xe.className}`,title:xe.longLabel,children:xe.shortLabel})}),Me.map(({key:i,icon:E,total:S,enabled:B,label:ne})=>{const me=S===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${me?"is-empty":""}`,title:`${ne}: ${B}/${S}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(us,{icon:E})}),e.jsx("span",{className:"hub-server-capability-value",children:me?"0":`${B}/${S}`})]},i)}),n&&n.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${n.exposed} / ${o("cost.gross")} ${n.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ce(n.exposed),"/",ce(n.gross)]})]}):n?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:o("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:i=>i.stopPropagation(),children:e.jsx(ds,{isLoading:u,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ee,{checked:Y,onCheckedChange:Ts,disabled:u||!X,size:"compact","aria-label":`${o(Y?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:ee,children:[X&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),L(E=>!E)},"aria-label":"More","aria-busy":l,children:l?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(rt,{size:14})}),X&&z&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:i=>i.stopPropagation(),children:[e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),r(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(nt,{size:13})," ",o("server.edit")]}),p&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!l&&p(s)},disabled:l,"aria-busy":l,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[l?e.jsx(be,{size:13,className:"animate-spin"}):e.jsx(at,{size:13})," ",o("server.duplicate")]}),e.jsxs("button",{onClick:Os,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),P&&e.jsxs("button",{onClick:$s,disabled:F||u||!Y,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(be,{size:13})," ",o("server.reload")]}),d&&ge&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!X||G||!Y)&&K(!0)},disabled:G||u||!Y,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(ot,{size:13})," ",o("server.reinstall")]}),zs&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!X||Z)&&y(!0)},disabled:Z,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(it,{size:13})," ",o("server.disconnectOAuth")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),T(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(lt,{size:13})," ",o("server.delete")]})]})]})]}),_&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[((is=s.config)==null?void 0:is.description)&&e.jsxs("section",{className:"mb-3","aria-labelledby":`server-about-${s.name}`,children:[e.jsx("h3",{id:`server-about-${s.name}`,className:"text-[11px] font-medium tracking-wide uppercase",style:{color:"var(--hub-ink-3)",marginBottom:6},children:o("server.description")}),e.jsx("p",{className:"text-[13px] leading-5 whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.config.description})]}),e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Me.map(i=>{const E=I===i.key,S=i.icon;return e.jsxs("button",{onClick:()=>V(E?null:i.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:E?"var(--hub-surface)":"transparent",border:"1px solid "+(E?"var(--hub-line)":"transparent"),color:E?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(us,{icon:S}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),n&&n.connected&&e.jsxs("button",{onClick:()=>V(I==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:I==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(I==="cost"?"var(--hub-line)":"transparent"),color:I==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:o("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:o("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ce(n.exposed),"/",ce(n.gross)]})]}),e.jsxs("div",{className:"ml-auto max-w-full flex-shrink-0 flex items-center justify-end gap-1.5 flex-wrap",children:[e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:Fe,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Fe)},title:o("common.copyUrl"),children:e.jsx(ye,{size:12})})]}),e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/api/"}),e.jsx("div",{className:"hub-endpoint-url",title:Ae,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Ae)},title:o("common.copyOpenApiUrl"),children:e.jsx(ye,{size:12})})]})]})]}),I==="cost"&&(n==null?void 0:n.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...n.items].sort((i,E)=>E.cost-i.cost).map(i=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:i.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:i.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ce(i.cost)})]},`${i.kind}:${i.name}`))}),I==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,E)=>{var S;return e.jsx(Tt,{server:s.name,tool:i,readOnly:!X,onToggle:Ms,onDescriptionUpdate:Bs,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="tool"&&B.name===i.name))==null?void 0:S.cost},E)})}),I==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,E)=>{var S;return e.jsx(Ft,{server:s.name,prompt:i,readOnly:!X,onToggle:Vs,onDescriptionUpdate:Ls,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="prompt"&&B.name===i.name))==null?void 0:S.cost},E)})}),I==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:o("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,E)=>{var S;return e.jsx(At,{resource:i,readOnly:!X,onToggle:Us,onDescriptionUpdate:Js,cost:(S=n==null?void 0:n.items.find(B=>B.kind==="resource"&&B.name===i.uri))==null?void 0:S.cost},`${i.uri}-${E}`)})})})]})]}),e.jsx(xt,{isOpen:b!==null,target:b,onClose:()=>C(null)}),e.jsx(gt,{isOpen:H,onClose:()=>T(!1),onConfirm:()=>{t(s.name),T(!1)},serverName:s.name}),e.jsx(Te,{isOpen:M,onClose:()=>K(!1),onConfirm:()=>{K(!1),Is()},title:o("server.reinstall"),message:o("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:o("server.reinstall"),variant:"warning"}),e.jsx(Te,{isOpen:te,onClose:()=>y(!1),onConfirm:()=>{y(!1),Rs()},title:o("server.disconnectOAuth"),message:o("server.disconnectOAuthConfirm")||"This will revoke stored OAuth credentials where supported and require authorization again.",confirmText:o("server.disconnectOAuth"),variant:"warning"})]})},hs="-copy",Lt=s=>{const n=Math.max(jt-hs.length,0);return`${s.slice(0,n)}${hs}`},Jt=s=>{const{oauth:n,...t}=s.config??{},{accessToken:r,accessTokenExpiresAt:p,refreshToken:l,pendingAuthorization:a,...j}=n??{};return{name:Lt(s.name),status:"disconnected",config:{...t,...Object.keys(j).length>0?{oauth:j}:{}}}},Wt=(s,n)=>{if(s)return Object.fromEntries(Object.entries(s).map(([t,r])=>[n(t),r]))},qt=(s,n,t={})=>{const r=n.config;if(!r)return s;const p=t.nameSeparator||"-",l=new Set((n.tools??[]).map(f=>f.name)),a=f=>`${s.name}${f.slice(n.name.length)}`,j=`${n.name}${p}`,x=r.tools?Object.fromEntries(Object.entries(r.tools).flatMap(([f,o])=>l.has(f)?[[a(f),o]]:f.startsWith(j)&&l.has(`${j}${f}`)?[[f,o]]:f.startsWith(j)?[]:[[f,o]])):void 0,P=Wt(r.prompts,f=>f.startsWith(j)?a(f):f),d={};return x&&Object.keys(x).length>0&&(d.tools=x),P&&Object.keys(P).length>0&&(d.prompts=P),r.resources&&Object.keys(r.resources).length>0&&(d.resources=r.resources),{...s,config:{...s.config,...d}}},xs=(s,n)=>s===n?"commit":"stale",Ht=({onAdd:s,duplicateSource:n=null,onDuplicateCancel:t})=>{const{t:r}=ae(),{nameSeparator:p}=Pe(),[l,a]=c.useState(!1),[j,x]=c.useState(null),[P,d]=c.useState(!1),[f,o]=c.useState(null),[h,O]=c.useState([]),v=c.useMemo(()=>n?Jt(n):null,[n]),k=l||n!==null,D=()=>{x(null),d(!1),o(null)},_=()=>{a(!1),D(),n&&(t==null||t())},R=()=>{if(k){_();return}a(!0),D()},I=async()=>{f&&(await V(f),d(!1),o(null))},V=async T=>{try{x(null);const M=await ie("/servers",T);if(!M.success){M&&M.message?x(M.message):x(r("server.addError"));return}_(),s()}catch(M){console.error("Error adding server:",M),navigator.onLine?M instanceof TypeError&&(M.message.includes("NetworkError")||M.message.includes("Failed to fetch"))?x(r("errors.serverConnection")):x(r("errors.serverAdd")):x(r("errors.network"))}},H=async T=>{try{const M=n?qt(T,n,{nameSeparator:p}):T,K=vt(M);K.length>0?(O(K),o(M),d(!0)):await V(M)}catch(M){console.error("Error processing server submission:",M),x(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:R,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),k&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(vs,{onSubmit:H,onCancel:_,initialData:v,mode:"create",shareCandidatesFrom:n==null?void 0:n.name,modalTitle:n?r("server.duplicateTitle",{serverName:n.name}):r("server.addServer"),formError:j},(n==null?void 0:n.name)??"add")}),P&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700/60 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800 dark:text-yellow-300",children:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700 dark:text-yellow-300",children:h.map((T,M)=>e.jsxs("li",{className:"font-mono",children:["$",`{${T}}`]},M))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{d(!1),o(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:I,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},Kt=({server:s,onEdit:n,onCancel:t})=>{const{t:r}=ae(),[p,l]=c.useState(null),a=async j=>{try{l(null);const x=encodeURIComponent(s.name),P=j.name&&j.name!==s.name,d={config:j.config,...P?{newName:j.name}:{}},f=await ve(`/servers/${x}`,d);if(!f.success){f&&f.message?l(f.message):l(r("server.updateError",{serverName:s.name}));return}n()}catch(x){console.error("Error updating server:",x),navigator.onLine?x instanceof TypeError&&(x.message.includes("NetworkError")||x.message.includes("Failed to fetch"))?l(r("errors.serverConnection")):l(r("errors.serverUpdate",{serverName:s.name})):l(r("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(vs,{onSubmit:a,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:p},s.name)})},Gt=({onSuccess:s,onCancel:n})=>{const{t}=ae(),[r,p]=c.useState(!1),[l,a]=c.useState(!1),[j,x]=c.useState(null),[P,d]=c.useState(null),[f,o]=c.useState(!1),[h,O]=c.useState(null),[v,k]=c.useState(""),[D,_]=c.useState(!1),[R,I]=c.useState(""),V=u=>{u.preventDefault(),p(!0)},H=u=>{u.preventDefault(),p(!1)},T=u=>{u.preventDefault(),p(!1);const g=u.dataTransfer.files;if(g.length>0){const m=g[0];m.name.endsWith(".mcpb")?(d(m),x(null)):x(t("mcpb.invalidFileType"))}},M=u=>{const g=u.target.files;if(g&&g.length>0){const m=g[0];m.name.endsWith(".mcpb")?(d(m),x(null)):x(t("mcpb.invalidFileType"))}},K=async()=>{if(!P){x(t("mcpb.noFileSelected"));return}a(!0),x(null);try{const u=new FormData;u.append("mcpbFile",P);const g=await Ys(Zs("/mcpb/upload"),{method:"POST",body:u}),m=await g.json();if(!g.ok)throw new Error(m.message||`HTTP error! Status: ${g.status}`);if(m.success&&m.data)O(m.data.manifest),k(m.data.extractDir),o(!0);else throw new Error(m.message||t("mcpb.uploadFailed"))}catch(u){console.error("MCPB upload error:",u),x(u instanceof Error?u.message:t("mcpb.uploadFailed"))}finally{a(!1)}},te=async(u,g=!1)=>{var m;a(!0),x(null);try{const N=C(h,v,u);if(!g){const $=await bs("/servers");if($.success&&((m=$.data)==null?void 0:m.find(W=>W.name===u))){I(u),_(!0),a(!1);return}}let F;if(g?F=await ve(`/servers/${encodeURIComponent(u)}`,{name:u,config:N}):F=await ie("/servers",{name:u,config:N}),F.success)s(N);else throw new Error(F.message||t("mcpb.installFailed"))}catch(N){console.error("MCPB install error:",N),x(N instanceof Error?N.message:t("mcpb.installFailed")),a(!1)}},y=()=>{_(!1),R&&te(R,!0)},b=()=>{_(!1),I(""),a(!1)},C=(u,g,m)=>{var $;const N=(($=u.server)==null?void 0:$.mcp_config)||{},F={type:"stdio",command:N.command||"node",args:(N.args||[]).map(G=>G.replace("${__dirname}",g))};return N.env&&Object.keys(N.env).length>0&&(F.env={...N.env},Object.keys(F.env).forEach(G=>{typeof F.env[G]=="string"&&(F.env[G]=F.env[G].replace("${__dirname}",g))})),F};return f&&h?e.jsxs(e.Fragment,{children:[e.jsx(Te,{isOpen:D,onClose:b,onConfirm:y,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:R}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${D?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg",children:[e.jsx("h3",{className:"font-medium text-gray-900 mb-2",children:t("mcpb.extensionInfo")}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.name"),":"]})," ",h.display_name||h.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",h.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",h.description]}),h.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",h.author.name]}),h.tools&&h.tools.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.tools"),":"]}),e.jsx("ul",{className:"list-disc list-inside ml-4",children:h.tools.map((u,g)=>e.jsxs("li",{children:[u.name," - ",u.description]},g))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:h.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const u=document.getElementById("serverName"),g=(u==null?void 0:u.value.trim())||h.name;te(g)},disabled:l,className:"hub-btn primary",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 dark:text-red-300",children:j})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${r?"border-blue-500 bg-blue-50 dark:bg-blue-900/20":P?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:V,onDragLeave:H,onDrop:T,children:[P?e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-green-200",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm text-gray-900 font-medium",children:P.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(P.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:M,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:l,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!P||l,className:"hub-btn primary flex items-center",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Xt=["sse","streamable-http"],Yt=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","protocolNegotiation","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),Zt=s=>{const n=[],t=[];for(const[r,p]of Object.entries(s.mcpServers)){const l=p??{},a={},j=Object.keys(l).filter(x=>!Yt.has(x));if(j.length>0){t.push({name:r,message:`unknown field(s) "${j.join('", "')}" — not part of the mcphub server schema. For OAuth, use an "oauth" object (e.g. {"scopes":["email"]}).`});continue}if(l.protocolNegotiation!==void 0){if(!["auto","legacy"].includes(l.protocolNegotiation)||l.protocolNegotiation==="auto"&&l.type!=="streamable-http"){t.push({name:r,message:"protocolNegotiation must be auto or legacy; auto requires streamable-http."});continue}a.protocolNegotiation=l.protocolNegotiation}if(l.type==="sse"||l.type==="streamable-http"){if(a.type=l.type,a.url=l.url,l.headers&&(a.headers=l.headers),l.oauth&&(a.oauth=l.oauth),!l.url){t.push({name:r,message:`"${l.type}" servers require a "url" field.`});continue}}else if(l.type==="openapi")a.type="openapi",a.openapi=l.openapi;else if(l.type===void 0||l.type==="stdio"){if(l.url&&!l.command){t.push({name:r,message:`has a "url" but type "${l.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(a.type="stdio",a.command=l.command,a.args=l.args||[],l.env&&(a.env=l.env),l.options&&(a.options=l.options),!l.command){t.push({name:r,message:'stdio servers require a "command" field.'});continue}}else{const x=Xt.includes(String(l.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:r,message:`unsupported type "${l.type}".${x}`});continue}n.push({name:r,config:a})}return{servers:n,issues:t}},Qt=({onSuccess:s,onCancel:n})=>{const{t}=ae(),[r,p]=c.useState(""),[l,a]=c.useState(null),[j,x]=c.useState(!1),[P,d]=c.useState(null),f=`{
7
7
  "mcpServers": {
8
8
  "stdio-server-example": {
9
9
  "command": "npx",
@@ -36,4 +36,4 @@ All servers will be imported in a single efficient batch operation.`,o=v=>{try{c
36
36
  `+_),k.length===0)return}d(k)},O=async()=>{if(P){x(!0),a(null);try{const v=await ie("/servers/batch",{servers:P});if(v.success&&v.data){const{successCount:k,failureCount:D,results:_}=v.data;if(D>0){const R=_.filter(I=>!I.success).map(I=>`${I.name}: ${I.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:k,total:P.length})+`
37
37
  `+R.join(`
38
38
  `))}k>0&&s()}else a(v.message||t("jsonImport.importFailed"))}catch(v){console.error("Import error:",v),a(t("jsonImport.importFailed"))}finally{x(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),l&&e.jsx("div",{className:"mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 whitespace-pre-wrap",children:l})}),P?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-3",children:t("jsonImport.previewTitle")}),e.jsx("div",{className:"space-y-3",children:P.map((v,k)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:v.name}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm text-gray-600",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.type"),":"]})," ",v.config.type||"stdio"]}),v.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",v.config.command]}),v.config.args&&v.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",v.config.args.join(" ")]}),v.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",v.config.url]}),v.config.env&&Object.keys(v.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(v.config.env).join(", ")]}),v.config.headers&&Object.keys(v.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(v.config.headers).join(", ")]})]})]})})},k))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>d(null),disabled:j,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:O,disabled:j,className:"hub-btn primary",children:j?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:r,onChange:v=>p(v.target.value),className:"w-full h-96 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-sm",placeholder:f}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:h,disabled:!r.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},er=s=>({all:s.length,online:s.filter(n=>n.status==="connected").length,issues:s.filter(n=>n.status!=="connected"&&n.enabled!==!1).length,disabled:s.filter(n=>n.enabled===!1).length}),sr=(s,n,t="")=>{const r=t.trim().toLowerCase();return s.filter(p=>{var a,j;return n==="online"&&p.status!=="connected"||n==="issues"&&(p.status==="connected"||p.enabled===!1)||n==="disabled"&&p.enabled!==!1?!1:r?(p.name+" "+(((a=p.config)==null?void 0:a.description)||"")+" "+(((j=p.tools)==null?void 0:j.map(x=>x.name).join(" "))||"")).toLowerCase().includes(r):!0})},tr=(s,n,t,r,p)=>{const l=sr(s,n,t),a=l.length,j=Math.max(1,Math.ceil(a/p)),x=Math.min(Math.max(1,r),j),P=(x-1)*p;return{servers:l.slice(P,P+p),pagination:{page:x,limit:p,total:a,totalPages:j,hasNextPage:x<j,hasPrevPage:x>1}}},gr=()=>{const{t:s}=ae(),n=Gs(),{servers:t,allServers:r,error:p,setError:l,isLoading:a,currentPage:j,serversPerPage:x,setCurrentPage:P,setServersPerPage:d,handleServerAdd:f,handleServerEdit:o,handleServerRemove:h,handleServerToggle:O,handleServerVisibilityChange:v,handleServerReload:k,handleServerReinstall:D,handleServerOAuthDisconnect:_,triggerRefresh:R}=wt({refreshOnMount:!0}),{serverCosts:I}=kt(ft(r)),[V,H]=c.useState(null),[T,M]=c.useState(null),[K,te]=c.useState(null),[y,b]=c.useState(!1),[C,u]=c.useState(!1),[g,m]=c.useState(!1),[N,F]=c.useState("all"),[$,G]=c.useState(""),W=c.useMemo(()=>er(r),[r]),{servers:Z,pagination:q}=c.useMemo(()=>tr(r,N,$,j,x),[r,N,$,j,x]);c.useEffect(()=>{q.page!==j&&P(q.page)},[q.page,j,P]);const z=c.useRef(0),L=async J=>{const ee=++z.current,A=await o(J);ee===z.current&&A&&H(A)},se=c.useRef(0),oe=async J=>{if(K===J.name)return;const ee=++se.current;te(J.name);try{const A=await o(J);if(xs(ee,se.current)==="stale")return;A&&M(A)}finally{xs(ee,se.current)==="commit"&&te(null)}},le=async()=>{b(!0);try{R(),await new Promise(J=>setTimeout(J,400))}finally{b(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("pages.servers.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:W.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:W.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:W.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>n("/market"),children:[e.jsx(ct,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>m(!0),children:[e.jsx(dt,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>u(!0),children:[e.jsx(ut,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:le,disabled:y,"aria-label":s("common.refresh"),children:[e.jsx(be,{size:13,className:y?"animate-spin":""}),s("common.refresh")]}),e.jsx(Ht,{onAdd:f,duplicateSource:T,onDuplicateCancel:()=>M(null)})]})]}),p&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ce,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:p})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>l(null),"aria-label":s("app.closeButton"),children:e.jsx(ze,{size:13})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-4 flex-wrap",children:[e.jsx("div",{className:"hub-card flex items-center",style:{padding:2,borderRadius:7,background:"var(--hub-surface)"},children:[["all",s("common.all")||"All",W.all],["online",s("status.online"),W.online],["issues",s("common.inactive")||"Issues",W.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",W.disabled]].map(([J,ee,A])=>e.jsxs("button",{onClick:()=>F(J),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:N===J?"var(--hub-bg-2)":"transparent",color:N===J?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(N===J?"var(--hub-line)":"transparent")},children:[ee,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:A})]},J))}),e.jsxs("div",{className:"hub-card flex items-center gap-2 px-2.5 flex-1",style:{height:30,background:"var(--hub-surface)",maxWidth:360},children:[e.jsx(mt,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:$,onChange:J=>G(J.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),$&&e.jsx("button",{onClick:()=>G(""),className:"hub-icon-btn sm",children:e.jsx(ze,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[q.total,"/",r.length]})]}),a&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(be,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):Z.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:e.jsx("p",{children:t.length===0?s("app.noServers"):s("market.noServers")})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col",children:Z.map(J=>e.jsx(Bt,{server:J,cost:I.find(ee=>ee.name===J.name),onRemove:h,onEdit:L,onDuplicate:oe,isDuplicating:K===J.name,onToggle:O,onVisibilityChange:v,onRefresh:R,onReload:k,onReinstall:D,onOAuthDisconnect:_},J.name))}),e.jsxs("div",{className:"flex items-center mt-4 text-[12px]",style:{color:"var(--hub-ink-3)"},children:[e.jsx("div",{className:"flex-[2]",children:s("common.showing",{start:(q.page-1)*q.limit+1,end:Math.min(q.page*q.limit,q.total),total:q.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:q.totalPages>1&&e.jsx(Nt,{currentPage:q.page,totalPages:q.totalPages,onPageChange:P,disabled:a})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s("common.itemsPerPage"),":"]}),e.jsxs("select",{id:"perPage",value:x,onChange:J=>d(Number(J.target.value)),disabled:a,className:"hub-input",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})]}),V&&e.jsx(Kt,{server:V,onEdit:()=>{H(null),R()},onCancel:()=>H(null)}),C&&e.jsx(Gt,{onSuccess:()=>{u(!1),R()},onCancel:()=>u(!1)}),g&&e.jsx(Qt,{onSuccess:()=>{m(!1),R()},onCancel:()=>m(!1)})]})};export{gr as default};
39
- //# sourceMappingURL=ServersPage-DHYwQ5AM.js.map
39
+ //# sourceMappingURL=ServersPage-DBcC8pG2.js.map