2025-08-05 03:56:23 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
"github.com/goccy/go-yaml"
|
2025-08-05 03:56:23 +02:00
|
|
|
)
|
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
type EnvTokens struct {
|
|
|
|
OpenRouter string `json:"openrouter"`
|
|
|
|
Exa string `json:"exa"`
|
|
|
|
}
|
2025-08-14 17:08:45 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
type EnvSettings struct {
|
2025-08-16 15:16:34 +02:00
|
|
|
CleanContent bool `json:"cleanup"`
|
|
|
|
MaxIterations uint `json:"iterations"`
|
2025-08-16 15:15:06 +02:00
|
|
|
}
|
2025-08-14 17:08:45 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
type Environment struct {
|
|
|
|
Debug bool `json:"debug"`
|
|
|
|
Tokens EnvTokens `json:"tokens"`
|
|
|
|
Settings EnvSettings `json:"settings"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var env Environment
|
2025-08-05 03:56:23 +02:00
|
|
|
|
|
|
|
func init() {
|
2025-08-16 15:15:06 +02:00
|
|
|
file, err := os.OpenFile("config.yml", os.O_RDONLY, 0)
|
|
|
|
log.MustPanic(err)
|
2025-08-05 03:56:23 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
defer file.Close()
|
2025-08-14 03:53:14 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
err = yaml.NewDecoder(file).Decode(&env)
|
|
|
|
log.MustPanic(err)
|
2025-08-14 17:08:45 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
log.MustPanic(env.Init())
|
|
|
|
}
|
2025-08-14 17:08:45 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
func (e *Environment) Init() error {
|
|
|
|
// print if debug is enabled
|
|
|
|
if e.Debug {
|
|
|
|
log.Warning("Debug mode enabled")
|
|
|
|
}
|
2025-08-14 03:53:14 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
// check max iterations
|
|
|
|
e.Settings.MaxIterations = max(e.Settings.MaxIterations, 1)
|
2025-08-14 03:53:14 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
// check if openrouter token is set
|
|
|
|
if e.Tokens.OpenRouter == "" {
|
|
|
|
return errors.New("missing tokens.openrouter")
|
2025-08-14 03:53:14 +02:00
|
|
|
}
|
2025-08-11 01:16:52 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
// check if exa token is set
|
|
|
|
if e.Tokens.Exa == "" {
|
|
|
|
log.Warning("missing token.exa, web search unavailable")
|
2025-08-05 03:56:23 +02:00
|
|
|
}
|
2025-08-11 01:16:52 +02:00
|
|
|
|
2025-08-16 15:15:06 +02:00
|
|
|
return nil
|
2025-08-05 03:56:23 +02:00
|
|
|
}
|