using Microsoft.EntityFrameworkCore;
using TeamUp.Modules.OrgBoard.Persistence;
using TeamUp.SharedKernel.Ai;
namespace TeamUp.Modules.OrgBoard.Runtime;
/// Gathers the agent config + task into an for the assembler.
internal sealed class AgentRunContextProvider(OrgBoardDbContext db) : IAgentRunContextProvider
{
public async Task GetAsync(Guid seatId, Guid workItemId, CancellationToken cancellationToken = default)
{
var agent = await db.Agents.FirstOrDefaultAsync(a => a.SeatId == seatId, cancellationToken);
if (agent is null)
{
return null;
}
var item = await db.WorkItems.FirstOrDefaultAsync(w => w.Id == workItemId, cancellationToken);
if (item is null)
{
return null;
}
var team = await db.Teams.FirstOrDefaultAsync(t => t.Id == item.TeamId, cancellationToken);
if (team is null)
{
return null;
}
return new AgentRunContext(
seatId, agent.Id, agent.Name, agent.Monogram, agent.Autonomy,
agent.ApiConfigId, agent.FallbackApiConfigId, agent.SkillKeys, agent.McpServerIds, agent.Docs,
item.Id, item.Title, item.Description, item.Type.ToString(),
team.Id, team.OrganizationId);
}
}