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/CHANGELOG.md +15 -0
- package/dist/index.js +144 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -93
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +45 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +45 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/prompt/convert-to-language-model-prompt.ts +13 -0
- package/src/ui/process-ui-message-stream.ts +109 -61
- package/src/util/detect-media-type.ts +10 -1
package/dist/index.mjs
CHANGED
|
@@ -1081,7 +1081,17 @@ var audioMediaTypeSignatures = [
|
|
|
1081
1081
|
},
|
|
1082
1082
|
{
|
|
1083
1083
|
mediaType: "audio/mp4",
|
|
1084
|
-
bytesPrefix: [
|
|
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.
|
|
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 =
|
|
5709
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
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
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
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
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
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
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
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;
|