ai 6.0.301 → 6.0.302
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 +14 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +75 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/docs/02-foundations/04-tools.mdx +1 -1
- package/docs/03-agents/06-memory.mdx +1 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
- package/docs/03-ai-sdk-core/45-provider-management.mdx +2 -2
- package/package.json +3 -3
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +6 -1
- package/src/ui/convert-to-model-messages.ts +41 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.302
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5430af1: fix(ai): preserve V2 provider-reported total tokens in raw usage
|
|
8
|
+
- f8d8324: fix(ai): publish the latest error after repeated failed stream resume attempts
|
|
9
|
+
- 5df41a7: fix(ai): prevent unavailable tools, including tools named after Object.prototype properties, from exposing persisted output to models
|
|
10
|
+
- 6a12ead: fix(ai): avoid duplicate slashes in chat reconnect URLs
|
|
11
|
+
- Updated dependencies [bedd5bb]
|
|
12
|
+
- Updated dependencies [6dd6693]
|
|
13
|
+
- Updated dependencies [5607cb2]
|
|
14
|
+
- Updated dependencies [fca8a28]
|
|
15
|
+
- @ai-sdk/gateway@3.0.211
|
|
16
|
+
|
|
3
17
|
## 6.0.301
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1836,6 +1836,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
|
|
1836
1836
|
}>;
|
|
1837
1837
|
type DynamicToolUIPart = {
|
|
1838
1838
|
type: 'dynamic-tool';
|
|
1839
|
+
/**
|
|
1840
|
+
* `false` when a static tool part was normalized to a dynamic tool part
|
|
1841
|
+
* because its current tool schema was unavailable or incompatible.
|
|
1842
|
+
*
|
|
1843
|
+
* This preserves its static origin across persistence boundaries.
|
|
1844
|
+
*/
|
|
1845
|
+
dynamic?: false;
|
|
1839
1846
|
/**
|
|
1840
1847
|
* Name of the tool that is being called.
|
|
1841
1848
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1836,6 +1836,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
|
|
1836
1836
|
}>;
|
|
1837
1837
|
type DynamicToolUIPart = {
|
|
1838
1838
|
type: 'dynamic-tool';
|
|
1839
|
+
/**
|
|
1840
|
+
* `false` when a static tool part was normalized to a dynamic tool part
|
|
1841
|
+
* because its current tool schema was unavailable or incompatible.
|
|
1842
|
+
*
|
|
1843
|
+
* This preserves its static origin across persistence boundaries.
|
|
1844
|
+
*/
|
|
1845
|
+
dynamic?: false;
|
|
1839
1846
|
/**
|
|
1840
1847
|
* Name of the tool that is being called.
|
|
1841
1848
|
*/
|
package/dist/index.js
CHANGED
|
@@ -895,7 +895,8 @@ function convertV2UsageToV3(usage) {
|
|
|
895
895
|
total: usage.outputTokens,
|
|
896
896
|
text: void 0,
|
|
897
897
|
reasoning: usage.reasoningTokens
|
|
898
|
-
}
|
|
898
|
+
},
|
|
899
|
+
raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
|
|
899
900
|
};
|
|
900
901
|
}
|
|
901
902
|
|
|
@@ -1334,7 +1335,7 @@ function detectMediaType({
|
|
|
1334
1335
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1335
1336
|
|
|
1336
1337
|
// src/version.ts
|
|
1337
|
-
var VERSION = true ? "6.0.
|
|
1338
|
+
var VERSION = true ? "6.0.302" : "0.0.0-test";
|
|
1338
1339
|
|
|
1339
1340
|
// src/util/download/download.ts
|
|
1340
1341
|
var download = async ({
|
|
@@ -2806,6 +2807,7 @@ function createNullLanguageModelUsage() {
|
|
|
2806
2807
|
}
|
|
2807
2808
|
function addLanguageModelUsage(usage1, usage2) {
|
|
2808
2809
|
var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2810
|
+
const raw = isNullLanguageModelUsage(usage1) ? usage2.raw : isNullLanguageModelUsage(usage2) ? usage1.raw : void 0;
|
|
2809
2811
|
return {
|
|
2810
2812
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
2811
2813
|
inputTokenDetails: {
|
|
@@ -2841,9 +2843,14 @@ function addLanguageModelUsage(usage1, usage2) {
|
|
|
2841
2843
|
cachedInputTokens: addTokenCounts(
|
|
2842
2844
|
usage1.cachedInputTokens,
|
|
2843
2845
|
usage2.cachedInputTokens
|
|
2844
|
-
)
|
|
2846
|
+
),
|
|
2847
|
+
...raw == null ? {} : { raw }
|
|
2845
2848
|
};
|
|
2846
2849
|
}
|
|
2850
|
+
function isNullLanguageModelUsage(usage) {
|
|
2851
|
+
var _a23, _b, _c, _d, _e;
|
|
2852
|
+
return usage.inputTokens == null && ((_a23 = usage.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens) == null && ((_b = usage.inputTokenDetails) == null ? void 0 : _b.cacheReadTokens) == null && ((_c = usage.inputTokenDetails) == null ? void 0 : _c.cacheWriteTokens) == null && usage.outputTokens == null && ((_d = usage.outputTokenDetails) == null ? void 0 : _d.textTokens) == null && ((_e = usage.outputTokenDetails) == null ? void 0 : _e.reasoningTokens) == null && usage.totalTokens == null && usage.raw == null;
|
|
2853
|
+
}
|
|
2847
2854
|
function addTokenCounts(tokenCount1, tokenCount2) {
|
|
2848
2855
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
|
2849
2856
|
}
|
|
@@ -9708,6 +9715,22 @@ function readUIMessageStream({
|
|
|
9708
9715
|
|
|
9709
9716
|
// src/ui/convert-to-model-messages.ts
|
|
9710
9717
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
9718
|
+
|
|
9719
|
+
// src/util/get-own.ts
|
|
9720
|
+
function getOwn(obj, key) {
|
|
9721
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
9722
|
+
}
|
|
9723
|
+
|
|
9724
|
+
// src/ui/unavailable-tool.ts
|
|
9725
|
+
function markToolPartAsUnavailable(part) {
|
|
9726
|
+
part.dynamic = false;
|
|
9727
|
+
return part;
|
|
9728
|
+
}
|
|
9729
|
+
function isToolPartFromUnavailableTool(part) {
|
|
9730
|
+
return part.type === "dynamic-tool" && part.dynamic === false;
|
|
9731
|
+
}
|
|
9732
|
+
|
|
9733
|
+
// src/ui/convert-to-model-messages.ts
|
|
9711
9734
|
async function convertToModelMessages(messages, options) {
|
|
9712
9735
|
const modelMessages = [];
|
|
9713
9736
|
if (options == null ? void 0 : options.ignoreIncompleteToolCalls) {
|
|
@@ -9718,6 +9741,27 @@ async function convertToModelMessages(messages, options) {
|
|
|
9718
9741
|
)
|
|
9719
9742
|
}));
|
|
9720
9743
|
}
|
|
9744
|
+
async function createModelOutput({
|
|
9745
|
+
toolPart,
|
|
9746
|
+
toolName,
|
|
9747
|
+
output,
|
|
9748
|
+
errorMode
|
|
9749
|
+
}) {
|
|
9750
|
+
const tool2 = getOwn(options == null ? void 0 : options.tools, toolName);
|
|
9751
|
+
if (errorMode === "none" && tool2 == null && isToolPartFromUnavailableTool(toolPart)) {
|
|
9752
|
+
return {
|
|
9753
|
+
type: "text",
|
|
9754
|
+
value: "Tool output omitted because the tool is no longer available."
|
|
9755
|
+
};
|
|
9756
|
+
}
|
|
9757
|
+
return createToolModelOutput({
|
|
9758
|
+
toolCallId: toolPart.toolCallId,
|
|
9759
|
+
input: toolPart.input,
|
|
9760
|
+
output,
|
|
9761
|
+
tool: tool2,
|
|
9762
|
+
errorMode
|
|
9763
|
+
});
|
|
9764
|
+
}
|
|
9721
9765
|
for (const message of messages) {
|
|
9722
9766
|
switch (message.role) {
|
|
9723
9767
|
case "system": {
|
|
@@ -9772,7 +9816,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9772
9816
|
if (message.parts != null) {
|
|
9773
9817
|
let block = [];
|
|
9774
9818
|
async function processBlock() {
|
|
9775
|
-
var _a23, _b, _c, _d, _e, _f, _g
|
|
9819
|
+
var _a23, _b, _c, _d, _e, _f, _g;
|
|
9776
9820
|
if (block.length === 0) {
|
|
9777
9821
|
return;
|
|
9778
9822
|
}
|
|
@@ -9830,11 +9874,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
9830
9874
|
type: "tool-result",
|
|
9831
9875
|
toolCallId: part.toolCallId,
|
|
9832
9876
|
toolName,
|
|
9833
|
-
output: await
|
|
9834
|
-
|
|
9835
|
-
|
|
9877
|
+
output: await createModelOutput({
|
|
9878
|
+
toolPart: part,
|
|
9879
|
+
toolName,
|
|
9836
9880
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
9837
|
-
tool: (_d = options == null ? void 0 : options.tools) == null ? void 0 : _d[toolName],
|
|
9838
9881
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
9839
9882
|
}),
|
|
9840
9883
|
...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
|
|
@@ -9842,7 +9885,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9842
9885
|
}
|
|
9843
9886
|
}
|
|
9844
9887
|
} else if (isDataUIPart(part)) {
|
|
9845
|
-
const dataPart = (
|
|
9888
|
+
const dataPart = (_d = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _d.call(
|
|
9846
9889
|
options,
|
|
9847
9890
|
part
|
|
9848
9891
|
);
|
|
@@ -9870,7 +9913,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9870
9913
|
{
|
|
9871
9914
|
const content2 = [];
|
|
9872
9915
|
for (const toolPart of toolParts) {
|
|
9873
|
-
if (((
|
|
9916
|
+
if (((_e = toolPart.approval) == null ? void 0 : _e.approved) != null) {
|
|
9874
9917
|
content2.push({
|
|
9875
9918
|
type: "tool-approval-response",
|
|
9876
9919
|
approvalId: toolPart.approval.id,
|
|
@@ -9890,7 +9933,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9890
9933
|
toolName: getToolName(toolPart),
|
|
9891
9934
|
output: {
|
|
9892
9935
|
type: "error-text",
|
|
9893
|
-
value: (
|
|
9936
|
+
value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool call execution denied."
|
|
9894
9937
|
},
|
|
9895
9938
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
9896
9939
|
});
|
|
@@ -9903,11 +9946,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
9903
9946
|
type: "tool-result",
|
|
9904
9947
|
toolCallId: toolPart.toolCallId,
|
|
9905
9948
|
toolName,
|
|
9906
|
-
output: await
|
|
9907
|
-
|
|
9908
|
-
|
|
9949
|
+
output: await createModelOutput({
|
|
9950
|
+
toolPart,
|
|
9951
|
+
toolName,
|
|
9909
9952
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
9910
|
-
tool: (_i = options == null ? void 0 : options.tools) == null ? void 0 : _i[toolName],
|
|
9911
9953
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
9912
9954
|
}),
|
|
9913
9955
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -9963,11 +10005,11 @@ function isEmptyObject(value) {
|
|
|
9963
10005
|
}
|
|
9964
10006
|
function asDynamicToolPart(toolPart) {
|
|
9965
10007
|
const { type, ...part } = toolPart;
|
|
9966
|
-
return {
|
|
10008
|
+
return markToolPartAsUnavailable({
|
|
9967
10009
|
...part,
|
|
9968
10010
|
type: "dynamic-tool",
|
|
9969
10011
|
toolName: type.slice(5)
|
|
9970
|
-
};
|
|
10012
|
+
});
|
|
9971
10013
|
}
|
|
9972
10014
|
function getToolPartInputSchemaInput(toolPart) {
|
|
9973
10015
|
return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
|
|
@@ -10044,6 +10086,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10044
10086
|
}),
|
|
10045
10087
|
import_v48.z.object({
|
|
10046
10088
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10089
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10047
10090
|
toolName: import_v48.z.string(),
|
|
10048
10091
|
toolCallId: import_v48.z.string(),
|
|
10049
10092
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10058,6 +10101,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10058
10101
|
}),
|
|
10059
10102
|
import_v48.z.object({
|
|
10060
10103
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10104
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10061
10105
|
toolName: import_v48.z.string(),
|
|
10062
10106
|
toolCallId: import_v48.z.string(),
|
|
10063
10107
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10071,6 +10115,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10071
10115
|
}),
|
|
10072
10116
|
import_v48.z.object({
|
|
10073
10117
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10118
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10074
10119
|
toolName: import_v48.z.string(),
|
|
10075
10120
|
toolCallId: import_v48.z.string(),
|
|
10076
10121
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10084,6 +10129,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10084
10129
|
}),
|
|
10085
10130
|
import_v48.z.object({
|
|
10086
10131
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10132
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10087
10133
|
toolName: import_v48.z.string(),
|
|
10088
10134
|
toolCallId: import_v48.z.string(),
|
|
10089
10135
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10097,6 +10143,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10097
10143
|
}),
|
|
10098
10144
|
import_v48.z.object({
|
|
10099
10145
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10146
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10100
10147
|
toolName: import_v48.z.string(),
|
|
10101
10148
|
toolCallId: import_v48.z.string(),
|
|
10102
10149
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10112,6 +10159,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10112
10159
|
}),
|
|
10113
10160
|
import_v48.z.object({
|
|
10114
10161
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10162
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10115
10163
|
toolName: import_v48.z.string(),
|
|
10116
10164
|
toolCallId: import_v48.z.string(),
|
|
10117
10165
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10127,6 +10175,7 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(() => {
|
|
|
10127
10175
|
}),
|
|
10128
10176
|
import_v48.z.object({
|
|
10129
10177
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10178
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10130
10179
|
toolName: import_v48.z.string(),
|
|
10131
10180
|
toolCallId: import_v48.z.string(),
|
|
10132
10181
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10315,7 +10364,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
10315
10364
|
if (shouldValidateToolParts && part.type.startsWith("tool-")) {
|
|
10316
10365
|
const toolPart = part;
|
|
10317
10366
|
const toolName = toolPart.type.slice(5);
|
|
10318
|
-
const tool2 = tools
|
|
10367
|
+
const tool2 = getOwn(tools, toolName);
|
|
10319
10368
|
const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
|
|
10320
10369
|
if (!tool2 && isTerminal) {
|
|
10321
10370
|
if (tools != null || convertMissingTerminalToolsToDynamic) {
|
|
@@ -10632,11 +10681,6 @@ var DefaultEmbedResult = class {
|
|
|
10632
10681
|
}
|
|
10633
10682
|
};
|
|
10634
10683
|
|
|
10635
|
-
// src/util/get-own.ts
|
|
10636
|
-
function getOwn(obj, key) {
|
|
10637
|
-
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
10638
|
-
}
|
|
10639
|
-
|
|
10640
10684
|
// src/util/set-own.ts
|
|
10641
10685
|
function setOwn(object2, key, value) {
|
|
10642
10686
|
Object.defineProperty(object2, key, {
|
|
@@ -14440,7 +14484,9 @@ var import_provider_utils42 = require("@ai-sdk/provider-utils");
|
|
|
14440
14484
|
var import_provider_utils41 = require("@ai-sdk/provider-utils");
|
|
14441
14485
|
function appendPathToUrl(url, path) {
|
|
14442
14486
|
const queryOrFragmentStart = url.search(/[?#]/);
|
|
14443
|
-
|
|
14487
|
+
const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
|
|
14488
|
+
const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
|
|
14489
|
+
return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
|
|
14444
14490
|
}
|
|
14445
14491
|
var HttpChatTransport = class {
|
|
14446
14492
|
constructor({
|
|
@@ -14834,8 +14880,12 @@ var AbstractChat = class {
|
|
|
14834
14880
|
status,
|
|
14835
14881
|
error
|
|
14836
14882
|
}) {
|
|
14837
|
-
if (this.status === status)
|
|
14883
|
+
if (this.status === status) {
|
|
14884
|
+
if (this.error !== error) {
|
|
14885
|
+
this.state.error = error;
|
|
14886
|
+
}
|
|
14838
14887
|
return;
|
|
14888
|
+
}
|
|
14839
14889
|
this.state.status = status;
|
|
14840
14890
|
this.state.error = error;
|
|
14841
14891
|
}
|