Class: Rubino::Interaction::State
- Inherits:
-
Object
- Object
- Rubino::Interaction::State
- Defined in:
- lib/rubino/interaction/state.rb
Overview
Tracks the current state of an interaction. Implements a simple state machine with valid transitions.
Constant Summary collapse
- VALID_STATES =
%i[ idle receiving_input loading_session loading_memory building_context checking_budget compressing_context calling_model persisting_session enqueueing_jobs finished failed ].freeze
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
- #idle? ⇒ Boolean
-
#initialize ⇒ State
constructor
A new instance of State.
- #terminal? ⇒ Boolean
-
#transition_to!(new_state, event_bus: nil) ⇒ Object
Transitions to a new state, emitting an event.
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
25 26 27 |
# File 'lib/rubino/interaction/state.rb', line 25 def initialize @current = :idle end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
23 24 25 |
# File 'lib/rubino/interaction/state.rb', line 23 def current @current end |
Instance Method Details
#failed? ⇒ Boolean
47 48 49 |
# File 'lib/rubino/interaction/state.rb', line 47 def failed? @current == :failed end |
#finished? ⇒ Boolean
43 44 45 |
# File 'lib/rubino/interaction/state.rb', line 43 def finished? @current == :finished end |
#idle? ⇒ Boolean
39 40 41 |
# File 'lib/rubino/interaction/state.rb', line 39 def idle? @current == :idle end |
#terminal? ⇒ Boolean
51 52 53 |
# File 'lib/rubino/interaction/state.rb', line 51 def terminal? finished? || failed? end |
#transition_to!(new_state, event_bus: nil) ⇒ Object
Transitions to a new state, emitting an event
30 31 32 33 34 35 36 37 |
# File 'lib/rubino/interaction/state.rb', line 30 def transition_to!(new_state, event_bus: nil) raise Error, "Invalid state: #{new_state}" unless VALID_STATES.include?(new_state) old_state = @current @current = new_state event_bus&.emit(Events::STATUS_CHANGED, from: old_state, to: new_state) end |