ObjectStackObjectStack

State Machine

State Machine protocol schemas

XState-inspired State Machine Protocol

Used to define strict business logic constraints and lifecycle management.

Prevent AI "hallucinations" by enforcing valid valid transitions.

Source: packages/spec/src/automation/state-machine.zod.ts

TypeScript Usage

import { ActionRef, Event, GuardRef, StateMachine, StateNode, Transition } from '@objectstack/spec/automation';
import type { ActionRef, Event, GuardRef, StateMachine, StateNode, Transition } from '@objectstack/spec/automation';

// Validate data
const result = ActionRef.parse(data);

ActionRef

Union Options

This schema accepts one of the following structures:

Option 1

Action Name

Type: string


Option 2

Properties

PropertyTypeRequiredDescription
typestring
paramsRecord<string, any>optional


Event

Properties

PropertyTypeRequiredDescription
typestringEvent Type (e.g. "APPROVE", "REJECT", "Submit")
schemaRecord<string, any>optionalExpected event payload structure

GuardRef

Union Options

This schema accepts one of the following structures:

Option 1

Guard Name (e.g., "isManager", "amountGT1000")

Type: string


Option 2

Properties

PropertyTypeRequiredDescription
typestring
paramsRecord<string, any>optional


StateMachine

Properties

PropertyTypeRequiredDescription
idstringUnique Machine ID
descriptionstringoptional
contextSchemaRecord<string, any>optionalZod Schema for the machine context/memory
initialstringInitial State ID
statesRecord<string, [__schema0](./__schema0)>State Nodes
onRecord<string, string | Object | Object[]>optional

StateNode

Properties

PropertyTypeRequiredDescription
typeEnum<'atomic' | 'compound' | 'parallel' | 'final' | 'history'>
entrystring | Object[]optionalActions to run when entering this state
exitstring | Object[]optionalActions to run when leaving this state
onRecord<string, string | Object | Object[]>optionalMap of Event Type -> Transition Definition
alwaysObject[]optional
initialstringoptionalInitial child state (if compound)
statesRecord<string, [#](./#)>optional
metaObjectoptional

Transition

Properties

PropertyTypeRequiredDescription
targetstringoptionalTarget State ID
condstring | ObjectoptionalCondition (Guard) required to take this path
actionsstring | Object[]optionalActions to execute during transition
descriptionstringoptionalHuman readable description of this rule

On this page