dsh-model-allowance 1.0.6 → 1.0.7

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 CHANGED
@@ -25,6 +25,10 @@ of the current conversation, next to the input box.
25
25
 
26
26
  ### Not supported
27
27
 
28
+ These vendors publish no balance API. As long as they are configured here,
29
+ they still appear in the card: the panel says there is no balance API, and
30
+ their models stay switchable.
31
+
28
32
  - Qwen Token Plan: the vendor publishes no balance API
29
33
  - Mimo Token Plan:the vendor publishes no balance API
30
34
 
@@ -36,10 +40,10 @@ of the current conversation, next to the input box.
36
40
  2. Choose **Install** and enter:
37
41
 
38
42
  ```
39
- dsh-model-allowance@1.0.0
43
+ dsh-model-allowance@1.0.7
40
44
  ```
41
45
 
42
- Use the latest published version instead of `1.0.0` when a newer one
46
+ Use the latest published version instead of `1.0.7` when a newer one
43
47
  exists.
44
48
  3. Confirm the installation. If DSH reports **restart required**, restart
45
49
  DSH; otherwise refresh the page.
@@ -49,7 +53,7 @@ The npm installation is eligible for the Plugin Manager's **Update** action.
49
53
  ### Install from GitHub
50
54
 
51
55
  ```
52
- git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.0
56
+ git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.7
53
57
  ```
54
58
 
55
59
  Git installations are not covered by the Plugin Manager's **Update** action;
package/README.zh.md CHANGED
@@ -23,6 +23,9 @@
23
23
 
24
24
  ### 不支持
25
25
 
26
+ 以下厂商没有余额接口,但只要本地配置了它们,它们依然会出现在卡片里:
27
+ 面板会提示“目前无余额接口”,模型列表照常可以切换。
28
+
26
29
  - 千问 Token Plan:官方未提供余额接口
27
30
  - Mimo Token Plan:官方未提供余额接口
28
31
 
@@ -34,10 +37,10 @@
34
37
  2. 点击 **Install(安装)**,填入:
35
38
 
36
39
  ```
37
- dsh-model-allowance@1.0.0
40
+ dsh-model-allowance@1.0.7
38
41
  ```
39
42
 
40
- 如果已有更新版本,请把 `1.0.0` 换成最新的精确版本。
43
+ 如果已有更新版本,请把 `1.0.7` 换成最新的精确版本。
41
44
  3. 确认安装。如果 DSH 提示需要重启,重启 DSH;否则刷新页面即可。
42
45
 
43
46
  通过 npm 安装的版本可以在 Plugin Manager 中使用 **Update** 更新。
@@ -45,7 +48,7 @@
45
48
  ### 从 GitHub 安装
46
49
 
47
50
  ```
48
- git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.0
51
+ git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.7
49
52
  ```
50
53
 
51
54
  Git 安装不受 Plugin Manager 的 **Update** 管理;更新时需要先移除旧版本,
package/client.js CHANGED
@@ -224,6 +224,62 @@ var OPENCODE_PATHS = [
224
224
  { d: "M180 240H60V120H180V240Z", opacity: 0.5 },
225
225
  { d: "M180 60H60V240H180V60ZM240 300H0V0H240V300Z", opacity: 1 }
226
226
  ];
227
+ var QWEN_PATHS = [
228
+ "M27.0482997609375,16.093917358203125L23.2809152609375,13.918146358203124C23.374042060937498,13.757291758203126,23.4248380609375,13.573860658203126,23.4248380609375,13.381963758203124L23.4248380609375,12.217883958203124C23.4248380609375,11.835501458203126,23.2202429609375,11.481338678203125,22.888655660937502,11.289441828203126L21.8797874609375,10.706696778203124C21.5482001609375,10.514799900203124,21.1404194609375,10.514799900203124,20.8088343609375,10.706696778203124L17.7201426009375,12.490208158203124C17.3885564509375,12.682105058203124,17.1839599609375,13.034856558203124,17.1839599609375,13.418650158203125L17.1839599609375,14.582729858203125C17.1839599609375,14.965112658203125,17.3885553809375,15.319275358203125,17.7201426009375,15.511172258203125L24.9684791609375,19.696214658203125C25.300065960937502,19.888112058203127,25.7078466609375,19.888112058203127,26.0394315609375,19.696214658203125L27.0482997609375,19.113469158203124C27.379887960937502,18.921571758203125,27.5844829609375,18.568820958203126,27.5844829609375,18.185026658203125L27.5844829609375,17.020946958203126C27.5844829609375,16.638564558203125,27.379887960937502,16.284401858203125,27.0482997609375,16.092504958203126L27.0482997609375,16.093917358203125Z",
229
+ "M22.335545490625,3.7476133590625L18.568160490625,5.923384639062499C18.475033490625,5.7625300390625,18.342399590625,5.627073739062499,18.175900890625,5.5311251390625L17.167031490625,4.9483796390625C16.835445390625,4.7564827390625,16.427664590625,4.7564827390625,16.096077490625,4.9483796390625L15.087208030625,5.5311251390625C14.755621880625,5.7230219390625,14.551025390625,6.0757734390625,14.551025390625,6.459567339062501L14.551025390625,10.026589839062499C14.551025390625,10.4089722390625,14.755620810625,10.7631349390625,15.087208030625,10.9550318390625L16.096077490625,11.5377769390625C16.427663590625,11.7296743390625,16.835444190625,11.7296743390625,17.167030290625,11.5377769390625L24.415367090625,7.3527338390625C24.746954390625,7.1608369390625,24.951549390625,6.8080854390625,24.951549390625,6.4242920390625L24.951549390625,5.2602123390625C24.951549390625,4.8778299390625,24.746954390625,4.5236670990625,24.415367090625,4.3317704790625005L23.406498890625002,3.7490251990625C23.074911090625,3.5571283180625,22.667130490625,3.5571283180625,22.335545490625,3.7490251990625L22.335545490625,3.7476133590625Z",
230
+ "M9.2878987390625,1.6551098L9.2878987390625,6.0052404C9.1030566390625,6.0052404,8.9182152390625,6.053215,8.7517166390625,6.1491632L7.7428471490625,6.7319088C7.4112609890625,6.9238057,7.2066650390625,7.276557,7.2066650390625,7.6603503L7.2066650390625,8.8244305C7.2066650390625,9.2068129,7.4112609890625,9.560976,7.7428471490625,9.7528725L10.8315389390625,11.536385C11.1631250390625,11.728281,11.570905639062499,11.728281,11.902493039062499,11.536385L12.9113621390625,10.953639C13.2429485390625,10.761743,13.4475450390625,10.408991,13.4475450390625,10.025197L13.4475450390625,1.6551098C13.4475450390625,1.2727274,13.2429494390625,0.91856486,12.9113621390625,0.726668L11.902493039062499,0.1439226C11.5709066390625,-0.047974203,11.1631262390625,-0.047974203,10.8315398390625,0.1439226L9.8226704390625,0.726668C9.4910843390625,0.91856486,9.2864885390625,1.2713163,9.2864885390625,1.6551098L9.2878987390625,1.6551098Z",
231
+ "M0.95170956375,11.90887979140625L4.71909524375,14.08465049140625C4.62596894375,14.245504891406249,4.57517244375,14.428935991406249,4.57517244375,14.62083289140625L4.57517244375,15.78491309140625C4.57517244375,16.16729549140625,4.77976844375,16.52145859140625,5.11135484375,16.71335509140625L6.12022404375,17.296099691406248C6.45181034375,17.487997091796875,6.85959104375,17.487997091796875,7.19117734375,17.296099691406248L10.27987004375,15.51258899140625C10.61145634375,15.32069209140625,10.81605234375,14.96794029140625,10.81605234375,14.584146491406251L10.81605234375,13.42006679140625C10.81605234375,13.03768439140625,10.61145734375,12.68352179140625,10.27987004375,12.491624791406249L3.03153274375,8.30658135140625C2.69994644375,8.11468447040625,2.2921658437500003,8.11468447040625,1.96057944375,8.30658135140625L0.95171022375,8.88932693140625C0.62012319375,9.07981253140625,0.41552734375,9.43397519140625,0.41552734375,9.81635769140625L0.41552734375,10.98043749140625C0.41552734375,11.36281989140625,0.62012319375,11.71698289140625,0.95170956375,11.90887979140625Z",
232
+ "M5.6630003703125,24.25519135703125L9.430386070312501,22.07942055703125C9.523513270312499,22.24027485703125,9.6561469703125,22.37573245703125,9.8226456703125,22.47168015703125L10.8315148703125,23.05442615703125C11.1631011703125,23.24632315703125,11.5708818703125,23.24632315703125,11.9024686703125,23.05442615703125L12.9113387703125,22.47168015703125C13.2429250703125,22.279783257031248,13.4475210703125,21.92703155703125,13.4475210703125,21.54323765703125L13.4475210703125,17.97621525703125C13.4475210703125,17.59383275703125,13.2429260703125,17.23966997703125,12.9113387703125,17.04777312703125L11.9024686703125,16.46502807703125C11.5708827703125,16.27313119903125,11.1631021703125,16.27313119903125,10.8315162703125,16.46502807703125L3.5831791803125,20.65007065703125C3.2515927603125,20.84196755703125,3.0469970703125,21.19471935703125,3.0469970703125,21.57851315703125L3.0469970703125,22.742592857031248C3.0469970703125,23.12497615703125,3.2515930203125,23.47913785703125,3.5831791803125,23.671034857031252L4.5920482703125,24.253780857031252C4.9236347703125,24.44567775703125,5.3314153703125005,24.44567775703125,5.6630019703125,24.253780857031252L5.6630003703125,24.25519135703125Z",
233
+ "M18.7120137640625,26.347708765625L18.7120137640625,21.997577665625002C18.8968553640625,21.997577665625002,19.0816964640625,21.949604065625,19.2481965640625,21.853654365625L20.2570648640625,21.270908365625C20.588652164062502,21.079011465625,20.7932476640625,20.726260165625,20.7932476640625,20.342466365625L20.7932476640625,19.178386465625C20.7932476640625,18.796002865625,20.588652164062502,18.441841165625,20.2570648640625,18.249944365625L17.1683730640625,16.466432955625C16.8367869640625,16.274536084625,16.4290063640625,16.274536084625,16.0974202640625,16.466432955625L15.0885508040625,17.049178005625C14.7569646540625,17.241074855625,14.5523681640625,17.593826265625,14.5523681640625,17.977620165625L14.5523681640625,26.347706765625C14.5523681640625,26.730089765625,14.7569635840625,27.084252765625,15.0885508040625,27.276148765625003L16.0974202640625,27.858895765625C16.4290063640625,28.050791765625,16.8367869640625,28.050791765625,17.1683730640625,27.858895765625L18.1772425640625,27.276148765625003C18.5088286640625,27.084252765625,18.713424164062502,26.731500765625,18.713424164062502,26.347706765625L18.7120137640625,26.347708765625Z"
234
+ ];
235
+ var QWEN_GRADIENTS = [
236
+ {
237
+ id: "dsh-balance-qwen-0",
238
+ x1: -0.9480395913124084,
239
+ y1: -1.0930798053741455,
240
+ x2: 1.292371777143182,
241
+ y2: 0.9053882745851343
242
+ },
243
+ {
244
+ id: "dsh-balance-qwen-1",
245
+ x1: -0.4444444477558136,
246
+ y1: -0.7164570093154907,
247
+ x2: 2.0650320456884637,
248
+ y2: 1.2322934398033913
249
+ },
250
+ {
251
+ id: "dsh-balance-qwen-2",
252
+ x1: -0.1266109049320221,
253
+ y1: 0.11379560083150864,
254
+ x2: 1.3623472942105739,
255
+ y2: 2.9004999850663093
256
+ },
257
+ {
258
+ id: "dsh-balance-qwen-3",
259
+ x1: 4070004215463996e-19,
260
+ y1: -0.0901901125907898,
261
+ x2: 2.240818614500846,
262
+ y2: 1.9082775852882916
263
+ },
264
+ {
265
+ id: "dsh-balance-qwen-4",
266
+ x1: -0.5029168128967285,
267
+ y1: -0.7912299036979675,
268
+ x2: 2.006559339146774,
269
+ y2: 1.1575211847572104
270
+ },
271
+ {
272
+ id: "dsh-balance-qwen-5",
273
+ x1: -2.119149923324585,
274
+ y1: -0.8479101061820984,
275
+ x2: -0.6301921696742209,
276
+ y2: 1.9387942856270293
277
+ }
278
+ ];
279
+ var QWEN_GRADIENT_STOPS = [
280
+ ["#082DFF", "0"],
281
+ ["#3FD2F9", "1"]
282
+ ];
227
283
  var ICON_GEOMETRY = {
228
284
  // DeepSeek's square icon draws 1..49.35 across and 7..43.35 down.
229
285
  deepseek: { x: 1, y: 7, vbW: 48.35, vbH: 36.35, inkW: 48.35, inkH: 36.35 },
@@ -233,7 +289,10 @@ var ICON_GEOMETRY = {
233
289
  // Kimi's K-only glyph draws 0..23.95 across and 0.94..24.19 down.
234
290
  kimi: { x: 0, y: 0.94, vbW: 23.95, vbH: 23.25, inkW: 23.95, inkH: 23.25 },
235
291
  // OpenCode's logo draws its 240x300 frame from the origin.
236
- opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 }
292
+ opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 },
293
+ // Qwen's petals draw 0.42..27.58 across and -0.05..28.05 down, so the
294
+ // published 28x28 box would clip a hair of the outer petals.
295
+ qwen: { x: 0.4155, y: -0.048, vbW: 27.169, vbH: 28.0988, inkW: 27.169, inkH: 28.0988 }
237
296
  };
238
297
  function markOf(entry, route) {
239
298
  const color = typeof entry?.color === "string" && entry.color !== "" ? entry.color : "#6b7280";
@@ -289,6 +348,37 @@ function providerIcon(route, inkHeight, mark) {
289
348
  content = KIMI_PATHS.map(
290
349
  (d, index) => (0, import_react.createElement)("path", { key: `kimi-${String(index)}`, d, fill: "currentColor" })
291
350
  );
351
+ } else if (mark.icon === "qwen") {
352
+ content = [
353
+ (0, import_react.createElement)(
354
+ "defs",
355
+ { key: "defs" },
356
+ ...QWEN_GRADIENTS.map(
357
+ (gradient) => (0, import_react.createElement)(
358
+ "linearGradient",
359
+ {
360
+ key: gradient.id,
361
+ id: gradient.id,
362
+ x1: gradient.x1,
363
+ y1: gradient.y1,
364
+ x2: gradient.x2,
365
+ y2: gradient.y2,
366
+ gradientUnits: "objectBoundingBox"
367
+ },
368
+ ...QWEN_GRADIENT_STOPS.map(
369
+ ([color, offset]) => (0, import_react.createElement)("stop", { key: offset, offset, stopColor: color })
370
+ )
371
+ )
372
+ )
373
+ ),
374
+ ...QWEN_PATHS.map(
375
+ (d, index) => (0, import_react.createElement)("path", {
376
+ key: `qwen-${String(index)}`,
377
+ d,
378
+ fill: `url(#${String(QWEN_GRADIENTS[index].id)})`
379
+ })
380
+ )
381
+ ];
292
382
  } else if (mark.icon === "opencode") {
293
383
  content = OPENCODE_PATHS.map(
294
384
  (path, index) => (0, import_react.createElement)("path", {
@@ -807,8 +897,7 @@ var STYLES = [
807
897
  ".dsh-model-allowance-panel{position:absolute;bottom:calc(100% + 6px);right:0;z-index:20;",
808
898
  "box-sizing:border-box;min-width:300px;max-width:calc(100vw - 24px);",
809
899
  "padding:8px 10px 10px;border:0;",
810
- "border-radius:var(--dsw-radius-lg);background:var(--dsw-specific-menu);",
811
- "backdrop-filter:var(--dsw-menu-backdrop-filter);",
900
+ "border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-2);",
812
901
  "box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);",
813
902
  "font-size:12px}",
814
903
  ".dsh-model-allowance-row{display:flex;justify-content:space-between;gap:16px;padding:2px 0}",
@@ -858,11 +947,10 @@ var STYLES = [
858
947
  ".dsh-model-allowance-more:hover{color:var(--dsw-alias-label-secondary);",
859
948
  "border-color:var(--dsw-alias-border-l2)}",
860
949
  // The overflow menu is a second floating surface, so it carries the same
861
- // menu surface and elevation as the card it belongs to.
950
+ // solid layer and elevation as the card it belongs to.
862
951
  ".dsh-model-allowance-menu{position:absolute;top:calc(100% + 2px);right:0;z-index:30;",
863
952
  "min-width:150px;padding:4px;border:0;",
864
- "border-radius:var(--dsw-radius-md);background:var(--dsw-specific-menu);",
865
- "backdrop-filter:var(--dsw-menu-backdrop-filter);",
953
+ "border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
866
954
  "box-shadow:var(--dsw-elevation-prominent)}",
867
955
  ".dsh-model-allowance-menu-item{display:flex;align-items:center;gap:8px;width:100%;",
868
956
  "padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);background:0 0;",
@@ -878,11 +966,15 @@ var STYLES = [
878
966
  // The model list is a third floating surface. It opens upwards from the
879
967
  // footer button, so it carries the same menu surface and elevation as the
880
968
  // card and the provider overflow menu.
969
+ //
970
+ // It is the one surface that is not translucent: the list floats over the
971
+ // conversation, and a frosted panel there let the text underneath show
972
+ // through the model names. A solid layer keeps the list readable wherever
973
+ // it opens.
881
974
  ".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
882
975
  ".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
883
976
  "min-width:180px;max-width:260px;max-height:240px;overflow-y:auto;padding:4px;border:0;",
884
- "border-radius:var(--dsw-radius-md);background:var(--dsw-specific-menu);",
885
- "backdrop-filter:var(--dsw-menu-backdrop-filter);",
977
+ "border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
886
978
  "box-shadow:var(--dsw-elevation-prominent)}",
887
979
  ".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
888
980
  "gap:10px;width:100%;padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);",
@@ -900,11 +992,11 @@ var STYLES = [
900
992
  ".dsh-model-allowance-model-arrow{color:var(--dsw-alias-label-tertiary);font-size:12px;",
901
993
  "line-height:1}",
902
994
  // The effort flyout opens to the right of the list, on the row the
903
- // pointer rests on, as a fourth floating surface of the card.
995
+ // pointer rests on, as a fourth floating surface of the card. It overlaps
996
+ // the list, so it is solid for the same reason the list is.
904
997
  ".dsh-model-allowance-effort-menu{position:absolute;left:calc(100% + 4px);z-index:31;",
905
998
  "display:flex;flex-direction:column;min-width:130px;max-width:220px;padding:4px;border:0;",
906
- "border-radius:var(--dsw-radius-md);background:var(--dsw-specific-menu);",
907
- "backdrop-filter:var(--dsw-menu-backdrop-filter);",
999
+ "border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
908
1000
  "box-shadow:var(--dsw-elevation-prominent)}",
909
1001
  ".dsh-model-allowance-effort-item{display:flex;align-items:center;justify-content:space-between;",
910
1002
  "gap:10px;width:100%;padding:3px 6px;border:0;border-radius:var(--dsw-radius-xs);",
@@ -1166,6 +1258,11 @@ function statusDisplayState(status) {
1166
1258
  if (status.state === "unknown" && !status.url && !status.error) return "unsupported";
1167
1259
  return status.state;
1168
1260
  }
1261
+ function entryCovers(entry, route) {
1262
+ if (entry === void 0 || entry === null) return false;
1263
+ if (entry.route === route) return true;
1264
+ return Array.isArray(entry.aliases) && entry.aliases.includes(route);
1265
+ }
1169
1266
  function BalanceBadge(props) {
1170
1267
  const { useProjection, ctx, t } = props;
1171
1268
  const selection = useProjection("modelSelection");
@@ -1184,7 +1281,7 @@ function BalanceBadge(props) {
1184
1281
  const lastModelProvider = React.useRef(null);
1185
1282
  const available = directory.filter((entry) => entry.configured);
1186
1283
  const entryOf = React.useCallback(
1187
- (route) => directory.find((entry) => entry.route === route),
1284
+ (route) => directory.find((entry) => entryCovers(entry, route)),
1188
1285
  [directory]
1189
1286
  );
1190
1287
  const nameOf = React.useCallback((route) => pickName(entryOf(route), route), [entryOf]);
@@ -1250,8 +1347,8 @@ function BalanceBadge(props) {
1250
1347
  setPicked(null);
1251
1348
  });
1252
1349
  const activeProvider = picked ?? provider;
1253
- const activeModel = picked === null || picked === provider ? selectedModel : void 0;
1254
- const inUse = activeProvider === provider;
1350
+ const inUse = activeProvider === provider || entryOf(provider)?.route === activeProvider;
1351
+ const activeModel = inUse ? selectedModel : void 0;
1255
1352
  const switchLabel = t(inUse ? "detail.switchModelHere" : "detail.switchModelThere", {
1256
1353
  name: nameOf(activeProvider)
1257
1354
  });
@@ -1636,7 +1733,7 @@ function BalanceBadge(props) {
1636
1733
  }
1637
1734
  let shown = available.slice(0, visibleCount);
1638
1735
  let overflow = available.slice(visibleCount);
1639
- const activeIndex = overflow.findIndex((entry) => entry.route === activeProvider);
1736
+ const activeIndex = overflow.findIndex((entry) => entryCovers(entry, activeProvider));
1640
1737
  if (activeIndex >= 0 && shown.length > 0) {
1641
1738
  const displaced = shown[shown.length - 1];
1642
1739
  shown = [...shown.slice(0, -1), overflow[activeIndex]];
@@ -1645,6 +1742,7 @@ function BalanceBadge(props) {
1645
1742
  const markButton = (entry) => {
1646
1743
  const mark = markFor(entry.route);
1647
1744
  const name = nameOf(entry.route);
1745
+ const active = entryCovers(entry, activeProvider);
1648
1746
  return (0, import_react3.createElement)(
1649
1747
  "button",
1650
1748
  {
@@ -1652,8 +1750,8 @@ function BalanceBadge(props) {
1652
1750
  key: entry.route,
1653
1751
  role: "tab",
1654
1752
  className: "dsh-model-allowance-tab",
1655
- "data-active": entry.route === activeProvider ? "true" : "false",
1656
- "aria-selected": entry.route === activeProvider ? "true" : "false",
1753
+ "data-active": active ? "true" : "false",
1754
+ "aria-selected": active ? "true" : "false",
1657
1755
  "aria-label": name,
1658
1756
  title: name,
1659
1757
  style: { "--provider-mark": mark.color },
package/lib/balance.js CHANGED
@@ -8,11 +8,19 @@
8
8
 
9
9
  import { createRouteCredentialResolver } from './credentials.js'
10
10
  import { displayOf, readEndpointAdapter } from './providers/shared.js'
11
- import { findAdapter, KIND_AMOUNT, KIND_QUOTA, PROVIDER_ADAPTERS } from './providers.js'
11
+ import { aliasesOf, findAdapter, KIND_AMOUNT, KIND_QUOTA, PROVIDER_ADAPTERS } from './providers.js'
12
12
 
13
13
  /** Default lifetime of one cached reading, in milliseconds. */
14
14
  const DEFAULT_TTL_MS = 5 * 60 * 1000
15
15
 
16
+ /**
17
+ * The colour a vendor without a declared brand colour is drawn in.
18
+ *
19
+ * The browser draws such a vendor as its route's initial over this colour,
20
+ * the same neutral the client falls back to on its own.
21
+ */
22
+ const NEUTRAL_COLOR = '#6b7280'
23
+
16
24
  /**
17
25
  * Round a monetary amount to avoid floating-point precision artifacts.
18
26
  *
@@ -293,39 +301,111 @@ export class BalanceService {
293
301
  * browser needs to name and draw it.
294
302
  *
295
303
  * The card offers these as a switcher, so a route only answers `configured`
296
- * when its credential (or the service behind it) actually resolves here. One
297
- * entry per route rather than per adapter: the two Zhipu routes carry
298
- * different credentials, so an installation using the CN plan should see
299
- * that route, not the international one.
304
+ * when this installation can really route to it. The harness is the
305
+ * authority on that: it registers a route when a configuration supplies a
306
+ * profile for it. One entry per route rather than per adapter: the two
307
+ * Zhipu routes are separate plans, so an installation using the CN plan
308
+ * should see that route, not the international one.
300
309
  *
301
- * @returns {Promise<Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string}>>}
310
+ * The harness serves routes this plugin has no adapter for as well — a
311
+ * vendor whose balance API is not implemented is still a vendor the user
312
+ * routes to. Those routes are listed too, so their models stay reachable
313
+ * from the card; the panel says there is no balance API for them.
314
+ *
315
+ * @returns {Promise<Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string, aliases?: readonly string[], modelRoutes?: readonly string[]}>>}
302
316
  * The routes.
303
317
  */
304
318
  async available() {
305
- /** @type {Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string, modelRoutes?: readonly string[]}>} */
319
+ const host = this.#hostRoutes()
320
+ /** @type {Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string, aliases?: readonly string[], modelRoutes?: readonly string[]}>} */
306
321
  const routes = []
307
322
  for (const adapter of PROVIDER_ADAPTERS) {
323
+ const aliases = aliasesOf(adapter)
308
324
  for (const route of adapter.routes) {
309
- let configured
310
- if (adapter.readWithEnv) {
311
- // A service-backed adapter is available when the service is mounted.
312
- const service =
313
- typeof this.ctx.get === 'function' ? this.ctx.get(adapter.service) : undefined
314
- configured = service !== undefined
315
- } else {
316
- configured = (await this.routeCredentials.resolve(route, adapter)) !== undefined
317
- }
318
325
  routes.push({
319
326
  route,
320
- configured,
327
+ configured: await this.#configured(adapter, route, host),
321
328
  ...displayOf(adapter),
322
329
  ...(adapter.modelRoutes === undefined ? {} : { modelRoutes: adapter.modelRoutes }),
330
+ ...(aliases.length === 0 ? {} : { aliases }),
323
331
  })
324
332
  }
325
333
  }
334
+ // The vendors the harness serves and no adapter covers. They are the
335
+ // vendors this build cannot report a balance for, and they still belong
336
+ // in the switcher: the card is how their models are picked.
337
+ for (const [route, name] of host ?? []) {
338
+ if (routes.some((entry) => entry.route === route || entry.aliases?.includes(route))) continue
339
+ routes.push({
340
+ route,
341
+ configured: true,
342
+ name: { zh: name, en: name },
343
+ color: NEUTRAL_COLOR,
344
+ })
345
+ }
326
346
  return routes
327
347
  }
328
348
 
349
+ /**
350
+ * The provider routes the harness itself serves, with the names it gives them.
351
+ *
352
+ * The harness registers a route when a configuration supplies a profile for
353
+ * it, so this is the set of vendors this installation can actually route
354
+ * to. The plugin's own registry does not cover them all, and it must not
355
+ * decide which of them exist: a vendor with no balance adapter is still a
356
+ * vendor the user routes to.
357
+ *
358
+ * `undefined` means the harness cannot answer at all — no LLM runtime, or
359
+ * one too old to name its routes — and the credential is then all there is
360
+ * to go on.
361
+ *
362
+ * @returns {Map<string, string> | undefined} Route to display name.
363
+ */
364
+ #hostRoutes() {
365
+ const llm = typeof this.ctx.get === 'function' ? this.ctx.get('llm') : undefined
366
+ if (typeof llm?.listProviders !== 'function') return undefined
367
+ /** @type {Map<string, string>} */
368
+ const routes = new Map()
369
+ try {
370
+ for (const info of llm.listProviders() ?? []) {
371
+ if (!info || typeof info.id !== 'string' || info.id === '') continue
372
+ routes.set(info.id, typeof info.name === 'string' && info.name !== '' ? info.name : info.id)
373
+ }
374
+ } catch {
375
+ // A harness that cannot answer knows no routes; the plugin's own
376
+ // registry still stands.
377
+ }
378
+ return routes
379
+ }
380
+
381
+ /**
382
+ * Whether one route is set up in this installation.
383
+ *
384
+ * The harness is the authority on which routes exist: a stored key without a
385
+ * profile is not a route the user can switch to, so a route it does not
386
+ * serve is not offered. The one exception is the same vendor under another
387
+ * id — the harness serving that id means the vendor is set up here.
388
+ *
389
+ * A harness that cannot answer leaves the credential as the only evidence:
390
+ * it says what the plugin can read, which is what this list has always
391
+ * meant.
392
+ *
393
+ * @param {import('./providers.js').ProviderAdapter} adapter Adapter serving the route.
394
+ * @param {string} route Provider route.
395
+ * @param {Map<string, string> | undefined} host Routes the harness serves.
396
+ * @returns {Promise<boolean>} Whether the route is configured.
397
+ */
398
+ async #configured(adapter, route, host) {
399
+ if (adapter.service !== undefined) {
400
+ const service = typeof this.ctx.get === 'function' ? this.ctx.get(adapter.service) : undefined
401
+ return service !== undefined
402
+ }
403
+ if (host !== undefined) {
404
+ return host.has(route) || (adapter.modelRoutes ?? []).some((alias) => host.has(alias))
405
+ }
406
+ return (await this.routeCredentials.resolve(route, adapter)) !== undefined
407
+ }
408
+
329
409
  /**
330
410
  * Drop every cached reading.
331
411
  */
@@ -415,7 +415,7 @@ export const qwenTokenPlanAdapters = [
415
415
  id: 'qwen-token-plan',
416
416
  routes: ['qwen-token-plan'],
417
417
  name: { zh: '通义千问 Token Plan', en: 'Qwen Token Plan' },
418
- color: '#ff6a00',
418
+ color: '#082DFF',
419
419
  icon: 'qwen',
420
420
  consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
421
421
  }),
@@ -429,7 +429,7 @@ export const qwenTokenPlanCnAdapters = [
429
429
  id: 'qwen-token-plan-cn',
430
430
  routes: ['qwen-token-plan-cn'],
431
431
  name: { zh: '通义千问 Token Plan (国内)', en: 'Qwen Token Plan (CN)' },
432
- color: '#ff6a00',
432
+ color: '#082DFF',
433
433
  icon: 'qwen',
434
434
  consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
435
435
  }),
@@ -443,7 +443,7 @@ export const qwenTokenPlanIndividualAdapters = [
443
443
  id: 'qwen-token-plan-individual',
444
444
  routes: ['qwen-token-plan-individual'],
445
445
  name: { zh: '通义千问个人版', en: 'Qwen Token Plan Individual' },
446
- color: '#ff6a00',
446
+ color: '#082DFF',
447
447
  icon: 'qwen',
448
448
  consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
449
449
  }),
package/lib/providers.js CHANGED
@@ -94,7 +94,8 @@ import { zaiAdapters } from './providers/zai.js'
94
94
  * @property {readonly string[]} routes Provider routes this adapter serves.
95
95
  * @property {readonly string[]} [modelRoutes] Host provider routes whose catalog
96
96
  * groups list this vendor's models, when they differ from the balance route.
97
- * The first one that carries models answers.
97
+ * The first one that carries models answers. They are the same vendor under
98
+ * another id, so a reading for one of them answers through this adapter.
98
99
  * @property {'amount'|'quota'} kind Quantity dimension of the reading.
99
100
  * @property {boolean} [modelScoped] Whether the reading is per provider-owned model.
100
101
  * @property {string} consoleUrl Provider console for a manual check.
@@ -168,6 +169,16 @@ export const PROVIDER_ADAPTERS = Object.freeze([
168
169
 
169
170
  /** Route to the adapter serving it, resolved once at load. */
170
171
  const BY_ROUTE = new Map()
172
+ /**
173
+ * Host route id to the adapter whose vendor it stands for.
174
+ *
175
+ * A balance route and the Host route that lists the same vendor's models are
176
+ * not always the same id: the DeepSeek API vendor answers a balance query as
177
+ * `deepseek` and a model request as `deepseek-official`. The second id is the
178
+ * same vendor, so it reads through the same adapter — otherwise the card
179
+ * would report "no balance API" for a vendor whose balance it can read.
180
+ */
181
+ const BY_MODEL_ROUTE = new Map()
171
182
  for (const adapter of PROVIDER_ADAPTERS) {
172
183
  for (const route of adapter.routes) {
173
184
  // Two adapters answering the same route would make a reading depend on
@@ -177,15 +188,38 @@ for (const adapter of PROVIDER_ADAPTERS) {
177
188
  }
178
189
  BY_ROUTE.set(route, adapter)
179
190
  }
191
+ for (const route of adapter.modelRoutes ?? []) {
192
+ // The adapter's own balance route needs no second entry.
193
+ if (BY_ROUTE.get(route) === adapter) continue
194
+ if (BY_ROUTE.has(route) || BY_MODEL_ROUTE.has(route)) {
195
+ throw new Error(`two provider adapters declare the route "${route}"`)
196
+ }
197
+ BY_MODEL_ROUTE.set(route, adapter)
198
+ }
180
199
  }
181
200
 
182
201
  /**
183
202
  * Find the adapter serving one provider route.
203
+ *
204
+ * A route the harness names for the same vendor under another id is served by
205
+ * the same adapter, so a reading never depends on which spelling the caller
206
+ * happens to hold.
207
+ *
184
208
  * @param {string} route Provider route, e.g. `minimax-cn`.
185
209
  * @returns {ProviderAdapter | undefined} The adapter, when one serves the route.
186
210
  */
187
211
  export function findAdapter(route) {
188
- return BY_ROUTE.get(route)
212
+ return BY_ROUTE.get(route) ?? BY_MODEL_ROUTE.get(route)
213
+ }
214
+
215
+ /**
216
+ * The Host route ids that stand for the same vendor as one balance route.
217
+ *
218
+ * @param {ProviderAdapter} adapter The adapter.
219
+ * @returns {readonly string[]} The other ids of the same vendor.
220
+ */
221
+ export function aliasesOf(adapter) {
222
+ return (adapter.modelRoutes ?? []).filter((route) => !adapter.routes.includes(route))
189
223
  }
190
224
 
191
225
  export { KIND_AMOUNT, KIND_QUOTA }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-allowance",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "Shows the current conversation model's provider balance or remaining allowance in the composer.",
6
6
  "license": "MIT",