import {z} from 'zod' export type GetApiAgentsDirectoryStatsArgs = {offset?: number | undefined, limit?: number | undefined, filter_text?: string | undefined}; export type GetApiAgentsDirectoryStatsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const agentServerDirectoryFileStats = z.object({name: z.string(), path: z.string(), size_bytes: z.number().int(), size_human_readable: z.string(), created_timestamp: z.number(), modified_timestamp: z.number(), created_date: z.string(), modified_date: z.string(), is_directory: z.boolean(), owner: z.string(), permissions: z.string(), sha256: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const agentServerDirectoryStats = z.object({id: z.string(), object: z.string(), size_bytes: z.number().int(), size_human_readable: z.string(), file_count: z.number().int(), directory_count: z.number().int(), created_timestamp: z.number(), modified_timestamp: z.number(), created_date: z.string(), modified_date: z.string(), is_empty: z.boolean(), top_level_contents: z.array(z.string()), owner: z.string(), permissions: z.string(), files: z.array(agentServerDirectoryFileStats).optional()}).and(z.record(z.string(), z.unknown())); export const agentServerDirectoryStatsPerAgentChatSession = z.object({agent_chat_session_id: z.string(), chat_preview: z.string(), stats: z.array(agentServerDirectoryStats)}); export const getApiAgentsDirectoryStatsResponse = z.array(agentServerDirectoryStatsPerAgentChatSession); 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 }; /** * Lists agent directory stats across all agent chat sessions. * * GET /agents/directory_stats */ export const getApiAgentsDirectoryStats = async (args: GetApiAgentsDirectoryStatsArgs, options?: GetApiAgentsDirectoryStatsOptions) => { const {baseUrl = "https://h2ogpte.genai.h2o.ai/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.filter_text != null) query.append("filter_text", String(args.filter_text)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/directory_stats${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(getApiAgentsDirectoryStatsResponse, await res.json()) };