feat(ai): ImageRef enum with sync URL/path/bytes resolution #129

Closed
casper-stevens wants to merge 1 commit from development_ai_imageref into development_ai_image_generation
Member

Summary

  • Adds ImageRef — caller-intent enum with Url(String), Path(PathBuf), and Bytes { mime, data } variants — plus ImageGenerationRequest::add_image_ref{,_with} builder methods that resolve the ref synchronously through the shared image_io pipeline.
  • URL fetching uses the already-bundled blocking ureq client (no new deps, no tokio). Downstream callers (hero_slides) can drop their own reqwest / image deps.
  • Factors out load_image_from_bytes from load_image_from_path so URL and pre-loaded bytes share the resize/transcode path.

Design

See docs/adr/0001-imageref-abstraction-for-image-request-builder.md for the rationale — in short, the existing ImageInput enum stays (it's the "what gets sent to the API" representation and legitimately passes URLs through). ImageRef is the new "what the caller has" layer on top; add_image_ref fetches URLs / reads paths / re-encodes bytes, then attaches the result as ImageInput::Bytes.

Dependency

This PR depends on #125 — it is branched off development_ai_image_generation and extends the builder introduced there. Please merge #125 first, then rebase/re-target this PR onto development.

Closes #128.

Test plan

  • cargo test -p herolib_ai --lib — 64 passed (3 new ImageRef tests)
  • cargo check --workspace in sibling hero_slides2 repo still green via path-patch
  • Manual: URL fetch path exercised through hero_slides follow-up PR

🤖 Generated with Claude Code

## Summary - Adds `ImageRef` — caller-intent enum with `Url(String)`, `Path(PathBuf)`, and `Bytes { mime, data }` variants — plus `ImageGenerationRequest::add_image_ref{,_with}` builder methods that resolve the ref synchronously through the shared `image_io` pipeline. - URL fetching uses the already-bundled blocking `ureq` client (no new deps, no tokio). Downstream callers (hero_slides) can drop their own `reqwest` / `image` deps. - Factors out `load_image_from_bytes` from `load_image_from_path` so URL and pre-loaded bytes share the resize/transcode path. ## Design See [docs/adr/0001-imageref-abstraction-for-image-request-builder.md](docs/adr/0001-imageref-abstraction-for-image-request-builder.md) for the rationale — in short, the existing `ImageInput` enum stays (it's the "what gets sent to the API" representation and legitimately passes URLs through). `ImageRef` is the new "what the caller has" layer on top; `add_image_ref` fetches URLs / reads paths / re-encodes bytes, then attaches the result as `ImageInput::Bytes`. ## Dependency **This PR depends on #125** — it is branched off `development_ai_image_generation` and extends the builder introduced there. Please merge #125 first, then rebase/re-target this PR onto `development`. Closes #128. ## Test plan - [x] `cargo test -p herolib_ai --lib` — 64 passed (3 new ImageRef tests) - [x] `cargo check --workspace` in sibling `hero_slides2` repo still green via path-patch - [ ] Manual: URL fetch path exercised through hero_slides follow-up PR 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(ai): ImageRef enum with sync URL/path/bytes resolution
Some checks failed
Lint / lint-linux (push) Failing after 5s
Tests with Services / test-linux (push) Failing after 12m20s
633810f6c5
Adds `ImageRef` — a caller-intent enum with `Url(String)`, `Path(PathBuf)`,
and `Bytes { mime, data }` variants — plus `ImageGenerationRequest::
add_image_ref{,_with}` methods that resolve the ref synchronously through
the shared `image_io` pipeline. URL fetching uses the already-bundled
blocking `ureq` client, so downstream callers (hero_slides) can drop
their own `reqwest` / `image` dependencies.

Also factors out `load_image_from_bytes` from `load_image_from_path` so
URL and pre-loaded bytes share the resize/transcode path.

See docs/adr/0001-imageref-abstraction-for-image-request-builder.md.

Closes lhumina_code/hero_lib#128
Author
Member

Consumer side proven: hero_slides commit 0251648 on PR 21 adopts ImageRef / add_image_ref_with via the ../hero_lib path-patch. Workspace compiles green and all 47 hero_slides_lib tests pass. Validates the API surface proposed here (Url / Path / Bytes { mime, data } + sync URL fetch).

🤖 via Claude

Consumer side proven: hero_slides [commit `0251648`](https://forge.ourworld.tf/lhumina_code/hero_slides/commit/0251648) on PR 21 adopts `ImageRef` / `add_image_ref_with` via the `../hero_lib` path-patch. Workspace compiles green and all 47 `hero_slides_lib` tests pass. Validates the API surface proposed here (`Url` / `Path` / `Bytes { mime, data }` + sync URL fetch). 🤖 via Claude
despiegk closed this pull request 2026-04-17 07:38:17 +00:00
Some checks failed
Lint / lint-linux (push) Failing after 5s
Tests with Services / test-linux (push) Failing after 12m20s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_lib!129
No description provided.