dsh-model-allowance 1.1.0 → 1.2.0
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 +23 -5
- package/README.zh.md +17 -5
- package/client.js +694 -97
- package/index.js +69 -0
- package/lib/balance.js +11 -2
- package/lib/providers/placeholder.js +0 -42
- package/lib/providers/promotions.js +169 -0
- package/lib/providers/qwen_promotions.js +223 -0
- package/lib/providers/qwen_token_plan.js +716 -0
- package/lib/providers/shared.js +24 -0
- package/lib/providers/zai.js +25 -0
- package/lib/providers.js +9 -6
- package/lib/remote.js +32 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -42,14 +42,14 @@ __export(index_exports, {
|
|
|
42
42
|
inject: () => inject
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
|
-
var
|
|
45
|
+
var import_react10 = require("react");
|
|
46
46
|
|
|
47
47
|
// src/client/badge.js
|
|
48
48
|
var React6 = __toESM(require("react"), 1);
|
|
49
|
-
var
|
|
49
|
+
var import_react8 = require("react");
|
|
50
50
|
|
|
51
51
|
// src/client/components/balance-panel.js
|
|
52
|
-
var
|
|
52
|
+
var import_react7 = require("react");
|
|
53
53
|
|
|
54
54
|
// src/client/format.js
|
|
55
55
|
var CURRENCY_SYMBOLS = {
|
|
@@ -484,7 +484,28 @@ var zh = {
|
|
|
484
484
|
"duration.daysHours": "{days} \u5929 {hours} \u5C0F\u65F6",
|
|
485
485
|
"duration.hoursMinutes": "{hours} \u5C0F\u65F6 {minutes} \u5206",
|
|
486
486
|
"duration.minutes": "{minutes} \u5206\u949F",
|
|
487
|
-
"duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F"
|
|
487
|
+
"duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F",
|
|
488
|
+
"settings.nav": "Model Allowance",
|
|
489
|
+
"settings.title": "Model Allowance",
|
|
490
|
+
"settings.loading": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u2026",
|
|
491
|
+
"settings.unavailable": "\u672C\u673A\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u51ED\u636E\u3002",
|
|
492
|
+
"settings.edit": "\u4FEE\u6539",
|
|
493
|
+
"settings.delete": "\u5220\u9664",
|
|
494
|
+
"settings.cancel": "\u53D6\u6D88",
|
|
495
|
+
"settings.save": "\u4FDD\u5B58",
|
|
496
|
+
"settings.testing": "\u9A8C\u8BC1\u4E2D\u2026",
|
|
497
|
+
"settings.fillAll": "\u8BF7\u586B\u5199\u5B8C\u6574\u7684\u51ED\u636E\u540E\u518D\u4FDD\u5B58",
|
|
498
|
+
"settings.testFailed": "\u51ED\u636E\u9A8C\u8BC1\u672A\u901A\u8FC7\uFF0C\u672A\u4FDD\u5B58",
|
|
499
|
+
"settings.testRejected": "\u5382\u5546\u62D2\u7EDD\u4E86\u8FD9\u5BF9\u51ED\u636E",
|
|
500
|
+
"settings.doc": "\u5982\u4F55\u83B7\u53D6\u51ED\u636E\uFF1F",
|
|
501
|
+
"settings.saved": "\u5DF2\u4FDD\u5B58",
|
|
502
|
+
"settings.configured": "\u5DF2\u914D\u7F6E",
|
|
503
|
+
"settings.deleted": "\u5DF2\u5220\u9664",
|
|
504
|
+
"settings.saveFailed": "\u4FDD\u5B58\u5931\u8D25",
|
|
505
|
+
"settings.deleteFailed": "\u5220\u9664\u5931\u8D25",
|
|
506
|
+
"settings.loadFailed": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25",
|
|
507
|
+
"badge.setupHint": "\u5C1A\u672A\u914D\u7F6E\u8BE5\u5382\u5546\u7684\u67E5\u8BE2\u51ED\u636E\u3002\u6253\u5F00 \u8BBE\u7F6E \u2192 Model Allowance \u5F55\u5165\u3002",
|
|
508
|
+
"badge.setupDoc": "\u67E5\u770B\u914D\u7F6E\u6307\u5357"
|
|
488
509
|
};
|
|
489
510
|
var en = {
|
|
490
511
|
"badge.loading": "Loading\u2026",
|
|
@@ -548,7 +569,28 @@ var en = {
|
|
|
548
569
|
"duration.daysHours": "{days}d {hours}h",
|
|
549
570
|
"duration.hoursMinutes": "{hours}h {minutes}m",
|
|
550
571
|
"duration.minutes": "{minutes}m",
|
|
551
|
-
"duration.lessThanMinute": "under a minute"
|
|
572
|
+
"duration.lessThanMinute": "under a minute",
|
|
573
|
+
"settings.nav": "Model Allowance",
|
|
574
|
+
"settings.title": "Model Allowance",
|
|
575
|
+
"settings.loading": "Reading credential status\u2026",
|
|
576
|
+
"settings.unavailable": "This host provides no credential store, so credentials cannot be saved.",
|
|
577
|
+
"settings.edit": "Edit",
|
|
578
|
+
"settings.delete": "Delete",
|
|
579
|
+
"settings.cancel": "Cancel",
|
|
580
|
+
"settings.save": "Save",
|
|
581
|
+
"settings.testing": "Verifying\u2026",
|
|
582
|
+
"settings.fillAll": "Fill in every field before saving",
|
|
583
|
+
"settings.testFailed": "The credentials were rejected and were not saved",
|
|
584
|
+
"settings.testRejected": "the vendor refused this credential pair",
|
|
585
|
+
"settings.doc": "How do I get the credentials?",
|
|
586
|
+
"settings.saved": "Saved",
|
|
587
|
+
"settings.configured": "Configured",
|
|
588
|
+
"settings.deleted": "Deleted",
|
|
589
|
+
"settings.saveFailed": "Save failed",
|
|
590
|
+
"settings.deleteFailed": "Delete failed",
|
|
591
|
+
"settings.loadFailed": "Could not read credential status",
|
|
592
|
+
"badge.setupHint": "No credentials are stored for this provider yet. Open Settings \u2192 Model Allowance to add them.",
|
|
593
|
+
"badge.setupDoc": "Open the setup guide"
|
|
552
594
|
};
|
|
553
595
|
function activeLanguage() {
|
|
554
596
|
const tag = typeof document !== "undefined" ? document.documentElement?.lang : void 0;
|
|
@@ -574,6 +616,9 @@ function statusLabel(state, t) {
|
|
|
574
616
|
return key === void 0 ? t("status.unknown") : t(key);
|
|
575
617
|
}
|
|
576
618
|
|
|
619
|
+
// src/client/promotions.js
|
|
620
|
+
var import_react3 = require("react");
|
|
621
|
+
|
|
577
622
|
// src/client/schedule.js
|
|
578
623
|
var import_react2 = require("react");
|
|
579
624
|
function formatCountdown(ms) {
|
|
@@ -768,6 +813,57 @@ function scheduleView(schedule, now, t) {
|
|
|
768
813
|
);
|
|
769
814
|
}
|
|
770
815
|
|
|
816
|
+
// src/client/promotions.js
|
|
817
|
+
var pad22 = (value) => String(value).padStart(2, "0");
|
|
818
|
+
function wallMinutes2(time) {
|
|
819
|
+
const [hour, minute] = time.split(":").map(Number);
|
|
820
|
+
return hour * 60 + minute;
|
|
821
|
+
}
|
|
822
|
+
function promotionActive(promotion, now) {
|
|
823
|
+
if (promotion.timezone === void 0) return true;
|
|
824
|
+
const parts = zoneParts(now, promotion.timezone);
|
|
825
|
+
if (promotion.from !== void 0 && promotion.to !== void 0) {
|
|
826
|
+
const date = `${String(parts.year)}-${pad22(parts.month)}-${pad22(parts.day)}`;
|
|
827
|
+
if (date < promotion.from || date > promotion.to) return false;
|
|
828
|
+
}
|
|
829
|
+
if (promotion.daily !== void 0) {
|
|
830
|
+
const minutes = parts.hour * 60 + parts.minute;
|
|
831
|
+
const from = wallMinutes2(promotion.daily.from);
|
|
832
|
+
const to = wallMinutes2(promotion.daily.to);
|
|
833
|
+
const inside = from <= to ? minutes >= from && minutes < to : minutes >= from || minutes < to;
|
|
834
|
+
if (!inside) return false;
|
|
835
|
+
}
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
function promotionChip(promotion) {
|
|
839
|
+
const language = activeLanguage();
|
|
840
|
+
return promotion.chip?.[language] ?? promotion.chip?.en ?? promotion.chip?.zh;
|
|
841
|
+
}
|
|
842
|
+
function promotionForModel(promotions, modelId) {
|
|
843
|
+
if (!Array.isArray(promotions) || typeof modelId !== "string" || modelId === "") return void 0;
|
|
844
|
+
const wanted = modelId.toLowerCase();
|
|
845
|
+
return promotions.find(
|
|
846
|
+
(promotion) => promotion.models.some((model) => model.toLowerCase() === wanted)
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
function promotionNote(promotion) {
|
|
850
|
+
const language = activeLanguage();
|
|
851
|
+
return promotion.note?.[language] ?? promotion.note?.en ?? promotion.note?.zh;
|
|
852
|
+
}
|
|
853
|
+
function promoTipView(promotion, position) {
|
|
854
|
+
const note = promotionNote(promotion);
|
|
855
|
+
if (note === void 0) return null;
|
|
856
|
+
return (0, import_react3.createElement)(
|
|
857
|
+
"div",
|
|
858
|
+
{
|
|
859
|
+
className: "dsh-model-allowance-promo-tip",
|
|
860
|
+
role: "tooltip",
|
|
861
|
+
style: { bottom: `${String(position.bottom)}px`, right: `${String(position.right)}px` }
|
|
862
|
+
},
|
|
863
|
+
note
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
771
867
|
// src/client/windows.js
|
|
772
868
|
function windowTitle(window, t) {
|
|
773
869
|
const label = window.label?.[activeLanguage()] ?? window.label?.en ?? window.label?.zh;
|
|
@@ -826,7 +922,7 @@ function barTone(percent) {
|
|
|
826
922
|
}
|
|
827
923
|
|
|
828
924
|
// src/client/components/effort-flyout.js
|
|
829
|
-
var
|
|
925
|
+
var import_react4 = require("react");
|
|
830
926
|
|
|
831
927
|
// src/client/models.js
|
|
832
928
|
function providerGroup(catalog, provider) {
|
|
@@ -879,7 +975,7 @@ function EffortFlyout({
|
|
|
879
975
|
keepEffortFlyout,
|
|
880
976
|
scheduleEffortFlyoutClose
|
|
881
977
|
}) {
|
|
882
|
-
return (0,
|
|
978
|
+
return (0, import_react4.createElement)(
|
|
883
979
|
"div",
|
|
884
980
|
{
|
|
885
981
|
className: "dsh-model-allowance-effort-menu",
|
|
@@ -893,7 +989,7 @@ function EffortFlyout({
|
|
|
893
989
|
},
|
|
894
990
|
...effortChoices(hoverModel.model).map((effort) => {
|
|
895
991
|
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
896
|
-
return (0,
|
|
992
|
+
return (0, import_react4.createElement)(
|
|
897
993
|
"button",
|
|
898
994
|
{
|
|
899
995
|
type: "button",
|
|
@@ -908,19 +1004,19 @@ function EffortFlyout({
|
|
|
908
1004
|
void switchToModel(hoverModel.model, effort.id);
|
|
909
1005
|
}
|
|
910
1006
|
},
|
|
911
|
-
(0,
|
|
1007
|
+
(0, import_react4.createElement)(
|
|
912
1008
|
"span",
|
|
913
1009
|
{ className: "dsh-model-allowance-model-name" },
|
|
914
1010
|
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
915
1011
|
),
|
|
916
|
-
effort.isDefault && !isCurrentEffort ? (0,
|
|
1012
|
+
effort.isDefault && !isCurrentEffort ? (0, import_react4.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.effortDefault")) : null
|
|
917
1013
|
);
|
|
918
1014
|
})
|
|
919
1015
|
);
|
|
920
1016
|
}
|
|
921
1017
|
|
|
922
1018
|
// src/client/components/model-menu.js
|
|
923
|
-
var
|
|
1019
|
+
var import_react5 = require("react");
|
|
924
1020
|
function ModelMenu({
|
|
925
1021
|
t,
|
|
926
1022
|
models,
|
|
@@ -931,18 +1027,21 @@ function ModelMenu({
|
|
|
931
1027
|
switchToModel,
|
|
932
1028
|
modelWrapRef,
|
|
933
1029
|
showEffortFlyout,
|
|
934
|
-
scheduleEffortFlyoutClose
|
|
1030
|
+
scheduleEffortFlyoutClose,
|
|
1031
|
+
promotions,
|
|
1032
|
+
showPromoTip,
|
|
1033
|
+
hidePromoTip
|
|
935
1034
|
}) {
|
|
936
|
-
return (0,
|
|
1035
|
+
return (0, import_react5.createElement)(
|
|
937
1036
|
"div",
|
|
938
1037
|
{
|
|
939
1038
|
className: "dsh-model-allowance-model-menu",
|
|
940
1039
|
role: "menu",
|
|
941
1040
|
"aria-label": t("model.title")
|
|
942
1041
|
},
|
|
943
|
-
state === "loading" ? (0,
|
|
944
|
-
state === "empty" ? (0,
|
|
945
|
-
state === "error" ? (0,
|
|
1042
|
+
state === "loading" ? (0, import_react5.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.loading")) : null,
|
|
1043
|
+
state === "empty" ? (0, import_react5.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.empty")) : null,
|
|
1044
|
+
state === "error" ? (0, import_react5.createElement)(
|
|
946
1045
|
"div",
|
|
947
1046
|
{
|
|
948
1047
|
className: "dsh-model-allowance-model-message",
|
|
@@ -954,7 +1053,9 @@ function ModelMenu({
|
|
|
954
1053
|
const isCurrent = model.id === currentModel;
|
|
955
1054
|
const efforts = effortChoices(model);
|
|
956
1055
|
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
957
|
-
|
|
1056
|
+
const promotion = promotionForModel(promotions, model.id);
|
|
1057
|
+
const chip = promotion === void 0 ? void 0 : promotionChip(promotion);
|
|
1058
|
+
return (0, import_react5.createElement)(
|
|
958
1059
|
"button",
|
|
959
1060
|
{
|
|
960
1061
|
type: "button",
|
|
@@ -971,6 +1072,7 @@ function ModelMenu({
|
|
|
971
1072
|
},
|
|
972
1073
|
...efforts === null ? {} : {
|
|
973
1074
|
onMouseEnter: (event) => {
|
|
1075
|
+
if (event.target?.closest?.(".dsh-model-allowance-promo-chip")) return;
|
|
974
1076
|
const wrap = modelWrapRef.current;
|
|
975
1077
|
if (!wrap) return;
|
|
976
1078
|
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
@@ -981,12 +1083,30 @@ function ModelMenu({
|
|
|
981
1083
|
}
|
|
982
1084
|
}
|
|
983
1085
|
},
|
|
984
|
-
(0,
|
|
985
|
-
(0,
|
|
1086
|
+
(0, import_react5.createElement)("span", { className: "dsh-model-allowance-model-name" }, model.name ?? model.id),
|
|
1087
|
+
promotion === void 0 || chip === void 0 || chip === "" ? null : (0, import_react5.createElement)(
|
|
1088
|
+
"span",
|
|
1089
|
+
{
|
|
1090
|
+
className: "dsh-model-allowance-promo-chip",
|
|
1091
|
+
// A bare span is role=generic, which ARIA forbids naming;
|
|
1092
|
+
// img lets the announcement reach assistive tech.
|
|
1093
|
+
role: "img",
|
|
1094
|
+
"aria-label": promotionNote(promotion),
|
|
1095
|
+
onMouseEnter: (event) => {
|
|
1096
|
+
scheduleEffortFlyoutClose(model.id);
|
|
1097
|
+
showPromoTip?.(model, event);
|
|
1098
|
+
},
|
|
1099
|
+
onMouseLeave: () => {
|
|
1100
|
+
hidePromoTip?.();
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
chip
|
|
1104
|
+
),
|
|
1105
|
+
(0, import_react5.createElement)(
|
|
986
1106
|
"span",
|
|
987
1107
|
{ className: "dsh-model-allowance-model-side" },
|
|
988
|
-
switchingModel === model.id ? (0,
|
|
989
|
-
efforts === null ? null : (0,
|
|
1108
|
+
switchingModel === model.id ? (0, import_react5.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.switching")) : isCurrent ? (0, import_react5.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.current")) : null,
|
|
1109
|
+
efforts === null ? null : (0, import_react5.createElement)(
|
|
990
1110
|
"span",
|
|
991
1111
|
{
|
|
992
1112
|
className: "dsh-model-allowance-model-arrow",
|
|
@@ -998,7 +1118,7 @@ function ModelMenu({
|
|
|
998
1118
|
);
|
|
999
1119
|
}),
|
|
1000
1120
|
// A failed switch keeps the list open and says why.
|
|
1001
|
-
modelError && state !== "error" ? (0,
|
|
1121
|
+
modelError && state !== "error" ? (0, import_react5.createElement)(
|
|
1002
1122
|
"div",
|
|
1003
1123
|
{
|
|
1004
1124
|
className: "dsh-model-allowance-model-message",
|
|
@@ -1011,7 +1131,7 @@ function ModelMenu({
|
|
|
1011
1131
|
|
|
1012
1132
|
// src/client/components/provider-strip.js
|
|
1013
1133
|
var React2 = __toESM(require("react"), 1);
|
|
1014
|
-
var
|
|
1134
|
+
var import_react6 = require("react");
|
|
1015
1135
|
|
|
1016
1136
|
// src/client/hooks/use-provider-directory.js
|
|
1017
1137
|
var React = __toESM(require("react"), 1);
|
|
@@ -1169,7 +1289,7 @@ function ProviderStrip({
|
|
|
1169
1289
|
const mark = markFor(entry.route);
|
|
1170
1290
|
const name = nameOf(entry.route);
|
|
1171
1291
|
const active = entryCovers(entry, activeProvider);
|
|
1172
|
-
return (0,
|
|
1292
|
+
return (0, import_react6.createElement)(
|
|
1173
1293
|
"button",
|
|
1174
1294
|
{
|
|
1175
1295
|
type: "button",
|
|
@@ -1198,10 +1318,10 @@ function ProviderStrip({
|
|
|
1198
1318
|
event.preventDefault();
|
|
1199
1319
|
tabs[next]?.focus();
|
|
1200
1320
|
};
|
|
1201
|
-
return (0,
|
|
1321
|
+
return (0, import_react6.createElement)(
|
|
1202
1322
|
"div",
|
|
1203
1323
|
{ className: "dsh-model-allowance-switcher-wrap" },
|
|
1204
|
-
(0,
|
|
1324
|
+
(0, import_react6.createElement)(
|
|
1205
1325
|
"div",
|
|
1206
1326
|
{
|
|
1207
1327
|
ref: stripRef,
|
|
@@ -1211,7 +1331,7 @@ function ProviderStrip({
|
|
|
1211
1331
|
onKeyDown: onTabKeyDown
|
|
1212
1332
|
},
|
|
1213
1333
|
...shown.map(markButton),
|
|
1214
|
-
overflow.length > 0 ? (0,
|
|
1334
|
+
overflow.length > 0 ? (0, import_react6.createElement)(
|
|
1215
1335
|
"button",
|
|
1216
1336
|
{
|
|
1217
1337
|
type: "button",
|
|
@@ -1225,11 +1345,11 @@ function ProviderStrip({
|
|
|
1225
1345
|
"\u22EF"
|
|
1226
1346
|
) : null
|
|
1227
1347
|
),
|
|
1228
|
-
menuOpen && overflow.length > 0 ? (0,
|
|
1348
|
+
menuOpen && overflow.length > 0 ? (0, import_react6.createElement)(
|
|
1229
1349
|
"div",
|
|
1230
1350
|
{ className: "dsh-model-allowance-menu", role: "menu" },
|
|
1231
1351
|
...overflow.map(
|
|
1232
|
-
(entry) => (0,
|
|
1352
|
+
(entry) => (0, import_react6.createElement)(
|
|
1233
1353
|
"button",
|
|
1234
1354
|
{
|
|
1235
1355
|
type: "button",
|
|
@@ -1241,7 +1361,7 @@ function ProviderStrip({
|
|
|
1241
1361
|
setMenuOpen(false);
|
|
1242
1362
|
}
|
|
1243
1363
|
},
|
|
1244
|
-
(0,
|
|
1364
|
+
(0, import_react6.createElement)(
|
|
1245
1365
|
"span",
|
|
1246
1366
|
{
|
|
1247
1367
|
className: "dsh-model-allowance-menu-mark",
|
|
@@ -1249,7 +1369,7 @@ function ProviderStrip({
|
|
|
1249
1369
|
},
|
|
1250
1370
|
providerIcon(entry.route, 11, markFor(entry.route))
|
|
1251
1371
|
),
|
|
1252
|
-
(0,
|
|
1372
|
+
(0, import_react6.createElement)("span", null, nameOf(entry.route))
|
|
1253
1373
|
)
|
|
1254
1374
|
)
|
|
1255
1375
|
) : null
|
|
@@ -1264,6 +1384,7 @@ function BalancePanel({
|
|
|
1264
1384
|
activeProvider,
|
|
1265
1385
|
available,
|
|
1266
1386
|
schedule,
|
|
1387
|
+
promotions,
|
|
1267
1388
|
currentStatus,
|
|
1268
1389
|
serviceState,
|
|
1269
1390
|
refresh,
|
|
@@ -1282,7 +1403,9 @@ function BalancePanel({
|
|
|
1282
1403
|
setStripWidth,
|
|
1283
1404
|
stripRef
|
|
1284
1405
|
}) {
|
|
1285
|
-
|
|
1406
|
+
const activePromotions = promotions?.provider === activeProvider ? (promotions.promotions ?? []).filter((promotion) => promotionActive(promotion, now)) : [];
|
|
1407
|
+
const tipPromotion = catalog.promoTip == null ? void 0 : promotionForModel(activePromotions, catalog.promoTip.model.id);
|
|
1408
|
+
return (0, import_react7.createElement)(
|
|
1286
1409
|
"div",
|
|
1287
1410
|
{
|
|
1288
1411
|
className: "dsh-model-allowance-panel",
|
|
@@ -1292,7 +1415,7 @@ function BalancePanel({
|
|
|
1292
1415
|
},
|
|
1293
1416
|
// With more than one readable provider the card opens a switcher;
|
|
1294
1417
|
// with one there is nothing to switch, so it just names it.
|
|
1295
|
-
available.length > 1 ? (0,
|
|
1418
|
+
available.length > 1 ? (0, import_react7.createElement)(ProviderStrip, {
|
|
1296
1419
|
t,
|
|
1297
1420
|
available,
|
|
1298
1421
|
activeProvider,
|
|
@@ -1304,24 +1427,24 @@ function BalancePanel({
|
|
|
1304
1427
|
stripWidth,
|
|
1305
1428
|
setStripWidth,
|
|
1306
1429
|
stripRef
|
|
1307
|
-
}) : (0,
|
|
1430
|
+
}) : (0, import_react7.createElement)(
|
|
1308
1431
|
"div",
|
|
1309
1432
|
{ className: "dsh-model-allowance-row" },
|
|
1310
|
-
(0,
|
|
1311
|
-
(0,
|
|
1433
|
+
(0, import_react7.createElement)("span", null, t("detail.provider")),
|
|
1434
|
+
(0, import_react7.createElement)("span", null, nameOf(activeProvider))
|
|
1312
1435
|
),
|
|
1313
|
-
view?.kind === "amount" && typeof view.amount === "number" ? (0,
|
|
1436
|
+
view?.kind === "amount" && typeof view.amount === "number" ? (0, import_react7.createElement)(
|
|
1314
1437
|
"div",
|
|
1315
1438
|
{ className: "dsh-model-allowance-row" },
|
|
1316
|
-
(0,
|
|
1317
|
-
(0,
|
|
1439
|
+
(0, import_react7.createElement)("span", null, t("detail.amount")),
|
|
1440
|
+
(0, import_react7.createElement)("span", null, formatAmount(view.amount, view.currency))
|
|
1318
1441
|
) : null,
|
|
1319
1442
|
...Array.isArray(view?.windows) && view.windows.length > 0 ? view.windows.map((window, index) => {
|
|
1320
1443
|
const consumed = windowUsedPercent(window);
|
|
1321
1444
|
const percent = consumed === void 0 ? void 0 : Math.max(0, Math.round(consumed));
|
|
1322
1445
|
const filled = consumed === void 0 ? 0 : Math.min(100, Math.max(0, consumed));
|
|
1323
1446
|
const usage = windowUsage(window, t);
|
|
1324
|
-
return (0,
|
|
1447
|
+
return (0, import_react7.createElement)(
|
|
1325
1448
|
"div",
|
|
1326
1449
|
{
|
|
1327
1450
|
className: "dsh-model-allowance-window",
|
|
@@ -1332,20 +1455,20 @@ function BalancePanel({
|
|
|
1332
1455
|
// *between* windows are drawn.
|
|
1333
1456
|
"data-first": index === 0 ? "true" : void 0
|
|
1334
1457
|
},
|
|
1335
|
-
(0,
|
|
1458
|
+
(0, import_react7.createElement)(
|
|
1336
1459
|
"div",
|
|
1337
1460
|
{ className: "dsh-model-allowance-window-head" },
|
|
1338
|
-
(0,
|
|
1461
|
+
(0, import_react7.createElement)("span", { className: "dsh-model-allowance-window-title" }, windowTitle(window, t)),
|
|
1339
1462
|
// Countable units sit beside the title; a plan that
|
|
1340
1463
|
// reports only a percentage has none to show.
|
|
1341
|
-
usage === void 0 ? null : (0,
|
|
1464
|
+
usage === void 0 ? null : (0, import_react7.createElement)("span", { className: "dsh-model-allowance-usage" }, usage)
|
|
1342
1465
|
),
|
|
1343
|
-
percent === void 0 ? null : (0,
|
|
1466
|
+
percent === void 0 ? null : (0, import_react7.createElement)(
|
|
1344
1467
|
"div",
|
|
1345
1468
|
{ className: "dsh-model-allowance-percent" },
|
|
1346
1469
|
t("window.usedPercent", { percent })
|
|
1347
1470
|
),
|
|
1348
|
-
percent === void 0 ? null : (0,
|
|
1471
|
+
percent === void 0 ? null : (0, import_react7.createElement)(
|
|
1349
1472
|
"div",
|
|
1350
1473
|
{
|
|
1351
1474
|
className: "dsh-model-allowance-bar",
|
|
@@ -1355,7 +1478,7 @@ function BalancePanel({
|
|
|
1355
1478
|
"aria-valuemax": 100,
|
|
1356
1479
|
"aria-valuetext": t("window.usedPercent", { percent })
|
|
1357
1480
|
},
|
|
1358
|
-
(0,
|
|
1481
|
+
(0, import_react7.createElement)("div", {
|
|
1359
1482
|
className: "dsh-model-allowance-bar-fill",
|
|
1360
1483
|
"data-tone": barTone(percent),
|
|
1361
1484
|
style: { width: `${String(filled)}%` }
|
|
@@ -1364,66 +1487,82 @@ function BalancePanel({
|
|
|
1364
1487
|
// A window with zero usage has not started its rolling timer
|
|
1365
1488
|
// yet, so the countdown would be misleading. Hide it until
|
|
1366
1489
|
// consumption begins.
|
|
1367
|
-
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0,
|
|
1490
|
+
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0, import_react7.createElement)(
|
|
1368
1491
|
"div",
|
|
1369
1492
|
{ className: "dsh-model-allowance-foot" },
|
|
1370
|
-
(0,
|
|
1493
|
+
(0, import_react7.createElement)(
|
|
1371
1494
|
"span",
|
|
1372
1495
|
null,
|
|
1373
1496
|
t("window.resetIn", {
|
|
1374
1497
|
duration: formatCountdown(window.resetAt - now)
|
|
1375
1498
|
})
|
|
1376
1499
|
),
|
|
1377
|
-
(0,
|
|
1500
|
+
(0, import_react7.createElement)("span", null, formatResetAt(window.resetAt))
|
|
1378
1501
|
) : null
|
|
1379
1502
|
);
|
|
1380
1503
|
}) : [],
|
|
1381
1504
|
// A single scalar reading has no windows to break down.
|
|
1382
|
-
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0,
|
|
1505
|
+
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0, import_react7.createElement)(
|
|
1383
1506
|
"div",
|
|
1384
1507
|
{ className: "dsh-model-allowance-row" },
|
|
1385
|
-
(0,
|
|
1386
|
-
(0,
|
|
1508
|
+
(0, import_react7.createElement)("span", null, t("detail.remaining")),
|
|
1509
|
+
(0, import_react7.createElement)("span", null, formatDuration(view.remainingMs, t))
|
|
1387
1510
|
) : null,
|
|
1388
|
-
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0,
|
|
1511
|
+
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0, import_react7.createElement)(
|
|
1389
1512
|
"div",
|
|
1390
1513
|
{ className: "dsh-model-allowance-row" },
|
|
1391
|
-
(0,
|
|
1392
|
-
(0,
|
|
1514
|
+
(0, import_react7.createElement)("span", null, t("detail.remaining")),
|
|
1515
|
+
(0, import_react7.createElement)("span", null, String(view.remaining))
|
|
1393
1516
|
) : null,
|
|
1394
|
-
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0,
|
|
1517
|
+
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0, import_react7.createElement)(
|
|
1395
1518
|
"div",
|
|
1396
1519
|
{ className: "dsh-model-allowance-row" },
|
|
1397
|
-
(0,
|
|
1398
|
-
(0,
|
|
1520
|
+
(0, import_react7.createElement)("span", null, t("detail.total")),
|
|
1521
|
+
(0, import_react7.createElement)("span", null, String(view.total))
|
|
1399
1522
|
) : null,
|
|
1400
|
-
view?.status === "failed" ? (0,
|
|
1523
|
+
view?.status === "failed" ? (0, import_react7.createElement)(
|
|
1401
1524
|
"div",
|
|
1402
1525
|
{ className: "dsh-model-allowance-error" },
|
|
1403
1526
|
t("detail.error"),
|
|
1404
1527
|
// The Host reports why a reading failed; showing it is what
|
|
1405
1528
|
// turns "it does not work" into something actionable.
|
|
1406
|
-
view.error ? (0,
|
|
1529
|
+
view.error ? (0, import_react7.createElement)("div", { className: "dsh-model-allowance-reason" }, view.error) : null
|
|
1407
1530
|
) : null,
|
|
1408
|
-
view?.status === "unsupported" ? (0,
|
|
1531
|
+
view?.status === "unsupported" ? (0, import_react7.createElement)(
|
|
1409
1532
|
"div",
|
|
1410
1533
|
{ className: "dsh-model-allowance-reason" },
|
|
1411
1534
|
t("badge.unsupportedWithName", { name: nameOf(activeProvider) })
|
|
1412
1535
|
) : null,
|
|
1413
|
-
view?.status === "unconfigured" ? (0,
|
|
1536
|
+
view?.status === "unconfigured" ? (0, import_react7.createElement)(
|
|
1537
|
+
"div",
|
|
1538
|
+
{ className: "dsh-model-allowance-reason" },
|
|
1539
|
+
t("badge.setupHint"),
|
|
1540
|
+
// The reading carries the provider's setup guide; it is the walk
|
|
1541
|
+
// from "no credential" to a stored pair, so it is one click away.
|
|
1542
|
+
view.setupUrl ? (0, import_react7.createElement)(
|
|
1543
|
+
"a",
|
|
1544
|
+
{
|
|
1545
|
+
className: "dsh-model-allowance-setup-link",
|
|
1546
|
+
href: view.setupUrl,
|
|
1547
|
+
target: "_blank",
|
|
1548
|
+
rel: "noreferrer noopener"
|
|
1549
|
+
},
|
|
1550
|
+
`${t("badge.setupDoc")} \u2197`
|
|
1551
|
+
) : null
|
|
1552
|
+
) : null,
|
|
1414
1553
|
// A vendor that prices by the wall clock gets its phase and
|
|
1415
1554
|
// countdown here, above the footer.
|
|
1416
1555
|
schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
|
|
1417
|
-
(0,
|
|
1556
|
+
(0, import_react7.createElement)(
|
|
1418
1557
|
"div",
|
|
1419
1558
|
{ className: "dsh-model-allowance-actions" },
|
|
1420
1559
|
// The platform status sits at the left edge of the footer, on
|
|
1421
1560
|
// the same line as the reading time: the card gains no extra
|
|
1422
1561
|
// row, and the state and the source page stay together.
|
|
1423
|
-
(0,
|
|
1562
|
+
(0, import_react7.createElement)(
|
|
1424
1563
|
"span",
|
|
1425
1564
|
{ className: "dsh-model-allowance-status-wrap" },
|
|
1426
|
-
(0,
|
|
1565
|
+
(0, import_react7.createElement)(
|
|
1427
1566
|
currentStatus?.url ? "a" : "span",
|
|
1428
1567
|
{
|
|
1429
1568
|
className: "dsh-model-allowance-status",
|
|
@@ -1434,17 +1573,17 @@ function BalancePanel({
|
|
|
1434
1573
|
rel: "noreferrer noopener"
|
|
1435
1574
|
} : {}
|
|
1436
1575
|
},
|
|
1437
|
-
(0,
|
|
1576
|
+
(0, import_react7.createElement)("span", {
|
|
1438
1577
|
className: "dsh-model-allowance-status-dot",
|
|
1439
1578
|
"aria-hidden": true
|
|
1440
1579
|
}),
|
|
1441
|
-
(0,
|
|
1580
|
+
(0, import_react7.createElement)(
|
|
1442
1581
|
"span",
|
|
1443
1582
|
{ className: "dsh-model-allowance-status-label" },
|
|
1444
1583
|
statusLabel(serviceState, t)
|
|
1445
1584
|
),
|
|
1446
1585
|
...currentStatus?.url ? [
|
|
1447
|
-
(0,
|
|
1586
|
+
(0, import_react7.createElement)(
|
|
1448
1587
|
"span",
|
|
1449
1588
|
{
|
|
1450
1589
|
className: "dsh-model-allowance-status-arrow",
|
|
@@ -1457,7 +1596,7 @@ function BalancePanel({
|
|
|
1457
1596
|
// The reason is a warning mark rather than another line:
|
|
1458
1597
|
// the footer stays one row, and the detail is one hover
|
|
1459
1598
|
// — or one keyboard focus — away.
|
|
1460
|
-
currentStatus?.summary ? (0,
|
|
1599
|
+
currentStatus?.summary ? (0, import_react7.createElement)(
|
|
1461
1600
|
"span",
|
|
1462
1601
|
{
|
|
1463
1602
|
className: "dsh-model-allowance-status-help",
|
|
@@ -1465,26 +1604,26 @@ function BalancePanel({
|
|
|
1465
1604
|
role: "note",
|
|
1466
1605
|
"aria-label": currentStatus.summary
|
|
1467
1606
|
},
|
|
1468
|
-
(0,
|
|
1607
|
+
(0, import_react7.createElement)(
|
|
1469
1608
|
"span",
|
|
1470
1609
|
{
|
|
1471
1610
|
"aria-hidden": true
|
|
1472
1611
|
},
|
|
1473
1612
|
"!"
|
|
1474
1613
|
),
|
|
1475
|
-
(0,
|
|
1614
|
+
(0, import_react7.createElement)(
|
|
1476
1615
|
"span",
|
|
1477
1616
|
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
1478
1617
|
currentStatus.summary
|
|
1479
1618
|
)
|
|
1480
1619
|
) : null
|
|
1481
1620
|
),
|
|
1482
|
-
view?.updatedAt ? (0,
|
|
1621
|
+
view?.updatedAt ? (0, import_react7.createElement)(
|
|
1483
1622
|
"span",
|
|
1484
1623
|
{ className: "dsh-model-allowance-updated" },
|
|
1485
1624
|
t("detail.updatedAt", { time: formatClock(view.updatedAt) })
|
|
1486
1625
|
) : null,
|
|
1487
|
-
(0,
|
|
1626
|
+
(0, import_react7.createElement)(
|
|
1488
1627
|
"button",
|
|
1489
1628
|
{
|
|
1490
1629
|
type: "button",
|
|
@@ -1496,7 +1635,7 @@ function BalancePanel({
|
|
|
1496
1635
|
},
|
|
1497
1636
|
refreshGlyph(16)
|
|
1498
1637
|
),
|
|
1499
|
-
view?.consoleUrl ? (0,
|
|
1638
|
+
view?.consoleUrl ? (0, import_react7.createElement)(
|
|
1500
1639
|
"a",
|
|
1501
1640
|
{
|
|
1502
1641
|
className: "dsh-model-allowance-icon-button",
|
|
@@ -1511,10 +1650,10 @@ function BalancePanel({
|
|
|
1511
1650
|
// The switch to another model of this provider. It sits to the
|
|
1512
1651
|
// right of the console link, which is the last thing the footer
|
|
1513
1652
|
// offered before, so the two never trade places.
|
|
1514
|
-
canSwitch ? (0,
|
|
1653
|
+
canSwitch ? (0, import_react7.createElement)(
|
|
1515
1654
|
"span",
|
|
1516
1655
|
{ ref: catalog.modelWrapRef, className: "dsh-model-allowance-model-wrap" },
|
|
1517
|
-
(0,
|
|
1656
|
+
(0, import_react7.createElement)(
|
|
1518
1657
|
"button",
|
|
1519
1658
|
{
|
|
1520
1659
|
type: "button",
|
|
@@ -1532,7 +1671,7 @@ function BalancePanel({
|
|
|
1532
1671
|
},
|
|
1533
1672
|
modelGlyph(16)
|
|
1534
1673
|
),
|
|
1535
|
-
catalog.modelMenuOpen ? (0,
|
|
1674
|
+
catalog.modelMenuOpen ? (0, import_react7.createElement)(ModelMenu, {
|
|
1536
1675
|
t,
|
|
1537
1676
|
models: catalog.shownModelList,
|
|
1538
1677
|
state: catalog.shownModelListState,
|
|
@@ -1542,12 +1681,15 @@ function BalancePanel({
|
|
|
1542
1681
|
switchToModel: catalog.switchToModel,
|
|
1543
1682
|
modelWrapRef: catalog.modelWrapRef,
|
|
1544
1683
|
showEffortFlyout: catalog.showEffortFlyout,
|
|
1545
|
-
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1684
|
+
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose,
|
|
1685
|
+
promotions: activePromotions,
|
|
1686
|
+
showPromoTip: catalog.showPromoTip,
|
|
1687
|
+
hidePromoTip: catalog.hidePromoTip
|
|
1546
1688
|
}) : null,
|
|
1547
1689
|
// The effort flyout is a sibling of the list, not a
|
|
1548
1690
|
// child: the list scrolls, and a nested panel would be
|
|
1549
1691
|
// clipped by it.
|
|
1550
|
-
catalog.modelMenuOpen && catalog.hoverModel !== null && catalog.shownModelList.includes(catalog.hoverModel.model) ? (0,
|
|
1692
|
+
catalog.modelMenuOpen && catalog.hoverModel !== null && catalog.shownModelList.includes(catalog.hoverModel.model) ? (0, import_react7.createElement)(EffortFlyout, {
|
|
1551
1693
|
t,
|
|
1552
1694
|
hoverModel: catalog.hoverModel,
|
|
1553
1695
|
currentModel: catalog.currentModel,
|
|
@@ -1556,7 +1698,11 @@ function BalancePanel({
|
|
|
1556
1698
|
switchToModel: catalog.switchToModel,
|
|
1557
1699
|
keepEffortFlyout: catalog.keepEffortFlyout,
|
|
1558
1700
|
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1559
|
-
}) : null
|
|
1701
|
+
}) : null,
|
|
1702
|
+
// The badge's tip is a sibling of the list for the same reason
|
|
1703
|
+
// the flyout is: the list scrolls, and a nested hint would be
|
|
1704
|
+
// clipped by it.
|
|
1705
|
+
catalog.modelMenuOpen && catalog.promoTip != null && tipPromotion !== void 0 && catalog.shownModelList.some((model) => model.id === catalog.promoTip.model.id) ? promoTipView(tipPromotion, catalog.promoTip) : null
|
|
1560
1706
|
) : null
|
|
1561
1707
|
)
|
|
1562
1708
|
);
|
|
@@ -1724,6 +1870,7 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1724
1870
|
const [modelMenuOpen, setModelMenuOpen] = React5.useState(false);
|
|
1725
1871
|
const [hoverModel, setHoverModel] = React5.useState(null);
|
|
1726
1872
|
const hoverModelTimer = React5.useRef(null);
|
|
1873
|
+
const [promoTip, setPromoTip] = React5.useState(null);
|
|
1727
1874
|
const [switchingModel, setSwitchingModel] = React5.useState(null);
|
|
1728
1875
|
const modelWrapRef = React5.useRef(null);
|
|
1729
1876
|
const catalogRef = React5.useRef({ value: null, at: 0 });
|
|
@@ -1838,10 +1985,25 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1838
1985
|
const keepEffortFlyout = React5.useCallback(() => {
|
|
1839
1986
|
clearTimeout(hoverModelTimer.current);
|
|
1840
1987
|
}, []);
|
|
1988
|
+
const showPromoTip = React5.useCallback((model, event) => {
|
|
1989
|
+
const wrap = modelWrapRef.current;
|
|
1990
|
+
if (!wrap) return;
|
|
1991
|
+
const chip = event.currentTarget.getBoundingClientRect();
|
|
1992
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
1993
|
+
setPromoTip({
|
|
1994
|
+
model,
|
|
1995
|
+
bottom: wrapRect.bottom - chip.top + 6,
|
|
1996
|
+
right: wrapRect.right - chip.right
|
|
1997
|
+
});
|
|
1998
|
+
}, []);
|
|
1999
|
+
const hidePromoTip = React5.useCallback(() => {
|
|
2000
|
+
setPromoTip(null);
|
|
2001
|
+
}, []);
|
|
1841
2002
|
const toggleModelMenu = React5.useCallback(() => {
|
|
1842
2003
|
setModelError(null);
|
|
1843
2004
|
clearTimeout(hoverModelTimer.current);
|
|
1844
2005
|
setHoverModel(null);
|
|
2006
|
+
setPromoTip(null);
|
|
1845
2007
|
setModelMenuOpen((value) => !value);
|
|
1846
2008
|
}, []);
|
|
1847
2009
|
const modelProvider = catalogProvider ?? activeProvider;
|
|
@@ -1862,6 +2024,9 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1862
2024
|
showEffortFlyout,
|
|
1863
2025
|
scheduleEffortFlyoutClose,
|
|
1864
2026
|
keepEffortFlyout,
|
|
2027
|
+
promoTip,
|
|
2028
|
+
showPromoTip,
|
|
2029
|
+
hidePromoTip,
|
|
1865
2030
|
toggleModelMenu,
|
|
1866
2031
|
switchToModel
|
|
1867
2032
|
};
|
|
@@ -1996,8 +2161,12 @@ var STYLES = [
|
|
|
1996
2161
|
// through the model names. A solid layer keeps the list readable wherever
|
|
1997
2162
|
// it opens.
|
|
1998
2163
|
".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
|
|
2164
|
+
// The list sizes itself to its content: a model name is always shown in
|
|
2165
|
+
// full, and the menu widens to fit it rather than truncating. Only the
|
|
2166
|
+
// viewport caps the width; a long list still scrolls vertically.
|
|
1999
2167
|
".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
|
|
2000
|
-
"min-width:180px;max-width:
|
|
2168
|
+
"width:max-content;min-width:180px;max-width:calc(100vw - 24px);",
|
|
2169
|
+
"max-height:240px;overflow-y:auto;padding:4px;border:0;",
|
|
2001
2170
|
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
2002
2171
|
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
2003
2172
|
".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
|
|
@@ -2008,7 +2177,7 @@ var STYLES = [
|
|
|
2008
2177
|
// would give the chip a second meaning it does not have.
|
|
2009
2178
|
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
2010
2179
|
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
2011
|
-
".dsh-model-allowance-model-name{
|
|
2180
|
+
".dsh-model-allowance-model-name{white-space:nowrap}",
|
|
2012
2181
|
// The trailing side of a model row carries its state label and, for a
|
|
2013
2182
|
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
2014
2183
|
// the right.
|
|
@@ -2034,6 +2203,25 @@ var STYLES = [
|
|
|
2034
2203
|
// The trailing label names the state of one model: the one in use, or the
|
|
2035
2204
|
// one being switched to.
|
|
2036
2205
|
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
2206
|
+
// A running promotion marks its model with a small multiplier badge beside
|
|
2207
|
+
// the name — the card's only statement of the event. The business hue says
|
|
2208
|
+
// "offer" without borrowing the success green the allowance bars speak;
|
|
2209
|
+
// the badge paints its own colour, so the dimmed current row still shows it.
|
|
2210
|
+
".dsh-model-allowance-promo-chip{display:inline-flex;align-items:center;flex:none;",
|
|
2211
|
+
"padding:0 5px;border-radius:999px;height:16px;font-size:10px;font-weight:600;line-height:1;",
|
|
2212
|
+
"color:var(--dsw-alias-state-business-primary);",
|
|
2213
|
+
"background:color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent)}",
|
|
2214
|
+
// The auto margin belongs to the menu row: it keeps name and badge together
|
|
2215
|
+
// at the left while the state label stays at the right edge.
|
|
2216
|
+
".dsh-model-allowance-model-item .dsh-model-allowance-promo-chip{margin-right:auto}",
|
|
2217
|
+
// The badge's hover tip reads the vendor's one-line announcement on the
|
|
2218
|
+
// card's shared tooltip surface. A sibling of the scrolling menu, so
|
|
2219
|
+
// nothing clips it; pointer-events:none keeps it a pure hint.
|
|
2220
|
+
".dsh-model-allowance-promo-tip{position:absolute;z-index:32;width:max-content;",
|
|
2221
|
+
"max-width:240px;padding:6px 8px;border:0;border-radius:var(--dsw-radius-sm);",
|
|
2222
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
2223
|
+
"font-size:11px;line-height:1.5;color:var(--dsw-static-neutral-bluish-00);",
|
|
2224
|
+
"pointer-events:none;white-space:normal;text-align:left}",
|
|
2037
2225
|
// A message covers the whole list: it loads, it is empty, or the switch
|
|
2038
2226
|
// failed and says why.
|
|
2039
2227
|
".dsh-model-allowance-model-message{padding:4px 6px;color:var(--dsw-alias-label-secondary);",
|
|
@@ -2069,6 +2257,10 @@ var STYLES = [
|
|
|
2069
2257
|
".dsh-model-allowance-error{padding:4px 0;color:var(--dsw-alias-state-error-primary)}",
|
|
2070
2258
|
".dsh-model-allowance-reason{padding:2px 0;color:var(--dsw-alias-label-secondary);",
|
|
2071
2259
|
"font-size:11px;word-break:break-word}",
|
|
2260
|
+
".dsh-model-allowance-setup-link{margin-left:6px;color:var(--dsw-alias-state-business-primary);",
|
|
2261
|
+
"text-decoration:none;white-space:nowrap}",
|
|
2262
|
+
".dsh-model-allowance-setup-link:hover,.dsh-model-allowance-setup-link:focus-visible",
|
|
2263
|
+
"{text-decoration:underline}",
|
|
2072
2264
|
// The footer is one right-aligned cluster: the reading time sits directly
|
|
2073
2265
|
// left of the two icon buttons.
|
|
2074
2266
|
".dsh-model-allowance-actions{display:flex;align-items:center;",
|
|
@@ -2229,6 +2421,7 @@ function BalanceBadge(props) {
|
|
|
2229
2421
|
}, [open]);
|
|
2230
2422
|
const [stripWidth, setStripWidth] = React6.useState(0);
|
|
2231
2423
|
const stripRef = React6.useRef(null);
|
|
2424
|
+
const [promotions, setPromotions] = React6.useState(null);
|
|
2232
2425
|
const { available, defaultProvider, entryOf, nameOf } = useProviderDirectory(selected);
|
|
2233
2426
|
const provider = selected ?? defaultProvider;
|
|
2234
2427
|
const activeProvider = picked ?? provider;
|
|
@@ -2262,17 +2455,18 @@ function BalanceBadge(props) {
|
|
|
2262
2455
|
React6.useEffect(() => {
|
|
2263
2456
|
if (!activeProvider) return void 0;
|
|
2264
2457
|
let cancelled = false;
|
|
2265
|
-
|
|
2458
|
+
const readDeclaration = async (method, apply2, label2) => {
|
|
2266
2459
|
try {
|
|
2267
2460
|
const api = await getBalanceApi();
|
|
2268
|
-
if (!api || typeof api
|
|
2269
|
-
const result = await api
|
|
2270
|
-
if (cancelled
|
|
2271
|
-
setSchedule(result.value);
|
|
2461
|
+
if (!api || typeof api[method] !== "function") return;
|
|
2462
|
+
const result = await api[method](activeProvider);
|
|
2463
|
+
if (!cancelled && result.ok) apply2(result.value);
|
|
2272
2464
|
} catch (error) {
|
|
2273
|
-
console.error(
|
|
2465
|
+
console.error(`[model-allowance] reading the ${label2} failed`, { error });
|
|
2274
2466
|
}
|
|
2275
|
-
}
|
|
2467
|
+
};
|
|
2468
|
+
void readDeclaration("schedule", setSchedule, "pricing schedule");
|
|
2469
|
+
void readDeclaration("promotions", setPromotions, "usage promotions");
|
|
2276
2470
|
return () => {
|
|
2277
2471
|
cancelled = true;
|
|
2278
2472
|
};
|
|
@@ -2356,7 +2550,7 @@ function BalanceBadge(props) {
|
|
|
2356
2550
|
if (!provider) return null;
|
|
2357
2551
|
const currentStatus = providerStatus?.provider === activeProvider ? providerStatus : null;
|
|
2358
2552
|
const serviceState = statusDisplayState(currentStatus);
|
|
2359
|
-
return (0,
|
|
2553
|
+
return (0, import_react8.createElement)(
|
|
2360
2554
|
"div",
|
|
2361
2555
|
{
|
|
2362
2556
|
ref: rootRef,
|
|
@@ -2366,8 +2560,8 @@ function BalanceBadge(props) {
|
|
|
2366
2560
|
},
|
|
2367
2561
|
// Component-local styles: React removes them with the component, and
|
|
2368
2562
|
// every colour comes from a theme token so light and dark both follow.
|
|
2369
|
-
(0,
|
|
2370
|
-
(0,
|
|
2563
|
+
(0, import_react8.createElement)("style", { key: "styles" }, STYLES_JOINED),
|
|
2564
|
+
(0, import_react8.createElement)(
|
|
2371
2565
|
"button",
|
|
2372
2566
|
{
|
|
2373
2567
|
type: "button",
|
|
@@ -2377,12 +2571,12 @@ function BalanceBadge(props) {
|
|
|
2377
2571
|
"aria-controls": open ? "dsh-model-allowance-panel" : void 0,
|
|
2378
2572
|
onClick: () => setOpen((value) => !value)
|
|
2379
2573
|
},
|
|
2380
|
-
(0,
|
|
2381
|
-
(0,
|
|
2574
|
+
(0, import_react8.createElement)("span", { className: "dsh-model-allowance-dot", "aria-hidden": true }),
|
|
2575
|
+
(0, import_react8.createElement)("span", { className: "dsh-model-allowance-label" }, label),
|
|
2382
2576
|
// How far the number moved since the last reading, for a few seconds
|
|
2383
2577
|
// after it lands. The arrow follows the number shown beside it: down
|
|
2384
2578
|
// means the balance fell.
|
|
2385
|
-
showingDifference ? (0,
|
|
2579
|
+
showingDifference ? (0, import_react8.createElement)(
|
|
2386
2580
|
"span",
|
|
2387
2581
|
{
|
|
2388
2582
|
className: "dsh-model-allowance-delta",
|
|
@@ -2392,13 +2586,14 @@ function BalanceBadge(props) {
|
|
|
2392
2586
|
`${view.consumption.delta < 0 ? "\u2193" : "\u2191"}${formatDelta(view.consumption)}`
|
|
2393
2587
|
) : null
|
|
2394
2588
|
),
|
|
2395
|
-
open ? (0,
|
|
2589
|
+
open ? (0, import_react8.createElement)(BalancePanel, {
|
|
2396
2590
|
t,
|
|
2397
2591
|
now,
|
|
2398
2592
|
view,
|
|
2399
2593
|
activeProvider,
|
|
2400
2594
|
available,
|
|
2401
2595
|
schedule,
|
|
2596
|
+
promotions,
|
|
2402
2597
|
currentStatus,
|
|
2403
2598
|
serviceState,
|
|
2404
2599
|
refresh,
|
|
@@ -2455,6 +2650,9 @@ function createBalanceContribution() {
|
|
|
2455
2650
|
at: z.number()
|
|
2456
2651
|
}).optional(),
|
|
2457
2652
|
consoleUrl: z.string().optional(),
|
|
2653
|
+
// The setup guide rides an unconfigured reading: the card links it so the
|
|
2654
|
+
// user lands on the walkthrough for this provider's credentials.
|
|
2655
|
+
setupUrl: z.string().optional(),
|
|
2458
2656
|
updatedAt: z.number().optional(),
|
|
2459
2657
|
error: z.string().optional()
|
|
2460
2658
|
});
|
|
@@ -2482,6 +2680,21 @@ function createBalanceContribution() {
|
|
|
2482
2680
|
holidays: z.array(z.string()).optional(),
|
|
2483
2681
|
note: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional()
|
|
2484
2682
|
}).nullable();
|
|
2683
|
+
const promotionSchema = z.object({
|
|
2684
|
+
models: z.array(z.string()),
|
|
2685
|
+
chip: z.object({ zh: z.string().optional(), en: z.string().optional() }),
|
|
2686
|
+
note: z.object({ zh: z.string().optional(), en: z.string().optional() }),
|
|
2687
|
+
// A static declaration carries a date window; a live catalog read may
|
|
2688
|
+
// carry a daily one (a night offer badges only at night), or none at all.
|
|
2689
|
+
timezone: z.string().optional(),
|
|
2690
|
+
from: z.string().optional(),
|
|
2691
|
+
to: z.string().optional(),
|
|
2692
|
+
daily: z.object({ from: z.string(), to: z.string() }).optional()
|
|
2693
|
+
});
|
|
2694
|
+
const promotionsSchema = z.object({
|
|
2695
|
+
provider: z.string(),
|
|
2696
|
+
promotions: z.array(promotionSchema)
|
|
2697
|
+
}).nullable();
|
|
2485
2698
|
const strict = (schema, description, typeSymbol) => ({
|
|
2486
2699
|
mode: "strict",
|
|
2487
2700
|
typeSymbol,
|
|
@@ -2556,6 +2769,38 @@ function createBalanceContribution() {
|
|
|
2556
2769
|
"dsh-model-allowance#defaultProvider"
|
|
2557
2770
|
)
|
|
2558
2771
|
},
|
|
2772
|
+
"balance/testCredentials": {
|
|
2773
|
+
service: "balanceController",
|
|
2774
|
+
description: "Walk a provider's credential chain against the live endpoints.",
|
|
2775
|
+
invocation: { kind: "direct" },
|
|
2776
|
+
parameters: [
|
|
2777
|
+
{
|
|
2778
|
+
name: "accessKeyId",
|
|
2779
|
+
wire: "accessKeyId",
|
|
2780
|
+
source: "json",
|
|
2781
|
+
codec: strict(
|
|
2782
|
+
z.string().min(1),
|
|
2783
|
+
"AccessKey ID candidate.",
|
|
2784
|
+
"dsh-model-allowance#accessKeyId"
|
|
2785
|
+
)
|
|
2786
|
+
},
|
|
2787
|
+
{
|
|
2788
|
+
name: "secretAccessKey",
|
|
2789
|
+
wire: "secretAccessKey",
|
|
2790
|
+
source: "json",
|
|
2791
|
+
codec: strict(
|
|
2792
|
+
z.string().min(1),
|
|
2793
|
+
"AccessKey secret candidate.",
|
|
2794
|
+
"dsh-model-allowance#secretAccessKey"
|
|
2795
|
+
)
|
|
2796
|
+
}
|
|
2797
|
+
],
|
|
2798
|
+
result: strict(
|
|
2799
|
+
z.object({ ok: z.boolean(), error: z.string().optional() }),
|
|
2800
|
+
"The outcome.",
|
|
2801
|
+
"dsh-model-allowance#testOutcome"
|
|
2802
|
+
)
|
|
2803
|
+
},
|
|
2559
2804
|
"balance/refresh": {
|
|
2560
2805
|
service: "balanceController",
|
|
2561
2806
|
description: "Force a fresh reading for one provider, bypassing the cache.",
|
|
@@ -2589,11 +2834,350 @@ function createBalanceContribution() {
|
|
|
2589
2834
|
invocation: { kind: "direct" },
|
|
2590
2835
|
parameters: [providerParameter],
|
|
2591
2836
|
result: strict(scheduleSchema, "The schedule, or null.", "dsh-model-allowance#schedule")
|
|
2837
|
+
},
|
|
2838
|
+
"balance/promotions": {
|
|
2839
|
+
service: "balanceController",
|
|
2840
|
+
description: "The model-scoped usage promotions for one provider, when it declares any.",
|
|
2841
|
+
invocation: { kind: "direct" },
|
|
2842
|
+
parameters: [providerParameter],
|
|
2843
|
+
result: strict(
|
|
2844
|
+
promotionsSchema,
|
|
2845
|
+
"The promotions, or null.",
|
|
2846
|
+
"dsh-model-allowance#promotions"
|
|
2847
|
+
)
|
|
2592
2848
|
}
|
|
2593
2849
|
}
|
|
2594
2850
|
};
|
|
2595
2851
|
}
|
|
2596
2852
|
|
|
2853
|
+
// src/client/credentials-page.js
|
|
2854
|
+
var React7 = __toESM(require("react"), 1);
|
|
2855
|
+
var import_react9 = require("react");
|
|
2856
|
+
|
|
2857
|
+
// src/client/credential-groups.js
|
|
2858
|
+
var CREDENTIAL_GROUPS = Object.freeze([
|
|
2859
|
+
{
|
|
2860
|
+
id: "aliyun",
|
|
2861
|
+
name: {
|
|
2862
|
+
zh: "\u963F\u91CC\u4E91\uFF08\u5343\u95EE Token Plan\uFF09",
|
|
2863
|
+
en: "Alibaba Cloud (Qwen Token Plan)"
|
|
2864
|
+
},
|
|
2865
|
+
docLabel: {
|
|
2866
|
+
zh: "\u5982\u4F55\u83B7\u53D6 AccessKey\uFF1F",
|
|
2867
|
+
en: "How do I get an AccessKey?"
|
|
2868
|
+
},
|
|
2869
|
+
docUrl: "https://github.com/MeiK2333/dsh-model-allowance/blob/master/docs/qwen-token-plen-cn/README.md",
|
|
2870
|
+
test: "qwen",
|
|
2871
|
+
fields: [
|
|
2872
|
+
{
|
|
2873
|
+
ref: "ALIBABA_CLOUD_ACCESS_KEY_ID",
|
|
2874
|
+
label: { zh: "AccessKey ID", en: "AccessKey ID" }
|
|
2875
|
+
},
|
|
2876
|
+
{
|
|
2877
|
+
ref: "ALIBABA_CLOUD_ACCESS_KEY_SECRET",
|
|
2878
|
+
label: { zh: "AccessKey Secret", en: "AccessKey Secret" }
|
|
2879
|
+
}
|
|
2880
|
+
]
|
|
2881
|
+
}
|
|
2882
|
+
]);
|
|
2883
|
+
var CREDENTIAL_REFS = Object.freeze(
|
|
2884
|
+
CREDENTIAL_GROUPS.flatMap((group) => group.fields.map((field) => field.ref))
|
|
2885
|
+
);
|
|
2886
|
+
|
|
2887
|
+
// src/client/credentials-page.js
|
|
2888
|
+
var STYLES2 = [
|
|
2889
|
+
".dsh-allowance-cfg{display:flex;flex-direction:column;gap:12px;max-width:720px;",
|
|
2890
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2891
|
+
".dsh-allowance-cfg-title{margin:0;font-size:16px;line-height:24px;font-weight:500;",
|
|
2892
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2893
|
+
".dsh-allowance-cfg-card{display:flex;flex-direction:column;gap:12px;padding:12px 14px;",
|
|
2894
|
+
"border:0.5px solid var(--dsw-alias-settings-card-stroke);",
|
|
2895
|
+
"background:var(--dsw-alias-settings-card-fill);border-radius:var(--dsw-radius-xl)}",
|
|
2896
|
+
".dsh-allowance-cfg-card-title{margin:0;font-size:14px;line-height:22px;font-weight:500;",
|
|
2897
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2898
|
+
".dsh-allowance-cfg-card-head{display:flex;align-items:center;gap:8px}",
|
|
2899
|
+
".dsh-allowance-cfg-field{display:flex;flex-direction:column;gap:6px}",
|
|
2900
|
+
".dsh-allowance-cfg-field-label{font-size:12px;line-height:18px;font-weight:500;",
|
|
2901
|
+
"color:var(--dsw-alias-label-secondary)}",
|
|
2902
|
+
".dsh-allowance-cfg-text{font-size:14px;line-height:22px;",
|
|
2903
|
+
"color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
|
|
2904
|
+
".dsh-allowance-cfg-status{display:inline-flex;align-items:center;height:22px;",
|
|
2905
|
+
"padding:0 8px;border-radius:var(--dsw-radius-sm);font-size:12px;line-height:18px;",
|
|
2906
|
+
"border:0.5px solid var(--dsw-alias-state-success-primary);",
|
|
2907
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
2908
|
+
".dsh-allowance-cfg-input{box-sizing:border-box;width:100%;height:32px;padding:0 10px;",
|
|
2909
|
+
"border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);",
|
|
2910
|
+
"font:inherit;font-size:14px;line-height:22px;background:var(--dsw-alias-bg-layer-1);",
|
|
2911
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2912
|
+
".dsh-allowance-cfg-input:focus{outline:none;",
|
|
2913
|
+
"border-color:var(--dsw-alias-state-business-primary)}",
|
|
2914
|
+
".dsh-allowance-cfg-input:disabled{opacity:.6;cursor:default}",
|
|
2915
|
+
".dsh-allowance-cfg-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
2916
|
+
".dsh-allowance-cfg-button{box-sizing:border-box;display:inline-flex;align-items:center;",
|
|
2917
|
+
"justify-content:center;height:32px;padding:0 14px;border:none;",
|
|
2918
|
+
"border-radius:var(--dsw-radius-md);font:inherit;font-size:14px;line-height:22px;",
|
|
2919
|
+
"cursor:pointer}",
|
|
2920
|
+
'.dsh-allowance-cfg-button[data-tone="primary"]{',
|
|
2921
|
+
"background:var(--dsw-alias-button-primary-fill);",
|
|
2922
|
+
"color:var(--dsw-alias-label-primary-foreground)}",
|
|
2923
|
+
'.dsh-allowance-cfg-button[data-tone="primary"]:hover:not(:disabled){',
|
|
2924
|
+
"background:var(--dsw-alias-button-primary-hover)}",
|
|
2925
|
+
'.dsh-allowance-cfg-button[data-tone="secondary"]{',
|
|
2926
|
+
"border:0.5px solid var(--dsw-alias-border-l3);background:transparent;",
|
|
2927
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2928
|
+
'.dsh-allowance-cfg-button[data-tone="secondary"]:hover:not(:disabled){',
|
|
2929
|
+
"background:var(--dsw-alias-interactive-bg-hover-solid)}",
|
|
2930
|
+
".dsh-allowance-cfg-button:disabled{opacity:.5;cursor:default}",
|
|
2931
|
+
".dsh-allowance-cfg-link{font-size:12px;line-height:18px;",
|
|
2932
|
+
"color:var(--dsw-alias-state-business-primary);text-decoration:none}",
|
|
2933
|
+
".dsh-allowance-cfg-link:hover{text-decoration:underline}",
|
|
2934
|
+
".dsh-allowance-cfg-saved{margin:0;font-size:12px;line-height:18px;",
|
|
2935
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
2936
|
+
".dsh-allowance-cfg-error{margin:0;font-size:12px;line-height:18px;",
|
|
2937
|
+
"color:var(--dsw-alias-state-error-primary)}",
|
|
2938
|
+
".dsh-allowance-cfg-hint{margin:0;font-size:12px;line-height:18px;",
|
|
2939
|
+
"color:var(--dsh-alias-label-tertiary)}"
|
|
2940
|
+
].join("");
|
|
2941
|
+
function pick(bilingual) {
|
|
2942
|
+
return bilingual[activeLanguage()] ?? bilingual.en ?? bilingual.zh;
|
|
2943
|
+
}
|
|
2944
|
+
function errorText(error) {
|
|
2945
|
+
return error instanceof Error ? error.message : String(error);
|
|
2946
|
+
}
|
|
2947
|
+
async function testGroup(group, drafts, refId, refSecret, t) {
|
|
2948
|
+
if (group.test !== "qwen") return { ok: true };
|
|
2949
|
+
try {
|
|
2950
|
+
const api = await getBalanceApi();
|
|
2951
|
+
if (!api || typeof api.testCredentials !== "function") return { ok: true };
|
|
2952
|
+
const result = await api.testCredentials(drafts[refId] ?? "", drafts[refSecret] ?? "");
|
|
2953
|
+
if (result.ok && result.value?.ok === true) return { ok: true };
|
|
2954
|
+
if (result.ok && result.value?.ok === false) {
|
|
2955
|
+
return { ok: false, error: result.value.error ?? t("settings.testRejected") };
|
|
2956
|
+
}
|
|
2957
|
+
return { ok: false, error: errorText(result.error ?? t("settings.testRejected")) };
|
|
2958
|
+
} catch (error) {
|
|
2959
|
+
return { ok: false, error: errorText(error) };
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
function unwrap(response) {
|
|
2963
|
+
if (response?.ok) return response.value;
|
|
2964
|
+
const detail = response?.error;
|
|
2965
|
+
throw new Error(
|
|
2966
|
+
detail instanceof Error ? detail.message : typeof detail?.message === "string" ? detail.message : typeof detail === "string" ? detail : "the Host refused the call"
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
function CredentialsSection({ ctx, t }) {
|
|
2970
|
+
const credentials = ctx.get("remote.credentials");
|
|
2971
|
+
const [infos, setInfos] = React7.useState(void 0);
|
|
2972
|
+
const [drafts, setDrafts] = React7.useState({});
|
|
2973
|
+
const [editing, setEditing] = React7.useState({});
|
|
2974
|
+
const [busy, setBusy] = React7.useState(false);
|
|
2975
|
+
const [notice, setNotice] = React7.useState(void 0);
|
|
2976
|
+
const load = React7.useCallback(async () => {
|
|
2977
|
+
if (credentials === void 0) return;
|
|
2978
|
+
try {
|
|
2979
|
+
setInfos(unwrap(await credentials.describe([...CREDENTIAL_REFS])));
|
|
2980
|
+
} catch (error) {
|
|
2981
|
+
setInfos({});
|
|
2982
|
+
setNotice({ tone: "error", text: `${t("settings.loadFailed")}: ${errorText(error)}` });
|
|
2983
|
+
}
|
|
2984
|
+
}, [credentials, t]);
|
|
2985
|
+
React7.useEffect(() => {
|
|
2986
|
+
void load();
|
|
2987
|
+
}, [load]);
|
|
2988
|
+
const resetGroup = (group) => {
|
|
2989
|
+
setDrafts((previous) => {
|
|
2990
|
+
const next = { ...previous };
|
|
2991
|
+
for (const field of group.fields) delete next[field.ref];
|
|
2992
|
+
return next;
|
|
2993
|
+
});
|
|
2994
|
+
setEditing((previous) => ({ ...previous, [group.id]: false }));
|
|
2995
|
+
};
|
|
2996
|
+
const saveGroup = async (group) => {
|
|
2997
|
+
const values = group.fields.map((field) => (drafts[field.ref] ?? "").trim());
|
|
2998
|
+
if (values.some((value) => value === "")) {
|
|
2999
|
+
setNotice({ tone: "error", text: t("settings.fillAll") });
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
setBusy(true);
|
|
3003
|
+
setNotice(void 0);
|
|
3004
|
+
try {
|
|
3005
|
+
const [idField, secretField] = group.fields;
|
|
3006
|
+
const tested = await testGroup(
|
|
3007
|
+
group,
|
|
3008
|
+
Object.fromEntries(
|
|
3009
|
+
group.fields.map((field) => [field.ref, (drafts[field.ref] ?? "").trim()])
|
|
3010
|
+
),
|
|
3011
|
+
idField.ref,
|
|
3012
|
+
secretField.ref,
|
|
3013
|
+
t
|
|
3014
|
+
);
|
|
3015
|
+
if (!tested.ok) {
|
|
3016
|
+
setNotice({ tone: "error", text: `${t("settings.testFailed")}: ${tested.error}` });
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
for (const field of group.fields) {
|
|
3020
|
+
unwrap(await credentials.set(field.ref, (drafts[field.ref] ?? "").trim()));
|
|
3021
|
+
}
|
|
3022
|
+
resetGroup(group);
|
|
3023
|
+
setNotice({ tone: "ok", text: t("settings.saved") });
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
setNotice({ tone: "error", text: `${t("settings.saveFailed")}: ${errorText(error)}` });
|
|
3026
|
+
} finally {
|
|
3027
|
+
setBusy(false);
|
|
3028
|
+
await load();
|
|
3029
|
+
}
|
|
3030
|
+
};
|
|
3031
|
+
const deleteGroup = async (group) => {
|
|
3032
|
+
setBusy(true);
|
|
3033
|
+
setNotice(void 0);
|
|
3034
|
+
try {
|
|
3035
|
+
for (const field of group.fields) {
|
|
3036
|
+
unwrap(await credentials.unset(field.ref));
|
|
3037
|
+
}
|
|
3038
|
+
resetGroup(group);
|
|
3039
|
+
setNotice({ tone: "ok", text: t("settings.deleted") });
|
|
3040
|
+
} catch (error) {
|
|
3041
|
+
setNotice({ tone: "error", text: `${t("settings.deleteFailed")}: ${errorText(error)}` });
|
|
3042
|
+
} finally {
|
|
3043
|
+
setBusy(false);
|
|
3044
|
+
await load();
|
|
3045
|
+
}
|
|
3046
|
+
};
|
|
3047
|
+
const renderField = (field, editMode) => {
|
|
3048
|
+
const info = infos?.[field.ref];
|
|
3049
|
+
return (0, import_react9.createElement)(
|
|
3050
|
+
"div",
|
|
3051
|
+
{ key: field.ref, className: "dsh-allowance-cfg-field" },
|
|
3052
|
+
(0, import_react9.createElement)(
|
|
3053
|
+
editMode ? "label" : "div",
|
|
3054
|
+
{
|
|
3055
|
+
className: "dsh-allowance-cfg-field-label",
|
|
3056
|
+
htmlFor: editMode ? `dsh-allowance-cfg-${field.ref}` : void 0
|
|
3057
|
+
},
|
|
3058
|
+
pick(field.label)
|
|
3059
|
+
),
|
|
3060
|
+
editMode ? (0, import_react9.createElement)("input", {
|
|
3061
|
+
id: `dsh-allowance-cfg-${field.ref}`,
|
|
3062
|
+
className: "dsh-allowance-cfg-input",
|
|
3063
|
+
type: "password",
|
|
3064
|
+
autoComplete: "off",
|
|
3065
|
+
spellCheck: false,
|
|
3066
|
+
disabled: busy || info?.writable === false,
|
|
3067
|
+
value: drafts[field.ref] ?? "",
|
|
3068
|
+
onChange: (event) => setDrafts((previous) => ({ ...previous, [field.ref]: event.target.value }))
|
|
3069
|
+
}) : (
|
|
3070
|
+
// A stored record reads as text, not as a box that mimics the
|
|
3071
|
+
// entry form: the two states must be told apart at a glance.
|
|
3072
|
+
(0, import_react9.createElement)(
|
|
3073
|
+
"span",
|
|
3074
|
+
{ className: "dsh-allowance-cfg-text" },
|
|
3075
|
+
typeof info?.masked === "string" && info.masked !== "" ? info.masked : "********"
|
|
3076
|
+
)
|
|
3077
|
+
)
|
|
3078
|
+
);
|
|
3079
|
+
};
|
|
3080
|
+
const renderGroup = (group) => {
|
|
3081
|
+
const allStored = group.fields.every((field) => infos?.[field.ref]?.configured === true);
|
|
3082
|
+
const editMode = !allStored || editing[group.id] === true;
|
|
3083
|
+
return (0, import_react9.createElement)(
|
|
3084
|
+
"section",
|
|
3085
|
+
{ key: group.id, className: "dsh-allowance-cfg-card" },
|
|
3086
|
+
(0, import_react9.createElement)(
|
|
3087
|
+
"div",
|
|
3088
|
+
{ className: "dsh-allowance-cfg-card-head" },
|
|
3089
|
+
(0, import_react9.createElement)("h3", { className: "dsh-allowance-cfg-card-title" }, pick(group.name)),
|
|
3090
|
+
// The stored state names itself, so the card reads as configured or
|
|
3091
|
+
// as a form to fill without reading any field.
|
|
3092
|
+
allStored ? (0, import_react9.createElement)("span", { className: "dsh-allowance-cfg-status" }, t("settings.configured")) : null
|
|
3093
|
+
),
|
|
3094
|
+
group.docUrl ? (0, import_react9.createElement)(
|
|
3095
|
+
"a",
|
|
3096
|
+
{
|
|
3097
|
+
className: "dsh-allowance-cfg-link",
|
|
3098
|
+
href: group.docUrl,
|
|
3099
|
+
target: "_blank",
|
|
3100
|
+
rel: "noreferrer noopener"
|
|
3101
|
+
},
|
|
3102
|
+
`${group.docLabel ? pick(group.docLabel) : t("settings.doc")} \u2197`
|
|
3103
|
+
) : null,
|
|
3104
|
+
group.fields.map((field) => renderField(field, editMode)),
|
|
3105
|
+
(0, import_react9.createElement)(
|
|
3106
|
+
"div",
|
|
3107
|
+
{ className: "dsh-allowance-cfg-actions" },
|
|
3108
|
+
editMode ? (0, import_react9.createElement)(
|
|
3109
|
+
"button",
|
|
3110
|
+
{
|
|
3111
|
+
type: "button",
|
|
3112
|
+
className: "dsh-allowance-cfg-button",
|
|
3113
|
+
"data-tone": "primary",
|
|
3114
|
+
disabled: busy,
|
|
3115
|
+
onClick: () => void saveGroup(group)
|
|
3116
|
+
},
|
|
3117
|
+
busy ? t("settings.testing") : t("settings.save")
|
|
3118
|
+
) : [
|
|
3119
|
+
(0, import_react9.createElement)(
|
|
3120
|
+
"button",
|
|
3121
|
+
{
|
|
3122
|
+
type: "button",
|
|
3123
|
+
key: "edit",
|
|
3124
|
+
className: "dsh-allowance-cfg-button",
|
|
3125
|
+
"data-tone": "secondary",
|
|
3126
|
+
disabled: busy,
|
|
3127
|
+
onClick: () => setEditing((previous) => ({ ...previous, [group.id]: true }))
|
|
3128
|
+
},
|
|
3129
|
+
t("settings.edit")
|
|
3130
|
+
),
|
|
3131
|
+
(0, import_react9.createElement)(
|
|
3132
|
+
"button",
|
|
3133
|
+
{
|
|
3134
|
+
type: "button",
|
|
3135
|
+
key: "delete",
|
|
3136
|
+
className: "dsh-allowance-cfg-button",
|
|
3137
|
+
"data-tone": "secondary",
|
|
3138
|
+
disabled: busy,
|
|
3139
|
+
onClick: () => void deleteGroup(group)
|
|
3140
|
+
},
|
|
3141
|
+
t("settings.delete")
|
|
3142
|
+
)
|
|
3143
|
+
],
|
|
3144
|
+
allStored && editMode ? (0, import_react9.createElement)(
|
|
3145
|
+
"button",
|
|
3146
|
+
{
|
|
3147
|
+
type: "button",
|
|
3148
|
+
className: "dsh-allowance-cfg-button",
|
|
3149
|
+
"data-tone": "secondary",
|
|
3150
|
+
disabled: busy,
|
|
3151
|
+
onClick: () => resetGroup(group)
|
|
3152
|
+
},
|
|
3153
|
+
t("settings.cancel")
|
|
3154
|
+
) : null
|
|
3155
|
+
)
|
|
3156
|
+
);
|
|
3157
|
+
};
|
|
3158
|
+
return (0, import_react9.createElement)(
|
|
3159
|
+
React7.Fragment,
|
|
3160
|
+
null,
|
|
3161
|
+
// Component-local styles: React removes them with the component.
|
|
3162
|
+
(0, import_react9.createElement)("style", { key: "styles" }, STYLES2),
|
|
3163
|
+
(0, import_react9.createElement)(
|
|
3164
|
+
"div",
|
|
3165
|
+
{ className: "dsh-allowance-cfg" },
|
|
3166
|
+
(0, import_react9.createElement)("h2", { className: "dsh-allowance-cfg-title" }, t("settings.title")),
|
|
3167
|
+
credentials === void 0 ? (0, import_react9.createElement)("p", { className: "dsh-allowance-cfg-error" }, t("settings.unavailable")) : infos === void 0 ? (0, import_react9.createElement)("p", { className: "dsh-allowance-cfg-hint" }, t("settings.loading")) : CREDENTIAL_GROUPS.map((group) => renderGroup(group)),
|
|
3168
|
+
notice === void 0 ? null : (0, import_react9.createElement)(
|
|
3169
|
+
"p",
|
|
3170
|
+
{
|
|
3171
|
+
key: "notice",
|
|
3172
|
+
role: "status",
|
|
3173
|
+
className: notice.tone === "error" ? "dsh-allowance-cfg-error" : "dsh-allowance-cfg-saved"
|
|
3174
|
+
},
|
|
3175
|
+
notice.text
|
|
3176
|
+
)
|
|
3177
|
+
)
|
|
3178
|
+
);
|
|
3179
|
+
}
|
|
3180
|
+
|
|
2597
3181
|
// src/client/index.js
|
|
2598
3182
|
var inject = ["slots", "locale", "remote"];
|
|
2599
3183
|
function apply(ctx) {
|
|
@@ -2658,7 +3242,20 @@ function apply(ctx) {
|
|
|
2658
3242
|
id: "model-allowance",
|
|
2659
3243
|
order: 10
|
|
2660
3244
|
},
|
|
2661
|
-
(props) => (0,
|
|
3245
|
+
(props) => (0, import_react10.createElement)(BalanceBadge, { ...props, ctx, t })
|
|
3246
|
+
)
|
|
3247
|
+
);
|
|
3248
|
+
const SECTION = "settings.section";
|
|
3249
|
+
ctx.slots.inject(
|
|
3250
|
+
SECTION,
|
|
3251
|
+
() => ctx.slots.register(
|
|
3252
|
+
{
|
|
3253
|
+
name: SECTION,
|
|
3254
|
+
id: "model-allowance",
|
|
3255
|
+
order: 30,
|
|
3256
|
+
label: () => t("settings.nav")
|
|
3257
|
+
},
|
|
3258
|
+
(props) => (0, import_react10.createElement)(CredentialsSection, { ...props, ctx, t })
|
|
2662
3259
|
)
|
|
2663
3260
|
);
|
|
2664
3261
|
}
|