import{t as e}from"./subsystem-kTFXkQM5.js";import"./paths-BjD3T_xq.js";import"./boolean-D15s2V33.js";import{Br as t,Cr as n,Hr as r,Qr as i,Sr as a,Ti as o,Vr as s,jo as c,wi as l,xr as u}from"./auth-profiles-qXC1L8hs.js";import"./agent-scope-BKE4M04k.js";import"./utils-7Gdj77QB.js";import"./openclaw-root-CnsBf6ZU.js";import"./github-copilot-token-C79yeDKS.js";import"./env-overrides-R4odAlsj.js";import"./version-q3SkUw2K.js";import"./registry-Div2nEwi.js";import"./skills-Df0CxTMH.js";import"./frontmatter-C7mzDNxd.js";import"./plugins-CCU8jDti.js";import"./logger-C1GUBMt-.js";import"./exec-CiwCrGw3.js";import"./windows-spawn-Dw4dpTt2.js";import"./redact-bVcVj47r.js";import"./path-alias-guards-kY_ZbWs-.js";import"./errors-DNQO70y-.js";import"./paths-BfjJY2VL.js";import"./chat-envelope-Bznn2SoS.js";import d from"express";let f=null;const p=e(`browser`).child(`server`);async function m(){if(f)return f;let e=c(),s=i(e.browser,e);if(!s.enabled)return null;let m=o(e),h=!1;try{let t=await l({cfg:e});m=t.auth,t.generatedToken&&p.info(`No browser auth configured; generated gateway.auth.token automatically.`)}catch(e){p.warn(`failed to auto-configure browser auth: ${String(e)}`),h=!0}if(h&&!m.token&&!m.password)return p.error(`browser control startup aborted: authentication bootstrap failed and no fallback auth is configured.`),null;let g=d();a(g),u(g,m),n(g,r({getState:()=>f,refreshConfigFromDisk:!0}));let _=s.controlPort,v=await new Promise((e,t)=>{let n=g.listen(_,`127.0.0.1`,()=>e(n));n.once(`error`,t)}).catch(e=>(p.error(`openclaw browser server failed to bind 127.0.0.1:${_}: ${String(e)}`),null));if(!v)return null;f=await t({server:v,port:_,resolved:s,onWarn:e=>p.warn(e)});let y=m.token?`token`:m.password?`password`:`off`;return p.info(`Browser control listening on http://127.0.0.1:${_}/ (auth=${y})`),f}async function h(){await s({current:f,getState:()=>f,clearState:()=>{f=null},closeServer:!0,onWarn:e=>p.warn(e)})}export{m as startBrowserControlServerFromConfig,h as stopBrowserControlServer};
