rivetkit 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/schemas/actor-persist/v1.ts +21 -24
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/tsup/actor/errors.cjs +10 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +17 -4
- package/dist/tsup/actor/errors.d.ts +17 -4
- package/dist/tsup/actor/errors.js +11 -3
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-2MD57QF4.js} +119 -115
- package/dist/tsup/chunk-2MD57QF4.js.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-5QGQK44L.cjs} +103 -44
- package/dist/tsup/chunk-5QGQK44L.cjs.map +1 -0
- package/dist/tsup/chunk-5YTI25C3.cjs +250 -0
- package/dist/tsup/chunk-5YTI25C3.cjs.map +1 -0
- package/dist/tsup/chunk-B2QGJGZQ.js +338 -0
- package/dist/tsup/chunk-B2QGJGZQ.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-CFFKMUYH.js} +61 -22
- package/dist/tsup/chunk-CFFKMUYH.js.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-CKA54YQN.js} +15 -8
- package/dist/tsup/chunk-CKA54YQN.js.map +1 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs +20 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-FGFT4FVX.cjs} +12 -27
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +1 -0
- package/dist/tsup/chunk-I5VTWPHW.js +20 -0
- package/dist/tsup/chunk-I5VTWPHW.js.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-IRMBWX36.cjs} +146 -142
- package/dist/tsup/chunk-IRMBWX36.cjs.map +1 -0
- package/dist/tsup/chunk-L7QRXNWP.js +6562 -0
- package/dist/tsup/chunk-L7QRXNWP.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LZIBTLEY.cjs} +20 -13
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +1 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs +6562 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-PG3K2LI7.js} +3 -5
- package/dist/tsup/chunk-PG3K2LI7.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-PHSQJ6QI.cjs} +3 -5
- package/dist/tsup/chunk-PHSQJ6QI.cjs.map +1 -0
- package/dist/tsup/chunk-RM2SVURR.cjs +338 -0
- package/dist/tsup/chunk-RM2SVURR.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-WADSS5X4.cjs} +66 -27
- package/dist/tsup/chunk-WADSS5X4.cjs.map +1 -0
- package/dist/tsup/chunk-WNGOBAA7.js +250 -0
- package/dist/tsup/chunk-WNGOBAA7.js.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-YPZFLUO6.js} +103 -44
- package/dist/tsup/chunk-YPZFLUO6.js.map +1 -0
- package/dist/tsup/{chunk-6PDXBYI5.js → chunk-YW6Y6VNE.js} +8 -23
- package/dist/tsup/chunk-YW6Y6VNE.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +7 -13
- package/dist/tsup/client/mod.d.ts +7 -13
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +23 -17
- package/dist/tsup/common/log.d.ts +23 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
- package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
- package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BvE-Oq7t.d.ts} +215 -234
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-DTzmWwU5.d.cts} +215 -234
- package/dist/tsup/driver-helpers/mod.cjs +6 -9
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +5 -6
- package/dist/tsup/driver-helpers/mod.d.ts +5 -6
- package/dist/tsup/driver-helpers/mod.js +6 -9
- package/dist/tsup/driver-test-suite/mod.cjs +615 -1357
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +12 -6
- package/dist/tsup/driver-test-suite/mod.d.ts +12 -6
- package/dist/tsup/driver-test-suite/mod.js +1334 -2076
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -8
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +3 -3
- package/dist/tsup/inspector/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.js +8 -10
- package/dist/tsup/mod.cjs +9 -15
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +47 -42
- package/dist/tsup/mod.d.ts +47 -42
- package/dist/tsup/mod.js +10 -16
- package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-CctffZNL.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-DFm1BglJ.d.ts} +2 -3
- package/dist/tsup/test/mod.cjs +10 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +9 -13
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +5 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +19 -2
- package/dist/tsup/utils.d.ts +19 -2
- package/dist/tsup/utils.js +4 -2
- package/package.json +6 -6
- package/src/actor/action.ts +1 -5
- package/src/actor/config.ts +27 -295
- package/src/actor/connection.ts +9 -12
- package/src/actor/context.ts +1 -4
- package/src/actor/definition.ts +7 -11
- package/src/actor/errors.ts +98 -36
- package/src/actor/generic-conn-driver.ts +28 -16
- package/src/actor/instance.ts +177 -133
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +0 -5
- package/src/actor/protocol/old.ts +42 -26
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +47 -39
- package/src/actor/router.ts +22 -19
- package/src/actor/unstable-react.ts +1 -1
- package/src/actor/utils.ts +6 -2
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +152 -91
- package/src/client/actor-handle.ts +85 -25
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +29 -98
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +1 -0
- package/src/client/log.ts +2 -4
- package/src/client/mod.ts +16 -12
- package/src/client/raw-utils.ts +82 -25
- package/src/client/utils.ts +5 -3
- package/src/common/fake-event-source.ts +10 -9
- package/src/common/inline-websocket-adapter2.ts +39 -30
- package/src/common/log.ts +176 -101
- package/src/common/logfmt.ts +21 -30
- package/src/common/router.ts +12 -19
- package/src/common/utils.ts +27 -13
- package/src/common/websocket.ts +0 -1
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +87 -61
- package/src/driver-test-suite/test-inline-client-driver.ts +441 -255
- package/src/driver-test-suite/tests/actor-error-handling.ts +4 -12
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +2 -1
- package/src/driver-test-suite/tests/manager-driver.ts +5 -3
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/request-access.ts +112 -126
- package/src/driver-test-suite/utils.ts +10 -6
- package/src/drivers/default.ts +7 -4
- package/src/drivers/engine/actor-driver.ts +22 -13
- package/src/drivers/engine/config.ts +2 -10
- package/src/drivers/engine/kv.ts +1 -1
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +2 -3
- package/src/drivers/file-system/actor.ts +1 -1
- package/src/drivers/file-system/global-state.ts +36 -21
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +33 -15
- package/src/inspector/config.ts +9 -4
- package/src/inspector/log.ts +1 -1
- package/src/inspector/manager.ts +2 -2
- package/src/inspector/utils.ts +1 -1
- package/src/manager/driver.ts +10 -2
- package/src/manager/hono-websocket-adapter.ts +21 -12
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +378 -1390
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +0 -2
- package/src/registry/config.ts +1 -1
- package/src/registry/log.ts +2 -4
- package/src/registry/mod.ts +63 -34
- package/src/registry/run-config.ts +39 -26
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +74 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +64 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +46 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +275 -0
- package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
- package/src/serde.ts +8 -2
- package/src/test/log.ts +1 -3
- package/src/test/mod.ts +17 -16
- package/src/utils.ts +53 -0
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/src/client/http-client-driver.ts +0 -326
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/manager/auth.ts +0 -121
- /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
package/src/actor/log.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import { getLogger } from "@/common
|
|
1
|
+
import { getLogger } from "@/common/log";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
/** Logger used for logs from the actor instance itself. */
|
|
7
|
-
export const ACTOR_LOGGER_NAME = "actor";
|
|
8
|
-
|
|
9
|
-
export function logger() {
|
|
10
|
-
return getLogger(RUNTIME_LOGGER_NAME);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function instanceLogger() {
|
|
14
|
-
return getLogger(ACTOR_LOGGER_NAME);
|
|
3
|
+
/** Prever to use ActorInstance.rlog child logger. This does not provide context in the log, should only be used as a last resort if you cannot pass the actor's child logger. */
|
|
4
|
+
export function loggerWithoutContext() {
|
|
5
|
+
return getLogger("actor-runtime");
|
|
15
6
|
}
|
package/src/actor/mod.ts
CHANGED
|
@@ -14,7 +14,6 @@ export function actor<
|
|
|
14
14
|
TConnState,
|
|
15
15
|
TVars,
|
|
16
16
|
TInput,
|
|
17
|
-
TAuthData,
|
|
18
17
|
TDatabase extends AnyDatabaseProvider,
|
|
19
18
|
TActions extends Actions<
|
|
20
19
|
TState,
|
|
@@ -22,7 +21,6 @@ export function actor<
|
|
|
22
21
|
TConnState,
|
|
23
22
|
TVars,
|
|
24
23
|
TInput,
|
|
25
|
-
TAuthData,
|
|
26
24
|
TDatabase
|
|
27
25
|
>,
|
|
28
26
|
>(
|
|
@@ -32,7 +30,6 @@ export function actor<
|
|
|
32
30
|
TConnState,
|
|
33
31
|
TVars,
|
|
34
32
|
TInput,
|
|
35
|
-
TAuthData,
|
|
36
33
|
TDatabase,
|
|
37
34
|
TActions
|
|
38
35
|
>,
|
|
@@ -42,7 +39,6 @@ export function actor<
|
|
|
42
39
|
TConnState,
|
|
43
40
|
TVars,
|
|
44
41
|
TInput,
|
|
45
|
-
TAuthData,
|
|
46
42
|
TDatabase,
|
|
47
43
|
TActions
|
|
48
44
|
> {
|
|
@@ -52,7 +48,6 @@ export function actor<
|
|
|
52
48
|
TConnState,
|
|
53
49
|
TVars,
|
|
54
50
|
TInput,
|
|
55
|
-
TAuthData,
|
|
56
51
|
TDatabase
|
|
57
52
|
>;
|
|
58
53
|
return new ActorDefinition(config);
|
|
@@ -18,7 +18,6 @@ import { assertUnreachable, bufferToArrayBuffer } from "../../utils";
|
|
|
18
18
|
import { ActionContext } from "../action";
|
|
19
19
|
import type { Conn } from "../connection";
|
|
20
20
|
import type { ActorInstance } from "../instance";
|
|
21
|
-
import { logger } from "../log";
|
|
22
21
|
|
|
23
22
|
export const TransportSchema = z.enum(["websocket", "sse"]);
|
|
24
23
|
|
|
@@ -75,8 +74,17 @@ export async function parseMessage(
|
|
|
75
74
|
throw new errors.MessageTooLong();
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
//
|
|
79
|
-
|
|
77
|
+
// Convert value
|
|
78
|
+
let buffer = await inputDataToBuffer(value);
|
|
79
|
+
|
|
80
|
+
// HACK: For some reason, the output buffer needs to be cloned when using BARE encoding
|
|
81
|
+
//
|
|
82
|
+
// THis is likely because the input data is of type `Buffer` and there is an inconsistency in implementation that I am not aware of
|
|
83
|
+
if (buffer instanceof Buffer) {
|
|
84
|
+
buffer = new Uint8Array(buffer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Deserialize message
|
|
80
88
|
return deserializeWithEncoding(opts.encoding, buffer, TO_SERVER_VERSIONED);
|
|
81
89
|
}
|
|
82
90
|
|
|
@@ -86,21 +94,20 @@ export interface ProcessMessageHandler<
|
|
|
86
94
|
CS,
|
|
87
95
|
V,
|
|
88
96
|
I,
|
|
89
|
-
AD,
|
|
90
97
|
DB extends AnyDatabaseProvider,
|
|
91
98
|
> {
|
|
92
99
|
onExecuteAction?: (
|
|
93
|
-
ctx: ActionContext<S, CP, CS, V, I,
|
|
100
|
+
ctx: ActionContext<S, CP, CS, V, I, DB>,
|
|
94
101
|
name: string,
|
|
95
102
|
args: unknown[],
|
|
96
103
|
) => Promise<unknown>;
|
|
97
104
|
onSubscribe?: (
|
|
98
105
|
eventName: string,
|
|
99
|
-
conn: Conn<S, CP, CS, V, I,
|
|
106
|
+
conn: Conn<S, CP, CS, V, I, DB>,
|
|
100
107
|
) => Promise<void>;
|
|
101
108
|
onUnsubscribe?: (
|
|
102
109
|
eventName: string,
|
|
103
|
-
conn: Conn<S, CP, CS, V, I,
|
|
110
|
+
conn: Conn<S, CP, CS, V, I, DB>,
|
|
104
111
|
) => Promise<void>;
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -110,13 +117,12 @@ export async function processMessage<
|
|
|
110
117
|
CS,
|
|
111
118
|
V,
|
|
112
119
|
I,
|
|
113
|
-
AD,
|
|
114
120
|
DB extends AnyDatabaseProvider,
|
|
115
121
|
>(
|
|
116
122
|
message: protocol.ToServer,
|
|
117
|
-
actor: ActorInstance<S, CP, CS, V, I,
|
|
118
|
-
conn: Conn<S, CP, CS, V, I,
|
|
119
|
-
handler: ProcessMessageHandler<S, CP, CS, V, I,
|
|
123
|
+
actor: ActorInstance<S, CP, CS, V, I, DB>,
|
|
124
|
+
conn: Conn<S, CP, CS, V, I, DB>,
|
|
125
|
+
handler: ProcessMessageHandler<S, CP, CS, V, I, DB>,
|
|
120
126
|
) {
|
|
121
127
|
let actionId: bigint | undefined;
|
|
122
128
|
let actionName: string | undefined;
|
|
@@ -134,12 +140,13 @@ export async function processMessage<
|
|
|
134
140
|
actionName = name;
|
|
135
141
|
const args = cbor.decode(new Uint8Array(argsRaw));
|
|
136
142
|
|
|
137
|
-
|
|
143
|
+
actor.rLog.debug({
|
|
144
|
+
msg: "processing action request",
|
|
138
145
|
actionId: id,
|
|
139
146
|
actionName: name,
|
|
140
147
|
});
|
|
141
148
|
|
|
142
|
-
const ctx = new ActionContext<S, CP, CS, V, I,
|
|
149
|
+
const ctx = new ActionContext<S, CP, CS, V, I, DB>(
|
|
143
150
|
actor.actorContext,
|
|
144
151
|
conn,
|
|
145
152
|
);
|
|
@@ -148,7 +155,8 @@ export async function processMessage<
|
|
|
148
155
|
// This will wait for async actions to complete
|
|
149
156
|
const output = await handler.onExecuteAction(ctx, name, args);
|
|
150
157
|
|
|
151
|
-
|
|
158
|
+
actor.rLog.debug({
|
|
159
|
+
msg: "sending action response",
|
|
152
160
|
actionId: id,
|
|
153
161
|
actionName: name,
|
|
154
162
|
outputType: typeof output,
|
|
@@ -171,7 +179,7 @@ export async function processMessage<
|
|
|
171
179
|
),
|
|
172
180
|
);
|
|
173
181
|
|
|
174
|
-
|
|
182
|
+
actor.rLog.debug({ msg: "action response sent", id, name: name });
|
|
175
183
|
} else if (message.body.tag === "SubscriptionRequest") {
|
|
176
184
|
// Subscription request
|
|
177
185
|
|
|
@@ -183,7 +191,8 @@ export async function processMessage<
|
|
|
183
191
|
}
|
|
184
192
|
|
|
185
193
|
const { eventName, subscribe } = message.body.val;
|
|
186
|
-
|
|
194
|
+
actor.rLog.debug({
|
|
195
|
+
msg: "processing subscription request",
|
|
187
196
|
eventName,
|
|
188
197
|
subscribe,
|
|
189
198
|
});
|
|
@@ -194,7 +203,8 @@ export async function processMessage<
|
|
|
194
203
|
await handler.onUnsubscribe(eventName, conn);
|
|
195
204
|
}
|
|
196
205
|
|
|
197
|
-
|
|
206
|
+
actor.rLog.debug({
|
|
207
|
+
msg: "subscription request completed",
|
|
198
208
|
eventName,
|
|
199
209
|
subscribe,
|
|
200
210
|
});
|
|
@@ -202,13 +212,18 @@ export async function processMessage<
|
|
|
202
212
|
assertUnreachable(message.body);
|
|
203
213
|
}
|
|
204
214
|
} catch (error) {
|
|
205
|
-
const { code, message, metadata } = deconstructError(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
const { group, code, message, metadata } = deconstructError(
|
|
216
|
+
error,
|
|
217
|
+
actor.rLog,
|
|
218
|
+
{
|
|
219
|
+
connectionId: conn.id,
|
|
220
|
+
actionId,
|
|
221
|
+
actionName,
|
|
222
|
+
},
|
|
223
|
+
);
|
|
210
224
|
|
|
211
|
-
|
|
225
|
+
actor.rLog.debug({
|
|
226
|
+
msg: "sending error response",
|
|
212
227
|
actionId,
|
|
213
228
|
actionName,
|
|
214
229
|
code,
|
|
@@ -222,6 +237,7 @@ export async function processMessage<
|
|
|
222
237
|
body: {
|
|
223
238
|
tag: "Error",
|
|
224
239
|
val: {
|
|
240
|
+
group,
|
|
225
241
|
code,
|
|
226
242
|
message,
|
|
227
243
|
metadata: bufferToArrayBuffer(cbor.encode(metadata)),
|
|
@@ -233,7 +249,7 @@ export async function processMessage<
|
|
|
233
249
|
),
|
|
234
250
|
);
|
|
235
251
|
|
|
236
|
-
|
|
252
|
+
actor.rLog.debug({ msg: "error response sent", actionId, actionName });
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
|
|
@@ -255,7 +271,7 @@ export async function processMessage<
|
|
|
255
271
|
//export async function deserialize(data: InputData, encoding: Encoding) {
|
|
256
272
|
// if (encoding === "json") {
|
|
257
273
|
// if (typeof data !== "string") {
|
|
258
|
-
//
|
|
274
|
+
// actor.rLog.warn("received non-string for json parse");
|
|
259
275
|
// throw new errors.MalformedMessage();
|
|
260
276
|
// } else {
|
|
261
277
|
// return JSON.parse(data);
|
|
@@ -272,7 +288,7 @@ export async function processMessage<
|
|
|
272
288
|
// ) {
|
|
273
289
|
// return cbor.decode(new Uint8Array(data));
|
|
274
290
|
// } else {
|
|
275
|
-
//
|
|
291
|
+
// actor.rLog.warn("received non-binary type for cbor parse");
|
|
276
292
|
// throw new errors.MalformedMessage();
|
|
277
293
|
// }
|
|
278
294
|
// } else {
|
|
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import * as errors from "@/actor/errors";
|
|
4
4
|
import type { VersionedDataHandler } from "@/common/versioned-data";
|
|
5
5
|
import { serializeWithEncoding } from "@/serde";
|
|
6
|
-
import {
|
|
6
|
+
import { loggerWithoutContext } from "../log";
|
|
7
7
|
import { assertUnreachable } from "../utils";
|
|
8
8
|
|
|
9
9
|
/** Data that can be deserialized. */
|
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
GenericSseDriverState,
|
|
39
39
|
GenericWebSocketDriverState,
|
|
40
40
|
} from "./generic-conn-driver";
|
|
41
|
-
import {
|
|
41
|
+
import { loggerWithoutContext } from "./log";
|
|
42
42
|
import { parseMessage } from "./protocol/old";
|
|
43
43
|
|
|
44
44
|
export interface ConnectWebSocketOpts {
|
|
@@ -137,7 +137,7 @@ export async function handleWebSocketConnect(
|
|
|
137
137
|
onOpen: (_evt: any, ws: WSContext) => {
|
|
138
138
|
const { code } = deconstructError(
|
|
139
139
|
error,
|
|
140
|
-
|
|
140
|
+
actor.rLog,
|
|
141
141
|
{
|
|
142
142
|
wsEvent: "open",
|
|
143
143
|
},
|
|
@@ -155,7 +155,7 @@ export async function handleWebSocketConnect(
|
|
|
155
155
|
|
|
156
156
|
return {
|
|
157
157
|
onOpen: (_evt: any, ws: WSContext) => {
|
|
158
|
-
|
|
158
|
+
actor.rLog.debug("websocket open");
|
|
159
159
|
|
|
160
160
|
// Run async operations in background
|
|
161
161
|
(async () => {
|
|
@@ -168,7 +168,8 @@ export async function handleWebSocketConnect(
|
|
|
168
168
|
const connGlobalState =
|
|
169
169
|
actorDriver.getGenericConnGlobalState(actorId);
|
|
170
170
|
connGlobalState.websockets.set(connId, ws);
|
|
171
|
-
|
|
171
|
+
actor.rLog.debug({
|
|
172
|
+
msg: "registered websocket for conn",
|
|
172
173
|
actorId,
|
|
173
174
|
totalCount: connGlobalState.websockets.size,
|
|
174
175
|
});
|
|
@@ -191,7 +192,7 @@ export async function handleWebSocketConnect(
|
|
|
191
192
|
|
|
192
193
|
const { code } = deconstructError(
|
|
193
194
|
error,
|
|
194
|
-
|
|
195
|
+
actor.rLog,
|
|
195
196
|
{
|
|
196
197
|
wsEvent: "open",
|
|
197
198
|
},
|
|
@@ -205,7 +206,7 @@ export async function handleWebSocketConnect(
|
|
|
205
206
|
// Handle message asynchronously
|
|
206
207
|
handlersPromise
|
|
207
208
|
.then(({ conn, actor }) => {
|
|
208
|
-
|
|
209
|
+
actor.rLog.debug({ msg: "received message" });
|
|
209
210
|
|
|
210
211
|
const value = evt.data.valueOf() as InputData;
|
|
211
212
|
parseMessage(value, {
|
|
@@ -216,7 +217,7 @@ export async function handleWebSocketConnect(
|
|
|
216
217
|
actor.processMessage(message, conn).catch((error) => {
|
|
217
218
|
const { code } = deconstructError(
|
|
218
219
|
error,
|
|
219
|
-
|
|
220
|
+
actor.rLog,
|
|
220
221
|
{
|
|
221
222
|
wsEvent: "message",
|
|
222
223
|
},
|
|
@@ -228,7 +229,7 @@ export async function handleWebSocketConnect(
|
|
|
228
229
|
.catch((error) => {
|
|
229
230
|
const { code } = deconstructError(
|
|
230
231
|
error,
|
|
231
|
-
|
|
232
|
+
actor.rLog,
|
|
232
233
|
{
|
|
233
234
|
wsEvent: "message",
|
|
234
235
|
},
|
|
@@ -240,7 +241,7 @@ export async function handleWebSocketConnect(
|
|
|
240
241
|
.catch((error) => {
|
|
241
242
|
const { code } = deconstructError(
|
|
242
243
|
error,
|
|
243
|
-
|
|
244
|
+
actor.rLog,
|
|
244
245
|
{
|
|
245
246
|
wsEvent: "message",
|
|
246
247
|
},
|
|
@@ -258,13 +259,15 @@ export async function handleWebSocketConnect(
|
|
|
258
259
|
ws: WSContext,
|
|
259
260
|
) => {
|
|
260
261
|
if (event.wasClean) {
|
|
261
|
-
|
|
262
|
+
actor.rLog.info({
|
|
263
|
+
msg: "websocket closed",
|
|
262
264
|
code: event.code,
|
|
263
265
|
reason: event.reason,
|
|
264
266
|
wasClean: event.wasClean,
|
|
265
267
|
});
|
|
266
268
|
} else {
|
|
267
|
-
|
|
269
|
+
actor.rLog.warn({
|
|
270
|
+
msg: "websocket closed",
|
|
268
271
|
code: event.code,
|
|
269
272
|
reason: event.reason,
|
|
270
273
|
wasClean: event.wasClean,
|
|
@@ -282,11 +285,13 @@ export async function handleWebSocketConnect(
|
|
|
282
285
|
actorDriver.getGenericConnGlobalState(actorId);
|
|
283
286
|
const didDelete = connGlobalState.websockets.delete(connId);
|
|
284
287
|
if (didDelete) {
|
|
285
|
-
|
|
288
|
+
actor.rLog.info({
|
|
289
|
+
msg: "removing websocket for conn",
|
|
286
290
|
totalCount: connGlobalState.websockets.size,
|
|
287
291
|
});
|
|
288
292
|
} else {
|
|
289
|
-
|
|
293
|
+
actor.rLog.warn({
|
|
294
|
+
msg: "websocket does not exist for conn",
|
|
290
295
|
actorId,
|
|
291
296
|
totalCount: connGlobalState.websockets.size,
|
|
292
297
|
});
|
|
@@ -297,7 +302,7 @@ export async function handleWebSocketConnect(
|
|
|
297
302
|
.catch((error) => {
|
|
298
303
|
deconstructError(
|
|
299
304
|
error,
|
|
300
|
-
|
|
305
|
+
actor.rLog,
|
|
301
306
|
{ wsEvent: "close" },
|
|
302
307
|
exposeInternalError,
|
|
303
308
|
);
|
|
@@ -306,11 +311,11 @@ export async function handleWebSocketConnect(
|
|
|
306
311
|
onError: (_error: unknown) => {
|
|
307
312
|
try {
|
|
308
313
|
// Actors don't need to know about this, since it's abstracted away
|
|
309
|
-
|
|
314
|
+
actor.rLog.warn({ msg: "websocket error" });
|
|
310
315
|
} catch (error) {
|
|
311
316
|
deconstructError(
|
|
312
317
|
error,
|
|
313
|
-
|
|
318
|
+
actor.rLog,
|
|
314
319
|
{ wsEvent: "error" },
|
|
315
320
|
exposeInternalError,
|
|
316
321
|
);
|
|
@@ -347,7 +352,7 @@ export async function handleSseConnect(
|
|
|
347
352
|
connToken = generateConnToken();
|
|
348
353
|
connState = await actor.prepareConn(parameters, c.req.raw);
|
|
349
354
|
|
|
350
|
-
|
|
355
|
+
actor.rLog.debug("sse open");
|
|
351
356
|
|
|
352
357
|
// Save stream
|
|
353
358
|
actorDriver
|
|
@@ -368,10 +373,16 @@ export async function handleSseConnect(
|
|
|
368
373
|
// Wait for close
|
|
369
374
|
const abortResolver = Promise.withResolvers();
|
|
370
375
|
|
|
376
|
+
// HACK: This is required so the abort handler below works
|
|
377
|
+
//
|
|
378
|
+
// See https://github.com/honojs/hono/issues/1770#issuecomment-2461966225
|
|
379
|
+
stream.onAbort(() => {});
|
|
380
|
+
|
|
371
381
|
// Handle stream abort (when client closes the connection)
|
|
372
|
-
|
|
382
|
+
c.req.raw.signal.addEventListener("abort", async () => {
|
|
383
|
+
const rLog = actor?.rLog ?? loggerWithoutContext();
|
|
373
384
|
try {
|
|
374
|
-
|
|
385
|
+
rLog.debug("sse stream aborted");
|
|
375
386
|
|
|
376
387
|
// Cleanup
|
|
377
388
|
if (connId) {
|
|
@@ -385,7 +396,7 @@ export async function handleSseConnect(
|
|
|
385
396
|
|
|
386
397
|
abortResolver.resolve(undefined);
|
|
387
398
|
} catch (error) {
|
|
388
|
-
|
|
399
|
+
rLog.error({ msg: "error closing sse connection", error });
|
|
389
400
|
abortResolver.resolve(undefined);
|
|
390
401
|
}
|
|
391
402
|
});
|
|
@@ -398,7 +409,7 @@ export async function handleSseConnect(
|
|
|
398
409
|
// Wait until connection aborted
|
|
399
410
|
await abortResolver.promise;
|
|
400
411
|
} catch (error) {
|
|
401
|
-
|
|
412
|
+
loggerWithoutContext().error({ msg: "error in sse connection", error });
|
|
402
413
|
|
|
403
414
|
// Cleanup on error
|
|
404
415
|
if (connId !== undefined) {
|
|
@@ -430,8 +441,6 @@ export async function handleAction(
|
|
|
430
441
|
const encoding = getRequestEncoding(c.req);
|
|
431
442
|
const parameters = getRequestConnParams(c.req);
|
|
432
443
|
|
|
433
|
-
logger().debug("handling action", { actionName, encoding });
|
|
434
|
-
|
|
435
444
|
// Validate incoming request
|
|
436
445
|
const arrayBuffer = await c.req.arrayBuffer();
|
|
437
446
|
const request = deserializeWithEncoding(
|
|
@@ -448,6 +457,8 @@ export async function handleAction(
|
|
|
448
457
|
try {
|
|
449
458
|
actor = await actorDriver.loadActor(actorId);
|
|
450
459
|
|
|
460
|
+
actor.rLog.debug({ msg: "handling action", actionName, encoding });
|
|
461
|
+
|
|
451
462
|
// Create conn
|
|
452
463
|
const connState = await actor.prepareConn(parameters, c.req.raw);
|
|
453
464
|
conn = await actor.createConn(
|
|
@@ -544,8 +555,9 @@ export async function handleRawWebSocketHandler(
|
|
|
544
555
|
// Extract the path after prefix and preserve query parameters
|
|
545
556
|
// Use URL API for cleaner parsing
|
|
546
557
|
const url = new URL(path, "http://actor");
|
|
547
|
-
const pathname = url.pathname.replace(/^\/raw\/websocket
|
|
548
|
-
const normalizedPath =
|
|
558
|
+
const pathname = url.pathname.replace(/^\/raw\/websocket\/?/, "") || "/";
|
|
559
|
+
const normalizedPath =
|
|
560
|
+
(pathname.startsWith("/") ? pathname : "/" + pathname) + url.search;
|
|
549
561
|
|
|
550
562
|
let newRequest: Request;
|
|
551
563
|
if (req) {
|
|
@@ -556,15 +568,18 @@ export async function handleRawWebSocketHandler(
|
|
|
556
568
|
});
|
|
557
569
|
}
|
|
558
570
|
|
|
559
|
-
|
|
571
|
+
actor.rLog.debug({
|
|
572
|
+
msg: "rewriting websocket url",
|
|
560
573
|
from: path,
|
|
561
574
|
to: newRequest.url,
|
|
575
|
+
pathname: url.pathname,
|
|
576
|
+
search: url.search,
|
|
577
|
+
normalizedPath,
|
|
562
578
|
});
|
|
563
579
|
|
|
564
580
|
// Call the actor's onWebSocket handler with the adapted WebSocket
|
|
565
581
|
actor.handleWebSocket(adapter, {
|
|
566
582
|
request: newRequest,
|
|
567
|
-
auth: authData,
|
|
568
583
|
});
|
|
569
584
|
},
|
|
570
585
|
onMessage: (event: any, ws: any) => {
|
|
@@ -606,20 +621,16 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
|
|
|
606
621
|
return result.data;
|
|
607
622
|
}
|
|
608
623
|
|
|
609
|
-
export function getRequestExposeInternalError(
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
return param === "true";
|
|
624
|
+
export function getRequestExposeInternalError(_req: Request): boolean {
|
|
625
|
+
// Unipmlemented
|
|
626
|
+
return false;
|
|
616
627
|
}
|
|
617
628
|
|
|
618
629
|
export function getRequestQuery(c: HonoContext): unknown {
|
|
619
630
|
// Get query parameters for actor lookup
|
|
620
631
|
const queryParam = c.req.header(HEADER_ACTOR_QUERY);
|
|
621
632
|
if (!queryParam) {
|
|
622
|
-
|
|
633
|
+
loggerWithoutContext().error({ msg: "missing query parameter" });
|
|
623
634
|
throw new errors.InvalidRequest("missing query");
|
|
624
635
|
}
|
|
625
636
|
|
|
@@ -628,7 +639,7 @@ export function getRequestQuery(c: HonoContext): unknown {
|
|
|
628
639
|
const parsed = JSON.parse(queryParam);
|
|
629
640
|
return parsed;
|
|
630
641
|
} catch (error) {
|
|
631
|
-
|
|
642
|
+
loggerWithoutContext().error({ msg: "invalid query json", error });
|
|
632
643
|
throw new errors.InvalidQueryJSON(error);
|
|
633
644
|
}
|
|
634
645
|
}
|
|
@@ -637,9 +648,6 @@ export const HEADER_ACTOR_QUERY = "X-RivetKit-Query";
|
|
|
637
648
|
|
|
638
649
|
export const HEADER_ENCODING = "X-RivetKit-Encoding";
|
|
639
650
|
|
|
640
|
-
// Internal header
|
|
641
|
-
export const HEADER_EXPOSE_INTERNAL_ERROR = "X-RivetKit-Expose-Internal-Error";
|
|
642
|
-
|
|
643
651
|
// IMPORTANT: Params must be in headers or in an E2EE part of the request (i.e. NOT the URL or query string) in order to ensure that tokens can be securely passed in params.
|
|
644
652
|
export const HEADER_CONN_PARAMS = "X-RivetKit-Conn-Params";
|
|
645
653
|
|
package/src/actor/router.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Hono, type Context as HonoContext } from "hono";
|
|
2
|
+
import { cors } from "hono/cors";
|
|
2
3
|
import invariant from "invariant";
|
|
3
4
|
import { EncodingSchema } from "@/actor/protocol/serde";
|
|
4
5
|
import {
|
|
@@ -34,7 +35,7 @@ import { secureInspector } from "@/inspector/utils";
|
|
|
34
35
|
import type { RunConfig } from "@/registry/run-config";
|
|
35
36
|
import type { ActorDriver } from "./driver";
|
|
36
37
|
import { InternalError } from "./errors";
|
|
37
|
-
import {
|
|
38
|
+
import { loggerWithoutContext } from "./log";
|
|
38
39
|
|
|
39
40
|
export const PATH_CONNECT_WEBSOCKET = "/connect/websocket";
|
|
40
41
|
export const PATH_RAW_WEBSOCKET_PREFIX = "/raw/websocket/";
|
|
@@ -64,7 +65,7 @@ export function createActorRouter(
|
|
|
64
65
|
): ActorRouter {
|
|
65
66
|
const router = new Hono<{ Bindings: ActorRouterBindings }>({ strict: false });
|
|
66
67
|
|
|
67
|
-
router.use("*", loggerMiddleware(
|
|
68
|
+
router.use("*", loggerMiddleware(loggerWithoutContext()));
|
|
68
69
|
|
|
69
70
|
router.get("/", (c) => {
|
|
70
71
|
return c.text(
|
|
@@ -174,9 +175,11 @@ export function createActorRouter(
|
|
|
174
175
|
method: c.req.method,
|
|
175
176
|
headers: c.req.raw.headers,
|
|
176
177
|
body: c.req.raw.body,
|
|
177
|
-
|
|
178
|
+
duplex: "half",
|
|
179
|
+
} as RequestInit);
|
|
178
180
|
|
|
179
|
-
|
|
181
|
+
loggerWithoutContext().debug({
|
|
182
|
+
msg: "rewriting http url",
|
|
180
183
|
from: c.req.url,
|
|
181
184
|
to: correctedRequest.url,
|
|
182
185
|
});
|
|
@@ -212,7 +215,8 @@ export function createActorRouter(
|
|
|
212
215
|
const url = new URL(c.req.url);
|
|
213
216
|
const pathWithQuery = c.req.path + url.search;
|
|
214
217
|
|
|
215
|
-
|
|
218
|
+
loggerWithoutContext().debug({
|
|
219
|
+
msg: "actor router raw websocket",
|
|
216
220
|
path: c.req.path,
|
|
217
221
|
url: c.req.url,
|
|
218
222
|
search: url.search,
|
|
@@ -239,25 +243,24 @@ export function createActorRouter(
|
|
|
239
243
|
router.route(
|
|
240
244
|
"/inspect",
|
|
241
245
|
new Hono<ActorInspectorRouterEnv & { Bindings: ActorRouterBindings }>()
|
|
242
|
-
.use(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
.use(
|
|
247
|
+
cors(runConfig.inspector.cors),
|
|
248
|
+
secureInspector(runConfig),
|
|
249
|
+
async (c, next) => {
|
|
250
|
+
const inspector = (await actorDriver.loadActor(c.env.actorId))
|
|
251
|
+
.inspector;
|
|
252
|
+
invariant(inspector, "inspector not supported on this platform");
|
|
253
|
+
|
|
254
|
+
c.set("inspector", inspector);
|
|
255
|
+
return next();
|
|
256
|
+
},
|
|
257
|
+
)
|
|
250
258
|
.route("/", createActorInspectorRouter()),
|
|
251
259
|
);
|
|
252
260
|
}
|
|
253
261
|
|
|
254
262
|
router.notFound(handleRouteNotFound);
|
|
255
|
-
router.onError(
|
|
256
|
-
handleRouteError.bind(undefined, {
|
|
257
|
-
// All headers to this endpoint are considered secure, so we can enable the expose internal error header for requests from the internal client
|
|
258
|
-
enableExposeInternalError: true,
|
|
259
|
-
}),
|
|
260
|
-
);
|
|
263
|
+
router.onError(handleRouteError);
|
|
261
264
|
|
|
262
265
|
return router;
|
|
263
266
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// *
|
|
10
10
|
// * Supports rendering React elements as action responses.
|
|
11
11
|
// *
|
|
12
|
-
// * @see [Documentation](https://rivet.
|
|
12
|
+
// * @see [Documentation](https://rivet.dev/docs/client/react)
|
|
13
13
|
// * @experimental
|
|
14
14
|
// */
|
|
15
15
|
//export class RscActor<
|
package/src/actor/utils.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import * as errors from "./errors";
|
|
2
|
-
import {
|
|
2
|
+
import { loggerWithoutContext } from "./log";
|
|
3
3
|
|
|
4
4
|
export function assertUnreachable(x: never): never {
|
|
5
|
-
|
|
5
|
+
loggerWithoutContext().error({
|
|
6
|
+
msg: "unreachable",
|
|
7
|
+
value: `${x}`,
|
|
8
|
+
stack: new Error().stack,
|
|
9
|
+
});
|
|
6
10
|
throw new errors.Unreachable(x);
|
|
7
11
|
}
|
|
8
12
|
|
|
@@ -21,7 +21,7 @@ export type ActorActionFunction<
|
|
|
21
21
|
*/
|
|
22
22
|
export type ActorDefinitionActions<AD extends AnyActorDefinition> =
|
|
23
23
|
// biome-ignore lint/suspicious/noExplicitAny: safe to use any here
|
|
24
|
-
AD extends ActorDefinition<any, any, any, any, any, any,
|
|
24
|
+
AD extends ActorDefinition<any, any, any, any, any, any, infer R>
|
|
25
25
|
? {
|
|
26
26
|
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return
|
|
27
27
|
? ActorActionFunction<Args, Return>
|