rivetkit 2.3.18 → 2.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/browser/client.d.ts +754 -608
  2. package/dist/browser/client.js +184 -28
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +6 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +5 -1
  11. package/dist/tsup/agent-os/index.cjs +36 -1
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +149 -3
  14. package/dist/tsup/agent-os/index.d.ts +149 -3
  15. package/dist/tsup/agent-os/index.js +36 -1
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-2IDK6NX3.cjs → chunk-2CE5UNWK.cjs} +13 -13
  18. package/dist/tsup/chunk-2CE5UNWK.cjs.map +1 -0
  19. package/dist/tsup/{chunk-IPXIZSE7.js → chunk-2NXLTFWI.js} +3 -3
  20. package/dist/tsup/{chunk-OKVVWOC3.cjs → chunk-3WS7Z64U.cjs} +3 -3
  21. package/dist/tsup/{chunk-OKVVWOC3.cjs.map → chunk-3WS7Z64U.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-LAITPJRA.js → chunk-553CIQJY.js} +2 -2
  23. package/dist/tsup/{chunk-PXKNBNVU.js → chunk-5G2J26VM.js} +188 -31
  24. package/dist/tsup/chunk-5G2J26VM.js.map +1 -0
  25. package/dist/tsup/{chunk-IKZ6DJMP.cjs → chunk-76YTS32R.cjs} +4 -4
  26. package/dist/tsup/{chunk-IKZ6DJMP.cjs.map → chunk-76YTS32R.cjs.map} +1 -1
  27. package/dist/tsup/{chunk-NRIRV3Z2.cjs → chunk-A36FMKOV.cjs} +352 -195
  28. package/dist/tsup/chunk-A36FMKOV.cjs.map +1 -0
  29. package/dist/tsup/{chunk-6W5VGLFT.js → chunk-CSOHAAZK.js} +33 -1
  30. package/dist/tsup/chunk-CSOHAAZK.js.map +1 -0
  31. package/dist/tsup/{chunk-T6JUXRNI.cjs → chunk-CVLNRT7O.cjs} +3 -3
  32. package/dist/tsup/{chunk-T6JUXRNI.cjs.map → chunk-CVLNRT7O.cjs.map} +1 -1
  33. package/dist/tsup/{chunk-7EPLADKM.js → chunk-DHWZTUKA.js} +7 -7
  34. package/dist/tsup/chunk-DHWZTUKA.js.map +1 -0
  35. package/dist/tsup/{chunk-4XECVATQ.js → chunk-DMQUERRN.js} +2 -2
  36. package/dist/tsup/{chunk-25Z2RK7C.cjs → chunk-IHKDFKM4.cjs} +3 -3
  37. package/dist/tsup/{chunk-25Z2RK7C.cjs.map → chunk-IHKDFKM4.cjs.map} +1 -1
  38. package/dist/tsup/{chunk-2JSYYH6P.cjs → chunk-JX2ITWAV.cjs} +13 -2
  39. package/dist/tsup/chunk-JX2ITWAV.cjs.map +1 -0
  40. package/dist/tsup/{chunk-4KGXFC6M.cjs → chunk-NWCAIWHL.cjs} +34 -2
  41. package/dist/tsup/chunk-NWCAIWHL.cjs.map +1 -0
  42. package/dist/tsup/{chunk-OUQUIBVW.js → chunk-P2OFXH4G.js} +12 -1
  43. package/dist/tsup/chunk-P2OFXH4G.js.map +1 -0
  44. package/dist/tsup/{chunk-ZRTESY7V.cjs → chunk-RSIOGT2U.cjs} +7 -7
  45. package/dist/tsup/{chunk-ZRTESY7V.cjs.map → chunk-RSIOGT2U.cjs.map} +1 -1
  46. package/dist/tsup/{chunk-QIFZELUQ.js → chunk-SNNVRHLX.js} +2 -2
  47. package/dist/tsup/{chunk-2MK75JFR.js → chunk-TZVAVPGJ.js} +4 -4
  48. package/dist/tsup/{chunk-TNSLNSQH.js → chunk-W2PXGWMR.js} +2 -2
  49. package/dist/tsup/{chunk-O7RSU3UC.cjs → chunk-WAISW7KR.cjs} +10 -10
  50. package/dist/tsup/{chunk-O7RSU3UC.cjs.map → chunk-WAISW7KR.cjs.map} +1 -1
  51. package/dist/tsup/client/mod.cjs +6 -6
  52. package/dist/tsup/client/mod.d.cts +5 -5
  53. package/dist/tsup/client/mod.d.ts +5 -5
  54. package/dist/tsup/client/mod.js +5 -5
  55. package/dist/tsup/common/log.cjs +3 -3
  56. package/dist/tsup/common/log.js +2 -2
  57. package/dist/tsup/common/websocket.cjs +4 -4
  58. package/dist/tsup/common/websocket.js +3 -3
  59. package/dist/tsup/{config-Ug5M2MOr.d.ts → config-Be-VOHaX.d.ts} +155 -11
  60. package/dist/tsup/{config-gvHwMas-.d.cts → config-Ct5uXxXk.d.cts} +155 -11
  61. package/dist/tsup/{context-DererUCI.d.ts → context-CXLa0BIM.d.ts} +1 -1
  62. package/dist/tsup/{context-BSCBvbfM.d.cts → context-Cw-11Q-B.d.cts} +1 -1
  63. package/dist/tsup/db/drizzle.cjs +3 -3
  64. package/dist/tsup/db/drizzle.js +2 -2
  65. package/dist/tsup/db/mod.cjs +4 -4
  66. package/dist/tsup/db/mod.js +3 -3
  67. package/dist/tsup/dynamic/mod.cjs +2 -2
  68. package/dist/tsup/dynamic/mod.d.cts +3 -3
  69. package/dist/tsup/dynamic/mod.d.ts +3 -3
  70. package/dist/tsup/dynamic/mod.js +1 -1
  71. package/dist/tsup/inspector/mod.cjs +6 -6
  72. package/dist/tsup/inspector/mod.js +5 -5
  73. package/dist/tsup/inspector/workflow.cjs +5 -5
  74. package/dist/tsup/inspector/workflow.js +4 -4
  75. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  76. package/dist/tsup/inspector-tab/mod.d.cts +4 -4
  77. package/dist/tsup/inspector-tab/mod.d.ts +4 -4
  78. package/dist/tsup/inspector-tab/mod.js +1 -1
  79. package/dist/tsup/mod.cjs +506 -319
  80. package/dist/tsup/mod.cjs.map +1 -1
  81. package/dist/tsup/mod.d.cts +5 -5
  82. package/dist/tsup/mod.d.ts +5 -5
  83. package/dist/tsup/mod.js +381 -194
  84. package/dist/tsup/mod.js.map +1 -1
  85. package/dist/tsup/test/mod.cjs +7 -7
  86. package/dist/tsup/test/mod.d.cts +3 -3
  87. package/dist/tsup/test/mod.d.ts +3 -3
  88. package/dist/tsup/test/mod.js +5 -5
  89. package/dist/tsup/{utils-Bbz-3411.d.cts → utils-CNFeS-Dk.d.cts} +1 -1
  90. package/dist/tsup/{utils-vvJQyygr.d.ts → utils-DsoDinPz.d.cts} +9 -1
  91. package/dist/tsup/{utils-vvJQyygr.d.cts → utils-DsoDinPz.d.ts} +9 -1
  92. package/dist/tsup/{utils-BqdWVlzm.d.ts → utils-OQHBjfcM.d.ts} +1 -1
  93. package/dist/tsup/utils.cjs +3 -3
  94. package/dist/tsup/utils.d.cts +2 -2
  95. package/dist/tsup/utils.d.ts +2 -2
  96. package/dist/tsup/utils.js +2 -2
  97. package/dist/tsup/workflow/mod.cjs +33 -27
  98. package/dist/tsup/workflow/mod.cjs.map +1 -1
  99. package/dist/tsup/workflow/mod.d.cts +5 -5
  100. package/dist/tsup/workflow/mod.d.ts +5 -5
  101. package/dist/tsup/workflow/mod.js +25 -19
  102. package/dist/tsup/workflow/mod.js.map +1 -1
  103. package/package.json +10 -8
  104. package/src/actor/actions.ts +36 -0
  105. package/src/actor/config.ts +65 -0
  106. package/src/actor/definition.ts +6 -1
  107. package/src/actor/errors.ts +31 -0
  108. package/src/actor/mod.ts +5 -0
  109. package/src/actor/tracing.ts +28 -0
  110. package/src/client/actor-conn.ts +7 -0
  111. package/src/client/actor-handle.ts +57 -17
  112. package/src/client/client.ts +26 -6
  113. package/src/client/outbound-telemetry.ts +66 -0
  114. package/src/client/queue.ts +3 -0
  115. package/src/client/raw-utils.ts +3 -0
  116. package/src/common/actor-router-consts.ts +3 -0
  117. package/src/common/actor-telemetry-context.ts +19 -0
  118. package/src/common/otel-context.ts +99 -0
  119. package/src/common/utils.ts +1 -19
  120. package/src/engine-client/actor-http-client.ts +15 -0
  121. package/src/registry/index.ts +6 -0
  122. package/src/registry/napi-runtime.ts +155 -35
  123. package/src/registry/native.ts +295 -191
  124. package/src/registry/runtime.ts +74 -0
  125. package/src/registry/wasm-runtime.ts +40 -0
  126. package/src/workflow/driver.ts +20 -12
  127. package/dist/tsup/chunk-2IDK6NX3.cjs.map +0 -1
  128. package/dist/tsup/chunk-2JSYYH6P.cjs.map +0 -1
  129. package/dist/tsup/chunk-4KGXFC6M.cjs.map +0 -1
  130. package/dist/tsup/chunk-6W5VGLFT.js.map +0 -1
  131. package/dist/tsup/chunk-7EPLADKM.js.map +0 -1
  132. package/dist/tsup/chunk-NRIRV3Z2.cjs.map +0 -1
  133. package/dist/tsup/chunk-OUQUIBVW.js.map +0 -1
  134. package/dist/tsup/chunk-PXKNBNVU.js.map +0 -1
  135. /package/dist/tsup/{chunk-IPXIZSE7.js.map → chunk-2NXLTFWI.js.map} +0 -0
  136. /package/dist/tsup/{chunk-LAITPJRA.js.map → chunk-553CIQJY.js.map} +0 -0
  137. /package/dist/tsup/{chunk-4XECVATQ.js.map → chunk-DMQUERRN.js.map} +0 -0
  138. /package/dist/tsup/{chunk-QIFZELUQ.js.map → chunk-SNNVRHLX.js.map} +0 -0
  139. /package/dist/tsup/{chunk-2MK75JFR.js.map → chunk-TZVAVPGJ.js.map} +0 -0
  140. /package/dist/tsup/{chunk-TNSLNSQH.js.map → chunk-W2PXGWMR.js.map} +0 -0
@@ -339,6 +339,29 @@ declare class UserError extends RivetError {
339
339
  constructor(message: string, options?: UserErrorOptions);
340
340
  }
341
341
 
342
+ /** Sample rates keyed by action name, nested like the actor's action groups. */
343
+ interface ActionSampleRates {
344
+ readonly [name: string]: number | ActionSampleRates;
345
+ }
346
+ /**
347
+ * {@link ActionSampleRates} limited to the actions of one actor, so a rate for
348
+ * an action that does not exist is a compile error.
349
+ */
350
+ type ActionTraceSamplers<TActions> = {
351
+ readonly [K in keyof TActions]?: TActions[K] extends (...args: never[]) => unknown ? number : ActionTraceSamplers<TActions[K]>;
352
+ };
353
+ /** Trace sampling for one actor definition. */
354
+ interface ActorTracingOptions<TActions> {
355
+ /**
356
+ * Share of this actor's invocations that are recorded, from 0 to 1. A rate
357
+ * lowers what is recorded and never raises it, so an invocation inside a
358
+ * trace the caller did not record is not recorded at any rate.
359
+ */
360
+ readonly sampler?: number;
361
+ /** Rates that replace `sampler` for single actions. */
362
+ readonly actions?: ActionTraceSamplers<TActions>;
363
+ }
364
+
342
365
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
343
366
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
344
367
 
@@ -420,216 +443,714 @@ interface ActorOutput {
420
443
  error?: unknown;
421
444
  }
422
445
 
423
- interface QueueSendWaitOptions {
424
- wait: true;
425
- timeout?: number;
426
- signal?: AbortSignal;
427
- }
428
- interface QueueSendNoWaitOptions {
429
- wait?: false;
430
- timeout?: never;
431
- signal?: AbortSignal;
432
- }
433
- interface QueueSendResult<TResponse = unknown> {
434
- status: "completed" | "timedOut";
435
- response?: TResponse;
446
+ /** Correlation owned by the currently executing Core actor invocation. */
447
+ interface ActorInvocationTraceContext {
448
+ /** Ray ID the invocation received, absent when nothing upstream supplied one. */
449
+ readonly rayId?: string;
450
+ /** Core-owned invocation span context, absent when tracing is disabled. */
451
+ readonly span?: ActorInvocationSpanContext;
452
+ }
453
+ /** W3C span context of the Core invocation span. */
454
+ interface ActorInvocationSpanContext {
455
+ /** W3C trace identifier. */
456
+ readonly traceId: string;
457
+ /** W3C span identifier for the Core invocation. */
458
+ readonly spanId: string;
459
+ /** OpenTelemetry trace flags encoded as an integer. */
460
+ readonly traceFlags: number;
461
+ /** Optional vendor trace state inherited by the Core invocation. */
462
+ readonly tracestate?: string;
436
463
  }
437
464
 
438
- /**
439
- * Action function returned by Actor connections and handles.
440
- *
441
- * @typedef {Function} ActorActionFunction
442
- * @template Args
443
- * @template Response
444
- * @param {...Args} args - Arguments for the action function.
445
- * @returns {Promise<Response>}
446
- */
447
- type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
448
- type IsAny<T> = 0 extends 1 & T ? true : false;
449
- type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
450
- type ActorActionMap<R> = {
451
- [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : NonNullable<R>[K] extends Record<string, unknown> ? ActorActionMap<NonNullable<R>[K]> : never;
465
+ declare const handleBrand: unique symbol;
466
+ type OpaqueHandle<Name extends string> = {
467
+ readonly [handleBrand]: Name;
452
468
  };
453
- type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
454
- actions?: infer R;
455
- } ? R : never;
456
- interface ActorGatewayOptions {
457
- skipReadyWait?: boolean;
469
+ type RegistryHandle = OpaqueHandle<"registry">;
470
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
471
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
472
+ type ConnHandle = OpaqueHandle<"conn">;
473
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
474
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
475
+ type ActorStateTransactionHandle = OpaqueHandle<"actorStateTransaction">;
476
+ type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
477
+ type RuntimeBytes = Uint8Array;
478
+ interface RuntimeActorKeySegment {
479
+ kind: string;
480
+ stringValue?: string;
481
+ numberValue?: number;
458
482
  }
459
- interface ActorActionOptions extends ActorGatewayOptions {
460
- signal?: AbortSignal;
483
+ /** Resolves correlation at operation time so retained clients cannot freeze stale context. */
484
+ type CurrentActorInvocation = () => ActorInvocationTraceContext | undefined;
485
+ /** One open call from an actor out to another actor. */
486
+ interface RuntimeOutboundCall {
487
+ /**
488
+ * W3C context of the call's own span, to send to the callee so it parents to
489
+ * the call. Absent when tracing is disabled.
490
+ */
491
+ readonly span?: ActorInvocationSpanContext;
492
+ /**
493
+ * Records the call's outcome. `error` is the failure encoded the way the
494
+ * bridge encodes errors, so a structured error keeps its group and code.
495
+ */
496
+ finish(error?: string): void;
461
497
  }
462
- type ActorConnectOptions = ActorGatewayOptions;
463
- type ActorFetchInit = RequestInit & ActorGatewayOptions;
464
- type ActorWebSocketOptions = ActorGatewayOptions;
465
498
  /**
466
- * Maps action methods from actor definition to typed function signatures.
499
+ * Opens the span covering one call out to another actor, or returns `undefined`
500
+ * outside an invocation or on a runtime without invocation telemetry. Callers
501
+ * send their own context when it returns nothing.
467
502
  */
468
- type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
469
- type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
470
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
471
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
472
- (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
473
- (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
503
+ type StartCallSpan = (actorName: string, actionName: string) => RuntimeOutboundCall | undefined;
504
+ interface RuntimeHttpRequest {
505
+ method: string;
506
+ uri: string;
507
+ headers?: Record<string, string>;
508
+ body?: RuntimeBytes;
509
+ }
510
+ interface RuntimeHttpResponseBodyStream {
511
+ cancelled(): Promise<void>;
512
+ write(chunk: Uint8Array): Promise<void>;
513
+ end(): Promise<void>;
514
+ error(message: string): Promise<void>;
515
+ }
516
+ interface RuntimeStateDeltaPayload {
517
+ state?: RuntimeBytes;
518
+ connHibernation: Array<{
519
+ connId: string;
520
+ bytes: RuntimeBytes;
521
+ }>;
522
+ connHibernationRemoved: string[];
523
+ }
524
+ interface RuntimeWorkflowKvWrite {
525
+ key: RuntimeBytes;
526
+ value: RuntimeBytes;
527
+ }
528
+ interface RuntimeRequestSaveOpts {
529
+ immediate?: boolean;
530
+ maxWaitMs?: number;
531
+ }
532
+ interface RuntimeInspectorSnapshot {
533
+ stateRevision: number;
534
+ connectionsRevision: number;
535
+ queueRevision: number;
536
+ activeConnections: number;
537
+ queueSize: number;
538
+ connectedClients: number;
539
+ }
540
+ interface RuntimeQueueMessage {
541
+ id(): bigint;
542
+ name(): string;
543
+ body(): RuntimeBytes;
544
+ createdAt(): number;
545
+ isCompletable(): boolean;
546
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
547
+ }
548
+ interface RuntimeQueueInspectMessage {
549
+ id: number;
550
+ name: string;
551
+ createdAtMs: number;
552
+ }
553
+ interface RuntimeScheduledEventInfo {
554
+ id: string;
555
+ action: string;
556
+ args: RuntimeBytes;
557
+ runAt: number;
558
+ }
559
+ interface RuntimeCronJobInfo {
560
+ name: string;
561
+ kind: "cron" | "every";
562
+ action: string;
563
+ args: RuntimeBytes;
564
+ nextRunAt: number;
565
+ lastRunAt?: number;
566
+ expression?: string;
567
+ timezone?: string;
568
+ intervalMs?: number;
569
+ maxHistory: number;
570
+ }
571
+ interface RuntimeScheduleErrorInfo {
572
+ group: string;
573
+ code: string;
574
+ message: string;
575
+ metadata?: unknown;
576
+ }
577
+ interface RuntimeCronFire {
578
+ action: string;
579
+ scheduledAt: number;
580
+ firedAt: number;
581
+ finishedAt?: number;
582
+ result: "running" | "ok" | "error" | "skipped";
583
+ error?: RuntimeScheduleErrorInfo;
584
+ }
585
+ interface RuntimeQueueNextBatchOptions {
586
+ names?: string[];
587
+ count?: number;
588
+ timeoutMs?: number;
589
+ completable?: boolean;
590
+ }
591
+ interface RuntimeQueueWaitOptions {
592
+ timeoutMs?: number;
593
+ completable?: boolean;
594
+ }
595
+ interface RuntimeQueueEnqueueAndWaitOptions {
596
+ timeoutMs?: number;
597
+ }
598
+ interface RuntimeQueueTryNextBatchOptions {
599
+ names?: string[];
600
+ count?: number;
601
+ completable?: boolean;
602
+ }
603
+ interface RuntimeKvListOptions {
604
+ reverse?: boolean;
605
+ limit?: number;
606
+ }
607
+ interface RuntimeKvEntry {
608
+ key: RuntimeBytes;
609
+ value: RuntimeBytes;
610
+ }
611
+ type RuntimeSqlBindNoValues = {
612
+ intValue?: never;
613
+ floatValue?: never;
614
+ textValue?: never;
615
+ blobValue?: never;
474
616
  };
475
- type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
476
- <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
477
- (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
617
+ type RuntimeSqlBindParam = ({
618
+ kind: "null";
619
+ } & RuntimeSqlBindNoValues) | {
620
+ kind: "int";
621
+ intValue: number;
622
+ floatValue?: never;
623
+ textValue?: never;
624
+ blobValue?: never;
625
+ } | {
626
+ kind: "float";
627
+ intValue?: never;
628
+ floatValue: number;
629
+ textValue?: never;
630
+ blobValue?: never;
631
+ } | {
632
+ kind: "text";
633
+ intValue?: never;
634
+ floatValue?: never;
635
+ textValue: string;
636
+ blobValue?: never;
637
+ } | {
638
+ kind: "blob";
639
+ intValue?: never;
640
+ floatValue?: never;
641
+ textValue?: never;
642
+ blobValue: RuntimeBytes;
478
643
  };
479
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
480
- send: ActorQueueSend<Record<string, any>>;
481
- } : AD extends {
482
- config: {
483
- queues?: infer Q;
484
- };
485
- } ? Q extends QueueSchemaConfig ? {
486
- send: ActorQueueSend<Q>;
487
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
488
- send: ActorQueueSend<Q>;
489
- } : {} : {};
490
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
491
- on: LooseEventSubscribe;
492
- once: LooseEventSubscribe;
493
- } : AD extends {
494
- config: {
495
- events?: infer E;
496
- };
497
- } ? E extends EventSchemaConfig ? {
498
- on: ActorEventSubscribe<E>;
499
- once: ActorEventSubscribe<E>;
500
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
501
- on: ActorEventSubscribe<E>;
502
- once: ActorEventSubscribe<E>;
503
- } : {} : {};
504
-
505
- declare class ActorClientError extends Error {
644
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
645
+ interface RuntimeActorRuntimeSocketEndpointInfo {
646
+ path: string;
506
647
  }
507
- declare class ManagerError extends ActorClientError {
508
- constructor(error: string, opts?: ErrorOptions);
648
+ interface RuntimeSqlQueryResult {
649
+ columns: string[];
650
+ rows: unknown[][];
509
651
  }
510
- declare class MalformedResponseMessage extends ActorClientError {
511
- constructor(cause?: unknown);
652
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
653
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
654
+ changes: number;
655
+ lastInsertRowId?: number | null;
512
656
  }
513
-
514
- declare class ActorConnDisposed extends ActorClientError {
515
- constructor();
657
+ interface RuntimeSqlBatchStatement {
658
+ sql: string;
659
+ params?: RuntimeSqlBindParams;
516
660
  }
517
-
518
- type ActorResolutionState = ActorQuery;
519
-
520
- /**
521
- * Connection status for an actor connection.
522
- *
523
- * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
524
- * - `"connecting"`: Attempting to establish connection
525
- * - `"connected"`: Connection is active
526
- * - `"disconnected"`: Connection was lost, will auto-reconnect
527
- */
528
- type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
529
- /**
530
- * A function that unsubscribes from an event.
531
- *
532
- * @typedef {Function} EventUnsubscribe
533
- */
534
- type EventUnsubscribe = () => void;
535
- /**
536
- * A function that handles connection errors.
537
- *
538
- * @typedef {Function} ActorErrorCallback
539
- */
540
- type ActorErrorCallback = (error: RivetError) => void;
541
- /**
542
- * A callback for connection state changes.
543
- *
544
- * @typedef {Function} ConnectionStateCallback
545
- */
546
- type ConnectionStateCallback = () => void;
547
- /**
548
- * A callback for connection status changes.
549
- *
550
- * @typedef {Function} StatusChangeCallback
551
- */
552
- type StatusChangeCallback = (status: ActorConnStatus) => void;
553
- declare const CONNECT_SYMBOL: unique symbol;
554
- /**
555
- * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
556
- *
557
- * @see {@link ActorConn}
558
- */
559
- declare class ActorConnRaw {
560
- #private;
661
+ interface RuntimeSqlRunResult {
662
+ changes: number;
663
+ }
664
+ /** Sample rates for the traces an actor starts, in the shape core takes. */
665
+ interface RuntimeActorTracingConfig {
666
+ sampler?: number;
667
+ /** Keyed by flattened, dot-separated action name. */
668
+ actions?: Record<string, number>;
669
+ }
670
+ interface RuntimeActorConfig {
671
+ name?: string;
672
+ icon?: string;
673
+ hasDatabase?: boolean;
674
+ remoteSqlite?: boolean;
675
+ sqliteProfiling?: SqliteProfilingOptions;
676
+ tracing?: RuntimeActorTracingConfig;
677
+ enableActorRuntimeSocket?: boolean;
678
+ hasState?: boolean;
679
+ canHibernateWebsocket?: boolean;
680
+ stateSaveIntervalMs?: number;
681
+ createStateTimeoutMs?: number;
682
+ onCreateTimeoutMs?: number;
683
+ createVarsTimeoutMs?: number;
684
+ createConnStateTimeoutMs?: number;
685
+ onBeforeConnectTimeoutMs?: number;
686
+ onConnectTimeoutMs?: number;
687
+ onMigrateTimeoutMs?: number;
688
+ onWakeTimeoutMs?: number;
689
+ onBeforeActorStartTimeoutMs?: number;
690
+ actionTimeoutMs?: number;
691
+ onRequestTimeoutMs?: number;
692
+ sleepTimeoutMs?: number;
693
+ noSleep?: boolean;
694
+ sleepGracePeriodMs?: number;
695
+ connectionLivenessTimeoutMs?: number;
696
+ connectionLivenessIntervalMs?: number;
697
+ maxQueueSize?: number;
698
+ maxSchedules?: number;
699
+ maxQueueMessageSize?: number;
700
+ maxIncomingMessageSize?: number;
701
+ maxOutgoingMessageSize?: number;
702
+ preloadMaxWorkflowBytes?: number;
703
+ preloadMaxConnectionsBytes?: number;
704
+ actions?: Array<{
705
+ name: string;
706
+ }>;
707
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
708
+ }
709
+ interface RuntimeInspectorTabEntry {
710
+ id: string;
711
+ /** Required for custom entries; omitted for built-in hides. */
712
+ label?: string;
561
713
  /**
562
- * Do not call this directly.
563
- *
564
- * Creates an instance of ActorConnRaw.
565
- *
566
- * @protected
714
+ * Required for custom entries — absolute path to the source directory.
715
+ * Resolved on the TS side before being handed to the runtime.
567
716
  */
568
- constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
569
- send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
570
- send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
717
+ source?: string;
718
+ /** Optional icon id for custom entries. */
719
+ icon?: string;
720
+ /** Set to true for built-in hide entries. */
721
+ hidden?: boolean;
722
+ }
723
+ interface RuntimeServeConfig {
724
+ version: number;
725
+ endpoint: string;
726
+ token?: string;
727
+ namespace: string;
728
+ poolName: string;
729
+ engineBinaryPath?: string;
730
+ startServices?: boolean;
731
+ servicesBinaryPath?: string;
732
+ engineHost?: string;
733
+ enginePort?: number;
734
+ handleInspectorHttpInRuntime?: boolean;
735
+ inspectorTestToken?: string;
736
+ serverlessBasePath?: string;
737
+ serverlessPackageVersion: string;
738
+ serverlessClientEndpoint?: string;
739
+ serverlessClientNamespace?: string;
740
+ serverlessClientToken?: string;
741
+ serverlessValidateEndpoint: boolean;
742
+ serverlessMaxStartPayloadBytes: number;
743
+ }
744
+ interface RuntimeListenerConfig {
745
+ port: number;
746
+ host?: string;
747
+ publicDir?: string;
748
+ application?: RuntimeApplicationFetch;
749
+ }
750
+ interface RuntimeServerlessRequest {
751
+ method: string;
752
+ url: string;
753
+ headers: Record<string, string>;
754
+ body: RuntimeBytes;
755
+ }
756
+ interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
757
+ cancelToken?: CancellationTokenHandle;
758
+ }
759
+ interface RuntimeApplicationResponse {
760
+ status: number;
761
+ headers: Record<string, string>;
762
+ body?: RuntimeBytes;
763
+ stream?: boolean;
764
+ }
765
+ type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
766
+ interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
767
+ application: RuntimeApplicationFetch;
768
+ }
769
+ interface RuntimeServerlessResponseHead {
770
+ status: number;
771
+ headers: Record<string, string>;
772
+ }
773
+ interface RuntimeRegistryRouteResponse {
774
+ status: number;
775
+ headers: Record<string, string>;
776
+ body: RuntimeBytes;
777
+ }
778
+ type RuntimeServerlessStreamEvent = {
779
+ kind: "chunk";
780
+ chunk?: RuntimeBytes;
781
+ } | {
782
+ kind: "end";
783
+ error?: {
784
+ group: string;
785
+ code: string;
786
+ message: string;
787
+ };
788
+ };
789
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
790
+ type RuntimeWebSocketEvent = {
791
+ kind: "message";
792
+ data: string | RuntimeBytes;
793
+ binary: boolean;
794
+ messageIndex?: number;
795
+ } | {
796
+ kind: "close";
797
+ code: number;
798
+ reason: string;
799
+ wasClean: boolean;
800
+ };
801
+ interface CoreRuntime {
802
+ readonly kind: "napi" | "wasm";
803
+ createRegistry(): RegistryHandle;
804
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
805
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
806
+ waitRegistryReady(registry: RegistryHandle): Promise<void>;
807
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
808
+ shutdownTelemetry?(): Promise<void>;
809
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
810
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
811
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
812
+ serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
813
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
814
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
815
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
816
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
817
+ createCancellationToken(): CancellationTokenHandle;
818
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
819
+ cancelCancellationToken(token: CancellationTokenHandle): void;
820
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
821
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
822
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
823
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
824
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
825
+ actorSetRunWakeAt(ctx: ActorContextHandle, timestampMs?: number | undefined | null): Promise<void>;
826
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
827
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
828
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
829
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
830
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
831
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
832
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
833
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
834
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
835
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
836
+ actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
837
+ actorId(ctx: ActorContextHandle): string;
571
838
  /**
572
- * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
573
- *
574
- * @see {@link ActorConn}
575
- * @template Args - The type of arguments to pass to the action function.
576
- * @template Response - The type of the response returned by the action function.
577
- * @param {string} name - The name of the action function to call.
578
- * @param {...Args} args - The arguments to pass to the action function.
579
- * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
839
+ * Runs one actor callback with `ctx` as the current invocation: operations
840
+ * on retained handles for the same actor resolve to it, and its Core span
841
+ * is the active OpenTelemetry span for the duration of `run`. Only actions,
842
+ * raw requests, and queue dispatch run this way; other callbacks have no
843
+ * invocation span.
580
844
  */
581
- action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
582
- name: string;
583
- args: Args;
584
- signal?: AbortSignal;
585
- }): Promise<Response>;
845
+ runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T;
586
846
  /**
587
- * Do not call this directly.
588
- * Establishes a connection to the server using the specified endpoint & encoding & driver.
589
- *
590
- * @protected
847
+ * Correlation of the invocation currently executing for this actor, or
848
+ * `undefined` outside an invocation or after it finished. A sampled-out
849
+ * invocation can still expose valid span context for propagation.
591
850
  */
592
- [CONNECT_SYMBOL](): void;
851
+ actorInvocationTraceContext(ctx: ActorContextHandle): ActorInvocationTraceContext | undefined;
593
852
  /**
594
- * Subscribes to an event that will happen repeatedly.
595
- *
596
- * @template Args - The type of arguments the event callback will receive.
597
- * @param {string} eventName - The name of the event to subscribe to.
598
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
599
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
600
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
853
+ * Opens the span covering one call this actor makes to another actor. See
854
+ * `StartCallSpan` for when this returns nothing.
601
855
  */
602
- on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
603
- /**
604
- * Subscribes to an event that will be triggered only once.
605
- *
606
- * @template Args - The type of arguments the event callback will receive.
607
- * @param {string} eventName - The name of the event to subscribe to.
608
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
609
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
610
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
611
- */
612
- once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
856
+ startCallSpan(ctx: ActorContextHandle, actorName: string, actionName: string): RuntimeOutboundCall | undefined;
857
+ /** Backs `ActorRun.startWorkflowSpan`. */
858
+ startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan>;
859
+ /** Backs `ActorRun.runOutsideWorkflowSpan`. */
860
+ runOutsideActorInvocationContext<T>(run: () => T): T;
861
+ /** Identity of the invocation the caller runs in, usable as a cache key. */
862
+ currentInvocationScope(): object | undefined;
863
+ actorName(ctx: ActorContextHandle): string;
864
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
865
+ actorRegion(ctx: ActorContextHandle): string;
866
+ actorSleep(ctx: ActorContextHandle): void;
867
+ actorDestroy(ctx: ActorContextHandle): void;
868
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
869
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
870
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
871
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
872
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
873
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
874
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
875
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
876
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
877
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
878
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
879
+ actorRuntimeState(ctx: ActorContextHandle): object;
880
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
881
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
882
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
883
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
884
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
885
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
886
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
887
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
888
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
889
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
890
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
891
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
892
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
893
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
894
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
895
+ actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
896
+ actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<SqliteTransactionHandle>;
897
+ actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
898
+ actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
899
+ actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
900
+ actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
901
+ actorBeginStateTransaction(ctx: ActorContextHandle, timeoutMs?: number): Promise<ActorStateTransactionHandle>;
902
+ actorStateTransactionExecute(transaction: ActorStateTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
903
+ actorStateTransactionCommit(transaction: ActorStateTransactionHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
904
+ actorStateTransactionRollback(transaction: ActorStateTransactionHandle): Promise<void>;
905
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
906
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
907
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
908
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
909
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
910
+ actorRuntimeSocketProvision(ctx: ActorContextHandle): Promise<RuntimeActorRuntimeSocketEndpointInfo>;
911
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
912
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
913
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
914
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
915
+ actorQueueCompletePersisted(ctx: ActorContextHandle, messageId: bigint, expectedName: string, response?: RuntimeBytes | undefined | null): Promise<boolean>;
916
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
917
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
918
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
919
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
920
+ actorQueueReset(ctx: ActorContextHandle): Promise<void>;
921
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
922
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
923
+ actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
924
+ actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
925
+ actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
926
+ actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
927
+ actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
928
+ actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
929
+ actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
930
+ actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
931
+ actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
932
+ connId(conn: ConnHandle): string;
933
+ connParams(conn: ConnHandle): RuntimeBytes;
934
+ connState(conn: ConnHandle): RuntimeBytes;
935
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
936
+ connIsHibernatable(conn: ConnHandle): boolean;
937
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
938
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
939
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
940
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
941
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
942
+ }
943
+
944
+ interface QueueSendWaitOptions {
945
+ wait: true;
946
+ timeout?: number;
947
+ signal?: AbortSignal;
948
+ }
949
+ interface QueueSendNoWaitOptions {
950
+ wait?: false;
951
+ timeout?: never;
952
+ signal?: AbortSignal;
953
+ }
954
+ interface QueueSendResult<TResponse = unknown> {
955
+ status: "completed" | "timedOut";
956
+ response?: TResponse;
957
+ }
958
+
959
+ /**
960
+ * Action function returned by Actor connections and handles.
961
+ *
962
+ * @typedef {Function} ActorActionFunction
963
+ * @template Args
964
+ * @template Response
965
+ * @param {...Args} args - Arguments for the action function.
966
+ * @returns {Promise<Response>}
967
+ */
968
+ type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
969
+ type IsAny<T> = 0 extends 1 & T ? true : false;
970
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
971
+ type ActorActionMap<R> = {
972
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : NonNullable<R>[K] extends Record<string, unknown> ? ActorActionMap<NonNullable<R>[K]> : never;
973
+ };
974
+ type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
975
+ actions?: infer R;
976
+ } ? R : never;
977
+ interface ActorGatewayOptions {
978
+ skipReadyWait?: boolean;
979
+ }
980
+ interface ActorActionOptions extends ActorGatewayOptions {
981
+ signal?: AbortSignal;
982
+ }
983
+ type ActorConnectOptions = ActorGatewayOptions;
984
+ type ActorFetchInit = RequestInit & ActorGatewayOptions;
985
+ type ActorWebSocketOptions = ActorGatewayOptions;
986
+ /**
987
+ * Maps action methods from actor definition to typed function signatures.
988
+ */
989
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
990
+ type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
991
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
992
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
993
+ (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
994
+ (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
995
+ };
996
+ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
997
+ <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
998
+ (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
999
+ };
1000
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1001
+ send: ActorQueueSend<Record<string, any>>;
1002
+ } : AD extends {
1003
+ config: {
1004
+ queues?: infer Q;
1005
+ };
1006
+ } ? Q extends QueueSchemaConfig ? {
1007
+ send: ActorQueueSend<Q>;
1008
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1009
+ send: ActorQueueSend<Q>;
1010
+ } : {} : {};
1011
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1012
+ on: LooseEventSubscribe;
1013
+ once: LooseEventSubscribe;
1014
+ } : AD extends {
1015
+ config: {
1016
+ events?: infer E;
1017
+ };
1018
+ } ? E extends EventSchemaConfig ? {
1019
+ on: ActorEventSubscribe<E>;
1020
+ once: ActorEventSubscribe<E>;
1021
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1022
+ on: ActorEventSubscribe<E>;
1023
+ once: ActorEventSubscribe<E>;
1024
+ } : {} : {};
1025
+
1026
+ declare class ActorClientError extends Error {
1027
+ }
1028
+ declare class ManagerError extends ActorClientError {
1029
+ constructor(error: string, opts?: ErrorOptions);
1030
+ }
1031
+ declare class MalformedResponseMessage extends ActorClientError {
1032
+ constructor(cause?: unknown);
1033
+ }
1034
+
1035
+ declare class ActorConnDisposed extends ActorClientError {
1036
+ constructor();
1037
+ }
1038
+
1039
+ type ActorResolutionState = ActorQuery;
1040
+
1041
+ /**
1042
+ * Connection status for an actor connection.
1043
+ *
1044
+ * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
1045
+ * - `"connecting"`: Attempting to establish connection
1046
+ * - `"connected"`: Connection is active
1047
+ * - `"disconnected"`: Connection was lost, will auto-reconnect
1048
+ */
1049
+ type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
1050
+ /**
1051
+ * A function that unsubscribes from an event.
1052
+ *
1053
+ * @typedef {Function} EventUnsubscribe
1054
+ */
1055
+ type EventUnsubscribe = () => void;
1056
+ /**
1057
+ * A function that handles connection errors.
1058
+ *
1059
+ * @typedef {Function} ActorErrorCallback
1060
+ */
1061
+ type ActorErrorCallback = (error: RivetError) => void;
1062
+ /**
1063
+ * A callback for connection state changes.
1064
+ *
1065
+ * @typedef {Function} ConnectionStateCallback
1066
+ */
1067
+ type ConnectionStateCallback = () => void;
1068
+ /**
1069
+ * A callback for connection status changes.
1070
+ *
1071
+ * @typedef {Function} StatusChangeCallback
1072
+ */
1073
+ type StatusChangeCallback = (status: ActorConnStatus) => void;
1074
+ declare const CONNECT_SYMBOL: unique symbol;
1075
+ /**
1076
+ * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
1077
+ *
1078
+ * @see {@link ActorConn}
1079
+ */
1080
+ declare class ActorConnRaw {
1081
+ #private;
613
1082
  /**
614
- * Subscribes to connection errors.
1083
+ * Do not call this directly.
615
1084
  *
616
- * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
617
- * @returns {() => void} - A function to unsubscribe from the error handler.
1085
+ * Creates an instance of ActorConnRaw.
1086
+ *
1087
+ * @protected
618
1088
  */
619
- onError(callback: ActorErrorCallback): () => void;
1089
+ constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, currentActorInvocation?: CurrentActorInvocation);
1090
+ send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1091
+ send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
620
1092
  /**
621
- * Returns the current connection status.
1093
+ * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
622
1094
  *
623
- * @returns {ActorConnStatus} - The current connection status.
1095
+ * @see {@link ActorConn}
1096
+ * @template Args - The type of arguments to pass to the action function.
1097
+ * @template Response - The type of the response returned by the action function.
1098
+ * @param {string} name - The name of the action function to call.
1099
+ * @param {...Args} args - The arguments to pass to the action function.
1100
+ * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
624
1101
  */
625
- get connStatus(): ActorConnStatus;
1102
+ action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
1103
+ name: string;
1104
+ args: Args;
1105
+ signal?: AbortSignal;
1106
+ }): Promise<Response>;
626
1107
  /**
627
- * Returns whether the connection is currently open.
1108
+ * Do not call this directly.
1109
+ * Establishes a connection to the server using the specified endpoint & encoding & driver.
628
1110
  *
629
- * @deprecated Use `connStatus` instead.
630
- * @returns {boolean} - True if the connection is open, false otherwise.
1111
+ * @protected
631
1112
  */
632
- get isConnected(): boolean;
1113
+ [CONNECT_SYMBOL](): void;
1114
+ /**
1115
+ * Subscribes to an event that will happen repeatedly.
1116
+ *
1117
+ * @template Args - The type of arguments the event callback will receive.
1118
+ * @param {string} eventName - The name of the event to subscribe to.
1119
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1120
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1121
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1122
+ */
1123
+ on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1124
+ /**
1125
+ * Subscribes to an event that will be triggered only once.
1126
+ *
1127
+ * @template Args - The type of arguments the event callback will receive.
1128
+ * @param {string} eventName - The name of the event to subscribe to.
1129
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1130
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1131
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1132
+ */
1133
+ once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1134
+ /**
1135
+ * Subscribes to connection errors.
1136
+ *
1137
+ * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
1138
+ * @returns {() => void} - A function to unsubscribe from the error handler.
1139
+ */
1140
+ onError(callback: ActorErrorCallback): () => void;
1141
+ /**
1142
+ * Returns the current connection status.
1143
+ *
1144
+ * @returns {ActorConnStatus} - The current connection status.
1145
+ */
1146
+ get connStatus(): ActorConnStatus;
1147
+ /**
1148
+ * Returns whether the connection is currently open.
1149
+ *
1150
+ * @deprecated Use `connStatus` instead.
1151
+ * @returns {boolean} - True if the connection is open, false otherwise.
1152
+ */
1153
+ get isConnected(): boolean;
633
1154
  /**
634
1155
  * Resolves when this connection first reaches the connected state.
635
1156
  */
@@ -701,7 +1222,7 @@ declare class ActorHandleRaw {
701
1222
  *
702
1223
  * @protected
703
1224
  */
704
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, signal?: AbortSignal);
1225
+ constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, signal?: AbortSignal, currentActorInvocation?: CurrentActorInvocation, startCallSpan?: StartCallSpan);
705
1226
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
706
1227
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
707
1228
  /**
@@ -951,6 +1472,18 @@ interface Region {
951
1472
  }
952
1473
  declare const ACTOR_CONNS_SYMBOL: unique symbol;
953
1474
  declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
1475
+ /** Options for constructing a raw actor client. */
1476
+ interface ClientRawOptions {
1477
+ encoding?: Encoding;
1478
+ gateway?: ActorGatewayOptions;
1479
+ }
1480
+ /** Runtime-supplied wiring for clients created inside an actor. Set only by the native runtime. */
1481
+ interface ActorClientRuntimeOptions {
1482
+ /** Supplies the calling actor's invocation so actor-to-actor clients propagate its trace and ray ID. */
1483
+ currentActorInvocation?: CurrentActorInvocation;
1484
+ /** Opens and finishes the Core span covering an actor-to-actor call. */
1485
+ startCallSpan?: StartCallSpan;
1486
+ }
954
1487
  /**
955
1488
  * Client for managing & connecting to actors.
956
1489
  *
@@ -963,7 +1496,7 @@ declare class ClientRaw {
963
1496
  /**
964
1497
  * Creates an instance of Client.
965
1498
  */
966
- constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
1499
+ constructor(driver: EngineControlClient, options?: ClientRawOptions & ActorClientRuntimeOptions);
967
1500
  /**
968
1501
  * Gets a stateless handle to a actor by its ID.
969
1502
  *
@@ -1270,6 +1803,28 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1270
1803
  client<T = any>(): ActorClientFor<T>;
1271
1804
  [key: string]: any;
1272
1805
  }
1806
+ /** @experimental How one run of a workflow function ended. */
1807
+ type WorkflowOutcome = "completed" | "sleeping" | "evicted" | "failed" | "cancelled";
1808
+ /** @experimental How one workflow step attempt ended. `retry` will be tried again, `failed` will not. */
1809
+ type WorkflowStepOutcome = "ok" | "retry" | "failed";
1810
+ /** @experimental One open run of a workflow function, traced as its own invocation. */
1811
+ interface WorkflowSpan {
1812
+ /** Runs `body` attributed to this run. */
1813
+ run<T>(body: () => Promise<T>): Promise<T>;
1814
+ /**
1815
+ * Called by a workflow engine before each attempt at a step. Returns
1816
+ * nothing when tracing is off.
1817
+ */
1818
+ startStep(name: string, attempt: number): WorkflowStepSpan | undefined;
1819
+ finish(outcome: WorkflowOutcome): Promise<void>;
1820
+ }
1821
+ /** @experimental One open attempt at one workflow step. */
1822
+ interface WorkflowStepSpan {
1823
+ /** Runs `body` attributed to this attempt. */
1824
+ run<T>(body: () => Promise<T>): Promise<T>;
1825
+ /** `error` is what the step callback threw. */
1826
+ finish(outcome: WorkflowStepOutcome, error?: unknown): void;
1827
+ }
1273
1828
  /** @experimental */
1274
1829
  interface ActorRun {
1275
1830
  /**
@@ -1277,6 +1832,13 @@ interface ActorRun {
1277
1832
  * ensures this actor's run handler is active, starting it if inactive.
1278
1833
  */
1279
1834
  setWakeAt(timestamp: number | null): Promise<void>;
1835
+ /** @experimental Called by a workflow engine each time it runs the workflow function. */
1836
+ startWorkflowSpan(): Promise<WorkflowSpan>;
1837
+ /**
1838
+ * @experimental Runs `body` outside the current workflow run, so a workflow
1839
+ * engine's own history storage stays out of the trace.
1840
+ */
1841
+ runOutsideWorkflowSpan<T>(body: () => T): T;
1280
1842
  }
1281
1843
  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> & {
1282
1844
  conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
@@ -1342,6 +1904,10 @@ declare const ActorConfigSchema: z.ZodObject<{
1342
1904
  onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1343
1905
  actions: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
1344
1906
  actionInputSchemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1907
+ tracing: z.ZodOptional<z.ZodObject<{
1908
+ sampler: z.ZodOptional<z.ZodNumber>;
1909
+ actions: z.ZodOptional<z.ZodType<ActionSampleRates, unknown, z.core.$ZodTypeInternals<ActionSampleRates, unknown>>>;
1910
+ }, z.core.$strict>>;
1345
1911
  connParamsSchema: z.ZodOptional<z.ZodAny>;
1346
1912
  events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1347
1913
  queues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
@@ -1389,8 +1955,8 @@ declare const ActorConfigSchema: z.ZodObject<{
1389
1955
  state: "state";
1390
1956
  database: "database";
1391
1957
  console: "console";
1392
- workflow: "workflow";
1393
1958
  queue: "queue";
1959
+ workflow: "workflow";
1394
1960
  schedules: "schedules";
1395
1961
  connections: "connections";
1396
1962
  }>;
@@ -1582,6 +2148,11 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1582
2148
  * May mirror nested action groups or use dot-separated low-level action names.
1583
2149
  */
1584
2150
  actionInputSchemas?: ActionInputSchemas;
2151
+ /**
2152
+ * How much of this actor's work is recorded in traces. Defaults to the
2153
+ * process sampler from `OTEL_TRACES_SAMPLER`.
2154
+ */
2155
+ tracing?: ActorTracingOptions<TActions>;
1585
2156
  /**
1586
2157
  * Optional schema for validating connection params in native runtimes.
1587
2158
  */
@@ -1840,431 +2411,6 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1840
2411
  use: A;
1841
2412
  };
1842
2413
 
1843
- declare const handleBrand: unique symbol;
1844
- type OpaqueHandle<Name extends string> = {
1845
- readonly [handleBrand]: Name;
1846
- };
1847
- type RegistryHandle = OpaqueHandle<"registry">;
1848
- type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1849
- type ActorContextHandle = OpaqueHandle<"actorContext">;
1850
- type ConnHandle = OpaqueHandle<"conn">;
1851
- type WebSocketHandle = OpaqueHandle<"webSocket">;
1852
- type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1853
- type ActorStateTransactionHandle = OpaqueHandle<"actorStateTransaction">;
1854
- type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
1855
- type RuntimeBytes = Uint8Array;
1856
- interface RuntimeActorKeySegment {
1857
- kind: string;
1858
- stringValue?: string;
1859
- numberValue?: number;
1860
- }
1861
- interface RuntimeHttpRequest {
1862
- method: string;
1863
- uri: string;
1864
- headers?: Record<string, string>;
1865
- body?: RuntimeBytes;
1866
- }
1867
- interface RuntimeHttpResponseBodyStream {
1868
- cancelled(): Promise<void>;
1869
- write(chunk: Uint8Array): Promise<void>;
1870
- end(): Promise<void>;
1871
- error(message: string): Promise<void>;
1872
- }
1873
- interface RuntimeStateDeltaPayload {
1874
- state?: RuntimeBytes;
1875
- connHibernation: Array<{
1876
- connId: string;
1877
- bytes: RuntimeBytes;
1878
- }>;
1879
- connHibernationRemoved: string[];
1880
- }
1881
- interface RuntimeWorkflowKvWrite {
1882
- key: RuntimeBytes;
1883
- value: RuntimeBytes;
1884
- }
1885
- interface RuntimeRequestSaveOpts {
1886
- immediate?: boolean;
1887
- maxWaitMs?: number;
1888
- }
1889
- interface RuntimeInspectorSnapshot {
1890
- stateRevision: number;
1891
- connectionsRevision: number;
1892
- queueRevision: number;
1893
- activeConnections: number;
1894
- queueSize: number;
1895
- connectedClients: number;
1896
- }
1897
- interface RuntimeQueueMessage {
1898
- id(): bigint;
1899
- name(): string;
1900
- body(): RuntimeBytes;
1901
- createdAt(): number;
1902
- isCompletable(): boolean;
1903
- complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1904
- }
1905
- interface RuntimeQueueInspectMessage {
1906
- id: number;
1907
- name: string;
1908
- createdAtMs: number;
1909
- }
1910
- interface RuntimeScheduledEventInfo {
1911
- id: string;
1912
- action: string;
1913
- args: RuntimeBytes;
1914
- runAt: number;
1915
- }
1916
- interface RuntimeCronJobInfo {
1917
- name: string;
1918
- kind: "cron" | "every";
1919
- action: string;
1920
- args: RuntimeBytes;
1921
- nextRunAt: number;
1922
- lastRunAt?: number;
1923
- expression?: string;
1924
- timezone?: string;
1925
- intervalMs?: number;
1926
- maxHistory: number;
1927
- }
1928
- interface RuntimeScheduleErrorInfo {
1929
- group: string;
1930
- code: string;
1931
- message: string;
1932
- metadata?: unknown;
1933
- }
1934
- interface RuntimeCronFire {
1935
- action: string;
1936
- scheduledAt: number;
1937
- firedAt: number;
1938
- finishedAt?: number;
1939
- result: "running" | "ok" | "error" | "skipped";
1940
- error?: RuntimeScheduleErrorInfo;
1941
- }
1942
- interface RuntimeQueueNextBatchOptions {
1943
- names?: string[];
1944
- count?: number;
1945
- timeoutMs?: number;
1946
- completable?: boolean;
1947
- }
1948
- interface RuntimeQueueWaitOptions {
1949
- timeoutMs?: number;
1950
- completable?: boolean;
1951
- }
1952
- interface RuntimeQueueEnqueueAndWaitOptions {
1953
- timeoutMs?: number;
1954
- }
1955
- interface RuntimeQueueTryNextBatchOptions {
1956
- names?: string[];
1957
- count?: number;
1958
- completable?: boolean;
1959
- }
1960
- interface RuntimeKvListOptions {
1961
- reverse?: boolean;
1962
- limit?: number;
1963
- }
1964
- interface RuntimeKvEntry {
1965
- key: RuntimeBytes;
1966
- value: RuntimeBytes;
1967
- }
1968
- type RuntimeSqlBindNoValues = {
1969
- intValue?: never;
1970
- floatValue?: never;
1971
- textValue?: never;
1972
- blobValue?: never;
1973
- };
1974
- type RuntimeSqlBindParam = ({
1975
- kind: "null";
1976
- } & RuntimeSqlBindNoValues) | {
1977
- kind: "int";
1978
- intValue: number;
1979
- floatValue?: never;
1980
- textValue?: never;
1981
- blobValue?: never;
1982
- } | {
1983
- kind: "float";
1984
- intValue?: never;
1985
- floatValue: number;
1986
- textValue?: never;
1987
- blobValue?: never;
1988
- } | {
1989
- kind: "text";
1990
- intValue?: never;
1991
- floatValue?: never;
1992
- textValue: string;
1993
- blobValue?: never;
1994
- } | {
1995
- kind: "blob";
1996
- intValue?: never;
1997
- floatValue?: never;
1998
- textValue?: never;
1999
- blobValue: RuntimeBytes;
2000
- };
2001
- type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
2002
- interface RuntimeActorRuntimeSocketEndpointInfo {
2003
- path: string;
2004
- }
2005
- interface RuntimeSqlQueryResult {
2006
- columns: string[];
2007
- rows: unknown[][];
2008
- }
2009
- type RuntimeSqlExecResult = RuntimeSqlQueryResult;
2010
- interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
2011
- changes: number;
2012
- lastInsertRowId?: number | null;
2013
- }
2014
- interface RuntimeSqlBatchStatement {
2015
- sql: string;
2016
- params?: RuntimeSqlBindParams;
2017
- }
2018
- interface RuntimeSqlRunResult {
2019
- changes: number;
2020
- }
2021
- interface RuntimeActorConfig {
2022
- name?: string;
2023
- icon?: string;
2024
- hasDatabase?: boolean;
2025
- remoteSqlite?: boolean;
2026
- sqliteProfiling?: SqliteProfilingOptions;
2027
- enableActorRuntimeSocket?: boolean;
2028
- hasState?: boolean;
2029
- canHibernateWebsocket?: boolean;
2030
- stateSaveIntervalMs?: number;
2031
- createStateTimeoutMs?: number;
2032
- onCreateTimeoutMs?: number;
2033
- createVarsTimeoutMs?: number;
2034
- createConnStateTimeoutMs?: number;
2035
- onBeforeConnectTimeoutMs?: number;
2036
- onConnectTimeoutMs?: number;
2037
- onMigrateTimeoutMs?: number;
2038
- onWakeTimeoutMs?: number;
2039
- onBeforeActorStartTimeoutMs?: number;
2040
- actionTimeoutMs?: number;
2041
- onRequestTimeoutMs?: number;
2042
- sleepTimeoutMs?: number;
2043
- noSleep?: boolean;
2044
- sleepGracePeriodMs?: number;
2045
- connectionLivenessTimeoutMs?: number;
2046
- connectionLivenessIntervalMs?: number;
2047
- maxQueueSize?: number;
2048
- maxSchedules?: number;
2049
- maxQueueMessageSize?: number;
2050
- maxIncomingMessageSize?: number;
2051
- maxOutgoingMessageSize?: number;
2052
- preloadMaxWorkflowBytes?: number;
2053
- preloadMaxConnectionsBytes?: number;
2054
- actions?: Array<{
2055
- name: string;
2056
- }>;
2057
- inspectorTabs?: Array<RuntimeInspectorTabEntry>;
2058
- }
2059
- interface RuntimeInspectorTabEntry {
2060
- id: string;
2061
- /** Required for custom entries; omitted for built-in hides. */
2062
- label?: string;
2063
- /**
2064
- * Required for custom entries — absolute path to the source directory.
2065
- * Resolved on the TS side before being handed to the runtime.
2066
- */
2067
- source?: string;
2068
- /** Optional icon id for custom entries. */
2069
- icon?: string;
2070
- /** Set to true for built-in hide entries. */
2071
- hidden?: boolean;
2072
- }
2073
- interface RuntimeServeConfig {
2074
- version: number;
2075
- endpoint: string;
2076
- token?: string;
2077
- namespace: string;
2078
- poolName: string;
2079
- engineBinaryPath?: string;
2080
- startServices?: boolean;
2081
- servicesBinaryPath?: string;
2082
- engineHost?: string;
2083
- enginePort?: number;
2084
- handleInspectorHttpInRuntime?: boolean;
2085
- inspectorTestToken?: string;
2086
- serverlessBasePath?: string;
2087
- serverlessPackageVersion: string;
2088
- serverlessClientEndpoint?: string;
2089
- serverlessClientNamespace?: string;
2090
- serverlessClientToken?: string;
2091
- serverlessValidateEndpoint: boolean;
2092
- serverlessMaxStartPayloadBytes: number;
2093
- }
2094
- interface RuntimeListenerConfig {
2095
- port: number;
2096
- host?: string;
2097
- publicDir?: string;
2098
- application?: RuntimeApplicationFetch;
2099
- }
2100
- interface RuntimeServerlessRequest {
2101
- method: string;
2102
- url: string;
2103
- headers: Record<string, string>;
2104
- body: RuntimeBytes;
2105
- }
2106
- interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
2107
- cancelToken?: CancellationTokenHandle;
2108
- }
2109
- interface RuntimeApplicationResponse {
2110
- status: number;
2111
- headers: Record<string, string>;
2112
- body?: RuntimeBytes;
2113
- stream?: boolean;
2114
- }
2115
- type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
2116
- interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
2117
- application: RuntimeApplicationFetch;
2118
- }
2119
- interface RuntimeServerlessResponseHead {
2120
- status: number;
2121
- headers: Record<string, string>;
2122
- }
2123
- interface RuntimeRegistryRouteResponse {
2124
- status: number;
2125
- headers: Record<string, string>;
2126
- body: RuntimeBytes;
2127
- }
2128
- type RuntimeServerlessStreamEvent = {
2129
- kind: "chunk";
2130
- chunk?: RuntimeBytes;
2131
- } | {
2132
- kind: "end";
2133
- error?: {
2134
- group: string;
2135
- code: string;
2136
- message: string;
2137
- };
2138
- };
2139
- type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
2140
- type RuntimeWebSocketEvent = {
2141
- kind: "message";
2142
- data: string | RuntimeBytes;
2143
- binary: boolean;
2144
- messageIndex?: number;
2145
- } | {
2146
- kind: "close";
2147
- code: number;
2148
- reason: string;
2149
- wasClean: boolean;
2150
- };
2151
- interface CoreRuntime {
2152
- readonly kind: "napi" | "wasm";
2153
- createRegistry(): RegistryHandle;
2154
- registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
2155
- serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
2156
- waitRegistryReady(registry: RegistryHandle): Promise<void>;
2157
- shutdownRegistry(registry: RegistryHandle): Promise<void>;
2158
- registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
2159
- handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
2160
- serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
2161
- serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
2162
- registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2163
- registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2164
- registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2165
- createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
2166
- createCancellationToken(): CancellationTokenHandle;
2167
- cancellationTokenAborted(token: CancellationTokenHandle): boolean;
2168
- cancelCancellationToken(token: CancellationTokenHandle): void;
2169
- onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
2170
- actorState(ctx: ActorContextHandle): RuntimeBytes;
2171
- actorBeginOnStateChange(ctx: ActorContextHandle): void;
2172
- actorEndOnStateChange(ctx: ActorContextHandle): void;
2173
- actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
2174
- actorSetRunWakeAt(ctx: ActorContextHandle, timestampMs?: number | undefined | null): Promise<void>;
2175
- actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
2176
- actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
2177
- actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
2178
- actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
2179
- actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
2180
- actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
2181
- actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
2182
- actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
2183
- actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
2184
- actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
2185
- actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
2186
- actorId(ctx: ActorContextHandle): string;
2187
- actorName(ctx: ActorContextHandle): string;
2188
- actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
2189
- actorRegion(ctx: ActorContextHandle): string;
2190
- actorSleep(ctx: ActorContextHandle): void;
2191
- actorDestroy(ctx: ActorContextHandle): void;
2192
- actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
2193
- actorConns(ctx: ActorContextHandle): ConnHandle[];
2194
- actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
2195
- actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
2196
- actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2197
- actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
2198
- actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
2199
- actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2200
- actorBeginKeepAwake(ctx: ActorContextHandle): number;
2201
- actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
2202
- actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2203
- actorRuntimeState(ctx: ActorContextHandle): object;
2204
- actorClearRuntimeState(ctx: ActorContextHandle): void;
2205
- actorRestartRunHandler(ctx: ActorContextHandle): void;
2206
- actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
2207
- actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
2208
- actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
2209
- actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
2210
- actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
2211
- actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
2212
- actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
2213
- actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
2214
- actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
2215
- actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
2216
- actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
2217
- actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
2218
- actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
2219
- actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
2220
- actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<SqliteTransactionHandle>;
2221
- actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
2222
- actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
2223
- actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
2224
- actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
2225
- actorBeginStateTransaction(ctx: ActorContextHandle, timeoutMs?: number): Promise<ActorStateTransactionHandle>;
2226
- actorStateTransactionExecute(transaction: ActorStateTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
2227
- actorStateTransactionCommit(transaction: ActorStateTransactionHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
2228
- actorStateTransactionRollback(transaction: ActorStateTransactionHandle): Promise<void>;
2229
- actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
2230
- actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
2231
- actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
2232
- actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
2233
- actorSqlClose(ctx: ActorContextHandle): Promise<void>;
2234
- actorRuntimeSocketProvision(ctx: ActorContextHandle): Promise<RuntimeActorRuntimeSocketEndpointInfo>;
2235
- actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
2236
- actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
2237
- actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
2238
- actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
2239
- actorQueueCompletePersisted(ctx: ActorContextHandle, messageId: bigint, expectedName: string, response?: RuntimeBytes | undefined | null): Promise<boolean>;
2240
- actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
2241
- actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
2242
- actorQueueMaxSize(ctx: ActorContextHandle): number;
2243
- actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
2244
- actorQueueReset(ctx: ActorContextHandle): Promise<void>;
2245
- actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
2246
- actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
2247
- actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
2248
- actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
2249
- actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
2250
- actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
2251
- actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
2252
- actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
2253
- actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
2254
- actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
2255
- actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
2256
- connId(conn: ConnHandle): string;
2257
- connParams(conn: ConnHandle): RuntimeBytes;
2258
- connState(conn: ConnHandle): RuntimeBytes;
2259
- connSetState(conn: ConnHandle, state: RuntimeBytes): void;
2260
- connIsHibernatable(conn: ConnHandle): boolean;
2261
- connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
2262
- connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
2263
- webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
2264
- webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
2265
- webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
2266
- }
2267
-
2268
2414
  declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
2269
2415
  runtime: CoreRuntime;
2270
2416
  registry: RegistryHandle;