import{z as n,y as d}from"./main.js";const o={listAgents:e=>n.get("v3/console/ai/a2a/list",{params:e}),getAgent:e=>n.get("v3/console/ai/a2a",{params:e}),createAgent:e=>n.post("v3/console/ai/a2a",e),updateAgent:e=>n.put("v3/console/ai/a2a",e),deleteAgent:e=>n.delete("v3/console/ai/a2a",{params:e}),getVersionList:e=>n.get("v3/console/ai/a2a/version/list",{params:e})},A=d((e,i)=>({agents:[],loading:!1,total:0,pageNo:1,pageSize:12,searchName:"",searchMode:"blur",selectedNames:new Set,currentAgent:null,detailLoading:!1,versionList:[],error:null,fetchAgents:async a=>{const r=i().agents.length>0;e({loading:!r,error:null});try{const{searchName:t,searchMode:s,pageNo:l,pageSize:c}=i(),g=(await o.listAgents({agentName:t||"",namespaceId:a,search:s,pageNo:l,pageSize:c})).data;e({agents:g.pageItems||[],total:g.totalCount||0,loading:!1})}catch(t){e({loading:!1,error:t.response?.data?.message||"Failed to fetch agents",agents:[],total:0})}},fetchAgentDetail:async(a,r,t)=>{const s=i().currentAgent!==null;e({detailLoading:!s,error:null});try{const c=await o.getAgent({agentName:r,version:t,namespaceId:a});e({currentAgent:c.data,detailLoading:!1})}catch(l){e({detailLoading:!1,error:l.response?.data?.message||"Failed to fetch agent detail",currentAgent:null})}},fetchVersionList:async(a,r)=>{try{const s=await o.getVersionList({agentName:r,namespaceId:a});e({versionList:s.data||[]})}catch{e({versionList:[]})}},deleteAgent:async(a,r)=>{try{return await o.deleteAgent({agentName:r,namespaceId:a}),!0}catch(t){return e({error:t.response?.data?.message||"Failed to delete agent"}),!1}},batchDelete:async(a,r)=>{let t=!0;for(const s of r)try{await o.deleteAgent({agentName:s,namespaceId:a})}catch{t=!1}return e({selectedNames:new Set}),t},setSearchParams:a=>{e(r=>({...r,...a,pageNo:1}))},setPage:(a,r)=>{e(t=>({pageNo:a,pageSize:r??t.pageSize}))},resetSearch:()=>{e({searchName:"",searchMode:"blur",pageNo:1})},toggleSelect:a=>{e(r=>{const t=new Set(r.selectedNames);return t.has(a)?t.delete(a):t.add(a),{selectedNames:t}})},selectAll:a=>{e({selectedNames:new Set(a)})},clearSelection:()=>{e({selectedNames:new Set})},clearCurrentAgent:()=>{e({currentAgent:null,versionList:[]})},clearError:()=>{e({error:null})}}));export{o as a,A as u};
