mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
fix: agents query
This commit is contained in:
parent
3f694f2e25
commit
dd90907a18
2 changed files with 9 additions and 10 deletions
|
|
@ -71,14 +71,13 @@ const deleteAgent = async (searchParameter) => {
|
|||
const getListAgents = async (searchParameter) => {
|
||||
const { author, ...otherParams } = searchParameter;
|
||||
|
||||
let query = {
|
||||
$or: [{ author }, { projectIds: { $exists: true, $ne: [], $not: { $size: 0 } } }],
|
||||
...otherParams,
|
||||
};
|
||||
let query = Object.assign({ author }, otherParams);
|
||||
|
||||
const globalProject = await getProjectByName(GLOBAL_PROJECT_NAME, 'agentIds');
|
||||
if (globalProject && globalProject.agentIds.length > 0) {
|
||||
query.$or.push({ _id: { $in: globalProject.agentIds } });
|
||||
const globalProject = await getProjectByName(GLOBAL_PROJECT_NAME, ['agentIds']);
|
||||
if (globalProject && (globalProject.agentIds?.length ?? 0) > 0) {
|
||||
const globalQuery = { id: { $in: globalProject.agentIds }, ...otherParams };
|
||||
delete globalQuery.author;
|
||||
query = { $or: [globalQuery, query] };
|
||||
}
|
||||
|
||||
const agents = await Agent.find(query, {
|
||||
|
|
|
|||
|
|
@ -131,9 +131,9 @@ const deleteAgentHandler = async (req, res) => {
|
|||
*/
|
||||
const getListAgentsHandler = async (req, res) => {
|
||||
try {
|
||||
const { user } = req.query;
|
||||
const filter = user ? { author: user } : {};
|
||||
const data = await getListAgents(filter);
|
||||
const data = await getListAgents({
|
||||
author: req.user.id,
|
||||
});
|
||||
return res.json(data);
|
||||
} catch (error) {
|
||||
logger.error('[/Agents] Error listing Agents', error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue