ai 3.1.30 → 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.
@@ -1,471 +1,13 @@
1
- import { Resource, Accessor, Setter } from 'solid-js';
1
+ import { useChat as useChat$1, useCompletion as useCompletion$1 } from '@ai-sdk/solid';
2
+ export { CreateMessage, Message, UseChatHelpers, UseChatOptions } from '@ai-sdk/solid';
2
3
 
3
4
  /**
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.
5
+ * @deprecated Use `useChat` from `@ai-sdk/solid` instead.
6
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
- /**
46
- * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
47
- */
48
- interface FunctionCall {
49
- /**
50
- * The arguments to call the function with, as generated by the model in JSON
51
- * format. Note that the model does not always generate valid JSON, and may
52
- * hallucinate parameters not defined by your function schema. Validate the
53
- * arguments in your code before calling your function.
54
- */
55
- arguments?: string;
56
- /**
57
- * The name of the function to call.
58
- */
59
- name?: string;
60
- }
61
- /**
62
- * @deprecated use AI SDK 3.1 CoreTool / ToolResult instead
63
- *
64
- * The tool calls generated by the model, such as function calls.
65
- */
66
- interface ToolCall {
67
- id: string;
68
- type: string;
69
- function: {
70
- name: string;
71
- arguments: string;
72
- };
73
- }
74
- /**
75
- * @deprecated use AI SDK 3.1 CoreTool / ToolChoice instead
76
- *
77
- * Controls which (if any) function is called by the model.
78
- * - none means the model will not call a function and instead generates a message.
79
- * - auto means the model can pick between generating a message or calling a function.
80
- * - Specifying a particular function via {"type: "function", "function": {"name": "my_function"}} forces the model to call that function.
81
- * none is the default when no functions are present. auto is the default if functions are present.
82
- */
83
- type ToolChoice = 'none' | 'auto' | {
84
- type: 'function';
85
- function: {
86
- name: string;
87
- };
88
- };
89
- /**
90
- * @deprecated use AI SDK 3.1 CoreTool instead
91
- *
92
- * A list of tools the model may call. Currently, only functions are supported as a tool.
93
- * Use this to provide a list of functions the model may generate JSON inputs for.
94
- */
95
- interface Tool {
96
- type: 'function';
97
- function: Function;
98
- }
99
- /**
100
- * @deprecated use AI SDK 3.1 CoreTool instead
101
- */
102
- interface Function {
103
- /**
104
- * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
105
- * underscores and dashes, with a maximum length of 64.
106
- */
107
- name: string;
108
- /**
109
- * The parameters the functions accepts, described as a JSON Schema object. See the
110
- * [guide](/docs/guides/gpt/function-calling) for examples, and the
111
- * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
112
- * documentation about the format.
113
- *
114
- * To describe a function that accepts no parameters, provide the value
115
- * `{"type": "object", "properties": {}}`.
116
- */
117
- parameters: Record<string, unknown>;
118
- /**
119
- * A description of what the function does, used by the model to choose when and
120
- * how to call the function.
121
- */
122
- description?: string;
123
- }
124
- type IdGenerator = () => string;
7
+ declare const useChat: typeof useChat$1;
125
8
  /**
126
- Tool invocations are either tool calls or tool results. For each assistant tool call,
127
- there is one tool invocation. While the call is in progress, the invocation is a tool call.
128
- Once the call is complete, the invocation is a tool result.
9
+ * @deprecated Use `useCompletion` from `@ai-sdk/solid` instead.
129
10
  */
130
- type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
131
- /**
132
- * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
133
- */
134
- interface Message {
135
- id: string;
136
- createdAt?: Date;
137
- content: string;
138
- tool_call_id?: string;
139
- /**
140
- @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
141
- */
142
- ui?: string | JSX.Element | JSX.Element[] | null | undefined;
143
- /**
144
- * `function` and `tool` roles are deprecated.
145
- */
146
- role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
147
- /**
148
- *
149
- * If the message has a role of `function`, the `name` field is the name of the function.
150
- * Otherwise, the name field should not be set.
151
- */
152
- name?: string;
153
- /**
154
- * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
155
- *
156
- * If the assistant role makes a function call, the `function_call` field
157
- * contains the function call name and arguments. Otherwise, the field should
158
- * not be set. (Deprecated and replaced by tool_calls.)
159
- */
160
- function_call?: string | FunctionCall;
161
- data?: JSONValue;
162
- /**
163
- * @deprecated Use AI SDK 3.1 `toolInvocations` instead.
164
- *
165
- * If the assistant role makes a tool call, the `tool_calls` field contains
166
- * the tool call name and arguments. Otherwise, the field should not be set.
167
- */
168
- tool_calls?: string | ToolCall[];
169
- /**
170
- * Additional message-specific information added on the server via StreamData
171
- */
172
- annotations?: JSONValue[] | undefined;
173
- /**
174
- Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
175
- that the assistant made as part of this message.
176
- */
177
- toolInvocations?: Array<ToolInvocation>;
178
- }
179
- type CreateMessage = Omit<Message, 'id'> & {
180
- id?: Message['id'];
181
- };
182
- type ChatRequest = {
183
- messages: Message[];
184
- options?: RequestOptions;
185
- functions?: Array<Function>;
186
- function_call?: FunctionCall;
187
- data?: Record<string, string>;
188
- tools?: Array<Tool>;
189
- tool_choice?: ToolChoice;
190
- };
191
- /**
192
- * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
193
- */
194
- type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
195
- /**
196
- * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
197
- */
198
- type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
199
- type RequestOptions = {
200
- /**
201
- An optional object of headers to be passed to the API endpoint.
202
- */
203
- headers?: Record<string, string> | Headers;
204
- /**
205
- An optional object to be passed to the API endpoint.
206
- */
207
- body?: object;
208
- };
209
- type ChatRequestOptions = {
210
- /**
211
- The options to be passed to the fetch call.
212
- */
213
- options?: RequestOptions;
214
- /**
215
- @deprecated
216
- */
217
- functions?: Array<Function>;
218
- /**
219
- @deprecated
220
- */
221
- function_call?: FunctionCall;
222
- /**
223
- @deprecated
224
- */
225
- tools?: Array<Tool>;
226
- /**
227
- @deprecated
228
- */
229
- tool_choice?: ToolChoice;
230
- /**
231
- Additional data to be sent to the server.
232
- */
233
- data?: Record<string, string>;
234
- };
235
- type UseChatOptions = {
236
- /**
237
- * The API endpoint that accepts a `{ messages: Message[] }` object and returns
238
- * a stream of tokens of the AI chat response. Defaults to `/api/chat`.
239
- */
240
- api?: string;
241
- /**
242
- * A unique identifier for the chat. If not provided, a random one will be
243
- * generated. When provided, the `useChat` hook with the same `id` will
244
- * have shared states across components.
245
- */
246
- id?: string;
247
- /**
248
- * Initial messages of the chat. Useful to load an existing chat history.
249
- */
250
- initialMessages?: Message[];
251
- /**
252
- * Initial input of the chat.
253
- */
254
- initialInput?: string;
255
- /**
256
- * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
257
- *
258
- * Callback function to be called when a function call is received.
259
- * If the function returns a `ChatRequest` object, the request will be sent
260
- * automatically to the API and will be used to update the chat.
261
- */
262
- experimental_onFunctionCall?: FunctionCallHandler;
263
- /**
264
- * @deprecated Use AI SDK 3.1 `streamText` and `onToolCall` instead.
265
- *
266
- * Callback function to be called when a tool call is received.
267
- * If the function returns a `ChatRequest` object, the request will be sent
268
- * automatically to the API and will be used to update the chat.
269
- */
270
- experimental_onToolCall?: ToolCallHandler;
271
- /**
272
- Optional callback function that is invoked when a tool call is received.
273
- Intended for automatic client-side tool execution.
274
-
275
- You can optionally return a result for the tool call,
276
- either synchronously or asynchronously.
277
- */
278
- onToolCall?: ({ toolCall, }: {
279
- toolCall: ToolCall$1<string, unknown>;
280
- }) => void | Promise<unknown> | unknown;
281
- /**
282
- * Callback function to be called when the API response is received.
283
- */
284
- onResponse?: (response: Response) => void | Promise<void>;
285
- /**
286
- * Callback function to be called when the chat is finished streaming.
287
- */
288
- onFinish?: (message: Message) => void;
289
- /**
290
- * Callback function to be called when an error is encountered.
291
- */
292
- onError?: (error: Error) => void;
293
- /**
294
- * A way to provide a function that is going to be used for ids for messages.
295
- * If not provided nanoid is used by default.
296
- */
297
- generateId?: IdGenerator;
298
- /**
299
- * The credentials mode to be used for the fetch request.
300
- * Possible values are: 'omit', 'same-origin', 'include'.
301
- * Defaults to 'same-origin'.
302
- */
303
- credentials?: RequestCredentials;
304
- /**
305
- * HTTP headers to be sent with the API request.
306
- */
307
- headers?: Record<string, string> | Headers;
308
- /**
309
- * Extra body object to be sent with the API request.
310
- * @example
311
- * Send a `sessionId` to the API along with the messages.
312
- * ```js
313
- * useChat({
314
- * body: {
315
- * sessionId: '123',
316
- * }
317
- * })
318
- * ```
319
- */
320
- body?: object;
321
- /**
322
- * Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
323
- * Defaults to `false`. When set to `true`, the API endpoint might need to
324
- * handle the extra fields before forwarding the request to the AI service.
325
- */
326
- sendExtraMessageFields?: boolean;
327
- /** Stream mode (default to "stream-data") */
328
- streamMode?: 'stream-data' | 'text';
329
- };
330
- type UseCompletionOptions = {
331
- /**
332
- * The API endpoint that accepts a `{ prompt: string }` object and returns
333
- * a stream of tokens of the AI completion response. Defaults to `/api/completion`.
334
- */
335
- api?: string;
336
- /**
337
- * An unique identifier for the chat. If not provided, a random one will be
338
- * generated. When provided, the `useChat` hook with the same `id` will
339
- * have shared states across components.
340
- */
341
- id?: string;
342
- /**
343
- * Initial prompt input of the completion.
344
- */
345
- initialInput?: string;
346
- /**
347
- * Initial completion result. Useful to load an existing history.
348
- */
349
- initialCompletion?: string;
350
- /**
351
- * Callback function to be called when the API response is received.
352
- */
353
- onResponse?: (response: Response) => void | Promise<void>;
354
- /**
355
- * Callback function to be called when the completion is finished streaming.
356
- */
357
- onFinish?: (prompt: string, completion: string) => void;
358
- /**
359
- * Callback function to be called when an error is encountered.
360
- */
361
- onError?: (error: Error) => void;
362
- /**
363
- * The credentials mode to be used for the fetch request.
364
- * Possible values are: 'omit', 'same-origin', 'include'.
365
- * Defaults to 'same-origin'.
366
- */
367
- credentials?: RequestCredentials;
368
- /**
369
- * HTTP headers to be sent with the API request.
370
- */
371
- headers?: Record<string, string> | Headers;
372
- /**
373
- * Extra body object to be sent with the API request.
374
- * @example
375
- * Send a `sessionId` to the API along with the prompt.
376
- * ```js
377
- * useChat({
378
- * body: {
379
- * sessionId: '123',
380
- * }
381
- * })
382
- * ```
383
- */
384
- body?: object;
385
- /** Stream mode (default to "stream-data") */
386
- streamMode?: 'stream-data' | 'text';
387
- };
388
- type JSONValue = null | string | number | boolean | {
389
- [x: string]: JSONValue;
390
- } | Array<JSONValue>;
391
-
392
- type UseChatHelpers = {
393
- /** Current messages in the chat */
394
- messages: Resource<Message[]>;
395
- /** The error object of the API request */
396
- error: Accessor<undefined | Error>;
397
- /**
398
- * Append a user message to the chat list. This triggers the API call to fetch
399
- * the assistant's response.
400
- * @param message The message to append
401
- * @param options Additional options to pass to the API call
402
- */
403
- append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
404
- /**
405
- * Reload the last AI chat response for the given chat history. If the last
406
- * message isn't from the assistant, it will request the API to generate a
407
- * new response.
408
- */
409
- reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
410
- /**
411
- * Abort the current request immediately, keep the generated tokens if any.
412
- */
413
- stop: () => void;
414
- /**
415
- * Update the `messages` state locally. This is useful when you want to
416
- * edit the messages on the client, and then trigger the `reload` method
417
- * manually to regenerate the AI response.
418
- */
419
- setMessages: (messages: Message[]) => void;
420
- /** The current value of the input */
421
- input: Accessor<string>;
422
- /** Signal setter to update the input value */
423
- setInput: Setter<string>;
424
- /** Form submission handler to automatically reset input and append a user message */
425
- handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
426
- /** Whether the API request is in progress */
427
- isLoading: Accessor<boolean>;
428
- /** Additional data added on the server via StreamData */
429
- data: Accessor<JSONValue[] | undefined>;
430
- };
431
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, onResponse, onFinish, onError, credentials, headers, body, streamMode, generateId, }?: UseChatOptions): UseChatHelpers;
432
-
433
- type UseCompletionHelpers = {
434
- /** The current completion result */
435
- completion: Resource<string>;
436
- /** The error object of the API request */
437
- error: Accessor<undefined | Error>;
438
- /**
439
- * Send a new prompt to the API endpoint and update the completion state.
440
- */
441
- complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
442
- /**
443
- * Abort the current API request but keep the generated tokens.
444
- */
445
- stop: () => void;
446
- /**
447
- * Update the `completion` state locally.
448
- */
449
- setCompletion: (completion: string) => void;
450
- /** The current value of the input */
451
- input: Accessor<string>;
452
- /** Signal Setter to update the input value */
453
- setInput: Setter<string>;
454
- /**
455
- * Form submission handler to automatically reset input and append a user message
456
- * @example
457
- * ```jsx
458
- * <form onSubmit={handleSubmit}>
459
- * <input value={input()} />
460
- * </form>
461
- * ```
462
- */
463
- handleSubmit: (e: any) => void;
464
- /** Whether the API request is in progress */
465
- isLoading: Accessor<boolean>;
466
- /** Additional data added on the server via StreamData */
467
- data: Accessor<JSONValue[] | undefined>;
468
- };
469
- declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
11
+ declare const useCompletion: typeof useCompletion$1;
470
12
 
471
- export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, UseCompletionOptions, useChat, useCompletion };
13
+ export { useChat, useCompletion };