Skip to content

Commit ee73e6e

Browse files
authored
Merge pull request #1273 from iceljc/features/refine-membase
refine repository and coding util
2 parents 9211d06 + 5e79163 commit ee73e6e

File tree

49 files changed

+276
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+276
-248
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace BotSharp.Abstraction.Coding.Utils;
2+
3+
public static class CodingUtil
4+
{
5+
/// <summary>
6+
/// Get code execution config => (useLock, useProcess, timeout seconds)
7+
/// </summary>
8+
/// <param name="settings"></param>
9+
/// <param name="defaultTimeoutSeconds"></param>
10+
/// <returns></returns>
11+
public static (bool, bool, int) GetCodeExecutionConfig(CodingSettings settings, int defaultTimeoutSeconds = 3)
12+
{
13+
var codeExecution = settings.CodeExecution;
14+
15+
var useLock = codeExecution?.UseLock ?? false;
16+
var useProcess = codeExecution?.UseProcess ?? false;
17+
var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
18+
19+
return (useLock, useProcess, timeoutSeconds);
20+
}
21+
}

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

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

34
namespace BotSharp.Abstraction.Conversations;
45

@@ -61,6 +62,4 @@ Task<bool> SendMessage(string agentId,
6162
Task SaveStates();
6263

6364
Task<List<string>> GetConversationStateSearhKeys(ConversationStateKeysFilter filter);
64-
65-
Task<bool> MigrateLatestStates(int batchSize = 100, int errorLimit = 10);
6665
}

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ public class DialogMetaData
123123

124124
[JsonPropertyName("create_at")]
125125
public DateTime CreatedTime { get; set; }
126-
}
126+
}

src/Infrastructure/BotSharp.Abstraction/Files/Models/InstructFileModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override string ToString()
3131
}
3232
else if (!string.IsNullOrEmpty(FileData))
3333
{
34-
return FileData.SubstringMax(20);
34+
return FileData.SubstringMax(50);
3535
}
3636
return string.Empty;
3737
}

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/CyperGraphModels.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ public class GraphQueryResult
99
public class GraphNode
1010
{
1111
public string Id { get; set; } = string.Empty;
12-
1312
public List<string> Labels { get; set; } = new();
14-
1513
public object Properties { get; set; } = new();
16-
1714
public DateTime Time { get; set; } = DateTime.UtcNow;
1815

1916
public override string ToString()

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Task<bool> UpdateRole(Role role, bool updateRoleAgents = false)
6161
Task UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
6262
Task UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
6363
Task UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
64-
ValueTask<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
64+
Task<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
6565
Task<List<User>> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
6666
Task<User?> GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
6767
Task<bool> UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
@@ -99,7 +99,7 @@ Task<bool> AppendAgentLabels(string agentId, List<string> labels)
9999
#endregion
100100

101101
#region Agent Task
102-
ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
102+
Task<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
103103
=> throw new NotImplementedException();
104104
Task<AgentTask?> GetAgentTask(string agentId, string taskId)
105105
=> throw new NotImplementedException();
@@ -143,7 +143,7 @@ Task UpdateConversationStatus(string conversationId, string status)
143143
=> throw new NotImplementedException();
144144
Task<Conversation> GetConversation(string conversationId, bool isLoadStates = false)
145145
=> throw new NotImplementedException();
146-
ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
146+
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
147147
=> throw new NotImplementedException();
148148
Task UpdateConversationTitle(string conversationId, string title)
149149
=> throw new NotImplementedException();
@@ -196,7 +196,7 @@ Task<DateTimePagination<ConversationStateLogModel>> GetConversationStateLogs(str
196196
Task<bool> SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
197197
=> throw new NotImplementedException();
198198

199-
ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
199+
Task<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
200200
=> throw new NotImplementedException();
201201

202202
Task<List<string>> GetInstructionLogSearchKeys(InstructLogKeysFilter filter)
@@ -249,7 +249,7 @@ Task<bool> SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData)
249249
/// <returns></returns>
250250
Task<bool> DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null)
251251
=> throw new NotImplementedException();
252-
ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
252+
Task<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
253253
=> throw new NotImplementedException();
254254
#endregion
255255

@@ -258,7 +258,7 @@ Task<bool> UpsertCrontabItem(CrontabItem cron)
258258
=> throw new NotImplementedException();
259259
Task<bool> DeleteCrontabItem(string conversationId)
260260
=> throw new NotImplementedException();
261-
ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
261+
Task<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
262262
=> throw new NotImplementedException();
263263
#endregion
264264
}

src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BotSharp.Abstraction.Coding.Enums;
55
using BotSharp.Abstraction.Coding.Models;
66
using BotSharp.Abstraction.Coding.Settings;
7+
using BotSharp.Abstraction.Coding.Utils;
78
using BotSharp.Abstraction.Conversations;
89
using BotSharp.Abstraction.Hooks;
910
using BotSharp.Abstraction.Models;
@@ -138,7 +139,7 @@ private async Task<bool> TriggerCodeScript(Agent agent, string triggerName, Rule
138139
await hook.BeforeCodeExecution(agent, context);
139140
}
140141

141-
var (useLock, useProcess, timeoutSeconds) = GetCodeExecutionConfig();
142+
var (useLock, useProcess, timeoutSeconds) = CodingUtil.GetCodeExecutionConfig(_codingSettings);
142143
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
143144
var response = processor.Run(codeScript.Content, options: new()
144145
{
@@ -199,17 +200,5 @@ private List<KeyValue> BuildArguments(string? name, JsonDocument? args)
199200
}
200201
return keyValues;
201202
}
202-
203-
private (bool, bool, int) GetCodeExecutionConfig()
204-
{
205-
var codeExecution = _codingSettings.CodeExecution;
206-
var defaultTimeoutSeconds = 3;
207-
208-
var useLock = codeExecution?.UseLock ?? false;
209-
var useProcess = codeExecution?.UseProcess ?? false;
210-
var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
211-
212-
return (useLock, useProcess, timeoutSeconds);
213-
}
214203
#endregion
215204
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Migration.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using BotSharp.Abstraction.Models;
2+
using BotSharp.Abstraction.Users.Models;
3+
using System.Threading.Tasks;
24

35
namespace BotSharp.Core.Conversations.Services;
46

src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Coding;
22
using BotSharp.Abstraction.Coding.Contexts;
33
using BotSharp.Abstraction.Coding.Enums;
4+
using BotSharp.Abstraction.Coding.Utils;
45
using BotSharp.Abstraction.Files.Options;
56
using BotSharp.Abstraction.Files.Proccessors;
67
using BotSharp.Abstraction.Instructs;
@@ -156,7 +157,7 @@ public async Task<InstructResult> Execute(
156157
}
157158

158159
// Run code script
159-
var (useLock, useProcess, timeoutSeconds) = GetCodeExecutionConfig(codingSettings);
160+
var (useLock, useProcess, timeoutSeconds) = CodingUtil.GetCodeExecutionConfig(codingSettings);
160161
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
161162
var codeResponse = codeProcessor.Run(context.CodeScript?.Content ?? string.Empty, options: new()
162163
{
@@ -350,20 +351,4 @@ private async Task<string> GetChatCompletion(
350351

351352
return result.Content;
352353
}
353-
354-
/// <summary>
355-
/// Returns (useLock, useProcess, timeoutSeconds)
356-
/// </summary>
357-
/// <returns></returns>
358-
private (bool, bool, int) GetCodeExecutionConfig(CodingSettings settings)
359-
{
360-
var codeExecution = settings.CodeExecution;
361-
var defaultTimeoutSeconds = 3;
362-
363-
var useLock = codeExecution?.UseLock ?? false;
364-
var useProcess = codeExecution?.UseProcess ?? false;
365-
var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
366-
367-
return (useLock, useProcess, timeoutSeconds);
368-
}
369354
}

0 commit comments

Comments
 (0)