@graphrefly/graphrefly 0.17.0 → 0.18.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-2PORF4RP.js → chunk-76YPZQTW.js} +2 -8
  2. package/dist/{chunk-2PORF4RP.js.map → chunk-76YPZQTW.js.map} +1 -1
  3. package/dist/{chunk-646OG3PO.js → chunk-F6ORUNO7.js} +18 -51
  4. package/dist/chunk-F6ORUNO7.js.map +1 -0
  5. package/dist/{chunk-EBNKJULL.js → chunk-FCLROC4Q.js} +2 -2
  6. package/dist/chunk-FCLROC4Q.js.map +1 -0
  7. package/dist/{chunk-F2ULI3Q3.js → chunk-J7S54G7I.js} +1 -2
  8. package/dist/{chunk-XJ6EMQ22.js → chunk-KJGUP35I.js} +3 -9
  9. package/dist/chunk-KJGUP35I.js.map +1 -0
  10. package/dist/{chunk-IHJHBADD.js → chunk-LB3RYLSC.js} +206 -173
  11. package/dist/chunk-LB3RYLSC.js.map +1 -0
  12. package/dist/{chunk-R6OHUUYB.js → chunk-TNKODJ6E.js} +2 -6
  13. package/dist/chunk-TNKODJ6E.js.map +1 -0
  14. package/dist/{chunk-YXROQFXZ.js → chunk-UVWEKTYC.js} +2 -2
  15. package/dist/compat/nestjs/index.cjs +221 -224
  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 +6 -12
  20. package/dist/core/index.cjs +0 -83
  21. package/dist/core/index.cjs.map +1 -1
  22. package/dist/core/index.d.cts +2 -2
  23. package/dist/core/index.d.ts +2 -2
  24. package/dist/core/index.js +2 -6
  25. package/dist/extra/index.cjs +17 -53
  26. package/dist/extra/index.cjs.map +1 -1
  27. package/dist/extra/index.d.cts +4 -4
  28. package/dist/extra/index.d.ts +4 -4
  29. package/dist/extra/index.js +2 -8
  30. package/dist/graph/index.cjs +204 -171
  31. package/dist/graph/index.cjs.map +1 -1
  32. package/dist/graph/index.d.cts +3 -3
  33. package/dist/graph/index.d.ts +3 -3
  34. package/dist/graph/index.js +3 -3
  35. package/dist/{graph-Dc-P9BVm.d.ts → graph-BYFlyNpX.d.cts} +47 -45
  36. package/dist/{graph-fCsaaVIa.d.cts → graph-gISB9n3n.d.ts} +47 -45
  37. package/dist/{index-N704txAA.d.ts → index-7WnwgjMu.d.ts} +5 -7
  38. package/dist/{index-DWq0P9T6.d.ts → index-B43mC7uY.d.cts} +5 -7
  39. package/dist/{index-BmoUvOGN.d.ts → index-B80mMeuf.d.ts} +2 -4
  40. package/dist/{index-DlGMf_Qe.d.cts → index-BqOWSFhr.d.cts} +2 -2
  41. package/dist/{index-BBVBYPxr.d.cts → index-CEDaJaYE.d.ts} +5 -7
  42. package/dist/{index-DhXznWyH.d.ts → index-CgKPpiu8.d.ts} +2 -2
  43. package/dist/{index-D7y9Q8W4.d.ts → index-Ci_vPaVm.d.cts} +4 -6
  44. package/dist/{index-4OIX-q0C.d.cts → index-DKaB2x0T.d.ts} +4 -6
  45. package/dist/{index-ClaKZFPl.d.cts → index-D_tUMcpz.d.cts} +5 -7
  46. package/dist/{index-YlOH1Gw6.d.cts → index-EmzYk-TG.d.cts} +2 -4
  47. package/dist/index.cjs +312 -239
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +51 -13
  50. package/dist/index.d.ts +51 -13
  51. package/dist/index.js +103 -24
  52. package/dist/index.js.map +1 -1
  53. package/dist/{meta-BV4pj9ML.d.cts → meta-npl5b97j.d.cts} +1 -53
  54. package/dist/{meta-BV4pj9ML.d.ts → meta-npl5b97j.d.ts} +1 -53
  55. package/dist/observable-DFBCBELR.d.cts +36 -0
  56. package/dist/observable-oAGygKvc.d.ts +36 -0
  57. package/dist/patterns/reactive-layout/index.cjs +204 -171
  58. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  59. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  60. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  61. package/dist/patterns/reactive-layout/index.js +3 -3
  62. package/package.json +1 -1
  63. package/dist/chunk-646OG3PO.js.map +0 -1
  64. package/dist/chunk-EBNKJULL.js.map +0 -1
  65. package/dist/chunk-IHJHBADD.js.map +0 -1
  66. package/dist/chunk-R6OHUUYB.js.map +0 -1
  67. package/dist/chunk-XJ6EMQ22.js.map +0 -1
  68. package/dist/observable-Cz-AWhwR.d.cts +0 -42
  69. package/dist/observable-DCqlwGyl.d.ts +0 -42
  70. /package/dist/{chunk-F2ULI3Q3.js.map → chunk-J7S54G7I.js.map} +0 -0
  71. /package/dist/{chunk-YXROQFXZ.js.map → chunk-UVWEKTYC.js.map} +0 -0
@@ -95,11 +95,8 @@ __export(nestjs_exports, {
95
95
  getActor: () => getActor,
96
96
  getGraphToken: () => getGraphToken,
97
97
  getNodeToken: () => getNodeToken,
98
- observeGraph$: () => observeGraph$,
99
- observeNode$: () => observeNode$,
100
98
  observeSSE: () => observeSSE,
101
99
  observeSubscription: () => observeSubscription,
102
- toMessages$: () => toMessages$,
103
100
  toObservable: () => toObservable
104
101
  });
105
102
  module.exports = __toCommonJS(nestjs_exports);
@@ -137,48 +134,28 @@ function propagatesToMeta(t) {
137
134
  }
138
135
 
139
136
  // src/extra/observable.ts
140
- function toObservable(node2) {
141
- return new import_rxjs.Observable((subscriber) => {
142
- const unsub = node2.subscribe((msgs) => {
143
- for (const m of msgs) {
137
+ function toObservable(node2, options) {
138
+ if (options?.raw) {
139
+ return new import_rxjs.Observable((subscriber) => {
140
+ const unsub = node2.subscribe((msgs) => {
144
141
  if (subscriber.closed) return;
145
- if (m[0] === DATA) {
146
- subscriber.next(m[1]);
147
- } else if (m[0] === ERROR) {
148
- subscriber.error(m[1]);
149
- return;
150
- } else if (m[0] === COMPLETE) {
151
- subscriber.complete();
152
- return;
142
+ subscriber.next(msgs);
143
+ for (const m of msgs) {
144
+ if (m[0] === ERROR) {
145
+ subscriber.error(m[1]);
146
+ return;
147
+ }
148
+ if (m[0] === COMPLETE) {
149
+ subscriber.complete();
150
+ return;
151
+ }
153
152
  }
154
- }
153
+ });
154
+ return unsub;
155
155
  });
156
- return unsub;
157
- });
158
- }
159
- function toMessages$(node2) {
156
+ }
160
157
  return new import_rxjs.Observable((subscriber) => {
161
158
  const unsub = node2.subscribe((msgs) => {
162
- if (subscriber.closed) return;
163
- subscriber.next(msgs);
164
- for (const m of msgs) {
165
- if (m[0] === ERROR) {
166
- subscriber.error(m[1]);
167
- return;
168
- }
169
- if (m[0] === COMPLETE) {
170
- subscriber.complete();
171
- return;
172
- }
173
- }
174
- });
175
- return unsub;
176
- });
177
- }
178
- function observeNode$(graph, path, options) {
179
- return new import_rxjs.Observable((subscriber) => {
180
- const handle = graph.observe(path, options);
181
- const unsub = handle.subscribe((msgs) => {
182
159
  for (const m of msgs) {
183
160
  if (subscriber.closed) return;
184
161
  if (m[0] === DATA) {
@@ -195,16 +172,6 @@ function observeNode$(graph, path, options) {
195
172
  return unsub;
196
173
  });
197
174
  }
198
- function observeGraph$(graph, options) {
199
- return new import_rxjs.Observable((subscriber) => {
200
- const handle = graph.observe(options);
201
- const unsub = handle.subscribe((nodePath, messages) => {
202
- if (subscriber.closed) return;
203
- subscriber.next({ path: nodePath, messages });
204
- });
205
- return unsub;
206
- });
207
- }
208
175
 
209
176
  // src/compat/nestjs/decorators.ts
210
177
  var import_common = require("@nestjs/common");
@@ -2827,7 +2794,7 @@ var RingBuffer = class {
2827
2794
  return result;
2828
2795
  }
2829
2796
  };
2830
- var SPY_ANSI_THEME = {
2797
+ var OBSERVE_ANSI_THEME = {
2831
2798
  data: "\x1B[32m",
2832
2799
  dirty: "\x1B[33m",
2833
2800
  resolved: "\x1B[36m",
@@ -2837,7 +2804,7 @@ var SPY_ANSI_THEME = {
2837
2804
  path: "\x1B[90m",
2838
2805
  reset: "\x1B[0m"
2839
2806
  };
2840
- var SPY_NO_COLOR_THEME = {
2807
+ var OBSERVE_NO_COLOR_THEME = {
2841
2808
  data: "",
2842
2809
  dirty: "",
2843
2810
  resolved: "",
@@ -2857,9 +2824,9 @@ function describeData(value) {
2857
2824
  return "[unserializable]";
2858
2825
  }
2859
2826
  }
2860
- function resolveSpyTheme(theme) {
2861
- if (theme === "none") return SPY_NO_COLOR_THEME;
2862
- if (theme === "ansi" || theme == null) return SPY_ANSI_THEME;
2827
+ function resolveObserveTheme(theme) {
2828
+ if (theme === "none") return OBSERVE_NO_COLOR_THEME;
2829
+ if (theme === "ansi" || theme == null) return OBSERVE_ANSI_THEME;
2863
2830
  return {
2864
2831
  data: theme.data ?? "",
2865
2832
  dirty: theme.dirty ?? "",
@@ -3630,9 +3597,13 @@ var Graph = class _Graph {
3630
3597
  if (actor2 != null && !target.allowsObserve(actor2)) {
3631
3598
  throw new GuardDenied({ actor: actor2, action: "observe", nodeName: path });
3632
3599
  }
3633
- const wantsStructured2 = resolved.structured === true || resolved.timeline === true || resolved.causal === true || resolved.derived === true || resolved.detail === "minimal" || resolved.detail === "full";
3634
- if (wantsStructured2 && _Graph.inspectorEnabled) {
3635
- return this._createObserveResult(path, target, resolved);
3600
+ const wantsStructured2 = resolved.structured === true || resolved.timeline === true || resolved.causal === true || resolved.derived === true || resolved.detail === "minimal" || resolved.detail === "full" || resolved.format != null;
3601
+ if (wantsStructured2) {
3602
+ const result = _Graph.inspectorEnabled ? this._createObserveResult(path, target, resolved) : this._createFallbackObserveResult(path, resolved);
3603
+ if (resolved.format != null) {
3604
+ this._attachFormatLogger(result, resolved);
3605
+ }
3606
+ return result;
3636
3607
  }
3637
3608
  return {
3638
3609
  subscribe(sink) {
@@ -3650,9 +3621,13 @@ var Graph = class _Graph {
3650
3621
  }
3651
3622
  const opts = resolveObserveDetail(pathOrOpts);
3652
3623
  const actor = opts.actor;
3653
- const wantsStructured = opts.structured === true || opts.timeline === true || opts.causal === true || opts.derived === true || opts.detail === "minimal" || opts.detail === "full";
3654
- if (wantsStructured && _Graph.inspectorEnabled) {
3655
- return this._createObserveResultForAll(opts);
3624
+ const wantsStructured = opts.structured === true || opts.timeline === true || opts.causal === true || opts.derived === true || opts.detail === "minimal" || opts.detail === "full" || opts.format != null;
3625
+ if (wantsStructured) {
3626
+ const result = _Graph.inspectorEnabled ? this._createObserveResultForAll(opts) : this._createFallbackObserveResultForAll(opts);
3627
+ if (opts.format != null) {
3628
+ this._attachFormatLogger(result, opts);
3629
+ }
3630
+ return result;
3656
3631
  }
3657
3632
  return {
3658
3633
  subscribe: (sink) => {
@@ -3696,6 +3671,7 @@ var Graph = class _Graph {
3696
3671
  let lastTriggerDepIndex;
3697
3672
  let lastRunDepValues;
3698
3673
  let detachInspectorHook;
3674
+ let batchSeq = 0;
3699
3675
  if ((causal || derived2) && target instanceof NodeImpl) {
3700
3676
  detachInspectorHook = target._setInspectorHook((event) => {
3701
3677
  if (event.kind === "dep_message") {
@@ -3708,15 +3684,16 @@ var Graph = class _Graph {
3708
3684
  type: "derived",
3709
3685
  path,
3710
3686
  dep_values: [...event.depValues],
3711
- ...timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {}
3687
+ ...timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {}
3712
3688
  });
3713
3689
  }
3714
3690
  });
3715
3691
  }
3716
3692
  const unsub = target.subscribe((msgs) => {
3693
+ batchSeq++;
3717
3694
  for (const m of msgs) {
3718
3695
  const t = m[0];
3719
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
3696
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
3720
3697
  const withCausal = causal && lastRunDepValues != null ? (() => {
3721
3698
  const triggerDep = lastTriggerDepIndex != null && lastTriggerDepIndex >= 0 && target instanceof NodeImpl ? target._deps[lastTriggerDepIndex] : void 0;
3722
3699
  const tv = triggerDep?.v;
@@ -3785,11 +3762,15 @@ var Graph = class _Graph {
3785
3762
  Object.assign(merged, extra);
3786
3763
  }
3787
3764
  const resolvedTarget = graph.resolve(basePath);
3788
- return graph._createObserveResult(
3765
+ const expanded = graph._createObserveResult(
3789
3766
  basePath,
3790
3767
  resolvedTarget,
3791
3768
  resolveObserveDetail(merged)
3792
3769
  );
3770
+ if (merged.format != null) {
3771
+ graph._attachFormatLogger(expanded, merged);
3772
+ }
3773
+ return expanded;
3793
3774
  }
3794
3775
  };
3795
3776
  }
@@ -3809,11 +3790,13 @@ var Graph = class _Graph {
3809
3790
  this._collectObserveTargets("", targets);
3810
3791
  targets.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
3811
3792
  const picked = actor == null ? targets : targets.filter(([, nd]) => nd.allowsObserve(actor));
3793
+ let batchSeq = 0;
3812
3794
  const unsubs = picked.map(
3813
3795
  ([path, nd]) => nd.subscribe((msgs) => {
3796
+ batchSeq++;
3814
3797
  for (const m of msgs) {
3815
3798
  const t = m[0];
3816
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
3799
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
3817
3800
  if (t === DATA) {
3818
3801
  result.values[path] = m[1];
3819
3802
  result.events.push({ type: "data", path, data: m[1], ...base });
@@ -3869,25 +3852,161 @@ var Graph = class _Graph {
3869
3852
  } else {
3870
3853
  Object.assign(merged, extra);
3871
3854
  }
3872
- return graph._createObserveResultForAll(resolveObserveDetail(merged));
3855
+ const expanded = graph._createObserveResultForAll(resolveObserveDetail(merged));
3856
+ if (merged.format != null) {
3857
+ graph._attachFormatLogger(expanded, merged);
3858
+ }
3859
+ return expanded;
3873
3860
  }
3874
3861
  };
3875
3862
  }
3876
3863
  /**
3877
- * Convenience live debugger over {@link Graph.observe}. Logs protocol events as they flow.
3878
- *
3879
- * Supports one-node (`path`) and graph-wide modes, event filtering, and JSON/pretty rendering.
3880
- * Color themes are built in (`ansi` / `none`) to avoid external dependencies.
3881
- *
3882
- * @param options - Spy configuration.
3883
- * @returns Disposable handle plus a structured observation accumulator.
3864
+ * Fallback ObserveResult for single-node when inspector is disabled but `format` is requested.
3865
+ * Subscribes to raw messages and accumulates events with timeline info.
3884
3866
  */
3885
- spy(options = {}) {
3867
+ _createFallbackObserveResult(path, options) {
3868
+ const timeline = options.timeline !== false;
3869
+ const acc = {
3870
+ values: {},
3871
+ dirtyCount: 0,
3872
+ resolvedCount: 0,
3873
+ events: [],
3874
+ completedCleanly: false,
3875
+ errored: false
3876
+ };
3877
+ const target = this.resolve(path);
3878
+ let batchSeq = 0;
3879
+ const unsub = target.subscribe((msgs) => {
3880
+ batchSeq++;
3881
+ for (const m of msgs) {
3882
+ const t = m[0];
3883
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
3884
+ if (t === DATA) {
3885
+ acc.values[path] = m[1];
3886
+ acc.events.push({ type: "data", path, data: m[1], ...base });
3887
+ } else if (t === DIRTY) {
3888
+ acc.dirtyCount++;
3889
+ acc.events.push({ type: "dirty", path, ...base });
3890
+ } else if (t === RESOLVED) {
3891
+ acc.resolvedCount++;
3892
+ acc.events.push({ type: "resolved", path, ...base });
3893
+ } else if (t === COMPLETE) {
3894
+ if (!acc.errored) acc.completedCleanly = true;
3895
+ acc.events.push({ type: "complete", path, ...base });
3896
+ } else if (t === ERROR) {
3897
+ acc.errored = true;
3898
+ acc.events.push({ type: "error", path, data: m[1], ...base });
3899
+ }
3900
+ }
3901
+ });
3902
+ return {
3903
+ get values() {
3904
+ return acc.values;
3905
+ },
3906
+ get dirtyCount() {
3907
+ return acc.dirtyCount;
3908
+ },
3909
+ get resolvedCount() {
3910
+ return acc.resolvedCount;
3911
+ },
3912
+ get events() {
3913
+ return acc.events;
3914
+ },
3915
+ get completedCleanly() {
3916
+ return acc.completedCleanly;
3917
+ },
3918
+ get errored() {
3919
+ return acc.errored;
3920
+ },
3921
+ dispose() {
3922
+ unsub();
3923
+ },
3924
+ expand() {
3925
+ throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
3926
+ }
3927
+ };
3928
+ }
3929
+ /**
3930
+ * Fallback ObserveResult for graph-wide when inspector is disabled but `format` is requested.
3931
+ */
3932
+ _createFallbackObserveResultForAll(options) {
3933
+ const timeline = options.timeline !== false;
3934
+ const actor = options.actor;
3935
+ const acc = {
3936
+ values: {},
3937
+ dirtyCount: 0,
3938
+ resolvedCount: 0,
3939
+ events: [],
3940
+ completedCleanly: false,
3941
+ errored: false
3942
+ };
3943
+ const targets = [];
3944
+ this._collectObserveTargets("", targets);
3945
+ targets.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
3946
+ const picked = actor == null ? targets : targets.filter(([, nd]) => nd.allowsObserve(actor));
3947
+ let batchSeq = 0;
3948
+ const unsubs = picked.map(
3949
+ ([path, nd]) => nd.subscribe((msgs) => {
3950
+ batchSeq++;
3951
+ for (const m of msgs) {
3952
+ const t = m[0];
3953
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
3954
+ if (t === DATA) {
3955
+ acc.values[path] = m[1];
3956
+ acc.events.push({ type: "data", path, data: m[1], ...base });
3957
+ } else if (t === DIRTY) {
3958
+ acc.dirtyCount++;
3959
+ acc.events.push({ type: "dirty", path, ...base });
3960
+ } else if (t === RESOLVED) {
3961
+ acc.resolvedCount++;
3962
+ acc.events.push({ type: "resolved", path, ...base });
3963
+ } else if (t === COMPLETE) {
3964
+ if (!acc.errored) acc.completedCleanly = true;
3965
+ acc.events.push({ type: "complete", path, ...base });
3966
+ } else if (t === ERROR) {
3967
+ acc.errored = true;
3968
+ acc.events.push({ type: "error", path, data: m[1], ...base });
3969
+ }
3970
+ }
3971
+ })
3972
+ );
3973
+ return {
3974
+ get values() {
3975
+ return acc.values;
3976
+ },
3977
+ get dirtyCount() {
3978
+ return acc.dirtyCount;
3979
+ },
3980
+ get resolvedCount() {
3981
+ return acc.resolvedCount;
3982
+ },
3983
+ get events() {
3984
+ return acc.events;
3985
+ },
3986
+ get completedCleanly() {
3987
+ return acc.completedCleanly;
3988
+ },
3989
+ get errored() {
3990
+ return acc.errored;
3991
+ },
3992
+ dispose() {
3993
+ for (const u of unsubs) u();
3994
+ },
3995
+ expand() {
3996
+ throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
3997
+ }
3998
+ };
3999
+ }
4000
+ /**
4001
+ * Attaches a format logger to an ObserveResult, rendering events as they arrive.
4002
+ * Wraps the result's dispose to flush pending events.
4003
+ */
4004
+ _attachFormatLogger(result, options) {
4005
+ const format = options.format;
4006
+ const logger = options.logger ?? ((line) => console.log(line));
3886
4007
  const include = options.includeTypes ? new Set(options.includeTypes) : null;
3887
4008
  const exclude = options.excludeTypes ? new Set(options.excludeTypes) : null;
3888
- const theme = resolveSpyTheme(options.theme);
3889
- const format = options.format ?? "pretty";
3890
- const logger = options.logger ?? ((line) => console.log(line));
4009
+ const theme = resolveObserveTheme(options.theme);
3891
4010
  const shouldLog = (type) => {
3892
4011
  if (include?.has(type) === false) return false;
3893
4012
  if (exclude?.has(type) === true) return false;
@@ -3912,133 +4031,26 @@ var Graph = class _Graph {
3912
4031
  const batchPart = event.in_batch ? " [batch]" : "";
3913
4032
  return `${pathPart}${color}${event.type.toUpperCase()}${theme.reset}${dataPart}${triggerPart}${batchPart}`;
3914
4033
  };
3915
- if (!_Graph.inspectorEnabled) {
3916
- const timeline = options.timeline ?? true;
3917
- const acc = {
3918
- values: {},
3919
- dirtyCount: 0,
3920
- resolvedCount: 0,
3921
- events: [],
3922
- completedCleanly: false,
3923
- errored: false
3924
- };
3925
- let stop2 = () => {
3926
- };
3927
- const result2 = {
3928
- get values() {
3929
- return acc.values;
3930
- },
3931
- get dirtyCount() {
3932
- return acc.dirtyCount;
3933
- },
3934
- get resolvedCount() {
3935
- return acc.resolvedCount;
3936
- },
3937
- get events() {
3938
- return acc.events;
3939
- },
3940
- get completedCleanly() {
3941
- return acc.completedCleanly;
3942
- },
3943
- get errored() {
3944
- return acc.errored;
3945
- },
3946
- dispose() {
3947
- stop2();
3948
- },
3949
- expand() {
3950
- throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
3951
- }
3952
- };
3953
- const pushEvent = (path, message) => {
3954
- const t = message[0];
3955
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
3956
- let event;
3957
- if (t === DATA) {
3958
- if (path != null) acc.values[path] = message[1];
3959
- event = { type: "data", ...path != null ? { path } : {}, data: message[1], ...base };
3960
- } else if (t === DIRTY) {
3961
- acc.dirtyCount += 1;
3962
- event = { type: "dirty", ...path != null ? { path } : {}, ...base };
3963
- } else if (t === RESOLVED) {
3964
- acc.resolvedCount += 1;
3965
- event = { type: "resolved", ...path != null ? { path } : {}, ...base };
3966
- } else if (t === COMPLETE) {
3967
- if (!acc.errored) acc.completedCleanly = true;
3968
- event = { type: "complete", ...path != null ? { path } : {}, ...base };
3969
- } else if (t === ERROR) {
3970
- acc.errored = true;
3971
- event = {
3972
- type: "error",
3973
- ...path != null ? { path } : {},
3974
- data: message[1],
3975
- ...base
3976
- };
4034
+ let cursor = 0;
4035
+ const flush = () => {
4036
+ const events = result.events;
4037
+ while (cursor < events.length) {
4038
+ const event = events[cursor++];
4039
+ if (shouldLog(event.type)) {
4040
+ logger(renderEvent(event), event);
3977
4041
  }
3978
- if (!event) return;
3979
- acc.events.push(event);
3980
- if (!shouldLog(event.type)) return;
3981
- logger(renderEvent(event), event);
3982
- };
3983
- if (options.path != null) {
3984
- const stream2 = this.observe(options.path, {
3985
- actor: options.actor,
3986
- structured: false
3987
- });
3988
- stop2 = stream2.subscribe((messages) => {
3989
- for (const m of messages) {
3990
- pushEvent(options.path, m);
3991
- }
3992
- });
3993
- } else {
3994
- const stream2 = this.observe({ actor: options.actor, structured: false });
3995
- stop2 = stream2.subscribe((path, messages) => {
3996
- for (const m of messages) {
3997
- pushEvent(path, m);
3998
- }
3999
- });
4000
4042
  }
4001
- return {
4002
- result: result2,
4003
- dispose() {
4004
- result2.dispose();
4005
- }
4006
- };
4007
- }
4008
- const structuredObserveOptions = {
4009
- actor: options.actor,
4010
- structured: true,
4011
- ...options.timeline !== false ? { timeline: true } : {},
4012
- ...options.causal ? { causal: true } : {},
4013
- ...options.derived ? { derived: true } : {}
4014
4043
  };
4015
- const result = options.path != null ? this.observe(options.path, structuredObserveOptions) : this.observe(structuredObserveOptions);
4016
- let cursor = 0;
4017
- const flushNewEvents = () => {
4018
- const nextEvents = result.events.slice(cursor);
4019
- cursor = result.events.length;
4020
- for (const event of nextEvents) {
4021
- if (!shouldLog(event.type)) continue;
4022
- logger(renderEvent(event), event);
4023
- }
4044
+ const origPush = result.events.push;
4045
+ result.events.push = function(...items) {
4046
+ const ret = origPush.apply(this, items);
4047
+ flush();
4048
+ return ret;
4024
4049
  };
4025
- const stream = options.path != null ? this.observe(options.path, { actor: options.actor, structured: false }) : this.observe({ actor: options.actor, structured: false });
4026
- const stop = options.path != null ? stream.subscribe((messages) => {
4027
- if (messages.length > 0) {
4028
- flushNewEvents();
4029
- }
4030
- }) : stream.subscribe((_path, messages) => {
4031
- if (messages.length > 0) {
4032
- flushNewEvents();
4033
- }
4034
- });
4035
- return {
4036
- result,
4037
- dispose() {
4038
- stop();
4039
- flushNewEvents();
4040
- result.dispose();
4041
- }
4050
+ const origDispose = result.dispose.bind(result);
4051
+ result.dispose = () => {
4052
+ origDispose();
4053
+ flush();
4042
4054
  };
4043
4055
  }
4044
4056
  /**
@@ -4433,33 +4445,21 @@ var Graph = class _Graph {
4433
4445
  // ——————————————————————————————————————————————————————————————
4434
4446
  /**
4435
4447
  * When `false`, structured observation options (`causal`, `timeline`),
4436
- * `annotate()`, and `traceLog()` are no-ops. Raw `observe()` always works.
4448
+ * and `trace()` writes are no-ops. Raw `observe()` always works.
4437
4449
  *
4438
4450
  * Default: `true` outside production (`process.env.NODE_ENV !== "production"`).
4439
4451
  */
4440
4452
  static inspectorEnabled = !(typeof process !== "undefined" && process.env?.NODE_ENV === "production");
4441
4453
  _annotations = /* @__PURE__ */ new Map();
4442
4454
  _traceRing = new RingBuffer(1e3);
4443
- /**
4444
- * Attaches a reasoning annotation to a node — captures *why* an AI agent set a value.
4445
- *
4446
- * No-op when {@link Graph.inspectorEnabled} is `false`.
4447
- *
4448
- * @param path - Qualified node path.
4449
- * @param reason - Free-text note stored in the trace ring buffer.
4450
- */
4451
- annotate(path, reason) {
4452
- if (!_Graph.inspectorEnabled) return;
4453
- this.resolve(path);
4454
- this._annotations.set(path, reason);
4455
- this._traceRing.push({ path, reason, timestamp_ns: monotonicNs() });
4456
- }
4457
- /**
4458
- * Returns a chronological log of all reasoning annotations (ring buffer).
4459
- *
4460
- * @returns `[]` when {@link Graph.inspectorEnabled} is `false`.
4461
- */
4462
- traceLog() {
4455
+ trace(path, reason) {
4456
+ if (path != null && reason != null) {
4457
+ if (!_Graph.inspectorEnabled) return;
4458
+ this.resolve(path);
4459
+ this._annotations.set(path, reason);
4460
+ this._traceRing.push({ path, reason, timestamp_ns: monotonicNs() });
4461
+ return;
4462
+ }
4463
4463
  if (!_Graph.inspectorEnabled) return [];
4464
4464
  return this._traceRing.toArray();
4465
4465
  }
@@ -5084,11 +5084,8 @@ var GraphReflyModule = _GraphReflyModule;
5084
5084
  getActor,
5085
5085
  getGraphToken,
5086
5086
  getNodeToken,
5087
- observeGraph$,
5088
- observeNode$,
5089
5087
  observeSSE,
5090
5088
  observeSubscription,
5091
- toMessages$,
5092
5089
  toObservable
5093
5090
  });
5094
5091
  //# sourceMappingURL=index.cjs.map