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.js
CHANGED
|
@@ -738,7 +738,17 @@ var audioMediaTypeSignatures = [
|
|
|
738
738
|
},
|
|
739
739
|
{
|
|
740
740
|
mediaType: "audio/mp4",
|
|
741
|
-
bytesPrefix: [
|
|
741
|
+
bytesPrefix: [
|
|
742
|
+
0,
|
|
743
|
+
0,
|
|
744
|
+
0,
|
|
745
|
+
null,
|
|
746
|
+
102,
|
|
747
|
+
116,
|
|
748
|
+
121,
|
|
749
|
+
112
|
|
750
|
+
// ftyp
|
|
751
|
+
]
|
|
742
752
|
},
|
|
743
753
|
{
|
|
744
754
|
mediaType: "audio/webm",
|
|
@@ -778,7 +788,7 @@ function detectMediaType({
|
|
|
778
788
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
779
789
|
|
|
780
790
|
// src/version.ts
|
|
781
|
-
var VERSION = true ? "5.0.
|
|
791
|
+
var VERSION = true ? "5.0.218" : "0.0.0-test";
|
|
782
792
|
|
|
783
793
|
// src/util/download/download.ts
|
|
784
794
|
var download = async ({
|
|
@@ -1922,6 +1932,21 @@ function extractTextContent(content) {
|
|
|
1922
1932
|
return parts.map((content2) => content2.text).join("");
|
|
1923
1933
|
}
|
|
1924
1934
|
|
|
1935
|
+
// src/generate-text/filter-active-tools.ts
|
|
1936
|
+
function filterActiveTools({
|
|
1937
|
+
tools,
|
|
1938
|
+
activeTools
|
|
1939
|
+
}) {
|
|
1940
|
+
if (tools == null || activeTools == null) {
|
|
1941
|
+
return tools;
|
|
1942
|
+
}
|
|
1943
|
+
return Object.fromEntries(
|
|
1944
|
+
Object.entries(tools).filter(
|
|
1945
|
+
([name16]) => activeTools.includes(name16)
|
|
1946
|
+
)
|
|
1947
|
+
);
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1925
1950
|
// src/generate-text/generated-file.ts
|
|
1926
1951
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1927
1952
|
var DefaultGeneratedFile = class {
|
|
@@ -2334,6 +2359,9 @@ async function generateText({
|
|
|
2334
2359
|
const responseMessages = [];
|
|
2335
2360
|
const steps = [];
|
|
2336
2361
|
do {
|
|
2362
|
+
if (steps.length > 0) {
|
|
2363
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
2364
|
+
}
|
|
2337
2365
|
const stepInputMessages = [
|
|
2338
2366
|
...initialPrompt.messages,
|
|
2339
2367
|
...responseMessages
|
|
@@ -2355,10 +2383,15 @@ async function generateText({
|
|
|
2355
2383
|
supportedUrls: await stepModel.supportedUrls,
|
|
2356
2384
|
download: download2
|
|
2357
2385
|
});
|
|
2386
|
+
const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
|
|
2387
|
+
const stepToolSet = filterActiveTools({
|
|
2388
|
+
tools,
|
|
2389
|
+
activeTools: stepActiveTools
|
|
2390
|
+
});
|
|
2358
2391
|
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
2359
2392
|
tools,
|
|
2360
|
-
toolChoice: (
|
|
2361
|
-
activeTools:
|
|
2393
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
2394
|
+
activeTools: stepActiveTools
|
|
2362
2395
|
});
|
|
2363
2396
|
currentModelResponse = await retry(
|
|
2364
2397
|
() => {
|
|
@@ -2462,7 +2495,7 @@ async function generateText({
|
|
|
2462
2495
|
).map(
|
|
2463
2496
|
(toolCall) => parseToolCall({
|
|
2464
2497
|
toolCall,
|
|
2465
|
-
tools,
|
|
2498
|
+
tools: stepToolSet,
|
|
2466
2499
|
repairToolCall,
|
|
2467
2500
|
system,
|
|
2468
2501
|
messages: stepInputMessages
|
|
@@ -2473,7 +2506,7 @@ async function generateText({
|
|
|
2473
2506
|
if (toolCall.invalid) {
|
|
2474
2507
|
continue;
|
|
2475
2508
|
}
|
|
2476
|
-
const tool2 =
|
|
2509
|
+
const tool2 = stepToolSet[toolCall.toolName];
|
|
2477
2510
|
if (tool2.onInputStart != null) {
|
|
2478
2511
|
await tool2.onInputStart({
|
|
2479
2512
|
toolCallId: toolCall.toolCallId,
|
|
@@ -2509,13 +2542,13 @@ async function generateText({
|
|
|
2509
2542
|
clientToolCalls = stepToolCalls.filter(
|
|
2510
2543
|
(toolCall) => !toolCall.providerExecuted
|
|
2511
2544
|
);
|
|
2512
|
-
if (
|
|
2545
|
+
if (stepToolSet != null) {
|
|
2513
2546
|
clientToolOutputs.push(
|
|
2514
2547
|
...await executeTools({
|
|
2515
2548
|
toolCalls: clientToolCalls.filter(
|
|
2516
2549
|
(toolCall) => !toolCall.invalid
|
|
2517
2550
|
),
|
|
2518
|
-
tools,
|
|
2551
|
+
tools: stepToolSet,
|
|
2519
2552
|
tracer,
|
|
2520
2553
|
telemetry,
|
|
2521
2554
|
messages: stepInputMessages,
|
|
@@ -2532,7 +2565,7 @@ async function generateText({
|
|
|
2532
2565
|
responseMessages.push(
|
|
2533
2566
|
...toResponseMessages({
|
|
2534
2567
|
content: stepContent,
|
|
2535
|
-
tools
|
|
2568
|
+
tools: stepToolSet
|
|
2536
2569
|
})
|
|
2537
2570
|
);
|
|
2538
2571
|
const currentStepResult = new DefaultStepResult({
|
|
@@ -3001,39 +3034,39 @@ var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
|
3001
3034
|
var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
3002
3035
|
() => (0, import_provider_utils11.zodSchema)(
|
|
3003
3036
|
import_v47.z.union([
|
|
3004
|
-
import_v47.z.
|
|
3037
|
+
import_v47.z.looseObject({
|
|
3005
3038
|
type: import_v47.z.literal("text-start"),
|
|
3006
3039
|
id: import_v47.z.string(),
|
|
3007
3040
|
providerMetadata: providerMetadataSchema.optional()
|
|
3008
3041
|
}),
|
|
3009
|
-
import_v47.z.
|
|
3042
|
+
import_v47.z.looseObject({
|
|
3010
3043
|
type: import_v47.z.literal("text-delta"),
|
|
3011
3044
|
id: import_v47.z.string(),
|
|
3012
3045
|
delta: import_v47.z.string(),
|
|
3013
3046
|
providerMetadata: providerMetadataSchema.optional()
|
|
3014
3047
|
}),
|
|
3015
|
-
import_v47.z.
|
|
3048
|
+
import_v47.z.looseObject({
|
|
3016
3049
|
type: import_v47.z.literal("text-end"),
|
|
3017
3050
|
id: import_v47.z.string(),
|
|
3018
3051
|
providerMetadata: providerMetadataSchema.optional()
|
|
3019
3052
|
}),
|
|
3020
|
-
import_v47.z.
|
|
3053
|
+
import_v47.z.looseObject({
|
|
3021
3054
|
type: import_v47.z.literal("error"),
|
|
3022
3055
|
errorText: import_v47.z.string()
|
|
3023
3056
|
}),
|
|
3024
|
-
import_v47.z.
|
|
3057
|
+
import_v47.z.looseObject({
|
|
3025
3058
|
type: import_v47.z.literal("tool-input-start"),
|
|
3026
3059
|
toolCallId: import_v47.z.string(),
|
|
3027
3060
|
toolName: import_v47.z.string(),
|
|
3028
3061
|
providerExecuted: import_v47.z.boolean().optional(),
|
|
3029
3062
|
dynamic: import_v47.z.boolean().optional()
|
|
3030
3063
|
}),
|
|
3031
|
-
import_v47.z.
|
|
3064
|
+
import_v47.z.looseObject({
|
|
3032
3065
|
type: import_v47.z.literal("tool-input-delta"),
|
|
3033
3066
|
toolCallId: import_v47.z.string(),
|
|
3034
3067
|
inputTextDelta: import_v47.z.string()
|
|
3035
3068
|
}),
|
|
3036
|
-
import_v47.z.
|
|
3069
|
+
import_v47.z.looseObject({
|
|
3037
3070
|
type: import_v47.z.literal("tool-input-available"),
|
|
3038
3071
|
toolCallId: import_v47.z.string(),
|
|
3039
3072
|
toolName: import_v47.z.string(),
|
|
@@ -3042,7 +3075,7 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3042
3075
|
providerMetadata: providerMetadataSchema.optional(),
|
|
3043
3076
|
dynamic: import_v47.z.boolean().optional()
|
|
3044
3077
|
}),
|
|
3045
|
-
import_v47.z.
|
|
3078
|
+
import_v47.z.looseObject({
|
|
3046
3079
|
type: import_v47.z.literal("tool-input-error"),
|
|
3047
3080
|
toolCallId: import_v47.z.string(),
|
|
3048
3081
|
toolName: import_v47.z.string(),
|
|
@@ -3052,7 +3085,7 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3052
3085
|
dynamic: import_v47.z.boolean().optional(),
|
|
3053
3086
|
errorText: import_v47.z.string()
|
|
3054
3087
|
}),
|
|
3055
|
-
import_v47.z.
|
|
3088
|
+
import_v47.z.looseObject({
|
|
3056
3089
|
type: import_v47.z.literal("tool-output-available"),
|
|
3057
3090
|
toolCallId: import_v47.z.string(),
|
|
3058
3091
|
output: import_v47.z.unknown(),
|
|
@@ -3060,37 +3093,37 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3060
3093
|
dynamic: import_v47.z.boolean().optional(),
|
|
3061
3094
|
preliminary: import_v47.z.boolean().optional()
|
|
3062
3095
|
}),
|
|
3063
|
-
import_v47.z.
|
|
3096
|
+
import_v47.z.looseObject({
|
|
3064
3097
|
type: import_v47.z.literal("tool-output-error"),
|
|
3065
3098
|
toolCallId: import_v47.z.string(),
|
|
3066
3099
|
errorText: import_v47.z.string(),
|
|
3067
3100
|
providerExecuted: import_v47.z.boolean().optional(),
|
|
3068
3101
|
dynamic: import_v47.z.boolean().optional()
|
|
3069
3102
|
}),
|
|
3070
|
-
import_v47.z.
|
|
3103
|
+
import_v47.z.looseObject({
|
|
3071
3104
|
type: import_v47.z.literal("reasoning-start"),
|
|
3072
3105
|
id: import_v47.z.string(),
|
|
3073
3106
|
providerMetadata: providerMetadataSchema.optional()
|
|
3074
3107
|
}),
|
|
3075
|
-
import_v47.z.
|
|
3108
|
+
import_v47.z.looseObject({
|
|
3076
3109
|
type: import_v47.z.literal("reasoning-delta"),
|
|
3077
3110
|
id: import_v47.z.string(),
|
|
3078
3111
|
delta: import_v47.z.string(),
|
|
3079
3112
|
providerMetadata: providerMetadataSchema.optional()
|
|
3080
3113
|
}),
|
|
3081
|
-
import_v47.z.
|
|
3114
|
+
import_v47.z.looseObject({
|
|
3082
3115
|
type: import_v47.z.literal("reasoning-end"),
|
|
3083
3116
|
id: import_v47.z.string(),
|
|
3084
3117
|
providerMetadata: providerMetadataSchema.optional()
|
|
3085
3118
|
}),
|
|
3086
|
-
import_v47.z.
|
|
3119
|
+
import_v47.z.looseObject({
|
|
3087
3120
|
type: import_v47.z.literal("source-url"),
|
|
3088
3121
|
sourceId: import_v47.z.string(),
|
|
3089
3122
|
url: import_v47.z.string(),
|
|
3090
3123
|
title: import_v47.z.string().optional(),
|
|
3091
3124
|
providerMetadata: providerMetadataSchema.optional()
|
|
3092
3125
|
}),
|
|
3093
|
-
import_v47.z.
|
|
3126
|
+
import_v47.z.looseObject({
|
|
3094
3127
|
type: import_v47.z.literal("source-document"),
|
|
3095
3128
|
sourceId: import_v47.z.string(),
|
|
3096
3129
|
mediaType: import_v47.z.string(),
|
|
@@ -3098,13 +3131,13 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3098
3131
|
filename: import_v47.z.string().optional(),
|
|
3099
3132
|
providerMetadata: providerMetadataSchema.optional()
|
|
3100
3133
|
}),
|
|
3101
|
-
import_v47.z.
|
|
3134
|
+
import_v47.z.looseObject({
|
|
3102
3135
|
type: import_v47.z.literal("file"),
|
|
3103
3136
|
url: import_v47.z.string(),
|
|
3104
3137
|
mediaType: import_v47.z.string(),
|
|
3105
3138
|
providerMetadata: providerMetadataSchema.optional()
|
|
3106
3139
|
}),
|
|
3107
|
-
import_v47.z.
|
|
3140
|
+
import_v47.z.looseObject({
|
|
3108
3141
|
type: import_v47.z.custom(
|
|
3109
3142
|
(value) => typeof value === "string" && value.startsWith("data-"),
|
|
3110
3143
|
{ message: 'Type must start with "data-"' }
|
|
@@ -3113,18 +3146,18 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3113
3146
|
data: import_v47.z.unknown(),
|
|
3114
3147
|
transient: import_v47.z.boolean().optional()
|
|
3115
3148
|
}),
|
|
3116
|
-
import_v47.z.
|
|
3149
|
+
import_v47.z.looseObject({
|
|
3117
3150
|
type: import_v47.z.literal("start-step")
|
|
3118
3151
|
}),
|
|
3119
|
-
import_v47.z.
|
|
3152
|
+
import_v47.z.looseObject({
|
|
3120
3153
|
type: import_v47.z.literal("finish-step")
|
|
3121
3154
|
}),
|
|
3122
|
-
import_v47.z.
|
|
3155
|
+
import_v47.z.looseObject({
|
|
3123
3156
|
type: import_v47.z.literal("start"),
|
|
3124
3157
|
messageId: import_v47.z.string().optional(),
|
|
3125
3158
|
messageMetadata: import_v47.z.unknown().optional()
|
|
3126
3159
|
}),
|
|
3127
|
-
import_v47.z.
|
|
3160
|
+
import_v47.z.looseObject({
|
|
3128
3161
|
type: import_v47.z.literal("finish"),
|
|
3129
3162
|
finishReason: import_v47.z.enum([
|
|
3130
3163
|
"stop",
|
|
@@ -3137,10 +3170,10 @@ var uiMessageChunkSchema = (0, import_provider_utils11.lazyValidator)(
|
|
|
3137
3170
|
]).optional(),
|
|
3138
3171
|
messageMetadata: import_v47.z.unknown().optional()
|
|
3139
3172
|
}),
|
|
3140
|
-
import_v47.z.
|
|
3173
|
+
import_v47.z.looseObject({
|
|
3141
3174
|
type: import_v47.z.literal("abort")
|
|
3142
3175
|
}),
|
|
3143
|
-
import_v47.z.
|
|
3176
|
+
import_v47.z.looseObject({
|
|
3144
3177
|
type: import_v47.z.literal("message-metadata"),
|
|
3145
3178
|
messageMetadata: import_v47.z.unknown()
|
|
3146
3179
|
})
|
|
@@ -3589,11 +3622,32 @@ function processUIMessageStream({
|
|
|
3589
3622
|
async transform(chunk, controller) {
|
|
3590
3623
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
3591
3624
|
var _a16, _b, _c, _d;
|
|
3625
|
+
function getCurrentStepParts() {
|
|
3626
|
+
const parts = state.message.parts;
|
|
3627
|
+
let currentStepStartIndex = parts.length - 1;
|
|
3628
|
+
while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
|
|
3629
|
+
currentStepStartIndex--;
|
|
3630
|
+
}
|
|
3631
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
3632
|
+
}
|
|
3633
|
+
function getCurrentStepToolInvocations() {
|
|
3634
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
3635
|
+
}
|
|
3592
3636
|
function getToolInvocation(toolCallId) {
|
|
3593
|
-
const toolInvocations =
|
|
3594
|
-
|
|
3637
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
3638
|
+
let toolInvocation = toolInvocations.find(
|
|
3595
3639
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3596
3640
|
);
|
|
3641
|
+
if (toolInvocation == null) {
|
|
3642
|
+
const parts = state.message.parts;
|
|
3643
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3644
|
+
const part = parts[i];
|
|
3645
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
3646
|
+
toolInvocation = part;
|
|
3647
|
+
break;
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3597
3651
|
if (toolInvocation == null) {
|
|
3598
3652
|
throw new Error(
|
|
3599
3653
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3602,12 +3656,22 @@ function processUIMessageStream({
|
|
|
3602
3656
|
return toolInvocation;
|
|
3603
3657
|
}
|
|
3604
3658
|
function getDynamicToolInvocation(toolCallId) {
|
|
3605
|
-
const toolInvocations =
|
|
3659
|
+
const toolInvocations = getCurrentStepParts().filter(
|
|
3606
3660
|
(part) => part.type === "dynamic-tool"
|
|
3607
3661
|
);
|
|
3608
|
-
|
|
3662
|
+
let toolInvocation = toolInvocations.find(
|
|
3609
3663
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3610
3664
|
);
|
|
3665
|
+
if (toolInvocation == null) {
|
|
3666
|
+
const parts = state.message.parts;
|
|
3667
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3668
|
+
const part = parts[i];
|
|
3669
|
+
if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) {
|
|
3670
|
+
toolInvocation = part;
|
|
3671
|
+
break;
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3611
3675
|
if (toolInvocation == null) {
|
|
3612
3676
|
throw new Error(
|
|
3613
3677
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3615,9 +3679,9 @@ function processUIMessageStream({
|
|
|
3615
3679
|
}
|
|
3616
3680
|
return toolInvocation;
|
|
3617
3681
|
}
|
|
3618
|
-
function updateToolPart(options) {
|
|
3682
|
+
function updateToolPart(options, existingPart) {
|
|
3619
3683
|
var _a17;
|
|
3620
|
-
const part =
|
|
3684
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3621
3685
|
(part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
3622
3686
|
);
|
|
3623
3687
|
const anyOptions = options;
|
|
@@ -3648,9 +3712,9 @@ function processUIMessageStream({
|
|
|
3648
3712
|
});
|
|
3649
3713
|
}
|
|
3650
3714
|
}
|
|
3651
|
-
function updateDynamicToolPart(options) {
|
|
3715
|
+
function updateDynamicToolPart(options, existingPart) {
|
|
3652
3716
|
var _a17, _b2;
|
|
3653
|
-
const part =
|
|
3717
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3654
3718
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
3655
3719
|
);
|
|
3656
3720
|
const anyOptions = options;
|
|
@@ -3782,7 +3846,7 @@ function processUIMessageStream({
|
|
|
3782
3846
|
break;
|
|
3783
3847
|
}
|
|
3784
3848
|
case "tool-input-start": {
|
|
3785
|
-
const toolInvocations =
|
|
3849
|
+
const toolInvocations = getCurrentStepParts().filter(isToolUIPart);
|
|
3786
3850
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
3787
3851
|
text: "",
|
|
3788
3852
|
toolName: chunk.toolName,
|
|
@@ -3892,25 +3956,31 @@ function processUIMessageStream({
|
|
|
3892
3956
|
const toolInvocation = getDynamicToolInvocation(
|
|
3893
3957
|
chunk.toolCallId
|
|
3894
3958
|
);
|
|
3895
|
-
updateDynamicToolPart(
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3959
|
+
updateDynamicToolPart(
|
|
3960
|
+
{
|
|
3961
|
+
toolCallId: chunk.toolCallId,
|
|
3962
|
+
toolName: toolInvocation.toolName,
|
|
3963
|
+
state: "output-available",
|
|
3964
|
+
input: toolInvocation.input,
|
|
3965
|
+
output: chunk.output,
|
|
3966
|
+
preliminary: chunk.preliminary
|
|
3967
|
+
},
|
|
3968
|
+
toolInvocation
|
|
3969
|
+
);
|
|
3903
3970
|
} else {
|
|
3904
3971
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3905
|
-
updateToolPart(
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3972
|
+
updateToolPart(
|
|
3973
|
+
{
|
|
3974
|
+
toolCallId: chunk.toolCallId,
|
|
3975
|
+
toolName: getToolName(toolInvocation),
|
|
3976
|
+
state: "output-available",
|
|
3977
|
+
input: toolInvocation.input,
|
|
3978
|
+
output: chunk.output,
|
|
3979
|
+
providerExecuted: chunk.providerExecuted,
|
|
3980
|
+
preliminary: chunk.preliminary
|
|
3981
|
+
},
|
|
3982
|
+
toolInvocation
|
|
3983
|
+
);
|
|
3914
3984
|
}
|
|
3915
3985
|
write();
|
|
3916
3986
|
break;
|
|
@@ -3920,25 +3990,31 @@ function processUIMessageStream({
|
|
|
3920
3990
|
const toolInvocation = getDynamicToolInvocation(
|
|
3921
3991
|
chunk.toolCallId
|
|
3922
3992
|
);
|
|
3923
|
-
updateDynamicToolPart(
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3993
|
+
updateDynamicToolPart(
|
|
3994
|
+
{
|
|
3995
|
+
toolCallId: chunk.toolCallId,
|
|
3996
|
+
toolName: toolInvocation.toolName,
|
|
3997
|
+
state: "output-error",
|
|
3998
|
+
input: toolInvocation.input,
|
|
3999
|
+
errorText: chunk.errorText,
|
|
4000
|
+
providerExecuted: chunk.providerExecuted
|
|
4001
|
+
},
|
|
4002
|
+
toolInvocation
|
|
4003
|
+
);
|
|
3931
4004
|
} else {
|
|
3932
4005
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3933
|
-
updateToolPart(
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
4006
|
+
updateToolPart(
|
|
4007
|
+
{
|
|
4008
|
+
toolCallId: chunk.toolCallId,
|
|
4009
|
+
toolName: getToolName(toolInvocation),
|
|
4010
|
+
state: "output-error",
|
|
4011
|
+
input: toolInvocation.input,
|
|
4012
|
+
rawInput: toolInvocation.rawInput,
|
|
4013
|
+
errorText: chunk.errorText,
|
|
4014
|
+
providerExecuted: chunk.providerExecuted
|
|
4015
|
+
},
|
|
4016
|
+
toolInvocation
|
|
4017
|
+
);
|
|
3942
4018
|
}
|
|
3943
4019
|
write();
|
|
3944
4020
|
break;
|
|
@@ -4759,6 +4835,7 @@ var DefaultStreamTextResult = class {
|
|
|
4759
4835
|
let recordedRequest = {};
|
|
4760
4836
|
let recordedWarnings = [];
|
|
4761
4837
|
const recordedSteps = [];
|
|
4838
|
+
let currentStepToolSet = tools;
|
|
4762
4839
|
let rootSpan;
|
|
4763
4840
|
let activeTextContent = createIdMap();
|
|
4764
4841
|
let activeReasoningContent = createIdMap();
|
|
@@ -4874,7 +4951,7 @@ var DefaultStreamTextResult = class {
|
|
|
4874
4951
|
if (part.type === "finish-step") {
|
|
4875
4952
|
const stepMessages = toResponseMessages({
|
|
4876
4953
|
content: recordedContent,
|
|
4877
|
-
tools
|
|
4954
|
+
tools: currentStepToolSet
|
|
4878
4955
|
});
|
|
4879
4956
|
const currentStepResult = new DefaultStepResult({
|
|
4880
4957
|
content: recordedContent,
|
|
@@ -5088,10 +5165,16 @@ var DefaultStreamTextResult = class {
|
|
|
5088
5165
|
supportedUrls: await stepModel.supportedUrls,
|
|
5089
5166
|
download: download2
|
|
5090
5167
|
});
|
|
5168
|
+
const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
|
|
5169
|
+
const stepToolSet = filterActiveTools({
|
|
5170
|
+
tools,
|
|
5171
|
+
activeTools: stepActiveTools
|
|
5172
|
+
});
|
|
5173
|
+
currentStepToolSet = stepToolSet;
|
|
5091
5174
|
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
5092
5175
|
tools,
|
|
5093
|
-
toolChoice: (
|
|
5094
|
-
activeTools:
|
|
5176
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
5177
|
+
activeTools: stepActiveTools
|
|
5095
5178
|
});
|
|
5096
5179
|
const {
|
|
5097
5180
|
result: { stream: stream2, response, request },
|
|
@@ -5157,7 +5240,7 @@ var DefaultStreamTextResult = class {
|
|
|
5157
5240
|
})
|
|
5158
5241
|
);
|
|
5159
5242
|
const streamWithToolResults = runToolsTransformation({
|
|
5160
|
-
tools,
|
|
5243
|
+
tools: stepToolSet,
|
|
5161
5244
|
generatorStream: stream2,
|
|
5162
5245
|
tracer,
|
|
5163
5246
|
telemetry,
|
|
@@ -5290,7 +5373,7 @@ var DefaultStreamTextResult = class {
|
|
|
5290
5373
|
}
|
|
5291
5374
|
case "tool-input-start": {
|
|
5292
5375
|
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
5293
|
-
const tool2 =
|
|
5376
|
+
const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
|
|
5294
5377
|
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
5295
5378
|
await tool2.onInputStart({
|
|
5296
5379
|
toolCallId: chunk.id,
|
|
@@ -5312,7 +5395,7 @@ var DefaultStreamTextResult = class {
|
|
|
5312
5395
|
}
|
|
5313
5396
|
case "tool-input-delta": {
|
|
5314
5397
|
const toolName = activeToolCallToolNames[chunk.id];
|
|
5315
|
-
const tool2 =
|
|
5398
|
+
const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
|
|
5316
5399
|
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
5317
5400
|
await tool2.onInputDelta({
|
|
5318
5401
|
inputTextDelta: chunk.delta,
|
|
@@ -5409,7 +5492,7 @@ var DefaultStreamTextResult = class {
|
|
|
5409
5492
|
// use transformed content to create the messages for the next step:
|
|
5410
5493
|
recordedSteps[recordedSteps.length - 1].content
|
|
5411
5494
|
),
|
|
5412
|
-
tools
|
|
5495
|
+
tools: stepToolSet
|
|
5413
5496
|
})
|
|
5414
5497
|
);
|
|
5415
5498
|
try {
|
|
@@ -9468,24 +9551,26 @@ var AbstractChat = class {
|
|
|
9468
9551
|
body,
|
|
9469
9552
|
messageId
|
|
9470
9553
|
}) {
|
|
9471
|
-
var _a16, _b, _c
|
|
9554
|
+
var _a16, _b, _c;
|
|
9472
9555
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
9473
9556
|
const lastMessage = this.lastMessage;
|
|
9474
9557
|
let isAbort = false;
|
|
9475
9558
|
let isDisconnect = false;
|
|
9476
9559
|
let isError = false;
|
|
9560
|
+
let activeResponse;
|
|
9477
9561
|
try {
|
|
9478
|
-
const
|
|
9562
|
+
const response = {
|
|
9479
9563
|
state: createStreamingUIMessageState({
|
|
9480
9564
|
lastMessage: this.state.snapshot(lastMessage),
|
|
9481
9565
|
messageId: this.generateId()
|
|
9482
9566
|
}),
|
|
9483
9567
|
abortController: new AbortController()
|
|
9484
9568
|
};
|
|
9485
|
-
activeResponse
|
|
9569
|
+
activeResponse = response;
|
|
9570
|
+
response.abortController.signal.addEventListener("abort", () => {
|
|
9486
9571
|
isAbort = true;
|
|
9487
9572
|
});
|
|
9488
|
-
this.activeResponse =
|
|
9573
|
+
this.activeResponse = response;
|
|
9489
9574
|
let stream;
|
|
9490
9575
|
if (trigger === "resume-stream") {
|
|
9491
9576
|
const reconnect = await this.transport.reconnectToStream({
|
|
@@ -9503,7 +9588,7 @@ var AbstractChat = class {
|
|
|
9503
9588
|
stream = await this.transport.sendMessages({
|
|
9504
9589
|
chatId: this.id,
|
|
9505
9590
|
messages: this.state.messages,
|
|
9506
|
-
abortSignal:
|
|
9591
|
+
abortSignal: response.abortController.signal,
|
|
9507
9592
|
metadata,
|
|
9508
9593
|
headers,
|
|
9509
9594
|
body,
|
|
@@ -9515,18 +9600,18 @@ var AbstractChat = class {
|
|
|
9515
9600
|
// serialize the job execution to avoid race conditions:
|
|
9516
9601
|
this.jobExecutor.run(
|
|
9517
9602
|
() => job({
|
|
9518
|
-
state:
|
|
9603
|
+
state: response.state,
|
|
9519
9604
|
write: () => {
|
|
9520
9605
|
var _a17;
|
|
9521
9606
|
this.setStatus({ status: "streaming" });
|
|
9522
|
-
const replaceLastMessage =
|
|
9607
|
+
const replaceLastMessage = response.state.message.id === ((_a17 = this.lastMessage) == null ? void 0 : _a17.id);
|
|
9523
9608
|
if (replaceLastMessage) {
|
|
9524
9609
|
this.state.replaceMessage(
|
|
9525
9610
|
this.state.messages.length - 1,
|
|
9526
|
-
|
|
9611
|
+
response.state.message
|
|
9527
9612
|
);
|
|
9528
9613
|
} else {
|
|
9529
|
-
this.state.pushMessage(
|
|
9614
|
+
this.state.pushMessage(response.state.message);
|
|
9530
9615
|
}
|
|
9531
9616
|
}
|
|
9532
9617
|
})
|
|
@@ -9565,23 +9650,27 @@ var AbstractChat = class {
|
|
|
9565
9650
|
this.setStatus({ status: "error", error: err });
|
|
9566
9651
|
} finally {
|
|
9567
9652
|
try {
|
|
9568
|
-
(
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9653
|
+
if (activeResponse) {
|
|
9654
|
+
(_a16 = this.onFinish) == null ? void 0 : _a16.call(this, {
|
|
9655
|
+
message: activeResponse.state.message,
|
|
9656
|
+
messages: this.state.messages,
|
|
9657
|
+
isAbort,
|
|
9658
|
+
isDisconnect,
|
|
9659
|
+
isError,
|
|
9660
|
+
finishReason: activeResponse.state.finishReason
|
|
9661
|
+
});
|
|
9662
|
+
}
|
|
9576
9663
|
} catch (err) {
|
|
9577
9664
|
console.error(err);
|
|
9578
9665
|
}
|
|
9579
|
-
this.activeResponse
|
|
9666
|
+
if (this.activeResponse === activeResponse) {
|
|
9667
|
+
this.activeResponse = void 0;
|
|
9668
|
+
}
|
|
9580
9669
|
}
|
|
9581
|
-
if (((
|
|
9670
|
+
if (((_b = this.sendAutomaticallyWhen) == null ? void 0 : _b.call(this, { messages: this.state.messages })) && !isError) {
|
|
9582
9671
|
await this.makeRequest({
|
|
9583
9672
|
trigger: "submit-message",
|
|
9584
|
-
messageId: (
|
|
9673
|
+
messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
|
|
9585
9674
|
metadata,
|
|
9586
9675
|
headers,
|
|
9587
9676
|
body
|