import {z} from 'zod' export type GetApiAideV1NamespacesNamespaceNotebooksNotebookNameLogArgs = {namespace: unknown, notebook_name: unknown, currentPage?: number | undefined, pageSize?: number | undefined, asc?: boolean | undefined}; export type GetApiAideV1NamespacesNamespaceNotebooksNotebookNameLogOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const notebookLog = z.object({log: z.string().optional()}); export const getNotebookLogResponse = z.object({total: z.number().int(), log_list: z.array(notebookLog).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 log of notebook in the given namespace * * GET /aide/v1/namespaces/{namespace}/notebooks/{notebook_name}/log */ export const getApiAideV1NamespacesNamespaceNotebooksNotebookNameLog = async (args: GetApiAideV1NamespacesNamespaceNotebooksNotebookNameLogArgs, options?: GetApiAideV1NamespacesNamespaceNotebooksNotebookNameLogOptions) => { const {baseUrl = "https://gateway.mlss.aide", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.currentPage != null) query.append("currentPage", String(args.currentPage)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.asc != null) query.append("asc", String(args.asc)) const url = `${baseUrl.replace(/\/+$/, '')}/aide/v1/namespaces/${encodeURIComponent(String(args.namespace))}/notebooks/${encodeURIComponent(String(args.notebook_name))}/log${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(getNotebookLogResponse, await res.json()) };