import {z} from 'zod' export type UUIDSchema = string; export type GetApiInspectImageUuidListArgs = {image_uuid: UUIDSchema, path: string, text?: boolean | undefined}; export type GetApiInspectImageUuidListOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const fileItem = z.object({size: z.number().int(), path: z.string(), owner: z.union([z.string(), z.number().int()]), group: z.union([z.string(), z.number().int()]), uid: z.number().int(), gid: z.number().int(), mode: z.number().int(), mtime: z.number().int(), nlink: z.number().int(), is_dir: z.boolean(), is_regular: z.boolean(), is_symlink: z.boolean(), is_socket: z.boolean(), is_fifo: z.boolean(), symlink_to: z.string()}); export const directoryList = z.object({path: z.string(), files: z.array(fileItem)}); 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 }; /** * List files in image * * GET /inspect/{image_uuid}/list */ export const getApiInspectImageUuidList = async (args: GetApiInspectImageUuidListArgs, options?: GetApiInspectImageUuidListOptions) => { const {baseUrl = "https://api.tokenfactory.nebius.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.path != null) query.append("path", String(args.path)) if (args.text != null) query.append("text", String(args.text)) const url = `${baseUrl.replace(/\/+$/, '')}/inspect/${encodeURIComponent(String(args.image_uuid))}/list${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(directoryList, await res.json()) };