record method
Record a new history entry.
Implementation
Future<HistoryEntry> record({
required String sessionId,
required HistoryEntryType type,
required String role,
required String content,
Map<String, dynamic>? metadata,
String? toolName,
String? toolId,
int? tokenCount,
double? cost,
Duration? latency,
String? parentId,
int turnIndex = 0,
}) async {
final entry = HistoryEntry(
id: _nextId(),
sessionId: sessionId,
type: type,
timestamp: DateTime.now(),
role: role,
content: content,
metadata: metadata,
toolName: toolName,
toolId: toolId,
tokenCount: tokenCount,
cost: cost,
latency: latency,
parentId: parentId,
turnIndex: turnIndex,
);
// Update cache.
_sessionCache.putIfAbsent(sessionId, () => []).add(entry);
// Queue for disk write.
_pendingWrites.add(entry);
// Notify listeners.
_entryStream.add(entry);
// Update session summary.
_updateSummary(entry);
return entry;
}