@blue-labs/document-processor 1.32.1 → 1.33.1

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 +5 -4
  6. package/dist/index.mjs +643 -522
  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 +3 -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
- 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) => {
1
+ var fe = Object.defineProperty;
2
+ var ge = (a, e, t) => e in a ? fe(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 ve, DocumentUpdateChannelSchema as we, EmbeddedNodeChannelSchema as F, LifecycleEventSchema as Te, TimelineEntrySchema as O, OperationSchema as be, OperationRequestSchema as Pe, UpdateDocumentSchema as j, TriggerEventSchema as x, 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 L, BlueNodeTypeSchema as P, 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 b = (...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 = b(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: b(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 b(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)) {
109
- const h = e.nodeToSchemaOutput(
110
- a,
111
- D
100
+ function z(a, e, t = "/", n = []) {
101
+ const o = a.getContracts() ?? {};
102
+ for (const [r, s] of Object.entries(o))
103
+ if (e.isTypeOf(s, W)) {
104
+ const d = e.nodeToSchemaOutput(
105
+ s,
106
+ W
112
107
  ).paths ?? [];
113
- for (const u of h)
108
+ for (const u of d)
114
109
  n.push({
115
- absPath: v(t, u),
116
- contractPath: v(t, `contracts/${r}`)
110
+ absPath: b(t, u),
111
+ contractPath: b(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
+ z(
116
+ s,
122
117
  e,
123
- v(t, r),
118
+ b(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 je {
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 xe = (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 je([], 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 J = B;
349
+ function Le(a) {
350
+ return Object.entries(a.getContracts() ?? {});
354
351
  }
355
- const _e = 64;
356
- class Fe {
352
+ const Je = 64;
353
+ class Ue {
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 J();
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
- const h = n.dispatchPath.split("/").filter(Boolean), u = { ...n };
383
- return delete u.dispatchPath, this.route(e, h, u, o, r);
379
+ const d = n.dispatchPath.split("/").filter(Boolean), u = { ...n };
380
+ return delete u.dispatchPath, this.route(e, d, 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)) ?? [];
387
- return this.route(e, h, n, o, r);
383
+ const d = ((c = n.originNodePath) == null ? void 0 : c.split("/").filter(Boolean)) ?? [];
384
+ return this.route(e, d, 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 = b("/", 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,48 +404,46 @@ 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 [d, u] of Le(n)) {
418
413
  if (!u.getType()) continue;
419
- const d = this.registry.get(u.getType());
420
- if (!d) {
421
- console.warn(`No processor registered for contract: ${h}`);
414
+ const h = this.registry.get(u.getType());
415
+ if (!h) {
416
+ console.warn(`No processor registered for contract: ${d}`);
422
417
  continue;
423
418
  }
424
419
  const p = {
425
420
  nodePath: o,
426
- contractName: h,
421
+ contractName: d,
427
422
  contractNode: u,
428
423
  event: r
429
- }, m = new oe(() => t, p, this.blue);
430
- if (d.supports(r, u, m, h))
431
- switch (d.role) {
424
+ }, m = new re(() => t, p, this.blue);
425
+ if (h.supports(r, u, m, d))
426
+ switch (h.role) {
432
427
  case "adapter":
433
428
  await this.processAdapter({
434
- cp: d,
429
+ cp: h,
435
430
  event: r,
436
431
  contractNode: u,
437
432
  ctx: m,
438
- contractName: h,
433
+ contractName: d,
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":
445
440
  this.scheduleHandler({
446
441
  contractNode: u,
447
- contractName: h,
442
+ contractName: d,
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
  }
@@ -464,51 +459,62 @@ class Fe {
464
459
  event: n,
465
460
  contractNode: o,
466
461
  ctx: r,
467
- contractName: a,
468
- doc: c,
469
- afterTaskId: i,
470
- inlineDepth: h
462
+ contractName: s,
463
+ doc: i,
464
+ afterTaskId: c,
465
+ inlineDepth: d
471
466
  } = e;
472
- if (h >= _e)
467
+ if (d >= Je)
473
468
  throw new Error("Adapter recursion limit reached");
474
469
  const u = this.traceManager.addHop(
475
470
  n,
476
471
  ((w = r.getTaskInfo()) == null ? void 0 : w.nodePath) ?? "",
477
- a
472
+ s
478
473
  );
479
- await t.handle(u, o, r, a);
480
- const d = await r.flush();
481
- if (d.find((T) => T.kind === "patch"))
474
+ await t.handle(u, o, r, s);
475
+ const h = await r.flush();
476
+ if (h.find((v) => v.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 m = h.filter((v) => v.kind === "event");
481
+ for (const v of m)
482
+ await this.route(i, [], v.event, c, d + 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,
501
- h,
493
+ const d = this.registry.orderOf(c), u = t.get("/order"), h = L(u) ? u.toNumber() : 0, p = this.getNextTaskId() + i, m = r.seq;
494
+ if (m === void 0)
495
+ throw new Error("Event sequence missing");
496
+ const w = xe(
497
+ s,
498
+ m,
502
499
  d,
500
+ h,
503
501
  n,
504
502
  p
505
- ), w = this.traceManager.addHop(r, o, n);
503
+ );
504
+ {
505
+ const f = `${o}#${n}`, D = r.trace ?? [];
506
+ if (r.source !== "external" && D.includes(f))
507
+ throw new Error(
508
+ `Loop detected: repeated hop ${f} within the same event chain`
509
+ );
510
+ }
511
+ const v = this.traceManager.addHop(r, o, n);
506
512
  this.queue.push({
507
- key: m,
513
+ key: w,
508
514
  nodePath: o,
509
515
  contractName: n,
510
516
  contractNode: t,
511
- event: w
517
+ event: v
512
518
  });
513
519
  }
514
520
  /**
@@ -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 ze = (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
- (!(r != null && r.checkpoint) || !b.isTypeOf(
537
+ (!(r != null && r.checkpoint) || !P.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 z(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 Re(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 He {
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,21 +593,21 @@ 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;
604
- class Re {
609
+ const K = (a, e) => a.get(e) !== void 0;
610
+ class Fe {
605
611
  constructor() {
606
612
  l(this, "firstSeen", /* @__PURE__ */ new Map());
607
613
  }
@@ -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 = b(
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, ve);
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, we), 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, F);
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, F), { 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), d = i.nodeToJson(r);
869
+ return Oe(c, d);
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, be), i = this.parseEventPayload(e, n), c = this.isOperationNameMatch(
883
+ i,
884
+ o
885
+ ), d = this.isOperationChannelMatch(
886
+ e,
887
+ s
888
+ ), u = this.isRequestPatternMatch(
889
+ i,
890
+ s,
891
+ n
892
+ );
893
+ return c && d && u;
878
894
  }
879
895
  async handle(e, t, n, o) {
880
896
  n.emitEvent({
@@ -885,12 +901,12 @@ 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(
@@ -900,18 +916,35 @@ class et {
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,50 @@ 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
+ function ot(a) {
957
+ return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(a) || /\bexport\s+/.test(a);
932
958
  }
933
- class j {
959
+ class A {
960
+ static getIvmUnavailableMessage() {
961
+ const e = typeof process < "u" && process.version ? process.version : "unknown", t = typeof process < "u" && process.platform ? process.platform : "unknown", n = typeof process < "u" && process.arch ? process.arch : "unknown";
962
+ return [
963
+ "isolated-vm is required for expression evaluation but could not be loaded.",
964
+ "This feature only works in a Node.js environment with the native addon available.",
965
+ "",
966
+ `Detected environment: Node ${e} on ${t}/${n}.`,
967
+ "",
968
+ "Common causes:",
969
+ "- Running in a non-Node environment (browser, edge/runtime without Node).",
970
+ "- 'isolated-vm' is not installed, or failed to build its native addon.",
971
+ "- The module was bundled/stripped by a build tool.",
972
+ "",
973
+ "How to fix:",
974
+ "- Ensure 'isolated-vm' is listed in dependencies (not devDependencies) of the executing package.",
975
+ "- Reinstall or rebuild: npm ci && npm rebuild isolated-vm (or equivalent with your package manager).",
976
+ "- Run this code on a supported Node.js runtime (not browser/edge workers)."
977
+ ].join(`
978
+ `);
979
+ }
980
+ static async ensureIvmLoaded() {
981
+ var t;
982
+ if (!(y || !(typeof process < "u" && ((t = process.versions) != null && t.node)))) {
983
+ try {
984
+ if (typeof require == "function") {
985
+ y = require("isolated-vm");
986
+ return;
987
+ }
988
+ } catch {
989
+ }
990
+ try {
991
+ const r = await import("isolated-vm").catch(() => null);
992
+ y = (r == null ? void 0 : r.default) ?? r;
993
+ } catch {
994
+ }
995
+ }
996
+ }
934
997
  /**
935
- * Main evaluation method - chooses between secure and simple evaluation strategies
998
+ * Main evaluation method - evaluates code securely in an isolated VM
936
999
  */
937
1000
  static async evaluate({
938
1001
  code: e,
@@ -940,87 +1003,60 @@ class j {
940
1003
  bindings: n = {},
941
1004
  options: o = {}
942
1005
  }) {
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
- }
1006
+ if (await this.ensureIvmLoaded(), !y)
1007
+ throw new Error(this.getIvmUnavailableMessage());
1008
+ return this.evaluateSecure(e, n, t, o);
973
1009
  }
974
1010
  /**
975
1011
  * Secure evaluation using isolated-vm with support for ES modules
976
1012
  */
977
1013
  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;
1014
+ if (!y) throw new Error(this.getIvmUnavailableMessage());
1015
+ const r = new y.Isolate({ memoryLimit: 32 }), s = await r.createContext(), i = s.global;
980
1016
  try {
981
- await this.setupIsolateEnvironment(c, t);
982
- const i = /* @__PURE__ */ new Map(), h = this.createModuleResolver(
1017
+ await this.setupIsolateEnvironment(i, t);
1018
+ const c = /* @__PURE__ */ new Map(), d = this.createModuleResolver(
983
1019
  r,
984
- a,
985
- i,
1020
+ s,
1021
+ c,
986
1022
  n
987
1023
  );
988
1024
  let u;
989
- return K(e) ? u = await this.evaluateESModule(
1025
+ return ot(e) ? u = await this.evaluateESModule(
990
1026
  r,
991
- a,
1027
+ s,
992
1028
  e,
993
1029
  o,
994
- h
1030
+ d
995
1031
  ) : u = await this.evaluateSimpleScript(
996
1032
  r,
997
- a,
1033
+ s,
998
1034
  e,
999
1035
  t,
1000
1036
  o
1001
1037
  ), this.deepClone(u);
1002
- } catch (i) {
1003
- throw o.isCodeBlock ? new L(e, i) : new F(e, i);
1038
+ } catch (c) {
1039
+ throw o.isCodeBlock ? new De(e, c) : new Ae(e, c);
1004
1040
  } finally {
1005
- a.release(), r.dispose();
1041
+ s.release(), r.dispose();
1006
1042
  }
1007
1043
  }
1008
1044
  /**
1009
1045
  * Setup the isolated VM environment with necessary host functions and data
1010
1046
  */
1011
1047
  static async setupIsolateEnvironment(e, t) {
1012
- if (!E) throw new Error("isolated-vm not available");
1013
- const n = new E.Callback(
1048
+ if (!y) throw new Error("isolated-vm not available");
1049
+ const n = new y.Callback(
1014
1050
  (...r) => console.log(...r)
1015
- ), o = new E.ExternalCopy({
1051
+ ), o = new y.ExternalCopy({
1016
1052
  log: n
1017
1053
  }).copyInto();
1018
1054
  await e.set("console", o);
1019
- for (const [r, a] of Object.entries(t))
1020
- typeof a == "function" ? await e.set(
1055
+ for (const [r, s] of Object.entries(t))
1056
+ typeof s == "function" ? await e.set(
1021
1057
  r,
1022
- new E.Callback(a)
1023
- ) : await e.set(r, new E.ExternalCopy(a).copyInto());
1058
+ new y.Callback(s)
1059
+ ) : await e.set(r, new y.ExternalCopy(s).copyInto());
1024
1060
  }
1025
1061
  /**
1026
1062
  * Create module resolver function for handling imports
@@ -1029,30 +1065,30 @@ class j {
1029
1065
  return async (r) => {
1030
1066
  if (n.has(r)) return n.get(r);
1031
1067
  if (r.startsWith("blue:")) {
1032
- const a = r.slice(5), c = o.loadBlueContent;
1033
- if (typeof c != "function")
1068
+ const s = r.slice(5), i = o.loadBlueContent;
1069
+ if (typeof i != "function")
1034
1070
  throw new Error(
1035
1071
  `ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${r})`
1036
1072
  );
1037
- const i = await c(a), h = await e.compileModule(i);
1038
- return n.set(r, h), await h.instantiate(
1073
+ const c = await i(s), d = await e.compileModule(c);
1074
+ return n.set(r, d), await d.instantiate(
1039
1075
  t,
1040
1076
  this.createModuleResolver(e, t, n, o)
1041
- ), h;
1077
+ ), d;
1042
1078
  }
1043
1079
  if (/^https?:\/\//.test(r)) {
1044
- let a;
1080
+ let s;
1045
1081
  if (typeof o.loadExternalModule == "function")
1046
- a = await o.loadExternalModule(r);
1082
+ s = await o.loadExternalModule(r);
1047
1083
  else
1048
1084
  throw new Error(
1049
1085
  `ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${r})`
1050
1086
  );
1051
- const c = await e.compileModule(a);
1052
- return n.set(r, c), await c.instantiate(
1087
+ const i = await e.compileModule(s);
1088
+ return n.set(r, i), await i.instantiate(
1053
1089
  t,
1054
1090
  this.createModuleResolver(e, t, n, o)
1055
- ), c;
1091
+ ), i;
1056
1092
  }
1057
1093
  throw new Error(`Unsupported module specifier "${r}"`);
1058
1094
  };
@@ -1061,8 +1097,8 @@ class j {
1061
1097
  * Evaluate code as a simple script (no imports/exports)
1062
1098
  */
1063
1099
  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, {
1100
+ const s = Object.keys(o).join(", "), i = Object.keys(o).map((u) => u), c = `(async (${s}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${i.join(", ")})`;
1101
+ return await (await e.compileScript(c)).run(t, {
1066
1102
  timeout: r.timeout ?? 500,
1067
1103
  promise: !0,
1068
1104
  copy: !0,
@@ -1073,27 +1109,27 @@ class j {
1073
1109
  * Evaluate code as an ES module with import/export support
1074
1110
  */
1075
1111
  static async evaluateESModule(e, t, n, o, r) {
1076
- let a = n;
1112
+ let s = n;
1077
1113
  if (o.isCodeBlock) {
1078
- const h = /^\s*(import\s.+?;|export\s.+?;)/gm, u = (n.match(h) || []).join(
1114
+ const d = /^\s*(import\s.+?;|export\s.+?;)/gm, u = (n.match(d) || []).join(
1079
1115
  `
1080
1116
  `
1081
- ), d = n.replace(h, "").trim();
1082
- a = `
1117
+ ), h = n.replace(d, "").trim();
1118
+ s = `
1083
1119
  ${u}
1084
1120
  const run = function() {
1085
- ${d}
1121
+ ${h}
1086
1122
  };
1087
1123
  export default run();
1088
1124
  `;
1089
1125
  }
1090
- const c = await e.compileModule(a);
1091
- return await c.instantiate(t, r), await c.evaluate({
1126
+ const i = await e.compileModule(s);
1127
+ return await i.instantiate(t, r), await i.evaluate({
1092
1128
  timeout: o.timeout ?? 500,
1093
1129
  promise: !0,
1094
1130
  reference: !0,
1095
1131
  release: !0
1096
- }), await c.namespace.get("default", {
1132
+ }), await i.namespace.get("default", {
1097
1133
  timeout: o.timeout ?? 500,
1098
1134
  promise: !0,
1099
1135
  copy: !0,
@@ -1108,197 +1144,242 @@ class j {
1108
1144
  return typeof e > "u" ? e : JSON.parse(JSON.stringify(e));
1109
1145
  }
1110
1146
  }
1111
- class V {
1147
+ class R {
1112
1148
  /**
1113
1149
  * Creates standard bindings for workflow step execution
1114
1150
  */
1115
1151
  static createStandardBindings(e, t, n) {
1116
- const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), a = x(r) ? r.toNumber() : r;
1152
+ const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), s = L(r) ? r.toNumber() : r;
1117
1153
  return {
1118
- document: (c) => {
1119
- const i = e.get(c);
1120
- return x(i) ? i.toNumber() : P(i) ? o.nodeToJson(i, "original") : i;
1154
+ document: (i) => {
1155
+ const c = e.get(i);
1156
+ return L(c) ? c.toNumber() : S(c) ? o.nodeToJson(c, "original") : c;
1121
1157
  },
1122
- event: a,
1158
+ event: s,
1123
1159
  steps: n
1124
1160
  };
1125
1161
  }
1126
1162
  }
1127
- function X(s, e) {
1128
- const { op: t, path: n, val: o, from: r } = s;
1163
+ const rt = /^\$\{([\s\S]*)\}$/, st = /\$\{([\s\S]*?)\}/, T = (a) => typeof a != "string" ? !1 : rt.test(a), U = (a) => typeof a != "string" ? !1 : st.test(a), ce = (a) => {
1164
+ if (!T(a))
1165
+ throw new Error(`Invalid expression: ${a}`);
1166
+ return a.slice(2, -1);
1167
+ };
1168
+ class q {
1169
+ static createBindings(e, t, n) {
1170
+ return R.createStandardBindings(e, t, n);
1171
+ }
1172
+ static async evaluate(e, t, n, o) {
1173
+ const { coerceToString: r } = o;
1174
+ if (T(e)) {
1175
+ const s = ce(e), i = await A.evaluate({
1176
+ code: s,
1177
+ ctx: t,
1178
+ bindings: n
1179
+ });
1180
+ return r ? String(i ?? "") : i;
1181
+ }
1182
+ if (U(e)) {
1183
+ const i = `\`${String(e).replace(/`/g, "\\`")}\``, c = await A.evaluate({
1184
+ code: i,
1185
+ ctx: t,
1186
+ bindings: n
1187
+ });
1188
+ return String(c ?? "");
1189
+ }
1190
+ return r ? String(e) : e;
1191
+ }
1192
+ }
1193
+ function Z(a, e) {
1194
+ const { op: t, path: n, val: o, from: r } = a;
1129
1195
  if ((t === "move" || t === "copy") && !r)
1130
1196
  throw new Error(`${t} operation requires 'from' path`);
1131
1197
  if ((t === "add" || t === "replace") && o === void 0)
1132
1198
  throw new Error(`${t} operation requires 'val' property`);
1133
- const a = {
1199
+ const s = {
1134
1200
  type: "Document Update",
1135
1201
  op: t,
1136
1202
  path: n
1137
1203
  };
1138
- return o !== void 0 && (a.val = o), r !== void 0 && (a.from = r), e.jsonValueToNode(a);
1204
+ return o !== void 0 && (s.val = o), r !== void 0 && (s.from = r), e.jsonValueToNode(s);
1139
1205
  }
1140
- function nt(s) {
1141
- return s.jsonValueToNode({
1206
+ function at(a) {
1207
+ return a.jsonValueToNode({
1142
1208
  type: "Document Processing Initiated"
1143
1209
  });
1144
1210
  }
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 {
1211
+ class it {
1151
1212
  constructor() {
1152
1213
  l(this, "stepType", "Update Document");
1153
1214
  }
1154
1215
  supports(e) {
1155
- return b.isTypeOf(e, $);
1216
+ return P.isTypeOf(e, j);
1156
1217
  }
1157
1218
  async execute(e, t, n, o, r) {
1158
- const a = n.getBlue();
1159
- if (!b.isTypeOf(e, $)) return;
1160
- const c = await this.evaluateChangeset(
1219
+ const s = n.getBlue();
1220
+ if (!P.isTypeOf(e, j)) return;
1221
+ const i = await this.evaluateChangeset(
1161
1222
  e.get("/changeset"),
1162
1223
  n,
1163
1224
  t,
1164
1225
  r
1165
- ), i = G(e, {
1226
+ ), c = te(e, {
1166
1227
  op: "replace",
1167
1228
  path: "/changeset",
1168
- val: c
1169
- }), h = n.getBlue().nodeToSchemaOutput(i, $);
1170
- for (const u of h.changeset ?? []) {
1229
+ val: i
1230
+ }), d = n.getBlue().nodeToSchemaOutput(c, j);
1231
+ for (const u of d.changeset ?? []) {
1171
1232
  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,
1233
+ const h = await this.evaluateChangePath(
1234
+ u.path,
1235
+ n,
1236
+ t,
1237
+ r
1238
+ ), p = u.val;
1239
+ if ((u.op === "replace" || u.op === "add") && M(p)) {
1240
+ const m = await this.evaluateChangeValue(
1241
+ p,
1176
1242
  n,
1177
1243
  t,
1178
1244
  r
1179
1245
  );
1180
1246
  n.addPatch({
1181
1247
  op: u.op,
1182
- path: u.path,
1183
- val: p
1248
+ path: h,
1249
+ val: m
1184
1250
  }), n.emitEvent({
1185
- payload: X(
1251
+ payload: Z(
1186
1252
  {
1187
1253
  op: u.op,
1188
- path: n.resolvePath(u.path),
1189
- val: a.nodeToJson(p, "original")
1254
+ path: n.resolvePath(h),
1255
+ val: s.nodeToJson(m, "original")
1190
1256
  },
1191
- a
1192
- )
1257
+ s
1258
+ ),
1259
+ emissionType: "update"
1193
1260
  });
1194
1261
  }
1195
- u.op === "remove" && (n.addPatch({ op: u.op, path: u.path }), n.emitEvent({
1196
- payload: X(
1262
+ u.op === "remove" && (n.addPatch({ op: u.op, path: h }), n.emitEvent({
1263
+ payload: Z(
1197
1264
  {
1198
1265
  op: u.op,
1199
- path: n.resolvePath(u.path),
1266
+ path: n.resolvePath(h),
1200
1267
  val: null
1201
1268
  },
1202
- a
1203
- )
1269
+ s
1270
+ ),
1271
+ emissionType: "update"
1204
1272
  }));
1205
1273
  }
1206
1274
  }
1207
1275
  async evaluateChangeset(e, t, n, o) {
1208
1276
  const r = t.getBlue();
1209
- if (O(e)) {
1210
- const a = Y(e), c = await j.evaluate({
1211
- code: a,
1277
+ if (T(e)) {
1278
+ const s = ce(e), i = await A.evaluate({
1279
+ code: s,
1212
1280
  ctx: t,
1213
- bindings: V.createStandardBindings(
1281
+ bindings: R.createStandardBindings(
1214
1282
  t,
1215
1283
  n,
1216
1284
  o
1217
1285
  )
1218
1286
  });
1219
- return r.jsonValueToNode(c ?? null);
1287
+ return r.jsonValueToNode(i ?? null);
1220
1288
  }
1221
- if (P(e))
1289
+ if (S(e))
1222
1290
  return e;
1223
1291
  throw new Error("Invalid changeset: expected a string or document node");
1224
1292
  }
1225
1293
  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
- )
1294
+ const r = e.getValue(), s = t.getBlue();
1295
+ if (T(r) || typeof r == "string" && U(r)) {
1296
+ const i = q.createBindings(
1297
+ t,
1298
+ n,
1299
+ o
1300
+ ), c = await q.evaluate(
1301
+ String(r),
1302
+ t,
1303
+ i,
1304
+ { coerceToString: !T(r) }
1305
+ );
1306
+ return s.jsonValueToNode(c ?? null);
1307
+ }
1308
+ return e;
1309
+ }
1310
+ async evaluateChangePath(e, t, n, o) {
1311
+ const r = q.createBindings(t, n, o);
1312
+ if (T(e) || U(e)) {
1313
+ const s = await q.evaluate(e, t, r, {
1314
+ coerceToString: !0
1236
1315
  });
1237
- return a.jsonValueToNode(i ?? null);
1316
+ return String(s ?? "");
1238
1317
  }
1239
1318
  return e;
1240
1319
  }
1241
1320
  }
1242
- class at {
1321
+ class ct {
1243
1322
  constructor() {
1244
1323
  l(this, "stepType", "Trigger Event");
1245
1324
  }
1246
1325
  supports(e) {
1247
- return b.isTypeOf(e, q);
1326
+ return P.isTypeOf(e, x);
1248
1327
  }
1249
1328
  async execute(e, t, n) {
1250
1329
  const o = n.getBlue();
1251
- if (!b.isTypeOf(e, q)) return;
1252
- const r = o.nodeToSchemaOutput(e, q);
1330
+ if (!P.isTypeOf(e, x)) return;
1331
+ const r = o.nodeToSchemaOutput(e, x);
1253
1332
  r.event && n.emitEvent({
1254
- payload: r.event
1333
+ payload: r.event,
1334
+ emissionType: "triggered"
1255
1335
  });
1256
1336
  }
1257
1337
  }
1258
- class st {
1338
+ class lt {
1259
1339
  constructor() {
1260
1340
  l(this, "stepType", "JavaScript Code");
1261
1341
  }
1262
1342
  supports(e) {
1263
- return b.isTypeOf(e, A);
1343
+ return P.isTypeOf(e, V);
1264
1344
  }
1265
1345
  async execute(e, t, n, o, r) {
1266
- if (!b.isTypeOf(e, A)) return;
1267
- const a = n.getBlue(), c = a.nodeToSchemaOutput(
1346
+ if (!P.isTypeOf(e, V)) return;
1347
+ const s = n.getBlue(), i = s.nodeToSchemaOutput(
1268
1348
  e,
1269
- A
1349
+ V
1270
1350
  );
1271
- if (!c.code)
1351
+ if (!i.code)
1272
1352
  throw new Error("JavaScript code is required");
1273
- const i = await j.evaluate({
1274
- code: c.code,
1353
+ const c = await A.evaluate({
1354
+ code: i.code,
1275
1355
  ctx: n,
1276
- bindings: V.createStandardBindings(n, t, r),
1356
+ bindings: R.createStandardBindings(n, t, r),
1277
1357
  options: {
1278
1358
  isCodeBlock: !0,
1279
1359
  timeout: 500
1280
1360
  }
1281
1361
  });
1282
- if (i && typeof i == "object" && "events" in i) {
1283
- const h = i;
1284
- if (Array.isArray(h.events))
1285
- for (const u of h.events)
1362
+ if (c && typeof c == "object" && "events" in c) {
1363
+ const d = c;
1364
+ if (Array.isArray(d.events))
1365
+ for (const u of d.events)
1286
1366
  n.emitEvent({
1287
- payload: a.jsonValueToNode(u)
1367
+ payload: s.jsonValueToNode(u),
1368
+ emissionType: "triggered"
1288
1369
  });
1289
1370
  }
1290
- return i;
1371
+ return c;
1291
1372
  }
1292
1373
  }
1293
- const ct = [
1294
- new rt(),
1295
- new at(),
1296
- new st()
1374
+ const ut = [
1375
+ new it(),
1376
+ new ct(),
1377
+ new lt()
1297
1378
  ];
1298
- class ie {
1299
- constructor(e = ct) {
1379
+ class le {
1380
+ constructor(e = ut) {
1300
1381
  l(this, "contractType", "Sequential Workflow");
1301
- l(this, "contractBlueId", f["Sequential Workflow"]);
1382
+ l(this, "contractBlueId", g["Sequential Workflow"]);
1302
1383
  l(this, "role", "handler");
1303
1384
  l(this, "executors", []);
1304
1385
  this.executors = e;
@@ -1308,48 +1389,67 @@ class ie {
1308
1389
  this.executors.push(e);
1309
1390
  }
1310
1391
  supports(e, t, n) {
1311
- const a = n.getBlue().nodeToSchemaOutput(
1392
+ const r = n.getBlue().nodeToSchemaOutput(
1312
1393
  t,
1313
1394
  Se
1314
- ).channel;
1315
- return e.source === "channel" && e.channelName === a;
1395
+ ), s = this.isChannelNameMatch(e, r), i = this.isEventPatternMatch(e, t, n);
1396
+ return s && i;
1316
1397
  }
1317
1398
  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()) {
1321
- const u = this.executors.find((p) => p.supports(h));
1399
+ var i;
1400
+ const r = {}, s = (i = t.getProperties()) == null ? void 0 : i.steps.getItems();
1401
+ for (const [c, d] of (s ?? []).entries()) {
1402
+ const u = this.executors.find((p) => p.supports(d));
1322
1403
  if (!u)
1323
- throw new Error(`Unsupported workflow step type "${h.getType()}"`);
1324
- const d = await u.execute(
1325
- h,
1404
+ throw new Error(`Unsupported workflow step type "${d.getType()}"`);
1405
+ const h = await u.execute(
1406
+ d,
1326
1407
  e,
1327
1408
  n,
1328
1409
  o,
1329
1410
  r
1330
1411
  );
1331
- if (d !== void 0) {
1332
- const p = h.getName(), m = typeof p == "string" ? p : `Step${i + 1}`;
1333
- r[m] = d;
1412
+ if (h !== void 0) {
1413
+ const p = d.getName(), m = typeof p == "string" ? p : `Step${c + 1}`;
1414
+ r[m] = h;
1334
1415
  }
1335
1416
  await n.flush();
1336
1417
  }
1337
1418
  }
1419
+ isChannelNameMatch(e, t) {
1420
+ const n = t.channel;
1421
+ return M(n) && e.source === "channel" && e.channelName === n;
1422
+ }
1423
+ /**
1424
+ * Checks if the event matches the channel's event pattern (if specified)
1425
+ */
1426
+ isEventPatternMatch(e, t, n) {
1427
+ var r;
1428
+ const o = (r = t.getProperties()) == null ? void 0 : r.event;
1429
+ if (!o)
1430
+ return !0;
1431
+ try {
1432
+ const s = n.getBlue(), i = s.resolve(e.payload);
1433
+ return s.isTypeOfNode(i, o);
1434
+ } catch (s) {
1435
+ return console.warn("Error during event pattern matching:", s), !1;
1436
+ }
1437
+ }
1338
1438
  }
1339
- class it {
1439
+ class dt {
1340
1440
  constructor(e) {
1341
1441
  l(this, "contractType", "Sequential Workflow Operation");
1342
- l(this, "contractBlueId", f["Sequential Workflow Operation"]);
1442
+ l(this, "contractBlueId", g["Sequential Workflow Operation"]);
1343
1443
  l(this, "role", "handler");
1344
1444
  l(this, "sequentialWorkflowProcessor");
1345
- this.sequentialWorkflowProcessor = e || new ie();
1445
+ this.sequentialWorkflowProcessor = e || new le();
1346
1446
  }
1347
1447
  supports(e, t, n) {
1348
- const a = n.getBlue().nodeToSchemaOutput(
1448
+ const s = n.getBlue().nodeToSchemaOutput(
1349
1449
  t,
1350
1450
  Ce
1351
- ).operation, c = e.channelName;
1352
- return e.source === "channel" && M(c) && M(a) && c === a;
1451
+ ).operation, i = e.channelName;
1452
+ return e.source === "channel" && M(i) && M(s) && i === s;
1353
1453
  }
1354
1454
  async handle(e, t, n, o) {
1355
1455
  try {
@@ -1362,68 +1462,86 @@ class it {
1362
1462
  }
1363
1463
  }
1364
1464
  }
1365
- const Z = (s) => b.isTypeOf(s.payload, N);
1366
- class lt extends S {
1465
+ const ee = (a) => P.isTypeOf(a.payload, O);
1466
+ class ht extends C {
1367
1467
  constructor() {
1368
1468
  super(...arguments);
1369
1469
  l(this, "contractType", "Timeline Channel");
1370
- l(this, "contractBlueId", f["Timeline Channel"]);
1470
+ l(this, "contractBlueId", g["Timeline Channel"]);
1371
1471
  }
1372
1472
  supports(t, n, o) {
1373
1473
  var u;
1374
- if (!this.baseSupports(t) || !Z(t)) return !1;
1375
- const a = o.getBlue().nodeToSchemaOutput(
1474
+ if (!this.baseSupports(t) || !ee(t)) return !1;
1475
+ const s = o.getBlue().nodeToSchemaOutput(
1376
1476
  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;
1477
+ O
1478
+ ), i = o.getBlue().nodeToSchemaOutput(n, Ne), c = (u = s.timeline) == null ? void 0 : u.timelineId;
1479
+ return E(i.timelineId) && E(c) && c === i.timelineId;
1380
1480
  }
1381
1481
  handle(t, n, o, r) {
1382
- Z(t) && o.emitEvent({
1482
+ ee(t) && o.emitEvent({
1383
1483
  payload: t.payload,
1384
1484
  channelName: r,
1385
1485
  source: "channel"
1386
1486
  });
1387
1487
  }
1388
1488
  }
1389
- const ut = [
1390
- new tt(),
1489
+ class pt extends C {
1490
+ constructor() {
1491
+ super(...arguments);
1492
+ l(this, "contractType", "Triggered Event Channel");
1493
+ l(this, "contractBlueId", g["Triggered Event Channel"]);
1494
+ }
1495
+ supports(t) {
1496
+ return this.baseSupports(t) ? t.emissionType === "triggered" : !1;
1497
+ }
1498
+ handle(t, n, o, r) {
1499
+ o.emitEvent({
1500
+ payload: t.payload,
1501
+ channelName: r,
1502
+ source: "channel"
1503
+ });
1504
+ }
1505
+ }
1506
+ const mt = [
1507
+ new nt(),
1391
1508
  // channels
1392
- new Ke(),
1509
+ new Ge(),
1393
1510
  new Qe(),
1394
- new lt(),
1511
+ new ht(),
1395
1512
  new Ze(),
1396
- new Ge(),
1397
- new He(),
1398
- new Ye(),
1399
1513
  new et(),
1514
+ new Xe(),
1515
+ new Ye(),
1516
+ new pt(),
1517
+ new tt(),
1400
1518
  // sequential workflows
1401
- new ie(),
1402
- new it(),
1519
+ new le(),
1520
+ new dt(),
1403
1521
  // markers
1404
- new Xe()
1522
+ new Ke()
1405
1523
  ];
1406
- class gt {
1524
+ class Tt {
1407
1525
  /**
1408
1526
  * Creates a new document processor
1409
1527
  *
1410
1528
  * @param processors - Initial list of processors to register
1411
1529
  */
1412
- constructor(e, t = ut) {
1530
+ constructor(e, t = mt) {
1413
1531
  l(this, "taskCounter", 0);
1414
1532
  l(this, "eventCounter", 0);
1415
1533
  l(this, "registry");
1416
1534
  l(this, "queue");
1417
1535
  l(this, "router");
1418
- l(this, "checkpointCache", new Re());
1419
- this.blue = e, this.registry = new We(t), this.queue = new Ve(), this.router = new Fe(
1536
+ l(this, "checkpointCache", new Fe());
1537
+ this.blue = e, this.registry = new We(t), this.queue = new _e(), this.router = new Ue(
1420
1538
  this.blue,
1421
1539
  this.registry,
1422
1540
  this.queue,
1423
1541
  () => ++this.taskCounter,
1424
1542
  () => ++this.eventCounter
1425
1543
  ), this.register(
1426
- new Ue(this.checkpointCache),
1544
+ new He(this.checkpointCache),
1427
1545
  9999
1428
1546
  );
1429
1547
  }
@@ -1443,13 +1561,15 @@ class gt {
1443
1561
  * @returns Processing result with final state and emitted events
1444
1562
  */
1445
1563
  async initialize(e) {
1446
- let t = R(I(e), this.blue);
1564
+ let t = G(I(e), this.blue);
1447
1565
  const n = {
1448
- payload: nt(this.blue)
1566
+ payload: at(this.blue),
1567
+ source: "internal",
1568
+ emissionType: "lifecycle"
1449
1569
  }, o = [n.payload];
1450
1570
  await this.router.route(t, [], n, 0);
1451
1571
  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 };
1572
+ return t = r.state, o.push(...r.emitted), t = Re(t, this.blue), { state: $(t), emitted: o };
1453
1573
  }
1454
1574
  /**
1455
1575
  * Processes a batch of events against the document
@@ -1459,83 +1579,83 @@ class gt {
1459
1579
  * @returns Processing result with final state and emitted events
1460
1580
  */
1461
1581
  async processEvents(e, t) {
1462
- let n = R(I(e), this.blue);
1582
+ let n = G(I(e), this.blue);
1463
1583
  const o = [];
1464
- if (!se(n, this.blue))
1584
+ if (!ie(n, this.blue))
1465
1585
  throw new Error("Document is not initialized");
1466
1586
  for (const r of t)
1467
1587
  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));
1588
+ const s = { payload: r, source: "external" };
1589
+ await this.router.route(n, [], s, 0);
1590
+ const i = await this.drainQueue(n);
1591
+ n = i.state, o.push(...i.emitted);
1592
+ const c = this.checkpointCache.flush(n);
1593
+ c.length && (n = Q(n, c));
1474
1594
  } finally {
1475
1595
  this.checkpointCache.clear();
1476
1596
  }
1477
- return { state: B(n), emitted: o };
1597
+ return { state: $(n), emitted: o };
1478
1598
  }
1479
1599
  /**
1480
1600
  * Drains the task queue and applies all actions
1481
1601
  */
1482
1602
  async drainQueue(e) {
1483
- var a;
1603
+ var s;
1484
1604
  let t = e;
1485
1605
  const n = [], o = 1e4;
1486
1606
  let r = 0;
1487
1607
  for (; this.queue.length; ) {
1488
1608
  if (++r > o)
1489
1609
  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;
1610
+ const i = this.queue.pop(), { nodePath: c, contractName: d, contractNode: u, event: h } = i, p = t.get(c);
1611
+ if (!S(p) || !((s = p.getContracts()) != null && s[d]) || !u.getType()) continue;
1492
1612
  const m = this.registry.get(u.getType());
1493
1613
  if (!m) {
1494
- console.warn(`No processor registered for contract: ${h}`);
1614
+ console.warn(`No processor registered for contract: ${d}`);
1495
1615
  continue;
1496
1616
  }
1497
- const w = new oe(
1617
+ const w = new re(
1498
1618
  () => t,
1499
- c,
1619
+ i,
1500
1620
  this.blue,
1501
- async (T) => {
1502
- for (const y of T)
1503
- if (y.kind === "patch") {
1504
- const ue = W(
1621
+ async (v) => {
1622
+ for (const f of v)
1623
+ if (f.kind === "patch") {
1624
+ const D = z(
1505
1625
  t,
1506
1626
  this.blue
1507
1627
  );
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
1628
+ for (const N of D) {
1629
+ const de = f.patch.op === "move" || f.patch.op === "copy" ? [f.patch.from, f.patch.path] : [f.patch.path], H = w.getNodePath(), he = de.some(
1630
+ (me) => X(me, N.absPath)
1631
+ ), pe = X(
1632
+ H,
1633
+ N.absPath
1514
1634
  );
1515
- if (de && !pe)
1635
+ if (he && !pe)
1516
1636
  throw new ae(
1517
- y.patch,
1518
- C.absPath,
1519
- J
1637
+ f.patch,
1638
+ N.absPath,
1639
+ H
1520
1640
  );
1521
1641
  }
1522
1642
  try {
1523
- t = U(t, [y.patch]);
1524
- } catch (C) {
1525
- throw Le(h, d, C), C;
1643
+ t = Q(t, [f.patch]);
1644
+ } catch (N) {
1645
+ throw ze(d, h, N), N;
1526
1646
  }
1527
- } else y.kind === "event" && (n.push(y.event.payload), await this.router.route(t, [], y.event, c.key[5]));
1647
+ } else f.kind === "event" && (n.push(f.event.payload), await this.router.route(t, [], f.event, i.key[5]));
1528
1648
  }
1529
1649
  );
1530
- await m.handle(d, u, w, h), await w.flush();
1650
+ await m.handle(h, u, w, d), await w.flush();
1531
1651
  }
1532
1652
  return { state: t, emitted: n };
1533
1653
  }
1534
1654
  }
1535
- class le {
1655
+ class ue {
1536
1656
  process(e, t) {
1537
1657
  const n = t.getValue();
1538
- if (O(n)) {
1658
+ if (T(n)) {
1539
1659
  const o = t.clone();
1540
1660
  return o.setValue(n), o.setProperties(void 0), o.setItems(void 0), o.setType(void 0), o;
1541
1661
  }
@@ -1546,21 +1666,21 @@ class le {
1546
1666
  */
1547
1667
  postProcess(e, t) {
1548
1668
  const n = t.getValue();
1549
- if (O(n) && e.getValue() !== n && n !== void 0) {
1669
+ if (T(n) && e.getValue() !== n && n !== void 0) {
1550
1670
  const o = e.clone();
1551
1671
  return o.setValue(n), o;
1552
1672
  }
1553
1673
  return e;
1554
1674
  }
1555
1675
  }
1556
- const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1676
+ const bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1557
1677
  __proto__: null,
1558
- ExpressionPreserver: le
1678
+ ExpressionPreserver: ue
1559
1679
  }, Symbol.toStringTag, { value: "Module" }));
1560
- function wt() {
1680
+ function Pt() {
1561
1681
  return new k.SequentialMergingProcessor([
1562
1682
  new k.ValuePropagator(),
1563
- new le(),
1683
+ new ue(),
1564
1684
  new k.TypeAssigner(),
1565
1685
  new k.ListProcessor(),
1566
1686
  new k.DictionaryProcessor(),
@@ -1568,25 +1688,26 @@ function wt() {
1568
1688
  ]);
1569
1689
  }
1570
1690
  export {
1571
- gt as BlueDocumentProcessor,
1572
- Ue as ChannelEventCheckpointProcessor,
1573
- L as CodeBlockEvaluationError,
1574
- He as CompositeTimelineChannelProcessor,
1691
+ Tt as BlueDocumentProcessor,
1692
+ He as ChannelEventCheckpointProcessor,
1693
+ De as CodeBlockEvaluationError,
1694
+ Xe as CompositeTimelineChannelProcessor,
1575
1695
  Qe as DocumentUpdateChannelProcessor,
1576
1696
  ae as EmbeddedDocumentModificationError,
1577
- Ke as EmbeddedNodeChannelProcessor,
1578
- F as ExpressionEvaluationError,
1579
- Xe as InitializedMarkerProcessor,
1697
+ Ge as EmbeddedNodeChannelProcessor,
1698
+ Ae as ExpressionEvaluationError,
1699
+ Ke as InitializedMarkerProcessor,
1580
1700
  Ye as LifecycleEventChannelProcessor,
1581
- Et as MergingProcessors,
1582
- Ge as MyOSAgentChannelProcessor,
1701
+ bt as MergingProcessors,
1702
+ et as MyOSAgentChannelProcessor,
1583
1703
  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
1704
+ tt as OperationProcessor,
1705
+ se as PatchApplicationError,
1706
+ nt as ProcessEmbeddedProcessor,
1707
+ dt as SequentialWorkflowOperationProcessor,
1708
+ le as SequentialWorkflowProcessor,
1709
+ ht as TimelineChannelProcessor,
1710
+ pt as TriggeredEventChannelProcessor,
1711
+ z as collectEmbeddedPathSpecs,
1712
+ Pt as createDefaultMergingProcessor
1592
1713
  };