import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { z } from 'zod'; import { AgentPurpose } from './agent.types'; const agentPurposeSchema = z.enum([ 'release-risk', 'failure-diagnosis', 'runbook-qa', 'release-note', 'incident-review', ]); const optionalTrimmedString = (maxLength: number) => z .string() .trim() .max(maxLength) .optional() .or(z.literal('').transform(() => undefined)); /** * Agent 入口只接受 DevOps 场景参数,防止演变成通用聊天代理。 */ export const createAgentInvocationSchema = z.object({ type: agentPurposeSchema, runId: optionalTrimmedString(120), projectKey: optionalTrimmedString(80), promptSummary: z.string().trim().min(1).max(2000), }); export type CreateAgentInvocationInput = z.infer< typeof createAgentInvocationSchema >; export class CreateAgentInvocationDto { @ApiProperty({ enum: [ 'release-risk', 'failure-diagnosis', 'runbook-qa', 'release-note', 'incident-review', ], example: 'failure-diagnosis', }) type!: AgentPurpose; @ApiPropertyOptional({ example: 'run-1052' }) runId?: string; @ApiPropertyOptional({ example: 'access-manage' }) projectKey?: string; @ApiProperty({ description: '本次 Agent 调用的中文问题或任务摘要', example: '分析 access-manage 测试环境最近一次 Jenkins 失败日志。', }) promptSummary!: string; }