rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.4e59a38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client.d.ts +561 -89
- package/dist/browser/client.js +1063 -430
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +22 -2
- package/dist/browser/inspector/client.js +1036 -232
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -74
- package/dist/tsup/actor/errors.d.ts +1 -74
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +2218 -2082
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +556 -85
- package/dist/tsup/agent-os/index.d.ts +556 -85
- package/dist/tsup/agent-os/index.js +2220 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-3GC3EP6D.cjs} +18 -10
- package/dist/tsup/chunk-3GC3EP6D.cjs.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
- package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-62LSMTP2.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-62LSMTP2.cjs.map} +1 -1
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-7IVUT2JT.js} +12 -4
- package/dist/tsup/chunk-7IVUT2JT.js.map +1 -0
- package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-GEYQLGXC.cjs} +925 -328
- package/dist/tsup/chunk-GEYQLGXC.cjs.map +1 -0
- package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-GMN45CQ6.cjs} +10 -10
- package/dist/tsup/chunk-GMN45CQ6.cjs.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-I336PMWT.cjs} +44 -9
- package/dist/tsup/chunk-I336PMWT.cjs.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-IB73AMGJ.js} +42 -7
- package/dist/tsup/chunk-IB73AMGJ.js.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-ITWJ6Y7G.js} +2 -2
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-W54QCENI.js → chunk-KTNBYGRU.js} +134 -20
- package/dist/tsup/chunk-KTNBYGRU.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
- package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-OUDV3ITX.cjs} +138 -24
- package/dist/tsup/chunk-OUDV3ITX.cjs.map +1 -0
- package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-PRXTIERO.cjs} +90 -65
- package/dist/tsup/chunk-PRXTIERO.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-WRZEVVLL.js} +6 -6
- package/dist/tsup/chunk-WRZEVVLL.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-XAIMHUPG.js} +780 -183
- package/dist/tsup/chunk-XAIMHUPG.js.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-XZ62SWSC.js} +83 -58
- package/dist/tsup/chunk-XZ62SWSC.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -9
- package/dist/tsup/client/mod.d.ts +8 -9
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
- package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
- package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
- package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
- package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
- package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +151 -79
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +2 -2
- package/dist/tsup/db/drizzle.d.ts +2 -2
- package/dist/tsup/db/drizzle.js +151 -79
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +79 -24
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +78 -23
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +37 -15
- package/dist/tsup/inspector/mod.d.ts +37 -15
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +240 -0
- package/dist/tsup/inspector-tab/mod.d.ts +240 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +1078 -479
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -6
- package/dist/tsup/mod.d.ts +5 -6
- package/dist/tsup/mod.js +996 -397
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- 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 +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
- package/dist/tsup/utils-CqDnC_PS.d.ts +104 -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/dist/tsup/workflow/mod.cjs +386 -322
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -9
- package/dist/tsup/workflow/mod.d.ts +8 -9
- package/dist/tsup/workflow/mod.js +363 -299
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +35 -14
- package/src/actor/config.ts +188 -59
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +70 -7
- package/src/actor/instance/mod.ts +39 -56
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/client/actor-common.ts +88 -62
- package/src/client/actor-conn.ts +58 -63
- package/src/client/actor-handle.ts +125 -71
- package/src/client/actor-query.ts +5 -5
- package/src/client/config.ts +3 -3
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +10 -10
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +34 -10
- package/src/common/actor-router-consts.ts +7 -4
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +176 -67
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/config.ts +16 -5
- package/src/common/database/mod.test.ts +83 -16
- package/src/common/database/mod.ts +86 -30
- package/src/common/database/native-database.test.ts +35 -22
- package/src/common/database/native-database.ts +26 -10
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +15 -8
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +10 -202
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +173 -96
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +76 -73
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +6 -9
- package/src/engine-client/actor-websocket-client.ts +14 -13
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +3 -4
- package/src/engine-client/mod.ts +17 -10
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +66 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector-tab/mod.ts +300 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +46 -20
- package/src/registry/index.ts +364 -87
- package/src/registry/napi-runtime.ts +97 -8
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +592 -343
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +85 -6
- package/src/registry/wasm-runtime.ts +72 -3
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +19 -8
- package/src/test/mod.ts +11 -8
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +37 -0
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +703 -240
- package/src/workflow/driver.ts +23 -12
- package/src/workflow/inspector.ts +12 -3
- package/src/workflow/mod.ts +37 -23
- package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
- package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
- package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
- package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
- package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
- package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-W54QCENI.js.map +0 -1
- package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
- package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
- package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-ITWJ6Y7G.js.map} +0 -0
package/src/actor/config.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Client } from "@/client/client";
|
|
3
3
|
import type {
|
|
4
4
|
AnyDatabaseProvider,
|
|
5
5
|
InferDatabaseClient,
|
|
6
|
-
RawDatabaseClient,
|
|
7
|
-
DrizzleDatabaseClient,
|
|
8
|
-
NativeDatabaseProvider,
|
|
9
6
|
} from "@/common/database/config";
|
|
10
|
-
import type {
|
|
7
|
+
import type { UniversalWebSocket } from "@/common/websocket-interface";
|
|
11
8
|
import type { Registry } from "@/registry";
|
|
12
9
|
import type { BaseActorDefinition } from "./definition";
|
|
13
10
|
import type {
|
|
14
11
|
EventSchemaConfig,
|
|
15
|
-
PrimitiveSchema,
|
|
16
|
-
QueueSchemaConfig,
|
|
17
|
-
} from "./schema";
|
|
18
|
-
import type {
|
|
19
|
-
InferEventArgs,
|
|
20
12
|
InferQueueCompleteMap,
|
|
21
13
|
InferSchemaMap,
|
|
14
|
+
PrimitiveSchema,
|
|
15
|
+
QueueSchemaConfig,
|
|
22
16
|
} from "./schema";
|
|
23
17
|
|
|
24
18
|
export const DEFAULT_SLEEP_GRACE_PERIOD = 15_000;
|
|
@@ -26,6 +20,7 @@ export const DEFAULT_SLEEP_GRACE_PERIOD = 15_000;
|
|
|
26
20
|
export const ACTOR_CONTEXT_INTERNAL_SYMBOL = Symbol(
|
|
27
21
|
"rivetkit.actor_context_internal",
|
|
28
22
|
);
|
|
23
|
+
export const RAW_STATE_SYMBOL = Symbol("rivetkit.raw_state");
|
|
29
24
|
export const CONN_DRIVER_SYMBOL = Symbol("rivetkit.conn_driver");
|
|
30
25
|
export const CONN_STATE_MANAGER_SYMBOL = Symbol("rivetkit.conn_state_manager");
|
|
31
26
|
|
|
@@ -67,6 +62,10 @@ type ActorKvListOptions<
|
|
|
67
62
|
|
|
68
63
|
type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
|
|
69
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
|
|
67
|
+
* or actor state instead.
|
|
68
|
+
*/
|
|
70
69
|
export interface ActorKv {
|
|
71
70
|
get<T extends ActorKvValueType = "text">(
|
|
72
71
|
key: Uint8Array | string,
|
|
@@ -97,7 +96,10 @@ export interface ActorKv {
|
|
|
97
96
|
end: Uint8Array | string,
|
|
98
97
|
options?: ActorKvListOptions<T, K>,
|
|
99
98
|
): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
|
|
100
|
-
list<
|
|
99
|
+
list<
|
|
100
|
+
T extends ActorKvValueType = "text",
|
|
101
|
+
K extends ActorKvKeyType = "text",
|
|
102
|
+
>(
|
|
101
103
|
prefix: Uint8Array | string,
|
|
102
104
|
options?: ActorKvListOptions<T, K>,
|
|
103
105
|
): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
|
|
@@ -118,7 +120,8 @@ export type QueueMessageOf<Name extends string, Body> = {
|
|
|
118
120
|
[key: string]: unknown;
|
|
119
121
|
};
|
|
120
122
|
|
|
121
|
-
export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues &
|
|
123
|
+
export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues &
|
|
124
|
+
string;
|
|
122
125
|
export type QueueFilterName<TQueues extends QueueSchemaConfig> =
|
|
123
126
|
keyof TQueues extends never ? string : QueueName<TQueues>;
|
|
124
127
|
|
|
@@ -228,7 +231,9 @@ export interface QueueIterOptions<
|
|
|
228
231
|
completable?: TCompletable;
|
|
229
232
|
}
|
|
230
233
|
|
|
231
|
-
export interface ActorQueue<
|
|
234
|
+
export interface ActorQueue<
|
|
235
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
236
|
+
> {
|
|
232
237
|
send<TName extends QueueFilterName<TQueues>>(
|
|
233
238
|
name: TName,
|
|
234
239
|
body: QueueMessageForName<TQueues, TName>["body"],
|
|
@@ -236,15 +241,11 @@ export interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, ne
|
|
|
236
241
|
next<
|
|
237
242
|
const TName extends QueueFilterName<TQueues>,
|
|
238
243
|
const TCompletable extends boolean = false,
|
|
239
|
-
>(
|
|
240
|
-
opts?: QueueNextOptions<TName, TCompletable>,
|
|
241
|
-
): Promise<any>;
|
|
244
|
+
>(opts?: QueueNextOptions<TName, TCompletable>): Promise<any>;
|
|
242
245
|
nextBatch<
|
|
243
246
|
const TName extends QueueFilterName<TQueues>,
|
|
244
247
|
const TCompletable extends boolean = false,
|
|
245
|
-
>(
|
|
246
|
-
opts?: QueueNextBatchOptions<TName, TCompletable>,
|
|
247
|
-
): Promise<any[]>;
|
|
248
|
+
>(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<any[]>;
|
|
248
249
|
waitForNames<
|
|
249
250
|
const TName extends QueueFilterName<TQueues>,
|
|
250
251
|
const TCompletable extends boolean = false,
|
|
@@ -260,33 +261,27 @@ export interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, ne
|
|
|
260
261
|
tryNext<
|
|
261
262
|
const TName extends QueueFilterName<TQueues>,
|
|
262
263
|
const TCompletable extends boolean = false,
|
|
263
|
-
>(
|
|
264
|
-
opts?: QueueTryNextOptions<TName, TCompletable>,
|
|
265
|
-
): Promise<any>;
|
|
264
|
+
>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<any>;
|
|
266
265
|
tryNextBatch<
|
|
267
266
|
const TName extends QueueFilterName<TQueues>,
|
|
268
267
|
const TCompletable extends boolean = false,
|
|
269
|
-
>(
|
|
270
|
-
opts?: QueueTryNextBatchOptions<TName, TCompletable>,
|
|
271
|
-
): Promise<any[]>;
|
|
268
|
+
>(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<any[]>;
|
|
272
269
|
iter<
|
|
273
270
|
const TName extends QueueFilterName<TQueues>,
|
|
274
271
|
const TCompletable extends boolean = false,
|
|
275
|
-
>(
|
|
276
|
-
opts?: QueueIterOptions<TName, TCompletable>,
|
|
277
|
-
): AsyncIterable<any>;
|
|
272
|
+
>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
|
|
278
273
|
[key: string]: any;
|
|
279
274
|
}
|
|
280
275
|
|
|
281
276
|
export interface Conn<
|
|
282
|
-
|
|
277
|
+
_TState = unknown,
|
|
283
278
|
TConnParams = unknown,
|
|
284
279
|
TConnState = unknown,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
280
|
+
_TVars = unknown,
|
|
281
|
+
_TInput = unknown,
|
|
282
|
+
_TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider,
|
|
283
|
+
_TEvents extends EventSchemaConfig = Record<never, never>,
|
|
284
|
+
_TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
290
285
|
> {
|
|
291
286
|
id: string;
|
|
292
287
|
params: TConnParams;
|
|
@@ -310,8 +305,14 @@ export interface ActorContext<
|
|
|
310
305
|
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
311
306
|
> {
|
|
312
307
|
[ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
|
|
308
|
+
/** Returns the raw unwrapped state without the write-through proxy. */
|
|
309
|
+
[RAW_STATE_SYMBOL](): TState;
|
|
313
310
|
state: TState;
|
|
314
311
|
vars: TVars;
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
|
|
314
|
+
* or actor state instead.
|
|
315
|
+
*/
|
|
315
316
|
readonly kv: ActorKv;
|
|
316
317
|
readonly db: InferDatabaseClient<TDatabase>;
|
|
317
318
|
readonly schedule: ActorSchedule;
|
|
@@ -320,7 +321,21 @@ export interface ActorContext<
|
|
|
320
321
|
readonly name: string;
|
|
321
322
|
readonly key: string[];
|
|
322
323
|
readonly region: string;
|
|
323
|
-
|
|
324
|
+
/** Provisions credentials for the experimental local actor Unix socket API. */
|
|
325
|
+
actorUds(): Promise<{ path: string; token: string }>;
|
|
326
|
+
readonly conns: Map<
|
|
327
|
+
string,
|
|
328
|
+
Conn<
|
|
329
|
+
TState,
|
|
330
|
+
TConnParams,
|
|
331
|
+
TConnState,
|
|
332
|
+
TVars,
|
|
333
|
+
TInput,
|
|
334
|
+
TDatabase,
|
|
335
|
+
TEvents,
|
|
336
|
+
TQueues
|
|
337
|
+
>
|
|
338
|
+
>;
|
|
324
339
|
readonly log: ActorLogger;
|
|
325
340
|
readonly abortSignal: AbortSignal;
|
|
326
341
|
readonly aborted: boolean;
|
|
@@ -651,7 +666,9 @@ export type WebSocketContext<
|
|
|
651
666
|
TQueues
|
|
652
667
|
>;
|
|
653
668
|
|
|
654
|
-
export type ActorContextOf<
|
|
669
|
+
export type ActorContextOf<
|
|
670
|
+
AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, any>,
|
|
671
|
+
> =
|
|
655
672
|
AD extends BaseActorDefinition<
|
|
656
673
|
infer TState,
|
|
657
674
|
infer TConnParams,
|
|
@@ -728,6 +745,88 @@ const RunInspectorConfigSchema = z
|
|
|
728
745
|
})
|
|
729
746
|
.optional();
|
|
730
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Built-in inspector tabs the dashboard ships. Used to validate
|
|
750
|
+
* `hidden: true` entries and reject custom-tab ids that collide with
|
|
751
|
+
* a built-in.
|
|
752
|
+
*/
|
|
753
|
+
export const BUILTIN_INSPECTOR_TAB_IDS = [
|
|
754
|
+
"workflow",
|
|
755
|
+
"database",
|
|
756
|
+
"state",
|
|
757
|
+
"queue",
|
|
758
|
+
"connections",
|
|
759
|
+
"console",
|
|
760
|
+
] as const;
|
|
761
|
+
|
|
762
|
+
export const BuiltinInspectorTabIdSchema = z.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
763
|
+
|
|
764
|
+
// Custom tab id grammar — mirrored in Rust at
|
|
765
|
+
// `rivetkit-rust/packages/rivetkit-core/src/inspector/tabs.rs`. Slashes are
|
|
766
|
+
// forbidden because the runtime splits `/inspector/custom-tabs/<id>/<rest>`
|
|
767
|
+
// on the first `/`.
|
|
768
|
+
const CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
769
|
+
|
|
770
|
+
export const CustomInspectorTabEntrySchema = z
|
|
771
|
+
.object({
|
|
772
|
+
id: z
|
|
773
|
+
.string()
|
|
774
|
+
.regex(
|
|
775
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
776
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash",
|
|
777
|
+
),
|
|
778
|
+
label: z.string().min(1),
|
|
779
|
+
source: z.string().min(1),
|
|
780
|
+
/**
|
|
781
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
782
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
783
|
+
*/
|
|
784
|
+
icon: z.string().min(1).optional(),
|
|
785
|
+
hidden: z.literal(false).optional(),
|
|
786
|
+
})
|
|
787
|
+
.strict();
|
|
788
|
+
|
|
789
|
+
export const HideInspectorTabEntrySchema = z
|
|
790
|
+
.object({
|
|
791
|
+
id: BuiltinInspectorTabIdSchema,
|
|
792
|
+
hidden: z.literal(true),
|
|
793
|
+
})
|
|
794
|
+
.strict();
|
|
795
|
+
|
|
796
|
+
export const InspectorTabEntrySchema = z.union([
|
|
797
|
+
CustomInspectorTabEntrySchema,
|
|
798
|
+
HideInspectorTabEntrySchema,
|
|
799
|
+
]);
|
|
800
|
+
|
|
801
|
+
export const ActorInspectorConfigSchema = z
|
|
802
|
+
.object({
|
|
803
|
+
tabs: z.array(InspectorTabEntrySchema).default(() => []),
|
|
804
|
+
})
|
|
805
|
+
.strict()
|
|
806
|
+
.refine(
|
|
807
|
+
(data) => {
|
|
808
|
+
const ids = data.tabs.map((t) => t.id);
|
|
809
|
+
return new Set(ids).size === ids.length;
|
|
810
|
+
},
|
|
811
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] },
|
|
812
|
+
)
|
|
813
|
+
.refine(
|
|
814
|
+
(data) => {
|
|
815
|
+
// A custom entry's id must not collide with a built-in id.
|
|
816
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
817
|
+
return data.tabs.every(
|
|
818
|
+
(t) => t.hidden === true || !builtinSet.has(t.id as any),
|
|
819
|
+
);
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
message:
|
|
823
|
+
"Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
824
|
+
path: ["tabs"],
|
|
825
|
+
},
|
|
826
|
+
);
|
|
827
|
+
|
|
828
|
+
export type ActorInspectorConfig = z.input<typeof ActorInspectorConfigSchema>;
|
|
829
|
+
|
|
731
830
|
// Schema for run handler with metadata
|
|
732
831
|
export const RunConfigSchema = z.object({
|
|
733
832
|
/** Display name for the actor in the Inspector UI. */
|
|
@@ -784,6 +883,8 @@ interface RunFunctionConfig {
|
|
|
784
883
|
icon?: string;
|
|
785
884
|
inspector?: RunInspectorConfig;
|
|
786
885
|
inspectorFactory?: (actor: unknown) => RunInspectorConfig | undefined;
|
|
886
|
+
/** Release any per-actor inspector state held for this actor id. */
|
|
887
|
+
disposeInspector?: (actorId: string) => void;
|
|
787
888
|
}
|
|
788
889
|
|
|
789
890
|
type RunFunctionWithConfig = ((...args: any[]) => any) & {
|
|
@@ -834,6 +935,18 @@ export function getRunInspectorConfig(
|
|
|
834
935
|
return run.inspector;
|
|
835
936
|
}
|
|
836
937
|
|
|
938
|
+
/** Release per-actor inspector state for a destroyed actor, if the run handler registered a disposer. */
|
|
939
|
+
export function disposeRunInspector(
|
|
940
|
+
run: ((...args: any[]) => any) | AnyRunConfig | undefined,
|
|
941
|
+
actorId: string,
|
|
942
|
+
): void {
|
|
943
|
+
if (!run || typeof run !== "function") {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
const config = (run as RunFunctionWithConfig)[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
947
|
+
config?.disposeInspector?.(actorId);
|
|
948
|
+
}
|
|
949
|
+
|
|
837
950
|
// This schema is used to validate the input at runtime. The generic types are defined below in `ActorConfig`.
|
|
838
951
|
//
|
|
839
952
|
// We don't use Zod generics with `z.custom` because:
|
|
@@ -944,6 +1057,7 @@ export const ActorConfigSchema = z
|
|
|
944
1057
|
db: z.any().optional(),
|
|
945
1058
|
createVars: zFunction().optional(),
|
|
946
1059
|
options: ActorOptionsSchema,
|
|
1060
|
+
inspector: ActorInspectorConfigSchema.optional(),
|
|
947
1061
|
})
|
|
948
1062
|
.strict()
|
|
949
1063
|
.refine(
|
|
@@ -979,9 +1093,9 @@ export const ActorConfigSchema = z
|
|
|
979
1093
|
// Data returned from this handler will be available on `c.state`.
|
|
980
1094
|
type CreateState<
|
|
981
1095
|
TState,
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1096
|
+
_TConnParams,
|
|
1097
|
+
_TConnState,
|
|
1098
|
+
_TVars,
|
|
985
1099
|
TInput,
|
|
986
1100
|
TDatabase extends AnyDatabaseProvider,
|
|
987
1101
|
TEvents extends EventSchemaConfig,
|
|
@@ -1001,6 +1115,7 @@ type CreateState<
|
|
|
1001
1115
|
// This must have only one or the other or else TState will not be able to be inferred
|
|
1002
1116
|
//
|
|
1003
1117
|
// Data returned from this handler will be available on `c.conn.state`.
|
|
1118
|
+
// The pending connection is not visible in `c.conns` until this succeeds.
|
|
1004
1119
|
type CreateConnState<
|
|
1005
1120
|
TState,
|
|
1006
1121
|
TConnParams,
|
|
@@ -1035,8 +1150,8 @@ type CreateConnState<
|
|
|
1035
1150
|
*/
|
|
1036
1151
|
type CreateVars<
|
|
1037
1152
|
TState,
|
|
1038
|
-
|
|
1039
|
-
|
|
1153
|
+
_TConnParams,
|
|
1154
|
+
_TConnState,
|
|
1040
1155
|
TVars,
|
|
1041
1156
|
TInput,
|
|
1042
1157
|
TDatabase extends AnyDatabaseProvider,
|
|
@@ -1227,7 +1342,7 @@ interface BaseActorConfig<
|
|
|
1227
1342
|
* shutdown window (`sleepGracePeriod`) cover deferred work.
|
|
1228
1343
|
*
|
|
1229
1344
|
* The handler receives an abort signal via `c.abortSignal` and a
|
|
1230
|
-
* `c.aborted` alias
|
|
1345
|
+
* `c.aborted` alias. Use these to gracefully exit when shutdown starts.
|
|
1231
1346
|
*
|
|
1232
1347
|
* If this handler exits, the actor will follow the normal idle sleep timeout
|
|
1233
1348
|
* once it becomes idle.
|
|
@@ -1292,10 +1407,11 @@ interface BaseActorConfig<
|
|
|
1292
1407
|
* Called before a client connects to the actor.
|
|
1293
1408
|
*
|
|
1294
1409
|
* Use this hook to determine if a connection should be accepted
|
|
1295
|
-
* and to
|
|
1410
|
+
* and to validate client-provided parameters. The pending connection
|
|
1411
|
+
* is not visible in `c.conns` while this hook runs.
|
|
1296
1412
|
*
|
|
1297
1413
|
* @param opts Connection parameters including client-provided data
|
|
1298
|
-
* @returns
|
|
1414
|
+
* @returns Void or a Promise.
|
|
1299
1415
|
* @throws Throw an error to reject the connection
|
|
1300
1416
|
*/
|
|
1301
1417
|
onBeforeConnect?: (
|
|
@@ -1314,7 +1430,8 @@ interface BaseActorConfig<
|
|
|
1314
1430
|
* Called when a client successfully connects to the actor.
|
|
1315
1431
|
*
|
|
1316
1432
|
* Use this hook to perform actions when a connection is established,
|
|
1317
|
-
* such as sending initial data or updating the actor's state.
|
|
1433
|
+
* such as sending initial data or updating the actor's state. The
|
|
1434
|
+
* connection is visible in `c.conns` before this hook runs.
|
|
1318
1435
|
*
|
|
1319
1436
|
* @param conn The connection object
|
|
1320
1437
|
* @returns Void or a Promise that resolves when connection handling is complete
|
|
@@ -1495,6 +1612,25 @@ export type ActorConfig<
|
|
|
1495
1612
|
TDatabase extends AnyDatabaseProvider,
|
|
1496
1613
|
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
1497
1614
|
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
1615
|
+
TActions extends Actions<
|
|
1616
|
+
TState,
|
|
1617
|
+
TConnParams,
|
|
1618
|
+
TConnState,
|
|
1619
|
+
TVars,
|
|
1620
|
+
TInput,
|
|
1621
|
+
TDatabase,
|
|
1622
|
+
TEvents,
|
|
1623
|
+
TQueues
|
|
1624
|
+
> = Actions<
|
|
1625
|
+
TState,
|
|
1626
|
+
TConnParams,
|
|
1627
|
+
TConnState,
|
|
1628
|
+
TVars,
|
|
1629
|
+
TInput,
|
|
1630
|
+
TDatabase,
|
|
1631
|
+
TEvents,
|
|
1632
|
+
TQueues
|
|
1633
|
+
>,
|
|
1498
1634
|
> = Omit<
|
|
1499
1635
|
z.infer<typeof ActorConfigSchema>,
|
|
1500
1636
|
| "actions"
|
|
@@ -1530,16 +1666,7 @@ export type ActorConfig<
|
|
|
1530
1666
|
TDatabase,
|
|
1531
1667
|
TEvents,
|
|
1532
1668
|
TQueues,
|
|
1533
|
-
|
|
1534
|
-
TState,
|
|
1535
|
-
TConnParams,
|
|
1536
|
-
TConnState,
|
|
1537
|
-
TVars,
|
|
1538
|
-
TInput,
|
|
1539
|
-
TDatabase,
|
|
1540
|
-
TEvents,
|
|
1541
|
-
TQueues
|
|
1542
|
-
>
|
|
1669
|
+
TActions
|
|
1543
1670
|
> &
|
|
1544
1671
|
CreateState<
|
|
1545
1672
|
TState,
|
|
@@ -1770,7 +1897,7 @@ export const DocActorOptionsSchema = z
|
|
|
1770
1897
|
.number()
|
|
1771
1898
|
.optional()
|
|
1772
1899
|
.describe(
|
|
1773
|
-
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler
|
|
1900
|
+
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`,
|
|
1774
1901
|
),
|
|
1775
1902
|
onDestroyTimeout: z
|
|
1776
1903
|
.number()
|
|
@@ -1875,7 +2002,7 @@ export const DocActorConfigSchema = z
|
|
|
1875
2002
|
.unknown()
|
|
1876
2003
|
.optional()
|
|
1877
2004
|
.describe(
|
|
1878
|
-
"Function to create connection state. Receives context and connection params. Cannot be used with connState.",
|
|
2005
|
+
"Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState.",
|
|
1879
2006
|
),
|
|
1880
2007
|
vars: z
|
|
1881
2008
|
.unknown()
|
|
@@ -1937,12 +2064,14 @@ export const DocActorConfigSchema = z
|
|
|
1937
2064
|
.unknown()
|
|
1938
2065
|
.optional()
|
|
1939
2066
|
.describe(
|
|
1940
|
-
"Called before a client connects. Throw an error to reject the connection.",
|
|
2067
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs.",
|
|
1941
2068
|
),
|
|
1942
2069
|
onConnect: z
|
|
1943
2070
|
.unknown()
|
|
1944
2071
|
.optional()
|
|
1945
|
-
.describe(
|
|
2072
|
+
.describe(
|
|
2073
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs.",
|
|
2074
|
+
),
|
|
1946
2075
|
onDisconnect: z
|
|
1947
2076
|
.unknown()
|
|
1948
2077
|
.optional()
|
|
@@ -16,10 +16,15 @@ import type {
|
|
|
16
16
|
WakeContext,
|
|
17
17
|
WebSocketContext,
|
|
18
18
|
} from "@/actor/config";
|
|
19
|
+
|
|
19
20
|
export type { ActorContextOf } from "@/actor/config";
|
|
20
|
-
|
|
21
|
-
import type {
|
|
21
|
+
|
|
22
|
+
import type {
|
|
23
|
+
AnyActorDefinition,
|
|
24
|
+
BaseActorDefinition,
|
|
25
|
+
} from "@/actor/definition";
|
|
22
26
|
import type { EventSchemaConfig, QueueSchemaConfig } from "@/actor/schema";
|
|
27
|
+
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
23
28
|
|
|
24
29
|
export type ActionContextOf<AD extends AnyActorDefinition> =
|
|
25
30
|
AD extends BaseActorDefinition<
|
package/src/actor/definition.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
1
2
|
import type { RegistryConfig } from "@/registry/config";
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type Actions,
|
|
5
|
+
type ActorConfig,
|
|
6
|
+
type ActorConfigInput,
|
|
7
|
+
ActorConfigSchema,
|
|
8
|
+
} from "./config";
|
|
3
9
|
import { loggerWithoutContext } from "./log";
|
|
4
|
-
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
5
10
|
import type { EventSchemaConfig, QueueSchemaConfig } from "./schema";
|
|
6
11
|
|
|
7
12
|
const warnedDeprecatedTimeoutKeys = new Set<string>();
|
|
@@ -28,7 +33,7 @@ export interface BaseActorDefinition<
|
|
|
28
33
|
DB extends AnyDatabaseProvider,
|
|
29
34
|
E extends EventSchemaConfig = Record<never, never>,
|
|
30
35
|
Q extends QueueSchemaConfig = Record<never, never>,
|
|
31
|
-
|
|
36
|
+
_R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<
|
|
32
37
|
S,
|
|
33
38
|
CP,
|
|
34
39
|
CS,
|
|
@@ -39,20 +44,12 @@ export interface BaseActorDefinition<
|
|
|
39
44
|
Q
|
|
40
45
|
>,
|
|
41
46
|
> {
|
|
42
|
-
readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
47
|
+
readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
export
|
|
46
|
-
any
|
|
47
|
-
|
|
48
|
-
any,
|
|
49
|
-
any,
|
|
50
|
-
any,
|
|
51
|
-
any,
|
|
52
|
-
any,
|
|
53
|
-
any,
|
|
54
|
-
any
|
|
55
|
-
>;
|
|
50
|
+
export interface AnyActorDefinition {
|
|
51
|
+
readonly config: any;
|
|
52
|
+
}
|
|
56
53
|
|
|
57
54
|
export type AnyStaticActorDefinition = ActorDefinition<
|
|
58
55
|
any,
|
|
@@ -87,13 +84,13 @@ export class ActorDefinition<
|
|
|
87
84
|
>,
|
|
88
85
|
> implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R>
|
|
89
86
|
{
|
|
90
|
-
#config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
87
|
+
#config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
|
|
91
88
|
|
|
92
|
-
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>) {
|
|
89
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>) {
|
|
93
90
|
this.#config = config;
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q> {
|
|
93
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R> {
|
|
97
94
|
return this.#config;
|
|
98
95
|
}
|
|
99
96
|
}
|
|
@@ -195,7 +192,8 @@ export function actor<
|
|
|
195
192
|
TInput,
|
|
196
193
|
TDatabase,
|
|
197
194
|
TEvents,
|
|
198
|
-
TQueues
|
|
195
|
+
TQueues,
|
|
196
|
+
TActions
|
|
199
197
|
>;
|
|
200
198
|
return new ActorDefinition(config);
|
|
201
199
|
}
|
package/src/actor/driver.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Context as HonoContext } from "hono";
|
|
2
2
|
import type { AnyClient } from "@/client/client";
|
|
3
|
-
import type { EngineControlClient } from "@/engine-client/driver";
|
|
4
|
-
import type { AnyActorInstance, AnyStaticActorInstance } from "./definition";
|
|
5
|
-
import type { RegistryConfig } from "@/registry/config";
|
|
6
3
|
import type {
|
|
7
4
|
DrizzleDatabaseClient,
|
|
8
5
|
NativeDatabaseProvider,
|
|
9
6
|
} from "@/common/database/config";
|
|
7
|
+
import type { EngineControlClient } from "@/engine-client/driver";
|
|
8
|
+
import type { RegistryConfig } from "@/registry/config";
|
|
9
|
+
import type { AnyActorInstance, AnyStaticActorInstance } from "./definition";
|
|
10
10
|
|
|
11
11
|
export type ActorDriverBuilder = (
|
|
12
12
|
config: RegistryConfig,
|