using Codex.Dal;
using Codex.Dal.Enums;
using Microsoft.EntityFrameworkCore;
namespace Codex.Api.Endpoints;
///
/// Simple, pragmatic REST endpoints for MVP.
/// No over-engineering. Just JSON lists that work.
///
public static class SimpleEndpoints
{
public static WebApplication MapSimpleEndpoints(this WebApplication app)
{
// ============================================================
// AGENTS
// ============================================================
app.MapGet("/api/agents", async (CodexDbContext db) =>
{
var agents = await db.Agents
.Where(a => !a.IsDeleted)
.OrderByDescending(a => a.CreatedAt)
.Select(a => new
{
a.Id,
a.Name,
a.Description,
a.Type,
a.ModelProvider,
a.ModelName,
a.ProviderType,
a.ModelEndpoint,
a.Status,
a.CreatedAt,
a.UpdatedAt,
ToolCount = a.Tools.Count(t => t.IsEnabled),
ExecutionCount = a.Executions.Count
})
.Take(100) // More than enough for MVP
.ToListAsync();
return Results.Ok(agents);
})
.WithName("GetAllAgents")
.WithTags("Agents")
.WithOpenApi(operation =>
{
operation.Summary = "Get all agents";
operation.Description = "Returns a list of all active agents with metadata. Limit: 100 most recent.";
return operation;
})
.Produces