import{Wo as e}from"./app-server-manager-signals-Yn0WSnoY.js";import{W as t,g as n,h as r}from"./vscode-api-DjORcpSo.js";import{n as i}from"./rpc-CJwVeoy_.js";var a=new Map,o=Promise.resolve();function s(){return a.size>0}function c({hostId:e}){let t=i.primaryRuntime;return t==null?Promise.reject(Error(`Primary runtime is unavailable`)):Promise.resolve(t.cancelInstall({hostId:e}))}function l({hostId:e,request:t,release:n}){let r=JSON.stringify({hostId:e,release:n}),s=a.get(r);if(s!=null)return s;let c=o.then(()=>{let r=i.primaryRuntime;if(r==null)throw Error(`Primary runtime is unavailable`);return r[t]({hostId:e,release:n})});return a.set(r,c),o=c.then(()=>void 0,()=>void 0),c.finally(()=>{a.delete(r)}).catch(()=>void 0),c}var u=t(r,null),d=t(r,`latest`),f=9e4;function p(e){switch(e?.phase){case void 0:case`ready`:case`error`:return!1;case`checking`:case`downloading`:case`verifying`:case`extracting`:case`validating`:case`installed`:case`configuring`:return!0}}async function m({hostId:t=e,release:n=`latest`}={}){await l({hostId:t,release:n,request:`finishInstall`})}async function h({hostId:t=e,release:r=`latest`}={}){let i=m({hostId:t,release:r}),a;try{await Promise.race([i.then(()=>`ready`),new Promise(e=>{a=window.setTimeout(()=>e(`timeout`),f)})])===`timeout`&&(n.warning(`Primary runtime install timed out before first turn`,{safe:{timeoutMs:f},sensitive:{}}),i.catch(e=>{n.error(`Primary runtime install failed after first-turn timeout`,{safe:{},sensitive:{error:e}})}))}catch(e){n.error(`Primary runtime install failed before first turn`,{safe:{},sensitive:{error:e}})}finally{a!=null&&window.clearTimeout(a)}}export{c as a,u as i,p as n,s as o,d as r,l as s,h as t};
//# sourceMappingURL=primary-runtime-install-state-B0daRQaC.js.map