refactor(executor): improve concurrency and code quality in GitHub Copilot executor

- Replace concurrent-unsafe metadata caching with thread-safe sync.RWMutex-protected map
- Extract magic numbers and hardcoded header values to named constants
- Replace verbose status code checks with isHTTPSuccess() helper
- Simplify normalizeModel() to no-op with explanatory comment (models already canonical)
- Remove redundant metadata manipulation in token caching
- Improve code clarity and performance with proper cache management
This commit is contained in:
Ernesto Martínez
2025-11-28 08:33:51 +01:00
parent 2c296e9cb1
commit 7515090cb6
2 changed files with 59 additions and 56 deletions

View File

@@ -36,9 +36,6 @@ func (a GitHubCopilotAuthenticator) Login(ctx context.Context, cfg *config.Confi
if cfg == nil {
return nil, fmt.Errorf("cliproxy auth: configuration is required")
}
if ctx == nil {
ctx = context.Background()
}
if opts == nil {
opts = &LoginOptions{}
}
@@ -85,7 +82,7 @@ func (a GitHubCopilotAuthenticator) Login(ctx context.Context, cfg *config.Confi
// Create the token storage
tokenStorage := authSvc.CreateTokenStorage(authBundle)
// Build metadata
// Build metadata with token information for the executor
metadata := map[string]any{
"type": "github-copilot",
"username": authBundle.Username,
@@ -93,7 +90,6 @@ func (a GitHubCopilotAuthenticator) Login(ctx context.Context, cfg *config.Confi
"token_type": authBundle.TokenData.TokenType,
"scope": authBundle.TokenData.Scope,
"timestamp": time.Now().UnixMilli(),
"api_endpoint": copilot.BuildChatCompletionURL(),
}
if apiToken.ExpiresAt > 0 {