UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.82 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Gi as t,ln as n,pn as r,tn as i}from"./control-ui-foundation-ZY_Flbbd.js";import{n as a,t as o}from"./response-body-krIvH2yK.js";function s(e,r){let o=globalThis.location,s=e.connectionRevision,u=e.connection;if(o?.protocol!==`https:`||i(u.gatewayUrl)!==i(`wss://${o.host}${r}`)||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 n=globalThis.setTimeout(()=>f.abort(),l);try{let n=await fetch(`${r}${c}`,{method:`GET`,headers:{Accept:`application/json`},credentials:`same-origin`,cache:`no-store`,redirect:`error`,signal:f.signal}),i=n.headers.get(`content-type`)?.split(`;`)[0]?.trim().toLowerCase();if(!n.ok||i!==`application/json`){n.body?.cancel().catch(()=>void 0);return}let o=await a(n,{maxBytes:8192,tooLargeMessage:`Browser bootstrap response exceeded its limit`}),l=t(JSON.parse(o));if(!l||Object.keys(l).length!==2||typeof l.bootstrapToken!=`string`||!/^[\x21-\x7e]{1,4096}$/u.test(l.bootstrapToken)||l.bootstrapProfile!==`owner`)return;!f.signal.aborted&&e.connectionRevision===s&&e.snapshot.client===m&&e.snapshot.phase===`stopped`&&e.connect({bootstrapToken:l.bootstrapToken,bootstrapProfile:l.bootstrapProfile})}catch{}finally{globalThis.clearTimeout(n)}},g=t=>{m??=t.client,(e.connectionRevision!==s||t.client!==m||t.phase===`connected`)&&f.abort(),!(p||f.signal.aborted||!t.client||t.phase!==`stopped`||t.lastErrorCode!==n.AUTH_TOKEN_MISSING&&t.lastErrorCode!==n.AUTH_PASSWORD_MISSING)&&(p=!0,h())},_=e.subscribe(g);return g(e.snapshot),()=>{f.abort(),_()}}var c,l;function u(){return(u=e((()=>{r(),o(),c=`/.well-known/openclaw/browser-bootstrap`,l=45e3})))()}u();export{s as startBrowserBootstrapRecovery};