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