From 0d2e220a54d70271bd01e38df00d95f519ef1feb Mon Sep 17 00:00:00 2001 From: binyangzhu000-sudo <224954946+binyangzhu000-sudo@users.noreply.github.com> Date: Mon, 20 Jul 2026 18:32:36 +0800 Subject: [PATCH] Add Atlas Cloud AI provider --- .env.example | 6 +- api/handler_ai_model.go | 3 + api/handler_ai_model_test.go | 47 ++++++++++++++ api/server.go | 4 +- mcp/options.go | 14 +++++ mcp/options_test.go | 21 +++++++ mcp/provider/atlascloud.go | 65 ++++++++++++++++++++ mcp/provider/atlascloud_test.go | 42 +++++++++++++ mcp/provider/options_test.go | 36 +++++++++++ mcp/providers.go | 11 +++- store/ai_model.go | 11 ++-- store/ai_model_atlascloud_test.go | 18 ++++++ store/strategy.go | 14 +++-- store/strategy_token_test.go | 3 + web/src/components/common/ModelIcons.tsx | 1 + web/src/components/trader/model-constants.ts | 7 +++ 16 files changed, 287 insertions(+), 16 deletions(-) create mode 100644 api/handler_ai_model_test.go create mode 100644 mcp/provider/atlascloud.go create mode 100644 mcp/provider/atlascloud_test.go create mode 100644 store/ai_model_atlascloud_test.go diff --git a/.env.example b/.env.example index dc2884e10d..ac1d77104f 100644 --- a/.env.example +++ b/.env.example @@ -52,6 +52,10 @@ TRANSPORT_ENCRYPTION=false # Optional: External Services # =========================================== +# Optional server-side fallback for the Atlas Cloud AI model provider. +# Users can also configure API keys from the web app settings. +ATLASCLOUD_API_KEY= + DB_TYPE=postgres DB_HOST=10. DB_PORT=5432 @@ -63,4 +67,4 @@ DB_SSLMODE=disable # Database configuration - SQLite (default) DB_TYPE=sqlite -DB_PATH=data/data.db \ No newline at end of file +DB_PATH=data/data.db diff --git a/api/handler_ai_model.go b/api/handler_ai_model.go index a114520df8..8d08a13383 100644 --- a/api/handler_ai_model.go +++ b/api/handler_ai_model.go @@ -76,6 +76,7 @@ func (s *Server) handleGetModelConfigs(c *gin.Context) { {ID: "grok", Name: "Grok AI", Provider: "grok", Enabled: false, HasAPIKey: false}, {ID: "kimi", Name: "Kimi AI", Provider: "kimi", Enabled: false, HasAPIKey: false}, {ID: "minimax", Name: "MiniMax AI", Provider: "minimax", Enabled: false, HasAPIKey: false}, + {ID: "atlascloud", Name: "Atlas Cloud", Provider: "atlascloud", Enabled: false, HasAPIKey: false}, } c.JSON(http.StatusOK, defaultModels) return @@ -124,6 +125,7 @@ func (s *Server) handleGetModelConfigs(c *gin.Context) { {ID: "grok", Name: "Grok AI", Provider: "grok", Enabled: false, HasAPIKey: false}, {ID: "kimi", Name: "Kimi AI", Provider: "kimi", Enabled: false, HasAPIKey: false}, {ID: "minimax", Name: "MiniMax AI", Provider: "minimax", Enabled: false, HasAPIKey: false}, + {ID: "atlascloud", Name: "Atlas Cloud", Provider: "atlascloud", Enabled: false, HasAPIKey: false}, } c.JSON(http.StatusOK, defaultModels) return @@ -247,6 +249,7 @@ func (s *Server) handleGetSupportedModels(c *gin.Context) { {"id": "grok", "name": "Grok (xAI)", "provider": "grok", "defaultModel": "grok-3-latest"}, {"id": "kimi", "name": "Kimi (Moonshot)", "provider": "kimi", "defaultModel": "moonshot-v1-auto"}, {"id": "minimax", "name": "MiniMax", "provider": "minimax", "defaultModel": "MiniMax-M2.7"}, + {"id": "atlascloud", "name": "Atlas Cloud", "provider": "atlascloud", "defaultModel": "qwen/qwen3.5-flash"}, {"id": "blockrun-base", "name": "BlockRun (Base Wallet)", "provider": "blockrun-base", "defaultModel": "auto"}, {"id": "blockrun-sol", "name": "BlockRun (Solana Wallet)", "provider": "blockrun-sol", "defaultModel": "auto"}, {"id": "claw402", "name": "Claw402 (Base USDC)", "provider": "claw402", "defaultModel": "deepseek-v4-flash"}, diff --git a/api/handler_ai_model_test.go b/api/handler_ai_model_test.go new file mode 100644 index 0000000000..1e3dc257b1 --- /dev/null +++ b/api/handler_ai_model_test.go @@ -0,0 +1,47 @@ +package api + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" +) + +func TestHandleGetSupportedModelsIncludesAtlasCloud(t *testing.T) { + gin.SetMode(gin.TestMode) + + recorder := httptest.NewRecorder() + ctx, _ := gin.CreateTestContext(recorder) + + server := &Server{} + server.handleGetSupportedModels(ctx) + + if recorder.Code != http.StatusOK { + t.Fatalf("status = %d, want %d", recorder.Code, http.StatusOK) + } + + var models []map[string]string + if err := json.Unmarshal(recorder.Body.Bytes(), &models); err != nil { + t.Fatalf("decode supported models: %v", err) + } + + for _, model := range models { + if model["id"] != "atlascloud" { + continue + } + if model["name"] != "Atlas Cloud" { + t.Fatalf("Atlas Cloud name = %q", model["name"]) + } + if model["provider"] != "atlascloud" { + t.Fatalf("Atlas Cloud provider = %q", model["provider"]) + } + if model["defaultModel"] != "qwen/qwen3.5-flash" { + t.Fatalf("Atlas Cloud defaultModel = %q", model["defaultModel"]) + } + return + } + + t.Fatal("Atlas Cloud model was not included in supported models") +} diff --git a/api/server.go b/api/server.go index 7d72915a88..051adb2027 100644 --- a/api/server.go +++ b/api/server.go @@ -280,8 +280,8 @@ CRITICAL: The "id" field (e.g. "abc123_deepseek") is what you must use for ai_mo s.handleGetModelConfigs) s.routeWithSchema(protected, "PUT", "/models", "Configure an AI model provider", `Body: {"models":{"":{"enabled":,"api_key":"","custom_api_url":"","custom_model_name":""}}} -model_id values: "openai","deepseek","qwen","kimi","grok","gemini","claude" -Defaults when custom fields empty: openai→api.openai.com/v1, deepseek→api.deepseek.com, qwen→dashscope.aliyuncs.com/compatible-mode/v1, kimi→api.moonshot.ai/v1, grok→api.x.ai/v1, gemini→generativelanguage.googleapis.com/v1beta/openai, claude→api.anthropic.com/v1`, +model_id values: "openai","deepseek","qwen","kimi","grok","gemini","claude","atlascloud" +Defaults when custom fields empty: openai→api.openai.com/v1, deepseek→api.deepseek.com, qwen→dashscope.aliyuncs.com/compatible-mode/v1, kimi→api.moonshot.ai/v1, grok→api.x.ai/v1, gemini→generativelanguage.googleapis.com/v1beta/openai, claude→api.anthropic.com/v1, atlascloud→api.atlascloud.ai/v1`, s.handleUpdateModelConfigs) // Exchange configuration diff --git a/mcp/options.go b/mcp/options.go index 335cec2894..f0af97a5e0 100644 --- a/mcp/options.go +++ b/mcp/options.go @@ -191,3 +191,17 @@ func WithMiniMaxConfig(apiKey string) ClientOption { c.Model = DefaultMiniMaxModel } } + +// WithAtlasCloudConfig sets Atlas Cloud OpenAI-compatible configuration. +// +// Usage example: +// +// client := mcp.NewClient(mcp.WithAtlasCloudConfig("sk-xxx")) +func WithAtlasCloudConfig(apiKey string) ClientOption { + return func(c *Config) { + c.Provider = ProviderAtlasCloud + c.APIKey = apiKey + c.BaseURL = DefaultAtlasCloudBaseURL + c.Model = DefaultAtlasCloudModel + } +} diff --git a/mcp/options_test.go b/mcp/options_test.go index 4bbe4719a9..8d8ea7248b 100644 --- a/mcp/options_test.go +++ b/mcp/options_test.go @@ -161,6 +161,27 @@ func TestWithQwenConfig(t *testing.T) { } } +func TestWithAtlasCloudConfig(t *testing.T) { + cfg := DefaultConfig() + WithAtlasCloudConfig("sk-atlas-key")(cfg) + + if cfg.Provider != ProviderAtlasCloud { + t.Errorf("Provider should be '%s', got '%s'", ProviderAtlasCloud, cfg.Provider) + } + + if cfg.APIKey != "sk-atlas-key" { + t.Errorf("APIKey should be 'sk-atlas-key', got '%s'", cfg.APIKey) + } + + if cfg.BaseURL != DefaultAtlasCloudBaseURL { + t.Errorf("BaseURL should be '%s', got '%s'", DefaultAtlasCloudBaseURL, cfg.BaseURL) + } + + if cfg.Model != DefaultAtlasCloudModel { + t.Errorf("Model should be '%s', got '%s'", DefaultAtlasCloudModel, cfg.Model) + } +} + // ============================================================ // Test Options Combination // ============================================================ diff --git a/mcp/provider/atlascloud.go b/mcp/provider/atlascloud.go new file mode 100644 index 0000000000..37c0a8fa96 --- /dev/null +++ b/mcp/provider/atlascloud.go @@ -0,0 +1,65 @@ +package provider + +import ( + "net/http" + + "nofx/mcp" +) + +func init() { + mcp.RegisterProvider(mcp.ProviderAtlasCloud, func(opts ...mcp.ClientOption) mcp.AIClient { + return NewAtlasCloudClientWithOptions(opts...) + }) +} + +type AtlasCloudClient struct { + *mcp.Client +} + +func (c *AtlasCloudClient) BaseClient() *mcp.Client { return c.Client } + +func NewAtlasCloudClient() mcp.AIClient { + return NewAtlasCloudClientWithOptions() +} + +func NewAtlasCloudClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient { + atlasOpts := []mcp.ClientOption{ + mcp.WithProvider(mcp.ProviderAtlasCloud), + mcp.WithModel(mcp.DefaultAtlasCloudModel), + mcp.WithBaseURL(mcp.DefaultAtlasCloudBaseURL), + } + + allOpts := append(atlasOpts, opts...) + baseClient := mcp.NewClient(allOpts...).(*mcp.Client) + + atlasClient := &AtlasCloudClient{ + Client: baseClient, + } + + baseClient.Hooks = atlasClient + return atlasClient +} + +func (c *AtlasCloudClient) SetAPIKey(apiKey string, customURL string, customModel string) { + c.APIKey = apiKey + + if len(apiKey) > 8 { + c.Log.Infof("🔧 [MCP] Atlas Cloud API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:]) + } + if customURL != "" { + c.BaseURL = customURL + c.Log.Infof("🔧 [MCP] Atlas Cloud using custom BaseURL: %s", customURL) + } else { + c.Log.Infof("🔧 [MCP] Atlas Cloud using default BaseURL: %s", c.BaseURL) + } + if customModel != "" { + c.Model = customModel + c.Log.Infof("🔧 [MCP] Atlas Cloud using custom Model: %s", customModel) + } else { + c.Log.Infof("🔧 [MCP] Atlas Cloud using default Model: %s", c.Model) + } +} + +func (c *AtlasCloudClient) SetAuthHeader(reqHeaders http.Header) { + c.Client.SetAuthHeader(reqHeaders) +} diff --git a/mcp/provider/atlascloud_test.go b/mcp/provider/atlascloud_test.go new file mode 100644 index 0000000000..3ef7606d5a --- /dev/null +++ b/mcp/provider/atlascloud_test.go @@ -0,0 +1,42 @@ +package provider + +import ( + "testing" + + "nofx/mcp" +) + +func TestAtlasCloudClientDefaults(t *testing.T) { + client := NewAtlasCloudClientWithOptions(mcp.WithAPIKey("sk-atlas-test")) + atlasClient := client.(*AtlasCloudClient) + + if atlasClient.Provider != mcp.ProviderAtlasCloud { + t.Fatalf("Provider = %q, want %q", atlasClient.Provider, mcp.ProviderAtlasCloud) + } + if atlasClient.BaseURL != mcp.DefaultAtlasCloudBaseURL { + t.Fatalf("BaseURL = %q, want %q", atlasClient.BaseURL, mcp.DefaultAtlasCloudBaseURL) + } + if atlasClient.Model != mcp.DefaultAtlasCloudModel { + t.Fatalf("Model = %q, want %q", atlasClient.Model, mcp.DefaultAtlasCloudModel) + } + if atlasClient.APIKey != "sk-atlas-test" { + t.Fatalf("APIKey = %q, want sk-atlas-test", atlasClient.APIKey) + } +} + +func TestAtlasCloudClientSetAPIKeyOverrides(t *testing.T) { + client := NewAtlasCloudClientWithOptions() + atlasClient := client.(*AtlasCloudClient) + + atlasClient.SetAPIKey("sk-atlas-test", "https://proxy.example.com/v1", "deepseek-ai/deepseek-v4-pro") + + if atlasClient.APIKey != "sk-atlas-test" { + t.Fatalf("APIKey = %q, want sk-atlas-test", atlasClient.APIKey) + } + if atlasClient.BaseURL != "https://proxy.example.com/v1" { + t.Fatalf("BaseURL = %q, want custom proxy URL", atlasClient.BaseURL) + } + if atlasClient.Model != "deepseek-ai/deepseek-v4-pro" { + t.Fatalf("Model = %q, want deepseek-ai/deepseek-v4-pro", atlasClient.Model) + } +} diff --git a/mcp/provider/options_test.go b/mcp/provider/options_test.go index cb03f9cfc9..dcea911469 100644 --- a/mcp/provider/options_test.go +++ b/mcp/provider/options_test.go @@ -81,3 +81,39 @@ func TestOptionsWithQwenClient(t *testing.T) { t.Error("MaxTokens should be 6000") } } + +func TestOptionsWithAtlasCloudClient(t *testing.T) { + logger := mcp.NewNoopLogger() + + client := NewAtlasCloudClientWithOptions( + mcp.WithAPIKey("sk-atlas-key"), + mcp.WithLogger(logger), + mcp.WithMaxTokens(7000), + ) + + atlasClient := client.(*AtlasCloudClient) + + if atlasClient.Provider != mcp.ProviderAtlasCloud { + t.Error("Provider should be Atlas Cloud") + } + + if atlasClient.BaseURL != mcp.DefaultAtlasCloudBaseURL { + t.Error("BaseURL should be Atlas Cloud default") + } + + if atlasClient.Model != mcp.DefaultAtlasCloudModel { + t.Error("Model should be Atlas Cloud default") + } + + if atlasClient.APIKey != "sk-atlas-key" { + t.Error("APIKey should be set from options") + } + + if atlasClient.Log != logger { + t.Error("Log should be set from options") + } + + if atlasClient.MaxTokens != 7000 { + t.Error("MaxTokens should be 7000") + } +} diff --git a/mcp/providers.go b/mcp/providers.go index 29018b3c6a..6f0b9a9861 100644 --- a/mcp/providers.go +++ b/mcp/providers.go @@ -9,9 +9,10 @@ const ( ProviderClaude = "claude" ProviderQwen = "qwen" ProviderGemini = "gemini" - ProviderGrok = "grok" - ProviderKimi = "kimi" - ProviderMiniMax = "minimax" + ProviderGrok = "grok" + ProviderKimi = "kimi" + ProviderMiniMax = "minimax" + ProviderAtlasCloud = "atlascloud" ProviderClaw402 = "claw402" @@ -26,4 +27,8 @@ const ( // Default MiniMax configuration (used by WithMiniMaxConfig convenience option) DefaultMiniMaxBaseURL = "https://api.minimax.io/v1" DefaultMiniMaxModel = "MiniMax-M2.7" + + // Default Atlas Cloud configuration (OpenAI-compatible) + DefaultAtlasCloudBaseURL = "https://api.atlascloud.ai/v1" + DefaultAtlasCloudModel = "qwen/qwen3.5-flash" ) diff --git a/store/ai_model.go b/store/ai_model.go index 15270a4748..9b90dd7035 100644 --- a/store/ai_model.go +++ b/store/ai_model.go @@ -188,10 +188,11 @@ func hasUsableAPIKey(model AIModel) bool { "openai": "OPENAI_API_KEY", "claude": "ANTHROPIC_API_KEY", "gemini": "GEMINI_API_KEY", - "grok": "XAI_API_KEY", - "kimi": "MOONSHOT_API_KEY", - "minimax": "MINIMAX_API_KEY", - "qwen": "DASHSCOPE_API_KEY", + "grok": "XAI_API_KEY", + "kimi": "MOONSHOT_API_KEY", + "minimax": "MINIMAX_API_KEY", + "qwen": "DASHSCOPE_API_KEY", + "atlascloud": "ATLASCLOUD_API_KEY", } envKey := envKeyByProvider[strings.ToLower(strings.TrimSpace(model.Provider))] return envKey != "" && strings.TrimSpace(os.Getenv(envKey)) != "" @@ -267,6 +268,8 @@ func (s *AIModelStore) UpdateWithName(userID, id, name string, enabled bool, api defaultName = "DeepSeek AI" } else if provider == "qwen" { defaultName = "Qwen AI" + } else if provider == "atlascloud" { + defaultName = "Atlas Cloud" } else { defaultName = provider + " AI" } diff --git a/store/ai_model_atlascloud_test.go b/store/ai_model_atlascloud_test.go new file mode 100644 index 0000000000..e111e6bcf9 --- /dev/null +++ b/store/ai_model_atlascloud_test.go @@ -0,0 +1,18 @@ +package store + +import ( + "testing" +) + +func TestHasUsableAPIKeyUsesAtlasCloudEnv(t *testing.T) { + t.Setenv("ATLASCLOUD_API_KEY", "sk-atlas-test") + + model := AIModel{ + Provider: "atlascloud", + Enabled: true, + } + + if !hasUsableAPIKey(model) { + t.Fatal("expected ATLASCLOUD_API_KEY to make Atlas Cloud model usable") + } +} diff --git a/store/strategy.go b/store/strategy.go index fe790aedc5..6a513c5dbd 100644 --- a/store/strategy.go +++ b/store/strategy.go @@ -1266,9 +1266,10 @@ const ( contextLimitClaude = 200_000 // 200K contextLimitQwen = 131_072 // 128K contextLimitGemini = 1_000_000 // 1M - contextLimitGrok = 131_072 // 128K - contextLimitKimi = 131_072 // 128K - contextLimitMinimax = 1_000_000 // 1M + contextLimitGrok = 131_072 // 128K + contextLimitKimi = 131_072 // 128K + contextLimitMinimax = 1_000_000 // 1M + contextLimitAtlasCloud = 131_072 // 128K ) // ModelContextLimits maps provider names to their context window sizes (in tokens) @@ -1278,9 +1279,10 @@ var ModelContextLimits = map[string]int{ "claude": contextLimitClaude, "qwen": contextLimitQwen, "gemini": contextLimitGemini, - "grok": contextLimitGrok, - "kimi": contextLimitKimi, - "minimax": contextLimitMinimax, + "grok": contextLimitGrok, + "kimi": contextLimitKimi, + "minimax": contextLimitMinimax, + "atlascloud": contextLimitAtlasCloud, } // GetContextLimit returns the context limit for a given provider diff --git a/store/strategy_token_test.go b/store/strategy_token_test.go index d9d0997a1e..367a7ec481 100644 --- a/store/strategy_token_test.go +++ b/store/strategy_token_test.go @@ -88,6 +88,9 @@ func TestGetContextLimit(t *testing.T) { if got := GetContextLimit("deepseek"); got != 131072 { t.Errorf("deepseek limit = %d, want 131072", got) } + if got := GetContextLimit("atlascloud"); got != 131072 { + t.Errorf("atlascloud limit = %d, want 131072", got) + } if got := GetContextLimit("unknown_provider"); got != 131072 { t.Errorf("unknown provider should return default 131072, got %d", got) } diff --git a/web/src/components/common/ModelIcons.tsx b/web/src/components/common/ModelIcons.tsx index 6e1d0000f0..92362b2ba3 100644 --- a/web/src/components/common/ModelIcons.tsx +++ b/web/src/components/common/ModelIcons.tsx @@ -15,6 +15,7 @@ const MODEL_COLORS: Record = { openai: '#10A37F', minimax: '#E45735', claw402: '#7C3AED', + atlascloud: '#2563EB', } // Returns the icon for an AI model diff --git a/web/src/components/trader/model-constants.ts b/web/src/components/trader/model-constants.ts index 9e0978e5e2..0524689c9c 100644 --- a/web/src/components/trader/model-constants.ts +++ b/web/src/components/trader/model-constants.ts @@ -31,6 +31,8 @@ export function getModelDisplayName(modelId: string): string { return 'Qwen' case 'claude': return 'Claude' + case 'atlascloud': + return 'Atlas Cloud' default: return modelId.toUpperCase() } @@ -129,6 +131,11 @@ export const AI_PROVIDER_CONFIG: Record = { apiUrl: 'https://platform.minimax.io', apiName: 'MiniMax', }, + atlascloud: { + defaultModel: 'qwen/qwen3.5-flash', + apiUrl: 'https://www.atlascloud.ai/console/api-keys', + apiName: 'Atlas Cloud', + }, claw402: { defaultModel: DEFAULT_CLAW402_MODEL, apiUrl: 'https://claw402.ai',