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:
@@ -0,0 +1,29 @@
|
||||
using Luna.Shared;
|
||||
using Microsoft.Extensions.AI;
|
||||
|
||||
namespace Luna.Core.Services;
|
||||
|
||||
public class ChatStreamUpdateBuilder : IChatStreamUpdateBuilder
|
||||
{
|
||||
public ChatStreamUpdate FromAiContent(AIContent content, string messageId)
|
||||
=> content switch
|
||||
{
|
||||
TextReasoningContent reasoning
|
||||
=> new ChatStreamUpdate(ChatStreamUpdateType.Text, reasoning.Text, "assistant", false, messageId),
|
||||
TextContent text
|
||||
=> new ChatStreamUpdate(ChatStreamUpdateType.Text, text.Text, "assistant", false, messageId),
|
||||
ToolCallContent toolCall
|
||||
=> new ChatStreamUpdate(ChatStreamUpdateType.ToolCall, toolCall.ToString(), "assistant", false, messageId),
|
||||
ToolResultContent toolResult
|
||||
=> new ChatStreamUpdate(ChatStreamUpdateType.ToolResult, toolResult.ToString(), "assistant", false, messageId),
|
||||
UsageContent usage
|
||||
=> new ChatStreamUpdate(ChatStreamUpdateType.Usage, usage.ToString(), "system", false, messageId),
|
||||
_ => throw new NotSupportedException($"Unsupported content type: {content.GetType().Name}")
|
||||
};
|
||||
|
||||
public ChatStreamUpdate FromString(string content, string messageId)
|
||||
=> new(ChatStreamUpdateType.Text, content, "assistant", false, messageId);
|
||||
|
||||
public ChatStreamUpdate CreateCompleteUpdate(string messageId)
|
||||
=> new(ChatStreamUpdateType.Complete, null, null, true, messageId);
|
||||
}
|
||||
Reference in New Issue
Block a user