Files
Teamup/src/Modules/TeamUp.Modules.Assembler/Endpoints/AssemblerEndpoints.cs
T

43 lines
1.8 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.EntityFrameworkCore;
using TeamUp.Modules.Assembler.Domain;
using TeamUp.Modules.Assembler.Persistence;
using TeamUp.SharedKernel.Ai;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Assembler.Endpoints;
internal static class AssemblerEndpoints
{
public static void Map(IEndpointRouteBuilder endpoints)
{
var group = endpoints.MapGroup("/api/assembler").WithTags("Assembler");
group.MapGet("/ping", () => TypedResults.Ok(new ModulePing("assembler")));
group.MapPost("/runs", CreateRun).RequireAuthorization();
group.MapGet("/runs/{id:guid}", GetRun).RequireAuthorization();
}
// Dispatch a task to an AI seat: record a queued AgentRun and enqueue the job. The worker
// drains it off the request path. Shares AgentRunDispatcher with the board triggers.
private static async Task<IResult> CreateRun(
CreateRunRequest request, IAgentDispatcher dispatcher, AssemblerDbContext db, CancellationToken ct)
{
var runId = await dispatcher.DispatchAsync(request.SeatId, request.WorkItemId, ct);
var run = await db.AgentRuns.FirstAsync(r => r.Id == runId, ct);
return Results.Ok(ToResponse(run));
}
private static async Task<IResult> GetRun(Guid id, AssemblerDbContext db, CancellationToken ct)
{
var run = await db.AgentRuns.FirstOrDefaultAsync(r => r.Id == id, ct);
return run is null ? Results.NotFound() : Results.Ok(ToResponse(run));
}
private static RunResponse ToResponse(AgentRun run) => new(
run.Id, run.SeatId, run.WorkItemId, run.AgentId, run.Status.ToString(),
run.ActionType, run.ActionRisk, run.Prompt, run.Output, run.Error);
}