@ai-sdk/provider 4.0.18 → 4.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,452 +1,401 @@
1
- // src/errors/ai-sdk-error.ts
2
- var marker = "vercel.ai.error";
3
- var symbol = Symbol.for(marker);
4
- var _a, _b;
5
- var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
6
- /**
7
- * Creates an AI SDK Error.
8
- *
9
- * @param {Object} params - The parameters for creating the error.
10
- * @param {string} params.name - The name of the error.
11
- * @param {string} params.message - The error message.
12
- * @param {unknown} [params.cause] - The underlying cause of the error.
13
- */
14
- constructor({
15
- name: name16,
16
- message,
17
- cause
18
- }) {
19
- super(message);
20
- this[_a] = true;
21
- this.name = name16;
22
- this.cause = cause;
23
- }
24
- /**
25
- * Checks if the given error is an AI SDK Error.
26
- * @param {unknown} error - The error to check.
27
- * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
28
- */
29
- static isInstance(error) {
30
- return _AISDKError.hasMarker(error, marker);
31
- }
32
- static hasMarker(error, marker17) {
33
- const markerSymbol = Symbol.for(marker17);
34
- return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
35
- }
1
+ //#region src/errors/ai-sdk-error.ts
2
+ /**
3
+ * Symbol used for identifying AI SDK Error instances.
4
+ * Enables checking if an error is an instance of AISDKError across package versions.
5
+ */
6
+ const marker$15 = "vercel.ai.error";
7
+ const symbol$15 = Symbol.for(marker$15);
8
+ /**
9
+ * Custom error class for AI SDK related errors.
10
+ * @extends Error
11
+ */
12
+ var AISDKError = class AISDKError extends Error {
13
+ /**
14
+ * Creates an AI SDK Error.
15
+ *
16
+ * @param {Object} params - The parameters for creating the error.
17
+ * @param {string} params.name - The name of the error.
18
+ * @param {string} params.message - The error message.
19
+ * @param {unknown} [params.cause] - The underlying cause of the error.
20
+ */
21
+ constructor({ name, message, cause }) {
22
+ super(message);
23
+ this[symbol$15] = true;
24
+ this.name = name;
25
+ this.cause = cause;
26
+ }
27
+ /**
28
+ * Checks if the given error is an AI SDK Error.
29
+ * @param {unknown} error - The error to check.
30
+ * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
31
+ */
32
+ static isInstance(error) {
33
+ return AISDKError.hasMarker(error, marker$15);
34
+ }
35
+ static hasMarker(error, marker) {
36
+ const markerSymbol = Symbol.for(marker);
37
+ return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
38
+ }
36
39
  };
37
-
38
- // src/errors/api-call-error.ts
39
- var name = "AI_APICallError";
40
- var marker2 = `vercel.ai.error.${name}`;
41
- var symbol2 = Symbol.for(marker2);
42
- var _a2, _b2;
43
- var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
44
- constructor({
45
- message,
46
- url,
47
- requestBodyValues,
48
- statusCode,
49
- responseHeaders,
50
- responseBody,
51
- cause,
52
- isRetryable = statusCode != null && (statusCode === 408 || // request timeout
53
- statusCode === 409 || // conflict
54
- statusCode === 429 || // too many requests
55
- statusCode >= 500),
56
- // server error
57
- data
58
- }) {
59
- super({ name, message, cause });
60
- this[_a2] = true;
61
- this.url = url;
62
- this.requestBodyValues = requestBodyValues;
63
- this.statusCode = statusCode;
64
- this.responseHeaders = responseHeaders;
65
- this.responseBody = responseBody;
66
- this.isRetryable = isRetryable;
67
- this.data = data;
68
- }
69
- static isInstance(error) {
70
- return AISDKError.hasMarker(error, marker2);
71
- }
40
+ //#endregion
41
+ //#region src/errors/api-call-error.ts
42
+ const name$14 = "AI_APICallError";
43
+ const marker$14 = `vercel.ai.error.${name$14}`;
44
+ const symbol$14 = Symbol.for(marker$14);
45
+ var APICallError = class extends AISDKError {
46
+ constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
47
+ super({
48
+ name: name$14,
49
+ message,
50
+ cause
51
+ });
52
+ this[symbol$14] = true;
53
+ this.url = url;
54
+ this.requestBodyValues = requestBodyValues;
55
+ this.statusCode = statusCode;
56
+ this.responseHeaders = responseHeaders;
57
+ this.responseBody = responseBody;
58
+ this.isRetryable = isRetryable;
59
+ this.data = data;
60
+ }
61
+ static isInstance(error) {
62
+ return AISDKError.hasMarker(error, marker$14);
63
+ }
72
64
  };
73
-
74
- // src/errors/empty-response-body-error.ts
75
- var name2 = "AI_EmptyResponseBodyError";
76
- var marker3 = `vercel.ai.error.${name2}`;
77
- var symbol3 = Symbol.for(marker3);
78
- var _a3, _b3;
79
- var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
80
- // used in isInstance
81
- constructor({ message = "Empty response body" } = {}) {
82
- super({ name: name2, message });
83
- this[_a3] = true;
84
- }
85
- static isInstance(error) {
86
- return AISDKError.hasMarker(error, marker3);
87
- }
65
+ //#endregion
66
+ //#region src/errors/empty-response-body-error.ts
67
+ const name$13 = "AI_EmptyResponseBodyError";
68
+ const marker$13 = `vercel.ai.error.${name$13}`;
69
+ const symbol$13 = Symbol.for(marker$13);
70
+ var EmptyResponseBodyError = class extends AISDKError {
71
+ constructor({ message = "Empty response body" } = {}) {
72
+ super({
73
+ name: name$13,
74
+ message
75
+ });
76
+ this[symbol$13] = true;
77
+ }
78
+ static isInstance(error) {
79
+ return AISDKError.hasMarker(error, marker$13);
80
+ }
88
81
  };
89
-
90
- // src/errors/evaluation-unsupported-question-type-error.ts
91
- var name3 = "AI_EvaluationUnsupportedQuestionTypeError";
92
- var marker4 = `vercel.ai.error.${name3}`;
93
- var symbol4 = Symbol.for(marker4);
94
- var _a4, _b4;
95
- var EvaluationUnsupportedQuestionTypeError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
96
- constructor({
97
- questionId,
98
- questionType,
99
- provider,
100
- modelId,
101
- message = `Question "${questionId}" has type "${questionType}", which is not supported by provider "${provider}" and model "${modelId}".`
102
- }) {
103
- super({ name: name3, message });
104
- this[_a4] = true;
105
- this.questionId = questionId;
106
- this.questionType = questionType;
107
- this.provider = provider;
108
- this.modelId = modelId;
109
- }
110
- static isInstance(error) {
111
- return AISDKError.hasMarker(error, marker4);
112
- }
82
+ //#endregion
83
+ //#region src/errors/evaluation-unsupported-question-type-error.ts
84
+ const name$12 = "AI_EvaluationUnsupportedQuestionTypeError";
85
+ const marker$12 = `vercel.ai.error.${name$12}`;
86
+ const symbol$12 = Symbol.for(marker$12);
87
+ /**
88
+ * An evaluation model does not support the type of a requested question.
89
+ */
90
+ var EvaluationUnsupportedQuestionTypeError = class extends AISDKError {
91
+ constructor({ questionId, questionType, provider, modelId, message = `Question "${questionId}" has type "${questionType}", which is not supported by provider "${provider}" and model "${modelId}".` }) {
92
+ super({
93
+ name: name$12,
94
+ message
95
+ });
96
+ this[symbol$12] = true;
97
+ this.questionId = questionId;
98
+ this.questionType = questionType;
99
+ this.provider = provider;
100
+ this.modelId = modelId;
101
+ }
102
+ static isInstance(error) {
103
+ return AISDKError.hasMarker(error, marker$12);
104
+ }
113
105
  };
114
-
115
- // src/errors/get-error-message.ts
106
+ //#endregion
107
+ //#region src/errors/get-error-message.ts
116
108
  function getErrorMessage(error) {
117
- if (error == null) {
118
- return "unknown error";
119
- }
120
- if (typeof error === "string") {
121
- return error;
122
- }
123
- if (error instanceof Error) {
124
- return error.toString();
125
- }
126
- return JSON.stringify(error);
109
+ if (error == null) return "unknown error";
110
+ if (typeof error === "string") return error;
111
+ if (error instanceof Error) return error.toString();
112
+ return JSON.stringify(error);
127
113
  }
128
-
129
- // src/errors/invalid-argument-error.ts
130
- var name4 = "AI_InvalidArgumentError";
131
- var marker5 = `vercel.ai.error.${name4}`;
132
- var symbol5 = Symbol.for(marker5);
133
- var _a5, _b5;
134
- var InvalidArgumentError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
135
- constructor({
136
- message,
137
- cause,
138
- argument
139
- }) {
140
- super({ name: name4, message, cause });
141
- this[_a5] = true;
142
- this.argument = argument;
143
- }
144
- static isInstance(error) {
145
- return AISDKError.hasMarker(error, marker5);
146
- }
114
+ //#endregion
115
+ //#region src/errors/invalid-argument-error.ts
116
+ const name$11 = "AI_InvalidArgumentError";
117
+ const marker$11 = `vercel.ai.error.${name$11}`;
118
+ const symbol$11 = Symbol.for(marker$11);
119
+ /**
120
+ * A function argument is invalid.
121
+ */
122
+ var InvalidArgumentError = class extends AISDKError {
123
+ constructor({ message, cause, argument }) {
124
+ super({
125
+ name: name$11,
126
+ message,
127
+ cause
128
+ });
129
+ this[symbol$11] = true;
130
+ this.argument = argument;
131
+ }
132
+ static isInstance(error) {
133
+ return AISDKError.hasMarker(error, marker$11);
134
+ }
147
135
  };
148
-
149
- // src/errors/invalid-prompt-error.ts
150
- var name5 = "AI_InvalidPromptError";
151
- var marker6 = `vercel.ai.error.${name5}`;
152
- var symbol6 = Symbol.for(marker6);
153
- var _a6, _b6;
154
- var InvalidPromptError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
155
- constructor({
156
- prompt,
157
- message,
158
- cause
159
- }) {
160
- super({ name: name5, message: `Invalid prompt: ${message}`, cause });
161
- this[_a6] = true;
162
- this.prompt = prompt;
163
- }
164
- static isInstance(error) {
165
- return AISDKError.hasMarker(error, marker6);
166
- }
136
+ //#endregion
137
+ //#region src/errors/invalid-prompt-error.ts
138
+ const name$10 = "AI_InvalidPromptError";
139
+ const marker$10 = `vercel.ai.error.${name$10}`;
140
+ const symbol$10 = Symbol.for(marker$10);
141
+ /**
142
+ * A prompt is invalid. This error should be thrown by providers when they cannot
143
+ * process a prompt.
144
+ */
145
+ var InvalidPromptError = class extends AISDKError {
146
+ constructor({ prompt, message, cause }) {
147
+ super({
148
+ name: name$10,
149
+ message: `Invalid prompt: ${message}`,
150
+ cause
151
+ });
152
+ this[symbol$10] = true;
153
+ this.prompt = prompt;
154
+ }
155
+ static isInstance(error) {
156
+ return AISDKError.hasMarker(error, marker$10);
157
+ }
167
158
  };
168
-
169
- // src/errors/invalid-response-data-error.ts
170
- var name6 = "AI_InvalidResponseDataError";
171
- var marker7 = `vercel.ai.error.${name6}`;
172
- var symbol7 = Symbol.for(marker7);
173
- var _a7, _b7;
174
- var InvalidResponseDataError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
175
- constructor({
176
- data,
177
- message = `Invalid response data: ${JSON.stringify(data)}.`
178
- }) {
179
- super({ name: name6, message });
180
- this[_a7] = true;
181
- this.data = data;
182
- }
183
- static isInstance(error) {
184
- return AISDKError.hasMarker(error, marker7);
185
- }
159
+ //#endregion
160
+ //#region src/errors/invalid-response-data-error.ts
161
+ const name$9 = "AI_InvalidResponseDataError";
162
+ const marker$9 = `vercel.ai.error.${name$9}`;
163
+ const symbol$9 = Symbol.for(marker$9);
164
+ /**
165
+ * Server returned a response with invalid data content.
166
+ * This should be thrown by providers when they cannot parse the response from the API.
167
+ */
168
+ var InvalidResponseDataError = class extends AISDKError {
169
+ constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
170
+ super({
171
+ name: name$9,
172
+ message
173
+ });
174
+ this[symbol$9] = true;
175
+ this.data = data;
176
+ }
177
+ static isInstance(error) {
178
+ return AISDKError.hasMarker(error, marker$9);
179
+ }
186
180
  };
187
-
188
- // src/errors/json-parse-error.ts
189
- var name7 = "AI_JSONParseError";
190
- var marker8 = `vercel.ai.error.${name7}`;
191
- var symbol8 = Symbol.for(marker8);
192
- var _a8, _b8;
193
- var JSONParseError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
194
- constructor({ text, cause }) {
195
- super({
196
- name: name7,
197
- message: `JSON parsing failed: Text: ${text}.
198
- Error message: ${getErrorMessage(cause)}`,
199
- cause
200
- });
201
- this[_a8] = true;
202
- this.text = text;
203
- }
204
- static isInstance(error) {
205
- return AISDKError.hasMarker(error, marker8);
206
- }
181
+ //#endregion
182
+ //#region src/errors/json-parse-error.ts
183
+ const name$8 = "AI_JSONParseError";
184
+ const marker$8 = `vercel.ai.error.${name$8}`;
185
+ const symbol$8 = Symbol.for(marker$8);
186
+ var JSONParseError = class extends AISDKError {
187
+ constructor({ text, cause }) {
188
+ super({
189
+ name: name$8,
190
+ message: `JSON parsing failed: Text: ${text}.\nError message: ${getErrorMessage(cause)}`,
191
+ cause
192
+ });
193
+ this[symbol$8] = true;
194
+ this.text = text;
195
+ }
196
+ static isInstance(error) {
197
+ return AISDKError.hasMarker(error, marker$8);
198
+ }
207
199
  };
208
-
209
- // src/errors/load-api-key-error.ts
210
- var name8 = "AI_LoadAPIKeyError";
211
- var marker9 = `vercel.ai.error.${name8}`;
212
- var symbol9 = Symbol.for(marker9);
213
- var _a9, _b9;
214
- var LoadAPIKeyError = class extends (_b9 = AISDKError, _a9 = symbol9, _b9) {
215
- // used in isInstance
216
- constructor({ message }) {
217
- super({ name: name8, message });
218
- this[_a9] = true;
219
- }
220
- static isInstance(error) {
221
- return AISDKError.hasMarker(error, marker9);
222
- }
200
+ //#endregion
201
+ //#region src/errors/load-api-key-error.ts
202
+ const name$7 = "AI_LoadAPIKeyError";
203
+ const marker$7 = `vercel.ai.error.${name$7}`;
204
+ const symbol$7 = Symbol.for(marker$7);
205
+ var LoadAPIKeyError = class extends AISDKError {
206
+ constructor({ message }) {
207
+ super({
208
+ name: name$7,
209
+ message
210
+ });
211
+ this[symbol$7] = true;
212
+ }
213
+ static isInstance(error) {
214
+ return AISDKError.hasMarker(error, marker$7);
215
+ }
223
216
  };
224
-
225
- // src/errors/load-setting-error.ts
226
- var name9 = "AI_LoadSettingError";
227
- var marker10 = `vercel.ai.error.${name9}`;
228
- var symbol10 = Symbol.for(marker10);
229
- var _a10, _b10;
230
- var LoadSettingError = class extends (_b10 = AISDKError, _a10 = symbol10, _b10) {
231
- // used in isInstance
232
- constructor({ message }) {
233
- super({ name: name9, message });
234
- this[_a10] = true;
235
- }
236
- static isInstance(error) {
237
- return AISDKError.hasMarker(error, marker10);
238
- }
217
+ //#endregion
218
+ //#region src/errors/load-setting-error.ts
219
+ const name$6 = "AI_LoadSettingError";
220
+ const marker$6 = `vercel.ai.error.${name$6}`;
221
+ const symbol$6 = Symbol.for(marker$6);
222
+ var LoadSettingError = class extends AISDKError {
223
+ constructor({ message }) {
224
+ super({
225
+ name: name$6,
226
+ message
227
+ });
228
+ this[symbol$6] = true;
229
+ }
230
+ static isInstance(error) {
231
+ return AISDKError.hasMarker(error, marker$6);
232
+ }
239
233
  };
240
-
241
- // src/errors/no-content-generated-error.ts
242
- var name10 = "AI_NoContentGeneratedError";
243
- var marker11 = `vercel.ai.error.${name10}`;
244
- var symbol11 = Symbol.for(marker11);
245
- var _a11, _b11;
246
- var NoContentGeneratedError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
247
- // used in isInstance
248
- constructor({
249
- message = "No content generated."
250
- } = {}) {
251
- super({ name: name10, message });
252
- this[_a11] = true;
253
- }
254
- static isInstance(error) {
255
- return AISDKError.hasMarker(error, marker11);
256
- }
234
+ //#endregion
235
+ //#region src/errors/no-content-generated-error.ts
236
+ const name$5 = "AI_NoContentGeneratedError";
237
+ const marker$5 = `vercel.ai.error.${name$5}`;
238
+ const symbol$5 = Symbol.for(marker$5);
239
+ /**
240
+ * Thrown when the AI provider fails to generate any content.
241
+ */
242
+ var NoContentGeneratedError = class extends AISDKError {
243
+ constructor({ message = "No content generated." } = {}) {
244
+ super({
245
+ name: name$5,
246
+ message
247
+ });
248
+ this[symbol$5] = true;
249
+ }
250
+ static isInstance(error) {
251
+ return AISDKError.hasMarker(error, marker$5);
252
+ }
257
253
  };
258
-
259
- // src/errors/no-such-model-error.ts
260
- var name11 = "AI_NoSuchModelError";
261
- var marker12 = `vercel.ai.error.${name11}`;
262
- var symbol12 = Symbol.for(marker12);
263
- var _a12, _b12;
264
- var NoSuchModelError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
265
- constructor({
266
- errorName = name11,
267
- modelId,
268
- modelType,
269
- message = `No such ${modelType}: ${modelId}`
270
- }) {
271
- super({ name: errorName, message });
272
- this[_a12] = true;
273
- this.modelId = modelId;
274
- this.modelType = modelType;
275
- }
276
- static isInstance(error) {
277
- return AISDKError.hasMarker(error, marker12);
278
- }
254
+ //#endregion
255
+ //#region src/errors/no-such-model-error.ts
256
+ const name$4 = "AI_NoSuchModelError";
257
+ const marker$4 = `vercel.ai.error.${name$4}`;
258
+ const symbol$4 = Symbol.for(marker$4);
259
+ var NoSuchModelError = class extends AISDKError {
260
+ constructor({ errorName = name$4, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
261
+ super({
262
+ name: errorName,
263
+ message
264
+ });
265
+ this[symbol$4] = true;
266
+ this.modelId = modelId;
267
+ this.modelType = modelType;
268
+ }
269
+ static isInstance(error) {
270
+ return AISDKError.hasMarker(error, marker$4);
271
+ }
279
272
  };
280
-
281
- // src/errors/no-such-provider-reference-error.ts
282
- var name12 = "AI_NoSuchProviderReferenceError";
283
- var marker13 = `vercel.ai.error.${name12}`;
284
- var symbol13 = Symbol.for(marker13);
285
- var _a13, _b13;
286
- var NoSuchProviderReferenceError = class extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
287
- constructor({
288
- provider,
289
- reference,
290
- message = `No provider reference found for provider '${provider}'. Available providers: ${Object.keys(reference).join(", ")}`
291
- }) {
292
- super({ name: name12, message });
293
- this[_a13] = true;
294
- this.provider = provider;
295
- this.reference = reference;
296
- }
297
- static isInstance(error) {
298
- return AISDKError.hasMarker(error, marker13);
299
- }
273
+ //#endregion
274
+ //#region src/errors/no-such-provider-reference-error.ts
275
+ const name$3 = "AI_NoSuchProviderReferenceError";
276
+ const marker$3 = `vercel.ai.error.${name$3}`;
277
+ const symbol$3 = Symbol.for(marker$3);
278
+ /**
279
+ * Thrown when a provider reference cannot be resolved because the specified
280
+ * provider is not found in the provider reference mapping.
281
+ */
282
+ var NoSuchProviderReferenceError = class extends AISDKError {
283
+ constructor({ provider, reference, message = `No provider reference found for provider '${provider}'. Available providers: ${Object.keys(reference).join(", ")}` }) {
284
+ super({
285
+ name: name$3,
286
+ message
287
+ });
288
+ this[symbol$3] = true;
289
+ this.provider = provider;
290
+ this.reference = reference;
291
+ }
292
+ static isInstance(error) {
293
+ return AISDKError.hasMarker(error, marker$3);
294
+ }
300
295
  };
301
-
302
- // src/errors/too-many-embedding-values-for-call-error.ts
303
- var name13 = "AI_TooManyEmbeddingValuesForCallError";
304
- var marker14 = `vercel.ai.error.${name13}`;
305
- var symbol14 = Symbol.for(marker14);
306
- var _a14, _b14;
307
- var TooManyEmbeddingValuesForCallError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
308
- constructor(options) {
309
- super({
310
- name: name13,
311
- message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
312
- });
313
- this[_a14] = true;
314
- this.provider = options.provider;
315
- this.modelId = options.modelId;
316
- this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
317
- this.values = options.values;
318
- }
319
- static isInstance(error) {
320
- return AISDKError.hasMarker(error, marker14);
321
- }
296
+ //#endregion
297
+ //#region src/errors/too-many-embedding-values-for-call-error.ts
298
+ const name$2 = "AI_TooManyEmbeddingValuesForCallError";
299
+ const marker$2 = `vercel.ai.error.${name$2}`;
300
+ const symbol$2 = Symbol.for(marker$2);
301
+ var TooManyEmbeddingValuesForCallError = class extends AISDKError {
302
+ constructor(options) {
303
+ super({
304
+ name: name$2,
305
+ message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
306
+ });
307
+ this[symbol$2] = true;
308
+ this.provider = options.provider;
309
+ this.modelId = options.modelId;
310
+ this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
311
+ this.values = options.values;
312
+ }
313
+ static isInstance(error) {
314
+ return AISDKError.hasMarker(error, marker$2);
315
+ }
322
316
  };
323
-
324
- // src/errors/type-validation-error.ts
325
- var name14 = "AI_TypeValidationError";
326
- var marker15 = `vercel.ai.error.${name14}`;
327
- var symbol15 = Symbol.for(marker15);
328
- var _a15, _b15;
329
- var TypeValidationError = class _TypeValidationError extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
330
- constructor({
331
- value,
332
- cause,
333
- context
334
- }) {
335
- let contextPrefix = "Type validation failed";
336
- if (context == null ? void 0 : context.field) {
337
- contextPrefix += ` for ${context.field}`;
338
- }
339
- if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
340
- contextPrefix += " (";
341
- const parts = [];
342
- if (context.entityName) {
343
- parts.push(context.entityName);
344
- }
345
- if (context.entityId) {
346
- parts.push(`id: "${context.entityId}"`);
347
- }
348
- contextPrefix += parts.join(", ");
349
- contextPrefix += ")";
350
- }
351
- super({
352
- name: name14,
353
- message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
354
- Error message: ${getErrorMessage(cause)}`,
355
- cause
356
- });
357
- this[_a15] = true;
358
- this.value = value;
359
- this.context = context;
360
- }
361
- static isInstance(error) {
362
- return AISDKError.hasMarker(error, marker15);
363
- }
364
- /**
365
- * Wraps an error into a TypeValidationError.
366
- * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
367
- * Otherwise, it creates a new TypeValidationError.
368
- *
369
- * @param {Object} params - The parameters for wrapping the error.
370
- * @param {unknown} params.value - The value that failed validation.
371
- * @param {unknown} params.cause - The original error or cause of the validation failure.
372
- * @param {TypeValidationContext} params.context - Optional context about what is being validated.
373
- * @returns {TypeValidationError} A TypeValidationError instance.
374
- */
375
- static wrap({
376
- value,
377
- cause,
378
- context
379
- }) {
380
- var _a17, _b17, _c;
381
- if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a17 = cause.context) == null ? void 0 : _a17.field) === (context == null ? void 0 : context.field) && ((_b17 = cause.context) == null ? void 0 : _b17.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) {
382
- return cause;
383
- }
384
- return new _TypeValidationError({ value, cause, context });
385
- }
317
+ //#endregion
318
+ //#region src/errors/type-validation-error.ts
319
+ const name$1 = "AI_TypeValidationError";
320
+ const marker$1 = `vercel.ai.error.${name$1}`;
321
+ const symbol$1 = Symbol.for(marker$1);
322
+ var TypeValidationError = class TypeValidationError extends AISDKError {
323
+ constructor({ value, cause, context }) {
324
+ let contextPrefix = "Type validation failed";
325
+ if (context?.field) contextPrefix += ` for ${context.field}`;
326
+ if (context?.entityName || context?.entityId) {
327
+ contextPrefix += " (";
328
+ const parts = [];
329
+ if (context.entityName) parts.push(context.entityName);
330
+ if (context.entityId) parts.push(`id: "${context.entityId}"`);
331
+ contextPrefix += parts.join(", ");
332
+ contextPrefix += ")";
333
+ }
334
+ super({
335
+ name: name$1,
336
+ message: `${contextPrefix}: Value: ${JSON.stringify(value)}.\nError message: ${getErrorMessage(cause)}`,
337
+ cause
338
+ });
339
+ this[symbol$1] = true;
340
+ this.value = value;
341
+ this.context = context;
342
+ }
343
+ static isInstance(error) {
344
+ return AISDKError.hasMarker(error, marker$1);
345
+ }
346
+ /**
347
+ * Wraps an error into a TypeValidationError.
348
+ * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
349
+ * Otherwise, it creates a new TypeValidationError.
350
+ *
351
+ * @param {Object} params - The parameters for wrapping the error.
352
+ * @param {unknown} params.value - The value that failed validation.
353
+ * @param {unknown} params.cause - The original error or cause of the validation failure.
354
+ * @param {TypeValidationContext} params.context - Optional context about what is being validated.
355
+ * @returns {TypeValidationError} A TypeValidationError instance.
356
+ */
357
+ static wrap({ value, cause, context }) {
358
+ if (TypeValidationError.isInstance(cause) && cause.value === value && cause.context?.field === context?.field && cause.context?.entityName === context?.entityName && cause.context?.entityId === context?.entityId) return cause;
359
+ return new TypeValidationError({
360
+ value,
361
+ cause,
362
+ context
363
+ });
364
+ }
386
365
  };
387
-
388
- // src/errors/unsupported-functionality-error.ts
389
- var name15 = "AI_UnsupportedFunctionalityError";
390
- var marker16 = `vercel.ai.error.${name15}`;
391
- var symbol16 = Symbol.for(marker16);
392
- var _a16, _b16;
393
- var UnsupportedFunctionalityError = class extends (_b16 = AISDKError, _a16 = symbol16, _b16) {
394
- constructor({
395
- functionality,
396
- message = `'${functionality}' functionality not supported.`
397
- }) {
398
- super({ name: name15, message });
399
- this[_a16] = true;
400
- this.functionality = functionality;
401
- }
402
- static isInstance(error) {
403
- return AISDKError.hasMarker(error, marker16);
404
- }
366
+ //#endregion
367
+ //#region src/errors/unsupported-functionality-error.ts
368
+ const name = "AI_UnsupportedFunctionalityError";
369
+ const marker = `vercel.ai.error.${name}`;
370
+ const symbol = Symbol.for(marker);
371
+ var UnsupportedFunctionalityError = class extends AISDKError {
372
+ constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
373
+ super({
374
+ name,
375
+ message
376
+ });
377
+ this[symbol] = true;
378
+ this.functionality = functionality;
379
+ }
380
+ static isInstance(error) {
381
+ return AISDKError.hasMarker(error, marker);
382
+ }
405
383
  };
406
-
407
- // src/json-value/is-json.ts
384
+ //#endregion
385
+ //#region src/json-value/is-json.ts
408
386
  function isJSONValue(value) {
409
- if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
410
- return true;
411
- }
412
- if (Array.isArray(value)) {
413
- return value.every(isJSONValue);
414
- }
415
- if (typeof value === "object") {
416
- return Object.entries(value).every(
417
- ([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val))
418
- );
419
- }
420
- return false;
387
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
388
+ if (Array.isArray(value)) return value.every(isJSONValue);
389
+ if (typeof value === "object") return Object.entries(value).every(([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val)));
390
+ return false;
421
391
  }
422
392
  function isJSONArray(value) {
423
- return Array.isArray(value) && value.every(isJSONValue);
393
+ return Array.isArray(value) && value.every(isJSONValue);
424
394
  }
425
395
  function isJSONObject(value) {
426
- return value != null && typeof value === "object" && Object.entries(value).every(
427
- ([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val))
428
- );
396
+ return value != null && typeof value === "object" && Object.entries(value).every(([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val)));
429
397
  }
430
- export {
431
- AISDKError,
432
- APICallError,
433
- EmptyResponseBodyError,
434
- EvaluationUnsupportedQuestionTypeError as Experimental_EvaluationUnsupportedQuestionTypeError,
435
- InvalidArgumentError,
436
- InvalidPromptError,
437
- InvalidResponseDataError,
438
- JSONParseError,
439
- LoadAPIKeyError,
440
- LoadSettingError,
441
- NoContentGeneratedError,
442
- NoSuchModelError,
443
- NoSuchProviderReferenceError,
444
- TooManyEmbeddingValuesForCallError,
445
- TypeValidationError,
446
- UnsupportedFunctionalityError,
447
- getErrorMessage,
448
- isJSONArray,
449
- isJSONObject,
450
- isJSONValue
451
- };
398
+ //#endregion
399
+ export { AISDKError, APICallError, EmptyResponseBodyError, EvaluationUnsupportedQuestionTypeError as Experimental_EvaluationUnsupportedQuestionTypeError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
400
+
452
401
  //# sourceMappingURL=index.js.map