Exception: Collavre::ApprovalPendingError

Inherits:
StandardError
  • Object
show all
Defined in:
app/errors/collavre/approval_pending_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = "Tool execution requires approval", tool_call: nil, task: nil) ⇒ ApprovalPendingError

Returns a new instance of ApprovalPendingError.



7
8
9
10
11
# File 'app/errors/collavre/approval_pending_error.rb', line 7

def initialize(message = "Tool execution requires approval", tool_call: nil, task: nil)
  @tool_call = tool_call
  @task = task
  super(message)
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task.



5
6
7
# File 'app/errors/collavre/approval_pending_error.rb', line 5

def task
  @task
end

#tool_callObject (readonly)

Returns the value of attribute tool_call.



5
6
7
# File 'app/errors/collavre/approval_pending_error.rb', line 5

def tool_call
  @tool_call
end

Instance Method Details

#to_hObject



45
46
47
48
49
50
51
52
# File 'app/errors/collavre/approval_pending_error.rb', line 45

def to_h
  {
    tool_name: tool_name,
    tool_call_id: tool_call_id,
    arguments: tool_arguments,
    task_id: task&.id
  }
end

#tool_argumentsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/errors/collavre/approval_pending_error.rb', line 23

def tool_arguments
  return {} unless tool_call

  if tool_call.respond_to?(:arguments)
    tool_call.arguments
  elsif tool_call.is_a?(Hash)
    tool_call["arguments"] || tool_call[:arguments] || {}
  else
    {}
  end
end

#tool_call_idObject



35
36
37
38
39
40
41
42
43
# File 'app/errors/collavre/approval_pending_error.rb', line 35

def tool_call_id
  return nil unless tool_call

  if tool_call.respond_to?(:id)
    tool_call.id
  elsif tool_call.is_a?(Hash)
    tool_call["id"] || tool_call[:id]
  end
end

#tool_nameObject



13
14
15
16
17
18
19
20
21
# File 'app/errors/collavre/approval_pending_error.rb', line 13

def tool_name
  return nil unless tool_call

  if tool_call.respond_to?(:name)
    tool_call.name
  elsif tool_call.is_a?(Hash)
    tool_call["name"] || tool_call[:name]
  end
end