Skip to content

Commit 2ebb3bd

Browse files
committed
refactor: Move token management to lib/token and simplify imports
1 parent 98a2533 commit 2ebb3bd

8 files changed

Lines changed: 14 additions & 132 deletions

File tree

src/lib/cli.ts

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

src/lib/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// VSCode client ID
32
const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
43
const GITHUB_OAUTH_SCOPES = [

src/lib/initialization.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import fs from "node:fs/promises"
33
import { FetchError } from "ofetch"
44

55
import { PATHS } from "~/lib/paths"
6+
import { tokenService } from "~/lib/token"
67
import { getGitHubUser } from "~/services/github/get-user/service"
7-
import { tokenService } from "~/services/token-service"
88

99
import { getModels } from "../services/copilot/get-models/service"
1010
import { getGitHubToken } from "../services/github/get-token/service"
@@ -49,10 +49,10 @@ async function initializeCopilotToken(): Promise<void> {
4949
await tokenService.initCopilotToken()
5050
}
5151

52-
async function initializeModelInformation(): Promise<void> {
52+
async function logModelInformation(): Promise<void> {
5353
const models = await getModels()
5454
consola.info(
55-
`Available models: \n${models.data.map((model) => `- ${model.id}`).join("\n")}`,
55+
`Available models: \n${models.data.map((model) => `- ${model.id}`).join("\n")}\n`,
5656
)
5757
}
5858

@@ -71,5 +71,5 @@ export async function initializeApp() {
7171
await initializeAppDirectory()
7272
await initializeGithubAuthentication()
7373
await initializeCopilotToken()
74-
await initializeModelInformation()
74+
await logModelInformation()
7575
}

src/lib/tokens.ts

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

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const main = defineCommand({
2525
await initializeApp()
2626

2727
const serverUrl = `http://localhost:${port}`
28-
consola.success(`Server started at ${serverUrl}`)
28+
consola.box(`Server started at ${serverUrl}`)
2929

3030
serve({
3131
fetch: server.fetch as ServerHandler,

src/services/api-instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
GITHUB_API_CONFIG,
77
GITHUB_WEB_API_CONFIG,
88
} from "~/lib/constants"
9-
import { tokenService } from "~/services/token-service"
9+
import { tokenService } from "~/lib/token"
1010

1111
export const copilot = ofetch.create({
1212
baseURL: COPILOT_API_CONFIG.baseURL,
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { stream } from "fetch-event-stream"
22

33
import { COPILOT_API_CONFIG } from "~/lib/constants"
4+
import { tokenService } from "~/lib/token"
45

56
import type { ChatCompletionsPayload } from "./types"
67

7-
import { TOKENS } from "../../../lib/tokens"
8+
export const chatCompletionsStream = async (
9+
payload: ChatCompletionsPayload,
10+
) => {
11+
const copilotToken = tokenService.getCopilotToken()
812

9-
export const chatCompletionsStream = async (payload: ChatCompletionsPayload) =>
10-
stream(`${COPILOT_API_CONFIG.baseURL}/chat/completions`, {
13+
return stream(`${COPILOT_API_CONFIG.baseURL}/chat/completions`, {
1114
method: "POST",
1215
headers: {
1316
...COPILOT_API_CONFIG.headers,
14-
authorization: `Bearer ${TOKENS.COPILOT_TOKEN}`,
17+
authorization: `Bearer ${copilotToken}`,
1518
},
1619
body: JSON.stringify(payload),
1720
})
21+
}

src/services/token-service.ts

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

0 commit comments

Comments
 (0)