12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/legion/llm/api/native/routing.rb', line 12
def self.registered(app)
log.debug('[llm][api][routing] registering routing routes')
app.get '/api/llm/routing' do
log.debug('[llm][api][routing] action=list_rules')
require_llm!
rules = Legion::LLM::Router.send(:load_rules)
auto_count = rules.count { |r| r.name.to_s.start_with?('auto:') }
manual_count = rules.size - auto_count
rule_list = rules.map do |rule|
{
name: rule.name,
priority: rule.priority,
conditions: rule.conditions,
target: rule.target,
constraint: rule.constraint,
auto: rule.name.to_s.start_with?('auto:')
}.compact
end
json_response({
routing_enabled: Legion::LLM::Router.routing_enabled?,
auto_rules_populated: Legion::LLM::Router.auto_rules_populated?,
rules: rule_list,
summary: {
total: rules.size,
auto: auto_count,
manual: manual_count
}
})
rescue StandardError => e
handle_exception(e, level: :error, handled: true, operation: 'llm.api.routing.list')
json_error('routing_error', e.message, status_code: 500)
end
log.debug('[llm][api][routing] routing routes registered')
end
|