fix: Agents hartcodiert mit File-Activity-Detection
- Tools/invoke Visibility scoped auf agent:main → keine Iris-Sessions sichtbar
- Hardcoded 6 Agenten mit korrekten Models
- Activity: checkt /mnt/workspace-{id}/memory Dateizeitstempel
This commit is contained in:
@@ -87,61 +87,56 @@ public sealed class OpenClawGatewayClient(HttpClient httpClient, IConfiguration
|
||||
|
||||
public async Task<List<DashboardAgentInfo>> GetAgentsAsync()
|
||||
{
|
||||
// Hardcoded agent list (known from OpenClaw config).
|
||||
// Tools/invoke visibility is restricted to agent:main scope,
|
||||
// so we can't enumerate Iris sessions programmatically.
|
||||
var agentDefs = new[]
|
||||
{
|
||||
new { Id = "iris", Name = "Iris", Model = "GPT-5.4" },
|
||||
new { Id = "programmer", Name = "Programmer", Model = "DeepSeek V4 Flash" },
|
||||
new { Id = "reviewer", Name = "Reviewer", Model = "DeepSeek V4 Pro" },
|
||||
new { Id = "architekt", Name = "DevOps", Model = "DeepSeek V4 Pro" },
|
||||
new { Id = "executor", Name = "Executor", Model = "DeepSeek V4 Flash" },
|
||||
new { Id = "researcher", Name = "Researcher", Model = "DeepSeek V4 Pro" },
|
||||
};
|
||||
|
||||
var agents = new List<DashboardAgentInfo>();
|
||||
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Get sessions list
|
||||
var sessionsResult = await InvokeToolAsync("sessions_list");
|
||||
var sessionsData = ExtractToolData(sessionsResult);
|
||||
|
||||
if (sessionsData is JsonObject so)
|
||||
foreach (var def in agentDefs)
|
||||
{
|
||||
// sessions_list returns { agents: [...], sessions: {...} }
|
||||
// Try agents array first (from gateway call)
|
||||
if (so["agents"] is JsonArray agentArray)
|
||||
{
|
||||
foreach (var a in agentArray)
|
||||
{
|
||||
if (a is null) continue;
|
||||
var id = a["agentId"]?.GetValue<string>() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(id) || !seenIds.Add(id)) continue;
|
||||
var name = a["name"]?.GetValue<string>() ?? id;
|
||||
var model = "GPT-5.4"; // default, overridden if available
|
||||
var isActive = false;
|
||||
var currentTask = (string?)null;
|
||||
string? currentTask = null;
|
||||
|
||||
// Check if agent has recent sessions (active indicator)
|
||||
if (a["sessions"] is JsonObject sess && sess["recent"] is JsonArray recent && recent.Count > 0)
|
||||
// Check workspace activity via file timestamps
|
||||
var memDir = $"/mnt/workspace-{def.Id}/memory";
|
||||
try
|
||||
{
|
||||
var age = recent[0]?["age"]?.GetValue<long>() ?? long.MaxValue;
|
||||
isActive = age < 300_000; // active if session < 5 min ago
|
||||
currentTask = recent[0]?["key"]?.GetValue<string>();
|
||||
}
|
||||
|
||||
agents.Add(new DashboardAgentInfo(id, name, DeriveRole(id), model, isActive, currentTask));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also get subagents list
|
||||
var subResult = await InvokeToolAsync("subagents", new { action = "list" });
|
||||
var subData = ExtractToolData(subResult);
|
||||
|
||||
if (subData is JsonArray subArray)
|
||||
if (Directory.Exists(memDir))
|
||||
{
|
||||
foreach (var s in subArray)
|
||||
{
|
||||
if (s is null) continue;
|
||||
var id = s["id"]?.GetValue<string>() ?? s["agentId"]?.GetValue<string>() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(id) || !seenIds.Add(id)) continue;
|
||||
var name = s["name"]?.GetValue<string>() ?? id;
|
||||
var status = s["status"]?.GetValue<string>() ?? "";
|
||||
var isActive = status is "active" or "running";
|
||||
var currentTask = s["task"]?.GetValue<string>() ?? s["currentTask"]?.GetValue<string>();
|
||||
var latestFile = Directory.GetFiles(memDir, "*", SearchOption.AllDirectories)
|
||||
.Select(f => new FileInfo(f))
|
||||
.OrderByDescending(f => f.LastWriteTimeUtc)
|
||||
.FirstOrDefault();
|
||||
|
||||
agents.Add(new DashboardAgentInfo(id, name, DeriveRole(id), "", isActive, currentTask));
|
||||
if (latestFile is not null)
|
||||
{
|
||||
var age = DateTime.UtcNow - latestFile.LastWriteTimeUtc;
|
||||
isActive = age.TotalMinutes < 15;
|
||||
if (isActive)
|
||||
currentTask = $"Modified: {latestFile.Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { /* workspace not mounted or inaccessible */ }
|
||||
|
||||
agents.Add(new DashboardAgentInfo(
|
||||
Id: def.Id,
|
||||
Name: def.Name,
|
||||
Role: DeriveRole(def.Id),
|
||||
Model: def.Model,
|
||||
IsActive: isActive,
|
||||
CurrentTask: currentTask
|
||||
));
|
||||
}
|
||||
|
||||
return agents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user