var Q=Object.defineProperty;var g=(e,t,a)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var c=(e,t,a)=>g(e,typeof t!="symbol"?t+"":t,a);import{D as x}from"./vendor-ClLR6ncd.js";import{m as B,q as I}from"./lodash-ZyeDnt0e.js";import{a2 as L,j as M,ax as j,aL as w,ag as P,aR as b,f as q,i as C}from"./index-OtVJl4GC.js";class o extends Error{}class l extends o{}c(l,"indicativeBackendErrorMessage","ask-chat: Incorrect API key provided");class y extends o{}c(y,"indicativeBackendErrorMessage","traverse-serp-jso: Invalid API key");const u=class u extends o{constructor(t){var a;super(t),this._vdb_name=(a=t.match(u.indicativeBackendErrorMessage))==null?void 0:a[1]}};c(u,"indicativeBackendErrorMessage",/An LLM API key has not been provided in db '(.*)' or is invalid$/);let h=u;class v extends o{}c(v,"indicativeBackendErrorMessage",/too many retries, embedding compute failed/);const O=[l,y,h,v];function F(e){try{return JSON.parse(decodeURIComponent(e["x-query-info"]))}catch{return}}const A=e=>()=>{(async()=>{try{await C({method:"delete",url:"/jobs",params:{jobId:e}})}catch(a){console.error("failed to abort job",a)}})()};function G(e,{queryText:t,url:a,params:s}){if(e)return{url:q(a,"graphql"),params:I(s,["default-prefix","infer"]),data:t};const r=new URLSearchParams;return r.append("query",t),{url:a,params:s,data:r}}const H={refetchOnMount:!1,refetchOnReconnect:!1,refetchOnWindowFocus:!1,refetchIntervalInBackground:!1};function J(e){var t,a;if(((t=e==null?void 0:e.response)==null?void 0:t.status)===400||((a=e==null?void 0:e.response)==null?void 0:a.status)===500){const s=e.response.data;if(typeof s=="string"){for(const r of O)if(s.match(r.indicativeBackendErrorMessage))return r}return o}return Error}async function U({urlSuffix:e,queryText:t,queryOptions:a,abortSignal:s,resultType:r}){const d=P({queryLanguage:a==null?void 0:a.queryLn}),i=x();return s==null||s.addEventListener("abort",A(i),{once:!0}),await b({signal:s,method:"post",...G(d,{queryText:t,url:e,params:{...r?{[r]:!0}:{},...a,uuid:i,returnQueryMetadata:!0}})},J)}function W(e,t,{transformResponse:a=B,onSuccess:s,onSettled:r,queryOptions:d,abortSignal:i,onCancel:m,setCurrentQueryType:E,resultType:f,enabled:R=!1,toAvoidRefetch:k=!0}={}){return M(t,async p=>{f&&E(f);const n=await U({urlSuffix:p,queryText:e,queryOptions:d,abortSignal:i,resultType:f});return{...a(n.data),info:F(n.headers)}},{enabled:R,onSuccess:s,onSettled:r,...k?H:{},retry:(p,n)=>j(n)||n instanceof o?!1:w(n)?(m(),!1):p<3})}function z(e,t,a={}){const{queryOptions:s}=L();return W(e,t,Object.assign({queryOptions:s},a))}export{v as E,h as M,l as O,y as S,H as a,z as b,J as e,U as h,W as u};
