Class: OllamaAgent::Streaming::ConsoleStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/streaming/console_streamer.rb

Overview

Attaches to a Hooks instance to print live streaming output to stdout. Auto-attached by CLI when –stream is passed and stdout is a TTY.

Instance Method Summary collapse

Instance Method Details

#attach(hooks) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength – one subscriber block per hook



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ollama_agent/streaming/console_streamer.rb', line 11

def attach(hooks)
  hooks.on(:on_thinking) do |payload|
    Console.write_streaming_thinking_fragment(payload[:token])
  end
  hooks.on(:on_token) do |payload|
    Console.finalize_streaming_thinking_before_content!
    Console.write_stream_token(payload[:token])
  end
  hooks.on(:on_tool_call)   { |payload| warn Console.tool_call_line(payload[:name], payload[:args]) }
  hooks.on(:on_tool_result) { |payload| warn Console.tool_result_line(payload[:name], payload[:result]) }
  hooks.on(:on_complete) do
    Console.close_streaming_thinking_if_still_open!
    puts
  end
end