@samanhappy/mcphub 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.fr.md +12 -6
- package/README.md +23 -7
- package/README.zh.md +24 -8
- package/dist/clients/openapi.js +439 -72
- package/dist/clients/openapi.js.map +1 -1
- package/dist/config/index.js +24 -2
- package/dist/config/index.js.map +1 -1
- package/dist/constants/oauthServerDefaults.js +5 -0
- package/dist/constants/oauthServerDefaults.js.map +1 -1
- package/dist/controllers/activityController.js +11 -0
- package/dist/controllers/activityController.js.map +1 -1
- package/dist/controllers/logController.js +10 -3
- package/dist/controllers/logController.js.map +1 -1
- package/dist/controllers/mcpbController.js +6 -13
- package/dist/controllers/mcpbController.js.map +1 -1
- package/dist/controllers/oauthCallbackController.js +26 -0
- package/dist/controllers/oauthCallbackController.js.map +1 -1
- package/dist/controllers/oauthServerController.js +40 -4
- package/dist/controllers/oauthServerController.js.map +1 -1
- package/dist/controllers/serverController.js +122 -31
- package/dist/controllers/serverController.js.map +1 -1
- package/dist/controllers/templateController.js +1 -1
- package/dist/controllers/templateController.js.map +1 -1
- package/dist/routes/index.js +2 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/services/authorizationService.js +28 -0
- package/dist/services/authorizationService.js.map +1 -0
- package/dist/services/cimdClientService.js +195 -0
- package/dist/services/cimdClientService.js.map +1 -0
- package/dist/services/mcpOAuthProvider.js +2 -2
- package/dist/services/mcpOAuthProvider.js.map +1 -1
- package/dist/services/mcpService.js +108 -11
- package/dist/services/mcpService.js.map +1 -1
- package/dist/services/oauthClientRegistration.js +27 -9
- package/dist/services/oauthClientRegistration.js.map +1 -1
- package/dist/services/oauthServerService.js +17 -1
- package/dist/services/oauthServerService.js.map +1 -1
- package/dist/services/openApiToolStatsService.js +37 -0
- package/dist/services/openApiToolStatsService.js.map +1 -0
- package/dist/services/serverConfigPresenter.js +85 -0
- package/dist/services/serverConfigPresenter.js.map +1 -0
- package/dist/services/templateService.js +48 -11
- package/dist/services/templateService.js.map +1 -1
- package/dist/services/vectorSearchService.js +31 -6
- package/dist/services/vectorSearchService.js.map +1 -1
- package/dist/utils/oauthIssuer.js +57 -0
- package/dist/utils/oauthIssuer.js.map +1 -0
- package/dist/utils/openApiRequestBody.js +220 -0
- package/dist/utils/openApiRequestBody.js.map +1 -0
- package/dist/utils/processTree.js +47 -0
- package/dist/utils/processTree.js.map +1 -0
- package/dist/utils/serverConfigPersistence.js +3 -0
- package/dist/utils/serverConfigPersistence.js.map +1 -1
- package/dist/utils/serverConfigValidation.js +13 -0
- package/dist/utils/serverConfigValidation.js.map +1 -0
- package/dist/utils/serverNameValidation.js +56 -0
- package/dist/utils/serverNameValidation.js.map +1 -0
- package/dist/utils/smartRouting.js +9 -4
- package/dist/utils/smartRouting.js.map +1 -1
- package/dist/utils/ssrf.js +6 -5
- package/dist/utils/ssrf.js.map +1 -1
- package/dist/utils/systemConfigCache.js +40 -2
- package/dist/utils/systemConfigCache.js.map +1 -1
- package/frontend/dist/assets/{ActivityPage-C6m1hGLq.js → ActivityPage-BYoyi-IG.js} +2 -2
- package/frontend/dist/assets/{ActivityPage-C6m1hGLq.js.map → ActivityPage-BYoyi-IG.js.map} +1 -1
- package/frontend/dist/assets/ConfirmDialog-3APts2Y9.js +2 -0
- package/frontend/dist/assets/ConfirmDialog-3APts2Y9.js.map +1 -0
- package/frontend/dist/assets/Dashboard-BOHkLPxE.js +2 -0
- package/frontend/dist/assets/{Dashboard-DFKfjPff.js.map → Dashboard-BOHkLPxE.js.map} +1 -1
- package/frontend/dist/assets/{EndpointCopy-CP_Fb1To.js → EndpointCopy-DDVLhiUy.js} +2 -2
- package/frontend/dist/assets/{EndpointCopy-CP_Fb1To.js.map → EndpointCopy-DDVLhiUy.js.map} +1 -1
- package/frontend/dist/assets/GroupsPage-B3bHSWmT.js +33 -0
- package/frontend/dist/assets/{GroupsPage-Cwfm5q-a.js.map → GroupsPage-B3bHSWmT.js.map} +1 -1
- package/frontend/dist/assets/{LoginPage-CnF44h_n.js → LoginPage-CfAnFIbQ.js} +2 -2
- package/frontend/dist/assets/{LoginPage-CnF44h_n.js.map → LoginPage-CfAnFIbQ.js.map} +1 -1
- package/frontend/dist/assets/{LogsPage-BFIpICsM.js → LogsPage-DT2VotXH.js} +2 -2
- package/frontend/dist/assets/{LogsPage-BFIpICsM.js.map → LogsPage-DT2VotXH.js.map} +1 -1
- package/frontend/dist/assets/MarketPage-Cn0J7UNX.js +3 -0
- package/frontend/dist/assets/MarketPage-Cn0J7UNX.js.map +1 -0
- package/frontend/dist/assets/{OAuthConsentPage-zqXUvKMF.js → OAuthConsentPage-DnKLaKDH.js} +2 -2
- package/frontend/dist/assets/{OAuthConsentPage-zqXUvKMF.js.map → OAuthConsentPage-DnKLaKDH.js.map} +1 -1
- package/frontend/dist/assets/{PromptsPage-Cm8ykiI4.js → PromptsPage-Ccg3fJWt.js} +2 -2
- package/frontend/dist/assets/{PromptsPage-Cm8ykiI4.js.map → PromptsPage-Ccg3fJWt.js.map} +1 -1
- package/frontend/dist/assets/{ResourcesPage-UMyO6mQ4.js → ResourcesPage-V45CxfvA.js} +2 -2
- package/frontend/dist/assets/{ResourcesPage-UMyO6mQ4.js.map → ResourcesPage-V45CxfvA.js.map} +1 -1
- package/frontend/dist/assets/{ServersPage-B0RoM8ez.js → ServersPage-DA_nkhLB.js} +5 -5
- package/frontend/dist/assets/{ServersPage-B0RoM8ez.js.map → ServersPage-DA_nkhLB.js.map} +1 -1
- package/frontend/dist/assets/SettingsPage-BJjO5cte.js +12 -0
- package/frontend/dist/assets/SettingsPage-BJjO5cte.js.map +1 -0
- package/frontend/dist/assets/{StatusDot-BAMXeT2x.js → StatusDot-DcjrhMNI.js} +2 -2
- package/frontend/dist/assets/{StatusDot-BAMXeT2x.js.map → StatusDot-DcjrhMNI.js.map} +1 -1
- package/frontend/dist/assets/{ToggleGroup-Cfgt5lJo.js → ToggleGroup-BSLtGF--.js} +2 -2
- package/frontend/dist/assets/{ToggleGroup-Cfgt5lJo.js.map → ToggleGroup-BSLtGF--.js.map} +1 -1
- package/frontend/dist/assets/UsersPage-DKdCe4GT.js +2 -0
- package/frontend/dist/assets/UsersPage-DKdCe4GT.js.map +1 -0
- package/frontend/dist/assets/contextCost-CilWqGWT.js +2 -0
- package/frontend/dist/assets/contextCost-CilWqGWT.js.map +1 -0
- package/frontend/dist/assets/index-DjExFs33.js +3 -0
- package/frontend/dist/assets/index-DjExFs33.js.map +1 -0
- package/frontend/dist/assets/index-DtrCVU1h.css +1 -0
- package/frontend/dist/assets/passwordValidation-DTLWgUy9.js +2 -0
- package/frontend/dist/assets/passwordValidation-DTLWgUy9.js.map +1 -0
- package/frontend/dist/assets/{resourceService-D2QmlFby.js → resourceService-DIUK5vbC.js} +2 -2
- package/frontend/dist/assets/{resourceService-D2QmlFby.js.map → resourceService-DIUK5vbC.js.map} +1 -1
- package/frontend/dist/assets/useCostData-CSeCIQmM.js +2 -0
- package/frontend/dist/assets/useCostData-CSeCIQmM.js.map +1 -0
- package/frontend/dist/assets/useSettingsData-CvAOhPaX.js +2 -0
- package/frontend/dist/assets/{useSettingsData-CeCvZ2nU.js.map → useSettingsData-CvAOhPaX.js.map} +1 -1
- package/frontend/dist/assets/variableDetection-BeF9gp9K.js +16 -0
- package/frontend/dist/assets/variableDetection-BeF9gp9K.js.map +1 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +7 -7
- package/frontend/dist/assets/ConfirmDialog-BCMNzi21.js +0 -2
- package/frontend/dist/assets/ConfirmDialog-BCMNzi21.js.map +0 -1
- package/frontend/dist/assets/Dashboard-DFKfjPff.js +0 -2
- package/frontend/dist/assets/GroupsPage-Cwfm5q-a.js +0 -33
- package/frontend/dist/assets/MarketPage-Du-NqiEl.js +0 -3
- package/frontend/dist/assets/MarketPage-Du-NqiEl.js.map +0 -1
- package/frontend/dist/assets/SettingsPage-BTB-36-n.js +0 -12
- package/frontend/dist/assets/SettingsPage-BTB-36-n.js.map +0 -1
- package/frontend/dist/assets/UsersPage-DlzYf7Su.js +0 -2
- package/frontend/dist/assets/UsersPage-DlzYf7Su.js.map +0 -1
- package/frontend/dist/assets/contextCost-kp2vZYp7.js +0 -2
- package/frontend/dist/assets/contextCost-kp2vZYp7.js.map +0 -1
- package/frontend/dist/assets/index-CGvImZ3F.css +0 -1
- package/frontend/dist/assets/index-CvXw771N.js +0 -3
- package/frontend/dist/assets/index-CvXw771N.js.map +0 -1
- package/frontend/dist/assets/useSettingsData-CeCvZ2nU.js +0 -2
- package/frontend/dist/assets/variableDetection-DKPiHkxr.js +0 -16
- package/frontend/dist/assets/variableDetection-DKPiHkxr.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{r as h,R as U,j as e}from"./framework-vendor-BHAQX05P.js";import{m as se,d as _,i as me,e as X}from"./index-DjExFs33.js";import{u as Y,a as Z}from"./useCostData-CSeCIQmM.js";import{u as ne}from"./useSettingsData-CvAOhPaX.js";import{f as B,p as ue}from"./contextCost-CilWqGWT.js";import{g as pe}from"./toolDescription-Dw3sa28K.js";import{u as $}from"./i18n-vendor-CMcB7XUR.js";import{W as xe,g as he,F as ge,C as be,q as V,G as fe,y as ye,w as je,T as ve,u as Ne,z as te,H as ke,P as re,l as Se,X as we}from"./icons-vendor-HZHHWeTa.js";import{D as Ce}from"./DeleteDialog-D9ycSRvn.js";const Ee={tools:[],prompts:[],resources:[]},ae={tools:"all",prompts:"all",resources:"all"},le=({servers:n,value:p,onChange:t,className:d,serverCosts:y=[]})=>{const{t:c}=$(),{nameSeparator:b}=ne(),[C,A]=h.useState(new Set),m=U.useMemo(()=>p.map(s=>typeof s=="string"?{name:s,...ae}:{...s,tools:s.tools||"all",prompts:s.prompts||"all",resources:s.resources||"all"}),[p]),N=U.useMemo(()=>n.filter(s=>s.enabled!==!1),[n]);U.useEffect(()=>{const s=new Set(m.map(a=>a.name)),l=new Set(N.map(a=>a.name));A(a=>{const f=new Set;return a.forEach(i=>{(s.has(i)||l.has(i))&&f.add(i)}),f})},[m,N]);const k=s=>{if(m.findIndex(a=>a.name===s)>=0){const a=m.filter(f=>f.name!==s);t(a)}else{const a=[...m,{name:s,...ae}];t(a)}},E=s=>{A(l=>{const a=new Set(l);return a.has(s)?a.delete(s):a.add(s),a})},S=s=>["tools","prompts","resources"].some(l=>{const a=s[l];return a==="all"||Array.isArray(a)&&a.length>0}),D=(s,l,a,f=!1)=>{const i=m.find(z=>z.name===s),R={...i?{...i}:{name:s,...Ee},[l]:a};if(!S(R)){const z=m.filter(v=>v.name!==s);t(z),f||A(v=>{const q=new Set(v);return q.delete(s),q});return}if(i){t(m.map(z=>z.name===s?R:z));return}t([...m,R])},u=(s,l)=>{const a=m.find(i=>i.name===s);if(!a)return;const f={...a};l?f.alias=l:delete f.alias,t(m.map(i=>i.name===s?f:i))},g=(s,l)=>{const a=`${s}${b}`;return l.startsWith(a)?l.slice(a.length):l},x=(s,l)=>l==="tools"?(s.tools||[]).filter(a=>a.enabled!==!1).map(a=>({key:a.name,value:g(s.name,a.name),description:a.description,defaultDescription:a.defaultDescription,hasDescriptionOverride:a.hasDescriptionOverride})):l==="prompts"?(s.prompts||[]).filter(a=>a.enabled!==!1).map(a=>({key:a.name,value:g(s.name,a.name),description:a.description})):(s.resources||[]).filter(a=>a.enabled!==!1).map(a=>({key:a.uri,value:a.uri,description:a.description})),r=U.useMemo(()=>{const s=new Map;return y.forEach(l=>{const a=new Map;l.items.forEach(f=>a.set(f.name,f.cost)),s.set(l.name,a)}),s},[y]),o=s=>r.get(s)??new Map,j=(s,l)=>{const a=o(s.name);return x(s,l).filter(f=>T(s.name,l,f.value)).reduce((f,i)=>f+(a.get(i.key)??0),0)},I=s=>["tools","prompts","resources"].reduce((l,a)=>l+j(s,a),0),F=(s,l,a)=>{const f=N.find(z=>z.name===s);if(!f)return;const i=x(f,l).map(z=>z.value),P=m.find(z=>z.name===s);if(!P){D(s,l,[a]);return}const R=P[l];if(R==="all"){const z=i.filter(v=>v!==a);D(s,l,z);return}if(Array.isArray(R)){if(R.includes(a)){D(s,l,R.filter(v=>v!==a));return}const z=[...R,a];D(s,l,z.length===i.length?"all":z);return}D(s,l,[a])},M=s=>{const l=m.find(a=>a.name===s);return!!(l&&S(l))},w=s=>{const l=m.find(a=>a.name===s);return l?["tools","prompts","resources"].some(a=>{const f=l[a];return Array.isArray(f)&&f.length>0}):!1},T=(s,l,a)=>{const f=m.find(P=>P.name===s);if(!f)return!1;const i=f[l];return i==="all"?!0:Array.isArray(i)?i.includes(a):!1},O=(s,l)=>{const a=m.find(P=>P.name===s.name);if(!a)return 0;const f=x(s,l),i=a[l];if(i==="all")return f.length;if(Array.isArray(i)){const P=new Set(f.map(R=>R.value));return i.filter(R=>P.has(R)).length}return 0},W=[{key:"tools",titleKey:"groups.toolSelection",countKey:"groups.toolsSelected",allKey:"groups.allTools"},{key:"prompts",titleKey:"groups.promptSelection",countKey:"groups.promptsSelected",allKey:"groups.allPrompts"},{key:"resources",titleKey:"groups.resourceSelection",countKey:"groups.resourcesSelected",allKey:"groups.allResources"}],J=s=>W.map(({key:l})=>({key:l,count:O(s,l)})).filter(l=>l.count>0);return e.jsxs("div",{className:se("space-y-4",d),children:[e.jsx("div",{className:"space-y-3",children:N.map(s=>{const l=M(s.name),a=w(s.name),f=C.has(s.name),i=m.find(v=>v.name===s.name),P=J(s),R=W.filter(({key:v})=>x(s,v).length>0),z=o(s.name);return e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg hover:border-gray-300 hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 cursor-pointer rounded-lg transition-colors",onClick:()=>E(s.name),children:[e.jsxs("div",{className:"flex items-center space-x-3",onClick:v=>{v.stopPropagation(),k(s.name)},children:[e.jsx("input",{type:"checkbox",checked:l||a,onChange:()=>k(s.name),className:"w-4 h-4 text-blue-600 bg-gray-100 dark:bg-gray-800 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"font-medium text-gray-900 cursor-pointer select-none",children:s.name})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[I(s)>0&&e.jsxs("span",{className:"text-sm text-gray-400 hub-mono",title:c("cost.estimate"),children:["Σ ",B(I(s))]}),P.map(({key:v,count:q})=>e.jsxs("span",{className:"text-sm text-green-600 flex items-center gap-1",children:[v==="tools"?e.jsx(xe,{size:14}):v==="prompts"?e.jsx(he,{size:14}):e.jsx(ge,{size:14})," ",q]},v)),R.length>0&&e.jsx("button",{type:"button",className:"p-1 text-gray-400 hover:text-gray-600 transition-colors",children:e.jsx("svg",{className:se("w-5 h-5 transition-transform",f&&"rotate-180"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})]}),f&&R.length>0&&e.jsx("div",{className:"border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 p-3",children:e.jsxs("div",{className:"space-y-4",children:[i&&e.jsxs("div",{className:"space-y-1",onClick:v=>v.stopPropagation(),children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600",children:c("groups.alias")}),e.jsx("input",{type:"text",value:i.alias||"",placeholder:s.name,onChange:v=>u(s.name,v.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-sm text-gray-800 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100"})]}),R.map(({key:v,titleKey:q,countKey:ie,allKey:ce})=>{const K=x(s,v),Q=O(s,v),H=(i==null?void 0:i[v])==="all"||Q===K.length;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:c(q)}),e.jsxs("div",{className:"flex items-center gap-3",children:[i&&e.jsx("span",{className:"text-xs text-green-600",children:H?`(${c(ce)} ${K.length}/${K.length})`:`(${c(ie)} ${Q}/${K.length})`}),i&&j(s,v)>0&&e.jsxs("span",{className:"text-xs text-gray-400 hub-mono",title:c("cost.estimate"),children:["Σ ",B(j(s,v))]}),e.jsx("button",{type:"button",onClick:()=>{D(s.name,v,H?[]:"all",!0)},className:"text-sm text-blue-600 hover:text-blue-800 transition-colors",children:c(H?"groups.selectNone":"groups.selectAll")})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-2 max-h-32 overflow-y-auto",children:K.map(G=>{const de=T(s.name,v,G.value),L=v==="tools"?pe({description:G.description,defaultDescription:G.defaultDescription,hasDescriptionOverride:G.hasDescriptionOverride},c("tool.noDescription")):null,ee=L!=null&&L.hasDescriptionOverride?c("tool.defaultDescriptionTooltip",{description:L.defaultDescription}):G.description;return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:de,onChange:()=>F(s.name,v,G.value),className:"w-3 h-3 text-blue-600 bg-gray-100 dark:bg-gray-800 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-gray-700 break-all whitespace-nowrap flex-shrink-0",children:G.value}),(G.description||(L==null?void 0:L.hasDescriptionOverride))&&e.jsxs("span",{className:"min-w-0 flex items-center gap-1 text-gray-400 text-xs truncate",children:[e.jsx("span",{className:"truncate",title:ee||void 0,children:L?L.currentDescription:G.description}),(L==null?void 0:L.hasDescriptionOverride)&&e.jsx("span",{className:"inline-flex flex-shrink-0 items-center rounded-full border border-amber-200 bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:border-amber-700/60 dark:bg-amber-900/20 dark:text-amber-300",title:ee||void 0,children:c("tool.descriptionModifiedBadge")})]}),z.get(G.key)!=null&&e.jsxs("span",{className:"text-xs text-gray-400 hub-mono whitespace-nowrap ml-auto flex-shrink-0",title:c("cost.estimate"),children:["Σ ",B(z.get(G.key))]})]},G.key)})})]},v)})]})})]},s.name)})}),N.length===0&&e.jsx("p",{className:"text-gray-500 text-sm",children:c("groups.noServerOptions")})]})},De=({onAdd:n,onCancel:p})=>{const{t}=$(),{createGroup:d}=_(),{allServers:y}=Y(),{serverCosts:c}=Z(),[b,C]=h.useState([]),[A,m]=h.useState(null),[N,k]=h.useState(!1),[E,S]=h.useState({name:"",description:"",servers:[]});h.useEffect(()=>{C(y.filter(g=>g.enabled!==!1))},[y]);const D=g=>{const{name:x,value:r}=g.target;S(o=>({...o,[x]:r}))},u=async g=>{g.preventDefault(),k(!0),m(null);try{if(!E.name.trim()){m(t("groups.nameRequired")),k(!1);return}const x=await d(E.name,E.description,E.servers);if(!x||!x.success){m((x==null?void 0:x.message)||t("groups.createError")),k(!1);return}n()}catch(x){m(x instanceof Error?x.message:String(x)),k(!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 rounded-lg shadow-lg max-w-3xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-6 flex-shrink-0",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-800 mb-4",children:t("groups.addNew")}),A&&e.jsx("div",{className:"mb-4 p-3 bg-red-100 text-red-700 rounded-md border border-gray-200 dark:border-gray-700",children:A})]}),e.jsxs("form",{onSubmit:u,className:"flex flex-col flex-1 min-h-0",children:[e.jsx("div",{className:"flex-1 overflow-y-auto px-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-gray-700 text-sm font-bold mb-2",htmlFor:"name",children:[t("groups.name")," *"]}),e.jsx("input",{type:"text",id:"name",name:"name",value:E.name,onChange:D,className:"w-full border border-gray-300 rounded-md px-3 py-2 text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:t("groups.namePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-gray-700 text-sm font-bold mb-2",children:t("groups.configureCapabilities")}),e.jsx(le,{servers:b,value:E.servers,onChange:g=>S(x=>({...x,servers:g})),className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 bg-gray-50 dark:bg-gray-800",serverCosts:c})]})]})}),e.jsxs("div",{className:"flex justify-end space-x-2 p-5 pt-3 border-t border-[var(--hub-line-2)] flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:p,className:"hub-btn",disabled:N,children:t("common.cancel")}),e.jsx("button",{type:"submit",className:"hub-btn primary",disabled:N,children:t(N?"common.submitting":"common.create")})]})]})]})})},Ae=({group:n,onEdit:p,onCancel:t})=>{const{t:d}=$(),{updateGroup:y}=_(),{allServers:c}=Y(),{serverCosts:b}=Z(),[C,A]=h.useState([]),[m,N]=h.useState(null),[k,E]=h.useState(!1),[S,D]=h.useState({name:n.name,description:n.description||"",servers:n.servers||[]});h.useEffect(()=>{A(c.filter(x=>x.enabled!==!1))},[c]);const u=x=>{const{name:r,value:o}=x.target;D(j=>({...j,[r]:o}))},g=async x=>{x.preventDefault(),E(!0),N(null);try{if(!S.name.trim()){N(d("groups.nameRequired")),E(!1);return}const r=await y(n.id,{name:S.name,description:S.description,servers:S.servers});if(!r||!r.success){N((r==null?void 0:r.message)||d("groups.updateError")),E(!1);return}p()}catch(r){N(r instanceof Error?r.message:String(r)),E(!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 rounded-lg shadow-lg max-w-3xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-6 flex-shrink-0",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-800 mb-4",children:d("groups.edit")}),m&&e.jsx("div",{className:"mb-4 p-3 bg-red-100 text-red-700 rounded-md border border-gray-200 dark:border-gray-700",children:m})]}),e.jsxs("form",{onSubmit:g,className:"flex flex-col flex-1 min-h-0",children:[e.jsx("div",{className:"flex-1 overflow-y-auto px-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-gray-700 text-sm font-bold mb-2",htmlFor:"name",children:[d("groups.name")," *"]}),e.jsx("input",{type:"text",id:"name",name:"name",value:S.name,onChange:u,className:"w-full border border-gray-300 rounded-md px-3 py-2 text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:d("groups.namePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-gray-700 text-sm font-bold mb-2",children:d("groups.configureCapabilities")}),e.jsx(le,{servers:C,value:S.servers,onChange:x=>D(r=>({...r,servers:x})),className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 bg-gray-50 dark:bg-gray-800",serverCosts:b})]})]})}),e.jsxs("div",{className:"flex justify-end space-x-2 p-5 pt-3 border-t border-[var(--hub-line-2)] flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:t,className:"hub-btn",disabled:k,children:d("common.cancel")}),e.jsx("button",{type:"submit",className:"hub-btn primary",disabled:k,children:d(k?"common.submitting":"common.save")})]})]})]})})},Ie=n=>n.map(p=>typeof p=="string"?p:p.name),oe=(n,p)=>{const t=n.servers.find(d=>typeof d=="string"?d===p:d.name===p);return t?typeof t=="string"?{name:t,tools:"all",prompts:"all",resources:"all"}:t:{name:p,tools:"all",prompts:"all",resources:"all"}},Te=(n,p)=>{var d;return((d=oe(n,p).alias)==null?void 0:d.trim())||p},ze=async n=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(n),!0}catch{}try{const p=document.createElement("textarea");p.value=n,p.style.position="fixed",p.style.left="-9999px",document.body.appendChild(p),p.focus(),p.select();const t=document.execCommand("copy");return document.body.removeChild(p),t}catch{return!1}},Fe=({group:n,servers:p,onEdit:t,onDelete:d,cost:y})=>{var M;const{t:c}=$(),{showToast:b}=me(),{installConfig:C,nameSeparator:A}=ne(),m=((M=C==null?void 0:C.baseUrl)==null?void 0:M.replace(/\/+$/,""))||"",[N,k]=h.useState(!1),[E,S]=h.useState(!1),[D,u]=h.useState(!1),g=h.useRef(null);h.useEffect(()=>{const w=T=>{g.current&&!g.current.contains(T.target)&&u(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const x=async w=>{await ze(w)?(S(!0),u(!1),b(c("common.copySuccess")||"Copied","success"),setTimeout(()=>S(!1),1500)):b(c("common.copyFailed")||"Copy failed","error")},r=`${m}/mcp/${n.name}`,o=Ie(n.servers),j=p.filter(w=>o.includes(w.name)),I=w=>{const T=oe(n,w.name),O=`${w.name}${A}`,W=w.tools||[],J=w.prompts||[],s=w.resources||[],l=Array.isArray(T.tools)?W.filter(i=>{if(i.enabled===!1)return!1;const P=i.name.startsWith(O)?i.name.slice(O.length):i.name;return T.tools.includes(P)}).length:W.filter(i=>i.enabled!==!1).length,a=Array.isArray(T.prompts)?J.filter(i=>{if(i.enabled===!1)return!1;const P=i.name.startsWith(O)?i.name.slice(O.length):i.name;return T.prompts.includes(P)}).length:J.filter(i=>i.enabled!==!1).length,f=Array.isArray(T.resources)?s.filter(i=>i.enabled!==!1&&T.resources.includes(i.uri)).length:s.filter(i=>i.enabled!==!1).length;return{visibleTools:l,totalTools:W.length,visiblePrompts:a,totalPrompts:J.length,visibleResources:f,totalResources:s.length}},F=j.reduce((w,T)=>w+I(T).visibleTools,0);return e.jsxs("div",{className:"hub-card flex h-full flex-col overflow-visible",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",style:{borderBottom:"1px solid var(--hub-line-2)"},children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{style:{fontSize:15,fontWeight:600,letterSpacing:"-0.015em"},children:n.name}),e.jsx("span",{className:"hub-mono",style:{fontSize:11,color:"var(--hub-ink-3)",padding:"0 6px",border:"1px solid var(--hub-line)",borderRadius:4,height:18,display:"inline-flex",alignItems:"center"},title:n.id,children:n.id})]}),n.description&&e.jsx("div",{style:{fontSize:12.5,color:"var(--hub-ink-3)",marginTop:2},children:n.description})]}),e.jsxs("div",{className:"flex items-center gap-1",ref:g,children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>u(w=>!w),className:"hub-icon-btn sm",title:c("common.copy"),children:E?e.jsx(be,{size:13,className:"text-[var(--hub-ok)]"}):e.jsx(V,{size:13})}),D&&e.jsxs("div",{className:"absolute top-full right-0 mt-1 z-20 hub-card",style:{minWidth:160,padding:4},children:[e.jsxs("button",{onClick:()=>x(n.id),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",children:[e.jsx(V,{size:12})," ",c("common.copyId")]}),e.jsxs("button",{onClick:()=>x(r),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",children:[e.jsx(fe,{size:12})," ",c("common.copyUrl")]}),e.jsxs("button",{onClick:()=>x(JSON.stringify({mcpServers:{mcphub:{url:r,headers:{Authorization:"Bearer <your-access-token>"}}}},null,2)),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",children:[e.jsx(ye,{size:12})," ",c("common.copyJson")]})]})]}),e.jsx("button",{onClick:()=>t(n),className:"hub-icon-btn sm",title:c("groups.edit"),children:e.jsx(je,{size:13})}),e.jsx("button",{onClick:()=>k(!0),className:"hub-icon-btn sm",title:c("groups.delete"),style:{color:"var(--hub-ink-3)"},children:e.jsx(ve,{size:13})})]})]}),e.jsxs("div",{className:"grid flex-1 items-center gap-3 px-4 py-3",style:{gridTemplateColumns:"1fr 80px 1fr",minHeight:180},children:[e.jsx("div",{className:"flex flex-col gap-1.5",children:j.length===0?e.jsx("div",{style:{fontSize:12,color:"var(--hub-ink-3)"},children:c("groups.noServers")}):j.map(w=>{const T=I(w);return e.jsxs("div",{className:"flex items-center gap-2.5 px-2.5 py-1.5 rounded-md",style:{background:"var(--hub-bg-2)",border:"1px solid var(--hub-line-2)"},children:[e.jsx("span",{className:"inline-block flex-shrink-0",style:{width:6,height:6,borderRadius:50,background:w.status==="connected"?"var(--hub-ok)":w.status==="connecting"?"var(--hub-warn)":"var(--hub-err)"}}),e.jsx("span",{className:"hub-mono truncate flex-1",style:{fontSize:12.5},children:e.jsx("span",{title:w.name,children:Te(n,w.name)})}),e.jsxs("span",{className:"hub-mono hub-num flex-shrink-0",style:{fontSize:11,color:"var(--hub-ink-3)"},children:[T.visibleTools,"/",T.totalTools," tools"]})]},w.name)})}),e.jsxs("svg",{width:"80",height:"80",viewBox:"0 0 80 80",className:"self-center",children:[j.length===0?e.jsx("path",{d:"M0,40 C30,40 50,40 80,40",stroke:"var(--hub-line)",strokeWidth:"1",fill:"none",strokeDasharray:"3 3"}):j.map((w,T)=>{const O=12+60/Math.max(j.length,1)*(T+.5);return e.jsx("path",{d:`M0,${O} C 30,${O} 50,40 80,40`,stroke:"var(--hub-line)",strokeWidth:"1",fill:"none",strokeDasharray:"3 3"},T)}),e.jsx("circle",{cx:"80",cy:"40",r:"4",fill:"var(--hub-ink)"})]}),e.jsxs("div",{className:"px-3 py-2.5 rounded-md",style:{border:"1px solid var(--hub-line)",background:"var(--hub-bg-2)"},children:[e.jsx("div",{className:"hub-sect",style:{marginBottom:4},children:"endpoint"}),e.jsxs("div",{className:"hub-mono break-all",style:{fontSize:12,color:"var(--hub-ink-2)",lineHeight:1.4},children:[e.jsx("span",{style:{color:"var(--hub-ink-3)"},children:"/mcp/"}),e.jsx("b",{style:{color:"var(--hub-ink)",fontWeight:600},children:n.name})]}),e.jsx("div",{className:"flex gap-1.5 mt-2",children:e.jsxs("button",{className:"hub-btn sm flex-1 justify-center",onClick:()=>x(r),children:[e.jsx(V,{size:11})," ",c("common.copy")]})})]})]}),e.jsxs("div",{className:"flex justify-between items-center px-4 py-2",style:{borderTop:"1px solid var(--hub-line-2)",background:"var(--hub-bg-2)",fontSize:12,color:"var(--hub-ink-3)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"hub-mono",children:[e.jsx("span",{style:{color:"var(--hub-ink-2)"},children:j.length})," ",c("nav.servers").toLowerCase()," ·"," ",e.jsx("span",{style:{color:"var(--hub-ink-2)"},children:F})," ",c("server.tools").toLowerCase()]}),y&&e.jsxs("div",{className:"hub-mono mt-1",style:{fontSize:11.5,color:"var(--hub-ink-3)"},children:[e.jsxs("div",{title:c("cost.estimate"),children:[c("cost.totalFootprint"),": ",B(y.direct.exposed),"/",B(y.direct.gross)]}),y.smartRouting&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[c("cost.smartRouting"),": ",B(y.smartRouting.base)," (",c("cost.saved",{percent:ue(y.direct.exposed,y.smartRouting.base)}),")"]}),e.jsxs("div",{title:c("cost.smartRoutingPdHint"),children:[c("cost.smartRoutingPd"),":"," ",B(y.smartRouting.progressiveDisclosure)]})]}),y.connectedCount<y.totalCount&&e.jsx("div",{children:c("cost.connectedOf",{connected:y.connectedCount,total:y.totalCount})})]})]}),e.jsxs("button",{className:"hub-btn ghost sm",style:{color:"var(--hub-ink-3)"},onClick:()=>t(n),children:[c("groups.configureTools")||c("groups.edit"),e.jsx(Ne,{size:11,style:{transform:"rotate(-90deg)"}})]})]}),e.jsx(Ce,{isOpen:N,onClose:()=>k(!1),onConfirm:()=>{d(n.id),k(!1)},serverName:n.name,isGroup:!0})]})},Re=({onSuccess:n,onCancel:p})=>{const{t}=$(),[d,y]=h.useState(""),[c,b]=h.useState(null),[C,A]=h.useState(!1),[m,N]=h.useState(null),k=`{
|
|
2
|
+
"groups": [
|
|
3
|
+
{
|
|
4
|
+
"name": "AI Assistants",
|
|
5
|
+
"servers": ["openai-server", "anthropic-server"]
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "Development Tools",
|
|
9
|
+
"servers": [
|
|
10
|
+
{
|
|
11
|
+
"name": "github-server",
|
|
12
|
+
"tools": ["create_issue", "list_repos"],
|
|
13
|
+
"prompts": ["triage_prompt"],
|
|
14
|
+
"resources": ["resource://docs/repo-guide"]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "gitlab-server",
|
|
18
|
+
"tools": "all",
|
|
19
|
+
"prompts": "all",
|
|
20
|
+
"resources": "all"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Supports:
|
|
28
|
+
- Simple server list: ["server1", "server2"]
|
|
29
|
+
- Advanced server config: [{"name": "server1", "tools": ["tool1"], "prompts": ["prompt1"], "resources": ["resource://docs/guide"]}]
|
|
30
|
+
- All groups will be imported in a single efficient batch operation.`,E=r=>{try{const o=JSON.parse(r.trim());if(!o.groups||!Array.isArray(o.groups))return b(t("groupImport.invalidFormat")),null;for(const j of o.groups)if(!j.name||typeof j.name!="string")return b(t("groupImport.missingName")),null;return o}catch{return b(t("groupImport.parseError")),null}},S=()=>{b(null);const r=E(d);r&&N(r.groups)},D=async()=>{if(m){A(!0),b(null);try{const r=await X("/groups/batch",{groups:m});if(r.success){const{successCount:o,failureCount:j,results:I}=r;if(j>0){const F=I.filter(M=>!M.success).map(M=>`${M.name}: ${M.message||t("groupImport.addFailed")}`);b(t("groupImport.partialSuccess",{count:o,total:m.length})+`
|
|
31
|
+
`+F.join(`
|
|
32
|
+
`))}o>0&&n()}else b(r.message||t("groupImport.importFailed"))}catch(r){console.error("Import error:",r),b(t("groupImport.importFailed"))}finally{A(!1)}}},u=r=>e.jsx("span",{className:"text-gray-500 ml-2",children:t(`groups.${r}`)}),g=(r,o)=>{if(!o||o==="all")return null;const j=Array.isArray(o)?o.join(", "):o;return e.jsx("span",{className:"text-gray-500 ml-2",children:t(`groups.${r}`,{items:j})})},x=r=>!r||r.length===0?e.jsx("span",{className:"text-gray-500",children:t("groups.noServers")}):e.jsx("div",{className:"space-y-1",children:r.map((o,j)=>typeof o=="string"?e.jsxs("div",{className:"text-sm",children:["• ",o]},j):e.jsxs("div",{className:"text-sm",children:["• ",o.name,o.tools&&o.tools!=="all"&&e.jsxs("span",{className:"text-gray-500 ml-2",children:["(",Array.isArray(o.tools)?o.tools.join(", "):o.tools,")"]}),o.tools==="all"&&u("previewAllTools"),g("previewPrompts",o.prompts),o.prompts==="all"&&u("previewAllPrompts"),g("previewResources",o.resources),o.resources==="all"&&u("previewAllResources")]},j))});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("groupImport.title")}),e.jsx("button",{onClick:p,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),c&&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:c})}),m?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("groupImport.previewTitle")}),e.jsx("div",{className:"space-y-3",children:m.map((r,o)=>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:r.name}),r.description&&e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:r.description}),e.jsxs("div",{className:"mt-2 text-sm text-gray-600",children:[e.jsxs("strong",{children:[t("groups.servers"),":"]}),e.jsx("div",{className:"mt-1",children:x(r.servers)})]})]})})},o))})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:()=>N(null),disabled:C,className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:D,disabled:C,className:"hub-btn primary",children:C?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("groupImport.importing")]}):t("groupImport.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("groupImport.inputLabel")}),e.jsx("textarea",{value:d,onChange:r=>y(r.target.value),className:"w-full h-96 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-sm",placeholder:k}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:t("groupImport.inputHelp")})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[e.jsx("button",{onClick:p,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:S,disabled:!d.trim(),className:"hub-btn primary",children:t("groupImport.preview")})]})]})]})})},Pe=({groups:n,onCancel:p})=>{const{t}=$(),[d,y]=h.useState(""),[c,b]=h.useState(""),[C,A]=h.useState([]),[m,N]=h.useState(!1),[k,E]=h.useState(!1),[S,D]=h.useState(null),u=r=>{A(o=>o.includes(r)?o.filter(j=>j!==r):[...o,r])},g=()=>{C.length===n.length?A([]):A(n.map(r=>r.id))},x=async()=>{if(!d.trim()){D(t("template.nameRequired"));return}E(!0),D(null);try{const r=await X("/templates/export",{name:d.trim(),description:c.trim()||void 0,groupIds:C.length>0?C:void 0,includeDisabledServers:m});if(r.success&&r.data){const o=r.data,j=new Blob([JSON.stringify(o,null,2)],{type:"application/json"}),I=URL.createObjectURL(j),F=document.createElement("a");F.href=I,F.download=`${o.name.replace(/[^a-zA-Z0-9-_]/g,"_")}.mcphub-template.json`,document.body.appendChild(F),F.click(),document.body.removeChild(F),URL.revokeObjectURL(I),p()}else D(r.message||t("template.exportFailed"))}catch(r){console.error("Export error:",r),D(t("template.exportFailed"))}finally{E(!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-3xl 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("template.exportTitle")}),e.jsx("button",{onClick:p,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),S&&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:S})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[t("template.name")," *"]}),e.jsx("input",{type:"text",value:d,onChange:r=>y(r.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:t("template.namePlaceholder")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:t("template.description")}),e.jsx("input",{type:"text",value:c,onChange:r=>b(r.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:t("template.descriptionPlaceholder")})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:t("template.selectGroups")}),e.jsx("button",{onClick:g,className:"text-sm text-blue-600 hover:text-blue-800",children:C.length===n.length?t("template.deselectAll"):t("template.selectAll")})]}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:t("template.selectGroupsHelp")}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md max-h-48 overflow-y-auto",children:n.map(r=>e.jsxs("label",{className:"flex items-center px-3 py-2 hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:C.includes(r.id),onChange:()=>u(r.id),className:"mr-3 h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:r.name}),r.description&&e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:r.description})]})]},r.id))})]}),e.jsxs("label",{className:"flex items-center space-x-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:r=>N(r.target.checked),className:"h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:t("template.includeDisabled")})]})]}),e.jsx("div",{className:"mt-4 p-3 bg-blue-50 border border-blue-200 rounded-md",children:e.jsx("p",{className:"text-sm text-blue-700",children:t("template.exportNote")})}),e.jsxs("div",{className:"flex justify-end space-x-4 mt-6",children:[e.jsx("button",{onClick:p,className:"hub-btn",children:t("common.cancel")}),e.jsx("button",{onClick:x,disabled:k||!d.trim(),className:"hub-btn primary",children:t(k?"template.exporting":"template.export")})]})]})})},Ge=({onSuccess:n,onCancel:p})=>{const{t}=$(),[d,y]=h.useState(null),[c,b]=h.useState(null),[C,A]=h.useState(!1),[m,N]=h.useState(null),k=h.useRef(null),E=u=>{var r;b(null),y(null),N(null);const g=(r=u.target.files)==null?void 0:r[0];if(!g)return;const x=new FileReader;x.onload=o=>{var j;try{const I=JSON.parse((j=o.target)==null?void 0:j.result);if(!I.version||!I.name||!I.servers||!I.groups){b(t("template.invalidFormat"));return}y(I)}catch{b(t("template.parseError"))}},x.readAsText(g)},S=u=>{if(b(null),y(null),N(null),!!u.trim())try{const g=JSON.parse(u.trim());if(!g.version||!g.name||!g.servers||!g.groups){b(t("template.invalidFormat"));return}y(g)}catch{b(t("template.parseError"))}},D=async()=>{if(d){A(!0),b(null);try{const u=await X("/templates/import",d);u.data?(N(u.data),u.data.success&&n()):b(u.message||t("template.importFailed"))}catch(u){console.error("Import error:",u),b(t("template.importFailed"))}finally{A(!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("template.importTitle")}),e.jsx("button",{onClick:p,className:"text-gray-500 hover:text-gray-700",children:"✕"})]}),c&&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:c})}),m&&e.jsxs("div",{className:`mb-4 p-4 rounded border-l-4 ${m.success?"bg-green-50 border-green-500":"bg-yellow-50 border-yellow-500"}`,children:[e.jsx("p",{className:m.success?"text-green-700":"text-yellow-700",children:t("template.importResult",{serversCreated:m.serversCreated,serversSkipped:m.serversSkipped,groupsCreated:m.groupsCreated,groupsSkipped:m.groupsSkipped})}),m.requiredEnvVars.length>0&&e.jsxs("div",{className:"mt-2 p-2 bg-orange-50 border border-orange-200 rounded",children:[e.jsx("p",{className:"text-sm font-medium text-orange-800",children:t("template.envVarsNeeded")}),e.jsx("ul",{className:"mt-1 text-sm text-orange-700",children:m.requiredEnvVars.map(u=>e.jsx("li",{className:"font-mono",children:u},u))})]})]}),d?e.jsxs("div",{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md",children:[e.jsx("h3",{className:"font-medium text-gray-900",children:d.name}),d.description&&e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:d.description}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[t("template.version"),": ",d.version," | ",t("template.createdAt"),":"," ",new Date(d.createdAt).toLocaleDateString()]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:[t("template.servers")," (",Object.keys(d.servers).length,")"]}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md divide-y divide-gray-200 dark:divide-gray-700 max-h-40 overflow-y-auto",children:Object.entries(d.servers).map(([u,g])=>e.jsxs("div",{className:"px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:u}),e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:g.type||"stdio"})]},u))})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:[t("template.groups")," (",d.groups.length,")"]}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md divide-y divide-gray-200 dark:divide-gray-700 max-h-40 overflow-y-auto",children:d.groups.map((u,g)=>e.jsxs("div",{className:"px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:u.name}),u.description&&e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:u.description}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[u.servers.length," ",t("template.serversInGroup")]})]},g))})]}),d.requiredEnvVars.length>0&&e.jsxs("div",{className:"p-3 bg-orange-50 border border-orange-200 rounded-md",children:[e.jsx("h4",{className:"text-sm font-medium text-orange-800",children:t("template.envVarsNeeded")}),e.jsx("ul",{className:"mt-1 text-sm text-orange-700 font-mono",children:d.requiredEnvVars.map(u=>e.jsx("li",{children:u},u))})]})]}),e.jsxs("div",{className:"flex justify-end space-x-4 mt-6",children:[e.jsx("button",{onClick:()=>{y(null),N(null),k.current&&(k.current.value="")},className:"hub-btn",children:t("common.back")}),e.jsx("button",{onClick:D,disabled:C,className:"hub-btn primary",children:t(C?"template.importing":"template.import")})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:t("template.uploadFile")})}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsx("input",{ref:k,type:"file",accept:".json",onChange:E,className:"block text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"})})]}),e.jsxs("div",{className:"relative my-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-300"})}),e.jsx("div",{className:"relative flex justify-center text-sm",children:e.jsx("span",{className:"bg-white dark:bg-gray-800 px-2 text-gray-500",children:t("template.or")})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t("template.pasteJson")}),e.jsx("textarea",{className:"w-full h-64 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:t("template.pastePlaceholder"),onChange:u=>S(u.target.value)})]}),e.jsx("div",{className:"flex justify-end space-x-4",children:e.jsx("button",{onClick:p,className:"hub-btn",children:t("common.cancel")})})]})]})})},Ue=()=>{const{t:n}=$(),{groups:p,loading:t,error:d,setError:y,deleteGroup:c,triggerRefresh:b}=_(),{allServers:C}=Y({refreshOnMount:!0}),{groupCosts:A,refetch:m}=Z();h.useEffect(()=>{m()},[p,C,m]);const[N,k]=h.useState(null),[E,S]=h.useState(!1),[D,u]=h.useState(!1),[g,x]=h.useState(!1),[r,o]=h.useState(!1),j=async I=>{const F=await c(I);(!F||!F.success)&&y((F==null?void 0:F.message)||n("groups.deleteError"))};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:n("pages.groups.title")}),e.jsxs("p",{className:"hub-sub",children:[e.jsx("span",{className:"hub-num",children:p.length})," ",n("nav.groups").toLowerCase()]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"hub-btn",onClick:()=>u(!0),children:[e.jsx(te,{size:13})," ",n("groupImport.button")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>x(!0),children:[e.jsx(ke,{size:13})," ",n("template.exportButton")]}),e.jsxs("button",{className:"hub-btn",onClick:()=>o(!0),children:[e.jsx(te,{size:13})," ",n("template.importButton")]}),e.jsxs("button",{className:"hub-btn primary",onClick:()=>S(!0),children:[e.jsx(re,{size:13})," ",n("groups.add")]})]})]}),d&&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(Se,{size:14,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate text-[13px]",children:d})]}),e.jsx("button",{className:"hub-icon-btn sm",onClick:()=>y(null),children:e.jsx(we,{size:13})})]}),t?e.jsx("div",{className:"hub-card p-6 text-center",style:{color:"var(--hub-ink-3)"},children:n("app.loading")}):p.length===0?e.jsx("div",{className:"hub-card p-10 text-center",style:{color:"var(--hub-ink-3)"},children:n("groups.noGroups")}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3.5",children:[p.map(I=>e.jsx(Fe,{group:I,servers:C,onEdit:k,onDelete:j,cost:A.find(F=>F.id===I.id)},I.id)),e.jsx("button",{onClick:()=>S(!0),className:"flex items-center justify-center text-[var(--hub-ink-3)] hover:text-[var(--hub-ink-2)] transition-colors",style:{border:"1px dashed var(--hub-line)",borderRadius:10,minHeight:200,background:"transparent",cursor:"pointer"},children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"grid place-items-center mx-auto mb-2",style:{width:36,height:36,borderRadius:10,border:"1px solid var(--hub-line)"},children:e.jsx(re,{size:16})}),e.jsx("div",{style:{fontSize:13,fontWeight:500,color:"var(--hub-ink-2)"},children:n("groups.add")}),e.jsx("div",{style:{fontSize:12,marginTop:2},children:n("groups.addNew")})]})})]}),E&&e.jsx(De,{onAdd:()=>{S(!1),b()},onCancel:()=>S(!1)}),D&&e.jsx(Re,{onSuccess:()=>{u(!1),b()},onCancel:()=>u(!1)}),N&&e.jsx(Ae,{group:N,onEdit:()=>{k(null),b()},onCancel:()=>k(null)}),g&&e.jsx(Pe,{groups:p,onCancel:()=>x(!1)}),r&&e.jsx(Ge,{onSuccess:()=>{o(!1),b()},onCancel:()=>o(!1)})]})};export{Ue as default};
|
|
33
|
+
//# sourceMappingURL=GroupsPage-B3bHSWmT.js.map
|