import {z} from 'zod' export type AdaptiveCadence = 'off' | 'daily' | 'weekly' | 'monthly'; export type ProjectUpdate = {name?: (string | null) | undefined, icon?: (string | null) | undefined, repo?: (string | null) | undefined, description?: (string | null) | undefined, tag?: (string | null) | undefined, observations?: (string | null) | undefined, active_model_id?: (string | null) | undefined, selected_model_id?: (string | null) | undefined, visibility?: ('private' | 'team' | null) | undefined, adaptive_cadence?: (AdaptiveCadence | null) | undefined}; export type PatchApiV1ProjectsProjectIdArgs = {project_id: string, body: ProjectUpdate}; export type PatchApiV1ProjectsProjectIdOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const adaptiveCadence = z.enum(["off", "daily", "weekly", "monthly"]); export const projectResponse = z.object({id: z.string(), user_id: z.string(), name: z.string(), icon: z.string().optional(), repo: z.string().nullable().optional(), description: z.string().nullable().optional(), active_model_id: z.string().nullable().optional(), tag: z.string().nullable().optional(), observations: z.string().nullable().optional(), example: z.record(z.string(), z.unknown()).nullable().optional(), team_id: z.string(), visibility: z.string().optional(), adaptive_cadence: adaptiveCadence.optional(), autonomy_enabled: z.boolean().optional(), created_at: z.string(), updated_at: z.string(), selected_model_id: z.string().nullable()}); 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 Project * * PATCH /v1/projects/{project_id} * * Also accepts auth: BearerAuth */ export const patchApiV1ProjectsProjectId = async (args: PatchApiV1ProjectsProjectIdArgs, options: PatchApiV1ProjectsProjectIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.project_id))}${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(projectResponse, await res.json()) };