import {z} from 'zod' export type BodyAssetFromAudioClipApiProjectsProjectIdAssetsFromAudioClipAudioClipIdPost = {name?: (string | null) | undefined}; export type CreateApiApiProjectsProjectIdAssetsFromAudioClipAudioClipIdArgs = {project_id: string, audio_clip_id: string, body: BodyAssetFromAudioClipApiProjectsProjectIdAssetsFromAudioClipAudioClipIdPost}; export type CreateApiApiProjectsProjectIdAssetsFromAudioClipAudioClipIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const assetVersionResponse = z.object({id: z.string(), versionNumber: z.number().int(), parentVersionId: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), isActive: z.boolean().optional(), thumbnailUrl: z.string().nullable().optional(), imageUrl: z.string().nullable().optional(), name: z.string().nullable().optional(), prompt: z.string().nullable().optional()}); export const assetResponse: z.ZodType = z.object({id: z.string(), projectId: z.string(), parentAssetId: z.string().nullable().optional(), sceneId: z.string().nullable().optional(), keyframeId: z.string().nullable().optional(), name: z.string(), prompt: z.string().nullable().optional(), mediaType: z.enum(["image", "video", "audio"]).optional(), imageUrl: z.string().nullable().optional(), imageId: z.string().nullable().optional(), videoUrl: z.string().nullable().optional(), audioUrl: z.string().nullable().optional(), durationMs: z.number().int().nullable().optional(), primaryVideoId: z.string().nullable().optional(), primaryAudioClipId: z.string().nullable().optional(), primaryImageId: z.string().nullable().optional(), secondaryImageIds: z.record(z.string(), z.string()).nullable().optional(), hasMultipleAngles: z.boolean().optional(), secondaryAngles: z.record(z.string(), z.string()).nullable().optional(), versions: z.array(assetVersionResponse).optional(), activeVersionNumber: z.number().int().optional(), createdAt: z.string(), updatedAt: z.string(), subAssets: z.array(z.lazy(() => assetResponse)).optional()}); export const generateAssetResponse = z.object({success: z.boolean().optional(), asset: assetResponse}); 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 }; /** * Asset From Audio Clip * * POST /api/projects/{project_id}/assets/from-audio-clip/{audio_clip_id} * * Also accepts auth: HTTPBearer */ export const createApiApiProjectsProjectIdAssetsFromAudioClipAudioClipId = async (args: CreateApiApiProjectsProjectIdAssetsFromAudioClipAudioClipIdArgs, options: CreateApiApiProjectsProjectIdAssetsFromAudioClipAudioClipIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.project_id))}/assets/from-audio-clip/${encodeURIComponent(String(args.audio_clip_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(generateAssetResponse, await res.json()) };