import {z} from 'zod' export type GetApiV1WorkflowsDeploymentsNameWorkersArgs = {name: string, worker_status?: ('active' | 'inactive' | null) | undefined, limit?: number | undefined, cursor?: (string | null) | undefined}; export type GetApiV1WorkflowsDeploymentsNameWorkersOptions = {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 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 deploymentWorkerListResponse = z.object({workers: z.array(deploymentWorkerResponse), next_cursor: z.string().nullable()}); 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 }; /** * List Deployment Workers * * GET /v1/workflows/deployments/{name}/workers */ export const getApiV1WorkflowsDeploymentsNameWorkers = async (args: GetApiV1WorkflowsDeploymentsNameWorkersArgs, options?: GetApiV1WorkflowsDeploymentsNameWorkersOptions) => { 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.worker_status != null) query.append("worker_status", String(args.worker_status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/deployments/${encodeURIComponent(String(args.name))}/workers${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(deploymentWorkerListResponse, await res.json()) };