restoreSessionStateFromLog function

void restoreSessionStateFromLog(
  1. ResumeLoadResult result,
  2. void setAppState(
    1. void (
      1. Map<String, dynamic>
      )
    )
)

Restore session state (file history, attribution, todos) from log.

Implementation

void restoreSessionStateFromLog(
  ResumeLoadResult result,
  void Function(void Function(Map<String, dynamic>)) setAppState,
) {
  // Restore file history state.
  if (result.fileHistorySnapshots != null &&
      result.fileHistorySnapshots!.isNotEmpty) {
    setAppState((prev) {
      prev['fileHistory'] = result.fileHistorySnapshots;
    });
  }

  // Restore attribution state.
  if (result.attributionSnapshots != null &&
      result.attributionSnapshots!.isNotEmpty) {
    setAppState((prev) {
      prev['attribution'] = result.attributionSnapshots;
    });
  }

  // Restore TodoWrite state from transcript.
  if (result.messages.isNotEmpty) {
    final todos = extractTodosFromTranscript(result.messages);
    if (todos.isNotEmpty) {
      setAppState((prev) {
        final todosMap = (prev['todos'] as Map<String, dynamic>?) ?? {};
        todosMap['default'] = todos;
        prev['todos'] = todosMap;
      });
    }
  }
}