import {z} from 'zod' export type AgentDefinition = {name: string, type: 'llm-call' | 'connector-call', llm?: ({provider?: string | undefined, model?: string | undefined}) | undefined, connector?: ({name?: string | undefined, operation?: string | undefined}) | undefined}; export type RoutingRule = {pattern: string, agent: string, priority?: number | undefined}; export type AgentConfigSpec = {execution?: ({default_mode?: ('auto' | 'parallel' | 'sequential') | undefined, max_parallel_tasks?: number | undefined, timeout_seconds?: number | undefined}) | undefined, agents?: Array | undefined, routing?: Array | undefined}; export type CreateAgentRequest = {name: string, domain?: string | undefined, description?: string | undefined, is_active?: boolean | undefined, config: AgentConfigSpec}; export type CreateApiApiV1AgentsArgs = {body: CreateAgentRequest}; export type CreateApiApiV1AgentsOptions = {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 agentResponse = z.object({agent: agentResource.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 }; /** * Create new agent (Enterprise) * * POST /api/v1/agents */ export const createApiApiV1Agents = async (args: CreateApiApiV1AgentsArgs, options?: CreateApiApiV1AgentsOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/agents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(agentResponse, await res.json()) };