Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
118ccc1
docs: Add roadmap to README
ericc-ch Mar 9, 2025
dccb7b7
refactor: Remove unused log paths and simplify server initialization
ericc-ch Mar 9, 2025
107c528
fix: Ensure GitHub token file exists and has correct permissions
ericc-ch Mar 9, 2025
2d925b1
refactor: use native fetch for github device flow
ericc-ch Mar 9, 2025
e7e9daf
refactor: extract token retrieval into smaller functions
ericc-ch Mar 10, 2025
ac7219f
feat: Improve initialization and update build config
ericc-ch Mar 10, 2025
9c457c5
chore: Update srvx dependency and remove vitest-related packages
ericc-ch Mar 11, 2025
0665661
refactor: simplify GitHub authentication and token handling
ericc-ch Mar 11, 2025
5bb8741
refactor: Move initialization logic to main and lib files
ericc-ch Mar 11, 2025
3ff3221
fix: Remove JSON.stringify from user login consola output
ericc-ch Mar 11, 2025
cb2b18c
Refactor: Use native fetch instead of ofetch for GitHub API calls
ericc-ch Mar 11, 2025
6e5ab64
refactor: Simplify and improve copilot models and github user services
ericc-ch Mar 11, 2025
1096cbf
refactor: Rename copilot-token service and move models types
ericc-ch Mar 11, 2025
6ba6c5b
refactor: Move API config to api-config.ts and update imports
ericc-ch Mar 11, 2025
1d99f2d
refactor: Move createEmbeddings to its own file and remove old files
ericc-ch Mar 11, 2025
43b3d29
refactor: Use fetch instead of copilot instance for chat completions
ericc-ch Mar 11, 2025
0e98c05
refactor: Refactor API headers and add chat completion types
ericc-ch Mar 11, 2025
adcbfca
fix: Use Bearer token for copilot authorization and remove logger.
ericc-ch Mar 11, 2025
e488fc5
feat: migrate to flat config and add prettier plugin for package.json
ericc-ch Mar 11, 2025
e2af351
build: Configure TypeScript for better module handling and strictness
ericc-ch Mar 11, 2025
67d0eec
chore: Update enhanced-resolve and knip config
ericc-ch Mar 11, 2025
b5f8ce6
chore: remove unused dependencies and knip config
ericc-ch Mar 11, 2025
1654e64
refactor: Simplify error handling and remove unused logging features
ericc-ch Mar 11, 2025
c589db2
refactor: Refactor error handling and copilot API calls
ericc-ch Mar 11, 2025
20c50dc
fix: Handle errors and cache models correctly
ericc-ch Mar 11, 2025
c9f992e
chore: Remove test script
ericc-ch Mar 11, 2025
b24db81
feat: Cache VSCode version on startup
ericc-ch Mar 11, 2025
2f293ab
fix: request device code with scopes
ericc-ch Mar 11, 2025
de13b29
refactor: Improve error handling and token management
ericc-ch Mar 11, 2025
bd5eaed
docs: Update README with minor fixes and roadmap item
ericc-ch Mar 11, 2025
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ npx copilot-api --port 8080

## Command Line Options

The command accepts several command line options:
The following command line options are available:

| Option | Description | Default |
| ------------- | ------------------------------------ | ------- |
| --port, -p | Port to listen on | 4141 |
| --verbose, -v | Enable verbose logging | false |
| --log-file | File to log request/response details | - |
| Option | Description | Default |
| ------------- | ---------------------- | ------- |
| --port, -p | Port to listen on | 4141 |
| --verbose, -v | Enable verbose logging | false |

Example with options:
Example usage:

```sh
npx copilot-api@latest --port 8080 --verbose --log-file copilot-api.txt
npx copilot-api@latest --port 8080 --verbose
```

## Running from Source
Expand All @@ -70,9 +69,19 @@ bun run dev
bun run start
```

## Tips to not hit the rate limit
## Usage Tips

- Use a free model from free provider like Gemini/Mistral/Openrouter for the weak model
- Rarely use architect mode
- Do not enable automatic yes in aider config
- Claude 3.7 thinking mode uses more tokens. Use it sparingly
To avoid rate limiting and optimize your experience:

- Consider using free models (e.g., Gemini, Mistral, Openrouter) as the `weak-model`
- Use architect mode sparingly
- Disable `yes-always` in your aider configuration
- Be mindful that Claude 3.7 thinking mode consume more tokens

## Roadmap

- [ ] Manual authentication flow
- [ ] Manual request approval system
- [ ] Rate limiting implementation
- [ ] Token usage tracking and monitoring
- [ ] Enhanced error handling and recovery
98 changes: 19 additions & 79 deletions bun.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions eslint.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import config from "@echristian/eslint-config"

export default config({
prettier: {
plugins: ["prettier-plugin-packagejson"],
},
})
6 changes: 0 additions & 6 deletions knip.config.ts

This file was deleted.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"prepack": "bun run build",
"prepare": "simple-git-hooks",
"release": "bumpp && bun publish --access public",
"start": "NODE_ENV=production bun run ./src/main.ts",
"test": "vitest"
"start": "NODE_ENV=production bun run ./src/main.ts"
},
"simple-git-hooks": {
"pre-commit": "bunx lint-staged"
Expand All @@ -42,24 +41,20 @@
"citty": "^0.1.6",
"consola": "^3.4.0",
"fetch-event-stream": "^0.1.5",
"get-port-please": "^3.1.2",
"hono": "^4.7.4",
"ofetch": "^1.4.1",
"pathe": "^2.0.3",
"srvx": "^0.1.4",
"zod": "^3.24.2"
"srvx": "^0.2.5"
},
"devDependencies": {
"@echristian/eslint-config": "^0.0.32",
"@types/bun": "^1.2.4",
"bumpp": "^10.0.3",
"eslint": "^9.22.0",
"jiti": "^2.4.2",
"knip": "^5.45.0",
"lint-staged": "^15.4.3",
"prettier-plugin-packagejson": "^2.5.10",
"simple-git-hooks": "^2.11.1",
"tinyexec": "^0.3.2",
"tsup": "^8.4.0",
"typescript": "^5.8.2",
"vitest": "^3.0.8"
"typescript": "^5.8.2"
}
}
40 changes: 40 additions & 0 deletions src/lib/api-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { State } from "./state"

export const standardHeaders = () => ({
"content-type": "application/json",
accept: "application/json",
})

export const COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com"
export const copilotHeaders = (state: State) => ({
Authorization: `Bearer ${state.copilotToken}`,
"content-type": standardHeaders()["content-type"],
"copilot-integration-id": "vscode-chat",
"editor-version": `vscode/${state.vsCodeVersion}`,
"editor-plugin-version": "copilot-chat/0.24.1",
"openai-intent": "conversation-panel",
"x-github-api-version": "2024-12-15",
"x-request-id": globalThis.crypto.randomUUID(),
"x-vscode-user-agent-library-version": "electron-fetch",
})

export const GITHUB_API_BASE_URL = "https://api.github.com"
export const githubHeaders = (state: State) => ({
...standardHeaders(),
authorization: `token ${state.githubToken}`,
"editor-version": `vscode/${state.vsCodeVersion}`,
"editor-plugin-version": "copilot-chat/0.24.1",
"user-agent": "GitHubCopilotChat/0.24.1",
"x-github-api-version": "2024-12-15",
"x-vscode-user-agent-library-version": "electron-fetch",
})

export const GITHUB_BASE_URL = "https://github.com"
export const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
export const GITHUB_APP_SCOPES = [
"read:org",
"read:user",
"repo",
"user:email",
"workflow",
].join(" ")
31 changes: 0 additions & 31 deletions src/lib/constants.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/lib/forward-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Context } from "hono"
import type { ContentfulStatusCode } from "hono/utils/http-status"

import consola from "consola"

import { HTTPError } from "./http-error"

export async function forwardError(c: Context, error: unknown) {
consola.error("Error occurred:", error)

if (error instanceof HTTPError) {
const errorText = await error.response.text()
return c.json(
{
error: {
message: errorText,
type: "error",
},
},
error.response.status as ContentfulStatusCode,
)
}

return c.json(
{
error: {
message: (error as Error).message,
type: "error",
},
},
500,
)
}
8 changes: 8 additions & 0 deletions src/lib/http-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class HTTPError extends Error {
response: Response

constructor(message: string, response: Response) {
super(message)
this.response = response
}
}
75 changes: 0 additions & 75 deletions src/lib/initialization.ts

This file was deleted.

Loading