import {z} from 'zod' export type ModelStages = 'none' | 'staging' | 'production' | 'archived' | 'latest'; export type ModelVersionUpdate = {model: string, stage?: (string | ModelStages | null) | undefined, force?: boolean | undefined, name?: (string | null) | undefined, description?: (string | null) | undefined, add_tags?: (Array | null) | undefined, remove_tags?: (Array | null) | undefined}; export type UpdateApiApiV1ModelVersionsModelVersionIdArgs = {model_version_id: string, body: ModelVersionUpdate}; export type UpdateApiApiV1ModelVersionsModelVersionIdOptions = {baseUrl: string, CookieOAuth2TokenBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userResponseBody = z.object({created: z.string(), updated: z.string(), active: z.boolean().optional(), activation_token: z.string().max(255).nullable().optional(), full_name: z.string().max(255).optional(), email_opted_in: z.boolean().nullable().optional(), is_service_account: z.boolean(), is_admin: z.boolean()}); export const userResponseMetadata = z.object({email: z.string().max(255).nullable().optional(), external_user_id: z.string().nullable().optional(), user_metadata: z.object({}).optional()}); export const userResponseResources = z.record(z.string(), z.unknown()); export const userResponse = z.object({body: userResponseBody.nullable().optional(), metadata: userResponseMetadata.nullable().optional(), resources: userResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const colorVariants = z.enum(["grey", "purple", "red", "green", "yellow", "orange", "lime", "teal", "turquoise", "magenta", "blue"]); export const tagResponseBody = z.object({created: z.string(), updated: z.string(), color: colorVariants.optional(), tagged_count: z.number().int()}); export const baseResponseMetadata = z.object({}); export const tagResponseResources = z.record(z.string(), z.unknown()); export const tagResponse = z.object({body: tagResponseBody.nullable().optional(), metadata: baseResponseMetadata.nullable().optional(), resources: tagResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const modelResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), tags: z.array(tagResponse), latest_version_name: z.string().nullable().optional(), latest_version_id: z.string().nullable().optional()}); export const workspaceResponseBody = z.object({created: z.string(), updated: z.string()}); export const workspaceResponseMetadata = z.object({description: z.string().max(255).optional()}); export const workspaceResponseResources = z.record(z.string(), z.unknown()); export const workspaceResponse = z.object({body: workspaceResponseBody.nullable().optional(), metadata: workspaceResponseMetadata.nullable().optional(), resources: workspaceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const modelResponseMetadata = z.object({workspace: workspaceResponse, license: z.string().max(65535).nullable().optional(), description: z.string().max(65535).nullable().optional(), audience: z.string().max(65535).nullable().optional(), use_cases: z.string().max(65535).nullable().optional(), limitations: z.string().max(65535).nullable().optional(), trade_offs: z.string().max(65535).nullable().optional(), ethics: z.string().max(65535).nullable().optional(), save_models_to_registry: z.boolean().optional()}); export const modelResponseResources = z.record(z.string(), z.unknown()); export const modelResponse = z.object({body: modelResponseBody.nullable().optional(), metadata: modelResponseMetadata.nullable().optional(), resources: modelResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const modelVersionResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), stage: z.string().max(255).nullable().optional(), number: z.number().int(), model: modelResponse, model_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), data_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), deployment_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), pipeline_run_ids: z.record(z.string(), z.string()).optional(), tags: z.array(tagResponse).optional()}); export const metadataTypeEnum = z.enum(["str", "int", "float", "bool", "list", "dict", "tuple", "set", "Uri", "Path", "DType", "StorageSize"]); export const runMetadataResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), key: z.string(), value: z.union([z.string(), z.number().int(), z.number(), z.boolean(), z.object({}), z.array(z.unknown()), z.array(z.unknown())]), type: metadataTypeEnum}); export const metadataResourceTypes = z.enum(["pipeline_run", "step_run", "artifact_version", "model_version"]); export const runMetadataResponseMetadata = z.object({workspace: workspaceResponse, resource_id: z.string(), resource_type: metadataResourceTypes, stack_component_id: z.string().nullable()}); export const runMetadataResponseResources = z.record(z.string(), z.unknown()); export const runMetadataResponse = z.object({body: runMetadataResponseBody.nullable().optional(), metadata: runMetadataResponseMetadata.nullable().optional(), resources: runMetadataResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const modelVersionResponseMetadata = z.object({workspace: workspaceResponse, description: z.string().max(65535).nullable().optional(), run_metadata: z.record(z.string(), runMetadataResponse).optional()}); export const serviceType = z.object({type: z.string(), flavor: z.string(), name: z.string().optional(), description: z.string().optional(), logo_url: z.string().optional()}); export const serviceState = z.enum(["inactive", "active", "pending_startup", "pending_shutdown", "error", "scaled_to_zero"]); export const serviceResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), service_type: serviceType, labels: z.record(z.string(), z.string()).nullable().optional(), state: serviceState.nullable().optional()}); export const serviceResponseMetadata = z.object({workspace: workspaceResponse, service_source: z.string().nullable(), admin_state: serviceState.nullable(), config: z.object({}), status: z.object({}).nullable(), endpoint: z.object({}).nullable().optional(), prediction_url: z.string().nullable().optional(), health_check_url: z.string().nullable().optional()}); export const serviceResponseResources = z.record(z.string(), z.unknown()); export const serviceResponse = z.object({body: serviceResponseBody.nullable().optional(), metadata: serviceResponseMetadata.nullable().optional(), resources: serviceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const pageServiceResponse = z.object({index: z.number().int().gt(0), max_size: z.number().int().gt(0), total_pages: z.number().int().gte(0), total: z.number().int().gte(0), items: z.array(serviceResponse)}); export const modelVersionResponseResources = z.object({services: pageServiceResponse}).and(z.record(z.string(), z.unknown())); export const modelVersionResponse = z.object({body: modelVersionResponseBody.nullable().optional(), metadata: modelVersionResponseMetadata.nullable().optional(), resources: modelVersionResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255).nullable().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 }; /** * Update Model Version * * PUT /api/v1/model_versions/{model_version_id} */ export const updateApiApiV1ModelVersionsModelVersionId = async (args: UpdateApiApiV1ModelVersionsModelVersionIdArgs, options: UpdateApiApiV1ModelVersionsModelVersionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, CookieOAuth2TokenBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (CookieOAuth2TokenBearer !== undefined) headers.set('authorization', `Bearer ${CookieOAuth2TokenBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/model_versions/${encodeURIComponent(String(args.model_version_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(modelVersionResponse, await res.json()) };