-
-
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 all 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
45 changes: 45 additions & 0 deletions
45
src/BloomBrowserUI/bookEdit/toolbox/canvas/aiEditorImageFormats.test.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,45 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
|
|
||
| import { isAiEditableImageSrc } from "./aiEditorImageFormats"; | ||
|
|
||
| // Unit tests for isAiEditableImageSrc (see aiEditorImageFormats.ts), the front-end gate that | ||
| // keeps "Edit with AI..." disabled for formats the editor can't open. It works off the src's | ||
| // final extension, ignoring any path prefix and cache-busting query string / hash. | ||
| describe("isAiEditableImageSrc", () => { | ||
| test("true for the editable raster formats, case-insensitively", () => { | ||
| expect(isAiEditableImageSrc("photo.png")).toBe(true); | ||
| expect(isAiEditableImageSrc("photo.jpg")).toBe(true); | ||
| expect(isAiEditableImageSrc("photo.jpeg")).toBe(true); | ||
| expect(isAiEditableImageSrc("photo.webp")).toBe(true); | ||
| expect(isAiEditableImageSrc("PHOTO.PNG")).toBe(true); | ||
| }); | ||
|
|
||
| test("false for formats the editor cannot edit", () => { | ||
| expect(isAiEditableImageSrc("drawing.svg")).toBe(false); | ||
| expect(isAiEditableImageSrc("scan.tif")).toBe(false); | ||
| expect(isAiEditableImageSrc("scan.tiff")).toBe(false); | ||
| expect(isAiEditableImageSrc("old.bmp")).toBe(false); | ||
| expect(isAiEditableImageSrc("anim.gif")).toBe(false); | ||
| }); | ||
|
|
||
| test("ignores path prefixes and a cache-busting query string or hash", () => { | ||
| expect( | ||
| isAiEditableImageSrc( | ||
| "/bloom/C$3A/books/My Book/photo.png?optional=true&nocache=123", | ||
| ), | ||
| ).toBe(true); | ||
| expect(isAiEditableImageSrc("images/drawing.svg?v=2")).toBe(false); | ||
| expect(isAiEditableImageSrc("photo.png#frag")).toBe(true); | ||
| // A query string containing a fake extension must not fool the extension check. | ||
| expect(isAiEditableImageSrc("drawing.svg?fallback=photo.png")).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("false for empty, missing, or extension-less src", () => { | ||
| expect(isAiEditableImageSrc(undefined)).toBe(false); | ||
| expect(isAiEditableImageSrc(null)).toBe(false); | ||
| expect(isAiEditableImageSrc("")).toBe(false); | ||
| expect(isAiEditableImageSrc("noextension")).toBe(false); | ||
| }); | ||
| }); |
35 changes: 35 additions & 0 deletions
35
src/BloomBrowserUI/bookEdit/toolbox/canvas/aiEditorImageFormats.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,35 @@ | ||
| // The image formats the AI Image Editor can actually load and edit. Kept deliberately | ||
| // short: formats the editor can't handle (e.g. svg, tif, bmp, gif) are excluded so the | ||
| // "Edit with AI..." menu item stays disabled for them and we never hand the editor an | ||
| // image it can't open. Must stay in sync with the host's list of the same name | ||
| // (BloomExe/web/controllers/AiImageEditorApi.cs, AllowedImageExtensions). | ||
| export const kAiEditableImageExtensions: ReadonlySet<string> = new Set([ | ||
| "png", | ||
| "jpg", | ||
| "jpeg", | ||
| "webp", | ||
| ]); | ||
|
|
||
| /** | ||
| * True if the given image src points at a format the AI Image Editor can edit. The src may | ||
| * carry a cache-busting query string or hash and any path prefix; only the final extension | ||
| * matters. A src with no recognizable extension is treated as not editable. | ||
| */ | ||
| export function isAiEditableImageSrc(src: string | null | undefined): boolean { | ||
| if (!src) { | ||
| return false; | ||
| } | ||
| // Drop any query string / hash, then take the text after the last dot in the filename. | ||
| const withoutQuery = src.split(/[?#]/)[0]; | ||
| const lastSlash = Math.max( | ||
| withoutQuery.lastIndexOf("/"), | ||
| withoutQuery.lastIndexOf("\\"), | ||
| ); | ||
| const filename = withoutQuery.substring(lastSlash + 1); | ||
| const lastDot = filename.lastIndexOf("."); | ||
| if (lastDot < 0) { | ||
| return false; | ||
| } | ||
| const extension = filename.substring(lastDot + 1).toLowerCase(); | ||
| return kAiEditableImageExtensions.has(extension); | ||
| } |
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.