import {z} from 'zod' export type UpdateAutoscalingSettingsV1 = {min_replica?: (number | null) | undefined, max_replica?: (number | null) | undefined, autoscaling_window?: (number | null) | undefined, scale_down_delay?: (number | null) | undefined, concurrency_target?: (number | null) | undefined, target_utilization_percentage?: (number | null) | undefined, target_in_flight_tokens?: (number | null) | undefined, max_scale_down_rate?: (number | null) | undefined}; export type PromotionCleanupStrategyV1 = 'KEEP' | 'SCALE_TO_ZERO' | 'DEACTIVATE'; export type RollingDeployStrategyV1 = 'REPLICA'; export type UpdateRollingDeployConfigV1 = {rolling_deploy_strategy?: (RollingDeployStrategyV1 | null) | undefined, max_surge_percent?: (number | null) | undefined, max_unavailable_percent?: (number | null) | undefined, stabilization_time_seconds?: (number | null) | undefined, replica_overhead_percent?: (number | null) | undefined}; export type UpdatePromotionSettingsV1 = {redeploy_on_promotion?: (boolean | null) | undefined, rolling_deploy?: (boolean | null) | undefined, promotion_cleanup_strategy?: (PromotionCleanupStrategyV1 | null) | undefined, rolling_deploy_config?: (UpdateRollingDeployConfigV1 | null) | undefined, ramp_up_while_promoting?: (boolean | null) | undefined, ramp_up_duration_seconds?: (number | null) | undefined}; export type CreateEnvironmentRequestV1 = {name: string, autoscaling_settings?: (UpdateAutoscalingSettingsV1 | null) | undefined, promotion_settings?: (UpdatePromotionSettingsV1 | null) | undefined}; export type CreateApiV1ModelsModelIdEnvironmentsArgs = {body: CreateEnvironmentRequestV1}; export type CreateApiV1ModelsModelIdEnvironmentsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentStatusV1 = z.enum(["BUILDING", "DEPLOYING", "DEPLOY_FAILED", "LOADING_MODEL", "ACTIVE", "UNHEALTHY", "BUILD_FAILED", "BUILD_STOPPED", "DEACTIVATING", "INACTIVE", "FAILED", "UPDATING", "SCALED_TO_ZERO", "WAKING_UP"]); export const autoscalingSettingsV1 = z.object({min_replica: z.number().int(), max_replica: z.number().int(), autoscaling_window: z.number().int().nullable(), scale_down_delay: z.number().int().nullable(), concurrency_target: z.number().int(), target_utilization_percentage: z.number().int().nullable(), target_in_flight_tokens: z.number().int().nullable().optional(), max_scale_down_rate: z.number().int().nullable().optional()}); export const deploymentV1 = z.object({id: z.string(), created_at: z.string(), name: z.string(), model_id: z.string(), is_production: z.boolean(), is_development: z.boolean(), status: deploymentStatusV1, active_replica_count: z.number().int(), autoscaling_settings: autoscalingSettingsV1.nullable(), instance_type_name: z.string().nullable(), environment: z.string().nullable(), labels: z.record(z.string(), z.unknown()).nullable().optional()}); export const inProgressPromotionStatusV1 = z.enum(["RELEASING", "RAMPING_UP", "RAMPING_DOWN", "PAUSED", "SUCCEEDED", "FAILED", "CANCELED"]); export const inProgressPromotionV1 = z.object({status: inProgressPromotionStatusV1, percent_traffic_to_new_version: z.number().int(), error_message: z.string().nullable().optional(), rolling_deploy: z.boolean().nullable().optional()}); export const promotionCleanupStrategyV1 = z.enum(["KEEP", "SCALE_TO_ZERO", "DEACTIVATE"]); export const rollingDeployStrategyV1 = z.literal("REPLICA"); export const rollingDeployConfigV1 = z.object({rolling_deploy_strategy: rollingDeployStrategyV1.optional(), max_surge_percent: z.number().int().optional(), max_unavailable_percent: z.number().int().optional(), stabilization_time_seconds: z.number().int().optional(), replica_overhead_percent: z.number().int().optional()}); export const promotionSettingsV1 = z.object({redeploy_on_promotion: z.boolean().nullable().optional(), rolling_deploy: z.boolean().nullable().optional(), promotion_cleanup_strategy: promotionCleanupStrategyV1.nullable().optional(), rolling_deploy_config: rollingDeployConfigV1.nullable().optional(), ramp_up_while_promoting: z.boolean().nullable().optional(), ramp_up_duration_seconds: z.number().int().nullable().optional()}); export const instanceTypeV1 = z.object({id: z.string(), name: z.string(), memory_limit_mib: z.number().int(), millicpu_limit: z.number().int(), gpu_count: z.number().int(), gpu_type: z.string().nullable(), gpu_memory_limit_mib: z.number().int().nullable()}); export const environmentV1 = z.object({name: z.string(), created_at: z.string(), model_id: z.string(), current_deployment: deploymentV1.nullable(), candidate_deployment: deploymentV1.nullable().optional(), in_progress_promotion: inProgressPromotionV1.nullable().optional(), autoscaling_settings: autoscalingSettingsV1, promotion_settings: promotionSettingsV1, instance_type: instanceTypeV1}); 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 }; /** * Creates an environment * * POST /v1/models/{model_id}/environments */ export const createApiV1ModelsModelIdEnvironments = async (args: CreateApiV1ModelsModelIdEnvironmentsArgs, options: CreateApiV1ModelsModelIdEnvironmentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/models/${encodeURIComponent(String(args.model_id))}/environments${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(environmentV1, await res.json()) };