@smthrs/flow 1.0.0-rc.7 → 1.0.0-rc.9

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 (61) hide show
  1. package/README.md +3 -1
  2. package/dist/cjs/Deadline.d.ts +5 -0
  3. package/dist/cjs/Deadline.d.ts.map +1 -1
  4. package/dist/cjs/Deadline.js +9 -1
  5. package/dist/cjs/Deadline.js.map +2 -2
  6. package/dist/cjs/DurableClock.d.ts +9 -10
  7. package/dist/cjs/DurableClock.d.ts.map +1 -1
  8. package/dist/cjs/DurableClock.js +19 -2
  9. package/dist/cjs/DurableClock.js.map +2 -2
  10. package/dist/cjs/Flow/make.d.ts +2 -1
  11. package/dist/cjs/Flow/make.d.ts.map +1 -1
  12. package/dist/cjs/Flow/make.js +3 -0
  13. package/dist/cjs/Flow/make.js.map +2 -2
  14. package/dist/cjs/HumanTask.d.ts.map +1 -1
  15. package/dist/cjs/HumanTask.js +2 -2
  16. package/dist/cjs/HumanTask.js.map +2 -2
  17. package/dist/cjs/Poll.d.ts +3 -1
  18. package/dist/cjs/Poll.d.ts.map +1 -1
  19. package/dist/cjs/Poll.js +6 -2
  20. package/dist/cjs/Poll.js.map +2 -2
  21. package/dist/cjs/Sleep.d.ts.map +1 -1
  22. package/dist/cjs/Sleep.js +15 -7
  23. package/dist/cjs/Sleep.js.map +2 -2
  24. package/dist/esm/Deadline.d.ts +5 -0
  25. package/dist/esm/Deadline.d.ts.map +1 -1
  26. package/dist/esm/Deadline.js +13 -1
  27. package/dist/esm/Deadline.js.map +1 -1
  28. package/dist/esm/DurableClock.d.ts +9 -10
  29. package/dist/esm/DurableClock.d.ts.map +1 -1
  30. package/dist/esm/DurableClock.js +49 -2
  31. package/dist/esm/DurableClock.js.map +1 -1
  32. package/dist/esm/Flow/make.d.ts +2 -1
  33. package/dist/esm/Flow/make.d.ts.map +1 -1
  34. package/dist/esm/Flow/make.js +5 -0
  35. package/dist/esm/Flow/make.js.map +1 -1
  36. package/dist/esm/HumanTask.d.ts.map +1 -1
  37. package/dist/esm/HumanTask.js +5 -3
  38. package/dist/esm/HumanTask.js.map +1 -1
  39. package/dist/esm/Poll.d.ts +3 -1
  40. package/dist/esm/Poll.d.ts.map +1 -1
  41. package/dist/esm/Poll.js +10 -3
  42. package/dist/esm/Poll.js.map +1 -1
  43. package/dist/esm/Sleep.d.ts.map +1 -1
  44. package/dist/esm/Sleep.js +30 -4
  45. package/dist/esm/Sleep.js.map +1 -1
  46. package/docs/README.md +3 -1
  47. package/docs/api.md +21 -17
  48. package/docs/guides/ask-a-person.md +5 -5
  49. package/docs/guides/inspect-the-plan.md +1 -1
  50. package/docs/guides/poll-until-ready.md +3 -1
  51. package/docs/guides/wait-for-a-deadline.md +5 -5
  52. package/docs/installation.md +14 -9
  53. package/docs/quickstart.md +5 -1
  54. package/docs/reference/flow.md +9 -5
  55. package/package.json +7 -7
  56. package/src/Deadline.ts +17 -1
  57. package/src/DurableClock.ts +45 -2
  58. package/src/Flow/make.ts +7 -1
  59. package/src/HumanTask.ts +5 -3
  60. package/src/Poll.ts +10 -4
  61. package/src/Sleep.ts +33 -4
@@ -1 +1 @@
1
- {"version":3,"file":"Deadline.js","sourceRoot":"","sources":["../../src/Deadline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAwB,MAAM,kB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AAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The wall-clock bound one run of a flow settles by.\n *\n * A deadline counts from the run's FIRST start, which is journaled, so it\n * survives park, resume and process death: a restarted engine honors the\n * original deadline instead of starting a new one. A trampoline lineage is one\n * run, so its rounds share one deadline: the round that hands off stamps the\n * lineage's start and bound on the {@link module:Result.Handoff}, and the next\n * round runs under that stamp rather than starting a clock of its own. Like\n * `maxRounds`, the bound belongs to the lineage originator; a handoff target\n * cannot reset or replace it.\n *\n * The engine applies {@link bound} to every execution of a flow that declares\n * `Flow.make(tag, { deadline })`. A control plane applies it inside a run body\n * to bound a run by an approved envelope's deadline. Both settle an expired\n * run with the same {@link module:DeadlineExceeded.DeadlineExceeded} defect.\n *\n * @since 1.0.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as Action from \"./Action/index.ts\"\nimport * as DurableClock from \"./DurableClock.ts\"\nimport { DeadlineExceeded } from \"./Flow/DeadlineExceeded.ts\"\nimport { Handoff, type LineageDeadline } from \"./Flow/Result.ts\"\nimport { FlowInstance } from \"./FlowRuntime/FlowInstance.ts\"\nimport { FlowRuntime } from \"./FlowRuntime/FlowRuntime.ts\"\n\n/**\n * The execution's first start, journaled once.\n *\n * A sealed action's result is recorded with its attempt and replayed on every\n * later drive, so the origin a deadline counts from is the time the execution\n * first ran, on this engine or on the one that resumes it after a restart.\n */\nconst origin = Action.make({\n name: \"@smthrs/engine/deadline-origin\",\n tier: \"sealed\",\n success: Schema.Number,\n execute: Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n})\n\n/**\n * Starts the current execution's deadline: the lineage deadline this round\n * inherited from a handoff, or `deadline` counted from the execution's\n * journaled first start, or from `startedAtMs` when the host supplies a\n * durable start of its own. Answers `undefined` when neither applies, which is\n * an unbounded execution.\n *\n * **Details**\n *\n * The first start is a sealed action, so every later drive of the execution,\n * on this engine or one that resumes it after a restart, reads the same\n * origin. A durable clock is armed at the deadline so a parked execution is\n * driven again when it passes; the clock keeps the due time it was first armed\n * with, so arming it on every drive is idempotent.\n *\n * **Gotchas**\n *\n * Start at most one deadline per execution, before any other dispatch that a\n * replay must line up with: the origin and the clock are addressed by fixed\n * names within the execution.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const start = (options: {\n /** The flow the refusal names. */\n readonly flowName: string\n /** The bound; a positive finite duration. Absent means unbounded. */\n readonly deadline?: Duration.Input | undefined\n /**\n * Where the bound counts from, when the host already holds a durable\n * start of its own, such as the time a control plane accepted the run.\n * Absent, the execution's first start is journaled and read back.\n */\n readonly startedAtMs?: number | undefined\n}): Effect.Effect<LineageDeadline | undefined, never, FlowRuntime | FlowInstance | Crypto.Crypto> =>\n Effect.gen(function*() {\n const instance = yield* FlowInstance\n let lineage = instance.lineageDeadline\n if (lineage === undefined) {\n if (options.deadline === undefined) return undefined\n const deadlineMs = Option.match(Duration.fromInput(options.deadline), {\n onNone: () => Number.NaN,\n onSome: Duration.toMillis\n })\n if (!Number.isFinite(deadlineMs) || deadlineMs <= 0) {\n return yield* Effect.die(\n new RangeError(`Deadline.start: \"${options.flowName}\" deadline must be a positive finite duration`)\n )\n }\n lineage = { startedAtMs: options.startedAtMs ?? (yield* origin), deadlineMs }\n }\n const remaining = yield* remainingMs(lineage)\n if (remaining > 0) {\n yield* (yield* FlowRuntime).scheduleClock(instance.flow, {\n executionId: instance.executionId,\n clock: DurableClock.make({ name: \"@smthrs/engine/deadline\", duration: remaining })\n })\n }\n return lineage\n })\n\n/**\n * The whole milliseconds left before `deadline` passes, as the durable clock\n * row stores its due time; zero or less once it has passed.\n *\n * @category getters\n * @since 1.0.0\n */\nexport const remainingMs = (deadline: LineageDeadline): Effect.Effect<number> =>\n Effect.map(Clock.currentTimeMillis, (now) => Math.ceil(deadline.startedAtMs + deadline.deadlineMs - now))\n\n/**\n * Runs `body` within a started deadline.\n *\n * A body that starts at or past the deadline settles at once, and one that\n * starts before it races the time remaining in this fiber, so a running\n * execution is stopped too. Both settle with the same `DeadlineExceeded`\n * defect. The race is `raceFirst`: a body that parks exits first, so parking\n * still parks. A round that hands off stamps the deadline on its handoff, so\n * the next round of the lineage runs under it. An `undefined` deadline runs\n * `body` unbounded.\n *\n * @category combinators\n * @since 1.0.0\n */\nexport const within =\n (deadline: LineageDeadline | undefined, flowName: string) =>\n <A, E, R>(body: Effect.Effect<A, E, R>): Effect.Effect<A, E, R | FlowInstance> =>\n deadline === undefined ? body : Effect.gen(function*() {\n const instance = yield* FlowInstance\n const expired = new DeadlineExceeded({\n flowName,\n executionId: instance.executionId,\n deadlineMs: deadline.deadlineMs,\n startedAtMs: deadline.startedAtMs,\n message: `${flowName} execution ${instance.executionId} ran past its ${deadline.deadlineMs} ms deadline, ` +\n `counted from its start at ${new Date(deadline.startedAtMs).toISOString()}`\n })\n const remaining = yield* remainingMs(deadline)\n if (remaining <= 0) return yield* Effect.die(expired)\n const value = yield* Effect.raceFirst(body, Effect.andThen(Effect.sleep(remaining), Effect.die(expired)))\n const handoff = instance.handoff\n if (handoff !== undefined && handoff.deadline === undefined) {\n instance.handoff = new Handoff({\n flow: handoff.flow,\n payload: handoff.payload,\n ...(handoff.capabilityCeilings === undefined ? {} : { capabilityCeilings: handoff.capabilityCeilings }),\n deadline\n })\n }\n return value\n })\n\n/**\n * Bounds the current execution by `deadline`, counted from its journaled first\n * start, or by the lineage deadline this round inherited from a handoff:\n * {@link start}, then {@link within}.\n *\n * A round that inherited a lineage deadline runs under it whatever it\n * declares, so every round of a lineage expires at the originator's time. With\n * no inherited deadline and `deadline` absent, the body runs unbounded.\n *\n * @category combinators\n * @since 1.0.0\n */\nexport const bound = (options: {\n /** The flow the refusal names. */\n readonly flowName: string\n /** The bound; a positive finite duration. Absent means unbounded. */\n readonly deadline?: Duration.Input | undefined\n /** Where the bound counts from; see {@link start}. */\n readonly startedAtMs?: number | undefined\n}) =>\n<A, E, R>(\n body: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R | FlowRuntime | FlowInstance | Crypto.Crypto> =>\n Effect.flatMap(start(options), (deadline) => within(deadline, options.flowName)(body))\n"]}
1
+ {"version":3,"file":"Deadline.js","sourceRoot":"","sources":["../../src/Deadline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAwB,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC;IACzB,IAAI,EAAE,gCAAgC;IACtC,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;CAC9D,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM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AAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The wall-clock bound one run of a flow settles by.\n *\n * A deadline counts from the run's FIRST start, which is journaled, so it\n * survives park, resume and process death: a restarted engine honors the\n * original deadline instead of starting a new one. A trampoline lineage is one\n * run, so its rounds share one deadline: the round that hands off stamps the\n * lineage's start and bound on the {@link module:Result.Handoff}, and the next\n * round runs under that stamp rather than starting a clock of its own. Like\n * `maxRounds`, the bound belongs to the lineage originator; a handoff target\n * cannot reset or replace it.\n *\n * The engine applies {@link bound} to every execution of a flow that declares\n * `Flow.make(tag, { deadline })`. A control plane applies it inside a run body\n * to bound a run by an approved envelope's deadline. Both settle an expired\n * run with the same {@link module:DeadlineExceeded.DeadlineExceeded} defect.\n *\n * @since 1.0.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as Action from \"./Action/index.ts\"\nimport * as DurableClock from \"./DurableClock.ts\"\nimport { DeadlineExceeded } from \"./Flow/DeadlineExceeded.ts\"\nimport { Handoff, type LineageDeadline } from \"./Flow/Result.ts\"\nimport { FlowInstance } from \"./FlowRuntime/FlowInstance.ts\"\nimport { FlowRuntime } from \"./FlowRuntime/FlowRuntime.ts\"\n\n/**\n * The execution's first start, journaled once.\n *\n * A sealed action's result is recorded with its attempt and replayed on every\n * later drive, so the origin a deadline counts from is the time the execution\n * first ran, on this engine or on the one that resumes it after a restart.\n */\nconst origin = Action.make({\n name: \"@smthrs/engine/deadline-origin\",\n tier: \"sealed\",\n success: Schema.Number,\n execute: Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n})\n\n/**\n * Starts the current execution's deadline: the lineage deadline this round\n * inherited from a handoff, or `deadline` counted from the execution's\n * journaled first start, or from `startedAtMs` when the host supplies a\n * durable start of its own. Answers `undefined` when neither applies, which is\n * an unbounded execution.\n *\n * **Details**\n *\n * The first start is a sealed action, so every later drive of the execution,\n * on this engine or one that resumes it after a restart, reads the same\n * origin. A durable clock is armed at the deadline so a parked execution is\n * driven again when it passes; the clock keeps the due time it was first armed\n * with, so arming it on every drive is idempotent.\n *\n * **Gotchas**\n *\n * Start at most one deadline per execution, before any other dispatch that a\n * replay must line up with: the origin and the clock are addressed by fixed\n * names within the execution.\n *\n * A deadline that is not a positive finite duration, a `startedAtMs` that is\n * not finite, or a bound that would expire after epoch millisecond\n * `Number.MAX_SAFE_INTEGER` dies with a `RangeError`: a durable store records\n * the clock's due time as a safe integer.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const start = (options: {\n /** The flow the refusal names. */\n readonly flowName: string\n /** The bound; a positive finite duration. Absent means unbounded. */\n readonly deadline?: Duration.Input | undefined\n /**\n * Where the bound counts from, when the host already holds a durable\n * start of its own, such as the time a control plane accepted the run.\n * Absent, the execution's first start is journaled and read back.\n */\n readonly startedAtMs?: number | undefined\n}): Effect.Effect<LineageDeadline | undefined, never, FlowRuntime | FlowInstance | Crypto.Crypto> =>\n Effect.gen(function*() {\n const instance = yield* FlowInstance\n let lineage = instance.lineageDeadline\n if (lineage === undefined) {\n if (options.deadline === undefined) return undefined\n const deadlineMs = Option.match(Duration.fromInput(options.deadline), {\n onNone: () => Number.NaN,\n onSome: Duration.toMillis\n })\n if (!Number.isFinite(deadlineMs) || deadlineMs <= 0) {\n return yield* Effect.die(\n new RangeError(`Deadline.start: \"${options.flowName}\" deadline must be a positive finite duration`)\n )\n }\n const startedAtMs = options.startedAtMs ?? (yield* origin)\n // The clock armed below is due at `startedAtMs + deadlineMs`, and a\n // durable store records a due time as a safe integer.\n if (!Number.isFinite(startedAtMs) || startedAtMs + deadlineMs > Number.MAX_SAFE_INTEGER) {\n return yield* Effect.die(\n new RangeError(\n `Deadline.start: \"${options.flowName}\" deadline must expire by epoch millisecond ` +\n `${Number.MAX_SAFE_INTEGER}, and a ${deadlineMs} ms deadline from ${startedAtMs} does not`\n )\n )\n }\n lineage = { startedAtMs, deadlineMs }\n }\n const remaining = yield* remainingMs(lineage)\n if (remaining > 0) {\n yield* (yield* FlowRuntime).scheduleClock(instance.flow, {\n executionId: instance.executionId,\n clock: DurableClock.make({ name: \"@smthrs/engine/deadline\", duration: remaining })\n })\n }\n return lineage\n })\n\n/**\n * The whole milliseconds left before `deadline` passes, as the durable clock\n * row stores its due time; zero or less once it has passed.\n *\n * @category getters\n * @since 1.0.0\n */\nexport const remainingMs = (deadline: LineageDeadline): Effect.Effect<number> =>\n Effect.map(Clock.currentTimeMillis, (now) => Math.ceil(deadline.startedAtMs + deadline.deadlineMs - now))\n\n/**\n * Runs `body` within a started deadline.\n *\n * A body that starts at or past the deadline settles at once, and one that\n * starts before it races the time remaining in this fiber, so a running\n * execution is stopped too. Both settle with the same `DeadlineExceeded`\n * defect. The race is `raceFirst`: a body that parks exits first, so parking\n * still parks. A round that hands off stamps the deadline on its handoff, so\n * the next round of the lineage runs under it. An `undefined` deadline runs\n * `body` unbounded.\n *\n * @category combinators\n * @since 1.0.0\n */\nexport const within =\n (deadline: LineageDeadline | undefined, flowName: string) =>\n <A, E, R>(body: Effect.Effect<A, E, R>): Effect.Effect<A, E, R | FlowInstance> =>\n deadline === undefined ? body : Effect.gen(function*() {\n const instance = yield* FlowInstance\n const expired = new DeadlineExceeded({\n flowName,\n executionId: instance.executionId,\n deadlineMs: deadline.deadlineMs,\n startedAtMs: deadline.startedAtMs,\n message: `${flowName} execution ${instance.executionId} ran past its ${deadline.deadlineMs} ms deadline, ` +\n `counted from its start at ${new Date(deadline.startedAtMs).toISOString()}`\n })\n const remaining = yield* remainingMs(deadline)\n if (remaining <= 0) return yield* Effect.die(expired)\n const value = yield* Effect.raceFirst(body, Effect.andThen(Effect.sleep(remaining), Effect.die(expired)))\n const handoff = instance.handoff\n if (handoff !== undefined && handoff.deadline === undefined) {\n instance.handoff = new Handoff({\n flow: handoff.flow,\n payload: handoff.payload,\n ...(handoff.capabilityCeilings === undefined ? {} : { capabilityCeilings: handoff.capabilityCeilings }),\n deadline\n })\n }\n return value\n })\n\n/**\n * Bounds the current execution by `deadline`, counted from its journaled first\n * start, or by the lineage deadline this round inherited from a handoff:\n * {@link start}, then {@link within}.\n *\n * A round that inherited a lineage deadline runs under it whatever it\n * declares, so every round of a lineage expires at the originator's time. With\n * no inherited deadline and `deadline` absent, the body runs unbounded.\n *\n * @category combinators\n * @since 1.0.0\n */\nexport const bound = (options: {\n /** The flow the refusal names. */\n readonly flowName: string\n /** The bound; a positive finite duration. Absent means unbounded. */\n readonly deadline?: Duration.Input | undefined\n /** Where the bound counts from; see {@link start}. */\n readonly startedAtMs?: number | undefined\n}) =>\n<A, E, R>(\n body: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R | FlowRuntime | FlowInstance | Crypto.Crypto> =>\n Effect.flatMap(start(options), (deadline) => within(deadline, options.flowName)(body))\n"]}
@@ -1,13 +1,3 @@
1
- /**
2
- * Durable timers for flow sleeps.
3
- *
4
- * `make` creates a `DurableClock` with a name, duration, and deferred wake-up
5
- * signal. `sleep` ignores zero durations, runs short sleeps through an
6
- * in-memory action, and schedules longer sleeps through the `FlowRuntime`
7
- * before awaiting the durable deferred tied to the clock.
8
- *
9
- * @since 0.1.0
10
- */
11
1
  import type * as Crypto from "effect/Crypto";
12
2
  import * as Duration from "effect/Duration";
13
3
  import * as Effect from "effect/Effect";
@@ -32,6 +22,10 @@ export interface DurableClock {
32
22
  /**
33
23
  * Declares one durable clock after validating its finite nonnegative duration.
34
24
  *
25
+ * Throws a `RangeError` for a malformed, infinite or negative duration, or one
26
+ * longer than `Number.MAX_SAFE_INTEGER` milliseconds: a durable store records
27
+ * a clock's due time as a safe integer.
28
+ *
35
29
  * @category constructors
36
30
  * @since 0.1.0
37
31
  */
@@ -43,6 +37,11 @@ export declare const make: (options: {
43
37
  * Waits inside a flow, using an in-memory action for durations at or
44
38
  * below the threshold and scheduling a durable clock for longer durations.
45
39
  *
40
+ * Throws a `RangeError` for the same durations {@link make} refuses, and for
41
+ * a malformed, infinite or negative threshold. A durable sleep that would
42
+ * wake after epoch millisecond `Number.MAX_SAFE_INTEGER` dies with a
43
+ * `RangeError` instead of arming its clock.
44
+ *
46
45
  * @category sleeping
47
46
  * @since 0.1.0
48
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"DurableClock.d.ts","sourceRoot":"","sources":["../../src/DurableClock.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D,QAAA,MAAM,MAAM,8BAA8B,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAA;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAA;IACpC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,eAAe,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;CACvE;AA4BD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,SAAS;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAA;CAClC,KAAG,YAAwF,CAAA;AAE5F;;;;;;GAMG;AACH,eAAO,MAA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KAAK,CAAA;CAClC,KAAG,YAAwE,CAAA;AAE5E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,GAChB,SAAS;IACP,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAA;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;CACxD,KACA,MAAM,CAAC,MAAM,CACd,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,MAAM,GAAG,WAAW,GAAG,YAAY,CA2C3C,CAAA"}
@@ -1,4 +1,15 @@
1
1
  // Deep reviewed and polished by a human on 2026-08-10.
2
+ /**
3
+ * Durable timers for flow sleeps.
4
+ *
5
+ * `make` creates a `DurableClock` with a name, duration, and deferred wake-up
6
+ * signal. `sleep` ignores zero durations, runs short sleeps through an
7
+ * in-memory action, and schedules longer sleeps through the `FlowRuntime`
8
+ * before awaiting the durable deferred tied to the clock.
9
+ *
10
+ * @since 0.1.0
11
+ */
12
+ import * as Clock from "effect/Clock";
2
13
  import * as Duration from "effect/Duration";
3
14
  import * as Effect from "effect/Effect";
4
15
  import * as Option from "effect/Option";
@@ -25,6 +36,26 @@ const durationFromInput = (input, field) => {
25
36
  }
26
37
  return parsed.value;
27
38
  };
39
+ /**
40
+ * The latest due time a durable timer records, in epoch milliseconds: a store
41
+ * keeps a clock's due time as a safe integer.
42
+ *
43
+ * @private
44
+ */
45
+ const latestDueAtMs = Number.MAX_SAFE_INTEGER;
46
+ /**
47
+ * Parses a clock's own duration, which a store adds to the current time and
48
+ * records, so it is at most {@link latestDueAtMs} milliseconds.
49
+ *
50
+ * @private
51
+ */
52
+ const clockDuration = (input) => {
53
+ const duration = durationFromInput(input, "duration");
54
+ if (Duration.toMillis(duration) > latestDueAtMs) {
55
+ throw new RangeError(`DurableClock: "duration" must be at most ${latestDueAtMs} milliseconds.`);
56
+ }
57
+ return duration;
58
+ };
28
59
  const makeClock = (name, duration) => ({
29
60
  [TypeId]: TypeId,
30
61
  name,
@@ -34,20 +65,29 @@ const makeClock = (name, duration) => ({
34
65
  /**
35
66
  * Declares one durable clock after validating its finite nonnegative duration.
36
67
  *
68
+ * Throws a `RangeError` for a malformed, infinite or negative duration, or one
69
+ * longer than `Number.MAX_SAFE_INTEGER` milliseconds: a durable store records
70
+ * a clock's due time as a safe integer.
71
+ *
37
72
  * @category constructors
38
73
  * @since 0.1.0
39
74
  */
40
- export const make = (options) => makeClock(options.name, durationFromInput(options.duration, "duration"));
75
+ export const make = (options) => makeClock(options.name, clockDuration(options.duration));
41
76
  /**
42
77
  * Waits inside a flow, using an in-memory action for durations at or
43
78
  * below the threshold and scheduling a durable clock for longer durations.
44
79
  *
80
+ * Throws a `RangeError` for the same durations {@link make} refuses, and for
81
+ * a malformed, infinite or negative threshold. A durable sleep that would
82
+ * wake after epoch millisecond `Number.MAX_SAFE_INTEGER` dies with a
83
+ * `RangeError` instead of arming its clock.
84
+ *
45
85
  * @category sleeping
46
86
  * @since 0.1.0
47
87
  */
48
88
  export const sleep = (options) => {
49
89
  const name = options.name;
50
- const duration = durationFromInput(options.duration, "duration");
90
+ const duration = clockDuration(options.duration);
51
91
  const inMemoryThreshold = durationFromInput(options.inMemoryThreshold ?? defaultInMemoryThreshold, "inMemoryThreshold");
52
92
  // Untraced because durable sleeps are recursively resumed by the engine.
53
93
  return Effect.fnUntraced(function* () {
@@ -61,6 +101,13 @@ export const sleep = (options) => {
61
101
  execute: Effect.sleep(duration)
62
102
  });
63
103
  }
104
+ // A due time past the latest one a store records would fail the park
105
+ // write deep in the engine, so the sleep refuses it here by name.
106
+ const now = yield* Clock.currentTimeMillis;
107
+ if (now + Duration.toMillis(duration) > latestDueAtMs) {
108
+ return yield* Effect.die(new RangeError(`DurableClock: "${name}" would wake after epoch millisecond ${latestDueAtMs}, ` +
109
+ `the latest due time a durable timer records.`));
110
+ }
64
111
  const engine = yield* FlowRuntime;
65
112
  const instance = yield* FlowInstance;
66
113
  const clock = makeClock(name, duration);
@@ -1 +1 @@
1
- {"version":3,"file":"DurableClock.js","sourceRoot":"","sources":["../../src/DurableClock.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAcvD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D,MAAM,MAAM,GAAG,2BAA2B,CAAA;AAgB1C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAE,KAAa,EAAqB,EAAE;IACpF,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,UAAU,CAAC,kBAAkB,KAAK,yDAAyD,CAAC,CAAA;IACxG,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/E,MAAM,IAAI,UAAU,CAAC,kBAAkB,KAAK,yDAAyD,CAAC,CAAA;IACxG,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,QAA2B,EAAgB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AAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACvC,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE;YACzC,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,KAAK;SACN,CAAC,CAAA;QACF,OAAO,KAAK,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACrD,CAAC,CAAC,EAAE,CAAA;AACN,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Durable timers for flow sleeps.\n *\n * `make` creates a `DurableClock` with a name, duration, and deferred wake-up\n * signal. `sleep` ignores zero durations, runs short sleeps through an\n * in-memory action, and schedules longer sleeps through the `FlowRuntime`\n * before awaiting the durable deferred tied to the clock.\n *\n * @since 0.1.0\n */\n\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport type * as Schema from \"effect/Schema\"\nimport * as Action from \"./Action/index.ts\"\nimport * as DurableDeferred from \"./DurableDeferred.ts\"\nimport { FlowInstance } from \"./FlowRuntime/FlowInstance.ts\"\nimport { FlowRuntime } from \"./FlowRuntime/FlowRuntime.ts\"\n\nconst TypeId = \"@smthrs/flow/DurableClock\"\n\n/**\n * Represents a durable flow timer with a name, duration, and deferred\n * completed when the timer wakes.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface DurableClock {\n readonly [TypeId]: typeof TypeId\n readonly name: string\n readonly duration: Duration.Duration\n readonly deferred: DurableDeferred.DurableDeferred<typeof Schema.Void>\n}\n\n/**\n * Parses one author-supplied duration and requires it to be finite and\n * nonnegative. Invalid input throws `RangeError` so the authoring mistake is\n * caught at declaration time, matching `Flow.make` and `Poll.make`.\n *\n * @private\n */\nconst durationFromInput = (input: Duration.Input, field: string): Duration.Duration => {\n const parsed = Duration.fromInput(input)\n if (Option.isNone(parsed)) {\n throw new RangeError(`DurableClock: \"${field}\" must be a valid finite duration that is not negative.`)\n }\n const millis = Duration.toMillis(parsed.value)\n if (!Duration.isFinite(parsed.value) || !Number.isFinite(millis) || millis < 0) {\n throw new RangeError(`DurableClock: \"${field}\" must be a valid finite duration that is not negative.`)\n }\n return parsed.value\n}\n\nconst makeClock = (name: string, duration: Duration.Duration): DurableClock => ({\n [TypeId]: TypeId,\n name,\n duration,\n deferred: DurableDeferred.make(`DurableClock/${name}`)\n})\n\n/**\n * Declares one durable clock after validating its finite nonnegative duration.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (options: {\n readonly name: string\n readonly duration: Duration.Input\n}): DurableClock => makeClock(options.name, durationFromInput(options.duration, \"duration\"))\n\n/**\n * Waits inside a flow, using an in-memory action for durations at or\n * below the threshold and scheduling a durable clock for longer durations.\n *\n * @category sleeping\n * @since 0.1.0\n */\nexport const sleep = (\n options: {\n readonly name: string\n readonly duration: Duration.Input\n /**\n * If the duration is less than or equal to this threshold, the clock will\n * be executed in memory.\n *\n * @default 60 seconds\n */\n readonly inMemoryThreshold?: Duration.Input | undefined\n }\n): Effect.Effect<\n void,\n never,\n Crypto.Crypto | FlowRuntime | FlowInstance\n> => {\n const name = options.name\n const duration = durationFromInput(options.duration, \"duration\")\n const inMemoryThreshold = durationFromInput(\n options.inMemoryThreshold ?? defaultInMemoryThreshold,\n \"inMemoryThreshold\"\n )\n\n // Untraced because durable sleeps are recursively resumed by the engine.\n return Effect.fnUntraced(function*() {\n if (Duration.isZero(duration)) {\n return\n }\n\n if (Duration.isLessThanOrEqualTo(duration, inMemoryThreshold)) {\n return yield* Action.make({\n name: `DurableClock/${name}`,\n tier: \"sealed\",\n execute: Effect.sleep(duration)\n })\n }\n\n const engine = yield* FlowRuntime\n const instance = yield* FlowInstance\n const clock = makeClock(name, duration)\n yield* engine.scheduleClock(instance.flow, {\n executionId: instance.executionId,\n clock\n })\n return yield* DurableDeferred.await(clock.deferred)\n })()\n}\n\nconst defaultInMemoryThreshold = Duration.seconds(60)\n"]}
1
+ {"version":3,"file":"DurableClock.js","sourceRoot":"","sources":["../../src/DurableClock.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;;;;;;GASG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D,MAAM,MAAM,GAAG,2BAA2B,CAAA;AAgB1C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAE,KAAa,EAAqB,EAAE;IACpF,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,UAAU,CAAC,kBAAkB,KAAK,yDAAyD,CAAC,CAAA;IACxG,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/E,MAAM,IAAI,UAAU,CAAC,kBAAkB,KAAK,yDAAyD,CAAC,CAAA;IACxG,CAAC;IACD,OAAO,MA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/**\n * Durable timers for flow sleeps.\n *\n * `make` creates a `DurableClock` with a name, duration, and deferred wake-up\n * signal. `sleep` ignores zero durations, runs short sleeps through an\n * in-memory action, and schedules longer sleeps through the `FlowRuntime`\n * before awaiting the durable deferred tied to the clock.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport type * as Schema from \"effect/Schema\"\nimport * as Action from \"./Action/index.ts\"\nimport * as DurableDeferred from \"./DurableDeferred.ts\"\nimport { FlowInstance } from \"./FlowRuntime/FlowInstance.ts\"\nimport { FlowRuntime } from \"./FlowRuntime/FlowRuntime.ts\"\n\nconst TypeId = \"@smthrs/flow/DurableClock\"\n\n/**\n * Represents a durable flow timer with a name, duration, and deferred\n * completed when the timer wakes.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface DurableClock {\n readonly [TypeId]: typeof TypeId\n readonly name: string\n readonly duration: Duration.Duration\n readonly deferred: DurableDeferred.DurableDeferred<typeof Schema.Void>\n}\n\n/**\n * Parses one author-supplied duration and requires it to be finite and\n * nonnegative. Invalid input throws `RangeError` so the authoring mistake is\n * caught at declaration time, matching `Flow.make` and `Poll.make`.\n *\n * @private\n */\nconst durationFromInput = (input: Duration.Input, field: string): Duration.Duration => {\n const parsed = Duration.fromInput(input)\n if (Option.isNone(parsed)) {\n throw new RangeError(`DurableClock: \"${field}\" must be a valid finite duration that is not negative.`)\n }\n const millis = Duration.toMillis(parsed.value)\n if (!Duration.isFinite(parsed.value) || !Number.isFinite(millis) || millis < 0) {\n throw new RangeError(`DurableClock: \"${field}\" must be a valid finite duration that is not negative.`)\n }\n return parsed.value\n}\n\n/**\n * The latest due time a durable timer records, in epoch milliseconds: a store\n * keeps a clock's due time as a safe integer.\n *\n * @private\n */\nconst latestDueAtMs = Number.MAX_SAFE_INTEGER\n\n/**\n * Parses a clock's own duration, which a store adds to the current time and\n * records, so it is at most {@link latestDueAtMs} milliseconds.\n *\n * @private\n */\nconst clockDuration = (input: Duration.Input): Duration.Duration => {\n const duration = durationFromInput(input, \"duration\")\n if (Duration.toMillis(duration) > latestDueAtMs) {\n throw new RangeError(`DurableClock: \"duration\" must be at most ${latestDueAtMs} milliseconds.`)\n }\n return duration\n}\n\nconst makeClock = (name: string, duration: Duration.Duration): DurableClock => ({\n [TypeId]: TypeId,\n name,\n duration,\n deferred: DurableDeferred.make(`DurableClock/${name}`)\n})\n\n/**\n * Declares one durable clock after validating its finite nonnegative duration.\n *\n * Throws a `RangeError` for a malformed, infinite or negative duration, or one\n * longer than `Number.MAX_SAFE_INTEGER` milliseconds: a durable store records\n * a clock's due time as a safe integer.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (options: {\n readonly name: string\n readonly duration: Duration.Input\n}): DurableClock => makeClock(options.name, clockDuration(options.duration))\n\n/**\n * Waits inside a flow, using an in-memory action for durations at or\n * below the threshold and scheduling a durable clock for longer durations.\n *\n * Throws a `RangeError` for the same durations {@link make} refuses, and for\n * a malformed, infinite or negative threshold. A durable sleep that would\n * wake after epoch millisecond `Number.MAX_SAFE_INTEGER` dies with a\n * `RangeError` instead of arming its clock.\n *\n * @category sleeping\n * @since 0.1.0\n */\nexport const sleep = (\n options: {\n readonly name: string\n readonly duration: Duration.Input\n /**\n * If the duration is less than or equal to this threshold, the clock will\n * be executed in memory.\n *\n * @default 60 seconds\n */\n readonly inMemoryThreshold?: Duration.Input | undefined\n }\n): Effect.Effect<\n void,\n never,\n Crypto.Crypto | FlowRuntime | FlowInstance\n> => {\n const name = options.name\n const duration = clockDuration(options.duration)\n const inMemoryThreshold = durationFromInput(\n options.inMemoryThreshold ?? defaultInMemoryThreshold,\n \"inMemoryThreshold\"\n )\n\n // Untraced because durable sleeps are recursively resumed by the engine.\n return Effect.fnUntraced(function*() {\n if (Duration.isZero(duration)) {\n return\n }\n\n if (Duration.isLessThanOrEqualTo(duration, inMemoryThreshold)) {\n return yield* Action.make({\n name: `DurableClock/${name}`,\n tier: \"sealed\",\n execute: Effect.sleep(duration)\n })\n }\n\n // A due time past the latest one a store records would fail the park\n // write deep in the engine, so the sleep refuses it here by name.\n const now = yield* Clock.currentTimeMillis\n if (now + Duration.toMillis(duration) > latestDueAtMs) {\n return yield* Effect.die(\n new RangeError(\n `DurableClock: \"${name}\" would wake after epoch millisecond ${latestDueAtMs}, ` +\n `the latest due time a durable timer records.`\n )\n )\n }\n const engine = yield* FlowRuntime\n const instance = yield* FlowInstance\n const clock = makeClock(name, duration)\n yield* engine.scheduleClock(instance.flow, {\n executionId: instance.executionId,\n clock\n })\n return yield* DurableDeferred.await(clock.deferred)\n })()\n}\n\nconst defaultInMemoryThreshold = Duration.seconds(60)\n"]}
@@ -78,7 +78,8 @@ interface MakeOptions<Payload extends Schema.Struct.Fields | AnyStructSchema, Su
78
78
  readonly maxRounds?: number | undefined;
79
79
  /**
80
80
  * How long one execution may take, counted from its journaled first start.
81
- * A positive finite duration; see {@link Flow.deadline}.
81
+ * A positive finite duration of at most `Number.MAX_SAFE_INTEGER`
82
+ * milliseconds; see {@link Flow.deadline}.
82
83
  */
83
84
  readonly deadline?: Duration.Input | undefined;
84
85
  readonly annotations?: Context.Context<never>;
@@ -1 +1 @@
1
- {"version":3,"file":"make.d.ts","sourceRoot":"","sources":["../../../src/Flow/make.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAG3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAKvC,OAAO,KAAK,KAAK,WAAW,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,WA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line) <= 0)) {
57
57
  throw new RangeError(`Flow.make: "${tag}" deadline must be a positive finite duration`);
58
58
  }
59
+ // The durable clock that enforces a deadline is due at its start plus the
60
+ // deadline, and a store records that due time as a safe integer.
61
+ if (deadline !== undefined && Duration.toMillis(deadline) > Number.MAX_SAFE_INTEGER) {
62
+ throw new RangeError(`Flow.make: "${tag}" deadline must be at most ${Number.MAX_SAFE_INTEGER} ms`);
63
+ }
59
64
  // Captured here, where the stack still names the author's file, and carried
60
65
  // as a non-enumerable property so no digest can see it
61
66
  // (`internal/DeclarationSite.ts`).
@@ -1 +1 @@
1
- {"version":3,"file":"make.js","sourceRoot":"","sources":["../../../src/Flow/make.ts"],"names":[],"mappings":"AAAA,uDAAuD;AASvD,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAEzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,KAAK,eAAe,MAAM,gCAAgC,CAAA;AAGjE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AA4GpC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAgB,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAE5F;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,IAAI,GA2Bb,CAOF,GAAQ,EACR,OAIC,EACI,EAAE;IACP,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,M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,EAAE,MAAM,CAAC,qBAAqB,IAAI,IAAI,EAAE,EACpF,CAAC,OAAyC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAgB,CAAC,CAC7E,CAAA;IACD,OAAO,eAAe,CAAC,QAAQ,CAC7B,SAAS,CAA0D;QACjE,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,aAAa;QACb,aAAa;QACb,WAAW;QACX,WAAW;QACX,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM;QACN,IAAI,EAAE,IAE+D;QACrE,cAAc,EAAE,OAAO,CAAC,cAAqB;QAC7C,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ;KACT,CAAC,EACF,IAAI,CACL,CAAA;AACH,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Constructs executable flow declarations from schema and policy data.\n *\n * @since 0.1.0\n */\n\nimport type * as Effects from \"@smthrs/plan/Effects\"\nimport * as Node from \"@smthrs/plan/Node\"\nimport type * as Context from \"effect/Context\"\nimport * as Duration from \"effect/Duration\"\nimport * as Option from \"effect/Option\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport type { Declared } from \"../Action/Action.ts\"\nimport * as Action from \"../Action/make.ts\"\nimport { lowerDeclarations } from \"../internal/Declarations.ts\"\nimport * as DeclarationSite from \"../internal/DeclarationSite.ts\"\nimport type * as RetryPolicy from \"../RetryPolicy.ts\"\nimport type { Any, AnyStructSchema, BodySuccess, DeclarationMetadata, Flow, PromptFlow } from \"./Flow.ts\"\nimport { makeProto } from \"./internal.ts\"\nimport { TypeId } from \"./TypeId.ts\"\n\n/**\n * The declaration data every flow takes beside its body.\n *\n * @private\n */\ninterface MakeOptions<\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top\n> extends DeclarationMetadata {\n readonly payload: Payload\n /**\n * Native declaration whose source location this reconstructed flow retains.\n * A source with no recorded location preserves that absence. This affects\n * diagnostics only, never identity; the new flow keeps its own body and calls.\n */\n readonly declaredFrom?: object | undefined\n /**\n * One sentence saying what this flow does, read by a catalog that lists it.\n */\n readonly description?: string | undefined\n /**\n * The capability ceiling this flow's body runs under, as string literals.\n *\n * It is the same ceiling {@link Annotations.Capabilities} carries, and\n * declaring it here is what makes it READABLE without importing the module:\n * a catalog projects a discovered flow's authority from the declaration, and\n * an annotation built at run time is invisible to that projection.\n */\n readonly capabilities?: ReadonlyArray<string> | undefined\n /**\n * The effect envelope this flow's body runs under, as a literal.\n *\n * It is the same declaration {@link Annotations.EffectEnvelope} carries, and\n * declaring it here is what makes it READABLE without importing the module,\n * exactly as `capabilities` is: a catalog projects a discovered flow's\n * authority from the source text of this literal, and an annotation built at\n * run time is invisible to that projection.\n *\n * {@link module:Graph.build} refuses a composition beneath this flow that\n * reads or writes outside the envelope, loosens `hermetic` to `expected`, or\n * raises the tier. `reads` and `writes` are normalized to sorted,\n * duplicate-free arrays, so two spellings of one envelope are one envelope.\n */\n readonly effects?: Effects.MakeOptions | undefined\n /**\n * Whether a catalog may offer this flow to a model, as a literal. Defaults\n * to `true`.\n *\n * It is the same statement {@link Annotations.ModelInvocable} carries, and\n * declaring it here is what makes it READABLE without importing the module,\n * exactly as `capabilities` and `effects` are: a registry projects a\n * discovered flow's visibility from the source text of this literal onto the\n * descriptor it lists, and an annotation built at run time is invisible to\n * that projection.\n *\n * Declare `false` when the actions this flow's body calls are implemented by\n * one host only. The file is discoverable wherever it sits, so a catalog\n * elsewhere would otherwise teach an agent a call with no implementation to\n * reach.\n */\n readonly modelInvocable?: boolean | undefined\n readonly idempotencyKey?:\n | ((\n payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload>\n : Payload[\"Type\"]\n ) => string)\n | undefined\n readonly success?: Success\n readonly error?: Error\n readonly suspendedRetryPolicy?: RetryPolicy.RetryPolicy | undefined\n /**\n * The round budget a trampoline lineage started from this flow runs under.\n */\n readonly maxRounds?: number | undefined\n /**\n * How long one execution may take, counted from its journaled first start.\n * A positive finite duration; see {@link Flow.deadline}.\n */\n readonly deadline?: Duration.Input | undefined\n readonly annotations?: Context.Context<never>\n}\n\n/**\n * The pure plan-time body, typed with the decoded payload.\n *\n * @private\n */\ntype Body<\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top,\n Requires\n> = (\n payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload> : Payload[\"Type\"]\n) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>\n\n/**\n * The payload schema a declaration's `payload` field stands for.\n *\n * @private\n */\ntype PayloadSchemaOf<Payload extends Schema.Struct.Fields | AnyStructSchema> = Payload extends Schema.Struct.Fields\n ? Schema.Struct<Payload>\n : Payload\n\n/**\n * Whether a value is a flow this package made.\n *\n * The check is the runtime type id, not the shape: a host that loads a module\n * and finds a default export has to decide whether it holds a flow before it\n * reads anything off it, and a structural guess would accept a look-alike from\n * another flow model.\n *\n * @category predicates\n * @since 0.1.0\n */\nexport const isFlow = (value: unknown): value is Any => Predicate.hasProperty(value, TypeId)\n\n/**\n * Creates a durable flow with one plan-time body or a typed prompt renderer.\n * A prompt lowers to one ordinary action implemented by the host; neither\n * construction nor planning renders it. Model metadata is interpreted by the\n * host and adds no execution model to this package.\n *\n * Invocation IDs are caller-selected or opt-in deterministic IDs derived\n * from the flow tag and idempotency key.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make: {\n <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never,\n Requires = never\n >(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly body: Body<Payload, Success, Error, Requires>\n readonly prompt?: never\n }\n ): Flow<Tag, PayloadSchemaOf<Payload>, Success, Error, Requires>\n <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never\n >(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly prompt: (payload: PayloadSchemaOf<Payload>[\"Type\"]) => string\n readonly body?: never\n readonly implementationVersion?: string | undefined\n }\n ): PromptFlow<Tag, PayloadSchemaOf<Payload>, Success, Error>\n} = <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never,\n Requires = never\n>(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly body?: Body<Payload, Success, Error, Requires> | undefined\n readonly prompt?: ((payload: PayloadSchemaOf<Payload>[\"Type\"]) => string) | undefined\n readonly implementationVersion?: string | undefined\n }\n): any => {\n if (typeof tag !== \"string\" || tag.trim().length === 0) {\n throw new TypeError(\"Flow.make: tag must be a non-empty string\")\n }\n if (\n (options.body === undefined && typeof options.prompt !== \"function\") ||\n (options.prompt === undefined && typeof options.body !== \"function\") ||\n (options.body !== undefined && options.prompt !== undefined)\n ) {\n throw new TypeError(`Flow.make: \"${tag}\" must declare exactly one function: body or prompt`)\n }\n // Invalid static configuration is a programmer error thrown at construction,\n // the same contract as effect's own `ExecutionPlan.make` (which throws on\n // `attempts <= 0`); `RangeError` matches effect's range-violation throws.\n if (\n options.maxRounds !== undefined &&\n (!Number.isSafeInteger(options.maxRounds) || options.maxRounds < 1)\n ) {\n throw new RangeError(`Flow.make: \"${tag}\" maxRounds must be a positive safe integer`)\n }\n const deadline = options.deadline === undefined\n ? undefined\n : Option.getOrUndefined(Duration.fromInput(options.deadline))\n if (\n options.deadline !== undefined &&\n (deadline === undefined || !Duration.isFinite(deadline) || Duration.toMillis(deadline) <= 0)\n ) {\n throw new RangeError(`Flow.make: \"${tag}\" deadline must be a positive finite duration`)\n }\n // Captured here, where the stack still names the author's file, and carried\n // as a non-enumerable property so no digest can see it\n // (`internal/DeclarationSite.ts`).\n const site = options.declaredFrom === undefined\n ? DeclarationSite.capture()\n : DeclarationSite.declaredAt(options.declaredFrom)\n const payloadSchema = (Schema.isSchema(options.payload)\n ? options.payload\n : Schema.Struct(options.payload as any)) as PayloadSchemaOf<Payload>\n const successSchema = options.success ?? (Schema.Void as unknown as Success)\n const errorSchema = options.error ?? (Schema.Never as unknown as Error)\n const annotations = lowerDeclarations(options)\n const action = options.prompt === undefined ? undefined : Action.make(`${tag}/prompt`, {\n payload: payloadSchema,\n success: successSchema,\n error: errorSchema,\n capabilities: options.capabilities,\n effects: options.effects,\n annotations,\n tier: options.effects?.tier ?? \"irreversible\",\n implementationVersion: options.implementationVersion,\n declaredFrom: options.declaredFrom\n }) as unknown as Declared<`${Tag}/prompt`, PayloadSchemaOf<Payload>, Success, Error>\n // The adapter only describes one dispatch. Prompt rendering belongs to the\n // host implementation and its reviewed source/implementation identity.\n const body = action === undefined ? options.body : Node.capture(\n { action: action.name, implementationVersion: action.implementationVersion ?? null },\n (payload: PayloadSchemaOf<Payload>[\"Type\"]) => action.call(payload as never)\n )\n return DeclarationSite.annotate(\n makeProto<Tag, PayloadSchemaOf<Payload>, Success, Error, Requires>({\n _tag: tag,\n description: options.description,\n payloadSchema,\n successSchema,\n errorSchema,\n annotations,\n model: options.model,\n effort: options.effort,\n system: options.system,\n chat: options.chat,\n flows: options.flows,\n prompt: options.prompt,\n action,\n body: body as (\n payload: PayloadSchemaOf<Payload>[\"Type\"]\n ) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>,\n idempotencyKey: options.idempotencyKey as any,\n suspendedRetryPolicy: options.suspendedRetryPolicy,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AE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAgB,CAAC,CAC7E,CAAA;IACD,OAAO,eAAe,CAAC,QAAQ,CAC7B,SAAS,CAA0D;QACjE,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,aAAa;QACb,aAAa;QACb,WAAW;QACX,WAAW;QACX,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM;QACN,IAAI,EAAE,IAE+D;QACrE,cAAc,EAAE,OAAO,CAAC,cAAqB;QAC7C,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ;KACT,CAAC,EACF,IAAI,CACL,CAAA;AACH,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Constructs executable flow declarations from schema and policy data.\n *\n * @since 0.1.0\n */\n\nimport type * as Effects from \"@smthrs/plan/Effects\"\nimport * as Node from \"@smthrs/plan/Node\"\nimport type * as Context from \"effect/Context\"\nimport * as Duration from \"effect/Duration\"\nimport * as Option from \"effect/Option\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport type { Declared } from \"../Action/Action.ts\"\nimport * as Action from \"../Action/make.ts\"\nimport { lowerDeclarations } from \"../internal/Declarations.ts\"\nimport * as DeclarationSite from \"../internal/DeclarationSite.ts\"\nimport type * as RetryPolicy from \"../RetryPolicy.ts\"\nimport type { Any, AnyStructSchema, BodySuccess, DeclarationMetadata, Flow, PromptFlow } from \"./Flow.ts\"\nimport { makeProto } from \"./internal.ts\"\nimport { TypeId } from \"./TypeId.ts\"\n\n/**\n * The declaration data every flow takes beside its body.\n *\n * @private\n */\ninterface MakeOptions<\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top\n> extends DeclarationMetadata {\n readonly payload: Payload\n /**\n * Native declaration whose source location this reconstructed flow retains.\n * A source with no recorded location preserves that absence. This affects\n * diagnostics only, never identity; the new flow keeps its own body and calls.\n */\n readonly declaredFrom?: object | undefined\n /**\n * One sentence saying what this flow does, read by a catalog that lists it.\n */\n readonly description?: string | undefined\n /**\n * The capability ceiling this flow's body runs under, as string literals.\n *\n * It is the same ceiling {@link Annotations.Capabilities} carries, and\n * declaring it here is what makes it READABLE without importing the module:\n * a catalog projects a discovered flow's authority from the declaration, and\n * an annotation built at run time is invisible to that projection.\n */\n readonly capabilities?: ReadonlyArray<string> | undefined\n /**\n * The effect envelope this flow's body runs under, as a literal.\n *\n * It is the same declaration {@link Annotations.EffectEnvelope} carries, and\n * declaring it here is what makes it READABLE without importing the module,\n * exactly as `capabilities` is: a catalog projects a discovered flow's\n * authority from the source text of this literal, and an annotation built at\n * run time is invisible to that projection.\n *\n * {@link module:Graph.build} refuses a composition beneath this flow that\n * reads or writes outside the envelope, loosens `hermetic` to `expected`, or\n * raises the tier. `reads` and `writes` are normalized to sorted,\n * duplicate-free arrays, so two spellings of one envelope are one envelope.\n */\n readonly effects?: Effects.MakeOptions | undefined\n /**\n * Whether a catalog may offer this flow to a model, as a literal. Defaults\n * to `true`.\n *\n * It is the same statement {@link Annotations.ModelInvocable} carries, and\n * declaring it here is what makes it READABLE without importing the module,\n * exactly as `capabilities` and `effects` are: a registry projects a\n * discovered flow's visibility from the source text of this literal onto the\n * descriptor it lists, and an annotation built at run time is invisible to\n * that projection.\n *\n * Declare `false` when the actions this flow's body calls are implemented by\n * one host only. The file is discoverable wherever it sits, so a catalog\n * elsewhere would otherwise teach an agent a call with no implementation to\n * reach.\n */\n readonly modelInvocable?: boolean | undefined\n readonly idempotencyKey?:\n | ((\n payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload>\n : Payload[\"Type\"]\n ) => string)\n | undefined\n readonly success?: Success\n readonly error?: Error\n readonly suspendedRetryPolicy?: RetryPolicy.RetryPolicy | undefined\n /**\n * The round budget a trampoline lineage started from this flow runs under.\n */\n readonly maxRounds?: number | undefined\n /**\n * How long one execution may take, counted from its journaled first start.\n * A positive finite duration of at most `Number.MAX_SAFE_INTEGER`\n * milliseconds; see {@link Flow.deadline}.\n */\n readonly deadline?: Duration.Input | undefined\n readonly annotations?: Context.Context<never>\n}\n\n/**\n * The pure plan-time body, typed with the decoded payload.\n *\n * @private\n */\ntype Body<\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top,\n Requires\n> = (\n payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload> : Payload[\"Type\"]\n) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>\n\n/**\n * The payload schema a declaration's `payload` field stands for.\n *\n * @private\n */\ntype PayloadSchemaOf<Payload extends Schema.Struct.Fields | AnyStructSchema> = Payload extends Schema.Struct.Fields\n ? Schema.Struct<Payload>\n : Payload\n\n/**\n * Whether a value is a flow this package made.\n *\n * The check is the runtime type id, not the shape: a host that loads a module\n * and finds a default export has to decide whether it holds a flow before it\n * reads anything off it, and a structural guess would accept a look-alike from\n * another flow model.\n *\n * @category predicates\n * @since 0.1.0\n */\nexport const isFlow = (value: unknown): value is Any => Predicate.hasProperty(value, TypeId)\n\n/**\n * Creates a durable flow with one plan-time body or a typed prompt renderer.\n * A prompt lowers to one ordinary action implemented by the host; neither\n * construction nor planning renders it. Model metadata is interpreted by the\n * host and adds no execution model to this package.\n *\n * Invocation IDs are caller-selected or opt-in deterministic IDs derived\n * from the flow tag and idempotency key.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make: {\n <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never,\n Requires = never\n >(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly body: Body<Payload, Success, Error, Requires>\n readonly prompt?: never\n }\n ): Flow<Tag, PayloadSchemaOf<Payload>, Success, Error, Requires>\n <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never\n >(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly prompt: (payload: PayloadSchemaOf<Payload>[\"Type\"]) => string\n readonly body?: never\n readonly implementationVersion?: string | undefined\n }\n ): PromptFlow<Tag, PayloadSchemaOf<Payload>, Success, Error>\n} = <\n const Tag extends string,\n Payload extends Schema.Struct.Fields | AnyStructSchema,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never,\n Requires = never\n>(\n tag: Tag,\n options: MakeOptions<Payload, Success, Error> & {\n readonly body?: Body<Payload, Success, Error, Requires> | undefined\n readonly prompt?: ((payload: PayloadSchemaOf<Payload>[\"Type\"]) => string) | undefined\n readonly implementationVersion?: string | undefined\n }\n): any => {\n if (typeof tag !== \"string\" || tag.trim().length === 0) {\n throw new TypeError(\"Flow.make: tag must be a non-empty string\")\n }\n if (\n (options.body === undefined && typeof options.prompt !== \"function\") ||\n (options.prompt === undefined && typeof options.body !== \"function\") ||\n (options.body !== undefined && options.prompt !== undefined)\n ) {\n throw new TypeError(`Flow.make: \"${tag}\" must declare exactly one function: body or prompt`)\n }\n // Invalid static configuration is a programmer error thrown at construction,\n // the same contract as effect's own `ExecutionPlan.make` (which throws on\n // `attempts <= 0`); `RangeError` matches effect's range-violation throws.\n if (\n options.maxRounds !== undefined &&\n (!Number.isSafeInteger(options.maxRounds) || options.maxRounds < 1)\n ) {\n throw new RangeError(`Flow.make: \"${tag}\" maxRounds must be a positive safe integer`)\n }\n const deadline = options.deadline === undefined\n ? undefined\n : Option.getOrUndefined(Duration.fromInput(options.deadline))\n if (\n options.deadline !== undefined &&\n (deadline === undefined || !Duration.isFinite(deadline) || Duration.toMillis(deadline) <= 0)\n ) {\n throw new RangeError(`Flow.make: \"${tag}\" deadline must be a positive finite duration`)\n }\n // The durable clock that enforces a deadline is due at its start plus the\n // deadline, and a store records that due time as a safe integer.\n if (deadline !== undefined && Duration.toMillis(deadline) > Number.MAX_SAFE_INTEGER) {\n throw new RangeError(`Flow.make: \"${tag}\" deadline must be at most ${Number.MAX_SAFE_INTEGER} ms`)\n }\n // Captured here, where the stack still names the author's file, and carried\n // as a non-enumerable property so no digest can see it\n // (`internal/DeclarationSite.ts`).\n const site = options.declaredFrom === undefined\n ? DeclarationSite.capture()\n : DeclarationSite.declaredAt(options.declaredFrom)\n const payloadSchema = (Schema.isSchema(options.payload)\n ? options.payload\n : Schema.Struct(options.payload as any)) as PayloadSchemaOf<Payload>\n const successSchema = options.success ?? (Schema.Void as unknown as Success)\n const errorSchema = options.error ?? (Schema.Never as unknown as Error)\n const annotations = lowerDeclarations(options)\n const action = options.prompt === undefined ? undefined : Action.make(`${tag}/prompt`, {\n payload: payloadSchema,\n success: successSchema,\n error: errorSchema,\n capabilities: options.capabilities,\n effects: options.effects,\n annotations,\n tier: options.effects?.tier ?? \"irreversible\",\n implementationVersion: options.implementationVersion,\n declaredFrom: options.declaredFrom\n }) as unknown as Declared<`${Tag}/prompt`, PayloadSchemaOf<Payload>, Success, Error>\n // The adapter only describes one dispatch. Prompt rendering belongs to the\n // host implementation and its reviewed source/implementation identity.\n const body = action === undefined ? options.body : Node.capture(\n { action: action.name, implementationVersion: action.implementationVersion ?? null },\n (payload: PayloadSchemaOf<Payload>[\"Type\"]) => action.call(payload as never)\n )\n return DeclarationSite.annotate(\n makeProto<Tag, PayloadSchemaOf<Payload>, Success, Error, Requires>({\n _tag: tag,\n description: options.description,\n payloadSchema,\n successSchema,\n errorSchema,\n annotations,\n model: options.model,\n effort: options.effort,\n system: options.system,\n chat: options.chat,\n flows: options.flows,\n prompt: options.prompt,\n action,\n body: body as (\n payload: PayloadSchemaOf<Payload>[\"Type\"]\n ) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>,\n idempotencyKey: options.idempotencyKey as any,\n suspendedRetryPolicy: options.suspendedRetryPolicy,\n maxRounds: options.maxRounds,\n deadline\n }),\n site\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"HumanTask.d.ts","sourceRoot":"","sources":["../../src/HumanTask.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAM1D;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;AAExD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAK9E,CAAA;;;;;;;;AAEF;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,eAAgB,SAAQ,oBASpC;CAAG;;;;;AAEJ;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,uBAQvC;CAAG;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,GAAG,sBAAsB,CAAA;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC;;;;;GAKG;AAC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;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,MAAM,GAChB,CAAC,SAAS,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MACtD,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAC/B,CAAA"}
@@ -537,10 +537,12 @@ const deadlineOf = (payload) => {
537
537
  const timeoutMs = payload.timeoutMs;
538
538
  if (timeoutMs === undefined)
539
539
  return Effect.succeed(undefined);
540
- return Number.isFinite(timeoutMs) && timeoutMs >= 0
540
+ // The timeout clock is due at its start plus the deadline, and a durable
541
+ // store records that due time as a safe integer.
542
+ return Number.isFinite(timeoutMs) && timeoutMs >= 0 && timeoutMs <= Number.MAX_SAFE_INTEGER
541
543
  ? Effect.succeed(Duration.millis(timeoutMs))
542
- : Effect.fail(failed(payload, "request_invalid", 0, [], `${tag} was called with timeoutMs ${timeoutMs}. A deadline is a finite number of ` +
543
- "milliseconds that is not negative; the question would be over before it was asked, or " +
544
+ : Effect.fail(failed(payload, "request_invalid", 0, [], `${tag} was called with timeoutMs ${timeoutMs}. A deadline is a number of milliseconds ` +
545
+ `from 0 to ${Number.MAX_SAFE_INTEGER}; the question would be over before it was asked, or ` +
544
546
  "never over at all."));
545
547
  };
546
548
  /**