import {z} from 'zod' export type V1ProfileConstraintNumeric = {min?: unknown | undefined, max?: (unknown | null) | undefined, default?: unknown | undefined, cumulativeMax?: (unknown | null) | undefined}; export type V1ProfileConstraintDuration = {min?: string | undefined, max?: (string | null) | undefined, default?: string | undefined}; export type DAIEngineProfileConfigEditability = 'CONFIG_EDITABILITY_UNSPECIFIED' | 'CONFIG_EDITABILITY_DISABLED' | 'CONFIG_EDITABILITY_BASE_CONFIG_ONLY' | 'CONFIG_EDITABILITY_FULL'; export type V1DAIEngineProfile = {name?: string | undefined, displayName?: string | undefined, priority?: number | undefined, enabled?: boolean | undefined, assignedOidcRolesEnabled?: boolean | undefined, assignedOidcRoles?: Array | undefined, maxRunningEngines?: (number | null) | undefined, cpuConstraint?: V1ProfileConstraintNumeric | undefined, gpuConstraint?: V1ProfileConstraintNumeric | undefined, memoryBytesConstraint?: V1ProfileConstraintNumeric | undefined, storageBytesConstraint?: V1ProfileConstraintNumeric | undefined, maxIdleDurationConstraint?: V1ProfileConstraintDuration | undefined, maxRunningDurationConstraint?: V1ProfileConstraintDuration | undefined, maxNonInteractionDuration?: (string | null) | undefined, maxUnusedDuration?: (string | null) | undefined, configurationOverride?: {[key: string]: string} | undefined, baseConfiguration?: {[key: string]: string} | undefined, configEditability?: DAIEngineProfileConfigEditability | undefined, yamlPodTemplateSpec?: string | undefined, yamlGpuTolerations?: string | undefined, tritonEnabled?: boolean | undefined, createTime?: string | undefined, updateTime?: (string | null) | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined, gpuResourceName?: string | undefined, dataDirectoryStorageClass?: string | undefined}; export type CreateApiV1ParentDaiEngineProfilesArgs = {parent: string, daiEngineProfileId: string, body: V1DAIEngineProfile}; export type CreateApiV1ParentDaiEngineProfilesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1ProfileConstraintNumeric = z.object({min: z.string().optional(), max: z.string().nullable().optional(), default: z.string().optional(), cumulativeMax: z.string().nullable().optional()}); export const v1ProfileConstraintDuration = z.object({min: z.string().optional(), max: z.string().nullable().optional(), default: z.string().optional()}); export const dAIEngineProfileConfigEditability = z.enum(["CONFIG_EDITABILITY_UNSPECIFIED", "CONFIG_EDITABILITY_DISABLED", "CONFIG_EDITABILITY_BASE_CONFIG_ONLY", "CONFIG_EDITABILITY_FULL"]); export const v1DAIEngineProfile = z.object({name: z.string().optional(), displayName: z.string().optional(), priority: z.number().int().optional(), enabled: z.boolean().optional(), assignedOidcRolesEnabled: z.boolean().optional(), assignedOidcRoles: z.array(z.string()).optional(), maxRunningEngines: z.number().int().nullable().optional(), cpuConstraint: v1ProfileConstraintNumeric.optional(), gpuConstraint: v1ProfileConstraintNumeric.optional(), memoryBytesConstraint: v1ProfileConstraintNumeric.optional(), storageBytesConstraint: v1ProfileConstraintNumeric.optional(), maxIdleDurationConstraint: v1ProfileConstraintDuration.optional(), maxRunningDurationConstraint: v1ProfileConstraintDuration.optional(), maxNonInteractionDuration: z.string().nullable().optional(), maxUnusedDuration: z.string().nullable().optional(), configurationOverride: z.record(z.string(), z.string()).optional(), baseConfiguration: z.record(z.string(), z.string()).optional(), configEditability: dAIEngineProfileConfigEditability.optional(), yamlPodTemplateSpec: z.string().optional(), yamlGpuTolerations: z.string().optional(), tritonEnabled: z.boolean().optional(), createTime: z.string().optional(), updateTime: z.string().nullable().optional(), creator: z.string().optional(), updater: z.string().optional(), creatorDisplayName: z.string().optional(), updaterDisplayName: z.string().optional(), gpuResourceName: z.string().optional(), dataDirectoryStorageClass: z.string().optional()}); export const v1CreateDAIEngineProfileResponse = z.object({daiEngineProfile: v1DAIEngineProfile.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 new DAIEngineProfile. * * POST /v1/{parent}/daiEngineProfiles */ export const createApiV1ParentDaiEngineProfiles = async (args: CreateApiV1ParentDaiEngineProfilesArgs, options: CreateApiV1ParentDaiEngineProfilesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.daiEngineProfileId != null) query.append("daiEngineProfileId", String(args.daiEngineProfileId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/daiEngineProfiles${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(v1CreateDAIEngineProfileResponse, await res.json()) };