import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common'; import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiTags, } from '@nestjs/swagger'; import { ZodValidationPipe } from '../common/pipes/zod-validation.pipe'; import { AuthGuard } from '../auth/auth.guard'; import { AuthenticatedUser } from '../auth/auth.types'; import { CurrentUser } from '../auth/current-user.decorator'; import { PasswordChangeGuard } from '../auth/password-change.guard'; import { AgentInvocation } from './agent.types'; import { AgentService } from './agent.service'; import { CreateAgentInvocationDto, CreateAgentInvocationInput, createAgentInvocationSchema, } from './create-agent-invocation.dto'; @ApiTags('Agent 调用') @Controller('agent/invocations') @UseGuards(AuthGuard, PasswordChangeGuard) export class AgentController { constructor(private readonly agentService: AgentService) {} @Get() @ApiOkResponse({ description: '查询 Agent 调用记录。' }) async listInvocations( @CurrentUser() user: AuthenticatedUser, ): Promise { return this.agentService.listInvocations(user); } @Post() @ApiBody({ type: CreateAgentInvocationDto }) @ApiCreatedResponse({ description: '创建 DevOps 工作流范围内的 Agent 调用。' }) async createInvocation( @CurrentUser() user: AuthenticatedUser, @Body(new ZodValidationPipe(createAgentInvocationSchema)) body: CreateAgentInvocationInput, ): Promise { return this.agentService.createInvocation(body, user); } }