| | | 1 | | using System.Text.Json.Serialization; |
| | | 2 | | using UIBlazor.Constants; |
| | | 3 | | |
| | | 4 | | namespace UIBlazor.Models; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents a chat message. |
| | | 8 | | /// Saved in session history |
| | | 9 | | /// </summary> |
| | | 10 | | public class VisualChatMessage |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets or sets the unique identifier for the message. |
| | | 14 | | /// </summary> |
| | | 15 | | [JsonIgnore] |
| | 6 | 16 | | public string Id { get; set; } = DateTime.Now.ToString("s") + Guid.NewGuid().ToString(); |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets or sets the content of the message. Without thinking block. |
| | | 20 | | /// </summary> |
| | 10 | 21 | | public string Content { get; set; } = string.Empty; |
| | | 22 | | |
| | | 23 | | [JsonIgnore] |
| | 35 | 24 | | public List<ContentSegment> Segments { get; set; } = []; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets or sets the content of the message for display in the UI. |
| | | 28 | | /// If null, Content is used. |
| | | 29 | | /// </summary> |
| | | 30 | | [JsonIgnore] |
| | 0 | 31 | | public string? DisplayContent { get; set; } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets or sets the content of the Reasoning message. Aka Think block. |
| | | 35 | | /// </summary> |
| | | 36 | | [JsonIgnore] |
| | 6 | 37 | | public string ReasoningContent { get; set; } = string.Empty; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets or sets the timestamp when the message was created. |
| | | 41 | | /// </summary> |
| | 7 | 42 | | public DateTime Timestamp { get; set; } = DateTime.Now; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets or sets whether this message is currently streaming. |
| | | 46 | | /// </summary> |
| | | 47 | | [JsonIgnore] |
| | 0 | 48 | | public bool IsStreaming { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets or sets whether this message is currently being edited. |
| | | 52 | | /// </summary> |
| | | 53 | | [JsonIgnore] |
| | 0 | 54 | | public bool IsEditing { get; set; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Temporary storage for content during editing. |
| | | 58 | | /// </summary> |
| | | 59 | | [JsonIgnore] |
| | 6 | 60 | | public string TempContent { get; set; } = string.Empty; |
| | | 61 | | |
| | | 62 | | [JsonIgnore] |
| | 6 | 63 | | public string ToolDisplayName { get; set; } = string.Empty; |
| | | 64 | | |
| | 0 | 65 | | public string? Model { get; set; } |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Gets or sets the role associated with the message (e.g., "user", "assistant"). |
| | | 69 | | /// </summary> |
| | 13 | 70 | | public string Role { get; set; } = ChatMessageRole.User; |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Nested tool messages for assistant messages. |
| | | 74 | | /// </summary> |
| | | 75 | | [JsonIgnore] |
| | 6 | 76 | | public List<VisualChatMessage> ToolMessages { get; set; } = []; |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Whether the message block is expanded or collapsed. |
| | | 80 | | /// </summary> |
| | | 81 | | [JsonIgnore] |
| | 0 | 82 | | public bool IsExpanded { get; set; } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Extracted plan content if any. |
| | | 86 | | /// </summary> |
| | | 87 | | [JsonIgnore] |
| | 0 | 88 | | public string? PlanContent { get; set; } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Whether this message contains a plan. |
| | | 92 | | /// </summary> |
| | | 93 | | [JsonIgnore] |
| | 0 | 94 | | public bool HasPlan => !string.IsNullOrEmpty(PlanContent); |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Approval states for each tool call in this message. |
| | | 98 | | /// Key is index from 0. |
| | | 99 | | /// </summary> |
| | | 100 | | [JsonIgnore] |
| | 6 | 101 | | public Dictionary<int, ToolApprovalStatus> ToolApprovalStates { get; set; } = []; |
| | | 102 | | |
| | | 103 | | [JsonIgnore] |
| | 0 | 104 | | public int RetryCountdown { get; set; } |
| | | 105 | | |
| | | 106 | | [JsonIgnore] |
| | 0 | 107 | | public int RetryAttempt { get; set; } |
| | | 108 | | |
| | | 109 | | [JsonIgnore] |
| | 0 | 110 | | public int MaxRetryAttempts { get; set; } |
| | | 111 | | |
| | | 112 | | [JsonIgnore] |
| | 0 | 113 | | public bool IsRetrying => RetryCountdown > 0; |
| | | 114 | | } |