rivetkit 2.3.4 → 2.3.5-rc.1

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 (161) hide show
  1. package/dist/browser/client.d.ts +157 -9
  2. package/dist/browser/client.js +518 -542
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +101 -2
  5. package/dist/browser/inspector/client.js +1245 -227
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/agent-os/index.cjs +103 -36
  8. package/dist/tsup/agent-os/index.cjs.map +1 -1
  9. package/dist/tsup/agent-os/index.d.cts +159 -11
  10. package/dist/tsup/agent-os/index.d.ts +159 -11
  11. package/dist/tsup/agent-os/index.js +103 -36
  12. package/dist/tsup/agent-os/index.js.map +1 -1
  13. package/dist/tsup/{chunk-7X4M7ZRA.cjs → chunk-4XKED5P5.cjs} +146 -177
  14. package/dist/tsup/chunk-4XKED5P5.cjs.map +1 -0
  15. package/dist/tsup/{chunk-Q7NBMTF3.cjs → chunk-6HQCLWAW.cjs} +384 -4
  16. package/dist/tsup/chunk-6HQCLWAW.cjs.map +1 -0
  17. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-7AFZMFPQ.js} +15 -1
  18. package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
  19. package/dist/tsup/{chunk-M7DCRMOZ.js → chunk-B4IZU537.js} +382 -2
  20. package/dist/tsup/chunk-B4IZU537.js.map +1 -0
  21. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-G3CCRCTK.cjs} +14 -9
  22. package/dist/tsup/chunk-G3CCRCTK.cjs.map +1 -0
  23. package/dist/tsup/{chunk-CMPFZ724.js → chunk-GAV4PKFT.js} +16 -47
  24. package/dist/tsup/{chunk-CMPFZ724.js.map → chunk-GAV4PKFT.js.map} +1 -1
  25. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-JI6GZ2C2.js} +2 -11
  26. package/dist/tsup/{chunk-HXUEHHJF.js.map → chunk-JI6GZ2C2.js.map} +1 -1
  27. package/dist/tsup/{chunk-3SNFA373.cjs → chunk-M3FCXL3Q.cjs} +3 -3
  28. package/dist/tsup/{chunk-3SNFA373.cjs.map → chunk-M3FCXL3Q.cjs.map} +1 -1
  29. package/dist/tsup/{chunk-GXW3VFJQ.js → chunk-MGTSVSUC.js} +2 -2
  30. package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-MYWZCDML.cjs} +2 -11
  31. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  32. package/dist/tsup/{chunk-M5TAM4JV.js → chunk-NIC3QLKL.js} +3 -3
  33. package/dist/tsup/{chunk-H4XOUVGP.js → chunk-P4OGQ4JL.js} +5 -7
  34. package/dist/tsup/{chunk-H4XOUVGP.js.map → chunk-P4OGQ4JL.js.map} +1 -1
  35. package/dist/tsup/{chunk-EOSGY3DC.js → chunk-PAG6G46L.js} +2 -2
  36. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-SHBE77IT.js} +14 -9
  37. package/dist/tsup/chunk-SHBE77IT.js.map +1 -0
  38. package/dist/tsup/{chunk-SRT2DPN3.cjs → chunk-TNIWIUNV.cjs} +9 -11
  39. package/dist/tsup/chunk-TNIWIUNV.cjs.map +1 -0
  40. package/dist/tsup/{chunk-UPOCJPEQ.cjs → chunk-TR5NLR5V.cjs} +4 -4
  41. package/dist/tsup/{chunk-UPOCJPEQ.cjs.map → chunk-TR5NLR5V.cjs.map} +1 -1
  42. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-UEULFXUI.cjs} +16 -2
  43. package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
  44. package/dist/tsup/{chunk-T4MURX4P.cjs → chunk-UJ2FQY63.cjs} +7 -7
  45. package/dist/tsup/{chunk-T4MURX4P.cjs.map → chunk-UJ2FQY63.cjs.map} +1 -1
  46. package/dist/tsup/client/mod.cjs +7 -8
  47. package/dist/tsup/client/mod.cjs.map +1 -1
  48. package/dist/tsup/client/mod.d.cts +5 -4
  49. package/dist/tsup/client/mod.d.ts +5 -4
  50. package/dist/tsup/client/mod.js +6 -7
  51. package/dist/tsup/common/log.cjs +2 -2
  52. package/dist/tsup/common/log.js +1 -1
  53. package/dist/tsup/common/websocket.cjs +3 -3
  54. package/dist/tsup/common/websocket.js +2 -2
  55. package/dist/tsup/{config-D49x8NpL.d.cts → config-BxOimoGX.d.cts} +16 -0
  56. package/dist/tsup/{config-D49x8NpL.d.ts → config-BxOimoGX.d.ts} +16 -0
  57. package/dist/tsup/{config-ZkIsRFsN.d.ts → config-BzdqbLAP.d.ts} +164 -27
  58. package/dist/tsup/{config-BfBhjEbk.d.cts → config-CPPEwn_e.d.cts} +164 -27
  59. package/dist/tsup/{context-sZ9GlaBK.d.cts → context-DSA9gFXB.d.cts} +2 -2
  60. package/dist/tsup/{context-B7-84u9K.d.ts → context-wWv-K2K_.d.ts} +2 -2
  61. package/dist/tsup/db/drizzle.cjs +120 -68
  62. package/dist/tsup/db/drizzle.cjs.map +1 -1
  63. package/dist/tsup/db/drizzle.d.cts +8 -3
  64. package/dist/tsup/db/drizzle.d.ts +8 -3
  65. package/dist/tsup/db/drizzle.js +120 -68
  66. package/dist/tsup/db/drizzle.js.map +1 -1
  67. package/dist/tsup/db/mod.cjs +74 -22
  68. package/dist/tsup/db/mod.cjs.map +1 -1
  69. package/dist/tsup/db/mod.d.cts +4 -3
  70. package/dist/tsup/db/mod.d.ts +4 -3
  71. package/dist/tsup/db/mod.js +74 -22
  72. package/dist/tsup/db/mod.js.map +1 -1
  73. package/dist/tsup/dynamic/mod.cjs +2 -2
  74. package/dist/tsup/dynamic/mod.d.cts +3 -3
  75. package/dist/tsup/dynamic/mod.d.ts +3 -3
  76. package/dist/tsup/dynamic/mod.js +1 -1
  77. package/dist/tsup/inspector/mod.cjs +4 -5
  78. package/dist/tsup/inspector/mod.cjs.map +1 -1
  79. package/dist/tsup/inspector/mod.js +3 -4
  80. package/dist/tsup/inspector/mod.js.map +1 -1
  81. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  82. package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
  83. package/dist/tsup/inspector-tab/mod.d.cts +5 -5
  84. package/dist/tsup/inspector-tab/mod.d.ts +5 -5
  85. package/dist/tsup/inspector-tab/mod.js +1 -1
  86. package/dist/tsup/inspector-tab/mod.js.map +1 -1
  87. package/dist/tsup/mod.cjs +605 -158
  88. package/dist/tsup/mod.cjs.map +1 -1
  89. package/dist/tsup/mod.d.cts +5 -5
  90. package/dist/tsup/mod.d.ts +5 -5
  91. package/dist/tsup/mod.js +528 -81
  92. package/dist/tsup/mod.js.map +1 -1
  93. package/dist/tsup/test/mod.cjs +10 -11
  94. package/dist/tsup/test/mod.cjs.map +1 -1
  95. package/dist/tsup/test/mod.d.cts +3 -3
  96. package/dist/tsup/test/mod.d.ts +3 -3
  97. package/dist/tsup/test/mod.js +6 -7
  98. package/dist/tsup/test/mod.js.map +1 -1
  99. package/dist/tsup/utils-CV0akuDD.d.ts +162 -0
  100. package/dist/tsup/utils-DQDCphrl.d.cts +162 -0
  101. package/dist/tsup/utils.cjs +6 -2
  102. package/dist/tsup/utils.cjs.map +1 -1
  103. package/dist/tsup/utils.d.cts +3 -146
  104. package/dist/tsup/utils.d.ts +3 -146
  105. package/dist/tsup/utils.js +5 -1
  106. package/dist/tsup/workflow/mod.cjs +198 -151
  107. package/dist/tsup/workflow/mod.cjs.map +1 -1
  108. package/dist/tsup/workflow/mod.d.cts +5 -5
  109. package/dist/tsup/workflow/mod.d.ts +5 -5
  110. package/dist/tsup/workflow/mod.js +187 -140
  111. package/dist/tsup/workflow/mod.js.map +1 -1
  112. package/package.json +8 -8
  113. package/src/actor/config.test.ts +14 -0
  114. package/src/actor/config.ts +104 -16
  115. package/src/actor/definition.ts +18 -7
  116. package/src/agent-os/actor/index.ts +2 -2
  117. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  118. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  119. package/src/common/database/config.ts +24 -0
  120. package/src/common/database/mod.test.ts +148 -59
  121. package/src/common/database/mod.ts +93 -23
  122. package/src/common/database/native-database.test.ts +9 -0
  123. package/src/common/database/native-database.ts +151 -0
  124. package/src/common/database/shared.ts +15 -0
  125. package/src/common/encoding.ts +28 -21
  126. package/src/db/drizzle.test.ts +157 -0
  127. package/src/db/drizzle.ts +170 -79
  128. package/src/dynamic/isolate-runtime.ts +0 -2
  129. package/src/engine-client/driver.ts +0 -15
  130. package/src/engine-client/mod.ts +0 -41
  131. package/src/inspector/client.browser.ts +69 -8
  132. package/src/inspector-tab/mod.ts +1 -0
  133. package/src/registry/config/index.ts +1 -35
  134. package/src/registry/napi-runtime.ts +204 -16
  135. package/src/registry/native.ts +200 -30
  136. package/src/registry/runtime.ts +146 -3
  137. package/src/registry/wasm-runtime.ts +217 -6
  138. package/src/utils.ts +3 -0
  139. package/src/workflow/context.ts +5 -27
  140. package/src/workflow/driver.test.ts +62 -0
  141. package/src/workflow/driver.ts +231 -113
  142. package/src/workflow/mod.ts +3 -3
  143. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  144. package/dist/tsup/chunk-7X4M7ZRA.cjs.map +0 -1
  145. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  146. package/dist/tsup/chunk-M7DCRMOZ.js.map +0 -1
  147. package/dist/tsup/chunk-Q7NBMTF3.cjs.map +0 -1
  148. package/dist/tsup/chunk-SRT2DPN3.cjs.map +0 -1
  149. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  150. package/dist/tsup/chunk-W6WPKZ6I.js +0 -382
  151. package/dist/tsup/chunk-W6WPKZ6I.js.map +0 -1
  152. package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
  153. package/dist/tsup/chunk-Z7PSQWMC.cjs +0 -382
  154. package/dist/tsup/chunk-Z7PSQWMC.cjs.map +0 -1
  155. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
  156. package/src/actor/driver.ts +0 -141
  157. package/src/actor/instance/mod.ts +0 -2484
  158. package/src/drivers/engine/actor-driver.ts +0 -2473
  159. /package/dist/tsup/{chunk-GXW3VFJQ.js.map → chunk-MGTSVSUC.js.map} +0 -0
  160. /package/dist/tsup/{chunk-M5TAM4JV.js.map → chunk-NIC3QLKL.js.map} +0 -0
  161. /package/dist/tsup/{chunk-EOSGY3DC.js.map → chunk-PAG6G46L.js.map} +0 -0
@@ -15,6 +15,8 @@ import type {
15
15
  RegistryHandle,
16
16
  RuntimeActorConfig,
17
17
  RuntimeBytes,
18
+ RuntimeCronFire,
19
+ RuntimeCronJobInfo,
18
20
  RuntimeHttpRequest,
19
21
  RuntimeKvEntry,
20
22
  RuntimeKvListOptions,
@@ -27,9 +29,11 @@ import type {
27
29
  RuntimeRegistryRouteResponse,
28
30
  RuntimeRequestSaveOpts,
29
31
  RuntimeServeConfig,
32
+ RuntimeScheduledEventInfo,
30
33
  RuntimeServerlessRequest,
31
34
  RuntimeServerlessResponseHead,
32
35
  RuntimeServerlessStreamCallback,
36
+ RuntimeSqlBatchStatement,
33
37
  RuntimeSqlBindParam,
34
38
  RuntimeSqlBindParams,
35
39
  RuntimeSqlExecResult,
@@ -38,6 +42,8 @@ import type {
38
42
  RuntimeSqlRunResult,
39
43
  RuntimeStateDeltaPayload,
40
44
  RuntimeWebSocketEvent,
45
+ RuntimeWorkflowKvWrite,
46
+ SqliteTransactionHandle,
41
47
  WebSocketHandle,
42
48
  } from "./runtime";
43
49
  import { normalizeRuntimeSqlExecuteResult } from "./runtime";
@@ -45,6 +51,12 @@ import { normalizeRuntimeSqlExecuteResult } from "./runtime";
45
51
  type NativeBindings = typeof import("@rivetkit/rivetkit-napi");
46
52
  type NapiSqlDatabase = ReturnType<NativeActorContext["sql"]>;
47
53
  type NapiSqlBindParams = Parameters<NapiSqlDatabase["execute"]>[1];
54
+ type NapiSqlBatchStatement = Parameters<
55
+ NapiSqlDatabase["executeBatch"]
56
+ >[0][number];
57
+ type NapiSqlTransaction = Awaited<
58
+ ReturnType<NapiSqlDatabase["beginTransaction"]>
59
+ >;
48
60
 
49
61
  function asNativeRegistry(handle: RegistryHandle): NativeCoreRegistry {
50
62
  return handle as unknown as NativeCoreRegistry;
@@ -66,6 +78,12 @@ function asNativeWebSocket(handle: WebSocketHandle): NativeWebSocket {
66
78
  return handle as unknown as NativeWebSocket;
67
79
  }
68
80
 
81
+ function asNativeSqlTransaction(
82
+ handle: SqliteTransactionHandle,
83
+ ): NapiSqlTransaction {
84
+ return handle as unknown as NapiSqlTransaction;
85
+ }
86
+
69
87
  function asNativeCancellationToken(
70
88
  handle: CancellationTokenHandle,
71
89
  ): NativeCancellationToken {
@@ -104,6 +122,15 @@ function toNapiSqlBindParams(params?: RuntimeSqlBindParams): NapiSqlBindParams {
104
122
  return params.map((param) => toNapiSqlBindParam(param));
105
123
  }
106
124
 
125
+ function toNapiSqlBatchStatement(
126
+ statement: RuntimeSqlBatchStatement,
127
+ ): NapiSqlBatchStatement {
128
+ return {
129
+ sql: statement.sql,
130
+ params: toNapiSqlBindParams(statement.params) ?? undefined,
131
+ };
132
+ }
133
+
107
134
  function toNapiBuffer(value: RuntimeBytes): Buffer {
108
135
  return Buffer.from(value);
109
136
  }
@@ -288,16 +315,24 @@ export class NapiCoreRuntime implements CoreRuntime {
288
315
  return new this.#bindings.CancellationToken() as unknown as CancellationTokenHandle;
289
316
  }
290
317
 
291
- createTestActorContext(
292
- actorId: string,
293
- name: string,
294
- region: string,
295
- ): ActorContextHandle {
296
- return new this.#bindings.ActorContext(
297
- actorId,
298
- name,
299
- region,
300
- ) as unknown as ActorContextHandle;
318
+ decodeInspectorRequest(
319
+ bytes: RuntimeBytes,
320
+ advertisedVersion: number,
321
+ ): RuntimeBytes {
322
+ return this.#bindings.decodeInspectorRequest(
323
+ toNapiBuffer(bytes),
324
+ advertisedVersion,
325
+ );
326
+ }
327
+
328
+ encodeInspectorResponse(
329
+ bytes: RuntimeBytes,
330
+ targetVersion: number,
331
+ ): RuntimeBytes {
332
+ return this.#bindings.encodeInspectorResponse(
333
+ toNapiBuffer(bytes),
334
+ targetVersion,
335
+ );
301
336
  }
302
337
 
303
338
  cancellationTokenAborted(token: CancellationTokenHandle): boolean {
@@ -407,6 +442,18 @@ export class NapiCoreRuntime implements CoreRuntime {
407
442
  );
408
443
  }
409
444
 
445
+ async actorSaveStateAndWorkflowBatch(
446
+ ctx: ActorContextHandle,
447
+ writes: RuntimeWorkflowKvWrite[],
448
+ ): Promise<void> {
449
+ await asNativeActorContext(ctx).saveStateAndWorkflowBatch(
450
+ writes.map((write) => ({
451
+ key: toNapiBuffer(write.key),
452
+ value: toNapiBuffer(write.value),
453
+ })),
454
+ );
455
+ }
456
+
410
457
  actorId(ctx: ActorContextHandle): string {
411
458
  return asNativeActorContext(ctx).actorId();
412
459
  }
@@ -614,6 +661,56 @@ export class NapiCoreRuntime implements CoreRuntime {
614
661
  return normalizeRuntimeSqlExecuteResult(result);
615
662
  }
616
663
 
664
+ async actorSqlExecuteBatch(
665
+ ctx: ActorContextHandle,
666
+ statements: RuntimeSqlBatchStatement[],
667
+ ): Promise<RuntimeSqlExecuteResult[]> {
668
+ const results = await this.#actorSql(ctx).executeBatch(
669
+ statements.map(toNapiSqlBatchStatement),
670
+ );
671
+ return results.map(normalizeRuntimeSqlExecuteResult);
672
+ }
673
+
674
+ async actorSqlBeginTransaction(
675
+ ctx: ActorContextHandle,
676
+ timeoutMs?: number,
677
+ ): Promise<SqliteTransactionHandle> {
678
+ return (await this.#actorSql(ctx).beginTransaction(
679
+ timeoutMs,
680
+ )) as unknown as SqliteTransactionHandle;
681
+ }
682
+
683
+ async actorSqlTransactionExec(
684
+ transaction: SqliteTransactionHandle,
685
+ sql: string,
686
+ ): Promise<RuntimeSqlExecResult> {
687
+ return await asNativeSqlTransaction(transaction).exec(sql);
688
+ }
689
+
690
+ async actorSqlTransactionExecute(
691
+ transaction: SqliteTransactionHandle,
692
+ sql: string,
693
+ params?: RuntimeSqlBindParams,
694
+ ): Promise<RuntimeSqlExecuteResult> {
695
+ const result = await asNativeSqlTransaction(transaction).execute(
696
+ sql,
697
+ toNapiSqlBindParams(params),
698
+ );
699
+ return normalizeRuntimeSqlExecuteResult(result);
700
+ }
701
+
702
+ async actorSqlTransactionCommit(
703
+ transaction: SqliteTransactionHandle,
704
+ ): Promise<void> {
705
+ await asNativeSqlTransaction(transaction).commit();
706
+ }
707
+
708
+ async actorSqlTransactionRollback(
709
+ transaction: SqliteTransactionHandle,
710
+ ): Promise<void> {
711
+ await asNativeSqlTransaction(transaction).rollback();
712
+ }
713
+
617
714
  async actorSqlQuery(
618
715
  ctx: ActorContextHandle,
619
716
  sql: string,
@@ -652,6 +749,10 @@ export class NapiCoreRuntime implements CoreRuntime {
652
749
  await database.close();
653
750
  }
654
751
 
752
+ async actorRuntimeSocketProvision(ctx: ActorContextHandle) {
753
+ return await asNativeActorContext(ctx).provisionActorRuntimeSocket();
754
+ }
755
+
655
756
  async actorQueueSend(
656
757
  ctx: ActorContextHandle,
657
758
  name: string,
@@ -749,28 +850,115 @@ export class NapiCoreRuntime implements CoreRuntime {
749
850
  await asNativeActorContext(ctx).queue().reset();
750
851
  }
751
852
 
752
- actorScheduleAfter(
853
+ async actorScheduleAfter(
753
854
  ctx: ActorContextHandle,
754
855
  durationMs: number,
755
856
  actionName: string,
756
857
  args: RuntimeBytes,
757
- ): void {
758
- asNativeActorContext(ctx)
858
+ ): Promise<string> {
859
+ return await asNativeActorContext(ctx)
759
860
  .schedule()
760
861
  .after(durationMs, actionName, toNapiBuffer(args));
761
862
  }
762
863
 
763
- actorScheduleAt(
864
+ async actorScheduleAt(
764
865
  ctx: ActorContextHandle,
765
866
  timestampMs: number,
766
867
  actionName: string,
767
868
  args: RuntimeBytes,
768
- ): void {
769
- asNativeActorContext(ctx)
869
+ ): Promise<string> {
870
+ return await asNativeActorContext(ctx)
770
871
  .schedule()
771
872
  .at(timestampMs, actionName, toNapiBuffer(args));
772
873
  }
773
874
 
875
+ async actorScheduleCancel(ctx: ActorContextHandle, id: string) {
876
+ return await asNativeActorContext(ctx).schedule().cancel(id);
877
+ }
878
+
879
+ async actorScheduleGet(
880
+ ctx: ActorContextHandle,
881
+ id: string,
882
+ ): Promise<RuntimeScheduledEventInfo | undefined> {
883
+ return (
884
+ (await asNativeActorContext(ctx).schedule().get(id)) ?? undefined
885
+ );
886
+ }
887
+
888
+ async actorScheduleList(ctx: ActorContextHandle) {
889
+ return await asNativeActorContext(ctx).schedule().list();
890
+ }
891
+
892
+ async actorCronSet(
893
+ ctx: ActorContextHandle,
894
+ name: string,
895
+ expression: string,
896
+ timezone: string | undefined,
897
+ actionName: string,
898
+ args: RuntimeBytes,
899
+ maxHistory: number | undefined,
900
+ ) {
901
+ await asNativeActorContext(ctx)
902
+ .schedule()
903
+ .cronSet(
904
+ name,
905
+ expression,
906
+ timezone,
907
+ actionName,
908
+ toNapiBuffer(args),
909
+ maxHistory,
910
+ );
911
+ }
912
+
913
+ async actorCronEvery(
914
+ ctx: ActorContextHandle,
915
+ name: string,
916
+ intervalMs: number,
917
+ actionName: string,
918
+ args: RuntimeBytes,
919
+ maxHistory: number | undefined,
920
+ ) {
921
+ await asNativeActorContext(ctx)
922
+ .schedule()
923
+ .cronEvery(
924
+ name,
925
+ intervalMs,
926
+ actionName,
927
+ toNapiBuffer(args),
928
+ maxHistory,
929
+ );
930
+ }
931
+
932
+ async actorCronGet(
933
+ ctx: ActorContextHandle,
934
+ name: string,
935
+ ): Promise<RuntimeCronJobInfo | undefined> {
936
+ return ((await asNativeActorContext(ctx).schedule().cronGet(name)) ??
937
+ undefined) as RuntimeCronJobInfo | undefined;
938
+ }
939
+
940
+ async actorCronList(
941
+ ctx: ActorContextHandle,
942
+ ): Promise<RuntimeCronJobInfo[]> {
943
+ return (await asNativeActorContext(ctx)
944
+ .schedule()
945
+ .cronList()) as RuntimeCronJobInfo[];
946
+ }
947
+
948
+ async actorCronDelete(ctx: ActorContextHandle, name: string) {
949
+ return await asNativeActorContext(ctx).schedule().cronDelete(name);
950
+ }
951
+
952
+ async actorCronHistory(
953
+ ctx: ActorContextHandle,
954
+ name: string,
955
+ limit: number | undefined,
956
+ ): Promise<RuntimeCronFire[]> {
957
+ return (await asNativeActorContext(ctx)
958
+ .schedule()
959
+ .cronHistory(name, limit)) as RuntimeCronFire[];
960
+ }
961
+
774
962
  connId(conn: ConnHandle): string {
775
963
  return asNativeConn(conn).id();
776
964
  }
@@ -6,6 +6,13 @@ import {
6
6
  getRunFunction,
7
7
  getRunInspectorConfig,
8
8
  RAW_STATE_SYMBOL,
9
+ type ActorCron,
10
+ type ActorCronEveryOptions,
11
+ type ActorCronSetOptions,
12
+ type ActorSchedule,
13
+ type CronFire,
14
+ type CronJobInfo,
15
+ type ScheduledEventInfo,
9
16
  type WorkflowInspectorConfig,
10
17
  } from "@/actor/config";
11
18
  import type { AnyActorDefinition } from "@/actor/definition";
@@ -79,7 +86,11 @@ import type {
79
86
  RuntimeBytes,
80
87
  RuntimeHttpResponse,
81
88
  RuntimeInspectorTabEntry,
89
+ RuntimeCronFire,
90
+ RuntimeCronJobInfo,
82
91
  RuntimeQueueMessage,
92
+ RuntimeScheduledEventInfo,
93
+ RuntimeScheduledFireInfo,
83
94
  RuntimeServeConfig,
84
95
  RuntimeStateDeltaPayload,
85
96
  WebSocketHandle,
@@ -512,6 +523,27 @@ function getOrCreateNativeSqlDatabase(
512
523
  const database = wrapJsNativeDatabase({
513
524
  exec: (sql) => runtime.actorSqlExec(ctx, sql),
514
525
  execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
526
+ executeBatch: (statements) =>
527
+ runtime.actorSqlExecuteBatch(ctx, statements),
528
+ beginTransaction: async (timeoutMs) => {
529
+ const transaction = await runtime.actorSqlBeginTransaction(
530
+ ctx,
531
+ timeoutMs,
532
+ );
533
+ return {
534
+ exec: (sql) =>
535
+ runtime.actorSqlTransactionExec(transaction, sql),
536
+ execute: (sql, params) =>
537
+ runtime.actorSqlTransactionExecute(
538
+ transaction,
539
+ sql,
540
+ params,
541
+ ),
542
+ commit: () => runtime.actorSqlTransactionCommit(transaction),
543
+ rollback: () =>
544
+ runtime.actorSqlTransactionRollback(transaction),
545
+ };
546
+ },
515
547
  query: (sql, params) => runtime.actorSqlQuery(ctx, sql, params),
516
548
  run: (sql, params) => runtime.actorSqlRun(ctx, sql, params),
517
549
  metrics: () => runtime.actorSqlMetrics(ctx),
@@ -732,13 +764,6 @@ function callNativeSync<T>(invoke: () => T): T {
732
764
  }
733
765
  }
734
766
 
735
- function actorAbortedError(): Error & { group: string; code: string } {
736
- return Object.assign(new Error("Actor aborted"), {
737
- group: "actor",
738
- code: "aborted",
739
- });
740
- }
741
-
742
767
  type NativeWorkflowInspectorConfig = WorkflowInspectorConfig<ArrayBuffer> & {
743
768
  getState?: () => Promise<unknown> | unknown;
744
769
  };
@@ -1319,7 +1344,7 @@ class NativeConnAdapter {
1319
1344
  }
1320
1345
  }
1321
1346
 
1322
- class NativeScheduleAdapter {
1347
+ class NativeScheduleAdapter implements ActorSchedule {
1323
1348
  #runtime: CoreRuntime;
1324
1349
  #ctx: ActorContextHandle;
1325
1350
 
@@ -1332,14 +1357,12 @@ class NativeScheduleAdapter {
1332
1357
  duration: number,
1333
1358
  action: string,
1334
1359
  ...args: unknown[]
1335
- ): Promise<void> {
1336
- callNativeSync(() =>
1337
- this.#runtime.actorScheduleAfter(
1338
- this.#ctx,
1339
- duration,
1340
- action,
1341
- encodeValue(args),
1342
- ),
1360
+ ): Promise<string> {
1361
+ return await this.#runtime.actorScheduleAfter(
1362
+ this.#ctx,
1363
+ duration,
1364
+ action,
1365
+ encodeValue(args),
1343
1366
  );
1344
1367
  }
1345
1368
 
@@ -1347,16 +1370,129 @@ class NativeScheduleAdapter {
1347
1370
  timestamp: number,
1348
1371
  action: string,
1349
1372
  ...args: unknown[]
1350
- ): Promise<void> {
1351
- callNativeSync(() =>
1352
- this.#runtime.actorScheduleAt(
1353
- this.#ctx,
1354
- timestamp,
1355
- action,
1356
- encodeValue(args),
1357
- ),
1373
+ ): Promise<string> {
1374
+ return await this.#runtime.actorScheduleAt(
1375
+ this.#ctx,
1376
+ timestamp,
1377
+ action,
1378
+ encodeValue(args),
1379
+ );
1380
+ }
1381
+
1382
+ async cancel(id: string): Promise<boolean> {
1383
+ return await this.#runtime.actorScheduleCancel(this.#ctx, id);
1384
+ }
1385
+
1386
+ async get(id: string): Promise<ScheduledEventInfo | undefined> {
1387
+ const event = await this.#runtime.actorScheduleGet(this.#ctx, id);
1388
+ return event ? decodeScheduledEventInfo(event) : undefined;
1389
+ }
1390
+
1391
+ async list(): Promise<ScheduledEventInfo[]> {
1392
+ return (await this.#runtime.actorScheduleList(this.#ctx)).map(
1393
+ decodeScheduledEventInfo,
1394
+ );
1395
+ }
1396
+ }
1397
+
1398
+ class NativeCronAdapter implements ActorCron {
1399
+ #runtime: CoreRuntime;
1400
+ #ctx: ActorContextHandle;
1401
+
1402
+ constructor(runtime: CoreRuntime, ctx: ActorContextHandle) {
1403
+ this.#runtime = runtime;
1404
+ this.#ctx = ctx;
1405
+ }
1406
+
1407
+ async set(options: ActorCronSetOptions): Promise<void> {
1408
+ await this.#runtime.actorCronSet(
1409
+ this.#ctx,
1410
+ options.name,
1411
+ options.expression,
1412
+ options.timezone,
1413
+ options.action,
1414
+ encodeValue(options.args ?? []),
1415
+ options.maxHistory,
1416
+ );
1417
+ }
1418
+
1419
+ async every(options: ActorCronEveryOptions): Promise<void> {
1420
+ await this.#runtime.actorCronEvery(
1421
+ this.#ctx,
1422
+ options.name,
1423
+ options.interval,
1424
+ options.action,
1425
+ encodeValue(options.args ?? []),
1426
+ options.maxHistory,
1358
1427
  );
1359
1428
  }
1429
+
1430
+ async get(name: string): Promise<CronJobInfo | undefined> {
1431
+ const job = await this.#runtime.actorCronGet(this.#ctx, name);
1432
+ return job ? decodeCronJobInfo(job) : undefined;
1433
+ }
1434
+
1435
+ async list(): Promise<CronJobInfo[]> {
1436
+ return (await this.#runtime.actorCronList(this.#ctx)).map(
1437
+ decodeCronJobInfo,
1438
+ );
1439
+ }
1440
+
1441
+ async delete(name: string): Promise<boolean> {
1442
+ return await this.#runtime.actorCronDelete(this.#ctx, name);
1443
+ }
1444
+
1445
+ async history(
1446
+ name: string,
1447
+ options?: { limit?: number },
1448
+ ): Promise<CronFire[]> {
1449
+ return (
1450
+ await this.#runtime.actorCronHistory(
1451
+ this.#ctx,
1452
+ name,
1453
+ options?.limit,
1454
+ )
1455
+ ).map(decodeCronFire);
1456
+ }
1457
+ }
1458
+
1459
+ function decodeScheduledEventInfo(
1460
+ event: RuntimeScheduledEventInfo,
1461
+ ): ScheduledEventInfo {
1462
+ return {
1463
+ id: event.id,
1464
+ action: event.action,
1465
+ args: decodeArgs(event.args),
1466
+ runAt: event.runAt,
1467
+ };
1468
+ }
1469
+
1470
+ function decodeCronJobInfo(job: RuntimeCronJobInfo): CronJobInfo {
1471
+ const base = {
1472
+ name: job.name,
1473
+ action: job.action,
1474
+ args: decodeArgs(job.args),
1475
+ nextRunAt: job.nextRunAt,
1476
+ lastRunAt: job.lastRunAt,
1477
+ maxHistory: job.maxHistory,
1478
+ };
1479
+ if (job.kind === "cron") {
1480
+ return {
1481
+ ...base,
1482
+ kind: "cron",
1483
+ expression: job.expression as string,
1484
+ timezone: job.timezone as string,
1485
+ };
1486
+ }
1487
+ return {
1488
+ ...base,
1489
+ kind: "every",
1490
+ interval: job.intervalMs as number,
1491
+ };
1492
+ }
1493
+
1494
+ function decodeCronFire(fire: RuntimeCronFire): CronFire {
1495
+ return { ...fire };
1360
1496
  }
1361
1497
 
1362
1498
  class NativeKvAdapter {
@@ -2414,6 +2550,7 @@ export class ActorContextHandleAdapter {
2414
2550
  #client?: AnyClient;
2415
2551
  #clientFactory?: () => AnyClient;
2416
2552
  #connMap?: NativeConnectionMap;
2553
+ #cron?: NativeCronAdapter;
2417
2554
  #databaseProvider?: Exclude<AnyDatabaseProvider, undefined>;
2418
2555
  #db?: unknown;
2419
2556
  #dispatchCancelToken?: CancellationTokenHandle;
@@ -2473,6 +2610,12 @@ export class ActorContextHandleAdapter {
2473
2610
  return this.#sql;
2474
2611
  }
2475
2612
 
2613
+ async actorRuntimeSocket(): Promise<{ path: string }> {
2614
+ return await callNative(() =>
2615
+ this.#runtime.actorRuntimeSocketProvision(this.#ctx),
2616
+ );
2617
+ }
2618
+
2476
2619
  get db() {
2477
2620
  if (!this.#databaseProvider) {
2478
2621
  throw databaseNotConfiguredError();
@@ -2582,6 +2725,13 @@ export class ActorContextHandleAdapter {
2582
2725
  return this.#schedule;
2583
2726
  }
2584
2727
 
2728
+ get cron(): NativeCronAdapter {
2729
+ if (!this.#cron) {
2730
+ this.#cron = new NativeCronAdapter(this.#runtime, this.#ctx);
2731
+ }
2732
+ return this.#cron;
2733
+ }
2734
+
2585
2735
  get actorId(): string {
2586
2736
  return callNativeSync(() => this.#runtime.actorId(this.#ctx));
2587
2737
  }
@@ -2796,6 +2946,14 @@ export class ActorContextHandleAdapter {
2796
2946
  );
2797
2947
  }
2798
2948
 
2949
+ async saveStateAndWorkflowBatch(
2950
+ writes: Array<{ key: Uint8Array; value: Uint8Array }>,
2951
+ ): Promise<void> {
2952
+ await callNative(() =>
2953
+ this.#runtime.actorSaveStateAndWorkflowBatch(this.#ctx, writes),
2954
+ );
2955
+ }
2956
+
2799
2957
  serializeForTick(reason: SerializeStateReason): RuntimeStateDeltaPayload {
2800
2958
  void reason;
2801
2959
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
@@ -3150,6 +3308,9 @@ class NativeWorkflowRuntimeAdapter {
3150
3308
  immediate?: boolean;
3151
3309
  maxWait?: number;
3152
3310
  }) => Promise<void>;
3311
+ saveStateAndWorkflowBatch: (
3312
+ writes: Array<{ key: Uint8Array; value: Uint8Array }>,
3313
+ ) => Promise<void>;
3153
3314
  };
3154
3315
 
3155
3316
  constructor(ctx: ActorContextHandleAdapter) {
@@ -3225,6 +3386,9 @@ class NativeWorkflowRuntimeAdapter {
3225
3386
  saveState: async (opts) => {
3226
3387
  await this.#ctx.saveState(opts);
3227
3388
  },
3389
+ saveStateAndWorkflowBatch: async (writes) => {
3390
+ await this.#ctx.saveStateAndWorkflowBatch(writes);
3391
+ },
3228
3392
  };
3229
3393
  }
3230
3394
 
@@ -3311,14 +3475,15 @@ function buildActorConfig(
3311
3475
  const config = definition.config as unknown as Record<string, unknown>;
3312
3476
  const options = (config.options ?? {}) as Record<string, unknown>;
3313
3477
  const canHibernate = options.canHibernateWebSocket;
3478
+ const usesRemoteSqlite =
3479
+ sqliteBackendForConfig(registryConfig) === "remote";
3314
3480
 
3315
3481
  return {
3316
3482
  name: options.name as string | undefined,
3317
3483
  icon: options.icon as string | undefined,
3318
- hasDatabase: config.db !== undefined,
3319
- remoteSqlite:
3320
- config.db !== undefined &&
3321
- sqliteBackendForConfig(registryConfig) === "remote",
3484
+ hasDatabase: config.db !== undefined || usesRemoteSqlite,
3485
+ remoteSqlite: usesRemoteSqlite,
3486
+ enableActorRuntimeSocket: options.enableActorRuntimeSocket === true,
3322
3487
  hasState:
3323
3488
  config.state !== undefined ||
3324
3489
  typeof config.createState === "function",
@@ -3345,6 +3510,7 @@ function buildActorConfig(
3345
3510
  | number
3346
3511
  | undefined,
3347
3512
  maxQueueSize: options.maxQueueSize as number | undefined,
3513
+ maxSchedules: options.maxSchedules as number | undefined,
3348
3514
  maxQueueMessageSize: options.maxQueueMessageSize as number | undefined,
3349
3515
  maxIncomingMessageSize: registryConfig.maxIncomingMessageSize as
3350
3516
  | number
@@ -3726,7 +3892,9 @@ export function buildNativeFactory(
3726
3892
  400,
3727
3893
  );
3728
3894
  }
3729
- const cbor = encodeCborCompat((body.body ?? null) as JsonCompatValue);
3895
+ const cbor = encodeCborCompat(
3896
+ (body.body ?? null) as JsonCompatValue,
3897
+ );
3730
3898
  const message = await runtime.actorQueueSend(ctx, name, cbor);
3731
3899
  return jsonResponse({
3732
3900
  id: message.id().toString(),
@@ -4691,10 +4859,11 @@ export function buildNativeFactory(
4691
4859
  conn: ConnHandle | null;
4692
4860
  name: string;
4693
4861
  args: RuntimeBytes;
4862
+ scheduledFire?: RuntimeScheduledFireInfo;
4694
4863
  cancelToken?: CancellationTokenHandle;
4695
4864
  },
4696
4865
  ) => {
4697
- const { ctx, conn, args, cancelToken } =
4866
+ const { ctx, conn, args, scheduledFire, cancelToken } =
4698
4867
  unwrapTsfnPayload(error, payload);
4699
4868
  const actorCtx =
4700
4869
  conn != null
@@ -4709,6 +4878,7 @@ export function buildNativeFactory(
4709
4878
  name,
4710
4879
  decodeArgs(args),
4711
4880
  ),
4881
+ ...(scheduledFire ? [scheduledFire] : []),
4712
4882
  ),
4713
4883
  );
4714
4884
  } finally {