@fungi.computer/darkroom 0.9.2 → 0.10.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.
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as z from "zod";
2
2
  import { reportCatchFailure } from "./failure.js";
3
+ import { sniffImageFormat } from "./media-content-type.js";
3
4
  import { referenceImageSizeIsValid } from "./reference-image-size.js";
4
- import { getGatewayModel, getMediaModel, mediaAudioModelIdSchema, MAX_REFERENCE_COUNT, MediaSettingsError, mediaModels, mediaVideoModelIdSchema, mediaVideoResolutionSchema, mediaVideoAspectRatioSchema, mediaVideoReferenceRoleSchema, MAX_MEDIA_PROMPT_LENGTH, } from "./model-catalog.js";
5
+ import { getGatewayModel, getMediaModel, mediaAudioModelIdSchema, MAX_REFERENCE_COUNT, MediaSettingsError, mediaModels, mediaVideoModelIdSchema, mediaVideoResolutionSchema, mediaVideoAspectRatioSchema, mediaVideoReferenceRoleSchema, MAX_MEDIA_PROMPT_LENGTH, transformMilliunits, } from "./model-catalog.js";
5
6
  export { mediaFailureStageSchema } from "./execution-error.js";
6
7
  export { MAX_AUDIO_REFERENCE_BODY_BYTES, MAX_AUDIO_REFERENCE_BYTES, } from "./audio-reference-types.js";
7
- export { MAX_MEDIA_PROMPT_LENGTH, getMediaModel, getGatewayModel, MAX_REFERENCE_COUNT, listMediaModels, mediaCatalogueSchema, mediaCatalogueModelSchema, parseMediaCatalogue, mediaModelInputSchema, mediaModelSchema, mediaRequestedImageFormatSchema, mediaModels, mediaModelTierSchema, MediaSettingsError, mediaVideoModelIdSchema, mediaVideoResolutionSchema, mediaVideoAspectRatioSchema, mediaVideoReferenceRoleSchema, mediaVideoFormatSchema, mediaVideoSchema, mediaAudioModelIdSchema, mediaAudioSchema, mediaAudioVoiceSchema, AUDIO_CHARACTER_BLOCK, } from "./model-catalog.js";
8
+ export { MAX_MEDIA_PROMPT_LENGTH, getMediaModel, getGatewayModel, MAX_REFERENCE_COUNT, listMediaModels, mediaCatalogueSchema, mediaCatalogueModelSchema, parseMediaCatalogue, mediaModelInputSchema, mediaModelSchema, mediaRequestedImageFormatSchema, mediaModels, mediaModelTierSchema, MediaSettingsError, mediaVideoModelIdSchema, mediaVideoResolutionSchema, mediaVideoAspectRatioSchema, mediaVideoReferenceRoleSchema, mediaVideoFormatSchema, mediaVideoSchema, mediaAudioModelIdSchema, mediaAudioSchema, mediaAudioVoiceSchema, mediaBillingUnitSchema, AUDIO_CHARACTER_BLOCK, mediaTransformSchema, mediaTransformOperationSchema, } from "./model-catalog.js";
8
9
  /** The long-edge bounds a viewer may ask for when fitting an image to look at. */
9
10
  export const MIN_VIEW_DIMENSION = 256;
10
11
  /** Maximum long-edge size accepted by an image viewer, in pixels. */
@@ -61,6 +62,8 @@ export const mediaGenerationSettingsSchema = z
61
62
  steps: z.number().int().optional(),
62
63
  /** Requested video or music length in whole seconds. */
63
64
  durationSeconds: z.number().int().optional(),
65
+ /** Upscale only: the output size in megapixels, one of the model's offered sizes. */
66
+ targetMegapixels: z.number().int().optional(),
64
67
  /** Speech models only: a premade voice from the catalog; the default when omitted. */
65
68
  voiceId: z.string().min(1).max(64).optional(),
66
69
  /** Video resolution; must match the nominal width/height selector. */
@@ -181,6 +184,10 @@ function normalizeGenerationSettings(input, normalize, catalogue) {
181
184
  }
182
185
  if (input.voiceId !== undefined)
183
186
  throw new MediaSettingsError(`${model.id} does not take a voice`);
187
+ if (model.transform !== null)
188
+ return normalizeTransformSettings(model, model.transform, prompt, input, normalize);
189
+ if (input.targetMegapixels !== undefined)
190
+ throw new MediaSettingsError(`${model.id} does not take an output size`);
184
191
  if (input.width === undefined || input.height === undefined)
185
192
  throw new MediaSettingsError(`${model.id} needs a width and a height`);
186
193
  const maximumDimension = model.video === null ? 4_096 : 5_040;
@@ -395,6 +402,40 @@ export function validateMediaVideoSelection(raw, catalogue = mediaModels) {
395
402
  selection.audioReferences = Object.freeze(normalized.audioReferences.map((reference) => Object.freeze(mediaAudioReferenceSelectionSchema.parse(reference))));
396
403
  return Object.freeze(selection);
397
404
  }
405
+ /**
406
+ * A source-image operation takes exactly one reference and, for an upscale, one
407
+ * of the model's offered output sizes. Its output size is the provider's, so it
408
+ * takes no width, height, steps or video settings.
409
+ */
410
+ function normalizeTransformSettings(model, transform, prompt, input, normalize) {
411
+ if (input.width !== undefined ||
412
+ input.height !== undefined ||
413
+ input.steps !== undefined ||
414
+ input.durationSeconds !== undefined ||
415
+ input.resolution !== undefined ||
416
+ input.aspectRatio !== undefined ||
417
+ input.generateAudio !== undefined ||
418
+ input.audioReferences !== undefined)
419
+ throw new MediaSettingsError(`${model.id} takes one source image${transform.defaultMegapixels === null ? "" : " and an output size"}`);
420
+ const references = input.references;
421
+ if (references?.length !== 1 || references[0]?.role !== undefined)
422
+ throw new MediaSettingsError(`${model.id} needs exactly one source image`);
423
+ const settings = {
424
+ model: model.id,
425
+ prompt,
426
+ references: Object.freeze(references.map(normalize)),
427
+ };
428
+ if (transform.defaultMegapixels === null) {
429
+ if (input.targetMegapixels !== undefined)
430
+ throw new MediaSettingsError(`${model.id} does not take an output size`);
431
+ return Object.freeze(settings);
432
+ }
433
+ const target = input.targetMegapixels ?? transform.defaultMegapixels;
434
+ if (transformMilliunits(transform, target) === undefined)
435
+ throw new MediaSettingsError(`${model.id} accepts output sizes of ${transform.sizes.map((price) => String(price.megapixels)).join(", ")} megapixels`);
436
+ settings.targetMegapixels = target;
437
+ return Object.freeze(settings);
438
+ }
398
439
  /** Neutral audio selection: speech takes a voice, music a length; model-specific limits are checked by validateMediaGenerationSettings. */
399
440
  export const mediaAudioSelectionSchema = z.lazy(() => z.strictObject({
400
441
  /** Verified catalog audio model identifier. */
@@ -407,6 +448,25 @@ export const mediaAudioSelectionSchema = z.lazy(() => z.strictObject({
407
448
  durationSeconds: z.number().int().min(3).max(600).optional(),
408
449
  }));
409
450
  const imageFormats = new Set(["png", "jpeg", "gif", "webp"]);
451
+ /**
452
+ * Refuse a source image the operation cannot take, with plain copy, before any
453
+ * paid call: an unsupported encoding, a source over Botanical's size bounds,
454
+ * or an upscale whose source is already as large as the chosen output.
455
+ */
456
+ function checkTransformSource(model, transform, settings, image) {
457
+ const { source } = transform;
458
+ const named = (format) => (format === "jpeg" ? "JPEG" : "PNG");
459
+ if (!source.formats.some((format) => format === image.format))
460
+ throw new MediaSettingsError(`${model.label} takes ${source.formats.map(named).join(" or ")} images, not ${image.format.toUpperCase()}.`);
461
+ if (image.bytes.byteLength > source.maxBytes)
462
+ throw new MediaSettingsError(`That image is over ${String(source.maxBytes / (1024 * 1024))} MB, the most ${model.label} takes.`);
463
+ const pixels = image.width * image.height;
464
+ if (pixels > source.maxPixels)
465
+ throw new MediaSettingsError(`That image is over ${String(source.maxPixels / 1_000_000)} megapixels, the most ${model.label} takes.`);
466
+ const target = settings.targetMegapixels;
467
+ if (target !== undefined && pixels >= target * 1_000_000)
468
+ throw new MediaSettingsError(`That image is already ${(pixels / 1_000_000).toFixed(1)} megapixels. Choose a larger output than ${String(target)} megapixels.`);
469
+ }
410
470
  /** Resolve only provider-accepted references through the caller's reader. */
411
471
  export const resolveMediaReferences = async (settings, reader, catalogue = mediaModels) => {
412
472
  const model = getMediaModel(settings.model, catalogue);
@@ -429,6 +489,8 @@ export const resolveMediaReferences = async (settings, reader, catalogue = media
429
489
  image.bytes.byteLength === 0 ||
430
490
  image.bytes.byteLength > MAX_REFERENCE_BYTES)
431
491
  throw new MediaSettingsError(`reference ${reference.computerId}:${reference.path} exceeds the bounded image contract`);
492
+ if (model.transform !== null)
493
+ checkTransformSource(model, model.transform, settings, image);
432
494
  totalBytes += image.bytes.byteLength;
433
495
  if (totalBytes > MAX_REFERENCE_BODY_BYTES)
434
496
  throw new MediaSettingsError("reference images exceed the total request size limit");
@@ -552,42 +614,6 @@ export const parseMediaProviderOutput = (value) => {
552
614
  entries: parsed.images,
553
615
  };
554
616
  };
555
- const sniffImageFormat = (bytes) => {
556
- if (bytes.length >= 8 &&
557
- bytes[0] === 0x89 &&
558
- bytes[1] === 0x50 &&
559
- bytes[2] === 0x4e &&
560
- bytes[3] === 0x47 &&
561
- bytes[4] === 0x0d &&
562
- bytes[5] === 0x0a &&
563
- bytes[6] === 0x1a &&
564
- bytes[7] === 0x0a)
565
- return "png";
566
- if (bytes.length >= 3 &&
567
- bytes[0] === 0xff &&
568
- bytes[1] === 0xd8 &&
569
- bytes[2] === 0xff)
570
- return "jpeg";
571
- if (bytes.length >= 6 &&
572
- bytes[0] === 0x47 &&
573
- bytes[1] === 0x49 &&
574
- bytes[2] === 0x46 &&
575
- bytes[3] === 0x38 &&
576
- (bytes[4] === 0x37 || bytes[4] === 0x39) &&
577
- bytes[5] === 0x61)
578
- return "gif";
579
- if (bytes.length >= 12 &&
580
- bytes[0] === 0x52 &&
581
- bytes[1] === 0x49 &&
582
- bytes[2] === 0x46 &&
583
- bytes[3] === 0x46 &&
584
- bytes[8] === 0x57 &&
585
- bytes[9] === 0x45 &&
586
- bytes[10] === 0x42 &&
587
- bytes[11] === 0x50)
588
- return "webp";
589
- return undefined;
590
- };
591
617
  const decodeEncoded = (value, maximumBytes) => {
592
618
  const comma = value.startsWith("data:") ? value.indexOf(",") : -1;
593
619
  const payload = comma >= 0 ? value.slice(comma + 1) : value;
@@ -34,6 +34,7 @@ export declare const mediaImageBindingInputSchema: z.ZodObject<{
34
34
  }, z.core.$strict>>>;
35
35
  model: z.ZodString;
36
36
  prompt: z.ZodString;
37
+ targetMegapixels: z.ZodOptional<z.ZodNumber>;
37
38
  generateAudio: z.ZodOptional<z.ZodBoolean>;
38
39
  width: z.ZodNumber;
39
40
  height: z.ZodNumber;
@@ -141,6 +142,7 @@ export declare const mediaBindingGenerationSchema: z.ZodDiscriminatedUnion<[z.Zo
141
142
  }, z.core.$strict>>>;
142
143
  model: z.ZodString;
143
144
  prompt: z.ZodString;
145
+ targetMegapixels: z.ZodOptional<z.ZodNumber>;
144
146
  generateAudio: z.ZodOptional<z.ZodBoolean>;
145
147
  width: z.ZodNumber;
146
148
  height: z.ZodNumber;
@@ -251,6 +253,7 @@ export declare const mediaBindingCallSchema: z.ZodDiscriminatedUnion<[z.ZodObjec
251
253
  }, z.core.$strict>>>;
252
254
  model: z.ZodString;
253
255
  prompt: z.ZodString;
256
+ targetMegapixels: z.ZodOptional<z.ZodNumber>;
254
257
  generateAudio: z.ZodOptional<z.ZodBoolean>;
255
258
  width: z.ZodNumber;
256
259
  height: z.ZodNumber;
@@ -0,0 +1,5 @@
1
+ import type { ImageFormat } from "./index.js";
2
+ /** The image encoding named by the file's magic bytes, if any. */
3
+ export declare const sniffImageFormat: (bytes: Uint8Array) => ImageFormat | undefined;
4
+ /** The MIME type for generated bytes, from their magic numbers. */
5
+ export declare const mediaContentType: (bytes: Uint8Array) => string;
@@ -0,0 +1,49 @@
1
+ import { isMp4 } from "./gateway-wire.js";
2
+ /** The image encoding named by the file's magic bytes, if any. */
3
+ export const sniffImageFormat = (bytes) => {
4
+ if (bytes.length >= 8 &&
5
+ bytes[0] === 0x89 &&
6
+ bytes[1] === 0x50 &&
7
+ bytes[2] === 0x4e &&
8
+ bytes[3] === 0x47 &&
9
+ bytes[4] === 0x0d &&
10
+ bytes[5] === 0x0a &&
11
+ bytes[6] === 0x1a &&
12
+ bytes[7] === 0x0a)
13
+ return "png";
14
+ if (bytes.length >= 3 &&
15
+ bytes[0] === 0xff &&
16
+ bytes[1] === 0xd8 &&
17
+ bytes[2] === 0xff)
18
+ return "jpeg";
19
+ if (bytes.length >= 6 &&
20
+ bytes[0] === 0x47 &&
21
+ bytes[1] === 0x49 &&
22
+ bytes[2] === 0x46 &&
23
+ bytes[3] === 0x38 &&
24
+ (bytes[4] === 0x37 || bytes[4] === 0x39) &&
25
+ bytes[5] === 0x61)
26
+ return "gif";
27
+ if (bytes.length >= 12 &&
28
+ bytes[0] === 0x52 &&
29
+ bytes[1] === 0x49 &&
30
+ bytes[2] === 0x46 &&
31
+ bytes[3] === 0x46 &&
32
+ bytes[8] === 0x57 &&
33
+ bytes[9] === 0x45 &&
34
+ bytes[10] === 0x42 &&
35
+ bytes[11] === 0x50)
36
+ return "webp";
37
+ return undefined;
38
+ };
39
+ /** The MIME type for generated bytes, from their magic numbers. */
40
+ export const mediaContentType = (bytes) => {
41
+ const image = sniffImageFormat(bytes);
42
+ if (image !== undefined)
43
+ return `image/${image}`;
44
+ if (isMp4(bytes))
45
+ return "video/mp4";
46
+ const id3 = bytes[0] === 0x49 && bytes[1] === 0x44 && bytes[2] === 0x33;
47
+ const frame = bytes[0] === 0xff && ((bytes[1] ?? 0) & 0xe0) === 0xe0;
48
+ return id3 || frame ? "audio/mpeg" : "application/octet-stream";
49
+ };
@@ -4,9 +4,8 @@ import { mediaGenerationSettingsSchema, validateMediaGenerationSettings, } from
4
4
  import { z } from "zod";
5
5
  import { reportCatchFailure } from "./failure.js";
6
6
  import { MediaExecutionError, MediaSafetyFilterRefusal, mediaFailureStageSchema, } from "./execution-error.js";
7
+ import { backgroundProviderTimeoutMs } from "./media-run-lifetime.js";
7
8
  import { mediaProviderDiagnosticWireSchema, } from "@fungi.computer/agar/errors";
8
- /** Safely inside the 15-minute alarm wall-clock limit that would kill the call. */
9
- const backgroundProviderTimeoutMs = 12 * 60_000;
10
9
  const providerFailureSchema = z.strictObject({
11
10
  stage: mediaFailureStageSchema.extract(["provider", "normalization"]),
12
11
  safetyRefused: z.boolean(),
@@ -0,0 +1,3 @@
1
+ import * as z from "zod";
2
+ /** A fixed destination or reference path: an R2 object key or a file path, never a URL. */
3
+ export declare const mediaPathSchema: z.ZodString;
@@ -0,0 +1,7 @@
1
+ import * as z from "zod";
2
+ /** A fixed destination or reference path: an R2 object key or a file path, never a URL. */
3
+ export const mediaPathSchema = z
4
+ .string()
5
+ .min(1)
6
+ .max(1_024)
7
+ .refine((path) => !path.includes("\0"));
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The longest a background provider call runs before it is cut off, safely
3
+ * inside the 15-minute alarm wall-clock limit that would kill the call.
4
+ */
5
+ export declare const backgroundProviderTimeoutMs: number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The longest a background provider call runs before it is cut off, safely
3
+ * inside the 15-minute alarm wall-clock limit that would kill the call.
4
+ */
5
+ export const backgroundProviderTimeoutMs = 12 * 60_000;
@@ -342,6 +342,75 @@ export declare const AUDIO_CHARACTER_BLOCK = 100;
342
342
  * `maxPromptLength` is the real bound; no model may exceed this ceiling.
343
343
  */
344
344
  export declare const MAX_MEDIA_PROMPT_LENGTH = 32000;
345
+ /**
346
+ * What a source-image operation does to its one reference image. Both write a
347
+ * new image and never touch the source.
348
+ */
349
+ export declare const mediaTransformOperationSchema: z.ZodEnum<{
350
+ /** Cut the foreground out onto a transparent PNG. */
351
+ readonly remove_background: "remove_background";
352
+ /** Enlarge the image to a chosen output size in megapixels. */
353
+ readonly upscale: "upscale";
354
+ }>;
355
+ /** A source-image operation. */
356
+ export type MediaTransformOperation = z.output<typeof mediaTransformOperationSchema>;
357
+ /**
358
+ * Facts of a catalog entry that edits one source image rather than generating
359
+ * from a prompt. The source limits are Botanical's own conservative bounds, not
360
+ * Cloudflare's: neither model page publishes an input size limit.
361
+ */
362
+ export declare const mediaTransformSchema: z.ZodLazy<z.ZodReadonly<z.ZodObject<{
363
+ operation: z.ZodEnum<{
364
+ /** Cut the foreground out onto a transparent PNG. */
365
+ readonly remove_background: "remove_background";
366
+ /** Enlarge the image to a chosen output size in megapixels. */
367
+ readonly upscale: "upscale";
368
+ }>;
369
+ source: z.ZodReadonly<z.ZodObject<{
370
+ formats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
371
+ /** PNG image encoding. */
372
+ readonly png: "png";
373
+ /** JPEG image encoding. */
374
+ readonly jpeg: "jpeg";
375
+ /** WebP image encoding. */
376
+ readonly webp: "webp";
377
+ }>>>;
378
+ maxBytes: z.ZodNumber;
379
+ maxPixels: z.ZodNumber;
380
+ }, z.core.$strict>>;
381
+ defaultMegapixels: z.ZodNullable<z.ZodNumber>;
382
+ milliunits: z.ZodNullable<z.ZodNumber>;
383
+ sizes: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
384
+ megapixels: z.ZodNumber;
385
+ milliunits: z.ZodNumber;
386
+ }, z.core.$strict>>>>;
387
+ }, z.core.$strict>>>;
388
+ /** Immutable source-image operation facts. */
389
+ export type MediaTransform = z.output<typeof mediaTransformSchema>;
390
+ /**
391
+ * What one generation bills: whole images, whole seconds of video or music, or
392
+ * blocks of {@link AUDIO_CHARACTER_BLOCK} speech characters (so a per-character
393
+ * provider rate is marked up once per block, not rounded up per character).
394
+ */
395
+ export declare const mediaBillingUnitSchema: z.ZodEnum<{
396
+ /** One image. */
397
+ readonly image: "image";
398
+ /** One whole second of video. */
399
+ readonly video_second: "video_second";
400
+ /** One whole second of music. */
401
+ readonly audio_second: "audio_second";
402
+ /** One block of speech characters. */
403
+ readonly audio_character_block: "audio_character_block";
404
+ }>;
405
+ /** The unit a model's generations are billed in. */
406
+ export type MediaBillingUnit = z.output<typeof mediaBillingUnitSchema>;
407
+ /** The one rule mapping a model's kind (and speech or music mode) to its billing unit. */
408
+ export declare const mediaBillingUnit: (model: Readonly<{
409
+ kind: "image" | "video" | "audio";
410
+ audio: Readonly<{
411
+ mode: "speech" | "music";
412
+ }> | null;
413
+ }>) => MediaBillingUnit;
345
414
  /** Public wire grammar for a catalog entry returned by the Media owner. */
346
415
  export declare const mediaModelSchema: z.ZodReadonly<z.ZodObject<{
347
416
  id: z.ZodString;
@@ -548,6 +617,42 @@ export declare const mediaModelSchema: z.ZodReadonly<z.ZodObject<{
548
617
  }, z.core.$strict>>>;
549
618
  milliunitsPerUnit: z.ZodNumber;
550
619
  }, z.core.$strict>>>>;
620
+ billingUnit: z.ZodEnum<{
621
+ /** One image. */
622
+ readonly image: "image";
623
+ /** One whole second of video. */
624
+ readonly video_second: "video_second";
625
+ /** One whole second of music. */
626
+ readonly audio_second: "audio_second";
627
+ /** One block of speech characters. */
628
+ readonly audio_character_block: "audio_character_block";
629
+ }>;
630
+ transform: z.ZodNullable<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
631
+ operation: z.ZodEnum<{
632
+ /** Cut the foreground out onto a transparent PNG. */
633
+ readonly remove_background: "remove_background";
634
+ /** Enlarge the image to a chosen output size in megapixels. */
635
+ readonly upscale: "upscale";
636
+ }>;
637
+ source: z.ZodReadonly<z.ZodObject<{
638
+ formats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
639
+ /** PNG image encoding. */
640
+ readonly png: "png";
641
+ /** JPEG image encoding. */
642
+ readonly jpeg: "jpeg";
643
+ /** WebP image encoding. */
644
+ readonly webp: "webp";
645
+ }>>>;
646
+ maxBytes: z.ZodNumber;
647
+ maxPixels: z.ZodNumber;
648
+ }, z.core.$strict>>;
649
+ defaultMegapixels: z.ZodNullable<z.ZodNumber>;
650
+ milliunits: z.ZodNullable<z.ZodNumber>;
651
+ sizes: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
652
+ megapixels: z.ZodNumber;
653
+ milliunits: z.ZodNumber;
654
+ }, z.core.$strict>>>>;
655
+ }, z.core.$strict>>>>;
551
656
  }, z.core.$strict>>;
552
657
  /** Model-specific dimensions, steps, transport and reference limits. */
553
658
  export type MediaModelInput = z.output<typeof mediaModelInputSchema>;
@@ -628,6 +733,16 @@ export declare const mediaCatalogueModelSchema: z.ZodReadonly<z.ZodObject<{
628
733
  }>;
629
734
  }, z.core.$strict>>>;
630
735
  sizes: z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
736
+ billingUnit: z.ZodOptional<z.ZodEnum<{
737
+ /** One image. */
738
+ readonly image: "image";
739
+ /** One whole second of video. */
740
+ readonly video_second: "video_second";
741
+ /** One whole second of music. */
742
+ readonly audio_second: "audio_second";
743
+ /** One block of speech characters. */
744
+ readonly audio_character_block: "audio_character_block";
745
+ }>>;
631
746
  audio: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
632
747
  provider: z.ZodLiteral<"elevenlabs">;
633
748
  mode: z.ZodEnum<{
@@ -648,6 +763,32 @@ export declare const mediaCatalogueModelSchema: z.ZodReadonly<z.ZodObject<{
648
763
  }, z.core.$strict>>>;
649
764
  milliunitsPerUnit: z.ZodNumber;
650
765
  }, z.core.$strict>>>>;
766
+ transform: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
767
+ operation: z.ZodEnum<{
768
+ /** Cut the foreground out onto a transparent PNG. */
769
+ readonly remove_background: "remove_background";
770
+ /** Enlarge the image to a chosen output size in megapixels. */
771
+ readonly upscale: "upscale";
772
+ }>;
773
+ source: z.ZodReadonly<z.ZodObject<{
774
+ formats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
775
+ /** PNG image encoding. */
776
+ readonly png: "png";
777
+ /** JPEG image encoding. */
778
+ readonly jpeg: "jpeg";
779
+ /** WebP image encoding. */
780
+ readonly webp: "webp";
781
+ }>>>;
782
+ maxBytes: z.ZodNumber;
783
+ maxPixels: z.ZodNumber;
784
+ }, z.core.$strict>>;
785
+ defaultMegapixels: z.ZodNullable<z.ZodNumber>;
786
+ milliunits: z.ZodNullable<z.ZodNumber>;
787
+ sizes: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
788
+ megapixels: z.ZodNumber;
789
+ milliunits: z.ZodNumber;
790
+ }, z.core.$strict>>>>;
791
+ }, z.core.$strict>>>>;
651
792
  video: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
652
793
  minSeconds: z.ZodNumber;
653
794
  maxSeconds: z.ZodNumber;
@@ -846,6 +987,16 @@ export declare const mediaCatalogueSchema: z.ZodPipe<z.ZodArray<z.ZodReadonly<z.
846
987
  }>;
847
988
  }, z.core.$strict>>>;
848
989
  sizes: z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
990
+ billingUnit: z.ZodOptional<z.ZodEnum<{
991
+ /** One image. */
992
+ readonly image: "image";
993
+ /** One whole second of video. */
994
+ readonly video_second: "video_second";
995
+ /** One whole second of music. */
996
+ readonly audio_second: "audio_second";
997
+ /** One block of speech characters. */
998
+ readonly audio_character_block: "audio_character_block";
999
+ }>>;
849
1000
  audio: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
850
1001
  provider: z.ZodLiteral<"elevenlabs">;
851
1002
  mode: z.ZodEnum<{
@@ -866,6 +1017,32 @@ export declare const mediaCatalogueSchema: z.ZodPipe<z.ZodArray<z.ZodReadonly<z.
866
1017
  }, z.core.$strict>>>;
867
1018
  milliunitsPerUnit: z.ZodNumber;
868
1019
  }, z.core.$strict>>>>;
1020
+ transform: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
1021
+ operation: z.ZodEnum<{
1022
+ /** Cut the foreground out onto a transparent PNG. */
1023
+ readonly remove_background: "remove_background";
1024
+ /** Enlarge the image to a chosen output size in megapixels. */
1025
+ readonly upscale: "upscale";
1026
+ }>;
1027
+ source: z.ZodReadonly<z.ZodObject<{
1028
+ formats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
1029
+ /** PNG image encoding. */
1030
+ readonly png: "png";
1031
+ /** JPEG image encoding. */
1032
+ readonly jpeg: "jpeg";
1033
+ /** WebP image encoding. */
1034
+ readonly webp: "webp";
1035
+ }>>>;
1036
+ maxBytes: z.ZodNumber;
1037
+ maxPixels: z.ZodNumber;
1038
+ }, z.core.$strict>>;
1039
+ defaultMegapixels: z.ZodNullable<z.ZodNumber>;
1040
+ milliunits: z.ZodNullable<z.ZodNumber>;
1041
+ sizes: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
1042
+ megapixels: z.ZodNumber;
1043
+ milliunits: z.ZodNumber;
1044
+ }, z.core.$strict>>>>;
1045
+ }, z.core.$strict>>>>;
869
1046
  video: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
870
1047
  minSeconds: z.ZodNumber;
871
1048
  maxSeconds: z.ZodNumber;
@@ -1023,6 +1200,20 @@ export declare const mediaCatalogueSchema: z.ZodPipe<z.ZodArray<z.ZodReadonly<z.
1023
1200
  }> | null;
1024
1201
  milliunitsPerUnit: number;
1025
1202
  }> | null;
1203
+ transform: Readonly<{
1204
+ operation: "remove_background" | "upscale";
1205
+ source: Readonly<{
1206
+ formats: readonly ("png" | "jpeg" | "webp")[];
1207
+ maxBytes: number;
1208
+ maxPixels: number;
1209
+ }>;
1210
+ defaultMegapixels: number | null;
1211
+ milliunits: number | null;
1212
+ sizes: readonly Readonly<{
1213
+ megapixels: number;
1214
+ milliunits: number;
1215
+ }>[];
1216
+ }> | null;
1026
1217
  video: Readonly<{
1027
1218
  minSeconds: number;
1028
1219
  maxSeconds: number;
@@ -1052,9 +1243,19 @@ export declare const mediaCatalogueSchema: z.ZodPipe<z.ZodArray<z.ZodReadonly<z.
1052
1243
  }> | null;
1053
1244
  provider: "seedance" | "veo" | "minimax" | "host";
1054
1245
  }> | null;
1246
+ billingUnit?: "image" | "video_second" | "audio_second" | "audio_character_block" | undefined;
1055
1247
  }>[]>>;
1056
1248
  /** Decode untrusted catalogue data, throwing a MediaSettingsError that names the first problem. */
1057
1249
  export declare const parseMediaCatalogue: (raw: unknown) => MediaCatalogue;
1250
+ /** A catalogue entry as the public `/models` list returns it: the entry plus its derived billing unit. */
1251
+ export declare const withBillingUnit: (model: MediaCatalogueModel) => MediaCatalogueModel & Readonly<{
1252
+ billingUnit: MediaBillingUnit;
1253
+ }>;
1254
+ /**
1255
+ * Provider milliunits for one image of a source-image operation at `megapixels`
1256
+ * (omitted: the model's default), or undefined when that output size is not offered.
1257
+ */
1258
+ export declare const transformMilliunits: (transform: MediaTransform, megapixels: number | undefined) => number | undefined;
1058
1259
  /** List the gateway provider's models in catalog order. */
1059
1260
  export declare const listMediaModels: () => readonly MediaModel[];
1060
1261
  /** Find a model in the Fungi gateway's own catalogue; gateway-internal code never sees a custom provider's models. */