|
171 | 171 | ---@class CopilotChat.config.providers.Provider |
172 | 172 | ---@field disabled nil|boolean |
173 | 173 | ---@field get_headers nil|fun():table<string, string>,number? |
| 174 | +---@field get_info nil|fun(headers:table):string[] |
174 | 175 | ---@field get_models nil|fun(headers:table):table<CopilotChat.client.Model> |
175 | 176 | ---@field embed nil|string|fun(inputs:table<string>, headers:table):table<CopilotChat.client.Embed> |
176 | 177 | ---@field prepare_input nil|fun(inputs:table<CopilotChat.client.Message>, opts:CopilotChat.config.providers.Options):table |
@@ -204,6 +205,56 @@ M.copilot = { |
204 | 205 | response.body.expires_at |
205 | 206 | end, |
206 | 207 |
|
| 208 | + get_info = function(headers) |
| 209 | + local response, err = utils.curl_get('https://api.github.com/copilot_internal/user', { |
| 210 | + json_response = true, |
| 211 | + headers = { |
| 212 | + ['Authorization'] = 'Token ' .. get_github_token('github_copilot'), |
| 213 | + }, |
| 214 | + }) |
| 215 | + |
| 216 | + if err then |
| 217 | + error(err) |
| 218 | + end |
| 219 | + |
| 220 | + local stats = response.body |
| 221 | + local lines = {} |
| 222 | + |
| 223 | + if not stats or not stats.quota_snapshots then |
| 224 | + return { 'No Copilot stats available.' } |
| 225 | + end |
| 226 | + |
| 227 | + local function usage_line(name, snap) |
| 228 | + if not snap then |
| 229 | + return |
| 230 | + end |
| 231 | + |
| 232 | + table.insert(lines, string.format(' **%s**', name)) |
| 233 | + |
| 234 | + if snap.unlimited then |
| 235 | + table.insert(lines, ' Usage: Unlimited') |
| 236 | + else |
| 237 | + local used = snap.entitlement - snap.remaining |
| 238 | + local percent = snap.entitlement > 0 and (used / snap.entitlement * 100) or 0 |
| 239 | + table.insert(lines, string.format(' Usage: %d / %d (%.1f%%)', used, snap.entitlement, percent)) |
| 240 | + table.insert(lines, string.format(' Remaining: %d', snap.remaining)) |
| 241 | + if snap.overage_permitted ~= nil then |
| 242 | + table.insert(lines, ' Overage: ' .. (snap.overage_permitted and 'Permitted' or 'Not Permitted')) |
| 243 | + end |
| 244 | + end |
| 245 | + end |
| 246 | + |
| 247 | + usage_line('Premium requests', stats.quota_snapshots.premium_interactions) |
| 248 | + usage_line('Chat', stats.quota_snapshots.chat) |
| 249 | + usage_line('Completions', stats.quota_snapshots.completions) |
| 250 | + |
| 251 | + if stats.quota_reset_date then |
| 252 | + table.insert(lines, string.format(' **Quota** resets on: %s', stats.quota_reset_date)) |
| 253 | + end |
| 254 | + |
| 255 | + return lines |
| 256 | + end, |
| 257 | + |
207 | 258 | get_models = function(headers) |
208 | 259 | local response, err = utils.curl_get('https://api.githubcopilot.com/models', { |
209 | 260 | json_response = true, |
|
0 commit comments