Skip to main content
The Transition interface in Solmyr’s workflow system corresponds to XState’s transition definitions. While our API is simplified for AI workflow use cases, it maps to XState’s underlying transition logic.
The Transition interface represents a transition between states in the workflow’s state machine. It defines the conditions and actions for moving from one state to another.

Structure

export interface Transition {
    description: string;
    target: string;
    guard?: {
        type: string;
    };
    actions?: { type: string };
}

Properties

description
string
required
Provides guidance for the AI on when and how to trigger this transition. This description helps the AI understand the context for choosing this transition.
target
string
required
The target state to transition to.
guard
object
Optional guard condition that must be true for the transition to occur. References a guard defined in the workflow’s guards property.
  • type: The name of the guard to check.
actions
object
Actions to be performed during the transition. Must be an object with a type property.
  • type: The type of action to perform.

Usage Example

const checkoutToProcessingTransition: Transition = {
    description: "Transition to processing state when the user confirms the order",
    target: "processing",
    guard: {
        type: "isCartValid"
    },
    actions: {
        type: "logOrderConfirmation"
    }
};
This example shows a transition from a checkout state to a processing state. It includes a guard to check if the cart is valid and an action to log the order confirmation.

Using Transitions in States

Transitions are typically used within the on property of a State object to define how the state responds to different events:
const checkoutState: State = {
    description: "Handle the checkout process",
    on: {
        "userConfirm": {
            description: "User confirmed the order",
            target: "processing",
            guard: {
                type: "isCartValid"
            },
            actions: {
                type: "logOrderConfirmation"
            }
        },
        "userCancel": {
            description: "User cancelled the order",
            target: "cancelled"
        }
    }
    // ... other state properties
};
In this example, the checkout state defines two possible transitions: one when the user confirms the order (leading to the “processing” state) and another when the user cancels (leading to the “cancelled” state).