55 */
66
77import type * as Cause from "effect/Cause"
8- import type * as Duration from "effect/Duration"
8+ import * as Duration from "effect/Duration"
99import * as Effect from "effect/Effect"
1010import * as Inspectable from "effect/Inspectable"
1111import * as Option from "effect/Option"
@@ -15,6 +15,7 @@ import type * as Schema from "effect/Schema"
1515import type * as Scope from "effect/Scope"
1616import type * as Stream from "effect/Stream"
1717import type * as Types from "effect/Types"
18+ import * as Activities from "./internal/machineActivities.js"
1819import type {
1920 ChildAlreadyExistsError ,
2021 InfiniteTransitionError ,
@@ -1868,6 +1869,28 @@ export declare namespace Machine {
18681869 */
18691870 export type TaggedSchema = Schema . Top & { readonly Type : { readonly _tag : PropertyKey } }
18701871
1872+ /**
1873+ * Descriptive annotations exposed for compiled state nodes.
1874+ *
1875+ * Schema-backed states resolve their complete Effect Schema annotation map.
1876+ * Pseudo-states accept only the descriptive fields below. Annotations never
1877+ * affect state identity, targeting, or runtime behavior.
1878+ *
1879+ * @category models
1880+ * @since 4.0.0
1881+ */
1882+ export interface StateNodeAnnotations extends Schema . Annotations . Annotations {
1883+ readonly title ?: string | undefined
1884+ readonly description ?: string | undefined
1885+ readonly documentation ?: string | undefined
1886+ }
1887+
1888+ /** Descriptive annotations accepted by schema-less pseudo-states. */
1889+ export type PseudoStateAnnotations = Pick <
1890+ StateNodeAnnotations ,
1891+ "title" | "description" | "documentation"
1892+ >
1893+
18711894 /**
18721895 * Configuration accepted for an atomic object state node.
18731896 *
@@ -1928,6 +1951,7 @@ export declare namespace Machine {
19281951 readonly type : "history"
19291952 /** Defaults to shallow history. */
19301953 readonly history ?: "shallow" | "deep"
1954+ readonly annotations ?: PseudoStateAnnotations
19311955 }
19321956
19331957 /**
@@ -1942,6 +1966,7 @@ export declare namespace Machine {
19421966 */
19431967 export interface ChoiceStateNodeConfig {
19441968 readonly type : "choice"
1969+ readonly annotations ?: PseudoStateAnnotations
19451970 }
19461971
19471972 /**
@@ -2075,10 +2100,12 @@ export declare namespace Machine {
20752100 readonly key : string
20762101 readonly schema : TaggedSchema | undefined
20772102 readonly output : Schema . Top | undefined
2103+ /** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
2104+ readonly annotations : Readonly < StateNodeAnnotations > | undefined
20782105 readonly type : "atomic" | "compound" | "parallel" | "final" | "history" | "choice"
20792106 readonly history : "shallow" | "deep" | undefined
20802107 readonly parent : Path | undefined
2081- /** Active child paths. History pseudo -states are available through their `parent` relationship. */
2108+ /** Active child paths. Pseudo -states are available through their `parent` relationship. */
20822109 readonly children : ReadonlyArray < Path >
20832110 readonly initial : Path | undefined
20842111 readonly order : number
@@ -2156,6 +2183,18 @@ export declare namespace Machine {
21562183 readonly targets : TransitionTargets < TargetPath >
21572184 }
21582185
2186+ /**
2187+ * Serializable description of state-owned work.
2188+ *
2189+ * Static invoke descriptors expose their lifecycle id and kind without
2190+ * retaining Effects, closures, services, or child runtimes. A function-valued
2191+ * invoke factory is reported as dynamic and is never evaluated by inspection.
2192+ *
2193+ * @category models
2194+ * @since 4.0.0
2195+ */
2196+ export type ActivityDefinition < SourcePath extends string = string > = Activities . ActivityDefinition < SourcePath >
2197+
21592198 /**
21602199 * Transition retained after hierarchy precedence and conflict resolution for
21612200 * one planned microstep.
@@ -3174,6 +3213,8 @@ export declare namespace Machine {
31743213 readonly state : StateByIdentifier < States , StateId >
31753214 readonly parent : ParentStateValue < States , StateId >
31763215 readonly parents : ParentStateValues < States , StateId >
3216+ /** Complete logical configuration captured at the start of this microstep. */
3217+ readonly snapshot : Snapshot < States >
31773218 readonly event : EventByTag < Events , EventTag >
31783219 readonly runtime : RuntimeEffect < Events , Emits >
31793220
@@ -3261,6 +3302,8 @@ export declare namespace Machine {
32613302 readonly state : StateByIdentifier < States , StateId >
32623303 readonly parent : ParentStateValue < States , StateId >
32633304 readonly parents : ParentStateValues < States , StateId >
3305+ /** Complete logical configuration captured at the start of this microstep. */
3306+ readonly snapshot : Snapshot < States >
32643307 readonly event : LifecycleEvent < Events >
32653308 readonly runtime : RuntimeEffect < Events , Emits >
32663309
@@ -3289,6 +3332,8 @@ export declare namespace Machine {
32893332 readonly state : StateByIdentifier < States , StateId >
32903333 readonly parent : ParentStateValue < States , StateId >
32913334 readonly parents : ParentStateValues < States , StateId >
3335+ /** Complete logical configuration captured at the start of this microstep. */
3336+ readonly snapshot : Snapshot < States >
32923337 readonly event : LifecycleEvent < Events >
32933338 readonly output : CompletionOutputByIdentifier < States , StateId >
32943339 readonly runtime : RuntimeEffect < Events , Emits >
@@ -3725,6 +3770,8 @@ export declare namespace Machine {
37253770 readonly requirements : Types . Covariant < ChildRequirements >
37263771 readonly initialError : Types . Covariant < ChildInitialError >
37273772 }
3773+ /** @internal Serializable descriptor metadata used by inspection. */
3774+ readonly [ Activities . ActivityMetadataTypeId ] ?: Activities . StaticActivityMetadata
37283775 readonly id : string
37293776 /**
37303777 * Optional parent-local address for sending events to this invocation.
@@ -5948,7 +5995,11 @@ export const invoke = <
59485995 ChildRequirements ,
59495996 ChildOutput ,
59505997 ChildInitialError
5951- > => ( { ...config , [ InvokeTypeId ] : undefined as any } )
5998+ > => ( {
5999+ ...config ,
6000+ [ InvokeTypeId ] : undefined as any ,
6001+ [ Activities . ActivityMetadataTypeId ] : { type : "process" }
6002+ } )
59526003
59536004type InvokeEffectResult < Requirements , Event > = Machine . InvokeConfig <
59546005 any ,
@@ -6020,8 +6071,8 @@ export const invokeEffect = <
60206071 readonly effect : Effect . Effect < unknown , unknown , unknown >
60216072 readonly onSuccess : ( value : unknown ) => unknown
60226073 readonly onFailure ?: ( error : unknown ) => unknown
6023- } ) =>
6024- invoke ( {
6074+ } ) => ( {
6075+ ... invoke ( {
60256076 id : config . id ,
60266077 src : ( ) =>
60276078 effect (
@@ -6032,7 +6083,15 @@ export const invokeEffect = <
60326083 onSuccess : ( value ) => Effect . succeed ( config . onSuccess ( value ) )
60336084 } )
60346085 )
6035- } ) ) ( config as any ) as any
6086+ } ) ,
6087+ [ Activities . ActivityMetadataTypeId ] : {
6088+ type : "effect" ,
6089+ outcomes : {
6090+ success : "dynamic" ,
6091+ failure : config . onFailure === undefined ? "none" : "dynamic"
6092+ }
6093+ }
6094+ } ) ) ( config as any ) as any
60366095
60376096/**
60386097 * Creates a cancellable state-scoped delayed event.
@@ -6048,11 +6107,17 @@ export const after = <Event extends { readonly _tag: PropertyKey }>(
60486107 duration : Duration . Input ,
60496108 event : Event ,
60506109 options ?: { readonly id ?: InvokeLifecycleId }
6051- ) : InvokeEffectResult < never , Event > =>
6052- invoke ( {
6110+ ) : InvokeEffectResult < never , Event > => ( {
6111+ ... invoke ( {
60536112 id : options ?. id ?? `Machine.after:${ String ( event . _tag ) } ` ,
60546113 src : ( ) => effect ( Effect . as ( Effect . sleep ( duration ) , event ) )
6055- } )
6114+ } ) ,
6115+ [ Activities . ActivityMetadataTypeId ] : {
6116+ type : "timer" ,
6117+ duration : Duration . format ( Duration . fromInputUnsafe ( duration ) ) ,
6118+ event : String ( event . _tag )
6119+ }
6120+ } )
60566121
60576122type RetagFields < Target extends Machine . TaggedSchema > = Omit < Target [ "~type.make.in" ] , "_tag" >
60586123
@@ -6317,6 +6382,13 @@ export const invokeMachine: {
63176382 : ( internalProcess . toProcessLogic as any ) ( machine , config . input ) ,
63186383 snapshot : config . snapshot ,
63196384 onDone : config . onDone ,
6385+ [ Activities . ActivityMetadataTypeId ] : {
6386+ type : "machine" ,
6387+ child : {
6388+ id : config . child . id ,
6389+ machineId : machine . id ?? null
6390+ }
6391+ } ,
63206392 [ InvokeTypeId ] : undefined as any
63216393 }
63226394} ) as any
@@ -6426,10 +6498,11 @@ export const planInitial: <
64266498 *
64276499 * **Details**
64286500 *
6429- * The result includes atomic, compound, parallel, final, and history nodes.
6430- * Use each node's `parent` property to reconstruct the complete hierarchy.
6431- * History pseudo-states are intentionally omitted from `children` because they
6432- * can never appear in an active configuration.
6501+ * The result includes atomic, compound, parallel, final, history, and choice
6502+ * nodes together with their resolved descriptive annotations. Use each node's
6503+ * `parent` property to reconstruct the complete hierarchy. Pseudo-states are
6504+ * intentionally omitted from `children` because they can never appear in an
6505+ * active configuration.
64336506 *
64346507 * @category getters
64356508 * @since 4.0.0
@@ -6472,14 +6545,34 @@ export const transitionDefinitions = <M extends Machine.Any>(
64726545 >
64736546 >
64746547
6548+ /**
6549+ * Returns serializable descriptions of every state-owned activity.
6550+ *
6551+ * **Details**
6552+ *
6553+ * Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
6554+ * expose stable ownership and lifecycle metadata without serializing runtime
6555+ * values. Function-valued invoke factories are represented as dynamic and are
6556+ * never evaluated during inspection.
6557+ *
6558+ * @category getters
6559+ * @since 4.0.0
6560+ */
6561+ export const activityDefinitions = < M extends Machine . Any > (
6562+ machine : M
6563+ ) : ReadonlyArray < Machine . ActivityDefinition < Machine . StateIdentifier < Machine . States < M > > > > =>
6564+ Activities . activityDefinitions ( machine ) as ReadonlyArray <
6565+ Machine . ActivityDefinition < Machine . StateIdentifier < Machine . States < M > > >
6566+ >
6567+
64756568/**
64766569 * Returns every state node active in a decoded snapshot, in definition order.
64776570 *
64786571 * **Details**
64796572 *
64806573 * Active compound ancestors and parallel regions are included together with
6481- * their active descendants. History pseudo-states are never active and are not
6482- * returned.
6574+ * their active descendants. History and choice pseudo-states are never active
6575+ * and are not returned.
64836576 *
64846577 * @category getters
64856578 * @since 4.0.0
0 commit comments