mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 01:53:36 +00:00
Added copying a chat from the chat toolbar
This commit is contained in:
parent
8ac23231ec
commit
d3ee7dbbec
@ -103,6 +103,10 @@
|
||||
<MudTooltip Text="@T("Move the chat to a workspace, or to another if it is already in one.")" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.MoveToInbox" Disabled="@(!this.CanThreadBeSaved || this.IsCurrentChatStreaming)" OnClick="@this.MoveChatToWorkspace"/>
|
||||
</MudTooltip>
|
||||
|
||||
<MudTooltip Text="@T("Copy this chat & continue in the copy.")" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Disabled="@(!this.CanThreadBeCopied)" OnClick="@this.CopyCurrentChat"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
|
||||
<AttachDocuments Name="File Attachments" DocumentPaths="@this.ComposerState.FileAttachments" DocumentPathsChanged="@this.ComposerAttachmentsChanged" CatchAllDocuments="true" UseSmallForm="true" ShowMediaStatus="false" Provider="@this.Provider" OwnerChat="@this.ChatThread" EnsureOwnerChatAsync="@this.EnsureMediaImportChatAsync" Disabled="@this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner)"/>
|
||||
|
||||
@ -650,6 +650,8 @@ public partial class ChatComponent : MSGComponentBase
|
||||
|
||||
private bool CanThreadBeSaved => this.ChatThread is not null && this.ChatThread.Blocks.Any(b => !b.HideFromUser);
|
||||
|
||||
private bool CanThreadBeCopied => this.CanThreadBeSaved && !this.IsCurrentChatStreaming && !this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner);
|
||||
|
||||
private string TooltipAddChatToWorkspace => string.Format(T("Start new chat in workspace '{0}'"), this.currentWorkspaceName);
|
||||
|
||||
private string UserInputStyle => this.SettingsManager.ConfigurationData.Confidence.ShowProviderConfidence ? this.Provider.UsedLLMProvider.GetConfidence(this.SettingsManager).SetColorStyle(this.SettingsManager) : string.Empty;
|
||||
@ -1345,6 +1347,47 @@ public partial class ChatComponent : MSGComponentBase
|
||||
await this.SyncWorkspaceHeaderWithChatThreadAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the open chat and continues in the copy.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Copied is the chat as it stands on the screen, not the state which was stored last. That is
|
||||
/// why nothing is asked about unsaved changes here, unlike everywhere else a chat is left
|
||||
/// behind: none of them are lost, they move into the copy, while the original keeps what was
|
||||
/// stored.<br/><br/>
|
||||
///
|
||||
/// The same holds for the message being written. The copy is marked as loaded right away,
|
||||
/// because the parameter update which follows would otherwise take it for another chat being
|
||||
/// opened and clear the composer. Only the transcripts attached to that message are exchanged:
|
||||
/// those of the original live in its directory, and the copy got copies of its own.
|
||||
/// </remarks>
|
||||
private async Task CopyCurrentChat()
|
||||
{
|
||||
if (this.ChatThread is null || !this.CanThreadBeCopied)
|
||||
return;
|
||||
|
||||
var sourceChat = this.ChatThread;
|
||||
var copy = this.Workspaces is null
|
||||
? await WorkspaceBehaviour.CopyChatAsync(this.DialogService, sourceChat)
|
||||
: await this.Workspaces.CopyChatAsync(sourceChat);
|
||||
|
||||
if (copy is null)
|
||||
return;
|
||||
|
||||
var transcriptsOfTheOriginal = sourceChat.PendingMediaTranscripts.Select(transcript => transcript.FilePath).ToHashSet(StringComparer.Ordinal);
|
||||
this.ComposerState.FileAttachments.RemoveWhere(attachment => transcriptsOfTheOriginal.Contains(attachment.FilePath));
|
||||
foreach (var transcript in copy.PendingMediaTranscripts)
|
||||
this.ComposerState.FileAttachments.Add(transcript);
|
||||
|
||||
this.ChatThread = copy;
|
||||
this.hasUnsavedChanges = false;
|
||||
|
||||
await this.SyncForegroundChatAsync();
|
||||
this.MarkCurrentChatAsLoadedParameter();
|
||||
await this.SyncWorkspaceHeaderWithChatThreadAsync();
|
||||
await this.ChatThreadChanged.InvokeAsync(this.ChatThread);
|
||||
}
|
||||
|
||||
private async Task LoadedChatChanged(bool notifyParent = true)
|
||||
{
|
||||
this.hasUnsavedChanges = false;
|
||||
|
||||
@ -660,6 +660,24 @@ public partial class Workspaces : MSGComponentBase
|
||||
await this.LoadTreeItemsAsync(startPrefetch: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the given chat, after asking the user for the name of the copy, and shows the copy in the tree.
|
||||
/// </summary>
|
||||
/// <param name="sourceChat">The chat to copy, as it stands in memory.</param>
|
||||
/// <returns>The persisted copy. Null when the user canceled the question, in which case nothing was copied.</returns>
|
||||
/// <remarks>
|
||||
/// Neither asks about unsaved changes nor opens the copy: which of both a caller needs depends
|
||||
/// on where the copy was asked for.
|
||||
/// </remarks>
|
||||
public async Task<ChatThread?> CopyChatAsync(ChatThread sourceChat)
|
||||
{
|
||||
var copy = await WorkspaceBehaviour.CopyChatAsync(this.DialogService, sourceChat);
|
||||
if (copy is not null)
|
||||
await this.LoadTreeItemsAsync(startPrefetch: false);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
private async Task<ChatThread?> LoadChatAsync(string? chatPath, bool switchToChat)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(chatPath))
|
||||
@ -819,11 +837,10 @@ public partial class Workspaces : MSGComponentBase
|
||||
}
|
||||
|
||||
var sourceChat = isCopyOfOpenChat ? openChat! : chat;
|
||||
var copy = await WorkspaceBehaviour.CopyChatAsync(this.DialogService, sourceChat);
|
||||
var copy = await this.CopyChatAsync(sourceChat);
|
||||
if (copy is null)
|
||||
return;
|
||||
|
||||
await this.LoadTreeItemsAsync(startPrefetch: false);
|
||||
this.CurrentChatThread = copy;
|
||||
await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user