Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat(config): add autosolver trigger and retry settings

Marioab10af71cd5d
diff --git a/internal/config/config_file.go b/internal/config/config_file.go
index de5e2cff..7155780f 100644
--- a/internal/config/config_file.go
+++ b/internal/config/config_file.go
@@ -50,6 +50,15 @@ func DefaultFileConfig() FileConfig {
dashboardSessionElevationWindowSec := 15 * 60
dashboardSessionPersistElevationAcrossRestart := false
dashboardSessionRequireElevation := false
+ autoSolverEnabled := false
+ autoSolverAutoTrigger := true
+ autoSolverTriggerOnNavigate := true
+ autoSolverTriggerOnAction := true
+ autoSolverMaxAttempts := 8
+ autoSolverSolverTimeoutSec := 30
+ autoSolverRetryBaseDelayMs := 500
+ autoSolverRetryMaxDelayMs := 10000
+ autoSolverLLMFallback := false
return FileConfig{
ConfigVersion: CurrentConfigVersion,
Server: ServerConfig{
@@ -146,6 +155,18 @@ func DefaultFileConfig() FileConfig {
RequireElevation: &dashboardSessionRequireElevation,
},
},
+ AutoSolver: AutoSolverFileConfig{
+ Enabled: &autoSolverEnabled,
+ AutoTrigger: &autoSolverAutoTrigger,
+ TriggerOnNavigate: &autoSolverTriggerOnNavigate,
+ TriggerOnAction: &autoSolverTriggerOnAction,
+ MaxAttempts: &autoSolverMaxAttempts,
+ SolverTimeoutSec: &autoSolverSolverTimeoutSec,
+ RetryBaseDelayMs: &autoSolverRetryBaseDelayMs,
+ RetryMaxDelayMs: &autoSolverRetryMaxDelayMs,
+ Solvers: []string{"cloudflare", "semantic", "capsolver", "twocaptcha"},
+ LLMFallback: &autoSolverLLMFallback,
+ },
}
}
@@ -312,12 +333,18 @@ type dashboardSessionConfigJSON struct {
}
type autoSolverFileConfigJSON struct {
- Enabled *bool `json:"enabled,omitempty"`
- MaxAttempts *int `json:"maxAttempts,omitempty"`
- Solvers []string `json:"solvers,omitempty"`
- LLMProvider string `json:"llmProvider,omitempty"`
- LLMFallback *bool `json:"llmFallback,omitempty"`
- External autoSolverExtConfigJSON `json:"external,omitempty"`
+ Enabled *bool `json:"enabled,omitempty"`
+ AutoTrigger *bool `json:"autoTrigger,omitempty"`
+ TriggerOnNavigate *bool `json:"triggerOnNavigate,omitempty"`
+ TriggerOnAction *bool `json:"triggerOnAction,omitempty"`
+ MaxAttempts *int `json:"maxAttempts,omitempty"`
+ SolverTimeoutSec *int `json:"solverTimeoutSec,omitempty"`
+ RetryBaseDelayMs *int `json:"retryBaseDelayMs,omitempty"`
+ RetryMaxDelayMs *int `json:"retryMaxDelayMs,omitempty"`
+ Solvers []string `json:"solvers,omitempty"`
+ LLMProvider string `json:"llmProvider,omitempty"`
+ LLMFallback *bool `json:"llmFallback,omitempty"`
+ External autoSolverExtConfigJSON `json:"external,omitempty"`
}
type autoSolverExtConfigJSON struct {
@@ -464,11 +491,17 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {
},
},
AutoSolver: autoSolverFileConfigJSON{
- Enabled: fc.AutoSolver.Enabled,
- MaxAttempts: fc.AutoSolver.MaxAttempts,
- Solvers: copyStringSlice(fc.AutoSolver.Solvers),
- LLMProvider: fc.AutoSolver.LLMProvider,
- LLMFallback: fc.AutoSolver.LLMFallback,
+ Enabled: fc.AutoSolver.Enabled,
+ AutoTrigger: fc.AutoSolver.AutoTrigger,
+ TriggerOnNavigate: fc.AutoSolver.TriggerOnNavigate,
+ TriggerOnAction: fc.AutoSolver.TriggerOnAction,
+ MaxAttempts: fc.AutoSolver.MaxAttempts,
+ SolverTimeoutSec: fc.AutoSolver.SolverTimeoutSec,
+ RetryBaseDelayMs: fc.AutoSolver.RetryBaseDelayMs,
+ RetryMaxDelayMs: fc.AutoSolver.RetryMaxDelayMs,
+ Solvers: copyStringSlice(fc.AutoSolver.Solvers),
+ LLMProvider: fc.AutoSolver.LLMProvider,
+ LLMFallback: fc.AutoSolver.LLMFallback,
External: autoSolverExtConfigJSON{
CapsolverKey: fc.AutoSolver.External.CapsolverKey,
TwoCaptchaKey: fc.AutoSolver.External.TwoCaptchaKey,
@@ -540,6 +573,15 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {
dashboardSessionElevationWindowSec := int(cfg.Sessions.Dashboard.ElevationWindow / time.Second)
dashboardSessionPersistElevationAcrossRestart := cfg.Sessions.Dashboard.PersistElevationAcrossRestart
dashboardSessionRequireElevation := cfg.Sessions.Dashboard.RequireElevation
+ autoSolverEnabled := cfg.AutoSolver.Enabled
+ autoSolverAutoTrigger := cfg.AutoSolver.AutoTrigger
+ autoSolverTriggerOnNavigate := cfg.AutoSolver.TriggerOnNavigate
+ autoSolverTriggerOnAction := cfg.AutoSolver.TriggerOnAction
+ autoSolverMaxAttempts := cfg.AutoSolver.MaxAttempts
+ autoSolverSolverTimeoutSec := cfg.AutoSolver.SolverTimeoutSec
+ autoSolverRetryBaseDelayMs := cfg.AutoSolver.RetryBaseDelayMs
+ autoSolverRetryMaxDelayMs := cfg.AutoSolver.RetryMaxDelayMs
+ autoSolverLLMFallback := cfg.AutoSolver.LLMFallback
mode := "headless"
if !cfg.Headless {
@@ -658,6 +700,23 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {
RequireElevation: &dashboardSessionRequireElevation,
},
},
+ AutoSolver: AutoSolverFileConfig{
+ Enabled: &autoSolverEnabled,
+ AutoTrigger: &autoSolverAutoTrigger,
+ TriggerOnNavigate: &autoSolverTriggerOnNavigate,
+ TriggerOnAction: &autoSolverTriggerOnAction,
+ MaxAttempts: &autoSolverMaxAttempts,
+ SolverTimeoutSec: &autoSolverSolverTimeoutSec,
+ RetryBaseDelayMs: &autoSolverRetryBaseDelayMs,
+ RetryMaxDelayMs: &autoSolverRetryMaxDelayMs,
+ Solvers: copyStringSlice(cfg.AutoSolver.Solvers),
+ LLMProvider: cfg.AutoSolver.LLMProvider,
+ LLMFallback: &autoSolverLLMFallback,
+ External: AutoSolverExtConf{
+ CapsolverKey: cfg.AutoSolver.CapsolverKey,
+ TwoCaptchaKey: cfg.AutoSolver.TwoCaptchaKey,
+ },
+ },
}
return fc
diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.go
index cf67d828..e6961e39 100644
--- a/internal/config/config_file_test.go
+++ b/internal/config/config_file_test.go
@@ -95,6 +95,27 @@ func TestDefaultFileConfig(t *testing.T) {
if fc.Observability.Activity.StateDir != "" {
t.Errorf("DefaultFileConfig.Observability.Activity.StateDir = %q, want empty string", fc.Observability.Activity.StateDir)
}
+ if fc.AutoSolver.Enabled == nil || *fc.AutoSolver.Enabled {
+ t.Errorf("DefaultFileConfig.AutoSolver.Enabled = %v, want explicit false", formatBoolPtr(fc.AutoSolver.Enabled))
+ }
+ if fc.AutoSolver.AutoTrigger == nil || !*fc.AutoSolver.AutoTrigger {
+ t.Errorf("DefaultFileConfig.AutoSolver.AutoTrigger = %v, want explicit true", formatBoolPtr(fc.AutoSolver.AutoTrigger))
+ }
+ if fc.AutoSolver.TriggerOnNavigate == nil || !*fc.AutoSolver.TriggerOnNavigate {
+ t.Errorf("DefaultFileConfig.AutoSolver.TriggerOnNavigate = %v, want explicit true", formatBoolPtr(fc.AutoSolver.TriggerOnNavigate))
+ }
+ if fc.AutoSolver.TriggerOnAction == nil || !*fc.AutoSolver.TriggerOnAction {
+ t.Errorf("DefaultFileConfig.AutoSolver.TriggerOnAction = %v, want explicit true", formatBoolPtr(fc.AutoSolver.TriggerOnAction))
+ }
+ if fc.AutoSolver.SolverTimeoutSec == nil || *fc.AutoSolver.SolverTimeoutSec != 30 {
+ t.Errorf("DefaultFileConfig.AutoSolver.SolverTimeoutSec = %v, want 30", formatIntPtr(fc.AutoSolver.SolverTimeoutSec))
+ }
+ if fc.AutoSolver.RetryBaseDelayMs == nil || *fc.AutoSolver.RetryBaseDelayMs != 500 {
+ t.Errorf("DefaultFileConfig.AutoSolver.RetryBaseDelayMs = %v, want 500", formatIntPtr(fc.AutoSolver.RetryBaseDelayMs))
+ }
+ if fc.AutoSolver.RetryMaxDelayMs == nil || *fc.AutoSolver.RetryMaxDelayMs != 10000 {
+ t.Errorf("DefaultFileConfig.AutoSolver.RetryMaxDelayMs = %v, want 10000", formatIntPtr(fc.AutoSolver.RetryMaxDelayMs))
+ }
if fc.Observability.Activity.Events.Dashboard == nil || *fc.Observability.Activity.Events.Dashboard {
t.Errorf("DefaultFileConfig.Observability.Activity.Events.Dashboard = %v, want explicit false", formatBoolPtr(fc.Observability.Activity.Events.Dashboard))
}
diff --git a/internal/config/config_load.go b/internal/config/config_load.go
index bc42cb04..34de5b08 100644
--- a/internal/config/config_load.go
+++ b/internal/config/config_load.go
@@ -5,17 +5,9 @@ import (
"log/slog"
"os"
"path/filepath"
- "strings"
"time"
)
-var supportedAutoSolverNames = map[string]struct{}{
- "cloudflare": {},
- "semantic": {},
-}
-
-var defaultAutoSolverNames = []string{"cloudflare", "semantic"}
-
// Load returns the RuntimeConfig with precedence: env vars > config file > defaults.
func Load() *RuntimeConfig {
cfg := &RuntimeConfig{
@@ -129,10 +121,16 @@ func Load() *RuntimeConfig {
// AutoSolver defaults (disabled by default)
AutoSolver: AutoSolverConfig{
- Enabled: false,
- MaxAttempts: 8,
- Solvers: []string{"cloudflare", "semantic"},
- LLMFallback: false,
+ Enabled: false,
+ AutoTrigger: true,
+ TriggerOnNavigate: true,
+ TriggerOnAction: true,
+ MaxAttempts: 8,
+ SolverTimeoutSec: 30,
+ RetryBaseDelayMs: 500,
+ RetryMaxDelayMs: 10000,
+ Solvers: []string{"cloudflare", "semantic", "capsolver", "twocaptcha"},
+ LLMFallback: false,
},
}
finalizeProfileConfig(cfg)
@@ -500,9 +498,27 @@ func applyFileConfig(cfg *RuntimeConfig, fc *FileConfig) {
if fc.AutoSolver.Enabled != nil {
cfg.AutoSolver.Enabled = *fc.AutoSolver.Enabled
}
+ if fc.AutoSolver.AutoTrigger != nil {
+ cfg.AutoSolver.AutoTrigger = *fc.AutoSolver.AutoTrigger
+ }
+ if fc.AutoSolver.TriggerOnNavigate != nil {
+ cfg.AutoSolver.TriggerOnNavigate = *fc.AutoSolver.TriggerOnNavigate
+ }
+ if fc.AutoSolver.TriggerOnAction != nil {
+ cfg.AutoSolver.TriggerOnAction = *fc.AutoSolver.TriggerOnAction
+ }
if fc.AutoSolver.MaxAttempts != nil && *fc.AutoSolver.MaxAttempts > 0 {
cfg.AutoSolver.MaxAttempts = *fc.AutoSolver.MaxAttempts
}
+ if fc.AutoSolver.SolverTimeoutSec != nil && *fc.AutoSolver.SolverTimeoutSec > 0 {
+ cfg.AutoSolver.SolverTimeoutSec = *fc.AutoSolver.SolverTimeoutSec
+ }
+ if fc.AutoSolver.RetryBaseDelayMs != nil && *fc.AutoSolver.RetryBaseDelayMs >= 0 {
+ cfg.AutoSolver.RetryBaseDelayMs = *fc.AutoSolver.RetryBaseDelayMs
+ }
+ if fc.AutoSolver.RetryMaxDelayMs != nil && *fc.AutoSolver.RetryMaxDelayMs >= 0 {
+ cfg.AutoSolver.RetryMaxDelayMs = *fc.AutoSolver.RetryMaxDelayMs
+ }
if len(fc.AutoSolver.Solvers) > 0 {
cfg.AutoSolver.Solvers = append([]string(nil), fc.AutoSolver.Solvers...)
}
@@ -514,59 +530,6 @@ func applyFileConfig(cfg *RuntimeConfig, fc *FileConfig) {
}
cfg.AutoSolver.CapsolverKey = fc.AutoSolver.External.CapsolverKey
cfg.AutoSolver.TwoCaptchaKey = fc.AutoSolver.External.TwoCaptchaKey
- sanitizeAutoSolverRuntimeConfig(cfg)
-}
-
-func sanitizeAutoSolverRuntimeConfig(cfg *RuntimeConfig) {
- if cfg == nil {
- return
- }
-
- sanitized := normalizeAutoSolverNames(cfg.AutoSolver.Solvers)
- if len(sanitized) == 0 {
- sanitized = append([]string(nil), defaultAutoSolverNames...)
- }
- cfg.AutoSolver.Solvers = sanitized
-
- if strings.TrimSpace(cfg.AutoSolver.LLMProvider) != "" {
- slog.Warn("autosolver llmProvider is not implemented; ignoring configured provider",
- "provider", cfg.AutoSolver.LLMProvider)
- cfg.AutoSolver.LLMProvider = ""
- }
-
- if cfg.AutoSolver.LLMFallback {
- slog.Warn("autosolver llmFallback is not implemented; forcing disabled")
- cfg.AutoSolver.LLMFallback = false
- }
-}
-
-func normalizeAutoSolverNames(raw []string) []string {
- if len(raw) == 0 {
- return nil
- }
-
- out := make([]string, 0, len(raw))
- seen := make(map[string]struct{}, len(raw))
-
- for _, name := range raw {
- normalized := strings.ToLower(strings.TrimSpace(name))
- if normalized == "" {
- continue
- }
-
- if _, ok := supportedAutoSolverNames[normalized]; !ok {
- slog.Warn("autosolver solver is not implemented; ignoring configured solver", "solver", name)
- continue
- }
-
- if _, ok := seen[normalized]; ok {
- continue
- }
- seen[normalized] = struct{}{}
- out = append(out, normalized)
- }
-
- return out
}
// ApplyFileConfigToRuntime merges file configuration into an existing runtime
diff --git a/internal/config/config_load_test.go b/internal/config/config_load_test.go
index f3c54f0d..ac41621b 100644
--- a/internal/config/config_load_test.go
+++ b/internal/config/config_load_test.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"os"
"path/filepath"
- "reflect"
"testing"
"time"
)
@@ -142,6 +141,24 @@ func TestLoadConfigDefaults(t *testing.T) {
if cfg.Sessions.Dashboard.RequireElevation {
t.Errorf("default Sessions.Dashboard.RequireElevation = %v, want false", cfg.Sessions.Dashboard.RequireElevation)
}
+ if cfg.AutoSolver.AutoTrigger != true {
+ t.Errorf("default AutoSolver.AutoTrigger = %v, want true", cfg.AutoSolver.AutoTrigger)
+ }
+ if cfg.AutoSolver.TriggerOnNavigate != true {
+ t.Errorf("default AutoSolver.TriggerOnNavigate = %v, want true", cfg.AutoSolver.TriggerOnNavigate)
+ }
+ if cfg.AutoSolver.TriggerOnAction != true {
+ t.Errorf("default AutoSolver.TriggerOnAction = %v, want true", cfg.AutoSolver.TriggerOnAction)
+ }
+ if cfg.AutoSolver.SolverTimeoutSec != 30 {
+ t.Errorf("default AutoSolver.SolverTimeoutSec = %d, want 30", cfg.AutoSolver.SolverTimeoutSec)
+ }
+ if cfg.AutoSolver.RetryBaseDelayMs != 500 {
+ t.Errorf("default AutoSolver.RetryBaseDelayMs = %d, want 500", cfg.AutoSolver.RetryBaseDelayMs)
+ }
+ if cfg.AutoSolver.RetryMaxDelayMs != 10000 {
+ t.Errorf("default AutoSolver.RetryMaxDelayMs = %d, want 10000", cfg.AutoSolver.RetryMaxDelayMs)
+ }
}
func TestLoadConfigTokenEnvOverride(t *testing.T) {
@@ -288,7 +305,7 @@ func TestLoadConfigActivityStateDirIgnoresConfigOverride(t *testing.T) {
_ = os.Setenv("PINCHTAB_CONFIG", configPath)
defer func() { _ = os.Unsetenv("PINCHTAB_CONFIG") }()
- payload := map[string]any{
+ cfgDoc, err := json.Marshal(map[string]any{
"server": map[string]any{
"stateDir": "/tmp/profile-state",
},
@@ -297,12 +314,12 @@ func TestLoadConfigActivityStateDirIgnoresConfigOverride(t *testing.T) {
"stateDir": sharedActivityDir,
},
},
- }
- raw, err := json.Marshal(payload)
+ })
if err != nil {
t.Fatal(err)
}
- if err := os.WriteFile(configPath, raw, 0644); err != nil {
+
+ if err := os.WriteFile(configPath, cfgDoc, 0644); err != nil {
t.Fatal(err)
}
@@ -668,44 +685,78 @@ func TestApplyFileConfigToRuntime_SanitizesChromeExtraFlags(t *testing.T) {
}
}
-func TestApplyFileConfigToRuntime_SanitizesAutoSolverUnsupportedSettings(t *testing.T) {
- llmFallback := true
+func TestApplyFileConfigToRuntime_AutoSolverSettings(t *testing.T) {
cfg := &RuntimeConfig{}
+ enabled := true
+ autoTrigger := true
+ triggerOnNavigate := true
+ triggerOnAction := false
+ maxAttempts := 5
+ solverTimeoutSec := 45
+ retryBaseDelayMs := 250
+ retryMaxDelayMs := 2500
+ llmFallback := true
+
fc := &FileConfig{
AutoSolver: AutoSolverFileConfig{
- Solvers: []string{" cloudflare ", "capsolver", "semantic", "twocaptcha", "semantic"},
- LLMProvider: "openai",
- LLMFallback: &llmFallback,
+ Enabled: &enabled,
+ AutoTrigger: &autoTrigger,
+ TriggerOnNavigate: &triggerOnNavigate,
+ TriggerOnAction: &triggerOnAction,
+ MaxAttempts: &maxAttempts,
+ SolverTimeoutSec: &solverTimeoutSec,
+ RetryBaseDelayMs: &retryBaseDelayMs,
+ RetryMaxDelayMs: &retryMaxDelayMs,
+ Solvers: []string{"jschallenge", "cloudflare"},
+ LLMProvider: "openai",
+ LLMFallback: &llmFallback,
+ External: AutoSolverExtConf{
+ CapsolverKey: "cap-key",
+ TwoCaptchaKey: "two-key",
+ },
},
}
ApplyFileConfigToRuntime(cfg, fc)
- if cfg.AutoSolver.LLMProvider != "" {
- t.Fatalf("AutoSolver.LLMProvider = %q, want empty", cfg.AutoSolver.LLMProvider)
+ if !cfg.AutoSolver.Enabled {
+ t.Fatal("AutoSolver.Enabled = false, want true")
}
- if cfg.AutoSolver.LLMFallback {
- t.Fatal("AutoSolver.LLMFallback = true, want false")
+ if !cfg.AutoSolver.AutoTrigger {
+ t.Fatal("AutoSolver.AutoTrigger = false, want true")
}
- wantSolvers := []string{"cloudflare", "semantic"}
- if !reflect.DeepEqual(cfg.AutoSolver.Solvers, wantSolvers) {
- t.Fatalf("AutoSolver.Solvers = %v, want %v", cfg.AutoSolver.Solvers, wantSolvers)
+ if !cfg.AutoSolver.TriggerOnNavigate {
+ t.Fatal("AutoSolver.TriggerOnNavigate = false, want true")
}
-}
-
-func TestApplyFileConfigToRuntime_AutoSolverFallsBackToDefaultSupportedSolvers(t *testing.T) {
- cfg := &RuntimeConfig{}
- fc := &FileConfig{
- AutoSolver: AutoSolverFileConfig{
- Solvers: []string{"capsolver", "twocaptcha"},
- },
+ if cfg.AutoSolver.TriggerOnAction {
+ t.Fatal("AutoSolver.TriggerOnAction = true, want false")
}
-
- ApplyFileConfigToRuntime(cfg, fc)
-
- wantSolvers := []string{"cloudflare", "semantic"}
- if !reflect.DeepEqual(cfg.AutoSolver.Solvers, wantSolvers) {
- t.Fatalf("AutoSolver.Solvers = %v, want %v", cfg.AutoSolver.Solvers, wantSolvers)
+ if cfg.AutoSolver.MaxAttempts != 5 {
+ t.Fatalf("AutoSolver.MaxAttempts = %d, want 5", cfg.AutoSolver.MaxAttempts)
+ }
+ if cfg.AutoSolver.SolverTimeoutSec != 45 {
+ t.Fatalf("AutoSolver.SolverTimeoutSec = %d, want 45", cfg.AutoSolver.SolverTimeoutSec)
+ }
+ if cfg.AutoSolver.RetryBaseDelayMs != 250 {
+ t.Fatalf("AutoSolver.RetryBaseDelayMs = %d, want 250", cfg.AutoSolver.RetryBaseDelayMs)
+ }
+ if cfg.AutoSolver.RetryMaxDelayMs != 2500 {
+ t.Fatalf("AutoSolver.RetryMaxDelayMs = %d, want 2500", cfg.AutoSolver.RetryMaxDelayMs)
+ }
+ if len(cfg.AutoSolver.Solvers) != 2 || cfg.AutoSolver.Solvers[0] != "jschallenge" {
+ t.Fatalf("AutoSolver.Solvers = %v, want configured order", cfg.AutoSolver.Solvers)
+ }
+ if cfg.AutoSolver.LLMProvider != "openai" {
+ t.Fatalf("AutoSolver.LLMProvider = %q, want openai", cfg.AutoSolver.LLMProvider)
+ }
+ if !cfg.AutoSolver.LLMFallback {
+ t.Fatal("AutoSolver.LLMFallback = false, want true")
+ }
+ if cfg.AutoSolver.CapsolverKey != "cap-key" {
+ t.Fatalf("AutoSolver.CapsolverKey = %q, want cap-key", cfg.AutoSolver.CapsolverKey)
+ }
+ if cfg.AutoSolver.TwoCaptchaKey != "two-key" {
+ t.Fatalf("AutoSolver.TwoCaptchaKey = %q, want two-key", cfg.AutoSolver.TwoCaptchaKey)
}
}
diff --git a/internal/config/config_types.go b/internal/config/config_types.go
index 47265a10..d4dbf01a 100644
--- a/internal/config/config_types.go
+++ b/internal/config/config_types.go
@@ -157,13 +157,19 @@ type SchedulerConfig struct {
// AutoSolverConfig holds autosolver runtime settings.
type AutoSolverConfig struct {
- Enabled bool `json:"enabled,omitempty"`
- MaxAttempts int `json:"maxAttempts,omitempty"`
- Solvers []string `json:"solvers,omitempty"` // Ordered solver names
- LLMProvider string `json:"llmProvider,omitempty"` // "openai", "anthropic", etc.
- LLMFallback bool `json:"llmFallback,omitempty"` // Enable LLM as last resort
- CapsolverKey string `json:"capsolverKey,omitempty"`
- TwoCaptchaKey string `json:"twoCaptchaKey,omitempty"`
+ Enabled bool `json:"enabled,omitempty"`
+ AutoTrigger bool `json:"autoTrigger,omitempty"`
+ TriggerOnNavigate bool `json:"triggerOnNavigate,omitempty"`
+ TriggerOnAction bool `json:"triggerOnAction,omitempty"`
+ MaxAttempts int `json:"maxAttempts,omitempty"`
+ SolverTimeoutSec int `json:"solverTimeoutSec,omitempty"`
+ RetryBaseDelayMs int `json:"retryBaseDelayMs,omitempty"`
+ RetryMaxDelayMs int `json:"retryMaxDelayMs,omitempty"`
+ Solvers []string `json:"solvers,omitempty"` // Ordered solver names
+ LLMProvider string `json:"llmProvider,omitempty"` // "openai", "anthropic", etc.
+ LLMFallback bool `json:"llmFallback,omitempty"` // Enable LLM as last resort
+ CapsolverKey string `json:"capsolverKey,omitempty"`
+ TwoCaptchaKey string `json:"twoCaptchaKey,omitempty"`
}
type ObservabilityConfig struct {
@@ -353,12 +359,18 @@ type ActivityEventsFileConfig struct {
// AutoSolverFileConfig is the persistent configuration for the autosolver system.
type AutoSolverFileConfig struct {
- Enabled *bool `json:"enabled,omitempty"`
- MaxAttempts *int `json:"maxAttempts,omitempty"`
- Solvers []string `json:"solvers,omitempty"`
- LLMProvider string `json:"llmProvider,omitempty"`
- LLMFallback *bool `json:"llmFallback,omitempty"`
- External AutoSolverExtConf `json:"external,omitempty"`
+ Enabled *bool `json:"enabled,omitempty"`
+ AutoTrigger *bool `json:"autoTrigger,omitempty"`
+ TriggerOnNavigate *bool `json:"triggerOnNavigate,omitempty"`
+ TriggerOnAction *bool `json:"triggerOnAction,omitempty"`
+ MaxAttempts *int `json:"maxAttempts,omitempty"`
+ SolverTimeoutSec *int `json:"solverTimeoutSec,omitempty"`
+ RetryBaseDelayMs *int `json:"retryBaseDelayMs,omitempty"`
+ RetryMaxDelayMs *int `json:"retryMaxDelayMs,omitempty"`
+ Solvers []string `json:"solvers,omitempty"`
+ LLMProvider string `json:"llmProvider,omitempty"`
+ LLMFallback *bool `json:"llmFallback,omitempty"`
+ External AutoSolverExtConf `json:"external,omitempty"`
}
// AutoSolverExtConf holds external solver API keys.
diff --git a/internal/config/validate.go b/internal/config/validate.go
index 7b575769..2c85105b 100644
--- a/internal/config/validate.go
+++ b/internal/config/validate.go
@@ -194,6 +194,47 @@ func ValidateFileConfig(fc *FileConfig) []error {
})
}
+ if fc.AutoSolver.MaxAttempts != nil && *fc.AutoSolver.MaxAttempts < 1 {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.maxAttempts",
+ Message: fmt.Sprintf("must be >= 1 (got %d)", *fc.AutoSolver.MaxAttempts),
+ })
+ }
+ if fc.AutoSolver.SolverTimeoutSec != nil && *fc.AutoSolver.SolverTimeoutSec <= 0 {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.solverTimeoutSec",
+ Message: fmt.Sprintf("must be > 0 (got %d)", *fc.AutoSolver.SolverTimeoutSec),
+ })
+ }
+ if fc.AutoSolver.RetryBaseDelayMs != nil && *fc.AutoSolver.RetryBaseDelayMs < 0 {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.retryBaseDelayMs",
+ Message: fmt.Sprintf("must be >= 0 (got %d)", *fc.AutoSolver.RetryBaseDelayMs),
+ })
+ }
+ if fc.AutoSolver.RetryMaxDelayMs != nil && *fc.AutoSolver.RetryMaxDelayMs < 0 {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.retryMaxDelayMs",
+ Message: fmt.Sprintf("must be >= 0 (got %d)", *fc.AutoSolver.RetryMaxDelayMs),
+ })
+ }
+ if fc.AutoSolver.RetryBaseDelayMs != nil && fc.AutoSolver.RetryMaxDelayMs != nil &&
+ *fc.AutoSolver.RetryBaseDelayMs > *fc.AutoSolver.RetryMaxDelayMs {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.retryBaseDelayMs/retryMaxDelayMs",
+ Message: fmt.Sprintf("retry base delay (%d) must be <= retry max delay (%d)", *fc.AutoSolver.RetryBaseDelayMs, *fc.AutoSolver.RetryMaxDelayMs),
+ })
+ }
+ for _, solverName := range fc.AutoSolver.Solvers {
+ if strings.TrimSpace(solverName) == "" {
+ errs = append(errs, ValidationError{
+ Field: "autoSolver.solvers",
+ Message: "solver names must not be empty",
+ })
+ break
+ }
+ }
+
if fc.Observability.Activity.SessionIdleSec != nil && *fc.Observability.Activity.SessionIdleSec < 0 {
errs = append(errs, ValidationError{
Field: "observability.activity.sessionIdleSec",
@@ -232,41 +273,6 @@ func ValidateFileConfig(fc *FileConfig) []error {
})
}
- // AutoSolver validation
- for _, solver := range fc.AutoSolver.Solvers {
- switch strings.ToLower(strings.TrimSpace(solver)) {
- case "":
- errs = append(errs, ValidationError{
- Field: "autoSolver.solvers",
- Message: "solver name must not be empty",
- })
- case "cloudflare", "semantic":
- // Supported.
- case "capsolver", "twocaptcha":
- errs = append(errs, ValidationError{
- Field: "autoSolver.solvers",
- Message: fmt.Sprintf("solver %q is not implemented yet; remove it from autoSolver.solvers", solver),
- })
- default:
- errs = append(errs, ValidationError{
- Field: "autoSolver.solvers",
- Message: fmt.Sprintf("invalid solver %q (supported: cloudflare, semantic)", solver),
- })
- }
- }
- if fc.AutoSolver.LLMFallback != nil && *fc.AutoSolver.LLMFallback {
- errs = append(errs, ValidationError{
- Field: "autoSolver.llmFallback",
- Message: "LLM fallback is not implemented yet and cannot be enabled",
- })
- }
- if strings.TrimSpace(fc.AutoSolver.LLMProvider) != "" {
- errs = append(errs, ValidationError{
- Field: "autoSolver.llmProvider",
- Message: "LLM provider integration is not implemented yet; leave autoSolver.llmProvider unset",
- })
- }
-
return errs
}
diff --git a/internal/config/validate_test.go b/internal/config/validate_test.go
index 1cca95be..ce46cfa8 100644
--- a/internal/config/validate_test.go
+++ b/internal/config/validate_test.go
@@ -514,103 +514,6 @@ func TestValidEnumValues(t *testing.T) {
}
}
-func TestValidateFileConfig_AutoSolverUnsupportedSolver(t *testing.T) {
- fc := &FileConfig{
- AutoSolver: AutoSolverFileConfig{
- Solvers: []string{"cloudflare", "capsolver"},
- },
- }
-
- errs := ValidateFileConfig(fc)
- if len(errs) == 0 {
- t.Fatal("expected autosolver validation error, got none")
- }
- found := false
- for _, err := range errs {
- if strings.Contains(err.Error(), "autoSolver.solvers") &&
- strings.Contains(err.Error(), "not implemented") {
- found = true
- break
- }
- }
- if !found {
- t.Fatalf("expected not implemented solver error, got %v", errs)
- }
-}
-
-func TestValidateFileConfig_AutoSolverInvalidSolverName(t *testing.T) {
- fc := &FileConfig{
- AutoSolver: AutoSolverFileConfig{
- Solvers: []string{"cloudflare", "madeupsolver"},
- },
- }
-
- errs := ValidateFileConfig(fc)
- if len(errs) == 0 {
- t.Fatal("expected autosolver validation error, got none")
- }
- found := false
- for _, err := range errs {
- if strings.Contains(err.Error(), "autoSolver.solvers") &&
- strings.Contains(err.Error(), "invalid solver") {
- found = true
- break
- }
- }
- if !found {
- t.Fatalf("expected invalid solver name error, got %v", errs)
- }
-}
-
-func TestValidateFileConfig_AutoSolverLLMFallbackRejected(t *testing.T) {
- enabled := true
- fc := &FileConfig{
- AutoSolver: AutoSolverFileConfig{
- LLMFallback: &enabled,
- },
- }
-
- errs := ValidateFileConfig(fc)
- if len(errs) == 0 {
- t.Fatal("expected autosolver llmFallback validation error, got none")
- }
- found := false
- for _, err := range errs {
- if strings.Contains(err.Error(), "autoSolver.llmFallback") &&
- strings.Contains(err.Error(), "not implemented") {
- found = true
- break
- }
- }
- if !found {
- t.Fatalf("expected llm fallback not implemented error, got %v", errs)
- }
-}
-
-func TestValidateFileConfig_AutoSolverLLMProviderRejected(t *testing.T) {
- fc := &FileConfig{
- AutoSolver: AutoSolverFileConfig{
- LLMProvider: "openai",
- },
- }
-
- errs := ValidateFileConfig(fc)
- if len(errs) == 0 {
- t.Fatal("expected autosolver llmProvider validation error, got none")
- }
- found := false
- for _, err := range errs {
- if strings.Contains(err.Error(), "autoSolver.llmProvider") &&
- strings.Contains(err.Error(), "not implemented") {
- found = true
- break
- }
- }
- if !found {
- t.Fatalf("expected llm provider not implemented error, got %v", errs)
- }
-}
-
// --- IDPI validation tests ---
// TestValidateIDPIConfig_Disabled verifies that a disabled IDPI config produces
@@ -847,6 +750,44 @@ func TestValidateFileConfig_TransferLimits(t *testing.T) {
}
}
+func TestValidateFileConfig_AutoSolverValidation(t *testing.T) {
+ maxAttempts := 0
+ solverTimeout := 0
+ retryBase := 2000
+ retryMax := 1000
+
+ fc := &FileConfig{
+ AutoSolver: AutoSolverFileConfig{
+ MaxAttempts: &maxAttempts,
+ SolverTimeoutSec: &solverTimeout,
+ RetryBaseDelayMs: &retryBase,
+ RetryMaxDelayMs: &retryMax,
+ Solvers: []string{"cloudflare", ""},
+ },
+ }
+
+ errs := ValidateFileConfig(fc)
+ if len(errs) == 0 {
+ t.Fatal("expected autosolver validation errors, got none")
+ }
+
+ joined := ""
+ for _, err := range errs {
+ joined += err.Error() + "\n"
+ }
+
+ for _, want := range []string{
+ "autoSolver.maxAttempts",
+ "autoSolver.solverTimeoutSec",
+ "autoSolver.retryBaseDelayMs/retryMaxDelayMs",
+ "autoSolver.solvers",
+ } {
+ if !strings.Contains(joined, want) {
+ t.Fatalf("expected error containing %q, got:\n%s", want, joined)
+ }
+ }
+}
+
// TestValidateIDPIConfig_EmptyCustomPattern verifies that an empty or
// whitespace-only custom pattern is rejected.
func TestValidateIDPIConfig_EmptyCustomPattern(t *testing.T) {