@assistant-ui/react 0.12.14 → 0.12.15
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/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +143 -38
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +21 -9
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarInteractionContext.d.ts +6 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.d.ts.map +1 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.js +5 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.js.map +1 -0
- package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js +18 -4
- package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts +2 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.js +3 -2
- package/dist/primitives/actionBar/useActionBarFloatStatus.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js +35 -2
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -1
- package/dist/utils/json/is-json-equal.d.ts +2 -0
- package/dist/utils/json/is-json-equal.d.ts.map +1 -0
- package/dist/utils/json/is-json-equal.js +31 -0
- package/dist/utils/json/is-json-equal.js.map +1 -0
- package/dist/utils/json/is-json.d.ts +1 -0
- package/dist/utils/json/is-json.d.ts.map +1 -1
- package/dist/utils/json/is-json.js +5 -3
- package/dist/utils/json/is-json.js.map +1 -1
- package/package.json +6 -6
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.test.ts +225 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +191 -50
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts +28 -10
- package/src/primitives/actionBar/ActionBarInteractionContext.ts +13 -0
- package/src/primitives/actionBar/ActionBarRoot.tsx +38 -8
- package/src/primitives/actionBar/useActionBarFloatStatus.ts +4 -1
- package/src/primitives/actionBarMore/ActionBarMoreRoot.tsx +52 -2
- package/src/tests/external-message-converter.test.ts +80 -0
- package/src/utils/json/is-json-equal.ts +48 -0
- package/src/utils/json/is-json.ts +6 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
2
|
+
import { isJSONValue, isRecord } from "./is-json";
|
|
3
|
+
|
|
4
|
+
const MAX_JSON_DEPTH = 100;
|
|
5
|
+
|
|
6
|
+
const isJSONValueEqualAtDepth = (
|
|
7
|
+
a: ReadonlyJSONValue,
|
|
8
|
+
b: ReadonlyJSONValue,
|
|
9
|
+
currentDepth: number,
|
|
10
|
+
): boolean => {
|
|
11
|
+
if (a === b) return true;
|
|
12
|
+
if (currentDepth > MAX_JSON_DEPTH) return false;
|
|
13
|
+
|
|
14
|
+
if (a == null || b == null) return false;
|
|
15
|
+
|
|
16
|
+
if (Array.isArray(a)) {
|
|
17
|
+
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
18
|
+
return a.every((item, index) =>
|
|
19
|
+
isJSONValueEqualAtDepth(
|
|
20
|
+
item,
|
|
21
|
+
b[index] as ReadonlyJSONValue,
|
|
22
|
+
currentDepth + 1,
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(b)) return false;
|
|
28
|
+
if (!isRecord(a) || !isRecord(b)) return false;
|
|
29
|
+
|
|
30
|
+
const aKeys = Object.keys(a);
|
|
31
|
+
const bKeys = Object.keys(b);
|
|
32
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
33
|
+
|
|
34
|
+
return aKeys.every(
|
|
35
|
+
(key) =>
|
|
36
|
+
Object.hasOwn(b, key) &&
|
|
37
|
+
isJSONValueEqualAtDepth(
|
|
38
|
+
a[key] as ReadonlyJSONValue,
|
|
39
|
+
b[key] as ReadonlyJSONValue,
|
|
40
|
+
currentDepth + 1,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const isJSONValueEqual = (a: unknown, b: unknown): boolean => {
|
|
46
|
+
if (!isJSONValue(a) || !isJSONValue(b)) return false;
|
|
47
|
+
return isJSONValueEqualAtDepth(a, b, 0);
|
|
48
|
+
};
|
|
@@ -4,6 +4,10 @@ import {
|
|
|
4
4
|
ReadonlyJSONValue,
|
|
5
5
|
} from "assistant-stream/utils";
|
|
6
6
|
|
|
7
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
8
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function isJSONValue(
|
|
8
12
|
value: unknown,
|
|
9
13
|
currentDepth: number = 0,
|
|
@@ -30,7 +34,7 @@ export function isJSONValue(
|
|
|
30
34
|
return value.every((item) => isJSONValue(item, currentDepth + 1));
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
if (
|
|
37
|
+
if (isRecord(value)) {
|
|
34
38
|
return Object.entries(value).every(
|
|
35
39
|
([key, val]) =>
|
|
36
40
|
typeof key === "string" && isJSONValue(val, currentDepth + 1),
|
|
@@ -46,8 +50,7 @@ export function isJSONArray(value: unknown): value is ReadonlyJSONArray {
|
|
|
46
50
|
|
|
47
51
|
export function isJSONObject(value: unknown): value is ReadonlyJSONObject {
|
|
48
52
|
return (
|
|
49
|
-
value
|
|
50
|
-
typeof value === "object" &&
|
|
53
|
+
isRecord(value) &&
|
|
51
54
|
Object.entries(value).every(
|
|
52
55
|
([key, val]) => typeof key === "string" && isJSONValue(val),
|
|
53
56
|
)
|