Skip to content

Commit 14db7f1

Browse files
authored
Merge pull request #1343 from visagang/features/vguruparan
fix(AgentController): case-insensitive agentId filtering and null-guard for GetRuleTriggers
2 parents e1de5c5 + 49a252a commit 14db7f1

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Rules/IRuleTrigger.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public interface IRuleTrigger
2121
/// Explain the purpose of rule trigger (display purpose)
2222
/// </summary>
2323
string Statement => string.Empty;
24+
25+
/// <summary>
26+
/// Optional list of agent IDs this trigger is associated with.
27+
/// Used for display/filtering in UI only (not used in execution logic).
28+
/// </summary>
29+
string[]? AgentIds => null;
2430
}

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ namespace BotSharp.OpenAPI.Controllers;
55

66
public partial class AgentController
77
{
8+
[HttpGet("/rule/triggers/{agentId}")]
9+
public ActionResult<IEnumerable<AgentRuleViewModel>> GetRuleTriggers(string agentId)
10+
{
11+
if (string.IsNullOrWhiteSpace(agentId))
12+
{
13+
return BadRequest("agentId is required");
14+
}
15+
16+
var triggers = _services.GetServices<IRuleTrigger>()
17+
.Where(x =>
18+
{
19+
var agentIds = x.AgentIds;
20+
return agentIds == null || agentIds.Contains(agentId, StringComparer.OrdinalIgnoreCase);
21+
});
22+
return Ok(triggers.Select(x => new AgentRuleViewModel
23+
{
24+
TriggerName = x.Name,
25+
Channel = x.Channel,
26+
Statement = x.Statement,
27+
OutputArgs = x.OutputArgs
28+
}).OrderBy(x => x.TriggerName));
29+
}
30+
831
[HttpGet("/rule/triggers")]
932
public IEnumerable<AgentRuleViewModel> GetRuleTriggers()
1033
{

0 commit comments

Comments
 (0)