@samanhappy/mcphub 1.0.16 → 1.0.18
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.
- package/dist/betterAuth.js +2 -2
- package/dist/betterAuth.js.map +1 -1
- package/dist/cli/commands/cache.js +39 -0
- package/dist/cli/commands/cache.js.map +1 -0
- package/dist/cli/commands/servers.js +14 -0
- package/dist/cli/commands/servers.js.map +1 -1
- package/dist/cli/help.js +11 -2
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +1 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/controllers/groupController.js +66 -2
- package/dist/controllers/groupController.js.map +1 -1
- package/dist/controllers/serverController.js +62 -1
- package/dist/controllers/serverController.js.map +1 -1
- package/dist/db/entities/Group.js.map +1 -1
- package/dist/middlewares/auth.js +20 -7
- package/dist/middlewares/auth.js.map +1 -1
- package/dist/routes/index.js +3 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/services/groupService.js +25 -0
- package/dist/services/groupService.js.map +1 -1
- package/dist/services/mcpService.js +270 -25
- package/dist/services/mcpService.js.map +1 -1
- package/dist/services/smartRoutingService.js +63 -12
- package/dist/services/smartRoutingService.js.map +1 -1
- package/dist/utils/cacheUtils.js +110 -0
- package/dist/utils/cacheUtils.js.map +1 -0
- package/frontend/dist/assets/{ActivityPage-BYPkr9n2.js → ActivityPage-C36IBbnj.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-BYPkr9n2.js.map → ActivityPage-C36IBbnj.js.map} +1 -1
- package/frontend/dist/assets/{ConfirmDialog-Cag_haxr.js → ConfirmDialog-BKNVI65J.js} +2 -2
- package/frontend/dist/assets/{ConfirmDialog-Cag_haxr.js.map → ConfirmDialog-BKNVI65J.js.map} +1 -1
- package/frontend/dist/assets/{Dashboard-BbGvQMHv.js → Dashboard-BsUNNsqb.js} +2 -2
- package/frontend/dist/assets/{Dashboard-BbGvQMHv.js.map → Dashboard-BsUNNsqb.js.map} +1 -1
- package/frontend/dist/assets/{DeleteDialog-BBfJpiiD.js → DeleteDialog-7NPk3Hro.js} +2 -2
- package/frontend/dist/assets/{DeleteDialog-BBfJpiiD.js.map → DeleteDialog-7NPk3Hro.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-DhPgdjmi.js → EndpointCopy-eF3xFbaZ.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-DhPgdjmi.js.map → EndpointCopy-eF3xFbaZ.js.map} +1 -1
- package/frontend/dist/assets/GroupsPage-Dp-NU5wZ.js +33 -0
- package/frontend/dist/assets/GroupsPage-Dp-NU5wZ.js.map +1 -0
- package/frontend/dist/assets/{LoginPage-2PH92kBp.js → LoginPage-9PIMlvGe.js} +2 -2
- package/frontend/dist/assets/{LoginPage-2PH92kBp.js.map → LoginPage-9PIMlvGe.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-D8ws1iFm.js → LogsPage-C8WS43Dw.js} +2 -2
- package/frontend/dist/assets/{LogsPage-D8ws1iFm.js.map → LogsPage-C8WS43Dw.js.map} +1 -1
- package/frontend/dist/assets/{MarketPage-BL9qUEMR.js → MarketPage-Cyl5VvwI.js} +2 -2
- package/frontend/dist/assets/{MarketPage-BL9qUEMR.js.map → MarketPage-Cyl5VvwI.js.map} +1 -1
- package/frontend/dist/assets/{Pagination-DBAu79mv.js → Pagination-DAcOi8eq.js} +2 -2
- package/frontend/dist/assets/{Pagination-DBAu79mv.js.map → Pagination-DAcOi8eq.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-CtXO4diZ.js → PromptsPage-CqxKWAR9.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-CtXO4diZ.js.map → PromptsPage-CqxKWAR9.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-GD-T8LpP.js → ResourcesPage-Dq7Grza0.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-GD-T8LpP.js.map → ResourcesPage-Dq7Grza0.js.map} +1 -1
- package/frontend/dist/assets/ServersPage-xt7QkwjZ.js +37 -0
- package/frontend/dist/assets/ServersPage-xt7QkwjZ.js.map +1 -0
- package/frontend/dist/assets/SettingsPage-Cn5Krvgb.js +12 -0
- package/frontend/dist/assets/SettingsPage-Cn5Krvgb.js.map +1 -0
- package/frontend/dist/assets/{StatusDot-Bp40buM9.js → StatusDot-DAStUyI3.js} +2 -2
- package/frontend/dist/assets/{StatusDot-Bp40buM9.js.map → StatusDot-DAStUyI3.js.map} +1 -1
- package/frontend/dist/assets/{ToggleGroup-B15lxnw6.js → ToggleGroup-CQvqGQLA.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-B15lxnw6.js.map → ToggleGroup-CQvqGQLA.js.map} +1 -1
- package/frontend/dist/assets/{UsersPage-Cv80MtZ4.js → UsersPage-Bsa2NGcJ.js} +2 -2
- package/frontend/dist/assets/{UsersPage-Cv80MtZ4.js.map → UsersPage-Bsa2NGcJ.js.map} +1 -1
- package/frontend/dist/assets/{contextCost-DldRDO4O.js → contextCost-DrQqHXcP.js} +2 -2
- package/frontend/dist/assets/{contextCost-DldRDO4O.js.map → contextCost-DrQqHXcP.js.map} +1 -1
- package/frontend/dist/assets/framework-vendor-X-WP1v0m.js +61 -0
- package/frontend/dist/assets/framework-vendor-X-WP1v0m.js.map +1 -0
- package/frontend/dist/assets/{i18n-vendor-DP1IRITP.js → i18n-vendor-BLr2MLKp.js} +2 -2
- package/frontend/dist/assets/{i18n-vendor-DP1IRITP.js.map → i18n-vendor-BLr2MLKp.js.map} +1 -1
- package/frontend/dist/assets/{icons-vendor-BTEm6PQs.js → icons-vendor-DMtsx1SI.js} +63 -58
- package/frontend/dist/assets/icons-vendor-DMtsx1SI.js.map +1 -0
- package/frontend/dist/assets/{index-D1-Bdpe1.css → index-BlTPJflb.css} +1 -1
- package/frontend/dist/assets/index-BsgjLwhT.js +3 -0
- package/frontend/dist/assets/index-BsgjLwhT.js.map +1 -0
- package/frontend/dist/assets/{resourceService-CN0gM37U.js → resourceService-Bg941cnv.js} +2 -2
- package/frontend/dist/assets/{resourceService-CN0gM37U.js.map → resourceService-Bg941cnv.js.map} +1 -1
- package/frontend/dist/assets/useSettingsData-BwKohDXD.js +2 -0
- package/frontend/dist/assets/{useSettingsData-DewLOhzu.js.map → useSettingsData-BwKohDXD.js.map} +1 -1
- package/frontend/dist/assets/{variableDetection-hIevXYOZ.js → variableDetection-Bp_stsiy.js} +2 -2
- package/frontend/dist/assets/{variableDetection-hIevXYOZ.js.map → variableDetection-Bp_stsiy.js.map} +1 -1
- package/frontend/dist/index.html +5 -5
- package/package.json +13 -12
- package/frontend/dist/assets/GroupsPage-BC9FlhX4.js +0 -33
- package/frontend/dist/assets/GroupsPage-BC9FlhX4.js.map +0 -1
- package/frontend/dist/assets/ServersPage-CXUBWjQO.js +0 -37
- package/frontend/dist/assets/ServersPage-CXUBWjQO.js.map +0 -1
- package/frontend/dist/assets/SettingsPage-C5tAS-rd.js +0 -12
- package/frontend/dist/assets/SettingsPage-C5tAS-rd.js.map +0 -1
- package/frontend/dist/assets/framework-vendor-DeqnZ0v6.js +0 -61
- package/frontend/dist/assets/framework-vendor-DeqnZ0v6.js.map +0 -1
- package/frontend/dist/assets/icons-vendor-BTEm6PQs.js.map +0 -1
- package/frontend/dist/assets/index-OwXusZPZ.js +0 -3
- package/frontend/dist/assets/index-OwXusZPZ.js.map +0 -1
- package/frontend/dist/assets/useSettingsData-DewLOhzu.js +0 -2
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-CN0gM37U.js","./index-OwXusZPZ.js","./framework-vendor-DeqnZ0v6.js","./i18n-vendor-DP1IRITP.js","./icons-vendor-BTEm6PQs.js","./index-D1-Bdpe1.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 ie,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-OwXusZPZ.js";import{f as oe,u as xs,a as hs}from"./contextCost-DldRDO4O.js";import{S as bs}from"./StatusDot-Bp40buM9.js";import{u as Ee}from"./useSettingsData-DewLOhzu.js";import{S as Ne}from"./ToggleGroup-B15lxnw6.js";import{u as se}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 De,s as Xe,t as Ye,u as Pe,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{g as Ds}from"./toolDescription-Dw3sa28K.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 $s}from"./Pagination-DBAu79mv.js";const Qe=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await ie(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return n.success===!1?{success:!1,error:n.message||"Tool call failed"}:{success:!0,content:(n==null?void 0:n.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Fs=async(s,r,t)=>{try{const n=await ie(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},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"}}},Is=Object.freeze(Object.defineProperty({__proto__:null,callTool:Qe,resetToolDescription:ss,toggleTool:Fs,updateToolDescription:es},Symbol.toStringTag,{value:"Module"})),ts=({schema:s,onSubmit:r,onCancel:t,loading:n=!1,storageKey:h,title:y})=>{const{t:a}=se(),[v,o]=d.useState({}),[f,u]=d.useState({}),[S,z]=d.useState(!1),[N,T]=d.useState(""),[w,k]=d.useState(""),E=d.useMemo(()=>(m=>{const j=i=>{if(typeof i=="object"&&i!==null){const p=i;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(([i,p])=>[i,j(p)])):void 0,required:m.required}})(s),[s]);d.useEffect(()=>{const x=(j,i="")=>{const p={};return j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,b])=>{const I=i?`${i}.${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(E);if(h)try{const j=localStorage.getItem(h);if(j){const i=JSON.parse(j);m={...m,...i}}}catch(j){console.warn("Failed to load saved form data:",j)}o(m)},[E,h]),d.useEffect(()=>{S&&Object.keys(v).length>0&&(T(JSON.stringify(v,null,2)),k(""))},[S,v]);const A=x=>{T(x),k("");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{k(a("tool.invalidJsonFormat"))}},V=()=>{T(JSON.stringify(v,null,2)),k(""),z(!0)},U=()=>{if(N.trim())try{const x=JSON.parse(N);o(x),k(""),z(!1)}catch{k(a("tool.fixJsonBeforeSwitching"));return}else z(!1)},F=(x,m)=>{o(j=>{const i={...j},p=x.split(".");let c=i;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(i))}catch(b){console.warn("Failed to save form data to localStorage:",b)}return i}),f[x]&&u(j=>{const i={...j};return delete i[x],i})},J=()=>{const x={},m=(j,i,p="")=>{j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([c,b])=>{var q;const I=p?`${p}.${c}`:c,R=i==null?void 0:i[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((_,G)=>{var Q;((Q=b.items)==null?void 0:Q.type)==="object"&&b.items.properties&&m(b.items,_,`${I}.${G}`)}):b.type==="object"&&typeof R=="object"&&m(b,R,I))})};return m(E,v),u(x),Object.keys(x).length===0},$=x=>{x.preventDefault(),J()&&r(v)},W=(x,m)=>m.split(".").reduce((j,i)=>j==null?void 0:j[i],x),K=(x,m,j,i)=>{const p=j==null?void 0:j[x];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",onChange:c=>i(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=>i(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);i(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=>i(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=>i(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})})},Z=(x,m,j="")=>{var b,I,R,q,_,G,Q,D,B,H,ce,P,L,ae;const i=j?`${j}.${x}`:x,p=W(v,i),c=f[i];if(m.type==="array"){const O=W(v,i)||[];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=W(E,j))==null?void 0:b.required)==null?void 0:I.includes(x):(R=E.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((Y,ee)=>{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:ee+1})}),e.jsx("button",{type:"button",onClick:()=>{const X=[...O];X.splice(ee,1),F(i,X)},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:Y||"",onChange:X=>{const te=[...O];te[ee]=X.target.value,F(i,te)},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((X,te)=>e.jsx("option",{value:X,children:X},te))]}):((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(([X,te])=>{var be,ue;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[X,((ue=(be=m.items)==null?void 0:be.required)==null?void 0:ue.includes(X))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(X,te,Y,ge=>{const ne=[...O];ne[ee]={...ne[ee],[X]:ge},F(i,ne)})]},X)})}):e.jsx("input",{type:"text",value:Y||"",onChange:X=>{const te=[...O];te[ee]=X.target.value,F(i,te)},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"})})]},ee)}),e.jsx("button",{type:"button",onClick:()=>{var ee;const Y=((ee=m.items)==null?void 0:ee.type)==="object"?{}:"";F(i,[...O,Y])},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})]},i)}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=W(E,j))==null?void 0:q.required)==null?void 0:_.includes(x):(G=E.required)==null?void 0:G.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,Y])=>Z(O,Y,i))}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},i):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(j?(D=(Q=W(E,j))==null?void 0:Q.required)==null?void 0:D.includes(x):(B=E.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 Y=JSON.parse(O.target.value);F(i,Y)}catch{F(i,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})]},i):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:(H=E.required)==null?void 0:H.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(i,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,Y)=>e.jsx("option",{value:O,children:O},Y))]}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},i):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=E.required)==null?void 0:ce.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(i,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})]},i):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:(P=E.required)==null?void 0:P.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 Y=O.target.value===""?"":m.type==="integer"?parseInt(O.target.value):parseFloat(O.target.value);F(i,Y)},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})]},i):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(i,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:(L=E.required)==null?void 0:L.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})]},i):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:(ae=E.required)==null?void 0:ae.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(i,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})]},i)};return E.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 ${S?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:V,className:`hub-btn sm ${S?"primary":""}`,children:a("tool.jsonMode")})]})]}),S?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 ${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:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const x=JSON.parse(N);r(x)}catch{k(a("tool.invalidJsonFormat"))}},disabled:n||!!w,className:"hub-btn sm primary",children:a(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[Object.entries(E.properties||{}).map(([x,m])=>Z(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")})]})]})},Rs=({result:s,onClose:r})=>{const{t}=se(),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 S=[];u.type==="image"&&u.data&&S.push({data:String(u.data),mimeType:h(u.mimeType||u.mime_type)});const z=u.image_base64||u.imageBase64||u.image_data||u.imageData||u.base64;return z&&S.push({data:String(z),mimeType:h(u.image_mimeType||u.image_mime_type||u.mimeType||u.mime_type)}),u.image&&typeof u.image=="object"&&S.push(...y(u.image)),Array.isArray(u.images)&&S.push(...y(u.images)),Array.isArray(u.content)&&S.push(...y(u.content)),S},a=u=>{const S=[];try{const T=JSON.parse(u);if(S.push(...y(T)),S.length>0)return S}catch{}const z=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let N;for(;(N=z.exec(u))!==null;){const T=`image/${N[1]==="jpg"?"jpeg":N[1]}`;S.push({data:N[2],mimeType:T})}return S},v=u=>{try{const S=JSON.parse(u),z=N=>{if(Array.isArray(N))return N.map(z);if(N&&typeof N=="object"){const T={};for(const[w,k]of Object.entries(N))typeof k=="string"&&w.toLowerCase().includes("base64")?T[w]="[base64 omitted]":T[w]=z(k);return T}return N};return JSON.stringify(z(S),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((S,z)=>e.jsx("div",{className:"mb-3 last:mb-0",children:f(S)},z)):f(u),f=u=>{if(typeof u=="string"){const S=a(u),z=v(u);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((N,T)=>e.jsx("img",{src:`data:${N.mimeType||"image/png"};base64,${N.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},T))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:z})]})}if(typeof u=="object"&&u!==null){if(u.type==="text"&&u.text){const S=a(u.text),z=v(u.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((N,T)=>e.jsx("img",{src:`data:${N.mimeType||"image/png"};base64,${N.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},T))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:z})]})}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 S=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(S,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 _s(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 Os=({tool:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:y})=>{const{t:a}=se(),{showToast:v}=Se(),{nameSeparator:o}=Ee(),[f,u]=d.useState(!1),[S,z]=d.useState(!1),[N,T]=d.useState(!1),[w,k]=d.useState(null),[E,A]=d.useState(!1),[V,U]=d.useState(!1),[F,J]=d.useState(s.description||""),$=d.useRef(null),W=d.useRef(null),[K,Z]=d.useState(0),[x,m]=d.useState(!1);d.useEffect(()=>{E&&$.current&&($.current.focus(),K>0&&($.current.style.width=`${K+20}px`))},[E,K]),d.useEffect(()=>{!E&&W.current&&Z(W.current.offsetWidth)},[E,F]),d.useEffect(()=>{J(s.description||"")},[s.description]);const j=s.name.replace(r+o,""),i=Ds(s,a("tool.noDescription")),p=i.hasDescriptionOverride?a("tool.defaultDescriptionTooltip",{description:i.defaultDescription}):void 0,c=d.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),b=d.useCallback(()=>{localStorage.removeItem(c())},[c]),I=P=>{!t&&n&&n(s.name,P)},R=()=>{t||A(!0)},q=async()=>{if(!t)try{const P=await es(r,s.name,F);P.success?(A(!1),h&&h(s.name,F)):(J(s.description||""),console.error("Failed to update tool description:",P.error))}catch(P){console.error("Error updating tool description:",P),J(s.description||""),A(!1)}},_=P=>{J(P.target.value)},G=async()=>{if(!t){U(!0);try{const P=await ss(r,s.name);if(P.success){const L=P.description||"";J(L),A(!1),h==null||h(s.name,L,{restored:!0})}else v(P.error||a("tool.restoreDefaultFailed"),"error")}catch(P){console.error("Error resetting tool description:",P),v(a("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},Q=P=>{P.key==="Enter"?q():P.key==="Escape"&&(J(s.description||""),A(!1))},D=async P=>{P.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 L=document.createElement("textarea");L.value=s.name,L.style.position="fixed",L.style.left="-9999px",document.body.appendChild(L),L.focus(),L.select();try{document.execCommand("copy"),m(!0),v(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(ae){v(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",ae)}document.body.removeChild(L)}}catch(L){v(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",L)}},B=async P=>{T(!0);try{P=Object.fromEntries(Object.entries(P).filter(([ae,O])=>!_s(O)));const L=await Qe({toolName:s.name,arguments:P},r);k(L)}catch(L){k({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{T(!1)}},H=()=>{z(!1),b(),k(null)},ce=()=>{k(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:P=>{P.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:D,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:E?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:$,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:F,onChange:_,onKeyDown:Q,onClick:P=>P.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),q()},disabled:V,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),G()},disabled:V,loading:V})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,title:p,children:i.currentDescription}),i.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:p,children:a("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),R()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:a("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),G()},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:["Σ ",oe(y)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:P=>P.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:I,disabled:N||t,size:"card","aria-label":`${a(s.enabled??!0?"server.disable":"server.enable")} ${j}`})}),e.jsxs("button",{onClick:P=>{P.stopPropagation(),u(!0),z(!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(Pe,{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:[i.hasDescriptionOverride&&i.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:a("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:i.defaultDescription})]}),!S&&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)})]}),S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:s.inputSchema||{type:"object"},onSubmit:B,onCancel:H,loading:N,storageKey:c(),title:a("tool.runToolWithName",{name:j})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Rs,{result:w,onClose:ce})})]})]})]})},As=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",n=await ie(t,{promptName:s.promptName,arguments:s.arguments});return n.success?{success:!0,data:n.data}:{success:!1,error:n.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},rs=async(s,r)=>{try{const t=await ie(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ms=async(s,r,t)=>{try{const n=await ie(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:n.success,error:n.success?void 0:n.message}}catch(n){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},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"}}},Vs=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:As,getPrompt:rs,resetPromptDescription:as,togglePrompt:Ms,updatePromptDescription:ns},Symbol.toStringTag,{value:"Module"})),Ue=({result:s,onClose:r})=>{const{t}=se(),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")})})]})})]})},Js=({prompt:s,server:r,readOnly:t=!1,onToggle:n,onDescriptionUpdate:h,cost:y})=>{const{t:a}=se(),{showToast:v}=Se(),{nameSeparator:o}=Ee(),[f,u]=d.useState(!1),[S,z]=d.useState(!1),[N,T]=d.useState(!1),[w,k]=d.useState(null),[E,A]=d.useState(!1),[V,U]=d.useState(!1),[F,J]=d.useState(s.description||""),$=d.useRef(null),W=d.useRef(null),[K,Z]=d.useState(0);d.useEffect(()=>{E&&$.current&&($.current.focus(),K>0&&($.current.style.width=`${K+20}px`))},[E,K]),d.useEffect(()=>{!E&&W.current&&Z(W.current.offsetWidth)},[E,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=D=>{!t&&n&&n(s.name,D)},i=()=>{t||A(!0)},p=async()=>{if(!t){A(!1);try{const D=await ns(r,s.name,F);D.success?h&&h(s.name,F):(v(D.error||a("prompt.descriptionUpdateFailed"),"error"),J(s.description||""))}catch(D){console.error("Error updating prompt description:",D),v(a("prompt.descriptionUpdateFailed"),"error"),J(s.description||"")}}},c=async()=>{if(!t){U(!0);try{const D=await as(r,s.name);if(D.success){const B=D.description||"";J(B),A(!1),h==null||h(s.name,B,{restored:!0})}else v(D.error||a("prompt.restoreDefaultFailed"),"error")}catch(D){console.error("Error resetting prompt description:",D),v(a("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},b=D=>{J(D.target.value)},I=D=>{D.key==="Enter"?p():D.key==="Escape"&&(J(s.description||""),A(!1))},R=async D=>{T(!0);try{const B=await rs({promptName:s.name,arguments:D},r);console.log("GetPrompt result:",B),k({success:B.success,data:B.data,error:B.error})}catch(B){k({success:!1,error:B instanceof Error?B.message:"Unknown error occurred"})}finally{T(!1)}},q=()=>{z(!1),m(),k(null)},_=()=>{k(null)},G=s.name.replace(r+o,""),Q=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const D={},B=[];return s.arguments.forEach(H=>{D[H.name]={type:"string",description:H.description||""},H.required&&B.push(H.name)}),{type:"object",properties:D,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:G}),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:E?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:$,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:K>0?`${K+20}px`:160,minWidth:80},value:F,onChange:b,onKeyDown:I,onClick:D=>D.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:D=>{D.stopPropagation(),p()},disabled:V,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:D=>{D.stopPropagation(),c()},disabled:V,loading:V})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:F||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:D=>{D.stopPropagation(),i()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:a("prompt.restoreDefault"),onClick:D=>{D.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:["Σ ",oe(y)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:D=>D.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")} ${G}`})}),e.jsxs("button",{onClick:D=>{D.stopPropagation(),u(!0),z(!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(Pe,{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:[S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:Q(),onSubmit:R,onCancel:q,loading:N,storageKey:x(),title:a("prompt.runPromptWithName",{name:G})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ue,{result:w,onClose:_})})]}),!S&&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((D,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:D.name}),D.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),D.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:D.description})]}),D.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:D.title})]},B))})]}),!S&&w&&e.jsx("div",{children:e.jsx(Ue,{result:w,onClose:_})})]})]})},Us=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:n,cost:h})=>{const{t:y}=se(),[a,v]=d.useState(!1),[o,f]=d.useState(!1),[u,S]=d.useState(!1),[z,N]=d.useState(s.description||""),T=d.useRef(null),w=d.useRef(null),[k,E]=d.useState(0);d.useEffect(()=>{o&&T.current&&(T.current.focus(),k>0&&(T.current.style.width=`${k+20}px`))},[o,k]),d.useEffect(()=>{!o&&w.current&&E(w.current.offsetWidth)},[o,z]),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,z))},F=async()=>{if(!r){S(!0);try{await(n==null?void 0:n(s.uri,"",{restored:!0})),f(!1)}finally{S(!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:T,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:k>0?`${k+20}px`:160,minWidth:80},value:z,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:w,children:z||y("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:$=>{$.stopPropagation(),f(!0)},children:e.jsx(De,{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:["Σ ",oe(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(Pe,{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"})]})]})},Bs=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,Ls={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)]"}},ze=s=>s==="public"||s==="group"?s:"private",Ws=(s,r)=>{const t=ze(r),n=Ls[t];return{value:t,shortLabel:s(n.shortKey,{defaultValue:n.shortFallback}),longLabel:s(n.longKey,{defaultValue:n.longFallback}),className:n.className}},qs=(s,r)=>{const t=ze(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)"}})})]}),Le=({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"})}),We=(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,Hs="text/html;profile=mcp-app",qe=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Ks=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===Hs||qe(n._meta)}))},Gs=({server:s,cost:r,onRemove:t,onEdit:n,onToggle:h,onVisibilityChange:y,onRefresh:a,onReload:v})=>{var $e,Fe,Ie,Re,_e,Oe,Ae,Me,Ve,Je;const{t:o}=se(),{showToast:f}=Se(),{exportMCPSettings:u,installConfig:S}=Ee(),{auth:z}=ds(),N=(($e=S==null?void 0:S.baseUrl)==null?void 0:$e.replace(/\/+$/,""))||"",[T,w]=d.useState(!1),[k,E]=d.useState(null),[A,V]=d.useState(!1),[U,F]=d.useState(!1),[J,$]=d.useState(!1),[W,K]=d.useState(!1),[Z,x]=d.useState(!1),[m,j]=d.useState(!1),[i,p]=d.useState(!1),c=d.useRef(null),b=d.useRef(null);d.useEffect(()=>{const l=g=>{c.current&&!c.current.contains(g.target)&&x(!1),b.current&&!b.current.contains(g.target)&&j(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[]);const I=((Fe=s.tools)==null?void 0:Fe.length)||0,R=((Ie=s.tools)==null?void 0:Ie.filter(l=>l.enabled!==!1).length)||0,q=((Re=s.prompts)==null?void 0:Re.length)||0,_=((_e=s.prompts)==null?void 0:_e.filter(l=>l.enabled!==!1).length)||0,G=((Oe=s.resources)==null?void 0:Oe.length)||0,Q=((Ae=s.resources)==null?void 0:Ae.filter(l=>l.enabled!==!1).length)||0,D=Ks(s),B=s.enabled!==!1,H=Bs(s,z.user),ce=async l=>{if(!(!H||U||!h)){F(!0);try{await h(s,l)}finally{F(!1)}}},P=async l=>{if(l.stopPropagation(),x(!1),!(!H||W||!v)){K(!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{K(!1)}}},L=async l=>{var C;if(l.stopPropagation(),!H||J||!y)return;const g=l.target.value;if(g!==ze(s.visibility??((C=s.config)==null?void 0:C.visibility))){$(!0);try{await y(s,g)}finally{$(!1)}}},ae=async l=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(l),!0}catch{}try{const g=document.createElement("textarea");g.value=l,g.style.position="fixed",g.style.left="-9999px",document.body.appendChild(g),g.focus(),g.select();const C=document.execCommand("copy");return document.body.removeChild(g),C}catch{return!1}},O=async l=>{if(l.stopPropagation(),!s.error)return;await ae(s.error)?(p(!0),f(o("common.copySuccess")||"Copied","success"),setTimeout(()=>p(!1),1500)):f(o("common.copyFailed")||"Copy failed","error")},Y=async l=>{if(l.stopPropagation(),x(!1),!!H)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 C=JSON.stringify(g.data,null,2),M=await ae(C);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")}},ee=l=>{var g;if(l.stopPropagation(),(g=s.oauth)!=null&&g.authorizationUrl){const re=window.screen.width/2-300,le=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${re},top=${le}`),f(o("status.oauthWindowOpened"),"info")}},pe=async(l,g)=>{try{const{toggleTool:C}=await fe(async()=>{const{toggleTool:re}=await Promise.resolve().then(()=>Is);return{toggleTool:re}},void 0,import.meta.url),M=await C(s.name,l,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),f(o("tool.toggleFailed"),"error")}},xe=async(l,g)=>{try{const{togglePrompt:C}=await fe(async()=>{const{togglePrompt:re}=await Promise.resolve().then(()=>Vs);return{togglePrompt:re}},void 0,import.meta.url),M=await C(s.name,l,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),f(o("tool.toggleFailed"),"error")}},he=async(l,g)=>{try{const{toggleResource:C}=await fe(async()=>{const{toggleResource:re}=await import("./resourceService-CN0gM37U.js");return{toggleResource:re}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),M=await C(s.name,l,g);M.success?(f(o(g?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),a==null||a()):f(M.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),f(o("tool.toggleFailed"),"error")}},X=(l,g,C)=>{f(C!=null&&C.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),a==null||a()},te=(l,g,C)=>{f(C!=null&&C.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),a==null||a()},be=async(l,g,C)=>{try{const{updateResourceDescription:M,resetResourceDescription:re}=await fe(async()=>{const{updateResourceDescription:is,resetResourceDescription:ls}=await import("./resourceService-CN0gM37U.js");return{updateResourceDescription:is,resetResourceDescription:ls}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),le=C!=null&&C.restored?await re(s.name,l):await M(s.name,l,g);le.success?(f(C!=null&&C.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),a==null||a()):f(le.error||(C!=null&&C.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(M){console.error(M),f(C!=null&&C.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var C;const l=s.config;if(!l)return"";if(l.url)return l.url;const g=[];return l.command&&g.push(l.command),(C=l.args)!=null&&C.length&&g.push(...l.args),g.join(" ")})();const ue=`${N}/mcp/${s.name}`,ge=(l,g)=>o(l,g),ne=Ws(ge,s.visibility??((Me=s.config)==null?void 0:Me.visibility)),os=qs(ge,ne.value),Te=[{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:G,enabled:Q,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:()=>w(!T),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:T?"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}),D&&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:l=>{l.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:l=>l.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:i?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:ee,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:We(o,s.config.type)??void 0,children:We(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:l=>l.stopPropagation(),children:H&&y?e.jsx(Be,{isLoading:J,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ne.value,onChange:L,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:ne.longLabel,children:os.map(l=>e.jsx("option",{value:l.value,disabled:l.disabled,children:l.label},l.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] ${ne.className}`,title:ne.longLabel,children:ne.shortLabel})}),Te.map(({key:l,icon:g,total:C,enabled:M,label:re})=>{const le=C===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${le?"is-empty":""}`,title:`${re}: ${M}/${C}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(Le,{icon:g})}),e.jsx("span",{className:"hub-server-capability-value",children:le?"0":`${M}/${C}`})]},l)}),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:[oe(r.exposed),"/",oe(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:l=>l.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:ce,disabled:U||!H,size:"compact","aria-label":`${o(B?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:c,children:[H&&e.jsx("button",{className:"hub-icon-btn",onClick:l=>{l.stopPropagation(),x(g=>!g)},"aria-label":"More",children:e.jsx(vs,{size:14})}),H&&Z&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:l=>l.stopPropagation(),children:[e.jsxs("button",{onClick:l=>{l.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:Y,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),v&&e.jsxs("button",{onClick:P,disabled:W||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:l=>{l.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")]})]})]})]}),T&&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:[Te.map(l=>{const g=k===l.key,C=l.icon;return e.jsxs("button",{onClick:()=>E(g?null:l.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(Le,{icon:C}),e.jsx("span",{children:l.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:l.total===0?"0":`${l.enabled}/${l.total}`})]},l.key)}),r&&r.connected&&e.jsxs("button",{onClick:()=>E(k==="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:k==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(k==="cost"?"var(--hub-line)":"transparent"),color:k==="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:[oe(r.exposed),"/",oe(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 l=>{l.stopPropagation();const g=await ae(ue);f(g?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",g?"success":"error")},title:o("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),k==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((l,g)=>g.cost-l.cost).map(l=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:l.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:l.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:oe(l.cost)})]},`${l.kind}:${l.name}`))}),k==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((l,g)=>{var C;return e.jsx(Os,{server:s.name,tool:l,readOnly:!H,onToggle:pe,onDescriptionUpdate:X,cost:(C=r==null?void 0:r.items.find(M=>M.kind==="tool"&&M.name===l.name))==null?void 0:C.cost},g)})}),k==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((l,g)=>{var C;return e.jsx(Js,{server:s.name,prompt:l,readOnly:!H,onToggle:xe,onDescriptionUpdate:te,cost:(C=r==null?void 0:r.items.find(M=>M.kind==="prompt"&&M.name===l.name))==null?void 0:C.cost},g)})}),k==="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((l,g)=>{var C;return e.jsx(Us,{resource:l,readOnly:!H,onToggle:he,onDescriptionUpdate:be,cost:(C=r==null?void 0:r.items.find(M=>M.kind==="resource"&&M.name===l.uri))==null?void 0:C.cost},`${l.uri}-${g}`)})})})]})]}),e.jsx(Ps,{isOpen:A,onClose:()=>V(!1),onConfirm:()=>{t(s.name),V(!1)},serverName:s.name})]})},Xs=({onAdd:s})=>{const{t:r}=se(),[t,n]=d.useState(!1),[h,y]=d.useState(null),[a,v]=d.useState(!1),[o,f]=d.useState(null),[u,S]=d.useState([]),z=()=>{n(!t),y(null),v(!1),f(null)},N=async()=>{o&&(await T(o),v(!1),f(null))},T=async k=>{try{y(null);const E=await ie("/servers",k);if(!E.success){E&&E.message?y(E.message):y(r("server.addError"));return}n(!1),s()}catch(E){console.error("Error adding server:",E),navigator.onLine?E instanceof TypeError&&(E.message.includes("NetworkError")||E.message.includes("Failed to fetch"))?y(r("errors.serverConnection")):y(r("errors.serverAdd")):y(r("errors.network"))}},w=async k=>{try{const E=zs(k);E.length>0?(S(E),f(k),v(!0)):await T(k)}catch(E){console.error("Error processing server submission:",E),y(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:z,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:w,onCancel:z,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((k,E)=>e.jsxs("li",{className:"font-mono",children:["$",`{${k}}`]},E))})]})]})}),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")})]})]})})]})},Ys=({server:s,onEdit:r,onCancel:t})=>{const{t:n}=se(),[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}:{}},S=await ve(`/servers/${o}`,u);if(!S.success){S&&S.message?y(S.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})})},Zs=({onSuccess:s,onCancel:r})=>{const{t}=se(),[n,h]=d.useState(!1),[y,a]=d.useState(!1),[v,o]=d.useState(null),[f,u]=d.useState(null),[S,z]=d.useState(!1),[N,T]=d.useState(null),[w,k]=d.useState(""),[E,A]=d.useState(!1),[V,U]=d.useState(""),F=i=>{i.preventDefault(),h(!0)},J=i=>{i.preventDefault(),h(!1)},$=i=>{i.preventDefault(),h(!1);const p=i.dataTransfer.files;if(p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},W=i=>{const p=i.target.files;if(p&&p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},K=async()=>{if(!f){o(t("mcpb.noFileSelected"));return}a(!0),o(null);try{const i=new FormData;i.append("mcpbFile",f);const p=await ms(ps("/mcpb/upload"),{method:"POST",body:i}),c=await p.json();if(!p.ok)throw new Error(c.message||`HTTP error! Status: ${p.status}`);if(c.success&&c.data)T(c.data.manifest),k(c.data.extractDir),z(!0);else throw new Error(c.message||t("mcpb.uploadFailed"))}catch(i){console.error("MCPB upload error:",i),o(i instanceof Error?i.message:t("mcpb.uploadFailed"))}finally{a(!1)}},Z=async(i,p=!1)=>{var c;a(!0),o(null);try{const b=j(N,w,i);if(!p){const R=await us("/servers");if(R.success&&((c=R.data)==null?void 0:c.find(_=>_.name===i))){U(i),A(!0),a(!1);return}}let I;if(p?I=await ve(`/servers/${encodeURIComponent(i)}`,{name:i,config:b}):I=await ie("/servers",{name:i,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&&Z(V,!0)},m=()=>{A(!1),U(""),a(!1)},j=(i,p,c)=>{var R;const b=((R=i.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 S&&N?e.jsxs(e.Fragment,{children:[e.jsx(Ts,{isOpen:E,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 ${E?"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((i,p)=>e.jsxs("li",{children:[i.name," - ",i.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 i=document.getElementById("serverName"),p=(i==null?void 0:i.value.trim())||N.name;Z(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:W,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:K,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")})]})]})})},Qs=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}}),et=({onSuccess:s,onCancel:r})=>{const{t}=se(),[n,h]=d.useState(""),[y,a]=d.useState(null),[v,o]=d.useState(!1),[f,u]=d.useState(null),S=`{
|
|
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.`,z=w=>{try{const k=JSON.parse(w.trim());return!k.mcpServers||typeof k.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):k}catch{return a(t("jsonImport.parseError")),null}},N=()=>{a(null);const w=z(n);w&&u(Qs(w))},T=async()=>{if(f){o(!0),a(null);try{const w=await ie("/servers/batch",{servers:f});if(w.success&&w.data){const{successCount:k,failureCount:E,results:A}=w.data;if(E>0){const V=A.filter(U=>!U.success).map(U=>`${U.name}: ${U.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:k,total:f.length})+`
|
|
35
|
-
`+V.join(`
|
|
36
|
-
`))}k>0&&s()}else a(w.message||t("jsonImport.importFailed"))}catch(w){console.error("Import error:",w),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((w,k)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children: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(", ")]})]})]})})},k))})]}),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:T,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:w=>h(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:S}),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")})]})]})]})})},st=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}),tt=(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})},bt=()=>{const{t:s}=se(),r=cs(),{servers:t,allServers:n,error:h,setError:y,isLoading:a,pagination:v,currentPage:o,serversPerPage:f,setCurrentPage:u,setServersPerPage:S,handleServerAdd:z,handleServerEdit:N,handleServerRemove:T,handleServerToggle:w,handleServerVisibilityChange:k,handleServerReload:E,triggerRefresh:A}=xs({refreshOnMount:!0}),{serverCosts:V,refetch:U}=hs();d.useEffect(()=>{U()},[t,U]);const[F,J]=d.useState(null),[$,W]=d.useState(!1),[K,Z]=d.useState(!1),[x,m]=d.useState(!1),[j,i]=d.useState("all"),[p,c]=d.useState(""),b=d.useMemo(()=>st(n),[n]),I=d.useMemo(()=>tt(t,j,p),[t,j,p]),R=async _=>{const G=await N(_);G&&J(G)},q=async()=>{W(!0);try{A(),await new Promise(_=>setTimeout(_,400))}finally{W(!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:()=>Z(!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(Xs,{onAdd:z})]})]}),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(([_,G,Q])=>e.jsxs("button",{onClick:()=>i(_),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:[G,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:Q})]},_))}),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(Gs,{server:_,cost:V.find(G=>G.name===_.name),onRemove:T,onEdit:R,onToggle:w,onVisibilityChange:k,onRefresh:A,onReload:E},_.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($s,{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:_=>S(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(Ys,{server:F,onEdit:()=>{J(null),A()},onCancel:()=>J(null)}),K&&e.jsx(Zs,{onSuccess:()=>{Z(!1),A()},onCancel:()=>Z(!1)}),x&&e.jsx(et,{onSuccess:()=>{m(!1),A()},onCancel:()=>m(!1)})]})};export{bt as default};
|
|
37
|
-
//# sourceMappingURL=ServersPage-CXUBWjQO.js.map
|