import {z} from 'zod' export type RecordField = {name: string, type?: string | undefined, description?: (string | null) | undefined, allowed_values?: (Array | null) | undefined}; export type ConstraintRequest = {description: string, choices?: (Array | null) | undefined, weights?: (Array | null) | undefined, probability?: (number | null) | undefined}; export type LabelExistingFieldsRequest = {user_id?: (string | null) | undefined, input_fields: Array, output_fields: Array, inputs: Array<{[key: string]: unknown}>, domain_description?: (string | null) | undefined, seed?: (number | null) | undefined, session_id?: (string | null) | undefined, config_num_examples?: number | undefined, temperature?: number | undefined, constraints?: (Array | null) | undefined, save_dataset?: boolean | undefined, dataset_name?: (string | null) | undefined, project_id?: (string | null) | undefined}; export type CreateApiV1GenerateFieldsLabelExistingArgs = {body: LabelExistingFieldsRequest}; export type CreateApiV1GenerateFieldsLabelExistingOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const generateResponse = z.object({success: z.boolean(), data: z.array(z.record(z.string(), z.unknown())), count: z.number().int(), task_type: z.string(), token_usage: z.number().int().nullable().optional(), dataset: z.record(z.string(), z.unknown()).nullable().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 }; /** * Label Existing Fields * * POST /v1/generate/fields/label-existing * * Also accepts auth: BearerAuth */ export const createApiV1GenerateFieldsLabelExisting = async (args: CreateApiV1GenerateFieldsLabelExistingArgs, options: CreateApiV1GenerateFieldsLabelExistingOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/generate/fields/label-existing${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(generateResponse, await res.json()) };