@devvibex/aiflow 1.14.0 → 1.15.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 +87 -14
- package/package.json +1 -1
- package/src/index.d.ts +72 -9
- package/src/index.js +81 -15
package/README.md
CHANGED
|
@@ -119,29 +119,72 @@ to invalidate the cache.
|
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, signal? })`
|
|
122
|
+
### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, webSearch?, signal? })`
|
|
123
123
|
|
|
124
124
|
Returns `Promise<{ id, model, content, usage: { inputTokens, outputTokens, creditsUsed } }>`.
|
|
125
|
+
Web search is built in and on by default; `webSearch: false` answers one
|
|
126
|
+
request without it. Caller-defined `tools` are not supported — passing them
|
|
127
|
+
throws.
|
|
125
128
|
|
|
126
129
|
### `aiflow.chatStream({ ... })`
|
|
127
130
|
|
|
128
131
|
Async iterable of `{ delta: string, done: boolean }` chunks. The final chunk
|
|
129
132
|
has `done: true` and carries the cumulative `usage` object.
|
|
130
133
|
|
|
131
|
-
### `aiflow.generateImage({ prompt, model?, size?, n?, image?, images?, system?, language?, background?, signal? })`
|
|
134
|
+
### `aiflow.generateImage({ prompt, model?, size?, aspectRatio?, n?, image?, images?, system?, language?, background?, signal? })`
|
|
132
135
|
|
|
133
136
|
Returns `{ images: [{ url?, b64?, mimeType }], usage: { creditsUsed } }`.
|
|
134
137
|
`url` is a short-lived signed URL (~1h). Pass `image`/`images` to edit an
|
|
135
|
-
existing image (image-to-image) instead of generating from text.
|
|
138
|
+
existing image (image-to-image) instead of generating from text.
|
|
139
|
+
`aspectRatio` (`'1:1'`, `'2:3'`, `'3:2'`, `'3:4'`, `'4:3'`, `'9:16'`, `'16:9'`,
|
|
140
|
+
`'21:9'`) sets the frame on the Gemini image models; GPT image models use
|
|
141
|
+
`size` instead. `background`
|
|
136
142
|
(`'auto'` | `'transparent'` | `'opaque'`) is honoured only by the models in
|
|
137
143
|
`config.imageBackgroundModels`; `generateImageBatch` takes it top-level or per
|
|
138
144
|
page. The module default is set with `admin.updateConfig({ imageBackground })`.
|
|
139
145
|
|
|
140
|
-
### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, video?, signal? })`
|
|
146
|
+
### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, lastFrame?, video?, referenceImages?, referenceVideos?, referenceAudios?, generateAudio?, signal? })`
|
|
141
147
|
|
|
142
148
|
Returns `{ videoUrl, usage: { creditsUsed } }`. Pass `image` for image-to-video
|
|
143
149
|
or `video` for video-to-video; omit both for pure text-to-video.
|
|
144
150
|
|
|
151
|
+
`image` is the clip's first frame. On **Seedance**, add `lastFrame` to fix the
|
|
152
|
+
frame the clip ends on as well — the video moves from `image` to `lastFrame`.
|
|
153
|
+
`lastFrame` requires `image`; Gemini Omni and Veo ignore it.
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const clip = await aiflow.generateVideo({
|
|
157
|
+
model: 'seedance',
|
|
158
|
+
prompt: 'The flower slowly opens as morning light sweeps across it',
|
|
159
|
+
image: firstFrameUrl, // https:// or data: URL
|
|
160
|
+
lastFrame: lastFrameUrl,
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Seedance reference mode.** Instead of a first frame, Seedance can take
|
|
165
|
+
reference assets and keep them consistent in a new shot — cite them in the
|
|
166
|
+
prompt as `[Image 1]`, `[Video 1]`, `[Audio 1]` in the order you pass them.
|
|
167
|
+
It is a separate mode: it cannot be combined with `image` / `lastFrame`.
|
|
168
|
+
|
|
169
|
+
| | Seedance 2.0 | Seedance 2.5 |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `referenceImages` | up to 9 | up to 30 |
|
|
172
|
+
| `referenceVideos` (`https://` / `asset://`) | up to 3, ≤15s total | up to 10, ≤30s total |
|
|
173
|
+
| `referenceAudios` (wav / mp3) | up to 3, ≤15s total, needs an image or video | up to 10, ≤30s total |
|
|
174
|
+
|
|
175
|
+
Images under 30 MB each and the whole request under 64 MB — pass large media
|
|
176
|
+
as `https://` URLs, not `data:` URLs. Seedance clips have generated sound by
|
|
177
|
+
default; `generateAudio: false` makes them silent.
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
const ad = await aiflow.generateVideo({
|
|
181
|
+
model: 'seedance',
|
|
182
|
+
prompt: 'The girl from [Image 1] unboxes the sneaker from [Image 2], dancing to [Audio 1]',
|
|
183
|
+
referenceImages: [characterUrl, productUrl],
|
|
184
|
+
referenceAudios: [musicUrl],
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
145
188
|
The default model is **Gemini Omni**: one clip of ~10s, **with sound**, 16:9 or
|
|
146
189
|
9:16 only, and no length parameter. For a longer or extendable video use
|
|
147
190
|
`generateLongVideo` / `createVideoSession` below — same model, so a single clip
|
|
@@ -297,24 +340,54 @@ job's `videoUrl` is the timeline and `segmentUrl` the new tail.
|
|
|
297
340
|
Every turn is billed separately (Omni prices by output token), and
|
|
298
341
|
`session.usage.creditsUsed` is the running total for the whole session.
|
|
299
342
|
|
|
300
|
-
### `aiflow.generateAudio({ prompt, model?, images?, signal?, timeout? })`
|
|
343
|
+
### `aiflow.generateAudio({ prompt, model?, images?, format?, negativePrompt?, seed?, signal?, timeout? })`
|
|
301
344
|
|
|
302
345
|
Generate music from a text prompt with Google **Lyria 3.5**. Returns
|
|
303
|
-
`{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`;
|
|
304
|
-
hosted mp3 on the CDN. `prompt` is a musical description (mood,
|
|
305
|
-
tempo/BPM, instrumentation), and length or exclusions go in it too
|
|
306
|
-
seconds, seamless loop", "no vocals").
|
|
307
|
-
|
|
308
|
-
`
|
|
309
|
-
|
|
346
|
+
`{ audioUrl, model, durationSeconds, lyrics, usage: { creditsUsed } }`;
|
|
347
|
+
`audioUrl` is a hosted mp3 on the CDN. `prompt` is a musical description (mood,
|
|
348
|
+
genre, tempo/BPM, instrumentation), and length or exclusions go in it too
|
|
349
|
+
("about 30 seconds, seamless loop", "no vocals"). Lyria treats length as a
|
|
350
|
+
guide, so read `durationSeconds` for the real one. Custom lyrics go in the
|
|
351
|
+
prompt with section tags (`[Verse]`, `[Chorus]`, `[Bridge]`).
|
|
352
|
+
|
|
353
|
+
- `images` — up to 10 https:// or data: URLs for the music to be inspired by,
|
|
354
|
+
on the models in `config.audioImageInputModels`.
|
|
355
|
+
- `format` — `'mp3'` (default) or `'wav'` (44.1 kHz stereo, about 10 MB per
|
|
356
|
+
minute — offer it as a download).
|
|
357
|
+
- `negativePrompt` — what the music must not contain; appended to the prompt
|
|
358
|
+
as an exclusion, since Lyria 3.5 has no separate field for it.
|
|
359
|
+
- `seed` — passed to Lyria; the same seed is not guaranteed to give the same
|
|
360
|
+
song.
|
|
361
|
+
- `lyrics` in the result — the sung words as plain text, a blank line between
|
|
362
|
+
sections; `null` for an instrumental.
|
|
310
363
|
|
|
311
|
-
|
|
364
|
+
```js
|
|
365
|
+
const song = await aiflow.generateAudio({
|
|
366
|
+
prompt: 'Bright acoustic pop, 100 BPM, female vocal. [Verse] Morning light on the harbour ... [Chorus] ...',
|
|
367
|
+
images: [coverPhotoUrl],
|
|
368
|
+
format: 'wav',
|
|
369
|
+
});
|
|
370
|
+
song.audioUrl; // .wav on the CDN
|
|
371
|
+
song.lyrics; // "Morning light on the harbour…\n\n…"
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### `aiflow.generateSfx({ prompt, model?, durationSeconds?, promptInfluence?, loop?, signal?, timeout? })`
|
|
312
375
|
|
|
313
376
|
Generate a one-shot sound effect from a text prompt (**ElevenLabs**). Returns
|
|
314
377
|
`{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `durationSeconds`
|
|
315
|
-
is clamped to `0.5–30`; omit it to let the model auto-decide.
|
|
378
|
+
is clamped to `0.5–30`; omit it to let the model auto-decide.
|
|
379
|
+
`promptInfluence` (0–1) sets how literally the sound follows the prompt —
|
|
380
|
+
higher is more literal, omitted uses the ElevenLabs default (~0.3). `loop: true`
|
|
381
|
+
makes a clip that loops seamlessly (rain, engine hum, room tone). Cache/replay
|
|
316
382
|
repeated UI sounds client-side rather than calling per interaction.
|
|
317
383
|
|
|
384
|
+
### `aiflow.vision({ imageUrl, prompt?, model?, maxTokens?, signal? })`
|
|
385
|
+
|
|
386
|
+
Read text from an image, or ask a question about it. Returns
|
|
387
|
+
`{ text, model, usage }`. It is a `chat()` call with the image attached and web
|
|
388
|
+
search off, on the module's chat model unless `model` is given; `prompt`
|
|
389
|
+
defaults to extracting all visible text.
|
|
390
|
+
|
|
318
391
|
### `aiflow.embed({ input, model?, signal? })`
|
|
319
392
|
|
|
320
393
|
Returns `{ data: [{ embedding: number[], index }], usage: { creditsUsed } }`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvibex/aiflow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
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
|
@@ -36,9 +36,12 @@ export interface ChatMessage {
|
|
|
36
36
|
role: ChatRole;
|
|
37
37
|
/** Plain string OR multimodal array of content blocks. */
|
|
38
38
|
content: string | ContentBlock[];
|
|
39
|
-
name?: string;
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated The gateway runs no caller-defined tools; passing `tools` throws.
|
|
43
|
+
* Web search is built in — see {@link ChatRequest.webSearch}.
|
|
44
|
+
*/
|
|
42
45
|
export interface ChatTool {
|
|
43
46
|
name: string;
|
|
44
47
|
description?: string;
|
|
@@ -51,6 +54,12 @@ export interface ChatRequest {
|
|
|
51
54
|
system?: string;
|
|
52
55
|
maxTokens?: number;
|
|
53
56
|
temperature?: number;
|
|
57
|
+
/**
|
|
58
|
+
* `false` answers this request without the built-in web search. Omit to use
|
|
59
|
+
* the module's setting (`config.webSearch`, on by default).
|
|
60
|
+
*/
|
|
61
|
+
webSearch?: boolean;
|
|
62
|
+
/** @deprecated Not supported by the gateway — passing it throws. */
|
|
54
63
|
tools?: ChatTool[];
|
|
55
64
|
signal?: AbortSignal;
|
|
56
65
|
}
|
|
@@ -91,6 +100,12 @@ export interface ImageRequest {
|
|
|
91
100
|
prompt: string;
|
|
92
101
|
model?: string;
|
|
93
102
|
size?: '512x512' | '1024x1024' | '1024x1792' | string;
|
|
103
|
+
/**
|
|
104
|
+
* Output aspect ratio for the Gemini image models — wins over the ratio
|
|
105
|
+
* `size` implies and over an input image's ratio. GPT image models ignore
|
|
106
|
+
* it (use `size`).
|
|
107
|
+
*/
|
|
108
|
+
aspectRatio?: '1:1' | '2:3' | '3:2' | '3:4' | '4:3' | '9:16' | '16:9' | '21:9';
|
|
94
109
|
n?: number;
|
|
95
110
|
image?: string;
|
|
96
111
|
images?: string[];
|
|
@@ -205,15 +220,51 @@ export interface VideoRequest {
|
|
|
205
220
|
*/
|
|
206
221
|
resolution?: '480p' | '720p' | '1080p' | string;
|
|
207
222
|
/**
|
|
208
|
-
* Clip length in seconds — Seedance only: an integer 4–15
|
|
209
|
-
* range, default 5). Gemini Omni takes no
|
|
210
|
-
*
|
|
223
|
+
* Clip length in seconds — Seedance only: an integer 4–15 on Seedance 2.0,
|
|
224
|
+
* 4–30 on 2.5 (clamped to that range, default 5). Gemini Omni takes no
|
|
225
|
+
* length and returns a ~10s clip (longer:
|
|
226
|
+
* {@link AIFlowClient.generateLongVideo}); Veo uses a fixed length.
|
|
211
227
|
*/
|
|
212
228
|
duration?: number;
|
|
213
229
|
/** Burn the provider watermark into the output (Seedance only). */
|
|
214
230
|
watermark?: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Still image to animate (image-to-video) — the clip's FIRST frame. An
|
|
233
|
+
* `https://` URL or a `data:` URL.
|
|
234
|
+
*/
|
|
215
235
|
image?: string;
|
|
236
|
+
/**
|
|
237
|
+
* Image the clip must END on (first + last frame). Same formats as `image`
|
|
238
|
+
* and requires it. Seedance only — Gemini Omni and Veo ignore it, so the
|
|
239
|
+
* module must be pinned to Seedance. Needs `@devvibex/aiflow` ≥ 1.15.0.
|
|
240
|
+
*/
|
|
241
|
+
lastFrame?: string;
|
|
216
242
|
video?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Seedance only — reference images that keep a character, product or style
|
|
245
|
+
* (omni reference mode). Up to 9 on Seedance 2.0, 30 on 2.5. Cited in the
|
|
246
|
+
* prompt as [Image 1], [Image 2], … in this order. `https://`, `data:` or
|
|
247
|
+
* `asset://`. Cannot be combined with `image` / `lastFrame`.
|
|
248
|
+
*/
|
|
249
|
+
referenceImages?: string[];
|
|
250
|
+
/**
|
|
251
|
+
* Seedance only — reference videos for motion/camera, or the clip to edit
|
|
252
|
+
* 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 [Video 1], ….
|
|
254
|
+
*/
|
|
255
|
+
referenceVideos?: string[];
|
|
256
|
+
/**
|
|
257
|
+
* Seedance only — reference audio (voice, music, rhythm), wav or mp3. Up to
|
|
258
|
+
* 3 on Seedance 2.0 (2–15s each, ≤15s total), and there it needs at least
|
|
259
|
+
* one reference image or video; 10 on 2.5 (≤30s total), audio alone allowed.
|
|
260
|
+
* Cited as [Audio 1], ….
|
|
261
|
+
*/
|
|
262
|
+
referenceAudios?: string[];
|
|
263
|
+
/**
|
|
264
|
+
* Seedance only — `false` for a silent clip. Omitted, Seedance generates
|
|
265
|
+
* synchronized sound (voice, effects, music).
|
|
266
|
+
*/
|
|
267
|
+
generateAudio?: boolean;
|
|
217
268
|
signal?: AbortSignal;
|
|
218
269
|
/**
|
|
219
270
|
* Overall wait budget across all status polls (ms). Defaults to 600000
|
|
@@ -502,9 +553,15 @@ export interface AudioRequest {
|
|
|
502
553
|
* `config.audioImageInputModels`; the gateway answers 400 otherwise.
|
|
503
554
|
*/
|
|
504
555
|
images?: string[];
|
|
505
|
-
/**
|
|
556
|
+
/**
|
|
557
|
+
* `'mp3'` (default) or `'wav'` — 44.1 kHz stereo, about 10 MB per minute,
|
|
558
|
+
* so offer WAV as a download rather than for in-page playback. Needs
|
|
559
|
+
* `@devvibex/aiflow` ≥ 1.15.0.
|
|
560
|
+
*/
|
|
561
|
+
format?: 'mp3' | 'wav';
|
|
562
|
+
/** What the music must not contain ("vocals, drums"); added to the prompt as an exclusion. */
|
|
506
563
|
negativePrompt?: string;
|
|
507
|
-
/**
|
|
564
|
+
/** Passed to Lyria as a seed. Google does not promise the same song for the same seed. */
|
|
508
565
|
seed?: number;
|
|
509
566
|
signal?: AbortSignal;
|
|
510
567
|
/** Per-call timeout (ms). Defaults to 180000 (3 min) — music gen is slow. */
|
|
@@ -518,6 +575,11 @@ export interface AudioResponse {
|
|
|
518
575
|
model: string;
|
|
519
576
|
/** Output duration in seconds, or null if undetermined. */
|
|
520
577
|
durationSeconds: number | null;
|
|
578
|
+
/**
|
|
579
|
+
* The sung lyrics as plain text, a blank line between sections. Null for an
|
|
580
|
+
* instrumental, and absent from gateways older than this field.
|
|
581
|
+
*/
|
|
582
|
+
lyrics?: string | null;
|
|
521
583
|
prompt?: string;
|
|
522
584
|
usage: { creditsUsed: number };
|
|
523
585
|
}
|
|
@@ -532,11 +594,12 @@ export interface SfxRequest {
|
|
|
532
594
|
durationSeconds?: number;
|
|
533
595
|
/**
|
|
534
596
|
* How strictly the output follows the prompt (0–1). Higher = more literal
|
|
535
|
-
* and less variable; lower = more creative/ambient. Omit to use the
|
|
536
|
-
*
|
|
537
|
-
* drifting into a musical/ambient soundscape.
|
|
597
|
+
* and less variable; lower = more creative/ambient. Omit to use the
|
|
598
|
+
* ElevenLabs default (~0.3).
|
|
538
599
|
*/
|
|
539
600
|
promptInfluence?: number;
|
|
601
|
+
/** Make the clip loop seamlessly (ambience, engine hum, rain). */
|
|
602
|
+
loop?: boolean;
|
|
540
603
|
signal?: AbortSignal;
|
|
541
604
|
/** Per-call timeout (ms). Defaults to 120000 (2 min). */
|
|
542
605
|
timeout?: number;
|
package/src/index.js
CHANGED
|
@@ -291,7 +291,9 @@ export class AIFlowClient {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
/**
|
|
294
|
-
* Non-streaming chat completion.
|
|
294
|
+
* Non-streaming chat completion. `webSearch: false` answers this one
|
|
295
|
+
* request without the built-in web search; omitted, the module's setting
|
|
296
|
+
* applies (on by default).
|
|
295
297
|
* @returns {Promise<{id:string, model:string, content:string, usage:{inputTokens:number,outputTokens:number,creditsUsed:number}}>}
|
|
296
298
|
*/
|
|
297
299
|
async chat({
|
|
@@ -300,12 +302,14 @@ export class AIFlowClient {
|
|
|
300
302
|
system,
|
|
301
303
|
maxTokens,
|
|
302
304
|
temperature,
|
|
305
|
+
webSearch,
|
|
303
306
|
tools,
|
|
304
307
|
signal,
|
|
305
308
|
} = {}) {
|
|
306
309
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
307
310
|
throw new AIFlowError('messages must be a non-empty array');
|
|
308
311
|
}
|
|
312
|
+
assertNoTools(tools);
|
|
309
313
|
const resolvedModel = model || (await this._resolveDefaultModel('chat'));
|
|
310
314
|
const resolvedSystem = await this._resolveSystemPrompt(system);
|
|
311
315
|
const res = await this._request(
|
|
@@ -316,7 +320,7 @@ export class AIFlowClient {
|
|
|
316
320
|
messages,
|
|
317
321
|
maxTokens,
|
|
318
322
|
temperature,
|
|
319
|
-
|
|
323
|
+
webSearch,
|
|
320
324
|
},
|
|
321
325
|
{ signal },
|
|
322
326
|
);
|
|
@@ -333,12 +337,14 @@ export class AIFlowClient {
|
|
|
333
337
|
system,
|
|
334
338
|
maxTokens,
|
|
335
339
|
temperature,
|
|
340
|
+
webSearch,
|
|
336
341
|
tools,
|
|
337
342
|
signal,
|
|
338
343
|
} = {}) {
|
|
339
344
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
340
345
|
throw new AIFlowError('messages must be a non-empty array');
|
|
341
346
|
}
|
|
347
|
+
assertNoTools(tools);
|
|
342
348
|
const resolvedModel = model || (await this._resolveDefaultModel('chat'));
|
|
343
349
|
const resolvedSystem = await this._resolveSystemPrompt(system);
|
|
344
350
|
const res = await this._request(
|
|
@@ -349,7 +355,7 @@ export class AIFlowClient {
|
|
|
349
355
|
messages,
|
|
350
356
|
maxTokens,
|
|
351
357
|
temperature,
|
|
352
|
-
|
|
358
|
+
webSearch,
|
|
353
359
|
stream: true,
|
|
354
360
|
},
|
|
355
361
|
{ signal, stream: true },
|
|
@@ -398,6 +404,7 @@ export class AIFlowClient {
|
|
|
398
404
|
prompt,
|
|
399
405
|
model,
|
|
400
406
|
size = '1024x1024',
|
|
407
|
+
aspectRatio,
|
|
401
408
|
n = 1,
|
|
402
409
|
image,
|
|
403
410
|
images,
|
|
@@ -422,6 +429,8 @@ export class AIFlowClient {
|
|
|
422
429
|
model: resolvedModel,
|
|
423
430
|
prompt,
|
|
424
431
|
size,
|
|
432
|
+
// Gemini image models only; wins over the ratio `size` implies.
|
|
433
|
+
aspectRatio,
|
|
425
434
|
n,
|
|
426
435
|
image,
|
|
427
436
|
images,
|
|
@@ -529,13 +538,30 @@ export class AIFlowClient {
|
|
|
529
538
|
duration,
|
|
530
539
|
watermark,
|
|
531
540
|
image,
|
|
541
|
+
lastFrame,
|
|
532
542
|
video,
|
|
543
|
+
referenceImages,
|
|
544
|
+
referenceVideos,
|
|
545
|
+
referenceAudios,
|
|
546
|
+
generateAudio,
|
|
533
547
|
signal,
|
|
534
548
|
timeout,
|
|
535
549
|
} = {}) {
|
|
536
550
|
if (!prompt || typeof prompt !== 'string') {
|
|
537
551
|
throw new AIFlowError('prompt is required');
|
|
538
552
|
}
|
|
553
|
+
if (lastFrame && !image) {
|
|
554
|
+
throw new AIFlowError('lastFrame requires image (the first frame)');
|
|
555
|
+
}
|
|
556
|
+
const hasReferences =
|
|
557
|
+
!!referenceImages?.length ||
|
|
558
|
+
!!referenceVideos?.length ||
|
|
559
|
+
!!referenceAudios?.length;
|
|
560
|
+
if (hasReferences && (image || lastFrame)) {
|
|
561
|
+
throw new AIFlowError(
|
|
562
|
+
'referenceImages / referenceVideos / referenceAudios cannot be combined with image / lastFrame',
|
|
563
|
+
);
|
|
564
|
+
}
|
|
539
565
|
const resolvedModel =
|
|
540
566
|
model || (await this._resolveDefaultModel('video'));
|
|
541
567
|
const res = await this._request(
|
|
@@ -548,10 +574,15 @@ export class AIFlowClient {
|
|
|
548
574
|
duration,
|
|
549
575
|
watermark,
|
|
550
576
|
image,
|
|
577
|
+
lastFrame,
|
|
551
578
|
video,
|
|
579
|
+
referenceImages,
|
|
580
|
+
referenceVideos,
|
|
581
|
+
referenceAudios,
|
|
582
|
+
generateAudio,
|
|
552
583
|
},
|
|
553
584
|
// Submit returns fast; the default client timeout is plenty even
|
|
554
|
-
// when an image-to-video request uploads
|
|
585
|
+
// when an image-to-video request uploads base64 frames.
|
|
555
586
|
{ signal, timeout: timeout ?? DEFAULT_TIMEOUT_MS },
|
|
556
587
|
);
|
|
557
588
|
return await res.json();
|
|
@@ -1006,13 +1037,16 @@ export class AIFlowClient {
|
|
|
1006
1037
|
/**
|
|
1007
1038
|
* Generate music / background audio from a text prompt (Lyria 3.5),
|
|
1008
1039
|
* optionally inspired by up to 10 reference `images` (https:// or data:
|
|
1009
|
-
* URLs) on the models in `config.audioImageInputModels`.
|
|
1010
|
-
*
|
|
1040
|
+
* URLs) on the models in `config.audioImageInputModels`. `format: 'wav'`
|
|
1041
|
+
* returns a WAV file instead of MP3; `lyrics` in the result holds the
|
|
1042
|
+
* sung words (null for an instrumental).
|
|
1043
|
+
* @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, lyrics:string|null, prompt?:string, usage:{creditsUsed:number}}>}
|
|
1011
1044
|
*/
|
|
1012
1045
|
async generateAudio({
|
|
1013
1046
|
prompt,
|
|
1014
1047
|
model,
|
|
1015
1048
|
images,
|
|
1049
|
+
format,
|
|
1016
1050
|
negativePrompt,
|
|
1017
1051
|
seed,
|
|
1018
1052
|
signal,
|
|
@@ -1032,6 +1066,7 @@ export class AIFlowClient {
|
|
|
1032
1066
|
model: resolvedModel,
|
|
1033
1067
|
prompt,
|
|
1034
1068
|
images: images?.length ? images : undefined,
|
|
1069
|
+
format,
|
|
1035
1070
|
negativePrompt,
|
|
1036
1071
|
seed,
|
|
1037
1072
|
},
|
|
@@ -1051,6 +1086,7 @@ export class AIFlowClient {
|
|
|
1051
1086
|
model,
|
|
1052
1087
|
durationSeconds,
|
|
1053
1088
|
promptInfluence,
|
|
1089
|
+
loop,
|
|
1054
1090
|
signal,
|
|
1055
1091
|
timeout,
|
|
1056
1092
|
} = {}) {
|
|
@@ -1065,6 +1101,7 @@ export class AIFlowClient {
|
|
|
1065
1101
|
prompt,
|
|
1066
1102
|
durationSeconds,
|
|
1067
1103
|
promptInfluence,
|
|
1104
|
+
loop,
|
|
1068
1105
|
},
|
|
1069
1106
|
{ signal, timeout: timeout ?? 120_000 },
|
|
1070
1107
|
);
|
|
@@ -1072,8 +1109,10 @@ export class AIFlowClient {
|
|
|
1072
1109
|
}
|
|
1073
1110
|
|
|
1074
1111
|
/**
|
|
1075
|
-
* Extract text (or answer a question) from
|
|
1076
|
-
*
|
|
1112
|
+
* Extract text (or answer a question) from one image. A `chat()` call with
|
|
1113
|
+
* the image as an `image_url` block and web search off, on the module's
|
|
1114
|
+
* chat model unless `model` is given — the gateway has no separate vision
|
|
1115
|
+
* route.
|
|
1077
1116
|
*
|
|
1078
1117
|
* @param {object} options
|
|
1079
1118
|
* @param {string} options.imageUrl Publicly accessible image URL (or base64 data-URI).
|
|
@@ -1088,13 +1127,27 @@ export class AIFlowClient {
|
|
|
1088
1127
|
if (!imageUrl || typeof imageUrl !== 'string') {
|
|
1089
1128
|
throw new AIFlowError('imageUrl is required');
|
|
1090
1129
|
}
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1130
|
+
const res = await this.chat({
|
|
1131
|
+
model,
|
|
1132
|
+
maxTokens,
|
|
1133
|
+
webSearch: false,
|
|
1134
|
+
messages: [
|
|
1135
|
+
{
|
|
1136
|
+
role: 'user',
|
|
1137
|
+
content: [
|
|
1138
|
+
{
|
|
1139
|
+
type: 'text',
|
|
1140
|
+
text:
|
|
1141
|
+
prompt ||
|
|
1142
|
+
'Extract all text visible in this image.',
|
|
1143
|
+
},
|
|
1144
|
+
{ type: 'image_url', image_url: { url: imageUrl } },
|
|
1145
|
+
],
|
|
1146
|
+
},
|
|
1147
|
+
],
|
|
1148
|
+
signal,
|
|
1149
|
+
});
|
|
1150
|
+
return { text: res.content, model: res.model, usage: res.usage };
|
|
1098
1151
|
}
|
|
1099
1152
|
|
|
1100
1153
|
/**
|
|
@@ -1684,6 +1737,19 @@ function parseSseEvent(rawEvent) {
|
|
|
1684
1737
|
}
|
|
1685
1738
|
}
|
|
1686
1739
|
|
|
1740
|
+
/**
|
|
1741
|
+
* The gateway runs no caller-defined tools (web search is built in — see
|
|
1742
|
+
* `webSearch`) and rejects a `tools` field with a 422, so fail here with a
|
|
1743
|
+
* message that says why.
|
|
1744
|
+
*/
|
|
1745
|
+
function assertNoTools(tools) {
|
|
1746
|
+
if (tools !== undefined && tools !== null) {
|
|
1747
|
+
throw new AIFlowError(
|
|
1748
|
+
'tools is not supported by the AIFlow gateway — web search is built in; use webSearch to turn it on or off',
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1687
1753
|
function anySignal(a, b) {
|
|
1688
1754
|
if (!a) return b;
|
|
1689
1755
|
if (!b) return a;
|