@ai-sdk/provider 0.0.0 → 0.0.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 +1 -1
- package/dist/index.d.mts +54 -33
- package/dist/index.d.ts +54 -33
- package/dist/index.js +24 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
# Vercel AI SDK - Language Model Specification
|
1
|
+
# Vercel AI SDK - Provider Language Model Specification
|
package/dist/index.d.mts
CHANGED
@@ -4,16 +4,18 @@ declare class APICallError extends Error {
|
|
4
4
|
readonly url: string;
|
5
5
|
readonly requestBodyValues: unknown;
|
6
6
|
readonly statusCode?: number;
|
7
|
+
readonly responseHeaders?: Record<string, string>;
|
7
8
|
readonly responseBody?: string;
|
8
9
|
readonly cause?: unknown;
|
9
10
|
readonly isRetryable: boolean;
|
10
11
|
readonly data?: unknown;
|
11
|
-
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, // server error
|
12
|
+
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable, // server error
|
12
13
|
data, }: {
|
13
14
|
message: string;
|
14
15
|
url: string;
|
15
16
|
requestBodyValues: unknown;
|
16
17
|
statusCode?: number;
|
18
|
+
responseHeaders?: Record<string, string>;
|
17
19
|
responseBody?: string;
|
18
20
|
cause?: unknown;
|
19
21
|
isRetryable?: boolean;
|
@@ -26,6 +28,7 @@ declare class APICallError extends Error {
|
|
26
28
|
url: string;
|
27
29
|
requestBodyValues: unknown;
|
28
30
|
statusCode: number | undefined;
|
31
|
+
responseHeaders: Record<string, string> | undefined;
|
29
32
|
responseBody: string | undefined;
|
30
33
|
cause: unknown;
|
31
34
|
isRetryable: boolean;
|
@@ -33,6 +36,18 @@ declare class APICallError extends Error {
|
|
33
36
|
};
|
34
37
|
}
|
35
38
|
|
39
|
+
declare class EmptyResponseBodyError extends Error {
|
40
|
+
constructor({ message }?: {
|
41
|
+
message?: string;
|
42
|
+
});
|
43
|
+
static isEmptyResponseBodyError(error: unknown): error is EmptyResponseBodyError;
|
44
|
+
toJSON(): {
|
45
|
+
name: string;
|
46
|
+
message: string;
|
47
|
+
stack: string | undefined;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
36
51
|
declare class InvalidArgumentError extends Error {
|
37
52
|
readonly parameter: string;
|
38
53
|
readonly value: unknown;
|
@@ -161,18 +176,6 @@ declare class NoTextGeneratedError extends Error {
|
|
161
176
|
};
|
162
177
|
}
|
163
178
|
|
164
|
-
declare class NoResponseBodyError extends Error {
|
165
|
-
constructor({ message }?: {
|
166
|
-
message?: string;
|
167
|
-
});
|
168
|
-
static isNoResponseBodyError(error: unknown): error is NoResponseBodyError;
|
169
|
-
toJSON(): {
|
170
|
-
name: string;
|
171
|
-
message: string;
|
172
|
-
stack: string | undefined;
|
173
|
-
};
|
174
|
-
}
|
175
|
-
|
176
179
|
declare class NoSuchToolError extends Error {
|
177
180
|
readonly toolName: string;
|
178
181
|
readonly availableTools: string[] | undefined;
|
@@ -307,23 +310,13 @@ type LanguageModelV1CallSettings = {
|
|
307
310
|
*/
|
308
311
|
maxTokens?: number;
|
309
312
|
/**
|
310
|
-
* Temperature setting.
|
311
|
-
* 1 (very random).
|
313
|
+
* Temperature setting.
|
312
314
|
*
|
313
|
-
*
|
314
|
-
* scales, so they'd need to map it (without mapping, the same temperature has
|
315
|
-
* different effects on different models). The provider can also chose to map
|
316
|
-
* this to topP, potentially even using a custom setting on their model.
|
317
|
-
*
|
318
|
-
* Note: This is an example of a setting that requires a clear specification of
|
319
|
-
* the semantics.
|
315
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
320
316
|
*/
|
321
317
|
temperature?: number;
|
322
318
|
/**
|
323
|
-
* Nucleus sampling.
|
324
|
-
*
|
325
|
-
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
326
|
-
* are considered.
|
319
|
+
* Nucleus sampling.
|
327
320
|
*
|
328
321
|
* It is recommended to set either `temperature` or `topP`, but not both.
|
329
322
|
*/
|
@@ -331,17 +324,11 @@ type LanguageModelV1CallSettings = {
|
|
331
324
|
/**
|
332
325
|
* Presence penalty setting. It affects the likelihood of the model to
|
333
326
|
* repeat information that is already in the prompt.
|
334
|
-
*
|
335
|
-
* The presence penalty is a number between -1 (increase repetition)
|
336
|
-
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
337
327
|
*/
|
338
328
|
presencePenalty?: number;
|
339
329
|
/**
|
340
330
|
* Frequency penalty setting. It affects the likelihood of the model
|
341
331
|
* to repeatedly use the same words or phrases.
|
342
|
-
*
|
343
|
-
* The frequency penalty is a number between -1 (increase repetition)
|
344
|
-
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
345
332
|
*/
|
346
333
|
frequencyPenalty?: number;
|
347
334
|
/**
|
@@ -507,6 +494,15 @@ type LanguageModelV1FunctionToolCall = {
|
|
507
494
|
args: string;
|
508
495
|
};
|
509
496
|
|
497
|
+
type LanguageModelV1LogProbs = Array<{
|
498
|
+
token: string;
|
499
|
+
logprob: number;
|
500
|
+
topLogprobs: Array<{
|
501
|
+
token: string;
|
502
|
+
logprob: number;
|
503
|
+
}>;
|
504
|
+
}>;
|
505
|
+
|
510
506
|
/**
|
511
507
|
* Experimental: Specification for a language model that implements the language model
|
512
508
|
* interface version 1.
|
@@ -580,7 +576,21 @@ type LanguageModelV1 = {
|
|
580
576
|
*/
|
581
577
|
rawSettings: Record<string, unknown>;
|
582
578
|
};
|
579
|
+
/**
|
580
|
+
* Optional raw response information for debugging purposes.
|
581
|
+
*/
|
582
|
+
rawResponse?: {
|
583
|
+
/**
|
584
|
+
* Response headers.
|
585
|
+
*/
|
586
|
+
headers?: Record<string, string>;
|
587
|
+
};
|
583
588
|
warnings?: LanguageModelV1CallWarning[];
|
589
|
+
/**
|
590
|
+
* Logprobs for the completion.
|
591
|
+
* `undefined` if the mode does not support logprobs or if was not enabled
|
592
|
+
*/
|
593
|
+
logprobs?: LanguageModelV1LogProbs;
|
584
594
|
}>;
|
585
595
|
/**
|
586
596
|
* Generates a language model output (streaming).
|
@@ -607,6 +617,15 @@ type LanguageModelV1 = {
|
|
607
617
|
*/
|
608
618
|
rawSettings: Record<string, unknown>;
|
609
619
|
};
|
620
|
+
/**
|
621
|
+
* Optional raw response data.
|
622
|
+
*/
|
623
|
+
rawResponse?: {
|
624
|
+
/**
|
625
|
+
* Response headers.
|
626
|
+
*/
|
627
|
+
headers?: Record<string, string>;
|
628
|
+
};
|
610
629
|
warnings?: LanguageModelV1CallWarning[];
|
611
630
|
}>;
|
612
631
|
};
|
@@ -624,6 +643,7 @@ type LanguageModelV1StreamPart = {
|
|
624
643
|
} | {
|
625
644
|
type: 'finish';
|
626
645
|
finishReason: LanguageModelV1FinishReason;
|
646
|
+
logprobs?: LanguageModelV1LogProbs;
|
627
647
|
usage: {
|
628
648
|
promptTokens: number;
|
629
649
|
completionTokens: number;
|
@@ -632,5 +652,6 @@ type LanguageModelV1StreamPart = {
|
|
632
652
|
type: 'error';
|
633
653
|
error: unknown;
|
634
654
|
};
|
655
|
+
type LanguageModelV1ResponseMetadata = {};
|
635
656
|
|
636
|
-
export { APICallError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError,
|
657
|
+
export { APICallError, EmptyResponseBodyError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ResponseMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError, NoSuchToolError, NoTextGeneratedError, RetryError, type RetryErrorReason, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError };
|
package/dist/index.d.ts
CHANGED
@@ -4,16 +4,18 @@ declare class APICallError extends Error {
|
|
4
4
|
readonly url: string;
|
5
5
|
readonly requestBodyValues: unknown;
|
6
6
|
readonly statusCode?: number;
|
7
|
+
readonly responseHeaders?: Record<string, string>;
|
7
8
|
readonly responseBody?: string;
|
8
9
|
readonly cause?: unknown;
|
9
10
|
readonly isRetryable: boolean;
|
10
11
|
readonly data?: unknown;
|
11
|
-
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, // server error
|
12
|
+
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable, // server error
|
12
13
|
data, }: {
|
13
14
|
message: string;
|
14
15
|
url: string;
|
15
16
|
requestBodyValues: unknown;
|
16
17
|
statusCode?: number;
|
18
|
+
responseHeaders?: Record<string, string>;
|
17
19
|
responseBody?: string;
|
18
20
|
cause?: unknown;
|
19
21
|
isRetryable?: boolean;
|
@@ -26,6 +28,7 @@ declare class APICallError extends Error {
|
|
26
28
|
url: string;
|
27
29
|
requestBodyValues: unknown;
|
28
30
|
statusCode: number | undefined;
|
31
|
+
responseHeaders: Record<string, string> | undefined;
|
29
32
|
responseBody: string | undefined;
|
30
33
|
cause: unknown;
|
31
34
|
isRetryable: boolean;
|
@@ -33,6 +36,18 @@ declare class APICallError extends Error {
|
|
33
36
|
};
|
34
37
|
}
|
35
38
|
|
39
|
+
declare class EmptyResponseBodyError extends Error {
|
40
|
+
constructor({ message }?: {
|
41
|
+
message?: string;
|
42
|
+
});
|
43
|
+
static isEmptyResponseBodyError(error: unknown): error is EmptyResponseBodyError;
|
44
|
+
toJSON(): {
|
45
|
+
name: string;
|
46
|
+
message: string;
|
47
|
+
stack: string | undefined;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
36
51
|
declare class InvalidArgumentError extends Error {
|
37
52
|
readonly parameter: string;
|
38
53
|
readonly value: unknown;
|
@@ -161,18 +176,6 @@ declare class NoTextGeneratedError extends Error {
|
|
161
176
|
};
|
162
177
|
}
|
163
178
|
|
164
|
-
declare class NoResponseBodyError extends Error {
|
165
|
-
constructor({ message }?: {
|
166
|
-
message?: string;
|
167
|
-
});
|
168
|
-
static isNoResponseBodyError(error: unknown): error is NoResponseBodyError;
|
169
|
-
toJSON(): {
|
170
|
-
name: string;
|
171
|
-
message: string;
|
172
|
-
stack: string | undefined;
|
173
|
-
};
|
174
|
-
}
|
175
|
-
|
176
179
|
declare class NoSuchToolError extends Error {
|
177
180
|
readonly toolName: string;
|
178
181
|
readonly availableTools: string[] | undefined;
|
@@ -307,23 +310,13 @@ type LanguageModelV1CallSettings = {
|
|
307
310
|
*/
|
308
311
|
maxTokens?: number;
|
309
312
|
/**
|
310
|
-
* Temperature setting.
|
311
|
-
* 1 (very random).
|
313
|
+
* Temperature setting.
|
312
314
|
*
|
313
|
-
*
|
314
|
-
* scales, so they'd need to map it (without mapping, the same temperature has
|
315
|
-
* different effects on different models). The provider can also chose to map
|
316
|
-
* this to topP, potentially even using a custom setting on their model.
|
317
|
-
*
|
318
|
-
* Note: This is an example of a setting that requires a clear specification of
|
319
|
-
* the semantics.
|
315
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
320
316
|
*/
|
321
317
|
temperature?: number;
|
322
318
|
/**
|
323
|
-
* Nucleus sampling.
|
324
|
-
*
|
325
|
-
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
326
|
-
* are considered.
|
319
|
+
* Nucleus sampling.
|
327
320
|
*
|
328
321
|
* It is recommended to set either `temperature` or `topP`, but not both.
|
329
322
|
*/
|
@@ -331,17 +324,11 @@ type LanguageModelV1CallSettings = {
|
|
331
324
|
/**
|
332
325
|
* Presence penalty setting. It affects the likelihood of the model to
|
333
326
|
* repeat information that is already in the prompt.
|
334
|
-
*
|
335
|
-
* The presence penalty is a number between -1 (increase repetition)
|
336
|
-
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
337
327
|
*/
|
338
328
|
presencePenalty?: number;
|
339
329
|
/**
|
340
330
|
* Frequency penalty setting. It affects the likelihood of the model
|
341
331
|
* to repeatedly use the same words or phrases.
|
342
|
-
*
|
343
|
-
* The frequency penalty is a number between -1 (increase repetition)
|
344
|
-
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
345
332
|
*/
|
346
333
|
frequencyPenalty?: number;
|
347
334
|
/**
|
@@ -507,6 +494,15 @@ type LanguageModelV1FunctionToolCall = {
|
|
507
494
|
args: string;
|
508
495
|
};
|
509
496
|
|
497
|
+
type LanguageModelV1LogProbs = Array<{
|
498
|
+
token: string;
|
499
|
+
logprob: number;
|
500
|
+
topLogprobs: Array<{
|
501
|
+
token: string;
|
502
|
+
logprob: number;
|
503
|
+
}>;
|
504
|
+
}>;
|
505
|
+
|
510
506
|
/**
|
511
507
|
* Experimental: Specification for a language model that implements the language model
|
512
508
|
* interface version 1.
|
@@ -580,7 +576,21 @@ type LanguageModelV1 = {
|
|
580
576
|
*/
|
581
577
|
rawSettings: Record<string, unknown>;
|
582
578
|
};
|
579
|
+
/**
|
580
|
+
* Optional raw response information for debugging purposes.
|
581
|
+
*/
|
582
|
+
rawResponse?: {
|
583
|
+
/**
|
584
|
+
* Response headers.
|
585
|
+
*/
|
586
|
+
headers?: Record<string, string>;
|
587
|
+
};
|
583
588
|
warnings?: LanguageModelV1CallWarning[];
|
589
|
+
/**
|
590
|
+
* Logprobs for the completion.
|
591
|
+
* `undefined` if the mode does not support logprobs or if was not enabled
|
592
|
+
*/
|
593
|
+
logprobs?: LanguageModelV1LogProbs;
|
584
594
|
}>;
|
585
595
|
/**
|
586
596
|
* Generates a language model output (streaming).
|
@@ -607,6 +617,15 @@ type LanguageModelV1 = {
|
|
607
617
|
*/
|
608
618
|
rawSettings: Record<string, unknown>;
|
609
619
|
};
|
620
|
+
/**
|
621
|
+
* Optional raw response data.
|
622
|
+
*/
|
623
|
+
rawResponse?: {
|
624
|
+
/**
|
625
|
+
* Response headers.
|
626
|
+
*/
|
627
|
+
headers?: Record<string, string>;
|
628
|
+
};
|
610
629
|
warnings?: LanguageModelV1CallWarning[];
|
611
630
|
}>;
|
612
631
|
};
|
@@ -624,6 +643,7 @@ type LanguageModelV1StreamPart = {
|
|
624
643
|
} | {
|
625
644
|
type: 'finish';
|
626
645
|
finishReason: LanguageModelV1FinishReason;
|
646
|
+
logprobs?: LanguageModelV1LogProbs;
|
627
647
|
usage: {
|
628
648
|
promptTokens: number;
|
629
649
|
completionTokens: number;
|
@@ -632,5 +652,6 @@ type LanguageModelV1StreamPart = {
|
|
632
652
|
type: 'error';
|
633
653
|
error: unknown;
|
634
654
|
};
|
655
|
+
type LanguageModelV1ResponseMetadata = {};
|
635
656
|
|
636
|
-
export { APICallError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError,
|
657
|
+
export { APICallError, EmptyResponseBodyError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ResponseMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError, NoSuchToolError, NoTextGeneratedError, RetryError, type RetryErrorReason, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError };
|
package/dist/index.js
CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
23
|
APICallError: () => APICallError,
|
24
|
+
EmptyResponseBodyError: () => EmptyResponseBodyError,
|
24
25
|
InvalidArgumentError: () => InvalidArgumentError,
|
25
26
|
InvalidDataContentError: () => InvalidDataContentError,
|
26
27
|
InvalidPromptError: () => InvalidPromptError,
|
@@ -28,7 +29,6 @@ __export(src_exports, {
|
|
28
29
|
InvalidToolArgumentsError: () => InvalidToolArgumentsError,
|
29
30
|
JSONParseError: () => JSONParseError,
|
30
31
|
LoadAPIKeyError: () => LoadAPIKeyError,
|
31
|
-
NoResponseBodyError: () => NoResponseBodyError,
|
32
32
|
NoSuchToolError: () => NoSuchToolError,
|
33
33
|
NoTextGeneratedError: () => NoTextGeneratedError,
|
34
34
|
RetryError: () => RetryError,
|
@@ -46,6 +46,7 @@ var APICallError = class extends Error {
|
|
46
46
|
url,
|
47
47
|
requestBodyValues,
|
48
48
|
statusCode,
|
49
|
+
responseHeaders,
|
49
50
|
responseBody,
|
50
51
|
cause,
|
51
52
|
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
@@ -60,13 +61,14 @@ var APICallError = class extends Error {
|
|
60
61
|
this.url = url;
|
61
62
|
this.requestBodyValues = requestBodyValues;
|
62
63
|
this.statusCode = statusCode;
|
64
|
+
this.responseHeaders = responseHeaders;
|
63
65
|
this.responseBody = responseBody;
|
64
66
|
this.cause = cause;
|
65
67
|
this.isRetryable = isRetryable;
|
66
68
|
this.data = data;
|
67
69
|
}
|
68
70
|
static isAPICallError(error) {
|
69
|
-
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
71
|
+
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseHeaders == null || typeof error.responseHeaders === "object") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
70
72
|
}
|
71
73
|
toJSON() {
|
72
74
|
return {
|
@@ -75,6 +77,7 @@ var APICallError = class extends Error {
|
|
75
77
|
url: this.url,
|
76
78
|
requestBodyValues: this.requestBodyValues,
|
77
79
|
statusCode: this.statusCode,
|
80
|
+
responseHeaders: this.responseHeaders,
|
78
81
|
responseBody: this.responseBody,
|
79
82
|
cause: this.cause,
|
80
83
|
isRetryable: this.isRetryable,
|
@@ -83,6 +86,24 @@ var APICallError = class extends Error {
|
|
83
86
|
}
|
84
87
|
};
|
85
88
|
|
89
|
+
// src/errors/empty-response-body-error.ts
|
90
|
+
var EmptyResponseBodyError = class extends Error {
|
91
|
+
constructor({ message = "Empty response body" } = {}) {
|
92
|
+
super(message);
|
93
|
+
this.name = "AI_EmptyResponseBodyError";
|
94
|
+
}
|
95
|
+
static isEmptyResponseBodyError(error) {
|
96
|
+
return error instanceof Error && error.name === "AI_EmptyResponseBodyError";
|
97
|
+
}
|
98
|
+
toJSON() {
|
99
|
+
return {
|
100
|
+
name: this.name,
|
101
|
+
message: this.message,
|
102
|
+
stack: this.stack
|
103
|
+
};
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
86
107
|
// src/errors/invalid-argument-error.ts
|
87
108
|
var InvalidArgumentError = class extends Error {
|
88
109
|
constructor({
|
@@ -281,24 +302,6 @@ var NoTextGeneratedError = class extends Error {
|
|
281
302
|
}
|
282
303
|
};
|
283
304
|
|
284
|
-
// src/errors/no-response-body-error.ts
|
285
|
-
var NoResponseBodyError = class extends Error {
|
286
|
-
constructor({ message = "No response body" } = {}) {
|
287
|
-
super(message);
|
288
|
-
this.name = "AI_NoResponseBodyError";
|
289
|
-
}
|
290
|
-
static isNoResponseBodyError(error) {
|
291
|
-
return error instanceof Error && error.name === "AI_NoResponseBodyError";
|
292
|
-
}
|
293
|
-
toJSON() {
|
294
|
-
return {
|
295
|
-
name: this.name,
|
296
|
-
message: this.message,
|
297
|
-
stack: this.stack
|
298
|
-
};
|
299
|
-
}
|
300
|
-
};
|
301
|
-
|
302
305
|
// src/errors/no-such-tool-error.ts
|
303
306
|
var NoSuchToolError = class extends Error {
|
304
307
|
constructor({
|
@@ -454,6 +457,7 @@ var UnsupportedJSONSchemaError = class extends Error {
|
|
454
457
|
// Annotate the CommonJS export names for ESM import in node:
|
455
458
|
0 && (module.exports = {
|
456
459
|
APICallError,
|
460
|
+
EmptyResponseBodyError,
|
457
461
|
InvalidArgumentError,
|
458
462
|
InvalidDataContentError,
|
459
463
|
InvalidPromptError,
|
@@ -461,7 +465,6 @@ var UnsupportedJSONSchemaError = class extends Error {
|
|
461
465
|
InvalidToolArgumentsError,
|
462
466
|
JSONParseError,
|
463
467
|
LoadAPIKeyError,
|
464
|
-
NoResponseBodyError,
|
465
468
|
NoSuchToolError,
|
466
469
|
NoTextGeneratedError,
|
467
470
|
RetryError,
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors/api-call-error.ts","../src/errors/invalid-argument-error.ts","../src/errors/invalid-data-content-error.ts","../src/errors/invalid-prompt-error.ts","../src/errors/invalid-response-data-error.ts","../src/errors/get-error-message.ts","../src/errors/invalid-tool-arguments-error.ts","../src/errors/json-parse-error.ts","../src/errors/load-api-key-error.ts","../src/errors/no-object-generated-error.ts","../src/errors/no-response-body-error.ts","../src/errors/no-such-tool-error.ts","../src/errors/retry-error.ts","../src/errors/tool-call-parse-error.ts","../src/errors/type-validation-error.ts","../src/errors/unsupported-functionality-error.ts","../src/errors/unsupported-json-schema-error.ts"],"sourcesContent":["export * from './errors/index';\nexport * from './language-model/index';\n","export class APICallError extends Error {\n readonly url: string;\n readonly requestBodyValues: unknown;\n readonly statusCode?: number;\n readonly responseBody?: string;\n readonly cause?: unknown;\n readonly isRetryable: boolean;\n readonly data?: unknown;\n\n constructor({\n message,\n url,\n requestBodyValues,\n statusCode,\n responseBody,\n cause,\n isRetryable = statusCode != null &&\n (statusCode === 408 || // request timeout\n statusCode === 409 || // conflict\n statusCode === 429 || // too many requests\n statusCode >= 500), // server error\n data,\n }: {\n message: string;\n url: string;\n requestBodyValues: unknown;\n statusCode?: number;\n responseBody?: string;\n cause?: unknown;\n isRetryable?: boolean;\n data?: unknown;\n }) {\n super(message);\n\n this.name = 'AI_APICallError';\n\n this.url = url;\n this.requestBodyValues = requestBodyValues;\n this.statusCode = statusCode;\n this.responseBody = responseBody;\n this.cause = cause;\n this.isRetryable = isRetryable;\n this.data = data;\n }\n\n static isAPICallError(error: unknown): error is APICallError {\n return (\n error instanceof Error &&\n error.name === 'AI_APICallError' &&\n typeof (error as APICallError).url === 'string' &&\n typeof (error as APICallError).requestBodyValues === 'object' &&\n ((error as APICallError).statusCode == null ||\n typeof (error as APICallError).statusCode === 'number') &&\n ((error as APICallError).responseBody == null ||\n typeof (error as APICallError).responseBody === 'string') &&\n ((error as APICallError).cause == null ||\n typeof (error as APICallError).cause === 'object') &&\n typeof (error as APICallError).isRetryable === 'boolean' &&\n ((error as APICallError).data == null ||\n typeof (error as APICallError).data === 'object')\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n url: this.url,\n requestBodyValues: this.requestBodyValues,\n statusCode: this.statusCode,\n responseBody: this.responseBody,\n cause: this.cause,\n isRetryable: this.isRetryable,\n data: this.data,\n };\n }\n}\n","export class InvalidArgumentError extends Error {\n readonly parameter: string;\n readonly value: unknown;\n\n constructor({\n parameter,\n value,\n message,\n }: {\n parameter: string;\n value: unknown;\n message: string;\n }) {\n super(`Invalid argument for parameter ${parameter}: ${message}`);\n\n this.name = 'AI_InvalidArgumentError';\n\n this.parameter = parameter;\n this.value = value;\n }\n\n static isInvalidArgumentError(error: unknown): error is InvalidArgumentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidArgumentError' &&\n typeof (error as InvalidArgumentError).parameter === 'string' &&\n typeof (error as InvalidArgumentError).value === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n parameter: this.parameter,\n value: this.value,\n };\n }\n}\n","export class InvalidDataContentError extends Error {\n readonly content: unknown;\n\n constructor({\n content,\n message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`,\n }: {\n content: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidDataContentError';\n\n this.content = content;\n }\n\n static isInvalidDataContentError(\n error: unknown,\n ): error is InvalidDataContentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidDataContentError' &&\n (error as InvalidDataContentError).content != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n content: this.content,\n };\n }\n}\n","export class InvalidPromptError extends Error {\n readonly prompt: unknown;\n\n constructor({ prompt, message }: { prompt: unknown; message: string }) {\n super(`Invalid prompt: ${message}`);\n\n this.name = 'AI_InvalidPromptError';\n\n this.prompt = prompt;\n }\n\n static isInvalidPromptError(error: unknown): error is InvalidPromptError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidPromptError' &&\n prompt != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n prompt: this.prompt,\n };\n }\n}\n","/**\nServer returned a response with invalid data content. This should be thrown by providers when they\ncannot parse the response from the API.\n */\nexport class InvalidResponseDataError extends Error {\n readonly data: unknown;\n\n constructor({\n data,\n message = `Invalid response data: ${JSON.stringify(data)}.`,\n }: {\n data: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidResponseDataError';\n\n this.data = data;\n }\n\n static isInvalidResponseDataError(\n error: unknown,\n ): error is InvalidResponseDataError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidResponseDataError' &&\n (error as InvalidResponseDataError).data != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n data: this.data,\n };\n }\n}\n","export function getErrorMessage(error: unknown | undefined) {\n if (error == null) {\n return 'unknown error';\n }\n\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n return JSON.stringify(error);\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class InvalidToolArgumentsError extends Error {\n readonly toolName: string;\n readonly toolArgs: string;\n readonly cause: unknown;\n\n constructor({\n toolArgs,\n toolName,\n cause,\n message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(\n cause,\n )}`,\n }: {\n message?: string;\n toolArgs: string;\n toolName: string;\n cause: unknown;\n }) {\n super(message);\n\n this.name = 'AI_InvalidToolArgumentsError';\n\n this.toolArgs = toolArgs;\n this.toolName = toolName;\n this.cause = cause;\n }\n\n static isInvalidToolArgumentsError(\n error: unknown,\n ): error is InvalidToolArgumentsError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidToolArgumentsError' &&\n typeof (error as InvalidToolArgumentsError).toolName === 'string' &&\n typeof (error as InvalidToolArgumentsError).toolArgs === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n toolName: this.toolName,\n toolArgs: this.toolArgs,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class JSONParseError extends Error {\n // note: property order determines debugging output\n readonly text: string;\n readonly cause: unknown;\n\n constructor({ text, cause }: { text: string; cause: unknown }) {\n super(\n `JSON parsing failed: ` +\n `Text: ${text}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_JSONParseError';\n\n this.cause = cause;\n this.text = text;\n }\n\n static isJSONParseError(error: unknown): error is JSONParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_JSONParseError' &&\n typeof (error as JSONParseError).text === 'string' &&\n typeof (error as JSONParseError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n valueText: this.text,\n };\n }\n}\n","export class LoadAPIKeyError extends Error {\n constructor({ message }: { message: string }) {\n super(message);\n\n this.name = 'AI_LoadAPIKeyError';\n }\n\n static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError {\n return error instanceof Error && error.name === 'AI_LoadAPIKeyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n };\n }\n}\n","export class NoTextGeneratedError extends Error {\n readonly cause: unknown;\n\n constructor() {\n super(`No text generated.`);\n\n this.name = 'AI_NoTextGeneratedError';\n }\n\n static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError {\n return error instanceof Error && error.name === 'AI_NoTextGeneratedError';\n }\n\n toJSON() {\n return {\n name: this.name,\n cause: this.cause,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoResponseBodyError extends Error {\n constructor({ message = 'No response body' }: { message?: string } = {}) {\n super(message);\n\n this.name = 'AI_NoResponseBodyError';\n }\n\n static isNoResponseBodyError(error: unknown): error is NoResponseBodyError {\n return error instanceof Error && error.name === 'AI_NoResponseBodyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoSuchToolError extends Error {\n readonly toolName: string;\n readonly availableTools: string[] | undefined;\n\n constructor({\n toolName,\n availableTools = undefined,\n message = `Model tried to call unavailable tool '${toolName}'. ${\n availableTools === undefined\n ? 'No tools are available.'\n : `Available tools: ${availableTools.join(', ')}.`\n }`,\n }: {\n toolName: string;\n availableTools?: string[] | undefined;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_NoSuchToolError';\n\n this.toolName = toolName;\n this.availableTools = availableTools;\n }\n\n static isNoSuchToolError(error: unknown): error is NoSuchToolError {\n return (\n error instanceof Error &&\n error.name === 'AI_NoSuchToolError' &&\n 'toolName' in error &&\n error.toolName != undefined &&\n typeof error.name === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n toolName: this.toolName,\n availableTools: this.availableTools,\n };\n }\n}\n","export type RetryErrorReason =\n | 'maxRetriesExceeded'\n | 'errorNotRetryable'\n | 'abort';\n\nexport class RetryError extends Error {\n // note: property order determines debugging output\n readonly reason: RetryErrorReason;\n readonly lastError: unknown;\n readonly errors: Array<unknown>;\n\n constructor({\n message,\n reason,\n errors,\n }: {\n message: string;\n reason: RetryErrorReason;\n errors: Array<unknown>;\n }) {\n super(message);\n\n this.name = 'AI_RetryError';\n this.reason = reason;\n this.errors = errors;\n\n // separate our last error to make debugging via log easier:\n this.lastError = errors[errors.length - 1];\n }\n\n static isRetryError(error: unknown): error is RetryError {\n return (\n error instanceof Error &&\n error.name === 'AI_RetryError' &&\n typeof (error as RetryError).reason === 'string' &&\n Array.isArray((error as RetryError).errors)\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n reason: this.reason,\n lastError: this.lastError,\n errors: this.errors,\n };\n }\n}\n","import { LanguageModelV1FunctionTool } from '../language-model/v1/language-model-v1-function-tool';\nimport { getErrorMessage } from './get-error-message';\n\nexport class ToolCallParseError extends Error {\n readonly cause: unknown;\n readonly text: string;\n readonly tools: LanguageModelV1FunctionTool[];\n\n constructor({\n cause,\n text,\n tools,\n message = `Failed to parse tool calls: ${getErrorMessage(cause)}`,\n }: {\n cause: unknown;\n text: string;\n tools: LanguageModelV1FunctionTool[];\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_ToolCallParseError';\n\n this.cause = cause;\n this.text = text;\n this.tools = tools;\n }\n\n static isToolCallParseError(error: unknown): error is ToolCallParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_ToolCallParseError' &&\n 'cause' in error &&\n error.cause != undefined &&\n 'text' in error &&\n error.text != undefined &&\n typeof error.text === 'string' &&\n 'tools' in error &&\n error.tools != undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n cause: this.cause,\n text: this.text,\n tools: this.tools,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class TypeValidationError extends Error {\n readonly value: unknown;\n readonly cause: unknown;\n\n constructor({ value, cause }: { value: unknown; cause: unknown }) {\n super(\n `Type validation failed: ` +\n `Value: ${JSON.stringify(value)}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_TypeValidationError';\n\n this.cause = cause;\n this.value = value;\n }\n\n static isTypeValidationError(error: unknown): error is TypeValidationError {\n return (\n error instanceof Error &&\n error.name === 'AI_TypeValidationError' &&\n typeof (error as TypeValidationError).value === 'string' &&\n typeof (error as TypeValidationError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n value: this.value,\n };\n }\n}\n","export class UnsupportedFunctionalityError extends Error {\n readonly functionality: string;\n\n constructor({ functionality }: { functionality: string }) {\n super(`'${functionality}' functionality not supported.`);\n\n this.name = 'AI_UnsupportedFunctionalityError';\n\n this.functionality = functionality;\n }\n\n static isUnsupportedFunctionalityError(\n error: unknown,\n ): error is UnsupportedFunctionalityError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedFunctionalityError' &&\n typeof (error as UnsupportedFunctionalityError).functionality === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n functionality: this.functionality,\n };\n }\n}\n","export class UnsupportedJSONSchemaError extends Error {\n readonly reason: string;\n readonly schema: unknown;\n\n constructor({\n schema,\n reason,\n message = `Unsupported JSON schema: ${reason}`,\n }: {\n schema: unknown;\n reason: string;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_UnsupportedJSONSchemaError';\n\n this.reason = reason;\n this.schema = schema;\n }\n\n static isUnsupportedJSONSchemaError(\n error: unknown,\n ): error is UnsupportedJSONSchemaError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedJSONSchemaError' &&\n 'reason' in error &&\n error.reason != undefined &&\n 'schema' in error &&\n error.schema !== undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n reason: this.reason,\n schema: this.schema,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAStC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc,SACzB,eAAe;AAAA,IACd,eAAe;AAAA,IACf,eAAe;AAAA,IACf,cAAc;AAAA;AAAA,IAClB;AAAA,EACF,GASG;AACD,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,SAAK,MAAM;AACX,SAAK,oBAAoB;AACzB,SAAK,aAAa;AAClB,SAAK,eAAe;AACpB,SAAK,QAAQ;AACb,SAAK,cAAc;AACnB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,eAAe,OAAuC;AAC3D,WACE,iBAAiB,SACjB,MAAM,SAAS,qBACf,OAAQ,MAAuB,QAAQ,YACvC,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SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MAEZ,eAAe,KAAK;AAAA,IACtB;AAAA,EACF;AACF;;;AC9BO,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAIpD,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU,4BAA4B,MAAM;AAAA,EAC9C,GAIG;AACD,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,6BACL,OACqC;AACrC,WACE,iBAAiB,SACjB,MAAM,SAAS,mCACf,YAAY,SACZ,MAAM,UAAU,UAChB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MAEZ,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;","names":["prompt"]}
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors/api-call-error.ts","../src/errors/empty-response-body-error.ts","../src/errors/invalid-argument-error.ts","../src/errors/invalid-data-content-error.ts","../src/errors/invalid-prompt-error.ts","../src/errors/invalid-response-data-error.ts","../src/errors/get-error-message.ts","../src/errors/invalid-tool-arguments-error.ts","../src/errors/json-parse-error.ts","../src/errors/load-api-key-error.ts","../src/errors/no-object-generated-error.ts","../src/errors/no-such-tool-error.ts","../src/errors/retry-error.ts","../src/errors/tool-call-parse-error.ts","../src/errors/type-validation-error.ts","../src/errors/unsupported-functionality-error.ts","../src/errors/unsupported-json-schema-error.ts"],"sourcesContent":["export * from './errors/index';\nexport * from './language-model/index';\n","export class APICallError extends Error {\n readonly url: string;\n readonly requestBodyValues: unknown;\n readonly statusCode?: number;\n\n readonly responseHeaders?: Record<string, string>;\n readonly responseBody?: string;\n\n readonly cause?: unknown;\n readonly isRetryable: boolean;\n readonly data?: unknown;\n\n constructor({\n message,\n url,\n requestBodyValues,\n statusCode,\n responseHeaders,\n responseBody,\n cause,\n isRetryable = statusCode != null &&\n (statusCode === 408 || // request timeout\n statusCode === 409 || // conflict\n statusCode === 429 || // too many requests\n statusCode >= 500), // server error\n data,\n }: {\n message: string;\n url: string;\n requestBodyValues: unknown;\n statusCode?: number;\n responseHeaders?: Record<string, string>;\n responseBody?: string;\n cause?: unknown;\n isRetryable?: boolean;\n data?: unknown;\n }) {\n super(message);\n\n this.name = 'AI_APICallError';\n\n this.url = url;\n this.requestBodyValues = requestBodyValues;\n this.statusCode = statusCode;\n this.responseHeaders = responseHeaders;\n this.responseBody = responseBody;\n this.cause = cause;\n this.isRetryable = isRetryable;\n this.data = data;\n }\n\n static isAPICallError(error: unknown): error is APICallError {\n return (\n error instanceof Error &&\n error.name === 'AI_APICallError' &&\n typeof (error as APICallError).url === 'string' &&\n typeof (error as APICallError).requestBodyValues === 'object' &&\n ((error as APICallError).statusCode == null ||\n typeof (error as APICallError).statusCode === 'number') &&\n ((error as APICallError).responseHeaders == null ||\n typeof (error as APICallError).responseHeaders === 'object') &&\n ((error as APICallError).responseBody == null ||\n typeof (error as APICallError).responseBody === 'string') &&\n ((error as APICallError).cause == null ||\n typeof (error as APICallError).cause === 'object') &&\n typeof (error as APICallError).isRetryable === 'boolean' &&\n ((error as APICallError).data == null ||\n typeof (error as APICallError).data === 'object')\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n url: this.url,\n requestBodyValues: this.requestBodyValues,\n statusCode: this.statusCode,\n responseHeaders: this.responseHeaders,\n responseBody: this.responseBody,\n cause: this.cause,\n isRetryable: this.isRetryable,\n data: this.data,\n };\n }\n}\n","export class EmptyResponseBodyError extends Error {\n constructor({ message = 'Empty response body' }: { message?: string } = {}) {\n super(message);\n\n this.name = 'AI_EmptyResponseBodyError';\n }\n\n static isEmptyResponseBodyError(\n error: unknown,\n ): error is EmptyResponseBodyError {\n return error instanceof Error && error.name === 'AI_EmptyResponseBodyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class InvalidArgumentError extends Error {\n readonly parameter: string;\n readonly value: unknown;\n\n constructor({\n parameter,\n value,\n message,\n }: {\n parameter: string;\n value: unknown;\n message: string;\n }) {\n super(`Invalid argument for parameter ${parameter}: ${message}`);\n\n this.name = 'AI_InvalidArgumentError';\n\n this.parameter = parameter;\n this.value = value;\n }\n\n static isInvalidArgumentError(error: unknown): error is InvalidArgumentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidArgumentError' &&\n typeof (error as InvalidArgumentError).parameter === 'string' &&\n typeof (error as InvalidArgumentError).value === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n parameter: this.parameter,\n value: this.value,\n };\n }\n}\n","export class InvalidDataContentError extends Error {\n readonly content: unknown;\n\n constructor({\n content,\n message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`,\n }: {\n content: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidDataContentError';\n\n this.content = content;\n }\n\n static isInvalidDataContentError(\n error: unknown,\n ): error is InvalidDataContentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidDataContentError' &&\n (error as InvalidDataContentError).content != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n content: this.content,\n };\n }\n}\n","export class InvalidPromptError extends Error {\n readonly prompt: unknown;\n\n constructor({ prompt, message }: { prompt: unknown; message: string }) {\n super(`Invalid prompt: ${message}`);\n\n this.name = 'AI_InvalidPromptError';\n\n this.prompt = prompt;\n }\n\n static isInvalidPromptError(error: unknown): error is InvalidPromptError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidPromptError' &&\n prompt != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n prompt: this.prompt,\n };\n }\n}\n","/**\nServer returned a response with invalid data content. This should be thrown by providers when they\ncannot parse the response from the API.\n */\nexport class InvalidResponseDataError extends Error {\n readonly data: unknown;\n\n constructor({\n data,\n message = `Invalid response data: ${JSON.stringify(data)}.`,\n }: {\n data: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidResponseDataError';\n\n this.data = data;\n }\n\n static isInvalidResponseDataError(\n error: unknown,\n ): error is InvalidResponseDataError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidResponseDataError' &&\n (error as InvalidResponseDataError).data != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n data: this.data,\n };\n }\n}\n","export function getErrorMessage(error: unknown | undefined) {\n if (error == null) {\n return 'unknown error';\n }\n\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n return JSON.stringify(error);\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class InvalidToolArgumentsError extends Error {\n readonly toolName: string;\n readonly toolArgs: string;\n readonly cause: unknown;\n\n constructor({\n toolArgs,\n toolName,\n cause,\n message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(\n cause,\n )}`,\n }: {\n message?: string;\n toolArgs: string;\n toolName: string;\n cause: unknown;\n }) {\n super(message);\n\n this.name = 'AI_InvalidToolArgumentsError';\n\n this.toolArgs = toolArgs;\n this.toolName = toolName;\n this.cause = cause;\n }\n\n static isInvalidToolArgumentsError(\n error: unknown,\n ): error is InvalidToolArgumentsError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidToolArgumentsError' &&\n typeof (error as InvalidToolArgumentsError).toolName === 'string' &&\n typeof (error as InvalidToolArgumentsError).toolArgs === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n toolName: this.toolName,\n toolArgs: this.toolArgs,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class JSONParseError extends Error {\n // note: property order determines debugging output\n readonly text: string;\n readonly cause: unknown;\n\n constructor({ text, cause }: { text: string; cause: unknown }) {\n super(\n `JSON parsing failed: ` +\n `Text: ${text}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_JSONParseError';\n\n this.cause = cause;\n this.text = text;\n }\n\n static isJSONParseError(error: unknown): error is JSONParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_JSONParseError' &&\n typeof (error as JSONParseError).text === 'string' &&\n typeof (error as JSONParseError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n valueText: this.text,\n };\n }\n}\n","export class LoadAPIKeyError extends Error {\n constructor({ message }: { message: string }) {\n super(message);\n\n this.name = 'AI_LoadAPIKeyError';\n }\n\n static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError {\n return error instanceof Error && error.name === 'AI_LoadAPIKeyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n };\n }\n}\n","export class NoTextGeneratedError extends Error {\n readonly cause: unknown;\n\n constructor() {\n super(`No text generated.`);\n\n this.name = 'AI_NoTextGeneratedError';\n }\n\n static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError {\n return error instanceof Error && error.name === 'AI_NoTextGeneratedError';\n }\n\n toJSON() {\n return {\n name: this.name,\n cause: this.cause,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoSuchToolError extends Error {\n readonly toolName: string;\n readonly availableTools: string[] | undefined;\n\n constructor({\n toolName,\n availableTools = undefined,\n message = `Model tried to call unavailable tool '${toolName}'. ${\n availableTools === undefined\n ? 'No tools are available.'\n : `Available tools: ${availableTools.join(', ')}.`\n }`,\n }: {\n toolName: string;\n availableTools?: string[] | undefined;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_NoSuchToolError';\n\n this.toolName = toolName;\n this.availableTools = availableTools;\n }\n\n static isNoSuchToolError(error: unknown): error is NoSuchToolError {\n return (\n error instanceof Error &&\n error.name === 'AI_NoSuchToolError' &&\n 'toolName' in error &&\n error.toolName != undefined &&\n typeof error.name === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n toolName: this.toolName,\n availableTools: this.availableTools,\n };\n }\n}\n","export type RetryErrorReason =\n | 'maxRetriesExceeded'\n | 'errorNotRetryable'\n | 'abort';\n\nexport class RetryError extends Error {\n // note: property order determines debugging output\n readonly reason: RetryErrorReason;\n readonly lastError: unknown;\n readonly errors: Array<unknown>;\n\n constructor({\n message,\n reason,\n errors,\n }: {\n message: string;\n reason: RetryErrorReason;\n errors: Array<unknown>;\n }) {\n super(message);\n\n this.name = 'AI_RetryError';\n this.reason = reason;\n this.errors = errors;\n\n // separate our last error to make debugging via log easier:\n this.lastError = errors[errors.length - 1];\n }\n\n static isRetryError(error: unknown): error is RetryError {\n return (\n error instanceof Error &&\n error.name === 'AI_RetryError' &&\n typeof (error as RetryError).reason === 'string' &&\n Array.isArray((error as RetryError).errors)\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n reason: this.reason,\n lastError: this.lastError,\n errors: this.errors,\n };\n }\n}\n","import { LanguageModelV1FunctionTool } from '../language-model/v1/language-model-v1-function-tool';\nimport { getErrorMessage } from './get-error-message';\n\nexport class ToolCallParseError extends Error {\n readonly cause: unknown;\n readonly text: string;\n readonly tools: LanguageModelV1FunctionTool[];\n\n constructor({\n cause,\n text,\n tools,\n message = `Failed to parse tool calls: ${getErrorMessage(cause)}`,\n }: {\n cause: unknown;\n text: string;\n tools: LanguageModelV1FunctionTool[];\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_ToolCallParseError';\n\n this.cause = cause;\n this.text = text;\n this.tools = tools;\n }\n\n static isToolCallParseError(error: unknown): error is ToolCallParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_ToolCallParseError' &&\n 'cause' in error &&\n error.cause != undefined &&\n 'text' in error &&\n error.text != undefined &&\n typeof error.text === 'string' &&\n 'tools' in error &&\n error.tools != undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n cause: this.cause,\n text: this.text,\n tools: this.tools,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class TypeValidationError extends Error {\n readonly value: unknown;\n readonly cause: unknown;\n\n constructor({ value, cause }: { value: unknown; cause: unknown }) {\n super(\n `Type validation failed: ` +\n `Value: ${JSON.stringify(value)}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_TypeValidationError';\n\n this.cause = cause;\n this.value = value;\n }\n\n static isTypeValidationError(error: unknown): error is TypeValidationError {\n return (\n error instanceof Error &&\n error.name === 'AI_TypeValidationError' &&\n typeof (error as TypeValidationError).value === 'string' &&\n typeof (error as TypeValidationError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n value: this.value,\n };\n }\n}\n","export class UnsupportedFunctionalityError extends Error {\n readonly functionality: string;\n\n constructor({ functionality }: { functionality: string }) {\n super(`'${functionality}' functionality not supported.`);\n\n this.name = 'AI_UnsupportedFunctionalityError';\n\n this.functionality = functionality;\n }\n\n static isUnsupportedFunctionalityError(\n error: unknown,\n ): error is UnsupportedFunctionalityError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedFunctionalityError' &&\n typeof (error as UnsupportedFunctionalityError).functionality === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n functionality: this.functionality,\n };\n }\n}\n","export class UnsupportedJSONSchemaError extends Error {\n readonly reason: string;\n readonly schema: unknown;\n\n constructor({\n schema,\n reason,\n message = `Unsupported JSON schema: ${reason}`,\n }: {\n schema: unknown;\n reason: string;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_UnsupportedJSONSchemaError';\n\n this.reason = reason;\n this.schema = schema;\n }\n\n static isUnsupportedJSONSchemaError(\n error: unknown,\n ): error is UnsupportedJSONSchemaError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedJSONSchemaError' &&\n 'reason' in error &&\n error.reason != undefined &&\n 'schema' in error &&\n error.schema !== undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n reason: this.reason,\n schema: this.schema,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAYtC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc,SACzB,eAAe;AAAA,IACd,eAAe;AAAA,IACf,eAAe;AAAA,IACf,cAAc;AAAA;AAAA,IAClB;AAAA,EACF,GAUG;AACD,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,SAAK,MAAM;AACX,SAAK,oBAAoB;AACzB,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AACpB,SAAK,QAAQ;AACb,SAAK,cAAc;AACnB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,eAAe,OAAuC;AAC3D,WACE,iBAAiB,SACjB,MAAM,SAAS,qBACf,OAAQ,MAAuB,QAAQ,YACvC,OAAQ,MAAuB,sBAAsB,aACnD,MAAuB,cAAc,QACrC,OAAQ,MAAuB,eAAe,cAC9C,MAAuB,mBAAmB,QAC1C,OAAQ,MAAuB,oBAAoB,cACnD,MAAuB,gBAAgB,QACvC,OAAQ,MAAuB,iBAAiB,cAChD,MAAuB,SAAS,QAChC,OAAQ,MAAuB,UAAU,aAC3C,OAAQ,MAAuB,gBAAgB,cAC7C,MAAuB,QAAQ,QAC/B,OAAQ,MAAuB,SAAS;AAAA,EAE9C;AAAA,EAEA,SAA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AAEZ,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,6BACL,OACqC;AACrC,WACE,iBAAiB,SACjB,MAAM,SAAS,mCACf,YAAY,SACZ,MAAM,UAAU,UAChB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MAEZ,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;","names":["prompt"]}
|
package/dist/index.mjs
CHANGED
@@ -5,6 +5,7 @@ var APICallError = class extends Error {
|
|
5
5
|
url,
|
6
6
|
requestBodyValues,
|
7
7
|
statusCode,
|
8
|
+
responseHeaders,
|
8
9
|
responseBody,
|
9
10
|
cause,
|
10
11
|
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
@@ -19,13 +20,14 @@ var APICallError = class extends Error {
|
|
19
20
|
this.url = url;
|
20
21
|
this.requestBodyValues = requestBodyValues;
|
21
22
|
this.statusCode = statusCode;
|
23
|
+
this.responseHeaders = responseHeaders;
|
22
24
|
this.responseBody = responseBody;
|
23
25
|
this.cause = cause;
|
24
26
|
this.isRetryable = isRetryable;
|
25
27
|
this.data = data;
|
26
28
|
}
|
27
29
|
static isAPICallError(error) {
|
28
|
-
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
30
|
+
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseHeaders == null || typeof error.responseHeaders === "object") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
29
31
|
}
|
30
32
|
toJSON() {
|
31
33
|
return {
|
@@ -34,6 +36,7 @@ var APICallError = class extends Error {
|
|
34
36
|
url: this.url,
|
35
37
|
requestBodyValues: this.requestBodyValues,
|
36
38
|
statusCode: this.statusCode,
|
39
|
+
responseHeaders: this.responseHeaders,
|
37
40
|
responseBody: this.responseBody,
|
38
41
|
cause: this.cause,
|
39
42
|
isRetryable: this.isRetryable,
|
@@ -42,6 +45,24 @@ var APICallError = class extends Error {
|
|
42
45
|
}
|
43
46
|
};
|
44
47
|
|
48
|
+
// src/errors/empty-response-body-error.ts
|
49
|
+
var EmptyResponseBodyError = class extends Error {
|
50
|
+
constructor({ message = "Empty response body" } = {}) {
|
51
|
+
super(message);
|
52
|
+
this.name = "AI_EmptyResponseBodyError";
|
53
|
+
}
|
54
|
+
static isEmptyResponseBodyError(error) {
|
55
|
+
return error instanceof Error && error.name === "AI_EmptyResponseBodyError";
|
56
|
+
}
|
57
|
+
toJSON() {
|
58
|
+
return {
|
59
|
+
name: this.name,
|
60
|
+
message: this.message,
|
61
|
+
stack: this.stack
|
62
|
+
};
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
45
66
|
// src/errors/invalid-argument-error.ts
|
46
67
|
var InvalidArgumentError = class extends Error {
|
47
68
|
constructor({
|
@@ -240,24 +261,6 @@ var NoTextGeneratedError = class extends Error {
|
|
240
261
|
}
|
241
262
|
};
|
242
263
|
|
243
|
-
// src/errors/no-response-body-error.ts
|
244
|
-
var NoResponseBodyError = class extends Error {
|
245
|
-
constructor({ message = "No response body" } = {}) {
|
246
|
-
super(message);
|
247
|
-
this.name = "AI_NoResponseBodyError";
|
248
|
-
}
|
249
|
-
static isNoResponseBodyError(error) {
|
250
|
-
return error instanceof Error && error.name === "AI_NoResponseBodyError";
|
251
|
-
}
|
252
|
-
toJSON() {
|
253
|
-
return {
|
254
|
-
name: this.name,
|
255
|
-
message: this.message,
|
256
|
-
stack: this.stack
|
257
|
-
};
|
258
|
-
}
|
259
|
-
};
|
260
|
-
|
261
264
|
// src/errors/no-such-tool-error.ts
|
262
265
|
var NoSuchToolError = class extends Error {
|
263
266
|
constructor({
|
@@ -412,6 +415,7 @@ var UnsupportedJSONSchemaError = class extends Error {
|
|
412
415
|
};
|
413
416
|
export {
|
414
417
|
APICallError,
|
418
|
+
EmptyResponseBodyError,
|
415
419
|
InvalidArgumentError,
|
416
420
|
InvalidDataContentError,
|
417
421
|
InvalidPromptError,
|
@@ -419,7 +423,6 @@ export {
|
|
419
423
|
InvalidToolArgumentsError,
|
420
424
|
JSONParseError,
|
421
425
|
LoadAPIKeyError,
|
422
|
-
NoResponseBodyError,
|
423
426
|
NoSuchToolError,
|
424
427
|
NoTextGeneratedError,
|
425
428
|
RetryError,
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/errors/api-call-error.ts","../src/errors/invalid-argument-error.ts","../src/errors/invalid-data-content-error.ts","../src/errors/invalid-prompt-error.ts","../src/errors/invalid-response-data-error.ts","../src/errors/get-error-message.ts","../src/errors/invalid-tool-arguments-error.ts","../src/errors/json-parse-error.ts","../src/errors/load-api-key-error.ts","../src/errors/no-object-generated-error.ts","../src/errors/no-response-body-error.ts","../src/errors/no-such-tool-error.ts","../src/errors/retry-error.ts","../src/errors/tool-call-parse-error.ts","../src/errors/type-validation-error.ts","../src/errors/unsupported-functionality-error.ts","../src/errors/unsupported-json-schema-error.ts"],"sourcesContent":["export class APICallError extends Error {\n readonly url: string;\n readonly requestBodyValues: unknown;\n readonly statusCode?: number;\n readonly responseBody?: string;\n readonly cause?: unknown;\n readonly isRetryable: boolean;\n readonly data?: unknown;\n\n constructor({\n message,\n url,\n requestBodyValues,\n statusCode,\n responseBody,\n cause,\n isRetryable = statusCode != null &&\n (statusCode === 408 || // request timeout\n statusCode === 409 || // conflict\n statusCode === 429 || // too many requests\n statusCode >= 500), // server error\n data,\n }: {\n message: string;\n url: string;\n requestBodyValues: unknown;\n statusCode?: number;\n responseBody?: string;\n cause?: unknown;\n isRetryable?: boolean;\n data?: unknown;\n }) {\n super(message);\n\n this.name = 'AI_APICallError';\n\n this.url = url;\n this.requestBodyValues = requestBodyValues;\n this.statusCode = statusCode;\n this.responseBody = responseBody;\n this.cause = cause;\n this.isRetryable = isRetryable;\n this.data = data;\n }\n\n static isAPICallError(error: unknown): error is APICallError {\n return (\n error instanceof Error &&\n error.name === 'AI_APICallError' &&\n typeof (error as APICallError).url === 'string' &&\n typeof (error as APICallError).requestBodyValues === 'object' &&\n ((error as APICallError).statusCode == null ||\n typeof (error as APICallError).statusCode === 'number') &&\n ((error as APICallError).responseBody == null ||\n typeof (error as APICallError).responseBody === 'string') &&\n ((error as APICallError).cause == null ||\n typeof (error as APICallError).cause === 'object') &&\n typeof (error as APICallError).isRetryable === 'boolean' &&\n ((error as APICallError).data == null ||\n typeof (error as APICallError).data === 'object')\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n url: this.url,\n requestBodyValues: this.requestBodyValues,\n statusCode: this.statusCode,\n responseBody: this.responseBody,\n cause: this.cause,\n isRetryable: this.isRetryable,\n data: this.data,\n };\n }\n}\n","export class InvalidArgumentError extends Error {\n readonly parameter: string;\n readonly value: unknown;\n\n constructor({\n parameter,\n value,\n message,\n }: {\n parameter: string;\n value: unknown;\n message: string;\n }) {\n super(`Invalid argument for parameter ${parameter}: ${message}`);\n\n this.name = 'AI_InvalidArgumentError';\n\n this.parameter = parameter;\n this.value = value;\n }\n\n static isInvalidArgumentError(error: unknown): error is InvalidArgumentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidArgumentError' &&\n typeof (error as InvalidArgumentError).parameter === 'string' &&\n typeof (error as InvalidArgumentError).value === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n parameter: this.parameter,\n value: this.value,\n };\n }\n}\n","export class InvalidDataContentError extends Error {\n readonly content: unknown;\n\n constructor({\n content,\n message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`,\n }: {\n content: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidDataContentError';\n\n this.content = content;\n }\n\n static isInvalidDataContentError(\n error: unknown,\n ): error is InvalidDataContentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidDataContentError' &&\n (error as InvalidDataContentError).content != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n content: this.content,\n };\n }\n}\n","export class InvalidPromptError extends Error {\n readonly prompt: unknown;\n\n constructor({ prompt, message }: { prompt: unknown; message: string }) {\n super(`Invalid prompt: ${message}`);\n\n this.name = 'AI_InvalidPromptError';\n\n this.prompt = prompt;\n }\n\n static isInvalidPromptError(error: unknown): error is InvalidPromptError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidPromptError' &&\n prompt != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n prompt: this.prompt,\n };\n }\n}\n","/**\nServer returned a response with invalid data content. This should be thrown by providers when they\ncannot parse the response from the API.\n */\nexport class InvalidResponseDataError extends Error {\n readonly data: unknown;\n\n constructor({\n data,\n message = `Invalid response data: ${JSON.stringify(data)}.`,\n }: {\n data: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidResponseDataError';\n\n this.data = data;\n }\n\n static isInvalidResponseDataError(\n error: unknown,\n ): error is InvalidResponseDataError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidResponseDataError' &&\n (error as InvalidResponseDataError).data != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n data: this.data,\n };\n }\n}\n","export function getErrorMessage(error: unknown | undefined) {\n if (error == null) {\n return 'unknown error';\n }\n\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n return JSON.stringify(error);\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class InvalidToolArgumentsError extends Error {\n readonly toolName: string;\n readonly toolArgs: string;\n readonly cause: unknown;\n\n constructor({\n toolArgs,\n toolName,\n cause,\n message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(\n cause,\n )}`,\n }: {\n message?: string;\n toolArgs: string;\n toolName: string;\n cause: unknown;\n }) {\n super(message);\n\n this.name = 'AI_InvalidToolArgumentsError';\n\n this.toolArgs = toolArgs;\n this.toolName = toolName;\n this.cause = cause;\n }\n\n static isInvalidToolArgumentsError(\n error: unknown,\n ): error is InvalidToolArgumentsError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidToolArgumentsError' &&\n typeof (error as InvalidToolArgumentsError).toolName === 'string' &&\n typeof (error as InvalidToolArgumentsError).toolArgs === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n toolName: this.toolName,\n toolArgs: this.toolArgs,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class JSONParseError extends Error {\n // note: property order determines debugging output\n readonly text: string;\n readonly cause: unknown;\n\n constructor({ text, cause }: { text: string; cause: unknown }) {\n super(\n `JSON parsing failed: ` +\n `Text: ${text}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_JSONParseError';\n\n this.cause = cause;\n this.text = text;\n }\n\n static isJSONParseError(error: unknown): error is JSONParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_JSONParseError' &&\n typeof (error as JSONParseError).text === 'string' &&\n typeof (error as JSONParseError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n valueText: this.text,\n };\n }\n}\n","export class LoadAPIKeyError extends Error {\n constructor({ message }: { message: string }) {\n super(message);\n\n this.name = 'AI_LoadAPIKeyError';\n }\n\n static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError {\n return error instanceof Error && error.name === 'AI_LoadAPIKeyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n };\n }\n}\n","export class NoTextGeneratedError extends Error {\n readonly cause: unknown;\n\n constructor() {\n super(`No text generated.`);\n\n this.name = 'AI_NoTextGeneratedError';\n }\n\n static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError {\n return error instanceof Error && error.name === 'AI_NoTextGeneratedError';\n }\n\n toJSON() {\n return {\n name: this.name,\n cause: this.cause,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoResponseBodyError extends Error {\n constructor({ message = 'No response body' }: { message?: string } = {}) {\n super(message);\n\n this.name = 'AI_NoResponseBodyError';\n }\n\n static isNoResponseBodyError(error: unknown): error is NoResponseBodyError {\n return error instanceof Error && error.name === 'AI_NoResponseBodyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoSuchToolError extends Error {\n readonly toolName: string;\n readonly availableTools: string[] | undefined;\n\n constructor({\n toolName,\n availableTools = undefined,\n message = `Model tried to call unavailable tool '${toolName}'. ${\n availableTools === undefined\n ? 'No tools are available.'\n : `Available tools: ${availableTools.join(', ')}.`\n }`,\n }: {\n toolName: string;\n availableTools?: string[] | undefined;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_NoSuchToolError';\n\n this.toolName = toolName;\n this.availableTools = availableTools;\n }\n\n static isNoSuchToolError(error: unknown): error is NoSuchToolError {\n return (\n error instanceof Error &&\n error.name === 'AI_NoSuchToolError' &&\n 'toolName' in error &&\n error.toolName != undefined &&\n typeof error.name === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n toolName: this.toolName,\n availableTools: this.availableTools,\n };\n }\n}\n","export type RetryErrorReason =\n | 'maxRetriesExceeded'\n | 'errorNotRetryable'\n | 'abort';\n\nexport class RetryError extends Error {\n // note: property order determines debugging output\n readonly reason: RetryErrorReason;\n readonly lastError: unknown;\n readonly errors: Array<unknown>;\n\n constructor({\n message,\n reason,\n errors,\n }: {\n message: string;\n reason: RetryErrorReason;\n errors: Array<unknown>;\n }) {\n super(message);\n\n this.name = 'AI_RetryError';\n this.reason = reason;\n this.errors = errors;\n\n // separate our last error to make debugging via log easier:\n this.lastError = errors[errors.length - 1];\n }\n\n static isRetryError(error: unknown): error is RetryError {\n return (\n error instanceof Error &&\n error.name === 'AI_RetryError' &&\n typeof (error as RetryError).reason === 'string' &&\n Array.isArray((error as RetryError).errors)\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n reason: this.reason,\n lastError: this.lastError,\n errors: this.errors,\n };\n }\n}\n","import { LanguageModelV1FunctionTool } from '../language-model/v1/language-model-v1-function-tool';\nimport { getErrorMessage } from './get-error-message';\n\nexport class ToolCallParseError extends Error {\n readonly cause: unknown;\n readonly text: string;\n readonly tools: LanguageModelV1FunctionTool[];\n\n constructor({\n cause,\n text,\n tools,\n message = `Failed to parse tool calls: ${getErrorMessage(cause)}`,\n }: {\n cause: unknown;\n text: string;\n tools: LanguageModelV1FunctionTool[];\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_ToolCallParseError';\n\n this.cause = cause;\n this.text = text;\n this.tools = tools;\n }\n\n static isToolCallParseError(error: unknown): error is ToolCallParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_ToolCallParseError' &&\n 'cause' in error &&\n error.cause != undefined &&\n 'text' in error &&\n error.text != undefined &&\n typeof error.text === 'string' &&\n 'tools' in error &&\n error.tools != undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n cause: this.cause,\n text: this.text,\n tools: this.tools,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class TypeValidationError extends Error {\n readonly value: unknown;\n readonly cause: unknown;\n\n constructor({ value, cause }: { value: unknown; cause: unknown }) {\n super(\n `Type validation failed: ` +\n `Value: ${JSON.stringify(value)}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_TypeValidationError';\n\n this.cause = cause;\n this.value = value;\n }\n\n static isTypeValidationError(error: unknown): error is TypeValidationError {\n return (\n error instanceof Error &&\n error.name === 'AI_TypeValidationError' &&\n typeof (error as TypeValidationError).value === 'string' &&\n typeof (error as TypeValidationError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n value: this.value,\n };\n }\n}\n","export class UnsupportedFunctionalityError extends Error {\n readonly functionality: string;\n\n constructor({ functionality }: { functionality: string }) {\n super(`'${functionality}' functionality not supported.`);\n\n this.name = 'AI_UnsupportedFunctionalityError';\n\n this.functionality = functionality;\n }\n\n static isUnsupportedFunctionalityError(\n error: unknown,\n ): error is UnsupportedFunctionalityError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedFunctionalityError' &&\n typeof (error as UnsupportedFunctionalityError).functionality === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n functionality: this.functionality,\n };\n }\n}\n","export class UnsupportedJSONSchemaError extends Error {\n readonly reason: string;\n readonly schema: unknown;\n\n constructor({\n schema,\n reason,\n message = `Unsupported JSON schema: ${reason}`,\n }: {\n schema: unknown;\n reason: string;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_UnsupportedJSONSchemaError';\n\n this.reason = reason;\n this.schema = schema;\n }\n\n static isUnsupportedJSONSchemaError(\n error: unknown,\n ): error is UnsupportedJSONSchemaError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedJSONSchemaError' &&\n 'reason' in error &&\n error.reason != undefined &&\n 'schema' in error &&\n error.schema !== undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n reason: this.reason,\n schema: this.schema,\n };\n }\n}\n"],"mappings":";AAAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAStC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AA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A,MACd,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,MAEZ,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AACF;;;ACtCO,IAAM,gCAAN,cAA4C,MAAM;AAAA,EAGvD,YAAY,EAAE,cAAc,GAA8B;AACxD,UAAM,IAAI,aAAa,gCAAgC;AAEvD,SAAK,OAAO;AAEZ,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,OAAO,gCACL,OACwC;AACxC,WACE,iBAAiB,SACjB,MAAM,SAAS,sCACf,OAAQ,MAAwC,kBAAkB;AAAA,EAEtE;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MAEZ,eAAe,KAAK;AAAA,IACtB;AAAA,EACF;AACF;;;AC9BO,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAIpD,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU,4BAA4B,MAAM;AAAA,EAC9C,GAIG;AACD,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,6BACL,OACqC;AACrC,WACE,iBAAiB,SACjB,MAAM,SAAS,mCACf,YAAY,SACZ,MAAM,UAAU,UAChB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MAEZ,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;","names":["prompt"]}
|
1
|
+
{"version":3,"sources":["../src/errors/api-call-error.ts","../src/errors/empty-response-body-error.ts","../src/errors/invalid-argument-error.ts","../src/errors/invalid-data-content-error.ts","../src/errors/invalid-prompt-error.ts","../src/errors/invalid-response-data-error.ts","../src/errors/get-error-message.ts","../src/errors/invalid-tool-arguments-error.ts","../src/errors/json-parse-error.ts","../src/errors/load-api-key-error.ts","../src/errors/no-object-generated-error.ts","../src/errors/no-such-tool-error.ts","../src/errors/retry-error.ts","../src/errors/tool-call-parse-error.ts","../src/errors/type-validation-error.ts","../src/errors/unsupported-functionality-error.ts","../src/errors/unsupported-json-schema-error.ts"],"sourcesContent":["export class APICallError extends Error {\n readonly url: string;\n readonly requestBodyValues: unknown;\n readonly statusCode?: number;\n\n readonly responseHeaders?: Record<string, string>;\n readonly responseBody?: string;\n\n readonly cause?: unknown;\n readonly isRetryable: boolean;\n readonly data?: unknown;\n\n constructor({\n message,\n url,\n requestBodyValues,\n statusCode,\n responseHeaders,\n responseBody,\n cause,\n isRetryable = statusCode != null &&\n (statusCode === 408 || // request timeout\n statusCode === 409 || // conflict\n statusCode === 429 || // too many requests\n statusCode >= 500), // server error\n data,\n }: {\n message: string;\n url: string;\n requestBodyValues: unknown;\n statusCode?: number;\n responseHeaders?: Record<string, string>;\n responseBody?: string;\n cause?: unknown;\n isRetryable?: boolean;\n data?: unknown;\n }) {\n super(message);\n\n this.name = 'AI_APICallError';\n\n this.url = url;\n this.requestBodyValues = requestBodyValues;\n this.statusCode = statusCode;\n this.responseHeaders = responseHeaders;\n this.responseBody = responseBody;\n this.cause = cause;\n this.isRetryable = isRetryable;\n this.data = data;\n }\n\n static isAPICallError(error: unknown): error is APICallError {\n return (\n error instanceof Error &&\n error.name === 'AI_APICallError' &&\n typeof (error as APICallError).url === 'string' &&\n typeof (error as APICallError).requestBodyValues === 'object' &&\n ((error as APICallError).statusCode == null ||\n typeof (error as APICallError).statusCode === 'number') &&\n ((error as APICallError).responseHeaders == null ||\n typeof (error as APICallError).responseHeaders === 'object') &&\n ((error as APICallError).responseBody == null ||\n typeof (error as APICallError).responseBody === 'string') &&\n ((error as APICallError).cause == null ||\n typeof (error as APICallError).cause === 'object') &&\n typeof (error as APICallError).isRetryable === 'boolean' &&\n ((error as APICallError).data == null ||\n typeof (error as APICallError).data === 'object')\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n url: this.url,\n requestBodyValues: this.requestBodyValues,\n statusCode: this.statusCode,\n responseHeaders: this.responseHeaders,\n responseBody: this.responseBody,\n cause: this.cause,\n isRetryable: this.isRetryable,\n data: this.data,\n };\n }\n}\n","export class EmptyResponseBodyError extends Error {\n constructor({ message = 'Empty response body' }: { message?: string } = {}) {\n super(message);\n\n this.name = 'AI_EmptyResponseBodyError';\n }\n\n static isEmptyResponseBodyError(\n error: unknown,\n ): error is EmptyResponseBodyError {\n return error instanceof Error && error.name === 'AI_EmptyResponseBodyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class InvalidArgumentError extends Error {\n readonly parameter: string;\n readonly value: unknown;\n\n constructor({\n parameter,\n value,\n message,\n }: {\n parameter: string;\n value: unknown;\n message: string;\n }) {\n super(`Invalid argument for parameter ${parameter}: ${message}`);\n\n this.name = 'AI_InvalidArgumentError';\n\n this.parameter = parameter;\n this.value = value;\n }\n\n static isInvalidArgumentError(error: unknown): error is InvalidArgumentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidArgumentError' &&\n typeof (error as InvalidArgumentError).parameter === 'string' &&\n typeof (error as InvalidArgumentError).value === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n parameter: this.parameter,\n value: this.value,\n };\n }\n}\n","export class InvalidDataContentError extends Error {\n readonly content: unknown;\n\n constructor({\n content,\n message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`,\n }: {\n content: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidDataContentError';\n\n this.content = content;\n }\n\n static isInvalidDataContentError(\n error: unknown,\n ): error is InvalidDataContentError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidDataContentError' &&\n (error as InvalidDataContentError).content != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n content: this.content,\n };\n }\n}\n","export class InvalidPromptError extends Error {\n readonly prompt: unknown;\n\n constructor({ prompt, message }: { prompt: unknown; message: string }) {\n super(`Invalid prompt: ${message}`);\n\n this.name = 'AI_InvalidPromptError';\n\n this.prompt = prompt;\n }\n\n static isInvalidPromptError(error: unknown): error is InvalidPromptError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidPromptError' &&\n prompt != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n prompt: this.prompt,\n };\n }\n}\n","/**\nServer returned a response with invalid data content. This should be thrown by providers when they\ncannot parse the response from the API.\n */\nexport class InvalidResponseDataError extends Error {\n readonly data: unknown;\n\n constructor({\n data,\n message = `Invalid response data: ${JSON.stringify(data)}.`,\n }: {\n data: unknown;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_InvalidResponseDataError';\n\n this.data = data;\n }\n\n static isInvalidResponseDataError(\n error: unknown,\n ): error is InvalidResponseDataError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidResponseDataError' &&\n (error as InvalidResponseDataError).data != null\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n data: this.data,\n };\n }\n}\n","export function getErrorMessage(error: unknown | undefined) {\n if (error == null) {\n return 'unknown error';\n }\n\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n return JSON.stringify(error);\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class InvalidToolArgumentsError extends Error {\n readonly toolName: string;\n readonly toolArgs: string;\n readonly cause: unknown;\n\n constructor({\n toolArgs,\n toolName,\n cause,\n message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(\n cause,\n )}`,\n }: {\n message?: string;\n toolArgs: string;\n toolName: string;\n cause: unknown;\n }) {\n super(message);\n\n this.name = 'AI_InvalidToolArgumentsError';\n\n this.toolArgs = toolArgs;\n this.toolName = toolName;\n this.cause = cause;\n }\n\n static isInvalidToolArgumentsError(\n error: unknown,\n ): error is InvalidToolArgumentsError {\n return (\n error instanceof Error &&\n error.name === 'AI_InvalidToolArgumentsError' &&\n typeof (error as InvalidToolArgumentsError).toolName === 'string' &&\n typeof (error as InvalidToolArgumentsError).toolArgs === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n toolName: this.toolName,\n toolArgs: this.toolArgs,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class JSONParseError extends Error {\n // note: property order determines debugging output\n readonly text: string;\n readonly cause: unknown;\n\n constructor({ text, cause }: { text: string; cause: unknown }) {\n super(\n `JSON parsing failed: ` +\n `Text: ${text}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_JSONParseError';\n\n this.cause = cause;\n this.text = text;\n }\n\n static isJSONParseError(error: unknown): error is JSONParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_JSONParseError' &&\n typeof (error as JSONParseError).text === 'string' &&\n typeof (error as JSONParseError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n valueText: this.text,\n };\n }\n}\n","export class LoadAPIKeyError extends Error {\n constructor({ message }: { message: string }) {\n super(message);\n\n this.name = 'AI_LoadAPIKeyError';\n }\n\n static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError {\n return error instanceof Error && error.name === 'AI_LoadAPIKeyError';\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n };\n }\n}\n","export class NoTextGeneratedError extends Error {\n readonly cause: unknown;\n\n constructor() {\n super(`No text generated.`);\n\n this.name = 'AI_NoTextGeneratedError';\n }\n\n static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError {\n return error instanceof Error && error.name === 'AI_NoTextGeneratedError';\n }\n\n toJSON() {\n return {\n name: this.name,\n cause: this.cause,\n message: this.message,\n stack: this.stack,\n };\n }\n}\n","export class NoSuchToolError extends Error {\n readonly toolName: string;\n readonly availableTools: string[] | undefined;\n\n constructor({\n toolName,\n availableTools = undefined,\n message = `Model tried to call unavailable tool '${toolName}'. ${\n availableTools === undefined\n ? 'No tools are available.'\n : `Available tools: ${availableTools.join(', ')}.`\n }`,\n }: {\n toolName: string;\n availableTools?: string[] | undefined;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_NoSuchToolError';\n\n this.toolName = toolName;\n this.availableTools = availableTools;\n }\n\n static isNoSuchToolError(error: unknown): error is NoSuchToolError {\n return (\n error instanceof Error &&\n error.name === 'AI_NoSuchToolError' &&\n 'toolName' in error &&\n error.toolName != undefined &&\n typeof error.name === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n toolName: this.toolName,\n availableTools: this.availableTools,\n };\n }\n}\n","export type RetryErrorReason =\n | 'maxRetriesExceeded'\n | 'errorNotRetryable'\n | 'abort';\n\nexport class RetryError extends Error {\n // note: property order determines debugging output\n readonly reason: RetryErrorReason;\n readonly lastError: unknown;\n readonly errors: Array<unknown>;\n\n constructor({\n message,\n reason,\n errors,\n }: {\n message: string;\n reason: RetryErrorReason;\n errors: Array<unknown>;\n }) {\n super(message);\n\n this.name = 'AI_RetryError';\n this.reason = reason;\n this.errors = errors;\n\n // separate our last error to make debugging via log easier:\n this.lastError = errors[errors.length - 1];\n }\n\n static isRetryError(error: unknown): error is RetryError {\n return (\n error instanceof Error &&\n error.name === 'AI_RetryError' &&\n typeof (error as RetryError).reason === 'string' &&\n Array.isArray((error as RetryError).errors)\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n reason: this.reason,\n lastError: this.lastError,\n errors: this.errors,\n };\n }\n}\n","import { LanguageModelV1FunctionTool } from '../language-model/v1/language-model-v1-function-tool';\nimport { getErrorMessage } from './get-error-message';\n\nexport class ToolCallParseError extends Error {\n readonly cause: unknown;\n readonly text: string;\n readonly tools: LanguageModelV1FunctionTool[];\n\n constructor({\n cause,\n text,\n tools,\n message = `Failed to parse tool calls: ${getErrorMessage(cause)}`,\n }: {\n cause: unknown;\n text: string;\n tools: LanguageModelV1FunctionTool[];\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_ToolCallParseError';\n\n this.cause = cause;\n this.text = text;\n this.tools = tools;\n }\n\n static isToolCallParseError(error: unknown): error is ToolCallParseError {\n return (\n error instanceof Error &&\n error.name === 'AI_ToolCallParseError' &&\n 'cause' in error &&\n error.cause != undefined &&\n 'text' in error &&\n error.text != undefined &&\n typeof error.text === 'string' &&\n 'tools' in error &&\n error.tools != undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n cause: this.cause,\n text: this.text,\n tools: this.tools,\n };\n }\n}\n","import { getErrorMessage } from './get-error-message';\n\nexport class TypeValidationError extends Error {\n readonly value: unknown;\n readonly cause: unknown;\n\n constructor({ value, cause }: { value: unknown; cause: unknown }) {\n super(\n `Type validation failed: ` +\n `Value: ${JSON.stringify(value)}.\\n` +\n `Error message: ${getErrorMessage(cause)}`,\n );\n\n this.name = 'AI_TypeValidationError';\n\n this.cause = cause;\n this.value = value;\n }\n\n static isTypeValidationError(error: unknown): error is TypeValidationError {\n return (\n error instanceof Error &&\n error.name === 'AI_TypeValidationError' &&\n typeof (error as TypeValidationError).value === 'string' &&\n typeof (error as TypeValidationError).cause === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n cause: this.cause,\n stack: this.stack,\n\n value: this.value,\n };\n }\n}\n","export class UnsupportedFunctionalityError extends Error {\n readonly functionality: string;\n\n constructor({ functionality }: { functionality: string }) {\n super(`'${functionality}' functionality not supported.`);\n\n this.name = 'AI_UnsupportedFunctionalityError';\n\n this.functionality = functionality;\n }\n\n static isUnsupportedFunctionalityError(\n error: unknown,\n ): error is UnsupportedFunctionalityError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedFunctionalityError' &&\n typeof (error as UnsupportedFunctionalityError).functionality === 'string'\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n functionality: this.functionality,\n };\n }\n}\n","export class UnsupportedJSONSchemaError extends Error {\n readonly reason: string;\n readonly schema: unknown;\n\n constructor({\n schema,\n reason,\n message = `Unsupported JSON schema: ${reason}`,\n }: {\n schema: unknown;\n reason: string;\n message?: string;\n }) {\n super(message);\n\n this.name = 'AI_UnsupportedJSONSchemaError';\n\n this.reason = reason;\n this.schema = schema;\n }\n\n static isUnsupportedJSONSchemaError(\n error: unknown,\n ): error is UnsupportedJSONSchemaError {\n return (\n error instanceof Error &&\n error.name === 'AI_UnsupportedJSONSchemaError' &&\n 'reason' in error &&\n error.reason != undefined &&\n 'schema' in error &&\n error.schema !== undefined\n );\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n\n reason: this.reason,\n schema: this.schema,\n };\n }\n}\n"],"mappings":";AAAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAYtC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc,SACzB,eAAe;AAAA,IACd,eAAe;AAAA,IACf,eAAe;AAAA,IACf,cAAc;AAAA;AAAA,IAClB;AAAA,EACF,GAUG;AACD,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,SAAK,MAAM;AACX,SAAK,oBAAoB;AACzB,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AACpB,SAAK,QAAQ;AACb,SAAK,cAAc;AACnB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,eAAe,OAAuC;AAC3D,WACE,iBAAiB,SACjB,MAAM,SAAS,qBACf,OAAQ,MAAuB,QAAQ,YACvC,OAAQ,MAAuB,sBAAsB,aACnD,MAAuB,cAAc,QACrC,OAAQ,MAAuB,eAAe,cAC9C,MAAuB,m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