@ai-sdk/provider 0.0.14 → 0.0.16
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.d.mts +191 -233
- package/dist/index.d.ts +191 -233
- package/dist/index.js +280 -346
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +276 -335
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
|
-
for (var
|
8
|
-
__defProp(target,
|
7
|
+
for (var name12 in all)
|
8
|
+
__defProp(target, name12, { get: all[name12], enumerable: true });
|
9
9
|
};
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
@@ -20,31 +20,79 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/index.ts
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
|
+
AISDKError: () => AISDKError,
|
23
24
|
APICallError: () => APICallError,
|
24
|
-
DownloadError: () => DownloadError,
|
25
25
|
EmptyResponseBodyError: () => EmptyResponseBodyError,
|
26
|
-
InvalidArgumentError: () => InvalidArgumentError,
|
27
|
-
InvalidDataContentError: () => InvalidDataContentError,
|
28
26
|
InvalidPromptError: () => InvalidPromptError,
|
29
27
|
InvalidResponseDataError: () => InvalidResponseDataError,
|
30
|
-
InvalidToolArgumentsError: () => InvalidToolArgumentsError,
|
31
28
|
JSONParseError: () => JSONParseError,
|
32
29
|
LoadAPIKeyError: () => LoadAPIKeyError,
|
33
30
|
LoadSettingError: () => LoadSettingError,
|
34
31
|
NoContentGeneratedError: () => NoContentGeneratedError,
|
35
|
-
NoObjectGeneratedError: () => NoObjectGeneratedError,
|
36
|
-
NoSuchToolError: () => NoSuchToolError,
|
37
|
-
RetryError: () => RetryError,
|
38
32
|
TooManyEmbeddingValuesForCallError: () => TooManyEmbeddingValuesForCallError,
|
39
|
-
ToolCallParseError: () => ToolCallParseError,
|
40
33
|
TypeValidationError: () => TypeValidationError,
|
41
34
|
UnsupportedFunctionalityError: () => UnsupportedFunctionalityError,
|
42
|
-
|
35
|
+
getErrorMessage: () => getErrorMessage
|
43
36
|
});
|
44
37
|
module.exports = __toCommonJS(src_exports);
|
45
38
|
|
39
|
+
// src/errors/ai-sdk-error.ts
|
40
|
+
var marker = "vercel.ai.error";
|
41
|
+
var symbol = Symbol.for(marker);
|
42
|
+
var _a;
|
43
|
+
var _AISDKError = class _AISDKError extends Error {
|
44
|
+
/**
|
45
|
+
* Creates an AI SDK Error.
|
46
|
+
*
|
47
|
+
* @param {Object} params - The parameters for creating the error.
|
48
|
+
* @param {string} params.name - The name of the error.
|
49
|
+
* @param {string} params.message - The error message.
|
50
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
51
|
+
*/
|
52
|
+
constructor({
|
53
|
+
name: name12,
|
54
|
+
message,
|
55
|
+
cause
|
56
|
+
}) {
|
57
|
+
super(message);
|
58
|
+
this[_a] = true;
|
59
|
+
this.name = name12;
|
60
|
+
this.cause = cause;
|
61
|
+
}
|
62
|
+
/**
|
63
|
+
* Checks if the given error is an AI SDK Error.
|
64
|
+
* @param {unknown} error - The error to check.
|
65
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
66
|
+
*/
|
67
|
+
static isInstance(error) {
|
68
|
+
return _AISDKError.hasMarker(error, marker);
|
69
|
+
}
|
70
|
+
static hasMarker(error, marker13) {
|
71
|
+
const markerSymbol = Symbol.for(marker13);
|
72
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
73
|
+
}
|
74
|
+
/**
|
75
|
+
* Returns a JSON representation of the error.
|
76
|
+
* @returns {Object} An object containing the error's name, message, and cause.
|
77
|
+
*
|
78
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
79
|
+
*/
|
80
|
+
toJSON() {
|
81
|
+
return {
|
82
|
+
name: this.name,
|
83
|
+
message: this.message
|
84
|
+
};
|
85
|
+
}
|
86
|
+
};
|
87
|
+
_a = symbol;
|
88
|
+
var AISDKError = _AISDKError;
|
89
|
+
|
46
90
|
// src/errors/api-call-error.ts
|
47
|
-
var
|
91
|
+
var name = "AI_APICallError";
|
92
|
+
var marker2 = `vercel.ai.error.${name}`;
|
93
|
+
var symbol2 = Symbol.for(marker2);
|
94
|
+
var _a2;
|
95
|
+
var APICallError = class extends AISDKError {
|
48
96
|
constructor({
|
49
97
|
message,
|
50
98
|
url,
|
@@ -60,20 +108,28 @@ var APICallError = class extends Error {
|
|
60
108
|
// server error
|
61
109
|
data
|
62
110
|
}) {
|
63
|
-
super(message);
|
64
|
-
this
|
111
|
+
super({ name, message, cause });
|
112
|
+
this[_a2] = true;
|
65
113
|
this.url = url;
|
66
114
|
this.requestBodyValues = requestBodyValues;
|
67
115
|
this.statusCode = statusCode;
|
68
116
|
this.responseHeaders = responseHeaders;
|
69
117
|
this.responseBody = responseBody;
|
70
|
-
this.cause = cause;
|
71
118
|
this.isRetryable = isRetryable;
|
72
119
|
this.data = data;
|
73
120
|
}
|
121
|
+
static isInstance(error) {
|
122
|
+
return AISDKError.hasMarker(error, marker2);
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* @deprecated Use isInstance instead.
|
126
|
+
*/
|
74
127
|
static isAPICallError(error) {
|
75
|
-
return error instanceof Error && error.name ===
|
128
|
+
return error instanceof Error && error.name === name && 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");
|
76
129
|
}
|
130
|
+
/**
|
131
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
132
|
+
*/
|
77
133
|
toJSON() {
|
78
134
|
return {
|
79
135
|
name: this.name,
|
@@ -89,118 +145,71 @@ var APICallError = class extends Error {
|
|
89
145
|
};
|
90
146
|
}
|
91
147
|
};
|
92
|
-
|
93
|
-
// src/errors/download-error.ts
|
94
|
-
var DownloadError = class extends Error {
|
95
|
-
constructor({
|
96
|
-
url,
|
97
|
-
statusCode,
|
98
|
-
statusText,
|
99
|
-
cause,
|
100
|
-
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
101
|
-
}) {
|
102
|
-
super(message);
|
103
|
-
this.name = "AI_DownloadError";
|
104
|
-
this.url = url;
|
105
|
-
this.statusCode = statusCode;
|
106
|
-
this.statusText = statusText;
|
107
|
-
this.cause = cause;
|
108
|
-
}
|
109
|
-
static isDownloadError(error) {
|
110
|
-
return error instanceof Error && error.name === "AI_DownloadError" && typeof error.url === "string" && (error.statusCode == null || typeof error.statusCode === "number") && (error.statusText == null || typeof error.statusText === "string");
|
111
|
-
}
|
112
|
-
toJSON() {
|
113
|
-
return {
|
114
|
-
name: this.name,
|
115
|
-
message: this.message,
|
116
|
-
url: this.url,
|
117
|
-
statusCode: this.statusCode,
|
118
|
-
statusText: this.statusText,
|
119
|
-
cause: this.cause
|
120
|
-
};
|
121
|
-
}
|
122
|
-
};
|
148
|
+
_a2 = symbol2;
|
123
149
|
|
124
150
|
// src/errors/empty-response-body-error.ts
|
125
|
-
var
|
151
|
+
var name2 = "AI_EmptyResponseBodyError";
|
152
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
153
|
+
var symbol3 = Symbol.for(marker3);
|
154
|
+
var _a3;
|
155
|
+
var EmptyResponseBodyError = class extends AISDKError {
|
156
|
+
// used in isInstance
|
126
157
|
constructor({ message = "Empty response body" } = {}) {
|
127
|
-
super(message);
|
128
|
-
this
|
158
|
+
super({ name: name2, message });
|
159
|
+
this[_a3] = true;
|
129
160
|
}
|
130
|
-
static
|
131
|
-
return error
|
161
|
+
static isInstance(error) {
|
162
|
+
return AISDKError.hasMarker(error, marker3);
|
132
163
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
};
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
// src/errors/invalid-argument-error.ts
|
143
|
-
var InvalidArgumentError = class extends Error {
|
144
|
-
constructor({
|
145
|
-
parameter,
|
146
|
-
value,
|
147
|
-
message
|
148
|
-
}) {
|
149
|
-
super(`Invalid argument for parameter ${parameter}: ${message}`);
|
150
|
-
this.name = "AI_InvalidArgumentError";
|
151
|
-
this.parameter = parameter;
|
152
|
-
this.value = value;
|
153
|
-
}
|
154
|
-
static isInvalidArgumentError(error) {
|
155
|
-
return error instanceof Error && error.name === "AI_InvalidArgumentError" && typeof error.parameter === "string" && typeof error.value === "string";
|
156
|
-
}
|
157
|
-
toJSON() {
|
158
|
-
return {
|
159
|
-
name: this.name,
|
160
|
-
message: this.message,
|
161
|
-
stack: this.stack,
|
162
|
-
parameter: this.parameter,
|
163
|
-
value: this.value
|
164
|
-
};
|
164
|
+
/**
|
165
|
+
* @deprecated use `isInstance` instead
|
166
|
+
*/
|
167
|
+
static isEmptyResponseBodyError(error) {
|
168
|
+
return error instanceof Error && error.name === name2;
|
165
169
|
}
|
166
170
|
};
|
171
|
+
_a3 = symbol3;
|
167
172
|
|
168
|
-
// src/errors/
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
cause,
|
173
|
-
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
174
|
-
}) {
|
175
|
-
super(message);
|
176
|
-
this.name = "AI_InvalidDataContentError";
|
177
|
-
this.cause = cause;
|
178
|
-
this.content = content;
|
173
|
+
// src/errors/get-error-message.ts
|
174
|
+
function getErrorMessage(error) {
|
175
|
+
if (error == null) {
|
176
|
+
return "unknown error";
|
179
177
|
}
|
180
|
-
|
181
|
-
return error
|
178
|
+
if (typeof error === "string") {
|
179
|
+
return error;
|
182
180
|
}
|
183
|
-
|
184
|
-
return
|
185
|
-
name: this.name,
|
186
|
-
message: this.message,
|
187
|
-
stack: this.stack,
|
188
|
-
cause: this.cause,
|
189
|
-
content: this.content
|
190
|
-
};
|
181
|
+
if (error instanceof Error) {
|
182
|
+
return error.message;
|
191
183
|
}
|
192
|
-
|
184
|
+
return JSON.stringify(error);
|
185
|
+
}
|
193
186
|
|
194
187
|
// src/errors/invalid-prompt-error.ts
|
195
|
-
var
|
188
|
+
var name3 = "AI_InvalidPromptError";
|
189
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
190
|
+
var symbol4 = Symbol.for(marker4);
|
191
|
+
var _a4;
|
192
|
+
var InvalidPromptError = class extends AISDKError {
|
196
193
|
constructor({ prompt: prompt2, message }) {
|
197
|
-
super(
|
198
|
-
|
194
|
+
super({
|
195
|
+
name: name3,
|
196
|
+
message: `Invalid prompt: ${message}`
|
197
|
+
});
|
198
|
+
this[_a4] = true;
|
199
199
|
this.prompt = prompt2;
|
200
200
|
}
|
201
|
+
static isInstance(error) {
|
202
|
+
return AISDKError.hasMarker(error, marker4);
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* @deprecated use `isInstance` instead
|
206
|
+
*/
|
201
207
|
static isInvalidPromptError(error) {
|
202
|
-
return error instanceof Error && error.name ===
|
208
|
+
return error instanceof Error && error.name === name3 && prompt != null;
|
203
209
|
}
|
210
|
+
/**
|
211
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
212
|
+
*/
|
204
213
|
toJSON() {
|
205
214
|
return {
|
206
215
|
name: this.name,
|
@@ -210,20 +219,34 @@ var InvalidPromptError = class extends Error {
|
|
210
219
|
};
|
211
220
|
}
|
212
221
|
};
|
222
|
+
_a4 = symbol4;
|
213
223
|
|
214
224
|
// src/errors/invalid-response-data-error.ts
|
215
|
-
var
|
225
|
+
var name4 = "AI_InvalidResponseDataError";
|
226
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
227
|
+
var symbol5 = Symbol.for(marker5);
|
228
|
+
var _a5;
|
229
|
+
var InvalidResponseDataError = class extends AISDKError {
|
216
230
|
constructor({
|
217
231
|
data,
|
218
232
|
message = `Invalid response data: ${JSON.stringify(data)}.`
|
219
233
|
}) {
|
220
|
-
super(message);
|
221
|
-
this
|
234
|
+
super({ name: name4, message });
|
235
|
+
this[_a5] = true;
|
222
236
|
this.data = data;
|
223
237
|
}
|
238
|
+
static isInstance(error) {
|
239
|
+
return AISDKError.hasMarker(error, marker5);
|
240
|
+
}
|
241
|
+
/**
|
242
|
+
* @deprecated use `isInstance` instead
|
243
|
+
*/
|
224
244
|
static isInvalidResponseDataError(error) {
|
225
|
-
return error instanceof Error && error.name ===
|
245
|
+
return error instanceof Error && error.name === name4 && error.data != null;
|
226
246
|
}
|
247
|
+
/**
|
248
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
249
|
+
*/
|
227
250
|
toJSON() {
|
228
251
|
return {
|
229
252
|
name: this.name,
|
@@ -233,66 +256,36 @@ var InvalidResponseDataError = class extends Error {
|
|
233
256
|
};
|
234
257
|
}
|
235
258
|
};
|
236
|
-
|
237
|
-
// src/errors/get-error-message.ts
|
238
|
-
function getErrorMessage(error) {
|
239
|
-
if (error == null) {
|
240
|
-
return "unknown error";
|
241
|
-
}
|
242
|
-
if (typeof error === "string") {
|
243
|
-
return error;
|
244
|
-
}
|
245
|
-
if (error instanceof Error) {
|
246
|
-
return error.message;
|
247
|
-
}
|
248
|
-
return JSON.stringify(error);
|
249
|
-
}
|
250
|
-
|
251
|
-
// src/errors/invalid-tool-arguments-error.ts
|
252
|
-
var InvalidToolArgumentsError = class extends Error {
|
253
|
-
constructor({
|
254
|
-
toolArgs,
|
255
|
-
toolName,
|
256
|
-
cause,
|
257
|
-
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
|
258
|
-
cause
|
259
|
-
)}`
|
260
|
-
}) {
|
261
|
-
super(message);
|
262
|
-
this.name = "AI_InvalidToolArgumentsError";
|
263
|
-
this.toolArgs = toolArgs;
|
264
|
-
this.toolName = toolName;
|
265
|
-
this.cause = cause;
|
266
|
-
}
|
267
|
-
static isInvalidToolArgumentsError(error) {
|
268
|
-
return error instanceof Error && error.name === "AI_InvalidToolArgumentsError" && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
269
|
-
}
|
270
|
-
toJSON() {
|
271
|
-
return {
|
272
|
-
name: this.name,
|
273
|
-
message: this.message,
|
274
|
-
cause: this.cause,
|
275
|
-
stack: this.stack,
|
276
|
-
toolName: this.toolName,
|
277
|
-
toolArgs: this.toolArgs
|
278
|
-
};
|
279
|
-
}
|
280
|
-
};
|
259
|
+
_a5 = symbol5;
|
281
260
|
|
282
261
|
// src/errors/json-parse-error.ts
|
283
|
-
var
|
262
|
+
var name5 = "AI_JSONParseError";
|
263
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
264
|
+
var symbol6 = Symbol.for(marker6);
|
265
|
+
var _a6;
|
266
|
+
var JSONParseError = class extends AISDKError {
|
284
267
|
constructor({ text, cause }) {
|
285
|
-
super(
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
268
|
+
super({
|
269
|
+
name: name5,
|
270
|
+
message: `JSON parsing failed: Text: ${text}.
|
271
|
+
Error message: ${getErrorMessage(cause)}`,
|
272
|
+
cause
|
273
|
+
});
|
274
|
+
this[_a6] = true;
|
291
275
|
this.text = text;
|
292
276
|
}
|
277
|
+
static isInstance(error) {
|
278
|
+
return AISDKError.hasMarker(error, marker6);
|
279
|
+
}
|
280
|
+
/**
|
281
|
+
* @deprecated use `isInstance` instead
|
282
|
+
*/
|
293
283
|
static isJSONParseError(error) {
|
294
|
-
return error instanceof Error && error.name ===
|
284
|
+
return error instanceof Error && error.name === name5 && typeof error.text === "string" && typeof error.cause === "string";
|
295
285
|
}
|
286
|
+
/**
|
287
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
288
|
+
*/
|
296
289
|
toJSON() {
|
297
290
|
return {
|
298
291
|
name: this.name,
|
@@ -303,71 +296,79 @@ Error message: ${getErrorMessage(cause)}`
|
|
303
296
|
};
|
304
297
|
}
|
305
298
|
};
|
299
|
+
_a6 = symbol6;
|
306
300
|
|
307
301
|
// src/errors/load-api-key-error.ts
|
308
|
-
var
|
302
|
+
var name6 = "AI_LoadAPIKeyError";
|
303
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
304
|
+
var symbol7 = Symbol.for(marker7);
|
305
|
+
var _a7;
|
306
|
+
var LoadAPIKeyError = class extends AISDKError {
|
307
|
+
// used in isInstance
|
309
308
|
constructor({ message }) {
|
310
|
-
super(message);
|
311
|
-
this
|
309
|
+
super({ name: name6, message });
|
310
|
+
this[_a7] = true;
|
312
311
|
}
|
313
|
-
static
|
314
|
-
return error
|
312
|
+
static isInstance(error) {
|
313
|
+
return AISDKError.hasMarker(error, marker7);
|
315
314
|
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
315
|
+
/**
|
316
|
+
* @deprecated Use isInstance instead.
|
317
|
+
*/
|
318
|
+
static isLoadAPIKeyError(error) {
|
319
|
+
return error instanceof Error && error.name === name6;
|
321
320
|
}
|
322
321
|
};
|
322
|
+
_a7 = symbol7;
|
323
323
|
|
324
324
|
// src/errors/load-setting-error.ts
|
325
|
-
var
|
325
|
+
var name7 = "AI_LoadSettingError";
|
326
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
327
|
+
var symbol8 = Symbol.for(marker8);
|
328
|
+
var _a8;
|
329
|
+
var LoadSettingError = class extends AISDKError {
|
330
|
+
// used in isInstance
|
326
331
|
constructor({ message }) {
|
327
|
-
super(message);
|
328
|
-
this
|
332
|
+
super({ name: name7, message });
|
333
|
+
this[_a8] = true;
|
329
334
|
}
|
330
|
-
static
|
331
|
-
return error
|
335
|
+
static isInstance(error) {
|
336
|
+
return AISDKError.hasMarker(error, marker8);
|
332
337
|
}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
+
/**
|
339
|
+
* @deprecated Use isInstance instead.
|
340
|
+
*/
|
341
|
+
static isLoadSettingError(error) {
|
342
|
+
return error instanceof Error && error.name === name7;
|
338
343
|
}
|
339
344
|
};
|
345
|
+
_a8 = symbol8;
|
340
346
|
|
341
347
|
// src/errors/no-content-generated-error.ts
|
342
|
-
var
|
348
|
+
var name8 = "AI_NoContentGeneratedError";
|
349
|
+
var marker9 = `vercel.ai.error.${name8}`;
|
350
|
+
var symbol9 = Symbol.for(marker9);
|
351
|
+
var _a9;
|
352
|
+
var NoContentGeneratedError = class extends AISDKError {
|
353
|
+
// used in isInstance
|
343
354
|
constructor({
|
344
355
|
message = "No content generated."
|
345
356
|
} = {}) {
|
346
|
-
super(message);
|
347
|
-
this
|
348
|
-
}
|
349
|
-
static isNoContentGeneratedError(error) {
|
350
|
-
return error instanceof Error && error.name === "AI_NoContentGeneratedError";
|
357
|
+
super({ name: name8, message });
|
358
|
+
this[_a9] = true;
|
351
359
|
}
|
352
|
-
|
353
|
-
return
|
354
|
-
name: this.name,
|
355
|
-
cause: this.cause,
|
356
|
-
message: this.message,
|
357
|
-
stack: this.stack
|
358
|
-
};
|
360
|
+
static isInstance(error) {
|
361
|
+
return AISDKError.hasMarker(error, marker9);
|
359
362
|
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
super(message);
|
366
|
-
this.name = "AI_NoObjectGeneratedError";
|
367
|
-
}
|
368
|
-
static isNoObjectGeneratedError(error) {
|
369
|
-
return error instanceof Error && error.name === "AI_NoObjectGeneratedError";
|
363
|
+
/**
|
364
|
+
* @deprecated Use isInstance instead.
|
365
|
+
*/
|
366
|
+
static isNoContentGeneratedError(error) {
|
367
|
+
return error instanceof Error && error.name === name8;
|
370
368
|
}
|
369
|
+
/**
|
370
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
371
|
+
*/
|
371
372
|
toJSON() {
|
372
373
|
return {
|
373
374
|
name: this.name,
|
@@ -377,75 +378,37 @@ var NoObjectGeneratedError = class extends Error {
|
|
377
378
|
};
|
378
379
|
}
|
379
380
|
};
|
380
|
-
|
381
|
-
// src/errors/no-such-tool-error.ts
|
382
|
-
var NoSuchToolError = class extends Error {
|
383
|
-
constructor({
|
384
|
-
toolName,
|
385
|
-
availableTools = void 0,
|
386
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
387
|
-
}) {
|
388
|
-
super(message);
|
389
|
-
this.name = "AI_NoSuchToolError";
|
390
|
-
this.toolName = toolName;
|
391
|
-
this.availableTools = availableTools;
|
392
|
-
}
|
393
|
-
static isNoSuchToolError(error) {
|
394
|
-
return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
395
|
-
}
|
396
|
-
toJSON() {
|
397
|
-
return {
|
398
|
-
name: this.name,
|
399
|
-
message: this.message,
|
400
|
-
stack: this.stack,
|
401
|
-
toolName: this.toolName,
|
402
|
-
availableTools: this.availableTools
|
403
|
-
};
|
404
|
-
}
|
405
|
-
};
|
406
|
-
|
407
|
-
// src/errors/retry-error.ts
|
408
|
-
var RetryError = class extends Error {
|
409
|
-
constructor({
|
410
|
-
message,
|
411
|
-
reason,
|
412
|
-
errors
|
413
|
-
}) {
|
414
|
-
super(message);
|
415
|
-
this.name = "AI_RetryError";
|
416
|
-
this.reason = reason;
|
417
|
-
this.errors = errors;
|
418
|
-
this.lastError = errors[errors.length - 1];
|
419
|
-
}
|
420
|
-
static isRetryError(error) {
|
421
|
-
return error instanceof Error && error.name === "AI_RetryError" && typeof error.reason === "string" && Array.isArray(error.errors);
|
422
|
-
}
|
423
|
-
toJSON() {
|
424
|
-
return {
|
425
|
-
name: this.name,
|
426
|
-
message: this.message,
|
427
|
-
reason: this.reason,
|
428
|
-
lastError: this.lastError,
|
429
|
-
errors: this.errors
|
430
|
-
};
|
431
|
-
}
|
432
|
-
};
|
381
|
+
_a9 = symbol9;
|
433
382
|
|
434
383
|
// src/errors/too-many-embedding-values-for-call-error.ts
|
435
|
-
var
|
384
|
+
var name9 = "AI_TooManyEmbeddingValuesForCallError";
|
385
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
386
|
+
var symbol10 = Symbol.for(marker10);
|
387
|
+
var _a10;
|
388
|
+
var TooManyEmbeddingValuesForCallError = class extends AISDKError {
|
436
389
|
constructor(options) {
|
437
|
-
super(
|
438
|
-
|
439
|
-
|
440
|
-
|
390
|
+
super({
|
391
|
+
name: name9,
|
392
|
+
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.`
|
393
|
+
});
|
394
|
+
this[_a10] = true;
|
441
395
|
this.provider = options.provider;
|
442
396
|
this.modelId = options.modelId;
|
443
397
|
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
444
398
|
this.values = options.values;
|
445
399
|
}
|
446
|
-
static
|
447
|
-
return
|
400
|
+
static isInstance(error) {
|
401
|
+
return AISDKError.hasMarker(error, marker10);
|
448
402
|
}
|
403
|
+
/**
|
404
|
+
* @deprecated use `isInstance` instead
|
405
|
+
*/
|
406
|
+
static isTooManyEmbeddingValuesForCallError(error) {
|
407
|
+
return error instanceof Error && error.name === name9 && "provider" in error && typeof error.provider === "string" && "modelId" in error && typeof error.modelId === "string" && "maxEmbeddingsPerCall" in error && typeof error.maxEmbeddingsPerCall === "number" && "values" in error && Array.isArray(error.values);
|
408
|
+
}
|
409
|
+
/**
|
410
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
411
|
+
*/
|
449
412
|
toJSON() {
|
450
413
|
return {
|
451
414
|
name: this.name,
|
@@ -458,50 +421,36 @@ var TooManyEmbeddingValuesForCallError = class extends Error {
|
|
458
421
|
};
|
459
422
|
}
|
460
423
|
};
|
461
|
-
|
462
|
-
// src/errors/tool-call-parse-error.ts
|
463
|
-
var ToolCallParseError = class extends Error {
|
464
|
-
constructor({
|
465
|
-
cause,
|
466
|
-
text,
|
467
|
-
tools,
|
468
|
-
message = `Failed to parse tool calls: ${getErrorMessage(cause)}`
|
469
|
-
}) {
|
470
|
-
super(message);
|
471
|
-
this.name = "AI_ToolCallParseError";
|
472
|
-
this.cause = cause;
|
473
|
-
this.text = text;
|
474
|
-
this.tools = tools;
|
475
|
-
}
|
476
|
-
static isToolCallParseError(error) {
|
477
|
-
return error instanceof Error && error.name === "AI_ToolCallParseError" && "cause" in error && error.cause != void 0 && "text" in error && error.text != void 0 && typeof error.text === "string" && "tools" in error && error.tools != void 0;
|
478
|
-
}
|
479
|
-
toJSON() {
|
480
|
-
return {
|
481
|
-
name: this.name,
|
482
|
-
message: this.message,
|
483
|
-
stack: this.stack,
|
484
|
-
cause: this.cause,
|
485
|
-
text: this.text,
|
486
|
-
tools: this.tools
|
487
|
-
};
|
488
|
-
}
|
489
|
-
};
|
424
|
+
_a10 = symbol10;
|
490
425
|
|
491
426
|
// src/errors/type-validation-error.ts
|
492
|
-
var
|
427
|
+
var name10 = "AI_TypeValidationError";
|
428
|
+
var marker11 = `vercel.ai.error.${name10}`;
|
429
|
+
var symbol11 = Symbol.for(marker11);
|
430
|
+
var _a11;
|
431
|
+
var TypeValidationError = class extends AISDKError {
|
493
432
|
constructor({ value, cause }) {
|
494
|
-
super(
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
433
|
+
super({
|
434
|
+
name: name10,
|
435
|
+
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
436
|
+
Error message: ${getErrorMessage(cause)}`,
|
437
|
+
cause
|
438
|
+
});
|
439
|
+
this[_a11] = true;
|
500
440
|
this.value = value;
|
501
441
|
}
|
442
|
+
static isInstance(error) {
|
443
|
+
return AISDKError.hasMarker(error, marker11);
|
444
|
+
}
|
445
|
+
/**
|
446
|
+
* @deprecated use `isInstance` instead
|
447
|
+
*/
|
502
448
|
static isTypeValidationError(error) {
|
503
|
-
return error instanceof Error && error.name ===
|
449
|
+
return error instanceof Error && error.name === name10;
|
504
450
|
}
|
451
|
+
/**
|
452
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
453
|
+
*/
|
505
454
|
toJSON() {
|
506
455
|
return {
|
507
456
|
name: this.name,
|
@@ -512,17 +461,34 @@ Error message: ${getErrorMessage(cause)}`
|
|
512
461
|
};
|
513
462
|
}
|
514
463
|
};
|
464
|
+
_a11 = symbol11;
|
515
465
|
|
516
466
|
// src/errors/unsupported-functionality-error.ts
|
517
|
-
var
|
467
|
+
var name11 = "AI_UnsupportedFunctionalityError";
|
468
|
+
var marker12 = `vercel.ai.error.${name11}`;
|
469
|
+
var symbol12 = Symbol.for(marker12);
|
470
|
+
var _a12;
|
471
|
+
var UnsupportedFunctionalityError = class extends AISDKError {
|
518
472
|
constructor({ functionality }) {
|
519
|
-
super(
|
520
|
-
|
473
|
+
super({
|
474
|
+
name: name11,
|
475
|
+
message: `'${functionality}' functionality not supported.`
|
476
|
+
});
|
477
|
+
this[_a12] = true;
|
521
478
|
this.functionality = functionality;
|
522
479
|
}
|
480
|
+
static isInstance(error) {
|
481
|
+
return AISDKError.hasMarker(error, marker12);
|
482
|
+
}
|
483
|
+
/**
|
484
|
+
* @deprecated Use isInstance instead.
|
485
|
+
*/
|
523
486
|
static isUnsupportedFunctionalityError(error) {
|
524
|
-
return error instanceof Error && error.name ===
|
487
|
+
return error instanceof Error && error.name === name11 && typeof error.functionality === "string";
|
525
488
|
}
|
489
|
+
/**
|
490
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
491
|
+
*/
|
526
492
|
toJSON() {
|
527
493
|
return {
|
528
494
|
name: this.name,
|
@@ -532,53 +498,21 @@ var UnsupportedFunctionalityError = class extends Error {
|
|
532
498
|
};
|
533
499
|
}
|
534
500
|
};
|
535
|
-
|
536
|
-
// src/errors/unsupported-json-schema-error.ts
|
537
|
-
var UnsupportedJSONSchemaError = class extends Error {
|
538
|
-
constructor({
|
539
|
-
schema,
|
540
|
-
reason,
|
541
|
-
message = `Unsupported JSON schema: ${reason}`
|
542
|
-
}) {
|
543
|
-
super(message);
|
544
|
-
this.name = "AI_UnsupportedJSONSchemaError";
|
545
|
-
this.reason = reason;
|
546
|
-
this.schema = schema;
|
547
|
-
}
|
548
|
-
static isUnsupportedJSONSchemaError(error) {
|
549
|
-
return error instanceof Error && error.name === "AI_UnsupportedJSONSchemaError" && "reason" in error && error.reason != void 0 && "schema" in error && error.schema !== void 0;
|
550
|
-
}
|
551
|
-
toJSON() {
|
552
|
-
return {
|
553
|
-
name: this.name,
|
554
|
-
message: this.message,
|
555
|
-
stack: this.stack,
|
556
|
-
reason: this.reason,
|
557
|
-
schema: this.schema
|
558
|
-
};
|
559
|
-
}
|
560
|
-
};
|
501
|
+
_a12 = symbol12;
|
561
502
|
// Annotate the CommonJS export names for ESM import in node:
|
562
503
|
0 && (module.exports = {
|
504
|
+
AISDKError,
|
563
505
|
APICallError,
|
564
|
-
DownloadError,
|
565
506
|
EmptyResponseBodyError,
|
566
|
-
InvalidArgumentError,
|
567
|
-
InvalidDataContentError,
|
568
507
|
InvalidPromptError,
|
569
508
|
InvalidResponseDataError,
|
570
|
-
InvalidToolArgumentsError,
|
571
509
|
JSONParseError,
|
572
510
|
LoadAPIKeyError,
|
573
511
|
LoadSettingError,
|
574
512
|
NoContentGeneratedError,
|
575
|
-
NoObjectGeneratedError,
|
576
|
-
NoSuchToolError,
|
577
|
-
RetryError,
|
578
513
|
TooManyEmbeddingValuesForCallError,
|
579
|
-
ToolCallParseError,
|
580
514
|
TypeValidationError,
|
581
515
|
UnsupportedFunctionalityError,
|
582
|
-
|
516
|
+
getErrorMessage
|
583
517
|
});
|
584
518
|
//# sourceMappingURL=index.js.map
|