@graphrefly/graphrefly 0.15.0 → 0.16.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.
Files changed (71) hide show
  1. package/dist/{chunk-2ZICUAUJ.js → chunk-26A4E7J7.js} +10 -12
  2. package/dist/chunk-26A4E7J7.js.map +1 -0
  3. package/dist/{chunk-CRACCCJY.js → chunk-3BLRREFM.js} +29 -5
  4. package/dist/chunk-3BLRREFM.js.map +1 -0
  5. package/dist/{chunk-XQ4UMAU7.js → chunk-ITDVOCFO.js} +2 -2
  6. package/dist/{chunk-YW6LFCFS.js → chunk-LKP7IWRV.js} +3 -3
  7. package/dist/{chunk-4APC3AFN.js → chunk-RLVFZDCE.js} +22 -49
  8. package/dist/chunk-RLVFZDCE.js.map +1 -0
  9. package/dist/{chunk-GKRKDYNT.js → chunk-RZSQ7P2C.js} +3 -3
  10. package/dist/{chunk-ZHTHUX5D.js → chunk-SHRJH2DN.js} +3 -3
  11. package/dist/{chunk-H243FWYP.js → chunk-VZY2B2LU.js} +1 -1
  12. package/dist/{chunk-H243FWYP.js.map → chunk-VZY2B2LU.js.map} +1 -1
  13. package/dist/{chunk-QVYZD65U.js → chunk-YX263TXI.js} +10 -38
  14. package/dist/chunk-YX263TXI.js.map +1 -0
  15. package/dist/compat/nestjs/index.cjs +38 -41
  16. package/dist/compat/nestjs/index.cjs.map +1 -1
  17. package/dist/compat/nestjs/index.d.cts +4 -4
  18. package/dist/compat/nestjs/index.d.ts +4 -4
  19. package/dist/compat/nestjs/index.js +7 -7
  20. package/dist/core/index.cjs.map +1 -1
  21. package/dist/core/index.d.cts +2 -2
  22. package/dist/core/index.d.ts +2 -2
  23. package/dist/core/index.js +3 -3
  24. package/dist/extra/index.cjs +27 -78
  25. package/dist/extra/index.cjs.map +1 -1
  26. package/dist/extra/index.d.cts +4 -4
  27. package/dist/extra/index.d.ts +4 -4
  28. package/dist/extra/index.js +3 -3
  29. package/dist/graph/index.cjs +26 -2
  30. package/dist/graph/index.cjs.map +1 -1
  31. package/dist/graph/index.d.cts +3 -3
  32. package/dist/graph/index.d.ts +3 -3
  33. package/dist/graph/index.js +4 -4
  34. package/dist/{graph-BXIK5Dq5.d.ts → graph-Dc-P9BVm.d.ts} +15 -3
  35. package/dist/{graph-BhADtuFU.d.cts → graph-fCsaaVIa.d.cts} +15 -3
  36. package/dist/{index-DSp5R3Xq.d.ts → index-BBVBYPxr.d.cts} +4 -4
  37. package/dist/{index-BkToATim.d.ts → index-BR19vQME.d.ts} +1 -1
  38. package/dist/{index-BNB0KjKe.d.ts → index-BmoUvOGN.d.ts} +1 -1
  39. package/dist/{index-DBhLjWSV.d.cts → index-ClaKZFPl.d.cts} +100 -31
  40. package/dist/{index-Dqemj9q0.d.cts → index-DWq0P9T6.d.ts} +4 -4
  41. package/dist/{index-Wa8jXne6.d.cts → index-Db27z6Ki.d.cts} +1 -1
  42. package/dist/{index-fYObbpUw.d.ts → index-DhXznWyH.d.ts} +2 -2
  43. package/dist/{index-DANO9Gg7.d.cts → index-DlGMf_Qe.d.cts} +2 -2
  44. package/dist/{index-CKyYg4IP.d.ts → index-N704txAA.d.ts} +100 -31
  45. package/dist/{index-DKIyo4Bq.d.cts → index-YlOH1Gw6.d.cts} +1 -1
  46. package/dist/index.cjs +109 -186
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +22 -35
  49. package/dist/index.d.ts +22 -35
  50. package/dist/index.js +63 -111
  51. package/dist/index.js.map +1 -1
  52. package/dist/{meta-CrZUQAJ6.d.cts → meta-BV4pj9ML.d.cts} +6 -0
  53. package/dist/{meta-CrZUQAJ6.d.ts → meta-BV4pj9ML.d.ts} +6 -0
  54. package/dist/observable-Cz-AWhwR.d.cts +42 -0
  55. package/dist/observable-DCqlwGyl.d.ts +42 -0
  56. package/dist/patterns/reactive-layout/index.cjs +26 -2
  57. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  58. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  59. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  60. package/dist/patterns/reactive-layout/index.js +4 -4
  61. package/package.json +1 -1
  62. package/dist/chunk-2ZICUAUJ.js.map +0 -1
  63. package/dist/chunk-4APC3AFN.js.map +0 -1
  64. package/dist/chunk-CRACCCJY.js.map +0 -1
  65. package/dist/chunk-QVYZD65U.js.map +0 -1
  66. package/dist/reactive-log-ChbpUrY2.d.cts +0 -137
  67. package/dist/reactive-log-DV--7BWd.d.ts +0 -137
  68. /package/dist/{chunk-XQ4UMAU7.js.map → chunk-ITDVOCFO.js.map} +0 -0
  69. /package/dist/{chunk-YW6LFCFS.js.map → chunk-LKP7IWRV.js.map} +0 -0
  70. /package/dist/{chunk-GKRKDYNT.js.map → chunk-RZSQ7P2C.js.map} +0 -0
  71. /package/dist/{chunk-ZHTHUX5D.js.map → chunk-SHRJH2DN.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -2997,15 +2997,14 @@ var GraphReflyEventExplorer = class {
2997
2997
  if (!cqrsGraph) return;
2998
2998
  cqrsGraph.event(meta.eventName);
2999
2999
  const eventNode = cqrsGraph.resolve(meta.eventName);
3000
- const currentSnap = eventNode.get();
3001
- const existingEntries = currentSnap?.value?.entries;
3000
+ const existingEntries = eventNode.get();
3002
3001
  let lastSeq = existingEntries && existingEntries.length > 0 ? existingEntries[existingEntries.length - 1].seq : 0;
3003
3002
  const handle = this.observeNodeOn(cqrsGraph, meta.eventName);
3004
3003
  const unsub = handle.subscribe((msgs) => {
3005
3004
  for (const m of msgs) {
3006
3005
  if (m[0] === DATA) {
3007
- const snap = m[1];
3008
- for (const entry of snap.value.entries) {
3006
+ const entries = m[1];
3007
+ for (const entry of entries) {
3009
3008
  if (entry.seq > lastSeq) {
3010
3009
  bound(entry);
3011
3010
  lastSeq = entry.seq;
@@ -3919,6 +3918,7 @@ var Graph = class _Graph {
3919
3918
  /** @internal — exposed for {@link teardownMountedGraph}. */
3920
3919
  _mounts = /* @__PURE__ */ new Map();
3921
3920
  _autoCheckpointDisposers = /* @__PURE__ */ new Set();
3921
+ _disposers = /* @__PURE__ */ new Set();
3922
3922
  _defaultVersioningLevel;
3923
3923
  static registerFactory(pattern, factory) {
3924
3924
  if (!pattern) {
@@ -5054,10 +5054,33 @@ var Graph = class _Graph {
5054
5054
  // Lifecycle & persistence (§3.7–§3.8)
5055
5055
  // ——————————————————————————————————————————————————————————————
5056
5056
  /**
5057
- * Sends `[[TEARDOWN]]` to all nodes, then clears registries on this graph and every
5058
- * mounted subgraph (§3.7). The instance is left empty and may be reused with {@link Graph.add}.
5057
+ * Register a cleanup function to be called on {@link Graph.destroy}.
5058
+ *
5059
+ * Factories use this to attach teardown logic for internal nodes, keepalive
5060
+ * subscriptions, or other resources that are not registered on the graph and
5061
+ * would otherwise leak on repeated create/destroy cycles.
5062
+ *
5063
+ * Returns a removal function — call it to unregister the disposer early.
5064
+ */
5065
+ addDisposer(fn) {
5066
+ this._disposers.add(fn);
5067
+ return () => {
5068
+ this._disposers.delete(fn);
5069
+ };
5070
+ }
5071
+ /**
5072
+ * Drains disposers (registered via {@link addDisposer}), then sends `[[TEARDOWN]]` to all
5073
+ * nodes and clears registries on this graph and every mounted subgraph (§3.7).
5074
+ * The instance is left empty and may be reused with {@link Graph.add}.
5059
5075
  */
5060
5076
  destroy() {
5077
+ for (const dispose of [...this._disposers]) {
5078
+ try {
5079
+ dispose();
5080
+ } catch {
5081
+ }
5082
+ }
5083
+ this._disposers.clear();
5061
5084
  this.signal([[TEARDOWN]], { internal: true });
5062
5085
  for (const dispose of [...this._autoCheckpointDisposers]) {
5063
5086
  try {
@@ -5666,25 +5689,7 @@ var ResettableTimer = class {
5666
5689
  }
5667
5690
  };
5668
5691
 
5669
- // src/extra/reactive-base.ts
5670
- function snapshotEqualsVersion(a, b) {
5671
- if (typeof a !== "object" || a == null || typeof b !== "object" || b == null) {
5672
- return Object.is(a, b);
5673
- }
5674
- if (!("version" in a) || !("version" in b)) return Object.is(a, b);
5675
- return a.version === b.version;
5676
- }
5677
- function bumpVersion(current, nextValue, v0) {
5678
- if (v0 != null) {
5679
- return { version: current.version + 1, value: nextValue, v0 };
5680
- }
5681
- return { version: current.version + 1, value: nextValue };
5682
- }
5683
-
5684
5692
  // src/extra/reactive-log.ts
5685
- function emptySnapshot() {
5686
- return { version: 0, value: { entries: [] } };
5687
- }
5688
5693
  function keepaliveDerived(n) {
5689
5694
  return n.subscribe(() => {
5690
5695
  });
@@ -5698,22 +5703,16 @@ function reactiveLog(initial, options = {}) {
5698
5703
  if (maxSize !== void 0 && buf.length > maxSize) {
5699
5704
  buf.splice(0, buf.length - maxSize);
5700
5705
  }
5701
- let current = buf.length > 0 ? { version: 1, value: { entries: [...buf] } } : emptySnapshot();
5702
- const entries = state(current, {
5706
+ const entries = state(buf.length > 0 ? [...buf] : [], {
5703
5707
  name,
5704
5708
  describeKind: "state",
5705
- equals: snapshotEqualsVersion
5709
+ equals: (a, b) => a === b
5706
5710
  });
5707
5711
  function pushSnapshot() {
5708
- const ev = entries.v;
5709
- current = bumpVersion(
5710
- current,
5711
- { entries: [...buf] },
5712
- ev ? { id: ev.id, version: ev.version } : void 0
5713
- );
5712
+ const snapshot = [...buf];
5714
5713
  batch(() => {
5715
5714
  entries.down([[DIRTY]]);
5716
- entries.down([[DATA, current]]);
5715
+ entries.down([[DATA, snapshot]]);
5717
5716
  });
5718
5717
  }
5719
5718
  function trimBuf() {
@@ -5756,13 +5755,12 @@ function reactiveLog(initial, options = {}) {
5756
5755
  if (n < 0) {
5757
5756
  throw new RangeError("n must be >= 0");
5758
5757
  }
5759
- const snap = entries.get();
5760
- const e = snap.value.entries;
5758
+ const e = entries.get();
5761
5759
  const init = n === 0 ? [] : e.slice(Math.max(0, e.length - n));
5762
5760
  const out = derived(
5763
5761
  [entries],
5764
5762
  ([s]) => {
5765
- const list = s.value.entries;
5763
+ const list = s;
5766
5764
  return n === 0 ? [] : list.slice(Math.max(0, list.length - n));
5767
5765
  },
5768
5766
  { initial: init, describeKind: "derived" }
@@ -5777,13 +5775,12 @@ function logSlice(log, start, stop) {
5777
5775
  if (start < 0) {
5778
5776
  throw new RangeError("start must be >= 0");
5779
5777
  }
5780
- const snap = log.entries.get();
5781
- const e = snap.value.entries;
5778
+ const e = log.entries.get();
5782
5779
  const init = stop === void 0 ? e.slice(start) : e.slice(start, stop);
5783
5780
  const out = derived(
5784
5781
  [log.entries],
5785
5782
  ([s]) => {
5786
- const list = s.value.entries;
5783
+ const list = s;
5787
5784
  return stop === void 0 ? list.slice(start) : list.slice(start, stop);
5788
5785
  },
5789
5786
  { initial: init, describeKind: "derived" }
@@ -6063,8 +6060,8 @@ var CqrsGraph = class extends Graph {
6063
6060
  (snapshots) => {
6064
6061
  const allEvents = [];
6065
6062
  for (const snapshot of snapshots) {
6066
- const snap = snapshot;
6067
- allEvents.push(...snap.value.entries);
6063
+ const entries = snapshot;
6064
+ allEvents.push(...entries);
6068
6065
  }
6069
6066
  allEvents.sort((a, b) => a.timestampNs - b.timestampNs || a.seq - b.seq);
6070
6067
  return reducer(initial, allEvents);
@@ -6105,9 +6102,8 @@ var CqrsGraph = class extends Graph {
6105
6102
  (snapshots) => {
6106
6103
  const errNode = sagaRef.n.meta.error;
6107
6104
  for (let i = 0; i < snapshots.length; i++) {
6108
- const snap = snapshots[i];
6105
+ const entries = snapshots[i];
6109
6106
  const eName = eventNames[i];
6110
- const entries = snap.value.entries;
6111
6107
  const lastCount = lastCounts.get(eName) ?? 0;
6112
6108
  if (entries.length > lastCount) {
6113
6109
  const newEntries = entries.slice(lastCount);
@@ -12046,9 +12042,6 @@ var throttleTime = throttle;
12046
12042
  var catchError = rescue;
12047
12043
 
12048
12044
  // src/extra/reactive-map.ts
12049
- function emptySnapshot2() {
12050
- return { version: 0, value: { map: /* @__PURE__ */ new Map() } };
12051
- }
12052
12045
  function isExpired(e, now) {
12053
12046
  return e.expiresAt !== void 0 && now >= e.expiresAt;
12054
12047
  }
@@ -12062,12 +12055,12 @@ function buildMap(store, now) {
12062
12055
  function reactiveMap(options = {}) {
12063
12056
  const { name, maxSize, defaultTtl, ...nodeOpts } = options;
12064
12057
  const store = /* @__PURE__ */ new Map();
12065
- let current = emptySnapshot2();
12066
- const n = state(current, {
12058
+ const n = state(/* @__PURE__ */ new Map(), {
12067
12059
  ...nodeOpts,
12068
12060
  name,
12069
12061
  describeKind: "state",
12070
- equals: snapshotEqualsVersion
12062
+ equals: (a, b) => a === b
12063
+ // identity; pushSnapshot always creates a new Map
12071
12064
  });
12072
12065
  function pruneExpiredInternal() {
12073
12066
  const now = monotonicNs();
@@ -12092,11 +12085,9 @@ function reactiveMap(options = {}) {
12092
12085
  pruneExpiredInternal();
12093
12086
  const now = monotonicNs();
12094
12087
  const map3 = buildMap(store, now);
12095
- const nv = n.v;
12096
- current = bumpVersion(current, { map: map3 }, nv ? { id: nv.id, version: nv.version } : void 0);
12097
12088
  batch(() => {
12098
12089
  n.down([[DIRTY]]);
12099
- n.down([[DATA, current]]);
12090
+ n.down([[DATA, map3]]);
12100
12091
  });
12101
12092
  }
12102
12093
  function touchLru(key) {
@@ -12106,7 +12097,7 @@ function reactiveMap(options = {}) {
12106
12097
  store.set(key, e);
12107
12098
  }
12108
12099
  const bundle = {
12109
- node: n,
12100
+ entries: n,
12110
12101
  get(key) {
12111
12102
  const now = monotonicNs();
12112
12103
  const e = store.get(key);
@@ -12203,13 +12194,11 @@ function keepalive2(node2) {
12203
12194
  node2.subscribe(() => void 0);
12204
12195
  }
12205
12196
  function mapFromSnapshot(snapshot) {
12206
- if (typeof snapshot === "object" && snapshot !== null && "value" in snapshot && typeof snapshot.value === "object" && snapshot.value !== null && "map" in snapshot.value) {
12207
- return snapshot.value.map ?? /* @__PURE__ */ new Map();
12208
- }
12197
+ if (snapshot instanceof Map) return snapshot;
12209
12198
  return /* @__PURE__ */ new Map();
12210
12199
  }
12211
12200
  function asReadonlyMap(store) {
12212
- return mapFromSnapshot(store.node.get());
12201
+ return mapFromSnapshot(store.entries.get());
12213
12202
  }
12214
12203
  function applyExtraction(store, extraction) {
12215
12204
  if (!Array.isArray(extraction.upsert)) {
@@ -12237,7 +12226,7 @@ function distill(source, extractFn, opts) {
12237
12226
  if (opts.evict) {
12238
12227
  const evictionKeys = dynamicNode((get) => {
12239
12228
  const out = [];
12240
- const snapshot = mapFromSnapshot(get(store.node));
12229
+ const snapshot = mapFromSnapshot(get(store.entries));
12241
12230
  for (const [key, mem] of snapshot) {
12242
12231
  const verdict = opts.evict(key, mem);
12243
12232
  if (isNodeLike(verdict)) {
@@ -12267,7 +12256,7 @@ function distill(source, extractFn, opts) {
12267
12256
  applyExtraction(store, extraction);
12268
12257
  });
12269
12258
  }
12270
- const compact = derived([store.node, contextNode], ([snapshot, context]) => {
12259
+ const compact = derived([store.entries, contextNode], ([snapshot, context]) => {
12271
12260
  const entries = [...mapFromSnapshot(snapshot).entries()].map(([key, value]) => ({
12272
12261
  key,
12273
12262
  value,
@@ -12285,7 +12274,7 @@ function distill(source, extractFn, opts) {
12285
12274
  }
12286
12275
  return packed;
12287
12276
  });
12288
- const size = derived([store.node], ([snapshot]) => mapFromSnapshot(snapshot).size);
12277
+ const size = derived([store.entries], ([snapshot]) => mapFromSnapshot(snapshot).size);
12289
12278
  keepalive2(compact);
12290
12279
  keepalive2(size);
12291
12280
  return { store, compact, size };
@@ -12322,9 +12311,6 @@ function pubsub() {
12322
12311
  }
12323
12312
 
12324
12313
  // src/extra/reactive-index.ts
12325
- function emptySnapshot3() {
12326
- return { version: 0, value: { rows: [] } };
12327
- }
12328
12314
  function rowKey(row) {
12329
12315
  return [row.secondary, row.primary];
12330
12316
  }
@@ -12370,31 +12356,25 @@ function keepaliveDerived2(n) {
12370
12356
  function reactiveIndex(options = {}) {
12371
12357
  const { name } = options;
12372
12358
  const buf = [];
12373
- let current = emptySnapshot3();
12374
- const ordered = state(current, {
12359
+ const ordered = state([], {
12375
12360
  name,
12376
12361
  describeKind: "state",
12377
- equals: snapshotEqualsVersion
12362
+ equals: (a, b) => a === b
12378
12363
  });
12379
12364
  const byPrimary = derived(
12380
12365
  [ordered],
12381
12366
  ([s]) => {
12382
- const rows = s.value.rows;
12367
+ const rows = s;
12383
12368
  return byPrimaryMap(rows);
12384
12369
  },
12385
12370
  { initial: /* @__PURE__ */ new Map(), describeKind: "derived" }
12386
12371
  );
12387
12372
  keepaliveDerived2(byPrimary);
12388
12373
  function pushSnapshot() {
12389
- const ov = ordered.v;
12390
- current = bumpVersion(
12391
- current,
12392
- { rows: [...buf] },
12393
- ov ? { id: ov.id, version: ov.version } : void 0
12394
- );
12374
+ const snapshot = [...buf];
12395
12375
  batch(() => {
12396
12376
  ordered.down([[DIRTY]]);
12397
- ordered.down([[DATA, current]]);
12377
+ ordered.down([[DATA, snapshot]]);
12398
12378
  });
12399
12379
  }
12400
12380
  return {
@@ -12425,28 +12405,19 @@ function reactiveIndex(options = {}) {
12425
12405
  }
12426
12406
 
12427
12407
  // src/extra/reactive-list.ts
12428
- function emptySnapshot4() {
12429
- return { version: 0, value: { items: [] } };
12430
- }
12431
12408
  function reactiveList(initial, options = {}) {
12432
12409
  const { name } = options;
12433
12410
  const buf = initial ? [...initial] : [];
12434
- let current = buf.length > 0 ? { version: 1, value: { items: [...buf] } } : emptySnapshot4();
12435
- const items = state(current, {
12411
+ const items = state(buf.length > 0 ? [...buf] : [], {
12436
12412
  name,
12437
12413
  describeKind: "state",
12438
- equals: snapshotEqualsVersion
12414
+ equals: (a, b) => a === b
12439
12415
  });
12440
12416
  function pushSnapshot() {
12441
- const iv = items.v;
12442
- current = bumpVersion(
12443
- current,
12444
- { items: [...buf] },
12445
- iv ? { id: iv.id, version: iv.version } : void 0
12446
- );
12417
+ const snapshot = [...buf];
12447
12418
  batch(() => {
12448
12419
  items.down([[DIRTY]]);
12449
- items.down([[DATA, current]]);
12420
+ items.down([[DATA, snapshot]]);
12450
12421
  });
12451
12422
  }
12452
12423
  return {
@@ -13581,7 +13552,6 @@ function promptNode(adapter, deps, prompt, opts) {
13581
13552
  }
13582
13553
  var ChatStreamGraph = class extends Graph {
13583
13554
  _log;
13584
- _keepaliveSubs = [];
13585
13555
  messages;
13586
13556
  latest;
13587
13557
  messageCount;
@@ -13596,7 +13566,7 @@ var ChatStreamGraph = class extends Graph {
13596
13566
  this.latest = derived(
13597
13567
  [this.messages],
13598
13568
  ([snapshot]) => {
13599
- const entries = snapshot.value.entries;
13569
+ const entries = snapshot;
13600
13570
  return entries.length === 0 ? void 0 : entries[entries.length - 1];
13601
13571
  },
13602
13572
  {
@@ -13608,10 +13578,10 @@ var ChatStreamGraph = class extends Graph {
13608
13578
  );
13609
13579
  this.add("latest", this.latest);
13610
13580
  this.connect("messages", "latest");
13611
- this._keepaliveSubs.push(keepalive3(this.latest));
13581
+ this.addDisposer(keepalive3(this.latest));
13612
13582
  this.messageCount = derived(
13613
13583
  [this.messages],
13614
- ([snapshot]) => snapshot.value.entries.length,
13584
+ ([snapshot]) => snapshot.length,
13615
13585
  {
13616
13586
  name: "messageCount",
13617
13587
  describeKind: "derived",
@@ -13621,7 +13591,7 @@ var ChatStreamGraph = class extends Graph {
13621
13591
  );
13622
13592
  this.add("messageCount", this.messageCount);
13623
13593
  this.connect("messages", "messageCount");
13624
- this._keepaliveSubs.push(keepalive3(this.messageCount));
13594
+ this.addDisposer(keepalive3(this.messageCount));
13625
13595
  }
13626
13596
  append(role, content, extra) {
13627
13597
  this._log.append({ role, content, ...extra });
@@ -13633,12 +13603,7 @@ var ChatStreamGraph = class extends Graph {
13633
13603
  this._log.clear();
13634
13604
  }
13635
13605
  allMessages() {
13636
- return this.messages.get().value.entries;
13637
- }
13638
- destroy() {
13639
- for (const unsub of this._keepaliveSubs) unsub();
13640
- this._keepaliveSubs.length = 0;
13641
- super.destroy();
13606
+ return this.messages.get();
13642
13607
  }
13643
13608
  };
13644
13609
  function chatStream(name, opts) {
@@ -13647,7 +13612,6 @@ function chatStream(name, opts) {
13647
13612
  var ToolRegistryGraph = class extends Graph {
13648
13613
  definitions;
13649
13614
  schemas;
13650
- _keepaliveSubs = [];
13651
13615
  constructor(name, opts = {}) {
13652
13616
  super(name, opts.graph);
13653
13617
  this.definitions = state(/* @__PURE__ */ new Map(), {
@@ -13668,7 +13632,7 @@ var ToolRegistryGraph = class extends Graph {
13668
13632
  );
13669
13633
  this.add("schemas", this.schemas);
13670
13634
  this.connect("definitions", "schemas");
13671
- this._keepaliveSubs.push(keepalive3(this.schemas));
13635
+ this.addDisposer(keepalive3(this.schemas));
13672
13636
  }
13673
13637
  register(tool) {
13674
13638
  const current = this.definitions.get();
@@ -13693,11 +13657,6 @@ var ToolRegistryGraph = class extends Graph {
13693
13657
  getDefinition(name) {
13694
13658
  return this.definitions.get().get(name);
13695
13659
  }
13696
- destroy() {
13697
- for (const unsub of this._keepaliveSubs) unsub();
13698
- this._keepaliveSubs.length = 0;
13699
- super.destroy();
13700
- }
13701
13660
  };
13702
13661
  function toolRegistry(name, opts) {
13703
13662
  return new ToolRegistryGraph(name, opts);
@@ -13842,9 +13801,7 @@ function admissionFilter3D(opts = {}) {
13842
13801
  }
13843
13802
  var DEFAULT_DECAY_RATE = Math.LN2 / (7 * 86400);
13844
13803
  function extractStoreMap(snapshot) {
13845
- if (snapshot && typeof snapshot === "object" && "value" in snapshot && typeof snapshot.value === "object" && snapshot.value !== null && "map" in snapshot.value) {
13846
- return snapshot.value.map ?? /* @__PURE__ */ new Map();
13847
- }
13804
+ if (snapshot instanceof Map) return snapshot;
13848
13805
  return /* @__PURE__ */ new Map();
13849
13806
  }
13850
13807
  function agentMemory(name, source, opts) {
@@ -13895,7 +13852,7 @@ function agentMemory(name, source, opts) {
13895
13852
  consolidateTrigger
13896
13853
  };
13897
13854
  const distillBundle = distill(filteredSource, extractFn, distillOpts);
13898
- graph.add("store", distillBundle.store.node);
13855
+ graph.add("store", distillBundle.store.entries);
13899
13856
  graph.add("compact", distillBundle.compact);
13900
13857
  graph.add("size", distillBundle.size);
13901
13858
  graph.connect("store", "compact");
@@ -13922,7 +13879,7 @@ function agentMemory(name, source, opts) {
13922
13879
  const permanentKeys = /* @__PURE__ */ new Set();
13923
13880
  const tierOf = (key) => {
13924
13881
  if (permanentKeys.has(key)) return "permanent";
13925
- const storeMap = extractStoreMap(distillBundle.store.node.get());
13882
+ const storeMap = extractStoreMap(distillBundle.store.entries.get());
13926
13883
  if (storeMap.has(key)) return "active";
13927
13884
  return "archived";
13928
13885
  };
@@ -13931,7 +13888,7 @@ function agentMemory(name, source, opts) {
13931
13888
  permanent.upsert(key, value);
13932
13889
  };
13933
13890
  const entryCreatedAtNs = /* @__PURE__ */ new Map();
13934
- const storeNode = distillBundle.store.node;
13891
+ const storeNode = distillBundle.store.entries;
13935
13892
  const contextNode = opts.context ? fromAny(opts.context) : state(null);
13936
13893
  const tierClassifier = effect([storeNode, contextNode], ([snapshot, ctx]) => {
13937
13894
  const storeMap = extractStoreMap(snapshot);
@@ -13998,7 +13955,7 @@ function agentMemory(name, source, opts) {
13998
13955
  if (vectors || kg) {
13999
13956
  const embedFn = opts.embedFn;
14000
13957
  const entityFn = opts.entityFn;
14001
- const storeNode = distillBundle.store.node;
13958
+ const storeNode = distillBundle.store.entries;
14002
13959
  const indexer = effect([storeNode], ([snapshot]) => {
14003
13960
  const storeMap = extractStoreMap(snapshot);
14004
13961
  for (const [key, mem] of storeMap) {
@@ -14043,7 +14000,7 @@ function agentMemory(name, source, opts) {
14043
14000
  });
14044
14001
  graph.add("retrievalTrace", traceState);
14045
14002
  retrievalTraceNode = traceState;
14046
- const storeNode = distillBundle.store.node;
14003
+ const storeNode = distillBundle.store.entries;
14047
14004
  let lastTrace = null;
14048
14005
  const retrievalDerived = derived(
14049
14006
  [queryInput, storeNode, contextNode],
@@ -14136,12 +14093,10 @@ function agentMemory(name, source, opts) {
14136
14093
  return result;
14137
14094
  };
14138
14095
  }
14139
- const origDestroy = graph.destroy.bind(graph);
14140
- graph.destroy = () => {
14096
+ graph.addDisposer(() => {
14141
14097
  for (const unsub of keepaliveSubs) unsub();
14142
14098
  keepaliveSubs.length = 0;
14143
- origDestroy();
14144
- };
14099
+ });
14145
14100
  return Object.assign(graph, {
14146
14101
  distillBundle,
14147
14102
  compact: distillBundle.compact,
@@ -15760,7 +15715,7 @@ function funnel(name, sources, stages, opts) {
15760
15715
  });
15761
15716
  g.add(bridgeName, br);
15762
15717
  g.connect(prevOutputPath, bridgeName);
15763
- keepalive4(br);
15718
+ g.addDisposer(keepalive4(br));
15764
15719
  prevOutputPath = `${stage.name}::output`;
15765
15720
  }
15766
15721
  return g;
@@ -15812,7 +15767,7 @@ function feedback(graph, condition, reentry, opts) {
15812
15767
  });
15813
15768
  graph.add(feedbackEffectName, feedbackEffect);
15814
15769
  graph.connect(condition, feedbackEffectName);
15815
- keepalive4(feedbackEffect);
15770
+ graph.addDisposer(keepalive4(feedbackEffect));
15816
15771
  return graph;
15817
15772
  }
15818
15773
  function budgetGate(source, constraints, opts) {
@@ -16192,7 +16147,7 @@ function contentModerationGraph(name, opts) {
16192
16147
  }
16193
16148
  });
16194
16149
  g.add("__review_accumulator", reviewAccumulator);
16195
- keepalive5(reviewAccumulator);
16150
+ g.addDisposer(keepalive5(reviewAccumulator));
16196
16151
  try {
16197
16152
  g.connect("stratify::branch/review", "__review_accumulator");
16198
16153
  } catch {
@@ -16240,8 +16195,7 @@ function contentModerationGraph(name, opts) {
16240
16195
  const fbCondition = derived(
16241
16196
  [reviewLog.entries, policy2],
16242
16197
  (vals) => {
16243
- const snap = vals[0];
16244
- const entries = snap?.value?.entries;
16198
+ const entries = vals[0];
16245
16199
  if (entries && entries.length > 0) {
16246
16200
  const latest = entries[entries.length - 1];
16247
16201
  if (latest && latest.falsePositive) {
@@ -17473,7 +17427,6 @@ function messagingMeta(kind, extra) {
17473
17427
  }
17474
17428
  var TopicGraph = class extends Graph {
17475
17429
  _log;
17476
- _keepaliveDisposers = [];
17477
17430
  events;
17478
17431
  latest;
17479
17432
  constructor(name, opts = {}) {
@@ -17484,7 +17437,7 @@ var TopicGraph = class extends Graph {
17484
17437
  this.latest = derived(
17485
17438
  [this.events],
17486
17439
  ([snapshot]) => {
17487
- const entries = snapshot.value.entries;
17440
+ const entries = snapshot;
17488
17441
  return entries.length === 0 ? void 0 : entries[entries.length - 1];
17489
17442
  },
17490
17443
  {
@@ -17496,23 +17449,16 @@ var TopicGraph = class extends Graph {
17496
17449
  );
17497
17450
  this.add("latest", this.latest);
17498
17451
  this.connect("events", "latest");
17499
- this._keepaliveDisposers.push(keepalive6(this.latest));
17500
- }
17501
- destroy() {
17502
- for (const dispose of this._keepaliveDisposers) dispose();
17503
- this._keepaliveDisposers.length = 0;
17504
- super.destroy();
17452
+ this.addDisposer(keepalive6(this.latest));
17505
17453
  }
17506
17454
  publish(value) {
17507
17455
  this._log.append(value);
17508
17456
  }
17509
17457
  retained() {
17510
- const snapshot = this.events.get();
17511
- return snapshot.value.entries;
17458
+ return this.events.get();
17512
17459
  }
17513
17460
  };
17514
17461
  var SubscriptionGraph = class extends Graph {
17515
- _keepaliveDisposers = [];
17516
17462
  source;
17517
17463
  cursor;
17518
17464
  available;
@@ -17537,7 +17483,7 @@ var SubscriptionGraph = class extends Graph {
17537
17483
  this.available = derived(
17538
17484
  [this.source, this.cursor],
17539
17485
  ([sourceSnapshot, cursor]) => {
17540
- const entries = sourceSnapshot.value.entries;
17486
+ const entries = sourceSnapshot;
17541
17487
  const start = Math.max(0, Math.trunc(cursor ?? 0));
17542
17488
  return entries.slice(start);
17543
17489
  },
@@ -17552,13 +17498,8 @@ var SubscriptionGraph = class extends Graph {
17552
17498
  this.connect("topic::events", "source");
17553
17499
  this.connect("source", "available");
17554
17500
  this.connect("cursor", "available");
17555
- this._keepaliveDisposers.push(keepalive6(this.source));
17556
- this._keepaliveDisposers.push(keepalive6(this.available));
17557
- }
17558
- destroy() {
17559
- for (const dispose of this._keepaliveDisposers) dispose();
17560
- this._keepaliveDisposers.length = 0;
17561
- super.destroy();
17501
+ this.addDisposer(keepalive6(this.source));
17502
+ this.addDisposer(keepalive6(this.available));
17562
17503
  }
17563
17504
  ack(count) {
17564
17505
  const available = this.available.get();
@@ -17580,7 +17521,6 @@ var SubscriptionGraph = class extends Graph {
17580
17521
  var JobQueueGraph = class extends Graph {
17581
17522
  _pending;
17582
17523
  _jobs;
17583
- _keepaliveDisposers = [];
17584
17524
  _seq = 0;
17585
17525
  pending;
17586
17526
  jobs;
@@ -17590,27 +17530,18 @@ var JobQueueGraph = class extends Graph {
17590
17530
  this._pending = reactiveList([], { name: "pending" });
17591
17531
  this._jobs = reactiveMap({ name: "jobs" });
17592
17532
  this.pending = this._pending.items;
17593
- this.jobs = this._jobs.node;
17533
+ this.jobs = this._jobs.entries;
17594
17534
  this.add("pending", this.pending);
17595
17535
  this.add("jobs", this.jobs);
17596
- this.depth = derived(
17597
- [this.pending],
17598
- ([snapshot]) => snapshot.value.items.length,
17599
- {
17600
- name: "depth",
17601
- describeKind: "derived",
17602
- meta: messagingMeta("queue_depth"),
17603
- initial: 0
17604
- }
17605
- );
17536
+ this.depth = derived([this.pending], ([snapshot]) => snapshot.length, {
17537
+ name: "depth",
17538
+ describeKind: "derived",
17539
+ meta: messagingMeta("queue_depth"),
17540
+ initial: 0
17541
+ });
17606
17542
  this.add("depth", this.depth);
17607
17543
  this.connect("pending", "depth");
17608
- this._keepaliveDisposers.push(keepalive6(this.depth));
17609
- }
17610
- destroy() {
17611
- for (const dispose of this._keepaliveDisposers) dispose();
17612
- this._keepaliveDisposers.length = 0;
17613
- super.destroy();
17544
+ this.addDisposer(keepalive6(this.depth));
17614
17545
  }
17615
17546
  enqueue(payload, opts = {}) {
17616
17547
  const id = opts.id ?? `${this.name}-${++this._seq}`;
@@ -17633,8 +17564,7 @@ var JobQueueGraph = class extends Graph {
17633
17564
  if (max === 0) return [];
17634
17565
  const out = [];
17635
17566
  while (out.length < max) {
17636
- const snapshot = this.pending.get();
17637
- const ids = snapshot.value.items;
17567
+ const ids = this.pending.get();
17638
17568
  if (ids.length === 0) break;
17639
17569
  const id = this._pending.pop(0);
17640
17570
  const job = this._jobs.get(id);
@@ -17670,7 +17600,6 @@ var JobQueueGraph = class extends Graph {
17670
17600
  var JobFlowGraph = class extends Graph {
17671
17601
  _stageNames;
17672
17602
  _queues = /* @__PURE__ */ new Map();
17673
- _keepaliveDisposers = [];
17674
17603
  _completed;
17675
17604
  completed;
17676
17605
  completedCount;
@@ -17695,7 +17624,7 @@ var JobFlowGraph = class extends Graph {
17695
17624
  this.add("completed", this.completed);
17696
17625
  this.completedCount = derived(
17697
17626
  [this.completed],
17698
- ([snapshot]) => snapshot.value.entries.length,
17627
+ ([snapshot]) => snapshot.length,
17699
17628
  {
17700
17629
  name: "completedCount",
17701
17630
  describeKind: "derived",
@@ -17705,7 +17634,7 @@ var JobFlowGraph = class extends Graph {
17705
17634
  );
17706
17635
  this.add("completedCount", this.completedCount);
17707
17636
  this.connect("completed", "completedCount");
17708
- this._keepaliveDisposers.push(keepalive6(this.completedCount));
17637
+ this.addDisposer(keepalive6(this.completedCount));
17709
17638
  const maxPerPump = Math.max(
17710
17639
  1,
17711
17640
  requireNonNegativeInt(opts.maxPerPump ?? DEFAULT_MAX_PER_PUMP, "job flow maxPerPump")
@@ -17745,14 +17674,9 @@ var JobFlowGraph = class extends Graph {
17745
17674
  );
17746
17675
  this.add(`pump_${stage}`, pump);
17747
17676
  this.connect(`${stage}::pending`, `pump_${stage}`);
17748
- this._keepaliveDisposers.push(keepalive6(pump));
17677
+ this.addDisposer(keepalive6(pump));
17749
17678
  }
17750
17679
  }
17751
- destroy() {
17752
- for (const dispose of this._keepaliveDisposers) dispose();
17753
- this._keepaliveDisposers.length = 0;
17754
- super.destroy();
17755
- }
17756
17680
  stages() {
17757
17681
  return this._stageNames;
17758
17682
  }
@@ -17765,14 +17689,12 @@ var JobFlowGraph = class extends Graph {
17765
17689
  return this.queue(this._stageNames[0]).enqueue(payload, opts);
17766
17690
  }
17767
17691
  retainedCompleted() {
17768
- const snapshot = this.completed.get();
17769
- return snapshot.value.entries;
17692
+ return this.completed.get();
17770
17693
  }
17771
17694
  };
17772
17695
  var TopicBridgeGraph = class extends Graph {
17773
17696
  _sourceSub;
17774
17697
  _target;
17775
- _keepaliveDisposers = [];
17776
17698
  bridgedCount;
17777
17699
  constructor(name, sourceTopic, targetTopic, opts = {}) {
17778
17700
  super(name, opts.graph);
@@ -17817,12 +17739,7 @@ var TopicBridgeGraph = class extends Graph {
17817
17739
  );
17818
17740
  this.add("pump", pump);
17819
17741
  this.connect("subscription::available", "pump");
17820
- this._keepaliveDisposers.push(keepalive6(pump));
17821
- }
17822
- destroy() {
17823
- for (const dispose of this._keepaliveDisposers) dispose();
17824
- this._keepaliveDisposers.length = 0;
17825
- super.destroy();
17742
+ this.addDisposer(keepalive6(pump));
17826
17743
  }
17827
17744
  };
17828
17745
  function topic(name, opts) {
@@ -18114,7 +18031,7 @@ function gate(graph, name, source, opts) {
18114
18031
  isOpenNode.down([[DATA, false]]);
18115
18032
  }
18116
18033
  };
18117
- countNode.subscribe(() => void 0);
18034
+ graph.addDisposer(countNode.subscribe(() => void 0));
18118
18035
  registerStep(graph, name, output, src.path ? [src.path] : []);
18119
18036
  const internal = new Graph(`${name}_state`);
18120
18037
  internal.add("pending", pendingNode);
@@ -18361,9 +18278,9 @@ var DEFAULT_QUEUE_CONFIGS = {
18361
18278
  function strategyModel() {
18362
18279
  const _map = reactiveMap({ name: "strategy-entries" });
18363
18280
  const snapshot = derived(
18364
- [_map.node],
18281
+ [_map.entries],
18365
18282
  ([mapSnap]) => {
18366
- const raw = mapSnap.value.map;
18283
+ const raw = mapSnap;
18367
18284
  return new Map(raw);
18368
18285
  },
18369
18286
  {
@@ -18398,7 +18315,10 @@ function strategyModel() {
18398
18315
  }
18399
18316
  const _unsub = snapshot.subscribe(() => {
18400
18317
  });
18401
- return { node: snapshot, record, lookup };
18318
+ function dispose() {
18319
+ _unsub();
18320
+ }
18321
+ return { node: snapshot, record, lookup, dispose };
18402
18322
  }
18403
18323
  function priorityScore(item, strategy, lastInteractionNs, urgency, signals) {
18404
18324
  const severityWeights = { ...DEFAULT_SEVERITY_WEIGHTS, ...signals?.severityWeights };
@@ -18554,7 +18474,7 @@ function harnessLoop(name, opts) {
18554
18474
  const topic2 = queueTopics.get(item.route);
18555
18475
  if (topic2) topic2.publish(item);
18556
18476
  });
18557
- router.subscribe(() => {
18477
+ const routerUnsub = router.subscribe(() => {
18558
18478
  });
18559
18479
  const gateGraph = new Graph("gates");
18560
18480
  const gateControllers = /* @__PURE__ */ new Map();
@@ -18666,7 +18586,7 @@ function harnessLoop(name, opts) {
18666
18586
  }
18667
18587
  }
18668
18588
  });
18669
- fastRetry.subscribe(() => {
18589
+ const fastRetryUnsub = fastRetry.subscribe(() => {
18670
18590
  });
18671
18591
  const harness = new HarnessGraph(
18672
18592
  name,
@@ -18678,6 +18598,9 @@ function harnessLoop(name, opts) {
18678
18598
  retryTracker,
18679
18599
  reingestionTracker
18680
18600
  );
18601
+ harness.addDisposer(routerUnsub);
18602
+ harness.addDisposer(fastRetryUnsub);
18603
+ harness.addDisposer(strategy.dispose);
18681
18604
  harness.mount("intake", intake);
18682
18605
  for (const [route, topic2] of queueTopics) {
18683
18606
  harness.mount(`queue/${route}`, topic2);