Skip to content

feat(auth): add CodeBuddy-CN browser OAuth authentication support#450

Open
lwiles692 wants to merge 3 commits intorouter-for-me:mainfrom
lwiles692:feature/add-codebuddy-support
Open

feat(auth): add CodeBuddy-CN browser OAuth authentication support#450
lwiles692 wants to merge 3 commits intorouter-for-me:mainfrom
lwiles692:feature/add-codebuddy-support

Conversation

@lwiles692
Copy link

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces full support for CodeBuddy-CN, enabling users to authenticate via a browser-based OAuth flow. It integrates CodeBuddy's AI models and API interactions into the system, providing a seamless experience for accessing CodeBuddy services. The changes encompass new authentication logic, API executors, model definitions, and improved error feedback, expanding the platform's capabilities to include Tencent's CodeBuddy offerings.

Highlights

  • CodeBuddy-CN Browser OAuth Support: Added comprehensive support for CodeBuddy-CN authentication using the browser OAuth flow, allowing users to log in and manage their CodeBuddy sessions.
  • New CodeBuddy API Executor: Introduced a dedicated executor for CodeBuddy API requests, handling both non-streaming and streaming interactions, along with token refresh mechanisms.
  • CodeBuddy Model Integration: Integrated CodeBuddy's available models (e.g., GLM-5.0, MiniMax M2.5, Kimi K2.5) into the model registry, making them discoverable and usable within the system.
  • Enhanced Error Handling: Implemented specific error types and user-friendly messages for CodeBuddy authentication failures, improving the user experience during login processes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces support for CodeBuddy-CN browser OAuth authentication. The changes are well-structured, adding new files for authentication logic, error handling, token storage, and integrating them into the existing command, registry, and executor systems. The new code includes appropriate error handling and defensive programming practices. However, there are several instances of hardcoded values for URLs, domains, user agents, and API paths that could be made configurable or derived from application build information for better maintainability. Additionally, some error wrapping uses %v instead of %w, and a few errors are ignored, which could mask underlying issues. A Chinese comment was also found and should be translated for consistency.

)

const (
BaseURL = "https://copilot.tencent.com"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This BaseURL is hardcoded. It would be more flexible and maintainable to make this configurable, especially if there are different environments (e.g., staging, production) or regional endpoints for CodeBuddy.


const (
BaseURL = "https://copilot.tencent.com"
DefaultDomain = "www.codebuddy.cn"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to BaseURL, DefaultDomain is hardcoded. Consider making this configurable to support different CodeBuddy domains if needed in the future.

const (
BaseURL = "https://copilot.tencent.com"
DefaultDomain = "www.codebuddy.cn"
UserAgent = "CLI/2.63.2 CodeBuddy/2.63.2"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The UserAgent string is hardcoded with a specific version. If the CLI version changes, this constant will need manual updates. It would be more robust to derive this from the application's build information or a central version constant.

codeBuddyStatePath = "/v2/plugin/auth/state"
codeBuddyTokenPath = "/v2/plugin/auth/token"
codeBuddyRefreshPath = "/v2/plugin/auth/token/refresh"
pollInterval = 5 * time.Second

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pollInterval is a hardcoded duration. Making this configurable would allow for fine-tuning the polling behavior without code changes, which can be useful for different network conditions or API rate limits.

codeBuddyTokenPath = "/v2/plugin/auth/token"
codeBuddyRefreshPath = "/v2/plugin/auth/token/refresh"
pollInterval = 5 * time.Second
maxPollDuration = 5 * time.Minute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The maxPollDuration is hardcoded. This duration might need adjustment based on user experience expectations or server-side timeouts. Consider making it configurable.

return nil, fmt.Errorf("codebuddy: empty data in refresh response")
}

newUserID, _ := a.DecodeUserID(result.Data.AccessToken)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned by a.DecodeUserID is ignored here. Consider logging this error or handling it more explicitly, as a failure to decode the user ID from the access token could indicate a malformed token or an unexpected API response.

newUserID, err := a.DecodeUserID(result.Data.AccessToken)
if err != nil {
	log.Debugf("codebuddy refresh: failed to decode user ID from access token: %v", err)
}


const (
codeBuddyChatPath = "/v2/chat/completions"
codeBuddyAuthType = "codebuddy"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The codeBuddyChatPath is a hardcoded API path. If the API version or path changes, this constant will need to be updated. Consider making this configurable if there's a possibility of variation.

}()

recordAPIResponseMetadata(ctx, e.cfg, httpResp.StatusCode, httpResp.Header.Clone())
if !isHTTPSuccess(httpResp.StatusCode) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned by io.ReadAll(httpResp.Body) is ignored here. While the subsequent if err != nil block handles a later io.ReadAll error, it's best practice to check the error from this specific io.ReadAll call explicitly to ensure all potential errors are caught.

b, errRead := io.ReadAll(httpResp.Body)
if errRead != nil {
	log.Debugf("codebuddy executor: failed to read error response body: %v", errRead)
	err = fmt.Errorf("codebuddy executor: failed to read error response body: %w", errRead)
	return resp, err
}

}()

scanner := bufio.NewScanner(httpResp.Body)
scanner.Buffer(nil, maxScannerBufferSize)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

maxScannerBufferSize is used here but is not defined within this file or explicitly imported from a package. Please ensure it's correctly defined or imported to avoid potential compilation or runtime issues.

Comment on lines +332 to +342
req.Header.Set("Authorization", "Bearer "+accessToken)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", codebuddy.UserAgent)
req.Header.Set("X-User-Id", userID)
req.Header.Set("X-Domain", domain)
req.Header.Set("X-Product", "SaaS")
req.Header.Set("X-IDE-Type", "CLI")
req.Header.Set("X-IDE-Name", "CLI")
req.Header.Set("X-IDE-Version", "2.63.2")
req.Header.Set("X-Requested-With", "XMLHttpRequest")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Several headers like X-IDE-Type, X-IDE-Name, X-IDE-Version, and X-Product are hardcoded. Similar to the UserAgent in codebuddy_auth.go, these values could ideally be derived from application build information or configuration to improve maintainability and ensure they are always up-to-date with the CLI's version.

lwiles692 and others added 2 commits March 19, 2026 09:46
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant