@blue-labs/document-processor 2.0.0-rc.2 → 2.0.0-rc.21

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 (75) hide show
  1. package/dist/api/document-processor.d.ts.map +1 -1
  2. package/dist/constants/processor-contract-constants.d.ts +2 -2
  3. package/dist/constants/processor-contract-constants.d.ts.map +1 -1
  4. package/dist/engine/channel-runner.d.ts +5 -2
  5. package/dist/engine/channel-runner.d.ts.map +1 -1
  6. package/dist/engine/checkpoint-manager.d.ts.map +1 -1
  7. package/dist/engine/contract-bundle.d.ts.map +1 -1
  8. package/dist/engine/contract-loader.d.ts.map +1 -1
  9. package/dist/engine/external-event.d.ts +3 -0
  10. package/dist/engine/external-event.d.ts.map +1 -0
  11. package/dist/engine/processor-engine.d.ts +4 -1
  12. package/dist/engine/processor-engine.d.ts.map +1 -1
  13. package/dist/engine/processor-execution-context.d.ts.map +1 -1
  14. package/dist/engine/scope-executor.d.ts +1 -0
  15. package/dist/engine/scope-executor.d.ts.map +1 -1
  16. package/dist/index.js +1480 -1153
  17. package/dist/model/channels/document-update-channel.d.ts +4 -0
  18. package/dist/model/channels/document-update-channel.d.ts.map +1 -1
  19. package/dist/model/channels/embedded-node-channel.d.ts +4 -0
  20. package/dist/model/channels/embedded-node-channel.d.ts.map +1 -1
  21. package/dist/model/channels/lifecycle-channel.d.ts +4 -0
  22. package/dist/model/channels/lifecycle-channel.d.ts.map +1 -1
  23. package/dist/model/channels/myos-timeline-channel.d.ts +4 -0
  24. package/dist/model/channels/myos-timeline-channel.d.ts.map +1 -1
  25. package/dist/model/channels/timeline-channel.d.ts +4 -0
  26. package/dist/model/channels/timeline-channel.d.ts.map +1 -1
  27. package/dist/model/channels/triggered-event-channel.d.ts +4 -0
  28. package/dist/model/channels/triggered-event-channel.d.ts.map +1 -1
  29. package/dist/model/handlers/sequential-workflow-operation.d.ts +2 -2
  30. package/dist/model/handlers/sequential-workflow-operation.d.ts.map +1 -1
  31. package/dist/model/handlers/sequential-workflow.d.ts +2 -2
  32. package/dist/model/handlers/sequential-workflow.d.ts.map +1 -1
  33. package/dist/model/markers/document-anchors.d.ts +23 -0
  34. package/dist/model/markers/document-anchors.d.ts.map +1 -0
  35. package/dist/model/markers/document-links.d.ts +23 -0
  36. package/dist/model/markers/document-links.d.ts.map +1 -0
  37. package/dist/model/markers/index.d.ts +5 -0
  38. package/dist/model/markers/index.d.ts.map +1 -1
  39. package/dist/model/markers/myos-participants-orchestration.d.ts +25 -0
  40. package/dist/model/markers/myos-participants-orchestration.d.ts.map +1 -0
  41. package/dist/model/markers/myos-session-interaction.d.ts +25 -0
  42. package/dist/model/markers/myos-session-interaction.d.ts.map +1 -0
  43. package/dist/model/markers/myos-worker-agency.d.ts +25 -0
  44. package/dist/model/markers/myos-worker-agency.d.ts.map +1 -0
  45. package/dist/model/shared/channel-contract-base.d.ts +3 -0
  46. package/dist/model/shared/channel-contract-base.d.ts.map +1 -1
  47. package/dist/model/shared/handler-contract-base.d.ts +2 -2
  48. package/dist/model/types.d.ts +2 -2
  49. package/dist/model/types.d.ts.map +1 -1
  50. package/dist/registry/processors/myos-timeline-channel-processor.d.ts +6 -1
  51. package/dist/registry/processors/myos-timeline-channel-processor.d.ts.map +1 -1
  52. package/dist/registry/processors/operation-marker-processor.d.ts.map +1 -1
  53. package/dist/registry/processors/sequential-workflow-operation-processor.d.ts +2 -2
  54. package/dist/registry/processors/sequential-workflow-operation-processor.d.ts.map +1 -1
  55. package/dist/registry/processors/sequential-workflow-processor.d.ts +2 -2
  56. package/dist/registry/processors/sequential-workflow-processor.d.ts.map +1 -1
  57. package/dist/registry/processors/shared/timeline-recency.d.ts +3 -0
  58. package/dist/registry/processors/shared/timeline-recency.d.ts.map +1 -0
  59. package/dist/registry/processors/steps/javascript-code-step-executor.d.ts +1 -1
  60. package/dist/registry/processors/steps/javascript-code-step-executor.d.ts.map +1 -1
  61. package/dist/registry/processors/steps/trigger-event-step-executor.d.ts.map +1 -1
  62. package/dist/registry/processors/steps/update-document-step-executor.d.ts.map +1 -1
  63. package/dist/registry/processors/timeline-channel-processor.d.ts +6 -1
  64. package/dist/registry/processors/timeline-channel-processor.d.ts.map +1 -1
  65. package/dist/registry/processors/utils/operation-utils.d.ts +1 -1
  66. package/dist/registry/processors/utils/operation-utils.d.ts.map +1 -1
  67. package/dist/registry/processors/workflow/operation-matcher.d.ts +2 -1
  68. package/dist/registry/processors/workflow/operation-matcher.d.ts.map +1 -1
  69. package/dist/registry/types.d.ts +5 -0
  70. package/dist/registry/types.d.ts.map +1 -1
  71. package/dist/test-support/blue.d.ts +16 -22
  72. package/dist/test-support/blue.d.ts.map +1 -1
  73. package/dist/util/expression/quickjs-expression-utils.d.ts +2 -0
  74. package/dist/util/expression/quickjs-expression-utils.d.ts.map +1 -1
  75. package/package.json +5 -7
package/dist/index.js CHANGED
@@ -1,42 +1,40 @@
1
- import { blueIds as p, ContractSchema as Xe, ChannelSchema as et, HandlerSchema as tt, MarkerSchema as nt, DocumentUpdateChannelSchema as rt, EmbeddedNodeChannelSchema as it, LifecycleEventChannelSchema as st, TriggeredEventChannelSchema as ot, ChannelEventCheckpointSchema as at, ProcessingInitializedMarkerSchema as ct, ProcessEmbeddedSchema as lt, ProcessingTerminatedMarkerSchema as ut, repository as dt } from "@blue-repository/core";
2
1
  import { getQuickJS as ht } from "quickjs-emscripten";
3
- import { BlueNode as d, blueNodeField as z, withTypeBlueId as ft, Blue as pt, MergingProcessors as R } from "@blue-labs/language";
4
- import de from "picomatch";
5
- import { z as S, ZodError as Te } from "zod";
6
- import { TimelineChannelSchema as mt, OperationSchema as x, SequentialWorkflowSchema as gt, SequentialWorkflowOperationSchema as Et, TimelineEntrySchema as k, blueIds as v, TriggerEventSchema as he, JavaScriptCodeSchema as fe, UpdateDocumentSchema as pe, OperationRequestSchema as ee, repository as yt } from "@blue-repository/conversation";
7
- import { MyOSTimelineChannelSchema as wt, blueIds as bt, MyOSTimelineEntrySchema as me, repository as St } from "@blue-repository/myos";
8
- import { isNullable as te } from "@blue-labs/shared-utils";
9
- function Ct(i) {
2
+ import { BlueNode as h, withTypeBlueId as f, blueNodeField as v, Properties as Ee, BlueIdCalculator as pt, Blue as ft, MergingProcessors as O } from "@blue-labs/language";
3
+ import we from "picomatch";
4
+ import { z as l, ZodError as xe } from "zod";
5
+ import { isNullable as ae } from "@blue-labs/shared-utils";
6
+ import { repository as mt } from "@blue-repository/types";
7
+ function gt(i) {
10
8
  return { ok: !0, value: i };
11
9
  }
12
- function kt(i) {
10
+ function yt(i) {
13
11
  return { ok: !1, error: i };
14
12
  }
15
- function jr(i) {
13
+ function Ci(i) {
16
14
  return i.ok;
17
15
  }
18
- function Jr(i) {
16
+ function Si(i) {
19
17
  return !i.ok;
20
18
  }
21
- function Qr(i, e) {
22
- return i.ok ? Ct(e(i.value)) : i;
19
+ function vi(i, e) {
20
+ return i.ok ? gt(e(i.value)) : i;
23
21
  }
24
- function Yr(i, e) {
25
- return i.ok ? i : kt(e(i.error));
22
+ function bi(i, e) {
23
+ return i.ok ? i : yt(e(i.error));
26
24
  }
27
- function Zr(i, e) {
25
+ function ki(i, e) {
28
26
  return i.ok ? e(i.value) : i;
29
27
  }
30
- function Xr(i, e) {
28
+ function Ti(i, e) {
31
29
  return i.ok ? i.value : e;
32
30
  }
33
- function ei(i, e) {
31
+ function Ii(i, e) {
34
32
  return i.ok ? i.value : e(i.error);
35
33
  }
36
- function ti(i, e) {
34
+ function Ri(i, e) {
37
35
  return i.ok ? e.ok(i.value) : e.err(i.error);
38
36
  }
39
- const g = {
37
+ const w = {
40
38
  capabilityFailure(i, e, t) {
41
39
  return { kind: "CapabilityFailure", capability: i, reason: e, details: t };
42
40
  },
@@ -56,14 +54,14 @@ const g = {
56
54
  return { kind: "UnsupportedOp", operation: i, reason: e };
57
55
  }
58
56
  };
59
- function It(i) {
57
+ function Et(i) {
60
58
  return Object.freeze([...i]);
61
59
  }
62
- const vt = {
60
+ const wt = {
63
61
  of(i, e, t) {
64
62
  return {
65
63
  document: i,
66
- triggeredEvents: It(e),
64
+ triggeredEvents: Et(e),
67
65
  totalGas: t,
68
66
  capabilityFailure: !1,
69
67
  failureReason: null
@@ -78,68 +76,85 @@ const vt = {
78
76
  failureReason: e ?? null
79
77
  };
80
78
  }
81
- }, Pe = vt, Rt = [
79
+ }, _e = wt, p = {
80
+ "Core/Channel": "DcoJyCh7XXxy1nR5xjy7qfkUgQ1GiZnKKSxh8DJusBSr",
81
+ "Core/Channel Event Checkpoint": "B7YQeYdQzUNuzaDQ4tNTd2iJqgd4YnVQkgz4QgymDWWU",
82
+ "Core/Contract": "AERp8BWnuUsjoPciAeNXuUWS9fmqPNMdWbxmKn3tcitx",
83
+ "Core/Document Processing Initiated": "BrpmpNt5JkapeUvPqYcxgXZrHNZX3R757dRwuXXdfNM2",
84
+ "Core/Document Processing Terminated": "5AJiAUgiSDwfCzv9rCYKNaAJu1hm8BXFu7eLNAEHNACr",
85
+ "Core/Document Update": "7htwgHAXA9FjUGRytXFfwYMUZz4R3BDMfmeHeGvpscLP",
86
+ "Core/Document Update Channel": "6H1iGrDAcqtFE1qv3iyMTj79jCZsMUMxsNUzqYSJNbyR",
87
+ "Core/Embedded Node Channel": "Fjbu3QpnUaTruDTcTidETCX2N5STyv7KYxT42PCzGHxm",
88
+ "Core/Handler": "9ZE5pGjtSGJgWJG7iAVz4iPEz5CatceX3yb3qp5MpAKJ",
89
+ "Core/Json Patch Entry": "Bz49DbfqKC1yJeCfv5RYPZUKTfb7rtZnmreCaz4RsXn5",
90
+ "Core/Lifecycle Event Channel": "H2aCCTUcLMTJozWkn7HPUjyFBFxamraw1q8DyWk87zxr",
91
+ "Core/Marker": "7QACj919YMRvFCTELCf6jfQTp41RVhtHdE6bPazLUZQ6",
92
+ "Core/Process Embedded": "Hu4XkfvyXLSdfFNUwuXebEu3oJeWcMyhBTcRV9AQyKPC",
93
+ "Core/Processing Initialized Marker": "EVguxFmq5iFtMZaBQgHfjWDojaoesQ1vEXCQFZ59yL28",
94
+ "Core/Processing Terminated Marker": "5NiEhupJ6uF54Q3vs4GwQX4UX4ExtwHpKRVvjKEHtvjR",
95
+ "Core/Triggered Event Channel": "C77W4kVGcxL7Mkx9WL9QESPEFFL2GzWAe647s1Efprt"
96
+ }, Ct = [
82
97
  "embedded",
83
98
  "initialized",
84
99
  "terminated",
85
100
  "checkpoint"
86
- ], Tt = [
87
- p["Document Update Channel"],
88
- p["Triggered Event Channel"],
89
- p["Lifecycle Event Channel"],
90
- p["Embedded Node Channel"]
91
- ], Ne = "embedded", Me = "initialized", Ae = "terminated", I = "checkpoint", ie = new Set(
92
- Rt
93
- ), Oe = new Set(Tt);
94
- function Pt(i) {
95
- return i != null && ie.has(i);
96
- }
97
- function se(i) {
98
- return i != null && Oe.has(
101
+ ], St = [
102
+ p["Core/Document Update Channel"],
103
+ p["Core/Triggered Event Channel"],
104
+ p["Core/Lifecycle Event Channel"],
105
+ p["Core/Embedded Node Channel"]
106
+ ], Fe = "embedded", Ue = "initialized", ze = "terminated", N = "checkpoint", de = new Set(
107
+ Ct
108
+ ), $e = new Set(St);
109
+ function vt(i) {
110
+ return i != null && de.has(i);
111
+ }
112
+ function he(i) {
113
+ return i != null && $e.has(
99
114
  i
100
115
  );
101
116
  }
102
- const ni = {
103
- KEY_EMBEDDED: Ne,
104
- KEY_INITIALIZED: Me,
105
- KEY_TERMINATED: Ae,
106
- KEY_CHECKPOINT: I,
107
- RESERVED_CONTRACT_KEYS: ie,
108
- PROCESSOR_MANAGED_CHANNEL_BLUE_IDS: Oe,
109
- isReservedContractKey: Pt,
110
- isProcessorManagedChannelBlueId: se
111
- }, A = "/contracts", ne = `${A}/${Me}`, De = `${A}/${Ae}`, Nt = `${A}/${Ne}`, Be = `${A}/${I}`, Le = "/lastEvents", _e = "/lastSignatures";
112
- function J(i) {
113
- return `${A}/${i}`;
114
- }
115
- function $e(i, e) {
116
- return `${J(i)}${Le}/${e}`;
117
- }
118
- function xe(i, e) {
119
- return `${J(i)}${_e}/${e}`;
120
- }
121
- const ri = {
122
- RELATIVE_CONTRACTS: A,
123
- RELATIVE_INITIALIZED: ne,
124
- RELATIVE_TERMINATED: De,
125
- RELATIVE_EMBEDDED: Nt,
126
- RELATIVE_CHECKPOINT: Be,
127
- LAST_EVENTS_SUFFIX: Le,
128
- LAST_SIGNATURES_SUFFIX: _e,
129
- relativeContractsEntry: J,
130
- relativeCheckpointLastEvent: $e,
131
- relativeCheckpointLastSignature: xe
117
+ const Pi = {
118
+ KEY_EMBEDDED: Fe,
119
+ KEY_INITIALIZED: Ue,
120
+ KEY_TERMINATED: ze,
121
+ KEY_CHECKPOINT: N,
122
+ RESERVED_CONTRACT_KEYS: de,
123
+ PROCESSOR_MANAGED_CHANNEL_BLUE_IDS: $e,
124
+ isReservedContractKey: vt,
125
+ isProcessorManagedChannelBlueId: he
126
+ }, x = "/contracts", ce = `${x}/${Ue}`, He = `${x}/${ze}`, bt = `${x}/${Fe}`, Ve = `${x}/${N}`, We = "/lastEvents", Ke = "/lastSignatures";
127
+ function Z(i) {
128
+ return `${x}/${i}`;
129
+ }
130
+ function qe(i, e) {
131
+ return `${Z(i)}${We}/${e}`;
132
+ }
133
+ function je(i, e) {
134
+ return `${Z(i)}${Ke}/${e}`;
135
+ }
136
+ const Mi = {
137
+ RELATIVE_CONTRACTS: x,
138
+ RELATIVE_INITIALIZED: ce,
139
+ RELATIVE_TERMINATED: He,
140
+ RELATIVE_EMBEDDED: bt,
141
+ RELATIVE_CHECKPOINT: Ve,
142
+ LAST_EVENTS_SUFFIX: We,
143
+ LAST_SIGNATURES_SUFFIX: Ke,
144
+ relativeContractsEntry: Z,
145
+ relativeCheckpointLastEvent: qe,
146
+ relativeCheckpointLastSignature: je
132
147
  };
133
- function Fe(i) {
148
+ function Je(i) {
134
149
  return i == null || i.length === 0;
135
150
  }
136
- function y(i) {
137
- return Fe(i) ? "/" : i.startsWith("/") ? i : `/${i}`;
151
+ function C(i) {
152
+ return Je(i) ? "/" : i.startsWith("/") ? i : `/${i}`;
138
153
  }
139
- function b(i) {
140
- return Fe(i) ? "/" : i.startsWith("/") ? i : `/${i}`;
154
+ function T(i) {
155
+ return Je(i) ? "/" : i.startsWith("/") ? i : `/${i}`;
141
156
  }
142
- function ge(i) {
157
+ function Ce(i) {
143
158
  if (i == null)
144
159
  return "";
145
160
  let e = i.trim();
@@ -151,16 +166,16 @@ function ge(i) {
151
166
  e = e.substring(0, e.length - 1);
152
167
  return e;
153
168
  }
154
- function ii(i, e) {
155
- const t = ge(i), n = ge(e);
169
+ function Ni(i, e) {
170
+ const t = Ce(i), n = Ce(e);
156
171
  return t.length === 0 && n.length === 0 ? "/" : t.length === 0 ? `/${n}` : n.length === 0 ? `/${t}` : `/${t}/${n}`;
157
172
  }
158
- function w(i, e) {
159
- const t = y(i), n = b(e);
173
+ function k(i, e) {
174
+ const t = C(i), n = T(e);
160
175
  return t === "/" ? n : n === "/" || n.length === 1 ? t : `${t}${n}`;
161
176
  }
162
- function Mt(i, e) {
163
- const t = y(i), n = b(e);
177
+ function kt(i, e) {
178
+ const t = C(i), n = T(e);
164
179
  if (t === "/" || !n.startsWith(t))
165
180
  return n;
166
181
  if (n.length === t.length)
@@ -168,87 +183,87 @@ function Mt(i, e) {
168
183
  const r = n.substring(t.length);
169
184
  return r.length === 0 ? "/" : r.startsWith("/") ? r : `/${r}`;
170
185
  }
171
- function At(i) {
186
+ function Tt(i) {
172
187
  return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
173
188
  }
174
- var Y, Ee;
175
- function Ot() {
176
- return Ee || (Ee = 1, Y = function i(e) {
189
+ var ie, Se;
190
+ function It() {
191
+ return Se || (Se = 1, ie = function i(e) {
177
192
  if (typeof e == "number" && isNaN(e))
178
193
  throw new Error("NaN is not allowed");
179
194
  if (typeof e == "number" && !isFinite(e))
180
195
  throw new Error("Infinity is not allowed");
181
- return e === null || typeof e != "object" ? JSON.stringify(e) : e.toJSON instanceof Function ? i(e.toJSON()) : Array.isArray(e) ? `[${e.reduce((r, s, o) => `${r}${o === 0 ? "" : ","}${i(s === void 0 || typeof s == "symbol" ? null : s)}`, "")}]` : `{${Object.keys(e).sort().reduce((n, r) => {
196
+ return e === null || typeof e != "object" ? JSON.stringify(e) : e.toJSON instanceof Function ? i(e.toJSON()) : Array.isArray(e) ? `[${e.reduce((r, o, s) => `${r}${s === 0 ? "" : ","}${i(o === void 0 || typeof o == "symbol" ? null : o)}`, "")}]` : `{${Object.keys(e).sort().reduce((n, r) => {
182
197
  if (e[r] === void 0 || typeof e[r] == "symbol")
183
198
  return n;
184
- const s = n.length === 0 ? "" : ",";
185
- return `${n}${s}${i(r)}:${i(e[r])}`;
199
+ const o = n.length === 0 ? "" : ",";
200
+ return `${n}${o}${i(r)}:${i(e[r])}`;
186
201
  }, "")}}`;
187
- }), Y;
202
+ }), ie;
188
203
  }
189
- var Dt = Ot();
190
- const Bt = /* @__PURE__ */ At(Dt);
191
- function Lt(i, e) {
204
+ var Rt = It();
205
+ const Pt = /* @__PURE__ */ Tt(Rt);
206
+ function Mt(i, e) {
192
207
  return i.nodeToJson(e, "official");
193
208
  }
194
- function _t(i, e) {
195
- const t = Lt(i, e);
196
- return Bt(t);
209
+ function Nt(i, e) {
210
+ const t = Mt(i, e);
211
+ return Pt(t);
197
212
  }
198
- function ze(i, e) {
199
- return e ? _t(i, e) : null;
213
+ function Ge(i, e) {
214
+ return e ? Nt(i, e) : null;
200
215
  }
201
- function ye(i, e) {
202
- const t = ze(i, e);
216
+ function ve(i, e) {
217
+ const t = Ge(i, e);
203
218
  return t == null ? 0 : new TextEncoder().encode(t).length;
204
219
  }
205
- function He(i) {
220
+ function Qe(i) {
206
221
  return typeof i == "object" && i !== null && !Array.isArray(i);
207
222
  }
208
- function $t(i) {
223
+ function Ot(i) {
209
224
  return i.replace(/~1/g, "/").replace(/~0/g, "~");
210
225
  }
211
- function xt(i) {
226
+ function At(i) {
212
227
  if (i.length === 0 || !/^\d+$/.test(i))
213
228
  return !1;
214
229
  const e = Number(i);
215
230
  return Number.isSafeInteger(e);
216
231
  }
217
- function _(i, e = !0) {
232
+ function H(i, e = !0) {
218
233
  if (Array.isArray(i))
219
- return e ? i.map((r) => _(r, !0)) : i.slice();
220
- if (!He(i))
234
+ return e ? i.map((r) => H(r, !0)) : i.slice();
235
+ if (!Qe(i))
221
236
  return i;
222
237
  if (Object.prototype.hasOwnProperty.call(i, "value")) {
223
238
  const r = i.value;
224
- return e ? _(r, !0) : r;
239
+ return e ? H(r, !0) : r;
225
240
  }
226
241
  const t = i.items;
227
242
  if (Array.isArray(t))
228
- return e ? t.map((r) => _(r, !0)) : t.slice();
243
+ return e ? t.map((r) => H(r, !0)) : t.slice();
229
244
  const n = {};
230
- for (const [r, s] of Object.entries(i))
231
- n[r] = e ? _(s, !0) : s;
245
+ for (const [r, o] of Object.entries(i))
246
+ n[r] = e ? H(o, !0) : o;
232
247
  return n;
233
248
  }
234
- function Ft(i, e) {
249
+ function Dt(i, e) {
235
250
  if (e === "")
236
251
  return i;
237
252
  if (!e.startsWith("/"))
238
253
  throw new TypeError('JSON pointer must start with "/"');
239
- const t = e.split("/").slice(1).map((r) => $t(r));
254
+ const t = e.split("/").slice(1).map((r) => Ot(r));
240
255
  let n = i;
241
256
  for (const r of t) {
242
257
  if (n == null)
243
258
  return;
244
259
  if (Array.isArray(n)) {
245
- if (!xt(r))
260
+ if (!At(r))
246
261
  return;
247
- const s = Number(r);
248
- n = n[s];
262
+ const o = Number(r);
263
+ n = n[o];
249
264
  continue;
250
265
  }
251
- if (He(n)) {
266
+ if (Qe(n)) {
252
267
  n = n[r];
253
268
  continue;
254
269
  }
@@ -256,37 +271,37 @@ function Ft(i, e) {
256
271
  }
257
272
  return n;
258
273
  }
259
- const zt = 500, Ht = 32 * 1024 * 1024;
260
- class oe {
274
+ const Bt = 500, Lt = 32 * 1024 * 1024;
275
+ class pe {
261
276
  modulePromise;
262
277
  moduleInstance;
263
278
  async evaluate({
264
279
  code: e,
265
280
  bindings: t,
266
- timeout: n = zt,
267
- memoryLimit: r = Ht
281
+ timeout: n = Bt,
282
+ memoryLimit: r = Lt
268
283
  }) {
269
- const o = (await this.ensureModule()).newRuntime();
270
- o.setMemoryLimit(r);
284
+ const s = (await this.ensureModule()).newRuntime();
285
+ s.setMemoryLimit(r);
271
286
  const a = Number.isFinite(n) ? Date.now() + Math.max(n, 0) : void 0;
272
- a !== void 0 && o.setInterruptHandler(() => Date.now() > a);
273
- const c = o.newContext();
287
+ a !== void 0 && s.setInterruptHandler(() => Date.now() > a);
288
+ const c = s.newContext();
274
289
  try {
275
290
  this.installConsole(c), this.installDeterministicGlobals(c), this.installCanonNamespace(c), this.installBindings(c, t);
276
- const l = this.wrapCode(e), u = c.evalCode(l), h = c.unwrapResult(u);
277
- let f = null;
291
+ const u = this.wrapCode(e), d = c.evalCode(u), g = c.unwrapResult(d);
292
+ let m = null;
278
293
  try {
279
- return f = await this.resolveHandle(
294
+ return m = await this.resolveHandle(
280
295
  c,
281
- o,
282
- h,
296
+ s,
297
+ g,
283
298
  a
284
- ), c.dump(f);
299
+ ), c.dump(m);
285
300
  } finally {
286
- f ? f.dispose() : h.dispose();
301
+ m ? m.dispose() : g.dispose();
287
302
  }
288
303
  } finally {
289
- c.dispose(), o.removeInterruptHandler?.(), o.dispose();
304
+ c.dispose(), s.removeInterruptHandler?.(), s.dispose();
290
305
  }
291
306
  }
292
307
  async ensureModule() {
@@ -301,11 +316,11 @@ ${e}
301
316
  e.newObject().consume((t) => {
302
317
  const n = ["log", "info", "warn", "error"];
303
318
  for (const r of n) {
304
- const s = console[r] ?? console.log;
305
- e.newFunction(r, (...o) => {
306
- const a = o.map((c) => e.dump(c));
307
- return s.apply(console, a), e.undefined;
308
- }).consume((o) => e.setProp(t, r, o));
319
+ const o = console[r] ?? console.log;
320
+ e.newFunction(r, (...s) => {
321
+ const a = s.map((c) => e.dump(c));
322
+ return o.apply(console, a), e.undefined;
323
+ }).consume((s) => e.setProp(t, r, s));
309
324
  }
310
325
  e.setProp(e.global, "console", t);
311
326
  });
@@ -317,27 +332,27 @@ ${e}
317
332
  e.newObject().consume((t) => {
318
333
  e.newFunction("unwrap", (...n) => {
319
334
  try {
320
- const [r, s] = n, o = r !== void 0 ? e.dump(r) : void 0, a = s === void 0 ? !0 : !!e.dump(s), c = _(o, a);
335
+ const [r, o] = n, s = r !== void 0 ? e.dump(r) : void 0, a = o === void 0 ? !0 : !!e.dump(o), c = H(s, a);
321
336
  return this.createReturnHandle(e, c);
322
337
  } catch (r) {
323
- const s = r instanceof Error ? r.message : String(r);
324
- return e.newError(s);
338
+ const o = r instanceof Error ? r.message : String(r);
339
+ return e.newError(o);
325
340
  }
326
341
  }).consume((n) => e.setProp(t, "unwrap", n)), e.newFunction("at", (...n) => {
327
342
  try {
328
- const [r, s] = n, o = r !== void 0 ? e.dump(r) : void 0;
329
- if (s === void 0)
343
+ const [r, o] = n, s = r !== void 0 ? e.dump(r) : void 0;
344
+ if (o === void 0)
330
345
  throw new TypeError(
331
346
  "canon.at(target, pointer) requires a pointer argument"
332
347
  );
333
- const a = e.dump(s);
348
+ const a = e.dump(o);
334
349
  if (typeof a != "string")
335
350
  throw new TypeError("canon.at pointer must be a string");
336
- const c = Ft(o, a);
351
+ const c = Dt(s, a);
337
352
  return this.createReturnHandle(e, c);
338
353
  } catch (r) {
339
- const s = r instanceof Error ? r.message : String(r);
340
- return e.newError(s);
354
+ const o = r instanceof Error ? r.message : String(r);
355
+ return e.newError(o);
341
356
  }
342
357
  }).consume((n) => e.setProp(t, "at", n)), e.setProp(e.global, "canon", t);
343
358
  });
@@ -350,22 +365,22 @@ ${e}
350
365
  n,
351
366
  r
352
367
  ).consume(
353
- (o) => e.setProp(e.global, n, o)
368
+ (s) => e.setProp(e.global, n, s)
354
369
  ) : r !== void 0 && this.createOwnedHandle(e, r).consume(
355
- (o) => e.setProp(e.global, n, o)
370
+ (s) => e.setProp(e.global, n, s)
356
371
  );
357
372
  }
358
373
  createFunctionHandle(e, t, n) {
359
374
  const r = e.newFunction(
360
375
  t,
361
- (...s) => {
376
+ (...o) => {
362
377
  try {
363
- const o = s.map((c) => e.dump(c)), a = n(...o);
378
+ const s = o.map((c) => e.dump(c)), a = n(...s);
364
379
  if (a instanceof Promise)
365
380
  throw new TypeError("Async bindings are not supported");
366
381
  return this.createReturnHandle(e, a);
367
- } catch (o) {
368
- const a = o instanceof Error ? o.message : String(o);
382
+ } catch (s) {
383
+ const a = s instanceof Error ? s.message : String(s);
369
384
  return e.newError(a);
370
385
  }
371
386
  }
@@ -380,22 +395,22 @@ ${e}
380
395
  */
381
396
  applyFunctionProperties(e, t, n) {
382
397
  if (!(n === null || typeof n != "object" && typeof n != "function"))
383
- for (const [r, s] of Object.entries(
398
+ for (const [r, o] of Object.entries(
384
399
  n
385
400
  )) {
386
- if (s === void 0)
401
+ if (o === void 0)
387
402
  continue;
388
- if (typeof s == "function") {
403
+ if (typeof o == "function") {
389
404
  this.createFunctionHandle(
390
405
  e,
391
406
  r,
392
- s
407
+ o
393
408
  ).consume(
394
409
  (c) => e.setProp(t, r, c)
395
410
  );
396
411
  continue;
397
412
  }
398
- this.createOwnedHandle(e, s).consume(
413
+ this.createOwnedHandle(e, o).consume(
399
414
  (a) => e.setProp(t, r, a)
400
415
  );
401
416
  }
@@ -449,12 +464,12 @@ ${e}
449
464
  );
450
465
  }
451
466
  async resolveHandle(e, t, n, r) {
452
- let s = n;
467
+ let o = n;
453
468
  for (; ; ) {
454
- const o = e.getPromiseState(s);
455
- if (o.type === "pending") {
469
+ const s = e.getPromiseState(o);
470
+ if (s.type === "pending") {
456
471
  if (r !== void 0 && Date.now() > r)
457
- throw s.dispose(), new Error("QuickJS execution timed out while awaiting Promise");
472
+ throw o.dispose(), new Error("QuickJS execution timed out while awaiting Promise");
458
473
  const a = t.executePendingJobs();
459
474
  let c = 0;
460
475
  try {
@@ -464,222 +479,340 @@ ${e}
464
479
  }
465
480
  if (c === 0) {
466
481
  if (r !== void 0 && Date.now() > r)
467
- throw s.dispose(), new Error(
482
+ throw o.dispose(), new Error(
468
483
  "QuickJS execution timed out while awaiting Promise"
469
484
  );
470
- await new Promise((l) => setTimeout(l, 0));
485
+ await new Promise((u) => setTimeout(u, 0));
471
486
  }
472
487
  continue;
473
488
  }
474
- if (o.type === "fulfilled") {
475
- if (o.notAPromise)
476
- return s;
477
- s.dispose(), s = o.value;
489
+ if (s.type === "fulfilled") {
490
+ if (s.notAPromise)
491
+ return o;
492
+ o.dispose(), o = s.value;
478
493
  continue;
479
494
  }
480
- if (o.type === "rejected")
495
+ if (s.type === "rejected")
481
496
  try {
482
- const a = e.dump(o.error);
497
+ const a = e.dump(s.error);
483
498
  throw a instanceof Error ? a : a && typeof a == "object" && "message" in a ? new Error(
484
499
  String(a.message)
485
500
  ) : new Error(
486
501
  typeof a == "string" ? a : JSON.stringify(a)
487
502
  );
488
503
  } finally {
489
- o.error.dispose(), s.dispose();
504
+ s.error.dispose(), o.dispose();
490
505
  }
491
506
  }
492
507
  }
493
508
  }
494
- const we = 120;
495
- function Ut(i) {
496
- return i.length <= we ? i : `${i.slice(0, we - 3)}...`;
509
+ const be = 120;
510
+ function xt(i) {
511
+ return i.length <= be ? i : `${i.slice(0, be - 3)}...`;
497
512
  }
498
- class Ue extends Error {
513
+ class Ye extends Error {
499
514
  constructor(e, t) {
500
- super(`Failed to evaluate code block: ${Ut(e)}`, { cause: t }), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
515
+ super(`Failed to evaluate code block: ${xt(e)}`, { cause: t }), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
501
516
  }
502
517
  }
503
- const Ve = /^\$\{([\s\S]*)\}$/, Vt = /\$\{([\s\S]+?)\}/, Ke = /\$\{([\s\S]+?)\}/g;
504
- function W(i) {
505
- if (typeof i != "string" || !Ve.test(i))
518
+ const Xe = /^\$\{([\s\S]*)\}$/, _t = /\$\{([\s\S]+?)\}/, Ze = /\$\{([\s\S]+?)\}/g;
519
+ function G(i) {
520
+ if (typeof i != "string" || !Xe.test(i))
506
521
  return !1;
507
522
  const e = i.indexOf("${"), t = i.lastIndexOf("${");
508
523
  return e === t;
509
524
  }
510
- function Kt(i) {
511
- return typeof i != "string" ? !1 : Ve.test(i) ? !0 : Vt.test(i);
525
+ function Ft(i) {
526
+ return typeof i != "string" ? !1 : Xe.test(i) ? !0 : _t.test(i);
512
527
  }
513
- function Wt(i) {
514
- if (!W(i))
528
+ function Ut(i) {
529
+ if (!G(i))
515
530
  throw new Error(`Invalid expression: ${i}`);
516
531
  return i.slice(2, -1);
517
532
  }
518
- async function We(i, e, t) {
533
+ async function et(i, e, t) {
519
534
  const n = `return await (${e});`;
520
535
  try {
521
536
  return await i.evaluate({ code: n, bindings: t });
522
537
  } catch (r) {
523
- throw new Ue(e, r);
538
+ throw new Ye(e, r);
524
539
  }
525
540
  }
526
- async function Gt(i, e, t) {
541
+ async function zt(i, e, t) {
527
542
  let n = "", r = 0;
528
- for (const s of e.matchAll(Ke)) {
529
- const o = s[0], a = s[1], c = s.index ?? 0;
543
+ for (const o of e.matchAll(Ze)) {
544
+ const s = o[0], a = o[1], c = o.index ?? 0;
530
545
  n += e.slice(r, c);
531
- const l = await We(
546
+ const u = await et(
532
547
  i,
533
548
  a,
534
549
  t
535
550
  );
536
- n += l == null ? "" : String(l), r = c + o.length;
551
+ n += u == null ? "" : String(u), r = c + s.length;
537
552
  }
538
553
  return n += e.slice(r), n;
539
554
  }
540
- function Ge({
555
+ function tt({
541
556
  include: i,
542
557
  exclude: e = [],
543
558
  options: t
544
559
  }) {
545
560
  const n = { dot: !0, ...t ?? {} }, r = i.map(
546
- (o) => de(o, n)
547
- ), s = e.map(
548
- (o) => de(o, n)
561
+ (s) => we(s, n)
562
+ ), o = e.map(
563
+ (s) => we(s, n)
549
564
  );
550
- return (o) => r.some((a) => a(o)) && !s.some((a) => a(o));
565
+ return (s) => r.some((a) => a(s)) && !o.some((a) => a(s));
551
566
  }
552
- async function G(i) {
567
+ async function Q(i) {
553
568
  const {
554
569
  evaluator: e,
555
570
  node: t,
556
571
  bindings: n,
557
572
  shouldResolve: r,
573
+ shouldDescend: o = () => !0,
558
574
  context: s,
559
- pointer: o = "/"
560
- } = i, a = t.clone(), c = a.getValue();
561
- if (c !== void 0) {
562
- if (typeof c == "string" && r(o)) {
563
- if (W(c)) {
564
- const h = Wt(c);
565
- s.gasMeter().chargeExpression(h);
566
- const f = await We(
575
+ pointer: a = "/"
576
+ } = i, c = t.clone();
577
+ if (!o(a, c))
578
+ return c;
579
+ const u = c.getValue();
580
+ if (u !== void 0) {
581
+ if (typeof u == "string" && r(a)) {
582
+ if (G(u)) {
583
+ const m = Ut(u);
584
+ s.gasMeter().chargeExpression(m);
585
+ const y = await et(
567
586
  e,
568
- h,
587
+ m,
569
588
  n
570
589
  );
571
- return s.blue.jsonValueToNode(f ?? null);
572
- } else if (Kt(c)) {
573
- const h = new RegExp(Ke);
574
- let f = 0;
575
- for (h.lastIndex = 0; h.exec(c); )
576
- f += 1;
577
- s.gasMeter().chargeTemplate(f, c);
578
- const E = await Gt(
590
+ return s.blue.jsonValueToNode(y ?? null);
591
+ } else if (Ft(u)) {
592
+ const m = new RegExp(Ze);
593
+ let y = 0;
594
+ for (m.lastIndex = 0; m.exec(u); )
595
+ y += 1;
596
+ s.gasMeter().chargeTemplate(y, u);
597
+ const P = await zt(
579
598
  e,
580
- c,
599
+ u,
581
600
  n
582
601
  );
583
- return new d().setValue(E);
602
+ return new h().setValue(P);
584
603
  }
585
604
  }
586
- return a;
605
+ return c;
587
606
  }
588
- const l = a.getItems?.();
589
- if (Array.isArray(l)) {
590
- const h = await Promise.all(
591
- l.map(
592
- (f, E) => G({
607
+ const d = c.getItems?.();
608
+ if (Array.isArray(d)) {
609
+ const m = await Promise.all(
610
+ d.map(
611
+ (y, P) => Q({
593
612
  ...i,
594
- node: f,
595
- pointer: `${o}/${E}`
613
+ node: y,
614
+ pointer: `${a}/${P}`
596
615
  })
597
616
  )
598
617
  );
599
- return a.setItems(h), a;
600
- }
601
- const u = a.getProperties?.();
602
- if (u) {
603
- const h = {};
604
- for (const [f, E] of Object.entries(u)) {
605
- const D = o === "/" ? `/${f}` : `${o}/${f}`;
606
- h[f] = await G({
618
+ return c.setItems(m), c;
619
+ }
620
+ const g = c.getProperties?.();
621
+ if (g) {
622
+ const m = {};
623
+ for (const [y, P] of Object.entries(g)) {
624
+ const re = a === "/" ? `/${y}` : `${a}/${y}`;
625
+ m[y] = await Q({
607
626
  ...i,
608
- node: E,
609
- pointer: D
627
+ node: P,
628
+ pointer: re
610
629
  });
611
630
  }
612
- a.setProperties(h);
613
- }
614
- return a;
615
- }
616
- const ae = Xe, O = et.merge(
617
- ae
631
+ c.setProperties(m);
632
+ }
633
+ return c;
634
+ }
635
+ const ee = f(p["Core/Contract"])(l.object({
636
+ description: l.string().optional(),
637
+ name: l.string().optional(),
638
+ order: l.number().optional()
639
+ })), fe = ee, _ = f(p["Core/Channel"])(ee.extend({
640
+ description: l.string().optional(),
641
+ event: v().optional(),
642
+ name: l.string().optional()
643
+ })), F = _.merge(
644
+ fe
618
645
  ).extend({
619
- path: S.string().optional(),
620
- definition: z().optional()
621
- }), qe = tt.merge(ae), H = nt.merge(ae), qt = S.object({
622
- op: S.enum(["ADD", "REPLACE", "REMOVE"]),
623
- path: S.string(),
624
- val: z().optional()
625
- }), si = ft("JsonPatch")(
626
- qt
646
+ path: l.string().optional(),
647
+ definition: v().optional()
648
+ }), nt = f(p["Core/Handler"])(ee.extend({
649
+ channel: l.string().optional(),
650
+ description: l.string().optional(),
651
+ event: v().optional(),
652
+ name: l.string().optional()
653
+ })), rt = nt.merge(fe), U = f(p["Core/Marker"])(ee.extend({
654
+ description: l.string().optional(),
655
+ name: l.string().optional()
656
+ })), R = U.merge(fe), $t = l.object({
657
+ op: l.enum(["ADD", "REPLACE", "REMOVE"]),
658
+ path: l.string(),
659
+ val: v().optional()
660
+ }), Oi = f("JsonPatch")(
661
+ $t
627
662
  ).superRefine((i, e) => {
628
663
  i.op === "REMOVE" && i.val !== void 0 && e.addIssue({
629
- code: S.ZodIssueCode.custom,
664
+ code: l.ZodIssueCode.custom,
630
665
  message: "REMOVE operations cannot include a value",
631
666
  path: ["val"]
632
667
  }), i.op !== "REMOVE" && i.val === void 0 && e.addIssue({
633
- code: S.ZodIssueCode.custom,
668
+ code: l.ZodIssueCode.custom,
634
669
  message: `${i.op} operations must include a value`,
635
670
  path: ["val"]
636
671
  });
637
- }), jt = rt.merge(
638
- O
639
- ), Jt = it.merge(
640
- O
641
- ), Qt = st.merge(
642
- O
643
- ), Yt = ot.merge(O), Zt = mt.merge(
644
- O
645
- ), Xt = wt.merge(O), en = at.merge(H).extend({
646
- lastSignatures: S.record(S.string()).optional()
647
- }), tn = ct.merge(H), nn = lt.merge(
648
- H
649
- ), rn = ut.merge(H), sn = x.merge(
650
- H
651
- ), oi = z(), on = gt.merge(qe).extend({
652
- steps: S.array(z()).optional()
653
- }), an = Et.merge(
654
- qe
672
+ }), Ht = f(p["Core/Document Update Channel"])(_.extend({
673
+ description: l.string().optional(),
674
+ name: l.string().optional(),
675
+ path: l.string().optional()
676
+ })), Vt = Ht.merge(
677
+ F
678
+ ), Wt = f(p["Core/Embedded Node Channel"])(_.extend({
679
+ childPath: l.string().optional(),
680
+ description: l.string().optional(),
681
+ name: l.string().optional()
682
+ })), Kt = Wt.merge(
683
+ F
684
+ ), qt = f(p["Core/Lifecycle Event Channel"])(_.extend({
685
+ description: l.string().optional(),
686
+ name: l.string().optional()
687
+ })), jt = qt.merge(
688
+ F
689
+ ), Jt = f(p["Core/Triggered Event Channel"])(_.extend({
690
+ description: l.string().optional(),
691
+ name: l.string().optional()
692
+ })), Gt = Jt.merge(F), S = {
693
+ "Conversation/Actor": "CN5efWVizJbRsMCw8YWRfT2q9vM9XfeGDN9wFvYcvMnQ",
694
+ "Conversation/JavaScript Code": "3hYcmWMtMUPAzXBLFLb7BpuG9537tuTJPCr7pxWXvTZK",
695
+ "Conversation/Operation": "BoAiqVUZv9Fum3wFqaX2JnQMBHJLxJSo2V9U2UBmCfsC",
696
+ "Conversation/Operation Request": "HM4Ku4LFcjC5MxnhPMRwQ8w3BbHmJKKZfHTTzsd4jbJq",
697
+ "Conversation/Sequential Workflow": "7X3LkN54Yp88JgZbppPhP6hM3Jqiqv8Z2i4kS7phXtQe",
698
+ "Conversation/Sequential Workflow Operation": "CGdxkNjPcsdescqLPz6SNLsMyak6demQQr7RoKNHbCyv",
699
+ "Conversation/Sequential Workflow Step": "HYsLiqsqk7t98d5fK6YxKEQGeqBaHNVjM4rRNdxK4yUW",
700
+ "Conversation/Timeline": "3Ge54FsGJaaeZmm8nTKJdS6HVdYhiR3g18fDwg3Ev1Sa",
701
+ "Conversation/Timeline Channel": "EvuCWsG1E6WJQg8QXmk6rwMANYTZjoLWVZ1vYQWUwdTH",
702
+ "Conversation/Timeline Entry": "EzDiC9Frs8V5yQBMtDYh1DobVnWtWpFemXDX5fGUULBn",
703
+ "Conversation/Trigger Event": "GxUtWr3eH9a6YQeioQkujEnsPjD5s9RU8ZhEfmsV1vuU",
704
+ "Conversation/Update Document": "BnnNLCnKF49TUJ1bRfZ5rSMaFw8SVfUNfnE4kJFG7HtM"
705
+ }, it = f(S["Conversation/Timeline Channel"])(_.extend({
706
+ description: l.string().optional(),
707
+ name: l.string().optional(),
708
+ timelineId: l.string().optional()
709
+ })), Qt = it.merge(
710
+ F
711
+ ), b = {
712
+ "MyOS/Document Anchor": "HS9yo34TGEAM2LGcNbLh7XPN4goPRhqdGZQkiyh473Wb",
713
+ "MyOS/Document Anchors": "7Usvk6dZMVqas3yqs23ZEXn1zu1YDPjgYiZFNYaw3puH",
714
+ "MyOS/Document Links": "4cmrbevB6K23ZenjqwmNxpnaw6RF4VB3wkP7XB59V7W5",
715
+ "MyOS/Link": "D2ERUvbpn6R6PR7hjFsGofwQsu9bkRfc6wbSYHcfJtMD",
716
+ "MyOS/MyOS Participants Orchestration": "6tzp2YX1rei3aAXg22SqYbeiiteGthj1LesTNCWm7wbU",
717
+ "MyOS/MyOS Session Interaction": "CeWyRmXAMZqvWBvby2KbRUZWcS7Pdxs42vnMXgn9gg6H",
718
+ "MyOS/MyOS Timeline": "2gyToM86KgFJpB8inz8TBVEMZk8UVGYdRozF4mfvxtuk",
719
+ "MyOS/MyOS Timeline Channel": "HCF8mXnX3dFjQ8osjxb4Wzm2Nm1DoXnTYuA5sPnV7NTs",
720
+ "MyOS/MyOS Timeline Entry": "Furgmg5xcJVMDmaQXZRfZ1XehSf7PWctrioo8etRYJHQ",
721
+ "MyOS/MyOS Worker Agency": "4Lix4AKXvBDvrwxw2htSdYFKxL4wugEQzqoSEYet5Dh1"
722
+ }, Yt = f(b["MyOS/MyOS Timeline Channel"])(it.extend({
723
+ accountId: l.string().optional(),
724
+ description: l.string().optional(),
725
+ email: l.string().optional(),
726
+ name: l.string().optional()
727
+ })), Xt = Yt.merge(F), Zt = f(p["Core/Channel Event Checkpoint"])(U.extend({
728
+ description: l.string().optional(),
729
+ lastEvents: l.record(l.string(), v()).optional(),
730
+ name: l.string().optional()
731
+ })), en = Zt.merge(R).extend({
732
+ lastSignatures: l.record(l.string()).optional()
733
+ }), tn = f(p["Core/Processing Initialized Marker"])(U.extend({
734
+ description: l.string().optional(),
735
+ documentId: l.string().optional(),
736
+ name: l.string().optional()
737
+ })), nn = tn.merge(R), rn = f(p["Core/Process Embedded"])(U.extend({
738
+ description: l.string().optional(),
739
+ name: l.string().optional(),
740
+ paths: l.array(l.string()).optional()
741
+ })), on = rn.merge(
742
+ R
743
+ ), sn = f(p["Core/Processing Terminated Marker"])(U.extend({
744
+ cause: l.string().optional(),
745
+ description: l.string().optional(),
746
+ name: l.string().optional(),
747
+ reason: l.string().optional()
748
+ })), an = sn.merge(R), W = f(S["Conversation/Operation"])(U.extend({
749
+ channel: l.string().optional(),
750
+ description: l.string().optional(),
751
+ name: l.string().optional(),
752
+ request: v().optional()
753
+ })), cn = W.merge(
754
+ R
755
+ ), ln = f(b["MyOS/Document Anchor"])(l.object({
756
+ description: l.string().optional(),
757
+ name: l.string().optional(),
758
+ template: v().optional()
759
+ })), un = f(b["MyOS/Document Anchors"])(l.object({}).catchall(ln)), dn = un.merge(R), hn = f(b["MyOS/Link"])(l.object({
760
+ anchor: l.string().optional(),
761
+ description: l.string().optional(),
762
+ name: l.string().optional()
763
+ })), pn = f(b["MyOS/Document Links"])(l.object({}).catchall(hn)), fn = pn.merge(
764
+ R
765
+ ), mn = f(b["MyOS/MyOS Participants Orchestration"])(l.object({
766
+ name: l.string().optional()
767
+ })), gn = mn.merge(R), yn = f(b["MyOS/MyOS Session Interaction"])(l.object({
768
+ name: l.string().optional()
769
+ })), En = yn.merge(R), wn = f(b["MyOS/MyOS Worker Agency"])(l.object({
770
+ name: l.string().optional()
771
+ })), Cn = wn.merge(
772
+ R
773
+ ), te = f(S["Conversation/Sequential Workflow Step"])(l.object({
774
+ description: l.string().optional(),
775
+ name: l.string().optional()
776
+ })), ot = f(S["Conversation/Sequential Workflow"])(nt.extend({
777
+ description: l.string().optional(),
778
+ name: l.string().optional(),
779
+ steps: l.array(te).optional()
780
+ })), Ai = v(), Sn = ot.merge(rt).extend({
781
+ steps: l.array(v()).optional()
782
+ }), vn = f(S["Conversation/Sequential Workflow Operation"])(ot.extend({
783
+ description: l.string().optional(),
784
+ name: l.string().optional(),
785
+ operation: l.string().optional()
786
+ })), bn = vn.merge(
787
+ rt
655
788
  ).extend({
656
- steps: S.array(z()).optional()
789
+ steps: l.array(v()).optional()
657
790
  });
658
- function cn(i) {
791
+ function kn(i) {
659
792
  if (!Array.isArray(i.blueIds) || i.blueIds.length === 0)
660
793
  throw new Error("Contract processors must declare at least one BlueId");
661
794
  for (const e of i.blueIds)
662
795
  if (typeof e != "string" || e.trim().length === 0)
663
796
  throw new Error("Contract processor BlueIds must be non-empty strings");
664
797
  }
665
- function V(i, e) {
666
- cn(i);
798
+ function j(i, e) {
799
+ kn(i);
667
800
  for (const t of i.blueIds)
668
801
  e.set(t, i);
669
802
  }
670
- class ln {
803
+ class Tn {
671
804
  processorsByBlueId = /* @__PURE__ */ new Map();
672
805
  handlerProcessors = /* @__PURE__ */ new Map();
673
806
  channelProcessors = /* @__PURE__ */ new Map();
674
807
  markerProcessors = /* @__PURE__ */ new Map();
675
808
  registerHandler(e) {
676
- V(e, this.handlerProcessors), this.registerProcessorMap(e);
809
+ j(e, this.handlerProcessors), this.registerProcessorMap(e);
677
810
  }
678
811
  registerChannel(e) {
679
- V(e, this.channelProcessors), this.registerProcessorMap(e);
812
+ j(e, this.channelProcessors), this.registerProcessorMap(e);
680
813
  }
681
814
  registerMarker(e) {
682
- V(e, this.markerProcessors), this.registerProcessorMap(e);
815
+ j(e, this.markerProcessors), this.registerProcessorMap(e);
683
816
  }
684
817
  register(e) {
685
818
  switch (e.kind) {
@@ -713,49 +846,96 @@ class ln {
713
846
  return new Map(this.processorsByBlueId);
714
847
  }
715
848
  registerProcessorMap(e) {
716
- V(e, this.processorsByBlueId);
717
- }
849
+ j(e, this.processorsByBlueId);
850
+ }
851
+ }
852
+ const In = f(S["Conversation/Actor"])(l.object({
853
+ description: l.string().optional(),
854
+ name: l.string().optional()
855
+ })), st = f(S["Conversation/Timeline"])(l.object({
856
+ description: l.string().optional(),
857
+ name: l.string().optional(),
858
+ timelineId: l.string().optional()
859
+ })), I = f(S["Conversation/Timeline Entry"])(l.object({
860
+ actor: In.optional(),
861
+ description: l.string().optional(),
862
+ message: v().optional(),
863
+ name: l.string().optional(),
864
+ prevEntry: v().optional(),
865
+ timeline: st.optional(),
866
+ timestamp: l.number().optional()
867
+ })), Rn = f(b["MyOS/MyOS Timeline"])(st.extend({
868
+ accountId: l.string().optional(),
869
+ description: l.string().optional(),
870
+ name: l.string().optional()
871
+ })), ke = f(b["MyOS/MyOS Timeline Entry"])(I.extend({
872
+ description: l.string().optional(),
873
+ name: l.string().optional(),
874
+ timeline: Rn.optional()
875
+ }));
876
+ function Te(i, e) {
877
+ return e && i.isTypeOf(e, I, { checkSchemaExtensions: !0 }) ? i.nodeToSchemaOutput(e, I) : null;
878
+ }
879
+ function at(i, e, t) {
880
+ const n = Te(i, e), r = Te(i, t);
881
+ if (!n || !r)
882
+ return !0;
883
+ const o = n.timestamp, s = r.timestamp;
884
+ return typeof o != "number" || typeof s != "number" ? !0 : o >= s;
718
885
  }
719
- function be(i, e) {
720
- return i.isTypeOf(e, me) ? i.nodeToSchemaOutput(e, me) : i.isTypeOf(e, k) ? i.nodeToSchemaOutput(e, k) : null;
886
+ function Ie(i, e) {
887
+ return i.isTypeOf(e, ke) ? i.nodeToSchemaOutput(e, ke) : i.isTypeOf(e, I) ? i.nodeToSchemaOutput(e, I) : null;
721
888
  }
722
- class un {
889
+ class Pn {
723
890
  kind = "channel";
724
- blueIds = [bt["MyOS Timeline Channel"]];
891
+ blueIds = [b["MyOS/MyOS Timeline Channel"]];
725
892
  schema = Xt;
726
893
  matches(e, t) {
727
894
  const { event: n, blue: r } = t;
728
895
  if (!n)
729
896
  return !1;
730
- const s = be(r, n);
731
- if (!s)
897
+ const o = Ie(r, n);
898
+ if (!o)
732
899
  return !1;
733
- const o = s.timeline?.timelineId;
734
- return !o || !e.timelineId ? !1 : o === e.timelineId;
900
+ const s = o.timeline?.timelineId;
901
+ return !s || !e.timelineId ? !1 : s === e.timelineId;
735
902
  }
736
903
  channelize(e, t) {
737
904
  const { event: n, blue: r } = t;
738
- return !n || !be(r, n) ? null : n.clone();
905
+ return !n || !Ie(r, n) ? null : n.clone();
906
+ }
907
+ isNewerEvent(e, t, n) {
908
+ const { event: r, blue: o } = t;
909
+ return r ? at(o, r, n) : !0;
739
910
  }
740
911
  }
741
- class dn {
912
+ class Mn {
742
913
  kind = "channel";
743
- blueIds = [v["Timeline Channel"]];
744
- schema = Zt;
914
+ blueIds = [S["Conversation/Timeline Channel"]];
915
+ schema = Qt;
745
916
  matches(e, t) {
746
917
  const { event: n, blue: r } = t;
747
- if (!n || !r.isTypeOf(n, k))
918
+ if (!n || !r.isTypeOf(n, I))
748
919
  return !1;
749
- const o = r.nodeToSchemaOutput(n, k).timeline?.timelineId;
750
- return !(!o || !e.timelineId || o !== e.timelineId);
920
+ const s = r.nodeToSchemaOutput(n, I).timeline?.timelineId;
921
+ return !(!s || !e.timelineId || s !== e.timelineId);
751
922
  }
752
923
  channelize(e, t) {
753
924
  const { event: n, blue: r } = t;
754
- return !n || !r.isTypeOf(n, k) ? null : n.clone();
925
+ return !n || !r.isTypeOf(n, I) ? null : n.clone();
926
+ }
927
+ isNewerEvent(e, t, n) {
928
+ const { event: r, blue: o } = t;
929
+ return r ? at(o, r, n) : !0;
755
930
  }
756
931
  }
757
- function ce(i) {
758
- const { context: e, eventNode: t, stepResults: n } = i, r = hn(e);
932
+ const Re = f(S["Conversation/Trigger Event"])(te.extend({
933
+ description: l.string().optional(),
934
+ event: v().optional(),
935
+ name: l.string().optional()
936
+ }));
937
+ function me(i) {
938
+ const { context: e, eventNode: t, stepResults: n } = i, r = On(e);
759
939
  return {
760
940
  event: e.blue.nodeToJson(t, "simple"),
761
941
  eventCanonical: e.blue.nodeToJson(t, "official"),
@@ -763,71 +943,94 @@ function ce(i) {
763
943
  document: r
764
944
  };
765
945
  }
766
- function hn(i) {
767
- const e = (r) => {
768
- const s = r == null ? "/" : typeof r == "string" ? r : (() => {
946
+ const Nn = /* @__PURE__ */ new Set(["blueId", "name", "description", "value"]);
947
+ function On(i) {
948
+ const e = (o) => {
949
+ if (o === "/")
950
+ return !1;
951
+ const s = o.lastIndexOf("/"), a = o.substring(s + 1);
952
+ return Nn.has(a);
953
+ }, t = (o) => {
954
+ const s = o == null ? "/" : typeof o == "string" ? o : (() => {
769
955
  throw new TypeError("document() expects a string pointer");
770
- })(), o = s.startsWith("/") ? s : i.resolvePointer(s), a = b(o), c = i.documentAt(a);
771
- return i.gasMeter().chargeDocumentSnapshot(a, c), { snapshot: c, normalizedPointer: a };
772
- }, t = (r, s) => {
773
- const { snapshot: o } = e(r);
774
- if (o)
775
- return i.blue.nodeToJson(o, s);
776
- }, n = (r) => t(r, "simple");
777
- return n.canonical = (r) => t(r, "official"), n;
778
- }
779
- class fn {
780
- supportedBlueIds = [v["Trigger Event"]];
781
- evaluator = new oe();
956
+ })(), a = s.startsWith("/") ? s : i.resolvePointer(s), c = T(a), u = i.documentAt(c);
957
+ return i.gasMeter().chargeDocumentSnapshot(c, u), { snapshot: u, normalizedPointer: c };
958
+ }, n = (o, s) => {
959
+ const { snapshot: a, normalizedPointer: c } = t(o);
960
+ if (a)
961
+ return e(c) ? i.blue.nodeToJson(a, "simple") : i.blue.nodeToJson(a, s);
962
+ }, r = (o) => n(o, "simple");
963
+ return r.canonical = (o) => n(o, "official"), r;
964
+ }
965
+ class An {
966
+ supportedBlueIds = [
967
+ S["Conversation/Trigger Event"]
968
+ ];
969
+ evaluator = new pe();
782
970
  async execute(e) {
783
971
  const { stepNode: t, context: n } = e;
784
- if (!n.blue.isTypeOf(t, he))
972
+ if (!n.blue.isTypeOf(t, Re))
785
973
  return n.throwFatal("Trigger Event step payload is invalid");
786
974
  n.gasMeter().chargeTriggerEventBase();
787
- const r = await G({
975
+ const r = await Q({
788
976
  evaluator: this.evaluator,
789
977
  node: t,
790
- bindings: ce(e),
791
- shouldResolve: Ge({
978
+ bindings: me(e),
979
+ shouldResolve: tt({
792
980
  include: ["/event", "/event/**"]
793
981
  }),
982
+ shouldDescend: Dn(),
794
983
  context: n
795
- }), o = n.blue.nodeToSchemaOutput(
984
+ }), s = n.blue.nodeToSchemaOutput(
796
985
  r,
797
- he
986
+ Re
798
987
  ).event;
799
- if (te(o))
988
+ if (ae(s))
800
989
  return n.throwFatal(
801
990
  "Trigger Event step must declare event payload"
802
991
  );
803
- n.emitEvent(o.clone());
992
+ n.emitEvent(s.clone());
804
993
  }
805
994
  }
806
- class pn {
807
- supportedBlueIds = [v["JavaScript Code"]];
808
- evaluator = new oe();
995
+ function Dn() {
996
+ return (i, e) => i === "/event" || !i.startsWith("/event/") ? !0 : !Bn(e);
997
+ }
998
+ function Bn(i) {
999
+ const e = i.getProperties?.();
1000
+ return e ? !!e.contracts : !1;
1001
+ }
1002
+ const Pe = f(S["Conversation/JavaScript Code"])(te.extend({
1003
+ code: l.string().optional(),
1004
+ description: l.string().optional(),
1005
+ name: l.string().optional()
1006
+ }));
1007
+ class Ln {
1008
+ supportedBlueIds = [
1009
+ S["Conversation/JavaScript Code"]
1010
+ ];
1011
+ evaluator = new pe();
809
1012
  async execute(e) {
810
1013
  const { context: t, stepNode: n } = e, { blue: r } = t;
811
- if (!r.isTypeOf(n, fe))
1014
+ if (!r.isTypeOf(n, Pe))
812
1015
  return t.throwFatal("JavaScript Code step payload is invalid");
813
- const o = r.nodeToSchemaOutput(
1016
+ const s = r.nodeToSchemaOutput(
814
1017
  n,
815
- fe
1018
+ Pe
816
1019
  ).code;
817
- if (!o)
1020
+ if (!s)
818
1021
  return t.throwFatal(
819
1022
  "JavaScript Code step must include code to execute"
820
1023
  );
821
- t.gasMeter().chargeJavaScriptCodeBase(o);
822
- const a = ce(e);
1024
+ t.gasMeter().chargeJavaScriptCodeBase(s);
1025
+ const a = me(e);
823
1026
  try {
824
1027
  const c = await this.evaluator.evaluate({
825
- code: o,
1028
+ code: s,
826
1029
  bindings: a
827
1030
  });
828
1031
  return this.handleEvents(c, t), c;
829
1032
  } catch (c) {
830
- throw new Ue(o, c);
1033
+ throw new Ye(s, c);
831
1034
  }
832
1035
  }
833
1036
  handleEvents(e, t) {
@@ -836,29 +1039,42 @@ class pn {
836
1039
  const n = e;
837
1040
  if (Array.isArray(n.events))
838
1041
  for (const r of n.events) {
839
- const s = t.blue.jsonValueToNode(r);
840
- t.emitEvent(s);
1042
+ const o = t.blue.jsonValueToNode(r);
1043
+ t.emitEvent(o);
841
1044
  }
842
1045
  }
843
1046
  }
844
- class mn {
845
- supportedBlueIds = [v["Update Document"]];
846
- evaluator = new oe();
1047
+ const xn = f(p["Core/Json Patch Entry"])(l.object({
1048
+ description: l.string().optional(),
1049
+ name: l.string().optional(),
1050
+ op: l.string().optional(),
1051
+ path: l.string().optional(),
1052
+ val: v().optional()
1053
+ })), Me = f(S["Conversation/Update Document"])(te.extend({
1054
+ changeset: l.array(xn).optional(),
1055
+ description: l.string().optional(),
1056
+ name: l.string().optional()
1057
+ }));
1058
+ class _n {
1059
+ supportedBlueIds = [
1060
+ S["Conversation/Update Document"]
1061
+ ];
1062
+ evaluator = new pe();
847
1063
  async execute(e) {
848
1064
  const { context: t, stepNode: n } = e, { blue: r } = t;
849
- if (!r.isTypeOf(n, pe))
1065
+ if (!r.isTypeOf(n, Me))
850
1066
  return t.throwFatal("Update Document step payload is invalid");
851
- const s = await G({
1067
+ const o = await Q({
852
1068
  evaluator: this.evaluator,
853
1069
  node: n,
854
- bindings: ce(e),
855
- shouldResolve: Ge({
1070
+ bindings: me(e),
1071
+ shouldResolve: tt({
856
1072
  include: ["/changeset", "/changeset/**"]
857
1073
  }),
858
1074
  context: t
859
- }), o = this.extractChanges(s, t);
860
- t.gasMeter().chargeUpdateDocumentBase(o.length);
861
- for (const a of o) {
1075
+ }), s = this.extractChanges(o, t);
1076
+ t.gasMeter().chargeUpdateDocumentBase(s.length);
1077
+ for (const a of s) {
862
1078
  const c = this.createPatch(a, t);
863
1079
  await t.applyPatch(c);
864
1080
  }
@@ -866,12 +1082,12 @@ class mn {
866
1082
  extractChanges(e, t) {
867
1083
  return t.blue.nodeToSchemaOutput(
868
1084
  e,
869
- pe
1085
+ Me
870
1086
  ).changeset ?? [];
871
1087
  }
872
1088
  createPatch(e, t) {
873
- const n = this.normalizeOperation(e.op, t), r = this.normalizePath(e.path, t), s = t.resolvePointer(r);
874
- return n === "REMOVE" ? { op: n, path: s } : { op: n, path: s, val: e.val };
1089
+ const n = this.normalizeOperation(e.op, t), r = this.normalizePath(e.path, t), o = t.resolvePointer(r);
1090
+ return n === "REMOVE" ? { op: n, path: o } : { op: n, path: o, val: e.val };
875
1091
  }
876
1092
  normalizeOperation(e, t) {
877
1093
  const n = typeof e == "string" ? e : void 0, r = (n ?? "REPLACE").toUpperCase();
@@ -886,14 +1102,14 @@ class mn {
886
1102
  return n.length === 0 ? t.throwFatal("Update Document path cannot be empty") : n;
887
1103
  }
888
1104
  }
889
- const le = [
890
- new fn(),
891
- new pn(),
892
- new mn()
1105
+ const ge = [
1106
+ new An(),
1107
+ new Ln(),
1108
+ new _n()
893
1109
  ];
894
- class je {
1110
+ class ct {
895
1111
  executorIndex;
896
- constructor(e = le) {
1112
+ constructor(e = ge) {
897
1113
  const t = /* @__PURE__ */ new Map();
898
1114
  for (const n of e)
899
1115
  for (const r of n.supportedBlueIds)
@@ -901,50 +1117,52 @@ class je {
901
1117
  this.executorIndex = t;
902
1118
  }
903
1119
  async run(e) {
904
- const { workflow: t, eventNode: n, context: r } = e, s = t.steps ?? [];
905
- if (s.length === 0)
1120
+ const { workflow: t, eventNode: n, context: r } = e, o = t.steps ?? [];
1121
+ if (o.length === 0)
906
1122
  return {};
907
- const o = {};
908
- for (const [a, c] of s.entries()) {
909
- const l = c.getType?.()?.getBlueId();
910
- if (te(l))
1123
+ const s = {};
1124
+ for (const [a, c] of o.entries()) {
1125
+ const u = c.getType?.()?.getBlueId();
1126
+ if (ae(u))
911
1127
  return r.throwFatal(
912
1128
  "Sequential workflow step is missing type metadata"
913
1129
  );
914
- const u = this.executorIndex.get(l);
915
- if (te(u)) {
916
- const E = c.getType?.()?.getName?.() ?? l;
1130
+ const d = this.executorIndex.get(u);
1131
+ if (ae(d)) {
1132
+ const y = c.getType?.()?.getName?.() ?? u;
917
1133
  return r.throwFatal(
918
- `Unsupported workflow step type "${E}"`
1134
+ `Unsupported workflow step type "${y}"`
919
1135
  );
920
1136
  }
921
- const h = {
1137
+ const g = {
922
1138
  workflow: t,
923
1139
  stepNode: c,
924
1140
  eventNode: n,
925
1141
  context: r,
926
- stepResults: o,
1142
+ stepResults: s,
927
1143
  stepIndex: a
928
- }, f = await u.execute(h);
929
- if (f !== void 0) {
930
- const E = this.stepResultKey(c, a);
931
- o[E] = f;
1144
+ }, m = await d.execute(g);
1145
+ if (m !== void 0) {
1146
+ const y = this.stepResultKey(c, a);
1147
+ s[y] = m;
932
1148
  }
933
1149
  }
934
- return o;
1150
+ return s;
935
1151
  }
936
1152
  stepResultKey(e, t) {
937
1153
  const n = e.getName?.();
938
1154
  return n && typeof n == "string" && n.length > 0 ? n : `Step${t + 1}`;
939
1155
  }
940
1156
  }
941
- class gn {
1157
+ class Fn {
942
1158
  kind = "handler";
943
- blueIds = [v["Sequential Workflow"]];
944
- schema = on;
1159
+ blueIds = [
1160
+ S["Conversation/Sequential Workflow"]
1161
+ ];
1162
+ schema = Sn;
945
1163
  runner;
946
- constructor(e = le) {
947
- this.runner = new je(e);
1164
+ constructor(e = ge) {
1165
+ this.runner = new ct(e);
948
1166
  }
949
1167
  async matches(e, t) {
950
1168
  const n = t.event();
@@ -955,12 +1173,20 @@ class gn {
955
1173
  n && await this.runner.run({ workflow: e, eventNode: n, context: t });
956
1174
  }
957
1175
  }
958
- class En {
1176
+ class Un {
959
1177
  kind = "marker";
960
- blueIds = [v.Operation];
961
- schema = sn;
962
- }
963
- function Je(i) {
1178
+ blueIds = [S["Conversation/Operation"]];
1179
+ schema = cn;
1180
+ }
1181
+ const le = f(S["Conversation/Operation Request"])(l.object({
1182
+ allowNewerVersion: l.boolean().optional(),
1183
+ description: l.string().optional(),
1184
+ document: v().optional(),
1185
+ name: l.string().optional(),
1186
+ operation: l.string().optional(),
1187
+ request: v().optional()
1188
+ }));
1189
+ function lt(i) {
964
1190
  const e = i.channel;
965
1191
  if (typeof e == "string") {
966
1192
  const t = e.trim();
@@ -969,49 +1195,49 @@ function Je(i) {
969
1195
  }
970
1196
  return null;
971
1197
  }
972
- function yn(i, e) {
1198
+ function zn(i, e) {
973
1199
  const t = i.getProperties()?.document;
974
- return t instanceof d ? e.blue.calculateBlueIdSync(t) : null;
1200
+ return t instanceof h ? e.blue.calculateBlueIdSync(t) : null;
975
1201
  }
976
- function wn(i, e) {
977
- if (e.isTypeOf(i, ee, {
1202
+ function $n(i, e) {
1203
+ if (e.isTypeOf(i, le, {
978
1204
  checkSchemaExtensions: !0
979
1205
  }))
980
1206
  return i;
981
- if (e.isTypeOf(i, k, {
1207
+ if (e.isTypeOf(i, I, {
982
1208
  checkSchemaExtensions: !0
983
1209
  })) {
984
- const n = e.nodeToSchemaOutput(i, k).message;
985
- if (n && e.isTypeOf(n, ee, {
1210
+ const n = e.nodeToSchemaOutput(i, I).message;
1211
+ if (n && e.isTypeOf(n, le, {
986
1212
  checkSchemaExtensions: !0
987
1213
  }))
988
1214
  return n;
989
1215
  }
990
1216
  return null;
991
1217
  }
992
- function bn(i, e, t, n) {
993
- const { blue: r } = n, s = i.operation;
994
- return !(!s || t.operation !== s || i.event && !r.isTypeOfNode(e, i.event));
1218
+ function Hn(i, e, t, n) {
1219
+ const { blue: r } = n, o = i.operation;
1220
+ return !(!o || t.operation !== o || i.event && !r.isTypeOfNode(e, i.event));
995
1221
  }
996
- function Sn(i, e) {
1222
+ function Vn(i, e) {
997
1223
  const t = i.operation;
998
1224
  if (!t)
999
1225
  return null;
1000
1226
  const n = e.resolvePointer(`/contracts/${t}`), r = e.documentAt(n);
1001
- if (!r || !e.blue.isTypeOf(r, x))
1227
+ if (!r || !e.blue.isTypeOf(r, W))
1002
1228
  return null;
1003
- const s = e.blue.nodeToSchemaOutput(
1229
+ const o = e.blue.nodeToSchemaOutput(
1004
1230
  r,
1005
- x
1006
- ), o = Je(s);
1007
- return { operationNode: r, operation: s, channelKey: o };
1231
+ W
1232
+ ), s = lt(o);
1233
+ return { operationNode: r, operation: o, channelKey: s };
1008
1234
  }
1009
- function Cn(i, e) {
1235
+ function Wn(i, e) {
1010
1236
  return !(i && e && i !== e);
1011
1237
  }
1012
- function kn(i, e, t) {
1238
+ function Kn(i, e, t) {
1013
1239
  const n = i.getProperties()?.request, r = e.getProperties()?.request;
1014
- if (!(n instanceof d) || !(r instanceof d))
1240
+ if (!(n instanceof h) || !(r instanceof h))
1015
1241
  return !1;
1016
1242
  try {
1017
1243
  if (!t.isTypeOfNode(n, r))
@@ -1021,65 +1247,65 @@ function kn(i, e, t) {
1021
1247
  }
1022
1248
  return !0;
1023
1249
  }
1024
- function In(i, e, t) {
1250
+ function qn(i, e, t) {
1025
1251
  if (!i || i.allowNewerVersion !== !1)
1026
1252
  return !0;
1027
- const n = yn(e, t);
1253
+ const n = zn(e, t);
1028
1254
  if (!n)
1029
1255
  return !0;
1030
- const r = t.resolvePointer("/"), s = t.documentAt(r);
1031
- if (!s)
1256
+ const r = t.resolvePointer("/"), o = t.documentAt(r);
1257
+ if (!o)
1032
1258
  return !1;
1033
- const c = (s.getContracts()?.initialized ?? null)?.get("/documentId") ?? null, l = typeof c == "string" && c.length > 0 ? c : t.blue.calculateBlueIdSync(s);
1034
- return n === l;
1259
+ const c = (o.getContracts()?.initialized ?? null)?.get("/documentId") ?? null, u = typeof c == "string" && c.length > 0 ? c : t.blue.calculateBlueIdSync(o);
1260
+ return n === u;
1035
1261
  }
1036
- class vn {
1262
+ class jn {
1037
1263
  kind = "handler";
1038
1264
  blueIds = [
1039
- v["Sequential Workflow Operation"]
1265
+ S["Conversation/Sequential Workflow Operation"]
1040
1266
  ];
1041
- schema = an;
1267
+ schema = bn;
1042
1268
  runner;
1043
- constructor(e = le) {
1044
- this.runner = new je(e);
1269
+ constructor(e = ge) {
1270
+ this.runner = new ct(e);
1045
1271
  }
1046
1272
  deriveChannel(e, t) {
1047
1273
  const n = e.operation;
1048
1274
  if (!n)
1049
1275
  return null;
1050
1276
  const r = t.scopeContracts.get(n);
1051
- if (!r || !t.blue.isTypeOf(r.node, x, {
1277
+ if (!r || !t.blue.isTypeOf(r.node, W, {
1052
1278
  checkSchemaExtensions: !0
1053
1279
  }))
1054
1280
  return null;
1055
- const s = t.blue.nodeToSchemaOutput(r.node, x);
1056
- return s ? Je(s) : null;
1281
+ const o = t.blue.nodeToSchemaOutput(r.node, W);
1282
+ return o ? lt(o) : null;
1057
1283
  }
1058
1284
  async matches(e, t) {
1059
1285
  const n = t.event();
1060
1286
  if (!n)
1061
1287
  return !1;
1062
- const r = wn(
1288
+ const r = $n(
1063
1289
  n,
1064
1290
  t.blue
1065
1291
  );
1066
1292
  if (!r)
1067
1293
  return !1;
1068
- const s = t.blue.nodeToSchemaOutput(
1294
+ const o = t.blue.nodeToSchemaOutput(
1069
1295
  r,
1070
- ee
1296
+ le
1071
1297
  );
1072
- if (!s || !bn(e, n, s, t))
1298
+ if (!o || !Hn(e, n, o, t))
1073
1299
  return !1;
1074
- const o = Sn(e, t);
1075
- if (!o)
1300
+ const s = Vn(e, t);
1301
+ if (!s)
1076
1302
  return !1;
1077
1303
  const a = typeof e.channel == "string" ? e.channel.trim() : "", c = a.length > 0 ? a : null;
1078
- return !(!Cn(o.channelKey, c) || !kn(
1304
+ return !(!Wn(s.channelKey, c) || !Kn(
1079
1305
  r,
1080
- o.operationNode,
1306
+ s.operationNode,
1081
1307
  t.blue
1082
- ) || s?.allowNewerVersion === !1 && !In(s, r, t));
1308
+ ) || o?.allowNewerVersion === !1 && !qn(o, r, t));
1083
1309
  }
1084
1310
  async execute(e, t) {
1085
1311
  const n = t.event();
@@ -1090,17 +1316,17 @@ class vn {
1090
1316
  });
1091
1317
  }
1092
1318
  }
1093
- class Q {
1319
+ class ne {
1094
1320
  constructor(e) {
1095
1321
  this.registry = e;
1096
1322
  }
1097
1323
  static create() {
1098
- return new Q(
1099
- new ln()
1324
+ return new ne(
1325
+ new Tn()
1100
1326
  );
1101
1327
  }
1102
1328
  registerDefaults() {
1103
- return this.registry.register(new un()), this.registry.register(new dn()), this.registry.register(new gn()), this.registry.register(new En()), this.registry.register(new vn()), this;
1329
+ return this.registry.register(new Pn()), this.registry.register(new Mn()), this.registry.register(new Fn()), this.registry.register(new Un()), this.registry.register(new jn()), this;
1104
1330
  }
1105
1331
  register(e) {
1106
1332
  return this.registry.register(e), this;
@@ -1109,11 +1335,11 @@ class Q {
1109
1335
  return this.registry;
1110
1336
  }
1111
1337
  }
1112
- const re = p["Channel Event Checkpoint"];
1113
- function Qe(i) {
1338
+ const ue = p["Core/Channel Event Checkpoint"];
1339
+ function ut(i) {
1114
1340
  return typeof i.order == "number" ? i.order : 0;
1115
1341
  }
1116
- class Rn {
1342
+ class Jn {
1117
1343
  constructor(e, t, n) {
1118
1344
  this.bindingKey = e, this.bindingContract = t, this.bindingBlueId = n;
1119
1345
  }
@@ -1127,10 +1353,10 @@ class Rn {
1127
1353
  return this.bindingBlueId;
1128
1354
  }
1129
1355
  order() {
1130
- return Qe(this.bindingContract);
1356
+ return ut(this.bindingContract);
1131
1357
  }
1132
1358
  }
1133
- class Tn {
1359
+ class Gn {
1134
1360
  constructor(e, t, n) {
1135
1361
  this.bindingKey = e, this.bindingContract = t, this.bindingBlueId = n;
1136
1362
  }
@@ -1144,28 +1370,28 @@ class Tn {
1144
1370
  return this.bindingBlueId;
1145
1371
  }
1146
1372
  order() {
1147
- return Qe(this.bindingContract);
1373
+ return ut(this.bindingContract);
1148
1374
  }
1149
1375
  }
1150
- class M {
1151
- constructor(e, t, n, r, s) {
1152
- this.channels = e, this.handlersByChannel = t, this.markerStore = n, this.embeddedPathsInternal = r, this.checkpointDeclared = s;
1376
+ class L {
1377
+ constructor(e, t, n, r, o) {
1378
+ this.channels = e, this.handlersByChannel = t, this.markerStore = n, this.embeddedPathsInternal = r, this.checkpointDeclared = o;
1153
1379
  }
1154
1380
  checkpointDeclared;
1155
- static fromComponents(e, t, n, r, s) {
1156
- return new M(
1381
+ static fromComponents(e, t, n, r, o) {
1382
+ return new L(
1157
1383
  e,
1158
1384
  t,
1159
1385
  n,
1160
1386
  r,
1161
- s
1387
+ o
1162
1388
  );
1163
1389
  }
1164
1390
  static builder() {
1165
- return new Pn();
1391
+ return new Qn();
1166
1392
  }
1167
1393
  static empty() {
1168
- return M.builder().build();
1394
+ return L.builder().build();
1169
1395
  }
1170
1396
  markers() {
1171
1397
  return new Map(
@@ -1195,32 +1421,32 @@ class M {
1195
1421
  throw new Error(
1196
1422
  "Duplicate Channel Event Checkpoint markers detected in same contracts map"
1197
1423
  );
1198
- this.markerStore.set(I, {
1199
- key: I,
1424
+ this.markerStore.set(N, {
1425
+ key: N,
1200
1426
  contract: e,
1201
- blueId: re
1427
+ blueId: ue
1202
1428
  }), this.checkpointDeclared = !0;
1203
1429
  }
1204
1430
  handlersFor(e) {
1205
1431
  const t = this.handlersByChannel.get(e);
1206
1432
  return !t || t.length === 0 ? [] : [...t].map(
1207
- (n) => new Tn(n.key, n.contract, n.blueId)
1433
+ (n) => new Gn(n.key, n.contract, n.blueId)
1208
1434
  ).sort((n, r) => {
1209
- const s = n.order() - r.order();
1210
- return s !== 0 ? s : n.key().localeCompare(r.key());
1435
+ const o = n.order() - r.order();
1436
+ return o !== 0 ? o : n.key().localeCompare(r.key());
1211
1437
  });
1212
1438
  }
1213
1439
  channelsOfType(...e) {
1214
1440
  const t = e.length > 0 ? new Set(e) : null, n = Array.from(this.channels.values()).filter((r) => !t || t.has(r.blueId)).map(
1215
- (r) => new Rn(r.key, r.contract, r.blueId)
1441
+ (r) => new Jn(r.key, r.contract, r.blueId)
1216
1442
  );
1217
- return n.sort((r, s) => {
1218
- const o = r.order() - s.order();
1219
- return o !== 0 ? o : r.key().localeCompare(s.key());
1443
+ return n.sort((r, o) => {
1444
+ const s = r.order() - o.order();
1445
+ return s !== 0 ? s : r.key().localeCompare(o.key());
1220
1446
  }), n;
1221
1447
  }
1222
1448
  }
1223
- class Pn {
1449
+ class Qn {
1224
1450
  channels = /* @__PURE__ */ new Map();
1225
1451
  handlersByChannel = /* @__PURE__ */ new Map();
1226
1452
  markerStore = /* @__PURE__ */ new Map();
@@ -1234,8 +1460,8 @@ class Pn {
1234
1460
  const r = t.channel;
1235
1461
  if (!r)
1236
1462
  throw new Error(`Handler ${e} must declare channel`);
1237
- const s = this.handlersByChannel.get(r) ?? [];
1238
- return s.push({ key: e, contract: t, blueId: n }), this.handlersByChannel.set(r, s), this;
1463
+ const o = this.handlersByChannel.get(r) ?? [];
1464
+ return o.push({ key: e, contract: t, blueId: n }), this.handlersByChannel.set(r, o), this;
1239
1465
  }
1240
1466
  setEmbedded(e) {
1241
1467
  if (this.embeddedDeclared)
@@ -1245,12 +1471,12 @@ class Pn {
1245
1471
  return this.embeddedDeclared = !0, this.embeddedPaths = e.paths ? [...e.paths] : [], this;
1246
1472
  }
1247
1473
  addMarker(e, t, n) {
1248
- if (e === I && n !== re)
1474
+ if (e === N && n !== ue)
1249
1475
  throw new Error(
1250
1476
  "Reserved key 'checkpoint' must contain a Channel Event Checkpoint"
1251
1477
  );
1252
- if (n === re) {
1253
- if (e !== I)
1478
+ if (n === ue) {
1479
+ if (e !== N)
1254
1480
  throw new Error(
1255
1481
  `Channel Event Checkpoint must use reserved key 'checkpoint' at key '${e}'`
1256
1482
  );
@@ -1263,7 +1489,7 @@ class Pn {
1263
1489
  return this.markerStore.set(e, { key: e, contract: t, blueId: n }), this;
1264
1490
  }
1265
1491
  build() {
1266
- return M.fromComponents(
1492
+ return L.fromComponents(
1267
1493
  new Map(this.channels),
1268
1494
  new Map(
1269
1495
  Array.from(this.handlersByChannel.entries(), ([e, t]) => [
@@ -1277,12 +1503,12 @@ class Pn {
1277
1503
  );
1278
1504
  }
1279
1505
  }
1280
- class m extends Error {
1506
+ class E extends Error {
1281
1507
  constructor(e, t) {
1282
1508
  super(e || "Processor fatal error"), this.processorError = t, this.name = "ProcessorFatalError";
1283
1509
  }
1284
1510
  }
1285
- class Nn {
1511
+ class Yn {
1286
1512
  constructor(e, t, n) {
1287
1513
  this.blue = e, this.registry = t, this.builtinChannelSchemas = n;
1288
1514
  }
@@ -1291,53 +1517,53 @@ class Nn {
1291
1517
  key: t,
1292
1518
  node: n,
1293
1519
  processor: r,
1294
- blueId: s,
1295
- scopeContracts: o
1520
+ blueId: o,
1521
+ scopeContracts: s
1296
1522
  }) {
1297
1523
  try {
1298
1524
  const a = r.schema, c = this.blue.nodeToSchemaOutput(
1299
1525
  n,
1300
1526
  a
1301
- ), l = this.resolveChannelKey({
1527
+ ), u = this.resolveChannelKey({
1302
1528
  contract: c,
1303
1529
  processor: r,
1304
- scopeContracts: o,
1530
+ scopeContracts: s,
1305
1531
  handlerKey: t
1306
- }), u = o.get(l);
1307
- if (!u)
1308
- throw new m(
1309
- `Handler ${t} references unknown channel '${l}'`,
1310
- g.invalidContract(
1311
- s,
1312
- `Channel '${l}' is not declared in this scope`,
1313
- `/contracts/${l}`
1532
+ }), d = s.get(u);
1533
+ if (!d)
1534
+ throw new E(
1535
+ `Handler ${t} references unknown channel '${u}'`,
1536
+ w.invalidContract(
1537
+ o,
1538
+ `Channel '${u}' is not declared in this scope`,
1539
+ `/contracts/${u}`
1314
1540
  )
1315
1541
  );
1316
- if (!this.isRegisteredChannel(u.nodeTypeBlueId))
1317
- throw new m(
1318
- `Contract '${l}' is not a channel`,
1319
- g.invalidContract(
1320
- u.nodeTypeBlueId,
1321
- `Contract '${l}' is not a channel`,
1322
- `/contracts/${l}`
1542
+ if (!this.isRegisteredChannel(d.nodeTypeBlueId))
1543
+ throw new E(
1544
+ `Contract '${u}' is not a channel`,
1545
+ w.invalidContract(
1546
+ d.nodeTypeBlueId,
1547
+ `Contract '${u}' is not a channel`,
1548
+ `/contracts/${u}`
1323
1549
  )
1324
1550
  );
1325
- e.addHandler(t, { ...c, channel: l }, s);
1551
+ e.addHandler(t, { ...c, channel: u }, o);
1326
1552
  } catch (a) {
1327
1553
  if (this.isZodError(a))
1328
- throw new m(
1554
+ throw new E(
1329
1555
  "Failed to parse handler contract",
1330
- g.invalidContract(
1331
- s,
1556
+ w.invalidContract(
1557
+ o,
1332
1558
  "Failed to parse handler contract",
1333
1559
  t,
1334
1560
  a
1335
1561
  )
1336
1562
  );
1337
1563
  const c = a?.message ?? "Failed to register handler contract";
1338
- throw new m(
1564
+ throw new E(
1339
1565
  c,
1340
- g.illegalState(c)
1566
+ w.illegalState(c)
1341
1567
  );
1342
1568
  }
1343
1569
  }
@@ -1347,94 +1573,114 @@ class Nn {
1347
1573
  scopeContracts: n,
1348
1574
  handlerKey: r
1349
1575
  }) {
1350
- let s = typeof e.channel == "string" ? e.channel.trim() : null;
1351
- if (s && s.length === 0 && (s = null), !s) {
1352
- const o = t.deriveChannel?.call(t, e, {
1576
+ let o = typeof e.channel == "string" ? e.channel.trim() : null;
1577
+ if (o && o.length === 0 && (o = null), !o) {
1578
+ const s = t.deriveChannel?.call(t, e, {
1353
1579
  blue: this.blue,
1354
1580
  scopeContracts: n
1355
1581
  }) ?? null;
1356
- if (typeof o == "string") {
1357
- const a = o.trim();
1358
- a.length > 0 && (s = a);
1582
+ if (typeof s == "string") {
1583
+ const a = s.trim();
1584
+ a.length > 0 && (o = a);
1359
1585
  }
1360
1586
  }
1361
- if (!s)
1362
- throw new m(
1587
+ if (!o)
1588
+ throw new E(
1363
1589
  `Handler ${r} must declare channel (missing explicit channel and derivation failed)`,
1364
- g.illegalState(
1590
+ w.illegalState(
1365
1591
  `Handler ${r} must declare channel (missing explicit channel and derivation failed)`
1366
1592
  )
1367
1593
  );
1368
- return s;
1594
+ return o;
1369
1595
  }
1370
1596
  isRegisteredChannel(e) {
1371
1597
  return this.builtinChannelSchemas.has(e) ? !0 : this.registry.lookupChannel(e) != null;
1372
1598
  }
1373
1599
  isZodError(e) {
1374
- return e instanceof Te;
1600
+ return e instanceof xe;
1375
1601
  }
1376
1602
  }
1377
- class F extends Error {
1603
+ class K extends Error {
1378
1604
  constructor(e) {
1379
1605
  super(e ?? "MustUnderstand failure"), this.name = "MustUnderstandFailure";
1380
1606
  }
1381
1607
  }
1382
- const Mn = p["Document Update Channel"], An = p["Embedded Node Channel"], On = p["Lifecycle Event Channel"], Dn = p["Triggered Event Channel"], Se = p["Process Embedded"], Bn = p["Processing Initialized Marker"], Ln = p["Processing Terminated Marker"], _n = p["Channel Event Checkpoint"], Ce = /* @__PURE__ */ new Map([
1608
+ const Xn = p["Core/Document Update Channel"], Zn = p["Core/Embedded Node Channel"], er = p["Core/Lifecycle Event Channel"], tr = p["Core/Triggered Event Channel"], Ne = p["Core/Process Embedded"], nr = p["Core/Processing Initialized Marker"], rr = p["Core/Processing Terminated Marker"], ir = p["Core/Channel Event Checkpoint"], or = b["MyOS/Document Anchors"], sr = b["MyOS/Document Links"], ar = b["MyOS/MyOS Participants Orchestration"], cr = b["MyOS/MyOS Session Interaction"], lr = b["MyOS/MyOS Worker Agency"], Oe = /* @__PURE__ */ new Map([
1383
1609
  [
1384
- Mn,
1385
- jt
1610
+ Xn,
1611
+ Vt
1386
1612
  ],
1387
1613
  [
1388
- An,
1389
- Jt
1614
+ Zn,
1615
+ Kt
1390
1616
  ],
1391
1617
  [
1392
- On,
1393
- Qt
1618
+ er,
1619
+ jt
1394
1620
  ],
1395
1621
  [
1396
- Dn,
1397
- Yt
1622
+ tr,
1623
+ Gt
1398
1624
  ]
1399
- ]), $n = /* @__PURE__ */ new Map([
1625
+ ]), ur = /* @__PURE__ */ new Map([
1400
1626
  [
1401
- Bn,
1402
- tn
1627
+ nr,
1628
+ nn
1403
1629
  ],
1404
1630
  [
1405
- Ln,
1406
- rn
1631
+ rr,
1632
+ an
1407
1633
  ],
1408
1634
  [
1409
- _n,
1635
+ ir,
1410
1636
  en
1637
+ ],
1638
+ [
1639
+ or,
1640
+ dn
1641
+ ],
1642
+ [
1643
+ sr,
1644
+ fn
1645
+ ],
1646
+ [
1647
+ ar,
1648
+ gn
1649
+ ],
1650
+ [
1651
+ cr,
1652
+ En
1653
+ ],
1654
+ [
1655
+ lr,
1656
+ Cn
1411
1657
  ]
1412
1658
  ]);
1413
- class xn {
1659
+ class dr {
1414
1660
  constructor(e, t) {
1415
- this.registry = e, this.blue = t, this.handlerRegistration = new Nn(
1661
+ this.registry = e, this.blue = t, this.handlerRegistration = new Yn(
1416
1662
  this.blue,
1417
1663
  this.registry,
1418
- Ce
1664
+ Oe
1419
1665
  );
1420
1666
  }
1421
1667
  handlerRegistration;
1422
1668
  load(e, t) {
1423
1669
  try {
1424
- const n = M.builder(), r = e.getContracts();
1670
+ const n = L.builder(), r = e.getContracts();
1425
1671
  if (!r)
1426
1672
  return n.build();
1427
- const s = this.buildScopeContractsIndex(r);
1428
- for (const [o, a] of Object.entries(r))
1429
- a && this.processContract(n, o, a, s);
1673
+ const o = this.buildScopeContractsIndex(r);
1674
+ for (const [s, a] of Object.entries(r))
1675
+ a && this.processContract(n, s, a, o);
1430
1676
  return n.build();
1431
1677
  } catch (n) {
1432
- if (n instanceof F || n instanceof m)
1678
+ if (n instanceof K || n instanceof E)
1433
1679
  throw n;
1434
1680
  const r = n?.message ?? "Failed to load contracts";
1435
- throw new m(
1681
+ throw new E(
1436
1682
  `Failed to load contracts for scope ${t}: ${r}`,
1437
- g.runtimeFatal(
1683
+ w.runtimeFatal(
1438
1684
  `Failed to load contracts for scope ${t}`,
1439
1685
  n
1440
1686
  )
@@ -1442,131 +1688,131 @@ class xn {
1442
1688
  }
1443
1689
  }
1444
1690
  processContract(e, t, n, r) {
1445
- const s = n.getType()?.getBlueId();
1446
- if (!s)
1691
+ const o = n.getType()?.getBlueId();
1692
+ if (!o)
1447
1693
  return;
1448
- if (s === Se) {
1694
+ if (o === Ne) {
1449
1695
  this.handleProcessEmbedded(e, t, n);
1450
1696
  return;
1451
1697
  }
1452
- const o = $n.get(s);
1453
- if (o) {
1454
- this.handleMarker(e, t, n, o, s);
1698
+ const s = ur.get(o);
1699
+ if (s) {
1700
+ this.handleMarker(e, t, n, s, o);
1455
1701
  return;
1456
1702
  }
1457
- const a = Ce.get(s);
1703
+ const a = Oe.get(o);
1458
1704
  if (a) {
1459
- this.handleChannel(e, t, n, a, s);
1705
+ this.handleChannel(e, t, n, a, o);
1460
1706
  return;
1461
1707
  }
1462
- const c = this.registry.lookupChannel(s);
1708
+ const c = this.registry.lookupChannel(o);
1463
1709
  if (c) {
1464
1710
  this.handleChannel(
1465
1711
  e,
1466
1712
  t,
1467
1713
  n,
1468
1714
  c.schema,
1469
- s
1715
+ o
1470
1716
  );
1471
1717
  return;
1472
1718
  }
1473
- const l = this.registry.lookupHandler(s);
1474
- if (l) {
1719
+ const u = this.registry.lookupHandler(o);
1720
+ if (u) {
1475
1721
  this.handlerRegistration.register({
1476
1722
  builder: e,
1477
1723
  key: t,
1478
1724
  node: n,
1479
- processor: l,
1480
- blueId: s,
1725
+ processor: u,
1726
+ blueId: o,
1481
1727
  scopeContracts: r
1482
1728
  });
1483
1729
  return;
1484
1730
  }
1485
- const u = this.registry.lookupMarker(s);
1486
- if (u) {
1731
+ const d = this.registry.lookupMarker(o);
1732
+ if (d) {
1487
1733
  this.handleMarker(
1488
1734
  e,
1489
1735
  t,
1490
1736
  n,
1491
- u.schema,
1492
- s
1737
+ d.schema,
1738
+ o
1493
1739
  );
1494
1740
  return;
1495
1741
  }
1496
- throw se(s) ? new m(
1742
+ throw he(o) ? new E(
1497
1743
  "Built-in processor-managed channel is missing schema registration",
1498
- g.invalidContract(
1499
- s,
1744
+ w.invalidContract(
1745
+ o,
1500
1746
  "Built-in processor-managed channel is missing schema registration",
1501
1747
  t
1502
1748
  )
1503
- ) : new F(`Unsupported contract type: ${s}`);
1749
+ ) : new K(`Unsupported contract type: ${o}`);
1504
1750
  }
1505
1751
  handleProcessEmbedded(e, t, n) {
1506
1752
  try {
1507
1753
  const r = this.convert(
1508
1754
  n,
1509
- nn
1755
+ on
1510
1756
  );
1511
1757
  e.setEmbedded(r);
1512
1758
  } catch (r) {
1513
- throw Z(r) ? new m(
1759
+ throw oe(r) ? new E(
1514
1760
  "Failed to parse ProcessEmbedded marker",
1515
- g.invalidContract(
1516
- Se,
1761
+ w.invalidContract(
1762
+ Ne,
1517
1763
  "Failed to parse ProcessEmbedded marker",
1518
1764
  t,
1519
1765
  r
1520
1766
  )
1521
- ) : new m(
1767
+ ) : new E(
1522
1768
  r?.message ?? "Failed to register ProcessEmbedded marker",
1523
- g.illegalState(
1769
+ w.illegalState(
1524
1770
  r?.message ?? "Failed to register ProcessEmbedded marker"
1525
1771
  )
1526
1772
  );
1527
1773
  }
1528
1774
  }
1529
- handleChannel(e, t, n, r, s) {
1775
+ handleChannel(e, t, n, r, o) {
1530
1776
  try {
1531
- const o = this.convert(n, r);
1532
- e.addChannel(t, o, s);
1533
- } catch (o) {
1534
- if (Z(o))
1535
- throw new m(
1777
+ const s = this.convert(n, r);
1778
+ e.addChannel(t, s, o);
1779
+ } catch (s) {
1780
+ if (oe(s))
1781
+ throw new E(
1536
1782
  "Failed to parse channel contract",
1537
- g.invalidContract(
1538
- s,
1783
+ w.invalidContract(
1784
+ o,
1539
1785
  "Failed to parse channel contract",
1540
1786
  t,
1541
- o
1787
+ s
1542
1788
  )
1543
1789
  );
1544
- const a = o?.message ?? "Failed to register channel contract";
1545
- throw new m(
1790
+ const a = s?.message ?? "Failed to register channel contract";
1791
+ throw new E(
1546
1792
  a,
1547
- g.illegalState(a)
1793
+ w.illegalState(a)
1548
1794
  );
1549
1795
  }
1550
1796
  }
1551
- handleMarker(e, t, n, r, s) {
1797
+ handleMarker(e, t, n, r, o) {
1552
1798
  try {
1553
- const o = this.convert(n, r);
1554
- e.addMarker(t, o, s);
1555
- } catch (o) {
1556
- if (Z(o))
1557
- throw new m(
1799
+ const s = this.convert(n, r);
1800
+ e.addMarker(t, s, o);
1801
+ } catch (s) {
1802
+ if (oe(s))
1803
+ throw new E(
1558
1804
  "Failed to parse marker contract",
1559
- g.invalidContract(
1560
- s,
1805
+ w.invalidContract(
1806
+ o,
1561
1807
  "Failed to parse marker contract",
1562
1808
  t,
1563
- o
1809
+ s
1564
1810
  )
1565
1811
  );
1566
- const a = o?.message ?? "Failed to register marker contract";
1567
- throw new m(
1812
+ const a = s?.message ?? "Failed to register marker contract";
1813
+ throw new E(
1568
1814
  a,
1569
- g.illegalState(a)
1815
+ w.illegalState(a)
1570
1816
  );
1571
1817
  }
1572
1818
  }
@@ -1575,8 +1821,8 @@ class xn {
1575
1821
  for (const [n, r] of Object.entries(e)) {
1576
1822
  if (!r)
1577
1823
  continue;
1578
- const s = r.getType()?.getBlueId();
1579
- typeof s == "string" && s.trim().length > 0 && t.set(n, { node: r, nodeTypeBlueId: s });
1824
+ const o = r.getType()?.getBlueId();
1825
+ typeof o == "string" && o.trim().length > 0 && t.set(n, { node: r, nodeTypeBlueId: o });
1580
1826
  }
1581
1827
  return t;
1582
1828
  }
@@ -1584,29 +1830,29 @@ class xn {
1584
1830
  return this.blue.nodeToSchemaOutput(e, t);
1585
1831
  }
1586
1832
  }
1587
- function Z(i) {
1588
- return i instanceof Te;
1833
+ function oe(i) {
1834
+ return i instanceof xe;
1589
1835
  }
1590
- const Fn = p["Channel Event Checkpoint"];
1591
- function zn(i) {
1836
+ const hr = p["Core/Channel Event Checkpoint"];
1837
+ function pr(i) {
1592
1838
  return i.jsonValueToNode({
1593
- type: { blueId: Fn },
1839
+ type: { blueId: hr },
1594
1840
  lastEvents: {},
1595
1841
  lastSignatures: {}
1596
1842
  });
1597
1843
  }
1598
- function Hn() {
1844
+ function fr() {
1599
1845
  return {
1600
1846
  lastEvents: {},
1601
1847
  lastSignatures: {}
1602
1848
  };
1603
1849
  }
1604
- function ke(i) {
1850
+ function Ae(i) {
1605
1851
  return i != null && Object.prototype.hasOwnProperty.call(i, "lastEvents") && Object.prototype.hasOwnProperty.call(i, "lastSignatures");
1606
1852
  }
1607
- class Un {
1608
- constructor(e, t, n, r, s) {
1609
- this.markerKey = e, this.checkpoint = t, this.channelKey = n, this.lastEventNode = r, this.lastEventSignature = s;
1853
+ class mr {
1854
+ constructor(e, t, n, r, o) {
1855
+ this.markerKey = e, this.checkpoint = t, this.channelKey = n, this.lastEventNode = r, this.lastEventSignature = o;
1610
1856
  }
1611
1857
  lastEventNode;
1612
1858
  lastEventSignature;
@@ -1614,32 +1860,32 @@ class Un {
1614
1860
  return e != null && e === this.lastEventSignature;
1615
1861
  }
1616
1862
  }
1617
- class Vn {
1863
+ class gr {
1618
1864
  constructor(e, t) {
1619
1865
  this.runtime = e, this.signatureFn = t;
1620
1866
  }
1621
1867
  ensureCheckpointMarker(e, t) {
1622
- const n = t.marker(I), r = w(e, Be);
1868
+ const n = t.marker(N), r = k(e, Ve);
1623
1869
  if (!n) {
1624
- const s = zn(this.runtime.blue());
1625
- this.runtime.directWrite(r, s), t.registerCheckpointMarker(Hn());
1870
+ const o = pr(this.runtime.blue());
1871
+ this.runtime.directWrite(r, o), t.registerCheckpointMarker(fr());
1626
1872
  return;
1627
1873
  }
1628
- if (!ke(n))
1874
+ if (!Ae(n))
1629
1875
  throw new Error(
1630
1876
  `Reserved key 'checkpoint' must contain a Channel Event Checkpoint at ${r}`
1631
1877
  );
1632
1878
  }
1633
1879
  findCheckpoint(e, t) {
1634
1880
  for (const [n, r] of e.markerEntries()) {
1635
- if (!ke(r))
1881
+ if (!Ae(r))
1636
1882
  continue;
1637
- const o = (r.lastEvents?.[t] ?? null)?.clone() ?? null, c = r.lastSignatures?.[t] ?? null ?? this.signatureFn(o);
1638
- return new Un(
1883
+ const s = (r.lastEvents?.[t] ?? null)?.clone() ?? null, c = r.lastSignatures?.[t] ?? null ?? this.signatureFn(s);
1884
+ return new mr(
1639
1885
  n,
1640
1886
  r,
1641
1887
  t,
1642
- o,
1888
+ s,
1643
1889
  c
1644
1890
  );
1645
1891
  }
@@ -1648,22 +1894,22 @@ class Vn {
1648
1894
  isDuplicate(e, t) {
1649
1895
  return e != null && e.matches(t);
1650
1896
  }
1651
- persist(e, t, n, r, s) {
1897
+ persist(e, t, n, r, o) {
1652
1898
  if (!n)
1653
1899
  return;
1654
- const o = w(
1900
+ const s = k(
1655
1901
  e,
1656
- $e(n.markerKey, n.channelKey)
1657
- ), a = s?.clone() ?? null;
1658
- this.runtime.gasMeter().chargeCheckpointUpdate(), this.runtime.directWrite(o, a), n.checkpoint.lastEvents || (n.checkpoint.lastEvents = {}), a ? n.checkpoint.lastEvents[n.channelKey] = a.clone() ?? null : delete n.checkpoint.lastEvents[n.channelKey], n.lastEventNode = a?.clone() ?? null;
1659
- const c = w(
1902
+ qe(n.markerKey, n.channelKey)
1903
+ ), a = o?.clone() ?? null;
1904
+ this.runtime.gasMeter().chargeCheckpointUpdate(), this.runtime.directWrite(s, a), n.checkpoint.lastEvents || (n.checkpoint.lastEvents = {}), a ? n.checkpoint.lastEvents[n.channelKey] = a.clone() ?? null : delete n.checkpoint.lastEvents[n.channelKey], n.lastEventNode = a?.clone() ?? null;
1905
+ const c = k(
1660
1906
  e,
1661
- xe(n.markerKey, n.channelKey)
1662
- ), l = r == null ? null : new d().setValue(r);
1663
- this.runtime.directWrite(c, l), n.checkpoint.lastSignatures || (n.checkpoint.lastSignatures = {}), r == null ? delete n.checkpoint.lastSignatures[n.channelKey] : n.checkpoint.lastSignatures[n.channelKey] = r, n.lastEventSignature = r ?? null;
1907
+ je(n.markerKey, n.channelKey)
1908
+ ), u = r == null ? null : new h().setValue(r);
1909
+ this.runtime.directWrite(c, u), n.checkpoint.lastSignatures || (n.checkpoint.lastSignatures = {}), r == null ? delete n.checkpoint.lastSignatures[n.channelKey] : n.checkpoint.lastSignatures[n.channelKey] = r, n.lastEventSignature = r ?? null;
1664
1910
  }
1665
1911
  }
1666
- class Kn {
1912
+ class yr {
1667
1913
  constructor(e, t, n) {
1668
1914
  this.runtime = e, this.checkpointManager = t, this.deps = n;
1669
1915
  }
@@ -1671,7 +1917,7 @@ class Kn {
1671
1917
  if (this.deps.isScopeInactive(e))
1672
1918
  return;
1673
1919
  this.runtime.gasMeter().chargeChannelMatchAttempt();
1674
- const s = await this.deps.evaluateChannel(
1920
+ const o = r, s = await this.deps.evaluateChannel(
1675
1921
  n,
1676
1922
  t,
1677
1923
  e,
@@ -1679,42 +1925,48 @@ class Kn {
1679
1925
  );
1680
1926
  if (!s.matches)
1681
1927
  return;
1682
- const o = s.eventNode ?? r, a = r;
1928
+ const a = s.eventNode ?? r;
1683
1929
  this.checkpointManager.ensureCheckpointMarker(e, t);
1684
1930
  const c = this.checkpointManager.findCheckpoint(
1685
1931
  t,
1686
1932
  n.key()
1687
- ), l = s.eventId ?? this.deps.canonicalSignature(a);
1688
- this.checkpointManager.isDuplicate(c, l) || (await this.runHandlers(
1933
+ ), u = s.eventId ?? this.deps.canonicalSignature(o);
1934
+ this.checkpointManager.isDuplicate(c, u) || !await this.shouldProcessRelativeToCheckpoint(
1689
1935
  e,
1690
1936
  t,
1691
- n.key(),
1937
+ n,
1692
1938
  o,
1939
+ c
1940
+ ) || (await this.runHandlers(
1941
+ e,
1942
+ t,
1943
+ n.key(),
1944
+ a,
1693
1945
  !1
1694
1946
  ), !this.deps.isScopeInactive(e) && this.checkpointManager.persist(
1695
1947
  e,
1696
1948
  t,
1697
1949
  c,
1698
- l ?? null,
1699
- a
1950
+ u ?? null,
1951
+ o
1700
1952
  ));
1701
1953
  }
1702
- async runHandlers(e, t, n, r, s) {
1703
- const o = t.handlersFor(n);
1704
- if (o.length !== 0)
1705
- for (const a of o) {
1706
- if (!s && this.deps.isScopeInactive(e))
1954
+ async runHandlers(e, t, n, r, o) {
1955
+ const s = t.handlersFor(n);
1956
+ if (s.length !== 0)
1957
+ for (const a of s) {
1958
+ if (!o && this.deps.isScopeInactive(e))
1707
1959
  break;
1708
1960
  try {
1709
1961
  const c = this.deps.createContext(
1710
1962
  e,
1711
1963
  t,
1712
1964
  r,
1713
- s
1965
+ o
1714
1966
  );
1715
1967
  if (!await this.deps.shouldRunHandler(a, c))
1716
1968
  continue;
1717
- if (this.runtime.gasMeter().chargeHandlerOverhead(), await this.deps.executeHandler(a, c), !s && this.deps.isScopeInactive(e))
1969
+ if (this.runtime.gasMeter().chargeHandlerOverhead(), await this.deps.executeHandler(a, c), !o && this.deps.isScopeInactive(e))
1718
1970
  break;
1719
1971
  } catch (c) {
1720
1972
  await this.deps.handleHandlerError(e, t, c);
@@ -1722,19 +1974,41 @@ class Kn {
1722
1974
  }
1723
1975
  }
1724
1976
  }
1977
+ async shouldProcessRelativeToCheckpoint(e, t, n, r, o) {
1978
+ if (!o?.lastEventNode)
1979
+ return !0;
1980
+ const s = this.deps.channelProcessorFor(n.blueId());
1981
+ if (!s || typeof s.isNewerEvent != "function")
1982
+ return !0;
1983
+ const a = {
1984
+ scopePath: e,
1985
+ blue: this.runtime.blue(),
1986
+ event: r.clone(),
1987
+ markers: t.markers(),
1988
+ bindingKey: n.key()
1989
+ };
1990
+ return await s.isNewerEvent(
1991
+ n.contract(),
1992
+ a,
1993
+ o.lastEventNode.clone()
1994
+ );
1995
+ }
1725
1996
  }
1726
- class N extends m {
1997
+ function Er(i, e) {
1998
+ return e.isResolved() ? i.createResolvedNode(e) : i.resolve(e);
1999
+ }
2000
+ class B extends E {
1727
2001
  constructor(e) {
1728
- super(e, g.illegalState(e)), this.name = "IllegalStateException";
2002
+ super(e, w.illegalState(e)), this.name = "IllegalStateException";
1729
2003
  }
1730
2004
  }
1731
- class T extends Error {
2005
+ class A extends Error {
1732
2006
  constructor(e) {
1733
2007
  super(e), this.name = "BoundaryViolationException";
1734
2008
  }
1735
2009
  }
1736
- const Wn = p["Document Update Channel"], Gn = p["Embedded Node Channel"], qn = p["Triggered Event Channel"], jn = p["Lifecycle Event Channel"], Ie = p["Processing Initialized Marker"], Jn = p["Document Processing Initiated"];
1737
- class Qn {
2010
+ const wr = p["Core/Document Update Channel"], Cr = p["Core/Embedded Node Channel"], Sr = p["Core/Triggered Event Channel"], vr = p["Core/Lifecycle Event Channel"], De = p["Core/Processing Initialized Marker"], br = p["Core/Document Processing Initiated"];
2011
+ class kr {
1738
2012
  runtime;
1739
2013
  contractLoader;
1740
2014
  channelRunner;
@@ -1748,70 +2022,74 @@ class Qn {
1748
2022
  this.runtime = e.runtime, this.contractLoader = e.contractLoader, this.channelRunner = e.channelRunner, this.bundles = e.bundles, this.hooks = e.hooks, this.blueId = e.blueId, this.nodeAt = e.nodeAt, this.createDocumentUpdateEvent = e.createDocumentUpdateEvent, this.matchesDocumentUpdate = e.matchesDocumentUpdate;
1749
2023
  }
1750
2024
  async initializeScope(e, t) {
1751
- const n = y(e), r = /* @__PURE__ */ new Set();
1752
- let s = null, o = null;
2025
+ const n = C(e), r = /* @__PURE__ */ new Set();
2026
+ let o = null, s = null;
1753
2027
  for (t && this.runtime.gasMeter().chargeScopeEntry(n); ; ) {
1754
- const h = this.nodeAt(n);
1755
- if (!h)
2028
+ const g = this.nodeAt(n);
2029
+ if (!g)
1756
2030
  return;
1757
- o || (o = h.clone()), s = this.loadBundle(h, n), this.bundles.set(n, s);
1758
- const f = s.embeddedPaths().find((Ze) => !r.has(Ze)) ?? null;
1759
- if (!f)
2031
+ s || (s = g.clone()), o = this.loadBundle(g, n), this.bundles.set(n, o);
2032
+ const m = o.embeddedPaths().find((re) => !r.has(re)) ?? null;
2033
+ if (!m)
1760
2034
  break;
1761
- r.add(f);
1762
- const E = w(n, f);
1763
- this.nodeAt(E) && await this.initializeScope(E, !0);
2035
+ r.add(m);
2036
+ const y = k(n, m);
2037
+ this.nodeAt(y) && await this.initializeScope(y, !0);
1764
2038
  }
1765
- if (!s)
2039
+ if (!o)
1766
2040
  return;
1767
2041
  const a = this.hasInitializationMarker(n);
1768
- if (!a && s.hasCheckpoint())
1769
- throw new N(
2042
+ if (!a && o.hasCheckpoint())
2043
+ throw new B(
1770
2044
  `Reserved key 'checkpoint' must not appear before initialization at scope ${n}`
1771
2045
  );
1772
2046
  if (a)
1773
2047
  return;
1774
2048
  this.runtime.gasMeter().chargeInitialization();
1775
- const c = this.blueId(o ?? new d()), l = this.createLifecycleEvent(c), u = this.hooks.createContext(
2049
+ const c = this.blueId(s ?? new h()), u = this.createLifecycleEvent(c), d = this.hooks.createContext(
1776
2050
  n,
1777
- s,
1778
- l,
2051
+ o,
2052
+ u,
1779
2053
  !1,
1780
2054
  !0
1781
2055
  );
1782
- await this.deliverLifecycle(n, s, l, !0), await this.addInitializationMarker(u, c);
2056
+ await this.deliverLifecycle(n, o, u, !0), await this.addInitializationMarker(d, c);
1783
2057
  }
1784
2058
  loadBundles(e) {
1785
- const t = y(e);
2059
+ const t = C(e);
1786
2060
  if (this.bundles.has(t))
1787
2061
  return;
1788
- const n = this.nodeAt(t), r = n ? this.loadBundle(n, t) : M.empty();
2062
+ const n = this.nodeAt(t), r = n ? this.loadBundle(n, t) : L.empty();
1789
2063
  this.bundles.set(t, r);
1790
- for (const s of r.embeddedPaths()) {
1791
- const o = w(t, s);
1792
- this.loadBundles(o);
2064
+ for (const o of r.embeddedPaths()) {
2065
+ const s = k(t, o);
2066
+ this.loadBundles(s);
1793
2067
  }
1794
2068
  }
1795
2069
  async processExternalEvent(e, t) {
1796
- const n = y(e);
2070
+ const n = Er(this.runtime.blue(), t);
2071
+ await this.processPreparedExternalEvent(e, n);
2072
+ }
2073
+ async processPreparedExternalEvent(e, t) {
2074
+ const n = C(e);
1797
2075
  if (this.hooks.isScopeInactive(n))
1798
2076
  return;
1799
2077
  this.runtime.gasMeter().chargeScopeEntry(n);
1800
2078
  const r = await this.processEmbeddedChildren(n, t);
1801
2079
  if (!r)
1802
2080
  return;
1803
- const s = r.channelsOfType();
1804
- if (s.length === 0) {
2081
+ const o = r.channelsOfType();
2082
+ if (o.length === 0) {
1805
2083
  this.finalizeScope(n, r);
1806
2084
  return;
1807
2085
  }
1808
- for (const o of s) {
2086
+ for (const s of o) {
1809
2087
  if (this.hooks.isScopeInactive(n))
1810
2088
  break;
1811
- se(o.blueId()) || await this.channelRunner.runExternalChannel(
2089
+ he(s.blueId()) || await this.channelRunner.runExternalChannel(
1812
2090
  n,
1813
2091
  r,
1814
- o,
2092
+ s,
1815
2093
  t
1816
2094
  );
1817
2095
  }
@@ -1826,13 +2104,13 @@ class Qn {
1826
2104
  n,
1827
2105
  r
1828
2106
  );
1829
- } catch (s) {
1830
- if (s instanceof T) {
1831
- const o = this.hooks.fatalReason(s, "Boundary violation");
1832
- await this.hooks.enterFatalTermination(e, t, o);
2107
+ } catch (o) {
2108
+ if (o instanceof A) {
2109
+ const s = this.hooks.fatalReason(o, "Boundary violation");
2110
+ await this.hooks.enterFatalTermination(e, t, s);
1833
2111
  return;
1834
2112
  }
1835
- throw s;
2113
+ throw o;
1836
2114
  }
1837
2115
  try {
1838
2116
  switch (n.op) {
@@ -1846,59 +2124,59 @@ class Qn {
1846
2124
  default:
1847
2125
  break;
1848
2126
  }
1849
- const s = this.runtime.applyPatch(e, n);
1850
- if (!s)
2127
+ const o = this.runtime.applyPatch(e, n);
2128
+ if (!o)
1851
2129
  return;
1852
- await this.markCutOffChildrenIfNeeded(e, t, s), this.runtime.gasMeter().chargeCascadeRouting(s.cascadeScopes.length);
1853
- for (const o of s.cascadeScopes) {
1854
- const a = this.bundles.get(o);
1855
- if (!a || this.hooks.isScopeInactive(o))
2130
+ await this.markCutOffChildrenIfNeeded(e, t, o), this.runtime.gasMeter().chargeCascadeRouting(o.cascadeScopes.length);
2131
+ for (const s of o.cascadeScopes) {
2132
+ const a = this.bundles.get(s);
2133
+ if (!a || this.hooks.isScopeInactive(s))
1856
2134
  continue;
1857
- const c = this.createDocumentUpdateEvent(s, o), l = a.channelsOfType(
1858
- Wn
2135
+ const c = this.createDocumentUpdateEvent(o, s), u = a.channelsOfType(
2136
+ wr
1859
2137
  );
1860
- for (const u of l) {
1861
- const h = u.contract();
2138
+ for (const d of u) {
2139
+ const g = d.contract();
1862
2140
  if (this.matchesDocumentUpdate(
1863
- o,
1864
- h.path ?? null,
1865
- s.path
2141
+ s,
2142
+ g.path ?? null,
2143
+ o.path
1866
2144
  ) && (await this.channelRunner.runHandlers(
1867
- o,
2145
+ s,
1868
2146
  a,
1869
- u.key(),
2147
+ d.key(),
1870
2148
  c,
1871
2149
  !1
1872
- ), this.hooks.isScopeInactive(o)))
2150
+ ), this.hooks.isScopeInactive(s)))
1873
2151
  break;
1874
2152
  }
1875
2153
  }
1876
- } catch (s) {
1877
- if (s instanceof T) {
1878
- const o = this.hooks.fatalReason(s, "Boundary violation");
1879
- await this.hooks.enterFatalTermination(e, t, o);
2154
+ } catch (o) {
2155
+ if (o instanceof A) {
2156
+ const s = this.hooks.fatalReason(o, "Boundary violation");
2157
+ await this.hooks.enterFatalTermination(e, t, s);
1880
2158
  return;
1881
2159
  }
1882
- if (s instanceof N || s instanceof Error && !(s instanceof m)) {
1883
- const o = this.hooks.fatalReason(s, "Runtime fatal");
1884
- await this.hooks.enterFatalTermination(e, t, o);
2160
+ if (o instanceof B || o instanceof Error && !(o instanceof E)) {
2161
+ const s = this.hooks.fatalReason(o, "Runtime fatal");
2162
+ await this.hooks.enterFatalTermination(e, t, s);
1885
2163
  return;
1886
2164
  }
1887
- throw s;
2165
+ throw o;
1888
2166
  }
1889
2167
  }
1890
2168
  }
1891
2169
  async deliverLifecycle(e, t, n, r) {
1892
2170
  if (this.runtime.gasMeter().chargeLifecycleDelivery(), await this.hooks.recordLifecycleForBridging(e, n), !t)
1893
2171
  return;
1894
- const s = t.channelsOfType(
1895
- jn
2172
+ const o = t.channelsOfType(
2173
+ vr
1896
2174
  );
1897
- for (const o of s)
2175
+ for (const s of o)
1898
2176
  if (await this.channelRunner.runHandlers(
1899
2177
  e,
1900
2178
  t,
1901
- o.key(),
2179
+ s.key(),
1902
2180
  n,
1903
2181
  !0
1904
2182
  ), this.hooks.isScopeInactive(e))
@@ -1906,24 +2184,24 @@ class Qn {
1906
2184
  r && await this.finalizeScope(e, t);
1907
2185
  }
1908
2186
  async processEmbeddedChildren(e, t) {
1909
- const n = y(e), r = /* @__PURE__ */ new Set();
1910
- let s = this.refreshBundle(n);
1911
- for (; s; ) {
1912
- const o = this.nextEmbeddedPath(s, r);
1913
- if (!o)
1914
- return s;
1915
- r.add(o);
1916
- const a = w(n, o);
2187
+ const n = C(e), r = /* @__PURE__ */ new Set();
2188
+ let o = this.refreshBundle(n);
2189
+ for (; o; ) {
2190
+ const s = this.nextEmbeddedPath(o, r);
2191
+ if (!s)
2192
+ return o;
2193
+ r.add(s);
2194
+ const a = k(n, s);
1917
2195
  if (a === n || this.hooks.isScopeInactive(a)) {
1918
- s = this.refreshBundle(n);
2196
+ o = this.refreshBundle(n);
1919
2197
  continue;
1920
2198
  }
1921
- this.nodeAt(a) && (await this.initializeScope(a, !1), await this.processExternalEvent(a, t)), s = this.refreshBundle(n);
2199
+ this.nodeAt(a) && (await this.initializeScope(a, !1), await this.processPreparedExternalEvent(a, t)), o = this.refreshBundle(n);
1922
2200
  }
1923
2201
  return null;
1924
2202
  }
1925
2203
  refreshBundle(e) {
1926
- const t = y(e), n = this.nodeAt(t);
2204
+ const t = C(e), n = this.nodeAt(t);
1927
2205
  if (!n)
1928
2206
  return this.bundles.delete(t), null;
1929
2207
  const r = this.loadBundle(n, t);
@@ -1941,12 +2219,12 @@ class Qn {
1941
2219
  try {
1942
2220
  return this.contractLoader.load(e, t);
1943
2221
  } catch (n) {
1944
- if (n instanceof m || n instanceof F)
2222
+ if (n instanceof E || n instanceof K)
1945
2223
  throw n;
1946
2224
  const r = n?.message ?? "Failed to load contracts";
1947
- throw new m(
2225
+ throw new E(
1948
2226
  r,
1949
- g.runtimeFatal(
2227
+ w.runtimeFatal(
1950
2228
  `Failed to load contracts for scope ${t}`,
1951
2229
  n
1952
2230
  )
@@ -1954,7 +2232,7 @@ class Qn {
1954
2232
  }
1955
2233
  }
1956
2234
  async addInitializationMarker(e, t) {
1957
- const n = new d().setType(new d().setBlueId(Ie)).addProperty("documentId", new d().setValue(t)), r = e.resolvePointer(ne);
2235
+ const n = new h().setType(new h().setBlueId(De)).addProperty("documentId", new h().setValue(t)), r = e.resolvePointer(ce);
1958
2236
  await e.applyPatch({
1959
2237
  op: "ADD",
1960
2238
  path: r,
@@ -1968,20 +2246,20 @@ class Qn {
1968
2246
  if (this.hooks.isScopeInactive(e) || t.embeddedPaths().length === 0)
1969
2247
  return;
1970
2248
  const n = t.channelsOfType(
1971
- Gn
2249
+ Cr
1972
2250
  );
1973
2251
  if (n.length !== 0)
1974
2252
  for (const r of t.embeddedPaths()) {
1975
- const s = w(e, r), a = this.runtime.scope(s).drainBridgeableEvents();
2253
+ const o = k(e, r), a = this.runtime.scope(o).drainBridgeableEvents();
1976
2254
  if (a.length !== 0)
1977
2255
  for (const c of a) {
1978
- let l = !1;
1979
- for (const u of n) {
1980
- const f = u.contract().childPath ?? "/";
1981
- w(e, f) === s && (l || (this.runtime.gasMeter().chargeBridge(), l = !0), await this.channelRunner.runHandlers(
2256
+ let u = !1;
2257
+ for (const d of n) {
2258
+ const m = d.contract().childPath ?? "/";
2259
+ k(e, m) === o && (u || (this.runtime.gasMeter().chargeBridge(), u = !0), await this.channelRunner.runHandlers(
1982
2260
  e,
1983
2261
  t,
1984
- u.key(),
2262
+ d.key(),
1985
2263
  c.clone(),
1986
2264
  !1
1987
2265
  ));
@@ -1993,18 +2271,18 @@ class Qn {
1993
2271
  if (this.hooks.isScopeInactive(e))
1994
2272
  return;
1995
2273
  const n = this.runtime.scope(e), r = t.channelsOfType(
1996
- qn
2274
+ Sr
1997
2275
  );
1998
2276
  if (r.length === 0) {
1999
2277
  n.clearTriggered();
2000
2278
  return;
2001
2279
  }
2002
2280
  for (; !n.triggeredIsEmpty(); ) {
2003
- const s = n.pollTriggered();
2004
- if (!s)
2281
+ const o = n.pollTriggered();
2282
+ if (!o)
2005
2283
  break;
2006
2284
  this.runtime.gasMeter().chargeDrainEvent();
2007
- for (const o of r) {
2285
+ for (const s of r) {
2008
2286
  if (this.hooks.isScopeInactive(e)) {
2009
2287
  n.clearTriggered();
2010
2288
  return;
@@ -2012,8 +2290,8 @@ class Qn {
2012
2290
  if (await this.channelRunner.runHandlers(
2013
2291
  e,
2014
2292
  t,
2015
- o.key(),
2016
- s.clone(),
2293
+ s.key(),
2294
+ o.clone(),
2017
2295
  !1
2018
2296
  ), this.hooks.isScopeInactive(e)) {
2019
2297
  n.clearTriggered();
@@ -2023,185 +2301,185 @@ class Qn {
2023
2301
  }
2024
2302
  }
2025
2303
  validatePatchBoundary(e, t, n) {
2026
- const r = y(e), s = b(n.path);
2027
- if (s === r)
2028
- throw new T(
2304
+ const r = C(e), o = T(n.path);
2305
+ if (o === r)
2306
+ throw new A(
2029
2307
  `Self-root mutation is forbidden at scope ${r}`
2030
2308
  );
2031
- if (r !== "/" && !s.startsWith(`${r}/`))
2032
- throw new T(
2033
- `Patch path ${s} is outside scope ${r}`
2309
+ if (r !== "/" && !o.startsWith(`${r}/`))
2310
+ throw new A(
2311
+ `Patch path ${o} is outside scope ${r}`
2034
2312
  );
2035
- for (const o of t.embeddedPaths()) {
2036
- const a = w(r, o);
2037
- if (s.startsWith(`${a}/`))
2038
- throw new T(
2039
- `Boundary violation: patch ${s} enters embedded scope ${a}`
2313
+ for (const s of t.embeddedPaths()) {
2314
+ const a = k(r, s);
2315
+ if (o.startsWith(`${a}/`))
2316
+ throw new A(
2317
+ `Boundary violation: patch ${o} enters embedded scope ${a}`
2040
2318
  );
2041
2319
  }
2042
2320
  }
2043
2321
  enforceReservedKeyWriteProtection(e, t, n) {
2044
2322
  if (n)
2045
2323
  return;
2046
- const r = y(e), s = b(t.path);
2047
- for (const o of ie) {
2048
- const a = w(
2324
+ const r = C(e), o = T(t.path);
2325
+ for (const s of de) {
2326
+ const a = k(
2049
2327
  r,
2050
- J(o)
2328
+ Z(s)
2051
2329
  );
2052
- if (s === a || s.startsWith(`${a}/`))
2053
- throw new T(
2054
- `Reserved key '${o}' is write-protected at ${a}`
2330
+ if (o === a || o.startsWith(`${a}/`))
2331
+ throw new A(
2332
+ `Reserved key '${s}' is write-protected at ${a}`
2055
2333
  );
2056
2334
  }
2057
2335
  }
2058
2336
  async markCutOffChildrenIfNeeded(e, t, n) {
2059
2337
  if (t.embeddedPaths().length === 0)
2060
2338
  return;
2061
- const r = b(n.path);
2062
- for (const s of t.embeddedPaths()) {
2063
- const o = w(e, s);
2064
- r === o && (n.op === "remove" || n.op === "replace") && await this.hooks.markCutOff(o);
2339
+ const r = T(n.path);
2340
+ for (const o of t.embeddedPaths()) {
2341
+ const s = k(e, o);
2342
+ r === s && (n.op === "remove" || n.op === "replace") && await this.hooks.markCutOff(s);
2065
2343
  }
2066
2344
  }
2067
2345
  hasInitializationMarker(e) {
2068
- const t = w(e, ne), n = this.nodeAt(t);
2346
+ const t = k(e, ce), n = this.nodeAt(t);
2069
2347
  if (!n)
2070
2348
  return !1;
2071
- if (!(n instanceof d)) {
2072
- const s = `Reserved key 'initialized' must contain a Processing Initialized Marker at ${t}`;
2073
- throw new N(s);
2349
+ if (!(n instanceof h)) {
2350
+ const o = `Reserved key 'initialized' must contain a Processing Initialized Marker at ${t}`;
2351
+ throw new B(o);
2074
2352
  }
2075
- if (n.getType()?.getBlueId() !== Ie) {
2076
- const s = `Reserved key 'initialized' must contain a Processing Initialized Marker at ${t}`;
2077
- throw new N(s);
2353
+ if (n.getType()?.getBlueId() !== De) {
2354
+ const o = `Reserved key 'initialized' must contain a Processing Initialized Marker at ${t}`;
2355
+ throw new B(o);
2078
2356
  }
2079
2357
  return !0;
2080
2358
  }
2081
2359
  createLifecycleEvent(e) {
2082
- return new d().setType(new d().setBlueId(Jn)).setProperties({
2083
- type: new d().setValue("Document Processing Initiated"),
2084
- documentId: new d().setValue(e)
2360
+ return new h().setType(new h().setBlueId(br)).setProperties({
2361
+ type: new h().setValue("Core/Document Processing Initiated"),
2362
+ documentId: new h().setValue(e)
2085
2363
  });
2086
2364
  }
2087
2365
  }
2088
- class q extends Error {
2366
+ class Y extends Error {
2089
2367
  constructor(e) {
2090
2368
  super(
2091
2369
  e ? "Processing terminated due to fatal error" : "Processing terminated"
2092
2370
  ), this.fatal = e, this.name = "RunTerminationError";
2093
2371
  }
2094
2372
  }
2095
- const Yn = p["Processing Terminated Marker"], Zn = p["Document Processing Terminated"];
2096
- class Xn {
2373
+ const Tr = p["Core/Processing Terminated Marker"], Ir = p["Core/Document Processing Terminated"];
2374
+ class Rr {
2097
2375
  constructor(e) {
2098
2376
  this.runtime = e;
2099
2377
  }
2100
- async terminateScope(e, t, n, r, s) {
2101
- e.recordPendingTermination(t, r, s ?? null);
2102
- const o = e.normalizeScope(t), a = w(o, De);
2378
+ async terminateScope(e, t, n, r, o) {
2379
+ e.recordPendingTermination(t, r, o ?? null);
2380
+ const s = e.normalizeScope(t), a = k(s, He);
2103
2381
  this.runtime.directWrite(
2104
2382
  a,
2105
- er(this.runtime.blue(), r, s)
2383
+ Pr(this.runtime.blue(), r, o)
2106
2384
  ), this.runtime.gasMeter().chargeTerminationMarker();
2107
- const c = n ?? e.bundleForScope(o) ?? null, l = tr(r, s);
2385
+ const c = n ?? e.bundleForScope(s) ?? null, u = Mr(r, o);
2108
2386
  if (await e.deliverLifecycle(
2109
- o,
2387
+ s,
2110
2388
  c,
2111
- l,
2389
+ u,
2112
2390
  !1
2113
- ), this.runtime.scope(o).finalizeTermination(r, s ?? null), e.clearPendingTermination(t), r === "FATAL" && this.runtime.gasMeter().chargeFatalTerminationOverhead(), r === "FATAL" && o === "/")
2114
- throw this.runtime.markRunTerminated(), new q(!0);
2115
- if (r === "GRACEFUL" && o === "/")
2116
- throw this.runtime.markRunTerminated(), new q(!1);
2391
+ ), this.runtime.scope(s).finalizeTermination(r, o ?? null), e.clearPendingTermination(t), r === "FATAL" && this.runtime.gasMeter().chargeFatalTerminationOverhead(), r === "FATAL" && s === "/")
2392
+ throw this.runtime.markRunTerminated(), new Y(!0);
2393
+ if (r === "GRACEFUL" && s === "/")
2394
+ throw this.runtime.markRunTerminated(), new Y(!1);
2117
2395
  }
2118
2396
  }
2119
- function er(i, e, t) {
2120
- return nr(i, {
2121
- type: { blueId: Yn },
2397
+ function Pr(i, e, t) {
2398
+ return Nr(i, {
2399
+ type: { blueId: Tr },
2122
2400
  cause: e === "GRACEFUL" ? "graceful" : "fatal",
2123
2401
  ...t ? { reason: t } : {}
2124
2402
  });
2125
2403
  }
2126
- function tr(i, e) {
2127
- const t = new d().setType(
2128
- new d().setBlueId(Zn)
2404
+ function Mr(i, e) {
2405
+ const t = new h().setType(
2406
+ new h().setBlueId(Ir)
2129
2407
  );
2130
2408
  return t.addProperty(
2131
2409
  "cause",
2132
- new d().setValue(i === "GRACEFUL" ? "graceful" : "fatal")
2133
- ), e && t.addProperty("reason", new d().setValue(e)), t;
2410
+ new h().setValue(i === "GRACEFUL" ? "graceful" : "fatal")
2411
+ ), e && t.addProperty("reason", new h().setValue(e)), t;
2134
2412
  }
2135
- function nr(i, e) {
2413
+ function Nr(i, e) {
2136
2414
  return i.jsonValueToNode(e);
2137
2415
  }
2138
- const $ = "-";
2139
- class rr {
2416
+ const V = "-";
2417
+ class Or {
2140
2418
  constructor(e) {
2141
2419
  this.document = e;
2142
2420
  }
2143
2421
  applyPatch(e, t) {
2144
- const n = y(e), r = b(t.path), s = Re(r), o = ve(this.document, s, "before", r);
2422
+ const n = C(e), r = T(t.path), o = Le(r), s = Be(this.document, o, "before", r);
2145
2423
  switch (t.op) {
2146
2424
  case "ADD":
2147
- this.applyAdd(s, r, t.val ?? null);
2425
+ this.applyAdd(o, r, t.val ?? null);
2148
2426
  break;
2149
2427
  case "REPLACE":
2150
- this.applyReplace(s, r, t.val ?? null);
2428
+ this.applyReplace(o, r, t.val ?? null);
2151
2429
  break;
2152
2430
  case "REMOVE":
2153
- this.applyRemove(s, r);
2431
+ this.applyRemove(o, r);
2154
2432
  break;
2155
2433
  }
2156
- const a = t.op === "REMOVE" ? null : ve(this.document, s, "after", r);
2434
+ const a = t.op === "REMOVE" ? null : Be(this.document, o, "after", r);
2157
2435
  return {
2158
2436
  path: r,
2159
- before: o,
2437
+ before: s,
2160
2438
  after: a,
2161
2439
  op: t.op.toLowerCase(),
2162
2440
  originScope: n,
2163
- cascadeScopes: ir(n)
2441
+ cascadeScopes: Ar(n)
2164
2442
  };
2165
2443
  }
2166
2444
  directWrite(e, t) {
2167
- const n = b(e);
2445
+ const n = T(e);
2168
2446
  if (n === "/")
2169
2447
  throw new Error("Direct write cannot target root document");
2170
- const r = Re(n), { parent: s, leaf: o } = this.resolveParent(r);
2171
- if (o === $)
2448
+ const r = Le(n), { parent: o, leaf: s } = this.resolveParent(r);
2449
+ if (s === V)
2172
2450
  throw new Error(
2173
2451
  `Direct write does not support append token '-' for path ${n}`
2174
2452
  );
2175
- const a = s.getItems();
2176
- if (a && P(o)) {
2177
- this.directWriteArray(s, a, o, t, n);
2453
+ const a = o.getItems();
2454
+ if (a && D(s)) {
2455
+ this.directWriteArray(o, a, s, t, n);
2178
2456
  return;
2179
2457
  }
2180
- this.directWriteObject(s, o, t);
2458
+ this.directWriteObject(o, s, t);
2181
2459
  }
2182
- directWriteArray(e, t, n, r, s) {
2183
- const o = X(e, t), a = C(n, s);
2460
+ directWriteArray(e, t, n, r, o) {
2461
+ const s = se(e, t), a = M(n, o);
2184
2462
  if (r == null) {
2185
- if (a < 0 || a >= o.length)
2463
+ if (a < 0 || a >= s.length)
2186
2464
  return;
2187
- o.splice(a, 1), e.setItems(o);
2465
+ s.splice(a, 1), e.setItems(s);
2188
2466
  return;
2189
2467
  }
2190
2468
  const c = r.clone();
2191
- if (a === o.length) {
2192
- o.push(c), e.setItems(o);
2469
+ if (a === s.length) {
2470
+ s.push(c), e.setItems(s);
2193
2471
  return;
2194
2472
  }
2195
- if (a >= 0 && a < o.length) {
2196
- o[a] = c, e.setItems(o);
2473
+ if (a >= 0 && a < s.length) {
2474
+ s[a] = c, e.setItems(s);
2197
2475
  return;
2198
2476
  }
2199
2477
  throw new Error(
2200
- `Array index out of bounds for direct write: ${s}`
2478
+ `Array index out of bounds for direct write: ${o}`
2201
2479
  );
2202
2480
  }
2203
2481
  directWriteObject(e, t, n) {
2204
- const r = K(e);
2482
+ const r = J(e);
2205
2483
  if (n == null) {
2206
2484
  delete r[t], e.setProperties(
2207
2485
  Object.keys(r).length > 0 ? r : void 0
@@ -2221,55 +2499,55 @@ class rr {
2221
2499
  return { parent: t, leaf: e[e.length - 1] };
2222
2500
  }
2223
2501
  getOrCreateChild(e, t, n, r) {
2224
- if (t === $)
2502
+ if (t === V)
2225
2503
  throw new Error(
2226
- `Append token '-' must be final segment: ${B(n, r)}`
2504
+ `Append token '-' must be final segment: ${z(n, r)}`
2227
2505
  );
2228
- const s = e.getItems();
2229
- if (s && P(t)) {
2230
- const c = C(t, B(n, r));
2231
- if (c < 0 || c >= s.length)
2506
+ const o = e.getItems();
2507
+ if (o && D(t)) {
2508
+ const c = M(t, z(n, r));
2509
+ if (c < 0 || c >= o.length)
2232
2510
  throw new Error(
2233
- `Array index out of bounds: ${B(n, r)}`
2511
+ `Array index out of bounds: ${z(n, r)}`
2234
2512
  );
2235
- const l = s[c];
2236
- if (!l)
2513
+ const u = o[c];
2514
+ if (!u)
2237
2515
  throw new Error(
2238
- `Path does not exist: ${B(n, r)}`
2516
+ `Path does not exist: ${z(n, r)}`
2239
2517
  );
2240
- return l;
2518
+ return u;
2241
2519
  }
2242
- const o = K(e);
2243
- let a = o[t];
2244
- return a || (a = new d(), o[t] = a, e.setProperties(o)), a;
2520
+ const s = J(e);
2521
+ let a = s[t];
2522
+ return a || (a = new h(), s[t] = a, e.setProperties(s)), a;
2245
2523
  }
2246
2524
  applyAdd(e, t, n) {
2247
2525
  if (t === "/" || t.length === 0)
2248
2526
  throw new Error("ADD operation cannot target document root");
2249
- const { parent: r, key: s, pointer: o, created: a } = this.resolveParentForPatch(
2527
+ const { parent: r, key: o, pointer: s, created: a } = this.resolveParentForPatch(
2250
2528
  e,
2251
2529
  t,
2252
2530
  "ADD"
2253
2531
  );
2254
2532
  try {
2255
- if (P(s)) {
2256
- const l = r.getItems(), u = s === $;
2257
- if (!l)
2533
+ if (D(o)) {
2534
+ const u = r.getItems(), d = o === V;
2535
+ if (!u)
2258
2536
  throw new Error(
2259
- u ? `Append token '-' requires array at ${o}` : `Array index segment requires array at ${o}`
2537
+ d ? `Append token '-' requires array at ${s}` : `Array index segment requires array at ${s}`
2260
2538
  );
2261
- if (u) {
2262
- X(r, l).push(L(n));
2539
+ if (d) {
2540
+ se(r, u).push($(n));
2263
2541
  return;
2264
2542
  }
2265
- const h = C(s, t);
2266
- if (h < 0 || h > l.length)
2543
+ const g = M(o, t);
2544
+ if (g < 0 || g > u.length)
2267
2545
  throw new Error(`Array index out of bounds in path: ${t}`);
2268
- X(r, l).splice(h, 0, L(n));
2546
+ se(r, u).splice(g, 0, $(n));
2269
2547
  return;
2270
2548
  }
2271
- const c = K(r);
2272
- c[s] = L(n), r.setProperties(c);
2549
+ const c = J(r);
2550
+ c[o] = $(n), r.setProperties(c);
2273
2551
  } catch (c) {
2274
2552
  throw this.rollbackCreated(a), c;
2275
2553
  }
@@ -2277,26 +2555,26 @@ class rr {
2277
2555
  applyReplace(e, t, n) {
2278
2556
  if (t === "/" || t.length === 0)
2279
2557
  throw new Error("REPLACE operation cannot target document root");
2280
- const { parent: r, key: s, created: o } = this.resolveParentForPatch(
2558
+ const { parent: r, key: o, created: s } = this.resolveParentForPatch(
2281
2559
  e,
2282
2560
  t,
2283
2561
  "REPLACE"
2284
2562
  );
2285
2563
  try {
2286
- if (P(s)) {
2564
+ if (D(o)) {
2287
2565
  const c = r.getItems();
2288
2566
  if (!c)
2289
2567
  throw new Error(`Array index segment requires array at ${t}`);
2290
- const l = C(s, t);
2291
- if (l < 0 || l >= c.length)
2568
+ const u = M(o, t);
2569
+ if (u < 0 || u >= c.length)
2292
2570
  throw new Error(`Array index out of bounds in path: ${t}`);
2293
- c[l] = L(n), r.setItems(c);
2571
+ c[u] = $(n), r.setItems(c);
2294
2572
  return;
2295
2573
  }
2296
- const a = K(r);
2297
- a[s] = L(n), r.setProperties(a);
2574
+ const a = J(r);
2575
+ a[o] = $(n), r.setProperties(a);
2298
2576
  } catch (a) {
2299
- throw this.rollbackCreated(o), a;
2577
+ throw this.rollbackCreated(s), a;
2300
2578
  }
2301
2579
  }
2302
2580
  applyRemove(e, t) {
@@ -2307,61 +2585,61 @@ class rr {
2307
2585
  t,
2308
2586
  "REMOVE"
2309
2587
  );
2310
- if (P(r)) {
2588
+ if (D(r)) {
2311
2589
  const a = n.getItems();
2312
2590
  if (!a)
2313
2591
  throw new Error(`Array index segment requires array at ${t}`);
2314
- const c = C(r, t);
2592
+ const c = M(r, t);
2315
2593
  if (c < 0 || c >= a.length)
2316
2594
  throw new Error(`Array index out of bounds in path: ${t}`);
2317
2595
  a.splice(c, 1), n.setItems(a);
2318
2596
  return;
2319
2597
  }
2320
- const s = n.getProperties();
2321
- if (!s || !Object.prototype.hasOwnProperty.call(s, r))
2598
+ const o = n.getProperties();
2599
+ if (!o || !Object.prototype.hasOwnProperty.call(o, r))
2322
2600
  throw new Error(`Path does not exist: ${t}`);
2323
- const o = { ...s };
2324
- delete o[r], n.setProperties(o);
2601
+ const s = { ...o };
2602
+ delete s[r], n.setProperties(s);
2325
2603
  }
2326
2604
  resolveParentForPatch(e, t, n) {
2327
2605
  if (e.length === 0)
2328
2606
  throw new Error(`${n} operation cannot target document root`);
2329
2607
  let r = this.document;
2330
- const s = [];
2608
+ const o = [];
2331
2609
  for (let a = 0; a < e.length - 1; a += 1) {
2332
- const c = e[a], l = B(e, a + 1);
2333
- if (P(c)) {
2334
- const f = r.getItems();
2335
- if (!f)
2336
- throw new Error(`Array index segment requires array at ${l}`);
2337
- const E = C(c, l);
2338
- if (E < 0 || E >= f.length)
2339
- throw new Error(`Array index out of bounds in path: ${l}`);
2340
- const D = f[E];
2341
- if (!(D instanceof d))
2342
- throw new Error(`Array index out of bounds in path: ${l}`);
2343
- r = D;
2610
+ const c = e[a], u = z(e, a + 1);
2611
+ if (D(c)) {
2612
+ const m = r.getItems();
2613
+ if (!m)
2614
+ throw new Error(`Array index segment requires array at ${u}`);
2615
+ const y = M(c, u);
2616
+ if (y < 0 || y >= m.length)
2617
+ throw new Error(`Array index out of bounds in path: ${u}`);
2618
+ const P = m[y];
2619
+ if (!(P instanceof h))
2620
+ throw new Error(`Array index out of bounds in path: ${u}`);
2621
+ r = P;
2344
2622
  continue;
2345
2623
  }
2346
- let u = r.getProperties(), h = u?.[c] ?? null;
2347
- if (!(h instanceof d)) {
2624
+ let d = r.getProperties(), g = d?.[c] ?? null;
2625
+ if (!(g instanceof h)) {
2348
2626
  if (n === "REMOVE")
2349
- throw new Error(`Path does not exist: ${l}`);
2350
- h = new d(), u || (u = {}), u[c] = h, r.setProperties(u), s.push({ owner: r, key: c });
2627
+ throw new Error(`Path does not exist: ${u}`);
2628
+ g = new h(), d || (d = {}), d[c] = g, r.setProperties(d), o.push({ owner: r, key: c });
2351
2629
  }
2352
- r = h;
2630
+ r = g;
2353
2631
  }
2354
- const o = e[e.length - 1];
2355
- return { parent: r, key: o, pointer: t, created: s };
2632
+ const s = e[e.length - 1];
2633
+ return { parent: r, key: s, pointer: t, created: o };
2356
2634
  }
2357
2635
  rollbackCreated(e) {
2358
2636
  for (let t = e.length - 1; t >= 0; t -= 1) {
2359
- const { owner: n, key: r } = e[t], s = n.getProperties();
2360
- s && (delete s[r], Object.keys(s).length === 0 ? n.setProperties(void 0) : n.setProperties(s));
2637
+ const { owner: n, key: r } = e[t], o = n.getProperties();
2638
+ o && (delete o[r], Object.keys(o).length === 0 ? n.setProperties(void 0) : n.setProperties(o));
2361
2639
  }
2362
2640
  }
2363
2641
  }
2364
- function ir(i) {
2642
+ function Ar(i) {
2365
2643
  const e = [];
2366
2644
  let t = i;
2367
2645
  for (; e.push(t), t !== "/"; ) {
@@ -2370,51 +2648,51 @@ function ir(i) {
2370
2648
  }
2371
2649
  return e;
2372
2650
  }
2373
- function ve(i, e, t, n) {
2651
+ function Be(i, e, t, n) {
2374
2652
  try {
2375
2653
  if (e.length === 0)
2376
2654
  return i.clone();
2377
- const r = sr(i, e, t, n);
2655
+ const r = Dr(i, e, t, n);
2378
2656
  return r ? r.clone() : null;
2379
2657
  } catch {
2380
2658
  return null;
2381
2659
  }
2382
2660
  }
2383
- function sr(i, e, t, n) {
2661
+ function Dr(i, e, t, n) {
2384
2662
  let r = i;
2385
- for (let s = 0; s < e.length; s += 1) {
2386
- const o = e[s] ?? "", a = s === e.length - 1;
2387
- if (r = or(r, o, a, t, n), !r)
2663
+ for (let o = 0; o < e.length; o += 1) {
2664
+ const s = e[o] ?? "", a = o === e.length - 1;
2665
+ if (r = Br(r, s, a, t, n), !r)
2388
2666
  return null;
2389
2667
  }
2390
2668
  return r;
2391
2669
  }
2392
- function or(i, e, t, n, r) {
2670
+ function Br(i, e, t, n, r) {
2393
2671
  if (!i)
2394
2672
  return null;
2395
- const s = i.getItems();
2396
- if (s) {
2397
- if (e === $) {
2673
+ const o = i.getItems();
2674
+ if (o) {
2675
+ if (e === V) {
2398
2676
  if (!t)
2399
2677
  throw new Error(`Append token '-' must be final segment: ${r}`);
2400
- return n === "before" || s.length === 0 ? null : s[s.length - 1] ?? null;
2678
+ return n === "before" || o.length === 0 ? null : o[o.length - 1] ?? null;
2401
2679
  }
2402
- const c = C(e, r);
2403
- return c < 0 || c >= s.length ? null : s[c] ?? null;
2680
+ const c = M(e, r);
2681
+ return c < 0 || c >= o.length ? null : o[c] ?? null;
2404
2682
  }
2405
- const o = i.getProperties();
2406
- if (!o)
2683
+ const s = i.getProperties();
2684
+ if (!s)
2407
2685
  return null;
2408
- const a = o[e];
2409
- return a instanceof d ? a : null;
2686
+ const a = s[e];
2687
+ return a instanceof h ? a : null;
2410
2688
  }
2411
- function Re(i) {
2689
+ function Le(i) {
2412
2690
  if (i === "/" || i === "")
2413
2691
  return [];
2414
2692
  const e = i.startsWith("/") ? i.slice(1) : i;
2415
2693
  return e.length === 0 ? [] : e.split("/");
2416
2694
  }
2417
- function C(i, e) {
2695
+ function M(i, e) {
2418
2696
  const t = Number.parseInt(i, 10);
2419
2697
  if (Number.isNaN(t))
2420
2698
  throw new Error(`Expected numeric array index in path: ${e}`);
@@ -2422,7 +2700,7 @@ function C(i, e) {
2422
2700
  throw new Error(`Negative array index in path: ${e}`);
2423
2701
  return t;
2424
2702
  }
2425
- function B(i, e) {
2703
+ function z(i, e) {
2426
2704
  if (e <= 0)
2427
2705
  return "/";
2428
2706
  const t = Math.min(e, i.length);
@@ -2431,11 +2709,11 @@ function B(i, e) {
2431
2709
  n += `/${i[r] ?? ""}`;
2432
2710
  return n === "" ? "/" : n;
2433
2711
  }
2434
- function X(i, e) {
2712
+ function se(i, e) {
2435
2713
  const t = [...e];
2436
2714
  return i.setItems(t), t;
2437
2715
  }
2438
- function K(i) {
2716
+ function J(i) {
2439
2717
  const e = i.getProperties();
2440
2718
  if (!e) {
2441
2719
  const n = {};
@@ -2444,13 +2722,13 @@ function K(i) {
2444
2722
  const t = { ...e };
2445
2723
  return i.setProperties(t), t;
2446
2724
  }
2447
- function P(i) {
2448
- return i === $ || /^\d+$/.test(i);
2725
+ function D(i) {
2726
+ return i === V || /^\d+$/.test(i);
2449
2727
  }
2450
- function L(i) {
2451
- return i == null ? new d().setValue(null) : i.clone();
2728
+ function $(i) {
2729
+ return i == null ? new h().setValue(null) : i.clone();
2452
2730
  }
2453
- class ar {
2731
+ class Lr {
2454
2732
  constructor(e) {
2455
2733
  this.path = e;
2456
2734
  }
@@ -2512,7 +2790,7 @@ class ar {
2512
2790
  return this.cutOff;
2513
2791
  }
2514
2792
  }
2515
- class cr {
2793
+ class xr {
2516
2794
  scopesMap = /* @__PURE__ */ new Map();
2517
2795
  rootEmissionList = [];
2518
2796
  scopes() {
@@ -2520,7 +2798,7 @@ class cr {
2520
2798
  }
2521
2799
  scope(e) {
2522
2800
  let t = this.scopesMap.get(e);
2523
- return t || (t = new ar(e), this.scopesMap.set(e, t)), t;
2801
+ return t || (t = new Lr(e), this.scopesMap.set(e, t)), t;
2524
2802
  }
2525
2803
  existingScope(e) {
2526
2804
  return this.scopesMap.get(e);
@@ -2538,45 +2816,45 @@ class cr {
2538
2816
  this.scopesMap.delete(e);
2539
2817
  }
2540
2818
  }
2541
- function U(i) {
2819
+ function q(i) {
2542
2820
  return Math.floor((i + 99) / 100);
2543
2821
  }
2544
- function ue(i) {
2822
+ function ye(i) {
2545
2823
  return new TextEncoder().encode(i).length;
2546
2824
  }
2547
- function lr(i) {
2548
- const e = b(i);
2825
+ function _r(i) {
2826
+ const e = T(i);
2549
2827
  return e === "/" ? 0 : e.split("/").length - 1;
2550
2828
  }
2551
- function ur(i) {
2552
- return 100 + U(ue(i));
2829
+ function Fr(i) {
2830
+ return 100 + q(ye(i));
2553
2831
  }
2554
- function dr(i) {
2832
+ function Ur(i) {
2555
2833
  return 40 + 5 * Math.max(0, i);
2556
2834
  }
2557
- function hr(i) {
2558
- return 5 + U(ue(i));
2835
+ function zr(i) {
2836
+ return 5 + q(ye(i));
2559
2837
  }
2560
- function fr(i, e) {
2561
- return 3 * Math.max(0, i) + U(ue(e));
2838
+ function $r(i, e) {
2839
+ return 3 * Math.max(0, i) + q(ye(e));
2562
2840
  }
2563
- function pr(i, e) {
2564
- return 8 + lr(i) + U(e);
2841
+ function Hr(i, e) {
2842
+ return 8 + _r(i) + q(e);
2565
2843
  }
2566
- const mr = 1e3, gr = 5, Er = 50, yr = 2, wr = 10, br = 10, Sr = 10, Cr = 20, kr = 20, Ir = 30, vr = 30, Rr = 100;
2567
- function Tr(i) {
2844
+ const Vr = 1e3, Wr = 5, Kr = 50, qr = 2, jr = 10, Jr = 10, Gr = 10, Qr = 20, Yr = 20, Xr = 30, Zr = 30, ei = 100;
2845
+ function ti(i) {
2568
2846
  return 50 + 10 * i;
2569
2847
  }
2570
- function Pr(i) {
2848
+ function ni(i) {
2571
2849
  return 20 + i;
2572
2850
  }
2573
- function Nr(i) {
2851
+ function ri(i) {
2574
2852
  return 10 * i;
2575
2853
  }
2576
- function Mr(i) {
2854
+ function ii(i) {
2577
2855
  return 20 + i;
2578
2856
  }
2579
- class Ar {
2857
+ class oi {
2580
2858
  constructor(e) {
2581
2859
  this.blue = e;
2582
2860
  }
@@ -2588,77 +2866,77 @@ class Ar {
2588
2866
  this.total += e;
2589
2867
  }
2590
2868
  chargeScopeEntry(e) {
2591
- this.add(Tr(this.scopeDepth(e)));
2869
+ this.add(ti(this.scopeDepth(e)));
2592
2870
  }
2593
2871
  chargeInitialization() {
2594
- this.add(mr);
2872
+ this.add(Vr);
2595
2873
  }
2596
2874
  chargeChannelMatchAttempt() {
2597
- this.add(gr);
2875
+ this.add(Wr);
2598
2876
  }
2599
2877
  chargeHandlerOverhead() {
2600
- this.add(Er);
2878
+ this.add(Kr);
2601
2879
  }
2602
2880
  chargeBoundaryCheck() {
2603
- this.add(yr);
2881
+ this.add(qr);
2604
2882
  }
2605
2883
  chargePatchAddOrReplace(e) {
2606
- this.add(Pr(this.payloadSizeCharge(e)));
2884
+ this.add(ni(this.payloadSizeCharge(e)));
2607
2885
  }
2608
2886
  chargePatchRemove() {
2609
- this.add(wr);
2887
+ this.add(jr);
2610
2888
  }
2611
2889
  chargeCascadeRouting(e) {
2612
- e > 0 && this.add(Nr(e));
2890
+ e > 0 && this.add(ri(e));
2613
2891
  }
2614
2892
  chargeEmitEvent(e) {
2615
- this.add(Mr(this.payloadSizeCharge(e)));
2893
+ this.add(ii(this.payloadSizeCharge(e)));
2616
2894
  }
2617
2895
  chargeBridge() {
2618
- this.add(br);
2896
+ this.add(Jr);
2619
2897
  }
2620
2898
  chargeDrainEvent() {
2621
- this.add(Sr);
2899
+ this.add(Gr);
2622
2900
  }
2623
2901
  chargeCheckpointUpdate() {
2624
- this.add(Cr);
2902
+ this.add(Qr);
2625
2903
  }
2626
2904
  chargeTerminationMarker() {
2627
- this.add(kr);
2905
+ this.add(Yr);
2628
2906
  }
2629
2907
  chargeLifecycleDelivery() {
2630
- this.add(Ir);
2908
+ this.add(Xr);
2631
2909
  }
2632
2910
  chargeFatalTerminationOverhead() {
2633
- this.add(Rr);
2911
+ this.add(ei);
2634
2912
  }
2635
2913
  chargeJavaScriptCodeBase(e) {
2636
- this.add(ur(e));
2914
+ this.add(Fr(e));
2637
2915
  }
2638
2916
  chargeTriggerEventBase() {
2639
- this.add(vr);
2917
+ this.add(Zr);
2640
2918
  }
2641
2919
  chargeUpdateDocumentBase(e) {
2642
- this.add(dr(e));
2920
+ this.add(Ur(e));
2643
2921
  }
2644
2922
  chargeExpression(e) {
2645
- this.add(hr(e));
2923
+ this.add(zr(e));
2646
2924
  }
2647
2925
  chargeTemplate(e, t) {
2648
- this.add(fr(e, t));
2926
+ this.add($r(e, t));
2649
2927
  }
2650
2928
  chargeDocumentSnapshot(e, t) {
2651
- const n = t ? ye(this.blue, t) : 0;
2652
- this.add(pr(e, n));
2929
+ const n = t ? ve(this.blue, t) : 0;
2930
+ this.add(Hr(e, n));
2653
2931
  }
2654
2932
  payloadSizeCharge(e) {
2655
2933
  if (!e)
2656
2934
  return 0;
2657
- const t = ye(this.blue, e);
2658
- return U(t);
2935
+ const t = ve(this.blue, e);
2936
+ return q(t);
2659
2937
  }
2660
2938
  scopeDepth(e) {
2661
- const t = y(e);
2939
+ const t = C(e);
2662
2940
  if (t === "/" || t.length <= 1)
2663
2941
  return 0;
2664
2942
  let n = 1;
@@ -2667,12 +2945,12 @@ class Ar {
2667
2945
  return n;
2668
2946
  }
2669
2947
  }
2670
- class Or {
2948
+ class si {
2671
2949
  constructor(e, t) {
2672
- this.documentRef = e, this.blueRef = t, this.patchEngine = new rr(this.documentRef), this.meter = new Ar(this.blueRef);
2950
+ this.documentRef = e, this.blueRef = t, this.patchEngine = new Or(this.documentRef), this.meter = new oi(this.blueRef);
2673
2951
  }
2674
2952
  patchEngine;
2675
- emissionRegistry = new cr();
2953
+ emissionRegistry = new xr();
2676
2954
  meter;
2677
2955
  runTerminated = !1;
2678
2956
  document() {
@@ -2721,66 +2999,67 @@ class Or {
2721
2999
  return this.patchEngine.applyPatch(e, t);
2722
3000
  }
2723
3001
  }
2724
- const Dr = p["Processing Initialized Marker"], Br = p["Document Update"];
2725
- class Lr {
3002
+ const ai = p["Core/Processing Initialized Marker"], ci = p["Core/Document Update"];
3003
+ class li {
2726
3004
  constructor(e, t, n, r) {
2727
- this.contractLoader = e, this.registry = t, this.runtimeRef = new Or(r, n);
2728
- const s = (o) => ze(this.runtimeRef.blue(), o);
2729
- this.checkpointManager = new Vn(
3005
+ this.contractLoader = e, this.registry = t, this.runtimeRef = new si(r, n);
3006
+ const o = (s) => Ge(this.runtimeRef.blue(), s);
3007
+ this.checkpointManager = new gr(
2730
3008
  this.runtimeRef,
2731
- s
2732
- ), this.terminationService = new Xn(this.runtimeRef), this.channelRunner = new Kn(
3009
+ o
3010
+ ), this.terminationService = new Rr(this.runtimeRef), this.channelRunner = new yr(
2733
3011
  this.runtimeRef,
2734
3012
  this.checkpointManager,
2735
3013
  {
2736
- evaluateChannel: async (o, a, c, l) => this.evaluateChannel(o, a, c, l),
2737
- isScopeInactive: (o) => this.isScopeInactive(o),
2738
- createContext: (o, a, c, l) => this.createContext(
2739
- o,
3014
+ evaluateChannel: async (s, a, c, u) => this.evaluateChannel(s, a, c, u),
3015
+ isScopeInactive: (s) => this.isScopeInactive(s),
3016
+ createContext: (s, a, c, u) => this.createContext(
3017
+ s,
2740
3018
  a,
2741
3019
  c,
2742
- l,
3020
+ u,
2743
3021
  !1
2744
3022
  ),
2745
- shouldRunHandler: async (o, a) => {
2746
- const c = this.registry.lookupHandler(o.blueId());
3023
+ shouldRunHandler: async (s, a) => {
3024
+ const c = this.registry.lookupHandler(s.blueId());
2747
3025
  if (!c) {
2748
- const u = `No processor registered for handler contract ${o.blueId()}`;
2749
- throw new m(
2750
- u,
2751
- g.illegalState(u)
3026
+ const d = `No processor registered for handler contract ${s.blueId()}`;
3027
+ throw new E(
3028
+ d,
3029
+ w.illegalState(d)
2752
3030
  );
2753
3031
  }
2754
- const l = c.matches;
2755
- return typeof l != "function" ? !0 : await l.call(c, o.contract(), a);
3032
+ const u = c.matches;
3033
+ return typeof u != "function" ? !0 : await u.call(c, s.contract(), a);
2756
3034
  },
2757
- executeHandler: async (o, a) => this.executeHandler(o, a),
2758
- handleHandlerError: async (o, a, c) => this.handleHandlerError(o, a, c),
2759
- canonicalSignature: s
3035
+ executeHandler: async (s, a) => this.executeHandler(s, a),
3036
+ handleHandlerError: async (s, a, c) => this.handleHandlerError(s, a, c),
3037
+ canonicalSignature: o,
3038
+ channelProcessorFor: (s) => this.registry.lookupChannel(s) ?? null
2760
3039
  }
2761
- ), this.scopeExecutor = new Qn({
3040
+ ), this.scopeExecutor = new kr({
2762
3041
  runtime: this.runtimeRef,
2763
3042
  contractLoader: this.contractLoader,
2764
3043
  channelRunner: this.channelRunner,
2765
3044
  bundles: this.bundles,
2766
3045
  hooks: {
2767
- isScopeInactive: (o) => this.isScopeInactive(o),
2768
- createContext: (o, a, c, l, u) => this.createContext(
2769
- o,
3046
+ isScopeInactive: (s) => this.isScopeInactive(s),
3047
+ createContext: (s, a, c, u, d) => this.createContext(
3048
+ s,
2770
3049
  a,
2771
3050
  c,
2772
- l,
2773
- u ?? !1
3051
+ u,
3052
+ d ?? !1
2774
3053
  ),
2775
- recordLifecycleForBridging: (o, a) => this.recordLifecycleForBridging(o, a),
2776
- enterFatalTermination: (o, a, c) => this.enterFatalTermination(o, a, c ?? null),
2777
- fatalReason: (o, a) => this.fatalReason(o, a),
2778
- markCutOff: (o) => this.markCutOff(o)
3054
+ recordLifecycleForBridging: (s, a) => this.recordLifecycleForBridging(s, a),
3055
+ enterFatalTermination: (s, a, c) => this.enterFatalTermination(s, a, c ?? null),
3056
+ fatalReason: (s, a) => this.fatalReason(s, a),
3057
+ markCutOff: (s) => this.markCutOff(s)
2779
3058
  },
2780
- blueId: (o) => this.runtimeRef.blue().calculateBlueIdSync(o),
2781
- nodeAt: (o) => this.nodeAt(o),
2782
- createDocumentUpdateEvent: (o, a) => this.createDocumentUpdateEvent(o, a),
2783
- matchesDocumentUpdate: (o, a, c) => this.matchesDocumentUpdate(o, a, c)
3059
+ blueId: (s) => this.runtimeRef.blue().calculateBlueIdSync(s),
3060
+ nodeAt: (s) => this.nodeAt(s),
3061
+ createDocumentUpdateEvent: (s, a) => this.createDocumentUpdateEvent(s, a),
3062
+ matchesDocumentUpdate: (s, a, c) => this.matchesDocumentUpdate(s, a, c)
2784
3063
  });
2785
3064
  }
2786
3065
  runtimeRef;
@@ -2808,19 +3087,19 @@ class Lr {
2808
3087
  r
2809
3088
  );
2810
3089
  }
2811
- createContext(e, t, n, r = !1, s = !1) {
2812
- return new _r(
3090
+ createContext(e, t, n, r = !1, o = !1) {
3091
+ return new ui(
2813
3092
  this,
2814
3093
  t,
2815
3094
  e,
2816
3095
  n.clone(),
2817
3096
  r,
2818
- s
3097
+ o
2819
3098
  );
2820
3099
  }
2821
3100
  result() {
2822
3101
  const e = this.runtimeRef.document().clone(), t = this.runtimeRef.rootEmissions().map((n) => n.clone());
2823
- return Pe.of(
3102
+ return _e.of(
2824
3103
  e,
2825
3104
  t,
2826
3105
  this.runtimeRef.totalGas()
@@ -2830,10 +3109,10 @@ class Lr {
2830
3109
  return this.runtimeRef;
2831
3110
  }
2832
3111
  bundleForScope(e) {
2833
- return this.bundles.get(y(e));
3112
+ return this.bundles.get(C(e));
2834
3113
  }
2835
3114
  isScopeInactive(e) {
2836
- const t = y(e);
3115
+ const t = C(e);
2837
3116
  return this.cutOffScopes.has(t) || this.pendingTerminations.has(t) || this.runtimeRef.isScopeTerminated(t);
2838
3117
  }
2839
3118
  async enterGracefulTermination(e, t, n) {
@@ -2843,13 +3122,13 @@ class Lr {
2843
3122
  await this.terminate(e, t, "FATAL", n);
2844
3123
  }
2845
3124
  recordPendingTermination(e, t, n) {
2846
- this.pendingTerminations.set(y(e), { kind: t, reason: n });
3125
+ this.pendingTerminations.set(C(e), { kind: t, reason: n });
2847
3126
  }
2848
3127
  clearPendingTermination(e) {
2849
- this.pendingTerminations.delete(y(e));
3128
+ this.pendingTerminations.delete(C(e));
2850
3129
  }
2851
3130
  async markCutOff(e) {
2852
- const t = y(e);
3131
+ const t = C(e);
2853
3132
  this.cutOffScopes.add(t) && this.runtimeRef.existingScope(t)?.markCutOff();
2854
3133
  }
2855
3134
  async deliverLifecycle(e, t, n, r) {
@@ -2864,14 +3143,14 @@ class Lr {
2864
3143
  this.runtimeRef.scope(e).recordBridgeable(t.clone()), e === "/" && this.runtimeRef.recordRootEmission(t.clone());
2865
3144
  }
2866
3145
  normalizeScope(e) {
2867
- return y(e);
3146
+ return C(e);
2868
3147
  }
2869
3148
  resolvePointer(e, t) {
2870
- return w(e, t);
3149
+ return k(e, t);
2871
3150
  }
2872
3151
  async terminate(e, t, n, r) {
2873
- const s = y(e);
2874
- this.pendingTerminations.has(s) || this.runtimeRef.isScopeTerminated(s) || (this.pendingTerminations.set(s, { kind: n, reason: r }), await this.terminationService.terminateScope(
3152
+ const o = C(e);
3153
+ this.pendingTerminations.has(o) || this.runtimeRef.isScopeTerminated(o) || (this.pendingTerminations.set(o, { kind: n, reason: r }), await this.terminationService.terminateScope(
2875
3154
  this,
2876
3155
  e,
2877
3156
  t,
@@ -2880,39 +3159,41 @@ class Lr {
2880
3159
  ));
2881
3160
  }
2882
3161
  nodeAt(e) {
2883
- const t = y(e);
2884
- return j.nodeAt(this.runtimeRef.document(), t);
3162
+ const t = C(e);
3163
+ return X.nodeAt(this.runtimeRef.document(), t, {
3164
+ calculateBlueId: (n) => this.runtimeRef.blue().calculateBlueIdSync(n)
3165
+ });
2885
3166
  }
2886
3167
  async evaluateChannel(e, t, n, r) {
2887
- const s = this.registry.lookupChannel(e.blueId());
2888
- if (!s)
3168
+ const o = this.registry.lookupChannel(e.blueId());
3169
+ if (!o)
2889
3170
  return { matches: !1 };
2890
- const o = this.runtimeRef.blue().calculateBlueIdSync(r), a = r.clone(), c = {
3171
+ const s = this.runtimeRef.blue().calculateBlueIdSync(r), a = r.clone(), c = e.contract(), u = c.event;
3172
+ if (u && !this.runtimeRef.blue().isTypeOfNode(a, u))
3173
+ return { matches: !1 };
3174
+ const d = {
2891
3175
  scopePath: n,
2892
3176
  blue: this.runtimeRef.blue(),
2893
3177
  event: a,
2894
3178
  markers: t.markers(),
2895
3179
  bindingKey: e.key()
2896
3180
  };
2897
- if (!await s.matches(
2898
- e.contract(),
2899
- c
2900
- ))
3181
+ if (!await o.matches(c, d))
2901
3182
  return { matches: !1 };
2902
- const u = s.channelize, h = u ? u.call(s, e.contract(), c) : void 0;
3183
+ const m = o.channelize, y = m ? m.call(o, c, d) : void 0;
2903
3184
  return {
2904
3185
  matches: !0,
2905
- eventId: o,
2906
- eventNode: h ?? a.clone()
3186
+ eventId: s,
3187
+ eventNode: y ?? a.clone()
2907
3188
  };
2908
3189
  }
2909
3190
  async executeHandler(e, t) {
2910
3191
  const n = this.registry.lookupHandler(e.blueId());
2911
3192
  if (!n) {
2912
3193
  const r = `No processor registered for handler contract ${e.blueId()}`;
2913
- throw new m(
3194
+ throw new E(
2914
3195
  r,
2915
- g.illegalState(r)
3196
+ w.illegalState(r)
2916
3197
  );
2917
3198
  }
2918
3199
  await n.execute(e.contract(), t);
@@ -2923,7 +3204,7 @@ class Lr {
2923
3204
  * the outer run logic can react according to spec (§22).
2924
3205
  */
2925
3206
  async handleHandlerError(e, t, n) {
2926
- if (n instanceof q || n instanceof F)
3207
+ if (n instanceof Y || n instanceof K)
2927
3208
  throw n;
2928
3209
  const r = this.fatalReason(n, "Runtime fatal");
2929
3210
  await this.enterFatalTermination(e, t, r);
@@ -2932,30 +3213,30 @@ class Lr {
2932
3213
  return e instanceof Error && typeof e.message == "string" ? e.message : t;
2933
3214
  }
2934
3215
  createDocumentUpdateEvent(e, t) {
2935
- const n = Mt(t, e.path), r = e.before != null ? e.before.clone() : new d().setValue(null), s = e.after != null ? e.after.clone() : new d().setValue(null), o = new d().setType(
2936
- new d().setBlueId(Br)
3216
+ const n = kt(t, e.path), r = e.before != null ? e.before.clone() : new h().setValue(null), o = e.after != null ? e.after.clone() : new h().setValue(null), s = new h().setType(
3217
+ new h().setBlueId(ci)
2937
3218
  );
2938
- return o.setProperties({
2939
- op: new d().setValue(e.op),
2940
- path: new d().setValue(n),
3219
+ return s.setProperties({
3220
+ op: new h().setValue(e.op),
3221
+ path: new h().setValue(n),
2941
3222
  before: r,
2942
- after: s
2943
- }), o;
3223
+ after: o
3224
+ }), s;
2944
3225
  }
2945
3226
  matchesDocumentUpdate(e, t, n) {
2946
3227
  if (!t || t.length === 0)
2947
3228
  return !1;
2948
- const r = b(w(e, t)), s = b(n);
2949
- return r === "/" || s === r ? !0 : s.startsWith(`${r}/`);
3229
+ const r = T(k(e, t)), o = T(n);
3230
+ return r === "/" || o === r ? !0 : o.startsWith(`${r}/`);
2950
3231
  }
2951
3232
  }
2952
- class j {
3233
+ class X {
2953
3234
  constructor(e, t, n) {
2954
3235
  this.contractLoader = e, this.registry = t, this.blue = n;
2955
3236
  }
2956
3237
  async initializeDocument(e) {
2957
3238
  if (this.isInitialized(e))
2958
- throw new N("Document already initialized");
3239
+ throw new B("Document already initialized");
2959
3240
  const t = this.createExecution(e.clone());
2960
3241
  return this.run(e, t, async () => {
2961
3242
  await t.initializeScope("/", !0);
@@ -2963,7 +3244,7 @@ class j {
2963
3244
  }
2964
3245
  async processDocument(e, t) {
2965
3246
  if (!this.isInitialized(e))
2966
- throw new N("Document not initialized");
3247
+ throw new B("Document not initialized");
2967
3248
  const n = this.createExecution(e.clone()), r = t.clone();
2968
3249
  return this.run(e, n, async () => {
2969
3250
  n.loadBundles("/"), await n.processExternalEvent("/", r);
@@ -2973,7 +3254,7 @@ class j {
2973
3254
  return this.initializationMarker(e) != null;
2974
3255
  }
2975
3256
  createExecution(e) {
2976
- return new Lr(
3257
+ return new li(
2977
3258
  this.contractLoader,
2978
3259
  this.registry,
2979
3260
  this.blue,
@@ -2984,12 +3265,12 @@ class j {
2984
3265
  try {
2985
3266
  await n();
2986
3267
  } catch (r) {
2987
- if (r instanceof q)
3268
+ if (r instanceof Y)
2988
3269
  return t.result();
2989
- if (r instanceof F) {
2990
- const s = e.clone();
2991
- return Pe.capabilityFailure(
2992
- s,
3270
+ if (r instanceof K) {
3271
+ const o = e.clone();
3272
+ return _e.capabilityFailure(
3273
+ o,
2993
3274
  r.message ?? null
2994
3275
  );
2995
3276
  }
@@ -2998,58 +3279,93 @@ class j {
2998
3279
  return t.result();
2999
3280
  }
3000
3281
  initializationMarker(e) {
3001
- const n = e.getProperties()?.contracts?.getProperties()?.initialized ?? null;
3282
+ const n = e.getProperties()?.[Ee.OBJECT_CONTRACTS]?.getProperties()?.initialized ?? null;
3002
3283
  if (!n)
3003
3284
  return null;
3004
- if (!(n instanceof d))
3005
- throw new m(
3285
+ if (!(n instanceof h))
3286
+ throw new E(
3006
3287
  "Initialization Marker must be a BlueNode",
3007
- g.illegalState(
3288
+ w.illegalState(
3008
3289
  "Initialization Marker must be a BlueNode"
3009
3290
  )
3010
3291
  );
3011
- if (n.getType()?.getBlueId() !== Dr)
3012
- throw new m(
3292
+ if (n.getType()?.getBlueId() !== ai)
3293
+ throw new E(
3013
3294
  "Initialization Marker must declare type 'Processing Initialized Marker'",
3014
- g.illegalState(
3295
+ w.illegalState(
3015
3296
  "Initialization Marker must declare type 'Processing Initialized Marker'"
3016
3297
  )
3017
3298
  );
3018
3299
  return n;
3019
3300
  }
3020
- static nodeAt(e, t) {
3021
- if (!(e instanceof d))
3301
+ static nodeAt(e, t, n) {
3302
+ if (!(e instanceof h))
3022
3303
  return null;
3023
- const n = b(t);
3024
- if (n === "/")
3304
+ const r = T(t);
3305
+ if (r === "/")
3025
3306
  return e;
3026
- const r = n.slice(1).split("/");
3307
+ const o = r.slice(1).split("/");
3027
3308
  let s = e;
3028
- for (const o of r) {
3309
+ for (const a of o) {
3029
3310
  if (!s)
3030
3311
  return null;
3031
- if (!o)
3312
+ if (!a)
3032
3313
  continue;
3033
- const a = s.getItems();
3034
- if (a && /^\d+$/.test(o)) {
3035
- const u = Number.parseInt(o, 10);
3036
- s = a[u] ?? null;
3314
+ const c = s.getItems();
3315
+ if (c && /^\d+$/.test(a)) {
3316
+ const g = Number.parseInt(a, 10);
3317
+ s = c[g] ?? null;
3037
3318
  continue;
3038
3319
  }
3039
- const c = s.getProperties();
3040
- if (!c)
3041
- return null;
3042
- const l = c[o];
3043
- if (!(l instanceof d))
3044
- return null;
3045
- s = l;
3320
+ const u = s.getProperties();
3321
+ if (u && a in u) {
3322
+ const g = u[a];
3323
+ if (!(g instanceof h))
3324
+ return null;
3325
+ s = g;
3326
+ continue;
3327
+ }
3328
+ const d = this.specialSegmentNode(s, a, n);
3329
+ if (d !== void 0) {
3330
+ s = d;
3331
+ continue;
3332
+ }
3333
+ return null;
3046
3334
  }
3047
3335
  return s;
3048
3336
  }
3337
+ static specialSegmentNode(e, t, n) {
3338
+ switch (t) {
3339
+ case "name":
3340
+ return new h().setValue(e.getName() ?? null);
3341
+ case "description":
3342
+ return new h().setValue(e.getDescription() ?? null);
3343
+ case "type":
3344
+ return e.getType() ?? null;
3345
+ case "itemType":
3346
+ return e.getItemType() ?? null;
3347
+ case "keyType":
3348
+ return e.getKeyType() ?? null;
3349
+ case "valueType":
3350
+ return e.getValueType() ?? null;
3351
+ case "value":
3352
+ return new h().setValue(e.getValue() ?? null);
3353
+ case "blue":
3354
+ return e.getBlue() ?? null;
3355
+ case Ee.OBJECT_CONTRACTS:
3356
+ return new h().setContracts(e.getContracts());
3357
+ case "blueId": {
3358
+ const r = e.getBlueId() ?? n?.calculateBlueId?.(e) ?? pt.calculateBlueIdSync(e);
3359
+ return new h().setValue(r ?? null);
3360
+ }
3361
+ default:
3362
+ return;
3363
+ }
3364
+ }
3049
3365
  }
3050
- class _r {
3051
- constructor(e, t, n, r, s, o) {
3052
- this.execution = e, this.bundle = t, this.scopePathValue = n, this.eventNode = r, this.allowTerminatedWork = s, this.allowReservedMutation = o;
3366
+ class ui {
3367
+ constructor(e, t, n, r, o, s) {
3368
+ this.execution = e, this.bundle = t, this.scopePathValue = n, this.eventNode = r, this.allowTerminatedWork = o, this.allowReservedMutation = s;
3053
3369
  }
3054
3370
  get scopePath() {
3055
3371
  return this.scopePathValue;
@@ -3083,7 +3399,7 @@ class _r {
3083
3399
  this.shouldSkipTerminatedWork() || this.execution.runtime().addGas(e);
3084
3400
  }
3085
3401
  throwFatal(e) {
3086
- throw new m(e, g.runtimeFatal(e));
3402
+ throw new E(e, w.runtimeFatal(e));
3087
3403
  }
3088
3404
  resolvePointer(e) {
3089
3405
  return this.execution.resolvePointer(this.scopePathValue, e);
@@ -3102,20 +3418,26 @@ class _r {
3102
3418
  if (!e)
3103
3419
  return !1;
3104
3420
  try {
3105
- return j.nodeAt(
3421
+ return X.nodeAt(
3106
3422
  this.execution.runtime().document(),
3107
- e
3423
+ e,
3424
+ {
3425
+ calculateBlueId: (t) => this.execution.runtime().blue().calculateBlueIdSync(t)
3426
+ }
3108
3427
  ) != null;
3109
3428
  } catch {
3110
3429
  return !1;
3111
3430
  }
3112
3431
  }
3113
3432
  documentNodeAt(e) {
3114
- const t = j.nodeAt(
3433
+ const t = X.nodeAt(
3115
3434
  this.execution.runtime().document(),
3116
- e
3435
+ e,
3436
+ {
3437
+ calculateBlueId: (n) => this.execution.runtime().blue().calculateBlueIdSync(n)
3438
+ }
3117
3439
  );
3118
- return t instanceof d ? t : null;
3440
+ return t instanceof h ? t : null;
3119
3441
  }
3120
3442
  async terminateGracefully(e) {
3121
3443
  await this.execution.enterGracefulTermination(
@@ -3135,16 +3457,16 @@ class _r {
3135
3457
  return !this.allowTerminatedWork && this.execution.isScopeInactive(this.scopePathValue);
3136
3458
  }
3137
3459
  }
3138
- const $r = new pt({
3139
- repositories: [dt, yt, St]
3460
+ const di = new ft({
3461
+ repositories: [mt]
3140
3462
  });
3141
- class xr {
3463
+ class hi {
3142
3464
  blue;
3143
3465
  registryRef;
3144
3466
  contractLoaderRef;
3145
3467
  engine;
3146
3468
  constructor(e) {
3147
- this.registryRef = e?.registry ?? Q.create().registerDefaults().build(), this.blue = e?.blue ?? $r, this.contractLoaderRef = new xn(this.registryRef, this.blue), this.engine = new j(
3469
+ this.registryRef = e?.registry ?? ne.create().registerDefaults().build(), this.blue = e?.blue ?? di, this.contractLoaderRef = new dr(this.registryRef, this.blue), this.engine = new X(
3148
3470
  this.contractLoaderRef,
3149
3471
  this.registryRef,
3150
3472
  this.blue
@@ -3177,14 +3499,14 @@ class xr {
3177
3499
  return this.contractLoaderRef;
3178
3500
  }
3179
3501
  static builder() {
3180
- return new Fr();
3502
+ return new pi();
3181
3503
  }
3182
3504
  }
3183
- class Fr {
3505
+ class pi {
3184
3506
  contractRegistry;
3185
3507
  blueInstance;
3186
3508
  constructor() {
3187
- this.contractRegistry = Q.create().registerDefaults().build();
3509
+ this.contractRegistry = ne.create().registerDefaults().build();
3188
3510
  }
3189
3511
  withRegistry(e) {
3190
3512
  return this.contractRegistry = e, this;
@@ -3196,16 +3518,16 @@ class Fr {
3196
3518
  return this.blueInstance = e, this;
3197
3519
  }
3198
3520
  build() {
3199
- return new xr({
3521
+ return new hi({
3200
3522
  registry: this.contractRegistry,
3201
3523
  blue: this.blueInstance
3202
3524
  });
3203
3525
  }
3204
3526
  }
3205
- class Ye {
3527
+ class dt {
3206
3528
  process(e, t) {
3207
3529
  const n = t.getValue();
3208
- if (W(n)) {
3530
+ if (G(n)) {
3209
3531
  const r = t.clone();
3210
3532
  return r.setValue(n), r.setProperties(void 0), r.setItems(void 0), r.setType(void 0), r;
3211
3533
  }
@@ -3216,118 +3538,123 @@ class Ye {
3216
3538
  */
3217
3539
  postProcess(e, t) {
3218
3540
  const n = t.getValue();
3219
- if (W(n) && e.getValue() !== n && n !== void 0) {
3541
+ if (G(n) && e.getValue() !== n && n !== void 0) {
3220
3542
  const r = e.clone();
3221
3543
  return r.setValue(n), r;
3222
3544
  }
3223
3545
  return e;
3224
3546
  }
3225
3547
  }
3226
- const ai = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3548
+ const Di = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3227
3549
  __proto__: null,
3228
- ExpressionPreserver: Ye
3550
+ ExpressionPreserver: dt
3229
3551
  }, Symbol.toStringTag, { value: "Module" }));
3230
- function ci() {
3231
- return new R.SequentialMergingProcessor([
3232
- new R.ValuePropagator(),
3233
- new Ye(),
3234
- new R.TypeAssigner(),
3235
- new R.ListProcessor(),
3236
- new R.DictionaryProcessor(),
3237
- new R.BasicTypesVerifier()
3552
+ function Bi() {
3553
+ return new O.SequentialMergingProcessor([
3554
+ new O.ValuePropagator(),
3555
+ new dt(),
3556
+ new O.TypeAssigner(),
3557
+ new O.ListProcessor(),
3558
+ new O.DictionaryProcessor(),
3559
+ new O.BasicTypesVerifier()
3238
3560
  ]);
3239
3561
  }
3240
3562
  export {
3241
- Rn as ChannelBinding,
3242
- Kn as ChannelRunner,
3243
- Vn as CheckpointManager,
3244
- Un as CheckpointRecord,
3245
- Ue as CodeBlockEvaluationError,
3246
- M as ContractBundle,
3247
- Pn as ContractBundleBuilder,
3248
- xn as ContractLoader,
3249
- ln as ContractProcessorRegistry,
3250
- Q as ContractProcessorRegistryBuilder,
3251
- Pe as DocumentProcessingResult,
3252
- Or as DocumentProcessingRuntime,
3253
- xr as DocumentProcessor,
3254
- Fr as DocumentProcessorBuilder,
3255
- cr as EmissionRegistry,
3256
- Ar as GasMeter,
3257
- Tn as HandlerBinding,
3258
- I as KEY_CHECKPOINT,
3259
- Ne as KEY_EMBEDDED,
3260
- Me as KEY_INITIALIZED,
3261
- Ae as KEY_TERMINATED,
3262
- ai as MergingProcessors,
3263
- Oe as PROCESSOR_MANAGED_CHANNEL_BLUE_IDS,
3264
- rr as PatchEngine,
3265
- ni as ProcessorContractConstants,
3266
- j as ProcessorEngine,
3267
- g as ProcessorErrors,
3268
- Lr as ProcessorExecution,
3269
- _r as ProcessorExecutionContext,
3270
- m as ProcessorFatalError,
3271
- ri as ProcessorPointerConstants,
3272
- oe as QuickJSEvaluator,
3273
- Be as RELATIVE_CHECKPOINT,
3274
- A as RELATIVE_CONTRACTS,
3275
- Nt as RELATIVE_EMBEDDED,
3276
- ne as RELATIVE_INITIALIZED,
3277
- De as RELATIVE_TERMINATED,
3278
- ie as RESERVED_CONTRACT_KEYS,
3279
- q as RunTerminationError,
3280
- Qn as ScopeExecutor,
3281
- ar as ScopeRuntimeContext,
3282
- Xn as TerminationService,
3283
- Zr as andThen,
3284
- ze as canonicalSignature,
3285
- ye as canonicalSize,
3286
- O as channelContractBaseSchema,
3563
+ Jn as ChannelBinding,
3564
+ yr as ChannelRunner,
3565
+ gr as CheckpointManager,
3566
+ mr as CheckpointRecord,
3567
+ Ye as CodeBlockEvaluationError,
3568
+ L as ContractBundle,
3569
+ Qn as ContractBundleBuilder,
3570
+ dr as ContractLoader,
3571
+ Tn as ContractProcessorRegistry,
3572
+ ne as ContractProcessorRegistryBuilder,
3573
+ _e as DocumentProcessingResult,
3574
+ si as DocumentProcessingRuntime,
3575
+ hi as DocumentProcessor,
3576
+ pi as DocumentProcessorBuilder,
3577
+ xr as EmissionRegistry,
3578
+ oi as GasMeter,
3579
+ Gn as HandlerBinding,
3580
+ N as KEY_CHECKPOINT,
3581
+ Fe as KEY_EMBEDDED,
3582
+ Ue as KEY_INITIALIZED,
3583
+ ze as KEY_TERMINATED,
3584
+ Di as MergingProcessors,
3585
+ $e as PROCESSOR_MANAGED_CHANNEL_BLUE_IDS,
3586
+ Or as PatchEngine,
3587
+ Pi as ProcessorContractConstants,
3588
+ X as ProcessorEngine,
3589
+ w as ProcessorErrors,
3590
+ li as ProcessorExecution,
3591
+ ui as ProcessorExecutionContext,
3592
+ E as ProcessorFatalError,
3593
+ Mi as ProcessorPointerConstants,
3594
+ pe as QuickJSEvaluator,
3595
+ Ve as RELATIVE_CHECKPOINT,
3596
+ x as RELATIVE_CONTRACTS,
3597
+ bt as RELATIVE_EMBEDDED,
3598
+ ce as RELATIVE_INITIALIZED,
3599
+ He as RELATIVE_TERMINATED,
3600
+ de as RESERVED_CONTRACT_KEYS,
3601
+ Y as RunTerminationError,
3602
+ kr as ScopeExecutor,
3603
+ Lr as ScopeRuntimeContext,
3604
+ Rr as TerminationService,
3605
+ ki as andThen,
3606
+ Ge as canonicalSignature,
3607
+ ve as canonicalSize,
3608
+ F as channelContractBaseSchema,
3287
3609
  en as channelEventCheckpointSchema,
3288
- Kt as containsExpression,
3289
- ae as contractBaseSchema,
3290
- ci as createDefaultMergingProcessor,
3291
- Ge as createPicomatchShouldResolve,
3292
- jt as documentUpdateChannelSchema,
3293
- Jt as embeddedNodeChannelSchema,
3294
- kt as err,
3295
- We as evaluateQuickJSExpression,
3296
- Wt as extractExpressionContent,
3297
- qe as handlerContractBaseSchema,
3298
- tn as initializationMarkerSchema,
3299
- Jr as isErr,
3300
- W as isExpression,
3301
- jr as isOk,
3302
- se as isProcessorManagedChannelBlueId,
3303
- Pt as isReservedContractKey,
3304
- ii as joinRelativePointers,
3305
- si as jsonPatchSchema,
3306
- Qt as lifecycleChannelSchema,
3307
- Qr as map,
3308
- Yr as mapErr,
3309
- H as markerContractBaseSchema,
3310
- ti as match,
3610
+ Ft as containsExpression,
3611
+ fe as contractBaseSchema,
3612
+ Bi as createDefaultMergingProcessor,
3613
+ tt as createPicomatchShouldResolve,
3614
+ dn as documentAnchorsMarkerSchema,
3615
+ fn as documentLinksMarkerSchema,
3616
+ Vt as documentUpdateChannelSchema,
3617
+ Kt as embeddedNodeChannelSchema,
3618
+ yt as err,
3619
+ et as evaluateQuickJSExpression,
3620
+ Ut as extractExpressionContent,
3621
+ rt as handlerContractBaseSchema,
3622
+ nn as initializationMarkerSchema,
3623
+ Si as isErr,
3624
+ G as isExpression,
3625
+ Ci as isOk,
3626
+ he as isProcessorManagedChannelBlueId,
3627
+ vt as isReservedContractKey,
3628
+ Ni as joinRelativePointers,
3629
+ Oi as jsonPatchSchema,
3630
+ jt as lifecycleChannelSchema,
3631
+ vi as map,
3632
+ bi as mapErr,
3633
+ R as markerContractBaseSchema,
3634
+ Ri as match,
3635
+ gn as myosParticipantsOrchestrationMarkerSchema,
3636
+ En as myosSessionInteractionMarkerSchema,
3311
3637
  Xt as myosTimelineChannelSchema,
3312
- b as normalizePointer,
3313
- y as normalizeScope,
3314
- Ct as ok,
3315
- sn as operationMarkerSchema,
3316
- nn as processEmbeddedMarkerSchema,
3317
- rn as processingTerminatedMarkerSchema,
3318
- $e as relativeCheckpointLastEvent,
3319
- xe as relativeCheckpointLastSignature,
3320
- J as relativeContractsEntry,
3321
- Mt as relativizePointer,
3322
- G as resolveNodeExpressions,
3323
- w as resolvePointer,
3324
- Gt as resolveTemplateString,
3325
- an as sequentialWorkflowOperationSchema,
3326
- on as sequentialWorkflowSchema,
3327
- oi as sequentialWorkflowStepSchema,
3328
- ge as stripSlashes,
3329
- Zt as timelineChannelSchema,
3330
- Yt as triggeredEventChannelSchema,
3331
- Xr as unwrapOr,
3332
- ei as unwrapOrElse
3638
+ Cn as myosWorkerAgencyMarkerSchema,
3639
+ T as normalizePointer,
3640
+ C as normalizeScope,
3641
+ gt as ok,
3642
+ cn as operationMarkerSchema,
3643
+ on as processEmbeddedMarkerSchema,
3644
+ an as processingTerminatedMarkerSchema,
3645
+ qe as relativeCheckpointLastEvent,
3646
+ je as relativeCheckpointLastSignature,
3647
+ Z as relativeContractsEntry,
3648
+ kt as relativizePointer,
3649
+ Q as resolveNodeExpressions,
3650
+ k as resolvePointer,
3651
+ zt as resolveTemplateString,
3652
+ bn as sequentialWorkflowOperationSchema,
3653
+ Sn as sequentialWorkflowSchema,
3654
+ Ai as sequentialWorkflowStepSchema,
3655
+ Ce as stripSlashes,
3656
+ Qt as timelineChannelSchema,
3657
+ Gt as triggeredEventChannelSchema,
3658
+ Ti as unwrapOr,
3659
+ Ii as unwrapOrElse
3333
3660
  };