AIML Docs

Transition Element

Element for defining state transitions

Transition Element

The <transition> element defines state transitions:

<transition 
event="success"
target="nextState"
type="external"
/>

Props

PropTypeDefault
id?
string
-
event?
string
-
condition?
Expression
-
target?
string
-
type?
"internal" | "external"
-

Examples

Basic Transition

<state id="start">
<transition target="processing" />
</state>

Event-Based Transition

<state id="waiting">
<transition 
  event="dataReceived"
  target="processing"
/>
<transition 
  event="timeout"
  target="error"
/>
</state>

Conditional Transition

<state id="validating">
<transition 
  target="success"
  condition={({state}) => state.isValid}
/>
<transition 
  target="failure"
  condition={({state}) => !state.isValid}
/>
</state>

Usage Notes

  • Defines movement between states
  • Can be triggered by events
  • Can include conditions
  • Can execute actions during transition

Common Patterns

Sequential Flow

<state id="step1">
<transition 
  event="complete"
  target="step2"
/>
</state>
 
<state id="step2">
<transition 
  event="complete"
  target="step3"
/>
</state>

Error Recovery

<state id="processing">
<transition 
  event="error"
  target="errorHandler"
>
  <log expr={({error}) => `Error: ${error.message}`} />
  <assign location="state.errorStatus" expr="logged" />
</transition>
</state>

Conditional Branching

<state id="decision">
<transition 
  target="pathA"
  condition={({state}) => state.value > 100}
/>
<transition 
  target="pathB"
  condition={({state}) => state.value <= 100}
/>
</state>

Advanced Features

Internal vs External Transitions

<!-- External transition (default) -->
<transition 
event="update"
target="processing"
type="external"
/>
 
<!-- Internal transition -->
<transition 
event="update"
target="processing"
type="internal"
/>

Multiple Targets

<transition event="split">
<target>path1</target>
<target>path2</target>
</transition>

Transition Actions

<transition event="process">
<assign location="state.status" expr={() => "processing"} />
<log expr="Starting process" />
<script>
  initializeProcess();
</script>
</transition>

On this page