openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
94 lines (93 loc) • 3.62 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { _ as resolveSecretInputRef, o as hasConfiguredSecretInput } from "./types.secrets-BmNLLnHp.mjs";
import { n as containsEnvVarReference } from "./env-substitution-CgVeOqUd.mjs";
import { c as getAuthoredConfigSecretRef, d as hasUnresolvedConfigPath, l as getConfigResolutionFacts } from "./resolution-facts-xaIKuREs.mjs";
//#region src/gateway/credential-planner.ts
const trimToUndefined = normalizeOptionalString;
/**
* Like trimToUndefined but also rejects unresolved env var placeholders (e.g. `${VAR}`).
* This prevents literal placeholder strings like `${OPENCLAW_GATEWAY_TOKEN}` from being
* accepted as valid credentials when the referenced env var is missing.
* Note: legitimate credential values containing literal `${UPPER_CASE}` patterns will
* also be rejected, but this is an extremely unlikely edge case.
*/
function trimCredentialToUndefined(e) {
const t = trimToUndefined(e);
if (t && containsEnvVarReference(t)) return;
return t;
}
function createGatewayCredentialPlan(e) {
const t = e.env ?? process.env;
const n = e.config.gateway;
const r = n?.remote;
const i = e.defaults ?? e.config.secrets?.defaults;
const a = n?.auth?.mode;
const o = trimToUndefined(t.OPENCLAW_GATEWAY_TOKEN);
const s = trimToUndefined(t.OPENCLAW_GATEWAY_PASSWORD);
function resolveInput(t, n) {
const r = getConfigResolutionFacts(e.config);
if (hasUnresolvedConfigPath(e.config, t) || getAuthoredConfigSecretRef(e.config, t)) return {
path: t,
configured: true,
refPath: t,
hasSecretRef: false
};
if (r !== null && typeof n === "string") return {
path: t,
configured: Boolean(trimToUndefined(n)),
value: trimToUndefined(n),
hasSecretRef: false
};
const a = resolveSecretInputRef({
value: n,
defaults: i
}).ref;
return {
path: t,
configured: hasConfiguredSecretInput(n, i),
value: a ? void 0 : trimToUndefined(n),
refPath: a ? t : void 0,
hasSecretRef: a !== null
};
}
const c = resolveInput("gateway.auth.token", n?.auth?.token);
const l = resolveInput("gateway.auth.password", n?.auth?.password);
const u = resolveInput("gateway.remote.token", r?.token);
const d = resolveInput("gateway.remote.password", r?.password);
const f = a !== "password" && a !== "none" && a !== "trusted-proxy";
const p = a === "password" || a === "trusted-proxy" || a !== "token" && a !== "none" && !(o || c.configured);
const m = Boolean(o || c.configured || u.configured);
const h = a === "password" || a === "trusted-proxy" || a !== "token" && a !== "none" && !m;
const g = f && (a === "token" || a === void 0 && !(s || l.configured));
const _ = n?.mode === "remote";
const v = Boolean(trimToUndefined(r?.url));
const y = n?.tailscale?.mode === "serve" || n?.tailscale?.mode === "funnel";
const b = _ || v || y;
const x = f && !o && !c.configured;
const S = a !== "trusted-proxy" && !s && !l.configured && h;
return {
configuredMode: n?.mode === "remote" ? "remote" : "local",
authMode: a,
envToken: o,
envPassword: s,
localToken: c,
localPassword: l,
remoteToken: u,
remotePassword: d,
localTokenCanWin: f,
localPasswordCanWin: p,
localTokenSurfaceActive: g,
tokenCanWin: m,
passwordCanWin: h,
remoteMode: _,
remoteUrlConfigured: v,
tailscaleRemoteExposure: y,
remoteConfiguredSurface: b,
remoteTokenFallbackActive: x,
remoteTokenActive: b || x,
remotePasswordFallbackActive: S,
remotePasswordActive: b || S
};
}
//#endregion
export { trimCredentialToUndefined as n, trimToUndefined as r, createGatewayCredentialPlan as t };