dsh-model-allowance 1.0.5 → 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 +14 -3
- package/README.zh.md +12 -3
- package/client.js +282 -39
- package/lib/balance.js +102 -17
- package/lib/providers/deepseek.js +5 -0
- package/lib/providers/placeholder.js +3 -3
- package/lib/providers/shared.js +6 -0
- package/lib/providers.js +38 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,13 @@ conversation model.
|
|
|
8
8
|
The card also switches the session: the button next to the console link
|
|
9
9
|
lists the provider's models and moves the conversation to the one you pick.
|
|
10
10
|
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
The card shows the provider's remaining balance or allowance and the model
|
|
16
|
+
of the current conversation, next to the input box.
|
|
17
|
+
|
|
11
18
|
## Supported
|
|
12
19
|
|
|
13
20
|
- DeepSeek
|
|
@@ -18,6 +25,10 @@ lists the provider's models and moves the conversation to the one you pick.
|
|
|
18
25
|
|
|
19
26
|
### Not supported
|
|
20
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
|
+
|
|
21
32
|
- Qwen Token Plan: the vendor publishes no balance API
|
|
22
33
|
- Mimo Token Plan:the vendor publishes no balance API
|
|
23
34
|
|
|
@@ -29,10 +40,10 @@ lists the provider's models and moves the conversation to the one you pick.
|
|
|
29
40
|
2. Choose **Install** and enter:
|
|
30
41
|
|
|
31
42
|
```
|
|
32
|
-
dsh-model-allowance@1.0.
|
|
43
|
+
dsh-model-allowance@1.0.7
|
|
33
44
|
```
|
|
34
45
|
|
|
35
|
-
Use the latest published version instead of `1.0.
|
|
46
|
+
Use the latest published version instead of `1.0.7` when a newer one
|
|
36
47
|
exists.
|
|
37
48
|
3. Confirm the installation. If DSH reports **restart required**, restart
|
|
38
49
|
DSH; otherwise refresh the page.
|
|
@@ -42,7 +53,7 @@ The npm installation is eligible for the Plugin Manager's **Update** action.
|
|
|
42
53
|
### Install from GitHub
|
|
43
54
|
|
|
44
55
|
```
|
|
45
|
-
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.
|
|
56
|
+
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.7
|
|
46
57
|
```
|
|
47
58
|
|
|
48
59
|
Git installations are not covered by the Plugin Manager's **Update** action;
|
package/README.zh.md
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
卡片同时负责切换:控制台链接旁边的按钮会列出该厂商的模型,选中哪一个,
|
|
8
8
|
会话就切到哪一个。
|
|
9
9
|
|
|
10
|
+
## 使用
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
卡片显示厂商的余额或剩余额度,以及当前会话所用的模型,位于输入框旁。
|
|
15
|
+
|
|
10
16
|
## 支持
|
|
11
17
|
|
|
12
18
|
- DeepSeek
|
|
@@ -17,6 +23,9 @@
|
|
|
17
23
|
|
|
18
24
|
### 不支持
|
|
19
25
|
|
|
26
|
+
以下厂商没有余额接口,但只要本地配置了它们,它们依然会出现在卡片里:
|
|
27
|
+
面板会提示“目前无余额接口”,模型列表照常可以切换。
|
|
28
|
+
|
|
20
29
|
- 千问 Token Plan:官方未提供余额接口
|
|
21
30
|
- Mimo Token Plan:官方未提供余额接口
|
|
22
31
|
|
|
@@ -28,10 +37,10 @@
|
|
|
28
37
|
2. 点击 **Install(安装)**,填入:
|
|
29
38
|
|
|
30
39
|
```
|
|
31
|
-
dsh-model-allowance@1.0.
|
|
40
|
+
dsh-model-allowance@1.0.7
|
|
32
41
|
```
|
|
33
42
|
|
|
34
|
-
如果已有更新版本,请把 `1.0.
|
|
43
|
+
如果已有更新版本,请把 `1.0.7` 换成最新的精确版本。
|
|
35
44
|
3. 确认安装。如果 DSH 提示需要重启,重启 DSH;否则刷新页面即可。
|
|
36
45
|
|
|
37
46
|
通过 npm 安装的版本可以在 Plugin Manager 中使用 **Update** 更新。
|
|
@@ -39,7 +48,7 @@
|
|
|
39
48
|
### 从 GitHub 安装
|
|
40
49
|
|
|
41
50
|
```
|
|
42
|
-
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.
|
|
51
|
+
git+https://github.com/MeiK2333/dsh-model-allowance.git#v1.0.7
|
|
43
52
|
```
|
|
44
53
|
|
|
45
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", {
|
|
@@ -339,12 +429,13 @@ var zh = {
|
|
|
339
429
|
"detail.console": "\u63A7\u5236\u53F0",
|
|
340
430
|
"detail.error": "\u65E0\u6CD5\u8BFB\u53D6\u5382\u5546\u4F59\u989D\u3002",
|
|
341
431
|
"detail.moreProviders": "\u66F4\u591A\u5382\u5546",
|
|
342
|
-
"detail.switchModelHere": "\u5207\u6362 {name}
|
|
343
|
-
"detail.switchModelThere": "\u5207\u6362\u5230 {name}
|
|
432
|
+
"detail.switchModelHere": "\u5207\u6362 {name}",
|
|
433
|
+
"detail.switchModelThere": "\u5207\u6362\u5230 {name}",
|
|
344
434
|
"model.title": "\u6A21\u578B",
|
|
345
435
|
"model.loading": "\u52A0\u8F7D\u6A21\u578B\u2026",
|
|
346
436
|
"model.empty": "\u8BE5\u5382\u5546\u6682\u65E0\u53EF\u7528\u6A21\u578B",
|
|
347
437
|
"model.current": "\u5F53\u524D",
|
|
438
|
+
"model.effortDefault": "\u9ED8\u8BA4",
|
|
348
439
|
"model.switching": "\u5207\u6362\u4E2D\u2026",
|
|
349
440
|
"model.failed": "\u5207\u6362\u5931\u8D25\uFF1A{error}",
|
|
350
441
|
"model.loadFailed": "\u8BFB\u53D6\u6A21\u578B\u5217\u8868\u5931\u8D25\uFF1A{error}",
|
|
@@ -402,12 +493,13 @@ var en = {
|
|
|
402
493
|
"detail.console": "Console",
|
|
403
494
|
"detail.error": "Could not read the provider balance.",
|
|
404
495
|
"detail.moreProviders": "More providers",
|
|
405
|
-
"detail.switchModelHere": "Switch
|
|
406
|
-
"detail.switchModelThere": "Switch to
|
|
496
|
+
"detail.switchModelHere": "Switch within {name}",
|
|
497
|
+
"detail.switchModelThere": "Switch to {name}",
|
|
407
498
|
"model.title": "Models",
|
|
408
499
|
"model.loading": "Loading models\u2026",
|
|
409
500
|
"model.empty": "No models available for this provider",
|
|
410
501
|
"model.current": "Current",
|
|
502
|
+
"model.effortDefault": "Default",
|
|
411
503
|
"model.switching": "Switching\u2026",
|
|
412
504
|
"model.failed": "Switch failed: {error}",
|
|
413
505
|
"model.loadFailed": "Could not read the model list: {error}",
|
|
@@ -477,6 +569,30 @@ function modelsForProvider(catalog, provider) {
|
|
|
477
569
|
const models = Array.isArray(group?.models) ? group.models : [];
|
|
478
570
|
return models.filter((model) => typeof model?.id === "string" && model.id !== "");
|
|
479
571
|
}
|
|
572
|
+
function providerModelGroup(catalog, routes) {
|
|
573
|
+
const seen = /* @__PURE__ */ new Set();
|
|
574
|
+
for (const route of routes) {
|
|
575
|
+
if (typeof route !== "string" || route === "" || seen.has(route)) continue;
|
|
576
|
+
seen.add(route);
|
|
577
|
+
const models = modelsForProvider(catalog, route);
|
|
578
|
+
if (models.length > 0) return { provider: route, models };
|
|
579
|
+
}
|
|
580
|
+
return void 0;
|
|
581
|
+
}
|
|
582
|
+
function effortChoices(model) {
|
|
583
|
+
const reasoning = model?.reasoning;
|
|
584
|
+
const efforts = Array.isArray(reasoning?.efforts) ? reasoning.efforts : [];
|
|
585
|
+
if (efforts.length === 0) return null;
|
|
586
|
+
const entries = efforts.filter((effort) => typeof effort?.id === "string" && effort.id !== "").map((effort) => ({
|
|
587
|
+
id: effort.id,
|
|
588
|
+
name: typeof effort.name === "string" && effort.name !== "" ? effort.name : effort.id,
|
|
589
|
+
isDefault: effort.id === reasoning.defaultEffort
|
|
590
|
+
}));
|
|
591
|
+
if (reasoning.defaultEffort === void 0) {
|
|
592
|
+
entries.unshift({ id: void 0, providerDefault: true });
|
|
593
|
+
}
|
|
594
|
+
return entries;
|
|
595
|
+
}
|
|
480
596
|
function currentModelFor(selection, provider) {
|
|
481
597
|
const next = selection?.next ?? selection?.lastUsed;
|
|
482
598
|
if (next?.provider !== provider) return void 0;
|
|
@@ -781,8 +897,7 @@ var STYLES = [
|
|
|
781
897
|
".dsh-model-allowance-panel{position:absolute;bottom:calc(100% + 6px);right:0;z-index:20;",
|
|
782
898
|
"box-sizing:border-box;min-width:300px;max-width:calc(100vw - 24px);",
|
|
783
899
|
"padding:8px 10px 10px;border:0;",
|
|
784
|
-
"border-radius:var(--dsw-radius-lg);background:var(--dsw-
|
|
785
|
-
"backdrop-filter:var(--dsw-menu-backdrop-filter);",
|
|
900
|
+
"border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-2);",
|
|
786
901
|
"box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);",
|
|
787
902
|
"font-size:12px}",
|
|
788
903
|
".dsh-model-allowance-row{display:flex;justify-content:space-between;gap:16px;padding:2px 0}",
|
|
@@ -832,11 +947,10 @@ var STYLES = [
|
|
|
832
947
|
".dsh-model-allowance-more:hover{color:var(--dsw-alias-label-secondary);",
|
|
833
948
|
"border-color:var(--dsw-alias-border-l2)}",
|
|
834
949
|
// The overflow menu is a second floating surface, so it carries the same
|
|
835
|
-
//
|
|
950
|
+
// solid layer and elevation as the card it belongs to.
|
|
836
951
|
".dsh-model-allowance-menu{position:absolute;top:calc(100% + 2px);right:0;z-index:30;",
|
|
837
952
|
"min-width:150px;padding:4px;border:0;",
|
|
838
|
-
"border-radius:var(--dsw-radius-md);background:var(--dsw-
|
|
839
|
-
"backdrop-filter:var(--dsw-menu-backdrop-filter);",
|
|
953
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
840
954
|
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
841
955
|
".dsh-model-allowance-menu-item{display:flex;align-items:center;gap:8px;width:100%;",
|
|
842
956
|
"padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);background:0 0;",
|
|
@@ -852,11 +966,15 @@ var STYLES = [
|
|
|
852
966
|
// The model list is a third floating surface. It opens upwards from the
|
|
853
967
|
// footer button, so it carries the same menu surface and elevation as the
|
|
854
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.
|
|
855
974
|
".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
|
|
856
975
|
".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
|
|
857
976
|
"min-width:180px;max-width:260px;max-height:240px;overflow-y:auto;padding:4px;border:0;",
|
|
858
|
-
"border-radius:var(--dsw-radius-md);background:var(--dsw-
|
|
859
|
-
"backdrop-filter:var(--dsw-menu-backdrop-filter);",
|
|
977
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
860
978
|
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
861
979
|
".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
|
|
862
980
|
"gap:10px;width:100%;padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
@@ -867,6 +985,28 @@ var STYLES = [
|
|
|
867
985
|
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
868
986
|
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
869
987
|
".dsh-model-allowance-model-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
988
|
+
// The trailing side of a model row carries its state label and, for a
|
|
989
|
+
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
990
|
+
// the right.
|
|
991
|
+
".dsh-model-allowance-model-side{display:inline-flex;align-items:center;gap:4px;flex:none}",
|
|
992
|
+
".dsh-model-allowance-model-arrow{color:var(--dsw-alias-label-tertiary);font-size:12px;",
|
|
993
|
+
"line-height:1}",
|
|
994
|
+
// The effort flyout opens to the right of the list, on the row the
|
|
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.
|
|
997
|
+
".dsh-model-allowance-effort-menu{position:absolute;left:calc(100% + 4px);z-index:31;",
|
|
998
|
+
"display:flex;flex-direction:column;min-width:130px;max-width:220px;padding:4px;border:0;",
|
|
999
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
1000
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
1001
|
+
".dsh-model-allowance-effort-item{display:flex;align-items:center;justify-content:space-between;",
|
|
1002
|
+
"gap:10px;width:100%;padding:3px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
1003
|
+
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
1004
|
+
".dsh-model-allowance-effort-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1005
|
+
// The provider's own default effort is dimmed like the model in use, so
|
|
1006
|
+
// the open submenu points at it before anything is picked.
|
|
1007
|
+
'.dsh-model-allowance-effort-item[data-default="true"],',
|
|
1008
|
+
'.dsh-model-allowance-effort-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
1009
|
+
".dsh-model-allowance-effort-item[disabled]{opacity:.6;cursor:default}",
|
|
870
1010
|
// The trailing label names the state of one model: the one in use, or the
|
|
871
1011
|
// one being switched to.
|
|
872
1012
|
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
@@ -1118,11 +1258,17 @@ function statusDisplayState(status) {
|
|
|
1118
1258
|
if (status.state === "unknown" && !status.url && !status.error) return "unsupported";
|
|
1119
1259
|
return status.state;
|
|
1120
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
|
+
}
|
|
1121
1266
|
function BalanceBadge(props) {
|
|
1122
1267
|
const { useProjection, ctx, t } = props;
|
|
1123
1268
|
const selection = useProjection("modelSelection");
|
|
1124
1269
|
const selected = selection?.next?.provider ?? selection?.lastUsed?.provider ?? null;
|
|
1125
1270
|
const selectedModel = selection?.next?.model ?? selection?.lastUsed?.model ?? void 0;
|
|
1271
|
+
const selectedEffort = selection?.next?.reasoningEffort ?? selection?.lastUsed?.reasoningEffort ?? void 0;
|
|
1126
1272
|
const sessionId = props.sessionId;
|
|
1127
1273
|
const [rawView, setView] = React.useState(null);
|
|
1128
1274
|
const [loading, setLoading] = React.useState(false);
|
|
@@ -1135,7 +1281,7 @@ function BalanceBadge(props) {
|
|
|
1135
1281
|
const lastModelProvider = React.useRef(null);
|
|
1136
1282
|
const available = directory.filter((entry) => entry.configured);
|
|
1137
1283
|
const entryOf = React.useCallback(
|
|
1138
|
-
(route) => directory.find((entry) => entry
|
|
1284
|
+
(route) => directory.find((entry) => entryCovers(entry, route)),
|
|
1139
1285
|
[directory]
|
|
1140
1286
|
);
|
|
1141
1287
|
const nameOf = React.useCallback((route) => pickName(entryOf(route), route), [entryOf]);
|
|
@@ -1147,9 +1293,13 @@ function BalanceBadge(props) {
|
|
|
1147
1293
|
const [providerStatus, setProviderStatus] = React.useState(null);
|
|
1148
1294
|
const [schedule, setSchedule] = React.useState(null);
|
|
1149
1295
|
const [modelList, setModelList] = React.useState([]);
|
|
1296
|
+
const [modelListRoute, setModelListRoute] = React.useState(null);
|
|
1297
|
+
const [catalogProvider, setCatalogProvider] = React.useState(null);
|
|
1150
1298
|
const [modelListState, setModelListState] = React.useState("idle");
|
|
1151
1299
|
const [modelError, setModelError] = React.useState(null);
|
|
1152
1300
|
const [modelMenuOpen, setModelMenuOpen] = React.useState(false);
|
|
1301
|
+
const [hoverModel, setHoverModel] = React.useState(null);
|
|
1302
|
+
const hoverModelTimer = React.useRef(null);
|
|
1153
1303
|
const [switchingModel, setSwitchingModel] = React.useState(null);
|
|
1154
1304
|
const modelWrapRef = React.useRef(null);
|
|
1155
1305
|
const catalogRef = React.useRef({ value: null, at: 0 });
|
|
@@ -1197,12 +1347,15 @@ function BalanceBadge(props) {
|
|
|
1197
1347
|
setPicked(null);
|
|
1198
1348
|
});
|
|
1199
1349
|
const activeProvider = picked ?? provider;
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1350
|
+
const inUse = activeProvider === provider || entryOf(provider)?.route === activeProvider;
|
|
1351
|
+
const activeModel = inUse ? selectedModel : void 0;
|
|
1202
1352
|
const switchLabel = t(inUse ? "detail.switchModelHere" : "detail.switchModelThere", {
|
|
1203
1353
|
name: nameOf(activeProvider)
|
|
1204
1354
|
});
|
|
1205
|
-
const
|
|
1355
|
+
const modelProvider = catalogProvider ?? activeProvider;
|
|
1356
|
+
const currentModel = currentModelFor(selection, modelProvider);
|
|
1357
|
+
const shownModelList = modelListRoute === activeProvider ? modelList : [];
|
|
1358
|
+
const shownModelListState = modelListRoute === activeProvider ? modelListState : "loading";
|
|
1206
1359
|
const sessionFace = lookupSessionFace(ctx);
|
|
1207
1360
|
const canSwitch = typeof sessionId === "string" && sessionId !== "" && sessionFace !== void 0 && typeof sessionFace.selectModel === "function";
|
|
1208
1361
|
const view = rawView?.provider === activeProvider ? rawView : null;
|
|
@@ -1425,11 +1578,15 @@ function BalanceBadge(props) {
|
|
|
1425
1578
|
}, [activeProvider, activeModel]);
|
|
1426
1579
|
const showModels = React.useCallback(
|
|
1427
1580
|
(catalog) => {
|
|
1428
|
-
const
|
|
1581
|
+
const routes = [activeProvider, ...entryOf(activeProvider)?.modelRoutes ?? []];
|
|
1582
|
+
const group = providerModelGroup(catalog, routes);
|
|
1583
|
+
const models = group?.models ?? [];
|
|
1584
|
+
setCatalogProvider(group?.provider ?? null);
|
|
1585
|
+
setModelListRoute(activeProvider);
|
|
1429
1586
|
setModelList(models);
|
|
1430
1587
|
setModelListState(models.length > 0 ? "ready" : "empty");
|
|
1431
1588
|
},
|
|
1432
|
-
[activeProvider]
|
|
1589
|
+
[activeProvider, entryOf]
|
|
1433
1590
|
);
|
|
1434
1591
|
React.useEffect(() => {
|
|
1435
1592
|
if (!modelMenuOpen) return void 0;
|
|
@@ -1482,7 +1639,7 @@ function BalanceBadge(props) {
|
|
|
1482
1639
|
};
|
|
1483
1640
|
}, [modelMenuOpen]);
|
|
1484
1641
|
const switchToModel = React.useCallback(
|
|
1485
|
-
async (model) => {
|
|
1642
|
+
async (model, effort) => {
|
|
1486
1643
|
const face = lookupSessionFace(ctx);
|
|
1487
1644
|
if (face === void 0 || typeof face.selectModel !== "function") {
|
|
1488
1645
|
setModelError(t("model.unavailable"));
|
|
@@ -1494,10 +1651,9 @@ function BalanceBadge(props) {
|
|
|
1494
1651
|
}
|
|
1495
1652
|
setSwitchingModel(model.id);
|
|
1496
1653
|
try {
|
|
1497
|
-
const effort = model.reasoning?.defaultEffort;
|
|
1498
1654
|
const result = await face.selectModel({
|
|
1499
1655
|
sessionId,
|
|
1500
|
-
provider: activeProvider,
|
|
1656
|
+
provider: catalogProvider ?? activeProvider,
|
|
1501
1657
|
model: model.id,
|
|
1502
1658
|
...typeof effort === "string" && effort !== "" ? { reasoningEffort: effort } : {}
|
|
1503
1659
|
});
|
|
@@ -1516,8 +1672,18 @@ function BalanceBadge(props) {
|
|
|
1516
1672
|
setSwitchingModel(null);
|
|
1517
1673
|
}
|
|
1518
1674
|
},
|
|
1519
|
-
[ctx, sessionId, activeProvider, t]
|
|
1675
|
+
[ctx, sessionId, activeProvider, catalogProvider, t]
|
|
1520
1676
|
);
|
|
1677
|
+
const showEffortFlyout = React.useCallback((model, top) => {
|
|
1678
|
+
clearTimeout(hoverModelTimer.current);
|
|
1679
|
+
setHoverModel({ model, top });
|
|
1680
|
+
}, []);
|
|
1681
|
+
const scheduleEffortFlyoutClose = React.useCallback((id) => {
|
|
1682
|
+
clearTimeout(hoverModelTimer.current);
|
|
1683
|
+
hoverModelTimer.current = setTimeout(() => {
|
|
1684
|
+
setHoverModel((current) => current?.model?.id === id ? null : current);
|
|
1685
|
+
}, 150);
|
|
1686
|
+
}, []);
|
|
1521
1687
|
const label = React.useMemo(() => {
|
|
1522
1688
|
if (!provider) return "";
|
|
1523
1689
|
if (!view) return t("badge.loading");
|
|
@@ -1567,7 +1733,7 @@ function BalanceBadge(props) {
|
|
|
1567
1733
|
}
|
|
1568
1734
|
let shown = available.slice(0, visibleCount);
|
|
1569
1735
|
let overflow = available.slice(visibleCount);
|
|
1570
|
-
const activeIndex = overflow.findIndex((entry) => entry
|
|
1736
|
+
const activeIndex = overflow.findIndex((entry) => entryCovers(entry, activeProvider));
|
|
1571
1737
|
if (activeIndex >= 0 && shown.length > 0) {
|
|
1572
1738
|
const displaced = shown[shown.length - 1];
|
|
1573
1739
|
shown = [...shown.slice(0, -1), overflow[activeIndex]];
|
|
@@ -1576,6 +1742,7 @@ function BalanceBadge(props) {
|
|
|
1576
1742
|
const markButton = (entry) => {
|
|
1577
1743
|
const mark = markFor(entry.route);
|
|
1578
1744
|
const name = nameOf(entry.route);
|
|
1745
|
+
const active = entryCovers(entry, activeProvider);
|
|
1579
1746
|
return (0, import_react3.createElement)(
|
|
1580
1747
|
"button",
|
|
1581
1748
|
{
|
|
@@ -1583,8 +1750,8 @@ function BalanceBadge(props) {
|
|
|
1583
1750
|
key: entry.route,
|
|
1584
1751
|
role: "tab",
|
|
1585
1752
|
className: "dsh-model-allowance-tab",
|
|
1586
|
-
"data-active":
|
|
1587
|
-
"aria-selected":
|
|
1753
|
+
"data-active": active ? "true" : "false",
|
|
1754
|
+
"aria-selected": active ? "true" : "false",
|
|
1588
1755
|
"aria-label": name,
|
|
1589
1756
|
title: name,
|
|
1590
1757
|
style: { "--provider-mark": mark.color },
|
|
@@ -1939,6 +2106,8 @@ function BalanceBadge(props) {
|
|
|
1939
2106
|
"aria-label": switchLabel,
|
|
1940
2107
|
onClick: () => {
|
|
1941
2108
|
setModelError(null);
|
|
2109
|
+
clearTimeout(hoverModelTimer.current);
|
|
2110
|
+
setHoverModel(null);
|
|
1942
2111
|
setModelMenuOpen((value) => !value);
|
|
1943
2112
|
}
|
|
1944
2113
|
},
|
|
@@ -1951,17 +2120,17 @@ function BalanceBadge(props) {
|
|
|
1951
2120
|
role: "menu",
|
|
1952
2121
|
"aria-label": t("model.title")
|
|
1953
2122
|
},
|
|
1954
|
-
|
|
2123
|
+
shownModelListState === "loading" ? (0, import_react3.createElement)(
|
|
1955
2124
|
"div",
|
|
1956
2125
|
{ className: "dsh-model-allowance-model-message" },
|
|
1957
2126
|
t("model.loading")
|
|
1958
2127
|
) : null,
|
|
1959
|
-
|
|
2128
|
+
shownModelListState === "empty" ? (0, import_react3.createElement)(
|
|
1960
2129
|
"div",
|
|
1961
2130
|
{ className: "dsh-model-allowance-model-message" },
|
|
1962
2131
|
t("model.empty")
|
|
1963
2132
|
) : null,
|
|
1964
|
-
|
|
2133
|
+
shownModelListState === "error" ? (0, import_react3.createElement)(
|
|
1965
2134
|
"div",
|
|
1966
2135
|
{
|
|
1967
2136
|
className: "dsh-model-allowance-model-message",
|
|
@@ -1969,8 +2138,10 @@ function BalanceBadge(props) {
|
|
|
1969
2138
|
},
|
|
1970
2139
|
modelError ?? t("model.unavailable")
|
|
1971
2140
|
) : null,
|
|
1972
|
-
...
|
|
2141
|
+
...shownModelList.map((model) => {
|
|
1973
2142
|
const isCurrent = model.id === currentModel;
|
|
2143
|
+
const efforts = effortChoices(model);
|
|
2144
|
+
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
1974
2145
|
return (0, import_react3.createElement)(
|
|
1975
2146
|
"button",
|
|
1976
2147
|
{
|
|
@@ -1982,8 +2153,20 @@ function BalanceBadge(props) {
|
|
|
1982
2153
|
className: "dsh-model-allowance-model-item",
|
|
1983
2154
|
disabled: switchingModel !== null,
|
|
1984
2155
|
title: model.id,
|
|
2156
|
+
...efforts === null ? {} : { "aria-haspopup": "menu" },
|
|
1985
2157
|
onClick: () => {
|
|
1986
|
-
void switchToModel(model);
|
|
2158
|
+
void switchToModel(model, defaultEffortId);
|
|
2159
|
+
},
|
|
2160
|
+
...efforts === null ? {} : {
|
|
2161
|
+
onMouseEnter: (event) => {
|
|
2162
|
+
const wrap = modelWrapRef.current;
|
|
2163
|
+
if (!wrap) return;
|
|
2164
|
+
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
2165
|
+
showEffortFlyout(model, top);
|
|
2166
|
+
},
|
|
2167
|
+
onMouseLeave: () => {
|
|
2168
|
+
scheduleEffortFlyoutClose(model.id);
|
|
2169
|
+
}
|
|
1987
2170
|
}
|
|
1988
2171
|
},
|
|
1989
2172
|
(0, import_react3.createElement)(
|
|
@@ -1991,19 +2174,31 @@ function BalanceBadge(props) {
|
|
|
1991
2174
|
{ className: "dsh-model-allowance-model-name" },
|
|
1992
2175
|
model.name ?? model.id
|
|
1993
2176
|
),
|
|
1994
|
-
|
|
1995
|
-
"span",
|
|
1996
|
-
{ className: "dsh-model-allowance-model-note" },
|
|
1997
|
-
t("model.switching")
|
|
1998
|
-
) : isCurrent ? (0, import_react3.createElement)(
|
|
2177
|
+
(0, import_react3.createElement)(
|
|
1999
2178
|
"span",
|
|
2000
|
-
{ className: "dsh-model-allowance-model-
|
|
2001
|
-
|
|
2002
|
-
|
|
2179
|
+
{ className: "dsh-model-allowance-model-side" },
|
|
2180
|
+
switchingModel === model.id ? (0, import_react3.createElement)(
|
|
2181
|
+
"span",
|
|
2182
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2183
|
+
t("model.switching")
|
|
2184
|
+
) : isCurrent ? (0, import_react3.createElement)(
|
|
2185
|
+
"span",
|
|
2186
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2187
|
+
t("model.current")
|
|
2188
|
+
) : null,
|
|
2189
|
+
efforts === null ? null : (0, import_react3.createElement)(
|
|
2190
|
+
"span",
|
|
2191
|
+
{
|
|
2192
|
+
className: "dsh-model-allowance-model-arrow",
|
|
2193
|
+
"aria-hidden": true
|
|
2194
|
+
},
|
|
2195
|
+
"\u203A"
|
|
2196
|
+
)
|
|
2197
|
+
)
|
|
2003
2198
|
);
|
|
2004
2199
|
}),
|
|
2005
2200
|
// A failed switch keeps the list open and says why.
|
|
2006
|
-
modelError &&
|
|
2201
|
+
modelError && shownModelListState !== "error" ? (0, import_react3.createElement)(
|
|
2007
2202
|
"div",
|
|
2008
2203
|
{
|
|
2009
2204
|
className: "dsh-model-allowance-model-message",
|
|
@@ -2011,6 +2206,54 @@ function BalanceBadge(props) {
|
|
|
2011
2206
|
},
|
|
2012
2207
|
modelError
|
|
2013
2208
|
) : null
|
|
2209
|
+
) : null,
|
|
2210
|
+
// The effort flyout is a sibling of the list, not a
|
|
2211
|
+
// child: the list scrolls, and a nested panel would be
|
|
2212
|
+
// clipped by it. Sharing the hover with the row keeps
|
|
2213
|
+
// it open while the pointer crosses over.
|
|
2214
|
+
modelMenuOpen && hoverModel !== null && shownModelList.includes(hoverModel.model) ? (0, import_react3.createElement)(
|
|
2215
|
+
"div",
|
|
2216
|
+
{
|
|
2217
|
+
className: "dsh-model-allowance-effort-menu",
|
|
2218
|
+
role: "menu",
|
|
2219
|
+
"aria-label": t("model.title"),
|
|
2220
|
+
style: { top: `${hoverModel.top}px` },
|
|
2221
|
+
onMouseEnter: () => {
|
|
2222
|
+
clearTimeout(hoverModelTimer.current);
|
|
2223
|
+
},
|
|
2224
|
+
onMouseLeave: () => {
|
|
2225
|
+
scheduleEffortFlyoutClose(hoverModel.model.id);
|
|
2226
|
+
}
|
|
2227
|
+
},
|
|
2228
|
+
...effortChoices(hoverModel.model).map((effort) => {
|
|
2229
|
+
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
2230
|
+
return (0, import_react3.createElement)(
|
|
2231
|
+
"button",
|
|
2232
|
+
{
|
|
2233
|
+
type: "button",
|
|
2234
|
+
key: effort.id ?? "provider-default",
|
|
2235
|
+
role: "menuitemradio",
|
|
2236
|
+
"aria-checked": isCurrentEffort ? "true" : "false",
|
|
2237
|
+
"data-current": isCurrentEffort ? "true" : "false",
|
|
2238
|
+
"data-default": effort.isDefault ? "true" : "false",
|
|
2239
|
+
className: "dsh-model-allowance-effort-item",
|
|
2240
|
+
disabled: switchingModel !== null,
|
|
2241
|
+
onClick: () => {
|
|
2242
|
+
void switchToModel(hoverModel.model, effort.id);
|
|
2243
|
+
}
|
|
2244
|
+
},
|
|
2245
|
+
(0, import_react3.createElement)(
|
|
2246
|
+
"span",
|
|
2247
|
+
{ className: "dsh-model-allowance-model-name" },
|
|
2248
|
+
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
2249
|
+
),
|
|
2250
|
+
effort.isDefault && !isCurrentEffort ? (0, import_react3.createElement)(
|
|
2251
|
+
"span",
|
|
2252
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2253
|
+
t("model.effortDefault")
|
|
2254
|
+
) : null
|
|
2255
|
+
);
|
|
2256
|
+
})
|
|
2014
2257
|
) : null
|
|
2015
2258
|
) : null
|
|
2016
2259
|
)
|
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,34 +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
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
configured = (await this.routeCredentials.resolve(route, adapter)) !== undefined
|
|
317
|
-
}
|
|
318
|
-
routes.push({ route, configured, ...displayOf(adapter) })
|
|
325
|
+
routes.push({
|
|
326
|
+
route,
|
|
327
|
+
configured: await this.#configured(adapter, route, host),
|
|
328
|
+
...displayOf(adapter),
|
|
329
|
+
...(adapter.modelRoutes === undefined ? {} : { modelRoutes: adapter.modelRoutes }),
|
|
330
|
+
...(aliases.length === 0 ? {} : { aliases }),
|
|
331
|
+
})
|
|
319
332
|
}
|
|
320
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
|
+
}
|
|
321
346
|
return routes
|
|
322
347
|
}
|
|
323
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
|
+
|
|
324
409
|
/**
|
|
325
410
|
* Drop every cached reading.
|
|
326
411
|
*/
|
|
@@ -389,6 +389,11 @@ export const deepseekAdapters = [
|
|
|
389
389
|
id: 'deepseek-api-key',
|
|
390
390
|
routes: ['deepseek'],
|
|
391
391
|
kind: KIND_AMOUNT,
|
|
392
|
+
// The balance route and the Host provider routes that list this vendor's
|
|
393
|
+
// models are not the same id: the catalog group with the API-key models
|
|
394
|
+
// answers as `deepseek-official` while the pi-ai `deepseek` route may be
|
|
395
|
+
// unconfigured and carry an empty group.
|
|
396
|
+
modelRoutes: ['deepseek', 'deepseek-official'],
|
|
392
397
|
endpoint: 'https://api.deepseek.com/user/balance',
|
|
393
398
|
auth: 'bearer',
|
|
394
399
|
credentialRefs: ['DEEPSEEK_API_KEY'],
|
|
@@ -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: '#
|
|
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: '#
|
|
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: '#
|
|
446
|
+
color: '#082DFF',
|
|
447
447
|
icon: 'qwen',
|
|
448
448
|
consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
|
|
449
449
|
}),
|
package/lib/providers/shared.js
CHANGED
|
@@ -147,6 +147,9 @@ export function bindingWindow(windows) {
|
|
|
147
147
|
* @param {object} spec The declaration.
|
|
148
148
|
* @param {string} spec.id Adapter identity.
|
|
149
149
|
* @param {readonly string[]} spec.routes Provider routes this adapter serves.
|
|
150
|
+
* @param {readonly string[]} [spec.modelRoutes] Host provider routes whose
|
|
151
|
+
* catalog groups list this vendor's models, when they differ from the
|
|
152
|
+
* balance route.
|
|
150
153
|
* @param {'amount'|'quota'} spec.kind Quantity dimension of the reading.
|
|
151
154
|
* @param {boolean} [spec.modelScoped] Whether the reading is per model.
|
|
152
155
|
* @param {string} spec.consoleUrl Provider console for a manual check.
|
|
@@ -248,6 +251,9 @@ export function defineAdapter(spec) {
|
|
|
248
251
|
return Object.freeze({
|
|
249
252
|
id: spec.id,
|
|
250
253
|
routes: Object.freeze([...spec.routes]),
|
|
254
|
+
...(spec.modelRoutes === undefined
|
|
255
|
+
? {}
|
|
256
|
+
: { modelRoutes: Object.freeze([...spec.modelRoutes]) }),
|
|
251
257
|
kind: spec.kind,
|
|
252
258
|
...(spec.modelScoped === true ? { modelScoped: true } : {}),
|
|
253
259
|
consoleUrl: spec.consoleUrl,
|
package/lib/providers.js
CHANGED
|
@@ -92,6 +92,10 @@ import { zaiAdapters } from './providers/zai.js'
|
|
|
92
92
|
* @typedef {object} ProviderAdapter
|
|
93
93
|
* @property {string} id Adapter identity.
|
|
94
94
|
* @property {readonly string[]} routes Provider routes this adapter serves.
|
|
95
|
+
* @property {readonly string[]} [modelRoutes] Host provider routes whose catalog
|
|
96
|
+
* groups list this vendor's models, when they differ from the balance route.
|
|
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.
|
|
95
99
|
* @property {'amount'|'quota'} kind Quantity dimension of the reading.
|
|
96
100
|
* @property {boolean} [modelScoped] Whether the reading is per provider-owned model.
|
|
97
101
|
* @property {string} consoleUrl Provider console for a manual check.
|
|
@@ -165,6 +169,16 @@ export const PROVIDER_ADAPTERS = Object.freeze([
|
|
|
165
169
|
|
|
166
170
|
/** Route to the adapter serving it, resolved once at load. */
|
|
167
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()
|
|
168
182
|
for (const adapter of PROVIDER_ADAPTERS) {
|
|
169
183
|
for (const route of adapter.routes) {
|
|
170
184
|
// Two adapters answering the same route would make a reading depend on
|
|
@@ -174,15 +188,38 @@ for (const adapter of PROVIDER_ADAPTERS) {
|
|
|
174
188
|
}
|
|
175
189
|
BY_ROUTE.set(route, adapter)
|
|
176
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
|
+
}
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
/**
|
|
180
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
|
+
*
|
|
181
208
|
* @param {string} route Provider route, e.g. `minimax-cn`.
|
|
182
209
|
* @returns {ProviderAdapter | undefined} The adapter, when one serves the route.
|
|
183
210
|
*/
|
|
184
211
|
export function findAdapter(route) {
|
|
185
|
-
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))
|
|
186
223
|
}
|
|
187
224
|
|
|
188
225
|
export { KIND_AMOUNT, KIND_QUOTA }
|