import {z} from 'zod' export type GetApiV1WorkflowsEventsListArgs = {root_workflow_exec_id?: (string | null) | undefined, workflow_exec_id?: (string | null) | undefined, workflow_run_id?: (string | null) | undefined, limit?: number | undefined, cursor?: (string | null) | undefined}; export type GetApiV1WorkflowsEventsListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const encodedPayloadOptions = z.enum(["offloaded", "encrypted", "encrypted-partial", "compressed"]); export const jSONPayloadResponse = z.object({type: z.literal("json"), value: z.unknown(), encoding_options: z.array(encodedPayloadOptions).nullable().optional()}); export const workflowExecutionStartedAttributesResponse = z.object({task_id: z.string(), workflow_name: z.string(), display_name: z.string().nullable().optional(), input: jSONPayloadResponse, attempt: z.number().int().optional()}); export const workflowExecutionStartedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_EXECUTION_STARTED"), attributes: workflowExecutionStartedAttributesResponse}); export const workflowExecutionCompletedAttributesResponse = z.object({task_id: z.string(), result: jSONPayloadResponse, attempt: z.number().int().optional()}); export const workflowExecutionCompletedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_EXECUTION_COMPLETED"), attributes: workflowExecutionCompletedAttributesResponse}); export const failure = z.object({message: z.string()}); export const workflowExecutionFailedAttributes = z.object({task_id: z.string(), failure: failure, attempt: z.number().int().optional()}); export const workflowExecutionFailedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_EXECUTION_FAILED"), attributes: workflowExecutionFailedAttributes}); export const workflowExecutionCanceledAttributes = z.object({task_id: z.string(), reason: z.string().nullable().optional(), attempt: z.number().int().optional()}); export const workflowExecutionCanceledResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_EXECUTION_CANCELED"), attributes: workflowExecutionCanceledAttributes}); export const workflowExecutionContinuedAsNewAttributesResponse = z.object({task_id: z.string(), new_execution_run_id: z.string(), workflow_name: z.string(), input: jSONPayloadResponse}); export const workflowExecutionContinuedAsNewResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_EXECUTION_CONTINUED_AS_NEW"), attributes: workflowExecutionContinuedAsNewAttributesResponse}); export const workflowTaskTimedOutAttributes = z.object({task_id: z.string(), timeout_type: z.string().nullable().optional()}); export const workflowTaskTimedOutResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_TASK_TIMED_OUT"), attributes: workflowTaskTimedOutAttributes}); export const workflowTaskFailedAttributes = z.object({task_id: z.string(), failure: failure}); export const workflowTaskFailedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("WORKFLOW_TASK_FAILED"), attributes: workflowTaskFailedAttributes}); export const customTaskStartedAttributesResponse = z.object({custom_task_id: z.string(), custom_task_type: z.string(), payload: jSONPayloadResponse.optional()}); export const customTaskStartedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_STARTED"), attributes: customTaskStartedAttributesResponse}); export const encryptedPatchValue = z.object({type: z.literal("__encrypted__"), value: z.string()}); export const jSONPatchAppend = z.object({path: z.string(), value: z.union([z.string(), encryptedPatchValue]), op: z.literal("append")}); export const jSONPatchAdd = z.object({path: z.string(), value: z.unknown(), op: z.literal("add")}); export const jSONPatchReplace = z.object({path: z.string(), value: z.unknown(), op: z.literal("replace")}); export const jSONPatchRemove = z.object({path: z.string(), value: z.unknown(), op: z.literal("remove")}); export const jSONPatch = z.discriminatedUnion("op", [jSONPatchAppend, jSONPatchAdd, jSONPatchReplace, jSONPatchRemove]); export const jSONPatchPayloadValueResponse = z.union([z.array(jSONPatch), z.string()]); export const jSONPatchPayloadResponse = z.object({type: z.literal("json_patch"), value: jSONPatchPayloadValueResponse, encoding_options: z.array(encodedPayloadOptions).nullable().optional()}); export const customTaskInProgressAttributesResponse = z.object({custom_task_id: z.string(), custom_task_type: z.string(), payload: z.discriminatedUnion("type", [jSONPayloadResponse, jSONPatchPayloadResponse])}); export const customTaskInProgressResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_IN_PROGRESS"), attributes: customTaskInProgressAttributesResponse}); export const customTaskCompletedAttributesResponse = z.object({custom_task_id: z.string(), custom_task_type: z.string(), payload: jSONPayloadResponse}); export const customTaskCompletedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_COMPLETED"), attributes: customTaskCompletedAttributesResponse}); export const customTaskFailedAttributes = z.object({custom_task_id: z.string(), custom_task_type: z.string(), failure: failure}); export const customTaskFailedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_FAILED"), attributes: customTaskFailedAttributes}); export const customTaskTimedOutAttributes = z.object({custom_task_id: z.string(), custom_task_type: z.string(), timeout_type: z.string().nullable().optional()}); export const customTaskTimedOutResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_TIMED_OUT"), attributes: customTaskTimedOutAttributes}); export const customTaskCanceledAttributes = z.object({custom_task_id: z.string(), custom_task_type: z.string(), reason: z.string().nullable().optional()}); export const customTaskCanceledResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("CUSTOM_TASK_CANCELED"), attributes: customTaskCanceledAttributes}); export const activityTaskStartedAttributesResponse = z.object({task_id: z.string(), activity_name: z.string(), input: jSONPayloadResponse}); export const activityTaskStartedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("ACTIVITY_TASK_STARTED"), attributes: activityTaskStartedAttributesResponse}); export const activityTaskCompletedAttributesResponse = z.object({task_id: z.string(), activity_name: z.string(), result: jSONPayloadResponse}); export const activityTaskCompletedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("ACTIVITY_TASK_COMPLETED"), attributes: activityTaskCompletedAttributesResponse}); export const activityTaskRetryingAttributes = z.object({task_id: z.string(), activity_name: z.string(), attempt: z.number().int(), failure: failure}); export const activityTaskRetryingResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("ACTIVITY_TASK_RETRYING"), attributes: activityTaskRetryingAttributes}); export const activityTaskFailedAttributes = z.object({task_id: z.string(), activity_name: z.string(), attempt: z.number().int(), failure: failure}); export const activityTaskFailedResponse = z.object({event_id: z.string(), event_timestamp: z.number().int(), root_workflow_exec_id: z.string(), parent_workflow_exec_id: z.string().nullable(), continued_run_id: z.string().nullable().optional(), first_execution_run_id: z.string().nullable().optional(), chain_run_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), workflow_exec_id: z.string(), workflow_run_id: z.string(), workflow_name: z.string(), event_type: z.literal("ACTIVITY_TASK_FAILED"), attributes: activityTaskFailedAttributes}); export const listWorkflowEventResponse = z.object({events: z.array(z.union([workflowExecutionStartedResponse, workflowExecutionCompletedResponse, workflowExecutionFailedResponse, workflowExecutionCanceledResponse, workflowExecutionContinuedAsNewResponse, workflowTaskTimedOutResponse, workflowTaskFailedResponse, customTaskStartedResponse, customTaskInProgressResponse, customTaskCompletedResponse, customTaskFailedResponse, customTaskTimedOutResponse, customTaskCanceledResponse, activityTaskStartedResponse, activityTaskCompletedResponse, activityTaskRetryingResponse, activityTaskFailedResponse])), next_cursor: z.string().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 }; /** * Get Workflow Events * * GET /v1/workflows/events/list */ export const getApiV1WorkflowsEventsList = async (args: GetApiV1WorkflowsEventsListArgs, options?: GetApiV1WorkflowsEventsListOptions) => { 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.root_workflow_exec_id != null) query.append("root_workflow_exec_id", String(args.root_workflow_exec_id)) if (args.workflow_exec_id != null) query.append("workflow_exec_id", String(args.workflow_exec_id)) if (args.workflow_run_id != null) query.append("workflow_run_id", String(args.workflow_run_id)) 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/events/list${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(listWorkflowEventResponse, await res.json()) };