import {z} from 'zod' export type NetworkConfig = {base_url?: string | undefined, extra_headers?: {[key: string]: string} | undefined, default_request_timeout_in_seconds?: number | undefined, max_retries?: number | undefined, retry_backoff_initial?: number | undefined, retry_backoff_max?: number | undefined, insecure_skip_verify?: boolean | undefined, ca_cert_pem?: string | undefined, allow_private_network?: boolean | undefined}; export type ConcurrencyAndBufferSize = {concurrency?: number | undefined, buffer_size?: number | undefined}; export type ModelProvider = 'openai' | 'azure' | 'anthropic' | 'bedrock' | 'cohere' | 'vertex' | 'vllm' | 'mistral' | 'ollama' | 'groq' | 'sgl' | 'parasail' | 'perplexity' | 'replicate' | 'cerebras' | 'deepseek' | 'gemini' | 'openrouter' | 'elevenlabs' | 'huggingface' | 'nebius' | 'xai' | 'runway' | 'fireworks'; export type UpdateProviderRequest = {network_config?: NetworkConfig | undefined, concurrency_and_buffer_size?: ConcurrencyAndBufferSize | undefined, proxy_config?: ({type?: ('none' | 'http' | 'socks5' | 'environment') | undefined, url?: string | undefined, username?: string | undefined, password?: string | undefined, ca_cert_pem?: string | undefined}) | undefined, send_back_raw_request?: boolean | undefined, send_back_raw_response?: boolean | undefined, store_raw_request_response?: boolean | undefined, custom_provider_config?: ({is_key_less?: boolean | undefined, base_provider_type?: ModelProvider | undefined, allowed_requests?: ({list_models?: boolean | undefined, text_completion?: boolean | undefined, text_completion_stream?: boolean | undefined, chat_completion?: boolean | undefined, chat_completion_stream?: boolean | undefined, responses?: boolean | undefined, responses_stream?: boolean | undefined, count_tokens?: boolean | undefined, embedding?: boolean | undefined, speech?: boolean | undefined, speech_stream?: boolean | undefined, transcription?: boolean | undefined, transcription_stream?: boolean | undefined, image_generation?: boolean | undefined, image_generation_stream?: boolean | undefined, batch_create?: boolean | undefined, batch_list?: boolean | undefined, batch_retrieve?: boolean | undefined, batch_cancel?: boolean | undefined, batch_results?: boolean | undefined, file_upload?: boolean | undefined, file_list?: boolean | undefined, file_retrieve?: boolean | undefined, file_delete?: boolean | undefined, file_content?: boolean | undefined}) | undefined, request_path_overrides?: {[key: string]: string} | undefined}) | undefined}; export type UpdateApiApiProvidersProviderArgs = {provider: string, body: UpdateProviderRequest}; export type UpdateApiApiProvidersProviderOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelProvider = z.enum(["openai", "azure", "anthropic", "bedrock", "cohere", "vertex", "vllm", "mistral", "ollama", "groq", "sgl", "parasail", "perplexity", "replicate", "cerebras", "deepseek", "gemini", "openrouter", "elevenlabs", "huggingface", "nebius", "xai", "runway", "fireworks"]); export const networkConfig = z.object({base_url: z.string().optional(), extra_headers: z.record(z.string(), z.string()).optional(), default_request_timeout_in_seconds: z.number().int().optional(), max_retries: z.number().int().optional(), retry_backoff_initial: z.number().int().optional(), retry_backoff_max: z.number().int().optional(), insecure_skip_verify: z.boolean().optional(), ca_cert_pem: z.string().optional(), allow_private_network: z.boolean().optional()}); export const concurrencyAndBufferSize = z.object({concurrency: z.number().int().optional(), buffer_size: z.number().int().optional()}); export const providerResponse = z.object({name: modelProvider.optional(), network_config: networkConfig.optional(), concurrency_and_buffer_size: concurrencyAndBufferSize.optional(), proxy_config: z.object({type: z.enum(["none", "http", "socks5", "environment"]).optional(), url: z.string().optional(), username: z.string().optional(), password: z.string().optional(), ca_cert_pem: z.string().optional()}).optional(), send_back_raw_request: z.boolean().optional(), send_back_raw_response: z.boolean().optional(), store_raw_request_response: z.boolean().optional(), custom_provider_config: z.object({is_key_less: z.boolean().optional(), base_provider_type: modelProvider.optional(), allowed_requests: z.object({list_models: z.boolean().optional(), text_completion: z.boolean().optional(), text_completion_stream: z.boolean().optional(), chat_completion: z.boolean().optional(), chat_completion_stream: z.boolean().optional(), responses: z.boolean().optional(), responses_stream: z.boolean().optional(), count_tokens: z.boolean().optional(), embedding: z.boolean().optional(), speech: z.boolean().optional(), speech_stream: z.boolean().optional(), transcription: z.boolean().optional(), transcription_stream: z.boolean().optional(), image_generation: z.boolean().optional(), image_generation_stream: z.boolean().optional(), batch_create: z.boolean().optional(), batch_list: z.boolean().optional(), batch_retrieve: z.boolean().optional(), batch_cancel: z.boolean().optional(), batch_results: z.boolean().optional(), file_upload: z.boolean().optional(), file_list: z.boolean().optional(), file_retrieve: z.boolean().optional(), file_delete: z.boolean().optional(), file_content: z.boolean().optional()}).optional(), request_path_overrides: z.record(z.string(), z.string()).optional()}).optional(), provider_status: z.enum(["active", "error", "deleted"]).optional(), status: z.string().optional(), description: z.string().optional(), config_hash: 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 a provider * * PUT /api/providers/{provider} */ export const updateApiApiProvidersProvider = async (args: UpdateApiApiProvidersProviderArgs, options?: UpdateApiApiProvidersProviderOptions) => { 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/providers/${encodeURIComponent(String(args.provider))}${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(providerResponse, await res.json()) };