Module: RubyLLM::Protocols::Responses::Approvals
- Defined in:
- lib/ruby_llm/protocols/responses/approvals.rb
Overview
Approval requests and decisions for provider-managed tools.
Class Method Summary collapse
- .parse_pending_tool_calls(output, response: nil, finish_reason: nil) ⇒ Object
- .parse_tool_approvals(output, response: nil, finish_reason: nil) ⇒ Object
- .render_tool_approval_response(tool_call, approved:) ⇒ Object
Class Method Details
.parse_pending_tool_calls(output, response: nil, finish_reason: nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/ruby_llm/protocols/responses/approvals.rb', line 24 def parse_pending_tool_calls(output, response: nil, finish_reason: nil) calls = (parse_function_calls(output, response:, finish_reason:) || {}) .merge(parse_tool_approvals(output, response:, finish_reason:)) calls unless calls.empty? end |
.parse_tool_approvals(output, response: nil, finish_reason: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_llm/protocols/responses/approvals.rb', line 14 def parse_tool_approvals(output, response: nil, finish_reason: nil) output.select { |item| item['type'] == 'mcp_approval_request' }.to_h do |item| arguments = item['arguments'] arguments = parse_function_call_arguments(arguments, response:, finish_reason:) unless arguments.is_a?(Hash) call = ToolCall.new(id: item.fetch('id'), name: item.fetch('name'), arguments:, remote: true) [call.id, call] end end |
.render_tool_approval_response(tool_call, approved:) ⇒ Object
10 11 12 |
# File 'lib/ruby_llm/protocols/responses/approvals.rb', line 10 def render_tool_approval_response(tool_call, approved:) [{ type: 'mcp_approval_response', approval_request_id: tool_call.id, approve: approved }] end |