mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 23:07:23 +00:00
Fixed chats being stored when chats are stored manually or workspaces are disabled (#1145)
This commit is contained in:
1 parent
9532664a25
commit
64dc621a7d
12 files changed
+415
-71
No files matched your search
@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.RAG.RAGProcesses;
|
||||
|
||||
@@ -175,7 +176,7 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
|
||||
|
||||
request.AIText.InitialRemoteWait = true;
|
||||
request.AIText.IsStreaming = false;
|
||||
await CheckpointChatAsync(state, force: true);
|
||||
await this.CheckpointChatAsync(state, force: true);
|
||||
await this.NotifyChangedAsync(state);
|
||||
|
||||
//
|
||||
@@ -329,7 +330,7 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
|
||||
await this.NotifyChangedAsync(state);
|
||||
}
|
||||
|
||||
await CheckpointChatAsync(state);
|
||||
await this.CheckpointChatAsync(state);
|
||||
}
|
||||
|
||||
await this.CompleteChatGenerationAsync(state, token.IsCancellationRequested ? AIJobStatus.CANCELED : AIJobStatus.COMPLETED);
|
||||
@@ -393,7 +394,7 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
|
||||
}
|
||||
|
||||
this.activeChatJobsByChatId.TryRemove(request.ChatThread.ChatId, out _);
|
||||
await CheckpointChatAsync(state, force: true);
|
||||
await this.CheckpointChatAsync(state, force: true);
|
||||
await this.NotifyChangedAsync(state);
|
||||
await messageBus.SendMessage(null, Event.AI_JOB_FINISHED, state.Snapshot);
|
||||
state.CancellationTokenSource.Dispose();
|
||||
@@ -505,8 +506,26 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
|
||||
await messageBus.SendMessage(null, Event.AI_JOB_CHANGED, state.Snapshot);
|
||||
}
|
||||
|
||||
private static async Task CheckpointChatAsync(AIJobState state, bool force = false)
|
||||
/// <summary>
|
||||
/// Stores the chat of a job, at most once per <see cref="CHECKPOINT_MIN_TIME"/> unless forced.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only while chats are stored automatically. Whoever stores chats manually decides when a chat
|
||||
/// reaches the disk, with its save button, and whoever disabled the workspaces wants no chat on the
|
||||
/// disk at all. Storing it here anyway would put every message on the disk the moment it is sent,
|
||||
/// and overwrite what the user saved by hand with what they did not save. The chat marks the answer
|
||||
/// as unsaved instead, once the job is done.<br/><br/>
|
||||
///
|
||||
/// The storage mode is read every time rather than once for the job: whoever changes it while an
|
||||
/// answer is being written gets what the chat reads when the answer is done.
|
||||
/// </remarks>
|
||||
/// <param name="state">The job whose chat to store.</param>
|
||||
/// <param name="force">True stores the chat even when the last checkpoint was just now.</param>
|
||||
private async Task CheckpointChatAsync(AIJobState state, bool force = false)
|
||||
{
|
||||
if (settingsManager.ConfigurationData.Workspace.StorageBehavior is not WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY)
|
||||
return;
|
||||
|
||||
var now = DateTimeOffset.Now;
|
||||
if (!force && now - state.LastCheckpoint < CHECKPOINT_MIN_TIME)
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user