rivetkit 2.0.42 → 2.1.0-rc.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/dist/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
- package/dist/browser/client.js +5182 -0
- package/dist/browser/client.js.map +1 -0
- package/dist/browser/inspector/client.d.ts +130 -0
- package/dist/browser/inspector/client.js +2854 -0
- package/dist/browser/inspector/client.js.map +1 -0
- package/dist/browser/v3-DnYObHH3.d.ts +279 -0
- package/dist/schemas/actor-inspector/v2.ts +796 -0
- package/dist/schemas/actor-inspector/v3.ts +899 -0
- package/dist/schemas/actor-persist/v4.ts +406 -0
- package/dist/schemas/client-protocol/v3.ts +554 -0
- package/dist/schemas/persist/v1.ts +781 -0
- package/dist/schemas/transport/v1.ts +697 -0
- package/dist/tsup/actor/errors.cjs +27 -3
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +37 -1
- package/dist/tsup/actor/errors.d.ts +37 -1
- package/dist/tsup/actor/errors.js +26 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
- package/dist/tsup/chunk-424PT5DM.js +23 -0
- package/dist/tsup/chunk-424PT5DM.js.map +1 -0
- package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
- package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
- package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
- package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
- package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
- package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
- package/dist/tsup/chunk-7K4CYDGD.js +630 -0
- package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
- package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
- package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
- package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
- package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
- package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
- package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
- package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
- package/dist/tsup/chunk-IVG73YCW.js +534 -0
- package/dist/tsup/chunk-IVG73YCW.js.map +1 -0
- package/dist/tsup/chunk-KJSYAUOM.js +96 -0
- package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
- package/dist/tsup/{chunk-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
- package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
- package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
- package/dist/tsup/chunk-LW6KLR7A.cjs.map +1 -0
- package/dist/tsup/chunk-LXUQ667X.js +2006 -0
- package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
- package/dist/tsup/{chunk-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
- package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
- package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
- package/dist/tsup/chunk-MZ37VV3P.js.map +1 -0
- package/dist/tsup/chunk-N4KRDJ56.js +72 -0
- package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
- package/dist/tsup/chunk-OMEPCQK2.js +649 -0
- package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
- package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
- package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
- package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
- package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
- package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
- package/dist/tsup/chunk-TYLXNCA5.cjs.map +1 -0
- package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
- package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs +649 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs.map +1 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -10
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +11 -5
- package/dist/tsup/client/mod.d.ts +11 -5
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +4 -4
- package/dist/tsup/common/log.d.cts +2 -2
- package/dist/tsup/common/log.d.ts +2 -2
- package/dist/tsup/common/log.js +3 -2
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -3
- package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
- package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
- package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
- package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
- package/dist/tsup/db/drizzle/mod.cjs +49 -0
- package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
- package/dist/tsup/db/drizzle/mod.d.cts +17 -0
- package/dist/tsup/db/drizzle/mod.d.ts +17 -0
- package/dist/tsup/db/drizzle/mod.js +49 -0
- package/dist/tsup/db/drizzle/mod.js.map +1 -0
- package/dist/tsup/db/mod.cjs +9 -0
- package/dist/tsup/db/mod.cjs.map +1 -0
- package/dist/tsup/db/mod.d.cts +9 -0
- package/dist/tsup/db/mod.d.ts +9 -0
- package/dist/tsup/db/mod.js +9 -0
- package/dist/tsup/db/mod.js.map +1 -0
- package/dist/tsup/{driver-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
- package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
- package/dist/tsup/driver-helpers/mod.cjs +12 -6
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +12 -5
- package/dist/tsup/driver-helpers/mod.d.ts +12 -5
- package/dist/tsup/driver-helpers/mod.js +12 -5
- package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
- package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
- package/dist/tsup/driver-test-suite/mod.js +2093 -838
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +29 -3
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +124 -3
- package/dist/tsup/inspector/mod.d.ts +124 -3
- package/dist/tsup/inspector/mod.js +72 -45
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +16 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +26 -14
- package/dist/tsup/mod.d.ts +26 -14
- package/dist/tsup/mod.js +20 -13
- package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +1114 -29
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +84 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +10 -5
- package/dist/tsup/test/mod.d.ts +10 -5
- package/dist/tsup/test/mod.js +85 -11
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +10 -4
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +72 -2
- package/dist/tsup/utils.d.ts +72 -2
- package/dist/tsup/utils.js +9 -2
- package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
- package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
- package/dist/tsup/workflow/mod.cjs +16 -0
- package/dist/tsup/workflow/mod.cjs.map +1 -0
- package/dist/tsup/workflow/mod.d.cts +83 -0
- package/dist/tsup/workflow/mod.d.ts +83 -0
- package/dist/tsup/workflow/mod.js +16 -0
- package/dist/tsup/workflow/mod.js.map +1 -0
- package/package.json +62 -5
- package/src/actor/config.ts +478 -68
- package/src/actor/conn/mod.ts +68 -16
- package/src/actor/conn/state-manager.ts +2 -2
- package/src/actor/contexts/action.ts +20 -12
- package/src/actor/contexts/base/actor.ts +137 -7
- package/src/actor/contexts/base/conn-init.ts +27 -7
- package/src/actor/contexts/base/conn.ts +27 -18
- package/src/actor/contexts/before-action-response.ts +9 -2
- package/src/actor/contexts/before-connect.ts +7 -2
- package/src/actor/contexts/connect.ts +9 -2
- package/src/actor/contexts/create-conn-state.ts +7 -2
- package/src/actor/contexts/create-vars.ts +16 -3
- package/src/actor/contexts/create.ts +16 -3
- package/src/actor/contexts/destroy.ts +9 -3
- package/src/actor/contexts/disconnect.ts +10 -4
- package/src/actor/contexts/index.ts +4 -3
- package/src/actor/contexts/request.ts +23 -6
- package/src/actor/contexts/run.ts +47 -0
- package/src/actor/contexts/sleep.ts +9 -3
- package/src/actor/contexts/state-change.ts +9 -3
- package/src/actor/contexts/wake.ts +9 -3
- package/src/actor/contexts/websocket.ts +23 -6
- package/src/actor/database.ts +8 -18
- package/src/actor/definition.ts +20 -6
- package/src/actor/driver.ts +32 -3
- package/src/actor/errors.ts +127 -0
- package/src/actor/instance/connection-manager.ts +183 -80
- package/src/actor/instance/event-manager.ts +26 -15
- package/src/actor/instance/keys.ts +117 -0
- package/src/actor/instance/mod.ts +784 -174
- package/src/actor/instance/queue-manager.ts +603 -0
- package/src/actor/instance/queue.ts +287 -0
- package/src/actor/instance/schedule-manager.ts +49 -7
- package/src/actor/instance/state-manager.ts +35 -11
- package/src/actor/instance/traces-driver.ts +128 -0
- package/src/actor/mod.ts +26 -2
- package/src/actor/protocol/old.ts +28 -13
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +177 -21
- package/src/actor/router-websocket-endpoints.ts +18 -29
- package/src/actor/router.ts +177 -0
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.ts +40 -0
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +100 -33
- package/src/client/actor-handle.ts +61 -33
- package/src/client/client.ts +2 -4
- package/src/client/config.ts +1 -1
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +1 -4
- package/src/client/queue.ts +146 -0
- package/src/client/utils.ts +1 -1
- package/src/common/log.ts +1 -1
- package/src/common/utils.ts +3 -3
- package/src/db/config.ts +100 -0
- package/src/db/drizzle/mod.ts +226 -0
- package/src/db/drizzle/sqlite-core.ts +22 -0
- package/src/db/mod.ts +125 -0
- package/src/db/shared.ts +92 -0
- package/src/db/sqlite-vfs.ts +12 -0
- package/src/driver-helpers/mod.ts +1 -0
- package/src/driver-test-suite/mod.ts +69 -43
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
- package/src/driver-test-suite/tests/actor-db.ts +394 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
- package/src/driver-test-suite/tests/actor-kv.ts +41 -20
- package/src/driver-test-suite/tests/actor-queue.ts +324 -0
- package/src/driver-test-suite/tests/actor-run.ts +181 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
- package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
- package/src/driver-test-suite/tests/manager-driver.ts +11 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
- package/src/drivers/default.ts +7 -2
- package/src/drivers/engine/actor-driver.ts +45 -37
- package/src/drivers/engine/config.ts +1 -1
- package/src/drivers/file-system/actor.ts +20 -2
- package/src/drivers/file-system/global-state.ts +569 -258
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/manager.ts +22 -6
- package/src/drivers/file-system/mod.ts +39 -16
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/inspector/actor-inspector.ts +224 -102
- package/src/inspector/config.ts +1 -1
- package/src/inspector/handler.ts +102 -20
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +2 -0
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +5 -39
- package/src/manager/gateway.ts +1 -1
- package/src/manager/protocol/mod.ts +1 -1
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router-schema.ts +1 -1
- package/src/manager/router.ts +38 -12
- package/src/manager-api/actors.ts +1 -1
- package/src/manager-api/common.ts +1 -1
- package/src/registry/config/driver.ts +1 -1
- package/src/registry/config/index.ts +212 -43
- package/src/registry/config/legacy-runner.ts +1 -1
- package/src/registry/config/runner.ts +1 -1
- package/src/registry/config/serverless.ts +1 -1
- package/src/registry/index.ts +7 -5
- package/src/remote-manager-driver/api-utils.ts +1 -1
- package/src/schemas/actor-inspector/mod.ts +1 -1
- package/src/schemas/actor-inspector/versioned.ts +195 -8
- package/src/schemas/actor-persist/versioned.ts +87 -7
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +127 -11
- package/src/schemas/client-protocol-zod/mod.ts +16 -1
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +1 -1
- package/src/serve-test-suite/mod.ts +10 -9
- package/src/test/mod.ts +15 -56
- package/src/utils/endpoint-parser.test.ts +1 -1
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +12 -1
- package/src/utils/node.ts +15 -2
- package/src/utils.test.ts +34 -0
- package/src/utils.ts +140 -6
- package/src/workflow/constants.ts +2 -0
- package/src/workflow/context.ts +532 -0
- package/src/workflow/driver.ts +191 -0
- package/src/workflow/inspector.ts +268 -0
- package/src/workflow/mod.ts +122 -0
- package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
- package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
- package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
- package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
- package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
- package/dist/tsup/chunk-AQFSQMBG.js +0 -114
- package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
- package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
- package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
- package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
- package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
- package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
- package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
- package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
- package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
- package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
- package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
- package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
- package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
- package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
- package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
- package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
- package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
- package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
- package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
- package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
- package/dist/tsup/chunk-TCOEBUUE.js +0 -278
- package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
- package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
- package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
- package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
- package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
- package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
- /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
|
-
import { z } from "zod";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
3
|
import type { AnyDatabaseProvider } from "@/actor/database";
|
|
4
4
|
import * as errors from "@/actor/errors";
|
|
5
5
|
import {
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
import { CONN_SEND_MESSAGE_SYMBOL, type Conn } from "../conn/mod";
|
|
30
30
|
import { ActionContext } from "../contexts";
|
|
31
31
|
import type { ActorInstance } from "../instance/mod";
|
|
32
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "../schema";
|
|
32
33
|
|
|
33
34
|
interface MessageEventOpts {
|
|
34
35
|
encoding: Encoding;
|
|
@@ -139,19 +140,21 @@ export interface ProcessMessageHandler<
|
|
|
139
140
|
V,
|
|
140
141
|
I,
|
|
141
142
|
DB extends AnyDatabaseProvider,
|
|
143
|
+
E extends EventSchemaConfig,
|
|
144
|
+
Q extends QueueSchemaConfig,
|
|
142
145
|
> {
|
|
143
146
|
onExecuteAction?: (
|
|
144
|
-
ctx: ActionContext<S, CP, CS, V, I, DB>,
|
|
147
|
+
ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>,
|
|
145
148
|
name: string,
|
|
146
149
|
args: unknown[],
|
|
147
150
|
) => Promise<unknown>;
|
|
148
151
|
onSubscribe?: (
|
|
149
152
|
eventName: string,
|
|
150
|
-
conn: Conn<S, CP, CS, V, I, DB>,
|
|
153
|
+
conn: Conn<S, CP, CS, V, I, DB, E, Q>,
|
|
151
154
|
) => Promise<void>;
|
|
152
155
|
onUnsubscribe?: (
|
|
153
156
|
eventName: string,
|
|
154
|
-
conn: Conn<S, CP, CS, V, I, DB>,
|
|
157
|
+
conn: Conn<S, CP, CS, V, I, DB, E, Q>,
|
|
155
158
|
) => Promise<void>;
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -162,6 +165,8 @@ export async function processMessage<
|
|
|
162
165
|
V,
|
|
163
166
|
I,
|
|
164
167
|
DB extends AnyDatabaseProvider,
|
|
168
|
+
E extends EventSchemaConfig,
|
|
169
|
+
Q extends QueueSchemaConfig,
|
|
165
170
|
>(
|
|
166
171
|
message: {
|
|
167
172
|
body:
|
|
@@ -174,9 +179,9 @@ export async function processMessage<
|
|
|
174
179
|
val: { eventName: string; subscribe: boolean };
|
|
175
180
|
};
|
|
176
181
|
},
|
|
177
|
-
actor: ActorInstance<S, CP, CS, V, I, DB>,
|
|
178
|
-
conn: Conn<S, CP, CS, V, I, DB>,
|
|
179
|
-
handler: ProcessMessageHandler<S, CP, CS, V, I, DB>,
|
|
182
|
+
actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>,
|
|
183
|
+
conn: Conn<S, CP, CS, V, I, DB, E, Q>,
|
|
184
|
+
handler: ProcessMessageHandler<S, CP, CS, V, I, DB, E, Q>,
|
|
180
185
|
) {
|
|
181
186
|
let actionId: bigint | undefined;
|
|
182
187
|
let actionName: string | undefined;
|
|
@@ -199,7 +204,10 @@ export async function processMessage<
|
|
|
199
204
|
actionName: name,
|
|
200
205
|
});
|
|
201
206
|
|
|
202
|
-
const ctx = new ActionContext<S, CP, CS, V, I, DB>(
|
|
207
|
+
const ctx = new ActionContext<S, CP, CS, V, I, DB, E, Q>(
|
|
208
|
+
actor,
|
|
209
|
+
conn,
|
|
210
|
+
);
|
|
203
211
|
|
|
204
212
|
// Process the action request and wait for the result
|
|
205
213
|
// This will wait for async actions to complete
|
|
@@ -265,11 +273,18 @@ export async function processMessage<
|
|
|
265
273
|
subscribe,
|
|
266
274
|
});
|
|
267
275
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
276
|
+
if (subscribe) {
|
|
277
|
+
await actor.assertCanSubscribe(
|
|
278
|
+
new ActionContext<S, CP, CS, V, I, DB, E, Q>(
|
|
279
|
+
actor,
|
|
280
|
+
conn,
|
|
281
|
+
),
|
|
282
|
+
eventName,
|
|
283
|
+
);
|
|
284
|
+
await handler.onSubscribe(eventName, conn);
|
|
285
|
+
} else {
|
|
286
|
+
await handler.onUnsubscribe(eventName, conn);
|
|
287
|
+
}
|
|
273
288
|
|
|
274
289
|
actor.rLog.debug({
|
|
275
290
|
msg: "subscription request completed",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
2
|
import type { VersionedDataHandler } from "vbare";
|
|
3
|
-
import { z } from "zod";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
4
|
import * as errors from "@/actor/errors";
|
|
5
5
|
import { serializeWithEncoding } from "@/serde";
|
|
6
6
|
import { loggerWithoutContext } from "../log";
|
|
@@ -5,6 +5,7 @@ import { ActionContext } from "@/actor/contexts";
|
|
|
5
5
|
import * as errors from "@/actor/errors";
|
|
6
6
|
import type { AnyActorInstance } from "@/actor/instance/mod";
|
|
7
7
|
import { type Encoding, EncodingSchema } from "@/actor/protocol/serde";
|
|
8
|
+
import { hasSchemaConfigKey } from "@/actor/schema";
|
|
8
9
|
import {
|
|
9
10
|
HEADER_ACTOR_QUERY,
|
|
10
11
|
HEADER_CONN_PARAMS,
|
|
@@ -13,17 +14,24 @@ import {
|
|
|
13
14
|
WS_PROTOCOL_ENCODING,
|
|
14
15
|
} from "@/common/actor-router-consts";
|
|
15
16
|
import { stringifyError } from "@/common/utils";
|
|
17
|
+
import type { RegistryConfig } from "@/registry/config";
|
|
16
18
|
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
17
19
|
import {
|
|
18
20
|
CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
|
|
19
21
|
HTTP_ACTION_REQUEST_VERSIONED,
|
|
20
22
|
HTTP_ACTION_RESPONSE_VERSIONED,
|
|
23
|
+
HTTP_QUEUE_SEND_REQUEST_VERSIONED,
|
|
24
|
+
HTTP_QUEUE_SEND_RESPONSE_VERSIONED,
|
|
21
25
|
} from "@/schemas/client-protocol/versioned";
|
|
22
26
|
import {
|
|
23
27
|
type HttpActionRequest as HttpActionRequestJson,
|
|
24
28
|
HttpActionRequestSchema,
|
|
25
29
|
type HttpActionResponse as HttpActionResponseJson,
|
|
26
30
|
HttpActionResponseSchema,
|
|
31
|
+
type HttpQueueSendRequest as HttpQueueSendRequestJson,
|
|
32
|
+
HttpQueueSendRequestSchema,
|
|
33
|
+
type HttpQueueSendResponse as HttpQueueSendResponseJson,
|
|
34
|
+
HttpQueueSendResponseSchema,
|
|
27
35
|
} from "@/schemas/client-protocol-zod/mod";
|
|
28
36
|
import {
|
|
29
37
|
contentTypeForEncoding,
|
|
@@ -35,7 +43,6 @@ import { createHttpDriver } from "./conn/drivers/http";
|
|
|
35
43
|
import { createRawRequestDriver } from "./conn/drivers/raw-request";
|
|
36
44
|
import type { ActorDriver } from "./driver";
|
|
37
45
|
import { loggerWithoutContext } from "./log";
|
|
38
|
-
import { RegistryConfig } from "@/registry/config";
|
|
39
46
|
|
|
40
47
|
export interface ActionOpts {
|
|
41
48
|
req?: HonoRequest;
|
|
@@ -61,6 +68,15 @@ export interface FetchOpts {
|
|
|
61
68
|
actorId: string;
|
|
62
69
|
}
|
|
63
70
|
|
|
71
|
+
export interface QueueSendOpts {
|
|
72
|
+
req?: HonoRequest;
|
|
73
|
+
name: string;
|
|
74
|
+
body: unknown;
|
|
75
|
+
wait?: boolean;
|
|
76
|
+
timeout?: number;
|
|
77
|
+
actorId: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
/**
|
|
65
81
|
* Creates an action handler
|
|
66
82
|
*/
|
|
@@ -96,31 +112,50 @@ export async function handleAction(
|
|
|
96
112
|
const actionArgs = request;
|
|
97
113
|
|
|
98
114
|
// Invoke the action
|
|
99
|
-
let actor: AnyActorInstance | undefined;
|
|
100
|
-
let conn: AnyConn | undefined;
|
|
101
115
|
let output: unknown | undefined;
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
let outputReady = false;
|
|
117
|
+
const maxAttempts = 3;
|
|
118
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
119
|
+
let actor: AnyActorInstance | undefined;
|
|
120
|
+
let conn: AnyConn | undefined;
|
|
121
|
+
try {
|
|
122
|
+
actor = await actorDriver.loadActor(actorId);
|
|
104
123
|
|
|
105
|
-
|
|
124
|
+
actor.rLog.debug({ msg: "handling action", actionName, encoding });
|
|
106
125
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
// Create conn
|
|
127
|
+
conn = await actor.connectionManager.prepareAndConnectConn(
|
|
128
|
+
createHttpDriver(),
|
|
129
|
+
parameters,
|
|
130
|
+
c.req.raw,
|
|
131
|
+
c.req.path,
|
|
132
|
+
c.req.header(),
|
|
133
|
+
);
|
|
115
134
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
// Call action
|
|
136
|
+
const ctx = new ActionContext(actor, conn);
|
|
137
|
+
output = await actor.executeAction(ctx, actionName, actionArgs);
|
|
138
|
+
outputReady = true;
|
|
139
|
+
break;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
const shouldRetry =
|
|
142
|
+
error instanceof errors.InternalError &&
|
|
143
|
+
error.message === "Actor is stopping" &&
|
|
144
|
+
attempt < maxAttempts - 1;
|
|
145
|
+
if (shouldRetry) {
|
|
146
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
} finally {
|
|
151
|
+
if (conn) {
|
|
152
|
+
conn.disconnect();
|
|
153
|
+
}
|
|
122
154
|
}
|
|
123
155
|
}
|
|
156
|
+
if (!outputReady) {
|
|
157
|
+
throw new errors.InternalError("Action did not complete");
|
|
158
|
+
}
|
|
124
159
|
|
|
125
160
|
// Send response
|
|
126
161
|
const serialized = serializeWithEncoding(
|
|
@@ -138,7 +173,10 @@ export async function handleAction(
|
|
|
138
173
|
);
|
|
139
174
|
|
|
140
175
|
// Check outgoing message size
|
|
141
|
-
const messageSize =
|
|
176
|
+
const messageSize =
|
|
177
|
+
serialized instanceof Uint8Array
|
|
178
|
+
? serialized.byteLength
|
|
179
|
+
: serialized.length;
|
|
142
180
|
if (messageSize > config.maxOutgoingMessageSize) {
|
|
143
181
|
throw new errors.OutgoingMessageTooLong();
|
|
144
182
|
}
|
|
@@ -149,6 +187,124 @@ export async function handleAction(
|
|
|
149
187
|
});
|
|
150
188
|
}
|
|
151
189
|
|
|
190
|
+
export async function handleQueueSend(
|
|
191
|
+
c: HonoContext,
|
|
192
|
+
config: RegistryConfig,
|
|
193
|
+
actorDriver: ActorDriver,
|
|
194
|
+
actorId: string,
|
|
195
|
+
queueName?: string,
|
|
196
|
+
) {
|
|
197
|
+
const encoding = getRequestEncoding(c.req);
|
|
198
|
+
const params = getRequestConnParams(c.req);
|
|
199
|
+
const arrayBuffer = await c.req.arrayBuffer();
|
|
200
|
+
|
|
201
|
+
if (arrayBuffer.byteLength > config.maxIncomingMessageSize) {
|
|
202
|
+
throw new errors.IncomingMessageTooLong();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const request = deserializeWithEncoding(
|
|
206
|
+
encoding,
|
|
207
|
+
new Uint8Array(arrayBuffer),
|
|
208
|
+
HTTP_QUEUE_SEND_REQUEST_VERSIONED,
|
|
209
|
+
HttpQueueSendRequestSchema,
|
|
210
|
+
(json: HttpQueueSendRequestJson) => json,
|
|
211
|
+
(bare: protocol.HttpQueueSendRequest) => ({
|
|
212
|
+
name: bare.name ?? undefined,
|
|
213
|
+
body: cbor.decode(new Uint8Array(bare.body)),
|
|
214
|
+
wait: bare.wait ?? undefined,
|
|
215
|
+
timeout:
|
|
216
|
+
bare.timeout !== null && bare.timeout !== undefined
|
|
217
|
+
? Number(bare.timeout)
|
|
218
|
+
: undefined,
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const name = queueName ?? request.name;
|
|
223
|
+
if (!name) {
|
|
224
|
+
throw new errors.InvalidRequest("missing queue name");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const actor = await actorDriver.loadActor(actorId);
|
|
228
|
+
if (!hasSchemaConfigKey(actor.config.queues, name)) {
|
|
229
|
+
actor.rLog.warn({
|
|
230
|
+
msg: "ignoring incoming queue message for undefined queue",
|
|
231
|
+
queueName: name,
|
|
232
|
+
hasQueueConfig: actor.config.queues !== undefined,
|
|
233
|
+
});
|
|
234
|
+
const ignoredResponse = serializeWithEncoding(
|
|
235
|
+
encoding,
|
|
236
|
+
{ status: "completed" as const, response: undefined },
|
|
237
|
+
HTTP_QUEUE_SEND_RESPONSE_VERSIONED,
|
|
238
|
+
CLIENT_PROTOCOL_CURRENT_VERSION,
|
|
239
|
+
HttpQueueSendResponseSchema,
|
|
240
|
+
(value): HttpQueueSendResponseJson => ({
|
|
241
|
+
status: value.status,
|
|
242
|
+
response: value.response,
|
|
243
|
+
}),
|
|
244
|
+
(value): protocol.HttpQueueSendResponse => ({
|
|
245
|
+
status: value.status,
|
|
246
|
+
response:
|
|
247
|
+
value.response !== undefined
|
|
248
|
+
? bufferToArrayBuffer(cbor.encode(value.response))
|
|
249
|
+
: null,
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
252
|
+
return c.body(ignoredResponse as Uint8Array as any, 200, {
|
|
253
|
+
"Content-Type": contentTypeForEncoding(encoding),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const conn = await actor.connectionManager.prepareAndConnectConn(
|
|
258
|
+
createHttpDriver(),
|
|
259
|
+
params,
|
|
260
|
+
c.req.raw,
|
|
261
|
+
c.req.path,
|
|
262
|
+
c.req.header(),
|
|
263
|
+
);
|
|
264
|
+
let result: { status: "completed" | "timedOut"; response?: unknown } = {
|
|
265
|
+
status: "completed",
|
|
266
|
+
};
|
|
267
|
+
try {
|
|
268
|
+
const ctx = new ActionContext(actor, conn);
|
|
269
|
+
await actor.assertCanPublish(ctx, name);
|
|
270
|
+
|
|
271
|
+
if (request.wait) {
|
|
272
|
+
result = await actor.queueManager.enqueueAndWait(
|
|
273
|
+
name,
|
|
274
|
+
request.body,
|
|
275
|
+
request.timeout,
|
|
276
|
+
);
|
|
277
|
+
} else {
|
|
278
|
+
await actor.queueManager.enqueue(name, request.body);
|
|
279
|
+
}
|
|
280
|
+
} finally {
|
|
281
|
+
conn.disconnect();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const response = serializeWithEncoding(
|
|
285
|
+
encoding,
|
|
286
|
+
result,
|
|
287
|
+
HTTP_QUEUE_SEND_RESPONSE_VERSIONED,
|
|
288
|
+
CLIENT_PROTOCOL_CURRENT_VERSION,
|
|
289
|
+
HttpQueueSendResponseSchema,
|
|
290
|
+
(value): HttpQueueSendResponseJson => ({
|
|
291
|
+
status: value.status,
|
|
292
|
+
response: value.response,
|
|
293
|
+
}),
|
|
294
|
+
(value): protocol.HttpQueueSendResponse => ({
|
|
295
|
+
status: value.status,
|
|
296
|
+
response:
|
|
297
|
+
value.response !== undefined
|
|
298
|
+
? bufferToArrayBuffer(cbor.encode(value.response))
|
|
299
|
+
: null,
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
return c.body(response as Uint8Array as any, 200, {
|
|
304
|
+
"Content-Type": contentTypeForEncoding(encoding),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
152
308
|
export async function handleRawRequest(
|
|
153
309
|
c: HonoContext,
|
|
154
310
|
req: Request,
|
|
@@ -86,7 +86,7 @@ export async function routeWebSocket(
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
// Promise used to wait for the websocket close in `disconnect`
|
|
89
|
-
const closePromiseResolvers = promiseWithResolvers<void>();
|
|
89
|
+
const closePromiseResolvers = promiseWithResolvers<void>((reason) => loggerWithoutContext().warn({ msg: "unhandled websocket close promise rejection", reason }));
|
|
90
90
|
|
|
91
91
|
// Strip query parameters from requestPath for routing purposes.
|
|
92
92
|
// This handles paths like "/websocket?query=value" which should route
|
|
@@ -188,13 +188,13 @@ export async function routeWebSocket(
|
|
|
188
188
|
return {
|
|
189
189
|
conn: createdConn!,
|
|
190
190
|
onOpen: (_evt: any, ws: WSContext) => {
|
|
191
|
-
ws.close(1011, code);
|
|
191
|
+
ws.close(1011, `${group}.${code}`);
|
|
192
192
|
},
|
|
193
193
|
onMessage: (_evt: { data: any }, ws: WSContext) => {
|
|
194
194
|
ws.close(1011, "actor.not_loaded");
|
|
195
195
|
},
|
|
196
|
-
onClose: (_event: any, _ws: WSContext) => {},
|
|
197
|
-
onError: (_error: unknown) => {},
|
|
196
|
+
onClose: (_event: any, _ws: WSContext) => { },
|
|
197
|
+
onError: (_error: unknown) => { },
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -213,6 +213,10 @@ export async function handleWebSocketConnect(
|
|
|
213
213
|
exposeInternalError,
|
|
214
214
|
}: WebSocketHandlerOpts,
|
|
215
215
|
): Promise<UpgradeWebSocketArgs> {
|
|
216
|
+
// Process WS messages in order to avoid races between subscription updates
|
|
217
|
+
// and subsequent action requests.
|
|
218
|
+
let pendingMessage = Promise.resolve();
|
|
219
|
+
|
|
216
220
|
return {
|
|
217
221
|
conn,
|
|
218
222
|
actor,
|
|
@@ -230,33 +234,18 @@ export async function handleWebSocketConnect(
|
|
|
230
234
|
actor.connectionManager.connectConn(conn);
|
|
231
235
|
},
|
|
232
236
|
onMessage: (evt: RivetMessageEvent, ws: WSContext) => {
|
|
233
|
-
// Handle message asynchronously
|
|
234
237
|
actor.rLog.debug({ msg: "received message" });
|
|
235
|
-
|
|
236
238
|
const value = evt.data.valueOf() as InputData;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
actor.processMessage(message, conn).catch((error) => {
|
|
243
|
-
const { code } = deconstructError(
|
|
244
|
-
error,
|
|
245
|
-
actor.rLog,
|
|
246
|
-
{
|
|
247
|
-
wsEvent: "message",
|
|
248
|
-
},
|
|
249
|
-
exposeInternalError,
|
|
250
|
-
);
|
|
251
|
-
ws.close(1011, code);
|
|
239
|
+
pendingMessage = pendingMessage
|
|
240
|
+
.then(async () => {
|
|
241
|
+
const message = await parseMessage(value, {
|
|
242
|
+
encoding: encoding,
|
|
243
|
+
maxIncomingMessageSize: runConfig.maxIncomingMessageSize,
|
|
252
244
|
});
|
|
245
|
+
await actor.processMessage(message, conn);
|
|
253
246
|
})
|
|
254
247
|
.catch((error) => {
|
|
255
|
-
|
|
256
|
-
// This is fail-fast behavior: we cannot send an error response for a
|
|
257
|
-
// message we couldn't parse (no actionId), and skipping the message
|
|
258
|
-
// could cause request/response ordering corruption.
|
|
259
|
-
const { code } = deconstructError(
|
|
248
|
+
const { group, code } = deconstructError(
|
|
260
249
|
error,
|
|
261
250
|
actor.rLog,
|
|
262
251
|
{
|
|
@@ -264,7 +253,7 @@ export async function handleWebSocketConnect(
|
|
|
264
253
|
},
|
|
265
254
|
exposeInternalError,
|
|
266
255
|
);
|
|
267
|
-
ws.close(1011, code);
|
|
256
|
+
ws.close(1011, `${group}.${code}`);
|
|
268
257
|
});
|
|
269
258
|
},
|
|
270
259
|
onClose: (
|
|
@@ -350,7 +339,7 @@ export async function handleRawWebSocket(
|
|
|
350
339
|
},
|
|
351
340
|
// Raw websocket messages are handled directly by the actor's event
|
|
352
341
|
// listeners on the WebSocket object, not through this callback
|
|
353
|
-
onMessage: (_evt: any, _ws: any) => {},
|
|
342
|
+
onMessage: (_evt: any, _ws: any) => { },
|
|
354
343
|
onClose: (evt: any, ws: any) => {
|
|
355
344
|
// Resolve the close promise
|
|
356
345
|
closePromiseResolvers.resolve();
|
|
@@ -358,7 +347,7 @@ export async function handleRawWebSocket(
|
|
|
358
347
|
// Clean up the connection
|
|
359
348
|
conn.disconnect(evt?.reason);
|
|
360
349
|
},
|
|
361
|
-
onError: (error: any, ws: any) => {},
|
|
350
|
+
onError: (error: any, ws: any) => { },
|
|
362
351
|
};
|
|
363
352
|
}
|
|
364
353
|
|
package/src/actor/router.ts
CHANGED
|
@@ -4,8 +4,10 @@ import {
|
|
|
4
4
|
type ActionOutput,
|
|
5
5
|
type ConnsMessageOpts,
|
|
6
6
|
handleAction,
|
|
7
|
+
handleQueueSend,
|
|
7
8
|
handleRawRequest,
|
|
8
9
|
} from "@/actor/router-endpoints";
|
|
10
|
+
|
|
9
11
|
import {
|
|
10
12
|
PATH_CONNECT,
|
|
11
13
|
PATH_INSPECTOR_CONNECT,
|
|
@@ -17,6 +19,9 @@ import {
|
|
|
17
19
|
loggerMiddleware,
|
|
18
20
|
} from "@/common/router";
|
|
19
21
|
import { noopNext } from "@/common/utils";
|
|
22
|
+
import { inspectorLogger } from "@/inspector/log";
|
|
23
|
+
import { timingSafeEqual } from "@/utils/crypto";
|
|
24
|
+
import { getNodeEnv } from "@/utils/env-vars";
|
|
20
25
|
|
|
21
26
|
import type { RegistryConfig } from "@/registry/config";
|
|
22
27
|
import { type GetUpgradeWebSocket, VERSION } from "@/utils";
|
|
@@ -158,12 +163,184 @@ export function createActorRouter(
|
|
|
158
163
|
);
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
// Inspector HTTP endpoints for agent-based debugging
|
|
167
|
+
if (config.inspector.enabled) {
|
|
168
|
+
// Auth middleware for inspector routes
|
|
169
|
+
const inspectorAuth = async (c: any): Promise<Response | undefined> => {
|
|
170
|
+
if (getNodeEnv() === "development" && !config.inspector.token()) {
|
|
171
|
+
inspectorLogger().warn({
|
|
172
|
+
msg: "RIVET_INSPECTOR_TOKEN is not set, skipping inspector auth in development mode",
|
|
173
|
+
});
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const userToken = c.req.header("Authorization")?.replace("Bearer ", "");
|
|
178
|
+
if (!userToken) {
|
|
179
|
+
return c.text("Unauthorized", 401);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const inspectorToken = config.inspector.token();
|
|
183
|
+
if (!inspectorToken) {
|
|
184
|
+
return c.text("Unauthorized", 401);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!timingSafeEqual(userToken, inspectorToken)) {
|
|
188
|
+
return c.text("Unauthorized", 401);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return undefined;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
router.get("/inspector/state", async (c) => {
|
|
195
|
+
const authResponse = await inspectorAuth(c);
|
|
196
|
+
if (authResponse) return authResponse;
|
|
197
|
+
|
|
198
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
199
|
+
const isStateEnabled = actor.inspector.isStateEnabled();
|
|
200
|
+
const state = isStateEnabled ? actor.inspector.getStateJson() : undefined;
|
|
201
|
+
return c.json({ state, isStateEnabled });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
router.patch("/inspector/state", async (c) => {
|
|
205
|
+
const authResponse = await inspectorAuth(c);
|
|
206
|
+
if (authResponse) return authResponse;
|
|
207
|
+
|
|
208
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
209
|
+
const body = await c.req.json<{ state: unknown }>();
|
|
210
|
+
await actor.inspector.setStateJson(body.state);
|
|
211
|
+
return c.json({ ok: true });
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
router.get("/inspector/connections", async (c) => {
|
|
215
|
+
const authResponse = await inspectorAuth(c);
|
|
216
|
+
if (authResponse) return authResponse;
|
|
217
|
+
|
|
218
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
219
|
+
const connections = actor.inspector.getConnectionsJson();
|
|
220
|
+
return c.json({ connections });
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
router.get("/inspector/rpcs", async (c) => {
|
|
224
|
+
const authResponse = await inspectorAuth(c);
|
|
225
|
+
if (authResponse) return authResponse;
|
|
226
|
+
|
|
227
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
228
|
+
const rpcs = actor.inspector.getRpcs();
|
|
229
|
+
return c.json({ rpcs });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
router.post("/inspector/action/:name", async (c) => {
|
|
233
|
+
const authResponse = await inspectorAuth(c);
|
|
234
|
+
if (authResponse) return authResponse;
|
|
235
|
+
|
|
236
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
237
|
+
const name = c.req.param("name");
|
|
238
|
+
const body = await c.req.json<{ args: unknown[] }>();
|
|
239
|
+
const output = await actor.inspector.executeActionJson(
|
|
240
|
+
name,
|
|
241
|
+
body.args ?? [],
|
|
242
|
+
);
|
|
243
|
+
return c.json({ output });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
router.get("/inspector/queue", async (c) => {
|
|
247
|
+
const authResponse = await inspectorAuth(c);
|
|
248
|
+
if (authResponse) return authResponse;
|
|
249
|
+
|
|
250
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
251
|
+
const limit = parseInt(c.req.query("limit") ?? "50", 10);
|
|
252
|
+
const status = await actor.inspector.getQueueStatusJson(limit);
|
|
253
|
+
return c.json(status);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
router.get("/inspector/traces", async (c) => {
|
|
257
|
+
const authResponse = await inspectorAuth(c);
|
|
258
|
+
if (authResponse) return authResponse;
|
|
259
|
+
|
|
260
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
261
|
+
const startMs = parseInt(c.req.query("startMs") ?? "0", 10);
|
|
262
|
+
const endMs = parseInt(
|
|
263
|
+
c.req.query("endMs") ?? String(Date.now()),
|
|
264
|
+
10,
|
|
265
|
+
);
|
|
266
|
+
const limit = parseInt(c.req.query("limit") ?? "1000", 10);
|
|
267
|
+
|
|
268
|
+
await actor.traces.flush();
|
|
269
|
+
const result = await actor.inspector.getTracesJson({
|
|
270
|
+
startMs,
|
|
271
|
+
endMs,
|
|
272
|
+
limit,
|
|
273
|
+
});
|
|
274
|
+
return c.json(result);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
router.get("/inspector/workflow-history", async (c) => {
|
|
278
|
+
const authResponse = await inspectorAuth(c);
|
|
279
|
+
if (authResponse) return authResponse;
|
|
280
|
+
|
|
281
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
282
|
+
const result = actor.inspector.getWorkflowHistoryJson();
|
|
283
|
+
return c.json(result);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
router.get("/inspector/summary", async (c) => {
|
|
287
|
+
const authResponse = await inspectorAuth(c);
|
|
288
|
+
if (authResponse) return authResponse;
|
|
289
|
+
|
|
290
|
+
const actor = await actorDriver.loadActor(c.env.actorId);
|
|
291
|
+
|
|
292
|
+
const isStateEnabled = actor.inspector.isStateEnabled();
|
|
293
|
+
const isDatabaseEnabled = actor.inspector.isDatabaseEnabled();
|
|
294
|
+
const isWorkflowEnabled = actor.inspector.isWorkflowEnabled();
|
|
295
|
+
|
|
296
|
+
const state = isStateEnabled
|
|
297
|
+
? actor.inspector.getStateJson()
|
|
298
|
+
: undefined;
|
|
299
|
+
const connections = actor.inspector.getConnectionsJson();
|
|
300
|
+
const rpcs = actor.inspector.getRpcs();
|
|
301
|
+
const queueSize = actor.inspector.getQueueSize();
|
|
302
|
+
const workflowHistory = actor.inspector.getWorkflowHistory();
|
|
303
|
+
|
|
304
|
+
// Convert BigInt values in workflow history to numbers for JSON serialization.
|
|
305
|
+
const bigIntReplacer = (_key: string, value: unknown) =>
|
|
306
|
+
typeof value === "bigint" ? Number(value) : value;
|
|
307
|
+
const safeWorkflowHistory = workflowHistory
|
|
308
|
+
? JSON.parse(JSON.stringify(workflowHistory, bigIntReplacer))
|
|
309
|
+
: null;
|
|
310
|
+
|
|
311
|
+
return c.json({
|
|
312
|
+
state,
|
|
313
|
+
connections,
|
|
314
|
+
rpcs,
|
|
315
|
+
queueSize,
|
|
316
|
+
isStateEnabled,
|
|
317
|
+
isDatabaseEnabled,
|
|
318
|
+
isWorkflowEnabled,
|
|
319
|
+
workflowHistory: safeWorkflowHistory,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
161
324
|
router.post("/action/:action", async (c) => {
|
|
162
325
|
const actionName = c.req.param("action");
|
|
163
326
|
|
|
164
327
|
return handleAction(c, config, actorDriver, actionName, c.env.actorId);
|
|
165
328
|
});
|
|
166
329
|
|
|
330
|
+
router.post("/queue", async (c) => {
|
|
331
|
+
return handleQueueSend(c, config, actorDriver, c.env.actorId);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
router.post("/queue/:name", async (c) => {
|
|
335
|
+
return handleQueueSend(
|
|
336
|
+
c,
|
|
337
|
+
config,
|
|
338
|
+
actorDriver,
|
|
339
|
+
c.env.actorId,
|
|
340
|
+
c.req.param("name"),
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
|
|
167
344
|
router.all("/request/*", async (c) => {
|
|
168
345
|
// TODO: This is not a clean way of doing this since `/http/` might exist mid-path
|
|
169
346
|
// Strip the /http prefix from the URL to get the original path
|