forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-copilot-token.ts
More file actions
30 lines (25 loc) · 786 Bytes
/
get-copilot-token.ts
File metadata and controls
30 lines (25 loc) · 786 Bytes
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
import consola from "consola"
import { GITHUB_API_BASE_URL, githubHeaders } from "~/lib/api-config"
import { HTTPError } from "~/lib/error"
import { state } from "~/lib/state"
export const getCopilotToken = async () => {
const response = await fetch(
`${GITHUB_API_BASE_URL}/copilot_internal/v2/token`,
{
headers: githubHeaders(state),
},
)
if (!response.ok) {
consola.error(
`Failed to get Copilot token: HTTP ${response.status} ${response.statusText} from ${response.url}`,
)
throw new HTTPError("Failed to get Copilot token", response)
}
return (await response.json()) as GetCopilotTokenResponse
}
// Trimmed for the sake of simplicity
interface GetCopilotTokenResponse {
expires_at: number
refresh_in: number
token: string
}