Add Luna.Core server with SignalR hub, session management, and tool system

Implement the core application server as an ASP.NET web host with:
- SignalR ChatHub for real-time client communication
- Session management with token estimation for context windowing
- Extensible tool system with attribute-based tool discovery
- Chat stream update builder for streaming AI responses
- App configuration with appsettings for development and production
This commit is contained in:
2026-04-04 04:10:58 +02:00
parent 29eb3851c9
commit 2f5841a1b9
23 changed files with 586 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
using Luna.Channels.Abstractions;
using Luna.Channels.Cli;
using Luna.Channels.Web;
using Luna.Core.Abstractions;
using Luna.Shared;
using Microsoft.AspNetCore.SignalR;
namespace Luna.Core.Hubs;
public class ChatHub(IChannelManager channelManager, IChatHubContext hubContext) : Hub
{
public override Task OnConnectedAsync()
{
var clientType = Context.GetHttpContext()?.Request.Query["clientType"].ToString();
IChannel channel = clientType switch
{
"web" => new WebChannel(Context.ConnectionId, hubContext),
_ => new CliChannel(Context.ConnectionId, hubContext)
};
channelManager.RegisterChannel(channel);
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception? exception)
{
channelManager.UnregisterChannel(Context.ConnectionId);
return base.OnDisconnectedAsync(exception);
}
public void OnMessageReceived(ChannelMessage message)
{
var channel = channelManager.GetChannel(Context.ConnectionId);
switch (channel)
{
case CliChannel cli:
cli.RaiseMessageReceived(this, message);
break;
case WebChannel web:
web.RaiseMessageReceived(this, message);
break;
default:
throw new InvalidOperationException(
$"ChannelManager returned channel of unexpected type: {channel?.GetType().Name ?? "null"}");
}
}
}