UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

6 lines • 6.32 kB
import{a as isWssUrl}from"./url-protocol-BLfSvQhh.mjs";import{o as requireTlsFingerprint}from"./client-address-utils-CIkL4kpz.mjs";import{c as trimToUndefined,r as resolveExplicitGatewayAuth}from"./credentials-BL-kavyD.mjs";import{t as resolveGatewayPublicOrigin}from"./gateway-public-origin-BbL1ndHu.mjs";import{t as normalizeControlUiBasePath}from"./control-ui-shared-Ch8iHnEl.mjs";import{n as buildGatewayConnectionDetailsWithResolvers,o as resolveGatewayDeviceAuthRoute}from"./connection-details-CL6thwAz.mjs";import{n as resolveGatewayProbeSurfaceAuth,t as resolveGatewayInteractiveSurfaceAuth}from"./auth-surface-resolution-BnZxc5Ql.mjs";import{n as resolveGatewayCredentialsWithSecretInputs}from"./credentials-secret-inputs-CK6zIfEz.mjs";import{t as gatewayEdgeAuthValueForTarget}from"./edge-auth-xjMGW-UQ.mjs"; //!src/gateway/tls-fingerprint.ts async function resolveGatewayConnectionTlsFingerprint(e){const t=e.explicitTlsFingerprint?requireTlsFingerprint(e.explicitTlsFingerprint):void 0;if(t)return t;const n=e.config.gateway?.mode===`remote`&&(e.urlSource===`config gateway.remote.url`||e.urlSource===`env OPENCLAW_GATEWAY_URL`)?e.config.gateway.remote?.tlsFingerprint?requireTlsFingerprint(e.config.gateway.remote.tlsFingerprint):void 0:void 0;if(n)return n;if(!isWssUrl(e.url))return;if(!(e.urlSource===`local loopback`||e.urlSource===`missing gateway.remote.url (fallback local)`)||e.config.gateway?.tls?.enabled!==true)return;const{inspectGatewayTlsCertificate:r}=await import(`./gateway-DYX9nAy1.mjs`);const i=await r(e.config.gateway.tls);return i.ok?i.value.fingerprintSha256:void 0} //!src/gateway/client-bootstrap.ts var GatewayExplicitAuthRequiredError=class extends Error{constructor(e){super(e);this.name=`GatewayExplicitAuthRequiredError`}};async function ensureExplicitGatewayAuth(e){if(!e.urlOverride||!e.urlOverrideSource)return;if(e.explicitAuth?.token||e.explicitAuth?.password)return;if(e.urlOverrideSource===`env`&&(e.resolvedAuth?.token||e.resolvedAuth?.password))return;if(e.deviceAuthScope&&await e.allowStoredOriginAuth?.(e.deviceAuthScope)===true)return;const t=e.urlOverrideSource===`env`?`Set OPENCLAW_GATEWAY_TOKEN or OPENCLAW_GATEWAY_PASSWORD alongside OPENCLAW_GATEWAY_URL; config credentials are intentionally not reused.`:`For the default local or SSH-tunneled Gateway, remove --url to use the configured target.`;throw new GatewayExplicitAuthRequiredError([`gateway url override requires explicit credentials`,e.errorHint,t,e.configPath?`Config: ${e.configPath}`:void 0].filter(Boolean).join(` `))}function resolveGatewayUrlOverride(e){const t=trimToUndefined(e.gatewayUrl);if(t)return{url:t,source:`cli`};if(e.ignoreEnvUrlOverride||e.localPortOverride!==void 0)return{};const n=trimToUndefined((e.env??process.env).OPENCLAW_GATEWAY_URL);return n?{url:n,source:`env`}:{}}async function resolveGatewayClientBootstrap(e){const t=e.env??process.env;const n=resolveExplicitGatewayAuth(e.explicitAuth);const r=resolveGatewayUrlOverride({gatewayUrl:e.gatewayUrl,env:t,ignoreEnvUrlOverride:e.ignoreEnvUrlOverride,localPortOverride:e.localPortOverride});const i=e.buildConnectionDetails??buildGatewayConnectionDetailsWithResolvers;const a=i({config:e.config,url:r.url,...e.configPath?{configPath:e.configPath}:{},...r.source?{urlSource:r.source}:{},ignoreEnvUrlOverride:true,...e.localPortOverride!==void 0?{localPortOverride:e.localPortOverride}:{},...e.serviceTargetUrl?{serviceTargetUrl:e.serviceTargetUrl}:{}});const o=a.urlSource===`cli --url`?`cli`:a.urlSource===`env OPENCLAW_GATEWAY_URL`?`env`:void 0;const s=r.source??o;let c;if(e.allowConfiguredAuthForExactTarget&&s===`cli`){if(e.config.gateway?.mode===`remote`){const t=trimToUndefined(e.config.gateway.remote?.url);if(t&&t===a.url)c={authSurface:`remote`,tlsSource:`config gateway.remote.url`}}else{const t={...e.config.gateway,mode:`local`};delete t.remote;const n=i({config:{...e.config,gateway:t},ignoreEnvUrlOverride:true,...e.localPortOverride!==void 0?{localPortOverride:e.localPortOverride}:{}}).url;const r=normalizeControlUiBasePath(e.config.gateway?.controlUi?.basePath??``);if(`${n}${r}`===a.url)c={authSurface:`local`,tlsSource:`local loopback`};else{const t=resolveGatewayPublicOrigin(e.config);if(t&&`${t.replace(/^https:/u,`wss:`).replace(/^http:/u,`ws:`)}${r}`===a.url)c={authSurface:`local`}}}}const l=c?.tlsSource??a.urlSource;const u=await resolveGatewayConnectionTlsFingerprint({config:e.config,url:a.url,urlSource:l,explicitTlsFingerprint:e.explicitTlsFingerprint});const d=c?.authSurface??e.modeOverride??(e.localPortOverride!==void 0?`local`:e.config.gateway?.mode===`remote`?`remote`:`local`);let f;if(e.skipImplicitAuth)f=n;else if(s&&!c)f=e.suppressEnvAuthFallback?n:await resolveGatewayCredentialsWithSecretInputs({config:e.config,explicitAuth:n,env:t,urlOverride:a.url,urlOverrideSource:s,modeOverride:e.modeOverride});else if(e.authPolicy===`probe`)f=await resolveGatewayProbeSurfaceAuth({config:e.config,env:t,surface:d});else if(e.authPolicy===`interactive`)f=await resolveGatewayInteractiveSurfaceAuth({config:e.config,env:t,explicitAuth:n,suppressEnvAuthFallback:e.suppressEnvAuthFallback,surface:d});else f=await resolveGatewayCredentialsWithSecretInputs({config:e.config,explicitAuth:n,env:t,urlOverride:s?a.url:void 0,urlOverrideSource:s,modeOverride:d});const{deviceAuthScope:p,sshTunnel:m}=resolveGatewayDeviceAuthRoute({config:e.config,url:a.url,remote:Boolean(s||a.urlSource===`config gateway.remote.url`),configuredRemote:!s&&a.urlSource===`config gateway.remote.url`||c?.authSurface===`remote`,tlsFingerprint:u});const h=gatewayEdgeAuthValueForTarget({config:e.config,targetUrl:a.url})!==void 0;if(e.overrideAuthErrorHint&&!c&&!h)await ensureExplicitGatewayAuth({urlOverride:s?a.url:void 0,urlOverrideSource:s,explicitAuth:n,resolvedAuth:f,deviceAuthScope:p,allowStoredOriginAuth:e.allowStoredOriginAuth,errorHint:e.overrideAuthErrorHint,configPath:e.configPath});return{url:a.url,urlSource:a.urlSource,connectionDetails:a,...s?{urlOverrideSource:s}:{},...p?{deviceAuthScope:p}:{},...m?{sshTunnel:m}:{},...f.failureReason?{authFailureReason:f.failureReason}:{},...u?{tlsFingerprint:u}:{},auth:{token:f.token,password:f.password}}}export{resolveGatewayUrlOverride as i,ensureExplicitGatewayAuth as n,resolveGatewayClientBootstrap as r,GatewayExplicitAuthRequiredError as t};