From d5d7c87fd637b5af7945c5bdf9e906a956e619d0 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 26 Jan 2026 17:13:07 +0800 Subject: [PATCH] fix(dialog): support wrapped format for Gemini common config Address audit finding: EditProviderDialog.tsx:121 only parsed flat JSON format, not the wrapped {"env": {...}} format. Changes: - Detect if common config is wrapped or flat format - Extract env object from either format - Properly compute difference for live settings extraction This ensures backward compatibility with existing wrapped-format data. --- src/components/providers/EditProviderDialog.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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; }