@fluidgrids/workflows 2026.1028.2 → 2026.1030.1

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 (154) hide show
  1. package/README.md +181 -11
  2. package/dist/{activation-BBh1p82z.d.cts → activation-DqUfpHzk.d.cts} +1 -1
  3. package/dist/{activation-DnhG7SmF.d.ts → activation-xpx1oWuo.d.ts} +1 -1
  4. package/dist/{chunk-VRHHBPT6.js → chunk-2D3MYIIF.js} +1212 -128
  5. package/dist/chunk-3U2NU7YC.cjs +124 -0
  6. package/dist/{chunk-NEIUQASE.cjs → chunk-4QKB4ARC.cjs} +3 -3
  7. package/dist/{chunk-GBQ33SIZ.cjs → chunk-54FLQNUM.cjs} +12 -1
  8. package/dist/chunk-5HIVIV53.js +330 -0
  9. package/dist/chunk-5MFVJM76.js +1222 -0
  10. package/dist/{chunk-JD2VQIDZ.cjs → chunk-672KMMBK.cjs} +2 -2
  11. package/dist/{chunk-C5OLWZ42.js → chunk-6A2FGSUS.js} +22 -14
  12. package/dist/{chunk-XKJA7KX3.js → chunk-6OLN6BMB.js} +52 -3
  13. package/dist/{chunk-6FSHT5IL.js → chunk-7EZIANC7.js} +1 -1
  14. package/dist/{chunk-2J6TF7YI.cjs → chunk-A5SXCA62.cjs} +10 -3
  15. package/dist/{chunk-BO6OVILK.js → chunk-AC6ZEXVR.js} +10 -4
  16. package/dist/{chunk-ABFZWYHT.js → chunk-AE5Q6ZAJ.js} +315 -50
  17. package/dist/chunk-C4F5KJTI.js +293 -0
  18. package/dist/{chunk-IISBRUWJ.js → chunk-G5H32GIG.js} +1 -1
  19. package/dist/chunk-GEQDGUGB.cjs +2719 -0
  20. package/dist/{chunk-XHXIDVEC.js → chunk-HCM7ZC7Q.js} +1 -1
  21. package/dist/chunk-HMZUGSMU.cjs +1554 -0
  22. package/dist/{chunk-SAOBPYYJ.cjs → chunk-IQPXHQQQ.cjs} +8 -4
  23. package/dist/{chunk-P6TA5EZT.cjs → chunk-ISOIA7NV.cjs} +335 -58
  24. package/dist/chunk-JSC75O5C.cjs +167 -0
  25. package/dist/chunk-M272AHEX.js +25 -0
  26. package/dist/{chunk-BD7ZPG53.js → chunk-NWQ5WRLE.js} +10 -2
  27. package/dist/chunk-ODZ2IAR2.cjs +1247 -0
  28. package/dist/chunk-Q4MWQNJK.cjs +28 -0
  29. package/dist/{chunk-HWJZVOG7.js → chunk-SR7TR5KX.js} +6 -2
  30. package/dist/{chunk-FEW3JBYA.cjs → chunk-TCTE7DX5.cjs} +3 -3
  31. package/dist/{chunk-623FVQSN.cjs → chunk-TYF56RGB.cjs} +123 -0
  32. package/dist/chunk-VA4OFR72.cjs +324 -0
  33. package/dist/chunk-VU5S5A7V.js +150 -0
  34. package/dist/chunk-YEHR4NNE.js +1522 -0
  35. package/dist/{chunk-FMSW2HDF.cjs → chunk-ZCGKGDCL.cjs} +23 -15
  36. package/dist/codegen/index.d.cts +2 -2
  37. package/dist/codegen/index.d.ts +2 -2
  38. package/dist/collect-6NIEufHd.d.ts +103 -0
  39. package/dist/collect-CcTCKqx6.d.cts +103 -0
  40. package/dist/{file-BOoHZgoQ.d.cts → file-BxYpwjRQ.d.cts} +1007 -21
  41. package/dist/{file-yuPCFU5b.d.ts → file-CFdPQJI9.d.ts} +1007 -21
  42. package/dist/history/index.cjs +375 -86
  43. package/dist/history/index.d.cts +590 -12
  44. package/dist/history/index.d.ts +590 -12
  45. package/dist/history/index.js +50 -4
  46. package/dist/index.cjs +156 -50
  47. package/dist/index.d.cts +38 -58
  48. package/dist/index.d.ts +38 -58
  49. package/dist/index.js +6 -4
  50. package/dist/interceptors-CNcr2dlk.d.ts +159 -0
  51. package/dist/interceptors-CqkNZVfI.d.cts +159 -0
  52. package/dist/ir/index.cjs +362 -38
  53. package/dist/ir/index.d.cts +282 -7
  54. package/dist/ir/index.d.ts +282 -7
  55. package/dist/ir/index.js +329 -23
  56. package/dist/{lower-BzmUz0sq.d.cts → lower-BtRfIW2A.d.cts} +56 -8
  57. package/dist/{lower-_-iT4HYs.d.ts → lower-CpsMFOFX.d.ts} +56 -8
  58. package/dist/{manifest-C8N6HDYl.d.ts → manifest-D-I_twys.d.ts} +1 -1
  59. package/dist/{manifest-0OLw0i7k.d.cts → manifest-DahBQVM8.d.cts} +1 -1
  60. package/dist/node-evaluator-DGQDPSPI.cjs +24 -0
  61. package/dist/node-evaluator-LEEVD7H7.js +14 -0
  62. package/dist/payload-fields-BVRQn2yH.d.cts +122 -0
  63. package/dist/payload-fields-oOBWxDiG.d.ts +122 -0
  64. package/dist/quickjs/index.cjs +28 -27
  65. package/dist/quickjs/index.d.cts +6 -6
  66. package/dist/quickjs/index.d.ts +6 -6
  67. package/dist/quickjs/index.js +10 -9
  68. package/dist/roundtrip/index.cjs +259 -51
  69. package/dist/roundtrip/index.d.cts +100 -9
  70. package/dist/roundtrip/index.d.ts +100 -9
  71. package/dist/roundtrip/index.js +177 -11
  72. package/dist/runtime/index.cjs +21 -20
  73. package/dist/runtime/index.d.cts +184 -15
  74. package/dist/runtime/index.d.ts +184 -15
  75. package/dist/runtime/index.js +8 -7
  76. package/dist/testing/index.cjs +1122 -115
  77. package/dist/testing/index.d.cts +294 -13
  78. package/dist/testing/index.d.ts +294 -13
  79. package/dist/testing/index.js +1086 -84
  80. package/dist/{types-DV-HX_Gt.d.ts → types-Bv2i4cBX.d.cts} +244 -33
  81. package/dist/{types-CpBBjaGX.d.cts → types-DGx-b9eq.d.ts} +244 -33
  82. package/dist/{types-BGoPzgcl.d.ts → types-V7jEEUaL.d.cts} +20 -1
  83. package/dist/{types-BGoPzgcl.d.cts → types-V7jEEUaL.d.ts} +20 -1
  84. package/dist/{workflow-Bpr3vnA_.d.ts → workflow-B18OeF7g.d.ts} +2 -2
  85. package/dist/workflow-BGnv8SS6.d.ts +803 -0
  86. package/dist/{workflow-FXUkpIBc.d.cts → workflow-BJPFv3cp.d.cts} +2 -2
  87. package/dist/workflow-DS32Gtws.d.cts +803 -0
  88. package/fixtures/histories/activity-options-updated.history.json +159 -0
  89. package/fixtures/histories/activity-paused-unpaused.history.json +160 -0
  90. package/fixtures/histories/auto-upgrade-patched.history.json +276 -0
  91. package/fixtures/histories/benign-failure.history.json +146 -0
  92. package/fixtures/histories/cancel-activity-try-cancel.history.json +150 -0
  93. package/fixtures/histories/child-cancel-wait-requested.history.json +217 -0
  94. package/fixtures/histories/child-options-roundtrip.history.json +192 -0
  95. package/fixtures/histories/codec-opaque.history.json +229 -0
  96. package/fixtures/histories/continue-as-new-last-result.history.json +86 -0
  97. package/fixtures/histories/continue-as-new-options.history.json +99 -0
  98. package/fixtures/histories/continue-as-new-r1-long-task-queue.history.json +78 -0
  99. package/fixtures/histories/continue-as-new-r1-retry-options.history.json +83 -0
  100. package/fixtures/histories/dynamic-workflow.history.json +150 -0
  101. package/fixtures/histories/execution-timeout-chain.history.json +98 -0
  102. package/fixtures/histories/external-cancel-resolved.history.json +123 -0
  103. package/fixtures/histories/external-cancel-unknown-target.history.json +127 -0
  104. package/fixtures/histories/failure-error-types-fails-run.history.json +144 -0
  105. package/fixtures/histories/handler-drain-warn.history.json +222 -0
  106. package/fixtures/histories/heartbeat-details-on-retry.history.json +145 -0
  107. package/fixtures/histories/interceptor-headers.history.json +339 -0
  108. package/fixtures/histories/local-activity-abandoned-at-completion.history.json +73 -0
  109. package/fixtures/histories/local-activity-cancelled-in-scope.history.json +118 -0
  110. package/fixtures/histories/local-activity-completed.history.json +157 -0
  111. package/fixtures/histories/local-activity-failed.history.json +93 -0
  112. package/fixtures/histories/local-activity-retry-in-task.history.json +88 -0
  113. package/fixtures/histories/query-custom.history.json +213 -0
  114. package/fixtures/histories/query-default-handler.history.json +120 -0
  115. package/fixtures/histories/reset-forked-reapplied-signals.history.json +239 -0
  116. package/fixtures/histories/reset-reapplied-update-admitted.history.json +228 -0
  117. package/fixtures/histories/run-retry-last-failure.history.json +90 -0
  118. package/fixtures/histories/run-timeout.history.json +159 -0
  119. package/fixtures/histories/schedule-to-start-timeout.history.json +132 -0
  120. package/fixtures/histories/search-attributes-upserted.history.json +177 -0
  121. package/fixtures/histories/start-delay-signal-ends-delay.history.json +155 -0
  122. package/fixtures/histories/typeerror-task-retry-100.history.json +137 -0
  123. package/fixtures/histories/update-accepted-completed.history.json +45 -30
  124. package/fixtures/histories/update-default-handler.history.json +246 -0
  125. package/fixtures/histories/update-handler-awaits-activity.history.json +196 -0
  126. package/fixtures/histories/update-not-handled.history.json +138 -0
  127. package/fixtures/histories/update-rejected-no-event.history.json +190 -0
  128. package/fixtures/histories/update-with-start-admitted.history.json +150 -0
  129. package/fixtures/histories/user-activity-cancel.history.json +149 -0
  130. package/fixtures/histories/user-activity-retry.history.json +143 -0
  131. package/fixtures/histories/user-activity.history.json +149 -0
  132. package/package.json +1 -1
  133. package/schema/bridge-v2.schema.json +1062 -0
  134. package/schema/history-file.schema.json +538 -83
  135. package/schema/ir-v2.schema.json +290 -0
  136. package/schema/payload-fields.json +162 -0
  137. package/schema/run-event.schema.json +503 -82
  138. package/schema/workflow-command.schema.json +372 -69
  139. package/schema/workflow-task.schema.json +924 -171
  140. package/dist/assemble-BLqQ8lSu.d.cts +0 -39
  141. package/dist/assemble-DWgaXHd-.d.ts +0 -39
  142. package/dist/chunk-DHTLALBL.cjs +0 -80
  143. package/dist/chunk-DJYMDLV5.js +0 -227
  144. package/dist/chunk-I5LR3D2K.js +0 -869
  145. package/dist/chunk-M4BBAERY.cjs +0 -1635
  146. package/dist/chunk-N23SKIG4.js +0 -73
  147. package/dist/chunk-PZCVF76Q.cjs +0 -868
  148. package/dist/chunk-QQ6ULXHI.cjs +0 -885
  149. package/dist/chunk-UK3WM7YZ.cjs +0 -75
  150. package/dist/chunk-VOKMAAJP.js +0 -848
  151. package/dist/node-evaluator-4MSDKWOG.cjs +0 -22
  152. package/dist/node-evaluator-SX4LEYQC.js +0 -12
  153. package/dist/workflow-C2a05WUJ.d.ts +0 -444
  154. package/dist/workflow-J-yYixny.d.cts +0 -444
@@ -0,0 +1,1554 @@
1
+ 'use strict';
2
+
3
+ var chunkJSC75O5C_cjs = require('./chunk-JSC75O5C.cjs');
4
+ var chunkSAENRNBJ_cjs = require('./chunk-SAENRNBJ.cjs');
5
+ var chunkISOIA7NV_cjs = require('./chunk-ISOIA7NV.cjs');
6
+ var chunkA5SXCA62_cjs = require('./chunk-A5SXCA62.cjs');
7
+ var chunkTYF56RGB_cjs = require('./chunk-TYF56RGB.cjs');
8
+ var _2020_js = require('ajv/dist/2020.js');
9
+
10
+ // src/history/bridge.ts
11
+ var BRIDGE_PROTOCOL_VERSION = 2;
12
+ var BRIDGE_PATH = "/runner-bridge";
13
+ var BRIDGE_PING_SECONDS = 20;
14
+ var BRIDGE_WORKER_HEARTBEAT_SECONDS = 30;
15
+ var BRIDGE_IDLE_TIMEOUT_MS = 65e3;
16
+ var BRIDGE_MAX_FRAME_BYTES = 10 * 1024 * 1024;
17
+ var BRIDGE_MAX_HISTORY_TAIL_BYTES = 4 * 1024 * 1024;
18
+ var BridgeCloseCode = {
19
+ Unauthorized: 4001,
20
+ Revoked: 4002,
21
+ Replaced: 4003,
22
+ /** Also a v2 hello on a RUNNER token, or a v1 hello on a WORKER token. */
23
+ ProtocolError: 4004,
24
+ IdleTimeout: 4008,
25
+ /** The service is shutting down, or `WORKER_BRIDGE_ENABLED` is off. */
26
+ ShuttingDown: 4009,
27
+ /** The workspace has no free worker seat (`fluidgrids.workers.count`). */
28
+ QuotaExceeded: 4010,
29
+ /** The token does not allow a task queue the hello names. */
30
+ QueueNotAllowed: 4011,
31
+ /** `fluidgrids.self-hosted-workers` (or a prerequisite) is off for the workspace. */
32
+ FeatureDisabled: 4012
33
+ };
34
+ var BRIDGE_REQUEST_METHODS = ["history.page", "activity.connection"];
35
+ var ID = { type: "string", minLength: 1, maxLength: 256 };
36
+ var COUNT = { type: "integer", minimum: 0 };
37
+ var POSITIVE = { type: "integer", minimum: 1 };
38
+ var STRINGS = { type: "array", items: { type: "string", minLength: 1 } };
39
+ function frame(type, required, properties) {
40
+ return {
41
+ type: "object",
42
+ required: ["type", ...required],
43
+ properties: { type: { const: type }, ...properties },
44
+ additionalProperties: false
45
+ };
46
+ }
47
+ var SLOT_USAGE = {
48
+ type: "object",
49
+ required: ["used", "total"],
50
+ properties: { used: COUNT, total: COUNT },
51
+ additionalProperties: false
52
+ };
53
+ var TASK_FAILURE = {
54
+ type: "object",
55
+ required: ["cause", "message"],
56
+ properties: {
57
+ cause: { enum: [...chunkTYF56RGB_cjs.TASK_FAILURE_CAUSES] },
58
+ message: { type: "string" },
59
+ stackTrace: { type: "string" },
60
+ seq: { type: "integer" },
61
+ errorType: { type: "string" }
62
+ },
63
+ additionalProperties: false
64
+ };
65
+ var BRIDGE_V2_SCHEMA_ID = "https://docs.fluidgrids.ai/schemas/bridge-v2.schema.json";
66
+ var BRIDGE_V2_SCHEMA = {
67
+ $schema: "https://json-schema.org/draft/2020-12/schema",
68
+ $id: BRIDGE_V2_SCHEMA_ID,
69
+ title: "FluidGrids worker bridge, protocol 2",
70
+ description: "Frames between a self-hosted worker and wspace-sandbox-svc over /runner-bridge (JSON text frames, Bearer fgr_ token of kind WORKER, ping every 20 s, 65 s idle timeout, 10 MiB frame cap). Close codes: 4001 Unauthorized, 4002 Revoked, 4003 Replaced, 4004 ProtocolError, 4008 IdleTimeout, 4009 ShuttingDown, 4010 QuotaExceeded, 4011 QueueNotAllowed, 4012 FeatureDisabled.",
71
+ oneOf: [{ $ref: "#/$defs/workerFrame" }, { $ref: "#/$defs/serviceFrame" }],
72
+ $defs: {
73
+ workflowTaskRef: {
74
+ type: "object",
75
+ required: ["kind", "runId", "taskId", "attempt", "expectedHistoryLength"],
76
+ properties: {
77
+ kind: { const: "workflow" },
78
+ runId: ID,
79
+ taskId: ID,
80
+ attempt: POSITIVE,
81
+ expectedHistoryLength: POSITIVE
82
+ },
83
+ additionalProperties: false
84
+ },
85
+ queryTaskRef: {
86
+ type: "object",
87
+ required: ["kind", "runId", "queryTaskId"],
88
+ properties: { kind: { const: "query" }, runId: ID, queryTaskId: ID },
89
+ additionalProperties: false
90
+ },
91
+ activityTaskRef: {
92
+ type: "object",
93
+ required: ["kind", "runId", "activityId", "attempt"],
94
+ properties: { kind: { const: "activity" }, runId: ID, activityId: ID, attempt: POSITIVE },
95
+ additionalProperties: false
96
+ },
97
+ taskRef: {
98
+ oneOf: [
99
+ { $ref: "#/$defs/workflowTaskRef" },
100
+ { $ref: "#/$defs/queryTaskRef" },
101
+ { $ref: "#/$defs/activityTaskRef" }
102
+ ]
103
+ },
104
+ historyPage: {
105
+ type: "object",
106
+ required: ["events", "from", "nextAfter", "hasMore"],
107
+ properties: {
108
+ events: { type: "array", items: { type: "object" } },
109
+ from: POSITIVE,
110
+ nextAfter: { oneOf: [{ type: "null" }, POSITIVE] },
111
+ hasMore: { type: "boolean" }
112
+ },
113
+ additionalProperties: false
114
+ },
115
+ queryRequests: {
116
+ type: "array",
117
+ items: {
118
+ type: "object",
119
+ required: ["queryId", "name"],
120
+ properties: { queryId: ID, name: ID, args: {} },
121
+ additionalProperties: false
122
+ }
123
+ },
124
+ queryResults: {
125
+ type: "array",
126
+ items: {
127
+ type: "object",
128
+ required: ["queryId"],
129
+ properties: {
130
+ queryId: ID,
131
+ value: {},
132
+ error: { type: "string" },
133
+ rejected: { type: "boolean" }
134
+ },
135
+ additionalProperties: false
136
+ }
137
+ },
138
+ hello: frame(
139
+ "hello",
140
+ [
141
+ "protocol",
142
+ "kind",
143
+ "sdk",
144
+ "identity",
145
+ "taskQueues",
146
+ "buildIds",
147
+ "workflows",
148
+ "activities",
149
+ "slots",
150
+ "host",
151
+ "encodings"
152
+ ],
153
+ {
154
+ protocol: { const: BRIDGE_PROTOCOL_VERSION },
155
+ kind: { const: "worker" },
156
+ sdk: {
157
+ type: "object",
158
+ required: ["language", "version"],
159
+ properties: { language: { enum: ["typescript", "python"] }, version: ID },
160
+ additionalProperties: false
161
+ },
162
+ identity: ID,
163
+ taskQueues: { ...STRINGS, minItems: 1 },
164
+ buildIds: STRINGS,
165
+ workflows: STRINGS,
166
+ activities: STRINGS,
167
+ slots: {
168
+ type: "object",
169
+ required: ["workflow", "activity", "localActivity"],
170
+ properties: { workflow: COUNT, activity: COUNT, localActivity: COUNT },
171
+ additionalProperties: false
172
+ },
173
+ host: {
174
+ type: "object",
175
+ properties: {
176
+ os: { type: "string" },
177
+ arch: { type: "string" },
178
+ hostname: { type: "string" },
179
+ runtime: { type: "string" }
180
+ },
181
+ additionalProperties: false
182
+ },
183
+ encodings: STRINGS
184
+ }
185
+ ),
186
+ ping: frame("ping", [], { t: { type: "number" } }),
187
+ pollers: frame("pollers", ["workflow", "activity"], { workflow: COUNT, activity: COUNT }),
188
+ taskResult: {
189
+ oneOf: [
190
+ frame("taskResult", ["taskRef", "commands", "logs", "cachedUpTo"], {
191
+ taskRef: { $ref: "#/$defs/workflowTaskRef" },
192
+ commands: { type: "array", items: { type: "object" } },
193
+ logs: { type: "array", items: { type: "object" } },
194
+ cachedUpTo: COUNT,
195
+ queryResults: { $ref: "#/$defs/queryResults" },
196
+ unfinishedHandlers: { type: "array", items: { type: "object" } }
197
+ }),
198
+ frame("taskResult", ["taskRef", "result"], {
199
+ taskRef: { $ref: "#/$defs/activityTaskRef" },
200
+ result: {}
201
+ }),
202
+ frame("taskResult", ["taskRef", "queryResults"], {
203
+ taskRef: { $ref: "#/$defs/queryTaskRef" },
204
+ queryResults: { $ref: "#/$defs/queryResults" }
205
+ })
206
+ ]
207
+ },
208
+ taskFailed: {
209
+ oneOf: [
210
+ frame("taskFailed", ["taskRef", "failure"], {
211
+ taskRef: {
212
+ oneOf: [{ $ref: "#/$defs/workflowTaskRef" }, { $ref: "#/$defs/queryTaskRef" }]
213
+ },
214
+ failure: TASK_FAILURE
215
+ }),
216
+ frame("taskFailed", ["taskRef", "failure"], {
217
+ taskRef: { $ref: "#/$defs/activityTaskRef" },
218
+ failure: {
219
+ type: "object",
220
+ required: ["errorType", "message"],
221
+ description: "An activity failure (run-event failure shape)."
222
+ }
223
+ })
224
+ ]
225
+ },
226
+ heartbeat: frame("heartbeat", ["reqId", "taskRef"], {
227
+ reqId: ID,
228
+ taskRef: { $ref: "#/$defs/activityTaskRef" },
229
+ details: {}
230
+ }),
231
+ workerHeartbeat: frame("workerHeartbeat", ["slots", "pollers", "tasksInFlight", "cachedRuns"], {
232
+ slots: {
233
+ type: "object",
234
+ required: ["workflow", "activity", "localActivity"],
235
+ properties: { workflow: SLOT_USAGE, activity: SLOT_USAGE, localActivity: SLOT_USAGE },
236
+ additionalProperties: false
237
+ },
238
+ pollers: {
239
+ type: "object",
240
+ required: ["workflow", "activity"],
241
+ properties: { workflow: COUNT, activity: COUNT },
242
+ additionalProperties: false
243
+ },
244
+ tasksInFlight: COUNT,
245
+ cachedRuns: COUNT
246
+ }),
247
+ req: frame("req", ["id", "method", "params"], {
248
+ id: ID,
249
+ method: { enum: [...BRIDGE_REQUEST_METHODS] },
250
+ params: { type: "object" }
251
+ }),
252
+ bye: frame("bye", ["reason"], { reason: { type: "string" } }),
253
+ welcome: frame(
254
+ "welcome",
255
+ [
256
+ "protocol",
257
+ "sessionId",
258
+ "workerId",
259
+ "workspaceId",
260
+ "heartbeatSeconds",
261
+ "workerHeartbeatSeconds",
262
+ "maxFrameBytes"
263
+ ],
264
+ {
265
+ protocol: { const: BRIDGE_PROTOCOL_VERSION },
266
+ sessionId: ID,
267
+ workerId: { type: "string", pattern: "^worker:.+$" },
268
+ workspaceId: ID,
269
+ heartbeatSeconds: POSITIVE,
270
+ workerHeartbeatSeconds: POSITIVE,
271
+ maxFrameBytes: POSITIVE
272
+ }
273
+ ),
274
+ task: {
275
+ oneOf: [
276
+ frame("task", ["taskRef", "lease", "request", "history"], {
277
+ taskRef: { $ref: "#/$defs/workflowTaskRef" },
278
+ lease: { type: "object" },
279
+ request: {
280
+ type: "object",
281
+ required: ["workflowFn", "info", "nowMs"],
282
+ properties: {
283
+ workflowFn: ID,
284
+ info: { type: "object" },
285
+ nowMs: { type: "number" },
286
+ updates: { type: "array", items: { type: "object" } },
287
+ queries: { $ref: "#/$defs/queryRequests" }
288
+ },
289
+ additionalProperties: false
290
+ },
291
+ history: { $ref: "#/$defs/historyPage" }
292
+ }),
293
+ frame("task", ["taskRef", "request", "history"], {
294
+ taskRef: { $ref: "#/$defs/queryTaskRef" },
295
+ request: {
296
+ type: "object",
297
+ required: ["workflowFn", "info", "queries"],
298
+ properties: {
299
+ workflowFn: ID,
300
+ info: { type: "object" },
301
+ queries: { $ref: "#/$defs/queryRequests" }
302
+ },
303
+ additionalProperties: false
304
+ },
305
+ history: { $ref: "#/$defs/historyPage" }
306
+ }),
307
+ frame("task", ["taskRef", "lease"], {
308
+ taskRef: { $ref: "#/$defs/activityTaskRef" },
309
+ lease: { type: "object" }
310
+ })
311
+ ]
312
+ },
313
+ heartbeatAck: frame("heartbeatAck", ["reqId", "cancelRequested", "paused"], {
314
+ reqId: ID,
315
+ cancelRequested: { type: "boolean" },
316
+ paused: { type: "boolean" },
317
+ pauseReason: { type: "string" }
318
+ }),
319
+ cancel: frame("cancel", ["taskRef", "reason"], {
320
+ taskRef: { $ref: "#/$defs/taskRef" },
321
+ reason: { type: "string" }
322
+ }),
323
+ res: {
324
+ ...frame("res", ["id", "ok"], {
325
+ id: ID,
326
+ ok: { type: "boolean" },
327
+ result: {},
328
+ error: {
329
+ type: "object",
330
+ required: ["code", "message"],
331
+ properties: { code: { type: "string" }, message: { type: "string" } },
332
+ additionalProperties: false
333
+ }
334
+ }),
335
+ if: { properties: { ok: { const: false } }, required: ["ok"] },
336
+ then: { required: ["error"] }
337
+ },
338
+ pong: frame("pong", [], { t: { type: "number" } }),
339
+ workerFrame: {
340
+ oneOf: [
341
+ { $ref: "#/$defs/hello" },
342
+ { $ref: "#/$defs/ping" },
343
+ { $ref: "#/$defs/pollers" },
344
+ { $ref: "#/$defs/taskResult" },
345
+ { $ref: "#/$defs/taskFailed" },
346
+ { $ref: "#/$defs/heartbeat" },
347
+ { $ref: "#/$defs/workerHeartbeat" },
348
+ { $ref: "#/$defs/req" },
349
+ { $ref: "#/$defs/bye" }
350
+ ]
351
+ },
352
+ serviceFrame: {
353
+ oneOf: [
354
+ { $ref: "#/$defs/welcome" },
355
+ { $ref: "#/$defs/task" },
356
+ { $ref: "#/$defs/heartbeatAck" },
357
+ { $ref: "#/$defs/cancel" },
358
+ { $ref: "#/$defs/res" },
359
+ { $ref: "#/$defs/pong" }
360
+ ]
361
+ }
362
+ }
363
+ };
364
+
365
+ // src/history/schema.ts
366
+ var BASE = "https://docs.fluidgrids.ai/schemas";
367
+ var RUN_EVENT_SCHEMA_ID = `${BASE}/run-event.schema.json`;
368
+ var WORKFLOW_COMMAND_SCHEMA_ID = `${BASE}/workflow-command.schema.json`;
369
+ var WORKFLOW_TASK_SCHEMA_ID = `${BASE}/workflow-task.schema.json`;
370
+ var HISTORY_FILE_SCHEMA_ID = `${BASE}/history-file.schema.json`;
371
+ var HISTORY_FILE_FORMAT = "fluidgrids.history";
372
+ var ID2 = { type: "string", minLength: 1, maxLength: 256 };
373
+ var NON_NEGATIVE_MS = { type: "integer", minimum: 0 };
374
+ var STRING_MAP = {
375
+ type: "object",
376
+ additionalProperties: { type: "string" },
377
+ description: "Interceptor headers (11 \xA72.10): string values; a user activity carries at most 16 KiB of JSON (checked by validateCommands)."
378
+ };
379
+ var FAIRNESS_KEY = {
380
+ type: "string",
381
+ minLength: 1,
382
+ maxLength: chunkTYF56RGB_cjs.FAIRNESS_KEY_MAX_LENGTH,
383
+ description: "Phase C: the fairness key of the task (11 \xA72.11); default the workspace id."
384
+ };
385
+ var FAIRNESS_WEIGHT = {
386
+ type: "number",
387
+ minimum: chunkTYF56RGB_cjs.FAIRNESS_WEIGHT_MIN,
388
+ maximum: chunkTYF56RGB_cjs.FAIRNESS_WEIGHT_MAX,
389
+ description: "Phase C: the weight of the fairness key, 0.1 to 10 (default 1)."
390
+ };
391
+ var ACTIVITY_NAME = { type: "string", pattern: chunkTYF56RGB_cjs.ACTIVITY_NAME_PATTERN };
392
+ var TASK_QUEUE_NAME = { type: "string", pattern: chunkTYF56RGB_cjs.TASK_QUEUE_NAME_PATTERN };
393
+ var SHARED_DEFS = {
394
+ json: {
395
+ description: "Any JSON value."
396
+ },
397
+ failure: {
398
+ type: "object",
399
+ required: ["errorType", "message"],
400
+ properties: {
401
+ errorType: { enum: [...chunkTYF56RGB_cjs.ERROR_TYPES] },
402
+ message: { type: "string" },
403
+ type: { type: "string" },
404
+ details: {},
405
+ nonRetryable: { type: "boolean" },
406
+ nextRetryDelayMs: NON_NEGATIVE_MS,
407
+ category: { const: "BENIGN" },
408
+ timeoutType: { type: "string" },
409
+ cause: { $ref: "#/$defs/failure" },
410
+ stackTrace: { type: "string" },
411
+ source: { type: "string" }
412
+ },
413
+ additionalProperties: false
414
+ },
415
+ retryPolicy: {
416
+ type: "object",
417
+ required: ["retryDelay"],
418
+ description: "maxRetries absent means unlimited attempts, bounded by scheduleToCloseTimeout.",
419
+ properties: {
420
+ maxRetries: { type: "integer", minimum: 0 },
421
+ retryDelay: NON_NEGATIVE_MS,
422
+ backoffMultiplier: { type: "number", minimum: 1 },
423
+ maxDelay: NON_NEGATIVE_MS,
424
+ retryOnErrorTypes: { type: "array", items: { enum: [...chunkTYF56RGB_cjs.ERROR_TYPES] } },
425
+ nonRetryableErrorTypes: { type: "array", items: { type: "string" } }
426
+ },
427
+ additionalProperties: false
428
+ },
429
+ runTarget: {
430
+ oneOf: [
431
+ {
432
+ type: "object",
433
+ required: ["runId"],
434
+ properties: { runId: ID2 },
435
+ additionalProperties: false
436
+ },
437
+ {
438
+ type: "object",
439
+ required: ["parent"],
440
+ properties: { parent: { const: true } },
441
+ additionalProperties: false
442
+ },
443
+ {
444
+ type: "object",
445
+ required: ["childId"],
446
+ properties: { childId: ID2 },
447
+ additionalProperties: false
448
+ },
449
+ {
450
+ type: "object",
451
+ required: ["workflowKey", "workflowId"],
452
+ description: "The open run of a workflow id, following its continue-as-new chain; firstRunId pins the chain (R2).",
453
+ properties: { workflowKey: ID2, workflowId: ID2, firstRunId: ID2 },
454
+ additionalProperties: false
455
+ }
456
+ ]
457
+ },
458
+ runRetryPolicy: {
459
+ type: "object",
460
+ required: ["initialDelayMs"],
461
+ description: "Run-level retry (11 \xA72.17), in milliseconds. maxAttempts counts every attempt; absent means unlimited, bounded by the execution timeout.",
462
+ properties: {
463
+ maxAttempts: { type: "integer", minimum: 1 },
464
+ initialDelayMs: NON_NEGATIVE_MS,
465
+ backoffMultiplier: { type: "number", minimum: 1 },
466
+ maxDelayMs: NON_NEGATIVE_MS,
467
+ retryOnErrorTypes: { type: "array", items: { enum: [...chunkTYF56RGB_cjs.ERROR_TYPES] } },
468
+ nonRetryableErrorTypes: { type: "array", items: { type: "string" } }
469
+ },
470
+ additionalProperties: false
471
+ },
472
+ timeouts: {
473
+ type: "object",
474
+ description: "The three workflow timeouts (11 \xA72.20), in milliseconds.",
475
+ properties: {
476
+ executionTimeout: NON_NEGATIVE_MS,
477
+ runTimeout: NON_NEGATIVE_MS,
478
+ workflowTaskTimeout: NON_NEGATIVE_MS
479
+ },
480
+ additionalProperties: false
481
+ },
482
+ childOptions: {
483
+ type: "object",
484
+ required: ["parentClosePolicy"],
485
+ properties: {
486
+ parentClosePolicy: { enum: [...chunkTYF56RGB_cjs.PARENT_CLOSE_POLICIES] },
487
+ cancellationType: { enum: [...chunkTYF56RGB_cjs.CHILD_CANCELLATION_TYPES] },
488
+ taskQueue: ID2,
489
+ workflowId: ID2,
490
+ priority: { type: "integer", minimum: 1, maximum: 5 },
491
+ summary: { type: "string", maxLength: 200 },
492
+ details: { type: "string" },
493
+ context: { type: "object" },
494
+ executionTimeout: NON_NEGATIVE_MS,
495
+ runTimeout: NON_NEGATIVE_MS,
496
+ workflowTaskTimeout: NON_NEGATIVE_MS,
497
+ startDelay: NON_NEGATIVE_MS,
498
+ retry: { $ref: "#/$defs/runRetryPolicy" },
499
+ versioningBehavior: { enum: [...chunkTYF56RGB_cjs.VERSIONING_BEHAVIORS] },
500
+ idReusePolicy: { enum: [...chunkTYF56RGB_cjs.WORKFLOW_ID_REUSE_POLICIES] },
501
+ idConflictPolicy: { enum: [...chunkTYF56RGB_cjs.WORKFLOW_ID_CONFLICT_POLICIES] },
502
+ fairnessKey: FAIRNESS_KEY,
503
+ fairnessWeight: FAIRNESS_WEIGHT
504
+ }
505
+ },
506
+ legacyCanRetryPolicy: {
507
+ type: "object",
508
+ required: ["retryDelay"],
509
+ description: "The R1 activity-shaped CONTINUE_AS_NEW retry: whatever explicitRetryPolicy wrote from a Partial<RetryPolicy>, so numbers carry no integer or minimum constraint. It never had a meaning, and the service ignores it.",
510
+ properties: {
511
+ maxRetries: { type: "number" },
512
+ retryDelay: { type: "number" },
513
+ backoffMultiplier: { type: "number" },
514
+ maxDelay: { type: "number" },
515
+ retryOnErrorTypes: { type: "array", items: { type: "string" } },
516
+ nonRetryableErrorTypes: { type: "array", items: { type: "string" } }
517
+ },
518
+ additionalProperties: false
519
+ },
520
+ canOptions: {
521
+ type: "object",
522
+ description: "Options of a CONTINUE_AS_NEW command (C-SCHEMA, frozen in R2). retry is the R2 run-retry policy of the new run, or the R1 activity shape (retryDelay, maxRetries, maxDelay) that R1 bundles wrote and R2 bundles still write for that shape: it never had a meaning, and the service ignores it instead of reading it as a run-retry policy.",
523
+ properties: {
524
+ taskQueue: ID2,
525
+ retry: {
526
+ oneOf: [{ $ref: "#/$defs/runRetryPolicy" }, { $ref: "#/$defs/legacyCanRetryPolicy" }]
527
+ },
528
+ workflowTaskTimeout: NON_NEGATIVE_MS,
529
+ context: { type: "object" },
530
+ versioningBehavior: { enum: [...chunkTYF56RGB_cjs.VERSIONING_BEHAVIORS] }
531
+ },
532
+ additionalProperties: false
533
+ },
534
+ headers: STRING_MAP
535
+ };
536
+ function command(type, required, properties) {
537
+ return {
538
+ type: "object",
539
+ required: ["type", ...required],
540
+ properties: { type: { const: type }, headers: { $ref: "#/$defs/headers" }, ...properties },
541
+ additionalProperties: false
542
+ };
543
+ }
544
+ var ACTIVITY_COMMON = {
545
+ activityId: ID2,
546
+ args: {},
547
+ retry: { $ref: "#/$defs/retryPolicy" },
548
+ startToCloseTimeout: NON_NEGATIVE_MS,
549
+ scheduleToCloseTimeout: NON_NEGATIVE_MS,
550
+ scheduleToStartTimeout: NON_NEGATIVE_MS,
551
+ heartbeatTimeout: NON_NEGATIVE_MS,
552
+ cancellationType: { enum: [...chunkTYF56RGB_cjs.ACTIVITY_CANCELLATION_TYPES] },
553
+ priority: { type: "integer", minimum: 1, maximum: 5 },
554
+ summary: { type: "string", maxLength: 200 },
555
+ fairnessKey: FAIRNESS_KEY,
556
+ fairnessWeight: FAIRNESS_WEIGHT
557
+ };
558
+ var NODE_ACTIVITY = {
559
+ kind: { const: "node" },
560
+ nodeType: ID2,
561
+ nodeVersion: { type: "string" },
562
+ operation: ID2,
563
+ connection: ID2,
564
+ runOn: { type: "string" }
565
+ };
566
+ var USER_ACTIVITY = {
567
+ kind: { const: "user" },
568
+ activityName: ACTIVITY_NAME,
569
+ taskQueue: TASK_QUEUE_NAME,
570
+ connections: {
571
+ type: "array",
572
+ maxItems: chunkTYF56RGB_cjs.MAX_ACTIVITY_CONNECTIONS,
573
+ uniqueItems: true,
574
+ items: ID2,
575
+ description: "Connection names the worker may resolve for each started attempt (H2: declared by the definition and on the worker token allow-list)."
576
+ }
577
+ };
578
+ var NODE_ACTIVITY_REQUIRED = ["activityId", "kind", "nodeType", "operation", "args", "retry"];
579
+ var USER_ACTIVITY_REQUIRED = ["activityId", "kind", "activityName", "taskQueue", "args", "retry"];
580
+ var COMMAND_DEFS = {
581
+ SCHEDULE_ACTIVITY: {
582
+ description: "A oneOf on kind (C-CMD-C): node runs a canvas node operation; user (Phase C) runs a user activity on a self-hosted task queue.",
583
+ oneOf: [
584
+ command("SCHEDULE_ACTIVITY", NODE_ACTIVITY_REQUIRED.slice(), {
585
+ ...ACTIVITY_COMMON,
586
+ ...NODE_ACTIVITY
587
+ }),
588
+ command("SCHEDULE_ACTIVITY", USER_ACTIVITY_REQUIRED.slice(), {
589
+ ...ACTIVITY_COMMON,
590
+ ...USER_ACTIVITY
591
+ })
592
+ ]
593
+ },
594
+ REQUEST_CANCEL_ACTIVITY: command("REQUEST_CANCEL_ACTIVITY", ["activityId"], { activityId: ID2 }),
595
+ START_TIMER: command("START_TIMER", ["timerId", "durationMs"], {
596
+ timerId: ID2,
597
+ durationMs: { type: "integer", minimum: 1 },
598
+ summary: { type: "string", maxLength: 200 }
599
+ }),
600
+ CANCEL_TIMER: command("CANCEL_TIMER", ["timerId"], { timerId: ID2 }),
601
+ START_CHILD_RUN: {
602
+ ...command("START_CHILD_RUN", ["childId", "input", "options"], {
603
+ childId: ID2,
604
+ workflowKey: ID2,
605
+ workflowFn: ID2,
606
+ version: { type: "string", minLength: 1 },
607
+ input: {},
608
+ options: { $ref: "#/$defs/childOptions" }
609
+ }),
610
+ oneOf: [{ required: ["workflowKey"] }, { required: ["workflowFn"] }]
611
+ },
612
+ SIGNAL_RUN: command("SIGNAL_RUN", ["externalId", "target", "name", "payload"], {
613
+ externalId: ID2,
614
+ target: { $ref: "#/$defs/runTarget" },
615
+ name: ID2,
616
+ payload: {}
617
+ }),
618
+ RECORD_SIDE_EFFECT: command("RECORD_SIDE_EFFECT", ["sideEffectId", "value"], {
619
+ sideEffectId: ID2,
620
+ value: {}
621
+ }),
622
+ RECORD_MARKER: command("RECORD_MARKER", ["markerId", "data"], { markerId: ID2, data: {} }),
623
+ COMPLETE_WORKFLOW: command("COMPLETE_WORKFLOW", ["output"], { output: {} }),
624
+ FAIL_WORKFLOW: command("FAIL_WORKFLOW", ["failure"], {
625
+ failure: { $ref: "#/$defs/failure" }
626
+ }),
627
+ CANCEL_WORKFLOW: command("CANCEL_WORKFLOW", [], {}),
628
+ UPSERT_CONTEXT: command("UPSERT_CONTEXT", ["entries"], { entries: { type: "object" } }),
629
+ RECORD_LOCAL_ACTIVITY: {
630
+ ...command("RECORD_LOCAL_ACTIVITY", ["localActivityId", "attempts"], {
631
+ localActivityId: ID2,
632
+ result: {},
633
+ failure: { $ref: "#/$defs/failure" },
634
+ attempts: { type: "integer", minimum: 1 },
635
+ nodeType: ID2,
636
+ operation: ID2,
637
+ summary: { type: "string", maxLength: 200 }
638
+ }),
639
+ oneOf: [{ required: ["result"] }, { required: ["failure"] }]
640
+ },
641
+ CONTINUE_AS_NEW: command("CONTINUE_AS_NEW", ["input", "options"], {
642
+ input: {},
643
+ options: { $ref: "#/$defs/canOptions" }
644
+ }),
645
+ REQUEST_CANCEL_EXTERNAL_RUN: command("REQUEST_CANCEL_EXTERNAL_RUN", ["externalId", "target"], {
646
+ externalId: ID2,
647
+ target: { $ref: "#/$defs/runTarget" }
648
+ }),
649
+ UPSERT_SEARCH_ATTRIBUTES: command("UPSERT_SEARCH_ATTRIBUTES", ["attributes"], {
650
+ attributes: { type: "object" }
651
+ }),
652
+ ACCEPT_UPDATE: command("ACCEPT_UPDATE", ["updateId"], { updateId: ID2 }),
653
+ REJECT_UPDATE: command("REJECT_UPDATE", ["updateId", "failure"], {
654
+ updateId: ID2,
655
+ failure: { $ref: "#/$defs/failure" }
656
+ }),
657
+ COMPLETE_UPDATE: command("COMPLETE_UPDATE", ["updateId"], {
658
+ updateId: ID2,
659
+ result: {},
660
+ failure: { $ref: "#/$defs/failure" }
661
+ })
662
+ };
663
+ function payload(required, properties) {
664
+ return { type: "object", required, properties };
665
+ }
666
+ var FAILURE_REF = { $ref: "#/$defs/failure" };
667
+ var EVENT_PAYLOADS = {
668
+ WORKFLOW_STARTED: payload(["workflowFn", "input"], {
669
+ workflowFn: ID2,
670
+ input: {},
671
+ workflowKey: { type: "string" },
672
+ version: {},
673
+ buildId: { type: "string" },
674
+ taskQueue: { type: "string" },
675
+ parentRunId: { type: ["string", "null"] },
676
+ rootRunId: { type: ["string", "null"] },
677
+ firstRunId: { type: ["string", "null"] },
678
+ continuedFromRunId: { type: ["string", "null"] },
679
+ parentClosePolicy: { enum: [...chunkTYF56RGB_cjs.PARENT_CLOSE_POLICIES] },
680
+ startDelay: NON_NEGATIVE_MS,
681
+ lastCompletionResult: {},
682
+ lastFailure: { oneOf: [{ type: "null" }, FAILURE_REF] },
683
+ summary: { type: "string" },
684
+ details: { type: "string" },
685
+ context: { type: "object" },
686
+ executionTimeout: NON_NEGATIVE_MS,
687
+ runTimeout: NON_NEGATIVE_MS,
688
+ workflowTaskTimeout: NON_NEGATIVE_MS,
689
+ versioningBehavior: { enum: [...chunkTYF56RGB_cjs.VERSIONING_BEHAVIORS] },
690
+ /** Seed of `ctx.random()`/`ctx.uuid()`; the service writes the run id. Absent: `info.runId`. */
691
+ randomnessSeed: ID2,
692
+ startDelayMs: {
693
+ ...NON_NEGATIVE_MS,
694
+ description: "R2: the start delay of a delayed run (11 \xA72.23); the first task waits for it."
695
+ },
696
+ runAttempt: {
697
+ type: "integer",
698
+ minimum: 1,
699
+ description: "R2: the run-level retry attempt (11 \xA72.17), 1-based."
700
+ },
701
+ businessId: {
702
+ type: "string",
703
+ description: "R2: the workflow id (11 \xA72.1), stored as WorkflowRun.businessId."
704
+ },
705
+ workflowId: { type: "string", description: "R2: the same value as businessId." },
706
+ timeouts: { $ref: "#/$defs/timeouts" },
707
+ retry: { $ref: "#/$defs/runRetryPolicy" },
708
+ priority: { type: "integer", minimum: 1, maximum: 5 },
709
+ headers: { $ref: "#/$defs/headers" },
710
+ searchAttributes: {
711
+ type: "object",
712
+ description: "Phase C: the search attributes the start set (11 \xA72.8)."
713
+ },
714
+ fairnessKey: FAIRNESS_KEY,
715
+ fairnessWeight: FAIRNESS_WEIGHT
716
+ }),
717
+ WORKFLOW_TASK_SCHEDULED: payload(["taskId"], {
718
+ taskId: ID2,
719
+ attempt: { type: "integer", minimum: 1 }
720
+ }),
721
+ WORKFLOW_TASK_STARTED: payload(["taskId", "attempt"], {
722
+ taskId: ID2,
723
+ attempt: { type: "integer", minimum: 1 },
724
+ workerId: { type: "string" },
725
+ buildId: { type: "string" },
726
+ startedAt: {
727
+ type: "string",
728
+ 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."
729
+ },
730
+ historyLength: {
731
+ type: "integer",
732
+ minimum: 1,
733
+ 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."
734
+ },
735
+ version: {
736
+ description: "R2: the workflow version whose bundle served the task (it differs from WORKFLOW_STARTED.version after an AUTO_UPGRADE or a versioning override)."
737
+ }
738
+ }),
739
+ WORKFLOW_TASK_COMPLETED: payload(["taskId"], {
740
+ taskId: ID2,
741
+ buildId: { type: "string" },
742
+ workerId: { type: "string" }
743
+ }),
744
+ WORKFLOW_TASK_FAILED: payload(["taskId", "attempt", "cause"], {
745
+ taskId: ID2,
746
+ attempt: { type: "integer", minimum: 1 },
747
+ cause: { enum: [...chunkTYF56RGB_cjs.TASK_FAILURE_CAUSES] },
748
+ message: { type: "string" },
749
+ stackTrace: { type: "string" },
750
+ buildId: { type: "string" }
751
+ }),
752
+ WORKFLOW_TASK_TIMED_OUT: payload(["taskId", "attempt"], {
753
+ taskId: ID2,
754
+ attempt: { type: "integer", minimum: 1 }
755
+ }),
756
+ ACTIVITY_SCHEDULED: {
757
+ description: "The SCHEDULE_ACTIVITY command as the service accepted it: kind node, or kind user (Phase C) with activityName, taskQueue, fairness, connections and headers.",
758
+ oneOf: [
759
+ payload(NODE_ACTIVITY_REQUIRED.slice(), {
760
+ ...ACTIVITY_COMMON,
761
+ ...NODE_ACTIVITY,
762
+ headers: { $ref: "#/$defs/headers" }
763
+ }),
764
+ payload(USER_ACTIVITY_REQUIRED.slice(), {
765
+ ...ACTIVITY_COMMON,
766
+ ...USER_ACTIVITY,
767
+ headers: { $ref: "#/$defs/headers" }
768
+ })
769
+ ]
770
+ },
771
+ ACTIVITY_STARTED: payload(["activityId", "attempt"], {
772
+ activityId: ID2,
773
+ attempt: { type: "integer", minimum: 1 },
774
+ workerId: { type: "string" }
775
+ }),
776
+ ACTIVITY_HEARTBEAT: payload(["activityId"], { activityId: ID2, details: {} }),
777
+ ACTIVITY_COMPLETED: payload(["activityId", "attempt"], {
778
+ activityId: ID2,
779
+ attempt: { type: "integer", minimum: 1 },
780
+ result: {}
781
+ }),
782
+ ACTIVITY_FAILED: payload(["activityId", "attempt", "failure"], {
783
+ activityId: ID2,
784
+ attempt: { type: "integer", minimum: 1 },
785
+ failure: FAILURE_REF
786
+ }),
787
+ ACTIVITY_TIMED_OUT: payload(["activityId", "attempt", "timeoutType"], {
788
+ activityId: ID2,
789
+ attempt: { type: "integer", minimum: 1 },
790
+ timeoutType: {
791
+ enum: ["START_TO_CLOSE", "SCHEDULE_TO_START", "SCHEDULE_TO_CLOSE", "HEARTBEAT"]
792
+ },
793
+ failure: FAILURE_REF
794
+ }),
795
+ ACTIVITY_CANCEL_REQUESTED: payload(["activityId"], { activityId: ID2 }),
796
+ ACTIVITY_CANCELLED: payload(["activityId"], { activityId: ID2, details: {} }),
797
+ ACTIVITY_PAUSED: payload(["activityId"], { activityId: ID2, reason: { type: "string" } }),
798
+ ACTIVITY_UNPAUSED: payload(["activityId"], { activityId: ID2 }),
799
+ ACTIVITY_RESET: payload(["activityId"], { activityId: ID2 }),
800
+ ACTIVITY_OPTIONS_UPDATED: payload(["activityId"], {
801
+ activityId: ID2,
802
+ options: { type: "object" }
803
+ }),
804
+ TIMER_STARTED: payload(["timerId", "durationMs", "fireAt"], {
805
+ timerId: ID2,
806
+ durationMs: { type: "integer", minimum: 1 },
807
+ fireAt: { type: "string" },
808
+ summary: { type: "string" }
809
+ }),
810
+ TIMER_FIRED: payload(["timerId"], { timerId: ID2 }),
811
+ TIMER_CANCELLED: payload(["timerId"], { timerId: ID2 }),
812
+ SIGNAL_RECEIVED: payload(["name"], {
813
+ name: ID2,
814
+ payload: {},
815
+ receivedAt: { type: "string" },
816
+ actor: {},
817
+ idempotencyKey: { type: "string" },
818
+ headers: { $ref: "#/$defs/headers" }
819
+ }),
820
+ UPDATE_ADMITTED: payload(["updateId", "name"], {
821
+ updateId: ID2,
822
+ name: ID2,
823
+ args: {},
824
+ headers: { $ref: "#/$defs/headers" }
825
+ }),
826
+ UPDATE_ACCEPTED: payload(["updateId", "name"], {
827
+ updateId: ID2,
828
+ name: ID2,
829
+ args: {},
830
+ headers: { $ref: "#/$defs/headers" }
831
+ }),
832
+ UPDATE_COMPLETED: payload(["updateId"], { updateId: ID2, result: {}, failure: FAILURE_REF }),
833
+ CHILD_RUN_INITIATED: payload(["childId", "input", "options"], {
834
+ childId: ID2,
835
+ workflowKey: ID2,
836
+ workflowFn: ID2,
837
+ version: { type: "string" },
838
+ input: {},
839
+ options: { $ref: "#/$defs/childOptions" },
840
+ childRunId: { type: "string" },
841
+ executionKind: { enum: ["GRAPH", "DURABLE_FN"] },
842
+ headers: { $ref: "#/$defs/headers" }
843
+ }),
844
+ CHILD_RUN_STARTED: payload(["childId", "childRunId"], {
845
+ childId: ID2,
846
+ childRunId: ID2,
847
+ executionKind: { enum: ["GRAPH", "DURABLE_FN"] }
848
+ }),
849
+ CHILD_RUN_COMPLETED: payload(["childId"], { childId: ID2, childRunId: ID2, result: {} }),
850
+ CHILD_RUN_FAILED: payload(["childId", "failure"], {
851
+ childId: ID2,
852
+ childRunId: ID2,
853
+ failure: FAILURE_REF
854
+ }),
855
+ CHILD_RUN_CANCELLED: payload(["childId"], { childId: ID2, childRunId: ID2 }),
856
+ CHILD_RUN_TERMINATED: payload(["childId"], {
857
+ childId: ID2,
858
+ childRunId: ID2,
859
+ reason: { type: "string" }
860
+ }),
861
+ CHILD_RUN_TIMED_OUT: payload(["childId"], {
862
+ childId: ID2,
863
+ childRunId: ID2,
864
+ timeoutType: { enum: [...chunkTYF56RGB_cjs.WORKFLOW_TIMEOUT_TYPES] }
865
+ }),
866
+ EXTERNAL_RUN_CANCEL_REQUESTED: payload(["externalId", "target"], {
867
+ externalId: ID2,
868
+ target: { $ref: "#/$defs/runTarget" }
869
+ }),
870
+ EXTERNAL_RUN_CANCEL_RESOLVED: payload(["externalId", "ok"], {
871
+ externalId: ID2,
872
+ ok: { type: "boolean" },
873
+ targetRunId: { type: "string" },
874
+ failure: FAILURE_REF
875
+ }),
876
+ EXTERNAL_RUN_SIGNALED: {
877
+ type: "object",
878
+ required: ["externalId"],
879
+ 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?}.",
880
+ properties: {
881
+ externalId: ID2,
882
+ target: { $ref: "#/$defs/runTarget" },
883
+ name: ID2,
884
+ payload: {},
885
+ resolved: { const: true },
886
+ ok: { type: "boolean" },
887
+ targetRunId: { type: "string" },
888
+ failure: FAILURE_REF
889
+ },
890
+ if: { required: ["resolved"] },
891
+ then: { required: ["ok"] },
892
+ else: { required: ["target", "name"] }
893
+ },
894
+ SIDE_EFFECT_RECORDED: payload(["sideEffectId", "value"], { sideEffectId: ID2, value: {} }),
895
+ LOCAL_ACTIVITY_COMPLETED: payload(["localActivityId", "attempts"], {
896
+ localActivityId: ID2,
897
+ result: {},
898
+ attempts: { type: "integer", minimum: 1 },
899
+ nodeType: ID2,
900
+ operation: ID2,
901
+ summary: { type: "string" }
902
+ }),
903
+ LOCAL_ACTIVITY_FAILED: payload(["localActivityId", "attempts", "failure"], {
904
+ localActivityId: ID2,
905
+ failure: FAILURE_REF,
906
+ attempts: { type: "integer", minimum: 1 },
907
+ nodeType: ID2,
908
+ operation: ID2,
909
+ summary: { type: "string" }
910
+ }),
911
+ SEARCH_ATTRIBUTES_UPSERTED: payload(["attributes"], { attributes: { type: "object" } }),
912
+ CONTEXT_UPSERTED: payload(["entries"], { entries: { type: "object" } }),
913
+ MARKER_RECORDED: payload(["markerId", "data"], {
914
+ markerId: ID2,
915
+ data: {}
916
+ }),
917
+ WORKFLOW_CANCEL_REQUESTED: payload([], { actor: {}, reason: { type: "string" } }),
918
+ WORKFLOW_RESET: payload(["fromRunId", "toSeq"], {
919
+ fromRunId: ID2,
920
+ toSeq: { type: "integer", minimum: 1 },
921
+ reason: { type: "string" },
922
+ actor: {},
923
+ reapplySignals: { type: "boolean" },
924
+ reapplyUpdates: { type: "boolean" }
925
+ }),
926
+ VERSIONING_OVERRIDE_SET: payload(["override"], {
927
+ override: {
928
+ description: "The per-run override (11 \xA72.27): { behavior: PINNED, version } pins the run, { behavior: AUTO_UPGRADE } upgrades it, null removes the override.",
929
+ oneOf: [
930
+ { type: "null" },
931
+ {
932
+ type: "object",
933
+ required: ["behavior", "version"],
934
+ properties: { behavior: { const: "PINNED" }, version: {} },
935
+ additionalProperties: false
936
+ },
937
+ {
938
+ type: "object",
939
+ required: ["behavior"],
940
+ properties: { behavior: { const: "AUTO_UPGRADE" } },
941
+ additionalProperties: false
942
+ }
943
+ ]
944
+ },
945
+ actor: {},
946
+ reason: { type: "string" }
947
+ }),
948
+ WORKFLOW_COMPLETED: payload(["output"], { output: {} }),
949
+ WORKFLOW_FAILED: payload(["failure"], { failure: FAILURE_REF }),
950
+ WORKFLOW_CANCELLED: payload([], { details: {} }),
951
+ WORKFLOW_TERMINATED: payload([], { reason: { type: "string" }, actor: {} }),
952
+ WORKFLOW_TIMED_OUT: payload(["timeoutType"], {
953
+ timeoutType: { enum: [...chunkTYF56RGB_cjs.WORKFLOW_TIMEOUT_TYPES] },
954
+ failure: FAILURE_REF
955
+ }),
956
+ WORKFLOW_CONTINUED_AS_NEW: payload(["input", "options"], {
957
+ input: {},
958
+ // Not canOptions: the event keeps what the service accepted when the run
959
+ // continued, and Phase B (R1) runs stored options that the R2 command shape
960
+ // refuses (fractional delays, a backoff below 1, a long task queue).
961
+ options: {
962
+ type: "object",
963
+ description: "The CONTINUE_AS_NEW options as the service recorded them. New commands are checked against canOptions; histories recorded before R2 may hold any object the R1 contract accepted."
964
+ },
965
+ newRunId: { type: "string" }
966
+ })
967
+ };
968
+ function compact(value) {
969
+ const out = {};
970
+ for (const [key, entry] of Object.entries(value)) {
971
+ if (entry === void 0) continue;
972
+ out[key] = typeof entry === "object" && entry !== null && !Array.isArray(entry) ? compact(entry) : entry;
973
+ }
974
+ return out;
975
+ }
976
+ var RUN_EVENT_RECORD = {
977
+ type: "object",
978
+ required: ["seq", "type", "payload", "createdAt"],
979
+ properties: {
980
+ seq: { type: "integer", minimum: 1 },
981
+ type: { enum: [...chunkTYF56RGB_cjs.EVENT_TYPES] },
982
+ taskId: { type: ["string", "null"] },
983
+ payload: { type: "object" },
984
+ createdAt: { type: "string", minLength: 1 },
985
+ dedupeKey: { type: ["string", "null"] }
986
+ },
987
+ allOf: chunkTYF56RGB_cjs.EVENT_TYPES.map((type) => ({
988
+ if: { properties: { type: { const: type } }, required: ["type"] },
989
+ then: { properties: { payload: { $ref: `#/$defs/payload_${type}` } } }
990
+ }))
991
+ };
992
+ function payloadDefs() {
993
+ const defs = {};
994
+ for (const type of chunkTYF56RGB_cjs.EVENT_TYPES) defs[`payload_${type}`] = compact(EVENT_PAYLOADS[type]);
995
+ return defs;
996
+ }
997
+ function commandDefs() {
998
+ const defs = {};
999
+ for (const type of chunkTYF56RGB_cjs.COMMAND_TYPES) defs[`command_${type}`] = COMMAND_DEFS[type];
1000
+ return defs;
1001
+ }
1002
+ var COMMAND_ONE_OF = {
1003
+ type: "object",
1004
+ required: ["type"],
1005
+ properties: { type: { enum: [...chunkTYF56RGB_cjs.COMMAND_TYPES] } },
1006
+ allOf: chunkTYF56RGB_cjs.COMMAND_TYPES.map((type) => ({
1007
+ if: { properties: { type: { const: type } }, required: ["type"] },
1008
+ then: { $ref: `#/$defs/command_${type}` }
1009
+ }))
1010
+ };
1011
+ var RUN_EVENT_SCHEMA = {
1012
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1013
+ $id: RUN_EVENT_SCHEMA_ID,
1014
+ title: "FluidGrids durable-function history event",
1015
+ description: "One row of workflow_run_events as the service returns it (offloaded payloads inlined). type is UPPER_SNAKE.",
1016
+ ...RUN_EVENT_RECORD,
1017
+ $defs: { ...SHARED_DEFS, ...payloadDefs() }
1018
+ };
1019
+ var WORKFLOW_COMMAND_SCHEMA = {
1020
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1021
+ $id: WORKFLOW_COMMAND_SCHEMA_ID,
1022
+ title: "FluidGrids workflow-task command",
1023
+ description: "A flat object discriminated by an UPPER_SNAKE type. Commands travel as [JSON!]! (DB4). UPSERT_SEARCH_ATTRIBUTES, ACCEPT_UPDATE, REJECT_UPDATE, COMPLETE_UPDATE and SCHEDULE_ACTIVITY of kind user are Phase C: the service accepts them only for the C-GATE features its flags enable (c.searchAttributes, c.updates, c.userActivity).",
1024
+ ...COMMAND_ONE_OF,
1025
+ $defs: { ...SHARED_DEFS, ...commandDefs() }
1026
+ };
1027
+ var WORKFLOW_TASK_SCHEMA = {
1028
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1029
+ $id: WORKFLOW_TASK_SCHEMA_ID,
1030
+ title: "FluidGrids workflow task (runtime ABI protocol 1)",
1031
+ description: 'globalThis.__fluidgridsRuntime: start(JSON of request); while (step() === "more") drain jobs; complete() returns JSON of result.',
1032
+ oneOf: [{ $ref: "#/$defs/request" }, { $ref: "#/$defs/result" }],
1033
+ $defs: {
1034
+ ...SHARED_DEFS,
1035
+ ...payloadDefs(),
1036
+ ...commandDefs(),
1037
+ event: RUN_EVENT_RECORD,
1038
+ command: COMMAND_ONE_OF,
1039
+ info: {
1040
+ type: "object",
1041
+ required: ["runId", "workspaceId"],
1042
+ properties: {
1043
+ runId: ID2,
1044
+ workspaceId: ID2,
1045
+ workflowKey: { type: "string" },
1046
+ version: {},
1047
+ buildId: { type: "string" },
1048
+ businessId: { type: "string" },
1049
+ workflowId: { type: "string" },
1050
+ attempt: { type: "integer", minimum: 1 },
1051
+ runAttempt: { type: "integer", minimum: 1 },
1052
+ taskQueue: { type: "string" },
1053
+ parentRunId: { type: ["string", "null"] },
1054
+ rootRunId: { type: ["string", "null"] },
1055
+ firstRunId: { type: ["string", "null"] },
1056
+ continuedFromRunId: { type: ["string", "null"] },
1057
+ lastResult: {},
1058
+ lastFailure: { oneOf: [{ type: "null" }, FAILURE_REF] },
1059
+ startedAt: { type: "string" },
1060
+ runStartedAt: { type: "string" },
1061
+ historyLimit: {
1062
+ type: "object",
1063
+ required: ["events", "bytes"],
1064
+ properties: {
1065
+ events: { type: "integer", minimum: 1 },
1066
+ bytes: { type: "integer", minimum: 1 }
1067
+ }
1068
+ },
1069
+ timeouts: { type: "object" },
1070
+ headers: { $ref: "#/$defs/headers" },
1071
+ priority: { type: "integer", minimum: 1, maximum: 5 },
1072
+ summary: { type: "string" },
1073
+ details: { type: "string" },
1074
+ context: { type: "object" },
1075
+ memo: { type: "object" },
1076
+ versioningBehavior: { enum: [...chunkTYF56RGB_cjs.VERSIONING_BEHAVIORS] },
1077
+ retry: { $ref: "#/$defs/runRetryPolicy" },
1078
+ searchAttributes: { type: "object" },
1079
+ fairnessKey: FAIRNESS_KEY,
1080
+ fairnessWeight: FAIRNESS_WEIGHT
1081
+ }
1082
+ },
1083
+ updateRequest: {
1084
+ type: "object",
1085
+ required: ["updateId", "name"],
1086
+ description: "Phase C (C-ABI-H): a pending update the lease delivers. admitted marks one history already holds as UPDATE_ADMITTED; the runtime delivers that one from the event.",
1087
+ properties: {
1088
+ updateId: ID2,
1089
+ name: ID2,
1090
+ args: {},
1091
+ admitted: { type: "boolean" },
1092
+ headers: { $ref: "#/$defs/headers" }
1093
+ },
1094
+ additionalProperties: false
1095
+ },
1096
+ sinkCall: {
1097
+ type: "object",
1098
+ required: ["sink", "fn", "args"],
1099
+ description: "Phase C: a call of ctx.sinks.<sink>.<fn>(...args), never made on replay.",
1100
+ properties: {
1101
+ sink: ID2,
1102
+ fn: ID2,
1103
+ args: { type: "array" }
1104
+ },
1105
+ additionalProperties: false
1106
+ },
1107
+ localActivityRequest: {
1108
+ type: "object",
1109
+ required: [
1110
+ "localActivityId",
1111
+ "kind",
1112
+ "nodeType",
1113
+ "operation",
1114
+ "args",
1115
+ "retry",
1116
+ "startToCloseTimeout",
1117
+ "attempt",
1118
+ "backoffMs"
1119
+ ],
1120
+ description: "R2: a local activity the task needs (11 \xA72.12). Run attempt `attempt` after waiting backoffMs, then run the same task again with the outcome in localActivityResults.",
1121
+ properties: {
1122
+ localActivityId: ID2,
1123
+ kind: { const: "node" },
1124
+ nodeType: ID2,
1125
+ nodeVersion: { type: "string" },
1126
+ operation: ID2,
1127
+ args: {},
1128
+ connection: ID2,
1129
+ retry: { $ref: "#/$defs/retryPolicy" },
1130
+ startToCloseTimeout: {
1131
+ type: "integer",
1132
+ minimum: 1,
1133
+ maximum: chunkTYF56RGB_cjs.LOCAL_ACTIVITY_MAX_TIMEOUT_MS
1134
+ },
1135
+ attempt: { type: "integer", minimum: 1 },
1136
+ backoffMs: NON_NEGATIVE_MS,
1137
+ summary: { type: "string", maxLength: 200 }
1138
+ },
1139
+ additionalProperties: false
1140
+ },
1141
+ request: {
1142
+ type: "object",
1143
+ required: ["protocol", "kind", "workflowFn", "info", "history", "nowMs"],
1144
+ properties: {
1145
+ protocol: { const: chunkTYF56RGB_cjs.HISTORY_PROTOCOL },
1146
+ kind: { enum: ["task", "query", "verify"] },
1147
+ workflowFn: ID2,
1148
+ info: { $ref: "#/$defs/info" },
1149
+ history: { type: "array", items: { $ref: "#/$defs/event" } },
1150
+ nowMs: { type: "number" },
1151
+ localActivityResults: {
1152
+ type: "array",
1153
+ items: {
1154
+ type: "object",
1155
+ required: ["localActivityId", "attempts"],
1156
+ properties: {
1157
+ localActivityId: ID2,
1158
+ result: {},
1159
+ failure: FAILURE_REF,
1160
+ attempts: { type: "integer", minimum: 1 }
1161
+ }
1162
+ }
1163
+ },
1164
+ updates: {
1165
+ type: "array",
1166
+ items: { $ref: "#/$defs/updateRequest" }
1167
+ },
1168
+ queries: {
1169
+ type: "array",
1170
+ items: {
1171
+ type: "object",
1172
+ required: ["queryId", "name"],
1173
+ properties: {
1174
+ queryId: ID2,
1175
+ name: {
1176
+ ...ID2,
1177
+ description: `A built-in query (${chunkTYF56RGB_cjs.BUILT_IN_QUERIES.join(", ")}) or, from C-R1, the name of a custom query.`
1178
+ },
1179
+ args: {}
1180
+ }
1181
+ }
1182
+ },
1183
+ features: {
1184
+ type: "array",
1185
+ items: { type: "string", minLength: 1 },
1186
+ uniqueItems: true,
1187
+ description: "The bundle features (code.features names) the workspace enables for this task. From C-R1 the runtime reads `interceptors`: a task of a bundle that exports interceptors fails with UNSUPPORTED_COMMAND unless it is listed."
1188
+ }
1189
+ }
1190
+ },
1191
+ result: {
1192
+ type: "object",
1193
+ required: ["protocol", "outcome", "commands", "logs"],
1194
+ properties: {
1195
+ protocol: { const: chunkTYF56RGB_cjs.HISTORY_PROTOCOL },
1196
+ outcome: { enum: ["commands", "failed", "localActivityRequested"] },
1197
+ commands: { type: "array", items: { $ref: "#/$defs/command" } },
1198
+ localActivityRequests: {
1199
+ type: "array",
1200
+ items: { $ref: "#/$defs/localActivityRequest" }
1201
+ },
1202
+ unfinishedHandlers: {
1203
+ type: "array",
1204
+ description: "R2: handlers still running when the terminal command was issued (11 \xA72.18); never set on replay.",
1205
+ items: {
1206
+ type: "object",
1207
+ required: ["kind", "name", "count"],
1208
+ properties: {
1209
+ kind: { enum: ["signal", "update"] },
1210
+ name: { type: "string" },
1211
+ count: { type: "integer", minimum: 1 }
1212
+ },
1213
+ additionalProperties: false
1214
+ }
1215
+ },
1216
+ queryResults: {
1217
+ type: "array",
1218
+ items: {
1219
+ type: "object",
1220
+ required: ["queryId"],
1221
+ properties: {
1222
+ queryId: ID2,
1223
+ value: {},
1224
+ error: { type: "string" },
1225
+ rejected: {
1226
+ type: "boolean",
1227
+ description: "Phase C: no handler took the query name (the service answers VALIDATION)."
1228
+ }
1229
+ }
1230
+ }
1231
+ },
1232
+ sinkCalls: {
1233
+ type: "array",
1234
+ maxItems: chunkTYF56RGB_cjs.MAX_SINK_CALLS,
1235
+ items: { $ref: "#/$defs/sinkCall" }
1236
+ },
1237
+ failure: {
1238
+ type: "object",
1239
+ required: ["cause", "message"],
1240
+ properties: {
1241
+ cause: { enum: [...chunkTYF56RGB_cjs.TASK_FAILURE_CAUSES] },
1242
+ message: { type: "string" },
1243
+ stackTrace: { type: "string" },
1244
+ seq: { type: "integer" },
1245
+ errorType: { type: "string" }
1246
+ }
1247
+ },
1248
+ logs: {
1249
+ type: "array",
1250
+ items: {
1251
+ type: "object",
1252
+ required: ["level", "message"],
1253
+ properties: {
1254
+ level: { enum: ["debug", "info", "warn", "error"] },
1255
+ message: { type: "string" },
1256
+ data: {}
1257
+ }
1258
+ }
1259
+ },
1260
+ stackTrace: { type: "string" }
1261
+ }
1262
+ }
1263
+ }
1264
+ };
1265
+ var HISTORY_FILE_SCHEMA = {
1266
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1267
+ $id: HISTORY_FILE_SCHEMA_ID,
1268
+ title: "FluidGrids durable-function history file",
1269
+ type: "object",
1270
+ required: ["format", "formatVersion", "workflowFn", "events"],
1271
+ properties: {
1272
+ format: { const: HISTORY_FILE_FORMAT },
1273
+ formatVersion: { const: chunkTYF56RGB_cjs.HISTORY_PROTOCOL },
1274
+ name: { type: "string" },
1275
+ description: { type: "string" },
1276
+ workflowFn: ID2,
1277
+ source: { type: "string", description: "Fixture source module, relative to the file." },
1278
+ replaySource: {
1279
+ type: "string",
1280
+ description: "Fixture module the replay check runs instead of source (a hotfix or a patched() version)."
1281
+ },
1282
+ replay: {
1283
+ type: "boolean",
1284
+ description: "False for histories that are parsed and projected but not replayed (written by hand for a feature the recording runtime did not have)."
1285
+ },
1286
+ info: { $ref: "#/$defs/info" },
1287
+ nowMs: {
1288
+ type: "number",
1289
+ description: "nowMs of the replay request for the conformance check."
1290
+ },
1291
+ events: { type: "array", items: { $ref: "#/$defs/event" } },
1292
+ expected: {
1293
+ type: "object",
1294
+ description: "The replay result the conformance check must reproduce."
1295
+ }
1296
+ },
1297
+ $defs: {
1298
+ ...SHARED_DEFS,
1299
+ ...payloadDefs(),
1300
+ event: RUN_EVENT_RECORD,
1301
+ info: WORKFLOW_TASK_SCHEMA.$defs.info
1302
+ }
1303
+ };
1304
+ var HISTORY_SCHEMA_FILES = [
1305
+ ["run-event.schema.json", RUN_EVENT_SCHEMA],
1306
+ ["workflow-command.schema.json", WORKFLOW_COMMAND_SCHEMA],
1307
+ ["workflow-task.schema.json", WORKFLOW_TASK_SCHEMA],
1308
+ ["history-file.schema.json", HISTORY_FILE_SCHEMA],
1309
+ ["bridge-v2.schema.json", BRIDGE_V2_SCHEMA],
1310
+ ["payload-fields.json", chunkJSC75O5C_cjs.PAYLOAD_FIELDS_DOCUMENT]
1311
+ ];
1312
+ var tools;
1313
+ function schemaTools() {
1314
+ if (!tools) {
1315
+ const ajv = new _2020_js.Ajv2020({ allErrors: true, strict: false });
1316
+ tools = {
1317
+ ajv,
1318
+ command: ajv.compile(WORKFLOW_COMMAND_SCHEMA),
1319
+ event: ajv.compile(RUN_EVENT_SCHEMA),
1320
+ file: ajv.compile(HISTORY_FILE_SCHEMA),
1321
+ bridge: ajv.compile(BRIDGE_V2_SCHEMA)
1322
+ };
1323
+ }
1324
+ return tools;
1325
+ }
1326
+ function issuesOf(index, errors) {
1327
+ const real = (errors ?? []).filter((error) => error.keyword !== "if");
1328
+ return real.map((error) => ({
1329
+ index,
1330
+ code: `schema.${error.keyword}`,
1331
+ message: `${error.instancePath || "/"} ${error.message ?? "is invalid"}`,
1332
+ path: error.instancePath
1333
+ }));
1334
+ }
1335
+ function validateCommand(command2, index = 0) {
1336
+ const { command: validate } = schemaTools();
1337
+ if (validate(command2)) {
1338
+ return { ok: true, command: command2 };
1339
+ }
1340
+ return { ok: false, issues: issuesOf(index, validate.errors) };
1341
+ }
1342
+ function idOf(command2) {
1343
+ switch (command2.type) {
1344
+ case "SCHEDULE_ACTIVITY":
1345
+ return `activity:${command2.activityId}`;
1346
+ case "START_TIMER":
1347
+ return `timer:${command2.timerId}`;
1348
+ case "START_CHILD_RUN":
1349
+ return `child:${command2.childId}`;
1350
+ case "SIGNAL_RUN":
1351
+ case "REQUEST_CANCEL_EXTERNAL_RUN":
1352
+ return `external:${command2.externalId}`;
1353
+ case "RECORD_SIDE_EFFECT":
1354
+ return `sideEffect:${command2.sideEffectId}`;
1355
+ case "RECORD_MARKER":
1356
+ return `marker:${command2.markerId}`;
1357
+ case "RECORD_LOCAL_ACTIVITY":
1358
+ return `local:${command2.localActivityId}`;
1359
+ default:
1360
+ return void 0;
1361
+ }
1362
+ }
1363
+ function validateCommands(commands, options = {}) {
1364
+ const max = options.maxCommands ?? 1e3;
1365
+ if (!Array.isArray(commands))
1366
+ return {
1367
+ ok: false,
1368
+ cause: "INVALID_REQUEST",
1369
+ issues: [{ index: 0, code: "commands.notArray", message: "commands must be an array" }]
1370
+ };
1371
+ if (commands.length > max)
1372
+ return {
1373
+ ok: false,
1374
+ cause: "INVALID_REQUEST",
1375
+ issues: [
1376
+ {
1377
+ index: max,
1378
+ code: "commands.tooMany",
1379
+ message: `A task may return at most ${max} commands; it returned ${commands.length}`
1380
+ }
1381
+ ]
1382
+ };
1383
+ const issues = [];
1384
+ const valid = [];
1385
+ const ids = /* @__PURE__ */ new Set();
1386
+ let unsupported = false;
1387
+ commands.forEach((raw, index) => {
1388
+ const checked = validateCommand(raw, index);
1389
+ if (!checked.ok) {
1390
+ issues.push(...checked.issues);
1391
+ return;
1392
+ }
1393
+ const command2 = checked.command;
1394
+ if (!chunkISOIA7NV_cjs.isWorkflowCommandEnabled(command2, options.enabled) && !(options.relief !== void 0 && chunkISOIA7NV_cjs.isReliefCommand(command2, options.relief))) {
1395
+ unsupported = true;
1396
+ issues.push({
1397
+ index,
1398
+ code: "commands.unsupported",
1399
+ message: chunkISOIA7NV_cjs.unsupportedMessage(command2, options.enabled)
1400
+ });
1401
+ }
1402
+ const id = idOf(command2);
1403
+ if (id !== void 0) {
1404
+ if (ids.has(id))
1405
+ issues.push({ index, code: "commands.duplicateId", message: `${id} is used twice` });
1406
+ ids.add(id);
1407
+ }
1408
+ if (chunkTYF56RGB_cjs.TERMINAL_COMMANDS.has(command2.type) && index !== commands.length - 1)
1409
+ issues.push({
1410
+ index,
1411
+ code: "commands.terminalNotLast",
1412
+ message: `${command2.type} must be the last command of the batch`
1413
+ });
1414
+ if (command2.type === "SCHEDULE_ACTIVITY" && command2.kind === "node" && !chunkA5SXCA62_cjs.isActivityNodeTypeAllowed(command2.nodeType))
1415
+ issues.push({
1416
+ index,
1417
+ code: "durable.activityTypeNotAllowed",
1418
+ message: `${command2.nodeType} cannot run as a durable activity`,
1419
+ path: "/nodeType"
1420
+ });
1421
+ if (command2.type === "SCHEDULE_ACTIVITY" && command2.kind === "user" && command2.headers !== void 0 && chunkISOIA7NV_cjs.utf8Bytes(JSON.stringify(command2.headers)) > chunkTYF56RGB_cjs.MAX_HEADERS_BYTES)
1422
+ issues.push({
1423
+ index,
1424
+ code: "commands.headersTooLarge",
1425
+ message: `The headers of ${command2.type} exceed ${chunkTYF56RGB_cjs.MAX_HEADERS_BYTES} bytes`,
1426
+ path: "/headers"
1427
+ });
1428
+ valid.push(command2);
1429
+ });
1430
+ if (issues.length > 0)
1431
+ return { ok: false, cause: unsupported ? "UNSUPPORTED_COMMAND" : "INVALID_REQUEST", issues };
1432
+ return { ok: true, commands: valid };
1433
+ }
1434
+ function validateHistory(events) {
1435
+ const { event: validate } = schemaTools();
1436
+ if (!Array.isArray(events))
1437
+ return {
1438
+ ok: false,
1439
+ issues: [{ index: 0, code: "history.notArray", message: "history must be an array" }]
1440
+ };
1441
+ const issues = [];
1442
+ events.forEach((event, index) => {
1443
+ if (!validate(event)) {
1444
+ issues.push(...issuesOf(index, validate.errors));
1445
+ return;
1446
+ }
1447
+ if (chunkSAENRNBJ_cjs.isRecord(event) && event["seq"] !== index + 1)
1448
+ issues.push({
1449
+ index,
1450
+ code: "history.seqGap",
1451
+ message: `event ${index + 1} has seq ${String(event["seq"])}`
1452
+ });
1453
+ });
1454
+ return { ok: issues.length === 0, issues };
1455
+ }
1456
+ function validateHistoryFile(value) {
1457
+ const { file: validate } = schemaTools();
1458
+ if (validate(value)) return validateHistory(chunkSAENRNBJ_cjs.isRecord(value) ? value["events"] : void 0);
1459
+ return { ok: false, issues: issuesOf(0, validate.errors) };
1460
+ }
1461
+ function validateBridgeFrame(value) {
1462
+ const { bridge: validate } = schemaTools();
1463
+ if (validate(value)) return { ok: true, frame: value };
1464
+ return { ok: false, issues: issuesOf(0, validate.errors) };
1465
+ }
1466
+ function compilePayloadValidator(schema) {
1467
+ const { ajv } = schemaTools();
1468
+ const validate = ajv.compile(schema);
1469
+ return (value) => {
1470
+ if (validate(value)) return { ok: true };
1471
+ return {
1472
+ ok: false,
1473
+ errors: (validate.errors ?? []).map(
1474
+ (error) => `${error.instancePath || "/"} ${error.message ?? "is invalid"}`
1475
+ )
1476
+ };
1477
+ };
1478
+ }
1479
+
1480
+ // src/history/file.ts
1481
+ var HistoryFileError = class extends Error {
1482
+ constructor(message, issues = []) {
1483
+ super(message);
1484
+ this.issues = issues;
1485
+ this.name = "HistoryFileError";
1486
+ }
1487
+ issues;
1488
+ };
1489
+ function parseHistoryFile(input) {
1490
+ let value = input;
1491
+ if (typeof input === "string") {
1492
+ try {
1493
+ value = JSON.parse(input);
1494
+ } catch (error) {
1495
+ throw new HistoryFileError(
1496
+ `Not JSON: ${error instanceof Error ? error.message : String(error)}`
1497
+ );
1498
+ }
1499
+ }
1500
+ if (!chunkSAENRNBJ_cjs.isRecord(value) || value["format"] !== HISTORY_FILE_FORMAT)
1501
+ throw new HistoryFileError(`Not a ${HISTORY_FILE_FORMAT} document`);
1502
+ const checked = validateHistoryFile(value);
1503
+ if (!checked.ok)
1504
+ throw new HistoryFileError(
1505
+ "The history file does not match history-file.schema.json",
1506
+ checked.issues.map((issue) => `#${issue.index}: ${issue.message}`)
1507
+ );
1508
+ return value;
1509
+ }
1510
+ function createHistoryFile(workflowFn, events, extra = {}) {
1511
+ return {
1512
+ format: HISTORY_FILE_FORMAT,
1513
+ formatVersion: chunkTYF56RGB_cjs.HISTORY_PROTOCOL,
1514
+ ...extra,
1515
+ workflowFn,
1516
+ events
1517
+ };
1518
+ }
1519
+ function serializeHistoryFile(file) {
1520
+ return `${JSON.stringify(file, null, 2)}
1521
+ `;
1522
+ }
1523
+
1524
+ exports.BRIDGE_IDLE_TIMEOUT_MS = BRIDGE_IDLE_TIMEOUT_MS;
1525
+ exports.BRIDGE_MAX_FRAME_BYTES = BRIDGE_MAX_FRAME_BYTES;
1526
+ exports.BRIDGE_MAX_HISTORY_TAIL_BYTES = BRIDGE_MAX_HISTORY_TAIL_BYTES;
1527
+ exports.BRIDGE_PATH = BRIDGE_PATH;
1528
+ exports.BRIDGE_PING_SECONDS = BRIDGE_PING_SECONDS;
1529
+ exports.BRIDGE_PROTOCOL_VERSION = BRIDGE_PROTOCOL_VERSION;
1530
+ exports.BRIDGE_REQUEST_METHODS = BRIDGE_REQUEST_METHODS;
1531
+ exports.BRIDGE_V2_SCHEMA = BRIDGE_V2_SCHEMA;
1532
+ exports.BRIDGE_V2_SCHEMA_ID = BRIDGE_V2_SCHEMA_ID;
1533
+ exports.BRIDGE_WORKER_HEARTBEAT_SECONDS = BRIDGE_WORKER_HEARTBEAT_SECONDS;
1534
+ exports.BridgeCloseCode = BridgeCloseCode;
1535
+ exports.HISTORY_FILE_FORMAT = HISTORY_FILE_FORMAT;
1536
+ exports.HISTORY_FILE_SCHEMA = HISTORY_FILE_SCHEMA;
1537
+ exports.HISTORY_FILE_SCHEMA_ID = HISTORY_FILE_SCHEMA_ID;
1538
+ exports.HISTORY_SCHEMA_FILES = HISTORY_SCHEMA_FILES;
1539
+ exports.HistoryFileError = HistoryFileError;
1540
+ exports.RUN_EVENT_SCHEMA = RUN_EVENT_SCHEMA;
1541
+ exports.RUN_EVENT_SCHEMA_ID = RUN_EVENT_SCHEMA_ID;
1542
+ exports.WORKFLOW_COMMAND_SCHEMA = WORKFLOW_COMMAND_SCHEMA;
1543
+ exports.WORKFLOW_COMMAND_SCHEMA_ID = WORKFLOW_COMMAND_SCHEMA_ID;
1544
+ exports.WORKFLOW_TASK_SCHEMA = WORKFLOW_TASK_SCHEMA;
1545
+ exports.WORKFLOW_TASK_SCHEMA_ID = WORKFLOW_TASK_SCHEMA_ID;
1546
+ exports.compilePayloadValidator = compilePayloadValidator;
1547
+ exports.createHistoryFile = createHistoryFile;
1548
+ exports.parseHistoryFile = parseHistoryFile;
1549
+ exports.serializeHistoryFile = serializeHistoryFile;
1550
+ exports.validateBridgeFrame = validateBridgeFrame;
1551
+ exports.validateCommand = validateCommand;
1552
+ exports.validateCommands = validateCommands;
1553
+ exports.validateHistory = validateHistory;
1554
+ exports.validateHistoryFile = validateHistoryFile;