import {z} from 'zod' export type GetApiV1AnnotationQueuesQueueIdItemsArgs = {CONFIDENT_API_KEY: string, queueId: string, page?: number | undefined, pageSize?: number | undefined, start?: string | undefined, end?: string | undefined, sortBy?: 'addedAt' | undefined, ascending?: ('true' | 'false') | undefined, completed?: string | undefined}; export type GetApiV1AnnotationQueuesQueueIdItemsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const listQueueItemsResponse = z.object({success: z.boolean(), data: z.object({items: z.array(z.object({id: z.string().optional(), traceUuid: z.string().optional(), spanUuid: z.string().optional(), threadId: z.string().optional(), testCaseId: z.string().optional(), addedAt: z.string().optional(), completed: z.boolean().optional(), assignedToEmail: z.string().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 Queue Items * * GET /v1/annotation-queues/{queueId}/items */ export const getApiV1AnnotationQueuesQueueIdItems = async (args: GetApiV1AnnotationQueuesQueueIdItemsArgs, options?: GetApiV1AnnotationQueuesQueueIdItemsOptions) => { const {baseUrl = "https://api.confident-ai.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.CONFIDENT_API_KEY != null) headers.set("CONFIDENT_API_KEY", String(args.CONFIDENT_API_KEY)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.ascending != null) query.append("ascending", String(args.ascending)) if (args.completed != null) query.append("completed", String(args.completed)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/annotation-queues/${encodeURIComponent(String(args.queueId))}/items${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(listQueueItemsResponse, await res.json()) };