function normalizeMessageId(value: unknown): string {
  return String(value ?? '').trim()
}

export function isCompactTranscriptMessageId(value: unknown): boolean {
  const id = normalizeMessageId(value)
  return (
    id.startsWith('compact-')
    || id.startsWith('compact-restored-')
    || id.startsWith('restored-compact-')
  )
}

export function isCompressionTranscriptMessageId(value: unknown): boolean {
  const id = normalizeMessageId(value)
  return (
    id.startsWith('compression-')
    || id.startsWith('compression-restored-')
    || id.startsWith('restored-compression-')
  )
}

export function isSupplementalTranscriptAssistantMessage(
  message: unknown,
): boolean {
  if (!message || typeof message !== 'object')
    return false
  if (String((message as any)?.role ?? '').trim() !== 'assistant')
    return false
  const id = normalizeMessageId((message as any)?.id)
  return (
    isCompactTranscriptMessageId(id) || isCompressionTranscriptMessageId(id)
  )
}
