rivetkit 2.3.19 → 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.
Files changed (101) hide show
  1. package/dist/browser/client.d.ts +39 -0
  2. package/dist/browser/client.js +1 -1
  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 +34 -1
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +39 -0
  9. package/dist/tsup/agent-os/index.d.ts +39 -0
  10. package/dist/tsup/agent-os/index.js +34 -1
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-RJC5O2SD.cjs → chunk-2CE5UNWK.cjs} +2 -2
  13. package/dist/tsup/{chunk-RJC5O2SD.cjs.map → chunk-2CE5UNWK.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-7HTST3NX.js → chunk-2NXLTFWI.js} +3 -3
  15. package/dist/tsup/{chunk-OGPFN6BT.cjs → chunk-3WS7Z64U.cjs} +3 -3
  16. package/dist/tsup/{chunk-OGPFN6BT.cjs.map → chunk-3WS7Z64U.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-X7RMJQGY.js → chunk-553CIQJY.js} +2 -2
  18. package/dist/tsup/{chunk-BKX7UDTA.js → chunk-5G2J26VM.js} +3 -3
  19. package/dist/tsup/{chunk-PPEIPCW4.cjs → chunk-76YTS32R.cjs} +4 -4
  20. package/dist/tsup/{chunk-PPEIPCW4.cjs.map → chunk-76YTS32R.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-IJUXBWH4.cjs → chunk-A36FMKOV.cjs} +138 -138
  22. package/dist/tsup/{chunk-IJUXBWH4.cjs.map → chunk-A36FMKOV.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-EB77NZL4.js → chunk-CSOHAAZK.js} +33 -1
  24. package/dist/tsup/chunk-CSOHAAZK.js.map +1 -0
  25. package/dist/tsup/{chunk-Z4RAXFSD.cjs → chunk-CVLNRT7O.cjs} +3 -3
  26. package/dist/tsup/{chunk-Z4RAXFSD.cjs.map → chunk-CVLNRT7O.cjs.map} +1 -1
  27. package/dist/tsup/{chunk-DN6MD3KK.js → chunk-DHWZTUKA.js} +2 -2
  28. package/dist/tsup/{chunk-DN6MD3KK.js.map → chunk-DHWZTUKA.js.map} +1 -1
  29. package/dist/tsup/{chunk-464WE4RF.js → chunk-DMQUERRN.js} +2 -2
  30. package/dist/tsup/{chunk-G4U5L6AX.cjs → chunk-IHKDFKM4.cjs} +3 -3
  31. package/dist/tsup/{chunk-G4U5L6AX.cjs.map → chunk-IHKDFKM4.cjs.map} +1 -1
  32. package/dist/tsup/{chunk-EO5UOXXY.cjs → chunk-NWCAIWHL.cjs} +34 -2
  33. package/dist/tsup/chunk-NWCAIWHL.cjs.map +1 -0
  34. package/dist/tsup/{chunk-7A5EIXJJ.cjs → chunk-RSIOGT2U.cjs} +7 -7
  35. package/dist/tsup/{chunk-7A5EIXJJ.cjs.map → chunk-RSIOGT2U.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-4SC2NSAV.js → chunk-SNNVRHLX.js} +2 -2
  37. package/dist/tsup/{chunk-DK3L22R6.js → chunk-TZVAVPGJ.js} +4 -4
  38. package/dist/tsup/{chunk-WME6KOXW.js → chunk-W2PXGWMR.js} +2 -2
  39. package/dist/tsup/{chunk-7BRRGBRY.cjs → chunk-WAISW7KR.cjs} +10 -10
  40. package/dist/tsup/{chunk-7BRRGBRY.cjs.map → chunk-WAISW7KR.cjs.map} +1 -1
  41. package/dist/tsup/client/mod.cjs +5 -5
  42. package/dist/tsup/client/mod.d.cts +2 -2
  43. package/dist/tsup/client/mod.d.ts +2 -2
  44. package/dist/tsup/client/mod.js +4 -4
  45. package/dist/tsup/common/log.cjs +2 -2
  46. package/dist/tsup/common/log.js +1 -1
  47. package/dist/tsup/common/websocket.cjs +3 -3
  48. package/dist/tsup/common/websocket.js +2 -2
  49. package/dist/tsup/{config-DEm0yIVV.d.ts → config-Be-VOHaX.d.ts} +42 -2
  50. package/dist/tsup/{config-8n2AOhXK.d.cts → config-Ct5uXxXk.d.cts} +42 -2
  51. package/dist/tsup/{context-DGg2-IOm.d.ts → context-CXLa0BIM.d.ts} +1 -1
  52. package/dist/tsup/{context-DwjOVvlE.d.cts → context-Cw-11Q-B.d.cts} +1 -1
  53. package/dist/tsup/db/drizzle.cjs +2 -2
  54. package/dist/tsup/db/drizzle.js +1 -1
  55. package/dist/tsup/db/mod.cjs +3 -3
  56. package/dist/tsup/db/mod.js +2 -2
  57. package/dist/tsup/dynamic/mod.cjs +2 -2
  58. package/dist/tsup/dynamic/mod.d.cts +1 -1
  59. package/dist/tsup/dynamic/mod.d.ts +1 -1
  60. package/dist/tsup/dynamic/mod.js +1 -1
  61. package/dist/tsup/inspector/mod.cjs +5 -5
  62. package/dist/tsup/inspector/mod.js +4 -4
  63. package/dist/tsup/inspector/workflow.cjs +4 -4
  64. package/dist/tsup/inspector/workflow.js +3 -3
  65. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  66. package/dist/tsup/inspector-tab/mod.d.cts +2 -2
  67. package/dist/tsup/inspector-tab/mod.d.ts +2 -2
  68. package/dist/tsup/inspector-tab/mod.js +1 -1
  69. package/dist/tsup/mod.cjs +115 -101
  70. package/dist/tsup/mod.cjs.map +1 -1
  71. package/dist/tsup/mod.d.cts +3 -3
  72. package/dist/tsup/mod.d.ts +3 -3
  73. package/dist/tsup/mod.js +20 -6
  74. package/dist/tsup/mod.js.map +1 -1
  75. package/dist/tsup/test/mod.cjs +6 -6
  76. package/dist/tsup/test/mod.d.cts +1 -1
  77. package/dist/tsup/test/mod.d.ts +1 -1
  78. package/dist/tsup/test/mod.js +4 -4
  79. package/dist/tsup/utils.cjs +2 -2
  80. package/dist/tsup/utils.js +1 -1
  81. package/dist/tsup/workflow/mod.cjs +10 -10
  82. package/dist/tsup/workflow/mod.d.cts +3 -3
  83. package/dist/tsup/workflow/mod.d.ts +3 -3
  84. package/dist/tsup/workflow/mod.js +5 -5
  85. package/package.json +8 -8
  86. package/src/actor/actions.ts +36 -0
  87. package/src/actor/config.ts +27 -0
  88. package/src/actor/definition.ts +6 -1
  89. package/src/actor/mod.ts +5 -0
  90. package/src/actor/tracing.ts +28 -0
  91. package/src/registry/native.ts +18 -0
  92. package/src/registry/runtime.ts +8 -0
  93. package/dist/tsup/chunk-EB77NZL4.js.map +0 -1
  94. package/dist/tsup/chunk-EO5UOXXY.cjs.map +0 -1
  95. /package/dist/tsup/{chunk-7HTST3NX.js.map → chunk-2NXLTFWI.js.map} +0 -0
  96. /package/dist/tsup/{chunk-X7RMJQGY.js.map → chunk-553CIQJY.js.map} +0 -0
  97. /package/dist/tsup/{chunk-BKX7UDTA.js.map → chunk-5G2J26VM.js.map} +0 -0
  98. /package/dist/tsup/{chunk-464WE4RF.js.map → chunk-DMQUERRN.js.map} +0 -0
  99. /package/dist/tsup/{chunk-4SC2NSAV.js.map → chunk-SNNVRHLX.js.map} +0 -0
  100. /package/dist/tsup/{chunk-DK3L22R6.js.map → chunk-TZVAVPGJ.js.map} +0 -0
  101. /package/dist/tsup/{chunk-WME6KOXW.js.map → chunk-W2PXGWMR.js.map} +0 -0
@@ -543,6 +543,29 @@ declare class RivetError extends Error {
543
543
  toString(): string;
544
544
  }
545
545
 
546
+ /** Sample rates keyed by action name, nested like the actor's action groups. */
547
+ interface ActionSampleRates {
548
+ readonly [name: string]: number | ActionSampleRates;
549
+ }
550
+ /**
551
+ * {@link ActionSampleRates} limited to the actions of one actor, so a rate for
552
+ * an action that does not exist is a compile error.
553
+ */
554
+ type ActionTraceSamplers<TActions> = {
555
+ readonly [K in keyof TActions]?: TActions[K] extends (...args: never[]) => unknown ? number : ActionTraceSamplers<TActions[K]>;
556
+ };
557
+ /** Trace sampling for one actor definition. */
558
+ interface ActorTracingOptions<TActions> {
559
+ /**
560
+ * Share of this actor's invocations that are recorded, from 0 to 1. A rate
561
+ * lowers what is recorded and never raises it, so an invocation inside a
562
+ * trace the caller did not record is not recorded at any rate.
563
+ */
564
+ readonly sampler?: number;
565
+ /** Rates that replace `sampler` for single actions. */
566
+ readonly actions?: ActionTraceSamplers<TActions>;
567
+ }
568
+
546
569
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
547
570
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
548
571
 
@@ -842,12 +865,19 @@ interface RuntimeSqlBatchStatement {
842
865
  interface RuntimeSqlRunResult {
843
866
  changes: number;
844
867
  }
868
+ /** Sample rates for the traces an actor starts, in the shape core takes. */
869
+ interface RuntimeActorTracingConfig {
870
+ sampler?: number;
871
+ /** Keyed by flattened, dot-separated action name. */
872
+ actions?: Record<string, number>;
873
+ }
845
874
  interface RuntimeActorConfig {
846
875
  name?: string;
847
876
  icon?: string;
848
877
  hasDatabase?: boolean;
849
878
  remoteSqlite?: boolean;
850
879
  sqliteProfiling?: SqliteProfilingOptions;
880
+ tracing?: RuntimeActorTracingConfig;
851
881
  enableActorRuntimeSocket?: boolean;
852
882
  hasState?: boolean;
853
883
  canHibernateWebsocket?: boolean;
@@ -2115,6 +2145,10 @@ declare const ActorConfigSchema: z$1.ZodObject<{
2115
2145
  onWebSocket: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2116
2146
  actions: z$1.ZodDefault<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
2117
2147
  actionInputSchemas: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
2148
+ tracing: z$1.ZodOptional<z$1.ZodObject<{
2149
+ sampler: z$1.ZodOptional<z$1.ZodNumber>;
2150
+ actions: z$1.ZodOptional<z$1.ZodType<ActionSampleRates, unknown, z$1.core.$ZodTypeInternals<ActionSampleRates, unknown>>>;
2151
+ }, z$1.core.$strict>>;
2118
2152
  connParamsSchema: z$1.ZodOptional<z$1.ZodAny>;
2119
2153
  events: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
2120
2154
  queues: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
@@ -2355,6 +2389,11 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
2355
2389
  * May mirror nested action groups or use dot-separated low-level action names.
2356
2390
  */
2357
2391
  actionInputSchemas?: ActionInputSchemas;
2392
+ /**
2393
+ * How much of this actor's work is recorded in traces. Defaults to the
2394
+ * process sampler from `OTEL_TRACES_SAMPLER`.
2395
+ */
2396
+ tracing?: ActorTracingOptions<TActions>;
2358
2397
  /**
2359
2398
  * Optional schema for validating connection params in native runtimes.
2360
2399
  */
@@ -543,6 +543,29 @@ declare class RivetError extends Error {
543
543
  toString(): string;
544
544
  }
545
545
 
546
+ /** Sample rates keyed by action name, nested like the actor's action groups. */
547
+ interface ActionSampleRates {
548
+ readonly [name: string]: number | ActionSampleRates;
549
+ }
550
+ /**
551
+ * {@link ActionSampleRates} limited to the actions of one actor, so a rate for
552
+ * an action that does not exist is a compile error.
553
+ */
554
+ type ActionTraceSamplers<TActions> = {
555
+ readonly [K in keyof TActions]?: TActions[K] extends (...args: never[]) => unknown ? number : ActionTraceSamplers<TActions[K]>;
556
+ };
557
+ /** Trace sampling for one actor definition. */
558
+ interface ActorTracingOptions<TActions> {
559
+ /**
560
+ * Share of this actor's invocations that are recorded, from 0 to 1. A rate
561
+ * lowers what is recorded and never raises it, so an invocation inside a
562
+ * trace the caller did not record is not recorded at any rate.
563
+ */
564
+ readonly sampler?: number;
565
+ /** Rates that replace `sampler` for single actions. */
566
+ readonly actions?: ActionTraceSamplers<TActions>;
567
+ }
568
+
546
569
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
547
570
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
548
571
 
@@ -842,12 +865,19 @@ interface RuntimeSqlBatchStatement {
842
865
  interface RuntimeSqlRunResult {
843
866
  changes: number;
844
867
  }
868
+ /** Sample rates for the traces an actor starts, in the shape core takes. */
869
+ interface RuntimeActorTracingConfig {
870
+ sampler?: number;
871
+ /** Keyed by flattened, dot-separated action name. */
872
+ actions?: Record<string, number>;
873
+ }
845
874
  interface RuntimeActorConfig {
846
875
  name?: string;
847
876
  icon?: string;
848
877
  hasDatabase?: boolean;
849
878
  remoteSqlite?: boolean;
850
879
  sqliteProfiling?: SqliteProfilingOptions;
880
+ tracing?: RuntimeActorTracingConfig;
851
881
  enableActorRuntimeSocket?: boolean;
852
882
  hasState?: boolean;
853
883
  canHibernateWebsocket?: boolean;
@@ -2115,6 +2145,10 @@ declare const ActorConfigSchema: z$1.ZodObject<{
2115
2145
  onWebSocket: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2116
2146
  actions: z$1.ZodDefault<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
2117
2147
  actionInputSchemas: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
2148
+ tracing: z$1.ZodOptional<z$1.ZodObject<{
2149
+ sampler: z$1.ZodOptional<z$1.ZodNumber>;
2150
+ actions: z$1.ZodOptional<z$1.ZodType<ActionSampleRates, unknown, z$1.core.$ZodTypeInternals<ActionSampleRates, unknown>>>;
2151
+ }, z$1.core.$strict>>;
2118
2152
  connParamsSchema: z$1.ZodOptional<z$1.ZodAny>;
2119
2153
  events: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
2120
2154
  queues: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
@@ -2355,6 +2389,11 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
2355
2389
  * May mirror nested action groups or use dot-separated low-level action names.
2356
2390
  */
2357
2391
  actionInputSchemas?: ActionInputSchemas;
2392
+ /**
2393
+ * How much of this actor's work is recorded in traces. Defaults to the
2394
+ * process sampler from `OTEL_TRACES_SAMPLER`.
2395
+ */
2396
+ tracing?: ActorTracingOptions<TActions>;
2358
2397
  /**
2359
2398
  * Optional schema for validating connection params in native runtimes.
2360
2399
  */
@@ -33,6 +33,26 @@ function flattenActionInputSchemas(actions, schemas) {
33
33
  }
34
34
  return flattened;
35
35
  }
36
+ function flattenActionTraceSamplers(actions, rates = {}) {
37
+ const handlers = flattenActionHandlers(actions);
38
+ const flattened = Object.fromEntries(flattenSampleRates(rates, []));
39
+ for (const name of Object.keys(flattened)) {
40
+ if (!Object.hasOwn(handlers, name)) {
41
+ throw new TypeError(
42
+ `tracing.actions.${name} does not name an action`
43
+ );
44
+ }
45
+ }
46
+ return flattened;
47
+ }
48
+ function flattenSampleRates(rates, path) {
49
+ return Object.entries(rates).flatMap(
50
+ ([segment, rate]) => {
51
+ const childPath = [...path, segment];
52
+ return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
53
+ }
54
+ );
55
+ }
36
56
  function collectActionEntries(actions) {
37
57
  const entries = [];
38
58
  const names = /* @__PURE__ */ new Set();
@@ -228,6 +248,10 @@ var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => (
228
248
  var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
229
249
  InstanceActorOptionsBaseSchema.shape
230
250
  ).strict().prefault(() => ({}));
251
+ var zSampleRate = z.number().min(0).max(1);
252
+ var zActionSampleRates = z.lazy(
253
+ () => z.record(z.string(), z.union([zSampleRate, zActionSampleRates]))
254
+ );
231
255
  var ActorConfigSchema = z.object({
232
256
  onCreate: zFunction().optional(),
233
257
  onDestroy: zFunction().optional(),
@@ -244,6 +268,10 @@ var ActorConfigSchema = z.object({
244
268
  onWebSocket: zFunction().optional(),
245
269
  actions: zActionTree.default(() => ({})),
246
270
  actionInputSchemas: z.record(z.string(), z.any()).optional(),
271
+ tracing: z.object({
272
+ sampler: zSampleRate.optional(),
273
+ actions: zActionSampleRates.optional()
274
+ }).strict().optional(),
247
275
  connParamsSchema: z.any().optional(),
248
276
  events: z.record(z.string(), z.any()).optional(),
249
277
  queues: z.record(z.string(), z.any()).optional(),
@@ -391,6 +419,9 @@ var DocActorConfigSchema = z.object({
391
419
  actionInputSchemas: z.record(z.string(), z.unknown()).optional().describe(
392
420
  "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
393
421
  ),
422
+ tracing: z.unknown().optional().describe(
423
+ "Trace sampling for this actor: `sampler` is the share of its invocations that are recorded, from 0 to 1, with optional per-action rates under `actions`. A rate lowers what is recorded and never raises it. Defaults to the process sampler from OTEL_TRACES_SAMPLER."
424
+ ),
394
425
  connParamsSchema: z.unknown().optional().describe(
395
426
  "Optional schema for validating connection params in native runtimes."
396
427
  ),
@@ -420,7 +451,7 @@ function isRivetErrorCode(error, group, code) {
420
451
  // package.json
421
452
  var package_default = {
422
453
  name: "rivetkit",
423
- version: "2.3.19",
454
+ version: "2.3.20",
424
455
  description: "Lightweight libraries for building stateful actors on edge platforms",
425
456
  license: "Apache-2.0",
426
457
  keywords: [
@@ -889,12 +920,14 @@ var ActorDefinition = class {
889
920
  }
890
921
  };
891
922
  function actor(input) {
923
+ var _a;
892
924
  warnDeprecatedOptionKeys(
893
925
  input == null ? void 0 : input.options
894
926
  );
895
927
  const config = ActorConfigSchema.parse(input);
896
928
  flattenActionHandlers(config.actions);
897
929
  flattenActionInputSchemas(config.actions, config.actionInputSchemas);
930
+ flattenActionTraceSamplers(config.actions, (_a = config.tracing) == null ? void 0 : _a.actions);
898
931
  return new ActorDefinition(config);
899
932
  }
900
933