ai 5.0.5 → 5.0.7
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 +12 -0
- package/dist/index.d.mts +25 -4
- package/dist/index.d.ts +25 -4
- package/dist/index.js +855 -738
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +842 -721
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -17,7 +17,8 @@ import {
|
|
17
17
|
|
18
18
|
// src/generate-text/generate-text.ts
|
19
19
|
import {
|
20
|
-
createIdGenerator
|
20
|
+
createIdGenerator,
|
21
|
+
getErrorMessage as getErrorMessage5
|
21
22
|
} from "@ai-sdk/provider-utils";
|
22
23
|
|
23
24
|
// src/error/no-output-specified-error.ts
|
@@ -38,10 +39,23 @@ var NoOutputSpecifiedError = class extends AISDKError {
|
|
38
39
|
};
|
39
40
|
_a = symbol;
|
40
41
|
|
41
|
-
// src/
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
// src/model/resolve-model.ts
|
43
|
+
import { gateway } from "@ai-sdk/gateway";
|
44
|
+
|
45
|
+
// src/error/index.ts
|
46
|
+
import {
|
47
|
+
AISDKError as AISDKError16,
|
48
|
+
APICallError,
|
49
|
+
EmptyResponseBodyError,
|
50
|
+
InvalidPromptError,
|
51
|
+
InvalidResponseDataError,
|
52
|
+
JSONParseError,
|
53
|
+
LoadAPIKeyError,
|
54
|
+
NoContentGeneratedError,
|
55
|
+
NoSuchModelError,
|
56
|
+
TypeValidationError,
|
57
|
+
UnsupportedFunctionalityError
|
58
|
+
} from "@ai-sdk/provider";
|
45
59
|
|
46
60
|
// src/error/invalid-argument-error.ts
|
47
61
|
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
@@ -69,27 +83,20 @@ var InvalidArgumentError = class extends AISDKError2 {
|
|
69
83
|
};
|
70
84
|
_a2 = symbol2;
|
71
85
|
|
72
|
-
// src/
|
73
|
-
import { APICallError } from "@ai-sdk/provider";
|
74
|
-
import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
75
|
-
|
76
|
-
// src/util/retry-error.ts
|
86
|
+
// src/error/invalid-stream-part-error.ts
|
77
87
|
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
78
|
-
var name3 = "
|
88
|
+
var name3 = "AI_InvalidStreamPartError";
|
79
89
|
var marker3 = `vercel.ai.error.${name3}`;
|
80
90
|
var symbol3 = Symbol.for(marker3);
|
81
91
|
var _a3;
|
82
|
-
var
|
92
|
+
var InvalidStreamPartError = class extends AISDKError3 {
|
83
93
|
constructor({
|
84
|
-
|
85
|
-
|
86
|
-
errors
|
94
|
+
chunk,
|
95
|
+
message
|
87
96
|
}) {
|
88
97
|
super({ name: name3, message });
|
89
98
|
this[_a3] = true;
|
90
|
-
this.
|
91
|
-
this.errors = errors;
|
92
|
-
this.lastError = errors[errors.length - 1];
|
99
|
+
this.chunk = chunk;
|
93
100
|
}
|
94
101
|
static isInstance(error) {
|
95
102
|
return AISDKError3.hasMarker(error, marker3);
|
@@ -97,167 +104,342 @@ var RetryError = class extends AISDKError3 {
|
|
97
104
|
};
|
98
105
|
_a3 = symbol3;
|
99
106
|
|
100
|
-
// src/
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
// src/error/invalid-tool-input-error.ts
|
108
|
+
import { AISDKError as AISDKError4, getErrorMessage } from "@ai-sdk/provider";
|
109
|
+
var name4 = "AI_InvalidToolInputError";
|
110
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
111
|
+
var symbol4 = Symbol.for(marker4);
|
112
|
+
var _a4;
|
113
|
+
var InvalidToolInputError = class extends AISDKError4 {
|
114
|
+
constructor({
|
115
|
+
toolInput,
|
116
|
+
toolName,
|
117
|
+
cause,
|
118
|
+
message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
|
119
|
+
}) {
|
120
|
+
super({ name: name4, message, cause });
|
121
|
+
this[_a4] = true;
|
122
|
+
this.toolInput = toolInput;
|
123
|
+
this.toolName = toolName;
|
115
124
|
}
|
116
|
-
|
117
|
-
|
118
|
-
const timeoutSeconds = parseFloat(retryAfter);
|
119
|
-
if (!Number.isNaN(timeoutSeconds)) {
|
120
|
-
ms = timeoutSeconds * 1e3;
|
121
|
-
} else {
|
122
|
-
ms = Date.parse(retryAfter) - Date.now();
|
123
|
-
}
|
125
|
+
static isInstance(error) {
|
126
|
+
return AISDKError4.hasMarker(error, marker4);
|
124
127
|
}
|
125
|
-
|
126
|
-
|
128
|
+
};
|
129
|
+
_a4 = symbol4;
|
130
|
+
|
131
|
+
// src/error/mcp-client-error.ts
|
132
|
+
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
133
|
+
var name5 = "AI_MCPClientError";
|
134
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
135
|
+
var symbol5 = Symbol.for(marker5);
|
136
|
+
var _a5;
|
137
|
+
var MCPClientError = class extends AISDKError5 {
|
138
|
+
constructor({
|
139
|
+
name: name16 = "MCPClientError",
|
140
|
+
message,
|
141
|
+
cause
|
142
|
+
}) {
|
143
|
+
super({ name: name16, message, cause });
|
144
|
+
this[_a5] = true;
|
127
145
|
}
|
128
|
-
|
129
|
-
|
130
|
-
var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
131
|
-
maxRetries = 2,
|
132
|
-
initialDelayInMs = 2e3,
|
133
|
-
backoffFactor = 2,
|
134
|
-
abortSignal
|
135
|
-
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
136
|
-
maxRetries,
|
137
|
-
delayInMs: initialDelayInMs,
|
138
|
-
backoffFactor,
|
139
|
-
abortSignal
|
140
|
-
});
|
141
|
-
async function _retryWithExponentialBackoff(f, {
|
142
|
-
maxRetries,
|
143
|
-
delayInMs,
|
144
|
-
backoffFactor,
|
145
|
-
abortSignal
|
146
|
-
}, errors = []) {
|
147
|
-
try {
|
148
|
-
return await f();
|
149
|
-
} catch (error) {
|
150
|
-
if (isAbortError(error)) {
|
151
|
-
throw error;
|
152
|
-
}
|
153
|
-
if (maxRetries === 0) {
|
154
|
-
throw error;
|
155
|
-
}
|
156
|
-
const errorMessage = getErrorMessage(error);
|
157
|
-
const newErrors = [...errors, error];
|
158
|
-
const tryNumber = newErrors.length;
|
159
|
-
if (tryNumber > maxRetries) {
|
160
|
-
throw new RetryError({
|
161
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
162
|
-
reason: "maxRetriesExceeded",
|
163
|
-
errors: newErrors
|
164
|
-
});
|
165
|
-
}
|
166
|
-
if (error instanceof Error && APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
167
|
-
await delay(
|
168
|
-
getRetryDelayInMs({
|
169
|
-
error,
|
170
|
-
exponentialBackoffDelay: delayInMs
|
171
|
-
}),
|
172
|
-
{ abortSignal }
|
173
|
-
);
|
174
|
-
return _retryWithExponentialBackoff(
|
175
|
-
f,
|
176
|
-
{
|
177
|
-
maxRetries,
|
178
|
-
delayInMs: backoffFactor * delayInMs,
|
179
|
-
backoffFactor,
|
180
|
-
abortSignal
|
181
|
-
},
|
182
|
-
newErrors
|
183
|
-
);
|
184
|
-
}
|
185
|
-
if (tryNumber === 1) {
|
186
|
-
throw error;
|
187
|
-
}
|
188
|
-
throw new RetryError({
|
189
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
190
|
-
reason: "errorNotRetryable",
|
191
|
-
errors: newErrors
|
192
|
-
});
|
146
|
+
static isInstance(error) {
|
147
|
+
return AISDKError5.hasMarker(error, marker5);
|
193
148
|
}
|
194
|
-
}
|
149
|
+
};
|
150
|
+
_a5 = symbol5;
|
195
151
|
|
196
|
-
// src/
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
}
|
209
|
-
|
210
|
-
|
211
|
-
parameter: "maxRetries",
|
212
|
-
value: maxRetries,
|
213
|
-
message: "maxRetries must be >= 0"
|
214
|
-
});
|
215
|
-
}
|
152
|
+
// src/error/no-image-generated-error.ts
|
153
|
+
import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
|
154
|
+
var name6 = "AI_NoImageGeneratedError";
|
155
|
+
var marker6 = `vercel.ai.error.${name6}`;
|
156
|
+
var symbol6 = Symbol.for(marker6);
|
157
|
+
var _a6;
|
158
|
+
var NoImageGeneratedError = class extends AISDKError6 {
|
159
|
+
constructor({
|
160
|
+
message = "No image generated.",
|
161
|
+
cause,
|
162
|
+
responses
|
163
|
+
}) {
|
164
|
+
super({ name: name6, message, cause });
|
165
|
+
this[_a6] = true;
|
166
|
+
this.responses = responses;
|
216
167
|
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
abortSignal
|
223
|
-
})
|
224
|
-
};
|
225
|
-
}
|
168
|
+
static isInstance(error) {
|
169
|
+
return AISDKError6.hasMarker(error, marker6);
|
170
|
+
}
|
171
|
+
};
|
172
|
+
_a6 = symbol6;
|
226
173
|
|
227
|
-
// src/
|
228
|
-
import {
|
229
|
-
|
230
|
-
|
174
|
+
// src/error/no-object-generated-error.ts
|
175
|
+
import { AISDKError as AISDKError7 } from "@ai-sdk/provider";
|
176
|
+
var name7 = "AI_NoObjectGeneratedError";
|
177
|
+
var marker7 = `vercel.ai.error.${name7}`;
|
178
|
+
var symbol7 = Symbol.for(marker7);
|
179
|
+
var _a7;
|
180
|
+
var NoObjectGeneratedError = class extends AISDKError7 {
|
181
|
+
constructor({
|
182
|
+
message = "No object generated.",
|
183
|
+
cause,
|
184
|
+
text: text2,
|
185
|
+
response,
|
186
|
+
usage,
|
187
|
+
finishReason
|
188
|
+
}) {
|
189
|
+
super({ name: name7, message, cause });
|
190
|
+
this[_a7] = true;
|
191
|
+
this.text = text2;
|
192
|
+
this.response = response;
|
193
|
+
this.usage = usage;
|
194
|
+
this.finishReason = finishReason;
|
195
|
+
}
|
196
|
+
static isInstance(error) {
|
197
|
+
return AISDKError7.hasMarker(error, marker7);
|
198
|
+
}
|
199
|
+
};
|
200
|
+
_a7 = symbol7;
|
231
201
|
|
232
|
-
// src/
|
233
|
-
import {
|
234
|
-
var
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
202
|
+
// src/error/no-such-tool-error.ts
|
203
|
+
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
204
|
+
var name8 = "AI_NoSuchToolError";
|
205
|
+
var marker8 = `vercel.ai.error.${name8}`;
|
206
|
+
var symbol8 = Symbol.for(marker8);
|
207
|
+
var _a8;
|
208
|
+
var NoSuchToolError = class extends AISDKError8 {
|
209
|
+
constructor({
|
210
|
+
toolName,
|
211
|
+
availableTools = void 0,
|
212
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
213
|
+
}) {
|
214
|
+
super({ name: name8, message });
|
215
|
+
this[_a8] = true;
|
216
|
+
this.toolName = toolName;
|
217
|
+
this.availableTools = availableTools;
|
218
|
+
}
|
219
|
+
static isInstance(error) {
|
220
|
+
return AISDKError8.hasMarker(error, marker8);
|
221
|
+
}
|
222
|
+
};
|
223
|
+
_a8 = symbol8;
|
224
|
+
|
225
|
+
// src/error/tool-call-repair-error.ts
|
226
|
+
import { AISDKError as AISDKError9, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
227
|
+
var name9 = "AI_ToolCallRepairError";
|
228
|
+
var marker9 = `vercel.ai.error.${name9}`;
|
229
|
+
var symbol9 = Symbol.for(marker9);
|
230
|
+
var _a9;
|
231
|
+
var ToolCallRepairError = class extends AISDKError9 {
|
232
|
+
constructor({
|
233
|
+
cause,
|
234
|
+
originalError,
|
235
|
+
message = `Error repairing tool call: ${getErrorMessage2(cause)}`
|
236
|
+
}) {
|
237
|
+
super({ name: name9, message, cause });
|
238
|
+
this[_a9] = true;
|
239
|
+
this.originalError = originalError;
|
240
|
+
}
|
241
|
+
static isInstance(error) {
|
242
|
+
return AISDKError9.hasMarker(error, marker9);
|
243
|
+
}
|
244
|
+
};
|
245
|
+
_a9 = symbol9;
|
246
|
+
|
247
|
+
// src/error/unsupported-model-version-error.ts
|
248
|
+
import { AISDKError as AISDKError10 } from "@ai-sdk/provider";
|
249
|
+
var UnsupportedModelVersionError = class extends AISDKError10 {
|
250
|
+
constructor(options) {
|
251
|
+
super({
|
252
|
+
name: "AI_UnsupportedModelVersionError",
|
253
|
+
message: `Unsupported model version ${options.version} for provider "${options.provider}" and model "${options.modelId}". AI SDK 5 only supports models that implement specification version "v2".`
|
254
|
+
});
|
255
|
+
this.version = options.version;
|
256
|
+
this.provider = options.provider;
|
257
|
+
this.modelId = options.modelId;
|
258
|
+
}
|
259
|
+
};
|
260
|
+
|
261
|
+
// src/prompt/invalid-data-content-error.ts
|
262
|
+
import { AISDKError as AISDKError11 } from "@ai-sdk/provider";
|
263
|
+
var name10 = "AI_InvalidDataContentError";
|
264
|
+
var marker10 = `vercel.ai.error.${name10}`;
|
265
|
+
var symbol10 = Symbol.for(marker10);
|
266
|
+
var _a10;
|
267
|
+
var InvalidDataContentError = class extends AISDKError11 {
|
268
|
+
constructor({
|
269
|
+
content,
|
270
|
+
cause,
|
271
|
+
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
272
|
+
}) {
|
273
|
+
super({ name: name10, message, cause });
|
274
|
+
this[_a10] = true;
|
275
|
+
this.content = content;
|
276
|
+
}
|
277
|
+
static isInstance(error) {
|
278
|
+
return AISDKError11.hasMarker(error, marker10);
|
279
|
+
}
|
280
|
+
};
|
281
|
+
_a10 = symbol10;
|
282
|
+
|
283
|
+
// src/prompt/invalid-message-role-error.ts
|
284
|
+
import { AISDKError as AISDKError12 } from "@ai-sdk/provider";
|
285
|
+
var name11 = "AI_InvalidMessageRoleError";
|
286
|
+
var marker11 = `vercel.ai.error.${name11}`;
|
287
|
+
var symbol11 = Symbol.for(marker11);
|
288
|
+
var _a11;
|
289
|
+
var InvalidMessageRoleError = class extends AISDKError12 {
|
290
|
+
constructor({
|
291
|
+
role,
|
292
|
+
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
293
|
+
}) {
|
294
|
+
super({ name: name11, message });
|
295
|
+
this[_a11] = true;
|
296
|
+
this.role = role;
|
297
|
+
}
|
298
|
+
static isInstance(error) {
|
299
|
+
return AISDKError12.hasMarker(error, marker11);
|
300
|
+
}
|
301
|
+
};
|
302
|
+
_a11 = symbol11;
|
303
|
+
|
304
|
+
// src/prompt/message-conversion-error.ts
|
305
|
+
import { AISDKError as AISDKError13 } from "@ai-sdk/provider";
|
306
|
+
var name12 = "AI_MessageConversionError";
|
307
|
+
var marker12 = `vercel.ai.error.${name12}`;
|
308
|
+
var symbol12 = Symbol.for(marker12);
|
309
|
+
var _a12;
|
310
|
+
var MessageConversionError = class extends AISDKError13 {
|
311
|
+
constructor({
|
312
|
+
originalMessage,
|
313
|
+
message
|
314
|
+
}) {
|
315
|
+
super({ name: name12, message });
|
316
|
+
this[_a12] = true;
|
317
|
+
this.originalMessage = originalMessage;
|
318
|
+
}
|
319
|
+
static isInstance(error) {
|
320
|
+
return AISDKError13.hasMarker(error, marker12);
|
321
|
+
}
|
322
|
+
};
|
323
|
+
_a12 = symbol12;
|
324
|
+
|
325
|
+
// src/util/download-error.ts
|
326
|
+
import { AISDKError as AISDKError14 } from "@ai-sdk/provider";
|
327
|
+
var name13 = "AI_DownloadError";
|
328
|
+
var marker13 = `vercel.ai.error.${name13}`;
|
329
|
+
var symbol13 = Symbol.for(marker13);
|
330
|
+
var _a13;
|
331
|
+
var DownloadError = class extends AISDKError14 {
|
332
|
+
constructor({
|
333
|
+
url,
|
334
|
+
statusCode,
|
335
|
+
statusText,
|
336
|
+
cause,
|
337
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
338
|
+
}) {
|
339
|
+
super({ name: name13, message, cause });
|
340
|
+
this[_a13] = true;
|
341
|
+
this.url = url;
|
342
|
+
this.statusCode = statusCode;
|
343
|
+
this.statusText = statusText;
|
344
|
+
}
|
345
|
+
static isInstance(error) {
|
346
|
+
return AISDKError14.hasMarker(error, marker13);
|
347
|
+
}
|
348
|
+
};
|
349
|
+
_a13 = symbol13;
|
350
|
+
|
351
|
+
// src/util/retry-error.ts
|
352
|
+
import { AISDKError as AISDKError15 } from "@ai-sdk/provider";
|
353
|
+
var name14 = "AI_RetryError";
|
354
|
+
var marker14 = `vercel.ai.error.${name14}`;
|
355
|
+
var symbol14 = Symbol.for(marker14);
|
356
|
+
var _a14;
|
357
|
+
var RetryError = class extends AISDKError15 {
|
358
|
+
constructor({
|
359
|
+
message,
|
360
|
+
reason,
|
361
|
+
errors
|
362
|
+
}) {
|
363
|
+
super({ name: name14, message });
|
364
|
+
this[_a14] = true;
|
365
|
+
this.reason = reason;
|
366
|
+
this.errors = errors;
|
367
|
+
this.lastError = errors[errors.length - 1];
|
368
|
+
}
|
369
|
+
static isInstance(error) {
|
370
|
+
return AISDKError15.hasMarker(error, marker14);
|
371
|
+
}
|
372
|
+
};
|
373
|
+
_a14 = symbol14;
|
374
|
+
|
375
|
+
// src/model/resolve-model.ts
|
376
|
+
function resolveLanguageModel(model) {
|
377
|
+
if (typeof model !== "string") {
|
378
|
+
if (model.specificationVersion !== "v2") {
|
379
|
+
throw new UnsupportedModelVersionError({
|
380
|
+
version: model.specificationVersion,
|
381
|
+
provider: model.provider,
|
382
|
+
modelId: model.modelId
|
383
|
+
});
|
384
|
+
}
|
385
|
+
return model;
|
386
|
+
}
|
387
|
+
return getGlobalProvider().languageModel(model);
|
388
|
+
}
|
389
|
+
function resolveEmbeddingModel(model) {
|
390
|
+
if (typeof model !== "string") {
|
391
|
+
if (model.specificationVersion !== "v2") {
|
392
|
+
throw new UnsupportedModelVersionError({
|
393
|
+
version: model.specificationVersion,
|
394
|
+
provider: model.provider,
|
395
|
+
modelId: model.modelId
|
396
|
+
});
|
397
|
+
}
|
398
|
+
return model;
|
399
|
+
}
|
400
|
+
return getGlobalProvider().textEmbeddingModel(
|
401
|
+
model
|
402
|
+
);
|
403
|
+
}
|
404
|
+
function getGlobalProvider() {
|
405
|
+
var _a16;
|
406
|
+
return (_a16 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a16 : gateway;
|
407
|
+
}
|
408
|
+
|
409
|
+
// src/prompt/convert-to-language-model-prompt.ts
|
410
|
+
import {
|
411
|
+
isUrlSupported
|
412
|
+
} from "@ai-sdk/provider-utils";
|
413
|
+
|
414
|
+
// src/util/detect-media-type.ts
|
415
|
+
import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
|
416
|
+
var imageMediaTypeSignatures = [
|
417
|
+
{
|
418
|
+
mediaType: "image/gif",
|
419
|
+
bytesPrefix: [71, 73, 70],
|
420
|
+
base64Prefix: "R0lG"
|
421
|
+
},
|
422
|
+
{
|
423
|
+
mediaType: "image/png",
|
424
|
+
bytesPrefix: [137, 80, 78, 71],
|
425
|
+
base64Prefix: "iVBORw"
|
426
|
+
},
|
427
|
+
{
|
428
|
+
mediaType: "image/jpeg",
|
429
|
+
bytesPrefix: [255, 216],
|
430
|
+
base64Prefix: "/9j/"
|
431
|
+
},
|
432
|
+
{
|
433
|
+
mediaType: "image/webp",
|
434
|
+
bytesPrefix: [82, 73, 70, 70],
|
435
|
+
base64Prefix: "UklGRg"
|
436
|
+
},
|
437
|
+
{
|
438
|
+
mediaType: "image/bmp",
|
439
|
+
bytesPrefix: [66, 77],
|
440
|
+
base64Prefix: "Qk"
|
441
|
+
},
|
442
|
+
{
|
261
443
|
mediaType: "image/tiff",
|
262
444
|
bytesPrefix: [73, 73, 42, 0],
|
263
445
|
base64Prefix: "SUkqAA"
|
@@ -367,32 +549,6 @@ function detectMediaType({
|
|
367
549
|
return void 0;
|
368
550
|
}
|
369
551
|
|
370
|
-
// src/util/download-error.ts
|
371
|
-
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
372
|
-
var name4 = "AI_DownloadError";
|
373
|
-
var marker4 = `vercel.ai.error.${name4}`;
|
374
|
-
var symbol4 = Symbol.for(marker4);
|
375
|
-
var _a4;
|
376
|
-
var DownloadError = class extends AISDKError4 {
|
377
|
-
constructor({
|
378
|
-
url,
|
379
|
-
statusCode,
|
380
|
-
statusText,
|
381
|
-
cause,
|
382
|
-
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
383
|
-
}) {
|
384
|
-
super({ name: name4, message, cause });
|
385
|
-
this[_a4] = true;
|
386
|
-
this.url = url;
|
387
|
-
this.statusCode = statusCode;
|
388
|
-
this.statusText = statusText;
|
389
|
-
}
|
390
|
-
static isInstance(error) {
|
391
|
-
return AISDKError4.hasMarker(error, marker4);
|
392
|
-
}
|
393
|
-
};
|
394
|
-
_a4 = symbol4;
|
395
|
-
|
396
552
|
// src/util/download.ts
|
397
553
|
async function download({ url }) {
|
398
554
|
var _a16;
|
@@ -419,35 +575,13 @@ async function download({ url }) {
|
|
419
575
|
}
|
420
576
|
|
421
577
|
// src/prompt/data-content.ts
|
422
|
-
import { AISDKError as
|
578
|
+
import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
|
423
579
|
import {
|
424
580
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
425
581
|
convertUint8ArrayToBase64
|
426
582
|
} from "@ai-sdk/provider-utils";
|
427
583
|
import { z } from "zod/v4";
|
428
584
|
|
429
|
-
// src/prompt/invalid-data-content-error.ts
|
430
|
-
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
431
|
-
var name5 = "AI_InvalidDataContentError";
|
432
|
-
var marker5 = `vercel.ai.error.${name5}`;
|
433
|
-
var symbol5 = Symbol.for(marker5);
|
434
|
-
var _a5;
|
435
|
-
var InvalidDataContentError = class extends AISDKError5 {
|
436
|
-
constructor({
|
437
|
-
content,
|
438
|
-
cause,
|
439
|
-
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
440
|
-
}) {
|
441
|
-
super({ name: name5, message, cause });
|
442
|
-
this[_a5] = true;
|
443
|
-
this.content = content;
|
444
|
-
}
|
445
|
-
static isInstance(error) {
|
446
|
-
return AISDKError5.hasMarker(error, marker5);
|
447
|
-
}
|
448
|
-
};
|
449
|
-
_a5 = symbol5;
|
450
|
-
|
451
585
|
// src/prompt/split-data-url.ts
|
452
586
|
function splitDataUrl(dataUrl) {
|
453
587
|
try {
|
@@ -496,7 +630,7 @@ function convertToLanguageModelV2DataContent(content) {
|
|
496
630
|
content.toString()
|
497
631
|
);
|
498
632
|
if (dataUrlMediaType == null || base64Content == null) {
|
499
|
-
throw new
|
633
|
+
throw new AISDKError17({
|
500
634
|
name: "InvalidDataContentError",
|
501
635
|
message: `Invalid data URL format in content ${content.toString()}`
|
502
636
|
});
|
@@ -535,27 +669,6 @@ function convertDataContentToUint8Array(content) {
|
|
535
669
|
throw new InvalidDataContentError({ content });
|
536
670
|
}
|
537
671
|
|
538
|
-
// src/prompt/invalid-message-role-error.ts
|
539
|
-
import { AISDKError as AISDKError7 } from "@ai-sdk/provider";
|
540
|
-
var name6 = "AI_InvalidMessageRoleError";
|
541
|
-
var marker6 = `vercel.ai.error.${name6}`;
|
542
|
-
var symbol6 = Symbol.for(marker6);
|
543
|
-
var _a6;
|
544
|
-
var InvalidMessageRoleError = class extends AISDKError7 {
|
545
|
-
constructor({
|
546
|
-
role,
|
547
|
-
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
548
|
-
}) {
|
549
|
-
super({ name: name6, message });
|
550
|
-
this[_a6] = true;
|
551
|
-
this.role = role;
|
552
|
-
}
|
553
|
-
static isInstance(error) {
|
554
|
-
return AISDKError7.hasMarker(error, marker6);
|
555
|
-
}
|
556
|
-
};
|
557
|
-
_a6 = symbol6;
|
558
|
-
|
559
672
|
// src/prompt/convert-to-language-model-prompt.ts
|
560
673
|
async function convertToLanguageModelPrompt({
|
561
674
|
prompt,
|
@@ -813,347 +926,117 @@ function prepareCallSettings({
|
|
813
926
|
value: temperature,
|
814
927
|
message: "temperature must be a number"
|
815
928
|
});
|
816
|
-
}
|
817
|
-
}
|
818
|
-
if (topP != null) {
|
819
|
-
if (typeof topP !== "number") {
|
820
|
-
throw new InvalidArgumentError({
|
821
|
-
parameter: "topP",
|
822
|
-
value: topP,
|
823
|
-
message: "topP must be a number"
|
824
|
-
});
|
825
|
-
}
|
826
|
-
}
|
827
|
-
if (topK != null) {
|
828
|
-
if (typeof topK !== "number") {
|
829
|
-
throw new InvalidArgumentError({
|
830
|
-
parameter: "topK",
|
831
|
-
value: topK,
|
832
|
-
message: "topK must be a number"
|
833
|
-
});
|
834
|
-
}
|
835
|
-
}
|
836
|
-
if (presencePenalty != null) {
|
837
|
-
if (typeof presencePenalty !== "number") {
|
838
|
-
throw new InvalidArgumentError({
|
839
|
-
parameter: "presencePenalty",
|
840
|
-
value: presencePenalty,
|
841
|
-
message: "presencePenalty must be a number"
|
842
|
-
});
|
843
|
-
}
|
844
|
-
}
|
845
|
-
if (frequencyPenalty != null) {
|
846
|
-
if (typeof frequencyPenalty !== "number") {
|
847
|
-
throw new InvalidArgumentError({
|
848
|
-
parameter: "frequencyPenalty",
|
849
|
-
value: frequencyPenalty,
|
850
|
-
message: "frequencyPenalty must be a number"
|
851
|
-
});
|
852
|
-
}
|
853
|
-
}
|
854
|
-
if (seed != null) {
|
855
|
-
if (!Number.isInteger(seed)) {
|
856
|
-
throw new InvalidArgumentError({
|
857
|
-
parameter: "seed",
|
858
|
-
value: seed,
|
859
|
-
message: "seed must be an integer"
|
860
|
-
});
|
861
|
-
}
|
862
|
-
}
|
863
|
-
return {
|
864
|
-
maxOutputTokens,
|
865
|
-
temperature,
|
866
|
-
topP,
|
867
|
-
topK,
|
868
|
-
presencePenalty,
|
869
|
-
frequencyPenalty,
|
870
|
-
stopSequences,
|
871
|
-
seed
|
872
|
-
};
|
873
|
-
}
|
874
|
-
|
875
|
-
// src/prompt/prepare-tools-and-tool-choice.ts
|
876
|
-
import { asSchema } from "@ai-sdk/provider-utils";
|
877
|
-
|
878
|
-
// src/util/is-non-empty-object.ts
|
879
|
-
function isNonEmptyObject(object2) {
|
880
|
-
return object2 != null && Object.keys(object2).length > 0;
|
881
|
-
}
|
882
|
-
|
883
|
-
// src/prompt/prepare-tools-and-tool-choice.ts
|
884
|
-
function prepareToolsAndToolChoice({
|
885
|
-
tools,
|
886
|
-
toolChoice,
|
887
|
-
activeTools
|
888
|
-
}) {
|
889
|
-
if (!isNonEmptyObject(tools)) {
|
890
|
-
return {
|
891
|
-
tools: void 0,
|
892
|
-
toolChoice: void 0
|
893
|
-
};
|
894
|
-
}
|
895
|
-
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
896
|
-
([name16]) => activeTools.includes(name16)
|
897
|
-
) : Object.entries(tools);
|
898
|
-
return {
|
899
|
-
tools: filteredTools.map(([name16, tool3]) => {
|
900
|
-
const toolType = tool3.type;
|
901
|
-
switch (toolType) {
|
902
|
-
case void 0:
|
903
|
-
case "dynamic":
|
904
|
-
case "function":
|
905
|
-
return {
|
906
|
-
type: "function",
|
907
|
-
name: name16,
|
908
|
-
description: tool3.description,
|
909
|
-
inputSchema: asSchema(tool3.inputSchema).jsonSchema,
|
910
|
-
providerOptions: tool3.providerOptions
|
911
|
-
};
|
912
|
-
case "provider-defined":
|
913
|
-
return {
|
914
|
-
type: "provider-defined",
|
915
|
-
name: name16,
|
916
|
-
id: tool3.id,
|
917
|
-
args: tool3.args
|
918
|
-
};
|
919
|
-
default: {
|
920
|
-
const exhaustiveCheck = toolType;
|
921
|
-
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
922
|
-
}
|
923
|
-
}
|
924
|
-
}),
|
925
|
-
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
926
|
-
};
|
927
|
-
}
|
928
|
-
|
929
|
-
// src/prompt/resolve-language-model.ts
|
930
|
-
import { gateway } from "@ai-sdk/gateway";
|
931
|
-
|
932
|
-
// src/error/index.ts
|
933
|
-
import {
|
934
|
-
AISDKError as AISDKError17,
|
935
|
-
APICallError as APICallError2,
|
936
|
-
EmptyResponseBodyError,
|
937
|
-
InvalidPromptError,
|
938
|
-
InvalidResponseDataError,
|
939
|
-
JSONParseError,
|
940
|
-
LoadAPIKeyError,
|
941
|
-
NoContentGeneratedError,
|
942
|
-
NoSuchModelError,
|
943
|
-
TypeValidationError,
|
944
|
-
UnsupportedFunctionalityError
|
945
|
-
} from "@ai-sdk/provider";
|
946
|
-
|
947
|
-
// src/error/invalid-stream-part-error.ts
|
948
|
-
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
949
|
-
var name7 = "AI_InvalidStreamPartError";
|
950
|
-
var marker7 = `vercel.ai.error.${name7}`;
|
951
|
-
var symbol7 = Symbol.for(marker7);
|
952
|
-
var _a7;
|
953
|
-
var InvalidStreamPartError = class extends AISDKError8 {
|
954
|
-
constructor({
|
955
|
-
chunk,
|
956
|
-
message
|
957
|
-
}) {
|
958
|
-
super({ name: name7, message });
|
959
|
-
this[_a7] = true;
|
960
|
-
this.chunk = chunk;
|
961
|
-
}
|
962
|
-
static isInstance(error) {
|
963
|
-
return AISDKError8.hasMarker(error, marker7);
|
964
|
-
}
|
965
|
-
};
|
966
|
-
_a7 = symbol7;
|
967
|
-
|
968
|
-
// src/error/invalid-tool-input-error.ts
|
969
|
-
import { AISDKError as AISDKError9, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
970
|
-
var name8 = "AI_InvalidToolInputError";
|
971
|
-
var marker8 = `vercel.ai.error.${name8}`;
|
972
|
-
var symbol8 = Symbol.for(marker8);
|
973
|
-
var _a8;
|
974
|
-
var InvalidToolInputError = class extends AISDKError9 {
|
975
|
-
constructor({
|
976
|
-
toolInput,
|
977
|
-
toolName,
|
978
|
-
cause,
|
979
|
-
message = `Invalid input for tool ${toolName}: ${getErrorMessage2(cause)}`
|
980
|
-
}) {
|
981
|
-
super({ name: name8, message, cause });
|
982
|
-
this[_a8] = true;
|
983
|
-
this.toolInput = toolInput;
|
984
|
-
this.toolName = toolName;
|
985
|
-
}
|
986
|
-
static isInstance(error) {
|
987
|
-
return AISDKError9.hasMarker(error, marker8);
|
988
|
-
}
|
989
|
-
};
|
990
|
-
_a8 = symbol8;
|
991
|
-
|
992
|
-
// src/error/mcp-client-error.ts
|
993
|
-
import { AISDKError as AISDKError10 } from "@ai-sdk/provider";
|
994
|
-
var name9 = "AI_MCPClientError";
|
995
|
-
var marker9 = `vercel.ai.error.${name9}`;
|
996
|
-
var symbol9 = Symbol.for(marker9);
|
997
|
-
var _a9;
|
998
|
-
var MCPClientError = class extends AISDKError10 {
|
999
|
-
constructor({
|
1000
|
-
name: name16 = "MCPClientError",
|
1001
|
-
message,
|
1002
|
-
cause
|
1003
|
-
}) {
|
1004
|
-
super({ name: name16, message, cause });
|
1005
|
-
this[_a9] = true;
|
1006
|
-
}
|
1007
|
-
static isInstance(error) {
|
1008
|
-
return AISDKError10.hasMarker(error, marker9);
|
1009
|
-
}
|
1010
|
-
};
|
1011
|
-
_a9 = symbol9;
|
1012
|
-
|
1013
|
-
// src/error/no-image-generated-error.ts
|
1014
|
-
import { AISDKError as AISDKError11 } from "@ai-sdk/provider";
|
1015
|
-
var name10 = "AI_NoImageGeneratedError";
|
1016
|
-
var marker10 = `vercel.ai.error.${name10}`;
|
1017
|
-
var symbol10 = Symbol.for(marker10);
|
1018
|
-
var _a10;
|
1019
|
-
var NoImageGeneratedError = class extends AISDKError11 {
|
1020
|
-
constructor({
|
1021
|
-
message = "No image generated.",
|
1022
|
-
cause,
|
1023
|
-
responses
|
1024
|
-
}) {
|
1025
|
-
super({ name: name10, message, cause });
|
1026
|
-
this[_a10] = true;
|
1027
|
-
this.responses = responses;
|
1028
|
-
}
|
1029
|
-
static isInstance(error) {
|
1030
|
-
return AISDKError11.hasMarker(error, marker10);
|
1031
|
-
}
|
1032
|
-
};
|
1033
|
-
_a10 = symbol10;
|
1034
|
-
|
1035
|
-
// src/error/no-object-generated-error.ts
|
1036
|
-
import { AISDKError as AISDKError12 } from "@ai-sdk/provider";
|
1037
|
-
var name11 = "AI_NoObjectGeneratedError";
|
1038
|
-
var marker11 = `vercel.ai.error.${name11}`;
|
1039
|
-
var symbol11 = Symbol.for(marker11);
|
1040
|
-
var _a11;
|
1041
|
-
var NoObjectGeneratedError = class extends AISDKError12 {
|
1042
|
-
constructor({
|
1043
|
-
message = "No object generated.",
|
1044
|
-
cause,
|
1045
|
-
text: text2,
|
1046
|
-
response,
|
1047
|
-
usage,
|
1048
|
-
finishReason
|
1049
|
-
}) {
|
1050
|
-
super({ name: name11, message, cause });
|
1051
|
-
this[_a11] = true;
|
1052
|
-
this.text = text2;
|
1053
|
-
this.response = response;
|
1054
|
-
this.usage = usage;
|
1055
|
-
this.finishReason = finishReason;
|
1056
|
-
}
|
1057
|
-
static isInstance(error) {
|
1058
|
-
return AISDKError12.hasMarker(error, marker11);
|
1059
|
-
}
|
1060
|
-
};
|
1061
|
-
_a11 = symbol11;
|
1062
|
-
|
1063
|
-
// src/error/no-such-tool-error.ts
|
1064
|
-
import { AISDKError as AISDKError13 } from "@ai-sdk/provider";
|
1065
|
-
var name12 = "AI_NoSuchToolError";
|
1066
|
-
var marker12 = `vercel.ai.error.${name12}`;
|
1067
|
-
var symbol12 = Symbol.for(marker12);
|
1068
|
-
var _a12;
|
1069
|
-
var NoSuchToolError = class extends AISDKError13 {
|
1070
|
-
constructor({
|
1071
|
-
toolName,
|
1072
|
-
availableTools = void 0,
|
1073
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
1074
|
-
}) {
|
1075
|
-
super({ name: name12, message });
|
1076
|
-
this[_a12] = true;
|
1077
|
-
this.toolName = toolName;
|
1078
|
-
this.availableTools = availableTools;
|
1079
|
-
}
|
1080
|
-
static isInstance(error) {
|
1081
|
-
return AISDKError13.hasMarker(error, marker12);
|
1082
|
-
}
|
1083
|
-
};
|
1084
|
-
_a12 = symbol12;
|
1085
|
-
|
1086
|
-
// src/error/tool-call-repair-error.ts
|
1087
|
-
import { AISDKError as AISDKError14, getErrorMessage as getErrorMessage3 } from "@ai-sdk/provider";
|
1088
|
-
var name13 = "AI_ToolCallRepairError";
|
1089
|
-
var marker13 = `vercel.ai.error.${name13}`;
|
1090
|
-
var symbol13 = Symbol.for(marker13);
|
1091
|
-
var _a13;
|
1092
|
-
var ToolCallRepairError = class extends AISDKError14 {
|
1093
|
-
constructor({
|
1094
|
-
cause,
|
1095
|
-
originalError,
|
1096
|
-
message = `Error repairing tool call: ${getErrorMessage3(cause)}`
|
1097
|
-
}) {
|
1098
|
-
super({ name: name13, message, cause });
|
1099
|
-
this[_a13] = true;
|
1100
|
-
this.originalError = originalError;
|
1101
|
-
}
|
1102
|
-
static isInstance(error) {
|
1103
|
-
return AISDKError14.hasMarker(error, marker13);
|
1104
|
-
}
|
1105
|
-
};
|
1106
|
-
_a13 = symbol13;
|
1107
|
-
|
1108
|
-
// src/error/unsupported-model-version-error.ts
|
1109
|
-
import { AISDKError as AISDKError15 } from "@ai-sdk/provider";
|
1110
|
-
var UnsupportedModelVersionError = class extends AISDKError15 {
|
1111
|
-
constructor(options) {
|
1112
|
-
super({
|
1113
|
-
name: "AI_UnsupportedModelVersionError",
|
1114
|
-
message: `Unsupported model version ${options.version} for provider "${options.provider}" and model "${options.modelId}". AI SDK 5 only supports models that implement specification version "v2".`
|
1115
|
-
});
|
1116
|
-
this.version = options.version;
|
1117
|
-
this.provider = options.provider;
|
1118
|
-
this.modelId = options.modelId;
|
929
|
+
}
|
1119
930
|
}
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
var MessageConversionError = class extends AISDKError16 {
|
1129
|
-
constructor({
|
1130
|
-
originalMessage,
|
1131
|
-
message
|
1132
|
-
}) {
|
1133
|
-
super({ name: name14, message });
|
1134
|
-
this[_a14] = true;
|
1135
|
-
this.originalMessage = originalMessage;
|
931
|
+
if (topP != null) {
|
932
|
+
if (typeof topP !== "number") {
|
933
|
+
throw new InvalidArgumentError({
|
934
|
+
parameter: "topP",
|
935
|
+
value: topP,
|
936
|
+
message: "topP must be a number"
|
937
|
+
});
|
938
|
+
}
|
1136
939
|
}
|
1137
|
-
|
1138
|
-
|
940
|
+
if (topK != null) {
|
941
|
+
if (typeof topK !== "number") {
|
942
|
+
throw new InvalidArgumentError({
|
943
|
+
parameter: "topK",
|
944
|
+
value: topK,
|
945
|
+
message: "topK must be a number"
|
946
|
+
});
|
947
|
+
}
|
1139
948
|
}
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
if (model.specificationVersion !== "v2") {
|
1147
|
-
throw new UnsupportedModelVersionError({
|
1148
|
-
version: model.specificationVersion,
|
1149
|
-
provider: model.provider,
|
1150
|
-
modelId: model.modelId
|
949
|
+
if (presencePenalty != null) {
|
950
|
+
if (typeof presencePenalty !== "number") {
|
951
|
+
throw new InvalidArgumentError({
|
952
|
+
parameter: "presencePenalty",
|
953
|
+
value: presencePenalty,
|
954
|
+
message: "presencePenalty must be a number"
|
1151
955
|
});
|
1152
956
|
}
|
1153
|
-
return model;
|
1154
957
|
}
|
1155
|
-
|
1156
|
-
|
958
|
+
if (frequencyPenalty != null) {
|
959
|
+
if (typeof frequencyPenalty !== "number") {
|
960
|
+
throw new InvalidArgumentError({
|
961
|
+
parameter: "frequencyPenalty",
|
962
|
+
value: frequencyPenalty,
|
963
|
+
message: "frequencyPenalty must be a number"
|
964
|
+
});
|
965
|
+
}
|
966
|
+
}
|
967
|
+
if (seed != null) {
|
968
|
+
if (!Number.isInteger(seed)) {
|
969
|
+
throw new InvalidArgumentError({
|
970
|
+
parameter: "seed",
|
971
|
+
value: seed,
|
972
|
+
message: "seed must be an integer"
|
973
|
+
});
|
974
|
+
}
|
975
|
+
}
|
976
|
+
return {
|
977
|
+
maxOutputTokens,
|
978
|
+
temperature,
|
979
|
+
topP,
|
980
|
+
topK,
|
981
|
+
presencePenalty,
|
982
|
+
frequencyPenalty,
|
983
|
+
stopSequences,
|
984
|
+
seed
|
985
|
+
};
|
986
|
+
}
|
987
|
+
|
988
|
+
// src/prompt/prepare-tools-and-tool-choice.ts
|
989
|
+
import { asSchema } from "@ai-sdk/provider-utils";
|
990
|
+
|
991
|
+
// src/util/is-non-empty-object.ts
|
992
|
+
function isNonEmptyObject(object2) {
|
993
|
+
return object2 != null && Object.keys(object2).length > 0;
|
994
|
+
}
|
995
|
+
|
996
|
+
// src/prompt/prepare-tools-and-tool-choice.ts
|
997
|
+
function prepareToolsAndToolChoice({
|
998
|
+
tools,
|
999
|
+
toolChoice,
|
1000
|
+
activeTools
|
1001
|
+
}) {
|
1002
|
+
if (!isNonEmptyObject(tools)) {
|
1003
|
+
return {
|
1004
|
+
tools: void 0,
|
1005
|
+
toolChoice: void 0
|
1006
|
+
};
|
1007
|
+
}
|
1008
|
+
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
1009
|
+
([name16]) => activeTools.includes(name16)
|
1010
|
+
) : Object.entries(tools);
|
1011
|
+
return {
|
1012
|
+
tools: filteredTools.map(([name16, tool3]) => {
|
1013
|
+
const toolType = tool3.type;
|
1014
|
+
switch (toolType) {
|
1015
|
+
case void 0:
|
1016
|
+
case "dynamic":
|
1017
|
+
case "function":
|
1018
|
+
return {
|
1019
|
+
type: "function",
|
1020
|
+
name: name16,
|
1021
|
+
description: tool3.description,
|
1022
|
+
inputSchema: asSchema(tool3.inputSchema).jsonSchema,
|
1023
|
+
providerOptions: tool3.providerOptions
|
1024
|
+
};
|
1025
|
+
case "provider-defined":
|
1026
|
+
return {
|
1027
|
+
type: "provider-defined",
|
1028
|
+
name: name16,
|
1029
|
+
id: tool3.id,
|
1030
|
+
args: tool3.args
|
1031
|
+
};
|
1032
|
+
default: {
|
1033
|
+
const exhaustiveCheck = toolType;
|
1034
|
+
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
1035
|
+
}
|
1036
|
+
}
|
1037
|
+
}),
|
1038
|
+
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
1039
|
+
};
|
1157
1040
|
}
|
1158
1041
|
|
1159
1042
|
// src/prompt/standardize-prompt.ts
|
@@ -1610,9 +1493,143 @@ function addLanguageModelUsage(usage1, usage2) {
|
|
1610
1493
|
)
|
1611
1494
|
};
|
1612
1495
|
}
|
1613
|
-
function addTokenCounts(tokenCount1, tokenCount2) {
|
1614
|
-
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
1615
|
-
}
|
1496
|
+
function addTokenCounts(tokenCount1, tokenCount2) {
|
1497
|
+
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
// src/util/as-array.ts
|
1501
|
+
function asArray(value) {
|
1502
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
1503
|
+
}
|
1504
|
+
|
1505
|
+
// src/util/retry-with-exponential-backoff.ts
|
1506
|
+
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
1507
|
+
import { delay, getErrorMessage as getErrorMessage3, isAbortError } from "@ai-sdk/provider-utils";
|
1508
|
+
function getRetryDelayInMs({
|
1509
|
+
error,
|
1510
|
+
exponentialBackoffDelay
|
1511
|
+
}) {
|
1512
|
+
const headers = error.responseHeaders;
|
1513
|
+
if (!headers)
|
1514
|
+
return exponentialBackoffDelay;
|
1515
|
+
let ms;
|
1516
|
+
const retryAfterMs = headers["retry-after-ms"];
|
1517
|
+
if (retryAfterMs) {
|
1518
|
+
const timeoutMs = parseFloat(retryAfterMs);
|
1519
|
+
if (!Number.isNaN(timeoutMs)) {
|
1520
|
+
ms = timeoutMs;
|
1521
|
+
}
|
1522
|
+
}
|
1523
|
+
const retryAfter = headers["retry-after"];
|
1524
|
+
if (retryAfter && ms === void 0) {
|
1525
|
+
const timeoutSeconds = parseFloat(retryAfter);
|
1526
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
1527
|
+
ms = timeoutSeconds * 1e3;
|
1528
|
+
} else {
|
1529
|
+
ms = Date.parse(retryAfter) - Date.now();
|
1530
|
+
}
|
1531
|
+
}
|
1532
|
+
if (ms != null && !Number.isNaN(ms) && 0 <= ms && (ms < 60 * 1e3 || ms < exponentialBackoffDelay)) {
|
1533
|
+
return ms;
|
1534
|
+
}
|
1535
|
+
return exponentialBackoffDelay;
|
1536
|
+
}
|
1537
|
+
var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
1538
|
+
maxRetries = 2,
|
1539
|
+
initialDelayInMs = 2e3,
|
1540
|
+
backoffFactor = 2,
|
1541
|
+
abortSignal
|
1542
|
+
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
1543
|
+
maxRetries,
|
1544
|
+
delayInMs: initialDelayInMs,
|
1545
|
+
backoffFactor,
|
1546
|
+
abortSignal
|
1547
|
+
});
|
1548
|
+
async function _retryWithExponentialBackoff(f, {
|
1549
|
+
maxRetries,
|
1550
|
+
delayInMs,
|
1551
|
+
backoffFactor,
|
1552
|
+
abortSignal
|
1553
|
+
}, errors = []) {
|
1554
|
+
try {
|
1555
|
+
return await f();
|
1556
|
+
} catch (error) {
|
1557
|
+
if (isAbortError(error)) {
|
1558
|
+
throw error;
|
1559
|
+
}
|
1560
|
+
if (maxRetries === 0) {
|
1561
|
+
throw error;
|
1562
|
+
}
|
1563
|
+
const errorMessage = getErrorMessage3(error);
|
1564
|
+
const newErrors = [...errors, error];
|
1565
|
+
const tryNumber = newErrors.length;
|
1566
|
+
if (tryNumber > maxRetries) {
|
1567
|
+
throw new RetryError({
|
1568
|
+
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
1569
|
+
reason: "maxRetriesExceeded",
|
1570
|
+
errors: newErrors
|
1571
|
+
});
|
1572
|
+
}
|
1573
|
+
if (error instanceof Error && APICallError2.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
1574
|
+
await delay(
|
1575
|
+
getRetryDelayInMs({
|
1576
|
+
error,
|
1577
|
+
exponentialBackoffDelay: delayInMs
|
1578
|
+
}),
|
1579
|
+
{ abortSignal }
|
1580
|
+
);
|
1581
|
+
return _retryWithExponentialBackoff(
|
1582
|
+
f,
|
1583
|
+
{
|
1584
|
+
maxRetries,
|
1585
|
+
delayInMs: backoffFactor * delayInMs,
|
1586
|
+
backoffFactor,
|
1587
|
+
abortSignal
|
1588
|
+
},
|
1589
|
+
newErrors
|
1590
|
+
);
|
1591
|
+
}
|
1592
|
+
if (tryNumber === 1) {
|
1593
|
+
throw error;
|
1594
|
+
}
|
1595
|
+
throw new RetryError({
|
1596
|
+
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
1597
|
+
reason: "errorNotRetryable",
|
1598
|
+
errors: newErrors
|
1599
|
+
});
|
1600
|
+
}
|
1601
|
+
}
|
1602
|
+
|
1603
|
+
// src/util/prepare-retries.ts
|
1604
|
+
function prepareRetries({
|
1605
|
+
maxRetries,
|
1606
|
+
abortSignal
|
1607
|
+
}) {
|
1608
|
+
if (maxRetries != null) {
|
1609
|
+
if (!Number.isInteger(maxRetries)) {
|
1610
|
+
throw new InvalidArgumentError({
|
1611
|
+
parameter: "maxRetries",
|
1612
|
+
value: maxRetries,
|
1613
|
+
message: "maxRetries must be an integer"
|
1614
|
+
});
|
1615
|
+
}
|
1616
|
+
if (maxRetries < 0) {
|
1617
|
+
throw new InvalidArgumentError({
|
1618
|
+
parameter: "maxRetries",
|
1619
|
+
value: maxRetries,
|
1620
|
+
message: "maxRetries must be >= 0"
|
1621
|
+
});
|
1622
|
+
}
|
1623
|
+
}
|
1624
|
+
const maxRetriesResult = maxRetries != null ? maxRetries : 2;
|
1625
|
+
return {
|
1626
|
+
maxRetries: maxRetriesResult,
|
1627
|
+
retry: retryWithExponentialBackoffRespectingRetryHeaders({
|
1628
|
+
maxRetries: maxRetriesResult,
|
1629
|
+
abortSignal
|
1630
|
+
})
|
1631
|
+
};
|
1632
|
+
}
|
1616
1633
|
|
1617
1634
|
// src/generate-text/extract-content-text.ts
|
1618
1635
|
function extractContentText(content) {
|
@@ -1675,38 +1692,50 @@ async function parseToolCall({
|
|
1675
1692
|
system,
|
1676
1693
|
messages
|
1677
1694
|
}) {
|
1678
|
-
if (tools == null) {
|
1679
|
-
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1680
|
-
}
|
1681
1695
|
try {
|
1682
|
-
|
1683
|
-
|
1684
|
-
if (repairToolCall == null || !(NoSuchToolError.isInstance(error) || InvalidToolInputError.isInstance(error))) {
|
1685
|
-
throw error;
|
1696
|
+
if (tools == null) {
|
1697
|
+
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1686
1698
|
}
|
1687
|
-
let repairedToolCall = null;
|
1688
1699
|
try {
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1700
|
+
return await doParseToolCall({ toolCall, tools });
|
1701
|
+
} catch (error) {
|
1702
|
+
if (repairToolCall == null || !(NoSuchToolError.isInstance(error) || InvalidToolInputError.isInstance(error))) {
|
1703
|
+
throw error;
|
1704
|
+
}
|
1705
|
+
let repairedToolCall = null;
|
1706
|
+
try {
|
1707
|
+
repairedToolCall = await repairToolCall({
|
1708
|
+
toolCall,
|
1709
|
+
tools,
|
1710
|
+
inputSchema: ({ toolName }) => {
|
1711
|
+
const { inputSchema } = tools[toolName];
|
1712
|
+
return asSchema2(inputSchema).jsonSchema;
|
1713
|
+
},
|
1714
|
+
system,
|
1715
|
+
messages,
|
1716
|
+
error
|
1717
|
+
});
|
1718
|
+
} catch (repairError) {
|
1719
|
+
throw new ToolCallRepairError({
|
1720
|
+
cause: repairError,
|
1721
|
+
originalError: error
|
1722
|
+
});
|
1723
|
+
}
|
1724
|
+
if (repairedToolCall == null) {
|
1725
|
+
throw error;
|
1726
|
+
}
|
1727
|
+
return await doParseToolCall({ toolCall: repairedToolCall, tools });
|
1708
1728
|
}
|
1709
|
-
|
1729
|
+
} catch (error) {
|
1730
|
+
return {
|
1731
|
+
type: "tool-call",
|
1732
|
+
toolCallId: toolCall.toolCallId,
|
1733
|
+
toolName: toolCall.toolName,
|
1734
|
+
input: toolCall.input,
|
1735
|
+
dynamic: true,
|
1736
|
+
invalid: true,
|
1737
|
+
error
|
1738
|
+
};
|
1710
1739
|
}
|
1711
1740
|
}
|
1712
1741
|
async function doParseToolCall({
|
@@ -2158,6 +2187,9 @@ async function generateText({
|
|
2158
2187
|
)
|
2159
2188
|
);
|
2160
2189
|
for (const toolCall of stepToolCalls) {
|
2190
|
+
if (toolCall.invalid) {
|
2191
|
+
continue;
|
2192
|
+
}
|
2161
2193
|
const tool3 = tools[toolCall.toolName];
|
2162
2194
|
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
2163
2195
|
await tool3.onInputAvailable({
|
@@ -2169,18 +2201,38 @@ async function generateText({
|
|
2169
2201
|
});
|
2170
2202
|
}
|
2171
2203
|
}
|
2204
|
+
const invalidToolCalls = stepToolCalls.filter(
|
2205
|
+
(toolCall) => toolCall.invalid && toolCall.dynamic
|
2206
|
+
);
|
2207
|
+
clientToolOutputs = [];
|
2208
|
+
for (const toolCall of invalidToolCalls) {
|
2209
|
+
clientToolOutputs.push({
|
2210
|
+
type: "tool-error",
|
2211
|
+
toolCallId: toolCall.toolCallId,
|
2212
|
+
toolName: toolCall.toolName,
|
2213
|
+
input: toolCall.input,
|
2214
|
+
error: getErrorMessage5(toolCall.error),
|
2215
|
+
dynamic: true
|
2216
|
+
});
|
2217
|
+
}
|
2172
2218
|
clientToolCalls = stepToolCalls.filter(
|
2173
|
-
(toolCall) => toolCall.providerExecuted
|
2219
|
+
(toolCall) => !toolCall.providerExecuted
|
2174
2220
|
);
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2221
|
+
if (tools != null) {
|
2222
|
+
clientToolOutputs.push(
|
2223
|
+
...await executeTools({
|
2224
|
+
toolCalls: clientToolCalls.filter(
|
2225
|
+
(toolCall) => !toolCall.invalid
|
2226
|
+
),
|
2227
|
+
tools,
|
2228
|
+
tracer,
|
2229
|
+
telemetry,
|
2230
|
+
messages: stepInputMessages,
|
2231
|
+
abortSignal,
|
2232
|
+
experimental_context
|
2233
|
+
})
|
2234
|
+
);
|
2235
|
+
}
|
2184
2236
|
const stepContent = asContent({
|
2185
2237
|
content: currentModelResponse.content,
|
2186
2238
|
toolCalls: stepToolCalls,
|
@@ -2489,7 +2541,7 @@ function asContent({
|
|
2489
2541
|
|
2490
2542
|
// src/generate-text/stream-text.ts
|
2491
2543
|
import {
|
2492
|
-
getErrorMessage as
|
2544
|
+
getErrorMessage as getErrorMessage7
|
2493
2545
|
} from "@ai-sdk/provider";
|
2494
2546
|
import {
|
2495
2547
|
createIdGenerator as createIdGenerator2,
|
@@ -2679,6 +2731,16 @@ var uiMessageChunkSchema = z7.union([
|
|
2679
2731
|
providerMetadata: providerMetadataSchema.optional(),
|
2680
2732
|
dynamic: z7.boolean().optional()
|
2681
2733
|
}),
|
2734
|
+
z7.strictObject({
|
2735
|
+
type: z7.literal("tool-input-error"),
|
2736
|
+
toolCallId: z7.string(),
|
2737
|
+
toolName: z7.string(),
|
2738
|
+
input: z7.unknown(),
|
2739
|
+
providerExecuted: z7.boolean().optional(),
|
2740
|
+
providerMetadata: providerMetadataSchema.optional(),
|
2741
|
+
dynamic: z7.boolean().optional(),
|
2742
|
+
errorText: z7.string()
|
2743
|
+
}),
|
2682
2744
|
z7.strictObject({
|
2683
2745
|
type: z7.literal("tool-output-available"),
|
2684
2746
|
toolCallId: z7.string(),
|
@@ -3218,6 +3280,7 @@ function processUIMessageStream({
|
|
3218
3280
|
anyPart.input = anyOptions.input;
|
3219
3281
|
anyPart.output = anyOptions.output;
|
3220
3282
|
anyPart.errorText = anyOptions.errorText;
|
3283
|
+
anyPart.rawInput = anyOptions.rawInput;
|
3221
3284
|
anyPart.providerExecuted = (_a17 = anyOptions.providerExecuted) != null ? _a17 : part.providerExecuted;
|
3222
3285
|
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
3223
3286
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
@@ -3229,6 +3292,7 @@ function processUIMessageStream({
|
|
3229
3292
|
state: options.state,
|
3230
3293
|
input: anyOptions.input,
|
3231
3294
|
output: anyOptions.output,
|
3295
|
+
rawInput: anyOptions.rawInput,
|
3232
3296
|
errorText: anyOptions.errorText,
|
3233
3297
|
providerExecuted: anyOptions.providerExecuted,
|
3234
3298
|
...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
|
@@ -3236,6 +3300,7 @@ function processUIMessageStream({
|
|
3236
3300
|
}
|
3237
3301
|
}
|
3238
3302
|
function updateDynamicToolPart(options) {
|
3303
|
+
var _a17;
|
3239
3304
|
const part = state.message.parts.find(
|
3240
3305
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
3241
3306
|
);
|
@@ -3247,6 +3312,7 @@ function processUIMessageStream({
|
|
3247
3312
|
anyPart.input = anyOptions.input;
|
3248
3313
|
anyPart.output = anyOptions.output;
|
3249
3314
|
anyPart.errorText = anyOptions.errorText;
|
3315
|
+
anyPart.rawInput = (_a17 = anyOptions.rawInput) != null ? _a17 : anyPart.rawInput;
|
3250
3316
|
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
3251
3317
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
3252
3318
|
}
|
@@ -3440,6 +3506,31 @@ function processUIMessageStream({
|
|
3440
3506
|
}
|
3441
3507
|
break;
|
3442
3508
|
}
|
3509
|
+
case "tool-input-error": {
|
3510
|
+
if (chunk.dynamic) {
|
3511
|
+
updateDynamicToolPart({
|
3512
|
+
toolCallId: chunk.toolCallId,
|
3513
|
+
toolName: chunk.toolName,
|
3514
|
+
state: "output-error",
|
3515
|
+
input: chunk.input,
|
3516
|
+
errorText: chunk.errorText,
|
3517
|
+
providerMetadata: chunk.providerMetadata
|
3518
|
+
});
|
3519
|
+
} else {
|
3520
|
+
updateToolPart({
|
3521
|
+
toolCallId: chunk.toolCallId,
|
3522
|
+
toolName: chunk.toolName,
|
3523
|
+
state: "output-error",
|
3524
|
+
input: void 0,
|
3525
|
+
rawInput: chunk.input,
|
3526
|
+
errorText: chunk.errorText,
|
3527
|
+
providerExecuted: chunk.providerExecuted,
|
3528
|
+
providerMetadata: chunk.providerMetadata
|
3529
|
+
});
|
3530
|
+
}
|
3531
|
+
write();
|
3532
|
+
break;
|
3533
|
+
}
|
3443
3534
|
case "tool-output-available": {
|
3444
3535
|
if (chunk.dynamic) {
|
3445
3536
|
const toolInvocation = getDynamicToolInvocation(
|
@@ -3485,6 +3576,7 @@ function processUIMessageStream({
|
|
3485
3576
|
toolName: getToolName(toolInvocation),
|
3486
3577
|
state: "output-error",
|
3487
3578
|
input: toolInvocation.input,
|
3579
|
+
rawInput: toolInvocation.rawInput,
|
3488
3580
|
errorText: chunk.errorText
|
3489
3581
|
});
|
3490
3582
|
}
|
@@ -3823,12 +3915,6 @@ var DelayedPromise = class {
|
|
3823
3915
|
}
|
3824
3916
|
};
|
3825
3917
|
|
3826
|
-
// src/util/now.ts
|
3827
|
-
function now() {
|
3828
|
-
var _a16, _b;
|
3829
|
-
return (_b = (_a16 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a16.now()) != null ? _b : Date.now();
|
3830
|
-
}
|
3831
|
-
|
3832
3918
|
// src/util/filter-stream-errors.ts
|
3833
3919
|
function filterStreamErrors(readable, onError) {
|
3834
3920
|
return new ReadableStream({
|
@@ -3853,8 +3939,17 @@ function filterStreamErrors(readable, onError) {
|
|
3853
3939
|
});
|
3854
3940
|
}
|
3855
3941
|
|
3942
|
+
// src/util/now.ts
|
3943
|
+
function now() {
|
3944
|
+
var _a16, _b;
|
3945
|
+
return (_b = (_a16 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a16.now()) != null ? _b : Date.now();
|
3946
|
+
}
|
3947
|
+
|
3856
3948
|
// src/generate-text/run-tools-transformation.ts
|
3857
|
-
import {
|
3949
|
+
import {
|
3950
|
+
generateId,
|
3951
|
+
getErrorMessage as getErrorMessage6
|
3952
|
+
} from "@ai-sdk/provider-utils";
|
3858
3953
|
function runToolsTransformation({
|
3859
3954
|
tools,
|
3860
3955
|
generatorStream,
|
@@ -3934,6 +4029,17 @@ function runToolsTransformation({
|
|
3934
4029
|
messages
|
3935
4030
|
});
|
3936
4031
|
controller.enqueue(toolCall);
|
4032
|
+
if (toolCall.invalid) {
|
4033
|
+
toolResultsStreamController.enqueue({
|
4034
|
+
type: "tool-error",
|
4035
|
+
toolCallId: toolCall.toolCallId,
|
4036
|
+
toolName: toolCall.toolName,
|
4037
|
+
input: toolCall.input,
|
4038
|
+
error: getErrorMessage6(toolCall.error),
|
4039
|
+
dynamic: true
|
4040
|
+
});
|
4041
|
+
break;
|
4042
|
+
}
|
3937
4043
|
const tool3 = tools[toolCall.toolName];
|
3938
4044
|
toolInputs.set(toolCall.toolCallId, toolCall.input);
|
3939
4045
|
if (tool3.onInputAvailable != null) {
|
@@ -4246,6 +4352,7 @@ var DefaultStreamTextResult = class {
|
|
4246
4352
|
this._steps = new DelayedPromise();
|
4247
4353
|
this.output = output;
|
4248
4354
|
this.includeRawChunks = includeRawChunks;
|
4355
|
+
this.tools = tools;
|
4249
4356
|
let stepFinish;
|
4250
4357
|
let recordedContent = [];
|
4251
4358
|
const recordedResponseMessages = [];
|
@@ -5048,12 +5155,19 @@ var DefaultStreamTextResult = class {
|
|
5048
5155
|
sendSources = false,
|
5049
5156
|
sendStart = true,
|
5050
5157
|
sendFinish = true,
|
5051
|
-
onError =
|
5158
|
+
onError = getErrorMessage7
|
5052
5159
|
} = {}) {
|
5053
5160
|
const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
|
5054
5161
|
originalMessages,
|
5055
5162
|
responseMessageId: generateMessageId
|
5056
5163
|
}) : void 0;
|
5164
|
+
const toolNamesByCallId = {};
|
5165
|
+
const isDynamic = (toolCallId) => {
|
5166
|
+
var _a16, _b;
|
5167
|
+
const toolName = toolNamesByCallId[toolCallId];
|
5168
|
+
const dynamic = ((_b = (_a16 = this.tools) == null ? void 0 : _a16[toolName]) == null ? void 0 : _b.type) === "dynamic";
|
5169
|
+
return dynamic ? true : void 0;
|
5170
|
+
};
|
5057
5171
|
const baseStream = this.fullStream.pipeThrough(
|
5058
5172
|
new TransformStream({
|
5059
5173
|
transform: async (part, controller) => {
|
@@ -5143,12 +5257,14 @@ var DefaultStreamTextResult = class {
|
|
5143
5257
|
break;
|
5144
5258
|
}
|
5145
5259
|
case "tool-input-start": {
|
5260
|
+
toolNamesByCallId[part.id] = part.toolName;
|
5261
|
+
const dynamic = isDynamic(part.id);
|
5146
5262
|
controller.enqueue({
|
5147
5263
|
type: "tool-input-start",
|
5148
5264
|
toolCallId: part.id,
|
5149
5265
|
toolName: part.toolName,
|
5150
5266
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5151
|
-
...
|
5267
|
+
...dynamic != null ? { dynamic } : {}
|
5152
5268
|
});
|
5153
5269
|
break;
|
5154
5270
|
}
|
@@ -5161,34 +5277,51 @@ var DefaultStreamTextResult = class {
|
|
5161
5277
|
break;
|
5162
5278
|
}
|
5163
5279
|
case "tool-call": {
|
5164
|
-
|
5165
|
-
|
5166
|
-
|
5167
|
-
|
5168
|
-
|
5169
|
-
|
5170
|
-
|
5171
|
-
|
5172
|
-
|
5280
|
+
toolNamesByCallId[part.toolCallId] = part.toolName;
|
5281
|
+
const dynamic = isDynamic(part.toolCallId);
|
5282
|
+
if (part.invalid) {
|
5283
|
+
controller.enqueue({
|
5284
|
+
type: "tool-input-error",
|
5285
|
+
toolCallId: part.toolCallId,
|
5286
|
+
toolName: part.toolName,
|
5287
|
+
input: part.input,
|
5288
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5289
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
5290
|
+
...dynamic != null ? { dynamic } : {},
|
5291
|
+
errorText: onError(part.error)
|
5292
|
+
});
|
5293
|
+
} else {
|
5294
|
+
controller.enqueue({
|
5295
|
+
type: "tool-input-available",
|
5296
|
+
toolCallId: part.toolCallId,
|
5297
|
+
toolName: part.toolName,
|
5298
|
+
input: part.input,
|
5299
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5300
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
5301
|
+
...dynamic != null ? { dynamic } : {}
|
5302
|
+
});
|
5303
|
+
}
|
5173
5304
|
break;
|
5174
5305
|
}
|
5175
5306
|
case "tool-result": {
|
5307
|
+
const dynamic = isDynamic(part.toolCallId);
|
5176
5308
|
controller.enqueue({
|
5177
5309
|
type: "tool-output-available",
|
5178
5310
|
toolCallId: part.toolCallId,
|
5179
5311
|
output: part.output,
|
5180
5312
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5181
|
-
...
|
5313
|
+
...dynamic != null ? { dynamic } : {}
|
5182
5314
|
});
|
5183
5315
|
break;
|
5184
5316
|
}
|
5185
5317
|
case "tool-error": {
|
5318
|
+
const dynamic = isDynamic(part.toolCallId);
|
5186
5319
|
controller.enqueue({
|
5187
5320
|
type: "tool-output-error",
|
5188
5321
|
toolCallId: part.toolCallId,
|
5189
5322
|
errorText: onError(part.error),
|
5190
5323
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5191
|
-
...
|
5324
|
+
...dynamic != null ? { dynamic } : {}
|
5192
5325
|
});
|
5193
5326
|
break;
|
5194
5327
|
}
|
@@ -5345,7 +5478,7 @@ var Agent = class {
|
|
5345
5478
|
|
5346
5479
|
// src/embed/embed.ts
|
5347
5480
|
async function embed({
|
5348
|
-
model,
|
5481
|
+
model: modelArg,
|
5349
5482
|
value,
|
5350
5483
|
providerOptions,
|
5351
5484
|
maxRetries: maxRetriesArg,
|
@@ -5353,13 +5486,7 @@ async function embed({
|
|
5353
5486
|
headers,
|
5354
5487
|
experimental_telemetry: telemetry
|
5355
5488
|
}) {
|
5356
|
-
|
5357
|
-
throw new UnsupportedModelVersionError({
|
5358
|
-
version: model.specificationVersion,
|
5359
|
-
provider: model.provider,
|
5360
|
-
modelId: model.modelId
|
5361
|
-
});
|
5362
|
-
}
|
5489
|
+
const model = resolveEmbeddingModel(modelArg);
|
5363
5490
|
const { maxRetries, retry } = prepareRetries({
|
5364
5491
|
maxRetries: maxRetriesArg,
|
5365
5492
|
abortSignal
|
@@ -5477,7 +5604,7 @@ function splitArray(array, chunkSize) {
|
|
5477
5604
|
|
5478
5605
|
// src/embed/embed-many.ts
|
5479
5606
|
async function embedMany({
|
5480
|
-
model,
|
5607
|
+
model: modelArg,
|
5481
5608
|
values,
|
5482
5609
|
maxParallelCalls = Infinity,
|
5483
5610
|
maxRetries: maxRetriesArg,
|
@@ -5486,13 +5613,7 @@ async function embedMany({
|
|
5486
5613
|
providerOptions,
|
5487
5614
|
experimental_telemetry: telemetry
|
5488
5615
|
}) {
|
5489
|
-
|
5490
|
-
throw new UnsupportedModelVersionError({
|
5491
|
-
version: model.specificationVersion,
|
5492
|
-
provider: model.provider,
|
5493
|
-
modelId: model.modelId
|
5494
|
-
});
|
5495
|
-
}
|
5616
|
+
const model = resolveEmbeddingModel(modelArg);
|
5496
5617
|
const { maxRetries, retry } = prepareRetries({
|
5497
5618
|
maxRetries: maxRetriesArg,
|
5498
5619
|
abortSignal
|
@@ -6094,6 +6215,63 @@ function getOutputStrategy({
|
|
6094
6215
|
}
|
6095
6216
|
}
|
6096
6217
|
|
6218
|
+
// src/generate-object/parse-and-validate-object-result.ts
|
6219
|
+
import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
|
6220
|
+
import { safeParseJSON as safeParseJSON3 } from "@ai-sdk/provider-utils";
|
6221
|
+
async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
6222
|
+
const parseResult = await safeParseJSON3({ text: result });
|
6223
|
+
if (!parseResult.success) {
|
6224
|
+
throw new NoObjectGeneratedError({
|
6225
|
+
message: "No object generated: could not parse the response.",
|
6226
|
+
cause: parseResult.error,
|
6227
|
+
text: result,
|
6228
|
+
response: context.response,
|
6229
|
+
usage: context.usage,
|
6230
|
+
finishReason: context.finishReason
|
6231
|
+
});
|
6232
|
+
}
|
6233
|
+
const validationResult = await outputStrategy.validateFinalResult(
|
6234
|
+
parseResult.value,
|
6235
|
+
{
|
6236
|
+
text: result,
|
6237
|
+
response: context.response,
|
6238
|
+
usage: context.usage
|
6239
|
+
}
|
6240
|
+
);
|
6241
|
+
if (!validationResult.success) {
|
6242
|
+
throw new NoObjectGeneratedError({
|
6243
|
+
message: "No object generated: response did not match schema.",
|
6244
|
+
cause: validationResult.error,
|
6245
|
+
text: result,
|
6246
|
+
response: context.response,
|
6247
|
+
usage: context.usage,
|
6248
|
+
finishReason: context.finishReason
|
6249
|
+
});
|
6250
|
+
}
|
6251
|
+
return validationResult.value;
|
6252
|
+
}
|
6253
|
+
async function parseAndValidateObjectResultWithRepair(result, outputStrategy, repairText, context) {
|
6254
|
+
try {
|
6255
|
+
return await parseAndValidateObjectResult(result, outputStrategy, context);
|
6256
|
+
} catch (error) {
|
6257
|
+
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError3.isInstance(error.cause))) {
|
6258
|
+
const repairedText = await repairText({
|
6259
|
+
text: result,
|
6260
|
+
error: error.cause
|
6261
|
+
});
|
6262
|
+
if (repairedText === null) {
|
6263
|
+
throw error;
|
6264
|
+
}
|
6265
|
+
return await parseAndValidateObjectResult(
|
6266
|
+
repairedText,
|
6267
|
+
outputStrategy,
|
6268
|
+
context
|
6269
|
+
);
|
6270
|
+
}
|
6271
|
+
throw error;
|
6272
|
+
}
|
6273
|
+
}
|
6274
|
+
|
6097
6275
|
// src/generate-object/validate-object-generation-input.ts
|
6098
6276
|
function validateObjectGenerationInput({
|
6099
6277
|
output,
|
@@ -6212,63 +6390,6 @@ function validateObjectGenerationInput({
|
|
6212
6390
|
}
|
6213
6391
|
}
|
6214
6392
|
|
6215
|
-
// src/generate-object/parse-and-validate-object-result.ts
|
6216
|
-
import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
|
6217
|
-
import { safeParseJSON as safeParseJSON3 } from "@ai-sdk/provider-utils";
|
6218
|
-
async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
6219
|
-
const parseResult = await safeParseJSON3({ text: result });
|
6220
|
-
if (!parseResult.success) {
|
6221
|
-
throw new NoObjectGeneratedError({
|
6222
|
-
message: "No object generated: could not parse the response.",
|
6223
|
-
cause: parseResult.error,
|
6224
|
-
text: result,
|
6225
|
-
response: context.response,
|
6226
|
-
usage: context.usage,
|
6227
|
-
finishReason: context.finishReason
|
6228
|
-
});
|
6229
|
-
}
|
6230
|
-
const validationResult = await outputStrategy.validateFinalResult(
|
6231
|
-
parseResult.value,
|
6232
|
-
{
|
6233
|
-
text: result,
|
6234
|
-
response: context.response,
|
6235
|
-
usage: context.usage
|
6236
|
-
}
|
6237
|
-
);
|
6238
|
-
if (!validationResult.success) {
|
6239
|
-
throw new NoObjectGeneratedError({
|
6240
|
-
message: "No object generated: response did not match schema.",
|
6241
|
-
cause: validationResult.error,
|
6242
|
-
text: result,
|
6243
|
-
response: context.response,
|
6244
|
-
usage: context.usage,
|
6245
|
-
finishReason: context.finishReason
|
6246
|
-
});
|
6247
|
-
}
|
6248
|
-
return validationResult.value;
|
6249
|
-
}
|
6250
|
-
async function parseAndValidateObjectResultWithRepair(result, outputStrategy, repairText, context) {
|
6251
|
-
try {
|
6252
|
-
return await parseAndValidateObjectResult(result, outputStrategy, context);
|
6253
|
-
} catch (error) {
|
6254
|
-
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError3.isInstance(error.cause))) {
|
6255
|
-
const repairedText = await repairText({
|
6256
|
-
text: result,
|
6257
|
-
error: error.cause
|
6258
|
-
});
|
6259
|
-
if (repairedText === null) {
|
6260
|
-
throw error;
|
6261
|
-
}
|
6262
|
-
return await parseAndValidateObjectResult(
|
6263
|
-
repairedText,
|
6264
|
-
outputStrategy,
|
6265
|
-
context
|
6266
|
-
);
|
6267
|
-
}
|
6268
|
-
throw error;
|
6269
|
-
}
|
6270
|
-
}
|
6271
|
-
|
6272
6393
|
// src/generate-object/generate-object.ts
|
6273
6394
|
var originalGenerateId3 = createIdGenerator3({ prefix: "aiobj", size: 24 });
|
6274
6395
|
async function generateObject(options) {
|
@@ -7275,7 +7396,7 @@ __export(output_exports, {
|
|
7275
7396
|
});
|
7276
7397
|
import {
|
7277
7398
|
asSchema as asSchema4,
|
7278
|
-
safeParseJSON as
|
7399
|
+
safeParseJSON as safeParseJSON4,
|
7279
7400
|
safeValidateTypes as safeValidateTypes4
|
7280
7401
|
} from "@ai-sdk/provider-utils";
|
7281
7402
|
var text = () => ({
|
@@ -7317,7 +7438,7 @@ var object = ({
|
|
7317
7438
|
}
|
7318
7439
|
},
|
7319
7440
|
async parseOutput({ text: text2 }, context) {
|
7320
|
-
const parseResult = await
|
7441
|
+
const parseResult = await safeParseJSON4({ text: text2 });
|
7321
7442
|
if (!parseResult.success) {
|
7322
7443
|
throw new NoObjectGeneratedError({
|
7323
7444
|
message: "No object generated: could not parse the response.",
|
@@ -9249,7 +9370,7 @@ function convertToModelMessages(messages, options) {
|
|
9249
9370
|
case "assistant": {
|
9250
9371
|
if (message.parts != null) {
|
9251
9372
|
let processBlock2 = function() {
|
9252
|
-
var _a16;
|
9373
|
+
var _a16, _b;
|
9253
9374
|
if (block.length === 0) {
|
9254
9375
|
return;
|
9255
9376
|
}
|
@@ -9301,7 +9422,7 @@ function convertToModelMessages(messages, options) {
|
|
9301
9422
|
type: "tool-call",
|
9302
9423
|
toolCallId: part.toolCallId,
|
9303
9424
|
toolName,
|
9304
|
-
input: part.input,
|
9425
|
+
input: part.state === "output-error" ? (_a16 = part.input) != null ? _a16 : part.rawInput : part.input,
|
9305
9426
|
providerExecuted: part.providerExecuted,
|
9306
9427
|
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
9307
9428
|
});
|
@@ -9312,7 +9433,7 @@ function convertToModelMessages(messages, options) {
|
|
9312
9433
|
toolName,
|
9313
9434
|
output: createToolModelOutput({
|
9314
9435
|
output: part.state === "output-error" ? part.errorText : part.output,
|
9315
|
-
tool: (
|
9436
|
+
tool: (_b = options == null ? void 0 : options.tools) == null ? void 0 : _b[toolName],
|
9316
9437
|
errorMode: part.state === "output-error" ? "json" : "none"
|
9317
9438
|
})
|
9318
9439
|
});
|
@@ -9445,11 +9566,11 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
9445
9566
|
// src/ui-message-stream/create-ui-message-stream.ts
|
9446
9567
|
import {
|
9447
9568
|
generateId as generateIdFunc2,
|
9448
|
-
getErrorMessage as
|
9569
|
+
getErrorMessage as getErrorMessage8
|
9449
9570
|
} from "@ai-sdk/provider-utils";
|
9450
9571
|
function createUIMessageStream({
|
9451
9572
|
execute,
|
9452
|
-
onError =
|
9573
|
+
onError = getErrorMessage8,
|
9453
9574
|
originalMessages,
|
9454
9575
|
onFinish,
|
9455
9576
|
generateId: generateId3 = generateIdFunc2
|
@@ -9579,8 +9700,8 @@ function readUIMessageStream({
|
|
9579
9700
|
return createAsyncIterableStream(outputStream);
|
9580
9701
|
}
|
9581
9702
|
export {
|
9582
|
-
|
9583
|
-
|
9703
|
+
AISDKError16 as AISDKError,
|
9704
|
+
APICallError,
|
9584
9705
|
AbstractChat,
|
9585
9706
|
DefaultChatTransport,
|
9586
9707
|
DownloadError,
|