import {z} from 'zod' export type V1SandboxEngineTemplate = {name?: string | undefined, displayName?: string | undefined, milliCpuRequest?: number | undefined, milliCpuLimit?: number | undefined, gpuResource?: string | undefined, gpu?: number | undefined, memoryBytesRequest?: unknown | undefined, memoryBytesLimit: unknown, storageBytes?: unknown | undefined, environmentalVariables?: {[key: string]: string} | undefined, yamlPodTemplateSpec?: string | undefined, enabled?: boolean | undefined, maxIdleDuration: string, maxRunningDuration: string, createTime?: string | undefined, updateTime?: (string | null) | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined}; export type CreateApiV1ParentSandboxEngineTemplatesArgs = {parent: string, sandboxEngineTemplateId?: string | undefined, body: V1SandboxEngineTemplate}; export type CreateApiV1ParentSandboxEngineTemplatesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1SandboxEngineTemplate = z.object({name: z.string().optional(), displayName: z.string().optional(), milliCpuRequest: z.number().int().optional(), milliCpuLimit: z.number().int().optional(), gpuResource: z.string().optional(), gpu: z.number().int().optional(), memoryBytesRequest: z.string().optional(), memoryBytesLimit: z.string(), storageBytes: z.string().optional(), environmentalVariables: z.record(z.string(), z.string()).optional(), yamlPodTemplateSpec: z.string().optional(), enabled: z.boolean().optional(), maxIdleDuration: z.string(), maxRunningDuration: z.string(), 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 v1CreateSandboxEngineTemplateResponse = z.object({sandboxEngineTemplate: v1SandboxEngineTemplate.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 SandboxEngineTemplate. * * POST /v1/{parent}/sandboxEngineTemplates */ export const createApiV1ParentSandboxEngineTemplates = async (args: CreateApiV1ParentSandboxEngineTemplatesArgs, options: CreateApiV1ParentSandboxEngineTemplatesOptions) => { 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.sandboxEngineTemplateId != null) query.append("sandboxEngineTemplateId", String(args.sandboxEngineTemplateId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/sandboxEngineTemplates${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(v1CreateSandboxEngineTemplateResponse, await res.json()) };