dsh-model-allowance 1.0.4 → 1.0.6
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 +7 -0
- package/README.zh.md +6 -0
- package/client.js +220 -50
- package/lib/balance.js +7 -2
- package/lib/providers/deepseek.js +5 -0
- package/lib/providers/shared.js +6 -0
- package/lib/providers.js +3 -0
- package/lib/status.js +3 -2
- 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
|
package/README.zh.md
CHANGED
package/client.js
CHANGED
|
@@ -339,12 +339,13 @@ var zh = {
|
|
|
339
339
|
"detail.console": "\u63A7\u5236\u53F0",
|
|
340
340
|
"detail.error": "\u65E0\u6CD5\u8BFB\u53D6\u5382\u5546\u4F59\u989D\u3002",
|
|
341
341
|
"detail.moreProviders": "\u66F4\u591A\u5382\u5546",
|
|
342
|
-
"detail.switchModelHere": "\u5207\u6362 {name}
|
|
343
|
-
"detail.switchModelThere": "\u5207\u6362\u5230 {name}
|
|
342
|
+
"detail.switchModelHere": "\u5207\u6362 {name}",
|
|
343
|
+
"detail.switchModelThere": "\u5207\u6362\u5230 {name}",
|
|
344
344
|
"model.title": "\u6A21\u578B",
|
|
345
345
|
"model.loading": "\u52A0\u8F7D\u6A21\u578B\u2026",
|
|
346
346
|
"model.empty": "\u8BE5\u5382\u5546\u6682\u65E0\u53EF\u7528\u6A21\u578B",
|
|
347
347
|
"model.current": "\u5F53\u524D",
|
|
348
|
+
"model.effortDefault": "\u9ED8\u8BA4",
|
|
348
349
|
"model.switching": "\u5207\u6362\u4E2D\u2026",
|
|
349
350
|
"model.failed": "\u5207\u6362\u5931\u8D25\uFF1A{error}",
|
|
350
351
|
"model.loadFailed": "\u8BFB\u53D6\u6A21\u578B\u5217\u8868\u5931\u8D25\uFF1A{error}",
|
|
@@ -354,6 +355,8 @@ var zh = {
|
|
|
354
355
|
"status.partialOutage": "\u90E8\u5206\u670D\u52A1\u4E2D\u65AD",
|
|
355
356
|
"status.majorOutage": "\u5927\u9762\u79EF\u4E2D\u65AD",
|
|
356
357
|
"status.maintenance": "\u7EF4\u62A4\u4E2D",
|
|
358
|
+
"status.loading": "\u72B6\u6001\u52A0\u8F7D\u4E2D\u2026",
|
|
359
|
+
"status.unsupported": "\u672A\u63D0\u4F9B\u72B6\u6001\u670D\u52A1",
|
|
357
360
|
"status.unknown": "\u72B6\u6001\u672A\u77E5",
|
|
358
361
|
"schedule.peakTitle": "\u9AD8\u5CF0\u65F6\u6BB5",
|
|
359
362
|
"schedule.offPeakTitle": "\u4F4E\u8C37\u65F6\u6BB5",
|
|
@@ -400,12 +403,13 @@ var en = {
|
|
|
400
403
|
"detail.console": "Console",
|
|
401
404
|
"detail.error": "Could not read the provider balance.",
|
|
402
405
|
"detail.moreProviders": "More providers",
|
|
403
|
-
"detail.switchModelHere": "Switch
|
|
404
|
-
"detail.switchModelThere": "Switch to
|
|
406
|
+
"detail.switchModelHere": "Switch within {name}",
|
|
407
|
+
"detail.switchModelThere": "Switch to {name}",
|
|
405
408
|
"model.title": "Models",
|
|
406
409
|
"model.loading": "Loading models\u2026",
|
|
407
410
|
"model.empty": "No models available for this provider",
|
|
408
411
|
"model.current": "Current",
|
|
412
|
+
"model.effortDefault": "Default",
|
|
409
413
|
"model.switching": "Switching\u2026",
|
|
410
414
|
"model.failed": "Switch failed: {error}",
|
|
411
415
|
"model.loadFailed": "Could not read the model list: {error}",
|
|
@@ -415,6 +419,8 @@ var en = {
|
|
|
415
419
|
"status.partialOutage": "Partial outage",
|
|
416
420
|
"status.majorOutage": "Major outage",
|
|
417
421
|
"status.maintenance": "Maintenance",
|
|
422
|
+
"status.loading": "Loading status\u2026",
|
|
423
|
+
"status.unsupported": "No status service provided",
|
|
418
424
|
"status.unknown": "Status unknown",
|
|
419
425
|
"schedule.peakTitle": "Peak hours",
|
|
420
426
|
"schedule.offPeakTitle": "Off-peak",
|
|
@@ -454,6 +460,8 @@ var STATUS_LABEL_KEYS = {
|
|
|
454
460
|
"partial-outage": "status.partialOutage",
|
|
455
461
|
"major-outage": "status.majorOutage",
|
|
456
462
|
maintenance: "status.maintenance",
|
|
463
|
+
loading: "status.loading",
|
|
464
|
+
unsupported: "status.unsupported",
|
|
457
465
|
unknown: "status.unknown"
|
|
458
466
|
};
|
|
459
467
|
function statusLabel(state, t) {
|
|
@@ -471,6 +479,30 @@ function modelsForProvider(catalog, provider) {
|
|
|
471
479
|
const models = Array.isArray(group?.models) ? group.models : [];
|
|
472
480
|
return models.filter((model) => typeof model?.id === "string" && model.id !== "");
|
|
473
481
|
}
|
|
482
|
+
function providerModelGroup(catalog, routes) {
|
|
483
|
+
const seen = /* @__PURE__ */ new Set();
|
|
484
|
+
for (const route of routes) {
|
|
485
|
+
if (typeof route !== "string" || route === "" || seen.has(route)) continue;
|
|
486
|
+
seen.add(route);
|
|
487
|
+
const models = modelsForProvider(catalog, route);
|
|
488
|
+
if (models.length > 0) return { provider: route, models };
|
|
489
|
+
}
|
|
490
|
+
return void 0;
|
|
491
|
+
}
|
|
492
|
+
function effortChoices(model) {
|
|
493
|
+
const reasoning = model?.reasoning;
|
|
494
|
+
const efforts = Array.isArray(reasoning?.efforts) ? reasoning.efforts : [];
|
|
495
|
+
if (efforts.length === 0) return null;
|
|
496
|
+
const entries = efforts.filter((effort) => typeof effort?.id === "string" && effort.id !== "").map((effort) => ({
|
|
497
|
+
id: effort.id,
|
|
498
|
+
name: typeof effort.name === "string" && effort.name !== "" ? effort.name : effort.id,
|
|
499
|
+
isDefault: effort.id === reasoning.defaultEffort
|
|
500
|
+
}));
|
|
501
|
+
if (reasoning.defaultEffort === void 0) {
|
|
502
|
+
entries.unshift({ id: void 0, providerDefault: true });
|
|
503
|
+
}
|
|
504
|
+
return entries;
|
|
505
|
+
}
|
|
474
506
|
function currentModelFor(selection, provider) {
|
|
475
507
|
const next = selection?.next ?? selection?.lastUsed;
|
|
476
508
|
if (next?.provider !== provider) return void 0;
|
|
@@ -861,6 +893,28 @@ var STYLES = [
|
|
|
861
893
|
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
862
894
|
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
863
895
|
".dsh-model-allowance-model-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
896
|
+
// The trailing side of a model row carries its state label and, for a
|
|
897
|
+
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
898
|
+
// the right.
|
|
899
|
+
".dsh-model-allowance-model-side{display:inline-flex;align-items:center;gap:4px;flex:none}",
|
|
900
|
+
".dsh-model-allowance-model-arrow{color:var(--dsw-alias-label-tertiary);font-size:12px;",
|
|
901
|
+
"line-height:1}",
|
|
902
|
+
// 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.
|
|
904
|
+
".dsh-model-allowance-effort-menu{position:absolute;left:calc(100% + 4px);z-index:31;",
|
|
905
|
+
"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);",
|
|
908
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
909
|
+
".dsh-model-allowance-effort-item{display:flex;align-items:center;justify-content:space-between;",
|
|
910
|
+
"gap:10px;width:100%;padding:3px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
911
|
+
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
912
|
+
".dsh-model-allowance-effort-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
913
|
+
// The provider's own default effort is dimmed like the model in use, so
|
|
914
|
+
// the open submenu points at it before anything is picked.
|
|
915
|
+
'.dsh-model-allowance-effort-item[data-default="true"],',
|
|
916
|
+
'.dsh-model-allowance-effort-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
917
|
+
".dsh-model-allowance-effort-item[disabled]{opacity:.6;cursor:default}",
|
|
864
918
|
// The trailing label names the state of one model: the one in use, or the
|
|
865
919
|
// one being switched to.
|
|
866
920
|
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
@@ -960,6 +1014,11 @@ var STYLES = [
|
|
|
960
1014
|
".dsh-model-allowance-status-help:focus-visible .dsh-model-allowance-status-tip{display:block}",
|
|
961
1015
|
".dsh-model-allowance-status-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
962
1016
|
"background:var(--dsw-alias-state-success-primary)}",
|
|
1017
|
+
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot,',
|
|
1018
|
+
'.dsh-model-allowance-status[data-state="unsupported"] .dsh-model-allowance-status-dot,',
|
|
1019
|
+
'.dsh-model-allowance-status[data-state="unknown"] .dsh-model-allowance-status-dot{',
|
|
1020
|
+
"background:var(--dsw-alias-state-idle-primary)}",
|
|
1021
|
+
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot{opacity:.5}',
|
|
963
1022
|
'.dsh-model-allowance-status[data-state="degraded"] .dsh-model-allowance-status-dot,',
|
|
964
1023
|
'.dsh-model-allowance-status[data-state="maintenance"] .dsh-model-allowance-status-dot{',
|
|
965
1024
|
"background:var(--dsw-alias-state-warn-primary)}",
|
|
@@ -1085,11 +1144,34 @@ var CATALOG_TTL_MS = 60 * 1e3;
|
|
|
1085
1144
|
function describe(error) {
|
|
1086
1145
|
return error instanceof Error ? error.message : String(error);
|
|
1087
1146
|
}
|
|
1147
|
+
async function readProviderStatus(provider) {
|
|
1148
|
+
try {
|
|
1149
|
+
const api = await getBalanceApi();
|
|
1150
|
+
if (!api || typeof api.status !== "function") {
|
|
1151
|
+
return { provider, state: "unknown", error: "status API unavailable" };
|
|
1152
|
+
}
|
|
1153
|
+
const result = await api.status(provider);
|
|
1154
|
+
if (!result.ok) {
|
|
1155
|
+
const error = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "status reading failed";
|
|
1156
|
+
return { provider, state: "unknown", error };
|
|
1157
|
+
}
|
|
1158
|
+
return result.value;
|
|
1159
|
+
} catch (error) {
|
|
1160
|
+
console.error("[model-allowance] reading provider status failed", { provider, error });
|
|
1161
|
+
return { provider, state: "unknown", error: describe(error) };
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
function statusDisplayState(status) {
|
|
1165
|
+
if (status === null) return "loading";
|
|
1166
|
+
if (status.state === "unknown" && !status.url && !status.error) return "unsupported";
|
|
1167
|
+
return status.state;
|
|
1168
|
+
}
|
|
1088
1169
|
function BalanceBadge(props) {
|
|
1089
1170
|
const { useProjection, ctx, t } = props;
|
|
1090
1171
|
const selection = useProjection("modelSelection");
|
|
1091
1172
|
const selected = selection?.next?.provider ?? selection?.lastUsed?.provider ?? null;
|
|
1092
1173
|
const selectedModel = selection?.next?.model ?? selection?.lastUsed?.model ?? void 0;
|
|
1174
|
+
const selectedEffort = selection?.next?.reasoningEffort ?? selection?.lastUsed?.reasoningEffort ?? void 0;
|
|
1093
1175
|
const sessionId = props.sessionId;
|
|
1094
1176
|
const [rawView, setView] = React.useState(null);
|
|
1095
1177
|
const [loading, setLoading] = React.useState(false);
|
|
@@ -1114,9 +1196,13 @@ function BalanceBadge(props) {
|
|
|
1114
1196
|
const [providerStatus, setProviderStatus] = React.useState(null);
|
|
1115
1197
|
const [schedule, setSchedule] = React.useState(null);
|
|
1116
1198
|
const [modelList, setModelList] = React.useState([]);
|
|
1199
|
+
const [modelListRoute, setModelListRoute] = React.useState(null);
|
|
1200
|
+
const [catalogProvider, setCatalogProvider] = React.useState(null);
|
|
1117
1201
|
const [modelListState, setModelListState] = React.useState("idle");
|
|
1118
1202
|
const [modelError, setModelError] = React.useState(null);
|
|
1119
1203
|
const [modelMenuOpen, setModelMenuOpen] = React.useState(false);
|
|
1204
|
+
const [hoverModel, setHoverModel] = React.useState(null);
|
|
1205
|
+
const hoverModelTimer = React.useRef(null);
|
|
1120
1206
|
const [switchingModel, setSwitchingModel] = React.useState(null);
|
|
1121
1207
|
const modelWrapRef = React.useRef(null);
|
|
1122
1208
|
const catalogRef = React.useRef({ value: null, at: 0 });
|
|
@@ -1169,7 +1255,10 @@ function BalanceBadge(props) {
|
|
|
1169
1255
|
const switchLabel = t(inUse ? "detail.switchModelHere" : "detail.switchModelThere", {
|
|
1170
1256
|
name: nameOf(activeProvider)
|
|
1171
1257
|
});
|
|
1172
|
-
const
|
|
1258
|
+
const modelProvider = catalogProvider ?? activeProvider;
|
|
1259
|
+
const currentModel = currentModelFor(selection, modelProvider);
|
|
1260
|
+
const shownModelList = modelListRoute === activeProvider ? modelList : [];
|
|
1261
|
+
const shownModelListState = modelListRoute === activeProvider ? modelListState : "loading";
|
|
1173
1262
|
const sessionFace = lookupSessionFace(ctx);
|
|
1174
1263
|
const canSwitch = typeof sessionId === "string" && sessionId !== "" && sessionFace !== void 0 && typeof sessionFace.selectModel === "function";
|
|
1175
1264
|
const view = rawView?.provider === activeProvider ? rawView : null;
|
|
@@ -1339,15 +1428,8 @@ function BalanceBadge(props) {
|
|
|
1339
1428
|
if (!activeProvider) return void 0;
|
|
1340
1429
|
let cancelled = false;
|
|
1341
1430
|
const readStatus = async () => {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
if (!api || typeof api.status !== "function") return;
|
|
1345
|
-
const result = await api.status(activeProvider);
|
|
1346
|
-
if (cancelled || !result.ok) return;
|
|
1347
|
-
setProviderStatus(result.value);
|
|
1348
|
-
} catch (error) {
|
|
1349
|
-
console.error("[model-allowance] reading provider status failed", { error });
|
|
1350
|
-
}
|
|
1431
|
+
const status = await readProviderStatus(activeProvider);
|
|
1432
|
+
if (!cancelled) setProviderStatus(status);
|
|
1351
1433
|
};
|
|
1352
1434
|
void readStatus();
|
|
1353
1435
|
const timer = setInterval(readStatus, STATUS_REFRESH_MS);
|
|
@@ -1385,10 +1467,8 @@ function BalanceBadge(props) {
|
|
|
1385
1467
|
result = await api.refresh(activeProvider, void 0);
|
|
1386
1468
|
}
|
|
1387
1469
|
if (result.ok) setView(result.value);
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
if (status.ok) setProviderStatus(status.value);
|
|
1391
|
-
}
|
|
1470
|
+
const status = await readProviderStatus(activeProvider);
|
|
1471
|
+
setProviderStatus(status);
|
|
1392
1472
|
} catch (error) {
|
|
1393
1473
|
console.error("[model-allowance] refresh failed", {
|
|
1394
1474
|
provider: activeProvider,
|
|
@@ -1401,11 +1481,15 @@ function BalanceBadge(props) {
|
|
|
1401
1481
|
}, [activeProvider, activeModel]);
|
|
1402
1482
|
const showModels = React.useCallback(
|
|
1403
1483
|
(catalog) => {
|
|
1404
|
-
const
|
|
1484
|
+
const routes = [activeProvider, ...entryOf(activeProvider)?.modelRoutes ?? []];
|
|
1485
|
+
const group = providerModelGroup(catalog, routes);
|
|
1486
|
+
const models = group?.models ?? [];
|
|
1487
|
+
setCatalogProvider(group?.provider ?? null);
|
|
1488
|
+
setModelListRoute(activeProvider);
|
|
1405
1489
|
setModelList(models);
|
|
1406
1490
|
setModelListState(models.length > 0 ? "ready" : "empty");
|
|
1407
1491
|
},
|
|
1408
|
-
[activeProvider]
|
|
1492
|
+
[activeProvider, entryOf]
|
|
1409
1493
|
);
|
|
1410
1494
|
React.useEffect(() => {
|
|
1411
1495
|
if (!modelMenuOpen) return void 0;
|
|
@@ -1458,7 +1542,7 @@ function BalanceBadge(props) {
|
|
|
1458
1542
|
};
|
|
1459
1543
|
}, [modelMenuOpen]);
|
|
1460
1544
|
const switchToModel = React.useCallback(
|
|
1461
|
-
async (model) => {
|
|
1545
|
+
async (model, effort) => {
|
|
1462
1546
|
const face = lookupSessionFace(ctx);
|
|
1463
1547
|
if (face === void 0 || typeof face.selectModel !== "function") {
|
|
1464
1548
|
setModelError(t("model.unavailable"));
|
|
@@ -1470,10 +1554,9 @@ function BalanceBadge(props) {
|
|
|
1470
1554
|
}
|
|
1471
1555
|
setSwitchingModel(model.id);
|
|
1472
1556
|
try {
|
|
1473
|
-
const effort = model.reasoning?.defaultEffort;
|
|
1474
1557
|
const result = await face.selectModel({
|
|
1475
1558
|
sessionId,
|
|
1476
|
-
provider: activeProvider,
|
|
1559
|
+
provider: catalogProvider ?? activeProvider,
|
|
1477
1560
|
model: model.id,
|
|
1478
1561
|
...typeof effort === "string" && effort !== "" ? { reasoningEffort: effort } : {}
|
|
1479
1562
|
});
|
|
@@ -1492,8 +1575,18 @@ function BalanceBadge(props) {
|
|
|
1492
1575
|
setSwitchingModel(null);
|
|
1493
1576
|
}
|
|
1494
1577
|
},
|
|
1495
|
-
[ctx, sessionId, activeProvider, t]
|
|
1578
|
+
[ctx, sessionId, activeProvider, catalogProvider, t]
|
|
1496
1579
|
);
|
|
1580
|
+
const showEffortFlyout = React.useCallback((model, top) => {
|
|
1581
|
+
clearTimeout(hoverModelTimer.current);
|
|
1582
|
+
setHoverModel({ model, top });
|
|
1583
|
+
}, []);
|
|
1584
|
+
const scheduleEffortFlyoutClose = React.useCallback((id) => {
|
|
1585
|
+
clearTimeout(hoverModelTimer.current);
|
|
1586
|
+
hoverModelTimer.current = setTimeout(() => {
|
|
1587
|
+
setHoverModel((current) => current?.model?.id === id ? null : current);
|
|
1588
|
+
}, 150);
|
|
1589
|
+
}, []);
|
|
1497
1590
|
const label = React.useMemo(() => {
|
|
1498
1591
|
if (!provider) return "";
|
|
1499
1592
|
if (!view) return t("badge.loading");
|
|
@@ -1530,7 +1623,8 @@ function BalanceBadge(props) {
|
|
|
1530
1623
|
return t("badge.failed");
|
|
1531
1624
|
}, [view, provider, activeProvider, nameOf, t]);
|
|
1532
1625
|
if (!provider) return null;
|
|
1533
|
-
const
|
|
1626
|
+
const currentStatus = providerStatus?.provider === activeProvider ? providerStatus : null;
|
|
1627
|
+
const serviceState = statusDisplayState(currentStatus);
|
|
1534
1628
|
const MARK_SIZE = 26;
|
|
1535
1629
|
const MARK_GAP = 4;
|
|
1536
1630
|
const MENU_SIZE = 26;
|
|
@@ -1804,16 +1898,16 @@ function BalanceBadge(props) {
|
|
|
1804
1898
|
// The platform status sits at the left edge of the footer, on
|
|
1805
1899
|
// the same line as the reading time: the card gains no extra
|
|
1806
1900
|
// row, and the state and the source page stay together.
|
|
1807
|
-
|
|
1901
|
+
(0, import_react3.createElement)(
|
|
1808
1902
|
"span",
|
|
1809
1903
|
{ className: "dsh-model-allowance-status-wrap" },
|
|
1810
1904
|
(0, import_react3.createElement)(
|
|
1811
|
-
|
|
1905
|
+
currentStatus?.url ? "a" : "span",
|
|
1812
1906
|
{
|
|
1813
1907
|
className: "dsh-model-allowance-status",
|
|
1814
|
-
"data-state":
|
|
1815
|
-
...
|
|
1816
|
-
href:
|
|
1908
|
+
"data-state": serviceState,
|
|
1909
|
+
...currentStatus?.url ? {
|
|
1910
|
+
href: currentStatus.url,
|
|
1817
1911
|
target: "_blank",
|
|
1818
1912
|
rel: "noreferrer noopener"
|
|
1819
1913
|
} : {}
|
|
@@ -1825,9 +1919,9 @@ function BalanceBadge(props) {
|
|
|
1825
1919
|
(0, import_react3.createElement)(
|
|
1826
1920
|
"span",
|
|
1827
1921
|
{ className: "dsh-model-allowance-status-label" },
|
|
1828
|
-
statusLabel(
|
|
1922
|
+
statusLabel(serviceState, t)
|
|
1829
1923
|
),
|
|
1830
|
-
...
|
|
1924
|
+
...currentStatus?.url ? [
|
|
1831
1925
|
(0, import_react3.createElement)(
|
|
1832
1926
|
"span",
|
|
1833
1927
|
{
|
|
@@ -1841,13 +1935,13 @@ function BalanceBadge(props) {
|
|
|
1841
1935
|
// The reason is a warning mark rather than another line:
|
|
1842
1936
|
// the footer stays one row, and the detail is one hover
|
|
1843
1937
|
// — or one keyboard focus — away.
|
|
1844
|
-
|
|
1938
|
+
currentStatus?.summary ? (0, import_react3.createElement)(
|
|
1845
1939
|
"span",
|
|
1846
1940
|
{
|
|
1847
1941
|
className: "dsh-model-allowance-status-help",
|
|
1848
1942
|
tabIndex: 0,
|
|
1849
1943
|
role: "note",
|
|
1850
|
-
"aria-label":
|
|
1944
|
+
"aria-label": currentStatus.summary
|
|
1851
1945
|
},
|
|
1852
1946
|
(0, import_react3.createElement)(
|
|
1853
1947
|
"span",
|
|
@@ -1859,10 +1953,10 @@ function BalanceBadge(props) {
|
|
|
1859
1953
|
(0, import_react3.createElement)(
|
|
1860
1954
|
"span",
|
|
1861
1955
|
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
1862
|
-
|
|
1956
|
+
currentStatus.summary
|
|
1863
1957
|
)
|
|
1864
1958
|
) : null
|
|
1865
|
-
)
|
|
1959
|
+
),
|
|
1866
1960
|
view?.updatedAt ? (0, import_react3.createElement)(
|
|
1867
1961
|
"span",
|
|
1868
1962
|
{ className: "dsh-model-allowance-updated" },
|
|
@@ -1914,6 +2008,8 @@ function BalanceBadge(props) {
|
|
|
1914
2008
|
"aria-label": switchLabel,
|
|
1915
2009
|
onClick: () => {
|
|
1916
2010
|
setModelError(null);
|
|
2011
|
+
clearTimeout(hoverModelTimer.current);
|
|
2012
|
+
setHoverModel(null);
|
|
1917
2013
|
setModelMenuOpen((value) => !value);
|
|
1918
2014
|
}
|
|
1919
2015
|
},
|
|
@@ -1926,17 +2022,17 @@ function BalanceBadge(props) {
|
|
|
1926
2022
|
role: "menu",
|
|
1927
2023
|
"aria-label": t("model.title")
|
|
1928
2024
|
},
|
|
1929
|
-
|
|
2025
|
+
shownModelListState === "loading" ? (0, import_react3.createElement)(
|
|
1930
2026
|
"div",
|
|
1931
2027
|
{ className: "dsh-model-allowance-model-message" },
|
|
1932
2028
|
t("model.loading")
|
|
1933
2029
|
) : null,
|
|
1934
|
-
|
|
2030
|
+
shownModelListState === "empty" ? (0, import_react3.createElement)(
|
|
1935
2031
|
"div",
|
|
1936
2032
|
{ className: "dsh-model-allowance-model-message" },
|
|
1937
2033
|
t("model.empty")
|
|
1938
2034
|
) : null,
|
|
1939
|
-
|
|
2035
|
+
shownModelListState === "error" ? (0, import_react3.createElement)(
|
|
1940
2036
|
"div",
|
|
1941
2037
|
{
|
|
1942
2038
|
className: "dsh-model-allowance-model-message",
|
|
@@ -1944,8 +2040,10 @@ function BalanceBadge(props) {
|
|
|
1944
2040
|
},
|
|
1945
2041
|
modelError ?? t("model.unavailable")
|
|
1946
2042
|
) : null,
|
|
1947
|
-
...
|
|
2043
|
+
...shownModelList.map((model) => {
|
|
1948
2044
|
const isCurrent = model.id === currentModel;
|
|
2045
|
+
const efforts = effortChoices(model);
|
|
2046
|
+
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
1949
2047
|
return (0, import_react3.createElement)(
|
|
1950
2048
|
"button",
|
|
1951
2049
|
{
|
|
@@ -1957,8 +2055,20 @@ function BalanceBadge(props) {
|
|
|
1957
2055
|
className: "dsh-model-allowance-model-item",
|
|
1958
2056
|
disabled: switchingModel !== null,
|
|
1959
2057
|
title: model.id,
|
|
2058
|
+
...efforts === null ? {} : { "aria-haspopup": "menu" },
|
|
1960
2059
|
onClick: () => {
|
|
1961
|
-
void switchToModel(model);
|
|
2060
|
+
void switchToModel(model, defaultEffortId);
|
|
2061
|
+
},
|
|
2062
|
+
...efforts === null ? {} : {
|
|
2063
|
+
onMouseEnter: (event) => {
|
|
2064
|
+
const wrap = modelWrapRef.current;
|
|
2065
|
+
if (!wrap) return;
|
|
2066
|
+
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
2067
|
+
showEffortFlyout(model, top);
|
|
2068
|
+
},
|
|
2069
|
+
onMouseLeave: () => {
|
|
2070
|
+
scheduleEffortFlyoutClose(model.id);
|
|
2071
|
+
}
|
|
1962
2072
|
}
|
|
1963
2073
|
},
|
|
1964
2074
|
(0, import_react3.createElement)(
|
|
@@ -1966,19 +2076,31 @@ function BalanceBadge(props) {
|
|
|
1966
2076
|
{ className: "dsh-model-allowance-model-name" },
|
|
1967
2077
|
model.name ?? model.id
|
|
1968
2078
|
),
|
|
1969
|
-
|
|
1970
|
-
"span",
|
|
1971
|
-
{ className: "dsh-model-allowance-model-note" },
|
|
1972
|
-
t("model.switching")
|
|
1973
|
-
) : isCurrent ? (0, import_react3.createElement)(
|
|
2079
|
+
(0, import_react3.createElement)(
|
|
1974
2080
|
"span",
|
|
1975
|
-
{ className: "dsh-model-allowance-model-
|
|
1976
|
-
|
|
1977
|
-
|
|
2081
|
+
{ className: "dsh-model-allowance-model-side" },
|
|
2082
|
+
switchingModel === model.id ? (0, import_react3.createElement)(
|
|
2083
|
+
"span",
|
|
2084
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2085
|
+
t("model.switching")
|
|
2086
|
+
) : isCurrent ? (0, import_react3.createElement)(
|
|
2087
|
+
"span",
|
|
2088
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2089
|
+
t("model.current")
|
|
2090
|
+
) : null,
|
|
2091
|
+
efforts === null ? null : (0, import_react3.createElement)(
|
|
2092
|
+
"span",
|
|
2093
|
+
{
|
|
2094
|
+
className: "dsh-model-allowance-model-arrow",
|
|
2095
|
+
"aria-hidden": true
|
|
2096
|
+
},
|
|
2097
|
+
"\u203A"
|
|
2098
|
+
)
|
|
2099
|
+
)
|
|
1978
2100
|
);
|
|
1979
2101
|
}),
|
|
1980
2102
|
// A failed switch keeps the list open and says why.
|
|
1981
|
-
modelError &&
|
|
2103
|
+
modelError && shownModelListState !== "error" ? (0, import_react3.createElement)(
|
|
1982
2104
|
"div",
|
|
1983
2105
|
{
|
|
1984
2106
|
className: "dsh-model-allowance-model-message",
|
|
@@ -1986,6 +2108,54 @@ function BalanceBadge(props) {
|
|
|
1986
2108
|
},
|
|
1987
2109
|
modelError
|
|
1988
2110
|
) : null
|
|
2111
|
+
) : null,
|
|
2112
|
+
// The effort flyout is a sibling of the list, not a
|
|
2113
|
+
// child: the list scrolls, and a nested panel would be
|
|
2114
|
+
// clipped by it. Sharing the hover with the row keeps
|
|
2115
|
+
// it open while the pointer crosses over.
|
|
2116
|
+
modelMenuOpen && hoverModel !== null && shownModelList.includes(hoverModel.model) ? (0, import_react3.createElement)(
|
|
2117
|
+
"div",
|
|
2118
|
+
{
|
|
2119
|
+
className: "dsh-model-allowance-effort-menu",
|
|
2120
|
+
role: "menu",
|
|
2121
|
+
"aria-label": t("model.title"),
|
|
2122
|
+
style: { top: `${hoverModel.top}px` },
|
|
2123
|
+
onMouseEnter: () => {
|
|
2124
|
+
clearTimeout(hoverModelTimer.current);
|
|
2125
|
+
},
|
|
2126
|
+
onMouseLeave: () => {
|
|
2127
|
+
scheduleEffortFlyoutClose(hoverModel.model.id);
|
|
2128
|
+
}
|
|
2129
|
+
},
|
|
2130
|
+
...effortChoices(hoverModel.model).map((effort) => {
|
|
2131
|
+
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
2132
|
+
return (0, import_react3.createElement)(
|
|
2133
|
+
"button",
|
|
2134
|
+
{
|
|
2135
|
+
type: "button",
|
|
2136
|
+
key: effort.id ?? "provider-default",
|
|
2137
|
+
role: "menuitemradio",
|
|
2138
|
+
"aria-checked": isCurrentEffort ? "true" : "false",
|
|
2139
|
+
"data-current": isCurrentEffort ? "true" : "false",
|
|
2140
|
+
"data-default": effort.isDefault ? "true" : "false",
|
|
2141
|
+
className: "dsh-model-allowance-effort-item",
|
|
2142
|
+
disabled: switchingModel !== null,
|
|
2143
|
+
onClick: () => {
|
|
2144
|
+
void switchToModel(hoverModel.model, effort.id);
|
|
2145
|
+
}
|
|
2146
|
+
},
|
|
2147
|
+
(0, import_react3.createElement)(
|
|
2148
|
+
"span",
|
|
2149
|
+
{ className: "dsh-model-allowance-model-name" },
|
|
2150
|
+
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
2151
|
+
),
|
|
2152
|
+
effort.isDefault && !isCurrentEffort ? (0, import_react3.createElement)(
|
|
2153
|
+
"span",
|
|
2154
|
+
{ className: "dsh-model-allowance-model-note" },
|
|
2155
|
+
t("model.effortDefault")
|
|
2156
|
+
) : null
|
|
2157
|
+
);
|
|
2158
|
+
})
|
|
1989
2159
|
) : null
|
|
1990
2160
|
) : null
|
|
1991
2161
|
)
|
package/lib/balance.js
CHANGED
|
@@ -302,7 +302,7 @@ export class BalanceService {
|
|
|
302
302
|
* The routes.
|
|
303
303
|
*/
|
|
304
304
|
async available() {
|
|
305
|
-
/** @type {Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string}>} */
|
|
305
|
+
/** @type {Array<{route: string, configured: boolean, name: {zh: string, en: string}, color: string, iconHint?: string, modelRoutes?: readonly string[]}>} */
|
|
306
306
|
const routes = []
|
|
307
307
|
for (const adapter of PROVIDER_ADAPTERS) {
|
|
308
308
|
for (const route of adapter.routes) {
|
|
@@ -315,7 +315,12 @@ export class BalanceService {
|
|
|
315
315
|
} else {
|
|
316
316
|
configured = (await this.routeCredentials.resolve(route, adapter)) !== undefined
|
|
317
317
|
}
|
|
318
|
-
routes.push({
|
|
318
|
+
routes.push({
|
|
319
|
+
route,
|
|
320
|
+
configured,
|
|
321
|
+
...displayOf(adapter),
|
|
322
|
+
...(adapter.modelRoutes === undefined ? {} : { modelRoutes: adapter.modelRoutes }),
|
|
323
|
+
})
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
return routes
|
|
@@ -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'],
|
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,9 @@ 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.
|
|
95
98
|
* @property {'amount'|'quota'} kind Quantity dimension of the reading.
|
|
96
99
|
* @property {boolean} [modelScoped] Whether the reading is per provider-owned model.
|
|
97
100
|
* @property {string} consoleUrl Provider console for a manual check.
|
package/lib/status.js
CHANGED
|
@@ -90,8 +90,9 @@ export class StatusService {
|
|
|
90
90
|
* Read one provider's platform status.
|
|
91
91
|
*
|
|
92
92
|
* A route whose vendor publishes no status page answers `unknown` without
|
|
93
|
-
* touching the network: the browser
|
|
94
|
-
* gains a source starts working
|
|
93
|
+
* touching the network: the browser presents that source-free reading as
|
|
94
|
+
* "no status service", and a route that later gains a source starts working
|
|
95
|
+
* without any other change.
|
|
95
96
|
*
|
|
96
97
|
* @param {string} provider Provider route.
|
|
97
98
|
* @returns {Promise<StatusView>} The reading.
|