@copilotkit/shared 2.0.0-rc.38 → 2.0.0-rc.39

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.
Files changed (102) hide show
  1. package/dist/generative-ui/clone-value.cjs +364 -0
  2. package/dist/generative-ui/clone-value.cjs.map +1 -0
  3. package/dist/generative-ui/clone-value.d.cts +51 -0
  4. package/dist/generative-ui/clone-value.d.cts.map +1 -0
  5. package/dist/generative-ui/clone-value.d.mts +51 -0
  6. package/dist/generative-ui/clone-value.d.mts.map +1 -0
  7. package/dist/generative-ui/clone-value.mjs +363 -0
  8. package/dist/generative-ui/clone-value.mjs.map +1 -0
  9. package/dist/generative-ui/index.cjs +39 -0
  10. package/dist/generative-ui/index.d.cts +8 -2
  11. package/dist/generative-ui/index.d.mts +8 -2
  12. package/dist/generative-ui/index.mjs +8 -2
  13. package/dist/generative-ui/is-record.d.cts +3 -1
  14. package/dist/generative-ui/is-record.d.cts.map +1 -1
  15. package/dist/generative-ui/is-record.d.mts +3 -1
  16. package/dist/generative-ui/is-record.d.mts.map +1 -1
  17. package/dist/generative-ui/schema-render.cjs +2 -1
  18. package/dist/generative-ui/schema-render.cjs.map +1 -1
  19. package/dist/generative-ui/schema-render.d.cts.map +1 -1
  20. package/dist/generative-ui/schema-render.d.mts.map +1 -1
  21. package/dist/generative-ui/schema-render.mjs +2 -1
  22. package/dist/generative-ui/schema-render.mjs.map +1 -1
  23. package/dist/generative-ui/standard/chart-config.cjs +347 -0
  24. package/dist/generative-ui/standard/chart-config.cjs.map +1 -0
  25. package/dist/generative-ui/standard/chart-config.d.cts +97 -0
  26. package/dist/generative-ui/standard/chart-config.d.cts.map +1 -0
  27. package/dist/generative-ui/standard/chart-config.d.mts +97 -0
  28. package/dist/generative-ui/standard/chart-config.d.mts.map +1 -0
  29. package/dist/generative-ui/standard/chart-config.mjs +342 -0
  30. package/dist/generative-ui/standard/chart-config.mjs.map +1 -0
  31. package/dist/generative-ui/standard/composites.d.cts +2 -2
  32. package/dist/generative-ui/standard/composites.d.mts +2 -2
  33. package/dist/generative-ui/standard/declarations.d.cts +68 -68
  34. package/dist/generative-ui/standard/declarations.d.mts +68 -68
  35. package/dist/generative-ui/standard/index.d.mts +5 -1
  36. package/dist/generative-ui/standard/inputs.d.cts +22 -22
  37. package/dist/generative-ui/standard/inputs.d.mts +22 -22
  38. package/dist/generative-ui/standard/layout.d.cts +90 -90
  39. package/dist/generative-ui/standard/layout.d.mts +90 -90
  40. package/dist/generative-ui/standard/map-helpers.cjs +104 -0
  41. package/dist/generative-ui/standard/map-helpers.cjs.map +1 -0
  42. package/dist/generative-ui/standard/map-helpers.d.cts +88 -0
  43. package/dist/generative-ui/standard/map-helpers.d.cts.map +1 -0
  44. package/dist/generative-ui/standard/map-helpers.d.mts +88 -0
  45. package/dist/generative-ui/standard/map-helpers.d.mts.map +1 -0
  46. package/dist/generative-ui/standard/map-helpers.mjs +95 -0
  47. package/dist/generative-ui/standard/map-helpers.mjs.map +1 -0
  48. package/dist/generative-ui/standard/media.d.cts +6 -6
  49. package/dist/generative-ui/standard/media.d.mts +6 -6
  50. package/dist/generative-ui/standard/style-helpers.cjs +151 -0
  51. package/dist/generative-ui/standard/style-helpers.cjs.map +1 -0
  52. package/dist/generative-ui/standard/style-helpers.d.cts +56 -0
  53. package/dist/generative-ui/standard/style-helpers.d.cts.map +1 -0
  54. package/dist/generative-ui/standard/style-helpers.d.mts +56 -0
  55. package/dist/generative-ui/standard/style-helpers.d.mts.map +1 -0
  56. package/dist/generative-ui/standard/style-helpers.mjs +142 -0
  57. package/dist/generative-ui/standard/style-helpers.mjs.map +1 -0
  58. package/dist/generative-ui/standard/text.d.cts +14 -14
  59. package/dist/generative-ui/standard/text.d.mts +14 -14
  60. package/dist/generative-ui/standard/url.cjs +54 -0
  61. package/dist/generative-ui/standard/url.cjs.map +1 -0
  62. package/dist/generative-ui/standard/url.d.cts +32 -0
  63. package/dist/generative-ui/standard/url.d.cts.map +1 -0
  64. package/dist/generative-ui/standard/url.d.mts +32 -0
  65. package/dist/generative-ui/standard/url.d.mts.map +1 -0
  66. package/dist/generative-ui/standard/url.mjs +50 -0
  67. package/dist/generative-ui/standard/url.mjs.map +1 -0
  68. package/dist/generative-ui/thrown.cjs +69 -0
  69. package/dist/generative-ui/thrown.cjs.map +1 -0
  70. package/dist/generative-ui/thrown.d.cts +21 -0
  71. package/dist/generative-ui/thrown.d.cts.map +1 -0
  72. package/dist/generative-ui/thrown.d.mts +21 -0
  73. package/dist/generative-ui/thrown.d.mts.map +1 -0
  74. package/dist/generative-ui/thrown.mjs +67 -0
  75. package/dist/generative-ui/thrown.mjs.map +1 -0
  76. package/dist/index.cjs +2 -0
  77. package/dist/index.cjs.map +1 -1
  78. package/dist/index.d.cts +2 -1
  79. package/dist/index.d.cts.map +1 -1
  80. package/dist/index.d.mts +2 -1
  81. package/dist/index.d.mts.map +1 -1
  82. package/dist/index.mjs +2 -1
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/index.umd.js +368 -2
  85. package/dist/index.umd.js.map +1 -1
  86. package/dist/package.cjs +1 -1
  87. package/dist/package.mjs +1 -1
  88. package/package.json +1 -1
  89. package/src/__tests__/schema-render.test.ts +78 -0
  90. package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
  91. package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
  92. package/src/generative-ui/clone-value.ts +511 -0
  93. package/src/generative-ui/index.ts +6 -2
  94. package/src/generative-ui/schema-render.ts +2 -1
  95. package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
  96. package/src/generative-ui/standard/chart-config.ts +434 -0
  97. package/src/generative-ui/standard/index.ts +36 -0
  98. package/src/generative-ui/standard/map-helpers.ts +155 -0
  99. package/src/generative-ui/standard/style-helpers.ts +170 -0
  100. package/src/generative-ui/standard/url.ts +51 -0
  101. package/src/generative-ui/thrown.ts +90 -0
  102. package/src/index.ts +5 -0
@@ -0,0 +1,511 @@
1
+ /**
2
+ * A deep copy of `value` with `structuredClone` semantics. Uses the global
3
+ * `structuredClone` when there is one. Hermes (React Native) has none, so
4
+ * there a local copy runs. It decides the kind of an object by the same
5
+ * internal slots that `structuredClone` reads (brand checks), not by
6
+ * `instanceof` or `Symbol.toStringTag`, and gives what the native
7
+ * `structuredClone` of V8 gives:
8
+ *
9
+ * - `undefined`, `null`, strings, booleans, numbers (also `NaN`,
10
+ * `Infinity` and `-0`) and bigints are returned as they are.
11
+ * - Arrays and ordinary objects are copied deeply: own enumerable string
12
+ * keys only, so a class instance, or an object with its own
13
+ * `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its
14
+ * holes and its length.
15
+ * - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a
16
+ * resizable one stays resizable), typed arrays (as the base type, never a
17
+ * subclass), `DataView`s, `Blob`s and `File`s are copied.
18
+ * - An `Error` becomes an `Error` of its standard type (a custom name or
19
+ * `AggregateError` becomes `Error`), with its own `message`, its `stack`
20
+ * and its own `cause`. A `DOMException` stays one where the global exists.
21
+ * - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.
22
+ * - Cycles and shared references are kept: an object reached twice is
23
+ * copied once.
24
+ * - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,
25
+ * `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web
26
+ * platform objects that cannot be cloned (`URL`, `Headers`, streams...)
27
+ * throw an error named `"DataCloneError"`: a `DOMException` where the
28
+ * global exists, else an `Error` (Hermes has no `DOMException`).
29
+ *
30
+ * Two differences are left. A `Proxy` cannot be told from its target in
31
+ * JavaScript, so the local copy reads it through its traps, where the
32
+ * native one throws. And an ordinary object takes a fast path that runs no
33
+ * brand check (each failed one throws and catches an exception, slow on
34
+ * Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype
35
+ * was changed to `Object.prototype` or `null` is copied as a plain object.
36
+ *
37
+ * It never installs a global `structuredClone`, and it does not use the
38
+ * JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns
39
+ * `undefined` into `{}` and drops or changes values JSON cannot hold.
40
+ *
41
+ * @param value - The value to copy.
42
+ * @returns A copy that shares no object with `value`, except a
43
+ * `SharedArrayBuffer`.
44
+ * @throws An error named `"DataCloneError"` for a value that cannot be
45
+ * cloned.
46
+ */
47
+ export function cloneValue<T>(value: T): T {
48
+ const native = (globalThis as { structuredClone?: <V>(value: V) => V })
49
+ .structuredClone;
50
+ if (typeof native === "function") return native(value);
51
+ return cloneInto(value, new Map()) as T;
52
+ }
53
+
54
+ type AnyFunction = (this: unknown, ...args: unknown[]) => unknown;
55
+ type Constructor = new (...args: unknown[]) => unknown;
56
+
57
+ /** A global, or `undefined` when this engine does not have it. */
58
+ function globalNamed<T = Constructor>(name: string): T | undefined {
59
+ return (globalThis as unknown as Record<string, T | undefined>)[name];
60
+ }
61
+
62
+ /** True when `method` accepts `value` as its `this`: a brand check. */
63
+ function hasBrand(
64
+ value: object,
65
+ method: AnyFunction | undefined,
66
+ ...args: unknown[]
67
+ ) {
68
+ if (typeof method !== "function") return false;
69
+ try {
70
+ method.call(value, ...args);
71
+ return true;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ /** The getter of `key` on `proto`, for a brand check. */
78
+ function getterOf(proto: object | undefined, key: PropertyKey) {
79
+ if (!proto) return undefined;
80
+ return Object.getOwnPropertyDescriptor(proto, key)?.get as
81
+ | AnyFunction
82
+ | undefined;
83
+ }
84
+
85
+ function protoOf(name: string): object | undefined {
86
+ return (globalNamed<{ prototype?: object }>(name) ?? {}).prototype;
87
+ }
88
+
89
+ function methodOf(name: string, key: string): AnyFunction | undefined {
90
+ const proto = protoOf(name) as Record<string, AnyFunction> | undefined;
91
+ return proto?.[key];
92
+ }
93
+
94
+ const ERROR_NAMES = new Set([
95
+ "Error",
96
+ "EvalError",
97
+ "RangeError",
98
+ "ReferenceError",
99
+ "SyntaxError",
100
+ "TypeError",
101
+ "URIError",
102
+ ]);
103
+
104
+ /** Web platform objects that `structuredClone` refuses, where they exist. */
105
+ const PLATFORM_UNCLONEABLE = [
106
+ "URL",
107
+ "URLSearchParams",
108
+ "Headers",
109
+ "Request",
110
+ "Response",
111
+ "FormData",
112
+ "ReadableStream",
113
+ "WritableStream",
114
+ "TransformStream",
115
+ "MessagePort",
116
+ ];
117
+
118
+ function* emptyGenerator() {
119
+ // Only its prototype chain is used.
120
+ }
121
+
122
+ /** The prototypes of the built-in iterators and generators. */
123
+ function iteratorPrototypes(): object[] {
124
+ const protos: object[] = [];
125
+ const add = (iterator: unknown) => {
126
+ const proto = iterator && Object.getPrototypeOf(iterator);
127
+ if (proto) protos.push(proto);
128
+ };
129
+ add([][Symbol.iterator]());
130
+ add(new Map()[Symbol.iterator]());
131
+ add(new Set()[Symbol.iterator]());
132
+ add(""[Symbol.iterator]());
133
+ // The prototype of a generator object is its function's own `prototype`;
134
+ // the shared one is above it.
135
+ protos.push(Object.getPrototypeOf(emptyGenerator.prototype) as object);
136
+ const matchAllKey = (Symbol as unknown as Record<string, symbol | undefined>)
137
+ .matchAll;
138
+ const matchAll = matchAllKey
139
+ ? (RegExp.prototype as unknown as Record<symbol, AnyFunction | undefined>)[
140
+ matchAllKey
141
+ ]
142
+ : undefined;
143
+ if (typeof matchAll === "function") add(matchAll.call(/a/g, ""));
144
+ return protos;
145
+ }
146
+
147
+ let iteratorProtos: object[] | undefined;
148
+
149
+ function inheritsFrom(value: object, protos: readonly object[]) {
150
+ for (
151
+ let proto = Object.getPrototypeOf(value);
152
+ proto !== null;
153
+ proto = Object.getPrototypeOf(proto)
154
+ ) {
155
+ if (protos.includes(proto)) return true;
156
+ }
157
+ return false;
158
+ }
159
+
160
+ function dataCloneError(what: string): Error {
161
+ const message = `${what} could not be cloned.`;
162
+ const DOMExceptionClass =
163
+ globalNamed<new (message: string, name: string) => Error>("DOMException");
164
+ if (typeof DOMExceptionClass === "function") {
165
+ return new DOMExceptionClass(message, "DataCloneError");
166
+ }
167
+ const error = new Error(message);
168
+ error.name = "DataCloneError";
169
+ return error;
170
+ }
171
+
172
+ function describe(value: unknown): string {
173
+ if (typeof value === "function") {
174
+ return value.name ? `function ${value.name}` : "A function";
175
+ }
176
+ if (typeof value === "symbol") return String(value);
177
+ return Object.prototype.toString.call(value);
178
+ }
179
+
180
+ /** True for an object with the [[ErrorData]] slot. */
181
+ function isError(value: object) {
182
+ const isErrorCheck = (Error as unknown as { isError?: AnyFunction }).isError;
183
+ if (typeof isErrorCheck === "function") {
184
+ return isErrorCheck.call(Error, value) === true;
185
+ }
186
+ // Without Error.isError the built-in tag shows the slot, unless a
187
+ // Symbol.toStringTag hides it (a DOMException has one).
188
+ if (!(Symbol.toStringTag in value)) {
189
+ return Object.prototype.toString.call(value) === "[object Error]";
190
+ }
191
+ return value instanceof Error;
192
+ }
193
+
194
+ function isDOMException(value: object) {
195
+ return hasBrand(value, getterOf(protoOf("DOMException"), "code"));
196
+ }
197
+
198
+ /** The name of the base typed-array type of a view, or `undefined`. */
199
+ function typedArrayName(value: object): string | undefined {
200
+ const TypedArrayProto = Object.getPrototypeOf(Uint8Array.prototype) as object;
201
+ const getter = getterOf(TypedArrayProto, Symbol.toStringTag);
202
+ if (!getter) return undefined;
203
+ const name = getter.call(value);
204
+ return typeof name === "string" ? name : undefined;
205
+ }
206
+
207
+ function cloneArrayBuffer(value: ArrayBuffer): ArrayBuffer {
208
+ const source = value as ArrayBuffer & {
209
+ resizable?: boolean;
210
+ maxByteLength?: number;
211
+ };
212
+ if (source.resizable === true) {
213
+ const ArrayBufferClass = ArrayBuffer as unknown as new (
214
+ length: number,
215
+ options: { maxByteLength: number },
216
+ ) => ArrayBuffer;
217
+ const copy = new ArrayBufferClass(source.byteLength, {
218
+ maxByteLength: source.maxByteLength as number,
219
+ });
220
+ new Uint8Array(copy).set(new Uint8Array(source));
221
+ return copy;
222
+ }
223
+ return ArrayBuffer.prototype.slice.call(value, 0) as ArrayBuffer;
224
+ }
225
+
226
+ function cloneError(value: Error, seen: Map<object, unknown>): Error {
227
+ let copy: Error;
228
+ const own = (key: string) => Object.prototype.hasOwnProperty.call(value, key);
229
+ const messageDescriptor = Object.getOwnPropertyDescriptor(value, "message");
230
+ const message =
231
+ messageDescriptor && "value" in messageDescriptor
232
+ ? `${messageDescriptor.value}`
233
+ : undefined;
234
+ if (isDOMException(value)) {
235
+ const DOMExceptionClass =
236
+ globalNamed<new (message?: string, name?: string) => Error>(
237
+ "DOMException",
238
+ )!;
239
+ copy = new DOMExceptionClass(value.message, value.name);
240
+ } else {
241
+ const name = ERROR_NAMES.has(value.name) ? value.name : "Error";
242
+ const ErrorClass = globalNamed<ErrorConstructor>(name) ?? Error;
243
+ copy = message === undefined ? new ErrorClass() : new ErrorClass(message);
244
+ }
245
+ seen.set(value, copy);
246
+ if (typeof value.stack === "string") copy.stack = value.stack;
247
+ if (!isDOMException(value)) {
248
+ const causeDescriptor = Object.getOwnPropertyDescriptor(value, "cause");
249
+ if (own("cause") && causeDescriptor && "value" in causeDescriptor) {
250
+ // Defined, not passed as an option: Hermes may not read ErrorOptions.
251
+ Object.defineProperty(copy, "cause", {
252
+ value: cloneInto(causeDescriptor.value, seen),
253
+ writable: true,
254
+ enumerable: false,
255
+ configurable: true,
256
+ });
257
+ }
258
+ }
259
+ return copy;
260
+ }
261
+
262
+ function cloneInto(value: unknown, seen: Map<object, unknown>): unknown {
263
+ if (typeof value === "function" || typeof value === "symbol") {
264
+ throw dataCloneError(describe(value));
265
+ }
266
+ if (typeof value !== "object" || value === null) return value;
267
+ const known = seen.get(value);
268
+ if (known !== undefined) return known;
269
+
270
+ if (Array.isArray(value)) {
271
+ // The same length, so a sparse array keeps its holes.
272
+ const copy: unknown[] = [];
273
+ copy.length = value.length;
274
+ seen.set(value, copy);
275
+ copyKeys(value, copy, seen);
276
+ return copy;
277
+ }
278
+ // The common case, before the brand checks below: each one that fails
279
+ // throws and catches an exception, which is slow on Hermes.
280
+ if (isPlainObject(value)) {
281
+ const copy: Record<string, unknown> = {};
282
+ seen.set(value, copy);
283
+ copyKeys(value, copy, seen);
284
+ return copy;
285
+ }
286
+ if (hasBrand(value, Date.prototype.getTime as AnyFunction)) {
287
+ const copy = new Date(Date.prototype.getTime.call(value));
288
+ seen.set(value, copy);
289
+ return copy;
290
+ }
291
+ if (hasBrand(value, getterOf(RegExp.prototype, "source"))) {
292
+ const source = getterOf(RegExp.prototype, "source")!.call(value) as string;
293
+ const flags = getterOf(RegExp.prototype, "flags")!.call(value) as string;
294
+ const copy = new RegExp(source, flags);
295
+ seen.set(value, copy);
296
+ return copy;
297
+ }
298
+ if (hasBrand(value, Map.prototype.has as AnyFunction, undefined)) {
299
+ const copy = new Map<unknown, unknown>();
300
+ seen.set(value, copy);
301
+ const entries: [unknown, unknown][] = [];
302
+ Map.prototype.forEach.call(value, (entry: unknown, key: unknown) => {
303
+ entries.push([key, entry]);
304
+ });
305
+ for (const [key, entry] of entries) {
306
+ copy.set(cloneInto(key, seen), cloneInto(entry, seen));
307
+ }
308
+ return copy;
309
+ }
310
+ if (hasBrand(value, Set.prototype.has as AnyFunction, undefined)) {
311
+ const copy = new Set<unknown>();
312
+ seen.set(value, copy);
313
+ const entries: unknown[] = [];
314
+ Set.prototype.forEach.call(value, (entry: unknown) => {
315
+ entries.push(entry);
316
+ });
317
+ for (const entry of entries) copy.add(cloneInto(entry, seen));
318
+ return copy;
319
+ }
320
+ if (hasBrand(value, getterOf(ArrayBuffer.prototype, "byteLength"))) {
321
+ const copy = cloneArrayBuffer(value as ArrayBuffer);
322
+ seen.set(value, copy);
323
+ return copy;
324
+ }
325
+ if (hasBrand(value, getterOf(protoOf("SharedArrayBuffer"), "byteLength"))) {
326
+ // structuredClone shares the memory of a SharedArrayBuffer.
327
+ seen.set(value, value);
328
+ return value;
329
+ }
330
+ if (ArrayBuffer.isView(value)) {
331
+ const view = value as ArrayBufferView;
332
+ const buffer = cloneInto(view.buffer, seen) as ArrayBuffer;
333
+ const isDataView = hasBrand(
334
+ value,
335
+ getterOf(DataView.prototype, "byteLength"),
336
+ );
337
+ let copy: ArrayBufferView;
338
+ if (isDataView) {
339
+ copy = new DataView(buffer, view.byteOffset, view.byteLength);
340
+ } else {
341
+ const name = typedArrayName(value);
342
+ const TypedArray = name
343
+ ? globalNamed<
344
+ new (
345
+ buffer: ArrayBuffer,
346
+ byteOffset: number,
347
+ length: number,
348
+ ) => ArrayBufferView
349
+ >(name)
350
+ : undefined;
351
+ if (!TypedArray) throw dataCloneError(describe(value));
352
+ const proto = Object.getPrototypeOf(Uint8Array.prototype) as object;
353
+ const offset = getterOf(proto, "byteOffset")!.call(value) as number;
354
+ const length = getterOf(proto, "length")!.call(value) as number;
355
+ copy = new TypedArray(buffer, offset, length);
356
+ }
357
+ seen.set(value, copy);
358
+ return copy;
359
+ }
360
+ if (isError(value)) return cloneError(value as Error, seen);
361
+
362
+ for (const [name, Boxed] of [
363
+ ["Boolean", Boolean],
364
+ ["Number", Number],
365
+ ["String", String],
366
+ ["BigInt", globalNamed("BigInt")],
367
+ ] as const) {
368
+ const valueOf = methodOf(name, "valueOf");
369
+ if (Boxed && hasBrand(value, valueOf)) {
370
+ const copy = Object(valueOf!.call(value));
371
+ seen.set(value, copy);
372
+ return copy;
373
+ }
374
+ }
375
+ if (hasBrand(value, methodOf("Symbol", "valueOf"))) {
376
+ throw dataCloneError(describe(value));
377
+ }
378
+ const BlobClass = globalNamed<{ prototype: Blob }>("Blob");
379
+ if (typeof BlobClass === "function" && value instanceof BlobClass) {
380
+ const copy = cloneBlob(value as Blob);
381
+ seen.set(value, copy);
382
+ return copy;
383
+ }
384
+ if (isUncloneable(value)) throw dataCloneError(describe(value));
385
+
386
+ const copy: Record<string, unknown> = {};
387
+ seen.set(value, copy);
388
+ copyKeys(value, copy, seen);
389
+ return copy;
390
+ }
391
+
392
+ function cloneBlob(value: Blob): Blob {
393
+ const FileClass =
394
+ globalNamed<
395
+ new (
396
+ parts: Blob[],
397
+ name: string,
398
+ options: { type: string; lastModified: number },
399
+ ) => Blob
400
+ >("File");
401
+ if (typeof FileClass === "function" && value instanceof FileClass) {
402
+ const file = value as Blob & { name: string; lastModified: number };
403
+ return new FileClass([value], file.name, {
404
+ type: value.type,
405
+ lastModified: file.lastModified,
406
+ });
407
+ }
408
+ const BlobClass =
409
+ globalNamed<new (parts: Blob[], options: { type: string }) => Blob>(
410
+ "Blob",
411
+ )!;
412
+ return new BlobClass([value], { type: value.type });
413
+ }
414
+
415
+ /**
416
+ * True for an ordinary object of this realm: its prototype is
417
+ * `Object.prototype` or `null`, it has no `Symbol.toStringTag`, and its
418
+ * built-in tag is "Object" (so not `arguments`, an `Error`, a `Date`, a
419
+ * `RegExp` or a boxed primitive, whatever their prototype). Throws nothing.
420
+ * An object with another slot (a `Map`, a `Set`, a `Promise`...) whose
421
+ * prototype was changed to one of those passes too; only a brand check,
422
+ * which throws, could tell, so it is copied as a plain object.
423
+ */
424
+ function isPlainObject(value: object): boolean {
425
+ const proto = Object.getPrototypeOf(value);
426
+ if (proto !== Object.prototype && proto !== null) return false;
427
+ if (Symbol.toStringTag in value) return false;
428
+ if (ArrayBuffer.isView(value)) return false;
429
+ return Object.prototype.toString.call(value) === "[object Object]";
430
+ }
431
+
432
+ /** The globals of PLATFORM_UNCLONEABLE and their prototypes, when last read. */
433
+ let platformCache: { classes: unknown[]; protos: object[] } | undefined;
434
+
435
+ /**
436
+ * The prototypes of the PLATFORM_UNCLONEABLE globals that exist. Kept
437
+ * between calls, and built again only when one of the globals changed (a
438
+ * polyfill installed late).
439
+ */
440
+ function platformPrototypes(): object[] {
441
+ const globals = globalThis as unknown as Record<string, unknown>;
442
+ const cached = platformCache;
443
+ if (
444
+ cached &&
445
+ PLATFORM_UNCLONEABLE.every(
446
+ (name, index) => globals[name] === cached.classes[index],
447
+ )
448
+ ) {
449
+ return cached.protos;
450
+ }
451
+ const classes = PLATFORM_UNCLONEABLE.map((name) => globals[name]);
452
+ const protos = PLATFORM_UNCLONEABLE.map(protoOf).filter(
453
+ (proto): proto is object => proto !== undefined,
454
+ );
455
+ platformCache = { classes, protos };
456
+ return protos;
457
+ }
458
+
459
+ /** An object that structuredClone refuses, though it has no data slot. */
460
+ function isUncloneable(value: object) {
461
+ // An arguments object: V8 refuses it. Only the built-in tag says so; an
462
+ // object that only claims the tag is a plain object.
463
+ if (
464
+ !(Symbol.toStringTag in value) &&
465
+ Object.prototype.toString.call(value) === "[object Arguments]"
466
+ ) {
467
+ return true;
468
+ }
469
+ if (
470
+ hasBrand(value, methodOf("WeakMap", "has"), {}) ||
471
+ hasBrand(value, methodOf("WeakSet", "has"), {}) ||
472
+ hasBrand(value, methodOf("WeakRef", "deref")) ||
473
+ hasBrand(value, methodOf("FinalizationRegistry", "unregister"), {})
474
+ ) {
475
+ return true;
476
+ }
477
+ const PromiseClass = globalNamed<{ prototype: object }>("Promise");
478
+ if (PromiseClass && value instanceof (PromiseClass as unknown as Constructor))
479
+ return true;
480
+ if (!iteratorProtos) iteratorProtos = iteratorPrototypes();
481
+ if (inheritsFrom(value, iteratorProtos)) return true;
482
+ return inheritsFrom(value, platformPrototypes());
483
+ }
484
+
485
+ /** Copies the own enumerable string keys, as structuredClone does. */
486
+ function copyKeys(source: object, target: object, seen: Map<object, unknown>) {
487
+ for (const key of Object.keys(source)) {
488
+ assign(
489
+ target as Record<string, unknown>,
490
+ key,
491
+ cloneInto((source as Record<string, unknown>)[key], seen),
492
+ );
493
+ }
494
+ }
495
+
496
+ /**
497
+ * Sets an own property. A plain assignment of "__proto__" would change the
498
+ * prototype of the copy instead (JSON.parse makes "__proto__" an own key).
499
+ */
500
+ function assign(target: Record<string, unknown>, key: string, value: unknown) {
501
+ if (key === "__proto__") {
502
+ Object.defineProperty(target, key, {
503
+ value,
504
+ enumerable: true,
505
+ configurable: true,
506
+ writable: true,
507
+ });
508
+ } else {
509
+ target[key] = value;
510
+ }
511
+ }
@@ -1,6 +1,7 @@
1
1
  // The `@copilotkit/shared/generative-ui` entry: the framework-free part of
2
- // generative UI. The framework packages (`@copilotkit/react-core`,
3
- // `@copilotkit/angular`) build their generative UI on it. The A2UI protocol
2
+ // generative UI. The generative UI engine of `@copilotkit/core` builds on
3
+ // it, and through core so do the framework packages (`@copilotkit/react-core`,
4
+ // its React Native entry, and `@copilotkit/angular`). The A2UI protocol
4
5
  // types stay on the package root, in `./base`.
5
6
  export * from "./types";
6
7
  export * from "./validate-operation";
@@ -14,3 +15,6 @@ export * from "./schema-render";
14
15
  export * from "./catalog";
15
16
  export * from "./standard";
16
17
  export { isRecord } from "./is-record";
18
+ export { hasOwnKey } from "./is-record";
19
+ export { cloneValue } from "./clone-value";
20
+ export { toError, withCause } from "./thrown";
@@ -1,4 +1,5 @@
1
1
  import { functionCallers } from "./basic-functions";
2
+ import { cloneValue } from "./clone-value";
2
3
  import {
3
4
  buildCompactGenerativeUISchema,
4
5
  compactProps,
@@ -323,7 +324,7 @@ export function applyDescriptionOverrides<
323
324
  manifest: M,
324
325
  overrides: Record<string, string>,
325
326
  ): { manifest: M; unknown: string[] } {
326
- const components = structuredClone(manifest.components);
327
+ const components = cloneValue(manifest.components);
327
328
  const unknown: string[] = [];
328
329
  for (const [key, description] of Object.entries(overrides)) {
329
330
  const [name, prop, ...rest] = key.split(".");