ai 3.1.16 → 3.1.18

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/dist/index.d.mts CHANGED
@@ -728,34 +728,6 @@ onlyBar('bar');
728
728
  */
729
729
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
730
730
 
731
- /**
732
- Typed tool call that is returned by generateText and streamText.
733
- It contains the tool call ID, the tool name, and the tool arguments.
734
- */
735
- interface ToolCall$1<NAME extends string, ARGS> {
736
- /**
737
- ID of the tool call. This ID is used to match the tool call with the tool result.
738
- */
739
- toolCallId: string;
740
- /**
741
- Name of the tool that is being called.
742
- */
743
- toolName: NAME;
744
- /**
745
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
746
- */
747
- args: ARGS;
748
- }
749
- type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
750
- [NAME in keyof TOOLS]: {
751
- type: 'tool-call';
752
- toolCallId: string;
753
- toolName: NAME & string;
754
- args: z.infer<TOOLS[NAME]['parameters']>;
755
- };
756
- }>;
757
- type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
758
-
759
731
  /**
760
732
  Typed tool result that is returned by generateText and streamText.
761
733
  It contains the tool call ID, the tool name, the tool arguments, and the tool result.
@@ -798,6 +770,44 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
798
770
  type ToToolResult<TOOLS extends Record<string, CoreTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
799
771
  type ToToolResultArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolResult<TOOLS>>;
800
772
 
773
+ /**
774
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
775
+ with the AI core functions (e.g. `streamText`).
776
+ */
777
+ declare function convertToCoreMessages(messages: Array<{
778
+ role: 'user' | 'assistant';
779
+ content: string;
780
+ toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
781
+ }>): CoreMessage[];
782
+
783
+ /**
784
+ Typed tool call that is returned by generateText and streamText.
785
+ It contains the tool call ID, the tool name, and the tool arguments.
786
+ */
787
+ interface ToolCall$1<NAME extends string, ARGS> {
788
+ /**
789
+ ID of the tool call. This ID is used to match the tool call with the tool result.
790
+ */
791
+ toolCallId: string;
792
+ /**
793
+ Name of the tool that is being called.
794
+ */
795
+ toolName: NAME;
796
+ /**
797
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
798
+ */
799
+ args: ARGS;
800
+ }
801
+ type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
802
+ [NAME in keyof TOOLS]: {
803
+ type: 'tool-call';
804
+ toolCallId: string;
805
+ toolName: NAME & string;
806
+ args: z.infer<TOOLS[NAME]['parameters']>;
807
+ };
808
+ }>;
809
+ type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
810
+
801
811
  /**
802
812
  Generate a text and call tools for a given prompt using a language model.
803
813
 
@@ -876,6 +886,14 @@ declare class GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
876
886
  */
877
887
  readonly warnings: CallWarning[] | undefined;
878
888
  /**
889
+ The response messages that were generated during the call. It consists of an assistant message,
890
+ potentially containing tool calls.
891
+ When there are tool results, there is an additional tool message with the tool results that are available.
892
+ If there are tools that do not have execute functions, they are not included in the tool results and
893
+ need to be added separately.
894
+ */
895
+ readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
896
+ /**
879
897
  Optional raw response data.
880
898
  */
881
899
  rawResponse?: {
@@ -1143,16 +1161,6 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1143
1161
  */
1144
1162
  declare const experimental_streamText: typeof streamText;
1145
1163
 
1146
- /**
1147
- Converts an array of messages from useChat into an array of CoreMessages that can be used
1148
- with the AI core functions (e.g. `streamText`).
1149
- */
1150
- declare function convertToCoreMessages(messages: Array<{
1151
- role: 'user' | 'assistant';
1152
- content: string;
1153
- toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
1154
- }>): CoreMessage[];
1155
-
1156
1164
  type AssistantStatus = 'in_progress' | 'awaiting_message';
1157
1165
  type UseAssistantOptions = {
1158
1166
  /**
@@ -1185,6 +1193,9 @@ type UseAssistantOptions = {
1185
1193
  onError?: (error: Error) => void;
1186
1194
  };
1187
1195
 
1196
+ /**
1197
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1198
+ */
1188
1199
  interface FunctionCall$1 {
1189
1200
  /**
1190
1201
  * The arguments to call the function with, as generated by the model in JSON
@@ -1199,6 +1210,8 @@ interface FunctionCall$1 {
1199
1210
  name?: string;
1200
1211
  }
1201
1212
  /**
1213
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1214
+ *
1202
1215
  * The tool calls generated by the model, such as function calls.
1203
1216
  */
1204
1217
  interface ToolCall {
@@ -1210,6 +1223,8 @@ interface ToolCall {
1210
1223
  };
1211
1224
  }
1212
1225
  /**
1226
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
1227
+ *
1213
1228
  * Controls which (if any) function is called by the model.
1214
1229
  * - none means the model will not call a function and instead generates a message.
1215
1230
  * - auto means the model can pick between generating a message or calling a function.
@@ -1223,6 +1238,8 @@ type ToolChoice = 'none' | 'auto' | {
1223
1238
  };
1224
1239
  };
1225
1240
  /**
1241
+ * @deprecated use AI SDK 3.1 CoreTool instead
1242
+ *
1226
1243
  * A list of tools the model may call. Currently, only functions are supported as a tool.
1227
1244
  * Use this to provide a list of functions the model may generate JSON inputs for.
1228
1245
  */
@@ -1230,6 +1247,9 @@ interface Tool {
1230
1247
  type: 'function';
1231
1248
  function: Function;
1232
1249
  }
1250
+ /**
1251
+ * @deprecated use AI SDK 3.1 CoreTool instead
1252
+ */
1233
1253
  interface Function {
1234
1254
  /**
1235
1255
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -1260,17 +1280,20 @@ Once the call is complete, the invocation is a tool result.
1260
1280
  */
1261
1281
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
1262
1282
  /**
1263
- * Shared types between the API and UI packages.
1283
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
1264
1284
  */
1265
1285
  interface Message$1 {
1266
1286
  id: string;
1267
- tool_call_id?: string;
1268
1287
  createdAt?: Date;
1269
1288
  content: string;
1289
+ tool_call_id?: string;
1270
1290
  /**
1271
1291
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
1272
1292
  */
1273
1293
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
1294
+ /**
1295
+ * `function` and `tool` roles are deprecated.
1296
+ */
1274
1297
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1275
1298
  /**
1276
1299
  *
@@ -1279,6 +1302,8 @@ interface Message$1 {
1279
1302
  */
1280
1303
  name?: string;
1281
1304
  /**
1305
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1306
+ *
1282
1307
  * If the assistant role makes a function call, the `function_call` field
1283
1308
  * contains the function call name and arguments. Otherwise, the field should
1284
1309
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -1286,6 +1311,8 @@ interface Message$1 {
1286
1311
  function_call?: string | FunctionCall$1;
1287
1312
  data?: JSONValue;
1288
1313
  /**
1314
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1315
+ *
1289
1316
  * If the assistant role makes a tool call, the `tool_calls` field contains
1290
1317
  * the tool call name and arguments. Otherwise, the field should not be set.
1291
1318
  */
@@ -1312,7 +1339,13 @@ type ChatRequest = {
1312
1339
  tools?: Array<Tool>;
1313
1340
  tool_choice?: ToolChoice;
1314
1341
  };
1342
+ /**
1343
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1344
+ */
1315
1345
  type FunctionCallHandler = (chatMessages: Message$1[], functionCall: FunctionCall$1) => Promise<ChatRequest | void>;
1346
+ /**
1347
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1348
+ */
1316
1349
  type ToolCallHandler = (chatMessages: Message$1[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
1317
1350
  type RequestOptions = {
1318
1351
  headers?: Record<string, string> | Headers;
@@ -1347,18 +1380,32 @@ type UseChatOptions = {
1347
1380
  */
1348
1381
  initialInput?: string;
1349
1382
  /**
1383
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1384
+ *
1350
1385
  * Callback function to be called when a function call is received.
1351
1386
  * If the function returns a `ChatRequest` object, the request will be sent
1352
1387
  * automatically to the API and will be used to update the chat.
1353
1388
  */
1354
1389
  experimental_onFunctionCall?: FunctionCallHandler;
1355
1390
  /**
1391
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1392
+ *
1356
1393
  * Callback function to be called when a tool call is received.
1357
1394
  * If the function returns a `ChatRequest` object, the request will be sent
1358
1395
  * automatically to the API and will be used to update the chat.
1359
1396
  */
1360
1397
  experimental_onToolCall?: ToolCallHandler;
1361
1398
  /**
1399
+ Optional callback function that is invoked when a tool call is received.
1400
+ Intended for automatic client-side tool execution.
1401
+
1402
+ You can optionally return a result for the tool call,
1403
+ either synchronously or asynchronously.
1404
+ */
1405
+ onToolCall?: ({ toolCall, }: {
1406
+ toolCall: ToolCall$1<string, unknown>;
1407
+ }) => void | Promise<unknown> | unknown;
1408
+ /**
1362
1409
  * Callback function to be called when the API response is received.
1363
1410
  */
1364
1411
  onResponse?: (response: Response) => void | Promise<void>;
package/dist/index.d.ts CHANGED
@@ -728,34 +728,6 @@ onlyBar('bar');
728
728
  */
729
729
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
730
730
 
731
- /**
732
- Typed tool call that is returned by generateText and streamText.
733
- It contains the tool call ID, the tool name, and the tool arguments.
734
- */
735
- interface ToolCall$1<NAME extends string, ARGS> {
736
- /**
737
- ID of the tool call. This ID is used to match the tool call with the tool result.
738
- */
739
- toolCallId: string;
740
- /**
741
- Name of the tool that is being called.
742
- */
743
- toolName: NAME;
744
- /**
745
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
746
- */
747
- args: ARGS;
748
- }
749
- type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
750
- [NAME in keyof TOOLS]: {
751
- type: 'tool-call';
752
- toolCallId: string;
753
- toolName: NAME & string;
754
- args: z.infer<TOOLS[NAME]['parameters']>;
755
- };
756
- }>;
757
- type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
758
-
759
731
  /**
760
732
  Typed tool result that is returned by generateText and streamText.
761
733
  It contains the tool call ID, the tool name, the tool arguments, and the tool result.
@@ -798,6 +770,44 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
798
770
  type ToToolResult<TOOLS extends Record<string, CoreTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
799
771
  type ToToolResultArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolResult<TOOLS>>;
800
772
 
773
+ /**
774
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
775
+ with the AI core functions (e.g. `streamText`).
776
+ */
777
+ declare function convertToCoreMessages(messages: Array<{
778
+ role: 'user' | 'assistant';
779
+ content: string;
780
+ toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
781
+ }>): CoreMessage[];
782
+
783
+ /**
784
+ Typed tool call that is returned by generateText and streamText.
785
+ It contains the tool call ID, the tool name, and the tool arguments.
786
+ */
787
+ interface ToolCall$1<NAME extends string, ARGS> {
788
+ /**
789
+ ID of the tool call. This ID is used to match the tool call with the tool result.
790
+ */
791
+ toolCallId: string;
792
+ /**
793
+ Name of the tool that is being called.
794
+ */
795
+ toolName: NAME;
796
+ /**
797
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
798
+ */
799
+ args: ARGS;
800
+ }
801
+ type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
802
+ [NAME in keyof TOOLS]: {
803
+ type: 'tool-call';
804
+ toolCallId: string;
805
+ toolName: NAME & string;
806
+ args: z.infer<TOOLS[NAME]['parameters']>;
807
+ };
808
+ }>;
809
+ type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
810
+
801
811
  /**
802
812
  Generate a text and call tools for a given prompt using a language model.
803
813
 
@@ -876,6 +886,14 @@ declare class GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
876
886
  */
877
887
  readonly warnings: CallWarning[] | undefined;
878
888
  /**
889
+ The response messages that were generated during the call. It consists of an assistant message,
890
+ potentially containing tool calls.
891
+ When there are tool results, there is an additional tool message with the tool results that are available.
892
+ If there are tools that do not have execute functions, they are not included in the tool results and
893
+ need to be added separately.
894
+ */
895
+ readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
896
+ /**
879
897
  Optional raw response data.
880
898
  */
881
899
  rawResponse?: {
@@ -1143,16 +1161,6 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1143
1161
  */
1144
1162
  declare const experimental_streamText: typeof streamText;
1145
1163
 
1146
- /**
1147
- Converts an array of messages from useChat into an array of CoreMessages that can be used
1148
- with the AI core functions (e.g. `streamText`).
1149
- */
1150
- declare function convertToCoreMessages(messages: Array<{
1151
- role: 'user' | 'assistant';
1152
- content: string;
1153
- toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
1154
- }>): CoreMessage[];
1155
-
1156
1164
  type AssistantStatus = 'in_progress' | 'awaiting_message';
1157
1165
  type UseAssistantOptions = {
1158
1166
  /**
@@ -1185,6 +1193,9 @@ type UseAssistantOptions = {
1185
1193
  onError?: (error: Error) => void;
1186
1194
  };
1187
1195
 
1196
+ /**
1197
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1198
+ */
1188
1199
  interface FunctionCall$1 {
1189
1200
  /**
1190
1201
  * The arguments to call the function with, as generated by the model in JSON
@@ -1199,6 +1210,8 @@ interface FunctionCall$1 {
1199
1210
  name?: string;
1200
1211
  }
1201
1212
  /**
1213
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1214
+ *
1202
1215
  * The tool calls generated by the model, such as function calls.
1203
1216
  */
1204
1217
  interface ToolCall {
@@ -1210,6 +1223,8 @@ interface ToolCall {
1210
1223
  };
1211
1224
  }
1212
1225
  /**
1226
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
1227
+ *
1213
1228
  * Controls which (if any) function is called by the model.
1214
1229
  * - none means the model will not call a function and instead generates a message.
1215
1230
  * - auto means the model can pick between generating a message or calling a function.
@@ -1223,6 +1238,8 @@ type ToolChoice = 'none' | 'auto' | {
1223
1238
  };
1224
1239
  };
1225
1240
  /**
1241
+ * @deprecated use AI SDK 3.1 CoreTool instead
1242
+ *
1226
1243
  * A list of tools the model may call. Currently, only functions are supported as a tool.
1227
1244
  * Use this to provide a list of functions the model may generate JSON inputs for.
1228
1245
  */
@@ -1230,6 +1247,9 @@ interface Tool {
1230
1247
  type: 'function';
1231
1248
  function: Function;
1232
1249
  }
1250
+ /**
1251
+ * @deprecated use AI SDK 3.1 CoreTool instead
1252
+ */
1233
1253
  interface Function {
1234
1254
  /**
1235
1255
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -1260,17 +1280,20 @@ Once the call is complete, the invocation is a tool result.
1260
1280
  */
1261
1281
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
1262
1282
  /**
1263
- * Shared types between the API and UI packages.
1283
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
1264
1284
  */
1265
1285
  interface Message$1 {
1266
1286
  id: string;
1267
- tool_call_id?: string;
1268
1287
  createdAt?: Date;
1269
1288
  content: string;
1289
+ tool_call_id?: string;
1270
1290
  /**
1271
1291
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
1272
1292
  */
1273
1293
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
1294
+ /**
1295
+ * `function` and `tool` roles are deprecated.
1296
+ */
1274
1297
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1275
1298
  /**
1276
1299
  *
@@ -1279,6 +1302,8 @@ interface Message$1 {
1279
1302
  */
1280
1303
  name?: string;
1281
1304
  /**
1305
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1306
+ *
1282
1307
  * If the assistant role makes a function call, the `function_call` field
1283
1308
  * contains the function call name and arguments. Otherwise, the field should
1284
1309
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -1286,6 +1311,8 @@ interface Message$1 {
1286
1311
  function_call?: string | FunctionCall$1;
1287
1312
  data?: JSONValue;
1288
1313
  /**
1314
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1315
+ *
1289
1316
  * If the assistant role makes a tool call, the `tool_calls` field contains
1290
1317
  * the tool call name and arguments. Otherwise, the field should not be set.
1291
1318
  */
@@ -1312,7 +1339,13 @@ type ChatRequest = {
1312
1339
  tools?: Array<Tool>;
1313
1340
  tool_choice?: ToolChoice;
1314
1341
  };
1342
+ /**
1343
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1344
+ */
1315
1345
  type FunctionCallHandler = (chatMessages: Message$1[], functionCall: FunctionCall$1) => Promise<ChatRequest | void>;
1346
+ /**
1347
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1348
+ */
1316
1349
  type ToolCallHandler = (chatMessages: Message$1[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
1317
1350
  type RequestOptions = {
1318
1351
  headers?: Record<string, string> | Headers;
@@ -1347,18 +1380,32 @@ type UseChatOptions = {
1347
1380
  */
1348
1381
  initialInput?: string;
1349
1382
  /**
1383
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1384
+ *
1350
1385
  * Callback function to be called when a function call is received.
1351
1386
  * If the function returns a `ChatRequest` object, the request will be sent
1352
1387
  * automatically to the API and will be used to update the chat.
1353
1388
  */
1354
1389
  experimental_onFunctionCall?: FunctionCallHandler;
1355
1390
  /**
1391
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1392
+ *
1356
1393
  * Callback function to be called when a tool call is received.
1357
1394
  * If the function returns a `ChatRequest` object, the request will be sent
1358
1395
  * automatically to the API and will be used to update the chat.
1359
1396
  */
1360
1397
  experimental_onToolCall?: ToolCallHandler;
1361
1398
  /**
1399
+ Optional callback function that is invoked when a tool call is received.
1400
+ Intended for automatic client-side tool execution.
1401
+
1402
+ You can optionally return a result for the tool call,
1403
+ either synchronously or asynchronously.
1404
+ */
1405
+ onToolCall?: ({ toolCall, }: {
1406
+ toolCall: ToolCall$1<string, unknown>;
1407
+ }) => void | Promise<unknown> | unknown;
1408
+ /**
1362
1409
  * Callback function to be called when the API response is received.
1363
1410
  */
1364
1411
  onResponse?: (response: Response) => void | Promise<void>;
package/dist/index.js CHANGED
@@ -1408,8 +1408,32 @@ var GenerateTextResult = class {
1408
1408
  this.warnings = options.warnings;
1409
1409
  this.rawResponse = options.rawResponse;
1410
1410
  this.logprobs = options.logprobs;
1411
+ this.responseMessages = toResponseMessages(options);
1411
1412
  }
1412
1413
  };
1414
+ function toResponseMessages({
1415
+ text,
1416
+ toolCalls,
1417
+ toolResults
1418
+ }) {
1419
+ const responseMessages = [];
1420
+ responseMessages.push({
1421
+ role: "assistant",
1422
+ content: [{ type: "text", text }, ...toolCalls]
1423
+ });
1424
+ if (toolResults.length > 0) {
1425
+ responseMessages.push({
1426
+ role: "tool",
1427
+ content: toolResults.map((result) => ({
1428
+ type: "tool-result",
1429
+ toolCallId: result.toolCallId,
1430
+ toolName: result.toolName,
1431
+ result: result.result
1432
+ }))
1433
+ });
1434
+ }
1435
+ return responseMessages;
1436
+ }
1413
1437
  var experimental_generateText = generateText;
1414
1438
 
1415
1439
  // core/generate-text/run-tools-transformation.ts
@@ -3304,6 +3328,7 @@ async function parseComplexResponse({
3304
3328
  reader,
3305
3329
  abortControllerRef,
3306
3330
  update,
3331
+ onToolCall,
3307
3332
  onFinish,
3308
3333
  generateId: generateId2 = generateId,
3309
3334
  getCurrentDate = () => /* @__PURE__ */ new Date()
@@ -3344,6 +3369,14 @@ async function parseComplexResponse({
3344
3369
  prefixMap.text.toolInvocations = [];
3345
3370
  }
3346
3371
  prefixMap.text.toolInvocations.push(value);
3372
+ if (onToolCall) {
3373
+ console.log("onToolCall", value);
3374
+ const result = await onToolCall({ toolCall: value });
3375
+ console.log("onToolCall result", result);
3376
+ if (result != null) {
3377
+ prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { ...value, result };
3378
+ }
3379
+ }
3347
3380
  } else if (type === "tool_result") {
3348
3381
  if (prefixMap.text == null) {
3349
3382
  prefixMap.text = {