import { apiDelete, apiGet, apiPost, apiPut } from "./api-client"; import type { ConnectivityResult, CreateLLMProviderInput, LLMProvider, ModelListItem, UpdateLLMProviderInput, } from "@/types/llm-provider"; export async function listProviders(): Promise { const data = await apiGet<{ providers: LLMProvider[] }>( "/api/v1/llm/providers", ); return data.providers; } export async function getProvider(id: string): Promise { const data = await apiGet<{ provider: LLMProvider }>( `/api/v1/llm/providers/${encodeURIComponent(id)}`, ); return data.provider; } export async function createProvider( input: CreateLLMProviderInput, ): Promise { const data = await apiPost<{ provider: LLMProvider }>( "/api/v1/llm/providers", input, ); return data.provider; } export async function updateProvider( id: string, patch: UpdateLLMProviderInput, ): Promise { const data = await apiPut<{ provider: LLMProvider }>( `/api/v1/llm/providers/${encodeURIComponent(id)}`, patch, ); return data.provider; } export async function deleteProvider(id: string): Promise { await apiDelete<{ deleted: boolean }>( `/api/v1/llm/providers/${encodeURIComponent(id)}`, ); } export async function fetchProviderModels( id: string, ): Promise { const data = await apiGet<{ models: ModelListItem[] }>( `/api/v1/llm/providers/${encodeURIComponent(id)}/models`, ); return data.models; } export async function testProviderConnectivity( id: string, ): Promise { const data = await apiPost<{ result: ConnectivityResult }>( `/api/v1/llm/providers/${encodeURIComponent(id)}/test`, ); return data.result; }