ai-retry 2.0.0-beta.0 → 2.0.0-beta.2
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 +21 -17
- package/dist/{create-retryable-model-CmfSxgGj.mjs → create-retryable-model-AsDcTL4O.mjs} +2 -2
- package/dist/{create-retryable-model-CHCZ0fQk.mjs → create-retryable-model-Bk2V0Etk.mjs} +2 -2
- package/dist/{create-retryable-model-kbZjWNJ0.mjs → create-retryable-model-BmUUjbnL.mjs} +3 -3
- package/dist/embedding-model/conditions/index.d.mts +2 -2
- package/dist/embedding-model/index.d.mts +2 -2
- package/dist/embedding-model/index.mjs +2 -2
- package/dist/image-model/conditions/index.d.mts +3 -3
- package/dist/image-model/index.d.mts +3 -3
- package/dist/image-model/index.mjs +2 -2
- package/dist/{index-Bo_FxEjD.d.mts → index-BelYKSAb.d.mts} +2 -2
- package/dist/{index-ChhH9SEc.d.mts → index-DEZS_l48.d.mts} +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +4 -4
- package/dist/language-model/conditions/index.d.mts +3 -3
- package/dist/language-model/index.d.mts +3 -3
- package/dist/language-model/index.mjs +2 -2
- package/dist/{or-MbQSVByG.d.mts → or-D5SqlYlL.d.mts} +1 -1
- package/dist/retryables/index.d.mts +1 -1
- package/dist/{telemetry-bNsaXZUI.mjs → telemetry-B9VxnSN2.mjs} +7 -1
- package/dist/{types-BrvhJykE.d.mts → types-CEH_V5nM.d.mts} +18 -10
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -715,11 +715,11 @@ const retryableModel = createRetryableModel({
|
|
|
715
715
|
> [!NOTE]
|
|
716
716
|
> Experimental: span names and attributes may change in patch versions.
|
|
717
717
|
|
|
718
|
-
`ai-retry` can emit [OpenTelemetry](https://opentelemetry.io/) spans for each request and every retry attempt. Spans are created on the active OpenTelemetry context, so they nest automatically under the AI SDK's own spans (e.g. `ai.generateText.doGenerate`) when
|
|
718
|
+
`ai-retry` can emit [OpenTelemetry](https://opentelemetry.io/) spans for each request and every retry attempt. Spans are created on the active OpenTelemetry context, so they nest automatically under the AI SDK's own spans (e.g. `ai.generateText.doGenerate`) when that integration is active — in AI SDK v7 that means installing [`@ai-sdk/otel`](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) and registering it with `registerTelemetry(new OpenTelemetry())`. A single trace then shows the individual attempts — which model each used, why it was retried, and the backoff between them — that the SDK's own span otherwise hides. Retry telemetry works on its own too: it talks to OpenTelemetry directly, so it does not require `@ai-sdk/otel`.
|
|
719
719
|
|
|
720
720
|
#### Setup
|
|
721
721
|
|
|
722
|
-
Telemetry uses the optional peer dependency `@opentelemetry/api` (
|
|
722
|
+
Telemetry uses the optional peer dependency `@opentelemetry/api`. In AI SDK v7 it is no longer a transitive dependency of `ai`, so install `@ai-sdk/otel` (which brings it in) or `@opentelemetry/api` directly. Register an OpenTelemetry SDK once at startup, then opt in per model:
|
|
723
723
|
|
|
724
724
|
```typescript
|
|
725
725
|
import { createRetryableModel } from 'ai-retry/language-model';
|
|
@@ -727,17 +727,19 @@ import { createRetryableModel } from 'ai-retry/language-model';
|
|
|
727
727
|
const retryableModel = createRetryableModel({
|
|
728
728
|
model: openai('gpt-4o'),
|
|
729
729
|
retries: [anthropic('claude-sonnet-4-5')],
|
|
730
|
-
|
|
730
|
+
telemetry: { isEnabled: true },
|
|
731
731
|
});
|
|
732
732
|
```
|
|
733
733
|
|
|
734
|
-
|
|
734
|
+
> [!NOTE]
|
|
735
|
+
> `telemetry` replaces the now-deprecated `experimental_telemetry` option. The old name still works as an alias; when both are set, `telemetry` wins.
|
|
736
|
+
|
|
737
|
+
The settings resemble the AI SDK's `telemetry` shape, but stay opt-in and keep a `tracer` field (which the AI SDK moved into `@ai-sdk/otel`):
|
|
735
738
|
|
|
736
739
|
```ts
|
|
737
740
|
interface RetryTelemetrySettings {
|
|
738
741
|
isEnabled?: boolean; // off by default while experimental
|
|
739
742
|
tracer?: Tracer; // defaults to trace.getTracer('ai-retry')
|
|
740
|
-
functionId?: string; // groups telemetry by function
|
|
741
743
|
metadata?: Record<string, AttributeValue>;
|
|
742
744
|
}
|
|
743
745
|
```
|
|
@@ -767,7 +769,7 @@ ai_retry.doGenerate outcome=success, attempts=2
|
|
|
767
769
|
| `ai_retry.model.start` | the model the request started with (`provider/modelId`) |
|
|
768
770
|
| `ai_retry.model.final` | the model that produced the final outcome |
|
|
769
771
|
| `ai_retry.error.{name,message,status,cause.name,cause.message,cause.status}` | the failing error (on failure); `status` when it carries an HTTP status code |
|
|
770
|
-
| `ai_retry.
|
|
772
|
+
| `ai_retry.metadata.*` | from the telemetry settings `metadata` |
|
|
771
773
|
|
|
772
774
|
**Attempt span** (`ai_retry.attempt`) attributes:
|
|
773
775
|
|
|
@@ -812,16 +814,16 @@ The function-style helpers (`contentFilterTriggered`, `requestTimeout`, `request
|
|
|
812
814
|
|
|
813
815
|
Each function-style retryable has a one-line equivalent in the new shape (imports from `ai-retry/language-model` unless noted):
|
|
814
816
|
|
|
815
|
-
| Function-style (deprecated) | Condition API
|
|
816
|
-
| ------------------------------------------- |
|
|
817
|
-
| `contentFilterTriggered(m)` | `finishReason('content-filter').switch({ model: m })`
|
|
818
|
-
| `requestTimeout(m)` | `timeout().switch({ model: m, timeout: 60_000 })`
|
|
819
|
-
| `requestNotRetryable(m)` | `error.isRetryable(false).switch({ model: m })`
|
|
820
|
-
| `schemaMismatch(m)` | `schemaInvalid().switch({ model: m })`
|
|
821
|
-
| `serviceOverloaded(m)` | `httpStatus(529).switch({ model: m })`
|
|
822
|
-
| `serviceUnavailable(m)` | `httpStatus(503).switch({ model: m })`
|
|
823
|
-
| `noImageGenerated(m)` | `noImage().switch({ model: m })` (from `ai-retry/image-model`)
|
|
824
|
-
| `retryAfterDelay({ delay, backoffFactor })` | `error.isRetryable(true).retry({ delay, backoffFactor })`
|
|
817
|
+
| Function-style (deprecated) | Condition API |
|
|
818
|
+
| ------------------------------------------- | -------------------------------------------------------------- |
|
|
819
|
+
| `contentFilterTriggered(m)` | `finishReason('content-filter').switch({ model: m })` |
|
|
820
|
+
| `requestTimeout(m)` | `timeout().switch({ model: m, timeout: 60_000 })` |
|
|
821
|
+
| `requestNotRetryable(m)` | `error.isRetryable(false).switch({ model: m })` |
|
|
822
|
+
| `schemaMismatch(m)` | `schemaInvalid().switch({ model: m })` |
|
|
823
|
+
| `serviceOverloaded(m)` | `httpStatus(529).switch({ model: m })` |
|
|
824
|
+
| `serviceUnavailable(m)` | `httpStatus(503).switch({ model: m })` |
|
|
825
|
+
| `noImageGenerated(m)` | `noImage().switch({ model: m })` (from `ai-retry/image-model`) |
|
|
826
|
+
| `retryAfterDelay({ delay, backoffFactor })` | `error.isRetryable(true).retry({ delay, backoffFactor })` |
|
|
825
827
|
|
|
826
828
|
#### Preamble buffering
|
|
827
829
|
|
|
@@ -844,6 +846,8 @@ interface RetryableModelOptions<
|
|
|
844
846
|
retries: Array<Retryable<MODEL> | MODEL>;
|
|
845
847
|
disabled?: boolean | (() => boolean);
|
|
846
848
|
reset?: Reset;
|
|
849
|
+
telemetry?: RetryTelemetrySettings;
|
|
850
|
+
/** @deprecated use `telemetry` */
|
|
847
851
|
experimental_telemetry?: RetryTelemetrySettings;
|
|
848
852
|
onError?: (context: RetryContext<MODEL>) => void;
|
|
849
853
|
onRetry?: (
|
|
@@ -860,7 +864,7 @@ interface RetryableModelOptions<
|
|
|
860
864
|
- `retries` — array of conditions (`.switch(...)` / `.retry(...)` outputs), models, or retry objects to try on failure.
|
|
861
865
|
- `disabled` — disable all retry logic. `boolean` or `() => boolean`. Default `false`.
|
|
862
866
|
- `reset` — controls when to reset back to the base model after a successful retry. Default `'after-request'`.
|
|
863
|
-
- `
|
|
867
|
+
- `telemetry` — OpenTelemetry instrumentation. See [Telemetry](#telemetry). (`experimental_telemetry` is a deprecated alias.)
|
|
864
868
|
- `onError` — fires when an error occurs.
|
|
865
869
|
- `onRetry` — fires before a retry attempt. May return `OnRetryOverrides` (or a promise of one) to override `options.*` for that attempt only. See [Dynamic call options](#dynamic-call-options).
|
|
866
870
|
- `onSuccess` — fires after a successful request.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as prepareRetryError, c as resolveImageModel, f as calculateExponentialBackoff, o as findRetryModel, p as BaseRetryableModel, r as mergeImageModelCallOptions, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-
|
|
1
|
+
import { a as prepareRetryError, c as resolveImageModel, f as calculateExponentialBackoff, o as findRetryModel, p as BaseRetryableModel, r as mergeImageModelCallOptions, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-B9VxnSN2.mjs";
|
|
2
2
|
import { o as isModel } from "./guards-CKn5dl__.mjs";
|
|
3
3
|
import { delay } from "@ai-sdk/provider-utils";
|
|
4
4
|
|
|
@@ -180,7 +180,7 @@ var RetryableImageModel = class extends BaseRetryableModel {
|
|
|
180
180
|
* If retries are disabled, bypass retry machinery entirely
|
|
181
181
|
*/
|
|
182
182
|
if (this.isDisabled()) return this.currentModel.doGenerate(callOptions);
|
|
183
|
-
const recorder = await createRetryTelemetry(this.
|
|
183
|
+
const recorder = await createRetryTelemetry(this.telemetrySettings, {
|
|
184
184
|
operation: "doGenerate",
|
|
185
185
|
genAiOperation: "generate_content",
|
|
186
186
|
provider: startModel.provider,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as prepareRetryError, f as calculateExponentialBackoff, n as mergeEmbeddingModelCallOptions, o as findRetryModel, p as BaseRetryableModel, s as resolveEmbeddingModel, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-
|
|
1
|
+
import { a as prepareRetryError, f as calculateExponentialBackoff, n as mergeEmbeddingModelCallOptions, o as findRetryModel, p as BaseRetryableModel, s as resolveEmbeddingModel, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-B9VxnSN2.mjs";
|
|
2
2
|
import { o as isModel } from "./guards-CKn5dl__.mjs";
|
|
3
3
|
import { delay } from "@ai-sdk/provider-utils";
|
|
4
4
|
|
|
@@ -183,7 +183,7 @@ var RetryableEmbeddingModel = class extends BaseRetryableModel {
|
|
|
183
183
|
* If retries are disabled, bypass retry machinery entirely
|
|
184
184
|
*/
|
|
185
185
|
if (this.isDisabled()) return this.currentModel.doEmbed(callOptions);
|
|
186
|
-
const recorder = await createRetryTelemetry(this.
|
|
186
|
+
const recorder = await createRetryTelemetry(this.telemetrySettings, {
|
|
187
187
|
operation: "doEmbed",
|
|
188
188
|
genAiOperation: "embeddings",
|
|
189
189
|
provider: startModel.provider,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as prepareRetryError, f as calculateExponentialBackoff, i as mergeLanguageModelCallOptions, l as resolveLanguageModel, o as findRetryModel, p as BaseRetryableModel, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-
|
|
1
|
+
import { a as prepareRetryError, f as calculateExponentialBackoff, i as mergeLanguageModelCallOptions, l as resolveLanguageModel, o as findRetryModel, p as BaseRetryableModel, t as createRetryTelemetry, u as countModelAttempts } from "./telemetry-B9VxnSN2.mjs";
|
|
2
2
|
import { i as isGenerateResult, l as isStreamContentPart, o as isModel, r as isErrorAttempt } from "./guards-CKn5dl__.mjs";
|
|
3
3
|
import { delay } from "@ai-sdk/provider-utils";
|
|
4
4
|
|
|
@@ -242,7 +242,7 @@ var RetryableLanguageModel = class extends BaseRetryableModel {
|
|
|
242
242
|
* If retries are disabled, bypass retry machinery entirely
|
|
243
243
|
*/
|
|
244
244
|
if (this.isDisabled()) return this.currentModel.doGenerate(callOptions);
|
|
245
|
-
const recorder = await createRetryTelemetry(this.
|
|
245
|
+
const recorder = await createRetryTelemetry(this.telemetrySettings, {
|
|
246
246
|
operation: "doGenerate",
|
|
247
247
|
genAiOperation: "chat",
|
|
248
248
|
provider: startModel.provider,
|
|
@@ -296,7 +296,7 @@ var RetryableLanguageModel = class extends BaseRetryableModel {
|
|
|
296
296
|
* If retries are disabled, bypass retry machinery entirely
|
|
297
297
|
*/
|
|
298
298
|
if (this.isDisabled()) return this.currentModel.doStream(callOptions);
|
|
299
|
-
const recorder = await createRetryTelemetry(this.
|
|
299
|
+
const recorder = await createRetryTelemetry(this.telemetrySettings, {
|
|
300
300
|
operation: "doStream",
|
|
301
301
|
genAiOperation: "chat",
|
|
302
302
|
provider: startModel.provider,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as RetryContext, T as ResolvableEmbeddingModel } from "../../types-
|
|
2
|
-
import { a as Condition, i as StatusPattern, n as not, r as and, t as or } from "../../or-
|
|
1
|
+
import { F as RetryContext, T as ResolvableEmbeddingModel } from "../../types-CEH_V5nM.mjs";
|
|
2
|
+
import { a as Condition, i as StatusPattern, n as not, r as and, t as or } from "../../or-D5SqlYlL.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/embedding-model/conditions/index.d.ts
|
|
5
5
|
declare const error: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as RetryableModelOptions, T as ResolvableEmbeddingModel, r as EmbeddingModel } from "../types-
|
|
2
|
-
import { n as not, r as and, t as or } from "../or-
|
|
1
|
+
import { B as RetryableModelOptions, T as ResolvableEmbeddingModel, r as EmbeddingModel } from "../types-CEH_V5nM.mjs";
|
|
2
|
+
import { n as not, r as and, t as or } from "../or-D5SqlYlL.mjs";
|
|
3
3
|
import { aborted, error, httpStatus, timeout } from "./conditions/index.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/embedding-model/create-retryable-model.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../telemetry-
|
|
2
|
-
import { t as createRetryableModel } from "../create-retryable-model-
|
|
1
|
+
import "../telemetry-B9VxnSN2.mjs";
|
|
2
|
+
import { t as createRetryableModel } from "../create-retryable-model-Bk2V0Etk.mjs";
|
|
3
3
|
import { i as or, n as and, t as not } from "../not-6hBRaJRl.mjs";
|
|
4
4
|
import { aborted, error, httpStatus, timeout } from "./conditions/index.mjs";
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { n as not, r as and, t as or } from "../../or-
|
|
3
|
-
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../index-
|
|
1
|
+
import "../../types-CEH_V5nM.mjs";
|
|
2
|
+
import { n as not, r as and, t as or } from "../../or-D5SqlYlL.mjs";
|
|
3
|
+
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../index-DEZS_l48.mjs";
|
|
4
4
|
export { aborted, and, error, httpStatus, noImage, not, or, timeout };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { B as RetryableModelOptions, E as ResolvableImageModel, d as ImageModel } from "../types-
|
|
2
|
-
import { n as not, r as and, t as or } from "../or-
|
|
3
|
-
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../index-
|
|
1
|
+
import { B as RetryableModelOptions, E as ResolvableImageModel, d as ImageModel } from "../types-CEH_V5nM.mjs";
|
|
2
|
+
import { n as not, r as and, t as or } from "../or-D5SqlYlL.mjs";
|
|
3
|
+
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../index-DEZS_l48.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/image-model/create-retryable-model.d.ts
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../telemetry-
|
|
2
|
-
import { t as createRetryableModel } from "../create-retryable-model-
|
|
1
|
+
import "../telemetry-B9VxnSN2.mjs";
|
|
2
|
+
import { t as createRetryableModel } from "../create-retryable-model-AsDcTL4O.mjs";
|
|
3
3
|
import { i as or, n as and, t as not } from "../not-6hBRaJRl.mjs";
|
|
4
4
|
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../conditions-CfeJD4K4.mjs";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as ResolvableLanguageModel, F as RetryContext, v as LanguageModelResult } from "./types-
|
|
2
|
-
import { a as Condition, i as StatusPattern } from "./or-
|
|
1
|
+
import { D as ResolvableLanguageModel, F as RetryContext, v as LanguageModelResult } from "./types-CEH_V5nM.mjs";
|
|
2
|
+
import { a as Condition, i as StatusPattern } from "./or-D5SqlYlL.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/conditions/result.d.ts
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as ResolvableImageModel, F as RetryContext } from "./types-
|
|
2
|
-
import { a as Condition, i as StatusPattern } from "./or-
|
|
1
|
+
import { E as ResolvableImageModel, F as RetryContext } from "./types-CEH_V5nM.mjs";
|
|
2
|
+
import { a as Condition, i as StatusPattern } from "./or-D5SqlYlL.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/conditions/no-image.d.ts
|
|
5
5
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Result, B as RetryableModelOptions, C as ProviderOptions, D as ResolvableLanguageModel, E as ResolvableImageModel, F as RetryContext, H as SuccessAttempt, I as RetryErrorAttempt, L as RetryResultAttempt, M as Retry, N as RetryAttempt, O as ResolvableModel, P as RetryCallOptions, R as RetryTelemetrySettings, S as OnRetryOverrides, T as ResolvableEmbeddingModel, U as SuccessContext, V as RetryableOptions, _ as LanguageModelGenerate, a as EmbeddingModelEmbed, b as LanguageModelStream, c as GatewayEmbeddingModelId, d as ImageModel, f as ImageModelCallOptions, g as LanguageModelCallOptions, h as LanguageModel, i as EmbeddingModelCallOptions, j as Retries, k as ResolvedModel, l as GatewayImageModelId, m as ImageModelRetryCallOptions, n as CallOptions, o as EmbeddingModelRetryCallOptions, p as ImageModelGenerate, r as EmbeddingModel, s as FailureContext, t as AnyResolvableModel, u as GatewayLanguageModelId, v as LanguageModelResult, w as Reset, x as LanguageModelStreamPart, y as LanguageModelRetryCallOptions, z as Retryable } from "./types-
|
|
1
|
+
import { A as Result, B as RetryableModelOptions, C as ProviderOptions, D as ResolvableLanguageModel, E as ResolvableImageModel, F as RetryContext, H as SuccessAttempt, I as RetryErrorAttempt, L as RetryResultAttempt, M as Retry, N as RetryAttempt, O as ResolvableModel, P as RetryCallOptions, R as RetryTelemetrySettings, S as OnRetryOverrides, T as ResolvableEmbeddingModel, U as SuccessContext, V as RetryableOptions, _ as LanguageModelGenerate, a as EmbeddingModelEmbed, b as LanguageModelStream, c as GatewayEmbeddingModelId, d as ImageModel, f as ImageModelCallOptions, g as LanguageModelCallOptions, h as LanguageModel, i as EmbeddingModelCallOptions, j as Retries, k as ResolvedModel, l as GatewayImageModelId, m as ImageModelRetryCallOptions, n as CallOptions, o as EmbeddingModelRetryCallOptions, p as ImageModelGenerate, r as EmbeddingModel, s as FailureContext, t as AnyResolvableModel, u as GatewayLanguageModelId, v as LanguageModelResult, w as Reset, x as LanguageModelStreamPart, y as LanguageModelRetryCallOptions, z as Retryable } from "./types-CEH_V5nM.mjs";
|
|
2
2
|
import "@ai-sdk/provider";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/create-retryable-model.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { d as getModelKey, l as resolveLanguageModel } from "./telemetry-
|
|
1
|
+
import { d as getModelKey, l as resolveLanguageModel } from "./telemetry-B9VxnSN2.mjs";
|
|
2
2
|
import { a as isImageModel, c as isResultAttempt, n as isEmbeddingModel, o as isModel, r as isErrorAttempt } from "./guards-CKn5dl__.mjs";
|
|
3
|
-
import { t as createRetryableModel$1 } from "./create-retryable-model-
|
|
4
|
-
import { t as createRetryableModel$2 } from "./create-retryable-model-
|
|
5
|
-
import { t as createRetryableModel$3 } from "./create-retryable-model-
|
|
3
|
+
import { t as createRetryableModel$1 } from "./create-retryable-model-Bk2V0Etk.mjs";
|
|
4
|
+
import { t as createRetryableModel$2 } from "./create-retryable-model-AsDcTL4O.mjs";
|
|
5
|
+
import { t as createRetryableModel$3 } from "./create-retryable-model-BmUUjbnL.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/internal/create-retryable-model.ts
|
|
8
8
|
function createRetryableModel(options) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { n as not, r as and, t as or } from "../../or-
|
|
3
|
-
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../../index-
|
|
1
|
+
import "../../types-CEH_V5nM.mjs";
|
|
2
|
+
import { n as not, r as and, t as or } from "../../or-D5SqlYlL.mjs";
|
|
3
|
+
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../../index-BelYKSAb.mjs";
|
|
4
4
|
export { aborted, and, error, finishReason, httpStatus, not, or, result, schemaInvalid, timeout };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { B as RetryableModelOptions, D as ResolvableLanguageModel, h as LanguageModel } from "../types-
|
|
2
|
-
import { n as not, r as and, t as or } from "../or-
|
|
3
|
-
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../index-
|
|
1
|
+
import { B as RetryableModelOptions, D as ResolvableLanguageModel, h as LanguageModel } from "../types-CEH_V5nM.mjs";
|
|
2
|
+
import { n as not, r as and, t as or } from "../or-D5SqlYlL.mjs";
|
|
3
|
+
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../index-BelYKSAb.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/language-model/create-retryable-model.d.ts
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../telemetry-
|
|
2
|
-
import { t as createRetryableModel } from "../create-retryable-model-
|
|
1
|
+
import "../telemetry-B9VxnSN2.mjs";
|
|
2
|
+
import { t as createRetryableModel } from "../create-retryable-model-BmUUjbnL.mjs";
|
|
3
3
|
import { i as or, n as and, t as not } from "../not-6hBRaJRl.mjs";
|
|
4
4
|
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../conditions-DAetW5_1.mjs";
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as RetryContext, M as Retry, t as AnyResolvableModel, z as Retryable } from "./types-
|
|
1
|
+
import { F as RetryContext, M as Retry, t as AnyResolvableModel, z as Retryable } from "./types-CEH_V5nM.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/internal/conditions/condition.d.ts
|
|
4
4
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as ResolvableLanguageModel, E as ResolvableImageModel, V as RetryableOptions, t as AnyResolvableModel, z as Retryable } from "../types-
|
|
1
|
+
import { D as ResolvableLanguageModel, E as ResolvableImageModel, V as RetryableOptions, t as AnyResolvableModel, z as Retryable } from "../types-CEH_V5nM.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/retryables/content-filter-triggered.d.ts
|
|
4
4
|
/**
|
|
@@ -73,6 +73,13 @@ var BaseRetryableModel = class {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
+
* Resolve the telemetry settings, preferring `telemetry` over the deprecated
|
|
77
|
+
* `experimental_telemetry` alias.
|
|
78
|
+
*/
|
|
79
|
+
get telemetrySettings() {
|
|
80
|
+
return this.options.telemetry ?? this.options.experimental_telemetry;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
76
83
|
* Check if retries are disabled
|
|
77
84
|
*/
|
|
78
85
|
isDisabled() {
|
|
@@ -358,7 +365,6 @@ var OpenTelemetrySink = class {
|
|
|
358
365
|
"ai_retry.model.start": `${info.provider}/${info.modelId}`,
|
|
359
366
|
"gen_ai.operation.name": info.genAiOperation
|
|
360
367
|
};
|
|
361
|
-
if (this.#settings.functionId !== void 0) attributes["ai_retry.function.id"] = this.#settings.functionId;
|
|
362
368
|
if (this.#settings.metadata) for (const [key, value] of Object.entries(this.#settings.metadata)) attributes[`ai_retry.metadata.${key}`] = value;
|
|
363
369
|
this.#operationSpan = this.#tracer.startSpan(`ai_retry.${info.operation}`, { attributes }, context.active());
|
|
364
370
|
this.#operationContext = trace.setSpan(context.active(), this.#operationSpan);
|
|
@@ -149,13 +149,20 @@ type FailureContext<MODEL extends ResolvableLanguageModel | EmbeddingModel | Ima
|
|
|
149
149
|
/**
|
|
150
150
|
* Telemetry configuration for retry instrumentation.
|
|
151
151
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
152
|
+
* Talks to OpenTelemetry directly and independently of the AI SDK: when
|
|
153
|
+
* enabled, each request emits a span for the operation with a child span per
|
|
154
|
+
* attempt. Spans created here nest under any active span (e.g. the AI SDK's
|
|
155
|
+
* `ai.generateText.doGenerate`, when that integration is registered) via
|
|
156
|
+
* OpenTelemetry context propagation.
|
|
157
157
|
*
|
|
158
|
-
*
|
|
158
|
+
* The shape resembles the AI SDK's `telemetry` settings but is opt-in and
|
|
159
|
+
* deliberately keeps a `tracer` field (which the AI SDK moved to its
|
|
160
|
+
* `@ai-sdk/otel` integration), so retry spans work without adopting that
|
|
161
|
+
* integration.
|
|
162
|
+
*
|
|
163
|
+
* Requires the optional peer dependency `@opentelemetry/api` to be installed
|
|
164
|
+
* (in AI SDK v7 it is no longer a transitive dependency of `ai`; install
|
|
165
|
+
* `@ai-sdk/otel` or `@opentelemetry/api` directly).
|
|
159
166
|
*/
|
|
160
167
|
interface RetryTelemetrySettings {
|
|
161
168
|
/**
|
|
@@ -168,10 +175,6 @@ interface RetryTelemetrySettings {
|
|
|
168
175
|
* OpenTelemetry SDK is registered.
|
|
169
176
|
*/
|
|
170
177
|
tracer?: Tracer;
|
|
171
|
-
/**
|
|
172
|
-
* Identifier for this function. Used to group telemetry data by function.
|
|
173
|
-
*/
|
|
174
|
-
functionId?: string;
|
|
175
178
|
/**
|
|
176
179
|
* Additional information to include in the telemetry data. Recorded on the
|
|
177
180
|
* operation span as `ai_retry.metadata.<key>` attributes.
|
|
@@ -197,6 +200,11 @@ interface RetryableModelOptions<MODEL extends LanguageModel | EmbeddingModel | I
|
|
|
197
200
|
* Telemetry configuration. When enabled, emits OpenTelemetry spans for
|
|
198
201
|
* retry operations and attempts. Requires `@opentelemetry/api`.
|
|
199
202
|
*/
|
|
203
|
+
telemetry?: RetryTelemetrySettings;
|
|
204
|
+
/**
|
|
205
|
+
* @deprecated Use `telemetry` instead. Kept as an alias for compatibility;
|
|
206
|
+
* when both are set, `telemetry` takes precedence.
|
|
207
|
+
*/
|
|
200
208
|
experimental_telemetry?: RetryTelemetrySettings;
|
|
201
209
|
onError?: (context: RetryContext<MODEL>) => void;
|
|
202
210
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-retry",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Retry and fallback mechanisms for AI SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -40,12 +40,14 @@
|
|
|
40
40
|
"@ai-sdk/google": "4.0.0-beta.82",
|
|
41
41
|
"@ai-sdk/groq": "4.0.0-beta.54",
|
|
42
42
|
"@ai-sdk/openai": "4.0.0-beta.74",
|
|
43
|
+
"@ai-sdk/otel": "1.0.0-beta.128",
|
|
43
44
|
"@ai-sdk/provider": "4.0.0-beta.19",
|
|
44
45
|
"@ai-sdk/provider-utils": "5.0.0-beta.49",
|
|
45
46
|
"@ai-sdk/test-server": "2.0.0-beta.7",
|
|
46
47
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
47
|
-
"@langfuse/otel": "^5.3
|
|
48
|
-
"@langfuse/tracing": "^5.3
|
|
48
|
+
"@langfuse/otel": "^5.5.3",
|
|
49
|
+
"@langfuse/tracing": "^5.5.3",
|
|
50
|
+
"@langfuse/vercel-ai-sdk": "5.5.0-beta.3",
|
|
49
51
|
"@opentelemetry/api": "1.9.0",
|
|
50
52
|
"@opentelemetry/context-async-hooks": "^2.7.1",
|
|
51
53
|
"@opentelemetry/sdk-node": "^0.218.0",
|