| 958 | 958 | } |
| 959 | 959 | }; |
| 960 | 960 | |
| 961 | | - await Promise.allSettled([getCharacterChatFiles(), getGroupChatFiles()]); |
| 961 | + const getRootChatFiles = async () => { |
| 962 | + const dirents = await fs.promises.readdir(request.user.directories.chats, { withFileTypes: true }); |
| 963 | + const chatFiles = dirents.filter(e => e.isFile() && path.extname(e.name) === '.jsonl').map(e => e.name); |
| 964 | + |
| 965 | + for (const file of chatFiles) { |
| 966 | + const filePath = path.join(request.user.directories.chats, file); |
| 967 | + const stats = await fs.promises.stat(filePath); |
| 968 | + allChatFiles.push({ filePath, mtime: stats.mtimeMs }); |
| 969 | + } |
| 970 | + }; |
| 971 | + |
| 972 | + await Promise.allSettled([getCharacterChatFiles(), getGroupChatFiles(), getRootChatFiles()]); |
| 962 | 973 | |
| 963 | 974 | const max = parseInt(request.body.max ?? Number.MAX_SAFE_INTEGER); |
| 964 | 975 | const recentChats = allChatFiles.sort((a, b) => b.mtime - a.mtime).slice(0, max); |