UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.34 kB
import{n as resolveCanonicalConfiguredSecretInputWithFallback}from"./resolve-configured-secret-input-string-BVebKi8N.mjs";import{c as trimToUndefined,s as createGatewayCredentialPlan}from"./credentials-BL-kavyD.mjs";import{o as readGatewaySecretInputValue}from"./secret-input-paths-DKW4Nh7w.mjs"; //!src/gateway/auth-surface-resolution.ts function createGatewayCredentialResolver(e){return async t=>{const n=await resolveCanonicalConfiguredSecretInputWithFallback({config:e.config,env:e.env,value:readGatewaySecretInputValue(e.config,t),path:t,unresolvedReasonStyle:`detailed`});if(n.unresolvedRefReason)e.diagnostics.push({message:n.unresolvedRefReason,code:n.unresolvedRefCode});return n}}function withDiagnostics(e,t){return e.length>0?{...t,diagnostics:e.map(({message:e})=>e),...e.some(({code:e})=>e===`SECRET_REF_REDACTED_VALUE`)?{warningCode:`SECRET_REF_REDACTED_VALUE`}:{}}:t}async function resolveGatewayProbeSurfaceAuth(e){const t=e.env??process.env;const n=[];const r=createGatewayCredentialResolver({config:e.config,env:t,diagnostics:n});const i=e.config.gateway?.auth?.mode;if(e.surface===`remote`){const e=await r(`gateway.remote.token`);const i=e.value?{value:void 0,secretRefConfigured:false}:await r(`gateway.remote.password`);const a=trimToUndefined(t.OPENCLAW_GATEWAY_TOKEN);const o=trimToUndefined(t.OPENCLAW_GATEWAY_PASSWORD);const s=Boolean(e.value||i.value);const c=!s&&n.length===0;return withDiagnostics(n,{token:e.value??(c?a:void 0),password:i.value??(c?o:void 0),...s?{source:`config`}:c&&(a||o)&&{source:`env`}})}if(i===`none`||i===`trusted-proxy`)return{};const a=trimToUndefined(t.OPENCLAW_GATEWAY_TOKEN);const o=trimToUndefined(t.OPENCLAW_GATEWAY_PASSWORD);if(i===`token`||i===`password`){const e=await r(`gateway.auth.${i}`);if(e.value)return withDiagnostics(n,{[i]:e.value,source:`config`});const t=i===`token`?a:o;return!e.secretRefConfigured&&t?{[i]:t,source:`env`}:withDiagnostics(n,{})}const s=await r(`gateway.auth.token`);if(s.value)return withDiagnostics(n,{token:s.value,source:`config`});if(s.secretRefConfigured)return withDiagnostics(n,{});const c=await r(`gateway.auth.password`);if(c.secretRefConfigured)return withDiagnostics(n,c.value?{password:c.value,source:`config`}:{});if(a)return{token:a,source:`env`};if(o)return withDiagnostics(n,{password:o,source:`env`});return withDiagnostics(n,{token:s.value,password:c.value,...c.value&&{source:`config`}})}async function resolveGatewayInteractiveSurfaceAuth(e){const t=e.env??process.env;const n=createGatewayCredentialResolver({config:e.config,env:t,diagnostics:[]});const r=trimToUndefined(e.explicitAuth?.token);const i=trimToUndefined(e.explicitAuth?.password);const a=createGatewayCredentialPlan({config:e.config,env:t});const o=e.config.gateway?.auth?.mode;const s=e.surface===`remote`?a.remoteToken.hasSecretRef||a.remotePassword.hasSecretRef:a.localTokenCanWin&&a.localToken.hasSecretRef||(o===`password`||o===void 0)&&a.localPassword.hasSecretRef;if((r||i)&&s)return{token:r,password:i};const c=e.suppressEnvAuthFallback?void 0:trimToUndefined(t.OPENCLAW_GATEWAY_TOKEN);const l=e.suppressEnvAuthFallback?void 0:trimToUndefined(t.OPENCLAW_GATEWAY_PASSWORD);if(e.surface===`remote`){const e=r?{value:r,secretRefConfigured:false}:await n(`gateway.remote.token`);if(e.value&&(e.secretRefConfigured||a.remotePassword.hasSecretRef))return{token:e.value,password:void 0};const t=i?{value:i,secretRefConfigured:false}:await n(`gateway.remote.password`);const o=e.secretRefConfigured||t.secretRefConfigured;const s=e.value??(o?void 0:c);const u=i??(o?t.value:l??t.value);return s||u?{token:s,password:u}:{failureReason:e.unresolvedRefReason??t.unresolvedRefReason??`Missing gateway auth credentials.`}}if(o===`none`||o===`trusted-proxy`)return{token:r??c,password:i??l};const u=o===`password`||o!==`token`&&(Boolean(i??l)&&!a.localToken.hasSecretRef||a.localPassword.configured&&!a.localToken.configured);const d=u?`password`:`token`;const f=u?i:r;const p=u?l:c;const m=f?{value:f,secretRefConfigured:false}:await n(`gateway.auth.${d}`);const h=m.value??(m.secretRefConfigured?void 0:p);return{token:u?m.secretRefConfigured?void 0:r??c:h,password:u?h:m.secretRefConfigured?void 0:i??l,failureReason:h?void 0:m.unresolvedRefReason??`Missing gateway auth ${d}.`}}export{resolveGatewayProbeSurfaceAuth as n,resolveGatewayInteractiveSurfaceAuth as t};