import {z} from 'zod' export type ExpertAvatarUpdate = {avatar_url?: (string | null) | undefined}; export type PatchApiApiExpertsExpertIdAvatarArgs = {expert_id: string, body: ExpertAvatarUpdate}; export type PatchApiApiExpertsExpertIdAvatarOptions = {baseUrl: string, HTTPBearerJWT?: string | undefined, fetch?: typeof fetch | undefined}; export const voiceSample = z.object({label: z.string(), text: z.string()}); export const expertDayOneItem = z.object({title: z.string().min(1).max(80), description: z.string().max(240).optional(), timing: z.string().max(40).optional()}); export const expertWorkflowChainItem = z.object({kind: z.enum(["integration", "input", "output", "trigger", "agent", "ai", "mcp", "human"]), provider: z.string().nullable().optional()}); export const expertWorkflowRef = z.object({id: z.string(), store_listing_version_id: z.string().nullable(), library_agent_id: z.string().nullable(), graph_id: z.string().nullable(), name: z.string().nullable(), description: z.string().nullable(), schedule_cron: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), chain: z.array(expertWorkflowChainItem).optional(), integration_providers: z.array(z.string()).optional()}); export const expert = z.object({id: z.string(), name: z.string(), avatar_url: z.string().nullable(), color: z.string().optional(), role: z.string(), job_title: z.string().nullable().optional(), tagline: z.string().nullable(), bio: z.string().nullable(), skills: z.array(z.string()), categories: z.array(z.string()).optional(), identity: z.string(), voice_preferences: z.string(), voice_samples: z.array(voiceSample).optional(), day_one: z.array(expertDayOneItem).optional(), boundaries: z.string(), protected_soul_rules: z.array(z.string()), is_template: z.boolean(), source_template_id: z.string().nullable(), is_archived: z.boolean(), workflows: z.array(expertWorkflowRef), credential_count: z.number().int().optional(), credential_providers: z.array(z.string()).optional(), last_run_at: z.string().nullable().optional(), last_run_status: z.string().nullable().optional(), weekly_budget: z.number().int().nullable().optional(), weekly_spend: z.number().int().optional(), schedules_paused_at: z.string().nullable().optional(), learning_paused_at: z.string().nullable().optional(), autopilot_mode: z.enum(["ask_first", "auto", "unsupervised"]).nullable().optional(), pod_id: z.string().nullable().optional(), setup_status: z.enum(["installing", "ready", "failed"]).optional(), setup_failures: z.array(z.string()).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 }; /** * Update Expert Avatar * * PATCH /api/experts/{expert_id}/avatar */ export const patchApiApiExpertsExpertIdAvatar = async (args: PatchApiApiExpertsExpertIdAvatarArgs, options: PatchApiApiExpertsExpertIdAvatarOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearerJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearerJWT !== undefined) headers.set('authorization', `Bearer ${HTTPBearerJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/experts/${encodeURIComponent(String(args.expert_id))}/avatar${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(expert, await res.json()) };