import {z} from 'zod' export type AiAgentModelConfig = {reasoning?: boolean | undefined, modelProvider: string, modelName: string}; export type ApiUpdateAiAgent = {name?: string | undefined, description?: (string | null) | undefined, projectUuid?: string | undefined, version?: number | undefined, userAccess?: Array | undefined, integrations?: Array<{channelId: string, type: 'slack'}> | undefined, tags?: (Array | null) | undefined, instruction?: (string | null) | undefined, imageUrl?: (string | null) | undefined, groupAccess?: Array | undefined, spaceAccess?: Array | undefined, enableDataAccess?: boolean | undefined, enableSelfImprovement?: boolean | undefined, enableContentTools?: boolean | undefined, enableUserContext?: boolean | undefined, adminOnly?: boolean | undefined, modelConfig?: (AiAgentModelConfig | null) | undefined, mcpServerUuids?: Array | undefined, uuid: string}; export type PatchApiApiV1ProjectsProjectUuidAiAgentsAgentUuidArgs = {projectUuid: string, agentUuid: string, body: ApiUpdateAiAgent}; export type PatchApiApiV1ProjectsProjectUuidAiAgentsAgentUuidOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const aiAgentModelConfig = z.object({reasoning: z.boolean().optional(), modelProvider: z.string(), modelName: z.string()}); export const aiAgent = z.object({name: z.string(), description: z.string().nullable(), uuid: z.string(), organizationUuid: z.string(), projectUuid: z.string(), updatedAt: z.string(), version: z.number(), createdAt: z.string(), userAccess: z.array(z.string()), integrations: z.array(z.object({channelId: z.string(), type: z.literal("slack")})), tags: z.array(z.string()).nullable(), instruction: z.string().nullable(), imageUrl: z.string().nullable(), imageUrlSource: z.enum(["url", "upload", "null"]).nullable(), groupAccess: z.array(z.string()), spaceAccess: z.array(z.string()), enableDataAccess: z.boolean(), enableSelfImprovement: z.boolean(), enableContentTools: z.boolean(), enableUserContext: z.boolean(), adminOnly: z.boolean(), modelConfig: aiAgentModelConfig.nullable()}); export const apiAiAgentResponse = z.object({results: aiAgent, 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 }; /** * PATCH /api/v1/projects/{projectUuid}/aiAgents/{agentUuid} */ export const patchApiApiV1ProjectsProjectUuidAiAgentsAgentUuid = async (args: PatchApiApiV1ProjectsProjectUuidAiAgentsAgentUuidArgs, options: PatchApiApiV1ProjectsProjectUuidAiAgentsAgentUuidOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/aiAgents/${encodeURIComponent(String(args.agentUuid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(apiAiAgentResponse, await res.json()) };