diff --git a/tools/ui/src/lib/constants/backend.constants.ts b/tools/ui/src/lib/constants/backend.constants.ts new file mode 100644 index 0000000000..10f2d6dc19 --- /dev/null +++ b/tools/ui/src/lib/constants/backend.constants.ts @@ -0,0 +1,10 @@ +import type { BackendProtocol } from '$lib/types'; + +/** Id of the built-in backend that points at the server serving this UI. */ +export const LOCAL_BACKEND_ID = 'local'; + +/** Protocols a configured backend can speak, in display order. */ +export const BACKEND_PROTOCOLS: readonly BackendProtocol[] = ['llama.cpp', 'openai', 'anthropic']; + +/** Prefix for generated ids of user-added backends. */ +export const BACKEND_ID_PREFIX = 'backend'; diff --git a/tools/ui/src/lib/constants/index.ts b/tools/ui/src/lib/constants/index.ts index 58eb992313..6412511736 100644 --- a/tools/ui/src/lib/constants/index.ts +++ b/tools/ui/src/lib/constants/index.ts @@ -4,6 +4,7 @@ export * from './agentic.constants'; export * from './api-endpoints.constants'; export * from './app.constants'; +export * from './backend.constants'; export * from './chat-tabs.constants'; export * from './database.constants'; export * from './reasoning-effort.constants'; diff --git a/tools/ui/src/lib/types/backend.d.ts b/tools/ui/src/lib/types/backend.d.ts new file mode 100644 index 0000000000..1d05752516 --- /dev/null +++ b/tools/ui/src/lib/types/backend.d.ts @@ -0,0 +1,30 @@ +/** + * Backend types. + * + * A backend is one API endpoint the UI can talk to. The built-in `local` + * backend is the llama-server serving the UI. External backends are + * user-configured endpoints that speak an OpenAI- or Anthropic-compatible + * protocol. + */ + +/** Request/response shape a backend speaks. */ +export type BackendProtocol = 'llama.cpp' | 'openai' | 'anthropic'; + +/** One configured API endpoint. */ +export interface Backend { + /** Bearer token / API key used for this backend. */ + apiKey?: string; + /** + * API root the endpoint paths are appended to, e.g. https://api.example.com. + * Empty for the local backend, which resolves against the UI origin instead. + */ + baseUrl: string; + /** Disabled backends stay configured but are not queried. */ + enabled: boolean; + /** Extra headers merged into every request to this backend. */ + headers?: Record; + /** Stable identity. The local backend id is reserved. */ + id: string; + name: string; + protocol: BackendProtocol; +} diff --git a/tools/ui/src/lib/types/index.ts b/tools/ui/src/lib/types/index.ts index 7f35a13633..10d0d9ed2f 100644 --- a/tools/ui/src/lib/types/index.ts +++ b/tools/ui/src/lib/types/index.ts @@ -35,6 +35,9 @@ export type { ApiStreamSession } from './api'; +// Backend types +export type { Backend, BackendProtocol } from './backend'; + // HuggingFace types export type { HfCatalogBuild,