ai 3.0.20 → 3.0.22

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.
Files changed (63) hide show
  1. package/dist/index.d.mts +45 -354
  2. package/dist/index.d.ts +45 -354
  3. package/dist/index.js +161 -460
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +136 -430
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +6 -41
  8. package/react/dist/index.d.mts +1 -1
  9. package/react/dist/index.d.ts +1 -1
  10. package/react/dist/index.js +3 -3
  11. package/react/dist/index.js.map +1 -1
  12. package/react/dist/index.mjs +3 -3
  13. package/react/dist/index.mjs.map +1 -1
  14. package/rsc/dist/rsc-server.mjs +3 -3
  15. package/rsc/dist/rsc-server.mjs.map +1 -1
  16. package/solid/dist/index.d.mts +1 -1
  17. package/solid/dist/index.d.ts +1 -1
  18. package/solid/dist/index.js +3 -3
  19. package/solid/dist/index.js.map +1 -1
  20. package/solid/dist/index.mjs +3 -3
  21. package/solid/dist/index.mjs.map +1 -1
  22. package/svelte/dist/index.d.mts +1 -1
  23. package/svelte/dist/index.d.ts +1 -1
  24. package/svelte/dist/index.js +3 -3
  25. package/svelte/dist/index.js.map +1 -1
  26. package/svelte/dist/index.mjs +3 -3
  27. package/svelte/dist/index.mjs.map +1 -1
  28. package/vue/dist/index.d.mts +1 -1
  29. package/vue/dist/index.d.ts +1 -1
  30. package/vue/dist/index.js +3 -3
  31. package/vue/dist/index.js.map +1 -1
  32. package/vue/dist/index.mjs +3 -3
  33. package/vue/dist/index.mjs.map +1 -1
  34. package/anthropic/dist/index.d.mts +0 -403
  35. package/anthropic/dist/index.d.ts +0 -403
  36. package/anthropic/dist/index.js +0 -950
  37. package/anthropic/dist/index.js.map +0 -1
  38. package/anthropic/dist/index.mjs +0 -914
  39. package/anthropic/dist/index.mjs.map +0 -1
  40. package/google/dist/index.d.mts +0 -399
  41. package/google/dist/index.d.ts +0 -399
  42. package/google/dist/index.js +0 -954
  43. package/google/dist/index.js.map +0 -1
  44. package/google/dist/index.mjs +0 -918
  45. package/google/dist/index.mjs.map +0 -1
  46. package/mistral/dist/index.d.mts +0 -404
  47. package/mistral/dist/index.d.ts +0 -404
  48. package/mistral/dist/index.js +0 -921
  49. package/mistral/dist/index.js.map +0 -1
  50. package/mistral/dist/index.mjs +0 -885
  51. package/mistral/dist/index.mjs.map +0 -1
  52. package/openai/dist/index.d.mts +0 -468
  53. package/openai/dist/index.d.ts +0 -468
  54. package/openai/dist/index.js +0 -1334
  55. package/openai/dist/index.js.map +0 -1
  56. package/openai/dist/index.mjs +0 -1298
  57. package/openai/dist/index.mjs.map +0 -1
  58. package/spec/dist/index.d.mts +0 -780
  59. package/spec/dist/index.d.ts +0 -780
  60. package/spec/dist/index.js +0 -863
  61. package/spec/dist/index.js.map +0 -1
  62. package/spec/dist/index.mjs +0 -797
  63. package/spec/dist/index.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,349 +1,8 @@
1
- // spec/errors/api-call-error.ts
2
- var APICallError = class extends Error {
3
- constructor({
4
- message,
5
- url,
6
- requestBodyValues,
7
- statusCode,
8
- responseBody,
9
- cause,
10
- isRetryable = statusCode != null && (statusCode === 408 || // request timeout
11
- statusCode === 409 || // conflict
12
- statusCode === 429 || // too many requests
13
- statusCode >= 500),
14
- // server error
15
- data
16
- }) {
17
- super(message);
18
- this.name = "AI_APICallError";
19
- this.url = url;
20
- this.requestBodyValues = requestBodyValues;
21
- this.statusCode = statusCode;
22
- this.responseBody = responseBody;
23
- this.cause = cause;
24
- this.isRetryable = isRetryable;
25
- this.data = data;
26
- }
27
- static isAPICallError(error) {
28
- 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");
29
- }
30
- toJSON() {
31
- return {
32
- name: this.name,
33
- message: this.message,
34
- url: this.url,
35
- requestBodyValues: this.requestBodyValues,
36
- statusCode: this.statusCode,
37
- responseBody: this.responseBody,
38
- cause: this.cause,
39
- isRetryable: this.isRetryable,
40
- data: this.data
41
- };
42
- }
43
- };
44
-
45
- // spec/errors/invalid-argument-error.ts
46
- var InvalidArgumentError = class extends Error {
47
- constructor({
48
- parameter,
49
- value,
50
- message
51
- }) {
52
- super(`Invalid argument for parameter ${parameter}: ${message}`);
53
- this.name = "AI_InvalidArgumentError";
54
- this.parameter = parameter;
55
- this.value = value;
56
- }
57
- static isInvalidArgumentError(error) {
58
- return error instanceof Error && error.name === "AI_InvalidArgumentError" && typeof error.parameter === "string" && typeof error.value === "string";
59
- }
60
- toJSON() {
61
- return {
62
- name: this.name,
63
- message: this.message,
64
- stack: this.stack,
65
- parameter: this.parameter,
66
- value: this.value
67
- };
68
- }
69
- };
70
-
71
- // spec/errors/invalid-data-content-error.ts
72
- var InvalidDataContentError = class extends Error {
73
- constructor({
74
- content,
75
- message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
76
- }) {
77
- super(message);
78
- this.name = "AI_InvalidDataContentError";
79
- this.content = content;
80
- }
81
- static isInvalidDataContentError(error) {
82
- return error instanceof Error && error.name === "AI_InvalidDataContentError" && error.content != null;
83
- }
84
- toJSON() {
85
- return {
86
- name: this.name,
87
- message: this.message,
88
- stack: this.stack,
89
- content: this.content
90
- };
91
- }
92
- };
93
-
94
- // spec/errors/invalid-prompt-error.ts
95
- var InvalidPromptError = class extends Error {
96
- constructor({ prompt: prompt2, message }) {
97
- super(`Invalid prompt: ${message}`);
98
- this.name = "AI_InvalidPromptError";
99
- this.prompt = prompt2;
100
- }
101
- static isInvalidPromptError(error) {
102
- return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
103
- }
104
- toJSON() {
105
- return {
106
- name: this.name,
107
- message: this.message,
108
- stack: this.stack,
109
- prompt: this.prompt
110
- };
111
- }
112
- };
113
-
114
- // spec/util/get-error-message.ts
115
- function getErrorMessage(error) {
116
- if (error == null) {
117
- return "unknown error";
118
- }
119
- if (typeof error === "string") {
120
- return error;
121
- }
122
- if (error instanceof Error) {
123
- return error.message;
124
- }
125
- return JSON.stringify(error);
126
- }
127
-
128
- // spec/util/parse-json.ts
129
- import SecureJSON from "secure-json-parse";
130
-
131
- // spec/errors/json-parse-error.ts
132
- var JSONParseError = class extends Error {
133
- constructor({ text, cause }) {
134
- super(
135
- `JSON parsing failed: Text: ${text}.
136
- Error message: ${getErrorMessage(cause)}`
137
- );
138
- this.name = "AI_JSONParseError";
139
- this.cause = cause;
140
- this.text = text;
141
- }
142
- static isJSONParseError(error) {
143
- return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
144
- }
145
- toJSON() {
146
- return {
147
- name: this.name,
148
- message: this.message,
149
- cause: this.cause,
150
- stack: this.stack,
151
- valueText: this.text
152
- };
153
- }
154
- };
155
-
156
- // spec/errors/type-validation-error.ts
157
- var TypeValidationError = class extends Error {
158
- constructor({ value, cause }) {
159
- super(
160
- `Type validation failed: Value: ${JSON.stringify(value)}.
161
- Error message: ${getErrorMessage(cause)}`
162
- );
163
- this.name = "AI_TypeValidationError";
164
- this.cause = cause;
165
- this.value = value;
166
- }
167
- static isTypeValidationError(error) {
168
- return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
169
- }
170
- toJSON() {
171
- return {
172
- name: this.name,
173
- message: this.message,
174
- cause: this.cause,
175
- stack: this.stack,
176
- value: this.value
177
- };
178
- }
179
- };
180
-
181
- // spec/util/validate-types.ts
182
- function safeValidateTypes({
183
- value,
184
- schema
185
- }) {
186
- try {
187
- const validationResult = schema.safeParse(value);
188
- if (validationResult.success) {
189
- return {
190
- success: true,
191
- value: validationResult.data
192
- };
193
- }
194
- return {
195
- success: false,
196
- error: new TypeValidationError({
197
- value,
198
- cause: validationResult.error
199
- })
200
- };
201
- } catch (error) {
202
- return {
203
- success: false,
204
- error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
205
- };
206
- }
207
- }
208
-
209
- // spec/util/parse-json.ts
210
- function safeParseJSON({
211
- text,
212
- schema
213
- }) {
214
- try {
215
- const value = SecureJSON.parse(text);
216
- if (schema == null) {
217
- return {
218
- success: true,
219
- value
220
- };
221
- }
222
- return safeValidateTypes({ value, schema });
223
- } catch (error) {
224
- return {
225
- success: false,
226
- error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
227
- };
228
- }
229
- }
230
-
231
- // spec/util/uint8-utils.ts
232
- function convertBase64ToUint8Array(base64String) {
233
- const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
234
- const latin1string = globalThis.atob(base64Url);
235
- return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
236
- }
237
- function convertUint8ArrayToBase64(array) {
238
- let latin1string = "";
239
- for (let i = 0; i < array.length; i++) {
240
- latin1string += String.fromCodePoint(array[i]);
241
- }
242
- return globalThis.btoa(latin1string);
243
- }
244
-
245
- // spec/errors/invalid-tool-arguments-error.ts
246
- var InvalidToolArgumentsError = class extends Error {
247
- constructor({
248
- toolArgs,
249
- toolName,
250
- cause,
251
- message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
252
- cause
253
- )}`
254
- }) {
255
- super(message);
256
- this.name = "AI_InvalidToolArgumentsError";
257
- this.toolArgs = toolArgs;
258
- this.toolName = toolName;
259
- this.cause = cause;
260
- }
261
- static isInvalidToolArgumentsError(error) {
262
- return error instanceof Error && error.name === "AI_InvalidToolArgumentsError" && typeof error.toolName === "string" && typeof error.toolArgs === "string";
263
- }
264
- toJSON() {
265
- return {
266
- name: this.name,
267
- message: this.message,
268
- cause: this.cause,
269
- stack: this.stack,
270
- toolName: this.toolName,
271
- toolArgs: this.toolArgs
272
- };
273
- }
274
- };
275
-
276
- // spec/errors/no-object-generated-error.ts
277
- var NoTextGeneratedError = class extends Error {
278
- constructor() {
279
- super(`No text generated.`);
280
- this.name = "AI_NoTextGeneratedError";
281
- }
282
- static isNoTextGeneratedError(error) {
283
- return error instanceof Error && error.name === "AI_NoTextGeneratedError";
284
- }
285
- toJSON() {
286
- return {
287
- name: this.name,
288
- cause: this.cause,
289
- message: this.message,
290
- stack: this.stack
291
- };
292
- }
293
- };
294
-
295
- // spec/errors/no-such-tool-error.ts
296
- var NoSuchToolError = class extends Error {
297
- constructor({
298
- toolName,
299
- availableTools = void 0,
300
- message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
301
- }) {
302
- super(message);
303
- this.name = "AI_NoSuchToolError";
304
- this.toolName = toolName;
305
- this.availableTools = availableTools;
306
- }
307
- static isNoSuchToolError(error) {
308
- return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
309
- }
310
- toJSON() {
311
- return {
312
- name: this.name,
313
- message: this.message,
314
- stack: this.stack,
315
- toolName: this.toolName,
316
- availableTools: this.availableTools
317
- };
318
- }
319
- };
320
-
321
- // spec/errors/retry-error.ts
322
- var RetryError = class extends Error {
323
- constructor({
324
- message,
325
- reason,
326
- errors
327
- }) {
328
- super(message);
329
- this.name = "AI_RetryError";
330
- this.reason = reason;
331
- this.errors = errors;
332
- this.lastError = errors[errors.length - 1];
333
- }
334
- static isRetryError(error) {
335
- return error instanceof Error && error.name === "AI_RetryError" && typeof error.reason === "string" && Array.isArray(error.errors);
336
- }
337
- toJSON() {
338
- return {
339
- name: this.name,
340
- message: this.message,
341
- reason: this.reason,
342
- lastError: this.lastError,
343
- errors: this.errors
344
- };
345
- }
346
- };
1
+ // core/generate-object/generate-object.ts
2
+ import {
3
+ NoTextGeneratedError
4
+ } from "@ai-sdk/provider";
5
+ import { safeParseJSON } from "@ai-sdk/provider-utils";
347
6
 
348
7
  // core/generate-text/token-usage.ts
349
8
  function calculateTokenUsage(usage) {
@@ -371,6 +30,11 @@ function detectImageMimeType(image) {
371
30
  }
372
31
 
373
32
  // core/prompt/data-content.ts
33
+ import { InvalidDataContentError } from "@ai-sdk/provider";
34
+ import {
35
+ convertBase64ToUint8Array,
36
+ convertUint8ArrayToBase64
37
+ } from "@ai-sdk/provider-utils";
374
38
  function convertDataContentToBase64String(content) {
375
39
  if (typeof content === "string") {
376
40
  return content;
@@ -394,22 +58,22 @@ function convertDataContentToUint8Array(content) {
394
58
  }
395
59
 
396
60
  // core/prompt/convert-to-language-model-prompt.ts
397
- function convertToLanguageModelPrompt(prompt2) {
61
+ function convertToLanguageModelPrompt(prompt) {
398
62
  const languageModelMessages = [];
399
- if (prompt2.system != null) {
400
- languageModelMessages.push({ role: "system", content: prompt2.system });
63
+ if (prompt.system != null) {
64
+ languageModelMessages.push({ role: "system", content: prompt.system });
401
65
  }
402
- switch (prompt2.type) {
66
+ switch (prompt.type) {
403
67
  case "prompt": {
404
68
  languageModelMessages.push({
405
69
  role: "user",
406
- content: [{ type: "text", text: prompt2.prompt }]
70
+ content: [{ type: "text", text: prompt.prompt }]
407
71
  });
408
72
  break;
409
73
  }
410
74
  case "messages": {
411
75
  languageModelMessages.push(
412
- ...prompt2.messages.map((message) => {
76
+ ...prompt.messages.map((message) => {
413
77
  switch (message.role) {
414
78
  case "user": {
415
79
  if (typeof message.content === "string") {
@@ -467,7 +131,7 @@ function convertToLanguageModelPrompt(prompt2) {
467
131
  break;
468
132
  }
469
133
  default: {
470
- const _exhaustiveCheck = prompt2;
134
+ const _exhaustiveCheck = prompt;
471
135
  throw new Error(`Unsupported prompt type: ${_exhaustiveCheck}`);
472
136
  }
473
137
  }
@@ -475,34 +139,36 @@ function convertToLanguageModelPrompt(prompt2) {
475
139
  }
476
140
 
477
141
  // core/prompt/get-validated-prompt.ts
478
- function getValidatedPrompt(prompt2) {
479
- if (prompt2.prompt == null && prompt2.messages == null) {
142
+ import { InvalidPromptError } from "@ai-sdk/provider";
143
+ function getValidatedPrompt(prompt) {
144
+ if (prompt.prompt == null && prompt.messages == null) {
480
145
  throw new InvalidPromptError({
481
- prompt: prompt2,
146
+ prompt,
482
147
  message: "prompt or messages must be defined"
483
148
  });
484
149
  }
485
- if (prompt2.prompt != null && prompt2.messages != null) {
150
+ if (prompt.prompt != null && prompt.messages != null) {
486
151
  throw new InvalidPromptError({
487
- prompt: prompt2,
152
+ prompt,
488
153
  message: "prompt and messages cannot be defined at the same time"
489
154
  });
490
155
  }
491
- return prompt2.prompt != null ? {
156
+ return prompt.prompt != null ? {
492
157
  type: "prompt",
493
- prompt: prompt2.prompt,
158
+ prompt: prompt.prompt,
494
159
  messages: void 0,
495
- system: prompt2.system
160
+ system: prompt.system
496
161
  } : {
497
162
  type: "messages",
498
163
  prompt: void 0,
499
- messages: prompt2.messages,
164
+ messages: prompt.messages,
500
165
  // only possible case bc of checks above
501
- system: prompt2.system
166
+ system: prompt.system
502
167
  };
503
168
  }
504
169
 
505
170
  // core/prompt/prepare-call-settings.ts
171
+ import { InvalidArgumentError } from "@ai-sdk/provider";
506
172
  function prepareCallSettings({
507
173
  maxTokens,
508
174
  temperature,
@@ -634,6 +300,10 @@ function convertZodToJSONSchema(zodSchema) {
634
300
  return zodToJsonSchema(zodSchema);
635
301
  }
636
302
 
303
+ // core/util/retry-with-exponential-backoff.ts
304
+ import { APICallError, RetryError } from "@ai-sdk/provider";
305
+ import { getErrorMessage } from "@ai-sdk/provider-utils";
306
+
637
307
  // core/util/delay.ts
638
308
  async function delay(delayInMs) {
639
309
  return new Promise((resolve) => setTimeout(resolve, delayInMs));
@@ -668,7 +338,7 @@ async function _retryWithExponentialBackoff(f, {
668
338
  const tryNumber = newErrors.length;
669
339
  if (tryNumber > maxRetries) {
670
340
  throw new RetryError({
671
- message: `Failed after ${tryNumber} attemps. Last error: ${errorMessage}`,
341
+ message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
672
342
  reason: "maxRetriesExceeded",
673
343
  errors: newErrors
674
344
  });
@@ -685,7 +355,7 @@ async function _retryWithExponentialBackoff(f, {
685
355
  throw error;
686
356
  }
687
357
  throw new RetryError({
688
- message: `Failed after ${tryNumber} attemps with non-retryable error: '${errorMessage}'`,
358
+ message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
689
359
  reason: "errorNotRetryable",
690
360
  errors: newErrors
691
361
  });
@@ -717,7 +387,7 @@ async function experimental_generateObject({
717
387
  schema,
718
388
  mode,
719
389
  system,
720
- prompt: prompt2,
390
+ prompt,
721
391
  messages,
722
392
  maxRetries,
723
393
  abortSignal,
@@ -737,7 +407,7 @@ async function experimental_generateObject({
737
407
  case "json": {
738
408
  const validatedPrompt = getValidatedPrompt({
739
409
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
740
- prompt: prompt2,
410
+ prompt,
741
411
  messages
742
412
  });
743
413
  const generateResult = await retry(() => {
@@ -761,7 +431,7 @@ async function experimental_generateObject({
761
431
  case "grammar": {
762
432
  const validatedPrompt = getValidatedPrompt({
763
433
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
764
- prompt: prompt2,
434
+ prompt,
765
435
  messages
766
436
  });
767
437
  const generateResult = await retry(
@@ -785,7 +455,7 @@ async function experimental_generateObject({
785
455
  case "tool": {
786
456
  const validatedPrompt = getValidatedPrompt({
787
457
  system,
788
- prompt: prompt2,
458
+ prompt,
789
459
  messages
790
460
  });
791
461
  const generateResult = await retry(
@@ -896,7 +566,7 @@ function isDeepEqualData(obj1, obj2) {
896
566
  }
897
567
 
898
568
  // core/util/parse-partial-json.ts
899
- import SecureJSON2 from "secure-json-parse";
569
+ import SecureJSON from "secure-json-parse";
900
570
 
901
571
  // core/util/fix-json.ts
902
572
  function fixJson(input) {
@@ -1221,11 +891,11 @@ function parsePartialJson(jsonText) {
1221
891
  return void 0;
1222
892
  }
1223
893
  try {
1224
- return SecureJSON2.parse(jsonText);
894
+ return SecureJSON.parse(jsonText);
1225
895
  } catch (ignored) {
1226
896
  try {
1227
897
  const fixedJsonText = fixJson(jsonText);
1228
- return SecureJSON2.parse(fixedJsonText);
898
+ return SecureJSON.parse(fixedJsonText);
1229
899
  } catch (ignored2) {
1230
900
  }
1231
901
  }
@@ -1238,7 +908,7 @@ async function experimental_streamObject({
1238
908
  schema,
1239
909
  mode,
1240
910
  system,
1241
- prompt: prompt2,
911
+ prompt,
1242
912
  messages,
1243
913
  maxRetries,
1244
914
  abortSignal,
@@ -1255,7 +925,7 @@ async function experimental_streamObject({
1255
925
  case "json": {
1256
926
  const validatedPrompt = getValidatedPrompt({
1257
927
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
1258
- prompt: prompt2,
928
+ prompt,
1259
929
  messages
1260
930
  });
1261
931
  callOptions = {
@@ -1282,7 +952,7 @@ async function experimental_streamObject({
1282
952
  case "grammar": {
1283
953
  const validatedPrompt = getValidatedPrompt({
1284
954
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
1285
- prompt: prompt2,
955
+ prompt,
1286
956
  messages
1287
957
  });
1288
958
  callOptions = {
@@ -1309,7 +979,7 @@ async function experimental_streamObject({
1309
979
  case "tool": {
1310
980
  const validatedPrompt = getValidatedPrompt({
1311
981
  system,
1312
- prompt: prompt2,
982
+ prompt,
1313
983
  messages
1314
984
  });
1315
985
  callOptions = {
@@ -1387,6 +1057,11 @@ var StreamObjectResult = class {
1387
1057
  };
1388
1058
 
1389
1059
  // core/generate-text/tool-call.ts
1060
+ import {
1061
+ InvalidToolArgumentsError,
1062
+ NoSuchToolError
1063
+ } from "@ai-sdk/provider";
1064
+ import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
1390
1065
  function parseToolCall({
1391
1066
  toolCall,
1392
1067
  tools
@@ -1402,7 +1077,7 @@ function parseToolCall({
1402
1077
  availableTools: Object.keys(tools)
1403
1078
  });
1404
1079
  }
1405
- const parseResult = safeParseJSON({
1080
+ const parseResult = safeParseJSON2({
1406
1081
  text: toolCall.args,
1407
1082
  schema: tool2.parameters
1408
1083
  });
@@ -1426,7 +1101,7 @@ async function experimental_generateText({
1426
1101
  model,
1427
1102
  tools,
1428
1103
  system,
1429
- prompt: prompt2,
1104
+ prompt,
1430
1105
  messages,
1431
1106
  maxRetries,
1432
1107
  abortSignal,
@@ -1434,7 +1109,7 @@ async function experimental_generateText({
1434
1109
  }) {
1435
1110
  var _a, _b;
1436
1111
  const retry = retryWithExponentialBackoff({ maxRetries });
1437
- const validatedPrompt = getValidatedPrompt({ system, prompt: prompt2, messages });
1112
+ const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
1438
1113
  const modelResponse = await retry(() => {
1439
1114
  return model.doGenerate({
1440
1115
  mode: {
@@ -1503,6 +1178,9 @@ var GenerateTextResult = class {
1503
1178
  }
1504
1179
  };
1505
1180
 
1181
+ // core/generate-text/run-tools-transformation.ts
1182
+ import { NoSuchToolError as NoSuchToolError2 } from "@ai-sdk/provider";
1183
+
1506
1184
  // shared/generate-id.ts
1507
1185
  import { customAlphabet } from "nanoid/non-secure";
1508
1186
  var generateId = customAlphabet(
@@ -1537,7 +1215,7 @@ function runToolsTransformation({
1537
1215
  if (tools == null) {
1538
1216
  toolResultsStreamController.enqueue({
1539
1217
  type: "error",
1540
- error: new NoSuchToolError({ toolName: chunk.toolName })
1218
+ error: new NoSuchToolError2({ toolName: chunk.toolName })
1541
1219
  });
1542
1220
  break;
1543
1221
  }
@@ -1545,7 +1223,7 @@ function runToolsTransformation({
1545
1223
  if (tool2 == null) {
1546
1224
  toolResultsStreamController.enqueue({
1547
1225
  type: "error",
1548
- error: new NoSuchToolError({
1226
+ error: new NoSuchToolError2({
1549
1227
  toolName: chunk.toolName,
1550
1228
  availableTools: Object.keys(tools)
1551
1229
  })
@@ -1651,14 +1329,14 @@ async function experimental_streamText({
1651
1329
  model,
1652
1330
  tools,
1653
1331
  system,
1654
- prompt: prompt2,
1332
+ prompt,
1655
1333
  messages,
1656
1334
  maxRetries,
1657
1335
  abortSignal,
1658
1336
  ...settings
1659
1337
  }) {
1660
1338
  const retry = retryWithExponentialBackoff({ maxRetries });
1661
- const validatedPrompt = getValidatedPrompt({ system, prompt: prompt2, messages });
1339
+ const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
1662
1340
  const { stream, warnings } = await retry(
1663
1341
  () => model.doStream({
1664
1342
  mode: {
@@ -1739,7 +1417,32 @@ var StreamTextResult = class {
1739
1417
  @returns an `AIStream` object.
1740
1418
  */
1741
1419
  toAIStream(callbacks) {
1742
- return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
1420
+ return this.textStream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
1421
+ }
1422
+ /**
1423
+ Creates a simple text stream response.
1424
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
1425
+ Non-text-delta events are ignored.
1426
+ */
1427
+ toTextStreamResponse(init) {
1428
+ const encoder = new TextEncoder();
1429
+ return new Response(
1430
+ this.textStream.pipeThrough(
1431
+ new TransformStream({
1432
+ transform(chunk, controller) {
1433
+ controller.enqueue(encoder.encode(chunk));
1434
+ }
1435
+ })
1436
+ ),
1437
+ {
1438
+ ...init,
1439
+ status: 200,
1440
+ headers: {
1441
+ "Content-Type": "text/plain; charset=utf-8",
1442
+ ...init == null ? void 0 : init.headers
1443
+ }
1444
+ }
1445
+ );
1743
1446
  }
1744
1447
  };
1745
1448
 
@@ -1848,9 +1551,9 @@ var toolCallStreamPart = {
1848
1551
  code: "7",
1849
1552
  name: "tool_calls",
1850
1553
  parse: (value) => {
1851
- if (value == null || typeof value !== "object" || !("tool_calls" in value) || typeof value.tool_calls !== "object" || value.tool_calls == null || !Array.isArray(value.tool_calls) || value.tool_calls.some((tc) => {
1852
- tc == null || typeof tc !== "object" || !("id" in tc) || typeof tc.id !== "string" || !("type" in tc) || typeof tc.type !== "string" || !("function" in tc) || tc.function == null || typeof tc.function !== "object" || !("arguments" in tc.function) || typeof tc.function.name !== "string" || typeof tc.function.arguments !== "string";
1853
- })) {
1554
+ if (value == null || typeof value !== "object" || !("tool_calls" in value) || typeof value.tool_calls !== "object" || value.tool_calls == null || !Array.isArray(value.tool_calls) || value.tool_calls.some(
1555
+ (tc) => tc == null || typeof tc !== "object" || !("id" in tc) || typeof tc.id !== "string" || !("type" in tc) || typeof tc.type !== "string" || !("function" in tc) || tc.function == null || typeof tc.function !== "object" || !("arguments" in tc.function) || typeof tc.function.name !== "string" || typeof tc.function.arguments !== "string"
1556
+ )) {
1854
1557
  throw new Error(
1855
1558
  '"tool_calls" parts expect an object with a ToolCallPayload.'
1856
1559
  );
@@ -1928,6 +1631,49 @@ function formatStreamPart(type, value) {
1928
1631
  `;
1929
1632
  }
1930
1633
 
1634
+ // shared/read-data-stream.ts
1635
+ var NEWLINE = "\n".charCodeAt(0);
1636
+ function concatChunks(chunks, totalLength) {
1637
+ const concatenatedChunks = new Uint8Array(totalLength);
1638
+ let offset = 0;
1639
+ for (const chunk of chunks) {
1640
+ concatenatedChunks.set(chunk, offset);
1641
+ offset += chunk.length;
1642
+ }
1643
+ chunks.length = 0;
1644
+ return concatenatedChunks;
1645
+ }
1646
+ async function* readDataStream(reader, {
1647
+ isAborted
1648
+ } = {}) {
1649
+ const decoder = new TextDecoder();
1650
+ const chunks = [];
1651
+ let totalLength = 0;
1652
+ while (true) {
1653
+ const { value } = await reader.read();
1654
+ if (value) {
1655
+ chunks.push(value);
1656
+ totalLength += value.length;
1657
+ if (value[value.length - 1] !== NEWLINE) {
1658
+ continue;
1659
+ }
1660
+ }
1661
+ if (chunks.length === 0) {
1662
+ break;
1663
+ }
1664
+ const concatenatedChunks = concatChunks(chunks, totalLength);
1665
+ totalLength = 0;
1666
+ const streamParts2 = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseStreamPart);
1667
+ for (const streamPart of streamParts2) {
1668
+ yield streamPart;
1669
+ }
1670
+ if (isAborted == null ? void 0 : isAborted()) {
1671
+ reader.cancel();
1672
+ break;
1673
+ }
1674
+ }
1675
+ }
1676
+
1931
1677
  // shared/utils.ts
1932
1678
  function createChunkDecoder(complex) {
1933
1679
  const decoder = new TextDecoder();
@@ -2903,49 +2649,6 @@ async function ReplicateStream(res, cb, options) {
2903
2649
  );
2904
2650
  }
2905
2651
 
2906
- // shared/read-data-stream.ts
2907
- var NEWLINE = "\n".charCodeAt(0);
2908
- function concatChunks(chunks, totalLength) {
2909
- const concatenatedChunks = new Uint8Array(totalLength);
2910
- let offset = 0;
2911
- for (const chunk of chunks) {
2912
- concatenatedChunks.set(chunk, offset);
2913
- offset += chunk.length;
2914
- }
2915
- chunks.length = 0;
2916
- return concatenatedChunks;
2917
- }
2918
- async function* readDataStream(reader, {
2919
- isAborted
2920
- } = {}) {
2921
- const decoder = new TextDecoder();
2922
- const chunks = [];
2923
- let totalLength = 0;
2924
- while (true) {
2925
- const { value } = await reader.read();
2926
- if (value) {
2927
- chunks.push(value);
2928
- totalLength += value.length;
2929
- if (value[value.length - 1] !== NEWLINE) {
2930
- continue;
2931
- }
2932
- }
2933
- if (chunks.length === 0) {
2934
- break;
2935
- }
2936
- const concatenatedChunks = concatChunks(chunks, totalLength);
2937
- totalLength = 0;
2938
- const streamParts2 = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseStreamPart);
2939
- for (const streamPart of streamParts2) {
2940
- yield streamPart;
2941
- }
2942
- if (isAborted == null ? void 0 : isAborted()) {
2943
- reader.cancel();
2944
- break;
2945
- }
2946
- }
2947
- }
2948
-
2949
2652
  // shared/parse-complex-response.ts
2950
2653
  function assignAnnotationsToMessage(message, annotations) {
2951
2654
  if (!message || !annotations || !annotations.length)
@@ -3170,9 +2873,12 @@ export {
3170
2873
  experimental_generateText,
3171
2874
  experimental_streamObject,
3172
2875
  experimental_streamText,
2876
+ formatStreamPart,
3173
2877
  generateId,
3174
2878
  isStreamStringEqualToType,
3175
2879
  generateId as nanoid,
2880
+ parseStreamPart,
2881
+ readDataStream,
3176
2882
  readableFromAsyncIterable,
3177
2883
  streamToResponse,
3178
2884
  tool,