forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-copilot-usage.ts
More file actions
45 lines (39 loc) · 1.14 KB
/
get-copilot-usage.ts
File metadata and controls
45 lines (39 loc) · 1.14 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
import { GITHUB_API_BASE_URL, githubHeaders } from "~/lib/api-config"
import { HTTPError } from "~/lib/error"
import { state } from "~/lib/state"
export const getCopilotUsage = async (): Promise<CopilotUsageResponse> => {
const response = await fetch(`${GITHUB_API_BASE_URL}/copilot_internal/user`, {
headers: githubHeaders(state),
})
if (!response.ok) {
throw new HTTPError("Failed to get Copilot usage", response)
}
return (await response.json()) as CopilotUsageResponse
}
export interface QuotaDetail {
entitlement: number
overage_count: number
overage_permitted: boolean
percent_remaining: number
quota_id: string
quota_remaining: number
remaining: number
unlimited: boolean
}
interface QuotaSnapshots {
chat: QuotaDetail
completions: QuotaDetail
premium_interactions: QuotaDetail
}
interface CopilotUsageResponse {
access_type_sku: string
analytics_tracking_id: string
assigned_date: string
can_signup_for_limited: boolean
chat_enabled: boolean
copilot_plan: string
organization_login_list: Array<unknown>
organization_list: Array<unknown>
quota_reset_date: string
quota_snapshots: QuotaSnapshots
}