-
-
Notifications
You must be signed in to change notification settings - Fork 615
Features/add conv thumbnail #1297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Oceania2018
merged 3 commits into
SciSharp:master
from
iceljc:features/add-conv-thumbnail
Feb 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStorage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| using BotSharp.Abstraction.Repositories.Filters; | ||
|
|
||
| namespace BotSharp.Abstraction.Conversations; | ||
|
|
||
| public interface IConversationStorage | ||
| { | ||
| Task Append(string conversationId, RoleDialogModel dialog); | ||
| Task Append(string conversationId, IEnumerable<RoleDialogModel> dialogs); | ||
| Task<List<RoleDialogModel>> GetDialogs(string conversationId); | ||
| Task<List<RoleDialogModel>> GetDialogs(string conversationId, ConversationDialogFilter? filter = null); | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationFile.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace BotSharp.Abstraction.Conversations.Models; | ||
|
|
||
| public class ConversationFile | ||
| { | ||
| public string ConversationId { get; set; } | ||
| public string? Thumbnail { get; set; } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationDialogFilter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace BotSharp.Abstraction.Repositories.Filters; | ||
|
|
||
| public class ConversationDialogFilter | ||
| { | ||
| public string Order { get; set; } = "asc"; | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFileFilter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace BotSharp.Abstraction.Repositories.Filters; | ||
|
|
||
| public class ConversationFileFilter | ||
| { | ||
| public IEnumerable<string> ConversationIds { get; set; } = []; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| using BotSharp.Abstraction.Loggers.Models; | ||
| using System.IO; | ||
| using System.Threading; | ||
|
|
||
| namespace BotSharp.Core.Repository; | ||
|
|
||
|
|
@@ -75,7 +74,7 @@ public Task<bool> DeleteConversations(IEnumerable<string> conversationIds) | |
| } | ||
|
|
||
| [SideCar] | ||
| public async Task<List<DialogElement>> GetConversationDialogs(string conversationId) | ||
| public async Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null) | ||
| { | ||
| var dialogs = new List<DialogElement>(); | ||
| var convDir = FindConversationDirectory(conversationId); | ||
|
|
@@ -93,11 +92,16 @@ public async Task<List<DialogElement>> GetConversationDialogs(string conversatio | |
| var texts = await File.ReadAllTextAsync(dialogDir); | ||
| try | ||
| { | ||
| dialogs = JsonSerializer.Deserialize<List<DialogElement>>(texts, _options) ?? new List<DialogElement>(); | ||
| dialogs = JsonSerializer.Deserialize<List<DialogElement>>(texts, _options) ?? []; | ||
| } | ||
| catch | ||
| { | ||
| dialogs = new List<DialogElement>(); | ||
| dialogs = []; | ||
| } | ||
|
Comment on lines
94
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. getconversationdialogs swallows deserialize errors JSON deserialization failures are caught without logging, which hides corrupt/invalid dialog data and makes production debugging difficult. This violates the requirement to avoid swallowed exceptions without logging or actionable context. Agent Prompt
|
||
|
|
||
| if (filter?.Order == "desc") | ||
| { | ||
| dialogs = dialogs.OrderByDescending(x => x.MetaData?.CreatedTime).ToList(); | ||
| } | ||
| } | ||
| finally | ||
|
|
@@ -884,6 +888,139 @@ public async Task<bool> MigrateConvsersationLatestStates(string conversationId) | |
| } | ||
|
|
||
|
|
||
| #region Files | ||
| public async Task<List<ConversationFile>> GetConversationFiles(ConversationFileFilter filter) | ||
| { | ||
| if (filter == null || filter.ConversationIds.IsNullOrEmpty()) | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| var files = new List<ConversationFile>(); | ||
| var baseDir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir); | ||
|
|
||
| if (!Directory.Exists(baseDir)) | ||
| { | ||
| return files; | ||
| } | ||
|
|
||
| foreach (var conversationId in filter.ConversationIds) | ||
| { | ||
| if (string.IsNullOrEmpty(conversationId)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var convDir = Path.Combine(baseDir, conversationId); | ||
| if (!Directory.Exists(convDir)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var filesFile = Path.Combine(convDir, CONV_FILES_FILE); | ||
| if (!File.Exists(filesFile)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var json = await File.ReadAllTextAsync(filesFile); | ||
| var conversationFile = JsonSerializer.Deserialize<ConversationFile>(json, _options); | ||
| if (conversationFile != null) | ||
| { | ||
| files.Add(conversationFile); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogWarning(ex, $"Error when reading conversation files for conversation {conversationId}."); | ||
| } | ||
| } | ||
|
|
||
| return files; | ||
| } | ||
|
|
||
| public async Task<bool> SaveConversationFiles(List<ConversationFile> files) | ||
| { | ||
| if (files.IsNullOrEmpty()) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var baseDir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir); | ||
|
|
||
| foreach (var file in files) | ||
| { | ||
| if (string.IsNullOrEmpty(file.ConversationId)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var convDir = Path.Combine(baseDir, file.ConversationId); | ||
| if (!Directory.Exists(convDir)) | ||
| { | ||
| Directory.CreateDirectory(convDir); | ||
| } | ||
|
|
||
| var convFile = Path.Combine(convDir, CONV_FILES_FILE); | ||
| var json = JsonSerializer.Serialize(file, _options); | ||
| await File.WriteAllTextAsync(convFile, json); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "Error when saving conversation files."); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public async Task<bool> DeleteConversationFiles(List<string> conversationIds) | ||
| { | ||
| if (conversationIds.IsNullOrEmpty()) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var baseDir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir); | ||
|
|
||
| foreach (var conversationId in conversationIds) | ||
| { | ||
| if (string.IsNullOrEmpty(conversationId)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var convDir = Path.Combine(baseDir, conversationId); | ||
| if (!Directory.Exists(convDir)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var filesFile = Path.Combine(convDir, CONV_FILES_FILE); | ||
| if (File.Exists(filesFile)) | ||
| { | ||
| File.Delete(filesFile); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "Error when deleting conversation files."); | ||
| return false; | ||
| } | ||
| } | ||
| #endregion | ||
|
|
||
|
|
||
| #region Private methods | ||
| private string? FindConversationDirectory(string conversationId) | ||
| { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Sidecar ignores order filter
🐞 Bug✓ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools