Files
HeatGuard/internal/config/config.go
vikingowl a89720fded feat: add LLM provider settings to web UI with encrypted API key storage
Add full LLM configuration section to the setup page with provider
dropdown, model/API key fields for cloud providers (Anthropic, OpenAI,
Gemini), and endpoint/model fields for Ollama. API keys are encrypted
with AES-256-GCM and stored in the database.
2026-02-09 11:41:16 +01:00

64 lines
1.4 KiB
Go

package config
import (
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
// Config holds the application configuration.
type Config struct {
LLM LLMConfig `yaml:"llm"`
}
// LLMConfig holds LLM provider settings.
type LLMConfig struct {
Provider string `yaml:"provider"` // anthropic, openai, ollama, none
Model string `yaml:"model"`
Endpoint string `yaml:"endpoint"` // for ollama
}
// DefaultConfig returns a Config with sensible defaults.
func DefaultConfig() Config {
return Config{
LLM: LLMConfig{Provider: "none"},
}
}
// ConfigDir returns the XDG config directory for heatwave.
func ConfigDir() string {
if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" {
return filepath.Join(xdg, "heatwave")
}
home, _ := os.UserHomeDir()
return filepath.Join(home, ".config", "heatwave")
}
// DataDir returns the XDG data directory for heatwave.
func DataDir() string {
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
return filepath.Join(xdg, "heatwave")
}
home, _ := os.UserHomeDir()
return filepath.Join(home, ".local", "share", "heatwave")
}
// DefaultDBPath returns the default SQLite database path.
func DefaultDBPath() string {
return filepath.Join(DataDir(), "heatwave.db")
}
// Load reads the config file from the config directory.
func Load() Config {
cfg := DefaultConfig()
path := filepath.Join(ConfigDir(), "config.yaml")
data, err := os.ReadFile(path)
if err != nil {
return cfg
}
_ = yaml.Unmarshal(data, &cfg)
return cfg
}