Class: Protege::IntrospectionToolCallPresentation
- Inherits:
-
Object
- Object
- Protege::IntrospectionToolCallPresentation
- Defined in:
- app/services/protege/introspection_tool_call_presentation.rb
Overview
Presents one live tool call for the console introspection panel — a PORO presentation helper for
the console experience, not part of the engine's inference core. The panel is an event-driven feed
(not a view of persisted rows): as the harness emits tool_call.started/completed/failed events,
IntrospectionBroadcaster builds an IntrospectionToolCallPresentation from the event and renders the
tool_call partial with it — first as a pending card, then replaced in place with the outcome.
Keeping the presentation here (rather than in the partial) keeps the card markup dumb and the
formatting unit-testable.
Build via the state factories: .pending (call just requested), .completed (tool returned a
successful Result), .failed (tool returned a failed Result, so an error).
Constant Summary collapse
- PREVIEW_LIMIT =
Longest inline preview/args summary before it is clipped or replaced by a size count.
80- ERROR_PREVIEW_LIMIT =
Longest error message shown on a failed card before clipping.
200
Instance Attribute Summary collapse
-
#status ⇒ Symbol
readonly
The card state —
:pending,:done, or:failed.
Class Method Summary collapse
-
.completed(tool_call:, result:) ⇒ IntrospectionToolCallPresentation
A card for a call that returned successfully.
-
.failed(tool_call:, error:) ⇒ IntrospectionToolCallPresentation
A card for a call that failed.
-
.pending(tool_call:) ⇒ IntrospectionToolCallPresentation
A card for a call the model just requested, before its result is known.
Instance Method Summary collapse
-
#arguments_summary ⇒ String?
A one-line rendering of the call's arguments, clipped for length.
-
#card_id ⇒ String
Stable DOM id for the card, so the pending card can be replaced in place by its outcome.
-
#initialize(tool_call:, status:, result: nil, error: nil) ⇒ IntrospectionToolCallPresentation
constructor
A new instance of IntrospectionToolCallPresentation.
-
#preview ⇒ String?
The response line: a short rendering of the result on success (or a size count when large), the error message on failure, and nothing while pending.
-
#tool_name ⇒ String
The tool's name.
Constructor Details
#initialize(tool_call:, status:, result: nil, error: nil) ⇒ IntrospectionToolCallPresentation
Returns a new instance of IntrospectionToolCallPresentation.
56 57 58 59 60 61 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 56 def initialize(tool_call:, status:, result: nil, error: nil) @tool_call = tool_call @status = status @result = result @error = error end |
Instance Attribute Details
#status ⇒ Symbol (readonly)
Returns the card state — :pending, :done, or :failed.
50 51 52 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 50 def status @status end |
Class Method Details
.completed(tool_call:, result:) ⇒ IntrospectionToolCallPresentation
A card for a call that returned successfully.
35 36 37 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 35 def completed(tool_call:, result:) new(tool_call:, status: :done, result:) end |
.failed(tool_call:, error:) ⇒ IntrospectionToolCallPresentation
A card for a call that failed.
44 45 46 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 44 def failed(tool_call:, error:) new(tool_call:, status: :failed, error:) end |
.pending(tool_call:) ⇒ IntrospectionToolCallPresentation
A card for a call the model just requested, before its result is known.
26 27 28 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 26 def pending(tool_call:) new(tool_call:, status: :pending) end |
Instance Method Details
#arguments_summary ⇒ String?
A one-line rendering of the call's arguments, clipped for length.
78 79 80 81 82 83 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 78 def arguments_summary input = @tool_call.input return nil if input.blank? clip(input.map { |key, value| "#{key}: #{value.inspect}" }.join(', '), limit: PREVIEW_LIMIT) end |
#card_id ⇒ String
Stable DOM id for the card, so the pending card can be replaced in place by its outcome.
66 67 68 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 66 def card_id "tool_call_#{@tool_call.id}" end |
#preview ⇒ String?
The response line: a short rendering of the result on success (or a size count when large), the error message on failure, and nothing while pending.
89 90 91 92 93 94 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 89 def preview case status when :failed then clip(@error&..to_s, limit: ERROR_PREVIEW_LIMIT) when :done then result_preview end end |
#tool_name ⇒ String
Returns the tool's name.
71 72 73 |
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 71 def tool_name @tool_call.name end |