active_harness 0.2.37 → 0.2.38

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: 5fb1f238ea442c93d556e18ef1b899ad8d8e8345c6ed18c8abd0d45370c847e0
4
- data.tar.gz: 8c8b0dceb9c779f6432dc86f141fdda65144b365511ee3096957a96954447b4e
3
+ metadata.gz: '064709a78ef949aadd741237f4cdd5a2f36056d211fa2038048a2911fc45a5be'
4
+ data.tar.gz: 298318704ce083cf46b87dc5dbaebbae15df127a313685ea32d5c82b03191072
5
5
  SHA512:
6
- metadata.gz: fd1da6cb093ea99b414576fe9e1fc2ec0fee4a894eca5bd5291582ea5daabdb1ee621f22a5b7e4460455c03fd47df5b152b5d9598c64df9a408cbaec93ca3371
7
- data.tar.gz: 939c5d39b1f172ae0225087f095e8665c84b34f6cc384bf2e8f949e871a0be63c3ecf59253e253a1066c40c6c41528f57c8b09790720dca765c8760175ce36ad
6
+ metadata.gz: b7c4e5a06e8f8a66e89a0f0b2289c7f461e76cd942a374abb5e6a3845f35e348b8b5fc63182e384d825863ef4c8698c59b64d606d11b5eb27bcada47b1d57642
7
+ data.tar.gz: 3528828f40f1a11a0b62b45ff193b49e05cc202e09e754a578e94c372279cdb760622d5e33de3f61aeef62d7cf15166197a4e0d2a5637d0c4cb8e5d5cf332112
@@ -1,12 +1,36 @@
1
1
  module ActiveHarness
2
2
  class Agent
3
+ # Providers that have a dedicated pricing source beyond ModelsDev.
4
+ # Consulted in tier-2 before the general ModelsDev fallback.
5
+ # Add entries here when a new provider-specific source is available.
6
+ PROVIDER_PRICING_SOURCES = {
7
+ openrouter: Pricing::OpenRouter
8
+ }.freeze
9
+
3
10
  private
4
11
 
5
- # Builds a CostBreakdown for a single request from token usage and
6
- # pricing data from ActiveHarness::Pricing.
7
- #
8
- # Returns CostBreakdown (input, output, total in USD),
9
- # or nil if usage is absent or the model is not found in the pricing registry.
12
+ # Cost lookup three-tier fallback:
13
+ # 1. provider_cost in the API response (handled in build_usage)
14
+ # 2. provider-specific source (e.g. Pricing::OpenRouter for :openrouter)
15
+ # 3. Pricing::ModelsDev general fallback
16
+ # nil when no data found at any tier
17
+ def lookup_model_cost(entry)
18
+ return nil unless entry
19
+
20
+ model = entry[:model].to_s
21
+ provider = entry[:provider].to_sym
22
+
23
+ source = PROVIDER_PRICING_SOURCES[provider]
24
+ cost = source&.find(model)
25
+ return cost if cost
26
+
27
+ Pricing::ModelsDev.find(model)
28
+ rescue StandardError
29
+ nil
30
+ end
31
+
32
+ # Builds a CostBreakdown from token counts and per-million rates.
33
+ # Returns nil when pricing or token data is absent.
10
34
  def calculate_cost(pricing, tokens)
11
35
  return nil unless pricing && tokens
12
36
  return nil unless pricing.input_per_million && pricing.output_per_million
@@ -198,18 +198,6 @@ module ActiveHarness
198
198
  UsageInfo.new(tokens: tokens, cost: cost)
199
199
  end
200
200
 
201
- def lookup_model_cost(entry)
202
- return nil unless entry
203
-
204
- if entry[:provider].to_sym == :openrouter
205
- Pricing::OpenRouter.find(entry[:model].to_s) || Pricing.find(entry[:model].to_s)
206
- else
207
- Pricing.find(entry[:model].to_s)
208
- end
209
- rescue StandardError
210
- nil
211
- end
212
-
213
201
  def normalize_input!
214
202
  return if @config.fetch(:normalize_input, true) == false
215
203
  @input = @input&.strip&.gsub(/\s+/, " ")
@@ -32,7 +32,7 @@ require_relative "active_harness/pipeline"
32
32
  require_relative "active_harness/railtie" if defined?(Rails::Railtie)
33
33
 
34
34
  module ActiveHarness
35
- VERSION = "0.2.37"
35
+ VERSION = "0.2.38"
36
36
 
37
37
  class << self
38
38
  # Configure ActiveHarness.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.37
4
+ version: 0.2.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - the-teacher