ai 6.0.0-beta.49 → 6.0.0-beta.51
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 +17 -0
- package/dist/index.d.mts +29 -16
- package/dist/index.d.ts +29 -16
- package/dist/index.js +77 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -46
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -104,6 +104,7 @@ import {
|
|
|
104
104
|
InvalidResponseDataError,
|
|
105
105
|
JSONParseError,
|
|
106
106
|
LoadAPIKeyError,
|
|
107
|
+
LoadSettingError,
|
|
107
108
|
NoContentGeneratedError,
|
|
108
109
|
NoSuchModelError,
|
|
109
110
|
TooManyEmbeddingValuesForCallError,
|
|
@@ -774,7 +775,7 @@ import {
|
|
|
774
775
|
} from "@ai-sdk/provider-utils";
|
|
775
776
|
|
|
776
777
|
// src/version.ts
|
|
777
|
-
var VERSION = true ? "6.0.0-beta.
|
|
778
|
+
var VERSION = true ? "6.0.0-beta.51" : "0.0.0-test";
|
|
778
779
|
|
|
779
780
|
// src/util/download/download.ts
|
|
780
781
|
var download = async ({ url }) => {
|
|
@@ -2186,6 +2187,9 @@ async function parseToolCall({
|
|
|
2186
2187
|
}) {
|
|
2187
2188
|
try {
|
|
2188
2189
|
if (tools == null) {
|
|
2190
|
+
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
2191
|
+
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
2192
|
+
}
|
|
2189
2193
|
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
|
2190
2194
|
}
|
|
2191
2195
|
try {
|
|
@@ -2232,6 +2236,25 @@ async function parseToolCall({
|
|
|
2232
2236
|
};
|
|
2233
2237
|
}
|
|
2234
2238
|
}
|
|
2239
|
+
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
2240
|
+
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON({ text: toolCall.input });
|
|
2241
|
+
if (parseResult.success === false) {
|
|
2242
|
+
throw new InvalidToolInputError({
|
|
2243
|
+
toolName: toolCall.toolName,
|
|
2244
|
+
toolInput: toolCall.input,
|
|
2245
|
+
cause: parseResult.error
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
return {
|
|
2249
|
+
type: "tool-call",
|
|
2250
|
+
toolCallId: toolCall.toolCallId,
|
|
2251
|
+
toolName: toolCall.toolName,
|
|
2252
|
+
input: parseResult.value,
|
|
2253
|
+
providerExecuted: true,
|
|
2254
|
+
dynamic: true,
|
|
2255
|
+
providerMetadata: toolCall.providerMetadata
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2235
2258
|
async function doParseToolCall({
|
|
2236
2259
|
toolCall,
|
|
2237
2260
|
tools
|
|
@@ -2239,6 +2262,9 @@ async function doParseToolCall({
|
|
|
2239
2262
|
const toolName = toolCall.toolName;
|
|
2240
2263
|
const tool3 = tools[toolName];
|
|
2241
2264
|
if (tool3 == null) {
|
|
2265
|
+
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
2266
|
+
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
2267
|
+
}
|
|
2242
2268
|
throw new NoSuchToolError({
|
|
2243
2269
|
toolName: toolCall.toolName,
|
|
2244
2270
|
availableTools: Object.keys(tools)
|
|
@@ -2713,7 +2739,10 @@ async function generateText({
|
|
|
2713
2739
|
if (toolCall.invalid) {
|
|
2714
2740
|
continue;
|
|
2715
2741
|
}
|
|
2716
|
-
const tool3 = tools[toolCall.toolName];
|
|
2742
|
+
const tool3 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
2743
|
+
if (tool3 == null) {
|
|
2744
|
+
continue;
|
|
2745
|
+
}
|
|
2717
2746
|
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
2718
2747
|
await tool3.onInputAvailable({
|
|
2719
2748
|
input: toolCall.input,
|
|
@@ -3823,7 +3852,7 @@ function processUIMessageStream({
|
|
|
3823
3852
|
}
|
|
3824
3853
|
}
|
|
3825
3854
|
function updateDynamicToolPart(options) {
|
|
3826
|
-
var _a18;
|
|
3855
|
+
var _a18, _b2;
|
|
3827
3856
|
const part = state.message.parts.find(
|
|
3828
3857
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
3829
3858
|
);
|
|
@@ -3837,6 +3866,7 @@ function processUIMessageStream({
|
|
|
3837
3866
|
anyPart.errorText = anyOptions.errorText;
|
|
3838
3867
|
anyPart.rawInput = (_a18 = anyOptions.rawInput) != null ? _a18 : anyPart.rawInput;
|
|
3839
3868
|
anyPart.preliminary = anyOptions.preliminary;
|
|
3869
|
+
anyPart.providerExecuted = (_b2 = anyOptions.providerExecuted) != null ? _b2 : part.providerExecuted;
|
|
3840
3870
|
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
|
3841
3871
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
3842
3872
|
}
|
|
@@ -3850,6 +3880,7 @@ function processUIMessageStream({
|
|
|
3850
3880
|
output: anyOptions.output,
|
|
3851
3881
|
errorText: anyOptions.errorText,
|
|
3852
3882
|
preliminary: anyOptions.preliminary,
|
|
3883
|
+
providerExecuted: anyOptions.providerExecuted,
|
|
3853
3884
|
...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
|
|
3854
3885
|
});
|
|
3855
3886
|
}
|
|
@@ -3966,7 +3997,8 @@ function processUIMessageStream({
|
|
|
3966
3997
|
toolCallId: chunk.toolCallId,
|
|
3967
3998
|
toolName: chunk.toolName,
|
|
3968
3999
|
state: "input-streaming",
|
|
3969
|
-
input: void 0
|
|
4000
|
+
input: void 0,
|
|
4001
|
+
providerExecuted: chunk.providerExecuted
|
|
3970
4002
|
});
|
|
3971
4003
|
} else {
|
|
3972
4004
|
updateToolPart({
|
|
@@ -4011,6 +4043,7 @@ function processUIMessageStream({
|
|
|
4011
4043
|
toolName: chunk.toolName,
|
|
4012
4044
|
state: "input-available",
|
|
4013
4045
|
input: chunk.input,
|
|
4046
|
+
providerExecuted: chunk.providerExecuted,
|
|
4014
4047
|
providerMetadata: chunk.providerMetadata
|
|
4015
4048
|
});
|
|
4016
4049
|
} else {
|
|
@@ -4039,6 +4072,7 @@ function processUIMessageStream({
|
|
|
4039
4072
|
state: "output-error",
|
|
4040
4073
|
input: chunk.input,
|
|
4041
4074
|
errorText: chunk.errorText,
|
|
4075
|
+
providerExecuted: chunk.providerExecuted,
|
|
4042
4076
|
providerMetadata: chunk.providerMetadata
|
|
4043
4077
|
});
|
|
4044
4078
|
} else {
|
|
@@ -4078,7 +4112,8 @@ function processUIMessageStream({
|
|
|
4078
4112
|
state: "output-available",
|
|
4079
4113
|
input: toolInvocation.input,
|
|
4080
4114
|
output: chunk.output,
|
|
4081
|
-
preliminary: chunk.preliminary
|
|
4115
|
+
preliminary: chunk.preliminary,
|
|
4116
|
+
providerExecuted: chunk.providerExecuted
|
|
4082
4117
|
});
|
|
4083
4118
|
} else {
|
|
4084
4119
|
updateToolPart({
|
|
@@ -4102,7 +4137,8 @@ function processUIMessageStream({
|
|
|
4102
4137
|
toolName: toolInvocation.toolName,
|
|
4103
4138
|
state: "output-error",
|
|
4104
4139
|
input: toolInvocation.input,
|
|
4105
|
-
errorText: chunk.errorText
|
|
4140
|
+
errorText: chunk.errorText,
|
|
4141
|
+
providerExecuted: chunk.providerExecuted
|
|
4106
4142
|
});
|
|
4107
4143
|
} else {
|
|
4108
4144
|
updateToolPart({
|
|
@@ -4111,7 +4147,8 @@ function processUIMessageStream({
|
|
|
4111
4147
|
state: "output-error",
|
|
4112
4148
|
input: toolInvocation.input,
|
|
4113
4149
|
rawInput: toolInvocation.rawInput,
|
|
4114
|
-
errorText: chunk.errorText
|
|
4150
|
+
errorText: chunk.errorText,
|
|
4151
|
+
providerExecuted: chunk.providerExecuted
|
|
4115
4152
|
});
|
|
4116
4153
|
}
|
|
4117
4154
|
write();
|
|
@@ -4607,7 +4644,10 @@ function runToolsTransformation({
|
|
|
4607
4644
|
});
|
|
4608
4645
|
break;
|
|
4609
4646
|
}
|
|
4610
|
-
const tool3 = tools[toolCall.toolName];
|
|
4647
|
+
const tool3 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
4648
|
+
if (tool3 == null) {
|
|
4649
|
+
break;
|
|
4650
|
+
}
|
|
4611
4651
|
if (tool3.onInputAvailable != null) {
|
|
4612
4652
|
await tool3.onInputAvailable({
|
|
4613
4653
|
input: toolCall.input,
|
|
@@ -4665,7 +4705,8 @@ function runToolsTransformation({
|
|
|
4665
4705
|
toolName,
|
|
4666
4706
|
input: toolInputs.get(chunk.toolCallId),
|
|
4667
4707
|
providerExecuted: chunk.providerExecuted,
|
|
4668
|
-
error: chunk.result
|
|
4708
|
+
error: chunk.result,
|
|
4709
|
+
dynamic: chunk.dynamic
|
|
4669
4710
|
});
|
|
4670
4711
|
} else {
|
|
4671
4712
|
controller.enqueue({
|
|
@@ -4674,7 +4715,8 @@ function runToolsTransformation({
|
|
|
4674
4715
|
toolName,
|
|
4675
4716
|
input: toolInputs.get(chunk.toolCallId),
|
|
4676
4717
|
output: chunk.result,
|
|
4677
|
-
providerExecuted: chunk.providerExecuted
|
|
4718
|
+
providerExecuted: chunk.providerExecuted,
|
|
4719
|
+
dynamic: chunk.dynamic
|
|
4678
4720
|
});
|
|
4679
4721
|
}
|
|
4680
4722
|
break;
|
|
@@ -5398,7 +5440,7 @@ var DefaultStreamTextResult = class {
|
|
|
5398
5440
|
streamWithToolResults.pipeThrough(
|
|
5399
5441
|
new TransformStream({
|
|
5400
5442
|
async transform(chunk, controller) {
|
|
5401
|
-
var _a18, _b2, _c2, _d2;
|
|
5443
|
+
var _a18, _b2, _c2, _d2, _e2;
|
|
5402
5444
|
if (chunk.type === "stream-start") {
|
|
5403
5445
|
warnings = chunk.warnings;
|
|
5404
5446
|
return;
|
|
@@ -5510,7 +5552,7 @@ var DefaultStreamTextResult = class {
|
|
|
5510
5552
|
}
|
|
5511
5553
|
controller.enqueue({
|
|
5512
5554
|
...chunk,
|
|
5513
|
-
dynamic: (tool3 == null ? void 0 : tool3.type) === "dynamic"
|
|
5555
|
+
dynamic: (_e2 = chunk.dynamic) != null ? _e2 : (tool3 == null ? void 0 : tool3.type) === "dynamic"
|
|
5514
5556
|
});
|
|
5515
5557
|
break;
|
|
5516
5558
|
}
|
|
@@ -5814,12 +5856,13 @@ var DefaultStreamTextResult = class {
|
|
|
5814
5856
|
originalMessages,
|
|
5815
5857
|
responseMessageId: generateMessageId
|
|
5816
5858
|
}) : void 0;
|
|
5817
|
-
const
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5859
|
+
const isDynamic = (part) => {
|
|
5860
|
+
var _a17;
|
|
5861
|
+
const tool3 = (_a17 = this.tools) == null ? void 0 : _a17[part.toolName];
|
|
5862
|
+
if (tool3 == null) {
|
|
5863
|
+
return part.dynamic;
|
|
5864
|
+
}
|
|
5865
|
+
return (tool3 == null ? void 0 : tool3.type) === "dynamic" ? true : void 0;
|
|
5823
5866
|
};
|
|
5824
5867
|
const baseStream = this.fullStream.pipeThrough(
|
|
5825
5868
|
new TransformStream({
|
|
@@ -5910,8 +5953,7 @@ var DefaultStreamTextResult = class {
|
|
|
5910
5953
|
break;
|
|
5911
5954
|
}
|
|
5912
5955
|
case "tool-input-start": {
|
|
5913
|
-
|
|
5914
|
-
const dynamic = isDynamic(part.id);
|
|
5956
|
+
const dynamic = isDynamic(part);
|
|
5915
5957
|
controller.enqueue({
|
|
5916
5958
|
type: "tool-input-start",
|
|
5917
5959
|
toolCallId: part.id,
|
|
@@ -5930,8 +5972,7 @@ var DefaultStreamTextResult = class {
|
|
|
5930
5972
|
break;
|
|
5931
5973
|
}
|
|
5932
5974
|
case "tool-call": {
|
|
5933
|
-
|
|
5934
|
-
const dynamic = isDynamic(part.toolCallId);
|
|
5975
|
+
const dynamic = isDynamic(part);
|
|
5935
5976
|
if (part.invalid) {
|
|
5936
5977
|
controller.enqueue({
|
|
5937
5978
|
type: "tool-input-error",
|
|
@@ -5965,7 +6006,7 @@ var DefaultStreamTextResult = class {
|
|
|
5965
6006
|
break;
|
|
5966
6007
|
}
|
|
5967
6008
|
case "tool-result": {
|
|
5968
|
-
const dynamic = isDynamic(part
|
|
6009
|
+
const dynamic = isDynamic(part);
|
|
5969
6010
|
controller.enqueue({
|
|
5970
6011
|
type: "tool-output-available",
|
|
5971
6012
|
toolCallId: part.toolCallId,
|
|
@@ -5977,7 +6018,7 @@ var DefaultStreamTextResult = class {
|
|
|
5977
6018
|
break;
|
|
5978
6019
|
}
|
|
5979
6020
|
case "tool-error": {
|
|
5980
|
-
const dynamic = isDynamic(part
|
|
6021
|
+
const dynamic = isDynamic(part);
|
|
5981
6022
|
controller.enqueue({
|
|
5982
6023
|
type: "tool-output-error",
|
|
5983
6024
|
toolCallId: part.toolCallId,
|
|
@@ -6216,32 +6257,14 @@ function convertToModelMessages(messages, options) {
|
|
|
6216
6257
|
text: part.text,
|
|
6217
6258
|
providerOptions: part.providerMetadata
|
|
6218
6259
|
});
|
|
6219
|
-
} else if (part
|
|
6220
|
-
const toolName = part
|
|
6260
|
+
} else if (isToolOrDynamicToolUIPart(part)) {
|
|
6261
|
+
const toolName = getToolOrDynamicToolName(part);
|
|
6221
6262
|
if (part.state !== "input-streaming") {
|
|
6222
6263
|
content.push({
|
|
6223
6264
|
type: "tool-call",
|
|
6224
6265
|
toolCallId: part.toolCallId,
|
|
6225
6266
|
toolName,
|
|
6226
|
-
input: part.input,
|
|
6227
|
-
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
|
6228
|
-
});
|
|
6229
|
-
}
|
|
6230
|
-
if (part.approval != null) {
|
|
6231
|
-
content.push({
|
|
6232
|
-
type: "tool-approval-request",
|
|
6233
|
-
approvalId: part.approval.id,
|
|
6234
|
-
toolCallId: part.toolCallId
|
|
6235
|
-
});
|
|
6236
|
-
}
|
|
6237
|
-
} else if (isToolUIPart(part)) {
|
|
6238
|
-
const toolName = getToolName(part);
|
|
6239
|
-
if (part.state !== "input-streaming") {
|
|
6240
|
-
content.push({
|
|
6241
|
-
type: "tool-call",
|
|
6242
|
-
toolCallId: part.toolCallId,
|
|
6243
|
-
toolName,
|
|
6244
|
-
input: part.state === "output-error" ? (_a17 = part.input) != null ? _a17 : part.rawInput : part.input,
|
|
6267
|
+
input: part.state === "output-error" ? (_a17 = part.input) != null ? _a17 : "rawInput" in part ? part.rawInput : void 0 : part.input,
|
|
6245
6268
|
providerExecuted: part.providerExecuted,
|
|
6246
6269
|
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
|
6247
6270
|
});
|
|
@@ -6275,7 +6298,7 @@ function convertToModelMessages(messages, options) {
|
|
|
6275
6298
|
content
|
|
6276
6299
|
});
|
|
6277
6300
|
const toolParts = block.filter(
|
|
6278
|
-
(part) =>
|
|
6301
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.providerExecuted !== true
|
|
6279
6302
|
);
|
|
6280
6303
|
if (toolParts.length > 0) {
|
|
6281
6304
|
modelMessages.push({
|
|
@@ -10614,6 +10637,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10614
10637
|
toolCallId: z10.string(),
|
|
10615
10638
|
state: z10.literal("input-streaming"),
|
|
10616
10639
|
input: z10.unknown().optional(),
|
|
10640
|
+
providerExecuted: z10.boolean().optional(),
|
|
10617
10641
|
output: z10.never().optional(),
|
|
10618
10642
|
errorText: z10.never().optional(),
|
|
10619
10643
|
approval: z10.never().optional()
|
|
@@ -10624,6 +10648,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10624
10648
|
toolCallId: z10.string(),
|
|
10625
10649
|
state: z10.literal("input-available"),
|
|
10626
10650
|
input: z10.unknown(),
|
|
10651
|
+
providerExecuted: z10.boolean().optional(),
|
|
10627
10652
|
output: z10.never().optional(),
|
|
10628
10653
|
errorText: z10.never().optional(),
|
|
10629
10654
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10635,6 +10660,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10635
10660
|
toolCallId: z10.string(),
|
|
10636
10661
|
state: z10.literal("approval-requested"),
|
|
10637
10662
|
input: z10.unknown(),
|
|
10663
|
+
providerExecuted: z10.boolean().optional(),
|
|
10638
10664
|
output: z10.never().optional(),
|
|
10639
10665
|
errorText: z10.never().optional(),
|
|
10640
10666
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10650,6 +10676,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10650
10676
|
toolCallId: z10.string(),
|
|
10651
10677
|
state: z10.literal("approval-responded"),
|
|
10652
10678
|
input: z10.unknown(),
|
|
10679
|
+
providerExecuted: z10.boolean().optional(),
|
|
10653
10680
|
output: z10.never().optional(),
|
|
10654
10681
|
errorText: z10.never().optional(),
|
|
10655
10682
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10665,6 +10692,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10665
10692
|
toolCallId: z10.string(),
|
|
10666
10693
|
state: z10.literal("output-available"),
|
|
10667
10694
|
input: z10.unknown(),
|
|
10695
|
+
providerExecuted: z10.boolean().optional(),
|
|
10668
10696
|
output: z10.unknown(),
|
|
10669
10697
|
errorText: z10.never().optional(),
|
|
10670
10698
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10681,6 +10709,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10681
10709
|
toolCallId: z10.string(),
|
|
10682
10710
|
state: z10.literal("output-error"),
|
|
10683
10711
|
input: z10.unknown(),
|
|
10712
|
+
providerExecuted: z10.boolean().optional(),
|
|
10684
10713
|
output: z10.never().optional(),
|
|
10685
10714
|
errorText: z10.string(),
|
|
10686
10715
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10696,6 +10725,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
10696
10725
|
toolCallId: z10.string(),
|
|
10697
10726
|
state: z10.literal("output-denied"),
|
|
10698
10727
|
input: z10.unknown(),
|
|
10728
|
+
providerExecuted: z10.boolean().optional(),
|
|
10699
10729
|
output: z10.never().optional(),
|
|
10700
10730
|
errorText: z10.never().optional(),
|
|
10701
10731
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -11078,6 +11108,7 @@ export {
|
|
|
11078
11108
|
JSONParseError,
|
|
11079
11109
|
JsonToSseTransformStream,
|
|
11080
11110
|
LoadAPIKeyError,
|
|
11111
|
+
LoadSettingError,
|
|
11081
11112
|
MCPClientError,
|
|
11082
11113
|
MessageConversionError,
|
|
11083
11114
|
NoContentGeneratedError,
|