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