From 7472270e1fd630ef50ec23603985ea9678369a58 Mon Sep 17 00:00:00 2001 From: openclaw Date: Mon, 19 Oct 2026 06:35:38 +0000 Subject: [PATCH] fix(auth): support ${ENV_VAR} syntax expansion and prioritize CCLOAD_API_KEY in image provider --- dist/image/index.js | 11 ++++++++--- dist/video/index.js | 7 ++++++- src/image/index.ts | 11 ++++++++--- src/video/index.ts | 7 ++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/dist/image/index.js b/dist/image/index.js index ef05429..2ffec97 100644 --- a/dist/image/index.js +++ b/dist/image/index.js @@ -27,7 +27,12 @@ const SUPPORTED_ASPECT_RATIOS = [ ]; export function resolvePluginApiKey(rawKey) { if (typeof rawKey === "string") { - return normalizeOptionalString(rawKey); + const trimmed = rawKey.trim(); + const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/); + if (envMatch) { + return normalizeOptionalString(process.env[envMatch[1]]); + } + return normalizeOptionalString(trimmed); } if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") { return normalizeOptionalString(process.env[rawKey.id]); @@ -82,8 +87,8 @@ export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured, if (resolvePluginApiKey(pluginCfg?.apiKey) || Boolean(pluginCfg?.apiKey) || normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) || - normalizeOptionalString(process.env.BIFROST_API_KEY) || normalizeOptionalString(process.env.CCLOAD_API_KEY) || + normalizeOptionalString(process.env.BIFROST_API_KEY) || normalizeOptionalString(process.env.OPENAI_API_KEY)) { return true; } @@ -122,8 +127,8 @@ export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured, const pluginCfg = resolveImageConfig(req.cfg, getPluginConfig?.()); const explicitApiKey = resolvePluginApiKey(pluginCfg?.apiKey) ?? normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ?? - normalizeOptionalString(process.env.BIFROST_API_KEY) ?? normalizeOptionalString(process.env.CCLOAD_API_KEY) ?? + normalizeOptionalString(process.env.BIFROST_API_KEY) ?? normalizeOptionalString(process.env.OPENAI_API_KEY); let apiKey = explicitApiKey; if (!apiKey) { diff --git a/dist/video/index.js b/dist/video/index.js index e38e135..158ec77 100644 --- a/dist/video/index.js +++ b/dist/video/index.js @@ -10,7 +10,12 @@ const OPENAI_VIDEO_SECONDS = [4, 8, 12]; const OPENAI_VIDEO_SIZES = ["720x1280", "1280x720", "1024x1792", "1792x1024"]; export function resolvePluginApiKey(rawKey) { if (typeof rawKey === "string") { - return normalizeOptionalString(rawKey); + const trimmed = rawKey.trim(); + const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/); + if (envMatch) { + return normalizeOptionalString(process.env[envMatch[1]]); + } + return normalizeOptionalString(trimmed); } if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") { return normalizeOptionalString(process.env[rawKey.id]); diff --git a/src/image/index.ts b/src/image/index.ts index 8f9a16f..900d75e 100644 --- a/src/image/index.ts +++ b/src/image/index.ts @@ -52,7 +52,12 @@ export interface ImagePluginConfig { export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined { if (typeof rawKey === "string") { - return normalizeOptionalString(rawKey); + const trimmed = rawKey.trim(); + const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/); + if (envMatch) { + return normalizeOptionalString(process.env[envMatch[1]]); + } + return normalizeOptionalString(trimmed); } if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") { return normalizeOptionalString(process.env[rawKey.id]); @@ -133,8 +138,8 @@ export function buildOpenAIImageGenerationProvider({ resolvePluginApiKey(pluginCfg?.apiKey) || Boolean(pluginCfg?.apiKey) || normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) || - normalizeOptionalString(process.env.BIFROST_API_KEY) || normalizeOptionalString(process.env.CCLOAD_API_KEY) || + normalizeOptionalString(process.env.BIFROST_API_KEY) || normalizeOptionalString(process.env.OPENAI_API_KEY) ) { return true; @@ -175,8 +180,8 @@ export function buildOpenAIImageGenerationProvider({ const explicitApiKey = resolvePluginApiKey(pluginCfg?.apiKey) ?? normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ?? - normalizeOptionalString(process.env.BIFROST_API_KEY) ?? normalizeOptionalString(process.env.CCLOAD_API_KEY) ?? + normalizeOptionalString(process.env.BIFROST_API_KEY) ?? normalizeOptionalString(process.env.OPENAI_API_KEY); let apiKey = explicitApiKey; diff --git a/src/video/index.ts b/src/video/index.ts index 4c947c0..cde2f43 100644 --- a/src/video/index.ts +++ b/src/video/index.ts @@ -63,7 +63,12 @@ export interface VideoPluginConfig { export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined { if (typeof rawKey === "string") { - return normalizeOptionalString(rawKey); + const trimmed = rawKey.trim(); + const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/); + if (envMatch) { + return normalizeOptionalString(process.env[envMatch[1]]); + } + return normalizeOptionalString(trimmed); } if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") { return normalizeOptionalString(process.env[rawKey.id]);