Skip to content

jrmyyee/copilot_layer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Copilot Bridge Extension

A VS Code extension that provides HTTP API access to GitHub Copilot via the VS Code Language Model API. This allows you to make programmatic calls to Copilot from any language or tool without using the Copilot UI directly.

Prerequisites

  • VS Code installed with GitHub Copilot extension
  • GitHub Copilot subscription (active and signed in)
  • Node.js installed (for development)

Quick Start

  1. Open this folder in VS Code
  2. Press F5 (or fn + F5 on Mac) to launch the Extension Development Host
  3. Look for notification: "Copilot Bridge API running on http://localhost:3000"
  4. Accept permissions: First API call will prompt for Copilot model access - click "Allow"
  5. Start making API calls to http://localhost:3000

API Usage

Basic Request

curl -X POST http://localhost:3000/copilot \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Write a hello world function in JavaScript"}'

With Custom System Prompt

curl -X POST http://localhost:3000/copilot \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Create a REST API endpoint for user authentication",
    "systemPrompt": "You are a Node.js security expert. Include input validation and error handling."
  }'

Response Format

{
  "response": "function helloWorld() {\n  console.log('Hello, World!');\n}"
}

Health Check

curl http://localhost:3000/health
# Returns: {"status": "ok", "timestamp": "2024-01-01T12:00:00.000Z"}

Integration Examples

Python

import requests

response = requests.post('http://localhost:3000/copilot', json={
    'prompt': 'Write a Python class for a simple calculator',
    'systemPrompt': 'Focus on clean, testable code with docstrings'
})
print(response.json()['response'])

JavaScript/Node.js

const response = await fetch('http://localhost:3000/copilot', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'Explain async/await in JavaScript',
    systemPrompt: 'Provide practical examples with error handling'
  })
});
const data = await response.json();
console.log(data.response);

Manual Testing (VS Code Command)

For testing within VS Code:

  1. Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P)
  2. Run: "Copilot Bridge: Ask"
  3. Enter your prompt
  4. Response opens in a new editor tab

API Reference

Endpoints

  • POST /copilot - Send prompt to Copilot

    • Body: { "prompt": string, "systemPrompt"?: string }
    • Response: { "response": string } or { "error": string }
  • GET /health - Health check

    • Response: { "status": "ok", "timestamp": string }

Important Notes

Privacy & Chat History

  • API calls do NOT appear in VS Code's chat history - they operate independently
  • All interactions are private and don't affect your VS Code Copilot chat sessions
  • Perfect for programmatic/automated use cases without UI clutter

Permissions

  • First API call will trigger VS Code's permission dialog for Copilot model access
  • You must click "Allow" to enable the API functionality
  • This is a one-time setup per VS Code session

Features

  • 🚀 HTTP REST API - Call from any programming language or tool
  • 🔒 Private operations - Won't appear in VS Code chat history
  • ⚙️ Custom system prompts - Fine-tune Copilot's behavior per request
  • 🎯 Direct model access - Uses your existing GitHub Copilot subscription
  • 📝 Manual testing - Built-in VS Code command for development
  • Real-time responses - Streams full responses efficiently

Development Commands

npm run compile    # Compile TypeScript to JavaScript
npm run watch      # Watch for changes and auto-compile

Troubleshooting

Issue Solution
"No Copilot models available" Ensure GitHub Copilot extension is installed and you're signed in to GitHub
Permission errors Accept the consent dialog when first making API calls
Extension won't start Check compilation with npm run compile, restart with F5
API not responding Verify the notification shows "API running on http://localhost:3000"
Port 3000 in use Close other applications using port 3000, or modify the PORT in src/extension.ts

Limitations

  • Requires VS Code to be running with extension active
  • Uses your GitHub Copilot subscription quota
  • API is only accessible while Extension Development Host is running
  • No built-in conversation memory - manage context in your application

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published