import {z} from 'zod' export type GetApiV1JobsJobUuidFeedbackArgs = {jobUuid: string, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV1JobsJobUuidFeedbackOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const v1Modality = z.enum(["MODALITY_UNSPECIFIED", "MODALITY_VIDEO", "MODALITY_AUDIO", "MODALITY_IMAGE", "MODALITY_TEXT"]); export const jobFeedbackTargetOccurrence = z.object({modality: v1Modality, startMs: z.string(), endMs: z.string().optional()}); export const v1JobFeedbackTarget = z.object({contentHash: z.string().optional(), occurrence: jobFeedbackTargetOccurrence.optional()}); export const v1EvaluationResult = z.enum(["EVALUATION_RESULT_UNSPECIFIED", "EVALUATION_RESULT_FLAGGED", "EVALUATION_RESULT_NOT_FLAGGED"]); export const v1JobAnnotation = z.object({id: z.string().optional(), jobUuid: z.string().optional(), jobResultId: z.string().optional(), target: v1JobFeedbackTarget.optional(), label: z.string().optional(), labelId: z.string().optional(), labelVersionId: z.string().optional(), expectedOutcome: v1EvaluationResult.optional(), actualOutcome: v1EvaluationResult.optional(), comment: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const v1GetJobFeedbackResponse = z.object({annotations: z.array(v1JobAnnotation).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 }; /** * Get job feedback * * GET /v1/jobs/{jobUuid}/feedback */ export const getApiV1JobsJobUuidFeedback = async (args: GetApiV1JobsJobUuidFeedbackArgs, options?: GetApiV1JobsJobUuidFeedbackOptions) => { 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.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/${encodeURIComponent(String(args.jobUuid))}/feedback${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(v1GetJobFeedbackResponse, await res.json()) };