@blue-labs/document-processor 1.32.0 → 1.33.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 (42) hide show
  1. package/dist/BlueDocumentProcessor.d.ts.map +1 -1
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/context.d.ts +1 -1
  4. package/dist/context.d.ts.map +1 -1
  5. package/dist/index.js +4 -4
  6. package/dist/index.mjs +580 -491
  7. package/dist/processors/BaseChannelProcessor.d.ts.map +1 -1
  8. package/dist/processors/CompositeTimelineChannelProcessor.d.ts +3 -3
  9. package/dist/processors/CompositeTimelineChannelProcessor.d.ts.map +1 -1
  10. package/dist/processors/DocumentUpdateChannelProcessor.d.ts +3 -3
  11. package/dist/processors/DocumentUpdateChannelProcessor.d.ts.map +1 -1
  12. package/dist/processors/LifecycleEventChannelProcessor.d.ts +2 -2
  13. package/dist/processors/LifecycleEventChannelProcessor.d.ts.map +1 -1
  14. package/dist/processors/OperationProcessor.d.ts +3 -0
  15. package/dist/processors/OperationProcessor.d.ts.map +1 -1
  16. package/dist/processors/SequentialWorkflowOperationProcessor.d.ts +1 -1
  17. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts +6 -1
  18. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts.map +1 -1
  19. package/dist/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts.map +1 -1
  20. package/dist/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts.map +1 -1
  21. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts +1 -0
  22. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts.map +1 -1
  23. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts +1 -6
  24. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts.map +1 -1
  25. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionResolver.d.ts +8 -0
  26. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionResolver.d.ts.map +1 -0
  27. package/dist/processors/TriggeredEventChannelProcessor.d.ts +12 -0
  28. package/dist/processors/TriggeredEventChannelProcessor.d.ts.map +1 -0
  29. package/dist/processors/index.d.ts +1 -0
  30. package/dist/processors/index.d.ts.map +1 -1
  31. package/dist/routing/EventRouter.d.ts.map +1 -1
  32. package/dist/routing/buildContractEntries.d.ts +3 -0
  33. package/dist/routing/buildContractEntries.d.ts.map +1 -0
  34. package/dist/types.d.ts +3 -1
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils/EventTraceManager.d.ts +1 -0
  37. package/dist/utils/EventTraceManager.d.ts.map +1 -1
  38. package/dist/utils/expressionUtils.d.ts +4 -0
  39. package/dist/utils/expressionUtils.d.ts.map +1 -1
  40. package/package.json +5 -5
  41. package/dist/utils/fetchText.d.ts +0 -2
  42. package/dist/utils/fetchText.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,31 +1,23 @@
1
1
  var me = Object.defineProperty;
2
- var ye = (s, e, t) => e in s ? me(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var l = (s, e, t) => ye(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { ProcessEmbeddedSchema as D, ChannelEventCheckpointSchema as ge, blueIds as f, InitializedMarkerSchema as Ee, CompositeTimelineChannelSchema as we, DocumentUpdateChannelSchema as ve, EmbeddedNodeChannelSchema as _, LifecycleEventSchema as be, TimelineEntrySchema as N, OperationSchema as Te, OperationRequestSchema as Pe, UpdateDocumentSchema as $, TriggerEventSchema as q, JavaScriptCodeSchema as A, SequentialWorkflowSchema as Se, SequentialWorkflowOperationSchema as Ce, TimelineChannelSchema as ke } from "@blue-repository/core-dev";
5
- import { applyBlueNodePatch as G, BlueNode as Ie, isBigNumber as x, BlueNodeTypeSchema as b, ResolvedBlueNode as Ne, MergingProcessors as k } from "@blue-labs/language";
6
- import { deepFreeze as Be, isNonNullable as M, deepContains as ee } from "@blue-labs/shared-utils";
7
- import { blueIds as te, MyOSTimelineEntrySchema as ne, MyOSTimelineChannelSchema as Oe, MyOSAgentEventSchema as Me, MyOSAgentChannelSchema as $e } from "@blue-repository/myos-dev";
8
- const qe = (s, e) => ({
9
- on: (t, n) => ({ end: () => n(null) })
10
- });
11
- async function Ae(s) {
12
- return new Promise((e, t) => {
13
- qe().on("error", t).end();
14
- });
15
- }
16
- const v = (...s) => s.map((e, t) => {
2
+ var ge = (a, e, t) => e in a ? me(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
+ var l = (a, e, t) => ge(a, typeof e != "symbol" ? e + "" : e, t);
4
+ import { ProcessEmbeddedSchema as W, ChannelEventCheckpointSchema as ye, blueIds as g, InitializedMarkerSchema as Ee, CompositeTimelineChannelSchema as we, DocumentUpdateChannelSchema as ve, EmbeddedNodeChannelSchema as R, LifecycleEventSchema as Te, TimelineEntrySchema as O, OperationSchema as Pe, OperationRequestSchema as be, UpdateDocumentSchema as x, TriggerEventSchema as j, JavaScriptCodeSchema as V, SequentialWorkflowSchema as Se, SequentialWorkflowOperationSchema as Ce, TimelineChannelSchema as Ne } from "@blue-repository/core-dev";
5
+ import { applyBlueNodePatch as te, BlueNode as ke, isBigNumber as J, BlueNodeTypeSchema as b, ResolvedBlueNode as Ie, MergingProcessors as k } from "@blue-labs/language";
6
+ import { deepFreeze as Be, isNonNullable as M, deepContains as Oe, isNullable as _ } from "@blue-labs/shared-utils";
7
+ import { blueIds as ne, MyOSTimelineEntrySchema as oe, MyOSTimelineChannelSchema as Me, MyOSAgentEventSchema as $e, MyOSAgentChannelSchema as qe } from "@blue-repository/myos-dev";
8
+ const P = (...a) => a.map((e, t) => {
17
9
  if (typeof e != "string") return "";
18
10
  if (t === 0 && e === "/") return "/";
19
11
  const n = t > 0 ? e.replace(/^\/+/, "") : e;
20
- return t < s.length - 1 ? n.replace(/\/+$/, "") : n;
12
+ return t < a.length - 1 ? n.replace(/\/+$/, "") : n;
21
13
  }).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
22
- class oe {
14
+ class re {
23
15
  constructor(e, t, n, o) {
24
16
  l(this, "actions", []);
25
17
  this.getDocument = e, this.taskInfo = t, this.blue = n, this.onFlush = o;
26
18
  }
27
19
  get(e) {
28
- const t = this.getDocument(), n = v(this.taskInfo.nodePath, e);
20
+ const t = this.getDocument(), n = P(this.taskInfo.nodePath, e);
29
21
  return t.get(n);
30
22
  }
31
23
  addPatch(e) {
@@ -33,16 +25,18 @@ class oe {
33
25
  kind: "patch",
34
26
  patch: {
35
27
  ...e,
36
- path: v(this.taskInfo.nodePath, e.path)
28
+ path: P(this.taskInfo.nodePath, e.path)
37
29
  }
38
30
  });
39
31
  }
40
32
  emitEvent(e) {
41
33
  const t = this.taskInfo.event, n = t.trace ?? [], o = {
42
34
  ...e,
35
+ source: e.source ?? "internal",
43
36
  originNodePath: e.originNodePath ?? this.taskInfo.nodePath,
44
37
  rootEvent: e.rootEvent ?? t.rootEvent ?? t,
45
- trace: [...n]
38
+ trace: [...n],
39
+ emissionType: e.emissionType ?? t.emissionType
46
40
  };
47
41
  this.actions.push({ kind: "event", event: o });
48
42
  }
@@ -56,7 +50,7 @@ class oe {
56
50
  return this.taskInfo.nodePath;
57
51
  }
58
52
  resolvePath(e) {
59
- return v(this.taskInfo.nodePath, e);
53
+ return P(this.taskInfo.nodePath, e);
60
54
  }
61
55
  getTaskInfo() {
62
56
  return this.taskInfo;
@@ -65,16 +59,17 @@ class oe {
65
59
  return this.blue;
66
60
  }
67
61
  /* TODO: Move to a separate interface */
68
- loadExternalModule(e) {
69
- if (!/^https?:\/\//.test(e))
70
- throw new Error("Only http/https URLs are allowed");
71
- return Ae();
62
+ loadExternalModule() {
63
+ throw new Error("Not implemented");
72
64
  }
73
65
  loadBlueContent(e) {
74
- throw new Error("Not implemented");
66
+ const t = this.blue.getNodeProvider().fetchFirstByBlueId(e);
67
+ if (!t)
68
+ throw new Error(`Blue node not found for blueId: ${e}`);
69
+ return Promise.resolve(JSON.stringify(this.blue.nodeToJson(t)));
75
70
  }
76
71
  }
77
- class re extends Error {
72
+ class se extends Error {
78
73
  constructor(e, t) {
79
74
  super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
80
75
  }
@@ -86,66 +81,66 @@ class ae extends Error {
86
81
  ), this.patch = e, this.offendingPath = t, this.contractNodePath = n, this.name = "EmbeddedDocumentModificationError";
87
82
  }
88
83
  }
89
- class F extends Error {
84
+ class Ae extends Error {
90
85
  constructor(e, t) {
91
86
  super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
92
87
  }
93
88
  }
94
- class L extends Error {
89
+ class De extends Error {
95
90
  constructor(e, t) {
96
91
  super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
97
92
  }
98
93
  }
99
- function I(s) {
100
- return Be(s);
94
+ function I(a) {
95
+ return Be(a);
101
96
  }
102
- function B(s) {
103
- return s.clone();
97
+ function $(a) {
98
+ return a.clone();
104
99
  }
105
- function W(s, e, t = "/", n = []) {
106
- const o = s.getContracts() ?? {};
107
- for (const [r, a] of Object.entries(o))
108
- if (e.isTypeOf(a, D)) {
100
+ function U(a, e, t = "/", n = []) {
101
+ const o = a.getContracts() ?? {};
102
+ for (const [r, s] of Object.entries(o))
103
+ if (e.isTypeOf(s, W)) {
109
104
  const h = e.nodeToSchemaOutput(
110
- a,
111
- D
105
+ s,
106
+ W
112
107
  ).paths ?? [];
113
108
  for (const u of h)
114
109
  n.push({
115
- absPath: v(t, u),
116
- contractPath: v(t, `contracts/${r}`)
110
+ absPath: P(t, u),
111
+ contractPath: P(t, `contracts/${r}`)
117
112
  });
118
113
  }
119
- for (const [r, a] of Object.entries(s.getProperties() ?? {}))
120
- W(
121
- a,
114
+ for (const [r, s] of Object.entries(a.getProperties() ?? {}))
115
+ U(
116
+ s,
122
117
  e,
123
- v(t, r),
118
+ P(t, r),
124
119
  n
125
120
  );
126
121
  return n;
127
122
  }
128
- function z(s, e) {
129
- return s === e || s.startsWith(e.endsWith("/") ? e : e + "/");
123
+ function X(a, e) {
124
+ return a === e || a.startsWith(e.endsWith("/") ? e : e + "/");
130
125
  }
131
- function U(s, e) {
132
- if (!e.length) return s;
133
- let t = B(s);
126
+ function Q(a, e) {
127
+ if (!e.length) return a;
128
+ let t = $(a);
134
129
  for (const n of e)
135
130
  try {
136
- t = G(t, n, !0);
131
+ t = te(t, n, !0);
137
132
  } catch (o) {
138
- throw new re(n, o);
133
+ throw new se(n, o);
139
134
  }
140
135
  return I(t);
141
136
  }
142
- function g(s) {
143
- return s != null;
137
+ function E(a) {
138
+ return a != null;
144
139
  }
145
- function P(s) {
146
- return s instanceof Ie;
140
+ function S(a) {
141
+ return a instanceof ke;
147
142
  }
148
- class De {
143
+ class xe {
149
144
  constructor(e = [], t = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
150
145
  l(this, "data");
151
146
  l(this, "length");
@@ -167,45 +162,45 @@ class De {
167
162
  _up(e) {
168
163
  const { data: t, compare: n } = this, o = t[e];
169
164
  for (; e > 0; ) {
170
- const r = e - 1 >> 1, a = t[r];
171
- if (n(o, a) >= 0) break;
172
- t[e] = a, e = r;
165
+ const r = e - 1 >> 1, s = t[r];
166
+ if (n(o, s) >= 0) break;
167
+ t[e] = s, e = r;
173
168
  }
174
169
  t[e] = o;
175
170
  }
176
171
  _down(e) {
177
172
  const { data: t, compare: n } = this, o = this.length >> 1, r = t[e];
178
173
  for (; e < o; ) {
179
- let a = (e << 1) + 1;
180
- const c = a + 1;
181
- if (c < this.length && n(t[c], t[a]) < 0 && (a = c), n(t[a], r) >= 0) break;
182
- t[e] = t[a], e = a;
174
+ let s = (e << 1) + 1;
175
+ const i = s + 1;
176
+ if (i < this.length && n(t[i], t[s]) < 0 && (s = i), n(t[s], r) >= 0) break;
177
+ t[e] = t[s], e = s;
183
178
  }
184
179
  t[e] = r;
185
180
  }
186
181
  }
187
- const xe = (s, e, t, n, o, r) => [
188
- -s,
182
+ const je = (a, e, t, n, o, r) => [
183
+ -a,
189
184
  e,
190
185
  t,
191
186
  n,
192
187
  o,
193
188
  r
194
- ], je = (s, e) => {
195
- for (let t = 0; t < s.key.length; t++) {
196
- const n = s.key[t], o = e.key[t];
189
+ ], Ve = (a, e) => {
190
+ for (let t = 0; t < a.key.length; t++) {
191
+ const n = a.key[t], o = e.key[t];
197
192
  if (n !== o)
198
193
  return typeof n == "number" && typeof o == "number" ? n - o : typeof n == "string" && typeof o == "string" ? n.localeCompare(o) : 0;
199
194
  }
200
195
  return 0;
201
196
  };
202
- class Ve {
197
+ class _e {
203
198
  /**
204
199
  * Creates a new task queue with the task key comparator
205
200
  */
206
201
  constructor() {
207
202
  l(this, "queue");
208
- this.queue = new De([], je);
203
+ this.queue = new xe([], Ve);
209
204
  }
210
205
  /**
211
206
  * Adds a task to the queue
@@ -285,10 +280,10 @@ class We {
285
280
  return this.processors.values();
286
281
  }
287
282
  }
288
- class Je {
283
+ const B = class B {
289
284
  constructor() {
290
285
  l(this, "isEnabled");
291
- this.isEnabled = process.env.TRACE_BLUE_ENABLED === "true";
286
+ this.isEnabled = process.env.TRACE_BLUE_ENABLED !== "false";
292
287
  }
293
288
  /**
294
289
  * Creates a hop entry for the trace
@@ -316,13 +311,10 @@ class Je {
316
311
  addHop(e, t, n) {
317
312
  if (!this.shouldTrace())
318
313
  return { ...e };
319
- const o = [
320
- ...e.trace ?? [],
321
- this.makeHop(t, n)
322
- ];
314
+ const o = e.trace ?? [], s = [...o.length >= B.MAX_TRACE_LENGTH ? o.slice(o.length - (B.MAX_TRACE_LENGTH - 1)) : o, this.makeHop(t, n)];
323
315
  return {
324
316
  ...e,
325
- trace: o
317
+ trace: s
326
318
  };
327
319
  }
328
320
  /**
@@ -351,9 +343,14 @@ class Je {
351
343
  isTracingEnabled() {
352
344
  return this.isEnabled;
353
345
  }
346
+ };
347
+ l(B, "MAX_TRACE_LENGTH", 128);
348
+ let L = B;
349
+ function Je(a) {
350
+ return Object.entries(a.getContracts() ?? {});
354
351
  }
355
- const _e = 64;
356
- class Fe {
352
+ const Le = 64;
353
+ class ze {
357
354
  /**
358
355
  * Creates a new event router
359
356
  *
@@ -364,7 +361,7 @@ class Fe {
364
361
  */
365
362
  constructor(e, t, n, o, r) {
366
363
  l(this, "traceManager");
367
- this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new Je();
364
+ this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new L();
368
365
  }
369
366
  /**
370
367
  * Routes an event to matching contracts in the document
@@ -376,22 +373,22 @@ class Fe {
376
373
  * @param inlineDepth - Current adapter recursion depth
377
374
  */
378
375
  async route(e, t, n, o, r = 0) {
379
- var i;
376
+ var c;
380
377
  if (n.seq === void 0 && (n.seq = this.getNextEventSeq()), t.length === 0) {
381
378
  if (n.dispatchPath) {
382
379
  const h = n.dispatchPath.split("/").filter(Boolean), u = { ...n };
383
380
  return delete u.dispatchPath, this.route(e, h, u, o, r);
384
381
  }
385
382
  if (n.source === "channel" && n.originNodePath && n.originNodePath !== "/") {
386
- const h = ((i = n.originNodePath) == null ? void 0 : i.split("/").filter(Boolean)) ?? [];
383
+ const h = ((c = n.originNodePath) == null ? void 0 : c.split("/").filter(Boolean)) ?? [];
387
384
  return this.route(e, h, n, o, r);
388
385
  }
389
386
  }
390
- const a = v("/", t.join("/")), c = e.get(a);
391
- P(c) && await this.traverseContracts({
387
+ const s = P("/", t.join("/")), i = e.get(s);
388
+ S(i) && await this.traverseContracts({
392
389
  doc: e,
393
- node: c,
394
- nodePath: a,
390
+ node: i,
391
+ nodePath: s,
395
392
  event: n,
396
393
  afterTaskId: o,
397
394
  pathSegments: t,
@@ -407,14 +404,12 @@ class Fe {
407
404
  node: n,
408
405
  nodePath: o,
409
406
  event: r,
410
- afterTaskId: a,
411
- pathSegments: c,
412
- inlineDepth: i
407
+ afterTaskId: s,
408
+ pathSegments: i,
409
+ inlineDepth: c
413
410
  } = e;
414
411
  if (!this.shouldSkipForChannel(r, o))
415
- for (const [h, u] of Object.entries(
416
- n.getContracts() ?? {}
417
- )) {
412
+ for (const [h, u] of Je(n)) {
418
413
  if (!u.getType()) continue;
419
414
  const d = this.registry.get(u.getType());
420
415
  if (!d) {
@@ -426,19 +421,19 @@ class Fe {
426
421
  contractName: h,
427
422
  contractNode: u,
428
423
  event: r
429
- }, m = new oe(() => t, p, this.blue);
430
- if (d.supports(r, u, m, h))
424
+ }, f = new re(() => t, p, this.blue);
425
+ if (d.supports(r, u, f, h))
431
426
  switch (d.role) {
432
427
  case "adapter":
433
428
  await this.processAdapter({
434
429
  cp: d,
435
430
  event: r,
436
431
  contractNode: u,
437
- ctx: m,
432
+ ctx: f,
438
433
  contractName: h,
439
434
  doc: t,
440
- afterTaskId: a,
441
- inlineDepth: i
435
+ afterTaskId: s,
436
+ inlineDepth: c
442
437
  });
443
438
  break;
444
439
  case "handler":
@@ -447,8 +442,8 @@ class Fe {
447
442
  contractName: h,
448
443
  nodePath: o,
449
444
  event: r,
450
- depth: c.length,
451
- afterTaskId: a
445
+ depth: i.length,
446
+ afterTaskId: s
452
447
  });
453
448
  break;
454
449
  }
@@ -458,53 +453,64 @@ class Fe {
458
453
  * Processes an adapter contract and routes any emitted events
459
454
  */
460
455
  async processAdapter(e) {
461
- var w;
456
+ var v;
462
457
  const {
463
458
  cp: t,
464
459
  event: n,
465
460
  contractNode: o,
466
461
  ctx: r,
467
- contractName: a,
468
- doc: c,
469
- afterTaskId: i,
462
+ contractName: s,
463
+ doc: i,
464
+ afterTaskId: c,
470
465
  inlineDepth: h
471
466
  } = e;
472
- if (h >= _e)
467
+ if (h >= Le)
473
468
  throw new Error("Adapter recursion limit reached");
474
469
  const u = this.traceManager.addHop(
475
470
  n,
476
- ((w = r.getTaskInfo()) == null ? void 0 : w.nodePath) ?? "",
477
- a
471
+ ((v = r.getTaskInfo()) == null ? void 0 : v.nodePath) ?? "",
472
+ s
478
473
  );
479
- await t.handle(u, o, r, a);
474
+ await t.handle(u, o, r, s);
480
475
  const d = await r.flush();
481
- if (d.find((T) => T.kind === "patch"))
476
+ if (d.find((w) => w.kind === "patch"))
482
477
  throw new Error(
483
- `Contract "${a}" (adapter) attempted to patch the document`
478
+ `Contract "${s}" (adapter) attempted to patch the document`
484
479
  );
485
- const m = d.filter((T) => T.kind === "event");
486
- for (const T of m)
487
- await this.route(c, [], T.event, i, h + 1);
480
+ const f = d.filter((w) => w.kind === "event");
481
+ for (const w of f)
482
+ await this.route(i, [], w.event, c, h + 1);
488
483
  }
489
484
  /**
490
485
  * Schedules a handler contract for future execution
491
486
  */
492
487
  scheduleHandler(e) {
493
- const { contractNode: t, contractName: n, nodePath: o, event: r, depth: a, afterTaskId: c } = e, i = t.getType();
494
- if (!i) {
488
+ const { contractNode: t, contractName: n, nodePath: o, event: r, depth: s, afterTaskId: i } = e, c = t.getType();
489
+ if (!c) {
495
490
  console.warn(`Contract node type is not defined for: ${n}`);
496
491
  return;
497
492
  }
498
- const h = this.registry.orderOf(i), u = t.get("/order"), d = x(u) ? u.toNumber() : 0, p = this.getNextTaskId() + c, m = xe(
499
- a,
500
- r.seq,
493
+ const h = this.registry.orderOf(c), u = t.get("/order"), d = J(u) ? u.toNumber() : 0, p = this.getNextTaskId() + i, f = r.seq;
494
+ if (f === void 0)
495
+ throw new Error("Event sequence missing");
496
+ const v = je(
497
+ s,
498
+ f,
501
499
  h,
502
500
  d,
503
501
  n,
504
502
  p
505
- ), w = this.traceManager.addHop(r, o, n);
503
+ );
504
+ {
505
+ const m = `${o}#${n}`, D = r.trace ?? [];
506
+ if (r.source !== "external" && D.includes(m))
507
+ throw new Error(
508
+ `Loop detected: repeated hop ${m} within the same event chain`
509
+ );
510
+ }
511
+ const w = this.traceManager.addHop(r, o, n);
506
512
  this.queue.push({
507
- key: m,
513
+ key: v,
508
514
  nodePath: o,
509
515
  contractName: n,
510
516
  contractNode: t,
@@ -518,61 +524,61 @@ class Fe {
518
524
  return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
519
525
  }
520
526
  }
521
- const Le = (s, e, t) => {
522
- (t instanceof re || t instanceof ae) && console.error(
523
- `[Blue] Failed to apply patches for contract "${s}" on event ${JSON.stringify(e)}`,
527
+ const Ue = (a, e, t) => {
528
+ (t instanceof se || t instanceof ae) && console.error(
529
+ `[Blue] Failed to apply patches for contract "${a}" on event ${JSON.stringify(e)}`,
524
530
  t
525
531
  );
526
532
  };
527
- function R(s, e) {
528
- const t = B(s), n = (o) => {
529
- if (!P(o)) return;
533
+ function G(a, e) {
534
+ const t = $(a), n = (o) => {
535
+ if (!S(o)) return;
530
536
  const r = o.getContracts();
531
537
  (!(r != null && r.checkpoint) || !b.isTypeOf(
532
538
  r.checkpoint,
533
- ge
539
+ ye
534
540
  )) && o.addContract(
535
541
  "checkpoint",
536
542
  e.jsonValueToNode({
537
543
  type: {
538
544
  name: "Channel Event Checkpoint",
539
- blueId: f["Channel Event Checkpoint"]
545
+ blueId: g["Channel Event Checkpoint"]
540
546
  },
541
547
  lastEvents: {}
542
548
  })
543
549
  );
544
550
  };
545
551
  n(t);
546
- for (const { absPath: o } of W(t, e)) {
552
+ for (const { absPath: o } of U(t, e)) {
547
553
  const r = t.get(o);
548
- P(r) && n(r);
554
+ S(r) && n(r);
549
555
  }
550
556
  return I(t);
551
557
  }
552
- function ze(s, e) {
553
- const t = B(s);
554
- return P(t) && (se(t, e) || t.addContract(
558
+ function He(a, e) {
559
+ const t = $(a);
560
+ return S(t) && (ie(t, e) || t.addContract(
555
561
  "initialized",
556
562
  e.jsonValueToNode({
557
563
  type: {
558
564
  name: "Initialized Marker",
559
- blueId: f["Initialized Marker"]
565
+ blueId: g["Initialized Marker"]
560
566
  }
561
567
  })
562
568
  )), I(t);
563
569
  }
564
- function se(s, e) {
565
- const t = s.getContracts();
570
+ function ie(a, e) {
571
+ const t = a.getContracts();
566
572
  return Object.values(t ?? {}).some(
567
573
  (n) => e.isTypeOf(n, Ee, {
568
574
  checkSchemaExtensions: !0
569
575
  })
570
576
  );
571
577
  }
572
- class Ue {
578
+ class Fe {
573
579
  constructor(e) {
574
580
  l(this, "contractType", "Channel Event Checkpoint");
575
- l(this, "contractBlueId", f["Channel Event Checkpoint"]);
581
+ l(this, "contractBlueId", g["Channel Event Checkpoint"]);
576
582
  l(this, "role", "handler");
577
583
  this.cache = e;
578
584
  }
@@ -587,20 +593,20 @@ class Ue {
587
593
  throw new Error(
588
594
  "Cannot calculate blueId for checkpoint: missing root event payload"
589
595
  );
590
- if (n instanceof Ne) {
596
+ if (n instanceof Ie) {
591
597
  const r = n.getMinimalNode();
592
598
  return await t.getBlue().calculateBlueId(r);
593
599
  }
594
600
  return await t.getBlue().calculateBlueId(n);
595
601
  }
596
602
  async handle(e, t, n) {
597
- var a;
598
- if (!e.channelName || !((a = e.rootEvent) != null && a.seq)) return;
603
+ var s;
604
+ if (!e.channelName || !((s = e.rootEvent) != null && s.seq)) return;
599
605
  const o = await this.getEventBlueId(e, n), r = n.getNodePath().replace(/\/contracts\/checkpoint$/, "");
600
606
  this.cache.record(r, e, o);
601
607
  }
602
608
  }
603
- const H = (s, e) => s.get(e) !== void 0;
609
+ const K = (a, e) => a.get(e) !== void 0;
604
610
  class Re {
605
611
  constructor() {
606
612
  l(this, "firstSeen", /* @__PURE__ */ new Map());
@@ -614,18 +620,18 @@ class Re {
614
620
  const t = [];
615
621
  for (const { docBase: n, event: o, eventBlueId: r } of this.firstSeen.values()) {
616
622
  if (!o.channelName) continue;
617
- const a = v(
623
+ const s = P(
618
624
  n,
619
625
  "contracts/checkpoint/lastEvents",
620
626
  o.channelName
621
- ), c = `${a}/blueId`;
622
- H(e, a) ? t.push({
623
- op: H(e, c) ? "replace" : "add",
624
- path: c,
627
+ ), i = `${s}/blueId`;
628
+ K(e, s) ? t.push({
629
+ op: K(e, i) ? "replace" : "add",
630
+ path: i,
625
631
  val: r
626
632
  }) : t.push({
627
633
  op: "add",
628
- path: a,
634
+ path: s,
629
635
  val: { blueId: r }
630
636
  });
631
637
  }
@@ -635,7 +641,25 @@ class Re {
635
641
  this.firstSeen.clear();
636
642
  }
637
643
  }
638
- class S {
644
+ class Xe {
645
+ constructor() {
646
+ l(this, "contractType", "Composite Timeline Channel");
647
+ l(this, "contractBlueId", g["Composite Timeline Channel"]);
648
+ l(this, "role", "adapter");
649
+ }
650
+ supports(e, t, n) {
651
+ const o = n.getBlue().nodeToSchemaOutput(t, we);
652
+ return !o.channels || !e.channelName ? !1 : o.channels.includes(e.channelName);
653
+ }
654
+ handle(e, t, n, o) {
655
+ n.emitEvent({
656
+ payload: e.payload,
657
+ channelName: o,
658
+ source: "channel"
659
+ });
660
+ }
661
+ }
662
+ class C {
639
663
  constructor() {
640
664
  l(this, "role", "adapter");
641
665
  }
@@ -647,15 +671,18 @@ class S {
647
671
  return e.source !== "channel";
648
672
  }
649
673
  }
650
- class He extends S {
674
+ class Qe extends C {
651
675
  constructor() {
652
676
  super(...arguments);
653
- l(this, "contractType", "Composite Timeline Channel");
654
- l(this, "contractBlueId", f["Composite Timeline Channel"]);
677
+ l(this, "contractType", "Document Update Channel");
678
+ l(this, "contractBlueId", g["Document Update Channel"]);
655
679
  }
656
680
  supports(t, n, o) {
657
- const r = o.getBlue().nodeToSchemaOutput(n, we);
658
- return !r.channels || !t.channelName ? !1 : r.channels.includes(t.channelName);
681
+ if (!this.baseSupports(t) || t.emissionType !== "update") return !1;
682
+ const r = o.getBlue().nodeToSchemaOutput(n, ve), s = t.payload.get("/path");
683
+ if (!s) return !1;
684
+ const i = r.path;
685
+ return M(i) && s === o.resolvePath(i);
659
686
  }
660
687
  handle(t, n, o, r) {
661
688
  o.emitEvent({
@@ -665,52 +692,30 @@ class He extends S {
665
692
  });
666
693
  }
667
694
  }
668
- class Qe extends S {
669
- constructor() {
670
- super(...arguments);
671
- l(this, "contractType", "Document Update Channel");
672
- l(this, "contractBlueId", f["Document Update Channel"]);
673
- }
674
- supports(t, n, o, r) {
675
- if (!this.baseSupports(t)) return !1;
676
- const a = o.getBlue().nodeToSchemaOutput(n, ve), c = t.payload.get("/path");
677
- if (!c || t.channelName === r) return !1;
678
- const i = a.path;
679
- return M(i) && c === o.resolvePath(i);
680
- }
681
- handle(t, n, o, r) {
682
- const a = t.payload;
683
- a && o.emitEvent({
684
- payload: a,
685
- channelName: r,
686
- source: "channel"
687
- });
688
- }
689
- }
690
- class Ke extends S {
695
+ class Ge extends C {
691
696
  constructor() {
692
697
  super(...arguments);
693
698
  l(this, "contractType", "Embedded Node Channel");
694
- l(this, "contractBlueId", f["Embedded Node Channel"]);
699
+ l(this, "contractBlueId", g["Embedded Node Channel"]);
695
700
  }
696
701
  supports(t, n, o) {
697
702
  if (!this.baseSupports(t)) return !1;
698
- const r = o.getBlue().nodeToSchemaOutput(n, _);
699
- return g(t.originNodePath) && g(r.path) && t.originNodePath === o.resolvePath(r.path);
703
+ const r = o.getBlue().nodeToSchemaOutput(n, R);
704
+ return E(t.originNodePath) && E(r.path) && t.originNodePath === o.resolvePath(r.path);
700
705
  }
701
706
  handle(t, n, o, r) {
702
- const a = o.getBlue().nodeToSchemaOutput(n, _), { originNodePath: c, payload: i } = t;
703
- g(a.path) && c === o.resolvePath(a.path) && o.emitEvent({
704
- payload: i,
707
+ const s = o.getBlue().nodeToSchemaOutput(n, R), { originNodePath: i, payload: c } = t;
708
+ E(s.path) && i === o.resolvePath(s.path) && o.emitEvent({
709
+ payload: c,
705
710
  channelName: r,
706
711
  source: "channel"
707
712
  });
708
713
  }
709
714
  }
710
- class Xe {
715
+ class Ke {
711
716
  constructor() {
712
717
  l(this, "contractType", "Initialized Marker");
713
- l(this, "contractBlueId", f["Initialized Marker"]);
718
+ l(this, "contractBlueId", g["Initialized Marker"]);
714
719
  l(this, "role", "marker");
715
720
  }
716
721
  supports() {
@@ -719,20 +724,21 @@ class Xe {
719
724
  handle() {
720
725
  }
721
726
  }
722
- class Ye extends S {
727
+ class Ye extends C {
723
728
  constructor() {
724
729
  super(...arguments);
725
730
  l(this, "contractType", "Lifecycle Event Channel");
726
- l(this, "contractBlueId", f["Lifecycle Event Channel"]);
731
+ l(this, "contractBlueId", g["Lifecycle Event Channel"]);
727
732
  }
728
733
  supports(t, n, o) {
729
- return !this.baseSupports(t) || !this.isLifecycleEvent(t, o) ? !1 : this.isEventPatternMatch(t, n, o);
734
+ return !this.baseSupports(t) || t.emissionType !== "lifecycle" || !this.isLifecycleEvent(t, o) ? !1 : this.isEventPatternMatch(t, n, o);
730
735
  }
731
736
  handle(t, n, o, r) {
732
737
  o.emitEvent({
733
738
  payload: t.payload,
734
739
  channelName: r,
735
- source: "channel"
740
+ source: "channel",
741
+ emissionType: t.emissionType
736
742
  });
737
743
  }
738
744
  /**
@@ -740,7 +746,7 @@ class Ye extends S {
740
746
  */
741
747
  isLifecycleEvent(t, n) {
742
748
  const o = n.getBlue(), r = t.payload;
743
- return o.isTypeOf(r, be, {
749
+ return o.isTypeOf(r, Te, {
744
750
  checkSchemaExtensions: !0
745
751
  });
746
752
  }
@@ -748,60 +754,60 @@ class Ye extends S {
748
754
  * Checks if the event matches the channel's event pattern (if specified)
749
755
  */
750
756
  isEventPatternMatch(t, n, o) {
751
- var a;
752
- const r = (a = n.getProperties()) == null ? void 0 : a.event;
757
+ var s;
758
+ const r = (s = n.getProperties()) == null ? void 0 : s.event;
753
759
  if (!r)
754
760
  return !0;
755
761
  try {
756
- const c = o.getBlue(), i = c.nodeToJson(t.payload), h = c.nodeToJson(r);
757
- return ee(i, h);
758
- } catch (c) {
759
- return console.warn("Error during lifecycle event pattern matching:", c), !1;
762
+ const i = o.getBlue(), c = i.resolve(t.payload);
763
+ return i.isTypeOfNode(c, r);
764
+ } catch (i) {
765
+ return console.warn("Error during lifecycle event pattern matching:", i), !1;
760
766
  }
761
767
  }
762
768
  }
763
- const Q = (s, e) => {
769
+ const Y = (a, e) => {
764
770
  const t = e.getBlue();
765
- return t.isTypeOf(s.payload, N) || t.isTypeOf(s.payload, ne);
771
+ return t.isTypeOf(a.payload, O) || t.isTypeOf(a.payload, oe);
766
772
  };
767
- class Ze extends S {
773
+ class Ze extends C {
768
774
  constructor() {
769
775
  super(...arguments);
770
776
  l(this, "contractType", "MyOS Timeline Channel");
771
- l(this, "contractBlueId", te["MyOS Timeline Channel"]);
777
+ l(this, "contractBlueId", ne["MyOS Timeline Channel"]);
772
778
  }
773
779
  supports(t, n, o) {
774
780
  var u;
775
- if (!this.baseSupports(t) || !Q(t, o)) return !1;
776
- const a = o.getBlue().nodeToSchemaOutput(
781
+ if (!this.baseSupports(t) || !Y(t, o)) return !1;
782
+ const s = o.getBlue().nodeToSchemaOutput(
777
783
  t.payload,
778
- ne
779
- ), c = o.getBlue().nodeToSchemaOutput(n, Oe), i = (u = a.timeline) == null ? void 0 : u.timelineId;
780
- return g(c.timelineId) && g(i) && i === c.timelineId;
784
+ oe
785
+ ), i = o.getBlue().nodeToSchemaOutput(n, Me), c = (u = s.timeline) == null ? void 0 : u.timelineId;
786
+ return E(i.timelineId) && E(c) && c === i.timelineId;
781
787
  }
782
788
  handle(t, n, o, r) {
783
- Q(t, o) && o.emitEvent({
789
+ Y(t, o) && o.emitEvent({
784
790
  payload: t.payload,
785
791
  channelName: r,
786
792
  source: "channel"
787
793
  });
788
794
  }
789
795
  }
790
- class Ge extends S {
796
+ class et extends C {
791
797
  constructor() {
792
798
  super(...arguments);
793
799
  l(this, "contractType", "MyOS Agent Channel");
794
- l(this, "contractBlueId", te["MyOS Agent Channel"]);
800
+ l(this, "contractBlueId", ne["MyOS Agent Channel"]);
795
801
  }
796
802
  supports(t, n, o) {
797
803
  if (!this.baseSupports(t)) return !1;
798
804
  try {
799
- const { myosAgentEvent: r, myosAgentChannel: a } = this.parseEventAndChannel(
805
+ const { myosAgentEvent: r, myosAgentChannel: s } = this.parseEventAndChannel(
800
806
  t,
801
807
  n,
802
808
  o
803
809
  );
804
- return this.isAgentMatch(r, a) && this.isEventPatternMatch(r, a, o);
810
+ return this.isAgentMatch(r, s) && this.isEventPatternMatch(r, s, o);
805
811
  } catch (r) {
806
812
  return console.warn("Error in MyOSAgentChannelProcessor.supports:", r), !1;
807
813
  }
@@ -818,14 +824,14 @@ class Ge extends S {
818
824
  * @throws {Error} If schema validation fails
819
825
  */
820
826
  parseEventAndChannel(t, n, o) {
821
- const r = o.getBlue(), a = r.nodeToSchemaOutput(
827
+ const r = o.getBlue(), s = r.nodeToSchemaOutput(
822
828
  t.payload,
823
- Me
824
- ), c = r.nodeToSchemaOutput(
825
- n,
826
829
  $e
830
+ ), i = r.nodeToSchemaOutput(
831
+ n,
832
+ qe
827
833
  );
828
- return { myosAgentEvent: a, myosAgentChannel: c };
834
+ return { myosAgentEvent: s, myosAgentChannel: i };
829
835
  }
830
836
  /**
831
837
  * Checks if the agent IDs match between event and channel
@@ -834,9 +840,9 @@ class Ge extends S {
834
840
  * @returns true if both have valid agent IDs and they match
835
841
  */
836
842
  isAgentMatch(t, n) {
837
- var a;
838
- const o = t.agentId, r = (a = n.agent) == null ? void 0 : a.agentId;
839
- return g(o) && g(r) && o === r;
843
+ var s;
844
+ const o = t.agentId, r = (s = n.agent) == null ? void 0 : s.agentId;
845
+ return E(o) && E(r) && o === r;
840
846
  }
841
847
  /**
842
848
  * Checks if the event pattern matches the channel's event filter
@@ -855,26 +861,36 @@ class Ge extends S {
855
861
  const r = n.event;
856
862
  if (!r)
857
863
  return !0;
858
- const a = t.event;
859
- if (!a)
864
+ const s = t.event;
865
+ if (!s)
860
866
  return !1;
861
867
  try {
862
- const c = o.getBlue(), i = c.nodeToJson(a), h = c.nodeToJson(r);
863
- return ee(i, h);
864
- } catch (c) {
865
- return console.warn("Error during event pattern matching:", c), !1;
868
+ const i = o.getBlue(), c = i.nodeToJson(s), h = i.nodeToJson(r);
869
+ return Oe(c, h);
870
+ } catch (i) {
871
+ return console.warn("Error during event pattern matching:", i), !1;
866
872
  }
867
873
  }
868
874
  }
869
- class et {
875
+ class tt {
870
876
  constructor() {
871
877
  l(this, "contractType", "Operation");
872
- l(this, "contractBlueId", f.Operation);
878
+ l(this, "contractBlueId", g.Operation);
873
879
  l(this, "role", "adapter");
874
880
  }
875
881
  supports(e, t, n, o) {
876
- const a = n.getBlue().nodeToSchemaOutput(t, Te), c = this.parseEventPayload(e, n);
877
- return g(c == null ? void 0 : c.operation) && c.operation === o && e.source === "channel" && e.channelName === a.channel;
882
+ const s = n.getBlue().nodeToSchemaOutput(t, Pe), i = this.parseEventPayload(e, n), c = this.isOperationNameMatch(
883
+ i,
884
+ o
885
+ ), h = this.isOperationChannelMatch(
886
+ e,
887
+ s
888
+ ), u = this.isRequestPatternMatch(
889
+ i,
890
+ s,
891
+ n
892
+ );
893
+ return c && h && u;
878
894
  }
879
895
  async handle(e, t, n, o) {
880
896
  n.emitEvent({
@@ -885,33 +901,50 @@ class et {
885
901
  }
886
902
  parseEventPayload(e, t) {
887
903
  const n = t.getBlue();
888
- if (n.isTypeOf(e.payload, N, {
904
+ if (n.isTypeOf(e.payload, O, {
889
905
  checkSchemaExtensions: !0
890
906
  })) {
891
907
  const o = n.nodeToSchemaOutput(
892
908
  e.payload,
893
- N
909
+ O
894
910
  );
895
911
  if (o.message)
896
912
  return n.nodeToSchemaOutput(
897
913
  o.message,
898
- Pe
914
+ be
899
915
  );
900
916
  }
901
917
  return null;
902
918
  }
919
+ isOperationNameMatch(e, t) {
920
+ return E(e == null ? void 0 : e.operation) && (e == null ? void 0 : e.operation) === t;
921
+ }
922
+ isOperationChannelMatch(e, t) {
923
+ const n = t.channel;
924
+ return _(n) ? !0 : e.source === "channel" && e.channelName === n;
925
+ }
926
+ isRequestPatternMatch(e, t, n) {
927
+ const o = t.request;
928
+ if (_(o))
929
+ return !0;
930
+ const r = n.getBlue(), s = e == null ? void 0 : e.request;
931
+ if (_(s))
932
+ return !1;
933
+ const i = r.resolve(s);
934
+ return r.isTypeOfNode(i, o);
935
+ }
903
936
  }
904
- class tt {
937
+ class nt {
905
938
  constructor() {
906
939
  l(this, "contractType", "Process Embedded");
907
940
  l(this, "role", "adapter");
908
- l(this, "contractBlueId", f["Process Embedded"]);
941
+ l(this, "contractBlueId", g["Process Embedded"]);
909
942
  }
910
943
  supports(e) {
911
944
  return e.source !== "channel";
912
945
  }
913
946
  handle(e, t, n) {
914
- const o = n.getBlue().nodeToSchemaOutput(t, D);
947
+ const o = n.getBlue().nodeToSchemaOutput(t, W);
915
948
  for (const r of o.paths ?? [])
916
949
  n.emitEvent({
917
950
  ...e,
@@ -919,20 +952,18 @@ class tt {
919
952
  });
920
953
  }
921
954
  }
922
- const ce = !process.env.SKIP_ISOLATED_VM;
923
- let E = null;
924
- if (ce)
925
- try {
926
- E = require("isolated-vm");
927
- } catch {
928
- console.warn("isolated-vm not available, using fallback evaluation method");
929
- }
930
- function K(s) {
931
- return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(s) || /\bexport\s+/.test(s);
955
+ let y = null;
956
+ try {
957
+ y = require("isolated-vm");
958
+ } catch {
959
+ y = null;
960
+ }
961
+ function ot(a) {
962
+ return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(a) || /\bexport\s+/.test(a);
932
963
  }
933
- class j {
964
+ class A {
934
965
  /**
935
- * Main evaluation method - chooses between secure and simple evaluation strategies
966
+ * Main evaluation method - evaluates code securely in an isolated VM
936
967
  */
937
968
  static async evaluate({
938
969
  code: e,
@@ -940,87 +971,60 @@ class j {
940
971
  bindings: n = {},
941
972
  options: o = {}
942
973
  }) {
943
- return !E || !ce ? this.evaluateSimple(e, n, o) : this.evaluateSecure(e, n, t, o);
944
- }
945
- /**
946
- * Fallback evaluation using Node's Function constructor
947
- * Used when isolated-vm is not available
948
- */
949
- static async evaluateSimple(e, t, n = {}) {
950
- if (K(e))
951
- throw new Error(
952
- "Static import/export syntax requires isolated-vm – start Node without SKIP_ISOLATED_VM."
953
- );
954
- try {
955
- if (n.isCodeBlock) {
956
- const o = Object.keys(t);
957
- return await (await new Function(
958
- ...o,
959
- `return async function codeBlock(${o.join(
960
- ", "
961
- )}) { ${e} }`
962
- )(
963
- ...o.map((c) => t[c])
964
- ))(...o.map((c) => t[c]));
965
- } else
966
- return new Function(
967
- ...Object.keys(t),
968
- `return ${e};`
969
- )(...Object.values(t));
970
- } catch (o) {
971
- throw n.isCodeBlock ? new L(e, o) : new F(e, o);
972
- }
974
+ if (!y)
975
+ throw new Error("isolated-vm is required for expression evaluation");
976
+ return this.evaluateSecure(e, n, t, o);
973
977
  }
974
978
  /**
975
979
  * Secure evaluation using isolated-vm with support for ES modules
976
980
  */
977
981
  static async evaluateSecure(e, t, n, o = {}) {
978
- if (!E) throw new Error("isolated-vm not available");
979
- const r = new E.Isolate({ memoryLimit: 32 }), a = await r.createContext(), c = a.global;
982
+ if (!y) throw new Error("isolated-vm not available");
983
+ const r = new y.Isolate({ memoryLimit: 32 }), s = await r.createContext(), i = s.global;
980
984
  try {
981
- await this.setupIsolateEnvironment(c, t);
982
- const i = /* @__PURE__ */ new Map(), h = this.createModuleResolver(
985
+ await this.setupIsolateEnvironment(i, t);
986
+ const c = /* @__PURE__ */ new Map(), h = this.createModuleResolver(
983
987
  r,
984
- a,
985
- i,
988
+ s,
989
+ c,
986
990
  n
987
991
  );
988
992
  let u;
989
- return K(e) ? u = await this.evaluateESModule(
993
+ return ot(e) ? u = await this.evaluateESModule(
990
994
  r,
991
- a,
995
+ s,
992
996
  e,
993
997
  o,
994
998
  h
995
999
  ) : u = await this.evaluateSimpleScript(
996
1000
  r,
997
- a,
1001
+ s,
998
1002
  e,
999
1003
  t,
1000
1004
  o
1001
1005
  ), this.deepClone(u);
1002
- } catch (i) {
1003
- throw o.isCodeBlock ? new L(e, i) : new F(e, i);
1006
+ } catch (c) {
1007
+ throw o.isCodeBlock ? new De(e, c) : new Ae(e, c);
1004
1008
  } finally {
1005
- a.release(), r.dispose();
1009
+ s.release(), r.dispose();
1006
1010
  }
1007
1011
  }
1008
1012
  /**
1009
1013
  * Setup the isolated VM environment with necessary host functions and data
1010
1014
  */
1011
1015
  static async setupIsolateEnvironment(e, t) {
1012
- if (!E) throw new Error("isolated-vm not available");
1013
- const n = new E.Callback(
1016
+ if (!y) throw new Error("isolated-vm not available");
1017
+ const n = new y.Callback(
1014
1018
  (...r) => console.log(...r)
1015
- ), o = new E.ExternalCopy({
1019
+ ), o = new y.ExternalCopy({
1016
1020
  log: n
1017
1021
  }).copyInto();
1018
1022
  await e.set("console", o);
1019
- for (const [r, a] of Object.entries(t))
1020
- typeof a == "function" ? await e.set(
1023
+ for (const [r, s] of Object.entries(t))
1024
+ typeof s == "function" ? await e.set(
1021
1025
  r,
1022
- new E.Callback(a)
1023
- ) : await e.set(r, new E.ExternalCopy(a).copyInto());
1026
+ new y.Callback(s)
1027
+ ) : await e.set(r, new y.ExternalCopy(s).copyInto());
1024
1028
  }
1025
1029
  /**
1026
1030
  * Create module resolver function for handling imports
@@ -1029,30 +1033,30 @@ class j {
1029
1033
  return async (r) => {
1030
1034
  if (n.has(r)) return n.get(r);
1031
1035
  if (r.startsWith("blue:")) {
1032
- const a = r.slice(5), c = o.loadBlueContent;
1033
- if (typeof c != "function")
1036
+ const s = r.slice(5), i = o.loadBlueContent;
1037
+ if (typeof i != "function")
1034
1038
  throw new Error(
1035
1039
  `ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${r})`
1036
1040
  );
1037
- const i = await c(a), h = await e.compileModule(i);
1041
+ const c = await i(s), h = await e.compileModule(c);
1038
1042
  return n.set(r, h), await h.instantiate(
1039
1043
  t,
1040
1044
  this.createModuleResolver(e, t, n, o)
1041
1045
  ), h;
1042
1046
  }
1043
1047
  if (/^https?:\/\//.test(r)) {
1044
- let a;
1048
+ let s;
1045
1049
  if (typeof o.loadExternalModule == "function")
1046
- a = await o.loadExternalModule(r);
1050
+ s = await o.loadExternalModule(r);
1047
1051
  else
1048
1052
  throw new Error(
1049
1053
  `ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${r})`
1050
1054
  );
1051
- const c = await e.compileModule(a);
1052
- return n.set(r, c), await c.instantiate(
1055
+ const i = await e.compileModule(s);
1056
+ return n.set(r, i), await i.instantiate(
1053
1057
  t,
1054
1058
  this.createModuleResolver(e, t, n, o)
1055
- ), c;
1059
+ ), i;
1056
1060
  }
1057
1061
  throw new Error(`Unsupported module specifier "${r}"`);
1058
1062
  };
@@ -1061,8 +1065,8 @@ class j {
1061
1065
  * Evaluate code as a simple script (no imports/exports)
1062
1066
  */
1063
1067
  static async evaluateSimpleScript(e, t, n, o, r) {
1064
- const a = Object.keys(o).join(", "), c = Object.keys(o).map((u) => u), i = `(async (${a}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${c.join(", ")})`;
1065
- return await (await e.compileScript(i)).run(t, {
1068
+ const s = Object.keys(o).join(", "), i = Object.keys(o).map((u) => u), c = `(async (${s}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${i.join(", ")})`;
1069
+ return await (await e.compileScript(c)).run(t, {
1066
1070
  timeout: r.timeout ?? 500,
1067
1071
  promise: !0,
1068
1072
  copy: !0,
@@ -1073,13 +1077,13 @@ class j {
1073
1077
  * Evaluate code as an ES module with import/export support
1074
1078
  */
1075
1079
  static async evaluateESModule(e, t, n, o, r) {
1076
- let a = n;
1080
+ let s = n;
1077
1081
  if (o.isCodeBlock) {
1078
1082
  const h = /^\s*(import\s.+?;|export\s.+?;)/gm, u = (n.match(h) || []).join(
1079
1083
  `
1080
1084
  `
1081
1085
  ), d = n.replace(h, "").trim();
1082
- a = `
1086
+ s = `
1083
1087
  ${u}
1084
1088
  const run = function() {
1085
1089
  ${d}
@@ -1087,13 +1091,13 @@ class j {
1087
1091
  export default run();
1088
1092
  `;
1089
1093
  }
1090
- const c = await e.compileModule(a);
1091
- return await c.instantiate(t, r), await c.evaluate({
1094
+ const i = await e.compileModule(s);
1095
+ return await i.instantiate(t, r), await i.evaluate({
1092
1096
  timeout: o.timeout ?? 500,
1093
1097
  promise: !0,
1094
1098
  reference: !0,
1095
1099
  release: !0
1096
- }), await c.namespace.get("default", {
1100
+ }), await i.namespace.get("default", {
1097
1101
  timeout: o.timeout ?? 500,
1098
1102
  promise: !0,
1099
1103
  copy: !0,
@@ -1108,197 +1112,242 @@ class j {
1108
1112
  return typeof e > "u" ? e : JSON.parse(JSON.stringify(e));
1109
1113
  }
1110
1114
  }
1111
- class V {
1115
+ class H {
1112
1116
  /**
1113
1117
  * Creates standard bindings for workflow step execution
1114
1118
  */
1115
1119
  static createStandardBindings(e, t, n) {
1116
- const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), a = x(r) ? r.toNumber() : r;
1120
+ const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), s = J(r) ? r.toNumber() : r;
1117
1121
  return {
1118
- document: (c) => {
1119
- const i = e.get(c);
1120
- return x(i) ? i.toNumber() : P(i) ? o.nodeToJson(i, "original") : i;
1122
+ document: (i) => {
1123
+ const c = e.get(i);
1124
+ return J(c) ? c.toNumber() : S(c) ? o.nodeToJson(c, "original") : c;
1121
1125
  },
1122
- event: a,
1126
+ event: s,
1123
1127
  steps: n
1124
1128
  };
1125
1129
  }
1126
1130
  }
1127
- function X(s, e) {
1128
- const { op: t, path: n, val: o, from: r } = s;
1131
+ const rt = /^\$\{([\s\S]*)\}$/, st = /\$\{([\s\S]*?)\}/, T = (a) => typeof a != "string" ? !1 : rt.test(a), z = (a) => typeof a != "string" ? !1 : st.test(a), ce = (a) => {
1132
+ if (!T(a))
1133
+ throw new Error(`Invalid expression: ${a}`);
1134
+ return a.slice(2, -1);
1135
+ };
1136
+ class q {
1137
+ static createBindings(e, t, n) {
1138
+ return H.createStandardBindings(e, t, n);
1139
+ }
1140
+ static async evaluate(e, t, n, o) {
1141
+ const { coerceToString: r } = o;
1142
+ if (T(e)) {
1143
+ const s = ce(e), i = await A.evaluate({
1144
+ code: s,
1145
+ ctx: t,
1146
+ bindings: n
1147
+ });
1148
+ return r ? String(i ?? "") : i;
1149
+ }
1150
+ if (z(e)) {
1151
+ const i = `\`${String(e).replace(/`/g, "\\`")}\``, c = await A.evaluate({
1152
+ code: i,
1153
+ ctx: t,
1154
+ bindings: n
1155
+ });
1156
+ return String(c ?? "");
1157
+ }
1158
+ return r ? String(e) : e;
1159
+ }
1160
+ }
1161
+ function Z(a, e) {
1162
+ const { op: t, path: n, val: o, from: r } = a;
1129
1163
  if ((t === "move" || t === "copy") && !r)
1130
1164
  throw new Error(`${t} operation requires 'from' path`);
1131
1165
  if ((t === "add" || t === "replace") && o === void 0)
1132
1166
  throw new Error(`${t} operation requires 'val' property`);
1133
- const a = {
1167
+ const s = {
1134
1168
  type: "Document Update",
1135
1169
  op: t,
1136
1170
  path: n
1137
1171
  };
1138
- return o !== void 0 && (a.val = o), r !== void 0 && (a.from = r), e.jsonValueToNode(a);
1172
+ return o !== void 0 && (s.val = o), r !== void 0 && (s.from = r), e.jsonValueToNode(s);
1139
1173
  }
1140
- function nt(s) {
1141
- return s.jsonValueToNode({
1174
+ function at(a) {
1175
+ return a.jsonValueToNode({
1142
1176
  type: "Document Processing Initiated"
1143
1177
  });
1144
1178
  }
1145
- const ot = /^\$\{(.*)\}$/, O = (s) => typeof s != "string" ? !1 : ot.test(s), Y = (s) => {
1146
- if (!O(s))
1147
- throw new Error(`Invalid expression: ${s}`);
1148
- return s.slice(2, -1);
1149
- };
1150
- class rt {
1179
+ class it {
1151
1180
  constructor() {
1152
1181
  l(this, "stepType", "Update Document");
1153
1182
  }
1154
1183
  supports(e) {
1155
- return b.isTypeOf(e, $);
1184
+ return b.isTypeOf(e, x);
1156
1185
  }
1157
1186
  async execute(e, t, n, o, r) {
1158
- const a = n.getBlue();
1159
- if (!b.isTypeOf(e, $)) return;
1160
- const c = await this.evaluateChangeset(
1187
+ const s = n.getBlue();
1188
+ if (!b.isTypeOf(e, x)) return;
1189
+ const i = await this.evaluateChangeset(
1161
1190
  e.get("/changeset"),
1162
1191
  n,
1163
1192
  t,
1164
1193
  r
1165
- ), i = G(e, {
1194
+ ), c = te(e, {
1166
1195
  op: "replace",
1167
1196
  path: "/changeset",
1168
- val: c
1169
- }), h = n.getBlue().nodeToSchemaOutput(i, $);
1197
+ val: i
1198
+ }), h = n.getBlue().nodeToSchemaOutput(c, x);
1170
1199
  for (const u of h.changeset ?? []) {
1171
1200
  if (!u.path) continue;
1172
- const d = u.val;
1173
- if ((u.op === "replace" || u.op === "add") && M(d)) {
1174
- const p = await this.evaluateChangeValue(
1175
- d,
1201
+ const d = await this.evaluateChangePath(
1202
+ u.path,
1203
+ n,
1204
+ t,
1205
+ r
1206
+ ), p = u.val;
1207
+ if ((u.op === "replace" || u.op === "add") && M(p)) {
1208
+ const f = await this.evaluateChangeValue(
1209
+ p,
1176
1210
  n,
1177
1211
  t,
1178
1212
  r
1179
1213
  );
1180
1214
  n.addPatch({
1181
1215
  op: u.op,
1182
- path: u.path,
1183
- val: p
1216
+ path: d,
1217
+ val: f
1184
1218
  }), n.emitEvent({
1185
- payload: X(
1219
+ payload: Z(
1186
1220
  {
1187
1221
  op: u.op,
1188
- path: n.resolvePath(u.path),
1189
- val: a.nodeToJson(p, "original")
1222
+ path: n.resolvePath(d),
1223
+ val: s.nodeToJson(f, "original")
1190
1224
  },
1191
- a
1192
- )
1225
+ s
1226
+ ),
1227
+ emissionType: "update"
1193
1228
  });
1194
1229
  }
1195
- u.op === "remove" && (n.addPatch({ op: u.op, path: u.path }), n.emitEvent({
1196
- payload: X(
1230
+ u.op === "remove" && (n.addPatch({ op: u.op, path: d }), n.emitEvent({
1231
+ payload: Z(
1197
1232
  {
1198
1233
  op: u.op,
1199
- path: n.resolvePath(u.path),
1234
+ path: n.resolvePath(d),
1200
1235
  val: null
1201
1236
  },
1202
- a
1203
- )
1237
+ s
1238
+ ),
1239
+ emissionType: "update"
1204
1240
  }));
1205
1241
  }
1206
1242
  }
1207
1243
  async evaluateChangeset(e, t, n, o) {
1208
1244
  const r = t.getBlue();
1209
- if (O(e)) {
1210
- const a = Y(e), c = await j.evaluate({
1211
- code: a,
1245
+ if (T(e)) {
1246
+ const s = ce(e), i = await A.evaluate({
1247
+ code: s,
1212
1248
  ctx: t,
1213
- bindings: V.createStandardBindings(
1249
+ bindings: H.createStandardBindings(
1214
1250
  t,
1215
1251
  n,
1216
1252
  o
1217
1253
  )
1218
1254
  });
1219
- return r.jsonValueToNode(c ?? null);
1255
+ return r.jsonValueToNode(i ?? null);
1220
1256
  }
1221
- if (P(e))
1257
+ if (S(e))
1222
1258
  return e;
1223
1259
  throw new Error("Invalid changeset: expected a string or document node");
1224
1260
  }
1225
1261
  async evaluateChangeValue(e, t, n, o) {
1226
- const r = e.getValue(), a = t.getBlue();
1227
- if (O(r)) {
1228
- const c = Y(r), i = await j.evaluate({
1229
- code: c,
1230
- ctx: t,
1231
- bindings: V.createStandardBindings(
1232
- t,
1233
- n,
1234
- o
1235
- )
1262
+ const r = e.getValue(), s = t.getBlue();
1263
+ if (T(r) || typeof r == "string" && z(r)) {
1264
+ const i = q.createBindings(
1265
+ t,
1266
+ n,
1267
+ o
1268
+ ), c = await q.evaluate(
1269
+ String(r),
1270
+ t,
1271
+ i,
1272
+ { coerceToString: !T(r) }
1273
+ );
1274
+ return s.jsonValueToNode(c ?? null);
1275
+ }
1276
+ return e;
1277
+ }
1278
+ async evaluateChangePath(e, t, n, o) {
1279
+ const r = q.createBindings(t, n, o);
1280
+ if (T(e) || z(e)) {
1281
+ const s = await q.evaluate(e, t, r, {
1282
+ coerceToString: !0
1236
1283
  });
1237
- return a.jsonValueToNode(i ?? null);
1284
+ return String(s ?? "");
1238
1285
  }
1239
1286
  return e;
1240
1287
  }
1241
1288
  }
1242
- class at {
1289
+ class ct {
1243
1290
  constructor() {
1244
1291
  l(this, "stepType", "Trigger Event");
1245
1292
  }
1246
1293
  supports(e) {
1247
- return b.isTypeOf(e, q);
1294
+ return b.isTypeOf(e, j);
1248
1295
  }
1249
1296
  async execute(e, t, n) {
1250
1297
  const o = n.getBlue();
1251
- if (!b.isTypeOf(e, q)) return;
1252
- const r = o.nodeToSchemaOutput(e, q);
1298
+ if (!b.isTypeOf(e, j)) return;
1299
+ const r = o.nodeToSchemaOutput(e, j);
1253
1300
  r.event && n.emitEvent({
1254
- payload: r.event
1301
+ payload: r.event,
1302
+ emissionType: "triggered"
1255
1303
  });
1256
1304
  }
1257
1305
  }
1258
- class st {
1306
+ class lt {
1259
1307
  constructor() {
1260
1308
  l(this, "stepType", "JavaScript Code");
1261
1309
  }
1262
1310
  supports(e) {
1263
- return b.isTypeOf(e, A);
1311
+ return b.isTypeOf(e, V);
1264
1312
  }
1265
1313
  async execute(e, t, n, o, r) {
1266
- if (!b.isTypeOf(e, A)) return;
1267
- const a = n.getBlue(), c = a.nodeToSchemaOutput(
1314
+ if (!b.isTypeOf(e, V)) return;
1315
+ const s = n.getBlue(), i = s.nodeToSchemaOutput(
1268
1316
  e,
1269
- A
1317
+ V
1270
1318
  );
1271
- if (!c.code)
1319
+ if (!i.code)
1272
1320
  throw new Error("JavaScript code is required");
1273
- const i = await j.evaluate({
1274
- code: c.code,
1321
+ const c = await A.evaluate({
1322
+ code: i.code,
1275
1323
  ctx: n,
1276
- bindings: V.createStandardBindings(n, t, r),
1324
+ bindings: H.createStandardBindings(n, t, r),
1277
1325
  options: {
1278
1326
  isCodeBlock: !0,
1279
1327
  timeout: 500
1280
1328
  }
1281
1329
  });
1282
- if (i && typeof i == "object" && "events" in i) {
1283
- const h = i;
1330
+ if (c && typeof c == "object" && "events" in c) {
1331
+ const h = c;
1284
1332
  if (Array.isArray(h.events))
1285
1333
  for (const u of h.events)
1286
1334
  n.emitEvent({
1287
- payload: a.jsonValueToNode(u)
1335
+ payload: s.jsonValueToNode(u),
1336
+ emissionType: "triggered"
1288
1337
  });
1289
1338
  }
1290
- return i;
1339
+ return c;
1291
1340
  }
1292
1341
  }
1293
- const ct = [
1294
- new rt(),
1295
- new at(),
1296
- new st()
1342
+ const ut = [
1343
+ new it(),
1344
+ new ct(),
1345
+ new lt()
1297
1346
  ];
1298
- class ie {
1299
- constructor(e = ct) {
1347
+ class le {
1348
+ constructor(e = ut) {
1300
1349
  l(this, "contractType", "Sequential Workflow");
1301
- l(this, "contractBlueId", f["Sequential Workflow"]);
1350
+ l(this, "contractBlueId", g["Sequential Workflow"]);
1302
1351
  l(this, "role", "handler");
1303
1352
  l(this, "executors", []);
1304
1353
  this.executors = e;
@@ -1308,16 +1357,16 @@ class ie {
1308
1357
  this.executors.push(e);
1309
1358
  }
1310
1359
  supports(e, t, n) {
1311
- const a = n.getBlue().nodeToSchemaOutput(
1360
+ const r = n.getBlue().nodeToSchemaOutput(
1312
1361
  t,
1313
1362
  Se
1314
- ).channel;
1315
- return e.source === "channel" && e.channelName === a;
1363
+ ), s = this.isChannelNameMatch(e, r), i = this.isEventPatternMatch(e, t, n);
1364
+ return s && i;
1316
1365
  }
1317
1366
  async handle(e, t, n, o) {
1318
- var c;
1319
- const r = {}, a = (c = t.getProperties()) == null ? void 0 : c.steps.getItems();
1320
- for (const [i, h] of (a ?? []).entries()) {
1367
+ var i;
1368
+ const r = {}, s = (i = t.getProperties()) == null ? void 0 : i.steps.getItems();
1369
+ for (const [c, h] of (s ?? []).entries()) {
1321
1370
  const u = this.executors.find((p) => p.supports(h));
1322
1371
  if (!u)
1323
1372
  throw new Error(`Unsupported workflow step type "${h.getType()}"`);
@@ -1329,27 +1378,46 @@ class ie {
1329
1378
  r
1330
1379
  );
1331
1380
  if (d !== void 0) {
1332
- const p = h.getName(), m = typeof p == "string" ? p : `Step${i + 1}`;
1333
- r[m] = d;
1381
+ const p = h.getName(), f = typeof p == "string" ? p : `Step${c + 1}`;
1382
+ r[f] = d;
1334
1383
  }
1335
1384
  await n.flush();
1336
1385
  }
1337
1386
  }
1387
+ isChannelNameMatch(e, t) {
1388
+ const n = t.channel;
1389
+ return M(n) && e.source === "channel" && e.channelName === n;
1390
+ }
1391
+ /**
1392
+ * Checks if the event matches the channel's event pattern (if specified)
1393
+ */
1394
+ isEventPatternMatch(e, t, n) {
1395
+ var r;
1396
+ const o = (r = t.getProperties()) == null ? void 0 : r.event;
1397
+ if (!o)
1398
+ return !0;
1399
+ try {
1400
+ const s = n.getBlue(), i = s.resolve(e.payload);
1401
+ return s.isTypeOfNode(i, o);
1402
+ } catch (s) {
1403
+ return console.warn("Error during event pattern matching:", s), !1;
1404
+ }
1405
+ }
1338
1406
  }
1339
- class it {
1407
+ class ht {
1340
1408
  constructor(e) {
1341
1409
  l(this, "contractType", "Sequential Workflow Operation");
1342
- l(this, "contractBlueId", f["Sequential Workflow Operation"]);
1410
+ l(this, "contractBlueId", g["Sequential Workflow Operation"]);
1343
1411
  l(this, "role", "handler");
1344
1412
  l(this, "sequentialWorkflowProcessor");
1345
- this.sequentialWorkflowProcessor = e || new ie();
1413
+ this.sequentialWorkflowProcessor = e || new le();
1346
1414
  }
1347
1415
  supports(e, t, n) {
1348
- const a = n.getBlue().nodeToSchemaOutput(
1416
+ const s = n.getBlue().nodeToSchemaOutput(
1349
1417
  t,
1350
1418
  Ce
1351
- ).operation, c = e.channelName;
1352
- return e.source === "channel" && M(c) && M(a) && c === a;
1419
+ ).operation, i = e.channelName;
1420
+ return e.source === "channel" && M(i) && M(s) && i === s;
1353
1421
  }
1354
1422
  async handle(e, t, n, o) {
1355
1423
  try {
@@ -1362,68 +1430,86 @@ class it {
1362
1430
  }
1363
1431
  }
1364
1432
  }
1365
- const Z = (s) => b.isTypeOf(s.payload, N);
1366
- class lt extends S {
1433
+ const ee = (a) => b.isTypeOf(a.payload, O);
1434
+ class dt extends C {
1367
1435
  constructor() {
1368
1436
  super(...arguments);
1369
1437
  l(this, "contractType", "Timeline Channel");
1370
- l(this, "contractBlueId", f["Timeline Channel"]);
1438
+ l(this, "contractBlueId", g["Timeline Channel"]);
1371
1439
  }
1372
1440
  supports(t, n, o) {
1373
1441
  var u;
1374
- if (!this.baseSupports(t) || !Z(t)) return !1;
1375
- const a = o.getBlue().nodeToSchemaOutput(
1442
+ if (!this.baseSupports(t) || !ee(t)) return !1;
1443
+ const s = o.getBlue().nodeToSchemaOutput(
1376
1444
  t.payload,
1377
- N
1378
- ), c = o.getBlue().nodeToSchemaOutput(n, ke), i = (u = a.timeline) == null ? void 0 : u.timelineId;
1379
- return g(c.timelineId) && g(i) && i === c.timelineId;
1445
+ O
1446
+ ), i = o.getBlue().nodeToSchemaOutput(n, Ne), c = (u = s.timeline) == null ? void 0 : u.timelineId;
1447
+ return E(i.timelineId) && E(c) && c === i.timelineId;
1380
1448
  }
1381
1449
  handle(t, n, o, r) {
1382
- Z(t) && o.emitEvent({
1450
+ ee(t) && o.emitEvent({
1383
1451
  payload: t.payload,
1384
1452
  channelName: r,
1385
1453
  source: "channel"
1386
1454
  });
1387
1455
  }
1388
1456
  }
1389
- const ut = [
1390
- new tt(),
1457
+ class pt extends C {
1458
+ constructor() {
1459
+ super(...arguments);
1460
+ l(this, "contractType", "Triggered Event Channel");
1461
+ l(this, "contractBlueId", g["Triggered Event Channel"]);
1462
+ }
1463
+ supports(t) {
1464
+ return this.baseSupports(t) ? t.emissionType === "triggered" : !1;
1465
+ }
1466
+ handle(t, n, o, r) {
1467
+ o.emitEvent({
1468
+ payload: t.payload,
1469
+ channelName: r,
1470
+ source: "channel"
1471
+ });
1472
+ }
1473
+ }
1474
+ const ft = [
1475
+ new nt(),
1391
1476
  // channels
1392
- new Ke(),
1477
+ new Ge(),
1393
1478
  new Qe(),
1394
- new lt(),
1479
+ new dt(),
1395
1480
  new Ze(),
1396
- new Ge(),
1397
- new He(),
1398
- new Ye(),
1399
1481
  new et(),
1482
+ new Xe(),
1483
+ new Ye(),
1484
+ new pt(),
1485
+ new tt(),
1400
1486
  // sequential workflows
1401
- new ie(),
1402
- new it(),
1487
+ new le(),
1488
+ new ht(),
1403
1489
  // markers
1404
- new Xe()
1490
+ new Ke()
1405
1491
  ];
1406
- class gt {
1492
+ class Tt {
1407
1493
  /**
1408
1494
  * Creates a new document processor
1409
1495
  *
1410
1496
  * @param processors - Initial list of processors to register
1411
1497
  */
1412
- constructor(e, t = ut) {
1498
+ constructor(e, t = ft) {
1413
1499
  l(this, "taskCounter", 0);
1414
1500
  l(this, "eventCounter", 0);
1415
1501
  l(this, "registry");
1416
1502
  l(this, "queue");
1417
1503
  l(this, "router");
1418
1504
  l(this, "checkpointCache", new Re());
1419
- this.blue = e, this.registry = new We(t), this.queue = new Ve(), this.router = new Fe(
1505
+ this.blue = e, this.registry = new We(t), this.queue = new _e(), this.router = new ze(
1420
1506
  this.blue,
1421
1507
  this.registry,
1422
1508
  this.queue,
1423
1509
  () => ++this.taskCounter,
1424
1510
  () => ++this.eventCounter
1425
1511
  ), this.register(
1426
- new Ue(this.checkpointCache),
1512
+ new Fe(this.checkpointCache),
1427
1513
  9999
1428
1514
  );
1429
1515
  }
@@ -1443,13 +1529,15 @@ class gt {
1443
1529
  * @returns Processing result with final state and emitted events
1444
1530
  */
1445
1531
  async initialize(e) {
1446
- let t = R(I(e), this.blue);
1532
+ let t = G(I(e), this.blue);
1447
1533
  const n = {
1448
- payload: nt(this.blue)
1534
+ payload: at(this.blue),
1535
+ source: "internal",
1536
+ emissionType: "lifecycle"
1449
1537
  }, o = [n.payload];
1450
1538
  await this.router.route(t, [], n, 0);
1451
1539
  const r = await this.drainQueue(t);
1452
- return t = r.state, o.push(...r.emitted), t = ze(t, this.blue), { state: B(t), emitted: o };
1540
+ return t = r.state, o.push(...r.emitted), t = He(t, this.blue), { state: $(t), emitted: o };
1453
1541
  }
1454
1542
  /**
1455
1543
  * Processes a batch of events against the document
@@ -1459,83 +1547,83 @@ class gt {
1459
1547
  * @returns Processing result with final state and emitted events
1460
1548
  */
1461
1549
  async processEvents(e, t) {
1462
- let n = R(I(e), this.blue);
1550
+ let n = G(I(e), this.blue);
1463
1551
  const o = [];
1464
- if (!se(n, this.blue))
1552
+ if (!ie(n, this.blue))
1465
1553
  throw new Error("Document is not initialized");
1466
1554
  for (const r of t)
1467
1555
  try {
1468
- const a = { payload: r, source: "external" };
1469
- await this.router.route(n, [], a, 0);
1470
- const c = await this.drainQueue(n);
1471
- n = c.state, o.push(...c.emitted);
1472
- const i = this.checkpointCache.flush(n);
1473
- i.length && (n = U(n, i));
1556
+ const s = { payload: r, source: "external" };
1557
+ await this.router.route(n, [], s, 0);
1558
+ const i = await this.drainQueue(n);
1559
+ n = i.state, o.push(...i.emitted);
1560
+ const c = this.checkpointCache.flush(n);
1561
+ c.length && (n = Q(n, c));
1474
1562
  } finally {
1475
1563
  this.checkpointCache.clear();
1476
1564
  }
1477
- return { state: B(n), emitted: o };
1565
+ return { state: $(n), emitted: o };
1478
1566
  }
1479
1567
  /**
1480
1568
  * Drains the task queue and applies all actions
1481
1569
  */
1482
1570
  async drainQueue(e) {
1483
- var a;
1571
+ var s;
1484
1572
  let t = e;
1485
1573
  const n = [], o = 1e4;
1486
1574
  let r = 0;
1487
1575
  for (; this.queue.length; ) {
1488
1576
  if (++r > o)
1489
1577
  throw new Error("Possible cycle – too many iterations");
1490
- const c = this.queue.pop(), { nodePath: i, contractName: h, contractNode: u, event: d } = c, p = t.get(i);
1491
- if (!P(p) || !((a = p.getContracts()) != null && a[h]) || !u.getType()) continue;
1492
- const m = this.registry.get(u.getType());
1493
- if (!m) {
1578
+ const i = this.queue.pop(), { nodePath: c, contractName: h, contractNode: u, event: d } = i, p = t.get(c);
1579
+ if (!S(p) || !((s = p.getContracts()) != null && s[h]) || !u.getType()) continue;
1580
+ const f = this.registry.get(u.getType());
1581
+ if (!f) {
1494
1582
  console.warn(`No processor registered for contract: ${h}`);
1495
1583
  continue;
1496
1584
  }
1497
- const w = new oe(
1585
+ const v = new re(
1498
1586
  () => t,
1499
- c,
1587
+ i,
1500
1588
  this.blue,
1501
- async (T) => {
1502
- for (const y of T)
1503
- if (y.kind === "patch") {
1504
- const ue = W(
1589
+ async (w) => {
1590
+ for (const m of w)
1591
+ if (m.kind === "patch") {
1592
+ const D = U(
1505
1593
  t,
1506
1594
  this.blue
1507
1595
  );
1508
- for (const C of ue) {
1509
- const he = y.patch.op === "move" || y.patch.op === "copy" ? [y.patch.from, y.patch.path] : [y.patch.path], J = w.getNodePath(), de = he.some(
1510
- (fe) => z(fe, C.absPath)
1511
- ), pe = z(
1512
- J,
1513
- C.absPath
1596
+ for (const N of D) {
1597
+ const he = m.patch.op === "move" || m.patch.op === "copy" ? [m.patch.from, m.patch.path] : [m.patch.path], F = v.getNodePath(), de = he.some(
1598
+ (fe) => X(fe, N.absPath)
1599
+ ), pe = X(
1600
+ F,
1601
+ N.absPath
1514
1602
  );
1515
1603
  if (de && !pe)
1516
1604
  throw new ae(
1517
- y.patch,
1518
- C.absPath,
1519
- J
1605
+ m.patch,
1606
+ N.absPath,
1607
+ F
1520
1608
  );
1521
1609
  }
1522
1610
  try {
1523
- t = U(t, [y.patch]);
1524
- } catch (C) {
1525
- throw Le(h, d, C), C;
1611
+ t = Q(t, [m.patch]);
1612
+ } catch (N) {
1613
+ throw Ue(h, d, N), N;
1526
1614
  }
1527
- } else y.kind === "event" && (n.push(y.event.payload), await this.router.route(t, [], y.event, c.key[5]));
1615
+ } else m.kind === "event" && (n.push(m.event.payload), await this.router.route(t, [], m.event, i.key[5]));
1528
1616
  }
1529
1617
  );
1530
- await m.handle(d, u, w, h), await w.flush();
1618
+ await f.handle(d, u, v, h), await v.flush();
1531
1619
  }
1532
1620
  return { state: t, emitted: n };
1533
1621
  }
1534
1622
  }
1535
- class le {
1623
+ class ue {
1536
1624
  process(e, t) {
1537
1625
  const n = t.getValue();
1538
- if (O(n)) {
1626
+ if (T(n)) {
1539
1627
  const o = t.clone();
1540
1628
  return o.setValue(n), o.setProperties(void 0), o.setItems(void 0), o.setType(void 0), o;
1541
1629
  }
@@ -1546,21 +1634,21 @@ class le {
1546
1634
  */
1547
1635
  postProcess(e, t) {
1548
1636
  const n = t.getValue();
1549
- if (O(n) && e.getValue() !== n && n !== void 0) {
1637
+ if (T(n) && e.getValue() !== n && n !== void 0) {
1550
1638
  const o = e.clone();
1551
1639
  return o.setValue(n), o;
1552
1640
  }
1553
1641
  return e;
1554
1642
  }
1555
1643
  }
1556
- const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1644
+ const Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1557
1645
  __proto__: null,
1558
- ExpressionPreserver: le
1646
+ ExpressionPreserver: ue
1559
1647
  }, Symbol.toStringTag, { value: "Module" }));
1560
- function wt() {
1648
+ function bt() {
1561
1649
  return new k.SequentialMergingProcessor([
1562
1650
  new k.ValuePropagator(),
1563
- new le(),
1651
+ new ue(),
1564
1652
  new k.TypeAssigner(),
1565
1653
  new k.ListProcessor(),
1566
1654
  new k.DictionaryProcessor(),
@@ -1568,25 +1656,26 @@ function wt() {
1568
1656
  ]);
1569
1657
  }
1570
1658
  export {
1571
- gt as BlueDocumentProcessor,
1572
- Ue as ChannelEventCheckpointProcessor,
1573
- L as CodeBlockEvaluationError,
1574
- He as CompositeTimelineChannelProcessor,
1659
+ Tt as BlueDocumentProcessor,
1660
+ Fe as ChannelEventCheckpointProcessor,
1661
+ De as CodeBlockEvaluationError,
1662
+ Xe as CompositeTimelineChannelProcessor,
1575
1663
  Qe as DocumentUpdateChannelProcessor,
1576
1664
  ae as EmbeddedDocumentModificationError,
1577
- Ke as EmbeddedNodeChannelProcessor,
1578
- F as ExpressionEvaluationError,
1579
- Xe as InitializedMarkerProcessor,
1665
+ Ge as EmbeddedNodeChannelProcessor,
1666
+ Ae as ExpressionEvaluationError,
1667
+ Ke as InitializedMarkerProcessor,
1580
1668
  Ye as LifecycleEventChannelProcessor,
1581
- Et as MergingProcessors,
1582
- Ge as MyOSAgentChannelProcessor,
1669
+ Pt as MergingProcessors,
1670
+ et as MyOSAgentChannelProcessor,
1583
1671
  Ze as MyOSTimelineChannelProcessor,
1584
- et as OperationProcessor,
1585
- re as PatchApplicationError,
1586
- tt as ProcessEmbeddedProcessor,
1587
- it as SequentialWorkflowOperationProcessor,
1588
- ie as SequentialWorkflowProcessor,
1589
- lt as TimelineChannelProcessor,
1590
- W as collectEmbeddedPathSpecs,
1591
- wt as createDefaultMergingProcessor
1672
+ tt as OperationProcessor,
1673
+ se as PatchApplicationError,
1674
+ nt as ProcessEmbeddedProcessor,
1675
+ ht as SequentialWorkflowOperationProcessor,
1676
+ le as SequentialWorkflowProcessor,
1677
+ dt as TimelineChannelProcessor,
1678
+ pt as TriggeredEventChannelProcessor,
1679
+ U as collectEmbeddedPathSpecs,
1680
+ bt as createDefaultMergingProcessor
1592
1681
  };