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 and analytical brain. Each event type has a dedicated subclass that implements rendering methods for each view mode:
-
basic / verbose / debug — TUI display modes returning structured hashes
-
brain — analytical brain transcript returning 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.
Brain mode returns condensed single-line strings for the analytical brain’s event transcript. Returns nil to exclude an event from the brain’s view.
Subclasses must override #render_basic. Verbose, debug, and brain 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"- MIDDLE_TRUNCATION_MARKER =
"\n[...truncated...]\n"
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_brain ⇒ String?
Analytical brain view — condensed single-line string for the brain’s event transcript.
-
#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.
76 77 78 79 80 81 82 |
# File 'app/decorators/event_decorator.rb', line 76 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.
98 99 100 101 102 103 |
# File 'app/decorators/event_decorator.rb', line 98 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.
107 108 109 |
# File 'app/decorators/event_decorator.rb', line 107 def render_basic raise NotImplementedError, "#{self.class} must implement #render_basic" end |
#render_brain ⇒ String?
Analytical brain view — condensed single-line string for the brain’s event transcript. Returns nil to exclude from the brain’s context. Subclasses override to provide event-type-specific formatting.
129 130 131 |
# File 'app/decorators/event_decorator.rb', line 129 def render_brain nil end |
#render_debug ⇒ Hash?
Debug view mode with token counts and system prompts. Delegates to #render_basic until subclasses provide their own implementations.
121 122 123 |
# File 'app/decorators/event_decorator.rb', line 121 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.
114 115 116 |
# File 'app/decorators/event_decorator.rb', line 114 def render_verbose render_basic end |