ai 3.1.29 → 3.1.31
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 +4 -563
- package/dist/index.d.ts +4 -563
- package/dist/index.js +38 -509
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -497
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -33
- package/prompts/dist/index.d.mts +2 -129
- package/prompts/dist/index.d.ts +2 -129
- package/prompts/dist/index.js.map +1 -1
- package/prompts/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +9 -648
- package/react/dist/index.d.ts +9 -648
- package/react/dist/index.js +4 -1441
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +9 -1429
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/rsc-server.mjs +15 -236
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/solid/dist/index.d.mts +7 -465
- package/solid/dist/index.d.ts +7 -465
- package/solid/dist/index.js +3 -1057
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +7 -1056
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +12 -422
- package/svelte/dist/index.d.ts +12 -422
- package/svelte/dist/index.js +12 -768
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +10 -762
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +7 -459
- package/vue/dist/index.d.ts +7 -459
- package/vue/dist/index.js +3 -1057
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +7 -1046
- package/vue/dist/index.mjs.map +1 -1
package/svelte/dist/index.d.ts
CHANGED
@@ -1,426 +1,7 @@
|
|
1
|
+
import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
|
2
|
+
export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
|
1
3
|
import { Readable, Writable } from 'svelte/store';
|
2
4
|
|
3
|
-
/**
|
4
|
-
Typed tool call that is returned by generateText and streamText.
|
5
|
-
It contains the tool call ID, the tool name, and the tool arguments.
|
6
|
-
*/
|
7
|
-
interface ToolCall$1<NAME extends string, ARGS> {
|
8
|
-
/**
|
9
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
10
|
-
*/
|
11
|
-
toolCallId: string;
|
12
|
-
/**
|
13
|
-
Name of the tool that is being called.
|
14
|
-
*/
|
15
|
-
toolName: NAME;
|
16
|
-
/**
|
17
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
18
|
-
*/
|
19
|
-
args: ARGS;
|
20
|
-
}
|
21
|
-
|
22
|
-
/**
|
23
|
-
Typed tool result that is returned by generateText and streamText.
|
24
|
-
It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
25
|
-
*/
|
26
|
-
interface ToolResult<NAME extends string, ARGS, RESULT> {
|
27
|
-
/**
|
28
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
29
|
-
*/
|
30
|
-
toolCallId: string;
|
31
|
-
/**
|
32
|
-
Name of the tool that was called.
|
33
|
-
*/
|
34
|
-
toolName: NAME;
|
35
|
-
/**
|
36
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
37
|
-
*/
|
38
|
-
args: ARGS;
|
39
|
-
/**
|
40
|
-
Result of the tool call. This is the result of the tool's execution.
|
41
|
-
*/
|
42
|
-
result: RESULT;
|
43
|
-
}
|
44
|
-
|
45
|
-
type AssistantStatus = 'in_progress' | 'awaiting_message';
|
46
|
-
type UseAssistantOptions = {
|
47
|
-
/**
|
48
|
-
* The API endpoint that accepts a `{ threadId: string | null; message: string; }` object and returns an `AssistantResponse` stream.
|
49
|
-
* The threadId refers to an existing thread with messages (or is `null` to create a new thread).
|
50
|
-
* The message is the next message that should be appended to the thread and sent to the assistant.
|
51
|
-
*/
|
52
|
-
api: string;
|
53
|
-
/**
|
54
|
-
* An optional string that represents the ID of an existing thread.
|
55
|
-
* If not provided, a new thread will be created.
|
56
|
-
*/
|
57
|
-
threadId?: string;
|
58
|
-
/**
|
59
|
-
* An optional literal that sets the mode of credentials to be used on the request.
|
60
|
-
* Defaults to "same-origin".
|
61
|
-
*/
|
62
|
-
credentials?: RequestCredentials;
|
63
|
-
/**
|
64
|
-
* An optional object of headers to be passed to the API endpoint.
|
65
|
-
*/
|
66
|
-
headers?: Record<string, string> | Headers;
|
67
|
-
/**
|
68
|
-
* An optional, additional body object to be passed to the API endpoint.
|
69
|
-
*/
|
70
|
-
body?: object;
|
71
|
-
/**
|
72
|
-
* An optional callback that will be called when the assistant encounters an error.
|
73
|
-
*/
|
74
|
-
onError?: (error: Error) => void;
|
75
|
-
};
|
76
|
-
|
77
|
-
/**
|
78
|
-
* @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
|
79
|
-
*/
|
80
|
-
interface FunctionCall {
|
81
|
-
/**
|
82
|
-
* The arguments to call the function with, as generated by the model in JSON
|
83
|
-
* format. Note that the model does not always generate valid JSON, and may
|
84
|
-
* hallucinate parameters not defined by your function schema. Validate the
|
85
|
-
* arguments in your code before calling your function.
|
86
|
-
*/
|
87
|
-
arguments?: string;
|
88
|
-
/**
|
89
|
-
* The name of the function to call.
|
90
|
-
*/
|
91
|
-
name?: string;
|
92
|
-
}
|
93
|
-
/**
|
94
|
-
* @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
|
95
|
-
*
|
96
|
-
* The tool calls generated by the model, such as function calls.
|
97
|
-
*/
|
98
|
-
interface ToolCall {
|
99
|
-
id: string;
|
100
|
-
type: string;
|
101
|
-
function: {
|
102
|
-
name: string;
|
103
|
-
arguments: string;
|
104
|
-
};
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
|
108
|
-
*
|
109
|
-
* Controls which (if any) function is called by the model.
|
110
|
-
* - none means the model will not call a function and instead generates a message.
|
111
|
-
* - auto means the model can pick between generating a message or calling a function.
|
112
|
-
* - Specifying a particular function via {"type: "function", "function": {"name": "my_function"}} forces the model to call that function.
|
113
|
-
* none is the default when no functions are present. auto is the default if functions are present.
|
114
|
-
*/
|
115
|
-
type ToolChoice = 'none' | 'auto' | {
|
116
|
-
type: 'function';
|
117
|
-
function: {
|
118
|
-
name: string;
|
119
|
-
};
|
120
|
-
};
|
121
|
-
/**
|
122
|
-
* @deprecated use AI SDK 3.1 CoreTool instead
|
123
|
-
*
|
124
|
-
* A list of tools the model may call. Currently, only functions are supported as a tool.
|
125
|
-
* Use this to provide a list of functions the model may generate JSON inputs for.
|
126
|
-
*/
|
127
|
-
interface Tool {
|
128
|
-
type: 'function';
|
129
|
-
function: Function;
|
130
|
-
}
|
131
|
-
/**
|
132
|
-
* @deprecated use AI SDK 3.1 CoreTool instead
|
133
|
-
*/
|
134
|
-
interface Function {
|
135
|
-
/**
|
136
|
-
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
137
|
-
* underscores and dashes, with a maximum length of 64.
|
138
|
-
*/
|
139
|
-
name: string;
|
140
|
-
/**
|
141
|
-
* The parameters the functions accepts, described as a JSON Schema object. See the
|
142
|
-
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
143
|
-
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
144
|
-
* documentation about the format.
|
145
|
-
*
|
146
|
-
* To describe a function that accepts no parameters, provide the value
|
147
|
-
* `{"type": "object", "properties": {}}`.
|
148
|
-
*/
|
149
|
-
parameters: Record<string, unknown>;
|
150
|
-
/**
|
151
|
-
* A description of what the function does, used by the model to choose when and
|
152
|
-
* how to call the function.
|
153
|
-
*/
|
154
|
-
description?: string;
|
155
|
-
}
|
156
|
-
type IdGenerator = () => string;
|
157
|
-
/**
|
158
|
-
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
159
|
-
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
160
|
-
Once the call is complete, the invocation is a tool result.
|
161
|
-
*/
|
162
|
-
type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
|
163
|
-
/**
|
164
|
-
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
165
|
-
*/
|
166
|
-
interface Message {
|
167
|
-
id: string;
|
168
|
-
createdAt?: Date;
|
169
|
-
content: string;
|
170
|
-
tool_call_id?: string;
|
171
|
-
/**
|
172
|
-
@deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
|
173
|
-
*/
|
174
|
-
ui?: string | JSX.Element | JSX.Element[] | null | undefined;
|
175
|
-
/**
|
176
|
-
* `function` and `tool` roles are deprecated.
|
177
|
-
*/
|
178
|
-
role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
|
179
|
-
/**
|
180
|
-
*
|
181
|
-
* If the message has a role of `function`, the `name` field is the name of the function.
|
182
|
-
* Otherwise, the name field should not be set.
|
183
|
-
*/
|
184
|
-
name?: string;
|
185
|
-
/**
|
186
|
-
* @deprecated Use AI SDK 3.1 `toolInvocations` instead.
|
187
|
-
*
|
188
|
-
* If the assistant role makes a function call, the `function_call` field
|
189
|
-
* contains the function call name and arguments. Otherwise, the field should
|
190
|
-
* not be set. (Deprecated and replaced by tool_calls.)
|
191
|
-
*/
|
192
|
-
function_call?: string | FunctionCall;
|
193
|
-
data?: JSONValue;
|
194
|
-
/**
|
195
|
-
* @deprecated Use AI SDK 3.1 `toolInvocations` instead.
|
196
|
-
*
|
197
|
-
* If the assistant role makes a tool call, the `tool_calls` field contains
|
198
|
-
* the tool call name and arguments. Otherwise, the field should not be set.
|
199
|
-
*/
|
200
|
-
tool_calls?: string | ToolCall[];
|
201
|
-
/**
|
202
|
-
* Additional message-specific information added on the server via StreamData
|
203
|
-
*/
|
204
|
-
annotations?: JSONValue[] | undefined;
|
205
|
-
/**
|
206
|
-
Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
|
207
|
-
that the assistant made as part of this message.
|
208
|
-
*/
|
209
|
-
toolInvocations?: Array<ToolInvocation>;
|
210
|
-
}
|
211
|
-
type CreateMessage = Omit<Message, 'id'> & {
|
212
|
-
id?: Message['id'];
|
213
|
-
};
|
214
|
-
type ChatRequest = {
|
215
|
-
messages: Message[];
|
216
|
-
options?: RequestOptions;
|
217
|
-
functions?: Array<Function>;
|
218
|
-
function_call?: FunctionCall;
|
219
|
-
data?: Record<string, string>;
|
220
|
-
tools?: Array<Tool>;
|
221
|
-
tool_choice?: ToolChoice;
|
222
|
-
};
|
223
|
-
/**
|
224
|
-
* @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
|
225
|
-
*/
|
226
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
227
|
-
/**
|
228
|
-
* @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
|
229
|
-
*/
|
230
|
-
type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
|
231
|
-
type RequestOptions = {
|
232
|
-
/**
|
233
|
-
An optional object of headers to be passed to the API endpoint.
|
234
|
-
*/
|
235
|
-
headers?: Record<string, string> | Headers;
|
236
|
-
/**
|
237
|
-
An optional object to be passed to the API endpoint.
|
238
|
-
*/
|
239
|
-
body?: object;
|
240
|
-
};
|
241
|
-
type ChatRequestOptions = {
|
242
|
-
/**
|
243
|
-
The options to be passed to the fetch call.
|
244
|
-
*/
|
245
|
-
options?: RequestOptions;
|
246
|
-
/**
|
247
|
-
@deprecated
|
248
|
-
*/
|
249
|
-
functions?: Array<Function>;
|
250
|
-
/**
|
251
|
-
@deprecated
|
252
|
-
*/
|
253
|
-
function_call?: FunctionCall;
|
254
|
-
/**
|
255
|
-
@deprecated
|
256
|
-
*/
|
257
|
-
tools?: Array<Tool>;
|
258
|
-
/**
|
259
|
-
@deprecated
|
260
|
-
*/
|
261
|
-
tool_choice?: ToolChoice;
|
262
|
-
/**
|
263
|
-
Additional data to be sent to the server.
|
264
|
-
*/
|
265
|
-
data?: Record<string, string>;
|
266
|
-
};
|
267
|
-
type UseChatOptions = {
|
268
|
-
/**
|
269
|
-
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
270
|
-
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
271
|
-
*/
|
272
|
-
api?: string;
|
273
|
-
/**
|
274
|
-
* A unique identifier for the chat. If not provided, a random one will be
|
275
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
276
|
-
* have shared states across components.
|
277
|
-
*/
|
278
|
-
id?: string;
|
279
|
-
/**
|
280
|
-
* Initial messages of the chat. Useful to load an existing chat history.
|
281
|
-
*/
|
282
|
-
initialMessages?: Message[];
|
283
|
-
/**
|
284
|
-
* Initial input of the chat.
|
285
|
-
*/
|
286
|
-
initialInput?: string;
|
287
|
-
/**
|
288
|
-
* @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
|
289
|
-
*
|
290
|
-
* Callback function to be called when a function call is received.
|
291
|
-
* If the function returns a `ChatRequest` object, the request will be sent
|
292
|
-
* automatically to the API and will be used to update the chat.
|
293
|
-
*/
|
294
|
-
experimental_onFunctionCall?: FunctionCallHandler;
|
295
|
-
/**
|
296
|
-
* @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
|
297
|
-
*
|
298
|
-
* Callback function to be called when a tool call is received.
|
299
|
-
* If the function returns a `ChatRequest` object, the request will be sent
|
300
|
-
* automatically to the API and will be used to update the chat.
|
301
|
-
*/
|
302
|
-
experimental_onToolCall?: ToolCallHandler;
|
303
|
-
/**
|
304
|
-
Optional callback function that is invoked when a tool call is received.
|
305
|
-
Intended for automatic client-side tool execution.
|
306
|
-
|
307
|
-
You can optionally return a result for the tool call,
|
308
|
-
either synchronously or asynchronously.
|
309
|
-
*/
|
310
|
-
onToolCall?: ({ toolCall, }: {
|
311
|
-
toolCall: ToolCall$1<string, unknown>;
|
312
|
-
}) => void | Promise<unknown> | unknown;
|
313
|
-
/**
|
314
|
-
* Callback function to be called when the API response is received.
|
315
|
-
*/
|
316
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
317
|
-
/**
|
318
|
-
* Callback function to be called when the chat is finished streaming.
|
319
|
-
*/
|
320
|
-
onFinish?: (message: Message) => void;
|
321
|
-
/**
|
322
|
-
* Callback function to be called when an error is encountered.
|
323
|
-
*/
|
324
|
-
onError?: (error: Error) => void;
|
325
|
-
/**
|
326
|
-
* A way to provide a function that is going to be used for ids for messages.
|
327
|
-
* If not provided nanoid is used by default.
|
328
|
-
*/
|
329
|
-
generateId?: IdGenerator;
|
330
|
-
/**
|
331
|
-
* The credentials mode to be used for the fetch request.
|
332
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
333
|
-
* Defaults to 'same-origin'.
|
334
|
-
*/
|
335
|
-
credentials?: RequestCredentials;
|
336
|
-
/**
|
337
|
-
* HTTP headers to be sent with the API request.
|
338
|
-
*/
|
339
|
-
headers?: Record<string, string> | Headers;
|
340
|
-
/**
|
341
|
-
* Extra body object to be sent with the API request.
|
342
|
-
* @example
|
343
|
-
* Send a `sessionId` to the API along with the messages.
|
344
|
-
* ```js
|
345
|
-
* useChat({
|
346
|
-
* body: {
|
347
|
-
* sessionId: '123',
|
348
|
-
* }
|
349
|
-
* })
|
350
|
-
* ```
|
351
|
-
*/
|
352
|
-
body?: object;
|
353
|
-
/**
|
354
|
-
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
355
|
-
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
356
|
-
* handle the extra fields before forwarding the request to the AI service.
|
357
|
-
*/
|
358
|
-
sendExtraMessageFields?: boolean;
|
359
|
-
/** Stream mode (default to "stream-data") */
|
360
|
-
streamMode?: 'stream-data' | 'text';
|
361
|
-
};
|
362
|
-
type UseCompletionOptions = {
|
363
|
-
/**
|
364
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
365
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
366
|
-
*/
|
367
|
-
api?: string;
|
368
|
-
/**
|
369
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
370
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
371
|
-
* have shared states across components.
|
372
|
-
*/
|
373
|
-
id?: string;
|
374
|
-
/**
|
375
|
-
* Initial prompt input of the completion.
|
376
|
-
*/
|
377
|
-
initialInput?: string;
|
378
|
-
/**
|
379
|
-
* Initial completion result. Useful to load an existing history.
|
380
|
-
*/
|
381
|
-
initialCompletion?: string;
|
382
|
-
/**
|
383
|
-
* Callback function to be called when the API response is received.
|
384
|
-
*/
|
385
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
386
|
-
/**
|
387
|
-
* Callback function to be called when the completion is finished streaming.
|
388
|
-
*/
|
389
|
-
onFinish?: (prompt: string, completion: string) => void;
|
390
|
-
/**
|
391
|
-
* Callback function to be called when an error is encountered.
|
392
|
-
*/
|
393
|
-
onError?: (error: Error) => void;
|
394
|
-
/**
|
395
|
-
* The credentials mode to be used for the fetch request.
|
396
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
397
|
-
* Defaults to 'same-origin'.
|
398
|
-
*/
|
399
|
-
credentials?: RequestCredentials;
|
400
|
-
/**
|
401
|
-
* HTTP headers to be sent with the API request.
|
402
|
-
*/
|
403
|
-
headers?: Record<string, string> | Headers;
|
404
|
-
/**
|
405
|
-
* Extra body object to be sent with the API request.
|
406
|
-
* @example
|
407
|
-
* Send a `sessionId` to the API along with the prompt.
|
408
|
-
* ```js
|
409
|
-
* useChat({
|
410
|
-
* body: {
|
411
|
-
* sessionId: '123',
|
412
|
-
* }
|
413
|
-
* })
|
414
|
-
* ```
|
415
|
-
*/
|
416
|
-
body?: object;
|
417
|
-
/** Stream mode (default to "stream-data") */
|
418
|
-
streamMode?: 'stream-data' | 'text';
|
419
|
-
};
|
420
|
-
type JSONValue = null | string | number | boolean | {
|
421
|
-
[x: string]: JSONValue;
|
422
|
-
} | Array<JSONValue>;
|
423
|
-
|
424
5
|
type UseChatHelpers = {
|
425
6
|
/** Current messages in the chat */
|
426
7
|
messages: Readable<Message[]>;
|
@@ -459,6 +40,9 @@ type UseChatHelpers = {
|
|
459
40
|
/** Additional data added on the server via StreamData */
|
460
41
|
data: Readable<JSONValue[] | undefined>;
|
461
42
|
};
|
43
|
+
/**
|
44
|
+
* @deprecated Use `useChat` from `@ai-sdk/svelte` instead.
|
45
|
+
*/
|
462
46
|
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: UseChatOptions): UseChatHelpers;
|
463
47
|
|
464
48
|
type UseCompletionHelpers = {
|
@@ -495,6 +79,9 @@ type UseCompletionHelpers = {
|
|
495
79
|
/** Additional data added on the server via StreamData */
|
496
80
|
data: Readable<JSONValue[] | undefined>;
|
497
81
|
};
|
82
|
+
/**
|
83
|
+
* @deprecated Use `useCompletion` from `@ai-sdk/svelte` instead.
|
84
|
+
*/
|
498
85
|
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
|
499
86
|
|
500
87
|
type UseAssistantHelpers = {
|
@@ -542,6 +129,9 @@ type UseAssistantHelpers = {
|
|
542
129
|
*/
|
543
130
|
error: Readable<undefined | Error>;
|
544
131
|
};
|
132
|
+
/**
|
133
|
+
* @deprecated Use `useAssistant` from `@ai-sdk/svelte` instead.
|
134
|
+
*/
|
545
135
|
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
|
546
136
|
|
547
|
-
export {
|
137
|
+
export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, useAssistant, useChat, useCompletion };
|