- Added file upload handler to process both multipart and raw file uploads. - Implemented parsing logic for upload requests, including handling file metadata. - Introduced SaveFileDecodedInput structure for handling decoded file uploads. - Created unit tests for file upload parsing and validation. feat: add metadata retry configuration and functionality - Introduced MetadataRetryConfig to the application configuration. - Implemented MetadataRetryer to handle retrying metadata extraction for thoughts. - Added new tool for retrying failed metadata extractions. - Updated thought metadata structure to include status and timestamps for metadata processing. fix: enhance metadata normalization and error handling - Updated metadata normalization functions to track status and errors. - Improved handling of metadata extraction failures during thought updates and captures. - Ensured that metadata status is correctly set during various operations. refactor: streamline file saving logic in FilesTool - Refactored Save method in FilesTool to utilize new SaveDecoded method. - Simplified project and thought ID resolution logic during file saving.
135 lines
3.0 KiB
Go
135 lines
3.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func Load(explicitPath string) (*Config, string, error) {
|
|
path := ResolvePath(explicitPath)
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, path, fmt.Errorf("read config %q: %w", path, err)
|
|
}
|
|
|
|
cfg := defaultConfig()
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, path, fmt.Errorf("decode config %q: %w", path, err)
|
|
}
|
|
|
|
applyEnvOverrides(&cfg)
|
|
if err := cfg.Validate(); err != nil {
|
|
return nil, path, err
|
|
}
|
|
|
|
return &cfg, path, nil
|
|
}
|
|
|
|
func ResolvePath(explicitPath string) string {
|
|
if path := strings.TrimSpace(explicitPath); path != "" {
|
|
if path != ".yaml" && path != ".yml" {
|
|
return path
|
|
}
|
|
}
|
|
|
|
if envPath := strings.TrimSpace(os.Getenv("AMCS_CONFIG")); envPath != "" {
|
|
return envPath
|
|
}
|
|
|
|
return DefaultConfigPath
|
|
}
|
|
|
|
func defaultConfig() Config {
|
|
return Config{
|
|
Server: ServerConfig{
|
|
Host: "0.0.0.0",
|
|
Port: 8080,
|
|
ReadTimeout: 15 * time.Second,
|
|
WriteTimeout: 30 * time.Second,
|
|
IdleTimeout: 60 * time.Second,
|
|
},
|
|
MCP: MCPConfig{
|
|
Path: "/mcp",
|
|
ServerName: "amcs",
|
|
Version: "0.1.0",
|
|
Transport: "streamable_http",
|
|
},
|
|
Auth: AuthConfig{
|
|
HeaderName: "x-brain-key",
|
|
QueryParam: "key",
|
|
},
|
|
AI: AIConfig{
|
|
Provider: "litellm",
|
|
Embeddings: AIEmbeddingConfig{
|
|
Model: "openai/text-embedding-3-small",
|
|
Dimensions: 1536,
|
|
},
|
|
Metadata: AIMetadataConfig{
|
|
Model: "gpt-4o-mini",
|
|
Temperature: 0.1,
|
|
Timeout: 10 * time.Second,
|
|
},
|
|
Ollama: OllamaConfig{
|
|
BaseURL: "http://localhost:11434/v1",
|
|
APIKey: "ollama",
|
|
},
|
|
},
|
|
Capture: CaptureConfig{
|
|
Source: DefaultSource,
|
|
MetadataDefaults: CaptureMetadataDefault{
|
|
Type: "observation",
|
|
TopicFallback: "uncategorized",
|
|
},
|
|
},
|
|
Search: SearchConfig{
|
|
DefaultLimit: 10,
|
|
DefaultThreshold: 0.5,
|
|
MaxLimit: 50,
|
|
},
|
|
Logging: LoggingConfig{
|
|
Level: "info",
|
|
Format: "json",
|
|
},
|
|
Backfill: BackfillConfig{
|
|
Enabled: false,
|
|
RunOnStartup: false,
|
|
Interval: 15 * time.Minute,
|
|
BatchSize: 20,
|
|
MaxPerRun: 100,
|
|
},
|
|
MetadataRetry: MetadataRetryConfig{
|
|
Enabled: false,
|
|
RunOnStartup: false,
|
|
Interval: 24 * time.Hour,
|
|
MaxPerRun: 100,
|
|
},
|
|
}
|
|
}
|
|
|
|
func applyEnvOverrides(cfg *Config) {
|
|
overrideString(&cfg.Database.URL, "AMCS_DATABASE_URL")
|
|
overrideString(&cfg.AI.LiteLLM.BaseURL, "AMCS_LITELLM_BASE_URL")
|
|
overrideString(&cfg.AI.LiteLLM.APIKey, "AMCS_LITELLM_API_KEY")
|
|
overrideString(&cfg.AI.Ollama.BaseURL, "AMCS_OLLAMA_BASE_URL")
|
|
overrideString(&cfg.AI.Ollama.APIKey, "AMCS_OLLAMA_API_KEY")
|
|
overrideString(&cfg.AI.OpenRouter.APIKey, "AMCS_OPENROUTER_API_KEY")
|
|
|
|
if value, ok := os.LookupEnv("AMCS_SERVER_PORT"); ok {
|
|
if port, err := strconv.Atoi(strings.TrimSpace(value)); err == nil {
|
|
cfg.Server.Port = port
|
|
}
|
|
}
|
|
}
|
|
|
|
func overrideString(target *string, envKey string) {
|
|
if value, ok := os.LookupEnv(envKey); ok {
|
|
*target = strings.TrimSpace(value)
|
|
}
|
|
}
|