ai 5.0.0-beta.28 → 5.0.0-beta.29
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 +10 -0
- package/dist/bin/ai.min.js +25 -25
- package/dist/index.d.mts +66 -6
- package/dist/index.d.ts +66 -6
- package/dist/index.js +245 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -105
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -0
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -0
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -56,7 +56,7 @@ __export(src_exports, {
|
|
56
56
|
UI_MESSAGE_STREAM_HEADERS: () => UI_MESSAGE_STREAM_HEADERS,
|
57
57
|
UnsupportedFunctionalityError: () => import_provider18.UnsupportedFunctionalityError,
|
58
58
|
UnsupportedModelVersionError: () => UnsupportedModelVersionError,
|
59
|
-
asSchema: () =>
|
59
|
+
asSchema: () => import_provider_utils27.asSchema,
|
60
60
|
assistantModelMessageSchema: () => assistantModelMessageSchema,
|
61
61
|
callCompletionApi: () => callCompletionApi,
|
62
62
|
consumeStream: () => consumeStream,
|
@@ -69,13 +69,14 @@ __export(src_exports, {
|
|
69
69
|
coreToolMessageSchema: () => coreToolMessageSchema,
|
70
70
|
coreUserMessageSchema: () => coreUserMessageSchema,
|
71
71
|
cosineSimilarity: () => cosineSimilarity,
|
72
|
-
createIdGenerator: () =>
|
72
|
+
createIdGenerator: () => import_provider_utils27.createIdGenerator,
|
73
73
|
createProviderRegistry: () => createProviderRegistry,
|
74
74
|
createTextStreamResponse: () => createTextStreamResponse,
|
75
75
|
createUIMessageStream: () => createUIMessageStream,
|
76
76
|
createUIMessageStreamResponse: () => createUIMessageStreamResponse,
|
77
77
|
customProvider: () => customProvider,
|
78
78
|
defaultSettingsMiddleware: () => defaultSettingsMiddleware,
|
79
|
+
dynamicTool: () => import_provider_utils27.dynamicTool,
|
79
80
|
embed: () => embed,
|
80
81
|
embedMany: () => embedMany,
|
81
82
|
experimental_createMCPClient: () => createMCPClient,
|
@@ -85,7 +86,7 @@ __export(src_exports, {
|
|
85
86
|
experimental_generateSpeech: () => generateSpeech,
|
86
87
|
experimental_transcribe: () => transcribe,
|
87
88
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
88
|
-
generateId: () =>
|
89
|
+
generateId: () => import_provider_utils27.generateId,
|
89
90
|
generateObject: () => generateObject,
|
90
91
|
generateText: () => generateText,
|
91
92
|
getTextFromDataUrl: () => getTextFromDataUrl,
|
@@ -93,7 +94,7 @@ __export(src_exports, {
|
|
93
94
|
hasToolCall: () => hasToolCall,
|
94
95
|
isDeepEqualData: () => isDeepEqualData,
|
95
96
|
isToolUIPart: () => isToolUIPart,
|
96
|
-
jsonSchema: () =>
|
97
|
+
jsonSchema: () => import_provider_utils27.jsonSchema,
|
97
98
|
lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
|
98
99
|
modelMessageSchema: () => modelMessageSchema,
|
99
100
|
parsePartialJson: () => parsePartialJson,
|
@@ -107,14 +108,14 @@ __export(src_exports, {
|
|
107
108
|
streamObject: () => streamObject,
|
108
109
|
streamText: () => streamText,
|
109
110
|
systemModelMessageSchema: () => systemModelMessageSchema,
|
110
|
-
tool: () =>
|
111
|
+
tool: () => import_provider_utils27.tool,
|
111
112
|
toolModelMessageSchema: () => toolModelMessageSchema,
|
112
113
|
userModelMessageSchema: () => userModelMessageSchema,
|
113
114
|
wrapLanguageModel: () => wrapLanguageModel,
|
114
115
|
wrapProvider: () => wrapProvider
|
115
116
|
});
|
116
117
|
module.exports = __toCommonJS(src_exports);
|
117
|
-
var
|
118
|
+
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
118
119
|
|
119
120
|
// src/generate-text/generate-text.ts
|
120
121
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
@@ -971,6 +972,7 @@ function prepareToolsAndToolChoice({
|
|
971
972
|
const toolType = tool3.type;
|
972
973
|
switch (toolType) {
|
973
974
|
case void 0:
|
975
|
+
case "dynamic":
|
974
976
|
case "function":
|
975
977
|
return {
|
976
978
|
type: "function",
|
@@ -1778,7 +1780,15 @@ async function doParseToolCall({
|
|
1778
1780
|
cause: parseResult.error
|
1779
1781
|
});
|
1780
1782
|
}
|
1781
|
-
return {
|
1783
|
+
return tool3.type === "dynamic" ? {
|
1784
|
+
type: "tool-call",
|
1785
|
+
toolCallId: toolCall.toolCallId,
|
1786
|
+
toolName: toolCall.toolName,
|
1787
|
+
input: parseResult.value,
|
1788
|
+
providerExecuted: toolCall.providerExecuted,
|
1789
|
+
providerMetadata: toolCall.providerMetadata,
|
1790
|
+
dynamic: true
|
1791
|
+
} : {
|
1782
1792
|
type: "tool-call",
|
1783
1793
|
toolCallId: toolCall.toolCallId,
|
1784
1794
|
toolName,
|
@@ -2319,7 +2329,8 @@ async function executeTools({
|
|
2319
2329
|
toolCallId,
|
2320
2330
|
toolName,
|
2321
2331
|
input,
|
2322
|
-
output: result
|
2332
|
+
output: result,
|
2333
|
+
dynamic: tool3.type === "dynamic"
|
2323
2334
|
};
|
2324
2335
|
} catch (error) {
|
2325
2336
|
recordErrorOnSpan(span, error);
|
@@ -2328,7 +2339,8 @@ async function executeTools({
|
|
2328
2339
|
toolCallId,
|
2329
2340
|
toolName,
|
2330
2341
|
input,
|
2331
|
-
error
|
2342
|
+
error,
|
2343
|
+
dynamic: tool3.type === "dynamic"
|
2332
2344
|
};
|
2333
2345
|
}
|
2334
2346
|
}
|
@@ -2460,7 +2472,8 @@ function asContent({
|
|
2460
2472
|
toolName: part.toolName,
|
2461
2473
|
input: toolCall.input,
|
2462
2474
|
error: part.result,
|
2463
|
-
providerExecuted: true
|
2475
|
+
providerExecuted: true,
|
2476
|
+
dynamic: toolCall.dynamic
|
2464
2477
|
};
|
2465
2478
|
}
|
2466
2479
|
return {
|
@@ -2469,7 +2482,8 @@ function asContent({
|
|
2469
2482
|
toolName: part.toolName,
|
2470
2483
|
input: toolCall.input,
|
2471
2484
|
output: part.result,
|
2472
|
-
providerExecuted: true
|
2485
|
+
providerExecuted: true,
|
2486
|
+
dynamic: toolCall.dynamic
|
2473
2487
|
};
|
2474
2488
|
}
|
2475
2489
|
}
|
@@ -2646,7 +2660,8 @@ var uiMessageChunkSchema = import_v47.z.union([
|
|
2646
2660
|
type: import_v47.z.literal("tool-input-start"),
|
2647
2661
|
toolCallId: import_v47.z.string(),
|
2648
2662
|
toolName: import_v47.z.string(),
|
2649
|
-
providerExecuted: import_v47.z.boolean().optional()
|
2663
|
+
providerExecuted: import_v47.z.boolean().optional(),
|
2664
|
+
dynamic: import_v47.z.boolean().optional()
|
2650
2665
|
}),
|
2651
2666
|
import_v47.z.strictObject({
|
2652
2667
|
type: import_v47.z.literal("tool-input-delta"),
|
@@ -2659,19 +2674,22 @@ var uiMessageChunkSchema = import_v47.z.union([
|
|
2659
2674
|
toolName: import_v47.z.string(),
|
2660
2675
|
input: import_v47.z.unknown(),
|
2661
2676
|
providerExecuted: import_v47.z.boolean().optional(),
|
2662
|
-
providerMetadata: providerMetadataSchema.optional()
|
2677
|
+
providerMetadata: providerMetadataSchema.optional(),
|
2678
|
+
dynamic: import_v47.z.boolean().optional()
|
2663
2679
|
}),
|
2664
2680
|
import_v47.z.strictObject({
|
2665
2681
|
type: import_v47.z.literal("tool-output-available"),
|
2666
2682
|
toolCallId: import_v47.z.string(),
|
2667
2683
|
output: import_v47.z.unknown(),
|
2668
|
-
providerExecuted: import_v47.z.boolean().optional()
|
2684
|
+
providerExecuted: import_v47.z.boolean().optional(),
|
2685
|
+
dynamic: import_v47.z.boolean().optional()
|
2669
2686
|
}),
|
2670
2687
|
import_v47.z.strictObject({
|
2671
2688
|
type: import_v47.z.literal("tool-output-error"),
|
2672
2689
|
toolCallId: import_v47.z.string(),
|
2673
2690
|
errorText: import_v47.z.string(),
|
2674
|
-
providerExecuted: import_v47.z.boolean().optional()
|
2691
|
+
providerExecuted: import_v47.z.boolean().optional(),
|
2692
|
+
dynamic: import_v47.z.boolean().optional()
|
2675
2693
|
}),
|
2676
2694
|
import_v47.z.strictObject({
|
2677
2695
|
type: import_v47.z.literal("reasoning"),
|
@@ -3160,7 +3178,33 @@ function processUIMessageStream({
|
|
3160
3178
|
async transform(chunk, controller) {
|
3161
3179
|
await runUpdateMessageJob(async ({ state, write }) => {
|
3162
3180
|
var _a16, _b, _c, _d;
|
3163
|
-
function
|
3181
|
+
function getToolInvocation(toolCallId) {
|
3182
|
+
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
3183
|
+
const toolInvocation = toolInvocations.find(
|
3184
|
+
(invocation) => invocation.toolCallId === toolCallId
|
3185
|
+
);
|
3186
|
+
if (toolInvocation == null) {
|
3187
|
+
throw new Error(
|
3188
|
+
"tool-output-error must be preceded by a tool-input-available"
|
3189
|
+
);
|
3190
|
+
}
|
3191
|
+
return toolInvocation;
|
3192
|
+
}
|
3193
|
+
function getDynamicToolInvocation(toolCallId) {
|
3194
|
+
const toolInvocations = state.message.parts.filter(
|
3195
|
+
(part) => part.type === "dynamic-tool"
|
3196
|
+
);
|
3197
|
+
const toolInvocation = toolInvocations.find(
|
3198
|
+
(invocation) => invocation.toolCallId === toolCallId
|
3199
|
+
);
|
3200
|
+
if (toolInvocation == null) {
|
3201
|
+
throw new Error(
|
3202
|
+
"tool-output-error must be preceded by a tool-input-available"
|
3203
|
+
);
|
3204
|
+
}
|
3205
|
+
return toolInvocation;
|
3206
|
+
}
|
3207
|
+
function updateToolPart(options) {
|
3164
3208
|
var _a17;
|
3165
3209
|
const part = state.message.parts.find(
|
3166
3210
|
(part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
@@ -3189,6 +3233,34 @@ function processUIMessageStream({
|
|
3189
3233
|
});
|
3190
3234
|
}
|
3191
3235
|
}
|
3236
|
+
function updateDynamicToolPart(options) {
|
3237
|
+
const part = state.message.parts.find(
|
3238
|
+
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
3239
|
+
);
|
3240
|
+
const anyOptions = options;
|
3241
|
+
const anyPart = part;
|
3242
|
+
if (part != null) {
|
3243
|
+
part.state = options.state;
|
3244
|
+
anyPart.toolName = options.toolName;
|
3245
|
+
anyPart.input = anyOptions.input;
|
3246
|
+
anyPart.output = anyOptions.output;
|
3247
|
+
anyPart.errorText = anyOptions.errorText;
|
3248
|
+
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
3249
|
+
part.callProviderMetadata = anyOptions.providerMetadata;
|
3250
|
+
}
|
3251
|
+
} else {
|
3252
|
+
state.message.parts.push({
|
3253
|
+
type: "dynamic-tool",
|
3254
|
+
toolName: options.toolName,
|
3255
|
+
toolCallId: options.toolCallId,
|
3256
|
+
state: options.state,
|
3257
|
+
input: anyOptions.input,
|
3258
|
+
output: anyOptions.output,
|
3259
|
+
errorText: anyOptions.errorText,
|
3260
|
+
...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
|
3261
|
+
});
|
3262
|
+
}
|
3263
|
+
}
|
3192
3264
|
async function updateMessageMetadata(metadata) {
|
3193
3265
|
if (metadata != null) {
|
3194
3266
|
const mergedMetadata = state.message.metadata != null ? mergeObjects(state.message.metadata, metadata) : metadata;
|
@@ -3293,15 +3365,25 @@ function processUIMessageStream({
|
|
3293
3365
|
state.partialToolCalls[chunk.toolCallId] = {
|
3294
3366
|
text: "",
|
3295
3367
|
toolName: chunk.toolName,
|
3296
|
-
index: toolInvocations.length
|
3368
|
+
index: toolInvocations.length,
|
3369
|
+
dynamic: chunk.dynamic
|
3297
3370
|
};
|
3298
|
-
|
3299
|
-
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3371
|
+
if (chunk.dynamic) {
|
3372
|
+
updateDynamicToolPart({
|
3373
|
+
toolCallId: chunk.toolCallId,
|
3374
|
+
toolName: chunk.toolName,
|
3375
|
+
state: "input-streaming",
|
3376
|
+
input: void 0
|
3377
|
+
});
|
3378
|
+
} else {
|
3379
|
+
updateToolPart({
|
3380
|
+
toolCallId: chunk.toolCallId,
|
3381
|
+
toolName: chunk.toolName,
|
3382
|
+
state: "input-streaming",
|
3383
|
+
input: void 0,
|
3384
|
+
providerExecuted: chunk.providerExecuted
|
3385
|
+
});
|
3386
|
+
}
|
3305
3387
|
write();
|
3306
3388
|
break;
|
3307
3389
|
}
|
@@ -3311,26 +3393,45 @@ function processUIMessageStream({
|
|
3311
3393
|
const { value: partialArgs } = await parsePartialJson(
|
3312
3394
|
partialToolCall.text
|
3313
3395
|
);
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
|
3319
|
-
|
3396
|
+
if (partialToolCall.dynamic) {
|
3397
|
+
updateDynamicToolPart({
|
3398
|
+
toolCallId: chunk.toolCallId,
|
3399
|
+
toolName: partialToolCall.toolName,
|
3400
|
+
state: "input-streaming",
|
3401
|
+
input: partialArgs
|
3402
|
+
});
|
3403
|
+
} else {
|
3404
|
+
updateToolPart({
|
3405
|
+
toolCallId: chunk.toolCallId,
|
3406
|
+
toolName: partialToolCall.toolName,
|
3407
|
+
state: "input-streaming",
|
3408
|
+
input: partialArgs
|
3409
|
+
});
|
3410
|
+
}
|
3320
3411
|
write();
|
3321
3412
|
break;
|
3322
3413
|
}
|
3323
3414
|
case "tool-input-available": {
|
3324
|
-
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
|
3330
|
-
|
3331
|
-
|
3415
|
+
if (chunk.dynamic) {
|
3416
|
+
updateDynamicToolPart({
|
3417
|
+
toolCallId: chunk.toolCallId,
|
3418
|
+
toolName: chunk.toolName,
|
3419
|
+
state: "input-available",
|
3420
|
+
input: chunk.input,
|
3421
|
+
providerMetadata: chunk.providerMetadata
|
3422
|
+
});
|
3423
|
+
} else {
|
3424
|
+
updateToolPart({
|
3425
|
+
toolCallId: chunk.toolCallId,
|
3426
|
+
toolName: chunk.toolName,
|
3427
|
+
state: "input-available",
|
3428
|
+
input: chunk.input,
|
3429
|
+
providerExecuted: chunk.providerExecuted,
|
3430
|
+
providerMetadata: chunk.providerMetadata
|
3431
|
+
});
|
3432
|
+
}
|
3332
3433
|
write();
|
3333
|
-
if (onToolCall && !chunk.providerExecuted) {
|
3434
|
+
if (onToolCall && !chunk.providerExecuted && !chunk.dynamic) {
|
3334
3435
|
await onToolCall({
|
3335
3436
|
toolCall: chunk
|
3336
3437
|
});
|
@@ -3338,56 +3439,53 @@ function processUIMessageStream({
|
|
3338
3439
|
break;
|
3339
3440
|
}
|
3340
3441
|
case "tool-output-available": {
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3344
|
-
}
|
3345
|
-
const toolInvocationIndex = toolInvocations.findIndex(
|
3346
|
-
(invocation) => invocation.toolCallId === chunk.toolCallId
|
3347
|
-
);
|
3348
|
-
if (toolInvocationIndex === -1) {
|
3349
|
-
throw new Error(
|
3350
|
-
"tool_result must be preceded by a tool_call with the same toolCallId"
|
3442
|
+
if (chunk.dynamic) {
|
3443
|
+
const toolInvocation = getDynamicToolInvocation(
|
3444
|
+
chunk.toolCallId
|
3351
3445
|
);
|
3446
|
+
updateDynamicToolPart({
|
3447
|
+
toolCallId: chunk.toolCallId,
|
3448
|
+
toolName: toolInvocation.toolName,
|
3449
|
+
state: "output-available",
|
3450
|
+
input: toolInvocation.input,
|
3451
|
+
output: chunk.output
|
3452
|
+
});
|
3453
|
+
} else {
|
3454
|
+
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
3455
|
+
updateToolPart({
|
3456
|
+
toolCallId: chunk.toolCallId,
|
3457
|
+
toolName: getToolName(toolInvocation),
|
3458
|
+
state: "output-available",
|
3459
|
+
input: toolInvocation.input,
|
3460
|
+
output: chunk.output,
|
3461
|
+
providerExecuted: chunk.providerExecuted
|
3462
|
+
});
|
3352
3463
|
}
|
3353
|
-
const toolName = getToolName(
|
3354
|
-
toolInvocations[toolInvocationIndex]
|
3355
|
-
);
|
3356
|
-
updateToolInvocationPart({
|
3357
|
-
toolCallId: chunk.toolCallId,
|
3358
|
-
toolName,
|
3359
|
-
state: "output-available",
|
3360
|
-
input: toolInvocations[toolInvocationIndex].input,
|
3361
|
-
output: chunk.output,
|
3362
|
-
providerExecuted: chunk.providerExecuted
|
3363
|
-
});
|
3364
3464
|
write();
|
3365
3465
|
break;
|
3366
3466
|
}
|
3367
3467
|
case "tool-output-error": {
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
}
|
3372
|
-
const toolInvocationIndex = toolInvocations.findIndex(
|
3373
|
-
(invocation) => invocation.toolCallId === chunk.toolCallId
|
3374
|
-
);
|
3375
|
-
if (toolInvocationIndex === -1) {
|
3376
|
-
throw new Error(
|
3377
|
-
"tool_result must be preceded by a tool_call with the same toolCallId"
|
3468
|
+
if (chunk.dynamic) {
|
3469
|
+
const toolInvocation = getDynamicToolInvocation(
|
3470
|
+
chunk.toolCallId
|
3378
3471
|
);
|
3472
|
+
updateDynamicToolPart({
|
3473
|
+
toolCallId: chunk.toolCallId,
|
3474
|
+
toolName: toolInvocation.toolName,
|
3475
|
+
state: "output-error",
|
3476
|
+
input: toolInvocation.input,
|
3477
|
+
errorText: chunk.errorText
|
3478
|
+
});
|
3479
|
+
} else {
|
3480
|
+
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
3481
|
+
updateToolPart({
|
3482
|
+
toolCallId: chunk.toolCallId,
|
3483
|
+
toolName: getToolName(toolInvocation),
|
3484
|
+
state: "output-error",
|
3485
|
+
input: toolInvocation.input,
|
3486
|
+
errorText: chunk.errorText
|
3487
|
+
});
|
3379
3488
|
}
|
3380
|
-
const toolName = getToolName(
|
3381
|
-
toolInvocations[toolInvocationIndex]
|
3382
|
-
);
|
3383
|
-
updateToolInvocationPart({
|
3384
|
-
toolCallId: chunk.toolCallId,
|
3385
|
-
toolName,
|
3386
|
-
state: "output-error",
|
3387
|
-
input: toolInvocations[toolInvocationIndex].input,
|
3388
|
-
errorText: chunk.errorText,
|
3389
|
-
providerExecuted: chunk.providerExecuted
|
3390
|
-
});
|
3391
3489
|
write();
|
3392
3490
|
break;
|
3393
3491
|
}
|
@@ -4638,7 +4736,10 @@ var DefaultStreamTextResult = class {
|
|
4638
4736
|
abortSignal
|
4639
4737
|
});
|
4640
4738
|
}
|
4641
|
-
controller.enqueue(
|
4739
|
+
controller.enqueue({
|
4740
|
+
...chunk,
|
4741
|
+
dynamic: (tool3 == null ? void 0 : tool3.type) === "dynamic"
|
4742
|
+
});
|
4642
4743
|
break;
|
4643
4744
|
}
|
4644
4745
|
case "tool-input-end": {
|
@@ -5018,7 +5119,8 @@ var DefaultStreamTextResult = class {
|
|
5018
5119
|
type: "tool-input-start",
|
5019
5120
|
toolCallId: part.id,
|
5020
5121
|
toolName: part.toolName,
|
5021
|
-
providerExecuted: part.providerExecuted
|
5122
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5123
|
+
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
5022
5124
|
});
|
5023
5125
|
break;
|
5024
5126
|
}
|
@@ -5036,8 +5138,9 @@ var DefaultStreamTextResult = class {
|
|
5036
5138
|
toolCallId: part.toolCallId,
|
5037
5139
|
toolName: part.toolName,
|
5038
5140
|
input: part.input,
|
5039
|
-
providerExecuted: part.providerExecuted,
|
5040
|
-
providerMetadata: part.providerMetadata
|
5141
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5142
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
5143
|
+
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
5041
5144
|
});
|
5042
5145
|
break;
|
5043
5146
|
}
|
@@ -5046,7 +5149,8 @@ var DefaultStreamTextResult = class {
|
|
5046
5149
|
type: "tool-output-available",
|
5047
5150
|
toolCallId: part.toolCallId,
|
5048
5151
|
output: part.output,
|
5049
|
-
providerExecuted: part.providerExecuted
|
5152
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5153
|
+
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
5050
5154
|
});
|
5051
5155
|
break;
|
5052
5156
|
}
|
@@ -5055,7 +5159,8 @@ var DefaultStreamTextResult = class {
|
|
5055
5159
|
type: "tool-output-error",
|
5056
5160
|
toolCallId: part.toolCallId,
|
5057
5161
|
errorText: onError(part.error),
|
5058
|
-
providerExecuted: part.providerExecuted
|
5162
|
+
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
5163
|
+
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
5059
5164
|
});
|
5060
5165
|
break;
|
5061
5166
|
}
|
@@ -7730,7 +7835,6 @@ var DefaultProviderRegistry = class {
|
|
7730
7835
|
|
7731
7836
|
// src/tool/mcp/mcp-client.ts
|
7732
7837
|
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
7733
|
-
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
7734
7838
|
|
7735
7839
|
// src/tool/mcp/mcp-sse-transport.ts
|
7736
7840
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
@@ -7740,9 +7844,10 @@ var import_v49 = require("zod/v4");
|
|
7740
7844
|
|
7741
7845
|
// src/tool/mcp/types.ts
|
7742
7846
|
var import_v48 = require("zod/v4");
|
7743
|
-
var LATEST_PROTOCOL_VERSION = "2025-
|
7847
|
+
var LATEST_PROTOCOL_VERSION = "2025-06-18";
|
7744
7848
|
var SUPPORTED_PROTOCOL_VERSIONS = [
|
7745
7849
|
LATEST_PROTOCOL_VERSION,
|
7850
|
+
"2025-03-26",
|
7746
7851
|
"2024-11-05"
|
7747
7852
|
];
|
7748
7853
|
var ClientOrServerImplementationSchema = import_v48.z.object({
|
@@ -8229,22 +8334,23 @@ var MCPClient = class {
|
|
8229
8334
|
continue;
|
8230
8335
|
}
|
8231
8336
|
const self = this;
|
8232
|
-
const
|
8337
|
+
const execute = async (args, options) => {
|
8338
|
+
var _a17;
|
8339
|
+
(_a17 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a17.throwIfAborted();
|
8340
|
+
return self.callTool({ name: name16, args, options });
|
8341
|
+
};
|
8342
|
+
const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils21.dynamicTool)({
|
8233
8343
|
description,
|
8234
|
-
inputSchema:
|
8344
|
+
inputSchema: (0, import_provider_utils21.jsonSchema)({
|
8235
8345
|
...inputSchema,
|
8236
8346
|
properties: (_a16 = inputSchema.properties) != null ? _a16 : {},
|
8237
8347
|
additionalProperties: false
|
8238
|
-
})
|
8239
|
-
execute
|
8240
|
-
|
8241
|
-
|
8242
|
-
|
8243
|
-
|
8244
|
-
args,
|
8245
|
-
options
|
8246
|
-
});
|
8247
|
-
}
|
8348
|
+
}),
|
8349
|
+
execute
|
8350
|
+
}) : (0, import_provider_utils21.tool)({
|
8351
|
+
description,
|
8352
|
+
inputSchema: schemas[name16].inputSchema,
|
8353
|
+
execute
|
8248
8354
|
});
|
8249
8355
|
tools[name16] = toolWithExecute;
|
8250
8356
|
}
|
@@ -8290,9 +8396,6 @@ var MCPClient = class {
|
|
8290
8396
|
}
|
8291
8397
|
};
|
8292
8398
|
|
8293
|
-
// src/tool/index.ts
|
8294
|
-
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
8295
|
-
|
8296
8399
|
// src/error/no-transcript-generated-error.ts
|
8297
8400
|
var import_provider30 = require("@ai-sdk/provider");
|
8298
8401
|
var NoTranscriptGeneratedError = class extends import_provider30.AISDKError {
|
@@ -8365,7 +8468,7 @@ var DefaultTranscriptionResult = class {
|
|
8365
8468
|
};
|
8366
8469
|
|
8367
8470
|
// src/ui/call-completion-api.ts
|
8368
|
-
var
|
8471
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
8369
8472
|
|
8370
8473
|
// src/ui/process-text-stream.ts
|
8371
8474
|
async function processTextStream({
|
@@ -8443,7 +8546,7 @@ async function callCompletionApi({
|
|
8443
8546
|
}
|
8444
8547
|
case "data": {
|
8445
8548
|
await consumeStream({
|
8446
|
-
stream: (0,
|
8549
|
+
stream: (0, import_provider_utils22.parseJsonEventStream)({
|
8447
8550
|
stream: response.body,
|
8448
8551
|
schema: uiMessageChunkSchema
|
8449
8552
|
}).pipeThrough(
|
@@ -8495,7 +8598,7 @@ async function callCompletionApi({
|
|
8495
8598
|
}
|
8496
8599
|
|
8497
8600
|
// src/ui/chat.ts
|
8498
|
-
var
|
8601
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
8499
8602
|
|
8500
8603
|
// src/ui/convert-file-list-to-file-ui-parts.ts
|
8501
8604
|
async function convertFileListToFileUIParts(files) {
|
@@ -8528,10 +8631,10 @@ async function convertFileListToFileUIParts(files) {
|
|
8528
8631
|
}
|
8529
8632
|
|
8530
8633
|
// src/ui/default-chat-transport.ts
|
8531
|
-
var
|
8634
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
8532
8635
|
|
8533
8636
|
// src/ui/http-chat-transport.ts
|
8534
|
-
var
|
8637
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
8535
8638
|
var HttpChatTransport = class {
|
8536
8639
|
constructor({
|
8537
8640
|
api = "/api/chat",
|
@@ -8555,9 +8658,9 @@ var HttpChatTransport = class {
|
|
8555
8658
|
...options
|
8556
8659
|
}) {
|
8557
8660
|
var _a16, _b, _c, _d, _e;
|
8558
|
-
const resolvedBody = await (0,
|
8559
|
-
const resolvedHeaders = await (0,
|
8560
|
-
const resolvedCredentials = await (0,
|
8661
|
+
const resolvedBody = await (0, import_provider_utils23.resolve)(this.body);
|
8662
|
+
const resolvedHeaders = await (0, import_provider_utils23.resolve)(this.headers);
|
8663
|
+
const resolvedCredentials = await (0, import_provider_utils23.resolve)(this.credentials);
|
8561
8664
|
const preparedRequest = await ((_a16 = this.prepareSendMessagesRequest) == null ? void 0 : _a16.call(this, {
|
8562
8665
|
api: this.api,
|
8563
8666
|
id: options.chatId,
|
@@ -8603,9 +8706,9 @@ var HttpChatTransport = class {
|
|
8603
8706
|
}
|
8604
8707
|
async reconnectToStream(options) {
|
8605
8708
|
var _a16, _b, _c, _d, _e;
|
8606
|
-
const resolvedBody = await (0,
|
8607
|
-
const resolvedHeaders = await (0,
|
8608
|
-
const resolvedCredentials = await (0,
|
8709
|
+
const resolvedBody = await (0, import_provider_utils23.resolve)(this.body);
|
8710
|
+
const resolvedHeaders = await (0, import_provider_utils23.resolve)(this.headers);
|
8711
|
+
const resolvedCredentials = await (0, import_provider_utils23.resolve)(this.credentials);
|
8609
8712
|
const preparedRequest = await ((_a16 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a16.call(this, {
|
8610
8713
|
api: this.api,
|
8611
8714
|
id: options.chatId,
|
@@ -8644,7 +8747,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
|
|
8644
8747
|
super(options);
|
8645
8748
|
}
|
8646
8749
|
processResponseStream(stream) {
|
8647
|
-
return (0,
|
8750
|
+
return (0, import_provider_utils24.parseJsonEventStream)({
|
8648
8751
|
stream,
|
8649
8752
|
schema: uiMessageChunkSchema
|
8650
8753
|
}).pipeThrough(
|
@@ -8663,7 +8766,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
|
|
8663
8766
|
// src/ui/chat.ts
|
8664
8767
|
var AbstractChat = class {
|
8665
8768
|
constructor({
|
8666
|
-
generateId: generateId3 =
|
8769
|
+
generateId: generateId3 = import_provider_utils25.generateId,
|
8667
8770
|
id = generateId3(),
|
8668
8771
|
transport = new DefaultChatTransport(),
|
8669
8772
|
messageMetadataSchema,
|
@@ -9032,6 +9135,22 @@ function convertToModelMessages(messages, options) {
|
|
9032
9135
|
text: part.text,
|
9033
9136
|
providerOptions: part.providerMetadata
|
9034
9137
|
});
|
9138
|
+
} else if (part.type === "dynamic-tool") {
|
9139
|
+
const toolName = part.toolName;
|
9140
|
+
if (part.state === "input-streaming") {
|
9141
|
+
throw new MessageConversionError({
|
9142
|
+
originalMessage: message,
|
9143
|
+
message: `incomplete tool input is not supported: ${part.toolCallId}`
|
9144
|
+
});
|
9145
|
+
} else {
|
9146
|
+
content.push({
|
9147
|
+
type: "tool-call",
|
9148
|
+
toolCallId: part.toolCallId,
|
9149
|
+
toolName,
|
9150
|
+
input: part.input,
|
9151
|
+
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
9152
|
+
});
|
9153
|
+
}
|
9035
9154
|
} else if (isToolUIPart(part)) {
|
9036
9155
|
const toolName = getToolName(part);
|
9037
9156
|
if (part.state === "input-streaming") {
|
@@ -9070,7 +9189,9 @@ function convertToModelMessages(messages, options) {
|
|
9070
9189
|
role: "assistant",
|
9071
9190
|
content
|
9072
9191
|
});
|
9073
|
-
const toolParts = block.filter(
|
9192
|
+
const toolParts = block.filter(
|
9193
|
+
(part) => isToolUIPart(part) && part.providerExecuted !== true || part.type === "dynamic-tool"
|
9194
|
+
);
|
9074
9195
|
if (toolParts.length > 0) {
|
9075
9196
|
modelMessages.push({
|
9076
9197
|
role: "tool",
|
@@ -9079,7 +9200,7 @@ function convertToModelMessages(messages, options) {
|
|
9079
9200
|
switch (toolPart.state) {
|
9080
9201
|
case "output-error":
|
9081
9202
|
case "output-available": {
|
9082
|
-
const toolName = getToolName(toolPart);
|
9203
|
+
const toolName = toolPart.type === "dynamic-tool" ? toolPart.toolName : getToolName(toolPart);
|
9083
9204
|
return {
|
9084
9205
|
type: "tool-result",
|
9085
9206
|
toolCallId: toolPart.toolCallId,
|
@@ -9106,7 +9227,7 @@ function convertToModelMessages(messages, options) {
|
|
9106
9227
|
var processBlock = processBlock2;
|
9107
9228
|
let block = [];
|
9108
9229
|
for (const part of message.parts) {
|
9109
|
-
if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolUIPart(part)) {
|
9230
|
+
if (part.type === "text" || part.type === "reasoning" || part.type === "file" || part.type === "dynamic-tool" || isToolUIPart(part)) {
|
9110
9231
|
block.push(part);
|
9111
9232
|
} else if (part.type === "step-start") {
|
9112
9233
|
processBlock2();
|
@@ -9184,13 +9305,13 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
9184
9305
|
};
|
9185
9306
|
|
9186
9307
|
// src/ui-message-stream/create-ui-message-stream.ts
|
9187
|
-
var
|
9308
|
+
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
9188
9309
|
function createUIMessageStream({
|
9189
9310
|
execute,
|
9190
|
-
onError =
|
9311
|
+
onError = import_provider_utils26.getErrorMessage,
|
9191
9312
|
originalMessages,
|
9192
9313
|
onFinish,
|
9193
|
-
generateId: generateId3 =
|
9314
|
+
generateId: generateId3 = import_provider_utils26.generateId
|
9194
9315
|
}) {
|
9195
9316
|
let controller;
|
9196
9317
|
const ongoingStreamPromises = [];
|
@@ -9374,6 +9495,7 @@ function readUIMessageStream({
|
|
9374
9495
|
createUIMessageStreamResponse,
|
9375
9496
|
customProvider,
|
9376
9497
|
defaultSettingsMiddleware,
|
9498
|
+
dynamicTool,
|
9377
9499
|
embed,
|
9378
9500
|
embedMany,
|
9379
9501
|
experimental_createMCPClient,
|