import{a7 as y,aT as o,a4 as a,aQ as u,e as d,ch as h,ci as T}from"./index-dNe6i2rS.js";import{r as m}from"./reverse-Cgyp6Kdo.js";const A=y.injectEndpoints({endpoints:r=>({getChats:r.query({query:({pId:e,params:t={offset:0,limit:1e3}})=>({url:`project/${e}/brewer/chats?${o.stringify(t)}`}),providesTags:u.providesListItems(a.ProjectTags.Chat,"id")}),getChat:r.query({query:({pId:e,chatId:t})=>({url:`project/${e}/brewer/chats/${t}`}),providesTags:u.cacheByIdArgProperty(a.ProjectTags.Chat,"chatId"),extraOptions:{skipError:!0}}),deleteChat:r.mutation({query:({pId:e,chatId:t})=>({url:`project/${e}/brewer/chats/${t}`,method:"DELETE"}),invalidatesTags:u.cacheByIdArgProperty(a.ProjectTags.Chat,"chatId")}),createChat:r.mutation({query:({pId:e,data:t,selectedAgent:s})=>({url:`project/${e}/brewer/chats?${o.stringify({selected_agent_id:s})}`,method:"POST",data:t}),invalidatesTags:u.invalidatesList(a.ProjectTags.Chat)}),getChatMessages:r.query({query:({pId:e,chatId:t,params:s={offset:0,limit:1e3}})=>({url:`project/${e}/brewer/chats/${t}/messages`}),transformResponse:d({items:m}),extraOptions:{skipError:!0}}),getSelectedAgents:r.query({query:({pId:e})=>({url:`project/${e}/brewer/selected_agents?expand=AGENTS`,method:"GET"}),providesTags:u.providesListItems(a.ProjectTags.SelectedAgent),extraOptions:{skipError:!0}}),createSelectedAgent:r.mutation({query:({pId:e,selectedAgent:t})=>({url:`project/${e}/brewer/selected_agents`,method:"POST",data:t}),invalidatesTags:[{type:a.ProjectTags.SelectedAgent,id:"LIST"}]}),updateSelectedAgent:r.mutation({query:({pId:e,selectedAgentId:t,selectedAgent:s})=>({url:`project/${e}/brewer/selected_agents/${t}`,method:"PUT",data:s}),invalidatesTags:(e,t,{selectedAgentId:s})=>[{type:a.ProjectTags.SelectedAgent,id:s},{type:a.ProjectTags.SelectedAgent,id:"LIST"}]}),deleteSelectedAgent:r.mutation({query:({pId:e,selectedAgentId:t})=>({url:`project/${e}/brewer/selected_agents/${t}`,method:"DELETE"}),invalidatesTags:(e,t,{selectedAgentId:s})=>[{type:a.ProjectTags.SelectedAgent,id:s},{type:a.ProjectTags.SelectedAgent,id:"LIST"}]}),getAllAgents:r.query({query:e=>({url:`brewer/agents${e?`?${o.stringify(e)}`:""}`,method:"GET"}),extraOptions:{skipError:!0}})})}),{useGetChatsQuery:q,useGetChatQuery:f,useCreateChatMutation:w,useGetChatMessagesQuery:C,useDeleteChatMutation:E,useGetSelectedAgentsQuery:v,useCreateSelectedAgentMutation:P,useUpdateSelectedAgentMutation:_,useDeleteSelectedAgentMutation:G,useGetAllAgentsQuery:O,util:k,endpoints:M}=A,$=h.injectEndpoints({endpoints:r=>({getAgentVersions:r.query({query:({pId:e,repoUrl:t})=>({url:`project/${e}/agent-versions?${o.stringify({repo_url:t})}`,method:"GET"})}),getAgentGraph:r.query({query:({pId:e,repoUrl:t,name:s,versionSpecifier:n})=>{const i={repo_url:t,name:s};return n&&(i.version_specifier=n),{url:`project/${e}/agent-graph?${o.stringify(i)}`,method:"GET"}}}),saveAgents:r.mutation({query:({pId:e,repoUrl:t,versionSpecifier:s})=>{const n={repo_url:t};return s&&(n.version_specifier=s),{url:`project/${e}/save-agents?${o.stringify(n)}`,method:"POST"}}}),stopChat:r.mutation({async queryFn({pId:e,chatId:t},s,n,i){try{await i({url:`project/${e}/chat/${t}/stop`,method:"POST"});let g=0;const p=async()=>{const{data:c}=await i({url:`project/${e}/chat/${t}/is-ongoing`}),l=(c==null?void 0:c["is-ongoing"])??!1;if(l&&g<10)return g+=1,await T(2e3),p();if(l)throw new Error(`Chat ${t} is still ongoing after 10 attempts to stop it`);return!0};return await p(),{data:!0}}catch(g){return{error:g}}}})})}),{useStopChatMutation:Q,useGetAgentVersionsQuery:I,useGetAgentGraphQuery:L,useSaveAgentsMutation:x}=$;export{f as a,C as b,w as c,Q as d,M as e,k as f,q as g,E as h,O as i,P as j,_ as k,G as l,I as m,L as n,x as o,v as u};
