Class: AgUi::Terminals::RubyLLM::TurnEmitter
- Inherits:
-
Object
- Object
- AgUi::Terminals::RubyLLM::TurnEmitter
- Defined in:
- lib/ag_ui/terminals/ruby_llm.rb
Overview
Emits the turn's reasoning + text phases lazily: nothing opens until its first non-empty delta (tool-call-only turns produce no empty bubbles), and reasoning closes as soon as text begins — providers stream thinking strictly before the answer.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(events) ⇒ TurnEmitter
constructor
A new instance of TurnEmitter.
- #text_delta(text) ⇒ Object
- #thinking_delta(text) ⇒ Object
Constructor Details
#initialize(events) ⇒ TurnEmitter
Returns a new instance of TurnEmitter.
93 94 95 96 97 98 99 |
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 93 def initialize(events) @events = events @text_id = SecureRandom.uuid @reasoning_id = SecureRandom.uuid @text_started = false @reasoning_open = false end |
Instance Method Details
#finish ⇒ Object
125 126 127 128 129 130 |
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 125 def finish close_reasoning if @text_started @events << { type: :text_message_end, data: { message_id: @text_id } } end end |
#text_delta(text) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 111 def text_delta(text) unless text.empty? close_reasoning unless @text_started @events << { type: :text_message_start, data: { message_id: @text_id } } @text_started = true end @events << { type: :text_message_content, data: { message_id: @text_id, delta: text }, } end end |
#thinking_delta(text) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 101 def thinking_delta(text) unless text.empty? open_reasoning @events << { type: :reasoning_message_content, data: { message_id: @reasoning_id, delta: text }, } end end |