@devvibex/aiflow 1.14.0 → 1.15.1
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 +97 -14
- package/package.json +1 -1
- package/src/index.d.ts +92 -17
- package/src/index.js +85 -14
package/README.md
CHANGED
|
@@ -119,29 +119,76 @@ 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** 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.
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
const clip = await aiflow.generateVideo({
|
|
161
|
+
model: 'seedance',
|
|
162
|
+
prompt: 'The flower slowly opens as morning light sweeps across it',
|
|
163
|
+
image: firstFrameUrl, // https:// or data: URL
|
|
164
|
+
lastFrame: lastFrameUrl,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Seedance reference mode.** Instead of a first frame, Seedance can take
|
|
169
|
+
reference assets and keep them consistent in a new shot — cite them in the
|
|
170
|
+
prompt as `[Image 1]`, `[Video 1]`, `[Audio 1]` in the order you pass them.
|
|
171
|
+
It is a separate mode: it cannot be combined with `image` / `lastFrame`.
|
|
172
|
+
|
|
173
|
+
| | Seedance 2.0 | Seedance 2.5 |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `referenceImages` | up to 9 | up to 30 |
|
|
176
|
+
| `referenceVideos` (`https://` / `asset://`) | up to 3, ≤15s total | up to 10, ≤30s total |
|
|
177
|
+
| `referenceAudios` (wav / mp3) | up to 3, ≤15s total, needs an image or video | up to 10, ≤30s total |
|
|
178
|
+
|
|
179
|
+
Images under 30 MB each and the whole request under 64 MB — pass large media
|
|
180
|
+
as `https://` URLs, not `data:` URLs. Seedance clips have generated sound by
|
|
181
|
+
default; `generateAudio: false` makes them silent.
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
const ad = await aiflow.generateVideo({
|
|
185
|
+
model: 'seedance',
|
|
186
|
+
prompt: 'The girl from [Image 1] unboxes the sneaker from [Image 2], dancing to [Audio 1]',
|
|
187
|
+
referenceImages: [characterUrl, productUrl],
|
|
188
|
+
referenceAudios: [musicUrl],
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
145
192
|
The default model is **Gemini Omni**: one clip of ~10s, **with sound**, 16:9 or
|
|
146
193
|
9:16 only, and no length parameter. For a longer or extendable video use
|
|
147
194
|
`generateLongVideo` / `createVideoSession` below — same model, so a single clip
|
|
@@ -297,24 +344,60 @@ job's `videoUrl` is the timeline and `segmentUrl` the new tail.
|
|
|
297
344
|
Every turn is billed separately (Omni prices by output token), and
|
|
298
345
|
`session.usage.creditsUsed` is the running total for the whole session.
|
|
299
346
|
|
|
300
|
-
### `aiflow.generateAudio({ prompt, model?, images?, signal?, timeout? })`
|
|
347
|
+
### `aiflow.generateAudio({ prompt, model?, images?, durationSeconds?, format?, negativePrompt?, seed?, signal?, timeout? })`
|
|
301
348
|
|
|
302
349
|
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)
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
350
|
+
`{ audioUrl, model, durationSeconds, lyrics, usage: { creditsUsed } }`;
|
|
351
|
+
`audioUrl` is a hosted mp3 on the CDN. `prompt` is a musical description (mood,
|
|
352
|
+
genre, tempo/BPM, instrumentation) and exclusions ("no vocals"). Custom lyrics
|
|
353
|
+
go in the prompt with section tags (`[Verse]`, `[Chorus]`, `[Bridge]`).
|
|
354
|
+
|
|
355
|
+
- `durationSeconds` — song length, 5–180. Lyria 3.5 has no length setting and
|
|
356
|
+
runs long (a 30s request measured 44–63s), so the gateway lays the song out
|
|
357
|
+
to this length and cuts it to exactly this length with a 1–3s fade-out.
|
|
358
|
+
Without it the song is as long as the model makes it, usually one to three
|
|
359
|
+
minutes. A length written only in `prompt` is a loose suggestion. Needs
|
|
360
|
+
≥ 1.15.1: 1.15.0 and older drop `durationSeconds` from music requests.
|
|
361
|
+
- `images` — up to 10 https:// or data: URLs for the music to be inspired by,
|
|
362
|
+
on the models in `config.audioImageInputModels`.
|
|
363
|
+
- `format` — `'mp3'` (default) or `'wav'` (48 kHz stereo, about 11.5 MB per
|
|
364
|
+
minute — offer it as a download).
|
|
365
|
+
- `negativePrompt` — what the music must not contain; appended to the prompt
|
|
366
|
+
as an exclusion, since Lyria 3.5 has no separate field for it.
|
|
367
|
+
- `seed` — passed to Lyria; the same seed is not guaranteed to give the same
|
|
368
|
+
song.
|
|
369
|
+
- `lyrics` in the result — the sung words as plain text, a blank line between
|
|
370
|
+
sections; `null` for an instrumental.
|
|
310
371
|
|
|
311
|
-
|
|
372
|
+
```js
|
|
373
|
+
const song = await aiflow.generateAudio({
|
|
374
|
+
prompt: 'Bright acoustic pop, 100 BPM, female vocal. [Verse] Morning light on the harbour ... [Chorus] ...',
|
|
375
|
+
images: [coverPhotoUrl],
|
|
376
|
+
durationSeconds: 30,
|
|
377
|
+
format: 'wav',
|
|
378
|
+
});
|
|
379
|
+
song.audioUrl; // .wav on the CDN
|
|
380
|
+
song.durationSeconds; // ~30
|
|
381
|
+
song.lyrics; // "Morning light on the harbour…\n\n…"
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### `aiflow.generateSfx({ prompt, model?, durationSeconds?, promptInfluence?, loop?, signal?, timeout? })`
|
|
312
385
|
|
|
313
386
|
Generate a one-shot sound effect from a text prompt (**ElevenLabs**). Returns
|
|
314
387
|
`{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `durationSeconds`
|
|
315
|
-
is clamped to `0.5–30`; omit it to let the model auto-decide.
|
|
388
|
+
is clamped to `0.5–30`; omit it to let the model auto-decide.
|
|
389
|
+
`promptInfluence` (0–1) sets how literally the sound follows the prompt —
|
|
390
|
+
higher is more literal, omitted uses the ElevenLabs default (~0.3). `loop: true`
|
|
391
|
+
makes a clip that loops seamlessly (rain, engine hum, room tone). Cache/replay
|
|
316
392
|
repeated UI sounds client-side rather than calling per interaction.
|
|
317
393
|
|
|
394
|
+
### `aiflow.vision({ imageUrl, prompt?, model?, maxTokens?, signal? })`
|
|
395
|
+
|
|
396
|
+
Read text from an image, or ask a question about it. Returns
|
|
397
|
+
`{ text, model, usage }`. It is a `chat()` call with the image attached and web
|
|
398
|
+
search off, on the module's chat model unless `model` is given; `prompt`
|
|
399
|
+
defaults to extracting all visible text.
|
|
400
|
+
|
|
318
401
|
### `aiflow.embed({ input, model?, signal? })`
|
|
319
402
|
|
|
320
403
|
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.1",
|
|
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[];
|
|
@@ -186,34 +201,73 @@ export interface ImageBatchResponse {
|
|
|
186
201
|
export interface VideoRequest {
|
|
187
202
|
prompt: string;
|
|
188
203
|
/**
|
|
189
|
-
* Video model: `'gemini-omni'` | `'veo'` | `'seedance'`. Defaults to the
|
|
204
|
+
* Video model: `'gemini-omni'` | `'veo'` | `'seedance'` | `'kling'`. Defaults to the
|
|
190
205
|
* app's configured model, which is Gemini Omni unless the module was pinned
|
|
191
206
|
* to another one. Omni clips always have sound and are the only ones that
|
|
192
207
|
* can be extended (see {@link AIFlowClient.createVideoSession}).
|
|
193
208
|
*/
|
|
194
209
|
model?: string;
|
|
195
210
|
/**
|
|
196
|
-
* Output aspect ratio. Gemini Omni supports 16:9 / 9:16 only; Veo
|
|
197
|
-
*
|
|
198
|
-
* 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.
|
|
199
215
|
*/
|
|
200
216
|
aspectRatio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '21:9' | string;
|
|
201
217
|
/**
|
|
202
|
-
* Output resolution: '720p' (default) | '1080p' on Gemini Omni
|
|
203
|
-
*
|
|
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
|
|
204
220
|
* faster and, on Omni, costs less. Ignored by Veo.
|
|
205
221
|
*/
|
|
206
222
|
resolution?: '480p' | '720p' | '1080p' | string;
|
|
207
223
|
/**
|
|
208
|
-
* Clip length in seconds — Seedance
|
|
209
|
-
* range, default 5). Gemini Omni takes no
|
|
210
|
-
*
|
|
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
|
|
226
|
+
* length and returns a ~10s clip (longer:
|
|
227
|
+
* {@link AIFlowClient.generateLongVideo}); Veo uses a fixed length.
|
|
211
228
|
*/
|
|
212
229
|
duration?: number;
|
|
213
230
|
/** Burn the provider watermark into the output (Seedance only). */
|
|
214
231
|
watermark?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Still image to animate (image-to-video) — the clip's FIRST frame. An
|
|
234
|
+
* `https://` URL or a `data:` URL.
|
|
235
|
+
*/
|
|
215
236
|
image?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Image the clip must END on (first + last frame). Same formats as `image`
|
|
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.
|
|
242
|
+
*/
|
|
243
|
+
lastFrame?: string;
|
|
216
244
|
video?: string;
|
|
245
|
+
/**
|
|
246
|
+
* Seedance only — reference images that keep a character, product or style
|
|
247
|
+
* (omni reference mode). Up to 9 on Seedance 2.0, 30 on 2.5. Cited in the
|
|
248
|
+
* prompt as [Image 1], [Image 2], … in this order. `https://`, `data:` or
|
|
249
|
+
* `asset://`. Cannot be combined with `image` / `lastFrame`.
|
|
250
|
+
*/
|
|
251
|
+
referenceImages?: string[];
|
|
252
|
+
/**
|
|
253
|
+
* Seedance only — reference videos for motion/camera, or the clip to edit
|
|
254
|
+
* or extend. Up to 3 on Seedance 2.0 (2–15s each, ≤15s total), 10 on 2.5
|
|
255
|
+
* (≤30s total). `https://` or `asset://` only. Cited as [Video 1], ….
|
|
256
|
+
*/
|
|
257
|
+
referenceVideos?: string[];
|
|
258
|
+
/**
|
|
259
|
+
* Seedance only — reference audio (voice, music, rhythm), wav or mp3. Up to
|
|
260
|
+
* 3 on Seedance 2.0 (2–15s each, ≤15s total), and there it needs at least
|
|
261
|
+
* one reference image or video; 10 on 2.5 (≤30s total), audio alone allowed.
|
|
262
|
+
* Cited as [Audio 1], ….
|
|
263
|
+
*/
|
|
264
|
+
referenceAudios?: string[];
|
|
265
|
+
/**
|
|
266
|
+
* Seedance and Kling — whether the clip gets synchronized sound (voice,
|
|
267
|
+
* effects, music). Omitted: on for Seedance, off for Kling (where sound
|
|
268
|
+
* costs more per second).
|
|
269
|
+
*/
|
|
270
|
+
generateAudio?: boolean;
|
|
217
271
|
signal?: AbortSignal;
|
|
218
272
|
/**
|
|
219
273
|
* Overall wait budget across all status polls (ms). Defaults to 600000
|
|
@@ -491,8 +545,9 @@ export interface VideoExtendSubmitResponse extends VideoJobSubmitResponse {
|
|
|
491
545
|
|
|
492
546
|
export interface AudioRequest {
|
|
493
547
|
/**
|
|
494
|
-
* Musical description — mood, genre, tempo (BPM), instrumentation, texture
|
|
495
|
-
*
|
|
548
|
+
* Musical description — mood, genre, tempo (BPM), instrumentation, texture
|
|
549
|
+
* and exclusions ("no vocals"). Put a set length in `durationSeconds`, not
|
|
550
|
+
* here: Lyria treats a length in the prompt as a loose suggestion.
|
|
496
551
|
*/
|
|
497
552
|
prompt: string;
|
|
498
553
|
model?: string;
|
|
@@ -502,9 +557,23 @@ export interface AudioRequest {
|
|
|
502
557
|
* `config.audioImageInputModels`; the gateway answers 400 otherwise.
|
|
503
558
|
*/
|
|
504
559
|
images?: string[];
|
|
505
|
-
/**
|
|
560
|
+
/**
|
|
561
|
+
* Song length in seconds, 5–180. Lyria 3.5 has no length setting and runs
|
|
562
|
+
* long, so the gateway lays the song out to this length and cuts it to
|
|
563
|
+
* exactly this length with a short fade-out; a shorter song is returned as
|
|
564
|
+
* is. Read the real length from `durationSeconds` in the response. Needs
|
|
565
|
+
* `@devvibex/aiflow` ≥ 1.15.1 — 1.15.0 and older drop it.
|
|
566
|
+
*/
|
|
567
|
+
durationSeconds?: number;
|
|
568
|
+
/**
|
|
569
|
+
* `'mp3'` (default) or `'wav'` — 48 kHz stereo, about 11.5 MB per minute,
|
|
570
|
+
* so offer WAV as a download rather than for in-page playback. Needs
|
|
571
|
+
* `@devvibex/aiflow` ≥ 1.15.0.
|
|
572
|
+
*/
|
|
573
|
+
format?: 'mp3' | 'wav';
|
|
574
|
+
/** What the music must not contain ("vocals, drums"); added to the prompt as an exclusion. */
|
|
506
575
|
negativePrompt?: string;
|
|
507
|
-
/**
|
|
576
|
+
/** Passed to Lyria as a seed. Google does not promise the same song for the same seed. */
|
|
508
577
|
seed?: number;
|
|
509
578
|
signal?: AbortSignal;
|
|
510
579
|
/** Per-call timeout (ms). Defaults to 180000 (3 min) — music gen is slow. */
|
|
@@ -518,6 +587,11 @@ export interface AudioResponse {
|
|
|
518
587
|
model: string;
|
|
519
588
|
/** Output duration in seconds, or null if undetermined. */
|
|
520
589
|
durationSeconds: number | null;
|
|
590
|
+
/**
|
|
591
|
+
* The sung lyrics as plain text, a blank line between sections. Null for an
|
|
592
|
+
* instrumental, and absent from gateways older than this field.
|
|
593
|
+
*/
|
|
594
|
+
lyrics?: string | null;
|
|
521
595
|
prompt?: string;
|
|
522
596
|
usage: { creditsUsed: number };
|
|
523
597
|
}
|
|
@@ -532,11 +606,12 @@ export interface SfxRequest {
|
|
|
532
606
|
durationSeconds?: number;
|
|
533
607
|
/**
|
|
534
608
|
* 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.
|
|
609
|
+
* and less variable; lower = more creative/ambient. Omit to use the
|
|
610
|
+
* ElevenLabs default (~0.3).
|
|
538
611
|
*/
|
|
539
612
|
promptInfluence?: number;
|
|
613
|
+
/** Make the clip loop seamlessly (ambience, engine hum, rain). */
|
|
614
|
+
loop?: boolean;
|
|
540
615
|
signal?: AbortSignal;
|
|
541
616
|
/** Per-call timeout (ms). Defaults to 120000 (2 min). */
|
|
542
617
|
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();
|
|
@@ -1007,12 +1038,18 @@ export class AIFlowClient {
|
|
|
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
1040
|
* URLs) on the models in `config.audioImageInputModels`.
|
|
1010
|
-
*
|
|
1041
|
+
* `durationSeconds` (5–180) fixes the length: Lyria has no length setting
|
|
1042
|
+
* and runs long, so the gateway plans the song to it and trims the rest
|
|
1043
|
+
* with a fade-out. `format: 'wav'` returns a WAV file instead of MP3;
|
|
1044
|
+
* `lyrics` in the result holds the sung words (null for an instrumental).
|
|
1045
|
+
* @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, lyrics:string|null, prompt?:string, usage:{creditsUsed:number}}>}
|
|
1011
1046
|
*/
|
|
1012
1047
|
async generateAudio({
|
|
1013
1048
|
prompt,
|
|
1014
1049
|
model,
|
|
1015
1050
|
images,
|
|
1051
|
+
durationSeconds,
|
|
1052
|
+
format,
|
|
1016
1053
|
negativePrompt,
|
|
1017
1054
|
seed,
|
|
1018
1055
|
signal,
|
|
@@ -1032,6 +1069,9 @@ export class AIFlowClient {
|
|
|
1032
1069
|
model: resolvedModel,
|
|
1033
1070
|
prompt,
|
|
1034
1071
|
images: images?.length ? images : undefined,
|
|
1072
|
+
// 5–180s; the gateway plans the song to it and trims overshoot.
|
|
1073
|
+
durationSeconds,
|
|
1074
|
+
format,
|
|
1035
1075
|
negativePrompt,
|
|
1036
1076
|
seed,
|
|
1037
1077
|
},
|
|
@@ -1051,6 +1091,7 @@ export class AIFlowClient {
|
|
|
1051
1091
|
model,
|
|
1052
1092
|
durationSeconds,
|
|
1053
1093
|
promptInfluence,
|
|
1094
|
+
loop,
|
|
1054
1095
|
signal,
|
|
1055
1096
|
timeout,
|
|
1056
1097
|
} = {}) {
|
|
@@ -1065,6 +1106,7 @@ export class AIFlowClient {
|
|
|
1065
1106
|
prompt,
|
|
1066
1107
|
durationSeconds,
|
|
1067
1108
|
promptInfluence,
|
|
1109
|
+
loop,
|
|
1068
1110
|
},
|
|
1069
1111
|
{ signal, timeout: timeout ?? 120_000 },
|
|
1070
1112
|
);
|
|
@@ -1072,8 +1114,10 @@ export class AIFlowClient {
|
|
|
1072
1114
|
}
|
|
1073
1115
|
|
|
1074
1116
|
/**
|
|
1075
|
-
* Extract text (or answer a question) from
|
|
1076
|
-
*
|
|
1117
|
+
* Extract text (or answer a question) from one image. A `chat()` call with
|
|
1118
|
+
* the image as an `image_url` block and web search off, on the module's
|
|
1119
|
+
* chat model unless `model` is given — the gateway has no separate vision
|
|
1120
|
+
* route.
|
|
1077
1121
|
*
|
|
1078
1122
|
* @param {object} options
|
|
1079
1123
|
* @param {string} options.imageUrl Publicly accessible image URL (or base64 data-URI).
|
|
@@ -1088,13 +1132,27 @@ export class AIFlowClient {
|
|
|
1088
1132
|
if (!imageUrl || typeof imageUrl !== 'string') {
|
|
1089
1133
|
throw new AIFlowError('imageUrl is required');
|
|
1090
1134
|
}
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1135
|
+
const res = await this.chat({
|
|
1136
|
+
model,
|
|
1137
|
+
maxTokens,
|
|
1138
|
+
webSearch: false,
|
|
1139
|
+
messages: [
|
|
1140
|
+
{
|
|
1141
|
+
role: 'user',
|
|
1142
|
+
content: [
|
|
1143
|
+
{
|
|
1144
|
+
type: 'text',
|
|
1145
|
+
text:
|
|
1146
|
+
prompt ||
|
|
1147
|
+
'Extract all text visible in this image.',
|
|
1148
|
+
},
|
|
1149
|
+
{ type: 'image_url', image_url: { url: imageUrl } },
|
|
1150
|
+
],
|
|
1151
|
+
},
|
|
1152
|
+
],
|
|
1153
|
+
signal,
|
|
1154
|
+
});
|
|
1155
|
+
return { text: res.content, model: res.model, usage: res.usage };
|
|
1098
1156
|
}
|
|
1099
1157
|
|
|
1100
1158
|
/**
|
|
@@ -1684,6 +1742,19 @@ function parseSseEvent(rawEvent) {
|
|
|
1684
1742
|
}
|
|
1685
1743
|
}
|
|
1686
1744
|
|
|
1745
|
+
/**
|
|
1746
|
+
* The gateway runs no caller-defined tools (web search is built in — see
|
|
1747
|
+
* `webSearch`) and rejects a `tools` field with a 422, so fail here with a
|
|
1748
|
+
* message that says why.
|
|
1749
|
+
*/
|
|
1750
|
+
function assertNoTools(tools) {
|
|
1751
|
+
if (tools !== undefined && tools !== null) {
|
|
1752
|
+
throw new AIFlowError(
|
|
1753
|
+
'tools is not supported by the AIFlow gateway — web search is built in; use webSearch to turn it on or off',
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1687
1758
|
function anySignal(a, b) {
|
|
1688
1759
|
if (!a) return b;
|
|
1689
1760
|
if (!b) return a;
|