@devvibex/aiflow 1.0.9 → 1.1.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 +36 -4
- package/package.json +6 -2
- package/src/index.d.ts +59 -0
- package/src/index.js +65 -0
package/README.md
CHANGED
|
@@ -74,6 +74,9 @@ console.log(emb.data[0].embedding.length);
|
|
|
74
74
|
| `defaultModel` | `string` | from `GET /config` | Override — wins over server config. |
|
|
75
75
|
| `defaultImageModel` | `string` | from `GET /config` | Override. |
|
|
76
76
|
| `defaultEmbedModel` | `string` | from `GET /config` | Override. |
|
|
77
|
+
| `defaultVideoModel` | `string` | from `GET /config` | Override. |
|
|
78
|
+
| `defaultAudioModel` | `string` | from `GET /config` | Override (music / Lyria). |
|
|
79
|
+
| `defaultSfxModel` | `string` | from `GET /config` | Override (sound effects / ElevenLabs). |
|
|
77
80
|
| `timeout` | `number` | `60000` | Per-request timeout (ms). |
|
|
78
81
|
| `maxRetries` | `number` | `2` | Retries on 429 / 5xx / network errors. |
|
|
79
82
|
| `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch (Node <18, testing). |
|
|
@@ -94,9 +97,18 @@ to invalidate the cache.
|
|
|
94
97
|
chat: string[], // e.g. ["claude-sonnet-4-6", "gpt-4o", ...]
|
|
95
98
|
image: string[],
|
|
96
99
|
embed: string[],
|
|
100
|
+
video: string[],
|
|
101
|
+
audio: string[], // Lyria — e.g. ["lyria-3-clip-preview", ...]
|
|
102
|
+
sfx: string[], // ElevenLabs — e.g. ["eleven_text_to_sound_v2"]
|
|
103
|
+
},
|
|
104
|
+
defaults: { chat: string, image: string, embed: string, video: string, audio: string, sfx: string },
|
|
105
|
+
limits: {
|
|
106
|
+
maxTokens: number,
|
|
107
|
+
maxImageN: number,
|
|
108
|
+
maxEmbedInputs: number,
|
|
109
|
+
minSfxDurationSeconds: number,
|
|
110
|
+
maxSfxDurationSeconds: number,
|
|
97
111
|
},
|
|
98
|
-
defaults: { chat: string, image: string, embed: string },
|
|
99
|
-
limits: { maxTokens: number, maxImageN: number, maxEmbedInputs: number },
|
|
100
112
|
creditValue: number,
|
|
101
113
|
}
|
|
102
114
|
```
|
|
@@ -110,10 +122,30 @@ Returns `Promise<{ id, model, content, usage: { inputTokens, outputTokens, credi
|
|
|
110
122
|
Async iterable of `{ delta: string, done: boolean }` chunks. The final chunk
|
|
111
123
|
has `done: true` and carries the cumulative `usage` object.
|
|
112
124
|
|
|
113
|
-
### `aiflow.generateImage({ prompt, model?, size?, n?, signal? })`
|
|
125
|
+
### `aiflow.generateImage({ prompt, model?, size?, n?, image?, images?, system?, language?, signal? })`
|
|
114
126
|
|
|
115
127
|
Returns `{ images: [{ url?, b64?, mimeType }], usage: { creditsUsed } }`.
|
|
116
|
-
`url` is a short-lived signed URL (~1h).
|
|
128
|
+
`url` is a short-lived signed URL (~1h). Pass `image`/`images` to edit an
|
|
129
|
+
existing image (image-to-image) instead of generating from text.
|
|
130
|
+
|
|
131
|
+
### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, video?, signal? })`
|
|
132
|
+
|
|
133
|
+
Returns `{ videoUrl, usage: { creditsUsed } }`. Pass `image` for image-to-video
|
|
134
|
+
or `video` for video-to-video; omit both for pure text-to-video.
|
|
135
|
+
|
|
136
|
+
### `aiflow.generateAudio({ prompt, model?, negativePrompt?, seed?, signal?, timeout? })`
|
|
137
|
+
|
|
138
|
+
Generate music / background audio from a text prompt (Google Vertex AI **Lyria**).
|
|
139
|
+
Returns `{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `audioUrl`
|
|
140
|
+
is a hosted mp3/wav on the CDN. `prompt` should be a musical description (mood,
|
|
141
|
+
genre, tempo/BPM, instrumentation). `negativePrompt`/`seed` apply to Lyria 2 only.
|
|
142
|
+
|
|
143
|
+
### `aiflow.generateSfx({ prompt, model?, durationSeconds?, signal?, timeout? })`
|
|
144
|
+
|
|
145
|
+
Generate a one-shot sound effect from a text prompt (**ElevenLabs**). Returns
|
|
146
|
+
`{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `durationSeconds`
|
|
147
|
+
is clamped to `0.5–30`; omit it to let the model auto-decide. Cache/replay
|
|
148
|
+
repeated UI sounds client-side rather than calling per interaction.
|
|
117
149
|
|
|
118
150
|
### `aiflow.embed({ input, model?, signal? })`
|
|
119
151
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvibex/aiflow",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image, video, music (Lyria), sound effects (ElevenLabs) and embeddings without shipping any third-party API key.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
7
7
|
"llm",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"claude",
|
|
10
10
|
"gpt",
|
|
11
11
|
"gemini",
|
|
12
|
+
"lyria",
|
|
13
|
+
"elevenlabs",
|
|
14
|
+
"music-generation",
|
|
15
|
+
"sound-effects",
|
|
12
16
|
"vibex",
|
|
13
17
|
"aiflow"
|
|
14
18
|
],
|
package/src/index.d.ts
CHANGED
|
@@ -174,6 +174,55 @@ export interface VideoResponse {
|
|
|
174
174
|
usage: { creditsUsed: number };
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// ─── Audio (music — Lyria) ──────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
export interface AudioRequest {
|
|
180
|
+
/** Musical description — mood, genre, tempo (BPM), instrumentation, texture. */
|
|
181
|
+
prompt: string;
|
|
182
|
+
model?: string;
|
|
183
|
+
/** Things to steer away from. Lyria 2 only — ignored by Lyria 3. */
|
|
184
|
+
negativePrompt?: string;
|
|
185
|
+
/** Deterministic seed (Lyria 2 only). */
|
|
186
|
+
seed?: number;
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
/** Per-call timeout (ms). Defaults to 180000 (3 min) — music gen is slow. */
|
|
189
|
+
timeout?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface AudioResponse {
|
|
193
|
+
/** Public CDN URL of the generated music clip (mp3/wav). */
|
|
194
|
+
audioUrl: string;
|
|
195
|
+
/** Resolved model id that produced the clip. */
|
|
196
|
+
model: string;
|
|
197
|
+
/** Output duration in seconds, or null if undetermined. */
|
|
198
|
+
durationSeconds: number | null;
|
|
199
|
+
prompt?: string;
|
|
200
|
+
usage: { creditsUsed: number };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ─── SFX (sound effects — ElevenLabs) ───────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
export interface SfxRequest {
|
|
206
|
+
/** Sound description (the source + its character), e.g. "glass shattering". */
|
|
207
|
+
prompt: string;
|
|
208
|
+
model?: string;
|
|
209
|
+
/** Clip length in seconds (0.5–30). Omit to let the model auto-decide. */
|
|
210
|
+
durationSeconds?: number;
|
|
211
|
+
signal?: AbortSignal;
|
|
212
|
+
/** Per-call timeout (ms). Defaults to 120000 (2 min). */
|
|
213
|
+
timeout?: number;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface SfxResponse {
|
|
217
|
+
/** Public CDN URL of the generated sound effect (mp3). */
|
|
218
|
+
audioUrl: string;
|
|
219
|
+
model: string;
|
|
220
|
+
/** Output duration in seconds, or null if the model auto-decided. */
|
|
221
|
+
durationSeconds: number | null;
|
|
222
|
+
prompt?: string;
|
|
223
|
+
usage: { creditsUsed: number };
|
|
224
|
+
}
|
|
225
|
+
|
|
177
226
|
// ─── Vision ───────────────────────────────────────────────────────────────────
|
|
178
227
|
|
|
179
228
|
export interface VisionRequest {
|
|
@@ -222,6 +271,8 @@ export interface AIFlowClientOptions {
|
|
|
222
271
|
defaultImageModel?: string | null;
|
|
223
272
|
defaultEmbedModel?: string | null;
|
|
224
273
|
defaultVideoModel?: string | null;
|
|
274
|
+
defaultAudioModel?: string | null;
|
|
275
|
+
defaultSfxModel?: string | null;
|
|
225
276
|
timeout?: number;
|
|
226
277
|
maxRetries?: number;
|
|
227
278
|
fetch?: typeof fetch;
|
|
@@ -234,17 +285,23 @@ export interface AiflowConfig {
|
|
|
234
285
|
image: string[];
|
|
235
286
|
embed: string[];
|
|
236
287
|
video: string[];
|
|
288
|
+
audio: string[];
|
|
289
|
+
sfx: string[];
|
|
237
290
|
};
|
|
238
291
|
defaults: {
|
|
239
292
|
chat: string;
|
|
240
293
|
image: string;
|
|
241
294
|
embed: string;
|
|
242
295
|
video: string;
|
|
296
|
+
audio: string;
|
|
297
|
+
sfx: string;
|
|
243
298
|
};
|
|
244
299
|
limits: {
|
|
245
300
|
maxTokens: number;
|
|
246
301
|
maxImageN: number;
|
|
247
302
|
maxEmbedInputs: number;
|
|
303
|
+
minSfxDurationSeconds: number;
|
|
304
|
+
maxSfxDurationSeconds: number;
|
|
248
305
|
};
|
|
249
306
|
creditValue: number;
|
|
250
307
|
/** Module-configured default system prompt, or null if none. */
|
|
@@ -269,6 +326,8 @@ export class AIFlowClient {
|
|
|
269
326
|
generateImage(request: ImageRequest): Promise<ImageResponse>;
|
|
270
327
|
generateImageBatch(request: ImageBatchRequest): Promise<ImageBatchResponse>;
|
|
271
328
|
generateVideo(request: VideoRequest): Promise<VideoResponse>;
|
|
329
|
+
generateAudio(request: AudioRequest): Promise<AudioResponse>;
|
|
330
|
+
generateSfx(request: SfxRequest): Promise<SfxResponse>;
|
|
272
331
|
embed(request: EmbedRequest): Promise<EmbedResponse>;
|
|
273
332
|
vision(request: VisionRequest): Promise<VisionResponse>;
|
|
274
333
|
}
|
package/src/index.js
CHANGED
|
@@ -38,6 +38,9 @@ export class AIFlowClient {
|
|
|
38
38
|
defaultModel = null,
|
|
39
39
|
defaultImageModel = null,
|
|
40
40
|
defaultEmbedModel = null,
|
|
41
|
+
defaultVideoModel = null,
|
|
42
|
+
defaultAudioModel = null,
|
|
43
|
+
defaultSfxModel = null,
|
|
41
44
|
timeout = DEFAULT_TIMEOUT_MS,
|
|
42
45
|
maxRetries = DEFAULT_MAX_RETRIES,
|
|
43
46
|
fetch: customFetch,
|
|
@@ -52,6 +55,9 @@ export class AIFlowClient {
|
|
|
52
55
|
chat: defaultModel,
|
|
53
56
|
image: defaultImageModel,
|
|
54
57
|
embed: defaultEmbedModel,
|
|
58
|
+
video: defaultVideoModel,
|
|
59
|
+
audio: defaultAudioModel,
|
|
60
|
+
sfx: defaultSfxModel,
|
|
55
61
|
};
|
|
56
62
|
this.timeout = timeout;
|
|
57
63
|
this.maxRetries = maxRetries;
|
|
@@ -358,6 +364,65 @@ export class AIFlowClient {
|
|
|
358
364
|
return await res.json();
|
|
359
365
|
}
|
|
360
366
|
|
|
367
|
+
/**
|
|
368
|
+
* Generate music / background audio from a text prompt (Lyria).
|
|
369
|
+
* @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, prompt?:string, usage:{creditsUsed:number}}>}
|
|
370
|
+
*/
|
|
371
|
+
async generateAudio({
|
|
372
|
+
prompt,
|
|
373
|
+
model,
|
|
374
|
+
negativePrompt,
|
|
375
|
+
seed,
|
|
376
|
+
signal,
|
|
377
|
+
timeout,
|
|
378
|
+
} = {}) {
|
|
379
|
+
if (!prompt || typeof prompt !== 'string') {
|
|
380
|
+
throw new AIFlowError('prompt is required');
|
|
381
|
+
}
|
|
382
|
+
const resolvedModel =
|
|
383
|
+
model || (await this._resolveDefaultModel('audio'));
|
|
384
|
+
const res = await this._request(
|
|
385
|
+
'/audio',
|
|
386
|
+
{
|
|
387
|
+
model: resolvedModel,
|
|
388
|
+
prompt,
|
|
389
|
+
negativePrompt,
|
|
390
|
+
seed,
|
|
391
|
+
},
|
|
392
|
+
// Music generation (esp. full-song Lyria 3 Pro) runs well past the
|
|
393
|
+
// 60s client default — allow 3 minutes before aborting.
|
|
394
|
+
{ signal, timeout: timeout ?? 180_000 },
|
|
395
|
+
);
|
|
396
|
+
return await res.json();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Generate a one-shot sound effect from a text prompt (ElevenLabs).
|
|
401
|
+
* @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, prompt?:string, usage:{creditsUsed:number}}>}
|
|
402
|
+
*/
|
|
403
|
+
async generateSfx({
|
|
404
|
+
prompt,
|
|
405
|
+
model,
|
|
406
|
+
durationSeconds,
|
|
407
|
+
signal,
|
|
408
|
+
timeout,
|
|
409
|
+
} = {}) {
|
|
410
|
+
if (!prompt || typeof prompt !== 'string') {
|
|
411
|
+
throw new AIFlowError('prompt is required');
|
|
412
|
+
}
|
|
413
|
+
const resolvedModel = model || (await this._resolveDefaultModel('sfx'));
|
|
414
|
+
const res = await this._request(
|
|
415
|
+
'/sfx',
|
|
416
|
+
{
|
|
417
|
+
model: resolvedModel,
|
|
418
|
+
prompt,
|
|
419
|
+
durationSeconds,
|
|
420
|
+
},
|
|
421
|
+
{ signal, timeout: timeout ?? 120_000 },
|
|
422
|
+
);
|
|
423
|
+
return await res.json();
|
|
424
|
+
}
|
|
425
|
+
|
|
361
426
|
/**
|
|
362
427
|
* Extract text (or answer a question) from an image URL using vision models.
|
|
363
428
|
* Defaults to Claude when no model is specified.
|