ai 5.0.278 → 5.0.280

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,25 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.280
4
+
5
+ ### Patch Changes
6
+
7
+ - 1e4ab85: fix(ai): remove orphaned reasoning, including consecutive summary parts, when pruning tool calls
8
+ - Updated dependencies [bd02a79]
9
+ - @ai-sdk/gateway@2.0.171
10
+
11
+ ## 5.0.279
12
+
13
+ ### Patch Changes
14
+
15
+ - 11b886a: Stop forwarding buffered source stream parts after a transform calls `stopStream()`. This prevents text and errors from appearing after the transform emits its finish events.
16
+ - Updated dependencies [d7b0ffa]
17
+ - Updated dependencies [5a96038]
18
+ - Updated dependencies [fd50c4d]
19
+ - Updated dependencies [4146790]
20
+ - @ai-sdk/provider-utils@3.0.42
21
+ - @ai-sdk/gateway@2.0.170
22
+
3
23
  ## 5.0.278
4
24
 
5
25
  ### Patch Changes
package/dist/index.js CHANGED
@@ -817,7 +817,7 @@ function detectMediaType({
817
817
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
818
818
 
819
819
  // src/version.ts
820
- var VERSION = true ? "5.0.278" : "0.0.0-test";
820
+ var VERSION = true ? "5.0.280" : "0.0.0-test";
821
821
 
822
822
  // src/util/download/download.ts
823
823
  var download = async ({
@@ -5415,12 +5415,23 @@ var DefaultStreamTextResult = class {
5415
5415
  return stitchableStream.stream.cancel(reason);
5416
5416
  }
5417
5417
  });
5418
+ let isRunning = true;
5419
+ stream = stream.pipeThrough(
5420
+ new TransformStream({
5421
+ async transform(chunk, controller) {
5422
+ if (isRunning) {
5423
+ controller.enqueue(chunk);
5424
+ }
5425
+ }
5426
+ })
5427
+ );
5418
5428
  for (const transform of transforms) {
5419
5429
  stream = stream.pipeThrough(
5420
5430
  transform({
5421
5431
  tools,
5422
5432
  stopStream() {
5423
5433
  stitchableStream.terminate();
5434
+ isRunning = false;
5424
5435
  }
5425
5436
  })
5426
5437
  );
@@ -8913,21 +8924,52 @@ function pruneMessages({
8913
8924
  if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
8914
8925
  return message;
8915
8926
  }
8916
- const toolCallIdToToolName = {};
8917
- return {
8918
- ...message,
8919
- content: message.content.filter((part) => {
8920
- if (part.type !== "tool-call" && part.type !== "tool-result") {
8921
- return true;
8927
+ const keepParts = message.content.map((part) => {
8928
+ if (part.type !== "tool-call" && part.type !== "tool-result") {
8929
+ return true;
8930
+ }
8931
+ if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId)) {
8932
+ return true;
8933
+ }
8934
+ return toolCall.tools != null && !toolCall.tools.includes(part.toolName);
8935
+ });
8936
+ if (message.role === "assistant") {
8937
+ for (let reasoningIndex = 0; reasoningIndex < message.content.length; reasoningIndex++) {
8938
+ const part = message.content[reasoningIndex];
8939
+ if (part.type !== "reasoning") {
8940
+ continue;
8922
8941
  }
8923
- if (part.type === "tool-call") {
8924
- toolCallIdToToolName[part.toolCallId] = part.toolName;
8942
+ let reasoningEndIndex = reasoningIndex + 1;
8943
+ while (reasoningEndIndex < message.content.length) {
8944
+ const nextPart = message.content[reasoningEndIndex];
8945
+ if (nextPart.type !== "reasoning") {
8946
+ break;
8947
+ }
8948
+ reasoningEndIndex++;
8925
8949
  }
8926
- if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId)) {
8927
- return true;
8950
+ let followingPartIndex = reasoningEndIndex;
8951
+ let hasFollowingPart = false;
8952
+ let hasKeptFollowingPart = false;
8953
+ while (followingPartIndex < message.content.length) {
8954
+ const followingPart = message.content[followingPartIndex];
8955
+ if (followingPart.type === "reasoning") {
8956
+ break;
8957
+ }
8958
+ hasFollowingPart = true;
8959
+ hasKeptFollowingPart || (hasKeptFollowingPart = keepParts[followingPartIndex]);
8960
+ followingPartIndex++;
8928
8961
  }
8929
- return toolCall.tools != null && !toolCall.tools.includes(part.toolName);
8930
- })
8962
+ if (hasFollowingPart && !hasKeptFollowingPart) {
8963
+ for (let index = reasoningIndex; index < reasoningEndIndex; index++) {
8964
+ keepParts[index] = false;
8965
+ }
8966
+ }
8967
+ reasoningIndex = followingPartIndex - 1;
8968
+ }
8969
+ }
8970
+ return {
8971
+ ...message,
8972
+ content: message.content.filter((_, index) => keepParts[index])
8931
8973
  };
8932
8974
  });
8933
8975
  }