Class: Clacky::UI2::Components::ToolComponent

Inherits:
BaseComponent show all
Defined in:
lib/clacky/ui2/components/tool_component.rb

Overview

ToolComponent renders tool calls and results

Instance Method Summary collapse

Methods inherited from BaseComponent

#initialize, render

Constructor Details

This class inherits a constructor from Clacky::UI2::Components::BaseComponent

Instance Method Details

#render(data) ⇒ String

Render a tool event

Parameters:

  • data (Hash)

    Tool event data

    • :type [Symbol] :call, :result, :error, :denied, :planned

    • :tool_name [String] Name of the tool

    • :formatted_call [String] Formatted tool call description

    • :result [String] Tool result (for :result type)

    • :error [String] Error message (for :error type)

Returns:

  • (String)

    Rendered tool event



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/clacky/ui2/components/tool_component.rb', line 18

def render(data)
  type = data[:type]
  
  case type
  when :call
    render_tool_call(data)
  when :result
    render_tool_result(data)
  when :error
    render_tool_error(data)
  when :denied
    render_tool_denied(data)
  when :planned
    render_tool_planned(data)
  else
    render_unknown_tool_event(data)
  end
end

#render_tool_call(data) ⇒ String

Render tool call

Parameters:

  • data (Hash)

    Tool call data

Returns:

  • (String)

    Rendered tool call



41
42
43
44
45
46
47
# File 'lib/clacky/ui2/components/tool_component.rb', line 41

def render_tool_call(data)
  symbol = format_symbol(:tool_call)
  formatted_call = data[:formatted_call] || "#{data[:tool_name]}(...)"
  text = format_text(formatted_call, :tool_call)

  "\n#{symbol} #{text}"
end

#render_tool_denied(data) ⇒ String

Render tool denied

Parameters:

  • data (Hash)

    Tool denied data

Returns:

  • (String)

    Rendered tool denied



76
77
78
79
80
81
82
# File 'lib/clacky/ui2/components/tool_component.rb', line 76

def render_tool_denied(data)
  symbol = format_symbol(:tool_denied)
  tool_name = data[:tool_name] || "unknown"
  text = format_text("Tool denied: #{tool_name}", :tool_denied)

  "\n#{symbol} #{text}"
end

#render_tool_error(data) ⇒ String

Render tool error Use a low-key style (same as tool_result) since most tool errors (e.g. tool not found, invalid args) are non-critical and the agent can retry.

Parameters:

  • data (Hash)

    Tool error data

Returns:

  • (String)

    Rendered tool error



65
66
67
68
69
70
71
# File 'lib/clacky/ui2/components/tool_component.rb', line 65

def render_tool_error(data)
  symbol = format_symbol(:tool_result)
  error_msg = data[:error] || "Unknown error"
  text = format_text(truncate(error_msg, 200), :tool_result)

  "#{symbol} #{text}"
end

#render_tool_planned(data) ⇒ String

Render tool planned

Parameters:

  • data (Hash)

    Tool planned data

Returns:

  • (String)

    Rendered tool planned



87
88
89
90
91
92
93
# File 'lib/clacky/ui2/components/tool_component.rb', line 87

def render_tool_planned(data)
  symbol = format_symbol(:tool_planned)
  tool_name = data[:tool_name] || "unknown"
  text = format_text("Planned: #{tool_name}", :tool_planned)

  "\n#{symbol} #{text}"
end

#render_tool_result(data) ⇒ String

Render tool result

Parameters:

  • data (Hash)

    Tool result data

Returns:

  • (String)

    Rendered tool result



52
53
54
55
56
57
58
# File 'lib/clacky/ui2/components/tool_component.rb', line 52

def render_tool_result(data)
  symbol = format_symbol(:tool_result)
  result = data[:result] || data[:summary] || "completed"
  text = format_text(truncate(result, 200), :tool_result)

  "#{symbol} #{text}"
end

#render_unknown_tool_event(data) ⇒ String

Render unknown tool event

Parameters:

  • data (Hash)

    Tool event data

Returns:

  • (String)

    Rendered unknown event



98
99
100
101
102
103
# File 'lib/clacky/ui2/components/tool_component.rb', line 98

def render_unknown_tool_event(data)
  symbol = format_symbol(:info)
  text = format_text("Tool event: #{data.inspect}", :info)

  "#{symbol} #{text}"
end