import {z} from 'zod' export type GetApiAideV1NotebooksIdStatusArgs = {id: unknown}; export type GetApiAideV1NotebooksIdStatusOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const resource = z.object({cpu: z.string().optional(), gpu: z.string().optional(), memory: z.string().optional()}); export const containerStatusInfo = z.object({container_name: z.string().optional(), namespace: z.string().optional(), containerId: z.string().optional(), startedTime: z.string().optional(), fineshedTime: z.string().optional(), containerStatusType: z.string().optional(), message: z.string().optional(), lastStartedTime: z.string().optional(), lastFinishedTime: z.string().optional(), lastContainerStateType: z.string().optional(), lastMessage: z.string().optional()}); export const getNotebookStatusResponse = z.object({name: z.string().optional(), namespace: z.string().optional(), resource_req: resource.optional(), resource_limit: resource.optional(), image: z.string().optional(), create_time: z.string().optional(), notebook_status: z.string().optional(), notebook_status_info: z.string().optional(), containers_status_info: z.array(containerStatusInfo).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 }; /** * Get the status of Notebooks in the given Namespace * * GET /aide/v1/notebooks/{id}/status */ export const getApiAideV1NotebooksIdStatus = async (args: GetApiAideV1NotebooksIdStatusArgs, options?: GetApiAideV1NotebooksIdStatusOptions) => { const {baseUrl = "https://gateway.mlss.aide", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/aide/v1/notebooks/${encodeURIComponent(String(args.id))}/status${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getNotebookStatusResponse, await res.json()) };