import {z} from 'zod' export type GetApiAgentsArgs = {limit?: number | undefined, offset?: number | undefined, search?: string | undefined, kind?: ('' | 'instructions' | 'code') | undefined, created_after?: string | undefined, created_before?: string | undefined, last_run_after?: string | undefined, last_run_before?: string | undefined}; export type GetApiAgentsOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const agent = z.object({$schema: z.string().optional(), accessibility_enabled: z.boolean(), capture_enabled: z.boolean(), created_at: z.string(), current_revision_id: z.string().optional(), id: z.string(), last_run_at: z.string().optional(), max_cost_microdollars: z.number().int(), max_steps: z.number().int(), model: z.string(), name: z.string(), output_schema: z.record(z.string(), z.unknown()).optional(), pause_timeout_seconds: z.number().int(), recording_enabled: z.boolean(), telemetry_enabled: z.boolean(), timeout_seconds: z.number().int(), updated_at: z.string()}); export const agentList = z.object({$schema: z.string().optional(), agents: z.array(agent).nullable(), limit: z.number().int(), offset: z.number().int(), total: z.number().int()}); 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 }; /** * List agents * * GET /agents */ export const getApiAgents = async (args: GetApiAgentsArgs, options: GetApiAgentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.last_run_after != null) query.append("last_run_after", String(args.last_run_after)) if (args.last_run_before != null) query.append("last_run_before", String(args.last_run_before)) if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/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(agentList, await res.json()) };