Define channel abstractions (IChannel, IChannelManager) with event-driven message and connection handling. Implement ChannelManager for multi-channel orchestration, CliChannel for terminal I/O, TelegramChannel with adapter pattern for bot API integration, and WebChannel stub. Includes DI registration and channel type enumeration.
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using Luna.Shared;
|
|
|
|
namespace Luna.Channels.Abstractions;
|
|
|
|
public delegate Task ChannelMessageReceivedEventHandler(object? sender, ChannelMessageReceivedEventArgs args);
|
|
public delegate Task ChannelConnectionChangedEventHandler(object? sender, ChannelConnectionEventArgs args);
|
|
|
|
/// <summary>
|
|
/// Represents a communication channel for the Luna AI Assistant.
|
|
/// Channels handle sending and receiving messages via different platforms
|
|
/// (e.g., CLI, Telegram, Discord, Email).
|
|
/// </summary>
|
|
public interface IChannel : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Unique identifier for this channel instance
|
|
/// </summary>
|
|
string ChannelId { get; }
|
|
|
|
/// <summary>
|
|
/// Type of channel (e.g., "cli", "telegram", "discord")
|
|
/// </summary>
|
|
string ChannelType { get; }
|
|
|
|
/// <summary>
|
|
/// Display name for the channel
|
|
/// </summary>
|
|
string DisplayName { get; }
|
|
|
|
/// <summary>
|
|
/// Indicates whether the channel is currently connected and ready
|
|
/// </summary>
|
|
bool IsConnected { get; }
|
|
|
|
/// <summary>
|
|
/// Event raised when a message is received from the channel
|
|
/// </summary>
|
|
event ChannelMessageReceivedEventHandler? MessageReceived;
|
|
|
|
/// <summary>
|
|
/// Event raised when the channel connection state changes
|
|
/// </summary>
|
|
event ChannelConnectionChangedEventHandler? ConnectionStateChanged;
|
|
|
|
/// <summary>
|
|
/// Send a message to the channel
|
|
/// </summary>
|
|
/// <param name="message">The message to send</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Task representing the send operation</returns>
|
|
Task SendMessageAsync(ChannelMessage message, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Send a streaming response to the channel
|
|
/// </summary>
|
|
/// <param name="messageStream">Async enumerable of response updates</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Task representing the send operation</returns>
|
|
Task SendStreamingMessageAsync(IAsyncEnumerable<ChatStreamUpdate> messageStream, CancellationToken cancellationToken = default);
|
|
} |