@copilotkit/core 2.0.0-rc.42 → 2.0.0-rc.44

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,4 +1,4 @@
1
- import { r as OpenThreadRegistration } from "./learning-bridge-DkOdyUdA.cjs";
1
+ import { r as OpenThreadRegistration } from "./learning-bridge-jOC46U9n.cjs";
2
2
 
3
3
  //#region src/chat/chat-configuration.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as OpenThreadRegistration } from "./learning-bridge-DNdPfyx2.mjs";
1
+ import { r as OpenThreadRegistration } from "./learning-bridge-DbE4J5tK.mjs";
2
2
 
3
3
  //#region src/chat/chat-configuration.d.ts
4
4
  /**
@@ -2,8 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_a2ui_markdown = require('../a2ui-markdown-DkMXFQih.cjs');
3
3
  let _copilotkit_shared = require("@copilotkit/shared");
4
4
  let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
5
- let _a2ui_web_core_catalog = require("@a2ui/web_core/catalog");
6
- let _a2ui_web_core_state = require("@a2ui/web_core/state");
7
5
  let zod = require("zod");
8
6
 
9
7
  //#region src/generative-ui/runtime.ts
@@ -1281,12 +1279,329 @@ var ExpressionParser = class {
1281
1279
  }
1282
1280
  };
1283
1281
 
1282
+ //#endregion
1283
+ //#region src/generative-ui/surface-model.ts
1284
+ /**
1285
+ * The state of one generated surface: its data model and its components.
1286
+ *
1287
+ * These classes replace the state classes of A2UI web_core (0.15) that
1288
+ * generative UI used before. They keep their behavior, so the surface
1289
+ * manager and the renderers work as before, without web_core, Zod 3 or
1290
+ * Preact Signals in the bundle:
1291
+ *
1292
+ * - Paths are JSON Pointers: `~1` reads as `/`, `~0` as `~`, and empty
1293
+ * segments are ignored ("/a//b/" is "/a/b").
1294
+ * - `set` makes the missing containers on its way: an array when the next
1295
+ * segment is an index, else an object. `null` and `undefined` remove the
1296
+ * key (an array index keeps its slot, as `undefined`).
1297
+ * - `get` returns the stored value itself, not a copy.
1298
+ * - A write notifies the subscribers of its path, of the paths above it and
1299
+ * of the paths below it, when the value at their path changed. An object
1300
+ * or an array always counts as changed; the subscriber gets a shallow copy.
1301
+ * - Notifications run after the write is complete. A write made by a
1302
+ * subscriber is notified after the current round of subscribers, and a
1303
+ * subscriber that throws does not stop the others: `set` throws its error
1304
+ * after all of them ran (the batching of Preact Signals, which web_core
1305
+ * used).
1306
+ */
1307
+ /** The largest array index that a write creates or extends to. */
1308
+ const MAX_ARRAY_INDEX = 1e4;
1309
+ /** Segments that could reach `Object.prototype`. */
1310
+ const FORBIDDEN_KEYS = new Set([
1311
+ "__proto__",
1312
+ "constructor",
1313
+ "prototype"
1314
+ ]);
1315
+ /** The number of notification rounds after which a write fails. */
1316
+ const MAX_NOTIFICATION_ROUNDS = 100;
1317
+ /** An object or array: something a path can go into. */
1318
+ function isContainer(value) {
1319
+ return typeof value === "object" && value !== null;
1320
+ }
1321
+ function isIndex(segment) {
1322
+ return /^(0|[1-9]\d*)$/.test(segment);
1323
+ }
1324
+ function hasOwn(target, key) {
1325
+ return Object.prototype.hasOwnProperty.call(target, key);
1326
+ }
1327
+ /** "/a//b/" to "/a/b", escapes kept. The root is "/". */
1328
+ function normalizePath$1(path) {
1329
+ const segments = path.split("/").filter((segment) => segment.length > 0);
1330
+ return segments.length === 0 ? "/" : `/${segments.join("/")}`;
1331
+ }
1332
+ /** The unescaped segments of a JSON Pointer. Throws for a forbidden one. */
1333
+ function parsePath(path) {
1334
+ return path.split("/").filter((segment) => segment.length > 0).map((raw) => {
1335
+ const segment = raw.replace(/~([01])/g, (_, digit) => digit === "1" ? "/" : "~");
1336
+ if (FORBIDDEN_KEYS.has(segment)) throw new Error(`Forbidden path segment '${segment}' in path '${path}'.`);
1337
+ return segment;
1338
+ });
1339
+ }
1340
+ function requirePath(path) {
1341
+ if (path === null || path === void 0) throw new Error("Path cannot be null or undefined.");
1342
+ }
1343
+ /** What a subscriber is given: a shallow copy of an object or an array. */
1344
+ function snapshot(value) {
1345
+ if (Array.isArray(value)) return value.slice();
1346
+ if (typeof value === "object" && value !== null) return { ...value };
1347
+ return value;
1348
+ }
1349
+ let batchDepth = 0;
1350
+ let round = 0;
1351
+ let queue = [];
1352
+ function enqueue(watcher) {
1353
+ if (watcher.queued) return;
1354
+ watcher.queued = true;
1355
+ queue.push(watcher);
1356
+ }
1357
+ function batch(write) {
1358
+ batchDepth++;
1359
+ try {
1360
+ write();
1361
+ } finally {
1362
+ endBatch();
1363
+ }
1364
+ }
1365
+ /** Runs the queued subscribers, round after round, once the outer batch ends. */
1366
+ function endBatch() {
1367
+ if (batchDepth > 1) {
1368
+ batchDepth--;
1369
+ return;
1370
+ }
1371
+ let error;
1372
+ let hasError = false;
1373
+ while (queue.length > 0) {
1374
+ const current = queue;
1375
+ queue = [];
1376
+ round++;
1377
+ for (let i = current.length - 1; i >= 0; i--) {
1378
+ const watcher = current[i];
1379
+ watcher.queued = false;
1380
+ if (!watcher.active) continue;
1381
+ try {
1382
+ watcher.onChange(watcher.state.value);
1383
+ } catch (thrown) {
1384
+ if (!hasError) {
1385
+ error = thrown;
1386
+ hasError = true;
1387
+ }
1388
+ }
1389
+ }
1390
+ }
1391
+ round = 0;
1392
+ batchDepth--;
1393
+ if (hasError) throw error;
1394
+ }
1395
+ /**
1396
+ * The data model of a surface: a JSON value read and written by JSON
1397
+ * Pointer, with subscriptions per path.
1398
+ */
1399
+ var DataModel = class {
1400
+ data;
1401
+ /** By normalized path. Kept until `dispose`, as web_core kept its signals. */
1402
+ paths = /* @__PURE__ */ new Map();
1403
+ /** @param initialData - The value of the root. Defaults to `{}`. */
1404
+ constructor(initialData = {}) {
1405
+ this.data = initialData;
1406
+ }
1407
+ /**
1408
+ * The value at `path`, or `undefined` when there is none. "/" or "" is the
1409
+ * root. The value is the stored one, not a copy.
1410
+ */
1411
+ get(path) {
1412
+ requirePath(path);
1413
+ if (path === "/" || path === "") return this.data;
1414
+ let current = this.data;
1415
+ for (const segment of parsePath(path)) {
1416
+ if (!isContainer(current)) return void 0;
1417
+ if (Array.isArray(current)) {
1418
+ if (!isIndex(segment)) return void 0;
1419
+ const index = Number.parseInt(segment, 10);
1420
+ if (index >= current.length) return void 0;
1421
+ current = current[index];
1422
+ } else {
1423
+ if (!hasOwn(current, segment)) return void 0;
1424
+ current = current[segment];
1425
+ }
1426
+ }
1427
+ return current;
1428
+ }
1429
+ /**
1430
+ * Writes `value` at `path`, making the missing containers on the way, and
1431
+ * notifies the subscribers. `null` or `undefined` removes the key; at the
1432
+ * root it resets the data to `{}`.
1433
+ *
1434
+ * @throws Error when a segment is forbidden, when the path goes through a
1435
+ * primitive, uses a non-index segment on an array, or an index above
1436
+ * 10000, or when a subscriber throws (after the write).
1437
+ */
1438
+ set(path, value) {
1439
+ requirePath(path);
1440
+ const segments = parsePath(path);
1441
+ const last = segments.pop();
1442
+ if (last === void 0) {
1443
+ this.data = value === null || value === void 0 ? {} : value;
1444
+ batch(() => {
1445
+ for (const key of this.paths.keys()) this.refresh(key);
1446
+ });
1447
+ return this;
1448
+ }
1449
+ const removes = value === null || value === void 0;
1450
+ if (removes && this.get(path) === void 0) return this;
1451
+ if (this.data === null || this.data === void 0) this.data = {};
1452
+ const root = this.data;
1453
+ if (!isContainer(root)) throw new Error(`Cannot set path '${path}': the data model root is a primitive value.`);
1454
+ const tooLarge = (segment) => /* @__PURE__ */ new Error(`Cannot set path '${path}': array index '${segment}' exceeds maximum supported index (${MAX_ARRAY_INDEX}).`);
1455
+ const checkArraySegment = (segment) => {
1456
+ if (!isIndex(segment)) throw new Error(`Cannot use non-numeric segment '${segment}' on an array in path '${path}'.`);
1457
+ if (Number.parseInt(segment, 10) > MAX_ARRAY_INDEX) throw tooLarge(segment);
1458
+ };
1459
+ let current = root;
1460
+ for (let i = 0; i < segments.length; i++) {
1461
+ const segment = segments[i];
1462
+ const isArray = Array.isArray(current);
1463
+ if (isArray) checkArraySegment(segment);
1464
+ const child = isArray || hasOwn(current, segment) ? current[segment] : void 0;
1465
+ if (child === void 0 || child === null) {
1466
+ const next = i < segments.length - 1 ? segments[i + 1] : last;
1467
+ if (isIndex(next)) {
1468
+ if (Number.parseInt(next, 10) > MAX_ARRAY_INDEX) throw tooLarge(next);
1469
+ current[segment] = [];
1470
+ } else current[segment] = {};
1471
+ } else if (typeof child !== "object") throw new Error(`Cannot set path '${path}': segment '${segment}' is a primitive value.`);
1472
+ const container = current[segment];
1473
+ if (!isContainer(container)) throw new Error(`Cannot set path '${path}'.`);
1474
+ current = container;
1475
+ }
1476
+ if (Array.isArray(current)) {
1477
+ checkArraySegment(last);
1478
+ if (removes) {
1479
+ const index = Number.parseInt(last, 10);
1480
+ if (index < current.length) current[index] = void 0;
1481
+ } else current[last] = value;
1482
+ } else if (removes) delete current[last];
1483
+ else current[last] = value;
1484
+ this.notify(path);
1485
+ return this;
1486
+ }
1487
+ /**
1488
+ * Calls `onChange` with the new value when the value at `path` changes:
1489
+ * after a write at `path`, above it or below it. It is not called with
1490
+ * the current value.
1491
+ */
1492
+ subscribe(path, onChange) {
1493
+ const key = normalizePath$1(path);
1494
+ let state = this.paths.get(key);
1495
+ if (!state) {
1496
+ state = {
1497
+ value: this.get(key),
1498
+ watchers: []
1499
+ };
1500
+ this.paths.set(key, state);
1501
+ }
1502
+ const watcher = {
1503
+ state,
1504
+ onChange,
1505
+ active: true,
1506
+ queued: false
1507
+ };
1508
+ state.watchers.push(watcher);
1509
+ return { unsubscribe: () => {
1510
+ watcher.active = false;
1511
+ const index = watcher.state.watchers.indexOf(watcher);
1512
+ if (index !== -1) watcher.state.watchers.splice(index, 1);
1513
+ } };
1514
+ }
1515
+ /** Ends every subscription. The data stays. */
1516
+ dispose() {
1517
+ for (const state of this.paths.values()) {
1518
+ for (const watcher of state.watchers) watcher.active = false;
1519
+ state.watchers = [];
1520
+ }
1521
+ this.paths.clear();
1522
+ }
1523
+ /** Refreshes `path`, the paths above it and the paths below it. */
1524
+ notify(path) {
1525
+ const key = normalizePath$1(path);
1526
+ batch(() => {
1527
+ this.refresh(key);
1528
+ let parent = key;
1529
+ while (parent !== "/") {
1530
+ parent = parent.slice(0, parent.lastIndexOf("/")) || "/";
1531
+ this.refresh(parent);
1532
+ }
1533
+ for (const other of this.paths.keys()) if (other.startsWith(`${key}/`)) this.refresh(other);
1534
+ });
1535
+ }
1536
+ /** Queues the subscribers of `key` when its value changed. */
1537
+ refresh(key) {
1538
+ const state = this.paths.get(key);
1539
+ if (!state) return;
1540
+ const next = snapshot(this.get(key));
1541
+ if (next === state.value) return;
1542
+ if (round > MAX_NOTIFICATION_ROUNDS) throw new Error("Cycle detected");
1543
+ state.value = next;
1544
+ for (let i = state.watchers.length - 1; i >= 0; i--) enqueue(state.watchers[i]);
1545
+ }
1546
+ };
1547
+ /** One component of a surface. */
1548
+ var ComponentModel = class {
1549
+ id;
1550
+ /** The component name, for example "Text". */
1551
+ type;
1552
+ /** The node without `id` and `component`. Replaced on update. */
1553
+ properties;
1554
+ constructor(id, type, properties) {
1555
+ this.id = id;
1556
+ this.type = type;
1557
+ this.properties = properties;
1558
+ }
1559
+ };
1560
+ /** The components of a surface, by id, in the order they were added. */
1561
+ var SurfaceComponentsModel = class {
1562
+ components = /* @__PURE__ */ new Map();
1563
+ get(id) {
1564
+ return this.components.get(id);
1565
+ }
1566
+ get entries() {
1567
+ return this.components.entries();
1568
+ }
1569
+ /** @throws Error when a component with the same id is there. */
1570
+ addComponent(component) {
1571
+ if (this.components.has(component.id)) throw new Error(`Component with id '${component.id}' already exists.`);
1572
+ this.components.set(component.id, component);
1573
+ }
1574
+ removeComponent(id) {
1575
+ this.components.delete(id);
1576
+ }
1577
+ dispose() {
1578
+ this.components.clear();
1579
+ }
1580
+ };
1581
+ /** The state of one surface. */
1582
+ var SurfaceModel = class {
1583
+ dataModel = new DataModel();
1584
+ componentsModel = new SurfaceComponentsModel();
1585
+ constructor(id) {
1586
+ this.id = id;
1587
+ }
1588
+ /** Ends the data subscriptions and drops the components. */
1589
+ dispose() {
1590
+ this.dataModel.dispose();
1591
+ this.componentsModel.dispose();
1592
+ }
1593
+ };
1594
+
1284
1595
  //#endregion
1285
1596
  //#region src/generative-ui/surface-manager.ts
1286
1597
  function surfaceKey(threadId, surfaceId) {
1287
1598
  return `${threadId}::${surfaceId}`;
1288
1599
  }
1289
1600
  let creationCounter = 0;
1601
+ /** `"0.9"` for content that the runtime converted from A2UI v0.9. */
1602
+ function sourceVersionOf(content) {
1603
+ return content.a2uiSourceVersion === "0.9" ? "0.9" : void 0;
1604
+ }
1290
1605
  const FORBIDDEN_SEGMENTS = new Set([
1291
1606
  "__proto__",
1292
1607
  "constructor",
@@ -1360,7 +1675,7 @@ function summarizeRejections(rejections) {
1360
1675
  return rejections.slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_SUMMARY_REJECTIONS).map(({ index, reason }) => `operation ${index}: ${reason}`.slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_REJECTION_LENGTH));
1361
1676
  }
1362
1677
  /**
1363
- * Framework-agnostic store of generated surfaces. One web_core SurfaceModel per
1678
+ * Framework-agnostic store of generated surfaces. One SurfaceModel per
1364
1679
  * (threadId, surfaceId), shared by every mount. Applies only newly committed
1365
1680
  * operations, validates each before applying it, and owns app state and the
1366
1681
  * data model paths that the user wrote, so agent updates cannot overwrite
@@ -1391,16 +1706,11 @@ var GenerativeUISurfaceManager = class {
1391
1706
  * to every part, so an input in one part drives a binding in another.
1392
1707
  */
1393
1708
  linked = /* @__PURE__ */ new Map();
1394
- webCoreCatalog;
1395
1709
  activeThreadId;
1396
1710
  version = 0;
1397
1711
  constructor(ui, options = {}) {
1398
1712
  this.ui = ui;
1399
1713
  this.options = options;
1400
- this.webCoreCatalog = new _a2ui_web_core_catalog.Catalog(ui.id, [...ui.components.keys()].map((name) => ({
1401
- name,
1402
- schema: zod.z.any()
1403
- })), []);
1404
1714
  }
1405
1715
  subscribe = (listener) => {
1406
1716
  this.listeners.add(listener);
@@ -1472,6 +1782,7 @@ var GenerativeUISurfaceManager = class {
1472
1782
  surface.serverRejected = serverRejected;
1473
1783
  changed = true;
1474
1784
  }
1785
+ surface.a2uiSourceVersion = sourceVersionOf(content);
1475
1786
  if (changed) this.notify();
1476
1787
  }
1477
1788
  /** The surface of a `key` (see `surfaceKey`), unless it is deleted. */
@@ -1521,7 +1832,8 @@ var GenerativeUISurfaceManager = class {
1521
1832
  target: surface.target,
1522
1833
  ...Object.keys(dataModel).length > 0 ? { dataModel } : {},
1523
1834
  ...rejections.length > 0 && status !== "deleted" ? { rejected: summarizeRejections(rejections) } : {},
1524
- ...status ? { status } : {}
1835
+ ...status ? { status } : {},
1836
+ ...surface.a2uiSourceVersion ? { a2uiSourceVersion: surface.a2uiSourceVersion } : {}
1525
1837
  };
1526
1838
  }
1527
1839
  return described;
@@ -1724,7 +2036,7 @@ var GenerativeUISurfaceManager = class {
1724
2036
  if (ownedPaths.some((ownedPath) => isAtOrBelow(path, ownedPath))) return void 0;
1725
2037
  const below = ownedPaths.filter((ownedPath) => isAtOrBelow(ownedPath, path));
1726
2038
  if (below.length === 0) return merged;
1727
- const scratch = new _a2ui_web_core_state.DataModel({ value: merged.value });
2039
+ const scratch = new DataModel({ value: merged.value });
1728
2040
  const prefix = path === "/" ? "" : path;
1729
2041
  for (const ownedPath of below) {
1730
2042
  const relative = ownedPath.slice(prefix.length);
@@ -1743,7 +2055,7 @@ var GenerativeUISurfaceManager = class {
1743
2055
  threadId,
1744
2056
  surfaceId: content.surfaceId,
1745
2057
  agentId,
1746
- model: new _a2ui_web_core_state.SurfaceModel(content.surfaceId, this.webCoreCatalog),
2058
+ model: new SurfaceModel(content.surfaceId),
1747
2059
  createdAt: ++creationCounter,
1748
2060
  target: content.target,
1749
2061
  status: content.status,
@@ -1767,7 +2079,7 @@ var GenerativeUISurfaceManager = class {
1767
2079
  closeSurface(surface) {
1768
2080
  surface.deleted = true;
1769
2081
  surface.model.dispose();
1770
- surface.model = new _a2ui_web_core_state.SurfaceModel(surface.surfaceId, this.webCoreCatalog);
2082
+ surface.model = new SurfaceModel(surface.surfaceId);
1771
2083
  this.owned.delete(surface.key);
1772
2084
  this.linked.delete(surface.key);
1773
2085
  }
@@ -1943,7 +2255,7 @@ var GenerativeUISurfaceManager = class {
1943
2255
  return;
1944
2256
  }
1945
2257
  if (existing) model.componentsModel.removeComponent(id);
1946
- model.componentsModel.addComponent(new _a2ui_web_core_state.ComponentModel(id, component, properties));
2258
+ model.componentsModel.addComponent(new ComponentModel(id, component, properties));
1947
2259
  }
1948
2260
  };
1949
2261