diff --git a/.env.example b/.env.example index 105a13d72d..f513a1b43e 100644 --- a/.env.example +++ b/.env.example @@ -68,6 +68,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 diff --git a/api/handler_ai_model.go b/api/handler_ai_model.go index c19b672705..1e5e3ff5c7 100644 --- a/api/handler_ai_model.go +++ b/api/handler_ai_model.go @@ -68,6 +68,7 @@ func (s *Server) handleGetModelConfigs(c *gin.Context) { if len(models) == 0 { logger.Infof("⚠️ No AI models in database, returning defaults") defaultModels := []SafeModelConfig{ + {ID: "atlascloud", Name: "Atlas Cloud", Provider: "atlascloud", Enabled: false, HasAPIKey: false}, {ID: "claw402", Name: "Claw402 (Base USDC)", Provider: "claw402", Enabled: false, HasAPIKey: false}, } c.JSON(http.StatusOK, defaultModels) @@ -109,6 +110,7 @@ func (s *Server) handleGetModelConfigs(c *gin.Context) { if len(safeModels) == 0 { logger.Infof("⚠️ No visible AI models in database, returning defaults") defaultModels := []SafeModelConfig{ + {ID: "atlascloud", Name: "Atlas Cloud", Provider: "atlascloud", Enabled: false, HasAPIKey: false}, {ID: "claw402", Name: "Claw402 (Base USDC)", Provider: "claw402", Enabled: false, HasAPIKey: false}, } c.JSON(http.StatusOK, defaultModels) @@ -244,6 +246,7 @@ func (s *Server) handleUpdateModelConfigs(c *gin.Context) { func (s *Server) handleGetSupportedModels(c *gin.Context) { // Return static list of supported AI models with default versions supportedModels := []map[string]interface{}{ + {"id": "atlascloud", "name": "Atlas Cloud", "provider": "atlascloud", "defaultModel": "qwen/qwen3.5-flash"}, {"id": "claw402", "name": "Claw402 (Base USDC)", "provider": "claw402", "defaultModel": "gpt-5.6"}, } 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 1e4b4f06e1..31235d572d 100644 --- a/api/server.go +++ b/api/server.go @@ -297,8 +297,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 0072f68836..09920a62bd 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 f2e18d3431..a654633017 100644 --- a/store/strategy.go +++ b/store/strategy.go @@ -1315,9 +1315,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) @@ -1327,9 +1328,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 d6f5efbe53..d9e7359743 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: '#0B2459', + atlascloud: '#2563EB', zhipu: '#3859F3', } diff --git a/web/src/components/trader/model-constants.ts b/web/src/components/trader/model-constants.ts index 8a9f5a22e7..f70bec238f 100644 --- a/web/src/components/trader/model-constants.ts +++ b/web/src/components/trader/model-constants.ts @@ -26,6 +26,8 @@ export function getModelDisplayName(modelId: string): string { return 'Qwen' case 'claude': return 'Claude' + case 'atlascloud': + return 'Atlas Cloud' default: return modelId.toUpperCase() } @@ -161,6 +163,11 @@ export const CLAW402_MODELS: Claw402Model[] = [ // AI Provider configuration - default models and API links export const AI_PROVIDER_CONFIG: Record = { + 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',