import {z} from 'zod' export type GetApiApiStoreAgentsUsernameAgentNameArgs = {username: string, agent_name: string, include_changelog?: boolean | undefined}; export type GetApiApiStoreAgentsUsernameAgentNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const changelogEntry = z.object({version: z.string(), changes_summary: z.string(), date: z.string()}); export const storeAgentDetails = z.object({store_listing_version_id: z.string(), slug: z.string(), agent_name: z.string(), agent_video: z.string(), agent_output_demo: z.string(), agent_image: z.array(z.string()), creator: z.string(), creator_avatar: z.string(), sub_heading: z.string(), description: z.string(), instructions: z.string().nullable().optional(), categories: z.array(z.string()), runs: z.number().int(), rating: z.number(), versions: z.array(z.string()), graph_id: z.string(), graph_versions: z.array(z.string()), last_updated: z.string(), recommended_schedule_cron: z.string().nullable().optional(), owning_org_id: z.string().nullable().optional(), active_version_id: z.string(), has_approved_version: z.boolean(), changelog: z.array(changelogEntry).nullable().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 }; /** * Get specific agent * * GET /api/store/agents/{username}/{agent_name} */ export const getApiApiStoreAgentsUsernameAgentName = async (args: GetApiApiStoreAgentsUsernameAgentNameArgs, options: GetApiApiStoreAgentsUsernameAgentNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_changelog != null) query.append("include_changelog", String(args.include_changelog)) const url = `${baseUrl.replace(/\/+$/, '')}/api/store/agents/${encodeURIComponent(String(args.username))}/${encodeURIComponent(String(args.agent_name))}${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(storeAgentDetails, await res.json()) };