dsh-model-allowance 1.2.0 → 1.2.1
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 +3 -3
- package/README.zh.md +3 -3
- package/client.js +5 -0
- package/lib/providers/openai_codex.js +334 -0
- package/lib/providers.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,10 +58,10 @@ their models stay switchable.
|
|
|
58
58
|
2. Choose **Install** and enter:
|
|
59
59
|
|
|
60
60
|
```
|
|
61
|
-
dsh-model-allowance@1.2.
|
|
61
|
+
dsh-model-allowance@1.2.1
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
Use the latest published version instead of `1.2.
|
|
64
|
+
Use the latest published version instead of `1.2.1` when a newer one
|
|
65
65
|
exists.
|
|
66
66
|
3. Confirm the installation. If DSH reports **restart required**, restart
|
|
67
67
|
DSH; otherwise refresh the page.
|
|
@@ -71,7 +71,7 @@ The npm installation is eligible for the Plugin Manager's **Update** action.
|
|
|
71
71
|
### Install from GitHub
|
|
72
72
|
|
|
73
73
|
```
|
|
74
|
-
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.2.
|
|
74
|
+
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.2.1
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Git installations are not covered by the Plugin Manager's **Update** action;
|
package/README.zh.md
CHANGED
|
@@ -49,10 +49,10 @@ Token Plan 用量查询用的阿里云 AccessKey ID/Secret)。可测试的凭
|
|
|
49
49
|
2. 点击 **Install(安装)**,填入:
|
|
50
50
|
|
|
51
51
|
```
|
|
52
|
-
dsh-model-allowance@1.2.
|
|
52
|
+
dsh-model-allowance@1.2.1
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
如果已有更新版本,请把 `1.2.
|
|
55
|
+
如果已有更新版本,请把 `1.2.1` 换成最新的精确版本。
|
|
56
56
|
3. 确认安装。如果 DSH 提示需要重启,重启 DSH;否则刷新页面即可。
|
|
57
57
|
|
|
58
58
|
通过 npm 安装的版本可以在 Plugin Manager 中使用 **Update** 更新。
|
|
@@ -60,7 +60,7 @@ Token Plan 用量查询用的阿里云 AccessKey ID/Secret)。可测试的凭
|
|
|
60
60
|
### 从 GitHub 安装
|
|
61
61
|
|
|
62
62
|
```
|
|
63
|
-
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.2.
|
|
63
|
+
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.2.1
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Git 安装不受 Plugin Manager 的 **Update** 管理;更新时需要先移除旧版本,
|
package/client.js
CHANGED
|
@@ -283,6 +283,7 @@ var QWEN_GRADIENT_STOPS = [
|
|
|
283
283
|
["#082DFF", "0"],
|
|
284
284
|
["#3FD2F9", "1"]
|
|
285
285
|
];
|
|
286
|
+
var OPENAI_PATH = "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z";
|
|
286
287
|
var XIAOMI_PATHS = [
|
|
287
288
|
"M73.7449 15.9987C73.4083 15.998 73.0857 15.8638 72.8479 15.6256C72.6101 15.3873 72.4766 15.0644 72.4766 14.7278V7.165C72.4914 6.83757 72.632 6.52848 72.869 6.30203C73.1059 6.07559 73.4211 5.94922 73.7488 5.94922C74.0766 5.94922 74.3918 6.07559 74.6287 6.30203C74.8657 6.52848 75.0062 6.83757 75.0211 7.165V14.7278C75.0208 14.895 74.9875 15.0606 74.9232 15.215C74.8588 15.3693 74.7647 15.5095 74.6462 15.6276C74.5277 15.7456 74.3871 15.8391 74.2325 15.9028C74.0778 15.9665 73.9122 15.9991 73.7449 15.9987Z",
|
|
288
289
|
"M87.3607 15.9993C87.0234 15.9993 86.6998 15.8655 86.4611 15.6272C86.2223 15.389 86.0878 15.0657 86.0871 14.7284V4.67881L81.4654 9.45281C81.2304 9.69657 80.9081 9.83697 80.5695 9.84312C80.231 9.84928 79.9038 9.72069 79.6601 9.48563C79.4163 9.25058 79.2759 8.92832 79.2697 8.58976C79.2667 8.42211 79.2967 8.25551 79.358 8.09947C79.4194 7.94342 79.5108 7.80098 79.6272 7.68028L86.4469 0.661082C86.6229 0.478921 86.8494 0.35354 87.0973 0.301033C87.3451 0.248526 87.603 0.271291 87.8378 0.366403C88.0727 0.461516 88.2737 0.624637 88.4151 0.834827C88.5566 1.04502 88.632 1.29268 88.6317 1.54603V14.7284C88.6317 15.0655 88.4978 15.3887 88.2594 15.6271C88.021 15.8654 87.6978 15.9993 87.3607 15.9993Z",
|
|
@@ -298,6 +299,8 @@ var ICON_GEOMETRY = {
|
|
|
298
299
|
kimi: { x: 0, y: 0.94, vbW: 23.95, vbH: 23.25, inkW: 23.95, inkH: 23.25 },
|
|
299
300
|
// OpenCode's logo draws its 240x300 frame from the origin.
|
|
300
301
|
opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 },
|
|
302
|
+
// OpenAI's blossom fills its published 24x24 box edge to edge.
|
|
303
|
+
openai: { x: 0, y: 0, vbW: 24, vbH: 24, inkW: 24, inkH: 24 },
|
|
301
304
|
// Qwen's petals draw 0.42..27.58 across and -0.05..28.05 down, so the
|
|
302
305
|
// published 28x28 box would clip a hair of the outer petals.
|
|
303
306
|
qwen: { x: 0.4155, y: -0.048, vbW: 27.169, vbH: 28.0988, inkW: 27.169, inkH: 28.0988 },
|
|
@@ -399,6 +402,8 @@ function providerIcon(route, inkHeight, mark) {
|
|
|
399
402
|
fillOpacity: path.opacity
|
|
400
403
|
})
|
|
401
404
|
);
|
|
405
|
+
} else if (mark.icon === "openai") {
|
|
406
|
+
content = [(0, import_react.createElement)("path", { key: "openai", d: OPENAI_PATH, fill: "currentColor" })];
|
|
402
407
|
} else if (mark.icon === "xiaomi") {
|
|
403
408
|
content = XIAOMI_PATHS.map(
|
|
404
409
|
(d, index) => (0, import_react.createElement)("path", { key: `xiaomi-${String(index)}`, d, fill: "#1F2329" })
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Codex (ChatGPT subscription) adapter.
|
|
3
|
+
*
|
|
4
|
+
* Shun-mao ("with the grain") by construction:
|
|
5
|
+
* - The data source is the vendor's OWN usage endpoint
|
|
6
|
+
* `GET https://chatgpt.com/backend-api/wham/usage` — the same one the official
|
|
7
|
+
* Codex CLI polls. One cheap metadata GET; it spends no plan quota, runs no
|
|
8
|
+
* inference and bills no turn (even an exhausted plan answers 200).
|
|
9
|
+
* - Authorization reuses the grant the host already owns and refreshes:
|
|
10
|
+
* pi-ai stores the ChatGPT OAuth under the credential record
|
|
11
|
+
* `llm-pi-ai/openai-codex` (kind `grant`, payload {access, refresh, expires,
|
|
12
|
+
* accountId}). This adapter only READS that record; it never refreshes a
|
|
13
|
+
* token itself, never spoofs a browser, and never posts a billed probe.
|
|
14
|
+
* - The request carries the official Codex client headers (bearer +
|
|
15
|
+
* ChatGPT-Account-Id + codex_cli_rs originator), matching what DSH's own
|
|
16
|
+
* pi-ai Codex provider sends.
|
|
17
|
+
*
|
|
18
|
+
* The plan meters a short rolling window (primary, usually 5 h) and a long one
|
|
19
|
+
* (secondary, usually weekly). Each reports `used_percent`; the shared shape
|
|
20
|
+
* carries the share LEFT, so this projects `100 - used_percent`. Window length
|
|
21
|
+
* is read from `limit_window_seconds` rather than assumed, because Plus plans
|
|
22
|
+
* have been seen to report a single seven-day primary window with no secondary.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { asObject, bindingWindow, defineAdapter, KIND_QUOTA, parseAmount } from './shared.js'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The host credential service widened to the record half of the seam: the
|
|
29
|
+
* Codex OAuth is a `grant` record read via readRecord, not an env resolve.
|
|
30
|
+
* @typedef {{ readRecord?: (key: string) => Promise<{ payload?: Record<string, unknown> } | undefined> }} GrantReader
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** The official Codex usage endpoint (same one the Codex CLI polls). */
|
|
34
|
+
const USAGE_ENDPOINT = 'https://chatgpt.com/backend-api/wham/usage'
|
|
35
|
+
|
|
36
|
+
/** Subscription side, where the plan itself lives — not the API billing console. */
|
|
37
|
+
const CONSOLE = 'https://chatgpt.com/'
|
|
38
|
+
|
|
39
|
+
/** pi-ai owns the Codex OAuth grant under this credential scope. */
|
|
40
|
+
const CREDENTIAL_SCOPE = 'llm-pi-ai'
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Name a window length from its duration in seconds, preferring whole weeks for
|
|
44
|
+
* the long window so a 7-day plan reads as "1 week", not "7 days".
|
|
45
|
+
* @param {number | undefined} seconds
|
|
46
|
+
* @returns {{unit: 'hour'|'day'|'week'|'month'|'unknown', count?: number}}
|
|
47
|
+
*/
|
|
48
|
+
function windowShape(seconds) {
|
|
49
|
+
if (seconds === undefined || !Number.isFinite(seconds) || seconds <= 0) return { unit: 'unknown' }
|
|
50
|
+
const hours = seconds / 3600
|
|
51
|
+
if (hours < 24) return { unit: 'hour', count: Math.round(hours) }
|
|
52
|
+
const days = seconds / 86400
|
|
53
|
+
if (days >= 7 && days < 28 && Number.isInteger(days / 7)) return { unit: 'week', count: days / 7 }
|
|
54
|
+
if (days < 28) return { unit: 'day', count: Math.round(days) }
|
|
55
|
+
return { unit: 'month', count: Math.round(days / 30) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Project one rate-limit window onto the shared BalanceWindow shape.
|
|
60
|
+
* @param {unknown} raw The vendor window node.
|
|
61
|
+
* @param {string} id Stable positional identity (`session` / `weekly`).
|
|
62
|
+
* @returns {import('./shared.js').BalanceWindow | undefined}
|
|
63
|
+
*/
|
|
64
|
+
function projectWindow(raw, id) {
|
|
65
|
+
const node = asObject(raw)
|
|
66
|
+
const used = parseAmount(node.used_percent)
|
|
67
|
+
if (used === undefined) return undefined
|
|
68
|
+
const shape = windowShape(parseAmount(node.limit_window_seconds))
|
|
69
|
+
// reset_at is epoch SECONDS; fall back to the relative reset_after_seconds.
|
|
70
|
+
const resetAtSec = parseAmount(node.reset_at)
|
|
71
|
+
const resetAfter = parseAmount(node.reset_after_seconds)
|
|
72
|
+
const resetAt =
|
|
73
|
+
resetAtSec !== undefined
|
|
74
|
+
? resetAtSec * 1000
|
|
75
|
+
: resetAfter !== undefined
|
|
76
|
+
? Date.now() + resetAfter * 1000
|
|
77
|
+
: undefined
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
unit: shape.unit,
|
|
81
|
+
...(shape.count === undefined ? {} : { count: shape.count }),
|
|
82
|
+
remainingPercent: Math.max(0, Math.round((100 - used) * 100) / 100),
|
|
83
|
+
...(resetAt === undefined ? {} : { resetAt }),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Read the Codex subscription rate-limit windows through the host's own grant.
|
|
89
|
+
* @param {import('../providers.js').AdapterEnv} env Query context.
|
|
90
|
+
* @returns {Promise<import('../providers.js').BalanceView>} The reading.
|
|
91
|
+
*/
|
|
92
|
+
async function readCodexUsage({ route, ctx, signal }) {
|
|
93
|
+
const credentials = /** @type {GrantReader | undefined} */ (
|
|
94
|
+
typeof ctx?.get === 'function' ? ctx.get('credentials') : undefined
|
|
95
|
+
)
|
|
96
|
+
if (credentials === undefined || typeof credentials.readRecord !== 'function') {
|
|
97
|
+
return { provider: route, status: 'unconfigured', kind: KIND_QUOTA }
|
|
98
|
+
}
|
|
99
|
+
// The grant key is deterministic from the route: <pi-ai scope>/<route>.
|
|
100
|
+
let record
|
|
101
|
+
try {
|
|
102
|
+
record = await credentials.readRecord(`${CREDENTIAL_SCOPE}/${route}`)
|
|
103
|
+
} catch {
|
|
104
|
+
record = undefined
|
|
105
|
+
}
|
|
106
|
+
const payload = asObject(record?.payload)
|
|
107
|
+
const access = typeof payload.access === 'string' ? payload.access : ''
|
|
108
|
+
const accountId = typeof payload.accountId === 'string' ? payload.accountId : ''
|
|
109
|
+
if (access === '' || accountId === '') {
|
|
110
|
+
return { provider: route, status: 'unconfigured', kind: KIND_QUOTA }
|
|
111
|
+
}
|
|
112
|
+
// Never refresh the token here — the host (pi-ai) owns refresh. An expired
|
|
113
|
+
// grant is reported so the user knows one Codex request will renew it.
|
|
114
|
+
const expires = parseAmount(payload.expires)
|
|
115
|
+
if (expires !== undefined && expires <= Date.now()) {
|
|
116
|
+
return {
|
|
117
|
+
provider: route,
|
|
118
|
+
status: 'failed',
|
|
119
|
+
kind: KIND_QUOTA,
|
|
120
|
+
error: 'Codex 登录态已过期,在 DSH 里用一次 Codex 模型即可自动刷新',
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const response = await fetch(USAGE_ENDPOINT, {
|
|
125
|
+
headers: {
|
|
126
|
+
authorization: `Bearer ${access}`,
|
|
127
|
+
'ChatGPT-Account-Id': accountId,
|
|
128
|
+
'User-Agent': 'codex_cli_rs/0.164.0',
|
|
129
|
+
originator: 'codex_cli_rs',
|
|
130
|
+
accept: 'application/json',
|
|
131
|
+
},
|
|
132
|
+
signal,
|
|
133
|
+
})
|
|
134
|
+
if (response.status === 401 || response.status === 403) {
|
|
135
|
+
return {
|
|
136
|
+
provider: route,
|
|
137
|
+
status: 'failed',
|
|
138
|
+
kind: KIND_QUOTA,
|
|
139
|
+
error: `Codex 授权被拒(HTTP ${String(response.status)}),请重新登录 ChatGPT/Codex`,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!response.ok) {
|
|
143
|
+
return {
|
|
144
|
+
provider: route,
|
|
145
|
+
status: 'failed',
|
|
146
|
+
kind: KIND_QUOTA,
|
|
147
|
+
error: `HTTP ${String(response.status)}`,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const body = asObject(await response.json())
|
|
151
|
+
const rateLimit = asObject(body.rate_limit)
|
|
152
|
+
/** @type {import('./shared.js').BalanceWindow[]} */
|
|
153
|
+
const windows = []
|
|
154
|
+
const primary = projectWindow(rateLimit.primary_window, 'session')
|
|
155
|
+
if (primary !== undefined) windows.push(primary)
|
|
156
|
+
const secondary = projectWindow(rateLimit.secondary_window, 'weekly')
|
|
157
|
+
if (secondary !== undefined) windows.push(secondary)
|
|
158
|
+
if (windows.length === 0) {
|
|
159
|
+
return {
|
|
160
|
+
provider: route,
|
|
161
|
+
status: 'failed',
|
|
162
|
+
kind: KIND_QUOTA,
|
|
163
|
+
error: 'wham/usage 未返回限流窗口(上游接口可能已变更)',
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const binding = bindingWindow(windows)
|
|
167
|
+
return {
|
|
168
|
+
provider: route,
|
|
169
|
+
status: 'ready',
|
|
170
|
+
kind: KIND_QUOTA,
|
|
171
|
+
...(binding?.remainingPercent === undefined ? {} : { percent: binding.remainingPercent }),
|
|
172
|
+
...(binding?.resetAt === undefined ? {} : { resetsAt: binding.resetAt }),
|
|
173
|
+
windows,
|
|
174
|
+
consoleUrl: CONSOLE,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A recorded future expiry so fixtures read as a live grant. */
|
|
179
|
+
const RECORDED_EXPIRES = 4102444800000 // 2100-01-01
|
|
180
|
+
|
|
181
|
+
/** The host grant record, as pi-ai stores it (values recorded, not real). */
|
|
182
|
+
const RECORDED_CREDENTIALS = {
|
|
183
|
+
readRecord: async (key) =>
|
|
184
|
+
key === 'llm-pi-ai/openai-codex'
|
|
185
|
+
? {
|
|
186
|
+
kind: 'grant',
|
|
187
|
+
payload: {
|
|
188
|
+
type: 'oauth',
|
|
189
|
+
access: 'recorded-access',
|
|
190
|
+
refresh: 'recorded-refresh',
|
|
191
|
+
expires: RECORDED_EXPIRES,
|
|
192
|
+
accountId: 'recorded-account',
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
: undefined,
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** An exhausted Plus plan: 5 h window full, weekly window 78 % used. PII stripped. */
|
|
199
|
+
const RECORDED_EXHAUSTED = {
|
|
200
|
+
plan_type: 'plus',
|
|
201
|
+
rate_limit: {
|
|
202
|
+
allowed: false,
|
|
203
|
+
limit_reached: true,
|
|
204
|
+
primary_window: {
|
|
205
|
+
used_percent: 100,
|
|
206
|
+
limit_window_seconds: 18000,
|
|
207
|
+
reset_after_seconds: 12650,
|
|
208
|
+
reset_at: 1796495712,
|
|
209
|
+
},
|
|
210
|
+
secondary_window: {
|
|
211
|
+
used_percent: 78,
|
|
212
|
+
limit_window_seconds: 604800,
|
|
213
|
+
reset_after_seconds: 426554,
|
|
214
|
+
reset_at: 1796909616,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** A healthy plan: 5 h window 30 % used, weekly 10 % used. */
|
|
220
|
+
const RECORDED_HEALTHY = {
|
|
221
|
+
plan_type: 'plus',
|
|
222
|
+
rate_limit: {
|
|
223
|
+
allowed: true,
|
|
224
|
+
limit_reached: false,
|
|
225
|
+
primary_window: {
|
|
226
|
+
used_percent: 30,
|
|
227
|
+
limit_window_seconds: 18000,
|
|
228
|
+
reset_after_seconds: 9000,
|
|
229
|
+
reset_at: 1796495712,
|
|
230
|
+
},
|
|
231
|
+
secondary_window: {
|
|
232
|
+
used_percent: 10,
|
|
233
|
+
limit_window_seconds: 604800,
|
|
234
|
+
reset_after_seconds: 500000,
|
|
235
|
+
reset_at: 1796909616,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** A single seven-day primary window, no secondary (seen on some Plus plans). */
|
|
241
|
+
const RECORDED_SINGLE = {
|
|
242
|
+
plan_type: 'plus',
|
|
243
|
+
rate_limit: {
|
|
244
|
+
allowed: true,
|
|
245
|
+
limit_reached: false,
|
|
246
|
+
primary_window: {
|
|
247
|
+
used_percent: 60,
|
|
248
|
+
limit_window_seconds: 604800,
|
|
249
|
+
reset_after_seconds: 300000,
|
|
250
|
+
reset_at: 1796909616,
|
|
251
|
+
},
|
|
252
|
+
secondary_window: null,
|
|
253
|
+
},
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The declared adapters this module serves. */
|
|
257
|
+
export const openaiCodexAdapters = [
|
|
258
|
+
defineAdapter({
|
|
259
|
+
id: 'openai-codex',
|
|
260
|
+
routes: ['openai-codex'],
|
|
261
|
+
kind: KIND_QUOTA,
|
|
262
|
+
consoleUrl: CONSOLE,
|
|
263
|
+
display: {
|
|
264
|
+
name: { zh: 'OpenAI Codex', en: 'OpenAI Codex' },
|
|
265
|
+
mark: { icon: 'openai', color: '#10A37F' },
|
|
266
|
+
},
|
|
267
|
+
readWithEnv: readCodexUsage,
|
|
268
|
+
fixtures: [
|
|
269
|
+
{
|
|
270
|
+
name: 'exhausted five-hour window pins the badge at zero',
|
|
271
|
+
services: { credentials: RECORDED_CREDENTIALS },
|
|
272
|
+
responses: [RECORDED_EXHAUSTED],
|
|
273
|
+
expect: {
|
|
274
|
+
status: 'ready',
|
|
275
|
+
kind: KIND_QUOTA,
|
|
276
|
+
percent: 0,
|
|
277
|
+
resetsAt: 1796495712000,
|
|
278
|
+
windows: [
|
|
279
|
+
{ id: 'session', unit: 'hour', count: 5, remainingPercent: 0, resetAt: 1796495712000 },
|
|
280
|
+
{ id: 'weekly', unit: 'week', count: 1, remainingPercent: 22, resetAt: 1796909616000 },
|
|
281
|
+
],
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: 'healthy plan reports the share left in both windows',
|
|
286
|
+
services: { credentials: RECORDED_CREDENTIALS },
|
|
287
|
+
responses: [RECORDED_HEALTHY],
|
|
288
|
+
expect: {
|
|
289
|
+
status: 'ready',
|
|
290
|
+
percent: 70,
|
|
291
|
+
windows: [
|
|
292
|
+
{ id: 'session', remainingPercent: 70 },
|
|
293
|
+
{ id: 'weekly', remainingPercent: 90 },
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: 'a single seven-day primary window reads as one week',
|
|
299
|
+
services: { credentials: RECORDED_CREDENTIALS },
|
|
300
|
+
responses: [RECORDED_SINGLE],
|
|
301
|
+
expect: {
|
|
302
|
+
status: 'ready',
|
|
303
|
+
percent: 40,
|
|
304
|
+
windows: [{ id: 'session', unit: 'week', count: 1, remainingPercent: 40 }],
|
|
305
|
+
},
|
|
306
|
+
absent: ['windows[1]'],
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: 'no host grant configured',
|
|
310
|
+
services: {},
|
|
311
|
+
expect: { status: 'unconfigured', kind: KIND_QUOTA },
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'an expired grant is reported, never self-refreshed',
|
|
315
|
+
services: {
|
|
316
|
+
credentials: {
|
|
317
|
+
readRecord: async () => ({
|
|
318
|
+
kind: 'grant',
|
|
319
|
+
payload: { type: 'oauth', access: 'a', accountId: 'b', expires: 1 },
|
|
320
|
+
}),
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
expect: { status: 'failed', kind: KIND_QUOTA },
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'an authorization refusal names the status',
|
|
327
|
+
services: { credentials: RECORDED_CREDENTIALS },
|
|
328
|
+
responses: [RECORDED_EXHAUSTED],
|
|
329
|
+
httpStatus: 401,
|
|
330
|
+
expect: { status: 'failed', kind: KIND_QUOTA },
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
}),
|
|
334
|
+
]
|
package/lib/providers.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { deepseekAdapters } from './providers/deepseek.js'
|
|
18
18
|
import { kimiCodingAdapters } from './providers/kimi_coding.js'
|
|
19
19
|
import { minimaxCnAdapters } from './providers/minimax_cn.js'
|
|
20
|
+
import { openaiCodexAdapters } from './providers/openai_codex.js'
|
|
20
21
|
import { opencodeGoAdapters } from './providers/opencode_go.js'
|
|
21
22
|
import {
|
|
22
23
|
amazonBedrockAdapters,
|
|
@@ -40,7 +41,6 @@ import {
|
|
|
40
41
|
moonshotaiCnAdapters,
|
|
41
42
|
nvidiaAdapters,
|
|
42
43
|
openaiAdapters,
|
|
43
|
-
openaiCodexAdapters,
|
|
44
44
|
opencodeAdapters,
|
|
45
45
|
openrouterAdapters,
|
|
46
46
|
radiusAdapters,
|
|
@@ -133,6 +133,7 @@ export const PROVIDER_ADAPTERS = Object.freeze([
|
|
|
133
133
|
...opencodeGoAdapters,
|
|
134
134
|
...xiaomiAdapters,
|
|
135
135
|
...qwenTokenPlanAdapters,
|
|
136
|
+
...openaiCodexAdapters,
|
|
136
137
|
// Placeholder adapters (unsupported status)
|
|
137
138
|
...amazonBedrockAdapters,
|
|
138
139
|
...antLingAdapters,
|
|
@@ -155,7 +156,6 @@ export const PROVIDER_ADAPTERS = Object.freeze([
|
|
|
155
156
|
...moonshotaiCnAdapters,
|
|
156
157
|
...nvidiaAdapters,
|
|
157
158
|
...openaiAdapters,
|
|
158
|
-
...openaiCodexAdapters,
|
|
159
159
|
...opencodeAdapters,
|
|
160
160
|
...openrouterAdapters,
|
|
161
161
|
...radiusAdapters,
|