openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
46 lines (45 loc) • 1.67 kB
TypeScript
/**
* Environment variable substitution for config values.
*
* Supports `${VAR_NAME}` syntax in string values, substituted at config load time.
* - Only uppercase env vars are matched: `[A-Z_][A-Z0-9_]*`
* - Escape with `$${}` to output literal `${}`
* - Missing env vars throw `MissingEnvVarError` with context
*
* @example
* ```json5
* {
* models: {
* providers: {
* "vercel-gateway": {
* apiKey: "${VERCEL_GATEWAY_API_KEY}"
* }
* }
* }
* }
* ```
*/
export declare class MissingEnvVarError extends Error {
readonly varName: string;
readonly configPath: string;
constructor(varName: string, configPath: string);
}
export type EnvSubstitutionWarning = {
varName: string;
configPath: string;
};
export type SubstituteOptions = {
/** When set, missing vars call this instead of throwing and the original placeholder is preserved. */
onMissing?: (warning: EnvSubstitutionWarning) => void;
};
export declare function containsEnvVarReference(value: string): boolean;
/**
* Resolves `${VAR_NAME}` environment variable references in config values.
*
* @param obj - The parsed config object (after JSON5 parse and $include resolution)
* @param env - Environment variables to use for substitution (defaults to process.env)
* @param opts - Options: `onMissing` callback to collect warnings instead of throwing.
* @returns The config object with env vars substituted
* @throws {MissingEnvVarError} If a referenced env var is not set or empty (unless `onMissing` is set)
*/
export declare function resolveConfigEnvVars(obj: unknown, env?: NodeJS.ProcessEnv, opts?: SubstituteOptions): unknown;