import {z} from 'zod' export type GetApiApiV1ProjectsProjectIdTasksArgs = {projectId: number, page?: number | undefined, limit?: number | undefined}; export type GetApiApiV1ProjectsProjectIdTasksOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const task = z.object({id: z.string().optional(), project_id: z.number().int().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const getApiApiV1ProjectsProjectIdTasksResponse = z.object({status: z.enum(["error", "success"]).optional(), data: z.object({current_page: z.number().int().optional(), data: z.array(task).optional(), first_page_url: z.string().optional(), from: z.number().int().optional(), last_page: z.number().int().optional(), last_page_url: z.string().optional(), next_page_url: z.string().optional(), path: z.string().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().optional(), to: z.number().int().optional(), total: z.number().int().optional()}).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 }; /** * List tasks. * * GET /api/v1/projects/{projectId}/tasks */ export const getApiApiV1ProjectsProjectIdTasks = async (args: GetApiApiV1ProjectsProjectIdTasksArgs, options?: GetApiApiV1ProjectsProjectIdTasksOptions) => { const {baseUrl = "https://app.customgpt.ai", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectId))}/tasks${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(getApiApiV1ProjectsProjectIdTasksResponse, await res.json()) };