@samanhappy/mcphub 1.1.10 → 1.1.11

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