@fungi.computer/darkroom 0.11.24 → 0.11.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/darkroom",
3
- "version": "0.11.24",
3
+ "version": "0.11.26",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Media generation, durable output retention and provenance with host-owned authority and billing",
6
6
  "type": "module",
@@ -66,7 +66,7 @@
66
66
  "exifreader": "4.46.0",
67
67
  "@fungi.computer/ts-webp": "0.1.6",
68
68
  "@xmldom/xmldom": "0.9.12",
69
- "@fungi.computer/agar": "0.28.5",
69
+ "@fungi.computer/agar": "0.29.0",
70
70
  "@fungi.computer/capnweb": "0.12.0-fungi.0"
71
71
  },
72
72
  "devDependencies": {
@@ -0,0 +1,87 @@
1
+ import sharp from "sharp";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { validateMediaGenerationSettings } from "../src/index.js";
4
+ import { generate, type MediaAiPort } from "../src/cloudflare/provider.js";
5
+
6
+ const lucid = "@cf/leonardo/lucid-origin";
7
+ const phoenix = "@cf/leonardo/phoenix-1.0";
8
+ const flux = "@cf/black-forest-labs/flux-1-schnell";
9
+
10
+ const png = async () =>
11
+ new Uint8Array(
12
+ await sharp({
13
+ create: { width: 8, height: 8, channels: 3, background: "white" },
14
+ })
15
+ .png()
16
+ .toBuffer(),
17
+ );
18
+
19
+ /** Run one generation against a recording Workers AI binding; no network. */
20
+ const sentBody = async (input: {
21
+ model: string;
22
+ guidance?: number;
23
+ }): Promise<object> => {
24
+ const image = await png();
25
+ const run = vi.fn<MediaAiPort["run"]>().mockResolvedValue(image);
26
+ const settings = validateMediaGenerationSettings({
27
+ prompt: "a lantern",
28
+ width: 1024,
29
+ height: 1024,
30
+ ...input,
31
+ });
32
+ await generate({ run }, settings, []);
33
+ expect(run).toHaveBeenCalledTimes(1);
34
+ const body = run.mock.calls[0]?.[1];
35
+ if (body === undefined) throw new Error("the binding was not called");
36
+ return body;
37
+ };
38
+
39
+ describe("Workers AI image guidance in the request body", () => {
40
+ it("sends an explicit guidance to Lucid Origin", async () => {
41
+ expect(await sentBody({ model: lucid, guidance: 7 })).toMatchObject({
42
+ guidance: 7,
43
+ });
44
+ });
45
+
46
+ it("sends the catalog default guidance when none is given", async () => {
47
+ expect(await sentBody({ model: lucid })).toMatchObject({ guidance: 5 });
48
+ expect(await sentBody({ model: phoenix })).toMatchObject({ guidance: 3 });
49
+ });
50
+
51
+ it("sends no guidance key to a model that takes none", async () => {
52
+ expect(await sentBody({ model: flux })).not.toHaveProperty("guidance");
53
+ });
54
+
55
+ it("refuses guidance outside the model's range, naming the range", () => {
56
+ expect(() =>
57
+ validateMediaGenerationSettings({
58
+ model: lucid,
59
+ prompt: "a lantern",
60
+ width: 1024,
61
+ height: 1024,
62
+ guidance: 11,
63
+ }),
64
+ ).toThrow(`${lucid} accepts guidance from 0 through 10`);
65
+ expect(() =>
66
+ validateMediaGenerationSettings({
67
+ model: phoenix,
68
+ prompt: "a lantern",
69
+ width: 1024,
70
+ height: 1024,
71
+ guidance: 1,
72
+ }),
73
+ ).toThrow(`${phoenix} accepts guidance from 2 through 10`);
74
+ });
75
+
76
+ it("refuses guidance on a model without a guidance range", () => {
77
+ expect(() =>
78
+ validateMediaGenerationSettings({
79
+ model: flux,
80
+ prompt: "a lantern",
81
+ width: 1024,
82
+ height: 1024,
83
+ guidance: 5,
84
+ }),
85
+ ).toThrow(`${flux} does not take guidance`);
86
+ });
87
+ });