UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) 2.22 kB
import { a as normalizeLowercaseStringOrEmpty } from "./string-coerce-mnp54Vah.js"; //#region src/infra/env.ts let log = null; let logPromise = null; const loggedEnv = /* @__PURE__ */ new Set(); async function getLog() { if (!log) { logPromise ??= import("./subsystem-Ck78B-rV.js").then(({ createSubsystemLogger }) => createSubsystemLogger("env")); log = await logPromise; } return log; } function formatEnvValue(value, redact) { if (redact) return "<redacted>"; const singleLine = value.replace(/\s+/g, " ").trim(); if (singleLine.length <= 160) return singleLine; return `${singleLine.slice(0, 160)}…`; } /** Logs an accepted env option once, with optional redaction for sensitive values. */ function logAcceptedEnvOption(option) { if (process.env.VITEST || false) return; if (loggedEnv.has(option.key)) return; const rawValue = option.value ?? process.env[option.key]; if (!rawValue || !rawValue.trim()) return; loggedEnv.add(option.key); getLog().then((logger) => { logger.info(`env: ${option.key}=${formatEnvValue(rawValue, option.redact)} (${option.description})`); }).catch(() => {}); } /** Normalizes the legacy Z_AI_API_KEY spelling into the canonical ZAI_API_KEY env var. */ function normalizeZaiEnv() { if (!process.env.ZAI_API_KEY?.trim() && process.env.Z_AI_API_KEY?.trim()) process.env.ZAI_API_KEY = process.env.Z_AI_API_KEY; } /** Interprets common human/operator truthy env strings. */ function isTruthyEnvValue(value) { if (typeof value !== "string") return false; switch (normalizeLowercaseStringOrEmpty(value)) { case "1": case "on": case "true": case "yes": return true; default: return false; } } /** Detects Vitest/test execution from the env shape used by local and worker processes. */ function isVitestRuntimeEnv(env = process.env) { return env.VITEST === "true" || env.VITEST === "1" || env.VITEST_POOL_ID !== void 0 || env.VITEST_WORKER_ID !== void 0 || env.NODE_ENV === "test"; } /** Applies process-wide env normalization before runtime configuration is read. */ function normalizeEnv() { normalizeZaiEnv(); } //#endregion export { normalizeZaiEnv as a, normalizeEnv as i, isVitestRuntimeEnv as n, logAcceptedEnvOption as r, isTruthyEnvValue as t };