import {z} from 'zod' export type GetApiV2DatasetsDatasetIdDatapointsDatapointIdArgs = {dataset_id: string, datapoint_id: string}; export type GetApiV2DatasetsDatasetIdDatapointsDatapointIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listValue = z.array(z.unknown()); export const datapoint = z.object({inputs: z.record(z.string(), z.unknown()).optional(), messages: listValue.optional(), expected_output: z.string().optional(), evaluations: listValue.optional(), dataset_id: z.string(), snapshot_version: z.string().optional(), created_by_id: z.string(), updated_by_id: z.string(), created: z.string().optional(), updated: z.string().optional(), workspace_id: z.string().optional(), _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 }; /** * Retrieve a datapoint * * GET /v2/datasets/{dataset_id}/datapoints/{datapoint_id} */ export const getApiV2DatasetsDatasetIdDatapointsDatapointId = async (args: GetApiV2DatasetsDatasetIdDatapointsDatapointIdArgs, options?: GetApiV2DatasetsDatasetIdDatapointsDatapointIdOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/datasets/${encodeURIComponent(String(args.dataset_id))}/datapoints/${encodeURIComponent(String(args.datapoint_id))}${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(datapoint, await res.json()) };