From 0a169a1ff6c0c6d0a71ce405b274d970c3df987d Mon Sep 17 00:00:00 2001 From: Ben Verhees Date: Thu, 17 Jul 2025 16:42:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A5=20fix:=20Collaborative=20Check=20F?= =?UTF-8?q?lag=20for=20Shared=20Agent=20Files=20(#8516)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/File.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/api/models/File.js b/api/models/File.js index 6d1d77a220..3d735434e3 100644 --- a/api/models/File.js +++ b/api/models/File.js @@ -21,7 +21,7 @@ const findFileById = async (file_id, options = {}) => { * @param {string} agentId - The agent ID that might grant access * @returns {Promise>} Map of fileId to access status */ -const hasAccessToFilesViaAgent = async (userId, fileIds, agentId) => { +const hasAccessToFilesViaAgent = async (userId, fileIds, agentId, checkCollaborative = true) => { const accessMap = new Map(); // Initialize all files as no access @@ -55,11 +55,11 @@ const hasAccessToFilesViaAgent = async (userId, fileIds, agentId) => { } // Agent is globally shared - check if it's collaborative - if (!agent.isCollaborative) { + if (checkCollaborative && !agent.isCollaborative) { return accessMap; } - // Agent is globally shared and collaborative - check which files are actually attached + // Check which files are actually attached const attachedFileIds = new Set(); if (agent.tool_resources) { for (const [_resourceType, resource] of Object.entries(agent.tool_resources)) { @@ -118,7 +118,12 @@ const getFiles = async (filter, _sortOptions, selectFields = { text: 0 }, option // Batch check access for all non-owned files const fileIds = filesToCheck.map((f) => f.file_id); - const accessMap = await hasAccessToFilesViaAgent(options.userId, fileIds, options.agentId); + const accessMap = await hasAccessToFilesViaAgent( + options.userId, + fileIds, + options.agentId, + false, + ); // Filter files based on access const accessibleFiles = filesToCheck.filter((file) => accessMap.get(file.file_id));