@demlik/tea 0.1.2 → 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.
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +8 -8
- package/dist/authed-call/index.d.ts +2 -2
- package/dist/authed-call/index.js +5 -5
- package/dist/await-terminal/index.d.ts +1 -1
- package/dist/await-terminal/index.js +2 -2
- package/dist/batch-window/index.d.ts +2 -2
- package/dist/batch-window/index.js +3 -3
- package/dist/cache/index.d.ts +2 -2
- package/dist/{chunk-EHIX7NYZ.js → chunk-5KVHID6A.js} +4 -4
- package/dist/{chunk-EHIX7NYZ.js.map → chunk-5KVHID6A.js.map} +1 -1
- package/dist/{chunk-27N2SPTN.js → chunk-6GIGQT6C.js} +4 -4
- package/dist/{chunk-27N2SPTN.js.map → chunk-6GIGQT6C.js.map} +1 -1
- package/dist/{chunk-3XJWC7VW.js → chunk-6OUDPSSG.js} +3 -3
- package/dist/{chunk-3XJWC7VW.js.map → chunk-6OUDPSSG.js.map} +1 -1
- package/dist/{chunk-MMH7CW5K.js → chunk-6VDCTR7N.js} +24 -27
- package/dist/chunk-6VDCTR7N.js.map +1 -0
- package/dist/{chunk-QLA76GIT.js → chunk-DYRKDCJI.js} +30 -5
- package/dist/chunk-DYRKDCJI.js.map +1 -0
- package/dist/{chunk-LP7VQBRG.js → chunk-EGWTT5XJ.js} +3 -3
- package/dist/{chunk-LP7VQBRG.js.map → chunk-EGWTT5XJ.js.map} +1 -1
- package/dist/{chunk-DILMKOZ7.js → chunk-EMJTPHI7.js} +4 -4
- package/dist/{chunk-DILMKOZ7.js.map → chunk-EMJTPHI7.js.map} +1 -1
- package/dist/{chunk-5DEQ5I3U.js → chunk-FOGL3TC7.js} +3 -3
- package/dist/{chunk-5DEQ5I3U.js.map → chunk-FOGL3TC7.js.map} +1 -1
- package/dist/{chunk-SQTCS44W.js → chunk-G2U7DJHL.js} +3 -3
- package/dist/{chunk-SQTCS44W.js.map → chunk-G2U7DJHL.js.map} +1 -1
- package/dist/{chunk-ON24RKSE.js → chunk-IK4S5DJN.js} +3 -3
- package/dist/{chunk-ON24RKSE.js.map → chunk-IK4S5DJN.js.map} +1 -1
- package/dist/{chunk-PS23H6KQ.js → chunk-M6UZT7HS.js} +3 -3
- package/dist/{chunk-PS23H6KQ.js.map → chunk-M6UZT7HS.js.map} +1 -1
- package/dist/{chunk-K7Q23EQ4.js → chunk-SKAMZKTE.js} +3 -3
- package/dist/{chunk-K7Q23EQ4.js.map → chunk-SKAMZKTE.js.map} +1 -1
- package/dist/{chunk-S3FQN4SL.js → chunk-VFGKTGGC.js} +7 -7
- package/dist/{chunk-S3FQN4SL.js.map → chunk-VFGKTGGC.js.map} +1 -1
- package/dist/{chunk-7W4LMPUW.js → chunk-ZDRN3YCE.js} +4 -4
- package/dist/{chunk-7W4LMPUW.js.map → chunk-ZDRN3YCE.js.map} +1 -1
- package/dist/{core-BoB6t7dB.d.ts → core-BmlJOvxM.d.ts} +10 -1
- package/dist/deadline/index.d.ts +2 -2
- package/dist/deadline/index.js +3 -3
- package/dist/do/index.d.ts +451 -335
- package/dist/do/index.js +172 -144
- package/dist/do/index.js.map +1 -1
- package/dist/{durable-effects-CO9Uh971.d.ts → durable-effects-9LxFpmh3.d.ts} +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +3 -3
- package/dist/extension/react.js +3 -3
- package/dist/extension/subs/index.d.ts +2 -2
- package/dist/fan-out/index.d.ts +1 -1
- package/dist/idempotent-intake/index.d.ts +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.js +2 -2
- package/dist/llm-call/index.d.ts +2 -2
- package/dist/llm-call/index.js +5 -5
- package/dist/machine-viz/index.d.ts +1 -1
- package/dist/machine-viz/index.js +2 -2
- package/dist/mem/index.d.ts +1 -1
- package/dist/monitored-run/index.d.ts +2 -2
- package/dist/monitored-run/index.js +5 -5
- package/dist/node/index.d.ts +1 -1
- package/dist/paginated-walk/index.d.ts +2 -2
- package/dist/paginated-walk/index.js +5 -5
- package/dist/parity/index.d.ts +1 -1
- package/dist/parity/index.js +3 -3
- package/dist/pbt/arbitraries/index.d.ts +1 -1
- package/dist/pbt/index.d.ts +1 -1
- package/dist/pbt/index.js +3 -3
- package/dist/pbt/runners/index.d.ts +1 -1
- package/dist/pbt/runners/index.js +3 -3
- package/dist/poller/index.d.ts +2 -2
- package/dist/poller/index.js +3 -3
- package/dist/prediction/index.d.ts +1 -1
- package/dist/prediction/index.js +2 -2
- package/dist/pure/index.d.ts +1 -1
- package/dist/pure/index.js +2 -2
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +2 -2
- package/dist/reconciler/index.d.ts +2 -2
- package/dist/reconciler/index.js +5 -5
- package/dist/recorder/index.d.ts +1 -1
- package/dist/resilient-call/index.d.ts +2 -2
- package/dist/resilient-call/index.js +4 -4
- package/dist/saga/index.d.ts +1 -1
- package/dist/snapshot/index.d.ts +1 -1
- package/dist/snapshot/index.js +3 -3
- package/dist/subs/index.d.ts +2 -2
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +2 -2
- package/dist/throttled-input/index.d.ts +2 -2
- package/dist/throttled-input/index.js +4 -4
- package/dist/token-refresh/index.d.ts +1 -1
- package/dist/token-refresh/index.js +3 -3
- package/dist/trace-replay/index.d.ts +1 -1
- package/dist/trace-replay/index.js +3 -3
- package/dist/{types-B-8bcAp8.d.ts → types-BoUWgwSm.d.ts} +1 -1
- package/dist/with-deadline/index.d.ts +1 -1
- package/dist/with-deadline/index.js +2 -2
- package/dist/with-resilience/index.d.ts +2 -2
- package/dist/with-resilience/index.js +4 -4
- package/dist/with-telemetry/index.d.ts +1 -1
- package/dist/with-telemetry/index.js +2 -2
- package/dist/work-queue/adapter.d.ts +1 -1
- package/dist/work-queue/index.d.ts +1 -1
- package/dist/work-queue/ops.d.ts +1 -1
- package/dist/workflow/index.d.ts +3 -3
- package/package.json +1 -19
- package/dist/chunk-6RGBKODV.js +0 -268
- package/dist/chunk-6RGBKODV.js.map +0 -1
- package/dist/chunk-MMH7CW5K.js.map +0 -1
- package/dist/chunk-QLA76GIT.js.map +0 -1
- package/dist/chunk-VLGARN6H.js +0 -202
- package/dist/chunk-VLGARN6H.js.map +0 -1
- package/dist/raft/demo.d.ts +0 -105
- package/dist/raft/demo.js +0 -172
- package/dist/raft/demo.js.map +0 -1
- package/dist/raft/index.d.ts +0 -548
- package/dist/raft/index.js +0 -7
- package/dist/raft/index.js.map +0 -1
- package/dist/raft/sim.d.ts +0 -222
- package/dist/raft/sim.js +0 -8
- package/dist/raft/sim.js.map +0 -1
- package/dist/raft/timeline.d.ts +0 -46
- package/dist/raft/timeline.js +0 -62
- 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-
|
|
2
|
-
import '../chunk-7W4LMPUW.js';
|
|
3
|
-
import '../chunk-PS23H6KQ.js';
|
|
1
|
+
import { status, agentBootMsg, agentEvents } from '../chunk-VFGKTGGC.js';
|
|
4
2
|
export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-3545BOYL.js';
|
|
5
|
-
import '../chunk-
|
|
6
|
-
import '../chunk-
|
|
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-
|
|
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-
|
|
22
|
-
import '../chunk-
|
|
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/
|
|
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,6 +245,8 @@ function sseFromAgentEvents(runtime, hub, toFrame) {
|
|
|
361
245
|
for (const off of offs) off();
|
|
362
246
|
};
|
|
363
247
|
}
|
|
248
|
+
|
|
249
|
+
// src/do/agent-host.ts
|
|
364
250
|
function createAgentHost(config) {
|
|
365
251
|
const sse = sseHub();
|
|
366
252
|
const now = config.now ?? Date.now;
|
|
@@ -396,6 +282,128 @@ function createAgentHost(config) {
|
|
|
396
282
|
};
|
|
397
283
|
}
|
|
398
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
|
+
|
|
399
407
|
// src/do/idempotent-effect.ts
|
|
400
408
|
function emptyApplied() {
|
|
401
409
|
return /* @__PURE__ */ new Set();
|
|
@@ -593,8 +601,12 @@ function constantTimeEqual(a, b) {
|
|
|
593
601
|
return diff === 0 && lengthMatches;
|
|
594
602
|
}
|
|
595
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
|
+
}
|
|
596
607
|
function stepHost(ctx, engine, config = {}) {
|
|
597
608
|
const giveUpAfterMs = config.giveUpAfterMs ?? DEFAULT_GIVE_UP_MS;
|
|
609
|
+
const deferResume = "deferResume" in config ? config.deferResume : null;
|
|
598
610
|
const intake = createIntake({
|
|
599
611
|
keyOf: (posted) => posted.callId
|
|
600
612
|
});
|
|
@@ -610,23 +622,31 @@ function stepHost(ctx, engine, config = {}) {
|
|
|
610
622
|
await ctx.storage.setAlarm(now + giveUpAfterMs);
|
|
611
623
|
const posted = request.posted;
|
|
612
624
|
if (posted !== null) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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) };
|
|
630
650
|
}
|
|
631
651
|
}
|
|
632
652
|
}
|
|
@@ -646,6 +666,7 @@ async function runStepLoop(token, runId, transport, execute, config) {
|
|
|
646
666
|
const rng = config.rng;
|
|
647
667
|
const executed = /* @__PURE__ */ new Map();
|
|
648
668
|
let posted = null;
|
|
669
|
+
let pollRetry = initRetry();
|
|
649
670
|
for (; ; ) {
|
|
650
671
|
if (now() >= config.deadlineMs) return { kind: "deadline_exceeded" };
|
|
651
672
|
let response;
|
|
@@ -662,6 +683,13 @@ async function runStepLoop(token, runId, transport, execute, config) {
|
|
|
662
683
|
}
|
|
663
684
|
}
|
|
664
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();
|
|
665
693
|
const step = response.step;
|
|
666
694
|
const cached = executed.get(step.callId);
|
|
667
695
|
const result = cached !== void 0 ? cached : await execute(step);
|