Class: Rixie::Subscribers::JsonLogger

Inherits:
Rixie::Subscriber show all
Defined in:
lib/rixie/subscribers/json_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ JsonLogger

Returns a new instance of JsonLogger.



8
9
10
# File 'lib/rixie/subscribers/json_logger.rb', line 8

def initialize(logger:)
  @logger = logger
end

Instance Method Details

#subscribe(listener) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rixie/subscribers/json_logger.rb', line 12

def subscribe(listener)
  listener.on(Event::TaskStart) { |envelope|
    e = envelope.event
    emit(envelope, "task_start", user_input: e.user_input, strategy: e.strategy.class.name)
  }
  listener.on(Event::TaskEnd) { |envelope|
    emit(envelope, "task_end", status: envelope.event.status)
  }
  listener.on(Event::RunStart) { |envelope|
    emit(envelope, "run_start", user_input: envelope.event.user_input)
  }
  listener.on(Event::RunEnd) { |envelope|
    emit(envelope, "run_end", status: envelope.event.status)
  }
  listener.on(Event::CompressionStart) { |envelope|
    e = envelope.event
    emit(envelope, "compression_start", entry_count: e.entry_count, keep_recent: e.keep_recent)
  }
  listener.on(Event::CompressionEnd) { |envelope|
    e = envelope.event
    emit(envelope, "compression_end", status: e.status, entry_count: e.entry_count)
  }
  listener.on(Event::LlmCallStart) { |envelope|
    emit(envelope, "llm_call_start", step_count: envelope.event.step_count)
  }
  listener.on(Event::ToolCallStart) { |envelope|
    tc = envelope.event.tool_call
    emit(envelope, "tool_call_start", tool_call: {id: tc.id, name: tc.name, arguments: tc.arguments})
  }
  listener.on(Event::ToolCallEnd) { |envelope|
    tc = envelope.event.tool_call
    r = envelope.event.result
    emit(envelope, "tool_call_end",
      tool_call: {id: tc.id, name: tc.name},
      result: {content: r.content, error: r.error&.message})
  }
  listener.on(Event::Finished) { |envelope|
    emit(envelope, "finished", content: envelope.event.content)
  }
end