mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
🔧 feat: Share Assistant Actions between Users (#2116)
* fix: remove unique field from assistant_id, which can be shared between different users * refactor: remove unique user fields from actions/assistant queries * feat: only allow user who saved action to delete it * refactor: allow deletions for anyone with builder access * refactor: update user.id when updating assistants/actions records, instead of searching with it * fix: stringify response data in case it's an object * fix: correctly handle path input * fix(decryptV2): handle edge case where value is already decrypted
This commit is contained in:
parent
2f90c8764a
commit
a8cdd3460c
7 changed files with 65 additions and 16 deletions
|
|
@ -17,7 +17,7 @@ const router = express.Router();
|
|||
*/
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
res.json(await getActions({ user: req.user.id }));
|
||||
res.json(await getActions());
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
|
|
@ -55,9 +55,9 @@ router.post('/:assistant_id', async (req, res) => {
|
|||
/** @type {{ openai: OpenAI }} */
|
||||
const { openai } = await initializeClient({ req, res });
|
||||
|
||||
initialPromises.push(getAssistant({ assistant_id, user: req.user.id }));
|
||||
initialPromises.push(getAssistant({ assistant_id }));
|
||||
initialPromises.push(openai.beta.assistants.retrieve(assistant_id));
|
||||
!!_action_id && initialPromises.push(getActions({ user: req.user.id, action_id }, true));
|
||||
!!_action_id && initialPromises.push(getActions({ action_id }, true));
|
||||
|
||||
/** @type {[AssistantDocument, Assistant, [Action|undefined]]} */
|
||||
const [assistant_data, assistant, actions_result] = await Promise.all(initialPromises);
|
||||
|
|
@ -115,14 +115,15 @@ router.post('/:assistant_id', async (req, res) => {
|
|||
const promises = [];
|
||||
promises.push(
|
||||
updateAssistant(
|
||||
{ assistant_id, user: req.user.id },
|
||||
{ assistant_id },
|
||||
{
|
||||
actions,
|
||||
user: req.user.id,
|
||||
},
|
||||
),
|
||||
);
|
||||
promises.push(openai.beta.assistants.update(assistant_id, { tools }));
|
||||
promises.push(updateAction({ action_id, user: req.user.id }, { metadata, assistant_id }));
|
||||
promises.push(updateAction({ action_id }, { metadata, assistant_id, user: req.user.id }));
|
||||
|
||||
/** @type {[AssistantDocument, Assistant, Action]} */
|
||||
const resolved = await Promise.all(promises);
|
||||
|
|
@ -155,7 +156,7 @@ router.delete('/:assistant_id/:action_id', async (req, res) => {
|
|||
const { openai } = await initializeClient({ req, res });
|
||||
|
||||
const initialPromises = [];
|
||||
initialPromises.push(getAssistant({ assistant_id, user: req.user.id }));
|
||||
initialPromises.push(getAssistant({ assistant_id }));
|
||||
initialPromises.push(openai.beta.assistants.retrieve(assistant_id));
|
||||
|
||||
/** @type {[AssistantDocument, Assistant]} */
|
||||
|
|
@ -180,14 +181,15 @@ router.delete('/:assistant_id/:action_id', async (req, res) => {
|
|||
const promises = [];
|
||||
promises.push(
|
||||
updateAssistant(
|
||||
{ assistant_id, user: req.user.id },
|
||||
{ assistant_id },
|
||||
{
|
||||
actions: updatedActions,
|
||||
user: req.user.id,
|
||||
},
|
||||
),
|
||||
);
|
||||
promises.push(openai.beta.assistants.update(assistant_id, { tools: updatedTools }));
|
||||
promises.push(deleteAction({ action_id, user: req.user.id }));
|
||||
promises.push(deleteAction({ action_id }));
|
||||
|
||||
await Promise.all(promises);
|
||||
res.status(200).json({ message: 'Action deleted successfully' });
|
||||
|
|
|
|||
|
|
@ -241,12 +241,13 @@ router.post('/avatar/:assistant_id', upload.single('file'), async (req, res) =>
|
|||
const promises = [];
|
||||
promises.push(
|
||||
updateAssistant(
|
||||
{ assistant_id, user: req.user.id },
|
||||
{ assistant_id },
|
||||
{
|
||||
avatar: {
|
||||
filepath: image.filepath,
|
||||
source: req.app.locals.fileStrategy,
|
||||
},
|
||||
user: req.user.id,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue