Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 62 additions & 47 deletions src/api/ai-workflow/ai-workflow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,6 @@ import { User } from 'src/shared/decorators/user.decorator';
export class AiWorkflowController {
constructor(private readonly aiWorkflowService: AiWorkflowService) {}

@Get('/:workflowId/runs/:runId/items')
@Roles(
UserRole.Admin,
UserRole.Copilot,
UserRole.ProjectManager,
UserRole.User,
)
@Scopes(Scope.ReadWorkflowRun)
@ApiOperation({
summary: 'Get AIWorkflowRunItems for a given workflow run ID',
})
@ApiResponse({
status: 200,
description: 'The AIWorkflowRunItems for the given run ID.',
})
@ApiResponse({ status: 400, description: 'Bad Request.' })
@ApiResponse({ status: 401, description: 'Unauthorized.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@ApiResponse({ status: 404, description: 'Run not found.' })
async getRunItems(
@Param('workflowId') workflowId: string,
@Param('runId') runId: string,
@User() user: JwtUser,
) {
return this.aiWorkflowService.getRunItems(workflowId, runId, user);
}

@Post()
@Roles(UserRole.Admin)
@Scopes(Scope.CreateWorkflow)
Expand All @@ -78,27 +51,19 @@ export class AiWorkflowController {
return this.aiWorkflowService.createWithValidation(createAiWorkflowDto);
}

@Post('/:workflowId/runs/:runId/items')
@Scopes(Scope.CreateWorkflowRun)
@ApiOperation({ summary: 'Create AIWorkflowRunItems in batch' })
@ApiResponse({
status: 201,
description: 'AIWorkflowRunItems created successfully.',
@Get()
@Roles(UserRole.Admin, UserRole.User, UserRole.Copilot, UserRole.Reviewer)
@Scopes(Scope.ReadWorkflow)
@ApiOperation({ summary: 'Fetch AI workflows' })
@ApiQuery({
name: 'name',
description: 'Filter AI workflows by name',
required: false,
type: 'string',
})
@ApiResponse({ status: 400, description: 'Bad Request.' })
@ApiResponse({ status: 401, description: 'Unauthorized.' })
@ApiResponse({ status: 404, description: 'Workflow or Run not found.' })
async createRunItems(
@Param('workflowId') workflowId: string,
@Param('runId') runId: string,
@Body(new ValidationPipe({ whitelist: true, transform: true }))
createItemsDto: CreateAiWorkflowRunItemsDto,
) {
return this.aiWorkflowService.createRunItemsBatch(
workflowId,
runId,
createItemsDto.items,
);
@ApiResponse({ status: 200, description: 'The AI workflow records.' })
async fetchRecords(@Query('name') name: string) {
return this.aiWorkflowService.getWorkflows({ name: name?.trim() });
}

@Get(':id')
Expand Down Expand Up @@ -236,4 +201,54 @@ export class AiWorkflowController {
) {
return this.aiWorkflowService.updateWorkflowRun(workflowId, runId, body);
}

@Post('/:workflowId/runs/:runId/items')
@Scopes(Scope.CreateWorkflowRun)
@ApiOperation({ summary: 'Create AIWorkflowRunItems in batch' })
@ApiResponse({
status: 201,
description: 'AIWorkflowRunItems created successfully.',
})
@ApiResponse({ status: 400, description: 'Bad Request.' })
@ApiResponse({ status: 401, description: 'Unauthorized.' })
@ApiResponse({ status: 404, description: 'Workflow or Run not found.' })
async createRunItems(
@Param('workflowId') workflowId: string,
@Param('runId') runId: string,
@Body(new ValidationPipe({ whitelist: true, transform: true }))
createItemsDto: CreateAiWorkflowRunItemsDto,
) {
return this.aiWorkflowService.createRunItemsBatch(
workflowId,
runId,
createItemsDto.items,
);
}

@Get('/:workflowId/runs/:runId/items')
@Roles(
UserRole.Admin,
UserRole.Copilot,
UserRole.ProjectManager,
UserRole.User,
)
@Scopes(Scope.ReadWorkflowRun)
@ApiOperation({
summary: 'Get AIWorkflowRunItems for a given workflow run ID',
})
@ApiResponse({
status: 200,
description: 'The AIWorkflowRunItems for the given run ID.',
})
@ApiResponse({ status: 400, description: 'Bad Request.' })
@ApiResponse({ status: 401, description: 'Unauthorized.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@ApiResponse({ status: 404, description: 'Run not found.' })
async getRunItems(
@Param('workflowId') workflowId: string,
@Param('runId') runId: string,
@User() user: JwtUser,
) {
return this.aiWorkflowService.getRunItems(workflowId, runId, user);
}
}
18 changes: 18 additions & 0 deletions src/api/ai-workflow/ai-workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ export class AiWorkflowService {
});
}

async getWorkflows(filters: { name: string }) {
const workflows = await this.prisma.aiWorkflow.findMany({
where: filters.name
? { name: { contains: filters.name, mode: 'insensitive' } }
: {},
include: {
llm: {
include: {
provider: true,
},
},
scorecard: true,
},
});

return workflows;
}

async getWorkflowById(id: string) {
const workflow = await this.prisma.aiWorkflow.findUnique({
where: { id },
Expand Down