import {z} from 'zod' export type UpdateApiV1WorkflowsWorkflowIdentifierArchiveArgs = {workflow_identifier: string}; export type UpdateApiV1WorkflowsWorkflowIdentifierArchiveOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowType = z.literal("code"); export const workflow = z.object({id: z.string(), name: z.string(), display_name: z.string(), type: workflowType, description: z.string().nullable().optional(), customer_id: z.string(), workspace_id: z.string(), shared_namespace: z.string().nullable().optional(), available_in_chat_assistant: z.boolean().optional(), is_technical: z.boolean().optional(), archived: z.boolean().optional(), tags: z.array(z.string()).optional()}); export const workflowArchiveResponse = z.object({workflow: workflow}); 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 }; /** * Archive Workflow * * PUT /v1/workflows/{workflow_identifier}/archive */ export const updateApiV1WorkflowsWorkflowIdentifierArchive = async (args: UpdateApiV1WorkflowsWorkflowIdentifierArchiveArgs, options?: UpdateApiV1WorkflowsWorkflowIdentifierArchiveOptions) => { 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/${encodeURIComponent(String(args.workflow_identifier))}/archive${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(workflowArchiveResponse, await res.json()) };