| 1 | import { createZodDto, UserType } from '@yikart/common' |
| 2 | import { z } from 'zod' |
| 3 | import { AudioRole, ContentType, ImageRole, TaskStatus, ToolType, VideoRole } from '../../libs/volcengine' |
| 4 | |
| 5 | // Volcengine视频生成请求 |
| 6 | 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(ContentType.Text), |
| 11 | text: z.string(), |
| 12 | }), |
| 13 | z.object({ |
| 14 | type: z.literal(ContentType.ImageUrl), |
| 15 | image_url: z.object({ |
| 16 | url: z.string(), |
| 17 | }), |
| 18 | role: z.enum(ImageRole).optional(), |
| 19 | }), |
| 20 | z.object({ |
| 21 | type: z.literal(ContentType.VideoUrl), |
| 22 | video_url: z.object({ |
| 23 | url: z.string(), |
| 24 | }), |
| 25 | role: z.literal(VideoRole.ReferenceVideo), |
| 26 | }), |
| 27 | z.object({ |
| 28 | type: z.literal(ContentType.AudioUrl), |
| 29 | audio_url: z.object({ |
| 30 | url: z.string(), |
| 31 | }), |
| 32 | role: z.literal(AudioRole.ReferenceAudio), |
| 33 | }), |
| 34 | ])).describe('输入内容'), |
| 35 | return_last_frame: z.boolean().optional().describe('是否返回尾帧图像'), |
| 36 | tools: z.array(z.object({ |
| 37 | type: z.literal(ToolType.WebSearch), |
| 38 | })).optional().describe('模型工具配置'), |
| 39 | resolution: z.string().optional().describe('分辨率'), |
| 40 | ratio: z.string().optional().describe('宽高比'), |
| 41 | duration: z.number().int().optional().describe('时长(秒)'), |
| 42 | seed: z.number().int().optional().describe('随机种子'), |
| 43 | watermark: z.boolean().optional().describe('是否带水印'), |
| 44 | }) |
| 45 | |
| 46 | export class VolcengineGenerationRequestDto extends createZodDto(volcengineGenerationRequestSchema) {} |
| 47 | |
| 48 | const userVolcengineGenerationRequestSchema = z.object({ |
| 49 | userId: z.string(), |
| 50 | userType: z.enum(UserType), |
| 51 | ...volcengineGenerationRequestSchema.shape, |
| 52 | }) |
| 53 | |
| 54 | export class UserVolcengineGenerationRequestDto extends createZodDto(userVolcengineGenerationRequestSchema) {} |
| 55 | |
| 56 | // Volcengine回调接口DTO(与查询API返回格式一致) |
| 57 | const volcengineCallbackSchema = z.object({ |
| 58 | id: z.string(), |
| 59 | model: z.string(), |
| 60 | status: z.enum(TaskStatus), |
| 61 | created_at: z.number(), |
| 62 | updated_at: z.number(), |
| 63 | content: z.object({ |
| 64 | video_url: z.string(), |
| 65 | last_frame_url: z.string().optional(), |
| 66 | }).optional(), |
| 67 | error: z.object({ |
| 68 | message: z.string(), |
| 69 | code: z.string(), |
| 70 | }).optional().nullable(), |
| 71 | seed: z.number().optional(), |
| 72 | resolution: z.string().optional(), |
| 73 | ratio: z.string().optional(), |
| 74 | duration: z.number().optional(), |
| 75 | framespersecond: z.number().optional(), |
| 76 | usage: z.object({ |
| 77 | completion_tokens: z.number(), |
| 78 | total_tokens: z.number(), |
| 79 | tool_usage: z.object({ |
| 80 | web_search: z.number().optional(), |
| 81 | }).optional(), |
| 82 | }).optional(), |
| 83 | }) |
| 84 | |
| 85 | export class VolcengineCallbackDto extends createZodDto(volcengineCallbackSchema) {} |
| 86 |