import {z} from 'zod' export type GetApiV1ObservabilityTracesTraceIdSpansSpanIdArgs = {trace_id: string, span_id: string, from?: (string | null) | undefined, to?: (string | null) | undefined}; export type GetApiV1ObservabilityTracesTraceIdSpansSpanIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getSpan = z.object({customer_id: z.string(), organization_id: z.string(), workspace_id: z.string(), user_id: z.string(), trace_id: z.string(), span_id: z.string(), parent_span_id: z.string(), trace_state: z.string(), start_time: z.string(), end_time: z.string(), duration_ns: z.number().int(), span_name: z.string(), span_kind: z.string(), service_name: z.string(), status_code: z.enum(["Error", "Ok", "Unset"]), status_message: z.string(), error_type: z.string(), operation_name: z.string(), provider_name: z.string(), request_model: z.string(), response_model: z.string(), response_id: z.string(), output_type: z.string(), conversation_id: z.string(), data_source_id: z.string(), agent_id: z.string(), agent_name: z.string(), agent_version: z.string(), agent_description: z.string(), workflow_name: z.string(), prompt_name: z.string(), tool_name: z.string(), tool_type: z.string(), tool_call_id: z.string(), input_messages: z.string(), output_messages: z.string(), system_instructions: z.string(), tool_definitions: z.string(), tool_call_arguments: z.string(), tool_call_result: z.string(), request_choice_count: z.number().int(), request_max_tokens: z.number().int(), request_temperature: z.number().nullable(), request_top_p: z.number().nullable(), request_top_k: z.number().nullable(), request_presence_penalty: z.number().nullable(), request_frequency_penalty: z.number().nullable(), request_seed: z.number().int(), request_stop_sequences: z.array(z.string()), request_encoding_formats: z.array(z.string()), response_finish_reasons: z.array(z.string()), usage_input_tokens: z.number().int(), usage_output_tokens: z.number().int(), usage_cache_read_input_tokens: z.number().int(), usage_cache_creation_input_tokens: z.number().int(), resource_attributes: z.record(z.string(), z.string()), span_attributes: z.record(z.string(), z.string()), scope_name: z.string(), scope_version: z.string()}); 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 span by id * * GET /v1/observability/traces/{trace_id}/spans/{span_id} */ export const getApiV1ObservabilityTracesTraceIdSpansSpanId = async (args: GetApiV1ObservabilityTracesTraceIdSpansSpanIdArgs, options?: GetApiV1ObservabilityTracesTraceIdSpansSpanIdOptions) => { 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.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/observability/traces/${encodeURIComponent(String(args.trace_id))}/spans/${encodeURIComponent(String(args.span_id))}${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(getSpan, await res.json()) };