@smthrs/flow 1.0.0-rc.4 → 1.0.0-rc.6

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 (49) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/README.md +4 -4
  3. package/dist/cjs/DurableDeferred.js +3 -3
  4. package/dist/cjs/DurableDeferred.js.map +2 -2
  5. package/dist/cjs/DurableQueue.d.ts +1 -1
  6. package/dist/cjs/DurableQueue.d.ts.map +1 -1
  7. package/dist/cjs/DurableQueue.js +2 -2
  8. package/dist/cjs/DurableQueue.js.map +2 -2
  9. package/dist/cjs/Flow/ExecutionIds.js +1 -1
  10. package/dist/cjs/Flow/ExecutionIds.js.map +2 -2
  11. package/dist/cjs/Flow/Result.d.ts +1 -1
  12. package/dist/cjs/Flow/Result.d.ts.map +1 -1
  13. package/dist/cjs/Flow/Result.js.map +2 -2
  14. package/dist/cjs/Flow/Runtime.js +1 -1
  15. package/dist/cjs/Flow/Runtime.js.map +2 -2
  16. package/dist/cjs/Flow/internal.js +1 -1
  17. package/dist/cjs/Flow/internal.js.map +2 -2
  18. package/dist/cjs/Graph.d.ts.map +1 -1
  19. package/dist/cjs/Graph.js +1 -2
  20. package/dist/cjs/Graph.js.map +2 -2
  21. package/dist/esm/DurableDeferred.js +3 -3
  22. package/dist/esm/DurableDeferred.js.map +1 -1
  23. package/dist/esm/DurableQueue.d.ts +1 -1
  24. package/dist/esm/DurableQueue.d.ts.map +1 -1
  25. package/dist/esm/DurableQueue.js +2 -2
  26. package/dist/esm/DurableQueue.js.map +1 -1
  27. package/dist/esm/Flow/ExecutionIds.js +1 -1
  28. package/dist/esm/Flow/ExecutionIds.js.map +1 -1
  29. package/dist/esm/Flow/Result.d.ts +1 -1
  30. package/dist/esm/Flow/Result.d.ts.map +1 -1
  31. package/dist/esm/Flow/Result.js.map +1 -1
  32. package/dist/esm/Flow/Runtime.js +1 -1
  33. package/dist/esm/Flow/Runtime.js.map +1 -1
  34. package/dist/esm/Flow/internal.js +1 -1
  35. package/dist/esm/Flow/internal.js.map +1 -1
  36. package/dist/esm/Graph.d.ts.map +1 -1
  37. package/dist/esm/Graph.js +4 -2
  38. package/dist/esm/Graph.js.map +1 -1
  39. package/docs/README.md +1 -1
  40. package/docs/installation.md +4 -4
  41. package/docs/reference/flow.md +1 -1
  42. package/package.json +10 -10
  43. package/src/DurableDeferred.ts +3 -3
  44. package/src/DurableQueue.ts +2 -2
  45. package/src/Flow/ExecutionIds.ts +1 -1
  46. package/src/Flow/Result.ts +1 -1
  47. package/src/Flow/Runtime.ts +1 -1
  48. package/src/Flow/internal.ts +1 -1
  49. package/src/Graph.ts +5 -2
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.js","sourceRoot":"","sources":["../../../src/Flow/Runtime.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;GAIG;AAEH,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAe,SAAS,EAAE,MAAM,aAAa,CAAA;AAExE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAA8B,EAK9B,EAAE,CACF,MAAM,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K,CAAA;IAC3C,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAA;AACnG,CAAC,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,YAAY,GAUrB,IAAI,CAAC,CAAC,EAAE,CACV,MAA8B,EAC9B,QAAmF,EACzB,EAAE,CAC5D,MAAM,CAAC,mBAAmB,CAAC,CAAC,OAAO,EAAE,EAAE,CACrC,MAAM,CAAC,GAAG,CACR,OAAO,CAAC,MAAM,CAAC,EACf,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CACpG,CACF,CAAC,CAAA;AAEJ;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,QAAiC,EAAwB,EAAE,CACjF,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAQ,GAAG,EAAE;IAC/C,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,EAAG,CAAA;IACjC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACjC,CAAC,CAAC,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Runtime helpers for flow completion, suspension, scopes, and rollback.\n *\n * @since 0.1.0\n */\n\nimport * as Arr from \"effect/Array\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Fiber from \"effect/Fiber\"\nimport * as Filter from \"effect/Filter\"\nimport { dual, identity } from \"effect/Function\"\nimport * as Scope from \"effect/Scope\"\nimport { FlowInstance } from \"../FlowRuntime/FlowInstance.ts\"\nimport { CaptureDefects, SuspendOnFailure } from \"./Annotations.ts\"\nimport { Complete, isResult, type Result, Suspended } from \"./Result.ts\"\n\n/**\n * Runs an effect as a flow execution and converts its outcome into a\n * `Result`, handling suspension, defect capture, interruption, and flow\n * scope finalization.\n *\n * @category results\n * @since 0.1.0\n */\nexport const intoResult = <A, E, R>(\n effect: Effect.Effect<A, E, R>\n): Effect.Effect<\n Result<A, E>,\n never,\n Exclude<R, Scope.Scope> | FlowInstance\n> =>\n Effect.contextWith((context: Context.Context<FlowInstance>) => {\n const instance = Context.get(context, FlowInstance)\n const captureDefects = Context.get(instance.flow.annotations, CaptureDefects)\n const suspendOnFailure = Context.get(instance.flow.annotations, SuspendOnFailure)\n return effect.pipe(\n // so we can use external interruption to suspend the flow\n Effect.forkChild({ startImmediately: true }),\n Effect.flatMap((fiber) => Effect.onInterrupt(Fiber.join(fiber), () => Fiber.interrupt(fiber))),\n Effect.interruptible,\n suspendOnFailure\n ? Effect.catchCause((cause) => {\n instance.suspended = true\n if (!Cause.hasInterruptsOnly(cause)) {\n instance.cause = Cause.die(Cause.squash(cause))\n }\n return Effect.interrupt\n })\n : identity,\n Effect.scoped,\n Effect.matchCauseEffect({\n // A body that handed off produced no answer of its own, so the slot\n // the handoff was recorded in wins over the value the handler returned\n // (`docs/concepts/trampoline-rounds.md`).\n onSuccess: (value) =>\n Effect.succeed(\n instance.handoff ?? new Complete({ exit: Exit.succeed(value) })\n ),\n onFailure: (cause): Effect.Effect<Result<A, E>> => {\n const [reasons, interrupts] = Arr.partition(\n cause.reasons,\n Filter.fromPredicate(Cause.isInterruptReason)\n )\n const hasInterruptsOnly = interrupts.length === cause.reasons.length\n const filtered = reasons.length === 0 ? cause : Cause.fromReasons(reasons)\n return instance.suspended && hasInterruptsOnly\n ? Effect.succeed(new Suspended({ cause: instance.cause }))\n : (!instance.interrupted && hasInterruptsOnly) ||\n (!captureDefects && Cause.hasDies(cause))\n ? Effect.failCause(filtered as Cause.Cause<never>)\n : Effect.succeed(new Complete({ exit: Exit.failCause(filtered) }))\n }\n }),\n (eff) =>\n Effect.onExitPrimitive(eff, (exit) => {\n if (Exit.isFailure(exit)) {\n return Scope.close(instance.scope, exit)\n } else if (exit.value._tag === \"Complete\") {\n return Scope.close(instance.scope, exit.value.exit)\n } else if (exit.value._tag === \"Handoff\") {\n // A handoff ends this round for good — the next round is a separate\n // execution with its own instance and its own scope — so the round's\n // scope closes here exactly as a completion closes it. A suspension\n // is the only settlement that keeps the scope open.\n return Scope.close(instance.scope, Exit.void)\n }\n return Effect.void\n }, true),\n Effect.uninterruptible\n )\n })\n\n/**\n * The action regions open on the current fiber's dynamic call stack.\n *\n * `actionState.count` says how many regions are open on an instance; it does\n * not say which of them the current region is nested inside. That difference is\n * the whole of {@link wrapActionResult}'s liveness: a region that suspends\n * waits for the *other* open regions to settle, and an enclosing region can\n * never settle before the region inside it returns. Carrying the enclosing\n * instances in the context is what lets a suspension tell a sibling — which\n * will settle — from an ancestor, which is waiting on the very fiber that is\n * waiting on it.\n *\n * It is a context reference rather than a fiber-local counter because the chain\n * crosses fibers: {@link intoResult} forks the body, and an engine gives every\n * action dispatch a fiber of its own. Context propagates to forked children;\n * a per-fiber counter would restart at each fork and read every ancestor as a\n * sibling again.\n */\nconst EnclosingActions = Context.Reference<ReadonlyArray<FlowInstance[\"Service\"]>>(\n \"@smthrs/flow/Flow/EnclosingActions\",\n { defaultValue: () => [] }\n)\n\n/**\n * Wraps an action-like effect so flow suspension waits for currently\n * running actions to finish or suspend.\n *\n * The wait is for *siblings*. An action that suspends holds work its siblings\n * have not journaled yet, so the flow must not park out from under them; an\n * enclosing region holds no such work, because everything it is doing is this\n * region. Waiting for one is a deadlock, and it was a real one: a harness cell\n * call is an action, the `wait` flow it dispatches awaits a `DurableClock`\n * under the run's own instance, and the round that should have parked instead\n * blocked forever inside an uninterruptible finalizer — not cancellable, not\n * resumable, and invisible in the journal past the `clock-scheduled` record.\n *\n * @category results\n * @since 0.1.0\n */\nexport const wrapActionResult = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n isSuspend: (value: A) => boolean\n): Effect.Effect<A, E, R | FlowInstance> =>\n Effect.contextWith((context: Context.Context<FlowInstance>) => {\n const instance = Context.get(context, FlowInstance)\n const enclosing = Context.getUnsafe(context, EnclosingActions)\n // How many of the regions counted on this instance are this one's own\n // ancestors, and so how many of them will still be open once every sibling\n // has settled.\n let ancestors = 0\n for (const open of enclosing) if (open === instance) ancestors++\n const state = instance.actionState\n if (state.count === 0) state.latch.closeUnsafe()\n state.count++\n return Effect.onExit(\n Effect.provideService(effect, EnclosingActions, [...enclosing, instance]),\n (exit) => {\n state.count--\n const isSuspended = Exit.isSuccess(exit) && isSuspend(exit.value)\n if (\n Exit.isSuccess(exit) &&\n isResult(exit.value) &&\n exit.value._tag === \"Suspended\" &&\n exit.value.cause\n ) {\n instance.cause = instance.cause\n ? Cause.combine(instance.cause, exit.value.cause)\n : exit.value.cause\n }\n if (state.count === 0) return state.latch.open\n // Every decrement can satisfy a waiter whose threshold is not zero, so\n // the waiters are released to re-test their own. `release` wakes them\n // without opening the latch, so the ones still short of their threshold\n // park again on the next turn of the loop.\n return isSuspended\n ? Effect.andThen(state.latch.release, waitForSiblings(instance, ancestors))\n : Effect.asVoid(state.latch.release)\n }\n )\n })\n\n// Untraced because this latch loop is a flow scheduler hot path.\nconst waitForSiblings = Effect.fnUntraced(function*(\n instance: FlowInstance[\"Service\"],\n ancestors: number\n) {\n const state = instance.actionState\n while (true) {\n if (state.count > ancestors) {\n yield* state.latch.await\n yield* Effect.yieldNow\n continue\n }\n yield* Effect.yieldNow\n if (state.count <= ancestors) return\n }\n})\n\n/**\n * Accesses the current round's flow scope. Suspension keeps it open;\n * completion or handoff closes it.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const scope: Effect.Effect<\n Scope.Scope,\n never,\n FlowInstance\n> = Effect.map(\n FlowInstance,\n (instance) => instance.scope as Scope.Scope\n)\n\n/**\n * Provides the current round's flow scope to the given effect. Suspension keeps\n * the scope open; completion or handoff closes it.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const provideScope = <A, E, R>(\n effect: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, Exclude<R, Scope.Scope> | FlowInstance> =>\n Effect.flatMap(scope, (scope) => Scope.provide(effect, scope))\n\n/**\n * Adds an exit finalizer to the current flow scope, preserving the\n * services available when the finalizer is registered.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const addFinalizer: <R>(\n f: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, R>\n) => Effect.Effect<\n void,\n never,\n FlowInstance | R\n> =\n // Untraced because suspension recursively re-enters flow execution.\n Effect.fnUntraced(function*<R>(\n f: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, R>\n ) {\n const instance = yield* FlowInstance\n const services = yield* Effect.context<R>()\n yield* Scope.addFinalizerExit(instance.scope, (exit) => Effect.provideContext(f(exit), services))\n })\n\n/**\n * Runs an effect and registers how to undo its successful result if the\n * current round later exits unsuccessfully.\n *\n * **When to use**\n *\n * Use when a top-level flow operation changes something that must be undone if\n * a later operation causes the same round to fail or be interrupted.\n *\n * **Details**\n *\n * The effect runs first. If it fails, no rollback is registered. If it\n * succeeds, its value is captured in a round-scope finalizer. The finalizer does\n * nothing when the round succeeds; when the round exits unsuccessfully\n * it calls `rollback(value, cause)`. Suspension keeps that scope open.\n *\n * A handoff completes the round successfully and discards its `withRollback` registrations.\n * A later round's failure cannot invoke those rollbacks. The engine does not\n * provide lineage-scoped compensation.\n *\n * **Gotchas**\n *\n * This applies only to effects run directly inside the flow execution. It does\n * not attach rollback behavior to nested actions. The rollback's typed error\n * channel is `never`; handle expected rollback failures inside the callback.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const withRollback: {\n <A, R2>(\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n ): <E, R>(\n effect: Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope>\n <A, E, R, R2>(\n effect: Effect.Effect<A, E, R>,\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n ): Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope>\n} = dual(2, <A, E, R, R2>(\n effect: Effect.Effect<A, E, R>,\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n): Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope> =>\n Effect.uninterruptibleMask((restore) =>\n Effect.tap(\n restore(effect),\n (value) => addFinalizer((exit) => Exit.isSuccess(exit) ? Effect.void : rollback(value, exit.cause))\n )\n ))\n\n/**\n * Marks a flow instance as suspended and interrupts the current fiber to\n * stop execution until it is resumed.\n *\n * @category results\n * @since 0.1.0\n */\nexport const suspend = (instance: FlowInstance[\"Service\"]): Effect.Effect<never> =>\n Effect.interruptible(Effect.callback<never>(() => {\n instance.suspended = true\n const fiber = Fiber.getCurrent()!\n fiber.interruptUnsafe(fiber.id)\n }))\n"]}
1
+ {"version":3,"file":"Runtime.js","sourceRoot":"","sources":["../../../src/Flow/Runtime.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;GAIG;AAEH,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAC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AQ,CAAQ,GAAG,EAAE;IAC/C,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,EAAG,CAAA;IACjC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACjC,CAAC,CAAC,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Runtime helpers for flow completion, suspension, scopes, and rollback.\n *\n * @since 0.1.0\n */\n\nimport * as Arr from \"effect/Array\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Fiber from \"effect/Fiber\"\nimport * as Filter from \"effect/Filter\"\nimport { dual, identity } from \"effect/Function\"\nimport * as Scope from \"effect/Scope\"\nimport { FlowInstance } from \"../FlowRuntime/FlowInstance.ts\"\nimport { CaptureDefects, SuspendOnFailure } from \"./Annotations.ts\"\nimport { Complete, isResult, type Result, Suspended } from \"./Result.ts\"\n\n/**\n * Runs an effect as a flow execution and converts its outcome into a\n * `Result`, handling suspension, defect capture, interruption, and flow\n * scope finalization.\n *\n * @category results\n * @since 0.1.0\n */\nexport const intoResult = <A, E, R>(\n effect: Effect.Effect<A, E, R>\n): Effect.Effect<\n Result<A, E>,\n never,\n Exclude<R, Scope.Scope> | FlowInstance\n> =>\n Effect.contextWith((context: Context.Context<FlowInstance>) => {\n const instance = Context.get(context, FlowInstance)\n const captureDefects = Context.get(instance.flow.annotations, CaptureDefects)\n const suspendOnFailure = Context.get(instance.flow.annotations, SuspendOnFailure)\n return effect.pipe(\n // so we can use external interruption to suspend the flow\n Effect.forkChild({ startImmediately: true }),\n Effect.flatMap((fiber) => Effect.onInterrupt(Fiber.join(fiber), () => Fiber.interrupt(fiber))),\n Effect.interruptible,\n suspendOnFailure\n ? Effect.catchCause((cause) => {\n instance.suspended = true\n if (!Cause.hasInterruptsOnly(cause)) {\n instance.cause = Cause.die(Cause.squash(cause))\n }\n return Effect.interrupt\n })\n : identity,\n Effect.scoped,\n Effect.matchCauseEffect({\n // A body that handed off produced no answer of its own, so the slot\n // the handoff was recorded in wins over the value the handler returned\n // (`docs/concepts/trampoline-rounds.md`).\n onSuccess: (value) =>\n Effect.succeed(\n instance.handoff ?? new Complete({ exit: Exit.succeed(value) })\n ),\n onFailure: (cause): Effect.Effect<Result<A, E>> => {\n const [interrupts, reasons] = Arr.partition(\n cause.reasons,\n Filter.fromPredicate(Cause.isInterruptReason)\n )\n const hasInterruptsOnly = interrupts.length === cause.reasons.length\n const filtered = reasons.length === 0 ? cause : Cause.fromReasons(reasons)\n return instance.suspended && hasInterruptsOnly\n ? Effect.succeed(new Suspended({ cause: instance.cause }))\n : (!instance.interrupted && hasInterruptsOnly) ||\n (!captureDefects && Cause.hasDies(cause))\n ? Effect.failCause(filtered as Cause.Cause<never>)\n : Effect.succeed(new Complete({ exit: Exit.failCause(filtered) }))\n }\n }),\n (eff) =>\n Effect.onExitPrimitive(eff, (exit) => {\n if (Exit.isFailure(exit)) {\n return Scope.close(instance.scope, exit)\n } else if (exit.value._tag === \"Complete\") {\n return Scope.close(instance.scope, exit.value.exit)\n } else if (exit.value._tag === \"Handoff\") {\n // A handoff ends this round for good — the next round is a separate\n // execution with its own instance and its own scope — so the round's\n // scope closes here exactly as a completion closes it. A suspension\n // is the only settlement that keeps the scope open.\n return Scope.close(instance.scope, Exit.void)\n }\n return Effect.void\n }, true),\n Effect.uninterruptible\n )\n })\n\n/**\n * The action regions open on the current fiber's dynamic call stack.\n *\n * `actionState.count` says how many regions are open on an instance; it does\n * not say which of them the current region is nested inside. That difference is\n * the whole of {@link wrapActionResult}'s liveness: a region that suspends\n * waits for the *other* open regions to settle, and an enclosing region can\n * never settle before the region inside it returns. Carrying the enclosing\n * instances in the context is what lets a suspension tell a sibling — which\n * will settle — from an ancestor, which is waiting on the very fiber that is\n * waiting on it.\n *\n * It is a context reference rather than a fiber-local counter because the chain\n * crosses fibers: {@link intoResult} forks the body, and an engine gives every\n * action dispatch a fiber of its own. Context propagates to forked children;\n * a per-fiber counter would restart at each fork and read every ancestor as a\n * sibling again.\n */\nconst EnclosingActions = Context.Reference<ReadonlyArray<FlowInstance[\"Service\"]>>(\n \"@smthrs/flow/Flow/EnclosingActions\",\n { defaultValue: () => [] }\n)\n\n/**\n * Wraps an action-like effect so flow suspension waits for currently\n * running actions to finish or suspend.\n *\n * The wait is for *siblings*. An action that suspends holds work its siblings\n * have not journaled yet, so the flow must not park out from under them; an\n * enclosing region holds no such work, because everything it is doing is this\n * region. Waiting for one is a deadlock, and it was a real one: a harness cell\n * call is an action, the `wait` flow it dispatches awaits a `DurableClock`\n * under the run's own instance, and the round that should have parked instead\n * blocked forever inside an uninterruptible finalizer — not cancellable, not\n * resumable, and invisible in the journal past the `clock-scheduled` record.\n *\n * @category results\n * @since 0.1.0\n */\nexport const wrapActionResult = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n isSuspend: (value: A) => boolean\n): Effect.Effect<A, E, R | FlowInstance> =>\n Effect.contextWith((context: Context.Context<FlowInstance>) => {\n const instance = Context.get(context, FlowInstance)\n const enclosing = Context.getUnsafe(context, EnclosingActions)\n // How many of the regions counted on this instance are this one's own\n // ancestors, and so how many of them will still be open once every sibling\n // has settled.\n let ancestors = 0\n for (const open of enclosing) if (open === instance) ancestors++\n const state = instance.actionState\n if (state.count === 0) state.latch.closeUnsafe()\n state.count++\n return Effect.onExit(\n Effect.provideService(effect, EnclosingActions, [...enclosing, instance]),\n (exit) => {\n state.count--\n const isSuspended = Exit.isSuccess(exit) && isSuspend(exit.value)\n if (\n Exit.isSuccess(exit) &&\n isResult(exit.value) &&\n exit.value._tag === \"Suspended\" &&\n exit.value.cause\n ) {\n instance.cause = instance.cause\n ? Cause.combine(instance.cause, exit.value.cause)\n : exit.value.cause\n }\n if (state.count === 0) return state.latch.open\n // Every decrement can satisfy a waiter whose threshold is not zero, so\n // the waiters are released to re-test their own. `release` wakes them\n // without opening the latch, so the ones still short of their threshold\n // park again on the next turn of the loop.\n return isSuspended\n ? Effect.andThen(state.latch.release, waitForSiblings(instance, ancestors))\n : Effect.asVoid(state.latch.release)\n }\n )\n })\n\n// Untraced because this latch loop is a flow scheduler hot path.\nconst waitForSiblings = Effect.fnUntraced(function*(\n instance: FlowInstance[\"Service\"],\n ancestors: number\n) {\n const state = instance.actionState\n while (true) {\n if (state.count > ancestors) {\n yield* state.latch.await\n yield* Effect.yieldNow\n continue\n }\n yield* Effect.yieldNow\n if (state.count <= ancestors) return\n }\n})\n\n/**\n * Accesses the current round's flow scope. Suspension keeps it open;\n * completion or handoff closes it.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const scope: Effect.Effect<\n Scope.Scope,\n never,\n FlowInstance\n> = Effect.map(\n FlowInstance,\n (instance) => instance.scope as Scope.Scope\n)\n\n/**\n * Provides the current round's flow scope to the given effect. Suspension keeps\n * the scope open; completion or handoff closes it.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const provideScope = <A, E, R>(\n effect: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, Exclude<R, Scope.Scope> | FlowInstance> =>\n Effect.flatMap(scope, (scope) => Scope.provide(effect, scope))\n\n/**\n * Adds an exit finalizer to the current flow scope, preserving the\n * services available when the finalizer is registered.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const addFinalizer: <R>(\n f: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, R>\n) => Effect.Effect<\n void,\n never,\n FlowInstance | R\n> =\n // Untraced because suspension recursively re-enters flow execution.\n Effect.fnUntraced(function*<R>(\n f: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, R>\n ) {\n const instance = yield* FlowInstance\n const services = yield* Effect.context<R>()\n yield* Scope.addFinalizerExit(instance.scope, (exit) => Effect.provideContext(f(exit), services))\n })\n\n/**\n * Runs an effect and registers how to undo its successful result if the\n * current round later exits unsuccessfully.\n *\n * **When to use**\n *\n * Use when a top-level flow operation changes something that must be undone if\n * a later operation causes the same round to fail or be interrupted.\n *\n * **Details**\n *\n * The effect runs first. If it fails, no rollback is registered. If it\n * succeeds, its value is captured in a round-scope finalizer. The finalizer does\n * nothing when the round succeeds; when the round exits unsuccessfully\n * it calls `rollback(value, cause)`. Suspension keeps that scope open.\n *\n * A handoff completes the round successfully and discards its `withRollback` registrations.\n * A later round's failure cannot invoke those rollbacks. The engine does not\n * provide lineage-scoped compensation.\n *\n * **Gotchas**\n *\n * This applies only to effects run directly inside the flow execution. It does\n * not attach rollback behavior to nested actions. The rollback's typed error\n * channel is `never`; handle expected rollback failures inside the callback.\n *\n * @category resource management\n * @since 0.1.0\n */\nexport const withRollback: {\n <A, R2>(\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n ): <E, R>(\n effect: Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope>\n <A, E, R, R2>(\n effect: Effect.Effect<A, E, R>,\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n ): Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope>\n} = dual(2, <A, E, R, R2>(\n effect: Effect.Effect<A, E, R>,\n rollback: (value: A, cause: Cause.Cause<unknown>) => Effect.Effect<void, never, R2>\n): Effect.Effect<A, E, R | R2 | FlowInstance | Scope.Scope> =>\n Effect.uninterruptibleMask((restore) =>\n Effect.tap(\n restore(effect),\n (value) => addFinalizer((exit) => Exit.isSuccess(exit) ? Effect.void : rollback(value, exit.cause))\n )\n ))\n\n/**\n * Marks a flow instance as suspended and interrupts the current fiber to\n * stop execution until it is resumed.\n *\n * @category results\n * @since 0.1.0\n */\nexport const suspend = (instance: FlowInstance[\"Service\"]): Effect.Effect<never> =>\n Effect.interruptible(Effect.callback<never>(() => {\n instance.suspended = true\n const fiber = Fiber.getCurrent()!\n fiber.interruptUnsafe(fiber.id)\n }))\n"]}
@@ -113,7 +113,7 @@ const Proto = {
113
113
  }))))))).pipe(Effect.withSpan(`${this._tag}.execute`, {}, { captureStackTrace: false }));
114
114
  },
115
115
  start(payload) {
116
- return Effect.flatMap(Crypto.Crypto, (crypto) => Effect.flatMap(Effect.orDie(crypto.randomUUIDv4), (executionId) => this.execute(payload, { executionId, discard: true })));
116
+ return Effect.flatMap(Crypto.Crypto, (crypto) => Effect.flatMap(Effect.orDie(crypto.randomUUIDv4()), (executionId) => this.execute(payload, { executionId, discard: true })));
117
117
  },
118
118
  ensure(payload, options) {
119
119
  return Schema.decodeUnknownEffect(Schema.String)(options.key).pipe(Effect.flatMap((key) => Effect.orDie(Schema.decodeUnknownEffect(Sha256)(JSON.stringify([this._tag, key])))), Effect.flatMap((executionId) => this.execute(payload, { executionId, discard: true })));
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/Flow/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAA;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,eAAe,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;;;;;;;;;;GAYG;AACH,MAAM,0B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E,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CACtG,CAAA;IACH,CAAC;IACD,WAAW,CAAqB,OAAY;QAC1C,OAAO,MAAM,CAAC,OAAO;QACnB,uGAAuG;QACvG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EACpD,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CACvD,CAAA;IACH,CAAC;IACD,YAAY,EAAE,CAAC,CAAC,GAAG,IAAwB,EAAE,EAAE,CAAE,YAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;CAChF,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAOvB,OAcC,EAC6C,EAAE;IAChD,SAAS,IAAI,KAAI,CAAC;IAClB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,IAAW,CAAA;AACpB,CAAC,CAAA","sourcesContent":["/**\n * Private flow construction shared by declarations and action registration.\n *\n * @since 1.0.0\n * @private\n */\n\nimport { Sha256 } from \"@smthrs/crypto\"\nimport * as Node from \"@smthrs/plan/Node\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Crypto from \"effect/Crypto\"\nimport type * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport { ExecutionIdentityConflict } from \"../FlowRuntime/ExecutionIdentityConflict.ts\"\nimport { FlowRuntime } from \"../FlowRuntime/FlowRuntime.ts\"\nimport * as DeclarationSite from \"../internal/DeclarationSite.ts\"\nimport type * as RetryPolicy from \"../RetryPolicy.ts\"\nimport { CurrentExecutionIds } from \"./ExecutionIds.ts\"\nimport type { Any, AnyStructSchema, AnyWithProps, BodySuccess, DeclarationMetadata, Flow } from \"./Flow.ts\"\nimport type { To } from \"./Outcome.ts\"\nimport { withRollback } from \"./Runtime.ts\"\nimport { TypeId } from \"./TypeId.ts\"\n\n/**\n * The identity of an invocation that named no `executionId`: the flow's own\n * declared key when it has one, and the ambient source otherwise.\n *\n * A declared key wins over the ambient source because it is the narrower\n * statement — this author said what makes two invocations of THIS flow the\n * same — where the source is the host's blanket answer for every flow it\n * drives.\n *\n * The tag and declared key are JSON-tuple framed before hashing. Their strings\n * are used exactly as given and encoded as UTF-8, with no Unicode\n * normalization. This preimage encoding freezes at rc.0.\n */\nconst makeExecutionIdFromPayload = (\n self: AnyWithProps,\n payload: unknown\n): Effect.Effect<string, never, any> => {\n const idempotencyKey = self.idempotencyKey\n return idempotencyKey === undefined\n ? Effect.flatMap(CurrentExecutionIds, (source) => source.mint(self, payload))\n // The JSON tuple prevents delimiter splicing. This exact framing freezes at rc.0.\n : Schema.decodeUnknownEffect(Sha256)(JSON.stringify([self._tag, idempotencyKey(payload)])).pipe(Effect.orDie)\n}\n\nconst resolveExecutionId = (\n self: AnyWithProps,\n payload: unknown,\n executionId: string | undefined\n): Effect.Effect<string, never, any> =>\n executionId === undefined\n ? makeExecutionIdFromPayload(self, payload)\n : Effect.succeed(executionId)\n\nconst Proto = {\n [TypeId]: TypeId,\n annotate(this: AnyWithProps, tag: Context.Key<any, any>, value: any) {\n return DeclarationSite.annotate(\n makeProto({\n _tag: this._tag,\n description: this.description,\n model: this.model,\n effort: this.effort,\n system: this.system,\n chat: this.chat,\n flows: this.flows,\n prompt: this.prompt,\n action: this.action,\n payloadSchema: this.payloadSchema,\n successSchema: this.successSchema,\n errorSchema: this.errorSchema,\n annotations: Context.add(this.annotations, tag, value),\n body: this.body,\n idempotencyKey: this.idempotencyKey,\n suspendedRetryPolicy: this.suspendedRetryPolicy,\n maxRounds: this.maxRounds,\n deadline: this.deadline\n }),\n DeclarationSite.declaredAt(this)\n )\n },\n annotateMerge(this: AnyWithProps, context: Context.Context<any>) {\n return DeclarationSite.annotate(\n makeProto({\n _tag: this._tag,\n description: this.description,\n model: this.model,\n effort: this.effort,\n system: this.system,\n chat: this.chat,\n flows: this.flows,\n prompt: this.prompt,\n action: this.action,\n payloadSchema: this.payloadSchema,\n successSchema: this.successSchema,\n errorSchema: this.errorSchema,\n annotations: Context.merge(this.annotations, context),\n body: this.body,\n idempotencyKey: this.idempotencyKey,\n suspendedRetryPolicy: this.suspendedRetryPolicy,\n maxRounds: this.maxRounds,\n deadline: this.deadline\n }),\n DeclarationSite.declaredAt(this)\n )\n },\n call(this: AnyWithProps, payload: unknown) {\n return Node.flowCall(this, this._tag, \"inline\", payload)\n },\n child(this: AnyWithProps, payload: unknown) {\n return Node.flowCall(this, this._tag, \"boundary\", payload)\n },\n to(this: AnyWithProps, payload: unknown): Node.Node<To<unknown>> {\n return Node.flowCall(this, this._tag, \"handoff\", payload)\n },\n execute<const Discard extends boolean = false>(\n this: AnyWithProps,\n fields: any,\n opts?: {\n readonly discard?: Discard\n readonly executionId?: string | undefined\n } | undefined\n ) {\n // Caller input that fails the payload schema is data, not programmer\n // wiring, so it FAILS with the schema's typed `SchemaError` — carrying\n // the offending field path — instead of dying with the raw constructor\n // throw `payloadSchema.make` would produce.\n return this.payloadSchema.makeEffect(fields).pipe(\n Effect.mapError((issue) => new Schema.SchemaError(issue)),\n Effect.flatMap((payload) =>\n Effect.flatMap(\n resolveExecutionId(this, payload, opts?.executionId),\n (executionId) =>\n Effect.flatMap(FlowRuntime, (engine) =>\n Effect.andThen(\n Effect.annotateCurrentSpan({ executionId }),\n engine.execute(this as any, {\n executionId,\n payload,\n discard: opts?.discard,\n suspendedRetryPolicy: this.suspendedRetryPolicy\n }).pipe(Effect.catchCause((cause) => {\n const reason = cause.reasons.length === 1 ? cause.reasons.find(Cause.isDieReason) : undefined\n return reason?.defect instanceof ExecutionIdentityConflict\n ? Effect.fail(reason.defect)\n : Effect.failCause(cause)\n }))\n ))\n )\n )\n ).pipe(\n Effect.withSpan(\n `${this._tag}.execute`,\n {},\n { captureStackTrace: false }\n )\n ) as any\n },\n start(this: AnyWithProps, payload: unknown) {\n return Effect.flatMap(\n Crypto.Crypto,\n (crypto) =>\n Effect.flatMap(\n Effect.orDie(crypto.randomUUIDv4),\n (executionId) => this.execute(payload, { executionId, discard: true })\n )\n )\n },\n ensure(this: AnyWithProps, payload: unknown, options: { readonly key: string }) {\n return Schema.decodeUnknownEffect(Schema.String)(options.key).pipe(\n Effect.flatMap((key) => Effect.orDie(Schema.decodeUnknownEffect(Sha256)(JSON.stringify([this._tag, key])))),\n Effect.flatMap((executionId) => this.execute(payload, { executionId, discard: true }))\n )\n },\n poll(this: Flow<string, AnyStructSchema, Schema.Top, Schema.Top, any>, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.poll(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.poll`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n interrupt(this: AnyWithProps, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.interrupt(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.interrupt`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n resume(this: Flow<string, AnyStructSchema, Schema.Top, Schema.Top, any>, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.resume(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.resume`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n executionId(this: AnyWithProps, payload: any) {\n return Effect.flatMap(\n // The channel stays never: precomputing callers must validate first, and an invalid payload dies here.\n Effect.orDie(this.payloadSchema.makeEffect(payload)),\n (payload) => makeExecutionIdFromPayload(this, payload)\n )\n },\n withRollback: ((...args: ReadonlyArray<any>) => (withRollback as any)(...args))\n}\n\n/**\n * Builds the private prototype from normalized declaration data.\n *\n * @since 1.0.0\n * @private\n */\nexport const makeProto = <\n const Tag extends string,\n Payload extends AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top,\n Requires\n>(\n options: DeclarationMetadata & {\n readonly _tag: Tag\n readonly description?: string | undefined\n readonly payloadSchema: Payload\n readonly successSchema: Success\n readonly errorSchema: Error\n readonly annotations: Context.Context<never>\n readonly body: (payload: Payload[\"Type\"]) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>\n readonly prompt?: ((payload: Payload[\"Type\"]) => string) | undefined\n readonly action?: Any[\"action\"] | undefined\n readonly idempotencyKey?: ((payload: Payload[\"Type\"]) => string) | undefined\n readonly suspendedRetryPolicy?: RetryPolicy.RetryPolicy | undefined\n readonly maxRounds?: number | undefined\n readonly deadline?: Duration.Duration | undefined\n }\n): Flow<Tag, Payload, Success, Error, Requires> => {\n function Flow() {}\n Object.setPrototypeOf(Flow, Proto)\n Object.assign(Flow, options)\n return Flow as any\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/Flow/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAA;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,eAAe,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;;;;;;;;;;GAYG;AAC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,WAAW,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CACtG,CAAA;IACH,CAAC;IACD,WAAW,CAAqB,OAAY;QAC1C,OAAO,MAAM,CAAC,OAAO;QACnB,uGAAuG;QACvG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EACpD,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CACvD,CAAA;IACH,CAAC;IACD,YAAY,EAAE,CAAC,CAAC,GAAG,IAAwB,EAAE,EAAE,CAAE,YAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;CAChF,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAOvB,OAcC,EAC6C,EAAE;IAChD,SAAS,IAAI,KAAI,CAAC;IAClB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,IAAW,CAAA;AACpB,CAAC,CAAA","sourcesContent":["/**\n * Private flow construction shared by declarations and action registration.\n *\n * @since 1.0.0\n * @private\n */\n\nimport { Sha256 } from \"@smthrs/crypto\"\nimport * as Node from \"@smthrs/plan/Node\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Crypto from \"effect/Crypto\"\nimport type * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport { ExecutionIdentityConflict } from \"../FlowRuntime/ExecutionIdentityConflict.ts\"\nimport { FlowRuntime } from \"../FlowRuntime/FlowRuntime.ts\"\nimport * as DeclarationSite from \"../internal/DeclarationSite.ts\"\nimport type * as RetryPolicy from \"../RetryPolicy.ts\"\nimport { CurrentExecutionIds } from \"./ExecutionIds.ts\"\nimport type { Any, AnyStructSchema, AnyWithProps, BodySuccess, DeclarationMetadata, Flow } from \"./Flow.ts\"\nimport type { To } from \"./Outcome.ts\"\nimport { withRollback } from \"./Runtime.ts\"\nimport { TypeId } from \"./TypeId.ts\"\n\n/**\n * The identity of an invocation that named no `executionId`: the flow's own\n * declared key when it has one, and the ambient source otherwise.\n *\n * A declared key wins over the ambient source because it is the narrower\n * statement — this author said what makes two invocations of THIS flow the\n * same — where the source is the host's blanket answer for every flow it\n * drives.\n *\n * The tag and declared key are JSON-tuple framed before hashing. Their strings\n * are used exactly as given and encoded as UTF-8, with no Unicode\n * normalization. This preimage encoding freezes at rc.0.\n */\nconst makeExecutionIdFromPayload = (\n self: AnyWithProps,\n payload: unknown\n): Effect.Effect<string, never, any> => {\n const idempotencyKey = self.idempotencyKey\n return idempotencyKey === undefined\n ? Effect.flatMap(CurrentExecutionIds, (source) => source.mint(self, payload))\n // The JSON tuple prevents delimiter splicing. This exact framing freezes at rc.0.\n : Schema.decodeUnknownEffect(Sha256)(JSON.stringify([self._tag, idempotencyKey(payload)])).pipe(Effect.orDie)\n}\n\nconst resolveExecutionId = (\n self: AnyWithProps,\n payload: unknown,\n executionId: string | undefined\n): Effect.Effect<string, never, any> =>\n executionId === undefined\n ? makeExecutionIdFromPayload(self, payload)\n : Effect.succeed(executionId)\n\nconst Proto = {\n [TypeId]: TypeId,\n annotate(this: AnyWithProps, tag: Context.Key<any, any>, value: any) {\n return DeclarationSite.annotate(\n makeProto({\n _tag: this._tag,\n description: this.description,\n model: this.model,\n effort: this.effort,\n system: this.system,\n chat: this.chat,\n flows: this.flows,\n prompt: this.prompt,\n action: this.action,\n payloadSchema: this.payloadSchema,\n successSchema: this.successSchema,\n errorSchema: this.errorSchema,\n annotations: Context.add(this.annotations, tag, value),\n body: this.body,\n idempotencyKey: this.idempotencyKey,\n suspendedRetryPolicy: this.suspendedRetryPolicy,\n maxRounds: this.maxRounds,\n deadline: this.deadline\n }),\n DeclarationSite.declaredAt(this)\n )\n },\n annotateMerge(this: AnyWithProps, context: Context.Context<any>) {\n return DeclarationSite.annotate(\n makeProto({\n _tag: this._tag,\n description: this.description,\n model: this.model,\n effort: this.effort,\n system: this.system,\n chat: this.chat,\n flows: this.flows,\n prompt: this.prompt,\n action: this.action,\n payloadSchema: this.payloadSchema,\n successSchema: this.successSchema,\n errorSchema: this.errorSchema,\n annotations: Context.merge(this.annotations, context),\n body: this.body,\n idempotencyKey: this.idempotencyKey,\n suspendedRetryPolicy: this.suspendedRetryPolicy,\n maxRounds: this.maxRounds,\n deadline: this.deadline\n }),\n DeclarationSite.declaredAt(this)\n )\n },\n call(this: AnyWithProps, payload: unknown) {\n return Node.flowCall(this, this._tag, \"inline\", payload)\n },\n child(this: AnyWithProps, payload: unknown) {\n return Node.flowCall(this, this._tag, \"boundary\", payload)\n },\n to(this: AnyWithProps, payload: unknown): Node.Node<To<unknown>> {\n return Node.flowCall(this, this._tag, \"handoff\", payload)\n },\n execute<const Discard extends boolean = false>(\n this: AnyWithProps,\n fields: any,\n opts?: {\n readonly discard?: Discard\n readonly executionId?: string | undefined\n } | undefined\n ) {\n // Caller input that fails the payload schema is data, not programmer\n // wiring, so it FAILS with the schema's typed `SchemaError` — carrying\n // the offending field path — instead of dying with the raw constructor\n // throw `payloadSchema.make` would produce.\n return this.payloadSchema.makeEffect(fields).pipe(\n Effect.mapError((issue) => new Schema.SchemaError(issue)),\n Effect.flatMap((payload) =>\n Effect.flatMap(\n resolveExecutionId(this, payload, opts?.executionId),\n (executionId) =>\n Effect.flatMap(FlowRuntime, (engine) =>\n Effect.andThen(\n Effect.annotateCurrentSpan({ executionId }),\n engine.execute(this as any, {\n executionId,\n payload,\n discard: opts?.discard,\n suspendedRetryPolicy: this.suspendedRetryPolicy\n }).pipe(Effect.catchCause((cause) => {\n const reason = cause.reasons.length === 1 ? cause.reasons.find(Cause.isDieReason) : undefined\n return reason?.defect instanceof ExecutionIdentityConflict\n ? Effect.fail(reason.defect)\n : Effect.failCause(cause)\n }))\n ))\n )\n )\n ).pipe(\n Effect.withSpan(\n `${this._tag}.execute`,\n {},\n { captureStackTrace: false }\n )\n ) as any\n },\n start(this: AnyWithProps, payload: unknown) {\n return Effect.flatMap(\n Crypto.Crypto,\n (crypto) =>\n Effect.flatMap(\n Effect.orDie(crypto.randomUUIDv4()),\n (executionId) => this.execute(payload, { executionId, discard: true })\n )\n )\n },\n ensure(this: AnyWithProps, payload: unknown, options: { readonly key: string }) {\n return Schema.decodeUnknownEffect(Schema.String)(options.key).pipe(\n Effect.flatMap((key) => Effect.orDie(Schema.decodeUnknownEffect(Sha256)(JSON.stringify([this._tag, key])))),\n Effect.flatMap((executionId) => this.execute(payload, { executionId, discard: true }))\n )\n },\n poll(this: Flow<string, AnyStructSchema, Schema.Top, Schema.Top, any>, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.poll(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.poll`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n interrupt(this: AnyWithProps, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.interrupt(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.interrupt`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n resume(this: Flow<string, AnyStructSchema, Schema.Top, Schema.Top, any>, executionId: string) {\n return Effect.flatMap(FlowRuntime, (engine) => engine.resume(this, executionId)).pipe(\n Effect.withSpan(`${this._tag}.resume`, { attributes: { executionId } }, { captureStackTrace: false })\n )\n },\n executionId(this: AnyWithProps, payload: any) {\n return Effect.flatMap(\n // The channel stays never: precomputing callers must validate first, and an invalid payload dies here.\n Effect.orDie(this.payloadSchema.makeEffect(payload)),\n (payload) => makeExecutionIdFromPayload(this, payload)\n )\n },\n withRollback: ((...args: ReadonlyArray<any>) => (withRollback as any)(...args))\n}\n\n/**\n * Builds the private prototype from normalized declaration data.\n *\n * @since 1.0.0\n * @private\n */\nexport const makeProto = <\n const Tag extends string,\n Payload extends AnyStructSchema,\n Success extends Schema.Top,\n Error extends Schema.Top,\n Requires\n>(\n options: DeclarationMetadata & {\n readonly _tag: Tag\n readonly description?: string | undefined\n readonly payloadSchema: Payload\n readonly successSchema: Success\n readonly errorSchema: Error\n readonly annotations: Context.Context<never>\n readonly body: (payload: Payload[\"Type\"]) => Node.Node<BodySuccess<Success[\"Type\"]>, Error[\"Type\"], Requires>\n readonly prompt?: ((payload: Payload[\"Type\"]) => string) | undefined\n readonly action?: Any[\"action\"] | undefined\n readonly idempotencyKey?: ((payload: Payload[\"Type\"]) => string) | undefined\n readonly suspendedRetryPolicy?: RetryPolicy.RetryPolicy | undefined\n readonly maxRounds?: number | undefined\n readonly deadline?: Duration.Duration | undefined\n }\n): Flow<Tag, Payload, Success, Error, Requires> => {\n function Flow() {}\n Object.setPrototypeOf(Flow, Proto)\n Object.assign(Flow, options)\n return Flow as any\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../src/Graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAIH,OAAO,EAAE,eAAe,EAAqB,MAAM,8BAA8B,CAAA;AAEjF,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAQ9C,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,KAAK,IAAI,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAA;AAKhE;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,cAAc,GAAG,SAAS,CAAA;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAA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eAAO,MAAM,WAAW,GAAI,OAAO,KAAK,KAAG,aAAa,CAAC,eAAe,CAAsB,CAAA;AAE9F;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,cAAc,CAAC,GAAG;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC5G,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;IACnC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9E,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACxF,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,IAAI,CAAC,GAAG,KAAG,UAkDxC,CAAA"}
package/dist/esm/Graph.js CHANGED
@@ -63,7 +63,6 @@ import * as Planned from "@smthrs/plan/Planned";
63
63
  import * as Context from "effect/Context";
64
64
  import * as Option from "effect/Option";
65
65
  import * as Predicate from "effect/Predicate";
66
- import * as Schema from "effect/Schema";
67
66
  import { TypeId as ActionTypeId } from "./Action/TypeId.js";
68
67
  import * as Annotations from "./Flow/Annotations.js";
69
68
  import { capabilityCeilings } from "./Flow/CapabilityCeiling.js";
@@ -128,13 +127,16 @@ const refusalMessage = (narrowed, site) => {
128
127
  * transformation and needs the call re-keyed renames the declaration.
129
128
  * `@smthrs/core` carries the same algorithm and the same limit.
130
129
  *
130
+ * `Node.schemaIdentity` prints the document, not the installed `effect`: a
131
+ * release that prints a schema differently must not move the identity.
132
+ *
131
133
  * @private
132
134
  */
133
135
  const schemaIdentity = (schema) => {
134
136
  const cached = schemaDocuments.get(schema);
135
137
  if (cached !== undefined)
136
138
  return cached;
137
- const document = Schema.toJsonSchemaDocument(schema, { onExcessProperty: "error" });
139
+ const document = Node.schemaIdentity(schema, { onExcessProperty: "error" });
138
140
  schemaDocuments.set(schema, document);
139
141
  return document;
140
142
  };