| 1 | import { createZodDto, UserType } from '@yikart/common' |
| 2 | import { z } from 'zod' |
| 3 | import { VolcengineContentType, VolcengineImageRole, VolcengineTaskStatus } from '../enums' |
| 4 | |
| 5 | // Volcengine视频生成请求 |
| 6 | export const volcengineGenerationRequestSchema = z.object({ |
| 7 | model: z.string().describe('模型ID或Endpoint ID'), |
| 8 | content: z.array(z.union([ |
| 9 | z.object({ |
| 10 | type: z.literal(VolcengineContentType.Text), |
| 11 | text: z.string(), |
| 12 | }), |
| 13 | z.object({ |
| 14 | type: z.literal(VolcengineContentType.ImageUrl), |
| 15 | image_url: z.object({ |
| 16 | url: z.string(), |
| 17 | }), |
| 18 | role: z.enum(VolcengineImageRole).optional(), |
| 19 | }), |
| 20 | ])).describe('输入内容'), |
| 21 | return_last_frame: z.boolean().optional().describe('是否返回尾帧图像'), |
| 22 | }) |
| 23 | |
| 24 | export class VolcengineGenerationRequestDto extends createZodDto(volcengineGenerationRequestSchema) {} |
| 25 | |
| 26 | const userVolcengineGenerationRequestSchema = z.object({ |
| 27 | userId: z.string(), |
| 28 | userType: z.enum(UserType), |
| 29 | ...volcengineGenerationRequestSchema.shape, |
| 30 | }) |
| 31 | |
| 32 | export class UserVolcengineGenerationRequestDto extends createZodDto(userVolcengineGenerationRequestSchema) {} |
| 33 | |
| 34 | // Volcengine回调接口DTO(与查询API返回格式一致) |
| 35 | const volcengineCallbackSchema = z.object({ |
| 36 | id: z.string(), |
| 37 | model: z.string(), |
| 38 | status: z.enum(VolcengineTaskStatus), |
| 39 | created_at: z.number(), |
| 40 | updated_at: z.number(), |
| 41 | content: z.object({ |
| 42 | video_url: z.string(), |
| 43 | last_frame_url: z.string().optional(), |
| 44 | }).optional(), |
| 45 | error: z.object({ |
| 46 | message: z.string(), |
| 47 | code: z.string(), |
| 48 | }).optional().nullable(), |
| 49 | seed: z.number().optional(), |
| 50 | resolution: z.string().optional(), |
| 51 | ratio: z.string().optional(), |
| 52 | duration: z.number().optional(), |
| 53 | framespersecond: z.number().optional(), |
| 54 | usage: z.object({ |
| 55 | completion_tokens: z.number(), |
| 56 | total_tokens: z.number(), |
| 57 | }).optional(), |
| 58 | }) |
| 59 | |
| 60 | export class VolcengineCallbackDto extends createZodDto(volcengineCallbackSchema) {} |
| 61 |