class Riffer::Rig::Terminal::TurnBuffer
Attributes
ghost
[R]
String?
@dynamic ghost, tool
tool
[R]
String?
Public Class Methods
(clock: ^() → Float) → void
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 21 def initialize(clock:) @clock = clock @started_at = clock.call @prose = +'' @answers = [] @steps = 0 @in_request = false @interrupted = false end
@rbs clock: ^() -> Float @rbs return: void
Public Instance Methods
(::Riffer::StreamEvents::Base | Riffer::Rig::Events::_Event event) → void
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 33 def absorb(event) case event when Riffer::StreamEvents::TextDelta begin_request @prose << event.content when Riffer::StreamEvents::ToolCallDone begin_request when Riffer::StreamEvents::FinishReasonDone begin_request classify(event.finish_reason) when Riffer::StreamEvents::TokenUsageDone begin_request # Gemini reports a running total on every chunk, so a request's usage is # its last reading, not the sum of them. @request_usage = event.token_usage when Riffer::Rig::Events::BeforeToolCall # A provider may send no FinishReasonDone, and nothing else marks the end # of a request. settle(:tool_calls) @tool = event.tool when Riffer::Rig::Events::AfterToolCall # A blocked tool call skips BeforeToolCall. settle(:tool_calls) @tool = nil when Riffer::Rig::Events::JobExit # A turn the Runtime continues for a job exit has no tool call between # its replies to end the first request. settle(:stop) when Riffer::StreamEvents::Interrupt @interrupted = true settle(:stop) when Riffer::Rig::Events::TurnEnd settle(:stop) @ended_at = @clock.call end end
@rbs event: ::Riffer::StreamEvents::Base | Riffer::Rig::Events::_Event @rbs return: void
() → String
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 71 def answer @answers.join("\n\n") end
@rbs return: String
() → bool
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 86 def ended? !@ended_at.nil? end
@rbs return: bool
() → bool
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 81 def interrupted? @interrupted end
@rbs return: bool
() → String
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 76 def prose @prose.dup end
@rbs return: String
Source
# File lib/riffer/rig/terminal/turn_buffer.rb, line 91 def stats Stats.new(steps: @steps, wall_time: (@ended_at || @clock.call) - @started_at, usage: usage) end
@rbs return: Riffer::Rig::Terminal::TurnBuffer::Stats