import {z} from 'zod' export type UpdateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsArgs = {projectId: number, actionKey: string, body: {settings?: ({document_source?: ('both' | 'knowledge_base' | 'attachments') | undefined, allowed_file_types?: (Array<'pdf' | 'docx' | 'doc' | 'odt' | 'txt' | 'jpg' | 'jpeg' | 'png' | 'webp'>) | undefined, max_file_size?: number | undefined, max_files_per_prompt?: number | undefined, max_file_length?: number | undefined, max_image_size?: number | undefined, enable_reranker?: boolean | undefined, target_url?: string | undefined, required_fields?: (Array<'name' | 'email' | 'phone_number' | 'company'>) | undefined, extra_options?: Array | undefined, is_collect_utm_tags_enabled?: boolean | undefined, use_case?: string | undefined, custom_use_case?: string | undefined, button_triggers?: (Array<'every_response' | 'no_answer' | 'user_request'>) | undefined, extra_trigger_options?: Array | undefined, button_title?: string | undefined, cta_value?: string | undefined}) | undefined}}; export type UpdateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsResponse = z.object({status: z.enum(["error", "success"]).optional(), data: z.object({action: z.object({key: z.string().optional(), name: z.string().optional(), is_enabled: z.boolean().optional(), settings: z.object({}).nullable().optional()}).optional()}).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 built-in action settings. * * PUT /api/v1/projects/{projectId}/actions/builtin/{actionKey}/settings */ export const updateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettings = async (args: UpdateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsArgs, options?: UpdateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsOptions) => { const {baseUrl = "https://app.customgpt.ai", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectId))}/actions/builtin/${encodeURIComponent(String(args.actionKey))}/settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV1ProjectsProjectIdActionsBuiltinActionKeySettingsResponse, await res.json()) };