203 lines
7.3 KiB
C#
Executable File
203 lines
7.3 KiB
C#
Executable File
namespace MarketAlly.AIPlugin.ClaudeCode;
|
|
|
|
/// <summary>
|
|
/// Service for managing chat sessions and real-time communication
|
|
/// </summary>
|
|
public interface IChatService
|
|
{
|
|
/// <summary>
|
|
/// Starts a new chat session
|
|
/// </summary>
|
|
/// <param name="request">Session start request</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Session information</returns>
|
|
Task<ClaudeCodeResponse<ChatSession>> StartSessionAsync(StartSessionRequest request, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Sends a message in an existing session
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="message">Message to send</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Claude's response</returns>
|
|
Task<ClaudeCodeResponse<ChatMessage>> SendMessageAsync(string sessionId, string message, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets session history
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="maxMessages">Maximum messages to return</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Session history</returns>
|
|
Task<ClaudeCodeResponse<List<ChatMessage>>> GetSessionHistoryAsync(string sessionId, int maxMessages = 50, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets all active sessions for the current user
|
|
/// </summary>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>List of active sessions</returns>
|
|
Task<ClaudeCodeResponse<List<ChatSession>>> GetActiveSessionsAsync(CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Ends a chat session
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Success response</returns>
|
|
Task<ClaudeCodeResponse<bool>> EndSessionAsync(string sessionId, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Updates session context or settings
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="updates">Context updates</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Updated session</returns>
|
|
Task<ClaudeCodeResponse<ChatSession>> UpdateSessionContextAsync(string sessionId, SessionContextUpdate updates, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Sets typing indicator for real-time chat
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="isTyping">Whether user is typing</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Success response</returns>
|
|
Task<ClaudeCodeResponse<bool>> SetTypingIndicatorAsync(string sessionId, bool isTyping, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets session statistics and analytics
|
|
/// </summary>
|
|
/// <param name="sessionId">Session identifier</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Session analytics</returns>
|
|
Task<ClaudeCodeResponse<SessionAnalytics>> GetSessionAnalyticsAsync(string sessionId, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start session request model
|
|
/// </summary>
|
|
public class StartSessionRequest
|
|
{
|
|
public string? SessionName { get; set; }
|
|
public string? ProjectPath { get; set; }
|
|
public Dictionary<string, object>? InitialContext { get; set; }
|
|
public ChatSessionSettings? Settings { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chat session model
|
|
/// </summary>
|
|
public class ChatSession
|
|
{
|
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
|
public string? Name { get; set; }
|
|
public string? ProjectPath { get; set; }
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public DateTime LastActivity { get; set; } = DateTime.UtcNow;
|
|
public bool IsActive { get; set; } = true;
|
|
public int MessageCount { get; set; }
|
|
public Dictionary<string, object> Context { get; set; } = new();
|
|
public ChatSessionSettings Settings { get; set; } = new();
|
|
public List<string> Participants { get; set; } = new();
|
|
public SessionStatus Status { get; set; } = SessionStatus.Active;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chat message model
|
|
/// </summary>
|
|
public class ChatMessage
|
|
{
|
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
|
public string SessionId { get; set; } = string.Empty;
|
|
public string Role { get; set; } = string.Empty; // user, assistant, system
|
|
public string Content { get; set; } = string.Empty;
|
|
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
|
|
public MessageType Type { get; set; } = MessageType.Text;
|
|
public Dictionary<string, object> Metadata { get; set; } = new();
|
|
public List<MessageAttachment>? Attachments { get; set; }
|
|
public bool IsThinking { get; set; }
|
|
public double? ConfidenceScore { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chat session settings
|
|
/// </summary>
|
|
public class ChatSessionSettings
|
|
{
|
|
public double Temperature { get; set; } = 0.7;
|
|
public int MaxTokens { get; set; } = 4096;
|
|
public bool IncludeProjectContext { get; set; } = true;
|
|
public bool IncludeConversationHistory { get; set; } = true;
|
|
public int MaxHistoryMessages { get; set; } = 20;
|
|
public string PersonalityMode { get; set; } = "helpful"; // helpful, creative, analytical, concise
|
|
public List<string> EnabledFeatures { get; set; } = new();
|
|
public Dictionary<string, object> CustomSettings { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Session context update model
|
|
/// </summary>
|
|
public class SessionContextUpdate
|
|
{
|
|
public string? ProjectPath { get; set; }
|
|
public Dictionary<string, object>? Context { get; set; }
|
|
public ChatSessionSettings? Settings { get; set; }
|
|
public string? Name { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Session analytics model
|
|
/// </summary>
|
|
public class SessionAnalytics
|
|
{
|
|
public string SessionId { get; set; } = string.Empty;
|
|
public int TotalMessages { get; set; }
|
|
public int UserMessages { get; set; }
|
|
public int AssistantMessages { get; set; }
|
|
public TimeSpan Duration { get; set; }
|
|
public DateTime FirstMessage { get; set; }
|
|
public DateTime LastMessage { get; set; }
|
|
public Dictionary<string, int> TopicBreakdown { get; set; } = new();
|
|
public double AverageResponseTime { get; set; }
|
|
public List<string> KeyInsights { get; set; } = new();
|
|
public int TokensUsed { get; set; }
|
|
public double EngagementScore { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Message attachment model
|
|
/// </summary>
|
|
public class MessageAttachment
|
|
{
|
|
public string Type { get; set; } = string.Empty; // file, image, code, link
|
|
public string Name { get; set; } = string.Empty;
|
|
public string Content { get; set; } = string.Empty;
|
|
public long Size { get; set; }
|
|
public string? MimeType { get; set; }
|
|
public Dictionary<string, object> Metadata { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Message type enumeration
|
|
/// </summary>
|
|
public enum MessageType
|
|
{
|
|
Text,
|
|
Code,
|
|
File,
|
|
Image,
|
|
System,
|
|
Error,
|
|
Command
|
|
}
|
|
|
|
/// <summary>
|
|
/// Session status enumeration
|
|
/// </summary>
|
|
public enum SessionStatus
|
|
{
|
|
Active,
|
|
Paused,
|
|
Ended,
|
|
Error
|
|
} |