7
8
9
10
11
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
51
52
53
|
# File 'lib/legate/web/routes/api_routes.rb', line 7
def self.registered(app)
app.get '/api/agents' do
content_type :json
agents_data = []
current_app_instance = self definition_store = current_app_instance.instance_variable_get(:@definition_store)
active_agents_hash = current_app_instance.instance_variable_get(:@agents)
if definition_store
begin
agent_summaries = definition_store.list_definitions
agents_data = agent_summaries.map do |summary|
agent_name = summary[:name]
running_key = agent_name.to_s
is_running = active_agents_hash.key?(running_key)
current_model = if is_running && active_agents_hash[running_key]
active_agents_hash[running_key].model_name
else
summary[:model]
end
{
name: agent_name,
description: summary[:description] || 'N/A',
running: is_running,
model: current_model
}
end
rescue Legate::DefinitionStore::StoreError => e
logger.error("Store error fetching agent list for API (from ApiRoutes): #{e.message}")
agents_data = []
end
else
logger.error('Definition Store unavailable during GET /api/agents (from ApiRoutes)')
end
json agents: agents_data.sort_by { |a| a[:name] }
end
app.get '/api/tools' do
content_type :json
json tools: Legate::GlobalToolManager.list_all_tools
end
end
|