Skip to content

Commit bb3462b

Browse files
authored
Merge pull request #11 from ericc-ch/refactor/core-cleanup
Refactor/core cleanup
2 parents 836c703 + bd5eaed commit bb3462b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+556
-1085
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"editor.codeActionsOnSave": {
55
"source.fixAll.eslint": "explicit",
66
"source.organizeImports": "never"
7-
}
7+
},
8+
"typescript.tsdk": "node_modules/typescript/lib"
89
}

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ npx copilot-api --port 8080
4040

4141
## Command Line Options
4242

43-
The command accepts several command line options:
43+
The following command line options are available:
4444

45-
| Option | Description | Default |
46-
| ------------- | ------------------------------------ | ------- |
47-
| --port, -p | Port to listen on | 4141 |
48-
| --verbose, -v | Enable verbose logging | false |
49-
| --log-file | File to log request/response details | - |
45+
| Option | Description | Default |
46+
| ------------- | ---------------------- | ------- |
47+
| --port, -p | Port to listen on | 4141 |
48+
| --verbose, -v | Enable verbose logging | false |
5049

51-
Example with options:
50+
Example usage:
5251

5352
```sh
54-
npx copilot-api@latest --port 8080 --verbose --log-file copilot-api.txt
53+
npx copilot-api@latest --port 8080 --verbose
5554
```
5655

5756
## Running from Source
@@ -70,9 +69,19 @@ bun run dev
7069
bun run start
7170
```
7271

73-
## Tips to not hit the rate limit
72+
## Usage Tips
7473

75-
- Use a free model from free provider like Gemini/Mistral/Openrouter for the weak model
76-
- Rarely use architect mode
77-
- Do not enable automatic yes in aider config
78-
- Claude 3.7 thinking mode uses more tokens. Use it sparingly
74+
To avoid rate limiting and optimize your experience:
75+
76+
- Consider using free models (e.g., Gemini, Mistral, Openrouter) as the `weak-model`
77+
- Use architect mode sparingly
78+
- Disable `yes-always` in your aider configuration
79+
- Be mindful that Claude 3.7 thinking mode consume more tokens
80+
81+
## Roadmap
82+
83+
- [ ] Manual authentication flow
84+
- [ ] Manual request approval system
85+
- [ ] Rate limiting implementation
86+
- [ ] Token usage tracking and monitoring
87+
- [ ] Enhanced error handling and recovery

bun.lock

Lines changed: 19 additions & 79 deletions
Large diffs are not rendered by default.

eslint.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

eslint.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import config from "@echristian/eslint-config"
2+
3+
export default config({
4+
prettier: {
5+
plugins: ["prettier-plugin-packagejson"],
6+
},
7+
})

knip.config.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"prepack": "bun run build",
3030
"prepare": "simple-git-hooks",
3131
"release": "bumpp && bun publish --access public",
32-
"start": "NODE_ENV=production bun run ./src/main.ts",
33-
"test": "vitest"
32+
"start": "NODE_ENV=production bun run ./src/main.ts"
3433
},
3534
"simple-git-hooks": {
3635
"pre-commit": "bunx lint-staged"
@@ -42,24 +41,20 @@
4241
"citty": "^0.1.6",
4342
"consola": "^3.4.0",
4443
"fetch-event-stream": "^0.1.5",
45-
"get-port-please": "^3.1.2",
4644
"hono": "^4.7.4",
47-
"ofetch": "^1.4.1",
48-
"pathe": "^2.0.3",
49-
"srvx": "^0.1.4",
50-
"zod": "^3.24.2"
45+
"srvx": "^0.2.5"
5146
},
5247
"devDependencies": {
5348
"@echristian/eslint-config": "^0.0.32",
5449
"@types/bun": "^1.2.4",
5550
"bumpp": "^10.0.3",
5651
"eslint": "^9.22.0",
52+
"jiti": "^2.4.2",
5753
"knip": "^5.45.0",
5854
"lint-staged": "^15.4.3",
55+
"prettier-plugin-packagejson": "^2.5.10",
5956
"simple-git-hooks": "^2.11.1",
60-
"tinyexec": "^0.3.2",
6157
"tsup": "^8.4.0",
62-
"typescript": "^5.8.2",
63-
"vitest": "^3.0.8"
58+
"typescript": "^5.8.2"
6459
}
6560
}

src/lib/api-config.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { State } from "./state"
2+
3+
export const standardHeaders = () => ({
4+
"content-type": "application/json",
5+
accept: "application/json",
6+
})
7+
8+
export const COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com"
9+
export const copilotHeaders = (state: State) => ({
10+
Authorization: `Bearer ${state.copilotToken}`,
11+
"content-type": standardHeaders()["content-type"],
12+
"copilot-integration-id": "vscode-chat",
13+
"editor-version": `vscode/${state.vsCodeVersion}`,
14+
"editor-plugin-version": "copilot-chat/0.24.1",
15+
"openai-intent": "conversation-panel",
16+
"x-github-api-version": "2024-12-15",
17+
"x-request-id": globalThis.crypto.randomUUID(),
18+
"x-vscode-user-agent-library-version": "electron-fetch",
19+
})
20+
21+
export const GITHUB_API_BASE_URL = "https://api.github.com"
22+
export const githubHeaders = (state: State) => ({
23+
...standardHeaders(),
24+
authorization: `token ${state.githubToken}`,
25+
"editor-version": `vscode/${state.vsCodeVersion}`,
26+
"editor-plugin-version": "copilot-chat/0.24.1",
27+
"user-agent": "GitHubCopilotChat/0.24.1",
28+
"x-github-api-version": "2024-12-15",
29+
"x-vscode-user-agent-library-version": "electron-fetch",
30+
})
31+
32+
export const GITHUB_BASE_URL = "https://github.com"
33+
export const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
34+
export const GITHUB_APP_SCOPES = [
35+
"read:org",
36+
"read:user",
37+
"repo",
38+
"user:email",
39+
"workflow",
40+
].join(" ")

src/lib/constants.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/lib/forward-error.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Context } from "hono"
2+
import type { ContentfulStatusCode } from "hono/utils/http-status"
3+
4+
import consola from "consola"
5+
6+
import { HTTPError } from "./http-error"
7+
8+
export async function forwardError(c: Context, error: unknown) {
9+
consola.error("Error occurred:", error)
10+
11+
if (error instanceof HTTPError) {
12+
const errorText = await error.response.text()
13+
return c.json(
14+
{
15+
error: {
16+
message: errorText,
17+
type: "error",
18+
},
19+
},
20+
error.response.status as ContentfulStatusCode,
21+
)
22+
}
23+
24+
return c.json(
25+
{
26+
error: {
27+
message: (error as Error).message,
28+
type: "error",
29+
},
30+
},
31+
500,
32+
)
33+
}

0 commit comments

Comments
 (0)