feat: ship agent-first mission control v0.2.57
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Claims;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Integrations;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[Authorize(Roles = "owner")]
|
||||
[ApiController]
|
||||
[Route("api/v1/chat")]
|
||||
public class ChatController(IAgentRuntime runtime, ILogger<ChatController> logger) : ControllerBase
|
||||
public class ChatController(
|
||||
IOpenClawChatService chat,
|
||||
ILogger<ChatController> logger) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
[EnableRateLimiting("agents")]
|
||||
@@ -31,7 +35,35 @@ public class ChatController(IAgentRuntime runtime, ILogger<ChatController> logge
|
||||
|
||||
try
|
||||
{
|
||||
return Results.Ok(await runtime.ChatAsync(message, conversationId, agentId, ct));
|
||||
var contextualMessage = MissionControlContextFormatter.Format(message, request.Context);
|
||||
var invocationContext = OpenClawInvocationContextFactory.Create(
|
||||
User.FindFirst("sub")?.Value
|
||||
?? User.FindFirst(ClaimTypes.NameIdentifier)?.Value
|
||||
?? User.Identity?.Name,
|
||||
Request.Headers["Idempotency-Key"].FirstOrDefault(),
|
||||
Request.Headers["X-Correlation-ID"].FirstOrDefault()
|
||||
?? HttpContext.TraceIdentifier,
|
||||
Request.Headers["traceparent"].FirstOrDefault()
|
||||
?? Activity.Current?.Id);
|
||||
var invocation = new Nexus.Api.Models.OpenClawInvocationMetadata(
|
||||
invocationContext.IdempotencyKey,
|
||||
invocationContext.CorrelationId,
|
||||
invocationContext.Actor,
|
||||
invocationContext.TraceParent);
|
||||
Response.Headers["X-Correlation-ID"] = invocation.CorrelationId;
|
||||
return Results.Ok(await chat.SendAsync(
|
||||
contextualMessage,
|
||||
conversationId,
|
||||
agentId,
|
||||
invocation,
|
||||
ct));
|
||||
}
|
||||
catch (ArgumentException exception)
|
||||
{
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["requestMetadata"] = [exception.Message]
|
||||
});
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -42,4 +74,5 @@ public class ChatController(IAgentRuntime runtime, ILogger<ChatController> logge
|
||||
statusCode: StatusCodes.Status503ServiceUnavailable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user