2026-04-16 08:38:18 +08:00
|
|
|
import { request } from '../client'
|
2026-04-11 15:59:14 +08:00
|
|
|
|
|
|
|
|
export interface HealthResponse {
|
|
|
|
|
status: string
|
|
|
|
|
version?: string
|
2026-04-16 13:51:42 +08:00
|
|
|
webui_version?: string
|
|
|
|
|
webui_latest?: string
|
|
|
|
|
webui_update_available?: boolean
|
2026-04-23 12:57:42 +08:00
|
|
|
node_version?: string
|
2026-04-11 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 23:23:50 +08:00
|
|
|
// Config-based model types
|
|
|
|
|
export interface ModelInfo {
|
|
|
|
|
id: string
|
|
|
|
|
label: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ModelGroup {
|
|
|
|
|
provider: string
|
|
|
|
|
models: ModelInfo[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ConfigModelsResponse {
|
|
|
|
|
default: string
|
|
|
|
|
groups: ModelGroup[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AvailableModelGroup {
|
|
|
|
|
provider: string // credential pool key (e.g. "zai", "custom:subrouter.ai")
|
|
|
|
|
label: string // display name (e.g. "zai", "subrouter.ai")
|
|
|
|
|
base_url: string
|
|
|
|
|
models: string[]
|
2026-04-19 20:59:25 +08:00
|
|
|
api_key: string
|
2026-05-07 22:16:52 +08:00
|
|
|
builtin?: boolean
|
2026-04-26 22:51:35 +08:00
|
|
|
/** 可选:模型 ID -> 元数据(preview/disabled)。目前仅 Copilot 提供。 */
|
|
|
|
|
model_meta?: Record<string, { preview?: boolean; disabled?: boolean }>
|
2026-04-12 23:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AvailableModelsResponse {
|
|
|
|
|
default: string
|
2026-04-19 15:05:05 +08:00
|
|
|
default_provider: string
|
2026-04-12 23:23:50 +08:00
|
|
|
groups: AvailableModelGroup[]
|
2026-04-19 20:59:25 +08:00
|
|
|
allProviders: AvailableModelGroup[]
|
2026-04-12 23:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CustomProvider {
|
|
|
|
|
name: string
|
|
|
|
|
base_url: string
|
|
|
|
|
api_key: string
|
|
|
|
|
model: string
|
2026-04-24 11:18:11 +08:00
|
|
|
context_length?: number
|
2026-04-13 12:15:16 +08:00
|
|
|
providerKey?: string | null
|
2026-04-12 23:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-11 15:59:14 +08:00
|
|
|
export async function checkHealth(): Promise<HealthResponse> {
|
|
|
|
|
return request<HealthResponse>('/health')
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-16 13:51:42 +08:00
|
|
|
export async function triggerUpdate(): Promise<{ success: boolean; message: string }> {
|
|
|
|
|
return request<{ success: boolean; message: string }>('/api/hermes/update', { method: 'POST' })
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 23:23:50 +08:00
|
|
|
export async function fetchConfigModels(): Promise<ConfigModelsResponse> {
|
2026-04-16 08:38:18 +08:00
|
|
|
return request<ConfigModelsResponse>('/api/hermes/config/models')
|
2026-04-12 23:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchAvailableModels(): Promise<AvailableModelsResponse> {
|
2026-04-16 08:38:18 +08:00
|
|
|
return request<AvailableModelsResponse>('/api/hermes/available-models')
|
2026-04-12 23:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateDefaultModel(data: {
|
|
|
|
|
default: string
|
|
|
|
|
provider?: string
|
|
|
|
|
base_url?: string
|
|
|
|
|
api_key?: string
|
|
|
|
|
}): Promise<void> {
|
2026-04-16 08:38:18 +08:00
|
|
|
await request('/api/hermes/config/model', {
|
2026-04-12 23:23:50 +08:00
|
|
|
method: 'PUT',
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addCustomProvider(data: CustomProvider): Promise<void> {
|
2026-04-16 08:38:18 +08:00
|
|
|
await request('/api/hermes/config/providers', {
|
2026-04-12 23:23:50 +08:00
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removeCustomProvider(name: string): Promise<void> {
|
2026-04-16 08:38:18 +08:00
|
|
|
await request(`/api/hermes/config/providers/${encodeURIComponent(name)}`, {
|
2026-04-12 23:23:50 +08:00
|
|
|
method: 'DELETE',
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-19 20:59:25 +08:00
|
|
|
|
|
|
|
|
export async function updateProvider(poolKey: string, data: {
|
|
|
|
|
name?: string
|
|
|
|
|
base_url?: string
|
|
|
|
|
api_key?: string
|
|
|
|
|
model?: string
|
|
|
|
|
}): Promise<void> {
|
|
|
|
|
await request(`/api/hermes/config/providers/${encodeURIComponent(poolKey)}`, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
})
|
|
|
|
|
}
|