import {z} from 'zod' export type V1Modality = 'MODALITY_UNSPECIFIED' | 'MODALITY_VIDEO' | 'MODALITY_AUDIO' | 'MODALITY_IMAGE' | 'MODALITY_TEXT'; export type JobFeedbackTargetOccurrence = {modality: V1Modality, startMs: unknown, endMs?: unknown | undefined}; export type V1JobFeedbackTarget = {contentHash?: string | undefined, occurrence?: JobFeedbackTargetOccurrence | undefined}; export type V1EvaluationResult = 'EVALUATION_RESULT_UNSPECIFIED' | 'EVALUATION_RESULT_FLAGGED' | 'EVALUATION_RESULT_NOT_FLAGGED'; export type V1JobFeedbackItem = {target?: V1JobFeedbackTarget | undefined, label?: string | undefined, expectedOutcome: V1EvaluationResult, comment?: string | undefined}; export type GatewayServiceSubmitJobFeedbackBody = {items: Array}; export type CreateApiV1JobsJobUuidFeedbackArgs = {jobUuid: string, body: GatewayServiceSubmitJobFeedbackBody}; export type CreateApiV1JobsJobUuidFeedbackOptions = {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 v1SubmitJobFeedbackResponse = z.object({annotations: z.array(v1JobAnnotation).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 }; /** * Submit job feedback * * POST /v1/jobs/{jobUuid}/feedback */ export const createApiV1JobsJobUuidFeedback = async (args: CreateApiV1JobsJobUuidFeedbackArgs, options?: CreateApiV1JobsJobUuidFeedbackOptions) => { const {baseUrl = "https://gateway.app.clavata.ai:8443", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1SubmitJobFeedbackResponse, await res.json()) };