forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentController.Rule.cs
More file actions
53 lines (47 loc) · 1.64 KB
/
AgentController.Rule.cs
File metadata and controls
53 lines (47 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using BotSharp.Abstraction.Rules;
using BotSharp.Abstraction.Rules.Models;
namespace BotSharp.OpenAPI.Controllers;
public partial class AgentController
{
[HttpGet("/rule/triggers/{agentId}")]
public IEnumerable<AgentRuleViewModel> GetRuleTriggers(string agentId)
{
var triggers = _services.GetServices<IRuleTrigger>();
triggers = triggers.Where(x => x.AgentIds?.Count() == 0 || x.AgentIds.Contains(agentId));
return triggers.Select(x => new AgentRuleViewModel
{
TriggerName = x.Name,
Channel = x.Channel,
Statement = x.Statement,
OutputArgs = x.OutputArgs
}).OrderBy(x => x.TriggerName);
}
[HttpGet("/rule/triggers")]
public IEnumerable<AgentRuleViewModel> GetRuleTriggers()
{
var triggers = _services.GetServices<IRuleTrigger>();
return triggers.Select(x => new AgentRuleViewModel
{
TriggerName = x.Name,
Channel = x.Channel,
Statement = x.Statement,
OutputArgs = x.OutputArgs
}).OrderBy(x => x.TriggerName);
}
[HttpGet("/rule/config/options")]
public async Task<IDictionary<string, RuleConfigModel>> GetRuleConfigOptions()
{
var dict = new Dictionary<string, RuleConfigModel>();
var flows = _services.GetServices<IRuleFlow<RuleGraph>>();
foreach (var flow in flows)
{
var config = await flow.GetTopologyConfigAsync();
if (string.IsNullOrEmpty(config.TopologyName))
{
continue;
}
dict[config.TopologyName] = config;
}
return dict;
}
}