UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.81 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{dn as t,hn as n,rn as r,xa as i}from"./ui-CmSP4d14.js";import{n as a,t as o}from"./response-body-Cs9VotSw.js";function s(e,n){let o=globalThis.location,s=e.connectionRevision,u=e.connection;if(o?.protocol!==`https:`||r(u.gatewayUrl)!==r(`wss://${o.host}${n}`)||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(),l);try{let t=await fetch(`${n}${c}`,{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`}),l=i(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(t)}},g=n=>{m??=n.client,(e.connectionRevision!==s||n.client!==m||n.phase===`connected`)&&f.abort(),!(p||f.signal.aborted||!n.client||n.phase!==`stopped`||n.lastErrorCode!==t.AUTH_TOKEN_MISSING&&n.lastErrorCode!==t.AUTH_PASSWORD_MISSING)&&(p=!0,h())},_=e.subscribe(g);return g(e.snapshot),()=>{f.abort(),_()}}var c,l;function u(){return(u=e((()=>{n(),o(),c=`/.well-known/openclaw/browser-bootstrap`,l=45e3})))()}u();export{s as startBrowserBootstrapRecovery};