ai 4.1.49 → 4.1.51

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,17 @@
1
1
  # ai
2
2
 
3
+ ## 4.1.51
4
+
5
+ ### Patch Changes
6
+
7
+ - 0cb2647: feat (ai/core): add streamText sendStart & sendFinish data stream options
8
+
9
+ ## 4.1.50
10
+
11
+ ### Patch Changes
12
+
13
+ - ae98f0d: fix (ai/core): forward providerOptions for text, image, and file parts
14
+
3
15
  ## 4.1.49
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2199,6 +2199,25 @@ type DataStreamOptions = {
2199
2199
  * Default to false.
2200
2200
  */
2201
2201
  sendSources?: boolean;
2202
+ /**
2203
+ * Send the finish event to the client.
2204
+ * Set to false if you are using additional streamText calls
2205
+ * that send additional data.
2206
+ * Default to true.
2207
+ */
2208
+ experimental_sendFinish?: boolean;
2209
+ /**
2210
+ * Send the message start event to the client.
2211
+ * Set to false if you are using additional streamText calls
2212
+ * and the message start event has already been sent.
2213
+ * Default to true.
2214
+ *
2215
+ * Note: this setting is currently not used, but you should
2216
+ * already set it to false if you are using additional
2217
+ * streamText calls that send additional data to prevent
2218
+ * the message start event from being sent multiple times.
2219
+ */
2220
+ experimental_sendStart?: boolean;
2202
2221
  };
2203
2222
  /**
2204
2223
  A result object for accessing different stream types and additional information.
package/dist/index.d.ts CHANGED
@@ -2199,6 +2199,25 @@ type DataStreamOptions = {
2199
2199
  * Default to false.
2200
2200
  */
2201
2201
  sendSources?: boolean;
2202
+ /**
2203
+ * Send the finish event to the client.
2204
+ * Set to false if you are using additional streamText calls
2205
+ * that send additional data.
2206
+ * Default to true.
2207
+ */
2208
+ experimental_sendFinish?: boolean;
2209
+ /**
2210
+ * Send the message start event to the client.
2211
+ * Set to false if you are using additional streamText calls
2212
+ * and the message start event has already been sent.
2213
+ * Default to true.
2214
+ *
2215
+ * Note: this setting is currently not used, but you should
2216
+ * already set it to false if you are using additional
2217
+ * streamText calls that send additional data to prevent
2218
+ * the message start event from being sent multiple times.
2219
+ */
2220
+ experimental_sendStart?: boolean;
2202
2221
  };
2203
2222
  /**
2204
2223
  A result object for accessing different stream types and additional information.
package/dist/index.js CHANGED
@@ -1326,12 +1326,12 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
1326
1326
  );
1327
1327
  }
1328
1328
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1329
- var _a16;
1329
+ var _a16, _b, _c, _d;
1330
1330
  if (part.type === "text") {
1331
1331
  return {
1332
1332
  type: "text",
1333
1333
  text: part.text,
1334
- providerMetadata: part.experimental_providerMetadata
1334
+ providerMetadata: (_a16 = part.providerOptions) != null ? _a16 : part.experimental_providerMetadata
1335
1335
  };
1336
1336
  }
1337
1337
  let mimeType = part.mimeType;
@@ -1379,13 +1379,13 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1379
1379
  switch (type) {
1380
1380
  case "image": {
1381
1381
  if (normalizedData instanceof Uint8Array) {
1382
- mimeType = (_a16 = detectImageMimeType(normalizedData)) != null ? _a16 : mimeType;
1382
+ mimeType = (_b = detectImageMimeType(normalizedData)) != null ? _b : mimeType;
1383
1383
  }
1384
1384
  return {
1385
1385
  type: "image",
1386
1386
  image: normalizedData,
1387
1387
  mimeType,
1388
- providerMetadata: part.experimental_providerMetadata
1388
+ providerMetadata: (_c = part.providerOptions) != null ? _c : part.experimental_providerMetadata
1389
1389
  };
1390
1390
  }
1391
1391
  case "file": {
@@ -1396,7 +1396,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1396
1396
  type: "file",
1397
1397
  data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
1398
1398
  mimeType,
1399
- providerMetadata: part.experimental_providerMetadata
1399
+ providerMetadata: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
1400
1400
  };
1401
1401
  }
1402
1402
  }
@@ -5770,7 +5770,8 @@ var DefaultStreamTextResult = class {
5770
5770
  // mask error messages for safety by default
5771
5771
  sendUsage = true,
5772
5772
  sendReasoning = false,
5773
- sendSources = false
5773
+ sendSources = false,
5774
+ experimental_sendFinish = true
5774
5775
  }) {
5775
5776
  return this.fullStream.pipeThrough(
5776
5777
  new TransformStream({
@@ -5882,15 +5883,17 @@ var DefaultStreamTextResult = class {
5882
5883
  break;
5883
5884
  }
5884
5885
  case "finish": {
5885
- controller.enqueue(
5886
- (0, import_ui_utils8.formatDataStreamPart)("finish_message", {
5887
- finishReason: chunk.finishReason,
5888
- usage: sendUsage ? {
5889
- promptTokens: chunk.usage.promptTokens,
5890
- completionTokens: chunk.usage.completionTokens
5891
- } : void 0
5892
- })
5893
- );
5886
+ if (experimental_sendFinish) {
5887
+ controller.enqueue(
5888
+ (0, import_ui_utils8.formatDataStreamPart)("finish_message", {
5889
+ finishReason: chunk.finishReason,
5890
+ usage: sendUsage ? {
5891
+ promptTokens: chunk.usage.promptTokens,
5892
+ completionTokens: chunk.usage.completionTokens
5893
+ } : void 0
5894
+ })
5895
+ );
5896
+ }
5894
5897
  break;
5895
5898
  }
5896
5899
  default: {
@@ -5910,7 +5913,8 @@ var DefaultStreamTextResult = class {
5910
5913
  getErrorMessage: getErrorMessage5,
5911
5914
  sendUsage,
5912
5915
  sendReasoning,
5913
- sendSources
5916
+ sendSources,
5917
+ experimental_sendFinish
5914
5918
  } = {}) {
5915
5919
  writeToServerResponse({
5916
5920
  response,
@@ -5925,7 +5929,8 @@ var DefaultStreamTextResult = class {
5925
5929
  getErrorMessage: getErrorMessage5,
5926
5930
  sendUsage,
5927
5931
  sendReasoning,
5928
- sendSources
5932
+ sendSources,
5933
+ experimental_sendFinish
5929
5934
  })
5930
5935
  });
5931
5936
  }
@@ -5946,7 +5951,8 @@ var DefaultStreamTextResult = class {
5946
5951
  getErrorMessage: options == null ? void 0 : options.getErrorMessage,
5947
5952
  sendUsage: options == null ? void 0 : options.sendUsage,
5948
5953
  sendReasoning: options == null ? void 0 : options.sendReasoning,
5949
- sendSources: options == null ? void 0 : options.sendSources
5954
+ sendSources: options == null ? void 0 : options.sendSources,
5955
+ experimental_sendFinish: options == null ? void 0 : options.experimental_sendFinish
5950
5956
  }).pipeThrough(new TextEncoderStream());
5951
5957
  return (options == null ? void 0 : options.data) ? mergeStreams(options == null ? void 0 : options.data.stream, stream) : stream;
5952
5958
  }
@@ -5956,7 +5962,8 @@ var DefaultStreamTextResult = class {
5956
5962
  getErrorMessage: writer.onError,
5957
5963
  sendUsage: options == null ? void 0 : options.sendUsage,
5958
5964
  sendReasoning: options == null ? void 0 : options.sendReasoning,
5959
- sendSources: options == null ? void 0 : options.sendSources
5965
+ sendSources: options == null ? void 0 : options.sendSources,
5966
+ experimental_sendFinish: options == null ? void 0 : options.experimental_sendFinish
5960
5967
  })
5961
5968
  );
5962
5969
  }
@@ -5968,7 +5975,8 @@ var DefaultStreamTextResult = class {
5968
5975
  getErrorMessage: getErrorMessage5,
5969
5976
  sendUsage,
5970
5977
  sendReasoning,
5971
- sendSources
5978
+ sendSources,
5979
+ experimental_sendFinish
5972
5980
  } = {}) {
5973
5981
  return new Response(
5974
5982
  this.toDataStream({
@@ -5976,7 +5984,8 @@ var DefaultStreamTextResult = class {
5976
5984
  getErrorMessage: getErrorMessage5,
5977
5985
  sendUsage,
5978
5986
  sendReasoning,
5979
- sendSources
5987
+ sendSources,
5988
+ experimental_sendFinish
5980
5989
  }),
5981
5990
  {
5982
5991
  status,