import {z} from 'zod' export type GetApiCabinetAdminBanSystemAgentsArgs = {search?: (string | null) | undefined, health?: (string | null) | undefined, status?: (string | null) | undefined}; export type GetApiCabinetAdminBanSystemAgentsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const banAgentItem = z.object({node_name: z.string(), sent_total: z.number().int().optional(), dropped_total: z.number().int().optional(), batches_total: z.number().int().optional(), reconnects: z.number().int().optional(), failures: z.number().int().optional(), queue_size: z.number().int().optional(), queue_max: z.number().int().optional(), dedup_checked: z.number().int().optional(), dedup_skipped: z.number().int().optional(), filter_checked: z.number().int().optional(), filter_filtered: z.number().int().optional(), health: z.string().optional(), is_online: z.boolean().optional(), last_report: z.string().nullable().optional()}); export const banAgentsSummary = z.object({total_agents: z.number().int().optional(), online_agents: z.number().int().optional(), total_sent: z.number().int().optional(), total_dropped: z.number().int().optional(), avg_queue_size: z.number().optional(), healthy_count: z.number().int().optional(), warning_count: z.number().int().optional(), critical_count: z.number().int().optional()}); export const banAgentsListResponse = z.object({agents: z.array(banAgentItem).optional(), summary: banAgentsSummary.nullable().optional(), total: z.number().int().optional(), online: 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 Agents * * GET /cabinet/admin/ban-system/agents */ export const getApiCabinetAdminBanSystemAgents = async (args: GetApiCabinetAdminBanSystemAgentsArgs, options: GetApiCabinetAdminBanSystemAgentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.health != null) query.append("health", String(args.health)) if (args.status != null) query.append("status", String(args.status)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/ban-system/agents${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(banAgentsListResponse, await res.json()) };