Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,4 @@ uv.lock
# package shadows the maturin overlay on sys.path.
/headroom/_core.*.so
/headroom/_core.so
plugin/
24 changes: 24 additions & 0 deletions Dockerfile.vscode-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:24-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
git ca-certificates \
&& rm -rf /var/lib/apt/lists/*

ARG VSCODE_FORK_REPO=https://github.com/damnthonyy/vscode.git
ARG VSCODE_FORK_BRANCH=main

WORKDIR /build
RUN git clone --depth=1 --branch=${VSCODE_FORK_BRANCH} ${VSCODE_FORK_REPO} vscode

WORKDIR /build/vscode/extensions/copilot

# Install deps without running postinstall (needs source files already present from the clone)
RUN npm install --ignore-scripts

# Run postinstall now that sources are present, build, then package
RUN npm run postinstall && \
npx tsx .esbuild.mts --sourcemaps && \
mkdir -p /plugin && \
npx vsce package --out /plugin/copilot-proxy.vsix --allow-missing-repository

CMD ["sh", "-c", "cp /plugin/copilot-proxy.vsix /output/ && echo 'Done:' && ls -lh /output/*.vsix"]
26 changes: 22 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
services:
headroom-proxy:
build: .
build:
context: .
args:
HEADROOM_EXTRAS: "proxy,code,ml"
command: ["--host", "0.0.0.0"]
environment:
- HEADROOM_HOST=0.0.0.0
# if you want to use a custom OpenAI-compatible API endpoint,
# uncomment and set the following line with the desired URL
# - OPENAI_TARGET_API_URL=https://api.x.ai
- OPENAI_TARGET_API_URL=https://api.githubcopilot.com
- GITHUB_TOKEN=${GITHUB_TOKEN}
ports:
- "8787:8787"
healthcheck:
Expand Down Expand Up @@ -45,6 +47,22 @@ services:
- NEO4J_apoc_import_file_enabled=true
- NEO4J_apoc_import_file_use__neo4j__config=true

# Build the patched Copilot Chat VSIX that routes LLM requests through headroom.
# Usage:
# docker compose --profile plugin run --rm vscode-plugin-builder
# code --install-extension ./plugin/copilot-proxy.vsix --force
vscode-plugin-builder:
build:
context: .
dockerfile: Dockerfile.vscode-plugin
args:
VSCODE_FORK_REPO: ${VSCODE_FORK_REPO:-https://github.com/damnthonyy/vscode.git}
VSCODE_FORK_BRANCH: ${VSCODE_FORK_BRANCH:-main}
volumes:
- ./plugin:/output
profiles:
- plugin

volumes:
qdrant_data:
neo4j_data:
2 changes: 2 additions & 0 deletions headroom/providers/proxy_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ async def gemini_delete_cached_content(request: Request, cache_id: str):
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
async def passthrough(request: Request, path: str):
custom_base = request.headers.get("x-headroom-base-url")
if not custom_base and "x-original-host" in request.headers:
custom_base = f"https://{request.headers['x-original-host']}"
if custom_base:
return await proxy.handle_passthrough(request, custom_base.rstrip("/"))

Expand Down
20 changes: 20 additions & 0 deletions tests/test_provider_proxy_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ async def fake_gemini_count(
).json()["base_url"]
== "https://custom.example/base"
)
# X-Original-Host support: patched VS Code Copilot extension sends this header
# instead of x-headroom-base-url to avoid modifying the path.
assert (
client.post(
"/chat/completions",
headers={"x-original-host": "api.githubcopilot.com"},
).json()["base_url"]
== "https://api.githubcopilot.com"
)
# x-headroom-base-url still wins over x-original-host when both are present
assert (
client.get(
"/chat/completions",
headers={
"x-headroom-base-url": "https://explicit.example",
"x-original-host": "api.githubcopilot.com",
},
).json()["base_url"]
== "https://explicit.example"
)
assert client.get("/another/path", headers={"x-goog-api-key": "test"}).json()[
"base_url"
] == ("https://api.gemini.test")
Expand Down
Loading