Class: Kward::TurnSummaryFormatter
- Inherits:
-
Object
- Object
- Kward::TurnSummaryFormatter
- Defined in:
- lib/kward/transcripts/turn_summary_formatter.rb
Overview
Shared plain-text presentation for terminal and exported turn summaries.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(summary) ⇒ TurnSummaryFormatter
constructor
A new instance of TurnSummaryFormatter.
- #render(mode:, width:) ⇒ Object
Constructor Details
#initialize(summary) ⇒ TurnSummaryFormatter
Returns a new instance of TurnSummaryFormatter.
13 14 15 |
# File 'lib/kward/transcripts/turn_summary_formatter.rb', line 13 def initialize(summary) @summary = summary end |
Class Method Details
.render(summary, mode: "compact", width: nil) ⇒ Object
7 8 9 10 11 |
# File 'lib/kward/transcripts/turn_summary_formatter.rb', line 7 def self.render(summary, mode: "compact", width: nil) return "" unless summary.is_a?(Hash) && mode != "off" new(summary).render(mode: mode, width: width) end |
Instance Method Details
#render(mode:, width:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kward/transcripts/turn_summary_formatter.rb', line 17 def render(mode:, width:) status = { "completed" => "Completed", "failed" => "Failed", "canceled" => "Cancelled" }.fetch(value(:status), "Finished") parts = [status, format("%.1fs", value(:elapsedMs).to_f / 1_000), token_text] parts << count_text(value(:modelRequests), "model request") if mode == "detailed" parts << count_text(value(:toolCalls), "tool call") lines = [fit(parts, width)] if mode == "detailed" && usage.is_a?(Hash) details = [ token_detail(:input_tokens, "Input"), cached_detail, token_detail(:output_tokens, "Output"), token_detail(:reasoning_tokens, "Reasoning"), token_detail(:cache_write_tokens, "Cache writes") ].compact lines << fit(details, width) unless details.empty? end lines.join("\n") end |