Skip to content

Commit 7bb63bc

Browse files
authored
Merge pull request #810 from hchen2020/master
rules
2 parents a13f925 + 2dbe6c4 commit 7bb63bc

File tree

19 files changed

+124
-23
lines changed

19 files changed

+124
-23
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ public class BuiltInAgentId
5050
/// <summary>
5151
/// Translates user-defined natural language rules into programmatic code
5252
/// </summary>
53-
public const string RuleEncoder = "6acfb93c-3412-402e-9ba5-c5d3cd8f0161";
53+
public const string RulesInterpreter = "201e49a2-40b3-4ccd-b8cc-2476565a1b40";
5454
}

src/Infrastructure/BotSharp.Core.Crontab/BotSharp.Core.Crontab.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>$(TargetFramework)</TargetFramework>
5+
<LangVersion>$(LangVersion)</LangVersion>
6+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
7+
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
8+
<OutputPath>$(SolutionDir)packages</OutputPath>
59
<ImplicitUsings>enable</ImplicitUsings>
610
<Nullable>enable</Nullable>
711
</PropertyGroup>

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabWatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2424
{
2525
var locker = scope.ServiceProvider.GetRequiredService<IDistributedLocker>();
2626

27-
while (!stoppingToken.IsCancellationRequested)
27+
/*while (!stoppingToken.IsCancellationRequested)
2828
{
2929
var delay = Task.Delay(1000, stoppingToken);
3030
@@ -34,7 +34,7 @@ await locker.LockAsync("CrontabWatcher", async () =>
3434
});
3535
3636
await delay;
37-
}
37+
}*/
3838

3939
_logger.LogWarning("Crontab Watcher background service is stopped.");
4040
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace BotSharp.Core.Rules.Actions;
2+
3+
public interface IRuleAction
4+
{
5+
}

src/Infrastructure/BotSharp.Core.Rules/BotSharp.Core.Rules.csproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>$(TargetFramework)</TargetFramework>
5+
<LangVersion>$(LangVersion)</LangVersion>
6+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
7+
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
8+
<OutputPath>$(SolutionDir)packages</OutputPath>
59
<ImplicitUsings>enable</ImplicitUsings>
610
<Nullable>enable</Nullable>
711
</PropertyGroup>
812

13+
<ItemGroup>
14+
<Content Include="data\agents\201e49a2-40b3-4ccd-b8cc-2476565a1b40\agent.json">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</Content>
17+
<Content Include="data\agents\201e49a2-40b3-4ccd-b8cc-2476565a1b40\instructions\instruction.liquid">
18+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
19+
</Content>
20+
<Content Include="data\agents\201e49a2-40b3-4ccd-b8cc-2476565a1b40\templates\criteria_check.liquid">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</Content>
23+
</ItemGroup>
24+
925
<ItemGroup>
1026
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
1127
</ItemGroup>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace BotSharp.Core.Rules.Criterias;
2+
3+
public interface IRuleCriteria
4+
{
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using BotSharp.Core.Rules.Triggers;
2+
3+
namespace BotSharp.Core.Rules.Engines;
4+
5+
public interface IRuleEngine
6+
{
7+
Task Triggered(IRuleTrigger trigger, string data);
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using BotSharp.Core.Rules.Triggers;
2+
3+
namespace BotSharp.Core.Rules.Engines;
4+
5+
public class RuleEngine : IRuleEngine
6+
{
7+
private readonly IServiceProvider _services;
8+
public RuleEngine(IServiceProvider services)
9+
{
10+
_services = services;
11+
}
12+
13+
public async Task Triggered(IRuleTrigger trigger, string data)
14+
{
15+
// Pull all user defined rules
16+
17+
var instructService = _services.GetRequiredService<IInstructService>();
18+
19+
var userSay = $"===Input data===\r\n{data}\r\n\r\nWhen WO NTE is greater than 100, notify resident.";
20+
21+
var result = await instructService.Execute(BuiltInAgentId.RulesInterpreter, new RoleDialogModel(AgentRole.User, data), "criteria_check", "#TEMPLATE#");
22+
23+
string[] rules = [];
24+
// Check if meet the criteria
25+
}
26+
}

src/Infrastructure/BotSharp.Core.Rules/RulesPlugin.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Core.Rules.Engines;
2+
13
namespace BotSharp.Core.Rules;
24

35
public class RulesPlugin : IBotSharpPlugin
@@ -9,11 +11,11 @@ public class RulesPlugin : IBotSharpPlugin
911

1012
public string[] AgentIds =
1113
[
12-
BuiltInAgentId.RuleEncoder
14+
BuiltInAgentId.RulesInterpreter
1315
];
1416

1517
public void RegisterDI(IServiceCollection services, IConfiguration config)
1618
{
17-
19+
services.AddScoped<IRuleEngine, RuleEngine>();
1820
}
1921
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace BotSharp.Core.Rules.Triggers;
2+
3+
public interface IRuleTrigger
4+
{
5+
string Channel => throw new NotImplementedException("Please set the channel of trigger");
6+
7+
string EventName { get; set; }
8+
string EntityType { get; set; }
9+
10+
string EntityId { get; set; }
11+
}

0 commit comments

Comments
 (0)