Skip to content

Commit

Permalink
fix: Handle assistant unlinking even if no valid files to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
thelinuxkid committed Jan 8, 2025
1 parent 916faf6 commit 6714a21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api/server/routes/files/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { getOpenAIClient } = require('~/server/controllers/assistants/helpers');
const { loadAuthValues } = require('~/app/clients/tools/util');
const { getAgent } = require('~/models/Agent');
const { getAssistant } = require('~/models/Assistant');
const { getFiles } = require('~/models/File');
const { logger } = require('~/config');

Expand Down Expand Up @@ -78,7 +79,7 @@ router.delete('/', async (req, res) => {
});
}

/* Handle entity unlinking even if no valid files to delete */
/* Handle agent unlinking even if no valid files to delete */
if (req.body.agent_id && req.body.tool_resource && dbFiles.length === 0) {
const agent = await getAgent({
id: req.body.agent_id,
Expand All @@ -88,7 +89,21 @@ router.delete('/', async (req, res) => {
const agentFiles = files.filter((f) => toolResourceFiles.includes(f.file_id));

await processDeleteRequest({ req, files: agentFiles });
res.status(200).json({ message: 'File associations removed successfully' });
res.status(200).json({ message: 'File associations removed successfully from agent' });
return;
}

/* Handle assistant unlinking even if no valid files to delete */
if (req.body.assistant_id && req.body.tool_resource && dbFiles.length === 0) {
const assistant = await getAssistant({
id: req.body.assistant_id,
});

const toolResourceFiles = assistant.tool_resources?.[req.body.tool_resource]?.file_ids ?? [];
const assistantFiles = files.filter((f) => toolResourceFiles.includes(f.file_id));

await processDeleteRequest({ req, files: assistantFiles });
res.status(200).json({ message: 'File associations removed successfully from assistant' });
return;
}

Expand Down

0 comments on commit 6714a21

Please sign in to comment.