import {z} from 'zod' export type GetApiV1StudioProjectsProjectIdSnapshotsProjectSnapshotIdArgs = {project_id: string, project_snapshot_id: string, 'xi-api-key'?: (string | null) | undefined}; export type GetApiV1StudioProjectsProjectIdSnapshotsProjectSnapshotIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const characterAlignmentModel = z.object({characters: z.array(z.string()), character_start_times_seconds: z.array(z.number()), character_end_times_seconds: z.array(z.number())}); export const projectSnapshotExtendedResponseModel = z.object({project_snapshot_id: z.string(), project_id: z.string(), created_at_unix: z.number().int(), name: z.string(), audio_upload: z.record(z.string(), z.unknown()).nullable().optional(), zip_upload: z.record(z.string(), z.unknown()).nullable().optional(), character_alignments: z.array(characterAlignmentModel), audio_duration_secs: z.number()}); 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 Project Snapshot * * GET /v1/studio/projects/{project_id}/snapshots/{project_snapshot_id} */ export const getApiV1StudioProjectsProjectIdSnapshotsProjectSnapshotId = async (args: GetApiV1StudioProjectsProjectIdSnapshotsProjectSnapshotIdArgs, options: GetApiV1StudioProjectsProjectIdSnapshotsProjectSnapshotIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['xi-api-key'] != null) headers.set("xi-api-key", String(args['xi-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/studio/projects/${encodeURIComponent(String(args.project_id))}/snapshots/${encodeURIComponent(String(args.project_snapshot_id))}${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(projectSnapshotExtendedResponseModel, await res.json()) };