Files
tm_back/cmd/web/bootstrap/config.go
T
Mazyar 20518e7b64
continuous-integration/drone/push Build is passing
Enhance AI recommendation caching and onboarding process in company service
- Updated `AISummarizerConfig` to allow for a default `RecommendationCacheTTL` of 0, enabling persistent caching until company updates.
- Refactored `StartAIOnboarding` to include cache invalidation and asynchronous recommendation refresh, improving responsiveness during onboarding.
- Introduced `triggerAIOnboardingAsync` method for background processing of AI onboarding and cache refresh, enhancing user experience.
- Improved logging for AI onboarding and recommendation fetching processes, providing better observability and error tracking.

This update optimizes the AI recommendation caching mechanism and onboarding workflow, ensuring a smoother and more efficient experience for users.
2026-06-23 13:43:39 +03:30

92 lines
3.8 KiB
Go

package bootstrap
import (
"time"
"tm/pkg/config"
)
// Config holds configuration for the web command
type Config struct {
Server config.ServerConfig
Database config.DatabaseConfig
Cache config.CacheConfig
Logging config.LoggingConfig
RateLimit config.RateLimitConfig
Assets config.AssetsConfig
Notification config.NotificationConfig
Ollama config.OllamaConfig
HCaptcha config.HCaptchaConfig
Scraper ScraperConfig
TED TEDConfig
UserAuth AuthConfig
CustomerAuth AuthConfig
DocumentScraper DocumentScraperConfig
AISummarizer AISummarizerConfig
GoRules GoRulesConfig
}
type ScraperConfig struct {
BaseURL string `env:"SCRAPER_BASE_URL"`
Timeout time.Duration `env:"SCRAPER_TIMEOUT"`
}
// TEDConfig holds configuration for TED scraper (one-time scraping from admin panel)
type TEDConfig struct {
BaseURL string `env:"TED_BASE_URL" envDefault:"https://ted.europa.eu"`
Timeout time.Duration `env:"TED_TIMEOUT" envDefault:"30s"`
MaxRetries int `env:"TED_MAX_RETRIES" envDefault:"3"`
RetryDelay time.Duration `env:"TED_RETRY_DELAY" envDefault:"5s"`
UserAgent string `env:"TED_USER_AGENT" envDefault:"TM-TED-Scraper/1.0"`
MaxConcurrency int `env:"TED_MAX_CONCURRENCY" envDefault:"5"`
DownloadDir string `env:"TED_DOWNLOAD_DIR" envDefault:"./downloads"`
CleanupAfter time.Duration `env:"TED_CLEANUP_AFTER" envDefault:"24h"`
ScrapingInterval string `env:"TED_SCRAPING_INTERVAL" envDefault:"* * 10 * * *"`
MaxNoticesPerDay int `env:"TED_MAX_NOTICES_PER_DAY" envDefault:"0"`
AlertMail string `env:"ALERT_MAIL" envDefault:"alerts@opplens.com"`
}
type AuthConfig struct {
JWT JWTConfig
}
type JWTConfig struct {
AccessSecret string `env:"USER_AUTH_ACCESS_SECRET"`
RefreshSecret string `env:"USER_AUTH_REFRESH_SECRET"`
AccessExpiresIn int `env:"USER_AUTH_ACCESS_EXPIRES_IN"`
RefreshExpiresIn int `env:"USER_AUTH_REFRESH_EXPIRES_IN"`
}
// DocumentScraperConfig holds configuration for the external document scraper service API
type DocumentScraperConfig struct {
APIKey string `env:"DOCUMENT_SCRAPER_API_KEY" envDefault:""`
}
// AISummarizerConfig holds configuration for the external AI summarizer service
type AISummarizerConfig struct {
// HTTP API settings
APIBaseURL string `env:"AI_SUMMARIZER_API_BASE_URL" envDefault:""`
APITimeout time.Duration `env:"AI_SUMMARIZER_API_TIMEOUT" envDefault:"120s"`
APIRetryCount int `env:"AI_SUMMARIZER_API_RETRY_COUNT" envDefault:"2"`
APIRetryDelay time.Duration `env:"AI_SUMMARIZER_API_RETRY_DELAY" envDefault:"3s"`
DefaultLanguage string `env:"AI_SUMMARIZER_DEFAULT_LANGUAGE" envDefault:"en"`
// RecommendationCacheTTL is an optional max Redis TTL for cached recommendations.
// When 0 (default), entries persist until the company is created, updated, or onboarded.
RecommendationCacheTTL time.Duration `env:"AI_RECOMMENDATION_CACHE_TTL" envDefault:"0"`
// MinIO storage settings
MinioEndpoint string `env:"AI_SUMMARIZER_MINIO_ENDPOINT" envDefault:""`
MinioAccessKey string `env:"AI_SUMMARIZER_MINIO_ACCESS_KEY" envDefault:""`
MinioSecretKey string `env:"AI_SUMMARIZER_MINIO_SECRET_KEY" envDefault:""`
MinioUseSSL bool `env:"AI_SUMMARIZER_MINIO_USE_SSL" envDefault:"false"`
MinioRegion string `env:"AI_SUMMARIZER_MINIO_REGION" envDefault:"us-east-1"`
MinioBucket string `env:"AI_SUMMARIZER_MINIO_BUCKET" envDefault:"opplens"`
}
// GoRulesConfig holds configuration for the GoRules status engine.
type GoRulesConfig struct {
BaseURL string `env:"GORULES_BASE_URL"`
Token string `env:"GORULES_TOKEN"`
RuleID string `env:"GORULES_RULE_ID"`
Timeout time.Duration `env:"GORULES_TIMEOUT"`
}