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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.233
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fe410e7: fix: detect MP4 audio from its ftyp box during transcription
|
|
8
|
+
- af7188c: fix(ai): preserve tool parts when tool call IDs repeat across steps
|
|
9
|
+
- Updated dependencies [a09f944]
|
|
10
|
+
- @ai-sdk/gateway@3.0.155
|
|
11
|
+
|
|
12
|
+
## 6.0.232
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 7644a61: Preserve provider options when combining consecutive tool messages.
|
|
17
|
+
|
|
3
18
|
## 6.0.231
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1200,7 +1200,17 @@ var audioMediaTypeSignatures = [
|
|
|
1200
1200
|
},
|
|
1201
1201
|
{
|
|
1202
1202
|
mediaType: "audio/mp4",
|
|
1203
|
-
bytesPrefix: [
|
|
1203
|
+
bytesPrefix: [
|
|
1204
|
+
0,
|
|
1205
|
+
0,
|
|
1206
|
+
0,
|
|
1207
|
+
null,
|
|
1208
|
+
102,
|
|
1209
|
+
116,
|
|
1210
|
+
121,
|
|
1211
|
+
112
|
|
1212
|
+
// ftyp
|
|
1213
|
+
]
|
|
1204
1214
|
},
|
|
1205
1215
|
{
|
|
1206
1216
|
mediaType: "audio/webm",
|
|
@@ -1282,7 +1292,7 @@ function detectMediaType({
|
|
|
1282
1292
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1283
1293
|
|
|
1284
1294
|
// src/version.ts
|
|
1285
|
-
var VERSION = true ? "6.0.
|
|
1295
|
+
var VERSION = true ? "6.0.233" : "0.0.0-test";
|
|
1286
1296
|
|
|
1287
1297
|
// src/util/download/download.ts
|
|
1288
1298
|
var download = async ({
|
|
@@ -1335,6 +1345,42 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
|
|
|
1335
1345
|
)
|
|
1336
1346
|
);
|
|
1337
1347
|
|
|
1348
|
+
// src/util/merge-objects.ts
|
|
1349
|
+
function mergeObjects(base, overrides) {
|
|
1350
|
+
if (base === void 0 && overrides === void 0) {
|
|
1351
|
+
return void 0;
|
|
1352
|
+
}
|
|
1353
|
+
if (base === void 0) {
|
|
1354
|
+
return overrides;
|
|
1355
|
+
}
|
|
1356
|
+
if (overrides === void 0) {
|
|
1357
|
+
return base;
|
|
1358
|
+
}
|
|
1359
|
+
const result = { ...base };
|
|
1360
|
+
for (const key in overrides) {
|
|
1361
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (Object.prototype.hasOwnProperty.call(overrides, key)) {
|
|
1365
|
+
const overridesValue = overrides[key];
|
|
1366
|
+
if (overridesValue === void 0)
|
|
1367
|
+
continue;
|
|
1368
|
+
const baseValue = key in base ? base[key] : void 0;
|
|
1369
|
+
const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
|
|
1370
|
+
const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
|
|
1371
|
+
if (isSourceObject && isTargetObject) {
|
|
1372
|
+
result[key] = mergeObjects(
|
|
1373
|
+
baseValue,
|
|
1374
|
+
overridesValue
|
|
1375
|
+
);
|
|
1376
|
+
} else {
|
|
1377
|
+
result[key] = overridesValue;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return result;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1338
1384
|
// src/prompt/data-content.ts
|
|
1339
1385
|
var import_provider23 = require("@ai-sdk/provider");
|
|
1340
1386
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
@@ -1482,7 +1528,15 @@ async function convertToLanguageModelPrompt({
|
|
|
1482
1528
|
}
|
|
1483
1529
|
const lastCombinedMessage = combinedMessages.at(-1);
|
|
1484
1530
|
if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
|
|
1531
|
+
const lastContentPart = lastCombinedMessage.content.at(-1);
|
|
1532
|
+
if (lastContentPart != null && lastCombinedMessage.providerOptions != null) {
|
|
1533
|
+
lastContentPart.providerOptions = mergeObjects(
|
|
1534
|
+
lastCombinedMessage.providerOptions,
|
|
1535
|
+
lastContentPart.providerOptions
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1485
1538
|
lastCombinedMessage.content.push(...message.content);
|
|
1539
|
+
lastCombinedMessage.providerOptions = message.providerOptions;
|
|
1486
1540
|
} else {
|
|
1487
1541
|
combinedMessages.push(message);
|
|
1488
1542
|
}
|
|
@@ -2739,42 +2793,6 @@ function addImageModelUsage(usage1, usage2) {
|
|
|
2739
2793
|
};
|
|
2740
2794
|
}
|
|
2741
2795
|
|
|
2742
|
-
// src/util/merge-objects.ts
|
|
2743
|
-
function mergeObjects(base, overrides) {
|
|
2744
|
-
if (base === void 0 && overrides === void 0) {
|
|
2745
|
-
return void 0;
|
|
2746
|
-
}
|
|
2747
|
-
if (base === void 0) {
|
|
2748
|
-
return overrides;
|
|
2749
|
-
}
|
|
2750
|
-
if (overrides === void 0) {
|
|
2751
|
-
return base;
|
|
2752
|
-
}
|
|
2753
|
-
const result = { ...base };
|
|
2754
|
-
for (const key in overrides) {
|
|
2755
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
2756
|
-
continue;
|
|
2757
|
-
}
|
|
2758
|
-
if (Object.prototype.hasOwnProperty.call(overrides, key)) {
|
|
2759
|
-
const overridesValue = overrides[key];
|
|
2760
|
-
if (overridesValue === void 0)
|
|
2761
|
-
continue;
|
|
2762
|
-
const baseValue = key in base ? base[key] : void 0;
|
|
2763
|
-
const isSourceObject = overridesValue !== null && typeof overridesValue === "object" && !Array.isArray(overridesValue) && !(overridesValue instanceof Date) && !(overridesValue instanceof RegExp);
|
|
2764
|
-
const isTargetObject = baseValue !== null && baseValue !== void 0 && typeof baseValue === "object" && !Array.isArray(baseValue) && !(baseValue instanceof Date) && !(baseValue instanceof RegExp);
|
|
2765
|
-
if (isSourceObject && isTargetObject) {
|
|
2766
|
-
result[key] = mergeObjects(
|
|
2767
|
-
baseValue,
|
|
2768
|
-
overridesValue
|
|
2769
|
-
);
|
|
2770
|
-
} else {
|
|
2771
|
-
result[key] = overridesValue;
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
return result;
|
|
2776
|
-
}
|
|
2777
|
-
|
|
2778
2796
|
// src/util/retry-with-exponential-backoff.ts
|
|
2779
2797
|
var import_provider27 = require("@ai-sdk/provider");
|
|
2780
2798
|
var import_gateway3 = require("@ai-sdk/gateway");
|
|
@@ -5778,11 +5796,32 @@ function processUIMessageStream({
|
|
|
5778
5796
|
async transform(chunk, controller) {
|
|
5779
5797
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
5780
5798
|
var _a22, _b, _c, _d;
|
|
5799
|
+
function getCurrentStepParts() {
|
|
5800
|
+
const parts = state.message.parts;
|
|
5801
|
+
let currentStepStartIndex = parts.length - 1;
|
|
5802
|
+
while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
|
|
5803
|
+
currentStepStartIndex--;
|
|
5804
|
+
}
|
|
5805
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
5806
|
+
}
|
|
5807
|
+
function getCurrentStepToolInvocations() {
|
|
5808
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
5809
|
+
}
|
|
5781
5810
|
function getToolInvocation(toolCallId) {
|
|
5782
|
-
const toolInvocations =
|
|
5783
|
-
|
|
5811
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
5812
|
+
let toolInvocation = toolInvocations.find(
|
|
5784
5813
|
(invocation) => invocation.toolCallId === toolCallId
|
|
5785
5814
|
);
|
|
5815
|
+
if (toolInvocation == null) {
|
|
5816
|
+
const parts = state.message.parts;
|
|
5817
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
5818
|
+
const part = parts[i];
|
|
5819
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
5820
|
+
toolInvocation = part;
|
|
5821
|
+
break;
|
|
5822
|
+
}
|
|
5823
|
+
}
|
|
5824
|
+
}
|
|
5786
5825
|
if (toolInvocation == null) {
|
|
5787
5826
|
throw new UIMessageStreamError({
|
|
5788
5827
|
chunkType: "tool-invocation",
|
|
@@ -5792,9 +5831,9 @@ function processUIMessageStream({
|
|
|
5792
5831
|
}
|
|
5793
5832
|
return toolInvocation;
|
|
5794
5833
|
}
|
|
5795
|
-
function updateToolPart(options) {
|
|
5834
|
+
function updateToolPart(options, existingPart) {
|
|
5796
5835
|
var _a23;
|
|
5797
|
-
const part =
|
|
5836
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5798
5837
|
(part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
5799
5838
|
);
|
|
5800
5839
|
const anyOptions = options;
|
|
@@ -5840,9 +5879,9 @@ function processUIMessageStream({
|
|
|
5840
5879
|
});
|
|
5841
5880
|
}
|
|
5842
5881
|
}
|
|
5843
|
-
function updateDynamicToolPart(options) {
|
|
5882
|
+
function updateDynamicToolPart(options, existingPart) {
|
|
5844
5883
|
var _a23, _b2;
|
|
5845
|
-
const part =
|
|
5884
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5846
5885
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
5847
5886
|
);
|
|
5848
5887
|
const anyOptions = options;
|
|
@@ -6022,7 +6061,7 @@ function processUIMessageStream({
|
|
|
6022
6061
|
break;
|
|
6023
6062
|
}
|
|
6024
6063
|
case "tool-input-start": {
|
|
6025
|
-
const toolInvocations =
|
|
6064
|
+
const toolInvocations = getCurrentStepParts().filter(isStaticToolUIPart);
|
|
6026
6065
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
6027
6066
|
text: "",
|
|
6028
6067
|
toolName: chunk.toolName,
|
|
@@ -6125,7 +6164,7 @@ function processUIMessageStream({
|
|
|
6125
6164
|
break;
|
|
6126
6165
|
}
|
|
6127
6166
|
case "tool-input-error": {
|
|
6128
|
-
const existingPart =
|
|
6167
|
+
const existingPart = getCurrentStepParts().filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
|
|
6129
6168
|
const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
|
|
6130
6169
|
if (isDynamic) {
|
|
6131
6170
|
updateDynamicToolPart({
|
|
@@ -6173,31 +6212,37 @@ function processUIMessageStream({
|
|
|
6173
6212
|
case "tool-output-available": {
|
|
6174
6213
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
6175
6214
|
if (toolInvocation.type === "dynamic-tool") {
|
|
6176
|
-
updateDynamicToolPart(
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6215
|
+
updateDynamicToolPart(
|
|
6216
|
+
{
|
|
6217
|
+
toolCallId: chunk.toolCallId,
|
|
6218
|
+
toolName: toolInvocation.toolName,
|
|
6219
|
+
state: "output-available",
|
|
6220
|
+
input: toolInvocation.input,
|
|
6221
|
+
output: chunk.output,
|
|
6222
|
+
preliminary: chunk.preliminary,
|
|
6223
|
+
providerExecuted: chunk.providerExecuted,
|
|
6224
|
+
providerMetadata: chunk.providerMetadata,
|
|
6225
|
+
title: toolInvocation.title,
|
|
6226
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6227
|
+
},
|
|
6228
|
+
toolInvocation
|
|
6229
|
+
);
|
|
6188
6230
|
} else {
|
|
6189
|
-
updateToolPart(
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6231
|
+
updateToolPart(
|
|
6232
|
+
{
|
|
6233
|
+
toolCallId: chunk.toolCallId,
|
|
6234
|
+
toolName: getStaticToolName(toolInvocation),
|
|
6235
|
+
state: "output-available",
|
|
6236
|
+
input: toolInvocation.input,
|
|
6237
|
+
output: chunk.output,
|
|
6238
|
+
providerExecuted: chunk.providerExecuted,
|
|
6239
|
+
preliminary: chunk.preliminary,
|
|
6240
|
+
providerMetadata: chunk.providerMetadata,
|
|
6241
|
+
title: toolInvocation.title,
|
|
6242
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6243
|
+
},
|
|
6244
|
+
toolInvocation
|
|
6245
|
+
);
|
|
6201
6246
|
}
|
|
6202
6247
|
write();
|
|
6203
6248
|
break;
|
|
@@ -6205,30 +6250,36 @@ function processUIMessageStream({
|
|
|
6205
6250
|
case "tool-output-error": {
|
|
6206
6251
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
6207
6252
|
if (toolInvocation.type === "dynamic-tool") {
|
|
6208
|
-
updateDynamicToolPart(
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6253
|
+
updateDynamicToolPart(
|
|
6254
|
+
{
|
|
6255
|
+
toolCallId: chunk.toolCallId,
|
|
6256
|
+
toolName: toolInvocation.toolName,
|
|
6257
|
+
state: "output-error",
|
|
6258
|
+
input: toolInvocation.input,
|
|
6259
|
+
errorText: chunk.errorText,
|
|
6260
|
+
providerExecuted: chunk.providerExecuted,
|
|
6261
|
+
providerMetadata: chunk.providerMetadata,
|
|
6262
|
+
title: toolInvocation.title,
|
|
6263
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6264
|
+
},
|
|
6265
|
+
toolInvocation
|
|
6266
|
+
);
|
|
6219
6267
|
} else {
|
|
6220
|
-
updateToolPart(
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6268
|
+
updateToolPart(
|
|
6269
|
+
{
|
|
6270
|
+
toolCallId: chunk.toolCallId,
|
|
6271
|
+
toolName: getStaticToolName(toolInvocation),
|
|
6272
|
+
state: "output-error",
|
|
6273
|
+
input: toolInvocation.input,
|
|
6274
|
+
rawInput: toolInvocation.rawInput,
|
|
6275
|
+
errorText: chunk.errorText,
|
|
6276
|
+
providerExecuted: chunk.providerExecuted,
|
|
6277
|
+
providerMetadata: chunk.providerMetadata,
|
|
6278
|
+
title: toolInvocation.title,
|
|
6279
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6280
|
+
},
|
|
6281
|
+
toolInvocation
|
|
6282
|
+
);
|
|
6232
6283
|
}
|
|
6233
6284
|
write();
|
|
6234
6285
|
break;
|