UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.48 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{a as createGatewayEnvSecretRef}from"./ref-contract-CdpCUlb6.mjs";import{_ as resolveSecretInputRef}from"./types.secrets-UWdyCdE6.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{t as randomToken}from"./random-token-CWOnwMog.mjs";import{s as normalizeGatewayTokenInput}from"./onboard-helpers-jemdbXwD.mjs";import{t as validateDottedDecimalIPv4Input}from"./ipv4-BFG40n7h.mjs";import{t as rejectOnboardingOption}from"./onboard-options-CnOGFxfd.mjs";import{t as provisionGatewayTokenStoreRef}from"./auth-token-store-ref-PaTq_X8D.mjs"; //!src/commands/onboard-non-interactive/local/gateway-config.ts async function applyNonInteractiveGatewayConfig(e){const{opts:t,runtime:n}=e;const reject=e=>{rejectOnboardingOption(t,n,e);return null};const r=e.nextConfig.gateway;const i=t.gatewayPort??e.defaultPort;let a=t.gatewayBind??r?.bind??`loopback`;const o=t.gatewayAuth;const s=t.gatewayToken!==void 0||t.gatewayTokenRefEnv!==void 0;let c=o??(s?`token`:t.gatewayPassword!==void 0?`password`:r?.auth?.mode)??`token`;const l=t.tailscale??r?.tailscale?.mode??`off`;if((t.gatewayBind!==void 0||t.tailscale!==void 0)&&l!==`off`&&a!==`loopback`)a=`loopback`;if(a===`custom`){const e=validateDottedDecimalIPv4Input(normalizeOptionalString(r?.customBindHost??``));if(e)return reject(`--gateway-bind custom requires gateway.customBindHost: ${e}. Set it with ${formatCliCommand(`openclaw config set gateway.customBindHost <ipv4>`)} and rerun, or run ${formatCliCommand(`openclaw onboard`)} interactively to be prompted for it.`)}const u=o!==void 0||s||t.tailscale!==void 0;if(u&&l===`serve`&&c===`none`)c=`token`;if(u&&l===`funnel`&&c!==`password`){if(c===`trusted-proxy`)return reject(`Tailscale Funnel requires password auth, but the Gateway is configured with "trusted-proxy" auth. Re-run with --gateway-auth password to switch, or keep Tailscale exposure off.`);c=`password`}const d=e.nextConfig;let f=r?.auth;const p=normalizeGatewayTokenInput(t.gatewayToken);const m=normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN);const h=d.gateway?.auth?.token;const g=resolveSecretInputRef({value:h,defaults:d.secrets?.defaults}).ref;const _=normalizeGatewayTokenInput(h);const v=p||_||m||void 0;const y=normalizeOptionalString(t.gatewayTokenRefEnv??``)??``;if(c===`token`){f={...f,mode:`token`};if(y){if(!process.env[y]?.trim())return reject(`Environment variable "${y}" is missing or empty. Export it first, then rerun ${formatCliCommand(`openclaw onboard --non-interactive`)}.`);f.token=createGatewayEnvSecretRef(d,y)}else if(p||!g){if(t.secretInputMode!==`ref`)f.token=v??randomToken();else if(!p&&!_&&m)f.token=createGatewayEnvSecretRef(d,`OPENCLAW_GATEWAY_TOKEN`);else f.token=(await provisionGatewayTokenStoreRef({config:d,...v?{token:v}:{}})).ref}}if(c===`password`){const e=t.gatewayPassword;const n=e===void 0?d.gateway?.auth?.password??normalizeOptionalString(process.env.OPENCLAW_GATEWAY_PASSWORD):normalizeOptionalString(e);if(!n)return reject(`Missing --gateway-password for password auth. Pass --gateway-password or use --gateway-auth token.`);f={...f,mode:`password`,...e!==void 0?{password:t.secretInputMode===`ref`?createGatewayEnvSecretRef(d,`OPENCLAW_GATEWAY_PASSWORD`):n}:{}}}return{nextConfig:{...d,gateway:{...r,...f?{auth:f}:{},port:i,bind:a,tailscale:{...r?.tailscale,mode:l}}},port:i,bind:a,authMode:c,tailscaleMode:l}}export{applyNonInteractiveGatewayConfig as t};