ai 5.0.217 → 5.0.218

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,14 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.218
4
+
5
+ ### Patch Changes
6
+
7
+ - a322c62: fix: detect MP4 audio from its ftyp box during transcription
8
+ - cf778a9: fix(ai): preserve tool parts when tool call IDs repeat across steps
9
+ - Updated dependencies [b05bffb]
10
+ - @ai-sdk/gateway@2.0.117
11
+
3
12
  ## 5.0.217
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -738,7 +738,17 @@ var audioMediaTypeSignatures = [
738
738
  },
739
739
  {
740
740
  mediaType: "audio/mp4",
741
- bytesPrefix: [102, 116, 121, 112]
741
+ bytesPrefix: [
742
+ 0,
743
+ 0,
744
+ 0,
745
+ null,
746
+ 102,
747
+ 116,
748
+ 121,
749
+ 112
750
+ // ftyp
751
+ ]
742
752
  },
743
753
  {
744
754
  mediaType: "audio/webm",
@@ -778,7 +788,7 @@ function detectMediaType({
778
788
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
779
789
 
780
790
  // src/version.ts
781
- var VERSION = true ? "5.0.217" : "0.0.0-test";
791
+ var VERSION = true ? "5.0.218" : "0.0.0-test";
782
792
 
783
793
  // src/util/download/download.ts
784
794
  var download = async ({
@@ -3612,11 +3622,32 @@ function processUIMessageStream({
3612
3622
  async transform(chunk, controller) {
3613
3623
  await runUpdateMessageJob(async ({ state, write }) => {
3614
3624
  var _a16, _b, _c, _d;
3625
+ function getCurrentStepParts() {
3626
+ const parts = state.message.parts;
3627
+ let currentStepStartIndex = parts.length - 1;
3628
+ while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
3629
+ currentStepStartIndex--;
3630
+ }
3631
+ return parts.slice(currentStepStartIndex + 1);
3632
+ }
3633
+ function getCurrentStepToolInvocations() {
3634
+ return getCurrentStepParts().filter(isToolUIPart);
3635
+ }
3615
3636
  function getToolInvocation(toolCallId) {
3616
- const toolInvocations = state.message.parts.filter(isToolUIPart);
3617
- const toolInvocation = toolInvocations.find(
3637
+ const toolInvocations = getCurrentStepToolInvocations();
3638
+ let toolInvocation = toolInvocations.find(
3618
3639
  (invocation) => invocation.toolCallId === toolCallId
3619
3640
  );
3641
+ if (toolInvocation == null) {
3642
+ const parts = state.message.parts;
3643
+ for (let i = parts.length - 1; i >= 0; i--) {
3644
+ const part = parts[i];
3645
+ if (isToolUIPart(part) && part.toolCallId === toolCallId) {
3646
+ toolInvocation = part;
3647
+ break;
3648
+ }
3649
+ }
3650
+ }
3620
3651
  if (toolInvocation == null) {
3621
3652
  throw new Error(
3622
3653
  "tool-output-error must be preceded by a tool-input-available"
@@ -3625,12 +3656,22 @@ function processUIMessageStream({
3625
3656
  return toolInvocation;
3626
3657
  }
3627
3658
  function getDynamicToolInvocation(toolCallId) {
3628
- const toolInvocations = state.message.parts.filter(
3659
+ const toolInvocations = getCurrentStepParts().filter(
3629
3660
  (part) => part.type === "dynamic-tool"
3630
3661
  );
3631
- const toolInvocation = toolInvocations.find(
3662
+ let toolInvocation = toolInvocations.find(
3632
3663
  (invocation) => invocation.toolCallId === toolCallId
3633
3664
  );
3665
+ if (toolInvocation == null) {
3666
+ const parts = state.message.parts;
3667
+ for (let i = parts.length - 1; i >= 0; i--) {
3668
+ const part = parts[i];
3669
+ if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) {
3670
+ toolInvocation = part;
3671
+ break;
3672
+ }
3673
+ }
3674
+ }
3634
3675
  if (toolInvocation == null) {
3635
3676
  throw new Error(
3636
3677
  "tool-output-error must be preceded by a tool-input-available"
@@ -3638,9 +3679,9 @@ function processUIMessageStream({
3638
3679
  }
3639
3680
  return toolInvocation;
3640
3681
  }
3641
- function updateToolPart(options) {
3682
+ function updateToolPart(options, existingPart) {
3642
3683
  var _a17;
3643
- const part = state.message.parts.find(
3684
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
3644
3685
  (part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
3645
3686
  );
3646
3687
  const anyOptions = options;
@@ -3671,9 +3712,9 @@ function processUIMessageStream({
3671
3712
  });
3672
3713
  }
3673
3714
  }
3674
- function updateDynamicToolPart(options) {
3715
+ function updateDynamicToolPart(options, existingPart) {
3675
3716
  var _a17, _b2;
3676
- const part = state.message.parts.find(
3717
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
3677
3718
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
3678
3719
  );
3679
3720
  const anyOptions = options;
@@ -3805,7 +3846,7 @@ function processUIMessageStream({
3805
3846
  break;
3806
3847
  }
3807
3848
  case "tool-input-start": {
3808
- const toolInvocations = state.message.parts.filter(isToolUIPart);
3849
+ const toolInvocations = getCurrentStepParts().filter(isToolUIPart);
3809
3850
  state.partialToolCalls[chunk.toolCallId] = {
3810
3851
  text: "",
3811
3852
  toolName: chunk.toolName,
@@ -3915,25 +3956,31 @@ function processUIMessageStream({
3915
3956
  const toolInvocation = getDynamicToolInvocation(
3916
3957
  chunk.toolCallId
3917
3958
  );
3918
- updateDynamicToolPart({
3919
- toolCallId: chunk.toolCallId,
3920
- toolName: toolInvocation.toolName,
3921
- state: "output-available",
3922
- input: toolInvocation.input,
3923
- output: chunk.output,
3924
- preliminary: chunk.preliminary
3925
- });
3959
+ updateDynamicToolPart(
3960
+ {
3961
+ toolCallId: chunk.toolCallId,
3962
+ toolName: toolInvocation.toolName,
3963
+ state: "output-available",
3964
+ input: toolInvocation.input,
3965
+ output: chunk.output,
3966
+ preliminary: chunk.preliminary
3967
+ },
3968
+ toolInvocation
3969
+ );
3926
3970
  } else {
3927
3971
  const toolInvocation = getToolInvocation(chunk.toolCallId);
3928
- updateToolPart({
3929
- toolCallId: chunk.toolCallId,
3930
- toolName: getToolName(toolInvocation),
3931
- state: "output-available",
3932
- input: toolInvocation.input,
3933
- output: chunk.output,
3934
- providerExecuted: chunk.providerExecuted,
3935
- preliminary: chunk.preliminary
3936
- });
3972
+ updateToolPart(
3973
+ {
3974
+ toolCallId: chunk.toolCallId,
3975
+ toolName: getToolName(toolInvocation),
3976
+ state: "output-available",
3977
+ input: toolInvocation.input,
3978
+ output: chunk.output,
3979
+ providerExecuted: chunk.providerExecuted,
3980
+ preliminary: chunk.preliminary
3981
+ },
3982
+ toolInvocation
3983
+ );
3937
3984
  }
3938
3985
  write();
3939
3986
  break;
@@ -3943,25 +3990,31 @@ function processUIMessageStream({
3943
3990
  const toolInvocation = getDynamicToolInvocation(
3944
3991
  chunk.toolCallId
3945
3992
  );
3946
- updateDynamicToolPart({
3947
- toolCallId: chunk.toolCallId,
3948
- toolName: toolInvocation.toolName,
3949
- state: "output-error",
3950
- input: toolInvocation.input,
3951
- errorText: chunk.errorText,
3952
- providerExecuted: chunk.providerExecuted
3953
- });
3993
+ updateDynamicToolPart(
3994
+ {
3995
+ toolCallId: chunk.toolCallId,
3996
+ toolName: toolInvocation.toolName,
3997
+ state: "output-error",
3998
+ input: toolInvocation.input,
3999
+ errorText: chunk.errorText,
4000
+ providerExecuted: chunk.providerExecuted
4001
+ },
4002
+ toolInvocation
4003
+ );
3954
4004
  } else {
3955
4005
  const toolInvocation = getToolInvocation(chunk.toolCallId);
3956
- updateToolPart({
3957
- toolCallId: chunk.toolCallId,
3958
- toolName: getToolName(toolInvocation),
3959
- state: "output-error",
3960
- input: toolInvocation.input,
3961
- rawInput: toolInvocation.rawInput,
3962
- errorText: chunk.errorText,
3963
- providerExecuted: chunk.providerExecuted
3964
- });
4006
+ updateToolPart(
4007
+ {
4008
+ toolCallId: chunk.toolCallId,
4009
+ toolName: getToolName(toolInvocation),
4010
+ state: "output-error",
4011
+ input: toolInvocation.input,
4012
+ rawInput: toolInvocation.rawInput,
4013
+ errorText: chunk.errorText,
4014
+ providerExecuted: chunk.providerExecuted
4015
+ },
4016
+ toolInvocation
4017
+ );
3965
4018
  }
3966
4019
  write();
3967
4020
  break;