ai 5.0.0-canary.16 → 5.0.0-canary.18

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.
@@ -3,228 +3,36 @@ import { InvalidPromptError } from "@ai-sdk/provider";
3
3
  import { safeValidateTypes } from "@ai-sdk/provider-utils";
4
4
  import { z as z7 } from "zod";
5
5
 
6
- // core/prompt/data-content.ts
7
- import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
8
- import {
9
- convertBase64ToUint8Array,
10
- convertUint8ArrayToBase64
11
- } from "@ai-sdk/provider-utils";
12
- import { z } from "zod";
13
-
14
- // core/prompt/invalid-data-content-error.ts
6
+ // core/prompt/message-conversion-error.ts
15
7
  import { AISDKError } from "@ai-sdk/provider";
16
- var name = "AI_InvalidDataContentError";
8
+ var name = "AI_MessageConversionError";
17
9
  var marker = `vercel.ai.error.${name}`;
18
10
  var symbol = Symbol.for(marker);
19
11
  var _a;
20
- var InvalidDataContentError = class extends AISDKError {
21
- constructor({
22
- content,
23
- cause,
24
- message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
25
- }) {
26
- super({ name, message, cause });
27
- this[_a] = true;
28
- this.content = content;
29
- }
30
- static isInstance(error) {
31
- return AISDKError.hasMarker(error, marker);
32
- }
33
- };
34
- _a = symbol;
35
-
36
- // core/prompt/split-data-url.ts
37
- function splitDataUrl(dataUrl) {
38
- try {
39
- const [header, base64Content] = dataUrl.split(",");
40
- return {
41
- mediaType: header.split(";")[0].split(":")[1],
42
- base64Content
43
- };
44
- } catch (error) {
45
- return {
46
- mediaType: void 0,
47
- base64Content: void 0
48
- };
49
- }
50
- }
51
-
52
- // core/prompt/data-content.ts
53
- var dataContentSchema = z.union([
54
- z.string(),
55
- z.instanceof(Uint8Array),
56
- z.instanceof(ArrayBuffer),
57
- z.custom(
58
- // Buffer might not be available in some environments such as CloudFlare:
59
- (value) => {
60
- var _a7, _b;
61
- return (_b = (_a7 = globalThis.Buffer) == null ? void 0 : _a7.isBuffer(value)) != null ? _b : false;
62
- },
63
- { message: "Must be a Buffer" }
64
- )
65
- ]);
66
- function convertToLanguageModelV2DataContent(content) {
67
- if (content instanceof Uint8Array) {
68
- return { data: content, mediaType: void 0 };
69
- }
70
- if (content instanceof ArrayBuffer) {
71
- return { data: new Uint8Array(content), mediaType: void 0 };
72
- }
73
- if (typeof content === "string") {
74
- try {
75
- content = new URL(content);
76
- } catch (error) {
77
- }
78
- }
79
- if (content instanceof URL && content.protocol === "data:") {
80
- const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
81
- content.toString()
82
- );
83
- if (dataUrlMediaType == null || base64Content == null) {
84
- throw new AISDKError2({
85
- name: "InvalidDataContentError",
86
- message: `Invalid data URL format in content ${content.toString()}`
87
- });
88
- }
89
- return { data: base64Content, mediaType: dataUrlMediaType };
90
- }
91
- return { data: content, mediaType: void 0 };
92
- }
93
- function convertDataContentToUint8Array(content) {
94
- if (content instanceof Uint8Array) {
95
- return content;
96
- }
97
- if (typeof content === "string") {
98
- try {
99
- return convertBase64ToUint8Array(content);
100
- } catch (error) {
101
- throw new InvalidDataContentError({
102
- message: "Invalid data content. Content string is not a base64-encoded media.",
103
- content,
104
- cause: error
105
- });
106
- }
107
- }
108
- if (content instanceof ArrayBuffer) {
109
- return new Uint8Array(content);
110
- }
111
- throw new InvalidDataContentError({ content });
112
- }
113
- function convertUint8ArrayToText(uint8Array) {
114
- try {
115
- return new TextDecoder().decode(uint8Array);
116
- } catch (error) {
117
- throw new Error("Error decoding Uint8Array to text");
118
- }
119
- }
120
-
121
- // core/prompt/attachments-to-parts.ts
122
- function attachmentsToParts(attachments) {
123
- var _a7, _b, _c;
124
- const parts = [];
125
- for (const attachment of attachments) {
126
- let url;
127
- try {
128
- url = new URL(attachment.url);
129
- } catch (error) {
130
- throw new Error(`Invalid URL: ${attachment.url}`);
131
- }
132
- switch (url.protocol) {
133
- case "http:":
134
- case "https:": {
135
- if ((_a7 = attachment.contentType) == null ? void 0 : _a7.startsWith("image/")) {
136
- parts.push({ type: "image", image: url });
137
- } else {
138
- if (!attachment.contentType) {
139
- throw new Error(
140
- "If the attachment is not an image, it must specify a content type"
141
- );
142
- }
143
- parts.push({
144
- type: "file",
145
- data: url,
146
- mediaType: attachment.contentType
147
- });
148
- }
149
- break;
150
- }
151
- case "data:": {
152
- let header;
153
- let base64Content;
154
- let mediaType;
155
- try {
156
- [header, base64Content] = attachment.url.split(",");
157
- mediaType = header.split(";")[0].split(":")[1];
158
- } catch (error) {
159
- throw new Error(`Error processing data URL: ${attachment.url}`);
160
- }
161
- if (mediaType == null || base64Content == null) {
162
- throw new Error(`Invalid data URL format: ${attachment.url}`);
163
- }
164
- if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
165
- parts.push({
166
- type: "image",
167
- image: convertDataContentToUint8Array(base64Content)
168
- });
169
- } else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
170
- parts.push({
171
- type: "text",
172
- text: convertUint8ArrayToText(
173
- convertDataContentToUint8Array(base64Content)
174
- )
175
- });
176
- } else {
177
- if (!attachment.contentType) {
178
- throw new Error(
179
- "If the attachment is not an image or text, it must specify a content type"
180
- );
181
- }
182
- parts.push({
183
- type: "file",
184
- data: base64Content,
185
- mediaType: attachment.contentType
186
- });
187
- }
188
- break;
189
- }
190
- default: {
191
- throw new Error(`Unsupported URL protocol: ${url.protocol}`);
192
- }
193
- }
194
- }
195
- return parts;
196
- }
197
-
198
- // core/prompt/message-conversion-error.ts
199
- import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
200
- var name2 = "AI_MessageConversionError";
201
- var marker2 = `vercel.ai.error.${name2}`;
202
- var symbol2 = Symbol.for(marker2);
203
- var _a2;
204
- var MessageConversionError = class extends AISDKError3 {
12
+ var MessageConversionError = class extends AISDKError {
205
13
  constructor({
206
14
  originalMessage,
207
15
  message
208
16
  }) {
209
- super({ name: name2, message });
210
- this[_a2] = true;
17
+ super({ name, message });
18
+ this[_a] = true;
211
19
  this.originalMessage = originalMessage;
212
20
  }
213
21
  static isInstance(error) {
214
- return AISDKError3.hasMarker(error, marker2);
22
+ return AISDKError.hasMarker(error, marker);
215
23
  }
216
24
  };
217
- _a2 = symbol2;
25
+ _a = symbol;
218
26
 
219
- // core/prompt/convert-to-core-messages.ts
220
- function convertToCoreMessages(messages, options) {
221
- var _a7, _b;
222
- const tools = (_a7 = options == null ? void 0 : options.tools) != null ? _a7 : {};
27
+ // core/prompt/convert-to-model-messages.ts
28
+ function convertToModelMessages(messages, options) {
29
+ var _a6, _b;
30
+ const tools = (_a6 = options == null ? void 0 : options.tools) != null ? _a6 : {};
223
31
  const coreMessages = [];
224
32
  for (let i = 0; i < messages.length; i++) {
225
33
  const message = messages[i];
226
34
  const isLastMessage = i === messages.length - 1;
227
- const { role, content, experimental_attachments } = message;
35
+ const { role, content } = message;
228
36
  switch (role) {
229
37
  case "system": {
230
38
  coreMessages.push({
@@ -234,30 +42,24 @@ function convertToCoreMessages(messages, options) {
234
42
  break;
235
43
  }
236
44
  case "user": {
237
- if (message.parts == null) {
238
- coreMessages.push({
239
- role: "user",
240
- content: experimental_attachments ? [
241
- { type: "text", text: content },
242
- ...attachmentsToParts(experimental_attachments)
243
- ] : content
244
- });
245
- } else {
246
- const textParts = message.parts.filter((part) => part.type === "text").map((part) => ({
247
- type: "text",
248
- text: part.text
249
- }));
250
- coreMessages.push({
251
- role: "user",
252
- content: experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts
253
- });
254
- }
45
+ coreMessages.push({
46
+ role: "user",
47
+ content: message.parts.filter(
48
+ (part) => part.type === "text" || part.type === "file"
49
+ ).map(
50
+ (part) => part.type === "file" ? {
51
+ type: "file",
52
+ mediaType: part.mediaType,
53
+ filename: part.filename,
54
+ data: part.url
55
+ } : part
56
+ )
57
+ });
255
58
  break;
256
59
  }
257
60
  case "assistant": {
258
61
  if (message.parts != null) {
259
62
  let processBlock2 = function() {
260
- var _a8;
261
63
  const content2 = [];
262
64
  for (const part of block) {
263
65
  switch (part.type) {
@@ -268,9 +70,8 @@ function convertToCoreMessages(messages, options) {
268
70
  case "file": {
269
71
  content2.push({
270
72
  type: "file",
271
- data: part.data,
272
- mediaType: (_a8 = part.mediaType) != null ? _a8 : part.mimeType
273
- // TODO migration, remove
73
+ mediaType: part.mediaType,
74
+ data: part.url
274
75
  });
275
76
  break;
276
77
  }
@@ -424,30 +225,96 @@ function detectSingleMessageCharacteristics(message) {
424
225
  import { z as z6 } from "zod";
425
226
 
426
227
  // core/types/provider-metadata.ts
427
- import { z as z3 } from "zod";
228
+ import { z as z2 } from "zod";
428
229
 
429
230
  // core/types/json-value.ts
430
- import { z as z2 } from "zod";
431
- var jsonValueSchema = z2.lazy(
432
- () => z2.union([
433
- z2.null(),
434
- z2.string(),
435
- z2.number(),
436
- z2.boolean(),
437
- z2.record(z2.string(), jsonValueSchema),
438
- z2.array(jsonValueSchema)
231
+ import { z } from "zod";
232
+ var jsonValueSchema = z.lazy(
233
+ () => z.union([
234
+ z.null(),
235
+ z.string(),
236
+ z.number(),
237
+ z.boolean(),
238
+ z.record(z.string(), jsonValueSchema),
239
+ z.array(jsonValueSchema)
439
240
  ])
440
241
  );
441
242
 
442
243
  // core/types/provider-metadata.ts
443
- var providerMetadataSchema = z3.record(
444
- z3.string(),
445
- z3.record(z3.string(), jsonValueSchema)
244
+ var providerMetadataSchema = z2.record(
245
+ z2.string(),
246
+ z2.record(z2.string(), jsonValueSchema)
446
247
  );
447
248
 
448
249
  // core/prompt/content-part.ts
449
250
  import { z as z5 } from "zod";
450
251
 
252
+ // core/prompt/data-content.ts
253
+ import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
254
+ import {
255
+ convertBase64ToUint8Array,
256
+ convertUint8ArrayToBase64
257
+ } from "@ai-sdk/provider-utils";
258
+ import { z as z3 } from "zod";
259
+
260
+ // core/prompt/split-data-url.ts
261
+ function splitDataUrl(dataUrl) {
262
+ try {
263
+ const [header, base64Content] = dataUrl.split(",");
264
+ return {
265
+ mediaType: header.split(";")[0].split(":")[1],
266
+ base64Content
267
+ };
268
+ } catch (error) {
269
+ return {
270
+ mediaType: void 0,
271
+ base64Content: void 0
272
+ };
273
+ }
274
+ }
275
+
276
+ // core/prompt/data-content.ts
277
+ var dataContentSchema = z3.union([
278
+ z3.string(),
279
+ z3.instanceof(Uint8Array),
280
+ z3.instanceof(ArrayBuffer),
281
+ z3.custom(
282
+ // Buffer might not be available in some environments such as CloudFlare:
283
+ (value) => {
284
+ var _a6, _b;
285
+ return (_b = (_a6 = globalThis.Buffer) == null ? void 0 : _a6.isBuffer(value)) != null ? _b : false;
286
+ },
287
+ { message: "Must be a Buffer" }
288
+ )
289
+ ]);
290
+ function convertToLanguageModelV2DataContent(content) {
291
+ if (content instanceof Uint8Array) {
292
+ return { data: content, mediaType: void 0 };
293
+ }
294
+ if (content instanceof ArrayBuffer) {
295
+ return { data: new Uint8Array(content), mediaType: void 0 };
296
+ }
297
+ if (typeof content === "string") {
298
+ try {
299
+ content = new URL(content);
300
+ } catch (error) {
301
+ }
302
+ }
303
+ if (content instanceof URL && content.protocol === "data:") {
304
+ const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
305
+ content.toString()
306
+ );
307
+ if (dataUrlMediaType == null || base64Content == null) {
308
+ throw new AISDKError2({
309
+ name: "InvalidDataContentError",
310
+ message: `Invalid data URL format in content ${content.toString()}`
311
+ });
312
+ }
313
+ return { data: base64Content, mediaType: dataUrlMediaType };
314
+ }
315
+ return { data: content, mediaType: void 0 };
316
+ }
317
+
451
318
  // core/prompt/tool-result-content.ts
452
319
  import { z as z4 } from "zod";
453
320
  var toolResultContentSchema = z4.array(
@@ -471,7 +338,6 @@ var imagePartSchema = z5.object({
471
338
  type: z5.literal("image"),
472
339
  image: z5.union([dataContentSchema, z5.instanceof(URL)]),
473
340
  mediaType: z5.string().optional(),
474
- mimeType: z5.string().optional(),
475
341
  providerOptions: providerMetadataSchema.optional()
476
342
  });
477
343
  var filePartSchema = z5.object({
@@ -479,7 +345,6 @@ var filePartSchema = z5.object({
479
345
  data: z5.union([dataContentSchema, z5.instanceof(URL)]),
480
346
  filename: z5.string().optional(),
481
347
  mediaType: z5.string(),
482
- mimeType: z5.string().optional(),
483
348
  providerOptions: providerMetadataSchema.optional()
484
349
  });
485
350
  var reasoningPartSchema = z5.object({
@@ -505,12 +370,14 @@ var toolResultPartSchema = z5.object({
505
370
  });
506
371
 
507
372
  // core/prompt/message.ts
508
- var coreSystemMessageSchema = z6.object({
509
- role: z6.literal("system"),
510
- content: z6.string(),
511
- providerOptions: providerMetadataSchema.optional()
512
- });
513
- var coreUserMessageSchema = z6.object({
373
+ var systemModelMessageSchema = z6.object(
374
+ {
375
+ role: z6.literal("system"),
376
+ content: z6.string(),
377
+ providerOptions: providerMetadataSchema.optional()
378
+ }
379
+ );
380
+ var userModelMessageSchema = z6.object({
514
381
  role: z6.literal("user"),
515
382
  content: z6.union([
516
383
  z6.string(),
@@ -518,7 +385,7 @@ var coreUserMessageSchema = z6.object({
518
385
  ]),
519
386
  providerOptions: providerMetadataSchema.optional()
520
387
  });
521
- var coreAssistantMessageSchema = z6.object({
388
+ var assistantModelMessageSchema = z6.object({
522
389
  role: z6.literal("assistant"),
523
390
  content: z6.union([
524
391
  z6.string(),
@@ -533,16 +400,16 @@ var coreAssistantMessageSchema = z6.object({
533
400
  ]),
534
401
  providerOptions: providerMetadataSchema.optional()
535
402
  });
536
- var coreToolMessageSchema = z6.object({
403
+ var toolModelMessageSchema = z6.object({
537
404
  role: z6.literal("tool"),
538
405
  content: z6.array(toolResultPartSchema),
539
406
  providerOptions: providerMetadataSchema.optional()
540
407
  });
541
- var coreMessageSchema = z6.union([
542
- coreSystemMessageSchema,
543
- coreUserMessageSchema,
544
- coreAssistantMessageSchema,
545
- coreToolMessageSchema
408
+ var modelMessageSchema = z6.union([
409
+ systemModelMessageSchema,
410
+ userModelMessageSchema,
411
+ assistantModelMessageSchema,
412
+ toolModelMessageSchema
546
413
  ]);
547
414
 
548
415
  // core/prompt/standardize-prompt.ts
@@ -590,10 +457,10 @@ async function standardizePrompt({
590
457
  if (promptType === "other") {
591
458
  throw new InvalidPromptError({
592
459
  prompt,
593
- message: "messages must be an array of CoreMessage or UIMessage"
460
+ message: "messages must be an array of ModelMessage or UIMessage"
594
461
  });
595
462
  }
596
- const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
463
+ const messages = promptType === "ui-messages" ? convertToModelMessages(prompt.messages, {
597
464
  tools
598
465
  }) : prompt.messages;
599
466
  if (messages.length === 0) {
@@ -604,12 +471,12 @@ async function standardizePrompt({
604
471
  }
605
472
  const validationResult = await safeValidateTypes({
606
473
  value: messages,
607
- schema: z7.array(coreMessageSchema)
474
+ schema: z7.array(modelMessageSchema)
608
475
  });
609
476
  if (!validationResult.success) {
610
477
  throw new InvalidPromptError({
611
478
  prompt,
612
- message: "messages must be an array of CoreMessage or UIMessage",
479
+ message: "messages must be an array of ModelMessage or UIMessage",
613
480
  cause: validationResult.error
614
481
  });
615
482
  }
@@ -623,9 +490,9 @@ async function standardizePrompt({
623
490
 
624
491
  // core/util/index.ts
625
492
  import {
493
+ asSchema,
626
494
  generateId,
627
- jsonSchema,
628
- asSchema
495
+ jsonSchema
629
496
  } from "@ai-sdk/provider-utils";
630
497
 
631
498
  // core/util/data-stream-parts.ts
@@ -741,10 +608,13 @@ var finishMessageStreamPart = {
741
608
  const result = {
742
609
  finishReason: value.finishReason
743
610
  };
744
- if ("usage" in value && value.usage != null && typeof value.usage === "object" && "promptTokens" in value.usage && "completionTokens" in value.usage) {
611
+ if ("usage" in value && value.usage != null && typeof value.usage === "object") {
745
612
  result.usage = {
746
- promptTokens: typeof value.usage.promptTokens === "number" ? value.usage.promptTokens : Number.NaN,
747
- completionTokens: typeof value.usage.completionTokens === "number" ? value.usage.completionTokens : Number.NaN
613
+ inputTokens: "inputTokens" in value.usage && typeof value.usage.inputTokens === "number" ? value.usage.inputTokens : void 0,
614
+ outputTokens: "outputTokens" in value.usage && typeof value.usage.outputTokens === "number" ? value.usage.outputTokens : void 0,
615
+ totalTokens: "totalTokens" in value.usage && typeof value.usage.totalTokens === "number" ? value.usage.totalTokens : void 0,
616
+ reasoningTokens: "reasoningTokens" in value.usage && typeof value.usage.reasoningTokens === "number" ? value.usage.reasoningTokens : void 0,
617
+ cachedInputTokens: "cachedInputTokens" in value.usage && typeof value.usage.cachedInputTokens === "number" ? value.usage.cachedInputTokens : void 0
748
618
  };
749
619
  }
750
620
  return {
@@ -766,10 +636,13 @@ var finishStepStreamPart = {
766
636
  finishReason: value.finishReason,
767
637
  isContinued: false
768
638
  };
769
- if ("usage" in value && value.usage != null && typeof value.usage === "object" && "promptTokens" in value.usage && "completionTokens" in value.usage) {
639
+ if ("usage" in value && value.usage != null && typeof value.usage === "object") {
770
640
  result.usage = {
771
- promptTokens: typeof value.usage.promptTokens === "number" ? value.usage.promptTokens : Number.NaN,
772
- completionTokens: typeof value.usage.completionTokens === "number" ? value.usage.completionTokens : Number.NaN
641
+ inputTokens: "inputTokens" in value.usage && typeof value.usage.inputTokens === "number" ? value.usage.inputTokens : void 0,
642
+ outputTokens: "outputTokens" in value.usage && typeof value.usage.outputTokens === "number" ? value.usage.outputTokens : void 0,
643
+ totalTokens: "totalTokens" in value.usage && typeof value.usage.totalTokens === "number" ? value.usage.totalTokens : void 0,
644
+ reasoningTokens: "reasoningTokens" in value.usage && typeof value.usage.reasoningTokens === "number" ? value.usage.reasoningTokens : void 0,
645
+ cachedInputTokens: "cachedInputTokens" in value.usage && typeof value.usage.cachedInputTokens === "number" ? value.usage.cachedInputTokens : void 0
773
646
  };
774
647
  }
775
648
  if ("isContinued" in value && typeof value.isContinued === "boolean") {
@@ -833,9 +706,9 @@ var fileStreamPart = {
833
706
  code: "k",
834
707
  name: "file",
835
708
  parse: (value) => {
836
- if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string" || !("mimeType" in value) || typeof value.mimeType !== "string") {
709
+ if (value == null || typeof value !== "object" || !("url" in value) || typeof value.url !== "string" || !("mediaType" in value) || typeof value.mediaType !== "string") {
837
710
  throw new Error(
838
- '"file" parts expect an object with a "data" and "mimeType" property.'
711
+ '"file" parts expect an object with a "url" and "mediaType" property.'
839
712
  );
840
713
  }
841
714
  return { type: "file", value };
@@ -902,24 +775,24 @@ function prepareToolsAndToolChoice({
902
775
  };
903
776
  }
904
777
  const filteredTools = activeTools != null ? Object.entries(tools).filter(
905
- ([name7]) => activeTools.includes(name7)
778
+ ([name6]) => activeTools.includes(name6)
906
779
  ) : Object.entries(tools);
907
780
  return {
908
- tools: filteredTools.map(([name7, tool]) => {
781
+ tools: filteredTools.map(([name6, tool]) => {
909
782
  const toolType = tool.type;
910
783
  switch (toolType) {
911
784
  case void 0:
912
785
  case "function":
913
786
  return {
914
787
  type: "function",
915
- name: name7,
788
+ name: name6,
916
789
  description: tool.description,
917
790
  parameters: asSchema(tool.parameters).jsonSchema
918
791
  };
919
792
  case "provider-defined":
920
793
  return {
921
794
  type: "provider-defined",
922
- name: name7,
795
+ name: name6,
923
796
  id: tool.id,
924
797
  args: tool.args
925
798
  };
@@ -934,58 +807,58 @@ function prepareToolsAndToolChoice({
934
807
  }
935
808
 
936
809
  // errors/invalid-argument-error.ts
937
- import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
938
- var name3 = "AI_InvalidArgumentError";
939
- var marker3 = `vercel.ai.error.${name3}`;
940
- var symbol3 = Symbol.for(marker3);
941
- var _a3;
942
- var InvalidArgumentError = class extends AISDKError4 {
810
+ import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
811
+ var name2 = "AI_InvalidArgumentError";
812
+ var marker2 = `vercel.ai.error.${name2}`;
813
+ var symbol2 = Symbol.for(marker2);
814
+ var _a2;
815
+ var InvalidArgumentError = class extends AISDKError3 {
943
816
  constructor({
944
817
  parameter,
945
818
  value,
946
819
  message
947
820
  }) {
948
821
  super({
949
- name: name3,
822
+ name: name2,
950
823
  message: `Invalid argument for parameter ${parameter}: ${message}`
951
824
  });
952
- this[_a3] = true;
825
+ this[_a2] = true;
953
826
  this.parameter = parameter;
954
827
  this.value = value;
955
828
  }
956
829
  static isInstance(error) {
957
- return AISDKError4.hasMarker(error, marker3);
830
+ return AISDKError3.hasMarker(error, marker2);
958
831
  }
959
832
  };
960
- _a3 = symbol3;
833
+ _a2 = symbol2;
961
834
 
962
835
  // util/retry-with-exponential-backoff.ts
963
836
  import { APICallError } from "@ai-sdk/provider";
964
837
  import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
965
838
 
966
839
  // util/retry-error.ts
967
- import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
968
- var name4 = "AI_RetryError";
969
- var marker4 = `vercel.ai.error.${name4}`;
970
- var symbol4 = Symbol.for(marker4);
971
- var _a4;
972
- var RetryError = class extends AISDKError5 {
840
+ import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
841
+ var name3 = "AI_RetryError";
842
+ var marker3 = `vercel.ai.error.${name3}`;
843
+ var symbol3 = Symbol.for(marker3);
844
+ var _a3;
845
+ var RetryError = class extends AISDKError4 {
973
846
  constructor({
974
847
  message,
975
848
  reason,
976
849
  errors
977
850
  }) {
978
- super({ name: name4, message });
979
- this[_a4] = true;
851
+ super({ name: name3, message });
852
+ this[_a3] = true;
980
853
  this.reason = reason;
981
854
  this.errors = errors;
982
855
  this.lastError = errors[errors.length - 1];
983
856
  }
984
857
  static isInstance(error) {
985
- return AISDKError5.hasMarker(error, marker4);
858
+ return AISDKError4.hasMarker(error, marker3);
986
859
  }
987
860
  };
988
- _a4 = symbol4;
861
+ _a3 = symbol3;
989
862
 
990
863
  // util/retry-with-exponential-backoff.ts
991
864
  var retryWithExponentialBackoff = ({
@@ -1160,13 +1033,16 @@ function prepareCallSettings({
1160
1033
  };
1161
1034
  }
1162
1035
 
1036
+ // core/prompt/convert-to-language-model-prompt.ts
1037
+ import { isUrlSupported } from "@ai-sdk/provider-utils";
1038
+
1163
1039
  // util/download-error.ts
1164
- import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
1165
- var name5 = "AI_DownloadError";
1166
- var marker5 = `vercel.ai.error.${name5}`;
1167
- var symbol5 = Symbol.for(marker5);
1168
- var _a5;
1169
- var DownloadError = class extends AISDKError6 {
1040
+ import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
1041
+ var name4 = "AI_DownloadError";
1042
+ var marker4 = `vercel.ai.error.${name4}`;
1043
+ var symbol4 = Symbol.for(marker4);
1044
+ var _a4;
1045
+ var DownloadError = class extends AISDKError5 {
1170
1046
  constructor({
1171
1047
  url,
1172
1048
  statusCode,
@@ -1174,21 +1050,21 @@ var DownloadError = class extends AISDKError6 {
1174
1050
  cause,
1175
1051
  message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
1176
1052
  }) {
1177
- super({ name: name5, message, cause });
1178
- this[_a5] = true;
1053
+ super({ name: name4, message, cause });
1054
+ this[_a4] = true;
1179
1055
  this.url = url;
1180
1056
  this.statusCode = statusCode;
1181
1057
  this.statusText = statusText;
1182
1058
  }
1183
1059
  static isInstance(error) {
1184
- return AISDKError6.hasMarker(error, marker5);
1060
+ return AISDKError5.hasMarker(error, marker4);
1185
1061
  }
1186
1062
  };
1187
- _a5 = symbol5;
1063
+ _a4 = symbol4;
1188
1064
 
1189
1065
  // util/download.ts
1190
1066
  async function download({ url }) {
1191
- var _a7;
1067
+ var _a6;
1192
1068
  const urlText = url.toString();
1193
1069
  try {
1194
1070
  const response = await fetch(urlText);
@@ -1201,7 +1077,7 @@ async function download({ url }) {
1201
1077
  }
1202
1078
  return {
1203
1079
  data: new Uint8Array(await response.arrayBuffer()),
1204
- mediaType: (_a7 = response.headers.get("content-type")) != null ? _a7 : void 0
1080
+ mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
1205
1081
  };
1206
1082
  } catch (error) {
1207
1083
  if (DownloadError.isInstance(error)) {
@@ -1313,28 +1189,27 @@ function detectMediaType({
1313
1189
  }
1314
1190
 
1315
1191
  // core/prompt/invalid-message-role-error.ts
1316
- import { AISDKError as AISDKError7 } from "@ai-sdk/provider";
1317
- var name6 = "AI_InvalidMessageRoleError";
1318
- var marker6 = `vercel.ai.error.${name6}`;
1319
- var symbol6 = Symbol.for(marker6);
1320
- var _a6;
1321
- var InvalidMessageRoleError = class extends AISDKError7 {
1192
+ import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
1193
+ var name5 = "AI_InvalidMessageRoleError";
1194
+ var marker5 = `vercel.ai.error.${name5}`;
1195
+ var symbol5 = Symbol.for(marker5);
1196
+ var _a5;
1197
+ var InvalidMessageRoleError = class extends AISDKError6 {
1322
1198
  constructor({
1323
1199
  role,
1324
1200
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
1325
1201
  }) {
1326
- super({ name: name6, message });
1327
- this[_a6] = true;
1202
+ super({ name: name5, message });
1203
+ this[_a5] = true;
1328
1204
  this.role = role;
1329
1205
  }
1330
1206
  static isInstance(error) {
1331
- return AISDKError7.hasMarker(error, marker6);
1207
+ return AISDKError6.hasMarker(error, marker5);
1332
1208
  }
1333
1209
  };
1334
- _a6 = symbol6;
1210
+ _a5 = symbol5;
1335
1211
 
1336
1212
  // core/prompt/convert-to-language-model-prompt.ts
1337
- import { isUrlSupported } from "@ai-sdk/provider-utils";
1338
1213
  async function convertToLanguageModelPrompt({
1339
1214
  prompt,
1340
1215
  supportedUrls,
@@ -1390,7 +1265,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
1390
1265
  // remove empty text parts:
1391
1266
  (part) => part.type !== "text" || part.text !== ""
1392
1267
  ).map((part) => {
1393
- var _a7;
1394
1268
  const providerOptions = part.providerOptions;
1395
1269
  switch (part.type) {
1396
1270
  case "file": {
@@ -1401,7 +1275,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
1401
1275
  type: "file",
1402
1276
  data,
1403
1277
  filename: part.filename,
1404
- mediaType: (_a7 = mediaType != null ? mediaType : part.mediaType) != null ? _a7 : part.mimeType,
1278
+ mediaType: mediaType != null ? mediaType : part.mediaType,
1405
1279
  providerOptions
1406
1280
  };
1407
1281
  }
@@ -1460,8 +1334,8 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
1460
1334
  ).flat().filter(
1461
1335
  (part) => part.type === "image" || part.type === "file"
1462
1336
  ).map((part) => {
1463
- var _a7, _b;
1464
- const mediaType = (_b = (_a7 = part.mediaType) != null ? _a7 : part.mimeType) != null ? _b : part.type === "image" ? "image/*" : void 0;
1337
+ var _a6;
1338
+ const mediaType = (_a6 = part.mediaType) != null ? _a6 : part.type === "image" ? "image/*" : void 0;
1465
1339
  let data = part.type === "image" ? part.image : part.data;
1466
1340
  if (typeof data === "string") {
1467
1341
  try {
@@ -1488,7 +1362,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
1488
1362
  );
1489
1363
  }
1490
1364
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1491
- var _a7, _b, _c;
1365
+ var _a6, _b;
1492
1366
  if (part.type === "text") {
1493
1367
  return {
1494
1368
  type: "text",
@@ -1509,19 +1383,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1509
1383
  throw new Error(`Unsupported part type: ${type}`);
1510
1384
  }
1511
1385
  const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
1512
- let mediaType = (_a7 = convertedMediaType != null ? convertedMediaType : part.mediaType) != null ? _a7 : part.mimeType;
1386
+ let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
1513
1387
  let data = convertedData;
1514
1388
  if (data instanceof URL) {
1515
1389
  const downloadedFile = downloadedAssets[data.toString()];
1516
1390
  if (downloadedFile) {
1517
1391
  data = downloadedFile.data;
1518
- mediaType = (_b = downloadedFile.mediaType) != null ? _b : mediaType;
1392
+ mediaType = (_a6 = downloadedFile.mediaType) != null ? _a6 : mediaType;
1519
1393
  }
1520
1394
  }
1521
1395
  switch (type) {
1522
1396
  case "image": {
1523
1397
  if (data instanceof Uint8Array || typeof data === "string") {
1524
- mediaType = (_c = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _c : mediaType;
1398
+ mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
1525
1399
  }
1526
1400
  return {
1527
1401
  type: "file",
@@ -1547,18 +1421,6 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1547
1421
  }
1548
1422
  }
1549
1423
 
1550
- // core/types/usage.ts
1551
- function calculateLanguageModelUsage({
1552
- inputTokens,
1553
- outputTokens
1554
- }) {
1555
- return {
1556
- promptTokens: inputTokens != null ? inputTokens : NaN,
1557
- completionTokens: outputTokens != null ? outputTokens : NaN,
1558
- totalTokens: (inputTokens != null ? inputTokens : 0) + (outputTokens != null ? outputTokens : 0)
1559
- };
1560
- }
1561
-
1562
1424
  // core/util/prepare-response-headers.ts
1563
1425
  function prepareResponseHeaders(headers, {
1564
1426
  contentType,
@@ -1759,7 +1621,6 @@ var StreamData = class {
1759
1621
  export {
1760
1622
  HANGING_STREAM_WARNING_TIME_MS,
1761
1623
  StreamData,
1762
- calculateLanguageModelUsage,
1763
1624
  convertToLanguageModelPrompt,
1764
1625
  createCallbacksTransformer,
1765
1626
  formatDataStreamPart,