mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-06-06 05:51:19 +08:00
Google discontinued gemini-3-pro-preview on 2026-03-26 and directs all callers to gemini-3.1-pro / gemini-3.1-pro-preview. Users on their own API key were getting errors from the native Gemini endpoint because the provider default pointed at the retired ID. Claw402 was unaffected because its route map already used gemini-3.1-pro. Align both the native provider default and the handler's preset list with gemini-3.1-pro so every code path sends a live model ID. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nofx/mcp"
|
|
)
|
|
|
|
const (
|
|
DefaultGeminiBaseURL = "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
DefaultGeminiModel = "gemini-3.1-pro"
|
|
)
|
|
|
|
func init() {
|
|
mcp.RegisterProvider(mcp.ProviderGemini, func(opts ...mcp.ClientOption) mcp.AIClient {
|
|
return NewGeminiClientWithOptions(opts...)
|
|
})
|
|
}
|
|
|
|
type GeminiClient struct {
|
|
*mcp.Client
|
|
}
|
|
|
|
func (c *GeminiClient) BaseClient() *mcp.Client { return c.Client }
|
|
|
|
// NewGeminiClient creates Gemini client (backward compatible)
|
|
func NewGeminiClient() mcp.AIClient {
|
|
return NewGeminiClientWithOptions()
|
|
}
|
|
|
|
// NewGeminiClientWithOptions creates Gemini client (supports options pattern)
|
|
func NewGeminiClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
|
|
geminiOpts := []mcp.ClientOption{
|
|
mcp.WithProvider(mcp.ProviderGemini),
|
|
mcp.WithModel(DefaultGeminiModel),
|
|
mcp.WithBaseURL(DefaultGeminiBaseURL),
|
|
}
|
|
|
|
allOpts := append(geminiOpts, opts...)
|
|
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
|
|
|
|
geminiClient := &GeminiClient{
|
|
Client: baseClient,
|
|
}
|
|
|
|
baseClient.Hooks = geminiClient
|
|
return geminiClient
|
|
}
|
|
|
|
func (c *GeminiClient) SetAPIKey(apiKey string, customURL string, customModel string) {
|
|
c.APIKey = apiKey
|
|
|
|
if len(apiKey) > 8 {
|
|
c.Log.Infof("🔧 [MCP] Gemini API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:])
|
|
}
|
|
if customURL != "" {
|
|
c.BaseURL = customURL
|
|
c.Log.Infof("🔧 [MCP] Gemini using custom BaseURL: %s", customURL)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] Gemini using default BaseURL: %s", c.BaseURL)
|
|
}
|
|
if customModel != "" {
|
|
c.Model = customModel
|
|
c.Log.Infof("🔧 [MCP] Gemini using custom Model: %s", customModel)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] Gemini using default Model: %s", c.Model)
|
|
}
|
|
}
|
|
|
|
// Gemini OpenAI-compatible API uses standard Bearer auth
|
|
func (c *GeminiClient) SetAuthHeader(reqHeaders http.Header) {
|
|
c.Client.SetAuthHeader(reqHeaders)
|
|
}
|