@ai-sdk/react 0.0.40 → 0.0.42
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 +19 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/use-chat.ui.test.tsx +339 -322
- package/src/use-object.ts +10 -4
package/src/use-object.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { isAbortError } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { isAbortError, safeValidateTypes } from '@ai-sdk/provider-utils';
|
|
2
2
|
import {
|
|
3
|
+
asSchema,
|
|
3
4
|
DeepPartial,
|
|
4
5
|
FetchFunction,
|
|
5
6
|
isDeepEqualData,
|
|
6
7
|
parsePartialJson,
|
|
8
|
+
Schema,
|
|
7
9
|
} from '@ai-sdk/ui-utils';
|
|
8
10
|
import { useCallback, useId, useRef, useState } from 'react';
|
|
9
11
|
import useSWR from 'swr';
|
|
@@ -21,7 +23,7 @@ export type Experimental_UseObjectOptions<RESULT> = {
|
|
|
21
23
|
/**
|
|
22
24
|
* A Zod schema that defines the shape of the complete object.
|
|
23
25
|
*/
|
|
24
|
-
schema: z.Schema<RESULT, z.ZodTypeDef, any>;
|
|
26
|
+
schema: z.Schema<RESULT, z.ZodTypeDef, any> | Schema<RESULT>;
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* An unique identifier. If not provided, a random one will be
|
|
@@ -185,10 +187,14 @@ function useObject<RESULT, INPUT = any>({
|
|
|
185
187
|
abortControllerRef.current = null;
|
|
186
188
|
|
|
187
189
|
if (onFinish != null) {
|
|
188
|
-
const validationResult =
|
|
190
|
+
const validationResult = safeValidateTypes({
|
|
191
|
+
value: latestObject,
|
|
192
|
+
schema: asSchema(schema),
|
|
193
|
+
});
|
|
194
|
+
|
|
189
195
|
onFinish(
|
|
190
196
|
validationResult.success
|
|
191
|
-
? { object: validationResult.
|
|
197
|
+
? { object: validationResult.value, error: undefined }
|
|
192
198
|
: { object: undefined, error: validationResult.error },
|
|
193
199
|
);
|
|
194
200
|
}
|