mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 13:39:44 +02:00
Merge branch 'agent-882-queue-preview-chat' into agent-882-queue-channel-messages
This commit is contained in:
commit
38f8d8ee47
|
|
@ -102,7 +102,7 @@ describe('AgentExecutionService', () => {
|
|||
async function recordExecution(params: RecordMessageParams): Promise<string> {
|
||||
const { record, ...startParams } = params;
|
||||
const executionId = await service.startExecutionRecording(
|
||||
{ ...startParams, agentName: 'Agent' },
|
||||
{ ...startParams, agentName: startParams.agentName ?? 'Agent' },
|
||||
new Date(record.startTime),
|
||||
);
|
||||
return await service.finalizeExecution(executionId, params);
|
||||
|
|
|
|||
|
|
@ -127,13 +127,7 @@ export function createTestTurnQueue(user: User = { id: 'user-1', disabled: false
|
|||
: null;
|
||||
});
|
||||
const agentRepository = mock<AgentRepository>();
|
||||
agentRepository.findSummariesByIds.mockImplementation(async ([id]) => [
|
||||
{
|
||||
id,
|
||||
name: 'Agent',
|
||||
projectId: rows.find((row) => row.agentId === id)?.projectId ?? 'project-1',
|
||||
},
|
||||
]);
|
||||
agentRepository.findNameByIdAndProjectId.mockResolvedValue('Agent');
|
||||
const userRepository = mock<UserRepository>();
|
||||
userRepository.findByIdWithRole.mockImplementation(async (id) =>
|
||||
id === user.id ? user : ({ id, disabled: true } as User),
|
||||
|
|
|
|||
|
|
@ -345,11 +345,12 @@ export class AgentTurnQueueService {
|
|||
private async withAgentName(
|
||||
turn: AgentTurnSubmission,
|
||||
): Promise<StartExecutionParams & TurnRowValues> {
|
||||
const [agent] = await this.agentRepository.findSummariesByIds([turn.agentId]);
|
||||
if (!agent || agent.projectId !== turn.projectId) {
|
||||
throw new UserError(`Agent "${turn.agentId}" not found`);
|
||||
}
|
||||
return { ...turn, agentName: agent.name, resourceId: turn.resourceId ?? null };
|
||||
const agentName = await this.agentRepository.findNameByIdAndProjectId(
|
||||
turn.agentId,
|
||||
turn.projectId,
|
||||
);
|
||||
if (agentName === null) throw new UserError(`Agent "${turn.agentId}" not found`);
|
||||
return { ...turn, agentName, resourceId: turn.resourceId ?? null };
|
||||
}
|
||||
|
||||
/** The sender must still be able to run the agent; the drain has no request that checked that. */
|
||||
|
|
|
|||
|
|
@ -210,6 +210,12 @@ export class AgentRepository extends Repository<Agent> {
|
|||
return await this.exists({ where: { id, projectId } });
|
||||
}
|
||||
|
||||
/** Scoped to the project so ownership is enforced by the query; `null` when the agent is not in it. */
|
||||
async findNameByIdAndProjectId(id: string, projectId: string): Promise<string | null> {
|
||||
const agent = await this.findOne({ select: ['id', 'name'], where: { id, projectId } });
|
||||
return agent?.name ?? null;
|
||||
}
|
||||
|
||||
async findByIdsAndProjectId(
|
||||
ids: string[],
|
||||
projectId: string,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user