ai 0.0.0-85f9a635-20240518005312 → 0.0.0-8777c42a-20250115032312
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/CHANGELOG.md +2863 -0
- package/README.md +99 -22
- package/dist/index.d.mts +1925 -1592
- package/dist/index.d.ts +1925 -1592
- package/dist/index.js +5500 -2961
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5497 -2916
- package/dist/index.mjs.map +1 -1
- package/package.json +39 -100
- package/react/dist/index.d.mts +8 -563
- package/react/dist/index.d.ts +8 -580
- package/react/dist/index.js +7 -1395
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +12 -1383
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +340 -197
- package/rsc/dist/rsc-server.d.mts +339 -197
- package/rsc/dist/rsc-server.mjs +1295 -1347
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +30 -23
- package/rsc/dist/rsc-shared.mjs +69 -105
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/test/dist/index.d.mts +67 -0
- package/test/dist/index.d.ts +67 -0
- package/test/dist/index.js +131 -0
- package/test/dist/index.js.map +1 -0
- package/test/dist/index.mjs +101 -0
- package/test/dist/index.mjs.map +1 -0
- package/prompts/dist/index.d.mts +0 -324
- package/prompts/dist/index.d.ts +0 -324
- package/prompts/dist/index.js +0 -178
- package/prompts/dist/index.js.map +0 -1
- package/prompts/dist/index.mjs +0 -146
- package/prompts/dist/index.mjs.map +0 -1
- package/react/dist/index.server.d.mts +0 -17
- package/react/dist/index.server.d.ts +0 -17
- package/react/dist/index.server.js +0 -50
- package/react/dist/index.server.js.map +0 -1
- package/react/dist/index.server.mjs +0 -23
- package/react/dist/index.server.mjs.map +0 -1
- package/solid/dist/index.d.mts +0 -408
- package/solid/dist/index.d.ts +0 -408
- package/solid/dist/index.js +0 -1072
- package/solid/dist/index.js.map +0 -1
- package/solid/dist/index.mjs +0 -1044
- package/solid/dist/index.mjs.map +0 -1
- package/svelte/dist/index.d.mts +0 -484
- package/svelte/dist/index.d.ts +0 -484
- package/svelte/dist/index.js +0 -1778
- package/svelte/dist/index.js.map +0 -1
- package/svelte/dist/index.mjs +0 -1749
- package/svelte/dist/index.mjs.map +0 -1
- package/vue/dist/index.d.mts +0 -402
- package/vue/dist/index.d.ts +0 -402
- package/vue/dist/index.js +0 -1072
- package/vue/dist/index.js.map +0 -1
- package/vue/dist/index.mjs +0 -1034
- package/vue/dist/index.mjs.map +0 -1
package/rsc/dist/index.d.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1 } from '@ai-sdk/provider';
|
2
2
|
import { ReactNode } from 'react';
|
3
|
-
import OpenAI from 'openai';
|
4
3
|
import { z } from 'zod';
|
5
|
-
import {
|
4
|
+
import { ToolInvocation, Attachment } from '@ai-sdk/ui-utils';
|
6
5
|
|
7
6
|
type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;
|
8
7
|
type AIActions<T = any, R = any> = Record<string, AIAction<T, R>>;
|
@@ -29,11 +28,6 @@ type MutableAIState<AIState> = {
|
|
29
28
|
update: (newState: ValueOrUpdater<AIState>) => void;
|
30
29
|
done: ((newState: AIState) => void) | (() => void);
|
31
30
|
};
|
32
|
-
/**
|
33
|
-
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
34
|
-
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
35
|
-
*/
|
36
|
-
type StreamableValue<T = any, E = any> = {};
|
37
31
|
|
38
32
|
/**
|
39
33
|
* Get the current AI state.
|
@@ -43,10 +37,10 @@ type StreamableValue<T = any, E = any> = {};
|
|
43
37
|
* @example const state = getAIState() // Get the entire AI state
|
44
38
|
* @example const field = getAIState('key') // Get the value of the key
|
45
39
|
*/
|
46
|
-
declare function getAIState<AI extends AIProvider = any>(): InferAIState<AI, any
|
47
|
-
declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): InferAIState<AI, any>[typeof key]
|
40
|
+
declare function getAIState<AI extends AIProvider = any>(): Readonly<InferAIState<AI, any>>;
|
41
|
+
declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): Readonly<InferAIState<AI, any>[typeof key]>;
|
48
42
|
/**
|
49
|
-
* Get the mutable AI state. Note that you must call `.
|
43
|
+
* Get the mutable AI state. Note that you must call `.done()` when finishing
|
50
44
|
* updating the AI state.
|
51
45
|
*
|
52
46
|
* @example
|
@@ -66,160 +60,45 @@ declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState
|
|
66
60
|
declare function getMutableAIState<AI extends AIProvider = any>(): MutableAIState<InferAIState<AI, any>>;
|
67
61
|
declare function getMutableAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): MutableAIState<InferAIState<AI, any>[typeof key]>;
|
68
62
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
declare function createStreamableUI(initialValue?: React.ReactNode): {
|
74
|
-
/**
|
75
|
-
* The value of the streamable UI. This can be returned from a Server Action and received by the client.
|
76
|
-
*/
|
77
|
-
value: react_jsx_runtime.JSX.Element;
|
63
|
+
declare function createAI<AIState = any, UIState = any, Actions extends AIActions = {}>({ actions, initialAIState, initialUIState, onSetAIState, onGetUIState, }: {
|
64
|
+
actions: Actions;
|
65
|
+
initialAIState?: AIState;
|
66
|
+
initialUIState?: UIState;
|
78
67
|
/**
|
79
|
-
* This
|
68
|
+
* This function is called whenever the AI state is updated by an Action.
|
69
|
+
* You can use this to persist the AI state to a database, or to send it to a
|
70
|
+
* logging service.
|
80
71
|
*/
|
81
|
-
|
72
|
+
onSetAIState?: OnSetAIState<AIState>;
|
82
73
|
/**
|
83
|
-
* This
|
84
|
-
*
|
85
|
-
*
|
86
|
-
* @example
|
87
|
-
* ```jsx
|
88
|
-
* const ui = createStreamableUI(<div>hello</div>)
|
89
|
-
* ui.append(<div>world</div>)
|
74
|
+
* This function is used to retrieve the UI state based on the AI state.
|
75
|
+
* For example, to render the initial UI state based on a given AI state, or
|
76
|
+
* to sync the UI state when the application is already loaded.
|
90
77
|
*
|
91
|
-
*
|
92
|
-
* // <>
|
93
|
-
* // <div>hello</div>
|
94
|
-
* // <div>world</div>
|
95
|
-
* // </>
|
96
|
-
* ```
|
97
|
-
*/
|
98
|
-
append(value: React.ReactNode): any;
|
99
|
-
/**
|
100
|
-
* This method is used to signal that there is an error in the UI stream.
|
101
|
-
* It will be thrown on the client side and caught by the nearest error boundary component.
|
102
|
-
*/
|
103
|
-
error(error: any): any;
|
104
|
-
/**
|
105
|
-
* This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
|
106
|
-
* Once called, the UI node cannot be updated or appended anymore.
|
78
|
+
* If returning `undefined`, the client side UI state will not be updated.
|
107
79
|
*
|
108
|
-
* This
|
109
|
-
*/
|
110
|
-
done(...args: [] | [React.ReactNode]): any;
|
111
|
-
};
|
112
|
-
declare const STREAMABLE_VALUE_INTERNAL_LOCK: unique symbol;
|
113
|
-
/**
|
114
|
-
* Create a wrapped, changable value that can be streamed to the client.
|
115
|
-
* On the client side, the value can be accessed via the readStreamableValue() API.
|
116
|
-
*/
|
117
|
-
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): {
|
118
|
-
/**
|
119
|
-
* @internal This is an internal lock to prevent the value from being
|
120
|
-
* updated by the user.
|
121
|
-
*/
|
122
|
-
[STREAMABLE_VALUE_INTERNAL_LOCK]: boolean;
|
123
|
-
/**
|
124
|
-
* The value of the streamable. This can be returned from a Server Action and
|
125
|
-
* received by the client. To read the streamed values, use the
|
126
|
-
* `readStreamableValue` or `useStreamableValue` APIs.
|
127
|
-
*/
|
128
|
-
readonly value: StreamableValue<T, E>;
|
129
|
-
/**
|
130
|
-
* This method updates the current value with a new one.
|
131
|
-
*/
|
132
|
-
update(value: T): any;
|
133
|
-
/**
|
134
|
-
* This method is used to append a delta string to the current value. It
|
135
|
-
* requires the current value of the streamable to be a string.
|
80
|
+
* This function must be annotated with the `"use server"` directive.
|
136
81
|
*
|
137
82
|
* @example
|
138
|
-
* ```
|
139
|
-
*
|
140
|
-
*
|
83
|
+
* ```tsx
|
84
|
+
* onGetUIState: async () => {
|
85
|
+
* 'use server';
|
141
86
|
*
|
142
|
-
*
|
143
|
-
*
|
144
|
-
*/
|
145
|
-
append(value: T): any;
|
146
|
-
/**
|
147
|
-
* This method is used to signal that there is an error in the value stream.
|
148
|
-
* It will be thrown on the client side when consumed via
|
149
|
-
* `readStreamableValue` or `useStreamableValue`.
|
150
|
-
*/
|
151
|
-
error(error: any): any;
|
152
|
-
/**
|
153
|
-
* This method marks the value as finalized. You can either call it without
|
154
|
-
* any parameters or with a new value as the final state.
|
155
|
-
* Once called, the value cannot be updated or appended anymore.
|
87
|
+
* const currentAIState = getAIState();
|
88
|
+
* const externalAIState = await loadAIStateFromDatabase();
|
156
89
|
*
|
157
|
-
*
|
158
|
-
* will be stuck in a loading state.
|
159
|
-
*/
|
160
|
-
done(...args: [] | [T]): any;
|
161
|
-
};
|
162
|
-
|
163
|
-
type Streamable$1 = ReactNode | Promise<ReactNode>;
|
164
|
-
type Renderer$1<T> = (props: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
|
165
|
-
/**
|
166
|
-
* `render` is a helper function to create a streamable UI from some LLMs.
|
167
|
-
* This API only supports OpenAI's GPT models with Function Calling and Assistants Tools,
|
168
|
-
* please use `streamUI` for compatibility with other providers.
|
169
|
-
*
|
170
|
-
* @deprecated It's recommended to use the `streamUI` API for compatibility with AI SDK Core APIs
|
171
|
-
* and future features. This API will be removed in a future release.
|
172
|
-
*/
|
173
|
-
declare function render<TS extends {
|
174
|
-
[name: string]: z.Schema;
|
175
|
-
} = {}, FS extends {
|
176
|
-
[name: string]: z.Schema;
|
177
|
-
} = {}>(options: {
|
178
|
-
/**
|
179
|
-
* The model name to use. Must be OpenAI SDK compatible. Tools and Functions are only supported
|
180
|
-
* GPT models (3.5/4), OpenAI Assistants, Mistral small and large, and Fireworks firefunction-v1.
|
90
|
+
* if (currentAIState === externalAIState) return undefined;
|
181
91
|
*
|
182
|
-
*
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
*
|
187
|
-
*
|
92
|
+
* // Update current AI state and return the new UI state
|
93
|
+
* const state = getMutableAIState()
|
94
|
+
* state.done(externalAIState)
|
95
|
+
*
|
96
|
+
* return <div>...</div>;
|
97
|
+
* }
|
98
|
+
* ```
|
188
99
|
*/
|
189
|
-
|
190
|
-
|
191
|
-
text?: Renderer$1<{
|
192
|
-
/**
|
193
|
-
* The full text content from the model so far.
|
194
|
-
*/
|
195
|
-
content: string;
|
196
|
-
/**
|
197
|
-
* The new appended text content from the model since the last `text` call.
|
198
|
-
*/
|
199
|
-
delta: string;
|
200
|
-
/**
|
201
|
-
* Whether the model is done generating text.
|
202
|
-
* If `true`, the `content` will be the final output and this call will be the last.
|
203
|
-
*/
|
204
|
-
done: boolean;
|
205
|
-
}>;
|
206
|
-
tools?: {
|
207
|
-
[name in keyof TS]: {
|
208
|
-
description?: string;
|
209
|
-
parameters: TS[name];
|
210
|
-
render: Renderer$1<z.infer<TS[name]>>;
|
211
|
-
};
|
212
|
-
};
|
213
|
-
functions?: {
|
214
|
-
[name in keyof FS]: {
|
215
|
-
description?: string;
|
216
|
-
parameters: FS[name];
|
217
|
-
render: Renderer$1<z.infer<FS[name]>>;
|
218
|
-
};
|
219
|
-
};
|
220
|
-
initial?: ReactNode;
|
221
|
-
temperature?: number;
|
222
|
-
}): ReactNode;
|
100
|
+
onGetUIState?: OnGetUIState<UIState>;
|
101
|
+
}): AIProvider<AIState, UIState, Actions>;
|
223
102
|
|
224
103
|
type CallSettings = {
|
225
104
|
/**
|
@@ -245,13 +124,18 @@ type CallSettings = {
|
|
245
124
|
*/
|
246
125
|
topP?: number;
|
247
126
|
/**
|
127
|
+
Only sample from the top K options for each subsequent token.
|
128
|
+
|
129
|
+
Used to remove "long tail" low probability responses.
|
130
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
131
|
+
*/
|
132
|
+
topK?: number;
|
133
|
+
/**
|
248
134
|
Presence penalty setting. It affects the likelihood of the model to
|
249
135
|
repeat information that is already in the prompt.
|
250
136
|
|
251
137
|
The presence penalty is a number between -1 (increase repetition)
|
252
138
|
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
253
|
-
|
254
|
-
@default 0
|
255
139
|
*/
|
256
140
|
presencePenalty?: number;
|
257
141
|
/**
|
@@ -260,11 +144,15 @@ type CallSettings = {
|
|
260
144
|
|
261
145
|
The frequency penalty is a number between -1 (increase repetition)
|
262
146
|
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
263
|
-
|
264
|
-
@default 0
|
265
147
|
*/
|
266
148
|
frequencyPenalty?: number;
|
267
149
|
/**
|
150
|
+
Stop sequences.
|
151
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
152
|
+
Providers may have limits on the number of stop sequences.
|
153
|
+
*/
|
154
|
+
stopSequences?: string[];
|
155
|
+
/**
|
268
156
|
The seed (integer) to use for random sampling. If set and supported
|
269
157
|
by the model, calls will generate deterministic results.
|
270
158
|
*/
|
@@ -279,6 +167,66 @@ type CallSettings = {
|
|
279
167
|
Abort signal.
|
280
168
|
*/
|
281
169
|
abortSignal?: AbortSignal;
|
170
|
+
/**
|
171
|
+
Additional HTTP headers to be sent with the request.
|
172
|
+
Only applicable for HTTP-based providers.
|
173
|
+
*/
|
174
|
+
headers?: Record<string, string | undefined>;
|
175
|
+
};
|
176
|
+
|
177
|
+
/**
|
178
|
+
Reason why a language model finished generating a response.
|
179
|
+
|
180
|
+
Can be one of the following:
|
181
|
+
- `stop`: model generated stop sequence
|
182
|
+
- `length`: model generated maximum number of tokens
|
183
|
+
- `content-filter`: content filter violation stopped the model
|
184
|
+
- `tool-calls`: model triggered tool calls
|
185
|
+
- `error`: model stopped because of an error
|
186
|
+
- `other`: model stopped for other reasons
|
187
|
+
*/
|
188
|
+
type FinishReason = LanguageModelV1FinishReason;
|
189
|
+
/**
|
190
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
191
|
+
some settings might not be supported, which can lead to suboptimal results.
|
192
|
+
*/
|
193
|
+
type CallWarning = LanguageModelV1CallWarning;
|
194
|
+
/**
|
195
|
+
Tool choice for the generation. It supports the following settings:
|
196
|
+
|
197
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
198
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
199
|
+
- `none`: the model must not call tools
|
200
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
201
|
+
*/
|
202
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
203
|
+
type: 'tool';
|
204
|
+
toolName: keyof TOOLS;
|
205
|
+
};
|
206
|
+
|
207
|
+
/**
|
208
|
+
Additional provider-specific metadata. They are passed through
|
209
|
+
to the provider from the AI SDK and enable provider-specific
|
210
|
+
functionality that can be fully encapsulated in the provider.
|
211
|
+
*/
|
212
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
213
|
+
|
214
|
+
/**
|
215
|
+
Represents the number of tokens used in a prompt and completion.
|
216
|
+
*/
|
217
|
+
type LanguageModelUsage = {
|
218
|
+
/**
|
219
|
+
The number of tokens used in the prompt.
|
220
|
+
*/
|
221
|
+
promptTokens: number;
|
222
|
+
/**
|
223
|
+
The number of tokens used in the completion.
|
224
|
+
*/
|
225
|
+
completionTokens: number;
|
226
|
+
/**
|
227
|
+
The total number of tokens used (promptTokens + completionTokens).
|
228
|
+
*/
|
229
|
+
totalTokens: number;
|
282
230
|
};
|
283
231
|
|
284
232
|
/**
|
@@ -286,6 +234,15 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
286
234
|
*/
|
287
235
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
288
236
|
|
237
|
+
type ToolResultContent = Array<{
|
238
|
+
type: 'text';
|
239
|
+
text: string;
|
240
|
+
} | {
|
241
|
+
type: 'image';
|
242
|
+
data: string;
|
243
|
+
mimeType?: string;
|
244
|
+
}>;
|
245
|
+
|
289
246
|
/**
|
290
247
|
Text content part of a prompt. It contains a string of text.
|
291
248
|
*/
|
@@ -295,6 +252,12 @@ interface TextPart {
|
|
295
252
|
The text content.
|
296
253
|
*/
|
297
254
|
text: string;
|
255
|
+
/**
|
256
|
+
Additional provider-specific metadata. They are passed through
|
257
|
+
to the provider from the AI SDK and enable provider-specific
|
258
|
+
functionality that can be fully encapsulated in the provider.
|
259
|
+
*/
|
260
|
+
experimental_providerMetadata?: ProviderMetadata;
|
298
261
|
}
|
299
262
|
/**
|
300
263
|
Image content part of a prompt. It contains an image.
|
@@ -312,6 +275,35 @@ interface ImagePart {
|
|
312
275
|
Optional mime type of the image.
|
313
276
|
*/
|
314
277
|
mimeType?: string;
|
278
|
+
/**
|
279
|
+
Additional provider-specific metadata. They are passed through
|
280
|
+
to the provider from the AI SDK and enable provider-specific
|
281
|
+
functionality that can be fully encapsulated in the provider.
|
282
|
+
*/
|
283
|
+
experimental_providerMetadata?: ProviderMetadata;
|
284
|
+
}
|
285
|
+
/**
|
286
|
+
File content part of a prompt. It contains a file.
|
287
|
+
*/
|
288
|
+
interface FilePart {
|
289
|
+
type: 'file';
|
290
|
+
/**
|
291
|
+
File data. Can either be:
|
292
|
+
|
293
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
294
|
+
- URL: a URL that points to the image
|
295
|
+
*/
|
296
|
+
data: DataContent | URL;
|
297
|
+
/**
|
298
|
+
Mime type of the file.
|
299
|
+
*/
|
300
|
+
mimeType: string;
|
301
|
+
/**
|
302
|
+
Additional provider-specific metadata. They are passed through
|
303
|
+
to the provider from the AI SDK and enable provider-specific
|
304
|
+
functionality that can be fully encapsulated in the provider.
|
305
|
+
*/
|
306
|
+
experimental_providerMetadata?: ProviderMetadata;
|
315
307
|
}
|
316
308
|
/**
|
317
309
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
@@ -330,6 +322,12 @@ interface ToolCallPart {
|
|
330
322
|
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
331
323
|
*/
|
332
324
|
args: unknown;
|
325
|
+
/**
|
326
|
+
Additional provider-specific metadata. They are passed through
|
327
|
+
to the provider from the AI SDK and enable provider-specific
|
328
|
+
functionality that can be fully encapsulated in the provider.
|
329
|
+
*/
|
330
|
+
experimental_providerMetadata?: ProviderMetadata;
|
333
331
|
}
|
334
332
|
/**
|
335
333
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
@@ -349,16 +347,21 @@ interface ToolResultPart {
|
|
349
347
|
*/
|
350
348
|
result: unknown;
|
351
349
|
/**
|
350
|
+
Multi-part content of the tool result. Only for tools that support multipart results.
|
351
|
+
*/
|
352
|
+
experimental_content?: ToolResultContent;
|
353
|
+
/**
|
352
354
|
Optional flag if the result is an error or an error message.
|
353
355
|
*/
|
354
356
|
isError?: boolean;
|
357
|
+
/**
|
358
|
+
Additional provider-specific metadata. They are passed through
|
359
|
+
to the provider from the AI SDK and enable provider-specific
|
360
|
+
functionality that can be fully encapsulated in the provider.
|
361
|
+
*/
|
362
|
+
experimental_providerMetadata?: ProviderMetadata;
|
355
363
|
}
|
356
364
|
|
357
|
-
/**
|
358
|
-
A message that can be used in the `messages` field of a prompt.
|
359
|
-
It can be a user message, an assistant message, or a tool message.
|
360
|
-
*/
|
361
|
-
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
362
365
|
/**
|
363
366
|
A system message. It can contain system information.
|
364
367
|
|
@@ -369,6 +372,12 @@ type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage |
|
|
369
372
|
type CoreSystemMessage = {
|
370
373
|
role: 'system';
|
371
374
|
content: string;
|
375
|
+
/**
|
376
|
+
Additional provider-specific metadata. They are passed through
|
377
|
+
to the provider from the AI SDK and enable provider-specific
|
378
|
+
functionality that can be fully encapsulated in the provider.
|
379
|
+
*/
|
380
|
+
experimental_providerMetadata?: ProviderMetadata;
|
372
381
|
};
|
373
382
|
/**
|
374
383
|
A user message. It can contain text or a combination of text and images.
|
@@ -376,17 +385,29 @@ A user message. It can contain text or a combination of text and images.
|
|
376
385
|
type CoreUserMessage = {
|
377
386
|
role: 'user';
|
378
387
|
content: UserContent;
|
388
|
+
/**
|
389
|
+
Additional provider-specific metadata. They are passed through
|
390
|
+
to the provider from the AI SDK and enable provider-specific
|
391
|
+
functionality that can be fully encapsulated in the provider.
|
392
|
+
*/
|
393
|
+
experimental_providerMetadata?: ProviderMetadata;
|
379
394
|
};
|
380
395
|
/**
|
381
396
|
Content of a user message. It can be a string or an array of text and image parts.
|
382
397
|
*/
|
383
|
-
type UserContent = string | Array<TextPart | ImagePart>;
|
398
|
+
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
384
399
|
/**
|
385
400
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
386
401
|
*/
|
387
402
|
type CoreAssistantMessage = {
|
388
403
|
role: 'assistant';
|
389
404
|
content: AssistantContent;
|
405
|
+
/**
|
406
|
+
Additional provider-specific metadata. They are passed through
|
407
|
+
to the provider from the AI SDK and enable provider-specific
|
408
|
+
functionality that can be fully encapsulated in the provider.
|
409
|
+
*/
|
410
|
+
experimental_providerMetadata?: ProviderMetadata;
|
390
411
|
};
|
391
412
|
/**
|
392
413
|
Content of an assistant message. It can be a string or an array of text and tool call parts.
|
@@ -398,14 +419,33 @@ A tool message. It contains the result of one or more tool calls.
|
|
398
419
|
type CoreToolMessage = {
|
399
420
|
role: 'tool';
|
400
421
|
content: ToolContent;
|
422
|
+
/**
|
423
|
+
Additional provider-specific metadata. They are passed through
|
424
|
+
to the provider from the AI SDK and enable provider-specific
|
425
|
+
functionality that can be fully encapsulated in the provider.
|
426
|
+
*/
|
427
|
+
experimental_providerMetadata?: ProviderMetadata;
|
401
428
|
};
|
402
429
|
/**
|
403
430
|
Content of a tool message. It is an array of tool result parts.
|
404
431
|
*/
|
405
432
|
type ToolContent = Array<ToolResultPart>;
|
433
|
+
/**
|
434
|
+
A message that can be used in the `messages` field of a prompt.
|
435
|
+
It can be a user message, an assistant message, or a tool message.
|
436
|
+
*/
|
437
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
438
|
+
|
439
|
+
type UIMessage = {
|
440
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
441
|
+
content: string;
|
442
|
+
toolInvocations?: ToolInvocation[];
|
443
|
+
experimental_attachments?: Attachment[];
|
444
|
+
};
|
406
445
|
|
407
446
|
/**
|
408
|
-
Prompt part of the AI function options.
|
447
|
+
Prompt part of the AI function options.
|
448
|
+
It contains a system message, a simple text prompt, or a list of messages.
|
409
449
|
*/
|
410
450
|
type Prompt = {
|
411
451
|
/**
|
@@ -417,9 +457,9 @@ type Prompt = {
|
|
417
457
|
*/
|
418
458
|
prompt?: string;
|
419
459
|
/**
|
420
|
-
A list of
|
460
|
+
A list of messages. You can either use `prompt` or `messages` but not both.
|
421
461
|
*/
|
422
|
-
messages?: Array<CoreMessage>;
|
462
|
+
messages?: Array<CoreMessage> | Array<UIMessage>;
|
423
463
|
};
|
424
464
|
|
425
465
|
type Streamable = ReactNode | Promise<ReactNode>;
|
@@ -460,7 +500,7 @@ type RenderResult = {
|
|
460
500
|
*/
|
461
501
|
declare function streamUI<TOOLS extends {
|
462
502
|
[name: string]: z.ZodTypeAny;
|
463
|
-
} = {}>({ model, tools, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
503
|
+
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, experimental_providerMetadata: providerMetadata, onFinish, ...settings }: CallSettings & Prompt & {
|
464
504
|
/**
|
465
505
|
* The language model to use.
|
466
506
|
*/
|
@@ -471,49 +511,151 @@ declare function streamUI<TOOLS extends {
|
|
471
511
|
tools?: {
|
472
512
|
[name in keyof TOOLS]: RenderTool<TOOLS[name]>;
|
473
513
|
};
|
514
|
+
/**
|
515
|
+
* The tool choice strategy. Default: 'auto'.
|
516
|
+
*/
|
517
|
+
toolChoice?: CoreToolChoice<TOOLS>;
|
474
518
|
text?: RenderText;
|
475
519
|
initial?: ReactNode;
|
520
|
+
/**
|
521
|
+
Additional provider-specific metadata. They are passed through
|
522
|
+
to the provider from the AI SDK and enable provider-specific
|
523
|
+
functionality that can be fully encapsulated in the provider.
|
524
|
+
*/
|
525
|
+
experimental_providerMetadata?: ProviderMetadata;
|
526
|
+
/**
|
527
|
+
* Callback that is called when the LLM response and the final object validation are finished.
|
528
|
+
*/
|
529
|
+
onFinish?: (event: {
|
530
|
+
/**
|
531
|
+
* The reason why the generation finished.
|
532
|
+
*/
|
533
|
+
finishReason: FinishReason;
|
534
|
+
/**
|
535
|
+
* The token usage of the generated response.
|
536
|
+
*/
|
537
|
+
usage: LanguageModelUsage;
|
538
|
+
/**
|
539
|
+
* The final ui node that was generated.
|
540
|
+
*/
|
541
|
+
value: ReactNode;
|
542
|
+
/**
|
543
|
+
* Warnings from the model provider (e.g. unsupported settings)
|
544
|
+
*/
|
545
|
+
warnings?: CallWarning[];
|
546
|
+
/**
|
547
|
+
* Optional raw response data.
|
548
|
+
*/
|
549
|
+
rawResponse?: {
|
550
|
+
/**
|
551
|
+
* Response headers.
|
552
|
+
*/
|
553
|
+
headers?: Record<string, string>;
|
554
|
+
};
|
555
|
+
}) => Promise<void> | void;
|
476
556
|
}): Promise<RenderResult>;
|
477
557
|
|
478
|
-
|
479
|
-
actions: Actions;
|
480
|
-
initialAIState?: AIState;
|
481
|
-
initialUIState?: UIState;
|
558
|
+
type StreamableUIWrapper = {
|
482
559
|
/**
|
483
|
-
* This
|
484
|
-
* You can use this to persist the AI state to a database, or to send it to a
|
485
|
-
* logging service.
|
560
|
+
* The value of the streamable UI. This can be returned from a Server Action and received by the client.
|
486
561
|
*/
|
487
|
-
|
562
|
+
readonly value: React.ReactNode;
|
488
563
|
/**
|
489
|
-
* This
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
*
|
494
|
-
*
|
495
|
-
* This function must be annotated with the `"use server"` directive.
|
564
|
+
* This method updates the current UI node. It takes a new UI node and replaces the old one.
|
565
|
+
*/
|
566
|
+
update(value: React.ReactNode): StreamableUIWrapper;
|
567
|
+
/**
|
568
|
+
* This method is used to append a new UI node to the end of the old one.
|
569
|
+
* Once appended a new UI node, the previous UI node cannot be updated anymore.
|
496
570
|
*
|
497
571
|
* @example
|
498
|
-
* ```
|
499
|
-
*
|
500
|
-
*
|
572
|
+
* ```jsx
|
573
|
+
* const ui = createStreamableUI(<div>hello</div>)
|
574
|
+
* ui.append(<div>world</div>)
|
501
575
|
*
|
502
|
-
*
|
503
|
-
*
|
576
|
+
* // The UI node will be:
|
577
|
+
* // <>
|
578
|
+
* // <div>hello</div>
|
579
|
+
* // <div>world</div>
|
580
|
+
* // </>
|
581
|
+
* ```
|
582
|
+
*/
|
583
|
+
append(value: React.ReactNode): StreamableUIWrapper;
|
584
|
+
/**
|
585
|
+
* This method is used to signal that there is an error in the UI stream.
|
586
|
+
* It will be thrown on the client side and caught by the nearest error boundary component.
|
587
|
+
*/
|
588
|
+
error(error: any): StreamableUIWrapper;
|
589
|
+
/**
|
590
|
+
* This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
|
591
|
+
* Once called, the UI node cannot be updated or appended anymore.
|
504
592
|
*
|
505
|
-
*
|
593
|
+
* This method is always **required** to be called, otherwise the response will be stuck in a loading state.
|
594
|
+
*/
|
595
|
+
done(...args: [React.ReactNode] | []): StreamableUIWrapper;
|
596
|
+
};
|
597
|
+
/**
|
598
|
+
* Create a piece of changeable UI that can be streamed to the client.
|
599
|
+
* On the client side, it can be rendered as a normal React node.
|
600
|
+
*/
|
601
|
+
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
|
602
|
+
|
603
|
+
declare const __internal_curr: unique symbol;
|
604
|
+
declare const __internal_error: unique symbol;
|
605
|
+
/**
|
606
|
+
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
607
|
+
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
608
|
+
*/
|
609
|
+
type StreamableValue<T = any, E = any> = {
|
610
|
+
[__internal_curr]?: T;
|
611
|
+
[__internal_error]?: E;
|
612
|
+
};
|
613
|
+
|
614
|
+
/**
|
615
|
+
* Create a wrapped, changeable value that can be streamed to the client.
|
616
|
+
* On the client side, the value can be accessed via the readStreamableValue() API.
|
617
|
+
*/
|
618
|
+
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
|
619
|
+
type StreamableValueWrapper<T, E> = {
|
620
|
+
/**
|
621
|
+
* The value of the streamable. This can be returned from a Server Action and
|
622
|
+
* received by the client. To read the streamed values, use the
|
623
|
+
* `readStreamableValue` or `useStreamableValue` APIs.
|
624
|
+
*/
|
625
|
+
readonly value: StreamableValue<T, E>;
|
626
|
+
/**
|
627
|
+
* This method updates the current value with a new one.
|
628
|
+
*/
|
629
|
+
update(value: T): StreamableValueWrapper<T, E>;
|
630
|
+
/**
|
631
|
+
* This method is used to append a delta string to the current value. It
|
632
|
+
* requires the current value of the streamable to be a string.
|
506
633
|
*
|
507
|
-
*
|
508
|
-
*
|
509
|
-
*
|
634
|
+
* @example
|
635
|
+
* ```jsx
|
636
|
+
* const streamable = createStreamableValue('hello');
|
637
|
+
* streamable.append(' world');
|
510
638
|
*
|
511
|
-
*
|
512
|
-
* }
|
639
|
+
* // The value will be 'hello world'
|
513
640
|
* ```
|
514
641
|
*/
|
515
|
-
|
516
|
-
|
642
|
+
append(value: T): StreamableValueWrapper<T, E>;
|
643
|
+
/**
|
644
|
+
* This method is used to signal that there is an error in the value stream.
|
645
|
+
* It will be thrown on the client side when consumed via
|
646
|
+
* `readStreamableValue` or `useStreamableValue`.
|
647
|
+
*/
|
648
|
+
error(error: any): StreamableValueWrapper<T, E>;
|
649
|
+
/**
|
650
|
+
* This method marks the value as finalized. You can either call it without
|
651
|
+
* any parameters or with a new value as the final state.
|
652
|
+
* Once called, the value cannot be updated or appended anymore.
|
653
|
+
*
|
654
|
+
* This method is always **required** to be called, otherwise the response
|
655
|
+
* will be stuck in a loading state.
|
656
|
+
*/
|
657
|
+
done(...args: [T] | []): StreamableValueWrapper<T, E>;
|
658
|
+
};
|
517
659
|
|
518
660
|
/**
|
519
661
|
* `readStreamableValue` takes a streamable value created via the `createStreamableValue().value` API,
|
@@ -546,6 +688,7 @@ declare function createAI<AIState = any, UIState = any, Actions extends AIAction
|
|
546
688
|
* This logs out 1, 2, 3 on console.
|
547
689
|
*/
|
548
690
|
declare function readStreamableValue<T = unknown>(streamableValue: StreamableValue<T>): AsyncIterable<T | undefined>;
|
691
|
+
|
549
692
|
/**
|
550
693
|
* `useStreamableValue` is a React hook that takes a streamable value created via the `createStreamableValue().value` API,
|
551
694
|
* and returns the current value, error, and pending state.
|
@@ -577,4 +720,4 @@ declare function useAIState<AI extends AIProvider = any>(key: keyof InferAIState
|
|
577
720
|
declare function useActions<AI extends AIProvider = any>(): InferActions<AI, any>;
|
578
721
|
declare function useSyncUIState(): () => Promise<void>;
|
579
722
|
|
580
|
-
export { StreamableValue, createAI, createStreamableUI, createStreamableValue, getAIState, getMutableAIState, readStreamableValue,
|
723
|
+
export { StreamableValue, createAI, createStreamableUI, createStreamableValue, getAIState, getMutableAIState, readStreamableValue, streamUI, useAIState, useActions, useStreamableValue, useSyncUIState, useUIState };
|