@fungi.computer/darkroom 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -0
- package/dist/app-media-contracts.d.ts +107 -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/browser-failure.d.ts +2 -0
- package/dist/browser-failure.js +2 -0
- package/dist/cloudflare/provider.d.ts +6 -4
- package/dist/cloudflare/provider.js +39 -21
- 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 +19 -9
- package/dist/gateway-models.js +57 -19
- package/dist/gateway-wire.d.ts +1 -0
- package/dist/gateway-wire.js +2 -0
- package/dist/index.d.ts +116 -24
- package/dist/index.js +147 -26
- package/dist/media-binding.d.ts +60 -7
- package/dist/media-binding.js +43 -21
- package/dist/media-generation.js +20 -7
- package/dist/media-operation-contract.d.ts +9 -3
- package/dist/media-operation-contract.js +6 -4
- package/dist/media-operation-do.d.ts +13 -2
- package/dist/media-operation-do.js +26 -1
- package/dist/media-operation-owner.d.ts +10 -2
- package/dist/media-operation-owner.js +56 -11
- package/dist/media-operation.js +5 -3
- package/dist/media-quote.d.ts +14 -0
- package/dist/media-quote.js +17 -0
- package/dist/model-catalog.d.ts +602 -6
- package/dist/model-catalog.js +309 -9
- package/dist/reference-image-size.d.ts +4 -3
- package/dist/reference-image-size.js +9 -9
- package/dist/server.d.ts +31 -8
- package/dist/server.js +51 -8
- 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 +50 -10
- package/docs/api/browser.md +4 -2
- package/docs/api/cloudflare.md +56 -3
- package/docs/api/index.md +1042 -121
- package/docs/api/server.md +306 -50
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -133,6 +133,135 @@ fact.
|
|
|
133
133
|
Video generation runs through the operation's alarm. A 202 response tells you to
|
|
134
134
|
retry the same request ID after the supplied `Retry-After` delay.
|
|
135
135
|
|
|
136
|
+
## Bring your own provider and models
|
|
137
|
+
|
|
138
|
+
A provider owns its model list. The built-in Fungi gateway provider carries
|
|
139
|
+
today's catalogue; a host that injects its own `MediaProvider` also supplies
|
|
140
|
+
that provider's catalogue, as data decoded with `parseMediaCatalogue`. Darkroom
|
|
141
|
+
validates every request against the active provider's catalogue, so `fal-ai/...`
|
|
142
|
+
ids are accepted by your provider and refused by the gateway's.
|
|
143
|
+
|
|
144
|
+
Each entry carries the per-model bounds the validator enforces: prompt length,
|
|
145
|
+
dimensions or exact sizes, steps, reference counts, and for video the durations,
|
|
146
|
+
resolution/aspect formats and per-second prices. Mark a video model's
|
|
147
|
+
`video.provider` as `"host"`: your provider owns that model's wire grammar.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import {
|
|
151
|
+
parseMediaCatalogue,
|
|
152
|
+
type MediaProvider,
|
|
153
|
+
} from "@fungi.computer/darkroom";
|
|
154
|
+
import { createMediaService } from "@fungi.computer/darkroom/server";
|
|
155
|
+
import { MediaOperationDO } from "@fungi.computer/darkroom/cloudflare";
|
|
156
|
+
|
|
157
|
+
declare const FAL_KEY: string; // your fal.ai key, from the host environment
|
|
158
|
+
|
|
159
|
+
// Decoded once; throws MediaSettingsError on a malformed or contradictory entry.
|
|
160
|
+
export const falCatalogue = parseMediaCatalogue([
|
|
161
|
+
{
|
|
162
|
+
id: "fal-ai/minimax/hailuo-2.3/standard/image-to-video",
|
|
163
|
+
label: "Hailuo 2.3 Standard",
|
|
164
|
+
kind: "video",
|
|
165
|
+
tier: "draft",
|
|
166
|
+
outputFormats: [],
|
|
167
|
+
maxPromptLength: 2_000,
|
|
168
|
+
sizes: ["1366x768"],
|
|
169
|
+
input: {
|
|
170
|
+
transport: "json",
|
|
171
|
+
dimensions: "own",
|
|
172
|
+
maxDimension: 1366,
|
|
173
|
+
maxDimensionDocumented: false,
|
|
174
|
+
defaultWidth: 1366,
|
|
175
|
+
defaultHeight: 768,
|
|
176
|
+
steps: "fixed",
|
|
177
|
+
maxSteps: null,
|
|
178
|
+
defaultSteps: null,
|
|
179
|
+
referenceField: "image_url",
|
|
180
|
+
maxReferences: 1,
|
|
181
|
+
referenceDimension: null,
|
|
182
|
+
referenceFormat: "png",
|
|
183
|
+
},
|
|
184
|
+
video: {
|
|
185
|
+
minSeconds: 6,
|
|
186
|
+
maxSeconds: 10,
|
|
187
|
+
defaultSeconds: 6,
|
|
188
|
+
durations: [6, 10],
|
|
189
|
+
provider: "host",
|
|
190
|
+
formats: [
|
|
191
|
+
{ resolution: "768p", aspectRatio: "16:9", width: 1366, height: 768 },
|
|
192
|
+
],
|
|
193
|
+
defaultResolution: "768p",
|
|
194
|
+
defaultAspectRatio: "16:9",
|
|
195
|
+
supportsAudio: false,
|
|
196
|
+
defaultGenerateAudio: null,
|
|
197
|
+
referenceRoles: ["first-frame"],
|
|
198
|
+
maxReferenceImages: 0,
|
|
199
|
+
referenceResolutions: [],
|
|
200
|
+
prices: [
|
|
201
|
+
{
|
|
202
|
+
resolution: "768p",
|
|
203
|
+
silentMilliunitsPerSecond: 3_000,
|
|
204
|
+
audioMilliunitsPerSecond: 3_000,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
]);
|
|
210
|
+
|
|
211
|
+
// Settings arrive already validated against falCatalogue.
|
|
212
|
+
export const falProvider: MediaProvider = async (
|
|
213
|
+
settings,
|
|
214
|
+
references,
|
|
215
|
+
signal,
|
|
216
|
+
) => {
|
|
217
|
+
const first = references[0];
|
|
218
|
+
if (first === undefined)
|
|
219
|
+
throw new Error("image-to-video needs a first frame");
|
|
220
|
+
const queued = await fetch(`https://queue.fal.run/${settings.model}`, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: {
|
|
223
|
+
Authorization: `Key ${FAL_KEY}`,
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify({
|
|
227
|
+
prompt: settings.prompt,
|
|
228
|
+
duration: String(settings.durationSeconds),
|
|
229
|
+
image_url: `data:image/${first.format};base64,${btoa(String.fromCharCode(...first.bytes))}`,
|
|
230
|
+
}),
|
|
231
|
+
signal: signal ?? null,
|
|
232
|
+
});
|
|
233
|
+
// ...poll the queue, download the MP4 and return it.
|
|
234
|
+
return {
|
|
235
|
+
bytes: new Uint8Array(await (await queued.blob()).arrayBuffer()),
|
|
236
|
+
format: "mp4",
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// The durable job engine runs your provider from its alarm, so it needs the
|
|
241
|
+
// same catalogue.
|
|
242
|
+
export class FalMediaOperationDO extends MediaOperationDO {
|
|
243
|
+
protected override mediaProvider() {
|
|
244
|
+
return falProvider;
|
|
245
|
+
}
|
|
246
|
+
protected override mediaCatalogue() {
|
|
247
|
+
return falCatalogue;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// In the request path, pass the catalogue and your own quote beside the provider.
|
|
252
|
+
const service = createMediaService({
|
|
253
|
+
// scope, operations, metering and destination as in the quick start
|
|
254
|
+
provider: falProvider,
|
|
255
|
+
catalogue: falCatalogue,
|
|
256
|
+
estimate: (settings) => 3_000 * (settings.durationSeconds ?? 6),
|
|
257
|
+
// ...
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`GET /models` lists `falCatalogue`. A request for a model outside it, or
|
|
262
|
+
settings outside its bounds, is refused before billing or dispatch. The
|
|
263
|
+
gateway's own models are refused by this provider the same way.
|
|
264
|
+
|
|
136
265
|
## API reference
|
|
137
266
|
|
|
138
267
|
| Import | Purpose |
|
|
@@ -329,6 +458,55 @@ destination and settings to recover the retained result. The host chooses the
|
|
|
329
458
|
output path, such as `prints-<requestId>.mp4`; Darkroom adds no output-naming
|
|
330
459
|
rule or human-review gate.
|
|
331
460
|
|
|
461
|
+
### Audio
|
|
462
|
+
|
|
463
|
+
Speech and music run through Cloudflare's Unified Billing, so Teams pay Team
|
|
464
|
+
credit at provider cost plus the normal markup and no customer key is involved.
|
|
465
|
+
The catalog carries `elevenlabs/eleven-multilingual-v2` (the default voice
|
|
466
|
+
model), `elevenlabs/eleven-v3` and `elevenlabs/music-v2`, each with
|
|
467
|
+
`kind: "audio"` and an `audio` block; every bound and rate comes from the
|
|
468
|
+
model's page under `https://developers.cloudflare.com/ai/models/elevenlabs/`.
|
|
469
|
+
Cloudflare offers no sound-effects model and no voice listing, so the only voice
|
|
470
|
+
is the one its pages list (`JBFqnCBsd6RMkjVDRZzb`), and sound effects, custom
|
|
471
|
+
voices and cloned voices are not offered.
|
|
472
|
+
|
|
473
|
+
Speech takes `prompt` (the spoken text, up to 10,000 characters) and an optional
|
|
474
|
+
catalog `voiceId`; music takes `prompt` and `durationSeconds` from 3 through 600
|
|
475
|
+
(30 when omitted). Neither takes dimensions, steps, `generateAudio` or
|
|
476
|
+
references; `validateMediaGenerationSettings` refuses them rather than dropping
|
|
477
|
+
them. Speech is quoted per character (5 or 10 milliunits) and music per second
|
|
478
|
+
(250 milliunits). `mediaUnits` bills speech as
|
|
479
|
+
`{unit: "audio_character_block", units: ceil(characters / 100)}` and music as
|
|
480
|
+
`{unit: "audio_second", units: durationSeconds}`, so a per-character rate is
|
|
481
|
+
marked up once per block. Requests ask ElevenLabs for `mp3_44100_128`; the
|
|
482
|
+
provider fetches the result URL and returns `{bytes, format: "mp3"}`. Audio runs
|
|
483
|
+
through the same durable alarm as video: HTTP returns 202 until the retained MP3
|
|
484
|
+
is ready, and the output has no embedded provenance. Hub public sharing does not
|
|
485
|
+
cover audio. The MEDIA binding accepts `kind: "audio"` with `prompt`, `voiceId`
|
|
486
|
+
or `durationSeconds`, and saves `<libraryPath>/prints-<requestId>.mp3`. The
|
|
487
|
+
`/models` listing still carries pictures and video only, because the Agar and
|
|
488
|
+
Prints catalog decoders have no audio kind yet; audio models are generated by
|
|
489
|
+
id.
|
|
490
|
+
|
|
491
|
+
Video models declare `video.audioReferences` (`{max, totalSeconds}`, or null).
|
|
492
|
+
Only Seedance 2.5 sets it, at 10 clips and 30 seconds, from its Cloudflare input
|
|
493
|
+
schema's `reference_audios`. A video selection may carry `audioReferences`
|
|
494
|
+
(`[{path}]`); every other model refuses them before admission, and a clip is
|
|
495
|
+
never dropped or trimmed. The host supplies authority through
|
|
496
|
+
`destination.readAudioReference(reference)`, which returns the raw bytes;
|
|
497
|
+
Darkroom parses each clip with music-metadata (mp3, m4a, wav, ogg or opus),
|
|
498
|
+
refuses unreadable bytes, and refuses a set whose count exceeds the model's
|
|
499
|
+
`max` or whose durations total more than `totalSeconds`, all before billing.
|
|
500
|
+
Clips reach the provider as `data:audio/...;base64,...` entries in
|
|
501
|
+
`reference_audios`, are retained in the artifacts bucket for the background
|
|
502
|
+
alarm like reference images, and are deleted after dispatch. A host that gives
|
|
503
|
+
no `readAudioReference` lists `audioReferences: null`. Standalone Oyster reads
|
|
504
|
+
clips from the Computer workspace; the Hub Agent host does not read audio
|
|
505
|
+
references yet. Parsing pulls in music-metadata, which reads Node built-ins, so
|
|
506
|
+
a Worker that runs the Media service needs the `nodejs_compat` flag (the Hub and
|
|
507
|
+
Oyster deploy configs set it). The hub-edge provider path only forwards clips
|
|
508
|
+
and MP3 output, and does not load the parser.
|
|
509
|
+
|
|
332
510
|
### App MEDIA binding
|
|
333
511
|
|
|
334
512
|
The shared `@fungi.computer/darkroom/server` binding grammar and reply decoder
|
|
@@ -12,10 +12,11 @@ export declare const mediaModelPriceEstimateSchema: z.ZodObject<{
|
|
|
12
12
|
settings: z.ZodObject<{
|
|
13
13
|
model: z.ZodString;
|
|
14
14
|
prompt: z.ZodString;
|
|
15
|
-
width: z.ZodNumber
|
|
16
|
-
height: z.ZodNumber
|
|
15
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
17
17
|
steps: z.ZodOptional<z.ZodNumber>;
|
|
18
18
|
durationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
voiceId: z.ZodOptional<z.ZodString>;
|
|
19
20
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
20
21
|
readonly p480: "480p";
|
|
21
22
|
readonly p720: "720p";
|
|
@@ -42,6 +43,10 @@ export declare const mediaModelPriceEstimateSchema: z.ZodObject<{
|
|
|
42
43
|
readonly reference: "reference";
|
|
43
44
|
}>>;
|
|
44
45
|
}, z.core.$strict>>>;
|
|
46
|
+
audioReferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
47
|
+
computerId: z.ZodString;
|
|
48
|
+
path: z.ZodString;
|
|
49
|
+
}, z.core.$strict>>>;
|
|
45
50
|
}, z.core.$strict>;
|
|
46
51
|
}, z.core.$strict>;
|
|
47
52
|
/** Host catalog projection; provider metadata remains owned by the sole catalog. */
|
|
@@ -51,6 +56,7 @@ export declare const mediaCatalogModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
51
56
|
kind: z.ZodEnum<{
|
|
52
57
|
readonly image: "image";
|
|
53
58
|
readonly video: "video";
|
|
59
|
+
readonly audio: "audio";
|
|
54
60
|
}>;
|
|
55
61
|
tier: z.ZodEnum<{
|
|
56
62
|
readonly draft: "draft";
|
|
@@ -154,6 +160,10 @@ export declare const mediaCatalogModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
154
160
|
readonly p1080: "1080p";
|
|
155
161
|
readonly p4k: "4k";
|
|
156
162
|
}>>>;
|
|
163
|
+
audioReferences: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
164
|
+
max: z.ZodNumber;
|
|
165
|
+
totalSeconds: z.ZodNumber;
|
|
166
|
+
}, z.core.$strict>>>;
|
|
157
167
|
prices: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
158
168
|
resolution: z.ZodEnum<{
|
|
159
169
|
readonly p480: "480p";
|
|
@@ -166,6 +176,24 @@ export declare const mediaCatalogModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
166
176
|
audioMilliunitsPerSecond: z.ZodNumber;
|
|
167
177
|
}, z.core.$strict>>>>;
|
|
168
178
|
}, z.core.$strict>>>>;
|
|
179
|
+
audio: z.ZodNullable<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
180
|
+
provider: z.ZodLiteral<"elevenlabs">;
|
|
181
|
+
mode: z.ZodEnum<{
|
|
182
|
+
readonly speech: "speech";
|
|
183
|
+
readonly music: "music";
|
|
184
|
+
}>;
|
|
185
|
+
voices: z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
186
|
+
id: z.ZodString;
|
|
187
|
+
label: z.ZodString;
|
|
188
|
+
}, z.core.$strict>>>>>;
|
|
189
|
+
defaultVoiceId: z.ZodNullable<z.ZodString>;
|
|
190
|
+
seconds: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
191
|
+
min: z.ZodNumber;
|
|
192
|
+
max: z.ZodNumber;
|
|
193
|
+
default: z.ZodNumber;
|
|
194
|
+
}, z.core.$strict>>>;
|
|
195
|
+
milliunitsPerUnit: z.ZodNumber;
|
|
196
|
+
}, z.core.$strict>>>>;
|
|
169
197
|
priceEstimate: z.ZodOptional<z.ZodObject<{
|
|
170
198
|
kind: z.ZodLiteral<"estimate">;
|
|
171
199
|
basis: z.ZodEnum<{
|
|
@@ -178,10 +206,11 @@ export declare const mediaCatalogModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
178
206
|
settings: z.ZodObject<{
|
|
179
207
|
model: z.ZodString;
|
|
180
208
|
prompt: z.ZodString;
|
|
181
|
-
width: z.ZodNumber
|
|
182
|
-
height: z.ZodNumber
|
|
209
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
210
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
183
211
|
steps: z.ZodOptional<z.ZodNumber>;
|
|
184
212
|
durationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
213
|
+
voiceId: z.ZodOptional<z.ZodString>;
|
|
185
214
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
186
215
|
readonly p480: "480p";
|
|
187
216
|
readonly p720: "720p";
|
|
@@ -208,6 +237,10 @@ export declare const mediaCatalogModelSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
208
237
|
readonly reference: "reference";
|
|
209
238
|
}>>;
|
|
210
239
|
}, z.core.$strict>>>;
|
|
240
|
+
audioReferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
241
|
+
computerId: z.ZodString;
|
|
242
|
+
path: z.ZodString;
|
|
243
|
+
}, z.core.$strict>>>;
|
|
211
244
|
}, z.core.$strict>;
|
|
212
245
|
}, z.core.$strict>>;
|
|
213
246
|
}, z.core.$strict>>;
|
|
@@ -218,6 +251,7 @@ export declare const mediaModelsSchema: z.ZodLazy<z.ZodArray<z.ZodReadonly<z.Zod
|
|
|
218
251
|
kind: z.ZodEnum<{
|
|
219
252
|
readonly image: "image";
|
|
220
253
|
readonly video: "video";
|
|
254
|
+
readonly audio: "audio";
|
|
221
255
|
}>;
|
|
222
256
|
tier: z.ZodEnum<{
|
|
223
257
|
readonly draft: "draft";
|
|
@@ -321,6 +355,10 @@ export declare const mediaModelsSchema: z.ZodLazy<z.ZodArray<z.ZodReadonly<z.Zod
|
|
|
321
355
|
readonly p1080: "1080p";
|
|
322
356
|
readonly p4k: "4k";
|
|
323
357
|
}>>>;
|
|
358
|
+
audioReferences: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
359
|
+
max: z.ZodNumber;
|
|
360
|
+
totalSeconds: z.ZodNumber;
|
|
361
|
+
}, z.core.$strict>>>;
|
|
324
362
|
prices: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
325
363
|
resolution: z.ZodEnum<{
|
|
326
364
|
readonly p480: "480p";
|
|
@@ -333,6 +371,24 @@ export declare const mediaModelsSchema: z.ZodLazy<z.ZodArray<z.ZodReadonly<z.Zod
|
|
|
333
371
|
audioMilliunitsPerSecond: z.ZodNumber;
|
|
334
372
|
}, z.core.$strict>>>>;
|
|
335
373
|
}, z.core.$strict>>>>;
|
|
374
|
+
audio: z.ZodNullable<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
375
|
+
provider: z.ZodLiteral<"elevenlabs">;
|
|
376
|
+
mode: z.ZodEnum<{
|
|
377
|
+
readonly speech: "speech";
|
|
378
|
+
readonly music: "music";
|
|
379
|
+
}>;
|
|
380
|
+
voices: z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
381
|
+
id: z.ZodString;
|
|
382
|
+
label: z.ZodString;
|
|
383
|
+
}, z.core.$strict>>>>>;
|
|
384
|
+
defaultVoiceId: z.ZodNullable<z.ZodString>;
|
|
385
|
+
seconds: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
386
|
+
min: z.ZodNumber;
|
|
387
|
+
max: z.ZodNumber;
|
|
388
|
+
default: z.ZodNumber;
|
|
389
|
+
}, z.core.$strict>>>;
|
|
390
|
+
milliunitsPerUnit: z.ZodNumber;
|
|
391
|
+
}, z.core.$strict>>>>;
|
|
336
392
|
priceEstimate: z.ZodOptional<z.ZodObject<{
|
|
337
393
|
kind: z.ZodLiteral<"estimate">;
|
|
338
394
|
basis: z.ZodEnum<{
|
|
@@ -345,10 +401,11 @@ export declare const mediaModelsSchema: z.ZodLazy<z.ZodArray<z.ZodReadonly<z.Zod
|
|
|
345
401
|
settings: z.ZodObject<{
|
|
346
402
|
model: z.ZodString;
|
|
347
403
|
prompt: z.ZodString;
|
|
348
|
-
width: z.ZodNumber
|
|
349
|
-
height: z.ZodNumber
|
|
404
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
405
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
350
406
|
steps: z.ZodOptional<z.ZodNumber>;
|
|
351
407
|
durationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
408
|
+
voiceId: z.ZodOptional<z.ZodString>;
|
|
352
409
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
353
410
|
readonly p480: "480p";
|
|
354
411
|
readonly p720: "720p";
|
|
@@ -375,6 +432,10 @@ export declare const mediaModelsSchema: z.ZodLazy<z.ZodArray<z.ZodReadonly<z.Zod
|
|
|
375
432
|
readonly reference: "reference";
|
|
376
433
|
}>>;
|
|
377
434
|
}, z.core.$strict>>>;
|
|
435
|
+
audioReferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
436
|
+
computerId: z.ZodString;
|
|
437
|
+
path: z.ZodString;
|
|
438
|
+
}, z.core.$strict>>>;
|
|
378
439
|
}, z.core.$strict>;
|
|
379
440
|
}, z.core.$strict>>;
|
|
380
441
|
}, z.core.$strict>>>>;
|
|
@@ -391,9 +452,10 @@ export declare const appMediaGenerationResultSchema: z.ZodObject<{
|
|
|
391
452
|
readonly gif: "gif";
|
|
392
453
|
readonly webp: "webp";
|
|
393
454
|
readonly mp4: "mp4";
|
|
455
|
+
readonly mp3: "mp3";
|
|
394
456
|
}>;
|
|
395
|
-
width: z.ZodNumber
|
|
396
|
-
height: z.ZodNumber
|
|
457
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
458
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
397
459
|
bytes: z.ZodNumber;
|
|
398
460
|
model: z.ZodString;
|
|
399
461
|
costMilliunits: z.ZodNumber;
|
|
@@ -464,6 +526,7 @@ export declare const agentAppMediaLibraryFailureSchema: z.ZodLazy<z.ZodObject<{
|
|
|
464
526
|
export declare const appMediaBrokerFailureSchema: z.ZodObject<{
|
|
465
527
|
error: z.ZodEnum<{
|
|
466
528
|
readonly CAPABILITY_DENIED: "CAPABILITY_DENIED";
|
|
529
|
+
readonly DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
|
|
467
530
|
readonly INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
|
|
468
531
|
readonly HOST_FAILURE: "HOST_FAILURE";
|
|
469
532
|
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
@@ -514,6 +577,7 @@ export declare const appMediaRefusalSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
514
577
|
}, z.core.$strict>>, z.ZodObject<{
|
|
515
578
|
error: z.ZodEnum<{
|
|
516
579
|
readonly CAPABILITY_DENIED: "CAPABILITY_DENIED";
|
|
580
|
+
readonly DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
|
|
517
581
|
readonly INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
|
|
518
582
|
readonly HOST_FAILURE: "HOST_FAILURE";
|
|
519
583
|
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
@@ -545,6 +609,7 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
545
609
|
kind: z.ZodEnum<{
|
|
546
610
|
readonly image: "image";
|
|
547
611
|
readonly video: "video";
|
|
612
|
+
readonly audio: "audio";
|
|
548
613
|
}>;
|
|
549
614
|
tier: z.ZodEnum<{
|
|
550
615
|
readonly draft: "draft";
|
|
@@ -648,6 +713,10 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
648
713
|
readonly p1080: "1080p";
|
|
649
714
|
readonly p4k: "4k";
|
|
650
715
|
}>>>;
|
|
716
|
+
audioReferences: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
717
|
+
max: z.ZodNumber;
|
|
718
|
+
totalSeconds: z.ZodNumber;
|
|
719
|
+
}, z.core.$strict>>>;
|
|
651
720
|
prices: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
652
721
|
resolution: z.ZodEnum<{
|
|
653
722
|
readonly p480: "480p";
|
|
@@ -660,6 +729,24 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
660
729
|
audioMilliunitsPerSecond: z.ZodNumber;
|
|
661
730
|
}, z.core.$strict>>>>;
|
|
662
731
|
}, z.core.$strict>>>>;
|
|
732
|
+
audio: z.ZodNullable<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
733
|
+
provider: z.ZodLiteral<"elevenlabs">;
|
|
734
|
+
mode: z.ZodEnum<{
|
|
735
|
+
readonly speech: "speech";
|
|
736
|
+
readonly music: "music";
|
|
737
|
+
}>;
|
|
738
|
+
voices: z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
739
|
+
id: z.ZodString;
|
|
740
|
+
label: z.ZodString;
|
|
741
|
+
}, z.core.$strict>>>>>;
|
|
742
|
+
defaultVoiceId: z.ZodNullable<z.ZodString>;
|
|
743
|
+
seconds: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
744
|
+
min: z.ZodNumber;
|
|
745
|
+
max: z.ZodNumber;
|
|
746
|
+
default: z.ZodNumber;
|
|
747
|
+
}, z.core.$strict>>>;
|
|
748
|
+
milliunitsPerUnit: z.ZodNumber;
|
|
749
|
+
}, z.core.$strict>>>>;
|
|
663
750
|
priceEstimate: z.ZodOptional<z.ZodObject<{
|
|
664
751
|
kind: z.ZodLiteral<"estimate">;
|
|
665
752
|
basis: z.ZodEnum<{
|
|
@@ -672,10 +759,11 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
672
759
|
settings: z.ZodObject<{
|
|
673
760
|
model: z.ZodString;
|
|
674
761
|
prompt: z.ZodString;
|
|
675
|
-
width: z.ZodNumber
|
|
676
|
-
height: z.ZodNumber
|
|
762
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
763
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
677
764
|
steps: z.ZodOptional<z.ZodNumber>;
|
|
678
765
|
durationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
766
|
+
voiceId: z.ZodOptional<z.ZodString>;
|
|
679
767
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
680
768
|
readonly p480: "480p";
|
|
681
769
|
readonly p720: "720p";
|
|
@@ -702,6 +790,10 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
702
790
|
readonly reference: "reference";
|
|
703
791
|
}>>;
|
|
704
792
|
}, z.core.$strict>>>;
|
|
793
|
+
audioReferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
794
|
+
computerId: z.ZodString;
|
|
795
|
+
path: z.ZodString;
|
|
796
|
+
}, z.core.$strict>>>;
|
|
705
797
|
}, z.core.$strict>;
|
|
706
798
|
}, z.core.$strict>>;
|
|
707
799
|
}, z.core.$strict>>>>, z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -729,6 +821,7 @@ export declare const appMediaModelsOutcomeSchema: z.ZodUnion<readonly [z.ZodLazy
|
|
|
729
821
|
}, z.core.$strict>>, z.ZodObject<{
|
|
730
822
|
error: z.ZodEnum<{
|
|
731
823
|
readonly CAPABILITY_DENIED: "CAPABILITY_DENIED";
|
|
824
|
+
readonly DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
|
|
732
825
|
readonly INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
|
|
733
826
|
readonly HOST_FAILURE: "HOST_FAILURE";
|
|
734
827
|
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
@@ -761,9 +854,10 @@ export declare const appMediaGenerationOutcomeSchema: z.ZodUnion<readonly [z.Zod
|
|
|
761
854
|
readonly gif: "gif";
|
|
762
855
|
readonly webp: "webp";
|
|
763
856
|
readonly mp4: "mp4";
|
|
857
|
+
readonly mp3: "mp3";
|
|
764
858
|
}>;
|
|
765
|
-
width: z.ZodNumber
|
|
766
|
-
height: z.ZodNumber
|
|
859
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
860
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
767
861
|
bytes: z.ZodNumber;
|
|
768
862
|
model: z.ZodString;
|
|
769
863
|
costMilliunits: z.ZodNumber;
|
|
@@ -799,6 +893,7 @@ export declare const appMediaGenerationOutcomeSchema: z.ZodUnion<readonly [z.Zod
|
|
|
799
893
|
}, z.core.$strict>>, z.ZodObject<{
|
|
800
894
|
error: z.ZodEnum<{
|
|
801
895
|
readonly CAPABILITY_DENIED: "CAPABILITY_DENIED";
|
|
896
|
+
readonly DAILY_LIMIT_REACHED: "DAILY_LIMIT_REACHED";
|
|
802
897
|
readonly INSUFFICIENT_CREDIT: "INSUFFICIENT_CREDIT";
|
|
803
898
|
readonly HOST_FAILURE: "HOST_FAILURE";
|
|
804
899
|
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type MediaModel } from "../model-catalog.js";
|
|
2
|
+
import type { MediaAiResult, MediaGenerationSettings } from "../index.js";
|
|
3
|
+
/**
|
|
4
|
+
* ElevenLabs on Cloudflare's Unified Billing. Every shape below is the model
|
|
5
|
+
* page's own `schema-input.json` / `schema-output.json`, checked 2026-11-13:
|
|
6
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-v3/
|
|
7
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-multilingual-v2/
|
|
8
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/music-v2/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* `mp3_44100_128` is in the `output_format` enum of every ElevenLabs model
|
|
12
|
+
* page above. It is requested explicitly so the saved file is always an MP3.
|
|
13
|
+
*/
|
|
14
|
+
declare const ELEVENLABS_OUTPUT_FORMAT = "mp3_44100_128";
|
|
15
|
+
/** A text-to-speech request: `text` (1-10,000 characters) and a required `voice_id`. */
|
|
16
|
+
export type ElevenLabsSpeechInput = {
|
|
17
|
+
text: string;
|
|
18
|
+
voice_id: string;
|
|
19
|
+
output_format: typeof ELEVENLABS_OUTPUT_FORMAT;
|
|
20
|
+
};
|
|
21
|
+
/** A music request: a `prompt` and `music_length_ms` of 3,000 through 600,000. */
|
|
22
|
+
export type ElevenLabsMusicInput = {
|
|
23
|
+
prompt: string;
|
|
24
|
+
music_length_ms: number;
|
|
25
|
+
output_format: typeof ELEVENLABS_OUTPUT_FORMAT;
|
|
26
|
+
};
|
|
27
|
+
/** Every ElevenLabs request body this catalog can produce. */
|
|
28
|
+
export type ElevenLabsInput = ElevenLabsSpeechInput | ElevenLabsMusicInput;
|
|
29
|
+
/** Results are fetched whole; 600 seconds of 128 kbps MP3 is about 10 MB. */
|
|
30
|
+
export declare const ELEVENLABS_MAX_BYTES: number;
|
|
31
|
+
/** The exact provider JSON body for one validated speech or music generation. */
|
|
32
|
+
export declare function buildElevenLabsInput(settings: MediaGenerationSettings, model: MediaModel): ElevenLabsInput;
|
|
33
|
+
/** Extract and validate the HTTPS result URL from the raw provider answer. */
|
|
34
|
+
export declare function decodeElevenLabsResultUrl(providerValue: MediaAiResult): string;
|
|
35
|
+
/**
|
|
36
|
+
* Provider cost in milliunits: speech is per character of text, music per
|
|
37
|
+
* second of output length asked for (1 USD = 100,000 milliunits).
|
|
38
|
+
*/
|
|
39
|
+
export declare function estimateElevenLabsMilliunits(settings: MediaGenerationSettings, model: MediaModel): number;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MediaSettingsError, } from "../model-catalog.js";
|
|
3
|
+
import { resultUrl } from "../gateway-wire.js";
|
|
4
|
+
/**
|
|
5
|
+
* ElevenLabs on Cloudflare's Unified Billing. Every shape below is the model
|
|
6
|
+
* page's own `schema-input.json` / `schema-output.json`, checked 2026-11-13:
|
|
7
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-v3/
|
|
8
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/eleven-multilingual-v2/
|
|
9
|
+
* https://developers.cloudflare.com/ai/models/elevenlabs/music-v2/
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* `mp3_44100_128` is in the `output_format` enum of every ElevenLabs model
|
|
13
|
+
* page above. It is requested explicitly so the saved file is always an MP3.
|
|
14
|
+
*/
|
|
15
|
+
const ELEVENLABS_OUTPUT_FORMAT = "mp3_44100_128";
|
|
16
|
+
/**
|
|
17
|
+
* The one shape a live Unified Billing call returned for Multilingual v2, v3
|
|
18
|
+
* and Music v2 (2026-11-13, REST envelope `{result: ...}` removed by the
|
|
19
|
+
* binding): `{state: "Completed", result: {audio: <HTTPS URL>}}`, the same
|
|
20
|
+
* wrapper Seedance and Veo use. The audio is a URL to fetch, not bytes. The
|
|
21
|
+
* model pages' bare `{audio}` schema-output is not what the gateway answers
|
|
22
|
+
* and is refused.
|
|
23
|
+
*/
|
|
24
|
+
const elevenLabsOutputSchema = z.lazy(() => z.looseObject({
|
|
25
|
+
state: z.literal("Completed"),
|
|
26
|
+
result: z.looseObject({ audio: resultUrl }),
|
|
27
|
+
}));
|
|
28
|
+
/** Results are fetched whole; 600 seconds of 128 kbps MP3 is about 10 MB. */
|
|
29
|
+
export const ELEVENLABS_MAX_BYTES = 32 * 1024 * 1024;
|
|
30
|
+
function audioOf(model) {
|
|
31
|
+
if (model.audio === null)
|
|
32
|
+
throw new MediaSettingsError(`${model.id} is not an audio model`);
|
|
33
|
+
return model.audio;
|
|
34
|
+
}
|
|
35
|
+
/** The exact provider JSON body for one validated speech or music generation. */
|
|
36
|
+
export function buildElevenLabsInput(settings, model) {
|
|
37
|
+
const audio = audioOf(model);
|
|
38
|
+
if (audio.mode === "speech") {
|
|
39
|
+
if (settings.voiceId === undefined)
|
|
40
|
+
throw new MediaSettingsError(`${model.id} needs a voice`);
|
|
41
|
+
return {
|
|
42
|
+
text: settings.prompt,
|
|
43
|
+
voice_id: settings.voiceId,
|
|
44
|
+
output_format: ELEVENLABS_OUTPUT_FORMAT,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (settings.durationSeconds === undefined)
|
|
48
|
+
throw new MediaSettingsError(`${model.id} needs a length`);
|
|
49
|
+
return {
|
|
50
|
+
prompt: settings.prompt,
|
|
51
|
+
music_length_ms: settings.durationSeconds * 1_000,
|
|
52
|
+
output_format: ELEVENLABS_OUTPUT_FORMAT,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Extract and validate the HTTPS result URL from the raw provider answer. */
|
|
56
|
+
export function decodeElevenLabsResultUrl(providerValue) {
|
|
57
|
+
return elevenLabsOutputSchema.parse(providerValue).result.audio;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Provider cost in milliunits: speech is per character of text, music per
|
|
61
|
+
* second of output length asked for (1 USD = 100,000 milliunits).
|
|
62
|
+
*/
|
|
63
|
+
export function estimateElevenLabsMilliunits(settings, model) {
|
|
64
|
+
const audio = audioOf(model);
|
|
65
|
+
const quantity = audio.mode === "speech" ? settings.prompt.length : settings.durationSeconds;
|
|
66
|
+
if (quantity === undefined)
|
|
67
|
+
throw new MediaSettingsError(`${model.id} needs a length`);
|
|
68
|
+
return quantity * audio.milliunitsPerUnit;
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type MediaVideoModel } from "./model-catalog.js";
|
|
2
|
+
/** Decoded bytes of one reference clip: well past 30 seconds of any admitted container. */
|
|
3
|
+
export declare const MAX_AUDIO_REFERENCE_BYTES: number;
|
|
4
|
+
/** Decoded bytes across every clip of one request; base64 adds a third. */
|
|
5
|
+
export declare const MAX_AUDIO_REFERENCE_BODY_BYTES: number;
|
|
6
|
+
/** One reference clip with the facts the provider request and the 30-second budget need. */
|
|
7
|
+
export type MediaAudioReferenceBytes = Readonly<{
|
|
8
|
+
/** Exact clip bytes as the Computer holds them. */
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
/** Media type of the clip's container, from its parsed header. */
|
|
11
|
+
mimeType: AudioReferenceMimeType;
|
|
12
|
+
/** Whole-clip duration in seconds, from the parsed header or decoded stream. */
|
|
13
|
+
durationSeconds: number;
|
|
14
|
+
/** Optional filename for diagnostics. */
|
|
15
|
+
filename?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Containers a clip may arrive in: `mp3`, `m4a`, `wav`, `ogg` and `opus`
|
|
19
|
+
* files. Seedance 2.5 states only that clips are "base64 data:audio/... URIs"
|
|
20
|
+
* and does not list formats, so Darkroom admits what the gallery plays.
|
|
21
|
+
* https://developers.cloudflare.com/ai/models/bytedance/seedance-2.5/schema-input.json
|
|
22
|
+
*/
|
|
23
|
+
export type AudioReferenceMimeType = "audio/mpeg" | "audio/mp4" | "audio/wav" | "audio/ogg";
|
|
24
|
+
/**
|
|
25
|
+
* Enforce the model's declared clip count and total duration. Neither is
|
|
26
|
+
* clamped: a clip over budget refuses the request instead of being dropped.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkAudioReferenceBudget(label: string, limits: NonNullable<MediaVideoModel["audioReferences"]>, clips: readonly Pick<MediaAudioReferenceBytes, "durationSeconds">[]): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MediaSettingsError } from "./model-catalog.js";
|
|
2
|
+
/** Decoded bytes of one reference clip: well past 30 seconds of any admitted container. */
|
|
3
|
+
export const MAX_AUDIO_REFERENCE_BYTES = 16 * 1024 * 1024;
|
|
4
|
+
/** Decoded bytes across every clip of one request; base64 adds a third. */
|
|
5
|
+
export const MAX_AUDIO_REFERENCE_BODY_BYTES = 24 * 1024 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Enforce the model's declared clip count and total duration. Neither is
|
|
8
|
+
* clamped: a clip over budget refuses the request instead of being dropped.
|
|
9
|
+
*/
|
|
10
|
+
export function checkAudioReferenceBudget(label, limits, clips) {
|
|
11
|
+
if (clips.length > limits.max)
|
|
12
|
+
throw new MediaSettingsError(`${label} takes up to ${String(limits.max)} audio references`);
|
|
13
|
+
const total = clips.reduce((sum, clip) => sum + clip.durationSeconds, 0);
|
|
14
|
+
if (total > limits.totalSeconds)
|
|
15
|
+
throw new MediaSettingsError(`${label} audio references total ${total.toFixed(1)} seconds; the limit is ${String(limits.totalSeconds)}`);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MediaCatalogue } from "./model-catalog.js";
|
|
2
|
+
import type { MediaGenerationSettings, MediaReference } from "./index.js";
|
|
3
|
+
import { type MediaAudioReferenceBytes } from "./audio-reference-types.js";
|
|
4
|
+
/** Host-authorized reader for the raw bytes of reference audio clips. */
|
|
5
|
+
export type MediaAudioReferenceReader = Readonly<{
|
|
6
|
+
/** Authorize and read one clip; Darkroom parses it, the host never does. */
|
|
7
|
+
read: (reference: MediaReference) => Promise<Uint8Array>;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Read every reference clip through the caller's reader and parse each with
|
|
11
|
+
* music-metadata. The model's declared clip count and total duration are
|
|
12
|
+
* enforced here, before billing admission; nothing is clamped or dropped.
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveMediaAudioReferences: (settings: MediaGenerationSettings, reader: MediaAudioReferenceReader, catalogue?: MediaCatalogue) => Promise<readonly MediaAudioReferenceBytes[]>;
|