When chat is ended by Salesforce Agent, it sets a flag in customFields agentEndedFlag to true.
But currently, it is also setting a flag in the case when the visitor ends the chat, which is misleading.
For now to differentiate chat ended by visitor and agent we can check Conversation closed: reason in RC .
It shows Chat closed by visitor.. when the agent closes the chat.
It shows Closed by visitor. when the visitor closes the chat
We are going to fix this confusion separately in #1278
FYI @ear-dev