import{t as e}from"./rolldown-runtime-CNxR59P3.js";import{na as t}from"./auth-profiles-qXC1L8hs.js";import{r as n}from"./onboard-helpers-DX-C8lCE.js";import{c as r,s as i}from"./auth-choice.apply-helpers-BmHr2APF.js";import{n as a}from"./widearea-dns-pIf18JCH.js";import{t as o}from"./bonjour-discovery-r6azAoI4.js";var s=e({promptRemoteGatewayConfig:()=>p});const c=`ws://127.0.0.1:18789`;function l(e){return e.host||e.tailnetDns||e.lanHost}function u(e){let t=l(e),n=e.port??e.gatewayPort??18789;return`${e.displayName??e.instanceName} (${t?`${t}:${n}`:`host unknown`})`}function d(e){return e.trim()||c}function f(e){let n=e.trim();if(!n.startsWith(`ws://`)&&!n.startsWith(`wss://`))return`URL must start with ws:// or wss://`;if(!t(n,{allowPrivateWs:process.env.OPENCLAW_ALLOW_INSECURE_PRIVATE_WS===`1`}))return`Use wss:// for remote hosts, or ws://127.0.0.1/localhost via SSH tunnel. Break-glass: OPENCLAW_ALLOW_INSECURE_PRIVATE_WS=1 for trusted private networks.`}async function p(e,t,s){let p=null,m=e.gateway?.remote?.url??c,h=await n(`dns-sd`)||await n(`avahi-browse`),g=h?await t.confirm({message:`Discover gateway on LAN (Bonjour)?`,initialValue:!0}):!1;if(h||await t.note([`Bonjour discovery requires dns-sd (macOS) or avahi-browse (Linux).`,`Docs: https://docs.openclaw.ai/gateway/discovery`].join(`
`),`Discovery`),g){let n=a({configDomain:e.discovery?.wideArea?.domain}),r=t.progress(`Searching for gateways…`),i=await o({timeoutMs:2e3,wideAreaDomain:n});if(r.stop(i.length>0?`Found ${i.length} gateway(s)`:`No gateways found`),i.length>0){let e=await t.select({message:`Select gateway`,options:[...i.map((e,t)=>({value:String(t),label:u(e)})),{value:`manual`,label:`Enter URL manually`}]});if(e!==`manual`){let t=Number.parseInt(String(e),10);p=Number.isFinite(t)?i[t]??null:null}}}if(p){let e=l(p),n=p.port??p.gatewayPort??18789;e&&(await t.select({message:`Connection method`,options:[{value:`direct`,label:`Direct gateway WS (${e}:${n})`},{value:`ssh`,label:`SSH tunnel (loopback)`}]})===`direct`?(m=`wss://${e}:${n}`,await t.note([`Direct remote access defaults to TLS.`,`Using: ${m}`,`If your gateway is loopback-only, choose SSH tunnel and keep ws://127.0.0.1:18789.`].join(`
`),`Direct remote`)):(m=c,await t.note([`Start a tunnel before using the CLI:`,`ssh -N -L 18789:127.0.0.1:18789 <user>@${e}${p.sshPort?` -p ${p.sshPort}`:``}`,`Docs: https://docs.openclaw.ai/gateway/remote`].join(`
`),`SSH tunnel`)))}let _=await t.text({message:`Gateway WebSocket URL`,initialValue:m,validate:e=>f(String(e))}),v=d(String(_)),y=await t.select({message:`Gateway auth`,options:[{value:`token`,label:`Token (recommended)`},{value:`password`,label:`Password`},{value:`off`,label:`No auth`}]}),b=e.gateway?.remote?.token,x=e.gateway?.remote?.password;return y===`token`?(b=await r({prompter:t,explicitMode:s?.secretInputMode,copy:{modeMessage:`How do you want to provide this gateway token?`,plaintextLabel:`Enter token now`,plaintextHint:`Stores the token directly in OpenClaw config`}})===`ref`?(await i({provider:`gateway-remote-token`,config:e,prompter:t,preferredEnvVar:`OPENCLAW_GATEWAY_TOKEN`,copy:{sourceMessage:`Where is this gateway token stored?`,envVarPlaceholder:`OPENCLAW_GATEWAY_TOKEN`}})).ref:String(await t.text({message:`Gateway token`,initialValue:typeof b==`string`?b:void 0,validate:e=>e?.trim()?void 0:`Required`})).trim(),x=void 0):y===`password`?(x=await r({prompter:t,explicitMode:s?.secretInputMode,copy:{modeMessage:`How do you want to provide this gateway password?`,plaintextLabel:`Enter password now`,plaintextHint:`Stores the password directly in OpenClaw config`}})===`ref`?(await i({provider:`gateway-remote-password`,config:e,prompter:t,preferredEnvVar:`OPENCLAW_GATEWAY_PASSWORD`,copy:{sourceMessage:`Where is this gateway password stored?`,envVarPlaceholder:`OPENCLAW_GATEWAY_PASSWORD`}})).ref:String(await t.text({message:`Gateway password`,initialValue:typeof x==`string`?x:void 0,validate:e=>e?.trim()?void 0:`Required`})).trim(),b=void 0):(b=void 0,x=void 0),{...e,gateway:{...e.gateway,mode:`remote`,remote:{url:v,...b===void 0?{}:{token:b},...x===void 0?{}:{password:x}}}}}export{p as n,s as t};
