@devvibex/aiflow 1.13.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 +135 -60
- package/package.json +1 -1
- package/src/index.d.ts +150 -30
- package/src/index.js +125 -31
package/README.md
CHANGED
|
@@ -97,45 +97,99 @@ to invalidate the cache.
|
|
|
97
97
|
{
|
|
98
98
|
appId: string,
|
|
99
99
|
models: {
|
|
100
|
-
chat: string[], // e.g. ["claude-
|
|
100
|
+
chat: string[], // version-less ids, e.g. ["claude-opus", "gpt", ...]
|
|
101
101
|
image: string[],
|
|
102
102
|
embed: string[],
|
|
103
103
|
video: string[],
|
|
104
|
-
audio: string[], // Lyria —
|
|
105
|
-
sfx: string[], // ElevenLabs —
|
|
104
|
+
audio: string[], // Lyria 3.5 — ["lyria-pro"]
|
|
105
|
+
sfx: string[], // ElevenLabs — ["elevenlabs-sfx"]
|
|
106
106
|
},
|
|
107
107
|
defaults: { chat: string, image: string, embed: string, video: string, audio: string, sfx: string },
|
|
108
|
+
imageBackgroundModels: string[], // image models that honour `background`
|
|
109
|
+
audioImageInputModels: string[], // audio models that take `images`
|
|
108
110
|
limits: {
|
|
109
111
|
maxTokens: number,
|
|
110
112
|
maxImageN: number,
|
|
111
113
|
maxEmbedInputs: number,
|
|
112
114
|
minSfxDurationSeconds: number,
|
|
113
115
|
maxSfxDurationSeconds: number,
|
|
116
|
+
maxAudioInputImages: number,
|
|
114
117
|
},
|
|
115
118
|
creditValue: number,
|
|
116
119
|
}
|
|
117
120
|
```
|
|
118
121
|
|
|
119
|
-
### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, signal? })`
|
|
122
|
+
### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, webSearch?, signal? })`
|
|
120
123
|
|
|
121
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.
|
|
122
128
|
|
|
123
129
|
### `aiflow.chatStream({ ... })`
|
|
124
130
|
|
|
125
131
|
Async iterable of `{ delta: string, done: boolean }` chunks. The final chunk
|
|
126
132
|
has `done: true` and carries the cumulative `usage` object.
|
|
127
133
|
|
|
128
|
-
### `aiflow.generateImage({ prompt, model?, size?, n?, image?, images?, system?, language?, signal? })`
|
|
134
|
+
### `aiflow.generateImage({ prompt, model?, size?, aspectRatio?, n?, image?, images?, system?, language?, background?, signal? })`
|
|
129
135
|
|
|
130
136
|
Returns `{ images: [{ url?, b64?, mimeType }], usage: { creditsUsed } }`.
|
|
131
137
|
`url` is a short-lived signed URL (~1h). Pass `image`/`images` to edit an
|
|
132
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`
|
|
142
|
+
(`'auto'` | `'transparent'` | `'opaque'`) is honoured only by the models in
|
|
143
|
+
`config.imageBackgroundModels`; `generateImageBatch` takes it top-level or per
|
|
144
|
+
page. The module default is set with `admin.updateConfig({ imageBackground })`.
|
|
133
145
|
|
|
134
|
-
### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, video?, signal? })`
|
|
146
|
+
### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, lastFrame?, video?, referenceImages?, referenceVideos?, referenceAudios?, generateAudio?, signal? })`
|
|
135
147
|
|
|
136
148
|
Returns `{ videoUrl, usage: { creditsUsed } }`. Pass `image` for image-to-video
|
|
137
149
|
or `video` for video-to-video; omit both for pure text-to-video.
|
|
138
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
|
+
|
|
188
|
+
The default model is **Gemini Omni**: one clip of ~10s, **with sound**, 16:9 or
|
|
189
|
+
9:16 only, and no length parameter. For a longer or extendable video use
|
|
190
|
+
`generateLongVideo` / `createVideoSession` below — same model, so a single clip
|
|
191
|
+
and an extended one look and sound alike. Veo and Seedance are opt-in per module.
|
|
192
|
+
|
|
139
193
|
### `aiflow.generateLongVideo({ prompt, durationSeconds, ... })` — long video from one prompt
|
|
140
194
|
|
|
141
195
|
One prompt plus a duration, one call, one finished video. The gateway splits your
|
|
@@ -143,10 +197,16 @@ prompt into a storyboard of ~10s beats, generates the opening clip, then extends
|
|
|
143
197
|
turn after turn — concatenating as it goes — until the timeline reaches the
|
|
144
198
|
length you asked for.
|
|
145
199
|
|
|
200
|
+
**Maximum 40 seconds.** A video is one Gemini Omni chain: an opening clip of up
|
|
201
|
+
to 10s (its default and its maximum) plus consecutive extends, 40s in total.
|
|
202
|
+
That is a model limit, not a setting — ask for more and you get 40s back with a
|
|
203
|
+
`warning` saying so. Past 40s, generate several videos and join them with
|
|
204
|
+
`mergeVideos` (below) — the joins are hard cuts.
|
|
205
|
+
|
|
146
206
|
```js
|
|
147
207
|
const video = await aiflow.generateLongVideo({
|
|
148
208
|
prompt: 'A lighthouse keeper climbing the spiral stairs at dawn, then the lamp sweeping out over the water',
|
|
149
|
-
durationSeconds: 30,
|
|
209
|
+
durationSeconds: 30, // 5-40
|
|
150
210
|
aspectRatio: '16:9',
|
|
151
211
|
onProgress: ({ segmentsDone, segmentsPlanned, durationSeconds, videoUrl }) => {
|
|
152
212
|
// videoUrl is ALREADY PLAYABLE — show the partial video, not a spinner
|
|
@@ -161,53 +221,32 @@ video.usage.creditsUsed;
|
|
|
161
221
|
video.warning; // set if it finished shorter than asked (still playable)
|
|
162
222
|
```
|
|
163
223
|
|
|
164
|
-
|
|
224
|
+
The result is always ONE CONTINUOUS SHOT — each clip continues the last — and
|
|
225
|
+
`extendVideo` can lengthen it afterwards while it is still under 40s.
|
|
165
226
|
|
|
166
|
-
|
|
167
|
-
|---|---|---|
|
|
168
|
-
| Shape | ONE continuous shot (chained) | independent SCENES, hard cuts |
|
|
169
|
-
| Generated | sequentially — each clip continues the last | **in parallel** |
|
|
170
|
-
| 10 min of video | impossible (~2.75h, and continuity is gone after ~1 min) | ~55 min |
|
|
171
|
-
| Resumable | no (extend it instead) | **yes** — `resumeLongVideo` |
|
|
227
|
+
Design the UI around four facts:
|
|
172
228
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// 10 minutes. ~60 scenes, ~55 min of building, ~$61 of provider cost.
|
|
182
|
-
const film = await aiflow.generateLongVideo({ prompt, durationSeconds: 600, onProgress });
|
|
183
|
-
|
|
184
|
-
// If it stopped short (gateway restart, provider hiccup, credits ran out):
|
|
185
|
-
if (film.warning) {
|
|
186
|
-
const finished = await aiflow.resumeLongVideo(film.sessionId, { onProgress });
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
`resumeLongVideo` regenerates **only the missing scenes** — every finished scene
|
|
191
|
-
is already paid for and is never regenerated. That is what makes an hours-long
|
|
192
|
-
build survivable, so treat `warning` as "call resume", not as a failure.
|
|
193
|
-
|
|
194
|
-
Design the UI around three facts:
|
|
195
|
-
|
|
196
|
-
- **It takes a long time** — roughly 2.5–3 minutes per 10 seconds for a
|
|
197
|
-
continuous video (~8 min for 30s, ~33 min for 2 min), and roughly that divided
|
|
198
|
-
by the gateway's scene concurrency for long-form (~55 min for 10 min of video).
|
|
199
|
-
`onProgress` fires after each clip, so show progress — and for continuous
|
|
200
|
-
builds the partial video, which is already playable.
|
|
201
|
-
- **The result is "at least" the requested length.** Omni cannot be asked for a
|
|
202
|
-
clip length, so the timeline overshoots by up to one segment.
|
|
229
|
+
- **Cap the duration control at 40s.** Preset chips (10s / 20s / 30s / 40s) say
|
|
230
|
+
it most clearly. Anything above is clamped, not honoured.
|
|
231
|
+
- **It takes a long time** — roughly 2.5–3 minutes per 10 seconds, so ~8 min for
|
|
232
|
+
a 30s video and ~10 for the full 40s. `onProgress` fires after each clip, so
|
|
233
|
+
show progress and the partial video, which is already playable.
|
|
234
|
+
- **The result is "at least" the requested length** (up to the 40s cap). Omni
|
|
235
|
+
cannot be asked for a clip length, so the timeline overshoots by up to one
|
|
236
|
+
segment.
|
|
203
237
|
- **A short build still resolves.** If a turn fails or credits run out mid-way,
|
|
204
238
|
you get the shorter video plus `warning` explaining why — show both; it is not
|
|
205
239
|
an error.
|
|
206
240
|
|
|
241
|
+
`resumeLongVideo(sessionId)` exists for the older **scene-based** long-form
|
|
242
|
+
builds (parallel scenes with hard cuts, `session.mode === 'scenes'`). No new
|
|
243
|
+
session is built that way while the 40s cap is in place; the method stays for
|
|
244
|
+
sessions created before it.
|
|
245
|
+
|
|
207
246
|
Cost scales with the finished length (Omni bills per delivered second), so show a
|
|
208
|
-
credit estimate before calling.
|
|
209
|
-
(`AIFLOW_VIDEO_MAX_TARGET_SECONDS
|
|
210
|
-
not refused.
|
|
247
|
+
credit estimate before calling. A deployment can lower the cap below 40s
|
|
248
|
+
(`AIFLOW_VIDEO_MAX_TARGET_SECONDS`) but never raise it; either way a larger
|
|
249
|
+
request is clamped, not refused.
|
|
211
250
|
|
|
212
251
|
Under the hood this is a video session (below) that the gateway drives for you —
|
|
213
252
|
`sessionId` comes back on the result, so you can keep extending it manually
|
|
@@ -255,9 +294,10 @@ interaction it still holds server-side. The gateway concatenates the segments
|
|
|
255
294
|
and always hands back the whole timeline, so your app plays **one url** and
|
|
256
295
|
never stitches anything itself.
|
|
257
296
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
297
|
+
Runs on Gemini Omni — Veo and Seedance hold no context between calls. Leave
|
|
298
|
+
`model` unset: the gateway uses Omni even when the module's video model is Veo
|
|
299
|
+
or Seedance, and refuses only a non-Omni model you pass explicitly. Total length
|
|
300
|
+
is capped at **40 seconds**.
|
|
261
301
|
|
|
262
302
|
```js
|
|
263
303
|
// 1. Open a session — generate the opening clip…
|
|
@@ -267,10 +307,11 @@ const { sessionId, jobId } = await aiflow.createVideoSession({
|
|
|
267
307
|
});
|
|
268
308
|
const opening = await aiflow.getVideoJob(jobId); // poll until 'succeeded'
|
|
269
309
|
|
|
270
|
-
// …or seed it from
|
|
271
|
-
//
|
|
310
|
+
// …or seed it from a clip you already have — an upload, a generateVideo or a
|
|
311
|
+
// mergeVideos result (no jobId — ready on return). The WHOLE clip stays on the
|
|
312
|
+
// timeline and counts toward the 40s, so up to 37s; Omni continues from its end.
|
|
272
313
|
const { sessionId: seeded } = await aiflow.createVideoSession({
|
|
273
|
-
video:
|
|
314
|
+
video: existingVideoUrlOrDataUrl,
|
|
274
315
|
});
|
|
275
316
|
|
|
276
317
|
// 2. Extend. Keep the prompt SIMPLE — terse continuation prompts extend best.
|
|
@@ -299,20 +340,54 @@ job's `videoUrl` is the timeline and `segmentUrl` the new tail.
|
|
|
299
340
|
Every turn is billed separately (Omni prices by output token), and
|
|
300
341
|
`session.usage.creditsUsed` is the running total for the whole session.
|
|
301
342
|
|
|
302
|
-
### `aiflow.generateAudio({ prompt, model?, negativePrompt?, seed?, signal?, timeout? })`
|
|
343
|
+
### `aiflow.generateAudio({ prompt, model?, images?, format?, negativePrompt?, seed?, signal?, timeout? })`
|
|
344
|
+
|
|
345
|
+
Generate music from a text prompt with Google **Lyria 3.5**. Returns
|
|
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.
|
|
303
363
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
+
```
|
|
308
373
|
|
|
309
|
-
### `aiflow.generateSfx({ prompt, model?, durationSeconds?, signal?, timeout? })`
|
|
374
|
+
### `aiflow.generateSfx({ prompt, model?, durationSeconds?, promptInfluence?, loop?, signal?, timeout? })`
|
|
310
375
|
|
|
311
376
|
Generate a one-shot sound effect from a text prompt (**ElevenLabs**). Returns
|
|
312
377
|
`{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `durationSeconds`
|
|
313
|
-
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
|
|
314
382
|
repeated UI sounds client-side rather than calling per interaction.
|
|
315
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
|
+
|
|
316
391
|
### `aiflow.embed({ input, model?, signal? })`
|
|
317
392
|
|
|
318
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
|
}
|
|
@@ -84,10 +93,19 @@ export interface ChatStreamChunk {
|
|
|
84
93
|
[key: string]: unknown;
|
|
85
94
|
}
|
|
86
95
|
|
|
96
|
+
/** Values for the image `background` option. */
|
|
97
|
+
export type ImageBackground = 'auto' | 'transparent' | 'opaque';
|
|
98
|
+
|
|
87
99
|
export interface ImageRequest {
|
|
88
100
|
prompt: string;
|
|
89
101
|
model?: string;
|
|
90
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';
|
|
91
109
|
n?: number;
|
|
92
110
|
image?: string;
|
|
93
111
|
images?: string[];
|
|
@@ -102,6 +120,12 @@ export interface ImageRequest {
|
|
|
102
120
|
* `{{language}}` placeholder in the system/user prompt server-side.
|
|
103
121
|
*/
|
|
104
122
|
language?: string;
|
|
123
|
+
/**
|
|
124
|
+
* What sits behind the subject: 'auto' (model decides, the default),
|
|
125
|
+
* 'transparent' (alpha PNG) or 'opaque'. Honoured only by the models in
|
|
126
|
+
* `config.imageBackgroundModels`; other models ignore it.
|
|
127
|
+
*/
|
|
128
|
+
background?: ImageBackground;
|
|
105
129
|
signal?: AbortSignal;
|
|
106
130
|
/** Per-call timeout (ms). Defaults to 180000 — image edits exceed the 60s client default. */
|
|
107
131
|
timeout?: number;
|
|
@@ -135,6 +159,8 @@ export interface ImageBatchPage {
|
|
|
135
159
|
images?: string[];
|
|
136
160
|
system?: string;
|
|
137
161
|
language?: string;
|
|
162
|
+
/** Per-page override of the shared `background`. */
|
|
163
|
+
background?: ImageBackground;
|
|
138
164
|
}
|
|
139
165
|
|
|
140
166
|
export interface ImageBatchRequest {
|
|
@@ -148,6 +174,8 @@ export interface ImageBatchRequest {
|
|
|
148
174
|
size?: '512x512' | '1024x1024' | '1024x1792' | string;
|
|
149
175
|
/** Max pages processed simultaneously (1–4, default 3 server-side). */
|
|
150
176
|
concurrency?: number;
|
|
177
|
+
/** Shared `background` for every page — see {@link ImageRequest.background}. */
|
|
178
|
+
background?: ImageBackground;
|
|
151
179
|
signal?: AbortSignal;
|
|
152
180
|
/** Per-call timeout (ms). Defaults to 600000 (10 min). */
|
|
153
181
|
timeout?: number;
|
|
@@ -173,31 +201,70 @@ export interface ImageBatchResponse {
|
|
|
173
201
|
export interface VideoRequest {
|
|
174
202
|
prompt: string;
|
|
175
203
|
/**
|
|
176
|
-
* Video model
|
|
177
|
-
*
|
|
178
|
-
*
|
|
204
|
+
* Video model: `'gemini-omni'` | `'veo'` | `'seedance'`. Defaults to the
|
|
205
|
+
* app's configured model, which is Gemini Omni unless the module was pinned
|
|
206
|
+
* to another one. Omni clips always have sound and are the only ones that
|
|
207
|
+
* can be extended (see {@link AIFlowClient.createVideoSession}).
|
|
179
208
|
*/
|
|
180
209
|
model?: string;
|
|
181
210
|
/**
|
|
182
|
-
* Output aspect ratio.
|
|
183
|
-
*
|
|
211
|
+
* Output aspect ratio. Gemini Omni supports 16:9 / 9:16 only; Veo also 1:1;
|
|
212
|
+
* Seedance also 1:1 / 4:3 / 3:4 / 21:9. An unsupported ratio is mapped to
|
|
213
|
+
* 16:9 by the server.
|
|
184
214
|
*/
|
|
185
215
|
aspectRatio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '21:9' | string;
|
|
186
216
|
/**
|
|
187
|
-
* Output resolution
|
|
188
|
-
*
|
|
189
|
-
*
|
|
217
|
+
* Output resolution: '720p' (default) | '1080p' on Gemini Omni and
|
|
218
|
+
* Seedance; Seedance also '480p' (Omni treats it as 720p). Lower generates
|
|
219
|
+
* faster and, on Omni, costs less. Ignored by Veo.
|
|
190
220
|
*/
|
|
191
221
|
resolution?: '480p' | '720p' | '1080p' | string;
|
|
192
222
|
/**
|
|
193
|
-
* Clip length in seconds
|
|
194
|
-
* that range, default 5).
|
|
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.
|
|
195
227
|
*/
|
|
196
228
|
duration?: number;
|
|
197
229
|
/** Burn the provider watermark into the output (Seedance only). */
|
|
198
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
|
+
*/
|
|
199
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;
|
|
200
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;
|
|
201
268
|
signal?: AbortSignal;
|
|
202
269
|
/**
|
|
203
270
|
* Overall wait budget across all status polls (ms). Defaults to 600000
|
|
@@ -333,9 +400,9 @@ export interface VideoSessionRequest {
|
|
|
333
400
|
*/
|
|
334
401
|
prompt?: string;
|
|
335
402
|
/**
|
|
336
|
-
*
|
|
337
|
-
* protocol
|
|
338
|
-
*
|
|
403
|
+
* Leave unset. Sessions run on Gemini Omni — the only model with a stateful
|
|
404
|
+
* extend protocol — and the gateway picks it even when the module's video
|
|
405
|
+
* model is Veo or Seedance. A non-Omni model passed here is rejected.
|
|
339
406
|
*/
|
|
340
407
|
model?: string;
|
|
341
408
|
/** Omni supports 16:9 and 9:16 only. Fixed for the whole session. */
|
|
@@ -345,9 +412,11 @@ export interface VideoSessionRequest {
|
|
|
345
412
|
/** Still image to animate into the opening clip (image-to-video). */
|
|
346
413
|
image?: string;
|
|
347
414
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
415
|
+
* A clip you already have — an upload, a `generateVideo` or a
|
|
416
|
+
* `mergeVideos` result — to seed the timeline with instead of generating an
|
|
417
|
+
* opener. An `https://` or `data:` URL. The WHOLE clip stays on the timeline
|
|
418
|
+
* and counts toward the 40s cap, so it may be at most 37s (longer is a 400);
|
|
419
|
+
* the model continues from its last ~10s (Omni's input limit).
|
|
351
420
|
*/
|
|
352
421
|
video?: string;
|
|
353
422
|
description?: string;
|
|
@@ -377,9 +446,14 @@ export interface LongVideoRequest {
|
|
|
377
446
|
/** What the whole video shows. The gateway splits it into per-segment beats. */
|
|
378
447
|
prompt: string;
|
|
379
448
|
/**
|
|
380
|
-
* How long the finished video should be, in seconds
|
|
381
|
-
*
|
|
382
|
-
*
|
|
449
|
+
* How long the finished video should be, in seconds — **5 to 40**.
|
|
450
|
+
*
|
|
451
|
+
* 40s is a model limit: a video is one Omni chain (an opening clip of up to
|
|
452
|
+
* 10s, then consecutive extends) and Google will not extend one past 40s.
|
|
453
|
+
* A larger number is CLAMPED to 40 and the result carries a `warning`.
|
|
454
|
+
*
|
|
455
|
+
* The result is "at least" this, up to the cap: Omni cannot be asked for a
|
|
456
|
+
* clip length, so the timeline overshoots by up to one ~10s segment.
|
|
383
457
|
*/
|
|
384
458
|
durationSeconds: number;
|
|
385
459
|
/** Must be a Gemini Omni model; defaults to the module's video model. */
|
|
@@ -403,9 +477,9 @@ export interface LongVideoResponse extends VideoResponse {
|
|
|
403
477
|
durationSeconds?: number;
|
|
404
478
|
segmentsDone?: number;
|
|
405
479
|
/**
|
|
406
|
-
* Set when the build came up short of `durationSeconds
|
|
407
|
-
*
|
|
408
|
-
* error.
|
|
480
|
+
* Set when the build came up short of `durationSeconds`, or when the request
|
|
481
|
+
* was clamped to the 40s maximum. The video is real and already paid for —
|
|
482
|
+
* show it, and the reason; do not treat it as an error.
|
|
409
483
|
*/
|
|
410
484
|
warning?: string;
|
|
411
485
|
}
|
|
@@ -464,15 +538,30 @@ export interface VideoExtendSubmitResponse extends VideoJobSubmitResponse {
|
|
|
464
538
|
sessionId: string;
|
|
465
539
|
}
|
|
466
540
|
|
|
467
|
-
// ─── Audio (music — Lyria)
|
|
541
|
+
// ─── Audio (music — Lyria 3.5) ──────────────────────────────────────────────
|
|
468
542
|
|
|
469
543
|
export interface AudioRequest {
|
|
470
|
-
/**
|
|
544
|
+
/**
|
|
545
|
+
* Musical description — mood, genre, tempo (BPM), instrumentation, texture,
|
|
546
|
+
* length ("about 30 seconds") and exclusions ("no vocals").
|
|
547
|
+
*/
|
|
471
548
|
prompt: string;
|
|
472
549
|
model?: string;
|
|
473
|
-
/**
|
|
550
|
+
/**
|
|
551
|
+
* Up to `config.limits.maxAudioInputImages` (10) reference images — https://
|
|
552
|
+
* or data: URLs — that the music should be inspired by. Only for models in
|
|
553
|
+
* `config.audioImageInputModels`; the gateway answers 400 otherwise.
|
|
554
|
+
*/
|
|
555
|
+
images?: string[];
|
|
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. */
|
|
474
563
|
negativePrompt?: string;
|
|
475
|
-
/**
|
|
564
|
+
/** Passed to Lyria as a seed. Google does not promise the same song for the same seed. */
|
|
476
565
|
seed?: number;
|
|
477
566
|
signal?: AbortSignal;
|
|
478
567
|
/** Per-call timeout (ms). Defaults to 180000 (3 min) — music gen is slow. */
|
|
@@ -486,6 +575,11 @@ export interface AudioResponse {
|
|
|
486
575
|
model: string;
|
|
487
576
|
/** Output duration in seconds, or null if undetermined. */
|
|
488
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;
|
|
489
583
|
prompt?: string;
|
|
490
584
|
usage: { creditsUsed: number };
|
|
491
585
|
}
|
|
@@ -500,11 +594,12 @@ export interface SfxRequest {
|
|
|
500
594
|
durationSeconds?: number;
|
|
501
595
|
/**
|
|
502
596
|
* How strictly the output follows the prompt (0–1). Higher = more literal
|
|
503
|
-
* and less variable; lower = more creative/ambient. Omit to use the
|
|
504
|
-
*
|
|
505
|
-
* drifting into a musical/ambient soundscape.
|
|
597
|
+
* and less variable; lower = more creative/ambient. Omit to use the
|
|
598
|
+
* ElevenLabs default (~0.3).
|
|
506
599
|
*/
|
|
507
600
|
promptInfluence?: number;
|
|
601
|
+
/** Make the clip loop seamlessly (ambience, engine hum, rain). */
|
|
602
|
+
loop?: boolean;
|
|
508
603
|
signal?: AbortSignal;
|
|
509
604
|
/** Per-call timeout (ms). Defaults to 120000 (2 min). */
|
|
510
605
|
timeout?: number;
|
|
@@ -810,12 +905,20 @@ export interface AiflowConfig {
|
|
|
810
905
|
modelUserSelectable?: boolean;
|
|
811
906
|
/** Per-feature form of `modelUserSelectable`. */
|
|
812
907
|
userSelectable?: Record<string, boolean>;
|
|
908
|
+
/** Module default for the image `background` option. */
|
|
909
|
+
imageBackground?: ImageBackground;
|
|
910
|
+
/** Image models that honour `background`. */
|
|
911
|
+
imageBackgroundModels?: string[];
|
|
912
|
+
/** Audio models that accept reference `images` in `generateAudio`. */
|
|
913
|
+
audioImageInputModels?: string[];
|
|
813
914
|
limits: {
|
|
814
915
|
maxTokens: number;
|
|
815
916
|
maxImageN: number;
|
|
816
917
|
maxEmbedInputs: number;
|
|
817
918
|
minSfxDurationSeconds: number;
|
|
818
919
|
maxSfxDurationSeconds: number;
|
|
920
|
+
/** Reference images per `generateAudio` call. */
|
|
921
|
+
maxAudioInputImages?: number;
|
|
819
922
|
};
|
|
820
923
|
creditValue: number;
|
|
821
924
|
/** Module-configured default system prompt, or null if none. */
|
|
@@ -838,6 +941,12 @@ export interface AiflowAdminModule {
|
|
|
838
941
|
title: string | null;
|
|
839
942
|
systemPrompt: string | null;
|
|
840
943
|
defaults: Record<string, string>;
|
|
944
|
+
/** Per-feature "User Selection" flags, key-for-key with `defaults`. */
|
|
945
|
+
userSelectable?: Record<string, boolean>;
|
|
946
|
+
/** Stored default for the image `background` option. */
|
|
947
|
+
imageBackground?: ImageBackground;
|
|
948
|
+
/** Image models that honour `background`. */
|
|
949
|
+
imageBackgroundModels?: string[];
|
|
841
950
|
models: string[];
|
|
842
951
|
}
|
|
843
952
|
|
|
@@ -852,6 +961,8 @@ export interface AiflowAdminUpdateConfigInput {
|
|
|
852
961
|
defaults?: Record<string, string>;
|
|
853
962
|
/** Sugar: sets the chat default model (folded into `defaults.chat`). */
|
|
854
963
|
defaultModel?: string;
|
|
964
|
+
/** Default image `background` for the module. Top-level — never inside `defaults`. */
|
|
965
|
+
imageBackground?: ImageBackground;
|
|
855
966
|
}
|
|
856
967
|
|
|
857
968
|
/**
|
|
@@ -967,6 +1078,10 @@ export class AIFlowClient {
|
|
|
967
1078
|
* the gateway storyboards the prompt into ~10s beats, generates them turn by
|
|
968
1079
|
* turn and concatenates them into one finished clip.
|
|
969
1080
|
*
|
|
1081
|
+
* **Maximum 40 seconds** — see {@link LongVideoRequest.durationSeconds}.
|
|
1082
|
+
* For anything longer, generate several videos and {@link mergeVideos} them;
|
|
1083
|
+
* the joins are hard cuts.
|
|
1084
|
+
*
|
|
970
1085
|
* Takes MINUTES (roughly two to three per 10s). `onProgress` fires after
|
|
971
1086
|
* every segment with a playable partial `videoUrl` — build the UI around
|
|
972
1087
|
* that, not a spinner.
|
|
@@ -986,6 +1101,11 @@ export class AIFlowClient {
|
|
|
986
1101
|
* provider hiccup, or credits that have since been topped up. Only missing
|
|
987
1102
|
* scenes are generated; finished ones are already paid for and are never
|
|
988
1103
|
* regenerated. Resolves with the re-assembled video.
|
|
1104
|
+
*
|
|
1105
|
+
* Applies to SCENE-based sessions (`mode === 'scenes'`) only. None are
|
|
1106
|
+
* created while the 40s cap is in place — every new build is continuous and
|
|
1107
|
+
* is lengthened with {@link extendVideo} — so this serves sessions made
|
|
1108
|
+
* before it. A continuous session is rejected with a 400.
|
|
989
1109
|
*/
|
|
990
1110
|
resumeLongVideo(
|
|
991
1111
|
sessionId: string,
|
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,11 +404,13 @@ 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,
|
|
404
411
|
system,
|
|
405
412
|
language,
|
|
413
|
+
background,
|
|
406
414
|
signal,
|
|
407
415
|
timeout,
|
|
408
416
|
} = {}) {
|
|
@@ -421,11 +429,16 @@ export class AIFlowClient {
|
|
|
421
429
|
model: resolvedModel,
|
|
422
430
|
prompt,
|
|
423
431
|
size,
|
|
432
|
+
// Gemini image models only; wins over the ratio `size` implies.
|
|
433
|
+
aspectRatio,
|
|
424
434
|
n,
|
|
425
435
|
image,
|
|
426
436
|
images,
|
|
427
437
|
system: resolvedSystem,
|
|
428
438
|
language,
|
|
439
|
+
// 'auto' | 'transparent' | 'opaque' — honoured only by the
|
|
440
|
+
// models in `config.imageBackgroundModels`.
|
|
441
|
+
background,
|
|
429
442
|
},
|
|
430
443
|
// Image edits (esp. document translation) routinely exceed the 60s
|
|
431
444
|
// client default — a single 2K edit was observed at ~63s. Default
|
|
@@ -455,6 +468,7 @@ export class AIFlowClient {
|
|
|
455
468
|
language,
|
|
456
469
|
size,
|
|
457
470
|
concurrency,
|
|
471
|
+
background,
|
|
458
472
|
signal,
|
|
459
473
|
timeout,
|
|
460
474
|
} = {}) {
|
|
@@ -474,6 +488,7 @@ export class AIFlowClient {
|
|
|
474
488
|
language,
|
|
475
489
|
size,
|
|
476
490
|
concurrency,
|
|
491
|
+
background,
|
|
477
492
|
},
|
|
478
493
|
// A batch of multi-minute edits needs far longer than a single
|
|
479
494
|
// request — default to 10 minutes, matching the server socket.
|
|
@@ -523,13 +538,30 @@ export class AIFlowClient {
|
|
|
523
538
|
duration,
|
|
524
539
|
watermark,
|
|
525
540
|
image,
|
|
541
|
+
lastFrame,
|
|
526
542
|
video,
|
|
543
|
+
referenceImages,
|
|
544
|
+
referenceVideos,
|
|
545
|
+
referenceAudios,
|
|
546
|
+
generateAudio,
|
|
527
547
|
signal,
|
|
528
548
|
timeout,
|
|
529
549
|
} = {}) {
|
|
530
550
|
if (!prompt || typeof prompt !== 'string') {
|
|
531
551
|
throw new AIFlowError('prompt is required');
|
|
532
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
|
+
}
|
|
533
565
|
const resolvedModel =
|
|
534
566
|
model || (await this._resolveDefaultModel('video'));
|
|
535
567
|
const res = await this._request(
|
|
@@ -542,10 +574,15 @@ export class AIFlowClient {
|
|
|
542
574
|
duration,
|
|
543
575
|
watermark,
|
|
544
576
|
image,
|
|
577
|
+
lastFrame,
|
|
545
578
|
video,
|
|
579
|
+
referenceImages,
|
|
580
|
+
referenceVideos,
|
|
581
|
+
referenceAudios,
|
|
582
|
+
generateAudio,
|
|
546
583
|
},
|
|
547
584
|
// Submit returns fast; the default client timeout is plenty even
|
|
548
|
-
// when an image-to-video request uploads
|
|
585
|
+
// when an image-to-video request uploads base64 frames.
|
|
549
586
|
{ signal, timeout: timeout ?? DEFAULT_TIMEOUT_MS },
|
|
550
587
|
);
|
|
551
588
|
return await res.json();
|
|
@@ -723,9 +760,9 @@ export class AIFlowClient {
|
|
|
723
760
|
// continuous. The gateway concatenates the segments and always hands back the
|
|
724
761
|
// whole timeline, so an app plays ONE url and never stitches anything itself.
|
|
725
762
|
//
|
|
726
|
-
//
|
|
727
|
-
//
|
|
728
|
-
//
|
|
763
|
+
// Runs on Gemini Omni — Veo and Seedance hold no context between calls. The
|
|
764
|
+
// gateway picks Omni itself when the module's video model is one of those;
|
|
765
|
+
// it refuses only a non-Omni `model` the caller passed explicitly.
|
|
729
766
|
|
|
730
767
|
/**
|
|
731
768
|
* Open a stateful video session.
|
|
@@ -734,9 +771,11 @@ export class AIFlowClient {
|
|
|
734
771
|
* - `prompt` (± `image`): the opening clip is GENERATED. The returned
|
|
735
772
|
* `jobId` is polled like any video job; `session.videoUrl` is empty until
|
|
736
773
|
* it lands.
|
|
737
|
-
* - `video`: the timeline is SEEDED from
|
|
738
|
-
*
|
|
739
|
-
*
|
|
774
|
+
* - `video`: the timeline is SEEDED from a clip you already have (an
|
|
775
|
+
* upload, a `generateVideo` result, a `mergeVideos` result) — ready on
|
|
776
|
+
* return, no `jobId`. The WHOLE clip stays on the timeline and counts
|
|
777
|
+
* toward the 40s cap, so it can be at most 37s; the model continues from
|
|
778
|
+
* its last ~10s (Omni's input limit).
|
|
740
779
|
*
|
|
741
780
|
* `aspectRatio` / `resolution` are fixed for the WHOLE session here: Omni
|
|
742
781
|
* inherits them across the chain, and segments of differing geometry could
|
|
@@ -761,12 +800,14 @@ export class AIFlowClient {
|
|
|
761
800
|
'createVideoSession needs either a prompt (to generate the opening clip) or a video (to seed the timeline)',
|
|
762
801
|
);
|
|
763
802
|
}
|
|
764
|
-
|
|
765
|
-
|
|
803
|
+
// `model` is sent only when the caller chose one. Filling it from the
|
|
804
|
+
// module default (as every other call does) would name `veo` on a module
|
|
805
|
+
// pinned to Veo, and the gateway refuses a session on an explicitly
|
|
806
|
+
// named non-Omni model; left out, it resolves to Omni itself.
|
|
766
807
|
const res = await this._request(
|
|
767
808
|
'/video/sessions',
|
|
768
809
|
{
|
|
769
|
-
model
|
|
810
|
+
model,
|
|
770
811
|
prompt,
|
|
771
812
|
aspectRatio,
|
|
772
813
|
resolution,
|
|
@@ -793,18 +834,25 @@ export class AIFlowClient {
|
|
|
793
834
|
* ```js
|
|
794
835
|
* const video = await aiflow.generateLongVideo({
|
|
795
836
|
* prompt: 'A lighthouse keeper climbing the spiral stairs at dawn',
|
|
796
|
-
* durationSeconds: 30,
|
|
837
|
+
* durationSeconds: 30, // 5-40
|
|
797
838
|
* onProgress: (p) => setStatus(`${p.segmentsDone}/${p.segmentsPlanned} — ${p.durationSeconds ?? 0}s`),
|
|
798
839
|
* });
|
|
799
840
|
* ```
|
|
800
841
|
*
|
|
801
|
-
*
|
|
842
|
+
* **Maximum 40 seconds.** A video is one Omni chain — an opening clip of up
|
|
843
|
+
* to 10s plus consecutive extends — and Google will not extend one past 40s.
|
|
844
|
+
* A larger `durationSeconds` is CLAMPED to 40 and the result carries a
|
|
845
|
+
* `warning`. For anything longer, generate several videos and
|
|
846
|
+
* {@link AIFlowClient#mergeVideos} them; the joins are hard cuts.
|
|
847
|
+
*
|
|
848
|
+
* Three things to design the UI around:
|
|
849
|
+
* - cap the duration control at 40s (chips of 10 / 20 / 30 / 40 read best);
|
|
802
850
|
* - it takes MINUTES (roughly two to three per 10s of video), and
|
|
803
851
|
* `onProgress` fires after every segment with a PLAYABLE partial
|
|
804
852
|
* `videoUrl` — show it rather than a spinner;
|
|
805
|
-
* - the result is "at least" `durationSeconds
|
|
806
|
-
* clip length, so the timeline overshoots by up to one
|
|
807
|
-
* `durationSeconds` off the result for the real length.
|
|
853
|
+
* - the result is "at least" `durationSeconds` up to the cap. Omni cannot be
|
|
854
|
+
* asked for a clip length, so the timeline overshoots by up to one
|
|
855
|
+
* segment; read `durationSeconds` off the result for the real length.
|
|
808
856
|
*
|
|
809
857
|
* A build that comes up short still RESOLVES — with a shorter, already-paid
|
|
810
858
|
* video and a `warning` saying why. Show the video and the warning; do not
|
|
@@ -987,12 +1035,18 @@ export class AIFlowClient {
|
|
|
987
1035
|
}
|
|
988
1036
|
|
|
989
1037
|
/**
|
|
990
|
-
* Generate music / background audio from a text prompt (Lyria)
|
|
991
|
-
*
|
|
1038
|
+
* Generate music / background audio from a text prompt (Lyria 3.5),
|
|
1039
|
+
* optionally inspired by up to 10 reference `images` (https:// or data:
|
|
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}}>}
|
|
992
1044
|
*/
|
|
993
1045
|
async generateAudio({
|
|
994
1046
|
prompt,
|
|
995
1047
|
model,
|
|
1048
|
+
images,
|
|
1049
|
+
format,
|
|
996
1050
|
negativePrompt,
|
|
997
1051
|
seed,
|
|
998
1052
|
signal,
|
|
@@ -1001,6 +1055,9 @@ export class AIFlowClient {
|
|
|
1001
1055
|
if (!prompt || typeof prompt !== 'string') {
|
|
1002
1056
|
throw new AIFlowError('prompt is required');
|
|
1003
1057
|
}
|
|
1058
|
+
if (images !== undefined && !Array.isArray(images)) {
|
|
1059
|
+
throw new AIFlowError('images must be an array of URLs');
|
|
1060
|
+
}
|
|
1004
1061
|
const resolvedModel =
|
|
1005
1062
|
model || (await this._resolveDefaultModel('audio'));
|
|
1006
1063
|
const res = await this._request(
|
|
@@ -1008,11 +1065,13 @@ export class AIFlowClient {
|
|
|
1008
1065
|
{
|
|
1009
1066
|
model: resolvedModel,
|
|
1010
1067
|
prompt,
|
|
1068
|
+
images: images?.length ? images : undefined,
|
|
1069
|
+
format,
|
|
1011
1070
|
negativePrompt,
|
|
1012
1071
|
seed,
|
|
1013
1072
|
},
|
|
1014
|
-
// Music generation (
|
|
1015
|
-
//
|
|
1073
|
+
// Music generation (a full Lyria 3.5 song) runs well past the 60s
|
|
1074
|
+
// client default — allow 3 minutes before aborting.
|
|
1016
1075
|
{ signal, timeout: timeout ?? 180_000 },
|
|
1017
1076
|
);
|
|
1018
1077
|
return await res.json();
|
|
@@ -1027,6 +1086,7 @@ export class AIFlowClient {
|
|
|
1027
1086
|
model,
|
|
1028
1087
|
durationSeconds,
|
|
1029
1088
|
promptInfluence,
|
|
1089
|
+
loop,
|
|
1030
1090
|
signal,
|
|
1031
1091
|
timeout,
|
|
1032
1092
|
} = {}) {
|
|
@@ -1041,6 +1101,7 @@ export class AIFlowClient {
|
|
|
1041
1101
|
prompt,
|
|
1042
1102
|
durationSeconds,
|
|
1043
1103
|
promptInfluence,
|
|
1104
|
+
loop,
|
|
1044
1105
|
},
|
|
1045
1106
|
{ signal, timeout: timeout ?? 120_000 },
|
|
1046
1107
|
);
|
|
@@ -1048,8 +1109,10 @@ export class AIFlowClient {
|
|
|
1048
1109
|
}
|
|
1049
1110
|
|
|
1050
1111
|
/**
|
|
1051
|
-
* Extract text (or answer a question) from
|
|
1052
|
-
*
|
|
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.
|
|
1053
1116
|
*
|
|
1054
1117
|
* @param {object} options
|
|
1055
1118
|
* @param {string} options.imageUrl Publicly accessible image URL (or base64 data-URI).
|
|
@@ -1064,13 +1127,27 @@ export class AIFlowClient {
|
|
|
1064
1127
|
if (!imageUrl || typeof imageUrl !== 'string') {
|
|
1065
1128
|
throw new AIFlowError('imageUrl is required');
|
|
1066
1129
|
}
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
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 };
|
|
1074
1151
|
}
|
|
1075
1152
|
|
|
1076
1153
|
/**
|
|
@@ -1408,6 +1485,7 @@ export class AIFlowClient {
|
|
|
1408
1485
|
systemPrompt,
|
|
1409
1486
|
defaults,
|
|
1410
1487
|
defaultModel,
|
|
1488
|
+
imageBackground,
|
|
1411
1489
|
signal,
|
|
1412
1490
|
} = {}) {
|
|
1413
1491
|
// `defaultModel` is sugar for setting the chat default; fold it into
|
|
@@ -1420,6 +1498,9 @@ export class AIFlowClient {
|
|
|
1420
1498
|
if (moduleId != null) body.moduleId = moduleId;
|
|
1421
1499
|
if (systemPrompt !== undefined) body.systemPrompt = systemPrompt;
|
|
1422
1500
|
if (resolvedDefaults !== undefined) body.defaults = resolvedDefaults;
|
|
1501
|
+
// A TOP-LEVEL sibling of `defaults`, never inside it: the gateway reads
|
|
1502
|
+
// every `defaults` key as a feature and rejects this one.
|
|
1503
|
+
if (imageBackground !== undefined) body.imageBackground = imageBackground;
|
|
1423
1504
|
const res = await this._adminRequest('/admin/config', body, {
|
|
1424
1505
|
method: 'PATCH',
|
|
1425
1506
|
signal,
|
|
@@ -1656,6 +1737,19 @@ function parseSseEvent(rawEvent) {
|
|
|
1656
1737
|
}
|
|
1657
1738
|
}
|
|
1658
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
|
+
|
|
1659
1753
|
function anySignal(a, b) {
|
|
1660
1754
|
if (!a) return b;
|
|
1661
1755
|
if (!b) return a;
|