Class: MessageDecorator
- Inherits:
-
ApplicationDecorator
- Object
- Draper::Decorator
- ApplicationDecorator
- MessageDecorator
- Defined in:
- app/decorators/message_decorator.rb
Overview
Base decorator for Message records, providing multi-resolution rendering for the TUI and Melete. Each message type has a dedicated subclass that implements rendering methods for each view mode:
-
basic / verbose / debug — TUI display modes returning structured hashes
-
melete — Melete transcript lines as plain strings (or nil to skip)
TUI decorators return structured hashes (not pre-formatted strings) so that the TUI can style and lay out content based on semantic role, without fragile regex parsing. The TUI receives structured data via ActionCable and formats it for display.
Melete mode returns condensed single-line strings for her message transcript. Returns nil to exclude a message from her view.
Subclasses must override #render_basic. Verbose, debug, and melete modes delegate to basic until subclasses provide their own implementations.
Instantiate via message.decorate — Message#decorator_class picks the concrete subclass based on message_type.
Direct Known Subclasses
AgentMessageDecorator, SystemMessageDecorator, ToolCallDecorator, ToolResponseDecorator, UserMessageDecorator
Constant Summary collapse
- TOOL_ICON =
"\u{1F527}"- RETURN_ARROW =
"\u21A9"- ERROR_ICON =
"\u274C"- MIDDLE_TRUNCATION_MARKER =
"\n[...truncated...]\n"
Instance Method Summary collapse
-
#render(mode) ⇒ Hash, ...
Dispatches to the render method for the given view mode.
-
#render_basic ⇒ Hash?
abstract
Structured message data, or nil to hide the message.
-
#render_debug ⇒ Hash?
Debug view mode with token counts and system prompts.
-
#render_melete ⇒ String?
Melete view — condensed single-line string for her message transcript.
-
#render_mneme ⇒ String, ...
Mneme memory view — transcript line for eviction/context zones.
-
#render_verbose ⇒ Hash?
Verbose view mode with timestamps and tool details.
Instance Method Details
#render(mode) ⇒ Hash, ...
Dispatches to the render method for the given view mode.
50 51 52 53 54 55 |
# File 'app/decorators/message_decorator.rb', line 50 def render(mode) method = RENDER_DISPATCH[mode] raise ArgumentError, "Invalid view mode: #{mode.inspect}" unless method public_send(method) end |
#render_basic ⇒ Hash?
Subclasses must implement to render the message for basic view mode.
Returns structured message data, or nil to hide the message.
59 60 61 |
# File 'app/decorators/message_decorator.rb', line 59 def render_basic raise NotImplementedError, "#{self.class} must implement #render_basic" end |
#render_debug ⇒ Hash?
Debug view mode with token counts and system prompts. Delegates to #render_basic until subclasses provide their own implementations.
73 74 75 |
# File 'app/decorators/message_decorator.rb', line 73 def render_debug render_basic end |
#render_melete ⇒ String?
Melete view — condensed single-line string for her message transcript. Returns nil to exclude from her context. Subclasses override to provide message-type-specific formatting.
81 82 83 |
# File 'app/decorators/message_decorator.rb', line 81 def render_melete nil end |
#render_mneme ⇒ String, ...
Mneme memory view — transcript line for eviction/context zones. Conversation and think messages return a prefixed string. Regular tool calls return :tool_call (counter marker). Tool responses return nil (silent).
90 91 92 |
# File 'app/decorators/message_decorator.rb', line 90 def render_mneme nil end |
#render_verbose ⇒ Hash?
Verbose view mode with timestamps and tool details. Delegates to #render_basic until subclasses provide their own implementations.
66 67 68 |
# File 'app/decorators/message_decorator.rb', line 66 def render_verbose render_basic end |