@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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +7406 -7183
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +376 -427
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/image-model/v4/image-model-v4.ts +16 -0
- package/src/image-model-middleware/v4/image-model-v4-middleware.ts +18 -0
package/dist/index.js
CHANGED
|
@@ -1,452 +1,401 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/errors/get-error-message.ts
|
|
116
108
|
function getErrorMessage(error) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
var
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
var
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
var
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
var
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/json-value/is-json.ts
|
|
408
386
|
function isJSONValue(value) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
393
|
+
return Array.isArray(value) && value.every(isJSONValue);
|
|
424
394
|
}
|
|
425
395
|
function isJSONObject(value) {
|
|
426
|
-
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|