import { request } from "../request"; import type { ProviderInfo, ProviderConfigRequest, ActiveModelsInfo, ProviderUsageInfo, ModelSlotRequest, CreateCustomProviderRequest, AddModelRequest, TestConnectionResponse, TestModelRequest, FallbackConfig, } from "../types"; export const providerApi = { listProviders: () => request("/models"), configureProvider: (providerId: string, body: ProviderConfigRequest) => request(`/models/${encodeURIComponent(providerId)}/config`, { method: "PUT", body: JSON.stringify(body), }), getActiveModels: () => request("/models/active"), setActiveLlm: (body: ModelSlotRequest) => request("/models/active", { method: "PUT", body: JSON.stringify(body), }), getProviderUsage: (providerId: string) => request( `/models/${encodeURIComponent(providerId)}/usage`, ), /* ---- Custom provider CRUD ---- */ createCustomProvider: (body: CreateCustomProviderRequest) => request("/models/custom-providers", { method: "POST", body: JSON.stringify(body), }), deleteCustomProvider: (providerId: string) => request( `/models/custom-providers/${encodeURIComponent(providerId)}`, { method: "DELETE" }, ), /* ---- Model CRUD (works for both built-in and custom providers) ---- */ addModel: (providerId: string, body: AddModelRequest) => request(`/models/${encodeURIComponent(providerId)}/models`, { method: "POST", body: JSON.stringify(body), }), removeModel: (providerId: string, modelId: string) => request( `/models/${encodeURIComponent(providerId)}/models/${encodeURIComponent( modelId, )}`, { method: "DELETE" }, ), /* ---- Test Connection ---- */ testProviderConnection: ( providerId: string, body?: { api_key?: string; base_url?: string }, ) => request( `/models/${encodeURIComponent(providerId)}/test`, { method: "POST", body: body ? JSON.stringify(body) : undefined, }, ), testModelConnection: (providerId: string, body: TestModelRequest) => request( `/models/${encodeURIComponent(providerId)}/models/test`, { method: "POST", body: JSON.stringify(body), }, ), /* ---- Fallback chain ---- */ getFallbackConfig: () => request("/models/fallback"), setFallbackConfig: (body: FallbackConfig) => request("/models/fallback", { method: "PUT", body: JSON.stringify(body), }), };