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
30 lines
1015 B
C#
30 lines
1015 B
C#
using Luna.Core.Abstractions;
|
|
using Luna.Shared;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace Luna.Core.Hubs;
|
|
|
|
public class ChatHubContext(IHubContext<ChatHub> hubContext) : IChatHubContext
|
|
{
|
|
public async Task SendResponseAsync(string connectionId, ChannelMessage message, CancellationToken cancellationToken = default)
|
|
{
|
|
await GetClient(connectionId)
|
|
.SendAsync("OnMessageReceived", message, cancellationToken);
|
|
}
|
|
|
|
public async Task SendStreamingResponseAsync(
|
|
string connectionId,
|
|
IAsyncEnumerable<ChatStreamUpdate> messageStream,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var client = GetClient(connectionId);
|
|
|
|
await foreach (var update in messageStream.WithCancellation(cancellationToken))
|
|
{
|
|
await client.SendAsync("OnMessageStreamReceived", update, cancellationToken);
|
|
}
|
|
}
|
|
|
|
private ISingleClientProxy GetClient(string connectionId)
|
|
=> hubContext.Clients.Client(connectionId);
|
|
} |