diff --git a/.changeset/gpt-image-2-6-svg.md b/.changeset/gpt-image-2-6-svg.md new file mode 100644 index 0000000000..8621820c9c --- /dev/null +++ b/.changeset/gpt-image-2-6-svg.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-module-images": minor +--- + +`brain image --format svg` has the GPT Image 2.6 models author a static SVG for a new image, written as a `.svg` file. SVG with `--ref`, `--mask` or `--transparent`, and SVG on a 2.5 or Gemini model, are refused before any request. A returned SVG that contains a script, an event handler, a `foreignObject`, an embedding element, a DOCTYPE, an `@import`, or a reference outside the document is refused and not written. An SVG's cost is reported as unknown. diff --git a/docs/decisions/governed-writable-workers.md b/docs/decisions/governed-writable-workers.md index f01f5612a8..555dca4309 100644 --- a/docs/decisions/governed-writable-workers.md +++ b/docs/decisions/governed-writable-workers.md @@ -4084,7 +4084,7 @@ reason through as the refusal body's `error.message` and an additive `outward_not_approved` (`const refuse`, `packages/ui-sdk/src/server/provider-relay.ts:386-391`). The OpenAI image provider no longer appends its account hint to a relay refusal -(`const relayRefusal`, `packages/module-images/src/providers/openai.ts:252-253`). +(`const relayRefusal`, `packages/module-images/src/providers/openai.ts:255-256`). A cancelled connection keeps its bare 403. The system prompt's turn-lifecycle section names these causes and what the user can do (`A blocked connection says why`, `packages/ui-sdk/src/server/system-prompt.ts:167-175`). Since #3246, diff --git a/docs/hosting/paid-cli-provider-qualification.md b/docs/hosting/paid-cli-provider-qualification.md index 5fe7ffd4bc..ab4bd54985 100644 --- a/docs/hosting/paid-cli-provider-qualification.md +++ b/docs/hosting/paid-cli-provider-qualification.md @@ -56,7 +56,7 @@ SDK conversion without adding a public embedding-provider seam. The image CLI preserves `bytes`, `costIsEstimate`, `costUsd`, `model`, `note`, `output`, `outputs`, `provider`, `reason` and `renamed` -(`const payload`, `packages/module-images/src/cli.ts:466-477`). Its help example +(`const payload`, `packages/module-images/src/cli.ts:474-485`). Its help example is abbreviated; it is not the complete machine contract. Internal image raw usage does not imply that this envelope exposes it. diff --git a/packages/module-images/README.md b/packages/module-images/README.md index fead10cbe9..eff3622280 100644 --- a/packages/module-images/README.md +++ b/packages/module-images/README.md @@ -34,6 +34,7 @@ serve at all: | Exact custom pixels | OpenAI | Gemini has fixed ratios; the 2.6 and 2.5 models take any size on a 16px grid up to 3840px, 3:1 and 8.3MP | | `--complexity` | OpenAI GPT Image 2.6 | Only the 2.6 models take it; it is refused anywhere else | | Animated GIF (`--format gif`) | OpenAI GPT Image 2.6 | Only the 2.6 models return GIF; it is refused anywhere else | +| Static SVG (`--format svg`) | OpenAI GPT Image 2.6 | Only the 2.6 models author SVG, on new images only | | Character consistency | Gemini | Narrows to models that claim it; no benchmark picks a winner | | >6 reference images | Gemini | 10 (Flash) / 14 (Lite) vs OpenAI's practical 8 | | Watermark-free | OpenAI | Gemini always applies SynthID | @@ -67,6 +68,18 @@ these is refused before any request. OpenAI serves GIF only to organizations with GIF preview access, and the refusal says so. A dry run reports a GIF's cost as unknown, because OpenAI publishes no per-frame token count. +`--format svg` asks a GPT Image 2.6 model to author a static SVG, written as +UTF-8 XML to a `.svg` file. It works on new images only: `--ref`, `--mask`, +`--transparent`, the 2.5 models and Gemini are refused before any request. +OpenAI says the output is static, but the module checks rather than trusts it. +An SVG that is not UTF-8 or not an SVG document, or that contains a DOCTYPE, +`'], + ["an event handler", ''], + ["an event handler on a child", ''], + ["a foreignObject", ''], + ["an external href", ''], + ["an external xlink:href", ''], + ["an embedded raster", ''], + ["a javascript: link", ''], + ["an external url()", ''], + ["a stylesheet import", ''], + ["an entity declaration", ']>'], + ["something that is not SVG", "
hi"], + ]; + for (const [label, svg] of active) { + test(`an SVG with ${label} is refused and nothing is written`, async () => { + serve(svg); + expect(await run(["x", "--format", "svg", "--out", "bad.svg"])).toBe(1); + expect(calls).toHaveLength(1); + expect(existsSync(join(root, "bad.svg")), "IMAGE_SVG_ACTIVE_CONTENT").toBe(false); + expect(out.join("\n")).toMatch(/SVG/); + }); + } + + test("an SVG's cost is unknown when its authoring tokens cannot be priced", async () => { + serve(CLEAN_SVG, { + usage: { output_tokens: 100, input_tokens_details: { text_tokens: 10, image_tokens: 0 } }, + svg_usage: { input_tokens: 500, output_tokens: 2000 }, + }); + expect(await run(["x", "--format", "svg", "--out", "x.svg"])).toBe(0); + expect(report().costUsd, "IMAGE_SVG_COST").toBeNull(); + }); + + test("an SVG dry run reports its cost as unknown", async () => { + expect(await run(["x", "--format", "svg", "--aspect", "1:1", "--dry-run"])).toBe(0); + expect(calls).toHaveLength(0); + expect(report().output).toEndWith(".svg"); + expect(report().estimatedCostUsd).toBeNull(); + }); +}); diff --git a/packages/module-images/tests/providers.test.ts b/packages/module-images/tests/providers.test.ts index 331afe9eb8..c05712542e 100644 --- a/packages/module-images/tests/providers.test.ts +++ b/packages/module-images/tests/providers.test.ts @@ -290,6 +290,41 @@ describe("openai provider — animated GIF (#3783)", () => { } }); +describe("openai provider — static SVG (#3784)", () => { + const svg = ''; + + test("only the 2.6 pair lists svg among its formats", () => { + expect(openaiProvider.models.filter((m) => m.outputFormats.includes("svg")).map((m) => m.id)).toEqual([SUNBURST, FLARE]); + }); + + test("an SVG response is decoded as image/svg+xml with its cost unknown", async () => { + stub({ data: [{ b64_json: Buffer.from(svg).toString("base64") }], usage: { output_tokens: 1, input_tokens_details: { text_tokens: 1, image_tokens: 0 } } }); + const result = await openaiProvider.generate(SUNBURST, { prompt: "x", format: "svg" }, "k"); + expect(result.images[0].mime).toBe("image/svg+xml"); + expect(new TextDecoder().decode(result.images[0].data)).toBe(svg); + expect(result.costUsd).toBeUndefined(); + }); + + const refusals: [string, Parameters