@samanhappy/mcphub 1.0.3 → 1.0.4
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/README.fr.md +1 -1
- package/README.md +1 -1
- package/dist/betterAuth.js +21 -6
- package/dist/betterAuth.js.map +1 -1
- package/dist/clients/openapi.js +31 -9
- package/dist/clients/openapi.js.map +1 -1
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -1
- package/dist/controllers/configController.js +4 -5
- package/dist/controllers/configController.js.map +1 -1
- package/dist/controllers/oauthDynamicRegistrationController.js +6 -6
- package/dist/controllers/oauthDynamicRegistrationController.js.map +1 -1
- package/dist/controllers/oauthServerController.js +7 -7
- package/dist/controllers/oauthServerController.js.map +1 -1
- package/dist/controllers/serverController.js +107 -21
- package/dist/controllers/serverController.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/middlewares/auth.js +2 -3
- package/dist/middlewares/auth.js.map +1 -1
- package/dist/middlewares/index.js +31 -23
- package/dist/middlewares/index.js.map +1 -1
- package/dist/routes/index.js +1 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/services/betterAuthConfig.js +43 -11
- package/dist/services/betterAuthConfig.js.map +1 -1
- package/dist/services/betterAuthSession.js +1 -1
- package/dist/services/betterAuthSession.js.map +1 -1
- package/dist/utils/systemConfigCache.js +13 -0
- package/dist/utils/systemConfigCache.js.map +1 -0
- package/frontend/dist/assets/{ActivityPage-DeJomvjn.js → ActivityPage-BC5odCF8.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-DeJomvjn.js.map → ActivityPage-BC5odCF8.js.map} +1 -1
- package/frontend/dist/assets/{Dashboard-CZPBdlCK.js → Dashboard-D3G8PwSI.js} +2 -2
- package/frontend/dist/assets/{Dashboard-CZPBdlCK.js.map → Dashboard-D3G8PwSI.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-Ds6T2k0b.js → EndpointCopy-DR92FdQt.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-Ds6T2k0b.js.map → EndpointCopy-DR92FdQt.js.map} +1 -1
- package/frontend/dist/assets/{GroupsPage-BN8Zp5i8.js → GroupsPage--XsL_jeG.js} +2 -2
- package/frontend/dist/assets/{GroupsPage-BN8Zp5i8.js.map → GroupsPage--XsL_jeG.js.map} +1 -1
- package/frontend/dist/assets/{LoginPage-CykN_c-N.js → LoginPage-B6FzN2_o.js} +2 -2
- package/frontend/dist/assets/{LoginPage-CykN_c-N.js.map → LoginPage-B6FzN2_o.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-cTSP1Ych.js → LogsPage-DonCddYQ.js} +2 -2
- package/frontend/dist/assets/{LogsPage-cTSP1Ych.js.map → LogsPage-DonCddYQ.js.map} +1 -1
- package/frontend/dist/assets/{MarketPage-3wD6aBlw.js → MarketPage-DlA2aXU9.js} +2 -2
- package/frontend/dist/assets/{MarketPage-3wD6aBlw.js.map → MarketPage-DlA2aXU9.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-DCki8rQ_.js → PromptsPage-DTPJHm1Y.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-DCki8rQ_.js.map → PromptsPage-DTPJHm1Y.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-BQouQx0Z.js → ResourcesPage-Dwjs_zER.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-BQouQx0Z.js.map → ResourcesPage-Dwjs_zER.js.map} +1 -1
- package/frontend/dist/assets/{ServersPage-Csxre8tN.js → ServersPage-9Ku6lufR.js} +4 -4
- package/frontend/dist/assets/{ServersPage-Csxre8tN.js.map → ServersPage-9Ku6lufR.js.map} +1 -1
- package/frontend/dist/assets/SettingsPage-DpM-PtFb.js +12 -0
- package/frontend/dist/assets/SettingsPage-DpM-PtFb.js.map +1 -0
- package/frontend/dist/assets/{StatusDot-Bue_Np95.js → StatusDot-BLQQqKOH.js} +2 -2
- package/frontend/dist/assets/{StatusDot-Bue_Np95.js.map → StatusDot-BLQQqKOH.js.map} +1 -1
- package/frontend/dist/assets/{ToggleGroup-tOnB-V7o.js → ToggleGroup-DoqIEGtu.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-tOnB-V7o.js.map → ToggleGroup-DoqIEGtu.js.map} +1 -1
- package/frontend/dist/assets/{UsersPage-TnUA9-uw.js → UsersPage-DzxtbiCa.js} +2 -2
- package/frontend/dist/assets/{UsersPage-TnUA9-uw.js.map → UsersPage-DzxtbiCa.js.map} +1 -1
- package/frontend/dist/assets/index-R7UAqPfE.js +3 -0
- package/frontend/dist/assets/index-R7UAqPfE.js.map +1 -0
- package/frontend/dist/assets/{resourceService-CQlrCAEY.js → resourceService-BpwGqVJZ.js} +2 -2
- package/frontend/dist/assets/{resourceService-CQlrCAEY.js.map → resourceService-BpwGqVJZ.js.map} +1 -1
- package/frontend/dist/assets/{useServerData-DP0ud49e.js → useServerData-CPGo5oC7.js} +2 -2
- package/frontend/dist/assets/{useServerData-DP0ud49e.js.map → useServerData-CPGo5oC7.js.map} +1 -1
- package/frontend/dist/assets/useSettingsData-cUOCzPSG.js +2 -0
- package/frontend/dist/assets/{useSettingsData-BoWRW73A.js.map → useSettingsData-cUOCzPSG.js.map} +1 -1
- package/frontend/dist/index.html +1 -1
- package/package.json +1 -1
- package/frontend/dist/assets/SettingsPage-ByIy81yn.js +0 -12
- package/frontend/dist/assets/SettingsPage-ByIy81yn.js.map +0 -1
- package/frontend/dist/assets/index-B49EwZHb.js +0 -3
- package/frontend/dist/assets/index-B49EwZHb.js.map +0 -1
- package/frontend/dist/assets/useSettingsData-BoWRW73A.js +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-
|
|
2
|
-
import{r as m,j as e,b as Ge}from"./framework-vendor-BUhDPOUZ.js";import{e as se,f as Fe,h as be,i as we,_ as ge,j as Ke,k as Xe,l as Ze}from"./index-B49EwZHb.js";import{S as Qe}from"./StatusDot-Bue_Np95.js";import{u as ke}from"./useSettingsData-BoWRW73A.js";import{S as Ce}from"./ToggleGroup-tOnB-V7o.js";import{u as Q}from"./i18n-vendor-Kbr87Ofu.js";import{l as Re,m as $e,j as je,n as Ye,C as de,o as fe,p as Se,q as Oe,r as _e,s as Ee,k as ye,X as ve,W as ze,f as Te,F as De,E as es,t as ss,R as Ne,T as ts,P as rs,u as ns,v as as,w as os}from"./icons-vendor-CKgJB3SC.js";import{D as ls}from"./DeleteDialog-DRbWonMu.js";import{S as Ae,d as is}from"./variableDetection-DsYuiOB_.js";import{C as cs}from"./ConfirmDialog-CxlizGia.js";import{P as ds}from"./Pagination-BFi-X7qY.js";import{u as ms}from"./useServerData-DP0ud49e.js";const Je=async(s,o)=>{try{const t=o?`/tools/${encodeURIComponent(o)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await se(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:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},us=async(s,o,t)=>{try{const n=await se(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Me=async(s,o,t)=>{try{const n=await be(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Ue=async(s,o)=>{var t;try{const n=await Fe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ps=Object.freeze(Object.defineProperty({__proto__:null,callTool:Je,resetToolDescription:Ue,toggleTool:us,updateToolDescription:Me},Symbol.toStringTag,{value:"Module"})),Be=({schema:s,onSubmit:o,onCancel:t,loading:n=!1,storageKey:i,title:f})=>{const{t:r}=Q(),[x,T]=m.useState({}),[I,d]=m.useState({}),[b,R]=m.useState(!1),[v,F]=m.useState(""),[N,E]=m.useState(""),g=m.useMemo(()=>(c=>{const k=a=>{if(typeof a=="object"&&a!==null){const u=a;return{type:u.type||"string",description:u.description,enum:u.enum,default:u.default,properties:u.properties?Object.fromEntries(Object.entries(u.properties).map(([l,j])=>[l,k(j)])):void 0,required:u.required,items:u.items?k(u.items):void 0}}return{type:"string"}};return{type:c.type,properties:c.properties?Object.fromEntries(Object.entries(c.properties).map(([a,u])=>[a,k(u)])):void 0,required:c.required}})(s),[s]);m.useEffect(()=>{const h=(k,a="")=>{const u={};return k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([l,j])=>{const C=a?`${a}.${l}`:l;j.default!==void 0?u[l]=j.default:j.type==="string"?u[l]="":j.type==="number"||j.type==="integer"?u[l]=0:j.type==="boolean"?u[l]=!1:j.type==="array"?u[l]=[]:j.type==="object"&&(j.properties?u[l]=h(j,C):u[l]={})}),u};let c=h(g);if(i)try{const k=localStorage.getItem(i);if(k){const a=JSON.parse(k);c={...c,...a}}}catch(k){console.warn("Failed to load saved form data:",k)}T(c)},[g,i]),m.useEffect(()=>{b&&Object.keys(x).length>0&&(F(JSON.stringify(x,null,2)),E(""))},[b,x]);const O=h=>{F(h),E("");try{const c=JSON.parse(h);if(T(c),i)try{localStorage.setItem(i,JSON.stringify(c))}catch(k){console.warn("Failed to save form data to localStorage:",k)}}catch{E(r("tool.invalidJsonFormat"))}},$=()=>{F(JSON.stringify(x,null,2)),E(""),R(!0)},z=()=>{if(v.trim())try{const h=JSON.parse(v);T(h),E(""),R(!1)}catch{E(r("tool.fixJsonBeforeSwitching"));return}else R(!1)},A=(h,c)=>{T(k=>{const a={...k},u=h.split(".");let l=a;for(let j=0;j<u.length-1;j++)l[u[j]]||(l[u[j]]={}),l=l[u[j]];if(l[u[u.length-1]]=c,i)try{localStorage.setItem(i,JSON.stringify(a))}catch(j){console.warn("Failed to save form data to localStorage:",j)}return a}),I[h]&&d(k=>{const a={...k};return delete a[h],a})},W=()=>{const h={},c=(k,a,u="")=>{k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([l,j])=>{var V;const C=u?`${u}.${l}`:l,D=a==null?void 0:a[l];if((V=k.required)!=null&&V.includes(l)&&(D==null||D===""||Array.isArray(D)&&D.length===0)){h[C]=`${l} is required`;return}D!=null&&D!==""&&(j.type==="string"&&typeof D!="string"?h[C]=`${l} must be a string`:j.type==="number"&&typeof D!="number"?h[C]=`${l} must be a number`:j.type==="integer"&&(!Number.isInteger(D)||typeof D!="number")?h[C]=`${l} must be an integer`:j.type==="boolean"&&typeof D!="boolean"?h[C]=`${l} must be a boolean`:j.type==="array"&&Array.isArray(D)?j.items&&D.forEach((w,J)=>{var S;((S=j.items)==null?void 0:S.type)==="object"&&j.items.properties&&c(j.items,w,`${C}.${J}`)}):j.type==="object"&&typeof D=="object"&&c(j,D,C))})};return c(g,x),d(h),Object.keys(h).length===0},B=h=>{h.preventDefault(),W()&&o(x)},H=(h,c)=>c.split(".").reduce((k,a)=>k==null?void 0:k[a],h),K=(h,c,k,a)=>{const u=k==null?void 0:k[h];return c.type==="string"?c.enum?e.jsxs("select",{value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:r("tool.selectOption")}),c.enum.map((l,j)=>e.jsx("option",{value:l,children:l},j))]}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:c.description||r("tool.enterKey",{key:h})}):c.type==="number"||c.type==="integer"?e.jsx("input",{type:"number",step:c.type==="integer"?"1":"any",value:u??"",onChange:l=>{const j=l.target.value===""?"":c.type==="integer"?parseInt(l.target.value):parseFloat(l.target.value);a(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"}):c.type==="boolean"?e.jsx("input",{type:"checkbox",checked:u||!1,onChange:l=>a(l.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:c.description||r("tool.enterKey",{key:h})})},M=(h,c,k="")=>{var j,C,D,V,w,J,S,U,te,re,me,ue,pe,xe;const a=k?`${k}.${h}`:h,u=H(x,a),l=I[a];if(c.type==="array"){const _=H(x,a)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(C=(j=H(g,k))==null?void 0:j.required)==null?void 0:C.includes(h):(D=g.required)==null?void 0:D.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[_.map((G,X)=>{var ae,oe,le;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:r("tool.item",{index:X+1})}),e.jsx("button",{type:"button",onClick:()=>{const q=[..._];q.splice(X,1),A(a,q)},className:"text-status-red hover:text-red-700 text-sm",children:r("common.remove")})]}),((ae=c.items)==null?void 0:ae.type)==="string"&&c.items.enum?e.jsxs("select",{value:G||"",onChange:q=>{const Z=[..._];Z[X]=q.target.value,A(a,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:r("tool.selectOption")}),c.items.enum.map((q,Z)=>e.jsx("option",{value:q,children:q},Z))]}):((oe=c.items)==null?void 0:oe.type)==="object"&&c.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(c.items.properties).map(([q,Z])=>{var ie,ce;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[q,((ce=(ie=c.items)==null?void 0:ie.required)==null?void 0:ce.includes(q))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(q,Z,G,he=>{const p=[..._];p[X]={...p[X],[q]:he},A(a,p)})]},q)})}):e.jsx("input",{type:"text",value:G||"",onChange:q=>{const Z=[..._];Z[X]=q.target.value,A(a,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:r("tool.enterValue",{type:((le=c.items)==null?void 0:le.type)||"value"})})]},X)}),e.jsx("button",{type:"button",onClick:()=>{var X;const G=((X=c.items)==null?void 0:X.type)==="object"?{}:"";A(a,[..._,G])},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:r("tool.addItem",{key:h})})]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a)}return c.type==="object"?c.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(w=(V=H(g,k))==null?void 0:V.required)==null?void 0:w.includes(h):(J=g.required)==null?void 0:J.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(c.properties).map(([_,G])=>M(_,G,a))}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(U=(S=H(g,k))==null?void 0:S.required)==null?void 0:U.includes(h):(te=g.required)==null?void 0:te.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("textarea",{value:typeof u=="object"?JSON.stringify(u,null,2):u||"{}",onChange:_=>{try{const G=JSON.parse(_.target.value);A(a,G)}catch{A(a,_.target.value)}},placeholder:`{
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-BpwGqVJZ.js","./index-R7UAqPfE.js","./framework-vendor-BUhDPOUZ.js","./i18n-vendor-Kbr87Ofu.js","./icons-vendor-CKgJB3SC.js","./index-D0OIBhmN.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as m,j as e,b as Ge}from"./framework-vendor-BUhDPOUZ.js";import{e as se,f as Fe,h as be,i as we,_ as ge,j as Ke,k as Xe,l as Ze}from"./index-R7UAqPfE.js";import{S as Qe}from"./StatusDot-BLQQqKOH.js";import{u as ke}from"./useSettingsData-cUOCzPSG.js";import{S as Ce}from"./ToggleGroup-DoqIEGtu.js";import{u as Q}from"./i18n-vendor-Kbr87Ofu.js";import{l as Re,m as $e,j as je,n as Ye,C as de,o as fe,p as Se,q as Oe,r as _e,s as Ee,k as ye,X as ve,W as ze,f as Te,F as De,E as es,t as ss,R as Ne,T as ts,P as rs,u as ns,v as as,w as os}from"./icons-vendor-CKgJB3SC.js";import{D as ls}from"./DeleteDialog-DRbWonMu.js";import{S as Ae,d as is}from"./variableDetection-DsYuiOB_.js";import{C as cs}from"./ConfirmDialog-CxlizGia.js";import{P as ds}from"./Pagination-BFi-X7qY.js";import{u as ms}from"./useServerData-CPGo5oC7.js";const Je=async(s,o)=>{try{const t=o?`/tools/${encodeURIComponent(o)}/${encodeURIComponent(s.toolName)}`:"/tools/call",n=await se(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:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},us=async(s,o,t)=>{try{const n=await se(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Me=async(s,o,t)=>{try{const n=await be(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Ue=async(s,o)=>{var t;try{const n=await Fe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ps=Object.freeze(Object.defineProperty({__proto__:null,callTool:Je,resetToolDescription:Ue,toggleTool:us,updateToolDescription:Me},Symbol.toStringTag,{value:"Module"})),Be=({schema:s,onSubmit:o,onCancel:t,loading:n=!1,storageKey:i,title:f})=>{const{t:r}=Q(),[x,T]=m.useState({}),[I,d]=m.useState({}),[b,R]=m.useState(!1),[v,F]=m.useState(""),[N,E]=m.useState(""),g=m.useMemo(()=>(c=>{const k=a=>{if(typeof a=="object"&&a!==null){const u=a;return{type:u.type||"string",description:u.description,enum:u.enum,default:u.default,properties:u.properties?Object.fromEntries(Object.entries(u.properties).map(([l,j])=>[l,k(j)])):void 0,required:u.required,items:u.items?k(u.items):void 0}}return{type:"string"}};return{type:c.type,properties:c.properties?Object.fromEntries(Object.entries(c.properties).map(([a,u])=>[a,k(u)])):void 0,required:c.required}})(s),[s]);m.useEffect(()=>{const h=(k,a="")=>{const u={};return k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([l,j])=>{const C=a?`${a}.${l}`:l;j.default!==void 0?u[l]=j.default:j.type==="string"?u[l]="":j.type==="number"||j.type==="integer"?u[l]=0:j.type==="boolean"?u[l]=!1:j.type==="array"?u[l]=[]:j.type==="object"&&(j.properties?u[l]=h(j,C):u[l]={})}),u};let c=h(g);if(i)try{const k=localStorage.getItem(i);if(k){const a=JSON.parse(k);c={...c,...a}}}catch(k){console.warn("Failed to load saved form data:",k)}T(c)},[g,i]),m.useEffect(()=>{b&&Object.keys(x).length>0&&(F(JSON.stringify(x,null,2)),E(""))},[b,x]);const O=h=>{F(h),E("");try{const c=JSON.parse(h);if(T(c),i)try{localStorage.setItem(i,JSON.stringify(c))}catch(k){console.warn("Failed to save form data to localStorage:",k)}}catch{E(r("tool.invalidJsonFormat"))}},$=()=>{F(JSON.stringify(x,null,2)),E(""),R(!0)},z=()=>{if(v.trim())try{const h=JSON.parse(v);T(h),E(""),R(!1)}catch{E(r("tool.fixJsonBeforeSwitching"));return}else R(!1)},A=(h,c)=>{T(k=>{const a={...k},u=h.split(".");let l=a;for(let j=0;j<u.length-1;j++)l[u[j]]||(l[u[j]]={}),l=l[u[j]];if(l[u[u.length-1]]=c,i)try{localStorage.setItem(i,JSON.stringify(a))}catch(j){console.warn("Failed to save form data to localStorage:",j)}return a}),I[h]&&d(k=>{const a={...k};return delete a[h],a})},W=()=>{const h={},c=(k,a,u="")=>{k.type==="object"&&k.properties&&Object.entries(k.properties).forEach(([l,j])=>{var V;const C=u?`${u}.${l}`:l,D=a==null?void 0:a[l];if((V=k.required)!=null&&V.includes(l)&&(D==null||D===""||Array.isArray(D)&&D.length===0)){h[C]=`${l} is required`;return}D!=null&&D!==""&&(j.type==="string"&&typeof D!="string"?h[C]=`${l} must be a string`:j.type==="number"&&typeof D!="number"?h[C]=`${l} must be a number`:j.type==="integer"&&(!Number.isInteger(D)||typeof D!="number")?h[C]=`${l} must be an integer`:j.type==="boolean"&&typeof D!="boolean"?h[C]=`${l} must be a boolean`:j.type==="array"&&Array.isArray(D)?j.items&&D.forEach((w,J)=>{var S;((S=j.items)==null?void 0:S.type)==="object"&&j.items.properties&&c(j.items,w,`${C}.${J}`)}):j.type==="object"&&typeof D=="object"&&c(j,D,C))})};return c(g,x),d(h),Object.keys(h).length===0},B=h=>{h.preventDefault(),W()&&o(x)},H=(h,c)=>c.split(".").reduce((k,a)=>k==null?void 0:k[a],h),K=(h,c,k,a)=>{const u=k==null?void 0:k[h];return c.type==="string"?c.enum?e.jsxs("select",{value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:r("tool.selectOption")}),c.enum.map((l,j)=>e.jsx("option",{value:l,children:l},j))]}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:c.description||r("tool.enterKey",{key:h})}):c.type==="number"||c.type==="integer"?e.jsx("input",{type:"number",step:c.type==="integer"?"1":"any",value:u??"",onChange:l=>{const j=l.target.value===""?"":c.type==="integer"?parseInt(l.target.value):parseFloat(l.target.value);a(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"}):c.type==="boolean"?e.jsx("input",{type:"checkbox",checked:u||!1,onChange:l=>a(l.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:u||"",onChange:l=>a(l.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:c.description||r("tool.enterKey",{key:h})})},M=(h,c,k="")=>{var j,C,D,V,w,J,S,U,te,re,me,ue,pe,xe;const a=k?`${k}.${h}`:h,u=H(x,a),l=I[a];if(c.type==="array"){const _=H(x,a)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(C=(j=H(g,k))==null?void 0:j.required)==null?void 0:C.includes(h):(D=g.required)==null?void 0:D.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[_.map((G,X)=>{var ae,oe,le;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:r("tool.item",{index:X+1})}),e.jsx("button",{type:"button",onClick:()=>{const q=[..._];q.splice(X,1),A(a,q)},className:"text-status-red hover:text-red-700 text-sm",children:r("common.remove")})]}),((ae=c.items)==null?void 0:ae.type)==="string"&&c.items.enum?e.jsxs("select",{value:G||"",onChange:q=>{const Z=[..._];Z[X]=q.target.value,A(a,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:r("tool.selectOption")}),c.items.enum.map((q,Z)=>e.jsx("option",{value:q,children:q},Z))]}):((oe=c.items)==null?void 0:oe.type)==="object"&&c.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(c.items.properties).map(([q,Z])=>{var ie,ce;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[q,((ce=(ie=c.items)==null?void 0:ie.required)==null?void 0:ce.includes(q))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),K(q,Z,G,he=>{const p=[..._];p[X]={...p[X],[q]:he},A(a,p)})]},q)})}):e.jsx("input",{type:"text",value:G||"",onChange:q=>{const Z=[..._];Z[X]=q.target.value,A(a,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:r("tool.enterValue",{type:((le=c.items)==null?void 0:le.type)||"value"})})]},X)}),e.jsx("button",{type:"button",onClick:()=>{var X;const G=((X=c.items)==null?void 0:X.type)==="object"?{}:"";A(a,[..._,G])},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:r("tool.addItem",{key:h})})]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a)}return c.type==="object"?c.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(w=(V=H(g,k))==null?void 0:V.required)==null?void 0:w.includes(h):(J=g.required)==null?void 0:J.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(c.properties).map(([_,G])=>M(_,G,a))}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?(U=(S=H(g,k))==null?void 0:S.required)==null?void 0:U.includes(h):(te=g.required)==null?void 0:te.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("textarea",{value:typeof u=="object"?JSON.stringify(u,null,2):u||"{}",onChange:_=>{try{const G=JSON.parse(_.target.value);A(a,G)}catch{A(a,_.target.value)}},placeholder:`{
|
|
3
3
|
"key": "value"
|
|
4
4
|
}`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="string"?c.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?!1:(re=g.required)==null?void 0:re.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsxs("select",{value:u||"",onChange:_=>A(a,_.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:r("tool.selectOption")}),c.enum.map((_,G)=>e.jsx("option",{value:_,children:_},G))]}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?!1:(me=g.required)==null?void 0:me.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"text",value:u||"",onChange:_=>A(a,_.target.value),className:`w-full border rounded-md px-3 py-2 ${l?"border-red":"border-gray-200"} focus:outline-none form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="number"||c.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?!1:(ue=g.required)==null?void 0:ue.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"number",step:c.type==="integer"?"1":"any",value:u??"",onChange:_=>{const G=_.target.value===""?"":c.type==="integer"?parseInt(_.target.value):parseFloat(_.target.value);A(a,G)},className:`w-full border rounded-md px-3 py-2 form-input ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):c.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:u||!1,onChange:_=>A(a,_.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[h,(k?!1:(pe=g.required)==null?void 0:pe.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:c.description}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(k?!1:(xe=g.required)==null?void 0:xe.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",c.type,")"]})]}),c.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:c.description}),e.jsx("input",{type:"text",value:u||"",onChange:_=>A(a,_.target.value),placeholder:r("tool.enterValue",{type:c.type}),className:`w-full border rounded-md px-3 py-2 ${l?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),l&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:l})]},a)};return g.properties?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-3",children:[e.jsx("h6",{className:"text-md font-medium text-gray-900",children:f}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:z,className:`hub-btn sm ${b?"":"primary"}`,children:r("tool.formMode")}),e.jsx("button",{type:"button",onClick:$,className:`hub-btn sm ${b?"primary":""}`,children:r("tool.jsonMode")})]})]}),b?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:r("tool.jsonConfiguration")}),e.jsx("textarea",{value:v,onChange:h=>O(h.target.value),placeholder:`{
|
|
5
5
|
"key": "value"
|
|
6
|
-
}`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${N?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),N&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:N})]}),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:r("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const h=JSON.parse(v);o(h)}catch{E(r("tool.invalidJsonFormat"))}},disabled:n||!!N,className:"hub-btn sm primary",children:r(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[Object.entries(g.properties||{}).map(([h,c])=>M(h,c)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:r("tool.cancel")}),e.jsx("button",{type:"submit",disabled:n,className:"hub-btn sm primary",children:r(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:r("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:r("tool.cancel")}),e.jsx("button",{onClick:()=>o({}),disabled:n,className:"hub-btn primary",children:r(n?"tool.running":"tool.runTool")})]})]})},xs=({result:s,onClose:o})=>{const{t}=Q(),n=s.content,i=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",f=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(v=>f(v));if(typeof d!="object")return[];const b=[];d.type==="image"&&d.data&&b.push({data:String(d.data),mimeType:i(d.mimeType||d.mime_type)});const R=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return R&&b.push({data:String(R),mimeType:i(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&b.push(...f(d.image)),Array.isArray(d.images)&&b.push(...f(d.images)),Array.isArray(d.content)&&b.push(...f(d.content)),b},r=d=>{const b=[];try{const F=JSON.parse(d);if(b.push(...f(F)),b.length>0)return b}catch{}const R=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let v;for(;(v=R.exec(d))!==null;){const F=`image/${v[1]==="jpg"?"jpeg":v[1]}`;b.push({data:v[2],mimeType:F})}return b},x=d=>{try{const b=JSON.parse(d),R=v=>{if(Array.isArray(v))return v.map(R);if(v&&typeof v=="object"){const F={};for(const[N,E]of Object.entries(v))typeof E=="string"&&N.toLowerCase().includes("base64")?F[N]="[base64 omitted]":F[N]=R(E);return F}return v};return JSON.stringify(R(b),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},T=d=>Array.isArray(d)?d.map((b,R)=>e.jsx("div",{className:"mb-3 last:mb-0",children:I(b)},R)):I(d),I=d=>{if(typeof d=="string"){const b=r(d),R=x(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[b.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:b.map((v,F)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:R})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const b=r(d.text),R=x(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[b.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:b.map((v,F)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:R})]})}if(d.type==="image"&&d.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${d.mimeType||"image/png"};base64,${d.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const b=typeof d=="string"?JSON.parse(d):d;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(b,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Re,{size:20,className:"text-status-green"}):e.jsx($e,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:o,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),T(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),n&&n.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),T(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")})})]})})]})},ne=({title:s,onClick:o,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:o,disabled:t,title:s,"aria-label":s,children:e.jsx(Ye,{size:14,className:n?"animate-spin":""})});function hs(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 gs=({tool:s,server:o,onToggle:t,onDescriptionUpdate:n})=>{const{t:i}=Q(),{showToast:f}=we(),{nameSeparator:r}=ke(),[x,T]=m.useState(!1),[I,d]=m.useState(!1),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,H]=m.useState(0),[K,M]=m.useState(!1);m.useEffect(()=>{N&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[N,B]),m.useEffect(()=>{!N&&W.current&&H(W.current.offsetWidth)},[N,$]),m.useEffect(()=>{z(s.description||"")},[s.description]);const h=m.useCallback(()=>`mcphub_tool_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),c=m.useCallback(()=>{localStorage.removeItem(h())},[h]),k=S=>{t&&t(s.name,S)},a=()=>{E(!0)},u=async()=>{try{const S=await Me(o,s.name,$);S.success?(E(!1),n&&n(s.name,$)):(z(s.description||""),console.error("Failed to update tool description:",S.error))}catch(S){console.error("Error updating tool description:",S),z(s.description||""),E(!1)}},l=S=>{z(S.target.value)},j=async()=>{O(!0);try{const S=await Ue(o,s.name);if(S.success){const U=S.description||"";z(U),E(!1),n==null||n(s.name,U,{restored:!0})}else f(S.error||i("tool.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting tool description:",S),f(i("tool.restoreDefaultFailed"),"error")}finally{O(!1)}},C=S=>{S.key==="Enter"?u():S.key==="Escape"&&(z(s.description||""),E(!1))},D=async S=>{S.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),M(!0),f(i("common.copySuccess"),"success"),setTimeout(()=>M(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),M(!0),f(i("common.copySuccess"),"success"),setTimeout(()=>M(!1),2e3)}catch(te){f(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",te)}document.body.removeChild(U)}}catch(U){f(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},V=async S=>{R(!0);try{S=Object.fromEntries(Object.entries(S).filter(([te,re])=>!hs(re)));const U=await Je({toolName:s.name,arguments:S},o);F(U)}catch(U){F({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{R(!1)}},w=()=>{d(!1),c(),F(null)},J=()=>{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:S=>{S.stopPropagation(),T(!x)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+r,"")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:D,title:i("common.copy"),children:K?e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(fe,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:N?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:$,onChange:l,onKeyDown:C,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),u()},disabled:g,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),j()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:$||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),a()},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),j()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:S=>S.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled??!0,onCheckedChange:k,disabled:b})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:b||!s.enabled,children:[b?e.jsx(Oe,{size:12,className:"animate-spin"}):e.jsx(_e,{size:12}),e.jsx("span",{children:i(b?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:x?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),x&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[!I&&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)})]}),I&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Be,{schema:s.inputSchema||{type:"object"},onSubmit:V,onCancel:w,loading:b,storageKey:h(),title:i("tool.runToolWithName",{name:s.name.replace(o+r,"")})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(xs,{result:v,onClose:J})})]})]})]})},fs=async(s,o)=>{try{const t=o?`/prompts/call/${o}`:"/prompts/call",n=await se(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:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ve=async(s,o)=>{try{const t=await se(`/mcp/${encodeURIComponent(o||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},bs=async(s,o,t)=>{try{const n=await se(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},We=async(s,o,t)=>{try{const n=await be(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Le=async(s,o)=>{var t;try{const n=await Fe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},js=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:fs,getPrompt:Ve,resetPromptDescription:Le,togglePrompt:bs,updatePromptDescription:We},Symbol.toStringTag,{value:"Module"})),Pe=({result:s,onClose:o})=>{const{t}=Q(),n=i=>{if(typeof i=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:i})});if(typeof i=="object"&&i!==null){if(i.description||i.messages)return e.jsxs("div",{className:"space-y-4",children:[i.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:i.description})})]}),i.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:i.messages.map((f,r)=>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:[f.role,":"]})}),typeof f.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:f.content}):typeof f.content=="object"&&f.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:f.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f.content,null,2)})]},r))})]})]});try{const f=typeof i=="string"?JSON.parse(i):i;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(i)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(i)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Re,{size:20,className:"text-status-green"}):e.jsx($e,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:o,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),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(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")})})]})})]})},ys=({prompt:s,server:o,onToggle:t,onDescriptionUpdate:n})=>{const{t:i}=Q(),{showToast:f}=we(),{nameSeparator:r}=ke(),[x,T]=m.useState(!1),[I,d]=m.useState(!1),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,H]=m.useState(0);m.useEffect(()=>{N&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[N,B]),m.useEffect(()=>{!N&&W.current&&H(W.current.offsetWidth)},[N,$]),m.useEffect(()=>{z(s.description||"")},[s.description]);const K=m.useCallback(()=>`mcphub_prompt_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),M=m.useCallback(()=>{localStorage.removeItem(K())},[K]),h=w=>{t&&t(s.name,w)},c=()=>{E(!0)},k=async()=>{E(!1);try{const w=await We(o,s.name,$);w.success?n&&n(s.name,$):(f(w.error||i("prompt.descriptionUpdateFailed"),"error"),z(s.description||""))}catch(w){console.error("Error updating prompt description:",w),f(i("prompt.descriptionUpdateFailed"),"error"),z(s.description||"")}},a=async()=>{O(!0);try{const w=await Le(o,s.name);if(w.success){const J=w.description||"";z(J),E(!1),n==null||n(s.name,J,{restored:!0})}else f(w.error||i("prompt.restoreDefaultFailed"),"error")}catch(w){console.error("Error resetting prompt description:",w),f(i("prompt.restoreDefaultFailed"),"error")}finally{O(!1)}},u=w=>{z(w.target.value)},l=w=>{w.key==="Enter"?k():w.key==="Escape"&&(z(s.description||""),E(!1))},j=async w=>{R(!0);try{const J=await Ve({promptName:s.name,arguments:w},o);console.log("GetPrompt result:",J),F({success:J.success,data:J.data,error:J.error})}catch(J){F({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{R(!1)}},C=()=>{d(!1),M(),F(null)},D=()=>{F(null)},V=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const w={},J=[];return s.arguments.forEach(S=>{w[S.name]={type:"string",description:S.description||""},S.required&&J.push(S.name)}),{type:"object",properties:w,required:J}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>T(!x),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+r,"")}),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:N?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:$,onChange:u,onKeyDown:l,onClick:w=>w.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),k()},disabled:g,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:i("prompt.restoreDefault"),onClick:w=>{w.stopPropagation(),a()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:$||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),c()},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:i("prompt.restoreDefault"),onClick:w=>{w.stopPropagation(),a()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:w=>w.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ce,{checked:s.enabled,onCheckedChange:h,disabled:b})}),e.jsxs("button",{onClick:w=>{w.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:b||!s.enabled,children:[b?e.jsx(Oe,{size:12,className:"animate-spin"}):e.jsx(_e,{size:12}),e.jsx("span",{children:i(b?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:x?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),x&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[I&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Be,{schema:V(),onSubmit:j,onCancel:C,loading:b,storageKey:K(),title:i("prompt.runPromptWithName",{name:s.name.replace(o+r,"")})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Pe,{result:v,onClose:D})})]}),!I&&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((w,J)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:w.name}),w.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),w.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:w.description})]}),w.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:w.title})]},J))})]}),!I&&v&&e.jsx("div",{children:e.jsx(Pe,{result:v,onClose:D})})]})]})},vs=({resource:s,onToggle:o,onDescriptionUpdate:t})=>{const{t:n}=Q(),[i,f]=m.useState(!1),[r,x]=m.useState(!1),[T,I]=m.useState(!1),[d,b]=m.useState(s.description||""),R=m.useRef(null),v=m.useRef(null),[F,N]=m.useState(0);m.useEffect(()=>{r&&R.current&&(R.current.focus(),F>0&&(R.current.style.width=`${F+20}px`))},[r,F]),m.useEffect(()=>{!r&&v.current&&N(v.current.offsetWidth)},[r,d]),m.useEffect(()=>{b(s.description||"")},[s.description]);const E=z=>{o&&o(s.uri,z)},g=async()=>{x(!1),t&&await t(s.uri,d)},O=async()=>{I(!0);try{await(t==null?void 0:t(s.uri,"",{restored:!0})),x(!1)}finally{I(!1)}},$=z=>{z.key==="Enter"?g():z.key==="Escape"&&(b(s.description||""),x(!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:()=>f(!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:r?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:R,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:F>0?`${F+20}px`:160,minWidth:80},value:d,onChange:z=>b(z.target.value),onKeyDown:$,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),g()},disabled:T,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:n("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:d||n("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),x(!0)},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:n("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:z=>z.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled!==!1,onCheckedChange:E})}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[n("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Ie=(s,o)=>o?o==="stdio"?s("server.typeStdio")||"stdio":o==="sse"?s("server.typeSse")||"sse":o==="streamable-http"?s("server.typeStreamableHttp")||"http":o==="openapi"?s("server.typeOpenapi")||"openapi":o:null,Ns=({server:s,onRemove:o,onEdit:t,onToggle:n,onRefresh:i,onReload:f})=>{var X,ae,oe,le,q,Z,ie,ce,he;const{t:r}=Q(),{showToast:x}=we(),{exportMCPSettings:T,installConfig:I}=ke(),d=((X=I==null?void 0:I.baseUrl)==null?void 0:X.replace(/\/+$/,""))||"",[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(!1),[A,W]=m.useState(!1),[B,H]=m.useState(!1),[K,M]=m.useState(!1),h=m.useRef(null),c=m.useRef(null);m.useEffect(()=>{const p=y=>{h.current&&!h.current.contains(y.target)&&W(!1),c.current&&!c.current.contains(y.target)&&H(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]);const k=((ae=s.tools)==null?void 0:ae.length)||0,a=((oe=s.tools)==null?void 0:oe.filter(p=>p.enabled!==!1).length)||0,u=((le=s.prompts)==null?void 0:le.length)||0,l=((q=s.prompts)==null?void 0:q.filter(p=>p.enabled!==!1).length)||0,j=((Z=s.resources)==null?void 0:Z.length)||0,C=((ie=s.resources)==null?void 0:ie.filter(p=>p.enabled!==!1).length)||0,D=async p=>{if(p.stopPropagation(),!(g||!n)){O(!0);try{await n(s,s.enabled===!1)}finally{O(!1)}}},V=async p=>{if(p.stopPropagation(),W(!1),!($||!f)){z(!0);try{await f(s)?x(r("server.reloadSuccess")||"Server reloaded successfully","success"):x(r("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{z(!1)}}},w=async p=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(p),!0}catch{}try{const y=document.createElement("textarea");y.value=p,y.style.position="fixed",y.style.left="-9999px",document.body.appendChild(y),y.focus(),y.select();const P=document.execCommand("copy");return document.body.removeChild(y),P}catch{return!1}},J=async p=>{if(p.stopPropagation(),!s.error)return;await w(s.error)?(M(!0),x(r("common.copySuccess")||"Copied","success"),setTimeout(()=>M(!1),1500)):x(r("common.copyFailed")||"Copy failed","error")},S=async p=>{p.stopPropagation(),W(!1);try{const y=await T(s.name);if(!y||!y.success||!y.data){x((y==null?void 0:y.message)||r("common.copyFailed")||"Copy failed","error");return}const P=JSON.stringify(y.data,null,2),L=await w(P);x(L?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Copy failed",L?"success":"error")}catch(y){console.error("Error copying server configuration:",y),x(r("common.copyFailed")||"Copy failed","error")}},U=p=>{var y;if(p.stopPropagation(),(y=s.oauth)!=null&&y.authorizationUrl){const Y=window.screen.width/2-300,ee=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${Y},top=${ee}`),x(r("status.oauthWindowOpened"),"info")}},te=async(p,y)=>{try{const{toggleTool:P}=await ge(async()=>{const{toggleTool:Y}=await Promise.resolve().then(()=>ps);return{toggleTool:Y}},void 0,import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},re=async(p,y)=>{try{const{togglePrompt:P}=await ge(async()=>{const{togglePrompt:Y}=await Promise.resolve().then(()=>js);return{togglePrompt:Y}},void 0,import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},me=async(p,y)=>{try{const{toggleResource:P}=await ge(async()=>{const{toggleResource:Y}=await import("./resourceService-CQlrCAEY.js");return{toggleResource:Y}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},ue=(p,y,P)=>{x(P!=null&&P.restored?r("tool.restoreDefaultSuccess"):r("tool.descriptionUpdateSuccess"),"success"),i==null||i()},pe=(p,y,P)=>{x(P!=null&&P.restored?r("prompt.restoreDefaultSuccess"):r("prompt.descriptionUpdateSuccess"),"success"),i==null||i()},xe=async(p,y,P)=>{try{const{updateResourceDescription:L,resetResourceDescription:Y}=await ge(async()=>{const{updateResourceDescription:qe,resetResourceDescription:He}=await import("./resourceService-CQlrCAEY.js");return{updateResourceDescription:qe,resetResourceDescription:He}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ee=P!=null&&P.restored?await Y(s.name,p):await L(s.name,p,y);ee.success?(x(P!=null&&P.restored?r("builtinResources.restoreDefaultSuccess"):r("builtinResources.descriptionUpdateSuccess"),"success"),i==null||i()):x(ee.error||(P!=null&&P.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed")),"error")}catch(L){console.error(L),x(P!=null&&P.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var P;const p=s.config;if(!p)return"";if(p.url)return p.url;const y=[];return p.command&&y.push(p.command),(P=p.args)!=null&&P.length&&y.push(...p.args),y.join(" ")})();const _=s.enabled!==!1,G=`${d}/mcp/${s.name}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10,opacity:_?1:.7},children:[e.jsxs("div",{className:"grid items-center gap-3 px-4 py-3 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",style:{gridTemplateColumns:"minmax(220px,1.9fr) minmax(110px,0.9fr) minmax(120px,0.95fr) minmax(180px,1.1fr) 72px 36px"},onClick:()=>R(!b),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ye,{size:12,style:{color:"var(--hub-ink-3)",transform:b?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"hub-mono truncate",style:{fontSize:13.5,color:_?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),s.error&&e.jsxs("div",{className:"relative",ref:c,children:[e.jsx("button",{onClick:p=>{p.stopPropagation(),H(y=>!y)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":r("server.viewErrorDetails"),children:e.jsx(je,{size:14})}),B&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:r("server.errorDetails")}),e.jsx("button",{onClick:J,className:"hub-icon-btn sm",title:r("common.copy"),children:K?e.jsx(de,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(fe,{size:12})})]}),e.jsx("button",{onClick:()=>H(!1),className:"hub-icon-btn sm","aria-label":r("app.closeButton"),children:e.jsx(ve,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),((ce=s.config)==null?void 0:ce.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(Qe,{status:s.status,enabled:s.enabled,onAuthClick:U})}),e.jsx("div",{className:"min-w-0",children:(he=s.config)!=null&&he.type?e.jsx("span",{className:"hub-tag",title:Ie(r,s.config.type)??void 0,children:Ie(r,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:[{key:"tools",icon:ze,total:k,enabled:a,label:r("server.tools")},{key:"prompts",icon:Te,total:u,enabled:l,label:r("server.prompts")},{key:"resources",icon:De,total:j,enabled:C,label:r("nav.resources")}].map(({key:p,icon:y,total:P,enabled:L,label:Y})=>{const ee=P===0;return e.jsxs("span",{className:"inline-flex items-center gap-1 hub-mono hub-num",title:`${Y}: ${L}/${P}`,style:{padding:"2px 7px",borderRadius:6,fontSize:11.5,lineHeight:"16px",background:ee?"transparent":"var(--hub-bg-2)",border:"1px solid",borderColor:ee?"transparent":"var(--hub-line-2)",color:ee?"var(--hub-ink-3)":"var(--hub-ink-2)"},children:[e.jsx(y,{size:12,style:{color:"var(--hub-ink-3)",flexShrink:0}}),e.jsx("span",{children:ee?"0":`${L}/${P}`})]},p)})}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{type:"button",className:"hub-switch"+(_?" on":""),onClick:D,disabled:g,"aria-label":r(_?"server.disable":"server.enable")})}),e.jsxs("div",{className:"relative",ref:h,children:[e.jsx("button",{className:"hub-icon-btn",onClick:p=>{p.stopPropagation(),W(y=>!y)},"aria-label":"More",children:e.jsx(es,{size:14})}),A&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:p=>p.stopPropagation(),children:[e.jsxs("button",{onClick:p=>{p.stopPropagation(),W(!1),t(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ss,{size:13})," ",r("server.edit")]}),e.jsxs("button",{onClick:S,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(fe,{size:13})," ",r("server.copy")]}),f&&e.jsxs("button",{onClick:V,disabled:$||g||!_,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(Ne,{size:13})," ",r("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:p=>{p.stopPropagation(),W(!1),E(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(ts,{size:13})," ",r("server.delete")]})]})]})]}),b&&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:[[{key:"tools",icon:e.jsx(ze,{size:12}),label:r("server.tools"),count:k,enabled:a},{key:"prompts",icon:e.jsx(Te,{size:12}),label:r("server.prompts"),count:u,enabled:l},{key:"resources",icon:e.jsx(De,{size:12}),label:r("nav.resources"),count:j,enabled:C}].map(p=>{const y=v===p.key;return e.jsxs("button",{onClick:()=>F(y?null:p.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:y?"var(--hub-surface)":"transparent",border:"1px solid "+(y?"var(--hub-line)":"transparent"),color:y?"var(--hub-ink)":"var(--hub-ink-2)"},children:[p.icon,e.jsx("span",{children:p.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:p.count===0?"0":`${p.enabled}/${p.count}`})]},p.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:G,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async p=>{p.stopPropagation();const y=await w(G);x(y?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Failed",y?"success":"error")},title:r("common.copy"),children:e.jsx(fe,{size:12})})]})})]}),v==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((p,y)=>e.jsx(gs,{server:s.name,tool:p,onToggle:te,onDescriptionUpdate:ue},y))}),v==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((p,y)=>e.jsx(ys,{server:s.name,prompt:p,onToggle:re,onDescriptionUpdate:pe},y))}),v==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:r("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((p,y)=>e.jsx(vs,{resource:p,onToggle:me,onDescriptionUpdate:xe},`${p.uri}-${y}`))})})]})]}),e.jsx(ls,{isOpen:N,onClose:()=>E(!1),onConfirm:()=>{o(s.name),E(!1)},serverName:s.name})]})},ws=({onAdd:s})=>{const{t:o}=Q(),[t,n]=m.useState(!1),[i,f]=m.useState(null),[r,x]=m.useState(!1),[T,I]=m.useState(null),[d,b]=m.useState([]),R=()=>{n(!t),f(null),x(!1),I(null)},v=async()=>{T&&(await F(T),x(!1),I(null))},F=async E=>{try{f(null);const g=await se("/servers",E);if(!g.success){g&&g.message?f(g.message):f(o("server.addError"));return}n(!1),s()}catch(g){console.error("Error adding server:",g),navigator.onLine?g instanceof TypeError&&(g.message.includes("NetworkError")||g.message.includes("Failed to fetch"))?f(o("errors.serverConnection")):f(o("errors.serverAdd")):f(o("errors.network"))}},N=async E=>{try{const g=is(E);g.length>0?(b(g),I(E),x(!0)):await F(E)}catch(g){console.error("Error processing server submission:",g),f(o("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:R,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),o("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ae,{onSubmit:N,onCancel:R,modalTitle:o("server.addServer"),formError:i})}),r&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:o("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:o("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[o("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:d.map((E,g)=>e.jsxs("li",{className:"font-mono",children:["$",`{${E}}`]},g))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:o("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{x(!1),I(null)},className:"hub-btn",children:o("common.cancel")}),e.jsx("button",{onClick:v,className:"hub-btn primary",children:o("server.confirmAndAdd")})]})]})})]})},ks=({server:s,onEdit:o,onCancel:t})=>{const{t:n}=Q(),[i,f]=m.useState(null),r=async x=>{try{f(null);const T=encodeURIComponent(s.name),I=x.name&&x.name!==s.name,d={config:x.config,...I?{newName:x.name}:{}},b=await be(`/servers/${T}`,d);if(!b.success){b&&b.message?f(b.message):f(n("server.updateError",{serverName:s.name}));return}o()}catch(T){console.error("Error updating server:",T),navigator.onLine?T instanceof TypeError&&(T.message.includes("NetworkError")||T.message.includes("Failed to fetch"))?f(n("errors.serverConnection")):f(n("errors.serverUpdate",{serverName:s.name})):f(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(Ae,{onSubmit:r,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:i})})},Cs=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[n,i]=m.useState(!1),[f,r]=m.useState(!1),[x,T]=m.useState(null),[I,d]=m.useState(null),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(""),[g,O]=m.useState(!1),[$,z]=m.useState(""),A=a=>{a.preventDefault(),i(!0)},W=a=>{a.preventDefault(),i(!1)},B=a=>{a.preventDefault(),i(!1);const u=a.dataTransfer.files;if(u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},H=a=>{const u=a.target.files;if(u&&u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},K=async()=>{if(!I){T(t("mcpb.noFileSelected"));return}r(!0),T(null);try{const a=new FormData;a.append("mcpbFile",I);const u=await Xe(Ze("/mcpb/upload"),{method:"POST",body:a}),l=await u.json();if(!u.ok)throw new Error(l.message||`HTTP error! Status: ${u.status}`);if(l.success&&l.data)F(l.data.manifest),E(l.data.extractDir),R(!0);else throw new Error(l.message||t("mcpb.uploadFailed"))}catch(a){console.error("MCPB upload error:",a),T(a instanceof Error?a.message:t("mcpb.uploadFailed"))}finally{r(!1)}},M=async(a,u=!1)=>{var l;r(!0),T(null);try{const j=k(v,N,a);if(!u){const D=await Ke("/servers");if(D.success&&((l=D.data)==null?void 0:l.find(w=>w.name===a))){z(a),O(!0),r(!1);return}}let C;if(u?C=await be(`/servers/${encodeURIComponent(a)}`,{name:a,config:j}):C=await se("/servers",{name:a,config:j}),C.success)s(j);else throw new Error(C.message||t("mcpb.installFailed"))}catch(j){console.error("MCPB install error:",j),T(j instanceof Error?j.message:t("mcpb.installFailed")),r(!1)}},h=()=>{O(!1),$&&M($,!0)},c=()=>{O(!1),z(""),r(!1)},k=(a,u,l)=>{var D;const j=((D=a.server)==null?void 0:D.mcp_config)||{},C={type:"stdio",command:j.command||"node",args:(j.args||[]).map(V=>V.replace("${__dirname}",u))};return j.env&&Object.keys(j.env).length>0&&(C.env={...j.env},Object.keys(C.env).forEach(V=>{typeof C.env[V]=="string"&&(C.env[V]=C.env[V].replace("${__dirname}",u))})),C};return b&&v?e.jsxs(e.Fragment,{children:[e.jsx(cs,{isOpen:g,onClose:c,onConfirm:h,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:$}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${g?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),x&&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:x})}),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((a,u)=>e.jsxs("li",{children:[a.name," - ",a.description]},u))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue: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:o,disabled:f,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const a=document.getElementById("serverName"),u=(a==null?void 0:a.value.trim())||v.name;M(u)},disabled:f,className:"hub-btn primary",children:f?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),x&&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:x})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${n?"border-blue-500 bg-blue-50":I?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:A,onDragLeave:W,onDrop:B,children:[I?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:I.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(I.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:H,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:o,disabled:f,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!I||f,className:"hub-btn primary flex items-center",children:f?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Ss=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[n,i]=m.useState(""),[f,r]=m.useState(null),[x,T]=m.useState(!1),[I,d]=m.useState(null),b=`{
|
|
6
|
+
}`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${N?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),N&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:N})]}),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:r("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const h=JSON.parse(v);o(h)}catch{E(r("tool.invalidJsonFormat"))}},disabled:n||!!N,className:"hub-btn sm primary",children:r(n?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[Object.entries(g.properties||{}).map(([h,c])=>M(h,c)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:r("tool.cancel")}),e.jsx("button",{type:"submit",disabled:n,className:"hub-btn sm primary",children:r(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:r("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:r("tool.cancel")}),e.jsx("button",{onClick:()=>o({}),disabled:n,className:"hub-btn primary",children:r(n?"tool.running":"tool.runTool")})]})]})},xs=({result:s,onClose:o})=>{const{t}=Q(),n=s.content,i=d=>d?d.startsWith("image/")?d:`image/${d}`:"image/png",f=d=>{if(!d)return[];if(Array.isArray(d))return d.flatMap(v=>f(v));if(typeof d!="object")return[];const b=[];d.type==="image"&&d.data&&b.push({data:String(d.data),mimeType:i(d.mimeType||d.mime_type)});const R=d.image_base64||d.imageBase64||d.image_data||d.imageData||d.base64;return R&&b.push({data:String(R),mimeType:i(d.image_mimeType||d.image_mime_type||d.mimeType||d.mime_type)}),d.image&&typeof d.image=="object"&&b.push(...f(d.image)),Array.isArray(d.images)&&b.push(...f(d.images)),Array.isArray(d.content)&&b.push(...f(d.content)),b},r=d=>{const b=[];try{const F=JSON.parse(d);if(b.push(...f(F)),b.length>0)return b}catch{}const R=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let v;for(;(v=R.exec(d))!==null;){const F=`image/${v[1]==="jpg"?"jpeg":v[1]}`;b.push({data:v[2],mimeType:F})}return b},x=d=>{try{const b=JSON.parse(d),R=v=>{if(Array.isArray(v))return v.map(R);if(v&&typeof v=="object"){const F={};for(const[N,E]of Object.entries(v))typeof E=="string"&&N.toLowerCase().includes("base64")?F[N]="[base64 omitted]":F[N]=R(E);return F}return v};return JSON.stringify(R(b),null,2)}catch{return d.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},T=d=>Array.isArray(d)?d.map((b,R)=>e.jsx("div",{className:"mb-3 last:mb-0",children:I(b)},R)):I(d),I=d=>{if(typeof d=="string"){const b=r(d),R=x(d);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[b.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:b.map((v,F)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:R})]})}if(typeof d=="object"&&d!==null){if(d.type==="text"&&d.text){const b=r(d.text),R=x(d.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[b.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:b.map((v,F)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:R})]})}if(d.type==="image"&&d.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${d.mimeType||"image/png"};base64,${d.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const b=typeof d=="string"?JSON.parse(d):d;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(b,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(d)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Re,{size:20,className:"text-status-green"}):e.jsx($e,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:o,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),T(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(je,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),n&&n.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),T(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")})})]})})]})},ne=({title:s,onClick:o,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:o,disabled:t,title:s,"aria-label":s,children:e.jsx(Ye,{size:14,className:n?"animate-spin":""})});function hs(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 gs=({tool:s,server:o,onToggle:t,onDescriptionUpdate:n})=>{const{t:i}=Q(),{showToast:f}=we(),{nameSeparator:r}=ke(),[x,T]=m.useState(!1),[I,d]=m.useState(!1),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,H]=m.useState(0),[K,M]=m.useState(!1);m.useEffect(()=>{N&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[N,B]),m.useEffect(()=>{!N&&W.current&&H(W.current.offsetWidth)},[N,$]),m.useEffect(()=>{z(s.description||"")},[s.description]);const h=m.useCallback(()=>`mcphub_tool_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),c=m.useCallback(()=>{localStorage.removeItem(h())},[h]),k=S=>{t&&t(s.name,S)},a=()=>{E(!0)},u=async()=>{try{const S=await Me(o,s.name,$);S.success?(E(!1),n&&n(s.name,$)):(z(s.description||""),console.error("Failed to update tool description:",S.error))}catch(S){console.error("Error updating tool description:",S),z(s.description||""),E(!1)}},l=S=>{z(S.target.value)},j=async()=>{O(!0);try{const S=await Ue(o,s.name);if(S.success){const U=S.description||"";z(U),E(!1),n==null||n(s.name,U,{restored:!0})}else f(S.error||i("tool.restoreDefaultFailed"),"error")}catch(S){console.error("Error resetting tool description:",S),f(i("tool.restoreDefaultFailed"),"error")}finally{O(!1)}},C=S=>{S.key==="Enter"?u():S.key==="Escape"&&(z(s.description||""),E(!1))},D=async S=>{S.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),M(!0),f(i("common.copySuccess"),"success"),setTimeout(()=>M(!1),2e3);else{const U=document.createElement("textarea");U.value=s.name,U.style.position="fixed",U.style.left="-9999px",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),M(!0),f(i("common.copySuccess"),"success"),setTimeout(()=>M(!1),2e3)}catch(te){f(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",te)}document.body.removeChild(U)}}catch(U){f(i("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",U)}},V=async S=>{R(!0);try{S=Object.fromEntries(Object.entries(S).filter(([te,re])=>!hs(re)));const U=await Je({toolName:s.name,arguments:S},o);F(U)}catch(U){F({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{R(!1)}},w=()=>{d(!1),c(),F(null)},J=()=>{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:S=>{S.stopPropagation(),T(!x)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+r,"")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:D,title:i("common.copy"),children:K?e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(fe,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:N?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:$,onChange:l,onKeyDown:C,onClick:S=>S.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),u()},disabled:g,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),j()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:$||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:S=>{S.stopPropagation(),a()},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:i("tool.restoreDefault"),onClick:S=>{S.stopPropagation(),j()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:S=>S.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled??!0,onCheckedChange:k,disabled:b})}),e.jsxs("button",{onClick:S=>{S.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:b||!s.enabled,children:[b?e.jsx(Oe,{size:12,className:"animate-spin"}):e.jsx(_e,{size:12}),e.jsx("span",{children:i(b?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:x?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),x&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[!I&&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)})]}),I&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Be,{schema:s.inputSchema||{type:"object"},onSubmit:V,onCancel:w,loading:b,storageKey:h(),title:i("tool.runToolWithName",{name:s.name.replace(o+r,"")})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(xs,{result:v,onClose:J})})]})]})]})},fs=async(s,o)=>{try{const t=o?`/prompts/call/${o}`:"/prompts/call",n=await se(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:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Ve=async(s,o)=>{try{const t=await se(`/mcp/${encodeURIComponent(o||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:o,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},bs=async(s,o,t)=>{try{const n=await se(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,enabled:t,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},We=async(s,o,t)=>{try{const n=await be(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},Le=async(s,o)=>{var t;try{const n=await Fe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(o)}/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:o,error:n}),{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},js=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:fs,getPrompt:Ve,resetPromptDescription:Le,togglePrompt:bs,updatePromptDescription:We},Symbol.toStringTag,{value:"Module"})),Pe=({result:s,onClose:o})=>{const{t}=Q(),n=i=>{if(typeof i=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:i})});if(typeof i=="object"&&i!==null){if(i.description||i.messages)return e.jsxs("div",{className:"space-y-4",children:[i.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:i.description})})]}),i.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:i.messages.map((f,r)=>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:[f.role,":"]})}),typeof f.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:f.content}):typeof f.content=="object"&&f.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:f.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f.content,null,2)})]},r))})]})]});try{const f=typeof i=="string"?JSON.parse(i):i;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(f,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(i)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(i)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Re,{size:20,className:"text-status-green"}):e.jsx($e,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:o,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),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(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")})})]})})]})},ys=({prompt:s,server:o,onToggle:t,onDescriptionUpdate:n})=>{const{t:i}=Q(),{showToast:f}=we(),{nameSeparator:r}=ke(),[x,T]=m.useState(!1),[I,d]=m.useState(!1),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(s.description||""),A=m.useRef(null),W=m.useRef(null),[B,H]=m.useState(0);m.useEffect(()=>{N&&A.current&&(A.current.focus(),B>0&&(A.current.style.width=`${B+20}px`))},[N,B]),m.useEffect(()=>{!N&&W.current&&H(W.current.offsetWidth)},[N,$]),m.useEffect(()=>{z(s.description||"")},[s.description]);const K=m.useCallback(()=>`mcphub_prompt_form_${o?`${o}_`:""}${s.name}`,[s.name,o]),M=m.useCallback(()=>{localStorage.removeItem(K())},[K]),h=w=>{t&&t(s.name,w)},c=()=>{E(!0)},k=async()=>{E(!1);try{const w=await We(o,s.name,$);w.success?n&&n(s.name,$):(f(w.error||i("prompt.descriptionUpdateFailed"),"error"),z(s.description||""))}catch(w){console.error("Error updating prompt description:",w),f(i("prompt.descriptionUpdateFailed"),"error"),z(s.description||"")}},a=async()=>{O(!0);try{const w=await Le(o,s.name);if(w.success){const J=w.description||"";z(J),E(!1),n==null||n(s.name,J,{restored:!0})}else f(w.error||i("prompt.restoreDefaultFailed"),"error")}catch(w){console.error("Error resetting prompt description:",w),f(i("prompt.restoreDefaultFailed"),"error")}finally{O(!1)}},u=w=>{z(w.target.value)},l=w=>{w.key==="Enter"?k():w.key==="Escape"&&(z(s.description||""),E(!1))},j=async w=>{R(!0);try{const J=await Ve({promptName:s.name,arguments:w},o);console.log("GetPrompt result:",J),F({success:J.success,data:J.data,error:J.error})}catch(J){F({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{R(!1)}},C=()=>{d(!1),M(),F(null)},D=()=>{F(null)},V=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const w={},J=[];return s.arguments.forEach(S=>{w[S.name]={type:"string",description:S.description||""},S.required&&J.push(S.name)}),{type:"object",properties:w,required:J}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>T(!x),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(o+r,"")}),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:N?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:A,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:B>0?`${B+20}px`:160,minWidth:80},value:$,onChange:u,onKeyDown:l,onClick:w=>w.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),k()},disabled:g,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:i("prompt.restoreDefault"),onClick:w=>{w.stopPropagation(),a()},disabled:g,loading:g})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:W,children:$||i("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:w=>{w.stopPropagation(),c()},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:i("prompt.restoreDefault"),onClick:w=>{w.stopPropagation(),a()},disabled:g,loading:g})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:w=>w.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ce,{checked:s.enabled,onCheckedChange:h,disabled:b})}),e.jsxs("button",{onClick:w=>{w.stopPropagation(),T(!0),d(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:b||!s.enabled,children:[b?e.jsx(Oe,{size:12,className:"animate-spin"}):e.jsx(_e,{size:12}),e.jsx("span",{children:i(b?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:x?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),x&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[I&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(Be,{schema:V(),onSubmit:j,onCancel:C,loading:b,storageKey:K(),title:i("prompt.runPromptWithName",{name:s.name.replace(o+r,"")})}),v&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Pe,{result:v,onClose:D})})]}),!I&&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((w,J)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"hub-mono",style:{fontSize:12.5,color:"var(--hub-ink)"},children:w.name}),w.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),w.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:w.description})]}),w.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:w.title})]},J))})]}),!I&&v&&e.jsx("div",{children:e.jsx(Pe,{result:v,onClose:D})})]})]})},vs=({resource:s,onToggle:o,onDescriptionUpdate:t})=>{const{t:n}=Q(),[i,f]=m.useState(!1),[r,x]=m.useState(!1),[T,I]=m.useState(!1),[d,b]=m.useState(s.description||""),R=m.useRef(null),v=m.useRef(null),[F,N]=m.useState(0);m.useEffect(()=>{r&&R.current&&(R.current.focus(),F>0&&(R.current.style.width=`${F+20}px`))},[r,F]),m.useEffect(()=>{!r&&v.current&&N(v.current.offsetWidth)},[r,d]),m.useEffect(()=>{b(s.description||"")},[s.description]);const E=z=>{o&&o(s.uri,z)},g=async()=>{x(!1),t&&await t(s.uri,d)},O=async()=>{I(!0);try{await(t==null?void 0:t(s.uri,"",{restored:!0})),x(!1)}finally{I(!1)}},$=z=>{z.key==="Enter"?g():z.key==="Escape"&&(b(s.description||""),x(!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:()=>f(!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:r?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:R,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:F>0?`${F+20}px`:160,minWidth:80},value:d,onChange:z=>b(z.target.value),onKeyDown:$,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),g()},disabled:T,children:e.jsx(de,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ne,{title:n("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:v,children:d||n("tool.noDescription")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),x(!0)},children:e.jsx(Se,{size:12})}),e.jsx(ne,{title:n("builtinResources.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:T,loading:T})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("div",{onClick:z=>z.stopPropagation(),children:e.jsx(Ce,{checked:s.enabled!==!1,onCheckedChange:E})}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(Ee,{size:14}):e.jsx(ye,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[n("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Ie=(s,o)=>o?o==="stdio"?s("server.typeStdio")||"stdio":o==="sse"?s("server.typeSse")||"sse":o==="streamable-http"?s("server.typeStreamableHttp")||"http":o==="openapi"?s("server.typeOpenapi")||"openapi":o:null,Ns=({server:s,onRemove:o,onEdit:t,onToggle:n,onRefresh:i,onReload:f})=>{var X,ae,oe,le,q,Z,ie,ce,he;const{t:r}=Q(),{showToast:x}=we(),{exportMCPSettings:T,installConfig:I}=ke(),d=((X=I==null?void 0:I.baseUrl)==null?void 0:X.replace(/\/+$/,""))||"",[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(!1),[g,O]=m.useState(!1),[$,z]=m.useState(!1),[A,W]=m.useState(!1),[B,H]=m.useState(!1),[K,M]=m.useState(!1),h=m.useRef(null),c=m.useRef(null);m.useEffect(()=>{const p=y=>{h.current&&!h.current.contains(y.target)&&W(!1),c.current&&!c.current.contains(y.target)&&H(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]);const k=((ae=s.tools)==null?void 0:ae.length)||0,a=((oe=s.tools)==null?void 0:oe.filter(p=>p.enabled!==!1).length)||0,u=((le=s.prompts)==null?void 0:le.length)||0,l=((q=s.prompts)==null?void 0:q.filter(p=>p.enabled!==!1).length)||0,j=((Z=s.resources)==null?void 0:Z.length)||0,C=((ie=s.resources)==null?void 0:ie.filter(p=>p.enabled!==!1).length)||0,D=async p=>{if(p.stopPropagation(),!(g||!n)){O(!0);try{await n(s,s.enabled===!1)}finally{O(!1)}}},V=async p=>{if(p.stopPropagation(),W(!1),!($||!f)){z(!0);try{await f(s)?x(r("server.reloadSuccess")||"Server reloaded successfully","success"):x(r("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{z(!1)}}},w=async p=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(p),!0}catch{}try{const y=document.createElement("textarea");y.value=p,y.style.position="fixed",y.style.left="-9999px",document.body.appendChild(y),y.focus(),y.select();const P=document.execCommand("copy");return document.body.removeChild(y),P}catch{return!1}},J=async p=>{if(p.stopPropagation(),!s.error)return;await w(s.error)?(M(!0),x(r("common.copySuccess")||"Copied","success"),setTimeout(()=>M(!1),1500)):x(r("common.copyFailed")||"Copy failed","error")},S=async p=>{p.stopPropagation(),W(!1);try{const y=await T(s.name);if(!y||!y.success||!y.data){x((y==null?void 0:y.message)||r("common.copyFailed")||"Copy failed","error");return}const P=JSON.stringify(y.data,null,2),L=await w(P);x(L?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Copy failed",L?"success":"error")}catch(y){console.error("Error copying server configuration:",y),x(r("common.copyFailed")||"Copy failed","error")}},U=p=>{var y;if(p.stopPropagation(),(y=s.oauth)!=null&&y.authorizationUrl){const Y=window.screen.width/2-300,ee=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${Y},top=${ee}`),x(r("status.oauthWindowOpened"),"info")}},te=async(p,y)=>{try{const{toggleTool:P}=await ge(async()=>{const{toggleTool:Y}=await Promise.resolve().then(()=>ps);return{toggleTool:Y}},void 0,import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},re=async(p,y)=>{try{const{togglePrompt:P}=await ge(async()=>{const{togglePrompt:Y}=await Promise.resolve().then(()=>js);return{togglePrompt:Y}},void 0,import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},me=async(p,y)=>{try{const{toggleResource:P}=await ge(async()=>{const{toggleResource:Y}=await import("./resourceService-BpwGqVJZ.js");return{toggleResource:Y}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),L=await P(s.name,p,y);L.success?(x(r(y?"tool.enableSuccess":"tool.disableSuccess",{name:p}),"success"),i==null||i()):x(L.error||r("tool.toggleFailed"),"error")}catch(P){console.error(P),x(r("tool.toggleFailed"),"error")}},ue=(p,y,P)=>{x(P!=null&&P.restored?r("tool.restoreDefaultSuccess"):r("tool.descriptionUpdateSuccess"),"success"),i==null||i()},pe=(p,y,P)=>{x(P!=null&&P.restored?r("prompt.restoreDefaultSuccess"):r("prompt.descriptionUpdateSuccess"),"success"),i==null||i()},xe=async(p,y,P)=>{try{const{updateResourceDescription:L,resetResourceDescription:Y}=await ge(async()=>{const{updateResourceDescription:qe,resetResourceDescription:He}=await import("./resourceService-BpwGqVJZ.js");return{updateResourceDescription:qe,resetResourceDescription:He}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ee=P!=null&&P.restored?await Y(s.name,p):await L(s.name,p,y);ee.success?(x(P!=null&&P.restored?r("builtinResources.restoreDefaultSuccess"):r("builtinResources.descriptionUpdateSuccess"),"success"),i==null||i()):x(ee.error||(P!=null&&P.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed")),"error")}catch(L){console.error(L),x(P!=null&&P.restored?r("builtinResources.restoreDefaultFailed"):r("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var P;const p=s.config;if(!p)return"";if(p.url)return p.url;const y=[];return p.command&&y.push(p.command),(P=p.args)!=null&&P.length&&y.push(...p.args),y.join(" ")})();const _=s.enabled!==!1,G=`${d}/mcp/${s.name}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10,opacity:_?1:.7},children:[e.jsxs("div",{className:"grid items-center gap-3 px-4 py-3 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",style:{gridTemplateColumns:"minmax(220px,1.9fr) minmax(110px,0.9fr) minmax(120px,0.95fr) minmax(180px,1.1fr) 72px 36px"},onClick:()=>R(!b),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ye,{size:12,style:{color:"var(--hub-ink-3)",transform:b?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"hub-mono truncate",style:{fontSize:13.5,color:_?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),s.error&&e.jsxs("div",{className:"relative",ref:c,children:[e.jsx("button",{onClick:p=>{p.stopPropagation(),H(y=>!y)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":r("server.viewErrorDetails"),children:e.jsx(je,{size:14})}),B&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:r("server.errorDetails")}),e.jsx("button",{onClick:J,className:"hub-icon-btn sm",title:r("common.copy"),children:K?e.jsx(de,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(fe,{size:12})})]}),e.jsx("button",{onClick:()=>H(!1),className:"hub-icon-btn sm","aria-label":r("app.closeButton"),children:e.jsx(ve,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),((ce=s.config)==null?void 0:ce.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(Qe,{status:s.status,enabled:s.enabled,onAuthClick:U})}),e.jsx("div",{className:"min-w-0",children:(he=s.config)!=null&&he.type?e.jsx("span",{className:"hub-tag",title:Ie(r,s.config.type)??void 0,children:Ie(r,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:[{key:"tools",icon:ze,total:k,enabled:a,label:r("server.tools")},{key:"prompts",icon:Te,total:u,enabled:l,label:r("server.prompts")},{key:"resources",icon:De,total:j,enabled:C,label:r("nav.resources")}].map(({key:p,icon:y,total:P,enabled:L,label:Y})=>{const ee=P===0;return e.jsxs("span",{className:"inline-flex items-center gap-1 hub-mono hub-num",title:`${Y}: ${L}/${P}`,style:{padding:"2px 7px",borderRadius:6,fontSize:11.5,lineHeight:"16px",background:ee?"transparent":"var(--hub-bg-2)",border:"1px solid",borderColor:ee?"transparent":"var(--hub-line-2)",color:ee?"var(--hub-ink-3)":"var(--hub-ink-2)"},children:[e.jsx(y,{size:12,style:{color:"var(--hub-ink-3)",flexShrink:0}}),e.jsx("span",{children:ee?"0":`${L}/${P}`})]},p)})}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{type:"button",className:"hub-switch"+(_?" on":""),onClick:D,disabled:g,"aria-label":r(_?"server.disable":"server.enable")})}),e.jsxs("div",{className:"relative",ref:h,children:[e.jsx("button",{className:"hub-icon-btn",onClick:p=>{p.stopPropagation(),W(y=>!y)},"aria-label":"More",children:e.jsx(es,{size:14})}),A&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:p=>p.stopPropagation(),children:[e.jsxs("button",{onClick:p=>{p.stopPropagation(),W(!1),t(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ss,{size:13})," ",r("server.edit")]}),e.jsxs("button",{onClick:S,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(fe,{size:13})," ",r("server.copy")]}),f&&e.jsxs("button",{onClick:V,disabled:$||g||!_,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(Ne,{size:13})," ",r("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:p=>{p.stopPropagation(),W(!1),E(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(ts,{size:13})," ",r("server.delete")]})]})]})]}),b&&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:[[{key:"tools",icon:e.jsx(ze,{size:12}),label:r("server.tools"),count:k,enabled:a},{key:"prompts",icon:e.jsx(Te,{size:12}),label:r("server.prompts"),count:u,enabled:l},{key:"resources",icon:e.jsx(De,{size:12}),label:r("nav.resources"),count:j,enabled:C}].map(p=>{const y=v===p.key;return e.jsxs("button",{onClick:()=>F(y?null:p.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:y?"var(--hub-surface)":"transparent",border:"1px solid "+(y?"var(--hub-line)":"transparent"),color:y?"var(--hub-ink)":"var(--hub-ink-2)"},children:[p.icon,e.jsx("span",{children:p.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:p.count===0?"0":`${p.enabled}/${p.count}`})]},p.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:G,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async p=>{p.stopPropagation();const y=await w(G);x(y?r("common.copySuccess")||"Copied":r("common.copyFailed")||"Failed",y?"success":"error")},title:r("common.copy"),children:e.jsx(fe,{size:12})})]})})]}),v==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((p,y)=>e.jsx(gs,{server:s.name,tool:p,onToggle:te,onDescriptionUpdate:ue},y))}),v==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((p,y)=>e.jsx(ys,{server:s.name,prompt:p,onToggle:re,onDescriptionUpdate:pe},y))}),v==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:r("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((p,y)=>e.jsx(vs,{resource:p,onToggle:me,onDescriptionUpdate:xe},`${p.uri}-${y}`))})})]})]}),e.jsx(ls,{isOpen:N,onClose:()=>E(!1),onConfirm:()=>{o(s.name),E(!1)},serverName:s.name})]})},ws=({onAdd:s})=>{const{t:o}=Q(),[t,n]=m.useState(!1),[i,f]=m.useState(null),[r,x]=m.useState(!1),[T,I]=m.useState(null),[d,b]=m.useState([]),R=()=>{n(!t),f(null),x(!1),I(null)},v=async()=>{T&&(await F(T),x(!1),I(null))},F=async E=>{try{f(null);const g=await se("/servers",E);if(!g.success){g&&g.message?f(g.message):f(o("server.addError"));return}n(!1),s()}catch(g){console.error("Error adding server:",g),navigator.onLine?g instanceof TypeError&&(g.message.includes("NetworkError")||g.message.includes("Failed to fetch"))?f(o("errors.serverConnection")):f(o("errors.serverAdd")):f(o("errors.network"))}},N=async E=>{try{const g=is(E);g.length>0?(b(g),I(E),x(!0)):await F(E)}catch(g){console.error("Error processing server submission:",g),f(o("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:R,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),o("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ae,{onSubmit:N,onCancel:R,modalTitle:o("server.addServer"),formError:i})}),r&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:o("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:o("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[o("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:d.map((E,g)=>e.jsxs("li",{className:"font-mono",children:["$",`{${E}}`]},g))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:o("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{x(!1),I(null)},className:"hub-btn",children:o("common.cancel")}),e.jsx("button",{onClick:v,className:"hub-btn primary",children:o("server.confirmAndAdd")})]})]})})]})},ks=({server:s,onEdit:o,onCancel:t})=>{const{t:n}=Q(),[i,f]=m.useState(null),r=async x=>{try{f(null);const T=encodeURIComponent(s.name),I=x.name&&x.name!==s.name,d={config:x.config,...I?{newName:x.name}:{}},b=await be(`/servers/${T}`,d);if(!b.success){b&&b.message?f(b.message):f(n("server.updateError",{serverName:s.name}));return}o()}catch(T){console.error("Error updating server:",T),navigator.onLine?T instanceof TypeError&&(T.message.includes("NetworkError")||T.message.includes("Failed to fetch"))?f(n("errors.serverConnection")):f(n("errors.serverUpdate",{serverName:s.name})):f(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(Ae,{onSubmit:r,onCancel:t,initialData:s,modalTitle:n("server.editTitle",{serverName:s.name}),formError:i})})},Cs=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[n,i]=m.useState(!1),[f,r]=m.useState(!1),[x,T]=m.useState(null),[I,d]=m.useState(null),[b,R]=m.useState(!1),[v,F]=m.useState(null),[N,E]=m.useState(""),[g,O]=m.useState(!1),[$,z]=m.useState(""),A=a=>{a.preventDefault(),i(!0)},W=a=>{a.preventDefault(),i(!1)},B=a=>{a.preventDefault(),i(!1);const u=a.dataTransfer.files;if(u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},H=a=>{const u=a.target.files;if(u&&u.length>0){const l=u[0];l.name.endsWith(".mcpb")?(d(l),T(null)):T(t("mcpb.invalidFileType"))}},K=async()=>{if(!I){T(t("mcpb.noFileSelected"));return}r(!0),T(null);try{const a=new FormData;a.append("mcpbFile",I);const u=await Xe(Ze("/mcpb/upload"),{method:"POST",body:a}),l=await u.json();if(!u.ok)throw new Error(l.message||`HTTP error! Status: ${u.status}`);if(l.success&&l.data)F(l.data.manifest),E(l.data.extractDir),R(!0);else throw new Error(l.message||t("mcpb.uploadFailed"))}catch(a){console.error("MCPB upload error:",a),T(a instanceof Error?a.message:t("mcpb.uploadFailed"))}finally{r(!1)}},M=async(a,u=!1)=>{var l;r(!0),T(null);try{const j=k(v,N,a);if(!u){const D=await Ke("/servers");if(D.success&&((l=D.data)==null?void 0:l.find(w=>w.name===a))){z(a),O(!0),r(!1);return}}let C;if(u?C=await be(`/servers/${encodeURIComponent(a)}`,{name:a,config:j}):C=await se("/servers",{name:a,config:j}),C.success)s(j);else throw new Error(C.message||t("mcpb.installFailed"))}catch(j){console.error("MCPB install error:",j),T(j instanceof Error?j.message:t("mcpb.installFailed")),r(!1)}},h=()=>{O(!1),$&&M($,!0)},c=()=>{O(!1),z(""),r(!1)},k=(a,u,l)=>{var D;const j=((D=a.server)==null?void 0:D.mcp_config)||{},C={type:"stdio",command:j.command||"node",args:(j.args||[]).map(V=>V.replace("${__dirname}",u))};return j.env&&Object.keys(j.env).length>0&&(C.env={...j.env},Object.keys(C.env).forEach(V=>{typeof C.env[V]=="string"&&(C.env[V]=C.env[V].replace("${__dirname}",u))})),C};return b&&v?e.jsxs(e.Fragment,{children:[e.jsx(cs,{isOpen:g,onClose:c,onConfirm:h,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:$}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${g?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),x&&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:x})}),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((a,u)=>e.jsxs("li",{children:[a.name," - ",a.description]},u))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue: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:o,disabled:f,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const a=document.getElementById("serverName"),u=(a==null?void 0:a.value.trim())||v.name;M(u)},disabled:f,className:"hub-btn primary",children:f?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),x&&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:x})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${n?"border-blue-500 bg-blue-50":I?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:A,onDragLeave:W,onDrop:B,children:[I?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:I.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(I.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:H,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:o,disabled:f,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:K,disabled:!I||f,className:"hub-btn primary flex items-center",children:f?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Ss=({onSuccess:s,onCancel:o})=>{const{t}=Q(),[n,i]=m.useState(""),[f,r]=m.useState(null),[x,T]=m.useState(!1),[I,d]=m.useState(null),b=`{
|
|
7
7
|
"mcpServers": {
|
|
8
8
|
"stdio-server-example": {
|
|
9
9
|
"command": "npx",
|
|
@@ -34,4 +34,4 @@ Supports: STDIO, SSE, HTTP (streamable-http), OpenAPI
|
|
|
34
34
|
All servers will be imported in a single efficient batch operation.`,R=N=>{try{const E=JSON.parse(N.trim());return!E.mcpServers||typeof E.mcpServers!="object"?(r(t("jsonImport.invalidFormat")),null):E}catch{return r(t("jsonImport.parseError")),null}},v=()=>{r(null);const N=R(n);if(!N)return;const E=Object.entries(N.mcpServers).map(([g,O])=>{const $={};return O.type==="sse"||O.type==="streamable-http"?($.type=O.type,$.url=O.url,O.headers&&($.headers=O.headers)):O.type==="openapi"?($.type="openapi",$.openapi=O.openapi):($.type="stdio",$.command=O.command,$.args=O.args||[],O.env&&($.env=O.env)),{name:g,config:$}});d(E)},F=async()=>{if(I){T(!0),r(null);try{const N=await se("/servers/batch",{servers:I});if(N.success&&N.data){const{successCount:E,failureCount:g,results:O}=N.data;if(g>0){const $=O.filter(z=>!z.success).map(z=>`${z.name}: ${z.message||t("jsonImport.addFailed")}`);r(t("jsonImport.partialSuccess",{count:E,total:I.length})+`
|
|
35
35
|
`+$.join(`
|
|
36
36
|
`))}E>0&&s()}else r(N.message||t("jsonImport.importFailed"))}catch(N){console.error("Import error:",N),r(t("jsonImport.importFailed"))}finally{T(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:o,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),f&&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:f})}),I?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:I.map((N,E)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:N.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"),":"]})," ",N.config.type||"stdio"]}),N.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",N.config.command]}),N.config.args&&N.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",N.config.args.join(" ")]}),N.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",N.config.url]}),N.config.env&&Object.keys(N.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(N.config.env).join(", ")]}),N.config.headers&&Object.keys(N.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(N.config.headers).join(", ")]})]})]})})},E))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>d(null),disabled:x,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:F,disabled:x,className:"hub-btn primary",children:x?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:N=>i(N.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:b}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:o,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:v,disabled:!n.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},Js=()=>{const{t:s}=Q(),o=Ge(),{servers:t,allServers:n,error:i,setError:f,isLoading:r,pagination:x,currentPage:T,serversPerPage:I,setCurrentPage:d,setServersPerPage:b,handleServerAdd:R,handleServerEdit:v,handleServerRemove:F,handleServerToggle:N,handleServerReload:E,triggerRefresh:g}=ms({refreshOnMount:!0}),[O,$]=m.useState(null),[z,A]=m.useState(!1),[W,B]=m.useState(!1),[H,K]=m.useState(!1),[M,h]=m.useState("all"),[c,k]=m.useState(""),a=m.useMemo(()=>({all:n.length,online:n.filter(C=>C.status==="connected").length,issues:n.filter(C=>C.status!=="connected"&&C.enabled!==!1).length}),[n]),u=m.useMemo(()=>{const C=c.trim().toLowerCase();return t.filter(D=>{var w,J;return M==="online"&&D.status!=="connected"||M==="issues"&&(D.status==="connected"||D.enabled===!1)?!1:C?(D.name+" "+(((w=D.config)==null?void 0:w.description)||"")+" "+(((J=D.tools)==null?void 0:J.map(S=>S.name).join(" "))||"")).toLowerCase().includes(C):!0})},[t,M,c]),l=async C=>{const D=await v(C);D&&$(D)},j=async()=>{A(!0);try{g(),await new Promise(C=>setTimeout(C,400))}finally{A(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("pages.servers.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:a.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:a.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:a.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>o("/market"),children:[e.jsx(rs,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>K(!0),children:[e.jsx(ns,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>B(!0),children:[e.jsx(as,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:j,disabled:z,"aria-label":s("common.refresh"),children:[e.jsx(Ne,{size:13,className:z?"animate-spin":""}),s("common.refresh")]}),e.jsx(ws,{onAdd:R})]})]}),i&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(je,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:i})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>f(null),"aria-label":s("app.closeButton"),children:e.jsx(ve,{size:13})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-4 flex-wrap",children:[e.jsx("div",{className:"hub-card flex items-center",style:{padding:2,borderRadius:7,background:"var(--hub-surface)"},children:[["all",s("common.all")||"All",a.all],["online",s("status.online"),a.online],["issues",s("common.inactive")||"Issues",a.issues]].map(([C,D,V])=>e.jsxs("button",{onClick:()=>h(C),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:M===C?"var(--hub-bg-2)":"transparent",color:M===C?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(M===C?"var(--hub-line)":"transparent")},children:[D,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:V})]},C))}),e.jsxs("div",{className:"hub-card flex items-center gap-2 px-2.5 flex-1",style:{height:30,background:"var(--hub-surface)",maxWidth:360},children:[e.jsx(os,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:c,onChange:C=>k(C.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),c&&e.jsx("button",{onClick:()=>k(""),className:"hub-icon-btn sm",children:e.jsx(ve,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[u.length,"/",t.length]})]}),r&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Ne,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):u.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:e.jsx("p",{children:t.length===0?s("app.noServers"):s("market.noServers")})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col",children:u.map(C=>e.jsx(Ns,{server:C,onRemove:F,onEdit:l,onToggle:N,onRefresh:g,onReload:E},C.name))}),e.jsxs("div",{className:"flex items-center mt-4 text-[12px]",style:{color:"var(--hub-ink-3)"},children:[e.jsx("div",{className:"flex-[2]",children:x?s("common.showing",{start:(x.page-1)*x.limit+1,end:Math.min(x.page*x.limit,x.total),total:x.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:x&&x.totalPages>1&&e.jsx(ds,{currentPage:T,totalPages:x.totalPages,onPageChange:d,disabled:r})}),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:I,onChange:C=>b(Number(C.target.value)),disabled:r,className:"hub-input",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})]}),O&&e.jsx(ks,{server:O,onEdit:()=>{$(null),g()},onCancel:()=>$(null)}),W&&e.jsx(Cs,{onSuccess:()=>{B(!1),g()},onCancel:()=>B(!1)}),H&&e.jsx(Ss,{onSuccess:()=>{K(!1),g()},onCancel:()=>K(!1)})]})};export{Js as default};
|
|
37
|
-
//# sourceMappingURL=ServersPage-
|
|
37
|
+
//# sourceMappingURL=ServersPage-9Ku6lufR.js.map
|