lex-llm-anthropic 0.2.6 → 0.2.7
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/lib/legion/extensions/llm/anthropic/actors/fleet_worker.rb +10 -1
- data/lib/legion/extensions/llm/anthropic/provider.rb +13 -0
- data/lib/legion/extensions/llm/anthropic/registry_event_builder.rb +7 -1
- data/lib/legion/extensions/llm/anthropic/registry_publisher.rb +17 -17
- data/lib/legion/extensions/llm/anthropic/version.rb +1 -1
- data/lib/legion/extensions/llm/anthropic.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 706b82cf938d0f347b19db1fbf2f1e66ff0a1fc2c0029c20ba0696b14463bf16
|
|
4
|
+
data.tar.gz: addcd78f5164cef165a316369f69fc6e8cabbd0e338f0a2c7bb6daacc8638392
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51a06c3a1c8e14435677f4ca79a7f8adadbcf497c7228ace93d7e6afaa1d2ae9d8796a0d36594ed8b8aa966e9ec85716a25da20a1ef80388527e7fcc944e3955
|
|
7
|
+
data.tar.gz: 58d3e043cc3f82a0982198a70535c321681236e637832c437674d54f9247449743f4a92519e4df562a54db5466267a8269351a9f9d2f493214f65a0f74440981
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.7 - 2026-05-13
|
|
4
|
+
|
|
5
|
+
- Use `Legion::Logging::Helper` for Anthropic provider and registry diagnostics.
|
|
6
|
+
- Route registry fallback errors through `handle_exception` with useful operation metadata.
|
|
7
|
+
|
|
3
8
|
## 0.2.6 - 2026-05-08
|
|
4
9
|
|
|
5
10
|
- Accept keyword arguments in `list_models` to match the base provider contract called by `discover_offerings`.
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/logging/helper'
|
|
4
|
+
|
|
5
|
+
actor_load_logger = Object.new.extend(Legion::Logging::Helper)
|
|
6
|
+
actor_load_logger.define_singleton_method(:lex_filename) { 'llm_anthropic' }
|
|
7
|
+
|
|
3
8
|
begin
|
|
4
9
|
require 'legion/extensions/actors/subscription'
|
|
5
10
|
rescue LoadError => e
|
|
6
|
-
|
|
11
|
+
subscription_load_error = e
|
|
7
12
|
end
|
|
8
13
|
|
|
9
14
|
unless defined?(Legion::Extensions::Actors::Subscription)
|
|
15
|
+
if subscription_load_error
|
|
16
|
+
actor_load_logger.handle_exception(subscription_load_error, level: :warn, handled: true,
|
|
17
|
+
operation: 'anthropic.actor.subscription_load')
|
|
18
|
+
end
|
|
10
19
|
raise LoadError, 'LegionIO actor runtime is required for Anthropic fleet worker'
|
|
11
20
|
end
|
|
12
21
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'legion/extensions/llm'
|
|
4
|
+
require 'legion/logging/helper'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
6
7
|
module Extensions
|
|
@@ -8,6 +9,8 @@ module Legion
|
|
|
8
9
|
module Anthropic
|
|
9
10
|
# Anthropic Messages API provider implementation for the Legion::Extensions::Llm contract.
|
|
10
11
|
class Provider < Legion::Extensions::Llm::Provider # rubocop:disable Metrics/ClassLength
|
|
12
|
+
include Legion::Logging::Helper
|
|
13
|
+
|
|
11
14
|
class << self
|
|
12
15
|
attr_writer :registry_publisher
|
|
13
16
|
|
|
@@ -52,7 +55,9 @@ module Legion
|
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
def list_models(**)
|
|
58
|
+
log.debug { 'listing available Anthropic models' }
|
|
55
59
|
super.tap do |models|
|
|
60
|
+
log.debug { "discovered #{Array(models).size} Anthropic model(s); publishing to registry" }
|
|
56
61
|
self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
|
|
57
62
|
end
|
|
58
63
|
end
|
|
@@ -60,6 +65,7 @@ module Legion
|
|
|
60
65
|
private
|
|
61
66
|
|
|
62
67
|
def render_payload(messages, tools:, temperature:, model:, stream:, schema:, thinking:, tool_prefs:) # rubocop:disable Metrics/ParameterLists
|
|
68
|
+
log_render_payload(messages:, tools:, model:, stream:, schema:)
|
|
63
69
|
system_messages, chat_messages = messages.partition { |message| message.role == :system }
|
|
64
70
|
|
|
65
71
|
{
|
|
@@ -76,6 +82,13 @@ module Legion
|
|
|
76
82
|
}.compact
|
|
77
83
|
end
|
|
78
84
|
|
|
85
|
+
def log_render_payload(messages:, tools:, model:, stream:, schema:)
|
|
86
|
+
log.debug do
|
|
87
|
+
"rendering Anthropic #{stream ? 'stream' : 'chat'} payload for #{model.id} " \
|
|
88
|
+
"with #{messages.size} message(s), #{tools.size} tool(s), schema=#{!schema.nil?}"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
79
92
|
def system_content(messages)
|
|
80
93
|
content = messages.flat_map { |message| content_blocks(message.content) }
|
|
81
94
|
content.empty? ? nil : content
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/logging/helper'
|
|
4
|
+
|
|
3
5
|
module Legion
|
|
4
6
|
module Extensions
|
|
5
7
|
module Llm
|
|
6
8
|
module Anthropic
|
|
7
9
|
# Builds sanitized lex-llm registry envelopes for Anthropic provider state.
|
|
8
10
|
class RegistryEventBuilder
|
|
11
|
+
include Legion::Logging::Helper
|
|
12
|
+
|
|
9
13
|
def model_available(model, readiness:)
|
|
10
14
|
registry_event_class.available(
|
|
11
15
|
model_offering(model),
|
|
@@ -54,7 +58,9 @@ module Legion
|
|
|
54
58
|
configured_node = (::Legion::Settings.dig(:node, :canonical_name) if defined?(::Legion::Settings))
|
|
55
59
|
value = configured_node.to_s.strip
|
|
56
60
|
value.empty? ? :anthropic : value.to_sym
|
|
57
|
-
rescue StandardError
|
|
61
|
+
rescue StandardError => e
|
|
62
|
+
handle_exception(e, level: :debug, handled: true,
|
|
63
|
+
operation: 'anthropic.registry.provider_instance')
|
|
58
64
|
:anthropic
|
|
59
65
|
end
|
|
60
66
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/logging/helper'
|
|
4
|
+
|
|
3
5
|
module Legion
|
|
4
6
|
module Extensions
|
|
5
7
|
module Llm
|
|
6
8
|
module Anthropic
|
|
7
9
|
# Best-effort publisher for Anthropic provider availability events.
|
|
8
10
|
class RegistryPublisher
|
|
11
|
+
include Legion::Logging::Helper
|
|
12
|
+
|
|
9
13
|
APP_ID = 'lex-llm-anthropic'
|
|
10
14
|
|
|
11
15
|
def initialize(builder: RegistryEventBuilder.new)
|
|
@@ -13,6 +17,7 @@ module Legion
|
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
def publish_models_async(models, readiness:)
|
|
20
|
+
log.debug { "publishing #{Array(models).size} Anthropic model event(s) to llm.registry" }
|
|
16
21
|
schedule do
|
|
17
22
|
Array(models).each do |model|
|
|
18
23
|
publish_event(@builder.model_available(model, readiness:))
|
|
@@ -29,10 +34,12 @@ module Legion
|
|
|
29
34
|
Thread.current.abort_on_exception = false
|
|
30
35
|
yield
|
|
31
36
|
rescue StandardError => e
|
|
32
|
-
|
|
37
|
+
handle_exception(e, level: :debug, handled: true,
|
|
38
|
+
operation: 'anthropic.registry.schedule_thread')
|
|
33
39
|
end
|
|
34
40
|
rescue StandardError => e
|
|
35
|
-
|
|
41
|
+
handle_exception(e, level: :debug, handled: true,
|
|
42
|
+
operation: 'anthropic.registry.schedule')
|
|
36
43
|
false
|
|
37
44
|
end
|
|
38
45
|
|
|
@@ -41,7 +48,8 @@ module Legion
|
|
|
41
48
|
|
|
42
49
|
message_class.new(event:, app_id: APP_ID).publish(spool: false)
|
|
43
50
|
rescue StandardError => e
|
|
44
|
-
|
|
51
|
+
handle_exception(e, level: :warn, handled: true,
|
|
52
|
+
operation: 'anthropic.registry.publish_event')
|
|
45
53
|
false
|
|
46
54
|
end
|
|
47
55
|
|
|
@@ -52,7 +60,9 @@ module Legion
|
|
|
52
60
|
return true unless ::Legion::Transport::Connection.respond_to?(:session_open?)
|
|
53
61
|
|
|
54
62
|
::Legion::Transport::Connection.session_open?
|
|
55
|
-
rescue StandardError
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
handle_exception(e, level: :debug, handled: true,
|
|
65
|
+
operation: 'anthropic.registry.publishing_available?')
|
|
56
66
|
false
|
|
57
67
|
end
|
|
58
68
|
|
|
@@ -66,7 +76,9 @@ module Legion
|
|
|
66
76
|
|
|
67
77
|
require 'legion/extensions/llm/anthropic/transport/messages/registry_event'
|
|
68
78
|
message_class_defined?
|
|
69
|
-
rescue LoadError
|
|
79
|
+
rescue LoadError => e
|
|
80
|
+
handle_exception(e, level: :debug, handled: true,
|
|
81
|
+
operation: 'anthropic.registry.transport_load')
|
|
70
82
|
false
|
|
71
83
|
end
|
|
72
84
|
|
|
@@ -77,18 +89,6 @@ module Legion
|
|
|
77
89
|
def message_class
|
|
78
90
|
::Legion::Extensions::Llm::Anthropic::Transport::Messages::RegistryEvent
|
|
79
91
|
end
|
|
80
|
-
|
|
81
|
-
def log_publish_failure(error, level: :warn)
|
|
82
|
-
message = "[lex-llm-anthropic] llm.registry publish failed: #{error.class}: #{error.message}"
|
|
83
|
-
logger = ::Legion::Extensions::Llm.logger if defined?(::Legion::Extensions::Llm)
|
|
84
|
-
if logger.respond_to?(level)
|
|
85
|
-
logger.public_send(level, message)
|
|
86
|
-
elsif logger.respond_to?(:debug)
|
|
87
|
-
logger.debug(message)
|
|
88
|
-
end
|
|
89
|
-
rescue StandardError
|
|
90
|
-
nil
|
|
91
|
-
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'legion/extensions/llm'
|
|
4
|
+
require 'legion/logging/helper'
|
|
4
5
|
require 'legion/extensions/llm/anthropic/registry_event_builder'
|
|
5
6
|
require 'legion/extensions/llm/anthropic/registry_publisher'
|
|
6
7
|
require 'legion/extensions/llm/anthropic/provider'
|
|
@@ -12,6 +13,7 @@ module Legion
|
|
|
12
13
|
# Anthropic provider extension namespace.
|
|
13
14
|
module Anthropic
|
|
14
15
|
extend ::Legion::Extensions::Core if ::Legion::Extensions.const_defined?(:Core, false)
|
|
16
|
+
extend Legion::Logging::Helper
|
|
15
17
|
extend Legion::Extensions::Llm::AutoRegistration
|
|
16
18
|
|
|
17
19
|
PROVIDER_FAMILY = :anthropic
|