@devvibex/aiflow 1.0.8 → 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 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.8",
4
- "description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image generation and embeddings without shipping any third-party API key.",
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
@@ -93,6 +93,8 @@ export interface ImageRequest {
93
93
  */
94
94
  language?: string;
95
95
  signal?: AbortSignal;
96
+ /** Per-call timeout (ms). Defaults to 180000 — image edits exceed the 60s client default. */
97
+ timeout?: number;
96
98
  }
97
99
 
98
100
  export interface GeneratedImage {
@@ -106,6 +108,56 @@ export interface ImageResponse {
106
108
  usage: { creditsUsed: number };
107
109
  }
108
110
 
111
+ // ─── Batch image ────────────────────────────────────────────────────────────
112
+
113
+ /**
114
+ * One page in a batch image request. Mirrors {@link ImageRequest} but `prompt`
115
+ * is optional — it can be supplied once at the batch level and shared across
116
+ * every page (the common case for translating all pages of a PDF).
117
+ */
118
+ export interface ImageBatchPage {
119
+ prompt?: string;
120
+ model?: string;
121
+ size?: '512x512' | '1024x1024' | '1024x1792' | string;
122
+ aspectRatio?: string;
123
+ n?: number;
124
+ image?: string;
125
+ images?: string[];
126
+ system?: string;
127
+ language?: string;
128
+ }
129
+
130
+ export interface ImageBatchRequest {
131
+ /** Pages to process (1–20). */
132
+ pages: ImageBatchPage[];
133
+ /** Shared defaults applied to any page that omits the field. */
134
+ prompt?: string;
135
+ model?: string;
136
+ system?: string;
137
+ language?: string;
138
+ size?: '512x512' | '1024x1024' | '1024x1792' | string;
139
+ /** Max pages processed simultaneously (1–4, default 3 server-side). */
140
+ concurrency?: number;
141
+ signal?: AbortSignal;
142
+ /** Per-call timeout (ms). Defaults to 600000 (10 min). */
143
+ timeout?: number;
144
+ }
145
+
146
+ export interface ImageBatchPageResult {
147
+ index: number;
148
+ status: 'success' | 'error';
149
+ images?: GeneratedImage[];
150
+ creditsUsed?: number;
151
+ error?: string;
152
+ }
153
+
154
+ export interface ImageBatchResponse {
155
+ results: ImageBatchPageResult[];
156
+ successCount: number;
157
+ errorCount: number;
158
+ totalCreditsUsed: number;
159
+ }
160
+
109
161
  // ─── Video ────────────────────────────────────────────────────────────────────
110
162
 
111
163
  export interface VideoRequest {
@@ -122,6 +174,55 @@ export interface VideoResponse {
122
174
  usage: { creditsUsed: number };
123
175
  }
124
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
+
125
226
  // ─── Vision ───────────────────────────────────────────────────────────────────
126
227
 
127
228
  export interface VisionRequest {
@@ -170,6 +271,8 @@ export interface AIFlowClientOptions {
170
271
  defaultImageModel?: string | null;
171
272
  defaultEmbedModel?: string | null;
172
273
  defaultVideoModel?: string | null;
274
+ defaultAudioModel?: string | null;
275
+ defaultSfxModel?: string | null;
173
276
  timeout?: number;
174
277
  maxRetries?: number;
175
278
  fetch?: typeof fetch;
@@ -182,17 +285,23 @@ export interface AiflowConfig {
182
285
  image: string[];
183
286
  embed: string[];
184
287
  video: string[];
288
+ audio: string[];
289
+ sfx: string[];
185
290
  };
186
291
  defaults: {
187
292
  chat: string;
188
293
  image: string;
189
294
  embed: string;
190
295
  video: string;
296
+ audio: string;
297
+ sfx: string;
191
298
  };
192
299
  limits: {
193
300
  maxTokens: number;
194
301
  maxImageN: number;
195
302
  maxEmbedInputs: number;
303
+ minSfxDurationSeconds: number;
304
+ maxSfxDurationSeconds: number;
196
305
  };
197
306
  creditValue: number;
198
307
  /** Module-configured default system prompt, or null if none. */
@@ -215,7 +324,10 @@ export class AIFlowClient {
215
324
  chat(request: ChatRequest): Promise<ChatResponse>;
216
325
  chatStream(request: ChatRequest): AsyncGenerator<ChatStreamChunk, void, void>;
217
326
  generateImage(request: ImageRequest): Promise<ImageResponse>;
327
+ generateImageBatch(request: ImageBatchRequest): Promise<ImageBatchResponse>;
218
328
  generateVideo(request: VideoRequest): Promise<VideoResponse>;
329
+ generateAudio(request: AudioRequest): Promise<AudioResponse>;
330
+ generateSfx(request: SfxRequest): Promise<SfxResponse>;
219
331
  embed(request: EmbedRequest): Promise<EmbedResponse>;
220
332
  vision(request: VisionRequest): Promise<VisionResponse>;
221
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;
@@ -249,6 +255,7 @@ export class AIFlowClient {
249
255
  system,
250
256
  language,
251
257
  signal,
258
+ timeout,
252
259
  } = {}) {
253
260
  if (!prompt || typeof prompt !== 'string') {
254
261
  throw new AIFlowError('prompt is required');
@@ -271,7 +278,57 @@ export class AIFlowClient {
271
278
  system: resolvedSystem,
272
279
  language,
273
280
  },
274
- { signal },
281
+ // Image edits (esp. document translation) routinely exceed the 60s
282
+ // client default — a single 2K edit was observed at ~63s. Default
283
+ // to 3 minutes so the SDK doesn't abort a request the server is
284
+ // still completing.
285
+ { signal, timeout: timeout ?? 180_000 },
286
+ );
287
+ return await res.json();
288
+ }
289
+
290
+ /**
291
+ * Batch image generation/editing — send many pages (e.g. every page of a
292
+ * translated PDF) in ONE call. The server processes them with bounded
293
+ * concurrency and isolates per-page failures, so one page hitting
294
+ * MAX_TOKENS or a rate-limit never fails the whole job. Top-level
295
+ * `prompt`/`model`/`system`/`language`/`size` are shared defaults applied
296
+ * to any page that omits them — handy for translating all pages with the
297
+ * same instruction while varying only the image.
298
+ *
299
+ * @returns {Promise<{results: Array<{index:number,status:'success'|'error',images?:Array<{url?:string,b64?:string,mimeType:string}>,creditsUsed?:number,error?:string}>, successCount:number, errorCount:number, totalCreditsUsed:number}>}
300
+ */
301
+ async generateImageBatch({
302
+ pages,
303
+ prompt,
304
+ model,
305
+ system,
306
+ language,
307
+ size,
308
+ concurrency,
309
+ signal,
310
+ timeout,
311
+ } = {}) {
312
+ if (!Array.isArray(pages) || pages.length === 0) {
313
+ throw new AIFlowError('pages must be a non-empty array');
314
+ }
315
+ const resolvedModel =
316
+ model || (await this._resolveDefaultModel('image'));
317
+ const resolvedSystem = await this._resolveSystemPrompt(system);
318
+ const res = await this._request(
319
+ '/image/batch',
320
+ {
321
+ pages,
322
+ prompt,
323
+ model: resolvedModel,
324
+ system: resolvedSystem,
325
+ language,
326
+ size,
327
+ concurrency,
328
+ },
329
+ // A batch of multi-minute edits needs far longer than a single
330
+ // request — default to 10 minutes, matching the server socket.
331
+ { signal, timeout: timeout ?? 600_000 },
275
332
  );
276
333
  return await res.json();
277
334
  }
@@ -307,6 +364,65 @@ export class AIFlowClient {
307
364
  return await res.json();
308
365
  }
309
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
+
310
426
  /**
311
427
  * Extract text (or answer a question) from an image URL using vision models.
312
428
  * Defaults to Claude when no model is specified.
@@ -356,20 +472,23 @@ export class AIFlowClient {
356
472
  // Internals
357
473
  // ────────────────────────────────────────────────────────────────────────
358
474
 
359
- async _request(path, body, { signal, stream = false } = {}) {
475
+ async _request(path, body, { signal, stream = false, timeout } = {}) {
360
476
  const url = `${this.baseUrl}${path}`;
361
477
  const headers = {
362
478
  'Content-Type': 'application/json',
363
479
  'x-app-id': this.appId,
364
480
  Accept: stream ? 'text/event-stream' : 'application/json',
365
481
  };
482
+ // Per-call timeout override — image/video calls run far longer than the
483
+ // 60s client default, so they pass a larger value here.
484
+ const effectiveTimeout = timeout ?? this.timeout;
366
485
 
367
486
  let attempt = 0;
368
487
  while (true) {
369
488
  const timeoutCtrl = new AbortController();
370
489
  const timer = setTimeout(
371
490
  () => timeoutCtrl.abort(),
372
- this.timeout,
491
+ effectiveTimeout,
373
492
  );
374
493
  const composedSignal = anySignal(signal, timeoutCtrl.signal);
375
494