@samanhappy/mcphub 1.0.38 → 1.0.39

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 (78) hide show
  1. package/dist/db/repositories/VectorEmbeddingRepository.js +35 -3
  2. package/dist/db/repositories/VectorEmbeddingRepository.js.map +1 -1
  3. package/dist/services/mcpService.js +85 -2
  4. package/dist/services/mcpService.js.map +1 -1
  5. package/dist/services/vectorSearchService.js +12 -3
  6. package/dist/services/vectorSearchService.js.map +1 -1
  7. package/dist/utils/cacheUtils.js +345 -1
  8. package/dist/utils/cacheUtils.js.map +1 -1
  9. package/dist/utils/packageUpdate.js +242 -0
  10. package/dist/utils/packageUpdate.js.map +1 -0
  11. package/dist/utils/serverConfigPersistence.js +6 -0
  12. package/dist/utils/serverConfigPersistence.js.map +1 -1
  13. package/frontend/dist/assets/{ActivityPage-BZNq-eGE.js → ActivityPage-CDKSVr2I.js} +2 -2
  14. package/frontend/dist/assets/{ActivityPage-BZNq-eGE.js.map → ActivityPage-CDKSVr2I.js.map} +1 -1
  15. package/frontend/dist/assets/CopyClientConfigDialog-DYiucK0d.js +4 -0
  16. package/frontend/dist/assets/CopyClientConfigDialog-DYiucK0d.js.map +1 -0
  17. package/frontend/dist/assets/{CredentialsPage-7kyDJLsX.js → CredentialsPage-DMJE4uT2.js} +2 -2
  18. package/frontend/dist/assets/{CredentialsPage-7kyDJLsX.js.map → CredentialsPage-DMJE4uT2.js.map} +1 -1
  19. package/frontend/dist/assets/Dashboard-Dh_39img.js +2 -0
  20. package/frontend/dist/assets/{Dashboard-CElNx820.js.map → Dashboard-Dh_39img.js.map} +1 -1
  21. package/frontend/dist/assets/EndpointCopy-CQmwGXbD.js +2 -0
  22. package/frontend/dist/assets/EndpointCopy-CQmwGXbD.js.map +1 -0
  23. package/frontend/dist/assets/GroupsPage-BqscWSfR.js +33 -0
  24. package/frontend/dist/assets/GroupsPage-BqscWSfR.js.map +1 -0
  25. package/frontend/dist/assets/{LoginPage-D23s7oM0.js → LoginPage-DcrwvgS6.js} +2 -2
  26. package/frontend/dist/assets/{LoginPage-D23s7oM0.js.map → LoginPage-DcrwvgS6.js.map} +1 -1
  27. package/frontend/dist/assets/{LogsPage-BuQMkmV-.js → LogsPage--Blkr-Ni.js} +2 -2
  28. package/frontend/dist/assets/{LogsPage-BuQMkmV-.js.map → LogsPage--Blkr-Ni.js.map} +1 -1
  29. package/frontend/dist/assets/{MarketPage-g9vEYzIq.js → MarketPage-DWv18j4V.js} +2 -2
  30. package/frontend/dist/assets/{MarketPage-g9vEYzIq.js.map → MarketPage-DWv18j4V.js.map} +1 -1
  31. package/frontend/dist/assets/{OAuthConsentPage-BiX1lpJR.js → OAuthConsentPage-DCKZIMzE.js} +2 -2
  32. package/frontend/dist/assets/{OAuthConsentPage-BiX1lpJR.js.map → OAuthConsentPage-DCKZIMzE.js.map} +1 -1
  33. package/frontend/dist/assets/{PromptsPage-g8SRFY6s.js → PromptsPage-DoVmnVnp.js} +2 -2
  34. package/frontend/dist/assets/{PromptsPage-g8SRFY6s.js.map → PromptsPage-DoVmnVnp.js.map} +1 -1
  35. package/frontend/dist/assets/{ResourcesPage-Ddhxi9Sf.js → ResourcesPage-B8udCQQR.js} +2 -2
  36. package/frontend/dist/assets/{ResourcesPage-Ddhxi9Sf.js.map → ResourcesPage-B8udCQQR.js.map} +1 -1
  37. package/frontend/dist/assets/ServersPage-OLpH1K1I.js +39 -0
  38. package/frontend/dist/assets/ServersPage-OLpH1K1I.js.map +1 -0
  39. package/frontend/dist/assets/{SettingsPage-DZXjQZXS.js → SettingsPage-DlK0Jcta.js} +3 -3
  40. package/frontend/dist/assets/{SettingsPage-DZXjQZXS.js.map → SettingsPage-DlK0Jcta.js.map} +1 -1
  41. package/frontend/dist/assets/{StatusDot-CdzMqjTi.js → StatusDot-DgDU3plH.js} +2 -2
  42. package/frontend/dist/assets/{StatusDot-CdzMqjTi.js.map → StatusDot-DgDU3plH.js.map} +1 -1
  43. package/frontend/dist/assets/{ToggleGroup-CJd8X_31.js → ToggleGroup-11yhmcwY.js} +2 -2
  44. package/frontend/dist/assets/{ToggleGroup-CJd8X_31.js.map → ToggleGroup-11yhmcwY.js.map} +1 -1
  45. package/frontend/dist/assets/{UsersPage-CkP_x9Rt.js → UsersPage-BqPEkoIX.js} +2 -2
  46. package/frontend/dist/assets/{UsersPage-CkP_x9Rt.js.map → UsersPage-BqPEkoIX.js.map} +1 -1
  47. package/frontend/dist/assets/clipboard-BukcCPLt.js +2 -0
  48. package/frontend/dist/assets/clipboard-BukcCPLt.js.map +1 -0
  49. package/frontend/dist/assets/{icons-vendor-VW-UwEhw.js → icons-vendor-Bk5sng-h.js} +66 -61
  50. package/frontend/dist/assets/icons-vendor-Bk5sng-h.js.map +1 -0
  51. package/frontend/dist/assets/index-D4Vy78bV.css +1 -0
  52. package/frontend/dist/assets/index-DhzWX9nb.js +3 -0
  53. package/frontend/dist/assets/{index-Bu4XuAH4.js.map → index-DhzWX9nb.js.map} +1 -1
  54. package/frontend/dist/assets/{resourceService-w-cZ31FD.js → resourceService-D-PRt7tB.js} +2 -2
  55. package/frontend/dist/assets/{resourceService-w-cZ31FD.js.map → resourceService-D-PRt7tB.js.map} +1 -1
  56. package/frontend/dist/assets/{useCostData-C72NC0PQ.js → useCostData-B-uSfiuA.js} +2 -2
  57. package/frontend/dist/assets/{useCostData-C72NC0PQ.js.map → useCostData-B-uSfiuA.js.map} +1 -1
  58. package/frontend/dist/assets/useSettingsData-Bk1AwN5F.js +2 -0
  59. package/frontend/dist/assets/{useSettingsData-JTEMu74D.js.map → useSettingsData-Bk1AwN5F.js.map} +1 -1
  60. package/frontend/dist/assets/variableDetection-B7Ko56CL.js +16 -0
  61. package/frontend/dist/assets/variableDetection-B7Ko56CL.js.map +1 -0
  62. package/frontend/dist/index.html +3 -3
  63. package/package.json +2 -1
  64. package/frontend/dist/assets/Dashboard-CElNx820.js +0 -2
  65. package/frontend/dist/assets/EndpointCopy-8jW5Xtka.js +0 -2
  66. package/frontend/dist/assets/EndpointCopy-8jW5Xtka.js.map +0 -1
  67. package/frontend/dist/assets/GroupsPage-dUkvX_iB.js +0 -33
  68. package/frontend/dist/assets/GroupsPage-dUkvX_iB.js.map +0 -1
  69. package/frontend/dist/assets/ServersPage-DAmKvrPV.js +0 -39
  70. package/frontend/dist/assets/ServersPage-DAmKvrPV.js.map +0 -1
  71. package/frontend/dist/assets/icons-vendor-VW-UwEhw.js.map +0 -1
  72. package/frontend/dist/assets/index-B3OqAhGz.css +0 -1
  73. package/frontend/dist/assets/index-Bu4XuAH4.js +0 -3
  74. package/frontend/dist/assets/toolDescription-Dw3sa28K.js +0 -2
  75. package/frontend/dist/assets/toolDescription-Dw3sa28K.js.map +0 -1
  76. package/frontend/dist/assets/useSettingsData-JTEMu74D.js +0 -2
  77. package/frontend/dist/assets/variableDetection-DfhNyFy-.js +0 -16
  78. package/frontend/dist/assets/variableDetection-DfhNyFy-.js.map +0 -1
@@ -1,39 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-w-cZ31FD.js","./index-Bu4XuAH4.js","./framework-vendor-_YL27Pfc.js","./i18n-vendor-BMaj5qV8.js","./icons-vendor-VW-UwEhw.js","./index-B3OqAhGz.css"])))=>i.map(i=>d[i]);
2
- import{r as u,j as e,L as $s,d as Is}from"./framework-vendor-_YL27Pfc.js";import{i as le,f as os,h as ve,j as Pe,u as Fs,_ as ye,e as Rs,k as Os,l as _s}from"./index-Bu4XuAH4.js";import{f as ie}from"./contextCost-CilWqGWT.js";import{S as As}from"./StatusDot-CdzMqjTi.js";import{u as ze}from"./useSettingsData-JTEMu74D.js";import{S as Ne}from"./ToggleGroup-CJd8X_31.js";import{u as te}from"./i18n-vendor-BMaj5qV8.js";import{n as is,o as ls,l as we,p as Ms,C as he,q as xe,r as Te,s as cs,t as ds,u as $e,m as ke,W as Vs,g as Us,F as Js,X as Ee,v as Bs,w as Ls,R as je,x as Ws,L as qs,T as Ks,P as Hs,y as Gs,z as Ys,D as Xs}from"./icons-vendor-VW-UwEhw.js";import{g as Zs}from"./toolDescription-Dw3sa28K.js";import{D as Qs}from"./DeleteDialog-BYhrMGZo.js";import{C as De}from"./ConfirmDialog-uWBwm8J1.js";import{S as us,d as et}from"./variableDetection-DfhNyFy-.js";import{P as st}from"./Pagination-CLUvn47x.js";import{u as tt,a as rt}from"./useCostData-C72NC0PQ.js";const ms=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",a=await le(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return a.success===!1?{success:!1,error:a.message||"Tool call failed"}:{success:!0,content:(a==null?void 0:a.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},nt=async(s,n,t)=>{try{const a=await le(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},ps=async(s,n,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating tool description",{serverName:s,toolName:n,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},xs=async(s,n)=>{var t;try{const a=await os(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},at=Object.freeze(Object.defineProperty({__proto__:null,callTool:ms,resetToolDescription:xs,toggleTool:nt,updateToolDescription:ps},Symbol.toStringTag,{value:"Module"})),hs=({schema:s,onSubmit:n,onCancel:t,loading:a=!1,storageKey:x,title:d})=>{const{t:o}=te(),[y,N]=u.useState({}),[D,r]=u.useState({}),[p,$]=u.useState(!1),[g,F]=u.useState(""),[w,E]=u.useState(""),k=u.useMemo(()=>(m=>{const j=l=>{if(typeof l=="object"&&l!==null){const h=l;return{type:h.type||"string",description:h.description,enum:h.enum,default:h.default,properties:h.properties?Object.fromEntries(Object.entries(h.properties).map(([c,v])=>[c,j(v)])):void 0,required:h.required,items:h.items?j(h.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([l,h])=>[l,j(h)])):void 0,required:m.required}})(s),[s]);u.useEffect(()=>{const b=(j,l="")=>{const h={};return j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,v])=>{const P=l?`${l}.${c}`:c;v.default!==void 0?h[c]=v.default:v.type==="string"?h[c]="":v.type==="number"||v.type==="integer"?h[c]=0:v.type==="boolean"?h[c]=!1:v.type==="array"?h[c]=[]:v.type==="object"&&(v.properties?h[c]=b(v,P):h[c]={})}),h};let m=b(k);if(x)try{const j=localStorage.getItem(x);if(j){const l=JSON.parse(j);m={...m,...l}}}catch(j){console.warn("Failed to load saved form data:",j)}N(m)},[k,x]),u.useEffect(()=>{p&&Object.keys(y).length>0&&(F(JSON.stringify(y,null,2)),E(""))},[p,y]);const R=b=>{F(b),E("");try{const m=JSON.parse(b);if(N(m),x)try{localStorage.setItem(x,JSON.stringify(m))}catch(j){console.warn("Failed to save form data to localStorage:",j)}}catch{E(o("tool.invalidJsonFormat"))}},_=()=>{F(JSON.stringify(y,null,2)),E(""),$(!0)},W=()=>{if(g.trim())try{const b=JSON.parse(g);N(b),E(""),$(!1)}catch{E(o("tool.fixJsonBeforeSwitching"));return}else $(!1)},O=(b,m)=>{N(j=>{const l={...j},h=b.split(".");let c=l;for(let P=0;P<h.length-1;P++){const T=h[P];if(T==="__proto__"||T==="constructor"||T==="prototype")return j;c[T]||(c[T]={}),c=c[T]}const v=h[h.length-1];if(!v||v==="__proto__"||v==="constructor"||v==="prototype")return j;if(c[v]=m,x)try{localStorage.setItem(x,JSON.stringify(l))}catch(P){console.warn("Failed to save form data to localStorage:",P)}return l}),D[b]&&r(j=>{const l={...j};return delete l[b],l})},B=()=>{const b={},m=(j,l,h="")=>{j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,v])=>{var A;const P=h?`${h}.${c}`:c,T=l==null?void 0:l[c];if((A=j.required)!=null&&A.includes(c)&&(T==null||T===""||Array.isArray(T)&&T.length===0)){b[P]=`${c} is required`;return}T!=null&&T!==""&&(v.type==="string"&&typeof T!="string"?b[P]=`${c} must be a string`:v.type==="number"&&typeof T!="number"?b[P]=`${c} must be a number`:v.type==="integer"&&(!Number.isInteger(T)||typeof T!="number")?b[P]=`${c} must be an integer`:v.type==="boolean"&&typeof T!="boolean"?b[P]=`${c} must be a boolean`:v.type==="array"&&Array.isArray(T)?v.items&&T.forEach((L,Q)=>{var M;((M=v.items)==null?void 0:M.type)==="object"&&v.items.properties&&m(v.items,L,`${P}.${Q}`)}):v.type==="object"&&typeof T=="object"&&m(v,T,P))})};return m(k,y),r(b),Object.keys(b).length===0},I=b=>{b.preventDefault(),B()&&n(y)},H=(b,m)=>m.split(".").reduce((j,l)=>j==null?void 0:j[l],b),q=(b,m,j,l)=>{const h=j==null?void 0:j[b];return m.type==="string"?m.enum?e.jsxs("select",{value:h||"",onChange:c=>l(c.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:o("tool.selectOption")}),m.enum.map((c,v)=>e.jsx("option",{value:c,children:c},v))]}):e.jsx("input",{type:"text",value:h||"",onChange:c=>l(c.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:m.description||o("tool.enterKey",{key:b})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:h??"",onChange:c=>{const v=c.target.value===""?"":m.type==="integer"?parseInt(c.target.value):parseFloat(c.target.value);l(v)},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"}):m.type==="boolean"?e.jsx("input",{type:"checkbox",checked:h||!1,onChange:c=>l(c.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:h||"",onChange:c=>l(c.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:m.description||o("tool.enterKey",{key:b})})},Y=(b,m,j="")=>{var v,P,T,A,L,Q,M,S,J,ee,oe,z,K,ce;const l=j?`${j}.${b}`:b,h=H(y,l),c=D[l];if(m.type==="array"){const V=H(y,l)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?(P=(v=H(k,j))==null?void 0:v.required)==null?void 0:P.includes(b):(T=k.required)==null?void 0:T.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.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:[V.map((Z,se)=>{var be,ae,G;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:o("tool.item",{index:se+1})}),e.jsx("button",{type:"button",onClick:()=>{const X=[...V];X.splice(se,1),O(l,X)},className:"text-status-red hover:text-red-700 text-sm",children:o("common.remove")})]}),((be=m.items)==null?void 0:be.type)==="string"&&m.items.enum?e.jsxs("select",{value:Z||"",onChange:X=>{const re=[...V];re[se]=X.target.value,O(l,re)},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:o("tool.selectOption")}),m.items.enum.map((X,re)=>e.jsx("option",{value:X,children:X},re))]}):((ae=m.items)==null?void 0:ae.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([X,re])=>{var fe,ge;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[X,((ge=(fe=m.items)==null?void 0:fe.required)==null?void 0:ge.includes(X))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),q(X,re,Z,Ce=>{const pe=[...V];pe[se]={...pe[se],[X]:Ce},O(l,pe)})]},X)})}):e.jsx("input",{type:"text",value:Z||"",onChange:X=>{const re=[...V];re[se]=X.target.value,O(l,re)},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:o("tool.enterValue",{type:((G=m.items)==null?void 0:G.type)||"value"})})]},se)}),e.jsx("button",{type:"button",onClick:()=>{var se;const Z=((se=m.items)==null?void 0:se.type)==="object"?{}:"";O(l,[...V,Z])},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:o("tool.addItem",{key:b})})]}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l)}return m.type==="object"?m.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?(L=(A=H(k,j))==null?void 0:A.required)==null?void 0:L.includes(b):(Q=k.required)==null?void 0:Q.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.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(m.properties).map(([V,Z])=>Y(V,Z,l))}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?(S=(M=H(k,j))==null?void 0:M.required)==null?void 0:S.includes(b):(J=k.required)==null?void 0:J.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("textarea",{value:typeof h=="object"?JSON.stringify(h,null,2):h||"{}",onChange:V=>{try{const Z=JSON.parse(V.target.value);O(l,Z)}catch{O(l,V.target.value)}},placeholder:`{
3
- "key": "value"
4
- }`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="string"?m.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?!1:(ee=k.required)==null?void 0:ee.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("select",{value:h||"",onChange:V=>O(l,V.target.value),className:`w-full border rounded-md px-3 py-2 ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:o("tool.selectOption")}),m.enum.map((V,Z)=>e.jsx("option",{value:V,children:V},Z))]}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?!1:(oe=k.required)==null?void 0:oe.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:h||"",onChange:V=>O(l,V.target.value),className:`w-full border rounded-md px-3 py-2 ${c?"border-red":"border-gray-200"} focus:outline-none form-input`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="number"||m.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?!1:(z=k.required)==null?void 0:z.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:h??"",onChange:V=>{const Z=V.target.value===""?"":m.type==="integer"?parseInt(V.target.value):parseFloat(V.target.value);O(l,Z)},className:`w-full border rounded-md px-3 py-2 form-input ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:h||!1,onChange:V=>O(l,V.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:[b,(j?!1:(K=k.required)==null?void 0:K.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:m.description}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[b,(j?!1:(ce=k.required)==null?void 0:ce.includes(b))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",m.type,")"]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:h||"",onChange:V=>O(l,V.target.value),placeholder:o("tool.enterValue",{type:m.type}),className:`w-full border rounded-md px-3 py-2 ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l)};return k.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:W,className:`hub-btn sm ${p?"":"primary"}`,children:o("tool.formMode")}),e.jsx("button",{type:"button",onClick:_,className:`hub-btn sm ${p?"primary":""}`,children:o("tool.jsonMode")})]})]}),p?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:o("tool.jsonConfiguration")}),e.jsx("textarea",{value:g,onChange:b=>R(b.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 ${w?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),w&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:w})]}),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:o("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const b=JSON.parse(g);n(b)}catch{E(o("tool.invalidJsonFormat"))}},disabled:a||!!w,className:"hub-btn sm primary",children:o(a?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:I,className:"space-y-4",children:[Object.entries(k.properties||{}).map(([b,m])=>Y(b,m)),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:o("tool.cancel")}),e.jsx("button",{type:"submit",disabled:a,className:"hub-btn sm primary",children:o(a?"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:o("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:o("tool.cancel")}),e.jsx("button",{onClick:()=>n({}),disabled:a,className:"hub-btn primary",children:o(a?"tool.running":"tool.runTool")})]})]})},ot=({result:s,onClose:n})=>{const{t}=te(),a=s.content,x=r=>r?r.startsWith("image/")?r:`image/${r}`:"image/png",d=r=>{if(!r)return[];if(Array.isArray(r))return r.flatMap(g=>d(g));if(typeof r!="object")return[];const p=[];r.type==="image"&&r.data&&p.push({data:String(r.data),mimeType:x(r.mimeType||r.mime_type)});const $=r.image_base64||r.imageBase64||r.image_data||r.imageData||r.base64;return $&&p.push({data:String($),mimeType:x(r.image_mimeType||r.image_mime_type||r.mimeType||r.mime_type)}),r.image&&typeof r.image=="object"&&p.push(...d(r.image)),Array.isArray(r.images)&&p.push(...d(r.images)),Array.isArray(r.content)&&p.push(...d(r.content)),p},o=r=>{const p=[];try{const F=JSON.parse(r);if(p.push(...d(F)),p.length>0)return p}catch{}const $=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let g;for(;(g=$.exec(r))!==null;){const F=`image/${g[1]==="jpg"?"jpeg":g[1]}`;p.push({data:g[2],mimeType:F})}return p},y=r=>{try{const p=JSON.parse(r),$=g=>{if(Array.isArray(g))return g.map($);if(g&&typeof g=="object"){const F={};for(const[w,E]of Object.entries(g))typeof E=="string"&&w.toLowerCase().includes("base64")?F[w]="[base64 omitted]":F[w]=$(E);return F}return g};return JSON.stringify($(p),null,2)}catch{return r.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},N=r=>Array.isArray(r)?r.map((p,$)=>e.jsx("div",{className:"mb-3 last:mb-0",children:D(p)},$)):D(r),D=r=>{if(typeof r=="string"){const p=o(r),$=y(r);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[p.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:p.map((g,F)=>e.jsx("img",{src:`data:${g.mimeType||"image/png"};base64,${g.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:$})]})}if(typeof r=="object"&&r!==null){if(r.type==="text"&&r.text){const p=o(r.text),$=y(r.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[p.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:p.map((g,F)=>e.jsx("img",{src:`data:${g.mimeType||"image/png"};base64,${g.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:$})]})}if(r.type==="image"&&r.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${r.mimeType||"image/png"};base64,${r.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const p=typeof r=="string"?JSON.parse(r):r;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(p,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(r)})})}}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(r)})})};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(is,{size:20,className:"text-status-green"}):e.jsx(ls,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),N(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(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),a&&a.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),N(a)]}):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")})})]})})]})},me=({title:s,onClick:n,disabled:t=!1,loading:a=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:n,disabled:t,title:s,"aria-label":s,children:e.jsx(Ms,{size:14,className:a?"animate-spin":""})});function it(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 lt=({tool:s,server:n,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:d})=>{const{t:o}=te(),{showToast:y}=Pe(),{nameSeparator:N}=ze(),[D,r]=u.useState(!1),[p,$]=u.useState(!1),[g,F]=u.useState(!1),[w,E]=u.useState(null),[k,R]=u.useState(!1),[_,W]=u.useState(!1),[O,B]=u.useState(s.description||""),I=u.useRef(null),H=u.useRef(null),[q,Y]=u.useState(0),[b,m]=u.useState(!1);u.useEffect(()=>{k&&I.current&&(I.current.focus(),q>0&&(I.current.style.width=`${q+20}px`))},[k,q]),u.useEffect(()=>{!k&&H.current&&Y(H.current.offsetWidth)},[k,O]),u.useEffect(()=>{B(s.description||"")},[s.description]);const j=s.name.replace(n+N,""),l=Zs(s,o("tool.noDescription")),h=l.hasDescriptionOverride?o("tool.defaultDescriptionTooltip",{description:l.defaultDescription}):void 0,c=u.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),v=u.useCallback(()=>{localStorage.removeItem(c())},[c]),P=z=>{!t&&a&&a(s.name,z)},T=()=>{t||R(!0)},A=async()=>{if(!t)try{const z=await ps(n,s.name,O);z.success?(R(!1),x&&x(s.name,O)):(B(s.description||""),console.error("Failed to update tool description:",z.error))}catch(z){console.error("Error updating tool description:",z),B(s.description||""),R(!1)}},L=z=>{B(z.target.value)},Q=async()=>{if(!t){W(!0);try{const z=await xs(n,s.name);if(z.success){const K=z.description||"";B(K),R(!1),x==null||x(s.name,K,{restored:!0})}else y(z.error||o("tool.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting tool description:",z),y(o("tool.restoreDefaultFailed"),"error")}finally{W(!1)}}},M=z=>{z.key==="Enter"?A():z.key==="Escape"&&(B(s.description||""),R(!1))},S=async z=>{z.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),y(o("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const K=document.createElement("textarea");K.value=s.name,K.style.position="fixed",K.style.left="-9999px",document.body.appendChild(K),K.focus(),K.select();try{document.execCommand("copy"),m(!0),y(o("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(ce){y(o("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",ce)}document.body.removeChild(K)}}catch(K){y(o("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",K)}},J=async z=>{F(!0);try{z=Object.fromEntries(Object.entries(z).filter(([ce,V])=>!it(V)));const K=await ms({toolName:s.name,arguments:z},n);E(K)}catch(K){E({success:!1,error:K instanceof Error?K.message:"Unknown error occurred"})}finally{F(!1)}},ee=()=>{$(!1),v(),E(null)},oe=()=>{E(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:z=>{z.stopPropagation(),r(!D)},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:j}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S,title:o("common.copy"),children:b?e.jsx(he,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(xe,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:k?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:O,onChange:L,onKeyDown:M,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),A()},disabled:_,children:e.jsx(he,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(me,{title:o("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),Q()},disabled:_,loading:_})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,title:h,children:l.currentDescription}),l.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:h,children:o("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),T()},children:e.jsx(Te,{size:12})}),e.jsx(me,{title:o("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),Q()},disabled:_,loading:_})]})]})})]}),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:o("cost.estimate"),children:["Σ ",ie(d)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:P,disabled:g||t,size:"card","aria-label":`${o(s.enabled??!0?"server.disable":"server.enable")} ${j}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),r(!0),$(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:g||!s.enabled,children:[g?e.jsx(cs,{size:12,className:"animate-spin"}):e.jsx(ds,{size:12}),e.jsx("span",{children:o(g?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:D?e.jsx($e,{size:14}):e.jsx(ke,{size:14})})]})]}),D&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[l.hasDescriptionOverride&&l.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:o("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:l.defaultDescription})]}),!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:o("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(hs,{schema:s.inputSchema||{type:"object"},onSubmit:J,onCancel:ee,loading:g,storageKey:c(),title:o("tool.runToolWithName",{name:j})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(ot,{result:w,onClose:oe})})]})]})]})},ct=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",a=await le(t,{promptName:s.promptName,arguments:s.arguments});return a.success?{success:!0,data:a.data}:{success:!1,error:a.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},bs=async(s,n)=>{try{const t=await le(`/mcp/${encodeURIComponent(n||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},dt=async(s,n,t)=>{try{const a=await le(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},fs=async(s,n,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},gs=async(s,n)=>{var t;try{const a=await os(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},ut=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:ct,getPrompt:bs,resetPromptDescription:gs,togglePrompt:dt,updatePromptDescription:fs},Symbol.toStringTag,{value:"Module"})),ss=({result:s,onClose:n})=>{const{t}=te(),a=x=>{if(typeof x=="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:x})});if(typeof x=="object"&&x!==null){if(x.description||x.messages)return e.jsxs("div",{className:"space-y-4",children:[x.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:x.description})})]}),x.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:x.messages.map((d,o)=>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)})]},o))})]})]});try{const d=typeof x=="string"?JSON.parse(x):x;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(x)})})}}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(x)})})};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(is,{size:20,className:"text-status-green"}):e.jsx(ls,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),a(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(we,{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")})})]})})]})},mt=({prompt:s,server:n,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:d})=>{const{t:o}=te(),{showToast:y}=Pe(),{nameSeparator:N}=ze(),[D,r]=u.useState(!1),[p,$]=u.useState(!1),[g,F]=u.useState(!1),[w,E]=u.useState(null),[k,R]=u.useState(!1),[_,W]=u.useState(!1),[O,B]=u.useState(s.description||""),I=u.useRef(null),H=u.useRef(null),[q,Y]=u.useState(0);u.useEffect(()=>{k&&I.current&&(I.current.focus(),q>0&&(I.current.style.width=`${q+20}px`))},[k,q]),u.useEffect(()=>{!k&&H.current&&Y(H.current.offsetWidth)},[k,O]),u.useEffect(()=>{B(s.description||"")},[s.description]);const b=u.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),m=u.useCallback(()=>{localStorage.removeItem(b())},[b]),j=S=>{!t&&a&&a(s.name,S)},l=()=>{t||R(!0)},h=async()=>{if(!t){R(!1);try{const S=await fs(n,s.name,O);S.success?x&&x(s.name,O):(y(S.error||o("prompt.descriptionUpdateFailed"),"error"),B(s.description||""))}catch(S){console.error("Error updating prompt description:",S),y(o("prompt.descriptionUpdateFailed"),"error"),B(s.description||"")}}},c=async()=>{if(!t){W(!0);try{const S=await gs(n,s.name);if(S.success){const J=S.description||"";B(J),R(!1),x==null||x(s.name,J,{restored:!0})}else y(S.error||o("prompt.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting prompt description:",S),y(o("prompt.restoreDefaultFailed"),"error")}finally{W(!1)}}},v=S=>{B(S.target.value)},P=S=>{S.key==="Enter"?h():S.key==="Escape"&&(B(s.description||""),R(!1))},T=async S=>{F(!0);try{const J=await bs({promptName:s.name,arguments:S},n);console.log("GetPrompt result:",J),E({success:J.success,data:J.data,error:J.error})}catch(J){E({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{F(!1)}},A=()=>{$(!1),m(),E(null)},L=()=>{E(null)},Q=s.name.replace(n+N,""),M=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const S={},J=[];return s.arguments.forEach(ee=>{S[ee.name]={type:"string",description:ee.description||""},ee.required&&J.push(ee.name)}),{type:"object",properties:S,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:()=>r(!D),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:Q}),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:k?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:O,onChange:v,onKeyDown:P,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),h()},disabled:_,children:e.jsx(he,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(me,{title:o("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),c()},disabled:_,loading:_})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,children:O||o("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),l()},children:e.jsx(Te,{size:12})}),e.jsx(me,{title:o("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),c()},disabled:_,loading:_})]})]})})]}),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:o("cost.estimate"),children:["Σ ",ie(d)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:S=>S.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ne,{checked:s.enabled,onCheckedChange:j,disabled:g||t,size:"card","aria-label":`${o(s.enabled?"server.disable":"server.enable")} ${Q}`})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),r(!0),$(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:g||!s.enabled,children:[g?e.jsx(cs,{size:12,className:"animate-spin"}):e.jsx(ds,{size:12}),e.jsx("span",{children:o(g?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:D?e.jsx($e,{size:14}):e.jsx(ke,{size:14})})]})]}),D&&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(hs,{schema:M(),onSubmit:T,onCancel:A,loading:g,storageKey:b(),title:o("prompt.runPromptWithName",{name:Q})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(ss,{result:w,onClose:L})})]}),!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:o("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((S,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:S.name}),S.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),S.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:S.description})]}),S.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:S.title})]},J))})]}),!p&&w&&e.jsx("div",{children:e.jsx(ss,{result:w,onClose:L})})]})]})},pt=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:a,cost:x})=>{const{t:d}=te(),[o,y]=u.useState(!1),[N,D]=u.useState(!1),[r,p]=u.useState(!1),[$,g]=u.useState(s.description||""),F=u.useRef(null),w=u.useRef(null),[E,k]=u.useState(0);u.useEffect(()=>{N&&F.current&&(F.current.focus(),E>0&&(F.current.style.width=`${E+20}px`))},[N,E]),u.useEffect(()=>{!N&&w.current&&k(w.current.offsetWidth)},[N,$]),u.useEffect(()=>{g(s.description||"")},[s.description]);const R=s.name||s.uri,_=I=>{!n&&t&&t(s.uri,I)},W=async()=>{n||(D(!1),a&&await a(s.uri,$))},O=async()=>{if(!n){p(!0);try{await(a==null?void 0:a(s.uri,"",{restored:!0})),D(!1)}finally{p(!1)}}},B=I=>{I.key==="Enter"?W():I.key==="Escape"&&(g(s.description||""),D(!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:()=>y(!o),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:R}),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:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:E>0?`${E+20}px`:160,minWidth:80},value:$,onChange:I=>g(I.target.value),onKeyDown:B,onClick:I=>I.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:I=>{I.stopPropagation(),W()},disabled:r,children:e.jsx(he,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(me,{title:d("builtinResources.restoreDefault"),onClick:I=>{I.stopPropagation(),O()},disabled:r,loading:r})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:w,children:$||d("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:I=>{I.stopPropagation(),D(!0)},children:e.jsx(Te,{size:12})}),e.jsx(me,{title:d("builtinResources.restoreDefault"),onClick:I=>{I.stopPropagation(),O()},disabled:r,loading:r})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[x!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:d("cost.estimate"),children:["Σ ",ie(x)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:I=>I.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled!==!1,onCheckedChange:_,disabled:n,size:"card","aria-label":`${d(s.enabled!==!1?"server.disable":"server.enable")} ${R}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:o?e.jsx($e,{size:14}):e.jsx(ke,{size:14})})]})]}),o&&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"})]})]})},xt=(s,n)=>n?n.isAdmin?!0:!!(s.owner&&s.owner===n.username):!1,ht={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)]"}},Ie=s=>s==="public"||s==="group"?s:"private",bt=(s,n)=>{const t=Ie(n),a=ht[t];return{value:t,shortLabel:s(a.shortKey,{defaultValue:a.shortFallback}),longLabel:s(a.longKey,{defaultValue:a.longFallback}),className:a.className}},ft=(s,n)=>{const t=Ie(n),a=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&a.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Shared"}),disabled:!0}),a.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),a},ts=({isLoading:s,children:n,className:t,overlayStyle:a,spinnerSize:x=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:n}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...a},children:e.jsx(je,{size:x,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),rs=({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"})}),ns=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,gt="text/html;profile=mcp-app",as=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,yt=s=>{var n,t;return!!((n=s.tools)!=null&&n.some(a=>as(a._meta))||(t=s.resources)!=null&&t.some(a=>{var x;return((x=a.uri)==null?void 0:x.startsWith("ui://"))||a.mimeType===gt||as(a._meta)}))},jt=({server:s,cost:n,onRemove:t,onEdit:a,onToggle:x,onVisibilityChange:d,onRefresh:o,onReload:y,onReinstall:N,onOAuthDisconnect:D})=>{var Me,Ve,Ue,Je,Be,Le,We,qe,Ke,He,Ge,Ye,Xe,Ze,Qe,es;const{t:r}=te(),{showToast:p}=Pe(),{exportMCPSettings:$,installConfig:g}=ze(),{auth:F}=Fs(),w=((Me=g==null?void 0:g.baseUrl)==null?void 0:Me.replace(/\/+$/,""))||"",[E,k]=u.useState(!1),[R,_]=u.useState(null),[W,O]=u.useState(!1),[B,I]=u.useState(!1),[H,q]=u.useState(!1),[Y,b]=u.useState(!1),[m,j]=u.useState(!1),[l,h]=u.useState(!1),[c,v]=u.useState(!1),[P,T]=u.useState(!1),[A,L]=u.useState(!1),[Q,M]=u.useState(!1),[S,J]=u.useState(!1),ee=u.useRef(null),oe=u.useRef(null);u.useEffect(()=>{const i=f=>{ee.current&&!ee.current.contains(f.target)&&L(!1),oe.current&&!oe.current.contains(f.target)&&M(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const z=((Ve=s.tools)==null?void 0:Ve.length)||0,K=((Ue=s.tools)==null?void 0:Ue.filter(i=>i.enabled!==!1).length)||0,ce=((Je=s.prompts)==null?void 0:Je.length)||0,V=((Be=s.prompts)==null?void 0:Be.filter(i=>i.enabled!==!1).length)||0,Z=((Le=s.resources)==null?void 0:Le.length)||0,se=((We=s.resources)==null?void 0:We.filter(i=>i.enabled!==!1).length)||0,be=yt(s),ae=s.enabled!==!1,G=xt(s,F.user),X=((qe=s.config)==null?void 0:qe.command)==="npx"||((Ke=s.config)==null?void 0:Ke.command)==="uvx",re=!!((He=s.oauth)!=null&&He.connected&&D),fe=async i=>{if(!(!G||Y||!x)){b(!0);try{await x(s,i)}finally{b(!1)}}},ge=async i=>{if(i.stopPropagation(),L(!1),!(!G||l||!y)){h(!0);try{await y(s)?p(r("server.reloadSuccess")||"Server reloaded successfully","success"):p(r("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{h(!1)}}},Ce=async()=>{if(L(!1),!(!G||c||!N)){v(!0);try{await N(s)?p(r("server.reinstallSuccess")||"Server reinstall initiated","success"):p(r("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{v(!1)}}},pe=async()=>{if(L(!1),!(!G||P||!D)){T(!0);try{await D(s)?p(r("server.disconnectOAuthSuccess")||"Server OAuth disconnected","success"):p(r("server.disconnectOAuthError",{serverName:s.name})||"Failed to disconnect OAuth","error")}finally{T(!1)}}},ys=async i=>{var C;if(i.stopPropagation(),!G||m||!d)return;const f=i.target.value;if(f!==Ie(s.visibility??((C=s.config)==null?void 0:C.visibility))){j(!0);try{await d(s,f)}finally{j(!1)}}},Se=async i=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(i),!0}catch{}try{const f=document.createElement("textarea");f.value=i,f.style.position="fixed",f.style.left="-9999px",document.body.appendChild(f),f.focus(),f.select();const C=document.execCommand("copy");return document.body.removeChild(f),C}catch{return!1}},js=async i=>{if(i.stopPropagation(),!s.error)return;await Se(s.error)?(J(!0),p(r("common.copySuccess")||"Copied","success"),setTimeout(()=>J(!1),1500)):p(r("common.copyFailed")||"Copy failed","error")},vs=async i=>{if(i.stopPropagation(),L(!1),!!G)try{const f=await $(s.name);if(!f||!f.success||!f.data){p((f==null?void 0:f.message)||r("common.copyFailed")||"Copy failed","error");return}const C=JSON.stringify(f.data,null,2),U=await Se(C);p(U?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Copy failed",U?"success":"error")}catch(f){console.error("Error copying server configuration:",f),p(r("common.copyFailed")||"Copy failed","error")}},Ns=i=>{var f;if(i.stopPropagation(),(f=s.oauth)!=null&&f.authorizationUrl){const ne=window.screen.width/2-300,de=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ne},top=${de}`),p(r("status.oauthWindowOpened"),"info"),s.oauth.clientIdConfigured&&p(r("status.oauthClientIdHint"),"warning")}},ws=async(i,f)=>{try{const{toggleTool:C}=await ye(async()=>{const{toggleTool:ne}=await Promise.resolve().then(()=>at);return{toggleTool:ne}},void 0,import.meta.url),U=await C(s.name,i,f);U.success?(p(r(f?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),o==null||o()):p(U.error||r("tool.toggleFailed"),"error")}catch(C){console.error(C),p(r("tool.toggleFailed"),"error")}},ks=async(i,f)=>{try{const{togglePrompt:C}=await ye(async()=>{const{togglePrompt:ne}=await Promise.resolve().then(()=>ut);return{togglePrompt:ne}},void 0,import.meta.url),U=await C(s.name,i,f);U.success?(p(r(f?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),o==null||o()):p(U.error||r("tool.toggleFailed"),"error")}catch(C){console.error(C),p(r("tool.toggleFailed"),"error")}},Cs=async(i,f)=>{try{const{toggleResource:C}=await ye(async()=>{const{toggleResource:ne}=await import("./resourceService-w-cZ31FD.js");return{toggleResource:ne}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),U=await C(s.name,i,f);U.success?(p(r(f?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),o==null||o()):p(U.error||r("tool.toggleFailed"),"error")}catch(C){console.error(C),p(r("tool.toggleFailed"),"error")}},Ss=(i,f,C)=>{p(C!=null&&C.restored?r("tool.restoreDefaultSuccess"):r("tool.descriptionUpdateSuccess"),"success"),o==null||o()},Es=(i,f,C)=>{p(C!=null&&C.restored?r("prompt.restoreDefaultSuccess"):r("prompt.descriptionUpdateSuccess"),"success"),o==null||o()},Ds=async(i,f,C)=>{try{const{updateResourceDescription:U,resetResourceDescription:ne}=await ye(async()=>{const{updateResourceDescription:zs,resetResourceDescription:Ts}=await import("./resourceService-w-cZ31FD.js");return{updateResourceDescription:zs,resetResourceDescription:Ts}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),de=C!=null&&C.restored?await ne(s.name,i):await U(s.name,i,f);de.success?(p(C!=null&&C.restored?r("builtinResources.restoreDefaultSuccess"):r("builtinResources.descriptionUpdateSuccess"),"success"),o==null||o()):p(de.error||(C!=null&&C.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed")),"error")}catch(U){console.error(U),p(C!=null&&C.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var C;const i=s.config;if(!i)return"";if(i.url)return i.url;const f=[];return i.command&&f.push(i.command),(C=i.args)!=null&&C.length&&f.push(...i.args),f.join(" ")})();const Fe=`${w}/mcp/${s.name}`,Re=`${w}/api/${s.name}`,Oe=async i=>{const f=await Se(i);p(f?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Failed",f?"success":"error")},_e=(i,f)=>r(i,f),ue=bt(_e,s.visibility??((Ge=s.config)==null?void 0:Ge.visibility)),Ps=ft(_e,ue.value),Ae=[{key:"tools",icon:Vs,total:z,enabled:K,label:r("server.tools")},{key:"prompts",icon:Us,total:ce,enabled:V,label:r("server.prompts")},{key:"resources",icon:Js,total:Z,enabled:se,label:r("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:()=>k(!E),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ke,{size:12,style:{color:"var(--hub-ink-3)",transform:E?"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:ae?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),be&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:r("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:oe,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),M(f=>!f)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":r("server.viewErrorDetails"),children:e.jsx(we,{size:14})}),Q&&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:r("server.errorDetails")}),e.jsx("button",{onClick:js,className:"hub-icon-btn sm",title:r("common.copy"),children:S?e.jsx(he,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(xe,{size:12})})]}),e.jsx("button",{onClick:()=>M(!1),className:"hub-icon-btn sm","aria-label":r("app.closeButton"),children:e.jsx(Ee,{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})})]})]})]}),!!((Xe=(Ye=s.config)==null?void 0:Ye.credentialTemplate)!=null&&Xe.length)&&e.jsxs($s,{className:"hub-tag text-xs",to:`/credentials?server=${encodeURIComponent(s.name)}`,onClick:i=>i.stopPropagation(),children:[r("credentials.personalBadge")," · ",r("credentials.manage")]}),((Ze=s.config)==null?void 0:Ze.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:e.jsx(As,{status:s.status,enabled:s.enabled,startOnDemand:((Qe=s.config)==null?void 0:Qe.startOnDemand)===!0,onAuthClick:Ns,className:"hub-server-card-status"})}),e.jsx("div",{className:"hub-server-card-transport-cell min-w-0",children:(es=s.config)!=null&&es.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:ns(r,s.config.type)??void 0,children:ns(r,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:i=>i.stopPropagation(),children:G&&d?e.jsx(ts,{isLoading:m,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ue.value,onChange:ys,disabled:m,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":r("server.visibility","Visibility"),title:ue.longLabel,children:Ps.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] ${ue.className}`,title:ue.longLabel,children:ue.shortLabel})}),Ae.map(({key:i,icon:f,total:C,enabled:U,label:ne})=>{const de=C===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${de?"is-empty":""}`,title:`${ne}: ${U}/${C}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(rs,{icon:f})}),e.jsx("span",{className:"hub-server-capability-value",children:de?"0":`${U}/${C}`})]},i)}),n&&n.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${r("cost.exposed")} ${n.exposed} / ${r("cost.gross")} ${n.gross} · ${r("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ie(n.exposed),"/",ie(n.gross)]})]}):n?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:r("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(ts,{isLoading:Y,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ne,{checked:ae,onCheckedChange:fe,disabled:Y||!G,size:"compact","aria-label":`${r(ae?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:ee,children:[G&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),L(f=>!f)},"aria-label":"More",children:e.jsx(Bs,{size:14})}),G&&A&&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),a(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(Ls,{size:13})," ",r("server.edit")]}),e.jsxs("button",{onClick:vs,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(xe,{size:13})," ",r("server.copy")]}),y&&e.jsxs("button",{onClick:ge,disabled:l||Y||!ae,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(je,{size:13})," ",r("server.reload")]}),N&&X&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!G||c||!ae)&&I(!0)},disabled:c||Y||!ae,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(Ws,{size:13})," ",r("server.reinstall")]}),re&&e.jsxs("button",{onClick:i=>{i.stopPropagation(),L(!1),!(!G||P)&&q(!0)},disabled:P,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(qs,{size:13})," ",r("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),O(!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(Ks,{size:13})," ",r("server.delete")]})]})]})]}),E&&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 flex-wrap",children:[Ae.map(i=>{const f=R===i.key,C=i.icon;return e.jsxs("button",{onClick:()=>_(f?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:f?"var(--hub-surface)":"transparent",border:"1px solid "+(f?"var(--hub-line)":"transparent"),color:f?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(rs,{icon:C}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),n&&n.connected&&e.jsxs("button",{onClick:()=>_(R==="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:R==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(R==="cost"?"var(--hub-line)":"transparent"),color:R==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:r("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:r("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ie(n.exposed),"/",ie(n.gross)]})]}),e.jsxs("div",{className:"ml-auto max-w-full flex-shrink-0 flex items-center justify-end gap-1.5 flex-wrap",children:[e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:Fe,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Fe)},title:r("common.copyUrl"),children:e.jsx(xe,{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:Re,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:i=>{i.stopPropagation(),Oe(Re)},title:r("common.copyOpenApiUrl"),children:e.jsx(xe,{size:12})})]})]})]}),R==="cost"&&(n==null?void 0:n.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...n.items].sort((i,f)=>f.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:ie(i.cost)})]},`${i.kind}:${i.name}`))}),R==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,f)=>{var C;return e.jsx(lt,{server:s.name,tool:i,readOnly:!G,onToggle:ws,onDescriptionUpdate:Ss,cost:(C=n==null?void 0:n.items.find(U=>U.kind==="tool"&&U.name===i.name))==null?void 0:C.cost},f)})}),R==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,f)=>{var C;return e.jsx(mt,{server:s.name,prompt:i,readOnly:!G,onToggle:ks,onDescriptionUpdate:Es,cost:(C=n==null?void 0:n.items.find(U=>U.kind==="prompt"&&U.name===i.name))==null?void 0:C.cost},f)})}),R==="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:r("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,f)=>{var C;return e.jsx(pt,{resource:i,readOnly:!G,onToggle:Cs,onDescriptionUpdate:Ds,cost:(C=n==null?void 0:n.items.find(U=>U.kind==="resource"&&U.name===i.uri))==null?void 0:C.cost},`${i.uri}-${f}`)})})})]})]}),e.jsx(Qs,{isOpen:W,onClose:()=>O(!1),onConfirm:()=>{t(s.name),O(!1)},serverName:s.name}),e.jsx(De,{isOpen:B,onClose:()=>I(!1),onConfirm:()=>{I(!1),Ce()},title:r("server.reinstall"),message:r("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:r("server.reinstall"),variant:"warning"}),e.jsx(De,{isOpen:H,onClose:()=>q(!1),onConfirm:()=>{q(!1),pe()},title:r("server.disconnectOAuth"),message:r("server.disconnectOAuthConfirm")||"This will revoke stored OAuth credentials where supported and require authorization again.",confirmText:r("server.disconnectOAuth"),variant:"warning"})]})},vt=({onAdd:s})=>{const{t:n}=te(),[t,a]=u.useState(!1),[x,d]=u.useState(null),[o,y]=u.useState(!1),[N,D]=u.useState(null),[r,p]=u.useState([]),$=()=>{a(!t),d(null),y(!1),D(null)},g=async()=>{N&&(await F(N),y(!1),D(null))},F=async E=>{try{d(null);const k=await le("/servers",E);if(!k.success){k&&k.message?d(k.message):d(n("server.addError"));return}a(!1),s()}catch(k){console.error("Error adding server:",k),navigator.onLine?k instanceof TypeError&&(k.message.includes("NetworkError")||k.message.includes("Failed to fetch"))?d(n("errors.serverConnection")):d(n("errors.serverAdd")):d(n("errors.network"))}},w=async E=>{try{const k=et(E);k.length>0?(p(k),D(E),y(!0)):await F(E)}catch(k){console.error("Error processing server submission:",k),d(n("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:$,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")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(us,{onSubmit:w,onCancel:$,modalTitle:n("server.addServer"),formError:x})}),o&&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 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:[n("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:r.map((E,k)=>e.jsxs("li",{className:"font-mono",children:["$",`{${E}}`]},k))})]})]})}),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:()=>{y(!1),D(null)},className:"hub-btn",children:n("common.cancel")}),e.jsx("button",{onClick:g,className:"hub-btn primary",children:n("server.confirmAndAdd")})]})]})})]})},Nt=({server:s,onEdit:n,onCancel:t})=>{const{t:a}=te(),[x,d]=u.useState(null),o=async y=>{try{d(null);const N=encodeURIComponent(s.name),D=y.name&&y.name!==s.name,r={config:y.config,...D?{newName:y.name}:{}},p=await ve(`/servers/${N}`,r);if(!p.success){p&&p.message?d(p.message):d(a("server.updateError",{serverName:s.name}));return}n()}catch(N){console.error("Error updating server:",N),navigator.onLine?N instanceof TypeError&&(N.message.includes("NetworkError")||N.message.includes("Failed to fetch"))?d(a("errors.serverConnection")):d(a("errors.serverUpdate",{serverName:s.name})):d(a("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(us,{onSubmit:o,onCancel:t,initialData:s,modalTitle:a("server.editTitle",{serverName:s.name}),formError:x})})},wt=({onSuccess:s,onCancel:n})=>{const{t}=te(),[a,x]=u.useState(!1),[d,o]=u.useState(!1),[y,N]=u.useState(null),[D,r]=u.useState(null),[p,$]=u.useState(!1),[g,F]=u.useState(null),[w,E]=u.useState(""),[k,R]=u.useState(!1),[_,W]=u.useState(""),O=l=>{l.preventDefault(),x(!0)},B=l=>{l.preventDefault(),x(!1)},I=l=>{l.preventDefault(),x(!1);const h=l.dataTransfer.files;if(h.length>0){const c=h[0];c.name.endsWith(".mcpb")?(r(c),N(null)):N(t("mcpb.invalidFileType"))}},H=l=>{const h=l.target.files;if(h&&h.length>0){const c=h[0];c.name.endsWith(".mcpb")?(r(c),N(null)):N(t("mcpb.invalidFileType"))}},q=async()=>{if(!D){N(t("mcpb.noFileSelected"));return}o(!0),N(null);try{const l=new FormData;l.append("mcpbFile",D);const h=await Os(_s("/mcpb/upload"),{method:"POST",body:l}),c=await h.json();if(!h.ok)throw new Error(c.message||`HTTP error! Status: ${h.status}`);if(c.success&&c.data)F(c.data.manifest),E(c.data.extractDir),$(!0);else throw new Error(c.message||t("mcpb.uploadFailed"))}catch(l){console.error("MCPB upload error:",l),N(l instanceof Error?l.message:t("mcpb.uploadFailed"))}finally{o(!1)}},Y=async(l,h=!1)=>{var c;o(!0),N(null);try{const v=j(g,w,l);if(!h){const T=await Rs("/servers");if(T.success&&((c=T.data)==null?void 0:c.find(L=>L.name===l))){W(l),R(!0),o(!1);return}}let P;if(h?P=await ve(`/servers/${encodeURIComponent(l)}`,{name:l,config:v}):P=await le("/servers",{name:l,config:v}),P.success)s(v);else throw new Error(P.message||t("mcpb.installFailed"))}catch(v){console.error("MCPB install error:",v),N(v instanceof Error?v.message:t("mcpb.installFailed")),o(!1)}},b=()=>{R(!1),_&&Y(_,!0)},m=()=>{R(!1),W(""),o(!1)},j=(l,h,c)=>{var T;const v=((T=l.server)==null?void 0:T.mcp_config)||{},P={type:"stdio",command:v.command||"node",args:(v.args||[]).map(A=>A.replace("${__dirname}",h))};return v.env&&Object.keys(v.env).length>0&&(P.env={...v.env},Object.keys(P.env).forEach(A=>{typeof P.env[A]=="string"&&(P.env[A]=P.env[A].replace("${__dirname}",h))})),P};return p&&g?e.jsxs(e.Fragment,{children:[e.jsx(De,{isOpen:k,onClose:m,onConfirm:b,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:_}),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 ${k?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),y&&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:y})}),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"),":"]})," ",g.display_name||g.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",g.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",g.description]}),g.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",g.author.name]}),g.tools&&g.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:g.tools.map((l,h)=>e.jsxs("li",{children:[l.name," - ",l.description]},h))})]})]})]}),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:g.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:d,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const l=document.getElementById("serverName"),h=(l==null?void 0:l.value.trim())||g.name;Y(h)},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:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),y&&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:y})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${a?"border-blue-500 bg-blue-50":D?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:O,onDragLeave:B,onDrop:I,children:[D?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:D.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(D.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:H,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:d,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:q,disabled:!D||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")})]})]})})},kt=["sse","streamable-http"],Ct=new Set(["type","url","command","args","env","headers","options","openapi","oauth","enabled","visibility","keepAliveInterval","enableKeepAlive","perSessionClient","tools","prompts","passthroughHeaders","proxy"]),St=s=>{const n=[],t=[];for(const[a,x]of Object.entries(s.mcpServers)){const d=x??{},o={},y=Object.keys(d).filter(N=>!Ct.has(N));if(y.length>0){t.push({name:a,message:`unknown field(s) "${y.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(o.type=d.type,o.url=d.url,d.headers&&(o.headers=d.headers),d.oauth&&(o.oauth=d.oauth),!d.url){t.push({name:a,message:`"${d.type}" servers require a "url" field.`});continue}}else if(d.type==="openapi")o.type="openapi",o.openapi=d.openapi;else if(d.type===void 0||d.type==="stdio"){if(d.url&&!d.command){t.push({name:a,message:`has a "url" but type "${d.type??"stdio"}". Use "streamable-http" or "sse" for remote servers.`});continue}if(o.type="stdio",o.command=d.command,o.args=d.args||[],d.env&&(o.env=d.env),d.options&&(o.options=d.options),!d.command){t.push({name:a,message:'stdio servers require a "command" field.'});continue}}else{const N=kt.includes(String(d.type))?"":' Did you mean "streamable-http"? Supported types: stdio, sse, streamable-http, openapi.';t.push({name:a,message:`unsupported type "${d.type}".${N}`});continue}n.push({name:a,config:o})}return{servers:n,issues:t}},Et=({onSuccess:s,onCancel:n})=>{const{t}=te(),[a,x]=u.useState(""),[d,o]=u.useState(null),[y,N]=u.useState(!1),[D,r]=u.useState(null),p=`{
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.`,$=w=>{try{const E=JSON.parse(w.trim());return!E.mcpServers||typeof E.mcpServers!="object"?(o(t("jsonImport.invalidFormat")),null):E}catch{return o(t("jsonImport.parseError")),null}},g=()=>{o(null);const w=$(a);if(!w)return;const{servers:E,issues:k}=St(w);if(k.length>0){const R=k.map(_=>`${_.name}: ${_.message}`).join(`
35
- `);if(o(t("jsonImport.validationErrors")+`
36
- `+R),E.length===0)return}r(E)},F=async()=>{if(D){N(!0),o(null);try{const w=await le("/servers/batch",{servers:D});if(w.success&&w.data){const{successCount:E,failureCount:k,results:R}=w.data;if(k>0){const _=R.filter(W=>!W.success).map(W=>`${W.name}: ${W.message||t("jsonImport.addFailed")}`);o(t("jsonImport.partialSuccess",{count:E,total:D.length})+`
37
- `+_.join(`
38
- `))}E>0&&s()}else o(w.message||t("jsonImport.importFailed"))}catch(w){console.error("Import error:",w),o(t("jsonImport.importFailed"))}finally{N(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),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})}),D?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:D.map((w,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:w.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"),":"]})," ",w.config.type||"stdio"]}),w.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",w.config.command]}),w.config.args&&w.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",w.config.args.join(" ")]}),w.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",w.config.url]}),w.config.env&&Object.keys(w.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(w.config.env).join(", ")]}),w.config.headers&&Object.keys(w.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(w.config.headers).join(", ")]})]})]})})},E))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>r(null),disabled:y,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:F,disabled:y,className:"hub-btn primary",children:y?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:a,onChange:w=>x(w.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:p}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:g,disabled:!a.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Dt=s=>({all:s.length,online:s.filter(n=>n.status==="connected").length,issues:s.filter(n=>n.status!=="connected"&&n.enabled!==!1).length,disabled:s.filter(n=>n.enabled===!1).length}),Pt=(s,n,t="")=>{const a=t.trim().toLowerCase();return s.filter(x=>{var o,y;return n==="online"&&x.status!=="connected"||n==="issues"&&(x.status==="connected"||x.enabled===!1)||n==="disabled"&&x.enabled!==!1?!1:a?(x.name+" "+(((o=x.config)==null?void 0:o.description)||"")+" "+(((y=x.tools)==null?void 0:y.map(N=>N.name).join(" "))||"")).toLowerCase().includes(a):!0})},zt=(s,n,t,a,x)=>{const d=Pt(s,n,t),o=d.length,y=Math.max(1,Math.ceil(o/x)),N=Math.min(Math.max(1,a),y),D=(N-1)*x;return{servers:d.slice(D,D+x),pagination:{page:N,limit:x,total:o,totalPages:y,hasNextPage:N<y,hasPrevPage:N>1}}},Wt=()=>{const{t:s}=te(),n=Is(),{servers:t,allServers:a,error:x,setError:d,isLoading:o,currentPage:y,serversPerPage:N,setCurrentPage:D,setServersPerPage:r,handleServerAdd:p,handleServerEdit:$,handleServerRemove:g,handleServerToggle:F,handleServerVisibilityChange:w,handleServerReload:E,handleServerReinstall:k,handleServerOAuthDisconnect:R,triggerRefresh:_}=tt({refreshOnMount:!0}),{serverCosts:W,refetch:O}=rt();u.useEffect(()=>{O()},[t,O]);const[B,I]=u.useState(null),[H,q]=u.useState(!1),[Y,b]=u.useState(!1),[m,j]=u.useState(!1),[l,h]=u.useState("all"),[c,v]=u.useState(""),P=u.useMemo(()=>Dt(a),[a]),{servers:T,pagination:A}=u.useMemo(()=>zt(a,l,c,y,N),[a,l,c,y,N]);u.useEffect(()=>{A.page!==y&&D(A.page)},[A.page,y,D]);const L=async M=>{const S=await $(M);S&&I(S)},Q=async()=>{q(!0);try{_(),await new Promise(M=>setTimeout(M,400))}finally{q(!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:P.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:P.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:P.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>n("/market"),children:[e.jsx(Hs,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>j(!0),children:[e.jsx(Gs,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>b(!0),children:[e.jsx(Ys,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:Q,disabled:H,"aria-label":s("common.refresh"),children:[e.jsx(je,{size:13,className:H?"animate-spin":""}),s("common.refresh")]}),e.jsx(vt,{onAdd:p})]})]}),x&&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(we,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:x})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>d(null),"aria-label":s("app.closeButton"),children:e.jsx(Ee,{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",P.all],["online",s("status.online"),P.online],["issues",s("common.inactive")||"Issues",P.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",P.disabled]].map(([M,S,J])=>e.jsxs("button",{onClick:()=>h(M),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:l===M?"var(--hub-bg-2)":"transparent",color:l===M?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(l===M?"var(--hub-line)":"transparent")},children:[S,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:J})]},M))}),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(Xs,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:c,onChange:M=>v(M.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:()=>v(""),className:"hub-icon-btn sm",children:e.jsx(Ee,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[A.total,"/",a.length]})]}),o&&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(je,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):T.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:T.map(M=>e.jsx(jt,{server:M,cost:W.find(S=>S.name===M.name),onRemove:g,onEdit:L,onToggle:F,onVisibilityChange:w,onRefresh:_,onReload:E,onReinstall:k,onOAuthDisconnect:R},M.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:(A.page-1)*A.limit+1,end:Math.min(A.page*A.limit,A.total),total:A.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:A.totalPages>1&&e.jsx(st,{currentPage:A.page,totalPages:A.totalPages,onPageChange:D,disabled:o})}),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:N,onChange:M=>r(Number(M.target.value)),disabled:o,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"})]})]})]})]}),B&&e.jsx(Nt,{server:B,onEdit:()=>{I(null),_()},onCancel:()=>I(null)}),Y&&e.jsx(wt,{onSuccess:()=>{b(!1),_()},onCancel:()=>b(!1)}),m&&e.jsx(Et,{onSuccess:()=>{j(!1),_()},onCancel:()=>j(!1)})]})};export{Wt as default};
39
- //# sourceMappingURL=ServersPage-DAmKvrPV.js.map