boxcars 0.10.9 → 0.10.10

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: 64b7e543514bf7d455bbc551248f34adff8c302422f59ebae31f43b314bf64d7
4
- data.tar.gz: 577e41b5b0361fc07173f2eec4a452f4021d5c826de6d89514c16d50d88bf24e
3
+ metadata.gz: 8d767d4ab5ffda00912f46c865922bbe971fd2c338cde5af54ccfbeffe5f1e70
4
+ data.tar.gz: c24a5d73b1597ee71ef5643740891e3641cd180658e2177d285fcb86d2f0deb2
5
5
  SHA512:
6
- metadata.gz: e54505c0d6a801c364d671032469795f17ac094e77855becbe8770d909c9771fc52efa7434fcb1ad225282bad519e16d68181c22851a5555c48abb648c10f0b5
7
- data.tar.gz: 84f62b772954edfd3555da6de18ba0e300e7fbdc76b6862dfae15f1b4e86de80161fc9990fc509c3d9508173b46b36adebebf43562e95c8f1fcab9ce8c5c0039
6
+ metadata.gz: 950f1737c92124bacb12ad99ab0baf29a800205c2fbd048b8629340bededc3615436cfd6b7ed93d9e379fcbfd6628428127144cd84cfae30ab75b9c18fd59e71
7
+ data.tar.gz: e67b18640bdb04014a173c84ff84b75f5e761c2d56d32b1fce531f94de0039eb474f23c7b01faf62f7c4b29a1904190c91abe5618f98a04fa798600c1363f8f7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.10.10] - 2026-05-07
6
+
7
+ ### Fixed
8
+
9
+ - Anthropic responses now extract and join all text-bearing content blocks, including Claude responses where `thinking` blocks precede the final text block.
10
+
5
11
  ## [0.10.9] - 2026-04-30
6
12
 
7
13
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.10.9)
4
+ boxcars (0.10.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -118,18 +118,21 @@ module Boxcars
118
118
  response_data[:parsed_json] = normalized_response
119
119
 
120
120
  if normalized_response && !normalized_response["error"]
121
- response_data[:success] = true
122
121
  response_data[:status_code] = 200 # Inferred
122
+ normalize_anthropic_usage!(normalized_response)
123
+
123
124
  # Transform response to match expected format
124
- normalized_response["completion"] = normalized_response.dig("content", 0, "text")
125
+ normalized_response["completion"] = extract_anthropic_completion(normalized_response)
126
+
127
+ if normalized_response["completion"].empty?
128
+ response_data[:success] = false
129
+ response_data[:error] ||= Error.new("Anthropic response contained no text content")
130
+ return
131
+ end
132
+
133
+ response_data[:success] = true
125
134
  normalized_response["choices"] ||= [{ "text" => normalized_response["completion"],
126
135
  "finish_reason" => normalized_response["stop_reason"] }]
127
- if normalized_response["usage"].is_a?(Hash)
128
- normalized_response["usage"]["prompt_tokens"] ||= normalized_response["usage"]["input_tokens"]
129
- normalized_response["usage"]["completion_tokens"] ||= normalized_response["usage"]["output_tokens"]
130
- normalized_response["usage"]["total_tokens"] ||= normalized_response["usage"]["prompt_tokens"].to_i +
131
- normalized_response["usage"]["completion_tokens"].to_i
132
- end
133
136
  normalized_response.delete("content")
134
137
  else
135
138
  response_data[:success] = false
@@ -139,6 +142,33 @@ module Boxcars
139
142
  end
140
143
  end
141
144
 
145
+ def extract_anthropic_completion(normalized_response)
146
+ content = normalized_response["content"]
147
+ blocks = content.is_a?(Array) ? content : [content]
148
+
149
+ blocks.filter_map { |block| extract_anthropic_text_block(block) }.join("\n").strip
150
+ end
151
+
152
+ def extract_anthropic_text_block(block)
153
+ case block
154
+ when String
155
+ block
156
+ when Hash
157
+ block["text"] || block[:text]
158
+ else
159
+ block.text if block.respond_to?(:text)
160
+ end
161
+ end
162
+
163
+ def normalize_anthropic_usage!(normalized_response)
164
+ return unless normalized_response["usage"].is_a?(Hash)
165
+
166
+ normalized_response["usage"]["prompt_tokens"] ||= normalized_response["usage"]["input_tokens"]
167
+ normalized_response["usage"]["completion_tokens"] ||= normalized_response["usage"]["output_tokens"]
168
+ normalized_response["usage"]["total_tokens"] ||= normalized_response["usage"]["prompt_tokens"].to_i +
169
+ normalized_response["usage"]["completion_tokens"].to_i
170
+ end
171
+
142
172
  # Handle errors from Anthropic API calls
143
173
  def handle_anthropic_error(error, response_data)
144
174
  response_data[:error] = error
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Boxcars
4
4
  # The current version of the gem.
5
- VERSION = "0.10.9"
5
+ VERSION = "0.10.10"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxcars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.9
4
+ version: 0.10.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Sullivan