import {z} from 'zod' export type GoogleCloudAiplatformV1FeatureStatsAnomaly = {anomalyDetectionThreshold?: number | undefined, anomalyUri?: string | undefined, distributionDeviation?: number | undefined, endTime?: unknown | undefined, score?: number | undefined, startTime?: unknown | undefined, statsUri?: string | undefined}; export type GoogleCloudAiplatformV1FeatureMonitoringStatsAnomaly = {featureStatsAnomaly?: GoogleCloudAiplatformV1FeatureStatsAnomaly | undefined, objective?: ('OBJECTIVE_UNSPECIFIED' | 'IMPORT_FEATURE_ANALYSIS' | 'SNAPSHOT_ANALYSIS') | undefined}; export type GoogleCloudAiplatformV1Feature = {createTime?: unknown | undefined, description?: string | undefined, disableMonitoring?: boolean | undefined, etag?: string | undefined, labels?: {[key: string]: string} | undefined, monitoringStatsAnomalies?: Array | undefined, name?: string | undefined, pointOfContact?: string | undefined, updateTime?: unknown | undefined, valueType?: ('VALUE_TYPE_UNSPECIFIED' | 'BOOL' | 'BOOL_ARRAY' | 'DOUBLE' | 'DOUBLE_ARRAY' | 'INT64' | 'INT64_ARRAY' | 'STRING' | 'STRING_ARRAY' | 'BYTES' | 'STRUCT') | undefined, versionColumnName?: string | undefined}; export type GoogleCloudAiplatformV1CreateFeatureRequest = {feature?: GoogleCloudAiplatformV1Feature | undefined, featureId?: string | undefined, parent?: string | undefined}; export type GoogleCloudAiplatformV1BatchCreateFeaturesRequest = {requests?: Array | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdFeatureGroupsFeatureGroupsIdFeaturesBatchCreateArgs = {projectsId: string, locationsId: string, featureGroupsId: string, body: GoogleCloudAiplatformV1BatchCreateFeaturesRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdFeatureGroupsFeatureGroupsIdFeaturesBatchCreateOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; 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 googleLongrunningOperation = z.object({done: z.boolean().optional(), error: googleRpcStatus.optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), response: z.record(z.string(), z.unknown()).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 batch of Features in a given FeatureGroup. * * POST /v1/projects/{projectsId}/locations/{locationsId}/featureGroups/{featureGroupsId}/features:batchCreate */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdFeatureGroupsFeatureGroupsIdFeaturesBatchCreate = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdFeatureGroupsFeatureGroupsIdFeaturesBatchCreateArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdFeatureGroupsFeatureGroupsIdFeaturesBatchCreateOptions) => { 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))}/featureGroups/${encodeURIComponent(String(args.featureGroupsId))}/features:batchCreate${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(googleLongrunningOperation, await res.json()) };