562261d13f
- Profile-aware proxy: inject API key from profile-specific .env, route requests via X-Hermes-Profile header - Remove auth.json dependency: built-in providers use .env, custom providers use config.yaml - Add allProviders field to available-models response with all hardcoded provider catalogs - Add Models tab in Settings for editing provider API keys (built-in → .env, custom → config.yaml) - Add PUT /api/config/providers/:poolKey for updating provider credentials - ProviderFormModal uses backend allProviders for preset dropdown - Gateway log format support: parse both agent and gateway log formats - Add webui server.log to log viewer with log rotation at 3MB - Fix provider delete loading state and OAuth provider cleanup - Setup script: require Node.js 23+, auto-upgrade if version too low Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import router from '@/router'
|
|
|
|
const DEFAULT_BASE_URL = ''
|
|
|
|
function getBaseUrl(): string {
|
|
return localStorage.getItem('hermes_server_url') || DEFAULT_BASE_URL
|
|
}
|
|
|
|
export function getApiKey(): string {
|
|
return localStorage.getItem('hermes_api_key') || ''
|
|
}
|
|
|
|
export function setServerUrl(url: string) {
|
|
localStorage.setItem('hermes_server_url', url)
|
|
}
|
|
|
|
export function setApiKey(key: string) {
|
|
localStorage.setItem('hermes_api_key', key)
|
|
}
|
|
|
|
export function clearApiKey() {
|
|
localStorage.removeItem('hermes_api_key')
|
|
}
|
|
|
|
export function hasApiKey(): boolean {
|
|
return !!getApiKey()
|
|
}
|
|
|
|
export async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
const base = getBaseUrl()
|
|
const url = `${base}${path}`
|
|
const headers: Record<string, string> = {
|
|
'Content-Type': 'application/json',
|
|
...options.headers as Record<string, string>,
|
|
}
|
|
|
|
const apiKey = getApiKey()
|
|
if (apiKey) {
|
|
headers['Authorization'] = `Bearer ${apiKey}`
|
|
}
|
|
|
|
// Inject active profile header for proxied gateway requests
|
|
const profileName = localStorage.getItem('hermes_active_profile_name')
|
|
if (profileName && profileName !== 'default') {
|
|
headers['X-Hermes-Profile'] = profileName
|
|
}
|
|
|
|
const res = await fetch(url, { ...options, headers })
|
|
|
|
// Global 401 handler — only redirect to login for local BFF endpoints
|
|
// Proxied gateway requests should not trigger logout
|
|
const isLocalBff = !path.startsWith('/api/hermes/v1/') &&
|
|
!path.startsWith('/api/hermes/jobs') &&
|
|
!path.startsWith('/api/hermes/skills')
|
|
|
|
if (res.status === 401 && isLocalBff) {
|
|
clearApiKey()
|
|
if (router.currentRoute.value.name !== 'login') {
|
|
router.replace({ name: 'login' })
|
|
}
|
|
throw new Error('Unauthorized')
|
|
}
|
|
|
|
if (!res.ok) {
|
|
const text = await res.text().catch(() => '')
|
|
throw new Error(`API Error ${res.status}: ${text || res.statusText}`)
|
|
}
|
|
|
|
return res.json()
|
|
}
|
|
|
|
export function getBaseUrlValue(): string {
|
|
return getBaseUrl()
|
|
}
|