import {z} from 'zod' export type GetApiApiMcpLogsHistogramArgs = {tool_names?: string | undefined, server_labels?: string | undefined, status?: string | undefined, virtual_key_ids?: string | undefined, llm_request_ids?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, min_latency?: number | undefined, max_latency?: number | undefined, content_search?: string | undefined}; export type GetApiApiMcpLogsHistogramOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiMcpLogsHistogramResponse = z.object({buckets: z.array(z.object({timestamp: z.string().optional(), count: z.number().int().optional(), success: z.number().int().optional(), error: z.number().int().optional()})).optional(), bucket_size_seconds: z.number().int().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 MCP tool call volume histogram * * GET /api/mcp-logs/histogram */ export const getApiApiMcpLogsHistogram = async (args: GetApiApiMcpLogsHistogramArgs, options?: GetApiApiMcpLogsHistogramOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, ManagementBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tool_names != null) query.append("tool_names", String(args.tool_names)) if (args.server_labels != null) query.append("server_labels", String(args.server_labels)) if (args.status != null) query.append("status", String(args.status)) if (args.virtual_key_ids != null) query.append("virtual_key_ids", String(args.virtual_key_ids)) if (args.llm_request_ids != null) query.append("llm_request_ids", String(args.llm_request_ids)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.min_latency != null) query.append("min_latency", String(args.min_latency)) if (args.max_latency != null) query.append("max_latency", String(args.max_latency)) if (args.content_search != null) query.append("content_search", String(args.content_search)) if (ManagementBearerAuth !== undefined) headers.set('authorization', `Bearer ${ManagementBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/mcp-logs/histogram${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(getApiApiMcpLogsHistogramResponse, await res.json()) };