import {z} from 'zod' export type ArtifactId = string; export type GetApiV1ArtifactsArtifactIdArgs = {artifact_id: ArtifactId}; export type GetApiV1ArtifactsArtifactIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const requestId = z.string(); export const runtimeLocation = z.enum(["local", "cloud"]); export const execution = z.object({location: runtimeLocation, capability_id: z.string().nullable().optional(), capability_version: z.string().nullable().optional()}); export const usage = z.object({billable: z.boolean(), quantity: z.number().gte(0), unit: z.string(), credits: z.number().gte(0).optional()}); export const artifactId = z.string(); export const jobId = z.string(); export const responseId = z.string(); export const evidenceId = z.string(); export const artifact = z.object({id: artifactId, kind: z.enum(["clip_gallery", "comparison", "timeline", "highlight_reel", "storyboard", "dataset_manifest", "review_queue"]), schema_version: z.string(), job_id: jobId.nullable().optional(), response_id: responseId.nullable().optional(), evidence_ids: z.array(evidenceId), payload: z.record(z.string(), z.unknown()), created_at: z.string()}); export const artifactResponse = z.object({request_id: requestId, execution: execution, usage: usage, warnings: z.array(z.string()), data: artifact}); 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 a structured artifact * * GET /v1/artifacts/{artifact_id} * * Also accepts auth: apiKeyAuth */ export const getApiV1ArtifactsArtifactId = async (args: GetApiV1ArtifactsArtifactIdArgs, options?: GetApiV1ArtifactsArtifactIdOptions) => { const {baseUrl = "https://api.cerul.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/artifacts/${encodeURIComponent(String(args.artifact_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(artifactResponse, await res.json()) };