import {z} from 'zod' export type GetApiV1WorkflowsExecutionsExecutionIdTraceOtelArgs = {execution_id: string}; export type GetApiV1WorkflowsExecutionsExecutionIdTraceOtelOptions = {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 tempoTraceAttributeStringValue = z.object({stringValue: z.string()}); export const tempoTraceAttributeIntValue = z.object({intValue: z.string()}); export const tempoTraceAttributeDoubleValue = z.object({doubleValue: z.number()}); export const tempoTraceAttributeBoolValue = z.object({boolValue: z.boolean()}); export const tempoTraceAttributeArrayElement = z.object({stringValue: z.string().nullable().optional(), intValue: z.string().nullable().optional(), doubleValue: z.number().nullable().optional(), boolValue: z.boolean().nullable().optional()}); export const tempoTraceAttributeArrayContainer = z.object({values: z.array(tempoTraceAttributeArrayElement).optional()}); export const tempoTraceAttributeArrayValue = z.object({arrayValue: tempoTraceAttributeArrayContainer}); export const tempoTraceAttribute = z.object({key: z.string(), value: z.union([tempoTraceAttributeStringValue, tempoTraceAttributeIntValue, tempoTraceAttributeDoubleValue, tempoTraceAttributeBoolValue, tempoTraceAttributeArrayValue])}); export const tempoTraceResource = z.object({attributes: z.array(tempoTraceAttribute).optional()}); export const tempoTraceScope = z.object({name: z.string()}); export const tempoTraceScopeKind = z.enum(["SPAN_KIND_INTERNAL", "SPAN_KIND_SERVER", "SPAN_KIND_CLIENT"]); export const tempoTraceEvent = z.object({name: z.string(), timeUnixNano: z.string(), attributes: z.array(tempoTraceAttribute).optional()}); export const tempoTraceSpan = z.object({traceId: z.string(), spanId: z.string(), parentSpanId: z.string().nullable().optional(), name: z.string(), kind: tempoTraceScopeKind, startTimeUnixNano: z.string(), endTimeUnixNano: z.string(), attributes: z.array(tempoTraceAttribute).optional(), events: z.array(tempoTraceEvent).optional()}); export const tempoTraceScopeSpan = z.object({scope: tempoTraceScope, spans: z.array(tempoTraceSpan).optional()}); export const tempoTraceBatch = z.object({resource: tempoTraceResource, scopeSpans: z.array(tempoTraceScopeSpan).optional()}); export const tempoGetTraceResponse = z.object({batches: z.array(tempoTraceBatch).optional()}); export const workflowExecutionTraceOTelResponse = 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(), data_source: z.string(), otel_trace_id: z.string().nullable().optional(), otel_trace_data: tempoGetTraceResponse.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 Otel * * GET /v1/workflows/executions/{execution_id}/trace/otel */ export const getApiV1WorkflowsExecutionsExecutionIdTraceOtel = async (args: GetApiV1WorkflowsExecutionsExecutionIdTraceOtelArgs, options?: GetApiV1WorkflowsExecutionsExecutionIdTraceOtelOptions) => { 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/otel${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(workflowExecutionTraceOTelResponse, await res.json()) };