Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

741 B
Raw Blame
import type { CoworkAttachedFile, CoworkTurn } from '@/types/coworkSession'

/**
 * Every document the user attached across the session, in the order they were
 * attached and deduplicated by source path: the same file attached to two
 * questions is one file. Later turns win, so a copy imported on a re-ask
 * supersedes the record of the failed first attempt.
 */
export function sessionAttachments(
  turns: CoworkTurn[] | undefined
): CoworkAttachedFile[] {
  if (!turns?.length) return []
  const byPath = new Map<string, CoworkAttachedFile>()
  for (const turn of turns) {
    if (turn.role !== 'user' || !turn.files?.length) continue
    for (const file of turn.files) byPath.set(file.path, file)
  }
  return [...byPath.values()]
}