import {z} from 'zod' export type ProjectSearchSimilarTextUnitsRequest = {run_name?: string | undefined, distance_type?: ('braycurtis' | 'canberra' | 'chebyshev' | 'cityblock' | 'correlation' | 'cosine' | 'dice' | 'euclidean' | 'hamming' | 'jaccard' | 'jensenshannon' | 'kulsinski' | 'kulczynski1' | 'mahalanobis' | 'minkowski' | 'rogerstanimoto' | 'russellrao' | 'seuclidean' | 'sokalmichener' | 'sokalsneath' | 'sqeuclidean' | 'yule') | undefined, similarity_threshold?: number | undefined, create_reverse_relations?: boolean | undefined, use_tfidf?: boolean | undefined, delete?: boolean | undefined, item_id?: number | undefined, unit_type?: ('sentence' | 'paragraph') | undefined, document_id?: number | undefined, location_start?: number | undefined, location_end?: number | undefined}; export type CreateApiApiV1ProjectProjectsIdSearchSimilarTextUnitsArgs = {id: string, body: ProjectSearchSimilarTextUnitsRequest}; export type CreateApiApiV1ProjectProjectsIdSearchSimilarTextUnitsOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const taskIdResponse = z.object({task_id: z.string()}); 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 }; /** * POST /api/v1/project/projects/{id}/search_similar_text_units/ */ export const createApiApiV1ProjectProjectsIdSearchSimilarTextUnits = async (args: CreateApiApiV1ProjectProjectsIdSearchSimilarTextUnitsArgs, options: CreateApiApiV1ProjectProjectsIdSearchSimilarTextUnitsOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/project/projects/${encodeURIComponent(String(args.id))}/search_similar_text_units/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(taskIdResponse, await res.json()) };