Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔄 fix: Update Agent Versioning to Include `agent_ids` (#7762)

matt burnett53df6a1a71df
diff --git a/api/models/Agent.js b/api/models/Agent.js
index eb16e4d238..12b7a478af 100644
--- a/api/models/Agent.js
+++ b/api/models/Agent.js
@@ -170,7 +170,6 @@ const isDuplicateVersion = (updateData, currentData, versions, actionsHash = nul
'created_at',
'updated_at',
'__v',
- 'agent_ids',
'versions',
'actionsHash', // Exclude actionsHash from direct comparison
];
diff --git a/api/models/Agent.spec.js b/api/models/Agent.spec.js
index 08ece95fb9..0e35ef36a7 100644
--- a/api/models/Agent.spec.js
+++ b/api/models/Agent.spec.js
@@ -662,6 +662,7 @@ describe('models/Agent', () => {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
+ Agent = mongoose.models.Agent || mongoose.model('Agent', agentSchema);
await mongoose.connect(mongoUri);
});
@@ -1323,6 +1324,7 @@ describe('models/Agent', () => {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
+ Agent = mongoose.models.Agent || mongoose.model('Agent', agentSchema);
await mongoose.connect(mongoUri);
});
@@ -1504,6 +1506,7 @@ describe('models/Agent', () => {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
+ Agent = mongoose.models.Agent || mongoose.model('Agent', agentSchema);
await mongoose.connect(mongoUri);
});
@@ -1797,6 +1800,7 @@ describe('models/Agent', () => {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
+ Agent = mongoose.models.Agent || mongoose.model('Agent', agentSchema);
await mongoose.connect(mongoUri);
});
@@ -2344,6 +2348,174 @@ describe('models/Agent', () => {
Agent.updateOne = originalUpdateOne;
});
});
+
+ describe('Agent IDs Field in Version Detection', () => {
+ let mongoServer;
+
+ beforeAll(async () => {
+ mongoServer = await MongoMemoryServer.create();
+ const mongoUri = mongoServer.getUri();
+ Agent = mongoose.models.Agent || mongoose.model('Agent', agentSchema);
+ await mongoose.connect(mongoUri);
+ });
+
+ afterAll(async () => {
+ await mongoose.disconnect();
+ await mongoServer.stop();
+ });
+
+ beforeEach(async () => {
+ await Agent.deleteMany({});
+ });
+
+ test('should now create new version when agent_ids field changes', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ const agent = await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ agent_ids: ['agent1', 'agent2'],
+ });
+
+ expect(agent).toBeDefined();
+ expect(agent.versions).toHaveLength(1);
+
+ const updated = await updateAgent(
+ { id: agentId },
+ { agent_ids: ['agent1', 'agent2', 'agent3'] },
+ );
+
+ // Since agent_ids is no longer excluded, this should create a new version
+ expect(updated.versions).toHaveLength(2);
+ expect(updated.agent_ids).toEqual(['agent1', 'agent2', 'agent3']);
+ });
+
+ test('should detect duplicate version if agent_ids is updated to same value', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ agent_ids: ['agent1', 'agent2'],
+ });
+
+ await updateAgent({ id: agentId }, { agent_ids: ['agent1', 'agent2', 'agent3'] });
+
+ await expect(
+ updateAgent({ id: agentId }, { agent_ids: ['agent1', 'agent2', 'agent3'] }),
+ ).rejects.toThrow('Duplicate version');
+ });
+
+ test('should handle agent_ids field alongside other fields', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ description: 'Initial description',
+ agent_ids: ['agent1'],
+ });
+
+ const updated = await updateAgent(
+ { id: agentId },
+ {
+ agent_ids: ['agent1', 'agent2'],
+ description: 'Updated description',
+ },
+ );
+
+ expect(updated.versions).toHaveLength(2);
+ expect(updated.agent_ids).toEqual(['agent1', 'agent2']);
+ expect(updated.description).toBe('Updated description');
+
+ const updated2 = await updateAgent({ id: agentId }, { description: 'Another description' });
+
+ expect(updated2.versions).toHaveLength(3);
+ expect(updated2.agent_ids).toEqual(['agent1', 'agent2']);
+ expect(updated2.description).toBe('Another description');
+ });
+
+ test('should preserve agent_ids in version history', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ agent_ids: ['agent1'],
+ });
+
+ await updateAgent({ id: agentId }, { agent_ids: ['agent1', 'agent2'] });
+
+ await updateAgent({ id: agentId }, { agent_ids: ['agent3'] });
+
+ const finalAgent = await getAgent({ id: agentId });
+
+ expect(finalAgent.versions).toHaveLength(3);
+ expect(finalAgent.versions[0].agent_ids).toEqual(['agent1']);
+ expect(finalAgent.versions[1].agent_ids).toEqual(['agent1', 'agent2']);
+ expect(finalAgent.versions[2].agent_ids).toEqual(['agent3']);
+ expect(finalAgent.agent_ids).toEqual(['agent3']);
+ });
+
+ test('should handle empty agent_ids arrays', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ agent_ids: ['agent1', 'agent2'],
+ });
+
+ const updated = await updateAgent({ id: agentId }, { agent_ids: [] });
+
+ expect(updated.versions).toHaveLength(2);
+ expect(updated.agent_ids).toEqual([]);
+
+ await expect(updateAgent({ id: agentId }, { agent_ids: [] })).rejects.toThrow(
+ 'Duplicate version',
+ );
+ });
+
+ test('should handle agent without agent_ids field', async () => {
+ const agentId = `agent_${uuidv4()}`;
+ const authorId = new mongoose.Types.ObjectId();
+
+ const agent = await createAgent({
+ id: agentId,
+ name: 'Test Agent',
+ provider: 'test',
+ model: 'test-model',
+ author: authorId,
+ });
+
+ expect(agent.agent_ids).toEqual([]);
+
+ const updated = await updateAgent({ id: agentId }, { agent_ids: ['agent1'] });
+
+ expect(updated.versions).toHaveLength(2);
+ expect(updated.agent_ids).toEqual(['agent1']);
+ });
+ });
});
function createBasicAgent(overrides = {}) {