class Clacky::UI2::Components::MessageComponent
MessageComponent renders user and assistant messages
def format_filesize(bytes)
def format_filesize(bytes) es < 1024 ytes}b" bytes < 1024 * 1024 bytes / 1024.0).round(1)}kb" bytes / (1024.0 * 1024)).round(1)}mb"
def render(data)
-
(String)- Rendered message
Parameters:
-
data(Hash) -- Message data
def render(data) role = data[:role] content = data[:content] timestamp = data[:timestamp] files = data[:files] || [] prefix_newline = data.fetch(:prefix_newline, true) case role when "user" render_user_message(content, timestamp, files) when "assistant" render_assistant_message(content, timestamp) else render_system_message(content, timestamp, prefix_newline) end end
def render_assistant_message(content, timestamp = nil)
-
(String)- Rendered message
Parameters:
-
timestamp(Time, nil) -- Optional timestamp -
content(String) -- Message content
def render_assistant_message(content, timestamp = nil) return "" if content.nil? || content.empty? symbol = format_symbol(:assistant) text = format_text(content, :assistant) time_str = timestamp ? @pastel.dim("[#{format_timestamp(timestamp)}]") : "" "\n#{symbol} #{text} #{time_str}".rstrip end
def render_system_message(content, timestamp = nil, prefix_newline = true)
-
(String)- Rendered message
Parameters:
-
prefix_newline(Boolean) -- Whether to add newline before message -
timestamp(Time, nil) -- Optional timestamp -
content(String) -- Message content
def render_system_message(content, timestamp = nil, prefix_newline = true) = format_symbol(:info) format_text(content, :info) tr = timestamp ? @pastel.dim("[#{format_timestamp(timestamp)}]") : "" = prefix_newline ? "\n" : "" fix}#{symbol} #{text} #{time_str}".rstrip
def render_user_message(content, timestamp = nil, files = [])
-
(String)- Rendered message
Parameters:
-
files(Array) -- Optional file hashes { name:, mime_type:, ... } -
timestamp(Time, nil) -- Optional timestamp -
content(String) -- Message content
def render_user_message(content, timestamp = nil, files = []) symbol = format_symbol(:user) text = format_text(content, :user) time_str = timestamp ? @pastel.dim("[#{format_timestamp(timestamp)}]") : "" 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