BlazorAgentView.SignalR 1.0.0

dotnet add package BlazorAgentView.SignalR --version 1.0.0
                    
NuGet\Install-Package BlazorAgentView.SignalR -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorAgentView.SignalR" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorAgentView.SignalR" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BlazorAgentView.SignalR" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorAgentView.SignalR --version 1.0.0
                    
#r "nuget: BlazorAgentView.SignalR, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorAgentView.SignalR@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorAgentView.SignalR&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BlazorAgentView.SignalR&version=1.0.0
                    
Install as a Cake Tool

BlazorAgentView.SignalR

SignalR integration package for BlazorAgentView - provides shared hub constants and helpers for streaming AI agent messages over a real-time SignalR connection.

NuGet License: MIT .NET 10


When do I need this?

Use this package when you want to drive an <AgentChatView> component with a real-time SignalR connection - for example, streaming AI responses from a server-side LLM pipeline to a Blazor client without holding a long HTTP request open.

If you are using Blazor Server with Interactive Server render mode and calling your AI backend directly in C# (no Hub needed), you can use the base BlazorAgentView package alone and skip this one.


Installation

Install both packages:

dotnet add package BlazorAgentView
dotnet add package BlazorAgentView.SignalR

How it works

The package exposes AgentChatSignalRHub - a static class with the canonical method name constants used by the hub. Sharing these between your server hub and your Blazor client avoids hardcoded strings on both sides.

public static class AgentChatSignalRHub
{
    public const string ReceiveMessage = "ReceiveMessage";  // full ChatMessage
    public const string AppendContent  = "AppendContent";   // streaming token
    public const string UpdateTool     = "UpdateTool";      // tool state change
}

Setup

1 - Server: define the Hub

using BlazorAgentView.SignalR;
using Microsoft.AspNetCore.SignalR;

public class AgentHub : Hub
{
    public async Task StartAgentRun(string userMessage)
    {
        // Echo the user message back
        await Clients.Caller.SendAsync(AgentChatSignalRHub.ReceiveMessage, new
        {
            role      = "user",
            content   = userMessage,
            timestamp = DateTimeOffset.UtcNow
        });

        // Start a streaming assistant reply
        var msgId = Guid.NewGuid().ToString();
        await Clients.Caller.SendAsync(AgentChatSignalRHub.ReceiveMessage, new
        {
            id          = msgId,
            role        = "assistant",
            content     = "",
            isStreaming = true,
            timestamp   = DateTimeOffset.UtcNow
        });

        // Stream tokens one by one
        await foreach (var token in MyAiService.StreamAsync(userMessage))
        {
            await Clients.Caller.SendAsync(AgentChatSignalRHub.AppendContent, msgId, token);
        }
    }
}

2 - Server: register the Hub

// Program.cs
app.MapHub<AgentHub>("/agent-hub");

3 - Client: connect and wire up the component

@page "/chat"
@rendermode InteractiveServer
@using BlazorAgentView.Components
@using BlazorAgentView.Models
@using BlazorAgentView.SignalR
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager Navigation
@implements IAsyncDisposable

<div style="height: 600px;">
    <AgentChatView @ref="_chatView" Messages="_messages" />
</div>

@code {
    private AgentChatView _chatView = default!;
    private List<ChatMessage> _messages = new();
    private HubConnection? _hub;

    protected override async Task OnInitializedAsync()
    {
        _hub = new HubConnectionBuilder()
            .WithUrl(Navigation.ToAbsoluteUri("/agent-hub"))
            .WithAutomaticReconnect()
            .Build();

        // Full message (user echo or initial assistant message)
        _hub.On<ChatMessageDto>(AgentChatSignalRHub.ReceiveMessage, dto =>
        {
            var msg = new ChatMessage
            {
                Id          = dto.Id ?? Guid.NewGuid().ToString(),
                Role        = Enum.Parse<MessageRole>(dto.Role, ignoreCase: true),
                Content     = dto.Content,
                IsStreaming = dto.IsStreaming,
                Timestamp   = dto.Timestamp
            };
            InvokeAsync(() => _chatView.AddMessage(msg));
        });

        // Streaming token - appended to an existing message by id
        _hub.On<string, string>(AgentChatSignalRHub.AppendContent, (id, token) =>
        {
            InvokeAsync(() => _chatView.AppendToMessage(id, token));
        });

        // Tool state update
        _hub.On<string, string, string>(AgentChatSignalRHub.UpdateTool, (msgId, toolId, state) =>
        {
            var toolState = Enum.Parse<ToolState>(state, ignoreCase: true);
            InvokeAsync(() => _chatView.UpdateToolState(msgId, toolId, toolState));
        });

        await _hub.StartAsync();
    }

    public async ValueTask DisposeAsync()
    {
        if (_hub is not null)
            await _hub.DisposeAsync();
    }
}

Hub method constants

Constant Value Direction Payload
ReceiveMessage "ReceiveMessage" Server → Client Full message DTO
AppendContent "AppendContent" Server → Client (string id, string token)
UpdateTool "UpdateTool" Server → Client (string msgId, string toolId, string state)


License

MIT © Felix Klakow

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 98 4/30/2026