lex-claude 0.3.0 → 0.3.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 513c8f540e4cdda4b2843e24546337c6f1ae55204b86b7393ee5f6dfa821b00a
|
|
4
|
+
data.tar.gz: 83adddcbdaf5b8f270c8cc9405f34dd9ff9bd0524e600ee5d17aa83c6fcb1490
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae5e070c06fa3121427b81d2bac44adae31690aa3592a4289334eef6f5ebccfb7d885cc8c4eee436e99947f461a4b2f29d12c546b7fc1077c00f9723f9215608
|
|
7
|
+
data.tar.gz: 6f18422ad53790e20cf2fda651881fcac2679bbcff9da38199cc817cf38ca715d1d660138edab3d899a7996841d98a38ecdd0368aac029bbd861ee0a4a3e5432
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.1] - 2026-03-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Extended cache fields in `parse_usage`: `cache_ephemeral_1h_tokens`, `cache_ephemeral_5m_tokens`, `cache_deleted_tokens` from Anthropic's `cache_creation` nested object
|
|
7
|
+
- `count_tokens` now returns `:usage` key with standardized usage hash
|
|
8
|
+
- SSE `collect_usage` returns full 7-field usage hash including cache tokens from stream events
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- `parse_usage` refactored to use `uval` helper for dual string/symbol key access
|
|
12
|
+
- SSE `collect_usage` uses `merge_usage` to generically accumulate all usage fields including nested `cache_creation`
|
|
13
|
+
|
|
3
14
|
## [0.3.0] - 2026-03-31
|
|
4
15
|
|
|
5
16
|
### Added
|
|
@@ -47,13 +47,23 @@ module Legion
|
|
|
47
47
|
|
|
48
48
|
def parse_usage(body)
|
|
49
49
|
usage = body.is_a?(Hash) ? (body[:usage] || body['usage'] || {}) : {} # rubocop:disable Legion/Framework/ApiStringKeys
|
|
50
|
+
cache_creation = usage.is_a?(Hash) ? (usage[:cache_creation] || usage['cache_creation'] || {}) : {}
|
|
50
51
|
{
|
|
51
|
-
input_tokens:
|
|
52
|
-
output_tokens:
|
|
53
|
-
cache_read_tokens:
|
|
54
|
-
cache_write_tokens:
|
|
52
|
+
input_tokens: uval(usage, :input_tokens),
|
|
53
|
+
output_tokens: uval(usage, :output_tokens),
|
|
54
|
+
cache_read_tokens: uval(usage, :cache_read_input_tokens),
|
|
55
|
+
cache_write_tokens: uval(usage, :cache_creation_input_tokens),
|
|
56
|
+
cache_ephemeral_1h_tokens: uval(cache_creation, :ephemeral_1h_input_tokens),
|
|
57
|
+
cache_ephemeral_5m_tokens: uval(cache_creation, :ephemeral_5m_input_tokens),
|
|
58
|
+
cache_deleted_tokens: uval(usage, :cache_deleted_input_tokens)
|
|
55
59
|
}
|
|
56
60
|
end
|
|
61
|
+
|
|
62
|
+
def uval(hash, key)
|
|
63
|
+
return 0 unless hash.is_a?(Hash)
|
|
64
|
+
|
|
65
|
+
(hash[key] || hash[key.to_s] || 0).to_i
|
|
66
|
+
end
|
|
57
67
|
end
|
|
58
68
|
end
|
|
59
69
|
end
|
|
@@ -45,22 +45,38 @@ module Legion
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def collect_usage(events)
|
|
48
|
-
|
|
49
|
-
output_tokens = 0
|
|
48
|
+
totals = Hash.new(0)
|
|
50
49
|
|
|
51
50
|
events.each do |e|
|
|
52
51
|
case e[:event]
|
|
53
52
|
when 'message_start'
|
|
54
|
-
|
|
55
|
-
input_tokens += usage.fetch('input_tokens', 0).to_i
|
|
56
|
-
output_tokens += usage.fetch('output_tokens', 0).to_i
|
|
53
|
+
merge_usage(totals, e[:data].dig('message', 'usage'))
|
|
57
54
|
when 'message_delta'
|
|
58
|
-
|
|
59
|
-
output_tokens += usage.fetch('output_tokens', 0).to_i
|
|
55
|
+
merge_usage(totals, e[:data]['usage'])
|
|
60
56
|
end
|
|
61
57
|
end
|
|
62
58
|
|
|
63
|
-
{
|
|
59
|
+
{
|
|
60
|
+
input_tokens: totals['input_tokens'],
|
|
61
|
+
output_tokens: totals['output_tokens'],
|
|
62
|
+
cache_read_tokens: totals['cache_read_input_tokens'],
|
|
63
|
+
cache_write_tokens: totals['cache_creation_input_tokens'],
|
|
64
|
+
cache_ephemeral_1h_tokens: totals['ephemeral_1h_input_tokens'],
|
|
65
|
+
cache_ephemeral_5m_tokens: totals['ephemeral_5m_input_tokens'],
|
|
66
|
+
cache_deleted_tokens: totals['cache_deleted_input_tokens']
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def merge_usage(totals, usage)
|
|
71
|
+
return unless usage.is_a?(Hash)
|
|
72
|
+
|
|
73
|
+
usage.each do |key, val|
|
|
74
|
+
if val.is_a?(Hash)
|
|
75
|
+
val.each { |k, v| totals[k.to_s] += v.to_i }
|
|
76
|
+
else
|
|
77
|
+
totals[key.to_s] += val.to_i
|
|
78
|
+
end
|
|
79
|
+
end
|
|
64
80
|
end
|
|
65
81
|
end
|
|
66
82
|
end
|
|
@@ -61,7 +61,9 @@ module Legion
|
|
|
61
61
|
resolved_betas << :interleaved_thinking if thinking && !resolved_betas.include?(:interleaved_thinking)
|
|
62
62
|
|
|
63
63
|
response = client(api_key: api_key, betas: resolved_betas).post('/v1/messages/count_tokens', body)
|
|
64
|
-
Helpers::Response.handle_response(response)
|
|
64
|
+
result = Helpers::Response.handle_response(response)
|
|
65
|
+
result[:usage] = Helpers::Response.parse_usage(response.body) if response.body.is_a?(Hash)
|
|
66
|
+
result
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
private
|