Skip to content

feat: Initial implementation of GitHub Copilot Proxy#1

Merged
BjornMelin merged 2 commits intomainfrom
dev
Mar 24, 2025
Merged

feat: Initial implementation of GitHub Copilot Proxy#1
BjornMelin merged 2 commits intomainfrom
dev

Conversation

@BjornMelin
Copy link
Copy Markdown
Owner

@BjornMelin BjornMelin commented Mar 24, 2025

GitHub Copilot Proxy - Initial Implementation

This pull request contains the initial implementation of the GitHub Copilot Proxy server. The project provides an OpenAI-compatible API endpoint that allows Cursor IDE to use GitHub Copilot's AI services instead of its native capabilities.

Features Implemented

  • OAuth Device Flow Authentication: Secure authentication with GitHub using the OAuth device flow
  • OpenAI-Compatible API: Implementation of /v1/models and /v1/chat/completions endpoints
  • Token Management: Automatic token refresh and validation
  • Streaming Support: Real-time streaming responses for completions
  • Rate Limiting: Configurable request and token-based rate limiting
  • Usage Monitoring: Tracking and visualization of usage metrics
  • Web Interface: Authentication UI and usage dashboard

Technical Stack

  • Backend: Node.js with TypeScript and Express.js
  • Authentication: GitHub OAuth device flow via @octokit/auth-oauth-device
  • Streaming: Server-Sent Events (SSE) via @microsoft/fetch-event-source
  • Configuration: Environment variables with Zod validation
  • Logging: Winston logger

Project Structure

The project follows a modular architecture:

  • src/config - Configuration management
  • src/middleware - Express middleware (rate limiter, error handler)
  • src/public - Web interface files
  • src/routes - Express route handlers
  • src/services - Business logic
  • src/types - TypeScript definitions
  • src/utils - Utility functions

Security Considerations

  • Tokens are stored in memory only, not persisted
  • No sensitive data is logged
  • Rate limiting is implemented to prevent abuse
  • All routes requiring authentication are protected

Testing

  • Unit tests for core components
  • Manual testing of authentication flow and API endpoints
  • Environment variable validation for configuration

Future Enhancements

  • Additional authentication methods
  • Enhanced usage analytics
  • Support for more OpenAI-compatible endpoints
  • Persistent token storage option for production

Summary by Sourcery

Implement the initial version of the GitHub Copilot Proxy, which provides an OpenAI-compatible API endpoint that allows Cursor IDE to use GitHub Copilot's AI services. This includes features such as OAuth device flow authentication, token management, streaming support, rate limiting, usage monitoring, and a web interface.

New Features:

  • Introduce OAuth Device Flow Authentication for secure authentication with GitHub.
  • Implement OpenAI-Compatible API endpoints (/v1/models and /v1/chat/completions).
  • Add automatic token refresh and validation.
  • Implement real-time streaming responses for completions.
  • Introduce configurable request and token-based rate limiting.
  • Implement tracking and visualization of usage metrics.
  • Provide a web interface for authentication and usage dashboard.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 24, 2025

Reviewer's Guide by Sourcery

This pull request introduces the initial implementation of the GitHub Copilot Proxy, which provides an OpenAI-compatible API endpoint for Cursor IDE to utilize GitHub Copilot's AI services. Key features include OAuth device flow authentication, OpenAI-compatible API endpoints with streaming support, rate limiting, usage monitoring, and a web interface. The implementation uses Node.js with TypeScript and Express.js, and follows a modular architecture.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implemented OAuth device flow authentication for secure GitHub authentication.
  • Utilized @octokit/auth-oauth-device for the OAuth device flow.
  • Implemented token refresh and validation mechanisms.
  • Ensured tokens are stored in memory only for security.
src/config
src/services/auth.ts
Developed OpenAI-compatible API endpoints for Cursor IDE integration.
  • Implemented /v1/models endpoint.
  • Implemented /v1/chat/completions endpoint.
  • Added streaming support using Server-Sent Events (SSE) via @microsoft/fetch-event-source.
src/routes/models.ts
src/routes/chatCompletions.ts
src/services/copilot.ts
Implemented rate limiting to prevent abuse.
  • Configured request-based rate limiting.
  • Configured token-based rate limiting.
  • Added configurable options via environment variables.
src/middleware/rateLimiter.ts
src/config
Added usage monitoring and a web interface for authentication and usage visualization.
  • Implemented tracking of usage metrics.
  • Developed an authentication UI.
  • Created a usage dashboard.
  • Included static files in the src/public directory.
src/public
src/routes/auth.ts
src/services/usage.ts
Configured the application using environment variables with Zod validation.
  • Defined environment variables using Zod.
  • Implemented validation of environment variables at startup.
  • Centralized configuration management in src/config.
src/config

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@BjornMelin BjornMelin self-assigned this Mar 24, 2025
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @BjornMelin - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@BjornMelin BjornMelin merged commit 4d6176a into main Mar 24, 2025
2 of 6 checks passed
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