mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-21 22:12:16 +00:00
Sync chat thread and workspace state in UI
This commit is contained in:
parent
bf329afc9f
commit
544d339699
@ -56,6 +56,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
private bool autoSaveEnabled;
|
private bool autoSaveEnabled;
|
||||||
private string currentWorkspaceName = string.Empty;
|
private string currentWorkspaceName = string.Empty;
|
||||||
private Guid currentWorkspaceId = Guid.Empty;
|
private Guid currentWorkspaceId = Guid.Empty;
|
||||||
|
private Guid currentChatThreadId = Guid.Empty;
|
||||||
private CancellationTokenSource? cancellationTokenSource;
|
private CancellationTokenSource? cancellationTokenSource;
|
||||||
private HashSet<FileAttachment> chatDocumentPaths = [];
|
private HashSet<FileAttachment> chatDocumentPaths = [];
|
||||||
|
|
||||||
@ -197,6 +198,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
//
|
//
|
||||||
if (this.ChatThread is not null)
|
if (this.ChatThread is not null)
|
||||||
{
|
{
|
||||||
|
this.currentChatThreadId = this.ChatThread.ChatId;
|
||||||
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
||||||
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
||||||
this.WorkspaceName(this.currentWorkspaceName);
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
@ -260,8 +262,40 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
await base.OnAfterRenderAsync(firstRender);
|
await base.OnAfterRenderAsync(firstRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override async Task OnParametersSetAsync()
|
||||||
|
{
|
||||||
|
await this.SyncWorkspaceHeaderWithChatThreadAsync();
|
||||||
|
await base.OnParametersSetAsync();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private async Task SyncWorkspaceHeaderWithChatThreadAsync()
|
||||||
|
{
|
||||||
|
if (this.ChatThread is null)
|
||||||
|
{
|
||||||
|
if (this.currentChatThreadId != Guid.Empty || this.currentWorkspaceId != Guid.Empty || !string.IsNullOrWhiteSpace(this.currentWorkspaceName))
|
||||||
|
{
|
||||||
|
this.currentChatThreadId = Guid.Empty;
|
||||||
|
this.currentWorkspaceId = Guid.Empty;
|
||||||
|
this.currentWorkspaceName = string.Empty;
|
||||||
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.currentChatThreadId == this.ChatThread.ChatId
|
||||||
|
&& this.currentWorkspaceId == this.ChatThread.WorkspaceId
|
||||||
|
&& !string.IsNullOrWhiteSpace(this.currentWorkspaceName))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.currentChatThreadId = this.ChatThread.ChatId;
|
||||||
|
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
||||||
|
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
||||||
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
|
}
|
||||||
|
|
||||||
private bool IsProviderSelected => this.Provider.UsedLLMProvider != LLMProviders.NONE;
|
private bool IsProviderSelected => this.Provider.UsedLLMProvider != LLMProviders.NONE;
|
||||||
|
|
||||||
private string ProviderPlaceholder => this.IsProviderSelected ? T("Type your input here...") : T("Select a provider first");
|
private string ProviderPlaceholder => this.IsProviderSelected ? T("Type your input here...") : T("Select a provider first");
|
||||||
@ -665,6 +699,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
// to reset the chat thread:
|
// to reset the chat thread:
|
||||||
//
|
//
|
||||||
this.ChatThread = null;
|
this.ChatThread = null;
|
||||||
|
this.currentChatThreadId = Guid.Empty;
|
||||||
this.currentWorkspaceId = Guid.Empty;
|
this.currentWorkspaceId = Guid.Empty;
|
||||||
this.currentWorkspaceName = string.Empty;
|
this.currentWorkspaceName = string.Empty;
|
||||||
this.WorkspaceName(this.currentWorkspaceName);
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
@ -760,10 +795,12 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
||||||
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
||||||
this.WorkspaceName(this.currentWorkspaceName);
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
|
this.currentChatThreadId = this.ChatThread.ChatId;
|
||||||
this.dataSourceSelectionComponent?.ChangeOptionWithoutSaving(this.ChatThread.DataSourceOptions, this.ChatThread.AISelectedDataSources);
|
this.dataSourceSelectionComponent?.ChangeOptionWithoutSaving(this.ChatThread.DataSourceOptions, this.ChatThread.AISelectedDataSources);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
this.currentChatThreadId = Guid.Empty;
|
||||||
this.currentWorkspaceId = Guid.Empty;
|
this.currentWorkspaceId = Guid.Empty;
|
||||||
this.currentWorkspaceName = string.Empty;
|
this.currentWorkspaceName = string.Empty;
|
||||||
this.WorkspaceName(this.currentWorkspaceName);
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
@ -785,6 +822,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
this.isStreaming = false;
|
this.isStreaming = false;
|
||||||
this.hasUnsavedChanges = false;
|
this.hasUnsavedChanges = false;
|
||||||
this.userInput = string.Empty;
|
this.userInput = string.Empty;
|
||||||
|
this.currentChatThreadId = Guid.Empty;
|
||||||
this.currentWorkspaceId = Guid.Empty;
|
this.currentWorkspaceId = Guid.Empty;
|
||||||
|
|
||||||
this.currentWorkspaceName = string.Empty;
|
this.currentWorkspaceName = string.Empty;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user