import {z} from 'zod' export type GetApiV1AccountsAccountIdEvaluationJobsEvaluationJobIdArgs = {readMask?: string | undefined, account_id: string, evaluation_job_id: string}; export type GetApiV1AccountsAccountIdEvaluationJobsEvaluationJobIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayJobState = z.enum(["JOB_STATE_UNSPECIFIED", "JOB_STATE_CREATING", "JOB_STATE_RUNNING", "JOB_STATE_COMPLETED", "JOB_STATE_FAILED", "JOB_STATE_CANCELLED", "JOB_STATE_DELETING", "JOB_STATE_WRITING_RESULTS", "JOB_STATE_VALIDATING", "JOB_STATE_DELETING_CLEANING_UP", "JOB_STATE_PENDING", "JOB_STATE_EXPIRED", "JOB_STATE_RE_QUEUEING", "JOB_STATE_CREATING_INPUT_DATASET", "JOB_STATE_IDLE", "JOB_STATE_CANCELLING", "JOB_STATE_EARLY_STOPPED", "JOB_STATE_PAUSED", "JOB_STATE_DELETED", "JOB_STATE_ARCHIVED"]); export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayAwsS3Config = z.object({credentialsSecret: z.string().optional(), iamRoleArn: z.string().optional()}); export const gatewayEvaluationJob = z.object({name: z.string().optional(), displayName: z.string().optional(), createTime: z.string().optional(), createdBy: z.string().optional(), state: gatewayJobState.optional(), status: gatewayStatus.optional(), evaluator: z.string(), inputDataset: z.string(), outputDataset: z.string(), metrics: z.record(z.string(), z.number()).optional(), outputStats: z.string().optional(), updateTime: z.string().optional(), awsS3Config: gatewayAwsS3Config.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 Evaluation Job * * GET /v1/accounts/{account_id}/evaluationJobs/{evaluation_job_id} */ export const getApiV1AccountsAccountIdEvaluationJobsEvaluationJobId = async (args: GetApiV1AccountsAccountIdEvaluationJobsEvaluationJobIdArgs, options: GetApiV1AccountsAccountIdEvaluationJobsEvaluationJobIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.readMask != null) query.append("readMask", String(args.readMask)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/evaluationJobs/${encodeURIComponent(String(args.evaluation_job_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(gatewayEvaluationJob, await res.json()) };