Skip to content

Commit 17beef2

Browse files
author
Jicheng Lu
committed
add incoming edge
1 parent ad26a85 commit 17beef2

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/Infrastructure/BotSharp.Abstraction/Rules/Hooks/IRuleTriggerHook.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace BotSharp.Abstraction.Rules.Hooks;
55

66
public interface IRuleTriggerHook : IHookBase
77
{
8-
Task BeforeRuleConditionExecuting(Agent agent, RuleNode conditionNode, IRuleTrigger trigger, RuleFlowContext context) => Task.CompletedTask;
9-
Task AfterRuleConditionExecuted(Agent agent, RuleNode conditionNode, IRuleTrigger trigger, RuleFlowContext context, RuleNodeResult result) => Task.CompletedTask;
8+
Task BeforeRuleConditionExecuting(Agent agent, RuleNode conditionNode, RuleEdge incomingEdge, IRuleTrigger trigger, RuleFlowContext context) => Task.CompletedTask;
9+
Task AfterRuleConditionExecuted(Agent agent, RuleNode conditionNode, RuleEdge incomingEdge, IRuleTrigger trigger, RuleFlowContext context, RuleNodeResult result) => Task.CompletedTask;
1010

11-
Task BeforeRuleActionExecuting(Agent agent, RuleNode actionNode, IRuleTrigger trigger, RuleFlowContext context) => Task.CompletedTask;
12-
Task AfterRuleActionExecuted(Agent agent, RuleNode actionNode, IRuleTrigger trigger, RuleFlowContext context, RuleNodeResult result) => Task.CompletedTask;
11+
Task BeforeRuleActionExecuting(Agent agent, RuleNode actionNode, RuleEdge incomingEdge, IRuleTrigger trigger, RuleFlowContext context) => Task.CompletedTask;
12+
Task AfterRuleActionExecuted(Agent agent, RuleNode actionNode, RuleEdge incomingEdge, IRuleTrigger trigger, RuleFlowContext context, RuleNodeResult result) => Task.CompletedTask;
1313
}

src/Infrastructure/BotSharp.Core.Rules/Conditions/LoopingCondition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ private void CleanLoopState(RuleFlowContext context)
158158
context.Parameters?.Remove(PARAM_ITERATE_INDEX);
159159
context.Parameters?.Remove(PARAM_ITERATE_ITEM_KEY);
160160
context.Parameters?.Remove(PARAM_ITERATE_NEXT_ITEM);
161+
context.Parameters?.Remove(PARAM_LIST_ITEMS_KEY);
161162

162163
if (!string.IsNullOrEmpty(itemKey))
163164
{

src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private async Task ExecuteGraphNodeDfs(
228228
if (RuleConstant.CONDITION_NODE_TYPES.Contains(nextNode.Type))
229229
{
230230
// Execute condition node
231-
var conditionResult = await ExecuteCondition(nextNode, graph, agent, trigger, context);
231+
var conditionResult = await ExecuteCondition(nextNode, edge, graph, agent, trigger, context);
232232
if (conditionResult == null)
233233
{
234234
results.Add(RuleFlowStepResult.FromResult(new()
@@ -255,7 +255,7 @@ private async Task ExecuteGraphNodeDfs(
255255
else if (RuleConstant.ACTION_NODE_TYPES.Contains(nextNode.Type))
256256
{
257257
// Execute action node
258-
var actionResult = await ExecuteAction(nextNode, graph, agent, trigger, context);
258+
var actionResult = await ExecuteAction(nextNode, edge, graph, agent, trigger, context);
259259
if (actionResult == null)
260260
{
261261
results.Add(RuleFlowStepResult.FromResult(new()
@@ -337,7 +337,7 @@ private async Task ExecuteGraphNodeBfs(
337337
if (RuleConstant.CONDITION_NODE_TYPES.Contains(nextNode.Type))
338338
{
339339
// Execute condition node
340-
var conditionResult = await ExecuteCondition(nextNode, graph, agent, trigger, context);
340+
var conditionResult = await ExecuteCondition(nextNode, nextEdge, graph, agent, trigger, context);
341341
innerData = new(context.Parameters ?? []);
342342

343343
if (conditionResult == null)
@@ -369,7 +369,7 @@ private async Task ExecuteGraphNodeBfs(
369369
else if (RuleConstant.ACTION_NODE_TYPES.Contains(nextNode.Type))
370370
{
371371
// Execute action node
372-
var actionResult = await ExecuteAction(nextNode, graph, agent, trigger, context);
372+
var actionResult = await ExecuteAction(nextNode, nextEdge, graph, agent, trigger, context);
373373
innerData = new(context.Parameters ?? []);
374374

375375
if (actionResult == null)
@@ -413,6 +413,7 @@ private async Task ExecuteGraphNodeBfs(
413413
#region Action
414414
private async Task<RuleNodeResult?> ExecuteAction(
415415
RuleNode node,
416+
RuleEdge incomingEdge,
416417
RuleGraph graph,
417418
Agent agent,
418419
IRuleTrigger trigger,
@@ -435,7 +436,7 @@ private async Task ExecuteGraphNodeBfs(
435436
var hooks = _services.GetHooks<IRuleTriggerHook>(agent.Id);
436437
foreach (var hook in hooks)
437438
{
438-
await hook.BeforeRuleActionExecuting(agent, node, trigger, context);
439+
await hook.BeforeRuleActionExecuting(agent, node, incomingEdge, trigger, context);
439440
}
440441

441442
// Execute action
@@ -444,7 +445,7 @@ private async Task ExecuteGraphNodeBfs(
444445

445446
foreach (var hook in hooks)
446447
{
447-
await hook.AfterRuleActionExecuted(agent, node, trigger, context, result);
448+
await hook.AfterRuleActionExecuted(agent, node, incomingEdge, trigger, context, result);
448449
}
449450

450451
return result;
@@ -499,6 +500,7 @@ private async Task ExecuteGraphNodeBfs(
499500
#region Condition
500501
private async Task<RuleNodeResult?> ExecuteCondition(
501502
RuleNode node,
503+
RuleEdge incomingEdge,
502504
RuleGraph graph,
503505
Agent agent,
504506
IRuleTrigger trigger,
@@ -521,7 +523,7 @@ private async Task ExecuteGraphNodeBfs(
521523
var hooks = _services.GetHooks<IRuleTriggerHook>(agent.Id);
522524
foreach (var hook in hooks)
523525
{
524-
await hook.BeforeRuleConditionExecuting(agent, node, trigger, context);
526+
await hook.BeforeRuleConditionExecuting(agent, node, incomingEdge, trigger, context);
525527
}
526528

527529
// Execute condition
@@ -530,7 +532,7 @@ private async Task ExecuteGraphNodeBfs(
530532

531533
foreach (var hook in hooks)
532534
{
533-
await hook.AfterRuleConditionExecuted(agent, node, trigger, context, result);
535+
await hook.AfterRuleConditionExecuted(agent, node, incomingEdge, trigger, context, result);
534536
}
535537

536538
return result;

0 commit comments

Comments
 (0)