import {z} from 'zod' export type V1IDEEngineState = 'STATE_UNSPECIFIED' | 'STATE_STARTING' | 'STATE_RUNNING' | 'STATE_PAUSING' | 'STATE_PAUSED' | 'STATE_FAILED' | 'STATE_DELETING' | 'STATE_TERMINATED'; export type V1IDEEngine = {name?: string | undefined, displayName?: string | undefined, state?: V1IDEEngineState | undefined, reconciling?: boolean | undefined, uid?: string | undefined, creator?: string | undefined, createTime?: string | undefined}; export type CreateApiV1ParentIdeEnginesArgs = {parent: string, ideEngineId: string, body: V1IDEEngine}; export type CreateApiV1ParentIdeEnginesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1IDEEngineState = z.enum(["STATE_UNSPECIFIED", "STATE_STARTING", "STATE_RUNNING", "STATE_PAUSING", "STATE_PAUSED", "STATE_FAILED", "STATE_DELETING", "STATE_TERMINATED"]); export const v1IDEEngine = z.object({name: z.string().optional(), displayName: z.string().optional(), state: v1IDEEngineState.optional(), reconciling: z.boolean().optional(), uid: z.string().optional(), creator: z.string().optional(), createTime: z.string().optional()}); export const v1CreateIDEEngineResponse = z.object({ideEngine: v1IDEEngine.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 IDEEngine within a specified workspace. * * POST /v1/{parent}/ideEngines */ export const createApiV1ParentIdeEngines = async (args: CreateApiV1ParentIdeEnginesArgs, options: CreateApiV1ParentIdeEnginesOptions) => { 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.ideEngineId != null) query.append("ideEngineId", String(args.ideEngineId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/ideEngines${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(v1CreateIDEEngineResponse, await res.json()) };