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
@@ -385,6 +385,10 @@ interface QueueSendResult<TResponse = unknown> {
385
385
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
386
386
  type IsAny<T> = 0 extends 1 & T ? true : false;
387
387
  type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
388
+ type ActorActionMap<R> = {
389
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
390
+ };
391
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
388
392
  interface ActorGatewayOptions {
389
393
  skipReadyWait?: boolean;
390
394
  }
@@ -397,15 +401,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
397
401
  /**
398
402
  * Maps action methods from actor definition to typed function signatures.
399
403
  */
400
- type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : AD extends {
401
- config: {
402
- actions?: infer R;
403
- };
404
- } ? {
405
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
406
- } : AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
407
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
408
- } : {};
404
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
409
405
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
410
406
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
411
407
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -1402,18 +1398,18 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1402
1398
  */
1403
1399
  db: TDatabase;
1404
1400
  } | Record<never, never>;
1405
- 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>;
1401
+ 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>;
1406
1402
 
1407
1403
  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>> {
1408
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1404
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
1409
1405
  }
1410
1406
  interface AnyActorDefinition {
1411
1407
  readonly config: any;
1412
1408
  }
1413
1409
  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> {
1414
1410
  #private;
1415
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1416
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1411
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
1412
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
1417
1413
  }
1418
1414
 
1419
1415
  declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1436,7 +1432,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1436
1432
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1437
1433
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1438
1434
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1439
- initInput: z$2.ZodOptional<z$2.ZodCustom<any, any>>;
1435
+ initInput: z$2.ZodOptional<z$2.ZodCustom<_rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
1440
1436
  }, z$2.core.$strip>>>;
1441
1437
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1442
1438
  local: "local";
@@ -1497,7 +1493,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1497
1493
  envoyKey: z$2.ZodOptional<z$2.ZodString>;
1498
1494
  }, z$2.core.$strip>>>;
1499
1495
  shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1500
- gracePeriodMs: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1496
+ gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
1501
1497
  disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1502
1498
  }, z$2.core.$strip>>>;
1503
1499
  }, z$2.core.$strip>, z$2.ZodTransform<{
@@ -1527,7 +1523,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1527
1523
  runtime: "auto" | "native" | "wasm";
1528
1524
  wasm: {
1529
1525
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1530
- initInput?: any;
1526
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1531
1527
  };
1532
1528
  noWelcome: boolean;
1533
1529
  logging: {
@@ -1546,8 +1542,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1546
1542
  envoyKey?: string | undefined;
1547
1543
  };
1548
1544
  shutdown: {
1549
- gracePeriodMs: number;
1550
1545
  disableSignalHandlers: boolean;
1546
+ gracePeriodMs?: number | undefined;
1551
1547
  };
1552
1548
  staticDir?: string | undefined;
1553
1549
  httpHost?: string | undefined;
@@ -1572,7 +1568,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1572
1568
  runtime: "auto" | "native" | "wasm";
1573
1569
  wasm: {
1574
1570
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1575
- initInput?: any;
1571
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1576
1572
  };
1577
1573
  sqlite: {
1578
1574
  backend: "local" | "remote";
@@ -1603,8 +1599,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1603
1599
  envoyKey?: string | undefined;
1604
1600
  };
1605
1601
  shutdown: {
1606
- gracePeriodMs: number;
1607
1602
  disableSignalHandlers: boolean;
1603
+ gracePeriodMs?: number | undefined;
1608
1604
  };
1609
1605
  staticDir?: string | undefined;
1610
1606
  httpHost?: string | undefined;
@@ -1624,6 +1620,318 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1624
1620
  use: A;
1625
1621
  };
1626
1622
 
1623
+ declare const handleBrand: unique symbol;
1624
+ type OpaqueHandle<Name extends string> = {
1625
+ readonly [handleBrand]: Name;
1626
+ };
1627
+ type RegistryHandle = OpaqueHandle<"registry">;
1628
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1629
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
1630
+ type ConnHandle = OpaqueHandle<"conn">;
1631
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
1632
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1633
+ type RuntimeBytes = Uint8Array;
1634
+ interface RuntimeActorKeySegment {
1635
+ kind: string;
1636
+ stringValue?: string;
1637
+ numberValue?: number;
1638
+ }
1639
+ interface RuntimeHttpRequest {
1640
+ method: string;
1641
+ uri: string;
1642
+ headers?: Record<string, string>;
1643
+ body?: RuntimeBytes;
1644
+ }
1645
+ interface RuntimeStateDeltaPayload {
1646
+ state?: RuntimeBytes;
1647
+ connHibernation: Array<{
1648
+ connId: string;
1649
+ bytes: RuntimeBytes;
1650
+ }>;
1651
+ connHibernationRemoved: string[];
1652
+ }
1653
+ interface RuntimeRequestSaveOpts {
1654
+ immediate?: boolean;
1655
+ maxWaitMs?: number;
1656
+ }
1657
+ interface RuntimeInspectorSnapshot {
1658
+ stateRevision: number;
1659
+ connectionsRevision: number;
1660
+ queueRevision: number;
1661
+ activeConnections: number;
1662
+ queueSize: number;
1663
+ connectedClients: number;
1664
+ }
1665
+ interface RuntimeQueueMessage {
1666
+ id(): bigint;
1667
+ name(): string;
1668
+ body(): RuntimeBytes;
1669
+ createdAt(): number;
1670
+ isCompletable(): boolean;
1671
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1672
+ }
1673
+ interface RuntimeQueueInspectMessage {
1674
+ id: number;
1675
+ name: string;
1676
+ createdAtMs: number;
1677
+ }
1678
+ interface RuntimeQueueNextBatchOptions {
1679
+ names?: string[];
1680
+ count?: number;
1681
+ timeoutMs?: number;
1682
+ completable?: boolean;
1683
+ }
1684
+ interface RuntimeQueueWaitOptions {
1685
+ timeoutMs?: number;
1686
+ completable?: boolean;
1687
+ }
1688
+ interface RuntimeQueueEnqueueAndWaitOptions {
1689
+ timeoutMs?: number;
1690
+ }
1691
+ interface RuntimeQueueTryNextBatchOptions {
1692
+ names?: string[];
1693
+ count?: number;
1694
+ completable?: boolean;
1695
+ }
1696
+ interface RuntimeKvListOptions {
1697
+ reverse?: boolean;
1698
+ limit?: number;
1699
+ }
1700
+ interface RuntimeKvEntry {
1701
+ key: RuntimeBytes;
1702
+ value: RuntimeBytes;
1703
+ }
1704
+ type RuntimeSqlBindNoValues = {
1705
+ intValue?: never;
1706
+ floatValue?: never;
1707
+ textValue?: never;
1708
+ blobValue?: never;
1709
+ };
1710
+ type RuntimeSqlBindParam = ({
1711
+ kind: "null";
1712
+ } & RuntimeSqlBindNoValues) | {
1713
+ kind: "int";
1714
+ intValue: number;
1715
+ floatValue?: never;
1716
+ textValue?: never;
1717
+ blobValue?: never;
1718
+ } | {
1719
+ kind: "float";
1720
+ intValue?: never;
1721
+ floatValue: number;
1722
+ textValue?: never;
1723
+ blobValue?: never;
1724
+ } | {
1725
+ kind: "text";
1726
+ intValue?: never;
1727
+ floatValue?: never;
1728
+ textValue: string;
1729
+ blobValue?: never;
1730
+ } | {
1731
+ kind: "blob";
1732
+ intValue?: never;
1733
+ floatValue?: never;
1734
+ textValue?: never;
1735
+ blobValue: RuntimeBytes;
1736
+ };
1737
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1738
+ interface RuntimeSqlQueryResult {
1739
+ columns: string[];
1740
+ rows: unknown[][];
1741
+ }
1742
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1743
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1744
+ changes: number;
1745
+ lastInsertRowId?: number | null;
1746
+ }
1747
+ interface RuntimeSqlRunResult {
1748
+ changes: number;
1749
+ }
1750
+ interface RuntimeActorConfig {
1751
+ name?: string;
1752
+ icon?: string;
1753
+ hasDatabase?: boolean;
1754
+ remoteSqlite?: boolean;
1755
+ hasState?: boolean;
1756
+ canHibernateWebsocket?: boolean;
1757
+ stateSaveIntervalMs?: number;
1758
+ createStateTimeoutMs?: number;
1759
+ onCreateTimeoutMs?: number;
1760
+ createVarsTimeoutMs?: number;
1761
+ createConnStateTimeoutMs?: number;
1762
+ onBeforeConnectTimeoutMs?: number;
1763
+ onConnectTimeoutMs?: number;
1764
+ onMigrateTimeoutMs?: number;
1765
+ onWakeTimeoutMs?: number;
1766
+ onBeforeActorStartTimeoutMs?: number;
1767
+ actionTimeoutMs?: number;
1768
+ onRequestTimeoutMs?: number;
1769
+ sleepTimeoutMs?: number;
1770
+ noSleep?: boolean;
1771
+ sleepGracePeriodMs?: number;
1772
+ connectionLivenessTimeoutMs?: number;
1773
+ connectionLivenessIntervalMs?: number;
1774
+ maxQueueSize?: number;
1775
+ maxQueueMessageSize?: number;
1776
+ maxIncomingMessageSize?: number;
1777
+ maxOutgoingMessageSize?: number;
1778
+ preloadMaxWorkflowBytes?: number;
1779
+ preloadMaxConnectionsBytes?: number;
1780
+ actions?: Array<{
1781
+ name: string;
1782
+ }>;
1783
+ }
1784
+ interface RuntimeServeConfig {
1785
+ version: number;
1786
+ endpoint: string;
1787
+ token?: string;
1788
+ namespace: string;
1789
+ poolName: string;
1790
+ engineBinaryPath?: string;
1791
+ handleInspectorHttpInRuntime?: boolean;
1792
+ inspectorTestToken?: string;
1793
+ serverlessBasePath?: string;
1794
+ serverlessPackageVersion: string;
1795
+ serverlessClientEndpoint?: string;
1796
+ serverlessClientNamespace?: string;
1797
+ serverlessClientToken?: string;
1798
+ serverlessValidateEndpoint: boolean;
1799
+ serverlessMaxStartPayloadBytes: number;
1800
+ }
1801
+ interface RuntimeServerlessRequest {
1802
+ method: string;
1803
+ url: string;
1804
+ headers: Record<string, string>;
1805
+ body: RuntimeBytes;
1806
+ }
1807
+ interface RuntimeServerlessResponseHead {
1808
+ status: number;
1809
+ headers: Record<string, string>;
1810
+ }
1811
+ interface RuntimeRegistryRouteResponse {
1812
+ status: number;
1813
+ headers: Record<string, string>;
1814
+ body: RuntimeBytes;
1815
+ }
1816
+ type RuntimeServerlessStreamEvent = {
1817
+ kind: "chunk";
1818
+ chunk?: RuntimeBytes;
1819
+ } | {
1820
+ kind: "end";
1821
+ error?: {
1822
+ group: string;
1823
+ code: string;
1824
+ message: string;
1825
+ };
1826
+ };
1827
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1828
+ type RuntimeWebSocketEvent = {
1829
+ kind: "message";
1830
+ data: string | RuntimeBytes;
1831
+ binary: boolean;
1832
+ messageIndex?: number;
1833
+ } | {
1834
+ kind: "close";
1835
+ code: number;
1836
+ reason: string;
1837
+ wasClean: boolean;
1838
+ };
1839
+ interface CoreRuntime {
1840
+ readonly kind: "napi" | "wasm";
1841
+ createRegistry(): RegistryHandle;
1842
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1843
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1844
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
1845
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1846
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1847
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1848
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1849
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1850
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1851
+ createCancellationToken(): CancellationTokenHandle;
1852
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1853
+ cancelCancellationToken(token: CancellationTokenHandle): void;
1854
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1855
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
1856
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
1857
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
1858
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1859
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1860
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1861
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1862
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1863
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1864
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1865
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1866
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1867
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1868
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1869
+ actorId(ctx: ActorContextHandle): string;
1870
+ actorName(ctx: ActorContextHandle): string;
1871
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1872
+ actorRegion(ctx: ActorContextHandle): string;
1873
+ actorSleep(ctx: ActorContextHandle): void;
1874
+ actorDestroy(ctx: ActorContextHandle): void;
1875
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1876
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
1877
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1878
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1879
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1880
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1881
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1882
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1883
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
1884
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1885
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1886
+ actorRuntimeState(ctx: ActorContextHandle): object;
1887
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
1888
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
1889
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1890
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1891
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1892
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1893
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1894
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1895
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1896
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1897
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1898
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1899
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1900
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1901
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1902
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1903
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1904
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1905
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1906
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1907
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1908
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1909
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1910
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1911
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1912
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1913
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1914
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1915
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1916
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1917
+ connId(conn: ConnHandle): string;
1918
+ connParams(conn: ConnHandle): RuntimeBytes;
1919
+ connState(conn: ConnHandle): RuntimeBytes;
1920
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1921
+ connIsHibernatable(conn: ConnHandle): boolean;
1922
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1923
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1924
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1925
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1926
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1927
+ }
1928
+
1929
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
1930
+ runtime: CoreRuntime;
1931
+ registry: RegistryHandle;
1932
+ serveConfig: RuntimeServeConfig;
1933
+ }>;
1934
+
1627
1935
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1628
1936
  interface ServerlessHandler {
1629
1937
  fetch: FetchHandler;
@@ -1633,12 +1941,20 @@ interface RegistryRoutes {
1633
1941
  metadata(): Promise<Response>;
1634
1942
  prometheusMetrics(request?: Request): Promise<Response>;
1635
1943
  }
1944
+ /**
1945
+ * Injectable dependencies for {@link Registry}. Production code uses the
1946
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
1947
+ * orchestration against a fake `CoreRuntime` without an engine.
1948
+ */
1949
+ interface RegistryDeps {
1950
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
1951
+ }
1636
1952
  declare class Registry<A extends RegistryActors> {
1637
1953
  #private;
1638
1954
  readonly routes: RegistryRoutes;
1639
1955
  get config(): RegistryConfigInput<A>;
1640
1956
  parseConfig(): RegistryConfig;
1641
- constructor(config: RegistryConfigInput<A>);
1957
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1642
1958
  /**
1643
1959
  * Handle an incoming HTTP request for serverless deployments.
1644
1960
  *
@@ -1678,6 +1994,27 @@ declare class Registry<A extends RegistryActors> {
1678
1994
  port?: number;
1679
1995
  publicDir?: string;
1680
1996
  }): Promise<void>;
1997
+ /**
1998
+ * Gracefully drains all live registries.
1999
+ *
2000
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2001
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2002
+ * waits for the serve promise to resolve, all bounded by the shutdown
2003
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2004
+ * signal or exit the process. The caller owns process lifetime.
2005
+ *
2006
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2007
+ * call even if nothing has been started.
2008
+ *
2009
+ * @example
2010
+ * ```ts
2011
+ * const registry = setup({ use: { counter } });
2012
+ * registry.start();
2013
+ * // ...later, on your own shutdown trigger:
2014
+ * await registry.shutdown();
2015
+ * ```
2016
+ */
2017
+ shutdown(): Promise<void>;
1681
2018
  startEnvoy(): void;
1682
2019
  /**
1683
2020
  * Starts the actor envoy for standalone server deployments.
@@ -145,7 +145,7 @@ function deconstructError(error, exposeInternalError = false) {
145
145
  actor = error.actor;
146
146
  }
147
147
  metadata = {
148
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
148
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
149
149
  };
150
150
  }
151
151
  return {
@@ -200,7 +200,7 @@ function noopNext() {
200
200
  // package.json
201
201
  var package_default = {
202
202
  name: "rivetkit",
203
- version: "2.3.0-rc.11",
203
+ version: "2.3.0-rc.12",
204
204
  description: "Lightweight libraries for building stateful actors on edge platforms",
205
205
  license: "Apache-2.0",
206
206
  keywords: [
@@ -6537,8 +6537,9 @@ var ActorHandleRaw = class {
6537
6537
  this.#gatewayOptions,
6538
6538
  options
6539
6539
  );
6540
+ const useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
6540
6541
  const target = await this.#resolveGatewayRequestTarget(
6541
- false,
6542
+ useQueryTarget,
6542
6543
  gatewayOptions
6543
6544
  );
6544
6545
  return await rawWebSocket(