@blue-labs/document-processor 1.22.0 → 1.23.0

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