mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 21:49:36 +02:00
refactor(core): Look up the queued agent once by message kind (no-changelog)
enqueue now decides on the system kind once. The custom-agents setting applies to every other kind. A system message without a registered provider now fails with "Agent not found", also when the admin turned off custom agents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5b1964908e
commit
edde04df32
|
|
@ -94,20 +94,18 @@ export class AgentMessageQueueService {
|
|||
): Promise<{ status: 'accepted'; item: AgentMessageQueue } | { status: 'duplicate' }> {
|
||||
const { payload } = input;
|
||||
// Only the system kind reaches a system agent. Project lookups never return instance agents.
|
||||
const systemAgent =
|
||||
payload.kind === 'system' ? this.systemAgents.get(input.agentId) : undefined;
|
||||
// System agents run even when the admin turns off custom agents.
|
||||
if (!systemAgent) await this.settingsService.assertEnabled();
|
||||
const agent =
|
||||
payload.kind === 'system'
|
||||
? systemAgent
|
||||
: await this.agentRepository.findByIdAndProjectId(input.agentId, input.projectId);
|
||||
const isSystem = payload.kind === 'system';
|
||||
if (!isSystem) await this.settingsService.assertEnabled();
|
||||
const agent = isSystem
|
||||
? this.systemAgents.get(input.agentId)
|
||||
: await this.agentRepository.findByIdAndProjectId(input.agentId, input.projectId);
|
||||
if (!agent) throw new UserError('Agent not found');
|
||||
const messageId = queuedMessageId(input.agentId, input.threadId, payload);
|
||||
let item: AgentMessageQueue;
|
||||
try {
|
||||
item = await this.txRunner.run({}, async (ctx) => {
|
||||
if (!systemAgent) await this.settingsService.assertEnabled(ctx);
|
||||
if (!isSystem) await this.settingsService.assertEnabled(ctx);
|
||||
await this.executionService.prepareThread(
|
||||
{
|
||||
...input,
|
||||
|
|
|
|||
|
|
@ -2693,6 +2693,16 @@ describe('AgentExecutionRepository', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('refuses a system message without a provider while custom agents are turned off', async () => {
|
||||
const services = recordingServices();
|
||||
await services.settingsService.setEnabled(false);
|
||||
await agentRepo.ensureInstanceAgent(systemAgentId, 'Test System Agent');
|
||||
|
||||
await expect(services.queue.enqueue(systemInput(uuid(), 'Hello', 'new'))).rejects.toThrow(
|
||||
'Agent not found',
|
||||
);
|
||||
});
|
||||
|
||||
it('refuses a Preview message for a system agent', async () => {
|
||||
const services = await systemServices();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user