|
| 1 | +import { defineCommand } from '../../command'; |
| 2 | +import { requestJson } from '../../client/http'; |
| 3 | +import { videoTaskV2ListEndpoint } from '../../client/endpoints'; |
| 4 | +import { formatOutput, detectOutputFormat } from '../../output/formatter'; |
| 5 | +import type { Config } from '../../config/schema'; |
| 6 | +import type { GlobalFlags } from '../../types/flags'; |
| 7 | +import type { VideoV2TaskListResponse } from '../../types/api'; |
| 8 | +import { VIDEO_V2_MODEL } from '../../video/v2'; |
| 9 | + |
| 10 | +export default defineCommand({ |
| 11 | + name: 'video task list', |
| 12 | + description: 'List Video Generation V2 tasks', |
| 13 | + apiDocs: '/docs/api-reference/video-generation-v2-list', |
| 14 | + usage: 'mmx video task list [flags]', |
| 15 | + options: [ |
| 16 | + { flag: '--page-num <number>', description: 'Page number to request', type: 'number' }, |
| 17 | + { flag: '--page-size <number>', description: 'Page size to request', type: 'number' }, |
| 18 | + { flag: '--status <status>', description: 'Filter by task status' }, |
| 19 | + { flag: '--task-id <id>', description: 'Filter by task ID; repeatable', type: 'array' }, |
| 20 | + { flag: '--task-type <type>', description: 'Filter by task type' }, |
| 21 | + ], |
| 22 | + examples: [ |
| 23 | + 'mmx video task list --output json', |
| 24 | + 'mmx video task list --status succeeded --page-size 20', |
| 25 | + ], |
| 26 | + async run(config: Config, flags: GlobalFlags) { |
| 27 | + const format = detectOutputFormat(config.output); |
| 28 | + const url = new URL(videoTaskV2ListEndpoint(config.baseUrl)); |
| 29 | + |
| 30 | + if (flags.pageNum !== undefined) url.searchParams.set('page_num', String(flags.pageNum)); |
| 31 | + if (flags.pageSize !== undefined) url.searchParams.set('page_size', String(flags.pageSize)); |
| 32 | + if (flags.status) url.searchParams.set('filter.status', String(flags.status)); |
| 33 | + const taskIds = flags.taskId as string[] | undefined; |
| 34 | + if (taskIds?.length) url.searchParams.set('filter.task_ids', taskIds.join(',')); |
| 35 | + url.searchParams.set('filter.model', VIDEO_V2_MODEL); |
| 36 | + if (flags.taskType) url.searchParams.set('filter.task_type', String(flags.taskType)); |
| 37 | + |
| 38 | + if (config.dryRun) { |
| 39 | + process.stdout.write(formatOutput({ request: { url: url.toString() } }, format) + '\n'); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + const response = await requestJson<VideoV2TaskListResponse>(config, { url: url.toString() }); |
| 44 | + |
| 45 | + if (format !== 'text') { |
| 46 | + process.stdout.write(formatOutput(response, format) + '\n'); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + if (!response.items || response.items.length === 0) { |
| 51 | + process.stdout.write('No video tasks found.\n'); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + const tableData = response.items.map(task => ({ |
| 56 | + ID: task.id, |
| 57 | + MODEL: task.model, |
| 58 | + STATUS: task.status, |
| 59 | + RESOLUTION: task.resolution ?? '', |
| 60 | + DURATION: task.duration ?? '', |
| 61 | + })); |
| 62 | + |
| 63 | + const { formatTable } = await import('../../output/text'); |
| 64 | + process.stdout.write(formatTable(tableData) + '\n'); |
| 65 | + }, |
| 66 | +}); |
0 commit comments