@fluidgrids/workflows 2026.1027.1 → 2026.1028.2

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 (166) hide show
  1. package/README.md +144 -13
  2. package/dist/activation-BBh1p82z.d.cts +57 -0
  3. package/dist/activation-DnhG7SmF.d.ts +57 -0
  4. package/dist/assemble-BLqQ8lSu.d.cts +39 -0
  5. package/dist/assemble-DWgaXHd-.d.ts +39 -0
  6. package/dist/chunk-2J6TF7YI.cjs +86 -0
  7. package/dist/chunk-4LYSEANA.js +199 -0
  8. package/dist/chunk-623FVQSN.cjs +251 -0
  9. package/dist/{chunk-W32BSO3M.js → chunk-6FSHT5IL.js} +2 -2
  10. package/dist/{chunk-E3APHA6O.cjs → chunk-7AAZGVKD.js} +1 -64
  11. package/dist/chunk-ABFZWYHT.js +612 -0
  12. package/dist/{chunk-6U446SKY.js → chunk-BD7ZPG53.js} +2 -2
  13. package/dist/chunk-BO6OVILK.js +79 -0
  14. package/dist/chunk-C5OLWZ42.js +245 -0
  15. package/dist/{chunk-OSPTJCDI.cjs → chunk-CPDK3K5N.cjs} +6 -6
  16. package/dist/chunk-DHTLALBL.cjs +80 -0
  17. package/dist/chunk-DJYMDLV5.js +227 -0
  18. package/dist/{chunk-IHKXLG6I.js → chunk-E2VK7J2C.js} +1 -1
  19. package/dist/{chunk-3M34AUIY.cjs → chunk-FEW3JBYA.cjs} +3 -3
  20. package/dist/chunk-FMSW2HDF.cjs +267 -0
  21. package/dist/chunk-FR7KYWRO.cjs +41 -0
  22. package/dist/{chunk-7YR7DI7B.cjs → chunk-GBQ33SIZ.cjs} +44 -44
  23. package/dist/{chunk-6AIAC2FP.cjs → chunk-GVTZMA5C.cjs} +4 -4
  24. package/dist/{chunk-EEAIM35V.js → chunk-HWJZVOG7.js} +64 -23
  25. package/dist/chunk-I5LR3D2K.js +869 -0
  26. package/dist/chunk-IISBRUWJ.js +13 -0
  27. package/dist/chunk-JD2VQIDZ.cjs +15 -0
  28. package/dist/{chunk-UB2BHU2M.js → chunk-JZ4TOOLN.js} +1 -1
  29. package/dist/chunk-L24YIZY7.cjs +207 -0
  30. package/dist/chunk-LNUQE6D6.js +39 -0
  31. package/dist/chunk-M4BBAERY.cjs +1635 -0
  32. package/dist/chunk-N23SKIG4.js +73 -0
  33. package/dist/{chunk-TWOYB4Y7.cjs → chunk-NEIUQASE.cjs} +13 -13
  34. package/dist/chunk-P6TA5EZT.cjs +634 -0
  35. package/dist/chunk-PMCM2OH4.js +46 -0
  36. package/dist/chunk-PZCVF76Q.cjs +868 -0
  37. package/dist/{chunk-6BEW4QD6.js → chunk-QAN5MZEM.js} +1 -1
  38. package/dist/{chunk-CSYBNN3V.cjs → chunk-QKZL3ONM.cjs} +2 -2
  39. package/dist/chunk-QQ6ULXHI.cjs +885 -0
  40. package/dist/chunk-SAENRNBJ.cjs +52 -0
  41. package/dist/{chunk-TQF7MYEN.cjs → chunk-SAOBPYYJ.cjs} +134 -96
  42. package/dist/{chunk-XBIID5DY.js → chunk-SMCANK3F.js} +5 -4
  43. package/dist/{chunk-UWQWD7BP.cjs → chunk-SX2PNKKT.cjs} +18 -17
  44. package/dist/{chunk-UJNHTS6D.js → chunk-TBDXTV22.cjs} +8 -45
  45. package/dist/chunk-UK3WM7YZ.cjs +75 -0
  46. package/dist/chunk-VOKMAAJP.js +848 -0
  47. package/dist/chunk-VRHHBPT6.js +1622 -0
  48. package/dist/{chunk-5AW745OG.js → chunk-XHXIDVEC.js} +1 -1
  49. package/dist/chunk-XKJA7KX3.js +72 -0
  50. package/dist/chunk-Z2Y65YOY.cjs +7 -0
  51. package/dist/codegen/index.cjs +9 -7
  52. package/dist/codegen/index.d.cts +2 -2
  53. package/dist/codegen/index.d.ts +2 -2
  54. package/dist/codegen/index.js +6 -5
  55. package/dist/file-BOoHZgoQ.d.cts +1557 -0
  56. package/dist/file-yuPCFU5b.d.ts +1557 -0
  57. package/dist/history/index.cjs +287 -0
  58. package/dist/history/index.d.cts +157 -0
  59. package/dist/history/index.d.ts +157 -0
  60. package/dist/history/index.js +5 -0
  61. package/dist/index.cjs +134 -36
  62. package/dist/index.d.cts +137 -9
  63. package/dist/index.d.ts +137 -9
  64. package/dist/index.js +8 -3
  65. package/dist/ir/index.cjs +152 -158
  66. package/dist/ir/index.d.cts +14 -4
  67. package/dist/ir/index.d.ts +14 -4
  68. package/dist/ir/index.js +41 -50
  69. package/dist/lower-BzmUz0sq.d.cts +129 -0
  70. package/dist/lower-_-iT4HYs.d.ts +129 -0
  71. package/dist/lower-types-DQNBfWQn.d.cts +37 -0
  72. package/dist/lower-types-DQNBfWQn.d.ts +37 -0
  73. package/dist/{manifest-Duf-gHdO.d.cts → manifest-0OLw0i7k.d.cts} +1 -1
  74. package/dist/{manifest-Bp9ZJlav.d.ts → manifest-C8N6HDYl.d.ts} +1 -1
  75. package/dist/node-evaluator-4MSDKWOG.cjs +22 -0
  76. package/dist/node-evaluator-SX4LEYQC.js +12 -0
  77. package/dist/quickjs/index.cjs +236 -12
  78. package/dist/quickjs/index.d.cts +46 -5
  79. package/dist/quickjs/index.d.ts +46 -5
  80. package/dist/quickjs/index.js +230 -9
  81. package/dist/roundtrip/index.cjs +333 -131
  82. package/dist/roundtrip/index.d.cts +39 -7
  83. package/dist/roundtrip/index.d.ts +39 -7
  84. package/dist/roundtrip/index.js +185 -13
  85. package/dist/runtime/index.cjs +90 -0
  86. package/dist/runtime/index.d.cts +297 -0
  87. package/dist/runtime/index.d.ts +297 -0
  88. package/dist/runtime/index.js +8 -0
  89. package/dist/testing/index.cjs +1057 -0
  90. package/dist/testing/index.d.cts +305 -0
  91. package/dist/testing/index.d.ts +305 -0
  92. package/dist/testing/index.js +1037 -0
  93. package/dist/{types-Dr2Fn1Ax.d.ts → types-BGoPzgcl.d.cts} +1 -1
  94. package/dist/{types-Dr2Fn1Ax.d.cts → types-BGoPzgcl.d.ts} +1 -1
  95. package/dist/types-CpBBjaGX.d.cts +380 -0
  96. package/dist/types-DV-HX_Gt.d.ts +380 -0
  97. package/dist/{assemble-CrpUyd_3.d.ts → workflow-Bpr3vnA_.d.ts} +40 -160
  98. package/dist/workflow-C2a05WUJ.d.ts +444 -0
  99. package/dist/{assemble-DEf3znGD.d.cts → workflow-FXUkpIBc.d.cts} +40 -160
  100. package/dist/workflow-J-yYixny.d.cts +444 -0
  101. package/fixtures/README.md +128 -0
  102. package/fixtures/histories/activity-failure-fails-run.history.json +163 -0
  103. package/fixtures/histories/activity-retry-then-success.history.json +147 -0
  104. package/fixtures/histories/cancel-activity-abandon.history.json +126 -0
  105. package/fixtures/histories/cancel-activity-compensate.history.json +307 -0
  106. package/fixtures/histories/cancel-concurrent-non-cancellable.history.json +234 -0
  107. package/fixtures/histories/cancel-concurrent-scope-timeout.history.json +184 -0
  108. package/fixtures/histories/cancel-condition-after-cancel.history.json +200 -0
  109. package/fixtures/histories/cancel-during-timer.history.json +123 -0
  110. package/fixtures/histories/cancel-saga-compensations.history.json +325 -0
  111. package/fixtures/histories/cancel-scope-timeout.history.json +148 -0
  112. package/fixtures/histories/child-abandon-outlives-parent.history.json +191 -0
  113. package/fixtures/histories/child-cancel-default.history.json +234 -0
  114. package/fixtures/histories/child-cancel-request.history.json +206 -0
  115. package/fixtures/histories/child-durable-child-side.history.json +124 -0
  116. package/fixtures/histories/child-durable-result.history.json +163 -0
  117. package/fixtures/histories/child-failure-caught.history.json +166 -0
  118. package/fixtures/histories/child-graph-by-key.history.json +138 -0
  119. package/fixtures/histories/child-terminated-by-parent-close.history.json +85 -0
  120. package/fixtures/histories/continue-as-new-first-run.history.json +146 -0
  121. package/fixtures/histories/continue-as-new-history-limit.history.json +489 -0
  122. package/fixtures/histories/continue-as-new-last-run.history.json +147 -0
  123. package/fixtures/histories/continue-as-new-suggested.history.json +352 -0
  124. package/fixtures/histories/details-and-context.history.json +176 -0
  125. package/fixtures/histories/deterministic-values.history.json +128 -0
  126. package/fixtures/histories/engine-builtins.history.json +172 -0
  127. package/fixtures/histories/gather-activities.history.json +291 -0
  128. package/fixtures/histories/gather-all-settled.history.json +219 -0
  129. package/fixtures/histories/gather-mixed.history.json +281 -0
  130. package/fixtures/histories/input-during-running-task.history.json +111 -0
  131. package/fixtures/histories/nondeterminism-reordered.history.json +218 -0
  132. package/fixtures/histories/patched-deprecated.history.json +271 -0
  133. package/fixtures/histories/patched-new-run.history.json +270 -0
  134. package/fixtures/histories/patched-old-history.history.json +190 -0
  135. package/fixtures/histories/race-activity-wins.history.json +152 -0
  136. package/fixtures/histories/race-signal-beats-child.history.json +161 -0
  137. package/fixtures/histories/race-timeout-wins.history.json +118 -0
  138. package/fixtures/histories/side-effect-recorded.history.json +153 -0
  139. package/fixtures/histories/signal-buffered-at-start.history.json +157 -0
  140. package/fixtures/histories/signal-default-handler.history.json +187 -0
  141. package/fixtures/histories/signal-handler.history.json +191 -0
  142. package/fixtures/histories/signal-parent-child-side.history.json +132 -0
  143. package/fixtures/histories/signal-parent.history.json +202 -0
  144. package/fixtures/histories/signal-run-delivered.history.json +128 -0
  145. package/fixtures/histories/signal-run-undelivered.history.json +134 -0
  146. package/fixtures/histories/signal-wait.history.json +111 -0
  147. package/fixtures/histories/task-failure-code-error.history.json +137 -0
  148. package/fixtures/histories/task-failure-then-transient-attempt.history.json +140 -0
  149. package/fixtures/histories/timer-condition-met.history.json +201 -0
  150. package/fixtures/histories/timer-condition-timeout.history.json +118 -0
  151. package/fixtures/histories/timer-sleep-once.history.json +118 -0
  152. package/fixtures/histories/timer-sleep-sequence.history.json +210 -0
  153. package/fixtures/histories/update-accepted-completed.history.json +149 -0
  154. package/fixtures/histories/update-with-start-rejected-validation.history.json +91 -0
  155. package/package.json +44 -5
  156. package/schema/history-file.schema.json +2544 -0
  157. package/schema/ir-v2.schema.json +16 -0
  158. package/schema/run-event.schema.json +2374 -0
  159. package/schema/workflow-command.schema.json +1095 -0
  160. package/schema/workflow-task.schema.json +3560 -0
  161. package/dist/chunk-MBBKGD7K.js +0 -440
  162. package/dist/chunk-Y7NWR3WH.cjs +0 -450
  163. package/dist/lower-CXggJTIo.d.ts +0 -67
  164. package/dist/lower-DAzvsJCo.d.cts +0 -67
  165. package/dist/node-evaluator-CH3XCJND.cjs +0 -17
  166. package/dist/node-evaluator-TULXA3WE.js +0 -8
@@ -0,0 +1,868 @@
1
+ 'use strict';
2
+
3
+ var chunkSAENRNBJ_cjs = require('./chunk-SAENRNBJ.cjs');
4
+ var chunkP6TA5EZT_cjs = require('./chunk-P6TA5EZT.cjs');
5
+ var chunk623FVQSN_cjs = require('./chunk-623FVQSN.cjs');
6
+ var chunk2J6TF7YI_cjs = require('./chunk-2J6TF7YI.cjs');
7
+ var _2020_js = require('ajv/dist/2020.js');
8
+
9
+ // src/history/schema.ts
10
+ var BASE = "https://docs.fluidgrids.ai/schemas";
11
+ var RUN_EVENT_SCHEMA_ID = `${BASE}/run-event.schema.json`;
12
+ var WORKFLOW_COMMAND_SCHEMA_ID = `${BASE}/workflow-command.schema.json`;
13
+ var WORKFLOW_TASK_SCHEMA_ID = `${BASE}/workflow-task.schema.json`;
14
+ var HISTORY_FILE_SCHEMA_ID = `${BASE}/history-file.schema.json`;
15
+ var HISTORY_FILE_FORMAT = "fluidgrids.history";
16
+ var ID = { type: "string", minLength: 1, maxLength: 256 };
17
+ var NON_NEGATIVE_MS = { type: "integer", minimum: 0 };
18
+ var STRING_MAP = { type: "object", additionalProperties: { type: "string" } };
19
+ var SHARED_DEFS = {
20
+ json: {
21
+ description: "Any JSON value."
22
+ },
23
+ failure: {
24
+ type: "object",
25
+ required: ["errorType", "message"],
26
+ properties: {
27
+ errorType: { enum: [...chunk623FVQSN_cjs.ERROR_TYPES] },
28
+ message: { type: "string" },
29
+ type: { type: "string" },
30
+ details: {},
31
+ nonRetryable: { type: "boolean" },
32
+ nextRetryDelayMs: NON_NEGATIVE_MS,
33
+ category: { const: "BENIGN" },
34
+ timeoutType: { type: "string" },
35
+ cause: { $ref: "#/$defs/failure" },
36
+ stackTrace: { type: "string" },
37
+ source: { type: "string" }
38
+ },
39
+ additionalProperties: false
40
+ },
41
+ retryPolicy: {
42
+ type: "object",
43
+ required: ["retryDelay"],
44
+ description: "maxRetries absent means unlimited attempts, bounded by scheduleToCloseTimeout.",
45
+ properties: {
46
+ maxRetries: { type: "integer", minimum: 0 },
47
+ retryDelay: NON_NEGATIVE_MS,
48
+ backoffMultiplier: { type: "number", minimum: 1 },
49
+ maxDelay: NON_NEGATIVE_MS,
50
+ retryOnErrorTypes: { type: "array", items: { enum: [...chunk623FVQSN_cjs.ERROR_TYPES] } },
51
+ nonRetryableErrorTypes: { type: "array", items: { type: "string" } }
52
+ },
53
+ additionalProperties: false
54
+ },
55
+ runTarget: {
56
+ oneOf: [
57
+ {
58
+ type: "object",
59
+ required: ["runId"],
60
+ properties: { runId: ID },
61
+ additionalProperties: false
62
+ },
63
+ {
64
+ type: "object",
65
+ required: ["parent"],
66
+ properties: { parent: { const: true } },
67
+ additionalProperties: false
68
+ },
69
+ {
70
+ type: "object",
71
+ required: ["childId"],
72
+ properties: { childId: ID },
73
+ additionalProperties: false
74
+ },
75
+ {
76
+ type: "object",
77
+ required: ["workflowKey", "workflowId"],
78
+ properties: { workflowKey: ID, workflowId: ID },
79
+ additionalProperties: false
80
+ }
81
+ ]
82
+ },
83
+ childOptions: {
84
+ type: "object",
85
+ required: ["parentClosePolicy"],
86
+ properties: {
87
+ parentClosePolicy: { enum: [...chunk623FVQSN_cjs.PARENT_CLOSE_POLICIES] },
88
+ cancellationType: { enum: [...chunk623FVQSN_cjs.CHILD_CANCELLATION_TYPES] },
89
+ taskQueue: ID,
90
+ workflowId: ID,
91
+ priority: { type: "integer", minimum: 1, maximum: 5 },
92
+ summary: { type: "string", maxLength: 200 },
93
+ details: { type: "string" },
94
+ context: { type: "object" },
95
+ executionTimeout: NON_NEGATIVE_MS,
96
+ runTimeout: NON_NEGATIVE_MS,
97
+ workflowTaskTimeout: NON_NEGATIVE_MS,
98
+ startDelay: NON_NEGATIVE_MS
99
+ }
100
+ },
101
+ headers: STRING_MAP
102
+ };
103
+ function command(type, required, properties) {
104
+ return {
105
+ type: "object",
106
+ required: ["type", ...required],
107
+ properties: { type: { const: type }, headers: { $ref: "#/$defs/headers" }, ...properties },
108
+ additionalProperties: false
109
+ };
110
+ }
111
+ var COMMAND_DEFS = {
112
+ SCHEDULE_ACTIVITY: command(
113
+ "SCHEDULE_ACTIVITY",
114
+ ["activityId", "kind", "nodeType", "operation", "args", "retry"],
115
+ {
116
+ activityId: ID,
117
+ kind: { const: "node" },
118
+ nodeType: ID,
119
+ nodeVersion: { type: "string" },
120
+ operation: ID,
121
+ args: {},
122
+ connection: ID,
123
+ retry: { $ref: "#/$defs/retryPolicy" },
124
+ startToCloseTimeout: NON_NEGATIVE_MS,
125
+ scheduleToCloseTimeout: NON_NEGATIVE_MS,
126
+ scheduleToStartTimeout: NON_NEGATIVE_MS,
127
+ heartbeatTimeout: NON_NEGATIVE_MS,
128
+ cancellationType: { enum: [...chunk623FVQSN_cjs.ACTIVITY_CANCELLATION_TYPES] },
129
+ priority: { type: "integer", minimum: 1, maximum: 5 },
130
+ summary: { type: "string", maxLength: 200 },
131
+ runOn: { type: "string" }
132
+ }
133
+ ),
134
+ REQUEST_CANCEL_ACTIVITY: command("REQUEST_CANCEL_ACTIVITY", ["activityId"], { activityId: ID }),
135
+ START_TIMER: command("START_TIMER", ["timerId", "durationMs"], {
136
+ timerId: ID,
137
+ durationMs: { type: "integer", minimum: 1 },
138
+ summary: { type: "string", maxLength: 200 }
139
+ }),
140
+ CANCEL_TIMER: command("CANCEL_TIMER", ["timerId"], { timerId: ID }),
141
+ START_CHILD_RUN: {
142
+ ...command("START_CHILD_RUN", ["childId", "input", "options"], {
143
+ childId: ID,
144
+ workflowKey: ID,
145
+ workflowFn: ID,
146
+ version: { type: "string", minLength: 1 },
147
+ input: {},
148
+ options: { $ref: "#/$defs/childOptions" }
149
+ }),
150
+ oneOf: [{ required: ["workflowKey"] }, { required: ["workflowFn"] }]
151
+ },
152
+ SIGNAL_RUN: command("SIGNAL_RUN", ["externalId", "target", "name", "payload"], {
153
+ externalId: ID,
154
+ target: { $ref: "#/$defs/runTarget" },
155
+ name: ID,
156
+ payload: {}
157
+ }),
158
+ RECORD_SIDE_EFFECT: command("RECORD_SIDE_EFFECT", ["sideEffectId", "value"], {
159
+ sideEffectId: ID,
160
+ value: {}
161
+ }),
162
+ RECORD_MARKER: command("RECORD_MARKER", ["markerId", "data"], { markerId: ID, data: {} }),
163
+ COMPLETE_WORKFLOW: command("COMPLETE_WORKFLOW", ["output"], { output: {} }),
164
+ FAIL_WORKFLOW: command("FAIL_WORKFLOW", ["failure"], {
165
+ failure: { $ref: "#/$defs/failure" }
166
+ }),
167
+ CANCEL_WORKFLOW: command("CANCEL_WORKFLOW", [], {}),
168
+ UPSERT_CONTEXT: command("UPSERT_CONTEXT", ["entries"], { entries: { type: "object" } }),
169
+ RECORD_LOCAL_ACTIVITY: {
170
+ ...command("RECORD_LOCAL_ACTIVITY", ["localActivityId", "attempts"], {
171
+ localActivityId: ID,
172
+ result: {},
173
+ failure: { $ref: "#/$defs/failure" },
174
+ attempts: { type: "integer", minimum: 1 }
175
+ }),
176
+ oneOf: [{ required: ["result"] }, { required: ["failure"] }]
177
+ },
178
+ CONTINUE_AS_NEW: command("CONTINUE_AS_NEW", ["input", "options"], {
179
+ input: {},
180
+ options: { type: "object" }
181
+ }),
182
+ REQUEST_CANCEL_EXTERNAL_RUN: command("REQUEST_CANCEL_EXTERNAL_RUN", ["externalId", "target"], {
183
+ externalId: ID,
184
+ target: { $ref: "#/$defs/runTarget" }
185
+ }),
186
+ UPSERT_SEARCH_ATTRIBUTES: command("UPSERT_SEARCH_ATTRIBUTES", ["attributes"], {
187
+ attributes: { type: "object" }
188
+ }),
189
+ ACCEPT_UPDATE: command("ACCEPT_UPDATE", ["updateId"], { updateId: ID }),
190
+ REJECT_UPDATE: command("REJECT_UPDATE", ["updateId", "failure"], {
191
+ updateId: ID,
192
+ failure: { $ref: "#/$defs/failure" }
193
+ }),
194
+ COMPLETE_UPDATE: command("COMPLETE_UPDATE", ["updateId"], {
195
+ updateId: ID,
196
+ result: {},
197
+ failure: { $ref: "#/$defs/failure" }
198
+ })
199
+ };
200
+ function payload(required, properties) {
201
+ return { type: "object", required, properties };
202
+ }
203
+ var FAILURE_REF = { $ref: "#/$defs/failure" };
204
+ var EVENT_PAYLOADS = {
205
+ WORKFLOW_STARTED: payload(["workflowFn", "input"], {
206
+ workflowFn: ID,
207
+ input: {},
208
+ workflowKey: { type: "string" },
209
+ version: {},
210
+ buildId: { type: "string" },
211
+ taskQueue: { type: "string" },
212
+ parentRunId: { type: ["string", "null"] },
213
+ rootRunId: { type: ["string", "null"] },
214
+ firstRunId: { type: ["string", "null"] },
215
+ continuedFromRunId: { type: ["string", "null"] },
216
+ parentClosePolicy: { enum: [...chunk623FVQSN_cjs.PARENT_CLOSE_POLICIES] },
217
+ startDelay: NON_NEGATIVE_MS,
218
+ lastCompletionResult: {},
219
+ lastFailure: { oneOf: [{ type: "null" }, FAILURE_REF] },
220
+ summary: { type: "string" },
221
+ details: { type: "string" },
222
+ context: { type: "object" },
223
+ executionTimeout: NON_NEGATIVE_MS,
224
+ runTimeout: NON_NEGATIVE_MS,
225
+ workflowTaskTimeout: NON_NEGATIVE_MS,
226
+ versioningBehavior: { enum: ["PINNED", "AUTO_UPGRADE"] },
227
+ /** Seed of `ctx.random()`/`ctx.uuid()`; the service writes the run id. Absent: `info.runId`. */
228
+ randomnessSeed: ID
229
+ }),
230
+ WORKFLOW_TASK_SCHEDULED: payload(["taskId"], {
231
+ taskId: ID,
232
+ attempt: { type: "integer", minimum: 1 }
233
+ }),
234
+ WORKFLOW_TASK_STARTED: payload(["taskId", "attempt"], {
235
+ taskId: ID,
236
+ attempt: { type: "integer", minimum: 1 },
237
+ workerId: { type: "string" },
238
+ buildId: { type: "string" },
239
+ startedAt: {
240
+ type: "string",
241
+ description: "When the attempt started, if different from the event time (a transient attempt is recorded at completion). This is the clock the task saw: nowMs of its request."
242
+ },
243
+ historyLength: {
244
+ type: "integer",
245
+ minimum: 1,
246
+ description: "The history length the attempt was leased with (run.taskStartedSeq), when it is not this event's own seq. Required on the WORKFLOW_TASK_STARTED of a transient attempt: input events with a higher seq that precede this event arrived during the attempt and belong to the next activation."
247
+ }
248
+ }),
249
+ WORKFLOW_TASK_COMPLETED: payload(["taskId"], {
250
+ taskId: ID,
251
+ buildId: { type: "string" },
252
+ workerId: { type: "string" }
253
+ }),
254
+ WORKFLOW_TASK_FAILED: payload(["taskId", "attempt", "cause"], {
255
+ taskId: ID,
256
+ attempt: { type: "integer", minimum: 1 },
257
+ cause: { enum: [...chunk623FVQSN_cjs.TASK_FAILURE_CAUSES] },
258
+ message: { type: "string" },
259
+ stackTrace: { type: "string" },
260
+ buildId: { type: "string" }
261
+ }),
262
+ WORKFLOW_TASK_TIMED_OUT: payload(["taskId", "attempt"], {
263
+ taskId: ID,
264
+ attempt: { type: "integer", minimum: 1 }
265
+ }),
266
+ ACTIVITY_SCHEDULED: payload(["activityId", "kind", "nodeType", "operation", "args", "retry"], {
267
+ ...COMMAND_DEFS.SCHEDULE_ACTIVITY.properties,
268
+ type: void 0
269
+ }),
270
+ ACTIVITY_STARTED: payload(["activityId", "attempt"], {
271
+ activityId: ID,
272
+ attempt: { type: "integer", minimum: 1 },
273
+ workerId: { type: "string" }
274
+ }),
275
+ ACTIVITY_HEARTBEAT: payload(["activityId"], { activityId: ID, details: {} }),
276
+ ACTIVITY_COMPLETED: payload(["activityId", "attempt"], {
277
+ activityId: ID,
278
+ attempt: { type: "integer", minimum: 1 },
279
+ result: {}
280
+ }),
281
+ ACTIVITY_FAILED: payload(["activityId", "attempt", "failure"], {
282
+ activityId: ID,
283
+ attempt: { type: "integer", minimum: 1 },
284
+ failure: FAILURE_REF
285
+ }),
286
+ ACTIVITY_TIMED_OUT: payload(["activityId", "attempt", "timeoutType"], {
287
+ activityId: ID,
288
+ attempt: { type: "integer", minimum: 1 },
289
+ timeoutType: {
290
+ enum: ["START_TO_CLOSE", "SCHEDULE_TO_START", "SCHEDULE_TO_CLOSE", "HEARTBEAT"]
291
+ },
292
+ failure: FAILURE_REF
293
+ }),
294
+ ACTIVITY_CANCEL_REQUESTED: payload(["activityId"], { activityId: ID }),
295
+ ACTIVITY_CANCELLED: payload(["activityId"], { activityId: ID, details: {} }),
296
+ ACTIVITY_PAUSED: payload(["activityId"], { activityId: ID, reason: { type: "string" } }),
297
+ ACTIVITY_UNPAUSED: payload(["activityId"], { activityId: ID }),
298
+ ACTIVITY_RESET: payload(["activityId"], { activityId: ID }),
299
+ ACTIVITY_OPTIONS_UPDATED: payload(["activityId"], {
300
+ activityId: ID,
301
+ options: { type: "object" }
302
+ }),
303
+ TIMER_STARTED: payload(["timerId", "durationMs", "fireAt"], {
304
+ timerId: ID,
305
+ durationMs: { type: "integer", minimum: 1 },
306
+ fireAt: { type: "string" },
307
+ summary: { type: "string" }
308
+ }),
309
+ TIMER_FIRED: payload(["timerId"], { timerId: ID }),
310
+ TIMER_CANCELLED: payload(["timerId"], { timerId: ID }),
311
+ SIGNAL_RECEIVED: payload(["name"], {
312
+ name: ID,
313
+ payload: {},
314
+ receivedAt: { type: "string" },
315
+ actor: {},
316
+ idempotencyKey: { type: "string" }
317
+ }),
318
+ UPDATE_ADMITTED: payload(["updateId", "name"], { updateId: ID, name: ID, args: {} }),
319
+ UPDATE_ACCEPTED: payload(["updateId", "name"], { updateId: ID, name: ID, args: {} }),
320
+ UPDATE_COMPLETED: payload(["updateId"], { updateId: ID, result: {}, failure: FAILURE_REF }),
321
+ CHILD_RUN_INITIATED: payload(["childId", "input", "options"], {
322
+ childId: ID,
323
+ workflowKey: ID,
324
+ workflowFn: ID,
325
+ version: { type: "string" },
326
+ input: {},
327
+ options: { $ref: "#/$defs/childOptions" },
328
+ childRunId: { type: "string" },
329
+ executionKind: { enum: ["GRAPH", "DURABLE_FN"] }
330
+ }),
331
+ CHILD_RUN_STARTED: payload(["childId", "childRunId"], {
332
+ childId: ID,
333
+ childRunId: ID,
334
+ executionKind: { enum: ["GRAPH", "DURABLE_FN"] }
335
+ }),
336
+ CHILD_RUN_COMPLETED: payload(["childId"], { childId: ID, childRunId: ID, result: {} }),
337
+ CHILD_RUN_FAILED: payload(["childId", "failure"], {
338
+ childId: ID,
339
+ childRunId: ID,
340
+ failure: FAILURE_REF
341
+ }),
342
+ CHILD_RUN_CANCELLED: payload(["childId"], { childId: ID, childRunId: ID }),
343
+ CHILD_RUN_TERMINATED: payload(["childId"], {
344
+ childId: ID,
345
+ childRunId: ID,
346
+ reason: { type: "string" }
347
+ }),
348
+ CHILD_RUN_TIMED_OUT: payload(["childId"], {
349
+ childId: ID,
350
+ childRunId: ID,
351
+ timeoutType: { enum: ["WORKFLOW_RUN", "WORKFLOW_EXECUTION"] }
352
+ }),
353
+ EXTERNAL_RUN_CANCEL_REQUESTED: payload(["externalId", "target"], {
354
+ externalId: ID,
355
+ target: { $ref: "#/$defs/runTarget" }
356
+ }),
357
+ EXTERNAL_RUN_CANCEL_RESOLVED: payload(["externalId", "ok"], {
358
+ externalId: ID,
359
+ ok: { type: "boolean" },
360
+ targetRunId: { type: "string" },
361
+ failure: FAILURE_REF
362
+ }),
363
+ EXTERNAL_RUN_SIGNALED: {
364
+ type: "object",
365
+ required: ["externalId"],
366
+ description: "Two forms. Initiated (appended for the SIGNAL_RUN command): {externalId, target, name, payload}. Resolved (appended by the service after delivery, dedupeKey signal-out:<runId>:<externalId>): {externalId, resolved: true, ok, failure?, targetRunId?}.",
367
+ properties: {
368
+ externalId: ID,
369
+ target: { $ref: "#/$defs/runTarget" },
370
+ name: ID,
371
+ payload: {},
372
+ resolved: { const: true },
373
+ ok: { type: "boolean" },
374
+ targetRunId: { type: "string" },
375
+ failure: FAILURE_REF
376
+ },
377
+ if: { required: ["resolved"] },
378
+ then: { required: ["ok"] },
379
+ else: { required: ["target", "name"] }
380
+ },
381
+ SIDE_EFFECT_RECORDED: payload(["sideEffectId", "value"], { sideEffectId: ID, value: {} }),
382
+ LOCAL_ACTIVITY_COMPLETED: payload(["localActivityId", "attempts"], {
383
+ localActivityId: ID,
384
+ result: {},
385
+ attempts: { type: "integer", minimum: 1 }
386
+ }),
387
+ LOCAL_ACTIVITY_FAILED: payload(["localActivityId", "attempts", "failure"], {
388
+ localActivityId: ID,
389
+ failure: FAILURE_REF,
390
+ attempts: { type: "integer", minimum: 1 }
391
+ }),
392
+ SEARCH_ATTRIBUTES_UPSERTED: payload(["attributes"], { attributes: { type: "object" } }),
393
+ CONTEXT_UPSERTED: payload(["entries"], { entries: { type: "object" } }),
394
+ MARKER_RECORDED: payload(["markerId", "data"], {
395
+ markerId: ID,
396
+ data: {}
397
+ }),
398
+ WORKFLOW_CANCEL_REQUESTED: payload([], { actor: {}, reason: { type: "string" } }),
399
+ WORKFLOW_RESET: payload(["fromRunId", "toSeq"], {
400
+ fromRunId: ID,
401
+ toSeq: { type: "integer", minimum: 1 },
402
+ reason: { type: "string" }
403
+ }),
404
+ VERSIONING_OVERRIDE_SET: payload(["override"], { override: {} }),
405
+ WORKFLOW_COMPLETED: payload(["output"], { output: {} }),
406
+ WORKFLOW_FAILED: payload(["failure"], { failure: FAILURE_REF }),
407
+ WORKFLOW_CANCELLED: payload([], { details: {} }),
408
+ WORKFLOW_TERMINATED: payload([], { reason: { type: "string" }, actor: {} }),
409
+ WORKFLOW_TIMED_OUT: payload(["timeoutType"], {
410
+ timeoutType: { enum: ["WORKFLOW_RUN", "WORKFLOW_EXECUTION"] }
411
+ }),
412
+ WORKFLOW_CONTINUED_AS_NEW: payload(["input", "options"], {
413
+ input: {},
414
+ options: { type: "object" },
415
+ newRunId: { type: "string" }
416
+ })
417
+ };
418
+ function compact(value) {
419
+ const out = {};
420
+ for (const [key, entry] of Object.entries(value)) {
421
+ if (entry === void 0) continue;
422
+ out[key] = typeof entry === "object" && entry !== null && !Array.isArray(entry) ? compact(entry) : entry;
423
+ }
424
+ return out;
425
+ }
426
+ var RUN_EVENT_RECORD = {
427
+ type: "object",
428
+ required: ["seq", "type", "payload", "createdAt"],
429
+ properties: {
430
+ seq: { type: "integer", minimum: 1 },
431
+ type: { enum: [...chunk623FVQSN_cjs.EVENT_TYPES] },
432
+ taskId: { type: ["string", "null"] },
433
+ payload: { type: "object" },
434
+ createdAt: { type: "string", minLength: 1 },
435
+ dedupeKey: { type: ["string", "null"] }
436
+ },
437
+ allOf: chunk623FVQSN_cjs.EVENT_TYPES.map((type) => ({
438
+ if: { properties: { type: { const: type } }, required: ["type"] },
439
+ then: { properties: { payload: { $ref: `#/$defs/payload_${type}` } } }
440
+ }))
441
+ };
442
+ function payloadDefs() {
443
+ const defs = {};
444
+ for (const type of chunk623FVQSN_cjs.EVENT_TYPES) defs[`payload_${type}`] = compact(EVENT_PAYLOADS[type]);
445
+ return defs;
446
+ }
447
+ function commandDefs() {
448
+ const defs = {};
449
+ for (const type of chunk623FVQSN_cjs.COMMAND_TYPES) defs[`command_${type}`] = COMMAND_DEFS[type];
450
+ return defs;
451
+ }
452
+ var COMMAND_ONE_OF = {
453
+ type: "object",
454
+ required: ["type"],
455
+ properties: { type: { enum: [...chunk623FVQSN_cjs.COMMAND_TYPES] } },
456
+ allOf: chunk623FVQSN_cjs.COMMAND_TYPES.map((type) => ({
457
+ if: { properties: { type: { const: type } }, required: ["type"] },
458
+ then: { $ref: `#/$defs/command_${type}` }
459
+ }))
460
+ };
461
+ var RUN_EVENT_SCHEMA = {
462
+ $schema: "https://json-schema.org/draft/2020-12/schema",
463
+ $id: RUN_EVENT_SCHEMA_ID,
464
+ title: "FluidGrids durable-function history event",
465
+ description: "One row of workflow_run_events as the service returns it (offloaded payloads inlined). type is UPPER_SNAKE.",
466
+ ...RUN_EVENT_RECORD,
467
+ $defs: { ...SHARED_DEFS, ...payloadDefs() }
468
+ };
469
+ var WORKFLOW_COMMAND_SCHEMA = {
470
+ $schema: "https://json-schema.org/draft/2020-12/schema",
471
+ $id: WORKFLOW_COMMAND_SCHEMA_ID,
472
+ title: "FluidGrids workflow-task command",
473
+ description: "A flat object discriminated by an UPPER_SNAKE type. Commands travel as [JSON!]! (DB4). UPSERT_SEARCH_ATTRIBUTES, ACCEPT_UPDATE, REJECT_UPDATE and COMPLETE_UPDATE are defined but refused in Phase B.",
474
+ ...COMMAND_ONE_OF,
475
+ $defs: { ...SHARED_DEFS, ...commandDefs() }
476
+ };
477
+ var WORKFLOW_TASK_SCHEMA = {
478
+ $schema: "https://json-schema.org/draft/2020-12/schema",
479
+ $id: WORKFLOW_TASK_SCHEMA_ID,
480
+ title: "FluidGrids workflow task (runtime ABI protocol 1)",
481
+ description: 'globalThis.__fluidgridsRuntime: start(JSON of request); while (step() === "more") drain jobs; complete() returns JSON of result.',
482
+ oneOf: [{ $ref: "#/$defs/request" }, { $ref: "#/$defs/result" }],
483
+ $defs: {
484
+ ...SHARED_DEFS,
485
+ ...payloadDefs(),
486
+ ...commandDefs(),
487
+ event: RUN_EVENT_RECORD,
488
+ command: COMMAND_ONE_OF,
489
+ info: {
490
+ type: "object",
491
+ required: ["runId", "workspaceId"],
492
+ properties: {
493
+ runId: ID,
494
+ workspaceId: ID,
495
+ workflowKey: { type: "string" },
496
+ version: {},
497
+ buildId: { type: "string" },
498
+ businessId: { type: "string" },
499
+ attempt: { type: "integer", minimum: 1 },
500
+ taskQueue: { type: "string" },
501
+ parentRunId: { type: ["string", "null"] },
502
+ rootRunId: { type: ["string", "null"] },
503
+ firstRunId: { type: ["string", "null"] },
504
+ continuedFromRunId: { type: ["string", "null"] },
505
+ lastResult: {},
506
+ lastFailure: { oneOf: [{ type: "null" }, FAILURE_REF] },
507
+ startedAt: { type: "string" },
508
+ runStartedAt: { type: "string" },
509
+ historyLimit: {
510
+ type: "object",
511
+ required: ["events", "bytes"],
512
+ properties: {
513
+ events: { type: "integer", minimum: 1 },
514
+ bytes: { type: "integer", minimum: 1 }
515
+ }
516
+ },
517
+ timeouts: { type: "object" },
518
+ headers: { $ref: "#/$defs/headers" },
519
+ priority: { type: "integer", minimum: 1, maximum: 5 },
520
+ summary: { type: "string" },
521
+ details: { type: "string" },
522
+ context: { type: "object" }
523
+ }
524
+ },
525
+ request: {
526
+ type: "object",
527
+ required: ["protocol", "kind", "workflowFn", "info", "history", "nowMs"],
528
+ properties: {
529
+ protocol: { const: chunk623FVQSN_cjs.HISTORY_PROTOCOL },
530
+ kind: { enum: ["task", "query", "verify"] },
531
+ workflowFn: ID,
532
+ info: { $ref: "#/$defs/info" },
533
+ history: { type: "array", items: { $ref: "#/$defs/event" } },
534
+ nowMs: { type: "number" },
535
+ localActivityResults: {
536
+ type: "array",
537
+ items: {
538
+ type: "object",
539
+ required: ["localActivityId", "attempts"],
540
+ properties: {
541
+ localActivityId: ID,
542
+ result: {},
543
+ failure: FAILURE_REF,
544
+ attempts: { type: "integer", minimum: 1 }
545
+ }
546
+ }
547
+ },
548
+ queries: {
549
+ type: "array",
550
+ items: {
551
+ type: "object",
552
+ required: ["queryId", "name"],
553
+ properties: {
554
+ queryId: ID,
555
+ name: { enum: [...chunk623FVQSN_cjs.BUILT_IN_QUERIES] },
556
+ args: {}
557
+ }
558
+ }
559
+ }
560
+ }
561
+ },
562
+ result: {
563
+ type: "object",
564
+ required: ["protocol", "outcome", "commands", "logs"],
565
+ properties: {
566
+ protocol: { const: chunk623FVQSN_cjs.HISTORY_PROTOCOL },
567
+ outcome: { enum: ["commands", "failed", "localActivityRequested"] },
568
+ commands: { type: "array", items: { $ref: "#/$defs/command" } },
569
+ localActivityRequests: { type: "array", items: { type: "object" } },
570
+ queryResults: {
571
+ type: "array",
572
+ items: {
573
+ type: "object",
574
+ required: ["queryId"],
575
+ properties: { queryId: ID, value: {}, error: { type: "string" } }
576
+ }
577
+ },
578
+ failure: {
579
+ type: "object",
580
+ required: ["cause", "message"],
581
+ properties: {
582
+ cause: { enum: [...chunk623FVQSN_cjs.TASK_FAILURE_CAUSES] },
583
+ message: { type: "string" },
584
+ stackTrace: { type: "string" },
585
+ seq: { type: "integer" },
586
+ errorType: { type: "string" }
587
+ }
588
+ },
589
+ logs: {
590
+ type: "array",
591
+ items: {
592
+ type: "object",
593
+ required: ["level", "message"],
594
+ properties: {
595
+ level: { enum: ["debug", "info", "warn", "error"] },
596
+ message: { type: "string" },
597
+ data: {}
598
+ }
599
+ }
600
+ },
601
+ stackTrace: { type: "string" }
602
+ }
603
+ }
604
+ }
605
+ };
606
+ var HISTORY_FILE_SCHEMA = {
607
+ $schema: "https://json-schema.org/draft/2020-12/schema",
608
+ $id: HISTORY_FILE_SCHEMA_ID,
609
+ title: "FluidGrids durable-function history file",
610
+ type: "object",
611
+ required: ["format", "formatVersion", "workflowFn", "events"],
612
+ properties: {
613
+ format: { const: HISTORY_FILE_FORMAT },
614
+ formatVersion: { const: chunk623FVQSN_cjs.HISTORY_PROTOCOL },
615
+ name: { type: "string" },
616
+ description: { type: "string" },
617
+ workflowFn: ID,
618
+ source: { type: "string", description: "Fixture source module, relative to the file." },
619
+ replaySource: {
620
+ type: "string",
621
+ description: "Fixture module the replay check runs instead of source (a hotfix or a patched() version)."
622
+ },
623
+ replay: {
624
+ type: "boolean",
625
+ description: "False for histories that use Phase C features (updates); they are parsed and projected but not replayed."
626
+ },
627
+ info: { $ref: "#/$defs/info" },
628
+ nowMs: {
629
+ type: "number",
630
+ description: "nowMs of the replay request for the conformance check."
631
+ },
632
+ events: { type: "array", items: { $ref: "#/$defs/event" } },
633
+ expected: {
634
+ type: "object",
635
+ description: "The replay result the conformance check must reproduce."
636
+ }
637
+ },
638
+ $defs: {
639
+ ...SHARED_DEFS,
640
+ ...payloadDefs(),
641
+ event: RUN_EVENT_RECORD,
642
+ info: WORKFLOW_TASK_SCHEMA.$defs.info
643
+ }
644
+ };
645
+ var HISTORY_SCHEMA_FILES = [
646
+ ["run-event.schema.json", RUN_EVENT_SCHEMA],
647
+ ["workflow-command.schema.json", WORKFLOW_COMMAND_SCHEMA],
648
+ ["workflow-task.schema.json", WORKFLOW_TASK_SCHEMA],
649
+ ["history-file.schema.json", HISTORY_FILE_SCHEMA]
650
+ ];
651
+ var tools;
652
+ function schemaTools() {
653
+ if (!tools) {
654
+ const ajv = new _2020_js.Ajv2020({ allErrors: true, strict: false });
655
+ tools = {
656
+ ajv,
657
+ command: ajv.compile(WORKFLOW_COMMAND_SCHEMA),
658
+ event: ajv.compile(RUN_EVENT_SCHEMA),
659
+ file: ajv.compile(HISTORY_FILE_SCHEMA)
660
+ };
661
+ }
662
+ return tools;
663
+ }
664
+ function issuesOf(index, errors) {
665
+ const real = (errors ?? []).filter((error) => error.keyword !== "if");
666
+ return real.map((error) => ({
667
+ index,
668
+ code: `schema.${error.keyword}`,
669
+ message: `${error.instancePath || "/"} ${error.message ?? "is invalid"}`,
670
+ path: error.instancePath
671
+ }));
672
+ }
673
+ function validateCommand(command2, index = 0) {
674
+ const { command: validate } = schemaTools();
675
+ if (validate(command2)) {
676
+ return { ok: true, command: command2 };
677
+ }
678
+ return { ok: false, issues: issuesOf(index, validate.errors) };
679
+ }
680
+ function idOf(command2) {
681
+ switch (command2.type) {
682
+ case "SCHEDULE_ACTIVITY":
683
+ return `activity:${command2.activityId}`;
684
+ case "START_TIMER":
685
+ return `timer:${command2.timerId}`;
686
+ case "START_CHILD_RUN":
687
+ return `child:${command2.childId}`;
688
+ case "SIGNAL_RUN":
689
+ case "REQUEST_CANCEL_EXTERNAL_RUN":
690
+ return `external:${command2.externalId}`;
691
+ case "RECORD_SIDE_EFFECT":
692
+ return `sideEffect:${command2.sideEffectId}`;
693
+ case "RECORD_MARKER":
694
+ return `marker:${command2.markerId}`;
695
+ case "RECORD_LOCAL_ACTIVITY":
696
+ return `local:${command2.localActivityId}`;
697
+ default:
698
+ return void 0;
699
+ }
700
+ }
701
+ function validateCommands(commands, options = {}) {
702
+ const max = options.maxCommands ?? 1e3;
703
+ if (!Array.isArray(commands))
704
+ return {
705
+ ok: false,
706
+ cause: "INVALID_REQUEST",
707
+ issues: [{ index: 0, code: "commands.notArray", message: "commands must be an array" }]
708
+ };
709
+ if (commands.length > max)
710
+ return {
711
+ ok: false,
712
+ cause: "INVALID_REQUEST",
713
+ issues: [
714
+ {
715
+ index: max,
716
+ code: "commands.tooMany",
717
+ message: `A task may return at most ${max} commands; it returned ${commands.length}`
718
+ }
719
+ ]
720
+ };
721
+ const issues = [];
722
+ const valid = [];
723
+ const ids = /* @__PURE__ */ new Set();
724
+ let unsupported = false;
725
+ commands.forEach((raw, index) => {
726
+ const checked = validateCommand(raw, index);
727
+ if (!checked.ok) {
728
+ issues.push(...checked.issues);
729
+ return;
730
+ }
731
+ const command2 = checked.command;
732
+ if (!chunkP6TA5EZT_cjs.isWorkflowCommandEnabled(command2, options.enabled)) {
733
+ unsupported = true;
734
+ issues.push({
735
+ index,
736
+ code: "commands.unsupported",
737
+ message: `${command2.type} is not supported in this release`
738
+ });
739
+ }
740
+ const id = idOf(command2);
741
+ if (id !== void 0) {
742
+ if (ids.has(id))
743
+ issues.push({ index, code: "commands.duplicateId", message: `${id} is used twice` });
744
+ ids.add(id);
745
+ }
746
+ if (chunk623FVQSN_cjs.TERMINAL_COMMANDS.has(command2.type) && index !== commands.length - 1)
747
+ issues.push({
748
+ index,
749
+ code: "commands.terminalNotLast",
750
+ message: `${command2.type} must be the last command of the batch`
751
+ });
752
+ if (command2.type === "SCHEDULE_ACTIVITY" && !chunk2J6TF7YI_cjs.isActivityNodeTypeAllowed(command2.nodeType))
753
+ issues.push({
754
+ index,
755
+ code: "durable.activityTypeNotAllowed",
756
+ message: `${command2.nodeType} cannot run as a durable activity`,
757
+ path: "/nodeType"
758
+ });
759
+ valid.push(command2);
760
+ });
761
+ if (issues.length > 0)
762
+ return { ok: false, cause: unsupported ? "UNSUPPORTED_COMMAND" : "INVALID_REQUEST", issues };
763
+ return { ok: true, commands: valid };
764
+ }
765
+ function validateHistory(events) {
766
+ const { event: validate } = schemaTools();
767
+ if (!Array.isArray(events))
768
+ return {
769
+ ok: false,
770
+ issues: [{ index: 0, code: "history.notArray", message: "history must be an array" }]
771
+ };
772
+ const issues = [];
773
+ events.forEach((event, index) => {
774
+ if (!validate(event)) {
775
+ issues.push(...issuesOf(index, validate.errors));
776
+ return;
777
+ }
778
+ if (chunkSAENRNBJ_cjs.isRecord(event) && event["seq"] !== index + 1)
779
+ issues.push({
780
+ index,
781
+ code: "history.seqGap",
782
+ message: `event ${index + 1} has seq ${String(event["seq"])}`
783
+ });
784
+ });
785
+ return { ok: issues.length === 0, issues };
786
+ }
787
+ function validateHistoryFile(value) {
788
+ const { file: validate } = schemaTools();
789
+ if (validate(value)) return validateHistory(chunkSAENRNBJ_cjs.isRecord(value) ? value["events"] : void 0);
790
+ return { ok: false, issues: issuesOf(0, validate.errors) };
791
+ }
792
+ function compilePayloadValidator(schema) {
793
+ const { ajv } = schemaTools();
794
+ const validate = ajv.compile(schema);
795
+ return (value) => {
796
+ if (validate(value)) return { ok: true };
797
+ return {
798
+ ok: false,
799
+ errors: (validate.errors ?? []).map(
800
+ (error) => `${error.instancePath || "/"} ${error.message ?? "is invalid"}`
801
+ )
802
+ };
803
+ };
804
+ }
805
+
806
+ // src/history/file.ts
807
+ var HistoryFileError = class extends Error {
808
+ constructor(message, issues = []) {
809
+ super(message);
810
+ this.issues = issues;
811
+ this.name = "HistoryFileError";
812
+ }
813
+ issues;
814
+ };
815
+ function parseHistoryFile(input) {
816
+ let value = input;
817
+ if (typeof input === "string") {
818
+ try {
819
+ value = JSON.parse(input);
820
+ } catch (error) {
821
+ throw new HistoryFileError(
822
+ `Not JSON: ${error instanceof Error ? error.message : String(error)}`
823
+ );
824
+ }
825
+ }
826
+ if (!chunkSAENRNBJ_cjs.isRecord(value) || value["format"] !== HISTORY_FILE_FORMAT)
827
+ throw new HistoryFileError(`Not a ${HISTORY_FILE_FORMAT} document`);
828
+ const checked = validateHistoryFile(value);
829
+ if (!checked.ok)
830
+ throw new HistoryFileError(
831
+ "The history file does not match history-file.schema.json",
832
+ checked.issues.map((issue) => `#${issue.index}: ${issue.message}`)
833
+ );
834
+ return value;
835
+ }
836
+ function createHistoryFile(workflowFn, events, extra = {}) {
837
+ return {
838
+ format: HISTORY_FILE_FORMAT,
839
+ formatVersion: chunk623FVQSN_cjs.HISTORY_PROTOCOL,
840
+ ...extra,
841
+ workflowFn,
842
+ events
843
+ };
844
+ }
845
+ function serializeHistoryFile(file) {
846
+ return `${JSON.stringify(file, null, 2)}
847
+ `;
848
+ }
849
+
850
+ exports.HISTORY_FILE_FORMAT = HISTORY_FILE_FORMAT;
851
+ exports.HISTORY_FILE_SCHEMA = HISTORY_FILE_SCHEMA;
852
+ exports.HISTORY_FILE_SCHEMA_ID = HISTORY_FILE_SCHEMA_ID;
853
+ exports.HISTORY_SCHEMA_FILES = HISTORY_SCHEMA_FILES;
854
+ exports.HistoryFileError = HistoryFileError;
855
+ exports.RUN_EVENT_SCHEMA = RUN_EVENT_SCHEMA;
856
+ exports.RUN_EVENT_SCHEMA_ID = RUN_EVENT_SCHEMA_ID;
857
+ exports.WORKFLOW_COMMAND_SCHEMA = WORKFLOW_COMMAND_SCHEMA;
858
+ exports.WORKFLOW_COMMAND_SCHEMA_ID = WORKFLOW_COMMAND_SCHEMA_ID;
859
+ exports.WORKFLOW_TASK_SCHEMA = WORKFLOW_TASK_SCHEMA;
860
+ exports.WORKFLOW_TASK_SCHEMA_ID = WORKFLOW_TASK_SCHEMA_ID;
861
+ exports.compilePayloadValidator = compilePayloadValidator;
862
+ exports.createHistoryFile = createHistoryFile;
863
+ exports.parseHistoryFile = parseHistoryFile;
864
+ exports.serializeHistoryFile = serializeHistoryFile;
865
+ exports.validateCommand = validateCommand;
866
+ exports.validateCommands = validateCommands;
867
+ exports.validateHistory = validateHistory;
868
+ exports.validateHistoryFile = validateHistoryFile;