run static method
Runs call as the audited call of the tool toolName, appending the
call's entries to context's log when it ends however it ends.
Implementation
static FutureOr<Object?> run(
String toolName,
AgentToolContext context,
Map<String, Object?> raw,
FutureOr<Object?> Function() call,
) {
final recording = AgentAuditRecording._(toolName, context, raw);
final FutureOr<Object?> result;
try {
result = runZoned(
call,
zoneValues: {
...context.callZoneValues(recording),
_recordingKey: recording,
},
);
} catch (error) {
recording._finish(error);
rethrow;
}
if (result is Future<Object?>) {
return result.then(
(value) {
recording._finish(null);
return value;
},
onError: (Object error, StackTrace stack) {
recording._finish(error);
Error.throwWithStackTrace(error, stack);
},
);
}
recording._finish(null);
return result;
}