import {z} from 'zod' export type GoogleCloudAiplatformV1SampleConfig = {followingBatchSamplePercentage?: number | undefined, initialBatchSamplePercentage?: number | undefined, sampleStrategy?: ('SAMPLE_STRATEGY_UNSPECIFIED' | 'UNCERTAINTY') | undefined}; export type GoogleCloudAiplatformV1TrainingConfig = {timeoutTrainingMilliHours?: unknown | undefined}; export type GoogleCloudAiplatformV1ActiveLearningConfig = {maxDataItemCount?: unknown | undefined, maxDataItemPercentage?: number | undefined, sampleConfig?: GoogleCloudAiplatformV1SampleConfig | undefined, trainingConfig?: GoogleCloudAiplatformV1TrainingConfig | undefined}; export type GoogleTypeMoney = {currencyCode?: string | undefined, nanos?: number | undefined, units?: unknown | undefined}; export type GoogleCloudAiplatformV1EncryptionSpec = {kmsKeyName?: string | undefined}; export type GoogleRpcStatus = {code?: number | undefined, details?: Array<{[key: string]: unknown}> | undefined, message?: string | undefined}; export type GoogleCloudAiplatformV1DataLabelingJob = {activeLearningConfig?: GoogleCloudAiplatformV1ActiveLearningConfig | undefined, annotationLabels?: {[key: string]: string} | undefined, createTime?: unknown | undefined, currentSpend?: GoogleTypeMoney | undefined, datasets?: Array | undefined, displayName?: string | undefined, encryptionSpec?: GoogleCloudAiplatformV1EncryptionSpec | undefined, error?: GoogleRpcStatus | undefined, inputs: unknown, inputsSchemaUri?: string | undefined, instructionUri?: string | undefined, labelerCount?: number | undefined, labelingProgress?: number | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined, specialistPools?: Array | undefined, state?: ('JOB_STATE_UNSPECIFIED' | 'JOB_STATE_QUEUED' | 'JOB_STATE_PENDING' | 'JOB_STATE_RUNNING' | 'JOB_STATE_SUCCEEDED' | 'JOB_STATE_FAILED' | 'JOB_STATE_CANCELLING' | 'JOB_STATE_CANCELLED' | 'JOB_STATE_PAUSED' | 'JOB_STATE_EXPIRED' | 'JOB_STATE_UPDATING' | 'JOB_STATE_PARTIALLY_SUCCEEDED') | undefined, updateTime?: unknown | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDataLabelingJobsArgs = {projectsId: string, locationsId: string, body: GoogleCloudAiplatformV1DataLabelingJob}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDataLabelingJobsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudAiplatformV1SampleConfig = z.object({followingBatchSamplePercentage: z.number().int().optional(), initialBatchSamplePercentage: z.number().int().optional(), sampleStrategy: z.enum(["SAMPLE_STRATEGY_UNSPECIFIED", "UNCERTAINTY"]).optional()}); export const googleCloudAiplatformV1TrainingConfig = z.object({timeoutTrainingMilliHours: z.string().optional()}); export const googleCloudAiplatformV1ActiveLearningConfig = z.object({maxDataItemCount: z.string().optional(), maxDataItemPercentage: z.number().int().optional(), sampleConfig: googleCloudAiplatformV1SampleConfig.optional(), trainingConfig: googleCloudAiplatformV1TrainingConfig.optional()}); export const googleTypeMoney = z.object({currencyCode: z.string().optional(), nanos: z.number().int().optional(), units: z.string().optional()}); export const googleCloudAiplatformV1EncryptionSpec = z.object({kmsKeyName: z.string().optional()}); export const googleRpcStatus = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const googleCloudAiplatformV1DataLabelingJob = z.object({activeLearningConfig: googleCloudAiplatformV1ActiveLearningConfig.optional(), annotationLabels: z.record(z.string(), z.string()).optional(), createTime: z.string().optional(), currentSpend: googleTypeMoney.optional(), datasets: z.array(z.string()).optional(), displayName: z.string().optional(), encryptionSpec: googleCloudAiplatformV1EncryptionSpec.optional(), error: googleRpcStatus.optional(), inputs: z.unknown(), inputsSchemaUri: z.string().optional(), instructionUri: z.string().optional(), labelerCount: z.number().int().optional(), labelingProgress: z.number().int().optional(), labels: z.record(z.string(), z.string()).optional(), name: z.string().optional(), specialistPools: z.array(z.string()).optional(), state: z.enum(["JOB_STATE_UNSPECIFIED", "JOB_STATE_QUEUED", "JOB_STATE_PENDING", "JOB_STATE_RUNNING", "JOB_STATE_SUCCEEDED", "JOB_STATE_FAILED", "JOB_STATE_CANCELLING", "JOB_STATE_CANCELLED", "JOB_STATE_PAUSED", "JOB_STATE_EXPIRED", "JOB_STATE_UPDATING", "JOB_STATE_PARTIALLY_SUCCEEDED"]).optional(), updateTime: 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 }; /** * Creates a DataLabelingJob. * * POST /v1/projects/{projectsId}/locations/{locationsId}/dataLabelingJobs */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdDataLabelingJobs = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDataLabelingJobsArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDataLabelingJobsOptions) => { const {baseUrl = "https://aiplatform.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/dataLabelingJobs${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(googleCloudAiplatformV1DataLabelingJob, await res.json()) };