4ad0f9e493
## Backend — Service Layer & Repository Refactoring ### Neue Services (21 neue Dateien) **Interfaces & Implementierungen:** - `IOpenClawGatewayClient` — Interface für OpenClawGatewayClient (DIP-Fix: DashboardController hing an konkreter Klasse) - `IAgentConfigService` / `AgentConfigService` — Agent-Config-File-I/O aus AgentsController extrahiert - `IProjectService` / `ProjectService` — Projekt-CRUD + Activity-Logging (SRP) - `ITaskService` / `TaskService` — Task-State-Machine, Approve/Reject, Dashboard-Operationen (eliminiert Duplikation zwischen TasksController und DashboardController) - `IDashboardService` / `DashboardService` — Queue-Aggregation, Priority-Normalisierung, Gateway-Delegation - `IOperationsService` / `OperationsService` — Metriken-Berechnung aus OperationsController - `ITeamService` / `TeamService` — IDENTITY.md-Lesen aus TeamController - `IMemoryService` / `MemoryService` — File-I/O aus MemoryController - `IIncidentService` / `IncidentService` — File-Parsing (Regex-Source-Generatoren) aus IncidentsController - `IDocService` / `DocService` — Directory-Scan aus DocsController - `ICalendarService` / `CalendarService` — Gateway-HTTP-Calls + Fallback-Daten aus CalendarController ### Repository-Fixes **IUserRepository / UserRepository:** - `SaveChangesAsync` entfernt (leaky abstraction — Caller sollten nie SaveChanges steuern) - `RevokeTokenAsync(tokenHash)` — atomares Token-Revoke inkl. SaveChanges - `RevokeFamilyAsync(familyId)` — Batch-Revoke einer Token-Familie inkl. SaveChanges - `RemoveExpiredTokensAsync` speichert jetzt selbst (war vorher dependent auf nachfolgenden Save) ### AuthService-Fixes - `GetUserAsync`: unnötiges `Task.Run` entfernt → direkt `_users.GetByIdAsync().AsTask()` - `RevokeAsync`: delegiert jetzt an `IUserRepository.RevokeTokenAsync` - `RefreshAsync`: Token-Reuse-Detection delegiert an `IUserRepository.RevokeFamilyAsync` ### Bug-Fix - `OpenClawGatewayClient.ReadAgentGoalAsync`: pre-existing `CS1656` behoben (`reader` war `using`-Variable und wurde neu zugewiesen — in `reader2` umbenannt) ### Controller (16 Stück — alle slim) Alle Controller reduziert auf: Input validieren → Service aufrufen → HTTP-Result zurückgeben. Kein Business-Logic, kein File-I/O, keine direkte Repository-Nutzung (außer AgentsController für Activity-Log). **Program.cs — neue Registrierungen:** - `AddHttpClient<IOpenClawGatewayClient, OpenClawGatewayClient>` (war vorher konkrete Klasse) - Scoped: IDashboardService, IProjectService, ITaskService, IOperationsService, ITeamService, ICalendarService - Singleton: IAgentConfigService, IMemoryService, IIncidentService, IDocService --- ## Frontend — Dashboard V2 Components **AgentDetailModal.vue, IrisChat.vue, TaskStrip.vue:** - V2 Design-System: Dark Space Theme, Glass-Panels, Gradient-Akzente - Stores (agents, chat, tasks) nutzen Service + Mapper-Pattern - NexusLayout, FlowBoard, Topbar — Layoutfixes für fullHeight-Route-Meta Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
101 lines
4.1 KiB
C#
101 lines
4.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
using Nexus.Api.DTOs;
|
|
using Nexus.Api.Integrations;
|
|
using Nexus.Api.Repositories;
|
|
using Nexus.Api.Services;
|
|
|
|
namespace Nexus.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/v1/agents")]
|
|
public class AgentsController(
|
|
IAgentService agentService,
|
|
IAgentRuntime runtime,
|
|
IActivityRepository activityRepo,
|
|
IAgentConfigService agentConfigService,
|
|
ILogger<AgentsController> logger) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IResult> GetAgents(CancellationToken ct)
|
|
{
|
|
var agents = await agentService.GetAgentsAsync(ct);
|
|
return Results.Ok(agents.Select(a => new AgentListResponse(
|
|
a.Id, a.Name, a.Role, a.Model, a.Status.ToString(), a.LastSeen, a.Workspace, a.Description)));
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<IResult> GetAgent(string id, CancellationToken ct)
|
|
{
|
|
var agent = await agentService.GetAgentAsync(id, ct);
|
|
if (agent is null) return Results.NotFound();
|
|
return Results.Ok(new AgentDetailResponse(
|
|
agent.Id, agent.Name, agent.Role, agent.Model, agent.Status.ToString(),
|
|
agent.LastSeen, agent.Workspace, agent.AgentDir, agent.Description,
|
|
agent.SubAgents, agent.IdentityName));
|
|
}
|
|
|
|
[HttpGet("{id}/activity")]
|
|
public async Task<IResult> GetAgentActivity(string id, CancellationToken ct)
|
|
{
|
|
var items = await activityRepo.GetByAgentAsync(id, 50, ct);
|
|
return Results.Ok(items.Select(x => new { x.Id, x.Type, x.Message, at = x.CreatedAt }));
|
|
}
|
|
|
|
[HttpPost("{id}/command")]
|
|
[EnableRateLimiting("agents")]
|
|
public async Task<IResult> SendCommand(string id, [FromBody] AgentCommandRequest request, CancellationToken ct)
|
|
{
|
|
var message = request.Message?.Trim();
|
|
if (string.IsNullOrWhiteSpace(message) || message.Length > 8000)
|
|
return Results.ValidationProblem(new Dictionary<string, string[]> { ["message"] = ["Message must contain between 1 and 8000 characters."] });
|
|
|
|
var conversationId = $"nexus-command-{id}-{Guid.NewGuid():N}";
|
|
|
|
try
|
|
{
|
|
var result = await runtime.ChatAsync(message, conversationId, id, ct);
|
|
await activityRepo.AddAsync(new Data.ActivityEvent { Type = "agent", Message = $"Command sent to agent {id}: {message[..Math.Min(message.Length, 80)]}" }, ct);
|
|
return Results.Ok(new AgentCommandResponse(result.Runtime, result.AgentId, result.ConversationId, result.Content));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogWarning(exception, "Agent command failed for {AgentId}", id);
|
|
return Results.Problem(
|
|
title: "Agent command failed",
|
|
detail: $"Could not send command to agent {id}: {exception.Message}",
|
|
statusCode: StatusCodes.Status503ServiceUnavailable);
|
|
}
|
|
}
|
|
|
|
// ── Config Editor ──
|
|
|
|
[HttpGet("{id}/config")]
|
|
public IResult GetConfig(string id)
|
|
=> Results.Ok(agentConfigService.GetConfigFiles(id));
|
|
|
|
[HttpGet("{id}/config/{fileName}")]
|
|
public async Task<IResult> GetConfigFile(string id, string fileName, CancellationToken ct)
|
|
{
|
|
var file = await agentConfigService.GetConfigFileAsync(id, fileName, ct);
|
|
return file is null
|
|
? Results.NotFound()
|
|
: Results.Ok(new { file.FileName, file.Content, file.Size, file.ModifiedAt });
|
|
}
|
|
|
|
[HttpPut("{id}/config/{fileName}")]
|
|
public async Task<IResult> SaveConfigFile(string id, string fileName, [FromBody] SaveConfigRequest request, CancellationToken ct)
|
|
{
|
|
if (request.Content is null)
|
|
return Results.BadRequest(new { error = "Content is required." });
|
|
|
|
if (request.Content.Length > 500 * 1024)
|
|
return Results.BadRequest(new { error = "Content exceeds maximum size of 500KB." });
|
|
|
|
var result = await agentConfigService.SaveConfigFileAsync(id, fileName, request.Content, ct);
|
|
return result is null
|
|
? Results.BadRequest(new { error = "Invalid filename or path." })
|
|
: Results.Ok(new { result.FileName, result.Size, result.ModifiedAt });
|
|
}
|
|
}
|