ai 7.0.32 → 7.0.34

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,24 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.34
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7c16f21]
8
+ - @ai-sdk/gateway@4.0.26
9
+
10
+ ## 7.0.33
11
+
12
+ ### Patch Changes
13
+
14
+ - 76cb673: fix: detect MP4 audio from its ftyp box during transcription
15
+ - e808fa5: fix(ai): preserve tool parts when tool call IDs repeat across steps
16
+ - 33647d7: Preserve provider options when combining consecutive tool messages.
17
+ - Updated dependencies [02ffdcb]
18
+ - Updated dependencies [76cb673]
19
+ - @ai-sdk/provider-utils@5.0.12
20
+ - @ai-sdk/gateway@4.0.25
21
+
3
22
  ## 7.0.32
4
23
 
5
24
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1089,7 +1089,7 @@ import {
1089
1089
  } from "@ai-sdk/provider-utils";
1090
1090
 
1091
1091
  // src/version.ts
1092
- var VERSION = true ? "7.0.32" : "0.0.0-test";
1092
+ var VERSION = true ? "7.0.34" : "0.0.0-test";
1093
1093
 
1094
1094
  // src/util/download/download.ts
1095
1095
  var download = async ({
@@ -1142,6 +1142,42 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
1142
1142
  )
1143
1143
  );
1144
1144
 
1145
+ // src/util/merge-objects.ts
1146
+ function mergeObjects(base, overrides) {
1147
+ if (base === void 0 && overrides === void 0) {
1148
+ return void 0;
1149
+ }
1150
+ if (base === void 0) {
1151
+ return overrides;
1152
+ }
1153
+ if (overrides === void 0) {
1154
+ return base;
1155
+ }
1156
+ const result = { ...base };
1157
+ for (const key in overrides) {
1158
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
1159
+ continue;
1160
+ }
1161
+ if (Object.prototype.hasOwnProperty.call(overrides, key)) {
1162
+ const overridesValue = overrides[key];
1163
+ if (overridesValue === void 0)
1164
+ continue;
1165
+ const baseValue = key in base ? base[key] : void 0;
1166
+ const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
1167
+ const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
1168
+ if (isSourceObject && isTargetObject) {
1169
+ result[key] = mergeObjects(
1170
+ baseValue,
1171
+ overridesValue
1172
+ );
1173
+ } else {
1174
+ result[key] = overridesValue;
1175
+ }
1176
+ }
1177
+ }
1178
+ return result;
1179
+ }
1180
+
1145
1181
  // src/prompt/file-part-data.ts
1146
1182
  import {
1147
1183
  isBuffer,
@@ -1307,7 +1343,15 @@ async function convertToLanguageModelPrompt({
1307
1343
  }
1308
1344
  const lastCombinedMessage = combinedMessages.at(-1);
1309
1345
  if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
1346
+ const lastContentPart = lastCombinedMessage.content.at(-1);
1347
+ if (lastContentPart != null && lastCombinedMessage.providerOptions != null) {
1348
+ lastContentPart.providerOptions = mergeObjects(
1349
+ lastCombinedMessage.providerOptions,
1350
+ lastContentPart.providerOptions
1351
+ );
1352
+ }
1310
1353
  lastCombinedMessage.content.push(...message.content);
1354
+ lastCombinedMessage.providerOptions = message.providerOptions;
1311
1355
  } else {
1312
1356
  combinedMessages.push(message);
1313
1357
  }
@@ -2586,42 +2630,6 @@ function mergeAbortSignals(...signals) {
2586
2630
  return validSignals.length === 0 ? void 0 : validSignals.length === 1 ? validSignals[0] : AbortSignal.any(validSignals);
2587
2631
  }
2588
2632
 
2589
- // src/util/merge-objects.ts
2590
- function mergeObjects(base, overrides) {
2591
- if (base === void 0 && overrides === void 0) {
2592
- return void 0;
2593
- }
2594
- if (base === void 0) {
2595
- return overrides;
2596
- }
2597
- if (overrides === void 0) {
2598
- return base;
2599
- }
2600
- const result = { ...base };
2601
- for (const key in overrides) {
2602
- if (key === "__proto__" || key === "constructor" || key === "prototype") {
2603
- continue;
2604
- }
2605
- if (Object.prototype.hasOwnProperty.call(overrides, key)) {
2606
- const overridesValue = overrides[key];
2607
- if (overridesValue === void 0)
2608
- continue;
2609
- const baseValue = key in base ? base[key] : void 0;
2610
- const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
2611
- const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
2612
- if (isSourceObject && isTargetObject) {
2613
- result[key] = mergeObjects(
2614
- baseValue,
2615
- overridesValue
2616
- );
2617
- } else {
2618
- result[key] = overridesValue;
2619
- }
2620
- }
2621
- }
2622
- return result;
2623
- }
2624
-
2625
2633
  // src/util/now.ts
2626
2634
  function now() {
2627
2635
  var _a22, _b;
@@ -6520,11 +6528,32 @@ function processUIMessageStream({
6520
6528
  async transform(chunk, controller) {
6521
6529
  await runUpdateMessageJob(async ({ state, write }) => {
6522
6530
  var _a22, _b, _c, _d;
6531
+ function getCurrentStepParts() {
6532
+ const parts = state.message.parts;
6533
+ let currentStepStartIndex = parts.length - 1;
6534
+ while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
6535
+ currentStepStartIndex--;
6536
+ }
6537
+ return parts.slice(currentStepStartIndex + 1);
6538
+ }
6539
+ function getCurrentStepToolInvocations() {
6540
+ return getCurrentStepParts().filter(isToolUIPart);
6541
+ }
6523
6542
  function getToolInvocation(toolCallId) {
6524
- const toolInvocations = state.message.parts.filter(isToolUIPart);
6525
- const toolInvocation = toolInvocations.find(
6543
+ const toolInvocations = getCurrentStepToolInvocations();
6544
+ let toolInvocation = toolInvocations.find(
6526
6545
  (invocation) => invocation.toolCallId === toolCallId
6527
6546
  );
6547
+ if (toolInvocation == null) {
6548
+ const parts = state.message.parts;
6549
+ for (let i = parts.length - 1; i >= 0; i--) {
6550
+ const part = parts[i];
6551
+ if (isToolUIPart(part) && part.toolCallId === toolCallId) {
6552
+ toolInvocation = part;
6553
+ break;
6554
+ }
6555
+ }
6556
+ }
6528
6557
  if (toolInvocation == null) {
6529
6558
  throw new UIMessageStreamError({
6530
6559
  chunkType: "tool-invocation",
@@ -6551,9 +6580,9 @@ function processUIMessageStream({
6551
6580
  }
6552
6581
  return toolInvocation;
6553
6582
  }
6554
- function updateToolPart(options) {
6583
+ function updateToolPart(options, existingPart) {
6555
6584
  var _a23;
6556
- const part = state.message.parts.find(
6585
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6557
6586
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
6558
6587
  );
6559
6588
  const anyOptions = options;
@@ -6599,9 +6628,9 @@ function processUIMessageStream({
6599
6628
  });
6600
6629
  }
6601
6630
  }
6602
- function updateDynamicToolPart(options) {
6631
+ function updateDynamicToolPart(options, existingPart) {
6603
6632
  var _a23, _b2;
6604
- const part = state.message.parts.find(
6633
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6605
6634
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
6606
6635
  );
6607
6636
  const anyOptions = options;
@@ -6792,7 +6821,7 @@ function processUIMessageStream({
6792
6821
  break;
6793
6822
  }
6794
6823
  case "tool-input-start": {
6795
- const toolInvocations = state.message.parts.filter(isStaticToolUIPart);
6824
+ const toolInvocations = getCurrentStepParts().filter(isStaticToolUIPart);
6796
6825
  state.partialToolCalls[chunk.toolCallId] = {
6797
6826
  text: "",
6798
6827
  toolName: chunk.toolName,
@@ -6895,7 +6924,7 @@ function processUIMessageStream({
6895
6924
  break;
6896
6925
  }
6897
6926
  case "tool-input-error": {
6898
- const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
6927
+ const existingPart = getCurrentStepParts().filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
6899
6928
  const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
6900
6929
  if (isDynamic) {
6901
6930
  updateDynamicToolPart({
@@ -6966,31 +6995,37 @@ function processUIMessageStream({
6966
6995
  case "tool-output-available": {
6967
6996
  const toolInvocation = getToolInvocation(chunk.toolCallId);
6968
6997
  if (toolInvocation.type === "dynamic-tool") {
6969
- updateDynamicToolPart({
6970
- toolCallId: chunk.toolCallId,
6971
- toolName: toolInvocation.toolName,
6972
- state: "output-available",
6973
- input: toolInvocation.input,
6974
- output: chunk.output,
6975
- preliminary: chunk.preliminary,
6976
- providerExecuted: chunk.providerExecuted,
6977
- providerMetadata: chunk.providerMetadata,
6978
- title: toolInvocation.title,
6979
- toolMetadata: toolInvocation.toolMetadata
6980
- });
6998
+ updateDynamicToolPart(
6999
+ {
7000
+ toolCallId: chunk.toolCallId,
7001
+ toolName: toolInvocation.toolName,
7002
+ state: "output-available",
7003
+ input: toolInvocation.input,
7004
+ output: chunk.output,
7005
+ preliminary: chunk.preliminary,
7006
+ providerExecuted: chunk.providerExecuted,
7007
+ providerMetadata: chunk.providerMetadata,
7008
+ title: toolInvocation.title,
7009
+ toolMetadata: toolInvocation.toolMetadata
7010
+ },
7011
+ toolInvocation
7012
+ );
6981
7013
  } else {
6982
- updateToolPart({
6983
- toolCallId: chunk.toolCallId,
6984
- toolName: getStaticToolName(toolInvocation),
6985
- state: "output-available",
6986
- input: toolInvocation.input,
6987
- output: chunk.output,
6988
- providerExecuted: chunk.providerExecuted,
6989
- preliminary: chunk.preliminary,
6990
- providerMetadata: chunk.providerMetadata,
6991
- title: toolInvocation.title,
6992
- toolMetadata: toolInvocation.toolMetadata
6993
- });
7014
+ updateToolPart(
7015
+ {
7016
+ toolCallId: chunk.toolCallId,
7017
+ toolName: getStaticToolName(toolInvocation),
7018
+ state: "output-available",
7019
+ input: toolInvocation.input,
7020
+ output: chunk.output,
7021
+ providerExecuted: chunk.providerExecuted,
7022
+ preliminary: chunk.preliminary,
7023
+ providerMetadata: chunk.providerMetadata,
7024
+ title: toolInvocation.title,
7025
+ toolMetadata: toolInvocation.toolMetadata
7026
+ },
7027
+ toolInvocation
7028
+ );
6994
7029
  }
6995
7030
  write();
6996
7031
  break;
@@ -6998,30 +7033,36 @@ function processUIMessageStream({
6998
7033
  case "tool-output-error": {
6999
7034
  const toolInvocation = getToolInvocation(chunk.toolCallId);
7000
7035
  if (toolInvocation.type === "dynamic-tool") {
7001
- updateDynamicToolPart({
7002
- toolCallId: chunk.toolCallId,
7003
- toolName: toolInvocation.toolName,
7004
- state: "output-error",
7005
- input: toolInvocation.input,
7006
- errorText: chunk.errorText,
7007
- providerExecuted: chunk.providerExecuted,
7008
- providerMetadata: chunk.providerMetadata,
7009
- title: toolInvocation.title,
7010
- toolMetadata: toolInvocation.toolMetadata
7011
- });
7036
+ updateDynamicToolPart(
7037
+ {
7038
+ toolCallId: chunk.toolCallId,
7039
+ toolName: toolInvocation.toolName,
7040
+ state: "output-error",
7041
+ input: toolInvocation.input,
7042
+ errorText: chunk.errorText,
7043
+ providerExecuted: chunk.providerExecuted,
7044
+ providerMetadata: chunk.providerMetadata,
7045
+ title: toolInvocation.title,
7046
+ toolMetadata: toolInvocation.toolMetadata
7047
+ },
7048
+ toolInvocation
7049
+ );
7012
7050
  } else {
7013
- updateToolPart({
7014
- toolCallId: chunk.toolCallId,
7015
- toolName: getStaticToolName(toolInvocation),
7016
- state: "output-error",
7017
- input: toolInvocation.input,
7018
- rawInput: toolInvocation.rawInput,
7019
- errorText: chunk.errorText,
7020
- providerExecuted: chunk.providerExecuted,
7021
- providerMetadata: chunk.providerMetadata,
7022
- title: toolInvocation.title,
7023
- toolMetadata: toolInvocation.toolMetadata
7024
- });
7051
+ updateToolPart(
7052
+ {
7053
+ toolCallId: chunk.toolCallId,
7054
+ toolName: getStaticToolName(toolInvocation),
7055
+ state: "output-error",
7056
+ input: toolInvocation.input,
7057
+ rawInput: toolInvocation.rawInput,
7058
+ errorText: chunk.errorText,
7059
+ providerExecuted: chunk.providerExecuted,
7060
+ providerMetadata: chunk.providerMetadata,
7061
+ title: toolInvocation.title,
7062
+ toolMetadata: toolInvocation.toolMetadata
7063
+ },
7064
+ toolInvocation
7065
+ );
7025
7066
  }
7026
7067
  write();
7027
7068
  break;