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/dist/index.mjs
CHANGED
|
@@ -775,7 +775,8 @@ function convertV2UsageToV3(usage) {
|
|
|
775
775
|
total: usage.outputTokens,
|
|
776
776
|
text: void 0,
|
|
777
777
|
reasoning: usage.reasoningTokens
|
|
778
|
-
}
|
|
778
|
+
},
|
|
779
|
+
raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
|
|
779
780
|
};
|
|
780
781
|
}
|
|
781
782
|
|
|
@@ -1224,7 +1225,7 @@ import {
|
|
|
1224
1225
|
} from "@ai-sdk/provider-utils";
|
|
1225
1226
|
|
|
1226
1227
|
// src/version.ts
|
|
1227
|
-
var VERSION = true ? "6.0.
|
|
1228
|
+
var VERSION = true ? "6.0.302" : "0.0.0-test";
|
|
1228
1229
|
|
|
1229
1230
|
// src/util/download/download.ts
|
|
1230
1231
|
var download = async ({
|
|
@@ -2704,6 +2705,7 @@ function createNullLanguageModelUsage() {
|
|
|
2704
2705
|
}
|
|
2705
2706
|
function addLanguageModelUsage(usage1, usage2) {
|
|
2706
2707
|
var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2708
|
+
const raw = isNullLanguageModelUsage(usage1) ? usage2.raw : isNullLanguageModelUsage(usage2) ? usage1.raw : void 0;
|
|
2707
2709
|
return {
|
|
2708
2710
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
2709
2711
|
inputTokenDetails: {
|
|
@@ -2739,9 +2741,14 @@ function addLanguageModelUsage(usage1, usage2) {
|
|
|
2739
2741
|
cachedInputTokens: addTokenCounts(
|
|
2740
2742
|
usage1.cachedInputTokens,
|
|
2741
2743
|
usage2.cachedInputTokens
|
|
2742
|
-
)
|
|
2744
|
+
),
|
|
2745
|
+
...raw == null ? {} : { raw }
|
|
2743
2746
|
};
|
|
2744
2747
|
}
|
|
2748
|
+
function isNullLanguageModelUsage(usage) {
|
|
2749
|
+
var _a23, _b, _c, _d, _e;
|
|
2750
|
+
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;
|
|
2751
|
+
}
|
|
2745
2752
|
function addTokenCounts(tokenCount1, tokenCount2) {
|
|
2746
2753
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
|
2747
2754
|
}
|
|
@@ -9641,6 +9648,22 @@ function readUIMessageStream({
|
|
|
9641
9648
|
import {
|
|
9642
9649
|
isNonNullable
|
|
9643
9650
|
} from "@ai-sdk/provider-utils";
|
|
9651
|
+
|
|
9652
|
+
// src/util/get-own.ts
|
|
9653
|
+
function getOwn(obj, key) {
|
|
9654
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
9655
|
+
}
|
|
9656
|
+
|
|
9657
|
+
// src/ui/unavailable-tool.ts
|
|
9658
|
+
function markToolPartAsUnavailable(part) {
|
|
9659
|
+
part.dynamic = false;
|
|
9660
|
+
return part;
|
|
9661
|
+
}
|
|
9662
|
+
function isToolPartFromUnavailableTool(part) {
|
|
9663
|
+
return part.type === "dynamic-tool" && part.dynamic === false;
|
|
9664
|
+
}
|
|
9665
|
+
|
|
9666
|
+
// src/ui/convert-to-model-messages.ts
|
|
9644
9667
|
async function convertToModelMessages(messages, options) {
|
|
9645
9668
|
const modelMessages = [];
|
|
9646
9669
|
if (options == null ? void 0 : options.ignoreIncompleteToolCalls) {
|
|
@@ -9651,6 +9674,27 @@ async function convertToModelMessages(messages, options) {
|
|
|
9651
9674
|
)
|
|
9652
9675
|
}));
|
|
9653
9676
|
}
|
|
9677
|
+
async function createModelOutput({
|
|
9678
|
+
toolPart,
|
|
9679
|
+
toolName,
|
|
9680
|
+
output,
|
|
9681
|
+
errorMode
|
|
9682
|
+
}) {
|
|
9683
|
+
const tool2 = getOwn(options == null ? void 0 : options.tools, toolName);
|
|
9684
|
+
if (errorMode === "none" && tool2 == null && isToolPartFromUnavailableTool(toolPart)) {
|
|
9685
|
+
return {
|
|
9686
|
+
type: "text",
|
|
9687
|
+
value: "Tool output omitted because the tool is no longer available."
|
|
9688
|
+
};
|
|
9689
|
+
}
|
|
9690
|
+
return createToolModelOutput({
|
|
9691
|
+
toolCallId: toolPart.toolCallId,
|
|
9692
|
+
input: toolPart.input,
|
|
9693
|
+
output,
|
|
9694
|
+
tool: tool2,
|
|
9695
|
+
errorMode
|
|
9696
|
+
});
|
|
9697
|
+
}
|
|
9654
9698
|
for (const message of messages) {
|
|
9655
9699
|
switch (message.role) {
|
|
9656
9700
|
case "system": {
|
|
@@ -9705,7 +9749,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9705
9749
|
if (message.parts != null) {
|
|
9706
9750
|
let block = [];
|
|
9707
9751
|
async function processBlock() {
|
|
9708
|
-
var _a23, _b, _c, _d, _e, _f, _g
|
|
9752
|
+
var _a23, _b, _c, _d, _e, _f, _g;
|
|
9709
9753
|
if (block.length === 0) {
|
|
9710
9754
|
return;
|
|
9711
9755
|
}
|
|
@@ -9763,11 +9807,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
9763
9807
|
type: "tool-result",
|
|
9764
9808
|
toolCallId: part.toolCallId,
|
|
9765
9809
|
toolName,
|
|
9766
|
-
output: await
|
|
9767
|
-
|
|
9768
|
-
|
|
9810
|
+
output: await createModelOutput({
|
|
9811
|
+
toolPart: part,
|
|
9812
|
+
toolName,
|
|
9769
9813
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
9770
|
-
tool: (_d = options == null ? void 0 : options.tools) == null ? void 0 : _d[toolName],
|
|
9771
9814
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
9772
9815
|
}),
|
|
9773
9816
|
...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
|
|
@@ -9775,7 +9818,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9775
9818
|
}
|
|
9776
9819
|
}
|
|
9777
9820
|
} else if (isDataUIPart(part)) {
|
|
9778
|
-
const dataPart = (
|
|
9821
|
+
const dataPart = (_d = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _d.call(
|
|
9779
9822
|
options,
|
|
9780
9823
|
part
|
|
9781
9824
|
);
|
|
@@ -9803,7 +9846,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9803
9846
|
{
|
|
9804
9847
|
const content2 = [];
|
|
9805
9848
|
for (const toolPart of toolParts) {
|
|
9806
|
-
if (((
|
|
9849
|
+
if (((_e = toolPart.approval) == null ? void 0 : _e.approved) != null) {
|
|
9807
9850
|
content2.push({
|
|
9808
9851
|
type: "tool-approval-response",
|
|
9809
9852
|
approvalId: toolPart.approval.id,
|
|
@@ -9823,7 +9866,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9823
9866
|
toolName: getToolName(toolPart),
|
|
9824
9867
|
output: {
|
|
9825
9868
|
type: "error-text",
|
|
9826
|
-
value: (
|
|
9869
|
+
value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool call execution denied."
|
|
9827
9870
|
},
|
|
9828
9871
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
9829
9872
|
});
|
|
@@ -9836,11 +9879,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
9836
9879
|
type: "tool-result",
|
|
9837
9880
|
toolCallId: toolPart.toolCallId,
|
|
9838
9881
|
toolName,
|
|
9839
|
-
output: await
|
|
9840
|
-
|
|
9841
|
-
|
|
9882
|
+
output: await createModelOutput({
|
|
9883
|
+
toolPart,
|
|
9884
|
+
toolName,
|
|
9842
9885
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
9843
|
-
tool: (_i = options == null ? void 0 : options.tools) == null ? void 0 : _i[toolName],
|
|
9844
9886
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
9845
9887
|
}),
|
|
9846
9888
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -9903,11 +9945,11 @@ function isEmptyObject(value) {
|
|
|
9903
9945
|
}
|
|
9904
9946
|
function asDynamicToolPart(toolPart) {
|
|
9905
9947
|
const { type, ...part } = toolPart;
|
|
9906
|
-
return {
|
|
9948
|
+
return markToolPartAsUnavailable({
|
|
9907
9949
|
...part,
|
|
9908
9950
|
type: "dynamic-tool",
|
|
9909
9951
|
toolName: type.slice(5)
|
|
9910
|
-
};
|
|
9952
|
+
});
|
|
9911
9953
|
}
|
|
9912
9954
|
function getToolPartInputSchemaInput(toolPart) {
|
|
9913
9955
|
return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
|
|
@@ -9984,6 +10026,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
9984
10026
|
}),
|
|
9985
10027
|
z8.object({
|
|
9986
10028
|
type: z8.literal("dynamic-tool"),
|
|
10029
|
+
dynamic: z8.literal(false).optional(),
|
|
9987
10030
|
toolName: z8.string(),
|
|
9988
10031
|
toolCallId: z8.string(),
|
|
9989
10032
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -9998,6 +10041,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
9998
10041
|
}),
|
|
9999
10042
|
z8.object({
|
|
10000
10043
|
type: z8.literal("dynamic-tool"),
|
|
10044
|
+
dynamic: z8.literal(false).optional(),
|
|
10001
10045
|
toolName: z8.string(),
|
|
10002
10046
|
toolCallId: z8.string(),
|
|
10003
10047
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10011,6 +10055,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
10011
10055
|
}),
|
|
10012
10056
|
z8.object({
|
|
10013
10057
|
type: z8.literal("dynamic-tool"),
|
|
10058
|
+
dynamic: z8.literal(false).optional(),
|
|
10014
10059
|
toolName: z8.string(),
|
|
10015
10060
|
toolCallId: z8.string(),
|
|
10016
10061
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10024,6 +10069,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
10024
10069
|
}),
|
|
10025
10070
|
z8.object({
|
|
10026
10071
|
type: z8.literal("dynamic-tool"),
|
|
10072
|
+
dynamic: z8.literal(false).optional(),
|
|
10027
10073
|
toolName: z8.string(),
|
|
10028
10074
|
toolCallId: z8.string(),
|
|
10029
10075
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10037,6 +10083,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
10037
10083
|
}),
|
|
10038
10084
|
z8.object({
|
|
10039
10085
|
type: z8.literal("dynamic-tool"),
|
|
10086
|
+
dynamic: z8.literal(false).optional(),
|
|
10040
10087
|
toolName: z8.string(),
|
|
10041
10088
|
toolCallId: z8.string(),
|
|
10042
10089
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10052,6 +10099,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
10052
10099
|
}),
|
|
10053
10100
|
z8.object({
|
|
10054
10101
|
type: z8.literal("dynamic-tool"),
|
|
10102
|
+
dynamic: z8.literal(false).optional(),
|
|
10055
10103
|
toolName: z8.string(),
|
|
10056
10104
|
toolCallId: z8.string(),
|
|
10057
10105
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10067,6 +10115,7 @@ var uiMessagesSchema = lazySchema2(() => {
|
|
|
10067
10115
|
}),
|
|
10068
10116
|
z8.object({
|
|
10069
10117
|
type: z8.literal("dynamic-tool"),
|
|
10118
|
+
dynamic: z8.literal(false).optional(),
|
|
10070
10119
|
toolName: z8.string(),
|
|
10071
10120
|
toolCallId: z8.string(),
|
|
10072
10121
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
@@ -10255,7 +10304,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
10255
10304
|
if (shouldValidateToolParts && part.type.startsWith("tool-")) {
|
|
10256
10305
|
const toolPart = part;
|
|
10257
10306
|
const toolName = toolPart.type.slice(5);
|
|
10258
|
-
const tool2 = tools
|
|
10307
|
+
const tool2 = getOwn(tools, toolName);
|
|
10259
10308
|
const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
|
|
10260
10309
|
if (!tool2 && isTerminal) {
|
|
10261
10310
|
if (tools != null || convertMissingTerminalToolsToDynamic) {
|
|
@@ -10574,11 +10623,6 @@ var DefaultEmbedResult = class {
|
|
|
10574
10623
|
}
|
|
10575
10624
|
};
|
|
10576
10625
|
|
|
10577
|
-
// src/util/get-own.ts
|
|
10578
|
-
function getOwn(obj, key) {
|
|
10579
|
-
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
10580
|
-
}
|
|
10581
|
-
|
|
10582
10626
|
// src/util/set-own.ts
|
|
10583
10627
|
function setOwn(object2, key, value) {
|
|
10584
10628
|
Object.defineProperty(object2, key, {
|
|
@@ -14430,7 +14474,9 @@ import {
|
|
|
14430
14474
|
} from "@ai-sdk/provider-utils";
|
|
14431
14475
|
function appendPathToUrl(url, path) {
|
|
14432
14476
|
const queryOrFragmentStart = url.search(/[?#]/);
|
|
14433
|
-
|
|
14477
|
+
const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
|
|
14478
|
+
const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
|
|
14479
|
+
return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
|
|
14434
14480
|
}
|
|
14435
14481
|
var HttpChatTransport = class {
|
|
14436
14482
|
constructor({
|
|
@@ -14824,8 +14870,12 @@ var AbstractChat = class {
|
|
|
14824
14870
|
status,
|
|
14825
14871
|
error
|
|
14826
14872
|
}) {
|
|
14827
|
-
if (this.status === status)
|
|
14873
|
+
if (this.status === status) {
|
|
14874
|
+
if (this.error !== error) {
|
|
14875
|
+
this.state.error = error;
|
|
14876
|
+
}
|
|
14828
14877
|
return;
|
|
14878
|
+
}
|
|
14829
14879
|
this.state.status = status;
|
|
14830
14880
|
this.state.error = error;
|
|
14831
14881
|
}
|