Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(copilot): improved support for AccessToken and Enterprise API #406

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

nathabonfim59
Copy link
Contributor

@nathabonfim59 nathabonfim59 commented Dec 15, 2024

Implements GitHub Copilot authentication with a new HTTP HttpClient, including token handling and support for new models.

Authentication and Configuration Updates:

  • copilot.go: Introduced a new CopilotHTTPClient struct to manage HTTP requests and token handling for Copilot, including methods for retrieving and refreshing tokens. This change also includes defining constants for the Copilot authentication URL, editor version, and user-agent.

  • mods.go: Updated the startCompletionCmd function to use the new CopilotHTTPClient for authentication, replacing the previous method of sending the RefreshToken to the API. This ensures that the token is properly managed and refreshed as needed.

Model Configuration Updates:

  • config_template.yml: Added new model configurations for gpt-4, gpt-3.5-turbo, o1-preview-2024-09-12, o1-mini-2024-09-12, and claude-3.5-sonnet, including their respective aliases and maximum input characters. Updated the existing gpt-4o model configuration to gpt-4o-2024-05-13 with new aliases.

  • copilot.go:

  • Add support for Windows file paths using runtime OS detection [1]
  • Handle new Copilot token format from apps.json [2]
  • Support both legacy and new token storage formats

Future work:

Officially, the only way to that is to use the compiled LSP from the VIM plugin[3, 4, 5], so you can generate the ~/.config/github-copilot folder automatically.

But you can also login direcly like a copilot extension[6] and the vscode CopilotChat ApplicationID.

References:

  1. https://github.com/orgs/community/discussions/38217#discussioncomment-4059872
  2. Copilot chat logged out while autocomplete is logged in zed-industries/zed#21255 (comment)
  3. https://github.com/github/copilot.vim
  4. https://github.com/MinusGix/lapce-copilot/blob/6b244612043157beb0f509b7ba16de0b5e7d95f4/src/main.rs#L218
  5. https://github.com/zed-industries/zed/blob/7e6233d70f329e400e3945ee4307300f3a9df272/crates/copilot/src/copilot.rs#L991
  6. https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow

@nathabonfim59 nathabonfim59 changed the title feat: copilot token retrieval on Windows feat(copilot): improved support for AccessToken and Enterprise API Dec 15, 2024
@caarlos0
Copy link
Member

amazing!

copilot.go Outdated Show resolved Hide resolved
copilot.go Outdated Show resolved Hide resolved
Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

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

just a couple of suggestions, but this looks great, and works well too!

thanks so much!

@nathabonfim59
Copy link
Contributor Author

I really appreciate it!

Suggestions implemented and fixed the linting errors.

Thinking back about what you said, it doesn't really make sense to export those copilot specific constants either.

I left just the CopilotAccessToken as it could be used by a third party to check if the token is expired or other metadata.

@nathabonfim59
Copy link
Contributor Author

BTW, yesterday, GitHub announced a new "Free Tier" with limited access (50 chat requests/month).

My guess is that they are using CopilotAccessToken.ErrorDetails.Message to tell if someone has used up all chat messages for the month. In this case, no changes would be necessary.

I don't have a GitHub account without a Copilot subscription, but if someone could verify this, please let me know.

@caarlos0 caarlos0 added the enhancement New feature or request label Dec 20, 2024
@caarlos0 caarlos0 merged commit f33015d into charmbracelet:main Jan 6, 2025
7 checks passed
@caarlos0
Copy link
Member

caarlos0 commented Jan 6, 2025

Thanks for the PR ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants