diff --git a/src/WebsearchSettings.jsx b/src/WebsearchSettings.jsx index 3918424..d96527b 100644 --- a/src/WebsearchSettings.jsx +++ b/src/WebsearchSettings.jsx @@ -1,21 +1,89 @@ // src/WebsearchSettings.jsx -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { WEBSEARCH_ENGINE_OPTIONS, normalizeWebsearchEngines } from './websearchEngines' +const BACKEND_API_URL_KEY = 'backendApiUrl' +const OLLAMA_API_URL_KEY = 'ollamaApiUrl' +const DEFAULT_BACKEND_API_URL = 'http://127.0.0.1:8000' +const DEFAULT_OLLAMA_API_URL = 'http://127.0.0.1:11434' + +function resolveBackendApiUrl(settings) { + return settings.backendApiUrl || settings.ollamaApiUrl || DEFAULT_BACKEND_API_URL +} + export default function WebsearchSettings({ + onBackendApiUrlChange, searxUrl, setSearxUrl, engines, setEngines, }) { + const [backendApiUrl, setBackendApiUrl] = useState('') + const [ollamaApiUrl, setOllamaApiUrl] = useState('') + + useEffect(() => { + let cancelled = false + + window.electronAPI.getSettings().then(settings => { + if (cancelled) { + return + } + setBackendApiUrl(resolveBackendApiUrl(settings)) + setOllamaApiUrl(settings.ollamaApiUrl || DEFAULT_OLLAMA_API_URL) + }) + + return () => { + cancelled = true + } + }, []) + const toggleEngine = (name) => { const set = new Set(engines || []); if (set.has(name)) set.delete(name); else set.add(name); setEngines(normalizeWebsearchEngines(Array.from(set))); } + const handleBackendUrlChange = (event) => { + const newUrl = event.target.value + setBackendApiUrl(newUrl) + window.electronAPI.setSetting(BACKEND_API_URL_KEY, newUrl) + if (onBackendApiUrlChange) { + onBackendApiUrlChange(newUrl) + } + } + + const handleOllamaUrlChange = (event) => { + const newUrl = event.target.value + setOllamaApiUrl(newUrl) + window.electronAPI.setSetting(OLLAMA_API_URL_KEY, newUrl) + } + return (
+
+

Heimgeist Backend URL

+ +

Internal UI requests like chats, sessions, and databases go to this URL.

+
+ +
+

Ollama URL

+ +

Heimgeist uses this URL to talk to Ollama for models and chat generation.

+
+

SearXNG URL