import {z} from 'zod' export type GetApiApiV1ProjectProjectsIdClusteringStatusArgs = {id: string, project_clustering_id?: number | undefined}; export type GetApiApiV1ProjectProjectsIdClusteringStatusOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const projectClusteringStatusResponse = z.object({document_clusters: z.array(z.object({})), project_clusters_documents_count: z.number().int(), project_clusters_actions_count: z.number().int(), status: z.string().nullable()}); 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 }; /** * Last Clustering task status/data * * GET /api/v1/project/projects/{id}/clustering-status/ */ export const getApiApiV1ProjectProjectsIdClusteringStatus = async (args: GetApiApiV1ProjectProjectsIdClusteringStatusArgs, options: GetApiApiV1ProjectProjectsIdClusteringStatusOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.project_clustering_id != null) query.append("project_clustering_id", String(args.project_clustering_id)) if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/project/projects/${encodeURIComponent(String(args.id))}/clustering-status/${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(projectClusteringStatusResponse, await res.json()) };