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