@blue-labs/document-processor 1.21.1 → 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 (103) 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 +5 -5
  5. package/dist/index.mjs +483 -533
  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 +1 -2
  11. package/dist/processors/ChannelEventCheckpointProcessor.d.ts.map +1 -1
  12. package/dist/processors/CompositeTimelineChannelProcessor.d.ts +1 -1
  13. package/dist/processors/CompositeTimelineChannelProcessor.d.ts.map +1 -1
  14. package/dist/processors/DocumentUpdateChannelProcessor.d.ts +1 -1
  15. package/dist/processors/DocumentUpdateChannelProcessor.d.ts.map +1 -1
  16. package/dist/processors/EmbeddedNodeChannelProcessor.d.ts +1 -1
  17. package/dist/processors/EmbeddedNodeChannelProcessor.d.ts.map +1 -1
  18. package/dist/processors/InitializedMarkerProcessor.d.ts +9 -0
  19. package/dist/processors/InitializedMarkerProcessor.d.ts.map +1 -0
  20. package/dist/processors/LifecycleEventChannelProcessor.d.ts +33 -0
  21. package/dist/processors/LifecycleEventChannelProcessor.d.ts.map +1 -0
  22. package/dist/processors/MyOSAgentChannelProcessor.d.ts +1 -1
  23. package/dist/processors/MyOSAgentChannelProcessor.d.ts.map +1 -1
  24. package/dist/processors/MyOSTimelineChannelProcessor.d.ts +1 -1
  25. package/dist/processors/MyOSTimelineChannelProcessor.d.ts.map +1 -1
  26. package/dist/processors/OperationProcessor.d.ts +1 -2
  27. package/dist/processors/OperationProcessor.d.ts.map +1 -1
  28. package/dist/processors/ProcessEmbeddedProcessor.d.ts +1 -2
  29. package/dist/processors/ProcessEmbeddedProcessor.d.ts.map +1 -1
  30. package/dist/processors/SequentialWorkflowOperationProcessor.d.ts +1 -1
  31. package/dist/processors/SequentialWorkflowOperationProcessor.d.ts.map +1 -1
  32. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts +1 -2
  33. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts.map +1 -1
  34. package/dist/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts.map +1 -1
  35. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts +2 -1
  36. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts.map +1 -1
  37. package/dist/processors/TimelineChannelProcessor.d.ts +1 -1
  38. package/dist/processors/TimelineChannelProcessor.d.ts.map +1 -1
  39. package/dist/processors/index.d.ts +2 -0
  40. package/dist/processors/index.d.ts.map +1 -1
  41. package/dist/routing/EventRouter.d.ts.map +1 -1
  42. package/dist/types.d.ts +1 -2
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/utils/checkpoint.d.ts.map +1 -1
  45. package/dist/utils/eventFactories.d.ts +37 -0
  46. package/dist/utils/eventFactories.d.ts.map +1 -0
  47. package/dist/utils/initialized.d.ts +4 -0
  48. package/dist/utils/initialized.d.ts.map +1 -0
  49. package/package.json +5 -6
  50. package/dist/repo/core/blue-ids/index.d.ts +0 -21
  51. package/dist/repo/core/blue-ids/index.d.ts.map +0 -1
  52. package/dist/repo/core/index.d.ts +0 -199
  53. package/dist/repo/core/index.d.ts.map +0 -1
  54. package/dist/repo/core/schema/Channel.d.ts +0 -13
  55. package/dist/repo/core/schema/Channel.d.ts.map +0 -1
  56. package/dist/repo/core/schema/CompositeTimelineChannel.d.ts +0 -17
  57. package/dist/repo/core/schema/CompositeTimelineChannel.d.ts.map +0 -1
  58. package/dist/repo/core/schema/DocumentUpdateChannel.d.ts +0 -17
  59. package/dist/repo/core/schema/DocumentUpdateChannel.d.ts.map +0 -1
  60. package/dist/repo/core/schema/EmbeddedNodeChannel.d.ts +0 -17
  61. package/dist/repo/core/schema/EmbeddedNodeChannel.d.ts.map +0 -1
  62. package/dist/repo/core/schema/JavaScriptCode.d.ts +0 -10
  63. package/dist/repo/core/schema/JavaScriptCode.d.ts.map +0 -1
  64. package/dist/repo/core/schema/JsonPatchEntry.d.ts +0 -22
  65. package/dist/repo/core/schema/JsonPatchEntry.d.ts.map +0 -1
  66. package/dist/repo/core/schema/Operation.d.ts +0 -16
  67. package/dist/repo/core/schema/Operation.d.ts.map +0 -1
  68. package/dist/repo/core/schema/OperationRequest.d.ts +0 -29
  69. package/dist/repo/core/schema/OperationRequest.d.ts.map +0 -1
  70. package/dist/repo/core/schema/ProcessEmbedded.d.ts +0 -10
  71. package/dist/repo/core/schema/ProcessEmbedded.d.ts.map +0 -1
  72. package/dist/repo/core/schema/SequentialWorkflow.d.ts +0 -13
  73. package/dist/repo/core/schema/SequentialWorkflow.d.ts.map +0 -1
  74. package/dist/repo/core/schema/SequentialWorkflowOperation.d.ts +0 -15
  75. package/dist/repo/core/schema/SequentialWorkflowOperation.d.ts.map +0 -1
  76. package/dist/repo/core/schema/SequentialWorkflowStep.d.ts +0 -13
  77. package/dist/repo/core/schema/SequentialWorkflowStep.d.ts.map +0 -1
  78. package/dist/repo/core/schema/TimelineChannel.d.ts +0 -17
  79. package/dist/repo/core/schema/TimelineChannel.d.ts.map +0 -1
  80. package/dist/repo/core/schema/TimelineEntry.d.ts +0 -25
  81. package/dist/repo/core/schema/TimelineEntry.d.ts.map +0 -1
  82. package/dist/repo/core/schema/TriggerEvent.d.ts +0 -10
  83. package/dist/repo/core/schema/TriggerEvent.d.ts.map +0 -1
  84. package/dist/repo/core/schema/UpdateDocument.d.ts +0 -40
  85. package/dist/repo/core/schema/UpdateDocument.d.ts.map +0 -1
  86. package/dist/repo/core/schema/index.d.ts +0 -15
  87. package/dist/repo/core/schema/index.d.ts.map +0 -1
  88. package/dist/repo/myos/blue-ids/index.d.ts +0 -8
  89. package/dist/repo/myos/blue-ids/index.d.ts.map +0 -1
  90. package/dist/repo/myos/index.d.ts +0 -101
  91. package/dist/repo/myos/index.d.ts.map +0 -1
  92. package/dist/repo/myos/schema/MyOSAgent.d.ts +0 -10
  93. package/dist/repo/myos/schema/MyOSAgent.d.ts.map +0 -1
  94. package/dist/repo/myos/schema/MyOSAgentChannel.d.ts +0 -30
  95. package/dist/repo/myos/schema/MyOSAgentChannel.d.ts.map +0 -1
  96. package/dist/repo/myos/schema/MyOSAgentEvent.d.ts +0 -19
  97. package/dist/repo/myos/schema/MyOSAgentEvent.d.ts.map +0 -1
  98. package/dist/repo/myos/schema/MyOSTimelineChannel.d.ts +0 -24
  99. package/dist/repo/myos/schema/MyOSTimelineChannel.d.ts.map +0 -1
  100. package/dist/repo/myos/schema/MyOSTimelineEntry.d.ts +0 -32
  101. package/dist/repo/myos/schema/MyOSTimelineEntry.d.ts.map +0 -1
  102. package/dist/repo/myos/schema/index.d.ts +0 -6
  103. package/dist/repo/myos/schema/index.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,30 +1,31 @@
1
- var he = Object.defineProperty;
2
- var de = (i, e, t) => e in i ? he(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var l = (i, e, t) => de(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { z as u } from "zod";
5
- import { withTypeBlueId as m, blueNodeField as k, applyBlueNodePatch as pe, BlueNodeTypeSchema as P, BlueNode as me, isBigNumber as z } from "@blue-labs/language";
6
- import { deepFreeze as X, isNonNullable as D, deepContains as fe } from "@blue-labs/shared-utils";
7
- const ge = (i, 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) => ({
8
9
  on: (t, n) => ({ end: () => n(null) })
9
10
  });
10
- async function ye(i) {
11
+ async function Se(c) {
11
12
  return new Promise((e, t) => {
12
- ge().on("error", t).end();
13
+ Ce().on("error", t).end();
13
14
  });
14
15
  }
15
- const S = (...i) => i.map((e, t) => {
16
+ const T = (...c) => c.map((e, t) => {
16
17
  if (typeof e != "string") return "";
17
18
  if (t === 0 && e === "/") return "/";
18
19
  const n = t > 0 ? e.replace(/^\/+/, "") : e;
19
- return t < i.length - 1 ? n.replace(/\/+$/, "") : n;
20
+ return t < c.length - 1 ? n.replace(/\/+$/, "") : n;
20
21
  }).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
21
- class Y {
22
+ class G {
22
23
  constructor(e, t, n, o) {
23
24
  l(this, "actions", []);
24
25
  this.getDocument = e, this.taskInfo = t, this.blue = n, this.onFlush = o;
25
26
  }
26
27
  get(e) {
27
- const t = this.getDocument(), n = S(this.taskInfo.nodePath, e);
28
+ const t = this.getDocument(), n = T(this.taskInfo.nodePath, e);
28
29
  return t.get(n);
29
30
  }
30
31
  addPatch(e) {
@@ -32,7 +33,7 @@ class Y {
32
33
  kind: "patch",
33
34
  patch: {
34
35
  ...e,
35
- path: S(this.taskInfo.nodePath, e.path)
36
+ path: T(this.taskInfo.nodePath, e.path)
36
37
  }
37
38
  });
38
39
  }
@@ -55,7 +56,7 @@ class Y {
55
56
  return this.taskInfo.nodePath;
56
57
  }
57
58
  resolvePath(e) {
58
- return S(this.taskInfo.nodePath, e);
59
+ return T(this.taskInfo.nodePath, e);
59
60
  }
60
61
  getTaskInfo() {
61
62
  return this.taskInfo;
@@ -67,188 +68,74 @@ class Y {
67
68
  loadExternalModule(e) {
68
69
  if (!/^https?:\/\//.test(e))
69
70
  throw new Error("Only http/https URLs are allowed");
70
- return ye();
71
+ return Se();
71
72
  }
72
73
  loadBlueContent(e) {
73
74
  throw new Error("Not implemented");
74
75
  }
75
76
  }
76
- class G extends Error {
77
+ class ee extends Error {
77
78
  constructor(e, t) {
78
79
  super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
79
80
  }
80
81
  }
81
- class ee extends Error {
82
+ class te extends Error {
82
83
  constructor(e, t, n) {
83
84
  super(
84
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}")`
85
86
  ), this.patch = e, this.offendingPath = t, this.contractNodePath = n, this.name = "EmbeddedDocumentModificationError";
86
87
  }
87
88
  }
88
- class W extends Error {
89
+ class V extends Error {
89
90
  constructor(e, t) {
90
91
  super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
91
92
  }
92
93
  }
93
- class Q extends Error {
94
+ class L extends Error {
94
95
  constructor(e, t) {
95
96
  super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
96
97
  }
97
98
  }
98
- const p = {
99
- Channel: "2RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc",
100
- "Timeline Channel": "RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2",
101
- "Composite Timeline Channel": "qxkh3uMkKoutP5DxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
102
- "Sequential Workflow": "h3uDxZ7dr6Eo27B7fuxMkKoutP5qxkQCS1VAptiCPc2R",
103
- "Process Embedded": "DxZ7dr6EoMkKoutP5qxkh3u27B7fuxQCS1VAptiCPc2R",
104
- "Embedded Node Channel": "MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2",
105
- "Document Update Channel": "MkKoutP5qxkh3uDQCS1VAptiCPc2xZ7dr6Eo27B7fux",
106
- "Channel Event Checkpoint": "o27B7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R",
107
- "Update Document": "7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R",
108
- "Trigger Event": "kQCS1VAp7fuxMkKoutPh3uDxZ7dr6E5qxtiCPc2R",
109
- "Json Patch Entry": "EnUQeMiMa2wHFW3JbeSPvdgfpL6qZYCR29m3SfeHsKSY",
110
- "JavaScript Code": "MkKoutPDxZ7dr6Eo5qxkh3u27B7fuxQCS1VAptiCPc2R",
111
- "Timeline Entry": "uDxZ7dr6Eo27B7fMkKoutP5qxkh3uxQCS1VAptiCPc2R",
112
- Operation: "OpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
113
- "Sequential Workflow Operation": "SeqOpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC",
114
- "Operation Request": "OpReqKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC"
115
- }, N = m(p.Channel)(
116
- u.object({
117
- name: u.string().optional(),
118
- description: u.string().optional()
119
- })
120
- ), Ee = m(
121
- p["Composite Timeline Channel"]
122
- )(
123
- N.extend({
124
- channels: u.array(u.string()).optional()
125
- })
126
- ), Ce = m(
127
- p["Document Update Channel"]
128
- )(
129
- N.extend({
130
- path: u.string().optional()
131
- })
132
- ), K = m(
133
- p["Embedded Node Channel"]
134
- )(
135
- N.extend({
136
- path: u.string().optional()
137
- })
138
- ), M = m(p["JavaScript Code"])(
139
- u.object({
140
- code: u.string().optional()
141
- })
142
- ), we = m(p.Operation)(
143
- u.object({
144
- request: k().optional(),
145
- description: u.string().optional(),
146
- channel: u.string().optional()
147
- })
148
- ), ve = m(
149
- p["Operation Request"]
150
- )(
151
- u.object({
152
- operation: u.string().optional(),
153
- request: k(),
154
- document: u.object({
155
- blueId: u.string().optional()
156
- }).optional(),
157
- allowNewerVersion: u.boolean().optional()
158
- })
159
- ), $ = m(
160
- p["Process Embedded"]
161
- )(
162
- u.object({
163
- paths: u.array(u.string()).optional()
164
- })
165
- ), j = m(
166
- p["Sequential Workflow"]
167
- )(
168
- u.object({
169
- steps: u.array(k()).optional(),
170
- channel: u.string().optional()
171
- })
172
- ), Se = m(
173
- p["Sequential Workflow Operation"]
174
- )(
175
- j.omit({
176
- channel: !0
177
- }).extend({
178
- operation: u.string().optional()
179
- })
180
- ), te = m(
181
- p["Timeline Channel"]
182
- )(
183
- N.extend({
184
- timelineId: u.string().optional()
185
- })
186
- ), I = m(p["Timeline Entry"])(
187
- u.object({
188
- timelineId: u.string().optional(),
189
- timelinePrev: u.string().optional(),
190
- thread: u.string().optional(),
191
- threadPrev: u.string().optional(),
192
- message: k().optional(),
193
- signature: u.string().optional()
194
- })
195
- ), q = m(p["Trigger Event"])(
196
- u.object({
197
- event: k()
198
- })
199
- ), Pe = m(p["Json Patch Entry"])(
200
- u.object({
201
- name: u.string().optional(),
202
- description: u.string().optional(),
203
- val: k().optional(),
204
- op: u.string().optional(),
205
- path: u.string().optional()
206
- })
207
- ), A = m(p["Update Document"])(
208
- u.object({
209
- changeset: u.array(Pe)
210
- })
211
- );
212
- function V(i, e, t = "/", n = []) {
213
- const o = i.getContracts() ?? {};
99
+ function j(c, e, t = "/", n = []) {
100
+ const o = c.getContracts() ?? {};
214
101
  for (const [a, r] of Object.entries(o))
215
- if (P.isTypeOf(
102
+ if (E.isTypeOf(
216
103
  r,
217
104
  $
218
105
  )) {
219
- const h = e.nodeToSchemaOutput(
106
+ const u = e.nodeToSchemaOutput(
220
107
  r,
221
108
  $
222
109
  ).paths ?? [];
223
- for (const d of h)
110
+ for (const h of u)
224
111
  n.push({
225
- absPath: S(t, d),
226
- contractPath: S(t, `contracts/${a}`)
112
+ absPath: T(t, h),
113
+ contractPath: T(t, `contracts/${a}`)
227
114
  });
228
115
  }
229
- for (const [a, r] of Object.entries(i.getProperties() ?? {}))
230
- V(r, e, S(t, a), n);
116
+ for (const [a, r] of Object.entries(c.getProperties() ?? {}))
117
+ j(r, e, T(t, a), n);
231
118
  return n;
232
119
  }
233
- function F(i, e) {
234
- return i === e || i.startsWith(e.endsWith("/") ? e : e + "/");
120
+ function F(c, e) {
121
+ return c === e || c.startsWith(e.endsWith("/") ? e : e + "/");
235
122
  }
236
- function U(i, e) {
237
- if (!e.length) return i;
238
- let t = i.clone();
123
+ function J(c, e) {
124
+ if (!e.length) return c;
125
+ let t = c.clone();
239
126
  for (const n of e)
240
127
  try {
241
- t = pe(t, n, !0);
128
+ t = K(t, n, !0);
242
129
  } catch (o) {
243
- throw new G(n, o);
130
+ throw new ee(n, o);
244
131
  }
245
- return X(t);
132
+ return I(t);
246
133
  }
247
- function y(i) {
248
- return i != null;
134
+ function f(c) {
135
+ return c != null;
249
136
  }
250
- function x(i) {
251
- return i instanceof me;
137
+ function b(c) {
138
+ return c instanceof ve;
252
139
  }
253
140
  class ke {
254
141
  constructor(e = [], t = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
@@ -289,28 +176,28 @@ class ke {
289
176
  t[e] = a;
290
177
  }
291
178
  }
292
- const be = (i, e, t, n, o, a) => [
293
- -i,
179
+ const Ie = (c, e, t, n, o, a) => [
180
+ -c,
294
181
  e,
295
182
  t,
296
183
  n,
297
184
  o,
298
185
  a
299
- ], Te = (i, e) => {
300
- for (let t = 0; t < i.key.length; t++) {
301
- const n = i.key[t], o = e.key[t];
186
+ ], Ne = (c, e) => {
187
+ for (let t = 0; t < c.key.length; t++) {
188
+ const n = c.key[t], o = e.key[t];
302
189
  if (n !== o)
303
190
  return typeof n == "number" && typeof o == "number" ? n - o : typeof n == "string" && typeof o == "string" ? n.localeCompare(o) : 0;
304
191
  }
305
192
  return 0;
306
193
  };
307
- class Oe {
194
+ class Be {
308
195
  /**
309
196
  * Creates a new task queue with the task key comparator
310
197
  */
311
198
  constructor() {
312
199
  l(this, "queue");
313
- this.queue = new ke([], Te);
200
+ this.queue = new ke([], Ne);
314
201
  }
315
202
  /**
316
203
  * Adds a task to the queue
@@ -335,7 +222,7 @@ class Oe {
335
222
  return this.queue.length;
336
223
  }
337
224
  }
338
- class Be {
225
+ class Oe {
339
226
  /**
340
227
  * Creates a new contract registry
341
228
  *
@@ -390,7 +277,7 @@ class Be {
390
277
  return this.processors.values();
391
278
  }
392
279
  }
393
- class xe {
280
+ class Me {
394
281
  constructor() {
395
282
  l(this, "isEnabled");
396
283
  this.isEnabled = process.env.TRACE_BLUE_ENABLED === "true";
@@ -457,8 +344,8 @@ class xe {
457
344
  return this.isEnabled;
458
345
  }
459
346
  }
460
- const Ne = 64;
461
- class Ie {
347
+ const $e = 64;
348
+ class qe {
462
349
  /**
463
350
  * Creates a new event router
464
351
  *
@@ -469,7 +356,7 @@ class Ie {
469
356
  */
470
357
  constructor(e, t, n, o, a) {
471
358
  l(this, "traceManager");
472
- this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = a, this.traceManager = new xe();
359
+ this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = a, this.traceManager = new Me();
473
360
  }
474
361
  /**
475
362
  * Routes an event to matching contracts in the document
@@ -481,19 +368,19 @@ class Ie {
481
368
  * @param inlineDepth - Current adapter recursion depth
482
369
  */
483
370
  async route(e, t, n, o, a = 0) {
484
- var c;
371
+ var i;
485
372
  if (n.seq === void 0 && (n.seq = this.getNextEventSeq()), t.length === 0) {
486
373
  if (n.dispatchPath) {
487
- const h = n.dispatchPath.split("/").filter(Boolean), d = { ...n };
488
- return delete d.dispatchPath, this.route(e, h, d, o, a);
374
+ const u = n.dispatchPath.split("/").filter(Boolean), h = { ...n };
375
+ return delete h.dispatchPath, this.route(e, u, h, o, a);
489
376
  }
490
377
  if (n.source === "channel" && n.originNodePath && n.originNodePath !== "/") {
491
- const h = ((c = n.originNodePath) == null ? void 0 : c.split("/").filter(Boolean)) ?? [];
492
- return this.route(e, h, n, o, a);
378
+ const u = ((i = n.originNodePath) == null ? void 0 : i.split("/").filter(Boolean)) ?? [];
379
+ return this.route(e, u, n, o, a);
493
380
  }
494
381
  }
495
- const r = S("/", t.join("/")), s = e.get(r);
496
- x(s) && await this.traverseContracts({
382
+ const r = T("/", t.join("/")), s = e.get(r);
383
+ b(s) && await this.traverseContracts({
497
384
  doc: e,
498
385
  node: s,
499
386
  nodePath: r,
@@ -514,42 +401,42 @@ class Ie {
514
401
  event: a,
515
402
  afterTaskId: r,
516
403
  pathSegments: s,
517
- inlineDepth: c
404
+ inlineDepth: i
518
405
  } = e;
519
406
  if (!this.shouldSkipForChannel(a, o))
520
- for (const [h, d] of Object.entries(
407
+ for (const [u, h] of Object.entries(
521
408
  n.getContracts() ?? {}
522
409
  )) {
523
- if (!d.getType()) continue;
524
- const f = this.registry.get(d.getType());
525
- if (!f) {
526
- console.warn(`No processor registered for contract: ${h}`);
410
+ if (!h.getType()) continue;
411
+ const d = this.registry.get(h.getType());
412
+ if (!d) {
413
+ console.warn(`No processor registered for contract: ${u}`);
527
414
  continue;
528
415
  }
529
- const C = {
416
+ const p = {
530
417
  nodePath: o,
531
- contractName: h,
532
- contractNode: d,
418
+ contractName: u,
419
+ contractNode: h,
533
420
  event: a
534
- }, g = new Y(() => t, C, this.blue);
535
- if (f.supports(a, d, g, h))
536
- switch (f.role) {
421
+ }, m = new G(() => t, p, this.blue);
422
+ if (d.supports(a, h, m, u))
423
+ switch (d.role) {
537
424
  case "adapter":
538
425
  await this.processAdapter({
539
- cp: f,
426
+ cp: d,
540
427
  event: a,
541
- contractNode: d,
542
- ctx: g,
543
- contractName: h,
428
+ contractNode: h,
429
+ ctx: m,
430
+ contractName: u,
544
431
  doc: t,
545
432
  afterTaskId: r,
546
- inlineDepth: c
433
+ inlineDepth: i
547
434
  });
548
435
  break;
549
436
  case "handler":
550
437
  this.scheduleHandler({
551
- contractNode: d,
552
- contractName: h,
438
+ contractNode: h,
439
+ contractName: u,
553
440
  nodePath: o,
554
441
  event: a,
555
442
  depth: s.length,
@@ -563,7 +450,7 @@ class Ie {
563
450
  * Processes an adapter contract and routes any emitted events
564
451
  */
565
452
  async processAdapter(e) {
566
- var w;
453
+ var v;
567
454
  const {
568
455
  cp: t,
569
456
  event: n,
@@ -571,49 +458,49 @@ class Ie {
571
458
  ctx: a,
572
459
  contractName: r,
573
460
  doc: s,
574
- afterTaskId: c,
575
- inlineDepth: h
461
+ afterTaskId: i,
462
+ inlineDepth: u
576
463
  } = e;
577
- if (h >= Ne)
464
+ if (u >= $e)
578
465
  throw new Error("Adapter recursion limit reached");
579
- const d = this.traceManager.addHop(
466
+ const h = this.traceManager.addHop(
580
467
  n,
581
- ((w = a.getTaskInfo()) == null ? void 0 : w.nodePath) ?? "",
468
+ ((v = a.getTaskInfo()) == null ? void 0 : v.nodePath) ?? "",
582
469
  r
583
470
  );
584
- await t.handle(d, o, a, r);
585
- const f = await a.flush();
586
- if (f.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"))
587
474
  throw new Error(
588
475
  `Contract "${r}" (adapter) attempted to patch the document`
589
476
  );
590
- const g = f.filter((b) => b.kind === "event");
591
- for (const b of g)
592
- await this.route(s, [], b.event, c, h + 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);
593
480
  }
594
481
  /**
595
482
  * Schedules a handler contract for future execution
596
483
  */
597
484
  scheduleHandler(e) {
598
- const { contractNode: t, contractName: n, nodePath: o, event: a, depth: r, afterTaskId: s } = e, c = t.getType();
599
- if (!c) {
485
+ const { contractNode: t, contractName: n, nodePath: o, event: a, depth: r, afterTaskId: s } = e, i = t.getType();
486
+ if (!i) {
600
487
  console.warn(`Contract node type is not defined for: ${n}`);
601
488
  return;
602
489
  }
603
- const h = this.registry.orderOf(c), d = t.get("/order"), f = z(d) ? d.toNumber() : 0, C = this.getNextTaskId() + s, g = be(
490
+ const u = this.registry.orderOf(i), h = t.get("/order"), d = X(h) ? h.toNumber() : 0, p = this.getNextTaskId() + s, m = Ie(
604
491
  r,
605
492
  a.seq,
606
- h,
607
- f,
493
+ u,
494
+ d,
608
495
  n,
609
- C
610
- ), w = this.traceManager.addHop(a, o, n);
496
+ p
497
+ ), v = this.traceManager.addHop(a, o, n);
611
498
  this.queue.push({
612
- key: g,
499
+ key: m,
613
500
  nodePath: o,
614
501
  contractName: n,
615
502
  contractNode: t,
616
- event: w
503
+ event: v
617
504
  });
618
505
  }
619
506
  /**
@@ -623,39 +510,60 @@ class Ie {
623
510
  return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
624
511
  }
625
512
  }
626
- const Me = (i, e, t) => {
627
- (t instanceof G || t instanceof ee) && console.error(
628
- `[Blue] Failed to apply patches for contract "${i}" on event ${JSON.stringify(e)}`,
513
+ const Ae = (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)}`,
629
516
  t
630
517
  );
631
518
  };
632
- function J(i, e) {
633
- const t = i.clone(), n = (o) => {
634
- var r;
635
- if (!x(o)) return;
519
+ function _(c, e) {
520
+ const t = c.clone(), n = (o) => {
521
+ if (!b(o)) return;
636
522
  const a = o.getContracts();
637
- a && (!a.checkpoint || ((r = a.checkpoint.getType()) == null ? void 0 : r.getBlueId()) !== p["Channel Event Checkpoint"]) && o.addContract(
523
+ (!(a != null && a.checkpoint) || !E.isTypeOf(
524
+ a.checkpoint,
525
+ he
526
+ )) && o.addContract(
638
527
  "checkpoint",
639
528
  e.jsonValueToNode({
640
529
  type: {
641
530
  name: "Channel Event Checkpoint",
642
- blueId: p["Channel Event Checkpoint"]
531
+ blueId: g["Channel Event Checkpoint"]
643
532
  },
644
533
  lastEvents: {}
645
534
  })
646
535
  );
647
536
  };
648
537
  n(t);
649
- for (const { absPath: o } of V(t, e)) {
538
+ for (const { absPath: o } of j(t, e)) {
650
539
  const a = t.get(o);
651
- x(a) && n(a);
540
+ b(a) && n(a);
652
541
  }
653
- return X(t);
542
+ return I(t);
654
543
  }
655
- class qe {
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);
562
+ }
563
+ class je {
656
564
  constructor(e) {
657
565
  l(this, "contractType", "Channel Event Checkpoint");
658
- l(this, "contractBlueId", p["Channel Event Checkpoint"]);
566
+ l(this, "contractBlueId", g["Channel Event Checkpoint"]);
659
567
  l(this, "role", "handler");
660
568
  this.cache = e;
661
569
  }
@@ -669,12 +577,9 @@ class qe {
669
577
  const o = await n.getBlue().calculateBlueId(e.rootEvent.payload), a = n.getNodePath().replace(/\/contracts\/checkpoint$/, "");
670
578
  this.cache.record(a, e, o);
671
579
  }
672
- init() {
673
- return [];
674
- }
675
580
  }
676
- const Z = (i, e) => i.get(e) !== void 0;
677
- class Ae {
581
+ const z = (c, e) => c.get(e) !== void 0;
582
+ class We {
678
583
  constructor() {
679
584
  l(this, "firstSeen", /* @__PURE__ */ new Map());
680
585
  }
@@ -687,13 +592,13 @@ class Ae {
687
592
  const t = [];
688
593
  for (const { docBase: n, event: o, eventBlueId: a } of this.firstSeen.values()) {
689
594
  if (!o.channelName) continue;
690
- const r = S(
595
+ const r = T(
691
596
  n,
692
597
  "contracts/checkpoint/lastEvents",
693
598
  o.channelName
694
599
  ), s = `${r}/blueId`;
695
- Z(e, r) ? t.push({
696
- op: Z(e, s) ? "replace" : "add",
600
+ z(e, r) ? t.push({
601
+ op: z(e, s) ? "replace" : "add",
697
602
  path: s,
698
603
  val: a
699
604
  }) : t.push({
@@ -708,7 +613,7 @@ class Ae {
708
613
  this.firstSeen.clear();
709
614
  }
710
615
  }
711
- class B {
616
+ class C {
712
617
  constructor() {
713
618
  l(this, "role", "adapter");
714
619
  }
@@ -719,22 +624,15 @@ class B {
719
624
  baseSupports(e) {
720
625
  return e.source !== "channel";
721
626
  }
722
- /**
723
- * Base implementation that returns empty array
724
- * Can be overridden by derived classes if needed
725
- */
726
- init() {
727
- return [];
728
- }
729
627
  }
730
- class De extends B {
628
+ class xe extends C {
731
629
  constructor() {
732
630
  super(...arguments);
733
631
  l(this, "contractType", "Composite Timeline Channel");
734
- l(this, "contractBlueId", p["Composite Timeline Channel"]);
632
+ l(this, "contractBlueId", g["Composite Timeline Channel"]);
735
633
  }
736
634
  supports(t, n, o) {
737
- const a = o.getBlue().nodeToSchemaOutput(n, Ee);
635
+ const a = o.getBlue().nodeToSchemaOutput(n, de);
738
636
  return !a.channels || !t.channelName ? !1 : a.channels.includes(t.channelName);
739
637
  }
740
638
  handle(t, n, o, a) {
@@ -745,18 +643,18 @@ class De extends B {
745
643
  });
746
644
  }
747
645
  }
748
- class $e extends B {
646
+ class Ve extends C {
749
647
  constructor() {
750
648
  super(...arguments);
751
649
  l(this, "contractType", "Document Update Channel");
752
- l(this, "contractBlueId", p["Document Update Channel"]);
650
+ l(this, "contractBlueId", g["Document Update Channel"]);
753
651
  }
754
652
  supports(t, n, o, a) {
755
653
  if (!this.baseSupports(t)) return !1;
756
- const r = o.getBlue().nodeToSchemaOutput(n, Ce), s = t.payload.path;
654
+ const r = o.getBlue().nodeToSchemaOutput(n, pe), s = t.payload.path;
757
655
  if (!s || t.channelName === a) return !1;
758
- const c = r.path;
759
- return D(c) && s === o.resolvePath(c);
656
+ const i = r.path;
657
+ return N(i) && s === o.resolvePath(i);
760
658
  }
761
659
  handle(t, n, o, a) {
762
660
  const r = t.payload;
@@ -767,92 +665,114 @@ class $e extends B {
767
665
  });
768
666
  }
769
667
  }
770
- class je extends B {
668
+ class Le extends C {
771
669
  constructor() {
772
670
  super(...arguments);
773
671
  l(this, "contractType", "Embedded Node Channel");
774
- l(this, "contractBlueId", p["Embedded Node Channel"]);
672
+ l(this, "contractBlueId", g["Embedded Node Channel"]);
775
673
  }
776
674
  supports(t, n, o) {
777
675
  if (!this.baseSupports(t)) return !1;
778
- const a = o.getBlue().nodeToSchemaOutput(n, K);
779
- return y(t.originNodePath) && y(a.path) && t.originNodePath === o.resolvePath(a.path);
676
+ const a = o.getBlue().nodeToSchemaOutput(n, x);
677
+ return f(t.originNodePath) && f(a.path) && t.originNodePath === o.resolvePath(a.path);
780
678
  }
781
679
  handle(t, n, o, a) {
782
- const r = o.getBlue().nodeToSchemaOutput(n, K), { originNodePath: s, payload: c } = t;
783
- y(r.path) && s === o.resolvePath(r.path) && o.emitEvent({
784
- payload: c,
680
+ const r = o.getBlue().nodeToSchemaOutput(n, x), { originNodePath: s, payload: i } = t;
681
+ f(r.path) && s === o.resolvePath(r.path) && o.emitEvent({
682
+ payload: i,
785
683
  channelName: a,
786
684
  source: "channel"
787
685
  });
788
686
  }
789
687
  }
790
- const T = {
791
- "MyOS Timeline Channel": "MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
792
- "MyOS Timeline Entry": "uDxZ7dr6Eo2MkKoutP5qxkh3uxQCS1VAptiCPc2R7B7f",
793
- "MyOS Agent": "AgentBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V",
794
- "MyOS Agent Channel": "AgentCh4nn3lBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V",
795
- "MyOS Agent Event": "AgentEv3ntBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V"
796
- }, Ve = m(
797
- T["MyOS Timeline Channel"]
798
- )(
799
- te.extend({
800
- account: u.string().optional(),
801
- email: u.string().optional()
802
- })
803
- ), Re = m(
804
- T["MyOS Timeline Entry"]
805
- )(
806
- I.extend({
807
- account: u.string().optional(),
808
- email: u.string().optional()
809
- })
810
- ), We = m(T["MyOS Agent"])(
811
- u.object({
812
- agentId: u.string().optional()
813
- })
814
- ), Qe = m(
815
- T["MyOS Agent Channel"]
816
- )(
817
- N.extend({
818
- agent: We.optional(),
819
- event: k().optional()
820
- })
821
- ), Ke = m(T["MyOS Agent Event"])(
822
- u.object({
823
- agentId: u.string().optional(),
824
- id: u.number().optional(),
825
- timestamp: u.number().optional(),
826
- event: k().optional()
827
- })
828
- ), _ = (i) => i.payload.type === "Timeline Entry" || i.payload.type === "MyOS Timeline Entry";
829
- class Fe extends B {
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 {
830
749
  constructor() {
831
750
  super(...arguments);
832
751
  l(this, "contractType", "MyOS Timeline Channel");
833
- l(this, "contractBlueId", T["MyOS Timeline Channel"]);
752
+ l(this, "contractBlueId", Z["MyOS Timeline Channel"]);
834
753
  }
835
754
  supports(t, n, o) {
836
- if (!this.baseSupports(t) || !_(t)) return !1;
755
+ var m;
756
+ if (!this.baseSupports(t) || !U(t)) return !1;
837
757
  const a = o.getBlue(), r = a.jsonValueToNode(t.payload), s = a.nodeToSchemaOutput(
838
758
  r,
839
- Re
840
- ), c = o.getBlue().nodeToSchemaOutput(n, Ve), h = y(c.timelineId) && y(s.timelineId), d = y(c.account) && y(s.account), f = y(c.email) && y(s.email);
841
- return h && s.timelineId === c.timelineId || d && s.account === c.account || f && s.email === c.email;
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);
761
+ return h && u === i.timelineId || d && s.account === i.account || p && s.email === i.email;
842
762
  }
843
763
  handle(t, n, o, a) {
844
- _(t) && o.emitEvent({
764
+ U(t) && o.emitEvent({
845
765
  payload: t.payload,
846
766
  channelName: a,
847
767
  source: "channel"
848
768
  });
849
769
  }
850
770
  }
851
- class Ue extends B {
771
+ class Ue extends C {
852
772
  constructor() {
853
773
  super(...arguments);
854
774
  l(this, "contractType", "MyOS Agent Channel");
855
- l(this, "contractBlueId", T["MyOS Agent Channel"]);
775
+ l(this, "contractBlueId", Z["MyOS Agent Channel"]);
856
776
  }
857
777
  supports(t, n, o) {
858
778
  if (!this.baseSupports(t)) return !1;
@@ -881,12 +801,12 @@ class Ue extends B {
881
801
  parseEventAndChannel(t, n, o) {
882
802
  const a = o.getBlue(), r = a.jsonValueToNode(t.payload), s = a.nodeToSchemaOutput(
883
803
  r,
884
- Ke
885
- ), c = a.nodeToSchemaOutput(
804
+ Pe
805
+ ), i = a.nodeToSchemaOutput(
886
806
  n,
887
- Qe
807
+ be
888
808
  );
889
- return { myosAgentEvent: s, myosAgentChannel: c };
809
+ return { myosAgentEvent: s, myosAgentChannel: i };
890
810
  }
891
811
  /**
892
812
  * Checks if the agent IDs match between event and channel
@@ -897,7 +817,7 @@ class Ue extends B {
897
817
  isAgentMatch(t, n) {
898
818
  var r;
899
819
  const o = t.agentId, a = (r = n.agent) == null ? void 0 : r.agentId;
900
- return y(o) && y(a) && o === a;
820
+ return f(o) && f(a) && o === a;
901
821
  }
902
822
  /**
903
823
  * Checks if the event pattern matches the channel's event filter
@@ -920,22 +840,22 @@ class Ue extends B {
920
840
  if (!r)
921
841
  return !1;
922
842
  try {
923
- const s = o.getBlue(), c = s.nodeToJson(r), h = s.nodeToJson(a);
924
- return fe(c, h);
843
+ const s = o.getBlue(), i = s.nodeToJson(r), u = s.nodeToJson(a);
844
+ return Y(i, u);
925
845
  } catch (s) {
926
846
  return console.warn("Error during event pattern matching:", s), !1;
927
847
  }
928
848
  }
929
849
  }
930
- class Je {
850
+ class He {
931
851
  constructor() {
932
852
  l(this, "contractType", "Operation");
933
- l(this, "contractBlueId", p.Operation);
853
+ l(this, "contractBlueId", g.Operation);
934
854
  l(this, "role", "adapter");
935
855
  }
936
856
  supports(e, t, n, o) {
937
- const r = n.getBlue().nodeToSchemaOutput(t, we), s = this.parseEventPayload(e, n);
938
- return y(s == null ? void 0 : s.operation) && s.operation === o && e.source === "channel" && e.channelName === r.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;
939
859
  }
940
860
  async handle(e, t, n, o) {
941
861
  n.emitEvent({
@@ -944,30 +864,27 @@ class Je {
944
864
  source: "channel"
945
865
  });
946
866
  }
947
- init() {
948
- return [];
949
- }
950
867
  parseEventPayload(e, t) {
951
868
  const n = t.getBlue(), o = n.jsonValueToNode(e.payload);
952
- if (P.isTypeOf(o, I)) {
869
+ if (E.isTypeOf(o, q)) {
953
870
  const a = n.nodeToSchemaOutput(
954
871
  o,
955
- I
872
+ q
956
873
  );
957
874
  if (a.message)
958
875
  return n.nodeToSchemaOutput(
959
876
  a.message,
960
- ve
877
+ fe
961
878
  );
962
879
  }
963
880
  return null;
964
881
  }
965
882
  }
966
- class Ze {
883
+ class Re {
967
884
  constructor() {
968
885
  l(this, "contractType", "Process Embedded");
969
886
  l(this, "role", "adapter");
970
- l(this, "contractBlueId", p["Process Embedded"]);
887
+ l(this, "contractBlueId", g["Process Embedded"]);
971
888
  }
972
889
  supports(e) {
973
890
  return e.source !== "channel";
@@ -980,22 +897,19 @@ class Ze {
980
897
  dispatchPath: n.resolvePath(a)
981
898
  });
982
899
  }
983
- init() {
984
- return [];
985
- }
986
900
  }
987
901
  const ne = !process.env.SKIP_ISOLATED_VM;
988
- let v = null;
902
+ let w = null;
989
903
  if (ne)
990
904
  try {
991
- v = require("isolated-vm");
905
+ w = require("isolated-vm");
992
906
  } catch {
993
907
  console.warn("isolated-vm not available, using fallback evaluation method");
994
908
  }
995
- function L(i) {
996
- return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(i) || /\bexport\s+/.test(i);
909
+ function H(c) {
910
+ return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(c) || /\bexport\s+/.test(c);
997
911
  }
998
- class oe {
912
+ class A {
999
913
  /**
1000
914
  * Main evaluation method - chooses between secure and simple evaluation strategies
1001
915
  */
@@ -1005,14 +919,14 @@ class oe {
1005
919
  bindings: n = {},
1006
920
  options: o = {}
1007
921
  }) {
1008
- return !v || !ne ? 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);
1009
923
  }
1010
924
  /**
1011
925
  * Fallback evaluation using Node's Function constructor
1012
926
  * Used when isolated-vm is not available
1013
927
  */
1014
928
  static async evaluateSimple(e, t, n = {}) {
1015
- if (L(e))
929
+ if (H(e))
1016
930
  throw new Error(
1017
931
  "Static import/export syntax requires isolated-vm – start Node without SKIP_ISOLATED_VM."
1018
932
  );
@@ -1033,29 +947,29 @@ class oe {
1033
947
  `return ${e};`
1034
948
  )(...Object.values(t));
1035
949
  } catch (o) {
1036
- throw n.isCodeBlock ? new Q(e, o) : new W(e, o);
950
+ throw n.isCodeBlock ? new L(e, o) : new V(e, o);
1037
951
  }
1038
952
  }
1039
953
  /**
1040
954
  * Secure evaluation using isolated-vm with support for ES modules
1041
955
  */
1042
956
  static async evaluateSecure(e, t, n, o = {}) {
1043
- if (!v) throw new Error("isolated-vm not available");
1044
- const a = new v.Isolate({ memoryLimit: 32 }), r = await a.createContext(), s = r.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;
1045
959
  try {
1046
960
  await this.setupIsolateEnvironment(s, t);
1047
- const c = /* @__PURE__ */ new Map(), h = this.createModuleResolver(
961
+ const i = /* @__PURE__ */ new Map(), u = this.createModuleResolver(
1048
962
  a,
1049
963
  r,
1050
- c,
964
+ i,
1051
965
  n
1052
966
  );
1053
- return L(e) ? await this.evaluateESModule(
967
+ return H(e) ? await this.evaluateESModule(
1054
968
  a,
1055
969
  r,
1056
970
  e,
1057
971
  o,
1058
- h
972
+ u
1059
973
  ) : await this.evaluateSimpleScript(
1060
974
  a,
1061
975
  r,
@@ -1063,8 +977,8 @@ class oe {
1063
977
  t,
1064
978
  o
1065
979
  );
1066
- } catch (c) {
1067
- throw o.isCodeBlock ? new Q(e, c) : new W(e, c);
980
+ } catch (i) {
981
+ throw o.isCodeBlock ? new L(e, i) : new V(e, i);
1068
982
  } finally {
1069
983
  r.release(), a.dispose();
1070
984
  }
@@ -1073,16 +987,16 @@ class oe {
1073
987
  * Setup the isolated VM environment with necessary host functions and data
1074
988
  */
1075
989
  static async setupIsolateEnvironment(e, t) {
1076
- if (!v) throw new Error("isolated-vm not available");
1077
- const n = new v.Callback(
990
+ if (!w) throw new Error("isolated-vm not available");
991
+ const n = new w.Callback(
1078
992
  (...o) => console.log(...o)
1079
993
  );
1080
994
  await e.set("log", n);
1081
995
  for (const [o, a] of Object.entries(t))
1082
996
  typeof a == "function" ? await e.set(
1083
997
  o,
1084
- new v.Callback(a)
1085
- ) : await e.set(o, new v.ExternalCopy(a).copyInto());
998
+ new w.Callback(a)
999
+ ) : await e.set(o, new w.ExternalCopy(a).copyInto());
1086
1000
  }
1087
1001
  /**
1088
1002
  * Create module resolver function for handling imports
@@ -1096,11 +1010,11 @@ class oe {
1096
1010
  throw new Error(
1097
1011
  `ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${a})`
1098
1012
  );
1099
- const c = await s(r), h = await e.compileModule(c);
1100
- return n.set(a, h), await h.instantiate(
1013
+ const i = await s(r), u = await e.compileModule(i);
1014
+ return n.set(a, u), await u.instantiate(
1101
1015
  t,
1102
1016
  this.createModuleResolver(e, t, n, o)
1103
- ), h;
1017
+ ), u;
1104
1018
  }
1105
1019
  if (/^https?:\/\//.test(a)) {
1106
1020
  let r;
@@ -1123,8 +1037,8 @@ class oe {
1123
1037
  * Evaluate code as a simple script (no imports/exports)
1124
1038
  */
1125
1039
  static async evaluateSimpleScript(e, t, n, o, a) {
1126
- const r = Object.keys(o).join(", "), s = Object.keys(o).map((d) => d), c = `(async (${r}) => { ${a.isCodeBlock ? n : `return (${n});`} })(${s.join(", ")})`;
1127
- return await (await e.compileScript(c)).run(t, {
1040
+ const r = Object.keys(o).join(", "), s = Object.keys(o).map((h) => h), i = `(async (${r}) => { ${a.isCodeBlock ? n : `return (${n});`} })(${s.join(", ")})`;
1041
+ return await (await e.compileScript(i)).run(t, {
1128
1042
  timeout: a.timeout ?? 500,
1129
1043
  promise: !0,
1130
1044
  copy: !0,
@@ -1137,14 +1051,14 @@ class oe {
1137
1051
  static async evaluateESModule(e, t, n, o, a) {
1138
1052
  let r = n;
1139
1053
  if (o.isCodeBlock) {
1140
- const h = /^\s*(import\s.+?;|export\s.+?;)/gm, d = (n.match(h) || []).join(
1054
+ const u = /^\s*(import\s.+?;|export\s.+?;)/gm, h = (n.match(u) || []).join(
1141
1055
  `
1142
1056
  `
1143
- ), f = n.replace(h, "").trim();
1057
+ ), d = n.replace(u, "").trim();
1144
1058
  r = `
1145
- ${d}
1059
+ ${h}
1146
1060
  const run = function() {
1147
- ${f}
1061
+ ${d}
1148
1062
  };
1149
1063
  export default run();
1150
1064
  `;
@@ -1163,7 +1077,7 @@ class oe {
1163
1077
  });
1164
1078
  }
1165
1079
  }
1166
- class ae {
1080
+ class D {
1167
1081
  /**
1168
1082
  * Creates standard bindings for workflow step execution
1169
1083
  */
@@ -1172,83 +1086,126 @@ class ae {
1172
1086
  return {
1173
1087
  document: (a) => {
1174
1088
  const r = e.get(a);
1175
- return z(r) ? r.toNumber() : x(r) ? o.nodeToJson(r, "original") : r;
1089
+ return X(r) ? r.toNumber() : b(r) ? o.nodeToJson(r, "original") : r;
1176
1090
  },
1177
1091
  event: t.payload,
1178
1092
  steps: n
1179
1093
  };
1180
1094
  }
1181
1095
  }
1182
- class _e {
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 {
1183
1111
  constructor() {
1184
1112
  l(this, "stepType", "Update Document");
1185
1113
  }
1186
1114
  supports(e) {
1187
- return P.isTypeOf(e, A);
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");
1188
1178
  }
1189
1179
  async evaluateChangeValue(e, t, n, o) {
1190
- const a = e == null ? void 0 : e.getValue();
1180
+ const a = e.getValue(), r = t.getBlue();
1191
1181
  if (typeof a == "string" && a.startsWith("${") && a.endsWith("}")) {
1192
- const r = a.slice(2, -1);
1193
- return await oe.evaluate({
1194
- code: r,
1182
+ const s = a.slice(2, -1), i = await A.evaluate({
1183
+ code: s,
1195
1184
  ctx: t,
1196
- bindings: ae.createStandardBindings(
1185
+ bindings: D.createStandardBindings(
1197
1186
  t,
1198
1187
  n,
1199
1188
  o
1200
1189
  )
1201
1190
  });
1191
+ return r.jsonValueToNode(i ?? null);
1202
1192
  }
1203
1193
  return e;
1204
1194
  }
1205
- async execute(e, t, n, o, a) {
1206
- if (!P.isTypeOf(e, A)) return;
1207
- const r = n.getBlue().nodeToSchemaOutput(e, A);
1208
- for (const s of r.changeset ?? [])
1209
- if (s.path) {
1210
- if (s.op === "replace" || s.op === "add") {
1211
- const c = await this.evaluateChangeValue(
1212
- s.val,
1213
- n,
1214
- t,
1215
- a
1216
- );
1217
- n.addPatch({
1218
- op: s.op,
1219
- path: s.path,
1220
- val: c
1221
- }), n.emitEvent({
1222
- payload: {
1223
- type: "Document Update",
1224
- op: s.op,
1225
- path: n.resolvePath(s.path),
1226
- val: c
1227
- }
1228
- });
1229
- }
1230
- s.op === "remove" && (n.addPatch({ op: s.op, path: s.path }), n.emitEvent({
1231
- payload: {
1232
- type: "Document Update",
1233
- op: s.op,
1234
- path: n.resolvePath(s.path),
1235
- val: null
1236
- }
1237
- }));
1238
- }
1239
- }
1240
1195
  }
1241
- class Le {
1196
+ class Xe {
1242
1197
  constructor() {
1243
1198
  l(this, "stepType", "Trigger Event");
1244
1199
  }
1245
1200
  supports(e) {
1246
- return P.isTypeOf(e, q);
1201
+ return E.isTypeOf(e, O);
1247
1202
  }
1248
1203
  async execute(e, t, n) {
1249
1204
  const o = n.getBlue();
1250
- if (!P.isTypeOf(e, q)) return;
1251
- const a = o.nodeToSchemaOutput(e, q), r = o.nodeToJson(
1205
+ if (!E.isTypeOf(e, O)) return;
1206
+ const a = o.nodeToSchemaOutput(e, O);
1207
+ if (!a.event) return;
1208
+ const r = o.nodeToJson(
1252
1209
  a.event,
1253
1210
  "original"
1254
1211
  );
@@ -1257,50 +1214,50 @@ class Le {
1257
1214
  });
1258
1215
  }
1259
1216
  }
1260
- class He {
1217
+ class Ye {
1261
1218
  constructor() {
1262
1219
  l(this, "stepType", "JavaScript Code");
1263
1220
  }
1264
1221
  supports(e) {
1265
- return P.isTypeOf(e, M);
1222
+ return E.isTypeOf(e, M);
1266
1223
  }
1267
1224
  async execute(e, t, n, o, a) {
1268
- if (!P.isTypeOf(e, M)) return;
1225
+ if (!E.isTypeOf(e, M)) return;
1269
1226
  const s = n.getBlue().nodeToSchemaOutput(
1270
1227
  e,
1271
1228
  M
1272
1229
  );
1273
1230
  if (!s.code)
1274
1231
  throw new Error("JavaScript code is required");
1275
- const c = await oe.evaluate({
1232
+ const i = await A.evaluate({
1276
1233
  code: s.code,
1277
1234
  ctx: n,
1278
- bindings: ae.createStandardBindings(n, t, a),
1235
+ bindings: D.createStandardBindings(n, t, a),
1279
1236
  options: {
1280
1237
  isCodeBlock: !0,
1281
1238
  timeout: 500
1282
1239
  }
1283
1240
  });
1284
- if (c && typeof c == "object" && "events" in c) {
1285
- const h = c;
1286
- if (Array.isArray(h.events))
1287
- for (const d of h.events)
1241
+ if (i && typeof i == "object" && "events" in i) {
1242
+ const u = i;
1243
+ if (Array.isArray(u.events))
1244
+ for (const h of u.events)
1288
1245
  n.emitEvent({
1289
- payload: d
1246
+ payload: h
1290
1247
  });
1291
1248
  }
1292
- return c;
1249
+ return i;
1293
1250
  }
1294
1251
  }
1295
- const ze = [
1296
- new _e(),
1297
- new Le(),
1298
- new He()
1252
+ const Ze = [
1253
+ new Ke(),
1254
+ new Xe(),
1255
+ new Ye()
1299
1256
  ];
1300
- class re {
1301
- constructor(e = ze) {
1257
+ class oe {
1258
+ constructor(e = Ze) {
1302
1259
  l(this, "contractType", "Sequential Workflow");
1303
- l(this, "contractBlueId", p["Sequential Workflow"]);
1260
+ l(this, "contractBlueId", g["Sequential Workflow"]);
1304
1261
  l(this, "role", "handler");
1305
1262
  l(this, "executors", []);
1306
1263
  this.executors = e;
@@ -1312,51 +1269,46 @@ class re {
1312
1269
  supports(e, t, n) {
1313
1270
  const r = n.getBlue().nodeToSchemaOutput(
1314
1271
  t,
1315
- j
1272
+ ye
1316
1273
  ).channel;
1317
1274
  return e.source === "channel" && e.channelName === r;
1318
1275
  }
1319
1276
  async handle(e, t, n, o) {
1320
- const r = n.getBlue().nodeToSchemaOutput(
1321
- t,
1322
- j
1323
- ), s = {}, c = r.steps;
1324
- for (const [h, d] of (c ?? []).entries()) {
1325
- const f = this.executors.find((g) => g.supports(d));
1326
- if (!f)
1327
- throw new Error(`Unsupported workflow step type "${d.getType()}"`);
1328
- const C = await f.execute(
1329
- d,
1277
+ var s;
1278
+ const a = {}, r = (s = t.getProperties()) == null ? void 0 : s.steps.getItems();
1279
+ for (const [i, u] of (r ?? []).entries()) {
1280
+ const h = this.executors.find((p) => p.supports(u));
1281
+ if (!h)
1282
+ throw new Error(`Unsupported workflow step type "${u.getType()}"`);
1283
+ const d = await h.execute(
1284
+ u,
1330
1285
  e,
1331
1286
  n,
1332
1287
  o,
1333
- s
1288
+ a
1334
1289
  );
1335
- if (C !== void 0) {
1336
- const g = d.getName(), w = typeof g == "string" ? g : `Step${h + 1}`;
1337
- s[w] = C;
1290
+ if (d !== void 0) {
1291
+ const p = u.getName(), m = typeof p == "string" ? p : `Step${i + 1}`;
1292
+ a[m] = d;
1338
1293
  }
1339
1294
  await n.flush();
1340
1295
  }
1341
1296
  }
1342
- init() {
1343
- return [];
1344
- }
1345
1297
  }
1346
- class Xe {
1298
+ class Ge {
1347
1299
  constructor(e) {
1348
1300
  l(this, "contractType", "Sequential Workflow Operation");
1349
- l(this, "contractBlueId", p["Sequential Workflow Operation"]);
1301
+ l(this, "contractBlueId", g["Sequential Workflow Operation"]);
1350
1302
  l(this, "role", "handler");
1351
1303
  l(this, "sequentialWorkflowProcessor");
1352
- this.sequentialWorkflowProcessor = e || new re();
1304
+ this.sequentialWorkflowProcessor = e || new oe();
1353
1305
  }
1354
1306
  supports(e, t, n) {
1355
1307
  const r = n.getBlue().nodeToSchemaOutput(
1356
1308
  t,
1357
- Se
1309
+ ge
1358
1310
  ).operation, s = e.channelName;
1359
- return e.source === "channel" && D(s) && D(r) && s === r;
1311
+ return e.source === "channel" && N(s) && N(r) && s === r;
1360
1312
  }
1361
1313
  async handle(e, t, n, o) {
1362
1314
  try {
@@ -1369,66 +1321,73 @@ class Xe {
1369
1321
  }
1370
1322
  }
1371
1323
  }
1372
- const H = (i) => i.payload.type === "Timeline Entry";
1373
- class Ye extends B {
1324
+ const Q = (c) => c.payload.type === "Timeline Entry";
1325
+ class et extends C {
1374
1326
  constructor() {
1375
1327
  super(...arguments);
1376
1328
  l(this, "contractType", "Timeline Channel");
1377
- l(this, "contractBlueId", p["Timeline Channel"]);
1329
+ l(this, "contractBlueId", g["Timeline Channel"]);
1378
1330
  }
1379
1331
  supports(t, n, o) {
1380
- if (!this.baseSupports(t) || !H(t)) return !1;
1381
- const a = o.getBlue(), r = a.jsonValueToNode(t.payload), s = a.nodeToSchemaOutput(
1382
- r,
1383
- I
1384
- ), c = o.getBlue().nodeToSchemaOutput(n, te);
1385
- return y(c.timelineId) && y(s.timelineId) && s.timelineId === c.timelineId;
1332
+ var h;
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;
1338
+ return f(s.timelineId) && f(i) && i === s.timelineId;
1386
1339
  }
1387
1340
  handle(t, n, o, a) {
1388
- H(t) && o.emitEvent({
1341
+ Q(t) && o.emitEvent({
1389
1342
  payload: t.payload,
1390
1343
  channelName: a,
1391
1344
  source: "channel"
1392
1345
  });
1393
1346
  }
1394
1347
  }
1395
- const Ge = [
1396
- new Ze(),
1348
+ const tt = [
1349
+ new Re(),
1397
1350
  // channels
1398
- new je(),
1399
- new $e(),
1400
- new Ye(),
1401
- new Fe(),
1351
+ new Le(),
1352
+ new Ve(),
1353
+ new et(),
1354
+ new ze(),
1402
1355
  new Ue(),
1403
- new De(),
1404
- new Je(),
1356
+ new xe(),
1357
+ new _e(),
1358
+ new He(),
1405
1359
  // sequential workflows
1406
- new re(),
1407
- new Xe()
1360
+ new oe(),
1361
+ new Ge(),
1362
+ // markers
1363
+ new Fe()
1408
1364
  ];
1409
- class rt {
1365
+ class it {
1410
1366
  /**
1411
1367
  * Creates a new document processor
1412
1368
  *
1413
1369
  * @param processors - Initial list of processors to register
1414
1370
  */
1415
- constructor(e, t = Ge) {
1371
+ constructor(e, t = tt) {
1416
1372
  l(this, "taskCounter", 0);
1417
1373
  l(this, "eventCounter", 0);
1418
1374
  l(this, "registry");
1419
1375
  l(this, "queue");
1420
1376
  l(this, "router");
1421
- l(this, "checkpointCache", new Ae());
1422
- this.blue = e, this.registry = new Be(t), this.queue = new Oe(), this.router = new Ie(
1377
+ l(this, "checkpointCache", new We());
1378
+ this.blue = e, this.registry = new Oe(t), this.queue = new Be(), this.router = new qe(
1423
1379
  this.blue,
1424
1380
  this.registry,
1425
1381
  this.queue,
1426
1382
  () => ++this.taskCounter,
1427
1383
  () => ++this.eventCounter
1428
1384
  ), this.register(
1429
- new qe(this.checkpointCache),
1385
+ new je(this.checkpointCache),
1430
1386
  9999
1431
- );
1387
+ ), this.blue.registerBlueIds({
1388
+ "Lifecycle Event Channel": k["Lifecycle Event Channel"],
1389
+ "Initialized Marker": k["Initialized Marker"]
1390
+ });
1432
1391
  }
1433
1392
  /**
1434
1393
  * Registers a new contract processor
@@ -1440,17 +1399,19 @@ class rt {
1440
1399
  this.registry.register(e, t);
1441
1400
  }
1442
1401
  /**
1443
- * Initializes a document and runs all init events
1402
+ * Initializes a document by emitting a Document Processing Initiated event
1444
1403
  *
1445
1404
  * @param document - The document to initialize
1446
1405
  * @returns Processing result with final state and emitted events
1447
1406
  */
1448
- async initialise(e) {
1449
- e = J(e, this.blue);
1450
- const t = await this.bootstrapContracts(e);
1451
- for (const n of t)
1452
- await this.router.route(e, [], n, 0);
1453
- 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 };
1454
1415
  }
1455
1416
  /**
1456
1417
  * Processes a batch of events against the document
@@ -1460,7 +1421,7 @@ class rt {
1460
1421
  * @returns Processing result with final state and emitted events
1461
1422
  */
1462
1423
  async processEvents(e, t) {
1463
- let n = J(e, this.blue);
1424
+ let n = _(e, this.blue);
1464
1425
  const o = [];
1465
1426
  for (const a of t)
1466
1427
  try {
@@ -1468,26 +1429,13 @@ class rt {
1468
1429
  await this.router.route(n, [], r, 0);
1469
1430
  const s = await this.drainQueue(n);
1470
1431
  n = s.state, o.push(...s.emitted);
1471
- const c = this.checkpointCache.flush(n);
1472
- c.length && (n = U(n, c));
1432
+ const i = this.checkpointCache.flush(n);
1433
+ i.length && (n = J(n, i));
1473
1434
  } finally {
1474
1435
  this.checkpointCache.clear();
1475
1436
  }
1476
1437
  return { state: n, emitted: o };
1477
1438
  }
1478
- /**
1479
- * Collects initialization events from contract processors
1480
- */
1481
- async bootstrapContracts(e) {
1482
- const t = [], n = e.getContracts();
1483
- if (!n)
1484
- return t;
1485
- for (const [, o] of Object.entries(n)) {
1486
- const a = this.registry.get(o.getType());
1487
- a != null && a.init && t.push(...await a.init(o));
1488
- }
1489
- return t;
1490
- }
1491
1439
  /**
1492
1440
  * Drains the task queue and applies all actions
1493
1441
  */
@@ -1499,59 +1447,61 @@ class rt {
1499
1447
  for (; this.queue.length; ) {
1500
1448
  if (++a > o)
1501
1449
  throw new Error("Possible cycle – too many iterations");
1502
- const s = this.queue.pop(), { nodePath: c, contractName: h, contractNode: d, event: f } = s, C = t.get(c);
1503
- if (!x(C) || !((r = C.getContracts()) != null && r[h]) || !d.getType()) continue;
1504
- const g = this.registry.get(d.getType());
1505
- if (!g) {
1506
- console.warn(`No processor registered for contract: ${h}`);
1450
+ const s = this.queue.pop(), { nodePath: i, contractName: u, contractNode: h, event: d } = s, p = t.get(i);
1451
+ if (!b(p) || !((r = p.getContracts()) != null && r[u]) || !h.getType()) continue;
1452
+ const m = this.registry.get(h.getType());
1453
+ if (!m) {
1454
+ console.warn(`No processor registered for contract: ${u}`);
1507
1455
  continue;
1508
1456
  }
1509
- const w = new Y(
1457
+ const v = new G(
1510
1458
  () => t,
1511
1459
  s,
1512
1460
  this.blue,
1513
- async (b) => {
1514
- for (const E of b)
1515
- if (E.kind === "patch") {
1516
- const se = V(t, this.blue);
1517
- for (const O of se) {
1518
- const ie = E.patch.op === "move" || E.patch.op === "copy" ? [E.patch.from, E.patch.path] : [E.patch.path], R = w.getNodePath(), ce = ie.some(
1519
- (ue) => F(ue, O.absPath)
1520
- ), le = F(
1521
- R,
1522
- O.absPath
1461
+ async (P) => {
1462
+ for (const y of P)
1463
+ if (y.kind === "patch") {
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,
1470
+ S.absPath
1523
1471
  );
1524
- if (ce && !le)
1525
- throw new ee(
1526
- E.patch,
1527
- O.absPath,
1528
- R
1472
+ if (se && !ce)
1473
+ throw new te(
1474
+ y.patch,
1475
+ S.absPath,
1476
+ W
1529
1477
  );
1530
1478
  }
1531
1479
  try {
1532
- t = U(t, [E.patch]);
1533
- } catch (O) {
1534
- throw Me(h, f, O), O;
1480
+ t = J(t, [y.patch]);
1481
+ } catch (S) {
1482
+ throw Ae(u, d, S), S;
1535
1483
  }
1536
- } else E.kind === "event" && (n.push(E.event.payload), await this.router.route(t, [], E.event, s.key[5]));
1484
+ } else y.kind === "event" && (n.push(y.event.payload), await this.router.route(t, [], y.event, s.key[5]));
1537
1485
  }
1538
1486
  );
1539
- await g.handle(f, d, w, h), await w.flush();
1487
+ await m.handle(d, h, v, u), await v.flush();
1540
1488
  }
1541
1489
  return { state: t, emitted: n };
1542
1490
  }
1543
1491
  }
1544
1492
  export {
1545
- rt as BlueDocumentProcessor,
1546
- qe as ChannelEventCheckpointProcessor,
1547
- De as CompositeTimelineChannelProcessor,
1548
- $e as DocumentUpdateChannelProcessor,
1549
- je as EmbeddedNodeChannelProcessor,
1493
+ it as BlueDocumentProcessor,
1494
+ je as ChannelEventCheckpointProcessor,
1495
+ xe as CompositeTimelineChannelProcessor,
1496
+ Ve as DocumentUpdateChannelProcessor,
1497
+ Le as EmbeddedNodeChannelProcessor,
1498
+ Fe as InitializedMarkerProcessor,
1499
+ _e as LifecycleEventChannelProcessor,
1550
1500
  Ue as MyOSAgentChannelProcessor,
1551
- Fe as MyOSTimelineChannelProcessor,
1552
- Je as OperationProcessor,
1553
- Ze as ProcessEmbeddedProcessor,
1554
- Xe as SequentialWorkflowOperationProcessor,
1555
- re as SequentialWorkflowProcessor,
1556
- Ye as TimelineChannelProcessor
1501
+ ze as MyOSTimelineChannelProcessor,
1502
+ He as OperationProcessor,
1503
+ Re as ProcessEmbeddedProcessor,
1504
+ Ge as SequentialWorkflowOperationProcessor,
1505
+ oe as SequentialWorkflowProcessor,
1506
+ et as TimelineChannelProcessor
1557
1507
  };