@fungi.computer/darkroom 0.6.0 → 0.7.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/README.md +129 -0
- package/dist/app-media-contracts.d.ts +4 -0
- package/dist/browser-failure.d.ts +2 -0
- package/dist/browser-failure.js +2 -0
- package/dist/cloudflare/provider.js +3 -3
- package/dist/cloudflare/reference-images.d.ts +6 -0
- package/dist/cloudflare/reference-images.js +25 -7
- package/dist/cost-estimate.js +2 -2
- package/dist/daily-media-meter.d.ts +55 -0
- package/dist/daily-media-meter.js +81 -0
- package/dist/execution-error.d.ts +1 -1
- package/dist/gateway-models.d.ts +8 -2
- package/dist/gateway-models.js +24 -7
- package/dist/gateway-wire.d.ts +1 -0
- package/dist/gateway-wire.js +2 -0
- package/dist/index.d.ts +49 -12
- package/dist/index.js +31 -21
- package/dist/media-binding.js +3 -3
- package/dist/media-generation.js +9 -5
- package/dist/media-operation-contract.d.ts +3 -1
- package/dist/media-operation-do.d.ts +13 -2
- package/dist/media-operation-do.js +26 -1
- package/dist/media-operation-owner.d.ts +8 -0
- package/dist/media-operation-owner.js +8 -5
- package/dist/media-operation.js +2 -2
- package/dist/media-quote.d.ts +14 -0
- package/dist/media-quote.js +17 -0
- package/dist/model-catalog.d.ts +435 -4
- package/dist/model-catalog.js +130 -6
- package/dist/reference-image-size.d.ts +4 -3
- package/dist/reference-image-size.js +9 -9
- package/dist/server.d.ts +17 -1
- package/dist/server.js +44 -6
- package/docs/api/app-media-contracts.md +4 -0
- package/docs/api/browser.md +4 -2
- package/docs/api/cloudflare.md +53 -0
- package/docs/api/index.md +461 -54
- package/docs/api/server.md +194 -5
- package/package.json +2 -2
package/dist/model-catalog.d.ts
CHANGED
|
@@ -473,12 +473,443 @@ export declare const mediaModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
473
473
|
export type MediaModelInput = z.output<typeof mediaModelInputSchema>;
|
|
474
474
|
/** One immutable provider catalog entry. */
|
|
475
475
|
export type MediaModel = z.output<typeof mediaModelSchema>;
|
|
476
|
-
/** The immutable image and video model catalog. */
|
|
476
|
+
/** The Fungi gateway provider's own immutable image and video model catalog. */
|
|
477
477
|
export declare const mediaModels: readonly MediaModel[];
|
|
478
|
-
/**
|
|
478
|
+
/**
|
|
479
|
+
* One catalogue entry. Same grammar as the gateway's wire entry, except that a
|
|
480
|
+
* video model may name `host` as its provider family: the injected provider
|
|
481
|
+
* owns that model's wire grammar and Darkroom builds no gateway request for it.
|
|
482
|
+
*/
|
|
483
|
+
export declare const mediaCatalogueModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
484
|
+
id: z.ZodString;
|
|
485
|
+
label: z.ZodString;
|
|
486
|
+
kind: z.ZodEnum<{
|
|
487
|
+
/** Still-image generation. */
|
|
488
|
+
readonly image: "image";
|
|
489
|
+
/** Video generation. */
|
|
490
|
+
readonly video: "video";
|
|
491
|
+
}>;
|
|
492
|
+
tier: z.ZodEnum<{
|
|
493
|
+
/** Cheap, fast draft model. */
|
|
494
|
+
readonly draft: "draft";
|
|
495
|
+
/** Balanced model selection. */
|
|
496
|
+
readonly balanced: "balanced";
|
|
497
|
+
/** Premium model selection. */
|
|
498
|
+
readonly premium: "premium";
|
|
499
|
+
/** Most expensive model selection. */
|
|
500
|
+
readonly max: "max";
|
|
501
|
+
}>;
|
|
502
|
+
outputFormats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
503
|
+
/** PNG image encoding. */
|
|
504
|
+
readonly png: "png";
|
|
505
|
+
/** JPEG image encoding. */
|
|
506
|
+
readonly jpeg: "jpeg";
|
|
507
|
+
/** WebP image encoding. */
|
|
508
|
+
readonly webp: "webp";
|
|
509
|
+
}>>>;
|
|
510
|
+
maxPromptLength: z.ZodNumber;
|
|
511
|
+
input: z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
512
|
+
transport: z.ZodEnum<{
|
|
513
|
+
/** JSON provider input. */
|
|
514
|
+
readonly json: "json";
|
|
515
|
+
/** Multipart provider input. */
|
|
516
|
+
readonly multipart: "multipart";
|
|
517
|
+
}>;
|
|
518
|
+
dimensions: z.ZodEnum<{
|
|
519
|
+
/** Provider chooses its own dimensions. */
|
|
520
|
+
readonly none: "none";
|
|
521
|
+
/** Provider accepts the requested dimensions. */
|
|
522
|
+
readonly own: "own";
|
|
523
|
+
}>;
|
|
524
|
+
maxDimension: z.ZodNullable<z.ZodNumber>;
|
|
525
|
+
maxDimensionDocumented: z.ZodBoolean;
|
|
526
|
+
defaultWidth: z.ZodNumber;
|
|
527
|
+
defaultHeight: z.ZodNumber;
|
|
528
|
+
steps: z.ZodEnum<{
|
|
529
|
+
/** Provider reads the steps field. */
|
|
530
|
+
readonly steps: "steps";
|
|
531
|
+
/** Provider reads the num_steps field. */
|
|
532
|
+
readonly num_steps: "num_steps";
|
|
533
|
+
/** Provider uses fixed inference steps. */
|
|
534
|
+
readonly fixed: "fixed";
|
|
535
|
+
}>;
|
|
536
|
+
maxSteps: z.ZodNullable<z.ZodNumber>;
|
|
537
|
+
defaultSteps: z.ZodNullable<z.ZodNumber>;
|
|
538
|
+
referenceField: z.ZodNullable<z.ZodString>;
|
|
539
|
+
maxReferences: z.ZodNumber;
|
|
540
|
+
referenceDimension: z.ZodNullable<z.ZodNumber>;
|
|
541
|
+
referenceFormat: z.ZodEnum<{
|
|
542
|
+
/** Lossless PNG. */
|
|
543
|
+
readonly png: "png";
|
|
544
|
+
/** Lossy WebP. */
|
|
545
|
+
readonly webp: "webp";
|
|
546
|
+
}>;
|
|
547
|
+
}, z.core.$strict>>>;
|
|
548
|
+
sizes: z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
549
|
+
video: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
550
|
+
minSeconds: z.ZodNumber;
|
|
551
|
+
maxSeconds: z.ZodNumber;
|
|
552
|
+
defaultSeconds: z.ZodNumber;
|
|
553
|
+
durations: z.ZodReadonly<z.ZodArray<z.ZodNumber>>;
|
|
554
|
+
formats: z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
555
|
+
resolution: z.ZodEnum<{
|
|
556
|
+
/** 480p. */
|
|
557
|
+
readonly p480: "480p";
|
|
558
|
+
/** 720p. */
|
|
559
|
+
readonly p720: "720p";
|
|
560
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
561
|
+
readonly p768: "768p";
|
|
562
|
+
/** 1080p. */
|
|
563
|
+
readonly p1080: "1080p";
|
|
564
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
565
|
+
readonly p4k: "4k";
|
|
566
|
+
}>;
|
|
567
|
+
aspectRatio: z.ZodEnum<{
|
|
568
|
+
/** Landscape widescreen. */
|
|
569
|
+
readonly wide: "16:9";
|
|
570
|
+
/** Landscape standard. */
|
|
571
|
+
readonly landscape: "4:3";
|
|
572
|
+
/** Square. */
|
|
573
|
+
readonly square: "1:1";
|
|
574
|
+
/** Portrait standard. */
|
|
575
|
+
readonly portrait: "3:4";
|
|
576
|
+
/** Portrait widescreen. */
|
|
577
|
+
readonly tall: "9:16";
|
|
578
|
+
/** Landscape ultrawide. */
|
|
579
|
+
readonly ultrawide: "21:9";
|
|
580
|
+
/** Portrait ultrawide. */
|
|
581
|
+
readonly ultratall: "9:21";
|
|
582
|
+
}>;
|
|
583
|
+
width: z.ZodNumber;
|
|
584
|
+
height: z.ZodNumber;
|
|
585
|
+
}, z.core.$strict>>>>>;
|
|
586
|
+
defaultResolution: z.ZodEnum<{
|
|
587
|
+
/** 480p. */
|
|
588
|
+
readonly p480: "480p";
|
|
589
|
+
/** 720p. */
|
|
590
|
+
readonly p720: "720p";
|
|
591
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
592
|
+
readonly p768: "768p";
|
|
593
|
+
/** 1080p. */
|
|
594
|
+
readonly p1080: "1080p";
|
|
595
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
596
|
+
readonly p4k: "4k";
|
|
597
|
+
}>;
|
|
598
|
+
defaultAspectRatio: z.ZodEnum<{
|
|
599
|
+
/** Landscape widescreen. */
|
|
600
|
+
readonly wide: "16:9";
|
|
601
|
+
/** Landscape standard. */
|
|
602
|
+
readonly landscape: "4:3";
|
|
603
|
+
/** Square. */
|
|
604
|
+
readonly square: "1:1";
|
|
605
|
+
/** Portrait standard. */
|
|
606
|
+
readonly portrait: "3:4";
|
|
607
|
+
/** Portrait widescreen. */
|
|
608
|
+
readonly tall: "9:16";
|
|
609
|
+
/** Landscape ultrawide. */
|
|
610
|
+
readonly ultrawide: "21:9";
|
|
611
|
+
/** Portrait ultrawide. */
|
|
612
|
+
readonly ultratall: "9:21";
|
|
613
|
+
}>;
|
|
614
|
+
supportsAudio: z.ZodBoolean;
|
|
615
|
+
defaultGenerateAudio: z.ZodNullable<z.ZodBoolean>;
|
|
616
|
+
referenceRoles: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
617
|
+
/** First frame; required when a last frame is supplied. */
|
|
618
|
+
readonly first: "first-frame";
|
|
619
|
+
/** Last frame, supported by Seedance only (`last_frame_image`). */
|
|
620
|
+
readonly last: "last-frame";
|
|
621
|
+
/** One image in Seedance reference-image mode. */
|
|
622
|
+
readonly reference: "reference";
|
|
623
|
+
}>>>;
|
|
624
|
+
maxReferenceImages: z.ZodNumber;
|
|
625
|
+
referenceResolutions: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
626
|
+
/** 480p. */
|
|
627
|
+
readonly p480: "480p";
|
|
628
|
+
/** 720p. */
|
|
629
|
+
readonly p720: "720p";
|
|
630
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
631
|
+
readonly p768: "768p";
|
|
632
|
+
/** 1080p. */
|
|
633
|
+
readonly p1080: "1080p";
|
|
634
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
635
|
+
readonly p4k: "4k";
|
|
636
|
+
}>>>;
|
|
637
|
+
prices: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
638
|
+
resolution: z.ZodEnum<{
|
|
639
|
+
/** 480p. */
|
|
640
|
+
readonly p480: "480p";
|
|
641
|
+
/** 720p. */
|
|
642
|
+
readonly p720: "720p";
|
|
643
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
644
|
+
readonly p768: "768p";
|
|
645
|
+
/** 1080p. */
|
|
646
|
+
readonly p1080: "1080p";
|
|
647
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
648
|
+
readonly p4k: "4k";
|
|
649
|
+
}>;
|
|
650
|
+
silentMilliunitsPerSecond: z.ZodNumber;
|
|
651
|
+
audioMilliunitsPerSecond: z.ZodNumber;
|
|
652
|
+
}, z.core.$strict>>>>;
|
|
653
|
+
provider: z.ZodEnum<{
|
|
654
|
+
/** Seedance integer duration and data-URI image fields. */
|
|
655
|
+
readonly seedance: "seedance";
|
|
656
|
+
/** Veo duration string and base64 image_input. */
|
|
657
|
+
readonly veo: "veo";
|
|
658
|
+
/** MiniMax multimodal `content[]` array and uppercase resolution. */
|
|
659
|
+
readonly minimax: "minimax";
|
|
660
|
+
/** The injected provider owns the wire grammar. */
|
|
661
|
+
readonly host: "host";
|
|
662
|
+
}>;
|
|
663
|
+
}, z.core.$strict>>>;
|
|
664
|
+
}, z.core.$strict>>;
|
|
665
|
+
/** One provider's catalogue entry. */
|
|
666
|
+
export type MediaCatalogueModel = z.output<typeof mediaCatalogueModelSchema>;
|
|
667
|
+
/** One provider's model list: the typed bounds every request is checked against. */
|
|
668
|
+
export type MediaCatalogue = readonly MediaCatalogueModel[];
|
|
669
|
+
/**
|
|
670
|
+
* Decode a host-supplied provider catalogue. Each entry is the same typed wire
|
|
671
|
+
* grammar the built-in catalogue uses; this adds the cross-field facts the
|
|
672
|
+
* validator relies on (unique ids, video metadata iff `kind` is video, defaults
|
|
673
|
+
* inside their own bounds).
|
|
674
|
+
*/
|
|
675
|
+
export declare const mediaCatalogueSchema: z.ZodPipe<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
676
|
+
id: z.ZodString;
|
|
677
|
+
label: z.ZodString;
|
|
678
|
+
kind: z.ZodEnum<{
|
|
679
|
+
/** Still-image generation. */
|
|
680
|
+
readonly image: "image";
|
|
681
|
+
/** Video generation. */
|
|
682
|
+
readonly video: "video";
|
|
683
|
+
}>;
|
|
684
|
+
tier: z.ZodEnum<{
|
|
685
|
+
/** Cheap, fast draft model. */
|
|
686
|
+
readonly draft: "draft";
|
|
687
|
+
/** Balanced model selection. */
|
|
688
|
+
readonly balanced: "balanced";
|
|
689
|
+
/** Premium model selection. */
|
|
690
|
+
readonly premium: "premium";
|
|
691
|
+
/** Most expensive model selection. */
|
|
692
|
+
readonly max: "max";
|
|
693
|
+
}>;
|
|
694
|
+
outputFormats: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
695
|
+
/** PNG image encoding. */
|
|
696
|
+
readonly png: "png";
|
|
697
|
+
/** JPEG image encoding. */
|
|
698
|
+
readonly jpeg: "jpeg";
|
|
699
|
+
/** WebP image encoding. */
|
|
700
|
+
readonly webp: "webp";
|
|
701
|
+
}>>>;
|
|
702
|
+
maxPromptLength: z.ZodNumber;
|
|
703
|
+
input: z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
704
|
+
transport: z.ZodEnum<{
|
|
705
|
+
/** JSON provider input. */
|
|
706
|
+
readonly json: "json";
|
|
707
|
+
/** Multipart provider input. */
|
|
708
|
+
readonly multipart: "multipart";
|
|
709
|
+
}>;
|
|
710
|
+
dimensions: z.ZodEnum<{
|
|
711
|
+
/** Provider chooses its own dimensions. */
|
|
712
|
+
readonly none: "none";
|
|
713
|
+
/** Provider accepts the requested dimensions. */
|
|
714
|
+
readonly own: "own";
|
|
715
|
+
}>;
|
|
716
|
+
maxDimension: z.ZodNullable<z.ZodNumber>;
|
|
717
|
+
maxDimensionDocumented: z.ZodBoolean;
|
|
718
|
+
defaultWidth: z.ZodNumber;
|
|
719
|
+
defaultHeight: z.ZodNumber;
|
|
720
|
+
steps: z.ZodEnum<{
|
|
721
|
+
/** Provider reads the steps field. */
|
|
722
|
+
readonly steps: "steps";
|
|
723
|
+
/** Provider reads the num_steps field. */
|
|
724
|
+
readonly num_steps: "num_steps";
|
|
725
|
+
/** Provider uses fixed inference steps. */
|
|
726
|
+
readonly fixed: "fixed";
|
|
727
|
+
}>;
|
|
728
|
+
maxSteps: z.ZodNullable<z.ZodNumber>;
|
|
729
|
+
defaultSteps: z.ZodNullable<z.ZodNumber>;
|
|
730
|
+
referenceField: z.ZodNullable<z.ZodString>;
|
|
731
|
+
maxReferences: z.ZodNumber;
|
|
732
|
+
referenceDimension: z.ZodNullable<z.ZodNumber>;
|
|
733
|
+
referenceFormat: z.ZodEnum<{
|
|
734
|
+
/** Lossless PNG. */
|
|
735
|
+
readonly png: "png";
|
|
736
|
+
/** Lossy WebP. */
|
|
737
|
+
readonly webp: "webp";
|
|
738
|
+
}>;
|
|
739
|
+
}, z.core.$strict>>>;
|
|
740
|
+
sizes: z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
741
|
+
video: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
742
|
+
minSeconds: z.ZodNumber;
|
|
743
|
+
maxSeconds: z.ZodNumber;
|
|
744
|
+
defaultSeconds: z.ZodNumber;
|
|
745
|
+
durations: z.ZodReadonly<z.ZodArray<z.ZodNumber>>;
|
|
746
|
+
formats: z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
747
|
+
resolution: z.ZodEnum<{
|
|
748
|
+
/** 480p. */
|
|
749
|
+
readonly p480: "480p";
|
|
750
|
+
/** 720p. */
|
|
751
|
+
readonly p720: "720p";
|
|
752
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
753
|
+
readonly p768: "768p";
|
|
754
|
+
/** 1080p. */
|
|
755
|
+
readonly p1080: "1080p";
|
|
756
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
757
|
+
readonly p4k: "4k";
|
|
758
|
+
}>;
|
|
759
|
+
aspectRatio: z.ZodEnum<{
|
|
760
|
+
/** Landscape widescreen. */
|
|
761
|
+
readonly wide: "16:9";
|
|
762
|
+
/** Landscape standard. */
|
|
763
|
+
readonly landscape: "4:3";
|
|
764
|
+
/** Square. */
|
|
765
|
+
readonly square: "1:1";
|
|
766
|
+
/** Portrait standard. */
|
|
767
|
+
readonly portrait: "3:4";
|
|
768
|
+
/** Portrait widescreen. */
|
|
769
|
+
readonly tall: "9:16";
|
|
770
|
+
/** Landscape ultrawide. */
|
|
771
|
+
readonly ultrawide: "21:9";
|
|
772
|
+
/** Portrait ultrawide. */
|
|
773
|
+
readonly ultratall: "9:21";
|
|
774
|
+
}>;
|
|
775
|
+
width: z.ZodNumber;
|
|
776
|
+
height: z.ZodNumber;
|
|
777
|
+
}, z.core.$strict>>>>>;
|
|
778
|
+
defaultResolution: z.ZodEnum<{
|
|
779
|
+
/** 480p. */
|
|
780
|
+
readonly p480: "480p";
|
|
781
|
+
/** 720p. */
|
|
782
|
+
readonly p720: "720p";
|
|
783
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
784
|
+
readonly p768: "768p";
|
|
785
|
+
/** 1080p. */
|
|
786
|
+
readonly p1080: "1080p";
|
|
787
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
788
|
+
readonly p4k: "4k";
|
|
789
|
+
}>;
|
|
790
|
+
defaultAspectRatio: z.ZodEnum<{
|
|
791
|
+
/** Landscape widescreen. */
|
|
792
|
+
readonly wide: "16:9";
|
|
793
|
+
/** Landscape standard. */
|
|
794
|
+
readonly landscape: "4:3";
|
|
795
|
+
/** Square. */
|
|
796
|
+
readonly square: "1:1";
|
|
797
|
+
/** Portrait standard. */
|
|
798
|
+
readonly portrait: "3:4";
|
|
799
|
+
/** Portrait widescreen. */
|
|
800
|
+
readonly tall: "9:16";
|
|
801
|
+
/** Landscape ultrawide. */
|
|
802
|
+
readonly ultrawide: "21:9";
|
|
803
|
+
/** Portrait ultrawide. */
|
|
804
|
+
readonly ultratall: "9:21";
|
|
805
|
+
}>;
|
|
806
|
+
supportsAudio: z.ZodBoolean;
|
|
807
|
+
defaultGenerateAudio: z.ZodNullable<z.ZodBoolean>;
|
|
808
|
+
referenceRoles: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
809
|
+
/** First frame; required when a last frame is supplied. */
|
|
810
|
+
readonly first: "first-frame";
|
|
811
|
+
/** Last frame, supported by Seedance only (`last_frame_image`). */
|
|
812
|
+
readonly last: "last-frame";
|
|
813
|
+
/** One image in Seedance reference-image mode. */
|
|
814
|
+
readonly reference: "reference";
|
|
815
|
+
}>>>;
|
|
816
|
+
maxReferenceImages: z.ZodNumber;
|
|
817
|
+
referenceResolutions: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
818
|
+
/** 480p. */
|
|
819
|
+
readonly p480: "480p";
|
|
820
|
+
/** 720p. */
|
|
821
|
+
readonly p720: "720p";
|
|
822
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
823
|
+
readonly p768: "768p";
|
|
824
|
+
/** 1080p. */
|
|
825
|
+
readonly p1080: "1080p";
|
|
826
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
827
|
+
readonly p4k: "4k";
|
|
828
|
+
}>>>;
|
|
829
|
+
prices: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
830
|
+
resolution: z.ZodEnum<{
|
|
831
|
+
/** 480p. */
|
|
832
|
+
readonly p480: "480p";
|
|
833
|
+
/** 720p. */
|
|
834
|
+
readonly p720: "720p";
|
|
835
|
+
/** 768p, admitted only by MiniMax H3 Max. */
|
|
836
|
+
readonly p768: "768p";
|
|
837
|
+
/** 1080p. */
|
|
838
|
+
readonly p1080: "1080p";
|
|
839
|
+
/** 4k, admitted only by Seedance 2.0. */
|
|
840
|
+
readonly p4k: "4k";
|
|
841
|
+
}>;
|
|
842
|
+
silentMilliunitsPerSecond: z.ZodNumber;
|
|
843
|
+
audioMilliunitsPerSecond: z.ZodNumber;
|
|
844
|
+
}, z.core.$strict>>>>;
|
|
845
|
+
provider: z.ZodEnum<{
|
|
846
|
+
/** Seedance integer duration and data-URI image fields. */
|
|
847
|
+
readonly seedance: "seedance";
|
|
848
|
+
/** Veo duration string and base64 image_input. */
|
|
849
|
+
readonly veo: "veo";
|
|
850
|
+
/** MiniMax multimodal `content[]` array and uppercase resolution. */
|
|
851
|
+
readonly minimax: "minimax";
|
|
852
|
+
/** The injected provider owns the wire grammar. */
|
|
853
|
+
readonly host: "host";
|
|
854
|
+
}>;
|
|
855
|
+
}, z.core.$strict>>>;
|
|
856
|
+
}, z.core.$strict>>>, z.ZodTransform<MediaCatalogue, Readonly<{
|
|
857
|
+
id: string;
|
|
858
|
+
label: string;
|
|
859
|
+
kind: "image" | "video";
|
|
860
|
+
tier: "draft" | "balanced" | "premium" | "max";
|
|
861
|
+
outputFormats: readonly ("png" | "jpeg" | "webp")[];
|
|
862
|
+
maxPromptLength: number;
|
|
863
|
+
input: Readonly<{
|
|
864
|
+
transport: "json" | "multipart";
|
|
865
|
+
dimensions: "none" | "own";
|
|
866
|
+
maxDimension: number | null;
|
|
867
|
+
maxDimensionDocumented: boolean;
|
|
868
|
+
defaultWidth: number;
|
|
869
|
+
defaultHeight: number;
|
|
870
|
+
steps: "steps" | "num_steps" | "fixed";
|
|
871
|
+
maxSteps: number | null;
|
|
872
|
+
defaultSteps: number | null;
|
|
873
|
+
referenceField: string | null;
|
|
874
|
+
maxReferences: number;
|
|
875
|
+
referenceDimension: number | null;
|
|
876
|
+
referenceFormat: "png" | "webp";
|
|
877
|
+
}>;
|
|
878
|
+
sizes: readonly string[] | null;
|
|
879
|
+
video: Readonly<{
|
|
880
|
+
minSeconds: number;
|
|
881
|
+
maxSeconds: number;
|
|
882
|
+
defaultSeconds: number;
|
|
883
|
+
durations: readonly number[];
|
|
884
|
+
formats: readonly Readonly<{
|
|
885
|
+
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
|
|
886
|
+
aspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
|
|
887
|
+
width: number;
|
|
888
|
+
height: number;
|
|
889
|
+
}>[];
|
|
890
|
+
defaultResolution: "480p" | "720p" | "768p" | "1080p" | "4k";
|
|
891
|
+
defaultAspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
|
|
892
|
+
supportsAudio: boolean;
|
|
893
|
+
defaultGenerateAudio: boolean | null;
|
|
894
|
+
referenceRoles: readonly ("first-frame" | "last-frame" | "reference")[];
|
|
895
|
+
maxReferenceImages: number;
|
|
896
|
+
referenceResolutions: readonly ("480p" | "720p" | "768p" | "1080p" | "4k")[];
|
|
897
|
+
prices: readonly Readonly<{
|
|
898
|
+
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
|
|
899
|
+
silentMilliunitsPerSecond: number;
|
|
900
|
+
audioMilliunitsPerSecond: number;
|
|
901
|
+
}>[];
|
|
902
|
+
provider: "seedance" | "veo" | "minimax" | "host";
|
|
903
|
+
}> | null;
|
|
904
|
+
}>[]>>;
|
|
905
|
+
/** Decode untrusted catalogue data, throwing a MediaSettingsError that names the first problem. */
|
|
906
|
+
export declare const parseMediaCatalogue: (raw: unknown) => MediaCatalogue;
|
|
907
|
+
/** List the gateway provider's models in catalog order. */
|
|
479
908
|
export declare const listMediaModels: () => readonly MediaModel[];
|
|
480
|
-
/** Find a model
|
|
481
|
-
export declare const
|
|
909
|
+
/** Find a model in the Fungi gateway's own catalogue; gateway-internal code never sees a custom provider's models. */
|
|
910
|
+
export declare const getGatewayModel: (id: string) => MediaModel | undefined;
|
|
911
|
+
/** Find a model in `catalogue` (the gateway's by default), or undefined when absent. */
|
|
912
|
+
export declare const getMediaModel: (id: string, catalogue?: MediaCatalogue) => MediaCatalogueModel | undefined;
|
|
482
913
|
/** Invalid generation settings or unsupported model parameters. */
|
|
483
914
|
export declare class MediaSettingsError extends Error {
|
|
484
915
|
constructor(message: string);
|
package/dist/model-catalog.js
CHANGED
|
@@ -270,7 +270,7 @@ const freezeModel = (model) => Object.freeze({
|
|
|
270
270
|
const GPT_IMAGE_MAX_EDGE = 3_840;
|
|
271
271
|
/** Largest pixel count the documented size grammar admits. */
|
|
272
272
|
const GPT_IMAGE_MAX_PIXELS = 8_294_400;
|
|
273
|
-
const
|
|
273
|
+
const COMMON_IMAGE_RATIOS = [
|
|
274
274
|
[1, 1],
|
|
275
275
|
[4, 3],
|
|
276
276
|
[3, 4],
|
|
@@ -284,7 +284,7 @@ const gptImageSizes = (() => {
|
|
|
284
284
|
const keep = new Set(["1024x1024", "1024x1536", "1536x1024"]);
|
|
285
285
|
const standard = [];
|
|
286
286
|
const largest = [];
|
|
287
|
-
for (const [across, down] of
|
|
287
|
+
for (const [across, down] of COMMON_IMAGE_RATIOS) {
|
|
288
288
|
const divisor = ((a, b) => {
|
|
289
289
|
let x = a;
|
|
290
290
|
let y = b;
|
|
@@ -306,6 +306,26 @@ const gptImageSizes = (() => {
|
|
|
306
306
|
}
|
|
307
307
|
return Object.freeze([...standard, ...largest]);
|
|
308
308
|
})();
|
|
309
|
+
/** The common ratios as exact 16-aligned sizes of about `area` pixels. */
|
|
310
|
+
const commonRatioSizes = (area) => Object.freeze(COMMON_IMAGE_RATIOS.map(([across, down]) => {
|
|
311
|
+
let x = across;
|
|
312
|
+
let y = down;
|
|
313
|
+
while (y !== 0)
|
|
314
|
+
[x, y] = [y, x % y];
|
|
315
|
+
const unitW = (16 * across) / x;
|
|
316
|
+
const unitH = (16 * down) / x;
|
|
317
|
+
const steps = Math.round(Math.sqrt(area / (unitW * unitH)));
|
|
318
|
+
return `${String(unitW * steps)}x${String(unitH * steps)}`;
|
|
319
|
+
}));
|
|
320
|
+
/**
|
|
321
|
+
* Seedream 5 Pro takes `size` as a string: "1K", "2K" or an explicit pixel
|
|
322
|
+
* size (the page's examples are "1K" and "1536x864"). It documents no bounds,
|
|
323
|
+
* so each common ratio is listed as an exact explicit size at the scale of its
|
|
324
|
+
* own 1536x864 example (about 1.3 megapixels), where 16:9 is that example.
|
|
325
|
+
* https://developers.cloudflare.com/ai/models/bytedance/seedream-5-pro/
|
|
326
|
+
* https://developers.cloudflare.com/ai/models/bytedance/seedream-5-pro/schema-input.json
|
|
327
|
+
*/
|
|
328
|
+
const seedreamSizes = commonRatioSizes(1536 * 864);
|
|
309
329
|
const videoShortEdges = {
|
|
310
330
|
"480p": 480,
|
|
311
331
|
"720p": 720,
|
|
@@ -707,6 +727,36 @@ const models = Object.freeze([
|
|
|
707
727
|
referenceFormat: "webp",
|
|
708
728
|
},
|
|
709
729
|
}),
|
|
730
|
+
freezeModel({
|
|
731
|
+
id: "bytedance/seedream-5-pro",
|
|
732
|
+
// The page documents no prompt maxLength (schema-input.json has none):
|
|
733
|
+
// keep the 2,048 host cap.
|
|
734
|
+
maxPromptLength: UNDOCUMENTED_PROMPT_LENGTH,
|
|
735
|
+
// The page's example results are .jpeg URLs; the schema has no format field.
|
|
736
|
+
outputFormats: Object.freeze(["jpeg"]),
|
|
737
|
+
tier: "premium",
|
|
738
|
+
label: "Seedream 5 Pro — ByteDance, high-quality images",
|
|
739
|
+
sizes: seedreamSizes,
|
|
740
|
+
input: {
|
|
741
|
+
transport: "json",
|
|
742
|
+
dimensions: "own",
|
|
743
|
+
// The longest listed edge: the page documents no maximum.
|
|
744
|
+
maxDimension: 1792,
|
|
745
|
+
maxDimensionDocumented: false,
|
|
746
|
+
defaultWidth: 1536,
|
|
747
|
+
defaultHeight: 864,
|
|
748
|
+
steps: "fixed",
|
|
749
|
+
maxSteps: null,
|
|
750
|
+
defaultSteps: null,
|
|
751
|
+
// The page says the model takes up to 10 reference images (`image`, a
|
|
752
|
+
// string or 1-10 strings) but shows only URL inputs and states no
|
|
753
|
+
// base64 or data-URI form, so Prints sends none until it does.
|
|
754
|
+
referenceField: null,
|
|
755
|
+
maxReferences: 0,
|
|
756
|
+
referenceDimension: 512,
|
|
757
|
+
referenceFormat: "png",
|
|
758
|
+
},
|
|
759
|
+
}),
|
|
710
760
|
videoModel(mediaVideoModelIdSchema.enum.seedance25, "Seedance 2.5", "balanced", "seedance", [
|
|
711
761
|
["480p", 10_280, 10_280],
|
|
712
762
|
["720p", 23_120, 23_120],
|
|
@@ -735,12 +785,86 @@ const models = Object.freeze([
|
|
|
735
785
|
]),
|
|
736
786
|
minimaxVideoModel(),
|
|
737
787
|
]);
|
|
738
|
-
/** The immutable image and video model catalog. */
|
|
788
|
+
/** The Fungi gateway provider's own immutable image and video model catalog. */
|
|
739
789
|
export const mediaModels = models;
|
|
740
|
-
/**
|
|
790
|
+
/**
|
|
791
|
+
* One catalogue entry. Same grammar as the gateway's wire entry, except that a
|
|
792
|
+
* video model may name `host` as its provider family: the injected provider
|
|
793
|
+
* owns that model's wire grammar and Darkroom builds no gateway request for it.
|
|
794
|
+
*/
|
|
795
|
+
export const mediaCatalogueModelSchema = mediaModelSchema
|
|
796
|
+
.unwrap()
|
|
797
|
+
.extend({
|
|
798
|
+
/** Video length constraints, or null for a still-image model. */
|
|
799
|
+
video: mediaVideoSchema
|
|
800
|
+
.unwrap()
|
|
801
|
+
.unwrap()
|
|
802
|
+
.extend({
|
|
803
|
+
/** Provider translation family, or `host` for a host-injected provider. */
|
|
804
|
+
provider: z.enum({
|
|
805
|
+
/** Seedance integer duration and data-URI image fields. */
|
|
806
|
+
seedance: "seedance",
|
|
807
|
+
/** Veo duration string and base64 image_input. */
|
|
808
|
+
veo: "veo",
|
|
809
|
+
/** MiniMax multimodal `content[]` array and uppercase resolution. */
|
|
810
|
+
minimax: "minimax",
|
|
811
|
+
/** The injected provider owns the wire grammar. */
|
|
812
|
+
host: "host",
|
|
813
|
+
}),
|
|
814
|
+
})
|
|
815
|
+
.readonly()
|
|
816
|
+
.nullable(),
|
|
817
|
+
})
|
|
818
|
+
.readonly();
|
|
819
|
+
/** Upper bound on one provider's model list. */
|
|
820
|
+
const MAX_CATALOGUE_MODELS = 256;
|
|
821
|
+
/**
|
|
822
|
+
* Decode a host-supplied provider catalogue. Each entry is the same typed wire
|
|
823
|
+
* grammar the built-in catalogue uses; this adds the cross-field facts the
|
|
824
|
+
* validator relies on (unique ids, video metadata iff `kind` is video, defaults
|
|
825
|
+
* inside their own bounds).
|
|
826
|
+
*/
|
|
827
|
+
export const mediaCatalogueSchema = z
|
|
828
|
+
.array(mediaCatalogueModelSchema)
|
|
829
|
+
.min(1)
|
|
830
|
+
.max(MAX_CATALOGUE_MODELS)
|
|
831
|
+
.superRefine((entries, context) => {
|
|
832
|
+
const seen = new Set();
|
|
833
|
+
entries.forEach((model, index) => {
|
|
834
|
+
const report = (message) => {
|
|
835
|
+
context.addIssue({ code: "custom", message, path: [index] });
|
|
836
|
+
};
|
|
837
|
+
if (seen.has(model.id))
|
|
838
|
+
report(`duplicate model id "${model.id}"`);
|
|
839
|
+
seen.add(model.id);
|
|
840
|
+
if ((model.kind === "video") !== (model.video !== null))
|
|
841
|
+
report(`${model.id} must carry video bounds exactly when kind is video`);
|
|
842
|
+
const video = model.video;
|
|
843
|
+
if (video === null)
|
|
844
|
+
return;
|
|
845
|
+
if (video.minSeconds > video.maxSeconds ||
|
|
846
|
+
video.durations.some((seconds) => seconds < video.minSeconds || seconds > video.maxSeconds) ||
|
|
847
|
+
!video.durations.includes(video.defaultSeconds))
|
|
848
|
+
report(`${model.id} durations must sit inside min/max and include the default`);
|
|
849
|
+
if (!video.formats.some(({ resolution, aspectRatio }) => resolution === video.defaultResolution &&
|
|
850
|
+
aspectRatio === video.defaultAspectRatio))
|
|
851
|
+
report(`${model.id} formats must include the default resolution and aspect`);
|
|
852
|
+
});
|
|
853
|
+
})
|
|
854
|
+
.transform((entries) => Object.freeze(entries.map((model) => Object.freeze({ ...model, input: Object.freeze(model.input) }))));
|
|
855
|
+
/** Decode untrusted catalogue data, throwing a MediaSettingsError that names the first problem. */
|
|
856
|
+
export const parseMediaCatalogue = (raw) => {
|
|
857
|
+
const parsed = mediaCatalogueSchema.safeParse(raw);
|
|
858
|
+
if (!parsed.success)
|
|
859
|
+
throw new MediaSettingsError(`media catalogue is invalid: ${parsed.error.issues[0]?.message ?? "unreadable"}`);
|
|
860
|
+
return parsed.data;
|
|
861
|
+
};
|
|
862
|
+
/** List the gateway provider's models in catalog order. */
|
|
741
863
|
export const listMediaModels = () => mediaModels;
|
|
742
|
-
/** Find a model
|
|
743
|
-
export const
|
|
864
|
+
/** Find a model in the Fungi gateway's own catalogue; gateway-internal code never sees a custom provider's models. */
|
|
865
|
+
export const getGatewayModel = (id) => mediaModels.find((model) => model.id === id);
|
|
866
|
+
/** Find a model in `catalogue` (the gateway's by default), or undefined when absent. */
|
|
867
|
+
export const getMediaModel = (id, catalogue = mediaModels) => catalogue.find((model) => model.id === id);
|
|
744
868
|
/** Invalid generation settings or unsupported model parameters. */
|
|
745
869
|
export class MediaSettingsError extends Error {
|
|
746
870
|
constructor(message) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type MediaCatalogue } from "./model-catalog.js";
|
|
1
2
|
/** Aspect-preserving native resize; only video references may be enlarged. */
|
|
2
|
-
export declare function referenceImageTransform(modelId: string, width: number, height: number): {
|
|
3
|
+
export declare function referenceImageTransform(modelId: string, width: number, height: number, catalogue?: MediaCatalogue): {
|
|
3
4
|
width: number;
|
|
4
5
|
height: number;
|
|
5
6
|
fit: "contain" | "scale-down";
|
|
6
7
|
};
|
|
7
8
|
/** Validate actual decoded output, rather than trusting requested resize dimensions. */
|
|
8
|
-
export declare function referenceImageSizeIsValid(modelId: string, width: number, height: number): boolean;
|
|
9
|
+
export declare function referenceImageSizeIsValid(modelId: string, width: number, height: number, catalogue?: MediaCatalogue): boolean;
|
|
9
10
|
/** The encoding the selected model's fitted references are sent in. */
|
|
10
|
-
export declare function referenceImageFormat(modelId: string): "image/webp" | "image/png";
|
|
11
|
+
export declare function referenceImageFormat(modelId: string, catalogue?: MediaCatalogue): "image/webp" | "image/png";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getMediaModel, MediaSettingsError } from "./model-catalog.js";
|
|
1
|
+
import { getMediaModel, mediaModels, MediaSettingsError, } from "./model-catalog.js";
|
|
2
2
|
const MIN_VIDEO_REFERENCE_DIMENSION = 320;
|
|
3
3
|
/** One owner for both native fitting and the resolved-reference boundary. */
|
|
4
|
-
function sizing(modelId) {
|
|
5
|
-
const model = getMediaModel(modelId);
|
|
4
|
+
function sizing(modelId, catalogue) {
|
|
5
|
+
const model = getMediaModel(modelId, catalogue);
|
|
6
6
|
if (model === undefined)
|
|
7
7
|
throw new MediaSettingsError("unknown Media model");
|
|
8
8
|
return model.video === null && model.input.referenceDimension !== null
|
|
@@ -10,8 +10,8 @@ function sizing(modelId) {
|
|
|
10
10
|
: { edge: "short", dimension: MIN_VIDEO_REFERENCE_DIMENSION };
|
|
11
11
|
}
|
|
12
12
|
/** Aspect-preserving native resize; only video references may be enlarged. */
|
|
13
|
-
export function referenceImageTransform(modelId, width, height) {
|
|
14
|
-
const rule = sizing(modelId);
|
|
13
|
+
export function referenceImageTransform(modelId, width, height, catalogue = mediaModels) {
|
|
14
|
+
const rule = sizing(modelId, catalogue);
|
|
15
15
|
const edge = rule.edge === "short" ? Math.min(width, height) : Math.max(width, height);
|
|
16
16
|
const ratio = rule.edge === "short"
|
|
17
17
|
? rule.dimension / edge
|
|
@@ -27,15 +27,15 @@ export function referenceImageTransform(modelId, width, height) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
/** Validate actual decoded output, rather than trusting requested resize dimensions. */
|
|
30
|
-
export function referenceImageSizeIsValid(modelId, width, height) {
|
|
31
|
-
const rule = sizing(modelId);
|
|
30
|
+
export function referenceImageSizeIsValid(modelId, width, height, catalogue = mediaModels) {
|
|
31
|
+
const rule = sizing(modelId, catalogue);
|
|
32
32
|
return rule.edge === "short"
|
|
33
33
|
? Math.min(width, height) >= rule.dimension
|
|
34
34
|
: Math.max(width, height) <= rule.dimension;
|
|
35
35
|
}
|
|
36
36
|
/** The encoding the selected model's fitted references are sent in. */
|
|
37
|
-
export function referenceImageFormat(modelId) {
|
|
38
|
-
const model = getMediaModel(modelId);
|
|
37
|
+
export function referenceImageFormat(modelId, catalogue = mediaModels) {
|
|
38
|
+
const model = getMediaModel(modelId, catalogue);
|
|
39
39
|
if (model === undefined)
|
|
40
40
|
throw new MediaSettingsError("unknown Media model");
|
|
41
41
|
return model.input.referenceFormat === "webp"
|