import {z} from 'zod' export type GetApiApiV1ProjectsArgs = {page?: number | undefined, duration?: number | undefined, order?: ('asc' | 'desc') | undefined, orderBy?: ('id' | 'created_at') | undefined, width?: string | undefined, height?: string | undefined, name?: string | undefined}; export type GetApiApiV1ProjectsOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const project = z.object({id: z.number().int().optional(), project_name: z.string().optional(), sitemap_path: z.string().optional(), is_chat_active: z.boolean().optional(), is_master: z.boolean().optional(), user_id: z.number().int().optional(), team_id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().nullable().optional(), type: z.enum(["SITEMAP", "URL"]).optional(), is_shared: z.boolean().optional(), shareable_slug: z.string().nullable().optional(), shareable_link: z.string().nullable().optional(), embed_code: z.string().nullable().optional(), live_chat_code: z.string().nullable().optional(), are_licenses_allowed: z.boolean().optional(), subdomain_slug: z.string().nullable().optional()}); export const getApiApiV1ProjectsResponse = z.object({status: z.enum(["error", "success"]).optional(), data: z.object({current_page: z.number().int().optional(), data: z.array(project).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 all agents. * * GET /api/v1/projects */ export const getApiApiV1Projects = async (args: GetApiApiV1ProjectsArgs, options?: GetApiApiV1ProjectsOptions) => { 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.duration != null) query.append("duration", String(args.duration)) if (args.order != null) query.append("order", String(args.order)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.width != null) query.append("width", String(args.width)) if (args.height != null) query.append("height", String(args.height)) if (args.name != null) query.append("name", String(args.name)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects${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(getApiApiV1ProjectsResponse, await res.json()) };