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>
164 lines
6.8 KiB
C#
164 lines
6.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Nexus.Api.Data;
|
|
using Nexus.Api.Models;
|
|
using Nexus.Api.Services;
|
|
|
|
namespace Nexus.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/dashboard")]
|
|
public class DashboardController(IDashboardService dashboardService, ITaskService taskService) : ControllerBase
|
|
{
|
|
[HttpGet("status")]
|
|
public async Task<DashboardStatus> GetStatus()
|
|
=> await dashboardService.GetStatusAsync();
|
|
|
|
[HttpGet("agents")]
|
|
public async Task<List<DashboardAgentInfo>> GetAgents()
|
|
=> await dashboardService.GetAgentsAsync();
|
|
|
|
[HttpGet("operations")]
|
|
public async Task<List<FeedEntry>> GetOperations(
|
|
[FromQuery] int limit = 20,
|
|
[FromQuery] string? agent = null)
|
|
=> await dashboardService.GetOperationsAsync(limit, agent);
|
|
|
|
[HttpPost("chat/send")]
|
|
public async Task<ChatResponse> SendChat([FromBody] ChatRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Message))
|
|
return new ChatResponse(false, null, "Message is required");
|
|
|
|
var agentId = string.IsNullOrWhiteSpace(request.AgentId) ? "iris" : request.AgentId.Trim();
|
|
return await dashboardService.SendChatAsync(agentId, request.Message.Trim());
|
|
}
|
|
|
|
[HttpGet("chat/messages")]
|
|
public async Task<List<MessageEntry>> GetMessages(
|
|
[FromQuery] string? sessionKey,
|
|
[FromQuery] int limit = 50,
|
|
[FromQuery] int offset = 0)
|
|
=> await dashboardService.GetMessagesAsync(sessionKey, limit, offset);
|
|
|
|
[HttpGet("queue")]
|
|
public async Task<List<QueueItem>> GetQueue(CancellationToken ct)
|
|
=> await dashboardService.GetQueueAsync(ct);
|
|
|
|
[HttpDelete("queue/{id}")]
|
|
public async Task<ActionResult> DeleteQueueItem(string id, [FromQuery] string? source, CancellationToken ct)
|
|
{
|
|
var result = await dashboardService.DeleteQueueItemAsync(id, source, ct);
|
|
return result.Outcome switch
|
|
{
|
|
QueueDeleteOutcome.Deleted => NoContent(),
|
|
QueueDeleteOutcome.NotFound => NotFound(new { error = "Queue item not found" }),
|
|
QueueDeleteOutcome.GatewayError => StatusCode(502, new { error = "Gateway could not delete cron job" }),
|
|
QueueDeleteOutcome.TaskNotFound => NotFound(new { error = "Task not found" }),
|
|
QueueDeleteOutcome.InvalidTaskId => BadRequest(new { error = "Invalid task id" }),
|
|
_ => StatusCode(500, new { error = "Internal error" })
|
|
};
|
|
}
|
|
|
|
[HttpPut("queue/{id}/priority")]
|
|
public async Task<ActionResult> ChangeQueuePriority(string id, CancellationToken ct)
|
|
{
|
|
var result = await dashboardService.CycleQueuePriorityAsync(id, ct);
|
|
return result.Outcome switch
|
|
{
|
|
QueuePriorityOutcome.Ignored => Ok(new { status = "ignored", reason = "Cron job priorities are managed by the gateway" }),
|
|
QueuePriorityOutcome.TaskNotFound => NotFound(new { error = "Task not found" }),
|
|
QueuePriorityOutcome.InvalidTaskId => BadRequest(new { error = "Invalid task id" }),
|
|
_ => Ok(new { status = "ok", priority = result.NewPriority })
|
|
};
|
|
}
|
|
|
|
[HttpGet("agents/{id}/model")]
|
|
public async Task<ActionResult<AgentModelInfo>> GetAgentModel(string id)
|
|
{
|
|
var info = await dashboardService.GetAgentModelAsync(id);
|
|
return info is null
|
|
? NotFound(new { error = $"Agent '{id}' not found or gateway unreachable" })
|
|
: Ok(info);
|
|
}
|
|
|
|
[HttpPut("agents/{id}/model")]
|
|
public async Task<ActionResult> SetAgentModel(string id, [FromBody] SetModelRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Model))
|
|
return BadRequest(new { error = "Model is required" });
|
|
|
|
var ok = await dashboardService.SetAgentModelAsync(id, request.Model);
|
|
return ok ? Ok(new { status = "ok", model = request.Model }) : StatusCode(502, new { error = "Gateway did not accept the change" });
|
|
}
|
|
|
|
[HttpGet("agents/{id}/activity")]
|
|
public async Task<List<AgentActivityEntry>> GetAgentActivity(string id, [FromQuery] int limit = 5)
|
|
=> await dashboardService.GetAgentActivityAsync(id, limit);
|
|
|
|
[HttpGet("models")]
|
|
public ActionResult<List<ModelOption>> GetAvailableModels()
|
|
=> Ok(dashboardService.GetAvailableModels());
|
|
|
|
// ── Task Endpoints ──
|
|
|
|
[HttpGet("tasks")]
|
|
public async Task<List<DashboardTaskDto>> GetTasks(CancellationToken ct)
|
|
{
|
|
var tasks = await taskService.GetOpenAsync(ct);
|
|
return tasks.Select(MapToDto).ToList();
|
|
}
|
|
|
|
[HttpPost("tasks")]
|
|
public async Task<ActionResult<DashboardTaskDto>> CreateTask(
|
|
[FromBody] CreateDashboardTaskRequest request, CancellationToken ct)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Title))
|
|
return BadRequest(new { error = "Title is required." });
|
|
|
|
var task = await taskService.CreateDashboardTaskAsync(
|
|
request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, ct);
|
|
return Created($"/api/dashboard/tasks/{task.Id}", MapToDto(task));
|
|
}
|
|
|
|
[HttpPut("tasks/{id:guid}")]
|
|
public async Task<ActionResult<DashboardTaskDto>> UpdateTask(
|
|
Guid id, [FromBody] UpdateDashboardTaskRequest request, CancellationToken ct)
|
|
{
|
|
var result = await taskService.UpdateDashboardTaskAsync(
|
|
id, request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => NotFound(new { error = "Task not found." }),
|
|
_ => Ok(MapToDto(result.Task!))
|
|
};
|
|
}
|
|
|
|
[HttpDelete("tasks/{id:guid}")]
|
|
public async Task<ActionResult> DeleteTask(Guid id, CancellationToken ct)
|
|
{
|
|
var result = await taskService.DeleteAsync(id, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => NotFound(new { error = "Task not found." }),
|
|
TaskOperationOutcome.InvalidState => StatusCode(403, new { error = "Only tasks in 'Done' or 'Backlog' state can be deleted." }),
|
|
_ => NoContent()
|
|
};
|
|
}
|
|
|
|
[HttpPatch("tasks/{id:guid}/status")]
|
|
public async Task<ActionResult<DashboardTaskDto>> UpdateTaskStatus(
|
|
Guid id, [FromBody] UpdateDashboardTaskStatusRequest request, CancellationToken ct)
|
|
{
|
|
var result = await taskService.UpdateStatusAsync(id, request.Status, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.InvalidState => BadRequest(new { error = $"Unsupported status: '{request.Status}'. Valid: {string.Join(", ", TaskStateHelper.AllStates)}" }),
|
|
TaskOperationOutcome.NotFound => NotFound(new { error = "Task not found." }),
|
|
_ => Ok(MapToDto(result.Task!))
|
|
};
|
|
}
|
|
|
|
private static DashboardTaskDto MapToDto(WorkTask t) => new(
|
|
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo, t.CreatedAt, t.UpdatedAt);
|
|
}
|