forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
96 lines (84 loc) · 2.18 KB
/
main.ts
File metadata and controls
96 lines (84 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
import { defineCommand, runMain } from "citty"
import consola from "consola"
import { serve, type ServerHandler } from "srvx"
import { cacheModels } from "./lib/models"
import { ensurePaths } from "./lib/paths"
import { state } from "./lib/state"
import { setupCopilotToken, setupGitHubToken } from "./lib/token"
import { cacheVSCodeVersion } from "./lib/vscode-version"
import { server } from "./server"
interface RunServerOptions {
port: number
verbose: boolean
business: boolean
manual: boolean
rateLimit: number
}
export async function runServer(options: RunServerOptions): Promise<void> {
if (options.verbose) {
consola.level = 5
consola.info("Verbose logging enabled")
}
if (options.business) {
state.accountType = "business"
consola.info("Using business plan GitHub account")
}
state.manualApprove = options.manual
state.rateLimitSeconds = options.rateLimit
await ensurePaths()
await cacheVSCodeVersion()
await setupGitHubToken()
await setupCopilotToken()
await cacheModels()
const serverUrl = `http://localhost:${options.port}`
consola.box(`Server started at ${serverUrl}`)
serve({
fetch: server.fetch as ServerHandler,
port: options.port,
})
}
const main = defineCommand({
args: {
port: {
alias: "p",
type: "string",
default: "4141",
description: "Port to listen on",
},
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "Enable verbose logging",
},
business: {
type: "boolean",
default: false,
description: "Use a business plan GitHub Account",
},
manual: {
type: "boolean",
default: false,
description: "Enable manual request approval",
},
rateLimit: {
alias: "r",
type: "string",
default: "5",
description: "Rate limit in seconds between requests",
},
},
run({ args }) {
const port = Number.parseInt(args.port, 10)
const rateLimit = Number.parseInt(args.rateLimit, 10)
return runServer({
port,
verbose: args.verbose,
business: args.business,
manual: args.manual,
rateLimit,
})
},
})
await runMain(main)