-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathAgentsController.java
More file actions
54 lines (45 loc) · 1.79 KB
/
AgentsController.java
File metadata and controls
54 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
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
54
package ai.javaclaw.api;
import ai.javaclaw.agents.AgentRegistry;
import ai.javaclaw.agents.AgentWorkspaceResolver;
import ai.javaclaw.agents.ConfiguredAgent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.nio.file.Path;
import java.util.List;
@Controller
public class AgentsController {
private final AgentRegistry agentRegistry;
private final AgentWorkspaceResolver agentWorkspaceResolver;
public AgentsController(AgentRegistry agentRegistry, AgentWorkspaceResolver agentWorkspaceResolver) {
this.agentRegistry = agentRegistry;
this.agentWorkspaceResolver = agentWorkspaceResolver;
}
@GetMapping("/agents")
public String agents(Model model) {
List<AgentView> agents = agentRegistry.getAgents().stream()
.map(configuredAgent -> new AgentView(
configuredAgent.id(),
configuredAgent.provider(),
configuredAgent.model(),
resolveWorkspace(configuredAgent),
configuredAgent.id().equals(agentRegistry.getDefaultAgentId())
))
.toList();
model.addAttribute("agents", agents);
model.addAttribute("hasAgents", !agents.isEmpty());
return "agents";
}
private String resolveWorkspace(ConfiguredAgent configuredAgent) {
Path workspacePath = agentWorkspaceResolver.resolveWorkspacePath(configuredAgent.workspacePath(), configuredAgent.id());
return workspacePath.toString();
}
public record AgentView(
String id,
String provider,
String model,
String workspace,
boolean isDefault
) {
}
}