import {z} from 'zod' export type GetApiApiAiV3ContentsGenerationsTasksTaskIdArgs = {taskId: string}; export type GetApiApiAiV3ContentsGenerationsTasksTaskIdOptions = {baseUrl?: string | undefined, apikeyHeaderAuthorization?: string | undefined, fetch?: typeof fetch | undefined}; export const volcengineTaskStatusResponseVo = z.object({id: z.string(), model: z.string(), status: z.string(), error: z.object({message: z.string(), code: z.string()}).nullable().optional(), created_at: z.number(), updated_at: z.number(), content: z.object({video_url: z.string().optional(), last_frame_url: z.string().optional()}).optional(), seed: z.number().optional(), resolution: z.string().optional(), ratio: z.string().optional(), duration: z.number().optional(), framespersecond: z.number().optional(), usage: z.object({completion_tokens: z.number().optional(), total_tokens: z.number().optional(), tool_usage: z.object({web_search: z.number().optional()}).optional()}).optional(), generate_audio: z.boolean().optional(), tools: z.array(z.object({type: z.string()})).optional(), safety_identifier: z.string().optional(), priority: z.number().optional(), execution_expires_after: z.number().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * 火山格式查询视频任务 * * GET /api/ai/v3/contents/generations/tasks/{taskId} */ export const getApiApiAiV3ContentsGenerationsTasksTaskId = async (args: GetApiApiAiV3ContentsGenerationsTasksTaskIdArgs, options?: GetApiApiAiV3ContentsGenerationsTasksTaskIdOptions) => { const {baseUrl = "https://aitoearn.cn", fetch: fetchFn = fetch, apikeyHeaderAuthorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apikeyHeaderAuthorization !== undefined) headers.set("Authorization", apikeyHeaderAuthorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/ai/v3/contents/generations/tasks/${encodeURIComponent(String(args.taskId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(volcengineTaskStatusResponseVo, await res.json()) };