Add GUI settings panel for API keys, model presets, and embedding model

- Add a password-protected /api/settings endpoint (HTTP Basic auth,
  backend/app/core/auth.py) backed by a DB-stored allowlist of
  connection settings (OPENAI_API_KEY, ANTHROPIC_API_KEY, AWS creds,
  OLLAMA_API_BASE, TAVILY_API_KEY, LOCAL_KB_EMBEDDING_MODEL). Saved
  values override .env and apply immediately via os.environ, so
  Lightsail deployments no longer need SSH + `.env` edits to rotate
  keys. Values are always returned masked to the frontend.
- Replace ModelSelector.vue's hardcoded model list with a DB-backed
  /api/models CRUD API (read is public, writes reuse the settings
  password) so the chat model dropdown can be edited from the GUI;
  seed it once with the previous hardcoded presets on first boot.
- Fix local_knowledge.py reading LOCAL_KB_EMBEDDING_MODEL once at
  import time instead of per-call, which would have silently ignored
  GUI/DB overrides for the embedding model.
- Add SettingsPanel.vue (API keys + model management UI) and document
  the new SETTINGS_PASSWORD env var in .env.example and the Lightsail
  deploy guide.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-18 01:27:08 +09:00
co-authored by Claude Sonnet 5
parent 8e01458bb2
commit d207537b53
16 changed files with 788 additions and 25 deletions
+66
View File
@@ -81,6 +81,72 @@ export async function deleteLog(logId: number): Promise<void> {
await fetch(`${BASE}/logs/${logId}`, { method: 'DELETE' })
}
export interface SettingEntry {
key: string
is_set: boolean
masked: string | null
overridden: boolean
}
function authHeader(password: string): HeadersInit {
return { Authorization: `Basic ${btoa(`x:${password}`)}` }
}
export async function fetchSettings(password: string): Promise<SettingEntry[]> {
const res = await fetch(`${BASE}/api/settings`, { headers: authHeader(password) })
return parseJson<SettingEntry[]>(res, '設定取得')
}
export async function saveSettings(values: Record<string, string>, password: string): Promise<SettingEntry[]> {
const res = await fetch(`${BASE}/api/settings`, {
method: 'PUT',
headers: { ...authHeader(password), 'Content-Type': 'application/json' },
body: JSON.stringify({ values }),
})
return parseJson<SettingEntry[]>(res, '設定保存')
}
export async function clearSetting(key: string, password: string): Promise<SettingEntry[]> {
const res = await fetch(`${BASE}/api/settings/${key}`, {
method: 'DELETE',
headers: authHeader(password),
})
return parseJson<SettingEntry[]>(res, '設定クリア')
}
export interface ModelPreset {
id: number
label: string
value: string
}
export async function fetchModelPresets(): Promise<ModelPreset[]> {
const res = await fetch(`${BASE}/api/models`)
return parseJson<ModelPreset[]>(res, 'モデル一覧取得')
}
export async function createModelPreset(label: string, value: string, password: string): Promise<ModelPreset> {
const res = await fetch(`${BASE}/api/models`, {
method: 'POST',
headers: { ...authHeader(password), 'Content-Type': 'application/json' },
body: JSON.stringify({ label, value }),
})
return parseJson<ModelPreset>(res, 'モデル追加')
}
export async function updateModelPreset(id: number, label: string, value: string, password: string): Promise<ModelPreset> {
const res = await fetch(`${BASE}/api/models/${id}`, {
method: 'PUT',
headers: { ...authHeader(password), 'Content-Type': 'application/json' },
body: JSON.stringify({ label, value }),
})
return parseJson<ModelPreset>(res, 'モデル更新')
}
export async function deleteModelPreset(id: number, password: string): Promise<void> {
await fetch(`${BASE}/api/models/${id}`, { method: 'DELETE', headers: authHeader(password) })
}
export function streamChat(
message: string,
sessionId: string | null,