import {z} from 'zod' export type GetApiV1WorkflowsDeploymentsNameArgs = {name: string, workflow_name?: (string | null) | undefined}; export type GetApiV1WorkflowsDeploymentsNameOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const locationType = z.enum(["local", "k8s", "managed"]); export const deploymentLocation = z.object({location_type: locationType, k8s_cluster: z.string().nullable().optional(), k8s_namespace: z.string().nullable().optional()}); export const deploymentSecretBinding = z.object({env_var_name: z.string(), reference: z.string()}); export const deploymentMistralCloudBackendSpec = z.object({type: z.enum(["mistral_cloud", "koyeb"]).optional(), build_directory: z.string().nullable().optional(), dockerfile_path: z.string().nullable().optional(), secrets: z.array(deploymentSecretBinding).nullable().optional()}); export const deploymentK8sBackendSpec = z.object({type: z.literal("kubernetes").optional(), entrypoint: z.string().nullable().optional(), working_dir: z.string().nullable().optional()}); export const gitCommitAuthor = z.object({name: z.string().nullable().optional(), username: z.string().nullable().optional(), html_url: z.string().nullable().optional()}); export const gitCommitMetadata = z.object({sha: z.string(), message: z.string().nullable().optional(), author: gitCommitAuthor.nullable().optional(), html_url: z.string().nullable().optional()}); export const deploymentWorkerSpecResponse = z.object({github_url: z.string(), type: z.string().optional(), revision: z.string().nullable().optional(), backend_spec: z.discriminatedUnion("type", [deploymentMistralCloudBackendSpec, deploymentK8sBackendSpec]), restarted_at: z.string().nullable().optional(), commit: gitCommitMetadata.nullable().optional()}); export const deploymentResourceConfig = z.object({replicas: z.number().int().nullable().optional()}); export const deploymentBuildState = z.object({phase: z.string().nullable().optional(), commit_sha: z.string().nullable().optional(), image: z.string().nullable().optional(), message: z.string().nullable().optional(), started_at: z.string().nullable().optional(), finished_at: z.string().nullable().optional()}); export const deploymentObservedState = z.object({phase: z.string().nullable().optional(), available_replicas: z.number().int().optional(), ready_replicas: z.number().int().optional(), endpoint: z.string().nullable().optional(), message: z.string().nullable().optional(), last_seen: z.string().nullable().optional(), deployed_revision: z.string().nullable().optional(), generation: z.number().int().nullable().optional(), build_state: deploymentBuildState.nullable().optional()}); export const principalType = z.enum(["api_key", "service_account", "user"]); export const managedDeploymentResponse = z.object({service_id: z.string(), name: z.string(), spec: deploymentWorkerSpecResponse, resources: deploymentResourceConfig, status: deploymentObservedState, created_at: z.string(), updated_at: z.string(), stopped: z.boolean().optional(), rollout_status: z.string().nullable().optional(), created_by: z.string().nullable().optional(), updated_by: z.string().nullable().optional(), deployed_by: z.string().nullable().optional(), deployed_at: z.string().nullable().optional(), is_hardened: z.boolean().optional(), runtime_credential_id: z.string().nullable().optional(), runtime_principal_type: principalType.nullable().optional()}); export const deploymentWorkerResponse = z.object({name: z.string(), created_at: z.string(), last_heartbeat: z.string(), updated_at: z.string(), is_active: z.boolean(), location: deploymentLocation.nullable().optional()}); export const deploymentDetailResponse = z.object({id: z.string(), name: z.string(), is_active: z.boolean(), is_hardened: z.boolean().optional(), created_at: z.string(), last_heartbeat: z.string(), updated_at: z.string(), owner: z.string().nullable().optional(), location: deploymentLocation.nullable().optional(), worker_count: z.number().int().optional(), active_worker_count: z.number().int().optional(), locations: z.array(locationType).optional(), managed: managedDeploymentResponse.nullable().optional(), workers: z.array(deploymentWorkerResponse)}); 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 Deployment * * GET /v1/workflows/deployments/{name} */ export const getApiV1WorkflowsDeploymentsName = async (args: GetApiV1WorkflowsDeploymentsNameArgs, options?: GetApiV1WorkflowsDeploymentsNameOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workflow_name != null) query.append("workflow_name", String(args.workflow_name)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/deployments/${encodeURIComponent(String(args.name))}${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(deploymentDetailResponse, await res.json()) };