Add ITool + ToolRegistry + GetCurrentTimeTool
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
namespace backend.Tools;
|
||||
|
||||
public class ToolRegistry
|
||||
{
|
||||
private readonly Dictionary<string, ITool> _byName;
|
||||
private readonly List<ITool> _all;
|
||||
|
||||
public ToolRegistry(IEnumerable<ITool> tools)
|
||||
{
|
||||
_all = tools.ToList();
|
||||
_byName = _all.ToDictionary(t => t.Name);
|
||||
}
|
||||
|
||||
public IReadOnlyList<ITool> All => _all;
|
||||
|
||||
public ITool? Get(string name) => _byName.GetValueOrDefault(name);
|
||||
|
||||
public IEnumerable<ITool> EnabledFor(IReadOnlySet<string> enabled)
|
||||
=> _all.Where(t => enabled.Contains(t.Name));
|
||||
}
|
||||
Reference in New Issue
Block a user