ai 4.0.20 → 4.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5ed5e45]
8
+ - @ai-sdk/provider-utils@2.0.5
9
+ - @ai-sdk/provider@1.0.3
10
+ - @ai-sdk/react@1.0.7
11
+ - @ai-sdk/ui-utils@1.0.6
12
+
13
+ ## 4.0.21
14
+
15
+ ### Patch Changes
16
+
17
+ - a8669a2: fix (ai/core): prefer auto-detected image mimetype
18
+ - 6fb3e91: fix (ai/core): include type in generateText toolResults result property.
19
+
3
20
  ## 4.0.20
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1229,6 +1229,7 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
1229
1229
  );
1230
1230
  }
1231
1231
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1232
+ var _a13;
1232
1233
  if (part.type === "text") {
1233
1234
  return {
1234
1235
  type: "text",
@@ -1279,9 +1280,9 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1279
1280
  normalizedData = convertDataContentToUint8Array(content);
1280
1281
  }
1281
1282
  switch (type) {
1282
- case "image":
1283
- if (mimeType == null && normalizedData instanceof Uint8Array) {
1284
- mimeType = detectImageMimeType(normalizedData);
1283
+ case "image": {
1284
+ if (normalizedData instanceof Uint8Array) {
1285
+ mimeType = (_a13 = detectImageMimeType(normalizedData)) != null ? _a13 : mimeType;
1285
1286
  }
1286
1287
  return {
1287
1288
  type: "image",
@@ -1289,7 +1290,8 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1289
1290
  mimeType,
1290
1291
  providerMetadata: part.experimental_providerMetadata
1291
1292
  };
1292
- case "file":
1293
+ }
1294
+ case "file": {
1293
1295
  if (mimeType == null) {
1294
1296
  throw new Error(`Mime type is missing for file part`);
1295
1297
  }
@@ -1299,6 +1301,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1299
1301
  mimeType,
1300
1302
  providerMetadata: part.experimental_providerMetadata
1301
1303
  };
1304
+ }
1302
1305
  }
1303
1306
  }
1304
1307
 
@@ -1845,12 +1848,10 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1845
1848
  var import_ui_utils2 = require("@ai-sdk/ui-utils");
1846
1849
 
1847
1850
  // core/util/async-iterable-stream.ts
1848
- function createAsyncIterableStream(source, transformer) {
1849
- const transformedStream = source.pipeThrough(
1850
- new TransformStream(transformer)
1851
- );
1852
- transformedStream[Symbol.asyncIterator] = () => {
1853
- const reader = transformedStream.getReader();
1851
+ function createAsyncIterableStream(source) {
1852
+ const stream = source.pipeThrough(new TransformStream());
1853
+ stream[Symbol.asyncIterator] = () => {
1854
+ const reader = stream.getReader();
1854
1855
  return {
1855
1856
  async next() {
1856
1857
  const { done, value } = await reader.read();
@@ -1858,7 +1859,7 @@ function createAsyncIterableStream(source, transformer) {
1858
1859
  }
1859
1860
  };
1860
1861
  };
1861
- return transformedStream;
1862
+ return stream;
1862
1863
  }
1863
1864
 
1864
1865
  // core/generate-object/output-strategy.ts
@@ -1988,29 +1989,35 @@ var arrayOutputStrategy = (schema) => {
1988
1989
  },
1989
1990
  createElementStream(originalStream) {
1990
1991
  let publishedElements = 0;
1991
- return createAsyncIterableStream(originalStream, {
1992
- transform(chunk, controller) {
1993
- switch (chunk.type) {
1994
- case "object": {
1995
- const array = chunk.object;
1996
- for (; publishedElements < array.length; publishedElements++) {
1997
- controller.enqueue(array[publishedElements]);
1992
+ return createAsyncIterableStream(
1993
+ originalStream.pipeThrough(
1994
+ new TransformStream({
1995
+ transform(chunk, controller) {
1996
+ switch (chunk.type) {
1997
+ case "object": {
1998
+ const array = chunk.object;
1999
+ for (; publishedElements < array.length; publishedElements++) {
2000
+ controller.enqueue(array[publishedElements]);
2001
+ }
2002
+ break;
2003
+ }
2004
+ case "text-delta":
2005
+ case "finish":
2006
+ break;
2007
+ case "error":
2008
+ controller.error(chunk.error);
2009
+ break;
2010
+ default: {
2011
+ const _exhaustiveCheck = chunk;
2012
+ throw new Error(
2013
+ `Unsupported chunk type: ${_exhaustiveCheck}`
2014
+ );
2015
+ }
1998
2016
  }
1999
- break;
2000
2017
  }
2001
- case "text-delta":
2002
- case "finish":
2003
- break;
2004
- case "error":
2005
- controller.error(chunk.error);
2006
- break;
2007
- default: {
2008
- const _exhaustiveCheck = chunk;
2009
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
2010
- }
2011
- }
2012
- }
2013
- });
2018
+ })
2019
+ )
2020
+ );
2014
2021
  }
2015
2022
  };
2016
2023
  };
@@ -3206,25 +3213,29 @@ var DefaultStreamObjectResult = class {
3206
3213
  return this.responsePromise.value;
3207
3214
  }
3208
3215
  get partialObjectStream() {
3209
- return createAsyncIterableStream(this.stitchableStream.stream, {
3210
- transform(chunk, controller) {
3211
- switch (chunk.type) {
3212
- case "object":
3213
- controller.enqueue(chunk.object);
3214
- break;
3215
- case "text-delta":
3216
- case "finish":
3217
- break;
3218
- case "error":
3219
- controller.error(chunk.error);
3220
- break;
3221
- default: {
3222
- const _exhaustiveCheck = chunk;
3223
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3216
+ return createAsyncIterableStream(
3217
+ this.stitchableStream.stream.pipeThrough(
3218
+ new TransformStream({
3219
+ transform(chunk, controller) {
3220
+ switch (chunk.type) {
3221
+ case "object":
3222
+ controller.enqueue(chunk.object);
3223
+ break;
3224
+ case "text-delta":
3225
+ case "finish":
3226
+ break;
3227
+ case "error":
3228
+ controller.error(chunk.error);
3229
+ break;
3230
+ default: {
3231
+ const _exhaustiveCheck = chunk;
3232
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3233
+ }
3234
+ }
3224
3235
  }
3225
- }
3226
- }
3227
- });
3236
+ })
3237
+ )
3238
+ );
3228
3239
  }
3229
3240
  get elementStream() {
3230
3241
  return this.outputStrategy.createElementStream(
@@ -3232,32 +3243,32 @@ var DefaultStreamObjectResult = class {
3232
3243
  );
3233
3244
  }
3234
3245
  get textStream() {
3235
- return createAsyncIterableStream(this.stitchableStream.stream, {
3236
- transform(chunk, controller) {
3237
- switch (chunk.type) {
3238
- case "text-delta":
3239
- controller.enqueue(chunk.textDelta);
3240
- break;
3241
- case "object":
3242
- case "finish":
3243
- break;
3244
- case "error":
3245
- controller.error(chunk.error);
3246
- break;
3247
- default: {
3248
- const _exhaustiveCheck = chunk;
3249
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3246
+ return createAsyncIterableStream(
3247
+ this.stitchableStream.stream.pipeThrough(
3248
+ new TransformStream({
3249
+ transform(chunk, controller) {
3250
+ switch (chunk.type) {
3251
+ case "text-delta":
3252
+ controller.enqueue(chunk.textDelta);
3253
+ break;
3254
+ case "object":
3255
+ case "finish":
3256
+ break;
3257
+ case "error":
3258
+ controller.error(chunk.error);
3259
+ break;
3260
+ default: {
3261
+ const _exhaustiveCheck = chunk;
3262
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3263
+ }
3264
+ }
3250
3265
  }
3251
- }
3252
- }
3253
- });
3266
+ })
3267
+ )
3268
+ );
3254
3269
  }
3255
3270
  get fullStream() {
3256
- return createAsyncIterableStream(this.stitchableStream.stream, {
3257
- transform(chunk, controller) {
3258
- controller.enqueue(chunk);
3259
- }
3260
- });
3271
+ return createAsyncIterableStream(this.stitchableStream.stream);
3261
3272
  }
3262
3273
  pipeTextStreamToResponse(response, init) {
3263
3274
  writeToServerResponse({
@@ -3930,6 +3941,7 @@ async function executeTools({
3930
3941
  }
3931
3942
  });
3932
3943
  return {
3944
+ type: "tool-result",
3933
3945
  toolCallId,
3934
3946
  toolName,
3935
3947
  args,
@@ -5007,22 +5019,22 @@ var DefaultStreamTextResult = class {
5007
5019
  return stream1;
5008
5020
  }
5009
5021
  get textStream() {
5010
- return createAsyncIterableStream(this.teeStream(), {
5011
- transform(chunk, controller) {
5012
- if (chunk.type === "text-delta") {
5013
- controller.enqueue(chunk.textDelta);
5014
- } else if (chunk.type === "error") {
5015
- controller.error(chunk.error);
5016
- }
5017
- }
5018
- });
5022
+ return createAsyncIterableStream(
5023
+ this.teeStream().pipeThrough(
5024
+ new TransformStream({
5025
+ transform(chunk, controller) {
5026
+ if (chunk.type === "text-delta") {
5027
+ controller.enqueue(chunk.textDelta);
5028
+ } else if (chunk.type === "error") {
5029
+ controller.error(chunk.error);
5030
+ }
5031
+ }
5032
+ })
5033
+ )
5034
+ );
5019
5035
  }
5020
5036
  get fullStream() {
5021
- return createAsyncIterableStream(this.teeStream(), {
5022
- transform(chunk, controller) {
5023
- controller.enqueue(chunk);
5024
- }
5025
- });
5037
+ return createAsyncIterableStream(this.teeStream());
5026
5038
  }
5027
5039
  toDataStreamInternal({
5028
5040
  getErrorMessage: getErrorMessage5 = () => "An error occurred.",