Initial commit: Nexus Mission Control Platform
- ASP.NET Core 10 Backend (JWT Auth, Agent config API) - Vue 3 Frontend (Dashboard, Team, Agents, Config Editor) - PostgreSQL Database - Docker Compose setup - Mission Control Dashboard redesign
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Nexus.Api.Domain;
|
||||
|
||||
namespace Nexus.Api.Integrations;
|
||||
|
||||
public sealed record AgentRuntimeStatus(
|
||||
string Runtime,
|
||||
OperationalStatus Status,
|
||||
TimeSpan? Latency,
|
||||
string? Detail);
|
||||
|
||||
public sealed record ModelProviderStatus(
|
||||
string Provider,
|
||||
string Model,
|
||||
OperationalStatus Status,
|
||||
bool IsLocal,
|
||||
string? Detail);
|
||||
|
||||
public sealed record AgentChatResult(
|
||||
string Runtime,
|
||||
string AgentId,
|
||||
string ConversationId,
|
||||
string Content);
|
||||
|
||||
public interface IAgentRuntime
|
||||
{
|
||||
string Name { get; }
|
||||
Task<AgentRuntimeStatus> GetStatusAsync(CancellationToken cancellationToken);
|
||||
Task<AgentChatResult> ChatAsync(
|
||||
string message,
|
||||
string conversationId,
|
||||
string agentId,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public interface IModelProvider
|
||||
{
|
||||
string Name { get; }
|
||||
Task<IReadOnlyCollection<ModelProviderStatus>> GetModelsAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Nexus.Api.Domain;
|
||||
|
||||
namespace Nexus.Api.Integrations;
|
||||
|
||||
public sealed class NvidiaProvider(IConfiguration configuration) : IModelProvider
|
||||
{
|
||||
public string Name => "NVIDIA";
|
||||
|
||||
public Task<IReadOnlyCollection<ModelProviderStatus>> GetModelsAsync(
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var configured = !string.IsNullOrWhiteSpace(
|
||||
configuration["Integrations:Nvidia:ApiKey"]);
|
||||
IReadOnlyCollection<ModelProviderStatus> models =
|
||||
[
|
||||
new(
|
||||
Name,
|
||||
"moonshotai/kimi-k2.6",
|
||||
configured ? OperationalStatus.Online : OperationalStatus.Unknown,
|
||||
false,
|
||||
configured ? "Credential configured" : "Credential required")
|
||||
];
|
||||
return Task.FromResult(models);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Net.Http.Json;
|
||||
using Nexus.Api.Domain;
|
||||
|
||||
namespace Nexus.Api.Integrations;
|
||||
|
||||
public sealed class OllamaProvider(HttpClient client) : IModelProvider
|
||||
{
|
||||
private sealed record OllamaTag(string Name);
|
||||
private sealed record OllamaTags(IReadOnlyCollection<OllamaTag>? Models);
|
||||
|
||||
public string Name => "Ollama";
|
||||
|
||||
public async Task<IReadOnlyCollection<ModelProviderStatus>> GetModelsAsync(
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await client.GetFromJsonAsync<OllamaTags>("/api/tags", cancellationToken);
|
||||
return response?.Models?
|
||||
.Select(model => new ModelProviderStatus(
|
||||
Name,
|
||||
model.Name,
|
||||
OperationalStatus.Online,
|
||||
true,
|
||||
"Local"))
|
||||
.ToArray() ?? [];
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return
|
||||
[
|
||||
new(Name, "qwen3:4b", OperationalStatus.Offline, true, exception.Message)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Nexus.Api.Domain;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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"]
|
||||
?? configuration["Integrations:OpenClaw:Token"];
|
||||
if (!string.IsNullOrWhiteSpace(credential))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", credential);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user