import {z} from 'zod' export type AssistantInputTypeEnum = 'prompt' | 'form'; export type FormFieldTypeEnum = 'text' | 'selection' | 'number' | 'email' | 'checkbox' | 'date' | 'file'; export type FormField = {name?: (string | null) | undefined, label: string, type: FormFieldTypeEnum, required?: boolean | undefined, options?: (Array | null) | undefined, placeholder?: (string | null) | undefined, description?: (string | null) | undefined}; export type AssistantIn = {name: string, model?: (string | null) | undefined, avatar?: (string | null) | undefined, description?: (string | null) | undefined, description_show_in_chat?: boolean | undefined, predefined_prompts?: (Array | null) | undefined, instructions?: (string | null) | undefined, temperature?: (number | null) | undefined, similarity_top_k?: (number | null) | undefined, input_type?: AssistantInputTypeEnum | undefined, form_fields?: (Array | null) | undefined}; export type PatchApiAssistantsAssistantIdArgs = {assistant_id: number, cookie_name?: (string | null) | undefined, body: AssistantIn}; export type PatchApiAssistantsAssistantIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const assistant = z.object({state: z.string().nullable().optional(), state_reason: z.string().nullable().optional(), state_changed_at: z.string().nullable().optional(), id: z.number().int().nullable().optional(), tenant_id: z.number().int(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), creator_user_id: z.number().int(), name: z.string(), avatar: z.string().nullable().optional(), description: z.string().nullable().optional(), description_show_in_chat: z.boolean().optional(), predefined_prompts: z.array(z.unknown()).nullable().optional(), instructions: z.string().nullable().optional(), llm_catalog_id: z.number().int().nullable().optional(), temperature: z.number().nullable().optional(), similarity_top_k: z.number().int().nullable().optional(), input_type: z.string().optional(), form_fields: z.array(z.unknown()).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 }; /** * Update an assistant * * PATCH /assistants/{assistant_id} */ export const patchApiAssistantsAssistantId = async (args: PatchApiAssistantsAssistantIdArgs, options?: PatchApiAssistantsAssistantIdOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/assistants/${encodeURIComponent(String(args.assistant_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(assistant, await res.json()) };