replaceSession method

JsonMap replaceSession(
  1. String threadId,
  2. String agentId, {
  3. required String reason,
  4. String? externalRef,
})

Ends the current session of threadId with reason and starts a new one, bound to externalRef when given (resetAgentSession, bindAgentSession).

Implementation

JsonMap replaceSession(
  String threadId,
  String agentId, {
  required String reason,
  String? externalRef,
}) {
  for (final s in sessions.putIfAbsent(threadId, () => [])) {
    if (s['is_current'] == true) {
      s
        ..['is_current'] = false
        ..['ended_at'] = world.stamp()
        ..['end_reason'] = reason
        ..['version'] = (s['version']! as int) + 1;
    }
  }
  return _newSession(threadId, agentId, externalRef: externalRef);
}