@blue-labs/document-processor 1.37.0 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/api/document-processor.d.ts +38 -0
  2. package/dist/api/document-processor.d.ts.map +1 -0
  3. package/dist/constants/processor-contract-constants.d.ts +24 -0
  4. package/dist/constants/processor-contract-constants.d.ts.map +1 -0
  5. package/dist/constants/processor-pointer-constants.d.ts +21 -0
  6. package/dist/constants/processor-pointer-constants.d.ts.map +1 -0
  7. package/dist/engine/boundary-violation-exception.d.ts +4 -0
  8. package/dist/engine/boundary-violation-exception.d.ts.map +1 -0
  9. package/dist/engine/channel-runner.d.ts +27 -0
  10. package/dist/engine/channel-runner.d.ts.map +1 -0
  11. package/dist/engine/checkpoint-manager.d.ts +23 -0
  12. package/dist/engine/checkpoint-manager.d.ts.map +1 -0
  13. package/dist/engine/contract-bundle.d.ts +70 -0
  14. package/dist/engine/contract-bundle.d.ts.map +1 -0
  15. package/dist/engine/contract-loader.d.ts +17 -0
  16. package/dist/engine/contract-loader.d.ts.map +1 -0
  17. package/dist/engine/handler-registration-service.d.ts +27 -0
  18. package/dist/engine/handler-registration-service.d.ts.map +1 -0
  19. package/dist/engine/illegal-state-exception.d.ts +5 -0
  20. package/dist/engine/illegal-state-exception.d.ts.map +1 -0
  21. package/dist/engine/index.d.ts +11 -0
  22. package/dist/engine/index.d.ts.map +1 -0
  23. package/dist/engine/must-understand-failure.d.ts +4 -0
  24. package/dist/engine/must-understand-failure.d.ts.map +1 -0
  25. package/dist/engine/processor-engine.d.ts +66 -0
  26. package/dist/engine/processor-engine.d.ts.map +1 -0
  27. package/dist/engine/processor-execution-context.d.ts +38 -0
  28. package/dist/engine/processor-execution-context.d.ts.map +1 -0
  29. package/dist/engine/processor-fatal-error.d.ts +6 -0
  30. package/dist/engine/processor-fatal-error.d.ts.map +1 -0
  31. package/dist/engine/run-termination-error.d.ts +5 -0
  32. package/dist/engine/run-termination-error.d.ts.map +1 -0
  33. package/dist/engine/scope-executor.d.ts +60 -0
  34. package/dist/engine/scope-executor.d.ts.map +1 -0
  35. package/dist/engine/termination-service.d.ts +17 -0
  36. package/dist/engine/termination-service.d.ts.map +1 -0
  37. package/dist/index.d.ts +14 -6
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3176 -9
  40. package/dist/merge/index.d.ts +2 -2
  41. package/dist/merge/index.d.ts.map +1 -1
  42. package/dist/merge/processors/index.d.ts +1 -1
  43. package/dist/merge/processors/index.d.ts.map +1 -1
  44. package/dist/model/channels/document-update-channel.d.ts +41 -0
  45. package/dist/model/channels/document-update-channel.d.ts.map +1 -0
  46. package/dist/model/channels/embedded-node-channel.d.ts +43 -0
  47. package/dist/model/channels/embedded-node-channel.d.ts.map +1 -0
  48. package/dist/model/channels/index.d.ts +7 -0
  49. package/dist/model/channels/index.d.ts.map +1 -0
  50. package/dist/model/channels/lifecycle-channel.d.ts +40 -0
  51. package/dist/model/channels/lifecycle-channel.d.ts.map +1 -0
  52. package/dist/model/channels/myos-timeline-channel.d.ts +52 -0
  53. package/dist/model/channels/myos-timeline-channel.d.ts.map +1 -0
  54. package/dist/model/channels/timeline-channel.d.ts +43 -0
  55. package/dist/model/channels/timeline-channel.d.ts.map +1 -0
  56. package/dist/model/channels/triggered-event-channel.d.ts +40 -0
  57. package/dist/model/channels/triggered-event-channel.d.ts.map +1 -0
  58. package/dist/model/events/document-update.d.ts +15 -0
  59. package/dist/model/events/document-update.d.ts.map +1 -0
  60. package/dist/model/handlers/index.d.ts +3 -0
  61. package/dist/model/handlers/index.d.ts.map +1 -0
  62. package/dist/model/handlers/sequential-workflow-operation.d.ts +61 -0
  63. package/dist/model/handlers/sequential-workflow-operation.d.ts.map +1 -0
  64. package/dist/model/handlers/sequential-workflow.d.ts +57 -0
  65. package/dist/model/handlers/sequential-workflow.d.ts.map +1 -0
  66. package/dist/model/index.d.ts +6 -0
  67. package/dist/model/index.d.ts.map +1 -0
  68. package/dist/model/markers/channel-event-checkpoint.d.ts +40 -0
  69. package/dist/model/markers/channel-event-checkpoint.d.ts.map +1 -0
  70. package/dist/model/markers/index.d.ts +6 -0
  71. package/dist/model/markers/index.d.ts.map +1 -0
  72. package/dist/model/markers/initialization-marker.d.ts +36 -0
  73. package/dist/model/markers/initialization-marker.d.ts.map +1 -0
  74. package/dist/model/markers/operation.d.ts +39 -0
  75. package/dist/model/markers/operation.d.ts.map +1 -0
  76. package/dist/model/markers/process-embedded.d.ts +36 -0
  77. package/dist/model/markers/process-embedded.d.ts.map +1 -0
  78. package/dist/model/markers/processing-terminated-marker.d.ts +39 -0
  79. package/dist/model/markers/processing-terminated-marker.d.ts.map +1 -0
  80. package/dist/model/shared/channel-contract-base.d.ts +30 -0
  81. package/dist/model/shared/channel-contract-base.d.ts.map +1 -0
  82. package/dist/model/shared/contract-base.d.ts +16 -0
  83. package/dist/model/shared/contract-base.d.ts.map +1 -0
  84. package/dist/model/shared/handler-contract-base.d.ts +29 -0
  85. package/dist/model/shared/handler-contract-base.d.ts.map +1 -0
  86. package/dist/model/shared/index.d.ts +6 -0
  87. package/dist/model/shared/index.d.ts.map +1 -0
  88. package/dist/model/shared/json-patch.d.ts +24 -0
  89. package/dist/model/shared/json-patch.d.ts.map +1 -0
  90. package/dist/model/shared/marker-contract-base.d.ts +23 -0
  91. package/dist/model/shared/marker-contract-base.d.ts.map +1 -0
  92. package/dist/model/types.d.ts +13 -0
  93. package/dist/model/types.d.ts.map +1 -0
  94. package/dist/registry/contract-processor-registry-builder.d.ts +11 -0
  95. package/dist/registry/contract-processor-registry-builder.d.ts.map +1 -0
  96. package/dist/registry/contract-processor-registry.d.ts +17 -0
  97. package/dist/registry/contract-processor-registry.d.ts.map +1 -0
  98. package/dist/registry/index.d.ts +4 -0
  99. package/dist/registry/index.d.ts.map +1 -0
  100. package/dist/registry/processors/myos-timeline-channel-processor.d.ts +59 -0
  101. package/dist/registry/processors/myos-timeline-channel-processor.d.ts.map +1 -0
  102. package/dist/registry/processors/operation-marker-processor.d.ts +43 -0
  103. package/dist/registry/processors/operation-marker-processor.d.ts.map +1 -0
  104. package/dist/registry/processors/sequential-workflow-operation-processor.d.ts +76 -0
  105. package/dist/registry/processors/sequential-workflow-operation-processor.d.ts.map +1 -0
  106. package/dist/registry/processors/sequential-workflow-processor.d.ts +64 -0
  107. package/dist/registry/processors/sequential-workflow-processor.d.ts.map +1 -0
  108. package/dist/registry/processors/steps/javascript-code-step-executor.d.ts +8 -0
  109. package/dist/registry/processors/steps/javascript-code-step-executor.d.ts.map +1 -0
  110. package/dist/registry/processors/steps/quickjs-step-bindings.d.ts +4 -0
  111. package/dist/registry/processors/steps/quickjs-step-bindings.d.ts.map +1 -0
  112. package/dist/registry/processors/steps/trigger-event-step-executor.d.ts +7 -0
  113. package/dist/registry/processors/steps/trigger-event-step-executor.d.ts.map +1 -0
  114. package/dist/registry/processors/steps/update-document-step-executor.d.ts +11 -0
  115. package/dist/registry/processors/steps/update-document-step-executor.d.ts.map +1 -0
  116. package/dist/registry/processors/timeline-channel-processor.d.ts +50 -0
  117. package/dist/registry/processors/timeline-channel-processor.d.ts.map +1 -0
  118. package/dist/registry/processors/utils/operation-utils.d.ts +6 -0
  119. package/dist/registry/processors/utils/operation-utils.d.ts.map +1 -0
  120. package/dist/registry/processors/workflow/operation-matcher.d.ts +17 -0
  121. package/dist/registry/processors/workflow/operation-matcher.d.ts.map +1 -0
  122. package/dist/registry/processors/workflow/step-runner.d.ts +28 -0
  123. package/dist/registry/processors/workflow/step-runner.d.ts.map +1 -0
  124. package/dist/registry/types.d.ts +71 -0
  125. package/dist/registry/types.d.ts.map +1 -0
  126. package/dist/runtime/document-processing-runtime.d.ts +31 -0
  127. package/dist/runtime/document-processing-runtime.d.ts.map +1 -0
  128. package/dist/runtime/emission-registry.d.ts +14 -0
  129. package/dist/runtime/emission-registry.d.ts.map +1 -0
  130. package/dist/runtime/gas-helpers.d.ts +9 -0
  131. package/dist/runtime/gas-helpers.d.ts.map +1 -0
  132. package/dist/runtime/gas-meter.d.ts +32 -0
  133. package/dist/runtime/gas-meter.d.ts.map +1 -0
  134. package/dist/runtime/index.d.ts +6 -0
  135. package/dist/runtime/index.d.ts.map +1 -0
  136. package/dist/runtime/patch-engine.d.ts +28 -0
  137. package/dist/runtime/patch-engine.d.ts.map +1 -0
  138. package/dist/runtime/scope-runtime-context.d.ts +31 -0
  139. package/dist/runtime/scope-runtime-context.d.ts.map +1 -0
  140. package/dist/test-support/blue.d.ts +27 -0
  141. package/dist/test-support/blue.d.ts.map +1 -0
  142. package/dist/test-support/workflow.d.ts +18 -0
  143. package/dist/test-support/workflow.d.ts.map +1 -0
  144. package/dist/types/document-processing-result.d.ts +13 -0
  145. package/dist/types/document-processing-result.d.ts.map +1 -0
  146. package/dist/types/errors.d.ts +42 -0
  147. package/dist/types/errors.d.ts.map +1 -0
  148. package/dist/types/index.d.ts +4 -0
  149. package/dist/types/index.d.ts.map +1 -0
  150. package/dist/types/result.d.ts +23 -0
  151. package/dist/types/result.d.ts.map +1 -0
  152. package/dist/types/scope-contracts.d.ts +7 -0
  153. package/dist/types/scope-contracts.d.ts.map +1 -0
  154. package/dist/util/expression/exceptions.d.ts +6 -0
  155. package/dist/util/expression/exceptions.d.ts.map +1 -0
  156. package/dist/util/expression/quickjs-evaluator.d.ts +23 -0
  157. package/dist/util/expression/quickjs-evaluator.d.ts.map +1 -0
  158. package/dist/util/expression/quickjs-expression-utils.d.ts +29 -0
  159. package/dist/util/expression/quickjs-expression-utils.d.ts.map +1 -0
  160. package/dist/util/node-canonicalizer.d.ts +4 -0
  161. package/dist/util/node-canonicalizer.d.ts.map +1 -0
  162. package/dist/util/pointer-utils.d.ts +7 -0
  163. package/dist/util/pointer-utils.d.ts.map +1 -0
  164. package/package.json +21 -19
  165. package/dist/BlueDocumentProcessor.d.ts +0 -50
  166. package/dist/BlueDocumentProcessor.d.ts.map +0 -1
  167. package/dist/config.d.ts +0 -3
  168. package/dist/config.d.ts.map +0 -1
  169. package/dist/context.d.ts +0 -21
  170. package/dist/context.d.ts.map +0 -1
  171. package/dist/index.mjs +0 -1657
  172. package/dist/processors/BaseChannelProcessor.d.ts +0 -22
  173. package/dist/processors/BaseChannelProcessor.d.ts.map +0 -1
  174. package/dist/processors/ChannelEventCheckpointProcessor.d.ts +0 -13
  175. package/dist/processors/ChannelEventCheckpointProcessor.d.ts.map +0 -1
  176. package/dist/processors/CompositeTimelineChannelProcessor.d.ts +0 -9
  177. package/dist/processors/CompositeTimelineChannelProcessor.d.ts.map +0 -1
  178. package/dist/processors/DocumentUpdateChannelProcessor.d.ts +0 -9
  179. package/dist/processors/DocumentUpdateChannelProcessor.d.ts.map +0 -1
  180. package/dist/processors/EmbeddedNodeChannelProcessor.d.ts +0 -9
  181. package/dist/processors/EmbeddedNodeChannelProcessor.d.ts.map +0 -1
  182. package/dist/processors/InitializedMarkerProcessor.d.ts +0 -9
  183. package/dist/processors/InitializedMarkerProcessor.d.ts.map +0 -1
  184. package/dist/processors/LifecycleEventChannelProcessor.d.ts +0 -33
  185. package/dist/processors/LifecycleEventChannelProcessor.d.ts.map +0 -1
  186. package/dist/processors/MyOSAgentChannelProcessor.d.ts +0 -60
  187. package/dist/processors/MyOSAgentChannelProcessor.d.ts.map +0 -1
  188. package/dist/processors/MyOSTimelineChannelProcessor.d.ts +0 -9
  189. package/dist/processors/MyOSTimelineChannelProcessor.d.ts.map +0 -1
  190. package/dist/processors/OperationProcessor.d.ts +0 -13
  191. package/dist/processors/OperationProcessor.d.ts.map +0 -1
  192. package/dist/processors/ProcessEmbeddedProcessor.d.ts +0 -9
  193. package/dist/processors/ProcessEmbeddedProcessor.d.ts.map +0 -1
  194. package/dist/processors/SequentialWorkflowOperationProcessor.d.ts +0 -12
  195. package/dist/processors/SequentialWorkflowOperationProcessor.d.ts.map +0 -1
  196. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts +0 -19
  197. package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts.map +0 -1
  198. package/dist/processors/SequentialWorkflowProcessor/index.d.ts +0 -2
  199. package/dist/processors/SequentialWorkflowProcessor/index.d.ts.map +0 -1
  200. package/dist/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts +0 -8
  201. package/dist/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts.map +0 -1
  202. package/dist/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts +0 -8
  203. package/dist/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts.map +0 -1
  204. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts +0 -14
  205. package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts.map +0 -1
  206. package/dist/processors/SequentialWorkflowProcessor/types.d.ts +0 -7
  207. package/dist/processors/SequentialWorkflowProcessor/types.d.ts.map +0 -1
  208. package/dist/processors/SequentialWorkflowProcessor/utils/BindingsFactory.d.ts +0 -12
  209. package/dist/processors/SequentialWorkflowProcessor/utils/BindingsFactory.d.ts.map +0 -1
  210. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts +0 -61
  211. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts.map +0 -1
  212. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionResolver.d.ts +0 -8
  213. package/dist/processors/SequentialWorkflowProcessor/utils/ExpressionResolver.d.ts.map +0 -1
  214. package/dist/processors/TimelineChannelProcessor.d.ts +0 -9
  215. package/dist/processors/TimelineChannelProcessor.d.ts.map +0 -1
  216. package/dist/processors/TriggeredEventChannelProcessor.d.ts +0 -12
  217. package/dist/processors/TriggeredEventChannelProcessor.d.ts.map +0 -1
  218. package/dist/processors/index.d.ts +0 -15
  219. package/dist/processors/index.d.ts.map +0 -1
  220. package/dist/queue/TaskKey.d.ts +0 -22
  221. package/dist/queue/TaskKey.d.ts.map +0 -1
  222. package/dist/queue/TaskQueue.d.ts +0 -31
  223. package/dist/queue/TaskQueue.d.ts.map +0 -1
  224. package/dist/registry/ContractRegistry.d.ts +0 -47
  225. package/dist/registry/ContractRegistry.d.ts.map +0 -1
  226. package/dist/routing/EventRouter.d.ts +0 -51
  227. package/dist/routing/EventRouter.d.ts.map +0 -1
  228. package/dist/routing/buildContractEntries.d.ts +0 -3
  229. package/dist/routing/buildContractEntries.d.ts.map +0 -1
  230. package/dist/testUtils.d.ts +0 -15
  231. package/dist/testUtils.d.ts.map +0 -1
  232. package/dist/types.d.ts +0 -84
  233. package/dist/types.d.ts.map +0 -1
  234. package/dist/utils/CheckpointCache.d.ts +0 -10
  235. package/dist/utils/CheckpointCache.d.ts.map +0 -1
  236. package/dist/utils/EventTraceManager.d.ts +0 -47
  237. package/dist/utils/EventTraceManager.d.ts.map +0 -1
  238. package/dist/utils/TinyQueue.d.ts +0 -12
  239. package/dist/utils/TinyQueue.d.ts.map +0 -1
  240. package/dist/utils/checkpoint.d.ts +0 -4
  241. package/dist/utils/checkpoint.d.ts.map +0 -1
  242. package/dist/utils/document.d.ts +0 -29
  243. package/dist/utils/document.d.ts.map +0 -1
  244. package/dist/utils/eventFactories.d.ts +0 -37
  245. package/dist/utils/eventFactories.d.ts.map +0 -1
  246. package/dist/utils/exceptions.d.ts +0 -28
  247. package/dist/utils/exceptions.d.ts.map +0 -1
  248. package/dist/utils/expressionUtils.d.ts +0 -18
  249. package/dist/utils/expressionUtils.d.ts.map +0 -1
  250. package/dist/utils/initialized.d.ts +0 -5
  251. package/dist/utils/initialized.d.ts.map +0 -1
  252. package/dist/utils/logPatchError.d.ts +0 -3
  253. package/dist/utils/logPatchError.d.ts.map +0 -1
  254. package/dist/utils/path.d.ts +0 -2
  255. package/dist/utils/path.d.ts.map +0 -1
  256. package/dist/utils/typeGuard.d.ts +0 -5
  257. package/dist/utils/typeGuard.d.ts.map +0 -1
package/dist/index.mjs DELETED
@@ -1,1657 +0,0 @@
1
- import { ProcessEmbeddedSchema as V, ChannelEventCheckpointSchema as de, blueIds as f, InitializedMarkerSchema as pe, CompositeTimelineChannelSchema as fe, DocumentUpdateChannelSchema as me, EmbeddedNodeChannelSchema as U, LifecycleEventSchema as ge, TimelineEntrySchema as k, OperationSchema as ye, OperationRequestSchema as Ee, UpdateDocumentSchema as A, TriggerEventSchema as D, JavaScriptCodeSchema as j, SequentialWorkflowSchema as ve, SequentialWorkflowOperationSchema as we, TimelineChannelSchema as Te } from "@blue-repository/core-dev";
2
- import { applyBlueNodePatch as Y, BlueNode as be, isBigNumber as _, BlueNodeTypeSchema as b, ResolvedBlueNode as Pe, MergingProcessors as C } from "@blue-labs/language";
3
- import { deepFreeze as Se, isNonNullable as I, deepContains as Ce, isNullable as x } from "@blue-labs/shared-utils";
4
- import { blueIds as Z, MyOSTimelineEntrySchema as ee, MyOSTimelineChannelSchema as Ne, MyOSAgentEventSchema as ke, MyOSAgentChannelSchema as Ie } from "@blue-repository/myos-dev";
5
- const T = (...a) => a.map((e, t) => {
6
- if (typeof e != "string") return "";
7
- if (t === 0 && e === "/") return "/";
8
- const n = t > 0 ? e.replace(/^\/+/, "") : e;
9
- return t < a.length - 1 ? n.replace(/\/+$/, "") : n;
10
- }).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
11
- class te {
12
- constructor(e, t, n, o) {
13
- this.getDocument = e, this.taskInfo = t, this.blue = n, this.onFlush = o;
14
- }
15
- actions = [];
16
- get(e) {
17
- const t = this.getDocument(), n = T(this.taskInfo.nodePath, e);
18
- return t.get(n);
19
- }
20
- addPatch(e) {
21
- this.actions.push({
22
- kind: "patch",
23
- patch: {
24
- ...e,
25
- path: T(this.taskInfo.nodePath, e.path)
26
- }
27
- });
28
- }
29
- emitEvent(e) {
30
- const t = this.taskInfo.event, n = t.trace ?? [], o = {
31
- ...e,
32
- source: e.source ?? "internal",
33
- originNodePath: e.originNodePath ?? this.taskInfo.nodePath,
34
- rootEvent: e.rootEvent ?? t.rootEvent ?? t,
35
- trace: [...n],
36
- emissionType: e.emissionType ?? t.emissionType
37
- };
38
- this.actions.push({ kind: "event", event: o });
39
- }
40
- async flush() {
41
- if (!this.actions.length) return [];
42
- const e = [...this.actions];
43
- return this.actions.length = 0, await this.onFlush?.(e), e;
44
- }
45
- getNodePath() {
46
- return this.taskInfo.nodePath;
47
- }
48
- resolvePath(e) {
49
- return T(this.taskInfo.nodePath, e);
50
- }
51
- getTaskInfo() {
52
- return this.taskInfo;
53
- }
54
- getBlue() {
55
- return this.blue;
56
- }
57
- /* TODO: Move to a separate interface */
58
- loadExternalModule() {
59
- throw new Error("Not implemented");
60
- }
61
- loadBlueContent(e) {
62
- const t = this.blue.getNodeProvider().fetchFirstByBlueId(e);
63
- if (!t)
64
- throw new Error(`Blue node not found for blueId: ${e}`);
65
- return Promise.resolve(JSON.stringify(this.blue.nodeToJson(t)));
66
- }
67
- }
68
- class ne extends Error {
69
- constructor(e, t) {
70
- super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
71
- }
72
- }
73
- class oe extends Error {
74
- constructor(e, t, n) {
75
- super(
76
- `Patch ${JSON.stringify(e)} touches "${e.op === "move" || e.op === "copy" ? `${e.from} → ${e.path}` : e.path}" which is inside embedded document "${t}" (Process Embedded @ "${n}")`
77
- ), this.patch = e, this.offendingPath = t, this.contractNodePath = n, this.name = "EmbeddedDocumentModificationError";
78
- }
79
- }
80
- class Be extends Error {
81
- constructor(e, t) {
82
- super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
83
- }
84
- }
85
- class Oe extends Error {
86
- constructor(e, t) {
87
- super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
88
- }
89
- }
90
- function N(a) {
91
- return Se(a);
92
- }
93
- function B(a) {
94
- return a.clone();
95
- }
96
- function W(a, e, t = "/", n = []) {
97
- const o = a.getContracts() ?? {};
98
- for (const [r, s] of Object.entries(o))
99
- if (e.isTypeOf(s, V)) {
100
- const u = e.nodeToSchemaOutput(
101
- s,
102
- V
103
- ).paths ?? [];
104
- for (const l of u)
105
- n.push({
106
- absPath: T(t, l),
107
- contractPath: T(t, `contracts/${r}`)
108
- });
109
- }
110
- for (const [r, s] of Object.entries(a.getProperties() ?? {}))
111
- W(
112
- s,
113
- e,
114
- T(t, r),
115
- n
116
- );
117
- return n;
118
- }
119
- function z(a, e) {
120
- return a === e || a.startsWith(e.endsWith("/") ? e : e + "/");
121
- }
122
- function H(a, e) {
123
- if (!e.length) return a;
124
- let t = B(a);
125
- for (const n of e)
126
- try {
127
- t = Y(t, n, !0);
128
- } catch (o) {
129
- throw new ne(n, o);
130
- }
131
- return N(t);
132
- }
133
- function y(a) {
134
- return a != null;
135
- }
136
- function P(a) {
137
- return a instanceof be;
138
- }
139
- class Me {
140
- data;
141
- length;
142
- compare;
143
- constructor(e = [], t = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
144
- if (this.data = e, this.length = this.data.length, this.compare = t, this.length > 0)
145
- for (let n = (this.length >> 1) - 1; n >= 0; n--) this._down(n);
146
- }
147
- push(e) {
148
- this.data.push(e), this._up(this.length++);
149
- }
150
- pop() {
151
- if (this.length === 0) return;
152
- const e = this.data[0], t = this.data.pop();
153
- return --this.length > 0 && (this.data[0] = t, this._down(0)), e;
154
- }
155
- peek() {
156
- return this.data[0];
157
- }
158
- _up(e) {
159
- const { data: t, compare: n } = this, o = t[e];
160
- for (; e > 0; ) {
161
- const r = e - 1 >> 1, s = t[r];
162
- if (n(o, s) >= 0) break;
163
- t[e] = s, e = r;
164
- }
165
- t[e] = o;
166
- }
167
- _down(e) {
168
- const { data: t, compare: n } = this, o = this.length >> 1, r = t[e];
169
- for (; e < o; ) {
170
- let s = (e << 1) + 1;
171
- const i = s + 1;
172
- if (i < this.length && n(t[i], t[s]) < 0 && (s = i), n(t[s], r) >= 0) break;
173
- t[e] = t[s], e = s;
174
- }
175
- t[e] = r;
176
- }
177
- }
178
- const qe = (a, e, t, n, o, r) => [
179
- -a,
180
- e,
181
- t,
182
- n,
183
- o,
184
- r
185
- ], $e = (a, e) => {
186
- for (let t = 0; t < a.key.length; t++) {
187
- const n = a.key[t], o = e.key[t];
188
- if (n !== o)
189
- return typeof n == "number" && typeof o == "number" ? n - o : typeof n == "string" && typeof o == "string" ? n.localeCompare(o) : 0;
190
- }
191
- return 0;
192
- };
193
- class Ae {
194
- queue;
195
- /**
196
- * Creates a new task queue with the task key comparator
197
- */
198
- constructor() {
199
- this.queue = new Me([], $e);
200
- }
201
- /**
202
- * Adds a task to the queue
203
- *
204
- * @param task - The task to add
205
- */
206
- push(e) {
207
- this.queue.push(e);
208
- }
209
- /**
210
- * Removes and returns the highest priority task
211
- *
212
- * @returns The highest priority task or undefined if queue is empty
213
- */
214
- pop() {
215
- return this.queue.pop();
216
- }
217
- /**
218
- * Gets the number of tasks in the queue
219
- */
220
- get length() {
221
- return this.queue.length;
222
- }
223
- }
224
- class De {
225
- processors = /* @__PURE__ */ new Map();
226
- typeOrder = /* @__PURE__ */ new Map();
227
- /**
228
- * Creates a new contract registry
229
- *
230
- * @param list - Initial list of processors to register
231
- */
232
- constructor(e = []) {
233
- e.forEach((t, n) => this.register(t, n));
234
- }
235
- /**
236
- * Registers a new contract processor
237
- *
238
- * @param proc - The processor to register
239
- * @param orderHint - Optional priority value for execution order
240
- * @throws Error if a processor for the same contract type is already registered
241
- */
242
- register(e, t) {
243
- if (this.processors.has(e.contractBlueId))
244
- throw new Error(`Processor for ${e.contractType} already registered`);
245
- this.processors.set(e.contractBlueId, e), this.typeOrder.has(e.contractBlueId) || this.typeOrder.set(e.contractBlueId, t ?? this.typeOrder.size);
246
- }
247
- /**
248
- * Gets a processor by contract type node
249
- *
250
- * @param typeNode - The contract type node
251
- * @returns The associated processor or undefined
252
- */
253
- get(e) {
254
- if (!e) return;
255
- const t = e.getBlueId();
256
- if (t)
257
- return this.processors.get(t);
258
- }
259
- /**
260
- * Gets the order priority for a contract type node
261
- *
262
- * @param typeNode - The contract type node
263
- * @returns The priority value (0 if not found)
264
- */
265
- orderOf(e) {
266
- if (!e) return 0;
267
- const t = e.getBlueId();
268
- return t ? this.typeOrder.get(t) ?? 0 : 0;
269
- }
270
- /**
271
- * Gets all registered processors
272
- *
273
- * @returns Iterator of all registered processors
274
- */
275
- values() {
276
- return this.processors.values();
277
- }
278
- }
279
- class q {
280
- isEnabled;
281
- static MAX_TRACE_LENGTH = 128;
282
- constructor() {
283
- this.isEnabled = process.env.TRACE_BLUE_ENABLED !== "false";
284
- }
285
- /**
286
- * Creates a hop entry for the trace
287
- * @param nodePath - The path to the node
288
- * @param contractName - The name of the contract
289
- * @returns A formatted hop string
290
- */
291
- makeHop(e, t) {
292
- return `${e}#${t}`;
293
- }
294
- /**
295
- * Checks if tracing is enabled
296
- * @returns Whether tracing is enabled
297
- */
298
- shouldTrace() {
299
- return this.isEnabled;
300
- }
301
- /**
302
- * Adds a hop to the event's trace if tracing is enabled
303
- * @param event - The event to add the trace to
304
- * @param nodePath - The path to the node
305
- * @param contractName - The name of the contract
306
- * @returns A new event with the updated trace
307
- */
308
- addHop(e, t, n) {
309
- if (!this.shouldTrace())
310
- return { ...e };
311
- const o = e.trace ?? [], s = [...o.length >= q.MAX_TRACE_LENGTH ? o.slice(o.length - (q.MAX_TRACE_LENGTH - 1)) : o, this.makeHop(t, n)];
312
- return {
313
- ...e,
314
- trace: s
315
- };
316
- }
317
- /**
318
- * Gets the current trace for an event
319
- * @param event - The event to get the trace for
320
- * @returns The current trace array or an empty array if none exists
321
- */
322
- getTrace(e) {
323
- return e.trace ?? [];
324
- }
325
- /**
326
- * Clears the trace for an event
327
- * @param event - The event to clear the trace for
328
- * @returns A new event with an empty trace
329
- */
330
- clearTrace(e) {
331
- return {
332
- ...e,
333
- trace: []
334
- };
335
- }
336
- /**
337
- * Checks if tracing is enabled globally
338
- * @returns Whether tracing is enabled
339
- */
340
- isTracingEnabled() {
341
- return this.isEnabled;
342
- }
343
- }
344
- function je(a) {
345
- return Object.entries(a.getContracts() ?? {});
346
- }
347
- const xe = 64;
348
- class Ve {
349
- /**
350
- * Creates a new event router
351
- *
352
- * @param registry - Contract registry for looking up processors
353
- * @param queue - Task queue for scheduling handlers
354
- * @param getNextTaskId - Function to get the next task ID
355
- * @param getNextEventSeq - Function to get the next event sequence number
356
- */
357
- constructor(e, t, n, o, r) {
358
- this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new q();
359
- }
360
- traceManager;
361
- /**
362
- * Routes an event to matching contracts in the document
363
- *
364
- * @param doc - The document to route events in
365
- * @param pathSegments - Path segments to the current node
366
- * @param event - The event to route
367
- * @param afterTaskId - Minimum task ID to use
368
- * @param inlineDepth - Current adapter recursion depth
369
- */
370
- async route(e, t, n, o, r = 0) {
371
- if (n.seq === void 0 && (n.seq = this.getNextEventSeq()), t.length === 0) {
372
- if (n.dispatchPath) {
373
- const c = n.dispatchPath.split("/").filter(Boolean), u = { ...n };
374
- return delete u.dispatchPath, this.route(e, c, u, o, r);
375
- }
376
- if (n.source === "channel" && n.originNodePath && n.originNodePath !== "/") {
377
- const c = n.originNodePath?.split("/").filter(Boolean) ?? [];
378
- return this.route(e, c, n, o, r);
379
- }
380
- }
381
- const s = T("/", t.join("/")), i = e.get(s);
382
- P(i) && await this.traverseContracts({
383
- doc: e,
384
- node: i,
385
- nodePath: s,
386
- event: n,
387
- afterTaskId: o,
388
- pathSegments: t,
389
- inlineDepth: r
390
- });
391
- }
392
- /**
393
- * Traverses contracts at the current node and routes to matching ones
394
- */
395
- async traverseContracts(e) {
396
- const {
397
- doc: t,
398
- node: n,
399
- nodePath: o,
400
- event: r,
401
- afterTaskId: s,
402
- pathSegments: i,
403
- inlineDepth: c
404
- } = e;
405
- if (!this.shouldSkipForChannel(r, o))
406
- for (const [u, l] of je(n)) {
407
- if (!l.getType()) continue;
408
- const h = this.registry.get(l.getType());
409
- if (!h) {
410
- console.warn(`No processor registered for contract: ${u}`);
411
- continue;
412
- }
413
- const g = {
414
- nodePath: o,
415
- contractName: u,
416
- contractNode: l,
417
- event: r
418
- }, p = new te(() => t, g, this.blue);
419
- if (h.supports(r, l, p, u))
420
- switch (h.role) {
421
- case "adapter":
422
- await this.processAdapter({
423
- cp: h,
424
- event: r,
425
- contractNode: l,
426
- ctx: p,
427
- contractName: u,
428
- doc: t,
429
- afterTaskId: s,
430
- inlineDepth: c
431
- });
432
- break;
433
- case "handler":
434
- this.scheduleHandler({
435
- contractNode: l,
436
- contractName: u,
437
- nodePath: o,
438
- event: r,
439
- depth: i.length,
440
- afterTaskId: s
441
- });
442
- break;
443
- }
444
- }
445
- }
446
- /**
447
- * Processes an adapter contract and routes any emitted events
448
- */
449
- async processAdapter(e) {
450
- const {
451
- cp: t,
452
- event: n,
453
- contractNode: o,
454
- ctx: r,
455
- contractName: s,
456
- doc: i,
457
- afterTaskId: c,
458
- inlineDepth: u
459
- } = e;
460
- if (u >= xe)
461
- throw new Error("Adapter recursion limit reached");
462
- const l = this.traceManager.addHop(
463
- n,
464
- r.getTaskInfo()?.nodePath ?? "",
465
- s
466
- );
467
- await t.handle(l, o, r, s);
468
- const h = await r.flush();
469
- if (h.find((E) => E.kind === "patch"))
470
- throw new Error(
471
- `Contract "${s}" (adapter) attempted to patch the document`
472
- );
473
- const p = h.filter((E) => E.kind === "event");
474
- for (const E of p)
475
- await this.route(i, [], E.event, c, u + 1);
476
- }
477
- /**
478
- * Schedules a handler contract for future execution
479
- */
480
- scheduleHandler(e) {
481
- const { contractNode: t, contractName: n, nodePath: o, event: r, depth: s, afterTaskId: i } = e, c = t.getType();
482
- if (!c) {
483
- console.warn(`Contract node type is not defined for: ${n}`);
484
- return;
485
- }
486
- const u = this.registry.orderOf(c), l = t.get("/order"), h = _(l) ? l.toNumber() : 0, g = this.getNextTaskId() + i, p = r.seq;
487
- if (p === void 0)
488
- throw new Error("Event sequence missing");
489
- const E = qe(
490
- s,
491
- p,
492
- u,
493
- h,
494
- n,
495
- g
496
- );
497
- {
498
- const O = `${o}#${n}`, v = r.trace ?? [];
499
- if (r.source !== "external" && v.includes(O))
500
- throw new Error(
501
- `Loop detected: repeated hop ${O} within the same event chain`
502
- );
503
- }
504
- const m = this.traceManager.addHop(r, o, n);
505
- this.queue.push({
506
- key: E,
507
- nodePath: o,
508
- contractName: n,
509
- contractNode: t,
510
- event: m
511
- });
512
- }
513
- /**
514
- * Checks if an event should be skipped because it came from another channel node
515
- */
516
- shouldSkipForChannel(e, t) {
517
- return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
518
- }
519
- }
520
- const _e = (a, e, t) => {
521
- (t instanceof ne || t instanceof oe) && console.error(
522
- `[Blue] Failed to apply patches for contract "${a}" on event ${JSON.stringify(e)}`,
523
- t
524
- );
525
- };
526
- function F(a, e) {
527
- const t = B(a), n = (o) => {
528
- if (!P(o)) return;
529
- const r = o.getContracts();
530
- (!r?.checkpoint || !b.isTypeOf(
531
- r.checkpoint,
532
- de
533
- )) && o.addContract(
534
- "checkpoint",
535
- e.jsonValueToNode({
536
- type: {
537
- name: "Channel Event Checkpoint",
538
- blueId: f["Channel Event Checkpoint"]
539
- },
540
- lastEvents: {}
541
- })
542
- );
543
- };
544
- n(t);
545
- for (const { absPath: o } of W(t, e)) {
546
- const r = t.get(o);
547
- P(r) && n(r);
548
- }
549
- return N(t);
550
- }
551
- function Re(a, e) {
552
- const t = B(a);
553
- return P(t) && (re(t, e) || t.addContract(
554
- "initialized",
555
- e.jsonValueToNode({
556
- type: {
557
- name: "Initialized Marker",
558
- blueId: f["Initialized Marker"]
559
- }
560
- })
561
- )), N(t);
562
- }
563
- function re(a, e) {
564
- const t = a.getContracts();
565
- return Object.values(t ?? {}).some(
566
- (n) => e.isTypeOf(n, pe, {
567
- checkSchemaExtensions: !0
568
- })
569
- );
570
- }
571
- class We {
572
- constructor(e) {
573
- this.cache = e;
574
- }
575
- contractType = "Channel Event Checkpoint";
576
- contractBlueId = f["Channel Event Checkpoint"];
577
- role = "handler";
578
- supports(e) {
579
- return e.source === "channel" && e.rootEvent?.payload === e.payload && e.rootEvent?.source === "external";
580
- }
581
- async getEventBlueId(e, t) {
582
- const n = e.rootEvent?.payload;
583
- if (!n)
584
- throw new Error(
585
- "Cannot calculate blueId for checkpoint: missing root event payload"
586
- );
587
- if (n instanceof Pe) {
588
- const o = n.getMinimalNode();
589
- return await t.getBlue().calculateBlueId(o);
590
- }
591
- return await t.getBlue().calculateBlueId(n);
592
- }
593
- async handle(e, t, n) {
594
- if (!e.channelName || !e.rootEvent?.seq) return;
595
- const o = await this.getEventBlueId(e, n), r = n.getNodePath().replace(/\/contracts\/checkpoint$/, "");
596
- this.cache.record(r, e, o);
597
- }
598
- }
599
- const X = (a, e) => a.get(e) !== void 0;
600
- class Je {
601
- firstSeen = /* @__PURE__ */ new Map();
602
- record(e, t, n) {
603
- const o = e;
604
- this.firstSeen.has(o) || this.firstSeen.set(o, { docBase: e, event: t, eventBlueId: n });
605
- }
606
- /** Turn cached data into JSON-Patch ops */
607
- flush(e) {
608
- const t = [];
609
- for (const { docBase: n, event: o, eventBlueId: r } of this.firstSeen.values()) {
610
- if (!o.channelName) continue;
611
- const s = T(
612
- n,
613
- "contracts/checkpoint/lastEvents",
614
- o.channelName
615
- ), i = `${s}/blueId`;
616
- X(e, s) ? t.push({
617
- op: X(e, i) ? "replace" : "add",
618
- path: i,
619
- val: r
620
- }) : t.push({
621
- op: "add",
622
- path: s,
623
- val: { blueId: r }
624
- });
625
- }
626
- return t;
627
- }
628
- clear() {
629
- this.firstSeen.clear();
630
- }
631
- }
632
- class Le {
633
- contractType = "Composite Timeline Channel";
634
- contractBlueId = f["Composite Timeline Channel"];
635
- role = "adapter";
636
- supports(e, t, n) {
637
- const o = n.getBlue().nodeToSchemaOutput(t, fe);
638
- return !o.channels || !e.channelName ? !1 : o.channels.includes(e.channelName);
639
- }
640
- handle(e, t, n, o) {
641
- n.emitEvent({
642
- payload: e.payload,
643
- channelName: o,
644
- source: "channel"
645
- });
646
- }
647
- }
648
- class S {
649
- role = "adapter";
650
- /**
651
- * Base implementation of supports that checks if the event is not from a channel
652
- * Derived classes should call this method first in their supports implementation
653
- */
654
- baseSupports(e) {
655
- return e.source !== "channel";
656
- }
657
- }
658
- class Ue extends S {
659
- contractType = "Document Update Channel";
660
- contractBlueId = f["Document Update Channel"];
661
- supports(e, t, n) {
662
- if (!this.baseSupports(e) || e.emissionType !== "update") return !1;
663
- const o = n.getBlue().nodeToSchemaOutput(t, me), r = e.payload.get("/path");
664
- if (!r) return !1;
665
- const s = o.path;
666
- return I(s) && r === n.resolvePath(s);
667
- }
668
- handle(e, t, n, o) {
669
- n.emitEvent({
670
- payload: e.payload,
671
- channelName: o,
672
- source: "channel"
673
- });
674
- }
675
- }
676
- class ze extends S {
677
- contractType = "Embedded Node Channel";
678
- contractBlueId = f["Embedded Node Channel"];
679
- supports(e, t, n) {
680
- if (!this.baseSupports(e)) return !1;
681
- const o = n.getBlue().nodeToSchemaOutput(t, U);
682
- return y(e.originNodePath) && y(o.path) && e.originNodePath === n.resolvePath(o.path);
683
- }
684
- handle(e, t, n, o) {
685
- const r = n.getBlue().nodeToSchemaOutput(t, U), { originNodePath: s, payload: i } = e;
686
- y(r.path) && s === n.resolvePath(r.path) && n.emitEvent({
687
- payload: i,
688
- channelName: o,
689
- source: "channel"
690
- });
691
- }
692
- }
693
- class He {
694
- contractType = "Initialized Marker";
695
- contractBlueId = f["Initialized Marker"];
696
- role = "marker";
697
- supports() {
698
- return !1;
699
- }
700
- handle() {
701
- }
702
- }
703
- class Fe extends S {
704
- contractType = "Lifecycle Event Channel";
705
- contractBlueId = f["Lifecycle Event Channel"];
706
- supports(e, t, n) {
707
- return !this.baseSupports(e) || e.emissionType !== "lifecycle" || !this.isLifecycleEvent(e, n) ? !1 : this.isEventPatternMatch(e, t, n);
708
- }
709
- handle(e, t, n, o) {
710
- n.emitEvent({
711
- payload: e.payload,
712
- channelName: o,
713
- source: "channel",
714
- emissionType: e.emissionType
715
- });
716
- }
717
- /**
718
- * Checks if the event is a supported lifecycle event type
719
- */
720
- isLifecycleEvent(e, t) {
721
- const n = t.getBlue(), o = e.payload;
722
- return n.isTypeOf(o, ge, {
723
- checkSchemaExtensions: !0
724
- });
725
- }
726
- /**
727
- * Checks if the event matches the channel's event pattern (if specified)
728
- */
729
- isEventPatternMatch(e, t, n) {
730
- const o = t.getProperties()?.event;
731
- if (!o)
732
- return !0;
733
- try {
734
- const r = n.getBlue(), s = r.resolve(e.payload);
735
- return r.isTypeOfNode(s, o);
736
- } catch (r) {
737
- return console.warn("Error during lifecycle event pattern matching:", r), !1;
738
- }
739
- }
740
- }
741
- const Q = (a, e) => {
742
- const t = e.getBlue();
743
- return t.isTypeOf(a.payload, k) || t.isTypeOf(a.payload, ee);
744
- };
745
- class Xe extends S {
746
- contractType = "MyOS Timeline Channel";
747
- contractBlueId = Z["MyOS Timeline Channel"];
748
- supports(e, t, n) {
749
- if (!this.baseSupports(e) || !Q(e, n)) return !1;
750
- const r = n.getBlue().nodeToSchemaOutput(
751
- e.payload,
752
- ee
753
- ), s = n.getBlue().nodeToSchemaOutput(t, Ne), i = r.timeline?.timelineId;
754
- return y(s.timelineId) && y(i) && i === s.timelineId;
755
- }
756
- handle(e, t, n, o) {
757
- Q(e, n) && n.emitEvent({
758
- payload: e.payload,
759
- channelName: o,
760
- source: "channel"
761
- });
762
- }
763
- }
764
- class Qe extends S {
765
- contractType = "MyOS Agent Channel";
766
- contractBlueId = Z["MyOS Agent Channel"];
767
- supports(e, t, n) {
768
- if (!this.baseSupports(e)) return !1;
769
- try {
770
- const { myosAgentEvent: o, myosAgentChannel: r } = this.parseEventAndChannel(
771
- e,
772
- t,
773
- n
774
- );
775
- return this.isAgentMatch(o, r) && this.isEventPatternMatch(o, r, n);
776
- } catch (o) {
777
- return console.warn("Error in MyOSAgentChannelProcessor.supports:", o), !1;
778
- }
779
- }
780
- handle(e, t, n, o) {
781
- n.emitEvent({
782
- payload: e.payload,
783
- channelName: o,
784
- source: "channel"
785
- });
786
- }
787
- /**
788
- * Parses and validates the event payload and channel configuration
789
- * @throws {Error} If schema validation fails
790
- */
791
- parseEventAndChannel(e, t, n) {
792
- const o = n.getBlue(), r = o.nodeToSchemaOutput(
793
- e.payload,
794
- ke
795
- ), s = o.nodeToSchemaOutput(
796
- t,
797
- Ie
798
- );
799
- return { myosAgentEvent: r, myosAgentChannel: s };
800
- }
801
- /**
802
- * Checks if the agent IDs match between event and channel
803
- * @param myosAgentEvent - The parsed agent event
804
- * @param myosAgentChannel - The parsed agent channel configuration
805
- * @returns true if both have valid agent IDs and they match
806
- */
807
- isAgentMatch(e, t) {
808
- const n = e.agentId, o = t.agent?.agentId;
809
- return y(n) && y(o) && n === o;
810
- }
811
- /**
812
- * Checks if the event pattern matches the channel's event filter
813
- *
814
- * @param myosAgentEvent - The parsed agent event
815
- * @param myosAgentChannel - The parsed agent channel configuration
816
- * @param ctx - Processing context for Blue instance access
817
- * @returns true if the event matches the channel's filter criteria
818
- *
819
- * **Matching Logic:**
820
- * - If no event pattern is specified in channel → matches all events
821
- * - If channel has event pattern but incoming event has no event data → no match
822
- * - Otherwise → uses deep containment matching (event must contain all channel pattern fields)
823
- */
824
- isEventPatternMatch(e, t, n) {
825
- const o = t.event;
826
- if (!o)
827
- return !0;
828
- const r = e.event;
829
- if (!r)
830
- return !1;
831
- try {
832
- const s = n.getBlue(), i = s.nodeToJson(r), c = s.nodeToJson(o);
833
- return Ce(i, c);
834
- } catch (s) {
835
- return console.warn("Error during event pattern matching:", s), !1;
836
- }
837
- }
838
- }
839
- class Ge {
840
- contractType = "Operation";
841
- contractBlueId = f.Operation;
842
- role = "adapter";
843
- supports(e, t, n, o) {
844
- const s = n.getBlue().nodeToSchemaOutput(t, ye), i = this.parseEventPayload(e, n), c = this.isOperationNameMatch(
845
- i,
846
- o
847
- ), u = this.isOperationChannelMatch(
848
- e,
849
- s
850
- ), l = this.isRequestPatternMatch(
851
- i,
852
- s,
853
- n
854
- );
855
- return c && u && l;
856
- }
857
- async handle(e, t, n, o) {
858
- n.emitEvent({
859
- payload: e.payload,
860
- channelName: o,
861
- source: "channel"
862
- });
863
- }
864
- parseEventPayload(e, t) {
865
- const n = t.getBlue();
866
- if (n.isTypeOf(e.payload, k, {
867
- checkSchemaExtensions: !0
868
- })) {
869
- const o = n.nodeToSchemaOutput(
870
- e.payload,
871
- k
872
- );
873
- if (o.message)
874
- return n.nodeToSchemaOutput(
875
- o.message,
876
- Ee
877
- );
878
- }
879
- return null;
880
- }
881
- isOperationNameMatch(e, t) {
882
- return y(e?.operation) && e?.operation === t;
883
- }
884
- isOperationChannelMatch(e, t) {
885
- const n = t.channel;
886
- return x(n) ? !0 : e.source === "channel" && e.channelName === n;
887
- }
888
- isRequestPatternMatch(e, t, n) {
889
- const o = t.request;
890
- if (x(o))
891
- return !0;
892
- const r = n.getBlue(), s = e?.request;
893
- if (x(s))
894
- return !1;
895
- const i = r.resolve(s);
896
- return r.isTypeOfNode(i, o);
897
- }
898
- }
899
- class Ke {
900
- contractType = "Process Embedded";
901
- role = "adapter";
902
- contractBlueId = f["Process Embedded"];
903
- supports(e) {
904
- return e.source !== "channel";
905
- }
906
- handle(e, t, n) {
907
- const o = n.getBlue().nodeToSchemaOutput(t, V);
908
- for (const r of o.paths ?? [])
909
- n.emitEvent({
910
- ...e,
911
- dispatchPath: n.resolvePath(r)
912
- });
913
- }
914
- }
915
- const Ye = !process.env.SKIP_ISOLATED_VM;
916
- let d = null;
917
- if (Ye)
918
- try {
919
- d = require("isolated-vm");
920
- } catch {
921
- console.warn("isolated-vm not available, using fallback evaluation method");
922
- }
923
- function Ze(a) {
924
- return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(a) || /\bexport\s+/.test(a);
925
- }
926
- class $ {
927
- static getIvmUnavailableMessage() {
928
- const e = typeof process < "u" && process.version ? process.version : "unknown", t = typeof process < "u" && process.platform ? process.platform : "unknown", n = typeof process < "u" && process.arch ? process.arch : "unknown";
929
- return [
930
- "isolated-vm is required for expression evaluation but could not be loaded.",
931
- "This feature only works in a Node.js environment with the native addon available.",
932
- "",
933
- `Detected environment: Node ${e} on ${t}/${n}.`,
934
- "",
935
- "Common causes:",
936
- "- Running in a non-Node environment (browser, edge/runtime without Node).",
937
- "- 'isolated-vm' is not installed, or failed to build its native addon.",
938
- "- The module was bundled/stripped by a build tool.",
939
- "",
940
- "How to fix:",
941
- "- Ensure 'isolated-vm' is listed in dependencies (not devDependencies) of the executing package.",
942
- "- Reinstall or rebuild: npm ci && npm rebuild isolated-vm (or equivalent with your package manager).",
943
- "- Run this code on a supported Node.js runtime (not browser/edge workers)."
944
- ].join(`
945
- `);
946
- }
947
- static async ensureIvm() {
948
- if (d)
949
- return d;
950
- try {
951
- typeof require == "function" ? d = require("isolated-vm") : d = (await import("isolated-vm")).default ?? await import("isolated-vm");
952
- } catch (e) {
953
- console.error(e), d = null;
954
- }
955
- return d;
956
- }
957
- /**
958
- * Main evaluation method - chooses between secure and simple evaluation strategies
959
- */
960
- static async evaluate({
961
- code: e,
962
- ctx: t,
963
- bindings: n = {},
964
- options: o = {}
965
- }) {
966
- if (await this.ensureIvm(), !d)
967
- throw new Error(this.getIvmUnavailableMessage());
968
- return this.evaluateSecure(e, n, t, o);
969
- }
970
- /**
971
- * Secure evaluation using isolated-vm with support for ES modules
972
- */
973
- static async evaluateSecure(e, t, n, o = {}) {
974
- if (!d) throw new Error(this.getIvmUnavailableMessage());
975
- const r = new d.Isolate({ memoryLimit: 32 }), s = await r.createContext(), i = s.global;
976
- try {
977
- await this.setupIsolateEnvironment(i, t);
978
- const c = /* @__PURE__ */ new Map(), u = this.createModuleResolver(
979
- r,
980
- s,
981
- c,
982
- n
983
- );
984
- let l;
985
- return Ze(e) ? l = await this.evaluateESModule(
986
- r,
987
- s,
988
- e,
989
- o,
990
- u
991
- ) : l = await this.evaluateSimpleScript(
992
- r,
993
- s,
994
- e,
995
- t,
996
- o
997
- ), this.deepClone(l);
998
- } catch (c) {
999
- throw o.isCodeBlock ? new Oe(e, c) : new Be(e, c);
1000
- } finally {
1001
- s.release(), r.dispose();
1002
- }
1003
- }
1004
- /**
1005
- * Setup the isolated VM environment with necessary host functions and data
1006
- */
1007
- static async setupIsolateEnvironment(e, t) {
1008
- if (!d) throw new Error("isolated-vm not available");
1009
- const n = new d.Callback(
1010
- (...r) => console.log(...r)
1011
- ), o = new d.ExternalCopy({
1012
- log: n
1013
- }).copyInto();
1014
- await e.set("console", o);
1015
- for (const [r, s] of Object.entries(t))
1016
- typeof s == "function" ? await e.set(
1017
- r,
1018
- new d.Callback(s)
1019
- ) : await e.set(r, new d.ExternalCopy(s).copyInto());
1020
- }
1021
- /**
1022
- * Create module resolver function for handling imports
1023
- */
1024
- static createModuleResolver(e, t, n, o) {
1025
- return async (r) => {
1026
- if (n.has(r)) return n.get(r);
1027
- if (r.startsWith("blue:")) {
1028
- const s = r.slice(5), i = o.loadBlueContent;
1029
- if (typeof i != "function")
1030
- throw new Error(
1031
- `ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${r})`
1032
- );
1033
- const c = await i(s), u = await e.compileModule(c);
1034
- return n.set(r, u), await u.instantiate(
1035
- t,
1036
- this.createModuleResolver(e, t, n, o)
1037
- ), u;
1038
- }
1039
- if (/^https?:\/\//.test(r)) {
1040
- let s;
1041
- if (typeof o.loadExternalModule == "function")
1042
- s = await o.loadExternalModule(r);
1043
- else
1044
- throw new Error(
1045
- `ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${r})`
1046
- );
1047
- const i = await e.compileModule(s);
1048
- return n.set(r, i), await i.instantiate(
1049
- t,
1050
- this.createModuleResolver(e, t, n, o)
1051
- ), i;
1052
- }
1053
- throw new Error(`Unsupported module specifier "${r}"`);
1054
- };
1055
- }
1056
- /**
1057
- * Evaluate code as a simple script (no imports/exports)
1058
- */
1059
- static async evaluateSimpleScript(e, t, n, o, r) {
1060
- const s = Object.keys(o).join(", "), i = Object.keys(o).map((l) => l), c = `(async (${s}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${i.join(", ")})`;
1061
- return await (await e.compileScript(c)).run(t, {
1062
- timeout: r.timeout ?? 500,
1063
- promise: !0,
1064
- copy: !0,
1065
- release: !0
1066
- });
1067
- }
1068
- /**
1069
- * Evaluate code as an ES module with import/export support
1070
- */
1071
- static async evaluateESModule(e, t, n, o, r) {
1072
- let s = n;
1073
- if (o.isCodeBlock) {
1074
- const u = /^\s*(import\s.+?;|export\s.+?;)/gm, l = (n.match(u) || []).join(
1075
- `
1076
- `
1077
- ), h = n.replace(u, "").trim();
1078
- s = `
1079
- ${l}
1080
- const run = function() {
1081
- ${h}
1082
- };
1083
- export default run();
1084
- `;
1085
- }
1086
- const i = await e.compileModule(s);
1087
- return await i.instantiate(t, r), await i.evaluate({
1088
- timeout: o.timeout ?? 500,
1089
- promise: !0,
1090
- reference: !0,
1091
- release: !0
1092
- }), await i.namespace.get("default", {
1093
- timeout: o.timeout ?? 500,
1094
- promise: !0,
1095
- copy: !0,
1096
- release: !0
1097
- });
1098
- }
1099
- /**
1100
- * Deep clones a value by serializing and deserializing it to/from JSON,
1101
- * which strips any isolate-specific object references.
1102
- */
1103
- static deepClone(e) {
1104
- return typeof e > "u" ? e : JSON.parse(JSON.stringify(e));
1105
- }
1106
- }
1107
- class J {
1108
- /**
1109
- * Creates standard bindings for workflow step execution
1110
- */
1111
- static createStandardBindings(e, t, n) {
1112
- const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), s = _(r) ? r.toNumber() : r;
1113
- return {
1114
- document: (i) => {
1115
- const c = e.get(i);
1116
- return _(c) ? c.toNumber() : P(c) ? o.nodeToJson(c, "original") : c;
1117
- },
1118
- event: s,
1119
- steps: n
1120
- };
1121
- }
1122
- }
1123
- const et = /^\$\{([\s\S]*)\}$/, tt = /\$\{([\s\S]*?)\}/, w = (a) => typeof a != "string" ? !1 : et.test(a), R = (a) => typeof a != "string" ? !1 : tt.test(a), se = (a) => {
1124
- if (!w(a))
1125
- throw new Error(`Invalid expression: ${a}`);
1126
- return a.slice(2, -1);
1127
- };
1128
- class M {
1129
- static createBindings(e, t, n) {
1130
- return J.createStandardBindings(e, t, n);
1131
- }
1132
- static async evaluate(e, t, n, o) {
1133
- const { coerceToString: r } = o;
1134
- if (w(e)) {
1135
- const s = se(e), i = await $.evaluate({
1136
- code: s,
1137
- ctx: t,
1138
- bindings: n
1139
- });
1140
- return r ? String(i ?? "") : i;
1141
- }
1142
- if (R(e)) {
1143
- const i = `\`${String(e).replace(/`/g, "\\`")}\``, c = await $.evaluate({
1144
- code: i,
1145
- ctx: t,
1146
- bindings: n
1147
- });
1148
- return String(c ?? "");
1149
- }
1150
- return r ? String(e) : e;
1151
- }
1152
- }
1153
- function G(a, e) {
1154
- const { op: t, path: n, val: o, from: r } = a;
1155
- if ((t === "move" || t === "copy") && !r)
1156
- throw new Error(`${t} operation requires 'from' path`);
1157
- if ((t === "add" || t === "replace") && o === void 0)
1158
- throw new Error(`${t} operation requires 'val' property`);
1159
- const s = {
1160
- type: "Document Update",
1161
- op: t,
1162
- path: n
1163
- };
1164
- return o !== void 0 && (s.val = o), r !== void 0 && (s.from = r), e.jsonValueToNode(s);
1165
- }
1166
- function nt(a) {
1167
- return a.jsonValueToNode({
1168
- type: "Document Processing Initiated"
1169
- });
1170
- }
1171
- class ot {
1172
- stepType = "Update Document";
1173
- supports(e) {
1174
- return b.isTypeOf(e, A);
1175
- }
1176
- async execute(e, t, n, o, r) {
1177
- const s = n.getBlue();
1178
- if (!b.isTypeOf(e, A)) return;
1179
- const i = await this.evaluateChangeset(
1180
- e.get("/changeset"),
1181
- n,
1182
- t,
1183
- r
1184
- ), c = Y(e, {
1185
- op: "replace",
1186
- path: "/changeset",
1187
- val: i
1188
- }), u = n.getBlue().nodeToSchemaOutput(c, A);
1189
- for (const l of u.changeset ?? []) {
1190
- if (!l.path) continue;
1191
- const h = await this.evaluateChangePath(
1192
- l.path,
1193
- n,
1194
- t,
1195
- r
1196
- ), g = l.val;
1197
- if ((l.op === "replace" || l.op === "add") && I(g)) {
1198
- const p = await this.evaluateChangeValue(
1199
- g,
1200
- n,
1201
- t,
1202
- r
1203
- );
1204
- n.addPatch({
1205
- op: l.op,
1206
- path: h,
1207
- val: p
1208
- }), n.emitEvent({
1209
- payload: G(
1210
- {
1211
- op: l.op,
1212
- path: n.resolvePath(h),
1213
- val: s.nodeToJson(p, "original")
1214
- },
1215
- s
1216
- ),
1217
- emissionType: "update"
1218
- });
1219
- }
1220
- l.op === "remove" && (n.addPatch({ op: l.op, path: h }), n.emitEvent({
1221
- payload: G(
1222
- {
1223
- op: l.op,
1224
- path: n.resolvePath(h),
1225
- val: null
1226
- },
1227
- s
1228
- ),
1229
- emissionType: "update"
1230
- }));
1231
- }
1232
- }
1233
- async evaluateChangeset(e, t, n, o) {
1234
- const r = t.getBlue();
1235
- if (w(e)) {
1236
- const s = se(e), i = await $.evaluate({
1237
- code: s,
1238
- ctx: t,
1239
- bindings: J.createStandardBindings(
1240
- t,
1241
- n,
1242
- o
1243
- )
1244
- });
1245
- return r.jsonValueToNode(i ?? null);
1246
- }
1247
- if (P(e))
1248
- return e;
1249
- throw new Error("Invalid changeset: expected a string or document node");
1250
- }
1251
- async evaluateChangeValue(e, t, n, o) {
1252
- const r = e.getValue(), s = t.getBlue();
1253
- if (w(r) || typeof r == "string" && R(r)) {
1254
- const i = M.createBindings(
1255
- t,
1256
- n,
1257
- o
1258
- ), c = await M.evaluate(
1259
- String(r),
1260
- t,
1261
- i,
1262
- { coerceToString: !w(r) }
1263
- );
1264
- return s.jsonValueToNode(c ?? null);
1265
- }
1266
- return e;
1267
- }
1268
- async evaluateChangePath(e, t, n, o) {
1269
- const r = M.createBindings(t, n, o);
1270
- if (w(e) || R(e)) {
1271
- const s = await M.evaluate(e, t, r, {
1272
- coerceToString: !0
1273
- });
1274
- return String(s ?? "");
1275
- }
1276
- return e;
1277
- }
1278
- }
1279
- class rt {
1280
- stepType = "Trigger Event";
1281
- supports(e) {
1282
- return b.isTypeOf(e, D);
1283
- }
1284
- async execute(e, t, n) {
1285
- const o = n.getBlue();
1286
- if (!b.isTypeOf(e, D)) return;
1287
- const r = o.nodeToSchemaOutput(e, D);
1288
- r.event && n.emitEvent({
1289
- payload: r.event,
1290
- emissionType: "triggered"
1291
- });
1292
- }
1293
- }
1294
- class st {
1295
- stepType = "JavaScript Code";
1296
- supports(e) {
1297
- return b.isTypeOf(e, j);
1298
- }
1299
- async execute(e, t, n, o, r) {
1300
- if (!b.isTypeOf(e, j)) return;
1301
- const s = n.getBlue(), i = s.nodeToSchemaOutput(
1302
- e,
1303
- j
1304
- );
1305
- if (!i.code)
1306
- throw new Error("JavaScript code is required");
1307
- const c = await $.evaluate({
1308
- code: i.code,
1309
- ctx: n,
1310
- bindings: J.createStandardBindings(n, t, r),
1311
- options: {
1312
- isCodeBlock: !0,
1313
- timeout: 500
1314
- }
1315
- });
1316
- if (c && typeof c == "object" && "events" in c) {
1317
- const u = c;
1318
- if (Array.isArray(u.events))
1319
- for (const l of u.events)
1320
- n.emitEvent({
1321
- payload: s.jsonValueToNode(l),
1322
- emissionType: "triggered"
1323
- });
1324
- }
1325
- return c;
1326
- }
1327
- }
1328
- const at = [
1329
- new ot(),
1330
- new rt(),
1331
- new st()
1332
- ];
1333
- class ae {
1334
- contractType = "Sequential Workflow";
1335
- contractBlueId = f["Sequential Workflow"];
1336
- role = "handler";
1337
- executors = [];
1338
- constructor(e = at) {
1339
- this.executors = e;
1340
- }
1341
- /** allow registering custom step executors */
1342
- registerExecutor(e) {
1343
- this.executors.push(e);
1344
- }
1345
- supports(e, t, n) {
1346
- const r = n.getBlue().nodeToSchemaOutput(
1347
- t,
1348
- ve
1349
- ), s = this.isChannelNameMatch(e, r), i = this.isEventPatternMatch(e, t, n);
1350
- return s && i;
1351
- }
1352
- async handle(e, t, n, o) {
1353
- const r = {}, s = t.getProperties()?.steps.getItems();
1354
- for (const [i, c] of (s ?? []).entries()) {
1355
- const u = this.executors.find((h) => h.supports(c));
1356
- if (!u)
1357
- throw new Error(`Unsupported workflow step type "${c.getType()}"`);
1358
- const l = await u.execute(
1359
- c,
1360
- e,
1361
- n,
1362
- o,
1363
- r
1364
- );
1365
- if (l !== void 0) {
1366
- const h = c.getName(), g = typeof h == "string" ? h : `Step${i + 1}`;
1367
- r[g] = l;
1368
- }
1369
- await n.flush();
1370
- }
1371
- }
1372
- isChannelNameMatch(e, t) {
1373
- const n = t.channel;
1374
- return I(n) && e.source === "channel" && e.channelName === n;
1375
- }
1376
- /**
1377
- * Checks if the event matches the channel's event pattern (if specified)
1378
- */
1379
- isEventPatternMatch(e, t, n) {
1380
- const o = t.getProperties()?.event;
1381
- if (!o)
1382
- return !0;
1383
- try {
1384
- const r = n.getBlue(), s = r.resolve(e.payload);
1385
- return r.isTypeOfNode(s, o);
1386
- } catch (r) {
1387
- return console.warn("Error during event pattern matching:", r), !1;
1388
- }
1389
- }
1390
- }
1391
- class it {
1392
- contractType = "Sequential Workflow Operation";
1393
- contractBlueId = f["Sequential Workflow Operation"];
1394
- role = "handler";
1395
- sequentialWorkflowProcessor;
1396
- constructor(e) {
1397
- this.sequentialWorkflowProcessor = e || new ae();
1398
- }
1399
- supports(e, t, n) {
1400
- const s = n.getBlue().nodeToSchemaOutput(
1401
- t,
1402
- we
1403
- ).operation, i = e.channelName;
1404
- return e.source === "channel" && I(i) && I(s) && i === s;
1405
- }
1406
- async handle(e, t, n, o) {
1407
- try {
1408
- await this.sequentialWorkflowProcessor.handle(e, t, n, o);
1409
- } catch (r) {
1410
- throw console.error(
1411
- "Error in SequentialWorkflowOperationProcessor.handle:",
1412
- r
1413
- ), r;
1414
- }
1415
- }
1416
- }
1417
- const K = (a) => b.isTypeOf(a.payload, k);
1418
- class ct extends S {
1419
- contractType = "Timeline Channel";
1420
- contractBlueId = f["Timeline Channel"];
1421
- supports(e, t, n) {
1422
- if (!this.baseSupports(e) || !K(e)) return !1;
1423
- const r = n.getBlue().nodeToSchemaOutput(
1424
- e.payload,
1425
- k
1426
- ), s = n.getBlue().nodeToSchemaOutput(t, Te), i = r.timeline?.timelineId;
1427
- return y(s.timelineId) && y(i) && i === s.timelineId;
1428
- }
1429
- handle(e, t, n, o) {
1430
- K(e) && n.emitEvent({
1431
- payload: e.payload,
1432
- channelName: o,
1433
- source: "channel"
1434
- });
1435
- }
1436
- }
1437
- class lt extends S {
1438
- contractType = "Triggered Event Channel";
1439
- contractBlueId = f["Triggered Event Channel"];
1440
- supports(e) {
1441
- return this.baseSupports(e) ? e.emissionType === "triggered" : !1;
1442
- }
1443
- handle(e, t, n, o) {
1444
- n.emitEvent({
1445
- payload: e.payload,
1446
- channelName: o,
1447
- source: "channel"
1448
- });
1449
- }
1450
- }
1451
- const ut = [
1452
- new Ke(),
1453
- // channels
1454
- new ze(),
1455
- new Ue(),
1456
- new ct(),
1457
- new Xe(),
1458
- new Qe(),
1459
- new Le(),
1460
- new Fe(),
1461
- new lt(),
1462
- new Ge(),
1463
- // sequential workflows
1464
- new ae(),
1465
- new it(),
1466
- // markers
1467
- new He()
1468
- ];
1469
- class gt {
1470
- /**
1471
- * Creates a new document processor
1472
- *
1473
- * @param processors - Initial list of processors to register
1474
- */
1475
- constructor(e, t = ut) {
1476
- this.blue = e, this.registry = new De(t), this.queue = new Ae(), this.router = new Ve(
1477
- this.blue,
1478
- this.registry,
1479
- this.queue,
1480
- () => ++this.taskCounter,
1481
- () => ++this.eventCounter
1482
- ), this.register(
1483
- new We(this.checkpointCache),
1484
- 9999
1485
- );
1486
- }
1487
- taskCounter = 0;
1488
- eventCounter = 0;
1489
- registry;
1490
- queue;
1491
- router;
1492
- checkpointCache = new Je();
1493
- /**
1494
- * Registers a new contract processor
1495
- *
1496
- * @param cp - The processor to register
1497
- * @param orderHint - Optional priority value for execution order
1498
- */
1499
- register(e, t) {
1500
- this.registry.register(e, t);
1501
- }
1502
- /**
1503
- * Initializes a document by emitting a Document Processing Initiated event
1504
- *
1505
- * @param document - The document to initialize
1506
- * @returns Processing result with final state and emitted events
1507
- */
1508
- async initialize(e) {
1509
- let t = F(N(e), this.blue);
1510
- const n = {
1511
- payload: nt(this.blue),
1512
- source: "internal",
1513
- emissionType: "lifecycle"
1514
- }, o = [n.payload];
1515
- await this.router.route(t, [], n, 0);
1516
- const r = await this.drainQueue(t);
1517
- return t = r.state, o.push(...r.emitted), t = Re(t, this.blue), { state: B(t), emitted: o };
1518
- }
1519
- /**
1520
- * Processes a batch of events against the document
1521
- *
1522
- * @param document - The document to process events against
1523
- * @param incoming - List of event payloads to process
1524
- * @returns Processing result with final state and emitted events
1525
- */
1526
- async processEvents(e, t) {
1527
- let n = F(N(e), this.blue);
1528
- const o = [];
1529
- if (!re(n, this.blue))
1530
- throw new Error("Document is not initialized");
1531
- for (const r of t)
1532
- try {
1533
- const s = { payload: r, source: "external" };
1534
- await this.router.route(n, [], s, 0);
1535
- const i = await this.drainQueue(n);
1536
- n = i.state, o.push(...i.emitted);
1537
- const c = this.checkpointCache.flush(n);
1538
- c.length && (n = H(n, c));
1539
- } finally {
1540
- this.checkpointCache.clear();
1541
- }
1542
- return { state: B(n), emitted: o };
1543
- }
1544
- /**
1545
- * Drains the task queue and applies all actions
1546
- */
1547
- async drainQueue(e) {
1548
- let t = e;
1549
- const n = [], o = 1e4;
1550
- let r = 0;
1551
- for (; this.queue.length; ) {
1552
- if (++r > o)
1553
- throw new Error("Possible cycle – too many iterations");
1554
- const s = this.queue.pop(), { nodePath: i, contractName: c, contractNode: u, event: l } = s, h = t.get(i);
1555
- if (!P(h) || !h.getContracts()?.[c] || !u.getType()) continue;
1556
- const g = this.registry.get(u.getType());
1557
- if (!g) {
1558
- console.warn(`No processor registered for contract: ${c}`);
1559
- continue;
1560
- }
1561
- const p = new te(
1562
- () => t,
1563
- s,
1564
- this.blue,
1565
- async (E) => {
1566
- for (const m of E)
1567
- if (m.kind === "patch") {
1568
- const O = W(
1569
- t,
1570
- this.blue
1571
- );
1572
- for (const v of O) {
1573
- const ce = m.patch.op === "move" || m.patch.op === "copy" ? [m.patch.from, m.patch.path] : [m.patch.path], L = p.getNodePath(), le = ce.some(
1574
- (he) => z(he, v.absPath)
1575
- ), ue = z(
1576
- L,
1577
- v.absPath
1578
- );
1579
- if (le && !ue)
1580
- throw new oe(
1581
- m.patch,
1582
- v.absPath,
1583
- L
1584
- );
1585
- }
1586
- try {
1587
- t = H(t, [m.patch]);
1588
- } catch (v) {
1589
- throw _e(c, l, v), v;
1590
- }
1591
- } else m.kind === "event" && (n.push(m.event.payload), await this.router.route(t, [], m.event, s.key[5]));
1592
- }
1593
- );
1594
- await g.handle(l, u, p, c), await p.flush();
1595
- }
1596
- return { state: t, emitted: n };
1597
- }
1598
- }
1599
- class ie {
1600
- process(e, t) {
1601
- const n = t.getValue();
1602
- if (w(n)) {
1603
- const o = t.clone();
1604
- return o.setValue(n), o.setProperties(void 0), o.setItems(void 0), o.setType(void 0), o;
1605
- }
1606
- return e;
1607
- }
1608
- /**
1609
- * Post-process to ensure expressions aren't overridden by subsequent processors
1610
- */
1611
- postProcess(e, t) {
1612
- const n = t.getValue();
1613
- if (w(n) && e.getValue() !== n && n !== void 0) {
1614
- const o = e.clone();
1615
- return o.setValue(n), o;
1616
- }
1617
- return e;
1618
- }
1619
- }
1620
- const yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1621
- __proto__: null,
1622
- ExpressionPreserver: ie
1623
- }, Symbol.toStringTag, { value: "Module" }));
1624
- function Et() {
1625
- return new C.SequentialMergingProcessor([
1626
- new C.ValuePropagator(),
1627
- new ie(),
1628
- new C.TypeAssigner(),
1629
- new C.ListProcessor(),
1630
- new C.DictionaryProcessor(),
1631
- new C.BasicTypesVerifier()
1632
- ]);
1633
- }
1634
- export {
1635
- gt as BlueDocumentProcessor,
1636
- We as ChannelEventCheckpointProcessor,
1637
- Oe as CodeBlockEvaluationError,
1638
- Le as CompositeTimelineChannelProcessor,
1639
- Ue as DocumentUpdateChannelProcessor,
1640
- oe as EmbeddedDocumentModificationError,
1641
- ze as EmbeddedNodeChannelProcessor,
1642
- Be as ExpressionEvaluationError,
1643
- He as InitializedMarkerProcessor,
1644
- Fe as LifecycleEventChannelProcessor,
1645
- yt as MergingProcessors,
1646
- Qe as MyOSAgentChannelProcessor,
1647
- Xe as MyOSTimelineChannelProcessor,
1648
- Ge as OperationProcessor,
1649
- ne as PatchApplicationError,
1650
- Ke as ProcessEmbeddedProcessor,
1651
- it as SequentialWorkflowOperationProcessor,
1652
- ae as SequentialWorkflowProcessor,
1653
- ct as TimelineChannelProcessor,
1654
- lt as TriggeredEventChannelProcessor,
1655
- W as collectEmbeddedPathSpecs,
1656
- Et as createDefaultMergingProcessor
1657
- };