66
77namespace Goodtocode . SemanticKernel . Infrastructure . SemanticKernel . Plugins ;
88
9- public sealed class ChatSessionsPlugin ( IServiceProvider serviceProvider ) : IChatSessionsPlugin
9+ public interface ISemanticPluginCompatible
10+ {
11+ string PluginName { get ; }
12+ string FunctionName { get ; }
13+ Dictionary < string , object > Parameters { get ; }
14+ }
15+
16+ public sealed class ChatSessionsPlugin ( IServiceProvider serviceProvider ) : IChatSessionsPlugin , ISemanticPluginCompatible
1017{
1118 private readonly IServiceProvider _serviceProvider = serviceProvider ;
1219
20+ public string PluginName => "ChatSessionsPlugin" ;
21+ public string FunctionName => _currentFunctionName ;
22+ public Dictionary < string , object > Parameters => _currentParameters ;
23+
24+ private string _currentFunctionName = string . Empty ;
25+ private Dictionary < string , object > _currentParameters = new ( ) ;
26+
1327 [ KernelFunction ( "list_sessions" ) ]
1428 [ Description ( "Retrieves a list of recent chat sessions. Optionally, filter results by start and/or end date to narrow the search." ) ]
15- public async Task < IEnumerable < string > > ListRecentSessionsAsync (
16- DateTime ? startDate = null ,
17- DateTime ? endDate = null ,
18- CancellationToken cancellationToken = default )
29+ public async Task < IEnumerable < string > > ListRecentSessionsAsync ( DateTime ? startDate = null , DateTime ? endDate = null , CancellationToken cancellationToken = default )
1930 {
20- // Get ISemanticKernelContext directly instead of constructor DI to allow this plugin to be registered via AddSingleton() and not scoped due to EF.
31+ _currentFunctionName = "list_sessions" ;
32+ _currentParameters = new ( )
33+ {
34+ { "startDate" , startDate ?? DateTime . UtcNow . AddDays ( - 7 ) } ,
35+ { "endDate" , endDate ?? DateTime . UtcNow . AddSeconds ( 1 ) }
36+ } ;
37+
2138 using var scope = _serviceProvider . CreateScope ( ) ;
2239 var context = scope . ServiceProvider . GetRequiredService < ISemanticKernelContext > ( ) ;
2340
@@ -37,19 +54,30 @@ public async Task<IEnumerable<string>> ListRecentSessionsAsync(
3754
3855 [ KernelFunction ( "change_title" ) ]
3956 [ Description ( "Changes the title on this chat session." ) ]
40- public async Task < string > UpdateChatSessionTitleAsync ( Guid sessionId , string newTitle ,
41- CancellationToken cancellationToken = default )
57+ public async Task < string > UpdateChatSessionTitleAsync ( Guid sessionId , string newTitle , CancellationToken cancellationToken = default )
4258 {
43- // Get ISemanticKernelContext directly instead of constructor DI to allow this plugin to be registered via AddSingleton() and not scoped due to EF.
59+ _currentFunctionName = "change_title" ;
60+ _currentParameters = new ( )
61+ {
62+ { "sessionId" , sessionId } ,
63+ { "newTitle" , newTitle }
64+ } ;
65+
4466 using var scope = _serviceProvider . CreateScope ( ) ;
4567 var context = scope . ServiceProvider . GetRequiredService < ISemanticKernelContext > ( ) ;
4668
4769 var chatSession = await context . ChatSessions
4870 . FirstOrDefaultAsync ( x => x . Id == sessionId , cancellationToken : cancellationToken ) ;
49- chatSession ! . Title = newTitle ;
71+
72+ if ( chatSession == null )
73+ {
74+ return $ "Session { sessionId } not found.";
75+ }
76+
77+ chatSession . Title = newTitle ;
5078 context . ChatSessions . Update ( chatSession ) ;
5179 await context . SaveChangesAsync ( cancellationToken ) ;
5280
5381 return $ "{ chatSession . Id } : { chatSession . Timestamp } - { chatSession . Title } : { chatSession . Author ? . Name } ";
5482 }
55- }
83+ }
0 commit comments