import {z} from 'zod' export type CustomLLMProvider = 'openai_compatible' | 'ollama' | 'openrouter' | 'gemini'; export type CustomLLMConfig = {display_name: string, provider: CustomLLMProvider, model_name: string, api_base?: (string | null) | undefined, api_key?: (string | null) | undefined, api_version?: (string | null) | undefined, supports_vision?: boolean | undefined, add_assistant_prefix?: boolean | undefined, max_completion_tokens?: (number | null) | undefined, temperature?: (number | null) | undefined, reasoning_effort?: (string | null) | undefined, extra_parameters?: {[key: string]: unknown} | undefined}; export type CustomLLMUpdateRequest = {config: CustomLLMConfig}; export type UpdateApiV1CustomLlmsCustomLlmIdArgs = {custom_llm_id: string, body: CustomLLMUpdateRequest}; export type UpdateApiV1CustomLlmsCustomLlmIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customLLMProvider = z.enum(["openai_compatible", "ollama", "openrouter", "gemini"]); export const customLLMConfig = z.object({display_name: z.string().min(1).max(120), provider: customLLMProvider, model_name: z.string().min(1).max(250), api_base: z.string().max(500).nullable().optional(), api_key: z.string().max(1000).nullable().optional(), api_version: z.string().max(100).nullable().optional(), supports_vision: z.boolean().optional(), add_assistant_prefix: z.boolean().optional(), max_completion_tokens: z.number().int().gte(1).lte(1000000).nullable().optional(), temperature: z.number().gte(0).lte(2).nullable().optional(), reasoning_effort: z.string().max(50).nullable().optional(), extra_parameters: z.record(z.string(), z.unknown()).optional()}); export const customLLM = z.object({id: z.string(), organization_id: z.string(), config: customLLMConfig, created_at: z.string(), modified_at: z.string(), valid: z.boolean()}); export const customLLMResponse = z.object({custom_llm: customLLM}); 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 Custom LLM * * PUT /v1/custom-llms/{custom_llm_id} */ export const updateApiV1CustomLlmsCustomLlmId = async (args: UpdateApiV1CustomLlmsCustomLlmIdArgs, options?: UpdateApiV1CustomLlmsCustomLlmIdOptions) => { const {baseUrl = "https://api.skyvern.com", 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/custom-llms/${encodeURIComponent(String(args.custom_llm_id))}${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(customLLMResponse, await res.json()) };