diff --git a/src/Infrastructure/BotSharp.Abstraction/Coding/Utils/CodingUtil.cs b/src/Infrastructure/BotSharp.Abstraction/Coding/Utils/CodingUtil.cs
new file mode 100644
index 000000000..57420d4d4
--- /dev/null
+++ b/src/Infrastructure/BotSharp.Abstraction/Coding/Utils/CodingUtil.cs
@@ -0,0 +1,21 @@
+namespace BotSharp.Abstraction.Coding.Utils;
+
+public static class CodingUtil
+{
+ ///
+ /// Get code execution config => (useLock, useProcess, timeout seconds)
+ ///
+ ///
+ ///
+ ///
+ public static (bool, bool, int) GetCodeExecutionConfig(CodingSettings settings, int defaultTimeoutSeconds = 3)
+ {
+ var codeExecution = settings.CodeExecution;
+
+ var useLock = codeExecution?.UseLock ?? false;
+ var useProcess = codeExecution?.UseProcess ?? false;
+ var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
+
+ return (useLock, useProcess, timeoutSeconds);
+ }
+}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
index 4a39028ed..fd3a89cd3 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
@@ -1,4 +1,5 @@
using BotSharp.Abstraction.Repositories.Filters;
+using BotSharp.Abstraction.Users.Models;
namespace BotSharp.Abstraction.Conversations;
@@ -61,6 +62,4 @@ Task SendMessage(string agentId,
Task SaveStates();
Task> GetConversationStateSearhKeys(ConversationStateKeysFilter filter);
-
- Task MigrateLatestStates(int batchSize = 100, int errorLimit = 10);
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs
index c4235a965..411ca0842 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs
@@ -123,4 +123,4 @@ public class DialogMetaData
[JsonPropertyName("create_at")]
public DateTime CreatedTime { get; set; }
-}
+}
\ No newline at end of file
diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Models/InstructFileModel.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Models/InstructFileModel.cs
index 76de57d68..e6e572563 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Files/Models/InstructFileModel.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Files/Models/InstructFileModel.cs
@@ -31,7 +31,7 @@ public override string ToString()
}
else if (!string.IsNullOrEmpty(FileData))
{
- return FileData.SubstringMax(20);
+ return FileData.SubstringMax(50);
}
return string.Empty;
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/CyperGraphModels.cs b/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/CyperGraphModels.cs
index 3d89488d4..afedc2723 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/CyperGraphModels.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/CyperGraphModels.cs
@@ -9,11 +9,8 @@ public class GraphQueryResult
public class GraphNode
{
public string Id { get; set; } = string.Empty;
-
public List Labels { get; set; } = new();
-
public object Properties { get; set; } = new();
-
public DateTime Time { get; set; } = DateTime.UtcNow;
public override string ToString()
diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs
index 20af9f03c..99cb1c9f4 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs
@@ -61,7 +61,7 @@ Task UpdateRole(Role role, bool updateRoleAgents = false)
Task UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
Task UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
Task UpdateUsersIsDisable(List userIds, bool isDisable) => throw new NotImplementedException();
- ValueTask> GetUsers(UserFilter filter) => throw new NotImplementedException();
+ Task> GetUsers(UserFilter filter) => throw new NotImplementedException();
Task> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
Task GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
Task UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
@@ -99,7 +99,7 @@ Task AppendAgentLabels(string agentId, List labels)
#endregion
#region Agent Task
- ValueTask> GetAgentTasks(AgentTaskFilter filter)
+ Task> GetAgentTasks(AgentTaskFilter filter)
=> throw new NotImplementedException();
Task GetAgentTask(string agentId, string taskId)
=> throw new NotImplementedException();
@@ -143,7 +143,7 @@ Task UpdateConversationStatus(string conversationId, string status)
=> throw new NotImplementedException();
Task GetConversation(string conversationId, bool isLoadStates = false)
=> throw new NotImplementedException();
- ValueTask> GetConversations(ConversationFilter filter)
+ Task> GetConversations(ConversationFilter filter)
=> throw new NotImplementedException();
Task UpdateConversationTitle(string conversationId, string title)
=> throw new NotImplementedException();
@@ -196,7 +196,7 @@ Task> GetConversationStateLogs(str
Task SaveInstructionLogs(IEnumerable logs)
=> throw new NotImplementedException();
- ValueTask> GetInstructionLogs(InstructLogFilter filter)
+ Task> GetInstructionLogs(InstructLogFilter filter)
=> throw new NotImplementedException();
Task> GetInstructionLogSearchKeys(InstructLogKeysFilter filter)
@@ -249,7 +249,7 @@ Task SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData)
///
Task DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null)
=> throw new NotImplementedException();
- ValueTask> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
+ Task> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
=> throw new NotImplementedException();
#endregion
@@ -258,7 +258,7 @@ Task UpsertCrontabItem(CrontabItem cron)
=> throw new NotImplementedException();
Task DeleteCrontabItem(string conversationId)
=> throw new NotImplementedException();
- ValueTask> GetCrontabItems(CrontabItemFilter filter)
+ Task> GetCrontabItems(CrontabItemFilter filter)
=> throw new NotImplementedException();
#endregion
}
diff --git a/src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs b/src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs
index 6d7a20d80..5f68b722d 100644
--- a/src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs
+++ b/src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs
@@ -4,6 +4,7 @@
using BotSharp.Abstraction.Coding.Enums;
using BotSharp.Abstraction.Coding.Models;
using BotSharp.Abstraction.Coding.Settings;
+using BotSharp.Abstraction.Coding.Utils;
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Hooks;
using BotSharp.Abstraction.Models;
@@ -138,7 +139,7 @@ private async Task TriggerCodeScript(Agent agent, string triggerName, Rule
await hook.BeforeCodeExecution(agent, context);
}
- var (useLock, useProcess, timeoutSeconds) = GetCodeExecutionConfig();
+ var (useLock, useProcess, timeoutSeconds) = CodingUtil.GetCodeExecutionConfig(_codingSettings);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
var response = processor.Run(codeScript.Content, options: new()
{
@@ -199,17 +200,5 @@ private List BuildArguments(string? name, JsonDocument? args)
}
return keyValues;
}
-
- private (bool, bool, int) GetCodeExecutionConfig()
- {
- var codeExecution = _codingSettings.CodeExecution;
- var defaultTimeoutSeconds = 3;
-
- var useLock = codeExecution?.UseLock ?? false;
- var useProcess = codeExecution?.UseProcess ?? false;
- var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
-
- return (useLock, useProcess, timeoutSeconds);
- }
#endregion
}
diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Migration.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Migration.cs
deleted file mode 100644
index 6d802f8b1..000000000
--- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Migration.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-using NetTopologySuite.Algorithm;
-using System.Diagnostics;
-
-namespace BotSharp.Core.Conversations.Services;
-
-public partial class ConversationService
-{
- public async Task MigrateLatestStates(int batchSize = 100, int errorLimit = 10)
- {
- var db = _services.GetRequiredService();
- var isSuccess = true;
- var errorCount = 0;
- var batchNum = 0;
- var info = string.Empty;
- var error = string.Empty;
-
-#if DEBUG
- Console.WriteLine($"\r\n#Start migrating Conversation Latest States...\r\n");
-#else
- _logger.LogInformation($"#Start migrating Conversation Latest States...");
-#endif
- var sw = Stopwatch.StartNew();
-
- var convIds = await db.GetConversationsToMigrate(batchSize);
-
- while (!convIds.IsNullOrEmpty())
- {
- batchNum++;
- var innerSw = Stopwatch.StartNew();
-#if DEBUG
- Console.WriteLine($"\r\n#Start migrating Conversation Latest States (batch number: {batchNum})\r\n");
-#else
- _logger.LogInformation($"#Start migrating Conversation Latest States (batch number: {batchNum})");
-#endif
-
- for (int i = 0; i < convIds.Count; i++)
- {
- var convId = convIds.ElementAt(i);
- try
- {
- var done = await db.MigrateConvsersationLatestStates(convId);
- info = $"Conversation {convId} latest states have been migrated ({i + 1}/{convIds.Count})!";
-#if DEBUG
- Console.WriteLine($"\r\n{info}\r\n");
-#else
- _logger.LogInformation($"{info}");
-#endif
- }
- catch (Exception ex)
- {
- errorCount++;
- error = $"Conversation {convId} latest states fail to be migrated! ({i + 1}/{convIds.Count})\r\n{ex.Message}\r\n{ex.InnerException}";
-#if DEBUG
- Console.WriteLine($"\r\n{error}\r\n");
-#else
- _logger.LogError(ex, $"{error}");
-#endif
- }
- }
-
- if (errorCount >= errorLimit)
- {
- error = $"\r\nErrors exceed limit => stop the migration!\r\n";
-#if DEBUG
- Console.WriteLine($"{error}");
-#else
- _logger.LogError($"{error}");
-#endif
- innerSw.Stop();
- isSuccess = false;
- break;
- }
-
- innerSw.Stop();
- info = $"#Done migrating Conversation Latest States (batch number: {batchNum}) " +
- $"(Total time: {innerSw.Elapsed.Hours} hrs, {innerSw.Elapsed.Minutes} mins, {innerSw.Elapsed.Seconds} seconds)";
-#if DEBUG
- Console.WriteLine($"\r\n{info}\r\n");
-#else
- _logger.LogInformation($"{info}");
-#endif
-
- await Task.Delay(100);
- convIds = await db.GetConversationsToMigrate(batchSize);
- }
-
- sw.Stop();
- info = $"#Done with migrating Conversation Latest States! " +
- $"(Total time: {sw.Elapsed.Days} days, {sw.Elapsed.Hours} hrs, {sw.Elapsed.Minutes} mins, {sw.Elapsed.Seconds} seconds)";
-#if DEBUG
- Console.WriteLine($"\r\n{info}\r\n");
-#else
- _logger.LogInformation($"{info}");
-#endif
-
- return isSuccess;
- }
-}
diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
index 8eadeeab4..faab95e2c 100644
--- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
+++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
@@ -1,4 +1,6 @@
using BotSharp.Abstraction.Models;
+using BotSharp.Abstraction.Users.Models;
+using System.Threading.Tasks;
namespace BotSharp.Core.Conversations.Services;
diff --git a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs
index ba4be1678..f78832f3c 100644
--- a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs
+++ b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs
@@ -1,6 +1,7 @@
using BotSharp.Abstraction.Coding;
using BotSharp.Abstraction.Coding.Contexts;
using BotSharp.Abstraction.Coding.Enums;
+using BotSharp.Abstraction.Coding.Utils;
using BotSharp.Abstraction.Files.Options;
using BotSharp.Abstraction.Files.Proccessors;
using BotSharp.Abstraction.Instructs;
@@ -156,7 +157,7 @@ public async Task Execute(
}
// Run code script
- var (useLock, useProcess, timeoutSeconds) = GetCodeExecutionConfig(codingSettings);
+ var (useLock, useProcess, timeoutSeconds) = CodingUtil.GetCodeExecutionConfig(codingSettings);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
var codeResponse = codeProcessor.Run(context.CodeScript?.Content ?? string.Empty, options: new()
{
@@ -350,20 +351,4 @@ private async Task GetChatCompletion(
return result.Content;
}
-
- ///
- /// Returns (useLock, useProcess, timeoutSeconds)
- ///
- ///
- private (bool, bool, int) GetCodeExecutionConfig(CodingSettings settings)
- {
- var codeExecution = settings.CodeExecution;
- var defaultTimeoutSeconds = 3;
-
- var useLock = codeExecution?.UseLock ?? false;
- var useProcess = codeExecution?.UseProcess ?? false;
- var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
-
- return (useLock, useProcess, timeoutSeconds);
- }
}
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
index 91aaf95e7..8f7386308 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs
@@ -6,7 +6,7 @@ namespace BotSharp.Core.Repository;
public partial class FileRepository
{
#region Task
- public async ValueTask> GetAgentTasks(AgentTaskFilter filter)
+ public async Task> GetAgentTasks(AgentTaskFilter filter)
{
if (filter == null)
{
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
index 51e328e93..06b26078b 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
@@ -452,7 +452,7 @@ public async Task GetConversation(string conversationId, bool isLo
return record;
}
- public async ValueTask> GetConversations(ConversationFilter filter)
+ public async Task> GetConversations(ConversationFilter filter)
{
if (filter == null)
{
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Crontab.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Crontab.cs
index b48d9f62c..2e3bb8e06 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Crontab.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Crontab.cs
@@ -63,7 +63,7 @@ public async Task DeleteCrontabItem(string conversationId)
}
- public async ValueTask> GetCrontabItems(CrontabItemFilter filter)
+ public async Task> GetCrontabItems(CrontabItemFilter filter)
{
if (filter == null)
{
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs
index bd22c2731..ad5ff7c7c 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs
@@ -177,7 +177,7 @@ public async Task DeleteKnolwedgeBaseFileMeta(string collectionName, strin
return await Task.FromResult(true);
}
- public async ValueTask> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
+ public async Task> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
{
if (string.IsNullOrWhiteSpace(collectionName)
|| string.IsNullOrWhiteSpace(vectorStoreProvider))
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs
index 624803793..f17c767b4 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs
@@ -263,7 +263,7 @@ public async Task UpdateInstructionLogStates(UpdateInstructionLogStatesMod
return true;
}
- public async ValueTask> GetInstructionLogs(InstructLogFilter filter)
+ public async Task> GetInstructionLogs(InstructLogFilter filter)
{
if (filter == null)
{
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs
index 6ad065983..c60ce7f6a 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs
@@ -111,7 +111,7 @@ public async Task UpdateUserVerified(string userId)
await File.WriteAllTextAsync(path, JsonSerializer.Serialize(user, _options));
}
- public async ValueTask> GetUsers(UserFilter filter)
+ public async Task> GetUsers(UserFilter filter)
{
if (filter == null)
{
diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj
index 41fcf07dc..3c65ccce5 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj
+++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj
@@ -1,4 +1,4 @@
-
+
$(TargetFramework)
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.State.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.State.cs
index be01ca7e3..876bdcb5d 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.State.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.State.cs
@@ -11,14 +11,4 @@ public async Task> GetConversationStateKeys([FromQuery] Conversatio
return keys;
}
#endregion
-
- #region Migrate Latest States
- [HttpPost("/conversation/latest-state/migrate")]
- public async Task MigrateConversationLatestStates([FromBody] MigrateLatestStateRequest request)
- {
- var convService = _services.GetRequiredService();
- var res = await convService.MigrateLatestStates(request.BatchSize, request.ErrorLimit);
- return res;
- }
- #endregion
}
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.cs
index 7ec5c3ae7..65b099f25 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.cs
@@ -25,7 +25,6 @@ public ConversationController(
_services = services;
_user = user;
_jsonOptions = InitJsonOptions(options);
-
}
[HttpPost("/conversation/{agentId}")]
@@ -145,7 +144,7 @@ public async Task> GetDialogs([FromRoute] string
[HttpGet("/conversation/{conversationId}")]
public async Task GetConversation([FromRoute] string conversationId, [FromQuery] bool isLoadStates = false)
{
- var service = _services.GetRequiredService();
+ var convService = _services.GetRequiredService();
var userService = _services.GetRequiredService();
var settings = _services.GetRequiredService();
@@ -158,13 +157,15 @@ public async Task> GetDialogs([FromRoute] string
IsLoadLatestStates = isLoadStates
};
- var conversations = await service.GetConversations(filter);
- var conv = !conversations.Items.IsNullOrEmpty()
- ? ConversationViewModel.FromSession(conversations.Items.First())
- : new();
+ var conversations = await convService.GetConversations(filter);
+ var conversation = conversations.Items?.FirstOrDefault();
+ if (conversation == null)
+ {
+ return new();
+ }
- user = !string.IsNullOrEmpty(conv?.User?.Id)
- ? await userService.GetUser(conv.User.Id)
+ user = !string.IsNullOrEmpty(conversation.UserId)
+ ? await userService.GetUser(conversation.UserId)
: null;
if (user == null)
@@ -180,9 +181,10 @@ public async Task> GetDialogs([FromRoute] string
};
}
- conv.User = UserViewModel.FromUser(user);
- conv.IsRealtimeEnabled = settings?.Assemblies?.Contains("BotSharp.Core.Realtime") ?? false;
- return conv;
+ var conversationView = ConversationViewModel.FromSession(conversation);
+ conversationView.User = UserViewModel.FromUser(user);
+ conversationView.IsRealtimeEnabled = settings?.Assemblies?.Contains("BotSharp.Core.Realtime") ?? false;
+ return conversationView;
}
[HttpPost("/conversation/summary")]
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/Request/InstructMessageModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/Request/InstructMessageModel.cs
index 4aa3c51f1..a56e29e11 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/Request/InstructMessageModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/Request/InstructMessageModel.cs
@@ -10,7 +10,7 @@ public class InstructMessageModel : IncomingMessageModel
public string? Instruction { get; set; }
public override string Channel { get; set; } = ConversationChannel.OpenAPI;
public string? Template { get; set; }
- public List Files { get; set; } = [];
+ public List? Files { get; set; }
public CodeInstructOptions? CodeOptions { get; set; }
public FileInstructOptions? FileOptions { get; set; }
}
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/View/UserViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/View/UserViewModel.cs
index 38596795d..d7b6bf7c1 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/View/UserViewModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/View/UserViewModel.cs
@@ -9,7 +9,7 @@ public class UserViewModel : UserDto
[JsonPropertyName("agent_actions")]
public IEnumerable AgentActions { get; set; } = [];
- public static UserViewModel FromUser(User user)
+ public static UserViewModel FromUser(User? user)
{
if (user == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Controllers/MembaseController.cs b/src/Plugins/BotSharp.Plugin.Membase/Controllers/MembaseController.cs
index b415bb2cf..7e1292346 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Controllers/MembaseController.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Controllers/MembaseController.cs
@@ -1,4 +1,3 @@
-using BotSharp.Plugin.Membase.Models;
using Microsoft.AspNetCore.Http;
namespace BotSharp.Plugin.Membase.Controllers;
diff --git a/src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs b/src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs
index 2368e6283..be7f19ca8 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs
@@ -11,17 +11,17 @@ public class MembasePlugin : IBotSharpPlugin
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
- var dbSettings = new MembaseSettings();
- config.Bind("Membase", dbSettings);
- services.AddSingleton(sp => dbSettings);
+ var settings = new MembaseSettings();
+ config.Bind("Membase", settings);
+ services.AddSingleton(sp => settings);
- services
- .AddRefitClient(new RefitSettings
- {
- AuthorizationHeaderValueGetter = (message, cancellation) =>
- Task.FromResult($"Bearer {dbSettings.ApiKey}")
- })
- .ConfigureHttpClient(c => c.BaseAddress = new Uri(dbSettings.Host));
+ services.AddTransient();
+ services.AddRefitClient(new RefitSettings
+ {
+ CollectionFormat = CollectionFormat.Multi
+ })
+ .AddHttpMessageHandler()
+ .ConfigureHttpClient(c => c.BaseAddress = new Uri(settings.Host));
services.AddScoped();
}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryRequest.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/CypherQueryRequest.cs
similarity index 99%
rename from src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryRequest.cs
rename to src/Plugins/BotSharp.Plugin.Membase/Models/Requests/CypherQueryRequest.cs
index 2a85f1530..b95485d84 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryRequest.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/CypherQueryRequest.cs
@@ -3,15 +3,12 @@ namespace BotSharp.Plugin.Membase.Models;
public class CypherQueryRequest
{
public string Query { get; set; } = string.Empty;
-
public Dictionary Parameters { get; set; } = [];
-
public bool IncludeExecutionPlan { get; set; } = false;
///
/// Whether to profile the query execution.
///
public bool Profile { get; set; } = false;
-
public int? TimeoutMs { get; set; }
}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeCreationModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeCreationModel.cs
new file mode 100644
index 000000000..2b0c0654b
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeCreationModel.cs
@@ -0,0 +1,12 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class EdgeCreationModel
+{
+ public string? Id { get; set; }
+ public string SourceNodeId { get; set; } = null!;
+ public string TargetNodeId { get; set; } = null!;
+ public string Type { get; set; } = null!;
+ public bool Directed { get; set; } = true;
+ public float? Weight { get; set; } = 1.0f;
+ public object? Properties { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeUpdateModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeUpdateModel.cs
new file mode 100644
index 000000000..9cc80123f
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/EdgeUpdateModel.cs
@@ -0,0 +1,6 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class EdgeUpdateModel
+{
+ public object? Properties { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/NodeCreationModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs
similarity index 71%
rename from src/Plugins/BotSharp.Plugin.Membase/Models/NodeCreationModel.cs
rename to src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs
index d32dfd3a6..4cb102c5d 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Models/NodeCreationModel.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs
@@ -5,6 +5,7 @@ public class NodeCreationModel
public string? Id { get; set; }
public string[]? Labels { get; set; }
public object? Properties { get; set; }
+ public EmbeddingInfo? Embedding { get; set; }
public DateTime? Time { get; set; }
public Node ToNode()
@@ -14,7 +15,14 @@ public Node ToNode()
Id = Id,
Labels = Labels?.ToList() ?? new List(),
Properties = Properties ?? new(),
+ Embedding = Embedding,
Time = Time ?? DateTime.UtcNow
};
}
}
+
+public class EmbeddingInfo
+{
+ public string Model { get; set; }
+ public float[] Vector { get; set; }
+}
\ No newline at end of file
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/NodeUpdateModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs
similarity index 85%
rename from src/Plugins/BotSharp.Plugin.Membase/Models/NodeUpdateModel.cs
rename to src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs
index 1a8746552..a97586894 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Models/NodeUpdateModel.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs
@@ -1,5 +1,3 @@
-using System.Text.Json;
-
namespace BotSharp.Plugin.Membase.Models;
public class NodeUpdateModel
@@ -7,6 +5,7 @@ public class NodeUpdateModel
public string Id { get; set; } = null!;
public string[]? Labels { get; set; }
public object? Properties { get; set; }
+ public EmbeddingInfo? Embedding { get; set; }
public DateTime? Time { get; set; }
public Node ToNode()
@@ -16,6 +15,7 @@ public Node ToNode()
Id = Id,
Labels = Labels?.ToList() ?? [],
Properties = Properties ?? new(),
+ Embedding = Embedding,
Time = Time ?? DateTime.UtcNow
};
}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryResponse.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/CypherQueryResponse.cs
similarity index 99%
rename from src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryResponse.cs
rename to src/Plugins/BotSharp.Plugin.Membase/Models/Responses/CypherQueryResponse.cs
index 724704785..91561144a 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Models/CypherQueryResponse.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/CypherQueryResponse.cs
@@ -4,7 +4,6 @@ public class CypherQueryResponse
{
public string[] Columns { get; set; } = [];
public Dictionary[] Data { get; set; } = [];
-
public CypherNotification[] Notifications { get; set; } = [];
public int RowCount { get; set; }
}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Edge.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Edge.cs
new file mode 100644
index 000000000..456e68542
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Edge.cs
@@ -0,0 +1,15 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class Edge
+{
+ public string Id { get; set; } = string.Empty;
+ public string SourceNodeId { get; set; } = string.Empty;
+ public string TargetNodeId { get; set; } = string.Empty;
+ public string Type { get; set; } = string.Empty;
+ public object? Properties { get; set; }
+ public string? Direction { get; set; }
+ public bool? Directed { get; set; }
+ public float? Weight { get; set; }
+ public DateTime? CreatedAt { get; set; }
+ public DateTime? UpdatedAt { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/EdgeDeleteResponse.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/EdgeDeleteResponse.cs
new file mode 100644
index 000000000..d5136fa52
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/EdgeDeleteResponse.cs
@@ -0,0 +1,6 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class EdgeDeleteResponse
+{
+ public string? Message { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/GraphInfo.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/GraphInfo.cs
new file mode 100644
index 000000000..128e7b6ff
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/GraphInfo.cs
@@ -0,0 +1,18 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class GraphInfo
+{
+ public string Id { get; set; } = null!;
+ public string Name { get; set; } = null!;
+ public string? Description { get; set; }
+ public string? Provider { get; set; }
+ public string? Region { get; set; }
+ public bool? SemanticAware { get; set; }
+ public string? DefaultEmbeddingModel { get; set; }
+ public string? OrgId { get; set; }
+ public string? ProjectId { get; set; }
+ public string? CreatedBy { get; set; }
+ public DateTime? CreatedAt { get; set; }
+ public string? UpdatedBy { get; set; }
+ public DateTime? UpdatedAt { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Node.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Node.cs
similarity index 74%
rename from src/Plugins/BotSharp.Plugin.Membase/Models/Node.cs
rename to src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Node.cs
index f1807b019..2a08cc6b7 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Models/Node.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/Node.cs
@@ -1,20 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.Json.Serialization;
-using System.Threading.Tasks;
-
namespace BotSharp.Plugin.Membase.Models;
public class Node
{
public string Id { get; set; } = string.Empty;
-
public List Labels { get; set; } = new();
-
public object Properties { get; set; } = new();
-
+ public EmbeddingInfo? Embedding { get; set; }
public DateTime Time { get; set; } = DateTime.UtcNow;
public override string ToString()
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/NodeDeleteResponse.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/NodeDeleteResponse.cs
new file mode 100644
index 000000000..14f4eeb3f
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Responses/NodeDeleteResponse.cs
@@ -0,0 +1,6 @@
+namespace BotSharp.Plugin.Membase.Models;
+
+public class NodeDeleteResponse
+{
+ public string? Message { get; set; }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Services/IMembaseApi.cs b/src/Plugins/BotSharp.Plugin.Membase/Services/IMembaseApi.cs
index 5455c3457..5f69f387f 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Services/IMembaseApi.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Services/IMembaseApi.cs
@@ -1,6 +1,4 @@
-using BotSharp.Plugin.Membase.Models;
using Refit;
-using System.Threading.Tasks;
namespace BotSharp.Plugin.Membase.Services;
@@ -10,15 +8,19 @@ namespace BotSharp.Plugin.Membase.Services;
///
public interface IMembaseApi
{
- [Post("/cypher/execute?graphId={graphId}")]
- Task CypherQueryAsync(string graphId, CypherQueryRequest request);
+ [Get("/graph/{graphId}")]
+ Task GetGraphInfoAsync(string graphId);
- [Post("/graph/{graphId}/node")]
- Task CreateNodeAsync(string graphId, [Body] NodeCreationModel node);
+ [Post("/cypher/execute")]
+ Task CypherQueryAsync([Query] string graphId, [Body] CypherQueryRequest request);
+ #region Node
[Get("/graph/{graphId}/node/{nodeId}")]
Task GetNodeAsync(string graphId, string nodeId);
+ [Post("/graph/{graphId}/node")]
+ Task CreateNodeAsync(string graphId, [Body] NodeCreationModel node);
+
[Put("/graph/{graphId}/node/{nodeId}")]
Task UpdateNodeAsync(string graphId, string nodeId, [Body] NodeUpdateModel node);
@@ -26,5 +28,20 @@ public interface IMembaseApi
Task MergeNodeAsync(string graphId, string nodeId, [Body] NodeUpdateModel node);
[Delete("/graph/{graphId}/node/{nodeId}")]
- Task DeleteNodeAsync(string graphId, string nodeId);
+ Task DeleteNodeAsync(string graphId, string nodeId);
+ #endregion
+
+ #region Edge
+ [Get("/graph/{graphId}/edge/{edgeId}")]
+ Task GetEdgeAsync(string graphId, string edgeId);
+
+ [Post("/graph/{graphId}/edge")]
+ Task CreateEdgeAsync(string graphId, [Body] EdgeCreationModel edge);
+
+ [Put("/graph/{graphId}/edge/{edgeId}")]
+ Task UpdateEdgeAsync(string graphId, string edgeId, [Body] EdgeUpdateModel edge);
+
+ [Delete("/graph/{graphId}/edge/{edgeId}")]
+ Task DeleteEdgeAsync(string graphId, string edgeId);
+ #endregion
}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseAuthHandler.cs b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseAuthHandler.cs
new file mode 100644
index 000000000..7dea503c8
--- /dev/null
+++ b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseAuthHandler.cs
@@ -0,0 +1,32 @@
+using Microsoft.Extensions.Logging;
+using System.Net.Http;
+using System.Threading;
+
+namespace BotSharp.Plugin.Membase.Services;
+
+public class MembaseAuthHandler : DelegatingHandler
+{
+ private readonly MembaseSettings _settings;
+ private readonly ILogger _logger;
+
+ public MembaseAuthHandler(
+ ILogger logger,
+ MembaseSettings settings)
+ {
+ _logger = logger;
+ _settings = settings;
+ }
+
+ protected override async Task SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken)
+ {
+ requestMessage.Headers.TryAddWithoutValidation("Authorization", $"Bearer {_settings.ApiKey}");
+ var response = await base.SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);
+
+#if DEBUG
+ var rawResponse = await response.Content.ReadAsStringAsync();
+ _logger.LogDebug(rawResponse);
+#endif
+
+ return response;
+ }
+}
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs
index 530ab715c..abd3c0700 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs
@@ -1,7 +1,4 @@
-using BotSharp.Abstraction.Knowledges;
using BotSharp.Abstraction.Knowledges.Models;
-using BotSharp.Plugin.Membase.Models;
-using System.Threading.Tasks;
namespace BotSharp.Plugin.Membase.Services;
diff --git a/src/Plugins/BotSharp.Plugin.Membase/Using.cs b/src/Plugins/BotSharp.Plugin.Membase/Using.cs
index 6f368942d..755fe4fb4 100644
--- a/src/Plugins/BotSharp.Plugin.Membase/Using.cs
+++ b/src/Plugins/BotSharp.Plugin.Membase/Using.cs
@@ -12,5 +12,6 @@
global using BotSharp.Abstraction.Knowledges;
global using BotSharp.Abstraction.Plugins;
global using BotSharp.Abstraction.Settings;
+global using BotSharp.Plugin.Membase.Models;
global using BotSharp.Plugin.Membase.Services;
global using BotSharp.Plugin.Membase.Settings;
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs
index 8fb852390..ac0287316 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs
@@ -12,6 +12,7 @@ public class ConversationDocument : MongoBase
public string Status { get; set; } = default!;
public int DialogCount { get; set; }
public List Tags { get; set; } = [];
+
public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }
public Dictionary LatestStates { get; set; } = new();
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs
index cdd76cb54..49511d7a4 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs
@@ -18,7 +18,7 @@ public class AgentLlmConfigMongoModel
- public static AgentLlmConfigMongoModel? ToMongoElement(AgentLlmConfig? config)
+ public static AgentLlmConfigMongoModel? ToMongoModel(AgentLlmConfig? config)
{
if (config == null)
{
@@ -39,7 +39,7 @@ public class AgentLlmConfigMongoModel
};
}
- public static AgentLlmConfig? ToDomainElement(AgentLlmConfigMongoModel? config)
+ public static AgentLlmConfig? ToDomainModel(AgentLlmConfigMongoModel? config)
{
if (config == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs
index 3c1e14f03..a62971baa 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs
@@ -377,7 +377,7 @@ private async Task UpdateAgentRules(string agentId, List rules)
private async Task UpdateAgentLlmConfig(string agentId, AgentLlmConfig? config)
{
- var llmConfig = AgentLlmConfigMongoModel.ToMongoElement(config);
+ var llmConfig = AgentLlmConfigMongoModel.ToMongoModel(config);
var filter = Builders.Filter.Eq(x => x.Id, agentId);
var update = Builders.Update
.Set(x => x.LlmConfig, llmConfig)
@@ -421,7 +421,7 @@ private async Task UpdateAgentAllFields(Agent agent)
.Set(x => x.McpTools, agent.McpTools.Select(u => AgentMcpToolMongoElement.ToMongoElement(u)).ToList())
.Set(x => x.KnowledgeBases, agent.KnowledgeBases.Select(u => AgentKnowledgeBaseMongoElement.ToMongoElement(u)).ToList())
.Set(x => x.Rules, agent.Rules.Select(e => AgentRuleMongoElement.ToMongoElement(e)).ToList())
- .Set(x => x.LlmConfig, AgentLlmConfigMongoModel.ToMongoElement(agent.LlmConfig))
+ .Set(x => x.LlmConfig, AgentLlmConfigMongoModel.ToMongoModel(agent.LlmConfig))
.Set(x => x.IsPublic, agent.IsPublic)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@@ -640,7 +640,7 @@ public async Task BulkInsertAgents(List agents)
MaxMessageCount = x.MaxMessageCount,
Profiles = x.Profiles ?? [],
Labels = x.Labels ?? [],
- LlmConfig = AgentLlmConfigMongoModel.ToMongoElement(x.LlmConfig),
+ LlmConfig = AgentLlmConfigMongoModel.ToMongoModel(x.LlmConfig),
ChannelInstructions = x.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?.ToList() ?? [],
Templates = x.Templates?.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?.ToList() ?? [],
Functions = x.Functions?.Select(f => FunctionDefMongoElement.ToMongoElement(f))?.ToList() ?? [],
@@ -761,7 +761,7 @@ private Agent TransformAgentDocument(AgentDocument? agentDoc)
Profiles = agentDoc.Profiles ?? [],
Labels = agentDoc.Labels ?? [],
MaxMessageCount = agentDoc.MaxMessageCount,
- LlmConfig = AgentLlmConfigMongoModel.ToDomainElement(agentDoc.LlmConfig),
+ LlmConfig = AgentLlmConfigMongoModel.ToDomainModel(agentDoc.LlmConfig),
ChannelInstructions = agentDoc.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))?.ToList() ?? [],
Templates = agentDoc.Templates?.Select(t => AgentTemplateMongoElement.ToDomainElement(t))?.ToList() ?? [],
Functions = agentDoc.Functions?.Select(f => FunctionDefMongoElement.ToDomainElement(f)).ToList() ?? [],
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
index a222b5915..8a3299372 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs
@@ -7,7 +7,7 @@ namespace BotSharp.Plugin.MongoStorage.Repository;
public partial class MongoRepository
{
#region Task
- public async ValueTask> GetAgentTasks(AgentTaskFilter filter)
+ public async Task> GetAgentTasks(AgentTaskFilter filter)
{
if (filter == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
index ae3383311..300700a64 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
@@ -345,7 +345,7 @@ public async Task GetConversation(string conversationId, bool isLo
};
}
- public async ValueTask> GetConversations(ConversationFilter filter)
+ public async Task> GetConversations(ConversationFilter filter)
{
if (filter == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Crontab.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Crontab.cs
index 2ac676acb..426e163be 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Crontab.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Crontab.cs
@@ -45,7 +45,7 @@ public async Task DeleteCrontabItem(string conversationId)
}
- public async ValueTask> GetCrontabItems(CrontabItemFilter filter)
+ public async Task> GetCrontabItems(CrontabItemFilter filter)
{
if (filter == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs
index 2b5b7daf1..49bbd9223 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs
@@ -181,7 +181,7 @@ public async Task DeleteKnolwedgeBaseFileMeta(string collectionName, strin
return res.DeletedCount > 0;
}
- public async ValueTask> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
+ public async Task> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
{
if (string.IsNullOrWhiteSpace(collectionName)
|| string.IsNullOrWhiteSpace(vectorStoreProvider))
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs
index 1dc042e88..f851d5625 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs
@@ -224,7 +224,7 @@ public async Task UpdateInstructionLogStates(UpdateInstructionLogStatesMod
return true;
}
- public async ValueTask> GetInstructionLogs(InstructLogFilter filter)
+ public async Task> GetInstructionLogs(InstructLogFilter filter)
{
if (filter == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs
index 774b3dae9..a3cd3b928 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs
@@ -206,7 +206,7 @@ public async Task UpdateUsersIsDisable(List userIds, bool isDisable)
}
}
- public async ValueTask> GetUsers(UserFilter filter)
+ public async Task> GetUsers(UserFilter filter)
{
if (filter == null)
{
diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Functions/PyProgrammerFn.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Functions/PyProgrammerFn.cs
index 73277d2ec..ee25b6a0b 100644
--- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Functions/PyProgrammerFn.cs
+++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Functions/PyProgrammerFn.cs
@@ -1,6 +1,5 @@
-using BotSharp.Abstraction.Coding.Settings;
+using BotSharp.Abstraction.Coding.Utils;
using Microsoft.Extensions.Logging;
-using Python.Runtime;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@@ -119,7 +118,7 @@ public async Task Execute(RoleDialogModel message)
return (false, "Unable to execute python code script.");
}
- var (useLock, useProcess, timeoutSeconds) = GetCodeExecutionConfig();
+ var (useLock, useProcess, timeoutSeconds) = CodingUtil.GetCodeExecutionConfig(_codingSettings, defaultTimeoutSeconds: 10);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
var response = processor.Run(codeScript, options: new()
@@ -201,16 +200,4 @@ private AgentLlmConfig GetLlmConfig()
ReasoningEffortLevel = reasoningEffortLevel
};
}
-
- private (bool, bool, int) GetCodeExecutionConfig()
- {
- var codeExecution = _codingSettings.CodeExecution;
- var defaultTimeoutSeconds = 10;
-
- var useLock = codeExecution?.UseLock ?? false;
- var useProcess = codeExecution?.UseProcess ?? false;
- var timeoutSeconds = codeExecution?.TimeoutSeconds > 0 ? codeExecution.TimeoutSeconds : defaultTimeoutSeconds;
-
- return (useLock, useProcess, timeoutSeconds);
- }
}