1d15c1c676
- src/agent: 新增 AgentInvocationRepository,统一封装 Prisma 落库和本地降级存储 - src/agent/agent.service.ts: 创建 Agent 调用后写入数据库,并按项目权限过滤历史列表 - src/agent/agent.module.ts: 注册 Agent 调用记录仓储依赖
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
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<AgentInvocation[]> {
|
|
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<AgentInvocation> {
|
|
return this.agentService.createInvocation(body, user);
|
|
}
|
|
}
|