Add database config

This commit is contained in:
dwrz
2026-09-20 12:27:03 +00:00
parent 7e46c3e429
commit 19aed53fee
2 changed files with 66 additions and 0 deletions
+22
View File
@@ -41,6 +41,19 @@ func (cfg TTS) Validate() error {
return nil return nil
} }
// Database holds the SQLite database configuration.
type Database struct {
// Path is the filesystem path to the SQLite database file.
Path string `yaml:"path"`
}
func (cfg Database) Validate() error {
if cfg.Path == "" {
return fmt.Errorf("missing path")
}
return nil
}
// STT holds the configuration for the frontend-facing speech-to-text server. // STT holds the configuration for the frontend-facing speech-to-text server.
type STT struct { type STT struct {
// URL is the base URL of the whisper-server. // URL is the base URL of the whisper-server.
@@ -115,6 +128,9 @@ type JobConfig struct {
Task string `yaml:"task"` Task string `yaml:"task"`
// Timeout limits the job execution time (e.g., "10m"). // Timeout limits the job execution time (e.g., "10m").
Timeout string `yaml:"timeout,omitempty"` Timeout string `yaml:"timeout,omitempty"`
// UserId identifies the user that owns conversations created by this job.
// It is assigned by the service until jobs are stored in the database.
UserId string `yaml:"user_id,omitempty"`
} }
func (cfg JobConfig) Validate() error { func (cfg JobConfig) Validate() error {
@@ -130,6 +146,7 @@ func (cfg JobConfig) Validate() error {
if cfg.MaxIterations < 0 { if cfg.MaxIterations < 0 {
return fmt.Errorf("max_iterations must be non-negative") return fmt.Errorf("max_iterations must be non-negative")
} }
return nil return nil
} }
@@ -171,6 +188,8 @@ func (cfg ToolConfig) Validate() error {
type Config struct { type Config struct {
// Address is the host:port to listen on. // Address is the host:port to listen on.
Address string `yaml:"address"` Address string `yaml:"address"`
// Database configures the SQLite database path.
Database Database `yaml:"database"`
// ShutdownTimeout is the maximum time to wait for graceful shutdown. // ShutdownTimeout is the maximum time to wait for graceful shutdown.
ShutdownTimeout string `yaml:"shutdown_timeout"` ShutdownTimeout string `yaml:"shutdown_timeout"`
// shutdownTimeout is the parsed duration, set during Load. // shutdownTimeout is the parsed duration, set during Load.
@@ -211,6 +230,9 @@ func (cfg *Config) Validate() error {
if cfg.Address == "" { if cfg.Address == "" {
return fmt.Errorf("address required") return fmt.Errorf("address required")
} }
if err := cfg.Database.Validate(); err != nil {
return fmt.Errorf("invalid database config: %w", err)
}
if cfg.DefaultModel.Provider == "" { if cfg.DefaultModel.Provider == "" {
return fmt.Errorf("default_model.provider required") return fmt.Errorf("default_model.provider required")
} }
+44
View File
@@ -14,6 +14,9 @@ func validConfig() string {
address: ":9090" address: ":9090"
shutdown_timeout: "60s" shutdown_timeout: "60s"
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -76,6 +79,9 @@ func TestLoad(t *testing.T) {
{ {
name: "defaults applied", name: "defaults applied",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -115,6 +121,9 @@ tts:
{ {
name: "env expansion", name: "env expansion",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -149,6 +158,9 @@ tts:
{ {
name: "env expansion unset var becomes empty", name: "env expansion unset var becomes empty",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -182,6 +194,29 @@ tts:
config: `providers: [invalid yaml`, config: `providers: [invalid yaml`,
shouldErr: true, shouldErr: true,
}, },
{
name: "missing database path",
config: `
address: ":9090"
shutdown_timeout: "60s"
default_model:
provider: testprovider
model: test-model
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
tts:
url: http://localhost:8880
voice: af_heart
`,
shouldErr: true,
},
{ {
name: "invalid shutdown_timeout", name: "invalid shutdown_timeout",
config: ` config: `
@@ -322,6 +357,9 @@ tts:
{ {
name: "config with tools", name: "config with tools",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -462,6 +500,9 @@ func TestLoad_Jobs(t *testing.T) {
{ {
name: "valid job config", name: "valid job config",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model
@@ -514,6 +555,9 @@ jobs:
{ {
name: "job with minimal config (defaults)", name: "job with minimal config (defaults)",
config: ` config: `
database:
path: "/tmp/odidere-test.db"
default_model: default_model:
provider: testprovider provider: testprovider
model: test-model model: test-model