dsh-bottom-info-bar 1.26.0 → 1.27.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/lib/client.js +3 -3
- package/lib/constants.js +4 -3
- package/lib/index.js +114 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -505,7 +505,7 @@ function clearNativePillVisibility() {
|
|
|
505
505
|
const PRESET_COLORS = ['red', 'green', 'blue', 'purple', 'orange', 'neutral'];
|
|
506
506
|
// v1.6 T7 / v1.7 FR-14:订阅/账单 provider 集合(构建注入,永不变)。以前在 BottomInfoBar 里每次渲染重建
|
|
507
507
|
// 字面量——值从不变,多建的只是垃圾。提到模块级,var 拼法保留(一致性测试按该字面锚点提取)。
|
|
508
|
-
var SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding'];
|
|
508
|
+
var SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'chatgpt-siwc', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding'];
|
|
509
509
|
var BILLING_PROVIDERS = ['together', 'fireworks', 'amazon-bedrock', 'cloudflare-ai-gateway', 'cloudflare-workers-ai', 'huggingface'];
|
|
510
510
|
const PRESET_COLOR_SET = new Set(PRESET_COLORS);
|
|
511
511
|
|
|
@@ -2906,7 +2906,7 @@ const CREDENTIAL_CATALOG = [
|
|
|
2906
2906
|
id: 'codex',
|
|
2907
2907
|
label: 'ChatGPT / Codex',
|
|
2908
2908
|
mode: 'subscription',
|
|
2909
|
-
providers: ['openai-codex', 'chatgpt', 'codex'],
|
|
2909
|
+
providers: ['openai-codex', 'chatgpt', 'chatgpt-siwc', 'codex'],
|
|
2910
2910
|
official: true,
|
|
2911
2911
|
verification: 'third-party',
|
|
2912
2912
|
credentials: [],
|
|
@@ -5309,7 +5309,7 @@ module.exports = {
|
|
|
5309
5309
|
// Codex 与 ChatGPT 已合并:实际 provider openai-codex / chatgpt 均显示 ChatGPT;codex 保持 Codex
|
|
5310
5310
|
// v1.6 T7:新增 zai/zai-coding-cn → '智谱';v1.7:小米 Token Plan → '小米 MiMo'
|
|
5311
5311
|
function subscriptionServiceName(provider) {
|
|
5312
|
-
if (provider === 'chatgpt' || provider === 'openai-codex') return 'ChatGPT';
|
|
5312
|
+
if (provider === 'chatgpt' || provider === 'openai-codex' || provider === 'chatgpt-siwc') return 'ChatGPT';
|
|
5313
5313
|
if (provider === 'codex') return 'Codex';
|
|
5314
5314
|
if (provider === 'opencode-go' || provider === 'opencode') return 'OpenCode Go';
|
|
5315
5315
|
if (provider === 'zai' || provider === 'zai-coding-cn') return t('ui.zhipu');
|
package/lib/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// v1.7:新增小米 MiMo Token Plan 三集群(月度 Credits 额度窗)
|
|
4
4
|
// v1.16.0:新增 MiniMax(海螺)Token Plan 双站点(Global minimax / CN minimax-cn,5 小时 + 周窗口)
|
|
5
5
|
// v1.22.0:新增阿里 Token Plan 中国站/国际站(百炼 Credits 订阅,月度窗口)与 Kimi For Coding(5 小时 + 周窗口)
|
|
6
|
-
export const SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding']
|
|
6
|
+
export const SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'chatgpt-siwc', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding']
|
|
7
7
|
// 云账单 provider 集合:这些 provider 走"账单型"显示(本月真实花费 / 预算%),与余额型/额度型互斥(FR-14)
|
|
8
8
|
export const BILLING_PROVIDERS = ['together', 'fireworks', 'amazon-bedrock', 'cloudflare-ai-gateway', 'cloudflare-workers-ai', 'huggingface']
|
|
9
9
|
|
|
@@ -126,7 +126,7 @@ export const CREDENTIAL_CATALOG = [
|
|
|
126
126
|
id: 'codex',
|
|
127
127
|
label: 'ChatGPT / Codex',
|
|
128
128
|
mode: 'subscription',
|
|
129
|
-
providers: ['openai-codex', 'chatgpt', 'codex'],
|
|
129
|
+
providers: ['openai-codex', 'chatgpt', 'chatgpt-siwc', 'codex'],
|
|
130
130
|
official: true,
|
|
131
131
|
verification: 'third-party',
|
|
132
132
|
credentials: [],
|
|
@@ -254,7 +254,7 @@ export const PROVIDER_DEFAULT_CURRENCY = {
|
|
|
254
254
|
'baseten': 'USD', 'cerebras': 'USD', 'cloudflare-ai-gateway': 'USD', 'cloudflare-workers-ai': 'USD',
|
|
255
255
|
'fireworks': 'USD', 'github-copilot': 'USD', 'google': 'USD', 'google-vertex': 'USD', 'groq': 'USD',
|
|
256
256
|
'huggingface': 'USD', 'kimi-coding': 'USD', 'mistral': 'USD', 'moonshotai': 'USD', 'nvidia': 'USD', 'openai': 'USD',
|
|
257
|
-
'openai-codex': 'USD', 'chatgpt': 'USD', 'codex': 'USD', 'openrouter': 'USD',
|
|
257
|
+
'openai-codex': 'USD', 'chatgpt': 'USD', 'chatgpt-siwc': 'USD', 'codex': 'USD', 'openrouter': 'USD',
|
|
258
258
|
'qwen-token-plan': 'USD', 'qwen-token-plan-individual': 'USD', 'together': 'USD',
|
|
259
259
|
'vercel-ai-gateway': 'USD', 'xai': 'USD',
|
|
260
260
|
}
|
|
@@ -281,6 +281,7 @@ export const PROVIDER_IDENTITY = {
|
|
|
281
281
|
'codex': { account: 'codex', subscription: 'codex', billing: null },
|
|
282
282
|
'chatgpt': { account: 'codex', subscription: 'codex', billing: null },
|
|
283
283
|
'openai-codex': { account: 'codex', subscription: 'codex', billing: null },
|
|
284
|
+
'chatgpt-siwc': { account: 'codex', subscription: 'codex', billing: null },
|
|
284
285
|
'opencode-go': { account: 'opencode-go', subscription: 'opencode-go', billing: null },
|
|
285
286
|
'opencode': { account: 'opencode-go', subscription: 'opencode-go', billing: null },
|
|
286
287
|
'zai': { account: 'zai', subscription: 'zai', billing: null },
|
package/lib/index.js
CHANGED
|
@@ -317,7 +317,7 @@ function latestVersion() {
|
|
|
317
317
|
|
|
318
318
|
// ---------- 双模式(余额制 / 订阅制)配置 ----------
|
|
319
319
|
// 订阅制 provider 集合:这些 provider 走"额度窗口"显示而非余额(共享常量注入,见 src/constants.js)
|
|
320
|
-
const SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding'];
|
|
320
|
+
const SUBSCRIPTION_PROVIDERS = ['codex', 'chatgpt', 'chatgpt-siwc', 'opencode-go', 'opencode', 'openai-codex', 'zai', 'zai-coding-cn', 'xiaomi-token-plan-cn', 'xiaomi-token-plan-sgp', 'xiaomi-token-plan-ams', 'command', 'command-code', 'minimax', 'minimax-cn', 'qwen-token-plan-cn', 'qwen-token-plan', 'qwen-token-plan-individual', 'kimi-coding'];
|
|
321
321
|
// 云账单 provider 集合:这些 provider 走"账单型"显示(本月真实花费 / 预算%),与余额型/额度型互斥(FR-14 共享常量注入)
|
|
322
322
|
const BILLING_PROVIDERS = ['together', 'fireworks', 'amazon-bedrock', 'cloudflare-ai-gateway', 'cloudflare-workers-ai', 'huggingface'];
|
|
323
323
|
// 窗口标签:模块顶层用硬编码中文兜底(避免加载时触发 translate);
|
|
@@ -900,6 +900,55 @@ function parseAppAuthCodexUsage(result, windowLabels) {
|
|
|
900
900
|
return { status: 'unavailable', reason: reason, plan: plan, planType: planType, windows: [] }
|
|
901
901
|
}
|
|
902
902
|
|
|
903
|
+
// /backend-api/wham/usage → 统一的 { provider, plan, planType, expiryAt, windows }。
|
|
904
|
+
// 这是 Codex 后端的额度接口:primary_window/secondary_window 带 used_percent、
|
|
905
|
+
// reset_at(Unix 秒)和 limit_window_seconds。SIWC 的 token 官方明确不接受,
|
|
906
|
+
// 所以只有本机存在 Codex 登录文件时才有数据。
|
|
907
|
+
function parseCodexWhamUsage(body, windowLabels) {
|
|
908
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
909
|
+
const wl = windowLabels || WINDOW_LABELS
|
|
910
|
+
const windows = []
|
|
911
|
+
const seen = {}
|
|
912
|
+
const addWindow = function (win, id) {
|
|
913
|
+
if (!win || typeof win !== 'object') return
|
|
914
|
+
const percent = parsePercent(win.used_percent)
|
|
915
|
+
const key = appAuthWindowKey(id, win.limit_window_seconds)
|
|
916
|
+
if (percent == null || !key || seen[key]) return
|
|
917
|
+
seen[key] = true
|
|
918
|
+
windows.push({
|
|
919
|
+
key: key,
|
|
920
|
+
label: wl[key],
|
|
921
|
+
usedPercent: Math.round(percent),
|
|
922
|
+
resetsAt: normalizeResetAt(win.reset_at),
|
|
923
|
+
})
|
|
924
|
+
}
|
|
925
|
+
const rateLimit = body.rate_limit && typeof body.rate_limit === 'object' ? body.rate_limit : {}
|
|
926
|
+
addWindow(rateLimit.primary_window, 'primary')
|
|
927
|
+
addWindow(rateLimit.secondary_window, 'secondary')
|
|
928
|
+
// Business 计划没有 rate_limit,只有管理员设的月度上限。
|
|
929
|
+
const spend = body.spend_control && typeof body.spend_control === 'object' ? body.spend_control.individual_limit : null
|
|
930
|
+
if (windows.length === 0 && spend && typeof spend === 'object') {
|
|
931
|
+
let percent = parsePercent(spend.used_percent)
|
|
932
|
+
if (percent == null) {
|
|
933
|
+
const used = Number(spend.used)
|
|
934
|
+
const limit = Number(spend.limit)
|
|
935
|
+
if (isFinite(used) && isFinite(limit) && limit > 0) percent = (used / limit) * 100
|
|
936
|
+
}
|
|
937
|
+
if (percent != null) {
|
|
938
|
+
windows.push({ key: 'monthly', label: wl.monthly, usedPercent: Math.round(percent), resetsAt: normalizeResetAt(spend.reset_at) })
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
if (windows.length === 0) return null
|
|
942
|
+
const planType = typeof body.plan_type === 'string' && body.plan_type.length > 0 ? body.plan_type : null
|
|
943
|
+
return {
|
|
944
|
+
provider: 'codex',
|
|
945
|
+
plan: planType ? planDisplayName(planType) : null,
|
|
946
|
+
planType: planType,
|
|
947
|
+
expiryAt: null,
|
|
948
|
+
windows: windows,
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
903
952
|
// ---------- FR-9 / D8:小米 MiMo 解析(数值一律容错:字符串/数字、百分比 0-1 或 0-100 双形态) ----------
|
|
904
953
|
function xiaomiRegionBaseUrl(region) {
|
|
905
954
|
if (region === 'sgp') return 'https://token-plan-sgp.xiaomimimo.com'
|
|
@@ -2908,11 +2957,74 @@ export default {
|
|
|
2908
2957
|
return { data: { provider: 'codex', plan: plan, planType: parsed.planType, expiryAt: parsed.expiryMs, windows: [] } };
|
|
2909
2958
|
}
|
|
2910
2959
|
|
|
2960
|
+
// SIWC 会话通道:dsh-chatgpt-sub 0.9+ 把官方 Sign in with ChatGPT 会话存在
|
|
2961
|
+
// DSH 凭据库(chatgpt-sub/session)。它没有 ~/.codex/auth.json 时,套餐与有效期
|
|
2962
|
+
// 从这里读;旧版 Codex 文件仍保留为第三兜底。
|
|
2963
|
+
async function fetchCodexUsageFromSession() {
|
|
2964
|
+
try {
|
|
2965
|
+
if (!ctx.credentials || typeof ctx.credentials.readRecord !== 'function') return null;
|
|
2966
|
+
const record = await ctx.credentials.readRecord('chatgpt-sub/session');
|
|
2967
|
+
const payload = record && record.kind === 'grant' ? record.payload : null;
|
|
2968
|
+
if (!payload || typeof payload !== 'object' || payload.version !== 1) return null;
|
|
2969
|
+
const idToken = typeof payload.idToken === 'string' && payload.idToken.length > 0 ? payload.idToken : null;
|
|
2970
|
+
let parsed = null;
|
|
2971
|
+
if (idToken) {
|
|
2972
|
+
try { parsed = parseCodexJwt(idToken); } catch (err) { /* 只用会话里的字段 */ }
|
|
2973
|
+
}
|
|
2974
|
+
const planType = (parsed && parsed.planType) || (typeof payload.plan === 'string' && payload.plan.length > 0 ? payload.plan : null);
|
|
2975
|
+
const expiryAt = (parsed && parsed.expiryMs) || (typeof payload.expiresAt === 'number' ? payload.expiresAt : null);
|
|
2976
|
+
return { data: { provider: 'codex', plan: planType ? planDisplayName(planType) : null, planType: planType, expiryAt: expiryAt, windows: [] } };
|
|
2977
|
+
} catch (err) {
|
|
2978
|
+
return null;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
// Codex 后端额度通道:需要本机 ~/.codex/auth.json(Codex CLI / 旧版插件留下的登录)。
|
|
2983
|
+
// SIWC 的 token 被官方明确拒绝在 ChatGPT 用量端点之外,所以这是当前唯一能拿到
|
|
2984
|
+
// 5 小时 / 每周 / 月度窗口百分比的路径。文件不存在或过期时返回 null,退回套餐/有效期。
|
|
2985
|
+
async function fetchCodexUsageFromWham() {
|
|
2986
|
+
const read = readCodexAuthFile(CODEX_AUTH_FILE);
|
|
2987
|
+
if (!read.ok) return null;
|
|
2988
|
+
const tokens = read.auth && read.auth.tokens;
|
|
2989
|
+
const access = tokens && typeof tokens.access_token === 'string' && tokens.access_token.length > 0 ? tokens.access_token : null;
|
|
2990
|
+
if (!access) return null;
|
|
2991
|
+
// 账号一致性:两边的 id_token 都能读到邮箱且不一致时,不拿另一个账号的额度冒充。
|
|
2992
|
+
try {
|
|
2993
|
+
if (ctx.credentials && typeof ctx.credentials.readRecord === 'function') {
|
|
2994
|
+
const record = await ctx.credentials.readRecord('chatgpt-sub/session');
|
|
2995
|
+
const payload = record && record.kind === 'grant' ? record.payload : null;
|
|
2996
|
+
const nativeClaims = payload && typeof payload.idToken === 'string' ? decodeJwtPayload(payload.idToken) : null;
|
|
2997
|
+
const codexClaims = typeof tokens.id_token === 'string' ? decodeJwtPayload(tokens.id_token) : null;
|
|
2998
|
+
if (nativeClaims && codexClaims && typeof nativeClaims.email === 'string' && typeof codexClaims.email === 'string'
|
|
2999
|
+
&& nativeClaims.email.toLowerCase() !== codexClaims.email.toLowerCase()) {
|
|
3000
|
+
return null;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
} catch (err) { /* 读不到会话就按纯 Codex 账号处理 */ }
|
|
3004
|
+
const headers = { Authorization: 'Bearer ' + access, Accept: 'application/json' };
|
|
3005
|
+
if (typeof tokens.account_id === 'string' && tokens.account_id.length > 0) headers['ChatGPT-Account-Id'] = tokens.account_id;
|
|
3006
|
+
try {
|
|
3007
|
+
const res = await fetch('https://chatgpt.com/backend-api/wham/usage', { headers: headers, signal: timeoutSignal(HTTP_TIMEOUT_MS) });
|
|
3008
|
+
if (!res.ok) return null;
|
|
3009
|
+
const body = await res.json();
|
|
3010
|
+
const data = parseCodexWhamUsage(body, windowLabels);
|
|
3011
|
+
return data ? { data: data } : null;
|
|
3012
|
+
} catch (err) {
|
|
3013
|
+
return null;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
|
|
2911
3017
|
async function fetchCodexUsage() {
|
|
2912
3018
|
// ① appAuth 优先:拿到额度窗口就用它(DSH Go 的唯一可用通道)
|
|
2913
3019
|
const viaAppAuth = await fetchCodexUsageViaAppAuth();
|
|
2914
3020
|
if (viaAppAuth && viaAppAuth.data) return viaAppAuth;
|
|
2915
|
-
// ②
|
|
3021
|
+
// ② Codex 后端额度:桌面端唯一能拿到窗口百分比的通道
|
|
3022
|
+
const viaWham = await fetchCodexUsageFromWham();
|
|
3023
|
+
if (viaWham && viaWham.data) return viaWham;
|
|
3024
|
+
// ③ 新版 dsh-chatgpt-sub 的 SIWC 会话(没有 Codex 文件也能显示套餐与有效期)
|
|
3025
|
+
const fromSession = await fetchCodexUsageFromSession();
|
|
3026
|
+
if (fromSession && fromSession.data) return fromSession;
|
|
3027
|
+
// ③ 旧版桌面文件通道:取到数据就用文件的数据,不被 appAuth 的失败状态遮住
|
|
2916
3028
|
const fromFile = fetchCodexUsageFromFile();
|
|
2917
3029
|
if (fromFile && fromFile.data) return fromFile;
|
|
2918
3030
|
// ③ 两条都失败:appAuth 存在时返回它的明确原因(「去 DSH App 授权」等),
|