dsh-desktop-statusbar 3.0.7 → 3.0.8

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 CHANGED
@@ -76,23 +76,24 @@ window.__ModuleLoader__.load({
76
76
  */
77
77
  const CONFIG_VERSION = 6;
78
78
  /** 插件版本:显示在设置页底部,用来确认页面加载的是哪一版客户端代码。 */
79
- const VERSION = "3.0.7";
79
+ const VERSION = "3.0.8";
80
80
  /** 官方参考价的版本:官方调价时改这个数字,老价格库会自动并入新参考价。
81
81
  * v4:官方模型目录(MODEL_PRESENTATION)**默认全部加入价格表**(按官网价播种),
82
82
  * 不再需要「点名字加入」;用户删掉的模型可用「恢复默认」找回。
83
83
  * v5:清理旧版目录点选加入、现已下架的官方模型(它们不该落进「自定义模型」组)。
84
84
  * v6:官方目录**新增**的模型自动补播给老用户(只补缺失项,已有条目不动)。
85
85
  * v7:每个条目补内部基准价 `base`(切币种来回切不漂的锚点,见 normalizeBase)。
86
- * v8:官方目录新增 Claude Fable 5.2,老用户价格库自动补播(只补缺失项,已有条目不覆盖)。 */
87
- const PRICE_VERSION = 8;
86
+ * v8:官方目录新增 Claude Fable 5.2,老用户价格库自动补播(只补缺失项,已有条目不覆盖)。
87
+ * v10:补 GPT-6.2 Astra / Sol,老用户价格库自动补播(只补缺失项,已有条目不覆盖)。 */
88
+ const PRICE_VERSION = 10;
88
89
  /** 官方目录默认播种的版本(v4 一次性迁移;后续版本不再重复播种)。 */
89
90
  const PRICE_SEED_VERSION = 4;
90
91
  /** 清理已下架官方残留条目的版本(v5 起;v8 再清一次 MiniMax / 阶跃星辰两个默认条目)。
91
92
  * v8 起与 PRICE_VERSION 同步:价格库版本 <8 的老用户升级时清理一次,≥8 不再重复。 */
92
93
  const PRICE_RETIRED_PRUNE_VERSION = 8;
93
- /** 补播官方目录新增模型的版本(v6 起每次目录加型号都靠这条自动补;v8 补 Claude Fable 5.2)。
94
+ /** 补播官方目录新增模型的版本(v6 起每次目录加型号都靠这条自动补;v8 补 Claude Fable 5.2;v10 补 GPT-6.2 Astra / Sol)。
94
95
  * 只补当前价格库缺失项,已有条目(用户改过的价 / 倍率)一律不动。 */
95
- const PRICE_BACKFILL_VERSION = 8;
96
+ const PRICE_BACKFILL_VERSION = 10;
96
97
  /** 给价格条目补「基准价」的版本(v7 一次性迁移;缺 base 的条目按当前值 + 当前币种补,不改数值)。 */
97
98
  const PRICE_BASE_VERSION = 7;
98
99
  /** 项目主页:设置页那个「去 GitHub 点 star」按钮跳这里(与 package.json 的 repository 同址)。 */
@@ -125,7 +126,7 @@ window.__ModuleLoader__.load({
125
126
  };
126
127
 
127
128
  /**
128
- * 官方模型目录(数据源:docs/official-models.json,2026-11-04 核验、2026-11-10 补 Claude Fable 5.2;每厂商只留最新一代)。
129
+ * 官方模型目录(数据源:docs/official-models.json,2026-11-04 核验、2026-11-10 补 Claude Fable 5.2、2026-11-22 补 GPT-6.2;每厂商只留最新一代)。
129
130
  * 只保留 UI 需要的两样:厂商 id + 官方价;来源链接 / 备注 / 分档说明不进界面。
130
131
  * 价格字段为 null = 官网未公布 → 不参与自动计费(不要填 0)。
131
132
  * 厂商与模型顺序 = JSON 的 vendors / models 顺序。
@@ -136,6 +137,8 @@ window.__ModuleLoader__.load({
136
137
  "claude-opus-5.5": { manufacturer: "anthropic", price: { tiered: false, currency: "USD", peak: { input: 4, cacheRead: 0.2, cacheWrite: 5, output: 20 }, offPeak: { input: 4, cacheRead: 0.2, cacheWrite: 5, output: 20 } } },
137
138
  "claude-sonnet-5.5": { manufacturer: "anthropic", price: { tiered: false, currency: "USD", peak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 }, offPeak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 } } },
138
139
  "claude-haiku-5.5": { manufacturer: "anthropic", price: { tiered: false, currency: "USD", peak: { input: 0.1, cacheRead: 0.01, cacheWrite: 0.125, output: 0.5 }, offPeak: { input: 0.1, cacheRead: 0.01, cacheWrite: 0.125, output: 0.5 } } },
140
+ "gpt-6.2-astra": { manufacturer: "openai", price: { tiered: false, currency: "USD", peak: { input: 8, cacheRead: 0.4, cacheWrite: 10, output: 40 }, offPeak: { input: 8, cacheRead: 0.4, cacheWrite: 10, output: 40 } } },
141
+ "gpt-6.2-sol": { manufacturer: "openai", price: { tiered: false, currency: "USD", peak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 }, offPeak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 } } },
139
142
  "gpt-6-astra": { manufacturer: "openai", price: { tiered: false, currency: "USD", peak: { input: 10, cacheRead: 1, cacheWrite: 12.5, output: 50 }, offPeak: { input: 10, cacheRead: 1, cacheWrite: 12.5, output: 50 } } },
140
143
  "gpt-6.1-sol": { manufacturer: "openai", price: { tiered: false, currency: "USD", peak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 }, offPeak: { input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 } } },
141
144
  "gpt-6.1-terra": { manufacturer: "openai", price: { tiered: false, currency: "USD", peak: { input: 1, cacheRead: 0.05, cacheWrite: 1.25, output: 5 }, offPeak: { input: 1, cacheRead: 0.05, cacheWrite: 1.25, output: 5 } } },
@@ -1895,7 +1898,8 @@ function platformOfBook(book, platforms, model) {
1895
1898
  */
1896
1899
  const PRICE_BACKFILL_ADDED = [
1897
1900
  { version: 6, names: ["kimi-k3"] },
1898
- { version: 8, names: ["claude-fable-5.2"] }
1901
+ { version: 8, names: ["claude-fable-5.2"] },
1902
+ { version: 10, names: ["gpt-6.2-astra", "gpt-6.2-sol"] }
1899
1903
  ];
1900
1904
  /** 从 fromVersion 升到当前版本时需要补播的官方新模型(只含新增项,已有条目不动)。 */
1901
1905
  function officialBackfillModels(fromVersion) {
@@ -2077,6 +2081,8 @@ function platformOfBook(book, platforms, model) {
2077
2081
  tipCreditsRefreshLatest: " · {date} 刷新(最近)",
2078
2082
  tipCreditsExpireLatest: " · {date} 到期(最近)",
2079
2083
  tipCreditsLeft: "剩余 {left} / {total}",
2084
+ quotaFiveHour: "5 小时额度",
2085
+ quotaSevenDay: "7 天额度",
2080
2086
 
2081
2087
  secSegments: "统计字段",
2082
2088
  secSegmentsHint: "勾选显示;按住拖动调整顺序。",
@@ -2251,6 +2257,8 @@ function platformOfBook(book, platforms, model) {
2251
2257
  tipCreditsRefreshLatest: " · refreshes {date} (nearest)",
2252
2258
  tipCreditsExpireLatest: " · expires {date} (nearest)",
2253
2259
  tipCreditsLeft: "{left} / {total} left",
2260
+ quotaFiveHour: "5-hour quota",
2261
+ quotaSevenDay: "7-day quota",
2254
2262
 
2255
2263
  secSegments: "Stats fields",
2256
2264
  secSegmentsHint: "Select to show; drag to reorder.",
@@ -2418,6 +2426,8 @@ function platformOfBook(book, platforms, model) {
2418
2426
  "tipCreditsRefreshLatest": " · {date} 更新(直近)",
2419
2427
  "tipCreditsExpireLatest": " · {date} 期限(直近)",
2420
2428
  "tipCreditsLeft": "残り {left} / {total}",
2429
+ "quotaFiveHour": "5時間クォータ",
2430
+ "quotaSevenDay": "7日間クォータ",
2421
2431
  "secSegments": "統計項目",
2422
2432
  "secSegmentsHint": "選択して表示、ドラッグで並べ替え。",
2423
2433
  "secPrices": "カスタムモデル価格",
@@ -2579,6 +2589,8 @@ function platformOfBook(book, platforms, model) {
2579
2589
  "tipCreditsRefreshLatest": " · se renueva {date} (próxima)",
2580
2590
  "tipCreditsExpireLatest": " · caduca {date} (próxima)",
2581
2591
  "tipCreditsLeft": "Quedan {left} / {total}",
2592
+ "quotaFiveHour": "Cuota de 5 horas",
2593
+ "quotaSevenDay": "Cuota de 7 días",
2582
2594
  "secSegments": "Campos de estadísticas",
2583
2595
  "secSegmentsHint": "Marca para mostrar; arrastra para reordenar.",
2584
2596
  "secPrices": "Precios personalizados de modelos",
@@ -2740,6 +2752,8 @@ function platformOfBook(book, platforms, model) {
2740
2752
  "tipCreditsRefreshLatest": " · renouvelé le {date} (le plus proche)",
2741
2753
  "tipCreditsExpireLatest": " · expire le {date} (le plus proche)",
2742
2754
  "tipCreditsLeft": "{left} / {total} restants",
2755
+ "quotaFiveHour": "Quota 5 heures",
2756
+ "quotaSevenDay": "Quota 7 jours",
2743
2757
  "secSegments": "Champs de statistiques",
2744
2758
  "secSegmentsHint": "Sélectionnez pour afficher ; faites glisser pour réorganiser.",
2745
2759
  "secPrices": "Prix des modèles personnalisés",
@@ -2901,6 +2915,8 @@ function platformOfBook(book, platforms, model) {
2901
2915
  "tipCreditsRefreshLatest": " · erneuert sich {date} (nächste)",
2902
2916
  "tipCreditsExpireLatest": " · verfällt {date} (nächste)",
2903
2917
  "tipCreditsLeft": "{left} / {total} übrig",
2918
+ "quotaFiveHour": "5-Stunden-Kontingent",
2919
+ "quotaSevenDay": "7-Tage-Kontingent",
2904
2920
  "secSegments": "Statistikfelder",
2905
2921
  "secSegmentsHint": "Zum Anzeigen auswählen; per Ziehen sortieren.",
2906
2922
  "secPrices": "Eigene Modellpreise",
@@ -3062,6 +3078,8 @@ function platformOfBook(book, platforms, model) {
3062
3078
  "tipCreditsRefreshLatest": " · обновление {date} (ближайшее)",
3063
3079
  "tipCreditsExpireLatest": " · истекает {date} (ближайшее)",
3064
3080
  "tipCreditsLeft": "осталось {left} / {total}",
3081
+ "quotaFiveHour": "Квота на 5 часов",
3082
+ "quotaSevenDay": "Квота на 7 дней",
3065
3083
  "secSegments": "Поля статистики",
3066
3084
  "secSegmentsHint": "Выберите для показа; перетащите для порядка.",
3067
3085
  "secPrices": "Свои цены моделей",
@@ -3223,6 +3241,8 @@ function platformOfBook(book, platforms, model) {
3223
3241
  "tipCreditsRefreshLatest": " · renova a {date} (mais próxima)",
3224
3242
  "tipCreditsExpireLatest": " · expira a {date} (mais próxima)",
3225
3243
  "tipCreditsLeft": "{left} / {total} restantes",
3244
+ "quotaFiveHour": "Cota de 5 horas",
3245
+ "quotaSevenDay": "Cota de 7 dias",
3226
3246
  "secSegments": "Campos de estatísticas",
3227
3247
  "secSegmentsHint": "Selecione para mostrar; arraste para reordenar.",
3228
3248
  "secPrices": "Preços de modelos personalizados",
@@ -4052,7 +4072,7 @@ function setModelCurrency(name, code, draftNow) {
4052
4072
  与弧长(percent,团队运行时是成员级最大/深层最小)不同源 —— 用户拍板:
4053
4073
  「环里的数字只显示主会话自己的上下文占用」,弧长仍按谁在跑切数据源。
4054
4074
  只显示整数(四舍五入);到 100 留空(14px 环心塞不下三位,回退的 4.5px 字号已删除)。
4055
- labelPercent 缺失 / 非数字 / null ⇒ 同样留空:不退回弧长的 percent(那是团队级数据,
4075
+ labelPercent 缺失 / 非数字 / null ⇒ 同样留空:不退回弧长的 percent(那是团队级数据,
4056
4076
 
4057
4077
  而且没有数据时 percent 也可能是 0,显示 "0" 会让用户误以为占用真的是 0)。 */
4058
4078
  const labelRaw = typeof labelPercent === "number" && Number.isFinite(labelPercent)
@@ -4066,8 +4086,12 @@ function setModelCurrency(name, code, draftNow) {
4066
4086
  : (state === "error" ? " dsb-ring-error" : (state === "approval" ? " dsb-ring-approval" : ""))));
4067
4087
  const offset = METER_CIRCUMFERENCE * (1 - displayPercent / 100);
4068
4088
  const dashes = notchDashes(compact);
4069
- return h("svg", {
4070
- className: "dsb-ring" + stateClass, key: "__ring", viewBox: "0 0 14 14", width: 14, height: 14
4089
+ /* 圆环 = 外层 span(相对定位,尺寸即 14px)套着 SVG(绝对铺满)+ 绝对定位居中的数字 span。
4090
+ 数字改用 HTML 覆盖层强制居中(flex align/justify center),彻底不依赖 SVG text 的
4091
+ dominantBaseline 基线 —— 那套基线在不同渲染环境里会偏,用户实测"有点不居中"。
4092
+ 数字只在 label 非空时渲染;100 与空数据留空(不生成节点)。 */
4093
+ const ringSvg = h("svg", {
4094
+ className: "dsb-ring", key: "__ring", viewBox: "0 0 14 14", width: 14, height: 14
4071
4095
  },
4072
4096
  h("circle", {
4073
4097
  className: "dsb-ring-track", cx: 7, cy: 7, r: METER_RADIUS,
@@ -4082,19 +4106,16 @@ function setModelCurrency(name, code, draftNow) {
4082
4106
  /* SVG 的弧默认从 3 点方向起,整体转 -90° 才是官方那种"12 点起、顺时针长" */
4083
4107
  transform: "rotate(-90 7 7)",
4084
4108
  strokeDasharray: METER_CIRCUMFERENCE, strokeDashoffset: offset
4085
- }),
4086
- /* 圆环中间显示占用数字(用户要"占用 80% 就在环里显示 80",不带百分号)。
4087
- 字号只由 CSS 一处固定 6px 决定(见 .dsb-ring-percent),这里不再写动态 fontSize。
4088
- 环心留空时仍是空 text 节点,结构(底环 + 进度弧 + 数字)不变。
4089
- dy 0.25px:SVG text 的 dominantBaseline="central" 在老内核上按字体度量居中,
4090
- 实测比视觉中心略高约半像素,给一点向下的基线微调补齐。 */
4091
- h("text", {
4092
- className: "dsb-ring-percent", x: 7, y: 7,
4093
- dy: "0.25px",
4094
- textAnchor: "middle", dominantBaseline: "central",
4095
- "aria-hidden": "true"
4096
- }, ringLabel)
4097
- )
4109
+ })
4110
+ );
4111
+ const percentSpan = ringLabel === ""
4112
+ ? null
4113
+ : h("span", {
4114
+ className: "dsb-ring-percent", key: "__pct", "aria-hidden": "true"
4115
+ }, ringLabel);
4116
+ return h("span", {
4117
+ className: "dsb-ring-wrap" + stateClass, key: "__ringwrap"
4118
+ }, percentSpan === null ? [ringSvg] : [ringSvg, percentSpan]);
4098
4119
  }
4099
4120
 
4100
4121
  /** 气泡自己那一圈描边的宽度(.dsb-tip 的 box-shadow spread:0 0 0 .5px):
@@ -6097,6 +6118,59 @@ function setModelCurrency(name, code, draftNow) {
6097
6118
  return { title: t("tipCreditsTitle"), totalText: totalText, rewards: rows };
6098
6119
  }
6099
6120
 
6121
+ /**
6122
+ * 订阅型配额(Magpie 百分比窗口)→ **复用积分套餐面板**的数据形状。
6123
+ * 五小时/七天窗口各构成 creditsPanel 的一个 rewards 块:
6124
+ * { label: 本地化窗口名, valueText: '剩余 xx%', percent: 已用%, remainingText: '剩余 xx%' }
6125
+ * 进度条沿用 creditsPanel 的 barOf(.dsb-bar/.dsb-bar-seg,灰=剩余、透明=已用),
6126
+ * 行沿用 .dsb-meter-row —— 不新造组件、不新增 CSS,视觉与现有积分套餐一致。
6127
+ * 返回 null 表示没有可显示的窗口(此时调用方不给 quota 气泡)。
6128
+ */
6129
+ /**
6130
+ * 单个百分比窗口 → creditsPanel 的 reward 形状(quotaPanelView 主行与 items 共用这一份映射)。
6131
+ * 输入 {key?, name, used, remaining},输出 {name,label,valueText,percent,remainingText}。
6132
+ * label 本地化:优先按 key(fiveHour/sevenDay)→ 再按 name 子串兜底 → 再原样/占位。
6133
+ */
6134
+ function quotaRewardRow(one, t, fallbackLabel) {
6135
+ const used = Number(one.used);
6136
+ const remaining = Number(one.remaining);
6137
+ const usedPct = Math.max(0, Math.min(100, Number.isFinite(used) ? used : 0));
6138
+ const leftPct = (100 - usedPct).toFixed(2) + "%";
6139
+ let label;
6140
+ const key = typeof one.key === "string" ? one.key : "";
6141
+ const rawName = typeof one.name === "string" ? one.name.toLowerCase() : "";
6142
+ if (key === "fiveHour" || rawName.indexOf("5") >= 0 || rawName.indexOf("hour") >= 0) label = t("quotaFiveHour");
6143
+ else if (key === "sevenDay" || rawName.indexOf("7") >= 0 || rawName.indexOf("day") >= 0) label = t("quotaSevenDay");
6144
+ else label = typeof one.name === "string" && one.name.length > 0 ? one.name : (fallbackLabel !== undefined ? fallbackLabel : t("segBalance"));
6145
+ return { name: label, label: label, valueText: leftPct, percent: usedPct, remainingText: leftPct };
6146
+ }
6147
+ function quotaPanelView(windows, t) {
6148
+ const list = Array.isArray(windows) ? windows : [];
6149
+ const rows = [];
6150
+ list.forEach((one) => {
6151
+ if (one === null || one === undefined || typeof one !== "object") return;
6152
+ if (Number.isFinite(Number(one.used)) !== true || Number.isFinite(Number(one.remaining)) !== true) return;
6153
+ const main = quotaRewardRow(one, t);
6154
+ /* 逐账号明细(items):复用同一映射函数(账号名作 label、不带 key)。 */
6155
+ const rawItems = Array.isArray(one.items) ? one.items : [];
6156
+ const items = [];
6157
+ rawItems.forEach((it) => {
6158
+ if (it === null || it === undefined || typeof it !== "object") return;
6159
+ if (Number.isFinite(Number(it.used)) !== true || Number.isFinite(Number(it.remaining)) !== true) return;
6160
+ items.push(quotaRewardRow({ name: it.name, used: it.used, remaining: it.remaining }, t));
6161
+ });
6162
+ rows.push({
6163
+ name: main.name, label: main.label, valueText: main.valueText,
6164
+ percent: main.percent, remainingText: main.remainingText,
6165
+ count: items.length, items: items
6166
+ });
6167
+ });
6168
+ if (rows.length === 0) return null;
6169
+ /* totalText 填第一行剩余百分比(与行内 valueText 同源);此前是空串。 */
6170
+ const totalText = rows[0].valueText;
6171
+ return { title: t("segBalance"), totalText: totalText, rewards: rows };
6172
+ }
6173
+
6100
6174
  /** 单次调用的缓存命中率(%);缓存字段没上报或没有输入 token 时返回 null(算不出可信比例)。 */
6101
6175
  function hitRateOf(call) {
6102
6176
  if (call === null || call === undefined) return null;
@@ -6748,12 +6822,20 @@ function setModelCurrency(name, code, draftNow) {
6748
6822
  宿主侧 `spent` 字段照旧返回(智谱适配器会给),但客户端一律不画 ——
6749
6823
  这一行口径与「总计」不同源、又只在部分平台出现,
6750
6824
  摆在同一张气泡里容易被当成同一个数字。 */
6751
- const tip = {
6752
- kind: "rows",
6753
- title: t("segBalance"),
6754
- segments: balanceSegments,
6755
- rows: balanceRows
6756
- };
6825
+ /* 订阅型配额(Magpie 百分比窗口):底栏文字仍按 quotaLeft(剩余)显示,不变;
6826
+ 点击时若带非空 windows,则弹「五小时/七天」进度条面板(复用 creditsPanel)。
6827
+ 其它口径(金额/积分/无窗口的配额)保持原 rows 气泡。 */
6828
+ const quotaPanel = isQuota === true && Array.isArray(balance.windows) && balance.windows.length > 0
6829
+ ? quotaPanelView(balance.windows, t)
6830
+ : null;
6831
+ const tip = quotaPanel !== null
6832
+ ? { kind: "quota", title: t("segBalance"), panel: quotaPanel }
6833
+ : {
6834
+ kind: "rows",
6835
+ title: t("segBalance"),
6836
+ segments: balanceSegments,
6837
+ rows: balanceRows
6838
+ };
6757
6839
  /* 不足一分钱时官方显示 <¥0.01,这里跟着来 */
6758
6840
  if (balance.subCent === true) return { id: id, text: t("f_balanceSubCent", { symbol: balSymbol }), tip: tip };
6759
6841
  /* 底栏那行文字:**百分比配额走 `quotaLeft`(剩余),不走 `balance.total`(已用)**。
@@ -6871,7 +6953,13 @@ function setModelCurrency(name, code, draftNow) {
6871
6953
  * 整条规则挂在 html.dsb-on 上:这个类由插件挂载/卸载时增删(设置页里
6872
6954
  * **没有**「启用状态栏」开关,别按那个理解)。卸下后官方原本的统计行与
6873
6955
  * 上下文按钮随即恢复(否则关掉插件只剩一片空白)。 */
6874
- 'html.dsb-on [data-slot="conversation.composer.dock"] > *:not(.dsb-root):not(:has(.dsb-root)){display:none !important}',
6956
+ /* 只藏「含官方特征」的直接子节点(官方统计行包装层):用 :has() 认它是官方节点的祖先。
6957
+ 第三方插件注册的直接子节点没有官方特征 ⇒ 不匹配 ⇒ 绝不误藏。 */
6958
+ 'html.dsb-on [data-slot="conversation.composer.dock"] > *:not(.dsb-root):not(:has(.dsb-root)):has([data-composer-stat],button[aria-haspopup="dialog"][aria-label*="上下文"],button[aria-haspopup="dialog"][aria-label*="context used"],span[class$="_root"]>button[aria-haspopup="dialog"]){display:none !important}',
6959
+ /* 官方 InputBar 的 dock 根 [data-composer-dock]:同理只藏含官方特征的包装层,第三方直接子节点不动。 */
6960
+ 'html.dsb-on [data-composer-dock] > *:not(.dsb-root):not(:has(.dsb-root)):has([data-composer-stat],button[aria-haspopup="dialog"][aria-label*="上下文"],button[aria-haspopup="dialog"][aria-label*="context used"],span[class$="_root"]>button[aria-haspopup="dialog"]){display:none !important}',
6961
+ /* 官方 StatsPills(活动 / 数据库用量)根节点固定带 data-composer-stat,直接隐藏。 */
6962
+ 'html.dsb-on [data-composer-stat]{display:none !important}',
6875
6963
  /* 官方新版在输入卡片下方右侧另有一个上下文占用按钮:已被本插件的圆环接管,藏掉它。
6876
6964
  * 用 aria-label 认它(中文含"上下文"、英文含"context used",随语言变),不碰官方 hash 类名。 */
6877
6965
  'html.dsb-on button[aria-haspopup="dialog"][aria-label*="上下文"],html.dsb-on button[aria-haspopup="dialog"][aria-label*="context used"]{display:none !important}',
@@ -6879,9 +6967,15 @@ function setModelCurrency(name, code, draftNow) {
6879
6967
  * 它的类名是 CSS module 的 <hash>_root / <hash>_trigger,hash 随构建变,因此按后缀认结构:
6880
6968
  * root 外壳里包着带 aria-haspopup 的 trigger 按钮(trigger 本身没有 aria-label 可认)。 */
6881
6969
  'html.dsb-on span[class$="_root"]>button[aria-haspopup="dialog"][class$="_trigger"]{display:none !important}',
6970
+ /* 消息操作行(MessageIconActions 的 [data-clock="end"])里的官方 TurnUsagePanel(「用量 6.6M tok」):
6971
+ * 上面的精确后缀选择器在真实 DOM 可能认不到,这里按行作用域再兜一层(只碰这一行内的按钮外壳,
6972
+ * 不会误伤 composer 或别的按钮)。 */
6973
+ 'html.dsb-on [data-clock="end"] span[class$="_root"]{display:none !important}',
6974
+ 'html.dsb-on [data-clock="end"] span:has(>button[aria-haspopup="dialog"]){display:none !important}',
6882
6975
  ".dsb-root{display:flex;align-items:center;justify-content:center;gap:2px;width:100%;max-width:var(--dsh-chat-content-width);box-sizing:border-box;padding:4px calc(var(--dsh-composer-side-clearance) + 16px) 0;margin:0 auto;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
6883
6976
  /* 上下文占用:圆环、分段小条与分项面板都按官方 ContextMeter 的几何与配色复刻 */
6884
- ".dsb-ring{flex:none;width:14px;height:14px}",
6977
+ ".dsb-ring-wrap{position:relative;display:inline-flex;width:14px;height:14px;flex:none;align-items:center;justify-content:center}",
6978
+ ".dsb-ring{position:absolute;inset:0;width:14px;height:14px}",
6885
6979
  ".dsb-ring-btn{position:relative;display:inline-flex;align-items:center;justify-content:center;flex:none;padding:3px;margin-right:5px;background:0 0;border:none;border-radius:50%;cursor:pointer;color:var(--dsw-alias-label-tertiary)}",
6886
6980
  '.dsb-ring-btn:hover,.dsb-ring-btn[aria-expanded="true"]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.1));color:var(--dsw-alias-label-secondary)}',
6887
6981
  ".dsb-seg-click{position:relative;cursor:pointer;border-radius:999px;padding:1px 6px;margin:0 -6px}",
@@ -6889,7 +6983,7 @@ function setModelCurrency(name, code, draftNow) {
6889
6983
  ".dsb-ring-track{fill:none;stroke:var(--dsw-alias-border-l3,rgba(127,127,127,.25));stroke-width:2px}",
6890
6984
  ".dsb-ring-fill{fill:none;stroke:var(--dsw-alias-label-tertiary);stroke-width:2px;stroke-linecap:round}",
6891
6985
  /* 环心的占用数字:填色跟随主题文字色、细字重、不吃鼠标事件(否则会挡住圆环按钮的点击/悬停) */
6892
- ".dsb-ring-percent{fill:var(--dsw-alias-label-secondary,currentColor);font-size:6px;font-weight:600;line-height:1;pointer-events:none;text-anchor:middle;dominant-baseline:central}",
6986
+ ".dsb-ring-percent{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:12px;transform:scale(0.5);transform-origin:center center;font-weight:600;line-height:1;pointer-events:none;color:var(--dsw-alias-label-secondary,currentColor);font-variant-numeric:tabular-nums}",
6893
6987
  /* 运行时:绿色那段在淡灰圆圈里匀速转,像加载圈。
6894
6988
  -90° 必须写进关键帧:circle 上的 SVG transform="rotate(-90 7 7)"(把弧的起点挪到 12 点)
6895
6989
  会被 CSS transform 整个覆盖,不写回来就会从 3 点起、看起来跑偏。
@@ -9665,6 +9759,8 @@ function setModelCurrency(name, code, draftNow) {
9665
9759
  /* 积分套餐气泡的下钻层:null = 根视图,数字 = 点开了第几个聚合行(×N 那行)。
9666
9760
  换字段 / 收起气泡 / 点标题返回都清掉,下次打开回到套餐列表。 */
9667
9761
  const [creditSub, setCreditSub] = react.useState(null);
9762
+ /* 订阅配额下钻的独立下标(与积分套餐 creditSub 分开,互不串状态)。 */
9763
+ const [quotaSub, setQuotaSub] = react.useState(null);
9668
9764
  /* 子视图「每列几行」:默认 3 行一列;量到一排放不下(列被折到下一排)就
9669
9765
  逐档 +1(最多 12 行,见下面气泡定位那条 layout effect)。换字段 / 换子视图都重置回 3。
9670
9766
  **名字保留 `toolRows`(历史原因),但它现在服务三个列表**:工具调用、技能注入、
@@ -10146,7 +10242,7 @@ function setModelCurrency(name, code, draftNow) {
10146
10242
  跟着 scroll 收起的话,气泡会在这些时刻莫名其妙消失。 */
10147
10243
  react.useEffect(() => {
10148
10244
  if (tipId === null) return undefined;
10149
- const close = () => { setTipId(null); setTipPos(null); setTipSub(null); setCreditSub(null); };
10245
+ const close = () => { setTipId(null); setTipPos(null); setTipSub(null); setCreditSub(null); setQuotaSub(null); };
10150
10246
  /**
10151
10247
  * 点面板外部就收起。
10152
10248
  *
@@ -10434,20 +10530,49 @@ function setModelCurrency(name, code, draftNow) {
10434
10530
  const OFFICIAL_SELECTORS = [
10435
10531
  'button[aria-haspopup="dialog"][aria-label*="上下文"]',
10436
10532
  'button[aria-haspopup="dialog"][aria-label*="context used"]',
10437
- 'span[class$="_root"]>button[aria-haspopup="dialog"][class$="_trigger"]'
10533
+ 'span[class$="_root"]>button[aria-haspopup="dialog"][class$="_trigger"]',
10534
+ '[data-composer-stat]',
10535
+ '[data-clock="end"] span:has(>button[aria-haspopup="dialog"])'
10438
10536
  ];
10439
10537
  const OFFICIAL = OFFICIAL_SELECTORS.join(",");
10440
10538
  /* el -> 我们改之前它的行内 display(可能为空串),卸载时逐个还原 */
10441
10539
  const hidden = new Map();
10442
- const dockOf = () => document.querySelector('[data-slot="conversation.composer.dock"]');
10443
- /* 只藏 dock 子树里匹配官方选择器的节点;别的节点(含第三方插件)一概不碰。 */
10540
+ /* 官方 InputBar 的 dock 根节点是 [data-composer-dock](.dock),把 slot 与
10541
+ ContextMeter/图标等官方兄弟节点都放进去;slot 只是它的子节点之一。优先查这个根,
10542
+ 老结构没有时退回 slot(行为不变)。 */
10543
+ const dockOf = () => document.querySelector("[data-composer-dock]")
10544
+ || document.querySelector('[data-slot="conversation.composer.dock"]');
10545
+ /* 独立隐藏一个节点(记下原行内 display,卸载还原),由 sweep 复用。 */
10546
+ const hideNode = (node) => {
10547
+ if (node === null || node === undefined || node.nodeType !== 1) return;
10548
+ if (node.style.display !== "none") {
10549
+ if (!hidden.has(node)) hidden.set(node, node.style.display);
10550
+ node.style.display = "none";
10551
+ }
10552
+ };
10553
+ /* 只藏**官方节点**以及它向上最近的、直属 dock 的包装层:
10554
+ · 先藏 dock 子树里匹配 OFFICIAL 的所有节点;
10555
+ · 再对每个官方节点,向上找它「最近的、parent 恰为 dock 的祖先」,一起藏掉
10556
+ (官方有时把 ContextMeter/StatsPills 包在一层外壳 div 里,那层本身不带官方特征)。
10557
+ **绝不无条件隐藏 dock 的其他直接子节点** —— 第三方插件后插入的直接子节点
10558
+ 只要没有任何官方特征,一律不碰(旧写法会把它们一起藏掉,实测误伤)。 */
10444
10559
  const sweep = () => {
10445
10560
  const dock = dockOf();
10446
10561
  if (dock === null || dock === undefined) return null;
10447
- Array.from(dock.querySelectorAll(OFFICIAL)).forEach((node) => {
10448
- if (node.style.display !== "none") {
10449
- if (!hidden.has(node)) hidden.set(node, node.style.display);
10450
- node.style.display = "none";
10562
+ const officials = Array.from(dock.querySelectorAll(OFFICIAL));
10563
+ officials.forEach(hideNode);
10564
+ officials.forEach((node) => {
10565
+ let cur = node;
10566
+ while (cur !== null && cur !== undefined && cur.parentNode !== null && cur.parentNode !== dock) {
10567
+ cur = cur.parentNode;
10568
+ }
10569
+ /* cur 现在要么是 dock 的直接子节点(parent=dock),要么是 dock 本身/越界。
10570
+ 双重保险:它自身是 .dsb-root、或**包含** .dsb-root(官方与本插件根同层)时都不藏,
10571
+ 否则会把整层连本插件状态栏一起藏掉。 */
10572
+ if (cur !== null && cur !== undefined && cur !== dock && cur.nodeType === 1
10573
+ && !(cur.classList !== undefined && cur.classList.contains("dsb-root"))
10574
+ && !(typeof cur.querySelector === "function" && cur.querySelector(".dsb-root") !== null)) {
10575
+ hideNode(cur);
10451
10576
  }
10452
10577
  });
10453
10578
  return dock;
@@ -10462,9 +10587,11 @@ function setModelCurrency(name, code, draftNow) {
10462
10587
  /* 只观察 childList:我们自己写 display 是 attribute 变动,不观察它就不会自激。
10463
10588
  老环境 / 测试替身没有 MutationObserver 时退回"只清扫一次",行为不退化。 */
10464
10589
  let observer = null;
10590
+ let classObserver = null;
10465
10591
  if (typeof MutationObserver === "function") {
10466
10592
  observer = new MutationObserver((records) => {
10467
- /* 只有新增节点牵涉到官方节点才重扫;纯文字/属性变化直接跳过,避免卡顿。 */
10593
+ /* 仍用 touchesOfficial 过滤:只有新增节点牵涉官方节点才重扫。
10594
+ 普通流式文本每帧新增的节点不命中官方选择器 ⇒ 不触发,避免卡顿。 */
10468
10595
  let relevant = false;
10469
10596
  for (const record of records) {
10470
10597
  const added = record.addedNodes;
@@ -10473,15 +10600,37 @@ function setModelCurrency(name, code, draftNow) {
10473
10600
  }
10474
10601
  if (relevant) break;
10475
10602
  }
10603
+ /* 只有真正牵涉官方节点才重扫;但**有新增节点时也轻扫一次**很难两全 ——
10604
+ 这里坚持必须命中官方节点才 sweep(防止流式文本每帧重扫)。 */
10476
10605
  if (relevant) sweep();
10477
10606
  });
10478
- const dock = sweep();
10479
- if (dock !== null && dock !== undefined) {
10480
- observer.observe(dock, { childList: true, subtree: true });
10607
+ sweep();
10608
+ /* 更稳的通用观察:看 document.body(无 body 退回 documentElement)的 childList+subtree。
10609
+ 打开侧栏可能替换整个 dock 或把官方节点插到深层子树,固定观察旧 dockRoot 会漏。
10610
+ sweep 内部 dockOf() 每次重新查 [data-composer-dock],dock 被替换也能压住新树。 */
10611
+ const observeRoot = (document.body !== null && document.body !== undefined)
10612
+ ? document.body
10613
+ : document.documentElement;
10614
+ if (observeRoot !== null && observeRoot !== undefined) {
10615
+ observer.observe(observeRoot, { childList: true, subtree: true });
10616
+ }
10617
+ /* 额外盯 documentElement 的 class:html.dsb-on 被意外移除(官方重插根节点)时补回。 */
10618
+ if (typeof document.documentElement !== "undefined" && document.documentElement !== null
10619
+ && document.documentElement.classList !== undefined) {
10620
+ classObserver = new MutationObserver(() => {
10621
+ if (document.documentElement.classList.contains("dsb-on") !== true) {
10622
+ document.documentElement.classList.add("dsb-on");
10623
+ sweep();
10624
+ }
10625
+ });
10626
+ classObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
10481
10627
  }
10482
10628
  }
10483
10629
  return () => {
10484
10630
  if (observer !== null) observer.disconnect();
10631
+ if (classObserver !== null) classObserver.disconnect();
10632
+ /* 只移除我们加的 dsb-on;用户自己可能也加了同名类,但我们只在自己挂载时加过它,
10633
+ 这里移除与旧行为一致(卸载即恢复官方原貌)。 */
10485
10634
  root.classList.remove("dsb-on");
10486
10635
  hidden.forEach((prev, el) => { el.style.display = prev; });
10487
10636
  };
@@ -10646,6 +10795,7 @@ function setModelCurrency(name, code, draftNow) {
10646
10795
  /* 换字段(含收起)一律回到根视图,别把上一个字段的下钻层带过来 */
10647
10796
  setTipSub(null);
10648
10797
  setCreditSub(null);
10798
+ setQuotaSub(null);
10649
10799
  /* 工具调用子视图的行数也回到默认 3:换字段 / 重开都重新量 */
10650
10800
  setToolRows(LIST_ROWS_PER_COLUMN);
10651
10801
  /* 悬停整组开关也必须复位(用户拍板的那条「放不下就全不显示」)。
@@ -10705,6 +10855,16 @@ function setModelCurrency(name, code, draftNow) {
10705
10855
  back: () => setCreditSub(null)
10706
10856
  });
10707
10857
  }
10858
+ if (tip.kind === "quota") {
10859
+ /* 订阅型配额窗口(五小时/七天):复用 creditsPanel,每个窗口一行 + 一条 .dsb-bar。
10860
+ count>1 的聚合行(多账号)可点下钻,子视图逐账号列出 5h/7d 各自剩余。
10861
+ 下钻用**独立 quotaSub** 状态(不与积分套餐 creditSub 串),toggleTip/close 都会清空。 */
10862
+ return creditsPanel(tip.panel, tip.title, tipPos, tipRef, {
10863
+ id: quotaSub,
10864
+ open: (index) => setQuotaSub(index),
10865
+ back: () => setQuotaSub(null)
10866
+ });
10867
+ }
10708
10868
  if (tip.kind === "meter") return meterPanel(tip.meter, t, tipPos, tipRef);
10709
10869
  if (tip.kind === "bars") return weekBarsPanel(tip, t, tipPos, tipRef, onHover, { week: hoverWeek, bar: hoverBar });
10710
10870
  return rowsPanel(tip, tipPos, tipRef, {
package/lib/index.js CHANGED
@@ -44,7 +44,7 @@
44
44
  import { z } from './vendor/zod/index.js'
45
45
  import {
46
46
  adapterFor, adaptersFor, BALANCE_PROVIDER_ENV, parseDeepSeekBalance, pluginRoutesIn,
47
- magpieModelProvider, magpieModelPrefix, magpieQuotaEntries, magpieBalanceOf, magpieAccountFromRoute,
47
+ magpieModelProvider, magpieModelPrefix, magpieModelQuotaProvider, magpieQuotaEntries, magpieBalanceOf, magpieAccountFromRoute,
48
48
  } from './balance-api.js'
49
49
  import { holidayHtmlToText, parseHolidayNotice } from './holiday.js'
50
50
  import { isUpdating, lastUpdateResult, resolveSelfDir, selfUpdateOnce } from './self-update.js'
@@ -2238,7 +2238,26 @@ async function queryRelayBalance(ctx, config, now) {
2238
2238
  }
2239
2239
  const raw = relayValueAt(data, relayPathSegments(config.balancePath))
2240
2240
  const parsed = typeof raw === 'number' ? raw : typeof raw === 'string' && raw.trim().length > 0 ? Number(raw) : NaN
2241
- if (!Number.isFinite(parsed)) return { ok: false, at: now, reason: 'invalid-balance', provider: config.channelKey }
2241
+ if (!Number.isFinite(parsed)) {
2242
+ /* 配置的 balancePath 在这份响应上解析不出来(典型:默认 `data.quota`,上游却返回
2243
+ `{ balance, unit }`)时,先按通用形状在同一响应上再试一遍,成功就按 generic 结果返回。
2244
+ 这条对所有自定义中转站生效,不针对任何具体站点。 */
2245
+ const generic = parseGenericRelayBalanceAny(data)
2246
+ if (generic !== null) {
2247
+ return {
2248
+ ok: true,
2249
+ at: now,
2250
+ source: 'relay',
2251
+ provider: config.channelKey,
2252
+ currency: generic.currency.length > 0 ? generic.currency : config.currency,
2253
+ total: generic.total,
2254
+ feeMultiplier: config.feeMultiplier,
2255
+ parts: [],
2256
+ available: true,
2257
+ }
2258
+ }
2259
+ return { ok: false, at: now, reason: 'invalid-balance', provider: config.channelKey }
2260
+ }
2242
2261
  /* 只做单位换算,不乘费用倍率:余额是账上真实金额,不是计费口径。 */
2243
2262
  const amount = parsed / config.balanceDivisor
2244
2263
  return {
@@ -2933,6 +2952,10 @@ const GENERIC_RELAY_AMOUNT_FIELDS = ['available', 'remaining_balance', 'balance_
2933
2952
  * 普通调用者请用下面的 parseGenericRelayBalance(只返回 { currency, total })。
2934
2953
  * 注意:subscription 的总额度字段不是余额,已从候选与解析中删除。
2935
2954
  */
2955
+ /* 通用中转站解析支持的响应种类(与 parseGenericRelayBalanceDetailed 的 kind 分支一一对应)。
2956
+ parseGenericRelayBalanceAny 与解析器共用这一份,避免两处维护漂移。 */
2957
+ const GENERIC_RELAY_KINDS = ['usage', 'user-self', 'credit-grants', 'credits']
2958
+
2936
2959
  function parseGenericRelayBalanceDetailed(kind, data) {
2937
2960
  if (data === null || data === undefined || typeof data !== 'object' || Array.isArray(data)) return null
2938
2961
  const objectOf = (value) => value !== null && value !== undefined
@@ -3031,6 +3054,22 @@ function parseGenericRelayBalance(kind, data) {
3031
3054
  return detailed === null ? null : { currency: detailed.currency, total: detailed.total }
3032
3055
  }
3033
3056
 
3057
+ /**
3058
+ * 通用中转站「形状未知」时的兜底解析:依次试 usage / user-self / credit-grants / credits,
3059
+ * 第一个能解析出余额的胜出,返回同样的 { currency, total }。全失败返回 null。
3060
+ *
3061
+ * 用途:平台配置了 endpoint、但配置的 balancePath 在这份响应上解析不出来(例如配置了默认
3062
+ * `data.quota`,而上游返回的是 `{ balance: 34.5, unit: 'USD' }`)时,先按同一份响应再试一遍通用
3063
+ * 形状,命中就用通用结果,避免只因路径不符就 invalid-balance。
3064
+ */
3065
+ function parseGenericRelayBalanceAny(data) {
3066
+ for (let i = 0; i < GENERIC_RELAY_KINDS.length; i += 1) {
3067
+ const parsed = parseGenericRelayBalance(GENERIC_RELAY_KINDS[i], data)
3068
+ if (parsed !== null) return parsed
3069
+ }
3070
+ return null
3071
+ }
3072
+
3034
3073
  /**
3035
3074
  * 从 settings 服务的 live config 里找 provider 的接入配置。
3036
3075
  * settings.describe() 返回每个插件 entry 的 SettingsDescriptor,value 是当前配置;
@@ -3499,6 +3538,13 @@ async function queryMagpieBalance(ctx, now, options) {
3499
3538
  const byPrefix = magpieModelPrefix(model)
3500
3539
  providerName = byPrefix === null ? null : providerAlias(byPrefix)
3501
3540
  }
3541
+ /* owned_by / 前缀都可能命不中 quotas:`owned_by=work`(前缀也只取第一段=work),
3542
+ 而 quotas 里是 `work/codex`。此时按「模型 id 的最长前缀」匹配 quotas.provider
3543
+ (通用最长前缀逻辑,不写死任何站名;任何 `<provider>/<model>` 形模型都适用)。 */
3544
+ if (providerName === null || magpieQuotaEntries(quotas, providerName).length === 0) {
3545
+ const byLongest = magpieModelQuotaProvider(quotas, model)
3546
+ if (byLongest !== null) providerName = providerAlias(byLongest)
3547
+ }
3502
3548
  /* 模型也认不出时保留 hint 作为诊断用的最后候选(让下游如实报 provider-not-found)。 */
3503
3549
  if (providerName === null && providerHint.length > 0) providerName = providerAlias(providerHint)
3504
3550
  if (providerName === null) {
@@ -3524,8 +3570,9 @@ async function queryMagpieBalance(ctx, now, options) {
3524
3570
  ok: true, at: now, source: 'magpie-quotas', provider: 'magpie',
3525
3571
  upstream: providerName, account: parsed.account,
3526
3572
  currency: parsed.currency, total: parsed.total,
3527
- isCredits: parsed.isCredits === true, isPercent: false,
3573
+ isCredits: parsed.isCredits === true, isPercent: parsed.isPercent === true,
3528
3574
  parts: parsed.parts,
3575
+ ...(parsed.windows === undefined ? {} : { windows: parsed.windows }),
3529
3576
  toppedUp: parsed.toppedUp === undefined ? '0.00' : parsed.toppedUp,
3530
3577
  granted: parsed.granted === undefined ? '0.00' : parsed.granted,
3531
3578
  ...(parsed.rewards === undefined ? {} : { rewards: parsed.rewards }),
@@ -3578,13 +3625,45 @@ async function queryBalance(ctx, force, provider, model, relay, session) {
3578
3625
  : undefined
3579
3626
  }
3580
3627
  const matches = [byRelay, byProvider, byModel]
3628
+ /* 直连余额失败时,若该中转站同时配置在 Magpie 里(quotas 有 provider 条目/百分比),
3629
+ 则透传 Magpie 查到的余额。不写站名、不伪造值:只有 Magpie 明确查不到才返回原 relay 失败。 */
3630
+ const magpieFallback = async (channelKey) => {
3631
+ const fromMagpie = await queryMagpieBalance(ctx, now, { model: model, session: session, providerHint: channelKey })
3632
+ /* 命中值得返回时打 viaMagpie:true(source 仍 'magpie-quotas'),让前端/调用方识别这是 Magpie 兜底。 */
3633
+ if (fromMagpie.ok === true) return Object.assign({}, fromMagpie, { viaMagpie: true })
3634
+ if (fromMagpie.reason === 'magpie-provider-not-found' || fromMagpie.reason === 'magpie-unknown-model') return null
3635
+ return null
3636
+ }
3581
3637
  for (const one of matches) {
3582
- if (usable(one) === true) return queryRelayBalance(ctx, one, now)
3638
+ if (usable(one) === true) {
3639
+ const relayResult = await queryRelayBalance(ctx, one, now)
3640
+ if (relayResult !== null && relayResult.ok === true) return relayResult
3641
+ const fromMagpie = await magpieFallback(one.channelKey)
3642
+ if (fromMagpie !== null) return fromMagpie
3643
+ return relayResult
3644
+ }
3583
3645
  }
3584
3646
  const emptyHit = matches.find((one) => emptyEndpoint(one) === true)
3585
3647
  if (emptyHit !== undefined) {
3586
3648
  const discovered = await queryDiscoveredRelayBalance(ctx, now, emptyHit)
3587
3649
  if (discovered !== null) return discovered
3650
+ /* 首次自动探测失败后,再用该平台自身的 relayProviderBaseUrl + provider 的 key 走一次
3651
+ 通用中转站探测(不跨站、不拿别家 baseURL)。成功就返回;仍失败原样报 relay-endpoint-empty。 */
3652
+ const platformBase = relayProviderBaseUrl(ctx, emptyHit.channelKey)
3653
+ if (platformBase !== null) {
3654
+ const platformKey = await resolveGenericRelayKey(ctx, emptyHit.channelKey, null)
3655
+ if (platformKey !== null) {
3656
+ const fromGeneric = await queryGenericRelayBalance(ctx, now, emptyHit.channelKey, {
3657
+ baseURL: platformBase,
3658
+ key: platformKey,
3659
+ })
3660
+ if (fromGeneric !== null) return fromGeneric
3661
+ }
3662
+ }
3663
+ /* 直连 discovered/generic 都失败:若该平台同时配置在 Magpie 里,透传 Magpie 余额;
3664
+ Magpie 明确查不到(provider-not-found/unknown-model)才原样报 relay-endpoint-empty。 */
3665
+ const fromMagpie = await queryMagpieBalance(ctx, now, { model: model, session: session, providerHint: emptyHit.channelKey })
3666
+ if (fromMagpie.ok === true) return Object.assign({}, fromMagpie, { viaMagpie: true })
3588
3667
  return { ok: false, at: now, reason: 'relay-endpoint-empty', provider: emptyHit.channelKey }
3589
3668
  }
3590
3669
  }
@@ -3650,6 +3729,20 @@ async function queryBalance(ctx, force, provider, model, relay, session) {
3650
3729
  })
3651
3730
  if (fromGeneric !== null) return fromGeneric
3652
3731
  }
3732
+ } else {
3733
+ /* settings 里取不到 provider 配置时(模型页没有该 provider 的条目),用 cordis.patch.yml 的
3734
+ baseURL + 按引用名解析的 key 再探一次通用中转站端点。对所有自定义 provider 生效。 */
3735
+ const patchBase = providerBaseUrlOf(provider)
3736
+ if (typeof patchBase === 'string' && patchBase.trim().length > 0) {
3737
+ const patchKey = await resolveGenericRelayKey(ctx, provider, null)
3738
+ if (patchKey !== null) {
3739
+ const fromPatch = await queryGenericRelayBalance(ctx, now, provider, {
3740
+ baseURL: patchBase.trim(),
3741
+ key: patchKey,
3742
+ })
3743
+ if (fromPatch !== null) return fromPatch
3744
+ }
3745
+ }
3653
3746
  }
3654
3747
  /* 内置适配器认不出的自定义 provider 也可能挂在 Magpie 网关:
3655
3748
  拿 provider 名直接问,明确"查不到"才退回未知平台;上游明确报错则原样返回。 */
@@ -5671,6 +5764,7 @@ export {
5671
5764
  /* relaySettings 合并逻辑(仅测试:验证改地址/解析字段清 balanceKind、无关更新保留)。 */
5672
5765
  relaySettings as relaySettingsForTest,
5673
5766
  parseGenericRelayBalance,
5767
+ parseGenericRelayBalanceAny,
5674
5768
  queryGenericRelayBalance,
5675
5769
  /* 空地址探测的冷却表与指纹(仅测试:验证同长度不同凭据不共享冷却、Map 容量上限)。 */
5676
5770
  relayDiscoveryFailures as relayDiscoveryFailuresForTest,