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 V1NotebookEngineProfile = {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, yamlPodTemplateSpec?: string | undefined, yamlGpuTolerations?: string | undefined, createTime?: string | undefined, updateTime?: (string | null) | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined, storageClassName?: string | undefined, gpuResourceName?: string | undefined, syncGitRepositoryEnabled?: boolean | undefined, gitRepository?: string | undefined, gitRef?: string | undefined, gitDirectoryName?: string | undefined}; export type CreateApiV1ParentNotebookEngineProfilesArgs = {parent: string, notebookEngineProfileId: string, body: V1NotebookEngineProfile}; export type CreateApiV1ParentNotebookEngineProfilesOptions = {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 v1NotebookEngineProfile = 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(), yamlPodTemplateSpec: z.string().optional(), yamlGpuTolerations: z.string().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(), storageClassName: z.string().optional(), gpuResourceName: z.string().optional(), syncGitRepositoryEnabled: z.boolean().optional(), gitRepository: z.string().optional(), gitRef: z.string().optional(), gitDirectoryName: z.string().optional()}); export const v1CreateNotebookEngineProfileResponse = z.object({notebookEngineProfile: v1NotebookEngineProfile.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 NotebookEngineProfile. * * POST /v1/{parent}/notebookEngineProfiles */ export const createApiV1ParentNotebookEngineProfiles = async (args: CreateApiV1ParentNotebookEngineProfilesArgs, options: CreateApiV1ParentNotebookEngineProfilesOptions) => { 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.notebookEngineProfileId != null) query.append("notebookEngineProfileId", String(args.notebookEngineProfileId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/notebookEngineProfiles${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(v1CreateNotebookEngineProfileResponse, await res.json()) };