Class: Protege::IntrospectionToolCallPresentation

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_call:, status:, result: nil, error: nil) ⇒ IntrospectionToolCallPresentation

Returns a new instance of IntrospectionToolCallPresentation.

Parameters:

  • tool_call (Protege::Inference::Provider::ToolCall)

    the call being presented

  • status (Symbol)

    :pending, :done, or :failed

  • result (Protege::Result, nil) (defaults to: nil)

    the successful outcome, when done

  • error (Exception, nil) (defaults to: nil)

    the failure, when failed



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

#statusSymbol (readonly)

Returns the card state — :pending, :done, or :failed.

Returns:

  • (Symbol)

    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.

Parameters:

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:



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_summaryString?

A one-line rendering of the call's arguments, clipped for length.

Returns:

  • (String, nil)

    the args summary, or nil when there are none



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_idString

Stable DOM id for the card, so the pending card can be replaced in place by its outcome.

Returns:

  • (String)

    the card's DOM id



66
67
68
# File 'app/services/protege/introspection_tool_call_presentation.rb', line 66

def card_id
  "tool_call_#{@tool_call.id}"
end

#previewString?

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.

Returns:

  • (String, nil)

    the preview, or nil when pending / empty



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&.message.to_s, limit: ERROR_PREVIEW_LIMIT)
  when :done   then result_preview
  end
end

#tool_nameString

Returns the tool's name.

Returns:

  • (String)

    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