Implemented removal of chat messages (#246)

This commit is contained in:
Thorsten Sommer 2025-01-03 18:01:22 +01:00 committed by GitHub
parent 6f5aecd92b
commit 5e445f09fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 2 deletions

View File

@ -97,4 +97,17 @@ public sealed record ChatThread
logger.LogInformation(logMessage);
return systemPromptText;
}
/// <summary>
/// Removes a content block from this chat thread.
/// </summary>
/// <param name="content">The content block to remove.</param>
public void Remove(IContent content)
{
var block = this.Blocks.FirstOrDefault(x => x.Content == content);
if(block is null)
return;
this.Blocks.Remove(block);
}
}

View File

@ -12,7 +12,15 @@
<MudText Typo="Typo.body1">@this.Role.ToName() (@this.Time)</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="@this.CopyToClipboard" />
@if (this.RemoveBlockFunc is not null)
{
<MudTooltip Text="Removes this block" Placement="Placement.Bottom">
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@this.RemoveBlock"/>
</MudTooltip>
}
<MudTooltip Text="Copies the content to the clipboard" Placement="Placement.Bottom">
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="@this.CopyToClipboard"/>
</MudTooltip>
</CardHeaderActions>
</MudCardHeader>
<MudCardContent>

View File

@ -41,6 +41,9 @@ public partial class ContentBlockComponent : ComponentBase
[Parameter]
public string Class { get; set; } = string.Empty;
[Parameter]
public Func<IContent, Task>? RemoveBlockFunc { get; set; }
[Inject]
private RustService RustService { get; init; } = null!;
@ -50,6 +53,9 @@ public partial class ContentBlockComponent : ComponentBase
[Inject]
private SettingsManager SettingsManager { get; init; } = null!;
[Inject]
private IDialogService DialogService { get; init; } = null!;
private bool HideContent { get; set; }
#region Overrides of ComponentBase
@ -122,4 +128,19 @@ public partial class ContentBlockComponent : ComponentBase
private string CardClasses => $"my-2 rounded-lg {this.Class}";
private CodeBlockTheme CodeColorPalette => this.SettingsManager.IsDarkMode ? CodeBlockTheme.Dark : CodeBlockTheme.Default;
private async Task RemoveBlock()
{
if (this.RemoveBlockFunc is null)
return;
var remove = await this.DialogService.ShowMessageBox(
"Remove Message",
"Do you really want to remove this message?",
"Yes, remove it",
"No, keep it");
if (remove.HasValue && remove.Value)
await this.RemoveBlockFunc(this.Content);
}
}

View File

@ -11,7 +11,7 @@
{
@if (!block.HideFromUser)
{
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content"/>
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content" RemoveBlockFunc="@this.RemoveBlock"/>
}
}
}

View File

@ -571,6 +571,17 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
await MessageBus.INSTANCE.SendMessage<bool>(this, Event.WORKSPACE_TOGGLE_OVERLAY);
}
private async Task RemoveBlock(IContent block)
{
if(this.ChatThread is null)
return;
this.ChatThread.Remove(block);
this.hasUnsavedChanges = true;
await this.SaveThread();
this.StateHasChanged();
}
#region Overrides of MSGComponentBase
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default

View File

@ -0,0 +1,2 @@
# v0.9.24, build 199 (2025-01-xx xx:xx UTC)
- Added a button to remove a message from the chat thread.