ai 5.0.0-canary.16 → 5.0.0-canary.17

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/dist/index.js CHANGED
@@ -52,9 +52,12 @@ __export(ai_exports, {
52
52
  appendClientMessage: () => appendClientMessage,
53
53
  appendResponseMessages: () => appendResponseMessages,
54
54
  asSchema: () => import_provider_utils4.asSchema,
55
+ assistantModelMessageSchema: () => assistantModelMessageSchema,
55
56
  callChatApi: () => callChatApi,
56
57
  callCompletionApi: () => callCompletionApi,
58
+ convertFileListToFileUIParts: () => convertFileListToFileUIParts,
57
59
  convertToCoreMessages: () => convertToCoreMessages,
60
+ convertToModelMessages: () => convertToModelMessages,
58
61
  coreAssistantMessageSchema: () => coreAssistantMessageSchema,
59
62
  coreMessageSchema: () => coreMessageSchema,
60
63
  coreSystemMessageSchema: () => coreSystemMessageSchema,
@@ -86,10 +89,10 @@ __export(ai_exports, {
86
89
  isAssistantMessageWithCompletedToolCalls: () => isAssistantMessageWithCompletedToolCalls,
87
90
  isDeepEqualData: () => isDeepEqualData,
88
91
  jsonSchema: () => import_provider_utils4.jsonSchema,
92
+ modelMessageSchema: () => modelMessageSchema,
89
93
  parseDataStreamPart: () => parseDataStreamPart,
90
94
  parsePartialJson: () => parsePartialJson,
91
95
  pipeDataStreamToResponse: () => pipeDataStreamToResponse,
92
- prepareAttachmentsForRequest: () => prepareAttachmentsForRequest,
93
96
  processDataStream: () => processDataStream,
94
97
  processTextStream: () => processTextStream,
95
98
  shouldResubmitMessages: () => shouldResubmitMessages,
@@ -98,8 +101,11 @@ __export(ai_exports, {
98
101
  smoothStream: () => smoothStream,
99
102
  streamObject: () => streamObject,
100
103
  streamText: () => streamText,
104
+ systemModelMessageSchema: () => systemModelMessageSchema,
101
105
  tool: () => tool,
106
+ toolModelMessageSchema: () => toolModelMessageSchema,
102
107
  updateToolCallResult: () => updateToolCallResult,
108
+ userModelMessageSchema: () => userModelMessageSchema,
103
109
  wrapLanguageModel: () => wrapLanguageModel
104
110
  });
105
111
  module.exports = __toCommonJS(ai_exports);
@@ -682,9 +688,9 @@ var fileStreamPart = {
682
688
  code: "k",
683
689
  name: "file",
684
690
  parse: (value) => {
685
- if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string" || !("mimeType" in value) || typeof value.mimeType !== "string") {
691
+ if (value == null || typeof value !== "object" || !("url" in value) || typeof value.url !== "string" || !("mediaType" in value) || typeof value.mediaType !== "string") {
686
692
  throw new Error(
687
- '"file" parts expect an object with a "data" and "mimeType" property.'
693
+ '"file" parts expect an object with a "url" and "mediaType" property.'
688
694
  );
689
695
  }
690
696
  return { type: "file", value };
@@ -955,8 +961,8 @@ async function processChatResponse({
955
961
  onFilePart(value) {
956
962
  message.parts.push({
957
963
  type: "file",
958
- mediaType: value.mimeType,
959
- data: value.data
964
+ mediaType: value.mediaType,
965
+ url: value.url
960
966
  });
961
967
  execUpdate();
962
968
  },
@@ -1144,19 +1150,30 @@ async function callChatApi({
1144
1150
  onToolCall,
1145
1151
  generateId: generateId3,
1146
1152
  fetch: fetch2 = getOriginalFetch(),
1147
- lastMessage
1153
+ lastMessage,
1154
+ getCurrentDate,
1155
+ requestType = "generate"
1148
1156
  }) {
1149
- var _a17, _b;
1150
- const response = await fetch2(api, {
1157
+ var _a17, _b, _c;
1158
+ const request = requestType === "resume" ? fetch2(`${api}?chatId=${body.id}`, {
1159
+ method: "GET",
1160
+ headers: {
1161
+ "Content-Type": "application/json",
1162
+ ...headers
1163
+ },
1164
+ signal: (_a17 = abortController == null ? void 0 : abortController()) == null ? void 0 : _a17.signal,
1165
+ credentials
1166
+ }) : fetch2(api, {
1151
1167
  method: "POST",
1152
1168
  body: JSON.stringify(body),
1153
1169
  headers: {
1154
1170
  "Content-Type": "application/json",
1155
1171
  ...headers
1156
1172
  },
1157
- signal: (_a17 = abortController == null ? void 0 : abortController()) == null ? void 0 : _a17.signal,
1173
+ signal: (_b = abortController == null ? void 0 : abortController()) == null ? void 0 : _b.signal,
1158
1174
  credentials
1159
- }).catch((err) => {
1175
+ });
1176
+ const response = await request.catch((err) => {
1160
1177
  restoreMessagesOnFailure();
1161
1178
  throw err;
1162
1179
  });
@@ -1170,7 +1187,7 @@ async function callChatApi({
1170
1187
  if (!response.ok) {
1171
1188
  restoreMessagesOnFailure();
1172
1189
  throw new Error(
1173
- (_b = await response.text()) != null ? _b : "Failed to fetch the chat response."
1190
+ (_c = await response.text()) != null ? _c : "Failed to fetch the chat response."
1174
1191
  );
1175
1192
  }
1176
1193
  if (!response.body) {
@@ -1197,7 +1214,8 @@ async function callChatApi({
1197
1214
  onFinish(message, { usage, finishReason });
1198
1215
  }
1199
1216
  },
1200
- generateId: generateId3
1217
+ generateId: generateId3,
1218
+ getCurrentDate
1201
1219
  });
1202
1220
  return;
1203
1221
  }
@@ -1318,6 +1336,36 @@ async function callCompletionApi({
1318
1336
  }
1319
1337
  }
1320
1338
 
1339
+ // core/util/convert-file-list-to-file-ui-parts.ts
1340
+ async function convertFileListToFileUIParts(files) {
1341
+ if (files == null) {
1342
+ return [];
1343
+ }
1344
+ if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
1345
+ throw new Error("FileList is not supported in the current environment");
1346
+ }
1347
+ return Promise.all(
1348
+ Array.from(files).map(async (file) => {
1349
+ const { name: name17, type } = file;
1350
+ const dataUrl = await new Promise((resolve, reject) => {
1351
+ const reader = new FileReader();
1352
+ reader.onload = (readerEvent) => {
1353
+ var _a17;
1354
+ resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
1355
+ };
1356
+ reader.onerror = (error) => reject(error);
1357
+ reader.readAsDataURL(file);
1358
+ });
1359
+ return {
1360
+ type: "file",
1361
+ mediaType: type,
1362
+ filename: name17,
1363
+ url: dataUrl
1364
+ };
1365
+ })
1366
+ );
1367
+ }
1368
+
1321
1369
  // core/util/data-url.ts
1322
1370
  function getTextFromDataUrl(dataUrl) {
1323
1371
  const [header, base64Content] = dataUrl.split(",");
@@ -1367,58 +1415,6 @@ function isDeepEqualData(obj1, obj2) {
1367
1415
  return true;
1368
1416
  }
1369
1417
 
1370
- // core/util/prepare-attachments-for-request.ts
1371
- async function prepareAttachmentsForRequest(attachmentsFromOptions) {
1372
- if (!attachmentsFromOptions) {
1373
- return [];
1374
- }
1375
- if (globalThis.FileList && attachmentsFromOptions instanceof globalThis.FileList) {
1376
- return Promise.all(
1377
- Array.from(attachmentsFromOptions).map(async (attachment) => {
1378
- const { name: name17, type } = attachment;
1379
- const dataUrl = await new Promise((resolve, reject) => {
1380
- const reader = new FileReader();
1381
- reader.onload = (readerEvent) => {
1382
- var _a17;
1383
- resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
1384
- };
1385
- reader.onerror = (error) => reject(error);
1386
- reader.readAsDataURL(attachment);
1387
- });
1388
- return {
1389
- name: name17,
1390
- contentType: type,
1391
- url: dataUrl
1392
- };
1393
- })
1394
- );
1395
- }
1396
- if (Array.isArray(attachmentsFromOptions)) {
1397
- return attachmentsFromOptions;
1398
- }
1399
- throw new Error("Invalid attachments type");
1400
- }
1401
-
1402
- // core/util/update-tool-call-result.ts
1403
- function updateToolCallResult({
1404
- messages,
1405
- toolCallId,
1406
- toolResult: result
1407
- }) {
1408
- const lastMessage = messages[messages.length - 1];
1409
- const invocationPart = lastMessage.parts.find(
1410
- (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
1411
- );
1412
- if (invocationPart == null) {
1413
- return;
1414
- }
1415
- invocationPart.toolInvocation = {
1416
- ...invocationPart.toolInvocation,
1417
- state: "result",
1418
- result
1419
- };
1420
- }
1421
-
1422
1418
  // core/util/should-resubmit-messages.ts
1423
1419
  function shouldResubmitMessages({
1424
1420
  originalMaxToolInvocationStep,
@@ -1448,6 +1444,26 @@ function isAssistantMessageWithCompletedToolCalls(message) {
1448
1444
  return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result" in part.toolInvocation);
1449
1445
  }
1450
1446
 
1447
+ // core/util/update-tool-call-result.ts
1448
+ function updateToolCallResult({
1449
+ messages,
1450
+ toolCallId,
1451
+ toolResult: result
1452
+ }) {
1453
+ const lastMessage = messages[messages.length - 1];
1454
+ const invocationPart = lastMessage.parts.find(
1455
+ (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
1456
+ );
1457
+ if (invocationPart == null) {
1458
+ return;
1459
+ }
1460
+ invocationPart.toolInvocation = {
1461
+ ...invocationPart.toolInvocation,
1462
+ state: "result",
1463
+ result
1464
+ };
1465
+ }
1466
+
1451
1467
  // core/data-stream/create-data-stream.ts
1452
1468
  function createDataStream({
1453
1469
  execute,
@@ -2465,7 +2481,7 @@ async function generateImage({
2465
2481
  abortSignal,
2466
2482
  headers
2467
2483
  }) {
2468
- var _a17;
2484
+ var _a17, _b;
2469
2485
  const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
2470
2486
  const maxImagesPerCall = (_a17 = model.maxImagesPerCall) != null ? _a17 : 1;
2471
2487
  const callCount = Math.ceil(n / maxImagesPerCall);
@@ -2495,6 +2511,7 @@ async function generateImage({
2495
2511
  const images = [];
2496
2512
  const warnings = [];
2497
2513
  const responses = [];
2514
+ const providerMetadata = {};
2498
2515
  for (const result of results) {
2499
2516
  images.push(
2500
2517
  ...result.images.map(
@@ -2511,18 +2528,32 @@ async function generateImage({
2511
2528
  )
2512
2529
  );
2513
2530
  warnings.push(...result.warnings);
2531
+ if (result.providerMetadata) {
2532
+ for (const [providerName, metadata] of Object.entries(result.providerMetadata)) {
2533
+ (_b = providerMetadata[providerName]) != null ? _b : providerMetadata[providerName] = { images: [] };
2534
+ providerMetadata[providerName].images.push(
2535
+ ...result.providerMetadata[providerName].images
2536
+ );
2537
+ }
2538
+ }
2514
2539
  responses.push(result.response);
2515
2540
  }
2516
2541
  if (!images.length) {
2517
2542
  throw new NoImageGeneratedError({ responses });
2518
2543
  }
2519
- return new DefaultGenerateImageResult({ images, warnings, responses });
2544
+ return new DefaultGenerateImageResult({
2545
+ images,
2546
+ warnings,
2547
+ responses,
2548
+ providerMetadata
2549
+ });
2520
2550
  }
2521
2551
  var DefaultGenerateImageResult = class {
2522
2552
  constructor(options) {
2523
2553
  this.images = options.images;
2524
2554
  this.warnings = options.warnings;
2525
2555
  this.responses = options.responses;
2556
+ this.providerMetadata = options.providerMetadata;
2526
2557
  }
2527
2558
  get image() {
2528
2559
  return this.images[0];
@@ -2572,6 +2603,9 @@ function extractContentText(content) {
2572
2603
  return parts.map((content2) => content2.text).join("");
2573
2604
  }
2574
2605
 
2606
+ // core/prompt/convert-to-language-model-prompt.ts
2607
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2608
+
2575
2609
  // util/download-error.ts
2576
2610
  var import_provider6 = require("@ai-sdk/provider");
2577
2611
  var name5 = "AI_DownloadError";
@@ -2736,13 +2770,6 @@ function convertDataContentToUint8Array(content) {
2736
2770
  }
2737
2771
  throw new InvalidDataContentError({ content });
2738
2772
  }
2739
- function convertUint8ArrayToText(uint8Array) {
2740
- try {
2741
- return new TextDecoder().decode(uint8Array);
2742
- } catch (error) {
2743
- throw new Error("Error decoding Uint8Array to text");
2744
- }
2745
- }
2746
2773
 
2747
2774
  // core/prompt/invalid-message-role-error.ts
2748
2775
  var import_provider9 = require("@ai-sdk/provider");
@@ -2766,7 +2793,6 @@ var InvalidMessageRoleError = class extends import_provider9.AISDKError {
2766
2793
  _a7 = symbol7;
2767
2794
 
2768
2795
  // core/prompt/convert-to-language-model-prompt.ts
2769
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2770
2796
  async function convertToLanguageModelPrompt({
2771
2797
  prompt,
2772
2798
  supportedUrls,
@@ -2822,7 +2848,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
2822
2848
  // remove empty text parts:
2823
2849
  (part) => part.type !== "text" || part.text !== ""
2824
2850
  ).map((part) => {
2825
- var _a17;
2826
2851
  const providerOptions = part.providerOptions;
2827
2852
  switch (part.type) {
2828
2853
  case "file": {
@@ -2833,7 +2858,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
2833
2858
  type: "file",
2834
2859
  data,
2835
2860
  filename: part.filename,
2836
- mediaType: (_a17 = mediaType != null ? mediaType : part.mediaType) != null ? _a17 : part.mimeType,
2861
+ mediaType: mediaType != null ? mediaType : part.mediaType,
2837
2862
  providerOptions
2838
2863
  };
2839
2864
  }
@@ -2892,8 +2917,8 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
2892
2917
  ).flat().filter(
2893
2918
  (part) => part.type === "image" || part.type === "file"
2894
2919
  ).map((part) => {
2895
- var _a17, _b;
2896
- const mediaType = (_b = (_a17 = part.mediaType) != null ? _a17 : part.mimeType) != null ? _b : part.type === "image" ? "image/*" : void 0;
2920
+ var _a17;
2921
+ const mediaType = (_a17 = part.mediaType) != null ? _a17 : part.type === "image" ? "image/*" : void 0;
2897
2922
  let data = part.type === "image" ? part.image : part.data;
2898
2923
  if (typeof data === "string") {
2899
2924
  try {
@@ -2920,7 +2945,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
2920
2945
  );
2921
2946
  }
2922
2947
  function convertPartToLanguageModelPart(part, downloadedAssets) {
2923
- var _a17, _b, _c;
2948
+ var _a17, _b;
2924
2949
  if (part.type === "text") {
2925
2950
  return {
2926
2951
  type: "text",
@@ -2941,19 +2966,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
2941
2966
  throw new Error(`Unsupported part type: ${type}`);
2942
2967
  }
2943
2968
  const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
2944
- let mediaType = (_a17 = convertedMediaType != null ? convertedMediaType : part.mediaType) != null ? _a17 : part.mimeType;
2969
+ let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
2945
2970
  let data = convertedData;
2946
2971
  if (data instanceof URL) {
2947
2972
  const downloadedFile = downloadedAssets[data.toString()];
2948
2973
  if (downloadedFile) {
2949
2974
  data = downloadedFile.data;
2950
- mediaType = (_b = downloadedFile.mediaType) != null ? _b : mediaType;
2975
+ mediaType = (_a17 = downloadedFile.mediaType) != null ? _a17 : mediaType;
2951
2976
  }
2952
2977
  }
2953
2978
  switch (type) {
2954
2979
  case "image": {
2955
2980
  if (data instanceof Uint8Array || typeof data === "string") {
2956
- mediaType = (_c = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _c : mediaType;
2981
+ mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
2957
2982
  }
2958
2983
  return {
2959
2984
  type: "file",
@@ -3077,83 +3102,6 @@ var import_provider11 = require("@ai-sdk/provider");
3077
3102
  var import_provider_utils10 = require("@ai-sdk/provider-utils");
3078
3103
  var import_zod7 = require("zod");
3079
3104
 
3080
- // core/prompt/attachments-to-parts.ts
3081
- function attachmentsToParts(attachments) {
3082
- var _a17, _b, _c;
3083
- const parts = [];
3084
- for (const attachment of attachments) {
3085
- let url;
3086
- try {
3087
- url = new URL(attachment.url);
3088
- } catch (error) {
3089
- throw new Error(`Invalid URL: ${attachment.url}`);
3090
- }
3091
- switch (url.protocol) {
3092
- case "http:":
3093
- case "https:": {
3094
- if ((_a17 = attachment.contentType) == null ? void 0 : _a17.startsWith("image/")) {
3095
- parts.push({ type: "image", image: url });
3096
- } else {
3097
- if (!attachment.contentType) {
3098
- throw new Error(
3099
- "If the attachment is not an image, it must specify a content type"
3100
- );
3101
- }
3102
- parts.push({
3103
- type: "file",
3104
- data: url,
3105
- mediaType: attachment.contentType
3106
- });
3107
- }
3108
- break;
3109
- }
3110
- case "data:": {
3111
- let header;
3112
- let base64Content;
3113
- let mediaType;
3114
- try {
3115
- [header, base64Content] = attachment.url.split(",");
3116
- mediaType = header.split(";")[0].split(":")[1];
3117
- } catch (error) {
3118
- throw new Error(`Error processing data URL: ${attachment.url}`);
3119
- }
3120
- if (mediaType == null || base64Content == null) {
3121
- throw new Error(`Invalid data URL format: ${attachment.url}`);
3122
- }
3123
- if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
3124
- parts.push({
3125
- type: "image",
3126
- image: convertDataContentToUint8Array(base64Content)
3127
- });
3128
- } else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
3129
- parts.push({
3130
- type: "text",
3131
- text: convertUint8ArrayToText(
3132
- convertDataContentToUint8Array(base64Content)
3133
- )
3134
- });
3135
- } else {
3136
- if (!attachment.contentType) {
3137
- throw new Error(
3138
- "If the attachment is not an image or text, it must specify a content type"
3139
- );
3140
- }
3141
- parts.push({
3142
- type: "file",
3143
- data: base64Content,
3144
- mediaType: attachment.contentType
3145
- });
3146
- }
3147
- break;
3148
- }
3149
- default: {
3150
- throw new Error(`Unsupported URL protocol: ${url.protocol}`);
3151
- }
3152
- }
3153
- }
3154
- return parts;
3155
- }
3156
-
3157
3105
  // core/prompt/message-conversion-error.ts
3158
3106
  var import_provider10 = require("@ai-sdk/provider");
3159
3107
  var name8 = "AI_MessageConversionError";
@@ -3175,15 +3123,15 @@ var MessageConversionError = class extends import_provider10.AISDKError {
3175
3123
  };
3176
3124
  _a8 = symbol8;
3177
3125
 
3178
- // core/prompt/convert-to-core-messages.ts
3179
- function convertToCoreMessages(messages, options) {
3126
+ // core/prompt/convert-to-model-messages.ts
3127
+ function convertToModelMessages(messages, options) {
3180
3128
  var _a17, _b;
3181
3129
  const tools = (_a17 = options == null ? void 0 : options.tools) != null ? _a17 : {};
3182
3130
  const coreMessages = [];
3183
3131
  for (let i = 0; i < messages.length; i++) {
3184
3132
  const message = messages[i];
3185
3133
  const isLastMessage = i === messages.length - 1;
3186
- const { role, content, experimental_attachments } = message;
3134
+ const { role, content } = message;
3187
3135
  switch (role) {
3188
3136
  case "system": {
3189
3137
  coreMessages.push({
@@ -3193,30 +3141,24 @@ function convertToCoreMessages(messages, options) {
3193
3141
  break;
3194
3142
  }
3195
3143
  case "user": {
3196
- if (message.parts == null) {
3197
- coreMessages.push({
3198
- role: "user",
3199
- content: experimental_attachments ? [
3200
- { type: "text", text: content },
3201
- ...attachmentsToParts(experimental_attachments)
3202
- ] : content
3203
- });
3204
- } else {
3205
- const textParts = message.parts.filter((part) => part.type === "text").map((part) => ({
3206
- type: "text",
3207
- text: part.text
3208
- }));
3209
- coreMessages.push({
3210
- role: "user",
3211
- content: experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts
3212
- });
3213
- }
3144
+ coreMessages.push({
3145
+ role: "user",
3146
+ content: message.parts.filter(
3147
+ (part) => part.type === "text" || part.type === "file"
3148
+ ).map(
3149
+ (part) => part.type === "file" ? {
3150
+ type: "file",
3151
+ mediaType: part.mediaType,
3152
+ filename: part.filename,
3153
+ data: part.url
3154
+ } : part
3155
+ )
3156
+ });
3214
3157
  break;
3215
3158
  }
3216
3159
  case "assistant": {
3217
3160
  if (message.parts != null) {
3218
3161
  let processBlock2 = function() {
3219
- var _a18;
3220
3162
  const content2 = [];
3221
3163
  for (const part of block) {
3222
3164
  switch (part.type) {
@@ -3227,9 +3169,8 @@ function convertToCoreMessages(messages, options) {
3227
3169
  case "file": {
3228
3170
  content2.push({
3229
3171
  type: "file",
3230
- data: part.data,
3231
- mediaType: (_a18 = part.mediaType) != null ? _a18 : part.mimeType
3232
- // TODO migration, remove
3172
+ mediaType: part.mediaType,
3173
+ data: part.url
3233
3174
  });
3234
3175
  break;
3235
3176
  }
@@ -3342,6 +3283,7 @@ function convertToCoreMessages(messages, options) {
3342
3283
  }
3343
3284
  return coreMessages;
3344
3285
  }
3286
+ var convertToCoreMessages = convertToModelMessages;
3345
3287
 
3346
3288
  // core/prompt/detect-prompt-type.ts
3347
3289
  function detectPromptType(prompt) {
@@ -3430,7 +3372,6 @@ var imagePartSchema = import_zod5.z.object({
3430
3372
  type: import_zod5.z.literal("image"),
3431
3373
  image: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
3432
3374
  mediaType: import_zod5.z.string().optional(),
3433
- mimeType: import_zod5.z.string().optional(),
3434
3375
  providerOptions: providerMetadataSchema.optional()
3435
3376
  });
3436
3377
  var filePartSchema = import_zod5.z.object({
@@ -3438,7 +3379,6 @@ var filePartSchema = import_zod5.z.object({
3438
3379
  data: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
3439
3380
  filename: import_zod5.z.string().optional(),
3440
3381
  mediaType: import_zod5.z.string(),
3441
- mimeType: import_zod5.z.string().optional(),
3442
3382
  providerOptions: providerMetadataSchema.optional()
3443
3383
  });
3444
3384
  var reasoningPartSchema = import_zod5.z.object({
@@ -3464,12 +3404,15 @@ var toolResultPartSchema = import_zod5.z.object({
3464
3404
  });
3465
3405
 
3466
3406
  // core/prompt/message.ts
3467
- var coreSystemMessageSchema = import_zod6.z.object({
3468
- role: import_zod6.z.literal("system"),
3469
- content: import_zod6.z.string(),
3470
- providerOptions: providerMetadataSchema.optional()
3471
- });
3472
- var coreUserMessageSchema = import_zod6.z.object({
3407
+ var systemModelMessageSchema = import_zod6.z.object(
3408
+ {
3409
+ role: import_zod6.z.literal("system"),
3410
+ content: import_zod6.z.string(),
3411
+ providerOptions: providerMetadataSchema.optional()
3412
+ }
3413
+ );
3414
+ var coreSystemMessageSchema = systemModelMessageSchema;
3415
+ var userModelMessageSchema = import_zod6.z.object({
3473
3416
  role: import_zod6.z.literal("user"),
3474
3417
  content: import_zod6.z.union([
3475
3418
  import_zod6.z.string(),
@@ -3477,7 +3420,8 @@ var coreUserMessageSchema = import_zod6.z.object({
3477
3420
  ]),
3478
3421
  providerOptions: providerMetadataSchema.optional()
3479
3422
  });
3480
- var coreAssistantMessageSchema = import_zod6.z.object({
3423
+ var coreUserMessageSchema = userModelMessageSchema;
3424
+ var assistantModelMessageSchema = import_zod6.z.object({
3481
3425
  role: import_zod6.z.literal("assistant"),
3482
3426
  content: import_zod6.z.union([
3483
3427
  import_zod6.z.string(),
@@ -3492,17 +3436,20 @@ var coreAssistantMessageSchema = import_zod6.z.object({
3492
3436
  ]),
3493
3437
  providerOptions: providerMetadataSchema.optional()
3494
3438
  });
3495
- var coreToolMessageSchema = import_zod6.z.object({
3439
+ var coreAssistantMessageSchema = assistantModelMessageSchema;
3440
+ var toolModelMessageSchema = import_zod6.z.object({
3496
3441
  role: import_zod6.z.literal("tool"),
3497
3442
  content: import_zod6.z.array(toolResultPartSchema),
3498
3443
  providerOptions: providerMetadataSchema.optional()
3499
3444
  });
3500
- var coreMessageSchema = import_zod6.z.union([
3501
- coreSystemMessageSchema,
3502
- coreUserMessageSchema,
3503
- coreAssistantMessageSchema,
3504
- coreToolMessageSchema
3445
+ var coreToolMessageSchema = toolModelMessageSchema;
3446
+ var modelMessageSchema = import_zod6.z.union([
3447
+ systemModelMessageSchema,
3448
+ userModelMessageSchema,
3449
+ assistantModelMessageSchema,
3450
+ toolModelMessageSchema
3505
3451
  ]);
3452
+ var coreMessageSchema = modelMessageSchema;
3506
3453
 
3507
3454
  // core/prompt/standardize-prompt.ts
3508
3455
  async function standardizePrompt({
@@ -3549,10 +3496,10 @@ async function standardizePrompt({
3549
3496
  if (promptType === "other") {
3550
3497
  throw new import_provider11.InvalidPromptError({
3551
3498
  prompt,
3552
- message: "messages must be an array of CoreMessage or UIMessage"
3499
+ message: "messages must be an array of ModelMessage or UIMessage"
3553
3500
  });
3554
3501
  }
3555
- const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
3502
+ const messages = promptType === "ui-messages" ? convertToModelMessages(prompt.messages, {
3556
3503
  tools
3557
3504
  }) : prompt.messages;
3558
3505
  if (messages.length === 0) {
@@ -3563,12 +3510,12 @@ async function standardizePrompt({
3563
3510
  }
3564
3511
  const validationResult = await (0, import_provider_utils10.safeValidateTypes)({
3565
3512
  value: messages,
3566
- schema: import_zod7.z.array(coreMessageSchema)
3513
+ schema: import_zod7.z.array(modelMessageSchema)
3567
3514
  });
3568
3515
  if (!validationResult.success) {
3569
3516
  throw new import_provider11.InvalidPromptError({
3570
3517
  prompt,
3571
- message: "messages must be an array of CoreMessage or UIMessage",
3518
+ message: "messages must be an array of ModelMessage or UIMessage",
3572
3519
  cause: validationResult.error
3573
3520
  });
3574
3521
  }
@@ -7202,8 +7149,8 @@ var DefaultStreamTextResult = class {
7202
7149
  controller.enqueue(
7203
7150
  // TODO update protocol to v2 or replace with event stream
7204
7151
  formatDataStreamPart("file", {
7205
- mimeType: chunk.file.mediaType,
7206
- data: chunk.file.base64
7152
+ mediaType: chunk.file.mediaType,
7153
+ url: `data:${chunk.file.mediaType};base64,${chunk.file.base64}`
7207
7154
  })
7208
7155
  );
7209
7156
  break;
@@ -7425,16 +7372,16 @@ var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
7425
7372
  super({ data, mediaType });
7426
7373
  let format = "mp3";
7427
7374
  if (mediaType) {
7428
- const mimeTypeParts = mediaType.split("/");
7429
- if (mimeTypeParts.length === 2) {
7375
+ const mediaTypeParts = mediaType.split("/");
7376
+ if (mediaTypeParts.length === 2) {
7430
7377
  if (mediaType !== "audio/mpeg") {
7431
- format = mimeTypeParts[1];
7378
+ format = mediaTypeParts[1];
7432
7379
  }
7433
7380
  }
7434
7381
  }
7435
7382
  if (!format) {
7436
7383
  throw new Error(
7437
- "Audio format must be provided or determinable from mimeType"
7384
+ "Audio format must be provided or determinable from media type"
7438
7385
  );
7439
7386
  }
7440
7387
  this.format = format;
@@ -7863,7 +7810,7 @@ function appendResponseMessages({
7863
7810
  responseMessages,
7864
7811
  _internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
7865
7812
  }) {
7866
- var _a17, _b, _c;
7813
+ var _a17, _b;
7867
7814
  const clonedMessages = structuredClone(messages);
7868
7815
  for (const message of responseMessages) {
7869
7816
  const role = message.role;
@@ -7927,8 +7874,8 @@ function appendResponseMessages({
7927
7874
  }
7928
7875
  parts.push({
7929
7876
  type: "file",
7930
- mediaType: (_a17 = part.mediaType) != null ? _a17 : part.mimeType,
7931
- data: convertDataContentToBase64String(part.data)
7877
+ mediaType: part.mediaType,
7878
+ url: `data:${part.mediaType};base64,${convertDataContentToBase64String(part.data)}`
7932
7879
  });
7933
7880
  break;
7934
7881
  }
@@ -7939,7 +7886,7 @@ function appendResponseMessages({
7939
7886
  getToolInvocations(lastMessage)
7940
7887
  // TODO remove once Message is removed
7941
7888
  );
7942
- (_b = lastMessage.parts) != null ? _b : lastMessage.parts = [];
7889
+ (_a17 = lastMessage.parts) != null ? _a17 : lastMessage.parts = [];
7943
7890
  lastMessage.content = textContent;
7944
7891
  lastMessage.parts.push(...parts);
7945
7892
  getToolInvocationsForStep2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
@@ -7972,7 +7919,7 @@ function appendResponseMessages({
7972
7919
  `Tool result must follow an assistant message: ${lastMessage.role}`
7973
7920
  );
7974
7921
  }
7975
- (_c = lastMessage.parts) != null ? _c : lastMessage.parts = [];
7922
+ (_b = lastMessage.parts) != null ? _b : lastMessage.parts = [];
7976
7923
  for (const contentPart of message.content) {
7977
7924
  const toolCall = getToolInvocations(
7978
7925
  lastMessage
@@ -8866,9 +8813,12 @@ var StreamData = class {
8866
8813
  appendClientMessage,
8867
8814
  appendResponseMessages,
8868
8815
  asSchema,
8816
+ assistantModelMessageSchema,
8869
8817
  callChatApi,
8870
8818
  callCompletionApi,
8819
+ convertFileListToFileUIParts,
8871
8820
  convertToCoreMessages,
8821
+ convertToModelMessages,
8872
8822
  coreAssistantMessageSchema,
8873
8823
  coreMessageSchema,
8874
8824
  coreSystemMessageSchema,
@@ -8900,10 +8850,10 @@ var StreamData = class {
8900
8850
  isAssistantMessageWithCompletedToolCalls,
8901
8851
  isDeepEqualData,
8902
8852
  jsonSchema,
8853
+ modelMessageSchema,
8903
8854
  parseDataStreamPart,
8904
8855
  parsePartialJson,
8905
8856
  pipeDataStreamToResponse,
8906
- prepareAttachmentsForRequest,
8907
8857
  processDataStream,
8908
8858
  processTextStream,
8909
8859
  shouldResubmitMessages,
@@ -8912,8 +8862,11 @@ var StreamData = class {
8912
8862
  smoothStream,
8913
8863
  streamObject,
8914
8864
  streamText,
8865
+ systemModelMessageSchema,
8915
8866
  tool,
8867
+ toolModelMessageSchema,
8916
8868
  updateToolCallResult,
8869
+ userModelMessageSchema,
8917
8870
  wrapLanguageModel
8918
8871
  });
8919
8872
  //# sourceMappingURL=index.js.map