import {z} from 'zod' export type V1NotebookEngineState = 'STATE_UNSPECIFIED' | 'STATE_STARTING' | 'STATE_RUNNING' | 'STATE_PAUSING' | 'STATE_PAUSED' | 'STATE_FAILED' | 'STATE_DELETING' | 'STATE_TERMINATED'; export type V1ImagePullPolicy = 'IMAGE_PULL_POLICY_UNSPECIFIED' | 'IMAGE_PULL_POLICY_ALWAYS' | 'IMAGE_PULL_POLICY_NEVER' | 'IMAGE_PULL_POLICY_IF_NOT_PRESENT'; export type V1NotebookEngineImageInfo = {image?: string | undefined, name?: string | undefined, displayName?: string | undefined, enabled?: boolean | undefined, imagePullPolicy?: V1ImagePullPolicy | undefined, imagePullSecrets?: Array | undefined, createTime?: string | undefined, updateTime?: (string | null) | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined}; 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 V1NotebookEngineProfileInfo = {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 NotebookEngineFailureReason = 'FAILURE_REASON_UNSPECIFIED' | 'FAILURE_REASON_UNKNOWN' | 'FAILURE_REASON_OOM_KILLED' | 'FAILURE_REASON_PROCESS_FAILED' | 'FAILURE_REASON_PVC_ACCESS_FAILURE'; export type PatchApiV1NotebookEngineNameArgs = {'notebookEngine.name': string, updateMask: string, body: {displayName?: string | undefined, profile: string, notebookImage: string, cpu?: (number | null) | undefined, gpu?: (number | null) | undefined, memoryBytes?: (unknown | null) | undefined, storageBytes?: (unknown | null) | undefined, maxIdleDuration?: (string | null) | undefined, maxRunningDuration?: (string | null) | undefined, state?: V1NotebookEngineState | undefined, reconciling?: boolean | undefined, uid?: string | undefined, notebookImageInfo?: V1NotebookEngineImageInfo | undefined, profileInfo?: V1NotebookEngineProfileInfo | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined, createTime?: string | undefined, updateTime?: (string | null) | undefined, resumeTime?: (string | null) | undefined, deleteTime?: (string | null) | undefined, currentIdleDuration?: (string | null) | undefined, currentRunningDuration?: (string | null) | undefined, storageClassName?: string | undefined, shared?: boolean | undefined, failureReason?: NotebookEngineFailureReason | undefined, storageResizing?: boolean | undefined}}; export type PatchApiV1NotebookEngineNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1NotebookEngineState = z.enum(["STATE_UNSPECIFIED", "STATE_STARTING", "STATE_RUNNING", "STATE_PAUSING", "STATE_PAUSED", "STATE_FAILED", "STATE_DELETING", "STATE_TERMINATED"]); export const v1ImagePullPolicy = z.enum(["IMAGE_PULL_POLICY_UNSPECIFIED", "IMAGE_PULL_POLICY_ALWAYS", "IMAGE_PULL_POLICY_NEVER", "IMAGE_PULL_POLICY_IF_NOT_PRESENT"]); export const v1NotebookEngineImageInfo = z.object({image: z.string().optional(), name: z.string().optional(), displayName: z.string().optional(), enabled: z.boolean().optional(), imagePullPolicy: v1ImagePullPolicy.optional(), imagePullSecrets: z.array(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()}); 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 v1NotebookEngineProfileInfo = 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 notebookEngineFailureReason = z.enum(["FAILURE_REASON_UNSPECIFIED", "FAILURE_REASON_UNKNOWN", "FAILURE_REASON_OOM_KILLED", "FAILURE_REASON_PROCESS_FAILED", "FAILURE_REASON_PVC_ACCESS_FAILURE"]); export const v1NotebookEngine = z.object({name: z.string().optional(), displayName: z.string().optional(), profile: z.string(), notebookImage: z.string(), cpu: z.number().int().nullable().optional(), gpu: z.number().int().nullable().optional(), memoryBytes: z.string().nullable().optional(), storageBytes: z.string().nullable().optional(), maxIdleDuration: z.string().nullable().optional(), maxRunningDuration: z.string().nullable().optional(), state: v1NotebookEngineState.optional(), reconciling: z.boolean().optional(), uid: z.string().optional(), notebookImageInfo: v1NotebookEngineImageInfo.optional(), profileInfo: v1NotebookEngineProfileInfo.optional(), creator: z.string().optional(), updater: z.string().optional(), creatorDisplayName: z.string().optional(), updaterDisplayName: z.string().optional(), createTime: z.string().optional(), updateTime: z.string().nullable().optional(), resumeTime: z.string().nullable().optional(), deleteTime: z.string().nullable().optional(), currentIdleDuration: z.string().nullable().optional(), currentRunningDuration: z.string().nullable().optional(), storageClassName: z.string().optional(), shared: z.boolean().optional(), failureReason: notebookEngineFailureReason.optional(), storageResizing: z.boolean().optional()}); export const v1UpdateNotebookEngineResponse = z.object({notebookEngine: v1NotebookEngine.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 }; /** * Updates a NotebookEngine. * * PATCH /v1/{notebookEngine.name} */ export const patchApiV1NotebookEngineName = async (args: PatchApiV1NotebookEngineNameArgs, options: PatchApiV1NotebookEngineNameOptions) => { 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.updateMask != null) query.append("updateMask", String(args.updateMask)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args['notebookEngine.name']))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(v1UpdateNotebookEngineResponse, await res.json()) };