37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using TeamUp.Modules.OrgBoard.Persistence;
|
||
|
|
using TeamUp.SharedKernel.Ai;
|
||
|
|
|
||
|
|
namespace TeamUp.Modules.OrgBoard.Runtime;
|
||
|
|
|
||
|
|
/// <summary>Gathers the agent config + task into an <see cref="AgentRunContext"/> for the assembler.</summary>
|
||
|
|
internal sealed class AgentRunContextProvider(OrgBoardDbContext db) : IAgentRunContextProvider
|
||
|
|
{
|
||
|
|
public async Task<AgentRunContext?> 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.Docs,
|
||
|
|
item.Id, item.Title, item.Description, item.Type.ToString(),
|
||
|
|
team.Id, team.OrganizationId);
|
||
|
|
}
|
||
|
|
}
|