lex-llm-bedrock 0.1.5 → 0.3.0
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 +18 -0
- data/lex-llm-bedrock.gemspec +1 -1
- data/lib/legion/extensions/llm/bedrock/provider.rb +35 -14
- data/lib/legion/extensions/llm/bedrock/version.rb +1 -1
- data/lib/legion/extensions/llm/bedrock.rb +116 -23
- metadata +3 -7
- data/lib/legion/extensions/llm/bedrock/registry_event_builder.rb +0 -95
- data/lib/legion/extensions/llm/bedrock/registry_publisher.rb +0 -98
- data/lib/legion/extensions/llm/bedrock/transport/exchanges/llm_registry.rb +0 -24
- data/lib/legion/extensions/llm/bedrock/transport/messages/registry_event.rb +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2fdf5749de02e358b9458e391edfc790c954d252a29380e3ca2a6ba4c34e085b
|
|
4
|
+
data.tar.gz: 4662cd33fd1fa36622850662707ef618d936ab96b74ed8dc73680153b5e475c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5117d3c2035ee76b7d3caa18079724b8246aa617765960b32c4b31ab7118171b55a599e87ffb6b712e77ab4bdf00e4fac29f70d0932bd1ea7436b18ea9c4e318
|
|
7
|
+
data.tar.gz: a0457d98e4da2489fce6c0ee0458b9567606a7cbe71cbe2e64d7b8d75030245cd5f11cbf601ed326eca903f5b5c0579a208f8ab7b5ac783f18421363768a5ad9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 - 2026-05-01
|
|
4
|
+
|
|
5
|
+
- Add auto-discovery via CredentialSources and AutoRegistration from lex-llm 0.3.0
|
|
6
|
+
- Self-register discovered instances into Call::Registry at require-time
|
|
7
|
+
- Require lex-llm >= 0.3.0
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 0.2.0 - 2026-04-30
|
|
11
|
+
|
|
12
|
+
- Adopt lex-llm 0.1.9 base contract: flat `default_settings`, base `RegistryPublisher`, base `RegistryEventBuilder`.
|
|
13
|
+
- Replace `provider_settings` call with flat default_settings hash (default_model, region, credentials, whitelist/blacklist, TLS, instances).
|
|
14
|
+
- Remove `Provider.register` call; register configuration options directly via `Configuration.register_provider_options`.
|
|
15
|
+
- Delete local `RegistryPublisher`, `RegistryEventBuilder`, and `transport/` directory; use parameterized base classes from lex-llm.
|
|
16
|
+
- Move `registry_publisher` from `Provider` class method to `Bedrock` module method using `Legion::Extensions::Llm::RegistryPublisher.new(provider_family: :bedrock)`.
|
|
17
|
+
- Rewrite `list_models` to return `Model::Info` with `capabilities`, `modalities_input`, and `modalities_output` derived from Bedrock `inputModalities`/`outputModalities`.
|
|
18
|
+
- Publish discovered models via `publish_models_async` (base contract) instead of `publish_offerings_async`.
|
|
19
|
+
- Bump gemspec dependency to `lex-llm >= 0.1.9`.
|
|
20
|
+
|
|
3
21
|
## 0.1.5 - 2026-04-30
|
|
4
22
|
|
|
5
23
|
- Audit logging, rescue blocks, and README for full observability.
|
data/lex-llm-bedrock.gemspec
CHANGED
|
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
|
|
|
28
28
|
spec.add_dependency 'legion-json', '>= 1.2.1'
|
|
29
29
|
spec.add_dependency 'legion-logging', '>= 1.3.2'
|
|
30
30
|
spec.add_dependency 'legion-settings', '>= 1.3.14'
|
|
31
|
-
spec.add_dependency 'lex-llm', '>= 0.
|
|
31
|
+
spec.add_dependency 'lex-llm', '>= 0.3.0'
|
|
32
32
|
end
|
|
@@ -27,8 +27,6 @@ module Legion
|
|
|
27
27
|
ALIASES = STATIC_MODELS.to_h { |entry| [entry.fetch(:alias), entry.fetch(:model)] }.freeze
|
|
28
28
|
|
|
29
29
|
class << self
|
|
30
|
-
attr_writer :registry_publisher
|
|
31
|
-
|
|
32
30
|
def slug = 'bedrock'
|
|
33
31
|
|
|
34
32
|
def configuration_options
|
|
@@ -47,7 +45,7 @@ module Legion
|
|
|
47
45
|
def capabilities = Capabilities
|
|
48
46
|
|
|
49
47
|
def registry_publisher
|
|
50
|
-
|
|
48
|
+
Bedrock.registry_publisher
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
def resolve_model_id(model_id, config: nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
@@ -96,7 +94,6 @@ module Legion
|
|
|
96
94
|
response = bedrock_client.list_foundation_models(**filters)
|
|
97
95
|
Array(value(response, :model_summaries)).map { |summary| offering_from_summary(summary) }.tap do |offerings|
|
|
98
96
|
log.info { "bedrock.provider.discover_offerings: found #{offerings.size} models" }
|
|
99
|
-
self.class.registry_publisher.publish_offerings_async(offerings, readiness: readiness(live: false))
|
|
100
97
|
end
|
|
101
98
|
end
|
|
102
99
|
|
|
@@ -145,16 +142,11 @@ module Legion
|
|
|
145
142
|
|
|
146
143
|
def list_models
|
|
147
144
|
log.info { 'bedrock.provider.list_models: fetching live model list' }
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
family: offering.metadata[:model_family],
|
|
154
|
-
capabilities: offering.capabilities.map(&:to_s),
|
|
155
|
-
metadata: offering.to_h
|
|
156
|
-
)
|
|
157
|
-
end
|
|
145
|
+
response = bedrock_client.list_foundation_models
|
|
146
|
+
models = Array(value(response, :model_summaries)).filter_map { |summary| model_info_from_summary(summary) }
|
|
147
|
+
log.info { "bedrock.provider.list_models: found #{models.size} models" }
|
|
148
|
+
self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
|
|
149
|
+
models
|
|
158
150
|
end
|
|
159
151
|
|
|
160
152
|
def chat(messages, model:, temperature: nil, max_tokens: nil, tools: {}, tool_prefs: nil, params: {})
|
|
@@ -244,6 +236,23 @@ module Legion
|
|
|
244
236
|
)
|
|
245
237
|
end
|
|
246
238
|
|
|
239
|
+
def model_info_from_summary(summary)
|
|
240
|
+
model = value(summary, :model_id)
|
|
241
|
+
input_mods = Array(value(summary, :input_modalities)).map { |m| m.to_s.downcase }
|
|
242
|
+
output_mods = Array(value(summary, :output_modalities)).map { |m| m.to_s.downcase }
|
|
243
|
+
|
|
244
|
+
Legion::Extensions::Llm::Model::Info.new(
|
|
245
|
+
id: model,
|
|
246
|
+
name: alias_for(model) || model,
|
|
247
|
+
provider: :bedrock,
|
|
248
|
+
family: (normalize_provider(value(summary, :provider_name)) || model_family_for(model)).to_s,
|
|
249
|
+
capabilities: capabilities_from_modalities(input_mods, output_mods, summary),
|
|
250
|
+
modalities_input: input_mods,
|
|
251
|
+
modalities_output: output_mods,
|
|
252
|
+
metadata: normalize_response(summary)
|
|
253
|
+
)
|
|
254
|
+
end
|
|
255
|
+
|
|
247
256
|
def build_offering(model:, model_family:, usage_type:, instance_id: :default, alias_name: nil,
|
|
248
257
|
capabilities: nil, metadata: {})
|
|
249
258
|
Legion::Extensions::Llm::Routing::ModelOffering.new(
|
|
@@ -480,6 +489,18 @@ module Legion
|
|
|
480
489
|
capabilities
|
|
481
490
|
end
|
|
482
491
|
|
|
492
|
+
def capabilities_from_modalities(input_mods, output_mods, summary)
|
|
493
|
+
caps = []
|
|
494
|
+
caps << :embedding if output_mods.include?('embedding')
|
|
495
|
+
unless caps.include?(:embedding)
|
|
496
|
+
caps << :completion
|
|
497
|
+
caps << :streaming if value(summary, :response_streaming_supported)
|
|
498
|
+
end
|
|
499
|
+
caps << :vision if input_mods.include?('image')
|
|
500
|
+
caps << :tools if caps.include?(:completion)
|
|
501
|
+
caps
|
|
502
|
+
end
|
|
503
|
+
|
|
483
504
|
def model_family_for(model)
|
|
484
505
|
normalize_provider(model.to_s.split('.').first)
|
|
485
506
|
end
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'legion/extensions/llm'
|
|
4
4
|
require 'legion/extensions/llm/bedrock/provider'
|
|
5
|
-
require 'legion/extensions/llm/bedrock/registry_event_builder'
|
|
6
|
-
require 'legion/extensions/llm/bedrock/registry_publisher'
|
|
7
5
|
require 'legion/extensions/llm/bedrock/version'
|
|
8
6
|
|
|
9
7
|
module Legion
|
|
@@ -12,38 +10,133 @@ module Legion
|
|
|
12
10
|
# Amazon Bedrock provider extension namespace.
|
|
13
11
|
module Bedrock
|
|
14
12
|
extend ::Legion::Extensions::Core if ::Legion::Extensions.const_defined?(:Core, false)
|
|
13
|
+
extend Legion::Logging::Helper
|
|
14
|
+
extend Legion::Extensions::Llm::AutoRegistration
|
|
15
15
|
|
|
16
16
|
PROVIDER_FAMILY = :bedrock
|
|
17
17
|
|
|
18
|
+
DEFAULT_REGION = 'us-east-2'
|
|
19
|
+
|
|
18
20
|
def self.default_settings
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
usage: { inference: true, embedding: true, token_counting: true },
|
|
35
|
-
limits: { concurrency: 4 }
|
|
36
|
-
}
|
|
37
|
-
)
|
|
21
|
+
{
|
|
22
|
+
enabled: false,
|
|
23
|
+
default_model: 'us.anthropic.claude-sonnet-4-6',
|
|
24
|
+
region: DEFAULT_REGION,
|
|
25
|
+
bearer_token: nil,
|
|
26
|
+
api_key: nil,
|
|
27
|
+
secret_key: nil,
|
|
28
|
+
session_token: nil,
|
|
29
|
+
model_whitelist: [],
|
|
30
|
+
model_blacklist: [],
|
|
31
|
+
model_cache_ttl: 3600,
|
|
32
|
+
tls: { enabled: false, verify: :peer },
|
|
33
|
+
instances: {}
|
|
34
|
+
}
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
def self.provider_class
|
|
41
38
|
Provider
|
|
42
39
|
end
|
|
40
|
+
|
|
41
|
+
def self.registry_publisher
|
|
42
|
+
@registry_publisher ||= Legion::Extensions::Llm::RegistryPublisher.new(provider_family: PROVIDER_FAMILY)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.discover_instances
|
|
46
|
+
candidates = {}
|
|
47
|
+
discover_env_bearer(candidates)
|
|
48
|
+
discover_claude_bearer(candidates)
|
|
49
|
+
discover_env_sigv4(candidates)
|
|
50
|
+
discover_settings(candidates)
|
|
51
|
+
discover_broker(candidates)
|
|
52
|
+
CredentialSources.dedup_credentials(candidates)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.discover_env_bearer(candidates)
|
|
56
|
+
bearer = CredentialSources.env('AWS_BEARER_TOKEN_BEDROCK')
|
|
57
|
+
return unless bearer
|
|
58
|
+
|
|
59
|
+
candidates[:env_bearer] = {
|
|
60
|
+
bearer_token: bearer,
|
|
61
|
+
bedrock_region: CredentialSources.env('AWS_DEFAULT_REGION') || DEFAULT_REGION,
|
|
62
|
+
tier: :cloud
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.discover_claude_bearer(candidates)
|
|
67
|
+
claude_bearer = CredentialSources.claude_env_value('AWS_BEARER_TOKEN_BEDROCK')
|
|
68
|
+
claude_bearer ||= claude_env_pattern_match
|
|
69
|
+
return unless claude_bearer
|
|
70
|
+
|
|
71
|
+
candidates[:claude] = {
|
|
72
|
+
bearer_token: claude_bearer,
|
|
73
|
+
bedrock_region: CredentialSources.claude_env_value('AWS_DEFAULT_REGION') || DEFAULT_REGION,
|
|
74
|
+
tier: :cloud
|
|
75
|
+
}
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.discover_env_sigv4(candidates)
|
|
79
|
+
akid = CredentialSources.env('AWS_ACCESS_KEY_ID')
|
|
80
|
+
skey = CredentialSources.env('AWS_SECRET_ACCESS_KEY')
|
|
81
|
+
return unless akid && skey
|
|
82
|
+
|
|
83
|
+
candidates[:env_sigv4] = {
|
|
84
|
+
api_key: akid, bedrock_access_key_id: akid, bedrock_secret_access_key: skey,
|
|
85
|
+
bedrock_session_token: CredentialSources.env('AWS_SESSION_TOKEN'),
|
|
86
|
+
bedrock_region: CredentialSources.env('AWS_DEFAULT_REGION') || DEFAULT_REGION, tier: :cloud
|
|
87
|
+
}.compact
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.discover_settings(candidates)
|
|
91
|
+
settings = CredentialSources.setting(:extensions, :llm, :bedrock)
|
|
92
|
+
candidates[:settings] = settings.merge(tier: :cloud) if settings.is_a?(Hash) && !settings.empty?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.discover_broker(candidates)
|
|
96
|
+
return unless defined?(Legion::Identity::Broker)
|
|
97
|
+
|
|
98
|
+
broker_creds = broker_aws_credentials
|
|
99
|
+
candidates[:broker] = broker_creds.merge(tier: :cloud) if broker_creds
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Scan Claude config env hash for any key containing all of
|
|
103
|
+
# AWS, BEARER, TOKEN, and BEDROCK fragments (case-insensitive).
|
|
104
|
+
def self.claude_env_pattern_match
|
|
105
|
+
env_hash = CredentialSources.claude_config_value(:env)
|
|
106
|
+
return nil unless env_hash.is_a?(Hash)
|
|
107
|
+
|
|
108
|
+
fragments = %w[AWS BEARER TOKEN BEDROCK]
|
|
109
|
+
_key, value = env_hash.find do |k, _v|
|
|
110
|
+
upper = k.to_s.upcase
|
|
111
|
+
fragments.all? { |frag| upper.include?(frag) }
|
|
112
|
+
end
|
|
113
|
+
value
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Fetch AWS credentials from the Legion Identity Broker.
|
|
117
|
+
def self.broker_aws_credentials
|
|
118
|
+
return nil unless defined?(Legion::Identity::Broker)
|
|
119
|
+
|
|
120
|
+
creds = Legion::Identity::Broker.credentials_for(:aws)
|
|
121
|
+
return nil unless creds.is_a?(Hash)
|
|
122
|
+
|
|
123
|
+
akid = creds[:access_key_id] || creds['access_key_id']
|
|
124
|
+
return nil unless akid
|
|
125
|
+
|
|
126
|
+
{ api_key: akid, bedrock_access_key_id: akid,
|
|
127
|
+
bedrock_secret_access_key: creds[:secret_access_key] || creds['secret_access_key'],
|
|
128
|
+
bedrock_session_token: creds[:session_token] || creds['session_token'],
|
|
129
|
+
bedrock_region: creds[:region] || creds['region'] || DEFAULT_REGION }.compact
|
|
130
|
+
end
|
|
43
131
|
end
|
|
44
132
|
end
|
|
45
133
|
end
|
|
46
134
|
end
|
|
47
135
|
|
|
48
|
-
Legion::Extensions::Llm::
|
|
49
|
-
|
|
136
|
+
if Legion::Extensions::Llm::Configuration.respond_to?(:register_provider_options)
|
|
137
|
+
Legion::Extensions::Llm::Configuration.register_provider_options(
|
|
138
|
+
Legion::Extensions::Llm::Bedrock::Provider.configuration_options
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
Legion::Extensions::Llm::Bedrock.register_discovered_instances
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lex-llm-bedrock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LegionIO
|
|
@@ -85,14 +85,14 @@ dependencies:
|
|
|
85
85
|
requirements:
|
|
86
86
|
- - ">="
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: 0.
|
|
88
|
+
version: 0.3.0
|
|
89
89
|
type: :runtime
|
|
90
90
|
prerelease: false
|
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
93
|
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: 0.
|
|
95
|
+
version: 0.3.0
|
|
96
96
|
description: Amazon Bedrock provider integration for the LegionIO LLM routing framework.
|
|
97
97
|
email:
|
|
98
98
|
- matthewdiverson@gmail.com
|
|
@@ -112,10 +112,6 @@ files:
|
|
|
112
112
|
- lex-llm-bedrock.gemspec
|
|
113
113
|
- lib/legion/extensions/llm/bedrock.rb
|
|
114
114
|
- lib/legion/extensions/llm/bedrock/provider.rb
|
|
115
|
-
- lib/legion/extensions/llm/bedrock/registry_event_builder.rb
|
|
116
|
-
- lib/legion/extensions/llm/bedrock/registry_publisher.rb
|
|
117
|
-
- lib/legion/extensions/llm/bedrock/transport/exchanges/llm_registry.rb
|
|
118
|
-
- lib/legion/extensions/llm/bedrock/transport/messages/registry_event.rb
|
|
119
115
|
- lib/legion/extensions/llm/bedrock/version.rb
|
|
120
116
|
homepage: https://github.com/LegionIO/lex-llm-bedrock
|
|
121
117
|
licenses:
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Legion
|
|
4
|
-
module Extensions
|
|
5
|
-
module Llm
|
|
6
|
-
module Bedrock
|
|
7
|
-
# Builds sanitized lex-llm registry envelopes for Bedrock provider state.
|
|
8
|
-
class RegistryEventBuilder
|
|
9
|
-
include Legion::Logging::Helper
|
|
10
|
-
|
|
11
|
-
def readiness(readiness)
|
|
12
|
-
registry_event_class.public_send(
|
|
13
|
-
readiness[:ready] ? :available : :unavailable,
|
|
14
|
-
provider_offering(readiness),
|
|
15
|
-
runtime: runtime_metadata,
|
|
16
|
-
health: readiness_health(readiness),
|
|
17
|
-
metadata: readiness_metadata(readiness)
|
|
18
|
-
)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def offering_available(offering, readiness:)
|
|
22
|
-
registry_event_class.available(
|
|
23
|
-
offering,
|
|
24
|
-
runtime: runtime_metadata,
|
|
25
|
-
health: offering_health(readiness),
|
|
26
|
-
metadata: offering_metadata
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
def provider_offering(readiness)
|
|
33
|
-
{
|
|
34
|
-
provider_family: :bedrock,
|
|
35
|
-
provider_instance: provider_instance,
|
|
36
|
-
transport: :aws_sdk,
|
|
37
|
-
model: 'provider-readiness',
|
|
38
|
-
usage_type: :inference,
|
|
39
|
-
capabilities: [],
|
|
40
|
-
health: readiness_health(readiness),
|
|
41
|
-
metadata: { lex: :llm_bedrock, provider_readiness: true }
|
|
42
|
-
}
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def readiness_health(readiness)
|
|
46
|
-
health = {
|
|
47
|
-
ready: readiness[:ready] == true,
|
|
48
|
-
status: readiness[:ready] ? :available : :unavailable,
|
|
49
|
-
checked: readiness[:checked] != false
|
|
50
|
-
}
|
|
51
|
-
add_readiness_error(health, readiness)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def add_readiness_error(health, source)
|
|
55
|
-
error_class = source[:error] || source['error']
|
|
56
|
-
error_message = source[:message] || source['message']
|
|
57
|
-
health[:error_class] = error_class if error_class
|
|
58
|
-
health[:error] = error_message if error_message
|
|
59
|
-
health
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def offering_health(readiness)
|
|
63
|
-
ready = readiness.fetch(:ready, true) == true
|
|
64
|
-
{ ready:, status: ready ? :available : :degraded, checked: readiness[:checked] != false }
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def readiness_metadata(readiness)
|
|
68
|
-
{
|
|
69
|
-
extension: :lex_llm_bedrock,
|
|
70
|
-
provider: :bedrock,
|
|
71
|
-
configured: readiness[:configured] == true,
|
|
72
|
-
live: readiness[:live] == true
|
|
73
|
-
}
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def offering_metadata
|
|
77
|
-
{ extension: :lex_llm_bedrock, provider: :bedrock }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def runtime_metadata
|
|
81
|
-
{ node: provider_instance }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def provider_instance
|
|
85
|
-
:bedrock
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def registry_event_class
|
|
89
|
-
::Legion::Extensions::Llm::Routing::RegistryEvent
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Legion
|
|
4
|
-
module Extensions
|
|
5
|
-
module Llm
|
|
6
|
-
module Bedrock
|
|
7
|
-
# Best-effort publisher for Bedrock provider availability events.
|
|
8
|
-
class RegistryPublisher
|
|
9
|
-
include Legion::Logging::Helper
|
|
10
|
-
|
|
11
|
-
APP_ID = 'lex-llm-bedrock'
|
|
12
|
-
|
|
13
|
-
def initialize(builder: RegistryEventBuilder.new)
|
|
14
|
-
@builder = builder
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def publish_readiness_async(readiness)
|
|
18
|
-
log.debug { 'bedrock.registry_publisher.publish_readiness_async: scheduling readiness event' }
|
|
19
|
-
schedule { publish_event(@builder.readiness(readiness)) }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def publish_offerings_async(offerings, readiness:)
|
|
23
|
-
log.debug do
|
|
24
|
-
"bedrock.registry_publisher.publish_offerings_async: scheduling #{Array(offerings).size} offerings"
|
|
25
|
-
end
|
|
26
|
-
schedule do
|
|
27
|
-
Array(offerings).each do |offering|
|
|
28
|
-
publish_event(@builder.offering_available(offering, readiness:))
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def schedule(&)
|
|
36
|
-
return false unless publishing_available?
|
|
37
|
-
|
|
38
|
-
Thread.new do
|
|
39
|
-
Thread.current.abort_on_exception = false
|
|
40
|
-
yield
|
|
41
|
-
rescue StandardError => e
|
|
42
|
-
handle_exception(e, level: :debug, handled: true, operation: 'bedrock.registry_publisher.schedule')
|
|
43
|
-
end
|
|
44
|
-
rescue StandardError => e
|
|
45
|
-
handle_exception(e, level: :debug, handled: true, operation: 'bedrock.registry_publisher.schedule')
|
|
46
|
-
false
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def publish_event(event)
|
|
50
|
-
return false unless publishing_available?
|
|
51
|
-
|
|
52
|
-
message_class.new(event:, app_id: APP_ID).publish(spool: false)
|
|
53
|
-
rescue StandardError => e
|
|
54
|
-
handle_exception(e, level: :warn, handled: true, operation: 'bedrock.registry_publisher.publish_event')
|
|
55
|
-
false
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def publishing_available?
|
|
59
|
-
return false unless registry_event_available?
|
|
60
|
-
return false unless transport_message_available?
|
|
61
|
-
return true unless defined?(::Legion::Transport::Connection)
|
|
62
|
-
return true unless ::Legion::Transport::Connection.respond_to?(:session_open?)
|
|
63
|
-
|
|
64
|
-
::Legion::Transport::Connection.session_open?
|
|
65
|
-
rescue StandardError => e
|
|
66
|
-
handle_exception(e, level: :debug, handled: true,
|
|
67
|
-
operation: 'bedrock.registry_publisher.publishing_available?')
|
|
68
|
-
false
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def registry_event_available?
|
|
72
|
-
defined?(::Legion::Extensions::Llm::Routing::RegistryEvent)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def transport_message_available?
|
|
76
|
-
return true if message_class_defined?
|
|
77
|
-
return false unless defined?(::Legion::Transport::Message) && defined?(::Legion::Transport::Exchange)
|
|
78
|
-
|
|
79
|
-
require 'legion/extensions/llm/bedrock/transport/messages/registry_event'
|
|
80
|
-
message_class_defined?
|
|
81
|
-
rescue LoadError => e
|
|
82
|
-
handle_exception(e, level: :debug, handled: true,
|
|
83
|
-
operation: 'bedrock.registry_publisher.transport_message_available?')
|
|
84
|
-
false
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def message_class_defined?
|
|
88
|
-
defined?(::Legion::Extensions::Llm::Bedrock::Transport::Messages::RegistryEvent)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def message_class
|
|
92
|
-
::Legion::Extensions::Llm::Bedrock::Transport::Messages::RegistryEvent
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Legion
|
|
4
|
-
module Extensions
|
|
5
|
-
module Llm
|
|
6
|
-
module Bedrock
|
|
7
|
-
module Transport
|
|
8
|
-
module Exchanges
|
|
9
|
-
# Topic exchange for Bedrock provider availability events.
|
|
10
|
-
class LlmRegistry < ::Legion::Transport::Exchange
|
|
11
|
-
def exchange_name
|
|
12
|
-
'llm.registry'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def default_type
|
|
16
|
-
'topic'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'legion/extensions/llm/bedrock/transport/exchanges/llm_registry'
|
|
4
|
-
|
|
5
|
-
module Legion
|
|
6
|
-
module Extensions
|
|
7
|
-
module Llm
|
|
8
|
-
module Bedrock
|
|
9
|
-
module Transport
|
|
10
|
-
module Messages
|
|
11
|
-
# Publishes lex-llm RegistryEvent envelopes to the llm.registry exchange.
|
|
12
|
-
class RegistryEvent < ::Legion::Transport::Message
|
|
13
|
-
def initialize(event:, **options)
|
|
14
|
-
super(**event.to_h.merge(options))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def exchange
|
|
18
|
-
Transport::Exchanges::LlmRegistry
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def routing_key
|
|
22
|
-
@options[:routing_key] || "llm.registry.#{@options.fetch(:event_type)}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def type
|
|
26
|
-
'llm.registry.event'
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def app_id
|
|
30
|
-
@options[:app_id] || RegistryPublisher::APP_ID
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def persistent # rubocop:disable Naming/PredicateMethod
|
|
34
|
-
false
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|