import {z} from 'zod' export type GetApiAgentsSkillsArgs = {offset?: number | undefined, limit?: number | undefined, query?: string | undefined}; export type GetApiAgentsSkillsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const agentSkill = z.object({id: z.string().optional(), skill_name: z.string().optional(), description: z.string().optional(), config: z.object({}).optional(), owner_email: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), enabled: z.boolean().optional(), warnings: z.array(z.string()).optional(), api_keys: z.object({required: z.array(z.string()).optional(), optional: z.array(z.string()).optional()}).optional(), api_key_hints: z.record(z.string(), z.string()).optional(), env_defaults: z.record(z.string(), z.string()).optional()}); export const getApiAgentsSkillsResponse = z.array(agentSkill); 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 }; /** * Lists agent skills for the current user. * * GET /agents/skills */ export const getApiAgentsSkills = async (args: GetApiAgentsSkillsArgs, options?: GetApiAgentsSkillsOptions) => { 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.query != null) query.append("query", String(args.query)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/skills${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(getApiAgentsSkillsResponse, await res.json()) };