import {z} from 'zod' export type DedicatedEngineBase = {id?: number | undefined, name?: string | undefined, description?: string | undefined, url?: string | undefined, status?: ('draft' | 'schema_review' | 'annotating_initial' | 'annotating_review' | 'annotating_training' | 'training_started' | 'training_finished' | 'retraining' | 'sample_review') | undefined, schema?: (string | null) | undefined, queues?: Array | undefined}; export type CreateApiApiV1DedicatedEnginesArgs = {body: DedicatedEngineBase}; export type CreateApiApiV1DedicatedEnginesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dedicatedEngine = z.object({id: z.number().int(), name: z.string(), description: z.string(), url: z.string(), status: z.enum(["draft", "schema_review", "annotating_initial", "annotating_review", "annotating_training", "training_started", "training_finished", "retraining", "sample_review"]), schema: z.string().nullable(), queues: z.array(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 }; /** * Create dedicated engine * * POST /api/v1/dedicated_engines */ export const createApiApiV1DedicatedEngines = async (args: CreateApiApiV1DedicatedEnginesArgs, options?: CreateApiApiV1DedicatedEnginesOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/dedicated_engines${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(dedicatedEngine, await res.json()) };