ai 3.1.0-canary.4 → 3.1.1
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 +982 -24
- package/dist/index.d.ts +982 -24
- package/dist/index.js +1748 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1723 -174
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -28
- package/prompts/dist/index.d.mts +13 -1
- package/prompts/dist/index.d.ts +13 -1
- package/prompts/dist/index.js +13 -0
- package/prompts/dist/index.js.map +1 -1
- package/prompts/dist/index.mjs +12 -0
- package/prompts/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +23 -6
- package/react/dist/index.d.ts +27 -8
- package/react/dist/index.js +154 -141
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +153 -141
- package/react/dist/index.mjs.map +1 -1
- package/react/dist/index.server.d.mts +4 -2
- package/react/dist/index.server.d.ts +4 -2
- package/react/dist/index.server.js.map +1 -1
- package/react/dist/index.server.mjs.map +1 -1
- package/rsc/dist/index.d.ts +388 -21
- package/rsc/dist/rsc-client.d.mts +1 -1
- package/rsc/dist/rsc-client.mjs +2 -0
- package/rsc/dist/rsc-client.mjs.map +1 -1
- package/rsc/dist/rsc-server.d.mts +370 -21
- package/rsc/dist/rsc-server.mjs +677 -36
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +24 -9
- package/rsc/dist/rsc-shared.mjs +98 -4
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/solid/dist/index.d.mts +7 -3
- package/solid/dist/index.d.ts +7 -3
- package/solid/dist/index.js +106 -107
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +106 -107
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +7 -3
- package/svelte/dist/index.d.ts +7 -3
- package/svelte/dist/index.js +109 -109
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +109 -109
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +7 -3
- package/vue/dist/index.d.ts +7 -3
- package/vue/dist/index.js +106 -107
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +106 -107
- package/vue/dist/index.mjs.map +1 -1
- package/ai-model-specification/dist/index.d.mts +0 -665
- package/ai-model-specification/dist/index.d.ts +0 -665
- package/ai-model-specification/dist/index.js +0 -716
- package/ai-model-specification/dist/index.js.map +0 -1
- package/ai-model-specification/dist/index.mjs +0 -656
- package/ai-model-specification/dist/index.mjs.map +0 -1
- package/core/dist/index.d.mts +0 -626
- package/core/dist/index.d.ts +0 -626
- package/core/dist/index.js +0 -1918
- package/core/dist/index.js.map +0 -1
- package/core/dist/index.mjs +0 -1873
- package/core/dist/index.mjs.map +0 -1
- package/openai/dist/index.d.mts +0 -429
- package/openai/dist/index.d.ts +0 -429
- package/openai/dist/index.js +0 -1231
- package/openai/dist/index.js.map +0 -1
- package/openai/dist/index.mjs +0 -1195
- package/openai/dist/index.mjs.map +0 -1
package/rsc/dist/index.d.ts
CHANGED
@@ -2,8 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
3
3
|
import OpenAI from 'openai';
|
4
4
|
import { z } from 'zod';
|
5
|
-
|
6
|
-
declare const STREAMABLE_VALUE_TYPE: unique symbol;
|
5
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
7
6
|
|
8
7
|
type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;
|
9
8
|
type AIActions<T = any, R = any> = Record<string, AIAction<T, R>>;
|
@@ -30,12 +29,11 @@ type MutableAIState<AIState> = {
|
|
30
29
|
update: (newState: ValueOrUpdater<AIState>) => void;
|
31
30
|
done: ((newState: AIState) => void) | (() => void);
|
32
31
|
};
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
};
|
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> = {};
|
39
37
|
|
40
38
|
/**
|
41
39
|
* Get the current AI state.
|
@@ -73,28 +71,104 @@ declare function getMutableAIState<AI extends AIProvider = any>(key: keyof Infer
|
|
73
71
|
* On the client side, it can be rendered as a normal React node.
|
74
72
|
*/
|
75
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
|
+
*/
|
76
77
|
value: react_jsx_runtime.JSX.Element;
|
78
|
+
/**
|
79
|
+
* This method updates the current UI node. It takes a new UI node and replaces the old one.
|
80
|
+
*/
|
77
81
|
update(value: React.ReactNode): void;
|
82
|
+
/**
|
83
|
+
* This method is used to append a new UI node to the end of the old one.
|
84
|
+
* Once appended a new UI node, the previous UI node cannot be updated anymore.
|
85
|
+
*
|
86
|
+
* @example
|
87
|
+
* ```jsx
|
88
|
+
* const ui = createStreamableUI(<div>hello</div>)
|
89
|
+
* ui.append(<div>world</div>)
|
90
|
+
*
|
91
|
+
* // The UI node will be:
|
92
|
+
* // <>
|
93
|
+
* // <div>hello</div>
|
94
|
+
* // <div>world</div>
|
95
|
+
* // </>
|
96
|
+
* ```
|
97
|
+
*/
|
78
98
|
append(value: React.ReactNode): void;
|
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
|
+
*/
|
79
103
|
error(error: any): void;
|
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.
|
107
|
+
*
|
108
|
+
* This method is always **required** to be called, otherwise the response will be stuck in a loading state.
|
109
|
+
*/
|
80
110
|
done(...args: [] | [React.ReactNode]): void;
|
81
111
|
};
|
112
|
+
declare const STREAMABLE_VALUE_INTERNAL_LOCK: unique symbol;
|
82
113
|
/**
|
83
114
|
* Create a wrapped, changable value that can be streamed to the client.
|
84
115
|
* On the client side, the value can be accessed via the readStreamableValue() API.
|
85
116
|
*/
|
86
|
-
declare function createStreamableValue<T = any, E = any>(initialValue?: T): {
|
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
|
+
*/
|
87
128
|
readonly value: StreamableValue<T, E>;
|
129
|
+
/**
|
130
|
+
* This method updates the current value with a new one.
|
131
|
+
*/
|
88
132
|
update(value: T): void;
|
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.
|
136
|
+
*
|
137
|
+
* @example
|
138
|
+
* ```jsx
|
139
|
+
* const streamable = createStreamableValue('hello');
|
140
|
+
* streamable.append(' world');
|
141
|
+
*
|
142
|
+
* // The value will be 'hello world'
|
143
|
+
* ```
|
144
|
+
*/
|
145
|
+
append(value: T): void;
|
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
|
+
*/
|
89
151
|
error(error: any): void;
|
90
|
-
|
91
|
-
|
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.
|
156
|
+
*
|
157
|
+
* This method is always **required** to be called, otherwise the response
|
158
|
+
* will be stuck in a loading state.
|
159
|
+
*/
|
160
|
+
done(...args: [] | [T]): void;
|
92
161
|
};
|
93
|
-
|
94
|
-
type
|
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>;
|
95
165
|
/**
|
96
166
|
* `render` is a helper function to create a streamable UI from some LLMs.
|
97
|
-
*
|
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.
|
98
172
|
*/
|
99
173
|
declare function render<TS extends {
|
100
174
|
[name: string]: z.Schema;
|
@@ -114,7 +188,7 @@ declare function render<TS extends {
|
|
114
188
|
*/
|
115
189
|
provider: OpenAI;
|
116
190
|
messages: Parameters<typeof OpenAI.prototype.chat.completions.create>[0]['messages'];
|
117
|
-
text?: Renderer<{
|
191
|
+
text?: Renderer$1<{
|
118
192
|
/**
|
119
193
|
* The full text content from the model so far.
|
120
194
|
*/
|
@@ -133,26 +207,301 @@ declare function render<TS extends {
|
|
133
207
|
[name in keyof TS]: {
|
134
208
|
description?: string;
|
135
209
|
parameters: TS[name];
|
136
|
-
render: Renderer<z.infer<TS[name]>>;
|
210
|
+
render: Renderer$1<z.infer<TS[name]>>;
|
137
211
|
};
|
138
212
|
};
|
139
213
|
functions?: {
|
140
214
|
[name in keyof FS]: {
|
141
215
|
description?: string;
|
142
216
|
parameters: FS[name];
|
143
|
-
render: Renderer<z.infer<FS[name]>>;
|
217
|
+
render: Renderer$1<z.infer<FS[name]>>;
|
144
218
|
};
|
145
219
|
};
|
146
220
|
initial?: ReactNode;
|
147
221
|
temperature?: number;
|
148
222
|
}): ReactNode;
|
149
223
|
|
150
|
-
|
224
|
+
type CallSettings = {
|
225
|
+
/**
|
226
|
+
Maximum number of tokens to generate.
|
227
|
+
*/
|
228
|
+
maxTokens?: number;
|
229
|
+
/**
|
230
|
+
Temperature setting. This is a number between 0 (almost no randomness) and
|
231
|
+
1 (very random).
|
232
|
+
|
233
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
234
|
+
|
235
|
+
@default 0
|
236
|
+
*/
|
237
|
+
temperature?: number;
|
238
|
+
/**
|
239
|
+
Nucleus sampling. This is a number between 0 and 1.
|
240
|
+
|
241
|
+
E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
242
|
+
are considered.
|
243
|
+
|
244
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
245
|
+
*/
|
246
|
+
topP?: number;
|
247
|
+
/**
|
248
|
+
Presence penalty setting. It affects the likelihood of the model to
|
249
|
+
repeat information that is already in the prompt.
|
250
|
+
|
251
|
+
The presence penalty is a number between -1 (increase repetition)
|
252
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
253
|
+
|
254
|
+
@default 0
|
255
|
+
*/
|
256
|
+
presencePenalty?: number;
|
257
|
+
/**
|
258
|
+
Frequency penalty setting. It affects the likelihood of the model
|
259
|
+
to repeatedly use the same words or phrases.
|
260
|
+
|
261
|
+
The frequency penalty is a number between -1 (increase repetition)
|
262
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
263
|
+
|
264
|
+
@default 0
|
265
|
+
*/
|
266
|
+
frequencyPenalty?: number;
|
267
|
+
/**
|
268
|
+
The seed (integer) to use for random sampling. If set and supported
|
269
|
+
by the model, calls will generate deterministic results.
|
270
|
+
*/
|
271
|
+
seed?: number;
|
272
|
+
/**
|
273
|
+
Maximum number of retries. Set to 0 to disable retries.
|
274
|
+
|
275
|
+
@default 2
|
276
|
+
*/
|
277
|
+
maxRetries?: number;
|
278
|
+
/**
|
279
|
+
Abort signal.
|
280
|
+
*/
|
281
|
+
abortSignal?: AbortSignal;
|
282
|
+
};
|
283
|
+
|
284
|
+
/**
|
285
|
+
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
286
|
+
*/
|
287
|
+
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
288
|
+
|
289
|
+
/**
|
290
|
+
Text content part of a prompt. It contains a string of text.
|
291
|
+
*/
|
292
|
+
interface TextPart {
|
293
|
+
type: 'text';
|
294
|
+
/**
|
295
|
+
The text content.
|
296
|
+
*/
|
297
|
+
text: string;
|
298
|
+
}
|
299
|
+
/**
|
300
|
+
Image content part of a prompt. It contains an image.
|
301
|
+
*/
|
302
|
+
interface ImagePart {
|
303
|
+
type: 'image';
|
304
|
+
/**
|
305
|
+
Image data. Can either be:
|
306
|
+
|
307
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
308
|
+
- URL: a URL that points to the image
|
309
|
+
*/
|
310
|
+
image: DataContent | URL;
|
311
|
+
/**
|
312
|
+
Optional mime type of the image.
|
313
|
+
*/
|
314
|
+
mimeType?: string;
|
315
|
+
}
|
316
|
+
/**
|
317
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
318
|
+
*/
|
319
|
+
interface ToolCallPart {
|
320
|
+
type: 'tool-call';
|
321
|
+
/**
|
322
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
323
|
+
*/
|
324
|
+
toolCallId: string;
|
325
|
+
/**
|
326
|
+
Name of the tool that is being called.
|
327
|
+
*/
|
328
|
+
toolName: string;
|
329
|
+
/**
|
330
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
331
|
+
*/
|
332
|
+
args: unknown;
|
333
|
+
}
|
334
|
+
/**
|
335
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
336
|
+
*/
|
337
|
+
interface ToolResultPart {
|
338
|
+
type: 'tool-result';
|
339
|
+
/**
|
340
|
+
ID of the tool call that this result is associated with.
|
341
|
+
*/
|
342
|
+
toolCallId: string;
|
343
|
+
/**
|
344
|
+
Name of the tool that generated this result.
|
345
|
+
*/
|
346
|
+
toolName: string;
|
347
|
+
/**
|
348
|
+
Result of the tool call. This is a JSON-serializable object.
|
349
|
+
*/
|
350
|
+
result: unknown;
|
351
|
+
/**
|
352
|
+
Optional flag if the result is an error or an error message.
|
353
|
+
*/
|
354
|
+
isError?: boolean;
|
355
|
+
}
|
356
|
+
|
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 = CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
362
|
+
/**
|
363
|
+
A user message. It can contain text or a combination of text and images.
|
364
|
+
*/
|
365
|
+
type CoreUserMessage = {
|
366
|
+
role: 'user';
|
367
|
+
content: UserContent;
|
368
|
+
};
|
369
|
+
/**
|
370
|
+
Content of a user message. It can be a string or an array of text and image parts.
|
371
|
+
*/
|
372
|
+
type UserContent = string | Array<TextPart | ImagePart>;
|
373
|
+
/**
|
374
|
+
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
375
|
+
*/
|
376
|
+
type CoreAssistantMessage = {
|
377
|
+
role: 'assistant';
|
378
|
+
content: AssistantContent;
|
379
|
+
};
|
380
|
+
/**
|
381
|
+
Content of an assistant message. It can be a string or an array of text and tool call parts.
|
382
|
+
*/
|
383
|
+
type AssistantContent = string | Array<TextPart | ToolCallPart>;
|
384
|
+
/**
|
385
|
+
A tool message. It contains the result of one or more tool calls.
|
386
|
+
*/
|
387
|
+
type CoreToolMessage = {
|
388
|
+
role: 'tool';
|
389
|
+
content: ToolContent;
|
390
|
+
};
|
391
|
+
/**
|
392
|
+
Content of a tool message. It is an array of tool result parts.
|
393
|
+
*/
|
394
|
+
type ToolContent = Array<ToolResultPart>;
|
395
|
+
|
396
|
+
/**
|
397
|
+
Prompt part of the AI function options. It contains a system message, a simple text prompt, or a list of messages.
|
398
|
+
*/
|
399
|
+
type Prompt = {
|
400
|
+
/**
|
401
|
+
System message to include in the prompt. Can be used with `prompt` or `messages`.
|
402
|
+
*/
|
403
|
+
system?: string;
|
404
|
+
/**
|
405
|
+
A simple text prompt. You can either use `prompt` or `messages` but not both.
|
406
|
+
*/
|
407
|
+
prompt?: string;
|
408
|
+
/**
|
409
|
+
A list of messsages. You can either use `prompt` or `messages` but not both.
|
410
|
+
*/
|
411
|
+
messages?: Array<CoreMessage>;
|
412
|
+
};
|
413
|
+
|
414
|
+
type Streamable = ReactNode | Promise<ReactNode>;
|
415
|
+
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
416
|
+
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
417
|
+
description?: string;
|
418
|
+
parameters: PARAMETERS;
|
419
|
+
generate?: Renderer<[
|
420
|
+
z.infer<PARAMETERS>,
|
421
|
+
{
|
422
|
+
toolName: string;
|
423
|
+
toolCallId: string;
|
424
|
+
}
|
425
|
+
]>;
|
426
|
+
};
|
427
|
+
type RenderText = Renderer<[
|
428
|
+
{
|
429
|
+
/**
|
430
|
+
* The full text content from the model so far.
|
431
|
+
*/
|
432
|
+
content: string;
|
433
|
+
/**
|
434
|
+
* The new appended text content from the model since the last `text` call.
|
435
|
+
*/
|
436
|
+
delta: string;
|
437
|
+
/**
|
438
|
+
* Whether the model is done generating text.
|
439
|
+
* If `true`, the `content` will be the final output and this call will be the last.
|
440
|
+
*/
|
441
|
+
done: boolean;
|
442
|
+
}
|
443
|
+
]>;
|
444
|
+
type RenderResult = {
|
445
|
+
value: ReactNode;
|
446
|
+
} & Awaited<ReturnType<LanguageModelV1['doStream']>>;
|
447
|
+
/**
|
448
|
+
* `streamUI` is a helper function to create a streamable UI from LLMs.
|
449
|
+
*/
|
450
|
+
declare function streamUI<TOOLS extends {
|
451
|
+
[name: string]: z.ZodTypeAny;
|
452
|
+
} = {}>({ model, tools, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
453
|
+
/**
|
454
|
+
* The language model to use.
|
455
|
+
*/
|
456
|
+
model: LanguageModelV1;
|
457
|
+
/**
|
458
|
+
* The tools that the model can call. The model needs to support calling tools.
|
459
|
+
*/
|
460
|
+
tools?: {
|
461
|
+
[name in keyof TOOLS]: RenderTool<TOOLS[name]>;
|
462
|
+
};
|
463
|
+
text?: RenderText;
|
464
|
+
initial?: ReactNode;
|
465
|
+
}): Promise<RenderResult>;
|
466
|
+
|
467
|
+
declare function createAI<AIState = any, UIState = any, Actions extends AIActions = {}>({ actions, initialAIState, initialUIState, onSetAIState, onGetUIState, }: {
|
151
468
|
actions: Actions;
|
152
469
|
initialAIState?: AIState;
|
153
470
|
initialUIState?: UIState;
|
154
|
-
|
155
|
-
|
471
|
+
/**
|
472
|
+
* This function is called whenever the AI state is updated by an Action.
|
473
|
+
* You can use this to persist the AI state to a database, or to send it to a
|
474
|
+
* logging service.
|
475
|
+
*/
|
476
|
+
onSetAIState?: OnSetAIState<AIState>;
|
477
|
+
/**
|
478
|
+
* This function is used to retrieve the UI state based on the AI state.
|
479
|
+
* For example, to render the initial UI state based on a given AI state, or
|
480
|
+
* to sync the UI state when the application is already loaded.
|
481
|
+
*
|
482
|
+
* If returning `undefined`, the client side UI state will not be updated.
|
483
|
+
*
|
484
|
+
* This function must be annotated with the `"use server"` directive.
|
485
|
+
*
|
486
|
+
* @example
|
487
|
+
* ```tsx
|
488
|
+
* onGetUIState: async () => {
|
489
|
+
* 'use server';
|
490
|
+
*
|
491
|
+
* const currentAIState = getAIState();
|
492
|
+
* const externalAIState = await loadAIStateFromDatabase();
|
493
|
+
*
|
494
|
+
* if (currentAIState === externalAIState) return undefined;
|
495
|
+
*
|
496
|
+
* // Update current AI state and return the new UI state
|
497
|
+
* const state = getMutableAIState()
|
498
|
+
* state.done(externalAIState)
|
499
|
+
*
|
500
|
+
* return <div>...</div>;
|
501
|
+
* }
|
502
|
+
* ```
|
503
|
+
*/
|
504
|
+
onGetUIState?: OnGetUIState<UIState>;
|
156
505
|
}): AIProvider<AIState, UIState, Actions>;
|
157
506
|
|
158
507
|
/**
|
@@ -186,6 +535,24 @@ declare function createAI<AIState = any, UIState = any, Actions extends AIAction
|
|
186
535
|
* This logs out 1, 2, 3 on console.
|
187
536
|
*/
|
188
537
|
declare function readStreamableValue<T = unknown>(streamableValue: StreamableValue<T>): AsyncIterable<T | undefined>;
|
538
|
+
/**
|
539
|
+
* `useStreamableValue` is a React hook that takes a streamable value created via the `createStreamableValue().value` API,
|
540
|
+
* and returns the current value, error, and pending state.
|
541
|
+
*
|
542
|
+
* This is useful for consuming streamable values received from a component's props. For example:
|
543
|
+
*
|
544
|
+
* ```js
|
545
|
+
* function MyComponent({ streamableValue }) {
|
546
|
+
* const [data, error, pending] = useStreamableValue(streamableValue);
|
547
|
+
*
|
548
|
+
* if (pending) return <div>Loading...</div>;
|
549
|
+
* if (error) return <div>Error: {error.message}</div>;
|
550
|
+
*
|
551
|
+
* return <div>Data: {data}</div>;
|
552
|
+
* }
|
553
|
+
* ```
|
554
|
+
*/
|
555
|
+
declare function useStreamableValue<T = unknown, Error = unknown>(streamableValue?: StreamableValue<T>): [data: T | undefined, error: Error | undefined, pending: boolean];
|
189
556
|
|
190
557
|
declare function useUIState<AI extends AIProvider = any>(): [InferUIState<AI, any>, (v: InferUIState<AI, any> | ((v_: InferUIState<AI, any>) => InferUIState<AI, any>)) => void];
|
191
558
|
declare function useAIState<AI extends AIProvider = any>(): [
|
@@ -199,4 +566,4 @@ declare function useAIState<AI extends AIProvider = any>(key: keyof InferAIState
|
|
199
566
|
declare function useActions<AI extends AIProvider = any>(): InferActions<AI, any>;
|
200
567
|
declare function useSyncUIState(): () => Promise<void>;
|
201
568
|
|
202
|
-
export { StreamableValue, createAI, createStreamableUI, createStreamableValue, getAIState, getMutableAIState, readStreamableValue, render, useAIState, useActions, useSyncUIState, useUIState };
|
569
|
+
export { StreamableValue, createAI, createStreamableUI, createStreamableValue, getAIState, getMutableAIState, readStreamableValue, render, streamUI, useAIState, useActions, useStreamableValue, useSyncUIState, useUIState };
|
@@ -1 +1 @@
|
|
1
|
-
export { readStreamableValue, useAIState, useActions, useSyncUIState, useUIState } from './rsc-shared.mjs';
|
1
|
+
export { readStreamableValue, useAIState, useActions, useStreamableValue, useSyncUIState, useUIState } from './rsc-shared.mjs';
|
package/rsc/dist/rsc-client.mjs
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
// rsc/rsc-client.ts
|
2
2
|
import {
|
3
3
|
readStreamableValue,
|
4
|
+
useStreamableValue,
|
4
5
|
useUIState,
|
5
6
|
useAIState,
|
6
7
|
useActions,
|
@@ -10,6 +11,7 @@ export {
|
|
10
11
|
readStreamableValue,
|
11
12
|
useAIState,
|
12
13
|
useActions,
|
14
|
+
useStreamableValue,
|
13
15
|
useSyncUIState,
|
14
16
|
useUIState
|
15
17
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../rsc-client.ts"],"sourcesContent":["export {\n readStreamableValue,\n useUIState,\n useAIState,\n useActions,\n useSyncUIState,\n} from './rsc-shared.mjs';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
1
|
+
{"version":3,"sources":["../rsc-client.ts"],"sourcesContent":["export {\n readStreamableValue,\n useStreamableValue,\n useUIState,\n useAIState,\n useActions,\n useSyncUIState,\n} from './rsc-shared.mjs';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|