import {z} from 'zod' export type GetApiAgentsCustomAgentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customAgentKeyAssociation = z.object({id: z.string(), agent_id: z.string(), env_key_name: z.string(), key_id: z.string().nullable().optional(), user_id: z.string(), requirement_type: z.enum(["required", "optional_with_default", "optional_no_default", "custom"]), key_name: z.string().nullable().optional(), owner_email: z.string().nullable().optional()}); export const customAgentDetail = z.object({id: z.string().optional(), agent_name: z.string().optional(), agent_type: z.string().optional(), agent_args: z.object({}).optional(), owner_email: z.string().optional(), mcp_servers: z.array(z.object({tool_name: z.string().optional(), tool_args: z.string().optional(), associated_tool: z.object({id: z.string().optional(), name: z.string().optional(), owner_email: z.string().optional(), description: z.string().optional()}).nullable().optional()})).nullable().optional(), api_keys: z.array(customAgentKeyAssociation).optional()}); export const getApiAgentsCustomAgentsResponse = z.array(customAgentDetail); 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 Custom Agents * * GET /agents/custom_agents */ export const getApiAgentsCustomAgents = async (options?: GetApiAgentsCustomAgentsOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/custom_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(getApiAgentsCustomAgentsResponse, await res.json()) };