import {z} from 'zod' export type GetApiAiAssistantsArgs = {offset?: number | undefined, limit?: number | undefined, name_filter?: string | undefined, status_filter?: string | undefined}; export type GetApiAiAssistantsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aiAssistant = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), system_prompt: z.string().optional(), llm: z.string().optional(), llm_args: z.object({}).optional(), status: z.enum(["stopped", "running", "sleeping", "error"]).optional(), custom_tool_definition: z.string().optional(), mcp_servers: z.array(z.object({})).optional(), credential_ids: z.array(z.string()).optional(), memory_block_id: z.string().optional(), notification_email: z.string().optional(), history_management: z.enum(["compactification", "truncation", "semantic_retrieval"]).optional(), history_max_chars: z.number().int().optional(), history_recent_chars: z.number().int().optional(), history_retrieval_chars: z.number().int().optional(), allowed_tool_actions: z.array(z.string()).nullable().optional(), allowed_trigger_types: z.array(z.string()).nullable().optional(), current_chat_session_id: z.string().optional(), wake_count: z.number().int().optional(), last_wake_at: z.string().optional(), last_sleep_at: z.string().optional(), error_message: z.string().optional(), user_id: z.string().optional(), username: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), is_owner: z.boolean().optional(), user_access_mode: z.string().optional(), forum_count: z.number().int().optional()}); export const getApiAiAssistantsResponse = z.array(aiAssistant); 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 AI assistants. * * GET /ai_assistants */ export const getApiAiAssistants = async (args: GetApiAiAssistantsArgs, options?: GetApiAiAssistantsOptions) => { 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 (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.name_filter != null) query.append("name_filter", String(args.name_filter)) if (args.status_filter != null) query.append("status_filter", String(args.status_filter)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ai_assistants${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(getApiAiAssistantsResponse, await res.json()) };