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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8689f00ee81cef79b268cbe7ee94cbc4e243488e34a68397af609543e6a34305
4
- data.tar.gz: eb1c05e7db5f8e322d286b00263fd8aa402d0989860cb5c86443bbe0357671ec
3
+ metadata.gz: 99a567735a4299c9772d4f8da83db0e0a79f546c8e6dda1f5ff97c5d94cba849
4
+ data.tar.gz: 9b0dab8a910c81ca19a4a9124958e8cb915a5bae601e28106242097491c3d99f
5
5
  SHA512:
6
- metadata.gz: 9f9a6640fc83eb4640df99eeb03d1581c1d6fab7addb59a23fe154804b760e4c41bdd51d994d433ed0c47ae0a9b7c53b0eee8e8bc90060cbef6aeabde641b1fa
7
- data.tar.gz: 2f3ddb1f8d0d028e557f1b8037c0ba1754bfca699d276fab627c0a7de28e9d85ec5bd830eb484e64a8be72671b968dc8d9a8aecdfc52df50efa526a414209313
6
+ metadata.gz: ac91d469375b3923985a2c2ee31fe1a0ae298d7daf69a2b34a617c85ede7e18c4143c66622d96bdf28832054e62a1e5272c7c654fb572b37ca5f277f882fe668
7
+ data.tar.gz: 1421869fbb95bc2b354c7c9bec559bba48bbbae85c69bba3dff54073fd1e2041eca01da3800a9869ec7b1d2079ee1efff6f1332ebc2af81862ba082b7b0533b6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.3] - 2026-04-06
4
+
5
+ ### Added
6
+ - Credential-only identity module for Phase 8 Broker integration (`Identity` module with `provide_token`)
7
+
3
8
  ## [0.3.2] - 2026-03-31
4
9
 
5
10
  ### Added
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.1.2
14
- **Specs**: 18 examples
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(api_key:, model:, messages:, ...), count_tokens(api_key:, model:, messages:, ...)
22
- │ ├── Models # list(api_key:, ...), retrieve(api_key:, model_id:, ...)
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
- └── Client # Faraday-based Anthropic API client (module, factory method)
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 a `client(api_key:, ...)` factory method. It sets `x-api-key` and `anthropic-version` headers. The `API_VERSION` constant is `'2023-06-01'` and `DEFAULT_HOST` is `'https://api.anthropic.com'`. All runner modules `extend` it.
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
- `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 any per-call overrides and delegates to `Helpers::Client.client(...)`.
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
- - `Helpers::Client` uses `module_function`, making `client(...)` callable as both a module-level method and as an instance method when mixed in. Runners use `extend Helpers::Client` to get `client(...)` as a module-level method.
36
- - `Client` class uses `include` (not `extend`) so runner methods become instance methods on the client object.
37
- - The Batches runner uses JSON-only payloads — no multipart dependency.
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 # 18 examples
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
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Claude
6
- VERSION = '0.3.2'
6
+ VERSION = '0.3.3'
7
7
  end
8
8
  end
9
9
  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.2
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