Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Coding/Utils/CodingUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace BotSharp.Abstraction.Coding.Utils;

public static class CodingUtil
{
/// <summary>
/// Get code execution config => (useLock, useProcess, timeout seconds)
/// </summary>
/// <param name="settings"></param>
/// <param name="defaultTimeoutSeconds"></param>
/// <returns></returns>
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BotSharp.Abstraction.Repositories.Filters;
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.Abstraction.Conversations;

Expand Down Expand Up @@ -61,6 +62,4 @@ Task<bool> SendMessage(string agentId,
Task SaveStates();

Task<List<string>> GetConversationStateSearhKeys(ConversationStateKeysFilter filter);

Task<bool> MigrateLatestStates(int batchSize = 100, int errorLimit = 10);
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ public class DialogMetaData

[JsonPropertyName("create_at")]
public DateTime CreatedTime { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override string ToString()
}
else if (!string.IsNullOrEmpty(FileData))
{
return FileData.SubstringMax(20);
return FileData.SubstringMax(50);
}
return string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ public class GraphQueryResult
public class GraphNode
{
public string Id { get; set; } = string.Empty;

public List<string> Labels { get; set; } = new();

public object Properties { get; set; } = new();

public DateTime Time { get; set; } = DateTime.UtcNow;

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Task<List<User>> GetUsersByAffiliateId(string affiliateId) => throw new NotImplementedException();
Task<User?> GetUserByUserName(string userName) => throw new NotImplementedException();
Task UpdateUserName(string userId, string userName) => throw new NotImplementedException();
Task<Dashboard?> GetDashboard(string id = null) => throw new NotImplementedException();

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Cannot convert null literal to non-nullable reference type.
Task CreateUser(User user) => throw new NotImplementedException();
Task UpdateExistUser(string userId, User user) => throw new NotImplementedException();
Task UpdateUserVerified(string userId) => throw new NotImplementedException();
Expand All @@ -61,7 +61,7 @@
Task UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
Task UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
Task UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
ValueTask<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
Task<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
Task<List<User>> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
Task<User?> GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
Task<bool> UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
Expand Down Expand Up @@ -99,7 +99,7 @@
#endregion

#region Agent Task
ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
Task<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
=> throw new NotImplementedException();
Task<AgentTask?> GetAgentTask(string agentId, string taskId)
=> throw new NotImplementedException();
Expand Down Expand Up @@ -143,7 +143,7 @@
=> throw new NotImplementedException();
Task<Conversation> GetConversation(string conversationId, bool isLoadStates = false)
=> throw new NotImplementedException();
ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
=> throw new NotImplementedException();
Task UpdateConversationTitle(string conversationId, string title)
=> throw new NotImplementedException();
Expand Down Expand Up @@ -196,7 +196,7 @@
Task<bool> SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
=> throw new NotImplementedException();

ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
Task<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
=> throw new NotImplementedException();

Task<List<string>> GetInstructionLogSearchKeys(InstructLogKeysFilter filter)
Expand Down Expand Up @@ -249,7 +249,7 @@
/// <returns></returns>
Task<bool> DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null)
=> throw new NotImplementedException();
ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
Task<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
=> throw new NotImplementedException();
#endregion

Expand All @@ -258,7 +258,7 @@
=> throw new NotImplementedException();
Task<bool> DeleteCrontabItem(string conversationId)
=> throw new NotImplementedException();
ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
Task<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
=> throw new NotImplementedException();
#endregion
}
15 changes: 2 additions & 13 deletions src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,7 +139,7 @@ private async Task<bool> 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()
{
Expand Down Expand Up @@ -199,17 +200,5 @@ private List<KeyValue> 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
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using BotSharp.Abstraction.Models;
using BotSharp.Abstraction.Users.Models;
using System.Threading.Tasks;

namespace BotSharp.Core.Conversations.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -156,7 +157,7 @@ public async Task<InstructResult> 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()
{
Expand Down Expand Up @@ -350,20 +351,4 @@ private async Task<string> GetChatCompletion(

return result.Content;
}

/// <summary>
/// Returns (useLock, useProcess, timeoutSeconds)
/// </summary>
/// <returns></returns>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BotSharp.Core.Repository;
public partial class FileRepository
{
#region Task
public async ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
public async Task<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
{
if (filter == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public async Task<Conversation> GetConversation(string conversationId, bool isLo
return record;
}

public async ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
public async Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
{
if (filter == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<bool> DeleteCrontabItem(string conversationId)
}


public async ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
public async Task<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
{
if (filter == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task<bool> DeleteKnolwedgeBaseFileMeta(string collectionName, strin
return await Task.FromResult(true);
}

public async ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
public async Task<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
{
if (string.IsNullOrWhiteSpace(collectionName)
|| string.IsNullOrWhiteSpace(vectorStoreProvider))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public async Task<bool> UpdateInstructionLogStates(UpdateInstructionLogStatesMod
return true;
}

public async ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
public async Task<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
{
if (filter == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task UpdateUserVerified(string userId)
await File.WriteAllTextAsync(path, JsonSerializer.Serialize(user, _options));
}

public async ValueTask<PagedItems<User>> GetUsers(UserFilter filter)
public async Task<PagedItems<User>> GetUsers(UserFilter filter)
{
if (filter == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TargetFramework)</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,4 @@ public async Task<List<string>> GetConversationStateKeys([FromQuery] Conversatio
return keys;
}
#endregion

#region Migrate Latest States
[HttpPost("/conversation/latest-state/migrate")]
public async Task<bool> MigrateConversationLatestStates([FromBody] MigrateLatestStateRequest request)
{
var convService = _services.GetRequiredService<IConversationService>();
var res = await convService.MigrateLatestStates(request.BatchSize, request.ErrorLimit);
return res;
}
#endregion
}
Loading
Loading