@demlik/tea 0.1.1 → 0.2.0

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 (150) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +8 -8
  3. package/dist/authed-call/index.d.ts +3 -3
  4. package/dist/authed-call/index.js +5 -5
  5. package/dist/await-terminal/index.d.ts +1 -1
  6. package/dist/await-terminal/index.js +2 -2
  7. package/dist/batch-window/index.d.ts +2 -2
  8. package/dist/batch-window/index.js +4 -4
  9. package/dist/cache/index.d.ts +2 -2
  10. package/dist/{chunk-EIZJTYKR.js → chunk-5KVHID6A.js} +4 -4
  11. package/dist/{chunk-EIZJTYKR.js.map → chunk-5KVHID6A.js.map} +1 -1
  12. package/dist/{chunk-RVJFGRGK.js → chunk-6GIGQT6C.js} +4 -4
  13. package/dist/chunk-6GIGQT6C.js.map +1 -0
  14. package/dist/{chunk-FH5RUIIL.js → chunk-6OUDPSSG.js} +3 -3
  15. package/dist/{chunk-FH5RUIIL.js.map → chunk-6OUDPSSG.js.map} +1 -1
  16. package/dist/{chunk-2WZHS4P2.js → chunk-6VDCTR7N.js} +25 -40
  17. package/dist/chunk-6VDCTR7N.js.map +1 -0
  18. package/dist/{chunk-BNJYE4AU.js → chunk-DYRKDCJI.js} +46 -16
  19. package/dist/chunk-DYRKDCJI.js.map +1 -0
  20. package/dist/{chunk-RGTPPF4U.js → chunk-EGWTT5XJ.js} +3 -3
  21. package/dist/{chunk-RGTPPF4U.js.map → chunk-EGWTT5XJ.js.map} +1 -1
  22. package/dist/{chunk-A56GNPI7.js → chunk-EMJTPHI7.js} +5 -23
  23. package/dist/chunk-EMJTPHI7.js.map +1 -0
  24. package/dist/{chunk-IFBQJYGI.js → chunk-FOGL3TC7.js} +3 -3
  25. package/dist/{chunk-IFBQJYGI.js.map → chunk-FOGL3TC7.js.map} +1 -1
  26. package/dist/{chunk-RVU3RBE6.js → chunk-G2U7DJHL.js} +6 -4
  27. package/dist/chunk-G2U7DJHL.js.map +1 -0
  28. package/dist/{chunk-WUV3PSCZ.js → chunk-HCEVHFJ7.js} +2 -2
  29. package/dist/chunk-HCEVHFJ7.js.map +1 -0
  30. package/dist/{chunk-EDGDR5XX.js → chunk-IK4S5DJN.js} +3 -3
  31. package/dist/{chunk-EDGDR5XX.js.map → chunk-IK4S5DJN.js.map} +1 -1
  32. package/dist/{chunk-EQRUAP2A.js → chunk-J6527VRQ.js} +2 -2
  33. package/dist/chunk-J6527VRQ.js.map +1 -0
  34. package/dist/{chunk-TAO4YOLO.js → chunk-M6UZT7HS.js} +3 -3
  35. package/dist/{chunk-TAO4YOLO.js.map → chunk-M6UZT7HS.js.map} +1 -1
  36. package/dist/{chunk-QGZW4W3E.js → chunk-SKAMZKTE.js} +3 -3
  37. package/dist/{chunk-QGZW4W3E.js.map → chunk-SKAMZKTE.js.map} +1 -1
  38. package/dist/{chunk-TC4HWABA.js → chunk-VFGKTGGC.js} +7 -7
  39. package/dist/{chunk-TC4HWABA.js.map → chunk-VFGKTGGC.js.map} +1 -1
  40. package/dist/{chunk-D5EQDLDV.js → chunk-ZDRN3YCE.js} +4 -4
  41. package/dist/{chunk-D5EQDLDV.js.map → chunk-ZDRN3YCE.js.map} +1 -1
  42. package/dist/{core-CymXZCeY.d.ts → core-BmlJOvxM.d.ts} +20 -1
  43. package/dist/deadline/index.d.ts +2 -2
  44. package/dist/deadline/index.js +3 -3
  45. package/dist/debounce/index.d.ts +6 -0
  46. package/dist/debounce/index.js +1 -1
  47. package/dist/do/index.d.ts +422 -315
  48. package/dist/do/index.js +173 -149
  49. package/dist/do/index.js.map +1 -1
  50. package/dist/{durable-effects-2MDxDs45.d.ts → durable-effects-9LxFpmh3.d.ts} +1 -1
  51. package/dist/extension/index.d.ts +1 -1
  52. package/dist/extension/index.js +3 -3
  53. package/dist/extension/react.js +3 -3
  54. package/dist/extension/subs/index.d.ts +2 -2
  55. package/dist/fan-out/index.d.ts +1 -1
  56. package/dist/idempotent-intake/index.d.ts +1 -1
  57. package/dist/index.d.ts +20 -3
  58. package/dist/index.js +2 -2
  59. package/dist/llm-call/index.d.ts +2 -2
  60. package/dist/llm-call/index.js +5 -5
  61. package/dist/machine-viz/index.d.ts +4 -4
  62. package/dist/machine-viz/index.js +4 -8
  63. package/dist/machine-viz/index.js.map +1 -1
  64. package/dist/mem/index.d.ts +1 -1
  65. package/dist/monitored-run/index.d.ts +2 -2
  66. package/dist/monitored-run/index.js +5 -5
  67. package/dist/node/index.d.ts +1 -1
  68. package/dist/paginated-walk/index.d.ts +2 -2
  69. package/dist/paginated-walk/index.js +5 -5
  70. package/dist/parity/index.d.ts +10 -4
  71. package/dist/parity/index.js +6 -5
  72. package/dist/parity/index.js.map +1 -1
  73. package/dist/pbt/arbitraries/index.d.ts +1 -1
  74. package/dist/pbt/index.d.ts +15 -8
  75. package/dist/pbt/index.js +5 -11
  76. package/dist/pbt/index.js.map +1 -1
  77. package/dist/pbt/runners/index.d.ts +1 -1
  78. package/dist/pbt/runners/index.js +3 -3
  79. package/dist/poller/index.d.ts +2 -2
  80. package/dist/poller/index.js +3 -3
  81. package/dist/prediction/index.d.ts +23 -2
  82. package/dist/prediction/index.js +2 -2
  83. package/dist/pure/index.d.ts +2 -2
  84. package/dist/pure/index.js +2 -2
  85. package/dist/react/index.d.ts +1 -1
  86. package/dist/react/index.js +8 -4
  87. package/dist/react/index.js.map +1 -1
  88. package/dist/reconciler/index.d.ts +2 -2
  89. package/dist/reconciler/index.js +5 -5
  90. package/dist/recorder/index.d.ts +1 -1
  91. package/dist/resilient-call/index.d.ts +45 -2
  92. package/dist/resilient-call/index.js +4 -4
  93. package/dist/retry-to-success/index.d.ts +109 -0
  94. package/dist/retry-to-success/index.js +35 -0
  95. package/dist/retry-to-success/index.js.map +1 -0
  96. package/dist/saga/index.d.ts +14 -1
  97. package/dist/saga/index.js.map +1 -1
  98. package/dist/snapshot/index.d.ts +1 -1
  99. package/dist/snapshot/index.js +3 -3
  100. package/dist/subs/index.d.ts +2 -2
  101. package/dist/testing/index.d.ts +1 -1
  102. package/dist/testing/index.js +2 -2
  103. package/dist/throttle/index.d.ts +9 -0
  104. package/dist/throttle/index.js +1 -1
  105. package/dist/throttled-input/index.d.ts +10 -2
  106. package/dist/throttled-input/index.js +6 -6
  107. package/dist/throttled-input/index.js.map +1 -1
  108. package/dist/token-refresh/index.d.ts +1 -1
  109. package/dist/token-refresh/index.js +3 -3
  110. package/dist/trace-replay/index.d.ts +1 -1
  111. package/dist/trace-replay/index.js +3 -3
  112. package/dist/{types-N9LZbdnr.d.ts → types-BoUWgwSm.d.ts} +1 -1
  113. package/dist/with-deadline/index.d.ts +1 -1
  114. package/dist/with-deadline/index.js +5 -24
  115. package/dist/with-deadline/index.js.map +1 -1
  116. package/dist/with-resilience/index.d.ts +2 -2
  117. package/dist/with-resilience/index.js +13 -36
  118. package/dist/with-resilience/index.js.map +1 -1
  119. package/dist/with-telemetry/index.d.ts +1 -1
  120. package/dist/with-telemetry/index.js +4 -29
  121. package/dist/with-telemetry/index.js.map +1 -1
  122. package/dist/work-queue/adapter.d.ts +1 -1
  123. package/dist/work-queue/index.d.ts +1 -1
  124. package/dist/work-queue/ops.d.ts +1 -1
  125. package/dist/workflow/index.d.ts +16 -10
  126. package/dist/workflow/index.js.map +1 -1
  127. package/package.json +8 -20
  128. package/dist/chunk-2WZHS4P2.js.map +0 -1
  129. package/dist/chunk-7VEG4KHB.js +0 -202
  130. package/dist/chunk-7VEG4KHB.js.map +0 -1
  131. package/dist/chunk-A56GNPI7.js.map +0 -1
  132. package/dist/chunk-BNJYE4AU.js.map +0 -1
  133. package/dist/chunk-EQRUAP2A.js.map +0 -1
  134. package/dist/chunk-RVJFGRGK.js.map +0 -1
  135. package/dist/chunk-RVU3RBE6.js.map +0 -1
  136. package/dist/chunk-WUV3PSCZ.js.map +0 -1
  137. package/dist/chunk-XRXKH7KA.js +0 -268
  138. package/dist/chunk-XRXKH7KA.js.map +0 -1
  139. package/dist/raft/demo.d.ts +0 -105
  140. package/dist/raft/demo.js +0 -172
  141. package/dist/raft/demo.js.map +0 -1
  142. package/dist/raft/index.d.ts +0 -548
  143. package/dist/raft/index.js +0 -7
  144. package/dist/raft/index.js.map +0 -1
  145. package/dist/raft/sim.d.ts +0 -222
  146. package/dist/raft/sim.js +0 -8
  147. package/dist/raft/sim.js.map +0 -1
  148. package/dist/raft/timeline.d.ts +0 -46
  149. package/dist/raft/timeline.js +0 -62
  150. package/dist/raft/timeline.js.map +0 -1
package/dist/do/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { status, agentBootMsg, agentEvents } from '../chunk-TC4HWABA.js';
2
- import '../chunk-TAO4YOLO.js';
1
+ import { status, agentBootMsg, agentEvents } from '../chunk-VFGKTGGC.js';
3
2
  export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-3545BOYL.js';
4
- import '../chunk-D5EQDLDV.js';
5
- import '../chunk-EIZJTYKR.js';
6
- import '../chunk-RVJFGRGK.js';
3
+ import '../chunk-ZDRN3YCE.js';
4
+ import '../chunk-M6UZT7HS.js';
5
+ import '../chunk-5KVHID6A.js';
6
+ import '../chunk-6GIGQT6C.js';
7
7
  import '../chunk-JELSZN25.js';
8
8
  import '../chunk-UV6UWGEO.js';
9
9
  import { createIntake } from '../chunk-LEC4U6CX.js';
10
- import '../chunk-QGZW4W3E.js';
10
+ import '../chunk-SKAMZKTE.js';
11
11
  import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-5VNWZADP.js';
12
12
  import '../chunk-2YOE5PIS.js';
13
13
  import '../chunk-BYQUGDD3.js';
@@ -18,8 +18,8 @@ import '../chunk-HJO6VNQI.js';
18
18
  import '../chunk-TGG26XMK.js';
19
19
  import '../chunk-NSDFA6M6.js';
20
20
  import '../chunk-2YFLOCWX.js';
21
- import { run, replay } from '../chunk-2WZHS4P2.js';
22
- import '../chunk-BNJYE4AU.js';
21
+ import { run, replay } from '../chunk-6VDCTR7N.js';
22
+ import '../chunk-DYRKDCJI.js';
23
23
 
24
24
  // src/do/durable-timer.ts
25
25
  function durableTimer(config) {
@@ -147,87 +147,7 @@ function doEventSourcedStore(storage, machine, ctx, opts = {}) {
147
147
  return { store, append, snapshotNow, readEvents };
148
148
  }
149
149
 
150
- // src/do/host.ts
151
- function deferredGateway() {
152
- const pending = /* @__PURE__ */ new Map();
153
- return {
154
- await(callId, send, deadlineMs) {
155
- const existing = pending.get(callId);
156
- if (existing !== void 0) return existing.promise;
157
- let resolve;
158
- let reject;
159
- const promise = new Promise((res, rej) => {
160
- resolve = res;
161
- reject = rej;
162
- });
163
- const timer = setTimeout(() => {
164
- if (pending.delete(callId)) {
165
- reject(new Error(`deadline_exceeded after ${deadlineMs}ms`));
166
- }
167
- }, deadlineMs);
168
- pending.set(callId, {
169
- resolve: (v) => {
170
- clearTimeout(timer);
171
- resolve(v);
172
- },
173
- reject: (e) => {
174
- clearTimeout(timer);
175
- reject(e);
176
- },
177
- promise
178
- });
179
- send();
180
- return promise;
181
- },
182
- settle(callId, result) {
183
- const entry = pending.get(callId);
184
- if (entry === void 0) return;
185
- pending.delete(callId);
186
- entry.resolve(result);
187
- },
188
- fail(callId, reason) {
189
- const entry = pending.get(callId);
190
- if (entry === void 0) return;
191
- pending.delete(callId);
192
- entry.reject(new Error(reason));
193
- },
194
- inFlight() {
195
- return [...pending.keys()];
196
- }
197
- };
198
- }
199
- function durableDeferredGateway(inner, recorder, hooks) {
200
- const idByCallId = /* @__PURE__ */ new Map();
201
- return {
202
- recorder,
203
- await(callId, send, deadlineMs) {
204
- if (!idByCallId.has(callId)) {
205
- const { id, event } = recorder.owe({ callId });
206
- idByCallId.set(callId, id);
207
- hooks.recordOwed(callId, event);
208
- }
209
- return inner.await(callId, send, deadlineMs);
210
- },
211
- settle(callId, result) {
212
- confirm(callId);
213
- inner.settle(callId, result);
214
- },
215
- fail(callId, reason) {
216
- confirm(callId);
217
- inner.fail(callId, reason);
218
- },
219
- inFlight() {
220
- return inner.inFlight();
221
- }
222
- };
223
- function confirm(callId) {
224
- const id = idByCallId.get(callId);
225
- if (id === void 0) return;
226
- idByCallId.delete(callId);
227
- const { event } = recorder.confirm(id);
228
- hooks.recordConfirmed(callId, event);
229
- }
230
- }
150
+ // src/do/resume.ts
231
151
  async function bootResume(booting, port, now = Date.now) {
232
152
  const runtime = await booting.ready;
233
153
  if (port.isResumable(runtime.getState())) {
@@ -244,44 +164,6 @@ async function autoBoot(booting, now = Date.now) {
244
164
  now
245
165
  );
246
166
  }
247
- function acceptCommandSocket(clients, onFrame) {
248
- const pair = new WebSocketPair();
249
- const [client, server] = [pair[0], pair[1]];
250
- server.accept();
251
- clients.add(server);
252
- server.addEventListener("message", (ev) => {
253
- if (typeof ev.data === "string") onFrame(ev.data);
254
- });
255
- server.addEventListener("close", () => clients.delete(server));
256
- return new Response(null, { status: 101, webSocket: client });
257
- }
258
- function broadcast(clients, frame) {
259
- const json = JSON.stringify(frame);
260
- for (const ws of clients) {
261
- try {
262
- ws.send(json);
263
- } catch {
264
- }
265
- }
266
- }
267
- function acceptDurableCommandSocket(ctx) {
268
- const pair = new WebSocketPair();
269
- const [client, server] = [pair[0], pair[1]];
270
- ctx.acceptWebSocket(server);
271
- return new Response(null, { status: 101, webSocket: client });
272
- }
273
- function broadcastHibernatable(ctx, frame) {
274
- const json = JSON.stringify(frame);
275
- for (const ws of ctx.getWebSockets()) {
276
- try {
277
- ws.send(json);
278
- } catch {
279
- }
280
- }
281
- }
282
- function durableCommandCarrier(inner, recorder, hooks) {
283
- return durableDeferredGateway(inner, recorder, hooks);
284
- }
285
167
  function reissueSurvivingEffects(carrier, reissue) {
286
168
  const reemitted = [];
287
169
  for (const { effect } of carrier.recorder.surviving()) {
@@ -290,6 +172,8 @@ function reissueSurvivingEffects(carrier, reissue) {
290
172
  }
291
173
  return reemitted;
292
174
  }
175
+
176
+ // src/do/sse.ts
293
177
  function sseHub() {
294
178
  const sinks = /* @__PURE__ */ new Set();
295
179
  const encoder = new TextEncoder();
@@ -361,10 +245,8 @@ function sseFromAgentEvents(runtime, hub, toFrame) {
361
245
  for (const off of offs) off();
362
246
  };
363
247
  }
364
- async function dispatchToIdle(runtime, msg) {
365
- await runtime.dispatch(msg);
366
- await runtime.idle();
367
- }
248
+
249
+ // src/do/agent-host.ts
368
250
  function createAgentHost(config) {
369
251
  const sse = sseHub();
370
252
  const now = config.now ?? Date.now;
@@ -400,6 +282,128 @@ function createAgentHost(config) {
400
282
  };
401
283
  }
402
284
 
285
+ // src/do/command-socket.ts
286
+ function acceptCommandSocket(clients, onFrame) {
287
+ const pair = new WebSocketPair();
288
+ const [client, server] = [pair[0], pair[1]];
289
+ server.accept();
290
+ clients.add(server);
291
+ server.addEventListener("message", (ev) => {
292
+ if (typeof ev.data === "string") onFrame(ev.data);
293
+ });
294
+ server.addEventListener("close", () => clients.delete(server));
295
+ return new Response(null, { status: 101, webSocket: client });
296
+ }
297
+ function broadcast(clients, frame) {
298
+ const json = JSON.stringify(frame);
299
+ for (const ws of clients) {
300
+ try {
301
+ ws.send(json);
302
+ } catch {
303
+ }
304
+ }
305
+ }
306
+ function acceptDurableCommandSocket(ctx) {
307
+ const pair = new WebSocketPair();
308
+ const [client, server] = [pair[0], pair[1]];
309
+ ctx.acceptWebSocket(server);
310
+ return new Response(null, { status: 101, webSocket: client });
311
+ }
312
+ function broadcastHibernatable(ctx, frame) {
313
+ const json = JSON.stringify(frame);
314
+ for (const ws of ctx.getWebSockets()) {
315
+ try {
316
+ ws.send(json);
317
+ } catch {
318
+ }
319
+ }
320
+ }
321
+
322
+ // src/do/deferred-gateway.ts
323
+ function deferredGateway() {
324
+ const pending = /* @__PURE__ */ new Map();
325
+ return {
326
+ await(callId, send, deadlineMs) {
327
+ const existing = pending.get(callId);
328
+ if (existing !== void 0) return existing.promise;
329
+ let resolve;
330
+ let reject;
331
+ const promise = new Promise((res, rej) => {
332
+ resolve = res;
333
+ reject = rej;
334
+ });
335
+ const timer = setTimeout(() => {
336
+ if (pending.delete(callId)) {
337
+ reject(new Error(`deadline_exceeded after ${deadlineMs}ms`));
338
+ }
339
+ }, deadlineMs);
340
+ pending.set(callId, {
341
+ resolve: (v) => {
342
+ clearTimeout(timer);
343
+ resolve(v);
344
+ },
345
+ reject: (e) => {
346
+ clearTimeout(timer);
347
+ reject(e);
348
+ },
349
+ promise
350
+ });
351
+ send();
352
+ return promise;
353
+ },
354
+ settle(callId, result) {
355
+ const entry = pending.get(callId);
356
+ if (entry === void 0) return;
357
+ pending.delete(callId);
358
+ entry.resolve(result);
359
+ },
360
+ fail(callId, reason) {
361
+ const entry = pending.get(callId);
362
+ if (entry === void 0) return;
363
+ pending.delete(callId);
364
+ entry.reject(new Error(reason));
365
+ },
366
+ inFlight() {
367
+ return [...pending.keys()];
368
+ }
369
+ };
370
+ }
371
+ function durableDeferredGateway(inner, recorder, hooks) {
372
+ const idByCallId = /* @__PURE__ */ new Map();
373
+ return {
374
+ recorder,
375
+ await(callId, send, deadlineMs) {
376
+ if (!idByCallId.has(callId)) {
377
+ const { id, event } = recorder.owe({ callId });
378
+ idByCallId.set(callId, id);
379
+ hooks.recordOwed(callId, event);
380
+ }
381
+ return inner.await(callId, send, deadlineMs);
382
+ },
383
+ settle(callId, result) {
384
+ confirm(callId);
385
+ inner.settle(callId, result);
386
+ },
387
+ fail(callId, reason) {
388
+ confirm(callId);
389
+ inner.fail(callId, reason);
390
+ },
391
+ inFlight() {
392
+ return inner.inFlight();
393
+ }
394
+ };
395
+ function confirm(callId) {
396
+ const id = idByCallId.get(callId);
397
+ if (id === void 0) return;
398
+ idByCallId.delete(callId);
399
+ const { event } = recorder.confirm(id);
400
+ hooks.recordConfirmed(callId, event);
401
+ }
402
+ }
403
+ function durableCommandCarrier(inner, recorder, hooks) {
404
+ return durableDeferredGateway(inner, recorder, hooks);
405
+ }
406
+
403
407
  // src/do/idempotent-effect.ts
404
408
  function emptyApplied() {
405
409
  return /* @__PURE__ */ new Set();
@@ -597,8 +601,12 @@ function constantTimeEqual(a, b) {
597
601
  return diff === 0 && lengthMatches;
598
602
  }
599
603
  var DEFAULT_GIVE_UP_MS = 5 * 6e4;
604
+ function workingBody(retryAfterMs) {
605
+ return retryAfterMs === void 0 ? { done: false, working: true } : { done: false, working: true, retryAfterMs };
606
+ }
600
607
  function stepHost(ctx, engine, config = {}) {
601
608
  const giveUpAfterMs = config.giveUpAfterMs ?? DEFAULT_GIVE_UP_MS;
609
+ const deferResume = "deferResume" in config ? config.deferResume : null;
602
610
  const intake = createIntake({
603
611
  keyOf: (posted) => posted.callId
604
612
  });
@@ -614,23 +622,31 @@ function stepHost(ctx, engine, config = {}) {
614
622
  await ctx.storage.setAlarm(now + giveUpAfterMs);
615
623
  const posted = request.posted;
616
624
  if (posted !== null) {
617
- const [nextIntake, cmds] = intake.receive(
618
- intakeState,
619
- posted,
620
- now,
621
- posted.callId
622
- );
623
- intakeState = nextIntake;
624
- for (const cmd of cmds) {
625
- if (cmd.type === "intake:process") {
626
- await engine.resume(request.runId, posted);
627
- const [completed] = intake.complete(
628
- intakeState,
629
- cmd.key,
630
- "settled",
631
- now
632
- );
633
- intakeState = completed;
625
+ if (deferResume === null) {
626
+ const [nextIntake, cmds] = intake.receive(
627
+ intakeState,
628
+ posted,
629
+ now,
630
+ posted.callId
631
+ );
632
+ intakeState = nextIntake;
633
+ for (const cmd of cmds) {
634
+ if (cmd.type === "intake:process") {
635
+ await engine.resume(request.runId, posted);
636
+ const [completed] = intake.complete(
637
+ intakeState,
638
+ cmd.key,
639
+ "settled",
640
+ now
641
+ );
642
+ intakeState = completed;
643
+ }
644
+ }
645
+ } else {
646
+ const ready = await deferResume.settled(request.runId, posted.callId);
647
+ if (!ready) {
648
+ await deferResume.enqueue(request.runId, posted);
649
+ return { status: 200, body: workingBody(deferResume.retryAfterMs) };
634
650
  }
635
651
  }
636
652
  }
@@ -650,6 +666,7 @@ async function runStepLoop(token, runId, transport, execute, config) {
650
666
  const rng = config.rng;
651
667
  const executed = /* @__PURE__ */ new Map();
652
668
  let posted = null;
669
+ let pollRetry = initRetry();
653
670
  for (; ; ) {
654
671
  if (now() >= config.deadlineMs) return { kind: "deadline_exceeded" };
655
672
  let response;
@@ -666,6 +683,13 @@ async function runStepLoop(token, runId, transport, execute, config) {
666
683
  }
667
684
  }
668
685
  if (response.done) return { kind: "done", output: response.output };
686
+ if ("working" in response) {
687
+ pollRetry = recordFailure(pollRetry, "working");
688
+ if (now() >= config.deadlineMs) return { kind: "deadline_exceeded" };
689
+ await sleep(response.retryAfterMs ?? nextDelayMs(pollRetry, policy, rng));
690
+ continue;
691
+ }
692
+ pollRetry = initRetry();
669
693
  const step = response.step;
670
694
  const cached = executed.get(step.callId);
671
695
  const result = cached !== void 0 ? cached : await execute(step);
@@ -695,6 +719,6 @@ function doStore(storage, parse, keyOrOptions = DEFAULT_STATE_KEY) {
695
719
  };
696
720
  }
697
721
 
698
- export { WS_READY_STATE_OPEN, acceptCommandSocket, acceptDurableCommandSocket, acceptPresenceSocket, agentIsResumable, appliedEffects, applyAppliedEvent, autoBoot, bootResume, broadcast, broadcastFrame, broadcastHibernatable, constantTimeEqual, createAgentHost, deferredGateway, dispatchToIdle, doEventSourcedStore, doStore, driveProjections, durableCommandCarrier, durableDeferredGateway, durableTimer, emptyApplied, foldApplied, idempotentEffect, isApplied, mintRunToken, presenceCount, projectionIdString, projectionRegistry, rebuildProjection, registerHibernatableSocket, reissueSurvivingEffects, runProjection, runStepLoop, sseFromAgentEvents, sseHub, sseProjection, stepHost };
722
+ export { WS_READY_STATE_OPEN, acceptCommandSocket, acceptDurableCommandSocket, acceptPresenceSocket, agentIsResumable, appliedEffects, applyAppliedEvent, autoBoot, bootResume, broadcast, broadcastFrame, broadcastHibernatable, constantTimeEqual, createAgentHost, deferredGateway, doEventSourcedStore, doStore, driveProjections, durableCommandCarrier, durableDeferredGateway, durableTimer, emptyApplied, foldApplied, idempotentEffect, isApplied, mintRunToken, presenceCount, projectionIdString, projectionRegistry, rebuildProjection, registerHibernatableSocket, reissueSurvivingEffects, runProjection, runStepLoop, sseFromAgentEvents, sseHub, sseProjection, stepHost };
699
723
  //# sourceMappingURL=index.js.map
700
724
  //# sourceMappingURL=index.js.map