import {z} from 'zod' export type ChampionRequest = {training_job_id?: (string | null) | undefined, base_model?: (string | null) | undefined, reason?: (string | null) | undefined}; export type CreateApiV1ProjectsProjectIdVersionsVersionIdChampionArgs = {project_id: string, version_id: string, body: ChampionRequest}; export type CreateApiV1ProjectsProjectIdVersionsVersionIdChampionOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const projectVersionStatus = z.enum(["current", "frozen", "abandoned"]); export const championRef = z.object({training_job_id: z.string().nullable().optional(), base_model: z.string().nullable().optional()}); export const projectVersionResponse = z.object({id: z.string(), project_id: z.string(), team_id: z.string(), version_number: z.number().int(), status: projectVersionStatus, objective: z.string().nullable(), carryover_summary: z.string(), champion: championRef.nullable(), created_by: z.string(), closed_by: z.string().nullable(), closed_at: z.string().nullable(), created_at: z.string()}); export const championResponse = z.object({version: projectVersionResponse, deployment_id: z.string(), active_model_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 }; /** * Select a milestone version's champion model * * POST /v1/projects/{project_id}/versions/{version_id}/champion * * Also accepts auth: BearerAuth */ export const createApiV1ProjectsProjectIdVersionsVersionIdChampion = async (args: CreateApiV1ProjectsProjectIdVersionsVersionIdChampionArgs, options: CreateApiV1ProjectsProjectIdVersionsVersionIdChampionOptions) => { 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/projects/${encodeURIComponent(String(args.project_id))}/versions/${encodeURIComponent(String(args.version_id))}/champion${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(championResponse, await res.json()) };