ai 6.0.231 → 6.0.233

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/dist/index.mjs CHANGED
@@ -1081,7 +1081,17 @@ var audioMediaTypeSignatures = [
1081
1081
  },
1082
1082
  {
1083
1083
  mediaType: "audio/mp4",
1084
- bytesPrefix: [102, 116, 121, 112]
1084
+ bytesPrefix: [
1085
+ 0,
1086
+ 0,
1087
+ 0,
1088
+ null,
1089
+ 102,
1090
+ 116,
1091
+ 121,
1092
+ 112
1093
+ // ftyp
1094
+ ]
1085
1095
  },
1086
1096
  {
1087
1097
  mediaType: "audio/webm",
@@ -1171,7 +1181,7 @@ import {
1171
1181
  } from "@ai-sdk/provider-utils";
1172
1182
 
1173
1183
  // src/version.ts
1174
- var VERSION = true ? "6.0.231" : "0.0.0-test";
1184
+ var VERSION = true ? "6.0.233" : "0.0.0-test";
1175
1185
 
1176
1186
  // src/util/download/download.ts
1177
1187
  var download = async ({
@@ -1224,6 +1234,42 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
1224
1234
  )
1225
1235
  );
1226
1236
 
1237
+ // src/util/merge-objects.ts
1238
+ function mergeObjects(base, overrides) {
1239
+ if (base === void 0 && overrides === void 0) {
1240
+ return void 0;
1241
+ }
1242
+ if (base === void 0) {
1243
+ return overrides;
1244
+ }
1245
+ if (overrides === void 0) {
1246
+ return base;
1247
+ }
1248
+ const result = { ...base };
1249
+ for (const key in overrides) {
1250
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
1251
+ continue;
1252
+ }
1253
+ if (Object.prototype.hasOwnProperty.call(overrides, key)) {
1254
+ const overridesValue = overrides[key];
1255
+ if (overridesValue === void 0)
1256
+ continue;
1257
+ const baseValue = key in base ? base[key] : void 0;
1258
+ const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
1259
+ const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
1260
+ if (isSourceObject && isTargetObject) {
1261
+ result[key] = mergeObjects(
1262
+ baseValue,
1263
+ overridesValue
1264
+ );
1265
+ } else {
1266
+ result[key] = overridesValue;
1267
+ }
1268
+ }
1269
+ }
1270
+ return result;
1271
+ }
1272
+
1227
1273
  // src/prompt/data-content.ts
1228
1274
  import { AISDKError as AISDKError23 } from "@ai-sdk/provider";
1229
1275
  import {
@@ -1374,7 +1420,15 @@ async function convertToLanguageModelPrompt({
1374
1420
  }
1375
1421
  const lastCombinedMessage = combinedMessages.at(-1);
1376
1422
  if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
1423
+ const lastContentPart = lastCombinedMessage.content.at(-1);
1424
+ if (lastContentPart != null && lastCombinedMessage.providerOptions != null) {
1425
+ lastContentPart.providerOptions = mergeObjects(
1426
+ lastCombinedMessage.providerOptions,
1427
+ lastContentPart.providerOptions
1428
+ );
1429
+ }
1377
1430
  lastCombinedMessage.content.push(...message.content);
1431
+ lastCombinedMessage.providerOptions = message.providerOptions;
1378
1432
  } else {
1379
1433
  combinedMessages.push(message);
1380
1434
  }
@@ -2636,42 +2690,6 @@ function addImageModelUsage(usage1, usage2) {
2636
2690
  };
2637
2691
  }
2638
2692
 
2639
- // src/util/merge-objects.ts
2640
- function mergeObjects(base, overrides) {
2641
- if (base === void 0 && overrides === void 0) {
2642
- return void 0;
2643
- }
2644
- if (base === void 0) {
2645
- return overrides;
2646
- }
2647
- if (overrides === void 0) {
2648
- return base;
2649
- }
2650
- const result = { ...base };
2651
- for (const key in overrides) {
2652
- if (key === "__proto__" || key === "constructor" || key === "prototype") {
2653
- continue;
2654
- }
2655
- if (Object.prototype.hasOwnProperty.call(overrides, key)) {
2656
- const overridesValue = overrides[key];
2657
- if (overridesValue === void 0)
2658
- continue;
2659
- const baseValue = key in base ? base[key] : void 0;
2660
- const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
2661
- const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
2662
- if (isSourceObject && isTargetObject) {
2663
- result[key] = mergeObjects(
2664
- baseValue,
2665
- overridesValue
2666
- );
2667
- } else {
2668
- result[key] = overridesValue;
2669
- }
2670
- }
2671
- }
2672
- return result;
2673
- }
2674
-
2675
2693
  // src/util/retry-with-exponential-backoff.ts
2676
2694
  import { APICallError as APICallError2 } from "@ai-sdk/provider";
2677
2695
  import { GatewayError } from "@ai-sdk/gateway";
@@ -5704,11 +5722,32 @@ function processUIMessageStream({
5704
5722
  async transform(chunk, controller) {
5705
5723
  await runUpdateMessageJob(async ({ state, write }) => {
5706
5724
  var _a22, _b, _c, _d;
5725
+ function getCurrentStepParts() {
5726
+ const parts = state.message.parts;
5727
+ let currentStepStartIndex = parts.length - 1;
5728
+ while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
5729
+ currentStepStartIndex--;
5730
+ }
5731
+ return parts.slice(currentStepStartIndex + 1);
5732
+ }
5733
+ function getCurrentStepToolInvocations() {
5734
+ return getCurrentStepParts().filter(isToolUIPart);
5735
+ }
5707
5736
  function getToolInvocation(toolCallId) {
5708
- const toolInvocations = state.message.parts.filter(isToolUIPart);
5709
- const toolInvocation = toolInvocations.find(
5737
+ const toolInvocations = getCurrentStepToolInvocations();
5738
+ let toolInvocation = toolInvocations.find(
5710
5739
  (invocation) => invocation.toolCallId === toolCallId
5711
5740
  );
5741
+ if (toolInvocation == null) {
5742
+ const parts = state.message.parts;
5743
+ for (let i = parts.length - 1; i >= 0; i--) {
5744
+ const part = parts[i];
5745
+ if (isToolUIPart(part) && part.toolCallId === toolCallId) {
5746
+ toolInvocation = part;
5747
+ break;
5748
+ }
5749
+ }
5750
+ }
5712
5751
  if (toolInvocation == null) {
5713
5752
  throw new UIMessageStreamError({
5714
5753
  chunkType: "tool-invocation",
@@ -5718,9 +5757,9 @@ function processUIMessageStream({
5718
5757
  }
5719
5758
  return toolInvocation;
5720
5759
  }
5721
- function updateToolPart(options) {
5760
+ function updateToolPart(options, existingPart) {
5722
5761
  var _a23;
5723
- const part = state.message.parts.find(
5762
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
5724
5763
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
5725
5764
  );
5726
5765
  const anyOptions = options;
@@ -5766,9 +5805,9 @@ function processUIMessageStream({
5766
5805
  });
5767
5806
  }
5768
5807
  }
5769
- function updateDynamicToolPart(options) {
5808
+ function updateDynamicToolPart(options, existingPart) {
5770
5809
  var _a23, _b2;
5771
- const part = state.message.parts.find(
5810
+ const part = existingPart != null ? existingPart : getCurrentStepParts().find(
5772
5811
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
5773
5812
  );
5774
5813
  const anyOptions = options;
@@ -5948,7 +5987,7 @@ function processUIMessageStream({
5948
5987
  break;
5949
5988
  }
5950
5989
  case "tool-input-start": {
5951
- const toolInvocations = state.message.parts.filter(isStaticToolUIPart);
5990
+ const toolInvocations = getCurrentStepParts().filter(isStaticToolUIPart);
5952
5991
  state.partialToolCalls[chunk.toolCallId] = {
5953
5992
  text: "",
5954
5993
  toolName: chunk.toolName,
@@ -6051,7 +6090,7 @@ function processUIMessageStream({
6051
6090
  break;
6052
6091
  }
6053
6092
  case "tool-input-error": {
6054
- const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
6093
+ const existingPart = getCurrentStepParts().filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
6055
6094
  const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
6056
6095
  if (isDynamic) {
6057
6096
  updateDynamicToolPart({
@@ -6099,31 +6138,37 @@ function processUIMessageStream({
6099
6138
  case "tool-output-available": {
6100
6139
  const toolInvocation = getToolInvocation(chunk.toolCallId);
6101
6140
  if (toolInvocation.type === "dynamic-tool") {
6102
- updateDynamicToolPart({
6103
- toolCallId: chunk.toolCallId,
6104
- toolName: toolInvocation.toolName,
6105
- state: "output-available",
6106
- input: toolInvocation.input,
6107
- output: chunk.output,
6108
- preliminary: chunk.preliminary,
6109
- providerExecuted: chunk.providerExecuted,
6110
- providerMetadata: chunk.providerMetadata,
6111
- title: toolInvocation.title,
6112
- toolMetadata: toolInvocation.toolMetadata
6113
- });
6141
+ updateDynamicToolPart(
6142
+ {
6143
+ toolCallId: chunk.toolCallId,
6144
+ toolName: toolInvocation.toolName,
6145
+ state: "output-available",
6146
+ input: toolInvocation.input,
6147
+ output: chunk.output,
6148
+ preliminary: chunk.preliminary,
6149
+ providerExecuted: chunk.providerExecuted,
6150
+ providerMetadata: chunk.providerMetadata,
6151
+ title: toolInvocation.title,
6152
+ toolMetadata: toolInvocation.toolMetadata
6153
+ },
6154
+ toolInvocation
6155
+ );
6114
6156
  } else {
6115
- updateToolPart({
6116
- toolCallId: chunk.toolCallId,
6117
- toolName: getStaticToolName(toolInvocation),
6118
- state: "output-available",
6119
- input: toolInvocation.input,
6120
- output: chunk.output,
6121
- providerExecuted: chunk.providerExecuted,
6122
- preliminary: chunk.preliminary,
6123
- providerMetadata: chunk.providerMetadata,
6124
- title: toolInvocation.title,
6125
- toolMetadata: toolInvocation.toolMetadata
6126
- });
6157
+ updateToolPart(
6158
+ {
6159
+ toolCallId: chunk.toolCallId,
6160
+ toolName: getStaticToolName(toolInvocation),
6161
+ state: "output-available",
6162
+ input: toolInvocation.input,
6163
+ output: chunk.output,
6164
+ providerExecuted: chunk.providerExecuted,
6165
+ preliminary: chunk.preliminary,
6166
+ providerMetadata: chunk.providerMetadata,
6167
+ title: toolInvocation.title,
6168
+ toolMetadata: toolInvocation.toolMetadata
6169
+ },
6170
+ toolInvocation
6171
+ );
6127
6172
  }
6128
6173
  write();
6129
6174
  break;
@@ -6131,30 +6176,36 @@ function processUIMessageStream({
6131
6176
  case "tool-output-error": {
6132
6177
  const toolInvocation = getToolInvocation(chunk.toolCallId);
6133
6178
  if (toolInvocation.type === "dynamic-tool") {
6134
- updateDynamicToolPart({
6135
- toolCallId: chunk.toolCallId,
6136
- toolName: toolInvocation.toolName,
6137
- state: "output-error",
6138
- input: toolInvocation.input,
6139
- errorText: chunk.errorText,
6140
- providerExecuted: chunk.providerExecuted,
6141
- providerMetadata: chunk.providerMetadata,
6142
- title: toolInvocation.title,
6143
- toolMetadata: toolInvocation.toolMetadata
6144
- });
6179
+ updateDynamicToolPart(
6180
+ {
6181
+ toolCallId: chunk.toolCallId,
6182
+ toolName: toolInvocation.toolName,
6183
+ state: "output-error",
6184
+ input: toolInvocation.input,
6185
+ errorText: chunk.errorText,
6186
+ providerExecuted: chunk.providerExecuted,
6187
+ providerMetadata: chunk.providerMetadata,
6188
+ title: toolInvocation.title,
6189
+ toolMetadata: toolInvocation.toolMetadata
6190
+ },
6191
+ toolInvocation
6192
+ );
6145
6193
  } else {
6146
- updateToolPart({
6147
- toolCallId: chunk.toolCallId,
6148
- toolName: getStaticToolName(toolInvocation),
6149
- state: "output-error",
6150
- input: toolInvocation.input,
6151
- rawInput: toolInvocation.rawInput,
6152
- errorText: chunk.errorText,
6153
- providerExecuted: chunk.providerExecuted,
6154
- providerMetadata: chunk.providerMetadata,
6155
- title: toolInvocation.title,
6156
- toolMetadata: toolInvocation.toolMetadata
6157
- });
6194
+ updateToolPart(
6195
+ {
6196
+ toolCallId: chunk.toolCallId,
6197
+ toolName: getStaticToolName(toolInvocation),
6198
+ state: "output-error",
6199
+ input: toolInvocation.input,
6200
+ rawInput: toolInvocation.rawInput,
6201
+ errorText: chunk.errorText,
6202
+ providerExecuted: chunk.providerExecuted,
6203
+ providerMetadata: chunk.providerMetadata,
6204
+ title: toolInvocation.title,
6205
+ toolMetadata: toolInvocation.toolMetadata
6206
+ },
6207
+ toolInvocation
6208
+ );
6158
6209
  }
6159
6210
  write();
6160
6211
  break;