| | | 1 | | namespace UIBlazor.Models; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a chat message. |
| | | 5 | | /// Saved in session history |
| | | 6 | | /// </summary> |
| | | 7 | | public class VisualChatMessage |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Gets or sets the unique identifier for the message. |
| | | 11 | | /// </summary> |
| | | 12 | | [JsonIgnore] |
| | 135 | 13 | | public string Id { get; } = DateTime.Now.ToString("s") + Guid.NewGuid(); |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Gets or sets the content of the message. Without thinking block. |
| | | 17 | | /// </summary> |
| | 239 | 18 | | public string Content { get; set; } = string.Empty; |
| | | 19 | | |
| | | 20 | | [JsonIgnore] |
| | 169 | 21 | | public List<ContentSegment> Segments { get; } = []; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets or sets the content of the message for display in the UI. |
| | | 25 | | /// If null, Content is used. |
| | | 26 | | /// </summary> |
| | | 27 | | [JsonIgnore] |
| | 1 | 28 | | public string? DisplayContent { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the content of the Reasoning message. Aka Think block. |
| | | 32 | | /// </summary> |
| | | 33 | | [JsonIgnore] |
| | 66 | 34 | | public string ReasoningContent { get; set; } = string.Empty; |
| | | 35 | | |
| | | 36 | | [JsonIgnore] |
| | 9 | 37 | | public MessageTimings? Timings { get; set; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets or sets the timestamp when the message was created. |
| | | 41 | | /// </summary> |
| | 163 | 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] |
| | 202 | 48 | | public bool IsStreaming { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets or sets whether this message is currently being edited. |
| | | 52 | | /// </summary> |
| | | 53 | | [JsonIgnore] |
| | 361 | 54 | | public bool IsEditing { get; set; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Temporary storage for content during editing. |
| | | 58 | | /// </summary> |
| | | 59 | | [JsonIgnore] |
| | 84 | 60 | | public string TempContent { get; set; } = string.Empty; |
| | | 61 | | |
| | | 62 | | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| | 53 | 63 | | public string? Model { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets or sets the role associated with the message (e.g., "user", "assistant"). |
| | | 67 | | /// </summary> |
| | 358 | 68 | | public string Role { get; set; } = ChatMessageRole.User; |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Nested tool messages for assistant messages. |
| | | 72 | | /// </summary> |
| | 66 | 73 | | public List<ToolResult> ToolResults { get; set; } = []; |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Whether the message block is expanded or collapsed. |
| | | 77 | | /// </summary> |
| | | 78 | | [JsonIgnore] |
| | 157 | 79 | | public bool IsExpanded { get; set; } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Extracted plan content if any. |
| | | 83 | | /// </summary> |
| | | 84 | | [JsonIgnore] |
| | 59 | 85 | | public string? PlanContent { get; set; } |
| | | 86 | | |
| | | 87 | | /// <summary> |
| | | 88 | | /// Whether this message contains a plan. |
| | | 89 | | /// </summary> |
| | | 90 | | [JsonIgnore] |
| | 50 | 91 | | public bool HasPlan => !string.IsNullOrEmpty(PlanContent); |
| | | 92 | | |
| | | 93 | | [JsonIgnore] |
| | 115 | 94 | | public int RetryCountdown { get; set; } |
| | | 95 | | |
| | | 96 | | [JsonIgnore] |
| | 2 | 97 | | public int RetryAttempt { get; set; } |
| | | 98 | | |
| | | 99 | | [JsonIgnore] |
| | 2 | 100 | | public int MaxRetryAttempts { get; set; } |
| | | 101 | | |
| | | 102 | | [JsonIgnore] |
| | 56 | 103 | | public bool IsRetrying => RetryCountdown > 0; |
| | | 104 | | } |