import {z} from 'zod' export type GetApiApiOrgIdExperimentsExperimentIdSlotsArgs = {org_id: string, experiment_id: string, from?: (number | null) | undefined, size?: (number | null) | undefined}; export type GetApiApiOrgIdExperimentsExperimentIdSlotsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const experimentSlotBody = z.object({expectedOutput: z.unknown(), input: z.unknown(), logicalId: z.string(), metadata: z.unknown(), rowId: z.string(), trialIndex: z.number().int().gte(0)}); export const getApiApiOrgIdExperimentsExperimentIdSlotsResponse = z.object({from: z.number().int().gte(0), hasMore: z.boolean(), size: z.number().int().gte(0), slots: z.array(experimentSlotBody), total: z.number().int().gte(0)}); 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 }; /** * Page through the Experiment's immutable Slot set * * GET /api/{org_id}/experiments/{experiment_id}/slots */ export const getApiApiOrgIdExperimentsExperimentIdSlots = async (args: GetApiApiOrgIdExperimentsExperimentIdSlotsArgs, options: GetApiApiOrgIdExperimentsExperimentIdSlotsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.size != null) query.append("size", String(args.size)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/experiments/${encodeURIComponent(String(args.experiment_id))}/slots${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(getApiApiOrgIdExperimentsExperimentIdSlotsResponse, await res.json()) };