ai 3.3.6 → 3.3.7
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 +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +24 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +186 -183
- package/rsc/dist/rsc-server.d.mts +185 -183
- package/rsc/dist/rsc-server.mjs +789 -786
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +24 -22
- package/rsc/dist/rsc-shared.mjs +46 -60
- package/rsc/dist/rsc-shared.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "3.3.
|
3
|
+
"version": "3.3.7",
|
4
4
|
"description": "Vercel AI SDK - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -58,13 +58,13 @@
|
|
58
58
|
}
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@ai-sdk/provider": "0.0.
|
62
|
-
"@ai-sdk/provider-utils": "1.0.
|
63
|
-
"@ai-sdk/react": "0.0.
|
64
|
-
"@ai-sdk/solid": "0.0.
|
65
|
-
"@ai-sdk/svelte": "0.0.
|
66
|
-
"@ai-sdk/ui-utils": "0.0.
|
67
|
-
"@ai-sdk/vue": "0.0.
|
61
|
+
"@ai-sdk/provider": "0.0.19",
|
62
|
+
"@ai-sdk/provider-utils": "1.0.11",
|
63
|
+
"@ai-sdk/react": "0.0.43",
|
64
|
+
"@ai-sdk/solid": "0.0.34",
|
65
|
+
"@ai-sdk/svelte": "0.0.36",
|
66
|
+
"@ai-sdk/ui-utils": "0.0.31",
|
67
|
+
"@ai-sdk/vue": "0.0.35",
|
68
68
|
"@opentelemetry/api": "1.9.0",
|
69
69
|
"eventsource-parser": "1.1.2",
|
70
70
|
"jsondiffpatch": "0.6.0",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1 } from '@ai-sdk/provider';
|
2
2
|
import { ReactNode } from 'react';
|
3
3
|
import { z } from 'zod';
|
4
|
-
import
|
4
|
+
import OpenAI from 'openai';
|
5
5
|
|
6
6
|
type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;
|
7
7
|
type AIActions<T = any, R = any> = Record<string, AIAction<T, R>>;
|
@@ -28,16 +28,6 @@ type MutableAIState<AIState> = {
|
|
28
28
|
update: (newState: ValueOrUpdater<AIState>) => void;
|
29
29
|
done: ((newState: AIState) => void) | (() => void);
|
30
30
|
};
|
31
|
-
declare const __internal_curr: unique symbol;
|
32
|
-
declare const __internal_error: unique symbol;
|
33
|
-
/**
|
34
|
-
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
35
|
-
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
36
|
-
*/
|
37
|
-
type StreamableValue<T = any, E = any> = {
|
38
|
-
[__internal_curr]?: T;
|
39
|
-
[__internal_error]?: E;
|
40
|
-
};
|
41
31
|
|
42
32
|
/**
|
43
33
|
* Get the current AI state.
|
@@ -70,156 +60,45 @@ declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState
|
|
70
60
|
declare function getMutableAIState<AI extends AIProvider = any>(): MutableAIState<InferAIState<AI, any>>;
|
71
61
|
declare function getMutableAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): MutableAIState<InferAIState<AI, any>[typeof key]>;
|
72
62
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
readonly value: React.ReactNode;
|
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): StreamableUIWrapper;
|
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): StreamableUIWrapper;
|
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] | []): StreamableUIWrapper;
|
111
|
-
};
|
112
|
-
/**
|
113
|
-
* Create a piece of changeable UI that can be streamed to the client.
|
114
|
-
* On the client side, it can be rendered as a normal React node.
|
115
|
-
*/
|
116
|
-
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
|
117
|
-
/**
|
118
|
-
* Create a wrapped, changeable value that can be streamed to the client.
|
119
|
-
* On the client side, the value can be accessed via the readStreamableValue() API.
|
120
|
-
*/
|
121
|
-
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
|
122
|
-
type StreamableValueWrapper<T, E> = {
|
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): StreamableValueWrapper<T, E>;
|
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): StreamableValueWrapper<T, E>;
|
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): StreamableValueWrapper<T, E>;
|
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] | []): StreamableValueWrapper<T, E>;
|
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
|
/**
|
@@ -488,12 +367,12 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
488
367
|
toolName: keyof TOOLS;
|
489
368
|
};
|
490
369
|
|
491
|
-
type Streamable = ReactNode | Promise<ReactNode>;
|
492
|
-
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
370
|
+
type Streamable$1 = ReactNode | Promise<ReactNode>;
|
371
|
+
type Renderer$1<T extends Array<any>> = (...args: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
|
493
372
|
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
494
373
|
description?: string;
|
495
374
|
parameters: PARAMETERS;
|
496
|
-
generate?: Renderer<[
|
375
|
+
generate?: Renderer$1<[
|
497
376
|
z.infer<PARAMETERS>,
|
498
377
|
{
|
499
378
|
toolName: string;
|
@@ -501,7 +380,7 @@ type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
|
501
380
|
}
|
502
381
|
]>;
|
503
382
|
};
|
504
|
-
type RenderText = Renderer<[
|
383
|
+
type RenderText = Renderer$1<[
|
505
384
|
{
|
506
385
|
/**
|
507
386
|
* The full text content from the model so far.
|
@@ -575,45 +454,168 @@ declare function streamUI<TOOLS extends {
|
|
575
454
|
}) => Promise<void> | void;
|
576
455
|
}): Promise<RenderResult>;
|
577
456
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
457
|
+
type Streamable = ReactNode | Promise<ReactNode>;
|
458
|
+
type Renderer<T> = (props: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
459
|
+
/**
|
460
|
+
* `render` is a helper function to create a streamable UI from some LLMs.
|
461
|
+
* This API only supports OpenAI's GPT models with Function Calling and Assistants Tools,
|
462
|
+
* please use `streamUI` for compatibility with other providers.
|
463
|
+
*
|
464
|
+
* @deprecated It's recommended to use the `streamUI` API for compatibility with AI SDK Core APIs
|
465
|
+
* and future features. This API will be removed in a future release.
|
466
|
+
*/
|
467
|
+
declare function render<TS extends {
|
468
|
+
[name: string]: z.Schema;
|
469
|
+
} = {}, FS extends {
|
470
|
+
[name: string]: z.Schema;
|
471
|
+
} = {}>(options: {
|
582
472
|
/**
|
583
|
-
*
|
584
|
-
*
|
585
|
-
*
|
473
|
+
* The model name to use. Must be OpenAI SDK compatible. Tools and Functions are only supported
|
474
|
+
* GPT models (3.5/4), OpenAI Assistants, Mistral small and large, and Fireworks firefunction-v1.
|
475
|
+
*
|
476
|
+
* @example "gpt-3.5-turbo"
|
586
477
|
*/
|
587
|
-
|
478
|
+
model: string;
|
588
479
|
/**
|
589
|
-
*
|
590
|
-
*
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
480
|
+
* The provider instance to use. Currently the only provider available is OpenAI.
|
481
|
+
* This needs to match the model name.
|
482
|
+
*/
|
483
|
+
provider: OpenAI;
|
484
|
+
messages: Parameters<typeof OpenAI.prototype.chat.completions.create>[0]['messages'];
|
485
|
+
text?: Renderer<{
|
486
|
+
/**
|
487
|
+
* The full text content from the model so far.
|
488
|
+
*/
|
489
|
+
content: string;
|
490
|
+
/**
|
491
|
+
* The new appended text content from the model since the last `text` call.
|
492
|
+
*/
|
493
|
+
delta: string;
|
494
|
+
/**
|
495
|
+
* Whether the model is done generating text.
|
496
|
+
* If `true`, the `content` will be the final output and this call will be the last.
|
497
|
+
*/
|
498
|
+
done: boolean;
|
499
|
+
}>;
|
500
|
+
tools?: {
|
501
|
+
[name in keyof TS]: {
|
502
|
+
description?: string;
|
503
|
+
parameters: TS[name];
|
504
|
+
render: Renderer<z.infer<TS[name]>>;
|
505
|
+
};
|
506
|
+
};
|
507
|
+
functions?: {
|
508
|
+
[name in keyof FS]: {
|
509
|
+
description?: string;
|
510
|
+
parameters: FS[name];
|
511
|
+
render: Renderer<z.infer<FS[name]>>;
|
512
|
+
};
|
513
|
+
};
|
514
|
+
initial?: ReactNode;
|
515
|
+
temperature?: number;
|
516
|
+
}): ReactNode;
|
517
|
+
|
518
|
+
type StreamableUIWrapper = {
|
519
|
+
/**
|
520
|
+
* The value of the streamable UI. This can be returned from a Server Action and received by the client.
|
521
|
+
*/
|
522
|
+
readonly value: React.ReactNode;
|
523
|
+
/**
|
524
|
+
* This method updates the current UI node. It takes a new UI node and replaces the old one.
|
525
|
+
*/
|
526
|
+
update(value: React.ReactNode): StreamableUIWrapper;
|
527
|
+
/**
|
528
|
+
* This method is used to append a new UI node to the end of the old one.
|
529
|
+
* Once appended a new UI node, the previous UI node cannot be updated anymore.
|
596
530
|
*
|
597
531
|
* @example
|
598
|
-
* ```
|
599
|
-
*
|
600
|
-
*
|
532
|
+
* ```jsx
|
533
|
+
* const ui = createStreamableUI(<div>hello</div>)
|
534
|
+
* ui.append(<div>world</div>)
|
601
535
|
*
|
602
|
-
*
|
603
|
-
*
|
536
|
+
* // The UI node will be:
|
537
|
+
* // <>
|
538
|
+
* // <div>hello</div>
|
539
|
+
* // <div>world</div>
|
540
|
+
* // </>
|
541
|
+
* ```
|
542
|
+
*/
|
543
|
+
append(value: React.ReactNode): StreamableUIWrapper;
|
544
|
+
/**
|
545
|
+
* This method is used to signal that there is an error in the UI stream.
|
546
|
+
* It will be thrown on the client side and caught by the nearest error boundary component.
|
547
|
+
*/
|
548
|
+
error(error: any): StreamableUIWrapper;
|
549
|
+
/**
|
550
|
+
* 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.
|
551
|
+
* Once called, the UI node cannot be updated or appended anymore.
|
604
552
|
*
|
605
|
-
*
|
553
|
+
* This method is always **required** to be called, otherwise the response will be stuck in a loading state.
|
554
|
+
*/
|
555
|
+
done(...args: [React.ReactNode] | []): StreamableUIWrapper;
|
556
|
+
};
|
557
|
+
/**
|
558
|
+
* Create a piece of changeable UI that can be streamed to the client.
|
559
|
+
* On the client side, it can be rendered as a normal React node.
|
560
|
+
*/
|
561
|
+
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
|
562
|
+
|
563
|
+
declare const __internal_curr: unique symbol;
|
564
|
+
declare const __internal_error: unique symbol;
|
565
|
+
/**
|
566
|
+
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
567
|
+
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
568
|
+
*/
|
569
|
+
type StreamableValue<T = any, E = any> = {
|
570
|
+
[__internal_curr]?: T;
|
571
|
+
[__internal_error]?: E;
|
572
|
+
};
|
573
|
+
|
574
|
+
/**
|
575
|
+
* Create a wrapped, changeable value that can be streamed to the client.
|
576
|
+
* On the client side, the value can be accessed via the readStreamableValue() API.
|
577
|
+
*/
|
578
|
+
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
|
579
|
+
type StreamableValueWrapper<T, E> = {
|
580
|
+
/**
|
581
|
+
* The value of the streamable. This can be returned from a Server Action and
|
582
|
+
* received by the client. To read the streamed values, use the
|
583
|
+
* `readStreamableValue` or `useStreamableValue` APIs.
|
584
|
+
*/
|
585
|
+
readonly value: StreamableValue<T, E>;
|
586
|
+
/**
|
587
|
+
* This method updates the current value with a new one.
|
588
|
+
*/
|
589
|
+
update(value: T): StreamableValueWrapper<T, E>;
|
590
|
+
/**
|
591
|
+
* This method is used to append a delta string to the current value. It
|
592
|
+
* requires the current value of the streamable to be a string.
|
606
593
|
*
|
607
|
-
*
|
608
|
-
*
|
609
|
-
*
|
594
|
+
* @example
|
595
|
+
* ```jsx
|
596
|
+
* const streamable = createStreamableValue('hello');
|
597
|
+
* streamable.append(' world');
|
610
598
|
*
|
611
|
-
*
|
612
|
-
* }
|
599
|
+
* // The value will be 'hello world'
|
613
600
|
* ```
|
614
601
|
*/
|
615
|
-
|
616
|
-
|
602
|
+
append(value: T): StreamableValueWrapper<T, E>;
|
603
|
+
/**
|
604
|
+
* This method is used to signal that there is an error in the value stream.
|
605
|
+
* It will be thrown on the client side when consumed via
|
606
|
+
* `readStreamableValue` or `useStreamableValue`.
|
607
|
+
*/
|
608
|
+
error(error: any): StreamableValueWrapper<T, E>;
|
609
|
+
/**
|
610
|
+
* This method marks the value as finalized. You can either call it without
|
611
|
+
* any parameters or with a new value as the final state.
|
612
|
+
* Once called, the value cannot be updated or appended anymore.
|
613
|
+
*
|
614
|
+
* This method is always **required** to be called, otherwise the response
|
615
|
+
* will be stuck in a loading state.
|
616
|
+
*/
|
617
|
+
done(...args: [T] | []): StreamableValueWrapper<T, E>;
|
618
|
+
};
|
617
619
|
|
618
620
|
/**
|
619
621
|
* `readStreamableValue` takes a streamable value created via the `createStreamableValue().value` API,
|
@@ -646,6 +648,7 @@ declare function createAI<AIState = any, UIState = any, Actions extends AIAction
|
|
646
648
|
* This logs out 1, 2, 3 on console.
|
647
649
|
*/
|
648
650
|
declare function readStreamableValue<T = unknown>(streamableValue: StreamableValue<T>): AsyncIterable<T | undefined>;
|
651
|
+
|
649
652
|
/**
|
650
653
|
* `useStreamableValue` is a React hook that takes a streamable value created via the `createStreamableValue().value` API,
|
651
654
|
* and returns the current value, error, and pending state.
|