var h=Object.defineProperty;var p=(e,t)=>h(e,"name",{value:t,configurable:!0});import{I as g,T as l,j as m,E as n,q as b,e as d}from"../packem_shared/Table-3pFgIUZ2-DABgc6rj.js";import{ReapiRemoteCache as f,resolveTurboEnvCompat as k}from"@visulima/task-runner";import{p as $}from"./bin.js";var w=Object.defineProperty,s=p((e,t)=>w(e,"name",{value:t,configurable:!0}),"s");const y=s((e,t)=>t==="http"||t==="reapi"?t:e.startsWith("grpc://")||e.startsWith("grpcs://")?"reapi":"http","inferBackend"),S=s(async(e,t)=>{const o=Date.now(),a=new AbortController,r=setTimeout(()=>{a.abort()},t);try{const i=await fetch(e,{method:"HEAD",signal:a.signal});return{backend:"http",durationMs:Date.now()-o,httpStatus:i.status,ok:!0,url:e}}catch(i){return{backend:"http",durationMs:Date.now()-o,error:i instanceof Error?i.message:String(i),ok:!1,url:e}}finally{clearTimeout(r)}},"probeHttp"),C=s(async(e,t)=>{const o=Date.now(),a=new f({...e,timeout:t});try{return{backend:"reapi",capabilities:await a.probeCapabilities(),durationMs:Date.now()-o,ok:!0,url:e.url}}catch(r){return{backend:"reapi",durationMs:Date.now()-o,error:r instanceof Error?r.message:String(r),ok:!1,url:e.url}}finally{try{await a.close()}catch{}}},"probeReapi"),D=s(e=>{const t=[],o=e.ok?g("OK"):l("FAIL");if(t.push(`${m("Remote cache")} ${o}`),t.push(`  ${n("URL:")}     ${b(e.url)}`),t.push(`  ${n("Backend:")} ${e.backend}`),t.push(`  ${n("Latency:")} ${String(e.durationMs)}ms`),e.httpStatus!==void 0&&t.push(`  ${n("Status:")}  ${String(e.httpStatus)}`),e.capabilities){const a=e.capabilities.digestFunctions.length>0?e.capabilities.digestFunctions.join(", "):d("(none advertised)");t.push(`  ${n("Digests:")} ${a}`),t.push(`  ${n("Batch:")}   ${String(e.capabilities.maxBatchTotalSizeBytes)} bytes`)}return e.error&&t.push(`  ${n("Error:")}   ${l(e.error)}`),t.join(`
`)},"formatTable"),T=s(async({logger:e,options:t,visConfig:o})=>{const a=k((o??{}).taskRunner?.remoteCache),r=t.url??a?.url,i=t.format??"table",u=t.timeout??5e3;if(!r){$.error("No remote cache configured. Set taskRunner.remoteCache.url in vis.config.ts, pass --url=..., or export TURBO_API."),process.exitCode=1;return}const c=y(r,t.backend)==="reapi"?await C({...a??{url:r},backend:"reapi",url:r},u):await S(r,u);i==="json"?e.log(JSON.stringify(c,null,2)):e.log(D(c)),c.ok||(process.exitCode=1)},"cacheDoctorExecute");export{T as cacheDoctorExecute};
