import {z} from 'zod' export type GetApiV1ProjectsProjectIdPreviewDeploymentsTrainingJobIdArgs = {project_id: string, training_job_id: string}; export type GetApiV1ProjectsProjectIdPreviewDeploymentsTrainingJobIdOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const previewState = z.enum(["ready", "warming", "provisioning", "inactive", "failed", "unavailable"]); export const deployabilityReason = z.enum(["project_mismatch", "job_deleted", "job_incomplete", "job_failed", "job_cancelled", "missing_artifact", "provider_incompatible"]); export const previewDeploymentResponse = z.object({training_job_id: z.string(), state: previewState, detail: z.string(), can_send_requests: z.boolean(), reason: deployabilityReason.nullable().optional(), retry_after_seconds: z.number().int().nullable().optional(), can_activate: z.boolean(), attempt_count: z.number().int(), retry_exhausted: z.boolean().optional()}); 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 }; /** * Get the preview status of one fine-tuned version * * GET /v1/projects/{project_id}/preview-deployments/{training_job_id} * * Also accepts auth: BearerAuth */ export const getApiV1ProjectsProjectIdPreviewDeploymentsTrainingJobId = async (args: GetApiV1ProjectsProjectIdPreviewDeploymentsTrainingJobIdArgs, options: GetApiV1ProjectsProjectIdPreviewDeploymentsTrainingJobIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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))}/preview-deployments/${encodeURIComponent(String(args.training_job_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(previewDeploymentResponse, await res.json()) };