From 516803feb40e7b3d31096e9d6b69e580ef823854 Mon Sep 17 00:00:00 2001 From: evilstar2016 Date: Wed, 6 May 2026 18:48:08 +0900 Subject: [PATCH] fix(gemini-webapi): add fallback scan for generated images when wants_generated fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `wants_generated` detection checks `candidate[12][7][0]` and an old `googleusercontent.com/image_generation_content/` URL pattern in the response text. Both are no longer present in the current Gemini Web API response format, causing the entire generated-image extraction block to be skipped even when Gemini successfully generates images — resulting in "No image returned in response" errors. Generated image URLs now appear as `https://lh3.googleusercontent.com/gg-dl/` somewhere in the response parts. This commit adds an unconditional fallback that scans all response parts for those URLs when `generated_images` is still empty after the existing `wants_generated` block, reusing the already-present `collect_strings` helper and `GeneratedImage` constructor. The existing code path is untouched — the fallback only runs when no images were found through the original logic, so old response formats continue to work. --- .../scripts/gemini-webapi/client.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/client.ts b/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/client.ts index 6603511..a7afd4b 100644 --- a/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/client.ts +++ b/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/client.ts @@ -459,6 +459,32 @@ export class GeminiClient extends GemMixin { } } + // Fallback: unconditionally scan all response parts for generated image URLs. + // The `wants_generated` detection above relies on `candidate[12][7][0]` and an old + // `googleusercontent.com/image_generation_content/` URL pattern, both of which no + // longer appear in the current Gemini Web API response format. + // When Gemini does generate images, their URLs now start with + // `https://lh3.googleusercontent.com/gg-dl/` and are present somewhere in the + // response parts — this fallback finds them so images are not silently dropped. + if (generated_images.length === 0) { + for (let part_index = body_index; part_index < (response_json as unknown[]).length; part_index++) { + const part = (response_json as unknown[])[part_index]; + if (!Array.isArray(part)) continue; + const part_body = get_nested_value(part, [2], null); + if (!part_body) continue; + try { + const part_json = JSON.parse(part_body) as unknown[]; + const cand = get_nested_value(part_json, [4, candidate_index], null); + if (!cand) continue; + const urls = collect_strings(cand, (s) => s.startsWith('https://lh3.googleusercontent.com/gg-dl/'), 4); + for (const url of urls) { + generated_images.push(new GeneratedImage(url, '[Generated Image]', '', this.proxy, this.cookies)); + } + if (generated_images.length > 0) break; + } catch {} + } + } + out.push(new Candidate({ rcid, text, thoughts, web_images, generated_images })); }