ai 7.0.0-beta.113 → 7.0.0-beta.115

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 (236) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/index.d.ts +1506 -1468
  3. package/dist/index.js +889 -979
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +273 -273
  6. package/dist/internal/index.js +367 -405
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/test/index.d.ts +18 -18
  9. package/dist/test/index.js +22 -22
  10. package/dist/test/index.js.map +1 -1
  11. package/docs/02-foundations/03-prompts.mdx +13 -11
  12. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +2 -1
  13. package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
  14. package/docs/03-ai-sdk-core/45-provider-management.mdx +1 -1
  15. package/docs/03-ai-sdk-core/60-telemetry.mdx +87 -13
  16. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
  17. package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
  18. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
  19. package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +9 -1
  20. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +104 -0
  21. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +56 -10
  22. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +1 -1
  23. package/docs/08-migration-guides/23-migration-guide-7-0.mdx +42 -0
  24. package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
  25. package/package.json +5 -5
  26. package/src/agent/agent.ts +13 -9
  27. package/src/agent/create-agent-ui-stream-response.ts +8 -8
  28. package/src/agent/create-agent-ui-stream.ts +9 -9
  29. package/src/agent/infer-agent-tools.ts +1 -1
  30. package/src/agent/infer-agent-ui-message.ts +2 -2
  31. package/src/agent/pipe-agent-ui-stream-to-response.ts +9 -9
  32. package/src/agent/tool-loop-agent-settings.ts +17 -19
  33. package/src/agent/tool-loop-agent.ts +16 -8
  34. package/src/embed/embed-many-result.ts +3 -4
  35. package/src/embed/embed-many.ts +5 -5
  36. package/src/embed/embed-result.ts +3 -4
  37. package/src/embed/embed.ts +4 -4
  38. package/src/error/invalid-stream-part-error.ts +1 -1
  39. package/src/error/no-image-generated-error.ts +1 -1
  40. package/src/error/no-object-generated-error.ts +3 -3
  41. package/src/error/no-speech-generated-error.ts +1 -1
  42. package/src/error/no-transcript-generated-error.ts +1 -1
  43. package/src/error/no-video-generated-error.ts +1 -1
  44. package/src/error/tool-call-repair-error.ts +2 -2
  45. package/src/error/verify-no-object-generated-error.ts +1 -1
  46. package/src/generate-image/generate-image-result.ts +5 -5
  47. package/src/generate-image/generate-image.ts +12 -15
  48. package/src/generate-image/index.ts +3 -2
  49. package/src/generate-object/generate-object-result.ts +2 -2
  50. package/src/generate-object/generate-object.ts +14 -14
  51. package/src/generate-object/inject-json-instruction.ts +1 -1
  52. package/src/generate-object/output-strategy.ts +10 -10
  53. package/src/generate-object/parse-and-validate-object-result.ts +1 -1
  54. package/src/generate-object/repair-text.ts +1 -1
  55. package/src/generate-object/stream-object-result.ts +4 -4
  56. package/src/generate-object/stream-object.ts +22 -19
  57. package/src/generate-object/validate-object-generation-input.ts +1 -1
  58. package/src/generate-speech/generate-speech-result.ts +4 -4
  59. package/src/generate-speech/generate-speech.ts +12 -13
  60. package/src/generate-speech/generated-audio-file.ts +1 -2
  61. package/src/generate-text/collect-tool-approvals.ts +4 -4
  62. package/src/generate-text/content-part.ts +9 -9
  63. package/src/generate-text/create-execute-tools-transformation.ts +9 -7
  64. package/src/generate-text/execute-tool-call.ts +11 -13
  65. package/src/generate-text/extract-reasoning-content.ts +1 -1
  66. package/src/generate-text/extract-text-content.ts +4 -1
  67. package/src/generate-text/generate-text-events.ts +2 -2
  68. package/src/generate-text/generate-text-result.ts +18 -14
  69. package/src/generate-text/generate-text.ts +42 -38
  70. package/src/generate-text/invoke-tool-callbacks-from-stream.ts +2 -3
  71. package/src/generate-text/output-utils.ts +1 -1
  72. package/src/generate-text/output.ts +8 -8
  73. package/src/generate-text/parse-tool-call.ts +36 -9
  74. package/src/generate-text/prepare-step.ts +3 -5
  75. package/src/generate-text/prune-messages.ts +1 -1
  76. package/src/generate-text/reasoning-output.ts +26 -9
  77. package/src/generate-text/reasoning.ts +1 -1
  78. package/src/generate-text/resolve-tool-approval.ts +3 -3
  79. package/src/generate-text/response-message.ts +1 -1
  80. package/src/generate-text/restricted-telemetry-dispatcher.ts +1 -1
  81. package/src/generate-text/smooth-stream.ts +6 -5
  82. package/src/generate-text/step-result.ts +16 -11
  83. package/src/generate-text/stop-condition.ts +1 -1
  84. package/src/generate-text/stream-language-model-call.ts +26 -21
  85. package/src/generate-text/stream-text-result.ts +29 -26
  86. package/src/generate-text/stream-text.ts +48 -46
  87. package/src/generate-text/to-response-messages.ts +2 -2
  88. package/src/generate-text/tool-approval-configuration.ts +2 -2
  89. package/src/generate-text/tool-approval-request-output.ts +1 -1
  90. package/src/generate-text/tool-approval-response-output.ts +1 -1
  91. package/src/generate-text/tool-call-repair-function.ts +4 -4
  92. package/src/generate-text/tool-call.ts +3 -4
  93. package/src/generate-text/tool-error.ts +3 -4
  94. package/src/generate-text/tool-execution-events.ts +2 -2
  95. package/src/generate-text/tool-output-denied.ts +1 -1
  96. package/src/generate-text/tool-output.ts +2 -2
  97. package/src/generate-text/tool-result.ts +7 -4
  98. package/src/generate-text/tools-context-parameter.ts +1 -1
  99. package/src/generate-text/validate-tool-context.ts +1 -2
  100. package/src/generate-video/generate-video-result.ts +4 -4
  101. package/src/generate-video/generate-video.ts +6 -10
  102. package/src/global.ts +2 -2
  103. package/src/index.ts +3 -3
  104. package/src/logger/log-warnings.ts +1 -1
  105. package/src/middleware/add-tool-input-examples-middleware.ts +2 -2
  106. package/src/middleware/default-embedding-settings-middleware.ts +2 -2
  107. package/src/middleware/default-settings-middleware.ts +2 -2
  108. package/src/middleware/extract-json-middleware.ts +1 -1
  109. package/src/middleware/extract-reasoning-middleware.ts +1 -1
  110. package/src/middleware/simulate-streaming-middleware.ts +1 -1
  111. package/src/middleware/wrap-embedding-model.ts +2 -2
  112. package/src/middleware/wrap-image-model.ts +2 -2
  113. package/src/middleware/wrap-language-model.ts +2 -2
  114. package/src/middleware/wrap-provider.ts +2 -2
  115. package/src/model/as-embedding-model-v3.ts +1 -1
  116. package/src/model/as-embedding-model-v4.ts +1 -1
  117. package/src/model/as-image-model-v3.ts +1 -1
  118. package/src/model/as-image-model-v4.ts +5 -1
  119. package/src/model/as-language-model-v3.ts +1 -1
  120. package/src/model/as-language-model-v4.ts +1 -1
  121. package/src/model/as-provider-v3.ts +1 -1
  122. package/src/model/as-provider-v4.ts +1 -1
  123. package/src/model/as-reranking-model-v4.ts +1 -1
  124. package/src/model/as-speech-model-v3.ts +1 -1
  125. package/src/model/as-speech-model-v4.ts +5 -1
  126. package/src/model/as-transcription-model-v3.ts +4 -1
  127. package/src/model/as-transcription-model-v4.ts +1 -1
  128. package/src/model/as-video-model-v4.ts +1 -1
  129. package/src/model/resolve-model.ts +8 -8
  130. package/src/prompt/content-part.ts +45 -15
  131. package/src/prompt/convert-to-language-model-prompt.ts +108 -122
  132. package/src/prompt/create-tool-model-output.ts +2 -2
  133. package/src/prompt/data-content.ts +1 -78
  134. package/src/prompt/file-part-data.ts +125 -0
  135. package/src/prompt/index.ts +3 -2
  136. package/src/prompt/language-model-call-options.ts +1 -1
  137. package/src/prompt/message-conversion-error.ts +1 -1
  138. package/src/prompt/message.ts +1 -1
  139. package/src/prompt/prepare-language-model-call-options.ts +1 -1
  140. package/src/prompt/prepare-tool-choice.ts +2 -2
  141. package/src/prompt/prepare-tools.ts +2 -2
  142. package/src/prompt/prompt.ts +1 -1
  143. package/src/prompt/standardize-prompt.ts +3 -3
  144. package/src/registry/custom-provider.ts +127 -92
  145. package/src/registry/index.ts +1 -1
  146. package/src/registry/provider-registry.ts +91 -87
  147. package/src/rerank/rerank-result.ts +1 -1
  148. package/src/rerank/rerank.ts +8 -5
  149. package/src/telemetry/create-telemetry-dispatcher.ts +11 -1
  150. package/src/telemetry/diagnostic-channel-publisher.ts +50 -0
  151. package/src/telemetry/diagnostic-channel.ts +24 -0
  152. package/src/telemetry/index.ts +5 -0
  153. package/src/telemetry/telemetry.ts +1 -1
  154. package/src/test/mock-embedding-model-v2.ts +1 -1
  155. package/src/test/mock-embedding-model-v3.ts +1 -1
  156. package/src/test/mock-embedding-model-v4.ts +1 -1
  157. package/src/test/mock-image-model-v2.ts +1 -1
  158. package/src/test/mock-image-model-v3.ts +1 -1
  159. package/src/test/mock-image-model-v4.ts +1 -1
  160. package/src/test/mock-language-model-v2.ts +1 -1
  161. package/src/test/mock-language-model-v3.ts +1 -1
  162. package/src/test/mock-language-model-v4.ts +1 -1
  163. package/src/test/mock-provider-v2.ts +6 -7
  164. package/src/test/mock-provider-v3.ts +7 -8
  165. package/src/test/mock-provider-v4.ts +7 -8
  166. package/src/test/mock-reranking-model-v3.ts +1 -1
  167. package/src/test/mock-reranking-model-v4.ts +1 -1
  168. package/src/test/mock-server-response.ts +1 -1
  169. package/src/test/mock-speech-model-v2.ts +1 -1
  170. package/src/test/mock-speech-model-v3.ts +1 -1
  171. package/src/test/mock-speech-model-v4.ts +1 -1
  172. package/src/test/mock-transcription-model-v2.ts +1 -1
  173. package/src/test/mock-transcription-model-v3.ts +1 -1
  174. package/src/test/mock-transcription-model-v4.ts +1 -1
  175. package/src/test/mock-video-model-v3.ts +1 -1
  176. package/src/test/mock-video-model-v4.ts +1 -1
  177. package/src/text-stream/pipe-text-stream-to-response.ts +1 -1
  178. package/src/transcribe/transcribe-result.ts +3 -3
  179. package/src/transcribe/transcribe.ts +12 -12
  180. package/src/types/embedding-model-middleware.ts +1 -1
  181. package/src/types/embedding-model.ts +1 -1
  182. package/src/types/image-model-middleware.ts +1 -1
  183. package/src/types/image-model.ts +1 -1
  184. package/src/types/json-value.ts +1 -1
  185. package/src/types/language-model-middleware.ts +1 -1
  186. package/src/types/language-model.ts +2 -2
  187. package/src/types/provider-metadata.ts +1 -1
  188. package/src/types/provider-reference.ts +1 -1
  189. package/src/types/provider.ts +4 -4
  190. package/src/types/reranking-model.ts +1 -1
  191. package/src/types/speech-model.ts +5 -1
  192. package/src/types/transcription-model.ts +1 -1
  193. package/src/types/usage.ts +1 -1
  194. package/src/types/video-model.ts +1 -1
  195. package/src/types/warning.ts +1 -1
  196. package/src/ui/call-completion-api.ts +2 -2
  197. package/src/ui/chat-transport.ts +3 -3
  198. package/src/ui/chat.ts +10 -11
  199. package/src/ui/convert-file-list-to-file-ui-parts.ts +1 -1
  200. package/src/ui/convert-to-model-messages.ts +34 -23
  201. package/src/ui/default-chat-transport.ts +4 -4
  202. package/src/ui/direct-chat-transport.ts +6 -6
  203. package/src/ui/http-chat-transport.ts +5 -5
  204. package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +0 -1
  205. package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +0 -1
  206. package/src/ui/process-ui-message-stream.ts +20 -21
  207. package/src/ui/text-stream-chat-transport.ts +3 -3
  208. package/src/ui/transform-text-to-ui-message-stream.ts +1 -1
  209. package/src/ui/ui-messages.ts +13 -6
  210. package/src/ui/use-completion.ts +1 -1
  211. package/src/ui/validate-ui-messages.ts +3 -3
  212. package/src/ui-message-stream/create-ui-message-stream-response.ts +2 -2
  213. package/src/ui-message-stream/create-ui-message-stream.ts +6 -6
  214. package/src/ui-message-stream/get-response-ui-message-id.ts +2 -2
  215. package/src/ui-message-stream/handle-ui-message-stream-finish.ts +6 -6
  216. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -3
  217. package/src/ui-message-stream/read-ui-message-stream.ts +4 -4
  218. package/src/ui-message-stream/ui-message-chunks.ts +4 -4
  219. package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +2 -2
  220. package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +1 -1
  221. package/src/ui-message-stream/ui-message-stream-writer.ts +3 -3
  222. package/src/upload-file/upload-file-result.ts +3 -3
  223. package/src/upload-file/upload-file.ts +34 -56
  224. package/src/upload-skill/upload-skill-result.ts +3 -3
  225. package/src/upload-skill/upload-skill.ts +27 -8
  226. package/src/util/create-resolvable-promise.ts +1 -1
  227. package/src/util/deep-partial.ts +1 -1
  228. package/src/util/download/download.ts +0 -2
  229. package/src/util/extract-literal-union.ts +18 -0
  230. package/src/util/is-node-runtime.ts +3 -0
  231. package/src/util/notify.ts +1 -1
  232. package/src/util/parse-partial-json.ts +1 -1
  233. package/src/util/prepare-retries.ts +1 -2
  234. package/src/util/serial-job-executor.ts +1 -1
  235. package/src/util/write-to-server-response.ts +1 -1
  236. package/src/util/detect-media-type.ts +0 -235
package/dist/index.js CHANGED
@@ -18,7 +18,9 @@ import {
18
18
  } from "@ai-sdk/provider-utils";
19
19
 
20
20
  // src/agent/tool-loop-agent.ts
21
- import { validateTypes as validateTypes3 } from "@ai-sdk/provider-utils";
21
+ import {
22
+ validateTypes as validateTypes3
23
+ } from "@ai-sdk/provider-utils";
22
24
 
23
25
  // src/generate-text/generate-text.ts
24
26
  import {
@@ -1015,258 +1017,23 @@ function getGlobalProvider() {
1015
1017
  // src/prompt/convert-to-language-model-prompt.ts
1016
1018
  import {
1017
1019
  asArray,
1018
- isProviderReference,
1020
+ detectMediaType,
1021
+ isFullMediaType,
1019
1022
  isUrlSupported
1020
1023
  } from "@ai-sdk/provider-utils";
1021
1024
 
1022
- // src/util/detect-media-type.ts
1023
- import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
1024
- var imageMediaTypeSignatures = [
1025
- {
1026
- mediaType: "image/gif",
1027
- bytesPrefix: [71, 73, 70]
1028
- // GIF
1029
- },
1030
- {
1031
- mediaType: "image/png",
1032
- bytesPrefix: [137, 80, 78, 71]
1033
- // PNG
1034
- },
1035
- {
1036
- mediaType: "image/jpeg",
1037
- bytesPrefix: [255, 216]
1038
- // JPEG
1039
- },
1040
- {
1041
- mediaType: "image/webp",
1042
- bytesPrefix: [
1043
- 82,
1044
- 73,
1045
- 70,
1046
- 70,
1047
- // "RIFF"
1048
- null,
1049
- null,
1050
- null,
1051
- null,
1052
- // file size (variable)
1053
- 87,
1054
- 69,
1055
- 66,
1056
- 80
1057
- // "WEBP"
1058
- ]
1059
- },
1060
- {
1061
- mediaType: "image/bmp",
1062
- bytesPrefix: [66, 77]
1063
- },
1064
- {
1065
- mediaType: "image/tiff",
1066
- bytesPrefix: [73, 73, 42, 0]
1067
- },
1068
- {
1069
- mediaType: "image/tiff",
1070
- bytesPrefix: [77, 77, 0, 42]
1071
- },
1072
- {
1073
- mediaType: "image/avif",
1074
- bytesPrefix: [
1075
- 0,
1076
- 0,
1077
- 0,
1078
- 32,
1079
- 102,
1080
- 116,
1081
- 121,
1082
- 112,
1083
- 97,
1084
- 118,
1085
- 105,
1086
- 102
1087
- ]
1088
- },
1089
- {
1090
- mediaType: "image/heic",
1091
- bytesPrefix: [
1092
- 0,
1093
- 0,
1094
- 0,
1095
- 32,
1096
- 102,
1097
- 116,
1098
- 121,
1099
- 112,
1100
- 104,
1101
- 101,
1102
- 105,
1103
- 99
1104
- ]
1105
- }
1106
- ];
1107
- var documentMediaTypeSignatures = [
1108
- {
1109
- mediaType: "application/pdf",
1110
- bytesPrefix: [37, 80, 68, 70]
1111
- // %PDF
1112
- }
1113
- ];
1114
- var audioMediaTypeSignatures = [
1115
- {
1116
- mediaType: "audio/mpeg",
1117
- bytesPrefix: [255, 251]
1118
- },
1119
- {
1120
- mediaType: "audio/mpeg",
1121
- bytesPrefix: [255, 250]
1122
- },
1123
- {
1124
- mediaType: "audio/mpeg",
1125
- bytesPrefix: [255, 243]
1126
- },
1127
- {
1128
- mediaType: "audio/mpeg",
1129
- bytesPrefix: [255, 242]
1130
- },
1131
- {
1132
- mediaType: "audio/mpeg",
1133
- bytesPrefix: [255, 227]
1134
- },
1135
- {
1136
- mediaType: "audio/mpeg",
1137
- bytesPrefix: [255, 226]
1138
- },
1139
- {
1140
- mediaType: "audio/wav",
1141
- bytesPrefix: [
1142
- 82,
1143
- // R
1144
- 73,
1145
- // I
1146
- 70,
1147
- // F
1148
- 70,
1149
- // F
1150
- null,
1151
- null,
1152
- null,
1153
- null,
1154
- 87,
1155
- // W
1156
- 65,
1157
- // A
1158
- 86,
1159
- // V
1160
- 69
1161
- // E
1162
- ]
1163
- },
1164
- {
1165
- mediaType: "audio/ogg",
1166
- bytesPrefix: [79, 103, 103, 83]
1167
- },
1168
- {
1169
- mediaType: "audio/flac",
1170
- bytesPrefix: [102, 76, 97, 67]
1171
- },
1172
- {
1173
- mediaType: "audio/aac",
1174
- bytesPrefix: [64, 21, 0, 0]
1175
- },
1176
- {
1177
- mediaType: "audio/mp4",
1178
- bytesPrefix: [102, 116, 121, 112]
1179
- },
1180
- {
1181
- mediaType: "audio/webm",
1182
- bytesPrefix: [26, 69, 223, 163]
1183
- }
1184
- ];
1185
- var videoMediaTypeSignatures = [
1186
- {
1187
- mediaType: "video/mp4",
1188
- bytesPrefix: [
1189
- 0,
1190
- 0,
1191
- 0,
1192
- null,
1193
- 102,
1194
- 116,
1195
- 121,
1196
- 112
1197
- // ftyp
1198
- ]
1199
- },
1200
- {
1201
- mediaType: "video/webm",
1202
- bytesPrefix: [26, 69, 223, 163]
1203
- // EBML
1204
- },
1205
- {
1206
- mediaType: "video/quicktime",
1207
- bytesPrefix: [
1208
- 0,
1209
- 0,
1210
- 0,
1211
- 20,
1212
- 102,
1213
- 116,
1214
- 121,
1215
- 112,
1216
- 113,
1217
- 116
1218
- // ftypqt
1219
- ]
1220
- },
1221
- {
1222
- mediaType: "video/x-msvideo",
1223
- bytesPrefix: [82, 73, 70, 70]
1224
- // RIFF (AVI)
1225
- }
1226
- ];
1227
- var stripID3 = (data) => {
1228
- const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
1229
- const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
1230
- return bytes.slice(id3Size + 10);
1231
- };
1232
- function stripID3TagsIfPresent(data) {
1233
- const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
1234
- data[1] === 68 && // 'D'
1235
- data[2] === 51;
1236
- return hasId3 ? stripID3(data) : data;
1237
- }
1238
- function detectMediaType({
1239
- data,
1240
- signatures
1241
- }) {
1242
- const processedData = stripID3TagsIfPresent(data);
1243
- const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
1244
- processedData.substring(0, Math.min(processedData.length, 24))
1245
- ) : processedData;
1246
- for (const signature of signatures) {
1247
- if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
1248
- (byte, index) => byte === null || bytes[index] === byte
1249
- )) {
1250
- return signature.mediaType;
1251
- }
1252
- }
1253
- return void 0;
1254
- }
1255
-
1256
1025
  // src/util/download/download.ts
1257
1026
  import {
1258
1027
  DownloadError as DownloadError2,
1259
1028
  readResponseWithSizeLimit,
1260
1029
  DEFAULT_MAX_DOWNLOAD_SIZE,
1261
- validateDownloadUrl
1262
- } from "@ai-sdk/provider-utils";
1263
- import {
1030
+ validateDownloadUrl,
1264
1031
  withUserAgentSuffix,
1265
1032
  getRuntimeEnvironmentUserAgent
1266
1033
  } from "@ai-sdk/provider-utils";
1267
1034
 
1268
1035
  // src/version.ts
1269
- var VERSION = true ? "7.0.0-beta.113" : "0.0.0-test";
1036
+ var VERSION = true ? "7.0.0-beta.115" : "0.0.0-test";
1270
1037
 
1271
1038
  // src/util/download/download.ts
1272
1039
  var download = async ({
@@ -1320,13 +1087,11 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
1320
1087
  )
1321
1088
  );
1322
1089
 
1323
- // src/prompt/data-content.ts
1324
- import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
1090
+ // src/prompt/file-part-data.ts
1325
1091
  import {
1326
- convertBase64ToUint8Array as convertBase64ToUint8Array2,
1327
- convertUint8ArrayToBase64
1092
+ isBuffer,
1093
+ isProviderReference
1328
1094
  } from "@ai-sdk/provider-utils";
1329
- import { z } from "zod/v4";
1330
1095
 
1331
1096
  // src/prompt/split-data-url.ts
1332
1097
  function splitDataUrl(dataUrl) {
@@ -1344,75 +1109,89 @@ function splitDataUrl(dataUrl) {
1344
1109
  }
1345
1110
  }
1346
1111
 
1347
- // src/prompt/data-content.ts
1348
- var dataContentSchema = z.union([
1349
- z.string(),
1350
- z.instanceof(Uint8Array),
1351
- z.instanceof(ArrayBuffer),
1352
- z.custom(
1353
- // Buffer might not be available in some environments such as CloudFlare:
1354
- (value) => {
1355
- var _a21, _b;
1356
- return (_b = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b : false;
1357
- },
1358
- { message: "Must be a Buffer" }
1359
- )
1360
- ]);
1361
- function convertToLanguageModelV4DataContent(content) {
1362
- if (content instanceof Uint8Array) {
1363
- return { data: content, mediaType: void 0 };
1364
- }
1365
- if (content instanceof ArrayBuffer) {
1366
- return { data: new Uint8Array(content), mediaType: void 0 };
1367
- }
1368
- if (typeof content === "string") {
1369
- try {
1370
- content = new URL(content);
1371
- } catch (e) {
1372
- }
1373
- }
1374
- if (content instanceof URL && content.protocol === "data:") {
1375
- const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
1376
- content.toString()
1377
- );
1378
- if (dataUrlMediaType == null || base64Content == null) {
1379
- throw new AISDKError22({
1380
- name: "InvalidDataContentError",
1381
- message: `Invalid data URL format in content ${content.toString()}`
1112
+ // src/prompt/file-part-data.ts
1113
+ function isTaggedFileData(value) {
1114
+ if (typeof value !== "object" || value === null)
1115
+ return false;
1116
+ const type = value.type;
1117
+ return type === "data" || type === "url" || type === "reference" || type === "text";
1118
+ }
1119
+ function convertUrlToFilePartData(url) {
1120
+ if (url.protocol === "data:") {
1121
+ const { mediaType, base64Content } = splitDataUrl(url.toString());
1122
+ if (mediaType == null || base64Content == null) {
1123
+ throw new InvalidDataContentError({
1124
+ content: url,
1125
+ message: `Invalid data URL format in content ${url.toString()}`
1382
1126
  });
1383
1127
  }
1384
- return { data: base64Content, mediaType: dataUrlMediaType };
1128
+ return { data: { type: "data", data: base64Content }, mediaType };
1385
1129
  }
1386
- return { data: content, mediaType: void 0 };
1130
+ return { data: { type: "url", url }, mediaType: void 0 };
1387
1131
  }
1388
- function convertDataContentToBase64String(content) {
1389
- if (typeof content === "string") {
1390
- return content;
1132
+ function convertInlineDataToFilePartData(content) {
1133
+ if (content instanceof Uint8Array) {
1134
+ return { data: { type: "data", data: content }, mediaType: void 0 };
1391
1135
  }
1392
1136
  if (content instanceof ArrayBuffer) {
1393
- return convertUint8ArrayToBase64(new Uint8Array(content));
1137
+ return {
1138
+ data: { type: "data", data: new Uint8Array(content) },
1139
+ mediaType: void 0
1140
+ };
1394
1141
  }
1395
- return convertUint8ArrayToBase64(content);
1142
+ if (isBuffer(content)) {
1143
+ return {
1144
+ data: { type: "data", data: new Uint8Array(content) },
1145
+ mediaType: void 0
1146
+ };
1147
+ }
1148
+ return {
1149
+ data: { type: "data", data: content },
1150
+ mediaType: void 0
1151
+ };
1396
1152
  }
1397
- function convertDataContentToUint8Array(content) {
1398
- if (content instanceof Uint8Array) {
1399
- return content;
1153
+ function convertToLanguageModelV4FilePart(content) {
1154
+ if (isTaggedFileData(content)) {
1155
+ switch (content.type) {
1156
+ case "data":
1157
+ if (typeof content.data === "string" && content.data.startsWith("data:")) {
1158
+ throw new InvalidDataContentError({
1159
+ content: content.data,
1160
+ message: 'Data URLs are not valid inline data. Pass them as { type: "url", url } instead.'
1161
+ });
1162
+ }
1163
+ return convertInlineDataToFilePartData(content.data);
1164
+ case "url":
1165
+ return convertUrlToFilePartData(content.url);
1166
+ case "reference":
1167
+ return {
1168
+ data: { type: "reference", reference: content.reference },
1169
+ mediaType: void 0
1170
+ };
1171
+ case "text":
1172
+ return {
1173
+ data: { type: "text", text: content.text },
1174
+ mediaType: void 0
1175
+ };
1176
+ }
1177
+ }
1178
+ if (content instanceof URL) {
1179
+ return convertUrlToFilePartData(content);
1400
1180
  }
1401
1181
  if (typeof content === "string") {
1402
1182
  try {
1403
- return convertBase64ToUint8Array2(content);
1404
- } catch (error) {
1405
- throw new InvalidDataContentError({
1406
- message: "Invalid data content. Content string is not a base64-encoded media.",
1407
- content,
1408
- cause: error
1409
- });
1183
+ return convertUrlToFilePartData(new URL(content));
1184
+ } catch (e) {
1185
+ return convertInlineDataToFilePartData(content);
1410
1186
  }
1411
1187
  }
1412
- if (content instanceof ArrayBuffer) {
1413
- return new Uint8Array(content);
1188
+ if (isProviderReference(content)) {
1189
+ return {
1190
+ data: { type: "reference", reference: content },
1191
+ mediaType: void 0
1192
+ };
1414
1193
  }
1415
- throw new InvalidDataContentError({ content });
1194
+ return convertInlineDataToFilePartData(content);
1416
1195
  }
1417
1196
 
1418
1197
  // src/prompt/convert-to-language-model-prompt.ts
@@ -1551,7 +1330,16 @@ function convertToLanguageModelMessage({
1551
1330
  }
1552
1331
  const converted = {
1553
1332
  role: "user",
1554
- content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
1333
+ content: message.content.map((part) => {
1334
+ if (part.type === "image") {
1335
+ warnings.push({
1336
+ type: "deprecated",
1337
+ setting: '"image" content part',
1338
+ message: `The "image" content part type is deprecated. Use a "file" part with mediaType: 'image' (or a more specific image/* subtype) instead.`
1339
+ });
1340
+ }
1341
+ return convertImagePartToFilePart(part);
1342
+ }).map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
1555
1343
  providerOptions: message.providerOptions
1556
1344
  };
1557
1345
  if (warnings.length > 0) {
@@ -1585,16 +1373,7 @@ function convertToLanguageModelMessage({
1585
1373
  };
1586
1374
  }
1587
1375
  case "file": {
1588
- if (!(part.data instanceof ArrayBuffer) && isProviderReference(part.data)) {
1589
- return {
1590
- type: "file",
1591
- data: part.data,
1592
- filename: part.filename,
1593
- mediaType: part.mediaType,
1594
- providerOptions
1595
- };
1596
- }
1597
- const { data, mediaType } = convertToLanguageModelV4DataContent(
1376
+ const { data, mediaType } = convertToLanguageModelV4FilePart(
1598
1377
  part.data
1599
1378
  );
1600
1379
  return {
@@ -1613,9 +1392,14 @@ function convertToLanguageModelMessage({
1613
1392
  };
1614
1393
  }
1615
1394
  case "reasoning-file": {
1616
- const { data, mediaType } = convertToLanguageModelV4DataContent(
1395
+ const { data, mediaType } = convertToLanguageModelV4FilePart(
1617
1396
  part.data
1618
1397
  );
1398
+ if (data.type !== "data" && data.type !== "url") {
1399
+ throw new Error(
1400
+ `Unsupported reasoning-file data type: ${data.type}`
1401
+ );
1402
+ }
1619
1403
  return {
1620
1404
  type: "reasoning-file",
1621
1405
  data,
@@ -1706,28 +1490,29 @@ function convertToLanguageModelMessage({
1706
1490
  }
1707
1491
  }
1708
1492
  }
1493
+ function convertImagePartToFilePart(part) {
1494
+ var _a21;
1495
+ if (part.type !== "image") {
1496
+ return part;
1497
+ }
1498
+ return {
1499
+ type: "file",
1500
+ data: part.image,
1501
+ mediaType: (_a21 = part.mediaType) != null ? _a21 : "image",
1502
+ providerOptions: part.providerOptions
1503
+ };
1504
+ }
1709
1505
  async function downloadAssets(messages, download2, supportedUrls) {
1710
1506
  const plannedDownloads = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
1711
1507
  (content) => Array.isArray(content)
1712
- ).flat().filter(
1713
- (part) => part.type === "image" || part.type === "file"
1714
- ).map((part) => {
1715
- var _a21;
1716
- const mediaType = (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : void 0;
1717
- let data = part.type === "image" ? part.image : part.data;
1718
- if (typeof data === "string") {
1719
- try {
1720
- data = new URL(data);
1721
- } catch (e) {
1722
- }
1723
- }
1508
+ ).flat().map((part) => convertImagePartToFilePart(part)).filter((part) => part.type === "file").map((part) => {
1509
+ const mediaType = part.mediaType;
1510
+ const { data } = convertToLanguageModelV4FilePart(part.data);
1724
1511
  return { mediaType, data };
1725
- }).filter(
1726
- (part) => part.data instanceof URL
1727
- ).map((part) => ({
1728
- url: part.data,
1512
+ }).filter((part) => part.data.type === "url").map((part) => ({
1513
+ url: part.data.url,
1729
1514
  isUrlSupportedByModel: part.mediaType != null && isUrlSupported({
1730
- url: part.data.toString(),
1515
+ url: part.data.url.toString(),
1731
1516
  mediaType: part.mediaType,
1732
1517
  supportedUrls
1733
1518
  })
@@ -1743,7 +1528,6 @@ async function downloadAssets(messages, download2, supportedUrls) {
1743
1528
  );
1744
1529
  }
1745
1530
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1746
- var _a21, _b;
1747
1531
  if (part.type === "text") {
1748
1532
  return {
1749
1533
  type: "text",
@@ -1751,55 +1535,37 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1751
1535
  providerOptions: part.providerOptions
1752
1536
  };
1753
1537
  }
1754
- const type = part.type;
1755
- const rawData = type === "image" ? part.image : part.data;
1756
- if (typeof rawData === "object" && !(rawData instanceof Uint8Array) && !(rawData instanceof ArrayBuffer) && !(rawData instanceof URL)) {
1757
- return {
1758
- type: "file",
1759
- mediaType: (_a21 = part.mediaType) != null ? _a21 : type === "image" ? "image/*" : "",
1760
- filename: type === "file" ? part.filename : void 0,
1761
- data: rawData,
1762
- providerOptions: part.providerOptions
1763
- };
1764
- }
1765
- const originalData = rawData;
1766
- const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV4DataContent(originalData);
1767
- let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
1768
- let data = convertedData;
1769
- if (data instanceof URL) {
1770
- const downloadedFile = downloadedAssets[data.toString()];
1538
+ const { data: normalizedData, mediaType: dataUrlMediaType } = convertToLanguageModelV4FilePart(part.data);
1539
+ let mediaType = dataUrlMediaType != null ? dataUrlMediaType : part.mediaType;
1540
+ let data = normalizedData;
1541
+ if (data.type === "url") {
1542
+ const downloadedFile = downloadedAssets[data.url.toString()];
1771
1543
  if (downloadedFile) {
1772
- data = downloadedFile.data;
1773
- mediaType != null ? mediaType : mediaType = downloadedFile.mediaType;
1774
- }
1775
- }
1776
- switch (type) {
1777
- case "image": {
1778
- if (data instanceof Uint8Array || typeof data === "string") {
1779
- mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
1544
+ data = { type: "data", data: downloadedFile.data };
1545
+ if (downloadedFile.mediaType != null && (mediaType == null || !isFullMediaType(mediaType))) {
1546
+ mediaType = downloadedFile.mediaType;
1780
1547
  }
1781
- return {
1782
- type: "file",
1783
- mediaType: mediaType != null ? mediaType : "image/*",
1784
- // any image
1785
- filename: void 0,
1786
- data,
1787
- providerOptions: part.providerOptions
1788
- };
1789
1548
  }
1790
- case "file": {
1791
- if (mediaType == null) {
1792
- throw new Error(`Media type is missing for file part`);
1793
- }
1794
- return {
1795
- type: "file",
1796
- mediaType,
1797
- filename: part.filename,
1798
- data,
1799
- providerOptions: part.providerOptions
1800
- };
1549
+ }
1550
+ if (data.type === "data" && (data.data instanceof Uint8Array || typeof data.data === "string")) {
1551
+ const imageMediaType = detectMediaType({
1552
+ data: data.data,
1553
+ topLevelType: "image"
1554
+ });
1555
+ if (imageMediaType != null) {
1556
+ mediaType = imageMediaType;
1801
1557
  }
1802
1558
  }
1559
+ if (mediaType == null) {
1560
+ throw new Error(`Media type is missing for file part`);
1561
+ }
1562
+ return {
1563
+ type: "file",
1564
+ mediaType,
1565
+ filename: part.filename,
1566
+ data,
1567
+ providerOptions: part.providerOptions
1568
+ };
1803
1569
  }
1804
1570
  function mapToolResultOutput({
1805
1571
  output,
@@ -2163,170 +1929,197 @@ import {
2163
1929
  asArray as asArray2,
2164
1930
  safeValidateTypes
2165
1931
  } from "@ai-sdk/provider-utils";
2166
- import { z as z6 } from "zod/v4";
1932
+ import { z as z5 } from "zod/v4";
2167
1933
 
2168
1934
  // src/prompt/message.ts
2169
- import { z as z5 } from "zod/v4";
1935
+ import { z as z4 } from "zod/v4";
2170
1936
 
2171
1937
  // src/types/provider-metadata.ts
2172
- import { z as z3 } from "zod/v4";
1938
+ import { z as z2 } from "zod/v4";
2173
1939
 
2174
1940
  // src/types/json-value.ts
2175
- import { z as z2 } from "zod/v4";
2176
- var jsonValueSchema = z2.lazy(
2177
- () => z2.union([
2178
- z2.null(),
2179
- z2.string(),
2180
- z2.number(),
2181
- z2.boolean(),
2182
- z2.record(z2.string(), jsonValueSchema.optional()),
2183
- z2.array(jsonValueSchema)
1941
+ import { z } from "zod/v4";
1942
+ var jsonValueSchema = z.lazy(
1943
+ () => z.union([
1944
+ z.null(),
1945
+ z.string(),
1946
+ z.number(),
1947
+ z.boolean(),
1948
+ z.record(z.string(), jsonValueSchema.optional()),
1949
+ z.array(jsonValueSchema)
2184
1950
  ])
2185
1951
  );
2186
1952
 
2187
1953
  // src/types/provider-metadata.ts
2188
- var providerMetadataSchema = z3.record(
2189
- z3.string(),
2190
- z3.record(z3.string(), jsonValueSchema.optional())
1954
+ var providerMetadataSchema = z2.record(
1955
+ z2.string(),
1956
+ z2.record(z2.string(), jsonValueSchema.optional())
2191
1957
  );
2192
1958
 
2193
1959
  // src/prompt/content-part.ts
2194
- import { z as z4 } from "zod/v4";
2195
- var providerReferenceSchema = z4.record(z4.string(), z4.string());
2196
- var textPartSchema = z4.object({
2197
- type: z4.literal("text"),
2198
- text: z4.string(),
1960
+ import {
1961
+ isBuffer as isBuffer2
1962
+ } from "@ai-sdk/provider-utils";
1963
+ import { z as z3 } from "zod/v4";
1964
+ var fileInlineDataSchema = z3.union([
1965
+ z3.string(),
1966
+ z3.instanceof(Uint8Array),
1967
+ z3.instanceof(ArrayBuffer),
1968
+ z3.custom(isBuffer2, { message: "Must be a Buffer" })
1969
+ ]);
1970
+ var providerReferenceSchema = z3.record(z3.string(), z3.string());
1971
+ var textPartSchema = z3.object({
1972
+ type: z3.literal("text"),
1973
+ text: z3.string(),
2199
1974
  providerOptions: providerMetadataSchema.optional()
2200
1975
  });
2201
- var imagePartSchema = z4.object({
2202
- type: z4.literal("image"),
2203
- image: z4.union([
2204
- dataContentSchema,
2205
- z4.instanceof(URL),
1976
+ var imagePartSchema = z3.object({
1977
+ type: z3.literal("image"),
1978
+ image: z3.union([
1979
+ fileInlineDataSchema,
1980
+ z3.instanceof(URL),
2206
1981
  providerReferenceSchema
2207
1982
  ]),
2208
- mediaType: z4.string().optional(),
1983
+ mediaType: z3.string().optional(),
2209
1984
  providerOptions: providerMetadataSchema.optional()
2210
1985
  });
2211
- var filePartSchema = z4.object({
2212
- type: z4.literal("file"),
2213
- data: z4.union([
2214
- dataContentSchema,
2215
- z4.instanceof(URL),
1986
+ var taggedFileDataSchema = z3.discriminatedUnion("type", [
1987
+ z3.object({ type: z3.literal("data"), data: fileInlineDataSchema }),
1988
+ z3.object({ type: z3.literal("url"), url: z3.instanceof(URL) }),
1989
+ z3.object({
1990
+ type: z3.literal("reference"),
1991
+ reference: providerReferenceSchema
1992
+ }),
1993
+ z3.object({ type: z3.literal("text"), text: z3.string() })
1994
+ ]);
1995
+ var taggedReasoningFileDataSchema = z3.discriminatedUnion("type", [
1996
+ z3.object({ type: z3.literal("data"), data: fileInlineDataSchema }),
1997
+ z3.object({ type: z3.literal("url"), url: z3.instanceof(URL) })
1998
+ ]);
1999
+ var filePartSchema = z3.object({
2000
+ type: z3.literal("file"),
2001
+ data: z3.union([
2002
+ taggedFileDataSchema,
2003
+ fileInlineDataSchema,
2004
+ z3.instanceof(URL),
2216
2005
  providerReferenceSchema
2217
2006
  ]),
2218
- filename: z4.string().optional(),
2219
- mediaType: z4.string(),
2007
+ filename: z3.string().optional(),
2008
+ mediaType: z3.string(),
2220
2009
  providerOptions: providerMetadataSchema.optional()
2221
2010
  });
2222
- var reasoningPartSchema = z4.object({
2223
- type: z4.literal("reasoning"),
2224
- text: z4.string(),
2011
+ var reasoningPartSchema = z3.object({
2012
+ type: z3.literal("reasoning"),
2013
+ text: z3.string(),
2225
2014
  providerOptions: providerMetadataSchema.optional()
2226
2015
  });
2227
- var customPartSchema = z4.object({
2228
- type: z4.literal("custom"),
2229
- kind: z4.string().transform((value) => value),
2016
+ var customPartSchema = z3.object({
2017
+ type: z3.literal("custom"),
2018
+ kind: z3.string().transform((value) => value),
2230
2019
  providerOptions: providerMetadataSchema.optional()
2231
2020
  });
2232
- var reasoningFilePartSchema = z4.object({
2233
- type: z4.literal("reasoning-file"),
2234
- data: z4.union([dataContentSchema, z4.instanceof(URL)]),
2235
- mediaType: z4.string(),
2021
+ var reasoningFilePartSchema = z3.object({
2022
+ type: z3.literal("reasoning-file"),
2023
+ data: z3.union([
2024
+ taggedReasoningFileDataSchema,
2025
+ fileInlineDataSchema,
2026
+ z3.instanceof(URL)
2027
+ ]),
2028
+ mediaType: z3.string(),
2236
2029
  providerOptions: providerMetadataSchema.optional()
2237
2030
  });
2238
- var toolCallPartSchema = z4.object({
2239
- type: z4.literal("tool-call"),
2240
- toolCallId: z4.string(),
2241
- toolName: z4.string(),
2242
- input: z4.unknown(),
2031
+ var toolCallPartSchema = z3.object({
2032
+ type: z3.literal("tool-call"),
2033
+ toolCallId: z3.string(),
2034
+ toolName: z3.string(),
2035
+ input: z3.unknown(),
2243
2036
  providerOptions: providerMetadataSchema.optional(),
2244
- providerExecuted: z4.boolean().optional()
2037
+ providerExecuted: z3.boolean().optional()
2245
2038
  });
2246
- var outputSchema = z4.discriminatedUnion(
2039
+ var outputSchema = z3.discriminatedUnion(
2247
2040
  "type",
2248
2041
  [
2249
- z4.object({
2250
- type: z4.literal("text"),
2251
- value: z4.string(),
2042
+ z3.object({
2043
+ type: z3.literal("text"),
2044
+ value: z3.string(),
2252
2045
  providerOptions: providerMetadataSchema.optional()
2253
2046
  }),
2254
- z4.object({
2255
- type: z4.literal("json"),
2047
+ z3.object({
2048
+ type: z3.literal("json"),
2256
2049
  value: jsonValueSchema,
2257
2050
  providerOptions: providerMetadataSchema.optional()
2258
2051
  }),
2259
- z4.object({
2260
- type: z4.literal("execution-denied"),
2261
- reason: z4.string().optional(),
2052
+ z3.object({
2053
+ type: z3.literal("execution-denied"),
2054
+ reason: z3.string().optional(),
2262
2055
  providerOptions: providerMetadataSchema.optional()
2263
2056
  }),
2264
- z4.object({
2265
- type: z4.literal("error-text"),
2266
- value: z4.string(),
2057
+ z3.object({
2058
+ type: z3.literal("error-text"),
2059
+ value: z3.string(),
2267
2060
  providerOptions: providerMetadataSchema.optional()
2268
2061
  }),
2269
- z4.object({
2270
- type: z4.literal("error-json"),
2062
+ z3.object({
2063
+ type: z3.literal("error-json"),
2271
2064
  value: jsonValueSchema,
2272
2065
  providerOptions: providerMetadataSchema.optional()
2273
2066
  }),
2274
- z4.object({
2275
- type: z4.literal("content"),
2276
- value: z4.array(
2277
- z4.union([
2278
- z4.object({
2279
- type: z4.literal("text"),
2280
- text: z4.string(),
2067
+ z3.object({
2068
+ type: z3.literal("content"),
2069
+ value: z3.array(
2070
+ z3.union([
2071
+ z3.object({
2072
+ type: z3.literal("text"),
2073
+ text: z3.string(),
2281
2074
  providerOptions: providerMetadataSchema.optional()
2282
2075
  }),
2283
- z4.object({
2284
- type: z4.literal("file-data"),
2285
- data: z4.string(),
2286
- mediaType: z4.string(),
2287
- filename: z4.string().optional(),
2076
+ z3.object({
2077
+ type: z3.literal("file-data"),
2078
+ data: z3.string(),
2079
+ mediaType: z3.string(),
2080
+ filename: z3.string().optional(),
2288
2081
  providerOptions: providerMetadataSchema.optional()
2289
2082
  }),
2290
- z4.object({
2291
- type: z4.literal("file-url"),
2292
- url: z4.string(),
2083
+ z3.object({
2084
+ type: z3.literal("file-url"),
2085
+ url: z3.string(),
2293
2086
  // Temporarily optional. TODO: make required in v8, after migration period.
2294
- mediaType: z4.string().optional(),
2087
+ mediaType: z3.string().optional(),
2295
2088
  providerOptions: providerMetadataSchema.optional()
2296
2089
  }),
2297
- z4.object({
2298
- type: z4.literal("file-id"),
2299
- fileId: z4.union([z4.string(), z4.record(z4.string(), z4.string())]),
2090
+ z3.object({
2091
+ type: z3.literal("file-id"),
2092
+ fileId: z3.union([z3.string(), z3.record(z3.string(), z3.string())]),
2300
2093
  providerOptions: providerMetadataSchema.optional()
2301
2094
  }),
2302
- z4.object({
2303
- type: z4.literal("file-reference"),
2304
- providerReference: z4.record(z4.string(), z4.string()),
2095
+ z3.object({
2096
+ type: z3.literal("file-reference"),
2097
+ providerReference: z3.record(z3.string(), z3.string()),
2305
2098
  providerOptions: providerMetadataSchema.optional()
2306
2099
  }),
2307
- z4.object({
2308
- type: z4.literal("image-data"),
2309
- data: z4.string(),
2310
- mediaType: z4.string(),
2100
+ z3.object({
2101
+ type: z3.literal("image-data"),
2102
+ data: z3.string(),
2103
+ mediaType: z3.string(),
2311
2104
  providerOptions: providerMetadataSchema.optional()
2312
2105
  }),
2313
- z4.object({
2314
- type: z4.literal("image-url"),
2315
- url: z4.string(),
2106
+ z3.object({
2107
+ type: z3.literal("image-url"),
2108
+ url: z3.string(),
2316
2109
  providerOptions: providerMetadataSchema.optional()
2317
2110
  }),
2318
- z4.object({
2319
- type: z4.literal("image-file-id"),
2320
- fileId: z4.union([z4.string(), z4.record(z4.string(), z4.string())]),
2111
+ z3.object({
2112
+ type: z3.literal("image-file-id"),
2113
+ fileId: z3.union([z3.string(), z3.record(z3.string(), z3.string())]),
2321
2114
  providerOptions: providerMetadataSchema.optional()
2322
2115
  }),
2323
- z4.object({
2324
- type: z4.literal("image-file-reference"),
2325
- providerReference: z4.record(z4.string(), z4.string()),
2116
+ z3.object({
2117
+ type: z3.literal("image-file-reference"),
2118
+ providerReference: z3.record(z3.string(), z3.string()),
2326
2119
  providerOptions: providerMetadataSchema.optional()
2327
2120
  }),
2328
- z4.object({
2329
- type: z4.literal("custom"),
2121
+ z3.object({
2122
+ type: z3.literal("custom"),
2330
2123
  providerOptions: providerMetadataSchema.optional()
2331
2124
  })
2332
2125
  ])
@@ -2334,47 +2127,47 @@ var outputSchema = z4.discriminatedUnion(
2334
2127
  })
2335
2128
  ]
2336
2129
  );
2337
- var toolResultPartSchema = z4.object({
2338
- type: z4.literal("tool-result"),
2339
- toolCallId: z4.string(),
2340
- toolName: z4.string(),
2130
+ var toolResultPartSchema = z3.object({
2131
+ type: z3.literal("tool-result"),
2132
+ toolCallId: z3.string(),
2133
+ toolName: z3.string(),
2341
2134
  output: outputSchema,
2342
2135
  providerOptions: providerMetadataSchema.optional()
2343
2136
  });
2344
- var toolApprovalRequestSchema = z4.object({
2345
- type: z4.literal("tool-approval-request"),
2346
- approvalId: z4.string(),
2347
- toolCallId: z4.string()
2137
+ var toolApprovalRequestSchema = z3.object({
2138
+ type: z3.literal("tool-approval-request"),
2139
+ approvalId: z3.string(),
2140
+ toolCallId: z3.string()
2348
2141
  });
2349
- var toolApprovalResponseSchema = z4.object({
2350
- type: z4.literal("tool-approval-response"),
2351
- approvalId: z4.string(),
2352
- approved: z4.boolean(),
2353
- reason: z4.string().optional()
2142
+ var toolApprovalResponseSchema = z3.object({
2143
+ type: z3.literal("tool-approval-response"),
2144
+ approvalId: z3.string(),
2145
+ approved: z3.boolean(),
2146
+ reason: z3.string().optional()
2354
2147
  });
2355
2148
 
2356
2149
  // src/prompt/message.ts
2357
- var systemModelMessageSchema = z5.object(
2150
+ var systemModelMessageSchema = z4.object(
2358
2151
  {
2359
- role: z5.literal("system"),
2360
- content: z5.string(),
2152
+ role: z4.literal("system"),
2153
+ content: z4.string(),
2361
2154
  providerOptions: providerMetadataSchema.optional()
2362
2155
  }
2363
2156
  );
2364
- var userModelMessageSchema = z5.object({
2365
- role: z5.literal("user"),
2366
- content: z5.union([
2367
- z5.string(),
2368
- z5.array(z5.union([textPartSchema, imagePartSchema, filePartSchema]))
2157
+ var userModelMessageSchema = z4.object({
2158
+ role: z4.literal("user"),
2159
+ content: z4.union([
2160
+ z4.string(),
2161
+ z4.array(z4.union([textPartSchema, imagePartSchema, filePartSchema]))
2369
2162
  ]),
2370
2163
  providerOptions: providerMetadataSchema.optional()
2371
2164
  });
2372
- var assistantModelMessageSchema = z5.object({
2373
- role: z5.literal("assistant"),
2374
- content: z5.union([
2375
- z5.string(),
2376
- z5.array(
2377
- z5.union([
2165
+ var assistantModelMessageSchema = z4.object({
2166
+ role: z4.literal("assistant"),
2167
+ content: z4.union([
2168
+ z4.string(),
2169
+ z4.array(
2170
+ z4.union([
2378
2171
  textPartSchema,
2379
2172
  customPartSchema,
2380
2173
  filePartSchema,
@@ -2388,12 +2181,12 @@ var assistantModelMessageSchema = z5.object({
2388
2181
  ]),
2389
2182
  providerOptions: providerMetadataSchema.optional()
2390
2183
  });
2391
- var toolModelMessageSchema = z5.object({
2392
- role: z5.literal("tool"),
2393
- content: z5.array(z5.union([toolResultPartSchema, toolApprovalResponseSchema])),
2184
+ var toolModelMessageSchema = z4.object({
2185
+ role: z4.literal("tool"),
2186
+ content: z4.array(z4.union([toolResultPartSchema, toolApprovalResponseSchema])),
2394
2187
  providerOptions: providerMetadataSchema.optional()
2395
2188
  });
2396
- var modelMessageSchema = z5.union([
2189
+ var modelMessageSchema = z4.union([
2397
2190
  systemModelMessageSchema,
2398
2191
  userModelMessageSchema,
2399
2192
  assistantModelMessageSchema,
@@ -2449,7 +2242,7 @@ async function standardizePrompt({
2449
2242
  }
2450
2243
  const validationResult = await safeValidateTypes({
2451
2244
  value: messages,
2452
- schema: z6.array(modelMessageSchema)
2245
+ schema: z5.array(modelMessageSchema)
2453
2246
  });
2454
2247
  if (!validationResult.success) {
2455
2248
  throw new InvalidPromptError2({
@@ -2463,14 +2256,14 @@ async function standardizePrompt({
2463
2256
 
2464
2257
  // src/prompt/wrap-gateway-error.ts
2465
2258
  import { GatewayAuthenticationError } from "@ai-sdk/gateway";
2466
- import { AISDKError as AISDKError23 } from "@ai-sdk/provider";
2259
+ import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
2467
2260
  function wrapGatewayError(error) {
2468
2261
  if (!GatewayAuthenticationError.isInstance(error))
2469
2262
  return error;
2470
2263
  const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
2471
2264
  const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
2472
2265
  if (isProductionEnv) {
2473
- return new AISDKError23({
2266
+ return new AISDKError22({
2474
2267
  name: "GatewayError",
2475
2268
  message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
2476
2269
  });
@@ -3001,8 +2794,8 @@ function filterActiveTools({
3001
2794
 
3002
2795
  // src/generate-text/generated-file.ts
3003
2796
  import {
3004
- convertBase64ToUint8Array as convertBase64ToUint8Array3,
3005
- convertUint8ArrayToBase64 as convertUint8ArrayToBase642
2797
+ convertBase64ToUint8Array,
2798
+ convertUint8ArrayToBase64
3006
2799
  } from "@ai-sdk/provider-utils";
3007
2800
  var DefaultGeneratedFile = class {
3008
2801
  constructor({
@@ -3017,14 +2810,14 @@ var DefaultGeneratedFile = class {
3017
2810
  // lazy conversion with caching to avoid unnecessary conversion overhead:
3018
2811
  get base64() {
3019
2812
  if (this.base64Data == null) {
3020
- this.base64Data = convertUint8ArrayToBase642(this.uint8ArrayData);
2813
+ this.base64Data = convertUint8ArrayToBase64(this.uint8ArrayData);
3021
2814
  }
3022
2815
  return this.base64Data;
3023
2816
  }
3024
2817
  // lazy conversion with caching to avoid unnecessary conversion overhead:
3025
2818
  get uint8Array() {
3026
2819
  if (this.uint8ArrayData == null) {
3027
- this.uint8ArrayData = convertBase64ToUint8Array3(this.base64Data);
2820
+ this.uint8ArrayData = convertBase64ToUint8Array(this.base64Data);
3028
2821
  }
3029
2822
  return this.uint8ArrayData;
3030
2823
  }
@@ -3710,6 +3503,15 @@ import {
3710
3503
  safeParseJSON as safeParseJSON3,
3711
3504
  safeValidateTypes as safeValidateTypes3
3712
3505
  } from "@ai-sdk/provider-utils";
3506
+ function mergeToolProviderMetadata(toolMetadata, callMetadata) {
3507
+ if (toolMetadata == null) {
3508
+ return callMetadata;
3509
+ }
3510
+ if (callMetadata == null) {
3511
+ return toolMetadata;
3512
+ }
3513
+ return { ...toolMetadata, ...callMetadata };
3514
+ }
3713
3515
  async function parseToolCall({
3714
3516
  toolCall,
3715
3517
  tools,
@@ -3717,7 +3519,7 @@ async function parseToolCall({
3717
3519
  system,
3718
3520
  messages
3719
3521
  }) {
3720
- var _a21;
3522
+ var _a21, _b;
3721
3523
  try {
3722
3524
  if (tools == null) {
3723
3525
  if (toolCall.providerExecuted && toolCall.dynamic) {
@@ -3768,7 +3570,10 @@ async function parseToolCall({
3768
3570
  error,
3769
3571
  title: (_a21 = tools == null ? void 0 : tools[toolCall.toolName]) == null ? void 0 : _a21.title,
3770
3572
  providerExecuted: toolCall.providerExecuted,
3771
- providerMetadata: toolCall.providerMetadata
3573
+ providerMetadata: mergeToolProviderMetadata(
3574
+ (_b = tools == null ? void 0 : tools[toolCall.toolName]) == null ? void 0 : _b.providerMetadata,
3575
+ toolCall.providerMetadata
3576
+ )
3772
3577
  };
3773
3578
  }
3774
3579
  }
@@ -3815,13 +3620,17 @@ async function doParseToolCall({
3815
3620
  cause: parseResult.error
3816
3621
  });
3817
3622
  }
3623
+ const mergedProviderMetadata = mergeToolProviderMetadata(
3624
+ tool2.providerMetadata,
3625
+ toolCall.providerMetadata
3626
+ );
3818
3627
  return tool2.type === "dynamic" ? {
3819
3628
  type: "tool-call",
3820
3629
  toolCallId: toolCall.toolCallId,
3821
3630
  toolName: toolCall.toolName,
3822
3631
  input: parseResult.value,
3823
3632
  providerExecuted: toolCall.providerExecuted,
3824
- providerMetadata: toolCall.providerMetadata,
3633
+ providerMetadata: mergedProviderMetadata,
3825
3634
  dynamic: true,
3826
3635
  title: tool2.title
3827
3636
  } : {
@@ -3830,12 +3639,18 @@ async function doParseToolCall({
3830
3639
  toolName,
3831
3640
  input: parseResult.value,
3832
3641
  providerExecuted: toolCall.providerExecuted,
3833
- providerMetadata: toolCall.providerMetadata,
3642
+ providerMetadata: mergedProviderMetadata,
3834
3643
  title: tool2.title
3835
3644
  };
3836
3645
  }
3837
3646
 
3838
3647
  // src/generate-text/reasoning-output.ts
3648
+ function unwrapReasoningFileData(data) {
3649
+ if (typeof data === "object" && data !== null && "type" in data) {
3650
+ return data.type === "data" ? data.data : data.url;
3651
+ }
3652
+ return data;
3653
+ }
3839
3654
  function convertFromReasoningOutputs(parts) {
3840
3655
  return parts.map((part) => {
3841
3656
  if (part.type === "reasoning") {
@@ -3862,10 +3677,12 @@ function convertToReasoningOutputs(parts) {
3862
3677
  ...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
3863
3678
  };
3864
3679
  }
3680
+ const rawData = unwrapReasoningFileData(part.data);
3681
+ const fileData = rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData;
3865
3682
  return {
3866
3683
  type: "reasoning-file",
3867
3684
  file: new DefaultGeneratedFile({
3868
- data: part.data instanceof ArrayBuffer ? new Uint8Array(part.data) : part.data instanceof URL ? part.data.toString() : part.data,
3685
+ data: fileData,
3869
3686
  mediaType: part.mediaType
3870
3687
  }),
3871
3688
  ...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
@@ -3887,6 +3704,40 @@ function mergeCallbacks(...callbacks) {
3887
3704
  };
3888
3705
  }
3889
3706
 
3707
+ // src/telemetry/diagnostic-channel.ts
3708
+ var AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL = "aisdk:telemetry";
3709
+
3710
+ // src/util/is-node-runtime.ts
3711
+ function isNodeRuntime() {
3712
+ var _a21;
3713
+ return typeof process !== "undefined" && ((_a21 = process.release) == null ? void 0 : _a21.name) === "node";
3714
+ }
3715
+
3716
+ // src/telemetry/diagnostic-channel-publisher.ts
3717
+ var diagnosticsChannelPromise;
3718
+ async function loadDiagnosticsChannel() {
3719
+ if (!isNodeRuntime()) {
3720
+ return void 0;
3721
+ }
3722
+ if (diagnosticsChannelPromise == null) {
3723
+ diagnosticsChannelPromise = import(
3724
+ /* webpackIgnore: true */
3725
+ "diagnostics_channel"
3726
+ ).catch(() => void 0);
3727
+ }
3728
+ return diagnosticsChannelPromise;
3729
+ }
3730
+ async function publishTelemetryDiagnosticChannelMessage(message) {
3731
+ const diagnosticsChannel = await loadDiagnosticsChannel();
3732
+ if ((diagnosticsChannel == null ? void 0 : diagnosticsChannel.hasSubscribers(AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL)) !== true) {
3733
+ return;
3734
+ }
3735
+ try {
3736
+ diagnosticsChannel.channel(AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL).publish(message);
3737
+ } catch (e) {
3738
+ }
3739
+ }
3740
+
3890
3741
  // src/telemetry/telemetry-registry.ts
3891
3742
  function registerTelemetry(...integrations) {
3892
3743
  if (!globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) {
@@ -3921,7 +3772,12 @@ function createTelemetryDispatcher({
3921
3772
  functionId: telemetry == null ? void 0 : telemetry.functionId
3922
3773
  };
3923
3774
  const mergeTelemetryCallback = (key) => {
3775
+ const publishDiagnosticChannelMessage = (event) => publishTelemetryDiagnosticChannelMessage({
3776
+ type: key,
3777
+ event: augmentEvent(event, telemetryMetadata)
3778
+ });
3924
3779
  return mergeCallbacks(
3780
+ publishDiagnosticChannelMessage,
3925
3781
  ...integrations.map((integration) => {
3926
3782
  var _a21;
3927
3783
  return (_a21 = integration[key]) == null ? void 0 : _a21.bind(integration);
@@ -5199,7 +5055,10 @@ function asContent({
5199
5055
  case "reasoning-file": {
5200
5056
  contentParts.push({
5201
5057
  type: part.type,
5202
- file: new DefaultGeneratedFile(part),
5058
+ file: new DefaultGeneratedFile({
5059
+ data: part.data.type === "data" ? part.data.data : part.data.url.toString(),
5060
+ mediaType: part.mediaType
5061
+ }),
5203
5062
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
5204
5063
  });
5205
5064
  break;
@@ -5466,172 +5325,172 @@ function getResponseUIMessageId({
5466
5325
  import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
5467
5326
 
5468
5327
  // src/ui-message-stream/ui-message-chunks.ts
5469
- import { z as z7 } from "zod/v4";
5328
+ import { z as z6 } from "zod/v4";
5470
5329
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
5471
5330
  var uiMessageChunkSchema = lazySchema(
5472
5331
  () => zodSchema(
5473
- z7.union([
5474
- z7.strictObject({
5475
- type: z7.literal("text-start"),
5476
- id: z7.string(),
5332
+ z6.union([
5333
+ z6.strictObject({
5334
+ type: z6.literal("text-start"),
5335
+ id: z6.string(),
5477
5336
  providerMetadata: providerMetadataSchema.optional()
5478
5337
  }),
5479
- z7.strictObject({
5480
- type: z7.literal("text-delta"),
5481
- id: z7.string(),
5482
- delta: z7.string(),
5338
+ z6.strictObject({
5339
+ type: z6.literal("text-delta"),
5340
+ id: z6.string(),
5341
+ delta: z6.string(),
5483
5342
  providerMetadata: providerMetadataSchema.optional()
5484
5343
  }),
5485
- z7.strictObject({
5486
- type: z7.literal("text-end"),
5487
- id: z7.string(),
5344
+ z6.strictObject({
5345
+ type: z6.literal("text-end"),
5346
+ id: z6.string(),
5488
5347
  providerMetadata: providerMetadataSchema.optional()
5489
5348
  }),
5490
- z7.strictObject({
5491
- type: z7.literal("error"),
5492
- errorText: z7.string()
5349
+ z6.strictObject({
5350
+ type: z6.literal("error"),
5351
+ errorText: z6.string()
5493
5352
  }),
5494
- z7.strictObject({
5495
- type: z7.literal("tool-input-start"),
5496
- toolCallId: z7.string(),
5497
- toolName: z7.string(),
5498
- providerExecuted: z7.boolean().optional(),
5353
+ z6.strictObject({
5354
+ type: z6.literal("tool-input-start"),
5355
+ toolCallId: z6.string(),
5356
+ toolName: z6.string(),
5357
+ providerExecuted: z6.boolean().optional(),
5499
5358
  providerMetadata: providerMetadataSchema.optional(),
5500
- dynamic: z7.boolean().optional(),
5501
- title: z7.string().optional()
5359
+ dynamic: z6.boolean().optional(),
5360
+ title: z6.string().optional()
5502
5361
  }),
5503
- z7.strictObject({
5504
- type: z7.literal("tool-input-delta"),
5505
- toolCallId: z7.string(),
5506
- inputTextDelta: z7.string()
5362
+ z6.strictObject({
5363
+ type: z6.literal("tool-input-delta"),
5364
+ toolCallId: z6.string(),
5365
+ inputTextDelta: z6.string()
5507
5366
  }),
5508
- z7.strictObject({
5509
- type: z7.literal("tool-input-available"),
5510
- toolCallId: z7.string(),
5511
- toolName: z7.string(),
5512
- input: z7.unknown(),
5513
- providerExecuted: z7.boolean().optional(),
5367
+ z6.strictObject({
5368
+ type: z6.literal("tool-input-available"),
5369
+ toolCallId: z6.string(),
5370
+ toolName: z6.string(),
5371
+ input: z6.unknown(),
5372
+ providerExecuted: z6.boolean().optional(),
5514
5373
  providerMetadata: providerMetadataSchema.optional(),
5515
- dynamic: z7.boolean().optional(),
5516
- title: z7.string().optional()
5374
+ dynamic: z6.boolean().optional(),
5375
+ title: z6.string().optional()
5517
5376
  }),
5518
- z7.strictObject({
5519
- type: z7.literal("tool-input-error"),
5520
- toolCallId: z7.string(),
5521
- toolName: z7.string(),
5522
- input: z7.unknown(),
5523
- providerExecuted: z7.boolean().optional(),
5377
+ z6.strictObject({
5378
+ type: z6.literal("tool-input-error"),
5379
+ toolCallId: z6.string(),
5380
+ toolName: z6.string(),
5381
+ input: z6.unknown(),
5382
+ providerExecuted: z6.boolean().optional(),
5524
5383
  providerMetadata: providerMetadataSchema.optional(),
5525
- dynamic: z7.boolean().optional(),
5526
- errorText: z7.string(),
5527
- title: z7.string().optional()
5384
+ dynamic: z6.boolean().optional(),
5385
+ errorText: z6.string(),
5386
+ title: z6.string().optional()
5528
5387
  }),
5529
- z7.strictObject({
5530
- type: z7.literal("tool-approval-request"),
5531
- approvalId: z7.string(),
5532
- toolCallId: z7.string(),
5533
- isAutomatic: z7.boolean().optional()
5388
+ z6.strictObject({
5389
+ type: z6.literal("tool-approval-request"),
5390
+ approvalId: z6.string(),
5391
+ toolCallId: z6.string(),
5392
+ isAutomatic: z6.boolean().optional()
5534
5393
  }),
5535
- z7.strictObject({
5536
- type: z7.literal("tool-approval-response"),
5537
- approvalId: z7.string(),
5538
- approved: z7.boolean(),
5539
- reason: z7.string().optional(),
5540
- providerExecuted: z7.boolean().optional(),
5394
+ z6.strictObject({
5395
+ type: z6.literal("tool-approval-response"),
5396
+ approvalId: z6.string(),
5397
+ approved: z6.boolean(),
5398
+ reason: z6.string().optional(),
5399
+ providerExecuted: z6.boolean().optional(),
5541
5400
  providerMetadata: providerMetadataSchema.optional()
5542
5401
  }),
5543
- z7.strictObject({
5544
- type: z7.literal("tool-output-available"),
5545
- toolCallId: z7.string(),
5546
- output: z7.unknown(),
5547
- providerExecuted: z7.boolean().optional(),
5402
+ z6.strictObject({
5403
+ type: z6.literal("tool-output-available"),
5404
+ toolCallId: z6.string(),
5405
+ output: z6.unknown(),
5406
+ providerExecuted: z6.boolean().optional(),
5548
5407
  providerMetadata: providerMetadataSchema.optional(),
5549
- dynamic: z7.boolean().optional(),
5550
- preliminary: z7.boolean().optional()
5408
+ dynamic: z6.boolean().optional(),
5409
+ preliminary: z6.boolean().optional()
5551
5410
  }),
5552
- z7.strictObject({
5553
- type: z7.literal("tool-output-error"),
5554
- toolCallId: z7.string(),
5555
- errorText: z7.string(),
5556
- providerExecuted: z7.boolean().optional(),
5411
+ z6.strictObject({
5412
+ type: z6.literal("tool-output-error"),
5413
+ toolCallId: z6.string(),
5414
+ errorText: z6.string(),
5415
+ providerExecuted: z6.boolean().optional(),
5557
5416
  providerMetadata: providerMetadataSchema.optional(),
5558
- dynamic: z7.boolean().optional()
5417
+ dynamic: z6.boolean().optional()
5559
5418
  }),
5560
- z7.strictObject({
5561
- type: z7.literal("tool-output-denied"),
5562
- toolCallId: z7.string()
5419
+ z6.strictObject({
5420
+ type: z6.literal("tool-output-denied"),
5421
+ toolCallId: z6.string()
5563
5422
  }),
5564
- z7.strictObject({
5565
- type: z7.literal("reasoning-start"),
5566
- id: z7.string(),
5423
+ z6.strictObject({
5424
+ type: z6.literal("reasoning-start"),
5425
+ id: z6.string(),
5567
5426
  providerMetadata: providerMetadataSchema.optional()
5568
5427
  }),
5569
- z7.strictObject({
5570
- type: z7.literal("reasoning-delta"),
5571
- id: z7.string(),
5572
- delta: z7.string(),
5428
+ z6.strictObject({
5429
+ type: z6.literal("reasoning-delta"),
5430
+ id: z6.string(),
5431
+ delta: z6.string(),
5573
5432
  providerMetadata: providerMetadataSchema.optional()
5574
5433
  }),
5575
- z7.strictObject({
5576
- type: z7.literal("reasoning-end"),
5577
- id: z7.string(),
5434
+ z6.strictObject({
5435
+ type: z6.literal("reasoning-end"),
5436
+ id: z6.string(),
5578
5437
  providerMetadata: providerMetadataSchema.optional()
5579
5438
  }),
5580
- z7.strictObject({
5581
- type: z7.literal("custom"),
5582
- kind: z7.string().transform((value) => value),
5439
+ z6.strictObject({
5440
+ type: z6.literal("custom"),
5441
+ kind: z6.string().transform((value) => value),
5583
5442
  providerMetadata: providerMetadataSchema.optional()
5584
5443
  }),
5585
- z7.strictObject({
5586
- type: z7.literal("source-url"),
5587
- sourceId: z7.string(),
5588
- url: z7.string(),
5589
- title: z7.string().optional(),
5444
+ z6.strictObject({
5445
+ type: z6.literal("source-url"),
5446
+ sourceId: z6.string(),
5447
+ url: z6.string(),
5448
+ title: z6.string().optional(),
5590
5449
  providerMetadata: providerMetadataSchema.optional()
5591
5450
  }),
5592
- z7.strictObject({
5593
- type: z7.literal("source-document"),
5594
- sourceId: z7.string(),
5595
- mediaType: z7.string(),
5596
- title: z7.string(),
5597
- filename: z7.string().optional(),
5451
+ z6.strictObject({
5452
+ type: z6.literal("source-document"),
5453
+ sourceId: z6.string(),
5454
+ mediaType: z6.string(),
5455
+ title: z6.string(),
5456
+ filename: z6.string().optional(),
5598
5457
  providerMetadata: providerMetadataSchema.optional()
5599
5458
  }),
5600
- z7.strictObject({
5601
- type: z7.literal("file"),
5602
- url: z7.string(),
5603
- mediaType: z7.string(),
5459
+ z6.strictObject({
5460
+ type: z6.literal("file"),
5461
+ url: z6.string(),
5462
+ mediaType: z6.string(),
5604
5463
  providerMetadata: providerMetadataSchema.optional()
5605
5464
  }),
5606
- z7.strictObject({
5607
- type: z7.literal("reasoning-file"),
5608
- url: z7.string(),
5609
- mediaType: z7.string(),
5465
+ z6.strictObject({
5466
+ type: z6.literal("reasoning-file"),
5467
+ url: z6.string(),
5468
+ mediaType: z6.string(),
5610
5469
  providerMetadata: providerMetadataSchema.optional()
5611
5470
  }),
5612
- z7.strictObject({
5613
- type: z7.custom(
5471
+ z6.strictObject({
5472
+ type: z6.custom(
5614
5473
  (value) => typeof value === "string" && value.startsWith("data-"),
5615
5474
  { message: 'Type must start with "data-"' }
5616
5475
  ),
5617
- id: z7.string().optional(),
5618
- data: z7.unknown(),
5619
- transient: z7.boolean().optional()
5476
+ id: z6.string().optional(),
5477
+ data: z6.unknown(),
5478
+ transient: z6.boolean().optional()
5620
5479
  }),
5621
- z7.strictObject({
5622
- type: z7.literal("start-step")
5480
+ z6.strictObject({
5481
+ type: z6.literal("start-step")
5623
5482
  }),
5624
- z7.strictObject({
5625
- type: z7.literal("finish-step")
5483
+ z6.strictObject({
5484
+ type: z6.literal("finish-step")
5626
5485
  }),
5627
- z7.strictObject({
5628
- type: z7.literal("start"),
5629
- messageId: z7.string().optional(),
5630
- messageMetadata: z7.unknown().optional()
5486
+ z6.strictObject({
5487
+ type: z6.literal("start"),
5488
+ messageId: z6.string().optional(),
5489
+ messageMetadata: z6.unknown().optional()
5631
5490
  }),
5632
- z7.strictObject({
5633
- type: z7.literal("finish"),
5634
- finishReason: z7.enum([
5491
+ z6.strictObject({
5492
+ type: z6.literal("finish"),
5493
+ finishReason: z6.enum([
5635
5494
  "stop",
5636
5495
  "length",
5637
5496
  "content-filter",
@@ -5639,15 +5498,15 @@ var uiMessageChunkSchema = lazySchema(
5639
5498
  "error",
5640
5499
  "other"
5641
5500
  ]).optional(),
5642
- messageMetadata: z7.unknown().optional()
5501
+ messageMetadata: z6.unknown().optional()
5643
5502
  }),
5644
- z7.strictObject({
5645
- type: z7.literal("abort"),
5646
- reason: z7.string().optional()
5503
+ z6.strictObject({
5504
+ type: z6.literal("abort"),
5505
+ reason: z6.string().optional()
5647
5506
  }),
5648
- z7.strictObject({
5649
- type: z7.literal("message-metadata"),
5650
- messageMetadata: z7.unknown()
5507
+ z6.strictObject({
5508
+ type: z6.literal("message-metadata"),
5509
+ messageMetadata: z6.unknown()
5651
5510
  })
5652
5511
  ])
5653
5512
  )
@@ -6989,7 +6848,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
6989
6848
  case "file":
6990
6849
  case "reasoning-file": {
6991
6850
  const file = new DefaultGeneratedFileWithType({
6992
- data: chunk.data,
6851
+ data: chunk.data.type === "data" ? chunk.data.data : chunk.data.url.toString(),
6993
6852
  mediaType: chunk.mediaType
6994
6853
  });
6995
6854
  modelCallContent.push({
@@ -7903,6 +7762,7 @@ var DefaultStreamTextResult = class {
7903
7762
  toolChoice: (_b2 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _b2 : toolChoice,
7904
7763
  system: stepSystem,
7905
7764
  messages: stepMessages,
7765
+ allowSystemInMessages,
7906
7766
  repairToolCall,
7907
7767
  abortSignal,
7908
7768
  headers,
@@ -9072,7 +8932,7 @@ async function convertToModelMessages(messages, options) {
9072
8932
  modelMessages.push({
9073
8933
  role: "user",
9074
8934
  content: message.parts.map((part) => {
9075
- var _a21, _b;
8935
+ var _a21;
9076
8936
  if (isTextUIPart(part)) {
9077
8937
  return {
9078
8938
  type: "text",
@@ -9085,12 +8945,15 @@ async function convertToModelMessages(messages, options) {
9085
8945
  type: "file",
9086
8946
  mediaType: part.mediaType,
9087
8947
  filename: part.filename,
9088
- data: (_a21 = part.providerReference) != null ? _a21 : part.url,
8948
+ data: part.providerReference != null ? {
8949
+ type: "reference",
8950
+ reference: part.providerReference
8951
+ } : { type: "url", url: new URL(part.url) },
9089
8952
  ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
9090
8953
  };
9091
8954
  }
9092
8955
  if (isDataUIPart(part)) {
9093
- return (_b = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _b.call(
8956
+ return (_a21 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a21.call(
9094
8957
  options,
9095
8958
  part
9096
8959
  );
@@ -9103,7 +8966,7 @@ async function convertToModelMessages(messages, options) {
9103
8966
  if (message.parts != null) {
9104
8967
  let block = [];
9105
8968
  async function processBlock() {
9106
- var _a21, _b, _c, _d, _e, _f, _g, _h, _i;
8969
+ var _a21, _b, _c, _d, _e, _f, _g, _h;
9107
8970
  if (block.length === 0) {
9108
8971
  return;
9109
8972
  }
@@ -9126,13 +8989,16 @@ async function convertToModelMessages(messages, options) {
9126
8989
  type: "file",
9127
8990
  mediaType: part.mediaType,
9128
8991
  filename: part.filename,
9129
- data: (_a21 = part.providerReference) != null ? _a21 : part.url,
8992
+ data: part.providerReference != null ? {
8993
+ type: "reference",
8994
+ reference: part.providerReference
8995
+ } : { type: "url", url: new URL(part.url) },
9130
8996
  ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
9131
8997
  });
9132
8998
  } else if (isReasoningFileUIPart(part)) {
9133
8999
  content.push({
9134
9000
  type: "reasoning-file",
9135
- data: part.url,
9001
+ data: { type: "url", url: new URL(part.url) },
9136
9002
  mediaType: part.mediaType,
9137
9003
  providerOptions: part.providerMetadata
9138
9004
  });
@@ -9149,7 +9015,7 @@ async function convertToModelMessages(messages, options) {
9149
9015
  type: "tool-call",
9150
9016
  toolCallId: part.toolCallId,
9151
9017
  toolName,
9152
- input: part.state === "output-error" ? (_b = part.input) != null ? _b : "rawInput" in part ? part.rawInput : void 0 : part.input,
9018
+ input: part.state === "output-error" ? (_a21 = part.input) != null ? _a21 : "rawInput" in part ? part.rawInput : void 0 : part.input,
9153
9019
  providerExecuted: part.providerExecuted,
9154
9020
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
9155
9021
  });
@@ -9162,7 +9028,7 @@ async function convertToModelMessages(messages, options) {
9162
9028
  });
9163
9029
  }
9164
9030
  if (part.providerExecuted === true && part.state !== "approval-responded" && (part.state === "output-available" || part.state === "output-error")) {
9165
- const resultProviderMetadata = (_c = part.resultProviderMetadata) != null ? _c : part.callProviderMetadata;
9031
+ const resultProviderMetadata = (_b = part.resultProviderMetadata) != null ? _b : part.callProviderMetadata;
9166
9032
  content.push({
9167
9033
  type: "tool-result",
9168
9034
  toolCallId: part.toolCallId,
@@ -9171,7 +9037,7 @@ async function convertToModelMessages(messages, options) {
9171
9037
  toolCallId: part.toolCallId,
9172
9038
  input: part.input,
9173
9039
  output: part.state === "output-error" ? part.errorText : part.output,
9174
- tool: (_d = options == null ? void 0 : options.tools) == null ? void 0 : _d[toolName],
9040
+ tool: (_c = options == null ? void 0 : options.tools) == null ? void 0 : _c[toolName],
9175
9041
  errorMode: part.state === "output-error" ? "json" : "none"
9176
9042
  }),
9177
9043
  ...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
@@ -9179,7 +9045,7 @@ async function convertToModelMessages(messages, options) {
9179
9045
  }
9180
9046
  }
9181
9047
  } else if (isDataUIPart(part)) {
9182
- const dataPart = (_e = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _e.call(
9048
+ const dataPart = (_d = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _d.call(
9183
9049
  options,
9184
9050
  part
9185
9051
  );
@@ -9205,7 +9071,7 @@ async function convertToModelMessages(messages, options) {
9205
9071
  {
9206
9072
  const content2 = [];
9207
9073
  for (const toolPart of toolParts) {
9208
- if (((_f = toolPart.approval) == null ? void 0 : _f.approved) != null) {
9074
+ if (((_e = toolPart.approval) == null ? void 0 : _e.approved) != null) {
9209
9075
  content2.push({
9210
9076
  type: "tool-approval-response",
9211
9077
  approvalId: toolPart.approval.id,
@@ -9214,7 +9080,7 @@ async function convertToModelMessages(messages, options) {
9214
9080
  providerExecuted: toolPart.providerExecuted
9215
9081
  });
9216
9082
  }
9217
- if (toolPart.state === "approval-responded" && ((_g = toolPart.approval) == null ? void 0 : _g.approved) === false) {
9083
+ if (toolPart.state === "approval-responded" && ((_f = toolPart.approval) == null ? void 0 : _f.approved) === false) {
9218
9084
  content2.push({
9219
9085
  type: "tool-result",
9220
9086
  toolCallId: toolPart.toolCallId,
@@ -9237,7 +9103,7 @@ async function convertToModelMessages(messages, options) {
9237
9103
  toolName: getToolName(toolPart),
9238
9104
  output: {
9239
9105
  type: "error-text",
9240
- value: (_h = toolPart.approval.reason) != null ? _h : "Tool call execution denied."
9106
+ value: (_g = toolPart.approval.reason) != null ? _g : "Tool call execution denied."
9241
9107
  },
9242
9108
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
9243
9109
  });
@@ -9254,7 +9120,7 @@ async function convertToModelMessages(messages, options) {
9254
9120
  toolCallId: toolPart.toolCallId,
9255
9121
  input: toolPart.input,
9256
9122
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
9257
- tool: (_i = options == null ? void 0 : options.tools) == null ? void 0 : _i[toolName],
9123
+ tool: (_h = options == null ? void 0 : options.tools) == null ? void 0 : _h[toolName],
9258
9124
  errorMode: toolPart.state === "output-error" ? "text" : "none"
9259
9125
  }),
9260
9126
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
@@ -9304,286 +9170,286 @@ import {
9304
9170
  validateTypes as validateTypes4,
9305
9171
  zodSchema as zodSchema2
9306
9172
  } from "@ai-sdk/provider-utils";
9307
- import { z as z8 } from "zod/v4";
9173
+ import { z as z7 } from "zod/v4";
9308
9174
  var uiMessagesSchema = lazySchema2(
9309
9175
  () => zodSchema2(
9310
- z8.array(
9311
- z8.object({
9312
- id: z8.string(),
9313
- role: z8.enum(["system", "user", "assistant"]),
9314
- metadata: z8.unknown().optional(),
9315
- parts: z8.array(
9316
- z8.union([
9317
- z8.object({
9318
- type: z8.literal("text"),
9319
- text: z8.string(),
9320
- state: z8.enum(["streaming", "done"]).optional(),
9176
+ z7.array(
9177
+ z7.object({
9178
+ id: z7.string(),
9179
+ role: z7.enum(["system", "user", "assistant"]),
9180
+ metadata: z7.unknown().optional(),
9181
+ parts: z7.array(
9182
+ z7.union([
9183
+ z7.object({
9184
+ type: z7.literal("text"),
9185
+ text: z7.string(),
9186
+ state: z7.enum(["streaming", "done"]).optional(),
9321
9187
  providerMetadata: providerMetadataSchema.optional()
9322
9188
  }),
9323
- z8.object({
9324
- type: z8.literal("reasoning"),
9325
- text: z8.string(),
9326
- state: z8.enum(["streaming", "done"]).optional(),
9189
+ z7.object({
9190
+ type: z7.literal("reasoning"),
9191
+ text: z7.string(),
9192
+ state: z7.enum(["streaming", "done"]).optional(),
9327
9193
  providerMetadata: providerMetadataSchema.optional()
9328
9194
  }),
9329
- z8.object({
9330
- type: z8.literal("custom"),
9331
- kind: z8.string(),
9195
+ z7.object({
9196
+ type: z7.literal("custom"),
9197
+ kind: z7.string(),
9332
9198
  providerMetadata: providerMetadataSchema.optional()
9333
9199
  }),
9334
- z8.object({
9335
- type: z8.literal("source-url"),
9336
- sourceId: z8.string(),
9337
- url: z8.string(),
9338
- title: z8.string().optional(),
9200
+ z7.object({
9201
+ type: z7.literal("source-url"),
9202
+ sourceId: z7.string(),
9203
+ url: z7.string(),
9204
+ title: z7.string().optional(),
9339
9205
  providerMetadata: providerMetadataSchema.optional()
9340
9206
  }),
9341
- z8.object({
9342
- type: z8.literal("source-document"),
9343
- sourceId: z8.string(),
9344
- mediaType: z8.string(),
9345
- title: z8.string(),
9346
- filename: z8.string().optional(),
9207
+ z7.object({
9208
+ type: z7.literal("source-document"),
9209
+ sourceId: z7.string(),
9210
+ mediaType: z7.string(),
9211
+ title: z7.string(),
9212
+ filename: z7.string().optional(),
9347
9213
  providerMetadata: providerMetadataSchema.optional()
9348
9214
  }),
9349
- z8.object({
9350
- type: z8.literal("file"),
9351
- mediaType: z8.string(),
9352
- filename: z8.string().optional(),
9353
- url: z8.string(),
9215
+ z7.object({
9216
+ type: z7.literal("file"),
9217
+ mediaType: z7.string(),
9218
+ filename: z7.string().optional(),
9219
+ url: z7.string(),
9354
9220
  providerMetadata: providerMetadataSchema.optional()
9355
9221
  }),
9356
- z8.object({
9357
- type: z8.literal("reasoning-file"),
9358
- mediaType: z8.string(),
9359
- url: z8.string(),
9222
+ z7.object({
9223
+ type: z7.literal("reasoning-file"),
9224
+ mediaType: z7.string(),
9225
+ url: z7.string(),
9360
9226
  providerMetadata: providerMetadataSchema.optional()
9361
9227
  }),
9362
- z8.object({
9363
- type: z8.literal("step-start")
9228
+ z7.object({
9229
+ type: z7.literal("step-start")
9364
9230
  }),
9365
- z8.object({
9366
- type: z8.string().startsWith("data-"),
9367
- id: z8.string().optional(),
9368
- data: z8.unknown()
9231
+ z7.object({
9232
+ type: z7.string().startsWith("data-"),
9233
+ id: z7.string().optional(),
9234
+ data: z7.unknown()
9369
9235
  }),
9370
- z8.object({
9371
- type: z8.literal("dynamic-tool"),
9372
- toolName: z8.string(),
9373
- toolCallId: z8.string(),
9374
- state: z8.literal("input-streaming"),
9375
- input: z8.unknown().optional(),
9376
- providerExecuted: z8.boolean().optional(),
9236
+ z7.object({
9237
+ type: z7.literal("dynamic-tool"),
9238
+ toolName: z7.string(),
9239
+ toolCallId: z7.string(),
9240
+ state: z7.literal("input-streaming"),
9241
+ input: z7.unknown().optional(),
9242
+ providerExecuted: z7.boolean().optional(),
9377
9243
  callProviderMetadata: providerMetadataSchema.optional(),
9378
- output: z8.never().optional(),
9379
- errorText: z8.never().optional(),
9380
- approval: z8.never().optional()
9244
+ output: z7.never().optional(),
9245
+ errorText: z7.never().optional(),
9246
+ approval: z7.never().optional()
9381
9247
  }),
9382
- z8.object({
9383
- type: z8.literal("dynamic-tool"),
9384
- toolName: z8.string(),
9385
- toolCallId: z8.string(),
9386
- state: z8.literal("input-available"),
9387
- input: z8.unknown(),
9388
- providerExecuted: z8.boolean().optional(),
9389
- output: z8.never().optional(),
9390
- errorText: z8.never().optional(),
9248
+ z7.object({
9249
+ type: z7.literal("dynamic-tool"),
9250
+ toolName: z7.string(),
9251
+ toolCallId: z7.string(),
9252
+ state: z7.literal("input-available"),
9253
+ input: z7.unknown(),
9254
+ providerExecuted: z7.boolean().optional(),
9255
+ output: z7.never().optional(),
9256
+ errorText: z7.never().optional(),
9391
9257
  callProviderMetadata: providerMetadataSchema.optional(),
9392
- approval: z8.never().optional()
9258
+ approval: z7.never().optional()
9393
9259
  }),
9394
- z8.object({
9395
- type: z8.literal("dynamic-tool"),
9396
- toolName: z8.string(),
9397
- toolCallId: z8.string(),
9398
- state: z8.literal("approval-requested"),
9399
- input: z8.unknown(),
9400
- providerExecuted: z8.boolean().optional(),
9401
- output: z8.never().optional(),
9402
- errorText: z8.never().optional(),
9260
+ z7.object({
9261
+ type: z7.literal("dynamic-tool"),
9262
+ toolName: z7.string(),
9263
+ toolCallId: z7.string(),
9264
+ state: z7.literal("approval-requested"),
9265
+ input: z7.unknown(),
9266
+ providerExecuted: z7.boolean().optional(),
9267
+ output: z7.never().optional(),
9268
+ errorText: z7.never().optional(),
9403
9269
  callProviderMetadata: providerMetadataSchema.optional(),
9404
- approval: z8.object({
9405
- id: z8.string(),
9406
- approved: z8.never().optional(),
9407
- reason: z8.never().optional(),
9408
- isAutomatic: z8.boolean().optional()
9270
+ approval: z7.object({
9271
+ id: z7.string(),
9272
+ approved: z7.never().optional(),
9273
+ reason: z7.never().optional(),
9274
+ isAutomatic: z7.boolean().optional()
9409
9275
  })
9410
9276
  }),
9411
- z8.object({
9412
- type: z8.literal("dynamic-tool"),
9413
- toolName: z8.string(),
9414
- toolCallId: z8.string(),
9415
- state: z8.literal("approval-responded"),
9416
- input: z8.unknown(),
9417
- providerExecuted: z8.boolean().optional(),
9418
- output: z8.never().optional(),
9419
- errorText: z8.never().optional(),
9277
+ z7.object({
9278
+ type: z7.literal("dynamic-tool"),
9279
+ toolName: z7.string(),
9280
+ toolCallId: z7.string(),
9281
+ state: z7.literal("approval-responded"),
9282
+ input: z7.unknown(),
9283
+ providerExecuted: z7.boolean().optional(),
9284
+ output: z7.never().optional(),
9285
+ errorText: z7.never().optional(),
9420
9286
  callProviderMetadata: providerMetadataSchema.optional(),
9421
- approval: z8.object({
9422
- id: z8.string(),
9423
- approved: z8.boolean(),
9424
- reason: z8.string().optional(),
9425
- isAutomatic: z8.boolean().optional()
9287
+ approval: z7.object({
9288
+ id: z7.string(),
9289
+ approved: z7.boolean(),
9290
+ reason: z7.string().optional(),
9291
+ isAutomatic: z7.boolean().optional()
9426
9292
  })
9427
9293
  }),
9428
- z8.object({
9429
- type: z8.literal("dynamic-tool"),
9430
- toolName: z8.string(),
9431
- toolCallId: z8.string(),
9432
- state: z8.literal("output-available"),
9433
- input: z8.unknown(),
9434
- providerExecuted: z8.boolean().optional(),
9435
- output: z8.unknown(),
9436
- errorText: z8.never().optional(),
9294
+ z7.object({
9295
+ type: z7.literal("dynamic-tool"),
9296
+ toolName: z7.string(),
9297
+ toolCallId: z7.string(),
9298
+ state: z7.literal("output-available"),
9299
+ input: z7.unknown(),
9300
+ providerExecuted: z7.boolean().optional(),
9301
+ output: z7.unknown(),
9302
+ errorText: z7.never().optional(),
9437
9303
  callProviderMetadata: providerMetadataSchema.optional(),
9438
9304
  resultProviderMetadata: providerMetadataSchema.optional(),
9439
- preliminary: z8.boolean().optional(),
9440
- approval: z8.object({
9441
- id: z8.string(),
9442
- approved: z8.literal(true),
9443
- reason: z8.string().optional(),
9444
- isAutomatic: z8.boolean().optional()
9305
+ preliminary: z7.boolean().optional(),
9306
+ approval: z7.object({
9307
+ id: z7.string(),
9308
+ approved: z7.literal(true),
9309
+ reason: z7.string().optional(),
9310
+ isAutomatic: z7.boolean().optional()
9445
9311
  }).optional()
9446
9312
  }),
9447
- z8.object({
9448
- type: z8.literal("dynamic-tool"),
9449
- toolName: z8.string(),
9450
- toolCallId: z8.string(),
9451
- state: z8.literal("output-error"),
9452
- input: z8.unknown(),
9453
- rawInput: z8.unknown().optional(),
9454
- providerExecuted: z8.boolean().optional(),
9455
- output: z8.never().optional(),
9456
- errorText: z8.string(),
9313
+ z7.object({
9314
+ type: z7.literal("dynamic-tool"),
9315
+ toolName: z7.string(),
9316
+ toolCallId: z7.string(),
9317
+ state: z7.literal("output-error"),
9318
+ input: z7.unknown(),
9319
+ rawInput: z7.unknown().optional(),
9320
+ providerExecuted: z7.boolean().optional(),
9321
+ output: z7.never().optional(),
9322
+ errorText: z7.string(),
9457
9323
  callProviderMetadata: providerMetadataSchema.optional(),
9458
9324
  resultProviderMetadata: providerMetadataSchema.optional(),
9459
- approval: z8.object({
9460
- id: z8.string(),
9461
- approved: z8.literal(true),
9462
- reason: z8.string().optional(),
9463
- isAutomatic: z8.boolean().optional()
9325
+ approval: z7.object({
9326
+ id: z7.string(),
9327
+ approved: z7.literal(true),
9328
+ reason: z7.string().optional(),
9329
+ isAutomatic: z7.boolean().optional()
9464
9330
  }).optional()
9465
9331
  }),
9466
- z8.object({
9467
- type: z8.literal("dynamic-tool"),
9468
- toolName: z8.string(),
9469
- toolCallId: z8.string(),
9470
- state: z8.literal("output-denied"),
9471
- input: z8.unknown(),
9472
- providerExecuted: z8.boolean().optional(),
9473
- output: z8.never().optional(),
9474
- errorText: z8.never().optional(),
9332
+ z7.object({
9333
+ type: z7.literal("dynamic-tool"),
9334
+ toolName: z7.string(),
9335
+ toolCallId: z7.string(),
9336
+ state: z7.literal("output-denied"),
9337
+ input: z7.unknown(),
9338
+ providerExecuted: z7.boolean().optional(),
9339
+ output: z7.never().optional(),
9340
+ errorText: z7.never().optional(),
9475
9341
  callProviderMetadata: providerMetadataSchema.optional(),
9476
- approval: z8.object({
9477
- id: z8.string(),
9478
- approved: z8.literal(false),
9479
- reason: z8.string().optional(),
9480
- isAutomatic: z8.boolean().optional()
9342
+ approval: z7.object({
9343
+ id: z7.string(),
9344
+ approved: z7.literal(false),
9345
+ reason: z7.string().optional(),
9346
+ isAutomatic: z7.boolean().optional()
9481
9347
  })
9482
9348
  }),
9483
- z8.object({
9484
- type: z8.string().startsWith("tool-"),
9485
- toolCallId: z8.string(),
9486
- state: z8.literal("input-streaming"),
9487
- providerExecuted: z8.boolean().optional(),
9349
+ z7.object({
9350
+ type: z7.string().startsWith("tool-"),
9351
+ toolCallId: z7.string(),
9352
+ state: z7.literal("input-streaming"),
9353
+ providerExecuted: z7.boolean().optional(),
9488
9354
  callProviderMetadata: providerMetadataSchema.optional(),
9489
- input: z8.unknown().optional(),
9490
- output: z8.never().optional(),
9491
- errorText: z8.never().optional(),
9492
- approval: z8.never().optional()
9355
+ input: z7.unknown().optional(),
9356
+ output: z7.never().optional(),
9357
+ errorText: z7.never().optional(),
9358
+ approval: z7.never().optional()
9493
9359
  }),
9494
- z8.object({
9495
- type: z8.string().startsWith("tool-"),
9496
- toolCallId: z8.string(),
9497
- state: z8.literal("input-available"),
9498
- providerExecuted: z8.boolean().optional(),
9499
- input: z8.unknown(),
9500
- output: z8.never().optional(),
9501
- errorText: z8.never().optional(),
9360
+ z7.object({
9361
+ type: z7.string().startsWith("tool-"),
9362
+ toolCallId: z7.string(),
9363
+ state: z7.literal("input-available"),
9364
+ providerExecuted: z7.boolean().optional(),
9365
+ input: z7.unknown(),
9366
+ output: z7.never().optional(),
9367
+ errorText: z7.never().optional(),
9502
9368
  callProviderMetadata: providerMetadataSchema.optional(),
9503
- approval: z8.never().optional()
9369
+ approval: z7.never().optional()
9504
9370
  }),
9505
- z8.object({
9506
- type: z8.string().startsWith("tool-"),
9507
- toolCallId: z8.string(),
9508
- state: z8.literal("approval-requested"),
9509
- input: z8.unknown(),
9510
- providerExecuted: z8.boolean().optional(),
9511
- output: z8.never().optional(),
9512
- errorText: z8.never().optional(),
9371
+ z7.object({
9372
+ type: z7.string().startsWith("tool-"),
9373
+ toolCallId: z7.string(),
9374
+ state: z7.literal("approval-requested"),
9375
+ input: z7.unknown(),
9376
+ providerExecuted: z7.boolean().optional(),
9377
+ output: z7.never().optional(),
9378
+ errorText: z7.never().optional(),
9513
9379
  callProviderMetadata: providerMetadataSchema.optional(),
9514
- approval: z8.object({
9515
- id: z8.string(),
9516
- approved: z8.never().optional(),
9517
- reason: z8.never().optional(),
9518
- isAutomatic: z8.boolean().optional()
9380
+ approval: z7.object({
9381
+ id: z7.string(),
9382
+ approved: z7.never().optional(),
9383
+ reason: z7.never().optional(),
9384
+ isAutomatic: z7.boolean().optional()
9519
9385
  })
9520
9386
  }),
9521
- z8.object({
9522
- type: z8.string().startsWith("tool-"),
9523
- toolCallId: z8.string(),
9524
- state: z8.literal("approval-responded"),
9525
- input: z8.unknown(),
9526
- providerExecuted: z8.boolean().optional(),
9527
- output: z8.never().optional(),
9528
- errorText: z8.never().optional(),
9387
+ z7.object({
9388
+ type: z7.string().startsWith("tool-"),
9389
+ toolCallId: z7.string(),
9390
+ state: z7.literal("approval-responded"),
9391
+ input: z7.unknown(),
9392
+ providerExecuted: z7.boolean().optional(),
9393
+ output: z7.never().optional(),
9394
+ errorText: z7.never().optional(),
9529
9395
  callProviderMetadata: providerMetadataSchema.optional(),
9530
- approval: z8.object({
9531
- id: z8.string(),
9532
- approved: z8.boolean(),
9533
- reason: z8.string().optional(),
9534
- isAutomatic: z8.boolean().optional()
9396
+ approval: z7.object({
9397
+ id: z7.string(),
9398
+ approved: z7.boolean(),
9399
+ reason: z7.string().optional(),
9400
+ isAutomatic: z7.boolean().optional()
9535
9401
  })
9536
9402
  }),
9537
- z8.object({
9538
- type: z8.string().startsWith("tool-"),
9539
- toolCallId: z8.string(),
9540
- state: z8.literal("output-available"),
9541
- providerExecuted: z8.boolean().optional(),
9542
- input: z8.unknown(),
9543
- output: z8.unknown(),
9544
- errorText: z8.never().optional(),
9403
+ z7.object({
9404
+ type: z7.string().startsWith("tool-"),
9405
+ toolCallId: z7.string(),
9406
+ state: z7.literal("output-available"),
9407
+ providerExecuted: z7.boolean().optional(),
9408
+ input: z7.unknown(),
9409
+ output: z7.unknown(),
9410
+ errorText: z7.never().optional(),
9545
9411
  callProviderMetadata: providerMetadataSchema.optional(),
9546
9412
  resultProviderMetadata: providerMetadataSchema.optional(),
9547
- preliminary: z8.boolean().optional(),
9548
- approval: z8.object({
9549
- id: z8.string(),
9550
- approved: z8.literal(true),
9551
- reason: z8.string().optional(),
9552
- isAutomatic: z8.boolean().optional()
9413
+ preliminary: z7.boolean().optional(),
9414
+ approval: z7.object({
9415
+ id: z7.string(),
9416
+ approved: z7.literal(true),
9417
+ reason: z7.string().optional(),
9418
+ isAutomatic: z7.boolean().optional()
9553
9419
  }).optional()
9554
9420
  }),
9555
- z8.object({
9556
- type: z8.string().startsWith("tool-"),
9557
- toolCallId: z8.string(),
9558
- state: z8.literal("output-error"),
9559
- providerExecuted: z8.boolean().optional(),
9560
- input: z8.unknown(),
9561
- rawInput: z8.unknown().optional(),
9562
- output: z8.never().optional(),
9563
- errorText: z8.string(),
9421
+ z7.object({
9422
+ type: z7.string().startsWith("tool-"),
9423
+ toolCallId: z7.string(),
9424
+ state: z7.literal("output-error"),
9425
+ providerExecuted: z7.boolean().optional(),
9426
+ input: z7.unknown(),
9427
+ rawInput: z7.unknown().optional(),
9428
+ output: z7.never().optional(),
9429
+ errorText: z7.string(),
9564
9430
  callProviderMetadata: providerMetadataSchema.optional(),
9565
9431
  resultProviderMetadata: providerMetadataSchema.optional(),
9566
- approval: z8.object({
9567
- id: z8.string(),
9568
- approved: z8.literal(true),
9569
- reason: z8.string().optional(),
9570
- isAutomatic: z8.boolean().optional()
9432
+ approval: z7.object({
9433
+ id: z7.string(),
9434
+ approved: z7.literal(true),
9435
+ reason: z7.string().optional(),
9436
+ isAutomatic: z7.boolean().optional()
9571
9437
  }).optional()
9572
9438
  }),
9573
- z8.object({
9574
- type: z8.string().startsWith("tool-"),
9575
- toolCallId: z8.string(),
9576
- state: z8.literal("output-denied"),
9577
- providerExecuted: z8.boolean().optional(),
9578
- input: z8.unknown(),
9579
- output: z8.never().optional(),
9580
- errorText: z8.never().optional(),
9439
+ z7.object({
9440
+ type: z7.string().startsWith("tool-"),
9441
+ toolCallId: z7.string(),
9442
+ state: z7.literal("output-denied"),
9443
+ providerExecuted: z7.boolean().optional(),
9444
+ input: z7.unknown(),
9445
+ output: z7.never().optional(),
9446
+ errorText: z7.never().optional(),
9581
9447
  callProviderMetadata: providerMetadataSchema.optional(),
9582
- approval: z8.object({
9583
- id: z8.string(),
9584
- approved: z8.literal(false),
9585
- reason: z8.string().optional(),
9586
- isAutomatic: z8.boolean().optional()
9448
+ approval: z7.object({
9449
+ id: z7.string(),
9450
+ approved: z7.literal(false),
9451
+ reason: z7.string().optional(),
9452
+ isAutomatic: z7.boolean().optional()
9587
9453
  })
9588
9454
  })
9589
9455
  ])
@@ -10202,9 +10068,47 @@ var DefaultEmbedManyResult = class {
10202
10068
 
10203
10069
  // src/generate-image/generate-image.ts
10204
10070
  import {
10205
- convertBase64ToUint8Array as convertBase64ToUint8Array4,
10071
+ convertBase64ToUint8Array as convertBase64ToUint8Array3,
10072
+ detectMediaType as detectMediaType2,
10206
10073
  withUserAgentSuffix as withUserAgentSuffix5
10207
10074
  } from "@ai-sdk/provider-utils";
10075
+
10076
+ // src/prompt/data-content.ts
10077
+ import {
10078
+ convertBase64ToUint8Array as convertBase64ToUint8Array2,
10079
+ convertUint8ArrayToBase64 as convertUint8ArrayToBase642
10080
+ } from "@ai-sdk/provider-utils";
10081
+ function convertDataContentToBase64String(content) {
10082
+ if (typeof content === "string") {
10083
+ return content;
10084
+ }
10085
+ if (content instanceof ArrayBuffer) {
10086
+ return convertUint8ArrayToBase642(new Uint8Array(content));
10087
+ }
10088
+ return convertUint8ArrayToBase642(content);
10089
+ }
10090
+ function convertDataContentToUint8Array(content) {
10091
+ if (content instanceof Uint8Array) {
10092
+ return content;
10093
+ }
10094
+ if (typeof content === "string") {
10095
+ try {
10096
+ return convertBase64ToUint8Array2(content);
10097
+ } catch (error) {
10098
+ throw new InvalidDataContentError({
10099
+ message: "Invalid data content. Content string is not a base64-encoded media.",
10100
+ content,
10101
+ cause: error
10102
+ });
10103
+ }
10104
+ }
10105
+ if (content instanceof ArrayBuffer) {
10106
+ return new Uint8Array(content);
10107
+ }
10108
+ throw new InvalidDataContentError({ content });
10109
+ }
10110
+
10111
+ // src/generate-image/generate-image.ts
10208
10112
  async function generateImage({
10209
10113
  model: modelArg,
10210
10114
  prompt: promptArg,
@@ -10272,9 +10176,9 @@ async function generateImage({
10272
10176
  var _a22;
10273
10177
  return new DefaultGeneratedFile({
10274
10178
  data: image,
10275
- mediaType: (_a22 = detectMediaType({
10179
+ mediaType: (_a22 = detectMediaType2({
10276
10180
  data: image,
10277
- signatures: imageMediaTypeSignatures
10181
+ topLevelType: "image"
10278
10182
  })) != null ? _a22 : "image/png"
10279
10183
  });
10280
10184
  }
@@ -10363,13 +10267,13 @@ function toImageModelV4File(dataContent) {
10363
10267
  if (typeof dataContent === "string" && dataContent.startsWith("data:")) {
10364
10268
  const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(dataContent);
10365
10269
  if (base64Content != null) {
10366
- const uint8Data2 = convertBase64ToUint8Array4(base64Content);
10270
+ const uint8Data2 = convertBase64ToUint8Array3(base64Content);
10367
10271
  return {
10368
10272
  type: "file",
10369
10273
  data: uint8Data2,
10370
- mediaType: dataUrlMediaType || detectMediaType({
10274
+ mediaType: dataUrlMediaType || detectMediaType2({
10371
10275
  data: uint8Data2,
10372
- signatures: imageMediaTypeSignatures
10276
+ topLevelType: "image"
10373
10277
  }) || "image/png"
10374
10278
  };
10375
10279
  }
@@ -10378,9 +10282,9 @@ function toImageModelV4File(dataContent) {
10378
10282
  return {
10379
10283
  type: "file",
10380
10284
  data: uint8Data,
10381
- mediaType: detectMediaType({
10285
+ mediaType: detectMediaType2({
10382
10286
  data: uint8Data,
10383
- signatures: imageMediaTypeSignatures
10287
+ topLevelType: "image"
10384
10288
  }) || "image/png"
10385
10289
  };
10386
10290
  }
@@ -11733,7 +11637,10 @@ var DefaultStreamObjectResult = class {
11733
11637
  };
11734
11638
 
11735
11639
  // src/generate-speech/generate-speech.ts
11736
- import { withUserAgentSuffix as withUserAgentSuffix7 } from "@ai-sdk/provider-utils";
11640
+ import {
11641
+ detectMediaType as detectMediaType3,
11642
+ withUserAgentSuffix as withUserAgentSuffix7
11643
+ } from "@ai-sdk/provider-utils";
11737
11644
 
11738
11645
  // src/generate-speech/generated-audio-file.ts
11739
11646
  var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
@@ -11811,9 +11718,9 @@ async function generateSpeech({
11811
11718
  return new DefaultSpeechResult({
11812
11719
  audio: new DefaultGeneratedAudioFile({
11813
11720
  data: result.audio,
11814
- mediaType: (_a21 = detectMediaType({
11721
+ mediaType: (_a21 = detectMediaType3({
11815
11722
  data: result.audio,
11816
- signatures: audioMediaTypeSignatures
11723
+ topLevelType: "audio"
11817
11724
  })) != null ? _a21 : "audio/mp3"
11818
11725
  }),
11819
11726
  warnings: result.warnings,
@@ -11912,7 +11819,9 @@ function pruneMessages({
11912
11819
 
11913
11820
  // src/generate-text/smooth-stream.ts
11914
11821
  import { delay as originalDelay } from "@ai-sdk/provider-utils";
11915
- import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
11822
+ import {
11823
+ InvalidArgumentError as InvalidArgumentError2
11824
+ } from "@ai-sdk/provider";
11916
11825
  var CHUNKING_REGEXPS = {
11917
11826
  word: /\S+\s+/m,
11918
11827
  line: /\n+/m
@@ -12010,8 +11919,9 @@ function smoothStream({
12010
11919
 
12011
11920
  // src/generate-video/generate-video.ts
12012
11921
  import {
12013
- convertBase64ToUint8Array as convertBase64ToUint8Array5,
12014
- withUserAgentSuffix as withUserAgentSuffix8
11922
+ convertBase64ToUint8Array as convertBase64ToUint8Array4,
11923
+ withUserAgentSuffix as withUserAgentSuffix8,
11924
+ detectMediaType as detectMediaType4
12015
11925
  } from "@ai-sdk/provider-utils";
12016
11926
  var defaultDownload = createDownload();
12017
11927
  async function experimental_generateVideo({
@@ -12079,9 +11989,9 @@ async function experimental_generateVideo({
12079
11989
  abortSignal
12080
11990
  });
12081
11991
  const isUsableMediaType = (type) => !!type && type !== "application/octet-stream";
12082
- const mediaType = isUsableMediaType(videoData.mediaType) && videoData.mediaType || isUsableMediaType(downloadedMediaType) && downloadedMediaType || detectMediaType({
11992
+ const mediaType = isUsableMediaType(videoData.mediaType) && videoData.mediaType || isUsableMediaType(downloadedMediaType) && downloadedMediaType || detectMediaType4({
12083
11993
  data,
12084
- signatures: videoMediaTypeSignatures
11994
+ topLevelType: "video"
12085
11995
  }) || "video/mp4";
12086
11996
  videos.push(
12087
11997
  new DefaultGeneratedFile({
@@ -12101,9 +12011,9 @@ async function experimental_generateVideo({
12101
12011
  break;
12102
12012
  }
12103
12013
  case "binary": {
12104
- const mediaType = videoData.mediaType || detectMediaType({
12014
+ const mediaType = videoData.mediaType || detectMediaType4({
12105
12015
  data: videoData.data,
12106
- signatures: videoMediaTypeSignatures
12016
+ topLevelType: "video"
12107
12017
  }) || "video/mp4";
12108
12018
  videos.push(
12109
12019
  new DefaultGeneratedFile({
@@ -12184,13 +12094,13 @@ function normalizePrompt2(promptArg) {
12184
12094
  image = {
12185
12095
  type: "file",
12186
12096
  mediaType: mediaType != null ? mediaType : "image/png",
12187
- data: convertBase64ToUint8Array5(base64Content != null ? base64Content : "")
12097
+ data: convertBase64ToUint8Array4(base64Content != null ? base64Content : "")
12188
12098
  };
12189
12099
  } else {
12190
- const bytes = convertBase64ToUint8Array5(dataContent);
12191
- const mediaType = (_a21 = detectMediaType({
12100
+ const bytes = convertBase64ToUint8Array4(dataContent);
12101
+ const mediaType = (_a21 = detectMediaType4({
12192
12102
  data: bytes,
12193
- signatures: imageMediaTypeSignatures
12103
+ topLevelType: "image"
12194
12104
  })) != null ? _a21 : "image/png";
12195
12105
  image = {
12196
12106
  type: "file",
@@ -12199,9 +12109,9 @@ function normalizePrompt2(promptArg) {
12199
12109
  };
12200
12110
  }
12201
12111
  } else if (dataContent instanceof Uint8Array) {
12202
- const mediaType = (_b = detectMediaType({
12112
+ const mediaType = (_b = detectMediaType4({
12203
12113
  data: dataContent,
12204
- signatures: imageMediaTypeSignatures
12114
+ topLevelType: "image"
12205
12115
  })) != null ? _b : "image/png";
12206
12116
  image = {
12207
12117
  type: "file",
@@ -12859,15 +12769,12 @@ function customProvider({
12859
12769
  skills,
12860
12770
  fallbackProvider: fallbackProviderArg
12861
12771
  }) {
12862
- var _a21, _b;
12863
- const fallbackProvider = fallbackProviderArg ? asProviderV4(fallbackProviderArg) : void 0;
12864
- const resolvedFiles = files != null ? files : (_a21 = fallbackProvider == null ? void 0 : fallbackProvider.files) == null ? void 0 : _a21.call(fallbackProvider);
12865
- const resolvedSkills = skills != null ? skills : (_b = fallbackProvider == null ? void 0 : fallbackProvider.skills) == null ? void 0 : _b.call(fallbackProvider);
12866
- return {
12772
+ const fallbackProvider = fallbackProviderArg == null ? void 0 : asProviderV4(fallbackProviderArg);
12773
+ const baseProvider = {
12867
12774
  specificationVersion: "v4",
12868
12775
  languageModel(modelId) {
12869
12776
  if (languageModels != null && modelId in languageModels) {
12870
- return asLanguageModelV4(languageModels[modelId]);
12777
+ return resolveLanguageModel(languageModels[modelId]);
12871
12778
  }
12872
12779
  if (fallbackProvider) {
12873
12780
  return fallbackProvider.languageModel(modelId);
@@ -12876,7 +12783,7 @@ function customProvider({
12876
12783
  },
12877
12784
  embeddingModel(modelId) {
12878
12785
  if (embeddingModels != null && modelId in embeddingModels) {
12879
- return asEmbeddingModelV4(embeddingModels[modelId]);
12786
+ return resolveEmbeddingModel(embeddingModels[modelId]);
12880
12787
  }
12881
12788
  if (fallbackProvider) {
12882
12789
  return fallbackProvider.embeddingModel(modelId);
@@ -12885,7 +12792,7 @@ function customProvider({
12885
12792
  },
12886
12793
  imageModel(modelId) {
12887
12794
  if (imageModels != null && modelId in imageModels) {
12888
- return asImageModelV4(imageModels[modelId]);
12795
+ return resolveImageModel(imageModels[modelId]);
12889
12796
  }
12890
12797
  if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
12891
12798
  return fallbackProvider.imageModel(modelId);
@@ -12894,7 +12801,10 @@ function customProvider({
12894
12801
  },
12895
12802
  transcriptionModel(modelId) {
12896
12803
  if (transcriptionModels != null && modelId in transcriptionModels) {
12897
- return asTranscriptionModelV4(transcriptionModels[modelId]);
12804
+ const model = resolveTranscriptionModel(transcriptionModels[modelId]);
12805
+ if (model != null) {
12806
+ return model;
12807
+ }
12898
12808
  }
12899
12809
  if (fallbackProvider == null ? void 0 : fallbackProvider.transcriptionModel) {
12900
12810
  return fallbackProvider.transcriptionModel(modelId);
@@ -12903,7 +12813,10 @@ function customProvider({
12903
12813
  },
12904
12814
  speechModel(modelId) {
12905
12815
  if (speechModels != null && modelId in speechModels) {
12906
- return asSpeechModelV4(speechModels[modelId]);
12816
+ const model = resolveSpeechModel(speechModels[modelId]);
12817
+ if (model != null) {
12818
+ return model;
12819
+ }
12907
12820
  }
12908
12821
  if (fallbackProvider == null ? void 0 : fallbackProvider.speechModel) {
12909
12822
  return fallbackProvider.speechModel(modelId);
@@ -12912,7 +12825,7 @@ function customProvider({
12912
12825
  },
12913
12826
  rerankingModel(modelId) {
12914
12827
  if (rerankingModels != null && modelId in rerankingModels) {
12915
- return asRerankingModelV4(rerankingModels[modelId]);
12828
+ return resolveRerankingModel(rerankingModels[modelId]);
12916
12829
  }
12917
12830
  if (fallbackProvider == null ? void 0 : fallbackProvider.rerankingModel) {
12918
12831
  return fallbackProvider.rerankingModel(modelId);
@@ -12921,22 +12834,32 @@ function customProvider({
12921
12834
  },
12922
12835
  videoModel(modelId) {
12923
12836
  if (videoModels != null && modelId in videoModels) {
12924
- return asVideoModelV4(videoModels[modelId]);
12837
+ return resolveVideoModel(videoModels[modelId]);
12925
12838
  }
12926
12839
  const videoModel = fallbackProvider == null ? void 0 : fallbackProvider.videoModel;
12927
12840
  if (videoModel) {
12928
12841
  return videoModel(modelId);
12929
12842
  }
12930
12843
  throw new NoSuchModelError2({ modelId, modelType: "videoModel" });
12931
- },
12932
- ...resolvedFiles != null ? { files: () => resolvedFiles } : {},
12933
- ...resolvedSkills != null ? { skills: () => resolvedSkills } : {}
12844
+ }
12934
12845
  };
12846
+ const filesAndSkills = {
12847
+ ...files != null || (fallbackProvider == null ? void 0 : fallbackProvider.files) != null ? {
12848
+ files() {
12849
+ return files != null ? files : fallbackProvider.files();
12850
+ }
12851
+ } : {},
12852
+ ...skills != null || (fallbackProvider == null ? void 0 : fallbackProvider.skills) != null ? {
12853
+ skills() {
12854
+ return skills != null ? skills : fallbackProvider.skills();
12855
+ }
12856
+ } : {}
12857
+ };
12858
+ return Object.assign(baseProvider, filesAndSkills);
12935
12859
  }
12936
- var experimental_customProvider = customProvider;
12937
12860
 
12938
12861
  // src/registry/no-such-provider-error.ts
12939
- import { AISDKError as AISDKError24, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
12862
+ import { AISDKError as AISDKError23, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
12940
12863
  var name20 = "AI_NoSuchProviderError";
12941
12864
  var marker20 = `vercel.ai.error.${name20}`;
12942
12865
  var symbol20 = Symbol.for(marker20);
@@ -12955,7 +12878,7 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
12955
12878
  this.availableProviders = availableProviders;
12956
12879
  }
12957
12880
  static isInstance(error) {
12958
- return AISDKError24.hasMarker(error, marker20);
12881
+ return AISDKError23.hasMarker(error, marker20);
12959
12882
  }
12960
12883
  };
12961
12884
  _a20 = symbol20;
@@ -12975,7 +12898,7 @@ function createProviderRegistry(providers, {
12975
12898
  imageModelMiddleware
12976
12899
  });
12977
12900
  for (const [id, provider] of Object.entries(providers)) {
12978
- registry.registerProvider({ id, provider: asProviderV4(provider) });
12901
+ registry.registerProvider({ id, provider });
12979
12902
  }
12980
12903
  return registry;
12981
12904
  }
@@ -12995,7 +12918,13 @@ var DefaultProviderRegistry = class {
12995
12918
  id,
12996
12919
  provider
12997
12920
  }) {
12998
- this.providers[id] = provider;
12921
+ var _a21;
12922
+ const providerV4 = asProviderV4(provider);
12923
+ const videoModel = (_a21 = provider.videoModel) == null ? void 0 : _a21.bind(provider);
12924
+ this.providers[id] = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
12925
+ ...providerV4,
12926
+ videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
12927
+ });
12999
12928
  }
13000
12929
  getProvider(id, modelType) {
13001
12930
  const provider = this.providers[id];
@@ -13007,7 +12936,7 @@ var DefaultProviderRegistry = class {
13007
12936
  availableProviders: Object.keys(this.providers)
13008
12937
  });
13009
12938
  }
13010
- return asProviderV4(provider);
12939
+ return provider;
13011
12940
  }
13012
12941
  splitId(id, modelType) {
13013
12942
  const index = id.indexOf(this.separator);
@@ -13108,50 +13037,36 @@ var DefaultProviderRegistry = class {
13108
13037
  if (model == null) {
13109
13038
  throw new NoSuchModelError4({ modelId: id, modelType: "videoModel" });
13110
13039
  }
13111
- return model;
13040
+ return asVideoModelV4(model);
13112
13041
  }
13113
- files(providerId) {
13114
- var _a21, _b;
13115
- const providerInstance = this.providers[providerId];
13116
- if (providerInstance == null) {
13117
- throw new NoSuchProviderError({
13118
- modelId: providerId,
13119
- modelType: "languageModel",
13120
- providerId,
13121
- availableProviders: Object.keys(this.providers)
13122
- });
13123
- }
13124
- const filesInterface = (_b = (_a21 = asProviderV4(providerInstance)).files) == null ? void 0 : _b.call(_a21);
13125
- if (filesInterface == null) {
13042
+ files(id) {
13043
+ var _a21;
13044
+ const provider = this.getProvider(id, "languageModel");
13045
+ const files = (_a21 = provider.files) == null ? void 0 : _a21.call(provider);
13046
+ if (files == null) {
13126
13047
  throw new Error(
13127
- `Provider '${providerId}' does not support files. Make sure the provider has a files() method.`
13048
+ `The provider "${id}" does not support file uploads. Make sure it exposes a files() method.`
13128
13049
  );
13129
13050
  }
13130
- return filesInterface;
13051
+ return files;
13131
13052
  }
13132
- skills(providerId) {
13133
- var _a21, _b;
13134
- const providerInstance = this.providers[providerId];
13135
- if (providerInstance == null) {
13136
- throw new NoSuchProviderError({
13137
- modelId: providerId,
13138
- modelType: "languageModel",
13139
- providerId,
13140
- availableProviders: Object.keys(this.providers)
13141
- });
13142
- }
13143
- const skillsInterface = (_b = (_a21 = asProviderV4(providerInstance)).skills) == null ? void 0 : _b.call(_a21);
13144
- if (skillsInterface == null) {
13053
+ skills(id) {
13054
+ var _a21;
13055
+ const provider = this.getProvider(id, "languageModel");
13056
+ const skills = (_a21 = provider.skills) == null ? void 0 : _a21.call(provider);
13057
+ if (skills == null) {
13145
13058
  throw new Error(
13146
- `Provider '${providerId}' does not support skills. Make sure the provider has a skills() method.`
13059
+ `The provider "${id}" does not support skills. Make sure it exposes a skills() method.`
13147
13060
  );
13148
13061
  }
13149
- return skillsInterface;
13062
+ return skills;
13150
13063
  }
13151
13064
  };
13152
13065
 
13153
13066
  // src/rerank/rerank.ts
13154
- import { createIdGenerator as createIdGenerator8 } from "@ai-sdk/provider-utils";
13067
+ import {
13068
+ createIdGenerator as createIdGenerator8
13069
+ } from "@ai-sdk/provider-utils";
13155
13070
  var originalGenerateCallId6 = createIdGenerator8({
13156
13071
  prefix: "call",
13157
13072
  size: 24
@@ -13349,7 +13264,10 @@ var DefaultRerankResult = class {
13349
13264
  };
13350
13265
 
13351
13266
  // src/transcribe/transcribe.ts
13352
- import { withUserAgentSuffix as withUserAgentSuffix9 } from "@ai-sdk/provider-utils";
13267
+ import {
13268
+ detectMediaType as detectMediaType5,
13269
+ withUserAgentSuffix as withUserAgentSuffix9
13270
+ } from "@ai-sdk/provider-utils";
13353
13271
  var defaultDownload2 = createDownload();
13354
13272
  async function transcribe({
13355
13273
  model,
@@ -13381,9 +13299,9 @@ async function transcribe({
13381
13299
  abortSignal,
13382
13300
  headers: headersWithUserAgent,
13383
13301
  providerOptions,
13384
- mediaType: (_a21 = detectMediaType({
13302
+ mediaType: (_a21 = detectMediaType5({
13385
13303
  data: audioData,
13386
- signatures: audioMediaTypeSignatures
13304
+ topLevelType: "audio"
13387
13305
  })) != null ? _a21 : "audio/wav"
13388
13306
  });
13389
13307
  }
@@ -14244,7 +14162,8 @@ var TextStreamChatTransport = class extends HttpChatTransport {
14244
14162
 
14245
14163
  // src/upload-file/upload-file.ts
14246
14164
  import {
14247
- convertBase64ToUint8Array as convertBase64ToUint8Array6
14165
+ convertBase64ToUint8Array as convertBase64ToUint8Array5,
14166
+ detectMediaType as detectMediaType6
14248
14167
  } from "@ai-sdk/provider-utils";
14249
14168
  async function uploadFile({
14250
14169
  api,
@@ -14254,21 +14173,8 @@ async function uploadFile({
14254
14173
  providerOptions
14255
14174
  }) {
14256
14175
  var _a21;
14257
- const { data } = convertToLanguageModelV4DataContent(dataArg);
14258
- if (data instanceof URL) {
14259
- throw new Error(
14260
- "URL data is not supported for file uploads. Fetch the URL content first and pass the bytes."
14261
- );
14262
- }
14263
- const mediaType = (_a21 = mediaTypeArg != null ? mediaTypeArg : detectMediaType({
14264
- data,
14265
- signatures: [
14266
- ...imageMediaTypeSignatures,
14267
- ...documentMediaTypeSignatures,
14268
- ...audioMediaTypeSignatures,
14269
- ...videoMediaTypeSignatures
14270
- ]
14271
- })) != null ? _a21 : isLikelyText(data) ? "text/plain" : "application/octet-stream";
14176
+ const data = dataArg instanceof Uint8Array || typeof dataArg === "string" ? { type: "data", data: dataArg } : dataArg;
14177
+ const mediaType = mediaTypeArg != null ? mediaTypeArg : data.type === "text" ? "text/plain" : (_a21 = detectMediaType6({ data: data.data })) != null ? _a21 : isLikelyText(data.data) ? "text/plain" : "application/octet-stream";
14272
14178
  const filesApi = "uploadFile" in api ? api : typeof api.files === "function" ? api.files() : (() => {
14273
14179
  throw new Error(
14274
14180
  "The provider does not support file uploads. Make sure it exposes a files() method."
@@ -14300,7 +14206,7 @@ var DefaultUploadFileResult = class {
14300
14206
  function isLikelyText(data) {
14301
14207
  const CHECK_LENGTH = 512;
14302
14208
  const BASE64_CHECK_LENGTH = Math.ceil((CHECK_LENGTH + 4) / 3) * 4;
14303
- const bytes = typeof data === "string" ? convertBase64ToUint8Array6(
14209
+ const bytes = typeof data === "string" ? convertBase64ToUint8Array5(
14304
14210
  data.substring(0, Math.min(data.length, BASE64_CHECK_LENGTH))
14305
14211
  ) : data;
14306
14212
  const checkLength = Math.min(bytes.length, CHECK_LENGTH);
@@ -14327,8 +14233,12 @@ async function uploadSkill({
14327
14233
  "The provider does not support skills. Make sure it exposes a skills() method."
14328
14234
  );
14329
14235
  })();
14236
+ const normalizedFiles = files.map((file) => ({
14237
+ ...file,
14238
+ data: file.data instanceof Uint8Array || typeof file.data === "string" ? { type: "data", data: file.data } : file.data
14239
+ }));
14330
14240
  const result = await skillsApi.uploadSkill({
14331
- files,
14241
+ files: normalizedFiles,
14332
14242
  displayTitle,
14333
14243
  providerOptions
14334
14244
  });
@@ -14336,6 +14246,7 @@ async function uploadSkill({
14336
14246
  }
14337
14247
  export {
14338
14248
  AISDKError21 as AISDKError,
14249
+ AI_SDK_TELEMETRY_DIAGNOSTIC_CHANNEL,
14339
14250
  APICallError,
14340
14251
  AbstractChat,
14341
14252
  DefaultChatTransport,
@@ -14408,7 +14319,6 @@ export {
14408
14319
  embed,
14409
14320
  embedMany,
14410
14321
  experimental_createProviderRegistry,
14411
- experimental_customProvider,
14412
14322
  filterActiveTools as experimental_filterActiveTools,
14413
14323
  experimental_generateImage,
14414
14324
  generateSpeech as experimental_generateSpeech,