import {z} from 'zod' export type UpdateConfigRequest = {client_config?: ({drop_excess_requests?: boolean | undefined, prometheus_labels?: Array | undefined, allowed_origins?: Array | undefined, initial_pool_size?: number | undefined, enable_logging?: boolean | undefined, disable_content_logging?: boolean | undefined, allow_per_request_content_storage_override?: boolean | undefined, allow_per_request_raw_override?: boolean | undefined, enforce_auth_on_inference?: boolean | undefined, enforce_governance_header?: boolean | undefined, max_request_body_size_mb?: number | undefined, compat?: ({convert_text_to_chat?: boolean | undefined, convert_chat_to_responses?: boolean | undefined, should_drop_params?: boolean | undefined, should_convert_params?: boolean | undefined}) | undefined, log_retention_days?: number | undefined, header_filter_config?: ({allowlist?: Array | undefined, denylist?: Array | undefined}) | undefined, mcp_agent_depth?: number | undefined, mcp_tool_execution_timeout?: number | undefined, mcp_code_mode_binding_level?: string | undefined, required_headers?: Array | undefined, logging_headers?: Array | undefined, mcp_external_client_url?: (string | {value?: string | undefined, env_var?: string | undefined, from_env?: boolean | undefined}) | undefined, mcp_server_auth_mode?: ('headers' | 'both' | 'oauth') | undefined, oauth2_server_config?: ({issuer_url?: (string | {value?: string | undefined, env_var?: string | undefined, from_env?: boolean | undefined}) | undefined, auth_code_ttl?: number | undefined, access_token_ttl?: number | undefined, disable_vk_identity?: boolean | undefined}) | undefined}) | undefined, framework_config?: ({id?: number | undefined, pricing_url?: string | undefined, pricing_sync_interval?: number | undefined}) | undefined, auth_config?: ({admin_username?: string | undefined, admin_password?: string | undefined, is_enabled?: boolean | undefined, disable_auth_on_inference?: boolean | undefined}) | undefined}; export type UpdateApiApiConfigArgs = {body: UpdateConfigRequest}; export type UpdateApiApiConfigOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const successResponse = z.object({status: z.string().optional(), message: 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 configuration * * PUT /api/config */ export const updateApiApiConfig = async (args: UpdateApiApiConfigArgs, options?: UpdateApiApiConfigOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, ManagementBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ManagementBearerAuth !== undefined) headers.set('authorization', `Bearer ${ManagementBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/config${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(successResponse, await res.json()) };