@samanhappy/mcphub 1.0.7 → 1.0.8
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/cli/commands/keys.js +2 -7
- package/dist/cli/commands/keys.js.map +1 -1
- package/dist/controllers/bearerKeyController.js +90 -79
- package/dist/controllers/bearerKeyController.js.map +1 -1
- package/dist/controllers/oauthServerController.js +9 -4
- package/dist/controllers/oauthServerController.js.map +1 -1
- package/dist/controllers/serverController.js +62 -4
- package/dist/controllers/serverController.js.map +1 -1
- package/dist/controllers/userController.js +6 -4
- package/dist/controllers/userController.js.map +1 -1
- package/dist/dao/BearerKeyDao.js +21 -1
- package/dist/dao/BearerKeyDao.js.map +1 -1
- package/dist/dao/BearerKeyDaoDbImpl.js +13 -0
- package/dist/dao/BearerKeyDaoDbImpl.js.map +1 -1
- package/dist/dao/UserDao.js +6 -1
- package/dist/dao/UserDao.js.map +1 -1
- package/dist/dao/UserDaoDbImpl.js +24 -36
- package/dist/dao/UserDaoDbImpl.js.map +1 -1
- package/dist/db/entities/BearerKey.js +8 -0
- package/dist/db/entities/BearerKey.js.map +1 -1
- package/dist/db/entities/User.js +4 -0
- package/dist/db/entities/User.js.map +1 -1
- package/dist/db/repositories/BearerKeyRepository.js +9 -0
- package/dist/db/repositories/BearerKeyRepository.js.map +1 -1
- package/dist/db/repositories/SystemConfigRepository.js +2 -1
- package/dist/db/repositories/SystemConfigRepository.js.map +1 -1
- package/dist/db/repositories/UserRepository.js +3 -0
- package/dist/db/repositories/UserRepository.js.map +1 -1
- package/dist/middlewares/auth.js +2 -2
- package/dist/middlewares/auth.js.map +1 -1
- package/dist/middlewares/userContext.js +5 -0
- package/dist/middlewares/userContext.js.map +1 -1
- package/dist/models/User.js +13 -1
- package/dist/models/User.js.map +1 -1
- package/dist/routes/index.js +7 -7
- package/dist/routes/index.js.map +1 -1
- package/dist/services/betterAuthSession.js +44 -6
- package/dist/services/betterAuthSession.js.map +1 -1
- package/dist/services/mcpService.js +16 -0
- package/dist/services/mcpService.js.map +1 -1
- package/dist/services/oauthServerService.js +9 -4
- package/dist/services/oauthServerService.js.map +1 -1
- package/dist/services/smartRoutingService.js +2 -0
- package/dist/services/smartRoutingService.js.map +1 -1
- package/dist/services/sseService.js +38 -3
- package/dist/services/sseService.js.map +1 -1
- package/dist/services/userService.js +15 -4
- package/dist/services/userService.js.map +1 -1
- package/dist/utils/migration.js +5 -0
- package/dist/utils/migration.js.map +1 -1
- package/frontend/dist/assets/{ActivityPage-DDIl8rcq.js → ActivityPage-CjUx2EbK.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-DDIl8rcq.js.map → ActivityPage-CjUx2EbK.js.map} +1 -1
- package/frontend/dist/assets/{Dashboard-CZBclnD_.js → Dashboard-Iq4lJkw-.js} +2 -2
- package/frontend/dist/assets/{Dashboard-CZBclnD_.js.map → Dashboard-Iq4lJkw-.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-C7kzq1Rv.js → EndpointCopy-BSQygOcu.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-C7kzq1Rv.js.map → EndpointCopy-BSQygOcu.js.map} +1 -1
- package/frontend/dist/assets/{GroupsPage-D5J8mmwv.js → GroupsPage-B_nc_tkn.js} +2 -2
- package/frontend/dist/assets/{GroupsPage-D5J8mmwv.js.map → GroupsPage-B_nc_tkn.js.map} +1 -1
- package/frontend/dist/assets/{LoginPage-BksVRHPq.js → LoginPage-DdxxHO3c.js} +2 -2
- package/frontend/dist/assets/{LoginPage-BksVRHPq.js.map → LoginPage-DdxxHO3c.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-VhqcvLlT.js → LogsPage-CgwQu0Zh.js} +2 -2
- package/frontend/dist/assets/{LogsPage-VhqcvLlT.js.map → LogsPage-CgwQu0Zh.js.map} +1 -1
- package/frontend/dist/assets/{MarketPage-Cr0ZJ-12.js → MarketPage-BX7TZNUO.js} +2 -2
- package/frontend/dist/assets/{MarketPage-Cr0ZJ-12.js.map → MarketPage-BX7TZNUO.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-BUFhppNh.js → PromptsPage-Ban8sC8u.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-BUFhppNh.js.map → PromptsPage-Ban8sC8u.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-CLUpqvNX.js → ResourcesPage-RBUlnQMZ.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-CLUpqvNX.js.map → ResourcesPage-RBUlnQMZ.js.map} +1 -1
- package/frontend/dist/assets/ServersPage-GbDb7jmE.js +37 -0
- package/frontend/dist/assets/ServersPage-GbDb7jmE.js.map +1 -0
- package/frontend/dist/assets/SettingsPage-eqjVV7ZP.js +12 -0
- package/frontend/dist/assets/SettingsPage-eqjVV7ZP.js.map +1 -0
- package/frontend/dist/assets/StatusDot-CnuxXTsd.js +2 -0
- package/frontend/dist/assets/StatusDot-CnuxXTsd.js.map +1 -0
- package/frontend/dist/assets/{ToggleGroup-C6hpbZ4n.js → ToggleGroup-9TIHUIkU.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-C6hpbZ4n.js.map → ToggleGroup-9TIHUIkU.js.map} +1 -1
- package/frontend/dist/assets/UsersPage-B8zPaI6u.js +2 -0
- package/frontend/dist/assets/UsersPage-B8zPaI6u.js.map +1 -0
- package/frontend/dist/assets/index-9Vmc8uCD.js +3 -0
- package/frontend/dist/assets/index-9Vmc8uCD.js.map +1 -0
- package/frontend/dist/assets/index-KKZS7IbJ.css +1 -0
- package/frontend/dist/assets/{resourceService-CLgvzUQW.js → resourceService-C_tjomqu.js} +2 -2
- package/frontend/dist/assets/{resourceService-CLgvzUQW.js.map → resourceService-C_tjomqu.js.map} +1 -1
- package/frontend/dist/assets/{useServerData-4qDtSQW3.js → useServerData-BX2-qyGg.js} +2 -2
- package/frontend/dist/assets/{useServerData-4qDtSQW3.js.map → useServerData-BX2-qyGg.js.map} +1 -1
- package/frontend/dist/assets/useSettingsData-CN236NdG.js +2 -0
- package/frontend/dist/assets/{useSettingsData-CSmSfVuv.js.map → useSettingsData-CN236NdG.js.map} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/ServersPage-BmDNiRbb.js +0 -37
- package/frontend/dist/assets/ServersPage-BmDNiRbb.js.map +0 -1
- package/frontend/dist/assets/SettingsPage-DdMb9-RV.js +0 -12
- package/frontend/dist/assets/SettingsPage-DdMb9-RV.js.map +0 -1
- package/frontend/dist/assets/StatusDot-DaXaKatw.js +0 -2
- package/frontend/dist/assets/StatusDot-DaXaKatw.js.map +0 -1
- package/frontend/dist/assets/UsersPage-BtYXxXM3.js +0 -2
- package/frontend/dist/assets/UsersPage-BtYXxXM3.js.map +0 -1
- package/frontend/dist/assets/index-D0OIBhmN.css +0 -1
- package/frontend/dist/assets/index-St_D2SAD.js +0 -3
- package/frontend/dist/assets/index-St_D2SAD.js.map +0 -1
- package/frontend/dist/assets/useSettingsData-CSmSfVuv.js +0 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-C_tjomqu.js","./index-9Vmc8uCD.js","./framework-vendor-BUhDPOUZ.js","./i18n-vendor-Kbr87Ofu.js","./icons-vendor-CKgJB3SC.js","./index-KKZS7IbJ.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as d,j as e,b as as}from"./framework-vendor-BUhDPOUZ.js";import{e as ne,f as Le,h as ye,i as ke,u as os,_ as be,j as is,k as ls,l as cs}from"./index-9Vmc8uCD.js";import{S as ds}from"./StatusDot-CnuxXTsd.js";import{u as Ce}from"./useSettingsData-CN236NdG.js";import{S as Se}from"./ToggleGroup-9TIHUIkU.js";import{u as Y}from"./i18n-vendor-Kbr87Ofu.js";import{l as We,m as qe,j as je,n as us,C as de,o as ge,p as Ee,q as He,r as Ke,s as Pe,k as ve,W as ms,f as ps,F as xs,X as we,E as hs,t as bs,R as fe,T as gs,P as fs,u as ys,v as js,w as vs}from"./icons-vendor-CKgJB3SC.js";import{D as Ns}from"./DeleteDialog-DRbWonMu.js";import{S as Ge,d as ws}from"./variableDetection-GTKqOf1F.js";import{C as ks}from"./ConfirmDialog-CxlizGia.js";import{P as Cs}from"./Pagination-BFi-X7qY.js";import{u as Ss}from"./useServerData-BX2-qyGg.js";const Xe=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await ne(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Es=async(s,n,t)=>{try{const r=await ne(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ze=async(s,n,t)=>{try{const r=await ye(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ye=async(s,n)=>{var t;try{const r=await Le(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ps=Object.freeze(Object.defineProperty({__proto__:null,callTool:Xe,resetToolDescription:Ye,toggleTool:Es,updateToolDescription:Ze},Symbol.toStringTag,{value:"Module"})),Qe=({schema:s,onSubmit:n,onCancel:t,loading:r=!1,storageKey:y,title:i})=>{const{t:h}=Y(),[a,b]=d.useState({}),[F,c]=d.useState({}),[k,D]=d.useState(!1),[v,I]=d.useState(""),[f,z]=d.useState(""),C=d.useMemo(()=>(u=>{const N=o=>{if(typeof o=="object"&&o!==null){const p=o;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([l,j])=>[l,N(j)])):void 0,required:p.required,items:p.items?N(p.items):void 0}}return{type:"string"}};return{type:u.type,properties:u.properties?Object.fromEntries(Object.entries(u.properties).map(([o,p])=>[o,N(p)])):void 0,required:u.required}})(s),[s]);d.useEffect(()=>{const x=(N,o="")=>{const p={};return N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([l,j])=>{const $=o?`${o}.${l}`:l;j.default!==void 0?p[l]=j.default:j.type==="string"?p[l]="":j.type==="number"||j.type==="integer"?p[l]=0:j.type==="boolean"?p[l]=!1:j.type==="array"?p[l]=[]:j.type==="object"&&(j.properties?p[l]=x(j,$):p[l]={})}),p};let u=x(C);if(y)try{const N=localStorage.getItem(y);if(N){const o=JSON.parse(N);u={...u,...o}}}catch(N){console.warn("Failed to load saved form data:",N)}b(u)},[C,y]),d.useEffect(()=>{k&&Object.keys(a).length>0&&(I(JSON.stringify(a,null,2)),z(""))},[k,a]);const R=x=>{I(x),z("");try{const u=JSON.parse(x);if(b(u),y)try{localStorage.setItem(y,JSON.stringify(u))}catch(N){console.warn("Failed to save form data to localStorage:",N)}}catch{z(h("tool.invalidJsonFormat"))}},U=()=>{I(JSON.stringify(a,null,2)),z(""),D(!0)},O=()=>{if(v.trim())try{const x=JSON.parse(v);b(x),z(""),D(!1)}catch{z(h("tool.fixJsonBeforeSwitching"));return}else D(!1)},E=(x,u)=>{b(N=>{const o={...N},p=x.split(".");let l=o;for(let j=0;j<p.length-1;j++)l[p[j]]||(l[p[j]]={}),l=l[p[j]];if(l[p[p.length-1]]=u,y)try{localStorage.setItem(y,JSON.stringify(o))}catch(j){console.warn("Failed to save form data to localStorage:",j)}return o}),F[x]&&c(N=>{const o={...N};return delete o[x],o})},W=()=>{const x={},u=(N,o,p="")=>{N.type==="object"&&N.properties&&Object.entries(N.properties).forEach(([l,j])=>{var _;const $=p?`${p}.${l}`:l,w=o==null?void 0:o[l];if((_=N.required)!=null&&_.includes(l)&&(w==null||w===""||Array.isArray(w)&&w.length===0)){x[$]=`${l} is required`;return}w!=null&&w!==""&&(j.type==="string"&&typeof w!="string"?x[$]=`${l} must be a string`:j.type==="number"&&typeof w!="number"?x[$]=`${l} must be a number`:j.type==="integer"&&(!Number.isInteger(w)||typeof w!="number")?x[$]=`${l} must be an integer`:j.type==="boolean"&&typeof w!="boolean"?x[$]=`${l} must be a boolean`:j.type==="array"&&Array.isArray(w)?j.items&&w.forEach((G,S)=>{var A;((A=j.items)==null?void 0:A.type)==="object"&&j.items.properties&&u(j.items,G,`${$}.${S}`)}):j.type==="object"&&typeof w=="object"&&u(j,w,$))})};return u(C,a),c(x),Object.keys(x).length===0},H=x=>{x.preventDefault(),W()&&n(a)},J=(x,u)=>u.split(".").reduce((N,o)=>N==null?void 0:N[o],x),Q=(x,u,N,o)=>{const p=N==null?void 0:N[x];return u.type==="string"?u.enum?e.jsxs("select",{value:p||"",onChange:l=>o(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:h("tool.selectOption")}),u.enum.map((l,j)=>e.jsx("option",{value:l,children:l},j))]}):e.jsx("input",{type:"text",value:p||"",onChange:l=>o(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:u.description||h("tool.enterKey",{key:x})}):u.type==="number"||u.type==="integer"?e.jsx("input",{type:"number",step:u.type==="integer"?"1":"any",value:p??"",onChange:l=>{const j=l.target.value===""?"":u.type==="integer"?parseInt(l.target.value):parseFloat(l.target.value);o(j)},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"}):u.type==="boolean"?e.jsx("input",{type:"checkbox",checked:p||!1,onChange:l=>o(l.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:p||"",onChange:l=>o(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:u.description||h("tool.enterKey",{key:x})})},B=(x,u,N="")=>{var j,$,w,_,G,S,A,P,L,se,oe,ue,me,pe;const o=N?`${N}.${x}`:x,p=J(a,o),l=F[o];if(u.type==="array"){const V=J(a,o)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?($=(j=J(C,N))==null?void 0:j.required)==null?void 0:$.includes(x):(w=C.required)==null?void 0:w.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[V.map((K,X)=>{var xe,he,re;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:h("tool.item",{index:X+1})}),e.jsx("button",{type:"button",onClick:()=>{const M=[...V];M.splice(X,1),E(o,M)},className:"text-status-red hover:text-red-700 text-sm",children:h("common.remove")})]}),((xe=u.items)==null?void 0:xe.type)==="string"&&u.items.enum?e.jsxs("select",{value:K||"",onChange:M=>{const Z=[...V];Z[X]=M.target.value,E(o,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:h("tool.selectOption")}),u.items.enum.map((M,Z)=>e.jsx("option",{value:M,children:M},Z))]}):((he=u.items)==null?void 0:he.type)==="object"&&u.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(u.items.properties).map(([M,Z])=>{var ce,te;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[M,((te=(ce=u.items)==null?void 0:ce.required)==null?void 0:te.includes(M))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),Q(M,Z,K,Ne=>{const ie=[...V];ie[X]={...ie[X],[M]:Ne},E(o,ie)})]},M)})}):e.jsx("input",{type:"text",value:K||"",onChange:M=>{const Z=[...V];Z[X]=M.target.value,E(o,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:h("tool.enterValue",{type:((re=u.items)==null?void 0:re.type)||"value"})})]},X)}),e.jsx("button",{type:"button",onClick:()=>{var X;const K=((X=u.items)==null?void 0:X.type)==="object"?{}:"";E(o,[...V,K])},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:h("tool.addItem",{key:x})})]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o)}return u.type==="object"?u.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?(G=(_=J(C,N))==null?void 0:_.required)==null?void 0:G.includes(x):(S=C.required)==null?void 0:S.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.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(u.properties).map(([V,K])=>B(V,K,o))}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?(P=(A=J(C,N))==null?void 0:A.required)==null?void 0:P.includes(x):(L=C.required)==null?void 0:L.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)"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsx("textarea",{value:typeof p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:V=>{try{const K=JSON.parse(V.target.value);E(o,K)}catch{E(o,V.target.value)}},placeholder:`{
|
|
3
|
+
"key": "value"
|
|
4
|
+
}`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):u.type==="string"?u.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(se=C.required)==null?void 0:se.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsxs("select",{value:p||"",onChange:V=>E(o,V.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:h("tool.selectOption")}),u.enum.map((V,K)=>e.jsx("option",{value:V,children:V},K))]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(oe=C.required)==null?void 0:oe.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsx("input",{type:"text",value:p||"",onChange:V=>E(o,V.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red":"border-gray-200"} focus:outline-none form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):u.type==="number"||u.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,(N?!1:(ue=C.required)==null?void 0:ue.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsx("input",{type:"number",step:u.type==="integer"?"1":"any",value:p??"",onChange:V=>{const K=V.target.value===""?"":u.type==="integer"?parseInt(V.target.value):parseFloat(V.target.value);E(o,K)},className:`w-full border rounded-md px-3 py-2 form-input ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):u.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:V=>E(o,V.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[x,(N?!1:(me=C.required)==null?void 0:me.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:u.description}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(N?!1:(pe=C.required)==null?void 0:pe.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",u.type,")"]})]}),u.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:u.description}),e.jsx("input",{type:"text",value:p||"",onChange:V=>E(o,V.target.value),placeholder:h("tool.enterValue",{type:u.type}),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},o)};return C.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:i}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:O,className:`hub-btn sm ${k?"":"primary"}`,children:h("tool.formMode")}),e.jsx("button",{type:"button",onClick:U,className:`hub-btn sm ${k?"primary":""}`,children:h("tool.jsonMode")})]})]}),k?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:h("tool.jsonConfiguration")}),e.jsx("textarea",{value:v,onChange:x=>R(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 ${f?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),f&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:f})]}),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:h("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const x=JSON.parse(v);n(x)}catch{z(h("tool.invalidJsonFormat"))}},disabled:r||!!f,className:"hub-btn sm primary",children:h(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[Object.entries(C.properties||{}).map(([x,u])=>B(x,u)),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:h("tool.cancel")}),e.jsx("button",{type:"submit",disabled:r,className:"hub-btn sm primary",children:h(r?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:h("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:h("tool.cancel")}),e.jsx("button",{onClick:()=>n({}),disabled:r,className:"hub-btn primary",children:h(r?"tool.running":"tool.runTool")})]})]})},Ts=({result:s,onClose:n})=>{const{t}=Y(),r=s.content,y=c=>c?c.startsWith("image/")?c:`image/${c}`:"image/png",i=c=>{if(!c)return[];if(Array.isArray(c))return c.flatMap(v=>i(v));if(typeof c!="object")return[];const k=[];c.type==="image"&&c.data&&k.push({data:String(c.data),mimeType:y(c.mimeType||c.mime_type)});const D=c.image_base64||c.imageBase64||c.image_data||c.imageData||c.base64;return D&&k.push({data:String(D),mimeType:y(c.image_mimeType||c.image_mime_type||c.mimeType||c.mime_type)}),c.image&&typeof c.image=="object"&&k.push(...i(c.image)),Array.isArray(c.images)&&k.push(...i(c.images)),Array.isArray(c.content)&&k.push(...i(c.content)),k},h=c=>{const k=[];try{const I=JSON.parse(c);if(k.push(...i(I)),k.length>0)return k}catch{}const D=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let v;for(;(v=D.exec(c))!==null;){const I=`image/${v[1]==="jpg"?"jpeg":v[1]}`;k.push({data:v[2],mimeType:I})}return k},a=c=>{try{const k=JSON.parse(c),D=v=>{if(Array.isArray(v))return v.map(D);if(v&&typeof v=="object"){const I={};for(const[f,z]of Object.entries(v))typeof z=="string"&&f.toLowerCase().includes("base64")?I[f]="[base64 omitted]":I[f]=D(z);return I}return v};return JSON.stringify(D(k),null,2)}catch{return c.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},b=c=>Array.isArray(c)?c.map((k,D)=>e.jsx("div",{className:"mb-3 last:mb-0",children:F(k)},D)):F(c),F=c=>{if(typeof c=="string"){const k=h(c),D=a(c);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[k.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:k.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:D})]})}if(typeof c=="object"&&c!==null){if(c.type==="text"&&c.text){const k=h(c.text),D=a(c.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[k.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:k.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:D})]})}if(c.type==="image"&&c.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${c.mimeType||"image/png"};base64,${c.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const k=typeof c=="string"?JSON.parse(c):c;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(k,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(c)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(c)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(We,{size:20,className:"text-status-green"}):e.jsx(qe,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),b(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),b(r)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},le=({title:s,onClick:n,disabled:t=!1,loading:r=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:n,disabled:t,title:s,"aria-label":s,children:e.jsx(us,{size:14,className:r?"animate-spin":""})});function zs(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 Ds=({tool:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:y})=>{const{t:i}=Y(),{showToast:h}=ke(),{nameSeparator:a}=Ce(),[b,F]=d.useState(!1),[c,k]=d.useState(!1),[D,v]=d.useState(!1),[I,f]=d.useState(null),[z,C]=d.useState(!1),[R,U]=d.useState(!1),[O,E]=d.useState(s.description||""),W=d.useRef(null),H=d.useRef(null),[J,Q]=d.useState(0),[B,x]=d.useState(!1);d.useEffect(()=>{z&&W.current&&(W.current.focus(),J>0&&(W.current.style.width=`${J+20}px`))},[z,J]),d.useEffect(()=>{!z&&H.current&&Q(H.current.offsetWidth)},[z,O]),d.useEffect(()=>{E(s.description||"")},[s.description]);const u=d.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),N=d.useCallback(()=>{localStorage.removeItem(u())},[u]),o=P=>{!t&&r&&r(s.name,P)},p=()=>{t||C(!0)},l=async()=>{if(!t)try{const P=await Ze(n,s.name,O);P.success?(C(!1),y&&y(s.name,O)):(E(s.description||""),console.error("Failed to update tool description:",P.error))}catch(P){console.error("Error updating tool description:",P),E(s.description||""),C(!1)}},j=P=>{E(P.target.value)},$=async()=>{if(!t){U(!0);try{const P=await Ye(n,s.name);if(P.success){const L=P.description||"";E(L),C(!1),y==null||y(s.name,L,{restored:!0})}else h(P.error||i("tool.restoreDefaultFailed"),"error")}catch(P){console.error("Error resetting tool description:",P),h(i("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},w=P=>{P.key==="Enter"?l():P.key==="Escape"&&(E(s.description||""),C(!1))},_=async P=>{P.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),x(!0),h(i("common.copySuccess"),"success"),setTimeout(()=>x(!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"),x(!0),h(i("common.copySuccess"),"success"),setTimeout(()=>x(!1),2e3)}catch(se){h(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",se)}document.body.removeChild(L)}}catch(L){h(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",L)}},G=async P=>{v(!0);try{P=Object.fromEntries(Object.entries(P).filter(([se,oe])=>!zs(oe)));const L=await Xe({toolName:s.name,arguments:P},n);f(L)}catch(L){f({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{v(!1)}},S=()=>{k(!1),N(),f(null)},A=()=>{f(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(),F(!b)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(n+a,"")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:_,title:i("common.copy"),children:B?e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ge,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:W,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:J>0?`${J+20}px`:160,minWidth:80},value:O,onChange:j,onKeyDown:w,onClick:P=>P.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),l()},disabled:R,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(le,{title:i("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),$()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,children:O||i("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),p()},children:e.jsx(Ee,{size:12})}),e.jsx(le,{title:i("tool.restoreDefault"),onClick:P=>{P.stopPropagation(),$()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:P=>P.stopPropagation(),children:e.jsx(Se,{checked:s.enabled??!0,onCheckedChange:o,disabled:D||t})}),e.jsxs("button",{onClick:P=>{P.stopPropagation(),F(!0),k(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:D||!s.enabled,children:[D?e.jsx(He,{size:12,className:"animate-spin"}):e.jsx(Ke,{size:12}),e.jsx("span",{children:i(D?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:b?e.jsx(Pe,{size:14}):e.jsx(ve,{size:14})})]})]}),b&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[!c&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:i("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),c&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Qe,{schema:s.inputSchema||{type:"object"},onSubmit:G,onCancel:S,loading:D,storageKey:u(),title:i("tool.runToolWithName",{name:s.name.replace(n+a,"")})}),I&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ts,{result:I,onClose:A})})]})]})]})},Fs=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",r=await ne(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},es=async(s,n)=>{try{const t=await ne(`/mcp/${encodeURIComponent(n||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Is=async(s,n,t)=>{try{const r=await ne(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ss=async(s,n,t)=>{try{const r=await ye(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ts=async(s,n)=>{var t;try{const r=await Le(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},$s=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:Fs,getPrompt:es,resetPromptDescription:ts,togglePrompt:Is,updatePromptDescription:ss},Symbol.toStringTag,{value:"Module"})),Me=({result:s,onClose:n})=>{const{t}=Y(),r=y=>{if(typeof y=="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:y})});if(typeof y=="object"&&y!==null){if(y.description||y.messages)return e.jsxs("div",{className:"space-y-4",children:[y.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:y.description})})]}),y.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:y.messages.map((i,h)=>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:[i.role,":"]})}),typeof i.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:i.content}):typeof i.content=="object"&&i.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:i.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(i.content,null,2)})]},h))})]})]});try{const i=typeof y=="string"?JSON.parse(y):y;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(i,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(y)})})}}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(y)})})};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(We,{size:20,className:"text-status-green"}):e.jsx(qe,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),r(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Rs=({prompt:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:y})=>{const{t:i}=Y(),{showToast:h}=ke(),{nameSeparator:a}=Ce(),[b,F]=d.useState(!1),[c,k]=d.useState(!1),[D,v]=d.useState(!1),[I,f]=d.useState(null),[z,C]=d.useState(!1),[R,U]=d.useState(!1),[O,E]=d.useState(s.description||""),W=d.useRef(null),H=d.useRef(null),[J,Q]=d.useState(0);d.useEffect(()=>{z&&W.current&&(W.current.focus(),J>0&&(W.current.style.width=`${J+20}px`))},[z,J]),d.useEffect(()=>{!z&&H.current&&Q(H.current.offsetWidth)},[z,O]),d.useEffect(()=>{E(s.description||"")},[s.description]);const B=d.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),x=d.useCallback(()=>{localStorage.removeItem(B())},[B]),u=S=>{!t&&r&&r(s.name,S)},N=()=>{t||C(!0)},o=async()=>{if(!t){C(!1);try{const S=await ss(n,s.name,O);S.success?y&&y(s.name,O):(h(S.error||i("prompt.descriptionUpdateFailed"),"error"),E(s.description||""))}catch(S){console.error("Error updating prompt description:",S),h(i("prompt.descriptionUpdateFailed"),"error"),E(s.description||"")}}},p=async()=>{if(!t){U(!0);try{const S=await ts(n,s.name);if(S.success){const A=S.description||"";E(A),C(!1),y==null||y(s.name,A,{restored:!0})}else h(S.error||i("prompt.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting prompt description:",S),h(i("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},l=S=>{E(S.target.value)},j=S=>{S.key==="Enter"?o():S.key==="Escape"&&(E(s.description||""),C(!1))},$=async S=>{v(!0);try{const A=await es({promptName:s.name,arguments:S},n);console.log("GetPrompt result:",A),f({success:A.success,data:A.data,error:A.error})}catch(A){f({success:!1,error:A instanceof Error?A.message:"Unknown error occurred"})}finally{v(!1)}},w=()=>{k(!1),x(),f(null)},_=()=>{f(null)},G=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const S={},A=[];return s.arguments.forEach(P=>{S[P.name]={type:"string",description:P.description||""},P.required&&A.push(P.name)}),{type:"object",properties:S,required:A}};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:()=>F(!b),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(n+a,"")}),s.title&&e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.title}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:z?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:W,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:J>0?`${J+20}px`:160,minWidth:80},value:O,onChange:l,onKeyDown:j,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),o()},disabled:R,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(le,{title:i("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),p()},disabled:R,loading:R})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:H,children:O||i("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),N()},children:e.jsx(Ee,{size:12})}),e.jsx(le,{title:i("prompt.restoreDefault"),onClick:S=>{S.stopPropagation(),p()},disabled:R,loading:R})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:S=>S.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Se,{checked:s.enabled,onCheckedChange:u,disabled:D||t})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),F(!0),k(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:D||!s.enabled,children:[D?e.jsx(He,{size:12,className:"animate-spin"}):e.jsx(Ke,{size:12}),e.jsx("span",{children:i(D?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:b?e.jsx(Pe,{size:14}):e.jsx(ve,{size:14})})]})]}),b&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[c&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Qe,{schema:G(),onSubmit:$,onCancel:w,loading:D,storageKey:B(),title:i("prompt.runPromptWithName",{name:s.name.replace(n+a,"")})}),I&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Me,{result:I,onClose:_})})]}),!c&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:i("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((S,A)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:S.name}),S.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),S.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:S.description})]}),S.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:S.title})]},A))})]}),!c&&I&&e.jsx("div",{children:e.jsx(Me,{result:I,onClose:_})})]})]})},_s=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:r})=>{const{t:y}=Y(),[i,h]=d.useState(!1),[a,b]=d.useState(!1),[F,c]=d.useState(!1),[k,D]=d.useState(s.description||""),v=d.useRef(null),I=d.useRef(null),[f,z]=d.useState(0);d.useEffect(()=>{a&&v.current&&(v.current.focus(),f>0&&(v.current.style.width=`${f+20}px`))},[a,f]),d.useEffect(()=>{!a&&I.current&&z(I.current.offsetWidth)},[a,k]),d.useEffect(()=>{D(s.description||"")},[s.description]);const C=E=>{!n&&t&&t(s.uri,E)},R=async()=>{n||(b(!1),r&&await r(s.uri,k))},U=async()=>{if(!n){c(!0);try{await(r==null?void 0:r(s.uri,"",{restored:!0})),b(!1)}finally{c(!1)}}},O=E=>{E.key==="Enter"?R():E.key==="Escape"&&(D(s.description||""),b(!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:()=>h(!i),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name||s.uri}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:a?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:v,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:f>0?`${f+20}px`:160,minWidth:80},value:k,onChange:E=>D(E.target.value),onKeyDown:O,onClick:E=>E.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),R()},disabled:F,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(le,{title:y("builtinResources.restoreDefault"),onClick:E=>{E.stopPropagation(),U()},disabled:F,loading:F})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:I,children:k||y("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),b(!0)},children:e.jsx(Ee,{size:12})}),e.jsx(le,{title:y("builtinResources.restoreDefault"),onClick:E=>{E.stopPropagation(),U()},disabled:F,loading:F})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:E=>E.stopPropagation(),children:e.jsx(Se,{checked:s.enabled!==!1,onCheckedChange:C,disabled:n})}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(Pe,{size:14}):e.jsx(ve,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[y("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Os=(s,n)=>n?n.isAdmin?!0:!!(s.owner&&s.owner===n.username):!1,As={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Te=s=>s==="public"||s==="group"?s:"private",Vs=(s,n)=>{const t=Te(n),r=As[t];return{value:t,shortLabel:s(r.shortKey,{defaultValue:r.shortFallback}),longLabel:s(r.longKey,{defaultValue:r.longFallback}),className:r.className}},Ms=(s,n)=>{const t=Te(n),r=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&r.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),r.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),r},Je=({isLoading:s,children:n,className:t,overlayStyle:r,spinnerSize:y=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:n}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...r},children:e.jsx(fe,{size:y,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),Ue=({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"})}),Be=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,Js=({server:s,onRemove:n,onEdit:t,onToggle:r,onVisibilityChange:y,onRefresh:i,onReload:h})=>{var ze,De,Fe,Ie,$e,Re,_e,Oe,Ae,Ve;const{t:a}=Y(),{showToast:b}=ke(),{exportMCPSettings:F,installConfig:c}=Ce(),{auth:k}=os(),D=((ze=c==null?void 0:c.baseUrl)==null?void 0:ze.replace(/\/+$/,""))||"",[v,I]=d.useState(!1),[f,z]=d.useState(null),[C,R]=d.useState(!1),[U,O]=d.useState(!1),[E,W]=d.useState(!1),[H,J]=d.useState(!1),[Q,B]=d.useState(!1),[x,u]=d.useState(!1),[N,o]=d.useState(!1),p=d.useRef(null),l=d.useRef(null);d.useEffect(()=>{const m=g=>{p.current&&!p.current.contains(g.target)&&B(!1),l.current&&!l.current.contains(g.target)&&u(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);const j=((De=s.tools)==null?void 0:De.length)||0,$=((Fe=s.tools)==null?void 0:Fe.filter(m=>m.enabled!==!1).length)||0,w=((Ie=s.prompts)==null?void 0:Ie.length)||0,_=(($e=s.prompts)==null?void 0:$e.filter(m=>m.enabled!==!1).length)||0,G=((Re=s.resources)==null?void 0:Re.length)||0,S=((_e=s.resources)==null?void 0:_e.filter(m=>m.enabled!==!1).length)||0,A=async m=>{if(m.stopPropagation(),!(!M||U||!r)){O(!0);try{await r(s,s.enabled===!1)}finally{O(!1)}}},P=async m=>{if(m.stopPropagation(),B(!1),!(!M||H||!h)){J(!0);try{await h(s)?b(a("server.reloadSuccess")||"Server reloaded successfully","success"):b(a("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{J(!1)}}},L=async m=>{var T;if(m.stopPropagation(),!M||E||!y)return;const g=m.target.value;if(g!==Te(s.visibility??((T=s.config)==null?void 0:T.visibility))){W(!0);try{await y(s,g)}finally{W(!1)}}},se=async m=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(m),!0}catch{}try{const g=document.createElement("textarea");g.value=m,g.style.position="fixed",g.style.left="-9999px",document.body.appendChild(g),g.focus(),g.select();const T=document.execCommand("copy");return document.body.removeChild(g),T}catch{return!1}},oe=async m=>{if(m.stopPropagation(),!s.error)return;await se(s.error)?(o(!0),b(a("common.copySuccess")||"Copied","success"),setTimeout(()=>o(!1),1500)):b(a("common.copyFailed")||"Copy failed","error")},ue=async m=>{if(m.stopPropagation(),B(!1),!!M)try{const g=await F(s.name);if(!g||!g.success||!g.data){b((g==null?void 0:g.message)||a("common.copyFailed")||"Copy failed","error");return}const T=JSON.stringify(g.data,null,2),q=await se(T);b(q?a("common.copySuccess")||"Copied":a("common.copyFailed")||"Copy failed",q?"success":"error")}catch(g){console.error("Error copying server configuration:",g),b(a("common.copyFailed")||"Copy failed","error")}},me=m=>{var g;if(m.stopPropagation(),(g=s.oauth)!=null&&g.authorizationUrl){const ee=window.screen.width/2-300,ae=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ee},top=${ae}`),b(a("status.oauthWindowOpened"),"info")}},pe=async(m,g)=>{try{const{toggleTool:T}=await be(async()=>{const{toggleTool:ee}=await Promise.resolve().then(()=>Ps);return{toggleTool:ee}},void 0,import.meta.url),q=await T(s.name,m,g);q.success?(b(a(g?"tool.enableSuccess":"tool.disableSuccess",{name:m}),"success"),i==null||i()):b(q.error||a("tool.toggleFailed"),"error")}catch(T){console.error(T),b(a("tool.toggleFailed"),"error")}},V=async(m,g)=>{try{const{togglePrompt:T}=await be(async()=>{const{togglePrompt:ee}=await Promise.resolve().then(()=>$s);return{togglePrompt:ee}},void 0,import.meta.url),q=await T(s.name,m,g);q.success?(b(a(g?"tool.enableSuccess":"tool.disableSuccess",{name:m}),"success"),i==null||i()):b(q.error||a("tool.toggleFailed"),"error")}catch(T){console.error(T),b(a("tool.toggleFailed"),"error")}},K=async(m,g)=>{try{const{toggleResource:T}=await be(async()=>{const{toggleResource:ee}=await import("./resourceService-C_tjomqu.js");return{toggleResource:ee}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),q=await T(s.name,m,g);q.success?(b(a(g?"tool.enableSuccess":"tool.disableSuccess",{name:m}),"success"),i==null||i()):b(q.error||a("tool.toggleFailed"),"error")}catch(T){console.error(T),b(a("tool.toggleFailed"),"error")}},X=(m,g,T)=>{b(T!=null&&T.restored?a("tool.restoreDefaultSuccess"):a("tool.descriptionUpdateSuccess"),"success"),i==null||i()},xe=(m,g,T)=>{b(T!=null&&T.restored?a("prompt.restoreDefaultSuccess"):a("prompt.descriptionUpdateSuccess"),"success"),i==null||i()},he=async(m,g,T)=>{try{const{updateResourceDescription:q,resetResourceDescription:ee}=await be(async()=>{const{updateResourceDescription:rs,resetResourceDescription:ns}=await import("./resourceService-C_tjomqu.js");return{updateResourceDescription:rs,resetResourceDescription:ns}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ae=T!=null&&T.restored?await ee(s.name,m):await q(s.name,m,g);ae.success?(b(T!=null&&T.restored?a("builtinResources.restoreDefaultSuccess"):a("builtinResources.descriptionUpdateSuccess"),"success"),i==null||i()):b(ae.error||(T!=null&&T.restored?a("builtinResources.restoreDefaultFailed"):a("builtinResources.descriptionUpdateFailed")),"error")}catch(q){console.error(q),b(T!=null&&T.restored?a("builtinResources.restoreDefaultFailed"):a("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var T;const m=s.config;if(!m)return"";if(m.url)return m.url;const g=[];return m.command&&g.push(m.command),(T=m.args)!=null&&T.length&&g.push(...m.args),g.join(" ")})();const re=s.enabled!==!1,M=Os(s,k.user),Z=`${D}/mcp/${s.name}`,ce=(m,g)=>a(m,g),te=Vs(ce,s.visibility??((Oe=s.config)==null?void 0:Oe.visibility)),Ne=Ms(ce,te.value),ie=[{key:"tools",icon:ms,total:j,enabled:$,label:a("server.tools")},{key:"prompts",icon:ps,total:w,enabled:_,label:a("server.prompts")},{key:"resources",icon:xs,total:G,enabled:S,label:a("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10,opacity:re?1:.7},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>I(!v),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ve,{size:12,style:{color:"var(--hub-ink-3)",transform:v?"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:re?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),s.error&&e.jsxs("div",{className:"relative",ref:l,children:[e.jsx("button",{onClick:m=>{m.stopPropagation(),u(g=>!g)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":a("server.viewErrorDetails"),children:e.jsx(je,{size:14})}),x&&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:m=>m.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:a("server.errorDetails")}),e.jsx("button",{onClick:oe,className:"hub-icon-btn sm",title:a("common.copy"),children:N?e.jsx(de,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ge,{size:12})})]}),e.jsx("button",{onClick:()=>u(!1),className:"hub-icon-btn sm","aria-label":a("app.closeButton"),children:e.jsx(we,{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})})]})]})]}),((Ae=s.config)==null?void 0:Ae.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(ds,{status:s.status,enabled:s.enabled,onAuthClick:me,className:"hub-server-card-status"})}),e.jsx("div",{className:"min-w-0",children:(Ve=s.config)!=null&&Ve.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Be(a,s.config.type)??void 0,children:Be(a,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:m=>m.stopPropagation(),children:M&&y?e.jsx(Je,{isLoading:E,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:te.value,onChange:L,disabled:E,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":a("server.visibility","Visibility"),title:te.longLabel,children:Ne.map(m=>e.jsx("option",{value:m.value,disabled:m.disabled,children:m.label},m.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] ${te.className}`,title:te.longLabel,children:te.shortLabel})}),ie.map(({key:m,icon:g,total:T,enabled:q,label:ee})=>{const ae=T===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${ae?"is-empty":""}`,title:`${ee}: ${q}/${T}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(Ue,{icon:g})}),e.jsx("span",{className:"hub-server-capability-value",children:ae?"0":`${q}/${T}`})]},m)}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Je,{isLoading:U,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx("button",{type:"button",className:"hub-switch"+(re?" on":""),onClick:A,disabled:U||!M,"aria-label":a(re?"server.disable":"server.enable")})})}),e.jsxs("div",{className:"relative",ref:p,children:[M&&e.jsx("button",{className:"hub-icon-btn",onClick:m=>{m.stopPropagation(),B(g=>!g)},"aria-label":"More",children:e.jsx(hs,{size:14})}),M&&Q&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:m=>m.stopPropagation(),children:[e.jsxs("button",{onClick:m=>{m.stopPropagation(),B(!1),t(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(bs,{size:13})," ",a("server.edit")]}),e.jsxs("button",{onClick:ue,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(ge,{size:13})," ",a("server.copy")]}),h&&e.jsxs("button",{onClick:P,disabled:H||U||!re,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(fe,{size:13})," ",a("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:m=>{m.stopPropagation(),B(!1),R(!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(gs,{size:13})," ",a("server.delete")]})]})]})]}),v&&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:[ie.map(m=>{const g=f===m.key,T=m.icon;return e.jsxs("button",{onClick:()=>z(g?null:m.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(Ue,{icon:T}),e.jsx("span",{children:m.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:m.total===0?"0":`${m.enabled}/${m.total}`})]},m.key)}),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:Z,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async m=>{m.stopPropagation();const g=await se(Z);b(g?a("common.copySuccess")||"Copied":a("common.copyFailed")||"Failed",g?"success":"error")},title:a("common.copy"),children:e.jsx(ge,{size:12})})]})})]}),f==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((m,g)=>e.jsx(Ds,{server:s.name,tool:m,readOnly:!M,onToggle:pe,onDescriptionUpdate:X},g))}),f==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((m,g)=>e.jsx(Rs,{server:s.name,prompt:m,readOnly:!M,onToggle:V,onDescriptionUpdate:xe},g))}),f==="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:a("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((m,g)=>e.jsx(_s,{resource:m,readOnly:!M,onToggle:K,onDescriptionUpdate:he},`${m.uri}-${g}`))})})]})]}),e.jsx(Ns,{isOpen:C,onClose:()=>R(!1),onConfirm:()=>{n(s.name),R(!1)},serverName:s.name})]})},Us=({onAdd:s})=>{const{t:n}=Y(),[t,r]=d.useState(!1),[y,i]=d.useState(null),[h,a]=d.useState(!1),[b,F]=d.useState(null),[c,k]=d.useState([]),D=()=>{r(!t),i(null),a(!1),F(null)},v=async()=>{b&&(await I(b),a(!1),F(null))},I=async z=>{try{i(null);const C=await ne("/servers",z);if(!C.success){C&&C.message?i(C.message):i(n("server.addError"));return}r(!1),s()}catch(C){console.error("Error adding server:",C),navigator.onLine?C instanceof TypeError&&(C.message.includes("NetworkError")||C.message.includes("Failed to fetch"))?i(n("errors.serverConnection")):i(n("errors.serverAdd")):i(n("errors.network"))}},f=async z=>{try{const C=ws(z);C.length>0?(k(C),F(z),a(!0)):await I(z)}catch(C){console.error("Error processing server submission:",C),i(n("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:D,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),n("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ge,{onSubmit:f,onCancel:D,modalTitle:n("server.addServer"),formError:y})}),h&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:n("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:n("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[n("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:c.map((z,C)=>e.jsxs("li",{className:"font-mono",children:["$",`{${z}}`]},C))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:n("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{a(!1),F(null)},className:"hub-btn",children:n("common.cancel")}),e.jsx("button",{onClick:v,className:"hub-btn primary",children:n("server.confirmAndAdd")})]})]})})]})},Bs=({server:s,onEdit:n,onCancel:t})=>{const{t:r}=Y(),[y,i]=d.useState(null),h=async a=>{try{i(null);const b=encodeURIComponent(s.name),F=a.name&&a.name!==s.name,c={config:a.config,...F?{newName:a.name}:{}},k=await ye(`/servers/${b}`,c);if(!k.success){k&&k.message?i(k.message):i(r("server.updateError",{serverName:s.name}));return}n()}catch(b){console.error("Error updating server:",b),navigator.onLine?b instanceof TypeError&&(b.message.includes("NetworkError")||b.message.includes("Failed to fetch"))?i(r("errors.serverConnection")):i(r("errors.serverUpdate",{serverName:s.name})):i(r("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ge,{onSubmit:h,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:y})})},Ls=({onSuccess:s,onCancel:n})=>{const{t}=Y(),[r,y]=d.useState(!1),[i,h]=d.useState(!1),[a,b]=d.useState(null),[F,c]=d.useState(null),[k,D]=d.useState(!1),[v,I]=d.useState(null),[f,z]=d.useState(""),[C,R]=d.useState(!1),[U,O]=d.useState(""),E=o=>{o.preventDefault(),y(!0)},W=o=>{o.preventDefault(),y(!1)},H=o=>{o.preventDefault(),y(!1);const p=o.dataTransfer.files;if(p.length>0){const l=p[0];l.name.endsWith(".mcpb")?(c(l),b(null)):b(t("mcpb.invalidFileType"))}},J=o=>{const p=o.target.files;if(p&&p.length>0){const l=p[0];l.name.endsWith(".mcpb")?(c(l),b(null)):b(t("mcpb.invalidFileType"))}},Q=async()=>{if(!F){b(t("mcpb.noFileSelected"));return}h(!0),b(null);try{const o=new FormData;o.append("mcpbFile",F);const p=await ls(cs("/mcpb/upload"),{method:"POST",body:o}),l=await p.json();if(!p.ok)throw new Error(l.message||`HTTP error! Status: ${p.status}`);if(l.success&&l.data)I(l.data.manifest),z(l.data.extractDir),D(!0);else throw new Error(l.message||t("mcpb.uploadFailed"))}catch(o){console.error("MCPB upload error:",o),b(o instanceof Error?o.message:t("mcpb.uploadFailed"))}finally{h(!1)}},B=async(o,p=!1)=>{var l;h(!0),b(null);try{const j=N(v,f,o);if(!p){const w=await is("/servers");if(w.success&&((l=w.data)==null?void 0:l.find(G=>G.name===o))){O(o),R(!0),h(!1);return}}let $;if(p?$=await ye(`/servers/${encodeURIComponent(o)}`,{name:o,config:j}):$=await ne("/servers",{name:o,config:j}),$.success)s(j);else throw new Error($.message||t("mcpb.installFailed"))}catch(j){console.error("MCPB install error:",j),b(j instanceof Error?j.message:t("mcpb.installFailed")),h(!1)}},x=()=>{R(!1),U&&B(U,!0)},u=()=>{R(!1),O(""),h(!1)},N=(o,p,l)=>{var w;const j=((w=o.server)==null?void 0:w.mcp_config)||{},$={type:"stdio",command:j.command||"node",args:(j.args||[]).map(_=>_.replace("${__dirname}",p))};return j.env&&Object.keys(j.env).length>0&&($.env={...j.env},Object.keys($.env).forEach(_=>{typeof $.env[_]=="string"&&($.env[_]=$.env[_].replace("${__dirname}",p))})),$};return k&&v?e.jsxs(e.Fragment,{children:[e.jsx(ks,{isOpen:C,onClose:u,onConfirm:x,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:U}),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 ${C?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),a&&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:a})}),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"),":"]})," ",v.display_name||v.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",v.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",v.description]}),v.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",v.author.name]}),v.tools&&v.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:v.tools.map((o,p)=>e.jsxs("li",{children:[o.name," - ",o.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:v.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:i,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const o=document.getElementById("serverName"),p=(o==null?void 0:o.value.trim())||v.name;B(p)},disabled:i,className:"hub-btn primary",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),a&&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:a})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${r?"border-blue-500 bg-blue-50":F?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:E,onDragLeave:W,onDrop:H,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:J,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:i,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:Q,disabled:!F||i,className:"hub-btn primary flex items-center",children:i?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")})]})]})})},Ws=s=>Object.entries(s.mcpServers).map(([n,t])=>{const r={};return t.type==="sse"||t.type==="streamable-http"?(r.type=t.type,r.url=t.url,t.headers&&(r.headers=t.headers)):t.type==="openapi"?(r.type="openapi",r.openapi=t.openapi):(r.type="stdio",r.command=t.command,r.args=t.args||[],t.env&&(r.env=t.env),t.options&&(r.options=t.options)),{name:n,config:r}}),qs=({onSuccess:s,onCancel:n})=>{const{t}=Y(),[r,y]=d.useState(""),[i,h]=d.useState(null),[a,b]=d.useState(!1),[F,c]=d.useState(null),k=`{
|
|
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.`,D=f=>{try{const z=JSON.parse(f.trim());return!z.mcpServers||typeof z.mcpServers!="object"?(h(t("jsonImport.invalidFormat")),null):z}catch{return h(t("jsonImport.parseError")),null}},v=()=>{h(null);const f=D(r);f&&c(Ws(f))},I=async()=>{if(F){b(!0),h(null);try{const f=await ne("/servers/batch",{servers:F});if(f.success&&f.data){const{successCount:z,failureCount:C,results:R}=f.data;if(C>0){const U=R.filter(O=>!O.success).map(O=>`${O.name}: ${O.message||t("jsonImport.addFailed")}`);h(t("jsonImport.partialSuccess",{count:z,total:F.length})+`
|
|
35
|
+
`+U.join(`
|
|
36
|
+
`))}z>0&&s()}else h(f.message||t("jsonImport.importFailed"))}catch(f){console.error("Import error:",f),h(t("jsonImport.importFailed"))}finally{b(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),i&&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:i})}),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((f,z)=>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:f.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"),":"]})," ",f.config.type||"stdio"]}),f.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",f.config.command]}),f.config.args&&f.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",f.config.args.join(" ")]}),f.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",f.config.url]}),f.config.env&&Object.keys(f.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(f.config.env).join(", ")]}),f.config.headers&&Object.keys(f.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(f.config.headers).join(", ")]})]})]})})},z))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>c(null),disabled:a,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:I,disabled:a,className:"hub-btn primary",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:r,onChange:f=>y(f.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:k}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:v,disabled:!r.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},at=()=>{const{t:s}=Y(),n=as(),{servers:t,allServers:r,error:y,setError:i,isLoading:h,pagination:a,currentPage:b,serversPerPage:F,setCurrentPage:c,setServersPerPage:k,handleServerAdd:D,handleServerEdit:v,handleServerRemove:I,handleServerToggle:f,handleServerVisibilityChange:z,handleServerReload:C,triggerRefresh:R}=Ss({refreshOnMount:!0}),[U,O]=d.useState(null),[E,W]=d.useState(!1),[H,J]=d.useState(!1),[Q,B]=d.useState(!1),[x,u]=d.useState("all"),[N,o]=d.useState(""),p=d.useMemo(()=>({all:r.length,online:r.filter(w=>w.status==="connected").length,issues:r.filter(w=>w.status!=="connected"&&w.enabled!==!1).length}),[r]),l=d.useMemo(()=>{const w=N.trim().toLowerCase();return t.filter(_=>{var S,A;return x==="online"&&_.status!=="connected"||x==="issues"&&(_.status==="connected"||_.enabled===!1)?!1:w?(_.name+" "+(((S=_.config)==null?void 0:S.description)||"")+" "+(((A=_.tools)==null?void 0:A.map(P=>P.name).join(" "))||"")).toLowerCase().includes(w):!0})},[t,x,N]),j=async w=>{const _=await v(w);_&&O(_)},$=async()=>{W(!0);try{R(),await new Promise(w=>setTimeout(w,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:p.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:p.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:p.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>n("/market"),children:[e.jsx(fs,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>B(!0),children:[e.jsx(ys,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>J(!0),children:[e.jsx(js,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:$,disabled:E,"aria-label":s("common.refresh"),children:[e.jsx(fe,{size:13,className:E?"animate-spin":""}),s("common.refresh")]}),e.jsx(Us,{onAdd:D})]})]}),y&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(je,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:y})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>i(null),"aria-label":s("app.closeButton"),children:e.jsx(we,{size:13})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-4 flex-wrap",children:[e.jsx("div",{className:"hub-card flex items-center",style:{padding:2,borderRadius:7,background:"var(--hub-surface)"},children:[["all",s("common.all")||"All",p.all],["online",s("status.online"),p.online],["issues",s("common.inactive")||"Issues",p.issues]].map(([w,_,G])=>e.jsxs("button",{onClick:()=>u(w),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:x===w?"var(--hub-bg-2)":"transparent",color:x===w?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(x===w?"var(--hub-line)":"transparent")},children:[_,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:G})]},w))}),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(vs,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:N,onChange:w=>o(w.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),N&&e.jsx("button",{onClick:()=>o(""),className:"hub-icon-btn sm",children:e.jsx(we,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[l.length,"/",t.length]})]}),h&&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(fe,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):l.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:l.map(w=>e.jsx(Js,{server:w,onRemove:I,onEdit:j,onToggle:f,onVisibilityChange:z,onRefresh:R,onReload:C},w.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:a?s("common.showing",{start:(a.page-1)*a.limit+1,end:Math.min(a.page*a.limit,a.total),total:a.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:a&&a.totalPages>1&&e.jsx(Cs,{currentPage:b,totalPages:a.totalPages,onPageChange:c,disabled:h})}),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:w=>k(Number(w.target.value)),disabled:h,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"})]})]})]})]}),U&&e.jsx(Bs,{server:U,onEdit:()=>{O(null),R()},onCancel:()=>O(null)}),H&&e.jsx(Ls,{onSuccess:()=>{J(!1),R()},onCancel:()=>J(!1)}),Q&&e.jsx(qs,{onSuccess:()=>{B(!1),R()},onCancel:()=>B(!1)})]})};export{at as default};
|
|
37
|
+
//# sourceMappingURL=ServersPage-GbDb7jmE.js.map
|