import {z} from 'zod' export type GetApiApiV1AgentsArgs = {page?: number | undefined, page_size?: number | undefined, domain?: string | undefined}; export type GetApiApiV1AgentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const agentDefinition = z.object({name: z.string(), type: z.enum(["llm-call", "connector-call"]), llm: z.object({provider: z.string().optional(), model: z.string().optional()}).optional(), connector: z.object({name: z.string().optional(), operation: z.string().optional()}).optional()}); export const routingRule = z.object({pattern: z.string(), agent: z.string(), priority: z.number().int().optional()}); export const agentConfigSpec = z.object({execution: z.object({default_mode: z.enum(["auto", "parallel", "sequential"]).optional(), max_parallel_tasks: z.number().int().optional(), timeout_seconds: z.number().int().optional()}).optional(), agents: z.array(agentDefinition).optional(), routing: z.array(routingRule).optional()}); export const agentResource = z.object({id: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), description: z.string().optional(), version: z.number().int().optional(), is_active: z.boolean().optional(), config: agentConfigSpec.optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const agentListResponse = z.object({agents: z.array(agentResource).optional(), pagination: z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total: z.number().int().optional(), total_pages: z.number().int().optional()}).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 }; /** * List all agents (Enterprise) * * GET /api/v1/agents */ export const getApiApiV1Agents = async (args: GetApiApiV1AgentsArgs, options?: GetApiApiV1AgentsOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.domain != null) query.append("domain", String(args.domain)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/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(agentListResponse, await res.json()) };