ai-retry 1.7.1 → 1.7.3
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/dist/experimental/embedding-model/retryables/index.d.mts +6 -6
- package/dist/experimental/image-model/index.d.mts +1 -1
- package/dist/experimental/image-model/retryables/index.d.mts +1 -1
- package/dist/experimental/language-model/index.d.mts +1 -1
- package/dist/experimental/language-model/index.mjs +1 -1
- package/dist/experimental/language-model/retryables/index.d.mts +1 -1
- package/dist/experimental/language-model/retryables/index.mjs +1 -1
- package/dist/index-BygX0XfC.d.mts +27 -0
- package/dist/index-Dvxg4bnp.d.mts +30 -0
- package/dist/retryables-DxsSL0_E.mjs +92 -0
- package/package.json +1 -1
- package/dist/index-DfqLMa2f.d.mts +0 -60
- package/dist/index-DmNbfl6t.d.mts +0 -30
- package/dist/retryables-nm5-elvB.mjs +0 -76
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { k as RetryContext } from "../../../types-DYMm5YMu.mjs";
|
|
2
2
|
import { n as Condition, t as StatusPattern } from "../../../error-CPbAtI-h.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _ai_sdk_provider13 from "@ai-sdk/provider";
|
|
4
4
|
|
|
5
5
|
//#region src/experimental/embedding-model/retryables/index.d.ts
|
|
6
6
|
/**
|
|
@@ -11,10 +11,10 @@ import * as _ai_sdk_provider0 from "@ai-sdk/provider";
|
|
|
11
11
|
* from 'ai-retry/experimental/embedding-model/retryables';
|
|
12
12
|
*/
|
|
13
13
|
declare const error: {
|
|
14
|
-
<MODEL extends
|
|
15
|
-
isRetryable<MODEL extends
|
|
16
|
-
statusCode<MODEL extends
|
|
17
|
-
message<MODEL extends
|
|
18
|
-
}, httpStatus: <MODEL extends
|
|
14
|
+
<MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3, E = unknown>(predicate: (err: E, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
15
|
+
isRetryable<MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>(flag?: boolean): Condition<MODEL>;
|
|
16
|
+
statusCode<MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>(...patterns: Array<number | RegExp>): Condition<MODEL>;
|
|
17
|
+
message<MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>(...patterns: Array<string | RegExp>): Condition<MODEL>;
|
|
18
|
+
}, httpStatus: <MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>(...patterns: Array<StatusPattern>) => Condition<MODEL>, timeout: <MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>() => Condition<MODEL>, aborted: <MODEL extends _ai_sdk_provider13.EmbeddingModelV3 = _ai_sdk_provider13.EmbeddingModelV3>() => Condition<MODEL>;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { aborted, error, httpStatus, timeout };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { N as RetryableModelOptions, s as ImageModel } from "../../types-DYMm5YMu.mjs";
|
|
2
2
|
import "../../error-CPbAtI-h.mjs";
|
|
3
|
-
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../index-
|
|
3
|
+
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../index-Dvxg4bnp.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/experimental/image-model/index.d.ts
|
|
6
6
|
declare function createRetryable<MODEL extends ImageModel>(options: RetryableModelOptions<MODEL>): ImageModel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../../../types-DYMm5YMu.mjs";
|
|
2
2
|
import "../../../error-CPbAtI-h.mjs";
|
|
3
|
-
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../../index-
|
|
3
|
+
import { a as noImage, i as timeout, n as error, r as httpStatus, t as aborted } from "../../../index-Dvxg4bnp.mjs";
|
|
4
4
|
export { aborted, error, httpStatus, noImage, timeout };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { N as RetryableModelOptions, d as LanguageModel, o as GatewayLanguageModelId } from "../../types-DYMm5YMu.mjs";
|
|
2
2
|
import "../../error-CPbAtI-h.mjs";
|
|
3
|
-
import { a as
|
|
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-BygX0XfC.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/experimental/language-model/index.d.ts
|
|
6
6
|
declare function createRetryable(options: Omit<RetryableModelOptions<LanguageModel>, 'model'> & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as createRetryable$1 } from "../../create-retryable-model-HLobeUXU.mjs";
|
|
2
2
|
import "../../error-_63RHJTp.mjs";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../../retryables-DxsSL0_E.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/experimental/language-model/index.ts
|
|
6
6
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../../../types-DYMm5YMu.mjs";
|
|
2
2
|
import "../../../error-CPbAtI-h.mjs";
|
|
3
|
-
import { a as
|
|
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-BygX0XfC.mjs";
|
|
4
4
|
export { aborted, error, finishReason, httpStatus, result, schemaInvalid, timeout };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../../../error-_63RHJTp.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as result, i as httpStatus, n as error, o as schemaInvalid, r as finishReason, s as timeout, t as aborted } from "../../../retryables-DxsSL0_E.mjs";
|
|
3
3
|
|
|
4
4
|
export { aborted, error, finishReason, httpStatus, result, schemaInvalid, timeout };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { k as RetryContext, m as LanguageModelResult, x as ResolvableLanguageModel } from "./types-DYMm5YMu.mjs";
|
|
2
|
+
import { n as Condition, t as StatusPattern } from "./error-CPbAtI-h.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/experimental/internal/result.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The unified finish reason produced by the AI SDK.
|
|
7
|
+
*/
|
|
8
|
+
type FinishReason = LanguageModelResult['finishReason']['unified'];
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/experimental/language-model/retryables/index.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Conditions are bound to `ResolvableLanguageModel` (instance or
|
|
13
|
+
* gateway string literal) so `.switch({ model: 'openai/gpt-5' })` is
|
|
14
|
+
* accepted alongside `.switch({ model: openai('gpt-4o') })`.
|
|
15
|
+
*/
|
|
16
|
+
declare const error: {
|
|
17
|
+
<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel, E = unknown>(predicate: (err: E, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
18
|
+
isRetryable<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(flag?: boolean): Condition<MODEL>;
|
|
19
|
+
statusCode<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...patterns: Array<number | RegExp>): Condition<MODEL>;
|
|
20
|
+
message<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...patterns: Array<string | RegExp>): Condition<MODEL>;
|
|
21
|
+
}, httpStatus: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...patterns: Array<StatusPattern>) => Condition<MODEL>, timeout: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>() => Condition<MODEL>, aborted: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>() => Condition<MODEL>;
|
|
22
|
+
declare const result: {
|
|
23
|
+
<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(predicate: (res: LanguageModelResult, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
24
|
+
finishReason<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...reasons: Array<FinishReason>): Condition<MODEL>;
|
|
25
|
+
}, finishReason: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...reasons: Array<FinishReason>) => Condition<MODEL>, schemaInvalid: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>() => Condition<MODEL>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { result as a, httpStatus as i, error as n, schemaInvalid as o, finishReason as r, timeout as s, aborted as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { k as RetryContext, s as ImageModel } from "./types-DYMm5YMu.mjs";
|
|
2
|
+
import { n as Condition, t as StatusPattern } from "./error-CPbAtI-h.mjs";
|
|
3
|
+
import * as _ai_sdk_provider0 from "@ai-sdk/provider";
|
|
4
|
+
|
|
5
|
+
//#region src/experimental/internal/no-image.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Match when image generation produced no images
|
|
8
|
+
* (`NoImageGeneratedError`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* noImage().switch({ model: fallback })
|
|
12
|
+
*/
|
|
13
|
+
declare function noImage<MODEL extends ImageModel = ImageModel>(): Condition<MODEL>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/experimental/image-model/retryables/index.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* Experimental composable conditions bound to `ImageModel`. For use with
|
|
18
|
+
* `generateImage`.
|
|
19
|
+
*
|
|
20
|
+
* import { error, noImage, ... }
|
|
21
|
+
* from 'ai-retry/experimental/image-model/retryables';
|
|
22
|
+
*/
|
|
23
|
+
declare const error: {
|
|
24
|
+
<MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3, E = unknown>(predicate: (err: E, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
25
|
+
isRetryable<MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>(flag?: boolean): Condition<MODEL>;
|
|
26
|
+
statusCode<MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>(...patterns: Array<number | RegExp>): Condition<MODEL>;
|
|
27
|
+
message<MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>(...patterns: Array<string | RegExp>): Condition<MODEL>;
|
|
28
|
+
}, httpStatus: <MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>(...patterns: Array<StatusPattern>) => Condition<MODEL>, timeout: <MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>() => Condition<MODEL>, aborted: <MODEL extends _ai_sdk_provider0.ImageModelV3 = _ai_sdk_provider0.ImageModelV3>() => Condition<MODEL>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { noImage as a, timeout as i, error as n, httpStatus as r, aborted as t };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { s as isResultAttempt } from "./guards-D8UJtxDK.mjs";
|
|
2
|
+
import { n as Condition, t as createErrorAPI } from "./error-_63RHJTp.mjs";
|
|
3
|
+
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
|
4
|
+
import { fromJSONSchema } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/experimental/internal/result.ts
|
|
7
|
+
/**
|
|
8
|
+
* Build the result-side condition helpers (`result`, `finishReason`,
|
|
9
|
+
* `schemaInvalid`) bound to a specific language-model family. Consumed
|
|
10
|
+
* by `language-model/retryables/index.ts` so the entry point exposes
|
|
11
|
+
* helpers whose `MODEL` generic is constrained to the right family.
|
|
12
|
+
*
|
|
13
|
+
* Result-based conditions are language-model only — embedding and image
|
|
14
|
+
* results have a different shape and are not supported.
|
|
15
|
+
*/
|
|
16
|
+
function createResultAPI() {
|
|
17
|
+
/**
|
|
18
|
+
* Build a condition from a predicate over the current generate result.
|
|
19
|
+
* The predicate runs only when the current attempt succeeded; error
|
|
20
|
+
* attempts return false.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* result<MODEL>((res) => res.finishReason.unified === 'length')
|
|
24
|
+
*/
|
|
25
|
+
function result(predicate) {
|
|
26
|
+
return new Condition(async (ctx) => {
|
|
27
|
+
if (!isResultAttempt(ctx.current)) return false;
|
|
28
|
+
return predicate(ctx.current.result, ctx);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Match the result's finish reason against one of the given values.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* result.finishReason('content-filter')
|
|
36
|
+
* result.finishReason('content-filter', 'length')
|
|
37
|
+
*/
|
|
38
|
+
result.finishReason = function finishReason(...reasons) {
|
|
39
|
+
return result((res) => reasons.includes(res.finishReason.unified));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Match the result's finish reason against one of the given values.
|
|
43
|
+
* Thin wrapper around `result.finishReason(...)`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* finishReason('content-filter')
|
|
47
|
+
* finishReason('content-filter', 'length')
|
|
48
|
+
*/
|
|
49
|
+
function finishReason(...reasons) {
|
|
50
|
+
return result.finishReason(...reasons);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Match when the result text fails JSON schema validation. The schema
|
|
54
|
+
* is read from the call's `responseFormat`, which `Output.object()`
|
|
55
|
+
* sets automatically. No-op when no schema is configured.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* schemaInvalid().switch({ model: fallback })
|
|
59
|
+
*/
|
|
60
|
+
function schemaInvalid() {
|
|
61
|
+
return result(async (res, ctx) => {
|
|
62
|
+
if (!isResultAttempt(ctx.current)) return false;
|
|
63
|
+
const callOptions = ctx.current.options;
|
|
64
|
+
const text = res.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
65
|
+
if (!text) return false;
|
|
66
|
+
const responseFormat = callOptions.responseFormat;
|
|
67
|
+
if (responseFormat?.type !== "json" || !responseFormat.schema) return false;
|
|
68
|
+
return !(await safeParseJSON({
|
|
69
|
+
text,
|
|
70
|
+
schema: fromJSONSchema(responseFormat.schema)
|
|
71
|
+
})).success;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
result,
|
|
76
|
+
finishReason,
|
|
77
|
+
schemaInvalid
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/experimental/language-model/retryables/index.ts
|
|
83
|
+
/**
|
|
84
|
+
* Conditions are bound to `ResolvableLanguageModel` (instance or
|
|
85
|
+
* gateway string literal) so `.switch({ model: 'openai/gpt-5' })` is
|
|
86
|
+
* accepted alongside `.switch({ model: openai('gpt-4o') })`.
|
|
87
|
+
*/
|
|
88
|
+
const { error, httpStatus, timeout, aborted } = createErrorAPI();
|
|
89
|
+
const { result, finishReason, schemaInvalid } = createResultAPI();
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { result as a, httpStatus as i, error as n, schemaInvalid as o, finishReason as r, timeout as s, aborted as t };
|
package/package.json
CHANGED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { k as RetryContext, m as LanguageModelResult, x as ResolvableLanguageModel } from "./types-DYMm5YMu.mjs";
|
|
2
|
-
import { n as Condition, t as StatusPattern } from "./error-CPbAtI-h.mjs";
|
|
3
|
-
import * as _ai_sdk_provider13 from "@ai-sdk/provider";
|
|
4
|
-
|
|
5
|
-
//#region src/experimental/internal/result.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Build a condition from a predicate over the current generate result.
|
|
8
|
-
* Available for language models only. The predicate runs only when the
|
|
9
|
-
* current attempt succeeded; error attempts return false.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* result<MODEL>((res) => res.finishReason.unified === 'length')
|
|
13
|
-
*/
|
|
14
|
-
declare function result<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(predicate: (res: LanguageModelResult, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
15
|
-
declare namespace result {
|
|
16
|
-
var finishReason: <MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...reasons: Array<FinishReason>) => Condition<MODEL>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The unified finish reason produced by the AI SDK.
|
|
20
|
-
*/
|
|
21
|
-
type FinishReason = LanguageModelResult['finishReason']['unified'];
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/experimental/internal/finish-reason.d.ts
|
|
24
|
-
/**
|
|
25
|
-
* Match the result's finish reason against one of the given values.
|
|
26
|
-
* Thin wrapper around `result.finishReason(...)`.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* finishReason('content-filter')
|
|
30
|
-
* finishReason('content-filter', 'length')
|
|
31
|
-
*/
|
|
32
|
-
declare function finishReason<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(...reasons: Array<FinishReason>): Condition<MODEL>;
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/experimental/internal/schema-invalid.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* Match when the result text fails JSON schema validation. The schema is
|
|
37
|
-
* read from the call's `responseFormat`, which `Output.object()` sets
|
|
38
|
-
* automatically. No-op when no schema is configured.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* schemaInvalid().switch({ model: fallback })
|
|
42
|
-
*/
|
|
43
|
-
declare function schemaInvalid<MODEL extends ResolvableLanguageModel = ResolvableLanguageModel>(): Condition<MODEL>;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/experimental/language-model/retryables/index.d.ts
|
|
46
|
-
/**
|
|
47
|
-
* Experimental composable conditions bound to `LanguageModel`. For use
|
|
48
|
-
* with `generateText`, `generateObject`, `streamText`, `streamObject`.
|
|
49
|
-
*
|
|
50
|
-
* import { error, httpStatus, finishReason, ... }
|
|
51
|
-
* from 'ai-retry/experimental/language-model/retryables';
|
|
52
|
-
*/
|
|
53
|
-
declare const error: {
|
|
54
|
-
<MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3, E = unknown>(predicate: (err: E, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
55
|
-
isRetryable<MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>(flag?: boolean): Condition<MODEL>;
|
|
56
|
-
statusCode<MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>(...patterns: Array<number | RegExp>): Condition<MODEL>;
|
|
57
|
-
message<MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>(...patterns: Array<string | RegExp>): Condition<MODEL>;
|
|
58
|
-
}, httpStatus: <MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>(...patterns: Array<StatusPattern>) => Condition<MODEL>, timeout: <MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>() => Condition<MODEL>, aborted: <MODEL extends _ai_sdk_provider13.LanguageModelV3 = _ai_sdk_provider13.LanguageModelV3>() => Condition<MODEL>;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { schemaInvalid as a, timeout as i, error as n, finishReason as o, httpStatus as r, result as s, aborted as t };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { k as RetryContext, s as ImageModel } from "./types-DYMm5YMu.mjs";
|
|
2
|
-
import { n as Condition, t as StatusPattern } from "./error-CPbAtI-h.mjs";
|
|
3
|
-
import * as _ai_sdk_provider27 from "@ai-sdk/provider";
|
|
4
|
-
|
|
5
|
-
//#region src/experimental/internal/no-image.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Match when image generation produced no images
|
|
8
|
-
* (`NoImageGeneratedError`).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* noImage().switch({ model: fallback })
|
|
12
|
-
*/
|
|
13
|
-
declare function noImage<MODEL extends ImageModel = ImageModel>(): Condition<MODEL>;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/experimental/image-model/retryables/index.d.ts
|
|
16
|
-
/**
|
|
17
|
-
* Experimental composable conditions bound to `ImageModel`. For use with
|
|
18
|
-
* `generateImage`.
|
|
19
|
-
*
|
|
20
|
-
* import { error, noImage, ... }
|
|
21
|
-
* from 'ai-retry/experimental/image-model/retryables';
|
|
22
|
-
*/
|
|
23
|
-
declare const error: {
|
|
24
|
-
<MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3, E = unknown>(predicate: (err: E, ctx: RetryContext<MODEL>) => boolean | Promise<boolean>): Condition<MODEL>;
|
|
25
|
-
isRetryable<MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>(flag?: boolean): Condition<MODEL>;
|
|
26
|
-
statusCode<MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>(...patterns: Array<number | RegExp>): Condition<MODEL>;
|
|
27
|
-
message<MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>(...patterns: Array<string | RegExp>): Condition<MODEL>;
|
|
28
|
-
}, httpStatus: <MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>(...patterns: Array<StatusPattern>) => Condition<MODEL>, timeout: <MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>() => Condition<MODEL>, aborted: <MODEL extends _ai_sdk_provider27.ImageModelV3 = _ai_sdk_provider27.ImageModelV3>() => Condition<MODEL>;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { noImage as a, timeout as i, error as n, httpStatus as r, aborted as t };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { s as isResultAttempt } from "./guards-D8UJtxDK.mjs";
|
|
2
|
-
import { n as Condition, t as createErrorAPI } from "./error-_63RHJTp.mjs";
|
|
3
|
-
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
|
4
|
-
import { fromJSONSchema } from "zod";
|
|
5
|
-
|
|
6
|
-
//#region src/experimental/internal/result.ts
|
|
7
|
-
/**
|
|
8
|
-
* Build a condition from a predicate over the current generate result.
|
|
9
|
-
* Available for language models only. The predicate runs only when the
|
|
10
|
-
* current attempt succeeded; error attempts return false.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* result<MODEL>((res) => res.finishReason.unified === 'length')
|
|
14
|
-
*/
|
|
15
|
-
function result(predicate) {
|
|
16
|
-
return new Condition(async (ctx) => {
|
|
17
|
-
if (!isResultAttempt(ctx.current)) return false;
|
|
18
|
-
return predicate(ctx.current.result, ctx);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Match the result's finish reason against one of the given values.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* result.finishReason('content-filter')
|
|
26
|
-
* result.finishReason('content-filter', 'length')
|
|
27
|
-
*/
|
|
28
|
-
result.finishReason = function finishReason(...reasons) {
|
|
29
|
-
return result((res) => reasons.includes(res.finishReason.unified));
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/experimental/internal/finish-reason.ts
|
|
34
|
-
/**
|
|
35
|
-
* Match the result's finish reason against one of the given values.
|
|
36
|
-
* Thin wrapper around `result.finishReason(...)`.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* finishReason('content-filter')
|
|
40
|
-
* finishReason('content-filter', 'length')
|
|
41
|
-
*/
|
|
42
|
-
function finishReason(...reasons) {
|
|
43
|
-
return result.finishReason(...reasons);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/experimental/internal/schema-invalid.ts
|
|
48
|
-
/**
|
|
49
|
-
* Match when the result text fails JSON schema validation. The schema is
|
|
50
|
-
* read from the call's `responseFormat`, which `Output.object()` sets
|
|
51
|
-
* automatically. No-op when no schema is configured.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* schemaInvalid().switch({ model: fallback })
|
|
55
|
-
*/
|
|
56
|
-
function schemaInvalid() {
|
|
57
|
-
return result(async (res, ctx) => {
|
|
58
|
-
if (!isResultAttempt(ctx.current)) return false;
|
|
59
|
-
const callOptions = ctx.current.options;
|
|
60
|
-
const text = res.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
61
|
-
if (!text) return false;
|
|
62
|
-
const responseFormat = callOptions.responseFormat;
|
|
63
|
-
if (responseFormat?.type !== "json" || !responseFormat.schema) return false;
|
|
64
|
-
return !(await safeParseJSON({
|
|
65
|
-
text,
|
|
66
|
-
schema: fromJSONSchema(responseFormat.schema)
|
|
67
|
-
})).success;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/experimental/language-model/retryables/index.ts
|
|
73
|
-
const { error, httpStatus, timeout, aborted } = createErrorAPI();
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
export { schemaInvalid as a, timeout as i, error as n, finishReason as o, httpStatus as r, result as s, aborted as t };
|