-
-
Notifications
You must be signed in to change notification settings - Fork 19
BL-16523 AI Image Editor: whole-book AI image editing + per-user OpenRouter key #8033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hatton
wants to merge
20
commits into
master
Choose a base branch
from
AddAIImages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8c585c7
AI Image Editor: whole-book image enumeration + book-wide replacement
hatton 3dd5687
Document AiImageEditorApi and remove the vestigial C# frame-message path
hatton ddf7be0
Merge remote-tracking branch 'origin/master' into AddAIImages
hatton da81d80
AI Image Editor: per-user OpenRouter key storage + serve editor from …
hatton 3046752
go.sh --with: develop local library checkouts alongside Bloom
hatton 1407bb6
go/dev: stage jQuery global in dev; make --with iframe-app startup wa…
hatton 4be4735
AI Image Editor: document public RegisterWithApiHandler (preflight)
hatton 87f4b36
Merge origin/master into AddAIImages (D5)
hatton c22c67f
AI Image Editor: apply preflight review decisions (D2-D4, F2-F5)
hatton 118aa43
AI Image Editor: robustness, image-replacement matching, and dev-laun…
hatton 3682c87
Merge remote-tracking branch 'origin/master' into AddAIImages
hatton 87637f8
AI Image Editor: clean up orphaned ai-image files; localize menu item…
hatton 5b5c881
AI Image Editor: fix CORS preflight, document OAuth reflection, test …
hatton 0ad16c6
AI Image Editor: add host-side tests; extract testable helpers (BL-16…
hatton aa5fb65
AI Image Editor: restrict to editable image formats (BL-16523)
hatton 3b59570
Merge remote-tracking branch 'origin/master' into AddAIImages
hatton a96190e
AI Image Editor: address review feedback (BL-16523)
hatton 5e4e97b
AI Image Editor: remove the OpenRouter OAuth sign-in path (BL-16523)
hatton 162ad6d
Merge remote-tracking branch 'origin/master' into AddAIImages
hatton dbecb8f
Correct two AI Image Editor code comments per review (BL-16523)
hatton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/BloomBrowserUI/bookEdit/toolbox/canvas/bloom-exe-ai-editor-open.uitest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { test, expect } from "playwright/test"; | ||
| import { connectToBloomExe } from "../../../react_components/component-tester/bloomExeCdp"; | ||
|
|
||
| // End-to-end smoke test for the "Edit with AI..." integration (see | ||
| // canvasControlRegistry.ts `editWithAi` and AiImageEditorApi.cs). It attaches to a | ||
| // real, running Bloom.exe over CDP and proves the editor can actually OPEN — the exact | ||
| // thing that silently 503'd when the editor app wasn't staged into the build. | ||
| // | ||
| // PRECONDITION: Bloom is running in the Edit tab with a book selected (the launch | ||
| // endpoint needs a current book). Run it with the app up, e.g. from src/BloomBrowserUI: | ||
| // pnpm exec playwright test --config react_components/component-tester/playwright.bloom-exe.config.ts \ | ||
| // bookEdit/toolbox/canvas/bloom-exe-ai-editor-open.uitest.ts | ||
| // | ||
| // It deliberately stops short of driving the right-click menu (that is the heavier | ||
| // "full UI" flow); instead it exercises the launch contract and confirms the editor | ||
| // iframe boots, which is what "we can open the AI editor" really means. | ||
| test.describe("Bloom exe CDP: AI Image Editor", () => { | ||
| test("launches and the editor app boots in its iframe", async () => { | ||
| const connection = await connectToBloomExe(); | ||
|
|
||
| try { | ||
| // 1. The launch endpoint mints a session and returns everything the overlay | ||
| // needs, including where the editor app is served (editorUrl). This is the | ||
| // call that returned 503 "not included in this build" before staging worked. | ||
| const launch = await connection.page.evaluate(async () => { | ||
| const response = await fetch( | ||
| "/bloom/api/aiImageEditor/launch", | ||
| { method: "POST" }, | ||
| ); | ||
| return { | ||
| status: response.status, | ||
| body: response.ok | ||
| ? await response.json() | ||
| : await response.text(), | ||
| }; | ||
| }); | ||
|
|
||
| expect( | ||
| launch.status, | ||
| `aiImageEditor/launch failed (is a book selected in the Edit tab?): ${JSON.stringify( | ||
| launch.body, | ||
| )}`, | ||
| ).toBe(200); | ||
|
|
||
| const launchData = launch.body as { | ||
| editorUrl: string; | ||
| sessionToken: string; | ||
| bookImages?: unknown[]; | ||
| }; | ||
| expect( | ||
| launchData.editorUrl, | ||
| "launch reply had no editorUrl", | ||
| ).toBeTruthy(); | ||
| expect( | ||
| launchData.sessionToken, | ||
| "launch reply had no sessionToken", | ||
| ).toBeTruthy(); | ||
|
|
||
| // 2. Prove the editor really opens: load it in an iframe exactly as the overlay | ||
| // does (mode=bloom-iframe) and wait for the editor's own "ready" handshake on | ||
| // the shared "bloom-ai-image-tools" channel. That message only fires once the | ||
| // app's HTML + JS have loaded and BloomHostedImageEditor has mounted, so it is | ||
| // the strongest signal that the editor genuinely booted rather than 404'd. | ||
| const bootResult = await connection.page.evaluate( | ||
| async (editorUrl: string) => { | ||
| const iframeUrl = new URL(editorUrl, window.location.href); | ||
| iframeUrl.searchParams.set("mode", "bloom-iframe"); | ||
|
|
||
| return await new Promise<{ | ||
| ready: boolean; | ||
| reason: string; | ||
| }>((resolve) => { | ||
| const iframe = document.createElement("iframe"); | ||
| iframe.id = "ai-editor-smoke-iframe"; | ||
| // Keep it out of sight; we only care that it boots. | ||
| iframe.style.cssText = | ||
| "position:fixed;left:-99999px;top:0;width:1024px;height:768px;border:0;"; | ||
|
|
||
| let settled = false; | ||
| const cleanup = () => { | ||
| window.removeEventListener("message", onMessage); | ||
| clearTimeout(timer); | ||
| iframe.remove(); | ||
| }; | ||
| const finish = (ready: boolean, reason: string) => { | ||
| if (settled) return; | ||
| settled = true; | ||
| cleanup(); | ||
| resolve({ ready, reason }); | ||
| }; | ||
|
|
||
| const onMessage = (event: MessageEvent) => { | ||
| if (event.source !== iframe.contentWindow) { | ||
| return; | ||
| } | ||
| const data = event.data as { | ||
| channel?: string; | ||
| type?: string; | ||
| }; | ||
| if ( | ||
| data?.channel === "bloom-ai-image-tools" && | ||
| data?.type === "ready" | ||
| ) { | ||
| finish(true, "received ready handshake"); | ||
| } | ||
| }; | ||
|
|
||
| const timer = setTimeout( | ||
| () => | ||
| finish( | ||
| false, | ||
| "timed out waiting for the editor's ready handshake", | ||
| ), | ||
| 20000, | ||
| ); | ||
|
|
||
| iframe.addEventListener("error", () => | ||
| finish(false, "iframe failed to load"), | ||
| ); | ||
|
|
||
| window.addEventListener("message", onMessage); | ||
| iframe.src = iframeUrl.toString(); | ||
| document.body.appendChild(iframe); | ||
| }); | ||
| }, | ||
| launchData.editorUrl, | ||
| ); | ||
|
|
||
| expect(bootResult.ready, bootResult.reason).toBe(true); | ||
| } finally { | ||
| await connection.browser.close(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.