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 +19 -0
- package/dist/index.js +133 -92
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +45 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/03-ai-sdk-core/65-devtools.mdx +17 -2
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +1 -1
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +1 -1
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +2 -2
- 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/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.
|
|
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 =
|
|
6525
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
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
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
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
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
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
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
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;
|