Skip to content

Commit 2d9f0df

Browse files
authored
Merge pull request #1297 from iceljc/features/add-conv-thumbnail
Features/add conv thumbnail
2 parents 90392d0 + 851e7fa commit 2d9f0df

21 files changed

Lines changed: 420 additions & 35 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Repositories.Filters;
2-
using BotSharp.Abstraction.Users.Models;
32

43
namespace BotSharp.Abstraction.Conversations;
54

@@ -41,7 +40,7 @@ Task<bool> SendMessage(string agentId,
4140
PostbackMessageModel? replyMessage,
4241
Func<RoleDialogModel, Task> onResponseReceived);
4342

44-
Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null);
43+
Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null, ConversationDialogFilter? filter = null);
4544
Task CleanHistory(string agentId);
4645

4746
/// <summary>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using BotSharp.Abstraction.Repositories.Filters;
2+
13
namespace BotSharp.Abstraction.Conversations;
24

35
public interface IConversationStorage
46
{
57
Task Append(string conversationId, RoleDialogModel dialog);
68
Task Append(string conversationId, IEnumerable<RoleDialogModel> dialogs);
7-
Task<List<RoleDialogModel>> GetDialogs(string conversationId);
9+
Task<List<RoleDialogModel>> GetDialogs(string conversationId, ConversationDialogFilter? filter = null);
810
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Conversations.Models;
2+
3+
public class ConversationFile
4+
{
5+
public string ConversationId { get; set; }
6+
public string? Thumbnail { get; set; }
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Repositories.Filters;
2+
3+
public class ConversationDialogFilter
4+
{
5+
public string Order { get; set; } = "asc";
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Repositories.Filters;
2+
3+
public class ConversationFileFilter
4+
{
5+
public IEnumerable<string> ConversationIds { get; set; } = [];
6+
}

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ConversationFilter
3131
public List<string>? Tags { get; set; }
3232

3333
public bool IsLoadLatestStates { get; set; }
34+
public bool IsLoadThumbnail { get; set; }
3435

3536
public static ConversationFilter Empty()
3637
{

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Task CreateNewConversation(Conversation conversation)
129129
=> throw new NotImplementedException();
130130
Task<bool> DeleteConversations(IEnumerable<string> conversationIds)
131131
=> throw new NotImplementedException();
132-
Task<List<DialogElement>> GetConversationDialogs(string conversationId)
132+
Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null)
133133
=> throw new NotImplementedException();
134134
Task AppendConversationDialogs(string conversationId, List<DialogElement> dialogs)
135135
=> throw new NotImplementedException();
@@ -169,6 +169,12 @@ Task<List<string>> GetConversationsToMigrate(int batchSize = 100)
169169
=> throw new NotImplementedException();
170170
Task<bool> MigrateConvsersationLatestStates(string conversationId)
171171
=> throw new NotImplementedException();
172+
Task<List<ConversationFile>> GetConversationFiles(ConversationFileFilter filter)
173+
=> throw new NotImplementedException();
174+
Task<bool> SaveConversationFiles(List<ConversationFile> files)
175+
=> throw new NotImplementedException();
176+
Task<bool> DeleteConversationFiles(List<string> conversationIds)
177+
=> throw new NotImplementedException();
172178
#endregion
173179

174180
#region LLM Completion Log

src/Infrastructure/BotSharp.Abstraction/SideCar/Attributes/SideCarAttribute.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ private static MethodInfo GetMethod(string name)
6262
try
6363
{
6464
var sidecar = serviceProvider.GetService<IConversationSideCar>();
65-
var argTypes = args.Select(x => x.GetType()).ToArray();
65+
var argTypes = args.Select(x => x != null ? x.GetType() : null).ToArray();
6666
var sidecarMethod = sidecar?.GetType()?.GetMethods(BindingFlags.Public | BindingFlags.Instance)
6767
.FirstOrDefault(x => x.Name == methodName
6868
&& x.ReturnType == retType
6969
&& x.GetParameters().Length == argTypes.Length
7070
&& x.GetParameters().Select(p => p.ParameterType)
71-
.Zip(argTypes, (paramType, argType) => paramType.IsAssignableFrom(argType)).All(y => y));
71+
.Zip(argTypes, (paramType, argType) => IsParameterTypeMatch(paramType, argType)).All(y => y));
7272

7373
return (sidecar, sidecarMethod);
7474
}
@@ -78,6 +78,28 @@ private static MethodInfo GetMethod(string name)
7878
}
7979
}
8080

81+
private static bool IsParameterTypeMatch(Type paramType, Type? argType)
82+
{
83+
// If argument is null, check if parameter type is nullable
84+
if (argType == null)
85+
{
86+
// Check if it's a nullable value type (e.g., int?)
87+
if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(Nullable<>))
88+
{
89+
return true;
90+
}
91+
// Check if it's a reference type (which are inherently nullable)
92+
if (!paramType.IsValueType)
93+
{
94+
return true;
95+
}
96+
return false;
97+
}
98+
99+
// Normal type matching
100+
return paramType.IsAssignableFrom(argType);
101+
}
102+
81103
private async Task<(bool, object?)> CallAsyncMethod(IConversationSideCar instance, MethodInfo method, Type retType, object[] args)
82104
{
83105
object? value = null;

src/Infrastructure/BotSharp.Abstraction/SideCar/IConversationSideCar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Repositories.Filters;
12
using BotSharp.Abstraction.SideCar.Options;
23

34
namespace BotSharp.Abstraction.SideCar;
@@ -8,7 +9,7 @@ public interface IConversationSideCar
89
bool IsEnabled { get; }
910

1011
Task AppendConversationDialogs(string conversationId, List<DialogElement> messages);
11-
Task<List<DialogElement>> GetConversationDialogs(string conversationId);
12+
Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null);
1213
Task UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint);
1314
Task<ConversationBreakpoint?> GetConversationBreakpoint(string conversationId);
1415
Task UpdateConversationStates(string conversationId, List<StateKeyValue> states);

src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You may obtain a copy of the License at
1414
limitations under the License.
1515
******************************************************************************/
1616

17-
using BotSharp.Abstraction.SideCar.Options;
17+
using BotSharp.Abstraction.Repositories.Filters;
1818
using BotSharp.Core.Infrastructures;
1919

2020
namespace BotSharp.Core.SideCar.Services;
@@ -54,16 +54,20 @@ public async Task AppendConversationDialogs(string conversationId, List<DialogEl
5454
await Task.CompletedTask;
5555
}
5656

57-
public async Task<List<DialogElement>> GetConversationDialogs(string conversationId)
57+
public async Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null)
5858
{
5959
if (!IsValid(conversationId))
6060
{
61-
return new List<DialogElement>();
61+
return [];
6262
}
6363

64-
await Task.CompletedTask;
64+
var dialogs = _contextStack.Peek().Dialogs ?? [];
65+
if (filter?.Order == "desc")
66+
{
67+
dialogs = dialogs.OrderByDescending(x => x.MetaData?.CreatedTime).ToList();
68+
}
6569

66-
return _contextStack.Peek().Dialogs;
70+
return await Task.FromResult(dialogs);
6771
}
6872

6973
public async Task UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint)
@@ -87,9 +91,7 @@ public async Task UpdateConversationBreakpoint(string conversationId, Conversati
8791
}
8892

8993
var top = _contextStack.Peek().Breakpoints;
90-
91-
await Task.CompletedTask;
92-
return top.LastOrDefault();
94+
return await Task.FromResult(top.LastOrDefault());
9395
}
9496

9597
public async Task UpdateConversationStates(string conversationId, List<StateKeyValue> states)

0 commit comments

Comments
 (0)