openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 1.89 kB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Kt as t,Un as n,en as r,in as i}from"./control-ui-foundation-Cydpkyqa.js";import{jr as a}from"./control-ui-boot-chat-_QSl8fbH.js";function o(e,i){let o=globalThis.location,l=e.connectionRevision,u=e.connection;if(o?.protocol!==`https:`||t(u.gatewayUrl)!==t(`wss://${o.host}${i}`)||u.token||u.password||u.bootstrapToken)return()=>{};let d=new URL(u.gatewayUrl);if(d.username||d.password||d.hash)return()=>{};let f=new AbortController,p=!1,m=e.snapshot.client,h=async()=>{let t=globalThis.setTimeout(()=>f.abort(),c);try{let t=await fetch(`${i}${s}`,{method:`GET`,headers:{Accept:`application/json`},credentials:`same-origin`,cache:`no-store`,redirect:`error`,signal:f.signal}),r=t.headers.get(`content-type`)?.split(`;`)[0]?.trim().toLowerCase();if(!t.ok||r!==`application/json`){t.body?.cancel().catch(()=>void 0);return}let o=await a(t,{maxBytes:8192,tooLargeMessage:`Browser bootstrap response exceeded its limit`}),c=n(JSON.parse(o));if(!c||Object.keys(c).length!==2||typeof c.bootstrapToken!=`string`||!/^[\x21-\x7e]{1,4096}$/u.test(c.bootstrapToken)||c.bootstrapProfile!==`owner`)return;!f.signal.aborted&&e.connectionRevision===l&&e.snapshot.client===m&&e.snapshot.phase===`stopped`&&e.connect({bootstrapToken:c.bootstrapToken,bootstrapProfile:c.bootstrapProfile})}catch{}finally{globalThis.clearTimeout(t)}},g=t=>{m??=t.client,(e.connectionRevision!==l||t.client!==m||t.phase===`connected`)&&f.abort(),!(p||f.signal.aborted||!t.client||t.phase!==`stopped`||t.lastErrorCode!==r.AUTH_TOKEN_MISSING&&t.lastErrorCode!==r.AUTH_PASSWORD_MISSING)&&(p=!0,h())},_=e.subscribe(g);return g(e.snapshot),()=>{f.abort(),_()}}var s,c;function l(){return(l=e((()=>{i(),s=`/.well-known/openclaw/browser-bootstrap`,c=45e3})))()}l();export{o as startBrowserBootstrapRecovery};
//# sourceMappingURL=browser-bootstrap.runtime-yU444ZS1.js.map