ai 6.0.230 → 6.0.232
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 +1 -131
- package/dist/index.d.ts +1 -131
- package/dist/index.js +111 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -75
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +45 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +45 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/generate-text/filter-active-tools.ts +19 -0
- package/src/generate-text/generate-text.ts +16 -7
- package/src/generate-text/stream-text.ts +13 -6
- package/src/prompt/convert-to-language-model-prompt.ts +13 -0
- package/src/ui-message-stream/ui-message-chunks.ts +26 -26
|
@@ -95,6 +95,7 @@ import type {
|
|
|
95
95
|
} from './callback-events';
|
|
96
96
|
import type { ContentPart } from './content-part';
|
|
97
97
|
import { executeToolCall } from './execute-tool-call';
|
|
98
|
+
import { filterActiveTools } from './filter-active-tools';
|
|
98
99
|
import { text, type Output } from './output';
|
|
99
100
|
import type {
|
|
100
101
|
InferCompleteOutput,
|
|
@@ -882,6 +883,7 @@ class DefaultStreamTextResult<
|
|
|
882
883
|
let recordedWarnings: Array<CallWarning> = [];
|
|
883
884
|
const recordedSteps: StepResult<TOOLS>[] = [];
|
|
884
885
|
let recordedNoOutputError: NoOutputGeneratedError | undefined;
|
|
886
|
+
let currentStepToolSet = tools;
|
|
885
887
|
|
|
886
888
|
// Track provider-executed tool calls that support deferred results
|
|
887
889
|
// (e.g., code_execution in programmatic tool calling scenarios).
|
|
@@ -1081,7 +1083,7 @@ class DefaultStreamTextResult<
|
|
|
1081
1083
|
if (part.type === 'finish-step') {
|
|
1082
1084
|
const stepMessages = await toResponseMessages({
|
|
1083
1085
|
content: recordedContent,
|
|
1084
|
-
tools,
|
|
1086
|
+
tools: currentStepToolSet,
|
|
1085
1087
|
});
|
|
1086
1088
|
|
|
1087
1089
|
// Add step information (after response messages are updated):
|
|
@@ -1641,6 +1643,11 @@ class DefaultStreamTextResult<
|
|
|
1641
1643
|
|
|
1642
1644
|
const stepActiveTools =
|
|
1643
1645
|
prepareStepResult?.activeTools ?? activeTools;
|
|
1646
|
+
const stepToolSet = filterActiveTools({
|
|
1647
|
+
tools,
|
|
1648
|
+
activeTools: stepActiveTools,
|
|
1649
|
+
});
|
|
1650
|
+
currentStepToolSet = stepToolSet;
|
|
1644
1651
|
|
|
1645
1652
|
const { toolChoice: stepToolChoice, tools: stepTools } =
|
|
1646
1653
|
await prepareToolsAndToolChoice({
|
|
@@ -1759,7 +1766,7 @@ class DefaultStreamTextResult<
|
|
|
1759
1766
|
);
|
|
1760
1767
|
|
|
1761
1768
|
const streamWithToolResults = runToolsTransformation({
|
|
1762
|
-
tools,
|
|
1769
|
+
tools: stepToolSet,
|
|
1763
1770
|
generatorStream: stream,
|
|
1764
1771
|
tracer,
|
|
1765
1772
|
telemetry,
|
|
@@ -1967,7 +1974,7 @@ class DefaultStreamTextResult<
|
|
|
1967
1974
|
case 'tool-input-start': {
|
|
1968
1975
|
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
1969
1976
|
|
|
1970
|
-
const tool =
|
|
1977
|
+
const tool = stepToolSet?.[chunk.toolName];
|
|
1971
1978
|
if (tool?.onInputStart != null) {
|
|
1972
1979
|
await tool.onInputStart({
|
|
1973
1980
|
toolCallId: chunk.id,
|
|
@@ -1993,7 +2000,7 @@ class DefaultStreamTextResult<
|
|
|
1993
2000
|
|
|
1994
2001
|
case 'tool-input-delta': {
|
|
1995
2002
|
const toolName = activeToolCallToolNames[chunk.id];
|
|
1996
|
-
const tool =
|
|
2003
|
+
const tool = stepToolSet?.[toolName];
|
|
1997
2004
|
|
|
1998
2005
|
if (tool?.onInputDelta != null) {
|
|
1999
2006
|
await tool.onInputDelta({
|
|
@@ -2167,7 +2174,7 @@ class DefaultStreamTextResult<
|
|
|
2167
2174
|
// the client tool's result is sent back.
|
|
2168
2175
|
for (const toolCall of stepToolCalls) {
|
|
2169
2176
|
if (toolCall.providerExecuted !== true) continue;
|
|
2170
|
-
const tool =
|
|
2177
|
+
const tool = stepToolSet?.[toolCall.toolName];
|
|
2171
2178
|
if (
|
|
2172
2179
|
tool?.type === 'provider' &&
|
|
2173
2180
|
tool.supportsDeferredResults
|
|
@@ -2220,7 +2227,7 @@ class DefaultStreamTextResult<
|
|
|
2220
2227
|
content:
|
|
2221
2228
|
// use transformed content to create the messages for the next step:
|
|
2222
2229
|
recordedSteps[recordedSteps.length - 1].content,
|
|
2223
|
-
tools,
|
|
2230
|
+
tools: stepToolSet,
|
|
2224
2231
|
})),
|
|
2225
2232
|
);
|
|
2226
2233
|
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
createDefaultDownloadFunction,
|
|
26
26
|
type DownloadFunction,
|
|
27
27
|
} from '../util/download/download-function';
|
|
28
|
+
import { mergeObjects } from '../util/merge-objects';
|
|
28
29
|
import {
|
|
29
30
|
convertDataContentToBase64String,
|
|
30
31
|
convertToLanguageModelV3DataContent,
|
|
@@ -106,7 +107,19 @@ export async function convertToLanguageModelPrompt({
|
|
|
106
107
|
|
|
107
108
|
const lastCombinedMessage = combinedMessages.at(-1);
|
|
108
109
|
if (lastCombinedMessage?.role === 'tool') {
|
|
110
|
+
const lastContentPart = lastCombinedMessage.content.at(-1);
|
|
111
|
+
if (
|
|
112
|
+
lastContentPart != null &&
|
|
113
|
+
lastCombinedMessage.providerOptions != null
|
|
114
|
+
) {
|
|
115
|
+
lastContentPart.providerOptions = mergeObjects(
|
|
116
|
+
lastCombinedMessage.providerOptions,
|
|
117
|
+
lastContentPart.providerOptions,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
109
121
|
lastCombinedMessage.content.push(...message.content);
|
|
122
|
+
lastCombinedMessage.providerOptions = message.providerOptions;
|
|
110
123
|
} else {
|
|
111
124
|
combinedMessages.push(message);
|
|
112
125
|
}
|
|
@@ -21,29 +21,29 @@ const toolMetadataSchema: z.ZodType<JSONObject> = z.record(
|
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
export const uiMessageChunkSchema = lazySchema(() =>
|
|
24
|
-
zodSchema(
|
|
24
|
+
zodSchema<UIMessageChunk>(
|
|
25
25
|
z.union([
|
|
26
|
-
z.
|
|
26
|
+
z.looseObject({
|
|
27
27
|
type: z.literal('text-start'),
|
|
28
28
|
id: z.string(),
|
|
29
29
|
providerMetadata: providerMetadataSchema.optional(),
|
|
30
30
|
}),
|
|
31
|
-
z.
|
|
31
|
+
z.looseObject({
|
|
32
32
|
type: z.literal('text-delta'),
|
|
33
33
|
id: z.string(),
|
|
34
34
|
delta: z.string(),
|
|
35
35
|
providerMetadata: providerMetadataSchema.optional(),
|
|
36
36
|
}),
|
|
37
|
-
z.
|
|
37
|
+
z.looseObject({
|
|
38
38
|
type: z.literal('text-end'),
|
|
39
39
|
id: z.string(),
|
|
40
40
|
providerMetadata: providerMetadataSchema.optional(),
|
|
41
41
|
}),
|
|
42
|
-
z.
|
|
42
|
+
z.looseObject({
|
|
43
43
|
type: z.literal('error'),
|
|
44
44
|
errorText: z.string(),
|
|
45
45
|
}),
|
|
46
|
-
z.
|
|
46
|
+
z.looseObject({
|
|
47
47
|
type: z.literal('tool-input-start'),
|
|
48
48
|
toolCallId: z.string(),
|
|
49
49
|
toolName: z.string(),
|
|
@@ -53,12 +53,12 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
53
53
|
dynamic: z.boolean().optional(),
|
|
54
54
|
title: z.string().optional(),
|
|
55
55
|
}),
|
|
56
|
-
z.
|
|
56
|
+
z.looseObject({
|
|
57
57
|
type: z.literal('tool-input-delta'),
|
|
58
58
|
toolCallId: z.string(),
|
|
59
59
|
inputTextDelta: z.string(),
|
|
60
60
|
}),
|
|
61
|
-
z.
|
|
61
|
+
z.looseObject({
|
|
62
62
|
type: z.literal('tool-input-available'),
|
|
63
63
|
toolCallId: z.string(),
|
|
64
64
|
toolName: z.string(),
|
|
@@ -69,7 +69,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
69
69
|
dynamic: z.boolean().optional(),
|
|
70
70
|
title: z.string().optional(),
|
|
71
71
|
}),
|
|
72
|
-
z.
|
|
72
|
+
z.looseObject({
|
|
73
73
|
type: z.literal('tool-input-error'),
|
|
74
74
|
toolCallId: z.string(),
|
|
75
75
|
toolName: z.string(),
|
|
@@ -81,13 +81,13 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
81
81
|
errorText: z.string(),
|
|
82
82
|
title: z.string().optional(),
|
|
83
83
|
}),
|
|
84
|
-
z.
|
|
84
|
+
z.looseObject({
|
|
85
85
|
type: z.literal('tool-approval-request'),
|
|
86
86
|
approvalId: z.string(),
|
|
87
87
|
toolCallId: z.string(),
|
|
88
88
|
signature: z.string().optional(),
|
|
89
89
|
}),
|
|
90
|
-
z.
|
|
90
|
+
z.looseObject({
|
|
91
91
|
type: z.literal('tool-output-available'),
|
|
92
92
|
toolCallId: z.string(),
|
|
93
93
|
output: z.unknown(),
|
|
@@ -97,7 +97,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
97
97
|
dynamic: z.boolean().optional(),
|
|
98
98
|
preliminary: z.boolean().optional(),
|
|
99
99
|
}),
|
|
100
|
-
z.
|
|
100
|
+
z.looseObject({
|
|
101
101
|
type: z.literal('tool-output-error'),
|
|
102
102
|
toolCallId: z.string(),
|
|
103
103
|
errorText: z.string(),
|
|
@@ -106,34 +106,34 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
106
106
|
toolMetadata: toolMetadataSchema.optional(),
|
|
107
107
|
dynamic: z.boolean().optional(),
|
|
108
108
|
}),
|
|
109
|
-
z.
|
|
109
|
+
z.looseObject({
|
|
110
110
|
type: z.literal('tool-output-denied'),
|
|
111
111
|
toolCallId: z.string(),
|
|
112
112
|
}),
|
|
113
|
-
z.
|
|
113
|
+
z.looseObject({
|
|
114
114
|
type: z.literal('reasoning-start'),
|
|
115
115
|
id: z.string(),
|
|
116
116
|
providerMetadata: providerMetadataSchema.optional(),
|
|
117
117
|
}),
|
|
118
|
-
z.
|
|
118
|
+
z.looseObject({
|
|
119
119
|
type: z.literal('reasoning-delta'),
|
|
120
120
|
id: z.string(),
|
|
121
121
|
delta: z.string(),
|
|
122
122
|
providerMetadata: providerMetadataSchema.optional(),
|
|
123
123
|
}),
|
|
124
|
-
z.
|
|
124
|
+
z.looseObject({
|
|
125
125
|
type: z.literal('reasoning-end'),
|
|
126
126
|
id: z.string(),
|
|
127
127
|
providerMetadata: providerMetadataSchema.optional(),
|
|
128
128
|
}),
|
|
129
|
-
z.
|
|
129
|
+
z.looseObject({
|
|
130
130
|
type: z.literal('source-url'),
|
|
131
131
|
sourceId: z.string(),
|
|
132
132
|
url: z.string(),
|
|
133
133
|
title: z.string().optional(),
|
|
134
134
|
providerMetadata: providerMetadataSchema.optional(),
|
|
135
135
|
}),
|
|
136
|
-
z.
|
|
136
|
+
z.looseObject({
|
|
137
137
|
type: z.literal('source-document'),
|
|
138
138
|
sourceId: z.string(),
|
|
139
139
|
mediaType: z.string(),
|
|
@@ -141,13 +141,13 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
141
141
|
filename: z.string().optional(),
|
|
142
142
|
providerMetadata: providerMetadataSchema.optional(),
|
|
143
143
|
}),
|
|
144
|
-
z.
|
|
144
|
+
z.looseObject({
|
|
145
145
|
type: z.literal('file'),
|
|
146
146
|
url: z.string(),
|
|
147
147
|
mediaType: z.string(),
|
|
148
148
|
providerMetadata: providerMetadataSchema.optional(),
|
|
149
149
|
}),
|
|
150
|
-
z.
|
|
150
|
+
z.looseObject({
|
|
151
151
|
type: z.custom<`data-${string}`>(
|
|
152
152
|
(value): value is `data-${string}` =>
|
|
153
153
|
typeof value === 'string' && value.startsWith('data-'),
|
|
@@ -157,18 +157,18 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
157
157
|
data: z.unknown(),
|
|
158
158
|
transient: z.boolean().optional(),
|
|
159
159
|
}),
|
|
160
|
-
z.
|
|
160
|
+
z.looseObject({
|
|
161
161
|
type: z.literal('start-step'),
|
|
162
162
|
}),
|
|
163
|
-
z.
|
|
163
|
+
z.looseObject({
|
|
164
164
|
type: z.literal('finish-step'),
|
|
165
165
|
}),
|
|
166
|
-
z.
|
|
166
|
+
z.looseObject({
|
|
167
167
|
type: z.literal('start'),
|
|
168
168
|
messageId: z.string().optional(),
|
|
169
169
|
messageMetadata: z.unknown().optional(),
|
|
170
170
|
}),
|
|
171
|
-
z.
|
|
171
|
+
z.looseObject({
|
|
172
172
|
type: z.literal('finish'),
|
|
173
173
|
finishReason: z
|
|
174
174
|
.enum([
|
|
@@ -182,11 +182,11 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
182
182
|
.optional(),
|
|
183
183
|
messageMetadata: z.unknown().optional(),
|
|
184
184
|
}),
|
|
185
|
-
z.
|
|
185
|
+
z.looseObject({
|
|
186
186
|
type: z.literal('abort'),
|
|
187
187
|
reason: z.string().optional(),
|
|
188
188
|
}),
|
|
189
|
-
z.
|
|
189
|
+
z.looseObject({
|
|
190
190
|
type: z.literal('message-metadata'),
|
|
191
191
|
messageMetadata: z.unknown(),
|
|
192
192
|
}),
|