feat: ship agent-first mission control v0.2.57
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Nexus.Api.Data;
|
||||
|
||||
namespace Nexus.Api.Integrations;
|
||||
@@ -32,39 +30,6 @@ public sealed class OpenClawRuntime(HttpClient client, IConfiguration configurat
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<AgentChatResult> ChatAsync(
|
||||
string message,
|
||||
string conversationId,
|
||||
string agentId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, "/v1/chat/completions");
|
||||
ApplyAuthorization(request);
|
||||
request.Content = JsonContent.Create(new
|
||||
{
|
||||
model = $"openclaw/{agentId}",
|
||||
messages = new[] { new { role = "user", content = message } },
|
||||
user = conversationId,
|
||||
stream = false
|
||||
});
|
||||
|
||||
using var response = await client.SendAsync(request, cancellationToken);
|
||||
var body = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new HttpRequestException($"OpenClaw chat returned HTTP {(int)response.StatusCode}: {body}");
|
||||
|
||||
using var document = JsonDocument.Parse(body);
|
||||
var content = document.RootElement
|
||||
.GetProperty("choices")[0]
|
||||
.GetProperty("message")
|
||||
.GetProperty("content")
|
||||
.GetString();
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
throw new InvalidOperationException("OpenClaw returned an empty assistant response.");
|
||||
|
||||
return new(Name, agentId, conversationId, content);
|
||||
}
|
||||
|
||||
private void ApplyAuthorization(HttpRequestMessage request)
|
||||
{
|
||||
var credential = configuration["Integrations:OpenClaw:Password"]
|
||||
|
||||
Reference in New Issue
Block a user