mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-09 17:31:19 +00:00
fix: unset empty Langfuse agent config
This commit is contained in:
parent
ddb7090d64
commit
bc2c19d841
5 changed files with 80 additions and 7 deletions
|
|
@ -566,12 +566,20 @@ const updateAgentHandler = async (req, res) => {
|
|||
}
|
||||
|
||||
if (updateData.langfuse) {
|
||||
updateData.langfuse = await normalizeLangfuseConfig(
|
||||
const normalizedLangfuse = await normalizeLangfuseConfig(
|
||||
updateData.langfuse,
|
||||
existingAgent.langfuse,
|
||||
);
|
||||
if (!updateData.langfuse) {
|
||||
if (normalizedLangfuse) {
|
||||
updateData.langfuse = normalizedLangfuse;
|
||||
} else {
|
||||
delete updateData.langfuse;
|
||||
if (existingAgent.langfuse) {
|
||||
updateData.$unset = {
|
||||
...(updateData.$unset || {}),
|
||||
langfuse: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -958,6 +958,36 @@ describe('Agent Controllers - Mass Assignment Protection', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should remove Langfuse config when update clears the only stored field', async () => {
|
||||
const encryptedOriginal = await encryptStoredSecret('sk-original');
|
||||
await Agent.updateOne(
|
||||
{ id: existingAgentId },
|
||||
{
|
||||
langfuse: {
|
||||
secretKey: encryptedOriginal,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
mockReq.params.id = existingAgentId;
|
||||
mockReq.body = {
|
||||
langfuse: {
|
||||
secretKey: LANGFUSE_SECRET_CLEAR_VALUE,
|
||||
},
|
||||
};
|
||||
|
||||
await updateAgentHandler(mockReq, mockRes);
|
||||
|
||||
expect(mockRes.json).toHaveBeenCalled();
|
||||
const updatedAgent = mockRes.json.mock.calls[0][0];
|
||||
expect(updatedAgent.langfuse).toBeUndefined();
|
||||
|
||||
const agentInDb = await Agent.findOne({ id: existingAgentId }).lean();
|
||||
expect(agentInDb.langfuse).toBeUndefined();
|
||||
const latestVersion = agentInDb.versions[agentInDb.versions.length - 1];
|
||||
expect(latestVersion.langfuse).toBeUndefined();
|
||||
});
|
||||
|
||||
test('uploadAgentAvatarHandler should redact Langfuse secret in response', async () => {
|
||||
await Agent.updateOne(
|
||||
{ id: existingAgentId },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue