2023-10-20 23:57:45 +00:00
|
|
|
using BotSharp.Abstraction.Routing.Settings;
|
|
|
|
|
|
2023-10-02 20:16:35 +00:00
|
|
|
namespace BotSharp.Abstraction.Routing.Models;
|
|
|
|
|
|
|
|
|
|
public class RoutingContext
|
|
|
|
|
{
|
2023-10-20 23:57:45 +00:00
|
|
|
private readonly RoutingSettings _setting;
|
|
|
|
|
public RoutingContext(RoutingSettings setting)
|
|
|
|
|
{
|
|
|
|
|
_setting = setting;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 20:16:35 +00:00
|
|
|
private Stack<string> _stack { get; set; }
|
|
|
|
|
= new Stack<string>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Intent name
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string IntentName { get; set; }
|
|
|
|
|
|
2023-10-27 01:23:06 +00:00
|
|
|
/// <summary>
|
2024-01-13 21:17:40 +00:00
|
|
|
/// Agent that can handle user original goal.
|
2023-10-27 01:23:06 +00:00
|
|
|
/// </summary>
|
2023-10-02 20:16:35 +00:00
|
|
|
public string OriginAgentId
|
2024-01-13 21:17:40 +00:00
|
|
|
=> _stack.Where(x => !_setting.AgentIds.Contains(x)).Last();
|
2023-10-02 20:16:35 +00:00
|
|
|
|
2023-10-29 01:54:10 +00:00
|
|
|
public bool IsEmpty => !_stack.Any();
|
2023-10-20 23:57:45 +00:00
|
|
|
public string GetCurrentAgentId()
|
|
|
|
|
{
|
|
|
|
|
return _stack.Peek();
|
|
|
|
|
}
|
2023-10-02 20:16:35 +00:00
|
|
|
|
|
|
|
|
public void Push(string agentId)
|
|
|
|
|
{
|
|
|
|
|
if (_stack.Count == 0 || _stack.Peek() != agentId)
|
|
|
|
|
{
|
|
|
|
|
_stack.Push(agentId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pop current agent
|
|
|
|
|
/// </summary>
|
2023-10-29 01:54:10 +00:00
|
|
|
public void Pop()
|
2023-10-02 20:16:35 +00:00
|
|
|
{
|
2023-10-29 01:54:10 +00:00
|
|
|
_stack.Pop();
|
|
|
|
|
}
|
2023-10-02 20:16:35 +00:00
|
|
|
|
2023-10-29 01:54:10 +00:00
|
|
|
public void Empty()
|
|
|
|
|
{
|
|
|
|
|
_stack.Clear();
|
2023-10-02 20:16:35 +00:00
|
|
|
}
|
|
|
|
|
}
|