import {z} from 'zod' export type CreateApiV1WorkflowsDeploymentsNameRestartArgs = {name: string}; export type CreateApiV1WorkflowsDeploymentsNameRestartOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; 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 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 }; /** * Restart Deployment * * POST /v1/workflows/deployments/{name}/restart */ export const createApiV1WorkflowsDeploymentsNameRestart = async (args: CreateApiV1WorkflowsDeploymentsNameRestartArgs, options?: CreateApiV1WorkflowsDeploymentsNameRestartOptions) => { 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 (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/deployments/${encodeURIComponent(String(args.name))}/restart${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(managedDeploymentResponse, await res.json()) };