import {z} from 'zod' export type GetApiApiV1ProjectsProjectUuidAiAgentsCodeArgs = {projectUuid: string, ids?: Array | undefined, offset?: number | undefined}; export type GetApiApiV1ProjectsProjectUuidAiAgentsCodeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const agentAsCodeEvaluationPrompt = z.object({expectedResponse: z.string().nullable(), prompt: z.string()}); export const agentAsCodeEvaluation = z.object({prompts: z.array(agentAsCodeEvaluationPrompt), title: z.string()}); export const aiAgentModelConfig = z.object({reasoning: z.boolean().optional(), modelProvider: z.string(), modelName: z.string()}); export const contentAsCodeTypeAIAGENT = z.literal("ai_agent"); export const agentAsCode = z.object({downloadedAt: z.string().optional(), updatedAt: z.string().optional(), evaluations: z.array(agentAsCodeEvaluation).optional(), modelConfig: aiAgentModelConfig.nullable(), enableUserContext: z.boolean(), enableContentTools: z.boolean(), enableSelfImprovement: z.boolean(), enableDataAccess: z.boolean(), tags: z.array(z.string()).nullable(), instruction: z.string().nullable(), imageUrl: z.string().nullable(), description: z.string().nullable(), name: z.string(), slug: z.string(), agentVersion: z.union([z.literal(1), z.literal(2)]), version: z.number(), contentType: contentAsCodeTypeAIAGENT}); export const apiAgentAsCodeListResponse = z.object({results: z.object({offset: z.number(), total: z.number(), missingIds: z.array(z.string()), agents: z.array(agentAsCode)}), status: z.literal("ok")}); 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 agents as code (deprecated) * * GET /api/v1/projects/{projectUuid}/aiAgents/code */ export const getApiApiV1ProjectsProjectUuidAiAgentsCode = async (args: GetApiApiV1ProjectsProjectUuidAiAgentsCodeArgs, options: GetApiApiV1ProjectsProjectUuidAiAgentsCodeOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.ids ?? []) query.append("ids", String(item)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/aiAgents/code${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(apiAgentAsCodeListResponse, await res.json()) };