@samanhappy/mcphub 1.0.9 → 1.0.11
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.md +2 -0
- package/dist/cli/commands/tools.js +4 -0
- package/dist/cli/commands/tools.js.map +1 -1
- package/dist/controllers/contextCostController.js +24 -0
- package/dist/controllers/contextCostController.js.map +1 -0
- package/dist/controllers/discoveryController.js +203 -0
- package/dist/controllers/discoveryController.js.map +1 -0
- package/dist/controllers/oauthCallbackController.js +3 -8
- package/dist/controllers/oauthCallbackController.js.map +1 -1
- package/dist/dao/SystemConfigDaoDbImpl.js +3 -0
- package/dist/dao/SystemConfigDaoDbImpl.js.map +1 -1
- package/dist/db/entities/SystemConfig.js +4 -0
- package/dist/db/entities/SystemConfig.js.map +1 -1
- package/dist/db/repositories/SystemConfigRepository.js +1 -0
- package/dist/db/repositories/SystemConfigRepository.js.map +1 -1
- package/dist/routes/index.js +16 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/services/contextCostService.js +101 -0
- package/dist/services/contextCostService.js.map +1 -0
- package/dist/services/groupService.js +1 -1
- package/dist/services/groupService.js.map +1 -1
- package/dist/services/hostedRuntimeCatalogService.js +2 -1
- package/dist/services/hostedRuntimeCatalogService.js.map +1 -1
- package/dist/services/mcpService.js +243 -98
- package/dist/services/mcpService.js.map +1 -1
- package/dist/services/openApiGeneratorService.js +5 -4
- package/dist/services/openApiGeneratorService.js.map +1 -1
- package/dist/services/smartRoutingService.js +53 -30
- package/dist/services/smartRoutingService.js.map +1 -1
- package/dist/services/vectorSearchService.js +3 -1
- package/dist/services/vectorSearchService.js.map +1 -1
- package/dist/utils/mcpApps.js +43 -0
- package/dist/utils/mcpApps.js.map +1 -0
- package/dist/utils/migration.js +1 -0
- package/dist/utils/migration.js.map +1 -1
- package/dist/utils/serialization.js +17 -1
- package/dist/utils/serialization.js.map +1 -1
- package/dist/utils/tokenCost.js +71 -0
- package/dist/utils/tokenCost.js.map +1 -0
- package/frontend/dist/assets/{ActivityPage-DrwHdeQ1.js → ActivityPage-DY-oWiYy.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-DrwHdeQ1.js.map → ActivityPage-DY-oWiYy.js.map} +1 -1
- package/frontend/dist/assets/{ConfirmDialog-CxlizGia.js → ConfirmDialog-Cag_haxr.js} +2 -2
- package/frontend/dist/assets/{ConfirmDialog-CxlizGia.js.map → ConfirmDialog-Cag_haxr.js.map} +1 -1
- package/frontend/dist/assets/Dashboard-DraIR5Hs.js +2 -0
- package/frontend/dist/assets/Dashboard-DraIR5Hs.js.map +1 -0
- package/frontend/dist/assets/{DeleteDialog-DRbWonMu.js → DeleteDialog-BBfJpiiD.js} +2 -2
- package/frontend/dist/assets/{DeleteDialog-DRbWonMu.js.map → DeleteDialog-BBfJpiiD.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-Doi0lGZI.js → EndpointCopy-Bkkaa0MC.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-Doi0lGZI.js.map → EndpointCopy-Bkkaa0MC.js.map} +1 -1
- package/frontend/dist/assets/GroupsPage-CTFtynaX.js +33 -0
- package/frontend/dist/assets/GroupsPage-CTFtynaX.js.map +1 -0
- package/frontend/dist/assets/{LoginPage-C3p_yHJd.js → LoginPage-BeZ9wg33.js} +2 -2
- package/frontend/dist/assets/{LoginPage-C3p_yHJd.js.map → LoginPage-BeZ9wg33.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-Z8Iueeij.js → LogsPage-D5LqNWlN.js} +2 -2
- package/frontend/dist/assets/LogsPage-D5LqNWlN.js.map +1 -0
- package/frontend/dist/assets/{MarketPage-BvEPL_eq.js → MarketPage-DmtOnQVN.js} +2 -2
- package/frontend/dist/assets/{MarketPage-BvEPL_eq.js.map → MarketPage-DmtOnQVN.js.map} +1 -1
- package/frontend/dist/assets/{Pagination-BFi-X7qY.js → Pagination-DBAu79mv.js} +2 -2
- package/frontend/dist/assets/{Pagination-BFi-X7qY.js.map → Pagination-DBAu79mv.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-BYoNsubQ.js → PromptsPage-blyfeDf6.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-BYoNsubQ.js.map → PromptsPage-blyfeDf6.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-BipHAbTQ.js → ResourcesPage-3gvaBRAN.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-BipHAbTQ.js.map → ResourcesPage-3gvaBRAN.js.map} +1 -1
- package/frontend/dist/assets/ServersPage-WhPsI-wN.js +37 -0
- package/frontend/dist/assets/ServersPage-WhPsI-wN.js.map +1 -0
- package/frontend/dist/assets/SettingsPage-Dg2-dPPZ.js +12 -0
- package/frontend/dist/assets/SettingsPage-Dg2-dPPZ.js.map +1 -0
- package/frontend/dist/assets/{StatusDot-C-kTn-AA.js → StatusDot-D3_AIDzm.js} +2 -2
- package/frontend/dist/assets/{StatusDot-C-kTn-AA.js.map → StatusDot-D3_AIDzm.js.map} +1 -1
- package/frontend/dist/assets/{ToggleGroup-B4fP-TVG.js → ToggleGroup-DU1_5iss.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-B4fP-TVG.js.map → ToggleGroup-DU1_5iss.js.map} +1 -1
- package/frontend/dist/assets/{UsersPage-MDtzW9-F.js → UsersPage-Cwi4XfTK.js} +2 -2
- package/frontend/dist/assets/{UsersPage-MDtzW9-F.js.map → UsersPage-Cwi4XfTK.js.map} +1 -1
- package/frontend/dist/assets/contextCost-qVdQkBuO.js +2 -0
- package/frontend/dist/assets/contextCost-qVdQkBuO.js.map +1 -0
- package/frontend/dist/assets/{framework-vendor-BUhDPOUZ.js → framework-vendor-DeqnZ0v6.js} +5 -5
- package/frontend/dist/assets/{framework-vendor-BUhDPOUZ.js.map → framework-vendor-DeqnZ0v6.js.map} +1 -1
- package/frontend/dist/assets/i18n-vendor-DP1IRITP.js +10 -0
- package/frontend/dist/assets/i18n-vendor-DP1IRITP.js.map +1 -0
- package/frontend/dist/assets/{icons-vendor-CKgJB3SC.js → icons-vendor-IYX_ppgH.js} +2 -2
- package/frontend/dist/assets/{icons-vendor-CKgJB3SC.js.map → icons-vendor-IYX_ppgH.js.map} +1 -1
- package/frontend/dist/assets/index-B-q7kaxJ.js +3 -0
- package/frontend/dist/assets/{index-otG7s0Ro.js.map → index-B-q7kaxJ.js.map} +1 -1
- package/frontend/dist/assets/index-D8V2fxz_.css +1 -0
- package/frontend/dist/assets/{resourceService-b5_G4mIW.js → resourceService-DvnBlx1V.js} +2 -2
- package/frontend/dist/assets/{resourceService-b5_G4mIW.js.map → resourceService-DvnBlx1V.js.map} +1 -1
- package/frontend/dist/assets/useSettingsData-Dc1fQY2w.js +2 -0
- package/frontend/dist/assets/{useSettingsData-BE6ZnRFg.js.map → useSettingsData-Dc1fQY2w.js.map} +1 -1
- package/frontend/dist/assets/{variableDetection-GTKqOf1F.js → variableDetection-Dnh8qFpO.js} +2 -2
- package/frontend/dist/assets/{variableDetection-GTKqOf1F.js.map → variableDetection-Dnh8qFpO.js.map} +1 -1
- package/frontend/dist/index.html +5 -5
- package/package.json +7 -7
- package/frontend/dist/assets/Dashboard-C6l7But8.js +0 -2
- package/frontend/dist/assets/Dashboard-C6l7But8.js.map +0 -1
- package/frontend/dist/assets/GroupsPage-Bx3Yi-md.js +0 -33
- package/frontend/dist/assets/GroupsPage-Bx3Yi-md.js.map +0 -1
- package/frontend/dist/assets/LogsPage-Z8Iueeij.js.map +0 -1
- package/frontend/dist/assets/ServersPage-Da24Dkfs.js +0 -37
- package/frontend/dist/assets/ServersPage-Da24Dkfs.js.map +0 -1
- package/frontend/dist/assets/SettingsPage-BiTd0EBn.js +0 -12
- package/frontend/dist/assets/SettingsPage-BiTd0EBn.js.map +0 -1
- package/frontend/dist/assets/i18n-vendor-Kbr87Ofu.js +0 -2
- package/frontend/dist/assets/i18n-vendor-Kbr87Ofu.js.map +0 -1
- package/frontend/dist/assets/index-aFFPxLwH.css +0 -1
- package/frontend/dist/assets/index-otG7s0Ro.js +0 -3
- package/frontend/dist/assets/useServerData-B_sSO_jj.js +0 -2
- package/frontend/dist/assets/useServerData-B_sSO_jj.js.map +0 -1
- package/frontend/dist/assets/useSettingsData-BE6ZnRFg.js +0 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./resourceService-DvnBlx1V.js","./index-B-q7kaxJ.js","./framework-vendor-DeqnZ0v6.js","./i18n-vendor-DP1IRITP.js","./icons-vendor-IYX_ppgH.js","./index-D8V2fxz_.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as d,j as e,d as cs}from"./framework-vendor-DeqnZ0v6.js";import{e as oe,f as He,h as ve,i as Ce,u as ds,_ as fe,j as us,k as ms,l as ps}from"./index-B-q7kaxJ.js";import{f as ae,u as xs,a as hs}from"./contextCost-qVdQkBuO.js";import{S as bs}from"./StatusDot-D3_AIDzm.js";import{u as Se}from"./useSettingsData-Dc1fQY2w.js";import{S as Ee}from"./ToggleGroup-DU1_5iss.js";import{u as se}from"./i18n-vendor-DP1IRITP.js";import{l as Ke,m as Ge,j as Ne,n as gs,C as ue,o as ye,p as Pe,q as Xe,r as Ye,s as ze,k as we,W as fs,f as ys,F as js,X as ke,E as vs,t as Ns,R as je,T as ws,P as ks,u as Cs,v as Ss,w as Es}from"./icons-vendor-IYX_ppgH.js";import{D as Ps}from"./DeleteDialog-BBfJpiiD.js";import{S as Ze,d as zs}from"./variableDetection-Dnh8qFpO.js";import{C as Ts}from"./ConfirmDialog-Cag_haxr.js";import{P as Ds}from"./Pagination-DBAu79mv.js";const Qe=async(s,n)=>{try{const t=n?`/tools/${encodeURIComponent(n)}/${encodeURIComponent(s.toolName)}`:"/tools/call",r=await oe(t,s.arguments,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return r.success===!1?{success:!1,error:r.message||"Tool call failed"}:{success:!0,content:(r==null?void 0:r.content)||[]}}catch(t){return console.error("Error calling tool",{toolName:s.toolName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Fs=async(s,n,t)=>{try{const r=await oe(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/toggle`,{enabled:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling tool",{serverName:s,toolName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},es=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ss=async(s,n)=>{var t;try{const r=await He(`/servers/${encodeURIComponent(s)}/tools/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting tool description",{serverName:s,toolName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Is=Object.freeze(Object.defineProperty({__proto__:null,callTool:Qe,resetToolDescription:ss,toggleTool:Fs,updateToolDescription:es},Symbol.toStringTag,{value:"Module"})),ts=({schema:s,onSubmit:n,onCancel:t,loading:r=!1,storageKey:y,title:v})=>{const{t:a}=se(),[N,o]=d.useState({}),[g,u]=d.useState({}),[S,D]=d.useState(!1),[j,F]=d.useState(""),[w,k]=d.useState(""),E=d.useMemo(()=>(m=>{const f=l=>{if(typeof l=="object"&&l!==null){const p=l;return{type:p.type||"string",description:p.description,enum:p.enum,default:p.default,properties:p.properties?Object.fromEntries(Object.entries(p.properties).map(([c,h])=>[c,f(h)])):void 0,required:p.required,items:p.items?f(p.items):void 0}}return{type:"string"}};return{type:m.type,properties:m.properties?Object.fromEntries(Object.entries(m.properties).map(([l,p])=>[l,f(p)])):void 0,required:m.required}})(s),[s]);d.useEffect(()=>{const x=(f,l="")=>{const p={};return f.type==="object"&&f.properties&&Object.entries(f.properties).forEach(([c,h])=>{const _=l?`${l}.${c}`:c;h.default!==void 0?p[c]=h.default:h.type==="string"?p[c]="":h.type==="number"||h.type==="integer"?p[c]=0:h.type==="boolean"?p[c]=!1:h.type==="array"?p[c]=[]:h.type==="object"&&(h.properties?p[c]=x(h,_):p[c]={})}),p};let m=x(E);if(y)try{const f=localStorage.getItem(y);if(f){const l=JSON.parse(f);m={...m,...l}}}catch(f){console.warn("Failed to load saved form data:",f)}o(m)},[E,y]),d.useEffect(()=>{S&&Object.keys(N).length>0&&(F(JSON.stringify(N,null,2)),k(""))},[S,N]);const A=x=>{F(x),k("");try{const m=JSON.parse(x);if(o(m),y)try{localStorage.setItem(y,JSON.stringify(m))}catch(f){console.warn("Failed to save form data to localStorage:",f)}}catch{k(a("tool.invalidJsonFormat"))}},O=()=>{F(JSON.stringify(N,null,2)),k(""),D(!0)},J=()=>{if(j.trim())try{const x=JSON.parse(j);o(x),k(""),D(!1)}catch{k(a("tool.fixJsonBeforeSwitching"));return}else D(!1)},R=(x,m)=>{o(f=>{const l={...f},p=x.split(".");let c=l;for(let h=0;h<p.length-1;h++)c[p[h]]||(c[p[h]]={}),c=c[p[h]];if(c[p[p.length-1]]=m,y)try{localStorage.setItem(y,JSON.stringify(l))}catch(h){console.warn("Failed to save form data to localStorage:",h)}return l}),g[x]&&u(f=>{const l={...f};return delete l[x],l})},T=()=>{const x={},m=(f,l,p="")=>{f.type==="object"&&f.properties&&Object.entries(f.properties).forEach(([c,h])=>{var H;const _=p?`${p}.${c}`:c,$=l==null?void 0:l[c];if((H=f.required)!=null&&H.includes(c)&&($==null||$===""||Array.isArray($)&&$.length===0)){x[_]=`${c} is required`;return}$!=null&&$!==""&&(h.type==="string"&&typeof $!="string"?x[_]=`${c} must be a string`:h.type==="number"&&typeof $!="number"?x[_]=`${c} must be a number`:h.type==="integer"&&(!Number.isInteger($)||typeof $!="number")?x[_]=`${c} must be an integer`:h.type==="boolean"&&typeof $!="boolean"?x[_]=`${c} must be a boolean`:h.type==="array"&&Array.isArray($)?h.items&&$.forEach((I,B)=>{var P;((P=h.items)==null?void 0:P.type)==="object"&&h.items.properties&&m(h.items,I,`${_}.${B}`)}):h.type==="object"&&typeof $=="object"&&m(h,$,_))})};return m(E,N),u(x),Object.keys(x).length===0},K=x=>{x.preventDefault(),T()&&n(N)},L=(x,m)=>m.split(".").reduce((f,l)=>f==null?void 0:f[l],x),q=(x,m,f,l)=>{const p=f==null?void 0:f[x];return m.type==="string"?m.enum?e.jsxs("select",{value:p||"",onChange:c=>l(c.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.enum.map((c,h)=>e.jsx("option",{value:c,children:c},h))]}):e.jsx("input",{type:"text",value:p||"",onChange:c=>l(c.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||a("tool.enterKey",{key:x})}):m.type==="number"||m.type==="integer"?e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:c=>{const h=c.target.value===""?"":m.type==="integer"?parseInt(c.target.value):parseFloat(c.target.value);l(h)},className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input"}):m.type==="boolean"?e.jsx("input",{type:"checkbox",checked:p||!1,onChange:c=>l(c.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}):e.jsx("input",{type:"text",value:p||"",onChange:c=>l(c.target.value),className:"w-full border rounded-md px-2 py-1 text-sm border-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500 form-input",placeholder:m.description||a("tool.enterKey",{key:x})})},Y=(x,m,f="")=>{var h,_,$,H,I,B,P,U,z,W,ie,ne,me,pe;const l=f?`${f}.${x}`:x,p=L(N,l),c=g[l];if(m.type==="array"){const M=L(N,l)||[];return e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?(_=(h=L(E,f))==null?void 0:h.required)==null?void 0:_.includes(x):($=E.required)==null?void 0:$.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-3 bg-gray-50 dark:bg-gray-800",children:[M.map((X,ee)=>{var xe,he,be;return e.jsxs("div",{className:"mb-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a("tool.item",{index:ee+1})}),e.jsx("button",{type:"button",onClick:()=>{const G=[...M];G.splice(ee,1),R(l,G)},className:"text-status-red hover:text-red-700 text-sm",children:a("common.remove")})]}),((xe=m.items)==null?void 0:xe.type)==="string"&&m.items.enum?e.jsxs("select",{value:X||"",onChange:G=>{const Z=[...M];Z[ee]=G.target.value,R(l,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.items.enum.map((G,Z)=>e.jsx("option",{value:G,children:G},Z))]}):((he=m.items)==null?void 0:he.type)==="object"&&m.items.properties?e.jsx("div",{className:"space-y-3",children:Object.entries(m.items.properties).map(([G,Z])=>{var Q,de;return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:[G,((de=(Q=m.items)==null?void 0:Q.required)==null?void 0:de.includes(G))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),q(G,Z,X,ge=>{const re=[...M];re[ee]={...re[ee],[G]:ge},R(l,re)})]},G)})}):e.jsx("input",{type:"text",value:X||"",onChange:G=>{const Z=[...M];Z[ee]=G.target.value,R(l,Z)},className:"w-full border rounded-md px-3 py-2 border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:a("tool.enterValue",{type:((be=m.items)==null?void 0:be.type)||"value"})})]},ee)}),e.jsx("button",{type:"button",onClick:()=>{var ee;const X=((ee=m.items)==null?void 0:ee.type)==="object"?{}:"";R(l,[...M,X])},className:"w-full mt-2 px-3 py-2 text-sm text-blue-600 border border-blue-300 rounded-md hover:bg-blue-50",children:a("tool.addItem",{key:x})})]}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l)}return m.type==="object"?m.properties?e.jsxs("div",{className:"mb-6",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?(I=(H=L(E,f))==null?void 0:H.required)==null?void 0:I.includes(x):(B=E.required)==null?void 0:B.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:Object.entries(m.properties).map(([M,X])=>Y(M,X,l))}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?(U=(P=L(E,f))==null?void 0:P.required)==null?void 0:U.includes(x):(z=E.required)==null?void 0:z.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsx("span",{className:"text-xs text-gray-500 ml-1",children:"(JSON object)"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("textarea",{value:typeof p=="object"?JSON.stringify(p,null,2):p||"{}",onChange:M=>{try{const X=JSON.parse(M.target.value);R(l,X)}catch{R(l,M.target.value)}},placeholder:`{
|
|
3
|
+
"key": "value"
|
|
4
|
+
}`,className:`w-full border rounded-md px-3 py-2 font-mono text-sm ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,rows:4}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="string"?m.enum?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?!1:(W=E.required)==null?void 0:W.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsxs("select",{value:p||"",onChange:M=>R(l,M.target.value),className:`w-full border rounded-md px-3 py-2 ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[e.jsx("option",{value:"",children:a("tool.selectOption")}),m.enum.map((M,X)=>e.jsx("option",{value:M,children:M},X))]}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?!1:(ie=E.required)==null?void 0:ie.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"text",value:p||"",onChange:M=>R(l,M.target.value),className:`w-full border rounded-md px-3 py-2 ${c?"border-red":"border-gray-200"} focus:outline-none form-input`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="number"||m.type==="integer"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?!1:(ne=E.required)==null?void 0:ne.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:m.description}),e.jsx("input",{type:"number",step:m.type==="integer"?"1":"any",value:p??"",onChange:M=>{const X=M.target.value===""?"":m.type==="integer"?parseInt(M.target.value):parseFloat(M.target.value);R(l,X)},className:`w-full border rounded-md px-3 py-2 form-input ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):m.type==="boolean"?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:p||!1,onChange:M=>R(l,M.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsxs("label",{className:"ml-2 block text-sm text-gray-700",children:[x,(f?!1:(me=E.required)==null?void 0:me.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})]}),m.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:m.description}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l):e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[x,(f?!1:(pe=E.required)==null?void 0:pe.includes(x))&&e.jsx("span",{className:"text-status-red ml-1",children:"*"}),e.jsxs("span",{className:"text-xs text-gray-500 ml-1",children:["(",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:M=>R(l,M.target.value),placeholder:a("tool.enterValue",{type:m.type}),className:`w-full border rounded-md px-3 py-2 ${c?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500 form-input`}),c&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:c})]},l)};return E.properties?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-3",children:[e.jsx("h6",{className:"text-md font-medium text-gray-900",children:v}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{type:"button",onClick:J,className:`hub-btn sm ${S?"":"primary"}`,children:a("tool.formMode")}),e.jsx("button",{type:"button",onClick:O,className:`hub-btn sm ${S?"primary":""}`,children:a("tool.jsonMode")})]})]}),S?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("tool.jsonConfiguration")}),e.jsx("textarea",{value:j,onChange:x=>A(x.target.value),placeholder:`{
|
|
5
|
+
"key": "value"
|
|
6
|
+
}`,className:`w-full h-64 border rounded-md px-3 py-2 font-mono text-sm resize-y form-input ${w?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-blue-500`}),w&&e.jsx("p",{className:"text-status-red text-xs mt-1",children:w})]}),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>{try{const x=JSON.parse(j);n(x)}catch{k(a("tool.invalidJsonFormat"))}},disabled:r||!!w,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]}):e.jsxs("form",{onSubmit:K,className:"space-y-4",children:[Object.entries(E.properties||{}).map(([x,m])=>Y(x,m)),e.jsxs("div",{className:"flex justify-end space-x-2 pt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn sm",children:a("tool.cancel")}),e.jsx("button",{type:"submit",disabled:r,className:"hub-btn sm primary",children:a(r?"tool.running":"tool.runTool")})]})]})]}):e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a("tool.noParameters")}),e.jsxs("div",{className:"flex justify-end space-x-2 mt-4",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",children:a("tool.cancel")}),e.jsx("button",{onClick:()=>n({}),disabled:r,className:"hub-btn primary",children:a(r?"tool.running":"tool.runTool")})]})]})},$s=({result:s,onClose:n})=>{const{t}=se(),r=s.content,y=u=>u?u.startsWith("image/")?u:`image/${u}`:"image/png",v=u=>{if(!u)return[];if(Array.isArray(u))return u.flatMap(j=>v(j));if(typeof u!="object")return[];const S=[];u.type==="image"&&u.data&&S.push({data:String(u.data),mimeType:y(u.mimeType||u.mime_type)});const D=u.image_base64||u.imageBase64||u.image_data||u.imageData||u.base64;return D&&S.push({data:String(D),mimeType:y(u.image_mimeType||u.image_mime_type||u.mimeType||u.mime_type)}),u.image&&typeof u.image=="object"&&S.push(...v(u.image)),Array.isArray(u.images)&&S.push(...v(u.images)),Array.isArray(u.content)&&S.push(...v(u.content)),S},a=u=>{const S=[];try{const F=JSON.parse(u);if(S.push(...v(F)),S.length>0)return S}catch{}const D=/data:image\/(png|jpe?g|gif|webp);base64,([A-Za-z0-9+/=]+)/g;let j;for(;(j=D.exec(u))!==null;){const F=`image/${j[1]==="jpg"?"jpeg":j[1]}`;S.push({data:j[2],mimeType:F})}return S},N=u=>{try{const S=JSON.parse(u),D=j=>{if(Array.isArray(j))return j.map(D);if(j&&typeof j=="object"){const F={};for(const[w,k]of Object.entries(j))typeof k=="string"&&w.toLowerCase().includes("base64")?F[w]="[base64 omitted]":F[w]=D(k);return F}return j};return JSON.stringify(D(S),null,2)}catch{return u.replace(/data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+/g,"[image data omitted]")}},o=u=>Array.isArray(u)?u.map((S,D)=>e.jsx("div",{className:"mb-3 last:mb-0",children:g(S)},D)):g(u),g=u=>{if(typeof u=="string"){const S=a(u),D=N(u);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((j,F)=>e.jsx("img",{src:`data:${j.mimeType||"image/png"};base64,${j.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:D})]})}if(typeof u=="object"&&u!==null){if(u.type==="text"&&u.text){const S=a(u.text),D=N(u.text);return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[S.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:S.map((j,F)=>e.jsx("img",{src:`data:${j.mimeType||"image/png"};base64,${j.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"},F))}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:D})]})}if(u.type==="image"&&u.data)return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("img",{src:`data:${u.mimeType||"image/png"};base64,${u.data}`,alt:t("tool.toolResult"),className:"max-w-full h-auto rounded-md"})});try{const S=typeof u=="string"?JSON.parse(u):u;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("tool.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(S,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(u)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(u)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Ke,{size:20,className:"text-status-green"}):e.jsx(Ge,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("tool.execution")," ",s.success?t("tool.successful"):t("tool.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.content&&s.content.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.result")}),o(s.content)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("tool.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ne,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("tool.error")})]}),r&&r.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("tool.errorDetails")}),o(r)]}):e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("tool.unknownError")})})]})})]})},ce=({title:s,onClick:n,disabled:t=!1,loading:r=!1})=>e.jsx("button",{type:"button",className:"ml-2 p-1 text-amber-600 hover:text-amber-700 cursor-pointer transition-colors disabled:opacity-60 disabled:cursor-not-allowed",onClick:n,disabled:t,title:s,"aria-label":s,children:e.jsx(gs,{size:14,className:r?"animate-spin":""})});function Rs(s){return s==null?!0:typeof s=="string"?s.trim()==="":Array.isArray(s)?s.length===0:typeof s=="object"?Object.keys(s).length===0:!1}const _s=({tool:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:y,cost:v})=>{const{t:a}=se(),{showToast:N}=Ce(),{nameSeparator:o}=Se(),[g,u]=d.useState(!1),[S,D]=d.useState(!1),[j,F]=d.useState(!1),[w,k]=d.useState(null),[E,A]=d.useState(!1),[O,J]=d.useState(!1),[R,T]=d.useState(s.description||""),K=d.useRef(null),L=d.useRef(null),[q,Y]=d.useState(0),[x,m]=d.useState(!1);d.useEffect(()=>{E&&K.current&&(K.current.focus(),q>0&&(K.current.style.width=`${q+20}px`))},[E,q]),d.useEffect(()=>{!E&&L.current&&Y(L.current.offsetWidth)},[E,R]),d.useEffect(()=>{T(s.description||"")},[s.description]);const f=d.useCallback(()=>`mcphub_tool_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),l=d.useCallback(()=>{localStorage.removeItem(f())},[f]),p=z=>{!t&&r&&r(s.name,z)},c=()=>{t||A(!0)},h=async()=>{if(!t)try{const z=await es(n,s.name,R);z.success?(A(!1),y&&y(s.name,R)):(T(s.description||""),console.error("Failed to update tool description:",z.error))}catch(z){console.error("Error updating tool description:",z),T(s.description||""),A(!1)}},_=z=>{T(z.target.value)},$=async()=>{if(!t){J(!0);try{const z=await ss(n,s.name);if(z.success){const W=z.description||"";T(W),A(!1),y==null||y(s.name,W,{restored:!0})}else N(z.error||a("tool.restoreDefaultFailed"),"error")}catch(z){console.error("Error resetting tool description:",z),N(a("tool.restoreDefaultFailed"),"error")}finally{J(!1)}}},H=z=>{z.key==="Enter"?h():z.key==="Escape"&&(T(s.description||""),A(!1))},I=async z=>{z.stopPropagation();try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s.name),m(!0),N(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3);else{const W=document.createElement("textarea");W.value=s.name,W.style.position="fixed",W.style.left="-9999px",document.body.appendChild(W),W.focus(),W.select();try{document.execCommand("copy"),m(!0),N(a("common.copySuccess"),"success"),setTimeout(()=>m(!1),2e3)}catch(ie){N(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",ie)}document.body.removeChild(W)}}catch(W){N(a("common.copyFailed"),"error"),console.error("Copy to clipboard failed:",W)}},B=async z=>{F(!0);try{z=Object.fromEntries(Object.entries(z).filter(([ie,ne])=>!Rs(ne)));const W=await Qe({toolName:s.name,arguments:z},n);k(W)}catch(W){k({success:!1,error:W instanceof Error?W.message:"Unknown error occurred"})}finally{F(!1)}},P=()=>{D(!1),l(),k(null)},U=()=>{k(null)};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:z=>{z.stopPropagation(),u(!g)},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(n+o,"")}),e.jsx("button",{className:"hub-icon-btn sm",onClick:I,title:a("common.copy"),children:x?e.jsx(ue,{size:12,style:{color:"var(--hub-ok)"}}):e.jsx(ye,{size:12})}),e.jsx("span",{className:"flex items-center gap-1",style:{fontSize:12,color:"var(--hub-ink-3)"},children:E?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:K,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:R,onChange:_,onKeyDown:H,onClick:z=>z.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),h()},disabled:O,children:e.jsx(ue,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ce,{title:a("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),$()},disabled:O,loading:O})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:L,children:R||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:z=>{z.stopPropagation(),c()},children:e.jsx(Pe,{size:12})}),e.jsx(ce,{title:a("tool.restoreDefault"),onClick:z=>{z.stopPropagation(),$()},disabled:O,loading:O})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ae(v)]}),e.jsx("div",{onClick:z=>z.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled??!0,onCheckedChange:p,disabled:j||t})}),e.jsxs("button",{onClick:z=>{z.stopPropagation(),u(!0),D(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(Xe,{size:12,className:"animate-spin"}):e.jsx(Ye,{size:12}),e.jsx("span",{children:a(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:g?e.jsx(ze,{size:14}):e.jsx(we,{size:14})})]})]}),g&&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:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.inputSchema")}),e.jsx("pre",{className:"hub-mono overflow-auto",style:{fontSize:11.5,color:"var(--hub-ink-2)",margin:0},children:JSON.stringify(s.inputSchema,null,2)})]}),S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:s.inputSchema||{type:"object"},onSubmit:B,onCancel:P,loading:j,storageKey:f(),title:a("tool.runToolWithName",{name:s.name.replace(n+o,"")})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx($s,{result:w,onClose:U})})]})]})]})},As=async(s,n)=>{try{const t=n?`/prompts/call/${n}`:"/prompts/call",r=await oe(t,{promptName:s.promptName,arguments:s.arguments});return r.success?{success:!0,data:r.data}:{success:!1,error:r.message||"Prompt call failed"}}catch(t){return console.error("Error calling prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},rs=async(s,n)=>{try{const t=await oe(`/mcp/${encodeURIComponent(n||"")}/prompts/${encodeURIComponent(s.promptName)}`,{name:s.promptName,arguments:s.arguments});if(!t.success)throw new Error(`Failed to get prompt: ${t.message||"Unknown error"}`);return{success:!0,data:t.data}}catch(t){return console.error("Error getting prompt",{promptName:s.promptName,server:n,error:t}),{success:!1,error:t instanceof Error?t.message:"Unknown error occurred"}}},Os=async(s,n,t)=>{try{const r=await oe(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/toggle`,{enabled:t});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error toggling prompt",{serverName:s,promptName:n,enabled:t,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},ns=async(s,n,t)=>{try{const r=await ve(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{description:t},{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message}}catch(r){return console.error("Error updating prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},as=async(s,n)=>{var t;try{const r=await He(`/servers/${encodeURIComponent(s)}/prompts/${encodeURIComponent(n)}/description`,{headers:{Authorization:`Bearer ${localStorage.getItem("mcphub_token")}`}});return{success:r.success,error:r.success?void 0:r.message,description:(t=r.data)==null?void 0:t.description}}catch(r){return console.error("Error resetting prompt description",{serverName:s,promptName:n,error:r}),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}},Ms=Object.freeze(Object.defineProperty({__proto__:null,callPrompt:As,getPrompt:rs,resetPromptDescription:as,togglePrompt:Os,updatePromptDescription:ns},Symbol.toStringTag,{value:"Module"})),Ue=({result:s,onClose:n})=>{const{t}=se(),r=y=>{if(typeof y=="string")return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:y})});if(typeof y=="object"&&y!==null){if(y.description||y.messages)return e.jsxs("div",{className:"space-y-4",children:[y.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.description")}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("p",{className:"text-sm text-gray-800",children:y.description})})]}),y.messages&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 mb-2",children:t("prompt.messages")}),e.jsx("div",{className:"space-y-3",children:y.messages.map((v,a)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"flex items-center mb-2",children:e.jsxs("span",{className:"inline-block w-16 text-xs font-medium text-gray-500",children:[v.role,":"]})}),typeof v.content=="string"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:v.content}):typeof v.content=="object"&&v.content.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:v.content.text}):e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(v.content,null,2)})]},a))})]})]});try{const v=typeof y=="string"?JSON.parse(y):y;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-2",children:t("prompt.jsonResponse")}),e.jsx("pre",{className:"text-sm text-gray-800 overflow-auto",children:JSON.stringify(v,null,2)})]})}catch{return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(y)})})}}return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-md p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-800 font-mono",children:String(y)})})};return e.jsxs("div",{className:"border border-gray-300 rounded-lg bg-white dark:bg-gray-800 shadow-sm",children:[e.jsx("div",{className:"border-b border-gray-300 px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.success?e.jsx(Ke,{size:20,className:"text-status-green"}):e.jsx(Ge,{size:20,className:"text-status-red"}),e.jsx("div",{children:e.jsxs("h4",{className:"text-sm font-medium text-gray-900",children:[t("prompt.execution")," ",s.success?t("prompt.successful"):t("prompt.failed")]})})]}),e.jsx("button",{onClick:n,className:"text-gray-400 hover:text-gray-600 text-sm",children:"✕"})]})}),e.jsx("div",{className:"p-4",children:s.success?e.jsx("div",{children:s.data?e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:t("prompt.result")}),r(s.data)]}):e.jsx("div",{className:"text-sm text-gray-500 italic",children:t("prompt.noContent")})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(Ne,{size:16,className:"text-red-500"}),e.jsx("span",{className:"text-sm font-medium text-red-700",children:t("prompt.error")})]}),e.jsx("div",{className:"bg-red-50 border border-red-300 rounded-md p-3",children:e.jsx("pre",{className:"text-sm text-red-800 whitespace-pre-wrap",children:s.error||s.message||t("prompt.unknownError")})})]})})]})},Vs=({prompt:s,server:n,readOnly:t=!1,onToggle:r,onDescriptionUpdate:y,cost:v})=>{const{t:a}=se(),{showToast:N}=Ce(),{nameSeparator:o}=Se(),[g,u]=d.useState(!1),[S,D]=d.useState(!1),[j,F]=d.useState(!1),[w,k]=d.useState(null),[E,A]=d.useState(!1),[O,J]=d.useState(!1),[R,T]=d.useState(s.description||""),K=d.useRef(null),L=d.useRef(null),[q,Y]=d.useState(0);d.useEffect(()=>{E&&K.current&&(K.current.focus(),q>0&&(K.current.style.width=`${q+20}px`))},[E,q]),d.useEffect(()=>{!E&&L.current&&Y(L.current.offsetWidth)},[E,R]),d.useEffect(()=>{T(s.description||"")},[s.description]);const x=d.useCallback(()=>`mcphub_prompt_form_${n?`${n}_`:""}${s.name}`,[s.name,n]),m=d.useCallback(()=>{localStorage.removeItem(x())},[x]),f=P=>{!t&&r&&r(s.name,P)},l=()=>{t||A(!0)},p=async()=>{if(!t){A(!1);try{const P=await ns(n,s.name,R);P.success?y&&y(s.name,R):(N(P.error||a("prompt.descriptionUpdateFailed"),"error"),T(s.description||""))}catch(P){console.error("Error updating prompt description:",P),N(a("prompt.descriptionUpdateFailed"),"error"),T(s.description||"")}}},c=async()=>{if(!t){J(!0);try{const P=await as(n,s.name);if(P.success){const U=P.description||"";T(U),A(!1),y==null||y(s.name,U,{restored:!0})}else N(P.error||a("prompt.restoreDefaultFailed"),"error")}catch(P){console.error("Error resetting prompt description:",P),N(a("prompt.restoreDefaultFailed"),"error")}finally{J(!1)}}},h=P=>{T(P.target.value)},_=P=>{P.key==="Enter"?p():P.key==="Escape"&&(T(s.description||""),A(!1))},$=async P=>{F(!0);try{const U=await rs({promptName:s.name,arguments:P},n);console.log("GetPrompt result:",U),k({success:U.success,data:U.data,error:U.error})}catch(U){k({success:!1,error:U instanceof Error?U.message:"Unknown error occurred"})}finally{F(!1)}},H=()=>{D(!1),m(),k(null)},I=()=>{k(null)},B=()=>{if(!s.arguments||s.arguments.length===0)return{type:"object",properties:{},required:[]};const P={},U=[];return s.arguments.forEach(z=>{P[z.name]={type:"string",description:z.description||""},z.required&&U.push(z.name)}),{type:"object",properties:P,required:U}};return e.jsxs("div",{className:"hub-card overflow-hidden",style:{marginBottom:8},children:[e.jsxs("div",{className:"flex justify-between items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-[var(--hub-surface-hover)] transition-colors",onClick:()=>u(!g),children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name.replace(n+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:E?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:K,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:q>0?`${q+20}px`:160,minWidth:80},value:R,onChange:h,onKeyDown:_,onClick:P=>P.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),p()},disabled:O,children:e.jsx(ue,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ce,{title:a("prompt.restoreDefault"),onClick:P=>{P.stopPropagation(),c()},disabled:O,loading:O})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:L,children:R||a("tool.noDescription")}),!t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:P=>{P.stopPropagation(),l()},children:e.jsx(Pe,{size:12})}),e.jsx(ce,{title:a("prompt.restoreDefault"),onClick:P=>{P.stopPropagation(),c()},disabled:O,loading:O})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:a("cost.estimate"),children:["Σ ",ae(v)]}),e.jsx("div",{onClick:P=>P.stopPropagation(),children:s.enabled!==void 0&&e.jsx(Ee,{checked:s.enabled,onCheckedChange:f,disabled:j||t})}),e.jsxs("button",{onClick:P=>{P.stopPropagation(),u(!0),D(!0)},className:"hub-btn sm",style:{color:"var(--hub-accent)"},disabled:j||!s.enabled,children:[j?e.jsx(Xe,{size:12,className:"animate-spin"}):e.jsx(Ye,{size:12}),e.jsx("span",{children:a(j?"tool.running":"tool.run")})]}),e.jsx("button",{className:"hub-icon-btn sm",children:g?e.jsx(ze,{size:14}):e.jsx(we,{size:14})})]})]}),g&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"10px 12px",display:"flex",flexDirection:"column",gap:10},children:[S&&e.jsxs("div",{style:{border:"1px solid var(--hub-line)",borderRadius:8,padding:14},children:[e.jsx(ts,{schema:B(),onSubmit:$,onCancel:H,loading:j,storageKey:x(),title:a("prompt.runPromptWithName",{name:s.name.replace(n+o,"")})}),w&&e.jsx("div",{style:{marginTop:12},children:e.jsx(Ue,{result:w,onClose:I})})]}),!S&&s.arguments&&s.arguments.length>0&&e.jsxs("div",{style:{background:"var(--hub-bg-2)",borderRadius:7,padding:"8px 12px",border:"1px solid var(--hub-line)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:6},children:a("tool.parameters")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.arguments.map((P,U)=>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:P.name}),P.required&&e.jsx("span",{style:{color:"var(--hub-err)",fontSize:12},children:"*"})]}),P.description&&e.jsx("p",{style:{fontSize:12,color:"var(--hub-ink-3)",margin:"2px 0 0"},children:P.description})]}),P.title&&e.jsx("span",{style:{fontSize:11,color:"var(--hub-ink-3)"},children:P.title})]},U))})]}),!S&&w&&e.jsx("div",{children:e.jsx(Ue,{result:w,onClose:I})})]})]})},Js=({resource:s,readOnly:n=!1,onToggle:t,onDescriptionUpdate:r,cost:y})=>{const{t:v}=se(),[a,N]=d.useState(!1),[o,g]=d.useState(!1),[u,S]=d.useState(!1),[D,j]=d.useState(s.description||""),F=d.useRef(null),w=d.useRef(null),[k,E]=d.useState(0);d.useEffect(()=>{o&&F.current&&(F.current.focus(),k>0&&(F.current.style.width=`${k+20}px`))},[o,k]),d.useEffect(()=>{!o&&w.current&&E(w.current.offsetWidth)},[o,D]),d.useEffect(()=>{j(s.description||"")},[s.description]);const A=T=>{!n&&t&&t(s.uri,T)},O=async()=>{n||(g(!1),r&&await r(s.uri,D))},J=async()=>{if(!n){S(!0);try{await(r==null?void 0:r(s.uri,"",{restored:!0})),g(!1)}finally{S(!1)}}},R=T=>{T.key==="Enter"?O():T.key==="Escape"&&(j(s.description||""),g(!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(!a),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"hub-mono font-medium truncate",style:{fontSize:13,color:"var(--hub-ink)"},children:s.name||s.uri}),e.jsx("span",{className:"hub-mono truncate",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:s.uri})]}),e.jsx("span",{className:"flex items-center gap-1 mt-0.5",style:{fontSize:12,color:"var(--hub-ink-3)"},children:o?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:F,type:"text",className:"hub-input",style:{height:26,fontSize:12,width:k>0?`${k+20}px`:160,minWidth:80},value:D,onChange:T=>j(T.target.value),onKeyDown:R,onClick:T=>T.stopPropagation()}),e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),O()},disabled:u,children:e.jsx(ue,{size:12,style:{color:"var(--hub-ok)"}})}),e.jsx(ce,{title:v("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),J()},disabled:u,loading:u})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:w,children:D||v("tool.noDescription")}),!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"hub-icon-btn sm",onClick:T=>{T.stopPropagation(),g(!0)},children:e.jsx(Pe,{size:12})}),e.jsx(ce,{title:v("builtinResources.restoreDefault"),onClick:T=>{T.stopPropagation(),J()},disabled:u,loading:u})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[y!=null&&e.jsxs("span",{className:"hub-mono flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},title:v("cost.estimate"),children:["Σ ",ae(y)]}),e.jsx("div",{onClick:T=>T.stopPropagation(),children:e.jsx(Ee,{checked:s.enabled!==!1,onCheckedChange:A,disabled:n})}),e.jsx("button",{className:"hub-icon-btn sm",children:a?e.jsx(ze,{size:14}):e.jsx(we,{size:14})})]})]}),a&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",padding:"8px 12px"},children:[e.jsxs("span",{className:"hub-sect",children:[v("builtinResources.mimeType"),":"]})," ",e.jsx("span",{style:{fontSize:12,color:"var(--hub-ink-2)"},children:s.mimeType||"text/plain"})]})]})},Us=(s,n)=>n?n.isAdmin?!0:!!(s.owner&&s.owner===n.username):!1,Bs={private:{shortKey:"server.visibilityPrivateShort",shortFallback:"Private",longKey:"server.visibilityPrivate",longFallback:"Private — only the owner and admins",className:"bg-[var(--hub-bg-2)] text-[var(--hub-ink-2)] border-[var(--hub-line-2)]"},group:{shortKey:"server.visibilityGroupShort",shortFallback:"Group",longKey:"server.visibilityGroup",longFallback:"Group (reserved — not yet implemented)",className:"bg-[oklch(0.97_0.02_85)] text-[oklch(0.45_0.07_85)] border-[oklch(0.88_0.04_85)]"},public:{shortKey:"server.visibilityPublicShort",shortFallback:"Public",longKey:"server.visibilityPublic",longFallback:"Public — every authenticated user",className:"bg-[oklch(0.97_0.03_145)] text-[oklch(0.42_0.12_145)] border-[oklch(0.88_0.04_145)]"}},Te=s=>s==="public"||s==="group"?s:"private",Ws=(s,n)=>{const t=Te(n),r=Bs[t];return{value:t,shortLabel:s(r.shortKey,{defaultValue:r.shortFallback}),longLabel:s(r.longKey,{defaultValue:r.longFallback}),className:r.className}},Ls=(s,n)=>{const t=Te(n),r=[{value:"private",label:s("server.visibilityPrivateShort",{defaultValue:"Private"}),disabled:!1}];return t==="group"&&r.push({value:"group",label:s("server.visibilityGroupShort",{defaultValue:"Group"}),disabled:!0}),r.push({value:"public",label:s("server.visibilityPublicShort",{defaultValue:"Public"}),disabled:!1}),r},Be=({isLoading:s,children:n,className:t,overlayStyle:r,spinnerSize:y=12})=>e.jsxs("div",{className:t?`relative flex items-center ${t}`:"relative flex items-center","aria-busy":s,children:[e.jsx("div",{className:"flex w-full items-center justify-center",style:{visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto"},children:n}),s&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",style:{background:"var(--hub-surface)",border:"1px solid var(--hub-line-2)",borderRadius:8,...r},children:e.jsx(je,{size:y,className:"animate-spin",style:{color:"var(--hub-ink-3)"}})})]}),We=({icon:s})=>e.jsx("span",{className:"hub-server-capability-icon","aria-hidden":"true",children:e.jsx(s,{size:11.5,strokeWidth:1.9,className:"block"})}),Le=(s,n)=>n?n==="stdio"?s("server.typeStdio")||"stdio":n==="sse"?s("server.typeSse")||"sse":n==="streamable-http"?s("server.typeStreamableHttp")||"http":n==="openapi"?s("server.typeOpenapi")||"openapi":n:null,qs="text/html;profile=mcp-app",qe=s=>s?!!(s.ui||s["ui/resourceUri"]):!1,Hs=s=>{var n,t;return!!((n=s.tools)!=null&&n.some(r=>qe(r._meta))||(t=s.resources)!=null&&t.some(r=>{var y;return((y=r.uri)==null?void 0:y.startsWith("ui://"))||r.mimeType===qs||qe(r._meta)}))},Ks=({server:s,cost:n,onRemove:t,onEdit:r,onToggle:y,onVisibilityChange:v,onRefresh:a,onReload:N})=>{var Fe,Ie,$e,Re,_e,Ae,Oe,Me,Ve,Je;const{t:o}=se(),{showToast:g}=Ce(),{exportMCPSettings:u,installConfig:S}=Se(),{auth:D}=ds(),j=((Fe=S==null?void 0:S.baseUrl)==null?void 0:Fe.replace(/\/+$/,""))||"",[F,w]=d.useState(!1),[k,E]=d.useState(null),[A,O]=d.useState(!1),[J,R]=d.useState(!1),[T,K]=d.useState(!1),[L,q]=d.useState(!1),[Y,x]=d.useState(!1),[m,f]=d.useState(!1),[l,p]=d.useState(!1),c=d.useRef(null),h=d.useRef(null);d.useEffect(()=>{const i=b=>{c.current&&!c.current.contains(b.target)&&x(!1),h.current&&!h.current.contains(b.target)&&f(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]);const _=((Ie=s.tools)==null?void 0:Ie.length)||0,$=(($e=s.tools)==null?void 0:$e.filter(i=>i.enabled!==!1).length)||0,H=((Re=s.prompts)==null?void 0:Re.length)||0,I=((_e=s.prompts)==null?void 0:_e.filter(i=>i.enabled!==!1).length)||0,B=((Ae=s.resources)==null?void 0:Ae.length)||0,P=((Oe=s.resources)==null?void 0:Oe.filter(i=>i.enabled!==!1).length)||0,U=Hs(s),z=async i=>{if(i.stopPropagation(),!(!Q||J||!y)){R(!0);try{await y(s,s.enabled===!1)}finally{R(!1)}}},W=async i=>{if(i.stopPropagation(),x(!1),!(!Q||L||!N)){q(!0);try{await N(s)?g(o("server.reloadSuccess")||"Server reloaded successfully","success"):g(o("server.reloadError",{serverName:s.name})||"Failed to reload","error")}finally{q(!1)}}},ie=async i=>{var C;if(i.stopPropagation(),!Q||T||!v)return;const b=i.target.value;if(b!==Te(s.visibility??((C=s.config)==null?void 0:C.visibility))){K(!0);try{await v(s,b)}finally{K(!1)}}},ne=async i=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(i),!0}catch{}try{const b=document.createElement("textarea");b.value=i,b.style.position="fixed",b.style.left="-9999px",document.body.appendChild(b),b.focus(),b.select();const C=document.execCommand("copy");return document.body.removeChild(b),C}catch{return!1}},me=async i=>{if(i.stopPropagation(),!s.error)return;await ne(s.error)?(p(!0),g(o("common.copySuccess")||"Copied","success"),setTimeout(()=>p(!1),1500)):g(o("common.copyFailed")||"Copy failed","error")},pe=async i=>{if(i.stopPropagation(),x(!1),!!Q)try{const b=await u(s.name);if(!b||!b.success||!b.data){g((b==null?void 0:b.message)||o("common.copyFailed")||"Copy failed","error");return}const C=JSON.stringify(b.data,null,2),V=await ne(C);g(V?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Copy failed",V?"success":"error")}catch(b){console.error("Error copying server configuration:",b),g(o("common.copyFailed")||"Copy failed","error")}},M=i=>{var b;if(i.stopPropagation(),(b=s.oauth)!=null&&b.authorizationUrl){const te=window.screen.width/2-300,le=window.screen.height/2-700/2;window.open(s.oauth.authorizationUrl,"OAuth Authorization",`width=600,height=700,left=${te},top=${le}`),g(o("status.oauthWindowOpened"),"info")}},X=async(i,b)=>{try{const{toggleTool:C}=await fe(async()=>{const{toggleTool:te}=await Promise.resolve().then(()=>Is);return{toggleTool:te}},void 0,import.meta.url),V=await C(s.name,i,b);V.success?(g(o(b?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):g(V.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),g(o("tool.toggleFailed"),"error")}},ee=async(i,b)=>{try{const{togglePrompt:C}=await fe(async()=>{const{togglePrompt:te}=await Promise.resolve().then(()=>Ms);return{togglePrompt:te}},void 0,import.meta.url),V=await C(s.name,i,b);V.success?(g(o(b?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):g(V.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),g(o("tool.toggleFailed"),"error")}},xe=async(i,b)=>{try{const{toggleResource:C}=await fe(async()=>{const{toggleResource:te}=await import("./resourceService-DvnBlx1V.js");return{toggleResource:te}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),V=await C(s.name,i,b);V.success?(g(o(b?"tool.enableSuccess":"tool.disableSuccess",{name:i}),"success"),a==null||a()):g(V.error||o("tool.toggleFailed"),"error")}catch(C){console.error(C),g(o("tool.toggleFailed"),"error")}},he=(i,b,C)=>{g(C!=null&&C.restored?o("tool.restoreDefaultSuccess"):o("tool.descriptionUpdateSuccess"),"success"),a==null||a()},be=(i,b,C)=>{g(C!=null&&C.restored?o("prompt.restoreDefaultSuccess"):o("prompt.descriptionUpdateSuccess"),"success"),a==null||a()},G=async(i,b,C)=>{try{const{updateResourceDescription:V,resetResourceDescription:te}=await fe(async()=>{const{updateResourceDescription:is,resetResourceDescription:ls}=await import("./resourceService-DvnBlx1V.js");return{updateResourceDescription:is,resetResourceDescription:ls}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),le=C!=null&&C.restored?await te(s.name,i):await V(s.name,i,b);le.success?(g(C!=null&&C.restored?o("builtinResources.restoreDefaultSuccess"):o("builtinResources.descriptionUpdateSuccess"),"success"),a==null||a()):g(le.error||(C!=null&&C.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed")),"error")}catch(V){console.error(V),g(C!=null&&C.restored?o("builtinResources.restoreDefaultFailed"):o("builtinResources.descriptionUpdateFailed"),"error")}};(()=>{var C;const i=s.config;if(!i)return"";if(i.url)return i.url;const b=[];return i.command&&b.push(i.command),(C=i.args)!=null&&C.length&&b.push(...i.args),b.join(" ")})();const Z=s.enabled!==!1,Q=Us(s,D.user),de=`${j}/mcp/${s.name}`,ge=(i,b)=>o(i,b),re=Ws(ge,s.visibility??((Me=s.config)==null?void 0:Me.visibility)),os=Ls(ge,re.value),De=[{key:"tools",icon:fs,total:_,enabled:$,label:o("server.tools")},{key:"prompts",icon:ys,total:H,enabled:I,label:o("server.prompts")},{key:"resources",icon:js,total:B,enabled:P,label:o("nav.resources")}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hub-card overflow-visible",style:{marginBottom:10,opacity:Z?1:.7},children:[e.jsxs("div",{className:"hub-server-card-row cursor-pointer px-4 py-3 transition-colors hover:bg-[var(--hub-surface-hover)]",onClick:()=>w(!F),children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(we,{size:12,style:{color:"var(--hub-ink-3)",transform:F?"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:Z?"var(--hub-ink)":"var(--hub-ink-3)"},children:s.name}),U&&e.jsx("span",{className:"hub-tag accent flex-shrink-0",title:o("server.mcpApp"),children:"App"}),s.error&&e.jsxs("div",{className:"relative",ref:h,children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),f(b=>!b)},className:"text-[var(--hub-err)] hover:opacity-80","aria-label":o("server.viewErrorDetails"),children:e.jsx(Ne,{size:14})}),m&&e.jsxs("div",{className:"absolute z-20 mt-1.5 hub-card",style:{left:0,top:"100%",width:460,maxHeight:320,overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.08)"},onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--hub-err)"},children:o("server.errorDetails")}),e.jsx("button",{onClick:me,className:"hub-icon-btn sm",title:o("common.copy"),children:l?e.jsx(ue,{size:12,className:"text-[var(--hub-ok)]"}):e.jsx(ye,{size:12})})]}),e.jsx("button",{onClick:()=>f(!1),className:"hub-icon-btn sm","aria-label":o("app.closeButton"),children:e.jsx(ke,{size:12})})]}),e.jsx("div",{className:"p-3 overflow-auto hub-mono",style:{maxHeight:260,fontSize:12},children:e.jsx("pre",{className:"whitespace-pre-wrap break-words m-0",style:{color:"var(--hub-ink-2)"},children:s.error})})]})]})]}),((Ve=s.config)==null?void 0:Ve.description)&&e.jsx("div",{className:"text-[11.5px] truncate",style:{color:"var(--hub-ink-3)",marginTop:1},title:s.config.description,children:s.config.description})]})]}),e.jsx("div",{className:"min-w-0",children:e.jsx(bs,{status:s.status,enabled:s.enabled,onAuthClick:M,className:"hub-server-card-status"})}),e.jsx("div",{className:"min-w-0",children:(Je=s.config)!=null&&Je.type?e.jsx("span",{className:"hub-tag hub-server-card-transport-tag",title:Le(o,s.config.type)??void 0,children:Le(o,s.config.type)}):e.jsx("span",{style:{color:"var(--hub-ink-3)",fontSize:12},children:"—"})}),e.jsx("div",{className:"hub-server-card-visibility min-w-0",onClick:i=>i.stopPropagation(),children:Q&&v?e.jsx(Be,{isLoading:T,className:"w-full",overlayStyle:{borderRadius:6},children:e.jsx("select",{value:re.value,onChange:ie,disabled:T,className:"hub-server-card-select w-full rounded-md border px-2 py-1 text-[11.5px] bg-[var(--hub-surface)] text-[var(--hub-ink)]",style:{borderColor:"var(--hub-line-2)"},"aria-label":o("server.visibility","Visibility"),title:re.longLabel,children:os.map(i=>e.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value))})}):e.jsx("span",{className:`hub-server-card-visibility-badge inline-flex items-center rounded-md border px-2 py-0.5 text-[11.5px] ${re.className}`,title:re.longLabel,children:re.shortLabel})}),De.map(({key:i,icon:b,total:C,enabled:V,label:te})=>{const le=C===0;return e.jsxs("span",{className:`hub-server-capability-stat hub-mono hub-num ${le?"is-empty":""}`,title:`${te}: ${V}/${C}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:e.jsx(We,{icon:b})}),e.jsx("span",{className:"hub-server-capability-value",children:le?"0":`${V}/${C}`})]},i)}),n&&n.connected?e.jsxs("span",{className:"hub-server-capability-stat hub-mono hub-num",title:`${o("cost.exposed")} ${n.exposed} / ${o("cost.gross")} ${n.gross} · ${o("cost.estimate")}`,children:[e.jsx("span",{className:"text-[var(--hub-ink-3)]",children:"Σ"}),e.jsxs("span",{className:"hub-server-capability-value",children:[ae(n.exposed),"/",ae(n.gross)]})]}):n?e.jsx("span",{className:"hub-server-capability-stat hub-mono is-empty",title:o("cost.notConnected"),children:e.jsx("span",{className:"hub-server-capability-value",children:"—"})}):null,e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Be,{isLoading:J,className:"h-[18px] w-[30px]",overlayStyle:{borderRadius:999,background:"var(--hub-bg-2)"},spinnerSize:10,children:e.jsx("button",{type:"button",className:"hub-switch"+(Z?" on":""),onClick:z,disabled:J||!Q,"aria-label":o(Z?"server.disable":"server.enable")})})}),e.jsxs("div",{className:"relative",ref:c,children:[Q&&e.jsx("button",{className:"hub-icon-btn",onClick:i=>{i.stopPropagation(),x(b=>!b)},"aria-label":"More",children:e.jsx(vs,{size:14})}),Q&&Y&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 hub-card",style:{minWidth:160,padding:4},onClick:i=>i.stopPropagation(),children:[e.jsxs("button",{onClick:i=>{i.stopPropagation(),x(!1),r(s)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(Ns,{size:13})," ",o("server.edit")]}),e.jsxs("button",{onClick:pe,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-ink)"},children:[e.jsx(ye,{size:13})," ",o("server.copy")]}),N&&e.jsxs("button",{onClick:W,disabled:L||J||!Z,className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left disabled:opacity-50 disabled:cursor-not-allowed",style:{color:"var(--hub-ink)"},children:[e.jsx(je,{size:13})," ",o("server.reload")]}),e.jsx("div",{style:{height:1,background:"var(--hub-line-2)",margin:"4px 0"}}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),x(!1),O(!0)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-[13px] rounded-md hover:bg-[var(--hub-surface-hover)] text-left",style:{color:"var(--hub-err)"},children:[e.jsx(ws,{size:13})," ",o("server.delete")]})]})]})]}),F&&e.jsxs("div",{style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",padding:"14px 16px 16px 38px"},children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:[De.map(i=>{const b=k===i.key,C=i.icon;return e.jsxs("button",{onClick:()=>E(b?null:i.key),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background: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(We,{icon:C}),e.jsx("span",{children:i.label}),e.jsx("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:i.total===0?"0":`${i.enabled}/${i.total}`})]},i.key)}),n&&n.connected&&e.jsxs("button",{onClick:()=>E(k==="cost"?null:"cost"),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] transition-colors hover:bg-[var(--hub-surface-hover)]",style:{background:k==="cost"?"var(--hub-surface)":"transparent",border:"1px solid "+(k==="cost"?"var(--hub-line)":"transparent"),color:k==="cost"?"var(--hub-ink)":"var(--hub-ink-2)"},title:o("cost.estimate"),children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"Σ"}),e.jsx("span",{children:o("cost.totalFootprint")}),e.jsxs("span",{className:"hub-mono hub-num",style:{color:"var(--hub-ink-3)",fontSize:11},children:[ae(n.exposed),"/",ae(n.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:de,style:{maxWidth:200},children:s.name}),e.jsx("button",{type:"button",className:"hub-endpoint-copy",onClick:async i=>{i.stopPropagation();const b=await ne(de);g(b?o("common.copySuccess")||"Copied":o("common.copyFailed")||"Failed",b?"success":"error")},title:o("common.copy"),children:e.jsx(ye,{size:12})})]})})]}),k==="cost"&&(n==null?void 0:n.connected)&&e.jsx("div",{className:"mt-2 space-y-1",children:[...n.items].sort((i,b)=>b.cost-i.cost).map(i=>e.jsxs("div",{className:"flex items-center justify-between hub-mono",style:{fontSize:11.5,color:i.enabled?"var(--hub-ink-2)":"var(--hub-ink-3)"},children:[e.jsx("span",{className:"truncate",children:i.name}),e.jsx("span",{className:"hub-num flex-shrink-0",children:ae(i.cost)})]},`${i.kind}:${i.name}`))}),k==="tools"&&s.tools&&e.jsx("div",{className:"space-y-3 mt-2",children:s.tools.map((i,b)=>{var C;return e.jsx(_s,{server:s.name,tool:i,readOnly:!Q,onToggle:X,onDescriptionUpdate:he,cost:(C=n==null?void 0:n.items.find(V=>V.kind==="tool"&&V.name===i.name))==null?void 0:C.cost},b)})}),k==="prompts"&&s.prompts&&e.jsx("div",{className:"space-y-3 mt-2",children:s.prompts.map((i,b)=>{var C;return e.jsx(Vs,{server:s.name,prompt:i,readOnly:!Q,onToggle:ee,onDescriptionUpdate:be,cost:(C=n==null?void 0:n.items.find(V=>V.kind==="prompt"&&V.name===i.name))==null?void 0:C.cost},b)})}),k==="resources"&&s.resources&&e.jsx("div",{className:"mt-2",children:s.resources.length===0?e.jsx("div",{className:"text-sm",style:{color:"var(--hub-ink-3)"},children:o("builtinResources.noResources")}):e.jsx("div",{className:"space-y-3",children:s.resources.map((i,b)=>{var C;return e.jsx(Js,{resource:i,readOnly:!Q,onToggle:xe,onDescriptionUpdate:G,cost:(C=n==null?void 0:n.items.find(V=>V.kind==="resource"&&V.name===i.uri))==null?void 0:C.cost},`${i.uri}-${b}`)})})})]})]}),e.jsx(Ps,{isOpen:A,onClose:()=>O(!1),onConfirm:()=>{t(s.name),O(!1)},serverName:s.name})]})},Gs=({onAdd:s})=>{const{t:n}=se(),[t,r]=d.useState(!1),[y,v]=d.useState(null),[a,N]=d.useState(!1),[o,g]=d.useState(null),[u,S]=d.useState([]),D=()=>{r(!t),v(null),N(!1),g(null)},j=async()=>{o&&(await F(o),N(!1),g(null))},F=async k=>{try{v(null);const E=await oe("/servers",k);if(!E.success){E&&E.message?v(E.message):v(n("server.addError"));return}r(!1),s()}catch(E){console.error("Error adding server:",E),navigator.onLine?E instanceof TypeError&&(E.message.includes("NetworkError")||E.message.includes("Failed to fetch"))?v(n("errors.serverConnection")):v(n("errors.serverAdd")):v(n("errors.network"))}},w=async k=>{try{const E=zs(k);E.length>0?(S(E),g(k),N(!0)):await F(k)}catch(E){console.error("Error processing server submission:",E),v(n("errors.serverAdd"))}};return e.jsxs("div",{children:[e.jsxs("button",{onClick:D,className:"hub-btn primary",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})}),n("server.add")]}),t&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ze,{onSubmit:w,onCancel:D,modalTitle:n("server.addServer"),formError:y})}),a&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center p-4",children:e.jsxs("div",{className:"hub-card p-6 w-full max-w-md",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:n("server.confirmVariables")}),e.jsx("p",{className:"text-gray-600 mb-4",children:n("server.variablesDetected")}),e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3 mb-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-yellow-800",children:[n("server.detectedVariables"),":"]}),e.jsx("ul",{className:"mt-1 text-sm text-yellow-700",children:u.map((k,E)=>e.jsxs("li",{className:"font-mono",children:["$",`{${k}}`]},E))})]})]})}),e.jsx("p",{className:"text-gray-600 text-sm mb-6",children:n("server.confirmVariablesMessage")}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{N(!1),g(null)},className:"hub-btn",children:n("common.cancel")}),e.jsx("button",{onClick:j,className:"hub-btn primary",children:n("server.confirmAndAdd")})]})]})})]})},Xs=({server:s,onEdit:n,onCancel:t})=>{const{t:r}=se(),[y,v]=d.useState(null),a=async N=>{try{v(null);const o=encodeURIComponent(s.name),g=N.name&&N.name!==s.name,u={config:N.config,...g?{newName:N.name}:{}},S=await ve(`/servers/${o}`,u);if(!S.success){S&&S.message?v(S.message):v(r("server.updateError",{serverName:s.name}));return}n()}catch(o){console.error("Error updating server:",o),navigator.onLine?o instanceof TypeError&&(o.message.includes("NetworkError")||o.message.includes("Failed to fetch"))?v(r("errors.serverConnection")):v(r("errors.serverUpdate",{serverName:s.name})):v(r("errors.network"))}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsx(Ze,{onSubmit:a,onCancel:t,initialData:s,modalTitle:r("server.editTitle",{serverName:s.name}),formError:y})})},Ys=({onSuccess:s,onCancel:n})=>{const{t}=se(),[r,y]=d.useState(!1),[v,a]=d.useState(!1),[N,o]=d.useState(null),[g,u]=d.useState(null),[S,D]=d.useState(!1),[j,F]=d.useState(null),[w,k]=d.useState(""),[E,A]=d.useState(!1),[O,J]=d.useState(""),R=l=>{l.preventDefault(),y(!0)},T=l=>{l.preventDefault(),y(!1)},K=l=>{l.preventDefault(),y(!1);const p=l.dataTransfer.files;if(p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},L=l=>{const p=l.target.files;if(p&&p.length>0){const c=p[0];c.name.endsWith(".mcpb")?(u(c),o(null)):o(t("mcpb.invalidFileType"))}},q=async()=>{if(!g){o(t("mcpb.noFileSelected"));return}a(!0),o(null);try{const l=new FormData;l.append("mcpbFile",g);const p=await ms(ps("/mcpb/upload"),{method:"POST",body:l}),c=await p.json();if(!p.ok)throw new Error(c.message||`HTTP error! Status: ${p.status}`);if(c.success&&c.data)F(c.data.manifest),k(c.data.extractDir),D(!0);else throw new Error(c.message||t("mcpb.uploadFailed"))}catch(l){console.error("MCPB upload error:",l),o(l instanceof Error?l.message:t("mcpb.uploadFailed"))}finally{a(!1)}},Y=async(l,p=!1)=>{var c;a(!0),o(null);try{const h=f(j,w,l);if(!p){const $=await us("/servers");if($.success&&((c=$.data)==null?void 0:c.find(I=>I.name===l))){J(l),A(!0),a(!1);return}}let _;if(p?_=await ve(`/servers/${encodeURIComponent(l)}`,{name:l,config:h}):_=await oe("/servers",{name:l,config:h}),_.success)s(h);else throw new Error(_.message||t("mcpb.installFailed"))}catch(h){console.error("MCPB install error:",h),o(h instanceof Error?h.message:t("mcpb.installFailed")),a(!1)}},x=()=>{A(!1),O&&Y(O,!0)},m=()=>{A(!1),J(""),a(!1)},f=(l,p,c)=>{var $;const h=(($=l.server)==null?void 0:$.mcp_config)||{},_={type:"stdio",command:h.command||"node",args:(h.args||[]).map(H=>H.replace("${__dirname}",p))};return h.env&&Object.keys(h.env).length>0&&(_.env={...h.env},Object.keys(_.env).forEach(H=>{typeof _.env[H]=="string"&&(_.env[H]=_.env[H].replace("${__dirname}",p))})),_};return S&&j?e.jsxs(e.Fragment,{children:[e.jsx(Ts,{isOpen:E,onClose:m,onConfirm:x,title:t("mcpb.serverExistsTitle"),message:t("mcpb.serverExistsConfirm",{serverName:O}),confirmText:t("mcpb.override"),cancelText:t("common.cancel"),variant:"warning"}),e.jsx("div",{className:`fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4 ${E?"opacity-50 pointer-events-none":""}`,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-3xl max-h-screen overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.installServer")}),e.jsx("button",{onClick:n,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"),":"]})," ",j.display_name||j.name]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.version"),":"]})," ",j.version]}),e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.description"),":"]})," ",j.description]}),j.author&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("mcpb.author"),":"]})," ",j.author.name]}),j.tools&&j.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:j.tools.map((l,p)=>e.jsxs("li",{children:[l.name," - ",l.description]},p))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("mcpb.serverName")}),e.jsx("input",{type:"text",id:"serverName",defaultValue:j.name,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 form-input",placeholder:t("mcpb.serverNamePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:v,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:()=>{const l=document.getElementById("serverName"),p=(l==null?void 0:l.value.trim())||j.name;Y(p)},disabled:v,className:"hub-btn primary",children:v?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.installing")]}):t("mcpb.install")})]})]})]})})]}):e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-lg",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("mcpb.uploadTitle")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),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 ${r?"border-blue-500 bg-blue-50":g?"border-gray-500 ":"border-gray-300 hover:border-gray-400"}`,onDragOver:R,onDragLeave:T,onDrop:K,children:[g?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:g.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(g.size/1024/1024).toFixed(2)," MB"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-900",children:t("mcpb.dropFileHere")}),e.jsx("p",{className:"text-xs text-gray-500",children:t("mcpb.orClickToSelect")})]})]}),e.jsx("input",{type:"file",accept:".mcpb",onChange:L,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsxs("div",{className:"mt-6 flex justify-end space-x-4",children:[e.jsx("button",{onClick:n,disabled:v,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:q,disabled:!g||v,className:"hub-btn primary flex items-center",children:v?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t("mcpb.uploading")]}):t("mcpb.upload")})]})]})})},Zs=s=>Object.entries(s.mcpServers).map(([n,t])=>{const r={};return t.type==="sse"||t.type==="streamable-http"?(r.type=t.type,r.url=t.url,t.headers&&(r.headers=t.headers)):t.type==="openapi"?(r.type="openapi",r.openapi=t.openapi):(r.type="stdio",r.command=t.command,r.args=t.args||[],t.env&&(r.env=t.env),t.options&&(r.options=t.options)),{name:n,config:r}}),Qs=({onSuccess:s,onCancel:n})=>{const{t}=se(),[r,y]=d.useState(""),[v,a]=d.useState(null),[N,o]=d.useState(!1),[g,u]=d.useState(null),S=`{
|
|
7
|
+
"mcpServers": {
|
|
8
|
+
"stdio-server-example": {
|
|
9
|
+
"command": "npx",
|
|
10
|
+
"args": ["-y", "mcp-server-example"]
|
|
11
|
+
},
|
|
12
|
+
"sse-server-example": {
|
|
13
|
+
"type": "sse",
|
|
14
|
+
"url": "http://localhost:3000"
|
|
15
|
+
},
|
|
16
|
+
"http-server-example": {
|
|
17
|
+
"type": "streamable-http",
|
|
18
|
+
"url": "http://localhost:3001",
|
|
19
|
+
"headers": {
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
"Authorization": "Bearer your-token"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"openapi-server-example": {
|
|
25
|
+
"type": "openapi",
|
|
26
|
+
"openapi": {
|
|
27
|
+
"url": "https://petstore.swagger.io/v2/swagger.json"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Supports: STDIO, SSE, HTTP (streamable-http), OpenAPI
|
|
34
|
+
All servers will be imported in a single efficient batch operation.`,D=w=>{try{const k=JSON.parse(w.trim());return!k.mcpServers||typeof k.mcpServers!="object"?(a(t("jsonImport.invalidFormat")),null):k}catch{return a(t("jsonImport.parseError")),null}},j=()=>{a(null);const w=D(r);w&&u(Zs(w))},F=async()=>{if(g){o(!0),a(null);try{const w=await oe("/servers/batch",{servers:g});if(w.success&&w.data){const{successCount:k,failureCount:E,results:A}=w.data;if(E>0){const O=A.filter(J=>!J.success).map(J=>`${J.name}: ${J.message||t("jsonImport.addFailed")}`);a(t("jsonImport.partialSuccess",{count:k,total:g.length})+`
|
|
35
|
+
`+O.join(`
|
|
36
|
+
`))}k>0&&s()}else a(w.message||t("jsonImport.importFailed"))}catch(w){console.error("Import error:",w),a(t("jsonImport.importFailed"))}finally{o(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("jsonImport.title")}),e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),v&&e.jsx("div",{className:"mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded",children:e.jsx("p",{className:"text-red-700 whitespace-pre-wrap",children:v})}),g?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:g.map((w,k)=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:w.name}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm text-gray-600",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.type"),":"]})," ",w.config.type||"stdio"]}),w.config.command&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.command"),":"]})," ",w.config.command]}),w.config.args&&w.config.args.length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.arguments"),":"]})," ",w.config.args.join(" ")]}),w.config.url&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.url"),":"]})," ",w.config.url]}),w.config.env&&Object.keys(w.config.env).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.envVars"),":"]})," ",Object.keys(w.config.env).join(", ")]}),w.config.headers&&Object.keys(w.config.headers).length>0&&e.jsxs("div",{children:[e.jsxs("strong",{children:[t("server.headers"),":"]})," ",Object.keys(w.config.headers).join(", ")]})]})]})})},k))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>u(null),disabled:N,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:F,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:r,onChange:w=>y(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:n,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:j,disabled:!r.trim(),className:"hub-btn primary",children:t("jsonImport.preview")})]})]})]})})},mt=()=>{const{t:s}=se(),n=cs(),{servers:t,allServers:r,error:y,setError:v,isLoading:a,pagination:N,currentPage:o,serversPerPage:g,setCurrentPage:u,setServersPerPage:S,handleServerAdd:D,handleServerEdit:j,handleServerRemove:F,handleServerToggle:w,handleServerVisibilityChange:k,handleServerReload:E,triggerRefresh:A}=xs({refreshOnMount:!0}),{serverCosts:O,refetch:J}=hs();d.useEffect(()=>{J()},[t,J]);const[R,T]=d.useState(null),[K,L]=d.useState(!1),[q,Y]=d.useState(!1),[x,m]=d.useState(!1),[f,l]=d.useState("all"),[p,c]=d.useState(""),h=d.useMemo(()=>({all:r.length,online:r.filter(I=>I.status==="connected").length,issues:r.filter(I=>I.status!=="connected"&&I.enabled!==!1).length}),[r]),_=d.useMemo(()=>{const I=p.trim().toLowerCase();return t.filter(B=>{var U,z;return f==="online"&&B.status!=="connected"||f==="issues"&&(B.status==="connected"||B.enabled===!1)?!1:I?(B.name+" "+(((U=B.config)==null?void 0:U.description)||"")+" "+(((z=B.tools)==null?void 0:z.map(W=>W.name).join(" "))||"")).toLowerCase().includes(I):!0})},[t,f,p]),$=async I=>{const B=await j(I);B&&T(B)},H=async()=>{L(!0);try{A(),await new Promise(I=>setTimeout(I,400))}finally{L(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"hub-h1",children:s("pages.servers.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:h.all})," ",s("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{className:"hub-num",children:h.online})," ",s("status.online")," ·"," ",e.jsx("span",{className:"hub-num",children:h.issues})," ",s("common.inactive")||"issues"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>n("/market"),children:[e.jsx(ks,{size:13})," ",s("nav.market")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>m(!0),children:[e.jsx(Cs,{size:13})," ",s("jsonImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>Y(!0),children:[e.jsx(Ss,{size:13})," ",s("mcpb.upload")]}),e.jsxs("button",{className:"hub-btn",onClick:H,disabled:K,"aria-label":s("common.refresh"),children:[e.jsx(je,{size:13,className:K?"animate-spin":""}),s("common.refresh")]}),e.jsx(Gs,{onAdd:D})]})]}),y&&e.jsxs("div",{className:"hub-card flex items-center justify-between gap-3 mb-4",style:{padding:"10px 14px",borderColor:"oklch(0.85 0.1 25)",background:"oklch(0.97 0.03 25)",color:"oklch(0.4 0.18 25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ne,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:y})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>v(null),"aria-label":s("app.closeButton"),children:e.jsx(ke,{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",h.all],["online",s("status.online"),h.online],["issues",s("common.inactive")||"Issues",h.issues]].map(([I,B,P])=>e.jsxs("button",{onClick:()=>l(I),className:"inline-flex items-center gap-1.5 px-3 text-[12px]",style:{height:24,borderRadius:5,background:f===I?"var(--hub-bg-2)":"transparent",color:f===I?"var(--hub-ink)":"var(--hub-ink-3)",border:"1px solid "+(f===I?"var(--hub-line)":"transparent")},children:[B,e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)"},children:P})]},I))}),e.jsxs("div",{className:"hub-card flex items-center gap-2 px-2.5 flex-1",style:{height:30,background:"var(--hub-surface)",maxWidth:360},children:[e.jsx(Es,{size:13,style:{color:"var(--hub-ink-3)"}}),e.jsx("input",{value:p,onChange:I=>c(I.target.value),className:"flex-1 bg-transparent outline-none text-[13px]",style:{color:"var(--hub-ink)"},placeholder:s("market.searchPlaceholder")||"Search…"}),p&&e.jsx("button",{onClick:()=>c(""),className:"hub-icon-btn sm",children:e.jsx(ke,{size:11})})]}),e.jsxs("div",{className:"ml-auto hub-mono text-[12px]",style:{color:"var(--hub-ink-3)"},children:[_.length,"/",t.length]})]}),a&&t.length===0?e.jsx("div",{className:"hub-card p-6 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(je,{size:20,className:"animate-spin",style:{color:"var(--hub-ink-3)"}}),e.jsx("p",{style:{color:"var(--hub-ink-3)"},children:s("app.loading")})]})}):_.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:_.map(I=>e.jsx(Ks,{server:I,cost:O.find(B=>B.name===I.name),onRemove:F,onEdit:$,onToggle:w,onVisibilityChange:k,onRefresh:A,onReload:E},I.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:N?s("common.showing",{start:(N.page-1)*N.limit+1,end:Math.min(N.page*N.limit,N.total),total:N.total}):s("common.showing",{start:1,end:t.length,total:t.length})}),e.jsx("div",{className:"flex-[4] flex justify-center",children:N&&N.totalPages>1&&e.jsx(Ds,{currentPage:o,totalPages:N.totalPages,onPageChange:u,disabled:a})}),e.jsxs("div",{className:"flex-[2] flex items-center justify-end gap-2",children:[e.jsxs("label",{htmlFor:"perPage",children:[s("common.itemsPerPage"),":"]}),e.jsxs("select",{id:"perPage",value:g,onChange:I=>S(Number(I.target.value)),disabled:a,className:"hub-input",style:{height:26,width:70,padding:"0 6px",fontSize:12},children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})]}),R&&e.jsx(Xs,{server:R,onEdit:()=>{T(null),A()},onCancel:()=>T(null)}),q&&e.jsx(Ys,{onSuccess:()=>{Y(!1),A()},onCancel:()=>Y(!1)}),x&&e.jsx(Qs,{onSuccess:()=>{m(!1),A()},onCancel:()=>m(!1)})]})};export{mt as default};
|
|
37
|
+
//# sourceMappingURL=ServersPage-WhPsI-wN.js.map
|