copilot-api / src /services /github /get-copilot-token.ts
imspsycho's picture
Initial upload from Google Colab
98c9143 verified
Raw
History Blame Contribute Delete
784 Bytes
import consola from "consola"
import { getGitHubApiBaseUrl, githubHeaders } from "~/lib/api-config"
import { HTTPError } from "~/lib/error"
import { state } from "~/lib/state"
export const getCopilotToken = async () => {
const response = await fetch(
`${getGitHubApiBaseUrl()}/copilot_internal/v2/token`,
{
headers: githubHeaders(state),
},
)
if (!response.ok) {
const errorText = await response.clone().text()
consola.error("Failed to get Copilot token response body", errorText)
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
}