lex-claude 0.3.2 → 0.3.3
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/CLAUDE.md +27 -12
- data/README.md +8 -0
- data/lib/legion/extensions/claude/identity.rb +44 -0
- data/lib/legion/extensions/claude/version.rb +1 -1
- data/lib/legion/extensions/claude.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99a567735a4299c9772d4f8da83db0e0a79f546c8e6dda1f5ff97c5d94cba849
|
|
4
|
+
data.tar.gz: 9b0dab8a910c81ca19a4a9124958e8cb915a5bae601e28106242097491c3d99f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac91d469375b3923985a2c2ee31fe1a0ae298d7daf69a2b34a617c85ede7e18c4143c66622d96bdf28832054e62a1e5272c7c654fb572b37ca5f277f882fe668
|
|
7
|
+
data.tar.gz: 1421869fbb95bc2b354c7c9bec559bba48bbbae85c69bba3dff54073fd1e2041eca01da3800a9869ec7b1d2079ee1efff6f1332ebc2af81862ba082b7b0533b6
|
data/CHANGELOG.md
CHANGED
data/CLAUDE.md
CHANGED
|
@@ -6,35 +6,48 @@
|
|
|
6
6
|
|
|
7
7
|
## Purpose
|
|
8
8
|
|
|
9
|
-
Legion Extension that connects LegionIO to the Claude Anthropic API. Provides runners for message creation, token counting, model listing, and asynchronous batch processing.
|
|
9
|
+
Legion Extension that connects LegionIO to the Claude Anthropic API. Provides runners for message creation (streaming and non-streaming), token counting, model listing, and asynchronous batch processing. Full support for prompt caching, extended thinking, structured output, web search, effort control, fast mode, and context management betas.
|
|
10
10
|
|
|
11
11
|
**GitHub**: https://github.com/LegionIO/lex-claude
|
|
12
12
|
**License**: MIT
|
|
13
|
-
**Version**: 0.
|
|
14
|
-
**Specs**:
|
|
13
|
+
**Version**: 0.3.3
|
|
14
|
+
**Specs**: 134 examples (12 spec files)
|
|
15
15
|
|
|
16
16
|
## Architecture
|
|
17
17
|
|
|
18
18
|
```
|
|
19
19
|
Legion::Extensions::Claude
|
|
20
20
|
├── Runners/
|
|
21
|
-
│ ├── Messages # create
|
|
22
|
-
│ ├── Models # list
|
|
21
|
+
│ ├── Messages # create, create_stream, count_tokens
|
|
22
|
+
│ ├── Models # list, retrieve
|
|
23
23
|
│ └── Batches # create_batch, list_batches, retrieve_batch, cancel_batch, batch_results
|
|
24
24
|
├── Helpers/
|
|
25
|
-
│
|
|
25
|
+
│ ├── Client # Faraday-based Anthropic API client (module + streaming_client factory)
|
|
26
|
+
│ ├── Errors # structured exception hierarchy (ApiError, RateLimitError, AuthenticationError, etc.)
|
|
27
|
+
│ ├── Models # model symbol alias resolution (Helpers::Models.resolve)
|
|
28
|
+
│ ├── Response # response handling + usage parsing (handle_response, parse_usage)
|
|
29
|
+
│ ├── Retry # Helpers::Retry.with_retry (configurable max_attempts)
|
|
30
|
+
│ ├── Sse # SSE stream parser (parse_stream, collect_text, collect_usage)
|
|
31
|
+
│ └── Tools # tool descriptor builders (web_search)
|
|
26
32
|
└── Client # Standalone client class (includes all runners, holds @config)
|
|
27
33
|
```
|
|
28
34
|
|
|
29
|
-
`Helpers::Client` is a **module** with
|
|
35
|
+
`Helpers::Client` is a **module** with two factory methods:
|
|
36
|
+
- `client(api_key:, betas: nil, ...)` — standard Faraday connection, sets `x-api-key` and `anthropic-version` headers, encodes betas as `anthropic-beta` header.
|
|
37
|
+
- `streaming_client(api_key:, betas: nil)` — same connection but configured for streaming responses.
|
|
30
38
|
|
|
31
|
-
`
|
|
39
|
+
`API_VERSION = '2023-06-01'`. `DEFAULT_HOST = 'https://api.anthropic.com'`.
|
|
40
|
+
|
|
41
|
+
`Client` (class) provides a standalone instantiable wrapper. It `include`s all runner modules and holds a persistent `@config` hash. Its private `client(**override_opts)` merges config with per-call overrides and delegates to `Helpers::Client.client(...)`.
|
|
32
42
|
|
|
33
43
|
## Key Design Decisions
|
|
34
44
|
|
|
35
|
-
- `
|
|
36
|
-
- `
|
|
37
|
-
-
|
|
45
|
+
- `Messages#create` auto-resolves beta headers based on opts: `cache_scope: :global` adds `:prompt_caching_scope`, `thinking:` adds `:interleaved_thinking`, `output_config.format` adds `:structured_outputs`, `output_config.effort` adds `:effort`, `fast_mode: true` adds `:fast_mode`, `context_management:` adds `:context_management`.
|
|
46
|
+
- `Messages#create_stream` uses `Helpers::Sse.parse_stream` for SSE event parsing. Returns `{ result: accumulated_text, events:, usage:, status: 200 }`.
|
|
47
|
+
- `Messages#count_tokens` posts to `/v1/messages/count_tokens`.
|
|
48
|
+
- `Batches` runner uses JSON-only payloads — no multipart dependency.
|
|
49
|
+
- `Helpers::Errors.from_response` builds typed exceptions from HTTP status codes.
|
|
50
|
+
- `Helpers::Retry.with_retry` retries on rate limit and server errors with exponential backoff.
|
|
38
51
|
- `include Legion::Extensions::Helpers::Lex` is guarded: only included when `lex-lex` is loaded.
|
|
39
52
|
|
|
40
53
|
## Dependencies
|
|
@@ -43,15 +56,17 @@ Legion::Extensions::Claude
|
|
|
43
56
|
|-----|---------|
|
|
44
57
|
| `faraday` >= 2.0 | HTTP client for Anthropic API |
|
|
45
58
|
| `multi_json` | JSON parser abstraction |
|
|
59
|
+
| `legion-cache`, `legion-crypt`, `legion-data`, `legion-json`, `legion-logging`, `legion-settings`, `legion-transport` | LegionIO core |
|
|
46
60
|
|
|
47
61
|
## Testing
|
|
48
62
|
|
|
49
63
|
```bash
|
|
50
64
|
bundle install
|
|
51
|
-
bundle exec rspec #
|
|
65
|
+
bundle exec rspec # 134 examples
|
|
52
66
|
bundle exec rubocop
|
|
53
67
|
```
|
|
54
68
|
|
|
55
69
|
---
|
|
56
70
|
|
|
57
71
|
**Maintained By**: Matthew Iverson (@Esity)
|
|
72
|
+
**Last Updated**: 2026-04-06
|
data/README.md
CHANGED
|
@@ -191,6 +191,10 @@ result = Legion::Extensions::Claude::Helpers::Retry.with_retry(max_attempts: 3)
|
|
|
191
191
|
end
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
## Version
|
|
195
|
+
|
|
196
|
+
0.3.3
|
|
197
|
+
|
|
194
198
|
## Dependencies
|
|
195
199
|
|
|
196
200
|
- `faraday` >= 2.0 — HTTP client
|
|
@@ -208,6 +212,10 @@ end
|
|
|
208
212
|
- `legion-llm` — High-level LLM interface
|
|
209
213
|
- `extensions-ai/CLAUDE.md` — Architecture patterns shared across all AI extensions
|
|
210
214
|
|
|
215
|
+
## Version
|
|
216
|
+
|
|
217
|
+
0.3.3
|
|
218
|
+
|
|
211
219
|
## License
|
|
212
220
|
|
|
213
221
|
MIT
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Claude
|
|
6
|
+
module Identity
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def provider_name = :anthropic
|
|
10
|
+
def provider_type = :credential
|
|
11
|
+
def facing = nil
|
|
12
|
+
def capabilities = %i[credentials]
|
|
13
|
+
|
|
14
|
+
def resolve(canonical_name: nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
15
|
+
nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def provide_token
|
|
19
|
+
api_key = resolve_api_key
|
|
20
|
+
return nil unless api_key
|
|
21
|
+
|
|
22
|
+
Legion::Identity::Lease.new(
|
|
23
|
+
provider: :anthropic,
|
|
24
|
+
credential: api_key,
|
|
25
|
+
expires_at: nil,
|
|
26
|
+
renewable: false,
|
|
27
|
+
issued_at: Time.now,
|
|
28
|
+
metadata: { credential_type: :api_key }
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def resolve_api_key
|
|
33
|
+
return nil unless defined?(Legion::Settings)
|
|
34
|
+
|
|
35
|
+
value = Legion::Settings.dig(:llm, :providers, :anthropic, :api_key)
|
|
36
|
+
value = value.find { |v| v && !v.empty? } if value.is_a?(Array)
|
|
37
|
+
value unless value.nil? || (value.is_a?(String) && (value.empty? || value.start_with?('env://')))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private_class_method :resolve_api_key
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -11,6 +11,7 @@ require 'legion/extensions/claude/helpers/models'
|
|
|
11
11
|
require 'legion/extensions/claude/runners/messages'
|
|
12
12
|
require 'legion/extensions/claude/runners/models'
|
|
13
13
|
require 'legion/extensions/claude/runners/batches'
|
|
14
|
+
require 'legion/extensions/claude/identity'
|
|
14
15
|
|
|
15
16
|
module Legion
|
|
16
17
|
module Extensions
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lex-claude
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
@@ -164,6 +164,7 @@ files:
|
|
|
164
164
|
- lib/legion/extensions/claude/helpers/retry.rb
|
|
165
165
|
- lib/legion/extensions/claude/helpers/sse.rb
|
|
166
166
|
- lib/legion/extensions/claude/helpers/tools.rb
|
|
167
|
+
- lib/legion/extensions/claude/identity.rb
|
|
167
168
|
- lib/legion/extensions/claude/runners/batches.rb
|
|
168
169
|
- lib/legion/extensions/claude/runners/messages.rb
|
|
169
170
|
- lib/legion/extensions/claude/runners/models.rb
|