Class: NitroIntelligence::ToolCallReviewValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro_intelligence/tool_call_review_validator.rb

Overview

The reviews a caller submitted, checked against the tool calls the interrupt is holding, before anything is sent. Raises Assistants::ThreadResumptionError on the first problem it finds.

Internal to Assistants#review_tool_calls, which builds the only instance there is. What #validate! takes follows what that method needs and has changed with it before, so it carries no promise to anything calling it directly.

Instance Method Summary collapse

Instance Method Details

#validate!(tool_calls:, tool_calls_under_review:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nitro_intelligence/tool_call_review_validator.rb', line 11

def validate!(tool_calls:, tool_calls_under_review:)
  tool_calls = normalize_tool_calls(tool_calls)
  tool_calls_under_review_by_id = Array(tool_calls_under_review).index_by { |tool_call| tool_call["id"] }

  tool_calls.each do |tool_call_id, review|
    tool_call_under_review = tool_calls_under_review_by_id[tool_call_id]&.with_indifferent_access
    raise_error!("Unknown tool call ids: #{tool_call_id}") unless tool_call_under_review

    review = normalize_review(tool_call_id, review)
    review_action = review[:action].to_s

    unless Array(tool_call_under_review[:allowed_decisions]).include?(review_action)
      raise_error!("Invalid review action `#{review_action}` for tool call #{tool_call_id}")
    end

    validate_review_details!(tool_call_id:, review:, review_action:, tool_call_under_review:)
  end

  validate_completeness!(
    submitted_tool_call_ids: tool_calls.keys,
    tool_calls_under_review:
  )
end