ai 3.1.16 → 3.1.17

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
@@ -1185,6 +1185,9 @@ type UseAssistantOptions = {
1185
1185
  onError?: (error: Error) => void;
1186
1186
  };
1187
1187
 
1188
+ /**
1189
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1190
+ */
1188
1191
  interface FunctionCall$1 {
1189
1192
  /**
1190
1193
  * The arguments to call the function with, as generated by the model in JSON
@@ -1199,6 +1202,8 @@ interface FunctionCall$1 {
1199
1202
  name?: string;
1200
1203
  }
1201
1204
  /**
1205
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1206
+ *
1202
1207
  * The tool calls generated by the model, such as function calls.
1203
1208
  */
1204
1209
  interface ToolCall {
@@ -1210,6 +1215,8 @@ interface ToolCall {
1210
1215
  };
1211
1216
  }
1212
1217
  /**
1218
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
1219
+ *
1213
1220
  * Controls which (if any) function is called by the model.
1214
1221
  * - none means the model will not call a function and instead generates a message.
1215
1222
  * - auto means the model can pick between generating a message or calling a function.
@@ -1223,6 +1230,8 @@ type ToolChoice = 'none' | 'auto' | {
1223
1230
  };
1224
1231
  };
1225
1232
  /**
1233
+ * @deprecated use AI SDK 3.1 CoreTool instead
1234
+ *
1226
1235
  * A list of tools the model may call. Currently, only functions are supported as a tool.
1227
1236
  * Use this to provide a list of functions the model may generate JSON inputs for.
1228
1237
  */
@@ -1230,6 +1239,9 @@ interface Tool {
1230
1239
  type: 'function';
1231
1240
  function: Function;
1232
1241
  }
1242
+ /**
1243
+ * @deprecated use AI SDK 3.1 CoreTool instead
1244
+ */
1233
1245
  interface Function {
1234
1246
  /**
1235
1247
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -1260,17 +1272,20 @@ Once the call is complete, the invocation is a tool result.
1260
1272
  */
1261
1273
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
1262
1274
  /**
1263
- * Shared types between the API and UI packages.
1275
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
1264
1276
  */
1265
1277
  interface Message$1 {
1266
1278
  id: string;
1267
- tool_call_id?: string;
1268
1279
  createdAt?: Date;
1269
1280
  content: string;
1281
+ tool_call_id?: string;
1270
1282
  /**
1271
1283
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
1272
1284
  */
1273
1285
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
1286
+ /**
1287
+ * `function` and `tool` roles are deprecated.
1288
+ */
1274
1289
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1275
1290
  /**
1276
1291
  *
@@ -1279,6 +1294,8 @@ interface Message$1 {
1279
1294
  */
1280
1295
  name?: string;
1281
1296
  /**
1297
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1298
+ *
1282
1299
  * If the assistant role makes a function call, the `function_call` field
1283
1300
  * contains the function call name and arguments. Otherwise, the field should
1284
1301
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -1286,6 +1303,8 @@ interface Message$1 {
1286
1303
  function_call?: string | FunctionCall$1;
1287
1304
  data?: JSONValue;
1288
1305
  /**
1306
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1307
+ *
1289
1308
  * If the assistant role makes a tool call, the `tool_calls` field contains
1290
1309
  * the tool call name and arguments. Otherwise, the field should not be set.
1291
1310
  */
@@ -1312,7 +1331,13 @@ type ChatRequest = {
1312
1331
  tools?: Array<Tool>;
1313
1332
  tool_choice?: ToolChoice;
1314
1333
  };
1334
+ /**
1335
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1336
+ */
1315
1337
  type FunctionCallHandler = (chatMessages: Message$1[], functionCall: FunctionCall$1) => Promise<ChatRequest | void>;
1338
+ /**
1339
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1340
+ */
1316
1341
  type ToolCallHandler = (chatMessages: Message$1[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
1317
1342
  type RequestOptions = {
1318
1343
  headers?: Record<string, string> | Headers;
@@ -1347,18 +1372,32 @@ type UseChatOptions = {
1347
1372
  */
1348
1373
  initialInput?: string;
1349
1374
  /**
1375
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1376
+ *
1350
1377
  * Callback function to be called when a function call is received.
1351
1378
  * If the function returns a `ChatRequest` object, the request will be sent
1352
1379
  * automatically to the API and will be used to update the chat.
1353
1380
  */
1354
1381
  experimental_onFunctionCall?: FunctionCallHandler;
1355
1382
  /**
1383
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1384
+ *
1356
1385
  * Callback function to be called when a tool call is received.
1357
1386
  * If the function returns a `ChatRequest` object, the request will be sent
1358
1387
  * automatically to the API and will be used to update the chat.
1359
1388
  */
1360
1389
  experimental_onToolCall?: ToolCallHandler;
1361
1390
  /**
1391
+ Optional callback function that is invoked when a tool call is received.
1392
+ Intended for automatic client-side tool execution.
1393
+
1394
+ You can optionally return a result for the tool call,
1395
+ either synchronously or asynchronously.
1396
+ */
1397
+ onToolCall?: ({ toolCall, }: {
1398
+ toolCall: ToolCall$1<string, unknown>;
1399
+ }) => void | Promise<unknown> | unknown;
1400
+ /**
1362
1401
  * Callback function to be called when the API response is received.
1363
1402
  */
1364
1403
  onResponse?: (response: Response) => void | Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1185,6 +1185,9 @@ type UseAssistantOptions = {
1185
1185
  onError?: (error: Error) => void;
1186
1186
  };
1187
1187
 
1188
+ /**
1189
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1190
+ */
1188
1191
  interface FunctionCall$1 {
1189
1192
  /**
1190
1193
  * The arguments to call the function with, as generated by the model in JSON
@@ -1199,6 +1202,8 @@ interface FunctionCall$1 {
1199
1202
  name?: string;
1200
1203
  }
1201
1204
  /**
1205
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
1206
+ *
1202
1207
  * The tool calls generated by the model, such as function calls.
1203
1208
  */
1204
1209
  interface ToolCall {
@@ -1210,6 +1215,8 @@ interface ToolCall {
1210
1215
  };
1211
1216
  }
1212
1217
  /**
1218
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
1219
+ *
1213
1220
  * Controls which (if any) function is called by the model.
1214
1221
  * - none means the model will not call a function and instead generates a message.
1215
1222
  * - auto means the model can pick between generating a message or calling a function.
@@ -1223,6 +1230,8 @@ type ToolChoice = 'none' | 'auto' | {
1223
1230
  };
1224
1231
  };
1225
1232
  /**
1233
+ * @deprecated use AI SDK 3.1 CoreTool instead
1234
+ *
1226
1235
  * A list of tools the model may call. Currently, only functions are supported as a tool.
1227
1236
  * Use this to provide a list of functions the model may generate JSON inputs for.
1228
1237
  */
@@ -1230,6 +1239,9 @@ interface Tool {
1230
1239
  type: 'function';
1231
1240
  function: Function;
1232
1241
  }
1242
+ /**
1243
+ * @deprecated use AI SDK 3.1 CoreTool instead
1244
+ */
1233
1245
  interface Function {
1234
1246
  /**
1235
1247
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -1260,17 +1272,20 @@ Once the call is complete, the invocation is a tool result.
1260
1272
  */
1261
1273
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
1262
1274
  /**
1263
- * Shared types between the API and UI packages.
1275
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
1264
1276
  */
1265
1277
  interface Message$1 {
1266
1278
  id: string;
1267
- tool_call_id?: string;
1268
1279
  createdAt?: Date;
1269
1280
  content: string;
1281
+ tool_call_id?: string;
1270
1282
  /**
1271
1283
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
1272
1284
  */
1273
1285
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
1286
+ /**
1287
+ * `function` and `tool` roles are deprecated.
1288
+ */
1274
1289
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1275
1290
  /**
1276
1291
  *
@@ -1279,6 +1294,8 @@ interface Message$1 {
1279
1294
  */
1280
1295
  name?: string;
1281
1296
  /**
1297
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1298
+ *
1282
1299
  * If the assistant role makes a function call, the `function_call` field
1283
1300
  * contains the function call name and arguments. Otherwise, the field should
1284
1301
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -1286,6 +1303,8 @@ interface Message$1 {
1286
1303
  function_call?: string | FunctionCall$1;
1287
1304
  data?: JSONValue;
1288
1305
  /**
1306
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
1307
+ *
1289
1308
  * If the assistant role makes a tool call, the `tool_calls` field contains
1290
1309
  * the tool call name and arguments. Otherwise, the field should not be set.
1291
1310
  */
@@ -1312,7 +1331,13 @@ type ChatRequest = {
1312
1331
  tools?: Array<Tool>;
1313
1332
  tool_choice?: ToolChoice;
1314
1333
  };
1334
+ /**
1335
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1336
+ */
1315
1337
  type FunctionCallHandler = (chatMessages: Message$1[], functionCall: FunctionCall$1) => Promise<ChatRequest | void>;
1338
+ /**
1339
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1340
+ */
1316
1341
  type ToolCallHandler = (chatMessages: Message$1[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
1317
1342
  type RequestOptions = {
1318
1343
  headers?: Record<string, string> | Headers;
@@ -1347,18 +1372,32 @@ type UseChatOptions = {
1347
1372
  */
1348
1373
  initialInput?: string;
1349
1374
  /**
1375
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1376
+ *
1350
1377
  * Callback function to be called when a function call is received.
1351
1378
  * If the function returns a `ChatRequest` object, the request will be sent
1352
1379
  * automatically to the API and will be used to update the chat.
1353
1380
  */
1354
1381
  experimental_onFunctionCall?: FunctionCallHandler;
1355
1382
  /**
1383
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
1384
+ *
1356
1385
  * Callback function to be called when a tool call is received.
1357
1386
  * If the function returns a `ChatRequest` object, the request will be sent
1358
1387
  * automatically to the API and will be used to update the chat.
1359
1388
  */
1360
1389
  experimental_onToolCall?: ToolCallHandler;
1361
1390
  /**
1391
+ Optional callback function that is invoked when a tool call is received.
1392
+ Intended for automatic client-side tool execution.
1393
+
1394
+ You can optionally return a result for the tool call,
1395
+ either synchronously or asynchronously.
1396
+ */
1397
+ onToolCall?: ({ toolCall, }: {
1398
+ toolCall: ToolCall$1<string, unknown>;
1399
+ }) => void | Promise<unknown> | unknown;
1400
+ /**
1362
1401
  * Callback function to be called when the API response is received.
1363
1402
  */
1364
1403
  onResponse?: (response: Response) => void | Promise<void>;
package/dist/index.js CHANGED
@@ -3304,6 +3304,7 @@ async function parseComplexResponse({
3304
3304
  reader,
3305
3305
  abortControllerRef,
3306
3306
  update,
3307
+ onToolCall,
3307
3308
  onFinish,
3308
3309
  generateId: generateId2 = generateId,
3309
3310
  getCurrentDate = () => /* @__PURE__ */ new Date()
@@ -3344,6 +3345,14 @@ async function parseComplexResponse({
3344
3345
  prefixMap.text.toolInvocations = [];
3345
3346
  }
3346
3347
  prefixMap.text.toolInvocations.push(value);
3348
+ if (onToolCall) {
3349
+ console.log("onToolCall", value);
3350
+ const result = await onToolCall({ toolCall: value });
3351
+ console.log("onToolCall result", result);
3352
+ if (result != null) {
3353
+ prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { ...value, result };
3354
+ }
3355
+ }
3347
3356
  } else if (type === "tool_result") {
3348
3357
  if (prefixMap.text == null) {
3349
3358
  prefixMap.text = {