@ai-sdk/react 0.0.2 → 0.0.4
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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-clean.log +1 -1
- package/CHANGELOG.md +17 -0
- package/dist/index.d.mts +83 -44
- package/dist/index.d.ts +83 -44
- package/dist/index.js +247 -182
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -173
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -4
- package/src/index.ts +2 -1
- package/src/use-assistant.ui.test.tsx +1 -1
- package/src/use-object.ts +123 -0
- package/src/use-object.ui.test.tsx +79 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @ai-sdk/react@0.0.
|
|
2
|
+
> @ai-sdk/react@0.0.4 build /home/runner/work/ai/ai/packages/react
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[34mCLI[39m Target: es2018
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
15
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
16
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
17
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m19.60 KB[39m
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m44.24 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 59ms
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m22.06 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m44.36 KB[39m
|
|
17
|
+
[32mCJS[39m ⚡️ Build success in 65ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 4971ms
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m8.76 KB[39m
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m8.76 KB[39m
|
package/.turbo/turbo-clean.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/react
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 008725ec: feat (@ai-sdk/react): add experimental_useObject to @ai-sdk/react
|
|
8
|
+
- Updated dependencies [008725ec]
|
|
9
|
+
- @ai-sdk/ui-utils@0.0.4
|
|
10
|
+
|
|
11
|
+
## 0.0.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [85712895]
|
|
16
|
+
- Updated dependencies [85712895]
|
|
17
|
+
- @ai-sdk/provider-utils@0.0.15
|
|
18
|
+
- @ai-sdk/ui-utils@0.0.3
|
|
19
|
+
|
|
3
20
|
## 0.0.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
|
-
import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions,
|
|
1
|
+
import { Message, CreateMessage, AssistantStatus, UseAssistantOptions, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, DeepPartial } from '@ai-sdk/ui-utils';
|
|
2
2
|
export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
|
|
5
|
+
type UseAssistantHelpers = {
|
|
6
|
+
/**
|
|
7
|
+
* The current array of chat messages.
|
|
8
|
+
*/
|
|
9
|
+
messages: Message[];
|
|
10
|
+
/**
|
|
11
|
+
* Update the message store with a new array of messages.
|
|
12
|
+
*/
|
|
13
|
+
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
14
|
+
/**
|
|
15
|
+
* The current thread ID.
|
|
16
|
+
*/
|
|
17
|
+
threadId: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The current value of the input field.
|
|
20
|
+
*/
|
|
21
|
+
input: string;
|
|
22
|
+
/**
|
|
23
|
+
* Append a user message to the chat list. This triggers the API call to fetch
|
|
24
|
+
* the assistant's response.
|
|
25
|
+
* @param message The message to append
|
|
26
|
+
* @param requestOptions Additional options to pass to the API call
|
|
27
|
+
*/
|
|
28
|
+
append: (message: Message | CreateMessage, requestOptions?: {
|
|
29
|
+
data?: Record<string, string>;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
Abort the current request immediately, keep the generated tokens if any.
|
|
33
|
+
*/
|
|
34
|
+
stop: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* setState-powered method to update the input value.
|
|
37
|
+
*/
|
|
38
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
39
|
+
/**
|
|
40
|
+
* Handler for the `onChange` event of the input field to control the input's value.
|
|
41
|
+
*/
|
|
42
|
+
handleInputChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Form submission handler that automatically resets the input field and appends a user message.
|
|
45
|
+
*/
|
|
46
|
+
submitMessage: (event?: React.FormEvent<HTMLFormElement>, requestOptions?: {
|
|
47
|
+
data?: Record<string, string>;
|
|
48
|
+
}) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* The current status of the assistant. This can be used to show a loading indicator.
|
|
51
|
+
*/
|
|
52
|
+
status: AssistantStatus;
|
|
53
|
+
/**
|
|
54
|
+
* The error thrown during the assistant message processing, if any.
|
|
55
|
+
*/
|
|
56
|
+
error: undefined | unknown;
|
|
57
|
+
};
|
|
58
|
+
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
|
|
59
|
+
/**
|
|
60
|
+
@deprecated Use `useAssistant` instead.
|
|
61
|
+
*/
|
|
62
|
+
declare const experimental_useAssistant: typeof useAssistant;
|
|
3
63
|
|
|
4
64
|
type UseChatHelpers = {
|
|
5
65
|
/** Current messages in the chat */
|
|
@@ -127,63 +187,42 @@ type UseCompletionHelpers = {
|
|
|
127
187
|
};
|
|
128
188
|
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
|
|
129
189
|
|
|
130
|
-
type
|
|
131
|
-
/**
|
|
132
|
-
* The current array of chat messages.
|
|
133
|
-
*/
|
|
134
|
-
messages: Message[];
|
|
190
|
+
type Experimental_UseObjectOptions<RESULT> = {
|
|
135
191
|
/**
|
|
136
|
-
*
|
|
192
|
+
* The API endpoint. It should stream JSON that matches the schema as chunked text.
|
|
137
193
|
*/
|
|
138
|
-
|
|
194
|
+
api: string;
|
|
139
195
|
/**
|
|
140
|
-
*
|
|
196
|
+
* A Zod schema that defines the shape of the complete object.
|
|
141
197
|
*/
|
|
142
|
-
|
|
198
|
+
schema: z.Schema<RESULT>;
|
|
143
199
|
/**
|
|
144
|
-
*
|
|
200
|
+
* An unique identifier. If not provided, a random one will be
|
|
201
|
+
* generated. When provided, the `useObject` hook with the same `id` will
|
|
202
|
+
* have shared states across components.
|
|
145
203
|
*/
|
|
146
|
-
|
|
204
|
+
id?: string;
|
|
147
205
|
/**
|
|
148
|
-
*
|
|
149
|
-
* the assistant's response.
|
|
150
|
-
* @param message The message to append
|
|
151
|
-
* @param requestOptions Additional options to pass to the API call
|
|
206
|
+
* An optional value for the initial object.
|
|
152
207
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
208
|
+
initialValue?: DeepPartial<RESULT>;
|
|
209
|
+
};
|
|
210
|
+
type Experimental_UseObjectHelpers<RESULT, INPUT> = {
|
|
156
211
|
/**
|
|
157
|
-
|
|
212
|
+
* Calls the API with the provided input as JSON body.
|
|
158
213
|
*/
|
|
159
|
-
|
|
214
|
+
setInput: (input: INPUT) => void;
|
|
160
215
|
/**
|
|
161
|
-
*
|
|
216
|
+
* The current value for the generated object. Updated as the API streams JSON chunks.
|
|
162
217
|
*/
|
|
163
|
-
|
|
218
|
+
object: DeepPartial<RESULT> | undefined;
|
|
164
219
|
/**
|
|
165
|
-
*
|
|
166
|
-
*/
|
|
167
|
-
handleInputChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
168
|
-
/**
|
|
169
|
-
* Form submission handler that automatically resets the input field and appends a user message.
|
|
170
|
-
*/
|
|
171
|
-
submitMessage: (event?: React.FormEvent<HTMLFormElement>, requestOptions?: {
|
|
172
|
-
data?: Record<string, string>;
|
|
173
|
-
}) => Promise<void>;
|
|
174
|
-
/**
|
|
175
|
-
* The current status of the assistant. This can be used to show a loading indicator.
|
|
176
|
-
*/
|
|
177
|
-
status: AssistantStatus;
|
|
178
|
-
/**
|
|
179
|
-
* The error thrown during the assistant message processing, if any.
|
|
220
|
+
* The error object of the API request if any.
|
|
180
221
|
*/
|
|
181
222
|
error: undefined | unknown;
|
|
182
223
|
};
|
|
183
|
-
declare function
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*/
|
|
187
|
-
declare const experimental_useAssistant: typeof useAssistant;
|
|
224
|
+
declare function useObject<RESULT, INPUT = any>({ api, id, schema, // required, in the future we will use it for validation
|
|
225
|
+
initialValue, }: Experimental_UseObjectOptions<RESULT>): Experimental_UseObjectHelpers<RESULT, INPUT>;
|
|
226
|
+
declare const experimental_useObject: typeof useObject;
|
|
188
227
|
|
|
189
|
-
export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, experimental_useAssistant, useAssistant, useChat, useCompletion };
|
|
228
|
+
export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, experimental_useAssistant, experimental_useObject, useAssistant, useChat, useCompletion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
|
-
import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions,
|
|
1
|
+
import { Message, CreateMessage, AssistantStatus, UseAssistantOptions, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, DeepPartial } from '@ai-sdk/ui-utils';
|
|
2
2
|
export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
|
|
5
|
+
type UseAssistantHelpers = {
|
|
6
|
+
/**
|
|
7
|
+
* The current array of chat messages.
|
|
8
|
+
*/
|
|
9
|
+
messages: Message[];
|
|
10
|
+
/**
|
|
11
|
+
* Update the message store with a new array of messages.
|
|
12
|
+
*/
|
|
13
|
+
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
14
|
+
/**
|
|
15
|
+
* The current thread ID.
|
|
16
|
+
*/
|
|
17
|
+
threadId: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The current value of the input field.
|
|
20
|
+
*/
|
|
21
|
+
input: string;
|
|
22
|
+
/**
|
|
23
|
+
* Append a user message to the chat list. This triggers the API call to fetch
|
|
24
|
+
* the assistant's response.
|
|
25
|
+
* @param message The message to append
|
|
26
|
+
* @param requestOptions Additional options to pass to the API call
|
|
27
|
+
*/
|
|
28
|
+
append: (message: Message | CreateMessage, requestOptions?: {
|
|
29
|
+
data?: Record<string, string>;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
Abort the current request immediately, keep the generated tokens if any.
|
|
33
|
+
*/
|
|
34
|
+
stop: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* setState-powered method to update the input value.
|
|
37
|
+
*/
|
|
38
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
39
|
+
/**
|
|
40
|
+
* Handler for the `onChange` event of the input field to control the input's value.
|
|
41
|
+
*/
|
|
42
|
+
handleInputChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Form submission handler that automatically resets the input field and appends a user message.
|
|
45
|
+
*/
|
|
46
|
+
submitMessage: (event?: React.FormEvent<HTMLFormElement>, requestOptions?: {
|
|
47
|
+
data?: Record<string, string>;
|
|
48
|
+
}) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* The current status of the assistant. This can be used to show a loading indicator.
|
|
51
|
+
*/
|
|
52
|
+
status: AssistantStatus;
|
|
53
|
+
/**
|
|
54
|
+
* The error thrown during the assistant message processing, if any.
|
|
55
|
+
*/
|
|
56
|
+
error: undefined | unknown;
|
|
57
|
+
};
|
|
58
|
+
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
|
|
59
|
+
/**
|
|
60
|
+
@deprecated Use `useAssistant` instead.
|
|
61
|
+
*/
|
|
62
|
+
declare const experimental_useAssistant: typeof useAssistant;
|
|
3
63
|
|
|
4
64
|
type UseChatHelpers = {
|
|
5
65
|
/** Current messages in the chat */
|
|
@@ -127,63 +187,42 @@ type UseCompletionHelpers = {
|
|
|
127
187
|
};
|
|
128
188
|
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
|
|
129
189
|
|
|
130
|
-
type
|
|
131
|
-
/**
|
|
132
|
-
* The current array of chat messages.
|
|
133
|
-
*/
|
|
134
|
-
messages: Message[];
|
|
190
|
+
type Experimental_UseObjectOptions<RESULT> = {
|
|
135
191
|
/**
|
|
136
|
-
*
|
|
192
|
+
* The API endpoint. It should stream JSON that matches the schema as chunked text.
|
|
137
193
|
*/
|
|
138
|
-
|
|
194
|
+
api: string;
|
|
139
195
|
/**
|
|
140
|
-
*
|
|
196
|
+
* A Zod schema that defines the shape of the complete object.
|
|
141
197
|
*/
|
|
142
|
-
|
|
198
|
+
schema: z.Schema<RESULT>;
|
|
143
199
|
/**
|
|
144
|
-
*
|
|
200
|
+
* An unique identifier. If not provided, a random one will be
|
|
201
|
+
* generated. When provided, the `useObject` hook with the same `id` will
|
|
202
|
+
* have shared states across components.
|
|
145
203
|
*/
|
|
146
|
-
|
|
204
|
+
id?: string;
|
|
147
205
|
/**
|
|
148
|
-
*
|
|
149
|
-
* the assistant's response.
|
|
150
|
-
* @param message The message to append
|
|
151
|
-
* @param requestOptions Additional options to pass to the API call
|
|
206
|
+
* An optional value for the initial object.
|
|
152
207
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
208
|
+
initialValue?: DeepPartial<RESULT>;
|
|
209
|
+
};
|
|
210
|
+
type Experimental_UseObjectHelpers<RESULT, INPUT> = {
|
|
156
211
|
/**
|
|
157
|
-
|
|
212
|
+
* Calls the API with the provided input as JSON body.
|
|
158
213
|
*/
|
|
159
|
-
|
|
214
|
+
setInput: (input: INPUT) => void;
|
|
160
215
|
/**
|
|
161
|
-
*
|
|
216
|
+
* The current value for the generated object. Updated as the API streams JSON chunks.
|
|
162
217
|
*/
|
|
163
|
-
|
|
218
|
+
object: DeepPartial<RESULT> | undefined;
|
|
164
219
|
/**
|
|
165
|
-
*
|
|
166
|
-
*/
|
|
167
|
-
handleInputChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
168
|
-
/**
|
|
169
|
-
* Form submission handler that automatically resets the input field and appends a user message.
|
|
170
|
-
*/
|
|
171
|
-
submitMessage: (event?: React.FormEvent<HTMLFormElement>, requestOptions?: {
|
|
172
|
-
data?: Record<string, string>;
|
|
173
|
-
}) => Promise<void>;
|
|
174
|
-
/**
|
|
175
|
-
* The current status of the assistant. This can be used to show a loading indicator.
|
|
176
|
-
*/
|
|
177
|
-
status: AssistantStatus;
|
|
178
|
-
/**
|
|
179
|
-
* The error thrown during the assistant message processing, if any.
|
|
220
|
+
* The error object of the API request if any.
|
|
180
221
|
*/
|
|
181
222
|
error: undefined | unknown;
|
|
182
223
|
};
|
|
183
|
-
declare function
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*/
|
|
187
|
-
declare const experimental_useAssistant: typeof useAssistant;
|
|
224
|
+
declare function useObject<RESULT, INPUT = any>({ api, id, schema, // required, in the future we will use it for validation
|
|
225
|
+
initialValue, }: Experimental_UseObjectOptions<RESULT>): Experimental_UseObjectHelpers<RESULT, INPUT>;
|
|
226
|
+
declare const experimental_useObject: typeof useObject;
|
|
188
227
|
|
|
189
|
-
export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, experimental_useAssistant, useAssistant, useChat, useCompletion };
|
|
228
|
+
export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, experimental_useAssistant, experimental_useObject, useAssistant, useChat, useCompletion };
|