import{r as e}from"./chunk-CMxvf4Kt.js";import{t}from"./preload-helper-zJ_50EbN.js";import{r as n}from"./api-base-B9gtivQY.js";import{c as r,d as i,f as a,l as o,r as s,u as c}from"./api-CtGubvBp.js";var l=e({clearTauriAuthFailure:()=>g,getTauriAuthFailure:()=>h,tauriAutoAuth:()=>b}),u=null,d=null,f=`Desktop authentication failed. Update or repair the managed Unsloth install, then restart Unsloth.`,p=`Backend is not ready`;function m(e){return typeof e==`string`&&e?e:e instanceof Error&&e.message?e.message:f}function h(){return d}function g(){d=null}function _(e){d=m(e),window.dispatchEvent(new CustomEvent(`tauri-auth-failed`,{detail:d}))}function v(e){return m(e).includes(p)}async function y(e){if(!e.force&&r()&&!c()||!e.force&&o()&&await s()&&r()&&!c())return g(),!0;try{let{invoke:e}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]),n=await e(`desktop_auth`);return a(n.access_token,n.refresh_token),i(!1),g(),!0}catch(e){return v(e)||_(e),!1}}function b(e={}){if(!n)return Promise.resolve(!1);let t=e.force===!0;if(!u||t&&!u.force){let e;e=y({force:t}).finally(()=>{u?.promise===e&&(u=null)}),u={promise:e,force:t}}return u.promise}export{l as i,h as n,b as r,g as t};