@copilotkit/shared 1.84.2-canary.openbot-intel-fixes → 1.86.0
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/event-transforms/recorded-events.cjs +7 -1
- package/dist/event-transforms/recorded-events.cjs.map +1 -1
- package/dist/event-transforms/recorded-events.mjs +8 -2
- package/dist/event-transforms/recorded-events.mjs.map +1 -1
- package/dist/generative-ui/clone-value.cjs +364 -0
- package/dist/generative-ui/clone-value.cjs.map +1 -0
- package/dist/generative-ui/clone-value.d.cts +51 -0
- package/dist/generative-ui/clone-value.d.cts.map +1 -0
- package/dist/generative-ui/clone-value.d.mts +51 -0
- package/dist/generative-ui/clone-value.d.mts.map +1 -0
- package/dist/generative-ui/clone-value.mjs +363 -0
- package/dist/generative-ui/clone-value.mjs.map +1 -0
- package/dist/generative-ui/index.cjs +39 -0
- package/dist/generative-ui/index.d.cts +8 -2
- package/dist/generative-ui/index.d.mts +8 -2
- package/dist/generative-ui/index.mjs +8 -2
- package/dist/generative-ui/is-record.d.cts +3 -1
- package/dist/generative-ui/is-record.d.cts.map +1 -1
- package/dist/generative-ui/is-record.d.mts +3 -1
- package/dist/generative-ui/is-record.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.cjs +2 -1
- package/dist/generative-ui/schema-render.cjs.map +1 -1
- package/dist/generative-ui/schema-render.d.cts.map +1 -1
- package/dist/generative-ui/schema-render.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.mjs +2 -1
- package/dist/generative-ui/schema-render.mjs.map +1 -1
- package/dist/generative-ui/standard/chart-config.cjs +347 -0
- package/dist/generative-ui/standard/chart-config.cjs.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.cts +97 -0
- package/dist/generative-ui/standard/chart-config.d.cts.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.mts +97 -0
- package/dist/generative-ui/standard/chart-config.d.mts.map +1 -0
- package/dist/generative-ui/standard/chart-config.mjs +342 -0
- package/dist/generative-ui/standard/chart-config.mjs.map +1 -0
- package/dist/generative-ui/standard/chart.d.cts +10 -10
- package/dist/generative-ui/standard/chart.d.mts +10 -10
- package/dist/generative-ui/standard/composites.d.cts +46 -46
- package/dist/generative-ui/standard/composites.d.mts +46 -46
- package/dist/generative-ui/standard/data.d.cts +42 -42
- package/dist/generative-ui/standard/data.d.mts +42 -42
- package/dist/generative-ui/standard/declarations.d.cts +226 -226
- package/dist/generative-ui/standard/declarations.d.mts +226 -226
- package/dist/generative-ui/standard/feedback.d.cts +4 -4
- package/dist/generative-ui/standard/feedback.d.mts +4 -4
- package/dist/generative-ui/standard/index.d.mts +5 -1
- package/dist/generative-ui/standard/inputs.d.cts +72 -72
- package/dist/generative-ui/standard/inputs.d.mts +72 -72
- package/dist/generative-ui/standard/layout.d.cts +156 -156
- package/dist/generative-ui/standard/layout.d.mts +156 -156
- package/dist/generative-ui/standard/map-helpers.cjs +104 -0
- package/dist/generative-ui/standard/map-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.cts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.mts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.mjs +95 -0
- package/dist/generative-ui/standard/map-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/map.d.cts +10 -10
- package/dist/generative-ui/standard/map.d.mts +10 -10
- package/dist/generative-ui/standard/media.d.cts +76 -76
- package/dist/generative-ui/standard/media.d.mts +76 -76
- package/dist/generative-ui/standard/style-helpers.cjs +151 -0
- package/dist/generative-ui/standard/style-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.cts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.mts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.mjs +142 -0
- package/dist/generative-ui/standard/style-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/text.d.cts +28 -28
- package/dist/generative-ui/standard/text.d.mts +28 -28
- package/dist/generative-ui/standard/url.cjs +54 -0
- package/dist/generative-ui/standard/url.cjs.map +1 -0
- package/dist/generative-ui/standard/url.d.cts +32 -0
- package/dist/generative-ui/standard/url.d.cts.map +1 -0
- package/dist/generative-ui/standard/url.d.mts +32 -0
- package/dist/generative-ui/standard/url.d.mts.map +1 -0
- package/dist/generative-ui/standard/url.mjs +50 -0
- package/dist/generative-ui/standard/url.mjs.map +1 -0
- package/dist/generative-ui/thrown.cjs +69 -0
- package/dist/generative-ui/thrown.cjs.map +1 -0
- package/dist/generative-ui/thrown.d.cts +21 -0
- package/dist/generative-ui/thrown.d.cts.map +1 -0
- package/dist/generative-ui/thrown.d.mts +21 -0
- package/dist/generative-ui/thrown.d.mts.map +1 -0
- package/dist/generative-ui/thrown.mjs +67 -0
- package/dist/generative-ui/thrown.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +368 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +2 -2
- package/src/__tests__/schema-render.test.ts +78 -0
- package/src/event-transforms/recorded-events.test.ts +35 -3
- package/src/event-transforms/recorded-events.ts +15 -2
- package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
- package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
- package/src/generative-ui/clone-value.ts +511 -0
- package/src/generative-ui/index.ts +6 -2
- package/src/generative-ui/schema-render.ts +2 -1
- package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
- package/src/generative-ui/standard/chart-config.ts +434 -0
- package/src/generative-ui/standard/index.ts +36 -0
- package/src/generative-ui/standard/map-helpers.ts +155 -0
- package/src/generative-ui/standard/style-helpers.ts +170 -0
- package/src/generative-ui/standard/url.ts +51 -0
- package/src/generative-ui/thrown.ts +90 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cloneValue } from "../clone-value";
|
|
3
|
+
|
|
4
|
+
// The local deep clone runs only when there is no global structuredClone
|
|
5
|
+
// (Hermes). Each case runs in both modes against the same expectations;
|
|
6
|
+
// clone-value-differential.test.ts compares the two modes with each other.
|
|
7
|
+
const modes = [
|
|
8
|
+
["without a global structuredClone", false],
|
|
9
|
+
["with the global structuredClone", true],
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
describe.each(modes)("cloneValue %s", (_name, withGlobal) => {
|
|
13
|
+
let saved: PropertyDescriptor | undefined;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
saved = Object.getOwnPropertyDescriptor(globalThis, "structuredClone");
|
|
17
|
+
if (!withGlobal) {
|
|
18
|
+
delete (globalThis as { structuredClone?: unknown }).structuredClone;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
if (saved) Object.defineProperty(globalThis, "structuredClone", saved);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("runs in the mode it says", () => {
|
|
27
|
+
expect(typeof globalThis.structuredClone).toBe(
|
|
28
|
+
withGlobal ? "function" : "undefined",
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("keeps undefined, null and primitives", () => {
|
|
33
|
+
expect(cloneValue(undefined)).toBeUndefined();
|
|
34
|
+
expect(cloneValue(null)).toBeNull();
|
|
35
|
+
expect(cloneValue("s")).toBe("s");
|
|
36
|
+
expect(cloneValue(true)).toBe(true);
|
|
37
|
+
expect(cloneValue(Number.NaN)).toBeNaN();
|
|
38
|
+
expect(cloneValue(Number.POSITIVE_INFINITY)).toBe(Infinity);
|
|
39
|
+
expect(cloneValue(Number.NEGATIVE_INFINITY)).toBe(-Infinity);
|
|
40
|
+
expect(Object.is(cloneValue(-0), -0)).toBe(true);
|
|
41
|
+
expect(cloneValue(BigInt(42))).toBe(BigInt(42));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("deep-copies plain objects and arrays", () => {
|
|
45
|
+
const value = { a: [1, { b: 2 }], c: { d: undefined, e: null } };
|
|
46
|
+
const copy = cloneValue(value);
|
|
47
|
+
expect(copy).toEqual(value);
|
|
48
|
+
expect(copy).not.toBe(value);
|
|
49
|
+
expect(copy.a).not.toBe(value.a);
|
|
50
|
+
expect(copy.a[1]).not.toBe(value.a[1]);
|
|
51
|
+
expect(copy.c).not.toBe(value.c);
|
|
52
|
+
expect("d" in copy.c).toBe(true);
|
|
53
|
+
// A sparse array keeps its length and its hole.
|
|
54
|
+
// eslint-disable-next-line no-sparse-arrays
|
|
55
|
+
const sparse = cloneValue([1, , 3]);
|
|
56
|
+
expect(sparse).toHaveLength(3);
|
|
57
|
+
expect(1 in sparse).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("drops the prototype of a class instance, like structuredClone", () => {
|
|
61
|
+
class Point {
|
|
62
|
+
constructor(
|
|
63
|
+
public x: number,
|
|
64
|
+
public y: number,
|
|
65
|
+
) {}
|
|
66
|
+
}
|
|
67
|
+
const copy = cloneValue(new Point(1, 2));
|
|
68
|
+
expect(Object.getPrototypeOf(copy)).toBe(Object.prototype);
|
|
69
|
+
expect(copy).toEqual({ x: 1, y: 2 });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("copies Date, Map, Set, RegExp and boxed primitives", () => {
|
|
73
|
+
const date = new Date(1234);
|
|
74
|
+
const key = { k: 1 };
|
|
75
|
+
const map = new Map<unknown, unknown>([[key, { v: 1 }]]);
|
|
76
|
+
const set = new Set([{ s: 1 }]);
|
|
77
|
+
const regexp = /a+b/gi;
|
|
78
|
+
const copy = cloneValue({ date, map, set, regexp, boxed: Object("x") });
|
|
79
|
+
expect(copy.date).toBeInstanceOf(Date);
|
|
80
|
+
expect(copy.date).not.toBe(date);
|
|
81
|
+
expect(copy.date.getTime()).toBe(1234);
|
|
82
|
+
expect(copy.map).toBeInstanceOf(Map);
|
|
83
|
+
expect(copy.map).not.toBe(map);
|
|
84
|
+
const [[copiedKey, copiedValue]] = [...copy.map];
|
|
85
|
+
expect(copiedKey).toEqual(key);
|
|
86
|
+
expect(copiedKey).not.toBe(key);
|
|
87
|
+
expect(copiedValue).toEqual({ v: 1 });
|
|
88
|
+
expect(copy.set).toBeInstanceOf(Set);
|
|
89
|
+
expect([...copy.set][0]).toEqual({ s: 1 });
|
|
90
|
+
expect([...copy.set][0]).not.toBe([...set][0]);
|
|
91
|
+
expect(copy.regexp).toBeInstanceOf(RegExp);
|
|
92
|
+
expect(copy.regexp).not.toBe(regexp);
|
|
93
|
+
expect(copy.regexp.source).toBe("a+b");
|
|
94
|
+
expect(copy.regexp.flags).toBe("gi");
|
|
95
|
+
expect(copy.boxed).toBeInstanceOf(String);
|
|
96
|
+
expect(String(copy.boxed)).toBe("x");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("copies typed arrays and their buffer", () => {
|
|
100
|
+
const bytes = new Uint8Array([1, 2, 3]);
|
|
101
|
+
const copy = cloneValue(bytes);
|
|
102
|
+
expect(copy).toBeInstanceOf(Uint8Array);
|
|
103
|
+
expect(copy.buffer).not.toBe(bytes.buffer);
|
|
104
|
+
expect([...copy]).toEqual([1, 2, 3]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("copies an Error with its name and message", () => {
|
|
108
|
+
const copy = cloneValue(new TypeError("bad"));
|
|
109
|
+
expect(copy).toBeInstanceOf(TypeError);
|
|
110
|
+
expect(copy.name).toBe("TypeError");
|
|
111
|
+
expect(copy.message).toBe("bad");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("keeps cycles and shared references", () => {
|
|
115
|
+
type Node = { name: string; self?: Node; peer?: object; list?: object[] };
|
|
116
|
+
const shared = { s: 1 };
|
|
117
|
+
const value: Node = { name: "n", peer: shared, list: [shared] };
|
|
118
|
+
value.self = value;
|
|
119
|
+
const copy = cloneValue(value);
|
|
120
|
+
expect(copy).not.toBe(value);
|
|
121
|
+
expect(copy.self).toBe(copy);
|
|
122
|
+
expect(copy.peer).not.toBe(shared);
|
|
123
|
+
expect(copy.list![0]).toBe(copy.peer);
|
|
124
|
+
const map = new Map<string, unknown>();
|
|
125
|
+
map.set("me", map);
|
|
126
|
+
const mapCopy = cloneValue(map);
|
|
127
|
+
expect(mapCopy.get("me")).toBe(mapCopy);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("throws a DataCloneError for functions, symbols, WeakMap and Promise", () => {
|
|
131
|
+
for (const value of [
|
|
132
|
+
() => 1,
|
|
133
|
+
{ nested: { fn: () => 1 } },
|
|
134
|
+
Symbol("s"),
|
|
135
|
+
[Symbol("s")],
|
|
136
|
+
new WeakMap(),
|
|
137
|
+
Promise.resolve(),
|
|
138
|
+
]) {
|
|
139
|
+
expect(() => cloneValue(value)).toThrow(
|
|
140
|
+
expect.objectContaining({ name: "DataCloneError" }),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("cloneValue exports", () => {
|
|
147
|
+
it("is the same function on the package root and the generative UI entry", async () => {
|
|
148
|
+
const root = await import("../../index");
|
|
149
|
+
const entry = await import("../index");
|
|
150
|
+
expect(root.cloneValue).toBe(cloneValue);
|
|
151
|
+
expect(entry.cloneValue).toBe(cloneValue);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Spies on the first brand checks that a non-array object reaches. Each
|
|
157
|
+
* one that fails throws and catches an exception, slow on Hermes.
|
|
158
|
+
*/
|
|
159
|
+
function spyOnBrandChecks() {
|
|
160
|
+
return [
|
|
161
|
+
vi.spyOn(Date.prototype, "getTime"),
|
|
162
|
+
vi.spyOn(Map.prototype, "has"),
|
|
163
|
+
vi.spyOn(Set.prototype, "has"),
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
const calls = (spies: { mock: { calls: unknown[] } }[]) =>
|
|
167
|
+
spies.reduce((sum, spy) => sum + spy.mock.calls.length, 0);
|
|
168
|
+
|
|
169
|
+
describe("cloneValue without a global structuredClone, on plain data", () => {
|
|
170
|
+
let saved: PropertyDescriptor | undefined;
|
|
171
|
+
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
saved = Object.getOwnPropertyDescriptor(globalThis, "structuredClone");
|
|
174
|
+
delete (globalThis as { structuredClone?: unknown }).structuredClone;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
afterEach(() => {
|
|
178
|
+
if (saved) Object.defineProperty(globalThis, "structuredClone", saved);
|
|
179
|
+
vi.restoreAllMocks();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("runs no brand check, so throws no exception, for plain objects and arrays", () => {
|
|
183
|
+
// A streamed surface: a few hundred nested plain objects.
|
|
184
|
+
const tree = {
|
|
185
|
+
components: Array.from({ length: 300 }, (_, index) => ({
|
|
186
|
+
id: `c${index}`,
|
|
187
|
+
props: { label: { text: `Item ${index}` }, style: { gap: index } },
|
|
188
|
+
children: [{ ref: `c${index + 1}` }],
|
|
189
|
+
})),
|
|
190
|
+
meta: Object.assign(Object.create(null), { n: 1 }),
|
|
191
|
+
};
|
|
192
|
+
const spies = spyOnBrandChecks();
|
|
193
|
+
const copy = cloneValue(tree);
|
|
194
|
+
expect(calls(spies)).toBe(0);
|
|
195
|
+
expect(copy).toEqual(tree);
|
|
196
|
+
expect(copy.components[0]).not.toBe(tree.components[0]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("still runs the brand checks for other objects", () => {
|
|
200
|
+
class Point {
|
|
201
|
+
x = 1;
|
|
202
|
+
}
|
|
203
|
+
const spies = spyOnBrandChecks();
|
|
204
|
+
expect(cloneValue({ when: new Date(5), at: new Point() })).toEqual({
|
|
205
|
+
when: new Date(5),
|
|
206
|
+
at: { x: 1 },
|
|
207
|
+
});
|
|
208
|
+
expect(calls(spies)).toBeGreaterThan(0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("does not take the fast path for arguments, Errors or boxed values", () => {
|
|
212
|
+
const args = (function () {
|
|
213
|
+
// eslint-disable-next-line prefer-rest-params
|
|
214
|
+
return arguments;
|
|
215
|
+
})();
|
|
216
|
+
expect(() => cloneValue(args)).toThrow(
|
|
217
|
+
expect.objectContaining({ name: "DataCloneError" }),
|
|
218
|
+
);
|
|
219
|
+
const error = Object.setPrototypeOf(new Error("x"), Object.prototype);
|
|
220
|
+
expect(cloneValue(error)).toBeInstanceOf(Error);
|
|
221
|
+
const boxed = Object.setPrototypeOf(new Number(3), null);
|
|
222
|
+
expect(Number.prototype.valueOf.call(cloneValue(boxed))).toBe(3);
|
|
223
|
+
const view = Object.setPrototypeOf(new Uint8Array([1]), Object.prototype);
|
|
224
|
+
expect(cloneValue(view)).toBeInstanceOf(Uint8Array);
|
|
225
|
+
});
|
|
226
|
+
});
|