small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo robot-docs imagegen.md

Image generation #

The imagegen extension exposes a shared Python interface for generating and editing raster images. It requires python. Driver extensions contribute ImagegenPlugin providers. Codex supplies the built-in driver through ChatGPT sign-in. The shared interface and the driver can be enabled independently.

extensions/imagegen/extension.gleam owns host routes, driver selection, reference resolution, and response bounds. imagegen.py owns local reference reads and output publication. See plugins for the driver contract.

Select a driver #

await imagegen.providers() returns the loaded drivers' names and labels. await imagegen.generate(prompt, provider=...) selects one by name. Omitting provider works only when exactly one driver is active. An absent or ambiguous selection fails without trying another driver. Reloading extensions updates the drivers captured for later host calls.

Driver discovery does not establish that an account is signed in or that the upstream service accepts its request. Codex selects credentials in the daemon through the existing account selection interface. Its configuration owns the image model setting separately from the reasoning model. Its configured default is gpt-image-2; this is not a model-availability guarantee. The production endpoint is fixed to https://chatgpt.com/backend-api/codex, and the transport refuses other destinations and does not follow redirects. Do not forward subscription credentials to an arbitrary image service.

Generate and inspect #

The Python call is:

result = await imagegen.generate(
    "A cut-paper illustration of a fox in snow",
    transparent_background=True,
    output="output/imagegen/fox.png",
)
show_image(result.path)

The result contains path, mime_type, width, height, bytes, request_id, and generation_id. Without an output path, the binding chooses output/imagegen/generated-<uuid>.png in the kernel's working directory. Output must be PNG and at most 5 MiB. Existing files and dangling output symlinks are refused. Publication uses a same-directory hard link to avoid replacing a destination created during generation.

Generating a file does not attach it to the conversation. show_image is a separate operation subject to the active reasoning model's viewing limits. Read the shipped image generation guidance for reference selection, prompting, inspection, and revisions. That skill grants no additional tools or permission to spend quota.

Reference images #

Pass at most five references to imagegen.generate(..., references=[...]). Local PNG, JPEG, and WebP files must total at most 5 MiB. The binding reads only regular files, checks the image bytes, and sends inline data to the daemon.

await imagegen.references(after=0, limit=50) discovers uploaded and tool-output images in the current session. Each entry includes a reference identifier, transcript sequence, image index, MIME type, width, and height. Pass the returned identifier to generate; do not invent identifiers or reuse another session's. The daemon resolves each identifier against the calling session and checks its stored image bytes. Each transcript reference is limited to 5 MiB.

Pages scan transcript rows, including rows without images. Continue with next_after while has_more is true, even when images is empty. The page limit is between 1 and 100 rows. Local references and transcript identifiers can be mixed, and their order is preserved.

Cancellation and recovery #

Generation can consume quota or incur provider charges. Do not automatically retry an interrupted, cancelled, or uncertain call, and do not change drivers as a fallback. Re-running the Python expression creates a new call identity and can submit another request. The admission map is not durable idempotency.

albedo_imagegen_calls owns bounded admission and cancellable workers. The kernel's existing host-call ledger owns replay decisions across reattachment. A worker ending locally cannot undo an already submitted upstream generation.

Successful cancellation waits for the coordinator and request worker to stop before releasing their slot. It does not establish whether the upstream service accepted the request before the worker stopped.

The binding probes the destination before contacting the provider and validates the returned image before publication. A later storage error can leave complete bytes in a .imagegen-*.png temporary file. Inspect the reported recovery path and the destination before generating again. A retained copy does not establish that its bytes reached durable storage. Partial output must not be reported as a complete image.

Host and driver refusals raise ImagegenError. Local validation and filesystem failures raise Python exceptions. Preserve request identifiers when reporting an uncertain outcome. Provider request accounting has a separate limitation for these calls.