opencode-enhancer 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/providers/auth.d.ts +1 -1
- package/dist/providers/auth.d.ts.map +1 -1
- package/dist/providers/auth.js +56 -48
- package/dist/providers/auth.js.map +1 -1
- package/dist/providers/chutes.d.ts +1 -1
- package/dist/providers/chutes.d.ts.map +1 -1
- package/dist/providers/chutes.js +19 -16
- package/dist/providers/chutes.js.map +1 -1
- package/dist/providers/codex.d.ts +1 -1
- package/dist/providers/codex.d.ts.map +1 -1
- package/dist/providers/codex.js +54 -35
- package/dist/providers/codex.js.map +1 -1
- package/dist/providers/copilot.d.ts +1 -1
- package/dist/providers/copilot.d.ts.map +1 -1
- package/dist/providers/copilot.js +92 -60
- package/dist/providers/copilot.js.map +1 -1
- package/dist/providers/types.d.ts +8 -4
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/providers/zai.d.ts +1 -1
- package/dist/providers/zai.d.ts.map +1 -1
- package/dist/providers/zai.js +29 -21
- package/dist/providers/zai.js.map +1 -1
- package/dist/usage-command.d.ts.map +1 -1
- package/dist/usage-command.js +390 -112
- package/dist/usage-command.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/providers/auth.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/providers/auth.ts"],"names":[],"mappings":"AAUA,UAAU,eAAe;IACvB,IAAI,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/providers/auth.ts"],"names":[],"mappings":"AAUA,UAAU,eAAe;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA8ID,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK7D;AAED,oDAAoD;AACpD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKpE;AAED,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAK3E;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQzD;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOlD;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAGD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;AAyBD,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAqClE"}
|
package/dist/providers/auth.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
// Read auth tokens from OpenCode's auth.json file
|
|
2
2
|
// Located at ~/.local/share/opencode/auth.json (XDG_DATA_HOME/opencode/auth.json)
|
|
3
|
-
import { readFileSync, existsSync } from
|
|
4
|
-
import { createRequire } from
|
|
5
|
-
import { join } from
|
|
6
|
-
import { homedir } from
|
|
3
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
let cachedAuth = null;
|
|
9
9
|
let cacheTimestamp = 0;
|
|
10
10
|
const CACHE_TTL_MS = 10_000; // 10 seconds
|
|
11
11
|
const AUTH_KEY_ALIASES = {
|
|
12
|
-
opencode: [
|
|
13
|
-
|
|
14
|
-
google: [
|
|
15
|
-
|
|
12
|
+
opencode: ["opencode-go"],
|
|
13
|
+
"opencode-go": ["opencode"],
|
|
14
|
+
google: ["google.oauth"],
|
|
15
|
+
"google.oauth": ["google"],
|
|
16
16
|
};
|
|
17
17
|
function getAuthFileCandidates() {
|
|
18
|
-
const xdgData = process.env.XDG_DATA_HOME || join(homedir(),
|
|
19
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(),
|
|
18
|
+
const xdgData = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
|
|
19
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
20
20
|
const candidates = [
|
|
21
|
-
join(xdgData,
|
|
22
|
-
join(xdgData,
|
|
23
|
-
join(xdgConfig,
|
|
24
|
-
join(xdgConfig,
|
|
21
|
+
join(xdgData, "opencode", "auth.json"),
|
|
22
|
+
join(xdgData, "opencode", "auth.js"),
|
|
23
|
+
join(xdgConfig, "opencode", "auth.json"),
|
|
24
|
+
join(xdgConfig, "opencode", "auth.js"),
|
|
25
25
|
];
|
|
26
26
|
return [...new Set(candidates)];
|
|
27
27
|
}
|
|
28
28
|
function getAuthFilePath() {
|
|
29
|
-
return getAuthFileCandidates().find((filePath) => existsSync(filePath)) || getAuthFileCandidates()[0];
|
|
29
|
+
return (getAuthFileCandidates().find((filePath) => existsSync(filePath)) || getAuthFileCandidates()[0]);
|
|
30
30
|
}
|
|
31
31
|
function parseAuthObject(value) {
|
|
32
|
-
if (!value || typeof value !==
|
|
32
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
33
33
|
return undefined;
|
|
34
34
|
return value;
|
|
35
35
|
}
|
|
@@ -37,11 +37,13 @@ function parseAuthJsSource(raw) {
|
|
|
37
37
|
const trimmed = raw.trim();
|
|
38
38
|
const candidates = [
|
|
39
39
|
trimmed,
|
|
40
|
-
trimmed.replace(/^export\s+default\s+/,
|
|
41
|
-
trimmed.replace(/^module\.exports\s*=\s*/,
|
|
40
|
+
trimmed.replace(/^export\s+default\s+/, "").replace(/;\s*$/, ""),
|
|
41
|
+
trimmed.replace(/^module\.exports\s*=\s*/, "").replace(/;\s*$/, ""),
|
|
42
42
|
];
|
|
43
43
|
for (const candidate of candidates) {
|
|
44
|
-
if (!candidate ||
|
|
44
|
+
if (!candidate ||
|
|
45
|
+
(candidate === trimmed &&
|
|
46
|
+
(trimmed.startsWith("export ") || trimmed.startsWith("module.exports")))) {
|
|
45
47
|
continue;
|
|
46
48
|
}
|
|
47
49
|
try {
|
|
@@ -58,7 +60,7 @@ function parseAuthJsSource(raw) {
|
|
|
58
60
|
}
|
|
59
61
|
function loadAuthFromPath(filePath) {
|
|
60
62
|
try {
|
|
61
|
-
const raw = readFileSync(filePath,
|
|
63
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
62
64
|
const fromJson = parseAuthObject(JSON.parse(raw));
|
|
63
65
|
if (fromJson)
|
|
64
66
|
return fromJson;
|
|
@@ -66,7 +68,7 @@ function loadAuthFromPath(filePath) {
|
|
|
66
68
|
catch {
|
|
67
69
|
// Fall through to .js parsing / require below.
|
|
68
70
|
}
|
|
69
|
-
if (!filePath.endsWith(
|
|
71
|
+
if (!filePath.endsWith(".js"))
|
|
70
72
|
return undefined;
|
|
71
73
|
try {
|
|
72
74
|
const resolved = require.resolve(filePath);
|
|
@@ -80,7 +82,7 @@ function loadAuthFromPath(filePath) {
|
|
|
80
82
|
// Fall through to raw object-literal parsing.
|
|
81
83
|
}
|
|
82
84
|
try {
|
|
83
|
-
const raw = readFileSync(filePath,
|
|
85
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
84
86
|
return parseAuthJsSource(raw);
|
|
85
87
|
}
|
|
86
88
|
catch {
|
|
@@ -123,7 +125,7 @@ function loadAuthFile() {
|
|
|
123
125
|
export function getOAuthToken(key) {
|
|
124
126
|
const auth = loadAuthFile();
|
|
125
127
|
const cred = getCredential(auth, key);
|
|
126
|
-
if (!cred || cred.type !==
|
|
128
|
+
if (!cred || cred.type !== "oauth")
|
|
127
129
|
return undefined;
|
|
128
130
|
return cred.access || undefined;
|
|
129
131
|
}
|
|
@@ -131,7 +133,7 @@ export function getOAuthToken(key) {
|
|
|
131
133
|
export function getOAuthRefreshToken(key) {
|
|
132
134
|
const auth = loadAuthFile();
|
|
133
135
|
const cred = getCredential(auth, key);
|
|
134
|
-
if (!cred || cred.type !==
|
|
136
|
+
if (!cred || cred.type !== "oauth")
|
|
135
137
|
return undefined;
|
|
136
138
|
return cred.refresh || undefined;
|
|
137
139
|
}
|
|
@@ -139,7 +141,7 @@ export function getOAuthRefreshToken(key) {
|
|
|
139
141
|
export function getOAuthCredential(key) {
|
|
140
142
|
const auth = loadAuthFile();
|
|
141
143
|
const cred = getCredential(auth, key);
|
|
142
|
-
if (!cred || cred.type !==
|
|
144
|
+
if (!cred || cred.type !== "oauth")
|
|
143
145
|
return undefined;
|
|
144
146
|
return cred;
|
|
145
147
|
}
|
|
@@ -149,10 +151,10 @@ export function getApiKey(key) {
|
|
|
149
151
|
const cred = getCredential(auth, key);
|
|
150
152
|
if (!cred)
|
|
151
153
|
return undefined;
|
|
152
|
-
if (cred.type ===
|
|
154
|
+
if (cred.type === "apikey" || cred.type === "api")
|
|
153
155
|
return cred.key || undefined;
|
|
154
156
|
// Some providers may store key in access field with oauth type
|
|
155
|
-
if (cred.type ===
|
|
157
|
+
if (cred.type === "oauth")
|
|
156
158
|
return cred.access || undefined;
|
|
157
159
|
return undefined;
|
|
158
160
|
}
|
|
@@ -162,9 +164,9 @@ export function hasCredential(key) {
|
|
|
162
164
|
const cred = getCredential(auth, key);
|
|
163
165
|
if (!cred)
|
|
164
166
|
return false;
|
|
165
|
-
if (cred.type ===
|
|
167
|
+
if (cred.type === "apikey" || cred.type === "api")
|
|
166
168
|
return !!cred.key;
|
|
167
|
-
if (cred.type ===
|
|
169
|
+
if (cred.type === "oauth")
|
|
168
170
|
return !!cred.access;
|
|
169
171
|
return false;
|
|
170
172
|
}
|
|
@@ -177,27 +179,41 @@ export function invalidateAuthCache() {
|
|
|
177
179
|
export function getAuthPath() {
|
|
178
180
|
return getAuthFilePath();
|
|
179
181
|
}
|
|
182
|
+
function buildGeminiOAuthCreds(refreshToken, clientId, clientSecret) {
|
|
183
|
+
const resolvedClientId = clientId ||
|
|
184
|
+
process.env.OPENCODE_ENHANCER_GOOGLE_CLIENT_ID ||
|
|
185
|
+
process.env.OPENCODE_MULTI_AUTH_GOOGLE_CLIENT_ID;
|
|
186
|
+
const resolvedClientSecret = clientSecret ||
|
|
187
|
+
process.env.OPENCODE_ENHANCER_GOOGLE_CLIENT_SECRET ||
|
|
188
|
+
process.env.OPENCODE_MULTI_AUTH_GOOGLE_CLIENT_SECRET;
|
|
189
|
+
if (!resolvedClientId || !resolvedClientSecret)
|
|
190
|
+
return undefined;
|
|
191
|
+
return {
|
|
192
|
+
client_id: resolvedClientId,
|
|
193
|
+
client_secret: resolvedClientSecret,
|
|
194
|
+
refresh_token: refreshToken,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
180
197
|
export function getGeminiOAuthCreds() {
|
|
181
198
|
// Try multiple locations
|
|
182
199
|
const paths = [
|
|
183
|
-
join(homedir(),
|
|
184
|
-
join(homedir(),
|
|
200
|
+
join(homedir(), ".gemini", "oauth_creds.json"),
|
|
201
|
+
join(homedir(), ".config", "opencode", "antigravity-accounts.json"),
|
|
185
202
|
];
|
|
186
203
|
for (const p of paths) {
|
|
187
204
|
if (!existsSync(p))
|
|
188
205
|
continue;
|
|
189
206
|
try {
|
|
190
|
-
const raw = readFileSync(p,
|
|
207
|
+
const raw = readFileSync(p, "utf-8");
|
|
191
208
|
const parsed = JSON.parse(raw);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return parsed;
|
|
209
|
+
if (parsed.refresh_token) {
|
|
210
|
+
return buildGeminiOAuthCreds(parsed.refresh_token, parsed.client_id, parsed.client_secret);
|
|
195
211
|
}
|
|
196
212
|
// Antigravity accounts format — take first account
|
|
197
213
|
if (Array.isArray(parsed)) {
|
|
198
214
|
const first = parsed[0];
|
|
199
|
-
if (first?.
|
|
200
|
-
return first;
|
|
215
|
+
if (first?.refresh_token) {
|
|
216
|
+
return buildGeminiOAuthCreds(first.refresh_token, first.client_id, first.client_secret);
|
|
201
217
|
}
|
|
202
218
|
}
|
|
203
219
|
}
|
|
@@ -207,17 +223,9 @@ export function getGeminiOAuthCreds() {
|
|
|
207
223
|
}
|
|
208
224
|
// Also check opencode auth.json for google.oauth
|
|
209
225
|
const auth = loadAuthFile();
|
|
210
|
-
const googleOAuth = auth[
|
|
211
|
-
if (googleOAuth && googleOAuth.type ===
|
|
212
|
-
|
|
213
|
-
const clientSecret = process.env.OPENCODE_ENHANCER_GOOGLE_CLIENT_SECRET || process.env.OPENCODE_MULTI_AUTH_GOOGLE_CLIENT_SECRET || '';
|
|
214
|
-
if (!clientId || !clientSecret)
|
|
215
|
-
return undefined;
|
|
216
|
-
return {
|
|
217
|
-
client_id: clientId,
|
|
218
|
-
client_secret: clientSecret,
|
|
219
|
-
refresh_token: googleOAuth.refresh,
|
|
220
|
-
};
|
|
226
|
+
const googleOAuth = auth["google.oauth"] || auth["google"];
|
|
227
|
+
if (googleOAuth && googleOAuth.type === "oauth" && googleOAuth.refresh) {
|
|
228
|
+
return buildGeminiOAuthCreds(googleOAuth.refresh);
|
|
221
229
|
}
|
|
222
230
|
return undefined;
|
|
223
231
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/providers/auth.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,kFAAkF;AAElF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/providers/auth.ts"],"names":[],"mappings":"AAA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d.ts","sourceRoot":"","sources":["../../src/providers/chutes.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAkB,aAAa,EAAe,MAAM,YAAY,CAAC;AAiB7E,eAAO,MAAM,cAAc,EAAE,aAwG5B,CAAC"}
|
package/dist/providers/chutes.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
// Quotas: GET https://api.chutes.ai/users/me/quotas
|
|
4
4
|
// Usage: GET https://api.chutes.ai/users/me/quota_usage/{chute_id}
|
|
5
5
|
// Auth: raw key in Authorization header (no Bearer prefix)
|
|
6
|
-
import { getApiKey, hasCredential } from
|
|
7
|
-
import { fetchWithTimeout } from
|
|
8
|
-
const AUTH_KEY =
|
|
9
|
-
const BASE_URL =
|
|
6
|
+
import { getApiKey, hasCredential } from "./auth.js";
|
|
7
|
+
import { fetchWithTimeout } from "./types.js";
|
|
8
|
+
const AUTH_KEY = "chutes";
|
|
9
|
+
const BASE_URL = "https://api.chutes.ai";
|
|
10
10
|
export const chutesProvider = {
|
|
11
|
-
id:
|
|
12
|
-
name:
|
|
13
|
-
billingType:
|
|
11
|
+
id: "chutes",
|
|
12
|
+
name: "Chutes AI",
|
|
13
|
+
billingType: "quotaBased",
|
|
14
14
|
async isConfigured() {
|
|
15
15
|
return hasCredential(AUTH_KEY);
|
|
16
16
|
},
|
|
@@ -21,7 +21,7 @@ export const chutesProvider = {
|
|
|
21
21
|
providerId: this.id,
|
|
22
22
|
providerName: this.name,
|
|
23
23
|
billingType: this.billingType,
|
|
24
|
-
status:
|
|
24
|
+
status: "not_configured",
|
|
25
25
|
fetchedAt: Date.now(),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -30,12 +30,12 @@ export const chutesProvider = {
|
|
|
30
30
|
// Fetch quotas
|
|
31
31
|
const quotasRes = await fetchWithTimeout(`${BASE_URL}/users/me/quotas`, { headers });
|
|
32
32
|
if (!quotasRes.ok) {
|
|
33
|
-
const text = await quotasRes.text().catch(() =>
|
|
33
|
+
const text = await quotasRes.text().catch(() => "");
|
|
34
34
|
return {
|
|
35
35
|
providerId: this.id,
|
|
36
36
|
providerName: this.name,
|
|
37
37
|
billingType: this.billingType,
|
|
38
|
-
status: quotasRes.status === 401 || quotasRes.status === 403 ?
|
|
38
|
+
status: quotasRes.status === 401 || quotasRes.status === 403 ? "auth_expired" : "error",
|
|
39
39
|
error: `HTTP ${quotasRes.status}: ${text.slice(0, 200)}`,
|
|
40
40
|
fetchedAt: Date.now(),
|
|
41
41
|
};
|
|
@@ -47,8 +47,8 @@ export const chutesProvider = {
|
|
|
47
47
|
providerId: this.id,
|
|
48
48
|
providerName: this.name,
|
|
49
49
|
billingType: this.billingType,
|
|
50
|
-
status:
|
|
51
|
-
usage: { type:
|
|
50
|
+
status: "ok",
|
|
51
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
52
52
|
fetchedAt: Date.now(),
|
|
53
53
|
};
|
|
54
54
|
}
|
|
@@ -59,21 +59,24 @@ export const chutesProvider = {
|
|
|
59
59
|
if (usageRes.ok) {
|
|
60
60
|
const usage = (await usageRes.json());
|
|
61
61
|
utilization = usage.quota > 0 ? (usage.used / usage.quota) * 100 : 0;
|
|
62
|
+
const remaining = usage.quota > 0 ? Math.max(0, usage.quota - usage.used) : undefined;
|
|
62
63
|
windows.push({
|
|
63
64
|
utilization,
|
|
64
65
|
resetsAt: defaultQuota.payment_refresh_date
|
|
65
66
|
? new Date(defaultQuota.payment_refresh_date).getTime()
|
|
66
67
|
: undefined,
|
|
67
|
-
label:
|
|
68
|
+
label: "monthly",
|
|
69
|
+
remaining,
|
|
70
|
+
entitlement: usage.quota,
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
return {
|
|
71
74
|
providerId: this.id,
|
|
72
75
|
providerName: this.name,
|
|
73
76
|
billingType: this.billingType,
|
|
74
|
-
status:
|
|
77
|
+
status: "ok",
|
|
75
78
|
usage: {
|
|
76
|
-
type:
|
|
79
|
+
type: "quotaBased",
|
|
77
80
|
utilization,
|
|
78
81
|
remaining: defaultQuota.quota
|
|
79
82
|
? Math.max(0, defaultQuota.quota - (utilization * defaultQuota.quota) / 100)
|
|
@@ -89,7 +92,7 @@ export const chutesProvider = {
|
|
|
89
92
|
providerId: this.id,
|
|
90
93
|
providerName: this.name,
|
|
91
94
|
billingType: this.billingType,
|
|
92
|
-
status:
|
|
95
|
+
status: "error",
|
|
93
96
|
error: `${err}`,
|
|
94
97
|
fetchedAt: Date.now(),
|
|
95
98
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chutes.js","sourceRoot":"","sources":["../../src/providers/chutes.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,8CAA8C;AAC9C,oDAAoD;AACpD,mEAAmE;AACnE,2DAA2D;AAE3D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"chutes.js","sourceRoot":"","sources":["../../src/providers/chutes.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,8CAA8C;AAC9C,oDAAoD;AACpD,mEAAmE;AACnE,2DAA2D;AAE3D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAC1B,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAczC,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,EAAE,EAAE,QAAQ;IACZ,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,YAAY;IAEzB,KAAK,CAAC,YAAY;QAChB,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,EAAE;g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KAAK,CAAC,KAAK;iBACzB,CAAC,CAAC;YACL,CAAC;YAED,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,EAAE;gBACnB,YAAY,EAAE,IAAI,CAAC,IAAI;gBACvB,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE;oBACL,IAAI,EAAE,YAAY;oBAClB,WAAW;oBACX,SAAS,EAAE,YAAY,CAAC,KAAK;wBAC3B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,KAAK,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;wBAC5E,CAAC,CAAC,SAAS;oBACb,WAAW,EAAE,YAAY,CAAC,KAAK;oBAC/B,OAAO;iBACR;gBACD,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,EAAE;gBACnB,YAAY,EAAE,IAAI,CAAC,IAAI;gBACvB,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,GAAG,GAAG,EAAE;gBACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/providers/codex.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAyC,aAAa,EAAe,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/providers/codex.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAyC,aAAa,EAAe,MAAM,YAAY,CAAC;AAEpG,eAAO,MAAM,aAAa,EAAE,aA2L3B,CAAC"}
|
package/dist/providers/codex.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// ChatGPT / Codex usage provider
|
|
2
2
|
// Uses the existing multi-account store and wham/usage API
|
|
3
3
|
// Endpoint: GET https://chatgpt.com/backend-api/wham/usage
|
|
4
|
-
import { loadStore, listAccounts } from
|
|
5
|
-
import { fetchUsageRateLimitsForAccount } from
|
|
4
|
+
import { loadStore, listAccounts } from "../store.js";
|
|
5
|
+
import { fetchUsageRateLimitsForAccount } from "../usage-limits.js";
|
|
6
6
|
export const codexProvider = {
|
|
7
|
-
id:
|
|
8
|
-
name:
|
|
9
|
-
billingType:
|
|
7
|
+
id: "codex",
|
|
8
|
+
name: "Codex",
|
|
9
|
+
billingType: "quotaBased",
|
|
10
10
|
async isConfigured() {
|
|
11
11
|
const accounts = listAccounts();
|
|
12
12
|
return accounts.length > 0;
|
|
@@ -19,7 +19,7 @@ export const codexProvider = {
|
|
|
19
19
|
providerId: this.id,
|
|
20
20
|
providerName: this.name,
|
|
21
21
|
billingType: this.billingType,
|
|
22
|
-
status:
|
|
22
|
+
status: "not_configured",
|
|
23
23
|
fetchedAt: Date.now(),
|
|
24
24
|
};
|
|
25
25
|
}
|
|
@@ -31,9 +31,9 @@ export const codexProvider = {
|
|
|
31
31
|
label: acc.alias,
|
|
32
32
|
email: acc.email,
|
|
33
33
|
plan: acc.planType,
|
|
34
|
-
status:
|
|
35
|
-
error:
|
|
36
|
-
usage: { type:
|
|
34
|
+
status: "error",
|
|
35
|
+
error: "Account disabled",
|
|
36
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
// Skip auth-invalid accounts
|
|
@@ -42,9 +42,9 @@ export const codexProvider = {
|
|
|
42
42
|
label: acc.alias,
|
|
43
43
|
email: acc.email,
|
|
44
44
|
plan: acc.planType,
|
|
45
|
-
status:
|
|
46
|
-
error:
|
|
47
|
-
usage: { type:
|
|
45
|
+
status: "auth_expired",
|
|
46
|
+
error: "Auth invalid",
|
|
47
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
try {
|
|
@@ -54,9 +54,9 @@ export const codexProvider = {
|
|
|
54
54
|
label: acc.alias,
|
|
55
55
|
email: acc.email,
|
|
56
56
|
plan: acc.planType,
|
|
57
|
-
status:
|
|
57
|
+
status: "auth_expired",
|
|
58
58
|
error: result.error,
|
|
59
|
-
usage: { type:
|
|
59
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
if (result.error && !result.rateLimits) {
|
|
@@ -64,9 +64,9 @@ export const codexProvider = {
|
|
|
64
64
|
label: acc.alias,
|
|
65
65
|
email: acc.email,
|
|
66
66
|
plan: acc.planType,
|
|
67
|
-
status:
|
|
67
|
+
status: "error",
|
|
68
68
|
error: result.error,
|
|
69
|
-
usage: { type:
|
|
69
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
const windows = [];
|
|
@@ -74,36 +74,50 @@ export const codexProvider = {
|
|
|
74
74
|
const wk = result.rateLimits?.weekly;
|
|
75
75
|
if (fh?.remaining !== undefined) {
|
|
76
76
|
const fhLimit = fh.limit ?? 100;
|
|
77
|
+
const hasAbsoluteFiveHourLimit = typeof fh.limit === "number" && fh.limit !== 100;
|
|
77
78
|
windows.push({
|
|
78
|
-
utilization: fhLimit === 100
|
|
79
|
+
utilization: fhLimit === 100
|
|
80
|
+
? Math.max(0, 100 - fh.remaining)
|
|
81
|
+
: Math.max(0, Math.round(((fhLimit - fh.remaining) / fhLimit) * 100)),
|
|
79
82
|
resetsAt: fh.resetAt,
|
|
80
|
-
label:
|
|
83
|
+
label: "5h",
|
|
84
|
+
remaining: hasAbsoluteFiveHourLimit ? fh.remaining : undefined,
|
|
85
|
+
entitlement: hasAbsoluteFiveHourLimit ? fh.limit : undefined,
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
if (wk?.remaining !== undefined) {
|
|
84
89
|
const wkLimit = wk.limit ?? 100;
|
|
90
|
+
const hasAbsoluteWeeklyLimit = typeof wk.limit === "number" && wk.limit !== 100;
|
|
85
91
|
windows.push({
|
|
86
|
-
utilization: wkLimit === 100
|
|
92
|
+
utilization: wkLimit === 100
|
|
93
|
+
? Math.max(0, 100 - wk.remaining)
|
|
94
|
+
: Math.max(0, Math.round(((wkLimit - wk.remaining) / wkLimit) * 100)),
|
|
87
95
|
resetsAt: wk.resetAt,
|
|
88
|
-
label:
|
|
96
|
+
label: "weekly",
|
|
97
|
+
remaining: hasAbsoluteWeeklyLimit ? wk.remaining : undefined,
|
|
98
|
+
entitlement: hasAbsoluteWeeklyLimit ? wk.limit : undefined,
|
|
89
99
|
});
|
|
90
100
|
}
|
|
91
101
|
const fhLimit = fh?.limit ?? 100;
|
|
92
102
|
const wkLimit = wk?.limit ?? 100;
|
|
93
103
|
const fhUtil = fh?.remaining !== undefined
|
|
94
|
-
?
|
|
104
|
+
? fhLimit === 100
|
|
105
|
+
? 100 - fh.remaining
|
|
106
|
+
: ((fhLimit - fh.remaining) / fhLimit) * 100
|
|
95
107
|
: 0;
|
|
96
108
|
const wkUtil = wk?.remaining !== undefined
|
|
97
|
-
?
|
|
109
|
+
? wkLimit === 100
|
|
110
|
+
? 100 - wk.remaining
|
|
111
|
+
: ((wkLimit - wk.remaining) / wkLimit) * 100
|
|
98
112
|
: 0;
|
|
99
113
|
const primaryUtil = Math.max(0, fhUtil, wkUtil);
|
|
100
114
|
return {
|
|
101
115
|
label: acc.alias,
|
|
102
116
|
email: acc.email,
|
|
103
117
|
plan: acc.planType,
|
|
104
|
-
status:
|
|
118
|
+
status: "ok",
|
|
105
119
|
usage: {
|
|
106
|
-
type:
|
|
120
|
+
type: "quotaBased",
|
|
107
121
|
utilization: primaryUtil,
|
|
108
122
|
windows,
|
|
109
123
|
},
|
|
@@ -114,37 +128,42 @@ export const codexProvider = {
|
|
|
114
128
|
label: acc.alias,
|
|
115
129
|
email: acc.email,
|
|
116
130
|
plan: acc.planType,
|
|
117
|
-
status:
|
|
131
|
+
status: "error",
|
|
118
132
|
error: `${err}`,
|
|
119
|
-
usage: { type:
|
|
133
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
120
134
|
};
|
|
121
135
|
}
|
|
122
136
|
}));
|
|
123
|
-
const accountResults = results.map((r) => r.status ===
|
|
137
|
+
const accountResults = results.map((r) => r.status === "fulfilled"
|
|
124
138
|
? r.value
|
|
125
139
|
: {
|
|
126
|
-
label:
|
|
127
|
-
status:
|
|
140
|
+
label: "?",
|
|
141
|
+
status: "error",
|
|
128
142
|
error: `${r.reason}`,
|
|
129
|
-
usage: { type:
|
|
143
|
+
usage: { type: "quotaBased", utilization: 0, windows: [] },
|
|
130
144
|
});
|
|
131
145
|
// Overall status: ok if any account succeeded
|
|
132
|
-
const anyOk = accountResults.some((a) => a.status ===
|
|
133
|
-
const okAccounts = accountResults.filter((a) => a.status ===
|
|
146
|
+
const anyOk = accountResults.some((a) => a.status === "ok");
|
|
147
|
+
const okAccounts = accountResults.filter((a) => a.status === "ok");
|
|
134
148
|
// Aggregate usage: take the best (lowest utilization) account
|
|
135
149
|
let aggregateUsage = undefined;
|
|
136
150
|
if (okAccounts.length > 0) {
|
|
137
|
-
const best = okAccounts.reduce((a, b) => a.usage.utilization < b.usage.utilization ? a : b);
|
|
151
|
+
const best = okAccounts.reduce((a, b) => (a.usage.utilization < b.usage.utilization ? a : b));
|
|
138
152
|
aggregateUsage = best.usage;
|
|
139
153
|
}
|
|
140
154
|
return {
|
|
141
155
|
providerId: this.id,
|
|
142
156
|
providerName: this.name,
|
|
143
157
|
billingType: this.billingType,
|
|
144
|
-
status: anyOk ?
|
|
158
|
+
status: anyOk ? "ok" : "error",
|
|
145
159
|
usage: aggregateUsage,
|
|
146
160
|
accounts: accountResults,
|
|
147
|
-
error: anyOk
|
|
161
|
+
error: anyOk
|
|
162
|
+
? undefined
|
|
163
|
+
: accountResults
|
|
164
|
+
.map((a) => a.error)
|
|
165
|
+
.filter(Boolean)
|
|
166
|
+
.join("; "),
|
|
148
167
|
fetchedAt: Date.now(),
|
|
149
168
|
};
|
|
150
169
|
},
|