@samanhappy/mcphub 1.0.12 → 1.0.14

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 (62) hide show
  1. package/dist/controllers/changelogController.js +26 -0
  2. package/dist/controllers/changelogController.js.map +1 -0
  3. package/dist/routes/index.js +3 -0
  4. package/dist/routes/index.js.map +1 -1
  5. package/dist/services/changelogService.js +121 -0
  6. package/dist/services/changelogService.js.map +1 -0
  7. package/dist/services/sseService.js +85 -132
  8. package/dist/services/sseService.js.map +1 -1
  9. package/frontend/dist/assets/{ActivityPage-BPfkCkM3.js → ActivityPage-BOpR9H2i.js} +2 -2
  10. package/frontend/dist/assets/{ActivityPage-BPfkCkM3.js.map → ActivityPage-BOpR9H2i.js.map} +1 -1
  11. package/frontend/dist/assets/{Dashboard-BvEkS4H1.js → Dashboard-C_-XmWQD.js} +2 -2
  12. package/frontend/dist/assets/{Dashboard-BvEkS4H1.js.map → Dashboard-C_-XmWQD.js.map} +1 -1
  13. package/frontend/dist/assets/{EndpointCopy-KhSo4Y6F.js → EndpointCopy-8kX4-19c.js} +2 -2
  14. package/frontend/dist/assets/{EndpointCopy-KhSo4Y6F.js.map → EndpointCopy-8kX4-19c.js.map} +1 -1
  15. package/frontend/dist/assets/{GroupsPage-CLkFTxqd.js → GroupsPage-htoQ6Qs0.js} +2 -2
  16. package/frontend/dist/assets/{GroupsPage-CLkFTxqd.js.map → GroupsPage-htoQ6Qs0.js.map} +1 -1
  17. package/frontend/dist/assets/{LoginPage-lM-z_O3X.js → LoginPage-aPFHvaWh.js} +2 -2
  18. package/frontend/dist/assets/{LoginPage-lM-z_O3X.js.map → LoginPage-aPFHvaWh.js.map} +1 -1
  19. package/frontend/dist/assets/{LogsPage-CS9OFma4.js → LogsPage-Chwx1nBj.js} +2 -2
  20. package/frontend/dist/assets/{LogsPage-CS9OFma4.js.map → LogsPage-Chwx1nBj.js.map} +1 -1
  21. package/frontend/dist/assets/{MarketPage-9LSDiVvR.js → MarketPage-AeI9OXrF.js} +3 -3
  22. package/frontend/dist/assets/{MarketPage-9LSDiVvR.js.map → MarketPage-AeI9OXrF.js.map} +1 -1
  23. package/frontend/dist/assets/PromptsPage-B4hqDzUf.js +2 -0
  24. package/frontend/dist/assets/{PromptsPage-CPFRMMgV.js.map → PromptsPage-B4hqDzUf.js.map} +1 -1
  25. package/frontend/dist/assets/ResourcesPage-D6Pjuosf.js +2 -0
  26. package/frontend/dist/assets/{ResourcesPage-DJ_7k1MF.js.map → ResourcesPage-D6Pjuosf.js.map} +1 -1
  27. package/frontend/dist/assets/ServersPage-CUIUW61l.js +37 -0
  28. package/frontend/dist/assets/ServersPage-CUIUW61l.js.map +1 -0
  29. package/frontend/dist/assets/{SettingsPage-CyYl7pb8.js → SettingsPage-BhlkLfh2.js} +2 -2
  30. package/frontend/dist/assets/{SettingsPage-CyYl7pb8.js.map → SettingsPage-BhlkLfh2.js.map} +1 -1
  31. package/frontend/dist/assets/{StatusDot-CZZGigtR.js → StatusDot-DeAk18AU.js} +2 -2
  32. package/frontend/dist/assets/{StatusDot-CZZGigtR.js.map → StatusDot-DeAk18AU.js.map} +1 -1
  33. package/frontend/dist/assets/ToggleGroup-B4Kg4S_t.js +2 -0
  34. package/frontend/dist/assets/ToggleGroup-B4Kg4S_t.js.map +1 -0
  35. package/frontend/dist/assets/{UsersPage-CLXhNpvg.js → UsersPage-DW6DqEcG.js} +2 -2
  36. package/frontend/dist/assets/{UsersPage-CLXhNpvg.js.map → UsersPage-DW6DqEcG.js.map} +1 -1
  37. package/frontend/dist/assets/{contextCost-mvvSAnFv.js → contextCost-Cy6hGdzI.js} +2 -2
  38. package/frontend/dist/assets/{contextCost-mvvSAnFv.js.map → contextCost-Cy6hGdzI.js.map} +1 -1
  39. package/frontend/dist/assets/{icons-vendor-IYX_ppgH.js → icons-vendor-BTEm6PQs.js} +65 -55
  40. package/frontend/dist/assets/icons-vendor-BTEm6PQs.js.map +1 -0
  41. package/frontend/dist/assets/index-Btd1KKSH.js +3 -0
  42. package/frontend/dist/assets/index-Btd1KKSH.js.map +1 -0
  43. package/frontend/dist/assets/index-H0KbCXxe.css +1 -0
  44. package/frontend/dist/assets/{resourceService-jx5dJGUy.js → resourceService-BECsvcJr.js} +2 -2
  45. package/frontend/dist/assets/{resourceService-jx5dJGUy.js.map → resourceService-BECsvcJr.js.map} +1 -1
  46. package/frontend/dist/assets/useSettingsData-ClhR9PBd.js +2 -0
  47. package/frontend/dist/assets/{useSettingsData-B4hMPWdK.js.map → useSettingsData-ClhR9PBd.js.map} +1 -1
  48. package/frontend/dist/assets/{variableDetection-Dnh8qFpO.js → variableDetection-hIevXYOZ.js} +2 -2
  49. package/frontend/dist/assets/{variableDetection-Dnh8qFpO.js.map → variableDetection-hIevXYOZ.js.map} +1 -1
  50. package/frontend/dist/index.html +3 -3
  51. package/package.json +2 -1
  52. package/frontend/dist/assets/PromptsPage-CPFRMMgV.js +0 -2
  53. package/frontend/dist/assets/ResourcesPage-DJ_7k1MF.js +0 -2
  54. package/frontend/dist/assets/ServersPage-BtPOdp4X.js +0 -37
  55. package/frontend/dist/assets/ServersPage-BtPOdp4X.js.map +0 -1
  56. package/frontend/dist/assets/ToggleGroup-C24CNPSz.js +0 -2
  57. package/frontend/dist/assets/ToggleGroup-C24CNPSz.js.map +0 -1
  58. package/frontend/dist/assets/icons-vendor-IYX_ppgH.js.map +0 -1
  59. package/frontend/dist/assets/index-D8V2fxz_.css +0 -1
  60. package/frontend/dist/assets/index-DRcTlhkb.js +0 -3
  61. package/frontend/dist/assets/index-DRcTlhkb.js.map +0 -1
  62. package/frontend/dist/assets/useSettingsData-B4hMPWdK.js +0 -2
@@ -0,0 +1,37 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-BECsvcJr.js","./index-Btd1KKSH.js","./framework-vendor-DeqnZ0v6.js","./i18n-vendor-DP1IRITP.js","./icons-vendor-BTEm6PQs.js","./index-H0KbCXxe.css"])))=>i.map(i=>d[i]);
2
+ import{r as d,j as e,d as cs}from"./framework-vendor-DeqnZ0v6.js";import{e as ae,f as He,h as ve,i as Se,u as ds,_ as fe,j as us,k as ms,l as ps}from"./index-Btd1KKSH.js";import{f as ne,u as xs,a as hs}from"./contextCost-Cy6hGdzI.js";import{S as bs}from"./StatusDot-DeAk18AU.js";import{u as Ee}from"./useSettingsData-ClhR9PBd.js";import{S as Ne}from"./ToggleGroup-B4Kg4S_t.js";import{u as ee}from"./i18n-vendor-DP1IRITP.js";import{n as Ke,o as Ge,l as we,p as gs,C as me,q as ye,r as Pe,s as Xe,t as Ye,u as ze,m as ke,W as fs,g as ys,F as js,X as Ce,E as vs,v as Ns,R as je,T as ws,P as ks,w as Cs,x as Ss,y as Es}from"./icons-vendor-BTEm6PQs.js";import{D as Ps}from"./DeleteDialog-BBfJpiiD.js";import{S as Ze,d as zs}from"./variableDetection-hIevXYOZ.js";import{C as Ts}from"./ConfirmDialog-Cag_haxr.js";import{P as Ds}from"./Pagination-DBAu79mv.js";const Qe=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await ae(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return n.success===!1?{success:!1,error:n.message||"Tool call failed"}:{success:!0,content:(n==null?void 0:n.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},$s=async(s,r,t)=>{try{const n=await ae(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},es=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ss=async(s,r)=>{var t;try{const n=await He(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting tool description",{serverName:s,toolName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Fs=Object.freeze(Object.defineProperty({__proto__:null,callTool:Qe,resetToolDescription:ss,toggleTool:$s,updateToolDescription:es},Symbol.toStringTag,{value:"Module"})),ts=({schema:s,onSubmit:r,onCancel:t,loading:n=!1,storageKey:h,title:y})=>{const{t:a}=ee(),[v,o]=d.useState({}),[f,u]=d.useState({}),[E,T]=d.useState(!1),[N,D]=d.useState(""),[k,C]=d.useState(""),P=d.useMemo(()=>(m=>{const j=l=>{if(typeof l=="object"&&l!==null){const p=l;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([c,b])=>[c,j(b)])):void 0,required:p.required,items:p.items?j(p.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([l,p])=>[l,j(p)])):void 0,required:m.required}})(s),[s]);d.useEffect(()=>{const x=(j,l="")=>{const p={};return j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,b])=>{const I=l?`${l}.${c}`:c;b.default!==void 0?p[c]=b.default:b.type==="string"?p[c]="":b.type==="number"||b.type==="integer"?p[c]=0:b.type==="boolean"?p[c]=!1:b.type==="array"?p[c]=[]:b.type==="object"&&(b.properties?p[c]=x(b,I):p[c]={})}),p};let m=x(P);if(h)try{const j=localStorage.getItem(h);if(j){const l=JSON.parse(j);m={...m,...l}}}catch(j){console.warn("Failed to load saved form data:",j)}o(m)},[P,h]),d.useEffect(()=>{E&&Object.keys(v).length>0&&(D(JSON.stringify(v,null,2)),C(""))},[E,v]);const A=x=>{D(x),C("");try{const m=JSON.parse(x);if(o(m),h)try{localStorage.setItem(h,JSON.stringify(m))}catch(j){console.warn("Failed to save form data to localStorage:",j)}}catch{C(a("tool.invalidJsonFormat"))}},V=()=>{D(JSON.stringify(v,null,2)),C(""),T(!0)},U=()=>{if(N.trim())try{const x=JSON.parse(N);o(x),C(""),T(!1)}catch{C(a("tool.fixJsonBeforeSwitching"));return}else T(!1)},F=(x,m)=>{o(j=>{const l={...j},p=x.split(".");let c=l;for(let b=0;b<p.length-1;b++)c[p[b]]||(c[p[b]]={}),c=c[p[b]];if(c[p[p.length-1]]=m,h)try{localStorage.setItem(h,JSON.stringify(l))}catch(b){console.warn("Failed to save form data to localStorage:",b)}return l}),f[x]&&u(j=>{const l={...j};return delete l[x],l})},J=()=>{const x={},m=(j,l,p="")=>{j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,b])=>{var q;const I=p?`${p}.${c}`:c,R=l==null?void 0:l[c];if((q=j.required)!=null&&q.includes(c)&&(R==null||R===""||Array.isArray(R)&&R.length===0)){x[I]=`${c} is required`;return}R!=null&&R!==""&&(b.type==="string"&&typeof R!="string"?x[I]=`${c} must be a string`:b.type==="number"&&typeof R!="number"?x[I]=`${c} must be a number`:b.type==="integer"&&(!Number.isInteger(R)||typeof R!="number")?x[I]=`${c} must be an integer`:b.type==="boolean"&&typeof R!="boolean"?x[I]=`${c} must be a boolean`:b.type==="array"&&Array.isArray(R)?b.items&&R.forEach((_,K)=>{var Z;((Z=b.items)==null?void 0:Z.type)==="object"&&b.items.properties&&m(b.items,_,`${I}.${K}`)}):b.type==="object"&&typeof R=="object"&&m(b,R,I))})};return m(P,v),u(x),Object.keys(x).length===0},$=x=>{x.preventDefault(),J()&&r(v)},L=(x,m)=>m.split(".").reduce((j,l)=>j==null?void 0:j[l],x),H=(x,m,j,l)=>{const p=j==null?void 0:j[x];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",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:a("tool.selectOption")}),m.enum.map((c,b)=>e.jsx("option",{value:c,children:c},b))]}):e.jsx("input",{type:"text",value:p||"",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||a("tool.enterKey",{key:x})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:c=>{const b=c.target.value===""?"":m.type==="integer"?parseInt(c.target.value):parseFloat(c.target.value);l(b)},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:p||!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:p||"",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||a("tool.enterKey",{key:x})})},Y=(x,m,j="")=>{var b,I,R,q,_,K,Z,z,B,w,W,oe,le,ce;const l=j?`${j}.${x}`:x,p=L(v,l),c=f[l];if(m.type==="array"){const O=L(v,l)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(j?(I=(b=L(P,j))==null?void 0:b.required)==null?void 0:I.includes(x):(R=P.required)==null?void 0:R.includes(x))&&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:[O.map((X,Q)=>{var pe,xe,he;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a("tool.item",{index:Q+1})}),e.jsx("button",{type:"button",onClick:()=>{const G=[...O];G.splice(Q,1),F(l,G)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((pe=m.items)==null?void 0:pe.type)==="string"&&m.items.enum?e.jsxs("select",{value:X||"",onChange:G=>{const se=[...O];se[Q]=G.target.value,F(l,se)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.items.enum.map((G,se)=>e.jsx("option",{value:G,children:G},se))]}):((xe=m.items)==null?void 0:xe.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([G,se])=>{var be,ue;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[G,((ue=(be=m.items)==null?void 0:be.required)==null?void 0:ue.includes(G))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),H(G,se,X,ge=>{const re=[...O];re[Q]={...re[Q],[G]:ge},F(l,re)})]},G)})}):e.jsx("input",{type:"text",value:X||"",onChange:G=>{const se=[...O];se[Q]=G.target.value,F(l,se)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:a("tool.enterValue",{type:((he=m.items)==null?void 0:he.type)||"value"})})]},Q)}),e.jsx("button",{type:"button",onClick:()=>{var Q;const X=((Q=m.items)==null?void 0:Q.type)==="object"?{}:"";F(l,[...O,X])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:a("tool.addItem",{key:x})})]}),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:[x,(j?(_=(q=L(P,j))==null?void 0:q.required)==null?void 0:_.includes(x):(K=P.required)==null?void 0:K.includes(x))&&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(([O,X])=>Y(O,X,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:[x,(j?(z=(Z=L(P,j))==null?void 0:Z.required)==null?void 0:z.includes(x):(B=P.required)==null?void 0:B.includes(x))&&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 p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:O=>{try{const X=JSON.parse(O.target.value);F(l,X)}catch{F(l,O.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:[x,(j?!1:(w=P.required)==null?void 0:w.includes(x))&&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:p||"",onChange:O=>F(l,O.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:a("tool.selectOption")}),m.enum.map((O,X)=>e.jsx("option",{value:O,children:O},X))]}),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:[x,(j?!1:(W=P.required)==null?void 0:W.includes(x))&&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:p||"",onChange:O=>F(l,O.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:[x,(j?!1:(oe=P.required)==null?void 0:oe.includes(x))&&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:p??"",onChange:O=>{const X=O.target.value===""?"":m.type==="integer"?parseInt(O.target.value):parseFloat(O.target.value);F(l,X)},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:p||!1,onChange:O=>F(l,O.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:[x,(j?!1:(le=P.required)==null?void 0:le.includes(x))&&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:[x,(j?!1:(ce=P.required)==null?void 0:ce.includes(x))&&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:p||"",onChange:O=>F(l,O.target.value),placeholder:a("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 P.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:y}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:U,className:`hub-btn sm ${E?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:V,className:`hub-btn sm ${E?"primary":""}`,children:a("tool.jsonMode")})]})]}),E?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("tool.jsonConfiguration")}),e.jsx("textarea",{value:N,onChange:x=>A(x.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 ${k?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),k&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:k})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const x=JSON.parse(N);r(x)}catch{C(a("tool.invalidJsonFormat"))}},disabled:n||!!k,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[Object.entries(P.properties||{}).map(([x,m])=>Y(x,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:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:n,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>r({}),disabled:n,className:"hub-btn primary",children:a(n?"tool.running":"tool.runTool")})]})]})},Is=({result:s,onClose:r})=>{const{t}=ee(),n=s.content,h=u=>u?u.startsWith("image/")?u:`image/${u}`:"image/png",y=u=>{if(!u)return[];if(Array.isArray(u))return u.flatMap(N=>y(N));if(typeof u!="object")return[];const E=[];u.type==="image"&&u.data&&E.push({data:String(u.data),mimeType:h(u.mimeType||u.mime_type)});const T=u.image_base64||u.imageBase64||u.image_data||u.imageData||u.base64;return T&&E.push({data:String(T),mimeType:h(u.image_mimeType||u.image_mime_type||u.mimeType||u.mime_type)}),u.image&&typeof u.image=="object"&&E.push(...y(u.image)),Array.isArray(u.images)&&E.push(...y(u.images)),Array.isArray(u.content)&&E.push(...y(u.content)),E},a=u=>{const E=[];try{const D=JSON.parse(u);if(E.push(...y(D)),E.length>0)return E}catch{}const T=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let N;for(;(N=T.exec(u))!==null;){const D=`image/${N[1]==="jpg"?"jpeg":N[1]}`;E.push({data:N[2],mimeType:D})}return E},v=u=>{try{const E=JSON.parse(u),T=N=>{if(Array.isArray(N))return N.map(T);if(N&&typeof N=="object"){const D={};for(const[k,C]of Object.entries(N))typeof C=="string"&&k.toLowerCase().includes("base64")?D[k]="[base64 omitted]":D[k]=T(C);return D}return N};return JSON.stringify(T(E),null,2)}catch{return u.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},o=u=>Array.isArray(u)?u.map((E,T)=>e.jsx("div",{className:"mb-3 last:mb-0",children:f(E)},T)):f(u),f=u=>{if(typeof u=="string"){const E=a(u),T=v(u);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[E.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:E.map((N,D)=>e.jsx("img",{src:`data:${N.mimeType||"image/png"};base64,${N.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},D))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(typeof u=="object"&&u!==null){if(u.type==="text"&&u.text){const E=a(u.text),T=v(u.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[E.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:E.map((N,D)=>e.jsx("img",{src:`data:${N.mimeType||"image/png"};base64,${N.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},D))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(u.type==="image"&&u.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${u.mimeType||"image/png"};base64,${u.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const E=typeof u=="string"?JSON.parse(u):u;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(E,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(u)})})}}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(u)})})};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(Ke,{size:20,className:"text-status-green"}):e.jsx(Ge,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),o(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")})]}),n&&n.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),o(n)]}):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")})})]})})]})},de=({title:s,onClick:r,disabled:t=!1,loading:n=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:r,disabled:t,title:s,"aria-label":s,children:e.jsx(gs,{size:14,className:n?"animate-spin":""})});function Rs(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 _s=({tool:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:y})=>{const{t:a}=ee(),{showToast:v}=Se(),{nameSeparator:o}=Ee(),[f,u]=d.useState(!1),[E,T]=d.useState(!1),[N,D]=d.useState(!1),[k,C]=d.useState(null),[P,A]=d.useState(!1),[V,U]=d.useState(!1),[F,J]=d.useState(s.description||""),$=d.useRef(null),L=d.useRef(null),[H,Y]=d.useState(0),[x,m]=d.useState(!1);d.useEffect(()=>{P&&$.current&&($.current.focus(),H>0&&($.current.style.width=`${H+20}px`))},[P,H]),d.useEffect(()=>{!P&&L.current&&Y(L.current.offsetWidth)},[P,F]),d.useEffect(()=>{J(s.description||"")},[s.description]);const j=s.name.replace(r+o,""),l=d.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),p=d.useCallback(()=>{localStorage.removeItem(l())},[l]),c=w=>{!t&&n&&n(s.name,w)},b=()=>{t||A(!0)},I=async()=>{if(!t)try{const w=await es(r,s.name,F);w.success?(A(!1),h&&h(s.name,F)):(J(s.description||""),console.error("Failed to update tool description:",w.error))}catch(w){console.error("Error updating tool description:",w),J(s.description||""),A(!1)}},R=w=>{J(w.target.value)},q=async()=>{if(!t){U(!0);try{const w=await ss(r,s.name);if(w.success){const W=w.description||"";J(W),A(!1),h==null||h(s.name,W,{restored:!0})}else v(w.error||a("tool.restoreDefaultFailed"),"error")}catch(w){console.error("Error resetting tool description:",w),v(a("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},_=w=>{w.key==="Enter"?I():w.key==="Escape"&&(J(s.description||""),A(!1))},K=async w=>{w.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),v(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const W=document.createElement("textarea");W.value=s.name,W.style.position="fixed",W.style.left="-9999px",document.body.appendChild(W),W.focus(),W.select();try{document.execCommand("copy"),m(!0),v(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(oe){v(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",oe)}document.body.removeChild(W)}}catch(W){v(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",W)}},Z=async w=>{D(!0);try{w=Object.fromEntries(Object.entries(w).filter(([oe,le])=>!Rs(le)));const W=await Qe({toolName:s.name,arguments:w},r);C(W)}catch(W){C({success:!1,error:W instanceof Error?W.message:"Unknown error occurred"})}finally{D(!1)}},z=()=>{T(!1),p(),C(null)},B=()=>{C(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:w=>{w.stopPropagation(),u(!f)},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:K,title:a("common.copy"),children:x?e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:P?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:$,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:F,onChange:R,onKeyDown:_,onClick:w=>w.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),I()},disabled:V,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),q()},disabled:V,loading:V})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:L,children:F||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),b()},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:w=>{w.stopPropagation(),q()},disabled:V,loading:V})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[y!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ne(y)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:w=>w.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:c,disabled:N||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${j}`})}),e.jsxs("button",{onClick:w=>{w.stopPropagation(),u(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:N||!s.enabled,children:[N?e.jsx(Xe,{size:12,className:"animate-spin"}):e.jsx(Ye,{size:12}),e.jsx("span",{children:a(N?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:f?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),f&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[!E&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),E&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:s.inputSchema||{type:"object"},onSubmit:Z,onCancel:z,loading:N,storageKey:l(),title:a("tool.runToolWithName",{name:j})}),k&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Is,{result:k,onClose:B})})]})]})]})},As=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",n=await ae(t,{promptName:s.promptName,arguments:s.arguments});return n.success?{success:!0,data:n.data}:{success:!1,error:n.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},rs=async(s,r)=>{try{const t=await ae(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Os=async(s,r,t)=>{try{const n=await ae(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ns=async(s,r,t)=>{try{const n=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},as=async(s,r)=>{var t;try{const n=await He(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message,description:(t=n.data)==null?void 0:t.description}}catch(n){return console.error("Error resetting prompt description",{serverName:s,promptName:r,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Ms=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:As,getPrompt:rs,resetPromptDescription:as,togglePrompt:Os,updatePromptDescription:ns},Symbol.toStringTag,{value:"Module"})),Ue=({result:s,onClose:r})=>{const{t}=ee(),n=h=>{if(typeof h=="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:h})});if(typeof h=="object"&&h!==null){if(h.description||h.messages)return e.jsxs("div",{className:"space-y-4",children:[h.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:h.description})})]}),h.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:h.messages.map((y,a)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"flex items-center mb-2",children:e.jsxs("span",{className:"inline-block w-16 text-xs font-medium text-gray-500",children:[y.role,":"]})}),typeof y.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:y.content}):typeof y.content=="object"&&y.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:y.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(y.content,null,2)})]},a))})]})]});try{const y=typeof h=="string"?JSON.parse(h):h;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(y,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(h)})})}}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(h)})})};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(Ke,{size:20,className:"text-status-green"}):e.jsx(Ge,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),n(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(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")})})]})})]})},Vs=({prompt:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:y})=>{const{t:a}=ee(),{showToast:v}=Se(),{nameSeparator:o}=Ee(),[f,u]=d.useState(!1),[E,T]=d.useState(!1),[N,D]=d.useState(!1),[k,C]=d.useState(null),[P,A]=d.useState(!1),[V,U]=d.useState(!1),[F,J]=d.useState(s.description||""),$=d.useRef(null),L=d.useRef(null),[H,Y]=d.useState(0);d.useEffect(()=>{P&&$.current&&($.current.focus(),H>0&&($.current.style.width=`${H+20}px`))},[P,H]),d.useEffect(()=>{!P&&L.current&&Y(L.current.offsetWidth)},[P,F]),d.useEffect(()=>{J(s.description||"")},[s.description]);const x=d.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),m=d.useCallback(()=>{localStorage.removeItem(x())},[x]),j=z=>{!t&&n&&n(s.name,z)},l=()=>{t||A(!0)},p=async()=>{if(!t){A(!1);try{const z=await ns(r,s.name,F);z.success?h&&h(s.name,F):(v(z.error||a("prompt.descriptionUpdateFailed"),"error"),J(s.description||""))}catch(z){console.error("Error updating prompt description:",z),v(a("prompt.descriptionUpdateFailed"),"error"),J(s.description||"")}}},c=async()=>{if(!t){U(!0);try{const z=await as(r,s.name);if(z.success){const B=z.description||"";J(B),A(!1),h==null||h(s.name,B,{restored:!0})}else v(z.error||a("prompt.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting prompt description:",z),v(a("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},b=z=>{J(z.target.value)},I=z=>{z.key==="Enter"?p():z.key==="Escape"&&(J(s.description||""),A(!1))},R=async z=>{D(!0);try{const B=await rs({promptName:s.name,arguments:z},r);console.log("GetPrompt result:",B),C({success:B.success,data:B.data,error:B.error})}catch(B){C({success:!1,error:B instanceof Error?B.message:"Unknown error occurred"})}finally{D(!1)}},q=()=>{T(!1),m(),C(null)},_=()=>{C(null)},K=s.name.replace(r+o,""),Z=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const z={},B=[];return s.arguments.forEach(w=>{z[w.name]={type:"string",description:w.description||""},w.required&&B.push(w.name)}),{type:"object",properties:z,required:B}};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:()=>u(!f),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:K}),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:P?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:$,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:F,onChange:b,onKeyDown:I,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),p()},disabled:V,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),c()},disabled:V,loading:V})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:L,children:F||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),l()},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:z=>{z.stopPropagation(),c()},disabled:V,loading:V})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[y!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ne(y)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ne,{checked:s.enabled,onCheckedChange:j,disabled:N||t,size:"card","aria-label":`${a(s.enabled?"server.disable":"server.enable")} ${K}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),u(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:N||!s.enabled,children:[N?e.jsx(Xe,{size:12,className:"animate-spin"}):e.jsx(Ye,{size:12}),e.jsx("span",{children:a(N?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:f?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),f&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[E&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:Z(),onSubmit:R,onCancel:q,loading:N,storageKey:x(),title:a("prompt.runPromptWithName",{name:K})}),k&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ue,{result:k,onClose:_})})]}),!E&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((z,B)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:z.name}),z.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),z.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:z.description})]}),z.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:z.title})]},B))})]}),!E&&k&&e.jsx("div",{children:e.jsx(Ue,{result:k,onClose:_})})]})]})},Js=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:n,cost:h})=>{const{t:y}=ee(),[a,v]=d.useState(!1),[o,f]=d.useState(!1),[u,E]=d.useState(!1),[T,N]=d.useState(s.description||""),D=d.useRef(null),k=d.useRef(null),[C,P]=d.useState(0);d.useEffect(()=>{o&&D.current&&(D.current.focus(),C>0&&(D.current.style.width=`${C+20}px`))},[o,C]),d.useEffect(()=>{!o&&k.current&&P(k.current.offsetWidth)},[o,T]),d.useEffect(()=>{N(s.description||"")},[s.description]);const A=s.name||s.uri,V=$=>{!r&&t&&t(s.uri,$)},U=async()=>{r||(f(!1),n&&await n(s.uri,T))},F=async()=>{if(!r){E(!0);try{await(n==null?void 0:n(s.uri,"",{restored:!0})),f(!1)}finally{E(!1)}}},J=$=>{$.key==="Enter"?U():$.key==="Escape"&&(N(s.description||""),f(!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:()=>v(!a),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:A}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:o?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:D,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:C>0?`${C+20}px`:160,minWidth:80},value:T,onChange:$=>N($.target.value),onKeyDown:J,onClick:$=>$.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:$=>{$.stopPropagation(),U()},disabled:u,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:y("builtinResources.restoreDefault"),onClick:$=>{$.stopPropagation(),F()},disabled:u,loading:u})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:k,children:T||y("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:$=>{$.stopPropagation(),f(!0)},children:e.jsx(Pe,{size:12})}),e.jsx(de,{title:y("builtinResources.restoreDefault"),onClick:$=>{$.stopPropagation(),F()},disabled:u,loading:u})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[h!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:y("cost.estimate"),children:["Σ ",ne(h)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:$=>$.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled!==!1,onCheckedChange:V,disabled:r,size:"card","aria-label":`${y(s.enabled!==!1?"server.disable":"server.enable")} ${A}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),a&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[y("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Us=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,Bs={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:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",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)]"}},Te=s=>s==="public"||s==="group"?s:"private",Ws=(s,r)=>{const t=Te(r),n=Bs[t];return{value:t,shortLabel:s(n.shortKey,{defaultValue:n.shortFallback}),longLabel:s(n.longKey,{defaultValue:n.longFallback}),className:n.className}},Ls=(s,r)=>{const t=Te(r),n=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&n.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),n.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),n},Be=({isLoading:s,children:r,className:t,overlayStyle:n,spinnerSize:h=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:r}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...n},children:e.jsx(je,{size:h,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),We=({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"})}),Le=(s,r)=>r?r==="stdio"?s("server.typeStdio")||"stdio":r==="sse"?s("server.typeSse")||"sse":r==="streamable-http"?s("server.typeStreamableHttp")||"http":r==="openapi"?s("server.typeOpenapi")||"openapi":r:null,qs="text/html;profile=mcp-app",qe=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Hs=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(n=>qe(n._meta))||(t=s.resources)!=null&&t.some(n=>{var h;return((h=n.uri)==null?void 0:h.startsWith("ui://"))||n.mimeType===qs||qe(n._meta)}))},Ks=({server:s,cost:r,onRemove:t,onEdit:n,onToggle:h,onVisibilityChange:y,onRefresh:a,onReload:v})=>{var $e,Fe,Ie,Re,_e,Ae,Oe,Me,Ve,Je;const{t:o}=ee(),{showToast:f}=Se(),{exportMCPSettings:u,installConfig:E}=Ee(),{auth:T}=ds(),N=(($e=E==null?void 0:E.baseUrl)==null?void 0:$e.replace(/\/+$/,""))||"",[D,k]=d.useState(!1),[C,P]=d.useState(null),[A,V]=d.useState(!1),[U,F]=d.useState(!1),[J,$]=d.useState(!1),[L,H]=d.useState(!1),[Y,x]=d.useState(!1),[m,j]=d.useState(!1),[l,p]=d.useState(!1),c=d.useRef(null),b=d.useRef(null);d.useEffect(()=>{const i=g=>{c.current&&!c.current.contains(g.target)&&x(!1),b.current&&!b.current.contains(g.target)&&j(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const I=((Fe=s.tools)==null?void 0:Fe.length)||0,R=((Ie=s.tools)==null?void 0:Ie.filter(i=>i.enabled!==!1).length)||0,q=((Re=s.prompts)==null?void 0:Re.length)||0,_=((_e=s.prompts)==null?void 0:_e.filter(i=>i.enabled!==!1).length)||0,K=((Ae=s.resources)==null?void 0:Ae.length)||0,Z=((Oe=s.resources)==null?void 0:Oe.filter(i=>i.enabled!==!1).length)||0,z=Hs(s),B=s.enabled!==!1,w=Us(s,T.user),W=async i=>{if(!(!w||U||!h)){F(!0);try{await h(s,i)}finally{F(!1)}}},oe=async i=>{if(i.stopPropagation(),x(!1),!(!w||L||!v)){H(!0);try{await v(s)?f(o("server.reloadSuccess")||"Server reloaded successfully","success"):f(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{H(!1)}}},le=async i=>{var S;if(i.stopPropagation(),!w||J||!y)return;const g=i.target.value;if(g!==Te(s.visibility??((S=s.config)==null?void 0:S.visibility))){$(!0);try{await y(s,g)}finally{$(!1)}}},ce=async i=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(i),!0}catch{}try{const g=document.createElement("textarea");g.value=i,g.style.position="fixed",g.style.left="-9999px",document.body.appendChild(g),g.focus(),g.select();const S=document.execCommand("copy");return document.body.removeChild(g),S}catch{return!1}},O=async i=>{if(i.stopPropagation(),!s.error)return;await ce(s.error)?(p(!0),f(o("common.copySuccess")||"Copied","success"),setTimeout(()=>p(!1),1500)):f(o("common.copyFailed")||"Copy failed","error")},X=async i=>{if(i.stopPropagation(),x(!1),!!w)try{const g=await u(s.name);if(!g||!g.success||!g.data){f((g==null?void 0:g.message)||o("common.copyFailed")||"Copy failed","error");return}const S=JSON.stringify(g.data,null,2),M=await ce(S);f(M?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Copy failed",M?"success":"error")}catch(g){console.error("Error copying server configuration:",g),f(o("common.copyFailed")||"Copy failed","error")}},Q=i=>{var g;if(i.stopPropagation(),(g=s.oauth)!=null&&g.authorizationUrl){const te=window.screen.width/2-300,ie=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${te},top=${ie}`),f(o("status.oauthWindowOpened"),"info")}},pe=async(i,g)=>{try{const{toggleTool:S}=await fe(async()=>{const{toggleTool:te}=await Promise.resolve().then(()=>Fs);return{toggleTool:te}},void 0,import.meta.url),M=await S(s.name,i,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),f(o("tool.toggleFailed"),"error")}},xe=async(i,g)=>{try{const{togglePrompt:S}=await fe(async()=>{const{togglePrompt:te}=await Promise.resolve().then(()=>Ms);return{togglePrompt:te}},void 0,import.meta.url),M=await S(s.name,i,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),f(o("tool.toggleFailed"),"error")}},he=async(i,g)=>{try{const{toggleResource:S}=await fe(async()=>{const{toggleResource:te}=await import("./resourceService-BECsvcJr.js");return{toggleResource:te}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),M=await S(s.name,i,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(S){console.error(S),f(o("tool.toggleFailed"),"error")}},G=(i,g,S)=>{f(S!=null&&S.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),a==null||a()},se=(i,g,S)=>{f(S!=null&&S.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),a==null||a()},be=async(i,g,S)=>{try{const{updateResourceDescription:M,resetResourceDescription:te}=await fe(async()=>{const{updateResourceDescription:is,resetResourceDescription:ls}=await import("./resourceService-BECsvcJr.js");return{updateResourceDescription:is,resetResourceDescription:ls}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ie=S!=null&&S.restored?await te(s.name,i):await M(s.name,i,g);ie.success?(f(S!=null&&S.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),a==null||a()):f(ie.error||(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(M){console.error(M),f(S!=null&&S.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var S;const i=s.config;if(!i)return"";if(i.url)return i.url;const g=[];return i.command&&g.push(i.command),(S=i.args)!=null&&S.length&&g.push(...i.args),g.join(" ")})();const ue=`${N}/mcp/${s.name}`,ge=(i,g)=>o(i,g),re=Ws(ge,s.visibility??((Me=s.config)==null?void 0:Me.visibility)),os=Ls(ge,re.value),De=[{key:"tools",icon:fs,total:I,enabled:R,label:o("server.tools")},{key:"prompts",icon:ys,total:q,enabled:_,label:o("server.prompts")},{key:"resources",icon:js,total:K,enabled:Z,label:o("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>k(!D),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:D?"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:B?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),z&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:b,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),j(g=>!g)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(we,{size:14})}),m&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:o("server.errorDetails")}),e.jsx("button",{onClick:O,className:"hub-icon-btn sm",title:o("common.copy"),children:l?e.jsx(me,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>j(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(Ce,{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})})]})]})]}),((Ve=s.config)==null?void 0:Ve.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:"min-w-0",children:e.jsx(bs,{status:s.status,enabled:s.enabled,onAuthClick:Q,className:"hub-server-card-status"})}),e.jsx("div",{className:"min-w-0",children:(Je=s.config)!=null&&Je.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Le(o,s.config.type)??void 0,children:Le(o,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:w&&y?e.jsx(Be,{isLoading:J,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:re.value,onChange:le,disabled:J,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":o("server.visibility","Visibility"),title:re.longLabel,children:os.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] ${re.className}`,title:re.longLabel,children:re.shortLabel})}),De.map(({key:i,icon:g,total:S,enabled:M,label:te})=>{const ie=S===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${ie?"is-empty":""}`,title:`${te}: ${M}/${S}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(We,{icon:g})}),e.jsx("span",{className:"hub-server-capability-value",children:ie?"0":`${M}/${S}`})]},i)}),r&&r.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${r.exposed} / ${o("cost.gross")} ${r.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ne(r.exposed),"/",ne(r.gross)]})]}):r?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:o("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:i=>i.stopPropagation(),children:e.jsx(Be,{isLoading:U,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ne,{checked:B,onCheckedChange:W,disabled:U||!w,size:"compact","aria-label":`${o(B?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:c,children:[w&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),x(g=>!g)},"aria-label":"More",children:e.jsx(vs,{size:14})}),w&&Y&&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(),x(!1),n(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(Ns,{size:13})," ",o("server.edit")]}),e.jsxs("button",{onClick:X,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),v&&e.jsxs("button",{onClick:oe,disabled:L||U||!B,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})," ",o("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),x(!1),V(!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(ws,{size:13})," ",o("server.delete")]})]})]})]}),D&&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:[De.map(i=>{const g=C===i.key,S=i.icon;return e.jsxs("button",{onClick:()=>P(g?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:g?"var(--hub-surface)":"transparent",border:"1px solid "+(g?"var(--hub-line)":"transparent"),color:g?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(We,{icon:S}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),r&&r.connected&&e.jsxs("button",{onClick:()=>P(C==="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:C==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(C==="cost"?"var(--hub-line)":"transparent"),color:C==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:o("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:o("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ne(r.exposed),"/",ne(r.gross)]})]}),e.jsx("div",{className:"ml-auto max-w-full flex-shrink-0",children:e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:ue,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async i=>{i.stopPropagation();const g=await ce(ue);f(g?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",g?"success":"error")},title:o("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),C==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((i,g)=>g.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:ne(i.cost)})]},`${i.kind}:${i.name}`))}),C==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,g)=>{var S;return e.jsx(_s,{server:s.name,tool:i,readOnly:!w,onToggle:pe,onDescriptionUpdate:G,cost:(S=r==null?void 0:r.items.find(M=>M.kind==="tool"&&M.name===i.name))==null?void 0:S.cost},g)})}),C==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,g)=>{var S;return e.jsx(Vs,{server:s.name,prompt:i,readOnly:!w,onToggle:xe,onDescriptionUpdate:se,cost:(S=r==null?void 0:r.items.find(M=>M.kind==="prompt"&&M.name===i.name))==null?void 0:S.cost},g)})}),C==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:o("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,g)=>{var S;return e.jsx(Js,{resource:i,readOnly:!w,onToggle:he,onDescriptionUpdate:be,cost:(S=r==null?void 0:r.items.find(M=>M.kind==="resource"&&M.name===i.uri))==null?void 0:S.cost},`${i.uri}-${g}`)})})})]})]}),e.jsx(Ps,{isOpen:A,onClose:()=>V(!1),onConfirm:()=>{t(s.name),V(!1)},serverName:s.name})]})},Gs=({onAdd:s})=>{const{t:r}=ee(),[t,n]=d.useState(!1),[h,y]=d.useState(null),[a,v]=d.useState(!1),[o,f]=d.useState(null),[u,E]=d.useState([]),T=()=>{n(!t),y(null),v(!1),f(null)},N=async()=>{o&&(await D(o),v(!1),f(null))},D=async C=>{try{y(null);const P=await ae("/servers",C);if(!P.success){P&&P.message?y(P.message):y(r("server.addError"));return}n(!1),s()}catch(P){console.error("Error adding server:",P),navigator.onLine?P instanceof TypeError&&(P.message.includes("NetworkError")||P.message.includes("Failed to fetch"))?y(r("errors.serverConnection")):y(r("errors.serverAdd")):y(r("errors.network"))}},k=async C=>{try{const P=zs(C);P.length>0?(E(P),f(C),v(!0)):await D(C)}catch(P){console.error("Error processing server submission:",P),y(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:T,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ze,{onSubmit:k,onCancel:T,modalTitle:r("server.addServer"),formError:h})}),a&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 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:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:u.map((C,P)=>e.jsxs("li",{className:"font-mono",children:["$",`{${C}}`]},P))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{v(!1),f(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:N,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},Xs=({server:s,onEdit:r,onCancel:t})=>{const{t:n}=ee(),[h,y]=d.useState(null),a=async v=>{try{y(null);const o=encodeURIComponent(s.name),f=v.name&&v.name!==s.name,u={config:v.config,...f?{newName:v.name}:{}},E=await ve(`/servers/${o}`,u);if(!E.success){E&&E.message?y(E.message):y(n("server.updateError",{serverName:s.name}));return}r()}catch(o){console.error("Error updating server:",o),navigator.onLine?o instanceof TypeError&&(o.message.includes("NetworkError")||o.message.includes("Failed to fetch"))?y(n("errors.serverConnection")):y(n("errors.serverUpdate",{serverName:s.name})):y(n("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ze,{onSubmit:a,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:h})})},Ys=({onSuccess:s,onCancel:r})=>{const{t}=ee(),[n,h]=d.useState(!1),[y,a]=d.useState(!1),[v,o]=d.useState(null),[f,u]=d.useState(null),[E,T]=d.useState(!1),[N,D]=d.useState(null),[k,C]=d.useState(""),[P,A]=d.useState(!1),[V,U]=d.useState(""),F=l=>{l.preventDefault(),h(!0)},J=l=>{l.preventDefault(),h(!1)},$=l=>{l.preventDefault(),h(!1);const p=l.dataTransfer.files;if(p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},L=l=>{const p=l.target.files;if(p&&p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},H=async()=>{if(!f){o(t("mcpb.noFileSelected"));return}a(!0),o(null);try{const l=new FormData;l.append("mcpbFile",f);const p=await ms(ps("/mcpb/upload"),{method:"POST",body:l}),c=await p.json();if(!p.ok)throw new Error(c.message||`HTTP error! Status: ${p.status}`);if(c.success&&c.data)D(c.data.manifest),C(c.data.extractDir),T(!0);else throw new Error(c.message||t("mcpb.uploadFailed"))}catch(l){console.error("MCPB upload error:",l),o(l instanceof Error?l.message:t("mcpb.uploadFailed"))}finally{a(!1)}},Y=async(l,p=!1)=>{var c;a(!0),o(null);try{const b=j(N,k,l);if(!p){const R=await us("/servers");if(R.success&&((c=R.data)==null?void 0:c.find(_=>_.name===l))){U(l),A(!0),a(!1);return}}let I;if(p?I=await ve(`/servers/${encodeURIComponent(l)}`,{name:l,config:b}):I=await ae("/servers",{name:l,config:b}),I.success)s(b);else throw new Error(I.message||t("mcpb.installFailed"))}catch(b){console.error("MCPB install error:",b),o(b instanceof Error?b.message:t("mcpb.installFailed")),a(!1)}},x=()=>{A(!1),V&&Y(V,!0)},m=()=>{A(!1),U(""),a(!1)},j=(l,p,c)=>{var R;const b=((R=l.server)==null?void 0:R.mcp_config)||{},I={type:"stdio",command:b.command||"node",args:(b.args||[]).map(q=>q.replace("${__dirname}",p))};return b.env&&Object.keys(b.env).length>0&&(I.env={...b.env},Object.keys(I.env).forEach(q=>{typeof I.env[q]=="string"&&(I.env[q]=I.env[q].replace("${__dirname}",p))})),I};return E&&N?e.jsxs(e.Fragment,{children:[e.jsx(Ts,{isOpen:P,onClose:m,onConfirm:x,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:V}),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 ${P?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),v&&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:v})}),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"),":"]})," ",N.display_name||N.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",N.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",N.description]}),N.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",N.author.name]}),N.tools&&N.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:N.tools.map((l,p)=>e.jsxs("li",{children:[l.name," - ",l.description]},p))})]})]})]}),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:N.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:y,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const l=document.getElementById("serverName"),p=(l==null?void 0:l.value.trim())||N.name;Y(p)},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("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),v&&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:v})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${n?"border-blue-500 bg-blue-50":f?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:F,onDragLeave:J,onDrop:$,children:[f?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:f.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(f.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:L,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:y,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:H,disabled:!f||y,className:"hub-btn primary flex items-center",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("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Zs=s=>Object.entries(s.mcpServers).map(([r,t])=>{const n={};return t.type==="sse"||t.type==="streamable-http"?(n.type=t.type,n.url=t.url,t.headers&&(n.headers=t.headers)):t.type==="openapi"?(n.type="openapi",n.openapi=t.openapi):(n.type="stdio",n.command=t.command,n.args=t.args||[],t.env&&(n.env=t.env),t.options&&(n.options=t.options)),{name:r,config:n}}),Qs=({onSuccess:s,onCancel:r})=>{const{t}=ee(),[n,h]=d.useState(""),[y,a]=d.useState(null),[v,o]=d.useState(!1),[f,u]=d.useState(null),E=`{
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.`,T=k=>{try{const C=JSON.parse(k.trim());return!C.mcpServers||typeof C.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):C}catch{return a(t("jsonImport.parseError")),null}},N=()=>{a(null);const k=T(n);k&&u(Zs(k))},D=async()=>{if(f){o(!0),a(null);try{const k=await ae("/servers/batch",{servers:f});if(k.success&&k.data){const{successCount:C,failureCount:P,results:A}=k.data;if(P>0){const V=A.filter(U=>!U.success).map(U=>`${U.name}: ${U.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:C,total:f.length})+`
35
+ `+V.join(`
36
+ `))}C>0&&s()}else a(k.message||t("jsonImport.importFailed"))}catch(k){console.error("Import error:",k),a(t("jsonImport.importFailed"))}finally{o(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),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 whitespace-pre-wrap",children:y})}),f?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:f.map((k,C)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:k.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"),":"]})," ",k.config.type||"stdio"]}),k.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",k.config.command]}),k.config.args&&k.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",k.config.args.join(" ")]}),k.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",k.config.url]}),k.config.env&&Object.keys(k.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(k.config.env).join(", ")]}),k.config.headers&&Object.keys(k.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(k.config.headers).join(", ")]})]})]})})},C))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>u(null),disabled:v,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:D,disabled:v,className:"hub-btn primary",children:v?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:n,onChange:k=>h(k.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:E}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:N,disabled:!n.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},et=s=>({all:s.length,online:s.filter(r=>r.status==="connected").length,issues:s.filter(r=>r.status!=="connected"&&r.enabled!==!1).length,disabled:s.filter(r=>r.enabled===!1).length}),st=(s,r,t="")=>{const n=t.trim().toLowerCase();return s.filter(h=>{var a,v;return r==="online"&&h.status!=="connected"||r==="issues"&&(h.status==="connected"||h.enabled===!1)||r==="disabled"&&h.enabled!==!1?!1:n?(h.name+" "+(((a=h.config)==null?void 0:a.description)||"")+" "+(((v=h.tools)==null?void 0:v.map(o=>o.name).join(" "))||"")).toLowerCase().includes(n):!0})},xt=()=>{const{t:s}=ee(),r=cs(),{servers:t,allServers:n,error:h,setError:y,isLoading:a,pagination:v,currentPage:o,serversPerPage:f,setCurrentPage:u,setServersPerPage:E,handleServerAdd:T,handleServerEdit:N,handleServerRemove:D,handleServerToggle:k,handleServerVisibilityChange:C,handleServerReload:P,triggerRefresh:A}=xs({refreshOnMount:!0}),{serverCosts:V,refetch:U}=hs();d.useEffect(()=>{U()},[t,U]);const[F,J]=d.useState(null),[$,L]=d.useState(!1),[H,Y]=d.useState(!1),[x,m]=d.useState(!1),[j,l]=d.useState("all"),[p,c]=d.useState(""),b=d.useMemo(()=>et(n),[n]),I=d.useMemo(()=>st(t,j,p),[t,j,p]),R=async _=>{const K=await N(_);K&&J(K)},q=async()=>{L(!0);try{A(),await new Promise(_=>setTimeout(_,400))}finally{L(!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:b.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:b.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:b.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>r("/market"),children:[e.jsx(ks,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>m(!0),children:[e.jsx(Cs,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>Y(!0),children:[e.jsx(Ss,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:q,disabled:$,"aria-label":s("common.refresh"),children:[e.jsx(je,{size:13,className:$?"animate-spin":""}),s("common.refresh")]}),e.jsx(Gs,{onAdd:T})]})]}),h&&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:h})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>y(null),"aria-label":s("app.closeButton"),children:e.jsx(Ce,{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",b.all],["online",s("status.online"),b.online],["issues",s("common.inactive")||"Issues",b.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",b.disabled]].map(([_,K,Z])=>e.jsxs("button",{onClick:()=>l(_),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:j===_?"var(--hub-bg-2)":"transparent",color:j===_?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(j===_?"var(--hub-line)":"transparent")},children:[K,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:Z})]},_))}),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(Es,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:p,onChange:_=>c(_.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),p&&e.jsx("button",{onClick:()=>c(""),className:"hub-icon-btn sm",children:e.jsx(Ce,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[I.length,"/",t.length]})]}),a&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(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")})]})}):I.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:I.map(_=>e.jsx(Ks,{server:_,cost:V.find(K=>K.name===_.name),onRemove:D,onEdit:R,onToggle:k,onVisibilityChange:C,onRefresh:A,onReload:P},_.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:v?s("common.showing",{start:(v.page-1)*v.limit+1,end:Math.min(v.page*v.limit,v.total),total:v.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:v&&v.totalPages>1&&e.jsx(Ds,{currentPage:o,totalPages:v.totalPages,onPageChange:u,disabled:a})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s("common.itemsPerPage"),":"]}),e.jsxs("select",{id:"perPage",value:f,onChange:_=>E(Number(_.target.value)),disabled:a,className:"hub-input",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})]}),F&&e.jsx(Xs,{server:F,onEdit:()=>{J(null),A()},onCancel:()=>J(null)}),H&&e.jsx(Ys,{onSuccess:()=>{Y(!1),A()},onCancel:()=>Y(!1)}),x&&e.jsx(Qs,{onSuccess:()=>{m(!1),A()},onCancel:()=>m(!1)})]})};export{xt as default};
37
+ //# sourceMappingURL=ServersPage-CUIUW61l.js.map