rivetkit 0.0.0-active-actors-fix-active-count.253e406 → 0.0.0-bisect-sync-sqlite-1.910d1c7
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/dist/browser/client.d.ts +1286 -89
- package/dist/browser/client.js +1699 -704
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2083 -236
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +8 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +7 -1
- package/dist/tsup/agent-os/index.cjs +3 -2289
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -1813
- package/dist/tsup/agent-os/index.d.ts +1 -1813
- package/dist/tsup/agent-os/index.js +3 -2289
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/chunk-2JJU7IQ7.cjs +14 -0
- package/dist/tsup/chunk-2JJU7IQ7.cjs.map +1 -0
- package/dist/tsup/{chunk-DZJZLZ4R.js → chunk-2MXBZGUP.js} +2 -2
- package/dist/tsup/{chunk-L4FVS7GY.js → chunk-47IS5ZFI.js} +6 -6
- package/dist/tsup/chunk-47IS5ZFI.js.map +1 -0
- package/dist/tsup/{chunk-DXWOGCZY.js → chunk-5XWY5CBA.js} +70 -8
- package/dist/tsup/chunk-5XWY5CBA.js.map +1 -0
- package/dist/tsup/{chunk-OQEEZDIK.cjs → chunk-6XVNZKKP.cjs} +506 -31
- package/dist/tsup/chunk-6XVNZKKP.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-A2CF6PFH.js} +20 -12
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-AQJFKHBK.cjs} +276 -27
- package/dist/tsup/chunk-AQJFKHBK.cjs.map +1 -0
- package/dist/tsup/chunk-DPWLASMC.cjs +244 -0
- package/dist/tsup/chunk-DPWLASMC.cjs.map +1 -0
- package/dist/tsup/{chunk-VUF2YEF4.cjs → chunk-DYJOU3MF.cjs} +10 -10
- package/dist/tsup/chunk-DYJOU3MF.cjs.map +1 -0
- package/dist/tsup/{chunk-7WXCRV25.cjs → chunk-ELZ6MT3V.cjs} +18 -11
- package/dist/tsup/chunk-ELZ6MT3V.cjs.map +1 -0
- package/dist/tsup/chunk-HYIVSH5X.js +244 -0
- package/dist/tsup/chunk-HYIVSH5X.js.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-IHEO5OT3.js} +275 -26
- package/dist/tsup/chunk-IHEO5OT3.js.map +1 -0
- package/dist/tsup/chunk-IWACVNN5.js +14 -0
- package/dist/tsup/chunk-IWACVNN5.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-V4JUWAT6.js → chunk-K3AJOPSF.js} +498 -23
- package/dist/tsup/chunk-K3AJOPSF.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-MGI2VVF6.cjs} +45 -9
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-QNLGOTQP.js → chunk-NPHTIUUJ.js} +1291 -420
- package/dist/tsup/chunk-NPHTIUUJ.js.map +1 -0
- package/dist/tsup/{chunk-7GKQJFSB.cjs → chunk-POCSZXPQ.cjs} +72 -10
- package/dist/tsup/chunk-POCSZXPQ.cjs.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-RTWH3AX3.cjs} +19 -11
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-ARRBQTAR.cjs → chunk-X76BM5JS.cjs} +1420 -549
- package/dist/tsup/chunk-X76BM5JS.cjs.map +1 -0
- package/dist/tsup/{chunk-AGBP757I.js → chunk-X7SYKFPM.js} +16 -9
- package/dist/tsup/chunk-X7SYKFPM.js.map +1 -0
- package/dist/tsup/{chunk-GKAMEBTZ.cjs → chunk-XLDJSZ3B.cjs} +3 -3
- package/dist/tsup/{chunk-GKAMEBTZ.cjs.map → chunk-XLDJSZ3B.cjs.map} +1 -1
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZOVJDAOW.js} +44 -8
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +33 -7
- package/dist/tsup/client/mod.d.ts +33 -7
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-nlTlOKaE.d.cts → config-BMGUEKMZ.d.cts} +1252 -75
- package/dist/tsup/config-CBTr4IhE.d.cts +224 -0
- package/dist/tsup/config-CBTr4IhE.d.ts +224 -0
- package/dist/tsup/{config-D7ykAntK.d.ts → config-iBpXyITj.d.ts} +1252 -75
- package/dist/tsup/context-hyVakgnU.d.ts +136 -0
- package/dist/tsup/context-qfvLuF0P.d.cts +136 -0
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -124
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -123
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +39 -0
- package/dist/tsup/dynamic/mod.d.ts +39 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +242 -0
- package/dist/tsup/inspector-tab/mod.d.ts +242 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +3527 -753
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +11 -7
- package/dist/tsup/mod.d.ts +11 -7
- package/dist/tsup/mod.js +3468 -694
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -5
- package/dist/tsup/test/mod.d.ts +7 -5
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/{utils-DVekpm4I.d.ts → utils-3rsE0JvI.d.cts} +26 -2
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-3rsE0JvI.d.ts} +26 -2
- package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
- package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +557 -410
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -9
- package/dist/tsup/workflow/mod.d.ts +11 -9
- package/dist/tsup/workflow/mod.js +551 -404
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +67 -18
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +679 -101
- package/src/actor/contexts/index.ts +9 -2
- package/src/actor/definition.ts +75 -26
- package/src/actor/errors.ts +107 -8
- package/src/actor/keys.ts +87 -1
- package/src/actor/mod.ts +36 -20
- package/src/actor/schema.ts +6 -2
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -64
- package/src/client/actor-common.ts +84 -54
- package/src/client/actor-conn.ts +231 -68
- package/src/client/actor-handle.ts +283 -89
- package/src/client/actor-query.ts +13 -6
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +182 -21
- package/src/client/config.ts +28 -3
- package/src/client/errors.ts +15 -2
- package/src/client/lifecycle-errors.ts +63 -5
- package/src/client/mod.ts +10 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +13 -3
- package/src/client/raw-utils.ts +59 -14
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/retry-budget.ts +81 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +22 -9
- package/src/common/actor-router-consts.ts +6 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +175 -9
- package/src/common/database/mod.ts +262 -77
- package/src/common/database/native-database.ts +442 -20
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +278 -34
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +15 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +14 -18
- package/src/common/utils.ts +8 -169
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +5 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-api/actors.ts +15 -3
- package/src/engine-client/actor-http-client.ts +37 -22
- package/src/engine-client/actor-websocket-client.ts +37 -9
- package/src/engine-client/api-endpoints.ts +128 -5
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -16
- package/src/engine-client/mod.ts +280 -111
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +3 -20
- package/src/registry/config/index.ts +91 -74
- package/src/registry/index.ts +702 -80
- package/src/registry/napi-runtime.ts +643 -42
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +1881 -582
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +441 -7
- package/src/registry/wasm-runtime.ts +516 -23
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +50 -2
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +703 -242
- package/src/workflow/driver.ts +284 -125
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-6NT2LIFN.cjs +0 -268
- package/dist/tsup/chunk-6NT2LIFN.cjs.map +0 -1
- package/dist/tsup/chunk-7GKQJFSB.cjs.map +0 -1
- package/dist/tsup/chunk-7WXCRV25.cjs.map +0 -1
- package/dist/tsup/chunk-AGBP757I.js.map +0 -1
- package/dist/tsup/chunk-ARRBQTAR.cjs.map +0 -1
- package/dist/tsup/chunk-DXWOGCZY.js.map +0 -1
- package/dist/tsup/chunk-JGIPV3QU.js +0 -268
- package/dist/tsup/chunk-JGIPV3QU.js.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-L4FVS7GY.js.map +0 -1
- package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
- package/dist/tsup/chunk-OQEEZDIK.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
- package/dist/tsup/chunk-QNLGOTQP.js.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-V4JUWAT6.js.map +0 -1
- package/dist/tsup/chunk-VUF2YEF4.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/config-CxjGYf4K.d.cts +0 -121
- package/dist/tsup/config-CxjGYf4K.d.ts +0 -121
- package/dist/tsup/context-88opQsfZ.d.cts +0 -92
- package/dist/tsup/context-CVEG5zfg.d.ts +0 -92
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2492
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -265
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -191
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/common/database/mod.test.ts +0 -137
- package/src/common/database/native-database.test.ts +0 -211
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/drivers/engine/actor-driver.ts +0 -2460
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils/serve.ts +0 -217
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-DZJZLZ4R.js.map → chunk-2MXBZGUP.js.map} +0 -0
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkELZ6MT3Vcjs = require('../chunk-ELZ6MT3V.cjs');
|
|
4
|
+
require('../chunk-2JJU7IQ7.cjs');
|
|
5
|
+
require('../chunk-POCSZXPQ.cjs');
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
var
|
|
8
|
-
require('../chunk-7GKQJFSB.cjs');
|
|
9
|
+
var _chunkAQJFKHBKcjs = require('../chunk-AQJFKHBK.cjs');
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
var
|
|
13
|
-
require('../chunk-6NT2LIFN.cjs');
|
|
13
|
+
var _chunkRTWH3AX3cjs = require('../chunk-RTWH3AX3.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunk6XVNZKKPcjs = require('../chunk-6XVNZKKP.cjs');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
var _chunkMGI2VVF6cjs = require('../chunk-MGI2VVF6.cjs');
|
|
20
21
|
|
|
21
22
|
// src/workflow/mod.ts
|
|
22
23
|
|
|
@@ -33,279 +34,109 @@ var _chunkQAZLM4WTcjs = require('../chunk-QAZLM4WT.cjs');
|
|
|
33
34
|
var _workflowengine = require('@rivetkit/workflow-engine');
|
|
34
35
|
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
35
36
|
|
|
36
|
-
// src/workflow/
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const upperBound = prefix.slice();
|
|
43
|
-
for (let i = upperBound.length - 1; i >= 0; i--) {
|
|
44
|
-
if (upperBound[i] !== 255) {
|
|
45
|
-
upperBound[i]++;
|
|
46
|
-
return upperBound.slice(0, i + 1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
var ActorWorkflowMessageDriver = class {
|
|
52
|
-
#actor;
|
|
53
|
-
#runCtx;
|
|
54
|
-
constructor(actor, runCtx) {
|
|
55
|
-
this.#actor = actor;
|
|
56
|
-
this.#runCtx = runCtx;
|
|
57
|
-
}
|
|
58
|
-
async addMessage(message) {
|
|
59
|
-
await this.#runCtx.internalKeepAwake(
|
|
60
|
-
this.#actor.queueManager.enqueue(message.name, message.data)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
async receiveMessages(opts) {
|
|
64
|
-
const messages = await this.#runCtx.internalKeepAwake(
|
|
65
|
-
this.#actor.queueManager.receive(
|
|
66
|
-
opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
|
|
67
|
-
opts.count,
|
|
68
|
-
0,
|
|
69
|
-
void 0,
|
|
70
|
-
opts.completable
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
return messages.map((message) => ({
|
|
74
|
-
id: message.id.toString(),
|
|
75
|
-
name: message.name,
|
|
76
|
-
data: message.body,
|
|
77
|
-
sentAt: message.createdAt,
|
|
78
|
-
...opts.completable ? {
|
|
79
|
-
complete: async (response) => {
|
|
80
|
-
await this.#runCtx.internalKeepAwake(
|
|
81
|
-
this.#actor.queueManager.completeMessage(
|
|
82
|
-
message,
|
|
83
|
-
response
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
} : {}
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
async completeMessage(messageId, response) {
|
|
91
|
-
let parsedId;
|
|
92
|
-
try {
|
|
93
|
-
parsedId = BigInt(messageId);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
await this.#runCtx.internalKeepAwake(
|
|
98
|
-
this.#actor.queueManager.completeMessageById(parsedId, response)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var ActorWorkflowDriver = (_class = class {
|
|
103
|
-
__init() {this.workerPollInterval = 100}
|
|
104
|
-
|
|
105
|
-
#actor;
|
|
37
|
+
// src/workflow/constants.ts
|
|
38
|
+
var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
|
39
|
+
|
|
40
|
+
// src/workflow/context.ts
|
|
41
|
+
var DEACTIVATE_STEP = /* @__PURE__ */ Symbol("workflow.step.deactivate");
|
|
42
|
+
var WorkflowStepContext = class {
|
|
106
43
|
#runCtx;
|
|
107
|
-
|
|
108
|
-
|
|
44
|
+
#active = true;
|
|
45
|
+
#onGuardViolation;
|
|
46
|
+
constructor(runCtx, onGuardViolation) {
|
|
109
47
|
this.#runCtx = runCtx;
|
|
110
|
-
this
|
|
111
|
-
}
|
|
112
|
-
async get(key) {
|
|
113
|
-
const [value] = await this.#runCtx.internalKeepAwake(
|
|
114
|
-
this.#actor.driver.kvBatchGet(this.#actor.id, [
|
|
115
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
|
|
116
|
-
])
|
|
117
|
-
);
|
|
118
|
-
return _nullishCoalesce(value, () => ( null));
|
|
48
|
+
this.#onGuardViolation = onGuardViolation;
|
|
119
49
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.#actor.driver.kvBatchPut(this.#actor.id, [
|
|
123
|
-
[_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key), value]
|
|
124
|
-
])
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
async delete(key) {
|
|
128
|
-
await this.#runCtx.internalKeepAwake(
|
|
129
|
-
this.#actor.driver.kvBatchDelete(this.#actor.id, [
|
|
130
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
|
|
131
|
-
])
|
|
132
|
-
);
|
|
50
|
+
[DEACTIVATE_STEP]() {
|
|
51
|
+
this.#active = false;
|
|
133
52
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.#actor.driver.kvDeleteRange(this.#actor.id, start, end)
|
|
140
|
-
);
|
|
141
|
-
} else {
|
|
142
|
-
const entries = await this.#runCtx.internalKeepAwake(
|
|
143
|
-
this.#actor.driver.kvListPrefix(this.#actor.id, start)
|
|
144
|
-
);
|
|
145
|
-
if (entries.length === 0) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
await this.#runCtx.internalKeepAwake(
|
|
149
|
-
this.#actor.driver.kvBatchDelete(
|
|
150
|
-
this.#actor.id,
|
|
151
|
-
entries.map(([key]) => key)
|
|
152
|
-
)
|
|
53
|
+
#ensureActive(feature) {
|
|
54
|
+
if (!this.#active) {
|
|
55
|
+
this.#onGuardViolation();
|
|
56
|
+
throw new Error(
|
|
57
|
+
`${feature} is only available inside workflow steps`
|
|
153
58
|
);
|
|
154
59
|
}
|
|
155
60
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.#actor.driver.kvDeleteRange(
|
|
159
|
-
this.#actor.id,
|
|
160
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, start),
|
|
161
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, end)
|
|
162
|
-
)
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
async list(prefix) {
|
|
166
|
-
const entries = await this.#runCtx.internalKeepAwake(
|
|
167
|
-
this.#actor.driver.kvListPrefix(
|
|
168
|
-
this.#actor.id,
|
|
169
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, prefix)
|
|
170
|
-
)
|
|
171
|
-
);
|
|
172
|
-
return entries.map(([key, value]) => ({
|
|
173
|
-
key: stripWorkflowKey(key),
|
|
174
|
-
value
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
async batch(writes) {
|
|
178
|
-
if (writes.length === 0) return;
|
|
179
|
-
await this.#runCtx.internalKeepAwake(
|
|
180
|
-
Promise.all([
|
|
181
|
-
this.#actor.driver.kvBatchPut(
|
|
182
|
-
this.#actor.id,
|
|
183
|
-
writes.map(({ key, value }) => [
|
|
184
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key),
|
|
185
|
-
value
|
|
186
|
-
])
|
|
187
|
-
),
|
|
188
|
-
this.#actor.stateManager.saveState({
|
|
189
|
-
immediate: true
|
|
190
|
-
})
|
|
191
|
-
])
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
async setAlarm(_workflowId, wakeAt) {
|
|
195
|
-
await this.#runCtx.internalKeepAwake(
|
|
196
|
-
this.#actor.driver.setAlarm(this.#actor, wakeAt)
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
async clearAlarm(_workflowId) {
|
|
200
|
-
return;
|
|
61
|
+
get actorId() {
|
|
62
|
+
return this.#runCtx.actorId;
|
|
201
63
|
}
|
|
202
|
-
|
|
203
|
-
return this.#
|
|
204
|
-
messageNames.length > 0 ? messageNames : void 0,
|
|
205
|
-
abortSignal
|
|
206
|
-
);
|
|
64
|
+
get name() {
|
|
65
|
+
return this.#runCtx.name;
|
|
207
66
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
async addMessage(_message) {
|
|
211
|
-
throw new Error("Workflow control driver does not support messages");
|
|
67
|
+
get key() {
|
|
68
|
+
return this.#runCtx.key;
|
|
212
69
|
}
|
|
213
|
-
|
|
214
|
-
|
|
70
|
+
get forkChain() {
|
|
71
|
+
return this.#runCtx.forkChain;
|
|
215
72
|
}
|
|
216
|
-
|
|
217
|
-
|
|
73
|
+
get namespace() {
|
|
74
|
+
return this.#runCtx.namespace;
|
|
218
75
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
__init2() {this.workerPollInterval = 100}
|
|
222
|
-
__init3() {this.messageDriver = new NoopWorkflowMessageDriver()}
|
|
223
|
-
#actor;
|
|
224
|
-
constructor(actor) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
|
|
225
|
-
this.#actor = actor;
|
|
76
|
+
get log() {
|
|
77
|
+
return this.#runCtx.log;
|
|
226
78
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
|
|
230
|
-
]);
|
|
231
|
-
return _nullishCoalesce(value, () => ( null));
|
|
79
|
+
get abortSignal() {
|
|
80
|
+
return this.#runCtx.abortSignal;
|
|
232
81
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
82
|
+
/** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state */
|
|
83
|
+
get state() {
|
|
84
|
+
this.#ensureActive("state");
|
|
85
|
+
return this.#runCtx.state;
|
|
237
86
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
]);
|
|
87
|
+
get vars() {
|
|
88
|
+
this.#ensureActive("vars");
|
|
89
|
+
return this.#runCtx.vars;
|
|
242
90
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (end) {
|
|
247
|
-
await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const entries = await this.#actor.driver.kvListPrefix(
|
|
251
|
-
this.#actor.id,
|
|
252
|
-
start
|
|
253
|
-
);
|
|
254
|
-
if (entries.length === 0) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
await this.#actor.driver.kvBatchDelete(
|
|
258
|
-
this.#actor.id,
|
|
259
|
-
entries.map(([key]) => key)
|
|
260
|
-
);
|
|
91
|
+
get db() {
|
|
92
|
+
this.#ensureActive("db");
|
|
93
|
+
return this.#runCtx.db;
|
|
261
94
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, start),
|
|
266
|
-
_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, end)
|
|
267
|
-
);
|
|
95
|
+
client() {
|
|
96
|
+
this.#ensureActive("client");
|
|
97
|
+
return this.#runCtx.client();
|
|
268
98
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
99
|
+
broadcast(name, ...args) {
|
|
100
|
+
this.#ensureActive("broadcast");
|
|
101
|
+
this.#runCtx.broadcast(
|
|
102
|
+
name,
|
|
103
|
+
...args
|
|
273
104
|
);
|
|
274
|
-
return entries.map(([key, value]) => ({
|
|
275
|
-
key: stripWorkflowKey(key),
|
|
276
|
-
value
|
|
277
|
-
}));
|
|
278
105
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
106
|
+
/** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
|
|
107
|
+
get queue() {
|
|
108
|
+
const self = this;
|
|
109
|
+
async function send(name, body) {
|
|
110
|
+
self.#ensureActive("queue.send");
|
|
111
|
+
await self.#runCtx.queue.send(name, body);
|
|
282
112
|
}
|
|
283
|
-
|
|
284
|
-
this.#actor.id,
|
|
285
|
-
writes.map(({ key, value }) => [_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key), value])
|
|
286
|
-
);
|
|
113
|
+
return { send };
|
|
287
114
|
}
|
|
288
|
-
|
|
289
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Holds the actor awake for the duration of the provided promise. The actor
|
|
117
|
+
* cannot idle-sleep or finalize the sleep grace period until the promise
|
|
118
|
+
* settles.
|
|
119
|
+
*/
|
|
120
|
+
keepAwake(promise) {
|
|
121
|
+
this.#ensureActive("keepAwake");
|
|
122
|
+
return this.#runCtx.keepAwake(promise);
|
|
290
123
|
}
|
|
291
|
-
|
|
292
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Registers a promise that the sleep grace period will wait on. Use this for
|
|
126
|
+
* best-effort flush/cleanup work that may complete inside the grace window.
|
|
127
|
+
*/
|
|
128
|
+
waitUntil(promise) {
|
|
129
|
+
this.#ensureActive("waitUntil");
|
|
130
|
+
this.#runCtx.waitUntil(promise);
|
|
293
131
|
}
|
|
294
|
-
|
|
295
|
-
|
|
132
|
+
destroy() {
|
|
133
|
+
this.#ensureActive("destroy");
|
|
134
|
+
this.#runCtx.destroy();
|
|
296
135
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// src/workflow/constants.ts
|
|
300
|
-
var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
|
301
|
-
|
|
302
|
-
// src/workflow/context.ts
|
|
303
|
-
var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
136
|
+
};
|
|
137
|
+
var WorkflowContext = class _WorkflowContext {
|
|
304
138
|
#inner;
|
|
305
139
|
#runCtx;
|
|
306
|
-
#actorAccessDepth = 0;
|
|
307
|
-
#allowActorAccess = false;
|
|
308
|
-
#guardViolation = false;
|
|
309
140
|
constructor(inner, runCtx) {
|
|
310
141
|
this.#inner = inner;
|
|
311
142
|
this.#runCtx = runCtx;
|
|
@@ -316,6 +147,25 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
316
147
|
get abortSignal() {
|
|
317
148
|
return this.#inner.abortSignal;
|
|
318
149
|
}
|
|
150
|
+
get actorId() {
|
|
151
|
+
return this.#runCtx.actorId;
|
|
152
|
+
}
|
|
153
|
+
get name() {
|
|
154
|
+
return this.#runCtx.name;
|
|
155
|
+
}
|
|
156
|
+
get key() {
|
|
157
|
+
return this.#runCtx.key;
|
|
158
|
+
}
|
|
159
|
+
get forkChain() {
|
|
160
|
+
return this.#runCtx.forkChain;
|
|
161
|
+
}
|
|
162
|
+
get namespace() {
|
|
163
|
+
return this.#runCtx.namespace;
|
|
164
|
+
}
|
|
165
|
+
get log() {
|
|
166
|
+
return this.#runCtx.log;
|
|
167
|
+
}
|
|
168
|
+
/** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
|
|
319
169
|
get queue() {
|
|
320
170
|
const self = this;
|
|
321
171
|
async function next(name, opts) {
|
|
@@ -328,14 +178,9 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
328
178
|
(message) => self.#toActorQueueMessage(message)
|
|
329
179
|
);
|
|
330
180
|
}
|
|
331
|
-
async function send(name, body) {
|
|
332
|
-
self.#ensureActorAccess("queue.send");
|
|
333
|
-
await self.#runCtx.queue.send(name, body);
|
|
334
|
-
}
|
|
335
181
|
return {
|
|
336
182
|
next,
|
|
337
|
-
nextBatch
|
|
338
|
-
send
|
|
183
|
+
nextBatch
|
|
339
184
|
};
|
|
340
185
|
}
|
|
341
186
|
async step(nameOrConfig, run) {
|
|
@@ -343,17 +188,17 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
343
188
|
if (!run) {
|
|
344
189
|
throw new Error("Step run function missing");
|
|
345
190
|
}
|
|
191
|
+
const stepRun = run;
|
|
346
192
|
return await this.#wrapActive(
|
|
347
|
-
() => this.#inner.step(
|
|
348
|
-
nameOrConfig,
|
|
349
|
-
() => this.#withActorAccess(run)
|
|
350
|
-
)
|
|
193
|
+
() => this.#inner.step(nameOrConfig, () => this.#runStep(stepRun))
|
|
351
194
|
);
|
|
352
195
|
}
|
|
353
196
|
const stepConfig = nameOrConfig;
|
|
197
|
+
const rollback = stepConfig.rollback;
|
|
354
198
|
const config = {
|
|
355
199
|
...stepConfig,
|
|
356
|
-
run: () => this.#
|
|
200
|
+
run: () => this.#runStep(stepConfig.run),
|
|
201
|
+
rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
|
|
357
202
|
};
|
|
358
203
|
return await this.#wrapActive(() => this.#inner.step(config));
|
|
359
204
|
}
|
|
@@ -362,17 +207,17 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
362
207
|
if (!run) {
|
|
363
208
|
throw new Error("Step run function missing");
|
|
364
209
|
}
|
|
210
|
+
const stepRun = run;
|
|
365
211
|
return await this.#wrapActive(
|
|
366
|
-
() => this.#inner.tryStep(
|
|
367
|
-
nameOrConfig,
|
|
368
|
-
() => this.#withActorAccess(run)
|
|
369
|
-
)
|
|
212
|
+
() => this.#inner.tryStep(nameOrConfig, () => this.#runStep(stepRun))
|
|
370
213
|
);
|
|
371
214
|
}
|
|
372
215
|
const stepConfig = nameOrConfig;
|
|
216
|
+
const rollback = stepConfig.rollback;
|
|
373
217
|
const config = {
|
|
374
218
|
...stepConfig,
|
|
375
|
-
run: () => this.#
|
|
219
|
+
run: () => this.#runStep(stepConfig.run),
|
|
220
|
+
rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
|
|
376
221
|
};
|
|
377
222
|
return await this.#wrapActive(() => this.#inner.tryStep(config));
|
|
378
223
|
}
|
|
@@ -381,10 +226,11 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
381
226
|
if (!run) {
|
|
382
227
|
throw new Error("Try run function missing");
|
|
383
228
|
}
|
|
229
|
+
const tryRun = run;
|
|
384
230
|
return await this.#wrapActive(
|
|
385
231
|
() => this.#inner.try(
|
|
386
232
|
nameOrConfig,
|
|
387
|
-
async (ctx) =>
|
|
233
|
+
async (ctx) => tryRun(this.#createChildContext(ctx))
|
|
388
234
|
)
|
|
389
235
|
);
|
|
390
236
|
}
|
|
@@ -400,16 +246,20 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
400
246
|
if (!run) {
|
|
401
247
|
throw new Error("Loop run function missing");
|
|
402
248
|
}
|
|
249
|
+
const loopRun = run;
|
|
403
250
|
return await this.#wrapActive(
|
|
404
251
|
() => this.#inner.loop(
|
|
405
252
|
nameOrConfig,
|
|
406
|
-
|
|
253
|
+
// A void return (no explicit Loop result) is undefined at
|
|
254
|
+
// runtime, which the engine treats as continue.
|
|
255
|
+
async (ctx) => await _asyncNullishCoalesce(await loopRun(this.#createChildContext(ctx)), async () => ( void 0))
|
|
407
256
|
)
|
|
408
257
|
);
|
|
409
258
|
}
|
|
259
|
+
const loopConfig = nameOrConfig;
|
|
410
260
|
const wrapped = {
|
|
411
|
-
...
|
|
412
|
-
run: async (ctx, state) =>
|
|
261
|
+
...loopConfig,
|
|
262
|
+
run: (async (ctx, state) => await _asyncNullishCoalesce(await loopConfig.run(this.#createChildContext(ctx), state), async () => ( void 0)))
|
|
413
263
|
};
|
|
414
264
|
return await this.#wrapActive(() => this.#inner.loop(wrapped));
|
|
415
265
|
}
|
|
@@ -419,10 +269,6 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
419
269
|
sleepUntil(name, timestampMs) {
|
|
420
270
|
return this.#inner.sleepUntil(name, timestampMs);
|
|
421
271
|
}
|
|
422
|
-
destroy() {
|
|
423
|
-
this.#ensureActorAccess("destroy");
|
|
424
|
-
this.#runCtx.destroy();
|
|
425
|
-
}
|
|
426
272
|
async rollbackCheckpoint(name) {
|
|
427
273
|
await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
|
|
428
274
|
}
|
|
@@ -451,71 +297,28 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
451
297
|
async removed(name, originalType) {
|
|
452
298
|
await this.#wrapActive(() => this.#inner.removed(name, originalType));
|
|
453
299
|
}
|
|
300
|
+
getVersion(name, latest) {
|
|
301
|
+
return this.#wrapActive(() => this.#inner.getVersion(name, latest));
|
|
302
|
+
}
|
|
454
303
|
isEvicted() {
|
|
455
304
|
return this.#inner.isEvicted();
|
|
456
305
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return this.#runCtx.client();
|
|
468
|
-
}
|
|
469
|
-
get db() {
|
|
470
|
-
this.#ensureActorAccess("db");
|
|
471
|
-
return this.#runCtx.db;
|
|
472
|
-
}
|
|
473
|
-
get log() {
|
|
474
|
-
return this.#runCtx.log;
|
|
475
|
-
}
|
|
476
|
-
/** @deprecated No-op. Use `keepAwake(promise)` or `waitUntil(promise)` instead. */
|
|
477
|
-
setPreventSleep(_prevent) {
|
|
478
|
-
this.#ensureActorAccess("setPreventSleep");
|
|
479
|
-
}
|
|
480
|
-
/** @deprecated No-op. Always returns `false`. */
|
|
481
|
-
get preventSleep() {
|
|
482
|
-
this.#ensureActorAccess("preventSleep");
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Holds the actor awake for the duration of the provided promise. The
|
|
487
|
-
* actor cannot idle-sleep or finalize the sleep grace period until the
|
|
488
|
-
* promise settles.
|
|
489
|
-
*/
|
|
490
|
-
keepAwake(promise) {
|
|
491
|
-
this.#ensureActorAccess("keepAwake");
|
|
492
|
-
return this.#runCtx.keepAwake(promise);
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Registers a promise that the sleep grace period will wait on. Use this
|
|
496
|
-
* for best-effort flush/cleanup work that may complete inside the grace
|
|
497
|
-
* window. For work the actor must stay running through, prefer
|
|
498
|
-
* `c.keepAwake(promise)` which also blocks idle sleep.
|
|
499
|
-
*/
|
|
500
|
-
waitUntil(promise) {
|
|
501
|
-
this.#ensureActorAccess("waitUntil");
|
|
502
|
-
this.#runCtx.waitUntil(promise);
|
|
503
|
-
}
|
|
504
|
-
get actorId() {
|
|
505
|
-
return this.#runCtx.actorId;
|
|
506
|
-
}
|
|
507
|
-
broadcast(name, ...args) {
|
|
508
|
-
this.#ensureActorAccess("broadcast");
|
|
509
|
-
this.#runCtx.broadcast(
|
|
510
|
-
name,
|
|
511
|
-
...args
|
|
512
|
-
);
|
|
306
|
+
// Runs a user step body inside a fresh step context and deactivates the step
|
|
307
|
+
// context once the body settles. Workflows are roll-forward only, so state and
|
|
308
|
+
// vars mutations made before a failure always remain visible.
|
|
309
|
+
async #runStep(run) {
|
|
310
|
+
const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
|
|
311
|
+
try {
|
|
312
|
+
return await run(stepCtx);
|
|
313
|
+
} finally {
|
|
314
|
+
stepCtx[DEACTIVATE_STEP]();
|
|
315
|
+
}
|
|
513
316
|
}
|
|
514
317
|
#toActorQueueMessage(message) {
|
|
515
318
|
let id;
|
|
516
319
|
try {
|
|
517
320
|
id = BigInt(message.id);
|
|
518
|
-
} catch (
|
|
321
|
+
} catch (e) {
|
|
519
322
|
throw new Error(`Invalid queue message id "${message.id}"`);
|
|
520
323
|
}
|
|
521
324
|
return {
|
|
@@ -526,44 +329,27 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
526
329
|
...message.complete ? { complete: message.complete } : {}
|
|
527
330
|
};
|
|
528
331
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
async #withActorAccess(run) {
|
|
533
|
-
this.#actorAccessDepth++;
|
|
534
|
-
if (this.#actorAccessDepth === 1) {
|
|
535
|
-
this.#allowActorAccess = true;
|
|
536
|
-
}
|
|
332
|
+
// Runs a step rollback compensation with an active step context.
|
|
333
|
+
async #runRollback(rollback, output) {
|
|
334
|
+
const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
|
|
537
335
|
try {
|
|
538
|
-
|
|
336
|
+
await rollback(stepCtx, output);
|
|
539
337
|
} finally {
|
|
540
|
-
|
|
541
|
-
if (this.#actorAccessDepth === 0) {
|
|
542
|
-
this.#allowActorAccess = false;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
#ensureActorAccess(feature) {
|
|
547
|
-
if (!this.#allowActorAccess) {
|
|
548
|
-
this.#guardViolation = true;
|
|
549
|
-
this.#markGuardTriggered();
|
|
550
|
-
throw new Error(
|
|
551
|
-
`${feature} is only available inside workflow steps`
|
|
552
|
-
);
|
|
338
|
+
stepCtx[DEACTIVATE_STEP]();
|
|
553
339
|
}
|
|
554
340
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
this.#guardViolation = false;
|
|
558
|
-
return violated;
|
|
341
|
+
async #wrapActive(run) {
|
|
342
|
+
return await this.#runCtx.internalKeepAwake(run);
|
|
559
343
|
}
|
|
344
|
+
// Records that a step context was used outside its step. Mirrors the value
|
|
345
|
+
// onto actor state and a KV flag so callers can observe the violation.
|
|
560
346
|
#markGuardTriggered() {
|
|
561
347
|
try {
|
|
562
348
|
const state = this.#runCtx.state;
|
|
563
349
|
if (state && typeof state === "object" && "guardTriggered" in state) {
|
|
564
350
|
state.guardTriggered = true;
|
|
565
351
|
}
|
|
566
|
-
} catch (
|
|
352
|
+
} catch (e2) {
|
|
567
353
|
}
|
|
568
354
|
this.#runCtx.waitUntil(
|
|
569
355
|
(async () => {
|
|
@@ -579,10 +365,376 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
|
579
365
|
);
|
|
580
366
|
}
|
|
581
367
|
#createChildContext(ctx) {
|
|
582
|
-
return new
|
|
368
|
+
return new _WorkflowContext(ctx, this.#runCtx);
|
|
583
369
|
}
|
|
584
370
|
};
|
|
585
371
|
|
|
372
|
+
// src/workflow/driver.ts
|
|
373
|
+
var WORKFLOW_STORAGE_PREFIX = _chunkRTWH3AX3cjs.workflowStoragePrefix.call(void 0, );
|
|
374
|
+
var WORKFLOW_SQLITE_MAX_BATCH_ROWS = 128;
|
|
375
|
+
var WORKFLOW_SQLITE_MAX_BATCH_BYTES = 512 * 1024;
|
|
376
|
+
var WORKFLOW_BATCH_TRANSACTION_NAME = "rivetkit-workflow-batch";
|
|
377
|
+
var WORKFLOW_DELETE_TRANSACTION_NAME = "rivetkit-workflow-delete";
|
|
378
|
+
function stripWorkflowKey(prefixed) {
|
|
379
|
+
return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
|
|
380
|
+
}
|
|
381
|
+
function computeUpperBound(prefix) {
|
|
382
|
+
const upperBound = prefix.slice();
|
|
383
|
+
for (let i = upperBound.length - 1; i >= 0; i--) {
|
|
384
|
+
if (upperBound[i] !== 255) {
|
|
385
|
+
upperBound[i]++;
|
|
386
|
+
return upperBound.slice(0, i + 1);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
function normalizeSqlBlob(value) {
|
|
392
|
+
if (value instanceof Uint8Array) {
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
if (value instanceof ArrayBuffer) {
|
|
396
|
+
return new Uint8Array(value);
|
|
397
|
+
}
|
|
398
|
+
if (ArrayBuffer.isView(value)) {
|
|
399
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
400
|
+
}
|
|
401
|
+
if (Array.isArray(value)) {
|
|
402
|
+
const bytes = new Uint8Array(value.length);
|
|
403
|
+
for (const [i, item] of value.entries()) {
|
|
404
|
+
if (!Number.isInteger(item) || item < 0 || item > 255) {
|
|
405
|
+
throw new Error("workflow sqlite value was not a byte array");
|
|
406
|
+
}
|
|
407
|
+
bytes[i] = item;
|
|
408
|
+
}
|
|
409
|
+
return bytes;
|
|
410
|
+
}
|
|
411
|
+
throw new Error("workflow sqlite value was not a blob");
|
|
412
|
+
}
|
|
413
|
+
function runtimeDbFromContext(runCtx) {
|
|
414
|
+
const db = runCtx == null ? void 0 : runCtx.db;
|
|
415
|
+
if (db && typeof db === "object" && "execute" in db && "transaction" in db) {
|
|
416
|
+
return db;
|
|
417
|
+
}
|
|
418
|
+
return void 0;
|
|
419
|
+
}
|
|
420
|
+
var WorkflowStorage = class {
|
|
421
|
+
#db;
|
|
422
|
+
constructor(db) {
|
|
423
|
+
if (!db) {
|
|
424
|
+
throw new Error(
|
|
425
|
+
"workflow storage requires embedded SQLite; actor KV workflow storage is no longer supported"
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
this.#db = db;
|
|
429
|
+
}
|
|
430
|
+
async get(key) {
|
|
431
|
+
var _a;
|
|
432
|
+
const prefixed = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, key);
|
|
433
|
+
const rows = await this.#db.execute(
|
|
434
|
+
"SELECT value FROM _rivet_wf_kv WHERE key = ?",
|
|
435
|
+
prefixed
|
|
436
|
+
);
|
|
437
|
+
return ((_a = rows[0]) == null ? void 0 : _a.value) == null ? null : normalizeSqlBlob(rows[0].value);
|
|
438
|
+
}
|
|
439
|
+
async set(key, value) {
|
|
440
|
+
await this.batch([{ key, value }]);
|
|
441
|
+
}
|
|
442
|
+
async delete(key) {
|
|
443
|
+
const prefixed = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, key);
|
|
444
|
+
await this.#db.execute(
|
|
445
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
446
|
+
prefixed
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
async batchDelete(keys) {
|
|
450
|
+
if (keys.length === 0) return;
|
|
451
|
+
await this.deleteRawKeys(keys.map((key) => _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, key)));
|
|
452
|
+
}
|
|
453
|
+
async deletePrefix(prefix) {
|
|
454
|
+
const start = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, prefix);
|
|
455
|
+
const end = computeUpperBound(start);
|
|
456
|
+
if (end) {
|
|
457
|
+
await this.#db.execute(
|
|
458
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
459
|
+
start,
|
|
460
|
+
end
|
|
461
|
+
);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const entries = await this.listRaw(start);
|
|
465
|
+
await this.deleteRawKeys(
|
|
466
|
+
entries.filter(([key]) => keyStartsWith(key, start)).map(([key]) => key)
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
async deleteRange(start, end) {
|
|
470
|
+
const prefixedStart = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, start);
|
|
471
|
+
const prefixedEnd = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, end);
|
|
472
|
+
await this.#db.execute(
|
|
473
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
474
|
+
prefixedStart,
|
|
475
|
+
prefixedEnd
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
async list(prefix) {
|
|
479
|
+
const prefixed = _chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, prefix);
|
|
480
|
+
const entries = await this.listRaw(prefixed);
|
|
481
|
+
return entries.filter(([key]) => keyStartsWith(key, prefixed)).map(([key, value]) => ({
|
|
482
|
+
key: stripWorkflowKey(key),
|
|
483
|
+
value
|
|
484
|
+
}));
|
|
485
|
+
}
|
|
486
|
+
async batch(writes) {
|
|
487
|
+
if (writes.length === 0) return;
|
|
488
|
+
for (const chunk of chunkWorkflowWrites(writes)) {
|
|
489
|
+
await this.#db.transaction(
|
|
490
|
+
async (tx) => {
|
|
491
|
+
for (const { key, value } of chunk) {
|
|
492
|
+
await tx.execute(
|
|
493
|
+
"INSERT INTO _rivet_wf_kv (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
|
494
|
+
_chunkRTWH3AX3cjs.makeWorkflowKey.call(void 0, key),
|
|
495
|
+
value
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{ name: WORKFLOW_BATCH_TRANSACTION_NAME }
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async listRaw(prefix) {
|
|
504
|
+
const end = computeUpperBound(prefix);
|
|
505
|
+
const rows = end ? await this.#db.execute(
|
|
506
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? AND key < ? ORDER BY key ASC",
|
|
507
|
+
prefix,
|
|
508
|
+
end
|
|
509
|
+
) : await this.#db.execute(
|
|
510
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? ORDER BY key ASC",
|
|
511
|
+
prefix
|
|
512
|
+
);
|
|
513
|
+
return rows.map((row) => [
|
|
514
|
+
normalizeSqlBlob(row.key),
|
|
515
|
+
normalizeSqlBlob(row.value)
|
|
516
|
+
]);
|
|
517
|
+
}
|
|
518
|
+
async deleteRawKeys(keys) {
|
|
519
|
+
for (let start = 0; start < keys.length; start += WORKFLOW_SQLITE_MAX_BATCH_ROWS) {
|
|
520
|
+
await this.#db.transaction(
|
|
521
|
+
async (tx) => {
|
|
522
|
+
for (const key of keys.slice(
|
|
523
|
+
start,
|
|
524
|
+
start + WORKFLOW_SQLITE_MAX_BATCH_ROWS
|
|
525
|
+
)) {
|
|
526
|
+
await tx.execute(
|
|
527
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
528
|
+
key
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
{ name: WORKFLOW_DELETE_TRANSACTION_NAME }
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
function chunkWorkflowWrites(writes) {
|
|
538
|
+
const chunks = [];
|
|
539
|
+
let chunk = [];
|
|
540
|
+
let chunkBytes = 0;
|
|
541
|
+
for (const write of writes) {
|
|
542
|
+
const writeBytes = WORKFLOW_STORAGE_PREFIX.length + write.key.length + write.value.length;
|
|
543
|
+
if (chunk.length > 0 && (chunk.length >= WORKFLOW_SQLITE_MAX_BATCH_ROWS || chunkBytes + writeBytes > WORKFLOW_SQLITE_MAX_BATCH_BYTES)) {
|
|
544
|
+
chunks.push(chunk);
|
|
545
|
+
chunk = [];
|
|
546
|
+
chunkBytes = 0;
|
|
547
|
+
}
|
|
548
|
+
chunk.push(write);
|
|
549
|
+
chunkBytes += writeBytes;
|
|
550
|
+
}
|
|
551
|
+
if (chunk.length > 0) chunks.push(chunk);
|
|
552
|
+
return chunks;
|
|
553
|
+
}
|
|
554
|
+
function keyStartsWith(key, prefix) {
|
|
555
|
+
if (key.length < prefix.length) return false;
|
|
556
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
557
|
+
if (key[i] !== prefix[i]) return false;
|
|
558
|
+
}
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
var ActorWorkflowMessageDriver = class {
|
|
562
|
+
#actor;
|
|
563
|
+
#runCtx;
|
|
564
|
+
constructor(actor, runCtx) {
|
|
565
|
+
this.#actor = actor;
|
|
566
|
+
this.#runCtx = runCtx;
|
|
567
|
+
}
|
|
568
|
+
async addMessage(message) {
|
|
569
|
+
await this.#runCtx.internalKeepAwake(
|
|
570
|
+
this.#actor.queueManager.enqueue(message.name, message.data)
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
async receiveMessages(opts) {
|
|
574
|
+
const messages = await this.#runCtx.internalKeepAwake(
|
|
575
|
+
this.#actor.queueManager.receive(
|
|
576
|
+
opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
|
|
577
|
+
opts.count,
|
|
578
|
+
0,
|
|
579
|
+
void 0,
|
|
580
|
+
opts.completable
|
|
581
|
+
)
|
|
582
|
+
);
|
|
583
|
+
return messages.map((message) => ({
|
|
584
|
+
id: message.id.toString(),
|
|
585
|
+
name: message.name,
|
|
586
|
+
data: message.body,
|
|
587
|
+
sentAt: message.createdAt,
|
|
588
|
+
...opts.completable ? {
|
|
589
|
+
complete: async (response) => {
|
|
590
|
+
await this.#runCtx.internalKeepAwake(
|
|
591
|
+
this.#actor.queueManager.completeMessage(
|
|
592
|
+
message,
|
|
593
|
+
response
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
} : {}
|
|
598
|
+
}));
|
|
599
|
+
}
|
|
600
|
+
async completeMessage(messageId, response) {
|
|
601
|
+
let parsedId;
|
|
602
|
+
try {
|
|
603
|
+
parsedId = BigInt(messageId);
|
|
604
|
+
} catch (e3) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
await this.#runCtx.internalKeepAwake(
|
|
608
|
+
this.#actor.queueManager.completeMessageById(parsedId, response)
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
var ActorWorkflowDriver = (_class = class {
|
|
613
|
+
__init() {this.atomicBatch = true}
|
|
614
|
+
__init2() {this.workerPollInterval = 100}
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
#actor;
|
|
618
|
+
#runCtx;
|
|
619
|
+
#storage;
|
|
620
|
+
constructor(actor, runCtx) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
621
|
+
this.#actor = actor;
|
|
622
|
+
this.#runCtx = runCtx;
|
|
623
|
+
this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
|
|
624
|
+
this.telemetry = {
|
|
625
|
+
startSpan: () => runCtx.run.startWorkflowSpan()
|
|
626
|
+
};
|
|
627
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
628
|
+
}
|
|
629
|
+
/** Keeps the engine's history storage out of the workflow run's trace. */
|
|
630
|
+
#untraced(run) {
|
|
631
|
+
return this.#runCtx.internalKeepAwake(
|
|
632
|
+
this.#runCtx.run.runOutsideWorkflowSpan(run)
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
async get(key) {
|
|
636
|
+
return await this.#untraced(() => this.#storage.get(key));
|
|
637
|
+
}
|
|
638
|
+
async set(key, value) {
|
|
639
|
+
await this.#untraced(() => this.#storage.set(key, value));
|
|
640
|
+
}
|
|
641
|
+
async delete(key) {
|
|
642
|
+
await this.#untraced(() => this.#storage.delete(key));
|
|
643
|
+
}
|
|
644
|
+
async batchDelete(keys) {
|
|
645
|
+
await this.#untraced(() => this.#storage.batchDelete(keys));
|
|
646
|
+
}
|
|
647
|
+
async deletePrefix(prefix) {
|
|
648
|
+
await this.#untraced(() => this.#storage.deletePrefix(prefix));
|
|
649
|
+
}
|
|
650
|
+
async deleteRange(start, end) {
|
|
651
|
+
await this.#untraced(() => this.#storage.deleteRange(start, end));
|
|
652
|
+
}
|
|
653
|
+
async list(prefix) {
|
|
654
|
+
return await this.#untraced(() => this.#storage.list(prefix));
|
|
655
|
+
}
|
|
656
|
+
async batch(writes) {
|
|
657
|
+
if (writes.length === 0) return;
|
|
658
|
+
await this.#untraced(
|
|
659
|
+
() => this.#actor.stateManager.saveStateAndWorkflowBatch(writes)
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
// The run wake-at shares the actor's one engine alarm with scheduled
|
|
663
|
+
// events, so schedule changes keep the workflow deadline armed. Round up
|
|
664
|
+
// because a fractional retry backoff gives a fractional deadline.
|
|
665
|
+
async setAlarm(_workflowId, wakeAt) {
|
|
666
|
+
await this.#runCtx.internalKeepAwake(
|
|
667
|
+
this.#runCtx.run.setWakeAt(Math.ceil(wakeAt))
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
async clearAlarm(_workflowId) {
|
|
671
|
+
await this.#runCtx.internalKeepAwake(this.#runCtx.run.setWakeAt(null));
|
|
672
|
+
}
|
|
673
|
+
waitForMessages(messageNames, abortSignal) {
|
|
674
|
+
return this.#actor.queueManager.waitForNames(
|
|
675
|
+
messageNames.length > 0 ? messageNames : void 0,
|
|
676
|
+
abortSignal
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
}, _class);
|
|
680
|
+
var NoopWorkflowMessageDriver = class {
|
|
681
|
+
async addMessage(_message) {
|
|
682
|
+
throw new Error("Workflow control driver does not support messages");
|
|
683
|
+
}
|
|
684
|
+
async receiveMessages(_opts) {
|
|
685
|
+
throw new Error("Workflow control driver does not support messages");
|
|
686
|
+
}
|
|
687
|
+
async completeMessage(_messageId, _response) {
|
|
688
|
+
throw new Error("Workflow control driver does not support messages");
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
var ActorWorkflowControlDriver = (_class2 = class {
|
|
692
|
+
__init3() {this.workerPollInterval = 100}
|
|
693
|
+
__init4() {this.messageDriver = new NoopWorkflowMessageDriver()}
|
|
694
|
+
#actor;
|
|
695
|
+
#storage;
|
|
696
|
+
constructor(actor, runCtx) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
|
|
697
|
+
this.#actor = actor;
|
|
698
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
699
|
+
}
|
|
700
|
+
async get(key) {
|
|
701
|
+
return await this.#storage.get(key);
|
|
702
|
+
}
|
|
703
|
+
async set(key, value) {
|
|
704
|
+
await this.#storage.set(key, value);
|
|
705
|
+
}
|
|
706
|
+
async delete(key) {
|
|
707
|
+
await this.#storage.delete(key);
|
|
708
|
+
}
|
|
709
|
+
async batchDelete(keys) {
|
|
710
|
+
await this.#storage.batchDelete(keys);
|
|
711
|
+
}
|
|
712
|
+
async deletePrefix(prefix) {
|
|
713
|
+
await this.#storage.deletePrefix(prefix);
|
|
714
|
+
}
|
|
715
|
+
async deleteRange(start, end) {
|
|
716
|
+
await this.#storage.deleteRange(start, end);
|
|
717
|
+
}
|
|
718
|
+
async list(prefix) {
|
|
719
|
+
return await this.#storage.list(prefix);
|
|
720
|
+
}
|
|
721
|
+
async batch(writes) {
|
|
722
|
+
if (writes.length === 0) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
await this.#storage.batch(writes);
|
|
726
|
+
}
|
|
727
|
+
async setAlarm(_workflowId, wakeAt) {
|
|
728
|
+
await this.#actor.driver.setAlarm(this.#actor, wakeAt);
|
|
729
|
+
}
|
|
730
|
+
async clearAlarm(_workflowId) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
waitForMessages(_messageNames, _abortSignal) {
|
|
734
|
+
throw new Error("Workflow control driver does not support messages");
|
|
735
|
+
}
|
|
736
|
+
}, _class2);
|
|
737
|
+
|
|
586
738
|
// src/workflow/mod.ts
|
|
587
739
|
|
|
588
740
|
function shouldRethrowWorkflowError(error) {
|
|
@@ -595,7 +747,7 @@ function shouldRethrowWorkflowError(error) {
|
|
|
595
747
|
return true;
|
|
596
748
|
}
|
|
597
749
|
function workflowReplayInFlightError() {
|
|
598
|
-
return new (0,
|
|
750
|
+
return new (0, _chunkMGI2VVF6cjs.RivetError)(
|
|
599
751
|
"actor",
|
|
600
752
|
"workflow_in_flight",
|
|
601
753
|
"Workflow replay is unavailable while the workflow is currently in flight.",
|
|
@@ -608,53 +760,63 @@ function workflowReplayInFlightError() {
|
|
|
608
760
|
function isWorkflowReplayBlockedByRunningEntry(error) {
|
|
609
761
|
return error instanceof Error && error.message === "Cannot replay a workflow while a step is currently running";
|
|
610
762
|
}
|
|
763
|
+
function isRunHandlerUnavailable(error) {
|
|
764
|
+
return error instanceof _chunkMGI2VVF6cjs.RivetError && error.group === "actor" && error.code === "run_handler_unavailable";
|
|
765
|
+
}
|
|
611
766
|
function workflow(fn, options = {}) {
|
|
612
767
|
const onError = options.onError;
|
|
613
768
|
const workflowInspectors = /* @__PURE__ */ new Map();
|
|
614
769
|
function getWorkflowInspector(actorId) {
|
|
615
770
|
let workflowInspector = workflowInspectors.get(actorId);
|
|
616
771
|
if (!workflowInspector) {
|
|
617
|
-
workflowInspector =
|
|
772
|
+
workflowInspector = _chunkELZ6MT3Vcjs.createWorkflowInspectorAdapter.call(void 0, );
|
|
618
773
|
workflowInspectors.set(actorId, workflowInspector);
|
|
619
774
|
}
|
|
620
775
|
return workflowInspector;
|
|
621
776
|
}
|
|
622
777
|
async function run(runCtx) {
|
|
623
|
-
const actor = runCtx[
|
|
778
|
+
const actor = runCtx[_chunkAQJFKHBKcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
|
|
624
779
|
_invariant2.default.call(void 0, actor, "workflow() requires an actor instance");
|
|
625
780
|
const workflowInspector = getWorkflowInspector(actor.id);
|
|
626
781
|
const driver = new ActorWorkflowDriver(actor, runCtx);
|
|
627
|
-
const controlDriver = new ActorWorkflowControlDriver(actor);
|
|
782
|
+
const controlDriver = new ActorWorkflowControlDriver(actor, runCtx);
|
|
628
783
|
workflowInspector.setReplayFromStep(async (entryId) => {
|
|
629
784
|
const workflowState = await workflowInspector.adapter.getState();
|
|
630
|
-
if (
|
|
785
|
+
if (workflowState === "pending" || workflowState === "running") {
|
|
631
786
|
throw workflowReplayInFlightError();
|
|
632
787
|
}
|
|
633
|
-
|
|
788
|
+
const control = workflowInspector.control;
|
|
789
|
+
_invariant2.default.call(void 0, control, "workflow Inspector control is not initialized");
|
|
634
790
|
try {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
791
|
+
return await control.run.withInactive(
|
|
792
|
+
{ restartOnSuccess: true },
|
|
793
|
+
async () => {
|
|
794
|
+
const snapshot = await _workflowengine.replayWorkflowFromStep.call(void 0,
|
|
795
|
+
actor.id,
|
|
796
|
+
controlDriver,
|
|
797
|
+
entryId,
|
|
798
|
+
{ scheduleAlarm: false }
|
|
799
|
+
);
|
|
800
|
+
workflowInspector.update(snapshot);
|
|
801
|
+
return workflowInspector.adapter.getHistory();
|
|
802
|
+
}
|
|
640
803
|
);
|
|
641
804
|
} catch (error) {
|
|
642
|
-
if (isWorkflowReplayBlockedByRunningEntry(error)) {
|
|
805
|
+
if (isWorkflowReplayBlockedByRunningEntry(error) || isRunHandlerUnavailable(error)) {
|
|
643
806
|
throw workflowReplayInFlightError();
|
|
644
807
|
}
|
|
645
808
|
throw error;
|
|
646
809
|
}
|
|
647
|
-
workflowInspector.update(snapshot);
|
|
648
|
-
await actor.restartRunHandler();
|
|
649
|
-
return workflowInspector.adapter.getHistory();
|
|
650
810
|
});
|
|
651
811
|
const handle = _workflowengine.runWorkflow.call(void 0,
|
|
652
812
|
actor.id,
|
|
653
|
-
async (ctx) => await fn(new
|
|
813
|
+
async (ctx) => await fn(new WorkflowContext(ctx, runCtx)),
|
|
654
814
|
void 0,
|
|
655
815
|
driver,
|
|
656
816
|
{
|
|
657
817
|
mode: "live",
|
|
818
|
+
// The actor logger and the engine's pino logger are runtime
|
|
819
|
+
// compatible but not structurally assignable.
|
|
658
820
|
logger: runCtx.log,
|
|
659
821
|
onHistoryUpdated: workflowInspector.update,
|
|
660
822
|
onError: onError ? async (event) => await onError(runCtx, event) : void 0
|
|
@@ -674,60 +836,45 @@ function workflow(fn, options = {}) {
|
|
|
674
836
|
try {
|
|
675
837
|
await handle.result;
|
|
676
838
|
} catch (error) {
|
|
677
|
-
if (runCtx.abortSignal.aborted) {
|
|
839
|
+
if (runCtx.abortSignal.aborted || _chunkMGI2VVF6cjs.isActorAbortedError.call(void 0, error)) {
|
|
678
840
|
return;
|
|
679
841
|
}
|
|
680
842
|
if (shouldRethrowWorkflowError(error)) {
|
|
681
843
|
runCtx.log.error({
|
|
682
844
|
msg: "workflow run failed",
|
|
683
|
-
error:
|
|
845
|
+
error: _chunk6XVNZKKPcjs.stringifyError.call(void 0, error)
|
|
684
846
|
});
|
|
685
847
|
throw error;
|
|
686
848
|
}
|
|
687
849
|
runCtx.log.warn({
|
|
688
850
|
msg: "workflow failed and will sleep until woken",
|
|
689
|
-
error:
|
|
851
|
+
error: _chunk6XVNZKKPcjs.stringifyError.call(void 0, error)
|
|
690
852
|
});
|
|
691
853
|
} finally {
|
|
692
854
|
runCtx.abortSignal.removeEventListener("abort", onAbort);
|
|
693
855
|
}
|
|
694
856
|
}
|
|
695
|
-
|
|
696
|
-
runWithConfig[_chunkWQ4HNA4Wcjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
|
|
857
|
+
return _chunkAQJFKHBKcjs.defineRunHandler.call(void 0, run, {
|
|
697
858
|
icon: "diagram-project",
|
|
698
|
-
|
|
699
|
-
|
|
859
|
+
inspectorKind: "workflow",
|
|
860
|
+
createInspector: ({ actorId, control }) => {
|
|
861
|
+
const workflowInspector = getWorkflowInspector(actorId);
|
|
862
|
+
workflowInspector.control = control;
|
|
700
863
|
return {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
864
|
+
inspector: { workflow: workflowInspector.adapter },
|
|
865
|
+
dispose: () => {
|
|
866
|
+
if (workflowInspectors.get(actorId) === workflowInspector) {
|
|
867
|
+
workflowInspectors.delete(actorId);
|
|
868
|
+
}
|
|
706
869
|
}
|
|
707
870
|
};
|
|
708
871
|
}
|
|
709
|
-
};
|
|
710
|
-
return runWithConfig;
|
|
711
|
-
}
|
|
712
|
-
function resolveWorkflowInspectorActorId(actor) {
|
|
713
|
-
if (typeof actor === "string" && actor.length > 0) {
|
|
714
|
-
return actor;
|
|
715
|
-
}
|
|
716
|
-
if (!actor || typeof actor !== "object") {
|
|
717
|
-
return void 0;
|
|
718
|
-
}
|
|
719
|
-
const candidate = actor;
|
|
720
|
-
if (typeof candidate.id === "string" && candidate.id.length > 0) {
|
|
721
|
-
return candidate.id;
|
|
722
|
-
}
|
|
723
|
-
if (typeof candidate.actorId === "string" && candidate.actorId.length > 0) {
|
|
724
|
-
return candidate.actorId;
|
|
725
|
-
}
|
|
726
|
-
return void 0;
|
|
872
|
+
});
|
|
727
873
|
}
|
|
728
874
|
|
|
729
875
|
|
|
730
876
|
|
|
731
877
|
|
|
732
|
-
|
|
878
|
+
|
|
879
|
+
exports.Loop = _workflowengine.Loop; exports.WorkflowContext = WorkflowContext; exports.WorkflowStepContext = WorkflowStepContext; exports.workflow = workflow;
|
|
733
880
|
//# sourceMappingURL=mod.cjs.map
|