import {z} from 'zod' export type WorkflowUpdateRequest = {display_name?: (string | null) | undefined, description?: (string | null) | undefined, available_in_chat_assistant?: (boolean | null) | undefined, tags?: (Array | null) | undefined}; export type UpdateApiV1WorkflowsWorkflowIdentifierArgs = {workflow_identifier: string, body: WorkflowUpdateRequest}; export type UpdateApiV1WorkflowsWorkflowIdentifierOptions = {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 workflowUpdateResponse = 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 }; /** * Update Workflow * * PUT /v1/workflows/{workflow_identifier} */ export const updateApiV1WorkflowsWorkflowIdentifier = async (args: UpdateApiV1WorkflowsWorkflowIdentifierArgs, options?: UpdateApiV1WorkflowsWorkflowIdentifierOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/${encodeURIComponent(String(args.workflow_identifier))}${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(workflowUpdateResponse, await res.json()) };