import {z} from 'zod' export type GetApiV1JobsArgs = {'query.createdTimeRange.start'?: string | undefined, 'query.createdTimeRange.end'?: string | undefined, 'query.createdTimeRange.inclusive'?: boolean | undefined, 'query.updatedTimeRange.start'?: string | undefined, 'query.updatedTimeRange.end'?: string | undefined, 'query.updatedTimeRange.inclusive'?: boolean | undefined, 'query.completedTimeRange.start'?: string | undefined, 'query.completedTimeRange.end'?: string | undefined, 'query.completedTimeRange.inclusive'?: boolean | undefined, 'query.status'?: ('JOB_STATUS_UNSPECIFIED' | 'JOB_STATUS_PENDING' | 'JOB_STATUS_RUNNING' | 'JOB_STATUS_COMPLETED' | 'JOB_STATUS_FAILED' | 'JOB_STATUS_CANCELED') | undefined, 'query.policyId'?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV1JobsOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const v1JobStatus = z.enum(["JOB_STATUS_UNSPECIFIED", "JOB_STATUS_PENDING", "JOB_STATUS_RUNNING", "JOB_STATUS_COMPLETED", "JOB_STATUS_FAILED", "JOB_STATUS_CANCELED"]); export const v1ContentData = z.object({contentHash: z.string().optional(), text: z.string().optional(), image: z.string().optional(), imageUrl: z.string().optional(), metadata: z.record(z.string(), z.string()).optional()}); export const v1Outcome = z.enum(["OUTCOME_UNSPECIFIED", "OUTCOME_FALSE", "OUTCOME_TRUE", "OUTCOME_FAILED"]); export const policyEvaluationReportAssertionEvaluationReport = z.object({result: v1Outcome.optional(), message: z.string().optional(), score: z.number().optional()}); export const policyEvaluationReportReviewResult = z.object({outcome: v1Outcome.optional(), score: z.number().optional()}); export const policyEvaluationReportExceptionEvaluationReport = z.object({result: v1Outcome.optional(), assertionEvaluationReports: z.array(policyEvaluationReportAssertionEvaluationReport).optional(), reviewResult: policyEvaluationReportReviewResult.optional()}); export const policyEvaluationReportSectionEvaluationReport = z.object({name: z.string().optional(), result: v1Outcome.optional(), message: z.string().optional(), assertionEvaluationReports: z.array(policyEvaluationReportAssertionEvaluationReport).optional(), exceptionEvaluationReport: policyEvaluationReportExceptionEvaluationReport.optional(), reviewResult: policyEvaluationReportReviewResult.optional()}); export const policyEvaluationReportTokenUsage = z.object({inputTokens: z.number().int().optional(), billedTokens: z.number().int().optional(), multiplier: z.number().optional()}); export const v1PolicyEvaluationReport = z.object({policyId: z.string().optional(), policyKey: z.string().optional(), policyVersionId: z.string().optional(), result: v1Outcome.optional(), sectionEvaluationReports: z.array(policyEvaluationReportSectionEvaluationReport).optional(), exceptionEvaluationReport: policyEvaluationReportExceptionEvaluationReport.optional(), contentHash: z.string().optional(), contentMetadata: z.record(z.string(), z.string()).optional(), reviewResult: policyEvaluationReportReviewResult.optional(), threshold: z.number().optional(), labelMatches: z.record(z.string(), z.number()).optional(), tokenUsage: policyEvaluationReportTokenUsage.optional(), labelId: z.string().optional(), labelVersionId: z.string().optional()}); export const v1JobResult = z.object({jobUuid: z.string().optional(), report: v1PolicyEvaluationReport.optional(), created: z.string().optional()}); export const v1JobType = z.enum(["JOB_TYPE_UNSPECIFIED", "JOB_TYPE_STANDARD", "JOB_TYPE_BATCH", "JOB_TYPE_FREE", "JOB_TYPE_TEST"]); export const v1JobErrorReason = z.enum(["JOB_ERROR_REASON_UNSPECIFIED", "JOB_ERROR_REASON_JOB_FAILED", "JOB_ERROR_REASON_VIDEO_VALIDATION_FAILURE", "JOB_ERROR_REASON_VIDEO_SCENE_CEILING_EXCEEDED", "JOB_ERROR_REASON_HLS_REMUX_TIMEOUT_EXHAUSTED", "JOB_ERROR_REASON_EXECUTION_DEADLINE_EXCEEDED", "JOB_ERROR_REASON_ADMISSION_QUEUE_TIMEOUT", "JOB_ERROR_REASON_ADMISSION_FAILED", "JOB_ERROR_REASON_TRANSCRIPT_CHUNK_ARTIFACT_INVALID", "JOB_ERROR_REASON_QUOTA_EXCEEDED", "JOB_ERROR_REASON_CONTENT_BLOCKED", "JOB_ERROR_REASON_CONTENT_PRECHECK_FAILED", "JOB_ERROR_REASON_VIDEO_SOURCE_UNREACHABLE", "JOB_ERROR_REASON_CONTENT_TOO_LARGE"]); export const v1JobError = z.object({reason: v1JobErrorReason.optional(), message: z.string().optional()}); export const v1Job = z.object({jobUuid: z.string().optional(), customerId: z.string().optional(), status: v1JobStatus.optional(), contentData: z.array(v1ContentData).optional(), results: z.array(v1JobResult).optional(), created: z.string().optional(), updated: z.string().optional(), completed: z.string().optional(), policyId: z.string().optional(), policyVersionId: z.string().optional(), threshold: z.number().optional(), labelId: z.string().optional(), labelVersionId: z.string().optional(), jobType: v1JobType.optional(), error: v1JobError.optional()}); export const v1ListJobsResponse = z.object({jobs: z.array(v1Job).optional(), nextPageToken: z.string().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 }; /** * List jobs * * GET /v1/jobs */ export const getApiV1Jobs = async (args: GetApiV1JobsArgs, options?: GetApiV1JobsOptions) => { const {baseUrl = "https://gateway.app.clavata.ai:8443", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['query.createdTimeRange.start'] != null) query.append("query.createdTimeRange.start", String(args['query.createdTimeRange.start'])) if (args['query.createdTimeRange.end'] != null) query.append("query.createdTimeRange.end", String(args['query.createdTimeRange.end'])) if (args['query.createdTimeRange.inclusive'] != null) query.append("query.createdTimeRange.inclusive", String(args['query.createdTimeRange.inclusive'])) if (args['query.updatedTimeRange.start'] != null) query.append("query.updatedTimeRange.start", String(args['query.updatedTimeRange.start'])) if (args['query.updatedTimeRange.end'] != null) query.append("query.updatedTimeRange.end", String(args['query.updatedTimeRange.end'])) if (args['query.updatedTimeRange.inclusive'] != null) query.append("query.updatedTimeRange.inclusive", String(args['query.updatedTimeRange.inclusive'])) if (args['query.completedTimeRange.start'] != null) query.append("query.completedTimeRange.start", String(args['query.completedTimeRange.start'])) if (args['query.completedTimeRange.end'] != null) query.append("query.completedTimeRange.end", String(args['query.completedTimeRange.end'])) if (args['query.completedTimeRange.inclusive'] != null) query.append("query.completedTimeRange.inclusive", String(args['query.completedTimeRange.inclusive'])) if (args['query.status'] != null) query.append("query.status", String(args['query.status'])) if (args['query.policyId'] != null) query.append("query.policyId", String(args['query.policyId'])) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/jobs${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(v1ListJobsResponse, await res.json()) };