What was the role of the second in top level matches? What was the role, the duties, etc. of the second (e.g. GM Ray Keene was Korchnoi’s second in the 1978 World Championship match vs. Karpov), and is this figure still present in contemporary top level chess?
What was the role, the duties, etc. of the second (e.g. GM Ray Keene
was Korchnoi’s second in the 1978 World Championship match vs. Karpov)

What it most definitely was NOT was writing a book of the match ready to rush into print the moment the match finished as Keene did.
The way it was supposed to work was that after the time control was reached at move 40 one of the players would seal a move. The players would then go back to their respective hotels with their seconds and perhaps discus a few lines. The principal would then have a meal and go to bed. The seconds would then stay up all night analyzing the position and coming up with a list of variations for the principal to look at and learn when he got up the next morning.
On nights when there was a new game starting the next morning it was the job of the seconds to prepare opening lines based on the opponent's repertoire for the principal to look at the next morning.
Sometimes, in the build up before a world championship match, a player would hire a strong player for a secret match to try out ideas in a realistic match atmosphere. Botvinnik famously did this as did Anand.

is this figure still present in contemporary top level chess?

Very much so.
Today the main job of the second to do the dogsbody work of opening preparation for the principal. Part of this may be preparing the player to play against a particular opponent's repertoire. Jan Gustaffson has famously helped Carlsen with opening prep as this is his main area of expertise as a chess player.
The other more interesting part is to come up with new ideas in opening lines. This requires creativity and computer skills with engines because they play a big role. This doesn't automatically require GM level chess ability. Nakamura has famously employed the same sub-2200 player, Kris Littlejohn, since 2008 simply because Littlejohn comes up with many creative opening ideas, is very good at investigating them with engines and gets along well with Nakamura on a personal level.
There is more on the Nakamura-Littlejohn relationship in this Chessbase India Facebook video and this episode of Ben Johnson's Perpetual Chess Podcast.
There is more interesting information about seconds in this post.