rivetkit 3.0.1-preview.2 → 3.0.2

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 (113) hide show
  1. package/dist/browser/client.d.ts +78 -7
  2. package/dist/browser/client.js +67 -7
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +4 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/{chunk-4QJQH4T4.cjs → chunk-3C5KLO4V.cjs} +4 -4
  7. package/dist/tsup/{chunk-4QJQH4T4.cjs.map → chunk-3C5KLO4V.cjs.map} +1 -1
  8. package/dist/tsup/{chunk-BSGU45BD.cjs → chunk-3KVVYC5I.cjs} +202 -145
  9. package/dist/tsup/chunk-3KVVYC5I.cjs.map +1 -0
  10. package/dist/tsup/{chunk-JRLVFBMY.js → chunk-3RE23GTB.js} +9 -3
  11. package/dist/tsup/chunk-3RE23GTB.js.map +1 -0
  12. package/dist/tsup/{chunk-SD3PQA7R.js → chunk-47W6FHPJ.js} +2 -2
  13. package/dist/tsup/{chunk-JKTXQQEE.js → chunk-4ASLJWUQ.js} +4 -4
  14. package/dist/tsup/{chunk-G5VHMGDB.js → chunk-ANP7UCAM.js} +66 -9
  15. package/dist/tsup/chunk-ANP7UCAM.js.map +1 -0
  16. package/dist/tsup/{chunk-LNYYP2PY.cjs → chunk-BBEH6RML.cjs} +3 -3
  17. package/dist/tsup/{chunk-LNYYP2PY.cjs.map → chunk-BBEH6RML.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-AGQUQEZM.cjs → chunk-DVXMOEFT.cjs} +7 -7
  19. package/dist/tsup/{chunk-AGQUQEZM.cjs.map → chunk-DVXMOEFT.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-N7UDXIJN.cjs → chunk-FR5QOAYE.cjs} +10 -10
  21. package/dist/tsup/{chunk-N7UDXIJN.cjs.map → chunk-FR5QOAYE.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-OOHHMLQX.js → chunk-HJWK46Z5.js} +3 -3
  23. package/dist/tsup/{chunk-CEUOGGOM.js → chunk-J7T52LN6.js} +2 -2
  24. package/dist/tsup/{chunk-4E76XTEX.cjs → chunk-KF7ETIFK.cjs} +3 -3
  25. package/dist/tsup/{chunk-4E76XTEX.cjs.map → chunk-KF7ETIFK.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-FUSYDRMB.cjs → chunk-M3H37DUQ.cjs} +9 -3
  27. package/dist/tsup/chunk-M3H37DUQ.cjs.map +1 -0
  28. package/dist/tsup/{chunk-BT4SSKF6.cjs → chunk-M7KPJSGO.cjs} +3 -3
  29. package/dist/tsup/{chunk-BT4SSKF6.cjs.map → chunk-M7KPJSGO.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-GPKL6OTF.js → chunk-OF63EVJQ.js} +2 -2
  31. package/dist/tsup/{chunk-HDVZ6YZG.cjs → chunk-SSF2XC33.cjs} +1 -1
  32. package/dist/tsup/chunk-SSF2XC33.cjs.map +1 -0
  33. package/dist/tsup/{chunk-6FEYCVZC.js → chunk-UXDASKP6.js} +1 -1
  34. package/dist/tsup/chunk-UXDASKP6.js.map +1 -0
  35. package/dist/tsup/{chunk-O3HSYSUU.js → chunk-ZAZAKYNQ.js} +2 -2
  36. package/dist/tsup/client/mod.cjs +5 -5
  37. package/dist/tsup/client/mod.d.cts +3 -3
  38. package/dist/tsup/client/mod.d.ts +3 -3
  39. package/dist/tsup/client/mod.js +4 -4
  40. package/dist/tsup/common/log.cjs +2 -2
  41. package/dist/tsup/common/log.js +1 -1
  42. package/dist/tsup/common/websocket.cjs +3 -3
  43. package/dist/tsup/common/websocket.js +2 -2
  44. package/dist/tsup/{config-DJ3KW-fe.d.ts → config-BtUHYdoj.d.ts} +23 -1
  45. package/dist/tsup/{config-B2wlj9wx.d.ts → config-CBTr4IhE.d.cts} +50 -8
  46. package/dist/tsup/{config-B2wlj9wx.d.cts → config-CBTr4IhE.d.ts} +50 -8
  47. package/dist/tsup/{config-8NgsxIcT.d.cts → config-H6pJy_J1.d.cts} +23 -1
  48. package/dist/tsup/{context-BL8kUGjq.d.ts → context-DrDoMXSD.d.ts} +2 -2
  49. package/dist/tsup/{context-_RoE_YHL.d.cts → context-TWrKZjqf.d.cts} +2 -2
  50. package/dist/tsup/db/drizzle.cjs +2 -2
  51. package/dist/tsup/db/drizzle.d.cts +1 -1
  52. package/dist/tsup/db/drizzle.d.ts +1 -1
  53. package/dist/tsup/db/drizzle.js +1 -1
  54. package/dist/tsup/db/mod.cjs +3 -3
  55. package/dist/tsup/db/mod.d.cts +2 -2
  56. package/dist/tsup/db/mod.d.ts +2 -2
  57. package/dist/tsup/db/mod.js +2 -2
  58. package/dist/tsup/dynamic/mod.cjs +2 -2
  59. package/dist/tsup/dynamic/mod.d.cts +2 -2
  60. package/dist/tsup/dynamic/mod.d.ts +2 -2
  61. package/dist/tsup/dynamic/mod.js +1 -1
  62. package/dist/tsup/inspector/mod.cjs +5 -5
  63. package/dist/tsup/inspector/mod.js +4 -4
  64. package/dist/tsup/inspector/workflow.cjs +4 -4
  65. package/dist/tsup/inspector/workflow.js +3 -3
  66. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  67. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  68. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  69. package/dist/tsup/inspector-tab/mod.js +1 -1
  70. package/dist/tsup/mod.cjs +258 -125
  71. package/dist/tsup/mod.cjs.map +1 -1
  72. package/dist/tsup/mod.d.cts +4 -4
  73. package/dist/tsup/mod.d.ts +4 -4
  74. package/dist/tsup/mod.js +159 -26
  75. package/dist/tsup/mod.js.map +1 -1
  76. package/dist/tsup/test/mod.cjs +6 -6
  77. package/dist/tsup/test/mod.d.cts +2 -2
  78. package/dist/tsup/test/mod.d.ts +2 -2
  79. package/dist/tsup/test/mod.js +4 -4
  80. package/dist/tsup/unstable/migrations.d.cts +1 -1
  81. package/dist/tsup/unstable/migrations.d.ts +1 -1
  82. package/dist/tsup/utils.cjs +2 -2
  83. package/dist/tsup/utils.js +1 -1
  84. package/dist/tsup/workflow/mod.cjs +10 -10
  85. package/dist/tsup/workflow/mod.cjs.map +1 -1
  86. package/dist/tsup/workflow/mod.d.cts +4 -4
  87. package/dist/tsup/workflow/mod.d.ts +4 -4
  88. package/dist/tsup/workflow/mod.js +5 -5
  89. package/package.json +12 -9
  90. package/src/actor/config.ts +2 -0
  91. package/src/client/actor-handle.ts +43 -7
  92. package/src/client/raw-utils.ts +17 -3
  93. package/src/client/utils.ts +4 -0
  94. package/src/common/database/config.ts +50 -7
  95. package/src/db/mod.ts +1 -0
  96. package/src/registry/config/index.ts +7 -5
  97. package/src/registry/index.ts +142 -1
  98. package/src/registry/napi-runtime.ts +15 -0
  99. package/src/registry/native.ts +24 -17
  100. package/src/registry/runtime.ts +7 -1
  101. package/src/utils/env-vars.ts +4 -2
  102. package/dist/tsup/chunk-6FEYCVZC.js.map +0 -1
  103. package/dist/tsup/chunk-BSGU45BD.cjs.map +0 -1
  104. package/dist/tsup/chunk-FUSYDRMB.cjs.map +0 -1
  105. package/dist/tsup/chunk-G5VHMGDB.js.map +0 -1
  106. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +0 -1
  107. package/dist/tsup/chunk-JRLVFBMY.js.map +0 -1
  108. /package/dist/tsup/{chunk-SD3PQA7R.js.map → chunk-47W6FHPJ.js.map} +0 -0
  109. /package/dist/tsup/{chunk-JKTXQQEE.js.map → chunk-4ASLJWUQ.js.map} +0 -0
  110. /package/dist/tsup/{chunk-OOHHMLQX.js.map → chunk-HJWK46Z5.js.map} +0 -0
  111. /package/dist/tsup/{chunk-CEUOGGOM.js.map → chunk-J7T52LN6.js.map} +0 -0
  112. /package/dist/tsup/{chunk-GPKL6OTF.js.map → chunk-OF63EVJQ.js.map} +0 -0
  113. /package/dist/tsup/{chunk-O3HSYSUU.js.map → chunk-ZAZAKYNQ.js.map} +0 -0
@@ -51,13 +51,16 @@ interface SqliteTransactionOptions {
51
51
  * to change without notice.
52
52
  */
53
53
  interface SqliteProfilingOptions {
54
- /** Exact SQL statements to give fingerprint labels. Profiling defaults to actor
55
- * aggregates without fingerprint labels. Profile logs remain enabled.
56
- * RIVETKIT_SQLITE_PROFILING overrides selection with a JSON object containing
57
- * queries and/or fingerprints arrays. An empty object clears fingerprint selection. */
58
- queries?: string[];
59
- /** Exact query fingerprints to label separately, as reported in profile logs. */
60
- fingerprints?: string[];
54
+ /** Exact SQL filter. Union with filterQueryFingerprints; both empty means all queries. */
55
+ filterQueries?: string[];
56
+ /** Fingerprint filter, including transaction fingerprints. Filters metrics, not diagnostic logs. */
57
+ filterQueryFingerprints?: string[];
58
+ /** Metric defaults apply even when omitted. Disabled metrics allocate no series. */
59
+ metrics?: SqliteProfilingMetricsOptions;
60
+ /** Duration buckets in seconds. Default [0.01, 0.1, 1]. Positive, finite, strictly increasing.
61
+ * All actors in a process enabling the duration histogram must use identical buckets. */
62
+ durationHistogramBucketsSeconds?: number[];
63
+ /** Maximum distinct statement fingerprints per process. Default: 512. */
61
64
  maxTrackedStatementFingerprints?: number;
62
65
  maxTrackedTransactionFingerprints?: number;
63
66
  maxPrometheusSeries?: number;
@@ -69,6 +72,45 @@ interface SqliteProfilingOptions {
69
72
  maxDiagnosticEventsPerMinute?: number;
70
73
  diagnosticEventQueueCapacity?: number;
71
74
  }
75
+ /** SQLite profiling metrics. Physical-request metrics and gauges have no query labels. */
76
+ interface SqliteProfilingMetricsOptions {
77
+ /** Execution count and cumulative seconds. Uses histogram count/sum when enabled, otherwise counters. Default: true. */
78
+ duration?: boolean;
79
+ /** Execution duration histogram. Only applies when duration is enabled. Default: true. */
80
+ durationHistogram?: boolean;
81
+ /** Outcome counters, including success and errors. Default: true. */
82
+ outcomes?: boolean;
83
+ /** Per-query timing phase histograms. Default: false. */
84
+ phaseDurationHistogram?: boolean;
85
+ /** Storage round trips per operation histogram. Default: false. */
86
+ getPagesRoundTripsHistogram?: boolean;
87
+ /** Statements per transaction histogram. Default: false. */
88
+ transactionStatementCountHistogram?: boolean;
89
+ /** Per-query pages returned from storage, including returned prefetch pages. Default: true. */
90
+ pagesFetched?: boolean;
91
+ /** Actor-level page counters by page kind (no query labels). Default: false. */
92
+ localPages?: boolean;
93
+ /** Actor-level byte counters by byte kind (no query labels). Default: false. */
94
+ localBytes?: boolean;
95
+ /** Actor-level physical storage request duration histogram. Default: false. */
96
+ getPagesDurationHistogram?: boolean;
97
+ /** Actor-level pages per storage request histograms, by page kind. Default: false. */
98
+ getPagesPagesHistogram?: boolean;
99
+ /** Actor-level storage response byte histogram. Default: false. */
100
+ getPagesResponseBytesHistogram?: boolean;
101
+ /** Actor-level missing response page counter. Default: false. */
102
+ getPagesMissingPages?: boolean;
103
+ /** Queued SQLite work, aggregated by actor name. Default: true. */
104
+ workerQueueDepth?: boolean;
105
+ /** Executing SQLite work, aggregated by actor name. Default: true. */
106
+ workerInflight?: boolean;
107
+ /** Transaction waiters, aggregated by actor name. Default: true. */
108
+ coordinatorQueueDepth?: boolean;
109
+ /** Counts observations exceeding fingerprint or series limits. Default: true. */
110
+ fingerprintOverflow?: boolean;
111
+ /** Counts diagnostic events dropped by rate limits or backpressure. Default: true. */
112
+ eventDropped?: boolean;
113
+ }
72
114
  interface SqliteNativeMetrics {
73
115
  requestBuildNs: number;
74
116
  serializeNs: number;
@@ -839,6 +881,8 @@ interface CoreRuntime {
839
881
  shutdownRegistry(registry: RegistryHandle): Promise<void>;
840
882
  shutdownTelemetry?(): Promise<void>;
841
883
  registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
884
+ registryActiveActorCount?(registry: RegistryHandle): number;
885
+ onRegistryActiveActorCountChange?(registry: RegistryHandle, callback: (count: number) => void, cancelToken: CancellationTokenHandle): void;
842
886
  handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
843
887
  serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
844
888
  serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
@@ -1757,6 +1801,13 @@ type CronJobInfo = {
1757
1801
  kind: "every";
1758
1802
  interval: number;
1759
1803
  });
1804
+ interface ScheduledFireInfo {
1805
+ kind: "at" | "cron" | "every";
1806
+ id: string;
1807
+ name?: string;
1808
+ scheduledAt: number;
1809
+ firedAt: number;
1810
+ }
1760
1811
  interface CronFire {
1761
1812
  action: string;
1762
1813
  scheduledAt: number;
@@ -1930,6 +1981,8 @@ interface ActorRun {
1930
1981
  runOutsideWorkflowSpan<T>(body: () => T): T;
1931
1982
  }
1932
1983
  type ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & {
1984
+ /** Present only when a durable schedule or cron invokes this action. */
1985
+ readonly scheduledFire?: ScheduledFireInfo;
1933
1986
  conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1934
1987
  };
1935
1988
  type BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
@@ -2624,6 +2677,24 @@ declare class Registry<A extends RegistryActors> {
2624
2677
  * ```
2625
2678
  */
2626
2679
  start(): void;
2680
+ /**
2681
+ * Returns the number of actors hosted by this process's envoy, which is zero
2682
+ * while it is not serving. Requires the native runtime.
2683
+ */
2684
+ activeActorCount(): number;
2685
+ /**
2686
+ * Calls `callback` with the number of actors hosted by this process's envoy
2687
+ * and again whenever it changes. Rapid changes may coalesce.
2688
+ * Returns a function that unsubscribes. Requires the native runtime.
2689
+ *
2690
+ * @example
2691
+ * ```ts
2692
+ * const unsubscribe = registry.onActiveActorCountChange((count) => {
2693
+ * setTaskProtection(count > 0);
2694
+ * });
2695
+ * ```
2696
+ */
2697
+ onActiveActorCountChange(callback: (count: number) => void): () => void;
2627
2698
  }
2628
2699
 
2629
2700
  /**
@@ -230,7 +230,7 @@ function noopNext() {
230
230
  // package.json
231
231
  var package_default = {
232
232
  name: "rivetkit",
233
- version: "3.0.1-preview.2",
233
+ version: "3.0.2",
234
234
  description: "Lightweight libraries for building stateful actors on edge platforms",
235
235
  license: "Apache-2.0",
236
236
  keywords: [
@@ -478,6 +478,9 @@ var package_default = {
478
478
  vitest: "^3.1.1",
479
479
  ws: "^8.18.1"
480
480
  },
481
+ optionalDependencies: {
482
+ "@rivet-dev/services": "^0.2.5"
483
+ },
481
484
  peerDependencies: {
482
485
  "drizzle-kit": "^0.31.2",
483
486
  eventsource: "^4.0.0",
@@ -3966,6 +3969,9 @@ async function sendHttpRequest(opts) {
3966
3969
  })
3967
3970
  );
3968
3971
  } catch (error) {
3972
+ if (RivetError.isRivetError(error)) {
3973
+ throw error;
3974
+ }
3969
3975
  throw new HttpRequestError(`Request failed: ${error}`, {
3970
3976
  cause: error
3971
3977
  });
@@ -6535,8 +6541,23 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}, t
6535
6541
  });
6536
6542
  return driver.sendRequest(target, proxyRequest, options);
6537
6543
  } catch (err) {
6538
- const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
6539
- throw new RivetError(group, code, message, { metadata, rayId, actor });
6544
+ const {
6545
+ group,
6546
+ code,
6547
+ message,
6548
+ metadata,
6549
+ rayId,
6550
+ actor,
6551
+ public: isPublic,
6552
+ statusCode
6553
+ } = deconstructError(err, true);
6554
+ throw new RivetError(group, code, message, {
6555
+ public: isPublic,
6556
+ statusCode,
6557
+ metadata,
6558
+ rayId,
6559
+ actor
6560
+ });
6540
6561
  }
6541
6562
  }
6542
6563
  async function rawWebSocket(driver, target, params, path, _protocols, options = {}) {
@@ -6693,7 +6714,16 @@ var ActorHandleRaw = class {
6693
6714
  }
6694
6715
  }).send(name, body, options);
6695
6716
  } catch (err) {
6696
- const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
6717
+ const {
6718
+ group,
6719
+ code,
6720
+ message,
6721
+ metadata,
6722
+ rayId,
6723
+ actor,
6724
+ public: isPublic,
6725
+ statusCode
6726
+ } = deconstructError(err, true);
6697
6727
  if (this.#shouldRetryQueueDispatchOverload(
6698
6728
  group,
6699
6729
  code,
@@ -6749,6 +6779,8 @@ var ActorHandleRaw = class {
6749
6779
  continue;
6750
6780
  }
6751
6781
  throw new RivetError(group, code, message, {
6782
+ public: isPublic,
6783
+ statusCode,
6752
6784
  metadata,
6753
6785
  rayId,
6754
6786
  actor
@@ -6872,7 +6904,16 @@ var ActorHandleRaw = class {
6872
6904
  }
6873
6905
  return output;
6874
6906
  } catch (err) {
6875
- const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
6907
+ const {
6908
+ group,
6909
+ code,
6910
+ message,
6911
+ metadata,
6912
+ rayId,
6913
+ actor,
6914
+ public: isPublic,
6915
+ statusCode
6916
+ } = deconstructError(err, true);
6876
6917
  if (await this.#shouldRetrySchedulingError(
6877
6918
  group,
6878
6919
  code,
@@ -6901,7 +6942,13 @@ var ActorHandleRaw = class {
6901
6942
  "actor",
6902
6943
  "not_found",
6903
6944
  "The actor does not exist or was destroyed.",
6904
- { metadata, rayId, actor }
6945
+ {
6946
+ public: true,
6947
+ statusCode: 404,
6948
+ metadata,
6949
+ rayId,
6950
+ actor
6951
+ }
6905
6952
  );
6906
6953
  }
6907
6954
  const invalidated = this.#invalidateResolvedActorId(
@@ -6918,6 +6965,8 @@ var ActorHandleRaw = class {
6918
6965
  continue;
6919
6966
  }
6920
6967
  throw new RivetError(group, code, message, {
6968
+ public: isPublic,
6969
+ statusCode,
6921
6970
  metadata,
6922
6971
  rayId,
6923
6972
  actor
@@ -7104,7 +7153,16 @@ var ActorHandleRaw = class {
7104
7153
  }
7105
7154
  return response;
7106
7155
  } catch (err) {
7107
- const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
7156
+ const {
7157
+ group,
7158
+ code,
7159
+ message,
7160
+ metadata,
7161
+ rayId,
7162
+ actor,
7163
+ public: isPublic,
7164
+ statusCode
7165
+ } = deconstructError(err, true);
7108
7166
  if (await this.#shouldRetrySchedulingError(
7109
7167
  group,
7110
7168
  code,
@@ -7141,6 +7199,8 @@ var ActorHandleRaw = class {
7141
7199
  continue;
7142
7200
  }
7143
7201
  throw new RivetError(group, code, message, {
7202
+ public: isPublic,
7203
+ statusCode,
7144
7204
  metadata,
7145
7205
  rayId,
7146
7206
  actor