trackMessage method
Track a new message for extraction threshold tracking.
Implementation
void trackMessage(Message message) {
// Rough token estimate
final tokens = message.content.fold<int>(0, (sum, block) {
return sum +
switch (block) {
TextBlock(text: final t) => (t.length / 4).ceil(),
ToolUseBlock(name: final n, input: final i) =>
(n.length / 4).ceil() + (i.toString().length / 4).ceil(),
ToolResultBlock(content: final c) => (c.length / 4).ceil(),
ImageBlock() => 2000,
};
});
_state.tokensSinceLastExtraction += tokens;
// Count tool calls
final toolUses = message.toolUses.length;
_state.toolCallsSinceLastExtraction += toolUses;
}