ai 3.0.20 → 3.0.21
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/anthropic/dist/index.d.mts +1 -353
- package/anthropic/dist/index.d.ts +1 -353
- package/anthropic/dist/index.js +30 -188
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +18 -172
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +7 -353
- package/dist/index.d.ts +7 -353
- package/dist/index.js +98 -324
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -296
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +1 -353
- package/google/dist/index.d.ts +1 -353
- package/google/dist/index.js +31 -189
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs +19 -173
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +1 -353
- package/mistral/dist/index.d.ts +1 -353
- package/mistral/dist/index.js +29 -187
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +17 -171
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +2 -354
- package/openai/dist/index.d.ts +2 -354
- package/openai/dist/index.js +64 -255
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs +52 -235
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +4 -10
- package/react/dist/index.d.mts +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs.map +1 -1
- package/solid/dist/index.d.mts +1 -1
- package/solid/dist/index.d.ts +1 -1
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +1 -1
- package/svelte/dist/index.d.ts +1 -1
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +1 -1
- package/vue/dist/index.d.ts +1 -1
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs.map +1 -1
- package/spec/dist/index.d.mts +0 -780
- package/spec/dist/index.d.ts +0 -780
- package/spec/dist/index.js +0 -863
- package/spec/dist/index.js.map +0 -1
- package/spec/dist/index.mjs +0 -797
- package/spec/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
@@ -75,118 +75,8 @@ __export(streams_exports, {
|
|
75
75
|
});
|
76
76
|
module.exports = __toCommonJS(streams_exports);
|
77
77
|
|
78
|
-
//
|
79
|
-
var
|
80
|
-
constructor({
|
81
|
-
message,
|
82
|
-
url,
|
83
|
-
requestBodyValues,
|
84
|
-
statusCode,
|
85
|
-
responseBody,
|
86
|
-
cause,
|
87
|
-
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
88
|
-
statusCode === 409 || // conflict
|
89
|
-
statusCode === 429 || // too many requests
|
90
|
-
statusCode >= 500),
|
91
|
-
// server error
|
92
|
-
data
|
93
|
-
}) {
|
94
|
-
super(message);
|
95
|
-
this.name = "AI_APICallError";
|
96
|
-
this.url = url;
|
97
|
-
this.requestBodyValues = requestBodyValues;
|
98
|
-
this.statusCode = statusCode;
|
99
|
-
this.responseBody = responseBody;
|
100
|
-
this.cause = cause;
|
101
|
-
this.isRetryable = isRetryable;
|
102
|
-
this.data = data;
|
103
|
-
}
|
104
|
-
static isAPICallError(error) {
|
105
|
-
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
106
|
-
}
|
107
|
-
toJSON() {
|
108
|
-
return {
|
109
|
-
name: this.name,
|
110
|
-
message: this.message,
|
111
|
-
url: this.url,
|
112
|
-
requestBodyValues: this.requestBodyValues,
|
113
|
-
statusCode: this.statusCode,
|
114
|
-
responseBody: this.responseBody,
|
115
|
-
cause: this.cause,
|
116
|
-
isRetryable: this.isRetryable,
|
117
|
-
data: this.data
|
118
|
-
};
|
119
|
-
}
|
120
|
-
};
|
121
|
-
|
122
|
-
// spec/errors/invalid-argument-error.ts
|
123
|
-
var InvalidArgumentError = class extends Error {
|
124
|
-
constructor({
|
125
|
-
parameter,
|
126
|
-
value,
|
127
|
-
message
|
128
|
-
}) {
|
129
|
-
super(`Invalid argument for parameter ${parameter}: ${message}`);
|
130
|
-
this.name = "AI_InvalidArgumentError";
|
131
|
-
this.parameter = parameter;
|
132
|
-
this.value = value;
|
133
|
-
}
|
134
|
-
static isInvalidArgumentError(error) {
|
135
|
-
return error instanceof Error && error.name === "AI_InvalidArgumentError" && typeof error.parameter === "string" && typeof error.value === "string";
|
136
|
-
}
|
137
|
-
toJSON() {
|
138
|
-
return {
|
139
|
-
name: this.name,
|
140
|
-
message: this.message,
|
141
|
-
stack: this.stack,
|
142
|
-
parameter: this.parameter,
|
143
|
-
value: this.value
|
144
|
-
};
|
145
|
-
}
|
146
|
-
};
|
147
|
-
|
148
|
-
// spec/errors/invalid-data-content-error.ts
|
149
|
-
var InvalidDataContentError = class extends Error {
|
150
|
-
constructor({
|
151
|
-
content,
|
152
|
-
message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
153
|
-
}) {
|
154
|
-
super(message);
|
155
|
-
this.name = "AI_InvalidDataContentError";
|
156
|
-
this.content = content;
|
157
|
-
}
|
158
|
-
static isInvalidDataContentError(error) {
|
159
|
-
return error instanceof Error && error.name === "AI_InvalidDataContentError" && error.content != null;
|
160
|
-
}
|
161
|
-
toJSON() {
|
162
|
-
return {
|
163
|
-
name: this.name,
|
164
|
-
message: this.message,
|
165
|
-
stack: this.stack,
|
166
|
-
content: this.content
|
167
|
-
};
|
168
|
-
}
|
169
|
-
};
|
170
|
-
|
171
|
-
// spec/errors/invalid-prompt-error.ts
|
172
|
-
var InvalidPromptError = class extends Error {
|
173
|
-
constructor({ prompt: prompt2, message }) {
|
174
|
-
super(`Invalid prompt: ${message}`);
|
175
|
-
this.name = "AI_InvalidPromptError";
|
176
|
-
this.prompt = prompt2;
|
177
|
-
}
|
178
|
-
static isInvalidPromptError(error) {
|
179
|
-
return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
|
180
|
-
}
|
181
|
-
toJSON() {
|
182
|
-
return {
|
183
|
-
name: this.name,
|
184
|
-
message: this.message,
|
185
|
-
stack: this.stack,
|
186
|
-
prompt: this.prompt
|
187
|
-
};
|
188
|
-
}
|
189
|
-
};
|
78
|
+
// core/generate-object/generate-object.ts
|
79
|
+
var import_provider7 = require("@ai-sdk/provider");
|
190
80
|
|
191
81
|
// spec/util/get-error-message.ts
|
192
82
|
function getErrorMessage(error) {
|
@@ -203,59 +93,11 @@ function getErrorMessage(error) {
|
|
203
93
|
}
|
204
94
|
|
205
95
|
// spec/util/parse-json.ts
|
96
|
+
var import_provider2 = require("@ai-sdk/provider");
|
206
97
|
var import_secure_json_parse = __toESM(require("secure-json-parse"));
|
207
98
|
|
208
|
-
// spec/errors/json-parse-error.ts
|
209
|
-
var JSONParseError = class extends Error {
|
210
|
-
constructor({ text, cause }) {
|
211
|
-
super(
|
212
|
-
`JSON parsing failed: Text: ${text}.
|
213
|
-
Error message: ${getErrorMessage(cause)}`
|
214
|
-
);
|
215
|
-
this.name = "AI_JSONParseError";
|
216
|
-
this.cause = cause;
|
217
|
-
this.text = text;
|
218
|
-
}
|
219
|
-
static isJSONParseError(error) {
|
220
|
-
return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
|
221
|
-
}
|
222
|
-
toJSON() {
|
223
|
-
return {
|
224
|
-
name: this.name,
|
225
|
-
message: this.message,
|
226
|
-
cause: this.cause,
|
227
|
-
stack: this.stack,
|
228
|
-
valueText: this.text
|
229
|
-
};
|
230
|
-
}
|
231
|
-
};
|
232
|
-
|
233
|
-
// spec/errors/type-validation-error.ts
|
234
|
-
var TypeValidationError = class extends Error {
|
235
|
-
constructor({ value, cause }) {
|
236
|
-
super(
|
237
|
-
`Type validation failed: Value: ${JSON.stringify(value)}.
|
238
|
-
Error message: ${getErrorMessage(cause)}`
|
239
|
-
);
|
240
|
-
this.name = "AI_TypeValidationError";
|
241
|
-
this.cause = cause;
|
242
|
-
this.value = value;
|
243
|
-
}
|
244
|
-
static isTypeValidationError(error) {
|
245
|
-
return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
|
246
|
-
}
|
247
|
-
toJSON() {
|
248
|
-
return {
|
249
|
-
name: this.name,
|
250
|
-
message: this.message,
|
251
|
-
cause: this.cause,
|
252
|
-
stack: this.stack,
|
253
|
-
value: this.value
|
254
|
-
};
|
255
|
-
}
|
256
|
-
};
|
257
|
-
|
258
99
|
// spec/util/validate-types.ts
|
100
|
+
var import_provider = require("@ai-sdk/provider");
|
259
101
|
function safeValidateTypes({
|
260
102
|
value,
|
261
103
|
schema
|
@@ -270,7 +112,7 @@ function safeValidateTypes({
|
|
270
112
|
}
|
271
113
|
return {
|
272
114
|
success: false,
|
273
|
-
error: new TypeValidationError({
|
115
|
+
error: new import_provider.TypeValidationError({
|
274
116
|
value,
|
275
117
|
cause: validationResult.error
|
276
118
|
})
|
@@ -278,7 +120,7 @@ function safeValidateTypes({
|
|
278
120
|
} catch (error) {
|
279
121
|
return {
|
280
122
|
success: false,
|
281
|
-
error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
|
123
|
+
error: import_provider.TypeValidationError.isTypeValidationError(error) ? error : new import_provider.TypeValidationError({ value, cause: error })
|
282
124
|
};
|
283
125
|
}
|
284
126
|
}
|
@@ -300,7 +142,7 @@ function safeParseJSON({
|
|
300
142
|
} catch (error) {
|
301
143
|
return {
|
302
144
|
success: false,
|
303
|
-
error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
|
145
|
+
error: import_provider2.JSONParseError.isJSONParseError(error) ? error : new import_provider2.JSONParseError({ text, cause: error })
|
304
146
|
};
|
305
147
|
}
|
306
148
|
}
|
@@ -319,109 +161,6 @@ function convertUint8ArrayToBase64(array) {
|
|
319
161
|
return globalThis.btoa(latin1string);
|
320
162
|
}
|
321
163
|
|
322
|
-
// spec/errors/invalid-tool-arguments-error.ts
|
323
|
-
var InvalidToolArgumentsError = class extends Error {
|
324
|
-
constructor({
|
325
|
-
toolArgs,
|
326
|
-
toolName,
|
327
|
-
cause,
|
328
|
-
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
|
329
|
-
cause
|
330
|
-
)}`
|
331
|
-
}) {
|
332
|
-
super(message);
|
333
|
-
this.name = "AI_InvalidToolArgumentsError";
|
334
|
-
this.toolArgs = toolArgs;
|
335
|
-
this.toolName = toolName;
|
336
|
-
this.cause = cause;
|
337
|
-
}
|
338
|
-
static isInvalidToolArgumentsError(error) {
|
339
|
-
return error instanceof Error && error.name === "AI_InvalidToolArgumentsError" && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
340
|
-
}
|
341
|
-
toJSON() {
|
342
|
-
return {
|
343
|
-
name: this.name,
|
344
|
-
message: this.message,
|
345
|
-
cause: this.cause,
|
346
|
-
stack: this.stack,
|
347
|
-
toolName: this.toolName,
|
348
|
-
toolArgs: this.toolArgs
|
349
|
-
};
|
350
|
-
}
|
351
|
-
};
|
352
|
-
|
353
|
-
// spec/errors/no-object-generated-error.ts
|
354
|
-
var NoTextGeneratedError = class extends Error {
|
355
|
-
constructor() {
|
356
|
-
super(`No text generated.`);
|
357
|
-
this.name = "AI_NoTextGeneratedError";
|
358
|
-
}
|
359
|
-
static isNoTextGeneratedError(error) {
|
360
|
-
return error instanceof Error && error.name === "AI_NoTextGeneratedError";
|
361
|
-
}
|
362
|
-
toJSON() {
|
363
|
-
return {
|
364
|
-
name: this.name,
|
365
|
-
cause: this.cause,
|
366
|
-
message: this.message,
|
367
|
-
stack: this.stack
|
368
|
-
};
|
369
|
-
}
|
370
|
-
};
|
371
|
-
|
372
|
-
// spec/errors/no-such-tool-error.ts
|
373
|
-
var NoSuchToolError = class extends Error {
|
374
|
-
constructor({
|
375
|
-
toolName,
|
376
|
-
availableTools = void 0,
|
377
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
378
|
-
}) {
|
379
|
-
super(message);
|
380
|
-
this.name = "AI_NoSuchToolError";
|
381
|
-
this.toolName = toolName;
|
382
|
-
this.availableTools = availableTools;
|
383
|
-
}
|
384
|
-
static isNoSuchToolError(error) {
|
385
|
-
return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
386
|
-
}
|
387
|
-
toJSON() {
|
388
|
-
return {
|
389
|
-
name: this.name,
|
390
|
-
message: this.message,
|
391
|
-
stack: this.stack,
|
392
|
-
toolName: this.toolName,
|
393
|
-
availableTools: this.availableTools
|
394
|
-
};
|
395
|
-
}
|
396
|
-
};
|
397
|
-
|
398
|
-
// spec/errors/retry-error.ts
|
399
|
-
var RetryError = class extends Error {
|
400
|
-
constructor({
|
401
|
-
message,
|
402
|
-
reason,
|
403
|
-
errors
|
404
|
-
}) {
|
405
|
-
super(message);
|
406
|
-
this.name = "AI_RetryError";
|
407
|
-
this.reason = reason;
|
408
|
-
this.errors = errors;
|
409
|
-
this.lastError = errors[errors.length - 1];
|
410
|
-
}
|
411
|
-
static isRetryError(error) {
|
412
|
-
return error instanceof Error && error.name === "AI_RetryError" && typeof error.reason === "string" && Array.isArray(error.errors);
|
413
|
-
}
|
414
|
-
toJSON() {
|
415
|
-
return {
|
416
|
-
name: this.name,
|
417
|
-
message: this.message,
|
418
|
-
reason: this.reason,
|
419
|
-
lastError: this.lastError,
|
420
|
-
errors: this.errors
|
421
|
-
};
|
422
|
-
}
|
423
|
-
};
|
424
|
-
|
425
164
|
// core/generate-text/token-usage.ts
|
426
165
|
function calculateTokenUsage(usage) {
|
427
166
|
return {
|
@@ -448,6 +187,7 @@ function detectImageMimeType(image) {
|
|
448
187
|
}
|
449
188
|
|
450
189
|
// core/prompt/data-content.ts
|
190
|
+
var import_provider3 = require("@ai-sdk/provider");
|
451
191
|
function convertDataContentToBase64String(content) {
|
452
192
|
if (typeof content === "string") {
|
453
193
|
return content;
|
@@ -467,26 +207,26 @@ function convertDataContentToUint8Array(content) {
|
|
467
207
|
if (content instanceof ArrayBuffer) {
|
468
208
|
return new Uint8Array(content);
|
469
209
|
}
|
470
|
-
throw new InvalidDataContentError({ content });
|
210
|
+
throw new import_provider3.InvalidDataContentError({ content });
|
471
211
|
}
|
472
212
|
|
473
213
|
// core/prompt/convert-to-language-model-prompt.ts
|
474
|
-
function convertToLanguageModelPrompt(
|
214
|
+
function convertToLanguageModelPrompt(prompt) {
|
475
215
|
const languageModelMessages = [];
|
476
|
-
if (
|
477
|
-
languageModelMessages.push({ role: "system", content:
|
216
|
+
if (prompt.system != null) {
|
217
|
+
languageModelMessages.push({ role: "system", content: prompt.system });
|
478
218
|
}
|
479
|
-
switch (
|
219
|
+
switch (prompt.type) {
|
480
220
|
case "prompt": {
|
481
221
|
languageModelMessages.push({
|
482
222
|
role: "user",
|
483
|
-
content: [{ type: "text", text:
|
223
|
+
content: [{ type: "text", text: prompt.prompt }]
|
484
224
|
});
|
485
225
|
break;
|
486
226
|
}
|
487
227
|
case "messages": {
|
488
228
|
languageModelMessages.push(
|
489
|
-
...
|
229
|
+
...prompt.messages.map((message) => {
|
490
230
|
switch (message.role) {
|
491
231
|
case "user": {
|
492
232
|
if (typeof message.content === "string") {
|
@@ -544,7 +284,7 @@ function convertToLanguageModelPrompt(prompt2) {
|
|
544
284
|
break;
|
545
285
|
}
|
546
286
|
default: {
|
547
|
-
const _exhaustiveCheck =
|
287
|
+
const _exhaustiveCheck = prompt;
|
548
288
|
throw new Error(`Unsupported prompt type: ${_exhaustiveCheck}`);
|
549
289
|
}
|
550
290
|
}
|
@@ -552,34 +292,36 @@ function convertToLanguageModelPrompt(prompt2) {
|
|
552
292
|
}
|
553
293
|
|
554
294
|
// core/prompt/get-validated-prompt.ts
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
295
|
+
var import_provider4 = require("@ai-sdk/provider");
|
296
|
+
function getValidatedPrompt(prompt) {
|
297
|
+
if (prompt.prompt == null && prompt.messages == null) {
|
298
|
+
throw new import_provider4.InvalidPromptError({
|
299
|
+
prompt,
|
559
300
|
message: "prompt or messages must be defined"
|
560
301
|
});
|
561
302
|
}
|
562
|
-
if (
|
563
|
-
throw new InvalidPromptError({
|
564
|
-
prompt
|
303
|
+
if (prompt.prompt != null && prompt.messages != null) {
|
304
|
+
throw new import_provider4.InvalidPromptError({
|
305
|
+
prompt,
|
565
306
|
message: "prompt and messages cannot be defined at the same time"
|
566
307
|
});
|
567
308
|
}
|
568
|
-
return
|
309
|
+
return prompt.prompt != null ? {
|
569
310
|
type: "prompt",
|
570
|
-
prompt:
|
311
|
+
prompt: prompt.prompt,
|
571
312
|
messages: void 0,
|
572
|
-
system:
|
313
|
+
system: prompt.system
|
573
314
|
} : {
|
574
315
|
type: "messages",
|
575
316
|
prompt: void 0,
|
576
|
-
messages:
|
317
|
+
messages: prompt.messages,
|
577
318
|
// only possible case bc of checks above
|
578
|
-
system:
|
319
|
+
system: prompt.system
|
579
320
|
};
|
580
321
|
}
|
581
322
|
|
582
323
|
// core/prompt/prepare-call-settings.ts
|
324
|
+
var import_provider5 = require("@ai-sdk/provider");
|
583
325
|
function prepareCallSettings({
|
584
326
|
maxTokens,
|
585
327
|
temperature,
|
@@ -591,14 +333,14 @@ function prepareCallSettings({
|
|
591
333
|
}) {
|
592
334
|
if (maxTokens != null) {
|
593
335
|
if (!Number.isInteger(maxTokens)) {
|
594
|
-
throw new InvalidArgumentError({
|
336
|
+
throw new import_provider5.InvalidArgumentError({
|
595
337
|
parameter: "maxTokens",
|
596
338
|
value: maxTokens,
|
597
339
|
message: "maxTokens must be an integer"
|
598
340
|
});
|
599
341
|
}
|
600
342
|
if (maxTokens < 1) {
|
601
|
-
throw new InvalidArgumentError({
|
343
|
+
throw new import_provider5.InvalidArgumentError({
|
602
344
|
parameter: "maxTokens",
|
603
345
|
value: maxTokens,
|
604
346
|
message: "maxTokens must be >= 1"
|
@@ -607,14 +349,14 @@ function prepareCallSettings({
|
|
607
349
|
}
|
608
350
|
if (temperature != null) {
|
609
351
|
if (typeof temperature !== "number") {
|
610
|
-
throw new InvalidArgumentError({
|
352
|
+
throw new import_provider5.InvalidArgumentError({
|
611
353
|
parameter: "temperature",
|
612
354
|
value: temperature,
|
613
355
|
message: "temperature must be a number"
|
614
356
|
});
|
615
357
|
}
|
616
358
|
if (temperature < 0 || temperature > 1) {
|
617
|
-
throw new InvalidArgumentError({
|
359
|
+
throw new import_provider5.InvalidArgumentError({
|
618
360
|
parameter: "temperature",
|
619
361
|
value: temperature,
|
620
362
|
message: "temperature must be between 0 and 1 (inclusive)"
|
@@ -623,14 +365,14 @@ function prepareCallSettings({
|
|
623
365
|
}
|
624
366
|
if (topP != null) {
|
625
367
|
if (typeof topP !== "number") {
|
626
|
-
throw new InvalidArgumentError({
|
368
|
+
throw new import_provider5.InvalidArgumentError({
|
627
369
|
parameter: "topP",
|
628
370
|
value: topP,
|
629
371
|
message: "topP must be a number"
|
630
372
|
});
|
631
373
|
}
|
632
374
|
if (topP < 0 || topP > 1) {
|
633
|
-
throw new InvalidArgumentError({
|
375
|
+
throw new import_provider5.InvalidArgumentError({
|
634
376
|
parameter: "topP",
|
635
377
|
value: topP,
|
636
378
|
message: "topP must be between 0 and 1 (inclusive)"
|
@@ -639,14 +381,14 @@ function prepareCallSettings({
|
|
639
381
|
}
|
640
382
|
if (presencePenalty != null) {
|
641
383
|
if (typeof presencePenalty !== "number") {
|
642
|
-
throw new InvalidArgumentError({
|
384
|
+
throw new import_provider5.InvalidArgumentError({
|
643
385
|
parameter: "presencePenalty",
|
644
386
|
value: presencePenalty,
|
645
387
|
message: "presencePenalty must be a number"
|
646
388
|
});
|
647
389
|
}
|
648
390
|
if (presencePenalty < -1 || presencePenalty > 1) {
|
649
|
-
throw new InvalidArgumentError({
|
391
|
+
throw new import_provider5.InvalidArgumentError({
|
650
392
|
parameter: "presencePenalty",
|
651
393
|
value: presencePenalty,
|
652
394
|
message: "presencePenalty must be between -1 and 1 (inclusive)"
|
@@ -655,14 +397,14 @@ function prepareCallSettings({
|
|
655
397
|
}
|
656
398
|
if (frequencyPenalty != null) {
|
657
399
|
if (typeof frequencyPenalty !== "number") {
|
658
|
-
throw new InvalidArgumentError({
|
400
|
+
throw new import_provider5.InvalidArgumentError({
|
659
401
|
parameter: "frequencyPenalty",
|
660
402
|
value: frequencyPenalty,
|
661
403
|
message: "frequencyPenalty must be a number"
|
662
404
|
});
|
663
405
|
}
|
664
406
|
if (frequencyPenalty < -1 || frequencyPenalty > 1) {
|
665
|
-
throw new InvalidArgumentError({
|
407
|
+
throw new import_provider5.InvalidArgumentError({
|
666
408
|
parameter: "frequencyPenalty",
|
667
409
|
value: frequencyPenalty,
|
668
410
|
message: "frequencyPenalty must be between -1 and 1 (inclusive)"
|
@@ -671,7 +413,7 @@ function prepareCallSettings({
|
|
671
413
|
}
|
672
414
|
if (seed != null) {
|
673
415
|
if (!Number.isInteger(seed)) {
|
674
|
-
throw new InvalidArgumentError({
|
416
|
+
throw new import_provider5.InvalidArgumentError({
|
675
417
|
parameter: "seed",
|
676
418
|
value: seed,
|
677
419
|
message: "seed must be an integer"
|
@@ -680,14 +422,14 @@ function prepareCallSettings({
|
|
680
422
|
}
|
681
423
|
if (maxRetries != null) {
|
682
424
|
if (!Number.isInteger(maxRetries)) {
|
683
|
-
throw new InvalidArgumentError({
|
425
|
+
throw new import_provider5.InvalidArgumentError({
|
684
426
|
parameter: "maxRetries",
|
685
427
|
value: maxRetries,
|
686
428
|
message: "maxRetries must be an integer"
|
687
429
|
});
|
688
430
|
}
|
689
431
|
if (maxRetries < 0) {
|
690
|
-
throw new InvalidArgumentError({
|
432
|
+
throw new import_provider5.InvalidArgumentError({
|
691
433
|
parameter: "maxRetries",
|
692
434
|
value: maxRetries,
|
693
435
|
message: "maxRetries must be >= 0"
|
@@ -711,6 +453,9 @@ function convertZodToJSONSchema(zodSchema) {
|
|
711
453
|
return (0, import_zod_to_json_schema.default)(zodSchema);
|
712
454
|
}
|
713
455
|
|
456
|
+
// core/util/retry-with-exponential-backoff.ts
|
457
|
+
var import_provider6 = require("@ai-sdk/provider");
|
458
|
+
|
714
459
|
// core/util/delay.ts
|
715
460
|
async function delay(delayInMs) {
|
716
461
|
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
@@ -744,13 +489,13 @@ async function _retryWithExponentialBackoff(f, {
|
|
744
489
|
const newErrors = [...errors, error];
|
745
490
|
const tryNumber = newErrors.length;
|
746
491
|
if (tryNumber > maxRetries) {
|
747
|
-
throw new RetryError({
|
492
|
+
throw new import_provider6.RetryError({
|
748
493
|
message: `Failed after ${tryNumber} attemps. Last error: ${errorMessage}`,
|
749
494
|
reason: "maxRetriesExceeded",
|
750
495
|
errors: newErrors
|
751
496
|
});
|
752
497
|
}
|
753
|
-
if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
498
|
+
if (error instanceof Error && import_provider6.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
754
499
|
await delay(delayInMs);
|
755
500
|
return _retryWithExponentialBackoff(
|
756
501
|
f,
|
@@ -761,7 +506,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
761
506
|
if (tryNumber === 1) {
|
762
507
|
throw error;
|
763
508
|
}
|
764
|
-
throw new RetryError({
|
509
|
+
throw new import_provider6.RetryError({
|
765
510
|
message: `Failed after ${tryNumber} attemps with non-retryable error: '${errorMessage}'`,
|
766
511
|
reason: "errorNotRetryable",
|
767
512
|
errors: newErrors
|
@@ -794,7 +539,7 @@ async function experimental_generateObject({
|
|
794
539
|
schema,
|
795
540
|
mode,
|
796
541
|
system,
|
797
|
-
prompt
|
542
|
+
prompt,
|
798
543
|
messages,
|
799
544
|
maxRetries,
|
800
545
|
abortSignal,
|
@@ -814,7 +559,7 @@ async function experimental_generateObject({
|
|
814
559
|
case "json": {
|
815
560
|
const validatedPrompt = getValidatedPrompt({
|
816
561
|
system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
|
817
|
-
prompt
|
562
|
+
prompt,
|
818
563
|
messages
|
819
564
|
});
|
820
565
|
const generateResult = await retry(() => {
|
@@ -827,7 +572,7 @@ async function experimental_generateObject({
|
|
827
572
|
});
|
828
573
|
});
|
829
574
|
if (generateResult.text === void 0) {
|
830
|
-
throw new NoTextGeneratedError();
|
575
|
+
throw new import_provider7.NoTextGeneratedError();
|
831
576
|
}
|
832
577
|
result = generateResult.text;
|
833
578
|
finishReason = generateResult.finishReason;
|
@@ -838,7 +583,7 @@ async function experimental_generateObject({
|
|
838
583
|
case "grammar": {
|
839
584
|
const validatedPrompt = getValidatedPrompt({
|
840
585
|
system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
|
841
|
-
prompt
|
586
|
+
prompt,
|
842
587
|
messages
|
843
588
|
});
|
844
589
|
const generateResult = await retry(
|
@@ -851,7 +596,7 @@ async function experimental_generateObject({
|
|
851
596
|
})
|
852
597
|
);
|
853
598
|
if (generateResult.text === void 0) {
|
854
|
-
throw new NoTextGeneratedError();
|
599
|
+
throw new import_provider7.NoTextGeneratedError();
|
855
600
|
}
|
856
601
|
result = generateResult.text;
|
857
602
|
finishReason = generateResult.finishReason;
|
@@ -862,7 +607,7 @@ async function experimental_generateObject({
|
|
862
607
|
case "tool": {
|
863
608
|
const validatedPrompt = getValidatedPrompt({
|
864
609
|
system,
|
865
|
-
prompt
|
610
|
+
prompt,
|
866
611
|
messages
|
867
612
|
});
|
868
613
|
const generateResult = await retry(
|
@@ -884,7 +629,7 @@ async function experimental_generateObject({
|
|
884
629
|
);
|
885
630
|
const functionArgs = (_b = (_a = generateResult.toolCalls) == null ? void 0 : _a[0]) == null ? void 0 : _b.args;
|
886
631
|
if (functionArgs === void 0) {
|
887
|
-
throw new NoTextGeneratedError();
|
632
|
+
throw new import_provider7.NoTextGeneratedError();
|
888
633
|
}
|
889
634
|
result = functionArgs;
|
890
635
|
finishReason = generateResult.finishReason;
|
@@ -1315,7 +1060,7 @@ async function experimental_streamObject({
|
|
1315
1060
|
schema,
|
1316
1061
|
mode,
|
1317
1062
|
system,
|
1318
|
-
prompt
|
1063
|
+
prompt,
|
1319
1064
|
messages,
|
1320
1065
|
maxRetries,
|
1321
1066
|
abortSignal,
|
@@ -1332,7 +1077,7 @@ async function experimental_streamObject({
|
|
1332
1077
|
case "json": {
|
1333
1078
|
const validatedPrompt = getValidatedPrompt({
|
1334
1079
|
system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
|
1335
|
-
prompt
|
1080
|
+
prompt,
|
1336
1081
|
messages
|
1337
1082
|
});
|
1338
1083
|
callOptions = {
|
@@ -1359,7 +1104,7 @@ async function experimental_streamObject({
|
|
1359
1104
|
case "grammar": {
|
1360
1105
|
const validatedPrompt = getValidatedPrompt({
|
1361
1106
|
system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
|
1362
|
-
prompt
|
1107
|
+
prompt,
|
1363
1108
|
messages
|
1364
1109
|
});
|
1365
1110
|
callOptions = {
|
@@ -1386,7 +1131,7 @@ async function experimental_streamObject({
|
|
1386
1131
|
case "tool": {
|
1387
1132
|
const validatedPrompt = getValidatedPrompt({
|
1388
1133
|
system,
|
1389
|
-
prompt
|
1134
|
+
prompt,
|
1390
1135
|
messages
|
1391
1136
|
});
|
1392
1137
|
callOptions = {
|
@@ -1464,17 +1209,18 @@ var StreamObjectResult = class {
|
|
1464
1209
|
};
|
1465
1210
|
|
1466
1211
|
// core/generate-text/tool-call.ts
|
1212
|
+
var import_provider8 = require("@ai-sdk/provider");
|
1467
1213
|
function parseToolCall({
|
1468
1214
|
toolCall,
|
1469
1215
|
tools
|
1470
1216
|
}) {
|
1471
1217
|
const toolName = toolCall.toolName;
|
1472
1218
|
if (tools == null) {
|
1473
|
-
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1219
|
+
throw new import_provider8.NoSuchToolError({ toolName: toolCall.toolName });
|
1474
1220
|
}
|
1475
1221
|
const tool2 = tools[toolName];
|
1476
1222
|
if (tool2 == null) {
|
1477
|
-
throw new NoSuchToolError({
|
1223
|
+
throw new import_provider8.NoSuchToolError({
|
1478
1224
|
toolName: toolCall.toolName,
|
1479
1225
|
availableTools: Object.keys(tools)
|
1480
1226
|
});
|
@@ -1484,7 +1230,7 @@ function parseToolCall({
|
|
1484
1230
|
schema: tool2.parameters
|
1485
1231
|
});
|
1486
1232
|
if (parseResult.success === false) {
|
1487
|
-
throw new InvalidToolArgumentsError({
|
1233
|
+
throw new import_provider8.InvalidToolArgumentsError({
|
1488
1234
|
toolName,
|
1489
1235
|
toolArgs: toolCall.args,
|
1490
1236
|
cause: parseResult.error
|
@@ -1503,7 +1249,7 @@ async function experimental_generateText({
|
|
1503
1249
|
model,
|
1504
1250
|
tools,
|
1505
1251
|
system,
|
1506
|
-
prompt
|
1252
|
+
prompt,
|
1507
1253
|
messages,
|
1508
1254
|
maxRetries,
|
1509
1255
|
abortSignal,
|
@@ -1511,7 +1257,7 @@ async function experimental_generateText({
|
|
1511
1257
|
}) {
|
1512
1258
|
var _a, _b;
|
1513
1259
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1514
|
-
const validatedPrompt = getValidatedPrompt({ system, prompt
|
1260
|
+
const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
|
1515
1261
|
const modelResponse = await retry(() => {
|
1516
1262
|
return model.doGenerate({
|
1517
1263
|
mode: {
|
@@ -1580,6 +1326,9 @@ var GenerateTextResult = class {
|
|
1580
1326
|
}
|
1581
1327
|
};
|
1582
1328
|
|
1329
|
+
// core/generate-text/run-tools-transformation.ts
|
1330
|
+
var import_provider9 = require("@ai-sdk/provider");
|
1331
|
+
|
1583
1332
|
// shared/generate-id.ts
|
1584
1333
|
var import_non_secure = require("nanoid/non-secure");
|
1585
1334
|
var generateId = (0, import_non_secure.customAlphabet)(
|
@@ -1614,7 +1363,7 @@ function runToolsTransformation({
|
|
1614
1363
|
if (tools == null) {
|
1615
1364
|
toolResultsStreamController.enqueue({
|
1616
1365
|
type: "error",
|
1617
|
-
error: new NoSuchToolError({ toolName: chunk.toolName })
|
1366
|
+
error: new import_provider9.NoSuchToolError({ toolName: chunk.toolName })
|
1618
1367
|
});
|
1619
1368
|
break;
|
1620
1369
|
}
|
@@ -1622,7 +1371,7 @@ function runToolsTransformation({
|
|
1622
1371
|
if (tool2 == null) {
|
1623
1372
|
toolResultsStreamController.enqueue({
|
1624
1373
|
type: "error",
|
1625
|
-
error: new NoSuchToolError({
|
1374
|
+
error: new import_provider9.NoSuchToolError({
|
1626
1375
|
toolName: chunk.toolName,
|
1627
1376
|
availableTools: Object.keys(tools)
|
1628
1377
|
})
|
@@ -1728,14 +1477,14 @@ async function experimental_streamText({
|
|
1728
1477
|
model,
|
1729
1478
|
tools,
|
1730
1479
|
system,
|
1731
|
-
prompt
|
1480
|
+
prompt,
|
1732
1481
|
messages,
|
1733
1482
|
maxRetries,
|
1734
1483
|
abortSignal,
|
1735
1484
|
...settings
|
1736
1485
|
}) {
|
1737
1486
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1738
|
-
const validatedPrompt = getValidatedPrompt({ system, prompt
|
1487
|
+
const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
|
1739
1488
|
const { stream, warnings } = await retry(
|
1740
1489
|
() => model.doStream({
|
1741
1490
|
mode: {
|
@@ -1818,6 +1567,31 @@ var StreamTextResult = class {
|
|
1818
1567
|
toAIStream(callbacks) {
|
1819
1568
|
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1820
1569
|
}
|
1570
|
+
/**
|
1571
|
+
Creates a simple text stream response.
|
1572
|
+
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
1573
|
+
Non-text-delta events are ignored.
|
1574
|
+
*/
|
1575
|
+
toTextStreamResponse(init) {
|
1576
|
+
const encoder = new TextEncoder();
|
1577
|
+
return new Response(
|
1578
|
+
this.textStream.pipeThrough(
|
1579
|
+
new TransformStream({
|
1580
|
+
transform(chunk, controller) {
|
1581
|
+
controller.enqueue(encoder.encode(chunk));
|
1582
|
+
}
|
1583
|
+
})
|
1584
|
+
),
|
1585
|
+
{
|
1586
|
+
...init,
|
1587
|
+
status: 200,
|
1588
|
+
headers: {
|
1589
|
+
"Content-Type": "text/plain; charset=utf-8",
|
1590
|
+
...init == null ? void 0 : init.headers
|
1591
|
+
}
|
1592
|
+
}
|
1593
|
+
);
|
1594
|
+
}
|
1821
1595
|
};
|
1822
1596
|
|
1823
1597
|
// core/tool/tool.ts
|