dsh-desktop-statusbar 3.0.2 → 3.0.4

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.
@@ -0,0 +1,124 @@
1
+ [
2
+ {
3
+ "vendorId": "anthropic",
4
+ "vendorLabel": "Anthropic",
5
+ "model": "Claude Opus 5.5 (Max, Default Fallback)",
6
+ "aaModelSlug": "claude-opus-5-5",
7
+ "aaIndex": 59.11,
8
+ "source": "https://artificialanalysis.ai/leaderboards/models",
9
+ "verifiedAt": "2026-11-04",
10
+ "note": "公开可用(AA provider 页 4 个 provider:Anthropic / Amazon / Google / Azure);对应目录 claude-opus-5.5。",
11
+ "excluded": []
12
+ },
13
+ {
14
+ "vendorId": "openai",
15
+ "vendorLabel": "OpenAI",
16
+ "model": "GPT-6 Astra (Max)",
17
+ "aaModelSlug": "gpt-6-astra",
18
+ "aaIndex": 56.85,
19
+ "source": "https://artificialanalysis.ai/leaderboards/models",
20
+ "verifiedAt": "2026-11-04",
21
+ "note": "公开可用(6 个 provider);对应目录 gpt-6-astra;同代 gpt-6.1-sol 为 54.61。",
22
+ "excluded": []
23
+ },
24
+ {
25
+ "vendorId": "google",
26
+ "vendorLabel": "Google Gemini",
27
+ "model": "Gemini 4 Argon (High)",
28
+ "aaModelSlug": "gemini-4-argon",
29
+ "aaIndex": 50.41,
30
+ "source": "https://artificialanalysis.ai/leaderboards/models",
31
+ "verifiedAt": "2026-11-04",
32
+ "note": "公开可用(3 个 provider,含 Google AI Studio / Google (Vertex));对应目录 gemini-4-argon。AA 全场第一的 Gemini 4 Carbon 按用户口径排除后,这是 Google 可用的最高分。",
33
+ "excluded": [
34
+ {
35
+ "model": "Gemini 4 Carbon (High / Medium / Low)",
36
+ "aaIndex": 60.03,
37
+ "reason": "用户明确反馈当前无法调用(不可用 / 未开放),据此排除,三个推理档一并排除(High 60.03、Medium 58.26、Low 54.22)。注意:AA 自己并未标注 preview/unavailable——其 provider 页写「Gemini 4 Carbon (high) is available through Google」(1 provider,公开价 $4/$20),故本条排除依据是用户的实际可访问性,不是 AA 的可用性字段。"
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "vendorId": "moonshot",
43
+ "vendorLabel": "月之暗面 Kimi",
44
+ "model": "Kimi K3.1 Pro",
45
+ "aaModelSlug": "kimi-k3-1-pro",
46
+ "aaIndex": 46.45,
47
+ "source": "https://artificialanalysis.ai/leaderboards/models",
48
+ "verifiedAt": "2026-11-04",
49
+ "note": "公开可用(2 个 provider);对应目录 kimi-k3.1-pro。Kimi K3 可正常调用但 AA 无独立条目,不影响排序。",
50
+ "excluded": []
51
+ },
52
+ {
53
+ "vendorId": "muse",
54
+ "vendorLabel": "Muse (Meta)",
55
+ "model": "Muse Wonder (Max)",
56
+ "aaModelSlug": "muse-wonder",
57
+ "aaIndex": 43.57,
58
+ "source": "https://artificialanalysis.ai/leaderboards/models",
59
+ "verifiedAt": "2026-11-04",
60
+ "note": "公开可用(AA provider 页 1 个 provider:Meta,公开价 $4/$20);对应目录 muse-wonder-1.0。Meta 在 AA 上分数最高的 Muse Wonder Full (Max) 因 AA 判定无任何 API provider 被排除。Meta 下一档 Muse Spark 1.3 (Max) 36.62 已被 AA 标 deprecated(Meta 已用 Muse Wonder 取代),且低于 Wonder,不影响排序。",
61
+ "excluded": [
62
+ {
63
+ "model": "Muse Wonder Full (Max)",
64
+ "aaIndex": 50.08,
65
+ "reason": "AA 明确判定无公开 API:provider 页「No API providers are currently available for Muse Wonder Full (max)」,Total 0 providers;排行榜该行 Cost / Time / TTFT 全为「--」,无公开价格(priceClass = null)。与用户反馈一致。"
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ "vendorId": "xai",
71
+ "vendorLabel": "xAI Grok",
72
+ "model": "Grok 4.7 (Xhigh)",
73
+ "aaModelSlug": "grok-4-7",
74
+ "aaIndex": 35.49,
75
+ "source": "https://artificialanalysis.ai/leaderboards/models",
76
+ "verifiedAt": "2026-11-04",
77
+ "note": "公开可用(1 个 provider,AA 记为 SpaceXAI);对应目录 grok-4.7。",
78
+ "excluded": []
79
+ },
80
+ {
81
+ "vendorId": "alibaba",
82
+ "vendorLabel": "阿里云通义千问",
83
+ "model": "Qwen3.8 Max (0902)",
84
+ "aaModelSlug": "qwen3-8-max",
85
+ "aaIndex": 33.65,
86
+ "source": "https://artificialanalysis.ai/leaderboards/models",
87
+ "verifiedAt": "2026-11-04",
88
+ "note": "公开可用(1 个 provider:Alibaba Cloud);AA 上厂商最强为 Qwen3.8 Max,不在精简目录(目录仅 qwen3.8-flash / qwen3.8-27b;AA 上 27b 为 20.11)。按“厂商最强模型”口径排序。",
89
+ "excluded": []
90
+ },
91
+ {
92
+ "vendorId": "deepseek",
93
+ "vendorLabel": "DeepSeek",
94
+ "model": "DeepSeek V4.1 Flash 1017 (Max)",
95
+ "aaModelSlug": "deepseek-v4-1-flash-1017",
96
+ "aaIndex": 32.59,
97
+ "source": "https://artificialanalysis.ai/leaderboards/models",
98
+ "verifiedAt": "2026-11-04",
99
+ "note": "公开可用(23 个 provider);AA 上厂商最强为 V4.1 Flash,目录内 v4-pro 在 AA 为 23.06;本排序按厂商最强口径。",
100
+ "excluded": []
101
+ },
102
+ {
103
+ "vendorId": "zhipu",
104
+ "vendorLabel": "智谱 GLM",
105
+ "model": "GLM-5.3 (Max)",
106
+ "aaModelSlug": "glm-5-3",
107
+ "aaIndex": 31.65,
108
+ "source": "https://artificialanalysis.ai/leaderboards/models",
109
+ "verifiedAt": "2026-11-04",
110
+ "note": "公开可用(26 个 provider);对应目录 GLM-5.3;同代 GLM-5.3-Flash 为 27.80。",
111
+ "excluded": []
112
+ },
113
+ {
114
+ "vendorId": "xiaomi",
115
+ "vendorLabel": "小米 MiMo",
116
+ "model": "MiMo-V2.6-Pro",
117
+ "aaModelSlug": "mimo-v2-6-pro",
118
+ "aaIndex": 29.89,
119
+ "source": "https://artificialanalysis.ai/leaderboards/models",
120
+ "verifiedAt": "2026-11-04",
121
+ "note": "公开可用(4 个 provider);对应目录 mimo-v2.6-pro;ultraspeed 档在 AA 无单独条目。",
122
+ "excluded": []
123
+ }
124
+ ]
@@ -0,0 +1,77 @@
1
+ # 厂商默认排序依据(Artificial Analysis,只计「公开可用」模型,2026-11-04 核实)
2
+
3
+ 来源:<https://artificialanalysis.ai/leaderboards/models>(2026-11-04 用 curl 抓取页面,解析 Next.js RSC 内嵌 JSON 得到每个模型的精确 `intelligenceIndex`)。
4
+ 可用性判定:逐个打开 AA 的 `/models/<slug>/providers` 页,以 **provider 数量** 为准——`Total 0 providers` / “No API providers are currently available for …” 视为不可用;`Total ≥1 providers` 且有公开价格视为公开可用。指数版本 **Artificial Analysis Intelligence Index v5.0.1**。
5
+
6
+ 排序规则:每个厂商取 AA 上**公开可用**的最高分模型(同一模型取最高推理档,如 Max / Xhigh);**不可用的一律排除**(0 provider、preview/internal、deprecated),改用该厂商可用的下一档。
7
+
8
+ ## 最终顺序(从高到低)
9
+
10
+ | 排名 | 厂商 | AA 可用最强模型 | Intelligence Index | AA provider 数 | 与原排序相比 |
11
+ | --- | --- | --- | --- | --- | --- |
12
+ | 1 | Anthropic | Claude Opus 5.5 (Max, Default Fallback) | 59.11 | 4(Anthropic/Amazon/Google/Azure) | 不变 |
13
+ | 2 | OpenAI | GPT-6 Astra (Max) | 56.85 | 6 | 不变 |
14
+ | 3 | Google Gemini | Gemini 4 Argon (High) | 50.41 | 3(AI Studio / Vertex 等) | 不变(仍排除 Carbon) |
15
+ | 4 | 月之暗面 Kimi | Kimi K3.1 Pro | 46.45 | 2 | **↑ 从第 5 升到第 4** |
16
+ | 5 | Muse (Meta) | Muse Wonder (Max) | 43.57 | 1(Meta) | **↓ 从第 4 降到第 5** |
17
+ | 6 | xAI Grok | Grok 4.7 (Xhigh) | 35.49 | 1(AA 记为 SpaceXAI) | 不变 |
18
+ | 7 | 阿里云通义千问 | Qwen3.8 Max (0902) | 33.65 | 1(Alibaba Cloud) | 不变 |
19
+ | 8 | DeepSeek | DeepSeek V4.1 Flash 1017 (Max) | 32.59 | 23 | 不变 |
20
+ | 9 | 智谱 GLM | GLM-5.3 (Max) | 31.65 | 26 | 不变 |
21
+ | 10 | 小米 MiMo | MiMo-V2.6-Pro | 29.89 | 4 | 不变 |
22
+
23
+ 机器可读版本:[vendor-intelligence-order.json](vendor-intelligence-order.json)(有序数组,每家带 `excluded` 数组)。
24
+
25
+ 客户端用的厂商标识顺序:
26
+
27
+ ```
28
+ ["anthropic","openai","google","moonshot","muse","xai","alibaba","deepseek","zhipu","xiaomi"]
29
+ ```
30
+
31
+ ## 被排除的不可用条目(排除清单)
32
+
33
+ | 厂商 | 被排除模型 | AA 分数 | 排除原因与证据 |
34
+ | --- | --- | --- | --- |
35
+ | Muse (Meta) | **Muse Wonder Full (Max)** | 50.08 | AA 明确判定无公开 API:`/models/muse-wonder-full/providers` 写 **“No API providers are currently available for Muse Wonder Full (max).”**、`Total 0 providers`;排行榜该行 Cost / Time / TTFT 全为 `--`,无价格(`priceClass = null`)。与用户反馈一致。 |
36
+ | Google Gemini | **Gemini 4 Carbon(High 60.03 / Medium 58.26 / Low 54.22)** | 60.03 | 用户明确说明该模型当前**用不了**,按其口径排除,三个推理档一并排除,Google 改用下一档 Gemini 4 Argon (High) 50.41。**注意**:AA 自己**没有**标 preview/unavailable——其 provider 页写 “Gemini 4 Carbon (high) is available through Google”(1 provider,公开价 $4/$20)。所以这条排除的依据是**用户的实际可访问性**,不是 AA 的可用性字段。 |
37
+
38
+ 其余 8 家(Anthropic、OpenAI、Kimi、xAI、阿里、DeepSeek、智谱、小米)在 AA 上分数最高的条目**本身就有 ≥1 个公开 provider**,无需排除,`excluded` 为空数组。
39
+
40
+ ## Meta (Muse) 专门核查
41
+
42
+ | 模型 | AA 分数 | AA provider | 结论 |
43
+ | --- | --- | --- | --- |
44
+ | Muse Wonder Full (Max) | 50.0772 | **0(无公开 API)** | **排除**(这就是用户说的“排最高的那个没开放”) |
45
+ | Muse Wonder (Max) | 43.5748 | 1(Meta,$4/$20) | **采用**(Meta 可用最高分),对应目录 `muse-wonder-1.0` |
46
+ | Muse Spark 1.3 (Max) | 36.6172 | 1(Meta,$1.25/$4.25) | 不用:AA 标 **deprecated**(“Meta has launched a newer release, Muse Wonder. We suggest considering it instead.”),且分数低于 Wonder |
47
+ | Muse Spark Open (Xhigh) | 24.8816 | 有(open weights) | Meta 若连 Wonder 也不可用时的兜底档 |
48
+ | Muse Glimmer (High) | 6.3413 | 有 | 太低,不参与 |
49
+
50
+ 即:Meta 去掉不能用的 Wonder Full 后,可用最高分是 **43.57**,低于 Kimi 的 46.45,所以 **Meta 排在 Kimi 之后**(第 5),与用户判断一致。
51
+
52
+ ## Google 专门核查
53
+
54
+ - Gemini 4 Carbon 三档 60.03 / 58.26 / 54.22 全部排除(依据见上表);若以后 Carbon 真正可用,Google 会以 60.03 升到**第 1**,Anthropic 退到第 2。
55
+ - 排除 Carbon 后 Google 可用最高为 **Gemini 4 Argon (High) 50.41**(3 providers,$4/$20),仍排第 3——Google 用「可用模型」口径在 Meta 之上,因为 Meta 可用最高只有 43.57。
56
+
57
+ ## 其他 8 家的可用性核查明细
58
+
59
+ | 厂商 | AA 最高条目 | 分数 | provider 数 | 结论 |
60
+ | --- | --- | --- | --- | --- |
61
+ | Anthropic | Claude Opus 5.5 (Max, Default Fallback) | 59.11 | 4 | 可用,采用 |
62
+ | OpenAI | GPT-6 Astra (Max) | 56.85 | 6 | 可用,采用 |
63
+ | 月之暗面 Kimi | Kimi K3.1 Pro | 46.45 | 2 | 可用,采用(Kimi 仅此一个 AA 有条目) |
64
+ | xAI | Grok 4.7 (Xhigh) | 35.49 | 1 | 可用,采用 |
65
+ | 阿里 | Qwen3.8 Max (0902) | 33.65 | 1 | 可用,采用(不在精简目录内,按厂商最强口径) |
66
+ | DeepSeek | DeepSeek V4.1 Flash 1017 (Max) | 32.59 | 23 | 可用,采用 |
67
+ | 智谱 | GLM-5.3 (Max) | 31.65 | 26 | 可用,采用 |
68
+ | 小米 | MiMo-V2.6-Pro | 29.89 | 4 | 可用,采用 |
69
+
70
+ ## 口径说明与风险
71
+
72
+ - **只算公开可用**:这是本次唯一的口径变化。上一版把 Meta 的 Muse Wonder Full (50.08) 当作可用,所以 Meta 排第 4;修正后 Meta 用 Wonder 的 43.57,掉到第 5,Kimi 升到第 4。其余厂商顺序不变。
73
+ - **“No publicly available API” 是图例文本,不是状态标记**:AA 的模型页/图表里到处都有这句(作为图表图例),不能当成模型状态;真正的可用性证据是 provider 页的 provider 数量与“No API providers are currently available”整句。
74
+ - 10 家厂商在 AA 上**均有数据**,没有“无数据”厂商;所有分数都是 AA 页面/RSC JSON 里的精确值(`50.0772123627021` 这类),未编造。
75
+ - 排序取「**厂商最强模型**」而不是「我们目录里最强的模型」:阿里(Qwen3.8 Max)、DeepSeek(V4.1 Flash)的 AA 最强档不在精简目录内。若改为按目录内模型排序,DeepSeek 会从第 8 掉到最后,顺序会变。
76
+ - **单一来源**:以上全部来自 Artificial Analysis 一个站点,时点为 2026-11-04 抓取;榜单更新(Intelligence Index 刚更新到 v5)后需重跑。敏感的排除项只有两个:Google Carbon(依据用户实际可访问性)与 Meta Wonder Full(依据 AA 的 0 provider)。
77
+ - 敏感性:若用户确认 Muse Wonder (Max) 同样调不通,Meta 应降到 Muse Spark Open 24.88(open weights 档)→ Meta 会掉到第 10(末位);若把已废弃的 Muse Spark 1.3 (36.62) 也算上,Meta 才会回到第 6。当前按 AA 的可用性数据取 Wonder 43.57。
@@ -31,6 +31,56 @@ function nameHash(text) {
31
31
  return hash.toString(36);
32
32
  }
33
33
 
34
+ /**
35
+ * DeepSeek `GET /user/balance` 响应的唯一解析实现。
36
+ *
37
+ * 为什么抽出来:adapter.parse 与 `index.js` 的 API-key 分支原来各写一份,
38
+ * 一份取 `balance_infos[0]`、一份优先 CNY;两份迟早漂移,而测试只打 adapter.parse
39
+ * 那份(生产走的是另一份),绿了也证明不了线上正确。现在两边共用这一份。
40
+ *
41
+ * 返回 `{ currency, total, parts, balances }`;响应里没有可用余额时返回 null。
42
+ * `balances` 每项都带自己的 toppedUp/granted,供底栏拼「充值 : 赠金」色条。
43
+ */
44
+ function parseDeepSeekBalance(data) {
45
+ const infos = Array.isArray(data && data.balance_infos) ? data.balance_infos : [];
46
+ const usable = infos.filter((info) => info !== null && info !== undefined && typeof info === 'object');
47
+ if (usable.length === 0) return null;
48
+ /* 历史口径取第一条;但余额界面要的是 CNY 主余额 —— 优先 CNY,没有才退回第一条。 */
49
+ const one = usable.filter((info) => info.currency === 'CNY')[0] ?? usable[0];
50
+ const total = typeof one.total_balance === 'string'
51
+ ? one.total_balance
52
+ : (typeof one.total_balance === 'number' && Number.isFinite(one.total_balance) ? String(one.total_balance) : null);
53
+ if (total === null || total.length === 0) return null;
54
+ const parts = [];
55
+ const partText = (value) => typeof value === 'string'
56
+ ? value
57
+ : (typeof value === 'number' && Number.isFinite(value) ? String(value) : null);
58
+ const toppedUpText = partText(one.topped_up_balance);
59
+ if (toppedUpText !== null) parts.push({ label: 'toppedUp', amount: toppedUpText });
60
+ const grantedText = partText(one.granted_balance);
61
+ if (grantedText !== null) parts.push({ label: 'granted', amount: grantedText });
62
+ /* 分币种余额:只收 total > 0 的(0 与负数都不进 —— 用户拍板「负数也不显示」)。 */
63
+ const balances = [];
64
+ for (const info of usable) {
65
+ const amount = Number(info.total_balance);
66
+ if (Number.isFinite(amount) !== true || amount <= 0) continue;
67
+ balances.push({
68
+ currency: info.currency === 'USD' ? 'USD' : 'CNY',
69
+ total: String(info.total_balance),
70
+ toppedUp: info.topped_up_balance === undefined || info.topped_up_balance === null
71
+ ? '0.00' : String(info.topped_up_balance),
72
+ granted: info.granted_balance === undefined || info.granted_balance === null
73
+ ? '0.00' : String(info.granted_balance),
74
+ });
75
+ }
76
+ return {
77
+ currency: typeof one.currency === 'string' ? one.currency : 'CNY',
78
+ total,
79
+ parts,
80
+ balances: balances.length === 0 ? undefined : balances,
81
+ };
82
+ }
83
+
34
84
  const adapters = [
35
85
  {
36
86
  id: 'deepseek',
@@ -43,41 +93,39 @@ const adapters = [
43
93
  url: 'https://api.deepseek.com/user/balance',
44
94
  headers: { authorization: 'Bearer ' + key, accept: 'application/json' }
45
95
  }),
96
+ parse: (data) => parseDeepSeekBalance(data)
97
+ },
98
+ {
99
+ id: 'selen',
100
+ label: 'selen',
101
+ /* 核实:GET https://selenapi.com/v1/usage,Authorization: Bearer <key>;
102
+ 响应 balance/billing.balance/remaining,单位 USD。 */
103
+ keys: ['selen'],
104
+ refs: ['SELEN_API_KEY'],
105
+ request: (key, base) => ({
106
+ /* DSH 的 provider.baseURL 一般自带 /v1(OpenAI 兼容写法),这里先剥掉再拼端点,避免 /v1/v1。 */
107
+ url: String(base || 'https://selenapi.com').trim().replace(/\/+$/, '').replace(/\/v1$/i, '') + '/v1/usage',
108
+ headers: { authorization: 'Bearer ' + key, accept: 'application/json' }
109
+ }),
46
110
  parse: (data) => {
47
- const infos = Array.isArray(data && data.balance_infos) ? data.balance_infos : [];
48
- if (infos.length === 0) return null;
49
- const one = infos[0];
50
- /* 数组元素可能是 null(上游坏数据):直接读 total_balance 会抛 TypeError,
51
- 整条余额就永久变横杠,所以先挡一道。 */
52
- if (one === null || one === undefined || typeof one !== 'object') return null;
53
- const total = typeof one.total_balance === 'string' ? one.total_balance : null;
54
- if (total === null || total.length === 0) return null;
55
- const parts = [];
56
- if (typeof one.topped_up_balance === 'string') parts.push({ label: 'toppedUp', amount: one.topped_up_balance });
57
- if (typeof one.granted_balance === 'string') parts.push({ label: 'granted', amount: one.granted_balance });
58
- /* **额外**返回一份分币种余额:DeepSeek 的 balance_infos 里可能同时有 CNY 和 USD 两笔,
59
- 而上面那段(取 infos[0])是历史逻辑,老调用方还在用,语义一个字不能动。
60
- 这里遍历**全部**条目,让底栏能显示成「余额 ¥14.12+$3.17」。
61
- 只收 total > 0 的:0 与负数都不进(用户拍板「负数也不显示」,与 0 同样处理)。
62
- 币种只认 USD / CNY 两种,其余一律按 CNY(与文件其它地方口径一致),
63
- 这样上层不用再猜符号。 */
64
- const balances = [];
65
- for (const info of infos) {
66
- if (info === null || info === undefined || typeof info !== 'object') continue;
67
- const amount = typeof info.total_balance === 'string' ? Number(info.total_balance) : Number.NaN;
68
- if (!Number.isFinite(amount) || amount <= 0) continue;
69
- balances.push({
70
- currency: info.currency === 'USD' ? 'USD' : 'CNY',
71
- total: info.total_balance,
72
- });
73
- }
74
- return {
75
- currency: typeof one.currency === 'string' ? one.currency : 'CNY',
76
- total,
77
- parts,
78
- /* 老调用方不看这个字段;上层拿到就用,拿不到(没有 balances 键)就退回单币种 */
79
- balances: balances.length === 0 ? undefined : balances,
80
- };
111
+ if (data === null || data === undefined || typeof data !== 'object' || Array.isArray(data)) return null;
112
+ const billing = data.billing !== null && data.billing !== undefined
113
+ && typeof data.billing === 'object' && Array.isArray(data.billing) !== true ? data.billing : null;
114
+ /* 严格判空与类型:null / undefined / '' / 布尔 / 对象都算“没给”,继续往后找;
115
+ 不能 Number(null)=0 显示 0.00,也不能把 true 当 1。 */
116
+ const present = (value) => (typeof value === 'number' && Number.isFinite(value))
117
+ || (typeof value === 'string' && value.trim().length > 0);
118
+ let raw = present(data.balance) ? data.balance : null;
119
+ if (raw === null && billing !== null && present(billing.balance)) raw = billing.balance;
120
+ if (raw === null && present(data.remaining)) raw = data.remaining;
121
+ if (raw === null) return null;
122
+ const amount = typeof raw === 'number' ? raw : Number(String(raw).trim());
123
+ if (Number.isFinite(amount) !== true) return null;
124
+ /* 币种优先 data.currency / billing.currency / unit;都没有给空串,不猜 USD/CNY。 */
125
+ const unit = data.currency || (billing !== null ? billing.currency : null) || (billing !== null ? billing.unit : null) || data.unit;
126
+ const rawCode = typeof unit === 'string' ? unit.trim().toUpperCase() : '';
127
+ const code = rawCode === 'RMB' || rawCode === '¥' || rawCode === '¥' ? 'CNY' : (rawCode === '$' ? 'USD' : rawCode);
128
+ return { currency: code, total: amount.toFixed(2), parts: [] };
81
129
  }
82
130
  },
83
131
  {
@@ -386,6 +434,8 @@ function dateOfMs(value) {
386
434
  function adapterFor(provider, model) {
387
435
  const providerText = String(provider === undefined || provider === null ? '' : provider).toLowerCase().trim();
388
436
  const modelText = String(model === undefined || model === null ? '' : model).toLowerCase().trim();
437
+ /* Magpie exposes no verified upstream identity; never infer a vendor from its model name. */
438
+ if (providerText.includes('magpie')) return null;
389
439
  const pick = (text) => {
390
440
  if (text.length === 0) return null;
391
441
  for (let i = 0; i < adapters.length; i += 1) {
@@ -496,4 +546,237 @@ function pluginRoutesIn(table) {
496
546
  * 绿了也不代表线上安全。
497
547
  */
498
548
 
499
- export { adapters, adapterFor, adaptersFor, pluginRoutesIn, LOCAL_READONLY_VERBS, LOCAL_NEVER_PROBE };
549
+ /* ------------------------------------------------------------------ Magpie 网关 */
550
+
551
+ /**
552
+ * Magpie 是本机聚合网关:provider 固定是 `magpie`(或 `remote-magpie`),真实上游藏在
553
+ * 模型 id 的 `owned_by` / 前缀里;权威额度源是 `GET <base>/v1/magpie/quotas`
554
+ * (零配置、无需 API Key)。下面只放**纯解析**,发请求由 index.js 负责 —— 这样能单测。
555
+ *
556
+ * 字段语义(2026-11-12 实测,务必别搞反):
557
+ * · `window.used` / `window.remaining` 都是 **0–100 的百分比**;
558
+ * · `window.amount` 是**已用数量**(= limit × used%),**不是剩余**;
559
+ * · 剩余数量 = `limit - amount`(也等于 `limit × remaining%`,两种算法实测一致)。
560
+ * 调研文档曾把 amount 误写成"剩余金额",这里以实测为准(拿 used 当余额会显示一个
561
+ * 看起来合理的错数,正是本项目反复强调要避免的事)。
562
+ */
563
+ const MAGPIE_CURRENCY_HINTS = [
564
+ ['CNY', ['¥', '¥', 'cny', 'rmb', '元']],
565
+ ['USD', ['$', 'usd']],
566
+ ['EUR', ['€', 'eur']],
567
+ ['GBP', ['£', 'gbp']],
568
+ ];
569
+
570
+ /** `/v1/models` 里 `id` → `owned_by`;取不到返回 null(不猜)。 */
571
+ function magpieModelProvider(modelsData, model) {
572
+ const want = String(model === undefined || model === null ? '' : model);
573
+ if (want.length === 0) return null;
574
+ const list = modelsData !== null && modelsData !== undefined && Array.isArray(modelsData.data) ? modelsData.data : [];
575
+ for (let i = 0; i < list.length; i += 1) {
576
+ const one = list[i];
577
+ if (one !== null && one !== undefined && one.id === want && typeof one.owned_by === 'string' && one.owned_by.length > 0) {
578
+ return one.owned_by;
579
+ }
580
+ }
581
+ /* 唯一后缀匹配:短名 `gpt-6-astra` 能命中 `selen/gpt-6-astra`;但同一短名属于多个
582
+ owner(orbis 也有 `orbis/gpt-6-astra`)时必须放弃,别的 owner 不能算到 selen 头上。 */
583
+ const suffix = '/' + want;
584
+ const owners = [];
585
+ for (let i = 0; i < list.length; i += 1) {
586
+ const one = list[i];
587
+ if (one === null || one === undefined || typeof one.id !== 'string' || one.id.endsWith(suffix) !== true) continue;
588
+ if (typeof one.owned_by !== 'string' || one.owned_by.length === 0) continue;
589
+ if (owners.indexOf(one.owned_by) < 0) owners.push(one.owned_by);
590
+ }
591
+ return owners.length === 1 ? owners[0] : null;
592
+ }
593
+
594
+ /** 模型 id 前缀(`group/deepseek-flash` → `group`、`workbuddy/x` → `workbuddy`)兜底。 */
595
+ function magpieModelPrefix(model) {
596
+ const text = String(model === undefined || model === null ? '' : model);
597
+ const slash = text.indexOf('/');
598
+ return slash > 0 ? text.slice(0, slash) : null;
599
+ }
600
+
601
+ /** quotas 里属于某个 provider 的账号条目(provider 名大小写不敏感;orbi 是 DSH 侧对 orbis 的写法)。 */
602
+ function magpieQuotaEntries(quotasData, provider) {
603
+ let want = String(provider === undefined || provider === null ? '' : provider).trim().toLowerCase();
604
+ if (want === 'orbi') want = 'orbis';
605
+ const list = quotasData !== null && quotasData !== undefined && Array.isArray(quotasData.data) ? quotasData.data : [];
606
+ if (want.length === 0) return [];
607
+ return list.filter((one) => one !== null && one !== undefined && typeof one.provider === 'string'
608
+ && one.provider.toLowerCase() === want);
609
+ }
610
+
611
+ /** 一个窗口的剩余数量;认不出返回 null(绝不猜)。优先 limit - amount,其次 limit × remaining%。 */
612
+ function magpieWindowRemaining(window) {
613
+ if (window === null || window === undefined || typeof window !== 'object') return null;
614
+ const limit = Number(window.limit);
615
+ const amount = Number(window.amount);
616
+ if (Number.isFinite(limit) && Number.isFinite(amount)) return Math.max(0, limit - amount);
617
+ const remainPct = Number(window.remaining);
618
+ if (Number.isFinite(limit) && Number.isFinite(remainPct)) return Math.max(0, (limit * remainPct) / 100);
619
+ return null;
620
+ }
621
+
622
+ /**
623
+ * 账号里代表「剩余积分」的窗口:优先 Total credits,其次 Credits,再到第一个 credits 单位窗口。
624
+ * 积分窗口的判据是 `unit === 'credits'`(token 估算窗口没有 unit,不能当积分)。
625
+ */
626
+ function magpiePrimaryCreditsWindow(entry) {
627
+ const windows = entry !== null && entry !== undefined && Array.isArray(entry.windows) ? entry.windows : [];
628
+ const creditWindows = windows.filter((one) => one !== null && one !== undefined && one.unit === 'credits');
629
+ if (creditWindows.length === 0) return null;
630
+ const order = ['Total credits', 'Credits'];
631
+ for (let i = 0; i < order.length; i += 1) {
632
+ const hit = creditWindows.filter((one) => one.name === order[i])[0];
633
+ if (hit !== undefined) return hit;
634
+ }
635
+ return creditWindows[0];
636
+ }
637
+
638
+ /** `'¥0.03'` → `{ currency:'CNY', amount:0.03 }`;认不出币种给空串、认不出数字给 null。 */
639
+ function magpieParseMoney(text) {
640
+ const raw = String(text === undefined || text === null ? '' : text).trim();
641
+ if (raw.length === 0) return null;
642
+ const match = raw.match(/-?\d+(?:\.\d+)?/);
643
+ if (match === null) return null;
644
+ const amount = Number(match[0]);
645
+ if (Number.isFinite(amount) !== true) return null;
646
+ const lower = raw.toLowerCase();
647
+ let currency = '';
648
+ for (let i = 0; i < MAGPIE_CURRENCY_HINTS.length; i += 1) {
649
+ const code = MAGPIE_CURRENCY_HINTS[i][0];
650
+ const hints = MAGPIE_CURRENCY_HINTS[i][1];
651
+ if (hints.some((hint) => lower.indexOf(hint) >= 0 || raw.indexOf(hint) >= 0)) { currency = code; break; }
652
+ }
653
+ return { currency, amount };
654
+ }
655
+
656
+ /** 一个账号 → 统一口径 `{ mode:'credits', remaining, limit }` / `{ mode:'money', currency, amount }`;认不出 null。 */
657
+ function magpieEntryPrimary(entry) {
658
+ if (entry === null || entry === undefined || typeof entry !== 'object') return null;
659
+ if (typeof entry.balance === 'string' && entry.balance.trim().length > 0) {
660
+ const money = magpieParseMoney(entry.balance);
661
+ if (money !== null) return { mode: 'money', currency: money.currency, amount: money.amount };
662
+ }
663
+ const window = magpiePrimaryCreditsWindow(entry);
664
+ if (window !== null) {
665
+ const remaining = magpieWindowRemaining(window);
666
+ const limit = Number(window.limit);
667
+ if (remaining !== null && Number.isFinite(limit) && limit > 0) return { mode: 'credits', remaining: remaining, limit: limit };
668
+ }
669
+ return null;
670
+ }
671
+
672
+ /** 账号列表 → 积分套餐气泡的行(每个账号一行,展示"剩余 / 总量")。 */
673
+ function magpieAccountRows(entries, providerName) {
674
+ const rows = [];
675
+ for (let i = 0; i < entries.length; i += 1) {
676
+ const entry = entries[i];
677
+ const primary = magpieEntryPrimary(entry);
678
+ if (primary === null || primary.mode !== 'credits') continue;
679
+ const who = typeof entry.user === 'string' && entry.user.length > 0
680
+ ? entry.user
681
+ : (typeof entry.plan === 'string' && entry.plan.length > 0 ? entry.plan : 'account');
682
+ rows.push({
683
+ name: who + (providerName.length > 0 ? ' · ' + providerName : ''),
684
+ used: Math.max(0, primary.limit - primary.remaining),
685
+ total: primary.limit,
686
+ expireAt: null,
687
+ refreshAt: null,
688
+ monthly: false,
689
+ });
690
+ }
691
+ return rows;
692
+ }
693
+
694
+ /**
695
+ * Magpie quotas + provider/账号 → 余额项口径。
696
+ *
697
+ * @param {object} quotasData `/v1/magpie/quotas` 的 JSON
698
+ * @param {{provider?:string, providerName?:string, account?:string|null}} options
699
+ * @returns {{ok:true, mode:'credits'|'money', currency, total, isCredits?, rewards?, toppedUp?, granted?, parts?, providerName, account}
700
+ * |{ok:false, reason:string, detail?, providerName}}
701
+ */
702
+ function magpieBalanceOf(quotasData, options) {
703
+ const opts = options === undefined || options === null ? {} : options;
704
+ const providerName = typeof opts.providerName === 'string' && opts.providerName.length > 0
705
+ ? opts.providerName
706
+ : String(opts.provider === undefined || opts.provider === null ? '' : opts.provider);
707
+ const entries = magpieQuotaEntries(quotasData, providerName);
708
+ if (entries.length === 0) return { ok: false, reason: 'magpie-provider-not-found', providerName: providerName };
709
+
710
+ /* 选中哪个账号:先按 account 精确匹配 user;只有一个账号时直接用它;否则汇总全池。 */
711
+ let chosen = null;
712
+ if (typeof opts.account === 'string' && opts.account.length > 0) {
713
+ const want = opts.account.trim().toLowerCase();
714
+ chosen = entries.filter((one) => typeof one.user === 'string' && one.user.trim().toLowerCase() === want)[0] ?? null;
715
+ }
716
+ if (chosen === null && entries.length === 1) chosen = entries[0];
717
+
718
+ const selected = chosen === null ? entries : [chosen];
719
+ /* 选中账号自身带 error(如 ZCode 没有套餐)时如实报错,不显示 0。 */
720
+ if (chosen !== null && typeof chosen.error === 'string' && chosen.error.length > 0) {
721
+ return { ok: false, reason: 'magpie-upstream-error', detail: chosen.error.slice(0, 240), providerName: providerName };
722
+ }
723
+
724
+ const primaries = [];
725
+ for (let i = 0; i < selected.length; i += 1) {
726
+ primaryOf(selected[i], primaries);
727
+ }
728
+ if (primaries.length === 0) {
729
+ const errors = entries.filter((one) => typeof one.error === 'string' && one.error.length > 0);
730
+ if (errors.length > 0) {
731
+ return { ok: false, reason: 'magpie-upstream-error', detail: errors[0].error.slice(0, 240), providerName: providerName };
732
+ }
733
+ return { ok: false, reason: 'magpie-no-balance-info', providerName: providerName };
734
+ }
735
+
736
+ const mode = primaries[0].mode;
737
+ const same = primaries.filter((one) => one.mode === mode);
738
+ const accountName = chosen !== null && typeof chosen.user === 'string' ? chosen.user : null;
739
+ if (mode === 'money') {
740
+ let sum = 0;
741
+ for (let i = 0; i < same.length; i += 1) sum += same[i].amount;
742
+ const total = sum.toFixed(2);
743
+ return {
744
+ ok: true, mode: 'money', currency: same[0].currency, total: total,
745
+ toppedUp: total, granted: '0.00', parts: [{ label: 'toppedUp', amount: total }],
746
+ providerName: providerName, account: accountName,
747
+ };
748
+ }
749
+ let remain = 0;
750
+ for (let i = 0; i < same.length; i += 1) remain += same[i].remaining;
751
+ return {
752
+ ok: true, mode: 'credits', currency: '', total: formatCredits(remain), isCredits: true,
753
+ rewards: magpieAccountRows(entries, providerName), providerName: providerName, account: accountName,
754
+ };
755
+ }
756
+
757
+ /* 内部小工具:把一条 entry 的统一口径压进数组(抽出来只为让上面主逻辑短一点)。 */
758
+ function primaryOf(entry, out) {
759
+ const primary = magpieEntryPrimary(entry);
760
+ if (primary !== null) out.push(primary);
761
+ }
762
+
763
+ /** `/v1/magpie/route` → 会话语义下的账号名;形状未定,按常见字段稳健提取,认不出 null。 */
764
+ function magpieAccountFromRoute(routeData) {
765
+ if (routeData === null || routeData === undefined || typeof routeData !== 'object') return null;
766
+ const route = routeData.route;
767
+ if (typeof route === 'string' && route.length > 0) return route;
768
+ if (route !== null && route !== undefined && typeof route === 'object') {
769
+ const keys = ['providerAccount', 'account', 'user', 'name'];
770
+ for (let i = 0; i < keys.length; i += 1) {
771
+ if (typeof route[keys[i]] === 'string' && route[keys[i]].length > 0) return route[keys[i]];
772
+ }
773
+ }
774
+ if (typeof routeData.providerAccount === 'string' && routeData.providerAccount.length > 0) return routeData.providerAccount;
775
+ return null;
776
+ }
777
+
778
+ export {
779
+ adapters, adapterFor, adaptersFor, pluginRoutesIn, parseDeepSeekBalance, LOCAL_READONLY_VERBS, LOCAL_NEVER_PROBE,
780
+ magpieModelProvider, magpieModelPrefix, magpieQuotaEntries, magpieBalanceOf,
781
+ magpieAccountFromRoute, magpieParseMoney, magpieEntryPrimary,
782
+ };