diff --git a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor
index 1754ca6..ca61acc 100644
--- a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor
+++ b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor
@@ -12,10 +12,22 @@
@this.Role.ToName() (@this.Time)
+ @if (this.IsSecondToLastBlock && this.Role is ChatRole.USER && this.EditLastUserBlockFunc is not null)
+ {
+
+
+
+ }
+ @if (this.IsLastContentBlock && this.Role is ChatRole.USER && this.EditLastBlockFunc is not null)
+ {
+
+
+
+ }
@if (this.IsLastContentBlock && this.Role is ChatRole.AI && this.RegenerateFunc is not null)
{
-
+
}
@if (this.RemoveBlockFunc is not null)
diff --git a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs
index a069e67..5797590 100644
--- a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs
+++ b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs
@@ -43,6 +43,9 @@ public partial class ContentBlockComponent : ComponentBase
[Parameter]
public bool IsLastContentBlock { get; set; } = false;
+
+ [Parameter]
+ public bool IsSecondToLastBlock { get; set; } = false;
[Parameter]
public Func? RemoveBlockFunc { get; set; }
@@ -50,6 +53,12 @@ public partial class ContentBlockComponent : ComponentBase
[Parameter]
public Func? RegenerateFunc { get; set; }
+ [Parameter]
+ public Func? EditLastBlockFunc { get; set; }
+
+ [Parameter]
+ public Func? EditLastUserBlockFunc { get; set; }
+
[Parameter]
public Func RegenerateEnabled { get; set; } = () => false;
@@ -170,4 +179,33 @@ public partial class ContentBlockComponent : ComponentBase
if (regenerate.HasValue && regenerate.Value)
await this.RegenerateFunc(this.Content);
}
+
+ private async Task EditLastBlock()
+ {
+ if (this.EditLastBlockFunc is null)
+ return;
+
+ if(this.Role is not ChatRole.USER)
+ return;
+
+ await this.EditLastBlockFunc(this.Content);
+ }
+
+ private async Task EditLastUserBlock()
+ {
+ if (this.EditLastUserBlockFunc is null)
+ return;
+
+ if(this.Role is not ChatRole.USER)
+ return;
+
+ var edit = await this.DialogService.ShowMessageBox(
+ "Edit Message",
+ "Do you really want to edit this message? In order to edit this message, the AI response will be deleted.",
+ "Yes, remove the AI response and edit it",
+ "No, keep it");
+
+ if (edit.HasValue && edit.Value)
+ await this.EditLastUserBlockFunc(this.Content);
+ }
}
\ No newline at end of file
diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor b/app/MindWork AI Studio/Components/ChatComponent.razor
index 4e7753d..ccfe1e1 100644
--- a/app/MindWork AI Studio/Components/ChatComponent.razor
+++ b/app/MindWork AI Studio/Components/ChatComponent.razor
@@ -12,9 +12,21 @@
{
var block = blocks[i];
var isLastBlock = i == blocks.Count - 1;
+ var isSecondLastBlock = i == blocks.Count - 2;
@if (!block.HideFromUser)
{
-
+
}
}
}
diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs
index 8cfae55..5017d01 100644
--- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs
+++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs
@@ -595,6 +595,44 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
await this.SendMessage(reuseLastUserPrompt: true);
}
+ private Task EditLastUserBlock(IContent block)
+ {
+ if(this.ChatThread is null)
+ return Task.CompletedTask;
+
+ if (block is not ContentText textBlock)
+ return Task.CompletedTask;
+
+ var lastBlock = this.ChatThread.Blocks.Last();
+ var lastBlockContent = lastBlock.Content;
+ if(lastBlockContent is null)
+ return Task.CompletedTask;
+
+ this.userInput = textBlock.Text;
+ this.ChatThread.Remove(block);
+ this.ChatThread.Remove(lastBlockContent);
+ this.hasUnsavedChanges = true;
+ this.StateHasChanged();
+
+ return Task.CompletedTask;
+ }
+
+ private Task EditLastBlock(IContent block)
+ {
+ if(this.ChatThread is null)
+ return Task.CompletedTask;
+
+ if (block is not ContentText textBlock)
+ return Task.CompletedTask;
+
+ this.userInput = textBlock.Text;
+ this.ChatThread.Remove(block);
+ this.hasUnsavedChanges = true;
+ this.StateHasChanged();
+
+ return Task.CompletedTask;
+ }
+
#region Overrides of MSGComponentBase
public override async Task ProcessIncomingMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md
index ce1786e..0c6775c 100644
--- a/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md
+++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md
@@ -1,3 +1,4 @@
# v0.9.24, build 199 (2025-01-xx xx:xx UTC)
- Added a button to remove a message from the chat thread.
-- Added a button to regenerate the last AI response.
\ No newline at end of file
+- Added a button to regenerate the last AI response.
+- Added a button to edit the last user message.
\ No newline at end of file