import {z} from 'zod' export type GetApiApiV2ProjectsProjectIdAgentDatasetsArgs = {project_id: string, page?: number | undefined, page_size?: number | undefined, id?: (string | null) | undefined, name?: (string | null) | undefined}; export type GetApiApiV2ProjectsProjectIdAgentDatasetsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tagResponse = z.object({id: z.string(), name: z.string(), color: z.string(), association_count: z.number().int().optional()}); export const agentDatasetResponse = z.object({id: z.string(), name: z.string(), description: z.string().nullable(), compatible_agent_ids: z.array(z.string()), tags: z.array(tagResponse).optional()}); export const paginationInfo = z.object({page: z.number().int(), page_size: z.number().int(), has_next: z.boolean()}); export const getApiApiV2ProjectsProjectIdAgentDatasetsResponse = z.object({data: z.array(agentDatasetResponse), pagination: paginationInfo}); 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 Agent Datasets * * GET /api/v2/projects/{project_id}/agent-datasets */ export const getApiApiV2ProjectsProjectIdAgentDatasets = async (args: GetApiApiV2ProjectsProjectIdAgentDatasetsArgs, options: GetApiApiV2ProjectsProjectIdAgentDatasetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = 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.page_size != null) query.append("page_size", String(args.page_size)) if (args.id != null) query.append("id", String(args.id)) if (args.name != null) query.append("name", String(args.name)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/agent-datasets${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(getApiApiV2ProjectsProjectIdAgentDatasetsResponse, await res.json()) };