rivetkit 2.0.3 → 2.0.4
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-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
- package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
- package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
- package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
- package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
- package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
- package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
- package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
- package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
- package/dist/tsup/chunk-HI3HWJRC.js +20 -0
- package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
- package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
- package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
- package/dist/tsup/chunk-LV2S3OU3.js +250 -0
- package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
- package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
- package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
- package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
- package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
- package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
- package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
- package/dist/tsup/chunk-TQ62L3X7.js +325 -0
- package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
- package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
- package/dist/tsup/chunk-XJQHKJ4P.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-BI-6UIBJ.d.ts} +196 -226
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
- 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 +155 -1363
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
- package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
- package/dist/tsup/driver-test-suite/mod.js +876 -2084
- 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-BTe_Rsdn.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.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 +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/package.json +4 -4
- 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 +97 -35
- 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 +41 -38
- package/src/actor/router.ts +20 -18
- 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 +86 -60
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- 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 +13 -10
- 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 +33 -20
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +31 -8
- 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 +277 -1657
- 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 +57 -24
- package/src/registry/run-config.ts +31 -33
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +72 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +43 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +274 -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/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/test-inline-client-driver.ts +0 -402
- 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
|
|
@@ -370,8 +375,9 @@ export async function handleSseConnect(
|
|
|
370
375
|
|
|
371
376
|
// Handle stream abort (when client closes the connection)
|
|
372
377
|
stream.onAbort(async () => {
|
|
378
|
+
const rLog = actor?.rLog ?? loggerWithoutContext();
|
|
373
379
|
try {
|
|
374
|
-
|
|
380
|
+
rLog.debug("sse stream aborted");
|
|
375
381
|
|
|
376
382
|
// Cleanup
|
|
377
383
|
if (connId) {
|
|
@@ -385,7 +391,7 @@ export async function handleSseConnect(
|
|
|
385
391
|
|
|
386
392
|
abortResolver.resolve(undefined);
|
|
387
393
|
} catch (error) {
|
|
388
|
-
|
|
394
|
+
rLog.error({ msg: "error closing sse connection", error });
|
|
389
395
|
abortResolver.resolve(undefined);
|
|
390
396
|
}
|
|
391
397
|
});
|
|
@@ -398,7 +404,7 @@ export async function handleSseConnect(
|
|
|
398
404
|
// Wait until connection aborted
|
|
399
405
|
await abortResolver.promise;
|
|
400
406
|
} catch (error) {
|
|
401
|
-
|
|
407
|
+
loggerWithoutContext().error({ msg: "error in sse connection", error });
|
|
402
408
|
|
|
403
409
|
// Cleanup on error
|
|
404
410
|
if (connId !== undefined) {
|
|
@@ -430,8 +436,6 @@ export async function handleAction(
|
|
|
430
436
|
const encoding = getRequestEncoding(c.req);
|
|
431
437
|
const parameters = getRequestConnParams(c.req);
|
|
432
438
|
|
|
433
|
-
logger().debug("handling action", { actionName, encoding });
|
|
434
|
-
|
|
435
439
|
// Validate incoming request
|
|
436
440
|
const arrayBuffer = await c.req.arrayBuffer();
|
|
437
441
|
const request = deserializeWithEncoding(
|
|
@@ -448,6 +452,8 @@ export async function handleAction(
|
|
|
448
452
|
try {
|
|
449
453
|
actor = await actorDriver.loadActor(actorId);
|
|
450
454
|
|
|
455
|
+
actor.rLog.debug({ msg: "handling action", actionName, encoding });
|
|
456
|
+
|
|
451
457
|
// Create conn
|
|
452
458
|
const connState = await actor.prepareConn(parameters, c.req.raw);
|
|
453
459
|
conn = await actor.createConn(
|
|
@@ -544,8 +550,9 @@ export async function handleRawWebSocketHandler(
|
|
|
544
550
|
// Extract the path after prefix and preserve query parameters
|
|
545
551
|
// Use URL API for cleaner parsing
|
|
546
552
|
const url = new URL(path, "http://actor");
|
|
547
|
-
const pathname = url.pathname.replace(/^\/raw\/websocket
|
|
548
|
-
const normalizedPath =
|
|
553
|
+
const pathname = url.pathname.replace(/^\/raw\/websocket\/?/, "") || "/";
|
|
554
|
+
const normalizedPath =
|
|
555
|
+
(pathname.startsWith("/") ? pathname : "/" + pathname) + url.search;
|
|
549
556
|
|
|
550
557
|
let newRequest: Request;
|
|
551
558
|
if (req) {
|
|
@@ -556,15 +563,18 @@ export async function handleRawWebSocketHandler(
|
|
|
556
563
|
});
|
|
557
564
|
}
|
|
558
565
|
|
|
559
|
-
|
|
566
|
+
actor.rLog.debug({
|
|
567
|
+
msg: "rewriting websocket url",
|
|
560
568
|
from: path,
|
|
561
569
|
to: newRequest.url,
|
|
570
|
+
pathname: url.pathname,
|
|
571
|
+
search: url.search,
|
|
572
|
+
normalizedPath,
|
|
562
573
|
});
|
|
563
574
|
|
|
564
575
|
// Call the actor's onWebSocket handler with the adapted WebSocket
|
|
565
576
|
actor.handleWebSocket(adapter, {
|
|
566
577
|
request: newRequest,
|
|
567
|
-
auth: authData,
|
|
568
578
|
});
|
|
569
579
|
},
|
|
570
580
|
onMessage: (event: any, ws: any) => {
|
|
@@ -606,20 +616,16 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
|
|
|
606
616
|
return result.data;
|
|
607
617
|
}
|
|
608
618
|
|
|
609
|
-
export function getRequestExposeInternalError(
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
return param === "true";
|
|
619
|
+
export function getRequestExposeInternalError(_req: Request): boolean {
|
|
620
|
+
// Unipmlemented
|
|
621
|
+
return false;
|
|
616
622
|
}
|
|
617
623
|
|
|
618
624
|
export function getRequestQuery(c: HonoContext): unknown {
|
|
619
625
|
// Get query parameters for actor lookup
|
|
620
626
|
const queryParam = c.req.header(HEADER_ACTOR_QUERY);
|
|
621
627
|
if (!queryParam) {
|
|
622
|
-
|
|
628
|
+
loggerWithoutContext().error({ msg: "missing query parameter" });
|
|
623
629
|
throw new errors.InvalidRequest("missing query");
|
|
624
630
|
}
|
|
625
631
|
|
|
@@ -628,7 +634,7 @@ export function getRequestQuery(c: HonoContext): unknown {
|
|
|
628
634
|
const parsed = JSON.parse(queryParam);
|
|
629
635
|
return parsed;
|
|
630
636
|
} catch (error) {
|
|
631
|
-
|
|
637
|
+
loggerWithoutContext().error({ msg: "invalid query json", error });
|
|
632
638
|
throw new errors.InvalidQueryJSON(error);
|
|
633
639
|
}
|
|
634
640
|
}
|
|
@@ -637,9 +643,6 @@ export const HEADER_ACTOR_QUERY = "X-RivetKit-Query";
|
|
|
637
643
|
|
|
638
644
|
export const HEADER_ENCODING = "X-RivetKit-Encoding";
|
|
639
645
|
|
|
640
|
-
// Internal header
|
|
641
|
-
export const HEADER_EXPOSE_INTERNAL_ERROR = "X-RivetKit-Expose-Internal-Error";
|
|
642
|
-
|
|
643
646
|
// 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
647
|
export const HEADER_CONN_PARAMS = "X-RivetKit-Conn-Params";
|
|
645
648
|
|
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(
|
|
@@ -176,7 +177,8 @@ export function createActorRouter(
|
|
|
176
177
|
body: c.req.raw.body,
|
|
177
178
|
});
|
|
178
179
|
|
|
179
|
-
|
|
180
|
+
loggerWithoutContext().debug({
|
|
181
|
+
msg: "rewriting http url",
|
|
180
182
|
from: c.req.url,
|
|
181
183
|
to: correctedRequest.url,
|
|
182
184
|
});
|
|
@@ -212,7 +214,8 @@ export function createActorRouter(
|
|
|
212
214
|
const url = new URL(c.req.url);
|
|
213
215
|
const pathWithQuery = c.req.path + url.search;
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
loggerWithoutContext().debug({
|
|
218
|
+
msg: "actor router raw websocket",
|
|
216
219
|
path: c.req.path,
|
|
217
220
|
url: c.req.url,
|
|
218
221
|
search: url.search,
|
|
@@ -239,25 +242,24 @@ export function createActorRouter(
|
|
|
239
242
|
router.route(
|
|
240
243
|
"/inspect",
|
|
241
244
|
new Hono<ActorInspectorRouterEnv & { Bindings: ActorRouterBindings }>()
|
|
242
|
-
.use(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
.use(
|
|
246
|
+
cors(runConfig.inspector.cors),
|
|
247
|
+
secureInspector(runConfig),
|
|
248
|
+
async (c, next) => {
|
|
249
|
+
const inspector = (await actorDriver.loadActor(c.env.actorId))
|
|
250
|
+
.inspector;
|
|
251
|
+
invariant(inspector, "inspector not supported on this platform");
|
|
252
|
+
|
|
253
|
+
c.set("inspector", inspector);
|
|
254
|
+
return next();
|
|
255
|
+
},
|
|
256
|
+
)
|
|
250
257
|
.route("/", createActorInspectorRouter()),
|
|
251
258
|
);
|
|
252
259
|
}
|
|
253
260
|
|
|
254
261
|
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
|
-
);
|
|
262
|
+
router.onError(handleRouteError);
|
|
261
263
|
|
|
262
264
|
return router;
|
|
263
265
|
}
|
|
@@ -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>
|