ai 4.1.50 → 4.1.52

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.52
4
+
5
+ ### Patch Changes
6
+
7
+ - 5329a69: fix (ai/core): fix duplicated reasoning in streamText onFinish and messages
8
+
9
+ ## 4.1.51
10
+
11
+ ### Patch Changes
12
+
13
+ - 0cb2647: feat (ai/core): add streamText sendStart & sendFinish data stream options
14
+
3
15
  ## 4.1.50
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
@@ -4991,7 +4991,7 @@ var DefaultStreamTextResult = class {
4991
4991
  let recordedStepText = "";
4992
4992
  let recordedContinuationText = "";
4993
4993
  let recordedFullText = "";
4994
- const stepReasoning = [];
4994
+ let stepReasoning = [];
4995
4995
  let activeReasoningText = void 0;
4996
4996
  let recordedStepSources = [];
4997
4997
  const recordedSources = [];
@@ -5105,6 +5105,8 @@ var DefaultStreamTextResult = class {
5105
5105
  recordedToolResults = [];
5106
5106
  recordedStepText = "";
5107
5107
  recordedStepSources = [];
5108
+ stepReasoning = [];
5109
+ activeReasoningText = void 0;
5108
5110
  if (nextStepType !== "done") {
5109
5111
  stepType = nextStepType;
5110
5112
  }
@@ -5770,7 +5772,8 @@ var DefaultStreamTextResult = class {
5770
5772
  // mask error messages for safety by default
5771
5773
  sendUsage = true,
5772
5774
  sendReasoning = false,
5773
- sendSources = false
5775
+ sendSources = false,
5776
+ experimental_sendFinish = true
5774
5777
  }) {
5775
5778
  return this.fullStream.pipeThrough(
5776
5779
  new TransformStream({
@@ -5882,15 +5885,17 @@ var DefaultStreamTextResult = class {
5882
5885
  break;
5883
5886
  }
5884
5887
  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
- );
5888
+ if (experimental_sendFinish) {
5889
+ controller.enqueue(
5890
+ (0, import_ui_utils8.formatDataStreamPart)("finish_message", {
5891
+ finishReason: chunk.finishReason,
5892
+ usage: sendUsage ? {
5893
+ promptTokens: chunk.usage.promptTokens,
5894
+ completionTokens: chunk.usage.completionTokens
5895
+ } : void 0
5896
+ })
5897
+ );
5898
+ }
5894
5899
  break;
5895
5900
  }
5896
5901
  default: {
@@ -5910,7 +5915,8 @@ var DefaultStreamTextResult = class {
5910
5915
  getErrorMessage: getErrorMessage5,
5911
5916
  sendUsage,
5912
5917
  sendReasoning,
5913
- sendSources
5918
+ sendSources,
5919
+ experimental_sendFinish
5914
5920
  } = {}) {
5915
5921
  writeToServerResponse({
5916
5922
  response,
@@ -5925,7 +5931,8 @@ var DefaultStreamTextResult = class {
5925
5931
  getErrorMessage: getErrorMessage5,
5926
5932
  sendUsage,
5927
5933
  sendReasoning,
5928
- sendSources
5934
+ sendSources,
5935
+ experimental_sendFinish
5929
5936
  })
5930
5937
  });
5931
5938
  }
@@ -5946,7 +5953,8 @@ var DefaultStreamTextResult = class {
5946
5953
  getErrorMessage: options == null ? void 0 : options.getErrorMessage,
5947
5954
  sendUsage: options == null ? void 0 : options.sendUsage,
5948
5955
  sendReasoning: options == null ? void 0 : options.sendReasoning,
5949
- sendSources: options == null ? void 0 : options.sendSources
5956
+ sendSources: options == null ? void 0 : options.sendSources,
5957
+ experimental_sendFinish: options == null ? void 0 : options.experimental_sendFinish
5950
5958
  }).pipeThrough(new TextEncoderStream());
5951
5959
  return (options == null ? void 0 : options.data) ? mergeStreams(options == null ? void 0 : options.data.stream, stream) : stream;
5952
5960
  }
@@ -5956,7 +5964,8 @@ var DefaultStreamTextResult = class {
5956
5964
  getErrorMessage: writer.onError,
5957
5965
  sendUsage: options == null ? void 0 : options.sendUsage,
5958
5966
  sendReasoning: options == null ? void 0 : options.sendReasoning,
5959
- sendSources: options == null ? void 0 : options.sendSources
5967
+ sendSources: options == null ? void 0 : options.sendSources,
5968
+ experimental_sendFinish: options == null ? void 0 : options.experimental_sendFinish
5960
5969
  })
5961
5970
  );
5962
5971
  }
@@ -5968,7 +5977,8 @@ var DefaultStreamTextResult = class {
5968
5977
  getErrorMessage: getErrorMessage5,
5969
5978
  sendUsage,
5970
5979
  sendReasoning,
5971
- sendSources
5980
+ sendSources,
5981
+ experimental_sendFinish
5972
5982
  } = {}) {
5973
5983
  return new Response(
5974
5984
  this.toDataStream({
@@ -5976,7 +5986,8 @@ var DefaultStreamTextResult = class {
5976
5986
  getErrorMessage: getErrorMessage5,
5977
5987
  sendUsage,
5978
5988
  sendReasoning,
5979
- sendSources
5989
+ sendSources,
5990
+ experimental_sendFinish
5980
5991
  }),
5981
5992
  {
5982
5993
  status,