ai 5.0.216 → 5.0.218
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 +21 -0
- package/dist/index.d.mts +1 -111
- package/dist/index.d.ts +1 -111
- package/dist/index.js +191 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -102
- 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/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -641,7 +641,17 @@ var audioMediaTypeSignatures = [
|
|
|
641
641
|
},
|
|
642
642
|
{
|
|
643
643
|
mediaType: "audio/mp4",
|
|
644
|
-
bytesPrefix: [
|
|
644
|
+
bytesPrefix: [
|
|
645
|
+
0,
|
|
646
|
+
0,
|
|
647
|
+
0,
|
|
648
|
+
null,
|
|
649
|
+
102,
|
|
650
|
+
116,
|
|
651
|
+
121,
|
|
652
|
+
112
|
|
653
|
+
// ftyp
|
|
654
|
+
]
|
|
645
655
|
},
|
|
646
656
|
{
|
|
647
657
|
mediaType: "audio/webm",
|
|
@@ -689,7 +699,7 @@ import {
|
|
|
689
699
|
} from "@ai-sdk/provider-utils";
|
|
690
700
|
|
|
691
701
|
// src/version.ts
|
|
692
|
-
var VERSION = true ? "5.0.
|
|
702
|
+
var VERSION = true ? "5.0.218" : "0.0.0-test";
|
|
693
703
|
|
|
694
704
|
// src/util/download/download.ts
|
|
695
705
|
var download = async ({
|
|
@@ -1838,6 +1848,21 @@ function extractTextContent(content) {
|
|
|
1838
1848
|
return parts.map((content2) => content2.text).join("");
|
|
1839
1849
|
}
|
|
1840
1850
|
|
|
1851
|
+
// src/generate-text/filter-active-tools.ts
|
|
1852
|
+
function filterActiveTools({
|
|
1853
|
+
tools,
|
|
1854
|
+
activeTools
|
|
1855
|
+
}) {
|
|
1856
|
+
if (tools == null || activeTools == null) {
|
|
1857
|
+
return tools;
|
|
1858
|
+
}
|
|
1859
|
+
return Object.fromEntries(
|
|
1860
|
+
Object.entries(tools).filter(
|
|
1861
|
+
([name16]) => activeTools.includes(name16)
|
|
1862
|
+
)
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1841
1866
|
// src/generate-text/generated-file.ts
|
|
1842
1867
|
import {
|
|
1843
1868
|
convertBase64ToUint8Array as convertBase64ToUint8Array3,
|
|
@@ -2259,6 +2284,9 @@ async function generateText({
|
|
|
2259
2284
|
const responseMessages = [];
|
|
2260
2285
|
const steps = [];
|
|
2261
2286
|
do {
|
|
2287
|
+
if (steps.length > 0) {
|
|
2288
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
2289
|
+
}
|
|
2262
2290
|
const stepInputMessages = [
|
|
2263
2291
|
...initialPrompt.messages,
|
|
2264
2292
|
...responseMessages
|
|
@@ -2280,10 +2308,15 @@ async function generateText({
|
|
|
2280
2308
|
supportedUrls: await stepModel.supportedUrls,
|
|
2281
2309
|
download: download2
|
|
2282
2310
|
});
|
|
2311
|
+
const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
|
|
2312
|
+
const stepToolSet = filterActiveTools({
|
|
2313
|
+
tools,
|
|
2314
|
+
activeTools: stepActiveTools
|
|
2315
|
+
});
|
|
2283
2316
|
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
2284
2317
|
tools,
|
|
2285
|
-
toolChoice: (
|
|
2286
|
-
activeTools:
|
|
2318
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
2319
|
+
activeTools: stepActiveTools
|
|
2287
2320
|
});
|
|
2288
2321
|
currentModelResponse = await retry(
|
|
2289
2322
|
() => {
|
|
@@ -2387,7 +2420,7 @@ async function generateText({
|
|
|
2387
2420
|
).map(
|
|
2388
2421
|
(toolCall) => parseToolCall({
|
|
2389
2422
|
toolCall,
|
|
2390
|
-
tools,
|
|
2423
|
+
tools: stepToolSet,
|
|
2391
2424
|
repairToolCall,
|
|
2392
2425
|
system,
|
|
2393
2426
|
messages: stepInputMessages
|
|
@@ -2398,7 +2431,7 @@ async function generateText({
|
|
|
2398
2431
|
if (toolCall.invalid) {
|
|
2399
2432
|
continue;
|
|
2400
2433
|
}
|
|
2401
|
-
const tool2 =
|
|
2434
|
+
const tool2 = stepToolSet[toolCall.toolName];
|
|
2402
2435
|
if (tool2.onInputStart != null) {
|
|
2403
2436
|
await tool2.onInputStart({
|
|
2404
2437
|
toolCallId: toolCall.toolCallId,
|
|
@@ -2434,13 +2467,13 @@ async function generateText({
|
|
|
2434
2467
|
clientToolCalls = stepToolCalls.filter(
|
|
2435
2468
|
(toolCall) => !toolCall.providerExecuted
|
|
2436
2469
|
);
|
|
2437
|
-
if (
|
|
2470
|
+
if (stepToolSet != null) {
|
|
2438
2471
|
clientToolOutputs.push(
|
|
2439
2472
|
...await executeTools({
|
|
2440
2473
|
toolCalls: clientToolCalls.filter(
|
|
2441
2474
|
(toolCall) => !toolCall.invalid
|
|
2442
2475
|
),
|
|
2443
|
-
tools,
|
|
2476
|
+
tools: stepToolSet,
|
|
2444
2477
|
tracer,
|
|
2445
2478
|
telemetry,
|
|
2446
2479
|
messages: stepInputMessages,
|
|
@@ -2457,7 +2490,7 @@ async function generateText({
|
|
|
2457
2490
|
responseMessages.push(
|
|
2458
2491
|
...toResponseMessages({
|
|
2459
2492
|
content: stepContent,
|
|
2460
|
-
tools
|
|
2493
|
+
tools: stepToolSet
|
|
2461
2494
|
})
|
|
2462
2495
|
);
|
|
2463
2496
|
const currentStepResult = new DefaultStepResult({
|
|
@@ -2932,39 +2965,39 @@ import { lazyValidator, zodSchema } from "@ai-sdk/provider-utils";
|
|
|
2932
2965
|
var uiMessageChunkSchema = lazyValidator(
|
|
2933
2966
|
() => zodSchema(
|
|
2934
2967
|
z7.union([
|
|
2935
|
-
z7.
|
|
2968
|
+
z7.looseObject({
|
|
2936
2969
|
type: z7.literal("text-start"),
|
|
2937
2970
|
id: z7.string(),
|
|
2938
2971
|
providerMetadata: providerMetadataSchema.optional()
|
|
2939
2972
|
}),
|
|
2940
|
-
z7.
|
|
2973
|
+
z7.looseObject({
|
|
2941
2974
|
type: z7.literal("text-delta"),
|
|
2942
2975
|
id: z7.string(),
|
|
2943
2976
|
delta: z7.string(),
|
|
2944
2977
|
providerMetadata: providerMetadataSchema.optional()
|
|
2945
2978
|
}),
|
|
2946
|
-
z7.
|
|
2979
|
+
z7.looseObject({
|
|
2947
2980
|
type: z7.literal("text-end"),
|
|
2948
2981
|
id: z7.string(),
|
|
2949
2982
|
providerMetadata: providerMetadataSchema.optional()
|
|
2950
2983
|
}),
|
|
2951
|
-
z7.
|
|
2984
|
+
z7.looseObject({
|
|
2952
2985
|
type: z7.literal("error"),
|
|
2953
2986
|
errorText: z7.string()
|
|
2954
2987
|
}),
|
|
2955
|
-
z7.
|
|
2988
|
+
z7.looseObject({
|
|
2956
2989
|
type: z7.literal("tool-input-start"),
|
|
2957
2990
|
toolCallId: z7.string(),
|
|
2958
2991
|
toolName: z7.string(),
|
|
2959
2992
|
providerExecuted: z7.boolean().optional(),
|
|
2960
2993
|
dynamic: z7.boolean().optional()
|
|
2961
2994
|
}),
|
|
2962
|
-
z7.
|
|
2995
|
+
z7.looseObject({
|
|
2963
2996
|
type: z7.literal("tool-input-delta"),
|
|
2964
2997
|
toolCallId: z7.string(),
|
|
2965
2998
|
inputTextDelta: z7.string()
|
|
2966
2999
|
}),
|
|
2967
|
-
z7.
|
|
3000
|
+
z7.looseObject({
|
|
2968
3001
|
type: z7.literal("tool-input-available"),
|
|
2969
3002
|
toolCallId: z7.string(),
|
|
2970
3003
|
toolName: z7.string(),
|
|
@@ -2973,7 +3006,7 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
2973
3006
|
providerMetadata: providerMetadataSchema.optional(),
|
|
2974
3007
|
dynamic: z7.boolean().optional()
|
|
2975
3008
|
}),
|
|
2976
|
-
z7.
|
|
3009
|
+
z7.looseObject({
|
|
2977
3010
|
type: z7.literal("tool-input-error"),
|
|
2978
3011
|
toolCallId: z7.string(),
|
|
2979
3012
|
toolName: z7.string(),
|
|
@@ -2983,7 +3016,7 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
2983
3016
|
dynamic: z7.boolean().optional(),
|
|
2984
3017
|
errorText: z7.string()
|
|
2985
3018
|
}),
|
|
2986
|
-
z7.
|
|
3019
|
+
z7.looseObject({
|
|
2987
3020
|
type: z7.literal("tool-output-available"),
|
|
2988
3021
|
toolCallId: z7.string(),
|
|
2989
3022
|
output: z7.unknown(),
|
|
@@ -2991,37 +3024,37 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
2991
3024
|
dynamic: z7.boolean().optional(),
|
|
2992
3025
|
preliminary: z7.boolean().optional()
|
|
2993
3026
|
}),
|
|
2994
|
-
z7.
|
|
3027
|
+
z7.looseObject({
|
|
2995
3028
|
type: z7.literal("tool-output-error"),
|
|
2996
3029
|
toolCallId: z7.string(),
|
|
2997
3030
|
errorText: z7.string(),
|
|
2998
3031
|
providerExecuted: z7.boolean().optional(),
|
|
2999
3032
|
dynamic: z7.boolean().optional()
|
|
3000
3033
|
}),
|
|
3001
|
-
z7.
|
|
3034
|
+
z7.looseObject({
|
|
3002
3035
|
type: z7.literal("reasoning-start"),
|
|
3003
3036
|
id: z7.string(),
|
|
3004
3037
|
providerMetadata: providerMetadataSchema.optional()
|
|
3005
3038
|
}),
|
|
3006
|
-
z7.
|
|
3039
|
+
z7.looseObject({
|
|
3007
3040
|
type: z7.literal("reasoning-delta"),
|
|
3008
3041
|
id: z7.string(),
|
|
3009
3042
|
delta: z7.string(),
|
|
3010
3043
|
providerMetadata: providerMetadataSchema.optional()
|
|
3011
3044
|
}),
|
|
3012
|
-
z7.
|
|
3045
|
+
z7.looseObject({
|
|
3013
3046
|
type: z7.literal("reasoning-end"),
|
|
3014
3047
|
id: z7.string(),
|
|
3015
3048
|
providerMetadata: providerMetadataSchema.optional()
|
|
3016
3049
|
}),
|
|
3017
|
-
z7.
|
|
3050
|
+
z7.looseObject({
|
|
3018
3051
|
type: z7.literal("source-url"),
|
|
3019
3052
|
sourceId: z7.string(),
|
|
3020
3053
|
url: z7.string(),
|
|
3021
3054
|
title: z7.string().optional(),
|
|
3022
3055
|
providerMetadata: providerMetadataSchema.optional()
|
|
3023
3056
|
}),
|
|
3024
|
-
z7.
|
|
3057
|
+
z7.looseObject({
|
|
3025
3058
|
type: z7.literal("source-document"),
|
|
3026
3059
|
sourceId: z7.string(),
|
|
3027
3060
|
mediaType: z7.string(),
|
|
@@ -3029,13 +3062,13 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
3029
3062
|
filename: z7.string().optional(),
|
|
3030
3063
|
providerMetadata: providerMetadataSchema.optional()
|
|
3031
3064
|
}),
|
|
3032
|
-
z7.
|
|
3065
|
+
z7.looseObject({
|
|
3033
3066
|
type: z7.literal("file"),
|
|
3034
3067
|
url: z7.string(),
|
|
3035
3068
|
mediaType: z7.string(),
|
|
3036
3069
|
providerMetadata: providerMetadataSchema.optional()
|
|
3037
3070
|
}),
|
|
3038
|
-
z7.
|
|
3071
|
+
z7.looseObject({
|
|
3039
3072
|
type: z7.custom(
|
|
3040
3073
|
(value) => typeof value === "string" && value.startsWith("data-"),
|
|
3041
3074
|
{ message: 'Type must start with "data-"' }
|
|
@@ -3044,18 +3077,18 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
3044
3077
|
data: z7.unknown(),
|
|
3045
3078
|
transient: z7.boolean().optional()
|
|
3046
3079
|
}),
|
|
3047
|
-
z7.
|
|
3080
|
+
z7.looseObject({
|
|
3048
3081
|
type: z7.literal("start-step")
|
|
3049
3082
|
}),
|
|
3050
|
-
z7.
|
|
3083
|
+
z7.looseObject({
|
|
3051
3084
|
type: z7.literal("finish-step")
|
|
3052
3085
|
}),
|
|
3053
|
-
z7.
|
|
3086
|
+
z7.looseObject({
|
|
3054
3087
|
type: z7.literal("start"),
|
|
3055
3088
|
messageId: z7.string().optional(),
|
|
3056
3089
|
messageMetadata: z7.unknown().optional()
|
|
3057
3090
|
}),
|
|
3058
|
-
z7.
|
|
3091
|
+
z7.looseObject({
|
|
3059
3092
|
type: z7.literal("finish"),
|
|
3060
3093
|
finishReason: z7.enum([
|
|
3061
3094
|
"stop",
|
|
@@ -3068,10 +3101,10 @@ var uiMessageChunkSchema = lazyValidator(
|
|
|
3068
3101
|
]).optional(),
|
|
3069
3102
|
messageMetadata: z7.unknown().optional()
|
|
3070
3103
|
}),
|
|
3071
|
-
z7.
|
|
3104
|
+
z7.looseObject({
|
|
3072
3105
|
type: z7.literal("abort")
|
|
3073
3106
|
}),
|
|
3074
|
-
z7.
|
|
3107
|
+
z7.looseObject({
|
|
3075
3108
|
type: z7.literal("message-metadata"),
|
|
3076
3109
|
messageMetadata: z7.unknown()
|
|
3077
3110
|
})
|
|
@@ -3520,11 +3553,32 @@ function processUIMessageStream({
|
|
|
3520
3553
|
async transform(chunk, controller) {
|
|
3521
3554
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
3522
3555
|
var _a16, _b, _c, _d;
|
|
3556
|
+
function getCurrentStepParts() {
|
|
3557
|
+
const parts = state.message.parts;
|
|
3558
|
+
let currentStepStartIndex = parts.length - 1;
|
|
3559
|
+
while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
|
|
3560
|
+
currentStepStartIndex--;
|
|
3561
|
+
}
|
|
3562
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
3563
|
+
}
|
|
3564
|
+
function getCurrentStepToolInvocations() {
|
|
3565
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
3566
|
+
}
|
|
3523
3567
|
function getToolInvocation(toolCallId) {
|
|
3524
|
-
const toolInvocations =
|
|
3525
|
-
|
|
3568
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
3569
|
+
let toolInvocation = toolInvocations.find(
|
|
3526
3570
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3527
3571
|
);
|
|
3572
|
+
if (toolInvocation == null) {
|
|
3573
|
+
const parts = state.message.parts;
|
|
3574
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3575
|
+
const part = parts[i];
|
|
3576
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
3577
|
+
toolInvocation = part;
|
|
3578
|
+
break;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3528
3582
|
if (toolInvocation == null) {
|
|
3529
3583
|
throw new Error(
|
|
3530
3584
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3533,12 +3587,22 @@ function processUIMessageStream({
|
|
|
3533
3587
|
return toolInvocation;
|
|
3534
3588
|
}
|
|
3535
3589
|
function getDynamicToolInvocation(toolCallId) {
|
|
3536
|
-
const toolInvocations =
|
|
3590
|
+
const toolInvocations = getCurrentStepParts().filter(
|
|
3537
3591
|
(part) => part.type === "dynamic-tool"
|
|
3538
3592
|
);
|
|
3539
|
-
|
|
3593
|
+
let toolInvocation = toolInvocations.find(
|
|
3540
3594
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3541
3595
|
);
|
|
3596
|
+
if (toolInvocation == null) {
|
|
3597
|
+
const parts = state.message.parts;
|
|
3598
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3599
|
+
const part = parts[i];
|
|
3600
|
+
if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) {
|
|
3601
|
+
toolInvocation = part;
|
|
3602
|
+
break;
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3542
3606
|
if (toolInvocation == null) {
|
|
3543
3607
|
throw new Error(
|
|
3544
3608
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3546,9 +3610,9 @@ function processUIMessageStream({
|
|
|
3546
3610
|
}
|
|
3547
3611
|
return toolInvocation;
|
|
3548
3612
|
}
|
|
3549
|
-
function updateToolPart(options) {
|
|
3613
|
+
function updateToolPart(options, existingPart) {
|
|
3550
3614
|
var _a17;
|
|
3551
|
-
const part =
|
|
3615
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3552
3616
|
(part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
3553
3617
|
);
|
|
3554
3618
|
const anyOptions = options;
|
|
@@ -3579,9 +3643,9 @@ function processUIMessageStream({
|
|
|
3579
3643
|
});
|
|
3580
3644
|
}
|
|
3581
3645
|
}
|
|
3582
|
-
function updateDynamicToolPart(options) {
|
|
3646
|
+
function updateDynamicToolPart(options, existingPart) {
|
|
3583
3647
|
var _a17, _b2;
|
|
3584
|
-
const part =
|
|
3648
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3585
3649
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
3586
3650
|
);
|
|
3587
3651
|
const anyOptions = options;
|
|
@@ -3713,7 +3777,7 @@ function processUIMessageStream({
|
|
|
3713
3777
|
break;
|
|
3714
3778
|
}
|
|
3715
3779
|
case "tool-input-start": {
|
|
3716
|
-
const toolInvocations =
|
|
3780
|
+
const toolInvocations = getCurrentStepParts().filter(isToolUIPart);
|
|
3717
3781
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
3718
3782
|
text: "",
|
|
3719
3783
|
toolName: chunk.toolName,
|
|
@@ -3823,25 +3887,31 @@ function processUIMessageStream({
|
|
|
3823
3887
|
const toolInvocation = getDynamicToolInvocation(
|
|
3824
3888
|
chunk.toolCallId
|
|
3825
3889
|
);
|
|
3826
|
-
updateDynamicToolPart(
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3890
|
+
updateDynamicToolPart(
|
|
3891
|
+
{
|
|
3892
|
+
toolCallId: chunk.toolCallId,
|
|
3893
|
+
toolName: toolInvocation.toolName,
|
|
3894
|
+
state: "output-available",
|
|
3895
|
+
input: toolInvocation.input,
|
|
3896
|
+
output: chunk.output,
|
|
3897
|
+
preliminary: chunk.preliminary
|
|
3898
|
+
},
|
|
3899
|
+
toolInvocation
|
|
3900
|
+
);
|
|
3834
3901
|
} else {
|
|
3835
3902
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3836
|
-
updateToolPart(
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3903
|
+
updateToolPart(
|
|
3904
|
+
{
|
|
3905
|
+
toolCallId: chunk.toolCallId,
|
|
3906
|
+
toolName: getToolName(toolInvocation),
|
|
3907
|
+
state: "output-available",
|
|
3908
|
+
input: toolInvocation.input,
|
|
3909
|
+
output: chunk.output,
|
|
3910
|
+
providerExecuted: chunk.providerExecuted,
|
|
3911
|
+
preliminary: chunk.preliminary
|
|
3912
|
+
},
|
|
3913
|
+
toolInvocation
|
|
3914
|
+
);
|
|
3845
3915
|
}
|
|
3846
3916
|
write();
|
|
3847
3917
|
break;
|
|
@@ -3851,25 +3921,31 @@ function processUIMessageStream({
|
|
|
3851
3921
|
const toolInvocation = getDynamicToolInvocation(
|
|
3852
3922
|
chunk.toolCallId
|
|
3853
3923
|
);
|
|
3854
|
-
updateDynamicToolPart(
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3924
|
+
updateDynamicToolPart(
|
|
3925
|
+
{
|
|
3926
|
+
toolCallId: chunk.toolCallId,
|
|
3927
|
+
toolName: toolInvocation.toolName,
|
|
3928
|
+
state: "output-error",
|
|
3929
|
+
input: toolInvocation.input,
|
|
3930
|
+
errorText: chunk.errorText,
|
|
3931
|
+
providerExecuted: chunk.providerExecuted
|
|
3932
|
+
},
|
|
3933
|
+
toolInvocation
|
|
3934
|
+
);
|
|
3862
3935
|
} else {
|
|
3863
3936
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3864
|
-
updateToolPart(
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3937
|
+
updateToolPart(
|
|
3938
|
+
{
|
|
3939
|
+
toolCallId: chunk.toolCallId,
|
|
3940
|
+
toolName: getToolName(toolInvocation),
|
|
3941
|
+
state: "output-error",
|
|
3942
|
+
input: toolInvocation.input,
|
|
3943
|
+
rawInput: toolInvocation.rawInput,
|
|
3944
|
+
errorText: chunk.errorText,
|
|
3945
|
+
providerExecuted: chunk.providerExecuted
|
|
3946
|
+
},
|
|
3947
|
+
toolInvocation
|
|
3948
|
+
);
|
|
3873
3949
|
}
|
|
3874
3950
|
write();
|
|
3875
3951
|
break;
|
|
@@ -4694,6 +4770,7 @@ var DefaultStreamTextResult = class {
|
|
|
4694
4770
|
let recordedRequest = {};
|
|
4695
4771
|
let recordedWarnings = [];
|
|
4696
4772
|
const recordedSteps = [];
|
|
4773
|
+
let currentStepToolSet = tools;
|
|
4697
4774
|
let rootSpan;
|
|
4698
4775
|
let activeTextContent = createIdMap();
|
|
4699
4776
|
let activeReasoningContent = createIdMap();
|
|
@@ -4809,7 +4886,7 @@ var DefaultStreamTextResult = class {
|
|
|
4809
4886
|
if (part.type === "finish-step") {
|
|
4810
4887
|
const stepMessages = toResponseMessages({
|
|
4811
4888
|
content: recordedContent,
|
|
4812
|
-
tools
|
|
4889
|
+
tools: currentStepToolSet
|
|
4813
4890
|
});
|
|
4814
4891
|
const currentStepResult = new DefaultStepResult({
|
|
4815
4892
|
content: recordedContent,
|
|
@@ -5023,10 +5100,16 @@ var DefaultStreamTextResult = class {
|
|
|
5023
5100
|
supportedUrls: await stepModel.supportedUrls,
|
|
5024
5101
|
download: download2
|
|
5025
5102
|
});
|
|
5103
|
+
const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
|
|
5104
|
+
const stepToolSet = filterActiveTools({
|
|
5105
|
+
tools,
|
|
5106
|
+
activeTools: stepActiveTools
|
|
5107
|
+
});
|
|
5108
|
+
currentStepToolSet = stepToolSet;
|
|
5026
5109
|
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
5027
5110
|
tools,
|
|
5028
|
-
toolChoice: (
|
|
5029
|
-
activeTools:
|
|
5111
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
5112
|
+
activeTools: stepActiveTools
|
|
5030
5113
|
});
|
|
5031
5114
|
const {
|
|
5032
5115
|
result: { stream: stream2, response, request },
|
|
@@ -5092,7 +5175,7 @@ var DefaultStreamTextResult = class {
|
|
|
5092
5175
|
})
|
|
5093
5176
|
);
|
|
5094
5177
|
const streamWithToolResults = runToolsTransformation({
|
|
5095
|
-
tools,
|
|
5178
|
+
tools: stepToolSet,
|
|
5096
5179
|
generatorStream: stream2,
|
|
5097
5180
|
tracer,
|
|
5098
5181
|
telemetry,
|
|
@@ -5225,7 +5308,7 @@ var DefaultStreamTextResult = class {
|
|
|
5225
5308
|
}
|
|
5226
5309
|
case "tool-input-start": {
|
|
5227
5310
|
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
5228
|
-
const tool2 =
|
|
5311
|
+
const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
|
|
5229
5312
|
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
5230
5313
|
await tool2.onInputStart({
|
|
5231
5314
|
toolCallId: chunk.id,
|
|
@@ -5247,7 +5330,7 @@ var DefaultStreamTextResult = class {
|
|
|
5247
5330
|
}
|
|
5248
5331
|
case "tool-input-delta": {
|
|
5249
5332
|
const toolName = activeToolCallToolNames[chunk.id];
|
|
5250
|
-
const tool2 =
|
|
5333
|
+
const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
|
|
5251
5334
|
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
5252
5335
|
await tool2.onInputDelta({
|
|
5253
5336
|
inputTextDelta: chunk.delta,
|
|
@@ -5344,7 +5427,7 @@ var DefaultStreamTextResult = class {
|
|
|
5344
5427
|
// use transformed content to create the messages for the next step:
|
|
5345
5428
|
recordedSteps[recordedSteps.length - 1].content
|
|
5346
5429
|
),
|
|
5347
|
-
tools
|
|
5430
|
+
tools: stepToolSet
|
|
5348
5431
|
})
|
|
5349
5432
|
);
|
|
5350
5433
|
try {
|
|
@@ -9444,24 +9527,26 @@ var AbstractChat = class {
|
|
|
9444
9527
|
body,
|
|
9445
9528
|
messageId
|
|
9446
9529
|
}) {
|
|
9447
|
-
var _a16, _b, _c
|
|
9530
|
+
var _a16, _b, _c;
|
|
9448
9531
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
9449
9532
|
const lastMessage = this.lastMessage;
|
|
9450
9533
|
let isAbort = false;
|
|
9451
9534
|
let isDisconnect = false;
|
|
9452
9535
|
let isError = false;
|
|
9536
|
+
let activeResponse;
|
|
9453
9537
|
try {
|
|
9454
|
-
const
|
|
9538
|
+
const response = {
|
|
9455
9539
|
state: createStreamingUIMessageState({
|
|
9456
9540
|
lastMessage: this.state.snapshot(lastMessage),
|
|
9457
9541
|
messageId: this.generateId()
|
|
9458
9542
|
}),
|
|
9459
9543
|
abortController: new AbortController()
|
|
9460
9544
|
};
|
|
9461
|
-
activeResponse
|
|
9545
|
+
activeResponse = response;
|
|
9546
|
+
response.abortController.signal.addEventListener("abort", () => {
|
|
9462
9547
|
isAbort = true;
|
|
9463
9548
|
});
|
|
9464
|
-
this.activeResponse =
|
|
9549
|
+
this.activeResponse = response;
|
|
9465
9550
|
let stream;
|
|
9466
9551
|
if (trigger === "resume-stream") {
|
|
9467
9552
|
const reconnect = await this.transport.reconnectToStream({
|
|
@@ -9479,7 +9564,7 @@ var AbstractChat = class {
|
|
|
9479
9564
|
stream = await this.transport.sendMessages({
|
|
9480
9565
|
chatId: this.id,
|
|
9481
9566
|
messages: this.state.messages,
|
|
9482
|
-
abortSignal:
|
|
9567
|
+
abortSignal: response.abortController.signal,
|
|
9483
9568
|
metadata,
|
|
9484
9569
|
headers,
|
|
9485
9570
|
body,
|
|
@@ -9491,18 +9576,18 @@ var AbstractChat = class {
|
|
|
9491
9576
|
// serialize the job execution to avoid race conditions:
|
|
9492
9577
|
this.jobExecutor.run(
|
|
9493
9578
|
() => job({
|
|
9494
|
-
state:
|
|
9579
|
+
state: response.state,
|
|
9495
9580
|
write: () => {
|
|
9496
9581
|
var _a17;
|
|
9497
9582
|
this.setStatus({ status: "streaming" });
|
|
9498
|
-
const replaceLastMessage =
|
|
9583
|
+
const replaceLastMessage = response.state.message.id === ((_a17 = this.lastMessage) == null ? void 0 : _a17.id);
|
|
9499
9584
|
if (replaceLastMessage) {
|
|
9500
9585
|
this.state.replaceMessage(
|
|
9501
9586
|
this.state.messages.length - 1,
|
|
9502
|
-
|
|
9587
|
+
response.state.message
|
|
9503
9588
|
);
|
|
9504
9589
|
} else {
|
|
9505
|
-
this.state.pushMessage(
|
|
9590
|
+
this.state.pushMessage(response.state.message);
|
|
9506
9591
|
}
|
|
9507
9592
|
}
|
|
9508
9593
|
})
|
|
@@ -9541,23 +9626,27 @@ var AbstractChat = class {
|
|
|
9541
9626
|
this.setStatus({ status: "error", error: err });
|
|
9542
9627
|
} finally {
|
|
9543
9628
|
try {
|
|
9544
|
-
(
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9629
|
+
if (activeResponse) {
|
|
9630
|
+
(_a16 = this.onFinish) == null ? void 0 : _a16.call(this, {
|
|
9631
|
+
message: activeResponse.state.message,
|
|
9632
|
+
messages: this.state.messages,
|
|
9633
|
+
isAbort,
|
|
9634
|
+
isDisconnect,
|
|
9635
|
+
isError,
|
|
9636
|
+
finishReason: activeResponse.state.finishReason
|
|
9637
|
+
});
|
|
9638
|
+
}
|
|
9552
9639
|
} catch (err) {
|
|
9553
9640
|
console.error(err);
|
|
9554
9641
|
}
|
|
9555
|
-
this.activeResponse
|
|
9642
|
+
if (this.activeResponse === activeResponse) {
|
|
9643
|
+
this.activeResponse = void 0;
|
|
9644
|
+
}
|
|
9556
9645
|
}
|
|
9557
|
-
if (((
|
|
9646
|
+
if (((_b = this.sendAutomaticallyWhen) == null ? void 0 : _b.call(this, { messages: this.state.messages })) && !isError) {
|
|
9558
9647
|
await this.makeRequest({
|
|
9559
9648
|
trigger: "submit-message",
|
|
9560
|
-
messageId: (
|
|
9649
|
+
messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
|
|
9561
9650
|
metadata,
|
|
9562
9651
|
headers,
|
|
9563
9652
|
body
|