import {z} from 'zod' export type AgentUpdateRequest = {$schema?: string | undefined, accessibility_enabled?: boolean | undefined, capture_enabled?: boolean | undefined, max_cost_microdollars?: number | undefined, max_steps?: number | undefined, model?: string | undefined, name?: string | undefined, output_schema?: ({[key: string]: unknown} | null) | undefined, pause_timeout_seconds?: number | undefined, recording_enabled?: boolean | undefined, telemetry_enabled?: boolean | undefined, timeout_seconds?: number | undefined}; export type PatchApiAgentsAgentIdArgs = {agent_id: string, body: AgentUpdateRequest}; export type PatchApiAgentsAgentIdOptions = {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 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 }; /** * Update an agent * * PATCH /agents/{agent_id} */ export const patchApiAgentsAgentId = async (args: PatchApiAgentsAgentIdArgs, options: PatchApiAgentsAgentIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/agents/${encodeURIComponent(String(args.agent_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(agent, await res.json()) };