@fungi.computer/darkroom 0.7.0 → 0.9.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 +49 -0
- package/dist/app-media-contracts.d.ts +103 -12
- package/dist/audio-providers/elevenlabs.d.ts +40 -0
- package/dist/audio-providers/elevenlabs.js +69 -0
- package/dist/audio-reference-types.d.ts +28 -0
- package/dist/audio-reference-types.js +16 -0
- package/dist/audio-references.d.ts +14 -0
- package/dist/audio-references.js +69 -0
- package/dist/cloudflare/provider.d.ts +6 -4
- package/dist/cloudflare/provider.js +37 -19
- package/dist/gateway-models.d.ts +12 -8
- package/dist/gateway-models.js +38 -17
- package/dist/index.d.ts +70 -15
- package/dist/index.js +118 -7
- package/dist/media-binding.d.ts +60 -7
- package/dist/media-binding.js +41 -19
- package/dist/media-generation.js +12 -3
- package/dist/media-operation-contract.d.ts +7 -3
- package/dist/media-operation-contract.js +6 -4
- package/dist/media-operation-owner.d.ts +2 -2
- package/dist/media-operation-owner.js +48 -6
- package/dist/media-operation.js +4 -2
- package/dist/model-catalog.d.ts +155 -4
- package/dist/model-catalog.js +173 -4
- package/dist/server.d.ts +14 -7
- package/dist/server.js +9 -4
- package/dist/video-providers/reference-encoding.d.ts +7 -2
- package/dist/video-providers/reference-encoding.js +14 -3
- package/dist/video-providers/types.d.ts +2 -2
- package/dist/video-providers/unified.d.ts +1 -0
- package/dist/video-providers/unified.js +4 -2
- package/docs/api/app-media-contracts.md +46 -10
- package/docs/api/cloudflare.md +3 -3
- package/docs/api/index.md +564 -84
- package/docs/api/server.md +129 -62
- package/package.json +3 -2
package/dist/model-catalog.js
CHANGED
|
@@ -23,7 +23,7 @@ export const mediaModelTierSchema = z.enum({
|
|
|
23
23
|
/** Most expensive model selection. */
|
|
24
24
|
max: "max",
|
|
25
25
|
});
|
|
26
|
-
/** Media's provider catalog: Workers AI images plus gateway image and
|
|
26
|
+
/** Media's provider catalog: Workers AI images plus gateway image, video and audio models. */
|
|
27
27
|
export const mediaModelInputSchema = z.lazy(() => z
|
|
28
28
|
.strictObject({
|
|
29
29
|
/**
|
|
@@ -190,6 +190,20 @@ export const mediaVideoSchema = z.lazy(() => z
|
|
|
190
190
|
maxReferenceImages: z.number().int().nonnegative(),
|
|
191
191
|
/** Resolutions supporting reference-image mode. */
|
|
192
192
|
referenceResolutions: z.array(mediaVideoResolutionSchema).readonly(),
|
|
193
|
+
/**
|
|
194
|
+
* Audio clips accepted as `reference_audios`, or null when the model has
|
|
195
|
+
* no audio references. Declared by the provider's input schema, never
|
|
196
|
+
* inferred from the family.
|
|
197
|
+
*/
|
|
198
|
+
audioReferences: z
|
|
199
|
+
.strictObject({
|
|
200
|
+
/** Most clips in one request. */
|
|
201
|
+
max: z.number().int().positive(),
|
|
202
|
+
/** Longest total duration of all clips, in seconds. */
|
|
203
|
+
totalSeconds: z.number().int().positive(),
|
|
204
|
+
})
|
|
205
|
+
.readonly()
|
|
206
|
+
.nullable(),
|
|
193
207
|
/** Non-video-input provider cost; 1 USD = 100,000 milliunits. */
|
|
194
208
|
prices: z
|
|
195
209
|
.array(z
|
|
@@ -205,6 +219,65 @@ export const mediaVideoSchema = z.lazy(() => z
|
|
|
205
219
|
.readonly(),
|
|
206
220
|
})
|
|
207
221
|
.readonly());
|
|
222
|
+
/**
|
|
223
|
+
* Verified ElevenLabs model identifiers on Cloudflare's Unified Billing, from
|
|
224
|
+
* the model pages under https://developers.cloudflare.com/ai/models/elevenlabs/
|
|
225
|
+
* (checked 2026-11-13). Cloudflare offers no sound-effects model. Eleven Flash
|
|
226
|
+
* v2.5 and Turbo v2.5 are listed there but a live Unified Billing call to Flash
|
|
227
|
+
* answered 403 code 2047 ("not available via unified billing. Please use
|
|
228
|
+
* BYOK"), so they are not offered. Multilingual v2 is the default voice model.
|
|
229
|
+
*/
|
|
230
|
+
export const mediaAudioModelIdSchema = z.enum({
|
|
231
|
+
/** Eleven Multilingual v2 text to speech. */
|
|
232
|
+
multilingual: "elevenlabs/eleven-multilingual-v2",
|
|
233
|
+
/** Eleven v3 expressive text to speech. */
|
|
234
|
+
v3: "elevenlabs/eleven-v3",
|
|
235
|
+
/** Eleven Music v2. */
|
|
236
|
+
music: "elevenlabs/music-v2",
|
|
237
|
+
});
|
|
238
|
+
/** One premade voice a speech model may speak with. */
|
|
239
|
+
export const mediaAudioVoiceSchema = z.lazy(() => z
|
|
240
|
+
.strictObject({
|
|
241
|
+
/** ElevenLabs voice identifier, exactly as Cloudflare's docs list it. */
|
|
242
|
+
id: z.string().min(1).max(64),
|
|
243
|
+
/** Customer-visible voice label. */
|
|
244
|
+
label: z.string().min(1).max(128),
|
|
245
|
+
})
|
|
246
|
+
.readonly());
|
|
247
|
+
/** Verified audio parameters and provider cost, checked 2026-11-13. */
|
|
248
|
+
export const mediaAudioSchema = z.lazy(() => z
|
|
249
|
+
.strictObject({
|
|
250
|
+
/** Provider translation family. */
|
|
251
|
+
provider: z.literal("elevenlabs"),
|
|
252
|
+
/** Speech reads the prompt aloud; music composes from it. */
|
|
253
|
+
mode: z.enum({
|
|
254
|
+
/** Text to speech: the prompt is the spoken text. */
|
|
255
|
+
speech: "speech",
|
|
256
|
+
/** Music: the prompt describes the track. */
|
|
257
|
+
music: "music",
|
|
258
|
+
}),
|
|
259
|
+
/** Premade voices; empty for music. */
|
|
260
|
+
voices: z.array(mediaAudioVoiceSchema).readonly(),
|
|
261
|
+
/** Voice used when none is chosen; null for music. */
|
|
262
|
+
defaultVoiceId: z.string().min(1).max(64).nullable(),
|
|
263
|
+
/** Music length bounds in whole seconds; null for speech. */
|
|
264
|
+
seconds: z
|
|
265
|
+
.strictObject({
|
|
266
|
+
/** Shortest track. */
|
|
267
|
+
min: z.number().int().positive(),
|
|
268
|
+
/** Longest track. */
|
|
269
|
+
max: z.number().int().positive(),
|
|
270
|
+
/** Length when omitted. */
|
|
271
|
+
default: z.number().int().positive(),
|
|
272
|
+
})
|
|
273
|
+
.readonly()
|
|
274
|
+
.nullable(),
|
|
275
|
+
/** Provider milliunits per billed unit; 1 USD = 100,000 milliunits. */
|
|
276
|
+
milliunitsPerUnit: z.number().int().positive(),
|
|
277
|
+
})
|
|
278
|
+
.readonly());
|
|
279
|
+
/** Characters one speech billing block covers. */
|
|
280
|
+
export const AUDIO_CHARACTER_BLOCK = 100;
|
|
208
281
|
/**
|
|
209
282
|
* Structural ceiling for any prompt on the wire. Each model's own
|
|
210
283
|
* `maxPromptLength` is the real bound; no model may exceed this ceiling.
|
|
@@ -225,6 +298,8 @@ export const mediaModelSchema = z
|
|
|
225
298
|
image: "image",
|
|
226
299
|
/** Video generation. */
|
|
227
300
|
video: "video",
|
|
301
|
+
/** Speech or music generation. */
|
|
302
|
+
audio: "audio",
|
|
228
303
|
}),
|
|
229
304
|
/** Model selection tier, independent of price. */
|
|
230
305
|
tier: mediaModelTierSchema,
|
|
@@ -247,12 +322,15 @@ export const mediaModelSchema = z
|
|
|
247
322
|
.nullable(),
|
|
248
323
|
/** Video length constraints, or null for a still-image model. */
|
|
249
324
|
video: mediaVideoSchema.nullable(),
|
|
325
|
+
/** Speech or music constraints, or null for an image or video model. */
|
|
326
|
+
audio: mediaAudioSchema.nullable(),
|
|
250
327
|
})
|
|
251
328
|
.readonly();
|
|
252
329
|
const freezeModel = (model) => Object.freeze({
|
|
253
330
|
kind: "image",
|
|
254
331
|
sizes: null,
|
|
255
332
|
video: null,
|
|
333
|
+
audio: null,
|
|
256
334
|
outputFormats: Object.freeze([]),
|
|
257
335
|
...model,
|
|
258
336
|
input: Object.freeze(model.input),
|
|
@@ -349,10 +427,13 @@ const videoAspects = {
|
|
|
349
427
|
* Prices are Cloudflare dashboard prices, supplied by the owner 2026-11-13;
|
|
350
428
|
* the public model page lists none. Only the non-video-input rates apply, as
|
|
351
429
|
* video-input references are unsupported.
|
|
430
|
+
* `reference_audios` takes at most 10 clips totalling 30 seconds
|
|
431
|
+
* (https://developers.cloudflare.com/ai/models/bytedance/seedance-2.5/schema-input.json).
|
|
352
432
|
*/
|
|
353
433
|
const seedance25 = {
|
|
354
434
|
maxSeconds: 30,
|
|
355
435
|
maxReferenceImages: 30,
|
|
436
|
+
audioReferences: { max: 10, totalSeconds: 30 },
|
|
356
437
|
maxPromptLength: 25_000,
|
|
357
438
|
resolutions: ["480p", "720p"],
|
|
358
439
|
aspects: mediaVideoAspectRatioSchema.options.filter((aspectRatio) => aspectRatio !== mediaVideoAspectRatioSchema.enum.ultratall),
|
|
@@ -407,6 +488,9 @@ function videoModel(id, label, tier, provider, rates, bounds) {
|
|
|
407
488
|
? mediaVideoReferenceRoleSchema.options
|
|
408
489
|
: [mediaVideoReferenceRoleSchema.enum.first]),
|
|
409
490
|
maxReferenceImages,
|
|
491
|
+
audioReferences: bounds === undefined
|
|
492
|
+
? null
|
|
493
|
+
: Object.freeze({ ...bounds.audioReferences }),
|
|
410
494
|
referenceResolutions: Object.freeze(seedance
|
|
411
495
|
? resolutions.filter((resolution) => resolution !== "1080p")
|
|
412
496
|
: []),
|
|
@@ -505,6 +589,7 @@ function minimaxVideoModel() {
|
|
|
505
589
|
// The vendor page documents up to nine; this stays at the conservative
|
|
506
590
|
// verified value of four until the gateway schema is confirmed.
|
|
507
591
|
maxReferenceImages: 4,
|
|
592
|
+
audioReferences: null,
|
|
508
593
|
referenceResolutions: Object.freeze(resolutions),
|
|
509
594
|
prices: Object.freeze([
|
|
510
595
|
{
|
|
@@ -548,6 +633,77 @@ function minimaxVideoModel() {
|
|
|
548
633
|
},
|
|
549
634
|
});
|
|
550
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
* The one voice Cloudflare's ElevenLabs pages list: every `voice_id` example
|
|
638
|
+
* and request sample on the TTS model pages uses it, and there is no voice
|
|
639
|
+
* listing endpoint on Cloudflare. More voices are added only from a page that
|
|
640
|
+
* lists them.
|
|
641
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-v3/
|
|
642
|
+
*/
|
|
643
|
+
const premadeVoices = Object.freeze([
|
|
644
|
+
Object.freeze({ id: "JBFqnCBsd6RMkjVDRZzb", label: "Default voice" }),
|
|
645
|
+
]);
|
|
646
|
+
/**
|
|
647
|
+
* An ElevenLabs speech model. Text is at most 10,000 characters and a
|
|
648
|
+
* `voice_id` is required (each model's `schema-input.json`); the rate is the
|
|
649
|
+
* per-character price on its Cloudflare page, 1 USD = 100,000 milliunits.
|
|
650
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-v3/
|
|
651
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-multilingual-v2/
|
|
652
|
+
*/
|
|
653
|
+
function speechModel(id, label, tier, milliunitsPerCharacter) {
|
|
654
|
+
return audioModel(id, label, tier, 10_000, {
|
|
655
|
+
provider: "elevenlabs",
|
|
656
|
+
mode: "speech",
|
|
657
|
+
voices: premadeVoices,
|
|
658
|
+
defaultVoiceId: premadeVoices[0]?.id ?? null,
|
|
659
|
+
seconds: null,
|
|
660
|
+
milliunitsPerUnit: milliunitsPerCharacter,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Eleven Music v2: `music_length_ms` runs 3,000 through 600,000 and the page
|
|
665
|
+
* lists $0.0025 per output second (250 milliunits). The prompt has no
|
|
666
|
+
* documented limit, so the retained 2,048 host cap applies. The model is run
|
|
667
|
+
* with a length always set, so the quote is the length asked for.
|
|
668
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/music-v2/
|
|
669
|
+
*/
|
|
670
|
+
function musicModel() {
|
|
671
|
+
return audioModel(mediaAudioModelIdSchema.enum.music, "Eleven Music v2", "premium", UNDOCUMENTED_PROMPT_LENGTH, {
|
|
672
|
+
provider: "elevenlabs",
|
|
673
|
+
mode: "music",
|
|
674
|
+
voices: Object.freeze([]),
|
|
675
|
+
defaultVoiceId: null,
|
|
676
|
+
seconds: Object.freeze({ min: 3, max: 600, default: 30 }),
|
|
677
|
+
milliunitsPerUnit: 250,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
function audioModel(id, label, tier, maxPromptLength, audio) {
|
|
681
|
+
return freezeModel({
|
|
682
|
+
id,
|
|
683
|
+
label,
|
|
684
|
+
tier,
|
|
685
|
+
maxPromptLength,
|
|
686
|
+
kind: "audio",
|
|
687
|
+
audio: Object.freeze(audio),
|
|
688
|
+
input: {
|
|
689
|
+
transport: "json",
|
|
690
|
+
dimensions: "none",
|
|
691
|
+
maxDimension: null,
|
|
692
|
+
maxDimensionDocumented: false,
|
|
693
|
+
// Audio has no dimensions; the shared wire grammar still requires a
|
|
694
|
+
// positive default, and nothing reads it for an audio model.
|
|
695
|
+
defaultWidth: 1,
|
|
696
|
+
defaultHeight: 1,
|
|
697
|
+
steps: "fixed",
|
|
698
|
+
maxSteps: null,
|
|
699
|
+
defaultSteps: null,
|
|
700
|
+
referenceField: null,
|
|
701
|
+
maxReferences: 0,
|
|
702
|
+
referenceDimension: null,
|
|
703
|
+
referenceFormat: "png",
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
}
|
|
551
707
|
const models = Object.freeze([
|
|
552
708
|
freezeModel({
|
|
553
709
|
id: "@cf/black-forest-labs/flux-1-schnell",
|
|
@@ -784,8 +940,12 @@ const models = Object.freeze([
|
|
|
784
940
|
["1080p", 10_000, 12_000],
|
|
785
941
|
]),
|
|
786
942
|
minimaxVideoModel(),
|
|
943
|
+
// ElevenLabs on Unified Billing: URL results, like the video models.
|
|
944
|
+
speechModel(mediaAudioModelIdSchema.enum.multilingual, "Eleven Multilingual v2 — natural speech", "balanced", 10),
|
|
945
|
+
speechModel(mediaAudioModelIdSchema.enum.v3, "Eleven v3 — expressive speech", "premium", 10),
|
|
946
|
+
musicModel(),
|
|
787
947
|
]);
|
|
788
|
-
/** The Fungi gateway provider's own immutable image and
|
|
948
|
+
/** The Fungi gateway provider's own immutable image, video and audio model catalog. */
|
|
789
949
|
export const mediaModels = models;
|
|
790
950
|
/**
|
|
791
951
|
* One catalogue entry. Same grammar as the gateway's wire entry, except that a
|
|
@@ -795,11 +955,18 @@ export const mediaModels = models;
|
|
|
795
955
|
export const mediaCatalogueModelSchema = mediaModelSchema
|
|
796
956
|
.unwrap()
|
|
797
957
|
.extend({
|
|
958
|
+
/** Speech or music constraints; a host's catalogue omits it unless it lists audio models. */
|
|
959
|
+
audio: mediaAudioSchema.unwrap().nullable().default(null),
|
|
798
960
|
/** Video length constraints, or null for a still-image model. */
|
|
799
961
|
video: mediaVideoSchema
|
|
800
962
|
.unwrap()
|
|
801
963
|
.unwrap()
|
|
802
964
|
.extend({
|
|
965
|
+
/** Audio reference limits; a host's catalogue omits it unless its model takes audio references. */
|
|
966
|
+
audioReferences: mediaVideoSchema
|
|
967
|
+
.unwrap()
|
|
968
|
+
.unwrap()
|
|
969
|
+
.shape.audioReferences.default(null),
|
|
803
970
|
/** Provider translation family, or `host` for a host-injected provider. */
|
|
804
971
|
provider: z.enum({
|
|
805
972
|
/** Seedance integer duration and data-URI image fields. */
|
|
@@ -839,6 +1006,8 @@ export const mediaCatalogueSchema = z
|
|
|
839
1006
|
seen.add(model.id);
|
|
840
1007
|
if ((model.kind === "video") !== (model.video !== null))
|
|
841
1008
|
report(`${model.id} must carry video bounds exactly when kind is video`);
|
|
1009
|
+
if ((model.kind === "audio") !== (model.audio !== null))
|
|
1010
|
+
report(`${model.id} must carry audio bounds exactly when kind is audio`);
|
|
842
1011
|
const video = model.video;
|
|
843
1012
|
if (video === null)
|
|
844
1013
|
return;
|
|
@@ -867,8 +1036,8 @@ export const getGatewayModel = (id) => mediaModels.find((model) => model.id ===
|
|
|
867
1036
|
export const getMediaModel = (id, catalogue = mediaModels) => catalogue.find((model) => model.id === id);
|
|
868
1037
|
/** Invalid generation settings or unsupported model parameters. */
|
|
869
1038
|
export class MediaSettingsError extends Error {
|
|
870
|
-
constructor(message) {
|
|
871
|
-
super(message);
|
|
1039
|
+
constructor(message, options) {
|
|
1040
|
+
super(message, options);
|
|
872
1041
|
this.name = "MediaSettingsError";
|
|
873
1042
|
}
|
|
874
1043
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -19,10 +19,11 @@ export declare const mediaRequestSchema: z.ZodObject<{
|
|
|
19
19
|
settings: z.ZodObject<{
|
|
20
20
|
model: z.ZodString;
|
|
21
21
|
prompt: z.ZodString;
|
|
22
|
-
width: z.ZodNumber
|
|
23
|
-
height: z.ZodNumber
|
|
22
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
24
24
|
steps: z.ZodOptional<z.ZodNumber>;
|
|
25
25
|
durationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
voiceId: z.ZodOptional<z.ZodString>;
|
|
26
27
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
27
28
|
readonly p480: "480p";
|
|
28
29
|
readonly p720: "720p";
|
|
@@ -49,6 +50,10 @@ export declare const mediaRequestSchema: z.ZodObject<{
|
|
|
49
50
|
readonly reference: "reference";
|
|
50
51
|
}>>;
|
|
51
52
|
}, z.core.$strict>>>;
|
|
53
|
+
audioReferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
54
|
+
computerId: z.ZodString;
|
|
55
|
+
path: z.ZodString;
|
|
56
|
+
}, z.core.$strict>>>;
|
|
52
57
|
}, z.core.$strict>;
|
|
53
58
|
outputFormat: z.ZodOptional<z.ZodEnum<{
|
|
54
59
|
readonly png: "png";
|
|
@@ -95,6 +100,8 @@ export type MediaServiceHost = Readonly<{
|
|
|
95
100
|
write: (path: string, bytes: Uint8Array) => Promise<void>;
|
|
96
101
|
/** Authorize and fit one selected reference image for the catalog model. */
|
|
97
102
|
readReference?: (reference: MediaReference, model: string) => Promise<MediaReferenceBytes>;
|
|
103
|
+
/** Authorize and read the raw bytes of one reference audio clip. */
|
|
104
|
+
readAudioReference?: (reference: MediaReference) => Promise<Uint8Array>;
|
|
98
105
|
}>;
|
|
99
106
|
/** Translate host authority failures; undefined uses the shared Media failure. */
|
|
100
107
|
onFailure?: (error: MediaExecutionError) => Response | undefined;
|
|
@@ -145,13 +152,13 @@ export type MediaGenerationOutcome = Readonly<{
|
|
|
145
152
|
/** Admitted price in milliunits, where 1 cent is 1,000 milliunits. */
|
|
146
153
|
costMilliunits: number;
|
|
147
154
|
/** Actual output encoding. */
|
|
148
|
-
format: "png" | "jpeg" | "gif" | "webp" | "mp4";
|
|
149
|
-
/** Requested image height or nominal video selector
|
|
150
|
-
height
|
|
155
|
+
format: "png" | "jpeg" | "gif" | "webp" | "mp4" | "mp3";
|
|
156
|
+
/** Requested image height or nominal video selector; absent for audio. */
|
|
157
|
+
height?: number | undefined;
|
|
151
158
|
/** Provider catalog model identifier. */
|
|
152
159
|
model: string;
|
|
153
|
-
/** Requested image width or nominal video selector
|
|
154
|
-
width
|
|
160
|
+
/** Requested image width or nominal video selector; absent for audio. */
|
|
161
|
+
width?: number | undefined;
|
|
155
162
|
}> | Readonly<{
|
|
156
163
|
/** Outcome or model-kind discriminant. */
|
|
157
164
|
kind: "pending";
|
package/dist/server.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as Effect from "effect/Effect";
|
|
|
8
8
|
import * as Result from "effect/Result";
|
|
9
9
|
import { runMediaGeneration } from "./media-generation.js";
|
|
10
10
|
import { quoteMediaGeneration } from "./media-quote.js";
|
|
11
|
-
import { validateMediaGenerationSettings,
|
|
11
|
+
import { validateMediaGenerationSettings, listMediaModels, mediaGenerationSettingsSchema, mediaRequestedImageFormatSchema, MediaSettingsError, } from "./index.js";
|
|
12
12
|
import { mediaResultSchema, } from "./media-operation-contract.js";
|
|
13
13
|
import { MediaOutputFormatMismatch, MediaBillingRefusal, MediaExecutionError, MediaSafetyFilterRefusal, } from "./execution-error.js";
|
|
14
14
|
export { createDailyMediaMetering, DailyMediaMeter, } from "./daily-media-meter.js";
|
|
@@ -194,15 +194,16 @@ function outcomeResponse(outcome) {
|
|
|
194
194
|
costMilliunits: outcome.costMilliunits,
|
|
195
195
|
path: outcome.path,
|
|
196
196
|
format: outcome.format,
|
|
197
|
-
height: outcome.height,
|
|
198
197
|
model: outcome.model,
|
|
198
|
+
height: outcome.height,
|
|
199
199
|
width: outcome.width,
|
|
200
200
|
}), { headers });
|
|
201
201
|
}
|
|
202
202
|
/** Relative HTTP routes; the caller admits identity and supplies destination access. */
|
|
203
203
|
export function createMediaService(host) {
|
|
204
204
|
const app = new Hono();
|
|
205
|
-
app.get("/models", () => Response.json((host.catalogue ??
|
|
205
|
+
app.get("/models", () => Response.json((host.catalogue ?? listMediaModels())
|
|
206
|
+
.map((model) => host.destination.readReference !== undefined ||
|
|
206
207
|
model.input.maxReferences === 0
|
|
207
208
|
? model
|
|
208
209
|
: {
|
|
@@ -213,7 +214,11 @@ export function createMediaService(host) {
|
|
|
213
214
|
maxReferences: 0,
|
|
214
215
|
referenceField: null,
|
|
215
216
|
},
|
|
216
|
-
})
|
|
217
|
+
})
|
|
218
|
+
.map((model) => host.destination.readAudioReference !== undefined ||
|
|
219
|
+
model.video?.audioReferences == null
|
|
220
|
+
? model
|
|
221
|
+
: { ...model, video: { ...model.video, audioReferences: null } }), { headers }));
|
|
217
222
|
app.post("/generate", async (context) => {
|
|
218
223
|
const body = await readJsonBody(context.req.raw);
|
|
219
224
|
const input = body.kind === "parsed"
|
|
@@ -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
|
-
|
|
2
|
+
function base64(bytes) {
|
|
3
3
|
const chunks = [];
|
|
4
|
-
for (let offset = 0; offset <
|
|
5
|
-
chunks.push(btoa(String.fromCharCode(...
|
|
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
|
};
|
|
@@ -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:
|
|
205
|
-
height:
|
|
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
|
>;
|
|
@@ -550,6 +583,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
|
|
|
550
583
|
kind: ZodEnum<{
|
|
551
584
|
image: "image";
|
|
552
585
|
video: "video";
|
|
586
|
+
audio: "audio";
|
|
553
587
|
}>;
|
|
554
588
|
tier: ZodEnum<{
|
|
555
589
|
draft: "draft";
|
|
@@ -580,6 +614,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
|
|
|
580
614
|
}, $strict>>>;
|
|
581
615
|
sizes: ZodNullable<ZodReadonly<ZodArray<ZodString>>>;
|
|
582
616
|
video: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
|
|
617
|
+
audio: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
|
|
583
618
|
}, $strict>>>>, ZodUnion<readonly [ZodObject<{
|
|
584
619
|
error: ZodEnum<{
|
|
585
620
|
revoked: "revoked";
|
|
@@ -646,10 +681,11 @@ const appMediaGenerationOutcomeSchema: ZodUnion<readonly [ZodObject<{
|
|
|
646
681
|
gif: "gif";
|
|
647
682
|
webp: "webp";
|
|
648
683
|
mp4: "mp4";
|
|
684
|
+
mp3: "mp3";
|
|
649
685
|
}>;
|
|
650
|
-
height: ZodNumber
|
|
686
|
+
height: ZodOptional<ZodNumber>;
|
|
651
687
|
model: ZodString;
|
|
652
|
-
width: ZodNumber
|
|
688
|
+
width: ZodOptional<ZodNumber>;
|
|
653
689
|
}, $strict>, ZodObject<{
|
|
654
690
|
kind: ZodLiteral<"pending">;
|
|
655
691
|
retryAfterMs: ZodNumber;
|
package/docs/api/cloudflare.md
CHANGED
|
@@ -374,9 +374,9 @@ output, and releases the lease so a later retry saves and charges it.
|
|
|
374
374
|
|
|
375
375
|
###### Parameters
|
|
376
376
|
|
|
377
|
-
| Parameter | Type
|
|
378
|
-
| ---------- |
|
|
379
|
-
| ...`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`; \}\>[]\] | - |
|
|
380
380
|
|
|
381
381
|
###### Returns
|
|
382
382
|
|