@ai-sdk/react 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @ai-sdk/react@0.0.3 build /home/runner/work/ai/ai/packages/react
2
+ > @ai-sdk/react@0.0.5 build /home/runner/work/ai/ai/packages/react
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,13 +9,13 @@
9
9
  CLI Target: es2018
10
10
  CJS Build start
11
11
  ESM Build start
12
- CJS dist/index.js 20.18 KB
13
- CJS dist/index.js.map 40.03 KB
14
- CJS ⚡️ Build success in 72ms
15
- ESM dist/index.mjs 17.85 KB
16
- ESM dist/index.mjs.map 39.94 KB
17
- ESM ⚡️ Build success in 72ms
12
+ ESM dist/index.mjs 19.60 KB
13
+ ESM dist/index.mjs.map 44.24 KB
14
+ ESM ⚡️ Build success in 36ms
15
+ CJS dist/index.js 22.06 KB
16
+ CJS dist/index.js.map 44.36 KB
17
+ CJS ⚡️ Build success in 41ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 5034ms
20
- DTS dist/index.d.ts 7.36 KB
21
- DTS dist/index.d.mts 7.36 KB
19
+ DTS ⚡️ Build success in 4924ms
20
+ DTS dist/index.d.ts 8.76 KB
21
+ DTS dist/index.d.mts 8.76 KB
@@ -1,4 +1,4 @@
1
1
 
2
- > @ai-sdk/react@0.0.3 clean /home/runner/work/ai/ai/packages/react
2
+ > @ai-sdk/react@0.0.5 clean /home/runner/work/ai/ai/packages/react
3
3
  > rm -rf dist
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @ai-sdk/react
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [02f6a088]
8
+ - @ai-sdk/provider-utils@0.0.16
9
+ - @ai-sdk/ui-utils@0.0.5
10
+
11
+ ## 0.0.4
12
+
13
+ ### Patch Changes
14
+
15
+ - 008725ec: feat (@ai-sdk/react): add experimental_useObject to @ai-sdk/react
16
+ - Updated dependencies [008725ec]
17
+ - @ai-sdk/ui-utils@0.0.4
18
+
3
19
  ## 0.0.3
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,65 @@
1
- import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
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 UseAssistantHelpers = {
131
- /**
132
- * The current array of chat messages.
133
- */
134
- messages: Message[];
190
+ type Experimental_UseObjectOptions<RESULT> = {
135
191
  /**
136
- * Update the message store with a new array of messages.
192
+ * The API endpoint. It should stream JSON that matches the schema as chunked text.
137
193
  */
138
- setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
194
+ api: string;
139
195
  /**
140
- * The current thread ID.
196
+ * A Zod schema that defines the shape of the complete object.
141
197
  */
142
- threadId: string | undefined;
198
+ schema: z.Schema<RESULT>;
143
199
  /**
144
- * The current value of the input field.
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
- input: string;
204
+ id?: string;
147
205
  /**
148
- * Append a user message to the chat list. This triggers the API call to fetch
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
- append: (message: Message | CreateMessage, requestOptions?: {
154
- data?: Record<string, string>;
155
- }) => Promise<void>;
208
+ initialValue?: DeepPartial<RESULT>;
209
+ };
210
+ type Experimental_UseObjectHelpers<RESULT, INPUT> = {
156
211
  /**
157
- Abort the current request immediately, keep the generated tokens if any.
212
+ * Calls the API with the provided input as JSON body.
158
213
  */
159
- stop: () => void;
214
+ setInput: (input: INPUT) => void;
160
215
  /**
161
- * setState-powered method to update the input value.
216
+ * The current value for the generated object. Updated as the API streams JSON chunks.
162
217
  */
163
- setInput: React.Dispatch<React.SetStateAction<string>>;
218
+ object: DeepPartial<RESULT> | undefined;
164
219
  /**
165
- * Handler for the `onChange` event of the input field to control the input's value.
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 useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
184
- /**
185
- @deprecated Use `useAssistant` instead.
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, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
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 UseAssistantHelpers = {
131
- /**
132
- * The current array of chat messages.
133
- */
134
- messages: Message[];
190
+ type Experimental_UseObjectOptions<RESULT> = {
135
191
  /**
136
- * Update the message store with a new array of messages.
192
+ * The API endpoint. It should stream JSON that matches the schema as chunked text.
137
193
  */
138
- setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
194
+ api: string;
139
195
  /**
140
- * The current thread ID.
196
+ * A Zod schema that defines the shape of the complete object.
141
197
  */
142
- threadId: string | undefined;
198
+ schema: z.Schema<RESULT>;
143
199
  /**
144
- * The current value of the input field.
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
- input: string;
204
+ id?: string;
147
205
  /**
148
- * Append a user message to the chat list. This triggers the API call to fetch
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
- append: (message: Message | CreateMessage, requestOptions?: {
154
- data?: Record<string, string>;
155
- }) => Promise<void>;
208
+ initialValue?: DeepPartial<RESULT>;
209
+ };
210
+ type Experimental_UseObjectHelpers<RESULT, INPUT> = {
156
211
  /**
157
- Abort the current request immediately, keep the generated tokens if any.
212
+ * Calls the API with the provided input as JSON body.
158
213
  */
159
- stop: () => void;
214
+ setInput: (input: INPUT) => void;
160
215
  /**
161
- * setState-powered method to update the input value.
216
+ * The current value for the generated object. Updated as the API streams JSON chunks.
162
217
  */
163
- setInput: React.Dispatch<React.SetStateAction<string>>;
218
+ object: DeepPartial<RESULT> | undefined;
164
219
  /**
165
- * Handler for the `onChange` event of the input field to control the input's value.
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 useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
184
- /**
185
- @deprecated Use `useAssistant` instead.
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 };