Repository navigation
Paint the Ren'Py scene's pictures with fal, under a cap - #403
Merged
Merged
Conversation
FalImageAgent is a third named door for a model call beside BaseAgent and SystemOneAgent: a plain Net::HTTP client for fal's queue API (submit, poll the status URL, read the result, fetch the picture without the key). The key is read from 1Password at run time by `rake art:generate` alone, sent only to the queue's own host, and never printed, logged or stored. In the test environment the real queue address is refused outright. Artwork rows hold one picture each of a Location (background) or a Character (standing portrait, the protagonist's side image, or a second expression edited from the portrait): kind, endpoint, the full prompt as sent, seed, request ids, the list price booked for each call, and the picture and cut-out files under TA_ART_ROOT (default storage/art, ignored). A row is written as soon as fal answers, so a paid call is always on record. Artwork::Prompt holds the approved wording; for The Lunar Cartographer's opening it makes the four approved prompts byte for byte, stored under test/fixtures/files/art/ and tested. Artwork::Plan derives the pictures from the export, keyed by their Ren'Py image tags, and prices them ($0.174 for the opening with the second expression). `rake art:prompts[story]` prints every prompt and the bill, free. `rake art:generate[story] CAP=... ONLY=...` refuses to start, before the key is read, when the bill exceeds CAP; the painter checks the cap again before every call. Renpy::Export shows a kept picture (the cut-out for a person) instead of its placeholder and copies it into game/art/. No fal request or model call was made building or testing this.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stage 2 of the Ren'Py proof: the pictures, from fal. This PR spends nothing. The paid run comes later, on the private copy, after this lands.
What it adds
FalImageAgent(app/agents/FalImageAgent.rb): a third named door for model calls, besideBaseAgentandSystemOneAgent. It is a plainNet::HTTPclient for fal's queue API and adds no new gem. It submits a request, polls the status URL, reads the result, then downloads the picture without the key.op read op://Mate/fal/credential, using the service account token in~/.config/op/service-account-token). Onlyrake art:generatereads it.#inspecthides it.Models and sizes, as approved:
fal-ai/bytedance/seedream/v4/text-to-imagefor portraits and backgrounds: 1024×1536 standing, 1024×1024 side image, 1920×1080 background.fal-ai/bria/background/removefor cut-outs.fal-ai/bytedance/seedream/v4/editfor the second expression, with the first portrait sent inline as a reference.artworkstable: one row per picture of aLocationorCharacter. Each row records:Files live under
TA_ART_ROOT(defaultstorage/art, which is git-ignored). A row is written as soon as fal answers, so every paid call is recorded even if its download fails.Artwork::Prompt: the approved prompt templates. For The Lunar Cartographer's opening they produce all four approved prompts byte for byte. The expected text is stored intest/fixtures/files/art/and tested.Artwork::Plan: works out the pictures from the export, keyed by Ren'Py image tag (c<id>,l<id>,c<id>-stern), and prices them. For the opening: $0.126 for the scene, $0.174 with the second expression, $0.048 for the trial (ONLY=c<grenn>).rake 'art:prompts[story]': prints every prompt and the bill. It is free: no key is read and nothing is sent.CAP=… ONLY=… [AGAIN=1] rake 'art:generate[story]': makes the pictures.CAP.CAPbefore it reads the key.Exporter:
Renpy::Exportuses a stored picture when one exists on this machine's disk (the cut-out, for a person) and copies it intogame/art/. Otherwise it keeps the placeholder. A retake changes the script and therefore the build's digest.Docs:
AGENTS.mdgains a line naming the third door, plus README,docs/local-deploy.md,deploy.env.example(TA_ART_ROOT) and the ignore rule.artworksis skipped in the engine's row dumps (Playthrough::Requests,EngineVectors::Records) because no request builder reads it.Post-update action
None. The new migration runs through
bin/update's existing migrate step.Tests
No network and no spend:
test/support/fake_fal.rb) for the agent and the painter;bin/rails test(5571 runs, 0 failures, 1 skip: the Ren'Py SDK lint),bundle exec rubocop,bin/rails zeitwerk:checkandbin/brakeman --no-pagerall pass. Every check ran withOPENROUTER_API_KEYandTYPESAFE_API_KEYunset.The migration version came from
bin/rails generate migration(20261204143219). It is newer than the latest migration on main (20261031180000).