MCPcopy Create free account
hub / github.com/arctic-cli/interface / loader

Function loader

packages/arctic/src/auth/github-copilot-oauth/plugin.ts:47–153  ·  view source on GitHub ↗
(getAuth, provider)

Source from the content-addressed store, hash-verified

45 provider: "github-copilot",
46
47 async loader(getAuth, provider) {
48 const info = await getAuth()
49
50 if (!info || info.type !== "oauth") return {}
51
52 if (provider && provider.models) {
53 for (const model of Object.values(provider.models)) {
54 model.cost = {
55 input: 0,
56 output: 0,
57 cache: {
58 read: 0,
59 write: 0,
60 },
61 }
62 }
63 }
64
65 const enterpriseUrl = (info as any).enterpriseUrl as string | undefined
66 const baseURL = enterpriseUrl
67 ? `https://copilot-api.${normalizeDomain(enterpriseUrl)}`
68 : "https://api.githubcopilot.com"
69
70 return {
71 baseURL,
72 apiKey: "",
73 async fetch(input: RequestInfo, init?: RequestInit): Promise<Response> {
74 const currentInfo = await getAuth()
75 if (currentInfo.type !== "oauth") return fetch(input, init)
76
77 const currentEnterpriseUrl = (currentInfo as any).enterpriseUrl as string | undefined
78 const domain = currentEnterpriseUrl ? normalizeDomain(currentEnterpriseUrl) : "github.com"
79 const urls = getUrls(domain)
80
81 let accessToken = currentInfo.access
82
83 // Refresh token if expired or missing
84 if (!accessToken || currentInfo.expires < Date.now()) {
85 const response = await fetch(urls.COPILOT_API_KEY_URL, {
86 headers: {
87 Accept: "application/json",
88 Authorization: `Bearer ${currentInfo.refresh}`,
89 ...HEADERS,
90 },
91 })
92
93 if (!response.ok) {
94 throw new Error(`Token refresh failed: ${response.status}`)
95 }
96
97 const tokenData = await response.json()
98 accessToken = tokenData.token
99 }
100
101 let isAgentCall = false
102 let isVisionRequest = false
103
104 try {

Callers

nothing calls this directly

Calls 1

normalizeDomainFunction · 0.85

Tested by

no test coverage detected