|
1 | | -import { getToken } from "./kiro-auth" |
2 | | - |
3 | | -const ENDPOINT = "https://q.us-east-1.amazonaws.com" |
| 1 | +import { getToken, getApiRegion } from "./kiro-auth" |
4 | 2 |
|
5 | 3 | export function getQuota(): Promise< |
6 | 4 | { currentUsage: number; usageLimit: number; subscriptionTitle: string } | undefined |
7 | 5 | > { |
8 | 6 | return getToken().then((token) => { |
9 | 7 | if (!token) return undefined |
10 | | - return fetch( |
11 | | - `${ENDPOINT}/getUsageLimits?origin=AI_EDITOR&resourceType=AGENTIC_REQUEST`, |
12 | | - { |
13 | | - method: "GET", |
14 | | - headers: { |
15 | | - Authorization: `Bearer ${token}`, |
16 | | - "Content-Type": "application/json", |
17 | | - "User-Agent": |
18 | | - "aws-sdk-js/1.0.27 ua/2.1 os/darwin lang/js api/codewhispererstreaming#1.0.27 m/E Kiro-opencode", |
19 | | - "x-amz-user-agent": "aws-sdk-js/1.0.27 Kiro-opencode", |
20 | | - "x-amzn-codewhisperer-optout": "true", |
21 | | - "x-amzn-kiro-agent-mode": "vibe", |
| 8 | + return getApiRegion().then((region) => |
| 9 | + fetch( |
| 10 | + `https://q.${region}.amazonaws.com/getUsageLimits?origin=AI_EDITOR&resourceType=AGENTIC_REQUEST`, |
| 11 | + { |
| 12 | + method: "GET", |
| 13 | + headers: { |
| 14 | + Authorization: `Bearer ${token}`, |
| 15 | + "Content-Type": "application/json", |
| 16 | + "User-Agent": |
| 17 | + "aws-sdk-js/1.0.27 ua/2.1 os/darwin lang/js api/codewhispererstreaming#1.0.27 m/E Kiro-opencode", |
| 18 | + "x-amz-user-agent": "aws-sdk-js/1.0.27 Kiro-opencode", |
| 19 | + "x-amzn-codewhisperer-optout": "true", |
| 20 | + "x-amzn-kiro-agent-mode": "vibe", |
| 21 | + }, |
22 | 22 | }, |
23 | | - }, |
24 | | - ) |
25 | | - .then((response) => { |
26 | | - if (!response.ok) return undefined |
27 | | - return response.json() as Promise<{ |
28 | | - subscriptionInfo: { |
29 | | - subscriptionTitle: string |
30 | | - } |
31 | | - usageBreakdownList: Array<{ |
32 | | - currentUsage: number |
33 | | - currentUsageWithPrecision: number |
34 | | - usageLimit: number |
35 | | - usageLimitWithPrecision: number |
| 23 | + ) |
| 24 | + .then((response) => { |
| 25 | + if (!response.ok) return undefined |
| 26 | + return response.json() as Promise<{ |
| 27 | + subscriptionInfo: { |
| 28 | + subscriptionTitle: string |
| 29 | + } |
| 30 | + usageBreakdownList: Array<{ |
| 31 | + currentUsage: number |
| 32 | + currentUsageWithPrecision: number |
| 33 | + usageLimit: number |
| 34 | + usageLimitWithPrecision: number |
| 35 | + }> |
36 | 36 | }> |
37 | | - }> |
38 | | - }) |
39 | | - .then((body) => { |
40 | | - if (!body) return undefined |
41 | | - const item = body.usageBreakdownList[0] |
42 | | - if (!item) return undefined |
43 | | - return { |
44 | | - currentUsage: item.currentUsageWithPrecision ?? item.currentUsage, |
45 | | - usageLimit: item.usageLimitWithPrecision ?? item.usageLimit, |
46 | | - subscriptionTitle: body.subscriptionInfo.subscriptionTitle |
47 | | - .toLowerCase() |
48 | | - .replace(/\b\w/g, (c) => c.toUpperCase()), |
49 | | - } |
50 | | - }) |
51 | | - .catch(() => undefined) |
| 37 | + }) |
| 38 | + .then((body) => { |
| 39 | + if (!body) return undefined |
| 40 | + const item = body.usageBreakdownList[0] |
| 41 | + if (!item) return undefined |
| 42 | + return { |
| 43 | + currentUsage: item.currentUsageWithPrecision ?? item.currentUsage, |
| 44 | + usageLimit: item.usageLimitWithPrecision ?? item.usageLimit, |
| 45 | + subscriptionTitle: body.subscriptionInfo.subscriptionTitle |
| 46 | + .toLowerCase() |
| 47 | + .replace(/\b\w/g, (c) => c.toUpperCase()), |
| 48 | + } |
| 49 | + }) |
| 50 | + .catch(() => undefined), |
| 51 | + ) |
52 | 52 | }) |
53 | 53 | } |
0 commit comments