"use client";
import e from"axios";import{createContext as t,useContext as n,useMemo as r,useRef as i}from"react";import{jsx as a}from"react/jsx-runtime";const o={rowCount:e=>[`row_count`,e],lineage:()=>[`lineage`],checks:()=>[`checks`,`list`],check:e=>[`checks`,e],checkEvents:e=>[`checks`,e,`events`],runs:()=>[`runs`],run:e=>[`runs`,e],runsAggregated:()=>[`runs_aggregated`],flag:()=>[`flag`],instanceInfo:()=>[`instance_info`],user:()=>[`user`]},s=t(null);s.displayName=`RecceApiContext`;function c(){let e=n(s);if(!e)throw Error(`useApiConfig must be used within RecceProvider`);return e}function l(){return n(s)}function u(){return c().apiClient}function d(e){let t=i(e),n=i(e?JSON.stringify(e):``),r=e?JSON.stringify(e):``;return r!==n.current&&(t.current=e,n.current=r),t.current}function f(t,n,r,i,a){let o=e.create({baseURL:t,headers:i,timeout:a});return(n||r)&&o.interceptors.request.use(e=>{try{return n&&e.url&&(e.url===`/api`?e.url=n:e.url.startsWith(`/api/`)&&(e.url=n+e.url.slice(4))),r&&(e.headers.Authorization=`Bearer ${r}`),e}catch(t){return console.warn(`API request interceptor error, proceeding with unmodified request:`,t),e}},e=>Promise.reject(e)),o}function p({children:e,config:t}){let n=`client`in t,i=n?t.client:null,o=n?t.baseUrl??``:t.baseUrl,c=n?void 0:t.timeout,l=n?void 0:t.headers,u=t.apiPrefix??``,p=t.authToken,m=d(l),h=r(()=>i||f(o,u,p,m,c??3e4),[i,o,u,p,m,c]),g=r(()=>({apiClient:h,apiPrefix:u,authToken:p,baseUrl:o}),[h,u,p,o]);return a(s.Provider,{value:g,children:e})}async function m(e){return(await e.get(`/api/flag`)).data}async function h(e){try{await e.post(`/api/relaunch-hint/completed`)}catch{}}async function g(e){return(await e.get(`/api/instance-info`)).data}function _(){return typeof window<`u`&&!!window.RECCE_DEBUG_IDLE}let v=0,y=!1,b=null;function x(e){b=e}async function S(e){if(Date.now()-v<3e3||y)return!1;try{return y=!0,await e.post(`/api/keep-alive`),v=Date.now(),b&&b(v),!0}catch(e){if(_()){let t=e instanceof Error?e.message:String(e);console.log(`[Keep-Alive] Failed to send`,{error:t,timestamp:new Date().toISOString(),willRetryOnNextActivity:!0})}return!1}finally{y=!1}}function C(){return v}function w(){v=0,y=!1,b=null}export{g as a,p as c,l as d,o as f,x as i,u as l,w as n,m as o,S as r,h as s,C as t,c as u};
//# sourceMappingURL=keepAlive-DHpmpKwK.js.map