@devvibex/aiflow 1.15.0 → 1.15.2
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 +43 -13
- package/package.json +1 -1
- package/src/index.d.ts +39 -24
- package/src/index.js +73 -8
package/README.md
CHANGED
|
@@ -148,9 +148,13 @@ page. The module default is set with `admin.updateConfig({ imageBackground })`.
|
|
|
148
148
|
Returns `{ videoUrl, usage: { creditsUsed } }`. Pass `image` for image-to-video
|
|
149
149
|
or `video` for video-to-video; omit both for pure text-to-video.
|
|
150
150
|
|
|
151
|
-
`image` is the clip's first frame. On **Seedance**, add `lastFrame`
|
|
152
|
-
frame the clip ends on as well — the video moves from `image` to
|
|
153
|
-
`lastFrame` requires `image`; Gemini Omni and Veo ignore it.
|
|
151
|
+
`image` is the clip's first frame. On **Seedance** and **Kling**, add `lastFrame`
|
|
152
|
+
to fix the frame the clip ends on as well — the video moves from `image` to
|
|
153
|
+
`lastFrame`. `lastFrame` requires `image`; Gemini Omni and Veo ignore it.
|
|
154
|
+
|
|
155
|
+
**Kling** (`model: 'kling'`, Kling 3.0): 3–15s clips (`duration`), 720p or
|
|
156
|
+
1080p, 16:9 / 9:16 / 1:1, JPG / PNG images only. Silent unless
|
|
157
|
+
`generateAudio: true`, which costs more per second.
|
|
154
158
|
|
|
155
159
|
```js
|
|
156
160
|
const clip = await aiflow.generateVideo({
|
|
@@ -163,7 +167,8 @@ const clip = await aiflow.generateVideo({
|
|
|
163
167
|
|
|
164
168
|
**Seedance reference mode.** Instead of a first frame, Seedance can take
|
|
165
169
|
reference assets and keep them consistent in a new shot — cite them in the
|
|
166
|
-
prompt as
|
|
170
|
+
prompt as `@Image 1`, `@Video 1`, `@Audio 1` (or `[Image 1]`) in the order you
|
|
171
|
+
pass them; the gateway converts to the form the running Seedance release uses.
|
|
167
172
|
It is a separate mode: it cannot be combined with `image` / `lastFrame`.
|
|
168
173
|
|
|
169
174
|
| | Seedance 2.0 | Seedance 2.5 |
|
|
@@ -179,12 +184,31 @@ default; `generateAudio: false` makes them silent.
|
|
|
179
184
|
```js
|
|
180
185
|
const ad = await aiflow.generateVideo({
|
|
181
186
|
model: 'seedance',
|
|
182
|
-
prompt: 'The girl from
|
|
187
|
+
prompt: 'The girl from @Image 1 unboxes the sneaker from @Image 2, dancing to @Audio 1',
|
|
183
188
|
referenceImages: [characterUrl, productUrl],
|
|
184
189
|
referenceAudios: [musicUrl],
|
|
185
190
|
});
|
|
186
191
|
```
|
|
187
192
|
|
|
193
|
+
**Sending audio (Seedance).** `referenceAudios` takes wav or mp3 clips — an
|
|
194
|
+
`https://` URL, a `data:` URL, an `asset://` id, or (≥ 1.15.2) the uploaded
|
|
195
|
+
`File` itself, which the SDK sends as a data URL. Each clip runs at least 2s and
|
|
196
|
+
is under 15 MB; together they stay within 15s on Seedance 2.0 and 30s on 2.5.
|
|
197
|
+
Browser microphone recordings (webm / ogg) are refused with an `AIFlowError`
|
|
198
|
+
before any request. Pair a voice or song with a picture of the performer for a
|
|
199
|
+
lip-synced clip:
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
const clip = await aiflow.generateVideo({
|
|
203
|
+
model: 'seedance',
|
|
204
|
+
prompt: 'The woman in @Image 1 sings @Audio 1 with precise lip sync',
|
|
205
|
+
referenceImages: [portraitFile], // File / Blob from <input type="file">
|
|
206
|
+
referenceAudios: [songFile], // wav or mp3 File
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
Reference audio is its own mode: it cannot be combined with `image` /
|
|
210
|
+
`lastFrame` (start and end frames).
|
|
211
|
+
|
|
188
212
|
The default model is **Gemini Omni**: one clip of ~10s, **with sound**, 16:9 or
|
|
189
213
|
9:16 only, and no length parameter. For a longer or extendable video use
|
|
190
214
|
`generateLongVideo` / `createVideoSession` below — same model, so a single clip
|
|
@@ -340,19 +364,23 @@ job's `videoUrl` is the timeline and `segmentUrl` the new tail.
|
|
|
340
364
|
Every turn is billed separately (Omni prices by output token), and
|
|
341
365
|
`session.usage.creditsUsed` is the running total for the whole session.
|
|
342
366
|
|
|
343
|
-
### `aiflow.generateAudio({ prompt, model?, images?, format?, negativePrompt?, seed?, signal?, timeout? })`
|
|
367
|
+
### `aiflow.generateAudio({ prompt, model?, images?, durationSeconds?, format?, negativePrompt?, seed?, signal?, timeout? })`
|
|
344
368
|
|
|
345
369
|
Generate music from a text prompt with Google **Lyria 3.5**. Returns
|
|
346
370
|
`{ audioUrl, model, durationSeconds, lyrics, usage: { creditsUsed } }`;
|
|
347
371
|
`audioUrl` is a hosted mp3 on the CDN. `prompt` is a musical description (mood,
|
|
348
|
-
genre, tempo/BPM, instrumentation)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
372
|
+
genre, tempo/BPM, instrumentation) and exclusions ("no vocals"). Custom lyrics
|
|
373
|
+
go in the prompt with section tags (`[Verse]`, `[Chorus]`, `[Bridge]`).
|
|
374
|
+
|
|
375
|
+
- `durationSeconds` — song length, 5–180. Lyria 3.5 has no length setting and
|
|
376
|
+
runs long (a 30s request measured 44–63s), so the gateway lays the song out
|
|
377
|
+
to this length and cuts it to exactly this length with a 1–3s fade-out.
|
|
378
|
+
Without it the song is as long as the model makes it, usually one to three
|
|
379
|
+
minutes. A length written only in `prompt` is a loose suggestion. Needs
|
|
380
|
+
≥ 1.15.1: 1.15.0 and older drop `durationSeconds` from music requests.
|
|
353
381
|
- `images` — up to 10 https:// or data: URLs for the music to be inspired by,
|
|
354
382
|
on the models in `config.audioImageInputModels`.
|
|
355
|
-
- `format` — `'mp3'` (default) or `'wav'` (
|
|
383
|
+
- `format` — `'mp3'` (default) or `'wav'` (48 kHz stereo, about 11.5 MB per
|
|
356
384
|
minute — offer it as a download).
|
|
357
385
|
- `negativePrompt` — what the music must not contain; appended to the prompt
|
|
358
386
|
as an exclusion, since Lyria 3.5 has no separate field for it.
|
|
@@ -365,9 +393,11 @@ prompt with section tags (`[Verse]`, `[Chorus]`, `[Bridge]`).
|
|
|
365
393
|
const song = await aiflow.generateAudio({
|
|
366
394
|
prompt: 'Bright acoustic pop, 100 BPM, female vocal. [Verse] Morning light on the harbour ... [Chorus] ...',
|
|
367
395
|
images: [coverPhotoUrl],
|
|
396
|
+
durationSeconds: 30,
|
|
368
397
|
format: 'wav',
|
|
369
398
|
});
|
|
370
|
-
song.audioUrl;
|
|
399
|
+
song.audioUrl; // .wav on the CDN
|
|
400
|
+
song.durationSeconds; // ~30
|
|
371
401
|
song.lyrics; // "Morning light on the harbour…\n\n…"
|
|
372
402
|
```
|
|
373
403
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvibex/aiflow",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.2",
|
|
4
4
|
"description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image, video (including stateful multi-turn video extension with Gemini Omni), music (Lyria), sound effects (ElevenLabs), embeddings and real-time speech translation (Gemini Live) without shipping any third-party API key.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
package/src/index.d.ts
CHANGED
|
@@ -201,27 +201,28 @@ export interface ImageBatchResponse {
|
|
|
201
201
|
export interface VideoRequest {
|
|
202
202
|
prompt: string;
|
|
203
203
|
/**
|
|
204
|
-
* Video model: `'gemini-omni'` | `'veo'` | `'seedance'`. Defaults to the
|
|
204
|
+
* Video model: `'gemini-omni'` | `'veo'` | `'seedance'` | `'kling'`. Defaults to the
|
|
205
205
|
* app's configured model, which is Gemini Omni unless the module was pinned
|
|
206
206
|
* to another one. Omni clips always have sound and are the only ones that
|
|
207
207
|
* can be extended (see {@link AIFlowClient.createVideoSession}).
|
|
208
208
|
*/
|
|
209
209
|
model?: string;
|
|
210
210
|
/**
|
|
211
|
-
* Output aspect ratio. Gemini Omni supports 16:9 / 9:16 only; Veo
|
|
212
|
-
*
|
|
213
|
-
* 16:9 by the
|
|
211
|
+
* Output aspect ratio. Gemini Omni supports 16:9 / 9:16 only; Veo and Kling
|
|
212
|
+
* also 1:1 (Kling image-to-video keeps the image's ratio); Seedance also
|
|
213
|
+
* 1:1 / 4:3 / 3:4 / 21:9. An unsupported ratio is mapped to 16:9 by the
|
|
214
|
+
* server.
|
|
214
215
|
*/
|
|
215
216
|
aspectRatio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '21:9' | string;
|
|
216
217
|
/**
|
|
217
|
-
* Output resolution: '720p' (default) | '1080p' on Gemini Omni
|
|
218
|
-
*
|
|
218
|
+
* Output resolution: '720p' (default) | '1080p' on Gemini Omni, Seedance
|
|
219
|
+
* and Kling; Seedance also '480p' (Omni and Kling treat it as 720p). Lower generates
|
|
219
220
|
* faster and, on Omni, costs less. Ignored by Veo.
|
|
220
221
|
*/
|
|
221
222
|
resolution?: '480p' | '720p' | '1080p' | string;
|
|
222
223
|
/**
|
|
223
|
-
* Clip length in seconds — Seedance
|
|
224
|
-
* 4–30 on 2.5 (clamped to that range, default 5). Gemini Omni takes no
|
|
224
|
+
* Clip length in seconds — Seedance and Kling: an integer 4–15 on Seedance
|
|
225
|
+
* 2.0, 4–30 on 2.5, 3–15 on Kling (clamped to that range, default 5). Gemini Omni takes no
|
|
225
226
|
* length and returns a ~10s clip (longer:
|
|
226
227
|
* {@link AIFlowClient.generateLongVideo}); Veo uses a fixed length.
|
|
227
228
|
*/
|
|
@@ -230,39 +231,44 @@ export interface VideoRequest {
|
|
|
230
231
|
watermark?: boolean;
|
|
231
232
|
/**
|
|
232
233
|
* Still image to animate (image-to-video) — the clip's FIRST frame. An
|
|
233
|
-
* `https://` URL
|
|
234
|
+
* `https://` URL, a `data:` URL, or a `File` / `Blob` (≥ 1.15.2).
|
|
234
235
|
*/
|
|
235
|
-
image?: string;
|
|
236
|
+
image?: string | Blob;
|
|
236
237
|
/**
|
|
237
238
|
* Image the clip must END on (first + last frame). Same formats as `image`
|
|
238
|
-
* and requires it. Seedance
|
|
239
|
-
* module must be pinned to
|
|
239
|
+
* and requires it. Seedance and Kling — Gemini Omni and Veo ignore it, so
|
|
240
|
+
* the module must be pinned to one of them. Kling takes JPG / PNG only.
|
|
241
|
+
* Needs `@devvibex/aiflow` ≥ 1.15.0.
|
|
240
242
|
*/
|
|
241
|
-
lastFrame?: string;
|
|
242
|
-
video?: string;
|
|
243
|
+
lastFrame?: string | Blob;
|
|
244
|
+
video?: string | Blob;
|
|
243
245
|
/**
|
|
244
246
|
* Seedance only — reference images that keep a character, product or style
|
|
245
247
|
* (omni reference mode). Up to 9 on Seedance 2.0, 30 on 2.5. Cited in the
|
|
246
|
-
* prompt as
|
|
248
|
+
* prompt as @Image 1, @Image 2, … (or [Image 1]) in this order. `https://`, `data:` or
|
|
247
249
|
* `asset://`. Cannot be combined with `image` / `lastFrame`.
|
|
248
250
|
*/
|
|
249
|
-
referenceImages?: string
|
|
251
|
+
referenceImages?: Array<string | Blob>;
|
|
250
252
|
/**
|
|
251
253
|
* Seedance only — reference videos for motion/camera, or the clip to edit
|
|
252
254
|
* or extend. Up to 3 on Seedance 2.0 (2–15s each, ≤15s total), 10 on 2.5
|
|
253
|
-
* (≤30s total). `https://` or `asset://` only. Cited as
|
|
255
|
+
* (≤30s total). `https://` or `asset://` only. Cited as @Video 1, ….
|
|
254
256
|
*/
|
|
255
257
|
referenceVideos?: string[];
|
|
256
258
|
/**
|
|
257
259
|
* Seedance only — reference audio (voice, music, rhythm), wav or mp3. Up to
|
|
258
260
|
* 3 on Seedance 2.0 (2–15s each, ≤15s total), and there it needs at least
|
|
259
261
|
* one reference image or video; 10 on 2.5 (≤30s total), audio alone allowed.
|
|
260
|
-
* Cited as
|
|
262
|
+
* Cited as @Audio 1, …. A voice or song with a character picture gives a
|
|
263
|
+
* lip-synced performance ("the woman in @Image 1 sings @Audio 1"). Pass the
|
|
264
|
+
* uploaded `File`s directly (sent as data URLs, ≥ 1.15.2) or https:// URLs;
|
|
265
|
+
* each clip under 15 MB. Browser recordings (webm / ogg) are refused.
|
|
261
266
|
*/
|
|
262
|
-
referenceAudios?: string
|
|
267
|
+
referenceAudios?: Array<string | Blob>;
|
|
263
268
|
/**
|
|
264
|
-
* Seedance
|
|
265
|
-
*
|
|
269
|
+
* Seedance and Kling — whether the clip gets synchronized sound (voice,
|
|
270
|
+
* effects, music). Omitted: on for Seedance, off for Kling (where sound
|
|
271
|
+
* costs more per second).
|
|
266
272
|
*/
|
|
267
273
|
generateAudio?: boolean;
|
|
268
274
|
signal?: AbortSignal;
|
|
@@ -542,8 +548,9 @@ export interface VideoExtendSubmitResponse extends VideoJobSubmitResponse {
|
|
|
542
548
|
|
|
543
549
|
export interface AudioRequest {
|
|
544
550
|
/**
|
|
545
|
-
* Musical description — mood, genre, tempo (BPM), instrumentation, texture
|
|
546
|
-
*
|
|
551
|
+
* Musical description — mood, genre, tempo (BPM), instrumentation, texture
|
|
552
|
+
* and exclusions ("no vocals"). Put a set length in `durationSeconds`, not
|
|
553
|
+
* here: Lyria treats a length in the prompt as a loose suggestion.
|
|
547
554
|
*/
|
|
548
555
|
prompt: string;
|
|
549
556
|
model?: string;
|
|
@@ -554,7 +561,15 @@ export interface AudioRequest {
|
|
|
554
561
|
*/
|
|
555
562
|
images?: string[];
|
|
556
563
|
/**
|
|
557
|
-
*
|
|
564
|
+
* Song length in seconds, 5–180. Lyria 3.5 has no length setting and runs
|
|
565
|
+
* long, so the gateway lays the song out to this length and cuts it to
|
|
566
|
+
* exactly this length with a short fade-out; a shorter song is returned as
|
|
567
|
+
* is. Read the real length from `durationSeconds` in the response. Needs
|
|
568
|
+
* `@devvibex/aiflow` ≥ 1.15.1 — 1.15.0 and older drop it.
|
|
569
|
+
*/
|
|
570
|
+
durationSeconds?: number;
|
|
571
|
+
/**
|
|
572
|
+
* `'mp3'` (default) or `'wav'` — 48 kHz stereo, about 11.5 MB per minute,
|
|
558
573
|
* so offer WAV as a download rather than for in-page playback. Needs
|
|
559
574
|
* `@devvibex/aiflow` ≥ 1.15.0.
|
|
560
575
|
*/
|
package/src/index.js
CHANGED
|
@@ -562,6 +562,31 @@ export class AIFlowClient {
|
|
|
562
562
|
'referenceImages / referenceVideos / referenceAudios cannot be combined with image / lastFrame',
|
|
563
563
|
);
|
|
564
564
|
}
|
|
565
|
+
if (referenceVideos?.some(isBlob)) {
|
|
566
|
+
throw new AIFlowError(
|
|
567
|
+
'referenceVideos take https:// or asset:// URLs — upload the video file first',
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
// A File / Blob is sent as a data URL, so an upload can be passed as-is.
|
|
571
|
+
const [imageIn, lastFrameIn, videoIn, referenceImagesIn, referenceAudiosIn] =
|
|
572
|
+
await Promise.all([
|
|
573
|
+
toMediaInput(image),
|
|
574
|
+
toMediaInput(lastFrame),
|
|
575
|
+
toMediaInput(video),
|
|
576
|
+
referenceImages && Promise.all(referenceImages.map(toMediaInput)),
|
|
577
|
+
referenceAudios && Promise.all(referenceAudios.map(toMediaInput)),
|
|
578
|
+
]);
|
|
579
|
+
const badAudio = referenceAudiosIn?.find(
|
|
580
|
+
(a) =>
|
|
581
|
+
typeof a === 'string' &&
|
|
582
|
+
a.startsWith('data:') &&
|
|
583
|
+
!REFERENCE_AUDIO_DATA_URL.test(a),
|
|
584
|
+
);
|
|
585
|
+
if (badAudio) {
|
|
586
|
+
throw new AIFlowError(
|
|
587
|
+
`referenceAudios must be wav or mp3 files (got ${badAudio.slice(5, badAudio.search(/[;,]/))}); browser recordings such as webm are not accepted`,
|
|
588
|
+
);
|
|
589
|
+
}
|
|
565
590
|
const resolvedModel =
|
|
566
591
|
model || (await this._resolveDefaultModel('video'));
|
|
567
592
|
const res = await this._request(
|
|
@@ -573,12 +598,12 @@ export class AIFlowClient {
|
|
|
573
598
|
resolution,
|
|
574
599
|
duration,
|
|
575
600
|
watermark,
|
|
576
|
-
image,
|
|
577
|
-
lastFrame,
|
|
578
|
-
video,
|
|
579
|
-
referenceImages,
|
|
601
|
+
image: imageIn,
|
|
602
|
+
lastFrame: lastFrameIn,
|
|
603
|
+
video: videoIn,
|
|
604
|
+
referenceImages: referenceImagesIn,
|
|
580
605
|
referenceVideos,
|
|
581
|
-
referenceAudios,
|
|
606
|
+
referenceAudios: referenceAudiosIn,
|
|
582
607
|
generateAudio,
|
|
583
608
|
},
|
|
584
609
|
// Submit returns fast; the default client timeout is plenty even
|
|
@@ -1037,15 +1062,18 @@ export class AIFlowClient {
|
|
|
1037
1062
|
/**
|
|
1038
1063
|
* Generate music / background audio from a text prompt (Lyria 3.5),
|
|
1039
1064
|
* optionally inspired by up to 10 reference `images` (https:// or data:
|
|
1040
|
-
* URLs) on the models in `config.audioImageInputModels`.
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1065
|
+
* URLs) on the models in `config.audioImageInputModels`.
|
|
1066
|
+
* `durationSeconds` (5–180) fixes the length: Lyria has no length setting
|
|
1067
|
+
* and runs long, so the gateway plans the song to it and trims the rest
|
|
1068
|
+
* with a fade-out. `format: 'wav'` returns a WAV file instead of MP3;
|
|
1069
|
+
* `lyrics` in the result holds the sung words (null for an instrumental).
|
|
1043
1070
|
* @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, lyrics:string|null, prompt?:string, usage:{creditsUsed:number}}>}
|
|
1044
1071
|
*/
|
|
1045
1072
|
async generateAudio({
|
|
1046
1073
|
prompt,
|
|
1047
1074
|
model,
|
|
1048
1075
|
images,
|
|
1076
|
+
durationSeconds,
|
|
1049
1077
|
format,
|
|
1050
1078
|
negativePrompt,
|
|
1051
1079
|
seed,
|
|
@@ -1066,6 +1094,8 @@ export class AIFlowClient {
|
|
|
1066
1094
|
model: resolvedModel,
|
|
1067
1095
|
prompt,
|
|
1068
1096
|
images: images?.length ? images : undefined,
|
|
1097
|
+
// 5–180s; the gateway plans the song to it and trims overshoot.
|
|
1098
|
+
durationSeconds,
|
|
1069
1099
|
format,
|
|
1070
1100
|
negativePrompt,
|
|
1071
1101
|
seed,
|
|
@@ -1678,6 +1708,41 @@ async function loadSocketIoClient() {
|
|
|
1678
1708
|
}
|
|
1679
1709
|
}
|
|
1680
1710
|
|
|
1711
|
+
// Media types for a File / Blob whose `type` the browser left empty.
|
|
1712
|
+
const MEDIA_TYPE_BY_EXTENSION = {
|
|
1713
|
+
mp3: 'audio/mpeg',
|
|
1714
|
+
wav: 'audio/wav',
|
|
1715
|
+
png: 'image/png',
|
|
1716
|
+
jpg: 'image/jpeg',
|
|
1717
|
+
jpeg: 'image/jpeg',
|
|
1718
|
+
webp: 'image/webp',
|
|
1719
|
+
gif: 'image/gif',
|
|
1720
|
+
mp4: 'video/mp4',
|
|
1721
|
+
mov: 'video/quicktime',
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
// The audio types Seedance takes as reference audio (wav / mp3, any of the
|
|
1725
|
+
// names browsers give them); the gateway relabels them for Ark.
|
|
1726
|
+
const REFERENCE_AUDIO_DATA_URL =
|
|
1727
|
+
/^data:audio\/(mpeg|mp3|mpeg3|x-mp3|x-mpeg|mpg|wav|x-wav|wave|vnd\.wave)[;,]/i;
|
|
1728
|
+
|
|
1729
|
+
function isBlob(value) {
|
|
1730
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
/** A File / Blob as a `data:` URL; strings and empty values pass through. */
|
|
1734
|
+
async function toMediaInput(value) {
|
|
1735
|
+
if (!isBlob(value)) return value;
|
|
1736
|
+
const ext = String(value.name || '')
|
|
1737
|
+
.split('.')
|
|
1738
|
+
.pop()
|
|
1739
|
+
.toLowerCase();
|
|
1740
|
+
const type =
|
|
1741
|
+
value.type || MEDIA_TYPE_BY_EXTENSION[ext] || 'application/octet-stream';
|
|
1742
|
+
const bytes = new Uint8Array(await value.arrayBuffer());
|
|
1743
|
+
return `data:${type};base64,${toBase64(bytes)}`;
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1681
1746
|
function toBase64(chunk) {
|
|
1682
1747
|
if (typeof chunk === 'string') return chunk; // assume already base64
|
|
1683
1748
|
let bytes;
|