@samanhappy/mcphub 1.0.21 → 1.0.23
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 +9 -0
- package/README.md +9 -0
- package/README.zh.md +9 -0
- package/dist/betterAuth.js +2 -1
- package/dist/betterAuth.js.map +1 -1
- package/dist/clients/openapi.js +21 -3
- package/dist/clients/openapi.js.map +1 -1
- package/dist/controllers/oauthCallbackController.js +51 -25
- package/dist/controllers/oauthCallbackController.js.map +1 -1
- package/dist/controllers/oauthDynamicRegistrationController.js +2 -1
- package/dist/controllers/oauthDynamicRegistrationController.js.map +1 -1
- package/dist/controllers/oauthServerController.js +3 -2
- package/dist/controllers/oauthServerController.js.map +1 -1
- package/dist/controllers/serverController.js +9 -4
- package/dist/controllers/serverController.js.map +1 -1
- package/dist/middlewares/i18n.js +11 -12
- package/dist/middlewares/i18n.js.map +1 -1
- package/dist/models/User.js +18 -8
- package/dist/models/User.js.map +1 -1
- package/dist/services/betterAuthConfig.js +2 -1
- package/dist/services/betterAuthConfig.js.map +1 -1
- package/dist/services/keepAliveService.js +79 -15
- package/dist/services/keepAliveService.js.map +1 -1
- package/dist/services/mcpOAuthProvider.js +2 -1
- package/dist/services/mcpOAuthProvider.js.map +1 -1
- package/dist/services/mcpService.js +19 -4
- package/dist/services/mcpService.js.map +1 -1
- package/dist/services/oauthClientRegistration.js +2 -1
- package/dist/services/oauthClientRegistration.js.map +1 -1
- package/dist/services/openApiGeneratorService.js +2 -1
- package/dist/services/openApiGeneratorService.js.map +1 -1
- package/dist/services/sseService.js +10 -3
- package/dist/services/sseService.js.map +1 -1
- package/dist/utils/i18n.js +48 -7
- package/dist/utils/i18n.js.map +1 -1
- package/dist/utils/installBaseUrl.js +24 -0
- package/dist/utils/installBaseUrl.js.map +1 -0
- package/dist/utils/path.js +24 -17
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/serialization.js +11 -2
- package/dist/utils/serialization.js.map +1 -1
- package/dist/utils/serverConfigPersistence.js +3 -3
- package/dist/utils/serverConfigPersistence.js.map +1 -1
- package/frontend/dist/assets/{ActivityPage-BdrQfThE.js → ActivityPage-BdZq-UUz.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-BdrQfThE.js.map → ActivityPage-BdZq-UUz.js.map} +1 -1
- package/frontend/dist/assets/{Dashboard-CvYsCiCj.js → Dashboard-B9NgJISN.js} +2 -2
- package/frontend/dist/assets/{Dashboard-CvYsCiCj.js.map → Dashboard-B9NgJISN.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-jLrukAqy.js → EndpointCopy-CxQGXtue.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-jLrukAqy.js.map → EndpointCopy-CxQGXtue.js.map} +1 -1
- package/frontend/dist/assets/{GroupsPage-bx0-O8QO.js → GroupsPage-DvkKDHf7.js} +2 -2
- package/frontend/dist/assets/GroupsPage-DvkKDHf7.js.map +1 -0
- package/frontend/dist/assets/{LoginPage-iaaOrcoD.js → LoginPage-BJKZSGKK.js} +2 -2
- package/frontend/dist/assets/{LoginPage-iaaOrcoD.js.map → LoginPage-BJKZSGKK.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-Db4bhPkI.js → LogsPage-Dd0rwLjA.js} +2 -2
- package/frontend/dist/assets/{LogsPage-Db4bhPkI.js.map → LogsPage-Dd0rwLjA.js.map} +1 -1
- package/frontend/dist/assets/{MarketPage-zlYEEKhe.js → MarketPage-upzNkwbt.js} +2 -2
- package/frontend/dist/assets/{MarketPage-zlYEEKhe.js.map → MarketPage-upzNkwbt.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-DlmjzEmf.js → PromptsPage-BuLeSc0F.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-DlmjzEmf.js.map → PromptsPage-BuLeSc0F.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-BNgVSvFC.js → ResourcesPage-DrZ_QvOI.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-BNgVSvFC.js.map → ResourcesPage-DrZ_QvOI.js.map} +1 -1
- package/frontend/dist/assets/{ServersPage-DkL4-rzA.js → ServersPage-hag0KLrj.js} +4 -4
- package/frontend/dist/assets/ServersPage-hag0KLrj.js.map +1 -0
- package/frontend/dist/assets/{SettingsPage-8P6SgOmM.js → SettingsPage-lYf7PdC3.js} +2 -2
- package/frontend/dist/assets/{SettingsPage-8P6SgOmM.js.map → SettingsPage-lYf7PdC3.js.map} +1 -1
- package/frontend/dist/assets/{StatusDot-lQsZ4t4B.js → StatusDot-DoWgjhoz.js} +2 -2
- package/frontend/dist/assets/{StatusDot-lQsZ4t4B.js.map → StatusDot-DoWgjhoz.js.map} +1 -1
- package/frontend/dist/assets/{ToggleGroup-mQioxU9F.js → ToggleGroup-D5ZAjFw-.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-mQioxU9F.js.map → ToggleGroup-D5ZAjFw-.js.map} +1 -1
- package/frontend/dist/assets/{UsersPage-Dk0qxPr-.js → UsersPage-4N_KUrap.js} +2 -2
- package/frontend/dist/assets/{UsersPage-Dk0qxPr-.js.map → UsersPage-4N_KUrap.js.map} +1 -1
- package/frontend/dist/assets/{contextCost-C8409usw.js → contextCost-DKF-jtb4.js} +2 -2
- package/frontend/dist/assets/{contextCost-C8409usw.js.map → contextCost-DKF-jtb4.js.map} +1 -1
- package/frontend/dist/assets/framework-vendor-X-WP1v0m.js.map +1 -1
- package/frontend/dist/assets/i18n-vendor-BLr2MLKp.js.map +1 -1
- package/frontend/dist/assets/{index-BlTPJflb.css → index-BfEBXfi0.css} +1 -1
- package/frontend/dist/assets/index-CSXs6vVg.js +3 -0
- package/frontend/dist/assets/{index-BUcur8GF.js.map → index-CSXs6vVg.js.map} +1 -1
- package/frontend/dist/assets/{resourceService-CfOZGPdl.js → resourceService-Cu9CYEjx.js} +2 -2
- package/frontend/dist/assets/{resourceService-CfOZGPdl.js.map → resourceService-Cu9CYEjx.js.map} +1 -1
- package/frontend/dist/assets/useSettingsData-CiFNo8wN.js +2 -0
- package/frontend/dist/assets/{useSettingsData-vLtA_KQ8.js.map → useSettingsData-CiFNo8wN.js.map} +1 -1
- package/frontend/dist/assets/{variableDetection-Bp_stsiy.js → variableDetection-DChuQNs-.js} +3 -3
- package/frontend/dist/assets/variableDetection-DChuQNs-.js.map +1 -0
- package/frontend/dist/index.html +2 -2
- package/mcp_settings.json +2 -8
- package/package.json +3 -3
- package/frontend/dist/assets/GroupsPage-bx0-O8QO.js.map +0 -1
- package/frontend/dist/assets/ServersPage-DkL4-rzA.js.map +0 -1
- package/frontend/dist/assets/index-BUcur8GF.js +0 -3
- package/frontend/dist/assets/useSettingsData-vLtA_KQ8.js +0 -2
- package/frontend/dist/assets/variableDetection-Bp_stsiy.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-
|
|
2
|
-
import{r as u,j as e,d as ys}from"./framework-vendor-X-WP1v0m.js";import{e as oe,f as Ze,h as ve,i as Ee,u as js,_ as ge,j as vs,k as Ns,l as ws}from"./index-BUcur8GF.js";import{f as ne,u as ks,a as Cs}from"./contextCost-C8409usw.js";import{S as Ss}from"./StatusDot-lQsZ4t4B.js";import{u as Pe}from"./useSettingsData-vLtA_KQ8.js";import{S as Ne}from"./ToggleGroup-mQioxU9F.js";import{u as se}from"./i18n-vendor-BLr2MLKp.js";import{n as Qe,o as es,l as we,p as Es,C as me,q as ye,r as De,s as ss,t as ts,u as ze,m as ke,W as Ps,g as Ds,F as zs,X as Se,E as Ts,v as $s,R as je,w as Fs,T as Is,P as Rs,x as _s,y as Os,z as As}from"./icons-vendor-DMtsx1SI.js";import{g as Ms}from"./toolDescription-Dw3sa28K.js";import{D as Vs}from"./DeleteDialog-7NPk3Hro.js";import{C as rs}from"./ConfirmDialog-BKNVI65J.js";import{S as as,d as Js}from"./variableDetection-Bp_stsiy.js";import{P as Us}from"./Pagination-DAcOi8eq.js";const ns=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",a=await oe(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return a.success===!1?{success:!1,error:a.message||"Tool call failed"}:{success:!0,content:(a==null?void 0:a.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Bs=async(s,r,t)=>{try{const a=await oe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},os=async(s,r,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating tool description",{serverName:s,toolName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},is=async(s,r)=>{var t;try{const a=await Ze(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting tool description",{serverName:s,toolName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},Ls=Object.freeze(Object.defineProperty({__proto__:null,callTool:ns,resetToolDescription:is,toggleTool:Bs,updateToolDescription:os},Symbol.toStringTag,{value:"Module"})),ls=({schema:s,onSubmit:r,onCancel:t,loading:a=!1,storageKey:x,title:g})=>{const{t:n}=se(),[N,C]=u.useState({}),[i,o]=u.useState({}),[S,T]=u.useState(!1),[v,I]=u.useState(""),[w,P]=u.useState(""),y=u.useMemo(()=>(m=>{const j=c=>{if(typeof c=="object"&&c!==null){const p=c;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([d,f])=>[d,j(f)])):void 0,required:p.required,items:p.items?j(p.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([c,p])=>[c,j(p)])):void 0,required:m.required}})(s),[s]);u.useEffect(()=>{const h=(j,c="")=>{const p={};return j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([d,f])=>{const R=c?`${c}.${d}`:d;f.default!==void 0?p[d]=f.default:f.type==="string"?p[d]="":f.type==="number"||f.type==="integer"?p[d]=0:f.type==="boolean"?p[d]=!1:f.type==="array"?p[d]=[]:f.type==="object"&&(f.properties?p[d]=h(f,R):p[d]={})}),p};let m=h(y);if(x)try{const j=localStorage.getItem(x);if(j){const c=JSON.parse(j);m={...m,...c}}}catch(j){console.warn("Failed to load saved form data:",j)}C(m)},[y,x]),u.useEffect(()=>{S&&Object.keys(N).length>0&&(I(JSON.stringify(N,null,2)),P(""))},[S,N]);const A=h=>{I(h),P("");try{const m=JSON.parse(h);if(C(m),x)try{localStorage.setItem(x,JSON.stringify(m))}catch(j){console.warn("Failed to save form data to localStorage:",j)}}catch{P(n("tool.invalidJsonFormat"))}},J=()=>{I(JSON.stringify(N,null,2)),P(""),T(!0)},U=()=>{if(v.trim())try{const h=JSON.parse(v);C(h),P(""),T(!1)}catch{P(n("tool.fixJsonBeforeSwitching"));return}else T(!1)},_=(h,m)=>{C(j=>{const c={...j},p=h.split(".");let d=c;for(let f=0;f<p.length-1;f++)d[p[f]]||(d[p[f]]={}),d=d[p[f]];if(d[p[p.length-1]]=m,x)try{localStorage.setItem(x,JSON.stringify(c))}catch(f){console.warn("Failed to save form data to localStorage:",f)}return c}),i[h]&&o(j=>{const c={...j};return delete c[h],c})},V=()=>{const h={},m=(j,c,p="")=>{j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([d,f])=>{var B;const R=p?`${p}.${d}`:d,D=c==null?void 0:c[d];if((B=j.required)!=null&&B.includes(d)&&(D==null||D===""||Array.isArray(D)&&D.length===0)){h[R]=`${d} is required`;return}D!=null&&D!==""&&(f.type==="string"&&typeof D!="string"?h[R]=`${d} must be a string`:f.type==="number"&&typeof D!="number"?h[R]=`${d} must be a number`:f.type==="integer"&&(!Number.isInteger(D)||typeof D!="number")?h[R]=`${d} must be an integer`:f.type==="boolean"&&typeof D!="boolean"?h[R]=`${d} must be a boolean`:f.type==="array"&&Array.isArray(D)?f.items&&D.forEach((X,O)=>{var G;((G=f.items)==null?void 0:G.type)==="object"&&f.items.properties&&m(f.items,X,`${R}.${O}`)}):f.type==="object"&&typeof D=="object"&&m(f,D,R))})};return m(y,N),o(h),Object.keys(h).length===0},F=h=>{h.preventDefault(),V()&&r(N)},q=(h,m)=>m.split(".").reduce((j,c)=>j==null?void 0:j[c],h),H=(h,m,j,c)=>{const p=j==null?void 0:j[h];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",onChange:d=>c(d.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:n("tool.selectOption")}),m.enum.map((d,f)=>e.jsx("option",{value:d,children:d},f))]}):e.jsx("input",{type:"text",value:p||"",onChange:d=>c(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||n("tool.enterKey",{key:h})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:d=>{const f=d.target.value===""?"":m.type==="integer"?parseInt(d.target.value):parseFloat(d.target.value);c(f)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):m.type==="boolean"?e.jsx("input",{type:"checkbox",checked:p||!1,onChange:d=>c(d.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:p||"",onChange:d=>c(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||n("tool.enterKey",{key:h})})},Y=(h,m,j="")=>{var f,R,D,B,X,O,G,E,L,te,le,z,W,Q;const c=j?`${j}.${h}`:h,p=q(N,c),d=i[c];if(m.type==="array"){const $=q(N,c)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(R=(f=q(y,j))==null?void 0:f.required)==null?void 0:R.includes(h):(D=y.required)==null?void 0:D.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[$.map((Z,ee)=>{var pe,xe,he;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:n("tool.item",{index:ee+1})}),e.jsx("button",{type:"button",onClick:()=>{const K=[...$];K.splice(ee,1),_(c,K)},className:"text-status-red hover:text-red-700 text-sm",children:n("common.remove")})]}),((pe=m.items)==null?void 0:pe.type)==="string"&&m.items.enum?e.jsxs("select",{value:Z||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(c,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:n("tool.selectOption")}),m.items.enum.map((K,re)=>e.jsx("option",{value:K,children:K},re))]}):((xe=m.items)==null?void 0:xe.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([K,re])=>{var be,fe;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[K,((fe=(be=m.items)==null?void 0:be.required)==null?void 0:fe.includes(K))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),H(K,re,Z,Ce=>{const ue=[...$];ue[ee]={...ue[ee],[K]:Ce},_(c,ue)})]},K)})}):e.jsx("input",{type:"text",value:Z||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(c,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:n("tool.enterValue",{type:((he=m.items)==null?void 0:he.type)||"value"})})]},ee)}),e.jsx("button",{type:"button",onClick:()=>{var ee;const Z=((ee=m.items)==null?void 0:ee.type)==="object"?{}:"";_(c,[...$,Z])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:n("tool.addItem",{key:h})})]}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c)}return m.type==="object"?m.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(X=(B=q(y,j))==null?void 0:B.required)==null?void 0:X.includes(h):(O=y.required)==null?void 0:O.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(m.properties).map(([$,Z])=>Y($,Z,c))}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(E=(G=q(y,j))==null?void 0:G.required)==null?void 0:E.includes(h):(L=y.required)==null?void 0:L.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)"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("textarea",{value:typeof p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:$=>{try{const Z=JSON.parse($.target.value);_(c,Z)}catch{_(c,$.target.value)}},placeholder:`{
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-Cu9CYEjx.js","./index-CSXs6vVg.js","./framework-vendor-X-WP1v0m.js","./i18n-vendor-BLr2MLKp.js","./icons-vendor-DMtsx1SI.js","./index-BfEBXfi0.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as u,j as e,d as ys}from"./framework-vendor-X-WP1v0m.js";import{e as oe,f as Ze,h as ve,i as Ee,u as js,_ as ge,j as vs,k as Ns,l as ws}from"./index-CSXs6vVg.js";import{f as ne,u as ks,a as Cs}from"./contextCost-DKF-jtb4.js";import{S as Ss}from"./StatusDot-DoWgjhoz.js";import{u as Pe}from"./useSettingsData-CiFNo8wN.js";import{S as Ne}from"./ToggleGroup-D5ZAjFw-.js";import{u as se}from"./i18n-vendor-BLr2MLKp.js";import{n as Qe,o as es,l as we,p as Es,C as me,q as ye,r as De,s as ss,t as ts,u as ze,m as ke,W as Ps,g as Ds,F as zs,X as Se,E as Ts,v as $s,R as je,w as Fs,T as Is,P as Rs,x as _s,y as Os,z as As}from"./icons-vendor-DMtsx1SI.js";import{g as Ms}from"./toolDescription-Dw3sa28K.js";import{D as Vs}from"./DeleteDialog-7NPk3Hro.js";import{C as rs}from"./ConfirmDialog-BKNVI65J.js";import{S as as,d as Js}from"./variableDetection-DChuQNs-.js";import{P as Us}from"./Pagination-DAcOi8eq.js";const ns=async(s,r)=>{try{const t=r?`/tools/${encodeURIComponent(r)}/${encodeURIComponent(s.toolName)}`:"/tools/call",a=await oe(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return a.success===!1?{success:!1,error:a.message||"Tool call failed"}:{success:!0,content:(a==null?void 0:a.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Bs=async(s,r,t)=>{try{const a=await oe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling tool",{serverName:s,toolName:r,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},os=async(s,r,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating tool description",{serverName:s,toolName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},is=async(s,r)=>{var t;try{const a=await Ze(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting tool description",{serverName:s,toolName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},Ls=Object.freeze(Object.defineProperty({__proto__:null,callTool:ns,resetToolDescription:is,toggleTool:Bs,updateToolDescription:os},Symbol.toStringTag,{value:"Module"})),ls=({schema:s,onSubmit:r,onCancel:t,loading:a=!1,storageKey:x,title:g})=>{const{t:n}=se(),[N,C]=u.useState({}),[i,o]=u.useState({}),[S,T]=u.useState(!1),[v,I]=u.useState(""),[w,P]=u.useState(""),y=u.useMemo(()=>(m=>{const j=c=>{if(typeof c=="object"&&c!==null){const p=c;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([d,f])=>[d,j(f)])):void 0,required:p.required,items:p.items?j(p.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([c,p])=>[c,j(p)])):void 0,required:m.required}})(s),[s]);u.useEffect(()=>{const h=(j,c="")=>{const p={};return j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([d,f])=>{const R=c?`${c}.${d}`:d;f.default!==void 0?p[d]=f.default:f.type==="string"?p[d]="":f.type==="number"||f.type==="integer"?p[d]=0:f.type==="boolean"?p[d]=!1:f.type==="array"?p[d]=[]:f.type==="object"&&(f.properties?p[d]=h(f,R):p[d]={})}),p};let m=h(y);if(x)try{const j=localStorage.getItem(x);if(j){const c=JSON.parse(j);m={...m,...c}}}catch(j){console.warn("Failed to load saved form data:",j)}C(m)},[y,x]),u.useEffect(()=>{S&&Object.keys(N).length>0&&(I(JSON.stringify(N,null,2)),P(""))},[S,N]);const A=h=>{I(h),P("");try{const m=JSON.parse(h);if(C(m),x)try{localStorage.setItem(x,JSON.stringify(m))}catch(j){console.warn("Failed to save form data to localStorage:",j)}}catch{P(n("tool.invalidJsonFormat"))}},J=()=>{I(JSON.stringify(N,null,2)),P(""),T(!0)},U=()=>{if(v.trim())try{const h=JSON.parse(v);C(h),P(""),T(!1)}catch{P(n("tool.fixJsonBeforeSwitching"));return}else T(!1)},_=(h,m)=>{C(j=>{const c={...j},p=h.split(".");let d=c;for(let f=0;f<p.length-1;f++)d[p[f]]||(d[p[f]]={}),d=d[p[f]];if(d[p[p.length-1]]=m,x)try{localStorage.setItem(x,JSON.stringify(c))}catch(f){console.warn("Failed to save form data to localStorage:",f)}return c}),i[h]&&o(j=>{const c={...j};return delete c[h],c})},V=()=>{const h={},m=(j,c,p="")=>{j.type==="object"&&j.properties&&Object.entries(j.properties).forEach(([d,f])=>{var B;const R=p?`${p}.${d}`:d,D=c==null?void 0:c[d];if((B=j.required)!=null&&B.includes(d)&&(D==null||D===""||Array.isArray(D)&&D.length===0)){h[R]=`${d} is required`;return}D!=null&&D!==""&&(f.type==="string"&&typeof D!="string"?h[R]=`${d} must be a string`:f.type==="number"&&typeof D!="number"?h[R]=`${d} must be a number`:f.type==="integer"&&(!Number.isInteger(D)||typeof D!="number")?h[R]=`${d} must be an integer`:f.type==="boolean"&&typeof D!="boolean"?h[R]=`${d} must be a boolean`:f.type==="array"&&Array.isArray(D)?f.items&&D.forEach((X,O)=>{var G;((G=f.items)==null?void 0:G.type)==="object"&&f.items.properties&&m(f.items,X,`${R}.${O}`)}):f.type==="object"&&typeof D=="object"&&m(f,D,R))})};return m(y,N),o(h),Object.keys(h).length===0},F=h=>{h.preventDefault(),V()&&r(N)},q=(h,m)=>m.split(".").reduce((j,c)=>j==null?void 0:j[c],h),H=(h,m,j,c)=>{const p=j==null?void 0:j[h];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",onChange:d=>c(d.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:n("tool.selectOption")}),m.enum.map((d,f)=>e.jsx("option",{value:d,children:d},f))]}):e.jsx("input",{type:"text",value:p||"",onChange:d=>c(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||n("tool.enterKey",{key:h})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:d=>{const f=d.target.value===""?"":m.type==="integer"?parseInt(d.target.value):parseFloat(d.target.value);c(f)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):m.type==="boolean"?e.jsx("input",{type:"checkbox",checked:p||!1,onChange:d=>c(d.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:p||"",onChange:d=>c(d.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||n("tool.enterKey",{key:h})})},Y=(h,m,j="")=>{var f,R,D,B,X,O,G,E,L,te,le,z,W,Q;const c=j?`${j}.${h}`:h,p=q(N,c),d=i[c];if(m.type==="array"){const $=q(N,c)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(R=(f=q(y,j))==null?void 0:f.required)==null?void 0:R.includes(h):(D=y.required)==null?void 0:D.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[$.map((Z,ee)=>{var pe,xe,he;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:n("tool.item",{index:ee+1})}),e.jsx("button",{type:"button",onClick:()=>{const K=[...$];K.splice(ee,1),_(c,K)},className:"text-status-red hover:text-red-700 text-sm",children:n("common.remove")})]}),((pe=m.items)==null?void 0:pe.type)==="string"&&m.items.enum?e.jsxs("select",{value:Z||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(c,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:n("tool.selectOption")}),m.items.enum.map((K,re)=>e.jsx("option",{value:K,children:K},re))]}):((xe=m.items)==null?void 0:xe.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([K,re])=>{var be,fe;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[K,((fe=(be=m.items)==null?void 0:be.required)==null?void 0:fe.includes(K))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),H(K,re,Z,Ce=>{const ue=[...$];ue[ee]={...ue[ee],[K]:Ce},_(c,ue)})]},K)})}):e.jsx("input",{type:"text",value:Z||"",onChange:K=>{const re=[...$];re[ee]=K.target.value,_(c,re)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:n("tool.enterValue",{type:((he=m.items)==null?void 0:he.type)||"value"})})]},ee)}),e.jsx("button",{type:"button",onClick:()=>{var ee;const Z=((ee=m.items)==null?void 0:ee.type)==="object"?{}:"";_(c,[...$,Z])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:n("tool.addItem",{key:h})})]}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c)}return m.type==="object"?m.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(X=(B=q(y,j))==null?void 0:B.required)==null?void 0:X.includes(h):(O=y.required)==null?void 0:O.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(m.properties).map(([$,Z])=>Y($,Z,c))}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?(E=(G=q(y,j))==null?void 0:G.required)==null?void 0:E.includes(h):(L=y.required)==null?void 0:L.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)"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("textarea",{value:typeof p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:$=>{try{const Z=JSON.parse($.target.value);_(c,Z)}catch{_(c,$.target.value)}},placeholder:`{
|
|
3
3
|
"key": "value"
|
|
4
4
|
}`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):m.type==="string"?m.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?!1:(te=y.required)==null?void 0:te.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("select",{value:p||"",onChange:$=>_(c,$.target.value),className:`w-full border rounded-md px-3 py-2 ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:n("tool.selectOption")}),m.enum.map(($,Z)=>e.jsx("option",{value:$,children:$},Z))]}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?!1:(le=y.required)==null?void 0:le.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:p||"",onChange:$=>_(c,$.target.value),className:`w-full border rounded-md px-3 py-2 ${d?"border-red":"border-gray-200"} focus:outline-none form-input`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):m.type==="number"||m.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?!1:(z=y.required)==null?void 0:z.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:$=>{const Z=$.target.value===""?"":m.type==="integer"?parseInt($.target.value):parseFloat($.target.value);_(c,Z)},className:`w-full border rounded-md px-3 py-2 form-input ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):m.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:p||!1,onChange:$=>_(c,$.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,(j?!1:(W=y.required)==null?void 0:W.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:m.description}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[h,(j?!1:(Q=y.required)==null?void 0:Q.includes(h))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",m.type,")"]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:p||"",onChange:$=>_(c,$.target.value),placeholder:n("tool.enterValue",{type:m.type}),className:`w-full border rounded-md px-3 py-2 ${d?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),d&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:d})]},c)};return y.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:g}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:U,className:`hub-btn sm ${S?"":"primary"}`,children:n("tool.formMode")}),e.jsx("button",{type:"button",onClick:J,className:`hub-btn sm ${S?"primary":""}`,children:n("tool.jsonMode")})]})]}),S?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:n("tool.jsonConfiguration")}),e.jsx("textarea",{value:v,onChange:h=>A(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 ${w?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),w&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:w})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:n("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const h=JSON.parse(v);r(h)}catch{P(n("tool.invalidJsonFormat"))}},disabled:a||!!w,className:"hub-btn sm primary",children:n(a?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[Object.entries(y.properties||{}).map(([h,m])=>Y(h,m)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:n("tool.cancel")}),e.jsx("button",{type:"submit",disabled:a,className:"hub-btn sm primary",children:n(a?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:n("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:n("tool.cancel")}),e.jsx("button",{onClick:()=>r({}),disabled:a,className:"hub-btn primary",children:n(a?"tool.running":"tool.runTool")})]})]})},Ws=({result:s,onClose:r})=>{const{t}=se(),a=s.content,x=o=>o?o.startsWith("image/")?o:`image/${o}`:"image/png",g=o=>{if(!o)return[];if(Array.isArray(o))return o.flatMap(v=>g(v));if(typeof o!="object")return[];const S=[];o.type==="image"&&o.data&&S.push({data:String(o.data),mimeType:x(o.mimeType||o.mime_type)});const T=o.image_base64||o.imageBase64||o.image_data||o.imageData||o.base64;return T&&S.push({data:String(T),mimeType:x(o.image_mimeType||o.image_mime_type||o.mimeType||o.mime_type)}),o.image&&typeof o.image=="object"&&S.push(...g(o.image)),Array.isArray(o.images)&&S.push(...g(o.images)),Array.isArray(o.content)&&S.push(...g(o.content)),S},n=o=>{const S=[];try{const I=JSON.parse(o);if(S.push(...g(I)),S.length>0)return S}catch{}const T=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let v;for(;(v=T.exec(o))!==null;){const I=`image/${v[1]==="jpg"?"jpeg":v[1]}`;S.push({data:v[2],mimeType:I})}return S},N=o=>{try{const S=JSON.parse(o),T=v=>{if(Array.isArray(v))return v.map(T);if(v&&typeof v=="object"){const I={};for(const[w,P]of Object.entries(v))typeof P=="string"&&w.toLowerCase().includes("base64")?I[w]="[base64 omitted]":I[w]=T(P);return I}return v};return JSON.stringify(T(S),null,2)}catch{return o.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},C=o=>Array.isArray(o)?o.map((S,T)=>e.jsx("div",{className:"mb-3 last:mb-0",children:i(S)},T)):i(o),i=o=>{if(typeof o=="string"){const S=n(o),T=N(o);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(typeof o=="object"&&o!==null){if(o.type==="text"&&o.text){const S=n(o.text),T=N(o.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(o.type==="image"&&o.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${o.mimeType||"image/png"};base64,${o.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const S=typeof o=="string"?JSON.parse(o):o;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(S,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(o)})})}}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(o)})})};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(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),C(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),a&&a.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),C(a)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},de=({title:s,onClick:r,disabled:t=!1,loading:a=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:r,disabled:t,title:s,"aria-label":s,children:e.jsx(Es,{size:14,className:a?"animate-spin":""})});function qs(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 Hs=({tool:s,server:r,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:g})=>{const{t:n}=se(),{showToast:N}=Ee(),{nameSeparator:C}=Pe(),[i,o]=u.useState(!1),[S,T]=u.useState(!1),[v,I]=u.useState(!1),[w,P]=u.useState(null),[y,A]=u.useState(!1),[J,U]=u.useState(!1),[_,V]=u.useState(s.description||""),F=u.useRef(null),q=u.useRef(null),[H,Y]=u.useState(0),[h,m]=u.useState(!1);u.useEffect(()=>{y&&F.current&&(F.current.focus(),H>0&&(F.current.style.width=`${H+20}px`))},[y,H]),u.useEffect(()=>{!y&&q.current&&Y(q.current.offsetWidth)},[y,_]),u.useEffect(()=>{V(s.description||"")},[s.description]);const j=s.name.replace(r+C,""),c=Ms(s,n("tool.noDescription")),p=c.hasDescriptionOverride?n("tool.defaultDescriptionTooltip",{description:c.defaultDescription}):void 0,d=u.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),f=u.useCallback(()=>{localStorage.removeItem(d())},[d]),R=z=>{!t&&a&&a(s.name,z)},D=()=>{t||A(!0)},B=async()=>{if(!t)try{const z=await os(r,s.name,_);z.success?(A(!1),x&&x(s.name,_)):(V(s.description||""),console.error("Failed to update tool description:",z.error))}catch(z){console.error("Error updating tool description:",z),V(s.description||""),A(!1)}},X=z=>{V(z.target.value)},O=async()=>{if(!t){U(!0);try{const z=await is(r,s.name);if(z.success){const W=z.description||"";V(W),A(!1),x==null||x(s.name,W,{restored:!0})}else N(z.error||n("tool.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting tool description:",z),N(n("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},G=z=>{z.key==="Enter"?B():z.key==="Escape"&&(V(s.description||""),A(!1))},E=async z=>{z.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),N(n("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const W=document.createElement("textarea");W.value=s.name,W.style.position="fixed",W.style.left="-9999px",document.body.appendChild(W),W.focus(),W.select();try{document.execCommand("copy"),m(!0),N(n("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(Q){N(n("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Q)}document.body.removeChild(W)}}catch(W){N(n("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",W)}},L=async z=>{I(!0);try{z=Object.fromEntries(Object.entries(z).filter(([Q,$])=>!qs($)));const W=await ns({toolName:s.name,arguments:z},r);P(W)}catch(W){P({success:!1,error:W instanceof Error?W.message:"Unknown error occurred"})}finally{I(!1)}},te=()=>{T(!1),f(),P(null)},le=()=>{P(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:z=>{z.stopPropagation(),o(!i)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:j}),e.jsx("button",{className:"hub-icon-btn sm",onClick:E,title:n("common.copy"),children:h?e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:y?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:_,onChange:X,onKeyDown:G,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),B()},disabled:J,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:n("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:J,loading:J})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:q,title:p,children:c.currentDescription}),c.hasDescriptionOverride&&e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{color:"var(--hub-accent)",borderColor:"var(--hub-line)",background:"var(--hub-bg-2)"},title:p,children:n("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),D()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:n("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:J,loading:J})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:n("cost.estimate"),children:["Σ ",ne(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:R,disabled:v||t,size:"card","aria-label":`${n(s.enabled??!0?"server.disable":"server.enable")} ${j}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),o(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:v||!s.enabled,children:[v?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:n(v?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[c.hasDescriptionOverride&&c.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:n("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c.defaultDescription})]}),!S&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:n("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:s.inputSchema||{type:"object"},onSubmit:L,onCancel:te,loading:v,storageKey:d(),title:n("tool.runToolWithName",{name:j})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ws,{result:w,onClose:le})})]})]})]})},Ks=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",a=await oe(t,{promptName:s.promptName,arguments:s.arguments});return a.success?{success:!0,data:a.data}:{success:!1,error:a.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},cs=async(s,r)=>{try{const t=await oe(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Gs=async(s,r,t)=>{try{const a=await oe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},ds=async(s,r,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},us=async(s,r)=>{var t;try{const a=await Ze(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting prompt description",{serverName:s,promptName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},Xs=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:Ks,getPrompt:cs,resetPromptDescription:us,togglePrompt:Gs,updatePromptDescription:ds},Symbol.toStringTag,{value:"Module"})),He=({result:s,onClose:r})=>{const{t}=se(),a=x=>{if(typeof x=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:x})});if(typeof x=="object"&&x!==null){if(x.description||x.messages)return e.jsxs("div",{className:"space-y-4",children:[x.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:x.description})})]}),x.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:x.messages.map((g,n)=>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:[g.role,":"]})}),typeof g.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content}):typeof g.content=="object"&&g.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g.content,null,2)})]},n))})]})]});try{const g=typeof x=="string"?JSON.parse(x):x;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(x)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(x)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),a(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Ys=({prompt:s,server:r,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:g})=>{const{t:n}=se(),{showToast:N}=Ee(),{nameSeparator:C}=Pe(),[i,o]=u.useState(!1),[S,T]=u.useState(!1),[v,I]=u.useState(!1),[w,P]=u.useState(null),[y,A]=u.useState(!1),[J,U]=u.useState(!1),[_,V]=u.useState(s.description||""),F=u.useRef(null),q=u.useRef(null),[H,Y]=u.useState(0);u.useEffect(()=>{y&&F.current&&(F.current.focus(),H>0&&(F.current.style.width=`${H+20}px`))},[y,H]),u.useEffect(()=>{!y&&q.current&&Y(q.current.offsetWidth)},[y,_]),u.useEffect(()=>{V(s.description||"")},[s.description]);const h=u.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),m=u.useCallback(()=>{localStorage.removeItem(h())},[h]),j=E=>{!t&&a&&a(s.name,E)},c=()=>{t||A(!0)},p=async()=>{if(!t){A(!1);try{const E=await ds(r,s.name,_);E.success?x&&x(s.name,_):(N(E.error||n("prompt.descriptionUpdateFailed"),"error"),V(s.description||""))}catch(E){console.error("Error updating prompt description:",E),N(n("prompt.descriptionUpdateFailed"),"error"),V(s.description||"")}}},d=async()=>{if(!t){U(!0);try{const E=await us(r,s.name);if(E.success){const L=E.description||"";V(L),A(!1),x==null||x(s.name,L,{restored:!0})}else N(E.error||n("prompt.restoreDefaultFailed"),"error")}catch(E){console.error("Error resetting prompt description:",E),N(n("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},f=E=>{V(E.target.value)},R=E=>{E.key==="Enter"?p():E.key==="Escape"&&(V(s.description||""),A(!1))},D=async E=>{I(!0);try{const L=await cs({promptName:s.name,arguments:E},r);console.log("GetPrompt result:",L),P({success:L.success,data:L.data,error:L.error})}catch(L){P({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{I(!1)}},B=()=>{T(!1),m(),P(null)},X=()=>{P(null)},O=s.name.replace(r+C,""),G=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const E={},L=[];return s.arguments.forEach(te=>{E[te.name]={type:"string",description:te.description||""},te.required&&L.push(te.name)}),{type:"object",properties:E,required:L}};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:()=>o(!i),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:O}),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:y?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:_,onChange:f,onKeyDown:R,onClick:E=>E.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),p()},disabled:J,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:n("prompt.restoreDefault"),onClick:E=>{E.stopPropagation(),d()},disabled:J,loading:J})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:q,children:_||n("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),c()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:n("prompt.restoreDefault"),onClick:E=>{E.stopPropagation(),d()},disabled:J,loading:J})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:n("cost.estimate"),children:["Σ ",ne(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:E=>E.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ne,{checked:s.enabled,onCheckedChange:j,disabled:v||t,size:"card","aria-label":`${n(s.enabled?"server.disable":"server.enable")} ${O}`})}),e.jsxs("button",{onClick:E=>{E.stopPropagation(),o(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:v||!s.enabled,children:[v?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:n(v?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:G(),onSubmit:D,onCancel:B,loading:v,storageKey:h(),title:n("prompt.runPromptWithName",{name:O})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(He,{result:w,onClose:X})})]}),!S&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:n("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((E,L)=>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:E.name}),E.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),E.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:E.description})]}),E.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:E.title})]},L))})]}),!S&&w&&e.jsx("div",{children:e.jsx(He,{result:w,onClose:X})})]})]})},Zs=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:a,cost:x})=>{const{t:g}=se(),[n,N]=u.useState(!1),[C,i]=u.useState(!1),[o,S]=u.useState(!1),[T,v]=u.useState(s.description||""),I=u.useRef(null),w=u.useRef(null),[P,y]=u.useState(0);u.useEffect(()=>{C&&I.current&&(I.current.focus(),P>0&&(I.current.style.width=`${P+20}px`))},[C,P]),u.useEffect(()=>{!C&&w.current&&y(w.current.offsetWidth)},[C,T]),u.useEffect(()=>{v(s.description||"")},[s.description]);const A=s.name||s.uri,J=F=>{!r&&t&&t(s.uri,F)},U=async()=>{r||(i(!1),a&&await a(s.uri,T))},_=async()=>{if(!r){S(!0);try{await(a==null?void 0:a(s.uri,"",{restored:!0})),i(!1)}finally{S(!1)}}},V=F=>{F.key==="Enter"?U():F.key==="Escape"&&(v(s.description||""),i(!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:()=>N(!n),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:A}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:C?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:P>0?`${P+20}px`:160,minWidth:80},value:T,onChange:F=>v(F.target.value),onKeyDown:V,onClick:F=>F.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:F=>{F.stopPropagation(),U()},disabled:o,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:F=>{F.stopPropagation(),_()},disabled:o,loading:o})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:w,children:T||g("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:F=>{F.stopPropagation(),i(!0)},children:e.jsx(De,{size:12})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:F=>{F.stopPropagation(),_()},disabled:o,loading:o})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[x!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:g("cost.estimate"),children:["Σ ",ne(x)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:F=>F.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled!==!1,onCheckedChange:J,disabled:r,size:"card","aria-label":`${g(s.enabled!==!1?"server.disable":"server.enable")} ${A}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:n?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),n&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[g("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Qs=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,et={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Te=s=>s==="public"||s==="group"?s:"private",st=(s,r)=>{const t=Te(r),a=et[t];return{value:t,shortLabel:s(a.shortKey,{defaultValue:a.shortFallback}),longLabel:s(a.longKey,{defaultValue:a.longFallback}),className:a.className}},tt=(s,r)=>{const t=Te(r),a=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&a.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),a.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),a},Ke=({isLoading:s,children:r,className:t,overlayStyle:a,spinnerSize:x=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:r}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...a},children:e.jsx(je,{size:x,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),Ge=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),Xe=(s,r)=>r?r==="stdio"?s("server.typeStdio")||"stdio":r==="sse"?s("server.typeSse")||"sse":r==="streamable-http"?s("server.typeStreamableHttp")||"http":r==="openapi"?s("server.typeOpenapi")||"openapi":r:null,rt="text/html;profile=mcp-app",Ye=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,at=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(a=>Ye(a._meta))||(t=s.resources)!=null&&t.some(a=>{var x;return((x=a.uri)==null?void 0:x.startsWith("ui://"))||a.mimeType===rt||Ye(a._meta)}))},nt=({server:s,cost:r,onRemove:t,onEdit:a,onToggle:x,onVisibilityChange:g,onRefresh:n,onReload:N,onReinstall:C})=>{var Re,_e,Oe,Ae,Me,Ve,Je,Ue,Be,Le,We,qe;const{t:i}=se(),{showToast:o}=Ee(),{exportMCPSettings:S,installConfig:T}=Pe(),{auth:v}=js(),I=((Re=T==null?void 0:T.baseUrl)==null?void 0:Re.replace(/\/+$/,""))||"",[w,P]=u.useState(!1),[y,A]=u.useState(null),[J,U]=u.useState(!1),[_,V]=u.useState(!1),[F,q]=u.useState(!1),[H,Y]=u.useState(!1),[h,m]=u.useState(!1),[j,c]=u.useState(!1),[p,d]=u.useState(!1),[f,R]=u.useState(!1),[D,B]=u.useState(!1),X=u.useRef(null),O=u.useRef(null);u.useEffect(()=>{const l=b=>{X.current&&!X.current.contains(b.target)&&d(!1),O.current&&!O.current.contains(b.target)&&R(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[]);const G=((_e=s.tools)==null?void 0:_e.length)||0,E=((Oe=s.tools)==null?void 0:Oe.filter(l=>l.enabled!==!1).length)||0,L=((Ae=s.prompts)==null?void 0:Ae.length)||0,te=((Me=s.prompts)==null?void 0:Me.filter(l=>l.enabled!==!1).length)||0,le=((Ve=s.resources)==null?void 0:Ve.length)||0,z=((Je=s.resources)==null?void 0:Je.filter(l=>l.enabled!==!1).length)||0,W=at(s),Q=s.enabled!==!1,$=Qs(s,v.user),Z=((Ue=s.config)==null?void 0:Ue.command)==="npx"||((Be=s.config)==null?void 0:Be.command)==="uvx",ee=async l=>{if(!(!$||F||!x)){q(!0);try{await x(s,l)}finally{q(!1)}}},pe=async l=>{if(l.stopPropagation(),d(!1),!(!$||h||!N)){m(!0);try{await N(s)?o(i("server.reloadSuccess")||"Server reloaded successfully","success"):o(i("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{m(!1)}}},xe=async()=>{if(d(!1),!(!$||j||!C)){c(!0);try{await C(s)?o(i("server.reinstallSuccess")||"Server reinstall initiated","success"):o(i("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{c(!1)}}},he=async l=>{var k;if(l.stopPropagation(),!$||H||!g)return;const b=l.target.value;if(b!==Te(s.visibility??((k=s.config)==null?void 0:k.visibility))){Y(!0);try{await g(s,b)}finally{Y(!1)}}},K=async l=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(l),!0}catch{}try{const b=document.createElement("textarea");b.value=l,b.style.position="fixed",b.style.left="-9999px",document.body.appendChild(b),b.focus(),b.select();const k=document.execCommand("copy");return document.body.removeChild(b),k}catch{return!1}},re=async l=>{if(l.stopPropagation(),!s.error)return;await K(s.error)?(B(!0),o(i("common.copySuccess")||"Copied","success"),setTimeout(()=>B(!1),1500)):o(i("common.copyFailed")||"Copy failed","error")},be=async l=>{if(l.stopPropagation(),d(!1),!!$)try{const b=await S(s.name);if(!b||!b.success||!b.data){o((b==null?void 0:b.message)||i("common.copyFailed")||"Copy failed","error");return}const k=JSON.stringify(b.data,null,2),M=await K(k);o(M?i("common.copySuccess")||"Copied":i("common.copyFailed")||"Copy failed",M?"success":"error")}catch(b){console.error("Error copying server configuration:",b),o(i("common.copyFailed")||"Copy failed","error")}},fe=l=>{var b;if(l.stopPropagation(),(b=s.oauth)!=null&&b.authorizationUrl){const ae=window.screen.width/2-300,ie=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ae},top=${ie}`),o(i("status.oauthWindowOpened"),"info")}},Ce=async(l,b)=>{try{const{toggleTool:k}=await ge(async()=>{const{toggleTool:ae}=await Promise.resolve().then(()=>Ls);return{toggleTool:ae}},void 0,import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ue=async(l,b)=>{try{const{togglePrompt:k}=await ge(async()=>{const{togglePrompt:ae}=await Promise.resolve().then(()=>Xs);return{togglePrompt:ae}},void 0,import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ms=async(l,b)=>{try{const{toggleResource:k}=await ge(async()=>{const{toggleResource:ae}=await import("./resourceService-CfOZGPdl.js");return{toggleResource:ae}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ps=(l,b,k)=>{o(k!=null&&k.restored?i("tool.restoreDefaultSuccess"):i("tool.descriptionUpdateSuccess"),"success"),n==null||n()},xs=(l,b,k)=>{o(k!=null&&k.restored?i("prompt.restoreDefaultSuccess"):i("prompt.descriptionUpdateSuccess"),"success"),n==null||n()},hs=async(l,b,k)=>{try{const{updateResourceDescription:M,resetResourceDescription:ae}=await ge(async()=>{const{updateResourceDescription:fs,resetResourceDescription:gs}=await import("./resourceService-CfOZGPdl.js");return{updateResourceDescription:fs,resetResourceDescription:gs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ie=k!=null&&k.restored?await ae(s.name,l):await M(s.name,l,b);ie.success?(o(k!=null&&k.restored?i("builtinResources.restoreDefaultSuccess"):i("builtinResources.descriptionUpdateSuccess"),"success"),n==null||n()):o(ie.error||(k!=null&&k.restored?i("builtinResources.restoreDefaultFailed"):i("builtinResources.descriptionUpdateFailed")),"error")}catch(M){console.error(M),o(k!=null&&k.restored?i("builtinResources.restoreDefaultFailed"):i("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var k;const l=s.config;if(!l)return"";if(l.url)return l.url;const b=[];return l.command&&b.push(l.command),(k=l.args)!=null&&k.length&&b.push(...l.args),b.join(" ")})();const $e=`${I}/mcp/${s.name}`,Fe=(l,b)=>i(l,b),ce=st(Fe,s.visibility??((Le=s.config)==null?void 0:Le.visibility)),bs=tt(Fe,ce.value),Ie=[{key:"tools",icon:Ps,total:G,enabled:E,label:i("server.tools")},{key:"prompts",icon:Ds,total:L,enabled:te,label:i("server.prompts")},{key:"resources",icon:zs,total:le,enabled:z,label:i("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>P(!w),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ke,{size:12,style:{color:"var(--hub-ink-3)",transform:w?"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:Q?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),W&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:i("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:O,children:[e.jsx("button",{onClick:l=>{l.stopPropagation(),R(b=>!b)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":i("server.viewErrorDetails"),children:e.jsx(we,{size:14})}),f&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:i("server.errorDetails")}),e.jsx("button",{onClick:re,className:"hub-icon-btn sm",title:i("common.copy"),children:D?e.jsx(me,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>R(!1),className:"hub-icon-btn sm","aria-label":i("app.closeButton"),children:e.jsx(Se,{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})})]})]})]}),((We=s.config)==null?void 0:We.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(Ss,{status:s.status,enabled:s.enabled,onAuthClick:fe,className:"hub-server-card-status"})}),e.jsx("div",{className:"min-w-0",children:(qe=s.config)!=null&&qe.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Xe(i,s.config.type)??void 0,children:Xe(i,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:l=>l.stopPropagation(),children:$&&g?e.jsx(Ke,{isLoading:H,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ce.value,onChange:he,disabled:H,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":i("server.visibility","Visibility"),title:ce.longLabel,children:bs.map(l=>e.jsx("option",{value:l.value,disabled:l.disabled,children:l.label},l.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${ce.className}`,title:ce.longLabel,children:ce.shortLabel})}),Ie.map(({key:l,icon:b,total:k,enabled:M,label:ae})=>{const ie=k===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${ie?"is-empty":""}`,title:`${ae}: ${M}/${k}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(Ge,{icon:b})}),e.jsx("span",{className:"hub-server-capability-value",children:ie?"0":`${M}/${k}`})]},l)}),r&&r.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${i("cost.exposed")} ${r.exposed} / ${i("cost.gross")} ${r.gross} · ${i("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ne(r.exposed),"/",ne(r.gross)]})]}):r?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:i("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:l=>l.stopPropagation(),children:e.jsx(Ke,{isLoading:F,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ne,{checked:Q,onCheckedChange:ee,disabled:F||!$,size:"compact","aria-label":`${i(Q?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:X,children:[$&&e.jsx("button",{className:"hub-icon-btn",onClick:l=>{l.stopPropagation(),d(b=>!b)},"aria-label":"More",children:e.jsx(Ts,{size:14})}),$&&p&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:l=>l.stopPropagation(),children:[e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),a(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx($s,{size:13})," ",i("server.edit")]}),e.jsxs("button",{onClick:be,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",i("server.copy")]}),N&&e.jsxs("button",{onClick:pe,disabled:h||F||!Q,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(je,{size:13})," ",i("server.reload")]}),C&&Z&&e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),!(!$||j||!Q)&&V(!0)},disabled:j||F||!Q,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(Fs,{size:13})," ",i("server.reinstall")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),U(!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(Is,{size:13})," ",i("server.delete")]})]})]})]}),w&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Ie.map(l=>{const b=y===l.key,k=l.icon;return e.jsxs("button",{onClick:()=>A(b?null:l.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:b?"var(--hub-surface)":"transparent",border:"1px solid "+(b?"var(--hub-line)":"transparent"),color:b?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(Ge,{icon:k}),e.jsx("span",{children:l.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:l.total===0?"0":`${l.enabled}/${l.total}`})]},l.key)}),r&&r.connected&&e.jsxs("button",{onClick:()=>A(y==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:y==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(y==="cost"?"var(--hub-line)":"transparent"),color:y==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:i("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:i("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ne(r.exposed),"/",ne(r.gross)]})]}),e.jsx("div",{className:"ml-auto max-w-full flex-shrink-0",children:e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:$e,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async l=>{l.stopPropagation();const b=await K($e);o(b?i("common.copySuccess")||"Copied":i("common.copyFailed")||"Failed",b?"success":"error")},title:i("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),y==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((l,b)=>b.cost-l.cost).map(l=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:l.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:l.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ne(l.cost)})]},`${l.kind}:${l.name}`))}),y==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((l,b)=>{var k;return e.jsx(Hs,{server:s.name,tool:l,readOnly:!$,onToggle:Ce,onDescriptionUpdate:ps,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="tool"&&M.name===l.name))==null?void 0:k.cost},b)})}),y==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((l,b)=>{var k;return e.jsx(Ys,{server:s.name,prompt:l,readOnly:!$,onToggle:ue,onDescriptionUpdate:xs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="prompt"&&M.name===l.name))==null?void 0:k.cost},b)})}),y==="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:i("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((l,b)=>{var k;return e.jsx(Zs,{resource:l,readOnly:!$,onToggle:ms,onDescriptionUpdate:hs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="resource"&&M.name===l.uri))==null?void 0:k.cost},`${l.uri}-${b}`)})})})]})]}),e.jsx(Vs,{isOpen:J,onClose:()=>U(!1),onConfirm:()=>{t(s.name),U(!1)},serverName:s.name}),e.jsx(rs,{isOpen:_,onClose:()=>V(!1),onConfirm:()=>{V(!1),xe()},title:i("server.reinstall"),message:i("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:i("server.reinstall"),variant:"warning"})]})},ot=({onAdd:s})=>{const{t:r}=se(),[t,a]=u.useState(!1),[x,g]=u.useState(null),[n,N]=u.useState(!1),[C,i]=u.useState(null),[o,S]=u.useState([]),T=()=>{a(!t),g(null),N(!1),i(null)},v=async()=>{C&&(await I(C),N(!1),i(null))},I=async P=>{try{g(null);const y=await oe("/servers",P);if(!y.success){y&&y.message?g(y.message):g(r("server.addError"));return}a(!1),s()}catch(y){console.error("Error adding server:",y),navigator.onLine?y instanceof TypeError&&(y.message.includes("NetworkError")||y.message.includes("Failed to fetch"))?g(r("errors.serverConnection")):g(r("errors.serverAdd")):g(r("errors.network"))}},w=async P=>{try{const y=Js(P);y.length>0?(S(y),i(P),N(!0)):await I(P)}catch(y){console.error("Error processing server submission:",y),g(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:T,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(as,{onSubmit:w,onCancel:T,modalTitle:r("server.addServer"),formError:x})}),n&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:o.map((P,y)=>e.jsxs("li",{className:"font-mono",children:["$",`{${P}}`]},y))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{N(!1),i(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:v,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},it=({server:s,onEdit:r,onCancel:t})=>{const{t:a}=se(),[x,g]=u.useState(null),n=async N=>{try{g(null);const C=encodeURIComponent(s.name),i=N.name&&N.name!==s.name,o={config:N.config,...i?{newName:N.name}:{}},S=await ve(`/servers/${C}`,o);if(!S.success){S&&S.message?g(S.message):g(a("server.updateError",{serverName:s.name}));return}r()}catch(C){console.error("Error updating server:",C),navigator.onLine?C instanceof TypeError&&(C.message.includes("NetworkError")||C.message.includes("Failed to fetch"))?g(a("errors.serverConnection")):g(a("errors.serverUpdate",{serverName:s.name})):g(a("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(as,{onSubmit:n,onCancel:t,initialData:s,modalTitle:a("server.editTitle",{serverName:s.name}),formError:x})})},lt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[a,x]=u.useState(!1),[g,n]=u.useState(!1),[N,C]=u.useState(null),[i,o]=u.useState(null),[S,T]=u.useState(!1),[v,I]=u.useState(null),[w,P]=u.useState(""),[y,A]=u.useState(!1),[J,U]=u.useState(""),_=c=>{c.preventDefault(),x(!0)},V=c=>{c.preventDefault(),x(!1)},F=c=>{c.preventDefault(),x(!1);const p=c.dataTransfer.files;if(p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),C(null)):C(t("mcpb.invalidFileType"))}},q=c=>{const p=c.target.files;if(p&&p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),C(null)):C(t("mcpb.invalidFileType"))}},H=async()=>{if(!i){C(t("mcpb.noFileSelected"));return}n(!0),C(null);try{const c=new FormData;c.append("mcpbFile",i);const p=await Ns(ws("/mcpb/upload"),{method:"POST",body:c}),d=await p.json();if(!p.ok)throw new Error(d.message||`HTTP error! Status: ${p.status}`);if(d.success&&d.data)I(d.data.manifest),P(d.data.extractDir),T(!0);else throw new Error(d.message||t("mcpb.uploadFailed"))}catch(c){console.error("MCPB upload error:",c),C(c instanceof Error?c.message:t("mcpb.uploadFailed"))}finally{n(!1)}},Y=async(c,p=!1)=>{var d;n(!0),C(null);try{const f=j(v,w,c);if(!p){const D=await vs("/servers");if(D.success&&((d=D.data)==null?void 0:d.find(X=>X.name===c))){U(c),A(!0),n(!1);return}}let R;if(p?R=await ve(`/servers/${encodeURIComponent(c)}`,{name:c,config:f}):R=await oe("/servers",{name:c,config:f}),R.success)s(f);else throw new Error(R.message||t("mcpb.installFailed"))}catch(f){console.error("MCPB install error:",f),C(f instanceof Error?f.message:t("mcpb.installFailed")),n(!1)}},h=()=>{A(!1),J&&Y(J,!0)},m=()=>{A(!1),U(""),n(!1)},j=(c,p,d)=>{var D;const f=((D=c.server)==null?void 0:D.mcp_config)||{},R={type:"stdio",command:f.command||"node",args:(f.args||[]).map(B=>B.replace("${__dirname}",p))};return f.env&&Object.keys(f.env).length>0&&(R.env={...f.env},Object.keys(R.env).forEach(B=>{typeof R.env[B]=="string"&&(R.env[B]=R.env[B].replace("${__dirname}",p))})),R};return S&&v?e.jsxs(e.Fragment,{children:[e.jsx(rs,{isOpen:y,onClose:m,onConfirm:h,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:J}),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 ${y?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),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((c,p)=>e.jsxs("li",{children:[c.name," - ",c.description]},p))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:v.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const c=document.getElementById("serverName"),p=(c==null?void 0:c.value.trim())||v.name;Y(p)},disabled:g,className:"hub-btn primary",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${a?"border-blue-500 bg-blue-50":i?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:_,onDragLeave:V,onDrop:F,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:q,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:H,disabled:!i||g,className:"hub-btn primary flex items-center",children:g?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")})]})]})})},ct=s=>Object.entries(s.mcpServers).map(([r,t])=>{const a={};return t.type==="sse"||t.type==="streamable-http"?(a.type=t.type,a.url=t.url,t.headers&&(a.headers=t.headers)):t.type==="openapi"?(a.type="openapi",a.openapi=t.openapi):(a.type="stdio",a.command=t.command,a.args=t.args||[],t.env&&(a.env=t.env),t.options&&(a.options=t.options)),{name:r,config:a}}),dt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[a,x]=u.useState(""),[g,n]=u.useState(null),[N,C]=u.useState(!1),[i,o]=u.useState(null),S=`{
|
|
6
|
+
}`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${w?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),w&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:w})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:n("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const h=JSON.parse(v);r(h)}catch{P(n("tool.invalidJsonFormat"))}},disabled:a||!!w,className:"hub-btn sm primary",children:n(a?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[Object.entries(y.properties||{}).map(([h,m])=>Y(h,m)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:n("tool.cancel")}),e.jsx("button",{type:"submit",disabled:a,className:"hub-btn sm primary",children:n(a?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:n("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:n("tool.cancel")}),e.jsx("button",{onClick:()=>r({}),disabled:a,className:"hub-btn primary",children:n(a?"tool.running":"tool.runTool")})]})]})},Ws=({result:s,onClose:r})=>{const{t}=se(),a=s.content,x=o=>o?o.startsWith("image/")?o:`image/${o}`:"image/png",g=o=>{if(!o)return[];if(Array.isArray(o))return o.flatMap(v=>g(v));if(typeof o!="object")return[];const S=[];o.type==="image"&&o.data&&S.push({data:String(o.data),mimeType:x(o.mimeType||o.mime_type)});const T=o.image_base64||o.imageBase64||o.image_data||o.imageData||o.base64;return T&&S.push({data:String(T),mimeType:x(o.image_mimeType||o.image_mime_type||o.mimeType||o.mime_type)}),o.image&&typeof o.image=="object"&&S.push(...g(o.image)),Array.isArray(o.images)&&S.push(...g(o.images)),Array.isArray(o.content)&&S.push(...g(o.content)),S},n=o=>{const S=[];try{const I=JSON.parse(o);if(S.push(...g(I)),S.length>0)return S}catch{}const T=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let v;for(;(v=T.exec(o))!==null;){const I=`image/${v[1]==="jpg"?"jpeg":v[1]}`;S.push({data:v[2],mimeType:I})}return S},N=o=>{try{const S=JSON.parse(o),T=v=>{if(Array.isArray(v))return v.map(T);if(v&&typeof v=="object"){const I={};for(const[w,P]of Object.entries(v))typeof P=="string"&&w.toLowerCase().includes("base64")?I[w]="[base64 omitted]":I[w]=T(P);return I}return v};return JSON.stringify(T(S),null,2)}catch{return o.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},C=o=>Array.isArray(o)?o.map((S,T)=>e.jsx("div",{className:"mb-3 last:mb-0",children:i(S)},T)):i(o),i=o=>{if(typeof o=="string"){const S=n(o),T=N(o);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(typeof o=="object"&&o!==null){if(o.type==="text"&&o.text){const S=n(o.text),T=N(o.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((v,I)=>e.jsx("img",{src:`data:${v.mimeType||"image/png"};base64,${v.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},I))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:T})]})}if(o.type==="image"&&o.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${o.mimeType||"image/png"};base64,${o.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const S=typeof o=="string"?JSON.parse(o):o;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(S,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(o)})})}}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(o)})})};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(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),C(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),a&&a.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),C(a)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},de=({title:s,onClick:r,disabled:t=!1,loading:a=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:r,disabled:t,title:s,"aria-label":s,children:e.jsx(Es,{size:14,className:a?"animate-spin":""})});function qs(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 Hs=({tool:s,server:r,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:g})=>{const{t:n}=se(),{showToast:N}=Ee(),{nameSeparator:C}=Pe(),[i,o]=u.useState(!1),[S,T]=u.useState(!1),[v,I]=u.useState(!1),[w,P]=u.useState(null),[y,A]=u.useState(!1),[J,U]=u.useState(!1),[_,V]=u.useState(s.description||""),F=u.useRef(null),q=u.useRef(null),[H,Y]=u.useState(0),[h,m]=u.useState(!1);u.useEffect(()=>{y&&F.current&&(F.current.focus(),H>0&&(F.current.style.width=`${H+20}px`))},[y,H]),u.useEffect(()=>{!y&&q.current&&Y(q.current.offsetWidth)},[y,_]),u.useEffect(()=>{V(s.description||"")},[s.description]);const j=s.name.replace(r+C,""),c=Ms(s,n("tool.noDescription")),p=c.hasDescriptionOverride?n("tool.defaultDescriptionTooltip",{description:c.defaultDescription}):void 0,d=u.useCallback(()=>`mcphub_tool_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),f=u.useCallback(()=>{localStorage.removeItem(d())},[d]),R=z=>{!t&&a&&a(s.name,z)},D=()=>{t||A(!0)},B=async()=>{if(!t)try{const z=await os(r,s.name,_);z.success?(A(!1),x&&x(s.name,_)):(V(s.description||""),console.error("Failed to update tool description:",z.error))}catch(z){console.error("Error updating tool description:",z),V(s.description||""),A(!1)}},X=z=>{V(z.target.value)},O=async()=>{if(!t){U(!0);try{const z=await is(r,s.name);if(z.success){const W=z.description||"";V(W),A(!1),x==null||x(s.name,W,{restored:!0})}else N(z.error||n("tool.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting tool description:",z),N(n("tool.restoreDefaultFailed"),"error")}finally{U(!1)}}},G=z=>{z.key==="Enter"?B():z.key==="Escape"&&(V(s.description||""),A(!1))},E=async z=>{z.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),N(n("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const W=document.createElement("textarea");W.value=s.name,W.style.position="fixed",W.style.left="-9999px",document.body.appendChild(W),W.focus(),W.select();try{document.execCommand("copy"),m(!0),N(n("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(Q){N(n("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",Q)}document.body.removeChild(W)}}catch(W){N(n("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",W)}},L=async z=>{I(!0);try{z=Object.fromEntries(Object.entries(z).filter(([Q,$])=>!qs($)));const W=await ns({toolName:s.name,arguments:z},r);P(W)}catch(W){P({success:!1,error:W instanceof Error?W.message:"Unknown error occurred"})}finally{I(!1)}},te=()=>{T(!1),f(),P(null)},le=()=>{P(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:z=>{z.stopPropagation(),o(!i)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:j}),e.jsx("button",{className:"hub-icon-btn sm",onClick:E,title:n("common.copy"),children:h?e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:y?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:_,onChange:X,onKeyDown:G,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),B()},disabled:J,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:n("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:J,loading:J})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:q,title:p,children:c.currentDescription}),c.hasDescriptionOverride&&e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{color:"var(--hub-accent)",borderColor:"var(--hub-line)",background:"var(--hub-bg-2)"},title:p,children:n("tool.descriptionModifiedBadge")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),D()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:n("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),O()},disabled:J,loading:J})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:n("cost.estimate"),children:["Σ ",ne(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:z=>z.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled??!0,onCheckedChange:R,disabled:v||t,size:"card","aria-label":`${n(s.enabled??!0?"server.disable":"server.enable")} ${j}`})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),o(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:v||!s.enabled,children:[v?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:n(v?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[c.hasDescriptionOverride&&c.defaultDescription&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px dashed var(--hub-line)",fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsx("span",{className:"hub-sect",style:{marginRight:6},children:n("tool.defaultDescriptionLabel")}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c.defaultDescription})]}),!S&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:n("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:s.inputSchema||{type:"object"},onSubmit:L,onCancel:te,loading:v,storageKey:d(),title:n("tool.runToolWithName",{name:j})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ws,{result:w,onClose:le})})]})]})]})},Ks=async(s,r)=>{try{const t=r?`/prompts/call/${r}`:"/prompts/call",a=await oe(t,{promptName:s.promptName,arguments:s.arguments});return a.success?{success:!0,data:a.data}:{success:!1,error:a.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},cs=async(s,r)=>{try{const t=await oe(`/mcp/${encodeURIComponent(r||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:r,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Gs=async(s,r,t)=>{try{const a=await oe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/toggle`,{enabled:t});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error toggling prompt",{serverName:s,promptName:r,enabled:t,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},ds=async(s,r,t)=>{try{const a=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message}}catch(a){return console.error("Error updating prompt description",{serverName:s,promptName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},us=async(s,r)=>{var t;try{const a=await Ze(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(r)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:a.success,error:a.success?void 0:a.message,description:(t=a.data)==null?void 0:t.description}}catch(a){return console.error("Error resetting prompt description",{serverName:s,promptName:r,error:a}),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}},Xs=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:Ks,getPrompt:cs,resetPromptDescription:us,togglePrompt:Gs,updatePromptDescription:ds},Symbol.toStringTag,{value:"Module"})),He=({result:s,onClose:r})=>{const{t}=se(),a=x=>{if(typeof x=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:x})});if(typeof x=="object"&&x!==null){if(x.description||x.messages)return e.jsxs("div",{className:"space-y-4",children:[x.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:x.description})})]}),x.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:x.messages.map((g,n)=>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:[g.role,":"]})}),typeof g.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content}):typeof g.content=="object"&&g.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:g.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g.content,null,2)})]},n))})]})]});try{const g=typeof x=="string"?JSON.parse(x):x;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(g,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(x)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(x)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Qe,{size:20,className:"text-status-green"}):e.jsx(es,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),a(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(we,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Ys=({prompt:s,server:r,readOnly:t=!1,onToggle:a,onDescriptionUpdate:x,cost:g})=>{const{t:n}=se(),{showToast:N}=Ee(),{nameSeparator:C}=Pe(),[i,o]=u.useState(!1),[S,T]=u.useState(!1),[v,I]=u.useState(!1),[w,P]=u.useState(null),[y,A]=u.useState(!1),[J,U]=u.useState(!1),[_,V]=u.useState(s.description||""),F=u.useRef(null),q=u.useRef(null),[H,Y]=u.useState(0);u.useEffect(()=>{y&&F.current&&(F.current.focus(),H>0&&(F.current.style.width=`${H+20}px`))},[y,H]),u.useEffect(()=>{!y&&q.current&&Y(q.current.offsetWidth)},[y,_]),u.useEffect(()=>{V(s.description||"")},[s.description]);const h=u.useCallback(()=>`mcphub_prompt_form_${r?`${r}_`:""}${s.name}`,[s.name,r]),m=u.useCallback(()=>{localStorage.removeItem(h())},[h]),j=E=>{!t&&a&&a(s.name,E)},c=()=>{t||A(!0)},p=async()=>{if(!t){A(!1);try{const E=await ds(r,s.name,_);E.success?x&&x(s.name,_):(N(E.error||n("prompt.descriptionUpdateFailed"),"error"),V(s.description||""))}catch(E){console.error("Error updating prompt description:",E),N(n("prompt.descriptionUpdateFailed"),"error"),V(s.description||"")}}},d=async()=>{if(!t){U(!0);try{const E=await us(r,s.name);if(E.success){const L=E.description||"";V(L),A(!1),x==null||x(s.name,L,{restored:!0})}else N(E.error||n("prompt.restoreDefaultFailed"),"error")}catch(E){console.error("Error resetting prompt description:",E),N(n("prompt.restoreDefaultFailed"),"error")}finally{U(!1)}}},f=E=>{V(E.target.value)},R=E=>{E.key==="Enter"?p():E.key==="Escape"&&(V(s.description||""),A(!1))},D=async E=>{I(!0);try{const L=await cs({promptName:s.name,arguments:E},r);console.log("GetPrompt result:",L),P({success:L.success,data:L.data,error:L.error})}catch(L){P({success:!1,error:L instanceof Error?L.message:"Unknown error occurred"})}finally{I(!1)}},B=()=>{T(!1),m(),P(null)},X=()=>{P(null)},O=s.name.replace(r+C,""),G=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const E={},L=[];return s.arguments.forEach(te=>{E[te.name]={type:"string",description:te.description||""},te.required&&L.push(te.name)}),{type:"object",properties:E,required:L}};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:()=>o(!i),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:O}),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:y?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:H>0?`${H+20}px`:160,minWidth:80},value:_,onChange:f,onKeyDown:R,onClick:E=>E.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),p()},disabled:J,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:n("prompt.restoreDefault"),onClick:E=>{E.stopPropagation(),d()},disabled:J,loading:J})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:q,children:_||n("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:E=>{E.stopPropagation(),c()},children:e.jsx(De,{size:12})}),e.jsx(de,{title:n("prompt.restoreDefault"),onClick:E=>{E.stopPropagation(),d()},disabled:J,loading:J})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[g!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:n("cost.estimate"),children:["Σ ",ne(g)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:E=>E.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ne,{checked:s.enabled,onCheckedChange:j,disabled:v||t,size:"card","aria-label":`${n(s.enabled?"server.disable":"server.enable")} ${O}`})}),e.jsxs("button",{onClick:E=>{E.stopPropagation(),o(!0),T(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:v||!s.enabled,children:[v?e.jsx(ss,{size:12,className:"animate-spin"}):e.jsx(ts,{size:12}),e.jsx("span",{children:n(v?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:i?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),i&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ls,{schema:G(),onSubmit:D,onCancel:B,loading:v,storageKey:h(),title:n("prompt.runPromptWithName",{name:O})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(He,{result:w,onClose:X})})]}),!S&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:n("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((E,L)=>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:E.name}),E.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),E.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:E.description})]}),E.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:E.title})]},L))})]}),!S&&w&&e.jsx("div",{children:e.jsx(He,{result:w,onClose:X})})]})]})},Zs=({resource:s,readOnly:r=!1,onToggle:t,onDescriptionUpdate:a,cost:x})=>{const{t:g}=se(),[n,N]=u.useState(!1),[C,i]=u.useState(!1),[o,S]=u.useState(!1),[T,v]=u.useState(s.description||""),I=u.useRef(null),w=u.useRef(null),[P,y]=u.useState(0);u.useEffect(()=>{C&&I.current&&(I.current.focus(),P>0&&(I.current.style.width=`${P+20}px`))},[C,P]),u.useEffect(()=>{!C&&w.current&&y(w.current.offsetWidth)},[C,T]),u.useEffect(()=>{v(s.description||"")},[s.description]);const A=s.name||s.uri,J=F=>{!r&&t&&t(s.uri,F)},U=async()=>{r||(i(!1),a&&await a(s.uri,T))},_=async()=>{if(!r){S(!0);try{await(a==null?void 0:a(s.uri,"",{restored:!0})),i(!1)}finally{S(!1)}}},V=F=>{F.key==="Enter"?U():F.key==="Escape"&&(v(s.description||""),i(!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:()=>N(!n),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:A}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:C?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:I,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:P>0?`${P+20}px`:160,minWidth:80},value:T,onChange:F=>v(F.target.value),onKeyDown:V,onClick:F=>F.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:F=>{F.stopPropagation(),U()},disabled:o,children:e.jsx(me,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:F=>{F.stopPropagation(),_()},disabled:o,loading:o})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:w,children:T||g("tool.noDescription")}),!r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:F=>{F.stopPropagation(),i(!0)},children:e.jsx(De,{size:12})}),e.jsx(de,{title:g("builtinResources.restoreDefault"),onClick:F=>{F.stopPropagation(),_()},disabled:o,loading:o})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[x!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:g("cost.estimate"),children:["Σ ",ne(x)]}),e.jsx("div",{className:"flex h-[26px] items-center",onClick:F=>F.stopPropagation(),children:e.jsx(Ne,{checked:s.enabled!==!1,onCheckedChange:J,disabled:r,size:"card","aria-label":`${g(s.enabled!==!1?"server.disable":"server.enable")} ${A}`})}),e.jsx("button",{className:"hub-icon-btn sm",children:n?e.jsx(ze,{size:14}):e.jsx(ke,{size:14})})]})]}),n&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[g("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Qs=(s,r)=>r?r.isAdmin?!0:!!(s.owner&&s.owner===r.username):!1,et={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Te=s=>s==="public"||s==="group"?s:"private",st=(s,r)=>{const t=Te(r),a=et[t];return{value:t,shortLabel:s(a.shortKey,{defaultValue:a.shortFallback}),longLabel:s(a.longKey,{defaultValue:a.longFallback}),className:a.className}},tt=(s,r)=>{const t=Te(r),a=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&a.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),a.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),a},Ke=({isLoading:s,children:r,className:t,overlayStyle:a,spinnerSize:x=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:r}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...a},children:e.jsx(je,{size:x,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),Ge=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),Xe=(s,r)=>r?r==="stdio"?s("server.typeStdio")||"stdio":r==="sse"?s("server.typeSse")||"sse":r==="streamable-http"?s("server.typeStreamableHttp")||"http":r==="openapi"?s("server.typeOpenapi")||"openapi":r:null,rt="text/html;profile=mcp-app",Ye=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,at=s=>{var r,t;return!!((r=s.tools)!=null&&r.some(a=>Ye(a._meta))||(t=s.resources)!=null&&t.some(a=>{var x;return((x=a.uri)==null?void 0:x.startsWith("ui://"))||a.mimeType===rt||Ye(a._meta)}))},nt=({server:s,cost:r,onRemove:t,onEdit:a,onToggle:x,onVisibilityChange:g,onRefresh:n,onReload:N,onReinstall:C})=>{var Re,_e,Oe,Ae,Me,Ve,Je,Ue,Be,Le,We,qe;const{t:i}=se(),{showToast:o}=Ee(),{exportMCPSettings:S,installConfig:T}=Pe(),{auth:v}=js(),I=((Re=T==null?void 0:T.baseUrl)==null?void 0:Re.replace(/\/+$/,""))||"",[w,P]=u.useState(!1),[y,A]=u.useState(null),[J,U]=u.useState(!1),[_,V]=u.useState(!1),[F,q]=u.useState(!1),[H,Y]=u.useState(!1),[h,m]=u.useState(!1),[j,c]=u.useState(!1),[p,d]=u.useState(!1),[f,R]=u.useState(!1),[D,B]=u.useState(!1),X=u.useRef(null),O=u.useRef(null);u.useEffect(()=>{const l=b=>{X.current&&!X.current.contains(b.target)&&d(!1),O.current&&!O.current.contains(b.target)&&R(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[]);const G=((_e=s.tools)==null?void 0:_e.length)||0,E=((Oe=s.tools)==null?void 0:Oe.filter(l=>l.enabled!==!1).length)||0,L=((Ae=s.prompts)==null?void 0:Ae.length)||0,te=((Me=s.prompts)==null?void 0:Me.filter(l=>l.enabled!==!1).length)||0,le=((Ve=s.resources)==null?void 0:Ve.length)||0,z=((Je=s.resources)==null?void 0:Je.filter(l=>l.enabled!==!1).length)||0,W=at(s),Q=s.enabled!==!1,$=Qs(s,v.user),Z=((Ue=s.config)==null?void 0:Ue.command)==="npx"||((Be=s.config)==null?void 0:Be.command)==="uvx",ee=async l=>{if(!(!$||F||!x)){q(!0);try{await x(s,l)}finally{q(!1)}}},pe=async l=>{if(l.stopPropagation(),d(!1),!(!$||h||!N)){m(!0);try{await N(s)?o(i("server.reloadSuccess")||"Server reloaded successfully","success"):o(i("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{m(!1)}}},xe=async()=>{if(d(!1),!(!$||j||!C)){c(!0);try{await C(s)?o(i("server.reinstallSuccess")||"Server reinstall initiated","success"):o(i("server.reinstallError",{serverName:s.name})||"Failed to reinstall","error")}finally{c(!1)}}},he=async l=>{var k;if(l.stopPropagation(),!$||H||!g)return;const b=l.target.value;if(b!==Te(s.visibility??((k=s.config)==null?void 0:k.visibility))){Y(!0);try{await g(s,b)}finally{Y(!1)}}},K=async l=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(l),!0}catch{}try{const b=document.createElement("textarea");b.value=l,b.style.position="fixed",b.style.left="-9999px",document.body.appendChild(b),b.focus(),b.select();const k=document.execCommand("copy");return document.body.removeChild(b),k}catch{return!1}},re=async l=>{if(l.stopPropagation(),!s.error)return;await K(s.error)?(B(!0),o(i("common.copySuccess")||"Copied","success"),setTimeout(()=>B(!1),1500)):o(i("common.copyFailed")||"Copy failed","error")},be=async l=>{if(l.stopPropagation(),d(!1),!!$)try{const b=await S(s.name);if(!b||!b.success||!b.data){o((b==null?void 0:b.message)||i("common.copyFailed")||"Copy failed","error");return}const k=JSON.stringify(b.data,null,2),M=await K(k);o(M?i("common.copySuccess")||"Copied":i("common.copyFailed")||"Copy failed",M?"success":"error")}catch(b){console.error("Error copying server configuration:",b),o(i("common.copyFailed")||"Copy failed","error")}},fe=l=>{var b;if(l.stopPropagation(),(b=s.oauth)!=null&&b.authorizationUrl){const ae=window.screen.width/2-300,ie=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${ae},top=${ie}`),o(i("status.oauthWindowOpened"),"info")}},Ce=async(l,b)=>{try{const{toggleTool:k}=await ge(async()=>{const{toggleTool:ae}=await Promise.resolve().then(()=>Ls);return{toggleTool:ae}},void 0,import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ue=async(l,b)=>{try{const{togglePrompt:k}=await ge(async()=>{const{togglePrompt:ae}=await Promise.resolve().then(()=>Xs);return{togglePrompt:ae}},void 0,import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ms=async(l,b)=>{try{const{toggleResource:k}=await ge(async()=>{const{toggleResource:ae}=await import("./resourceService-Cu9CYEjx.js");return{toggleResource:ae}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),M=await k(s.name,l,b);M.success?(o(i(b?"tool.enableSuccess":"tool.disableSuccess",{name:l}),"success"),n==null||n()):o(M.error||i("tool.toggleFailed"),"error")}catch(k){console.error(k),o(i("tool.toggleFailed"),"error")}},ps=(l,b,k)=>{o(k!=null&&k.restored?i("tool.restoreDefaultSuccess"):i("tool.descriptionUpdateSuccess"),"success"),n==null||n()},xs=(l,b,k)=>{o(k!=null&&k.restored?i("prompt.restoreDefaultSuccess"):i("prompt.descriptionUpdateSuccess"),"success"),n==null||n()},hs=async(l,b,k)=>{try{const{updateResourceDescription:M,resetResourceDescription:ae}=await ge(async()=>{const{updateResourceDescription:fs,resetResourceDescription:gs}=await import("./resourceService-Cu9CYEjx.js");return{updateResourceDescription:fs,resetResourceDescription:gs}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),ie=k!=null&&k.restored?await ae(s.name,l):await M(s.name,l,b);ie.success?(o(k!=null&&k.restored?i("builtinResources.restoreDefaultSuccess"):i("builtinResources.descriptionUpdateSuccess"),"success"),n==null||n()):o(ie.error||(k!=null&&k.restored?i("builtinResources.restoreDefaultFailed"):i("builtinResources.descriptionUpdateFailed")),"error")}catch(M){console.error(M),o(k!=null&&k.restored?i("builtinResources.restoreDefaultFailed"):i("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var k;const l=s.config;if(!l)return"";if(l.url)return l.url;const b=[];return l.command&&b.push(l.command),(k=l.args)!=null&&k.length&&b.push(...l.args),b.join(" ")})();const $e=`${I}/mcp/${s.name}`,Fe=(l,b)=>i(l,b),ce=st(Fe,s.visibility??((Le=s.config)==null?void 0:Le.visibility)),bs=tt(Fe,ce.value),Ie=[{key:"tools",icon:Ps,total:G,enabled:E,label:i("server.tools")},{key:"prompts",icon:Ds,total:L,enabled:te,label:i("server.prompts")},{key:"resources",icon:zs,total:le,enabled:z,label:i("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>P(!w),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(ke,{size:12,style:{color:"var(--hub-ink-3)",transform:w?"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:Q?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),W&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:i("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:O,children:[e.jsx("button",{onClick:l=>{l.stopPropagation(),R(b=>!b)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":i("server.viewErrorDetails"),children:e.jsx(we,{size:14})}),f&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:i("server.errorDetails")}),e.jsx("button",{onClick:re,className:"hub-icon-btn sm",title:i("common.copy"),children:D?e.jsx(me,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>R(!1),className:"hub-icon-btn sm","aria-label":i("app.closeButton"),children:e.jsx(Se,{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})})]})]})]}),((We=s.config)==null?void 0:We.description)&&e.jsx("div",{className:"text-[11.5px] truncate",style:{color:"var(--hub-ink-3)",marginTop:1},title:s.config.description,children:s.config.description})]})]}),e.jsx("div",{className:"hub-server-card-status-cell min-w-0",children:e.jsx(Ss,{status:s.status,enabled:s.enabled,onAuthClick:fe,className:"hub-server-card-status"})}),e.jsx("div",{className:"hub-server-card-transport-cell min-w-0",children:(qe=s.config)!=null&&qe.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Xe(i,s.config.type)??void 0,children:Xe(i,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:l=>l.stopPropagation(),children:$&&g?e.jsx(Ke,{isLoading:H,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:ce.value,onChange:he,disabled:H,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":i("server.visibility","Visibility"),title:ce.longLabel,children:bs.map(l=>e.jsx("option",{value:l.value,disabled:l.disabled,children:l.label},l.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${ce.className}`,title:ce.longLabel,children:ce.shortLabel})}),Ie.map(({key:l,icon:b,total:k,enabled:M,label:ae})=>{const ie=k===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${ie?"is-empty":""}`,title:`${ae}: ${M}/${k}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(Ge,{icon:b})}),e.jsx("span",{className:"hub-server-capability-value",children:ie?"0":`${M}/${k}`})]},l)}),r&&r.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${i("cost.exposed")} ${r.exposed} / ${i("cost.gross")} ${r.gross} · ${i("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ne(r.exposed),"/",ne(r.gross)]})]}):r?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:i("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",onClick:l=>l.stopPropagation(),children:e.jsx(Ke,{isLoading:F,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx(Ne,{checked:Q,onCheckedChange:ee,disabled:F||!$,size:"compact","aria-label":`${i(Q?"server.disable":"server.enable")} ${s.name}`})})}),e.jsxs("div",{className:"relative",ref:X,children:[$&&e.jsx("button",{className:"hub-icon-btn",onClick:l=>{l.stopPropagation(),d(b=>!b)},"aria-label":"More",children:e.jsx(Ts,{size:14})}),$&&p&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:l=>l.stopPropagation(),children:[e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),a(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx($s,{size:13})," ",i("server.edit")]}),e.jsxs("button",{onClick:be,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",i("server.copy")]}),N&&e.jsxs("button",{onClick:pe,disabled:h||F||!Q,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(je,{size:13})," ",i("server.reload")]}),C&&Z&&e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),!(!$||j||!Q)&&V(!0)},disabled:j||F||!Q,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(Fs,{size:13})," ",i("server.reinstall")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:l=>{l.stopPropagation(),d(!1),U(!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(Is,{size:13})," ",i("server.delete")]})]})]})]}),w&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[Ie.map(l=>{const b=y===l.key,k=l.icon;return e.jsxs("button",{onClick:()=>A(b?null:l.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:b?"var(--hub-surface)":"transparent",border:"1px solid "+(b?"var(--hub-line)":"transparent"),color:b?"var(--hub-ink)":"var(--hub-ink-2)"},children:[e.jsx(Ge,{icon:k}),e.jsx("span",{children:l.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:l.total===0?"0":`${l.enabled}/${l.total}`})]},l.key)}),r&&r.connected&&e.jsxs("button",{onClick:()=>A(y==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:y==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(y==="cost"?"var(--hub-line)":"transparent"),color:y==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:i("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:i("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ne(r.exposed),"/",ne(r.gross)]})]}),e.jsx("div",{className:"ml-auto max-w-full flex-shrink-0",children:e.jsxs("div",{className:"hub-endpoint",style:{height:26},children:[e.jsx("div",{className:"hub-endpoint-label",children:"/mcp/"}),e.jsx("div",{className:"hub-endpoint-url",title:$e,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async l=>{l.stopPropagation();const b=await K($e);o(b?i("common.copySuccess")||"Copied":i("common.copyFailed")||"Failed",b?"success":"error")},title:i("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),y==="cost"&&(r==null?void 0:r.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...r.items].sort((l,b)=>b.cost-l.cost).map(l=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:l.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:l.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ne(l.cost)})]},`${l.kind}:${l.name}`))}),y==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((l,b)=>{var k;return e.jsx(Hs,{server:s.name,tool:l,readOnly:!$,onToggle:Ce,onDescriptionUpdate:ps,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="tool"&&M.name===l.name))==null?void 0:k.cost},b)})}),y==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((l,b)=>{var k;return e.jsx(Ys,{server:s.name,prompt:l,readOnly:!$,onToggle:ue,onDescriptionUpdate:xs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="prompt"&&M.name===l.name))==null?void 0:k.cost},b)})}),y==="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:i("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((l,b)=>{var k;return e.jsx(Zs,{resource:l,readOnly:!$,onToggle:ms,onDescriptionUpdate:hs,cost:(k=r==null?void 0:r.items.find(M=>M.kind==="resource"&&M.name===l.uri))==null?void 0:k.cost},`${l.uri}-${b}`)})})})]})]}),e.jsx(Vs,{isOpen:J,onClose:()=>U(!1),onConfirm:()=>{t(s.name),U(!1)},serverName:s.name}),e.jsx(rs,{isOpen:_,onClose:()=>V(!1),onConfirm:()=>{V(!1),xe()},title:i("server.reinstall"),message:i("server.reinstallConfirm")||"This will clear the package cache and re-download dependencies. The server will restart.",confirmText:i("server.reinstall"),variant:"warning"})]})},ot=({onAdd:s})=>{const{t:r}=se(),[t,a]=u.useState(!1),[x,g]=u.useState(null),[n,N]=u.useState(!1),[C,i]=u.useState(null),[o,S]=u.useState([]),T=()=>{a(!t),g(null),N(!1),i(null)},v=async()=>{C&&(await I(C),N(!1),i(null))},I=async P=>{try{g(null);const y=await oe("/servers",P);if(!y.success){y&&y.message?g(y.message):g(r("server.addError"));return}a(!1),s()}catch(y){console.error("Error adding server:",y),navigator.onLine?y instanceof TypeError&&(y.message.includes("NetworkError")||y.message.includes("Failed to fetch"))?g(r("errors.serverConnection")):g(r("errors.serverAdd")):g(r("errors.network"))}},w=async P=>{try{const y=Js(P);y.length>0?(S(y),i(P),N(!0)):await I(P)}catch(y){console.error("Error processing server submission:",y),g(r("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:T,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),r("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(as,{onSubmit:w,onCancel:T,modalTitle:r("server.addServer"),formError:x})}),n&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:r("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:r("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[r("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:o.map((P,y)=>e.jsxs("li",{className:"font-mono",children:["$",`{${P}}`]},y))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:r("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{N(!1),i(null)},className:"hub-btn",children:r("common.cancel")}),e.jsx("button",{onClick:v,className:"hub-btn primary",children:r("server.confirmAndAdd")})]})]})})]})},it=({server:s,onEdit:r,onCancel:t})=>{const{t:a}=se(),[x,g]=u.useState(null),n=async N=>{try{g(null);const C=encodeURIComponent(s.name),i=N.name&&N.name!==s.name,o={config:N.config,...i?{newName:N.name}:{}},S=await ve(`/servers/${C}`,o);if(!S.success){S&&S.message?g(S.message):g(a("server.updateError",{serverName:s.name}));return}r()}catch(C){console.error("Error updating server:",C),navigator.onLine?C instanceof TypeError&&(C.message.includes("NetworkError")||C.message.includes("Failed to fetch"))?g(a("errors.serverConnection")):g(a("errors.serverUpdate",{serverName:s.name})):g(a("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(as,{onSubmit:n,onCancel:t,initialData:s,modalTitle:a("server.editTitle",{serverName:s.name}),formError:x})})},lt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[a,x]=u.useState(!1),[g,n]=u.useState(!1),[N,C]=u.useState(null),[i,o]=u.useState(null),[S,T]=u.useState(!1),[v,I]=u.useState(null),[w,P]=u.useState(""),[y,A]=u.useState(!1),[J,U]=u.useState(""),_=c=>{c.preventDefault(),x(!0)},V=c=>{c.preventDefault(),x(!1)},F=c=>{c.preventDefault(),x(!1);const p=c.dataTransfer.files;if(p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),C(null)):C(t("mcpb.invalidFileType"))}},q=c=>{const p=c.target.files;if(p&&p.length>0){const d=p[0];d.name.endsWith(".mcpb")?(o(d),C(null)):C(t("mcpb.invalidFileType"))}},H=async()=>{if(!i){C(t("mcpb.noFileSelected"));return}n(!0),C(null);try{const c=new FormData;c.append("mcpbFile",i);const p=await Ns(ws("/mcpb/upload"),{method:"POST",body:c}),d=await p.json();if(!p.ok)throw new Error(d.message||`HTTP error! Status: ${p.status}`);if(d.success&&d.data)I(d.data.manifest),P(d.data.extractDir),T(!0);else throw new Error(d.message||t("mcpb.uploadFailed"))}catch(c){console.error("MCPB upload error:",c),C(c instanceof Error?c.message:t("mcpb.uploadFailed"))}finally{n(!1)}},Y=async(c,p=!1)=>{var d;n(!0),C(null);try{const f=j(v,w,c);if(!p){const D=await vs("/servers");if(D.success&&((d=D.data)==null?void 0:d.find(X=>X.name===c))){U(c),A(!0),n(!1);return}}let R;if(p?R=await ve(`/servers/${encodeURIComponent(c)}`,{name:c,config:f}):R=await oe("/servers",{name:c,config:f}),R.success)s(f);else throw new Error(R.message||t("mcpb.installFailed"))}catch(f){console.error("MCPB install error:",f),C(f instanceof Error?f.message:t("mcpb.installFailed")),n(!1)}},h=()=>{A(!1),J&&Y(J,!0)},m=()=>{A(!1),U(""),n(!1)},j=(c,p,d)=>{var D;const f=((D=c.server)==null?void 0:D.mcp_config)||{},R={type:"stdio",command:f.command||"node",args:(f.args||[]).map(B=>B.replace("${__dirname}",p))};return f.env&&Object.keys(f.env).length>0&&(R.env={...f.env},Object.keys(R.env).forEach(B=>{typeof R.env[B]=="string"&&(R.env[B]=R.env[B].replace("${__dirname}",p))})),R};return S&&v?e.jsxs(e.Fragment,{children:[e.jsx(rs,{isOpen:y,onClose:m,onConfirm:h,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:J}),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 ${y?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),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((c,p)=>e.jsxs("li",{children:[c.name," - ",c.description]},p))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:v.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const c=document.getElementById("serverName"),p=(c==null?void 0:c.value.trim())||v.name;Y(p)},disabled:g,className:"hub-btn primary",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),N&&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:N})}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${a?"border-blue-500 bg-blue-50":i?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:_,onDragLeave:V,onDrop:F,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:q,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,disabled:g,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:H,disabled:!i||g,className:"hub-btn primary flex items-center",children:g?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")})]})]})})},ct=s=>Object.entries(s.mcpServers).map(([r,t])=>{const a={};return t.type==="sse"||t.type==="streamable-http"?(a.type=t.type,a.url=t.url,t.headers&&(a.headers=t.headers)):t.type==="openapi"?(a.type="openapi",a.openapi=t.openapi):(a.type="stdio",a.command=t.command,a.args=t.args||[],t.env&&(a.env=t.env),t.options&&(a.options=t.options)),{name:r,config:a}}),dt=({onSuccess:s,onCancel:r})=>{const{t}=se(),[a,x]=u.useState(""),[g,n]=u.useState(null),[N,C]=u.useState(!1),[i,o]=u.useState(null),S=`{
|
|
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.`,T=w=>{try{const P=JSON.parse(w.trim());return!P.mcpServers||typeof P.mcpServers!="object"?(n(t("jsonImport.invalidFormat")),null):P}catch{return n(t("jsonImport.parseError")),null}},v=()=>{n(null);const w=T(a);w&&o(ct(w))},I=async()=>{if(i){C(!0),n(null);try{const w=await oe("/servers/batch",{servers:i});if(w.success&&w.data){const{successCount:P,failureCount:y,results:A}=w.data;if(y>0){const J=A.filter(U=>!U.success).map(U=>`${U.name}: ${U.message||t("jsonImport.addFailed")}`);n(t("jsonImport.partialSuccess",{count:P,total:i.length})+`
|
|
35
35
|
`+J.join(`
|
|
36
36
|
`))}P>0&&s()}else n(w.message||t("jsonImport.importFailed"))}catch(w){console.error("Import error:",w),n(t("jsonImport.importFailed"))}finally{C(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),g&&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:g})}),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((w,P)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:w.name}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm text-gray-600",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.type"),":"]})," ",w.config.type||"stdio"]}),w.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",w.config.command]}),w.config.args&&w.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",w.config.args.join(" ")]}),w.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",w.config.url]}),w.config.env&&Object.keys(w.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(w.config.env).join(", ")]}),w.config.headers&&Object.keys(w.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(w.config.headers).join(", ")]})]})]})})},P))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>o(null),disabled:N,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:I,disabled:N,className:"hub-btn primary",children:N?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("jsonImport.importing")]}):t("jsonImport.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("jsonImport.inputLabel")}),e.jsx("textarea",{value:a,onChange:w=>x(w.target.value),className:"w-full h-96 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-sm",placeholder:S}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("jsonImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:r,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:v,disabled:!a.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},ut=s=>({all:s.length,online:s.filter(r=>r.status==="connected").length,issues:s.filter(r=>r.status!=="connected"&&r.enabled!==!1).length,disabled:s.filter(r=>r.enabled===!1).length}),mt=(s,r,t="")=>{const a=t.trim().toLowerCase();return s.filter(x=>{var n,N;return r==="online"&&x.status!=="connected"||r==="issues"&&(x.status==="connected"||x.enabled===!1)||r==="disabled"&&x.enabled!==!1?!1:a?(x.name+" "+(((n=x.config)==null?void 0:n.description)||"")+" "+(((N=x.tools)==null?void 0:N.map(C=>C.name).join(" "))||"")).toLowerCase().includes(a):!0})},pt=(s,r,t,a,x)=>{const g=mt(s,r,t),n=g.length,N=Math.max(1,Math.ceil(n/x)),C=Math.min(Math.max(1,a),N),i=(C-1)*x;return{servers:g.slice(i,i+x),pagination:{page:C,limit:x,total:n,totalPages:N,hasNextPage:C<N,hasPrevPage:C>1}}},Et=()=>{const{t:s}=se(),r=ys(),{servers:t,allServers:a,error:x,setError:g,isLoading:n,currentPage:N,serversPerPage:C,setCurrentPage:i,setServersPerPage:o,handleServerAdd:S,handleServerEdit:T,handleServerRemove:v,handleServerToggle:I,handleServerVisibilityChange:w,handleServerReload:P,handleServerReinstall:y,triggerRefresh:A}=ks({refreshOnMount:!0}),{serverCosts:J,refetch:U}=Cs();u.useEffect(()=>{U()},[t,U]);const[_,V]=u.useState(null),[F,q]=u.useState(!1),[H,Y]=u.useState(!1),[h,m]=u.useState(!1),[j,c]=u.useState("all"),[p,d]=u.useState(""),f=u.useMemo(()=>ut(a),[a]),{servers:R,pagination:D}=u.useMemo(()=>pt(a,j,p,N,C),[a,j,p,N,C]);u.useEffect(()=>{D.page!==N&&i(D.page)},[D.page,N,i]);const B=async O=>{const G=await T(O);G&&V(G)},X=async()=>{q(!0);try{A(),await new Promise(O=>setTimeout(O,400))}finally{q(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("pages.servers.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:f.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:f.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:f.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>r("/market"),children:[e.jsx(Rs,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>m(!0),children:[e.jsx(_s,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>Y(!0),children:[e.jsx(Os,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:X,disabled:F,"aria-label":s("common.refresh"),children:[e.jsx(je,{size:13,className:F?"animate-spin":""}),s("common.refresh")]}),e.jsx(ot,{onAdd:S})]})]}),x&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(we,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:x})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>g(null),"aria-label":s("app.closeButton"),children:e.jsx(Se,{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",f.all],["online",s("status.online"),f.online],["issues",s("common.inactive")||"Issues",f.issues],["disabled",s("pages.dashboard.disabledServers")||"Disabled",f.disabled]].map(([O,G,E])=>e.jsxs("button",{onClick:()=>c(O),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:j===O?"var(--hub-bg-2)":"transparent",color:j===O?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(j===O?"var(--hub-line)":"transparent")},children:[G,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:E})]},O))}),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(As,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:p,onChange:O=>d(O.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),p&&e.jsx("button",{onClick:()=>d(""),className:"hub-icon-btn sm",children:e.jsx(Se,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[D.total,"/",a.length]})]}),n&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(je,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):R.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:R.map(O=>e.jsx(nt,{server:O,cost:J.find(G=>G.name===O.name),onRemove:v,onEdit:B,onToggle:I,onVisibilityChange:w,onRefresh:A,onReload:P,onReinstall:y},O.name))}),e.jsxs("div",{className:"flex items-center mt-4 text-[12px]",style:{color:"var(--hub-ink-3)"},children:[e.jsx("div",{className:"flex-[2]",children:s("common.showing",{start:(D.page-1)*D.limit+1,end:Math.min(D.page*D.limit,D.total),total:D.total})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:D.totalPages>1&&e.jsx(Us,{currentPage:D.page,totalPages:D.totalPages,onPageChange:i,disabled:n})}),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:C,onChange:O=>o(Number(O.target.value)),disabled:n,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"})]})]})]})]}),_&&e.jsx(it,{server:_,onEdit:()=>{V(null),A()},onCancel:()=>V(null)}),H&&e.jsx(lt,{onSuccess:()=>{Y(!1),A()},onCancel:()=>Y(!1)}),h&&e.jsx(dt,{onSuccess:()=>{m(!1),A()},onCancel:()=>m(!1)})]})};export{Et as default};
|
|
37
|
-
//# sourceMappingURL=ServersPage-
|
|
37
|
+
//# sourceMappingURL=ServersPage-hag0KLrj.js.map
|