Path: redb-route/redb.Route.Llm/Tools/ToolFilter.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Llm/Tools/ToolFilter.cs
----
using redb.Route.Llm.Abstractions.Tools;
namespace redb.Route.Llm.Tools;
///
/// Resolves the per-call tool list from a registry given a CSV/wildcard filter.
/// Centralises the parsing rules so URI options, the inline DSL builder and the
/// consumer all behave the same.
///
internal static class ToolFilter
{
///
/// Resolves the tool list for a single call.
///
/// Registry to read from. May be null when DI is incomplete.
///
/// null/empty \u2014 no tools (default; explicit opt-in);
/// "*" \u2014 every descriptor in the registry;
/// CSV of names \u2014 only the named descriptors (missing names are skipped silently).
///
public static IReadOnlyList Resolve(
IToolDescriptorRegistry? registry,
string? filter)
{
if (registry is null) return [];
if (string.IsNullOrWhiteSpace(filter)) return [];
if (filter.Trim() == "*") return registry.All();
var names = filter
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (names.Length == 0) return [];
var result = new List(names.Length);
foreach (var name in names)
{
var descriptor = registry.Get(name);
if (descriptor is not null) result.Add(descriptor);
}
return result;
}
}