Merge branch 'agent-882-queue-preview-chat' into agent-882-queue-channel-messages

This commit is contained in:
Robin Braumann 2026-09-15 11:51:38 +02:00
commit 38f8d8ee47
No known key found for this signature in database
4 changed files with 14 additions and 13 deletions

View File

@ -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);

View File

@ -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),

View File

@ -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. */

View File

@ -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,