import{m as c}from"./mcp-D3Owym07.js";import{y as g}from"./main.js";const m=g((a,i)=>({mcpServers:[],loading:!1,total:0,pageNo:1,pageSize:12,searchName:"",searchMode:"blur",selectedNames:new Set,currentMcp:null,detailLoading:!1,selectedVersion:null,importDialogOpen:!1,error:null,fetchMcpServers:async e=>{const t=i().mcpServers.length>0;a({loading:!t,error:null});try{const{searchName:r,searchMode:o,pageNo:l,pageSize:s}=i(),n=(await c.listMcpServers({mcpName:r||void 0,namespaceId:e,search:o,pageNo:l,pageSize:s})).data;a({mcpServers:n.pageItems||[],total:n.totalCount||0,loading:!1})}catch(r){a({loading:!1,error:r.response?.data?.message||"Failed to fetch MCP servers",mcpServers:[],total:0})}},fetchMcpDetail:async(e,t,r)=>{const o=i().currentMcp!==null;a({detailLoading:!o,error:null});try{const s=await c.getMcpServer({mcpName:t,version:r,namespaceId:e});a({currentMcp:s.data,detailLoading:!1,selectedVersion:r||s.data?.versionDetail?.version||null})}catch(l){a({detailLoading:!1,error:l.response?.data?.message||"Failed to fetch MCP server detail",currentMcp:null})}},deleteMcpServer:async(e,t)=>{try{return await c.deleteMcpServer({mcpName:t,namespaceId:e}),!0}catch(r){return a({error:r.response?.data?.message||"Failed to delete MCP server"}),!1}},batchDelete:async(e,t)=>{let r=!0;for(const o of t)try{await c.deleteMcpServer({mcpName:o,namespaceId:e})}catch{r=!1}return a({selectedNames:new Set}),r},toggleEnabled:async(e,t)=>{try{const o={...{...t,enabled:!t.enabled}},{toolSpec:l,backendEndpoints:s,frontendEndpoints:d,allVersions:p,...n}=o;return await c.updateMcpServer({mcpName:t.name,namespaceId:e,serverSpecification:JSON.stringify(n),toolSpecification:l?JSON.stringify(l):void 0,endpointSpecification:s?JSON.stringify({type:t.remoteServerConfig?.serviceRef?"REF":"DIRECT",data:t.remoteServerConfig?.serviceRef||(s[0]??{})}):void 0,latest:!0}),!0}catch(r){return a({error:r.response?.data?.message||"Failed to toggle MCP server"}),!1}},setSearchParams:e=>{a(t=>({...t,...e,pageNo:1}))},setPage:(e,t)=>{a(r=>({pageNo:e,pageSize:t??r.pageSize}))},resetSearch:()=>{a({searchName:"",searchMode:"blur",pageNo:1})},setSelectedVersion:e=>{a({selectedVersion:e})},toggleSelect:e=>{a(t=>{const r=new Set(t.selectedNames);return r.has(e)?r.delete(e):r.add(e),{selectedNames:r}})},selectAll:e=>{a({selectedNames:new Set(e)})},clearSelection:()=>{a({selectedNames:new Set})},openImportDialog:()=>a({importDialogOpen:!0}),closeImportDialog:()=>a({importDialogOpen:!1}),clearCurrentMcp:()=>{a({currentMcp:null,selectedVersion:null})},clearError:()=>{a({error:null})}}));export{m as u};
