- Fix ObjectId comparison in getListAgentsHandler using .equals() method instead of strict equality

- Add findPubliclyAccessibleResources function to PermissionService for bulk public resource queries
  - Add hasPublicPermission function to PermissionService for individual resource public permission checks
  - Update getAgentHandler to use hasPublicPermission for accurate individual agent public status
  - Replace instanceProjectId-based global checks with isPublic property from backend in client code
  - Add isPublic property to Agent type definition
  - Add NODE_TLS_REJECT_UNAUTHORIZED debug setting to VS Code launch config
This commit is contained in:
Atef Bellaaj 2025-06-13 10:23:00 +02:00 committed by Danny Avila
parent 5979efd607
commit c9aa10d3d5
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
7 changed files with 102 additions and 12 deletions

View file

@ -15,7 +15,12 @@ const {
deleteAgent,
getListAgentsByAccess,
} = require('~/models/Agent');
const { grantPermission, findAccessibleResources } = require('~/server/services/PermissionService');
const {
grantPermission,
findAccessibleResources,
findPubliclyAccessibleResources,
hasPublicPermission,
} = require('~/server/services/PermissionService');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { updateAgentProjects, revertAgentVersion } = require('~/models/Agent');
const { resizeAvatar } = require('~/server/services/Files/images/avatar');
@ -134,6 +139,14 @@ const getAgentHandler = async (req, res, expandProperties = false) => {
// @deprecated - isCollaborative replaced by ACL permissions
agent.isCollaborative = !!agent.isCollaborative;
// Check if agent is public
const isPublic = await hasPublicPermission({
resourceType: 'agent',
resourceId: agent._id,
requiredPermissions: PermissionBits.VIEW,
});
agent.isPublic = isPublic;
if (agent.author !== author) {
delete agent.author;
}
@ -152,6 +165,7 @@ const getAgentHandler = async (req, res, expandProperties = false) => {
projectIds: agent.projectIds,
// @deprecated - isCollaborative replaced by ACL permissions
isCollaborative: agent.isCollaborative,
isPublic: agent.isPublic,
version: agent.version,
// Safe metadata
createdAt: agent.createdAt,
@ -392,14 +406,23 @@ const getListAgentsHandler = async (req, res) => {
resourceType: 'agent',
requiredPermissions: PermissionBits.VIEW,
});
const publiclyAccessibleIds = await findPubliclyAccessibleResources({
resourceType: 'agent',
requiredPermissions: PermissionBits.VIEW,
});
// Use the new ACL-aware function
const data = await getListAgentsByAccess({
accessibleIds,
otherParams: {}, // Can add query params here if needed
});
if (data?.data?.length) {
data.data = data.data.map((agent) => {
if (publiclyAccessibleIds.some(id => id.equals(agent._id))) {
agent.isPublic = true;
}
return agent;
});
}
return res.json(data);
} catch (error) {
logger.error('[/Agents] Error listing Agents', error);