rivetkit 2.3.18-rc.4 → 2.3.19

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 (136) hide show
  1. package/dist/browser/client.d.ts +723 -616
  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 +3 -1
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +110 -3
  14. package/dist/tsup/agent-os/index.d.ts +110 -3
  15. package/dist/tsup/agent-os/index.js +3 -1
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-ENDOWQTM.js → chunk-464WE4RF.js} +2 -2
  18. package/dist/tsup/{chunk-KKG2CTSI.js → chunk-4SC2NSAV.js} +2 -2
  19. package/dist/tsup/{chunk-R2WRP6VV.cjs → chunk-7A5EIXJJ.cjs} +7 -7
  20. package/dist/tsup/{chunk-R2WRP6VV.cjs.map → chunk-7A5EIXJJ.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-GUVDWB2O.cjs → chunk-7BRRGBRY.cjs} +10 -10
  22. package/dist/tsup/{chunk-GUVDWB2O.cjs.map → chunk-7BRRGBRY.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-KVPU65TI.js → chunk-7HTST3NX.js} +3 -3
  24. package/dist/tsup/{chunk-MS6C3B2I.js → chunk-BKX7UDTA.js} +185 -28
  25. package/dist/tsup/chunk-BKX7UDTA.js.map +1 -0
  26. package/dist/tsup/{chunk-FL2FDUSZ.js → chunk-DK3L22R6.js} +4 -4
  27. package/dist/tsup/{chunk-CAL23WOC.js → chunk-DN6MD3KK.js} +7 -7
  28. package/dist/tsup/chunk-DN6MD3KK.js.map +1 -0
  29. package/dist/tsup/{chunk-6W5VGLFT.js → chunk-EB77NZL4.js} +1 -1
  30. package/dist/tsup/chunk-EB77NZL4.js.map +1 -0
  31. package/dist/tsup/{chunk-4KGXFC6M.cjs → chunk-EO5UOXXY.cjs} +1 -1
  32. package/dist/tsup/chunk-EO5UOXXY.cjs.map +1 -0
  33. package/dist/tsup/{chunk-QFLG6UB4.cjs → chunk-G4U5L6AX.cjs} +3 -3
  34. package/dist/tsup/{chunk-QFLG6UB4.cjs.map → chunk-G4U5L6AX.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-TGGF6SZN.cjs → chunk-IJUXBWH4.cjs} +351 -194
  36. package/dist/tsup/chunk-IJUXBWH4.cjs.map +1 -0
  37. package/dist/tsup/{chunk-2JSYYH6P.cjs → chunk-JX2ITWAV.cjs} +13 -2
  38. package/dist/tsup/chunk-JX2ITWAV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-N3DJTMSZ.cjs → chunk-OGPFN6BT.cjs} +3 -3
  40. package/dist/tsup/{chunk-N3DJTMSZ.cjs.map → chunk-OGPFN6BT.cjs.map} +1 -1
  41. package/dist/tsup/{chunk-OUQUIBVW.js → chunk-P2OFXH4G.js} +12 -1
  42. package/dist/tsup/chunk-P2OFXH4G.js.map +1 -0
  43. package/dist/tsup/{chunk-F3IP3SGO.cjs → chunk-PPEIPCW4.cjs} +4 -4
  44. package/dist/tsup/{chunk-F3IP3SGO.cjs.map → chunk-PPEIPCW4.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-7E2W2YSM.cjs → chunk-RJC5O2SD.cjs} +13 -13
  46. package/dist/tsup/chunk-RJC5O2SD.cjs.map +1 -0
  47. package/dist/tsup/{chunk-YQD6RRVP.js → chunk-WME6KOXW.js} +2 -2
  48. package/dist/tsup/{chunk-PLAJJOTE.js → chunk-X7RMJQGY.js} +2 -2
  49. package/dist/tsup/{chunk-4OMHYVOQ.cjs → chunk-Z4RAXFSD.cjs} +3 -3
  50. package/dist/tsup/{chunk-4OMHYVOQ.cjs.map → chunk-Z4RAXFSD.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-gvHwMas-.d.cts → config-8n2AOhXK.d.cts} +114 -10
  60. package/dist/tsup/{config-Ug5M2MOr.d.ts → config-DEm0yIVV.d.ts} +114 -10
  61. package/dist/tsup/{context-DererUCI.d.ts → context-DGg2-IOm.d.ts} +1 -1
  62. package/dist/tsup/{context-BSCBvbfM.d.cts → context-DwjOVvlE.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 +492 -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 +367 -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/config.ts +38 -0
  105. package/src/actor/errors.ts +31 -0
  106. package/src/client/actor-conn.ts +7 -0
  107. package/src/client/actor-handle.ts +57 -17
  108. package/src/client/client.ts +26 -6
  109. package/src/client/outbound-telemetry.ts +66 -0
  110. package/src/client/queue.ts +3 -0
  111. package/src/client/raw-utils.ts +3 -0
  112. package/src/common/actor-router-consts.ts +3 -0
  113. package/src/common/actor-telemetry-context.ts +19 -0
  114. package/src/common/otel-context.ts +99 -0
  115. package/src/common/utils.ts +1 -19
  116. package/src/engine-client/actor-http-client.ts +15 -0
  117. package/src/registry/index.ts +6 -0
  118. package/src/registry/napi-runtime.ts +155 -35
  119. package/src/registry/native.ts +277 -191
  120. package/src/registry/runtime.ts +66 -0
  121. package/src/registry/wasm-runtime.ts +40 -0
  122. package/src/workflow/driver.ts +20 -12
  123. package/dist/tsup/chunk-2JSYYH6P.cjs.map +0 -1
  124. package/dist/tsup/chunk-4KGXFC6M.cjs.map +0 -1
  125. package/dist/tsup/chunk-6W5VGLFT.js.map +0 -1
  126. package/dist/tsup/chunk-7E2W2YSM.cjs.map +0 -1
  127. package/dist/tsup/chunk-CAL23WOC.js.map +0 -1
  128. package/dist/tsup/chunk-MS6C3B2I.js.map +0 -1
  129. package/dist/tsup/chunk-OUQUIBVW.js.map +0 -1
  130. package/dist/tsup/chunk-TGGF6SZN.cjs.map +0 -1
  131. /package/dist/tsup/{chunk-ENDOWQTM.js.map → chunk-464WE4RF.js.map} +0 -0
  132. /package/dist/tsup/{chunk-KKG2CTSI.js.map → chunk-4SC2NSAV.js.map} +0 -0
  133. /package/dist/tsup/{chunk-KVPU65TI.js.map → chunk-7HTST3NX.js.map} +0 -0
  134. /package/dist/tsup/{chunk-FL2FDUSZ.js.map → chunk-DK3L22R6.js.map} +0 -0
  135. /package/dist/tsup/{chunk-YQD6RRVP.js.map → chunk-WME6KOXW.js.map} +0 -0
  136. /package/dist/tsup/{chunk-PLAJJOTE.js.map → chunk-X7RMJQGY.js.map} +0 -0
@@ -420,226 +420,717 @@ interface ActorOutput {
420
420
  error?: unknown;
421
421
  }
422
422
 
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;
423
+ /** Correlation owned by the currently executing Core actor invocation. */
424
+ interface ActorInvocationTraceContext {
425
+ /** Ray ID the invocation received, absent when nothing upstream supplied one. */
426
+ readonly rayId?: string;
427
+ /** Core-owned invocation span context, absent when tracing is disabled. */
428
+ readonly span?: ActorInvocationSpanContext;
429
+ }
430
+ /** W3C span context of the Core invocation span. */
431
+ interface ActorInvocationSpanContext {
432
+ /** W3C trace identifier. */
433
+ readonly traceId: string;
434
+ /** W3C span identifier for the Core invocation. */
435
+ readonly spanId: string;
436
+ /** OpenTelemetry trace flags encoded as an integer. */
437
+ readonly traceFlags: number;
438
+ /** Optional vendor trace state inherited by the Core invocation. */
439
+ readonly tracestate?: string;
436
440
  }
437
441
 
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;
442
+ declare const handleBrand: unique symbol;
443
+ type OpaqueHandle<Name extends string> = {
444
+ readonly [handleBrand]: Name;
452
445
  };
453
- type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
454
- actions?: infer R;
455
- } ? R : never;
456
- interface ActorGatewayOptions {
457
- skipReadyWait?: boolean;
446
+ type RegistryHandle = OpaqueHandle<"registry">;
447
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
448
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
449
+ type ConnHandle = OpaqueHandle<"conn">;
450
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
451
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
452
+ type ActorStateTransactionHandle = OpaqueHandle<"actorStateTransaction">;
453
+ type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
454
+ type RuntimeBytes = Uint8Array;
455
+ interface RuntimeActorKeySegment {
456
+ kind: string;
457
+ stringValue?: string;
458
+ numberValue?: number;
458
459
  }
459
- interface ActorActionOptions extends ActorGatewayOptions {
460
- signal?: AbortSignal;
460
+ /** Resolves correlation at operation time so retained clients cannot freeze stale context. */
461
+ type CurrentActorInvocation = () => ActorInvocationTraceContext | undefined;
462
+ /** One open call from an actor out to another actor. */
463
+ interface RuntimeOutboundCall {
464
+ /**
465
+ * W3C context of the call's own span, to send to the callee so it parents to
466
+ * the call. Absent when tracing is disabled.
467
+ */
468
+ readonly span?: ActorInvocationSpanContext;
469
+ /**
470
+ * Records the call's outcome. `error` is the failure encoded the way the
471
+ * bridge encodes errors, so a structured error keeps its group and code.
472
+ */
473
+ finish(error?: string): void;
461
474
  }
462
- type ActorConnectOptions = ActorGatewayOptions;
463
- type ActorFetchInit = RequestInit & ActorGatewayOptions;
464
- type ActorWebSocketOptions = ActorGatewayOptions;
465
475
  /**
466
- * Maps action methods from actor definition to typed function signatures.
476
+ * Opens the span covering one call out to another actor, or returns `undefined`
477
+ * outside an invocation or on a runtime without invocation telemetry. Callers
478
+ * send their own context when it returns nothing.
467
479
  */
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>;
480
+ type StartCallSpan = (actorName: string, actionName: string) => RuntimeOutboundCall | undefined;
481
+ interface RuntimeHttpRequest {
482
+ method: string;
483
+ uri: string;
484
+ headers?: Record<string, string>;
485
+ body?: RuntimeBytes;
486
+ }
487
+ interface RuntimeHttpResponseBodyStream {
488
+ cancelled(): Promise<void>;
489
+ write(chunk: Uint8Array): Promise<void>;
490
+ end(): Promise<void>;
491
+ error(message: string): Promise<void>;
492
+ }
493
+ interface RuntimeStateDeltaPayload {
494
+ state?: RuntimeBytes;
495
+ connHibernation: Array<{
496
+ connId: string;
497
+ bytes: RuntimeBytes;
498
+ }>;
499
+ connHibernationRemoved: string[];
500
+ }
501
+ interface RuntimeWorkflowKvWrite {
502
+ key: RuntimeBytes;
503
+ value: RuntimeBytes;
504
+ }
505
+ interface RuntimeRequestSaveOpts {
506
+ immediate?: boolean;
507
+ maxWaitMs?: number;
508
+ }
509
+ interface RuntimeInspectorSnapshot {
510
+ stateRevision: number;
511
+ connectionsRevision: number;
512
+ queueRevision: number;
513
+ activeConnections: number;
514
+ queueSize: number;
515
+ connectedClients: number;
516
+ }
517
+ interface RuntimeQueueMessage {
518
+ id(): bigint;
519
+ name(): string;
520
+ body(): RuntimeBytes;
521
+ createdAt(): number;
522
+ isCompletable(): boolean;
523
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
524
+ }
525
+ interface RuntimeQueueInspectMessage {
526
+ id: number;
527
+ name: string;
528
+ createdAtMs: number;
529
+ }
530
+ interface RuntimeScheduledEventInfo {
531
+ id: string;
532
+ action: string;
533
+ args: RuntimeBytes;
534
+ runAt: number;
535
+ }
536
+ interface RuntimeCronJobInfo {
537
+ name: string;
538
+ kind: "cron" | "every";
539
+ action: string;
540
+ args: RuntimeBytes;
541
+ nextRunAt: number;
542
+ lastRunAt?: number;
543
+ expression?: string;
544
+ timezone?: string;
545
+ intervalMs?: number;
546
+ maxHistory: number;
547
+ }
548
+ interface RuntimeScheduleErrorInfo {
549
+ group: string;
550
+ code: string;
551
+ message: string;
552
+ metadata?: unknown;
553
+ }
554
+ interface RuntimeCronFire {
555
+ action: string;
556
+ scheduledAt: number;
557
+ firedAt: number;
558
+ finishedAt?: number;
559
+ result: "running" | "ok" | "error" | "skipped";
560
+ error?: RuntimeScheduleErrorInfo;
561
+ }
562
+ interface RuntimeQueueNextBatchOptions {
563
+ names?: string[];
564
+ count?: number;
565
+ timeoutMs?: number;
566
+ completable?: boolean;
567
+ }
568
+ interface RuntimeQueueWaitOptions {
569
+ timeoutMs?: number;
570
+ completable?: boolean;
571
+ }
572
+ interface RuntimeQueueEnqueueAndWaitOptions {
573
+ timeoutMs?: number;
574
+ }
575
+ interface RuntimeQueueTryNextBatchOptions {
576
+ names?: string[];
577
+ count?: number;
578
+ completable?: boolean;
579
+ }
580
+ interface RuntimeKvListOptions {
581
+ reverse?: boolean;
582
+ limit?: number;
583
+ }
584
+ interface RuntimeKvEntry {
585
+ key: RuntimeBytes;
586
+ value: RuntimeBytes;
587
+ }
588
+ type RuntimeSqlBindNoValues = {
589
+ intValue?: never;
590
+ floatValue?: never;
591
+ textValue?: never;
592
+ blobValue?: never;
474
593
  };
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;
594
+ type RuntimeSqlBindParam = ({
595
+ kind: "null";
596
+ } & RuntimeSqlBindNoValues) | {
597
+ kind: "int";
598
+ intValue: number;
599
+ floatValue?: never;
600
+ textValue?: never;
601
+ blobValue?: never;
602
+ } | {
603
+ kind: "float";
604
+ intValue?: never;
605
+ floatValue: number;
606
+ textValue?: never;
607
+ blobValue?: never;
608
+ } | {
609
+ kind: "text";
610
+ intValue?: never;
611
+ floatValue?: never;
612
+ textValue: string;
613
+ blobValue?: never;
614
+ } | {
615
+ kind: "blob";
616
+ intValue?: never;
617
+ floatValue?: never;
618
+ textValue?: never;
619
+ blobValue: RuntimeBytes;
478
620
  };
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 {
621
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
622
+ interface RuntimeActorRuntimeSocketEndpointInfo {
623
+ path: string;
506
624
  }
507
- declare class ManagerError extends ActorClientError {
508
- constructor(error: string, opts?: ErrorOptions);
625
+ interface RuntimeSqlQueryResult {
626
+ columns: string[];
627
+ rows: unknown[][];
509
628
  }
510
- declare class MalformedResponseMessage extends ActorClientError {
511
- constructor(cause?: unknown);
629
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
630
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
631
+ changes: number;
632
+ lastInsertRowId?: number | null;
512
633
  }
513
-
514
- declare class ActorConnDisposed extends ActorClientError {
515
- constructor();
634
+ interface RuntimeSqlBatchStatement {
635
+ sql: string;
636
+ params?: RuntimeSqlBindParams;
516
637
  }
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;
561
- /**
562
- * Do not call this directly.
563
- *
564
- * Creates an instance of ActorConnRaw.
565
- *
566
- * @protected
567
- */
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>;
571
- /**
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.
580
- */
581
- action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
638
+ interface RuntimeSqlRunResult {
639
+ changes: number;
640
+ }
641
+ interface RuntimeActorConfig {
642
+ name?: string;
643
+ icon?: string;
644
+ hasDatabase?: boolean;
645
+ remoteSqlite?: boolean;
646
+ sqliteProfiling?: SqliteProfilingOptions;
647
+ enableActorRuntimeSocket?: boolean;
648
+ hasState?: boolean;
649
+ canHibernateWebsocket?: boolean;
650
+ stateSaveIntervalMs?: number;
651
+ createStateTimeoutMs?: number;
652
+ onCreateTimeoutMs?: number;
653
+ createVarsTimeoutMs?: number;
654
+ createConnStateTimeoutMs?: number;
655
+ onBeforeConnectTimeoutMs?: number;
656
+ onConnectTimeoutMs?: number;
657
+ onMigrateTimeoutMs?: number;
658
+ onWakeTimeoutMs?: number;
659
+ onBeforeActorStartTimeoutMs?: number;
660
+ actionTimeoutMs?: number;
661
+ onRequestTimeoutMs?: number;
662
+ sleepTimeoutMs?: number;
663
+ noSleep?: boolean;
664
+ sleepGracePeriodMs?: number;
665
+ connectionLivenessTimeoutMs?: number;
666
+ connectionLivenessIntervalMs?: number;
667
+ maxQueueSize?: number;
668
+ maxSchedules?: number;
669
+ maxQueueMessageSize?: number;
670
+ maxIncomingMessageSize?: number;
671
+ maxOutgoingMessageSize?: number;
672
+ preloadMaxWorkflowBytes?: number;
673
+ preloadMaxConnectionsBytes?: number;
674
+ actions?: Array<{
582
675
  name: string;
583
- args: Args;
584
- signal?: AbortSignal;
585
- }): Promise<Response>;
676
+ }>;
677
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
678
+ }
679
+ interface RuntimeInspectorTabEntry {
680
+ id: string;
681
+ /** Required for custom entries; omitted for built-in hides. */
682
+ label?: string;
586
683
  /**
587
- * Do not call this directly.
588
- * Establishes a connection to the server using the specified endpoint & encoding & driver.
589
- *
590
- * @protected
684
+ * Required for custom entries — absolute path to the source directory.
685
+ * Resolved on the TS side before being handed to the runtime.
591
686
  */
592
- [CONNECT_SYMBOL](): void;
687
+ source?: string;
688
+ /** Optional icon id for custom entries. */
689
+ icon?: string;
690
+ /** Set to true for built-in hide entries. */
691
+ hidden?: boolean;
692
+ }
693
+ interface RuntimeServeConfig {
694
+ version: number;
695
+ endpoint: string;
696
+ token?: string;
697
+ namespace: string;
698
+ poolName: string;
699
+ engineBinaryPath?: string;
700
+ startServices?: boolean;
701
+ servicesBinaryPath?: string;
702
+ engineHost?: string;
703
+ enginePort?: number;
704
+ handleInspectorHttpInRuntime?: boolean;
705
+ inspectorTestToken?: string;
706
+ serverlessBasePath?: string;
707
+ serverlessPackageVersion: string;
708
+ serverlessClientEndpoint?: string;
709
+ serverlessClientNamespace?: string;
710
+ serverlessClientToken?: string;
711
+ serverlessValidateEndpoint: boolean;
712
+ serverlessMaxStartPayloadBytes: number;
713
+ }
714
+ interface RuntimeListenerConfig {
715
+ port: number;
716
+ host?: string;
717
+ publicDir?: string;
718
+ application?: RuntimeApplicationFetch;
719
+ }
720
+ interface RuntimeServerlessRequest {
721
+ method: string;
722
+ url: string;
723
+ headers: Record<string, string>;
724
+ body: RuntimeBytes;
725
+ }
726
+ interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
727
+ cancelToken?: CancellationTokenHandle;
728
+ }
729
+ interface RuntimeApplicationResponse {
730
+ status: number;
731
+ headers: Record<string, string>;
732
+ body?: RuntimeBytes;
733
+ stream?: boolean;
734
+ }
735
+ type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
736
+ interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
737
+ application: RuntimeApplicationFetch;
738
+ }
739
+ interface RuntimeServerlessResponseHead {
740
+ status: number;
741
+ headers: Record<string, string>;
742
+ }
743
+ interface RuntimeRegistryRouteResponse {
744
+ status: number;
745
+ headers: Record<string, string>;
746
+ body: RuntimeBytes;
747
+ }
748
+ type RuntimeServerlessStreamEvent = {
749
+ kind: "chunk";
750
+ chunk?: RuntimeBytes;
751
+ } | {
752
+ kind: "end";
753
+ error?: {
754
+ group: string;
755
+ code: string;
756
+ message: string;
757
+ };
758
+ };
759
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
760
+ type RuntimeWebSocketEvent = {
761
+ kind: "message";
762
+ data: string | RuntimeBytes;
763
+ binary: boolean;
764
+ messageIndex?: number;
765
+ } | {
766
+ kind: "close";
767
+ code: number;
768
+ reason: string;
769
+ wasClean: boolean;
770
+ };
771
+ interface CoreRuntime {
772
+ readonly kind: "napi" | "wasm";
773
+ createRegistry(): RegistryHandle;
774
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
775
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
776
+ waitRegistryReady(registry: RegistryHandle): Promise<void>;
777
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
778
+ shutdownTelemetry?(): Promise<void>;
779
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
780
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
781
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
782
+ serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
783
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
784
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
785
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
786
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
787
+ createCancellationToken(): CancellationTokenHandle;
788
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
789
+ cancelCancellationToken(token: CancellationTokenHandle): void;
790
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
791
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
792
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
793
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
794
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
795
+ actorSetRunWakeAt(ctx: ActorContextHandle, timestampMs?: number | undefined | null): Promise<void>;
796
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
797
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
798
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
799
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
800
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
801
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
802
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
803
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
804
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
805
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
806
+ actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
807
+ actorId(ctx: ActorContextHandle): string;
593
808
  /**
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}
809
+ * Runs one actor callback with `ctx` as the current invocation: operations
810
+ * on retained handles for the same actor resolve to it, and its Core span
811
+ * is the active OpenTelemetry span for the duration of `run`. Only actions,
812
+ * raw requests, and queue dispatch run this way; other callbacks have no
813
+ * invocation span.
601
814
  */
602
- on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
815
+ runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T;
603
816
  /**
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}
817
+ * Correlation of the invocation currently executing for this actor, or
818
+ * `undefined` outside an invocation or after it finished. A sampled-out
819
+ * invocation can still expose valid span context for propagation.
611
820
  */
612
- once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
821
+ actorInvocationTraceContext(ctx: ActorContextHandle): ActorInvocationTraceContext | undefined;
613
822
  /**
614
- * Subscribes to connection errors.
615
- *
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.
823
+ * Opens the span covering one call this actor makes to another actor. See
824
+ * `StartCallSpan` for when this returns nothing.
618
825
  */
619
- onError(callback: ActorErrorCallback): () => void;
826
+ startCallSpan(ctx: ActorContextHandle, actorName: string, actionName: string): RuntimeOutboundCall | undefined;
827
+ /** Backs `ActorRun.startWorkflowSpan`. */
828
+ startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan>;
829
+ /** Backs `ActorRun.runOutsideWorkflowSpan`. */
830
+ runOutsideActorInvocationContext<T>(run: () => T): T;
831
+ /** Identity of the invocation the caller runs in, usable as a cache key. */
832
+ currentInvocationScope(): object | undefined;
833
+ actorName(ctx: ActorContextHandle): string;
834
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
835
+ actorRegion(ctx: ActorContextHandle): string;
836
+ actorSleep(ctx: ActorContextHandle): void;
837
+ actorDestroy(ctx: ActorContextHandle): void;
838
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
839
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
840
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
841
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
842
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
843
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
844
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
845
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
846
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
847
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
848
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
849
+ actorRuntimeState(ctx: ActorContextHandle): object;
850
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
851
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
852
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
853
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
854
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
855
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
856
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
857
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
858
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
859
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
860
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
861
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
862
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
863
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
864
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
865
+ actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
866
+ actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<SqliteTransactionHandle>;
867
+ actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
868
+ actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
869
+ actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
870
+ actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
871
+ actorBeginStateTransaction(ctx: ActorContextHandle, timeoutMs?: number): Promise<ActorStateTransactionHandle>;
872
+ actorStateTransactionExecute(transaction: ActorStateTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
873
+ actorStateTransactionCommit(transaction: ActorStateTransactionHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
874
+ actorStateTransactionRollback(transaction: ActorStateTransactionHandle): Promise<void>;
875
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
876
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
877
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
878
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
879
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
880
+ actorRuntimeSocketProvision(ctx: ActorContextHandle): Promise<RuntimeActorRuntimeSocketEndpointInfo>;
881
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
882
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
883
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
884
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
885
+ actorQueueCompletePersisted(ctx: ActorContextHandle, messageId: bigint, expectedName: string, response?: RuntimeBytes | undefined | null): Promise<boolean>;
886
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
887
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
888
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
889
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
890
+ actorQueueReset(ctx: ActorContextHandle): Promise<void>;
891
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
892
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
893
+ actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
894
+ actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
895
+ actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
896
+ actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
897
+ actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
898
+ actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
899
+ actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
900
+ actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
901
+ actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
902
+ connId(conn: ConnHandle): string;
903
+ connParams(conn: ConnHandle): RuntimeBytes;
904
+ connState(conn: ConnHandle): RuntimeBytes;
905
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
906
+ connIsHibernatable(conn: ConnHandle): boolean;
907
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
908
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
909
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
910
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
911
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
912
+ }
913
+
914
+ interface QueueSendWaitOptions {
915
+ wait: true;
916
+ timeout?: number;
917
+ signal?: AbortSignal;
918
+ }
919
+ interface QueueSendNoWaitOptions {
920
+ wait?: false;
921
+ timeout?: never;
922
+ signal?: AbortSignal;
923
+ }
924
+ interface QueueSendResult<TResponse = unknown> {
925
+ status: "completed" | "timedOut";
926
+ response?: TResponse;
927
+ }
928
+
929
+ /**
930
+ * Action function returned by Actor connections and handles.
931
+ *
932
+ * @typedef {Function} ActorActionFunction
933
+ * @template Args
934
+ * @template Response
935
+ * @param {...Args} args - Arguments for the action function.
936
+ * @returns {Promise<Response>}
937
+ */
938
+ type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
939
+ type IsAny<T> = 0 extends 1 & T ? true : false;
940
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
941
+ type ActorActionMap<R> = {
942
+ [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;
943
+ };
944
+ type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
945
+ actions?: infer R;
946
+ } ? R : never;
947
+ interface ActorGatewayOptions {
948
+ skipReadyWait?: boolean;
949
+ }
950
+ interface ActorActionOptions extends ActorGatewayOptions {
951
+ signal?: AbortSignal;
952
+ }
953
+ type ActorConnectOptions = ActorGatewayOptions;
954
+ type ActorFetchInit = RequestInit & ActorGatewayOptions;
955
+ type ActorWebSocketOptions = ActorGatewayOptions;
956
+ /**
957
+ * Maps action methods from actor definition to typed function signatures.
958
+ */
959
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
960
+ type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
961
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
962
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
963
+ (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
964
+ (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
965
+ };
966
+ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
967
+ <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
968
+ (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
969
+ };
970
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
971
+ send: ActorQueueSend<Record<string, any>>;
972
+ } : AD extends {
973
+ config: {
974
+ queues?: infer Q;
975
+ };
976
+ } ? Q extends QueueSchemaConfig ? {
977
+ send: ActorQueueSend<Q>;
978
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
979
+ send: ActorQueueSend<Q>;
980
+ } : {} : {};
981
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
982
+ on: LooseEventSubscribe;
983
+ once: LooseEventSubscribe;
984
+ } : AD extends {
985
+ config: {
986
+ events?: infer E;
987
+ };
988
+ } ? E extends EventSchemaConfig ? {
989
+ on: ActorEventSubscribe<E>;
990
+ once: ActorEventSubscribe<E>;
991
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
992
+ on: ActorEventSubscribe<E>;
993
+ once: ActorEventSubscribe<E>;
994
+ } : {} : {};
995
+
996
+ declare class ActorClientError extends Error {
997
+ }
998
+ declare class ManagerError extends ActorClientError {
999
+ constructor(error: string, opts?: ErrorOptions);
1000
+ }
1001
+ declare class MalformedResponseMessage extends ActorClientError {
1002
+ constructor(cause?: unknown);
1003
+ }
1004
+
1005
+ declare class ActorConnDisposed extends ActorClientError {
1006
+ constructor();
1007
+ }
1008
+
1009
+ type ActorResolutionState = ActorQuery;
1010
+
1011
+ /**
1012
+ * Connection status for an actor connection.
1013
+ *
1014
+ * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
1015
+ * - `"connecting"`: Attempting to establish connection
1016
+ * - `"connected"`: Connection is active
1017
+ * - `"disconnected"`: Connection was lost, will auto-reconnect
1018
+ */
1019
+ type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
1020
+ /**
1021
+ * A function that unsubscribes from an event.
1022
+ *
1023
+ * @typedef {Function} EventUnsubscribe
1024
+ */
1025
+ type EventUnsubscribe = () => void;
1026
+ /**
1027
+ * A function that handles connection errors.
1028
+ *
1029
+ * @typedef {Function} ActorErrorCallback
1030
+ */
1031
+ type ActorErrorCallback = (error: RivetError) => void;
1032
+ /**
1033
+ * A callback for connection state changes.
1034
+ *
1035
+ * @typedef {Function} ConnectionStateCallback
1036
+ */
1037
+ type ConnectionStateCallback = () => void;
1038
+ /**
1039
+ * A callback for connection status changes.
1040
+ *
1041
+ * @typedef {Function} StatusChangeCallback
1042
+ */
1043
+ type StatusChangeCallback = (status: ActorConnStatus) => void;
1044
+ declare const CONNECT_SYMBOL: unique symbol;
1045
+ /**
1046
+ * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
1047
+ *
1048
+ * @see {@link ActorConn}
1049
+ */
1050
+ declare class ActorConnRaw {
1051
+ #private;
620
1052
  /**
621
- * Returns the current connection status.
1053
+ * Do not call this directly.
622
1054
  *
623
- * @returns {ActorConnStatus} - The current connection status.
1055
+ * Creates an instance of ActorConnRaw.
1056
+ *
1057
+ * @protected
624
1058
  */
625
- get connStatus(): ActorConnStatus;
1059
+ constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, currentActorInvocation?: CurrentActorInvocation);
1060
+ send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1061
+ send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
626
1062
  /**
627
- * Returns whether the connection is currently open.
1063
+ * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
628
1064
  *
629
- * @deprecated Use `connStatus` instead.
630
- * @returns {boolean} - True if the connection is open, false otherwise.
1065
+ * @see {@link ActorConn}
1066
+ * @template Args - The type of arguments to pass to the action function.
1067
+ * @template Response - The type of the response returned by the action function.
1068
+ * @param {string} name - The name of the action function to call.
1069
+ * @param {...Args} args - The arguments to pass to the action function.
1070
+ * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
631
1071
  */
632
- get isConnected(): boolean;
1072
+ action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
1073
+ name: string;
1074
+ args: Args;
1075
+ signal?: AbortSignal;
1076
+ }): Promise<Response>;
633
1077
  /**
634
- * Resolves when this connection first reaches the connected state.
1078
+ * Do not call this directly.
1079
+ * Establishes a connection to the server using the specified endpoint & encoding & driver.
1080
+ *
1081
+ * @protected
635
1082
  */
636
- get ready(): Promise<void>;
1083
+ [CONNECT_SYMBOL](): void;
637
1084
  /**
638
- * Subscribes to connection open events.
639
- *
640
- * This is called when the WebSocket connection is established and the Init message is received.
1085
+ * Subscribes to an event that will happen repeatedly.
641
1086
  *
642
- * @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
1087
+ * @template Args - The type of arguments the event callback will receive.
1088
+ * @param {string} eventName - The name of the event to subscribe to.
1089
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1090
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1091
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1092
+ */
1093
+ on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1094
+ /**
1095
+ * Subscribes to an event that will be triggered only once.
1096
+ *
1097
+ * @template Args - The type of arguments the event callback will receive.
1098
+ * @param {string} eventName - The name of the event to subscribe to.
1099
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1100
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1101
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1102
+ */
1103
+ once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1104
+ /**
1105
+ * Subscribes to connection errors.
1106
+ *
1107
+ * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
1108
+ * @returns {() => void} - A function to unsubscribe from the error handler.
1109
+ */
1110
+ onError(callback: ActorErrorCallback): () => void;
1111
+ /**
1112
+ * Returns the current connection status.
1113
+ *
1114
+ * @returns {ActorConnStatus} - The current connection status.
1115
+ */
1116
+ get connStatus(): ActorConnStatus;
1117
+ /**
1118
+ * Returns whether the connection is currently open.
1119
+ *
1120
+ * @deprecated Use `connStatus` instead.
1121
+ * @returns {boolean} - True if the connection is open, false otherwise.
1122
+ */
1123
+ get isConnected(): boolean;
1124
+ /**
1125
+ * Resolves when this connection first reaches the connected state.
1126
+ */
1127
+ get ready(): Promise<void>;
1128
+ /**
1129
+ * Subscribes to connection open events.
1130
+ *
1131
+ * This is called when the WebSocket connection is established and the Init message is received.
1132
+ *
1133
+ * @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
643
1134
  * @returns {() => void} - A function to unsubscribe from the open handler.
644
1135
  */
645
1136
  onOpen(callback: ConnectionStateCallback): () => void;
@@ -701,7 +1192,7 @@ declare class ActorHandleRaw {
701
1192
  *
702
1193
  * @protected
703
1194
  */
704
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, signal?: AbortSignal);
1195
+ constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, signal?: AbortSignal, currentActorInvocation?: CurrentActorInvocation, startCallSpan?: StartCallSpan);
705
1196
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
706
1197
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
707
1198
  /**
@@ -951,6 +1442,18 @@ interface Region {
951
1442
  }
952
1443
  declare const ACTOR_CONNS_SYMBOL: unique symbol;
953
1444
  declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
1445
+ /** Options for constructing a raw actor client. */
1446
+ interface ClientRawOptions {
1447
+ encoding?: Encoding;
1448
+ gateway?: ActorGatewayOptions;
1449
+ }
1450
+ /** Runtime-supplied wiring for clients created inside an actor. Set only by the native runtime. */
1451
+ interface ActorClientRuntimeOptions {
1452
+ /** Supplies the calling actor's invocation so actor-to-actor clients propagate its trace and ray ID. */
1453
+ currentActorInvocation?: CurrentActorInvocation;
1454
+ /** Opens and finishes the Core span covering an actor-to-actor call. */
1455
+ startCallSpan?: StartCallSpan;
1456
+ }
954
1457
  /**
955
1458
  * Client for managing & connecting to actors.
956
1459
  *
@@ -963,7 +1466,7 @@ declare class ClientRaw {
963
1466
  /**
964
1467
  * Creates an instance of Client.
965
1468
  */
966
- constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
1469
+ constructor(driver: EngineControlClient, options?: ClientRawOptions & ActorClientRuntimeOptions);
967
1470
  /**
968
1471
  * Gets a stateless handle to a actor by its ID.
969
1472
  *
@@ -1270,6 +1773,28 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1270
1773
  client<T = any>(): ActorClientFor<T>;
1271
1774
  [key: string]: any;
1272
1775
  }
1776
+ /** @experimental How one run of a workflow function ended. */
1777
+ type WorkflowOutcome = "completed" | "sleeping" | "evicted" | "failed" | "cancelled";
1778
+ /** @experimental How one workflow step attempt ended. `retry` will be tried again, `failed` will not. */
1779
+ type WorkflowStepOutcome = "ok" | "retry" | "failed";
1780
+ /** @experimental One open run of a workflow function, traced as its own invocation. */
1781
+ interface WorkflowSpan {
1782
+ /** Runs `body` attributed to this run. */
1783
+ run<T>(body: () => Promise<T>): Promise<T>;
1784
+ /**
1785
+ * Called by a workflow engine before each attempt at a step. Returns
1786
+ * nothing when tracing is off.
1787
+ */
1788
+ startStep(name: string, attempt: number): WorkflowStepSpan | undefined;
1789
+ finish(outcome: WorkflowOutcome): Promise<void>;
1790
+ }
1791
+ /** @experimental One open attempt at one workflow step. */
1792
+ interface WorkflowStepSpan {
1793
+ /** Runs `body` attributed to this attempt. */
1794
+ run<T>(body: () => Promise<T>): Promise<T>;
1795
+ /** `error` is what the step callback threw. */
1796
+ finish(outcome: WorkflowStepOutcome, error?: unknown): void;
1797
+ }
1273
1798
  /** @experimental */
1274
1799
  interface ActorRun {
1275
1800
  /**
@@ -1277,6 +1802,13 @@ interface ActorRun {
1277
1802
  * ensures this actor's run handler is active, starting it if inactive.
1278
1803
  */
1279
1804
  setWakeAt(timestamp: number | null): Promise<void>;
1805
+ /** @experimental Called by a workflow engine each time it runs the workflow function. */
1806
+ startWorkflowSpan(): Promise<WorkflowSpan>;
1807
+ /**
1808
+ * @experimental Runs `body` outside the current workflow run, so a workflow
1809
+ * engine's own history storage stays out of the trace.
1810
+ */
1811
+ runOutsideWorkflowSpan<T>(body: () => T): T;
1280
1812
  }
1281
1813
  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
1814
  conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
@@ -1389,8 +1921,8 @@ declare const ActorConfigSchema: z.ZodObject<{
1389
1921
  state: "state";
1390
1922
  database: "database";
1391
1923
  console: "console";
1392
- workflow: "workflow";
1393
1924
  queue: "queue";
1925
+ workflow: "workflow";
1394
1926
  schedules: "schedules";
1395
1927
  connections: "connections";
1396
1928
  }>;
@@ -1840,431 +2372,6 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1840
2372
  use: A;
1841
2373
  };
1842
2374
 
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
2375
  declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
2269
2376
  runtime: CoreRuntime;
2270
2377
  registry: RegistryHandle;