@fungi.computer/darkroom 0.6.0 → 0.8.0

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.
Files changed (53) hide show
  1. package/README.md +178 -0
  2. package/dist/app-media-contracts.d.ts +107 -12
  3. package/dist/audio-providers/elevenlabs.d.ts +40 -0
  4. package/dist/audio-providers/elevenlabs.js +69 -0
  5. package/dist/audio-reference-types.d.ts +28 -0
  6. package/dist/audio-reference-types.js +16 -0
  7. package/dist/audio-references.d.ts +14 -0
  8. package/dist/audio-references.js +69 -0
  9. package/dist/browser-failure.d.ts +2 -0
  10. package/dist/browser-failure.js +2 -0
  11. package/dist/cloudflare/provider.d.ts +6 -4
  12. package/dist/cloudflare/provider.js +39 -21
  13. package/dist/cloudflare/reference-images.d.ts +6 -0
  14. package/dist/cloudflare/reference-images.js +25 -7
  15. package/dist/cost-estimate.js +2 -2
  16. package/dist/daily-media-meter.d.ts +55 -0
  17. package/dist/daily-media-meter.js +81 -0
  18. package/dist/execution-error.d.ts +1 -1
  19. package/dist/gateway-models.d.ts +19 -9
  20. package/dist/gateway-models.js +57 -19
  21. package/dist/gateway-wire.d.ts +1 -0
  22. package/dist/gateway-wire.js +2 -0
  23. package/dist/index.d.ts +116 -24
  24. package/dist/index.js +147 -26
  25. package/dist/media-binding.d.ts +60 -7
  26. package/dist/media-binding.js +43 -21
  27. package/dist/media-generation.js +20 -7
  28. package/dist/media-operation-contract.d.ts +9 -3
  29. package/dist/media-operation-contract.js +6 -4
  30. package/dist/media-operation-do.d.ts +13 -2
  31. package/dist/media-operation-do.js +26 -1
  32. package/dist/media-operation-owner.d.ts +10 -2
  33. package/dist/media-operation-owner.js +56 -11
  34. package/dist/media-operation.js +5 -3
  35. package/dist/media-quote.d.ts +14 -0
  36. package/dist/media-quote.js +17 -0
  37. package/dist/model-catalog.d.ts +602 -6
  38. package/dist/model-catalog.js +309 -9
  39. package/dist/reference-image-size.d.ts +4 -3
  40. package/dist/reference-image-size.js +9 -9
  41. package/dist/server.d.ts +31 -8
  42. package/dist/server.js +51 -8
  43. package/dist/video-providers/reference-encoding.d.ts +7 -2
  44. package/dist/video-providers/reference-encoding.js +14 -3
  45. package/dist/video-providers/types.d.ts +2 -2
  46. package/dist/video-providers/unified.d.ts +1 -0
  47. package/dist/video-providers/unified.js +4 -2
  48. package/docs/api/app-media-contracts.md +50 -10
  49. package/docs/api/browser.md +4 -2
  50. package/docs/api/cloudflare.md +56 -3
  51. package/docs/api/index.md +1042 -121
  52. package/docs/api/server.md +306 -50
  53. package/package.json +3 -2
package/dist/server.js CHANGED
@@ -7,11 +7,14 @@ import { AppError, describeAppError } from "@fungi.computer/agar/errors";
7
7
  import * as Effect from "effect/Effect";
8
8
  import * as Result from "effect/Result";
9
9
  import { runMediaGeneration } from "./media-generation.js";
10
- import { validateMediaGenerationSettings, listMediaModels, mediaGenerationSettingsSchema, mediaRequestedImageFormatSchema, MediaSettingsError, } from "./index.js";
10
+ import { quoteMediaGeneration } from "./media-quote.js";
11
+ import { validateMediaGenerationSettings, listPictureMediaModels, mediaGenerationSettingsSchema, mediaRequestedImageFormatSchema, MediaSettingsError, } from "./index.js";
11
12
  import { mediaResultSchema, } from "./media-operation-contract.js";
12
13
  import { MediaOutputFormatMismatch, MediaBillingRefusal, MediaExecutionError, MediaSafetyFilterRefusal, } from "./execution-error.js";
14
+ export { createDailyMediaMetering, DailyMediaMeter, } from "./daily-media-meter.js";
13
15
  export { MediaBillingRefusal, MediaExecutionError, } from "./execution-error.js";
14
16
  export { mediaUnits } from "./gateway-models.js";
17
+ export { quoteMediaGeneration } from "./media-quote.js";
15
18
  export { MediaOperationOwner, mediaOperationDestinationSchema, mediaOperationCoordinatesSchema, mediaOperationStateSchema, mediaImageSchema, mediaOperationResultSchema, } from "./media-operation-owner.js";
16
19
  const identifier = z.lazy(() => z.string().min(1).max(256));
17
20
  /** Decode relative service generation input. Identity comes from the host. */
@@ -27,6 +30,10 @@ export const mediaRequestSchema = z.strictObject({
27
30
  /** Optional verified image encoding pin. */
28
31
  outputFormat: mediaRequestedImageFormatSchema.optional(),
29
32
  });
33
+ /** A price request: the exact settings, no destination or request id. */
34
+ const mediaQuoteRequestSchema = z.strictObject({
35
+ settings: mediaGenerationSettingsSchema,
36
+ });
30
37
  export { mediaResultSchema } from "./media-operation-contract.js";
31
38
  async function readJsonBody(request) {
32
39
  try {
@@ -46,6 +53,11 @@ const headers = {
46
53
  "Cache-Control": "private, no-store",
47
54
  "X-Content-Type-Options": "nosniff",
48
55
  };
56
+ const billingRefusalWire = {
57
+ insufficient_credits: { code: "INSUFFICIENT_CREDIT", status: 402 },
58
+ denied: { code: "CAPABILITY_DENIED", status: 403 },
59
+ daily_limit_reached: { code: "DAILY_LIMIT_REACHED", status: 429 },
60
+ };
49
61
  function failure(error, refusalMessages) {
50
62
  if (error instanceof MediaSafetyFilterRefusal)
51
63
  return Response.json({
@@ -76,12 +88,10 @@ function failure(error, refusalMessages) {
76
88
  error: refusalMessages?.[error.cause.code] ??
77
89
  "Media generation was refused by the host.",
78
90
  stage: "billing",
79
- code: error.cause.code === "insufficient_credits"
80
- ? "INSUFFICIENT_CREDIT"
81
- : "CAPABILITY_DENIED",
91
+ code: billingRefusalWire[error.cause.code].code,
82
92
  retryable: false,
83
93
  }, {
84
- status: error.cause.code === "denied" ? 403 : 402,
94
+ status: billingRefusalWire[error.cause.code].status,
85
95
  headers,
86
96
  });
87
97
  if (error instanceof MediaSettingsError ||
@@ -184,15 +194,16 @@ function outcomeResponse(outcome) {
184
194
  costMilliunits: outcome.costMilliunits,
185
195
  path: outcome.path,
186
196
  format: outcome.format,
187
- height: outcome.height,
188
197
  model: outcome.model,
198
+ height: outcome.height,
189
199
  width: outcome.width,
190
200
  }), { headers });
191
201
  }
192
202
  /** Relative HTTP routes; the caller admits identity and supplies destination access. */
193
203
  export function createMediaService(host) {
194
204
  const app = new Hono();
195
- app.get("/models", () => Response.json(listMediaModels().map((model) => host.destination.readReference !== undefined ||
205
+ app.get("/models", () => Response.json((host.catalogue ?? listPictureMediaModels())
206
+ .map((model) => host.destination.readReference !== undefined ||
196
207
  model.input.maxReferences === 0
197
208
  ? model
198
209
  : {
@@ -203,7 +214,11 @@ export function createMediaService(host) {
203
214
  maxReferences: 0,
204
215
  referenceField: null,
205
216
  },
206
- }), { headers }));
217
+ })
218
+ .map((model) => host.destination.readAudioReference !== undefined ||
219
+ model.video?.audioReferences == null
220
+ ? model
221
+ : { ...model, video: { ...model.video, audioReferences: null } }), { headers }));
207
222
  app.post("/generate", async (context) => {
208
223
  const body = await readJsonBody(context.req.raw);
209
224
  const input = body.kind === "parsed"
@@ -224,5 +239,33 @@ export function createMediaService(host) {
224
239
  : undefined) ?? failure(error, host.refusalMessages),
225
240
  })));
226
241
  });
242
+ // The provider cost of one exact request, priced by the same estimator and
243
+ // reference reads as /generate; the host applies any billing policy.
244
+ app.post("/quote", async (context) => {
245
+ const body = await readJsonBody(context.req.raw);
246
+ const input = body.kind === "parsed"
247
+ ? mediaQuoteRequestSchema.safeParse(body.value)
248
+ : undefined;
249
+ if (input?.success !== true)
250
+ return failure(new MediaSettingsError("invalid request"));
251
+ try {
252
+ const quote = await quoteMediaGeneration(input.data.settings, {
253
+ read: (reference, model) => {
254
+ if (host.destination.readReference === undefined)
255
+ throw new MediaSettingsError("reference images are unavailable");
256
+ return host.destination.readReference(reference, model);
257
+ },
258
+ });
259
+ return Response.json(quote, { headers });
260
+ }
261
+ catch (cause) {
262
+ if (cause instanceof MediaSettingsError)
263
+ return failure(cause);
264
+ const error = cause instanceof MediaExecutionError
265
+ ? cause
266
+ : new MediaExecutionError("estimate", { cause });
267
+ return host.onFailure?.(error) ?? failure(error, host.refusalMessages);
268
+ }
269
+ });
227
270
  return app;
228
271
  }
@@ -1,4 +1,9 @@
1
- import type { MediaReferenceBytes } from "../index.js";
2
- /** Encode in multiples of three so only the final chunk needs base64 padding. */
1
+ import type { MediaAudioReferenceBytes, MediaReferenceBytes } from "../index.js";
3
2
  export declare function imageBase64(image: MediaReferenceBytes): string;
3
+ /**
4
+ * One `reference_audios` entry: a `data:audio/...` base64 URI, the form
5
+ * Seedance 2.5's input schema documents next to HTTP(S) URLs.
6
+ * https://developers.cloudflare.com/ai/models/bytedance/seedance-2.5/schema-input.json
7
+ */
8
+ export declare function audioDataUri(clip: MediaAudioReferenceBytes): string;
4
9
  export declare function imageDataUri(image: MediaReferenceBytes): string;
@@ -1,10 +1,21 @@
1
1
  /** Encode in multiples of three so only the final chunk needs base64 padding. */
2
- export function imageBase64(image) {
2
+ function base64(bytes) {
3
3
  const chunks = [];
4
- for (let offset = 0; offset < image.bytes.length; offset += 32_766)
5
- chunks.push(btoa(String.fromCharCode(...image.bytes.subarray(offset, offset + 32_766))));
4
+ for (let offset = 0; offset < bytes.length; offset += 32_766)
5
+ chunks.push(btoa(String.fromCharCode(...bytes.subarray(offset, offset + 32_766))));
6
6
  return chunks.join("");
7
7
  }
8
+ export function imageBase64(image) {
9
+ return base64(image.bytes);
10
+ }
11
+ /**
12
+ * One `reference_audios` entry: a `data:audio/...` base64 URI, the form
13
+ * Seedance 2.5's input schema documents next to HTTP(S) URLs.
14
+ * https://developers.cloudflare.com/ai/models/bytedance/seedance-2.5/schema-input.json
15
+ */
16
+ export function audioDataUri(clip) {
17
+ return `data:${clip.mimeType};base64,${base64(clip.bytes)}`;
18
+ }
8
19
  export function imageDataUri(image) {
9
20
  const mime = image.format === "jpeg" ? "image/jpeg" : `image/${image.format}`;
10
21
  return `data:${mime};base64,${imageBase64(image)}`;
@@ -1,4 +1,4 @@
1
- import type { MediaAiResult, MediaGenerationSettings, MediaReferenceBytes } from "../index.js";
1
+ import type { MediaAiResult, MediaAudioReferenceBytes, MediaGenerationSettings, MediaReferenceBytes } from "../index.js";
2
2
  import type { MediaModel, MediaVideoAspectRatio, MediaVideoModel, MediaVideoResolution } from "../model-catalog.js";
3
3
  import type { UnifiedGatewayInput } from "./unified.js";
4
4
  import type { MinimaxGatewayInput } from "./minimax.js";
@@ -22,7 +22,7 @@ export type VideoProviderInput = UnifiedGatewayInput | MinimaxGatewayInput;
22
22
  */
23
23
  export type VideoProviderAdapter = {
24
24
  /** Build the provider JSON body for one validated video generation. */
25
- buildInput(checked: CheckedVideoSettings, references: readonly MediaReferenceBytes[], model: MediaModel): VideoProviderInput;
25
+ buildInput(checked: CheckedVideoSettings, references: readonly MediaReferenceBytes[], model: MediaModel, audioReferences: readonly MediaAudioReferenceBytes[]): VideoProviderInput;
26
26
  /** Extract and validate the HTTPS result URL from the raw provider answer. */
27
27
  decodeResultUrl(providerValue: MediaAiResult): string;
28
28
  };
@@ -8,6 +8,7 @@ export type UnifiedGatewayInput = {
8
8
  image?: string;
9
9
  last_frame_image?: string;
10
10
  reference_images?: string[];
11
+ reference_audios?: string[];
11
12
  image_input?: string;
12
13
  };
13
14
  /**
@@ -1,13 +1,13 @@
1
1
  import { MediaSettingsError } from "../model-catalog.js";
2
2
  import { gatewayOutputSchema } from "../gateway-wire.js";
3
- import { imageBase64, imageDataUri } from "./reference-encoding.js";
3
+ import { audioDataUri, imageBase64, imageDataUri, } from "./reference-encoding.js";
4
4
  /**
5
5
  * Seedance and Veo share the Unified AI gateway's `{state, result}` answer
6
6
  * and a flat prompt/image request body; only a few fields differ by
7
7
  * provider, handled inline below.
8
8
  */
9
9
  export const unifiedVideoAdapter = {
10
- buildInput(checked, references, model) {
10
+ buildInput(checked, references, model, audioReferences) {
11
11
  const veo = model.video?.provider === "veo";
12
12
  const input = {
13
13
  prompt: checked.prompt,
@@ -39,6 +39,8 @@ export const unifiedVideoAdapter = {
39
39
  });
40
40
  if (referenceImages.length > 0)
41
41
  input.reference_images = referenceImages;
42
+ if (audioReferences.length > 0)
43
+ input.reference_audios = audioReferences.map(audioDataUri);
42
44
  return input;
43
45
  },
44
46
  decodeResultUrl(providerValue) {
@@ -23,10 +23,11 @@ const mediaModelPriceEstimateSchema: ZodObject<{
23
23
  settings: ZodObject<{
24
24
  model: ZodString;
25
25
  prompt: ZodString;
26
- width: ZodNumber;
27
- height: ZodNumber;
26
+ width: ZodOptional<ZodNumber>;
27
+ height: ZodOptional<ZodNumber>;
28
28
  steps: ZodOptional<ZodNumber>;
29
29
  durationSeconds: ZodOptional<ZodNumber>;
30
+ voiceId: ZodOptional<ZodString>;
30
31
  resolution: ZodOptional<ZodEnum<{
31
32
  p480: "480p";
32
33
  p720: "720p";
@@ -53,6 +54,10 @@ const mediaModelPriceEstimateSchema: ZodObject<{
53
54
  reference: ...;
54
55
  }>>;
55
56
  }, $strict>>>;
57
+ audioReferences: ZodOptional<ZodArray<ZodObject<{
58
+ computerId: ZodString;
59
+ path: ZodString;
60
+ }, $strict>>>;
56
61
  }, $strict>;
57
62
  }, $strict>;
58
63
  ```
@@ -75,10 +80,11 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
75
80
  settings: ZodObject<{
76
81
  model: ZodString;
77
82
  prompt: ZodString;
78
- width: ZodNumber;
79
- height: ZodNumber;
83
+ width: ZodOptional<ZodNumber>;
84
+ height: ZodOptional<ZodNumber>;
80
85
  steps: ZodOptional<ZodNumber>;
81
86
  durationSeconds: ZodOptional<ZodNumber>;
87
+ voiceId: ZodOptional<ZodString>;
82
88
  resolution: ZodOptional<ZodEnum<{
83
89
  p480: ...;
84
90
  p720: ...;
@@ -97,6 +103,7 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
97
103
  }>>;
98
104
  generateAudio: ZodOptional<ZodBoolean>;
99
105
  references: ZodOptional<ZodArray<ZodObject<..., ...>>>;
106
+ audioReferences: ZodOptional<ZodArray<ZodObject<..., ...>>>;
100
107
  }, $strict>;
101
108
  }, $strict>>;
102
109
  id: ZodString;
@@ -104,6 +111,7 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
104
111
  kind: ZodEnum<{
105
112
  image: "image";
106
113
  video: "video";
114
+ audio: "audio";
107
115
  }>;
108
116
  tier: ZodEnum<{
109
117
  draft: "draft";
@@ -178,8 +186,20 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
178
186
  referenceRoles: ZodReadonly<ZodArray<ZodEnum<...>>>;
179
187
  maxReferenceImages: ZodNumber;
180
188
  referenceResolutions: ZodReadonly<ZodArray<ZodEnum<...>>>;
189
+ audioReferences: ZodNullable<ZodReadonly<ZodObject<..., ...>>>;
181
190
  prices: ZodReadonly<ZodArray<ZodReadonly<...>>>;
182
191
  }, $strict>>>>;
192
+ audio: ZodNullable<ZodLazy<ZodReadonly<ZodObject<{
193
+ provider: ZodLiteral<"elevenlabs">;
194
+ mode: ZodEnum<{
195
+ speech: "speech";
196
+ music: "music";
197
+ }>;
198
+ voices: ZodReadonly<ZodArray<ZodLazy<...>>>;
199
+ defaultVoiceId: ZodNullable<ZodString>;
200
+ seconds: ZodNullable<ZodReadonly<ZodObject<..., ...>>>;
201
+ milliunitsPerUnit: ZodNumber;
202
+ }, $strict>>>>;
183
203
  }, $strict>>;
184
204
  ```
185
205
 
@@ -201,14 +221,16 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
201
221
  settings: ZodObject<{
202
222
  model: ZodString;
203
223
  prompt: ZodString;
204
- width: ZodNumber;
205
- height: ZodNumber;
224
+ width: ZodOptional<...>;
225
+ height: ZodOptional<...>;
206
226
  steps: ZodOptional<...>;
207
227
  durationSeconds: ZodOptional<...>;
228
+ voiceId: ZodOptional<...>;
208
229
  resolution: ZodOptional<...>;
209
230
  aspectRatio: ZodOptional<...>;
210
231
  generateAudio: ZodOptional<...>;
211
232
  references: ZodOptional<...>;
233
+ audioReferences: ZodOptional<...>;
212
234
  }, $strict>;
213
235
  }, $strict>>;
214
236
  id: ZodString;
@@ -216,6 +238,7 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
216
238
  kind: ZodEnum<{
217
239
  image: "image";
218
240
  video: "video";
241
+ audio: "audio";
219
242
  }>;
220
243
  tier: ZodEnum<{
221
244
  draft: "draft";
@@ -272,8 +295,17 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
272
295
  referenceRoles: ZodReadonly<...>;
273
296
  maxReferenceImages: ZodNumber;
274
297
  referenceResolutions: ZodReadonly<...>;
298
+ audioReferences: ZodNullable<...>;
275
299
  prices: ZodReadonly<...>;
276
300
  }, $strict>>>>;
301
+ audio: ZodNullable<ZodLazy<ZodReadonly<ZodObject<{
302
+ provider: ZodLiteral<...>;
303
+ mode: ZodEnum<...>;
304
+ voices: ZodReadonly<...>;
305
+ defaultVoiceId: ZodNullable<...>;
306
+ seconds: ZodNullable<...>;
307
+ milliunitsPerUnit: ZodNumber;
308
+ }, $strict>>>>;
277
309
  }, $strict>>>>;
278
310
  ```
279
311
 
@@ -317,10 +349,11 @@ const appMediaGenerationResultSchema: ZodObject<
317
349
  gif: "gif";
318
350
  webp: "webp";
319
351
  mp4: "mp4";
352
+ mp3: "mp3";
320
353
  }>;
321
- height: ZodNumber;
354
+ height: ZodOptional<ZodNumber>;
322
355
  model: ZodString;
323
- width: ZodNumber;
356
+ width: ZodOptional<ZodNumber>;
324
357
  },
325
358
  $strict
326
359
  >;
@@ -449,6 +482,7 @@ Missing-library refusal decoded and returned by the App media broker.
449
482
  const appMediaBrokerFailureSchema: ZodObject<{
450
483
  error: ZodEnum<{
451
484
  CAPABILITY_DENIED: "CAPABILITY_DENIED";
485
+ DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
452
486
  INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
453
487
  HOST_FAILURE: "HOST_FAILURE";
454
488
  INVALID_ARGUMENT: "INVALID_ARGUMENT";
@@ -502,6 +536,7 @@ const appMediaRefusalSchema: ZodUnion<readonly [ZodObject<{
502
536
  }, $strict>>, ZodObject<{
503
537
  error: ZodEnum<{
504
538
  CAPABILITY_DENIED: "CAPABILITY_DENIED";
539
+ DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
505
540
  INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
506
541
  HOST_FAILURE: "HOST_FAILURE";
507
542
  INVALID_ARGUMENT: "INVALID_ARGUMENT";
@@ -548,6 +583,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
548
583
  kind: ZodEnum<{
549
584
  image: "image";
550
585
  video: "video";
586
+ audio: "audio";
551
587
  }>;
552
588
  tier: ZodEnum<{
553
589
  draft: "draft";
@@ -578,6 +614,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
578
614
  }, $strict>>>;
579
615
  sizes: ZodNullable<ZodReadonly<ZodArray<ZodString>>>;
580
616
  video: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
617
+ audio: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
581
618
  }, $strict>>>>, ZodUnion<readonly [ZodObject<{
582
619
  error: ZodEnum<{
583
620
  revoked: "revoked";
@@ -597,6 +634,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
597
634
  }, $strict>>, ZodObject<{
598
635
  error: ZodEnum<{
599
636
  CAPABILITY_DENIED: "CAPABILITY_DENIED";
637
+ DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
600
638
  INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
601
639
  HOST_FAILURE: "HOST_FAILURE";
602
640
  INVALID_ARGUMENT: "INVALID_ARGUMENT";
@@ -643,10 +681,11 @@ const appMediaGenerationOutcomeSchema: ZodUnion<readonly [ZodObject<{
643
681
  gif: "gif";
644
682
  webp: "webp";
645
683
  mp4: "mp4";
684
+ mp3: "mp3";
646
685
  }>;
647
- height: ZodNumber;
686
+ height: ZodOptional<ZodNumber>;
648
687
  model: ZodString;
649
- width: ZodNumber;
688
+ width: ZodOptional<ZodNumber>;
650
689
  }, $strict>, ZodObject<{
651
690
  kind: ZodLiteral<"pending">;
652
691
  retryAfterMs: ZodNumber;
@@ -669,6 +708,7 @@ const appMediaGenerationOutcomeSchema: ZodUnion<readonly [ZodObject<{
669
708
  }, $strict>>, ZodObject<{
670
709
  error: ZodEnum<{
671
710
  CAPABILITY_DENIED: "CAPABILITY_DENIED";
711
+ DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
672
712
  INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
673
713
  HOST_FAILURE: "HOST_FAILURE";
674
714
  INVALID_ARGUMENT: "INVALID_ARGUMENT";
@@ -62,6 +62,7 @@ const mediaFailureSchema: ZodObject<{
62
62
  }>;
63
63
  code: ZodEnum<{
64
64
  CAPABILITY_DENIED: "CAPABILITY_DENIED";
65
+ DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
65
66
  INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
66
67
  HOST_FAILURE: "HOST_FAILURE";
67
68
  INVALID_ARGUMENT: "INVALID_ARGUMENT";
@@ -101,6 +102,7 @@ function readMediaFailure(
101
102
  | "destination-write";
102
103
  code:
103
104
  | "CAPABILITY_DENIED"
105
+ | "DAILY_LIMIT_REACHED"
104
106
  | "INSUFFICIENT_CREDIT"
105
107
  | "HOST_FAILURE"
106
108
  | "INVALID_ARGUMENT"
@@ -127,8 +129,8 @@ Read and decode one Media host failure at the browser HTTP boundary.
127
129
  \| `"generation-authorization"` \| `"settings"` \| `"estimate"` \| `"billing"`
128
130
  \| `"operation"` \| `"normalization"` \| `"artifact"` \|
129
131
  `"destination-authorization"` \| `"destination-write"`; `code`: \|
130
- `"CAPABILITY_DENIED"` \| `"INSUFFICIENT_CREDIT"` \| `"HOST_FAILURE"` \|
131
- `"INVALID_ARGUMENT"` \| `"MEDIA_PROVIDER_FAILURE"` \|
132
+ `"CAPABILITY_DENIED"` \| `"DAILY_LIMIT_REACHED"` \| `"INSUFFICIENT_CREDIT"` \|
133
+ `"HOST_FAILURE"` \| `"INVALID_ARGUMENT"` \| `"MEDIA_PROVIDER_FAILURE"` \|
132
134
  `"MEDIA_PROVIDER_FAILURE_UNCHARGED"` \| `"SAFETY_FILTER_REFUSED"`; `retryable`:
133
135
  `boolean`; `provider?`: `MediaProviderDiagnostic`; \} \| `null`\>
134
136
 
@@ -18,6 +18,10 @@ Cloudflare lifecycle and RPC surface around the durable media owner.
18
18
 
19
19
  - `DurableObject`\<[`MediaOperationCloudflareEnvironment`](#mediaoperationcloudflareenvironment)\>
20
20
 
21
+ #### Implements
22
+
23
+ - [`DailyMediaMeterPort`](server.md#dailymediameterport)
24
+
21
25
  #### Constructors
22
26
 
23
27
  ##### Constructor
@@ -45,6 +49,55 @@ DurableObject<MediaOperationCloudflareEnvironment>.constructor
45
49
 
46
50
  #### Methods
47
51
 
52
+ ##### dailyAdmit()
53
+
54
+ ```ts
55
+ dailyAdmit(...input): boolean;
56
+ ```
57
+
58
+ Admit one generation against today's hard stop; false means the daily limit is
59
+ reached.
60
+
61
+ ###### Parameters
62
+
63
+ | Parameter | Type |
64
+ | ---------- | --------------------------------------------------------------------------------------------------------- |
65
+ | ...`input` | \[`Readonly`\<\{ `operationId`: `string`; `costMilliunits`: `number`; `limitMilliunits`: `number`; \}\>\] |
66
+
67
+ ###### Returns
68
+
69
+ `boolean`
70
+
71
+ ###### Implementation of
72
+
73
+ ```ts
74
+ DailyMediaMeterPort.dailyAdmit;
75
+ ```
76
+
77
+ ##### dailySettle()
78
+
79
+ ```ts
80
+ dailySettle(...input): void;
81
+ ```
82
+
83
+ Settle an admitted generation once its outcome is known.
84
+
85
+ ###### Parameters
86
+
87
+ | Parameter | Type |
88
+ | ---------- | ------------------------------------------------------------------------ |
89
+ | ...`input` | \[`Readonly`\<\{ `operationId`: `string`; `delivered`: `boolean`; \}\>\] |
90
+
91
+ ###### Returns
92
+
93
+ `void`
94
+
95
+ ###### Implementation of
96
+
97
+ ```ts
98
+ DailyMediaMeterPort.dailySettle;
99
+ ```
100
+
48
101
  ##### read()
49
102
 
50
103
  ```ts
@@ -321,9 +374,9 @@ output, and releases the lease so a later retry saves and charges it.
321
374
 
322
375
  ###### Parameters
323
376
 
324
- | Parameter | Type | Description |
325
- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
326
- | ...`input` | \[`string`, readonly `Readonly`\<\{ `bytes`: `Uint8Array`; `format`: [`ImageFormat`](index.md#imageformat); `width`: `number`; `height`: `number`; `filename?`: `string`; \}\>[]\] | - |
377
+ | Parameter | Type | Description |
378
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
379
+ | ...`input` | \[`string`, readonly `Readonly`\<\{ `bytes`: `Uint8Array`; `format`: [`ImageFormat`](index.md#imageformat); `width`: `number`; `height`: `number`; `filename?`: `string`; \}\>[], readonly `Readonly`\<\{ `bytes`: `Uint8Array`; `mimeType`: [`AudioReferenceMimeType`](index.md#audioreferencemimetype); `durationSeconds`: `number`; `filename?`: `string`; \}\>[]\] | - |
327
380
 
328
381
  ###### Returns
329
382