Class: EventDecorator
- Inherits:
-
ApplicationDecorator
- Object
- Draper::Decorator
- ApplicationDecorator
- EventDecorator
- Defined in:
- app/decorators/event_decorator.rb
Overview
Base decorator for Event records, providing multi-resolution rendering for the TUI. Each event type has a dedicated subclass that implements rendering methods for each view mode (basic, verbose, debug).
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.
Subclasses must override #render_basic. Verbose and debug modes delegate to basic until subclasses provide their own implementations.
Direct Known Subclasses
AgentMessageDecorator, SystemMessageDecorator, ToolCallDecorator, ToolResponseDecorator, UserMessageDecorator
Defined Under Namespace
Classes: EventPayload
Constant Summary collapse
- TOOL_ICON =
"\u{1F527}"- RETURN_ARROW =
"\u21A9"- ERROR_ICON =
"\u274C"
Class Method Summary collapse
-
.for(event) ⇒ EventDecorator?
Factory returning the appropriate subclass decorator for the given event.
Instance Method Summary collapse
-
#render(mode) ⇒ Hash?
Dispatches to the render method for the given view mode.
-
#render_basic ⇒ Hash?
abstract
Structured event data, or nil to hide the event.
-
#render_debug ⇒ Hash?
Debug view mode with token counts and system prompts.
-
#render_verbose ⇒ Hash?
Verbose view mode with timestamps and tool details.
Class Method Details
.for(event) ⇒ EventDecorator?
Factory returning the appropriate subclass decorator for the given event. Hashes are normalized via EventPayload to provide a uniform interface.
69 70 71 72 73 74 75 |
# File 'app/decorators/event_decorator.rb', line 69 def self.for(event) source = wrap_source(event) klass_name = DECORATOR_MAP[source.event_type] return nil unless klass_name klass_name.constantize.new(source) end |
Instance Method Details
#render(mode) ⇒ Hash?
Dispatches to the render method for the given view mode.
89 90 91 92 93 94 |
# File 'app/decorators/event_decorator.rb', line 89 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 event for basic view mode.
Returns structured event data, or nil to hide the event.
98 99 100 |
# File 'app/decorators/event_decorator.rb', line 98 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.
112 113 114 |
# File 'app/decorators/event_decorator.rb', line 112 def render_debug render_basic end |
#render_verbose ⇒ Hash?
Verbose view mode with timestamps and tool details. Delegates to #render_basic until subclasses provide their own implementations.
105 106 107 |
# File 'app/decorators/event_decorator.rb', line 105 def render_verbose render_basic end |