HTTP Ping Server Extension
A VS Code extension that starts a local HTTP server on port 3000 and handles POST requests to forward prompts to AI chat services.
Features
- HTTP Server: Listens on
http://localhost:3000 for incoming requests
- Copilot Integration: Route requests to GitHub Copilot via the
/ping endpoint with "target": "copilot"
- Amazon Q Integration: Route requests to Amazon Q via the
/ping endpoint with "target": "amazonq"
- JSON-based API: Accepts structured JSON payloads with
target and command fields
Usage
API Endpoint: POST /ping
The extension exposes a single HTTP endpoint that accepts POST requests with the following JSON body:
{
"target": "copilot" | "amazonq",
"command": "<your-prompt-or-command>"
}
Request Examples
Send a prompt to Copilot:
curl -X POST http://localhost:3000/ping \
-H "Content-Type: application/json" \
-d '{"target": "copilot", "command": "Explain this TypeScript code"}'
Send a prompt to Amazon Q:
curl -X POST http://localhost:3000/ping \
-H "Content-Type: application/json" \
-d '{"target": "amazonq", "command": "What are the best practices for AWS?"}'
Success Response (200 OK):
{
"success": true,
"message": "Command executed for target: copilot",
"command": "copilot.chat.sendPrompt"
}
Error Response (400 Bad Request - Unknown Target):
{
"error": "Unknown target: \"unknown\". Expected \"copilot\" or \"amazonq\"."
}
Error Response (400 Bad Request - Missing Fields):
{
"error": "Missing \"target\" or \"command\" field"
}
Error Response (400 Bad Request - Invalid JSON):
{
"error": "Invalid JSON body",
"details": "Unexpected token u in JSON at position 0"
}
Error Response (500 Internal Server Error):
{
"error": "Failed to execute command: copilot.chat.sendPrompt is not available"
}
Installation & Development
Prerequisites
- Visual Studio Code 1.106.0 or higher
- Node.js and npm
Build
npm run compile
Watch Mode
npm run watch
Run Tests
npm run test
Lint
npm run lint
Extension Structure
.
├── src/
│ ├── extension.ts # Main extension code with HTTP server
│ └── test/
│ └── extension.test.ts
├── package.json # Extension manifest and metadata
├── tsconfig.json # TypeScript configuration
└── README.md # This file
How It Works
- Activation: The extension activates on VS Code startup (
onStartupFinished)
- Server Start: An HTTP server is created and bound to port 3000
- Request Handling: When a POST request arrives at
/ping:
- The JSON body is parsed
- The
target field determines which VS Code command to execute
- The
command field is passed as an argument to that command
- Command Execution:
- For
target: "copilot": Executes copilot.chat.sendPrompt command
- For
target: "amazonq": Executes aws.q.sendPrompt command
- For any other target: Returns an error response
Commands
The extension provides one command accessible via the VS Code Command Palette:
- Stop HTTP Ping Server (
http-ping-server.stopServer) - Stops the running HTTP server
Configuration
The server runs on a fixed port (3000) and cannot be configured via settings. To change the port, modify the PORT constant in src/extension.ts and recompile.
Troubleshooting
Port Already in Use
If you see "Port 3000 is already in use", you can either:
- Kill the process using that port
- Stop the extension using the "Stop HTTP Ping Server" command
- Change the port in
src/extension.ts
Command Not Available
If you receive "command not available" errors:
- Ensure the required extension (Copilot or Amazon Q) is installed and enabled
- Check the VS Code logs for more details
Release Notes
1.0.0
Initial release of HTTP Ping Server extension with support for Copilot and Amazon Q integration.
Following extension guidelines
Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.
Working with Markdown
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
- Split the editor (
Cmd+\ on macOS or Ctrl+\ on Windows and Linux).
- Toggle preview (
Shift+Cmd+V on macOS or Shift+Ctrl+V on Windows and Linux).
- Press
Ctrl+Space (Windows, Linux, macOS) to see a list of Markdown snippets.
Enjoy!