feat: add client availability tracking and error handling improvements

- Introduced `IsAvailable` and `SetUnavailable` methods to clients for availability tracking.
- Integrated availability checks in client selection logic to skip unavailable clients.
- Enhanced error handling by marking clients unavailable on specific error codes (e.g., 401, 402).
- Removed redundant quota verification logs in client reordering logic.
This commit is contained in:
Luis Pater
2025-09-19 01:53:38 +08:00
parent 9ec8478b41
commit df66046b14
15 changed files with 183 additions and 21 deletions

View File

@@ -96,6 +96,7 @@ func NewGeminiWebClient(cfg *config.Config, ts *gemini.GeminiWebTokenStorage, to
cfg: cfg,
tokenStorage: ts,
modelQuotaExceeded: make(map[string]*time.Time),
isAvailable: true,
},
tokenFilePath: tokenFilePath,
convStore: make(map[string][]string),
@@ -1072,3 +1073,13 @@ func (c *GeminiWebClient) storeConversationJSON(model string, history []geminiWe
c.convMutex.Unlock()
_ = geminiWeb.SaveConvData(geminiWeb.ConvDataPath(c.tokenFilePath), items, index)
}
// IsAvailable returns true if the client is available for use.
func (c *GeminiWebClient) IsAvailable() bool {
return c.isAvailable
}
// SetUnavailable sets the client to unavailable.
func (c *GeminiWebClient) SetUnavailable() {
c.isAvailable = false
}