open_router_enhanced 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e39d5924a6388355a4ecae7a76933bf429546a3a5da1975d5dd020804735d24
4
- data.tar.gz: 220e9504b58ad511e971a8c4a13939edef2c390f0ffeb031e21dfdb30ce78941
3
+ metadata.gz: 34c685a89892a839ba66999ed50a0ed066db83f3a21c95c96edfdc25ade6a2b5
4
+ data.tar.gz: e3fdeb547d1588933cb85984f582d5d18db0b12e40c9adaa2dcb02f400f1b012
5
5
  SHA512:
6
- metadata.gz: 61f753aedc0057758a7cb8310ba06b5751da07ca17ed6bd433473e8ce36184286a37060cd32b2595ac9a8b5e9c798cd2db078ae5c7ddf2232c4b6c271d44623a
7
- data.tar.gz: bb9f8c9122ddc7fc1c850b34a76ee9e209ca14ff95ff4fe2dbd68b8fccdf10021f78111cd994c0e0f3a163ee61512434b39410227ec818cbf52a1cf22aac5ff6
6
+ metadata.gz: c33bca90ab16de26ba7bc7d6c995314f2a5b93b99b1b60a8ffb3fae0eaac94edb275b3777e6bbdd86b34aafe11526aab946b857334013b40cb327620cb91a55c
7
+ data.tar.gz: 790593fb868bb3728ae91630ecbbd85e660fcc1d00a51400cdcfb1fc10f0ef3395eb46dc2624a5af1590cfe6f8a788ae37f3fac651db362bb4556d6fc4e8ee46
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.1] - 2025-12-24
4
+
5
+ ### Fixed
6
+ - Memoized `output_id` in `ResponsesToolResult` to ensure consistent IDs across multiple calls
7
+ - Memoized `message_output` and `reasoning_output` finders in `ResponsesResponse` for performance
8
+
3
9
  ## [1.2.0] - 2025-12-24
4
10
 
5
11
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- open_router_enhanced (1.2.0)
4
+ open_router_enhanced (1.2.1)
5
5
  activesupport (>= 6.0, < 9.0)
6
6
  dotenv (>= 2.0, < 4.0)
7
7
  faraday (>= 1.0, < 3.0)
@@ -9,6 +9,7 @@ require "pry"
9
9
  module OpenRouter
10
10
  class ServerError < StandardError; end
11
11
 
12
+ # rubocop:disable Metrics/ClassLength
12
13
  class Client
13
14
  include OpenRouter::HTTP
14
15
 
@@ -103,8 +104,10 @@ module OpenRouter
103
104
  # @param extras [Hash] Optional hash of model-specific parameters to send to the OpenRouter API
104
105
  # @param stream [Proc, nil] Optional callable object for streaming
105
106
  # @return [Response] The completion response wrapped in a Response object.
107
+ # rubocop:disable Metrics/ParameterLists
106
108
  def complete(messages, model: "openrouter/auto", providers: [], transforms: [], plugins: [], tools: [], tool_choice: nil,
107
109
  response_format: nil, force_structured_output: nil, prediction: nil, extras: {}, stream: nil)
110
+ # rubocop:enable Metrics/ParameterLists
108
111
  parameters = prepare_base_parameters(messages, model, providers, transforms, plugins, prediction, stream, extras)
109
112
  forced_extraction = configure_tools_and_structured_outputs!(parameters, model, tools, tool_choice,
110
113
  response_format, force_structured_output)
@@ -666,4 +669,5 @@ module OpenRouter
666
669
  INSTRUCTION
667
670
  end
668
671
  end
672
+ # rubocop:enable Metrics/ClassLength
669
673
  end
@@ -367,9 +367,9 @@ module OpenRouter
367
367
  total_size = Dir.glob(File.join(CACHE_DIR, "**/*"))
368
368
  .select { |f| File.file?(f) }
369
369
  .sum do |f|
370
- File.size(f)
371
- rescue StandardError
372
- 0
370
+ File.size(f)
371
+ rescue StandardError
372
+ 0
373
373
  end
374
374
  total_size / (1024.0 * 1024.0)
375
375
  end
@@ -48,9 +48,10 @@ module OpenRouter
48
48
  end
49
49
 
50
50
  # Check if reasoning was included in the response
51
- def has_reasoning?
51
+ def reasoning?
52
52
  !reasoning_output.nil?
53
53
  end
54
+ alias has_reasoning? reasoning?
54
55
 
55
56
  # Get tool/function calls from the response as ResponsesToolCall objects
56
57
  #
@@ -68,9 +69,10 @@ module OpenRouter
68
69
  output.select { |o| o["type"] == "function_call" }
69
70
  end
70
71
 
71
- def has_tool_calls?
72
+ def tool_calls?
72
73
  tool_calls.any?
73
74
  end
75
+ alias has_tool_calls? tool_calls?
74
76
 
75
77
  # Execute all tool calls and return results
76
78
  #
@@ -137,9 +139,7 @@ module OpenRouter
137
139
  end
138
140
 
139
141
  # Add assistant message if present
140
- if message_output
141
- input_items << message_output
142
- end
142
+ input_items << message_output if message_output
143
143
 
144
144
  # Add follow-up user message if provided
145
145
  if follow_up_message
@@ -155,15 +155,15 @@ module OpenRouter
155
155
 
156
156
  # Token counts
157
157
  def input_tokens
158
- usage.dig("input_tokens") || 0
158
+ usage["input_tokens"] || 0
159
159
  end
160
160
 
161
161
  def output_tokens
162
- usage.dig("output_tokens") || 0
162
+ usage["output_tokens"] || 0
163
163
  end
164
164
 
165
165
  def total_tokens
166
- usage.dig("total_tokens") || 0
166
+ usage["total_tokens"] || 0
167
167
  end
168
168
 
169
169
  def reasoning_tokens
@@ -182,11 +182,11 @@ module OpenRouter
182
182
  private
183
183
 
184
184
  def message_output
185
- output.find { |o| o["type"] == "message" }
185
+ @message_output ||= output.find { |o| o["type"] == "message" }
186
186
  end
187
187
 
188
188
  def reasoning_output
189
- output.find { |o| o["type"] == "reasoning" }
189
+ @reasoning_output ||= output.find { |o| o["type"] == "reasoning" }
190
190
  end
191
191
  end
192
192
  end
@@ -18,9 +18,7 @@ module OpenRouter
18
18
  end
19
19
 
20
20
  # Get the function name
21
- def name
22
- @name
23
- end
21
+ attr_reader :name
24
22
 
25
23
  # Alias for consistency with ToolCall
26
24
  def function_name
@@ -56,12 +54,13 @@ module OpenRouter
56
54
  class ResponsesToolResult
57
55
  include ToolResultBase
58
56
 
59
- attr_reader :tool_call, :result, :error
57
+ attr_reader :tool_call, :result, :error, :output_id
60
58
 
61
59
  def initialize(tool_call, result = nil, error = nil)
62
60
  @tool_call = tool_call
63
61
  @result = result
64
62
  @error = error
63
+ @output_id = "fc_output_#{SecureRandom.hex(8)}"
65
64
  end
66
65
 
67
66
  # Convert to function_call_output format for conversation continuation
@@ -78,7 +77,7 @@ module OpenRouter
78
77
 
79
78
  {
80
79
  "type" => "function_call_output",
81
- "id" => "fc_output_#{SecureRandom.hex(8)}",
80
+ "id" => @output_id,
82
81
  "call_id" => @tool_call.call_id,
83
82
  "output" => output_content
84
83
  }
@@ -50,6 +50,7 @@ module OpenRouter
50
50
  !success?
51
51
  end
52
52
 
53
+ # Factory methods for creating tool results
53
54
  module ClassMethods
54
55
  # Create a failed result
55
56
  def failure(tool_call, error)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenRouter
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_router_enhanced
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Stiens