toolCallMatches function

bool toolCallMatches(
  1. List<ToolCall> calls,
  2. Map<String, Object?>? expect
)

One call with the expected name whose every expected argument contains one of its fragments, ignoring case; a null expect wants no call.

Implementation

bool toolCallMatches(List<ToolCall> calls, Map<String, Object?>? expect) {
  if (expect == null) return calls.isEmpty;
  if (calls.length != 1 || calls.single.name != expect['name']) return false;
  final args = calls.single.arguments;
  for (final MapEntry(:key, :value)
      in (expect['arguments'] as Map<String, Object?>).entries) {
    final actual = (args[key] ?? '').toLowerCase();
    if (!(value as List).cast<String>().any(actual.contains)) return false;
  }
  return true;
}