import {z} from 'zod' export type VersionCreateRequest = {revision_token: string, carryover_summary: string, objective?: (string | null) | undefined, abandon?: boolean | undefined, carry_dataset_ids?: (Array | null) | undefined}; export type CreateApiV1ProjectsProjectIdVersionsArgs = {project_id: string, body: VersionCreateRequest}; export type CreateApiV1ProjectsProjectIdVersionsOptions = {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 versionCreateResponse = z.object({closed: projectVersionResponse, current: projectVersionResponse}); 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 }; /** * Close the current milestone version and open the next * * POST /v1/projects/{project_id}/versions * * Also accepts auth: BearerAuth */ export const createApiV1ProjectsProjectIdVersions = async (args: CreateApiV1ProjectsProjectIdVersionsArgs, options: CreateApiV1ProjectsProjectIdVersionsOptions) => { 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${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(versionCreateResponse, await res.json()) };