import {z} from 'zod' export type GetApiV1WorkflowsExecutionsExecutionIdTraceSummaryArgs = {execution_id: string}; export type GetApiV1WorkflowsExecutionsExecutionIdTraceSummaryOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowExecutionStatus = z.enum(["RUNNING", "COMPLETED", "FAILED", "CANCELED", "TERMINATED", "CONTINUED_AS_NEW", "TIMED_OUT", "RETRYING_AFTER_ERROR"]); export const workflowExecutionTraceSummaryAttributesValues = z.union([z.string(), z.number().int(), z.number(), z.boolean(), z.array(z.unknown())]).nullable(); export const eventType = z.enum(["EVENT", "EVENT_PROGRESS"]); export const workflowExecutionTraceEvent = z.object({type: eventType.optional(), name: z.string(), id: z.string(), timestamp_unix_nano: z.number().int(), attributes: z.record(z.string(), workflowExecutionTraceSummaryAttributesValues), internal: z.boolean().optional()}); export const workflowExecutionTraceSummarySpan: z.ZodType = z.object({span_id: z.string(), name: z.string(), start_time_unix_nano: z.number().int(), end_time_unix_nano: z.number().int().nullable(), attributes: z.record(z.string(), workflowExecutionTraceSummaryAttributesValues), events: z.array(workflowExecutionTraceEvent), children: z.array(z.lazy(() => workflowExecutionTraceSummarySpan)).optional()}); export const workflowExecutionTraceSummaryResponse = z.object({workflow_name: z.string(), workflow_id: z.string().nullable().optional(), deployment_name: z.string().nullable().optional(), execution_id: z.string(), parent_execution_id: z.string().nullable().optional(), root_execution_id: z.string(), run_id: z.string().nullable().optional(), user_id: z.string().nullable().optional(), status: workflowExecutionStatus.nullable(), start_time: z.string(), end_time: z.string().nullable(), total_duration_ms: z.number().int().nullable().optional(), result: z.unknown(), search_keys: z.record(z.string(), z.string().nullable()).nullable().optional(), span_tree: workflowExecutionTraceSummarySpan.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 Execution Trace Summary * * GET /v1/workflows/executions/{execution_id}/trace/summary */ export const getApiV1WorkflowsExecutionsExecutionIdTraceSummary = async (args: GetApiV1WorkflowsExecutionsExecutionIdTraceSummaryArgs, options?: GetApiV1WorkflowsExecutionsExecutionIdTraceSummaryOptions) => { 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/executions/${encodeURIComponent(String(args.execution_id))}/trace/summary${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(workflowExecutionTraceSummaryResponse, await res.json()) };