The commented and lastCommented JQL functions support predicates like roleLevel and groupLevel to determine whether a comment was restricted using JIRA's out-of-the-box features for restricting access to a comment.
However, JIRA Service Desk uses its own entity property, sd.public.comment, to determine whether a comment is internal or external. See https://answers.atlassian.com/questions/14212548/answers/14212563 and
SRJIRA-2009 for some examples of accessing this property.
It would be helpful if commented and lastCommented supported the visibility property in their query syntax. There would need to be a check for whether JIRA service Desk was installed, among other things.