From 1464cedeff0ef86982504fe87d7b0e3d13b9e775 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 15 Apr 2026 18:15:32 +0800 Subject: [PATCH] feat(api): enhance strategy handling by integrating claw402 wallet key validation Added validation for the claw402 model's wallet key during strategy test runs. If the selected AI model is claw402, the server now checks for a valid wallet key and returns appropriate error messages if it's missing or if the model fails to load. This ensures better error handling and user feedback when working with AI models. --- api/strategy.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/api/strategy.go b/api/strategy.go index 1985c384..07e20987 100644 --- a/api/strategy.go +++ b/api/strategy.go @@ -516,8 +516,31 @@ func (s *Server) handleStrategyTestRun(c *gin.Context) { req.PromptVariant = "balanced" } + claw402WalletKey := "" + if req.AIModelID != "" { + model, err := s.store.AIModel().Get(userID, req.AIModelID) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Failed to load selected AI model", + "ai_response": "", + }) + return + } + + if model.Provider == "claw402" { + claw402WalletKey = string(model.APIKey) + if claw402WalletKey == "" { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Selected claw402 model is missing wallet private key", + "ai_response": "", + }) + return + } + } + } + // Create strategy engine to build prompt - engine := kernel.NewStrategyEngine(&req.Config) + engine := kernel.NewStrategyEngine(&req.Config, claw402WalletKey) // Get candidate coins candidates, err := engine.GetCandidateCoins()