Class: TranscriptViewer::ToolExecution

Inherits:
Object
  • Object
show all
Defined in:
lib/transcript_viewer/tool_execution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call:, result_entry: nil) ⇒ ToolExecution

Returns a new instance of ToolExecution.



9
10
11
12
# File 'lib/transcript_viewer/tool_execution.rb', line 9

def initialize(call:, result_entry: nil)
  @call = call
  @result_entry = result_entry
end

Instance Attribute Details

#callObject (readonly)

Returns the value of attribute call.



7
8
9
# File 'lib/transcript_viewer/tool_execution.rb', line 7

def call
  @call
end

#result_entryObject (readonly)

Returns the value of attribute result_entry.



7
8
9
# File 'lib/transcript_viewer/tool_execution.rb', line 7

def result_entry
  @result_entry
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/transcript_viewer/tool_execution.rb', line 53

def error?
  !pending? && !!result&.dig(:isError)
end

#idObject



14
15
16
# File 'lib/transcript_viewer/tool_execution.rb', line 14

def id
  call[:id]
end

#imagesObject



45
46
47
# File 'lib/transcript_viewer/tool_execution.rb', line 45

def images
  result_content.select { |block| block[:type] == "image" && present_value?(block[:data]) }
end

#inputObject Also known as: arguments



22
23
24
# File 'lib/transcript_viewer/tool_execution.rb', line 22

def input
  call[:arguments] || {}
end

#nameObject



18
19
20
# File 'lib/transcript_viewer/tool_execution.rb', line 18

def name
  call[:name].to_s
end

#pending?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/transcript_viewer/tool_execution.rb', line 49

def pending?
  result_entry.nil?
end

#resultObject



27
28
29
# File 'lib/transcript_viewer/tool_execution.rb', line 27

def result
  result_entry&.dig(:message)
end

#result_contentObject



31
32
33
# File 'lib/transcript_viewer/tool_execution.rb', line 31

def result_content
  Array(result&.dig(:content))
end

#result_jsonObject



39
40
41
42
43
# File 'lib/transcript_viewer/tool_execution.rb', line 39

def result_json
  JSON.parse(result_text)
rescue JSON::ParserError
  nil
end

#result_textObject



35
36
37
# File 'lib/transcript_viewer/tool_execution.rb', line 35

def result_text
  result_content.filter_map { |block| block[:text] if block[:type] == "text" }.join("\n")
end

#statusObject



61
62
63
64
65
66
# File 'lib/transcript_viewer/tool_execution.rb', line 61

def status
  return :pending if pending?
  return :error if error?

  :success
end

#success?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/transcript_viewer/tool_execution.rb', line 57

def success?
  !pending? && !error?
end