import{Y as p}from"./index-WOIPm_2l.js";async function k(){const t=window.astrbotDesktop,r=!!t&&typeof t.isDesktopRuntime=="function",o=!!t&&typeof t.restartBackend=="function"&&r;let s=!!(t!=null&&t.isDesktop);if(r)try{s=s||!!await t.isDesktopRuntime()}catch(e){console.warn("[desktop-runtime] Failed to detect desktop runtime.",e)}return{bridge:t,hasDesktopRuntimeProbe:r,hasDesktopRestartCapability:o,isDesktopRuntime:s}}async function u(t,r){t&&await t.check(r)}async function l(){var t,r;try{const o=await p.get("/api/stat/start-time",{timeout:1500}),s=(r=(t=o==null?void 0:o.data)==null?void 0:t.data)==null?void 0:r.start_time,e=Number(s);return Number.isFinite(e)?e:null}catch{return null}}async function h(t){var e,c;const{bridge:r,hasDesktopRestartCapability:o,isDesktopRuntime:s}=await k();if(r&&o&&s){const i=localStorage.getItem("token"),m=await l();try{const a=r.restartBackend(i);await u(t,m);const n=await a;if(!n.ok)throw(e=t==null?void 0:t.stop)==null||e.call(t),new Error(n.reason||"Failed to restart backend.")}catch(a){throw(c=t==null?void 0:t.stop)==null||c.call(t),a}return}await p.post("/api/stat/restart-core"),await u(t)}export{k as g,h as r};
