60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package lib
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// Config holds application configuration.
|
|
type Config struct {
|
|
VaultKey []byte // decoded from VAULT_KEY hex env
|
|
Port string // default "8765"
|
|
DBPath string // default "./clawvault.db"
|
|
FireworksAPIKey string
|
|
LLMModel string // default llama-v3p3-70b-instruct
|
|
SessionTTL int64 // default 86400 (24 hours)
|
|
}
|
|
|
|
// LoadConfig loads configuration from environment variables.
|
|
func LoadConfig() (*Config, error) {
|
|
vaultKeyHex := os.Getenv("VAULT_KEY")
|
|
if vaultKeyHex == "" {
|
|
return nil, fmt.Errorf("VAULT_KEY environment variable required")
|
|
}
|
|
vaultKey, err := hex.DecodeString(vaultKeyHex)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("VAULT_KEY must be hex: %w", err)
|
|
}
|
|
if len(vaultKey) != 32 {
|
|
return nil, fmt.Errorf("VAULT_KEY must be 32 bytes (64 hex chars)")
|
|
}
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8765"
|
|
}
|
|
|
|
dbPath := os.Getenv("DB_PATH")
|
|
if dbPath == "" {
|
|
dbPath = "./clawvault.db"
|
|
}
|
|
|
|
fireworksKey := os.Getenv("FIREWORKS_API_KEY")
|
|
llmModel := os.Getenv("LLM_MODEL")
|
|
if llmModel == "" {
|
|
llmModel = "accounts/fireworks/models/llama-v3p3-70b-instruct"
|
|
}
|
|
|
|
sessionTTL := int64(86400) // 24 hours default
|
|
|
|
return &Config{
|
|
VaultKey: vaultKey,
|
|
Port: port,
|
|
DBPath: dbPath,
|
|
FireworksAPIKey: fireworksKey,
|
|
LLMModel: llmModel,
|
|
SessionTTL: sessionTTL,
|
|
}, nil
|
|
}
|