Files
nexus/backend/Integrations/OpenClawRuntime.cs
T
AzuTear 144edf58fe
CI - Build & Test / Backend (.NET) (push) Successful in 40s
CI - Build & Test / Frontend (Vue/TS) (push) Successful in 2m47s
CI - Build & Test / Security Check (push) Successful in 3s
CI - Build & Test / Deploy Nexus (push) Successful in 34s
fix: restore production OpenClaw runtime health
2026-07-31 23:08:26 +02:00

42 lines
1.5 KiB
C#

using System.Diagnostics;
using System.Net.Http.Headers;
using Nexus.Api.Data;
namespace Nexus.Api.Integrations;
public sealed class OpenClawRuntime(HttpClient client, IConfiguration configuration) : IAgentRuntime
{
public string Name => "OpenClaw";
public async Task<AgentRuntimeStatus> GetStatusAsync(CancellationToken cancellationToken)
{
var stopwatch = Stopwatch.StartNew();
try
{
using var request = new HttpRequestMessage(HttpMethod.Get, "/");
ApplyAuthorization(request);
using var response = await client.SendAsync(request, cancellationToken);
stopwatch.Stop();
var status = response.IsSuccessStatusCode
? OperationalStatus.Online
: OperationalStatus.Degraded;
return new(Name, status, stopwatch.Elapsed, $"HTTP {(int)response.StatusCode}");
}
catch (Exception exception)
{
stopwatch.Stop();
return new(Name, OperationalStatus.Offline, stopwatch.Elapsed, exception.Message);
}
}
private void ApplyAuthorization(HttpRequestMessage request)
{
var credential = configuration["Integrations:OpenClaw:Password"];
if (string.IsNullOrWhiteSpace(credential))
credential = configuration["Integrations:OpenClaw:Token"];
if (!string.IsNullOrWhiteSpace(credential))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", credential);
}
}