replaceSession method
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);
}