ai-retry 0.9.0 → 0.10.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 +34 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -0
- package/dist/retryables/index.d.ts +1 -1
- package/dist/{types-BuPozWMn.d.ts → types-CphTxZ_b.d.ts} +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -391,6 +391,32 @@ By default, if a [`retry-after-ms`](https://learn.microsoft.com/en-us/azure/ai-f
|
|
|
391
391
|
|
|
392
392
|
### Options
|
|
393
393
|
|
|
394
|
+
#### Disabling Retries
|
|
395
|
+
|
|
396
|
+
You can disable retries entirely, which is useful for testing or specific environments. When disabled, the base model will execute directly without any retry logic.
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
const retryableModel = createRetryable({
|
|
400
|
+
model: openai('gpt-4'), // Base model
|
|
401
|
+
retries: [/* ... */],
|
|
402
|
+
disabled: true, // Retries are completely disabled
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// Or disable based on environment
|
|
406
|
+
const retryableModel = createRetryable({
|
|
407
|
+
model: openai('gpt-4'), // Base model
|
|
408
|
+
retries: [/* ... */],
|
|
409
|
+
disabled: process.env.NODE_ENV === 'test', // Disable in test environment
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// Or use a function for dynamic control
|
|
413
|
+
const retryableModel = createRetryable({
|
|
414
|
+
model: openai('gpt-4'), // Base model
|
|
415
|
+
retries: [/* ... */],
|
|
416
|
+
disabled: () => !featureFlags.isEnabled('ai-retries'), // Check feature flag
|
|
417
|
+
});
|
|
418
|
+
```
|
|
419
|
+
|
|
394
420
|
#### Retry Delays
|
|
395
421
|
|
|
396
422
|
You can delay retries with an optional exponential backoff. The delay respects abort signals, so requests can still be cancelled during the delay period.
|
|
@@ -548,11 +574,19 @@ Creates a retryable model that works with both language models and embedding mod
|
|
|
548
574
|
interface RetryableModelOptions<MODEL extends LanguageModelV2 | EmbeddingModelV2> {
|
|
549
575
|
model: MODEL;
|
|
550
576
|
retries: Array<Retryable<MODEL> | MODEL>;
|
|
577
|
+
disabled?: boolean | (() => boolean);
|
|
551
578
|
onError?: (context: RetryContext<MODEL>) => void;
|
|
552
579
|
onRetry?: (context: RetryContext<MODEL>) => void;
|
|
553
580
|
}
|
|
554
581
|
```
|
|
555
582
|
|
|
583
|
+
**Options:**
|
|
584
|
+
- `model`: The base model to use for the initial request.
|
|
585
|
+
- `retries`: Array of retryables (functions, models, or retry objects) to attempt on failure.
|
|
586
|
+
- `disabled`: Disable all retry logic. Can be a boolean or function returning boolean. Default: `false` (retries enabled).
|
|
587
|
+
- `onError`: Callback invoked when an error occurs.
|
|
588
|
+
- `onRetry`: Callback invoked before attempting a retry.
|
|
589
|
+
|
|
556
590
|
#### `Retryable`
|
|
557
591
|
|
|
558
592
|
A `Retryable` is a function that receives a `RetryContext` with the current error or result and model and all previous attempts.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as LanguageModelV2Generate, c as Retry, d as RetryErrorAttempt, f as RetryResultAttempt, h as RetryableOptions, i as LanguageModelV2, l as RetryAttempt, m as RetryableModelOptions, n as EmbeddingModelV2CallOptions, o as LanguageModelV2Stream, p as Retryable, r as EmbeddingModelV2Embed, s as Retries, t as EmbeddingModelV2, u as RetryContext } from "./types-
|
|
1
|
+
import { a as LanguageModelV2Generate, c as Retry, d as RetryErrorAttempt, f as RetryResultAttempt, h as RetryableOptions, i as LanguageModelV2, l as RetryAttempt, m as RetryableModelOptions, n as EmbeddingModelV2CallOptions, o as LanguageModelV2Stream, p as Retryable, r as EmbeddingModelV2Embed, s as Retries, t as EmbeddingModelV2, u as RetryContext } from "./types-CphTxZ_b.js";
|
|
2
2
|
import * as _ai_sdk_provider0 from "@ai-sdk/provider";
|
|
3
3
|
import { LanguageModelV2 as LanguageModelV2$1, LanguageModelV2StreamPart } from "@ai-sdk/provider";
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,13 @@ var RetryableEmbeddingModel = class {
|
|
|
105
105
|
this.currentModel = options.model;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
+
* Check if retries are disabled
|
|
109
|
+
*/
|
|
110
|
+
isDisabled() {
|
|
111
|
+
if (this.options.disabled === void 0) return false;
|
|
112
|
+
return typeof this.options.disabled === "function" ? this.options.disabled() : this.options.disabled;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
108
115
|
* Execute a function with retry logic for handling errors
|
|
109
116
|
*/
|
|
110
117
|
async withRetry(input) {
|
|
@@ -197,6 +204,10 @@ var RetryableEmbeddingModel = class {
|
|
|
197
204
|
* Always start with the original model
|
|
198
205
|
*/
|
|
199
206
|
this.currentModel = this.baseModel;
|
|
207
|
+
/**
|
|
208
|
+
* If retries are disabled, bypass retry machinery entirely
|
|
209
|
+
*/
|
|
210
|
+
if (this.isDisabled()) return this.currentModel.doEmbed(options);
|
|
200
211
|
const { result } = await this.withRetry({
|
|
201
212
|
fn: async (currentRetry) => {
|
|
202
213
|
const callOptions = {
|
|
@@ -234,6 +245,13 @@ var RetryableLanguageModel = class {
|
|
|
234
245
|
this.currentModel = options.model;
|
|
235
246
|
}
|
|
236
247
|
/**
|
|
248
|
+
* Check if retries are disabled
|
|
249
|
+
*/
|
|
250
|
+
isDisabled() {
|
|
251
|
+
if (this.options.disabled === void 0) return false;
|
|
252
|
+
return typeof this.options.disabled === "function" ? this.options.disabled() : this.options.disabled;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
237
255
|
* Execute a function with retry logic for handling errors
|
|
238
256
|
*/
|
|
239
257
|
async withRetry(input) {
|
|
@@ -371,6 +389,10 @@ var RetryableLanguageModel = class {
|
|
|
371
389
|
* Always start with the original model
|
|
372
390
|
*/
|
|
373
391
|
this.currentModel = this.baseModel;
|
|
392
|
+
/**
|
|
393
|
+
* If retries are disabled, bypass retry machinery entirely
|
|
394
|
+
*/
|
|
395
|
+
if (this.isDisabled()) return this.currentModel.doGenerate(options);
|
|
374
396
|
const { result } = await this.withRetry({
|
|
375
397
|
fn: async (currentRetry) => {
|
|
376
398
|
const callOptions = {
|
|
@@ -390,6 +412,10 @@ var RetryableLanguageModel = class {
|
|
|
390
412
|
*/
|
|
391
413
|
this.currentModel = this.baseModel;
|
|
392
414
|
/**
|
|
415
|
+
* If retries are disabled, bypass retry machinery entirely
|
|
416
|
+
*/
|
|
417
|
+
if (this.isDisabled()) return this.currentModel.doStream(options);
|
|
418
|
+
/**
|
|
393
419
|
* Perform the initial call to doStream with retry logic to handle errors before any data is streamed.
|
|
394
420
|
*/
|
|
395
421
|
let { result, attempts } = await this.withRetry({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as RetryableOptions, i as LanguageModelV2, p as Retryable, t as EmbeddingModelV2 } from "../types-
|
|
1
|
+
import { h as RetryableOptions, i as LanguageModelV2, p as Retryable, t as EmbeddingModelV2 } from "../types-CphTxZ_b.js";
|
|
2
2
|
|
|
3
3
|
//#region src/retryables/content-filter-triggered.d.ts
|
|
4
4
|
|
|
@@ -9,6 +9,7 @@ type EmbeddingModelV2$1<VALUE = any> = EmbeddingModelV2<VALUE>;
|
|
|
9
9
|
interface RetryableModelOptions<MODEL extends LanguageModelV2$1 | EmbeddingModelV2$1> {
|
|
10
10
|
model: MODEL;
|
|
11
11
|
retries: Retries<MODEL>;
|
|
12
|
+
disabled?: boolean | (() => boolean);
|
|
12
13
|
onError?: (context: RetryContext<MODEL>) => void;
|
|
13
14
|
onRetry?: (context: RetryContext<MODEL>) => void;
|
|
14
15
|
}
|