import {z} from 'zod' export type LM = {model: string, kwargs?: ({[key: string]: unknown} | null) | undefined}; export type GepaKwargs = {auto?: ('light' | 'medium' | 'heavy' | null) | undefined, max_full_evals?: (number | null) | undefined, max_metric_calls?: (number | null) | undefined, reflection_minibatch_size?: number | undefined, candidate_selection_strategy?: ('pareto' | 'current_best') | undefined, reflection_lm?: (LM | null) | undefined, skip_perfect_score?: boolean | undefined, add_format_failure_as_feedback?: boolean | undefined, component_selector?: ('round_robin' | 'all') | undefined, use_merge?: boolean | undefined, max_merge_invocations?: (number | null) | undefined, seed?: (number | null) | undefined, gepa_kwargs?: ({[key: string]: unknown} | null) | undefined}; export type GepaJobRequest = {arbiter_repo: string, arbiter_revision?: string | undefined, push_branch?: string | undefined, push_tag?: (string | null) | undefined, gepa_kwargs?: GepaKwargs | undefined}; export type CreateApiApiV1JobsGepaArgs = {authorization?: (string | null) | undefined, modaic_session?: (string | null) | undefined, body: GepaJobRequest}; export type CreateApiApiV1JobsGepaOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiApiV1JobsGepaResponse = 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 }; /** * Start Optimization Job * * POST /api/v1/jobs/gepa */ export const createApiApiV1JobsGepa = async (args: CreateApiApiV1JobsGepaArgs, options: CreateApiApiV1JobsGepaOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const cookies: string[] = [] headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args.modaic_session != null) cookies.push("modaic_session=" + encodeURIComponent(String(args.modaic_session))) if (cookies.length > 0) headers.set('cookie', cookies.join('; ')) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/jobs/gepa${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(createApiApiV1JobsGepaResponse, await res.json()) };