record method

Future<HistoryEntry> record({
  1. required String sessionId,
  2. required HistoryEntryType type,
  3. required String role,
  4. required String content,
  5. Map<String, dynamic>? metadata,
  6. String? toolName,
  7. String? toolId,
  8. int? tokenCount,
  9. double? cost,
  10. Duration? latency,
  11. String? parentId,
  12. int turnIndex = 0,
})

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;
}