@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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  describeNode,
3
3
  resolveDescribeFields
4
- } from "./chunk-F2ULI3Q3.js";
4
+ } from "./chunk-J7S54G7I.js";
5
5
  import {
6
6
  COMPLETE,
7
7
  DATA,
@@ -160,7 +160,7 @@ var RingBuffer = class {
160
160
  return result;
161
161
  }
162
162
  };
163
- var SPY_ANSI_THEME = {
163
+ var OBSERVE_ANSI_THEME = {
164
164
  data: "\x1B[32m",
165
165
  dirty: "\x1B[33m",
166
166
  resolved: "\x1B[36m",
@@ -170,7 +170,7 @@ var SPY_ANSI_THEME = {
170
170
  path: "\x1B[90m",
171
171
  reset: "\x1B[0m"
172
172
  };
173
- var SPY_NO_COLOR_THEME = {
173
+ var OBSERVE_NO_COLOR_THEME = {
174
174
  data: "",
175
175
  dirty: "",
176
176
  resolved: "",
@@ -190,9 +190,9 @@ function describeData(value) {
190
190
  return "[unserializable]";
191
191
  }
192
192
  }
193
- function resolveSpyTheme(theme) {
194
- if (theme === "none") return SPY_NO_COLOR_THEME;
195
- if (theme === "ansi" || theme == null) return SPY_ANSI_THEME;
193
+ function resolveObserveTheme(theme) {
194
+ if (theme === "none") return OBSERVE_NO_COLOR_THEME;
195
+ if (theme === "ansi" || theme == null) return OBSERVE_ANSI_THEME;
196
196
  return {
197
197
  data: theme.data ?? "",
198
198
  dirty: theme.dirty ?? "",
@@ -963,9 +963,13 @@ var Graph = class _Graph {
963
963
  if (actor2 != null && !target.allowsObserve(actor2)) {
964
964
  throw new GuardDenied({ actor: actor2, action: "observe", nodeName: path });
965
965
  }
966
- const wantsStructured2 = resolved.structured === true || resolved.timeline === true || resolved.causal === true || resolved.derived === true || resolved.detail === "minimal" || resolved.detail === "full";
967
- if (wantsStructured2 && _Graph.inspectorEnabled) {
968
- return this._createObserveResult(path, target, resolved);
966
+ const wantsStructured2 = resolved.structured === true || resolved.timeline === true || resolved.causal === true || resolved.derived === true || resolved.detail === "minimal" || resolved.detail === "full" || resolved.format != null;
967
+ if (wantsStructured2) {
968
+ const result = _Graph.inspectorEnabled ? this._createObserveResult(path, target, resolved) : this._createFallbackObserveResult(path, resolved);
969
+ if (resolved.format != null) {
970
+ this._attachFormatLogger(result, resolved);
971
+ }
972
+ return result;
969
973
  }
970
974
  return {
971
975
  subscribe(sink) {
@@ -983,9 +987,13 @@ var Graph = class _Graph {
983
987
  }
984
988
  const opts = resolveObserveDetail(pathOrOpts);
985
989
  const actor = opts.actor;
986
- const wantsStructured = opts.structured === true || opts.timeline === true || opts.causal === true || opts.derived === true || opts.detail === "minimal" || opts.detail === "full";
987
- if (wantsStructured && _Graph.inspectorEnabled) {
988
- return this._createObserveResultForAll(opts);
990
+ const wantsStructured = opts.structured === true || opts.timeline === true || opts.causal === true || opts.derived === true || opts.detail === "minimal" || opts.detail === "full" || opts.format != null;
991
+ if (wantsStructured) {
992
+ const result = _Graph.inspectorEnabled ? this._createObserveResultForAll(opts) : this._createFallbackObserveResultForAll(opts);
993
+ if (opts.format != null) {
994
+ this._attachFormatLogger(result, opts);
995
+ }
996
+ return result;
989
997
  }
990
998
  return {
991
999
  subscribe: (sink) => {
@@ -1029,6 +1037,7 @@ var Graph = class _Graph {
1029
1037
  let lastTriggerDepIndex;
1030
1038
  let lastRunDepValues;
1031
1039
  let detachInspectorHook;
1040
+ let batchSeq = 0;
1032
1041
  if ((causal || derived) && target instanceof NodeImpl) {
1033
1042
  detachInspectorHook = target._setInspectorHook((event) => {
1034
1043
  if (event.kind === "dep_message") {
@@ -1041,15 +1050,16 @@ var Graph = class _Graph {
1041
1050
  type: "derived",
1042
1051
  path,
1043
1052
  dep_values: [...event.depValues],
1044
- ...timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {}
1053
+ ...timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {}
1045
1054
  });
1046
1055
  }
1047
1056
  });
1048
1057
  }
1049
1058
  const unsub = target.subscribe((msgs) => {
1059
+ batchSeq++;
1050
1060
  for (const m of msgs) {
1051
1061
  const t = m[0];
1052
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
1062
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
1053
1063
  const withCausal = causal && lastRunDepValues != null ? (() => {
1054
1064
  const triggerDep = lastTriggerDepIndex != null && lastTriggerDepIndex >= 0 && target instanceof NodeImpl ? target._deps[lastTriggerDepIndex] : void 0;
1055
1065
  const tv = triggerDep?.v;
@@ -1118,11 +1128,15 @@ var Graph = class _Graph {
1118
1128
  Object.assign(merged, extra);
1119
1129
  }
1120
1130
  const resolvedTarget = graph.resolve(basePath);
1121
- return graph._createObserveResult(
1131
+ const expanded = graph._createObserveResult(
1122
1132
  basePath,
1123
1133
  resolvedTarget,
1124
1134
  resolveObserveDetail(merged)
1125
1135
  );
1136
+ if (merged.format != null) {
1137
+ graph._attachFormatLogger(expanded, merged);
1138
+ }
1139
+ return expanded;
1126
1140
  }
1127
1141
  };
1128
1142
  }
@@ -1142,11 +1156,13 @@ var Graph = class _Graph {
1142
1156
  this._collectObserveTargets("", targets);
1143
1157
  targets.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
1144
1158
  const picked = actor == null ? targets : targets.filter(([, nd]) => nd.allowsObserve(actor));
1159
+ let batchSeq = 0;
1145
1160
  const unsubs = picked.map(
1146
1161
  ([path, nd]) => nd.subscribe((msgs) => {
1162
+ batchSeq++;
1147
1163
  for (const m of msgs) {
1148
1164
  const t = m[0];
1149
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
1165
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
1150
1166
  if (t === DATA) {
1151
1167
  result.values[path] = m[1];
1152
1168
  result.events.push({ type: "data", path, data: m[1], ...base });
@@ -1202,25 +1218,161 @@ var Graph = class _Graph {
1202
1218
  } else {
1203
1219
  Object.assign(merged, extra);
1204
1220
  }
1205
- return graph._createObserveResultForAll(resolveObserveDetail(merged));
1221
+ const expanded = graph._createObserveResultForAll(resolveObserveDetail(merged));
1222
+ if (merged.format != null) {
1223
+ graph._attachFormatLogger(expanded, merged);
1224
+ }
1225
+ return expanded;
1206
1226
  }
1207
1227
  };
1208
1228
  }
1209
1229
  /**
1210
- * Convenience live debugger over {@link Graph.observe}. Logs protocol events as they flow.
1211
- *
1212
- * Supports one-node (`path`) and graph-wide modes, event filtering, and JSON/pretty rendering.
1213
- * Color themes are built in (`ansi` / `none`) to avoid external dependencies.
1214
- *
1215
- * @param options - Spy configuration.
1216
- * @returns Disposable handle plus a structured observation accumulator.
1230
+ * Fallback ObserveResult for single-node when inspector is disabled but `format` is requested.
1231
+ * Subscribes to raw messages and accumulates events with timeline info.
1232
+ */
1233
+ _createFallbackObserveResult(path, options) {
1234
+ const timeline = options.timeline !== false;
1235
+ const acc = {
1236
+ values: {},
1237
+ dirtyCount: 0,
1238
+ resolvedCount: 0,
1239
+ events: [],
1240
+ completedCleanly: false,
1241
+ errored: false
1242
+ };
1243
+ const target = this.resolve(path);
1244
+ let batchSeq = 0;
1245
+ const unsub = target.subscribe((msgs) => {
1246
+ batchSeq++;
1247
+ for (const m of msgs) {
1248
+ const t = m[0];
1249
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
1250
+ if (t === DATA) {
1251
+ acc.values[path] = m[1];
1252
+ acc.events.push({ type: "data", path, data: m[1], ...base });
1253
+ } else if (t === DIRTY) {
1254
+ acc.dirtyCount++;
1255
+ acc.events.push({ type: "dirty", path, ...base });
1256
+ } else if (t === RESOLVED) {
1257
+ acc.resolvedCount++;
1258
+ acc.events.push({ type: "resolved", path, ...base });
1259
+ } else if (t === COMPLETE) {
1260
+ if (!acc.errored) acc.completedCleanly = true;
1261
+ acc.events.push({ type: "complete", path, ...base });
1262
+ } else if (t === ERROR) {
1263
+ acc.errored = true;
1264
+ acc.events.push({ type: "error", path, data: m[1], ...base });
1265
+ }
1266
+ }
1267
+ });
1268
+ return {
1269
+ get values() {
1270
+ return acc.values;
1271
+ },
1272
+ get dirtyCount() {
1273
+ return acc.dirtyCount;
1274
+ },
1275
+ get resolvedCount() {
1276
+ return acc.resolvedCount;
1277
+ },
1278
+ get events() {
1279
+ return acc.events;
1280
+ },
1281
+ get completedCleanly() {
1282
+ return acc.completedCleanly;
1283
+ },
1284
+ get errored() {
1285
+ return acc.errored;
1286
+ },
1287
+ dispose() {
1288
+ unsub();
1289
+ },
1290
+ expand() {
1291
+ throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
1292
+ }
1293
+ };
1294
+ }
1295
+ /**
1296
+ * Fallback ObserveResult for graph-wide when inspector is disabled but `format` is requested.
1297
+ */
1298
+ _createFallbackObserveResultForAll(options) {
1299
+ const timeline = options.timeline !== false;
1300
+ const actor = options.actor;
1301
+ const acc = {
1302
+ values: {},
1303
+ dirtyCount: 0,
1304
+ resolvedCount: 0,
1305
+ events: [],
1306
+ completedCleanly: false,
1307
+ errored: false
1308
+ };
1309
+ const targets = [];
1310
+ this._collectObserveTargets("", targets);
1311
+ targets.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
1312
+ const picked = actor == null ? targets : targets.filter(([, nd]) => nd.allowsObserve(actor));
1313
+ let batchSeq = 0;
1314
+ const unsubs = picked.map(
1315
+ ([path, nd]) => nd.subscribe((msgs) => {
1316
+ batchSeq++;
1317
+ for (const m of msgs) {
1318
+ const t = m[0];
1319
+ const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching(), batch_id: batchSeq } : {};
1320
+ if (t === DATA) {
1321
+ acc.values[path] = m[1];
1322
+ acc.events.push({ type: "data", path, data: m[1], ...base });
1323
+ } else if (t === DIRTY) {
1324
+ acc.dirtyCount++;
1325
+ acc.events.push({ type: "dirty", path, ...base });
1326
+ } else if (t === RESOLVED) {
1327
+ acc.resolvedCount++;
1328
+ acc.events.push({ type: "resolved", path, ...base });
1329
+ } else if (t === COMPLETE) {
1330
+ if (!acc.errored) acc.completedCleanly = true;
1331
+ acc.events.push({ type: "complete", path, ...base });
1332
+ } else if (t === ERROR) {
1333
+ acc.errored = true;
1334
+ acc.events.push({ type: "error", path, data: m[1], ...base });
1335
+ }
1336
+ }
1337
+ })
1338
+ );
1339
+ return {
1340
+ get values() {
1341
+ return acc.values;
1342
+ },
1343
+ get dirtyCount() {
1344
+ return acc.dirtyCount;
1345
+ },
1346
+ get resolvedCount() {
1347
+ return acc.resolvedCount;
1348
+ },
1349
+ get events() {
1350
+ return acc.events;
1351
+ },
1352
+ get completedCleanly() {
1353
+ return acc.completedCleanly;
1354
+ },
1355
+ get errored() {
1356
+ return acc.errored;
1357
+ },
1358
+ dispose() {
1359
+ for (const u of unsubs) u();
1360
+ },
1361
+ expand() {
1362
+ throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
1363
+ }
1364
+ };
1365
+ }
1366
+ /**
1367
+ * Attaches a format logger to an ObserveResult, rendering events as they arrive.
1368
+ * Wraps the result's dispose to flush pending events.
1217
1369
  */
1218
- spy(options = {}) {
1370
+ _attachFormatLogger(result, options) {
1371
+ const format = options.format;
1372
+ const logger = options.logger ?? ((line) => console.log(line));
1219
1373
  const include = options.includeTypes ? new Set(options.includeTypes) : null;
1220
1374
  const exclude = options.excludeTypes ? new Set(options.excludeTypes) : null;
1221
- const theme = resolveSpyTheme(options.theme);
1222
- const format = options.format ?? "pretty";
1223
- const logger = options.logger ?? ((line) => console.log(line));
1375
+ const theme = resolveObserveTheme(options.theme);
1224
1376
  const shouldLog = (type) => {
1225
1377
  if (include?.has(type) === false) return false;
1226
1378
  if (exclude?.has(type) === true) return false;
@@ -1245,133 +1397,26 @@ var Graph = class _Graph {
1245
1397
  const batchPart = event.in_batch ? " [batch]" : "";
1246
1398
  return `${pathPart}${color}${event.type.toUpperCase()}${theme.reset}${dataPart}${triggerPart}${batchPart}`;
1247
1399
  };
1248
- if (!_Graph.inspectorEnabled) {
1249
- const timeline = options.timeline ?? true;
1250
- const acc = {
1251
- values: {},
1252
- dirtyCount: 0,
1253
- resolvedCount: 0,
1254
- events: [],
1255
- completedCleanly: false,
1256
- errored: false
1257
- };
1258
- let stop2 = () => {
1259
- };
1260
- const result2 = {
1261
- get values() {
1262
- return acc.values;
1263
- },
1264
- get dirtyCount() {
1265
- return acc.dirtyCount;
1266
- },
1267
- get resolvedCount() {
1268
- return acc.resolvedCount;
1269
- },
1270
- get events() {
1271
- return acc.events;
1272
- },
1273
- get completedCleanly() {
1274
- return acc.completedCleanly;
1275
- },
1276
- get errored() {
1277
- return acc.errored;
1278
- },
1279
- dispose() {
1280
- stop2();
1281
- },
1282
- expand() {
1283
- throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
1284
- }
1285
- };
1286
- const pushEvent = (path, message) => {
1287
- const t = message[0];
1288
- const base = timeline ? { timestamp_ns: monotonicNs(), in_batch: isBatching() } : {};
1289
- let event;
1290
- if (t === DATA) {
1291
- if (path != null) acc.values[path] = message[1];
1292
- event = { type: "data", ...path != null ? { path } : {}, data: message[1], ...base };
1293
- } else if (t === DIRTY) {
1294
- acc.dirtyCount += 1;
1295
- event = { type: "dirty", ...path != null ? { path } : {}, ...base };
1296
- } else if (t === RESOLVED) {
1297
- acc.resolvedCount += 1;
1298
- event = { type: "resolved", ...path != null ? { path } : {}, ...base };
1299
- } else if (t === COMPLETE) {
1300
- if (!acc.errored) acc.completedCleanly = true;
1301
- event = { type: "complete", ...path != null ? { path } : {}, ...base };
1302
- } else if (t === ERROR) {
1303
- acc.errored = true;
1304
- event = {
1305
- type: "error",
1306
- ...path != null ? { path } : {},
1307
- data: message[1],
1308
- ...base
1309
- };
1400
+ let cursor = 0;
1401
+ const flush = () => {
1402
+ const events = result.events;
1403
+ while (cursor < events.length) {
1404
+ const event = events[cursor++];
1405
+ if (shouldLog(event.type)) {
1406
+ logger(renderEvent(event), event);
1310
1407
  }
1311
- if (!event) return;
1312
- acc.events.push(event);
1313
- if (!shouldLog(event.type)) return;
1314
- logger(renderEvent(event), event);
1315
- };
1316
- if (options.path != null) {
1317
- const stream2 = this.observe(options.path, {
1318
- actor: options.actor,
1319
- structured: false
1320
- });
1321
- stop2 = stream2.subscribe((messages) => {
1322
- for (const m of messages) {
1323
- pushEvent(options.path, m);
1324
- }
1325
- });
1326
- } else {
1327
- const stream2 = this.observe({ actor: options.actor, structured: false });
1328
- stop2 = stream2.subscribe((path, messages) => {
1329
- for (const m of messages) {
1330
- pushEvent(path, m);
1331
- }
1332
- });
1333
1408
  }
1334
- return {
1335
- result: result2,
1336
- dispose() {
1337
- result2.dispose();
1338
- }
1339
- };
1340
- }
1341
- const structuredObserveOptions = {
1342
- actor: options.actor,
1343
- structured: true,
1344
- ...options.timeline !== false ? { timeline: true } : {},
1345
- ...options.causal ? { causal: true } : {},
1346
- ...options.derived ? { derived: true } : {}
1347
1409
  };
1348
- const result = options.path != null ? this.observe(options.path, structuredObserveOptions) : this.observe(structuredObserveOptions);
1349
- let cursor = 0;
1350
- const flushNewEvents = () => {
1351
- const nextEvents = result.events.slice(cursor);
1352
- cursor = result.events.length;
1353
- for (const event of nextEvents) {
1354
- if (!shouldLog(event.type)) continue;
1355
- logger(renderEvent(event), event);
1356
- }
1410
+ const origPush = result.events.push;
1411
+ result.events.push = function(...items) {
1412
+ const ret = origPush.apply(this, items);
1413
+ flush();
1414
+ return ret;
1357
1415
  };
1358
- const stream = options.path != null ? this.observe(options.path, { actor: options.actor, structured: false }) : this.observe({ actor: options.actor, structured: false });
1359
- const stop = options.path != null ? stream.subscribe((messages) => {
1360
- if (messages.length > 0) {
1361
- flushNewEvents();
1362
- }
1363
- }) : stream.subscribe((_path, messages) => {
1364
- if (messages.length > 0) {
1365
- flushNewEvents();
1366
- }
1367
- });
1368
- return {
1369
- result,
1370
- dispose() {
1371
- stop();
1372
- flushNewEvents();
1373
- result.dispose();
1374
- }
1416
+ const origDispose = result.dispose.bind(result);
1417
+ result.dispose = () => {
1418
+ origDispose();
1419
+ flush();
1375
1420
  };
1376
1421
  }
1377
1422
  /**
@@ -1766,33 +1811,21 @@ var Graph = class _Graph {
1766
1811
  // ——————————————————————————————————————————————————————————————
1767
1812
  /**
1768
1813
  * When `false`, structured observation options (`causal`, `timeline`),
1769
- * `annotate()`, and `traceLog()` are no-ops. Raw `observe()` always works.
1814
+ * and `trace()` writes are no-ops. Raw `observe()` always works.
1770
1815
  *
1771
1816
  * Default: `true` outside production (`process.env.NODE_ENV !== "production"`).
1772
1817
  */
1773
1818
  static inspectorEnabled = !(typeof process !== "undefined" && process.env?.NODE_ENV === "production");
1774
1819
  _annotations = /* @__PURE__ */ new Map();
1775
1820
  _traceRing = new RingBuffer(1e3);
1776
- /**
1777
- * Attaches a reasoning annotation to a node — captures *why* an AI agent set a value.
1778
- *
1779
- * No-op when {@link Graph.inspectorEnabled} is `false`.
1780
- *
1781
- * @param path - Qualified node path.
1782
- * @param reason - Free-text note stored in the trace ring buffer.
1783
- */
1784
- annotate(path, reason) {
1785
- if (!_Graph.inspectorEnabled) return;
1786
- this.resolve(path);
1787
- this._annotations.set(path, reason);
1788
- this._traceRing.push({ path, reason, timestamp_ns: monotonicNs() });
1789
- }
1790
- /**
1791
- * Returns a chronological log of all reasoning annotations (ring buffer).
1792
- *
1793
- * @returns `[]` when {@link Graph.inspectorEnabled} is `false`.
1794
- */
1795
- traceLog() {
1821
+ trace(path, reason) {
1822
+ if (path != null && reason != null) {
1823
+ if (!_Graph.inspectorEnabled) return;
1824
+ this.resolve(path);
1825
+ this._annotations.set(path, reason);
1826
+ this._traceRing.push({ path, reason, timestamp_ns: monotonicNs() });
1827
+ return;
1828
+ }
1796
1829
  if (!_Graph.inspectorEnabled) return [];
1797
1830
  return this._traceRing.toArray();
1798
1831
  }
@@ -1926,4 +1959,4 @@ export {
1926
1959
  Graph,
1927
1960
  reachable
1928
1961
  };
1929
- //# sourceMappingURL=chunk-IHJHBADD.js.map
1962
+ //# sourceMappingURL=chunk-LB3RYLSC.js.map