diff --git a/src/components/providers/EditProviderDialog.tsx b/src/components/providers/EditProviderDialog.tsx index cfea4ec18..45baadb36 100644 --- a/src/components/providers/EditProviderDialog.tsx +++ b/src/components/providers/EditProviderDialog.tsx @@ -114,16 +114,24 @@ export function EditProviderDialog({ setLiveSettings(live); } } else if (appId === "gemini") { - // Gemini: common config is stored as JSON {"KEY": "VALUE"} format + // Gemini: common config supports two formats: + // - Flat JSON: {"KEY": "VALUE", ...} + // - Wrapped JSON: {"env": {"KEY": "VALUE", ...}} const liveEnv = (live as { env?: Record }).env ?? {}; - // Parse common config as JSON - const commonEnvObj = JSON.parse( + // Parse common config as JSON with format detection + const parsedSnippet = JSON.parse( commonSnippet.trim(), ) as Record; + // Check if wrapped format {"env": {...}} + const commonEnvRaw = + parsedSnippet.env && + typeof parsedSnippet.env === "object" + ? (parsedSnippet.env as Record) + : parsedSnippet; // Convert to string record, filtering out non-string values const commonEnvStrObj: Record = {}; - for (const [key, value] of Object.entries(commonEnvObj)) { + for (const [key, value] of Object.entries(commonEnvRaw)) { if (typeof value === "string") { commonEnvStrObj[key] = value; }