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.
@@ -42,6 +42,9 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
42
42
  result: RESULT;
43
43
  }
44
44
 
45
+ /**
46
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
47
+ */
45
48
  interface FunctionCall {
46
49
  /**
47
50
  * The arguments to call the function with, as generated by the model in JSON
@@ -56,6 +59,8 @@ interface FunctionCall {
56
59
  name?: string;
57
60
  }
58
61
  /**
62
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
63
+ *
59
64
  * The tool calls generated by the model, such as function calls.
60
65
  */
61
66
  interface ToolCall {
@@ -67,6 +72,8 @@ interface ToolCall {
67
72
  };
68
73
  }
69
74
  /**
75
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
76
+ *
70
77
  * Controls which (if any) function is called by the model.
71
78
  * - none means the model will not call a function and instead generates a message.
72
79
  * - auto means the model can pick between generating a message or calling a function.
@@ -80,6 +87,8 @@ type ToolChoice = 'none' | 'auto' | {
80
87
  };
81
88
  };
82
89
  /**
90
+ * @deprecated use AI SDK 3.1 CoreTool instead
91
+ *
83
92
  * A list of tools the model may call. Currently, only functions are supported as a tool.
84
93
  * Use this to provide a list of functions the model may generate JSON inputs for.
85
94
  */
@@ -87,6 +96,9 @@ interface Tool {
87
96
  type: 'function';
88
97
  function: Function;
89
98
  }
99
+ /**
100
+ * @deprecated use AI SDK 3.1 CoreTool instead
101
+ */
90
102
  interface Function {
91
103
  /**
92
104
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -117,17 +129,20 @@ Once the call is complete, the invocation is a tool result.
117
129
  */
118
130
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
119
131
  /**
120
- * Shared types between the API and UI packages.
132
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
121
133
  */
122
134
  interface Message {
123
135
  id: string;
124
- tool_call_id?: string;
125
136
  createdAt?: Date;
126
137
  content: string;
138
+ tool_call_id?: string;
127
139
  /**
128
140
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
129
141
  */
130
142
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
143
+ /**
144
+ * `function` and `tool` roles are deprecated.
145
+ */
131
146
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
132
147
  /**
133
148
  *
@@ -136,6 +151,8 @@ interface Message {
136
151
  */
137
152
  name?: string;
138
153
  /**
154
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
155
+ *
139
156
  * If the assistant role makes a function call, the `function_call` field
140
157
  * contains the function call name and arguments. Otherwise, the field should
141
158
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -143,6 +160,8 @@ interface Message {
143
160
  function_call?: string | FunctionCall;
144
161
  data?: JSONValue;
145
162
  /**
163
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
164
+ *
146
165
  * If the assistant role makes a tool call, the `tool_calls` field contains
147
166
  * the tool call name and arguments. Otherwise, the field should not be set.
148
167
  */
@@ -169,7 +188,13 @@ type ChatRequest = {
169
188
  tools?: Array<Tool>;
170
189
  tool_choice?: ToolChoice;
171
190
  };
191
+ /**
192
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
193
+ */
172
194
  type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
195
+ /**
196
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
197
+ */
173
198
  type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
174
199
  type RequestOptions = {
175
200
  headers?: Record<string, string> | Headers;
@@ -204,18 +229,32 @@ type UseChatOptions = {
204
229
  */
205
230
  initialInput?: string;
206
231
  /**
232
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
233
+ *
207
234
  * Callback function to be called when a function call is received.
208
235
  * If the function returns a `ChatRequest` object, the request will be sent
209
236
  * automatically to the API and will be used to update the chat.
210
237
  */
211
238
  experimental_onFunctionCall?: FunctionCallHandler;
212
239
  /**
240
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
241
+ *
213
242
  * Callback function to be called when a tool call is received.
214
243
  * If the function returns a `ChatRequest` object, the request will be sent
215
244
  * automatically to the API and will be used to update the chat.
216
245
  */
217
246
  experimental_onToolCall?: ToolCallHandler;
218
247
  /**
248
+ Optional callback function that is invoked when a tool call is received.
249
+ Intended for automatic client-side tool execution.
250
+
251
+ You can optionally return a result for the tool call,
252
+ either synchronously or asynchronously.
253
+ */
254
+ onToolCall?: ({ toolCall, }: {
255
+ toolCall: ToolCall$1<string, unknown>;
256
+ }) => void | Promise<unknown> | unknown;
257
+ /**
219
258
  * Callback function to be called when the API response is received.
220
259
  */
221
260
  onResponse?: (response: Response) => void | Promise<void>;
@@ -42,6 +42,9 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
42
42
  result: RESULT;
43
43
  }
44
44
 
45
+ /**
46
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
47
+ */
45
48
  interface FunctionCall {
46
49
  /**
47
50
  * The arguments to call the function with, as generated by the model in JSON
@@ -56,6 +59,8 @@ interface FunctionCall {
56
59
  name?: string;
57
60
  }
58
61
  /**
62
+ * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
63
+ *
59
64
  * The tool calls generated by the model, such as function calls.
60
65
  */
61
66
  interface ToolCall {
@@ -67,6 +72,8 @@ interface ToolCall {
67
72
  };
68
73
  }
69
74
  /**
75
+ * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
76
+ *
70
77
  * Controls which (if any) function is called by the model.
71
78
  * - none means the model will not call a function and instead generates a message.
72
79
  * - auto means the model can pick between generating a message or calling a function.
@@ -80,6 +87,8 @@ type ToolChoice = 'none' | 'auto' | {
80
87
  };
81
88
  };
82
89
  /**
90
+ * @deprecated use AI SDK 3.1 CoreTool instead
91
+ *
83
92
  * A list of tools the model may call. Currently, only functions are supported as a tool.
84
93
  * Use this to provide a list of functions the model may generate JSON inputs for.
85
94
  */
@@ -87,6 +96,9 @@ interface Tool {
87
96
  type: 'function';
88
97
  function: Function;
89
98
  }
99
+ /**
100
+ * @deprecated use AI SDK 3.1 CoreTool instead
101
+ */
90
102
  interface Function {
91
103
  /**
92
104
  * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
@@ -117,17 +129,20 @@ Once the call is complete, the invocation is a tool result.
117
129
  */
118
130
  type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
119
131
  /**
120
- * Shared types between the API and UI packages.
132
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
121
133
  */
122
134
  interface Message {
123
135
  id: string;
124
- tool_call_id?: string;
125
136
  createdAt?: Date;
126
137
  content: string;
138
+ tool_call_id?: string;
127
139
  /**
128
140
  @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
129
141
  */
130
142
  ui?: string | JSX.Element | JSX.Element[] | null | undefined;
143
+ /**
144
+ * `function` and `tool` roles are deprecated.
145
+ */
131
146
  role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
132
147
  /**
133
148
  *
@@ -136,6 +151,8 @@ interface Message {
136
151
  */
137
152
  name?: string;
138
153
  /**
154
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
155
+ *
139
156
  * If the assistant role makes a function call, the `function_call` field
140
157
  * contains the function call name and arguments. Otherwise, the field should
141
158
  * not be set. (Deprecated and replaced by tool_calls.)
@@ -143,6 +160,8 @@ interface Message {
143
160
  function_call?: string | FunctionCall;
144
161
  data?: JSONValue;
145
162
  /**
163
+ * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
164
+ *
146
165
  * If the assistant role makes a tool call, the `tool_calls` field contains
147
166
  * the tool call name and arguments. Otherwise, the field should not be set.
148
167
  */
@@ -169,7 +188,13 @@ type ChatRequest = {
169
188
  tools?: Array<Tool>;
170
189
  tool_choice?: ToolChoice;
171
190
  };
191
+ /**
192
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
193
+ */
172
194
  type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
195
+ /**
196
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
197
+ */
173
198
  type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
174
199
  type RequestOptions = {
175
200
  headers?: Record<string, string> | Headers;
@@ -204,18 +229,32 @@ type UseChatOptions = {
204
229
  */
205
230
  initialInput?: string;
206
231
  /**
232
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
233
+ *
207
234
  * Callback function to be called when a function call is received.
208
235
  * If the function returns a `ChatRequest` object, the request will be sent
209
236
  * automatically to the API and will be used to update the chat.
210
237
  */
211
238
  experimental_onFunctionCall?: FunctionCallHandler;
212
239
  /**
240
+ * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
241
+ *
213
242
  * Callback function to be called when a tool call is received.
214
243
  * If the function returns a `ChatRequest` object, the request will be sent
215
244
  * automatically to the API and will be used to update the chat.
216
245
  */
217
246
  experimental_onToolCall?: ToolCallHandler;
218
247
  /**
248
+ Optional callback function that is invoked when a tool call is received.
249
+ Intended for automatic client-side tool execution.
250
+
251
+ You can optionally return a result for the tool call,
252
+ either synchronously or asynchronously.
253
+ */
254
+ onToolCall?: ({ toolCall, }: {
255
+ toolCall: ToolCall$1<string, unknown>;
256
+ }) => void | Promise<unknown> | unknown;
257
+ /**
219
258
  * Callback function to be called when the API response is received.
220
259
  */
221
260
  onResponse?: (response: Response) => void | Promise<void>;
package/vue/dist/index.js CHANGED
@@ -307,6 +307,7 @@ async function parseComplexResponse({
307
307
  reader,
308
308
  abortControllerRef,
309
309
  update,
310
+ onToolCall,
310
311
  onFinish,
311
312
  generateId: generateId2 = generateId,
312
313
  getCurrentDate = () => /* @__PURE__ */ new Date()
@@ -347,6 +348,14 @@ async function parseComplexResponse({
347
348
  prefixMap.text.toolInvocations = [];
348
349
  }
349
350
  prefixMap.text.toolInvocations.push(value);
351
+ if (onToolCall) {
352
+ console.log("onToolCall", value);
353
+ const result = await onToolCall({ toolCall: value });
354
+ console.log("onToolCall result", result);
355
+ if (result != null) {
356
+ prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { ...value, result };
357
+ }
358
+ }
350
359
  } else if (type === "tool_result") {
351
360
  if (prefixMap.text == null) {
352
361
  prefixMap.text = {
@@ -471,6 +480,7 @@ async function callChatApi({
471
480
  onResponse,
472
481
  onUpdate,
473
482
  onFinish,
483
+ onToolCall,
474
484
  generateId: generateId2
475
485
  }) {
476
486
  var _a;
@@ -540,6 +550,7 @@ async function callChatApi({
540
550
  reader,
541
551
  abortControllerRef: abortController != null ? { current: abortController() } : void 0,
542
552
  update: onUpdate,
553
+ onToolCall,
543
554
  onFinish(prefixMap) {
544
555
  if (onFinish && prefixMap.text != null) {
545
556
  onFinish(prefixMap.text);