Skip to content

Commit 7f4f431

Browse files
committed
feat: Support GitHub Copilot Business accounts
1 parent 7326a26 commit 7f4f431

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

src/lib/api-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const standardHeaders = () => ({
55
accept: "application/json",
66
})
77

8-
export const COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com"
8+
export const copilotBaseUrl = (state: State) =>
9+
`https://api.${state.accountType}.githubcopilot.com`
910
export const copilotHeaders = (state: State) => ({
1011
Authorization: `Bearer ${state.copilotToken}`,
1112
"content-type": standardHeaders()["content-type"],

src/lib/state.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ export interface State {
44
githubToken?: string
55
copilotToken?: string
66

7+
accountType: string
78
models?: ModelsResponse
89
vsCodeVersion?: string
910
}
1011

11-
export const state: State = {}
12+
export const state: State = {
13+
accountType: "individual",
14+
}

src/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { serve, type ServerHandler } from "srvx"
66

77
import { cacheModels } from "./lib/models"
88
import { ensurePaths } from "./lib/paths"
9+
import { state } from "./lib/state"
910
import { setupCopilotToken, setupGitHubToken } from "./lib/token"
1011
import { cacheVSCodeVersion } from "./lib/vscode-version"
1112
import { server } from "./server"
1213

1314
interface RunServerOptions {
1415
port: number
1516
verbose: boolean
17+
business: boolean
1618
}
1719

1820
export async function runServer(options: RunServerOptions): Promise<void> {
@@ -21,6 +23,11 @@ export async function runServer(options: RunServerOptions): Promise<void> {
2123
consola.info("Verbose logging enabled")
2224
}
2325

26+
if (options.business) {
27+
state.accountType = "business"
28+
consola.info("Using business plan GitHub account")
29+
}
30+
2431
await ensurePaths()
2532
await cacheVSCodeVersion()
2633
await setupGitHubToken()
@@ -50,13 +57,19 @@ const main = defineCommand({
5057
default: false,
5158
description: "Enable verbose logging",
5259
},
60+
business: {
61+
type: "boolean",
62+
default: false,
63+
description: "Use a business plan GitHub Account",
64+
},
5365
},
5466
run({ args }) {
5567
const port = Number.parseInt(args.port, 10)
5668

5769
return runServer({
5870
port,
5971
verbose: args.verbose,
72+
business: args.business,
6073
})
6174
},
6275
})

src/services/copilot/create-chat-completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { events } from "fetch-event-stream"
22

3-
import { copilotHeaders, COPILOT_API_BASE_URL } from "~/lib/api-config"
3+
import { copilotHeaders, copilotBaseUrl } from "~/lib/api-config"
44
import { HTTPError } from "~/lib/http-error"
55
import { state } from "~/lib/state"
66

@@ -9,7 +9,7 @@ export const createChatCompletions = async (
99
) => {
1010
if (!state.copilotToken) throw new Error("Copilot token not found")
1111

12-
const response = await fetch(`${COPILOT_API_BASE_URL}/chat/completions`, {
12+
const response = await fetch(`${copilotBaseUrl(state)}/chat/completions`, {
1313
method: "POST",
1414
headers: copilotHeaders(state),
1515
body: JSON.stringify(payload),

src/services/copilot/create-embeddings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { copilotHeaders, COPILOT_API_BASE_URL } from "~/lib/api-config"
1+
import { copilotHeaders, copilotBaseUrl } from "~/lib/api-config"
22
import { HTTPError } from "~/lib/http-error"
33
import { state } from "~/lib/state"
44

55
export const createEmbeddings = async (payload: EmbeddingRequest) => {
66
if (!state.copilotToken) throw new Error("Copilot token not found")
77

8-
const response = await fetch(`${COPILOT_API_BASE_URL}/embeddings`, {
8+
const response = await fetch(`${copilotBaseUrl(state)}/embeddings`, {
99
method: "POST",
1010
headers: copilotHeaders(state),
1111
body: JSON.stringify(payload),

src/services/copilot/get-models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { COPILOT_API_BASE_URL, copilotHeaders } from "~/lib/api-config"
1+
import { copilotBaseUrl, copilotHeaders } from "~/lib/api-config"
22
import { HTTPError } from "~/lib/http-error"
33
import { state } from "~/lib/state"
44

55
export const getModels = async () => {
6-
const response = await fetch(`${COPILOT_API_BASE_URL}/models`, {
6+
const response = await fetch(`${copilotBaseUrl(state)}/models`, {
77
headers: copilotHeaders(state),
88
})
99

0 commit comments

Comments
 (0)