rivetkit 2.3.18 → 2.3.20
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 +754 -608
- package/dist/browser/client.js +184 -28
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +3 -1
- 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 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +36 -1
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +149 -3
- package/dist/tsup/agent-os/index.d.ts +149 -3
- package/dist/tsup/agent-os/index.js +36 -1
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-2IDK6NX3.cjs → chunk-2CE5UNWK.cjs} +13 -13
- package/dist/tsup/chunk-2CE5UNWK.cjs.map +1 -0
- package/dist/tsup/{chunk-IPXIZSE7.js → chunk-2NXLTFWI.js} +3 -3
- package/dist/tsup/{chunk-OKVVWOC3.cjs → chunk-3WS7Z64U.cjs} +3 -3
- package/dist/tsup/{chunk-OKVVWOC3.cjs.map → chunk-3WS7Z64U.cjs.map} +1 -1
- package/dist/tsup/{chunk-LAITPJRA.js → chunk-553CIQJY.js} +2 -2
- package/dist/tsup/{chunk-PXKNBNVU.js → chunk-5G2J26VM.js} +188 -31
- package/dist/tsup/chunk-5G2J26VM.js.map +1 -0
- package/dist/tsup/{chunk-IKZ6DJMP.cjs → chunk-76YTS32R.cjs} +4 -4
- package/dist/tsup/{chunk-IKZ6DJMP.cjs.map → chunk-76YTS32R.cjs.map} +1 -1
- package/dist/tsup/{chunk-NRIRV3Z2.cjs → chunk-A36FMKOV.cjs} +352 -195
- package/dist/tsup/chunk-A36FMKOV.cjs.map +1 -0
- package/dist/tsup/{chunk-6W5VGLFT.js → chunk-CSOHAAZK.js} +33 -1
- package/dist/tsup/chunk-CSOHAAZK.js.map +1 -0
- package/dist/tsup/{chunk-T6JUXRNI.cjs → chunk-CVLNRT7O.cjs} +3 -3
- package/dist/tsup/{chunk-T6JUXRNI.cjs.map → chunk-CVLNRT7O.cjs.map} +1 -1
- package/dist/tsup/{chunk-7EPLADKM.js → chunk-DHWZTUKA.js} +7 -7
- package/dist/tsup/chunk-DHWZTUKA.js.map +1 -0
- package/dist/tsup/{chunk-4XECVATQ.js → chunk-DMQUERRN.js} +2 -2
- package/dist/tsup/{chunk-25Z2RK7C.cjs → chunk-IHKDFKM4.cjs} +3 -3
- package/dist/tsup/{chunk-25Z2RK7C.cjs.map → chunk-IHKDFKM4.cjs.map} +1 -1
- package/dist/tsup/{chunk-2JSYYH6P.cjs → chunk-JX2ITWAV.cjs} +13 -2
- package/dist/tsup/chunk-JX2ITWAV.cjs.map +1 -0
- package/dist/tsup/{chunk-4KGXFC6M.cjs → chunk-NWCAIWHL.cjs} +34 -2
- package/dist/tsup/chunk-NWCAIWHL.cjs.map +1 -0
- package/dist/tsup/{chunk-OUQUIBVW.js → chunk-P2OFXH4G.js} +12 -1
- package/dist/tsup/chunk-P2OFXH4G.js.map +1 -0
- package/dist/tsup/{chunk-ZRTESY7V.cjs → chunk-RSIOGT2U.cjs} +7 -7
- package/dist/tsup/{chunk-ZRTESY7V.cjs.map → chunk-RSIOGT2U.cjs.map} +1 -1
- package/dist/tsup/{chunk-QIFZELUQ.js → chunk-SNNVRHLX.js} +2 -2
- package/dist/tsup/{chunk-2MK75JFR.js → chunk-TZVAVPGJ.js} +4 -4
- package/dist/tsup/{chunk-TNSLNSQH.js → chunk-W2PXGWMR.js} +2 -2
- package/dist/tsup/{chunk-O7RSU3UC.cjs → chunk-WAISW7KR.cjs} +10 -10
- package/dist/tsup/{chunk-O7RSU3UC.cjs.map → chunk-WAISW7KR.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +5 -5
- package/dist/tsup/client/mod.d.ts +5 -5
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-Ug5M2MOr.d.ts → config-Be-VOHaX.d.ts} +155 -11
- package/dist/tsup/{config-gvHwMas-.d.cts → config-Ct5uXxXk.d.cts} +155 -11
- package/dist/tsup/{context-DererUCI.d.ts → context-CXLa0BIM.d.ts} +1 -1
- package/dist/tsup/{context-BSCBvbfM.d.cts → context-Cw-11Q-B.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.js +2 -2
- package/dist/tsup/db/mod.cjs +4 -4
- package/dist/tsup/db/mod.js +3 -3
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +3 -3
- package/dist/tsup/dynamic/mod.d.ts +3 -3
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/inspector/workflow.cjs +5 -5
- package/dist/tsup/inspector/workflow.js +4 -4
- package/dist/tsup/inspector-tab/mod.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.d.cts +4 -4
- package/dist/tsup/inspector-tab/mod.d.ts +4 -4
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +506 -319
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +381 -194
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/{utils-Bbz-3411.d.cts → utils-CNFeS-Dk.d.cts} +1 -1
- package/dist/tsup/{utils-vvJQyygr.d.ts → utils-DsoDinPz.d.cts} +9 -1
- package/dist/tsup/{utils-vvJQyygr.d.cts → utils-DsoDinPz.d.ts} +9 -1
- package/dist/tsup/{utils-BqdWVlzm.d.ts → utils-OQHBjfcM.d.ts} +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +2 -2
- package/dist/tsup/utils.d.ts +2 -2
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +33 -27
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +25 -19
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +10 -8
- package/src/actor/actions.ts +36 -0
- package/src/actor/config.ts +65 -0
- package/src/actor/definition.ts +6 -1
- package/src/actor/errors.ts +31 -0
- package/src/actor/mod.ts +5 -0
- package/src/actor/tracing.ts +28 -0
- package/src/client/actor-conn.ts +7 -0
- package/src/client/actor-handle.ts +57 -17
- package/src/client/client.ts +26 -6
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/queue.ts +3 -0
- package/src/client/raw-utils.ts +3 -0
- package/src/common/actor-router-consts.ts +3 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/otel-context.ts +99 -0
- package/src/common/utils.ts +1 -19
- package/src/engine-client/actor-http-client.ts +15 -0
- package/src/registry/index.ts +6 -0
- package/src/registry/napi-runtime.ts +155 -35
- package/src/registry/native.ts +295 -191
- package/src/registry/runtime.ts +74 -0
- package/src/registry/wasm-runtime.ts +40 -0
- package/src/workflow/driver.ts +20 -12
- package/dist/tsup/chunk-2IDK6NX3.cjs.map +0 -1
- package/dist/tsup/chunk-2JSYYH6P.cjs.map +0 -1
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +0 -1
- package/dist/tsup/chunk-6W5VGLFT.js.map +0 -1
- package/dist/tsup/chunk-7EPLADKM.js.map +0 -1
- package/dist/tsup/chunk-NRIRV3Z2.cjs.map +0 -1
- package/dist/tsup/chunk-OUQUIBVW.js.map +0 -1
- package/dist/tsup/chunk-PXKNBNVU.js.map +0 -1
- /package/dist/tsup/{chunk-IPXIZSE7.js.map → chunk-2NXLTFWI.js.map} +0 -0
- /package/dist/tsup/{chunk-LAITPJRA.js.map → chunk-553CIQJY.js.map} +0 -0
- /package/dist/tsup/{chunk-4XECVATQ.js.map → chunk-DMQUERRN.js.map} +0 -0
- /package/dist/tsup/{chunk-QIFZELUQ.js.map → chunk-SNNVRHLX.js.map} +0 -0
- /package/dist/tsup/{chunk-2MK75JFR.js.map → chunk-TZVAVPGJ.js.map} +0 -0
- /package/dist/tsup/{chunk-TNSLNSQH.js.map → chunk-W2PXGWMR.js.map} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import type {
|
|
2
3
|
ActorContext as NativeActorContext,
|
|
3
4
|
NapiActorFactory as NativeActorFactory,
|
|
@@ -7,6 +8,14 @@ import type {
|
|
|
7
8
|
HttpResponseBodyStream as NativeHttpResponseBodyStream,
|
|
8
9
|
WebSocket as NativeWebSocket,
|
|
9
10
|
} from "@rivetkit/rivetkit-napi";
|
|
11
|
+
import type { WorkflowSpan } from "@/actor/config";
|
|
12
|
+
import { encodeErrorForBridge } from "@/actor/errors";
|
|
13
|
+
import type { ActorInvocationTraceContext } from "@/common/actor-telemetry-context";
|
|
14
|
+
import {
|
|
15
|
+
readActiveTraceHeaders,
|
|
16
|
+
runWithActorInvocationSpan,
|
|
17
|
+
} from "@/common/otel-context";
|
|
18
|
+
import { logger } from "./log";
|
|
10
19
|
import type {
|
|
11
20
|
ActorContextHandle,
|
|
12
21
|
ActorFactoryHandle,
|
|
@@ -26,6 +35,7 @@ import type {
|
|
|
26
35
|
RuntimeKvEntry,
|
|
27
36
|
RuntimeKvListOptions,
|
|
28
37
|
RuntimeListenerConfig,
|
|
38
|
+
RuntimeOutboundCall,
|
|
29
39
|
RuntimeQueueEnqueueAndWaitOptions,
|
|
30
40
|
RuntimeQueueMessage,
|
|
31
41
|
RuntimeQueueNextBatchOptions,
|
|
@@ -65,6 +75,9 @@ type NapiSqlTransaction = Awaited<
|
|
|
65
75
|
type NapiActorStateTransaction = Awaited<
|
|
66
76
|
ReturnType<NativeActorContext["beginStateTransaction"]>
|
|
67
77
|
>;
|
|
78
|
+
type NapiQueueMessage = Awaited<
|
|
79
|
+
ReturnType<ReturnType<NativeActorContext["queue"]>["send"]>
|
|
80
|
+
>;
|
|
68
81
|
|
|
69
82
|
function asNativeRegistry(handle: RegistryHandle): NativeCoreRegistry {
|
|
70
83
|
return handle as unknown as NativeCoreRegistry;
|
|
@@ -233,7 +246,7 @@ function toNapiKvEntry(entry: RuntimeKvEntry): {
|
|
|
233
246
|
};
|
|
234
247
|
}
|
|
235
248
|
|
|
236
|
-
function toNapiQueueMessage(message:
|
|
249
|
+
function toNapiQueueMessage(message: NapiQueueMessage): RuntimeQueueMessage {
|
|
237
250
|
return {
|
|
238
251
|
id: () => message.id(),
|
|
239
252
|
name: () => message.name(),
|
|
@@ -254,23 +267,54 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
254
267
|
readonly kind = "napi";
|
|
255
268
|
|
|
256
269
|
#bindings: NativeBindings;
|
|
257
|
-
#
|
|
270
|
+
#sqlOpened = new WeakSet<NativeActorContext>();
|
|
271
|
+
#invocationContext: AsyncLocalStorage<NativeActorContext>;
|
|
258
272
|
|
|
259
|
-
constructor(
|
|
273
|
+
constructor(
|
|
274
|
+
bindings: NativeBindings,
|
|
275
|
+
invocationContext: AsyncLocalStorage<NativeActorContext>,
|
|
276
|
+
) {
|
|
260
277
|
this.#bindings = bindings;
|
|
278
|
+
this.#invocationContext = invocationContext;
|
|
261
279
|
}
|
|
262
280
|
|
|
263
|
-
#
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
if (!
|
|
267
|
-
|
|
268
|
-
this.#sql.set(nativeCtx, database);
|
|
281
|
+
#actorContextForOperation(owner: ActorContextHandle): NativeActorContext {
|
|
282
|
+
const ownerCtx = asNativeActorContext(owner);
|
|
283
|
+
const active = this.#invocationContext.getStore();
|
|
284
|
+
if (!active?.sameActorInstance(ownerCtx)) {
|
|
285
|
+
return ownerCtx;
|
|
269
286
|
}
|
|
270
|
-
|
|
287
|
+
const applicationSpan = readActiveTraceHeaders();
|
|
288
|
+
if (!applicationSpan) {
|
|
289
|
+
return active;
|
|
290
|
+
}
|
|
291
|
+
return active.withApplicationSpan(
|
|
292
|
+
applicationSpan.traceparent,
|
|
293
|
+
applicationSpan.tracestate ?? null,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
#actorSql(ctx: ActorContextHandle): NapiSqlDatabase {
|
|
298
|
+
this.#sqlOpened.add(asNativeActorContext(ctx));
|
|
299
|
+
return this.#actorContextForOperation(ctx).sql();
|
|
271
300
|
}
|
|
272
301
|
|
|
273
302
|
createRegistry(): RegistryHandle {
|
|
303
|
+
this.#bindings.setTelemetryLogSink(
|
|
304
|
+
(event: {
|
|
305
|
+
name: string;
|
|
306
|
+
message: string;
|
|
307
|
+
level: "warn" | "error";
|
|
308
|
+
}) => {
|
|
309
|
+
const fields = { otelEvent: event.name };
|
|
310
|
+
const message = event.message || event.name;
|
|
311
|
+
if (event.level === "error") {
|
|
312
|
+
logger().error(fields, message);
|
|
313
|
+
} else {
|
|
314
|
+
logger().warn(fields, message);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
);
|
|
274
318
|
return asRegistryHandle(new this.#bindings.CoreRegistry());
|
|
275
319
|
}
|
|
276
320
|
|
|
@@ -297,6 +341,10 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
297
341
|
await asNativeRegistry(registry).shutdown();
|
|
298
342
|
}
|
|
299
343
|
|
|
344
|
+
async shutdownTelemetry(): Promise<void> {
|
|
345
|
+
await this.#bindings.shutdownTelemetry();
|
|
346
|
+
}
|
|
347
|
+
|
|
300
348
|
async registryActorStopThresholdMs(
|
|
301
349
|
registry: RegistryHandle,
|
|
302
350
|
): Promise<number | undefined> {
|
|
@@ -552,6 +600,74 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
552
600
|
return asNativeActorContext(ctx).actorId();
|
|
553
601
|
}
|
|
554
602
|
|
|
603
|
+
runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T {
|
|
604
|
+
return this.#runAs(asNativeActorContext(ctx), run);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
#runAs<T>(nativeCtx: NativeActorContext, run: () => T): T {
|
|
608
|
+
const span = nativeCtx.invocationTraceContext()?.span;
|
|
609
|
+
return this.#invocationContext.run(nativeCtx, () =>
|
|
610
|
+
runWithActorInvocationSpan(span, run),
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
actorInvocationTraceContext(
|
|
615
|
+
ctx: ActorContextHandle,
|
|
616
|
+
): ActorInvocationTraceContext | undefined {
|
|
617
|
+
return (
|
|
618
|
+
this.#actorContextForOperation(ctx).invocationTraceContext() ??
|
|
619
|
+
undefined
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
startCallSpan(
|
|
624
|
+
ctx: ActorContextHandle,
|
|
625
|
+
actorName: string,
|
|
626
|
+
actionName: string,
|
|
627
|
+
): RuntimeOutboundCall | undefined {
|
|
628
|
+
const call = this.#actorContextForOperation(ctx).startCallSpan(
|
|
629
|
+
actorName,
|
|
630
|
+
actionName,
|
|
631
|
+
);
|
|
632
|
+
if (!call) return undefined;
|
|
633
|
+
return {
|
|
634
|
+
span: call.spanContext() ?? undefined,
|
|
635
|
+
finish: (error?: string) => call.finish(error),
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
async startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan> {
|
|
640
|
+
const span = await asNativeActorContext(ctx).startWorkflowSpan();
|
|
641
|
+
const spanCtx = span.ctx();
|
|
642
|
+
return {
|
|
643
|
+
run: (body) => this.#runAs(spanCtx, body),
|
|
644
|
+
startStep: (name, attempt) => {
|
|
645
|
+
const step = spanCtx.startWorkflowStepSpan(name, attempt);
|
|
646
|
+
if (!step) return undefined;
|
|
647
|
+
const stepCtx = step.ctx();
|
|
648
|
+
return {
|
|
649
|
+
run: (body) => this.#runAs(stepCtx, body),
|
|
650
|
+
finish: (outcome, error) =>
|
|
651
|
+
step.finish(
|
|
652
|
+
outcome,
|
|
653
|
+
error === undefined
|
|
654
|
+
? undefined
|
|
655
|
+
: encodeErrorForBridge(error),
|
|
656
|
+
),
|
|
657
|
+
};
|
|
658
|
+
},
|
|
659
|
+
finish: (outcome) => span.finish(outcome),
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
runOutsideActorInvocationContext<T>(run: () => T): T {
|
|
664
|
+
return this.#invocationContext.exit(run);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
currentInvocationScope(): object | undefined {
|
|
668
|
+
return this.#invocationContext.getStore();
|
|
669
|
+
}
|
|
670
|
+
|
|
555
671
|
actorName(ctx: ActorContextHandle): string {
|
|
556
672
|
return asNativeActorContext(ctx).name();
|
|
557
673
|
}
|
|
@@ -600,7 +716,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
600
716
|
}
|
|
601
717
|
|
|
602
718
|
actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void {
|
|
603
|
-
|
|
719
|
+
this.#actorContextForOperation(ctx).waitUntil(promise);
|
|
604
720
|
}
|
|
605
721
|
|
|
606
722
|
async actorWaitForTrackedShutdownWork(
|
|
@@ -810,7 +926,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
810
926
|
ctx: ActorContextHandle,
|
|
811
927
|
timeoutMs?: number,
|
|
812
928
|
): Promise<ActorStateTransactionHandle> {
|
|
813
|
-
return (await
|
|
929
|
+
return (await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
814
930
|
timeoutMs,
|
|
815
931
|
)) as unknown as ActorStateTransactionHandle;
|
|
816
932
|
}
|
|
@@ -871,13 +987,10 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
871
987
|
|
|
872
988
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
873
989
|
const nativeCtx = asNativeActorContext(ctx);
|
|
874
|
-
|
|
875
|
-
if (!database) {
|
|
990
|
+
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
876
991
|
return;
|
|
877
992
|
}
|
|
878
|
-
|
|
879
|
-
this.#sql.delete(nativeCtx);
|
|
880
|
-
await database.close();
|
|
993
|
+
await nativeCtx.sql().close();
|
|
881
994
|
}
|
|
882
995
|
|
|
883
996
|
async actorRuntimeSocketProvision(ctx: ActorContextHandle) {
|
|
@@ -890,7 +1003,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
890
1003
|
body: RuntimeBytes,
|
|
891
1004
|
): Promise<RuntimeQueueMessage> {
|
|
892
1005
|
return toNapiQueueMessage(
|
|
893
|
-
await
|
|
1006
|
+
await this.#actorContextForOperation(ctx)
|
|
894
1007
|
.queue()
|
|
895
1008
|
.send(name, toNapiBuffer(body)),
|
|
896
1009
|
);
|
|
@@ -901,7 +1014,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
901
1014
|
options?: RuntimeQueueNextBatchOptions | undefined | null,
|
|
902
1015
|
signal?: CancellationTokenHandle | undefined | null,
|
|
903
1016
|
): Promise<RuntimeQueueMessage[]> {
|
|
904
|
-
const messages = await
|
|
1017
|
+
const messages = await this.#actorContextForOperation(ctx)
|
|
905
1018
|
.queue()
|
|
906
1019
|
.nextBatch(
|
|
907
1020
|
options,
|
|
@@ -917,7 +1030,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
917
1030
|
signal?: CancellationTokenHandle | undefined | null,
|
|
918
1031
|
): Promise<RuntimeQueueMessage> {
|
|
919
1032
|
return toNapiQueueMessage(
|
|
920
|
-
await
|
|
1033
|
+
await this.#actorContextForOperation(ctx)
|
|
921
1034
|
.queue()
|
|
922
1035
|
.waitForNames(
|
|
923
1036
|
names,
|
|
@@ -964,7 +1077,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
964
1077
|
options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null,
|
|
965
1078
|
signal?: CancellationTokenHandle | undefined | null,
|
|
966
1079
|
): Promise<RuntimeBytes | null> {
|
|
967
|
-
return await
|
|
1080
|
+
return await this.#actorContextForOperation(ctx)
|
|
968
1081
|
.queue()
|
|
969
1082
|
.enqueueAndWait(
|
|
970
1083
|
name,
|
|
@@ -1002,7 +1115,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1002
1115
|
actionName: string,
|
|
1003
1116
|
args: RuntimeBytes,
|
|
1004
1117
|
): Promise<string> {
|
|
1005
|
-
return await
|
|
1118
|
+
return await this.#actorContextForOperation(ctx)
|
|
1006
1119
|
.schedule()
|
|
1007
1120
|
.after(durationMs, actionName, toNapiBuffer(args));
|
|
1008
1121
|
}
|
|
@@ -1013,13 +1126,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1013
1126
|
actionName: string,
|
|
1014
1127
|
args: RuntimeBytes,
|
|
1015
1128
|
): Promise<string> {
|
|
1016
|
-
return await
|
|
1129
|
+
return await this.#actorContextForOperation(ctx)
|
|
1017
1130
|
.schedule()
|
|
1018
1131
|
.at(timestampMs, actionName, toNapiBuffer(args));
|
|
1019
1132
|
}
|
|
1020
1133
|
|
|
1021
1134
|
async actorScheduleCancel(ctx: ActorContextHandle, id: string) {
|
|
1022
|
-
return await
|
|
1135
|
+
return await this.#actorContextForOperation(ctx).schedule().cancel(id);
|
|
1023
1136
|
}
|
|
1024
1137
|
|
|
1025
1138
|
async actorScheduleGet(
|
|
@@ -1027,12 +1140,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1027
1140
|
id: string,
|
|
1028
1141
|
): Promise<RuntimeScheduledEventInfo | undefined> {
|
|
1029
1142
|
return (
|
|
1030
|
-
(await
|
|
1143
|
+
(await this.#actorContextForOperation(ctx).schedule().get(id)) ??
|
|
1144
|
+
undefined
|
|
1031
1145
|
);
|
|
1032
1146
|
}
|
|
1033
1147
|
|
|
1034
1148
|
async actorScheduleList(ctx: ActorContextHandle) {
|
|
1035
|
-
return await
|
|
1149
|
+
return await this.#actorContextForOperation(ctx).schedule().list();
|
|
1036
1150
|
}
|
|
1037
1151
|
|
|
1038
1152
|
async actorCronSet(
|
|
@@ -1044,7 +1158,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1044
1158
|
args: RuntimeBytes,
|
|
1045
1159
|
maxHistory: number | undefined,
|
|
1046
1160
|
) {
|
|
1047
|
-
await
|
|
1161
|
+
await this.#actorContextForOperation(ctx)
|
|
1048
1162
|
.schedule()
|
|
1049
1163
|
.cronSet(
|
|
1050
1164
|
name,
|
|
@@ -1064,7 +1178,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1064
1178
|
args: RuntimeBytes,
|
|
1065
1179
|
maxHistory: number | undefined,
|
|
1066
1180
|
) {
|
|
1067
|
-
await
|
|
1181
|
+
await this.#actorContextForOperation(ctx)
|
|
1068
1182
|
.schedule()
|
|
1069
1183
|
.cronEvery(
|
|
1070
1184
|
name,
|
|
@@ -1079,20 +1193,23 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1079
1193
|
ctx: ActorContextHandle,
|
|
1080
1194
|
name: string,
|
|
1081
1195
|
): Promise<RuntimeCronJobInfo | undefined> {
|
|
1082
|
-
return ((await
|
|
1083
|
-
|
|
1196
|
+
return ((await this.#actorContextForOperation(ctx)
|
|
1197
|
+
.schedule()
|
|
1198
|
+
.cronGet(name)) ?? undefined) as RuntimeCronJobInfo | undefined;
|
|
1084
1199
|
}
|
|
1085
1200
|
|
|
1086
1201
|
async actorCronList(
|
|
1087
1202
|
ctx: ActorContextHandle,
|
|
1088
1203
|
): Promise<RuntimeCronJobInfo[]> {
|
|
1089
|
-
return (await
|
|
1204
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1090
1205
|
.schedule()
|
|
1091
1206
|
.cronList()) as RuntimeCronJobInfo[];
|
|
1092
1207
|
}
|
|
1093
1208
|
|
|
1094
1209
|
async actorCronDelete(ctx: ActorContextHandle, name: string) {
|
|
1095
|
-
return await
|
|
1210
|
+
return await this.#actorContextForOperation(ctx)
|
|
1211
|
+
.schedule()
|
|
1212
|
+
.cronDelete(name);
|
|
1096
1213
|
}
|
|
1097
1214
|
|
|
1098
1215
|
async actorCronHistory(
|
|
@@ -1100,7 +1217,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1100
1217
|
name: string,
|
|
1101
1218
|
limit: number | undefined,
|
|
1102
1219
|
): Promise<RuntimeCronFire[]> {
|
|
1103
|
-
return (await
|
|
1220
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1104
1221
|
.schedule()
|
|
1105
1222
|
.cronHistory(name, limit)) as RuntimeCronFire[];
|
|
1106
1223
|
}
|
|
@@ -1173,9 +1290,12 @@ export async function loadNapiRuntime(): Promise<{
|
|
|
1173
1290
|
// would snapshot the native `.node` addon into the deploy and 413. The
|
|
1174
1291
|
// computed specifier keeps it opaque to static analysis so it is never
|
|
1175
1292
|
// bundled. Enforced by scripts/ci/check-edge-native-closure.mjs.
|
|
1176
|
-
const bindings = await
|
|
1293
|
+
const [{ AsyncLocalStorage }, bindings] = await Promise.all([
|
|
1294
|
+
import("node:async_hooks"),
|
|
1295
|
+
import(["@rivetkit", "rivetkit-napi"].join("/")),
|
|
1296
|
+
]);
|
|
1177
1297
|
return {
|
|
1178
1298
|
bindings,
|
|
1179
|
-
runtime: new NapiCoreRuntime(bindings),
|
|
1299
|
+
runtime: new NapiCoreRuntime(bindings, new AsyncLocalStorage()),
|
|
1180
1300
|
};
|
|
1181
1301
|
}
|