Skip to content

fix: image generation with reference image support#52

Open
usexless wants to merge 5 commits into
Zen4-bit:mainfrom
usexless:main
Open

fix: image generation with reference image support#52
usexless wants to merge 5 commits into
Zen4-bit:mainfrom
usexless:main

Conversation

@usexless

@usexless usexless commented Jun 8, 2026

Copy link
Copy Markdown

What this fixes

Image generation returning "No response captured"

When ChatGPT generates an image, it navigates to a new conversation URL and renders the result in a layout that has no [data-message-author-role="assistant"] containers. The existing DOM extraction relied on these containers and returned nothing.

Fix: When no assistant containers are found, fall back to a full-page image search — but exclude uploaded file thumbnails (reference images appear inside BUTTON[aria-haspopup="dialog"] wrappers in the user message, so they are filtered out by walking up the parent chain).

Premature image capture (stop-button guard)

The image appeared in the DOM before ChatGPT finished generating (streaming still in progress). The tool returned an intermediate or wrong result.

Fix: Check for the stop button (button[aria-label*="Stop"]) before returning any image. If visible, return empty and keep polling. Image is only returned once the stop button disappears — i.e. generation is truly complete.

Reference image returned as the generated image

When a local file was uploaded as a style reference, the uploader's thumbnail appeared in the DOM immediately. The old bigImgs fallback picked it up before ChatGPT had generated anything.

Fix: isInsideDialogButton() traversal — any image found inside a dialog-trigger button is skipped as a reference thumbnail, not a generated result.

New feature: reference_image parameter

generate_image now accepts an optional reference_image (absolute local file path). The engine uploads it to ChatGPT before sending the prompt, allowing style-consistent multi-image generation.

generate_image tool description

Rewrote the MCP tool description so AI clients know:

  • Call new_conversation before each image (prevents context bleed / stale returns)
  • Generate one image at a time — never parallel
  • Be patient: tool blocks 30–90 s while generating
  • Prompt structure guide: [subject], [action], [setting], [lighting], [style], [quality]

Files changed

  • electron/main-v2.cjs — DOM image extraction, stop-button guard, isInsideDialogButton(), postProcessImages(), downloadImageWithSession()
  • src/mcp-server-v3.jsgenerate_image tool description + reference_image param
  • NOTES.md — architecture docs and fix log (new file)

Tested

  • Text-only image generation → correct image returned
  • Image generation with reference_image → newly generated image returned, not the uploaded file
  • Stop-button guard → waits for full completion before capturing

usexless and others added 5 commits May 25, 2026 22:20
- main-v2.cjs: fix image gen DOM extraction for ChatGPT reasoning UI
  - Added dalleImgs + bigImgs fallback for images outside assistant containers
  - Stop-button guard: only return image when ChatGPT fully done generating
  - Reference image false-positive fix: exclude BUTTON[aria-haspopup=dialog] wrappers
  - Added "Thought for X s" detection in diagnostic logging
  - postProcessImages(): download signed ChatGPT URLs via session cookies → local file
  - downloadImageWithSession() via electronNet with useSessionCookies
  - chatgptOldImageUrls pre-send snapshot to filter stale sidebar thumbnails
- rest-api.cjs: add Perplexity model aliases (sonar-pro, sonar-reasoning, r1-1776, etc.)
- mcp-server-v3.js: generate_image tool — remove DALL-E mention, add patience/flow
  instructions, prompt structure guide, reference_image param for style consistency
- NOTES.md: architecture docs, fix log, critical workflow notes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@qodo-code-review

qodo-code-review Bot commented Jun 8, 2026

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant