import {z} from 'zod' export type GetApiV1WorkflowsExecutionsExecutionIdLogsArgs = {execution_id: string, run_id?: (string | null) | undefined, activity_id?: (string | null) | undefined, after?: (string | null) | undefined, before?: (string | null) | undefined, order?: ('asc' | 'desc') | undefined, cursor?: (string | null) | undefined, limit?: number | undefined}; export type GetApiV1WorkflowsExecutionsExecutionIdLogsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const executionLogRecord = z.object({timestamp: z.string(), trace_id: z.string(), span_id: z.string(), severity_text: z.string(), body: z.string(), log_attributes: z.record(z.string(), z.string())}); export const executionLogSearchResponse = z.object({results: z.array(executionLogRecord), 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 Execution Logs * * GET /v1/workflows/executions/{execution_id}/logs */ export const getApiV1WorkflowsExecutionsExecutionIdLogs = async (args: GetApiV1WorkflowsExecutionsExecutionIdLogsArgs, options?: GetApiV1WorkflowsExecutionsExecutionIdLogsOptions) => { 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.run_id != null) query.append("run_id", String(args.run_id)) if (args.activity_id != null) query.append("activity_id", String(args.activity_id)) if (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) if (args.order != null) query.append("order", String(args.order)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/executions/${encodeURIComponent(String(args.execution_id))}/logs${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(executionLogSearchResponse, await res.json()) };