Skip to content

Commit 899f4c2

Browse files
committed
refactor: Remove old API configurations and update imports in services
1 parent 4ec3eab commit 899f4c2

File tree

6 files changed

+44
-37
lines changed

6 files changed

+44
-37
lines changed

src/lib/api.ts

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

src/lib/config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,33 @@ export const CONFIG = {
22
EMULATE_STREAMING: false,
33
LOGGING_ENABLED: false,
44
}
5+
6+
// VSCode client ID
7+
const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
8+
const GITHUB_OAUTH_SCOPES = [
9+
"read:org",
10+
"read:user",
11+
"repo",
12+
"user:email",
13+
"workflow",
14+
].join(" ")
15+
16+
export const ENV = {
17+
GITHUB_CLIENT_ID,
18+
GITHUB_OAUTH_SCOPES,
19+
}
20+
21+
export const COPILOT_API_CONFIG = {
22+
baseURL: "https://api.individual.githubcopilot.com",
23+
headers: {
24+
"copilot-integration-id": "vscode-chat",
25+
},
26+
} as const
27+
28+
export const GITHUB_API_CONFIG = {
29+
baseURL: "https://api.github.com",
30+
} as const
31+
32+
export const GITHUB_WEB_API_CONFIG = {
33+
baseURL: "https://github.com",
34+
} as const

src/lib/env.ts

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

src/services/api-instance.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import consola from "consola"
22
import { FetchError, ofetch } from "ofetch"
33

4-
import { COPILOT_CONFIG, GITHUB_CONFIG, GITHUB_WEB_CONFIG } from "~/lib/api"
4+
import {
5+
COPILOT_API_CONFIG,
6+
GITHUB_API_CONFIG,
7+
GITHUB_WEB_API_CONFIG,
8+
} from "~/lib/config"
59
import { TOKENS } from "~/lib/tokens"
610

711
export const copilot = ofetch.create({
8-
baseURL: COPILOT_CONFIG.baseURL,
9-
headers: COPILOT_CONFIG.headers,
12+
baseURL: COPILOT_API_CONFIG.baseURL,
13+
headers: COPILOT_API_CONFIG.headers,
1014

1115
onRequest({ options }) {
1216
options.headers.set("authorization", `Bearer ${TOKENS.COPILOT_TOKEN}`)
@@ -32,7 +36,7 @@ export const copilot = ofetch.create({
3236
})
3337

3438
export const github = ofetch.create({
35-
baseURL: GITHUB_CONFIG.baseURL,
39+
baseURL: GITHUB_API_CONFIG.baseURL,
3640

3741
onRequest({ options }) {
3842
options.headers.set("authorization", `token ${TOKENS.GITHUB_TOKEN}`)
@@ -41,5 +45,5 @@ export const github = ofetch.create({
4145

4246
// Only used for device flow auth
4347
export const _github = ofetch.create({
44-
baseURL: GITHUB_WEB_CONFIG.baseURL,
48+
baseURL: GITHUB_WEB_API_CONFIG.baseURL,
4549
})

src/services/copilot/chat-completions/service-streaming.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { stream } from "fetch-event-stream"
22

3+
import { COPILOT_API_CONFIG } from "~/lib/config"
4+
35
import type { ChatCompletionsPayload } from "./types"
46

5-
import { COPILOT_CONFIG } from "../../../lib/api"
67
import { TOKENS } from "../../../lib/tokens"
78

89
export const chatCompletionsStream = async (payload: ChatCompletionsPayload) =>
9-
stream(`${COPILOT_CONFIG.baseURL}/chat/completions`, {
10+
stream(`${COPILOT_API_CONFIG.baseURL}/chat/completions`, {
1011
method: "POST",
1112
headers: {
12-
...COPILOT_CONFIG.headers,
13+
...COPILOT_API_CONFIG.headers,
1314
authorization: `Bearer ${TOKENS.COPILOT_TOKEN}`,
1415
},
1516
body: JSON.stringify(payload),

src/services/github/get-token/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import consola from "consola"
22

3-
import { ENV } from "~/lib/env"
3+
import { ENV } from "~/lib/config"
44
import { _github } from "~/services/api-instance"
55

66
interface DeviceCodeResponse {

0 commit comments

Comments
 (0)