@@ -8,8 +8,8 @@ namespace BotSharp.Core.Conversations.Services;
8
8
public class ConversationStorage : IConversationStorage
9
9
{
10
10
private readonly BotSharpDatabaseSettings _dbSettings ;
11
+ private readonly BotSharpOptions _options ;
11
12
private readonly IServiceProvider _services ;
12
- private readonly JsonSerializerOptions _jsonOptions ;
13
13
14
14
public ConversationStorage (
15
15
BotSharpDatabaseSettings dbSettings ,
@@ -18,7 +18,7 @@ public ConversationStorage(
18
18
{
19
19
_dbSettings = dbSettings ;
20
20
_services = services ;
21
- _jsonOptions = InitJsonSerilizerOptions ( options ) ;
21
+ _options = options ;
22
22
}
23
23
24
24
public void Append ( string conversationId , RoleDialogModel dialog )
@@ -70,7 +70,7 @@ public void Append(string conversationId, RoleDialogModel dialog)
70
70
return ;
71
71
}
72
72
73
- var richContent = dialog . RichContent != null ? JsonSerializer . Serialize ( dialog . RichContent , _jsonOptions ) : null ;
73
+ var richContent = dialog . RichContent != null ? JsonSerializer . Serialize ( dialog . RichContent , _options . JsonSerializerOptions ) : null ;
74
74
dialogElements . Add ( new DialogElement ( meta , content , richContent ) ) ;
75
75
}
76
76
@@ -95,7 +95,7 @@ public List<RoleDialogModel> GetDialogs(string conversationId)
95
95
var senderId = role == AgentRole . Function ? currentAgentId : meta . SenderId ;
96
96
var createdAt = meta . CreateTime ;
97
97
var richContent = ! string . IsNullOrEmpty ( dialog . RichContent ) ?
98
- JsonSerializer . Deserialize < RichContent < IRichMessage > > ( dialog . RichContent , _jsonOptions ) : null ;
98
+ JsonSerializer . Deserialize < RichContent < IRichMessage > > ( dialog . RichContent , _options . JsonSerializerOptions ) : null ;
99
99
100
100
var record = new RoleDialogModel ( role , content )
101
101
{
@@ -140,21 +140,4 @@ private string GetStorageFile(string conversationId)
140
140
}
141
141
return Path . Combine ( dir , "dialogs.txt" ) ;
142
142
}
143
-
144
- private JsonSerializerOptions InitJsonSerilizerOptions ( BotSharpOptions botSharOptions )
145
- {
146
- var options = botSharOptions . JsonSerializerOptions ;
147
- var jsonOptions = new JsonSerializerOptions
148
- {
149
- PropertyNameCaseInsensitive = options . PropertyNameCaseInsensitive ,
150
- PropertyNamingPolicy = options . PropertyNamingPolicy ?? JsonNamingPolicy . CamelCase ,
151
- AllowTrailingCommas = options . AllowTrailingCommas ,
152
- } ;
153
-
154
- foreach ( var converter in options . Converters )
155
- {
156
- jsonOptions . Converters . Add ( converter ) ;
157
- }
158
- return jsonOptions ;
159
- }
160
143
}
0 commit comments