Class: Clacky::UI2::Components::MessageComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Clacky::UI2::Components::MessageComponent
- Defined in:
- lib/clacky/ui2/components/message_component.rb
Overview
MessageComponent renders user and assistant messages
Instance Method Summary collapse
-
#render(data) ⇒ String
Render a message.
-
#render_assistant_message(content, timestamp = nil) ⇒ String
Render assistant message.
-
#render_user_message(content, timestamp = nil, files = []) ⇒ String
Render user message.
Methods inherited from BaseComponent
Constructor Details
This class inherits a constructor from Clacky::UI2::Components::BaseComponent
Instance Method Details
#render(data) ⇒ String
Render a message
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/clacky/ui2/components/message_component.rb', line 18 def render(data) role = data[:role] content = data[:content] = data[:timestamp] files = data[:files] || [] prefix_newline = data.fetch(:prefix_newline, true) case role when "user" (content, , files) when "assistant" (content, ) else (content, , prefix_newline) end end |
#render_assistant_message(content, timestamp = nil) ⇒ String
Render assistant message
73 74 75 76 77 78 79 80 81 |
# File 'lib/clacky/ui2/components/message_component.rb', line 73 def (content, = nil) return "" if content.nil? || content.empty? symbol = format_symbol(:assistant) text = format_text(content, :assistant) time_str = ? @pastel.dim("[#{()}]") : "" "\n#{symbol} #{text} #{time_str}".rstrip end |
#render_user_message(content, timestamp = nil, files = []) ⇒ String
Render user message
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/clacky/ui2/components/message_component.rb', line 41 def (content, = nil, files = []) symbol = format_symbol(:user) text = format_text(content, :user) time_str = ? @pastel.dim("[#{()}]") : "" result = "\n#{symbol} #{text} #{time_str}".rstrip # Append file attachment info if present if files && files.any? files.each_with_index do |f, idx| filename = f[:name] || f["name"] || "file" result += "\n" + @pastel.dim(" [File #{idx + 1}] #{filename}") end end result end |