From 38b7d13312c04f96b2f5f5837bd110113b775557 Mon Sep 17 00:00:00 2001 From: "cubecraft-agents[bot]" <3458173+cubecraft-agents[bot]@users.noreply.github.com> Date: Sun, 26 Apr 2026 11:34:51 +0000 Subject: [PATCH] CUB-53: add SignalR hub registration and configuration --- backend/.gitignore | 21 +++++++++++ backend/ControlCenter.Api.csproj | 13 +++++++ backend/Hubs/AgentStatusHub.cs | 52 ++++++++++++++++++++++++++ backend/Program.cs | 24 ++++++++++++ backend/Properties/launchSettings.json | 23 ++++++++++++ backend/appsettings.Development.json | 8 ++++ backend/appsettings.json | 9 +++++ 7 files changed, 150 insertions(+) create mode 100644 backend/.gitignore create mode 100644 backend/ControlCenter.Api.csproj create mode 100644 backend/Hubs/AgentStatusHub.cs create mode 100644 backend/Program.cs create mode 100644 backend/Properties/launchSettings.json create mode 100644 backend/appsettings.Development.json create mode 100644 backend/appsettings.json diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..c2c0c5e --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,21 @@ +## .NET +bin/ +obj/ +*.user +*.suo +*.cache +*.dll +*.pdb + +## IDE +.vs/ +.idea/ +*.swp +*~ + +## OS +.DS_Store +Thumbs.db + +## Environment +.env \ No newline at end of file diff --git a/backend/ControlCenter.Api.csproj b/backend/ControlCenter.Api.csproj new file mode 100644 index 0000000..0ce26c7 --- /dev/null +++ b/backend/ControlCenter.Api.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + \ No newline at end of file diff --git a/backend/Hubs/AgentStatusHub.cs b/backend/Hubs/AgentStatusHub.cs new file mode 100644 index 0000000..70ab95d --- /dev/null +++ b/backend/Hubs/AgentStatusHub.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.SignalR; + +namespace ControlCenter.Api.Hubs; + +/// +/// SignalR hub for broadcasting agent status updates to connected clients. +/// +/// +/// Clients connect to this hub at the /hub endpoint to receive +/// real-time agent state changes. A background service subscribes to +/// OpenClaw Gateway events and pushes them through this hub. +/// +/// +/// +/// Architecture note: This hub bridges OpenClaw Gateway events to SignalR clients. +/// The full typed client interface and extension methods will be added in a +/// subsequent task (CUB-55). +/// +/// +public class AgentStatusHub : Hub +{ + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// Logger for diagnostic output. + public AgentStatusHub(ILogger logger) + { + _logger = logger; + } + + /// + /// Overrides to log new connections. + /// + public override Task OnConnectedAsync() + { + _logger.LogDebug("Client connected: {ConnectionId}", Context.ConnectionId); + return base.OnConnectedAsync(); + } + + /// + /// Overrides to log disconnections. + /// SignalR automatically removes disconnected connections from all groups. + /// + /// Exception that caused the disconnection, if any. + public override Task OnDisconnectedAsync(Exception? exception) + { + _logger.LogDebug("Client disconnected: {ConnectionId}", Context.ConnectionId); + return base.OnDisconnectedAsync(exception); + } +} \ No newline at end of file diff --git a/backend/Program.cs b/backend/Program.cs new file mode 100644 index 0000000..0276b30 --- /dev/null +++ b/backend/Program.cs @@ -0,0 +1,24 @@ +using ControlCenter.Api.Hubs; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddOpenApi(); + +// Register SignalR for real-time agent status updates +builder.Services.AddSignalR(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); +} + +app.UseHttpsRedirection(); + +// Map SignalR hub endpoint +app.MapHub("/hub"); + +app.Run(); \ No newline at end of file diff --git a/backend/Properties/launchSettings.json b/backend/Properties/launchSettings.json new file mode 100644 index 0000000..03ce50c --- /dev/null +++ b/backend/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5178", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7041;http://localhost:5178", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/backend/appsettings.Development.json b/backend/appsettings.Development.json new file mode 100644 index 0000000..1b2d3ba --- /dev/null +++ b/backend/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} \ No newline at end of file diff --git a/backend/appsettings.json b/backend/appsettings.json new file mode 100644 index 0000000..ec04bc1 --- /dev/null +++ b/backend/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file