| | | 1 | | @using System.Text.RegularExpressions |
| | | 2 | | @using UIBlazor.Components.Chat |
| | | 3 | | @using UIBlazor.Constants |
| | | 4 | | @using UIBlazor.Models |
| | | 5 | | |
| | | 6 | | <div class="ai-chat-message"> |
| | 0 | 7 | | @if (Message.Role != ChatMessageRole.Assistant) |
| | | 8 | | { |
| | | 9 | | <MarkdownBlock Content="@Message.Content" /> |
| | | 10 | | } |
| | | 11 | | else |
| | | 12 | | { |
| | 0 | 13 | | @if (!string.IsNullOrEmpty(Message.ReasoningContent)) |
| | | 14 | | { |
| | | 15 | | <details class="reasoning-details"> |
| | 0 | 16 | | <summary>@SharedResource.Thinking</summary> |
| | | 17 | | <MarkdownBlock Content="@Message.ReasoningContent" /> |
| | | 18 | | </details> |
| | | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | @foreach (var segment in Message.Segments) |
| | | 22 | | { |
| | 0 | 23 | | if (segment.Type == SegmentType.Tool) |
| | | 24 | | { |
| | | 25 | | <ToolCallBlock @key="segment.Id" |
| | | 26 | | Segment="@segment" |
| | | 27 | | OnApproval="@OnToolApprovalHandler" /> |
| | | 28 | | } |
| | 0 | 29 | | else if (segment.Type is SegmentType.Markdown) |
| | | 30 | | { |
| | | 31 | | <MarkdownBlock @key="segment.Id" Content="@segment.CurrentLine.ToString()" /> |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | @if (Message.ToolMessages.Any()) |
| | | 36 | | { |
| | | 37 | | <div class="message-tool-results rz-mt-2"> |
| | 0 | 38 | | @foreach (var toolMsg in Message.ToolMessages) |
| | | 39 | | { |
| | | 40 | | <details class="tool-details" @key="toolMsg.Id"> |
| | 0 | 41 | | <summary>@toolMsg.ToolDisplayName</summary> |
| | 0 | 42 | | <pre class="rz-p-2 rz-background-color-base-900 rz-color-white" style="font-size: 0.8rem; border |
| | | 43 | | </details> |
| | | 44 | | } |
| | | 45 | | </div> |
| | | 46 | | } |
| | | 47 | | } |
| | | 48 | | </div> |
| | | 49 | | |
| | | 50 | | @code { |
| | 0 | 51 | | [Parameter] public VisualChatMessage Message { get; set; } = new(); |
| | 0 | 52 | | [Parameter] public EventCallback<(string MessageId, string SegmentId, bool Approved)> OnToolApproval { get; set; } |
| | 0 | 53 | | [Inject] private IToolManager ToolManager { get; set; } = null!; |
| | | 54 | | |
| | 0 | 55 | | private string _lastContent = string.Empty; |
| | | 56 | | private bool isAssistant = false; |
| | | 57 | | |
| | | 58 | | protected override void OnParametersSet() |
| | | 59 | | { |
| | 0 | 60 | | if (Message.Content != _lastContent) |
| | | 61 | | { |
| | 0 | 62 | | isAssistant = Message.Role == ChatMessageRole.Assistant; |
| | 0 | 63 | | _lastContent = Message.Content; |
| | | 64 | | } |
| | 0 | 65 | | } |
| | | 66 | | |
| | | 67 | | private async Task OnToolApprovalHandler((string SegmentId, bool Approved) args) |
| | | 68 | | { |
| | 0 | 69 | | await OnToolApproval.InvokeAsync((Message.Id, args.SegmentId, args.Approved)); |
| | 0 | 70 | | } |
| | | 71 | | } |