Module: Legion::LLM::Router::HeaderConstraints
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/router/header_constraints.rb
Overview
Trusted routing constraints from canonical X-Legion-* headers (SSOT v3 §7.3) or from explicit internal arguments. These are HARD constraints, not body hints — X-Legion-Model is the deliberate escape hatch and is never subject to the D19 body whitelist/blacklist. Malformed trusted hints raise Errors::InvalidHeader (HTTP 400).
Defined Under Namespace
Classes: Value
Constant Summary collapse
- HEADER_KEYS =
{ provider: 'X-Legion-Provider', instance_id: 'X-Legion-Instance', model: 'X-Legion-Model', tier: 'X-Legion-Tier', maximum_attempts: 'X-Legion-Max-Attempts' }.freeze
Class Method Summary collapse
- .call(headers:, settings_snapshot:) ⇒ Object
- .from_internal(settings_snapshot:, provider: nil, instance_id: nil, model: nil, tier: nil, maximum_attempts: nil) ⇒ Object
Class Method Details
.call(headers:, settings_snapshot:) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/legion/llm/router/header_constraints.rb', line 38 def self.call(headers:, settings_snapshot:) raw = HEADER_KEYS.transform_values { |name| fetch_header(headers, name) } from_internal( provider: raw[:provider], instance_id: raw[:instance_id], model: raw[:model], tier: raw[:tier], maximum_attempts: raw[:maximum_attempts], settings_snapshot: settings_snapshot ) end |
.from_internal(settings_snapshot:, provider: nil, instance_id: nil, model: nil, tier: nil, maximum_attempts: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/legion/llm/router/header_constraints.rb', line 46 def self.from_internal(settings_snapshot:, provider: nil, instance_id: nil, model: nil, tier: nil, maximum_attempts: nil) Value.new( provider: normalize_provider(normalize_utf8!(provider, HEADER_KEYS[:provider])), instance_id: blank_to_nil(normalize_utf8!(instance_id, HEADER_KEYS[:instance_id])), model: blank_to_nil(normalize_utf8!(model, HEADER_KEYS[:model])), tier: normalize_tier(normalize_utf8!(tier, HEADER_KEYS[:tier])), maximum_attempts: normalize_max_attempts(normalize_utf8!(maximum_attempts, HEADER_KEYS[:maximum_attempts]), settings_snapshot) ) end |