<commit_before>import {Diff, AnnotationDetails, visitDiff} from '@sanity/field/diff'

export function collectLatestAuthorAnnotations(diff: Diff): AnnotationDetails[] {
  const authorMap = new Map<string, AnnotationDetails>()
  visitDiff(diff, child => {
    if (child.action === 'unchanged' || !('annotation' in child) || !child.annotation) {
      return true
    }

    const {author, timestamp} = child.annotation
    const previous = authorMap.get(author)
    if (!previous || previous.timestamp < timestamp) {
      authorMap.set(author, child.annotation)
    }

    return true
  })

  return Array.from(authorMap.values())
}<commit_msg>[desk-tool] Sort latest author annotations by timestamp<commit_after>import {Diff, AnnotationDetails, visitDiff} from '@sanity/field/diff'

export function collectLatestAuthorAnnotations(diff: Diff): AnnotationDetails[] {
  const authorMap = new Map<string, AnnotationDetails>()
  visitDiff(diff, child => {
    if (child.action === 'unchanged' || !('annotation' in child) || !child.annotation) {
      return true
    }

    const {author, timestamp} = child.annotation
    const previous = authorMap.get(author)
    if (!previous || previous.timestamp < timestamp) {
      authorMap.set(author, child.annotation)
    }

    return true
  })

  return Array.from(authorMap.values()).sort(
    (a, b) => Date.parse(b.timestamp) - Date.parse(a.timestamp)
  )
}
{'fraction_non_alphanumeric': 0.1326676176890157, 'fraction_numerical': 0.0, 'mean_word_length': 4.13919413919414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565252', 'n_tokens_mistral': 411, 'n_tokens_neox': 401, 'n_words': 98}