Module: Rubyagents::UI
- Defined in:
- lib/rubyagents/ui.rb
Defined Under Namespace
Modules: Styles
Classes: NullStyle, Spinner
Constant Summary
collapse
- SPINNER_FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
Class Method Summary
collapse
Class Method Details
.code(source) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/rubyagents/ui.rb', line 103
def code(source)
puts
highlighted = rouge_formatter.format(rouge_lexer.lex(source))
highlighted.each_line { |line| puts " #{line.rstrip}" }
puts
end
|
.error(text) ⇒ Object
114
115
116
|
# File 'lib/rubyagents/ui.rb', line 114
def error(text)
puts Styles.error.render("Error: ") + text
end
|
.final_answer(text) ⇒ Object
140
141
142
143
|
# File 'lib/rubyagents/ui.rb', line 140
def final_answer(text)
puts
puts Styles.final_answer.render("Final answer: ") + text.to_s
end
|
.observation(text) ⇒ Object
110
111
112
|
# File 'lib/rubyagents/ui.rb', line 110
def observation(text)
puts Styles.label.render("Result: ") + truncate(text, 200)
end
|
.plan(text) ⇒ Object
118
119
120
121
122
|
# File 'lib/rubyagents/ui.rb', line 118
def plan(text)
label = Styles.plan_label.render(" Plan ")
body = Styles.plan_box.render(text)
puts "\n#{label}\n#{body}\n"
end
|
.run_summary(total_steps:, total_duration:, total_tokens:) ⇒ Object
134
135
136
137
138
|
# File 'lib/rubyagents/ui.rb', line 134
def run_summary(total_steps:, total_duration:, total_tokens:)
parts = ["#{total_steps} steps", format("%.1fs total", total_duration)]
parts << total_tokens.to_s if total_tokens.total_tokens > 0
puts Styles.dim.render(parts.join(" | "))
end
|
.spinner(message) ⇒ Object
145
146
147
|
# File 'lib/rubyagents/ui.rb', line 145
def spinner(message)
Spinner.new(message)
end
|
.step_metrics(duration:, token_usage:) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/rubyagents/ui.rb', line 124
def step_metrics(duration:, token_usage:)
parts = []
parts << format("%.1fs", duration) if duration > 0
parts << token_usage.to_s if token_usage
return if parts.empty?
puts Styles.dim.render(parts.join(" | "))
puts
end
|
.thought(text) ⇒ Object
99
100
101
|
# File 'lib/rubyagents/ui.rb', line 99
def thought(text)
puts Styles.label.render("Thought: ") + text
end
|
.welcome ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/rubyagents/ui.rb', line 149
def welcome
if JRUBY
puts "rubyagents v#{VERSION}"
puts "Code-first AI agents for Ruby"
else
title = Lipgloss::Style.new
.bold(true)
.foreground("#7B61FF")
.render("rubyagents")
version = Styles.dim.render("v#{VERSION}")
puts "#{title} #{version}"
puts Styles.dim.render("Code-first AI agents for Ruby")
end
puts
end
|