Repository navigation
feat(chat): make images in Chat, pick one from the set and keep it in Files (W4-08, 00476, 00477) - #2103
Conversation
… Files (W4-08, 00476)
Chat makes images now instead of refusing (CHAT-15 §E). Before the first
image of a chat it asks which image model to use, the options read from
the price data: the cheapest first and recommended, each with its
multiplier and its share of the monthly AI limit per image ("Your key"
on the workspace's own OpenRouter key). Each request makes four images
at 1K after a cost card that says how many, on which model, and their
share. When the limit left covers only some, the parts check asks first
("Create 1 image now"), with no image made before the answer.
The images run on OpenRouter, held and charged through W4-07's metering
at the provider's real cost, and are filed as one set in Files. Its card
shows every image, the selected one marked; the person picks another in
their own chat and downloads it as PNG, converted in the browser.
The engine change is thin: the parts check counts images at their
model's price, and a deliverable that filed itself is named, not filed
again. 00476 lets chat-files take JPEG, which Google's image models send.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and round image multipliers (00477) Found in the preview of W4-08: - chat_files' formats check knew PNG and WebP only, so a set of JPEG images (Google's image models) wasn't filed: 00477 adds 'jpg'. - The model may skip the parts check: when the AI limit left covers only some of the images, the request's own check now sends it there before the card, so the person is asked first. - Shares come rounded to two decimals, so Nano Banana 2 read 2.1x: multipliers are whole from 2x, as CHAT-16 item 11 writes them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… images/access.ts The Content Editor's images (W4-09) need the same: the workspace's own OpenRouter key or Ansvisor's, and the image models with their multipliers and shares. They move out of chat-images.ts as they are, with their tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'t jsdom's Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Two things to fix:
-
The image tool tells the model never to refuse.
generate_image's description (web/src/lib/chat/registry/image-tools.ts:57) says "Never refuse an image request and never point to another image tool or app". That overrides Chat's other guardrails, so a request like a competitor's CEO in handcuffs is left to the image provider's own filter (Chat's test set requires that it insults no one). The intent, stopping "I can't make images", fits in: "Don't say you can't make images; make them with this tool", while keeping the normal rules (no real people's likeness, no insulting or misleading imagery of competitors, no trademarks the brand doesn't own). -
Admin provider switches aren't applied to images. The image models are
google/*andopenai/*, butimageModelOptions(images/access.ts),makeChatImagesand thegenerate_imageenum never checkmodelProviderOn/readProviderChoices(#2036). Once both land, an Admin who turns Google off still gets Nano Banana recommended and prompts sent to Google. Filter the models byproviderOnin the options, refuse in the precheck, and limit theplan_partsimage_model enum the same way (in whichever of #2036/#2103 merges second).
Small: when every request is refused, makeChatImages charges $0 and keeps units = the number held rather than releasing the row; selectRunImage updates only storage_path, so a mixed-type set keeps the first image's mime_type; the other images of a set (image-1..N) have no delete path yet.
…odels whose maker an Admin turned off Review on ansvisor#2103: - generate_image no longer says "never refuse": it says don't claim Chat can't make images, and keeps Chat's rules (no real person's likeness, no insulting or misleading imagery of a competitor or anyone, no trademark the brand doesn't own). - The provider switches of Settings › Chat (W4-34) apply to images: the model question offers only models whose maker is on, the precheck and the request refuse one that is off, and with every maker off Chat says it can't make images here. model-providers.ts is ansvisor#2036's, as it is. - A request every provider refused, billing nothing, lets its hold go; picking an image of a set takes its own type and format. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…generation # Conflicts: # server/src/lib/chat-budget.test.js # server/src/routes/internal-chat-budget.js # web/messages/en.json # web/src/lib/chat/budget.test.ts # web/src/lib/chat/engine.test.ts # web/src/lib/chat/registry/tools.test.ts # web/src/lib/chat/registry/tools.ts
|
Done in 535581e and merged main: generate_image now keeps Chat's rules (no real person's likeness, no insulting or misleading imagery, no trademarks the brand doesn't own) instead of "never refuse", image models follow the Settings › Chat provider switches (model question, precheck and request), and the small ones are fixed (all-refused request releases its hold, a picked image keeps its own type); the plan_parts enum stays static and the precheck refuses an off provider instead. |
gkhngyk
left a comment
There was a problem hiding this comment.
Both points are fixed; CI typecheck fails at web/src/lib/chat/partial-limit.ts:103 ("createImages" not assignable).
A merge left two "partial" blocks in en.json, and the second, without createImages, replaced the first, so typecheck failed in partial-limit.ts. The duplicate is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
…neration # Conflicts: # web/src/lib/chat/budget.test.ts # web/src/lib/chat/engine.test.ts # web/src/lib/chat/undo-output.ts
The merge-base changed after approval.
…generation # Conflicts: # supabase/schema.sql # web/.env.example # web/messages/en.json
…KEY entry Main already lists OPENROUTER_API_KEY for Chat's model menu (W4-03), so the merge left the key twice in web/.env.example. Chat's images now join that entry's comment instead of a second key line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
…generation # Conflicts: # supabase/schema.sql # web/.env.example # web/src/components/chat/run/deliverable-card.test.tsx # web/src/components/chat/run/deliverable-card.tsx # web/src/lib/chat/engine.test.ts # web/src/lib/chat/engine.ts # web/src/lib/chat/images/access.test.ts # web/src/lib/chat/images/access.ts
…generation # Conflicts: # supabase/schema.sql
…rned off (W4-34)
The editor's image list already hides such a model (imageModelOptions),
but POST /api/content/drafts/{id}/images still ran any listed model. It
now checks imageModelOn first, as Chat's image precheck does, and refuses
before anything is held, charged or sent to the provider: 409 with
{ ok: false, code: 'provider_off', model }, and the panel says the
model's maker is turned off in Settings › Chat. A failed read refuses too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
…generation # Conflicts: # supabase/schema.sql
Summary
W4-08: Chat makes images now instead of refusing (CHAT-15 §E, CHAT-20 §9 row 70). Ask in your own words, for example "Create a cover image for our GEO post".
The flow
list_image_models, a read), the cheapest first and Recommended.generate_image's own check counts what the limit covers before the card. When the limit covers only some, it sends the model to the parts check first, so the person is always asked.generate_imageis a WRITE with the cost card in every mode, Full auto too. The card says "4 images · Nano Banana 2 Lite · about 3.1% of your monthly AI limit". Admins and Managers only (asbuild_report).Whose key: the workspace's own OpenRouter key when Chat runs on it (
own_key, the limit doesn't move). Otherwise Ansvisor'sOPENROUTER_API_KEY. An own key of another provider can't make these images, so images run on the AI limit (CHAT-16 item 25). An own OpenRouter key that can't be read stops, as for Chat; Ansvisor's key never takes its place.Engine (
engine.ts): one thin change, in two places:coveredUnits: the parts check counts images at their image model's price (plan_partstakes an optionalimage_model).deliver(): a deliverable that filed itself (fileId) is named on its card, not filed again.Also changed
fileChatImagesfiles a set (one row, every image counted). New routes:GET /api/chat/runs/{id}/files/{n}/images(count, selected, whether the person may pick),POSTthe same path (pick, own chat only, read-only refused), andGET …/images/{image}(one image, inline, private).jpg,png,webp).generate_imageis recorded with no Undo (§9 row 70: the set is deleted in Files).chat-filestakesimage/jpeg. Google's image models answer in JPEG, and the bucket had only PNG and WebP (00411). Run again, it changes nothing.chat_files.formatstakes'jpg': the same list, with it. Run again, it ends the same.web/.env.exampledocumentsOPENROUTER_API_KEYfor the web app.help/chat/images.md(approved: false).Not in this PR (W4-08b):
/image;Stacked on #2095. If #2032 (W4-03) merges first,
web/.env.examplemay conflict on theOPENROUTER_API_KEYlines: keep one, with both comments merged.Tried end to end on the dev DB (Growth plan for the preview, then put back):
prompt_improve_usagerow:feature = 'image',units = 4,cost_usd = 0.1345, what OpenRouter billed.Screenshots (1024 px, light and dark): the image model question, the cost card, and the result card with image 3 selected.
Related issue
None. Chat Wave 4, W4-08 (CHAT-15 §E, CHAT-20 §9 row 70).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && yarn vitest run src/lib/chat/images src/lib/chat/file-store.test.ts src/lib/chat/partial-limit.test.ts src/components/chat/run/deliverable-card.test.tsx "src/app/api/chat/runs/[id]/files" src/lib/chat/registry src/lib/chat/undo.test.ts, andsrc/lib/chat/engine.test.ts -t "image".CHAT_AGENTICon andOPENROUTER_API_KEYset, open Chat as an Admin and ask "Create a cover image for our GEO post".prompt_improve_usagerow hasfeature = 'image',units = 4andcost_usdequal to what OpenRouter billed.Migrations 00476 and 00477 (apply both before deploying the web app). No new packages.
Checklist
yarn lintpassesyarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (9d2e271), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41688852990): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code