redactionHooks function
Builds the agent hooks that redact redactor's values:
afterToolCallmasks TextContent blocks of every tool result before it enters the transcript (and therefore the session JSONL).transformContextmasks text in the message list sent to the provider (belt-and-braces: user messages, assistant text/thinking, and any tool result that bypassedafterToolCall).
Implementation
RedactionHooks redactionHooks(SecretRedactor redactor) {
AfterToolCallResult? afterToolCall(
AfterToolCallContext context,
CancelToken? cancelToken,
) {
var changed = false;
final content = [
for (final block in context.result.content)
_redactBlock(redactor, block, onChange: () => changed = true),
];
return changed ? AfterToolCallResult(content: content) : null;
}
List<Message> transformContext(
List<Message> messages,
CancelToken? cancelToken,
) {
return [for (final message in messages) _redactMessage(redactor, message)];
}
return (afterToolCall: afterToolCall, transformContext: transformContext);
}