import {z} from 'zod' export type DtoJobTaskRequest = {file_path: string}; export type CreateApiApiV1ProjectProjectidJobsIdTasksTaskidLogsArgs = {projectid: string, id: number, taskid: string, source?: string | undefined, cursor?: string | undefined, limit?: number | undefined, direction?: string | undefined, body: DtoJobTaskRequest}; export type CreateApiApiV1ProjectProjectidJobsIdTasksTaskidLogsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dtoJobTaskLogsResponse = z.object({has_more_newer: z.boolean().optional(), has_more_older: z.boolean().optional(), logs: z.array(z.object({})).optional(), newer_cursor: z.string().optional(), older_cursor: z.string().optional()}); export const createApiApiV1ProjectProjectidJobsIdTasksTaskidLogsResponse = z.object({data: dtoJobTaskLogsResponse.optional(), message: z.string().optional(), success: z.boolean().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 task logs * * POST /api/v1/project/{projectid}/jobs/{id}/tasks/{taskid}/logs */ export const createApiApiV1ProjectProjectidJobsIdTasksTaskidLogs = async (args: CreateApiApiV1ProjectProjectidJobsIdTasksTaskidLogsArgs, options: CreateApiApiV1ProjectProjectidJobsIdTasksTaskidLogsOptions) => { 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.source != null) query.append("source", String(args.source)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.direction != null) query.append("direction", String(args.direction)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/project/${encodeURIComponent(String(args.projectid))}/jobs/${encodeURIComponent(String(args.id))}/tasks/${encodeURIComponent(String(args.taskid))}/logs${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(createApiApiV1ProjectProjectidJobsIdTasksTaskidLogsResponse, await res.json()) };