rivetkit 2.3.0-rc.11 → 2.3.0-rc.12

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.
Files changed (96) hide show
  1. package/dist/browser/client.d.ts +357 -20
  2. package/dist/browser/client.js +4 -3
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/agent-os/index.cjs +1 -1
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +354 -17
  9. package/dist/tsup/agent-os/index.d.ts +354 -17
  10. package/dist/tsup/agent-os/index.js +1 -1
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-XG25CGSW.cjs → chunk-2U6RLFKX.cjs} +141 -140
  13. package/dist/tsup/chunk-2U6RLFKX.cjs.map +1 -0
  14. package/dist/tsup/{chunk-2NXFKPRB.cjs → chunk-2ZTBRZRS.cjs} +10 -10
  15. package/dist/tsup/{chunk-2NXFKPRB.cjs.map → chunk-2ZTBRZRS.cjs.map} +1 -1
  16. package/dist/tsup/{chunk-4FP4FFB5.js → chunk-3EVVOYFD.js} +3 -3
  17. package/dist/tsup/chunk-3EVVOYFD.js.map +1 -0
  18. package/dist/tsup/{chunk-Y3JBOFBG.cjs → chunk-6KTMKPNU.cjs} +8 -8
  19. package/dist/tsup/{chunk-Y3JBOFBG.cjs.map → chunk-6KTMKPNU.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-TTLUIDVH.js → chunk-7UZF56RS.js} +6 -5
  21. package/dist/tsup/chunk-7UZF56RS.js.map +1 -0
  22. package/dist/tsup/{chunk-LNP7Q6I6.cjs → chunk-C7AAIILH.cjs} +4 -4
  23. package/dist/tsup/{chunk-LNP7Q6I6.cjs.map → chunk-C7AAIILH.cjs.map} +1 -1
  24. package/dist/tsup/{chunk-WXYWDLJY.js → chunk-EWVOWEMD.js} +4 -4
  25. package/dist/tsup/{chunk-YRQ4F5CD.js → chunk-OLIJHKLL.js} +3 -3
  26. package/dist/tsup/{chunk-KRC4L3YB.js → chunk-OOB32JVG.js} +2 -2
  27. package/dist/tsup/{chunk-GRFBV2U7.js → chunk-QKSGGKGQ.js} +2 -2
  28. package/dist/tsup/{chunk-GX6W4MW3.cjs → chunk-SS56HFM2.cjs} +5 -5
  29. package/dist/tsup/{chunk-GX6W4MW3.cjs.map → chunk-SS56HFM2.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-LW5HNCWD.cjs → chunk-UETC5RF7.cjs} +3 -3
  31. package/dist/tsup/{chunk-LW5HNCWD.cjs.map → chunk-UETC5RF7.cjs.map} +1 -1
  32. package/dist/tsup/{chunk-3P2JUHWJ.js → chunk-VLXRFJ7P.js} +2 -2
  33. package/dist/tsup/{chunk-RDBGKI66.cjs → chunk-VNMIAPPF.cjs} +3 -3
  34. package/dist/tsup/chunk-VNMIAPPF.cjs.map +1 -0
  35. package/dist/tsup/{chunk-XCDCURZ4.cjs → chunk-WHYBAEWG.cjs} +1 -1
  36. package/dist/tsup/{chunk-XCDCURZ4.cjs.map → chunk-WHYBAEWG.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-T3VCJ4PV.js → chunk-WIMUFZVJ.js} +1 -1
  38. package/dist/tsup/{chunk-T3VCJ4PV.js.map → chunk-WIMUFZVJ.js.map} +1 -1
  39. package/dist/tsup/client/mod.cjs +6 -6
  40. package/dist/tsup/client/mod.d.cts +2 -2
  41. package/dist/tsup/client/mod.d.ts +2 -2
  42. package/dist/tsup/client/mod.js +5 -5
  43. package/dist/tsup/common/log.cjs +2 -2
  44. package/dist/tsup/common/log.js +1 -1
  45. package/dist/tsup/common/websocket.cjs +3 -3
  46. package/dist/tsup/common/websocket.js +2 -2
  47. package/dist/tsup/{config-CTwe3WwC.d.cts → config-BtAh7oBu.d.cts} +356 -19
  48. package/dist/tsup/{config-De5UVu0V.d.ts → config-DKgPGC0f.d.ts} +356 -19
  49. package/dist/tsup/{context-DPHISlUi.d.ts → context-C-6dGebY.d.ts} +1 -1
  50. package/dist/tsup/{context-Dmj477Uh.d.cts → context-Cfjl5pgz.d.cts} +1 -1
  51. package/dist/tsup/dynamic/mod.cjs +2 -2
  52. package/dist/tsup/dynamic/mod.d.cts +1 -1
  53. package/dist/tsup/dynamic/mod.d.ts +1 -1
  54. package/dist/tsup/dynamic/mod.js +1 -1
  55. package/dist/tsup/inspector/mod.cjs +5 -5
  56. package/dist/tsup/inspector/mod.js +4 -4
  57. package/dist/tsup/mod.cjs +222 -127
  58. package/dist/tsup/mod.cjs.map +1 -1
  59. package/dist/tsup/mod.d.cts +3 -3
  60. package/dist/tsup/mod.d.ts +3 -3
  61. package/dist/tsup/mod.js +159 -64
  62. package/dist/tsup/mod.js.map +1 -1
  63. package/dist/tsup/test/mod.cjs +9 -9
  64. package/dist/tsup/test/mod.d.cts +1 -1
  65. package/dist/tsup/test/mod.d.ts +1 -1
  66. package/dist/tsup/test/mod.js +5 -5
  67. package/dist/tsup/utils.cjs +2 -2
  68. package/dist/tsup/utils.js +1 -1
  69. package/dist/tsup/workflow/mod.cjs +11 -11
  70. package/dist/tsup/workflow/mod.d.cts +3 -3
  71. package/dist/tsup/workflow/mod.d.ts +3 -3
  72. package/dist/tsup/workflow/mod.js +5 -5
  73. package/package.json +8 -8
  74. package/src/actor/config.ts +20 -10
  75. package/src/actor/definition.ts +6 -5
  76. package/src/client/actor-common.ts +24 -27
  77. package/src/client/actor-handle.ts +2 -1
  78. package/src/common/utils.ts +1 -1
  79. package/src/drivers/engine/actor-driver.ts +16 -5
  80. package/src/engine-client/api-endpoints.ts +5 -1
  81. package/src/registry/config/index.ts +3 -9
  82. package/src/registry/index.ts +139 -60
  83. package/src/registry/napi-runtime.ts +6 -0
  84. package/src/registry/native.ts +52 -20
  85. package/src/registry/process-metrics.ts +16 -4
  86. package/src/registry/runtime.ts +6 -0
  87. package/src/registry/wasm-runtime.ts +16 -1
  88. package/dist/tsup/chunk-4FP4FFB5.js.map +0 -1
  89. package/dist/tsup/chunk-RDBGKI66.cjs.map +0 -1
  90. package/dist/tsup/chunk-TTLUIDVH.js.map +0 -1
  91. package/dist/tsup/chunk-XG25CGSW.cjs.map +0 -1
  92. /package/dist/tsup/{chunk-WXYWDLJY.js.map → chunk-EWVOWEMD.js.map} +0 -0
  93. /package/dist/tsup/{chunk-YRQ4F5CD.js.map → chunk-OLIJHKLL.js.map} +0 -0
  94. /package/dist/tsup/{chunk-KRC4L3YB.js.map → chunk-OOB32JVG.js.map} +0 -0
  95. /package/dist/tsup/{chunk-GRFBV2U7.js.map → chunk-QKSGGKGQ.js.map} +0 -0
  96. /package/dist/tsup/{chunk-3P2JUHWJ.js.map → chunk-VLXRFJ7P.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
- import { A as AnyDatabaseProvider, I as InferDatabaseClient } from './config-D49x8NpL.cjs';
2
+ import { A as AnyDatabaseProvider, d as SqliteNativeMetrics, I as InferDatabaseClient } from './config-D49x8NpL.cjs';
3
3
  import * as _rivetkit_rivetkit_wasm from '@rivetkit/rivetkit-wasm';
4
4
  import { z as z$1 } from 'zod';
5
5
  import { Logger } from 'pino';
@@ -191,7 +191,7 @@ declare const RegistryConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
191
191
  envoyKey: z$1.ZodOptional<z$1.ZodString>;
192
192
  }, z$1.core.$strip>>>;
193
193
  shutdown: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
194
- gracePeriodMs: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
194
+ gracePeriodMs: z$1.ZodOptional<z$1.ZodNumber>;
195
195
  disableSignalHandlers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
196
196
  }, z$1.core.$strip>>>;
197
197
  }, z$1.core.$strip>, z$1.ZodTransform<{
@@ -240,8 +240,8 @@ declare const RegistryConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
240
240
  envoyKey?: string | undefined;
241
241
  };
242
242
  shutdown: {
243
- gracePeriodMs: number;
244
243
  disableSignalHandlers: boolean;
244
+ gracePeriodMs?: number | undefined;
245
245
  };
246
246
  staticDir?: string | undefined;
247
247
  httpHost?: string | undefined;
@@ -297,8 +297,8 @@ declare const RegistryConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
297
297
  envoyKey?: string | undefined;
298
298
  };
299
299
  shutdown: {
300
- gracePeriodMs: number;
301
300
  disableSignalHandlers: boolean;
301
+ gracePeriodMs?: number | undefined;
302
302
  };
303
303
  staticDir?: string | undefined;
304
304
  httpHost?: string | undefined;
@@ -456,7 +456,7 @@ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
456
456
  type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
457
457
 
458
458
  interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, _R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
459
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
459
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
460
460
  }
461
461
  interface AnyActorDefinition {
462
462
  readonly config: any;
@@ -464,8 +464,8 @@ interface AnyActorDefinition {
464
464
  type AnyStaticActorDefinition = ActorDefinition<any, any, any, any, any, any, any, any, any>;
465
465
  declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R> {
466
466
  #private;
467
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
468
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
467
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
468
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
469
469
  }
470
470
  interface BaseActorInstance<S = any, CP = any, CS = any, V = any, I = any, DB extends AnyDatabaseProvider = AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
471
471
  id: string;
@@ -559,6 +559,318 @@ interface ActorOutput {
559
559
  error?: unknown;
560
560
  }
561
561
 
562
+ declare const handleBrand: unique symbol;
563
+ type OpaqueHandle<Name extends string> = {
564
+ readonly [handleBrand]: Name;
565
+ };
566
+ type RegistryHandle = OpaqueHandle<"registry">;
567
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
568
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
569
+ type ConnHandle = OpaqueHandle<"conn">;
570
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
571
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
572
+ type RuntimeBytes = Uint8Array;
573
+ interface RuntimeActorKeySegment {
574
+ kind: string;
575
+ stringValue?: string;
576
+ numberValue?: number;
577
+ }
578
+ interface RuntimeHttpRequest {
579
+ method: string;
580
+ uri: string;
581
+ headers?: Record<string, string>;
582
+ body?: RuntimeBytes;
583
+ }
584
+ interface RuntimeStateDeltaPayload {
585
+ state?: RuntimeBytes;
586
+ connHibernation: Array<{
587
+ connId: string;
588
+ bytes: RuntimeBytes;
589
+ }>;
590
+ connHibernationRemoved: string[];
591
+ }
592
+ interface RuntimeRequestSaveOpts {
593
+ immediate?: boolean;
594
+ maxWaitMs?: number;
595
+ }
596
+ interface RuntimeInspectorSnapshot {
597
+ stateRevision: number;
598
+ connectionsRevision: number;
599
+ queueRevision: number;
600
+ activeConnections: number;
601
+ queueSize: number;
602
+ connectedClients: number;
603
+ }
604
+ interface RuntimeQueueMessage {
605
+ id(): bigint;
606
+ name(): string;
607
+ body(): RuntimeBytes;
608
+ createdAt(): number;
609
+ isCompletable(): boolean;
610
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
611
+ }
612
+ interface RuntimeQueueInspectMessage {
613
+ id: number;
614
+ name: string;
615
+ createdAtMs: number;
616
+ }
617
+ interface RuntimeQueueNextBatchOptions {
618
+ names?: string[];
619
+ count?: number;
620
+ timeoutMs?: number;
621
+ completable?: boolean;
622
+ }
623
+ interface RuntimeQueueWaitOptions {
624
+ timeoutMs?: number;
625
+ completable?: boolean;
626
+ }
627
+ interface RuntimeQueueEnqueueAndWaitOptions {
628
+ timeoutMs?: number;
629
+ }
630
+ interface RuntimeQueueTryNextBatchOptions {
631
+ names?: string[];
632
+ count?: number;
633
+ completable?: boolean;
634
+ }
635
+ interface RuntimeKvListOptions {
636
+ reverse?: boolean;
637
+ limit?: number;
638
+ }
639
+ interface RuntimeKvEntry {
640
+ key: RuntimeBytes;
641
+ value: RuntimeBytes;
642
+ }
643
+ type RuntimeSqlBindNoValues = {
644
+ intValue?: never;
645
+ floatValue?: never;
646
+ textValue?: never;
647
+ blobValue?: never;
648
+ };
649
+ type RuntimeSqlBindParam = ({
650
+ kind: "null";
651
+ } & RuntimeSqlBindNoValues) | {
652
+ kind: "int";
653
+ intValue: number;
654
+ floatValue?: never;
655
+ textValue?: never;
656
+ blobValue?: never;
657
+ } | {
658
+ kind: "float";
659
+ intValue?: never;
660
+ floatValue: number;
661
+ textValue?: never;
662
+ blobValue?: never;
663
+ } | {
664
+ kind: "text";
665
+ intValue?: never;
666
+ floatValue?: never;
667
+ textValue: string;
668
+ blobValue?: never;
669
+ } | {
670
+ kind: "blob";
671
+ intValue?: never;
672
+ floatValue?: never;
673
+ textValue?: never;
674
+ blobValue: RuntimeBytes;
675
+ };
676
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
677
+ interface RuntimeSqlQueryResult {
678
+ columns: string[];
679
+ rows: unknown[][];
680
+ }
681
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
682
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
683
+ changes: number;
684
+ lastInsertRowId?: number | null;
685
+ }
686
+ interface RuntimeSqlRunResult {
687
+ changes: number;
688
+ }
689
+ interface RuntimeActorConfig {
690
+ name?: string;
691
+ icon?: string;
692
+ hasDatabase?: boolean;
693
+ remoteSqlite?: boolean;
694
+ hasState?: boolean;
695
+ canHibernateWebsocket?: boolean;
696
+ stateSaveIntervalMs?: number;
697
+ createStateTimeoutMs?: number;
698
+ onCreateTimeoutMs?: number;
699
+ createVarsTimeoutMs?: number;
700
+ createConnStateTimeoutMs?: number;
701
+ onBeforeConnectTimeoutMs?: number;
702
+ onConnectTimeoutMs?: number;
703
+ onMigrateTimeoutMs?: number;
704
+ onWakeTimeoutMs?: number;
705
+ onBeforeActorStartTimeoutMs?: number;
706
+ actionTimeoutMs?: number;
707
+ onRequestTimeoutMs?: number;
708
+ sleepTimeoutMs?: number;
709
+ noSleep?: boolean;
710
+ sleepGracePeriodMs?: number;
711
+ connectionLivenessTimeoutMs?: number;
712
+ connectionLivenessIntervalMs?: number;
713
+ maxQueueSize?: number;
714
+ maxQueueMessageSize?: number;
715
+ maxIncomingMessageSize?: number;
716
+ maxOutgoingMessageSize?: number;
717
+ preloadMaxWorkflowBytes?: number;
718
+ preloadMaxConnectionsBytes?: number;
719
+ actions?: Array<{
720
+ name: string;
721
+ }>;
722
+ }
723
+ interface RuntimeServeConfig {
724
+ version: number;
725
+ endpoint: string;
726
+ token?: string;
727
+ namespace: string;
728
+ poolName: string;
729
+ engineBinaryPath?: string;
730
+ handleInspectorHttpInRuntime?: boolean;
731
+ inspectorTestToken?: string;
732
+ serverlessBasePath?: string;
733
+ serverlessPackageVersion: string;
734
+ serverlessClientEndpoint?: string;
735
+ serverlessClientNamespace?: string;
736
+ serverlessClientToken?: string;
737
+ serverlessValidateEndpoint: boolean;
738
+ serverlessMaxStartPayloadBytes: number;
739
+ }
740
+ interface RuntimeServerlessRequest {
741
+ method: string;
742
+ url: string;
743
+ headers: Record<string, string>;
744
+ body: RuntimeBytes;
745
+ }
746
+ interface RuntimeServerlessResponseHead {
747
+ status: number;
748
+ headers: Record<string, string>;
749
+ }
750
+ interface RuntimeRegistryRouteResponse {
751
+ status: number;
752
+ headers: Record<string, string>;
753
+ body: RuntimeBytes;
754
+ }
755
+ type RuntimeServerlessStreamEvent = {
756
+ kind: "chunk";
757
+ chunk?: RuntimeBytes;
758
+ } | {
759
+ kind: "end";
760
+ error?: {
761
+ group: string;
762
+ code: string;
763
+ message: string;
764
+ };
765
+ };
766
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
767
+ type RuntimeWebSocketEvent = {
768
+ kind: "message";
769
+ data: string | RuntimeBytes;
770
+ binary: boolean;
771
+ messageIndex?: number;
772
+ } | {
773
+ kind: "close";
774
+ code: number;
775
+ reason: string;
776
+ wasClean: boolean;
777
+ };
778
+ interface CoreRuntime {
779
+ readonly kind: "napi" | "wasm";
780
+ createRegistry(): RegistryHandle;
781
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
782
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
783
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
784
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
785
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
786
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
787
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
788
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
789
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
790
+ createCancellationToken(): CancellationTokenHandle;
791
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
792
+ cancelCancellationToken(token: CancellationTokenHandle): void;
793
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
794
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
795
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
796
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
797
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
798
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
799
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
800
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
801
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
802
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
803
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
804
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
805
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
806
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
807
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
808
+ actorId(ctx: ActorContextHandle): string;
809
+ actorName(ctx: ActorContextHandle): string;
810
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
811
+ actorRegion(ctx: ActorContextHandle): string;
812
+ actorSleep(ctx: ActorContextHandle): void;
813
+ actorDestroy(ctx: ActorContextHandle): void;
814
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
815
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
816
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
817
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
818
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
819
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
820
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
821
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
822
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
823
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
824
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
825
+ actorRuntimeState(ctx: ActorContextHandle): object;
826
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
827
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
828
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
829
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
830
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
831
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
832
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
833
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
834
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
835
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
836
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
837
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
838
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
839
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
840
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
841
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
842
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
843
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
844
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
845
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
846
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
847
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
848
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
849
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
850
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
851
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
852
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
853
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
854
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
855
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
856
+ connId(conn: ConnHandle): string;
857
+ connParams(conn: ConnHandle): RuntimeBytes;
858
+ connState(conn: ConnHandle): RuntimeBytes;
859
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
860
+ connIsHibernatable(conn: ConnHandle): boolean;
861
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
862
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
863
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
864
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
865
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
866
+ }
867
+
868
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
869
+ runtime: CoreRuntime;
870
+ registry: RegistryHandle;
871
+ serveConfig: RuntimeServeConfig;
872
+ }>;
873
+
562
874
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
563
875
  interface ServerlessHandler {
564
876
  fetch: FetchHandler;
@@ -568,12 +880,20 @@ interface RegistryRoutes {
568
880
  metadata(): Promise<Response>;
569
881
  prometheusMetrics(request?: Request): Promise<Response>;
570
882
  }
883
+ /**
884
+ * Injectable dependencies for {@link Registry}. Production code uses the
885
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
886
+ * orchestration against a fake `CoreRuntime` without an engine.
887
+ */
888
+ interface RegistryDeps {
889
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
890
+ }
571
891
  declare class Registry<A extends RegistryActors> {
572
892
  #private;
573
893
  readonly routes: RegistryRoutes;
574
894
  get config(): RegistryConfigInput<A>;
575
895
  parseConfig(): RegistryConfig;
576
- constructor(config: RegistryConfigInput<A>);
896
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
577
897
  /**
578
898
  * Handle an incoming HTTP request for serverless deployments.
579
899
  *
@@ -613,6 +933,27 @@ declare class Registry<A extends RegistryActors> {
613
933
  port?: number;
614
934
  publicDir?: string;
615
935
  }): Promise<void>;
936
+ /**
937
+ * Gracefully drains all live registries.
938
+ *
939
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
940
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
941
+ * waits for the serve promise to resolve, all bounded by the shutdown
942
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
943
+ * signal or exit the process. The caller owns process lifetime.
944
+ *
945
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
946
+ * call even if nothing has been started.
947
+ *
948
+ * @example
949
+ * ```ts
950
+ * const registry = setup({ use: { counter } });
951
+ * registry.start();
952
+ * // ...later, on your own shutdown trigger:
953
+ * await registry.shutdown();
954
+ * ```
955
+ */
956
+ shutdown(): Promise<void>;
616
957
  startEnvoy(): void;
617
958
  /**
618
959
  * Starts the actor envoy for standalone server deployments.
@@ -654,6 +995,10 @@ interface QueueSendResult<TResponse = unknown> {
654
995
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
655
996
  type IsAny<T> = 0 extends 1 & T ? true : false;
656
997
  type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
998
+ type ActorActionMap<R> = {
999
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
1000
+ };
1001
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
657
1002
  interface ActorGatewayOptions {
658
1003
  skipReadyWait?: boolean;
659
1004
  }
@@ -666,15 +1011,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
666
1011
  /**
667
1012
  * Maps action methods from actor definition to typed function signatures.
668
1013
  */
669
- type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : AD extends {
670
- config: {
671
- actions?: infer R;
672
- };
673
- } ? {
674
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
675
- } : AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
676
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
677
- } : {};
1014
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
678
1015
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
679
1016
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
680
1017
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -1710,7 +2047,7 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1710
2047
  */
1711
2048
  db: TDatabase;
1712
2049
  } | Record<never, never>;
1713
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
2050
+ type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> = Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
1714
2051
  type ActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TDatabase extends AnyDatabaseProvider = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> = Record<never, never>> = {
1715
2052
  types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
1716
2053
  } & Omit<z.input<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
@@ -1789,4 +2126,4 @@ declare const DocActorConfigSchema: z.ZodObject<{
1789
2126
  }, z.core.$strip>>;
1790
2127
  }, z.core.$strip>;
1791
2128
 
1792
- export { DocConfigurePoolSchema as $, type AnyActorDefinition as A, type BaseActorDefinition as B, type ConnectContext as C, type DestroyContext as D, type EventSchemaConfig as E, type ActorSchedule as F, type ActorTypes as G, ActorsSchema as H, type AnyActorInstance as I, type AnyClient as J, type AnyConn as K, type AnyStaticActorDefinition as L, type MigrateContext as M, type AnyStaticActorInstance as N, type AuthIntent as O, type BaseActorInstance as P, type QueueSchemaConfig as Q, type RequestContext as R, type SleepContext as S, CONN_DRIVER_SYMBOL as T, CONN_STATE_MANAGER_SYMBOL as U, type Client as V, type WakeContext as W, type Conn as X, DEFAULT_SLEEP_GRACE_PERIOD as Y, DocActorConfigSchema as Z, DocActorOptionsSchema as _, type ActionContext as a, type ActorAccessor as a$, DocEnvoyConfigSchema as a0, DocRegistryConfigSchema as a1, DocServerlessConfigSchema as a2, DocSqliteConfigSchema as a3, type Encoding as a4, type FetchHandler as a5, type GlobalActorOptions as a6, type GlobalActorOptionsInput as a7, GlobalActorOptionsSchema as a8, type InspectorUnsubscribe as a9, RuntimeKindSchema as aA, type ServerlessHandler as aB, type SqliteBackend as aC, SqliteBackendSchema as aD, type SqliteConfig as aE, SqliteConfigSchema as aF, type TestConfig as aG, TestConfigSchema as aH, type Type as aI, type WasmRuntimeBindings as aJ, type WasmRuntimeConfig as aK, WasmRuntimeConfigSchema as aL, type WasmRuntimeInitInput as aM, type WorkflowInspectorConfig as aN, actor as aO, buildActorNames as aP, createClientWithDriver as aQ, event as aR, getRunFunction as aS, getRunInspectorConfig as aT, getRunMetadata as aU, isStaticActorDefinition as aV, isStaticActorInstance as aW, lookupInRegistry as aX, queue as aY, setup as aZ, test as a_, type InstanceActorOptions as aa, type InstanceActorOptionsInput as ab, InstanceActorOptionsSchema as ac, type QueueEnqueueAndWaitOptions as ad, type QueueFilterName as ae, type QueueIterOptions as af, type QueueMessageOf as ag, type QueueName as ah, type QueueNextBatchOptions as ai, type QueueNextOptions as aj, type QueueResultMessageForName as ak, type QueueTryNextBatchOptions as al, type QueueTryNextOptions as am, type QueueWaitOptions as an, RAW_STATE_SYMBOL as ao, RUN_FUNCTION_CONFIG_SYMBOL as ap, Registry as aq, type RegistryActors as ar, type RegistryConfig as as, type RegistryConfigInput as at, RegistryConfigSchema as au, type RegistryRoutes as av, type RunConfig as aw, RunConfigSchema as ax, type RunInspectorConfig as ay, type RuntimeKind as az, type BeforeActionResponseContext as b, type ActorActionFunction as b0, type ActorActionOptions as b1, type ActorConn as b2, ActorConnRaw as b3, type ActorConnStatus as b4, type ActorConnectOptions as b5, type ActorGatewayOptions as b6, type ActorHandle as b7, ActorHandleRaw as b8, ClientRaw as b9, type ConnectionStateCallback as ba, type CreateOptions as bb, type CreateRequest as bc, type EventUnsubscribe as bd, type ExtractActorsFromRegistry as be, type ExtractRegistryFromClient as bf, type GetOptions as bg, type GetWithIdOptions as bh, type QueryOptions as bi, type Region as bj, type StatusChangeCallback as bk, type InferSchemaMap as bl, type InferEventArgs as bm, type BeforeConnectContext as c, type CreateConnStateContext as d, type CreateContext as e, type CreateVarsContext as f, type DisconnectContext as g, type RunContext as h, type StateChangeContext as i, type WebSocketContext as j, ACTOR_CONTEXT_INTERNAL_SYMBOL as k, type Actions as l, type ActorConfig as m, type ActorConfigInput as n, ActorConfigSchema as o, type ActorContext as p, type ActorContextOf as q, ActorDefinition as r, type ActorKey as s, type ActorKv as t, type ActorLogger as u, type ActorOptions as v, type ActorOptionsInput as w, ActorOptionsSchema as x, type ActorQuery as y, type ActorQueue as z };
2129
+ export { DocConfigurePoolSchema as $, type AnyActorDefinition as A, type BaseActorDefinition as B, type ConnectContext as C, type DestroyContext as D, type EventSchemaConfig as E, type ActorSchedule as F, type ActorTypes as G, ActorsSchema as H, type AnyActorInstance as I, type AnyClient as J, type AnyConn as K, type AnyStaticActorDefinition as L, type MigrateContext as M, type AnyStaticActorInstance as N, type AuthIntent as O, type BaseActorInstance as P, type QueueSchemaConfig as Q, type RequestContext as R, type SleepContext as S, CONN_DRIVER_SYMBOL as T, CONN_STATE_MANAGER_SYMBOL as U, type Client as V, type WakeContext as W, type Conn as X, DEFAULT_SLEEP_GRACE_PERIOD as Y, DocActorConfigSchema as Z, DocActorOptionsSchema as _, type ActionContext as a, test as a$, DocEnvoyConfigSchema as a0, DocRegistryConfigSchema as a1, DocServerlessConfigSchema as a2, DocSqliteConfigSchema as a3, type Encoding as a4, type FetchHandler as a5, type GlobalActorOptions as a6, type GlobalActorOptionsInput as a7, GlobalActorOptionsSchema as a8, type InspectorUnsubscribe as a9, type RuntimeKind as aA, RuntimeKindSchema as aB, type ServerlessHandler as aC, type SqliteBackend as aD, SqliteBackendSchema as aE, type SqliteConfig as aF, SqliteConfigSchema as aG, type TestConfig as aH, TestConfigSchema as aI, type Type as aJ, type WasmRuntimeBindings as aK, type WasmRuntimeConfig as aL, WasmRuntimeConfigSchema as aM, type WasmRuntimeInitInput as aN, type WorkflowInspectorConfig as aO, actor as aP, buildActorNames as aQ, createClientWithDriver as aR, event as aS, getRunFunction as aT, getRunInspectorConfig as aU, getRunMetadata as aV, isStaticActorDefinition as aW, isStaticActorInstance as aX, lookupInRegistry as aY, queue as aZ, setup as a_, type InstanceActorOptions as aa, type InstanceActorOptionsInput as ab, InstanceActorOptionsSchema as ac, type QueueEnqueueAndWaitOptions as ad, type QueueFilterName as ae, type QueueIterOptions as af, type QueueMessageOf as ag, type QueueName as ah, type QueueNextBatchOptions as ai, type QueueNextOptions as aj, type QueueResultMessageForName as ak, type QueueTryNextBatchOptions as al, type QueueTryNextOptions as am, type QueueWaitOptions as an, RAW_STATE_SYMBOL as ao, RUN_FUNCTION_CONFIG_SYMBOL as ap, Registry as aq, type RegistryActors as ar, type RegistryConfig as as, type RegistryConfigInput as at, RegistryConfigSchema as au, type RegistryDeps as av, type RegistryRoutes as aw, type RunConfig as ax, RunConfigSchema as ay, type RunInspectorConfig as az, type BeforeActionResponseContext as b, type ActorAccessor as b0, type ActorActionFunction as b1, type ActorActionOptions as b2, type ActorConn as b3, ActorConnRaw as b4, type ActorConnStatus as b5, type ActorConnectOptions as b6, type ActorGatewayOptions as b7, type ActorHandle as b8, ActorHandleRaw as b9, ClientRaw as ba, type ConnectionStateCallback as bb, type CreateOptions as bc, type CreateRequest as bd, type EventUnsubscribe as be, type ExtractActorsFromRegistry as bf, type ExtractRegistryFromClient as bg, type GetOptions as bh, type GetWithIdOptions as bi, type QueryOptions as bj, type Region as bk, type StatusChangeCallback as bl, type InferSchemaMap as bm, type InferEventArgs as bn, type BeforeConnectContext as c, type CreateConnStateContext as d, type CreateContext as e, type CreateVarsContext as f, type DisconnectContext as g, type RunContext as h, type StateChangeContext as i, type WebSocketContext as j, ACTOR_CONTEXT_INTERNAL_SYMBOL as k, type Actions as l, type ActorConfig as m, type ActorConfigInput as n, ActorConfigSchema as o, type ActorContext as p, type ActorContextOf as q, ActorDefinition as r, type ActorKey as s, type ActorKv as t, type ActorLogger as u, type ActorOptions as v, type ActorOptionsInput as w, ActorOptionsSchema as x, type ActorQuery as y, type ActorQueue as z };