import {z} from 'zod' export type CreateApiV1WorkspacesIdAutomaticSearchArgs = {id: string, 'Idempotency-Key'?: string | undefined, wait_seconds?: number | undefined, body: {query: string, context?: string | undefined, path_prefix?: string | undefined, paths?: Array | undefined, output_schema?: {[key: string]: unknown} | undefined, top_k?: number | undefined, mode?: ('auto' | 'fact' | 'agent') | undefined}}; export type CreateApiV1WorkspacesIdAutomaticSearchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceJob = z.object({job_id: z.string(), kind: z.string(), status: z.enum(["queued", "running", "succeeded", "failed", "cancelled"]), workspace_id: z.string().optional(), result: z.unknown()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Automatic search * * POST /v1/workspaces/{id}/automatic-search */ export const createApiV1WorkspacesIdAutomaticSearch = async (args: CreateApiV1WorkspacesIdAutomaticSearchArgs, options?: CreateApiV1WorkspacesIdAutomaticSearchOptions) => { const {baseUrl = "https://console.nace.ai", 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args.wait_seconds != null) query.append("wait_seconds", String(args.wait_seconds)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.id))}/automatic-search${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(workspaceJob, await res.json()) };