@typeonce/effect-machine 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +203 -16
  2. package/dist/Machine.d.ts +784 -289
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +158 -528
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/activities.d.ts +57 -0
  7. package/dist/internal/machine/activities.d.ts.map +1 -0
  8. package/dist/internal/machine/activities.js +49 -0
  9. package/dist/internal/machine/activities.js.map +1 -0
  10. package/dist/internal/machine/atom.d.ts +69 -0
  11. package/dist/internal/machine/atom.d.ts.map +1 -0
  12. package/dist/{AtomMachine.js → internal/machine/atom.js} +19 -94
  13. package/dist/internal/machine/atom.js.map +1 -0
  14. package/dist/internal/machine/cluster.d.ts +63 -0
  15. package/dist/internal/machine/cluster.d.ts.map +1 -0
  16. package/dist/{ClusterMachine.js → internal/machine/cluster.js} +14 -118
  17. package/dist/internal/machine/cluster.js.map +1 -0
  18. package/dist/internal/machine/command.d.ts +16 -0
  19. package/dist/internal/machine/command.d.ts.map +1 -0
  20. package/dist/internal/machine/command.js +45 -0
  21. package/dist/internal/machine/command.js.map +1 -0
  22. package/dist/internal/machine/commandRuntime.d.ts +13 -0
  23. package/dist/internal/machine/commandRuntime.d.ts.map +1 -0
  24. package/dist/internal/machine/commandRuntime.js +16 -0
  25. package/dist/internal/machine/commandRuntime.js.map +1 -0
  26. package/dist/internal/{machineModel.d.ts → machine/configuration.d.ts} +11 -60
  27. package/dist/internal/machine/configuration.d.ts.map +1 -0
  28. package/dist/internal/{machineModel.js → machine/configuration.js} +249 -544
  29. package/dist/internal/machine/configuration.js.map +1 -0
  30. package/dist/internal/{machineErrors.d.ts → machine/errors.d.ts} +1 -1
  31. package/dist/internal/machine/errors.d.ts.map +1 -0
  32. package/dist/internal/{machineErrors.js → machine/errors.js} +1 -1
  33. package/dist/internal/machine/errors.js.map +1 -0
  34. package/dist/internal/machine/executionPlan.d.ts +49 -0
  35. package/dist/internal/machine/executionPlan.d.ts.map +1 -0
  36. package/dist/internal/machine/executionPlan.js +667 -0
  37. package/dist/internal/machine/executionPlan.js.map +1 -0
  38. package/dist/internal/machine/invocation.d.ts +23 -0
  39. package/dist/internal/machine/invocation.d.ts.map +1 -0
  40. package/dist/internal/machine/invocation.js +77 -0
  41. package/dist/internal/machine/invocation.js.map +1 -0
  42. package/dist/internal/machine/machine.d.ts +183 -0
  43. package/dist/internal/machine/machine.d.ts.map +1 -0
  44. package/dist/internal/machine/machine.js +552 -0
  45. package/dist/internal/machine/machine.js.map +1 -0
  46. package/dist/internal/machine/planner.d.ts +182 -0
  47. package/dist/internal/machine/planner.d.ts.map +1 -0
  48. package/dist/internal/machine/planner.js +1082 -0
  49. package/dist/internal/machine/planner.js.map +1 -0
  50. package/dist/internal/{machineProcess.d.ts → machine/process.d.ts} +10 -4
  51. package/dist/internal/machine/process.d.ts.map +1 -0
  52. package/dist/internal/machine/process.js +446 -0
  53. package/dist/internal/machine/process.js.map +1 -0
  54. package/dist/internal/machine/protocol.d.ts +34 -0
  55. package/dist/internal/machine/protocol.d.ts.map +1 -0
  56. package/dist/internal/machine/protocol.js +182 -0
  57. package/dist/internal/machine/protocol.js.map +1 -0
  58. package/dist/internal/machine/readiness.d.ts +4 -0
  59. package/dist/internal/machine/readiness.d.ts.map +1 -0
  60. package/dist/internal/machine/readiness.js +2 -0
  61. package/dist/internal/machine/readiness.js.map +1 -0
  62. package/dist/internal/{machineRuntime.d.ts → machine/runtime.d.ts} +104 -2
  63. package/dist/internal/machine/runtime.d.ts.map +1 -0
  64. package/dist/internal/machine/runtime.js +1381 -0
  65. package/dist/internal/machine/runtime.js.map +1 -0
  66. package/dist/internal/machine/serialization.d.ts +14 -0
  67. package/dist/internal/machine/serialization.d.ts.map +1 -0
  68. package/dist/internal/machine/serialization.js +338 -0
  69. package/dist/internal/machine/serialization.js.map +1 -0
  70. package/dist/internal/machine/stateDefinition.d.ts +15 -0
  71. package/dist/internal/machine/stateDefinition.d.ts.map +1 -0
  72. package/dist/internal/machine/stateDefinition.js +210 -0
  73. package/dist/internal/machine/stateDefinition.js.map +1 -0
  74. package/dist/internal/machine/symbols.d.ts +3 -0
  75. package/dist/internal/machine/symbols.d.ts.map +1 -0
  76. package/dist/internal/machine/symbols.js +3 -0
  77. package/dist/internal/machine/symbols.js.map +1 -0
  78. package/dist/internal/machine/topology.d.ts +98 -0
  79. package/dist/internal/machine/topology.d.ts.map +1 -0
  80. package/dist/internal/machine/topology.js +347 -0
  81. package/dist/internal/machine/topology.js.map +1 -0
  82. package/dist/internal/testing/machine/arbitrary.d.ts +36 -0
  83. package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -0
  84. package/dist/internal/testing/machine/arbitrary.js +68 -0
  85. package/dist/internal/testing/machine/arbitrary.js.map +1 -0
  86. package/dist/internal/testing/machine/finiteModel.d.ts +322 -0
  87. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -0
  88. package/dist/internal/testing/machine/finiteModel.js +976 -0
  89. package/dist/internal/testing/machine/finiteModel.js.map +1 -0
  90. package/dist/internal/testing/machine/referenceModel.d.ts +203 -0
  91. package/dist/internal/testing/machine/referenceModel.d.ts.map +1 -0
  92. package/dist/internal/testing/machine/referenceModel.js +1012 -0
  93. package/dist/internal/testing/machine/referenceModel.js.map +1 -0
  94. package/dist/internal/testing/machine/runtime.d.ts +328 -0
  95. package/dist/internal/testing/machine/runtime.d.ts.map +1 -0
  96. package/dist/internal/testing/machine/runtime.js +437 -0
  97. package/dist/internal/testing/machine/runtime.js.map +1 -0
  98. package/dist/internal/testing/machine/verification.d.ts +33 -0
  99. package/dist/internal/testing/machine/verification.d.ts.map +1 -0
  100. package/dist/internal/testing/machine/verification.js +1446 -0
  101. package/dist/internal/testing/machine/verification.js.map +1 -0
  102. package/dist/testing/MachineTest.d.ts +606 -0
  103. package/dist/testing/MachineTest.d.ts.map +1 -0
  104. package/dist/testing/MachineTest.js +102 -0
  105. package/dist/testing/MachineTest.js.map +1 -0
  106. package/dist/testing/index.d.ts +7 -0
  107. package/dist/testing/index.d.ts.map +1 -0
  108. package/dist/testing/index.js +7 -0
  109. package/dist/testing/index.js.map +1 -0
  110. package/dist/{ClusterMachine.d.ts → unstable/cluster/ClusterMachine.d.ts} +19 -27
  111. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -0
  112. package/dist/unstable/cluster/ClusterMachine.js +126 -0
  113. package/dist/unstable/cluster/ClusterMachine.js.map +1 -0
  114. package/dist/{cluster.js → unstable/cluster/index.d.ts} +1 -1
  115. package/dist/unstable/cluster/index.d.ts.map +1 -0
  116. package/dist/{cluster.d.ts → unstable/cluster/index.js} +1 -1
  117. package/dist/unstable/cluster/index.js.map +1 -0
  118. package/dist/{AtomMachine.d.ts → unstable/reactivity/AtomMachine.d.ts} +35 -20
  119. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -0
  120. package/dist/unstable/reactivity/AtomMachine.js +113 -0
  121. package/dist/unstable/reactivity/AtomMachine.js.map +1 -0
  122. package/dist/{reactivity.js → unstable/reactivity/index.d.ts} +1 -1
  123. package/dist/unstable/reactivity/index.d.ts.map +1 -0
  124. package/dist/{reactivity.d.ts → unstable/reactivity/index.js} +1 -1
  125. package/dist/unstable/reactivity/index.js.map +1 -0
  126. package/docs/agent-guide.md +169 -31
  127. package/package.json +19 -10
  128. package/dist/AtomMachine.d.ts.map +0 -1
  129. package/dist/AtomMachine.js.map +0 -1
  130. package/dist/ClusterMachine.d.ts.map +0 -1
  131. package/dist/ClusterMachine.js.map +0 -1
  132. package/dist/cluster.d.ts.map +0 -1
  133. package/dist/cluster.js.map +0 -1
  134. package/dist/internal/machineErrors.d.ts.map +0 -1
  135. package/dist/internal/machineErrors.js.map +0 -1
  136. package/dist/internal/machineModel.d.ts.map +0 -1
  137. package/dist/internal/machineModel.js.map +0 -1
  138. package/dist/internal/machinePlanner.d.ts +0 -74
  139. package/dist/internal/machinePlanner.d.ts.map +0 -1
  140. package/dist/internal/machinePlanner.js +0 -797
  141. package/dist/internal/machinePlanner.js.map +0 -1
  142. package/dist/internal/machineProcess.d.ts.map +0 -1
  143. package/dist/internal/machineProcess.js +0 -181
  144. package/dist/internal/machineProcess.js.map +0 -1
  145. package/dist/internal/machineRuntime.d.ts.map +0 -1
  146. package/dist/internal/machineRuntime.js +0 -365
  147. package/dist/internal/machineRuntime.js.map +0 -1
  148. package/dist/reactivity.d.ts.map +0 -1
  149. package/dist/reactivity.js.map +0 -1
package/dist/Machine.d.ts CHANGED
@@ -5,17 +5,21 @@
5
5
  */
6
6
  import type * as Cause from "effect/Cause";
7
7
  import type * as Duration from "effect/Duration";
8
- import * as Effect from "effect/Effect";
9
- import * as Option from "effect/Option";
10
- import { type Pipeable } from "effect/Pipeable";
8
+ import type * as Effect from "effect/Effect";
9
+ import type * as Option from "effect/Option";
10
+ import type { Pipeable } from "effect/Pipeable";
11
11
  import type * as Schema from "effect/Schema";
12
12
  import type * as Scope from "effect/Scope";
13
13
  import type * as Stream from "effect/Stream";
14
14
  import type * as Types from "effect/Types";
15
- import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, ProcessLocalError, StartupError, StoppedError } from "./internal/machineErrors.js";
16
- import * as Model from "./internal/machineModel.js";
17
- import * as internalPlanner from "./internal/machinePlanner.js";
18
- import * as internalRuntime from "./internal/machineRuntime.js";
15
+ import type * as Activities from "./internal/machine/activities.js";
16
+ import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, StartupError, StoppedError } from "./internal/machine/machine.js";
17
+ import * as internal from "./internal/machine/machine.js";
18
+ import { InitialEventTypeId } from "./internal/machine/machine.js";
19
+ import type { EnsureExecutable } from "./internal/machine/readiness.js";
20
+ import type * as internalRuntime from "./internal/machine/runtime.js";
21
+ import type * as StateDefinition from "./internal/machine/stateDefinition.js";
22
+ import type * as Topology from "./internal/machine/topology.js";
19
23
  /**
20
24
  * String literal type used as the runtime type identifier for `Machine`
21
25
  * values.
@@ -40,7 +44,7 @@ declare const MachineTypeId: unique symbol;
40
44
  * @category type IDs
41
45
  * @since 4.0.0
42
46
  */
43
- export declare const InitialEventTypeId: typeof internalPlanner.InitialEventTypeId;
47
+ export { InitialEventTypeId };
44
48
  /**
45
49
  * Synthetic event passed to entry, exit, always, invoke, and output callbacks
46
50
  * that run while the machine is settling its initial state.
@@ -131,13 +135,16 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
131
135
  /** @internal */
132
136
  readonly stateNodes: Machine.StateNodes;
133
137
  /** @internal */
134
- readonly makeTargetBuilder: <Source extends Machine.StateIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
138
+ readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
135
139
  /** @internal */
136
140
  readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
137
141
  /**
138
142
  * Adds typed state handlers and returns the refined machine definition.
139
143
  * Successive calls implement the remaining unhandled states while retaining
140
144
  * accumulated errors, services, final states, and output evidence.
145
+ * Event dispatch maps and transition descriptors are captured by value, so
146
+ * later mutation of the objects supplied to this call cannot alter the
147
+ * resulting machine.
141
148
  *
142
149
  * @since 4.0.0
143
150
  */
@@ -201,7 +208,7 @@ StartupError,
201
208
  * @category errors
202
209
  * @since 4.0.0
203
210
  */
204
- StoppedError } from "./internal/machineErrors.js";
211
+ StoppedError } from "./internal/machine/machine.js";
205
212
  declare const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement";
206
213
  declare const ActionRequirementTypeId = "~effect/Machine/ActionRequirement";
207
214
  type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
@@ -247,7 +254,7 @@ export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequire
247
254
  */
248
255
  export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>, MachineRuntimeRequirement> | Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>;
249
256
  /**
250
- * Runtime capability available to machine actions.
257
+ * Managed runtime capability used to deliver raised and emitted events.
251
258
  *
252
259
  * @category models
253
260
  * @since 4.0.0
@@ -266,6 +273,39 @@ export interface Runtime<in Events, in Emits> {
266
273
  */
267
274
  readonly sendParent: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
268
275
  }
276
+ /**
277
+ * Synchronous commands available while a machine transition is being
278
+ * selected. Enqueuing only records statechart and actor operations; it never
279
+ * executes an Effect.
280
+ *
281
+ * @category models
282
+ * @since 4.0.0
283
+ */
284
+ export interface Enqueue<in Events, in Emits> {
285
+ /** Raises an event inside the current macrostep. */
286
+ readonly raise: (event: Events) => void;
287
+ /** Emits an event through the machine's parent boundary. */
288
+ readonly emit: (event: Emits) => void;
289
+ /** Sends an event to an invoked child after the transition is selected. */
290
+ readonly sendTo: {
291
+ <Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): void;
292
+ <Address extends ChildAddress<never>>(child: Address, event: ChildAddress.Event<Address>): void;
293
+ };
294
+ /** Stops an invoked child after the transition is selected. */
295
+ readonly stop: {
296
+ <Child extends ChildMachine.Any>(child: Child): void;
297
+ <Event>(child: ChildAddress<Event>): void;
298
+ };
299
+ }
300
+ /** A closed actor command recorded by a synchronous machine transition. */
301
+ export type Command = {
302
+ readonly _tag: "SendTo";
303
+ readonly child: ChildMachine.Any | ChildAddress<never>;
304
+ readonly event: unknown;
305
+ } | {
306
+ readonly _tag: "Stop";
307
+ readonly child: ChildMachine.Any | ChildAddress<never>;
308
+ };
269
309
  /**
270
310
  * Namespace containing type-level members associated with `Runtime`.
271
311
  *
@@ -273,7 +313,7 @@ export interface Runtime<in Events, in Emits> {
273
313
  */
274
314
  export declare namespace Runtime {
275
315
  /**
276
- * Protocol annotation accepted by {@link runtime}.
316
+ * Protocol annotation for managed event delivery.
277
317
  *
278
318
  * @category models
279
319
  * @since 4.0.0
@@ -315,44 +355,66 @@ export declare namespace Runtime {
315
355
  }
316
356
  type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
317
357
  type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
318
- declare const InvokeTypeId: unique symbol;
319
- type StateDefinitionError<Message extends string> = {
358
+ declare const InvokeTypeId: typeof internal.InvokeTypeId;
359
+ type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
320
360
  readonly "~effect/Machine/DefinitionError": Message;
361
+ readonly path: Path;
362
+ readonly details: Details;
321
363
  };
322
364
  type ActiveStateKey<States extends Machine.StateSchemas> = Machine.ActiveStateKey<States>;
323
365
  type HistoryStateKey<States extends Machine.StateSchemas> = Machine.HistoryStateKey<States>;
324
- type ValidateStateTree<States extends Machine.StateSchemas, AllowHistory extends boolean = false> = {
325
- readonly [Key in keyof States]: ValidateStateNode<States[Key], AllowHistory>;
366
+ type ChoiceStateKey<States extends Machine.StateSchemas> = Machine.ChoiceStateKey<States>;
367
+ type StateDefinitionPath<Prefix extends string, Key extends PropertyKey> = Key extends string ? Key extends "" ? Prefix extends "" ? "<empty>" : `${Prefix}.<empty>` : Prefix extends "" ? Key : `${Prefix}.${Key}` : Key extends number ? Prefix extends "" ? `${Key}` : `${Prefix}.${Key}` : Prefix extends "" ? "<symbol>" : `${Prefix}.<symbol>`;
368
+ type ValidateStateKey<Key extends PropertyKey, Prefix extends string> = Key extends symbol ? StateDefinitionError<"State keys must be strings, not symbols", StateDefinitionPath<Prefix, Key>, Key> : Key extends number ? StateDefinitionError<"State keys cannot use numeric forms", StateDefinitionPath<Prefix, Key>, Key> : Key extends "" ? StateDefinitionError<"State keys cannot be empty", StateDefinitionPath<Prefix, Key>, Key> : Key extends "__proto__" ? StateDefinitionError<"The state key \"__proto__\" is not allowed", StateDefinitionPath<Prefix, Key>, Key> : Key extends `${string}.${string}` ? StateDefinitionError<"State keys cannot contain \".\"", StateDefinitionPath<Prefix, Key>, Key> : Key extends `${number}` ? StateDefinitionError<"State keys cannot use numeric forms", StateDefinitionPath<Prefix, Key>, Key> : unknown;
369
+ type ValidateStateTree<States extends Machine.StateSchemas, AllowHistory extends boolean = false, Prefix extends string = ""> = {
370
+ readonly [Key in keyof States]: ValidateStateKey<Key, Prefix> & ValidateStateNode<States[Key], AllowHistory, StateDefinitionPath<Prefix, Key>>;
326
371
  };
327
- type ValidateStateNode<Node, AllowHistory extends boolean> = Node extends Machine.HistoryStateNodeConfig ? AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state"> : Node extends Machine.TaggedSchema ? unknown : Node extends {
372
+ type UnknownStateNodeProperty<Node, Kind extends StateDefinition.StateNodeKind> = Exclude<keyof Node, StateDefinition.AllowedStateNodeProperty<Kind>>;
373
+ type ValidateExactStateNodeProperties<Node, Kind extends StateDefinition.StateNodeKind, Path extends PropertyKey> = [UnknownStateNodeProperty<Node, Kind>] extends [never] ? unknown : StateDefinitionError<"State nodes cannot declare properties outside their state kind", Path, Extract<UnknownStateNodeProperty<Node, Kind>, PropertyKey>>;
374
+ type UnknownPseudoAnnotationProperty<Node> = Node extends {
375
+ readonly annotations: infer Annotations;
376
+ } ? Exclude<keyof Annotations, StateDefinition.AllowedPseudoStateAnnotationProperty> : never;
377
+ type ValidatePseudoStateAnnotations<Node, Path extends PropertyKey> = [UnknownPseudoAnnotationProperty<Node>] extends [
378
+ never
379
+ ] ? unknown : StateDefinitionError<"Pseudo-state annotations contain unknown properties", Path, Extract<UnknownPseudoAnnotationProperty<Node>, PropertyKey>>;
380
+ type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends {
328
381
  readonly schema: Machine.TaggedSchema;
329
- } ? ValidateStateNodeConfig<Node> : StateDefinitionError<"State nodes must be tagged schemas or state node configs">;
382
+ } ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
330
383
  type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
331
- Extract<keyof Node, "schema" | "states" | "initial" | "output">
384
+ Extract<keyof Node, "schema" | "states" | "initial" | "output" | "choice">
332
385
  ] extends [never] ? unknown : StateDefinitionError<"History states cannot declare schemas, children, initial states, or output">;
386
+ type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
387
+ Extract<keyof Node, "schema" | "states" | "initial" | "output" | "history">
388
+ ] extends [never] ? unknown : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">;
333
389
  type ValidateStateNodeConfig<Node extends {
334
390
  readonly schema: Machine.TaggedSchema;
335
- }> = Node extends {
391
+ }, Path extends PropertyKey> = Node extends {
392
+ readonly type: "parallel";
393
+ } ? ValidateExactStateNodeProperties<Node, "parallel", Path> & ValidateStateNodeWithChildren<Node, Node extends {
394
+ readonly states: infer Children;
395
+ } ? Children : never, Path> : Node extends {
396
+ readonly type: "final";
397
+ } ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> : Node extends {
336
398
  readonly states: infer Children;
337
- } ? ValidateStateNodeWithChildren<Node, Children> : ValidateStateNodeWithoutChildren<Node>;
399
+ } ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node>;
338
400
  type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
339
401
  readonly output: Schema.Top;
340
402
  } ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
341
403
  type ValidateStateNodeWithChildren<Node extends {
342
404
  readonly schema: Machine.TaggedSchema;
343
- }, Children> = Children extends Machine.StateSchemas ? Node extends {
405
+ }, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
344
406
  readonly type: "final";
345
407
  } ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
346
408
  readonly type: "parallel";
347
409
  } ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
348
- readonly states: ValidateStateTree<Children, true>;
349
- } & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children> : StateDefinitionError<"Child states must be a state tree">;
410
+ readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
411
+ } & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
350
412
  type ValidateCompoundStateNode<Node extends {
351
413
  readonly schema: Machine.TaggedSchema;
352
- }, Children extends Machine.StateSchemas> = Node extends {
414
+ }, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
353
415
  readonly initial: infer Initial;
354
- } ? Initial extends ActiveStateKey<Children> ? {
355
- readonly states: ValidateStateTree<Children, true>;
416
+ } ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
417
+ readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
356
418
  } : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
357
419
  type ValidateStateNodeWithoutChildren<Node extends {
358
420
  readonly schema: Machine.TaggedSchema;
@@ -362,7 +424,7 @@ type ValidateStateNodeWithoutChildren<Node extends {
362
424
  type DefineStateTreeInput<States extends Machine.StateSchemas> = {
363
425
  readonly [Key in keyof States]: DefineStateNodeInput<States[Key]>;
364
426
  };
365
- type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends {
427
+ type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends Machine.ChoiceStateNodeConfig ? Machine.ChoiceStateNodeConfig : Node extends {
366
428
  readonly type: "parallel";
367
429
  readonly states: infer Children extends Machine.StateSchemas;
368
430
  } ? Omit<Node, "states"> & {
@@ -370,7 +432,7 @@ type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Nod
370
432
  } : Node extends {
371
433
  readonly states: infer Children extends Machine.StateSchemas;
372
434
  } ? Omit<Node, "initial" | "states"> & {
373
- readonly initial: ActiveStateKey<Children>;
435
+ readonly initial: ActiveStateKey<Children> | ChoiceStateKey<Children>;
374
436
  readonly states: DefineStateTreeInput<Children>;
375
437
  } : Node;
376
438
  type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends [
@@ -393,7 +455,7 @@ type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen
393
455
  ] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag extends Seen ? Tag | DuplicateEventTag<Tail, Seen> : DuplicateEventTag<Tail, Seen | Tag> : never : never;
394
456
  type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
395
457
  type ValidateInternalEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInternal extends PropertyKey = DuplicateEventTag<InternalEvents>, Overlap extends PropertyKey = Extract<Machine.TagOf<InputEvents[number]>, Machine.TagOf<InternalEvents[number]>>> = [DuplicateInternal] extends [never] ? [Overlap] extends [never] ? unknown : EventProtocolError<"Public and internal event tags must be disjoint", Overlap> : EventProtocolError<"Internal event tags must be unique", DuplicateInternal>;
396
- declare const SnapshotBuilderStateTypeId: unique symbol;
458
+ declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
397
459
  declare const SnapshotBuilderConstructionTypeId: unique symbol;
398
460
  type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
399
461
  readonly [SnapshotBuilderStateTypeId]: Regions;
@@ -421,6 +483,8 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
421
483
  } : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
422
484
  type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
423
485
  readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
486
+ } & {
487
+ readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
424
488
  };
425
489
  type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
426
490
  type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
@@ -432,10 +496,10 @@ type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId exten
432
496
  ] : Node extends {
433
497
  readonly states: infer Children extends Machine.StateSchemas;
434
498
  } ? Node extends {
435
- readonly initial: infer Initial extends ActiveStateKey<Children>;
499
+ readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
436
500
  } ? [
437
501
  value: Machine.NodeSchema<Node>["Type"],
438
- state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSnapshotResult<Children, Initial, Path>
502
+ state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
439
503
  ] : never : [value: Machine.NodeSchema<Node>["Type"]] : never;
440
504
  type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
441
505
  readonly type: "parallel";
@@ -446,10 +510,10 @@ type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId e
446
510
  ] : Node extends {
447
511
  readonly states: infer Children extends Machine.StateSchemas;
448
512
  } ? Node extends {
449
- readonly initial: infer Initial extends ActiveStateKey<Children>;
513
+ readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
450
514
  } ? [
451
515
  input: Machine.NodeSchema<Node>["~type.make.in"],
452
- state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSnapshotResult<Children, Initial, Path>>
516
+ state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
453
517
  ] : never : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
454
518
  type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
455
519
  readonly type: "parallel";
@@ -457,8 +521,9 @@ type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends
457
521
  } ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
458
522
  readonly states: infer Children extends Machine.StateSchemas;
459
523
  } ? Node extends {
460
- readonly initial: infer Initial extends ActiveStateKey<Children>;
461
- } ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSnapshotResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]> : never;
524
+ readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
525
+ } ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]> : never;
526
+ type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
462
527
  type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
463
528
  readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
464
529
  };
@@ -473,6 +538,8 @@ type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends
473
538
  };
474
539
  type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
475
540
  readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix>;
541
+ } & {
542
+ readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
476
543
  };
477
544
  type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
478
545
  type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
@@ -485,7 +552,7 @@ type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends
485
552
  readonly states: infer Children extends Machine.StateSchemas;
486
553
  } ? [
487
554
  value: Machine.NodeSchema<Node>["Type"],
488
- state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path>
555
+ state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
489
556
  ] : [value: Machine.NodeSchema<Node>["Type"]] : never;
490
557
  type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
491
558
  readonly type: "parallel";
@@ -497,7 +564,7 @@ type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId exte
497
564
  readonly states: infer Children extends Machine.StateSchemas;
498
565
  } ? [
499
566
  input: Machine.NodeSchema<Node>["~type.make.in"],
500
- state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path>>
567
+ state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
501
568
  ] : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
502
569
  type FullSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>;
503
570
  type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
@@ -509,13 +576,68 @@ type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends str
509
576
  }, true>>;
510
577
  };
511
578
  };
579
+ type HistorySnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
580
+ readonly type: "parallel";
581
+ readonly states: infer Children extends Machine.StateSchemas;
582
+ } ? [
583
+ value: Machine.NodeSchema<Node>["Type"],
584
+ states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
585
+ ] : Node extends {
586
+ readonly states: infer Children extends Machine.StateSchemas;
587
+ } ? [
588
+ value: Machine.NodeSchema<Node>["Type"],
589
+ state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
590
+ ] : never : never;
591
+ type HistorySnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
592
+ readonly type: "parallel";
593
+ readonly states: infer Children extends Machine.StateSchemas;
594
+ } ? [
595
+ input: Machine.NodeSchema<Node>["~type.make.in"],
596
+ states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
597
+ ] : Node extends {
598
+ readonly states: infer Children extends Machine.StateSchemas;
599
+ } ? [
600
+ input: Machine.NodeSchema<Node>["~type.make.in"],
601
+ state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
602
+ ] : never : never;
603
+ type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotResult<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
604
+ readonly type: "parallel";
605
+ readonly states: infer Children extends Machine.StateSchemas;
606
+ } ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
607
+ readonly states: infer Children extends Machine.StateSchemas;
608
+ } ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
609
+ type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
610
+ type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
611
+ readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
612
+ }[ActiveStateKey<States>];
613
+ type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
614
+ readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
615
+ };
616
+ type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
617
+ readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
618
+ };
619
+ type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
620
+ readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? ((...args: HistorySnapshotArguments<States, Key, Prefix, Owner>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
621
+ readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
622
+ }, Constructed>) & {
623
+ readonly from: FromCallable<HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
624
+ readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
625
+ }, true>>;
626
+ } : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
627
+ readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
628
+ }, Constructed>) & {
629
+ readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
630
+ readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
631
+ }, true>>;
632
+ };
633
+ };
512
634
  type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}` ? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent : never;
513
635
  type IsCompoundNode<Node> = Node extends {
514
636
  readonly type: "parallel";
515
637
  } ? false : Node extends {
516
638
  readonly states: Machine.StateSchemas;
517
639
  } ? true : false;
518
- type NearestCompoundScope<States extends Machine.StateSchemas, Source extends Machine.StateIdentifier<States>> = IsCompoundNode<Machine.NodeByIdentifier<States, Source>> extends true ? Source : ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ? NearestCompoundScope<States, Parent> : never;
640
+ type NearestCompoundScope<States extends Machine.StateSchemas, Source extends Machine.StateNodeIdentifier<States>> = Source extends Machine.StateIdentifier<States> ? IsCompoundNode<Machine.NodeByIdentifier<States, Source>> extends true ? Source : ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ? NearestCompoundScope<States, Parent> : never : ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ? NearestCompoundScope<States, Parent> : never;
519
641
  type ChildrenOf<States extends Machine.StateSchemas, Path extends Machine.StateIdentifier<States>> = Machine.NodeByIdentifier<States, Path> extends {
520
642
  readonly states: infer Children extends Machine.StateSchemas;
521
643
  } ? Children : never;
@@ -527,11 +649,13 @@ type LocalTargetResult<AllStates extends Machine.StateSchemas, States extends Ma
527
649
  } ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : LocalTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
528
650
  type LocalTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
529
651
  readonly [Key in ActiveStateKey<States>]: LocalTargetResult<AllStates, States, Key, Prefix>;
530
- }[ActiveStateKey<States>];
531
- type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateIdentifier<AllStates>> = {
652
+ }[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
653
+ type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
532
654
  readonly [Key in ActiveStateKey<States>]: LocalTargetMethod<AllStates, States, Key, Prefix, Source>;
655
+ } & {
656
+ readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
533
657
  };
534
- type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
658
+ type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
535
659
  readonly type: "parallel";
536
660
  readonly states: infer Children extends Machine.StateSchemas;
537
661
  } ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
@@ -546,7 +670,7 @@ type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Ma
546
670
  } : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
547
671
  input: Machine.NodeSchema<Node>["~type.make.in"]
548
672
  ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
549
- type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & {
673
+ type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & {
550
674
  /**
551
675
  * Updates the value of the state containing the local group and moves to
552
676
  * one of the states inside it. Values in other active branches are kept.
@@ -564,11 +688,13 @@ type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends M
564
688
  } ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : BranchTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
565
689
  type BranchTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
566
690
  readonly [Key in ActiveStateKey<States>]: BranchTargetResult<AllStates, States, Key, Prefix>;
567
- }[ActiveStateKey<States>];
568
- type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateIdentifier<AllStates>> = {
691
+ }[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
692
+ type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
569
693
  readonly [Key in ActiveStateKey<States>]: BranchTargetMethod<AllStates, States, Key, Prefix, Source>;
694
+ } & {
695
+ readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
570
696
  };
571
- type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
697
+ type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
572
698
  readonly type: "parallel";
573
699
  readonly states: infer Children extends Machine.StateSchemas;
574
700
  } ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
@@ -583,7 +709,7 @@ type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends M
583
709
  } & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
584
710
  input: Machine.NodeSchema<Node>["~type.make.in"]
585
711
  ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
586
- type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateIdentifier<States>> = {
712
+ type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
587
713
  readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
588
714
  };
589
715
  type HistoryContainingKey<States extends Machine.StateSchemas> = {
@@ -1002,6 +1128,7 @@ export declare namespace Machine {
1002
1128
  readonly emits: ReadonlyArray<TaggedSchema>;
1003
1129
  readonly input: Schema.Top | undefined;
1004
1130
  readonly id: string | undefined;
1131
+ /** @internal */
1005
1132
  readonly stateNodes: StateNodes;
1006
1133
  /** @internal */
1007
1134
  readonly makeTargetBuilder: any;
@@ -1139,6 +1266,23 @@ export declare namespace Machine {
1139
1266
  readonly _tag: PropertyKey;
1140
1267
  };
1141
1268
  };
1269
+ /**
1270
+ * Descriptive annotations exposed for compiled state nodes.
1271
+ *
1272
+ * Schema-backed states resolve their complete Effect Schema annotation map.
1273
+ * Pseudo-states accept only the descriptive fields below. Annotations never
1274
+ * affect state identity, targeting, or runtime behavior.
1275
+ *
1276
+ * @category models
1277
+ * @since 4.0.0
1278
+ */
1279
+ interface StateNodeAnnotations extends Schema.Annotations.Annotations {
1280
+ readonly title?: string | undefined;
1281
+ readonly description?: string | undefined;
1282
+ readonly documentation?: string | undefined;
1283
+ }
1284
+ /** Descriptive annotations accepted by schema-less pseudo-states. */
1285
+ type PseudoStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
1142
1286
  /**
1143
1287
  * Configuration accepted for an atomic object state node.
1144
1288
  *
@@ -1183,6 +1327,9 @@ export declare namespace Machine {
1183
1327
  *
1184
1328
  * History nodes are transition targets only. They never become active and
1185
1329
  * therefore do not declare a state value schema or lifecycle handlers.
1330
+ * Both recorded history and a first-use default can rebuild inactive
1331
+ * ancestors. A default is a complete root configuration containing the
1332
+ * history owner, so its validity is independent of the transition source.
1186
1333
  *
1187
1334
  * @category models
1188
1335
  * @since 4.0.0
@@ -1191,6 +1338,21 @@ export declare namespace Machine {
1191
1338
  readonly type: "history";
1192
1339
  /** Defaults to shallow history. */
1193
1340
  readonly history?: "shallow" | "deep";
1341
+ readonly annotations?: PseudoStateAnnotations;
1342
+ }
1343
+ /**
1344
+ * Transient decision pseudo-state resolved immediately when targeted.
1345
+ *
1346
+ * Choice nodes have no value and never belong to an active configuration.
1347
+ * Their required `choice` implementation uses ordinary TypeScript or an
1348
+ * Effect to select a typed target.
1349
+ *
1350
+ * @category models
1351
+ * @since 4.0.0
1352
+ */
1353
+ interface ChoiceStateNodeConfig {
1354
+ readonly type: "choice";
1355
+ readonly annotations?: PseudoStateAnnotations;
1194
1356
  }
1195
1357
  /**
1196
1358
  * Configuration accepted for an object state node.
@@ -1198,10 +1360,13 @@ export declare namespace Machine {
1198
1360
  * @category models
1199
1361
  * @since 4.0.0
1200
1362
  */
1201
- type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig;
1363
+ type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig | ChoiceStateNodeConfig;
1202
1364
  /**
1203
1365
  * Object state tree keyed by state path.
1204
1366
  *
1367
+ * Keys must be non-empty, non-numeric strings without `.`. The
1368
+ * prototype-mutating key `__proto__` and symbol keys are not accepted.
1369
+ *
1205
1370
  * @category models
1206
1371
  * @since 4.0.0
1207
1372
  */
@@ -1284,33 +1449,171 @@ export declare namespace Machine {
1284
1449
  * @since 4.0.0
1285
1450
  */
1286
1451
  type ValidateStateSchemas<States extends StateSchemas> = ValidateStateTree<States>;
1452
+ /** Properties shared by every compiled state-node variant. */
1453
+ interface StateNodeBase<Path extends string = string> {
1454
+ readonly path: Path;
1455
+ readonly key: string;
1456
+ /** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
1457
+ readonly annotations: Readonly<StateNodeAnnotations> | undefined;
1458
+ readonly order: number;
1459
+ }
1460
+ /** Runtime metadata for a compiled atomic state. */
1461
+ interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1462
+ readonly type: "atomic";
1463
+ readonly schema: TaggedSchema;
1464
+ readonly output: undefined;
1465
+ readonly history: undefined;
1466
+ readonly parent: ActivePath | undefined;
1467
+ readonly children: readonly [];
1468
+ readonly initial: undefined;
1469
+ }
1470
+ /** Runtime metadata for a compiled compound state. */
1471
+ interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
1472
+ readonly type: "compound";
1473
+ readonly schema: TaggedSchema;
1474
+ readonly output: undefined;
1475
+ readonly history: undefined;
1476
+ readonly parent: ActivePath | undefined;
1477
+ /** Active child paths. Pseudo-states are available through their `parent` relationship. */
1478
+ readonly children: ReadonlyArray<ActivePath>;
1479
+ readonly initial: ActivePath | ChoicePath;
1480
+ }
1481
+ /** Runtime metadata for a compiled parallel state. */
1482
+ interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1483
+ readonly type: "parallel";
1484
+ readonly schema: TaggedSchema;
1485
+ readonly output: Schema.Top | undefined;
1486
+ readonly history: undefined;
1487
+ readonly parent: ActivePath | undefined;
1488
+ /** Active child paths. Pseudo-states are available through their `parent` relationship. */
1489
+ readonly children: ReadonlyArray<ActivePath>;
1490
+ readonly initial: undefined;
1491
+ }
1492
+ /** Runtime metadata for a compiled final state. */
1493
+ interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1494
+ readonly type: "final";
1495
+ readonly schema: TaggedSchema;
1496
+ readonly output: Schema.Top | undefined;
1497
+ readonly history: undefined;
1498
+ readonly parent: ActivePath | undefined;
1499
+ readonly children: readonly [];
1500
+ readonly initial: undefined;
1501
+ }
1502
+ /** Runtime metadata for a compiled history pseudo-state. */
1503
+ interface HistoryStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
1504
+ readonly type: "history";
1505
+ readonly schema: undefined;
1506
+ readonly output: undefined;
1507
+ readonly history: "shallow" | "deep";
1508
+ readonly parent: ActivePath;
1509
+ readonly children: readonly [];
1510
+ readonly initial: undefined;
1511
+ }
1512
+ /** Runtime metadata for a compiled choice pseudo-state. */
1513
+ interface ChoiceStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
1514
+ readonly type: "choice";
1515
+ readonly schema: undefined;
1516
+ readonly output: undefined;
1517
+ readonly history: undefined;
1518
+ readonly parent: ActivePath;
1519
+ readonly children: readonly [];
1520
+ readonly initial: undefined;
1521
+ }
1287
1522
  /**
1288
1523
  * Runtime metadata for a compiled state node.
1289
1524
  *
1525
+ * The `type` discriminator narrows every kind-specific topology and schema
1526
+ * property while preserving a uniform inspection shape.
1527
+ *
1290
1528
  * @category models
1291
1529
  * @since 4.0.0
1292
1530
  */
1293
- interface StateNode {
1294
- readonly path: string;
1295
- readonly key: string;
1296
- readonly schema: TaggedSchema | undefined;
1297
- readonly output: Schema.Top | undefined;
1298
- readonly type: "atomic" | "compound" | "parallel" | "final" | "history";
1299
- readonly history: "shallow" | "deep" | undefined;
1300
- readonly parent: string | undefined;
1301
- readonly children: ReadonlyArray<string>;
1302
- readonly initial: string | undefined;
1303
- readonly order: number;
1304
- }
1531
+ type ActiveStateNode<ActivePath extends string = string, ChoicePath extends string = ActivePath> = AtomicStateNode<ActivePath, ActivePath> | CompoundStateNode<ActivePath, ActivePath, ChoicePath> | ParallelStateNode<ActivePath, ActivePath> | FinalStateNode<ActivePath, ActivePath>;
1532
+ type StateNode<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> = ActiveStateNode<ActivePath, ChoicePath> | HistoryStateNode<HistoryPath, ActivePath> | ChoiceStateNode<ChoicePath, ActivePath>;
1305
1533
  /**
1306
1534
  * Runtime lookup table for state nodes.
1307
1535
  *
1308
1536
  * @category models
1309
1537
  * @since 4.0.0
1310
1538
  */
1311
- interface StateNodes {
1312
- readonly byPath: ReadonlyMap<string, StateNode>;
1313
- readonly roots: ReadonlyArray<string>;
1539
+ interface StateNodes<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> {
1540
+ readonly byPath: ReadonlyMap<ActivePath | HistoryPath | ChoicePath, StateNode<ActivePath, HistoryPath, ChoicePath>>;
1541
+ readonly roots: ReadonlyArray<ActivePath>;
1542
+ }
1543
+ /**
1544
+ * Trigger that selects a registered transition handler.
1545
+ *
1546
+ * @category models
1547
+ * @since 4.0.0
1548
+ */
1549
+ type TransitionTrigger<EventTag extends PropertyKey = PropertyKey> = {
1550
+ readonly type: "event";
1551
+ readonly event: EventTag;
1552
+ } | {
1553
+ readonly type: "always";
1554
+ } | {
1555
+ readonly type: "done";
1556
+ } | {
1557
+ readonly type: "choice";
1558
+ };
1559
+ /**
1560
+ * Statically inspectable destination paths for a transition handler.
1561
+ * A declared parent path covers every descendant below that state.
1562
+ *
1563
+ * @category models
1564
+ * @since 4.0.0
1565
+ */
1566
+ type TransitionTargets<Path extends string = string> = {
1567
+ readonly type: "dynamic";
1568
+ } | {
1569
+ readonly type: "declared";
1570
+ readonly paths: ReadonlyArray<Path>;
1571
+ };
1572
+ /**
1573
+ * Inspectable registration for a transition handler.
1574
+ *
1575
+ * **Details**
1576
+ *
1577
+ * Event, eventless, and completion handlers may declare an upper bound of
1578
+ * possible target paths. A handler without that declaration is explicitly
1579
+ * reported as dynamic. The source, trigger, and reentry behavior are
1580
+ * available without executing the handler.
1581
+ *
1582
+ * @category models
1583
+ * @since 4.0.0
1584
+ */
1585
+ interface TransitionDefinition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
1586
+ readonly source: SourcePath;
1587
+ readonly trigger: TransitionTrigger<EventTag>;
1588
+ readonly reenter: boolean;
1589
+ readonly targets: TransitionTargets<TargetPath>;
1590
+ }
1591
+ /**
1592
+ * Serializable description of state-owned work.
1593
+ *
1594
+ * Static invoke descriptors expose their lifecycle id and kind without
1595
+ * retaining Effects, closures, services, or child runtimes. A function-valued
1596
+ * invoke factory is reported as dynamic and is never evaluated by inspection.
1597
+ *
1598
+ * @category models
1599
+ * @since 4.0.0
1600
+ */
1601
+ type ActivityDefinition<SourcePath extends string = string> = Activities.ActivityDefinition<SourcePath>;
1602
+ /**
1603
+ * Transition retained after hierarchy precedence and conflict resolution for
1604
+ * one planned microstep.
1605
+ *
1606
+ * @category models
1607
+ * @since 4.0.0
1608
+ */
1609
+ interface RetainedTransition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
1610
+ readonly source: SourcePath;
1611
+ readonly trigger: TransitionTrigger<EventTag>;
1612
+ readonly reenter: boolean;
1613
+ /** Path returned by the handler, including a history pseudo-state. */
1614
+ readonly target: TargetPath | undefined;
1615
+ /** Concrete path used after resolving history, otherwise equal to `target`. */
1616
+ readonly resolvedTarget: TargetPath | undefined;
1314
1617
  }
1315
1618
  /**
1316
1619
  * Constructor arguments for a machine initial state function.
@@ -1357,7 +1660,7 @@ export declare namespace Machine {
1357
1660
  * @since 4.0.0
1358
1661
  */
1359
1662
  type StateIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
1360
- readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? never : States[Key] extends {
1663
+ readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : States[Key] extends {
1361
1664
  readonly states: infer Children;
1362
1665
  } ? Children extends StateSchemas ? JoinPath<Prefix, Key> | StateIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : JoinPath<Prefix, Key> : JoinPath<Prefix, Key>;
1363
1666
  }[Extract<keyof States, string>];
@@ -1368,20 +1671,39 @@ export declare namespace Machine {
1368
1671
  * @since 4.0.0
1369
1672
  */
1370
1673
  type HistoryIdentifier<States extends StateSchemas> = HistoryIdentifierWithPrefix<States>;
1674
+ /** Extracts the transition-only choice pseudo-state paths. */
1675
+ type ChoiceIdentifier<States extends StateSchemas> = ChoiceIdentifierWithPrefix<States>;
1676
+ /**
1677
+ * Extracts every compiled state-node path, including history pseudo-states.
1678
+ *
1679
+ * @category utility types
1680
+ * @since 4.0.0
1681
+ */
1682
+ type StateNodeIdentifier<States extends StateSchemas> = StateIdentifier<States> | HistoryIdentifier<States> | ChoiceIdentifier<States>;
1371
1683
  /** @internal */
1372
1684
  type HistoryIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
1373
1685
  readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
1374
1686
  readonly states: infer Children extends StateSchemas;
1375
1687
  } ? HistoryIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
1376
1688
  }[Extract<keyof States, string>];
1689
+ /** @internal */
1690
+ type ChoiceIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
1691
+ readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
1692
+ readonly states: infer Children extends StateSchemas;
1693
+ } ? ChoiceIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
1694
+ }[Extract<keyof States, string>];
1377
1695
  /** Active keys directly declared in a state tree. */
1378
1696
  type ActiveStateKey<States extends StateSchemas> = {
1379
- readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? never : Key;
1697
+ readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : Key;
1380
1698
  }[Extract<keyof States, string>];
1381
1699
  /** History pseudo-state keys directly declared in a state tree. */
1382
1700
  type HistoryStateKey<States extends StateSchemas> = {
1383
1701
  readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? Key : never;
1384
1702
  }[Extract<keyof States, string>];
1703
+ /** Choice pseudo-state keys directly declared in a state tree. */
1704
+ type ChoiceStateKey<States extends StateSchemas> = {
1705
+ readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? Key : never;
1706
+ }[Extract<keyof States, string>];
1385
1707
  /**
1386
1708
  * Active states that must implement implicit initial-value construction for
1387
1709
  * shallow history restoration.
@@ -1392,12 +1714,20 @@ export declare namespace Machine {
1392
1714
  type RequiredHistoryInitializers<States extends StateSchemas> = [HistoryIdentifier<States>] extends [never] ? never : Extract<RequiredHistoryInitializersWithPrefix<States, States, "">, StateIdentifier<States>>;
1393
1715
  /** Active parent states that own one or more history pseudo-states. */
1394
1716
  type HistoryParentIdentifier<States extends StateSchemas> = HistoryIdentifier<States> extends infer HistoryId ? HistoryId extends string ? Extract<ImmediateParentStateIdentifier<HistoryId>, StateIdentifier<States>> : never : never;
1717
+ /** Active parent states that own one or more choice pseudo-states. */
1718
+ type ChoiceParentIdentifier<States extends StateSchemas> = ChoiceIdentifier<States> extends infer ChoiceId ? ChoiceId extends string ? Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>> : never : never;
1395
1719
  /** History defaults and implicit initializers that remain unimplemented. */
1396
1720
  type MissingHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, HistoryParentIdentifier<States> | RequiredHistoryInitializers<States>>;
1721
+ /** Choice-owning active parents that remain unimplemented. */
1722
+ type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
1723
+ /** @internal Readiness proof for required choice resolvers. */
1724
+ type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
1725
+ readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>;
1726
+ };
1397
1727
  /** @internal Readiness proof required by planning and managed execution. */
1398
- type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
1728
+ type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
1399
1729
  readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
1400
- };
1730
+ }) & EnsureChoiceImplementations<States, UnhandledStates>;
1401
1731
  /**
1402
1732
  * Extracts a state-tree node by state path.
1403
1733
  *
@@ -1443,13 +1773,6 @@ export declare namespace Machine {
1443
1773
  * @since 4.0.0
1444
1774
  */
1445
1775
  type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
1446
- /**
1447
- * Runtime capability specialized to a machine's event protocols.
1448
- *
1449
- * @category utility types
1450
- * @since 4.0.0
1451
- */
1452
- type RuntimeEffect<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>> = Effect.Effect<Runtime<EventOf<Events>, EmitOf<Emits>>, never, Runtime.Requirement<EventOf<Events>, EmitOf<Emits>>>;
1453
1776
  /**
1454
1777
  * Extracts a state value from a state definition by identifier.
1455
1778
  *
@@ -1755,6 +2078,17 @@ export declare namespace Machine {
1755
2078
  } ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : States[StateId] extends {
1756
2079
  readonly states: infer Children;
1757
2080
  } ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>;
2081
+ /**
2082
+ * Extracts a complete root snapshot whose selected configuration contains a
2083
+ * particular active state.
2084
+ *
2085
+ * Parallel ancestors still require every region, while compound ancestors
2086
+ * are narrowed to the branch leading to `Owner`.
2087
+ *
2088
+ * @category utility types
2089
+ * @since 4.0.0
2090
+ */
2091
+ type CompleteSnapshotContaining<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotWithPrefix<States, Owner, "">;
1758
2092
  /**
1759
2093
  * Extracts the union of statechart snapshots represented by a state
1760
2094
  * definition.
@@ -1798,7 +2132,11 @@ export declare namespace Machine {
1798
2132
  */
1799
2133
  type EventByTag<Events extends ReadonlyArray<TaggedSchema>, Tag extends TagOf<Events[number]>> = Extract<EventOf<Events>, {
1800
2134
  readonly _tag: Tag;
1801
- }>;
2135
+ }> | (EventOf<Events> extends infer Event ? Event extends {
2136
+ readonly _tag: infer EventTag extends PropertyKey;
2137
+ } ? [EventTag] extends [Tag] ? never : [Tag] extends [EventTag] ? Omit<Event, "_tag"> & {
2138
+ readonly _tag: Tag;
2139
+ } : never : never : never);
1802
2140
  /**
1803
2141
  * Opaque state construction returned by a builder's `.from` method.
1804
2142
  *
@@ -1810,7 +2148,7 @@ export declare namespace Machine {
1810
2148
  * @since 4.0.0
1811
2149
  */
1812
2150
  interface StateConstruction<Result> {
1813
- readonly [Model.StateConstructionTypeId]: Result;
2151
+ readonly [Topology.StateConstructionTypeId]: Result;
1814
2152
  }
1815
2153
  /**
1816
2154
  * Machine-bound target instruction accepted from transition handlers.
@@ -1819,8 +2157,8 @@ export declare namespace Machine {
1819
2157
  * @since 4.0.0
1820
2158
  */
1821
2159
  interface Target<States extends StateSchemas, StateId extends StateIdentifier<States>> {
1822
- readonly [Model.TargetTypeId]: typeof Model.TargetTypeId;
1823
- readonly [Model.TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>;
2160
+ readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
2161
+ readonly [Topology.TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>;
1824
2162
  readonly path: StateId;
1825
2163
  readonly value: StateByIdentifier<States, StateId>;
1826
2164
  readonly values?: Partial<{
@@ -1838,10 +2176,21 @@ export declare namespace Machine {
1838
2176
  * @since 4.0.0
1839
2177
  */
1840
2178
  interface HistoryTarget<States extends StateSchemas, HistoryId extends HistoryIdentifier<States>> {
1841
- readonly [Model.HistoryTargetTypeId]: typeof Model.HistoryTargetTypeId;
2179
+ readonly [Topology.HistoryTargetTypeId]: typeof Topology.HistoryTargetTypeId;
1842
2180
  readonly path: HistoryId;
1843
2181
  readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>;
1844
2182
  }
2183
+ /** Branded transient target instruction used while constructing initial states. */
2184
+ interface ChoiceTargetInstruction<ChoiceId extends string = string> {
2185
+ readonly [Topology.ChoiceTargetTypeId]: typeof Topology.ChoiceTargetTypeId;
2186
+ readonly path: ChoiceId;
2187
+ readonly parent: ParentPath<ChoiceId>;
2188
+ readonly values?: Readonly<Record<string, unknown>>;
2189
+ }
2190
+ /** Transition instruction that enters a transient choice pseudo-state. */
2191
+ interface ChoiceTarget<States extends StateSchemas, ChoiceId extends ChoiceIdentifier<States>> extends ChoiceTargetInstruction<ChoiceId> {
2192
+ readonly parent: Extract<ParentPath<ChoiceId>, StateIdentifier<States>>;
2193
+ }
1845
2194
  /** Builder containing only history pseudo-state paths. */
1846
2195
  type HistoryTargetBuilder<States extends StateSchemas> = HistoryTargetBuilderWithPrefix<States, States, "">;
1847
2196
  /**
@@ -1856,6 +2205,13 @@ export declare namespace Machine {
1856
2205
  * @since 4.0.0
1857
2206
  */
1858
2207
  type FullTargetBuilder<States extends StateSchemas> = FullSnapshotBuilderWithPrefix<States>;
2208
+ /**
2209
+ * Builder for a complete fallback configuration containing a history owner.
2210
+ *
2211
+ * @category utility types
2212
+ * @since 4.0.0
2213
+ */
2214
+ type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotBuilderWithPrefix<States, Owner>;
1859
2215
  /**
1860
2216
  * Builder for source-local transition targets.
1861
2217
  *
@@ -1867,7 +2223,7 @@ export declare namespace Machine {
1867
2223
  * @category utility types
1868
2224
  * @since 4.0.0
1869
2225
  */
1870
- type LocalTargetBuilder<States extends StateSchemas, Source extends StateIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? LocalTargetBuilderForScope<States, Scope, Source> : {} : {};
2226
+ type LocalTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? LocalTargetBuilderForScope<States, Scope, Source> : {} : {};
1871
2227
  /**
1872
2228
  * Builder for partial transition targets within the active source root.
1873
2229
  *
@@ -1879,7 +2235,7 @@ export declare namespace Machine {
1879
2235
  * @category utility types
1880
2236
  * @since 4.0.0
1881
2237
  */
1882
- type BranchTargetBuilder<States extends StateSchemas, Source extends StateIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
2238
+ type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
1883
2239
  /**
1884
2240
  * Machine-bound target builders available in transition contexts.
1885
2241
  *
@@ -1899,7 +2255,7 @@ export declare namespace Machine {
1899
2255
  * @category models
1900
2256
  * @since 4.0.0
1901
2257
  */
1902
- interface TargetBuilder<States extends StateSchemas, Source extends StateIdentifier<States>> {
2258
+ interface TargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
1903
2259
  /**
1904
2260
  * Moves to another state in the same local group. The value of the state
1905
2261
  * containing that group, and values in other active branches, are kept.
@@ -1931,42 +2287,19 @@ export declare namespace Machine {
1931
2287
  /** Restores a declared shallow or deep history pseudo-state. */
1932
2288
  readonly history: HistoryTargetBuilder<States>;
1933
2289
  }
1934
- /**
1935
- * Stages an Effect to run after the current machine step is planned.
1936
- *
1937
- * The two-argument overload returns `next` after staging the Effect, which is
1938
- * useful when a handler should stage one action and return a target without
1939
- * introducing an Effect generator.
1940
- *
1941
- * @category models
1942
- * @since 4.0.0
1943
- */
1944
- interface Action {
1945
- <E, R>(effect: Effect.Effect<void, E, R>): Effect.Effect<void, never, ActionRequirement<E, R>>;
1946
- <E, R, Next>(effect: Effect.Effect<void, E, R>, next: Next): Effect.Effect<Next, never, ActionRequirement<E, R>>;
1947
- }
1948
- /**
1949
- * Planning capabilities shared by transition and lifecycle callbacks.
1950
- *
1951
- * @category models
1952
- * @since 4.0.0
1953
- */
1954
- interface PlanningCapabilities<Events, Emits> {
1955
- readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
1956
- readonly emit: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
1957
- }
1958
2290
  /**
1959
2291
  * Context passed to a state/event handler.
1960
2292
  *
1961
2293
  * @category models
1962
2294
  * @since 4.0.0
1963
2295
  */
1964
- interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
2296
+ interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
1965
2297
  readonly state: StateByIdentifier<States, StateId>;
1966
2298
  readonly parent: ParentStateValue<States, StateId>;
1967
2299
  readonly parents: ParentStateValues<States, StateId>;
2300
+ /** Complete logical configuration captured at the start of this microstep. */
2301
+ readonly snapshot: Snapshot<States>;
1968
2302
  readonly event: EventByTag<Events, EventTag>;
1969
- readonly runtime: RuntimeEffect<Events, Emits>;
1970
2303
  /**
1971
2304
  * Provides typed builders for choosing the next active state from this
1972
2305
  * handler. Each builder documents which existing state values it keeps.
@@ -1981,12 +2314,11 @@ export declare namespace Machine {
1981
2314
  * @category models
1982
2315
  * @since 4.0.0
1983
2316
  */
1984
- interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
2317
+ interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
1985
2318
  readonly state: StateByIdentifier<States, StateId>;
1986
2319
  readonly parent: ParentStateValue<States, StateId>;
1987
2320
  readonly parents: ParentStateValues<States, StateId>;
1988
2321
  readonly event: LifecycleEvent<Events>;
1989
- readonly runtime: RuntimeEffect<Events, Emits>;
1990
2322
  }
1991
2323
  /**
1992
2324
  * Context passed to an invoked child process source.
@@ -1999,7 +2331,6 @@ export declare namespace Machine {
1999
2331
  readonly parent: ParentStateValue<States, StateId>;
2000
2332
  readonly parents: ParentStateValues<States, StateId>;
2001
2333
  readonly event: LifecycleEvent<Events>;
2002
- readonly runtime: RuntimeEffect<Events, Emits>;
2003
2334
  }
2004
2335
  /**
2005
2336
  * Context passed to an invoked child process active snapshot mapper.
@@ -2029,12 +2360,13 @@ export declare namespace Machine {
2029
2360
  * @category models
2030
2361
  * @since 4.0.0
2031
2362
  */
2032
- interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
2363
+ interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
2033
2364
  readonly state: StateByIdentifier<States, StateId>;
2034
2365
  readonly parent: ParentStateValue<States, StateId>;
2035
2366
  readonly parents: ParentStateValues<States, StateId>;
2367
+ /** Complete logical configuration captured at the start of this microstep. */
2368
+ readonly snapshot: Snapshot<States>;
2036
2369
  readonly event: LifecycleEvent<Events>;
2037
- readonly runtime: RuntimeEffect<Events, Emits>;
2038
2370
  /**
2039
2371
  * Provides typed builders for choosing the next active state from this
2040
2372
  * eventless handler. Each builder documents which existing state values it
@@ -2050,13 +2382,14 @@ export declare namespace Machine {
2050
2382
  * @category models
2051
2383
  * @since 4.0.0
2052
2384
  */
2053
- interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
2385
+ interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
2054
2386
  readonly state: StateByIdentifier<States, StateId>;
2055
2387
  readonly parent: ParentStateValue<States, StateId>;
2056
2388
  readonly parents: ParentStateValues<States, StateId>;
2389
+ /** Complete logical configuration captured at the start of this microstep. */
2390
+ readonly snapshot: Snapshot<States>;
2057
2391
  readonly event: LifecycleEvent<Events>;
2058
2392
  readonly output: CompletionOutputByIdentifier<States, StateId>;
2059
- readonly runtime: RuntimeEffect<Events, Emits>;
2060
2393
  /**
2061
2394
  * Provides typed builders for choosing the next active state after this
2062
2395
  * state completes. Each builder documents which existing state values it
@@ -2066,6 +2399,15 @@ export declare namespace Machine {
2066
2399
  */
2067
2400
  readonly target: TargetBuilder<States, StateId>;
2068
2401
  }
2402
+ /** Context passed to a transient choice resolver. There is no `state` value. */
2403
+ interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
2404
+ readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
2405
+ readonly parents: {
2406
+ readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
2407
+ };
2408
+ readonly event: LifecycleEvent<Events>;
2409
+ readonly target: TargetBuilder<States, ChoiceId>;
2410
+ }
2069
2411
  /**
2070
2412
  * Context passed to a final state output function.
2071
2413
  *
@@ -2109,14 +2451,18 @@ export declare namespace Machine {
2109
2451
  * @category utility types
2110
2452
  * @since 4.0.0
2111
2453
  */
2112
- type StateActionResult<E, R> = void | Effect.Effect<void, E, R>;
2454
+ type StateActionResult<E, R> = undefined;
2113
2455
  /**
2114
2456
  * Return value accepted from a machine initial state function.
2115
2457
  *
2116
2458
  * @category utility types
2117
2459
  * @since 4.0.0
2118
2460
  */
2119
- type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | StateConstruction<Snapshot<States>> | Effect.Effect<Snapshot<States> | StateConstruction<Snapshot<States>>, E, R>;
2461
+ type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | StateConstruction<Snapshot<States> | InitialSnapshot<States>>;
2462
+ /** Initial snapshots may transiently terminate in a declared choice node. */
2463
+ type InitialSnapshot<States extends StateSchemas> = {
2464
+ readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
2465
+ }[ActiveStateKey<States>];
2120
2466
  /**
2121
2467
  * Return value accepted from transition handlers.
2122
2468
  *
@@ -2129,7 +2475,9 @@ export declare namespace Machine {
2129
2475
  * @category utility types
2130
2476
  * @since 4.0.0
2131
2477
  */
2132
- type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>>> | void | Effect.Effect<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>>> | void, E, R>;
2478
+ type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>>> | void;
2479
+ /** A choice resolver must always select a typed target synchronously. */
2480
+ type ChoiceResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>>>;
2133
2481
  /**
2134
2482
  * Extracts the union of handler return values from a handler map.
2135
2483
  *
@@ -2177,6 +2525,12 @@ export declare namespace Machine {
2177
2525
  readonly default: (...args: any) => infer Ret;
2178
2526
  } ? Ret : never;
2179
2527
  }[keyof NonNullable<History>] : never;
2528
+ /** Extracts the return value from a choice resolver. */
2529
+ type ChoiceReturn<Config> = Config extends {
2530
+ readonly choice: {
2531
+ readonly transition: (...args: any) => infer Ret;
2532
+ };
2533
+ } ? Ret : never;
2180
2534
  /**
2181
2535
  * Extracts the return value from an event transition config.
2182
2536
  *
@@ -2303,7 +2657,7 @@ export declare namespace Machine {
2303
2657
  */
2304
2658
  type AlwaysReturn<Config> = Config extends {
2305
2659
  readonly always?: infer Always;
2306
- } ? NonNullable<Always> extends (...args: any) => infer Ret ? Ret : never : never;
2660
+ } ? EventTransitionReturn<NonNullable<Always>> : never;
2307
2661
  /**
2308
2662
  * Extracts the return value from a state completion transition.
2309
2663
  *
@@ -2312,7 +2666,7 @@ export declare namespace Machine {
2312
2666
  */
2313
2667
  type DoneReturn<Config> = Config extends {
2314
2668
  readonly onDone?: infer OnDone;
2315
- } ? NonNullable<OnDone> extends (...args: any) => infer Ret ? Ret : never : never;
2669
+ } ? EventTransitionReturn<NonNullable<OnDone>> : never;
2316
2670
  /**
2317
2671
  * Extracts the return value from a final state output function.
2318
2672
  *
@@ -2328,7 +2682,7 @@ export declare namespace Machine {
2328
2682
  * @category utility types
2329
2683
  * @since 4.0.0
2330
2684
  */
2331
- type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<StateInitialReturn<Config>> | Effect.Services<HistoryDefaultReturn<Config>> | InvokeRequirements<Config>;
2685
+ type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<StateInitialReturn<Config>> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
2332
2686
  /**
2333
2687
  * Configuration for invoking a child process while a state is active.
2334
2688
  *
@@ -2344,6 +2698,8 @@ export declare namespace Machine {
2344
2698
  readonly requirements: Types.Covariant<ChildRequirements>;
2345
2699
  readonly initialError: Types.Covariant<ChildInitialError>;
2346
2700
  };
2701
+ /** @internal Serializable descriptor metadata used by inspection. */
2702
+ readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata;
2347
2703
  readonly id: string;
2348
2704
  /**
2349
2705
  * Optional parent-local address for sending events to this invocation.
@@ -2403,15 +2759,29 @@ export declare namespace Machine {
2403
2759
  * @since 4.0.0
2404
2760
  */
2405
2761
  type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = {
2406
- readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
2407
- readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
2762
+ readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
2763
+ readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
2408
2764
  readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
2409
- readonly always?: (context: AlwaysContext<States, Events, Emits, StateId>) => HandlerResult<States, any, any>;
2410
- readonly onDone?: (context: DoneContext<States, Events, Emits, StateId>) => HandlerResult<States, any, any>;
2765
+ readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
2766
+ /** Statically declared upper bound of possible target paths. */
2767
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
2768
+ readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
2769
+ };
2770
+ readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
2771
+ /** Statically declared upper bound of possible target paths. */
2772
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
2773
+ readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
2774
+ };
2411
2775
  readonly on?: {
2412
- readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>) => HandlerResult<States, any, any>) | {
2776
+ readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
2413
2777
  readonly reenter?: boolean;
2414
- readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>) => HandlerResult<States, any, any>;
2778
+ /**
2779
+ * Upper bound of state or history paths this handler may target.
2780
+ * Returning `void` is always permitted. Declaring a parent state also
2781
+ * permits concrete descendant targets below it.
2782
+ */
2783
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
2784
+ readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
2415
2785
  };
2416
2786
  };
2417
2787
  readonly initial?: StateInitialHandler<States, Events, Emits, StateId>;
@@ -2429,22 +2799,43 @@ export declare namespace Machine {
2429
2799
  /** Context passed to an implicit child-state initializer. */
2430
2800
  type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
2431
2801
  /** Initial child value implementation for a compound or parallel state. */
2432
- type StateInitialHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = (context: StateInitialContext<States, Events, Emits, StateId>) => StateInitialValue<States, StateId> | Effect.Effect<StateInitialValue<States, StateId>, any, any>;
2802
+ type StateInitialHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = (context: StateInitialContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateInitialValue<States, StateId>;
2433
2803
  /** Context used only when a history node has no previously captured record. */
2434
- interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
2804
+ interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
2435
2805
  readonly event: LifecycleEvent<Events>;
2436
- readonly runtime: RuntimeEffect<Events, Emits>;
2437
- readonly target: FullTargetBuilder<States>;
2806
+ readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
2438
2807
  readonly parent: ParentId;
2439
2808
  }
2440
- /** Typed fallback evaluated when a history node has no record yet. */
2441
- type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>) => SnapshotByIdentifier<States, ParentId> | StateConstruction<SnapshotByIdentifier<States, ParentId>> | Effect.Effect<SnapshotByIdentifier<States, ParentId> | StateConstruction<SnapshotByIdentifier<States, ParentId>>, any, any>;
2809
+ /**
2810
+ * Typed fallback evaluated when a history node has no record yet.
2811
+ *
2812
+ * The fallback constructs a complete root configuration containing the
2813
+ * history owner. This makes the default independent of the transition source
2814
+ * and provides every inactive ancestor and required parallel region.
2815
+ */
2816
+ type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
2442
2817
  /** Default implementations keyed by direct history child. */
2443
2818
  type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
2444
2819
  readonly [Key in HistoryStateKey<Children>]?: {
2445
2820
  readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
2446
2821
  };
2447
2822
  };
2823
+ /** Required implementation for a choice pseudo-state. */
2824
+ interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
2825
+ readonly choice: {
2826
+ /** Statically inspectable upper bound of every possible target. */
2827
+ readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>];
2828
+ readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
2829
+ };
2830
+ readonly entry?: never;
2831
+ readonly exit?: never;
2832
+ readonly invoke?: never;
2833
+ readonly always?: never;
2834
+ readonly on?: never;
2835
+ readonly onDone?: never;
2836
+ readonly output?: never;
2837
+ readonly initial?: never;
2838
+ }
2448
2839
  /**
2449
2840
  * Configuration accepted for a final state.
2450
2841
  *
@@ -2452,7 +2843,7 @@ export declare namespace Machine {
2452
2843
  * @since 4.0.0
2453
2844
  */
2454
2845
  type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
2455
- readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
2846
+ readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
2456
2847
  readonly exit?: never;
2457
2848
  readonly always?: never;
2458
2849
  readonly onDone?: never;
@@ -2467,27 +2858,45 @@ export declare namespace Machine {
2467
2858
  type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = NodeByIdentifier<States, StateId> extends {
2468
2859
  readonly type: "final";
2469
2860
  } ? FinalStateConfig<States, Events, Emits, StateId> : ActiveStateConfig<States, Events, Emits, StateId, E, R>;
2861
+ type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R> : never;
2470
2862
  type HandlerChildren<Node> = Node extends {
2471
2863
  readonly states: infer Children extends StateSchemas;
2472
2864
  } ? Children : never;
2473
- type HandlerStateId<States extends StateSchemas, Path extends string> = StateIdentifierFromPath<States, Path>;
2865
+ type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
2474
2866
  type HandlerConfigPart<Config> = {
2475
2867
  readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
2476
2868
  };
2477
- type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, StateId extends StateIdentifier<AllStates>> = HandlerConfig<AllStates, Events, Emits, StateId, E, R> & (HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
2869
+ type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
2870
+ readonly states?: infer Children;
2871
+ } ? NonNullable<Children> : never : never;
2872
+ type HandlerNodeByPath<States extends StateSchemas, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
2873
+ readonly states: infer Children extends StateSchemas;
2874
+ } ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
2875
+ type HandlerConfigAtPath<Config, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
2876
+ type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
2877
+ readonly [Key in Head]?: {
2878
+ readonly states: HandlerValidationAtPath<Rest, Validation>;
2879
+ };
2880
+ } : {
2881
+ readonly [Key in Path]?: Validation;
2882
+ };
2883
+ type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R> & (StateId extends ChoiceIdentifier<AllStates> ? {
2884
+ readonly states?: never;
2885
+ readonly history?: never;
2886
+ } : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
2478
2887
  readonly states?: never;
2479
2888
  readonly history?: never;
2480
2889
  } : {
2481
- readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, StateId>;
2482
- readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, StateId, Children>;
2890
+ readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, Extract<StateId, StateIdentifier<AllStates>>>;
2891
+ readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
2483
2892
  } : {
2484
2893
  readonly states?: never;
2485
2894
  readonly history?: never;
2486
2895
  });
2487
2896
  type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, Prefix extends string> = {
2488
- readonly [Key in ActiveStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerStateId<AllStates, JoinPath<Prefix, Key>>>;
2897
+ readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
2489
2898
  };
2490
- type HandlerNodeConfigKey = "always" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
2899
+ type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
2491
2900
  type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
2492
2901
  readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
2493
2902
  };
@@ -2525,19 +2934,36 @@ export declare namespace Machine {
2525
2934
  readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an event key that does not exist", StateId, Key>;
2526
2935
  };
2527
2936
  } : unknown;
2528
- type HandlerDepth = readonly [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown];
2529
- type HandlerNextDepth<Depth extends ReadonlyArray<unknown>> = Depth extends readonly [unknown, ...infer Rest extends ReadonlyArray<unknown>] ? Rest : readonly [];
2530
- type HandlerChildrenValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown>> = "states" extends keyof Config ? Depth extends readonly [] ? {
2531
- readonly states: HandlerValidationError<"Handler nesting exceeds the supported depth", Prefix>;
2532
- } : Config extends {
2937
+ type TransitionResultTargetPath<Result> = IsAny<Result> extends true ? never : Result extends Effect.Effect<infer Success, any, any> ? TransitionResultTargetPath<Success> : Result extends StateConstruction<infer Constructed> ? TransitionResultTargetPath<Constructed> : Result extends {
2938
+ readonly path: infer Path extends string;
2939
+ } ? Path : never;
2940
+ type DeclaredTransitionTarget<Transition> = Transition extends {
2941
+ readonly targets: infer Targets extends ReadonlyArray<string>;
2942
+ } ? Targets[number] : never;
2943
+ type ExcludeDeclaredTransitionTarget<Returned, Declared extends string> = Returned extends string ? Returned extends Declared | `${Declared}.${string}` ? never : Returned : never;
2944
+ type UndeclaredTransitionTarget<Transition> = "targets" extends keyof Transition ? ExcludeDeclaredTransitionTarget<TransitionResultTargetPath<EventTransitionReturn<Transition>>, DeclaredTransitionTarget<Transition>> : never;
2945
+ type HandlerOnTargetValidationErrors<StateId extends string, On> = {
2946
+ readonly [EventTag in keyof On as [UndeclaredTransitionTarget<On[EventTag]>] extends [never] ? never : EventTag]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [event: EventTag, target: UndeclaredTransitionTarget<On[EventTag]>]>;
2947
+ };
2948
+ type HandlerOnTargetValidation<StateId extends string, Config> = "on" extends keyof Config ? Config extends {
2949
+ readonly on?: infer On;
2950
+ } ? HandlerOnTargetValidationErrors<StateId, NonNullable<On>> extends infer Errors ? keyof Errors extends never ? unknown : {
2951
+ readonly on: Errors;
2952
+ } : never : unknown : unknown;
2953
+ type HandlerDirectTargetValidation<StateId extends string, Config, Trigger extends "always" | "onDone", Transition = Config extends {
2954
+ readonly [Key in Trigger]?: infer Value;
2955
+ } ? NonNullable<Value> : never, Undeclared extends string = UndeclaredTransitionTarget<Transition>> = Trigger extends keyof Config ? [Undeclared] extends [never] ? unknown : {
2956
+ readonly [Key in Trigger]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [trigger: Trigger, target: Undeclared]>;
2957
+ } : unknown;
2958
+ type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
2533
2959
  readonly states?: infer ChildrenConfig;
2534
2960
  } ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
2535
2961
  readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
2536
- } : HandlerTreeValidation<AllStates, Children, Events, Emits, Prefix, NonNullable<ChildrenConfig>, AvailableOutputStates, HandlerNextDepth<Depth>> extends infer Validation ? unknown extends Validation ? unknown : {
2962
+ } : HandlerUnknownStateKeyValidation<Children, Prefix, NonNullable<ChildrenConfig>> extends infer Validation ? unknown extends Validation ? unknown : {
2537
2963
  readonly states: Validation;
2538
- } : never : {
2964
+ } : never : never : {
2539
2965
  readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
2540
- } : unknown : unknown;
2966
+ } : unknown;
2541
2967
  type HandlerOutputRequirementValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, AvailableOutputStates extends StateIdentifier<AllStates>, Config> = ("onDone" extends keyof Config ? [
2542
2968
  Exclude<RequiredCompletionOutputStates<AllStates, StateId>, AvailableOutputStates>
2543
2969
  ] extends [never] ? unknown : {
@@ -2549,7 +2975,15 @@ export declare namespace Machine {
2549
2975
  ] extends [never] ? unknown : {
2550
2976
  readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
2551
2977
  } : unknown : unknown);
2552
- type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown>> = HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerInvokeOutputValidation<Events, StateId, Config> & HandlerInvokeEmitsValidation<Events, StateId, Config> & HandlerInvokeSnapshotValidation<Events, StateId, Config> & HandlerChildrenValidation<AllStates, Node, Events, Emits, StateId, Config, AvailableOutputStates, Depth> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config>;
2978
+ type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerChoiceTargetValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerOnTargetValidation<StateId, Config> & HandlerDirectTargetValidation<StateId, Config, "always"> & HandlerDirectTargetValidation<StateId, Config, "onDone"> & HandlerInvokeOutputValidation<Events, StateId, Config> & HandlerInvokeEmitsValidation<Events, StateId, Config> & HandlerInvokeSnapshotValidation<Events, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
2979
+ type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
2980
+ readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
2981
+ };
2982
+ type HandlerChoiceTargetValidation<StateId extends string, Config> = Config extends {
2983
+ readonly choice: infer Choice;
2984
+ } ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
2985
+ readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
2986
+ } : unknown;
2553
2987
  type HandlerInvokeOutputValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>] extends [never] ? unknown : {
2554
2988
  readonly invoke: HandlerValidationError<"Invoked child output must be a machine event or void", StateId, Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>>;
2555
2989
  };
@@ -2560,20 +2994,9 @@ export declare namespace Machine {
2560
2994
  readonly invoke: HandlerValidationError<"Invoked child snapshot mapper must return a machine event or undefined", StateId, Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>>;
2561
2995
  };
2562
2996
  type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmitOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
2563
- type HandlerTreeNodeValidationMap<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown>> = {
2564
- readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]?: HandlerNodeValidation<AllStates, States[Key], Events, Emits, HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], AvailableOutputStates, Depth>;
2565
- };
2566
- type HandlerTreeNodeValidationErrors<Validations> = {
2567
- readonly [Key in keyof Validations as unknown extends Validations[Key] ? never : Key]?: Validations[Key];
2568
- };
2569
- type HandlerTreeNodeValidations<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown>> = HandlerTreeNodeValidationMap<AllStates, States, Events, Emits, Prefix, Config, AvailableOutputStates, Depth> extends infer Validations ? HandlerTreeNodeValidationErrors<Validations> extends infer Errors ? keyof Errors extends never ? unknown : Errors : never : never;
2570
- type HandlerTreeValidation<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown> = HandlerDepth> = HandlerUnknownStateKeyValidation<States, Prefix, Config> & HandlerTreeNodeValidations<AllStates, States, Events, Emits, Prefix, Config, AvailableOutputStates, Depth>;
2571
- type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
2572
- readonly states?: infer Children;
2573
- } ? NonNullable<Children> : never : never;
2574
- type HandlerTreeStateIds<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
2575
- readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: HandlerImplementedStateId<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key]> | HandlerNodeChildStateIds<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
2576
- }[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
2997
+ type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : HandlerValidationAtPath<StateId, Validation> : never;
2998
+ type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, Emits, Config, AvailableOutputStates, StateId> : never : never>;
2999
+ type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, Emits, Config, AvailableOutputStates>;
2577
3000
  type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "initial" extends keyof Config ? true : false : true;
2578
3001
  type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
2579
3002
  readonly states: infer Children extends StateSchemas;
@@ -2582,36 +3005,31 @@ export declare namespace Machine {
2582
3005
  } ? [
2583
3006
  Exclude<HistoryStateKey<Children>, Extract<keyof NonNullable<HistoryConfig>, string>>
2584
3007
  ] extends [never] ? true : false : false : true;
2585
- type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? StateId : never : never;
2586
- type HandlerNodeChildStateIds<AllStates extends StateSchemas, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeStateIds<AllStates, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
2587
- type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<StateInitialReturn<Config>> | Effect.Error<HistoryDefaultReturn<Config>> | InvokeError<Config>;
2588
- type HandlerTreeError<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
2589
- readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: HandlerConfigError<HandlerConfigPart<Config[Key]>> | HandlerNodeChildError<AllStates, Events, Emits, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
2590
- }[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
2591
- type HandlerNodeChildError<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeError<AllStates, Events, Emits, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
2592
- type HandlerTreeServices<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
2593
- readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: ConfigServices<HandlerConfigPart<Config[Key]>> | HandlerNodeChildServices<AllStates, Events, Emits, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
2594
- }[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
2595
- type HandlerNodeChildServices<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeServices<AllStates, Events, Emits, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
2596
- type HandlerTreeOutputStates<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
2597
- readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: HandlerOutputStates<AllStates, HandlerStateId<AllStates, JoinPath<Prefix, Key>>, HandlerConfigPart<Config[Key]>> | HandlerNodeChildOutputStates<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
2598
- }[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
2599
- type HandlerNodeChildOutputStates<AllStates extends StateSchemas, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeOutputStates<AllStates, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
2600
- type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeStateIds<AllStates, AllStates, "", Config>>, E | HandlerTreeError<AllStates, Events, Emits, AllStates, "", Config>, ExcludeCompatibleRuntime<R | HandlerTreeServices<AllStates, Events, Emits, AllStates, "", Config>, EventOf<Events>, EmitOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeOutputStates<AllStates, AllStates, "", Config>, StateIdentifier<AllStates>>, InputEvents>;
3008
+ type HandlerHasRequiredChoices<Node, Config> = Node extends {
3009
+ readonly states: infer Children extends StateSchemas;
3010
+ } ? [ChoiceStateKey<Children>] extends [never] ? true : Config extends {
3011
+ readonly states?: infer ChildrenConfig;
3012
+ } ? [
3013
+ Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
3014
+ ] extends [never] ? true : false : false : true;
3015
+ type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
3016
+ type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<StateInitialReturn<Config>> | Effect.Error<HistoryDefaultReturn<Config>> | Effect.Error<ChoiceReturn<Config>> | InvokeError<Config>;
3017
+ type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
3018
+ readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
3019
+ readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
3020
+ readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
3021
+ readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
3022
+ };
3023
+ type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
3024
+ type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmitOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents>;
2601
3025
  /**
2602
3026
  * Adds state handlers from a root state object.
2603
3027
  *
2604
- * **Gotchas**
2605
- *
2606
- * Type inference traverses up to eight nested child-state objects. Deeper
2607
- * handler trees are rejected explicitly instead of silently dropping their
2608
- * error, service, final-state, or output channels.
2609
- *
2610
3028
  * @category combinators
2611
3029
  * @since 4.0.0
2612
3030
  */
2613
3031
  interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>> {
2614
- <const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, States, Events, Emits, "", NoInfer<Config>, OutputStates | Extract<HandlerTreeOutputStates<States, States, "", NoInfer<Config>>, StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
3032
+ <const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, Events, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
2615
3033
  }
2616
3034
  /**
2617
3035
  * Any state config.
@@ -2619,16 +3037,18 @@ export declare namespace Machine {
2619
3037
  * @category utility types
2620
3038
  * @since 4.0.0
2621
3039
  */
2622
- type AnyStateConfig = StateConfig<any, any, any, any, any, any, any>;
3040
+ type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
2623
3041
  /**
2624
3042
  * Runtime event-handler map stored for a single state tag.
2625
3043
  *
2626
3044
  * @category models
2627
3045
  * @since 4.0.0
2628
3046
  */
2629
- type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>) => HandlerResult<States, E, R>) | {
3047
+ type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
2630
3048
  readonly reenter?: boolean;
2631
- readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>) => HandlerResult<States, E, R>;
3049
+ /** Statically declared upper bound of possible target paths. */
3050
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
3051
+ readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
2632
3052
  }>>;
2633
3053
  /**
2634
3054
  * Runtime state config stored for a single state tag.
@@ -2637,11 +3057,17 @@ export declare namespace Machine {
2637
3057
  * @since 4.0.0
2638
3058
  */
2639
3059
  interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
2640
- readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<E, R>;
2641
- readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<E, R>;
3060
+ readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
3061
+ readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
2642
3062
  readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
2643
- readonly always?: (context: AlwaysContext<States, Events, Emits, StateId>) => HandlerResult<States, E, R>;
2644
- readonly onDone?: (context: DoneContext<States, Events, Emits, StateId>) => HandlerResult<States, E, R>;
3063
+ readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
3064
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
3065
+ readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
3066
+ };
3067
+ readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
3068
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
3069
+ readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
3070
+ };
2645
3071
  readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
2646
3072
  readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
2647
3073
  }
@@ -2651,7 +3077,7 @@ export declare namespace Machine {
2651
3077
  * @category models
2652
3078
  * @since 4.0.0
2653
3079
  */
2654
- type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R>>>;
3080
+ type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R> | ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>>>;
2655
3081
  }
2656
3082
  /**
2657
3083
  * Returns `true` if a value is a `Machine`.
@@ -2769,6 +3195,35 @@ interface Make {
2769
3195
  * @since 4.0.0
2770
3196
  */
2771
3197
  export declare const make: Make;
3198
+ type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ? [
3199
+ input?: EventSchema["~type.make.in"]
3200
+ ] : [input: EventSchema["~type.make.in"]];
3201
+ /**
3202
+ * Constructs an event from a schema owned by a machine's protocol.
3203
+ *
3204
+ * **Details**
3205
+ *
3206
+ * The schema constructor runs exactly once. The resulting decoded event is
3207
+ * trusted by this machine and definitions derived from it with `handle`, so
3208
+ * repeated delivery does not decode the same already-constructed value again.
3209
+ * Events supplied through ordinary `send` and `plan` calls remain untrusted
3210
+ * and continue through full runtime schema validation.
3211
+ * Treat the returned event as immutable after construction.
3212
+ *
3213
+ * The schema must be one of the machine's configured public or internal event
3214
+ * schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
3215
+ *
3216
+ * **Example**
3217
+ *
3218
+ * ```ts
3219
+ * const increment = Machine.event(counter, Increment, { by: 1 })
3220
+ * yield* ref.send(increment)
3221
+ * ```
3222
+ *
3223
+ * @category constructors
3224
+ * @since 4.0.0
3225
+ */
3226
+ export declare const event: <const M extends Machine.Any, const EventSchema extends Machine.TaggedSchema>(machine: M, schema: EventSchema & ([EventSchema["Type"]] extends [Machine.Event<M>] ? unknown : never), ...args: EventConstructorArgs<EventSchema>) => EventSchema["Type"];
2772
3227
  /**
2773
3228
  * Encodes a decoded machine snapshot into a normalized data representation.
2774
3229
  *
@@ -2984,48 +3439,120 @@ type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.
2984
3439
  */
2985
3440
  export declare const invokeMachine: {
2986
3441
  <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, DoneEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
2987
- readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates> & Machine.EnsureHistoryImplementations<States, UnhandledStates>>;
3442
+ readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
2988
3443
  readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
2989
3444
  readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
2990
3445
  } & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>, DoneEvent>;
2991
3446
  <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
2992
- readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates> & Machine.EnsureHistoryImplementations<States, UnhandledStates>>;
3447
+ readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
2993
3448
  readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
2994
3449
  readonly onDone?: never;
2995
3450
  } & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>>;
2996
3451
  };
2997
3452
  /**
2998
- * Plans the initial state for a machine without running deferred actions.
3453
+ * Plans the initial state for a machine without executing actor commands.
2999
3454
  *
3000
3455
  * **Details**
3001
3456
  *
3002
- * The returned plan contains the settled initial snapshot, staged actions,
3003
- * emitted events, and optional final output. Planning may evaluate transition
3004
- * logic and follow completion, eventless, and raised-event steps, but it does
3005
- * not execute effects passed to `action`.
3457
+ * The returned plan contains the settled initial snapshot, actor commands,
3458
+ * emitted events, optional final output, and every startup microstep. Planning
3459
+ * may evaluate transition logic and follow completion, eventless, and
3460
+ * raised-event steps. Transition callbacks are evaluated synchronously.
3461
+ * `startingState` and `initialEntryPaths` describe the normalized
3462
+ * configuration before entry callbacks and settlement begin.
3006
3463
  *
3007
3464
  * **Gotchas**
3008
3465
  *
3009
- * Callers that execute a plan manually must run actions sequentially before
3010
- * publishing its state or delivering its emitted events. `start` performs this
3011
- * protocol automatically.
3466
+ * `start` executes the closed command list as part of the managed actor commit
3467
+ * protocol. Manual planners may inspect commands but need a running actor scope
3468
+ * to execute child-addressed operations.
3012
3469
  *
3013
3470
  * @see {@link plan} for planning a received event.
3014
3471
  * @see {@link start} for the managed runtime protocol.
3015
3472
  * @category constructors
3016
3473
  * @since 4.0.0
3017
3474
  */
3018
- export declare const planInitial: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates> & Machine.EnsureHistoryImplementations<States, UnhandledStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
3475
+ export declare const planInitial: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
3476
+ readonly startingState: Machine.Snapshot<States>;
3477
+ readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
3019
3478
  readonly state: Machine.Snapshot<States>;
3020
- readonly actions: ReadonlyArray<Effect.Effect<void, ActionError<InitialR | R>, ActionServices<InitialR | R>>>;
3479
+ readonly commands: ReadonlyArray<Command>;
3021
3480
  readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
3481
+ readonly microsteps: ReadonlyArray<{
3482
+ readonly next: Machine.Snapshot<States>;
3483
+ readonly event: Machine.EventOf<Events> | InitialEvent;
3484
+ readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
3485
+ readonly commands: ReadonlyArray<Command>;
3486
+ readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
3487
+ readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
3488
+ readonly exitPaths: ReadonlyArray<string>;
3489
+ readonly entryPaths: ReadonlyArray<string>;
3490
+ readonly changed: boolean;
3491
+ }>;
3022
3492
  } & ({
3023
3493
  readonly done: true;
3024
3494
  readonly output: Output;
3025
3495
  } | {
3026
3496
  readonly done: false;
3027
3497
  readonly output: undefined;
3028
- }), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, ExcludeCompatibleRuntime<PlanningServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
3498
+ }), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
3499
+ /**
3500
+ * Returns every compiled state node in definition order.
3501
+ *
3502
+ * **Details**
3503
+ *
3504
+ * The result includes atomic, compound, parallel, final, history, and choice
3505
+ * nodes together with their resolved descriptive annotations. Use each node's
3506
+ * `parent` property to reconstruct the complete hierarchy. Pseudo-states are
3507
+ * intentionally omitted from `children` because they can never appear in an
3508
+ * active configuration.
3509
+ *
3510
+ * @category getters
3511
+ * @since 4.0.0
3512
+ */
3513
+ export declare const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.StateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.HistoryIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
3514
+ /**
3515
+ * Returns every registered transition handler in state definition order.
3516
+ *
3517
+ * **Details**
3518
+ *
3519
+ * Event handlers retain their handler-key order within each source state and
3520
+ * are followed by eventless and completion handlers. This function does not
3521
+ * execute handlers. Object-form event, eventless, and completion handlers with
3522
+ * a `targets` declaration expose those possible paths; handlers without one
3523
+ * remain dynamic.
3524
+ *
3525
+ * @category getters
3526
+ * @since 4.0.0
3527
+ */
3528
+ export declare const transitionDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.TransitionDefinition<Machine.StateNodeIdentifier<Machine.States<M>>, Machine.TagOf<Machine.Events<M>[number]>, Machine.StateNodeIdentifier<Machine.States<M>>>>;
3529
+ /**
3530
+ * Returns serializable descriptions of every state-owned activity.
3531
+ *
3532
+ * **Details**
3533
+ *
3534
+ * Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
3535
+ * expose stable ownership and lifecycle metadata without serializing runtime
3536
+ * values. Function-valued invoke factories are represented as dynamic and are
3537
+ * never evaluated during inspection.
3538
+ *
3539
+ * @category getters
3540
+ * @since 4.0.0
3541
+ */
3542
+ export declare const activityDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.ActivityDefinition<Machine.StateIdentifier<Machine.States<M>>>>;
3543
+ /**
3544
+ * Returns every state node active in a decoded snapshot, in definition order.
3545
+ *
3546
+ * **Details**
3547
+ *
3548
+ * Active compound ancestors and parallel regions are included together with
3549
+ * their active descendants. History and choice pseudo-states are never active
3550
+ * and are not returned.
3551
+ *
3552
+ * @category getters
3553
+ * @since 4.0.0
3554
+ */
3555
+ export declare const configuration: <M extends Machine.Any>(machine: M, state: Machine.Snapshot<Machine.States<M>>) => ReadonlyArray<Machine.ActiveStateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
3029
3556
  /**
3030
3557
  * Returns the event tags handled by the current state snapshot.
3031
3558
  *
@@ -3034,7 +3561,7 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
3034
3561
  */
3035
3562
  export declare const enabled: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, state: Machine.Snapshot<States>) => ReadonlyArray<Machine.TagOf<Events[number]>>;
3036
3563
  /**
3037
- * Plans the next state snapshot without running deferred actions.
3564
+ * Plans the next state snapshot synchronously.
3038
3565
  *
3039
3566
  * **Details**
3040
3567
  *
@@ -3045,25 +3572,25 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
3045
3572
  *
3046
3573
  * **Gotchas**
3047
3574
  *
3048
- * `plan` returns data; it does not implement the runtime commit protocol. Run
3049
- * actions sequentially, publish `next` only after they succeed, and then
3050
- * deliver `emittedEvents`. A failed action must retain the previously
3051
- * published state and suppress emissions. Events with no enabled transition
3052
- * are ignored and produce an unchanged plan.
3575
+ * `plan` returns data; it does not implement the actor commit protocol.
3576
+ * `start` executes child commands, publishes `next`, and then delivers
3577
+ * `emittedEvents`. Events with no enabled transition are ignored and produce
3578
+ * an unchanged plan.
3053
3579
  *
3054
3580
  * @see {@link planInitial} for planning machine startup.
3055
3581
  * @see {@link start} for managed execution and lifecycle observation.
3056
3582
  * @category combinators
3057
3583
  * @since 4.0.0
3058
3584
  */
3059
- export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates> & Machine.EnsureHistoryImplementations<States, UnhandledStates>, state: Machine.Snapshot<States>, event: Machine.EventOf<InputEvents>) => Effect.Effect<{
3585
+ export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, state: Machine.Snapshot<States>, event: Machine.EventOf<InputEvents>) => Effect.Effect<{
3060
3586
  readonly next: Machine.Snapshot<States>;
3061
- readonly actions: ReadonlyArray<Effect.Effect<void, ActionError<R>, ActionServices<R>>>;
3587
+ readonly commands: ReadonlyArray<Command>;
3062
3588
  readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
3063
3589
  readonly microsteps: ReadonlyArray<{
3064
3590
  readonly next: Machine.Snapshot<States>;
3065
3591
  readonly event: Machine.EventOf<Events> | InitialEvent;
3066
- readonly actions: ReadonlyArray<Effect.Effect<void, ActionError<R>, ActionServices<R>>>;
3592
+ readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
3593
+ readonly commands: ReadonlyArray<Command>;
3067
3594
  readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
3068
3595
  readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
3069
3596
  readonly exitPaths: ReadonlyArray<string>;
@@ -3076,67 +3603,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
3076
3603
  } | {
3077
3604
  readonly done: false;
3078
3605
  readonly output: undefined;
3079
- }), E | InfiniteTransitionError | MachineSchemaDecodeError, ExcludeCompatibleRuntime<PlanningServices<R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
3080
- /**
3081
- * Defers an effectful action until the current machine step is planned.
3082
- *
3083
- * **Details**
3084
- *
3085
- * The action's error and service requirements are retained in the machine
3086
- * type without becoming requirements of `plan` or `planInitial`. The managed
3087
- * runtime executes staged actions sequentially before publishing the planned
3088
- * state. Pass a second argument when the planning Effect should return that
3089
- * value after staging.
3090
- *
3091
- * **Example** (Typed staged action)
3092
- *
3093
- * ```ts
3094
- * import { Context, Effect } from "effect"
3095
- * import { Machine } from "@typeonce/effect-machine"
3096
- *
3097
- * class Audit extends Context.Service<Audit, {
3098
- * readonly write: Effect.Effect<void, "AuditError">
3099
- * }>()("example/Audit") {}
3100
- *
3101
- * const writeAudit = Machine.action(
3102
- * Effect.flatMap(Audit, (audit) => audit.write)
3103
- * )
3104
- * ```
3105
- *
3106
- * @see {@link plan} for inspecting staged actions without executing them.
3107
- * @category combinators
3108
- * @since 4.0.0
3109
- */
3110
- export declare const action: Machine.Action;
3111
- /**
3112
- * Runs staged machine actions sequentially with the supplied runtime.
3113
- *
3114
- * **When to use**
3115
- *
3116
- * Use when you implement a commit protocol around `plan` or `planInitial` and
3117
- * need to execute their staged actions before publishing the planned snapshot.
3118
- *
3119
- * **Gotchas**
3120
- *
3121
- * This function only runs actions. The caller remains responsible for
3122
- * publishing the planned state and delivering planned emitted events after all
3123
- * actions succeed. Process-local operations such as `spawn`, `sendTo`, and
3124
- * `stopChild` fail with `ProcessLocalError` because no managed machine process
3125
- * owns the actions.
3126
- *
3127
- * @see {@link plan} for creating a transition plan.
3128
- * @see {@link planInitial} for creating an initial plan.
3129
- * @category running
3130
- * @since 4.0.0
3131
- */
3132
- export declare const runActions: <E, R, Events, Emits>(actions: Iterable<Effect.Effect<void, E, R>>, runtime: Runtime<Events, Emits>) => Effect.Effect<void, E | ProcessLocalError, Exclude<ExcludeCompatibleRuntime<R, Events, Emits>, MachineRuntimeRequirement>>;
3133
- /**
3134
- * Returns the typed runtime capability for the current machine.
3135
- *
3136
- * @category combinators
3137
- * @since 4.0.0
3138
- */
3139
- export declare const runtime: <const Protocol extends Runtime.Protocol = {}>() => Effect.Effect<Runtime<Runtime.Events<Protocol>, Runtime.Emits<Protocol>>, never, Runtime.Requirement<Runtime.Events<Protocol>, Runtime.Emits<Protocol>>>;
3606
+ }), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
3140
3607
  /**
3141
3608
  * Creates a one-shot child process from an Effect.
3142
3609
  *
@@ -3256,15 +3723,14 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
3256
3723
  *
3257
3724
  * **When to use**
3258
3725
  *
3259
- * Use to create child processes from machine actions when the child
3260
- * should be addressed or stopped by the owning machine instead of tied to a
3261
- * single state's `invoke` lifecycle.
3726
+ * Use from lower-level process logic to create children that should be
3727
+ * addressed or stopped by the owning process instead of tied to a single
3728
+ * state's `invoke` lifecycle.
3262
3729
  *
3263
3730
  * **Gotchas**
3264
3731
  *
3265
- * This effect requires the machine runtime, so it only runs from machine
3266
- * actions. A named child id must be unique for the current parent machine until
3267
- * that child stops.
3732
+ * This Effect requires a managed process runtime. A named child id must be
3733
+ * unique for the current parent until that child stops.
3268
3734
  *
3269
3735
  * @see {@link invoke} for children that start and stop with a state.
3270
3736
  * @see {@link sendTo} for sending events to named children.
@@ -3312,11 +3778,10 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
3312
3778
  *
3313
3779
  * **Details**
3314
3780
  *
3315
- * For each accepted event the runtime plans the complete macrostep, runs staged
3316
- * actions sequentially, stops invokes for exited states, publishes the new
3317
- * state, delivers emitted events, and then starts invokes for entered states.
3318
- * If an action fails, the previous published state is retained and emissions
3319
- * from that plan are suppressed.
3781
+ * For each accepted event the runtime plans the complete synchronous
3782
+ * macrostep, executes closed actor commands, stops invokes for exited states,
3783
+ * publishes the new state, delivers emitted events, and then starts invokes
3784
+ * for entered states.
3320
3785
  *
3321
3786
  * **Gotchas**
3322
3787
  *
@@ -3330,5 +3795,35 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
3330
3795
  * @category constructors
3331
3796
  * @since 4.0.0
3332
3797
  */
3333
- export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates> & Machine.EnsureHistoryImplementations<States, UnhandledStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
3798
+ export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
3799
+ /**
3800
+ * Starts a fresh managed runtime from a decoded logical snapshot.
3801
+ *
3802
+ * **Details**
3803
+ *
3804
+ * `resume` validates and normalizes the supplied snapshot before publishing it
3805
+ * as the first state. It does not call the machine's initial function, replay
3806
+ * entry or transition actions, re-deliver raised or emitted events, or
3807
+ * re-evaluate historical completion and eventless transitions. Active-state
3808
+ * invokes start once in ancestor and document order with {@link InitialEvent};
3809
+ * delayed invokes restart their complete duration and invoked machines start
3810
+ * from their own initial state.
3811
+ *
3812
+ * Only logical state, completion, and history metadata are resumed. Queues,
3813
+ * scopes, subscriptions, fibers, spawned children, invoke progress, and prior
3814
+ * runtime status are process-local and are not restored. A final snapshot
3815
+ * immediately produces a completed ref with its current-machine output.
3816
+ *
3817
+ * Decode encoded data explicitly with {@link decodeSnapshot} before calling
3818
+ * this function. Stable snapshots are hosted as supplied; newly enabled
3819
+ * eventless or completion transitions in a changed machine definition are not
3820
+ * evaluated merely because the runtime was resumed; only ordinary subsequent
3821
+ * transition planning can enter and stabilize states.
3822
+ *
3823
+ * @see {@link decodeSnapshot} for the schema and transport boundary.
3824
+ * @see {@link start} for ordinary initial startup.
3825
+ * @category constructors
3826
+ * @since 4.0.0
3827
+ */
3828
+ export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, MachineSchemaDecodeError, ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
3334
3829
  //# sourceMappingURL=Machine.d.ts.map