@samanhappy/mcphub 1.0.0 → 1.0.1

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 (116) hide show
  1. package/README.fr.md +6 -4
  2. package/README.md +24 -4
  3. package/README.zh.md +25 -4
  4. package/bin/cli.js +64 -50
  5. package/dist/cli/call-arguments.js +81 -0
  6. package/dist/cli/call-arguments.js.map +1 -0
  7. package/dist/cli/commands/call.js +75 -0
  8. package/dist/cli/commands/call.js.map +1 -0
  9. package/dist/cli/commands/config.js +132 -0
  10. package/dist/cli/commands/config.js.map +1 -0
  11. package/dist/cli/commands/discover.js +127 -0
  12. package/dist/cli/commands/discover.js.map +1 -0
  13. package/dist/cli/commands/export.js +20 -0
  14. package/dist/cli/commands/export.js.map +1 -0
  15. package/dist/cli/commands/groups.js +107 -0
  16. package/dist/cli/commands/groups.js.map +1 -0
  17. package/dist/cli/commands/install.js +173 -0
  18. package/dist/cli/commands/install.js.map +1 -0
  19. package/dist/cli/commands/keys.js +91 -0
  20. package/dist/cli/commands/keys.js.map +1 -0
  21. package/dist/cli/commands/login.js +70 -0
  22. package/dist/cli/commands/login.js.map +1 -0
  23. package/dist/cli/commands/servers.js +142 -0
  24. package/dist/cli/commands/servers.js.map +1 -0
  25. package/dist/cli/commands/tools.js +162 -0
  26. package/dist/cli/commands/tools.js.map +1 -0
  27. package/dist/cli/context.js +44 -0
  28. package/dist/cli/context.js.map +1 -0
  29. package/dist/cli/errors.js +19 -0
  30. package/dist/cli/errors.js.map +1 -0
  31. package/dist/cli/help.js +157 -0
  32. package/dist/cli/help.js.map +1 -0
  33. package/dist/cli/http.js +93 -0
  34. package/dist/cli/http.js.map +1 -0
  35. package/dist/cli/main.js +81 -0
  36. package/dist/cli/main.js.map +1 -0
  37. package/dist/cli/output.js +47 -0
  38. package/dist/cli/output.js.map +1 -0
  39. package/dist/cli/parse-args.js +103 -0
  40. package/dist/cli/parse-args.js.map +1 -0
  41. package/dist/cli/profile.js +109 -0
  42. package/dist/cli/profile.js.map +1 -0
  43. package/dist/cli/prompts.js +56 -0
  44. package/dist/cli/prompts.js.map +1 -0
  45. package/dist/controllers/oauthServerController.js +37 -1
  46. package/dist/controllers/oauthServerController.js.map +1 -1
  47. package/dist/dao/ServerDaoDbImpl.js +3 -0
  48. package/dist/dao/ServerDaoDbImpl.js.map +1 -1
  49. package/dist/db/connection.js +48 -4
  50. package/dist/db/connection.js.map +1 -1
  51. package/dist/db/entities/Server.js +4 -0
  52. package/dist/db/entities/Server.js.map +1 -1
  53. package/dist/db/entities/VectorEmbedding.js +2 -5
  54. package/dist/db/entities/VectorEmbedding.js.map +1 -1
  55. package/dist/db/repositories/VectorEmbeddingRepository.js +100 -34
  56. package/dist/db/repositories/VectorEmbeddingRepository.js.map +1 -1
  57. package/dist/services/dataService.js +10 -1
  58. package/dist/services/dataService.js.map +1 -1
  59. package/dist/services/mcpService.js +5 -0
  60. package/dist/services/mcpService.js.map +1 -1
  61. package/dist/services/vectorSearchService.js +16 -3
  62. package/dist/services/vectorSearchService.js.map +1 -1
  63. package/dist/utils/migration.js +1 -0
  64. package/dist/utils/migration.js.map +1 -1
  65. package/dist/utils/serverConfigPersistence.js +5 -0
  66. package/dist/utils/serverConfigPersistence.js.map +1 -1
  67. package/frontend/dist/assets/{ActivityPage-VwilVMvp.js → ActivityPage-DwzGiMh_.js} +2 -2
  68. package/frontend/dist/assets/{ActivityPage-VwilVMvp.js.map → ActivityPage-DwzGiMh_.js.map} +1 -1
  69. package/frontend/dist/assets/Dashboard-BUCJcvk-.js +2 -0
  70. package/frontend/dist/assets/Dashboard-BUCJcvk-.js.map +1 -0
  71. package/frontend/dist/assets/{EndpointCopy-C59moJ3Y.js → EndpointCopy-D5NjDdYi.js} +2 -2
  72. package/frontend/dist/assets/{EndpointCopy-C59moJ3Y.js.map → EndpointCopy-D5NjDdYi.js.map} +1 -1
  73. package/frontend/dist/assets/{GroupsPage-Bhg51kbu.js → GroupsPage-DfLlww4U.js} +2 -2
  74. package/frontend/dist/assets/{GroupsPage-Bhg51kbu.js.map → GroupsPage-DfLlww4U.js.map} +1 -1
  75. package/frontend/dist/assets/{LoginPage-C8RkMoJN.js → LoginPage-DCjqYw_8.js} +2 -2
  76. package/frontend/dist/assets/{LoginPage-C8RkMoJN.js.map → LoginPage-DCjqYw_8.js.map} +1 -1
  77. package/frontend/dist/assets/{LogsPage-HBGNLtyN.js → LogsPage-CTa8kuDf.js} +2 -2
  78. package/frontend/dist/assets/{LogsPage-HBGNLtyN.js.map → LogsPage-CTa8kuDf.js.map} +1 -1
  79. package/frontend/dist/assets/{MarketPage-C5ATZ4WS.js → MarketPage-C2Rh4WJB.js} +2 -2
  80. package/frontend/dist/assets/{MarketPage-C5ATZ4WS.js.map → MarketPage-C2Rh4WJB.js.map} +1 -1
  81. package/frontend/dist/assets/{PromptsPage-DUge8OO4.js → PromptsPage-Dh3qjX3x.js} +2 -2
  82. package/frontend/dist/assets/{PromptsPage-DUge8OO4.js.map → PromptsPage-Dh3qjX3x.js.map} +1 -1
  83. package/frontend/dist/assets/{ResourcesPage-5J3JYGVC.js → ResourcesPage-Bc5ZpCIh.js} +2 -2
  84. package/frontend/dist/assets/{ResourcesPage-5J3JYGVC.js.map → ResourcesPage-Bc5ZpCIh.js.map} +1 -1
  85. package/frontend/dist/assets/ServersPage-hgCbCglG.js +37 -0
  86. package/frontend/dist/assets/ServersPage-hgCbCglG.js.map +1 -0
  87. package/frontend/dist/assets/{SettingsPage-BeLZKC1d.js → SettingsPage-BzNX8mXv.js} +2 -2
  88. package/frontend/dist/assets/{SettingsPage-BeLZKC1d.js.map → SettingsPage-BzNX8mXv.js.map} +1 -1
  89. package/frontend/dist/assets/{StatusDot-DR803YdX.js → StatusDot-CQzailBQ.js} +2 -2
  90. package/frontend/dist/assets/{StatusDot-DR803YdX.js.map → StatusDot-CQzailBQ.js.map} +1 -1
  91. package/frontend/dist/assets/{ToggleGroup-DE8t8Ni4.js → ToggleGroup-CNBBvo3C.js} +2 -2
  92. package/frontend/dist/assets/{ToggleGroup-DE8t8Ni4.js.map → ToggleGroup-CNBBvo3C.js.map} +1 -1
  93. package/frontend/dist/assets/{UsersPage-CMscqAmn.js → UsersPage-C33b7LCM.js} +2 -2
  94. package/frontend/dist/assets/{UsersPage-CMscqAmn.js.map → UsersPage-C33b7LCM.js.map} +1 -1
  95. package/frontend/dist/assets/index-BGiKkKzj.js +3 -0
  96. package/frontend/dist/assets/index-BGiKkKzj.js.map +1 -0
  97. package/frontend/dist/assets/index-D0OIBhmN.css +1 -0
  98. package/frontend/dist/assets/{resourceService-BFMkDDIh.js → resourceService-C6umWRgq.js} +2 -2
  99. package/frontend/dist/assets/{resourceService-BFMkDDIh.js.map → resourceService-C6umWRgq.js.map} +1 -1
  100. package/frontend/dist/assets/{useServerData-BnLmpLAC.js → useServerData-P5In98R4.js} +2 -2
  101. package/frontend/dist/assets/{useServerData-BnLmpLAC.js.map → useServerData-P5In98R4.js.map} +1 -1
  102. package/frontend/dist/assets/useSettingsData-Cz7vKGLE.js +2 -0
  103. package/frontend/dist/assets/{useSettingsData-Cqi9d7Ug.js.map → useSettingsData-Cz7vKGLE.js.map} +1 -1
  104. package/frontend/dist/assets/{variableDetection-BigiltQM.js → variableDetection-DsYuiOB_.js} +3 -3
  105. package/frontend/dist/assets/variableDetection-DsYuiOB_.js.map +1 -0
  106. package/frontend/dist/index.html +2 -2
  107. package/package.json +2 -1
  108. package/frontend/dist/assets/Dashboard-DuBJTbbA.js +0 -2
  109. package/frontend/dist/assets/Dashboard-DuBJTbbA.js.map +0 -1
  110. package/frontend/dist/assets/ServersPage-DtnlfwJF.js +0 -37
  111. package/frontend/dist/assets/ServersPage-DtnlfwJF.js.map +0 -1
  112. package/frontend/dist/assets/index-B9cW2F0H.js +0 -3
  113. package/frontend/dist/assets/index-B9cW2F0H.js.map +0 -1
  114. package/frontend/dist/assets/index-Crcbkt8x.css +0 -1
  115. package/frontend/dist/assets/useSettingsData-Cqi9d7Ug.js +0 -2
  116. package/frontend/dist/assets/variableDetection-BigiltQM.js.map +0 -1
@@ -1,37 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-BFMkDDIh.js","./index-B9cW2F0H.js","./framework-vendor-BUhDPOUZ.js","./i18n-vendor-Kbr87Ofu.js","./icons-vendor-CKgJB3SC.js","./index-Crcbkt8x.css"])))=>i.map(i=>d[i]);
2
- import{r as m,j as e,b as He}from"./framework-vendor-BUhDPOUZ.js";import{e as ee,f as $e,h as be,i as we,_ as ge,j as Ge,k as Ke,l as Xe}from"./index-B9cW2F0H.js";import{S as Ze}from"./StatusDot-DR803YdX.js";import{u as ke}from"./useSettingsData-Cqi9d7Ug.js";import{S as Ce}from"./ToggleGroup-DE8t8Ni4.js";import{u as Q}from"./i18n-vendor-Kbr87Ofu.js";import{l as Ie,m as Fe,j as je,n as Qe,C as ce,o as fe,p as Se,q as Re,r as Oe,s as Ee,k as ye,X as ve,W as ze,f as Te,F as De,E as Ye,t as es,R as Ne,T as ss,P as ts,u as rs,v as ns,w as as}from"./icons-vendor-CKgJB3SC.js";import{D as os}from"./DeleteDialog-DRbWonMu.js";import{S as _e,d as ls}from"./variableDetection-BigiltQM.js";import{C as is}from"./ConfirmDialog-CxlizGia.js";import{P as cs}from"./Pagination-BFi-X7qY.js";import{u as ds}from"./useServerData-BnLmpLAC.js";const Ae=async(s,o)=>{try{const t=o?`/tools/${encodeURIComponent(o)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await ee(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},ms=async(s,o,t)=>{try{const r=await ee(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:o,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Je=async(s,o,t)=>{try{const r=await be(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:o,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Me=async(s,o)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:o,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},us=Object.freeze(Object.defineProperty({__proto__:null,callTool:Ae,resetToolDescription:Me,toggleTool:ms,updateToolDescription:Je},Symbol.toStringTag,{value:"Module"})),Ue=({schema:s,onSubmit:o,onCancel:t,loading:r=!1,storageKey:i,title:b})=>{const{t:n}=Q(),[p,T]=m.useState({}),[P,d]=m.useState({}),[j,I]=m.useState(!1),[y,$]=m.useState(""),[v,E]=m.useState(""),g=m.useMemo(()=>(c=>{const N=a=>{if(typeof a=="object"&&a!==null){const u=a;return{type:u.type||"string",description:u.description,enum:u.enum,default:u.default,properties:u.properties?Object.fromEntries(Object.entries(u.properties).map(([l,f])=>[l,N(f)])):void 0,required:u.required,items:u.items?N(u.items):void 0}}return{type:"string"}};return{type:c.type,properties:c.properties?Object.fromEntries(Object.entries(c.properties).map(([a,u])=>[a,N(u)])):void 0,required:c.required}})(s),[s]);m.useEffect(()=>{const h=(N,a="")=>{const u={};return N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([l,f])=>{const C=a?`${a}.${l}`:l;f.default!==void 0?u[l]=f.default:f.type==="string"?u[l]="":f.type==="number"||f.type==="integer"?u[l]=0:f.type==="boolean"?u[l]=!1:f.type==="array"?u[l]=[]:f.type==="object"&&(f.properties?u[l]=h(f,C):u[l]={})}),u};let c=h(g);if(i)try{const N=localStorage.getItem(i);if(N){const a=JSON.parse(N);c={...c,...a}}}catch(N){console.warn("Failed to load saved form data:",N)}T(c)},[g,i]),m.useEffect(()=>{j&&Object.keys(p).length>0&&($(JSON.stringify(p,null,2)),E(""))},[j,p]);const O=h=>{$(h),E("");try{const c=JSON.parse(h);if(T(c),i)try{localStorage.setItem(i,JSON.stringify(c))}catch(N){console.warn("Failed to save form data to localStorage:",N)}}catch{E(n("tool.invalidJsonFormat"))}},R=()=>{$(JSON.stringify(p,null,2)),E(""),I(!0)},z=()=>{if(y.trim())try{const h=JSON.parse(y);T(h),E(""),I(!1)}catch{E(n("tool.fixJsonBeforeSwitching"));return}else I(!1)},A=(h,c)=>{T(N=>{const a={...N},u=h.split(".");let l=a;for(let f=0;f<u.length-1;f++)l[u[f]]||(l[u[f]]={}),l=l[u[f]];if(l[u[u.length-1]]=c,i)try{localStorage.setItem(i,JSON.stringify(a))}catch(f){console.warn("Failed to save form data to localStorage:",f)}return a}),P[h]&&d(N=>{const a={...N};return delete a[h],a})},W=()=>{const h={},c=(N,a,u="")=>{N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([l,f])=>{var V;const C=u?`${u}.${l}`:l,D=a==null?void 0:a[l];if((V=N.required)!=null&&V.includes(l)&&(D==null||D===""||Array.isArray(D)&&D.length===0)){h[C]=`${l} is required`;return}D!=null&&D!==""&&(f.type==="string"&&typeof D!="string"?h[C]=`${l} must be a string`:f.type==="number"&&typeof D!="number"?h[C]=`${l} must be a number`:f.type==="integer"&&(!Number.isInteger(D)||typeof D!="number")?h[C]=`${l} must be an integer`:f.type==="boolean"&&typeof D!="boolean"?h[C]=`${l} must be a boolean`:f.type==="array"&&Array.isArray(D)?f.items&&D.forEach((k,J)=>{var S;((S=f.items)==null?void 0:S.type)==="object"&&f.items.properties&&c(f.items,k,`${C}.${J}`)}):f.type==="object"&&typeof D=="object"&&c(f,D,C))})};return c(g,p),d(h),Object.keys(h).length===0},B=h=>{h.preventDefault(),W()&&o(p)},q=(h,c)=>c.split(".").reduce((N,a)=>N==null?void 0:N[a],h),K=(h,c,N,a)=>{const u=N==null?void 0:N[h];return c.type==="string"?c.enum?e.jsxs("select",{value:u||"",onChange:l=>a(l.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:n("tool.selectOption")}),c.enum.map((l,f)=>e.jsx("option",{value:l,children:l},f))]}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.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:c.description||n("tool.enterKey",{key:h})}):c.type==="number"||c.type==="integer"?e.jsx("input",{type:"number",step:c.type==="integer"?"1":"any",value:u??"",onChange:l=>{const f=l.target.value===""?"":c.type==="integer"?parseInt(l.target.value):parseFloat(l.target.value);a(f)},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"}):c.type==="boolean"?e.jsx("input",{type:"checkbox",checked:u||!1,onChange:l=>a(l.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.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:c.description||n("tool.enterKey",{key:h})})},M=(h,c,N="")=>{var f,C,D,V,k,J,S,U,se,te,de,me,ue,pe;const a=N?`${N}.${h}`:h,u=q(p,a),l=P[a];if(c.type==="array"){const _=q(p,a)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?(C=(f=q(g,N))==null?void 0:f.required)==null?void 0:C.includes(h):(D=g.required)==null?void 0:D.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.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:[_.map((H,X)=>{var ne,ae,oe;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:n("tool.item",{index:X+1})}),e.jsx("button",{type:"button",onClick:()=>{const L=[..._];L.splice(X,1),A(a,L)},className:"text-status-red hover:text-red-700 text-sm",children:n("common.remove")})]}),((ne=c.items)==null?void 0:ne.type)==="string"&&c.items.enum?e.jsxs("select",{value:H||"",onChange:L=>{const Z=[..._];Z[X]=L.target.value,A(a,Z)},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:n("tool.selectOption")}),c.items.enum.map((L,Z)=>e.jsx("option",{value:L,children:L},Z))]}):((ae=c.items)==null?void 0:ae.type)==="object"&&c.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(c.items.properties).map(([L,Z])=>{var le,ie;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[L,((ie=(le=c.items)==null?void 0:le.required)==null?void 0:ie.includes(L))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(L,Z,H,xe=>{const x=[..._];x[X]={...x[X],[L]:xe},A(a,x)})]},L)})}):e.jsx("input",{type:"text",value:H||"",onChange:L=>{const Z=[..._];Z[X]=L.target.value,A(a,Z)},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:n("tool.enterValue",{type:((oe=c.items)==null?void 0:oe.type)||"value"})})]},X)}),e.jsx("button",{type:"button",onClick:()=>{var X;const H=((X=c.items)==null?void 0:X.type)==="object"?{}:"";A(a,[..._,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:n("tool.addItem",{key:h})})]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a)}return c.type==="object"?c.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?(k=(V=q(g,N))==null?void 0:V.required)==null?void 0:k.includes(h):(J=g.required)==null?void 0:J.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.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(c.properties).map(([_,H])=>M(_,H,a))}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?(U=(S=q(g,N))==null?void 0:S.required)==null?void 0:U.includes(h):(se=g.required)==null?void 0:se.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("textarea",{value:typeof u=="object"?JSON.stringify(u,null,2):u||"{}",onChange:_=>{try{const H=JSON.parse(_.target.value);A(a,H)}catch{A(a,_.target.value)}},placeholder:`{
3
- "key": "value"
4
- }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="string"?c.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?!1:(te=g.required)==null?void 0:te.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsxs("select",{value:u||"",onChange:_=>A(a,_.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:n("tool.selectOption")}),c.enum.map((_,H)=>e.jsx("option",{value:_,children:_},H))]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?!1:(de=g.required)==null?void 0:de.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"text",value:u||"",onChange:_=>A(a,_.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red":"border-gray-200"} focus:outline-none form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="number"||c.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?!1:(me=g.required)==null?void 0:me.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"number",step:c.type==="integer"?"1":"any",value:u??"",onChange:_=>{const H=_.target.value===""?"":c.type==="integer"?parseInt(_.target.value):parseFloat(_.target.value);A(a,H)},className:`w-full border rounded-md px-3 py-2 form-input ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:u||!1,onChange:_=>A(a,_.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[h,(N?!1:(ue=g.required)==null?void 0:ue.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:c.description}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(N?!1:(pe=g.required)==null?void 0:pe.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",c.type,")"]})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"text",value:u||"",onChange:_=>A(a,_.target.value),placeholder:n("tool.enterValue",{type:c.type}),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a)};return g.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:b}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:z,className:`hub-btn sm ${j?"":"primary"}`,children:n("tool.formMode")}),e.jsx("button",{type:"button",onClick:R,className:`hub-btn sm ${j?"primary":""}`,children:n("tool.jsonMode")})]})]}),j?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:n("tool.jsonConfiguration")}),e.jsx("textarea",{value:y,onChange:h=>O(h.target.value),placeholder:`{
5
- "key": "value"
6
- }`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${v?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),v&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:v})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:n("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const h=JSON.parse(y);o(h)}catch{E(n("tool.invalidJsonFormat"))}},disabled:r||!!v,className:"hub-btn sm primary",children:n(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[Object.entries(g.properties||{}).map(([h,c])=>M(h,c)),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:n("tool.cancel")}),e.jsx("button",{type:"submit",disabled:r,className:"hub-btn sm primary",children:n(r?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:n("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:n("tool.cancel")}),e.jsx("button",{onClick:()=>o({}),disabled:r,className:"hub-btn primary",children:n(r?"tool.running":"tool.runTool")})]})]})},ps=({result:s,onClose:o})=>{const{t}=Q(),r=s.content,i=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",b=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(y=>b(y));if(typeof d!="object")return[];const j=[];d.type==="image"&&d.data&&j.push({data:String(d.data),mimeType:i(d.mimeType||d.mime_type)});const I=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return I&&j.push({data:String(I),mimeType:i(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&j.push(...b(d.image)),Array.isArray(d.images)&&j.push(...b(d.images)),Array.isArray(d.content)&&j.push(...b(d.content)),j},n=d=>{const j=[];try{const $=JSON.parse(d);if(j.push(...b($)),j.length>0)return j}catch{}const I=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let y;for(;(y=I.exec(d))!==null;){const $=`image/${y[1]==="jpg"?"jpeg":y[1]}`;j.push({data:y[2],mimeType:$})}return j},p=d=>{try{const j=JSON.parse(d),I=y=>{if(Array.isArray(y))return y.map(I);if(y&&typeof y=="object"){const $={};for(const[v,E]of Object.entries(y))typeof E=="string"&&v.toLowerCase().includes("base64")?$[v]="[base64 omitted]":$[v]=I(E);return $}return y};return JSON.stringify(I(j),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},T=d=>Array.isArray(d)?d.map((j,I)=>e.jsx("div",{className:"mb-3 last:mb-0",children:P(j)},I)):P(d),P=d=>{if(typeof d=="string"){const j=n(d),I=p(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[j.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:j.map((y,$)=>e.jsx("img",{src:`data:${y.mimeType||"image/png"};base64,${y.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:I})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const j=n(d.text),I=p(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[j.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:j.map((y,$)=>e.jsx("img",{src:`data:${y.mimeType||"image/png"};base64,${y.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:I})]})}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 j=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(j,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(Ie,{size:20,className:"text-status-green"}):e.jsx(Fe,{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:o,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")}),T(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(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),T(r)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},re=({title:s,onClick:o,disabled:t=!1,loading:r=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:o,disabled:t,title:s,"aria-label":s,children:e.jsx(Qe,{size:14,className:r?"animate-spin":""})});function xs(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 hs=({tool:s,server:o,onToggle:t,onDescriptionUpdate:r})=>{const{t:i}=Q(),{showToast:b}=we(),{nameSeparator:n}=ke(),[p,T]=m.useState(!1),[P,d]=m.useState(!1),[j,I]=m.useState(!1),[y,$]=m.useState(null),[v,E]=m.useState(!1),[g,O]=m.useState(!1),[R,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,q]=m.useState(0),[K,M]=m.useState(!1);m.useEffect(()=>{v&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[v,B]),m.useEffect(()=>{!v&&W.current&&q(W.current.offsetWidth)},[v,R]),m.useEffect(()=>{z(s.description||"")},[s.description]);const h=m.useCallback(()=>`mcphub_tool_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),c=m.useCallback(()=>{localStorage.removeItem(h())},[h]),N=S=>{t&&t(s.name,S)},a=()=>{E(!0)},u=async()=>{try{const S=await Je(o,s.name,R);S.success?(E(!1),r&&r(s.name,R)):(z(s.description||""),console.error("Failed to update tool description:",S.error))}catch(S){console.error("Error updating tool description:",S),z(s.description||""),E(!1)}},l=S=>{z(S.target.value)},f=async()=>{O(!0);try{const S=await Me(o,s.name);if(S.success){const U=S.description||"";z(U),E(!1),r==null||r(s.name,U,{restored:!0})}else b(S.error||i("tool.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting tool description:",S),b(i("tool.restoreDefaultFailed"),"error")}finally{O(!1)}},C=S=>{S.key==="Enter"?u():S.key==="Escape"&&(z(s.description||""),E(!1))},D=async S=>{S.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),M(!0),b(i("common.copySuccess"),"success"),setTimeout(()=>M(!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"),M(!0),b(i("common.copySuccess"),"success"),setTimeout(()=>M(!1),2e3)}catch(se){b(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",se)}document.body.removeChild(U)}}catch(U){b(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},V=async S=>{I(!0);try{S=Object.fromEntries(Object.entries(S).filter(([se,te])=>!xs(te)));const U=await Ae({toolName:s.name,arguments:S},o);$(U)}catch(U){$({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{I(!1)}},k=()=>{d(!1),c(),$(null)},J=()=>{$(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:S=>{S.stopPropagation(),T(!p)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+n,"")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:D,title:i("common.copy"),children:K?e.jsx(ce,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(fe,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:v?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:R,onChange:l,onKeyDown:C,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),u()},disabled:g,children:e.jsx(ce,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(re,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),f()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:R||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),a()},children:e.jsx(Se,{size:12})}),e.jsx(re,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),f()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:S=>S.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled??!0,onCheckedChange:N,disabled:j})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(Re,{size:12,className:"animate-spin"}):e.jsx(Oe,{size:12}),e.jsx("span",{children:i(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:p?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),p&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[!P&&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:i("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)})]}),P&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ue,{schema:s.inputSchema||{type:"object"},onSubmit:V,onCancel:k,loading:j,storageKey:h(),title:i("tool.runToolWithName",{name:s.name.replace(o+n,"")})}),y&&e.jsx("div",{style:{marginTop:12},children:e.jsx(ps,{result:y,onClose:J})})]})]})]})},gs=async(s,o)=>{try{const t=o?`/prompts/call/${o}`:"/prompts/call",r=await ee(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Be=async(s,o)=>{try{const t=await ee(`/mcp/${encodeURIComponent(o||"")}/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:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},fs=async(s,o,t)=>{try{const r=await ee(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:o,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ve=async(s,o,t)=>{try{const r=await be(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:o,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},We=async(s,o)=>{var t;try{const r=await $e(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:o,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},bs=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:gs,getPrompt:Be,resetPromptDescription:We,togglePrompt:fs,updatePromptDescription:Ve},Symbol.toStringTag,{value:"Module"})),Pe=({result:s,onClose:o})=>{const{t}=Q(),r=i=>{if(typeof i=="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:i})});if(typeof i=="object"&&i!==null){if(i.description||i.messages)return e.jsxs("div",{className:"space-y-4",children:[i.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:i.description})})]}),i.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:i.messages.map((b,n)=>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:[b.role,":"]})}),typeof b.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:b.content}):typeof b.content=="object"&&b.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:b.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(b.content,null,2)})]},n))})]})]});try{const b=typeof i=="string"?JSON.parse(i):i;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(b,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(i)})})}}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(i)})})};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(Ie,{size:20,className:"text-status-green"}):e.jsx(Fe,{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:o,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),r(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},js=({prompt:s,server:o,onToggle:t,onDescriptionUpdate:r})=>{const{t:i}=Q(),{showToast:b}=we(),{nameSeparator:n}=ke(),[p,T]=m.useState(!1),[P,d]=m.useState(!1),[j,I]=m.useState(!1),[y,$]=m.useState(null),[v,E]=m.useState(!1),[g,O]=m.useState(!1),[R,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,q]=m.useState(0);m.useEffect(()=>{v&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[v,B]),m.useEffect(()=>{!v&&W.current&&q(W.current.offsetWidth)},[v,R]),m.useEffect(()=>{z(s.description||"")},[s.description]);const K=m.useCallback(()=>`mcphub_prompt_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),M=m.useCallback(()=>{localStorage.removeItem(K())},[K]),h=k=>{t&&t(s.name,k)},c=()=>{E(!0)},N=async()=>{E(!1);try{const k=await Ve(o,s.name,R);k.success?r&&r(s.name,R):(b(k.error||i("prompt.descriptionUpdateFailed"),"error"),z(s.description||""))}catch(k){console.error("Error updating prompt description:",k),b(i("prompt.descriptionUpdateFailed"),"error"),z(s.description||"")}},a=async()=>{O(!0);try{const k=await We(o,s.name);if(k.success){const J=k.description||"";z(J),E(!1),r==null||r(s.name,J,{restored:!0})}else b(k.error||i("prompt.restoreDefaultFailed"),"error")}catch(k){console.error("Error resetting prompt description:",k),b(i("prompt.restoreDefaultFailed"),"error")}finally{O(!1)}},u=k=>{z(k.target.value)},l=k=>{k.key==="Enter"?N():k.key==="Escape"&&(z(s.description||""),E(!1))},f=async k=>{I(!0);try{const J=await Be({promptName:s.name,arguments:k},o);console.log("GetPrompt result:",J),$({success:J.success,data:J.data,error:J.error})}catch(J){$({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{I(!1)}},C=()=>{d(!1),M(),$(null)},D=()=>{$(null)},V=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const k={},J=[];return s.arguments.forEach(S=>{k[S.name]={type:"string",description:S.description||""},S.required&&J.push(S.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:()=>T(!p),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+n,"")}),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:v?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:R,onChange:u,onKeyDown:l,onClick:k=>k.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:k=>{k.stopPropagation(),N()},disabled:g,children:e.jsx(ce,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(re,{title:i("prompt.restoreDefault"),onClick:k=>{k.stopPropagation(),a()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:R||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:k=>{k.stopPropagation(),c()},children:e.jsx(Se,{size:12})}),e.jsx(re,{title:i("prompt.restoreDefault"),onClick:k=>{k.stopPropagation(),a()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:k=>k.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ce,{checked:s.enabled,onCheckedChange:h,disabled:j})}),e.jsxs("button",{onClick:k=>{k.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(Re,{size:12,className:"animate-spin"}):e.jsx(Oe,{size:12}),e.jsx("span",{children:i(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:p?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),p&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[P&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Ue,{schema:V(),onSubmit:f,onCancel:C,loading:j,storageKey:K(),title:i("prompt.runPromptWithName",{name:s.name.replace(o+n,"")})}),y&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Pe,{result:y,onClose:D})})]}),!P&&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:i("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))})]}),!P&&y&&e.jsx("div",{children:e.jsx(Pe,{result:y,onClose:D})})]})]})},ys=({resource:s,onToggle:o,onDescriptionUpdate:t})=>{const{t:r}=Q(),[i,b]=m.useState(!1),[n,p]=m.useState(!1),[T,P]=m.useState(!1),[d,j]=m.useState(s.description||""),I=m.useRef(null),y=m.useRef(null),[$,v]=m.useState(0);m.useEffect(()=>{n&&I.current&&(I.current.focus(),$>0&&(I.current.style.width=`${$+20}px`))},[n,$]),m.useEffect(()=>{!n&&y.current&&v(y.current.offsetWidth)},[n,d]),m.useEffect(()=>{j(s.description||"")},[s.description]);const E=z=>{o&&o(s.uri,z)},g=async()=>{p(!1),t&&await t(s.uri,d)},O=async()=>{P(!0);try{await(t==null?void 0:t(s.uri,"",{restored:!0})),p(!1)}finally{P(!1)}},R=z=>{z.key==="Enter"?g():z.key==="Escape"&&(j(s.description||""),p(!1))};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>b(!i),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:s.name||s.uri}),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:n?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:$>0?`${$+20}px`:160,minWidth:80},value:d,onChange:z=>j(z.target.value),onKeyDown:R,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),g()},disabled:T,children:e.jsx(ce,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(re,{title:r("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:y,children:d||r("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),p(!0)},children:e.jsx(Se,{size:12})}),e.jsx(re,{title:r("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:z=>z.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled!==!1,onCheckedChange:E})}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[r("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},vs=(s,o)=>o?o==="stdio"?s("server.typeStdio")||"stdio":o==="sse"?s("server.typeSse")||"sse":o==="streamable-http"?s("server.typeStreamableHttp")||"http":o==="openapi"?s("server.typeOpenapi")||"openapi":o:null,Ns=({server:s,onRemove:o,onEdit:t,onToggle:r,onRefresh:i,onReload:b})=>{var X,ne,ae,oe,L,Z,le,ie,xe;const{t:n}=Q(),{showToast:p}=we(),{exportMCPSettings:T,installConfig:P}=ke(),d=((X=P==null?void 0:P.baseUrl)==null?void 0:X.replace(/\/+$/,""))||"",[j,I]=m.useState(!1),[y,$]=m.useState(null),[v,E]=m.useState(!1),[g,O]=m.useState(!1),[R,z]=m.useState(!1),[A,W]=m.useState(!1),[B,q]=m.useState(!1),[K,M]=m.useState(!1),h=m.useRef(null),c=m.useRef(null);m.useEffect(()=>{const x=w=>{h.current&&!h.current.contains(w.target)&&W(!1),c.current&&!c.current.contains(w.target)&&q(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const N=((ne=s.tools)==null?void 0:ne.length)||0,a=((ae=s.tools)==null?void 0:ae.filter(x=>x.enabled!==!1).length)||0,u=((oe=s.prompts)==null?void 0:oe.length)||0,l=((L=s.prompts)==null?void 0:L.filter(x=>x.enabled!==!1).length)||0,f=((Z=s.resources)==null?void 0:Z.length)||0,C=((le=s.resources)==null?void 0:le.filter(x=>x.enabled!==!1).length)||0,D=async x=>{if(x.stopPropagation(),!(g||!r)){O(!0);try{await r(s,s.enabled===!1)}finally{O(!1)}}},V=async x=>{if(x.stopPropagation(),W(!1),!(R||!b)){z(!0);try{await b(s)?p(n("server.reloadSuccess")||"Server reloaded successfully","success"):p(n("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{z(!1)}}},k=async x=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(x),!0}catch{}try{const w=document.createElement("textarea");w.value=x,w.style.position="fixed",w.style.left="-9999px",document.body.appendChild(w),w.focus(),w.select();const F=document.execCommand("copy");return document.body.removeChild(w),F}catch{return!1}},J=async x=>{if(x.stopPropagation(),!s.error)return;await k(s.error)?(M(!0),p(n("common.copySuccess")||"Copied","success"),setTimeout(()=>M(!1),1500)):p(n("common.copyFailed")||"Copy failed","error")},S=async x=>{x.stopPropagation(),W(!1);try{const w=await T(s.name);if(!w||!w.success||!w.data){p((w==null?void 0:w.message)||n("common.copyFailed")||"Copy failed","error");return}const F=JSON.stringify(w.data,null,2),G=await k(F);p(G?n("common.copySuccess")||"Copied":n("common.copyFailed")||"Copy failed",G?"success":"error")}catch(w){console.error("Error copying server configuration:",w),p(n("common.copyFailed")||"Copy failed","error")}},U=x=>{var w;if(x.stopPropagation(),(w=s.oauth)!=null&&w.authorizationUrl){const Y=window.screen.width/2-300,he=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${Y},top=${he}`),p(n("status.oauthWindowOpened"),"info")}},se=async(x,w)=>{try{const{toggleTool:F}=await ge(async()=>{const{toggleTool:Y}=await Promise.resolve().then(()=>us);return{toggleTool:Y}},void 0,import.meta.url),G=await F(s.name,x,w);G.success?(p(n(w?"tool.enableSuccess":"tool.disableSuccess",{name:x}),"success"),i==null||i()):p(G.error||n("tool.toggleFailed"),"error")}catch(F){console.error(F),p(n("tool.toggleFailed"),"error")}},te=async(x,w)=>{try{const{togglePrompt:F}=await ge(async()=>{const{togglePrompt:Y}=await Promise.resolve().then(()=>bs);return{togglePrompt:Y}},void 0,import.meta.url),G=await F(s.name,x,w);G.success?(p(n(w?"tool.enableSuccess":"tool.disableSuccess",{name:x}),"success"),i==null||i()):p(G.error||n("tool.toggleFailed"),"error")}catch(F){console.error(F),p(n("tool.toggleFailed"),"error")}},de=async(x,w)=>{try{const{toggleResource:F}=await ge(async()=>{const{toggleResource:Y}=await import("./resourceService-BFMkDDIh.js");return{toggleResource:Y}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),G=await F(s.name,x,w);G.success?(p(n(w?"tool.enableSuccess":"tool.disableSuccess",{name:x}),"success"),i==null||i()):p(G.error||n("tool.toggleFailed"),"error")}catch(F){console.error(F),p(n("tool.toggleFailed"),"error")}},me=(x,w,F)=>{p(F!=null&&F.restored?n("tool.restoreDefaultSuccess"):n("tool.descriptionUpdateSuccess"),"success"),i==null||i()},ue=(x,w,F)=>{p(F!=null&&F.restored?n("prompt.restoreDefaultSuccess"):n("prompt.descriptionUpdateSuccess"),"success"),i==null||i()},pe=async(x,w,F)=>{try{const{updateResourceDescription:G,resetResourceDescription:Y}=await ge(async()=>{const{updateResourceDescription:Le,resetResourceDescription:qe}=await import("./resourceService-BFMkDDIh.js");return{updateResourceDescription:Le,resetResourceDescription:qe}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),he=F!=null&&F.restored?await Y(s.name,x):await G(s.name,x,w);he.success?(p(F!=null&&F.restored?n("builtinResources.restoreDefaultSuccess"):n("builtinResources.descriptionUpdateSuccess"),"success"),i==null||i()):p(he.error||(F!=null&&F.restored?n("builtinResources.restoreDefaultFailed"):n("builtinResources.descriptionUpdateFailed")),"error")}catch(G){console.error(G),p(F!=null&&F.restored?n("builtinResources.restoreDefaultFailed"):n("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var F;const x=s.config;if(!x)return"";if(x.url)return x.url;const w=[];return x.command&&w.push(x.command),(F=x.args)!=null&&F.length&&w.push(...x.args),w.join(" ")})();const _=s.enabled!==!1,H=`${d}/mcp/${s.name}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10,opacity:_?1:.7},children:[e.jsxs("div",{className:"grid items-center gap-3 px-4 py-3 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",style:{gridTemplateColumns:"minmax(220px,1.6fr) 130px 90px 140px 80px 36px"},onClick:()=>I(!j),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ye,{size:12,style:{color:"var(--hub-ink-3)",transform:j?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"hub-mono truncate",style:{fontSize:13.5,color:_?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),s.error&&e.jsxs("div",{className:"relative",ref:c,children:[e.jsx("button",{onClick:x=>{x.stopPropagation(),q(w=>!w)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":n("server.viewErrorDetails"),children:e.jsx(je,{size:14})}),B&&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:x=>x.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:n("server.errorDetails")}),e.jsx("button",{onClick:J,className:"hub-icon-btn sm",title:n("common.copy"),children:K?e.jsx(ce,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(fe,{size:12})})]}),e.jsx("button",{onClick:()=>q(!1),className:"hub-icon-btn sm","aria-label":n("app.closeButton"),children:e.jsx(ve,{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})})]})]})]}),((ie=s.config)==null?void 0:ie.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",{children:e.jsx(Ze,{status:s.status,enabled:s.enabled,onAuthClick:U})}),e.jsx("div",{children:(xe=s.config)!=null&&xe.type?e.jsx("span",{className:"hub-tag",children:vs(n,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsxs("div",{className:"flex items-center gap-2.5 hub-num hub-mono",style:{color:"var(--hub-ink-2)",fontSize:12},title:`T:${a}/${N} · P:${l}/${u} · R:${C}/${f}`,children:[e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(ze,{size:11,style:{color:"var(--hub-ink-3)",flexShrink:0}}),e.jsx("span",{children:N===0?"0":`${a}/${N}`})]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(Te,{size:11,style:{color:"var(--hub-ink-3)",flexShrink:0}}),e.jsx("span",{children:u===0?"0":`${l}/${u}`})]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(De,{size:11,style:{color:"var(--hub-ink-3)",flexShrink:0}}),e.jsx("span",{children:f===0?"0":`${C}/${f}`})]})]}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{type:"button",className:"hub-switch"+(_?" on":""),onClick:D,disabled:g,"aria-label":n(_?"server.disable":"server.enable")})}),e.jsxs("div",{className:"relative",ref:h,children:[e.jsx("button",{className:"hub-icon-btn",onClick:x=>{x.stopPropagation(),W(w=>!w)},"aria-label":"More",children:e.jsx(Ye,{size:14})}),A&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:x=>x.stopPropagation(),children:[e.jsxs("button",{onClick:x=>{x.stopPropagation(),W(!1),t(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(es,{size:13})," ",n("server.edit")]}),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(fe,{size:13})," ",n("server.copy")]}),b&&e.jsxs("button",{onClick:V,disabled:R||g||!_,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(Ne,{size:13})," ",n("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:x=>{x.stopPropagation(),W(!1),E(!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(ss,{size:13})," ",n("server.delete")]})]})]})]}),j&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[[{key:"tools",icon:e.jsx(ze,{size:12}),label:n("server.tools"),count:N,enabled:a},{key:"prompts",icon:e.jsx(Te,{size:12}),label:n("server.prompts"),count:u,enabled:l},{key:"resources",icon:e.jsx(De,{size:12}),label:n("nav.resources"),count:f,enabled:C}].map(x=>{const w=y===x.key;return e.jsxs("button",{onClick:()=>$(w?null:x.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:w?"var(--hub-surface)":"transparent",border:"1px solid "+(w?"var(--hub-line)":"transparent"),color:w?"var(--hub-ink)":"var(--hub-ink-2)"},children:[x.icon,e.jsx("span",{children:x.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:x.count===0?"0":`${x.enabled}/${x.count}`})]},x.key)}),e.jsx("div",{className:"ml-auto flex-shrink-0",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:H,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async x=>{x.stopPropagation();const w=await k(H);p(w?n("common.copySuccess")||"Copied":n("common.copyFailed")||"Failed",w?"success":"error")},title:n("common.copy"),children:e.jsx(fe,{size:12})})]})})]}),y==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((x,w)=>e.jsx(hs,{server:s.name,tool:x,onToggle:se,onDescriptionUpdate:me},w))}),y==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((x,w)=>e.jsx(js,{server:s.name,prompt:x,onToggle:te,onDescriptionUpdate:ue},w))}),y==="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:n("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((x,w)=>e.jsx(ys,{resource:x,onToggle:de,onDescriptionUpdate:pe},`${x.uri}-${w}`))})})]})]}),e.jsx(os,{isOpen:v,onClose:()=>E(!1),onConfirm:()=>{o(s.name),E(!1)},serverName:s.name})]})},ws=({onAdd:s})=>{const{t:o}=Q(),[t,r]=m.useState(!1),[i,b]=m.useState(null),[n,p]=m.useState(!1),[T,P]=m.useState(null),[d,j]=m.useState([]),I=()=>{r(!t),b(null),p(!1),P(null)},y=async()=>{T&&(await $(T),p(!1),P(null))},$=async E=>{try{b(null);const g=await ee("/servers",E);if(!g.success){g&&g.message?b(g.message):b(o("server.addError"));return}r(!1),s()}catch(g){console.error("Error adding server:",g),navigator.onLine?g instanceof TypeError&&(g.message.includes("NetworkError")||g.message.includes("Failed to fetch"))?b(o("errors.serverConnection")):b(o("errors.serverAdd")):b(o("errors.network"))}},v=async E=>{try{const g=ls(E);g.length>0?(j(g),P(E),p(!0)):await $(E)}catch(g){console.error("Error processing server submission:",g),b(o("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:I,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"})}),o("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(_e,{onSubmit:v,onCancel:I,modalTitle:o("server.addServer"),formError:i})}),n&&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:o("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:o("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[o("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:d.map((E,g)=>e.jsxs("li",{className:"font-mono",children:["$",`{${E}}`]},g))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:o("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{p(!1),P(null)},className:"hub-btn",children:o("common.cancel")}),e.jsx("button",{onClick:y,className:"hub-btn primary",children:o("server.confirmAndAdd")})]})]})})]})},ks=({server:s,onEdit:o,onCancel:t})=>{const{t:r}=Q(),[i,b]=m.useState(null),n=async p=>{try{b(null);const T=encodeURIComponent(s.name),P=p.name&&p.name!==s.name,d={config:p.config,...P?{newName:p.name}:{}},j=await be(`/servers/${T}`,d);if(!j.success){j&&j.message?b(j.message):b(r("server.updateError",{serverName:s.name}));return}o()}catch(T){console.error("Error updating server:",T),navigator.onLine?T instanceof TypeError&&(T.message.includes("NetworkError")||T.message.includes("Failed to fetch"))?b(r("errors.serverConnection")):b(r("errors.serverUpdate",{serverName:s.name})):b(r("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(_e,{onSubmit:n,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:i})})},Cs=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[r,i]=m.useState(!1),[b,n]=m.useState(!1),[p,T]=m.useState(null),[P,d]=m.useState(null),[j,I]=m.useState(!1),[y,$]=m.useState(null),[v,E]=m.useState(""),[g,O]=m.useState(!1),[R,z]=m.useState(""),A=a=>{a.preventDefault(),i(!0)},W=a=>{a.preventDefault(),i(!1)},B=a=>{a.preventDefault(),i(!1);const u=a.dataTransfer.files;if(u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},q=a=>{const u=a.target.files;if(u&&u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},K=async()=>{if(!P){T(t("mcpb.noFileSelected"));return}n(!0),T(null);try{const a=new FormData;a.append("mcpbFile",P);const u=await Ke(Xe("/mcpb/upload"),{method:"POST",body:a}),l=await u.json();if(!u.ok)throw new Error(l.message||`HTTP error! Status: ${u.status}`);if(l.success&&l.data)$(l.data.manifest),E(l.data.extractDir),I(!0);else throw new Error(l.message||t("mcpb.uploadFailed"))}catch(a){console.error("MCPB upload error:",a),T(a instanceof Error?a.message:t("mcpb.uploadFailed"))}finally{n(!1)}},M=async(a,u=!1)=>{var l;n(!0),T(null);try{const f=N(y,v,a);if(!u){const D=await Ge("/servers");if(D.success&&((l=D.data)==null?void 0:l.find(k=>k.name===a))){z(a),O(!0),n(!1);return}}let C;if(u?C=await be(`/servers/${encodeURIComponent(a)}`,{name:a,config:f}):C=await ee("/servers",{name:a,config:f}),C.success)s(f);else throw new Error(C.message||t("mcpb.installFailed"))}catch(f){console.error("MCPB install error:",f),T(f instanceof Error?f.message:t("mcpb.installFailed")),n(!1)}},h=()=>{O(!1),R&&M(R,!0)},c=()=>{O(!1),z(""),n(!1)},N=(a,u,l)=>{var D;const f=((D=a.server)==null?void 0:D.mcp_config)||{},C={type:"stdio",command:f.command||"node",args:(f.args||[]).map(V=>V.replace("${__dirname}",u))};return f.env&&Object.keys(f.env).length>0&&(C.env={...f.env},Object.keys(C.env).forEach(V=>{typeof C.env[V]=="string"&&(C.env[V]=C.env[V].replace("${__dirname}",u))})),C};return j&&y?e.jsxs(e.Fragment,{children:[e.jsx(is,{isOpen:g,onClose:c,onConfirm:h,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:R}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${g?"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:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),p&&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",children:p})}),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"),":"]})," ",y.display_name||y.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",y.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",y.description]}),y.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",y.author.name]}),y.tools&&y.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:y.tools.map((a,u)=>e.jsxs("li",{children:[a.name," - ",a.description]},u))})]})]})]}),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:y.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:o,disabled:b,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const a=document.getElementById("serverName"),u=(a==null?void 0:a.value.trim())||y.name;M(u)},disabled:b,className:"hub-btn primary",children:b?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:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),p&&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",children:p})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${r?"border-blue-500 bg-blue-50":P?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:A,onDragLeave:W,onDrop:B,children:[P?e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-green-200",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm text-gray-900 font-medium",children:P.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(P.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:q,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:o,disabled:b,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!P||b,className:"hub-btn primary flex items-center",children:b?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")})]})]})})},Ss=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[r,i]=m.useState(""),[b,n]=m.useState(null),[p,T]=m.useState(!1),[P,d]=m.useState(null),j=`{
7
- "mcpServers": {
8
- "stdio-server-example": {
9
- "command": "npx",
10
- "args": ["-y", "mcp-server-example"]
11
- },
12
- "sse-server-example": {
13
- "type": "sse",
14
- "url": "http://localhost:3000"
15
- },
16
- "http-server-example": {
17
- "type": "streamable-http",
18
- "url": "http://localhost:3001",
19
- "headers": {
20
- "Content-Type": "application/json",
21
- "Authorization": "Bearer your-token"
22
- }
23
- },
24
- "openapi-server-example": {
25
- "type": "openapi",
26
- "openapi": {
27
- "url": "https://petstore.swagger.io/v2/swagger.json"
28
- }
29
- }
30
- }
31
- }
32
-
33
- Supports: STDIO, SSE, HTTP (streamable-http), OpenAPI
34
- All servers will be imported in a single efficient batch operation.`,I=v=>{try{const E=JSON.parse(v.trim());return!E.mcpServers||typeof E.mcpServers!="object"?(n(t("jsonImport.invalidFormat")),null):E}catch{return n(t("jsonImport.parseError")),null}},y=()=>{n(null);const v=I(r);if(!v)return;const E=Object.entries(v.mcpServers).map(([g,O])=>{const R={};return O.type==="sse"||O.type==="streamable-http"?(R.type=O.type,R.url=O.url,O.headers&&(R.headers=O.headers)):O.type==="openapi"?(R.type="openapi",R.openapi=O.openapi):(R.type="stdio",R.command=O.command,R.args=O.args||[],O.env&&(R.env=O.env)),{name:g,config:R}});d(E)},$=async()=>{if(P){T(!0),n(null);try{const v=await ee("/servers/batch",{servers:P});if(v.success&&v.data){const{successCount:E,failureCount:g,results:O}=v.data;if(g>0){const R=O.filter(z=>!z.success).map(z=>`${z.name}: ${z.message||t("jsonImport.addFailed")}`);n(t("jsonImport.partialSuccess",{count:E,total:P.length})+`
35
- `+R.join(`
36
- `))}E>0&&s()}else n(v.message||t("jsonImport.importFailed"))}catch(v){console.error("Import error:",v),n(t("jsonImport.importFailed"))}finally{T(!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:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),b&&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:b})}),P?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-3",children:t("jsonImport.previewTitle")}),e.jsx("div",{className:"space-y-3",children:P.map((v,E)=>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(", ")]})]})]})})},E))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>d(null),disabled:p,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:$,disabled:p,className:"hub-btn primary",children:p?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:r,onChange:v=>i(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:j}),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:o,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:y,disabled:!r.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Js=()=>{const{t:s}=Q(),o=He(),{servers:t,allServers:r,error:i,setError:b,isLoading:n,pagination:p,currentPage:T,serversPerPage:P,setCurrentPage:d,setServersPerPage:j,handleServerAdd:I,handleServerEdit:y,handleServerRemove:$,handleServerToggle:v,handleServerReload:E,triggerRefresh:g}=ds({refreshOnMount:!0}),[O,R]=m.useState(null),[z,A]=m.useState(!1),[W,B]=m.useState(!1),[q,K]=m.useState(!1),[M,h]=m.useState("all"),[c,N]=m.useState(""),a=m.useMemo(()=>({all:r.length,online:r.filter(C=>C.status==="connected").length,issues:r.filter(C=>C.status!=="connected"&&C.enabled!==!1).length}),[r]),u=m.useMemo(()=>{const C=c.trim().toLowerCase();return t.filter(D=>{var k,J;return M==="online"&&D.status!=="connected"||M==="issues"&&(D.status==="connected"||D.enabled===!1)?!1:C?(D.name+" "+(((k=D.config)==null?void 0:k.description)||"")+" "+(((J=D.tools)==null?void 0:J.map(S=>S.name).join(" "))||"")).toLowerCase().includes(C):!0})},[t,M,c]),l=async C=>{const D=await y(C);D&&R(D)},f=async()=>{A(!0);try{g(),await new Promise(C=>setTimeout(C,400))}finally{A(!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:a.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:a.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:a.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>o("/market"),children:[e.jsx(ts,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>K(!0),children:[e.jsx(rs,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>B(!0),children:[e.jsx(ns,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:f,disabled:z,"aria-label":s("common.refresh"),children:[e.jsx(Ne,{size:13,className:z?"animate-spin":""}),s("common.refresh")]}),e.jsx(ws,{onAdd:I})]})]}),i&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(je,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:i})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>b(null),"aria-label":s("app.closeButton"),children:e.jsx(ve,{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",a.all],["online",s("status.online"),a.online],["issues",s("common.inactive")||"Issues",a.issues]].map(([C,D,V])=>e.jsxs("button",{onClick:()=>h(C),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:M===C?"var(--hub-bg-2)":"transparent",color:M===C?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(M===C?"var(--hub-line)":"transparent")},children:[D,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:V})]},C))}),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(as,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:c,onChange:C=>N(C.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),c&&e.jsx("button",{onClick:()=>N(""),className:"hub-icon-btn sm",children:e.jsx(ve,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[u.length,"/",t.length]})]}),n&&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(Ne,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):u.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:u.map(C=>e.jsx(Ns,{server:C,onRemove:$,onEdit:l,onToggle:v,onRefresh:g,onReload:E},C.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:p?s("common.showing",{start:(p.page-1)*p.limit+1,end:Math.min(p.page*p.limit,p.total),total:p.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:p&&p.totalPages>1&&e.jsx(cs,{currentPage:T,totalPages:p.totalPages,onPageChange:d,disabled:n})}),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:P,onChange:C=>j(Number(C.target.value)),disabled:n,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"})]})]})]})]}),O&&e.jsx(ks,{server:O,onEdit:()=>{R(null),g()},onCancel:()=>R(null)}),W&&e.jsx(Cs,{onSuccess:()=>{B(!1),g()},onCancel:()=>B(!1)}),q&&e.jsx(Ss,{onSuccess:()=>{K(!1),g()},onCancel:()=>K(!1)})]})};export{Js as default};
37
- //# sourceMappingURL=ServersPage-DtnlfwJF.js.map