import {z} from 'zod' export type LogsRequest = {search_expression?: (string | null) | undefined, order?: ('asc' | 'desc') | undefined}; export type CreateApiV1ObservabilityLogsSearchArgs = {from?: (string | null) | undefined, to?: (string | null) | undefined, page_size?: number | undefined, cursor?: (string | null) | undefined, body: LogsRequest}; export type CreateApiV1ObservabilityLogsSearchOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getLog = z.object({customer_id: z.string(), organization_id: z.string(), workspace_id: z.string(), user_id: z.string(), timestamp: z.string(), trace_id: z.string(), span_id: z.string(), trace_flags: z.number().int(), severity_text: z.string(), severity_number: z.number().int(), service_name: z.string(), body: z.string(), event_name: z.string(), resource_schema_url: z.string(), resource_attributes: z.record(z.string(), z.string()), scope_schema_url: z.string(), scope_name: z.string(), scope_version: z.string(), scope_attributes: z.record(z.string(), z.string()), log_attributes: z.record(z.string(), z.string())}); export const feedResultGetLog = z.object({results: z.array(getLog).optional(), next: z.string().nullable().optional(), cursor: z.string().nullable().optional()}); export const getLogs = z.object({logs: feedResultGetLog}); 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 }; /** * Search logs * * POST /v1/observability/logs/search */ export const createApiV1ObservabilityLogsSearch = async (args: CreateApiV1ObservabilityLogsSearchArgs, options?: CreateApiV1ObservabilityLogsSearchOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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 (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/observability/logs/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getLogs, await res.json()) };