@swirls/looms 0.12.4 → 0.13.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ab05943: A run on a Durable Object now recovers by itself when its isolate is lost while an in-process effect is running. Until now such a run had no alarm, so after an eviction, deploy, or crash mid-effect it stayed `running` until something signalled it. While a wake waits on in-process effects it now keeps the object's alarm about 30 seconds ahead and renews it; if the isolate goes away the alarm fires in a new one, the run wakes, and the effect is re-attempted as it already is on any later wake. `WakeScheduler` gains an optional `keepAlive` for hosts whose wakes outlive the process, and `livenessLeaseMs` sets the interval. Schedulers without `keepAlive`, including the default in-process one, behave as before.
8
+
9
+ ## 0.13.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 70b0f88: Let `authorize` say who a request acts as, and decide in a Cloudflare Worker.
14
+
15
+ - An allowed `AuthDecision` may carry `actorId` (`authAllowedAs(actorId)`). Events sent through
16
+ `POST /runs/:runId/events` and named signals are then recorded with
17
+ `origin: { type: 'external', actorId }`, replacing any origin the request claimed.
18
+ - `RouteInfo` has `signal` (`namespace/name`) for named signal requests, so a policy can allow
19
+ specific signals.
20
+ - `describeRoute(method, pathname)` describes a request's Looms route without a runtime.
21
+ - `routeToDurableObject` takes `authorize`, checked in the Worker before a request is forwarded. The
22
+ actor it names reaches the Durable Object in a header clients cannot set; `forwardedActorAuth()`
23
+ on the object records it.
24
+
3
25
  ## 0.12.4
4
26
 
5
27
  ### Patch Changes
@@ -9,6 +9,8 @@ export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] =
9
9
  readonly definitionResolver?: DefinitionResolver;
10
10
  readonly snapshotEvery?: number;
11
11
  readonly maxWakeIterations?: number;
12
+ /** See `CreateRuntimeOptions.livenessLeaseMs`. */
13
+ readonly livenessLeaseMs?: number;
12
14
  readonly maxPendingRunOperations?: number;
13
15
  readonly snapshotStore?: SnapshotStore;
14
16
  readonly trimAfterSnapshot?: {
@@ -17,6 +17,7 @@ export function createActorCell(options) {
17
17
  worker: options.worker,
18
18
  snapshotEvery: options.snapshotEvery,
19
19
  maxWakeIterations: options.maxWakeIterations,
20
+ livenessLeaseMs: options.livenessLeaseMs,
20
21
  maxPendingRunOperations: options.maxPendingRunOperations,
21
22
  snapshotStore: options.snapshotStore,
22
23
  trimAfterSnapshot: options.trimAfterSnapshot,
@@ -24,6 +24,252 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
24
24
  readonly alreadyCompacted?: boolean | undefined;
25
25
  readonly consumedSteerMessageIds?: readonly string[] | undefined;
26
26
  }, AgentDefinitionsTag | LlmTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
27
+ readonly type: "runtime.child.close.requested";
28
+ readonly payload: {
29
+ readonly policy: "terminate" | "wait";
30
+ };
31
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
32
+ readonly type: "runtime.child.settled";
33
+ readonly payload: {
34
+ readonly runId: string;
35
+ readonly status: "cancelled" | "completed" | "failed";
36
+ readonly output: Schema.Json;
37
+ readonly error: string | null;
38
+ };
39
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
40
+ readonly type: "runtime.effect.ambiguous";
41
+ readonly payload: {
42
+ readonly effectId: string;
43
+ readonly attempt: number;
44
+ readonly error: string;
45
+ };
46
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
47
+ readonly type: "runtime.effect.attempt.started";
48
+ readonly payload: {
49
+ readonly effectId: string;
50
+ readonly attempt: number;
51
+ };
52
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
53
+ readonly type: "runtime.effect.cancel.requested";
54
+ readonly payload: {
55
+ readonly effectId: string;
56
+ readonly attempt: number;
57
+ readonly deadlineAt: number | null;
58
+ };
59
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
60
+ readonly type: "runtime.effect.cancelled";
61
+ readonly payload: {
62
+ readonly effectId: string;
63
+ readonly attempt: number;
64
+ };
65
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
66
+ readonly type: "runtime.effect.completed";
67
+ readonly payload: {
68
+ readonly effectId: string;
69
+ readonly attempt: number;
70
+ };
71
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
72
+ readonly type: "runtime.effect.dispatch.deferred";
73
+ readonly payload: {
74
+ readonly effectId: string;
75
+ readonly attempt: number;
76
+ readonly retryAt: number;
77
+ readonly error: string;
78
+ readonly try: number;
79
+ };
80
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
81
+ readonly type: "runtime.effect.dispatched";
82
+ readonly payload: {
83
+ readonly effectId: string;
84
+ readonly attempt: number;
85
+ readonly deadlineAt: number | null;
86
+ };
87
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
88
+ readonly type: "runtime.effect.failed";
89
+ readonly payload: {
90
+ readonly effectId: string;
91
+ readonly error: string;
92
+ readonly nonRetryable?: boolean | undefined;
93
+ readonly retryAfterMs?: number | undefined;
94
+ };
95
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
96
+ readonly type: "runtime.effect.heartbeat";
97
+ readonly payload: {
98
+ readonly effectId: string;
99
+ readonly attempt: number;
100
+ readonly heartbeatAt: number;
101
+ readonly deadlineAt: number | null;
102
+ readonly details?: Schema.Json | undefined;
103
+ };
104
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
105
+ readonly type: "runtime.effect.queued";
106
+ readonly payload: {
107
+ readonly effectId: string;
108
+ readonly attempt: number;
109
+ readonly deadlineAt: number | null;
110
+ };
111
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
112
+ readonly type: "runtime.effect.retry.scheduled";
113
+ readonly payload: {
114
+ readonly effectId: string;
115
+ readonly attempt: number;
116
+ readonly nextAttemptAt: number;
117
+ readonly error: string;
118
+ };
119
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
120
+ readonly type: "runtime.effect.timed_out";
121
+ readonly payload: {
122
+ readonly effectId: string;
123
+ readonly attempt: number;
124
+ readonly timeout: string;
125
+ };
126
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
127
+ readonly type: "runtime.effect.worker.started";
128
+ readonly payload: {
129
+ readonly effectId: string;
130
+ readonly attempt: number;
131
+ readonly deadlineAt: number | null;
132
+ };
133
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
134
+ readonly type: "runtime.fork.elided";
135
+ readonly payload: {
136
+ readonly type: string;
137
+ };
138
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
139
+ readonly type: "runtime.run.cancelled";
140
+ readonly payload: {
141
+ readonly reason?: string | undefined;
142
+ };
143
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
144
+ readonly type: "runtime.run.completed";
145
+ readonly payload: {
146
+ readonly output: Schema.Json;
147
+ readonly error: string | null;
148
+ };
149
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
150
+ readonly type: "runtime.run.forked";
151
+ readonly payload: {
152
+ readonly sourceRunId: string;
153
+ readonly sourceSeq: number;
154
+ };
155
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
156
+ readonly type: "runtime.run.launched";
157
+ readonly payload: {
158
+ readonly runId: string;
159
+ readonly kind: string;
160
+ readonly definitionName: string;
161
+ readonly definitionVersion: string;
162
+ readonly effectId: string;
163
+ readonly close: "terminate" | "wait";
164
+ };
165
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
166
+ readonly type: "runtime.run.started";
167
+ readonly payload: {
168
+ readonly rootThreadId?: string | undefined;
169
+ readonly kind: string;
170
+ readonly definitionName: string;
171
+ readonly definitionVersion: string;
172
+ readonly input: Schema.Json;
173
+ readonly requestedThreadId?: string | null | undefined;
174
+ readonly launchedBy?: {
175
+ readonly runId: string;
176
+ readonly threadId: string;
177
+ readonly effectId: string;
178
+ readonly causationId: string;
179
+ readonly causationSeq: number;
180
+ } | undefined;
181
+ readonly attributes?: {
182
+ readonly [x: string]: string;
183
+ } | undefined;
184
+ readonly trace?: {
185
+ readonly traceparent: string;
186
+ readonly tracestate?: string | undefined;
187
+ } | undefined;
188
+ };
189
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
190
+ readonly type: "runtime.signal.received";
191
+ readonly payload: {
192
+ readonly signalType: string;
193
+ };
194
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
195
+ readonly type: "runtime.snapshot.taken";
196
+ readonly payload: {
197
+ readonly seq: number;
198
+ readonly stateHash: string;
199
+ readonly state?: Schema.Json | undefined;
200
+ };
201
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
202
+ readonly type: "runtime.thread.cancel.requested";
203
+ readonly payload: {
204
+ readonly threadId: string;
205
+ };
206
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
207
+ readonly type: "runtime.thread.cancelled";
208
+ readonly payload: {
209
+ readonly threadId: string;
210
+ readonly reason?: string | undefined;
211
+ readonly resumeSeq?: number | undefined;
212
+ };
213
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
214
+ readonly type: "runtime.thread.completed";
215
+ readonly payload: {
216
+ readonly threadId: string;
217
+ readonly output: Schema.Json;
218
+ };
219
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
220
+ readonly type: "runtime.thread.failed";
221
+ readonly payload: {
222
+ readonly threadId: string;
223
+ readonly error: string;
224
+ };
225
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
226
+ readonly type: "runtime.thread.started";
227
+ readonly payload: {
228
+ readonly threadId: string;
229
+ readonly kind: string;
230
+ readonly definitionName: string;
231
+ readonly definitionVersion: string;
232
+ readonly input: Schema.Json;
233
+ readonly parentThreadId: string | null;
234
+ };
235
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
236
+ readonly type: "runtime.timer.fired";
237
+ readonly payload: {
238
+ readonly timerId: string;
239
+ readonly waitId: string;
240
+ };
241
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
242
+ readonly type: "runtime.timer.set";
243
+ readonly payload: {
244
+ readonly timerId: string;
245
+ readonly waitId: string;
246
+ readonly wakeAt: number;
247
+ };
248
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
249
+ readonly type: "runtime.wait.registered";
250
+ readonly payload: {
251
+ readonly waitId: string;
252
+ readonly threadId?: string | undefined;
253
+ readonly on: {
254
+ readonly type: string | readonly string[];
255
+ readonly match?: Schema.Json | undefined;
256
+ } | {
257
+ readonly timerAt: number;
258
+ };
259
+ readonly tag?: Schema.Json | undefined;
260
+ };
261
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
262
+ readonly type: "runtime.wait.satisfied";
263
+ readonly payload: {
264
+ readonly waitId: string;
265
+ readonly tag?: Schema.Json | undefined;
266
+ readonly event: {
267
+ readonly id: string;
268
+ readonly type: string;
269
+ readonly payload: Schema.Json;
270
+ };
271
+ };
272
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
27
273
  readonly type: "agent.context.compacted";
28
274
  readonly payload: {
29
275
  readonly turn: number;
@@ -271,7 +517,19 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
271
517
  readonly input: number;
272
518
  readonly output: number;
273
519
  };
274
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
520
+ })>>;
521
+ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
522
+ readonly turn: number;
523
+ readonly definitionName?: string | undefined;
524
+ readonly definitionVersion: string;
525
+ readonly toolCall: {
526
+ readonly id: string;
527
+ readonly name: string;
528
+ readonly arguments: Schema.Json;
529
+ };
530
+ readonly input?: Schema.Json | undefined;
531
+ readonly depth?: number | undefined;
532
+ }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
275
533
  readonly type: "runtime.child.close.requested";
276
534
  readonly payload: {
277
535
  readonly policy: "terminate" | "wait";
@@ -510,26 +768,14 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
510
768
  readonly type: "runtime.wait.satisfied";
511
769
  readonly payload: {
512
770
  readonly waitId: string;
513
- readonly tag?: Schema.Json | undefined;
514
- readonly event: {
515
- readonly id: string;
516
- readonly type: string;
517
- readonly payload: Schema.Json;
518
- };
519
- };
520
- })>>;
521
- export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
522
- readonly turn: number;
523
- readonly definitionName?: string | undefined;
524
- readonly definitionVersion: string;
525
- readonly toolCall: {
526
- readonly id: string;
527
- readonly name: string;
528
- readonly arguments: Schema.Json;
771
+ readonly tag?: Schema.Json | undefined;
772
+ readonly event: {
773
+ readonly id: string;
774
+ readonly type: string;
775
+ readonly payload: Schema.Json;
776
+ };
529
777
  };
530
- readonly input?: Schema.Json | undefined;
531
- readonly depth?: number | undefined;
532
- }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
778
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
533
779
  readonly type: "agent.context.compacted";
534
780
  readonly payload: {
535
781
  readonly turn: number;
@@ -777,251 +1023,5 @@ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").Loc
777
1023
  readonly input: number;
778
1024
  readonly output: number;
779
1025
  };
780
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
781
- readonly type: "runtime.child.close.requested";
782
- readonly payload: {
783
- readonly policy: "terminate" | "wait";
784
- };
785
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
786
- readonly type: "runtime.child.settled";
787
- readonly payload: {
788
- readonly runId: string;
789
- readonly status: "cancelled" | "completed" | "failed";
790
- readonly output: Schema.Json;
791
- readonly error: string | null;
792
- };
793
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
794
- readonly type: "runtime.effect.ambiguous";
795
- readonly payload: {
796
- readonly effectId: string;
797
- readonly attempt: number;
798
- readonly error: string;
799
- };
800
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
801
- readonly type: "runtime.effect.attempt.started";
802
- readonly payload: {
803
- readonly effectId: string;
804
- readonly attempt: number;
805
- };
806
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
807
- readonly type: "runtime.effect.cancel.requested";
808
- readonly payload: {
809
- readonly effectId: string;
810
- readonly attempt: number;
811
- readonly deadlineAt: number | null;
812
- };
813
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
814
- readonly type: "runtime.effect.cancelled";
815
- readonly payload: {
816
- readonly effectId: string;
817
- readonly attempt: number;
818
- };
819
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
820
- readonly type: "runtime.effect.completed";
821
- readonly payload: {
822
- readonly effectId: string;
823
- readonly attempt: number;
824
- };
825
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
826
- readonly type: "runtime.effect.dispatch.deferred";
827
- readonly payload: {
828
- readonly effectId: string;
829
- readonly attempt: number;
830
- readonly retryAt: number;
831
- readonly error: string;
832
- readonly try: number;
833
- };
834
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
835
- readonly type: "runtime.effect.dispatched";
836
- readonly payload: {
837
- readonly effectId: string;
838
- readonly attempt: number;
839
- readonly deadlineAt: number | null;
840
- };
841
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
842
- readonly type: "runtime.effect.failed";
843
- readonly payload: {
844
- readonly effectId: string;
845
- readonly error: string;
846
- readonly nonRetryable?: boolean | undefined;
847
- readonly retryAfterMs?: number | undefined;
848
- };
849
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
850
- readonly type: "runtime.effect.heartbeat";
851
- readonly payload: {
852
- readonly effectId: string;
853
- readonly attempt: number;
854
- readonly heartbeatAt: number;
855
- readonly deadlineAt: number | null;
856
- readonly details?: Schema.Json | undefined;
857
- };
858
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
859
- readonly type: "runtime.effect.queued";
860
- readonly payload: {
861
- readonly effectId: string;
862
- readonly attempt: number;
863
- readonly deadlineAt: number | null;
864
- };
865
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
866
- readonly type: "runtime.effect.retry.scheduled";
867
- readonly payload: {
868
- readonly effectId: string;
869
- readonly attempt: number;
870
- readonly nextAttemptAt: number;
871
- readonly error: string;
872
- };
873
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
874
- readonly type: "runtime.effect.timed_out";
875
- readonly payload: {
876
- readonly effectId: string;
877
- readonly attempt: number;
878
- readonly timeout: string;
879
- };
880
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
881
- readonly type: "runtime.effect.worker.started";
882
- readonly payload: {
883
- readonly effectId: string;
884
- readonly attempt: number;
885
- readonly deadlineAt: number | null;
886
- };
887
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
888
- readonly type: "runtime.fork.elided";
889
- readonly payload: {
890
- readonly type: string;
891
- };
892
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
893
- readonly type: "runtime.run.cancelled";
894
- readonly payload: {
895
- readonly reason?: string | undefined;
896
- };
897
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
898
- readonly type: "runtime.run.completed";
899
- readonly payload: {
900
- readonly output: Schema.Json;
901
- readonly error: string | null;
902
- };
903
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
904
- readonly type: "runtime.run.forked";
905
- readonly payload: {
906
- readonly sourceRunId: string;
907
- readonly sourceSeq: number;
908
- };
909
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
910
- readonly type: "runtime.run.launched";
911
- readonly payload: {
912
- readonly runId: string;
913
- readonly kind: string;
914
- readonly definitionName: string;
915
- readonly definitionVersion: string;
916
- readonly effectId: string;
917
- readonly close: "terminate" | "wait";
918
- };
919
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
920
- readonly type: "runtime.run.started";
921
- readonly payload: {
922
- readonly rootThreadId?: string | undefined;
923
- readonly kind: string;
924
- readonly definitionName: string;
925
- readonly definitionVersion: string;
926
- readonly input: Schema.Json;
927
- readonly requestedThreadId?: string | null | undefined;
928
- readonly launchedBy?: {
929
- readonly runId: string;
930
- readonly threadId: string;
931
- readonly effectId: string;
932
- readonly causationId: string;
933
- readonly causationSeq: number;
934
- } | undefined;
935
- readonly attributes?: {
936
- readonly [x: string]: string;
937
- } | undefined;
938
- readonly trace?: {
939
- readonly traceparent: string;
940
- readonly tracestate?: string | undefined;
941
- } | undefined;
942
- };
943
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
944
- readonly type: "runtime.signal.received";
945
- readonly payload: {
946
- readonly signalType: string;
947
- };
948
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
949
- readonly type: "runtime.snapshot.taken";
950
- readonly payload: {
951
- readonly seq: number;
952
- readonly stateHash: string;
953
- readonly state?: Schema.Json | undefined;
954
- };
955
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
956
- readonly type: "runtime.thread.cancel.requested";
957
- readonly payload: {
958
- readonly threadId: string;
959
- };
960
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
961
- readonly type: "runtime.thread.cancelled";
962
- readonly payload: {
963
- readonly threadId: string;
964
- readonly reason?: string | undefined;
965
- readonly resumeSeq?: number | undefined;
966
- };
967
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
968
- readonly type: "runtime.thread.completed";
969
- readonly payload: {
970
- readonly threadId: string;
971
- readonly output: Schema.Json;
972
- };
973
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
974
- readonly type: "runtime.thread.failed";
975
- readonly payload: {
976
- readonly threadId: string;
977
- readonly error: string;
978
- };
979
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
980
- readonly type: "runtime.thread.started";
981
- readonly payload: {
982
- readonly threadId: string;
983
- readonly kind: string;
984
- readonly definitionName: string;
985
- readonly definitionVersion: string;
986
- readonly input: Schema.Json;
987
- readonly parentThreadId: string | null;
988
- };
989
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
990
- readonly type: "runtime.timer.fired";
991
- readonly payload: {
992
- readonly timerId: string;
993
- readonly waitId: string;
994
- };
995
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
996
- readonly type: "runtime.timer.set";
997
- readonly payload: {
998
- readonly timerId: string;
999
- readonly waitId: string;
1000
- readonly wakeAt: number;
1001
- };
1002
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1003
- readonly type: "runtime.wait.registered";
1004
- readonly payload: {
1005
- readonly waitId: string;
1006
- readonly threadId?: string | undefined;
1007
- readonly on: {
1008
- readonly type: string | readonly string[];
1009
- readonly match?: Schema.Json | undefined;
1010
- } | {
1011
- readonly timerAt: number;
1012
- };
1013
- readonly tag?: Schema.Json | undefined;
1014
- };
1015
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1016
- readonly type: "runtime.wait.satisfied";
1017
- readonly payload: {
1018
- readonly waitId: string;
1019
- readonly tag?: Schema.Json | undefined;
1020
- readonly event: {
1021
- readonly id: string;
1022
- readonly type: string;
1023
- readonly payload: Schema.Json;
1024
- };
1025
- };
1026
1026
  })>>;
1027
1027
  export declare function readToolCall(value: JsonValue): ToolCall | null;
@@ -10,10 +10,19 @@ export interface DurableObjectAlarms {
10
10
  readonly scheduler: WakeScheduler;
11
11
  /** Ensures the alarm fires no later than `at` without forgetting the runtime deadline. */
12
12
  readonly scheduleAtEarliest: (at: number) => Effect.Effect<void>;
13
+ /**
14
+ * Run when the alarm fires, before waking. A runtime deadline that is already due is being
15
+ * delivered by this alarm, so it is forgotten instead of being set again by a later rearm.
16
+ */
17
+ readonly fired: Effect.Effect<void>;
13
18
  }
14
19
  /**
15
20
  * The single owner of a Durable Object's one alarm. Every write is serialized and sets the alarm to
16
- * the earliest of the runtime deadline, `additionalDeadline` (such as projector retries), and the
17
- * requested time, so concurrent writers cannot overwrite each other's deadlines.
21
+ * the earliest of the runtime deadline, the liveness deadline of a wake with in-process effects in
22
+ * flight, `additionalDeadline` (such as projector retries), and the requested time, so concurrent
23
+ * writers cannot overwrite each other's deadlines.
24
+ *
25
+ * The liveness deadline is what recovers a run whose isolate is lost mid-effect: the live wake
26
+ * keeps pushing it forward, and once nothing does it fires in a fresh isolate, which wakes the run.
18
27
  */
19
28
  export declare function durableObjectAlarms(storage: AlarmStorage, additionalDeadline?: () => Effect.Effect<number | null>): DurableObjectAlarms;
@@ -1,16 +1,21 @@
1
- import { Effect, Semaphore } from 'effect';
1
+ import { Clock, Effect, Semaphore } from 'effect';
2
2
  function earliest(...deadlines) {
3
3
  const known = deadlines.filter((deadline) => deadline !== null && deadline !== undefined);
4
4
  return known.length === 0 ? null : Math.min(...known);
5
5
  }
6
6
  /**
7
7
  * The single owner of a Durable Object's one alarm. Every write is serialized and sets the alarm to
8
- * the earliest of the runtime deadline, `additionalDeadline` (such as projector retries), and the
9
- * requested time, so concurrent writers cannot overwrite each other's deadlines.
8
+ * the earliest of the runtime deadline, the liveness deadline of a wake with in-process effects in
9
+ * flight, `additionalDeadline` (such as projector retries), and the requested time, so concurrent
10
+ * writers cannot overwrite each other's deadlines.
11
+ *
12
+ * The liveness deadline is what recovers a run whose isolate is lost mid-effect: the live wake
13
+ * keeps pushing it forward, and once nothing does it fires in a fresh isolate, which wakes the run.
10
14
  */
11
15
  export function durableObjectAlarms(storage, additionalDeadline) {
12
16
  // `undefined` until the runtime reports a deadline; until then an existing alarm is preserved.
13
17
  let runtimeDeadline;
18
+ let livenessDeadline = null;
14
19
  const writes = Semaphore.makeUnsafe(1);
15
20
  const rearm = (requested) => Semaphore.withPermits(writes, 1, Effect.gen(function* () {
16
21
  const [additional, current] = yield* Effect.all([
@@ -18,7 +23,7 @@ export function durableObjectAlarms(storage, additionalDeadline) {
18
23
  Effect.promise(() => storage.getAlarm?.() ?? Promise.resolve(null)),
19
24
  ], { concurrency: 'unbounded' });
20
25
  const preserved = runtimeDeadline === undefined ? current : null;
21
- const desired = earliest(runtimeDeadline, additional, requested, preserved);
26
+ const desired = earliest(runtimeDeadline, livenessDeadline, additional, requested, preserved);
22
27
  if (desired === current) {
23
28
  return;
24
29
  }
@@ -34,7 +39,16 @@ export function durableObjectAlarms(storage, additionalDeadline) {
34
39
  runtimeDeadline = null;
35
40
  return rearm(null);
36
41
  }),
42
+ keepAlive: (_runId, until) => Effect.suspend(() => {
43
+ livenessDeadline = until;
44
+ return rearm(null);
45
+ }),
37
46
  },
38
47
  scheduleAtEarliest: rearm,
48
+ fired: Clock.currentTimeMillis.pipe(Effect.map((now) => {
49
+ if (runtimeDeadline !== undefined && runtimeDeadline !== null && runtimeDeadline <= now) {
50
+ runtimeDeadline = null;
51
+ }
52
+ })),
39
53
  };
40
54
  }