loadChat method

Future<AgentChat<State>> loadChat({
  1. String? snapshotId,
  2. String? sessionId,
  3. Map<String, dynamic>? context,
})

Loads a server snapshot and returns a chat with history restored. Provide exactly one of snapshotId / sessionId.

Implementation

Future<AgentChat<State>> loadChat({
  String? snapshotId,
  String? sessionId,
  Map<String, dynamic>? context,
}) async {
  assert(
    (snapshotId != null) ^ (sessionId != null),
    'Provide exactly one of snapshotId or sessionId.',
  );
  final snapshot = await _transport.getSnapshot(
    snapshotId: snapshotId,
    sessionId: sessionId,
    context: context,
  );
  if (snapshot == null) {
    final id = snapshotId ?? 'session $sessionId';
    throw StateError('Snapshot $id not found.');
  }
  final chat = AgentChat<State>._(_transport, null, _stateSchema);
  chat._loadFromSnapshot(snapshot);
  return chat;
}