@devvibex/aiflow 1.16.0 → 1.16.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 CHANGED
@@ -190,7 +190,10 @@ const res = await aiflow.generateImage({ prompt, tag: 'poster' });
190
190
  ```
191
191
 
192
192
  A job whose server restarted mid-way fails with `code: 'interrupted'` (status
193
- 503) and is not charged — credits are deducted only on success.
193
+ 503) and is not charged — credits are deducted only on success. `chat`,
194
+ `generateImage`, `generateImageBatch`, `generateAudio` and `generateSfx` submit
195
+ such a job once more by themselves (≥ 1.16.1; `onJob` fires again with the new
196
+ id); `waitForJob` on a stored id and `chatStream` throw it, so offer a retry.
194
197
 
195
198
  ### `aiflow.generateImage({ prompt, model?, size?, aspectRatio?, n?, image?, images?, system?, language?, background?, signal? })`
196
199
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvibex/aiflow",
3
- "version": "1.16.0",
3
+ "version": "1.16.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
@@ -27,7 +27,9 @@ export interface BackgroundJobOptions {
27
27
  /**
28
28
  * Called once the gateway has accepted the job, before it finishes. Store
29
29
  * the id (e.g. on a "generating" row) to pick the result up later with
30
- * `waitForJob(jobId)` / `resumeChatStream(jobId)`.
30
+ * `waitForJob(jobId)` / `resumeChatStream(jobId)`. Fires again with a new id
31
+ * when a job cut off by a gateway restart is run once more (chat, image,
32
+ * music and SFX calls do that automatically).
31
33
  */
32
34
  onJob?: (jobId: string, info?: { sessionId?: string }) => void;
33
35
  /** Label for the job in `jobs.latest(tag)` / `listJobs()` (max 128 chars). */
package/src/index.js CHANGED
@@ -16,6 +16,11 @@ const JOB_WAIT_MS = 20_000;
16
16
  const DEFAULT_JOB_TIMEOUT_MS = 30 * 60_000;
17
17
  /** Times a dropped chat stream is re-attached to its job before giving up. */
18
18
  const STREAM_RESUME_ATTEMPTS = 3;
19
+ /**
20
+ * Times a job cut off by a gateway restart (`code: 'interrupted'`) is
21
+ * submitted again. Such a job was never charged.
22
+ */
23
+ const INTERRUPTED_RESUBMITS = 1;
19
24
 
20
25
  /**
21
26
  * Above this many seconds the gateway builds a video as independent SCENES in
@@ -1490,13 +1495,32 @@ export class AIFlowClient {
1490
1495
  */
1491
1496
  async _generate({ kind, path, body, signal, timeout, requestTimeout, onJob, tag }) {
1492
1497
  if (await this._jobsEnabled()) {
1493
- const res = await this._request(`${path}/jobs${tagQuery(tag)}`, body, {
1494
- signal,
1495
- timeout: requestTimeout ?? DEFAULT_TIMEOUT_MS,
1496
- });
1497
- const { jobId } = await res.json();
1498
- this._trackJob(jobId, kind, tag, onJob);
1499
- return this.waitForJob(jobId, { signal, timeout });
1498
+ const deadline = Date.now() + (timeout ?? DEFAULT_JOB_TIMEOUT_MS);
1499
+ for (let attempt = 0; ; attempt += 1) {
1500
+ const res = await this._request(`${path}/jobs${tagQuery(tag)}`, body, {
1501
+ signal,
1502
+ timeout: requestTimeout ?? DEFAULT_TIMEOUT_MS,
1503
+ });
1504
+ const { jobId } = await res.json();
1505
+ this._trackJob(jobId, kind, tag, onJob);
1506
+ try {
1507
+ return await this.waitForJob(jobId, {
1508
+ signal,
1509
+ timeout: Math.max(1, deadline - Date.now()),
1510
+ });
1511
+ } catch (err) {
1512
+ // The gateway pod running the job restarted (a deploy or a
1513
+ // scale-down) before it finished. Nothing was charged, so run
1514
+ // it once more — what the retry on a cut-off synchronous
1515
+ // request used to do. `onJob` fires again with the new id.
1516
+ const rerun =
1517
+ err?.code === 'interrupted' &&
1518
+ attempt < INTERRUPTED_RESUBMITS &&
1519
+ !signal?.aborted &&
1520
+ Date.now() < deadline;
1521
+ if (!rerun) throw err;
1522
+ }
1523
+ }
1500
1524
  }
1501
1525
  const res = await this._request(path, body, {
1502
1526
  signal,