dsh-model-allowance 1.1.1 → 1.2.1
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 +9 -3
- package/README.zh.md +7 -3
- package/client.js +282 -118
- package/index.js +69 -0
- package/lib/providers/openai_codex.js +334 -0
- package/lib/providers/promotions.js +169 -0
- package/lib/providers/qwen_promotions.js +223 -0
- package/lib/providers/qwen_token_plan.js +3 -0
- package/lib/providers/shared.js +14 -0
- package/lib/providers/zai.js +25 -0
- package/lib/providers.js +6 -2
- package/lib/remote.js +14 -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 = {
|
|
@@ -283,6 +283,7 @@ var QWEN_GRADIENT_STOPS = [
|
|
|
283
283
|
["#082DFF", "0"],
|
|
284
284
|
["#3FD2F9", "1"]
|
|
285
285
|
];
|
|
286
|
+
var OPENAI_PATH = "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z";
|
|
286
287
|
var XIAOMI_PATHS = [
|
|
287
288
|
"M73.7449 15.9987C73.4083 15.998 73.0857 15.8638 72.8479 15.6256C72.6101 15.3873 72.4766 15.0644 72.4766 14.7278V7.165C72.4914 6.83757 72.632 6.52848 72.869 6.30203C73.1059 6.07559 73.4211 5.94922 73.7488 5.94922C74.0766 5.94922 74.3918 6.07559 74.6287 6.30203C74.8657 6.52848 75.0062 6.83757 75.0211 7.165V14.7278C75.0208 14.895 74.9875 15.0606 74.9232 15.215C74.8588 15.3693 74.7647 15.5095 74.6462 15.6276C74.5277 15.7456 74.3871 15.8391 74.2325 15.9028C74.0778 15.9665 73.9122 15.9991 73.7449 15.9987Z",
|
|
288
289
|
"M87.3607 15.9993C87.0234 15.9993 86.6998 15.8655 86.4611 15.6272C86.2223 15.389 86.0878 15.0657 86.0871 14.7284V4.67881L81.4654 9.45281C81.2304 9.69657 80.9081 9.83697 80.5695 9.84312C80.231 9.84928 79.9038 9.72069 79.6601 9.48563C79.4163 9.25058 79.2759 8.92832 79.2697 8.58976C79.2667 8.42211 79.2967 8.25551 79.358 8.09947C79.4194 7.94342 79.5108 7.80098 79.6272 7.68028L86.4469 0.661082C86.6229 0.478921 86.8494 0.35354 87.0973 0.301033C87.3451 0.248526 87.603 0.271291 87.8378 0.366403C88.0727 0.461516 88.2737 0.624637 88.4151 0.834827C88.5566 1.04502 88.632 1.29268 88.6317 1.54603V14.7284C88.6317 15.0655 88.4978 15.3887 88.2594 15.6271C88.021 15.8654 87.6978 15.9993 87.3607 15.9993Z",
|
|
@@ -298,6 +299,8 @@ var ICON_GEOMETRY = {
|
|
|
298
299
|
kimi: { x: 0, y: 0.94, vbW: 23.95, vbH: 23.25, inkW: 23.95, inkH: 23.25 },
|
|
299
300
|
// OpenCode's logo draws its 240x300 frame from the origin.
|
|
300
301
|
opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 },
|
|
302
|
+
// OpenAI's blossom fills its published 24x24 box edge to edge.
|
|
303
|
+
openai: { x: 0, y: 0, vbW: 24, vbH: 24, inkW: 24, inkH: 24 },
|
|
301
304
|
// Qwen's petals draw 0.42..27.58 across and -0.05..28.05 down, so the
|
|
302
305
|
// published 28x28 box would clip a hair of the outer petals.
|
|
303
306
|
qwen: { x: 0.4155, y: -0.048, vbW: 27.169, vbH: 28.0988, inkW: 27.169, inkH: 28.0988 },
|
|
@@ -399,6 +402,8 @@ function providerIcon(route, inkHeight, mark) {
|
|
|
399
402
|
fillOpacity: path.opacity
|
|
400
403
|
})
|
|
401
404
|
);
|
|
405
|
+
} else if (mark.icon === "openai") {
|
|
406
|
+
content = [(0, import_react.createElement)("path", { key: "openai", d: OPENAI_PATH, fill: "currentColor" })];
|
|
402
407
|
} else if (mark.icon === "xiaomi") {
|
|
403
408
|
content = XIAOMI_PATHS.map(
|
|
404
409
|
(d, index) => (0, import_react.createElement)("path", { key: `xiaomi-${String(index)}`, d, fill: "#1F2329" })
|
|
@@ -616,6 +621,9 @@ function statusLabel(state, t) {
|
|
|
616
621
|
return key === void 0 ? t("status.unknown") : t(key);
|
|
617
622
|
}
|
|
618
623
|
|
|
624
|
+
// src/client/promotions.js
|
|
625
|
+
var import_react3 = require("react");
|
|
626
|
+
|
|
619
627
|
// src/client/schedule.js
|
|
620
628
|
var import_react2 = require("react");
|
|
621
629
|
function formatCountdown(ms) {
|
|
@@ -810,6 +818,57 @@ function scheduleView(schedule, now, t) {
|
|
|
810
818
|
);
|
|
811
819
|
}
|
|
812
820
|
|
|
821
|
+
// src/client/promotions.js
|
|
822
|
+
var pad22 = (value) => String(value).padStart(2, "0");
|
|
823
|
+
function wallMinutes2(time) {
|
|
824
|
+
const [hour, minute] = time.split(":").map(Number);
|
|
825
|
+
return hour * 60 + minute;
|
|
826
|
+
}
|
|
827
|
+
function promotionActive(promotion, now) {
|
|
828
|
+
if (promotion.timezone === void 0) return true;
|
|
829
|
+
const parts = zoneParts(now, promotion.timezone);
|
|
830
|
+
if (promotion.from !== void 0 && promotion.to !== void 0) {
|
|
831
|
+
const date = `${String(parts.year)}-${pad22(parts.month)}-${pad22(parts.day)}`;
|
|
832
|
+
if (date < promotion.from || date > promotion.to) return false;
|
|
833
|
+
}
|
|
834
|
+
if (promotion.daily !== void 0) {
|
|
835
|
+
const minutes = parts.hour * 60 + parts.minute;
|
|
836
|
+
const from = wallMinutes2(promotion.daily.from);
|
|
837
|
+
const to = wallMinutes2(promotion.daily.to);
|
|
838
|
+
const inside = from <= to ? minutes >= from && minutes < to : minutes >= from || minutes < to;
|
|
839
|
+
if (!inside) return false;
|
|
840
|
+
}
|
|
841
|
+
return true;
|
|
842
|
+
}
|
|
843
|
+
function promotionChip(promotion) {
|
|
844
|
+
const language = activeLanguage();
|
|
845
|
+
return promotion.chip?.[language] ?? promotion.chip?.en ?? promotion.chip?.zh;
|
|
846
|
+
}
|
|
847
|
+
function promotionForModel(promotions, modelId) {
|
|
848
|
+
if (!Array.isArray(promotions) || typeof modelId !== "string" || modelId === "") return void 0;
|
|
849
|
+
const wanted = modelId.toLowerCase();
|
|
850
|
+
return promotions.find(
|
|
851
|
+
(promotion) => promotion.models.some((model) => model.toLowerCase() === wanted)
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
function promotionNote(promotion) {
|
|
855
|
+
const language = activeLanguage();
|
|
856
|
+
return promotion.note?.[language] ?? promotion.note?.en ?? promotion.note?.zh;
|
|
857
|
+
}
|
|
858
|
+
function promoTipView(promotion, position) {
|
|
859
|
+
const note = promotionNote(promotion);
|
|
860
|
+
if (note === void 0) return null;
|
|
861
|
+
return (0, import_react3.createElement)(
|
|
862
|
+
"div",
|
|
863
|
+
{
|
|
864
|
+
className: "dsh-model-allowance-promo-tip",
|
|
865
|
+
role: "tooltip",
|
|
866
|
+
style: { bottom: `${String(position.bottom)}px`, right: `${String(position.right)}px` }
|
|
867
|
+
},
|
|
868
|
+
note
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
|
|
813
872
|
// src/client/windows.js
|
|
814
873
|
function windowTitle(window, t) {
|
|
815
874
|
const label = window.label?.[activeLanguage()] ?? window.label?.en ?? window.label?.zh;
|
|
@@ -868,7 +927,7 @@ function barTone(percent) {
|
|
|
868
927
|
}
|
|
869
928
|
|
|
870
929
|
// src/client/components/effort-flyout.js
|
|
871
|
-
var
|
|
930
|
+
var import_react4 = require("react");
|
|
872
931
|
|
|
873
932
|
// src/client/models.js
|
|
874
933
|
function providerGroup(catalog, provider) {
|
|
@@ -921,7 +980,7 @@ function EffortFlyout({
|
|
|
921
980
|
keepEffortFlyout,
|
|
922
981
|
scheduleEffortFlyoutClose
|
|
923
982
|
}) {
|
|
924
|
-
return (0,
|
|
983
|
+
return (0, import_react4.createElement)(
|
|
925
984
|
"div",
|
|
926
985
|
{
|
|
927
986
|
className: "dsh-model-allowance-effort-menu",
|
|
@@ -935,7 +994,7 @@ function EffortFlyout({
|
|
|
935
994
|
},
|
|
936
995
|
...effortChoices(hoverModel.model).map((effort) => {
|
|
937
996
|
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
938
|
-
return (0,
|
|
997
|
+
return (0, import_react4.createElement)(
|
|
939
998
|
"button",
|
|
940
999
|
{
|
|
941
1000
|
type: "button",
|
|
@@ -950,19 +1009,19 @@ function EffortFlyout({
|
|
|
950
1009
|
void switchToModel(hoverModel.model, effort.id);
|
|
951
1010
|
}
|
|
952
1011
|
},
|
|
953
|
-
(0,
|
|
1012
|
+
(0, import_react4.createElement)(
|
|
954
1013
|
"span",
|
|
955
1014
|
{ className: "dsh-model-allowance-model-name" },
|
|
956
1015
|
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
957
1016
|
),
|
|
958
|
-
effort.isDefault && !isCurrentEffort ? (0,
|
|
1017
|
+
effort.isDefault && !isCurrentEffort ? (0, import_react4.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.effortDefault")) : null
|
|
959
1018
|
);
|
|
960
1019
|
})
|
|
961
1020
|
);
|
|
962
1021
|
}
|
|
963
1022
|
|
|
964
1023
|
// src/client/components/model-menu.js
|
|
965
|
-
var
|
|
1024
|
+
var import_react5 = require("react");
|
|
966
1025
|
function ModelMenu({
|
|
967
1026
|
t,
|
|
968
1027
|
models,
|
|
@@ -973,18 +1032,21 @@ function ModelMenu({
|
|
|
973
1032
|
switchToModel,
|
|
974
1033
|
modelWrapRef,
|
|
975
1034
|
showEffortFlyout,
|
|
976
|
-
scheduleEffortFlyoutClose
|
|
1035
|
+
scheduleEffortFlyoutClose,
|
|
1036
|
+
promotions,
|
|
1037
|
+
showPromoTip,
|
|
1038
|
+
hidePromoTip
|
|
977
1039
|
}) {
|
|
978
|
-
return (0,
|
|
1040
|
+
return (0, import_react5.createElement)(
|
|
979
1041
|
"div",
|
|
980
1042
|
{
|
|
981
1043
|
className: "dsh-model-allowance-model-menu",
|
|
982
1044
|
role: "menu",
|
|
983
1045
|
"aria-label": t("model.title")
|
|
984
1046
|
},
|
|
985
|
-
state === "loading" ? (0,
|
|
986
|
-
state === "empty" ? (0,
|
|
987
|
-
state === "error" ? (0,
|
|
1047
|
+
state === "loading" ? (0, import_react5.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.loading")) : null,
|
|
1048
|
+
state === "empty" ? (0, import_react5.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.empty")) : null,
|
|
1049
|
+
state === "error" ? (0, import_react5.createElement)(
|
|
988
1050
|
"div",
|
|
989
1051
|
{
|
|
990
1052
|
className: "dsh-model-allowance-model-message",
|
|
@@ -996,7 +1058,9 @@ function ModelMenu({
|
|
|
996
1058
|
const isCurrent = model.id === currentModel;
|
|
997
1059
|
const efforts = effortChoices(model);
|
|
998
1060
|
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
999
|
-
|
|
1061
|
+
const promotion = promotionForModel(promotions, model.id);
|
|
1062
|
+
const chip = promotion === void 0 ? void 0 : promotionChip(promotion);
|
|
1063
|
+
return (0, import_react5.createElement)(
|
|
1000
1064
|
"button",
|
|
1001
1065
|
{
|
|
1002
1066
|
type: "button",
|
|
@@ -1013,6 +1077,7 @@ function ModelMenu({
|
|
|
1013
1077
|
},
|
|
1014
1078
|
...efforts === null ? {} : {
|
|
1015
1079
|
onMouseEnter: (event) => {
|
|
1080
|
+
if (event.target?.closest?.(".dsh-model-allowance-promo-chip")) return;
|
|
1016
1081
|
const wrap = modelWrapRef.current;
|
|
1017
1082
|
if (!wrap) return;
|
|
1018
1083
|
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
@@ -1023,12 +1088,30 @@ function ModelMenu({
|
|
|
1023
1088
|
}
|
|
1024
1089
|
}
|
|
1025
1090
|
},
|
|
1026
|
-
(0,
|
|
1027
|
-
(0,
|
|
1091
|
+
(0, import_react5.createElement)("span", { className: "dsh-model-allowance-model-name" }, model.name ?? model.id),
|
|
1092
|
+
promotion === void 0 || chip === void 0 || chip === "" ? null : (0, import_react5.createElement)(
|
|
1093
|
+
"span",
|
|
1094
|
+
{
|
|
1095
|
+
className: "dsh-model-allowance-promo-chip",
|
|
1096
|
+
// A bare span is role=generic, which ARIA forbids naming;
|
|
1097
|
+
// img lets the announcement reach assistive tech.
|
|
1098
|
+
role: "img",
|
|
1099
|
+
"aria-label": promotionNote(promotion),
|
|
1100
|
+
onMouseEnter: (event) => {
|
|
1101
|
+
scheduleEffortFlyoutClose(model.id);
|
|
1102
|
+
showPromoTip?.(model, event);
|
|
1103
|
+
},
|
|
1104
|
+
onMouseLeave: () => {
|
|
1105
|
+
hidePromoTip?.();
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
chip
|
|
1109
|
+
),
|
|
1110
|
+
(0, import_react5.createElement)(
|
|
1028
1111
|
"span",
|
|
1029
1112
|
{ className: "dsh-model-allowance-model-side" },
|
|
1030
|
-
switchingModel === model.id ? (0,
|
|
1031
|
-
efforts === null ? null : (0,
|
|
1113
|
+
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,
|
|
1114
|
+
efforts === null ? null : (0, import_react5.createElement)(
|
|
1032
1115
|
"span",
|
|
1033
1116
|
{
|
|
1034
1117
|
className: "dsh-model-allowance-model-arrow",
|
|
@@ -1040,7 +1123,7 @@ function ModelMenu({
|
|
|
1040
1123
|
);
|
|
1041
1124
|
}),
|
|
1042
1125
|
// A failed switch keeps the list open and says why.
|
|
1043
|
-
modelError && state !== "error" ? (0,
|
|
1126
|
+
modelError && state !== "error" ? (0, import_react5.createElement)(
|
|
1044
1127
|
"div",
|
|
1045
1128
|
{
|
|
1046
1129
|
className: "dsh-model-allowance-model-message",
|
|
@@ -1053,7 +1136,7 @@ function ModelMenu({
|
|
|
1053
1136
|
|
|
1054
1137
|
// src/client/components/provider-strip.js
|
|
1055
1138
|
var React2 = __toESM(require("react"), 1);
|
|
1056
|
-
var
|
|
1139
|
+
var import_react6 = require("react");
|
|
1057
1140
|
|
|
1058
1141
|
// src/client/hooks/use-provider-directory.js
|
|
1059
1142
|
var React = __toESM(require("react"), 1);
|
|
@@ -1211,7 +1294,7 @@ function ProviderStrip({
|
|
|
1211
1294
|
const mark = markFor(entry.route);
|
|
1212
1295
|
const name = nameOf(entry.route);
|
|
1213
1296
|
const active = entryCovers(entry, activeProvider);
|
|
1214
|
-
return (0,
|
|
1297
|
+
return (0, import_react6.createElement)(
|
|
1215
1298
|
"button",
|
|
1216
1299
|
{
|
|
1217
1300
|
type: "button",
|
|
@@ -1240,10 +1323,10 @@ function ProviderStrip({
|
|
|
1240
1323
|
event.preventDefault();
|
|
1241
1324
|
tabs[next]?.focus();
|
|
1242
1325
|
};
|
|
1243
|
-
return (0,
|
|
1326
|
+
return (0, import_react6.createElement)(
|
|
1244
1327
|
"div",
|
|
1245
1328
|
{ className: "dsh-model-allowance-switcher-wrap" },
|
|
1246
|
-
(0,
|
|
1329
|
+
(0, import_react6.createElement)(
|
|
1247
1330
|
"div",
|
|
1248
1331
|
{
|
|
1249
1332
|
ref: stripRef,
|
|
@@ -1253,7 +1336,7 @@ function ProviderStrip({
|
|
|
1253
1336
|
onKeyDown: onTabKeyDown
|
|
1254
1337
|
},
|
|
1255
1338
|
...shown.map(markButton),
|
|
1256
|
-
overflow.length > 0 ? (0,
|
|
1339
|
+
overflow.length > 0 ? (0, import_react6.createElement)(
|
|
1257
1340
|
"button",
|
|
1258
1341
|
{
|
|
1259
1342
|
type: "button",
|
|
@@ -1267,11 +1350,11 @@ function ProviderStrip({
|
|
|
1267
1350
|
"\u22EF"
|
|
1268
1351
|
) : null
|
|
1269
1352
|
),
|
|
1270
|
-
menuOpen && overflow.length > 0 ? (0,
|
|
1353
|
+
menuOpen && overflow.length > 0 ? (0, import_react6.createElement)(
|
|
1271
1354
|
"div",
|
|
1272
1355
|
{ className: "dsh-model-allowance-menu", role: "menu" },
|
|
1273
1356
|
...overflow.map(
|
|
1274
|
-
(entry) => (0,
|
|
1357
|
+
(entry) => (0, import_react6.createElement)(
|
|
1275
1358
|
"button",
|
|
1276
1359
|
{
|
|
1277
1360
|
type: "button",
|
|
@@ -1283,7 +1366,7 @@ function ProviderStrip({
|
|
|
1283
1366
|
setMenuOpen(false);
|
|
1284
1367
|
}
|
|
1285
1368
|
},
|
|
1286
|
-
(0,
|
|
1369
|
+
(0, import_react6.createElement)(
|
|
1287
1370
|
"span",
|
|
1288
1371
|
{
|
|
1289
1372
|
className: "dsh-model-allowance-menu-mark",
|
|
@@ -1291,7 +1374,7 @@ function ProviderStrip({
|
|
|
1291
1374
|
},
|
|
1292
1375
|
providerIcon(entry.route, 11, markFor(entry.route))
|
|
1293
1376
|
),
|
|
1294
|
-
(0,
|
|
1377
|
+
(0, import_react6.createElement)("span", null, nameOf(entry.route))
|
|
1295
1378
|
)
|
|
1296
1379
|
)
|
|
1297
1380
|
) : null
|
|
@@ -1306,6 +1389,7 @@ function BalancePanel({
|
|
|
1306
1389
|
activeProvider,
|
|
1307
1390
|
available,
|
|
1308
1391
|
schedule,
|
|
1392
|
+
promotions,
|
|
1309
1393
|
currentStatus,
|
|
1310
1394
|
serviceState,
|
|
1311
1395
|
refresh,
|
|
@@ -1324,7 +1408,9 @@ function BalancePanel({
|
|
|
1324
1408
|
setStripWidth,
|
|
1325
1409
|
stripRef
|
|
1326
1410
|
}) {
|
|
1327
|
-
|
|
1411
|
+
const activePromotions = promotions?.provider === activeProvider ? (promotions.promotions ?? []).filter((promotion) => promotionActive(promotion, now)) : [];
|
|
1412
|
+
const tipPromotion = catalog.promoTip == null ? void 0 : promotionForModel(activePromotions, catalog.promoTip.model.id);
|
|
1413
|
+
return (0, import_react7.createElement)(
|
|
1328
1414
|
"div",
|
|
1329
1415
|
{
|
|
1330
1416
|
className: "dsh-model-allowance-panel",
|
|
@@ -1334,7 +1420,7 @@ function BalancePanel({
|
|
|
1334
1420
|
},
|
|
1335
1421
|
// With more than one readable provider the card opens a switcher;
|
|
1336
1422
|
// with one there is nothing to switch, so it just names it.
|
|
1337
|
-
available.length > 1 ? (0,
|
|
1423
|
+
available.length > 1 ? (0, import_react7.createElement)(ProviderStrip, {
|
|
1338
1424
|
t,
|
|
1339
1425
|
available,
|
|
1340
1426
|
activeProvider,
|
|
@@ -1346,24 +1432,24 @@ function BalancePanel({
|
|
|
1346
1432
|
stripWidth,
|
|
1347
1433
|
setStripWidth,
|
|
1348
1434
|
stripRef
|
|
1349
|
-
}) : (0,
|
|
1435
|
+
}) : (0, import_react7.createElement)(
|
|
1350
1436
|
"div",
|
|
1351
1437
|
{ className: "dsh-model-allowance-row" },
|
|
1352
|
-
(0,
|
|
1353
|
-
(0,
|
|
1438
|
+
(0, import_react7.createElement)("span", null, t("detail.provider")),
|
|
1439
|
+
(0, import_react7.createElement)("span", null, nameOf(activeProvider))
|
|
1354
1440
|
),
|
|
1355
|
-
view?.kind === "amount" && typeof view.amount === "number" ? (0,
|
|
1441
|
+
view?.kind === "amount" && typeof view.amount === "number" ? (0, import_react7.createElement)(
|
|
1356
1442
|
"div",
|
|
1357
1443
|
{ className: "dsh-model-allowance-row" },
|
|
1358
|
-
(0,
|
|
1359
|
-
(0,
|
|
1444
|
+
(0, import_react7.createElement)("span", null, t("detail.amount")),
|
|
1445
|
+
(0, import_react7.createElement)("span", null, formatAmount(view.amount, view.currency))
|
|
1360
1446
|
) : null,
|
|
1361
1447
|
...Array.isArray(view?.windows) && view.windows.length > 0 ? view.windows.map((window, index) => {
|
|
1362
1448
|
const consumed = windowUsedPercent(window);
|
|
1363
1449
|
const percent = consumed === void 0 ? void 0 : Math.max(0, Math.round(consumed));
|
|
1364
1450
|
const filled = consumed === void 0 ? 0 : Math.min(100, Math.max(0, consumed));
|
|
1365
1451
|
const usage = windowUsage(window, t);
|
|
1366
|
-
return (0,
|
|
1452
|
+
return (0, import_react7.createElement)(
|
|
1367
1453
|
"div",
|
|
1368
1454
|
{
|
|
1369
1455
|
className: "dsh-model-allowance-window",
|
|
@@ -1374,20 +1460,20 @@ function BalancePanel({
|
|
|
1374
1460
|
// *between* windows are drawn.
|
|
1375
1461
|
"data-first": index === 0 ? "true" : void 0
|
|
1376
1462
|
},
|
|
1377
|
-
(0,
|
|
1463
|
+
(0, import_react7.createElement)(
|
|
1378
1464
|
"div",
|
|
1379
1465
|
{ className: "dsh-model-allowance-window-head" },
|
|
1380
|
-
(0,
|
|
1466
|
+
(0, import_react7.createElement)("span", { className: "dsh-model-allowance-window-title" }, windowTitle(window, t)),
|
|
1381
1467
|
// Countable units sit beside the title; a plan that
|
|
1382
1468
|
// reports only a percentage has none to show.
|
|
1383
|
-
usage === void 0 ? null : (0,
|
|
1469
|
+
usage === void 0 ? null : (0, import_react7.createElement)("span", { className: "dsh-model-allowance-usage" }, usage)
|
|
1384
1470
|
),
|
|
1385
|
-
percent === void 0 ? null : (0,
|
|
1471
|
+
percent === void 0 ? null : (0, import_react7.createElement)(
|
|
1386
1472
|
"div",
|
|
1387
1473
|
{ className: "dsh-model-allowance-percent" },
|
|
1388
1474
|
t("window.usedPercent", { percent })
|
|
1389
1475
|
),
|
|
1390
|
-
percent === void 0 ? null : (0,
|
|
1476
|
+
percent === void 0 ? null : (0, import_react7.createElement)(
|
|
1391
1477
|
"div",
|
|
1392
1478
|
{
|
|
1393
1479
|
className: "dsh-model-allowance-bar",
|
|
@@ -1397,7 +1483,7 @@ function BalancePanel({
|
|
|
1397
1483
|
"aria-valuemax": 100,
|
|
1398
1484
|
"aria-valuetext": t("window.usedPercent", { percent })
|
|
1399
1485
|
},
|
|
1400
|
-
(0,
|
|
1486
|
+
(0, import_react7.createElement)("div", {
|
|
1401
1487
|
className: "dsh-model-allowance-bar-fill",
|
|
1402
1488
|
"data-tone": barTone(percent),
|
|
1403
1489
|
style: { width: `${String(filled)}%` }
|
|
@@ -1406,59 +1492,59 @@ function BalancePanel({
|
|
|
1406
1492
|
// A window with zero usage has not started its rolling timer
|
|
1407
1493
|
// yet, so the countdown would be misleading. Hide it until
|
|
1408
1494
|
// consumption begins.
|
|
1409
|
-
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0,
|
|
1495
|
+
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0, import_react7.createElement)(
|
|
1410
1496
|
"div",
|
|
1411
1497
|
{ className: "dsh-model-allowance-foot" },
|
|
1412
|
-
(0,
|
|
1498
|
+
(0, import_react7.createElement)(
|
|
1413
1499
|
"span",
|
|
1414
1500
|
null,
|
|
1415
1501
|
t("window.resetIn", {
|
|
1416
1502
|
duration: formatCountdown(window.resetAt - now)
|
|
1417
1503
|
})
|
|
1418
1504
|
),
|
|
1419
|
-
(0,
|
|
1505
|
+
(0, import_react7.createElement)("span", null, formatResetAt(window.resetAt))
|
|
1420
1506
|
) : null
|
|
1421
1507
|
);
|
|
1422
1508
|
}) : [],
|
|
1423
1509
|
// A single scalar reading has no windows to break down.
|
|
1424
|
-
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0,
|
|
1510
|
+
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0, import_react7.createElement)(
|
|
1425
1511
|
"div",
|
|
1426
1512
|
{ className: "dsh-model-allowance-row" },
|
|
1427
|
-
(0,
|
|
1428
|
-
(0,
|
|
1513
|
+
(0, import_react7.createElement)("span", null, t("detail.remaining")),
|
|
1514
|
+
(0, import_react7.createElement)("span", null, formatDuration(view.remainingMs, t))
|
|
1429
1515
|
) : null,
|
|
1430
|
-
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0,
|
|
1516
|
+
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0, import_react7.createElement)(
|
|
1431
1517
|
"div",
|
|
1432
1518
|
{ className: "dsh-model-allowance-row" },
|
|
1433
|
-
(0,
|
|
1434
|
-
(0,
|
|
1519
|
+
(0, import_react7.createElement)("span", null, t("detail.remaining")),
|
|
1520
|
+
(0, import_react7.createElement)("span", null, String(view.remaining))
|
|
1435
1521
|
) : null,
|
|
1436
|
-
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0,
|
|
1522
|
+
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0, import_react7.createElement)(
|
|
1437
1523
|
"div",
|
|
1438
1524
|
{ className: "dsh-model-allowance-row" },
|
|
1439
|
-
(0,
|
|
1440
|
-
(0,
|
|
1525
|
+
(0, import_react7.createElement)("span", null, t("detail.total")),
|
|
1526
|
+
(0, import_react7.createElement)("span", null, String(view.total))
|
|
1441
1527
|
) : null,
|
|
1442
|
-
view?.status === "failed" ? (0,
|
|
1528
|
+
view?.status === "failed" ? (0, import_react7.createElement)(
|
|
1443
1529
|
"div",
|
|
1444
1530
|
{ className: "dsh-model-allowance-error" },
|
|
1445
1531
|
t("detail.error"),
|
|
1446
1532
|
// The Host reports why a reading failed; showing it is what
|
|
1447
1533
|
// turns "it does not work" into something actionable.
|
|
1448
|
-
view.error ? (0,
|
|
1534
|
+
view.error ? (0, import_react7.createElement)("div", { className: "dsh-model-allowance-reason" }, view.error) : null
|
|
1449
1535
|
) : null,
|
|
1450
|
-
view?.status === "unsupported" ? (0,
|
|
1536
|
+
view?.status === "unsupported" ? (0, import_react7.createElement)(
|
|
1451
1537
|
"div",
|
|
1452
1538
|
{ className: "dsh-model-allowance-reason" },
|
|
1453
1539
|
t("badge.unsupportedWithName", { name: nameOf(activeProvider) })
|
|
1454
1540
|
) : null,
|
|
1455
|
-
view?.status === "unconfigured" ? (0,
|
|
1541
|
+
view?.status === "unconfigured" ? (0, import_react7.createElement)(
|
|
1456
1542
|
"div",
|
|
1457
1543
|
{ className: "dsh-model-allowance-reason" },
|
|
1458
1544
|
t("badge.setupHint"),
|
|
1459
1545
|
// The reading carries the provider's setup guide; it is the walk
|
|
1460
1546
|
// from "no credential" to a stored pair, so it is one click away.
|
|
1461
|
-
view.setupUrl ? (0,
|
|
1547
|
+
view.setupUrl ? (0, import_react7.createElement)(
|
|
1462
1548
|
"a",
|
|
1463
1549
|
{
|
|
1464
1550
|
className: "dsh-model-allowance-setup-link",
|
|
@@ -1472,16 +1558,16 @@ function BalancePanel({
|
|
|
1472
1558
|
// A vendor that prices by the wall clock gets its phase and
|
|
1473
1559
|
// countdown here, above the footer.
|
|
1474
1560
|
schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
|
|
1475
|
-
(0,
|
|
1561
|
+
(0, import_react7.createElement)(
|
|
1476
1562
|
"div",
|
|
1477
1563
|
{ className: "dsh-model-allowance-actions" },
|
|
1478
1564
|
// The platform status sits at the left edge of the footer, on
|
|
1479
1565
|
// the same line as the reading time: the card gains no extra
|
|
1480
1566
|
// row, and the state and the source page stay together.
|
|
1481
|
-
(0,
|
|
1567
|
+
(0, import_react7.createElement)(
|
|
1482
1568
|
"span",
|
|
1483
1569
|
{ className: "dsh-model-allowance-status-wrap" },
|
|
1484
|
-
(0,
|
|
1570
|
+
(0, import_react7.createElement)(
|
|
1485
1571
|
currentStatus?.url ? "a" : "span",
|
|
1486
1572
|
{
|
|
1487
1573
|
className: "dsh-model-allowance-status",
|
|
@@ -1492,17 +1578,17 @@ function BalancePanel({
|
|
|
1492
1578
|
rel: "noreferrer noopener"
|
|
1493
1579
|
} : {}
|
|
1494
1580
|
},
|
|
1495
|
-
(0,
|
|
1581
|
+
(0, import_react7.createElement)("span", {
|
|
1496
1582
|
className: "dsh-model-allowance-status-dot",
|
|
1497
1583
|
"aria-hidden": true
|
|
1498
1584
|
}),
|
|
1499
|
-
(0,
|
|
1585
|
+
(0, import_react7.createElement)(
|
|
1500
1586
|
"span",
|
|
1501
1587
|
{ className: "dsh-model-allowance-status-label" },
|
|
1502
1588
|
statusLabel(serviceState, t)
|
|
1503
1589
|
),
|
|
1504
1590
|
...currentStatus?.url ? [
|
|
1505
|
-
(0,
|
|
1591
|
+
(0, import_react7.createElement)(
|
|
1506
1592
|
"span",
|
|
1507
1593
|
{
|
|
1508
1594
|
className: "dsh-model-allowance-status-arrow",
|
|
@@ -1515,7 +1601,7 @@ function BalancePanel({
|
|
|
1515
1601
|
// The reason is a warning mark rather than another line:
|
|
1516
1602
|
// the footer stays one row, and the detail is one hover
|
|
1517
1603
|
// — or one keyboard focus — away.
|
|
1518
|
-
currentStatus?.summary ? (0,
|
|
1604
|
+
currentStatus?.summary ? (0, import_react7.createElement)(
|
|
1519
1605
|
"span",
|
|
1520
1606
|
{
|
|
1521
1607
|
className: "dsh-model-allowance-status-help",
|
|
@@ -1523,26 +1609,26 @@ function BalancePanel({
|
|
|
1523
1609
|
role: "note",
|
|
1524
1610
|
"aria-label": currentStatus.summary
|
|
1525
1611
|
},
|
|
1526
|
-
(0,
|
|
1612
|
+
(0, import_react7.createElement)(
|
|
1527
1613
|
"span",
|
|
1528
1614
|
{
|
|
1529
1615
|
"aria-hidden": true
|
|
1530
1616
|
},
|
|
1531
1617
|
"!"
|
|
1532
1618
|
),
|
|
1533
|
-
(0,
|
|
1619
|
+
(0, import_react7.createElement)(
|
|
1534
1620
|
"span",
|
|
1535
1621
|
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
1536
1622
|
currentStatus.summary
|
|
1537
1623
|
)
|
|
1538
1624
|
) : null
|
|
1539
1625
|
),
|
|
1540
|
-
view?.updatedAt ? (0,
|
|
1626
|
+
view?.updatedAt ? (0, import_react7.createElement)(
|
|
1541
1627
|
"span",
|
|
1542
1628
|
{ className: "dsh-model-allowance-updated" },
|
|
1543
1629
|
t("detail.updatedAt", { time: formatClock(view.updatedAt) })
|
|
1544
1630
|
) : null,
|
|
1545
|
-
(0,
|
|
1631
|
+
(0, import_react7.createElement)(
|
|
1546
1632
|
"button",
|
|
1547
1633
|
{
|
|
1548
1634
|
type: "button",
|
|
@@ -1554,7 +1640,7 @@ function BalancePanel({
|
|
|
1554
1640
|
},
|
|
1555
1641
|
refreshGlyph(16)
|
|
1556
1642
|
),
|
|
1557
|
-
view?.consoleUrl ? (0,
|
|
1643
|
+
view?.consoleUrl ? (0, import_react7.createElement)(
|
|
1558
1644
|
"a",
|
|
1559
1645
|
{
|
|
1560
1646
|
className: "dsh-model-allowance-icon-button",
|
|
@@ -1569,10 +1655,10 @@ function BalancePanel({
|
|
|
1569
1655
|
// The switch to another model of this provider. It sits to the
|
|
1570
1656
|
// right of the console link, which is the last thing the footer
|
|
1571
1657
|
// offered before, so the two never trade places.
|
|
1572
|
-
canSwitch ? (0,
|
|
1658
|
+
canSwitch ? (0, import_react7.createElement)(
|
|
1573
1659
|
"span",
|
|
1574
1660
|
{ ref: catalog.modelWrapRef, className: "dsh-model-allowance-model-wrap" },
|
|
1575
|
-
(0,
|
|
1661
|
+
(0, import_react7.createElement)(
|
|
1576
1662
|
"button",
|
|
1577
1663
|
{
|
|
1578
1664
|
type: "button",
|
|
@@ -1590,7 +1676,7 @@ function BalancePanel({
|
|
|
1590
1676
|
},
|
|
1591
1677
|
modelGlyph(16)
|
|
1592
1678
|
),
|
|
1593
|
-
catalog.modelMenuOpen ? (0,
|
|
1679
|
+
catalog.modelMenuOpen ? (0, import_react7.createElement)(ModelMenu, {
|
|
1594
1680
|
t,
|
|
1595
1681
|
models: catalog.shownModelList,
|
|
1596
1682
|
state: catalog.shownModelListState,
|
|
@@ -1600,12 +1686,15 @@ function BalancePanel({
|
|
|
1600
1686
|
switchToModel: catalog.switchToModel,
|
|
1601
1687
|
modelWrapRef: catalog.modelWrapRef,
|
|
1602
1688
|
showEffortFlyout: catalog.showEffortFlyout,
|
|
1603
|
-
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1689
|
+
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose,
|
|
1690
|
+
promotions: activePromotions,
|
|
1691
|
+
showPromoTip: catalog.showPromoTip,
|
|
1692
|
+
hidePromoTip: catalog.hidePromoTip
|
|
1604
1693
|
}) : null,
|
|
1605
1694
|
// The effort flyout is a sibling of the list, not a
|
|
1606
1695
|
// child: the list scrolls, and a nested panel would be
|
|
1607
1696
|
// clipped by it.
|
|
1608
|
-
catalog.modelMenuOpen && catalog.hoverModel !== null && catalog.shownModelList.includes(catalog.hoverModel.model) ? (0,
|
|
1697
|
+
catalog.modelMenuOpen && catalog.hoverModel !== null && catalog.shownModelList.includes(catalog.hoverModel.model) ? (0, import_react7.createElement)(EffortFlyout, {
|
|
1609
1698
|
t,
|
|
1610
1699
|
hoverModel: catalog.hoverModel,
|
|
1611
1700
|
currentModel: catalog.currentModel,
|
|
@@ -1614,7 +1703,11 @@ function BalancePanel({
|
|
|
1614
1703
|
switchToModel: catalog.switchToModel,
|
|
1615
1704
|
keepEffortFlyout: catalog.keepEffortFlyout,
|
|
1616
1705
|
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1617
|
-
}) : null
|
|
1706
|
+
}) : null,
|
|
1707
|
+
// The badge's tip is a sibling of the list for the same reason
|
|
1708
|
+
// the flyout is: the list scrolls, and a nested hint would be
|
|
1709
|
+
// clipped by it.
|
|
1710
|
+
catalog.modelMenuOpen && catalog.promoTip != null && tipPromotion !== void 0 && catalog.shownModelList.some((model) => model.id === catalog.promoTip.model.id) ? promoTipView(tipPromotion, catalog.promoTip) : null
|
|
1618
1711
|
) : null
|
|
1619
1712
|
)
|
|
1620
1713
|
);
|
|
@@ -1782,6 +1875,7 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1782
1875
|
const [modelMenuOpen, setModelMenuOpen] = React5.useState(false);
|
|
1783
1876
|
const [hoverModel, setHoverModel] = React5.useState(null);
|
|
1784
1877
|
const hoverModelTimer = React5.useRef(null);
|
|
1878
|
+
const [promoTip, setPromoTip] = React5.useState(null);
|
|
1785
1879
|
const [switchingModel, setSwitchingModel] = React5.useState(null);
|
|
1786
1880
|
const modelWrapRef = React5.useRef(null);
|
|
1787
1881
|
const catalogRef = React5.useRef({ value: null, at: 0 });
|
|
@@ -1896,10 +1990,25 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1896
1990
|
const keepEffortFlyout = React5.useCallback(() => {
|
|
1897
1991
|
clearTimeout(hoverModelTimer.current);
|
|
1898
1992
|
}, []);
|
|
1993
|
+
const showPromoTip = React5.useCallback((model, event) => {
|
|
1994
|
+
const wrap = modelWrapRef.current;
|
|
1995
|
+
if (!wrap) return;
|
|
1996
|
+
const chip = event.currentTarget.getBoundingClientRect();
|
|
1997
|
+
const wrapRect = wrap.getBoundingClientRect();
|
|
1998
|
+
setPromoTip({
|
|
1999
|
+
model,
|
|
2000
|
+
bottom: wrapRect.bottom - chip.top + 6,
|
|
2001
|
+
right: wrapRect.right - chip.right
|
|
2002
|
+
});
|
|
2003
|
+
}, []);
|
|
2004
|
+
const hidePromoTip = React5.useCallback(() => {
|
|
2005
|
+
setPromoTip(null);
|
|
2006
|
+
}, []);
|
|
1899
2007
|
const toggleModelMenu = React5.useCallback(() => {
|
|
1900
2008
|
setModelError(null);
|
|
1901
2009
|
clearTimeout(hoverModelTimer.current);
|
|
1902
2010
|
setHoverModel(null);
|
|
2011
|
+
setPromoTip(null);
|
|
1903
2012
|
setModelMenuOpen((value) => !value);
|
|
1904
2013
|
}, []);
|
|
1905
2014
|
const modelProvider = catalogProvider ?? activeProvider;
|
|
@@ -1920,6 +2029,9 @@ function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection
|
|
|
1920
2029
|
showEffortFlyout,
|
|
1921
2030
|
scheduleEffortFlyoutClose,
|
|
1922
2031
|
keepEffortFlyout,
|
|
2032
|
+
promoTip,
|
|
2033
|
+
showPromoTip,
|
|
2034
|
+
hidePromoTip,
|
|
1923
2035
|
toggleModelMenu,
|
|
1924
2036
|
switchToModel
|
|
1925
2037
|
};
|
|
@@ -2054,8 +2166,12 @@ var STYLES = [
|
|
|
2054
2166
|
// through the model names. A solid layer keeps the list readable wherever
|
|
2055
2167
|
// it opens.
|
|
2056
2168
|
".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
|
|
2169
|
+
// The list sizes itself to its content: a model name is always shown in
|
|
2170
|
+
// full, and the menu widens to fit it rather than truncating. Only the
|
|
2171
|
+
// viewport caps the width; a long list still scrolls vertically.
|
|
2057
2172
|
".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
|
|
2058
|
-
"min-width:180px;max-width:
|
|
2173
|
+
"width:max-content;min-width:180px;max-width:calc(100vw - 24px);",
|
|
2174
|
+
"max-height:240px;overflow-y:auto;padding:4px;border:0;",
|
|
2059
2175
|
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
2060
2176
|
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
2061
2177
|
".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
|
|
@@ -2066,7 +2182,7 @@ var STYLES = [
|
|
|
2066
2182
|
// would give the chip a second meaning it does not have.
|
|
2067
2183
|
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
2068
2184
|
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
2069
|
-
".dsh-model-allowance-model-name{
|
|
2185
|
+
".dsh-model-allowance-model-name{white-space:nowrap}",
|
|
2070
2186
|
// The trailing side of a model row carries its state label and, for a
|
|
2071
2187
|
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
2072
2188
|
// the right.
|
|
@@ -2092,6 +2208,25 @@ var STYLES = [
|
|
|
2092
2208
|
// The trailing label names the state of one model: the one in use, or the
|
|
2093
2209
|
// one being switched to.
|
|
2094
2210
|
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
2211
|
+
// A running promotion marks its model with a small multiplier badge beside
|
|
2212
|
+
// the name — the card's only statement of the event. The business hue says
|
|
2213
|
+
// "offer" without borrowing the success green the allowance bars speak;
|
|
2214
|
+
// the badge paints its own colour, so the dimmed current row still shows it.
|
|
2215
|
+
".dsh-model-allowance-promo-chip{display:inline-flex;align-items:center;flex:none;",
|
|
2216
|
+
"padding:0 5px;border-radius:999px;height:16px;font-size:10px;font-weight:600;line-height:1;",
|
|
2217
|
+
"color:var(--dsw-alias-state-business-primary);",
|
|
2218
|
+
"background:color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent)}",
|
|
2219
|
+
// The auto margin belongs to the menu row: it keeps name and badge together
|
|
2220
|
+
// at the left while the state label stays at the right edge.
|
|
2221
|
+
".dsh-model-allowance-model-item .dsh-model-allowance-promo-chip{margin-right:auto}",
|
|
2222
|
+
// The badge's hover tip reads the vendor's one-line announcement on the
|
|
2223
|
+
// card's shared tooltip surface. A sibling of the scrolling menu, so
|
|
2224
|
+
// nothing clips it; pointer-events:none keeps it a pure hint.
|
|
2225
|
+
".dsh-model-allowance-promo-tip{position:absolute;z-index:32;width:max-content;",
|
|
2226
|
+
"max-width:240px;padding:6px 8px;border:0;border-radius:var(--dsw-radius-sm);",
|
|
2227
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
2228
|
+
"font-size:11px;line-height:1.5;color:var(--dsw-static-neutral-bluish-00);",
|
|
2229
|
+
"pointer-events:none;white-space:normal;text-align:left}",
|
|
2095
2230
|
// A message covers the whole list: it loads, it is empty, or the switch
|
|
2096
2231
|
// failed and says why.
|
|
2097
2232
|
".dsh-model-allowance-model-message{padding:4px 6px;color:var(--dsw-alias-label-secondary);",
|
|
@@ -2291,6 +2426,7 @@ function BalanceBadge(props) {
|
|
|
2291
2426
|
}, [open]);
|
|
2292
2427
|
const [stripWidth, setStripWidth] = React6.useState(0);
|
|
2293
2428
|
const stripRef = React6.useRef(null);
|
|
2429
|
+
const [promotions, setPromotions] = React6.useState(null);
|
|
2294
2430
|
const { available, defaultProvider, entryOf, nameOf } = useProviderDirectory(selected);
|
|
2295
2431
|
const provider = selected ?? defaultProvider;
|
|
2296
2432
|
const activeProvider = picked ?? provider;
|
|
@@ -2324,17 +2460,18 @@ function BalanceBadge(props) {
|
|
|
2324
2460
|
React6.useEffect(() => {
|
|
2325
2461
|
if (!activeProvider) return void 0;
|
|
2326
2462
|
let cancelled = false;
|
|
2327
|
-
|
|
2463
|
+
const readDeclaration = async (method, apply2, label2) => {
|
|
2328
2464
|
try {
|
|
2329
2465
|
const api = await getBalanceApi();
|
|
2330
|
-
if (!api || typeof api
|
|
2331
|
-
const result = await api
|
|
2332
|
-
if (cancelled
|
|
2333
|
-
setSchedule(result.value);
|
|
2466
|
+
if (!api || typeof api[method] !== "function") return;
|
|
2467
|
+
const result = await api[method](activeProvider);
|
|
2468
|
+
if (!cancelled && result.ok) apply2(result.value);
|
|
2334
2469
|
} catch (error) {
|
|
2335
|
-
console.error(
|
|
2470
|
+
console.error(`[model-allowance] reading the ${label2} failed`, { error });
|
|
2336
2471
|
}
|
|
2337
|
-
}
|
|
2472
|
+
};
|
|
2473
|
+
void readDeclaration("schedule", setSchedule, "pricing schedule");
|
|
2474
|
+
void readDeclaration("promotions", setPromotions, "usage promotions");
|
|
2338
2475
|
return () => {
|
|
2339
2476
|
cancelled = true;
|
|
2340
2477
|
};
|
|
@@ -2418,7 +2555,7 @@ function BalanceBadge(props) {
|
|
|
2418
2555
|
if (!provider) return null;
|
|
2419
2556
|
const currentStatus = providerStatus?.provider === activeProvider ? providerStatus : null;
|
|
2420
2557
|
const serviceState = statusDisplayState(currentStatus);
|
|
2421
|
-
return (0,
|
|
2558
|
+
return (0, import_react8.createElement)(
|
|
2422
2559
|
"div",
|
|
2423
2560
|
{
|
|
2424
2561
|
ref: rootRef,
|
|
@@ -2428,8 +2565,8 @@ function BalanceBadge(props) {
|
|
|
2428
2565
|
},
|
|
2429
2566
|
// Component-local styles: React removes them with the component, and
|
|
2430
2567
|
// every colour comes from a theme token so light and dark both follow.
|
|
2431
|
-
(0,
|
|
2432
|
-
(0,
|
|
2568
|
+
(0, import_react8.createElement)("style", { key: "styles" }, STYLES_JOINED),
|
|
2569
|
+
(0, import_react8.createElement)(
|
|
2433
2570
|
"button",
|
|
2434
2571
|
{
|
|
2435
2572
|
type: "button",
|
|
@@ -2439,12 +2576,12 @@ function BalanceBadge(props) {
|
|
|
2439
2576
|
"aria-controls": open ? "dsh-model-allowance-panel" : void 0,
|
|
2440
2577
|
onClick: () => setOpen((value) => !value)
|
|
2441
2578
|
},
|
|
2442
|
-
(0,
|
|
2443
|
-
(0,
|
|
2579
|
+
(0, import_react8.createElement)("span", { className: "dsh-model-allowance-dot", "aria-hidden": true }),
|
|
2580
|
+
(0, import_react8.createElement)("span", { className: "dsh-model-allowance-label" }, label),
|
|
2444
2581
|
// How far the number moved since the last reading, for a few seconds
|
|
2445
2582
|
// after it lands. The arrow follows the number shown beside it: down
|
|
2446
2583
|
// means the balance fell.
|
|
2447
|
-
showingDifference ? (0,
|
|
2584
|
+
showingDifference ? (0, import_react8.createElement)(
|
|
2448
2585
|
"span",
|
|
2449
2586
|
{
|
|
2450
2587
|
className: "dsh-model-allowance-delta",
|
|
@@ -2454,13 +2591,14 @@ function BalanceBadge(props) {
|
|
|
2454
2591
|
`${view.consumption.delta < 0 ? "\u2193" : "\u2191"}${formatDelta(view.consumption)}`
|
|
2455
2592
|
) : null
|
|
2456
2593
|
),
|
|
2457
|
-
open ? (0,
|
|
2594
|
+
open ? (0, import_react8.createElement)(BalancePanel, {
|
|
2458
2595
|
t,
|
|
2459
2596
|
now,
|
|
2460
2597
|
view,
|
|
2461
2598
|
activeProvider,
|
|
2462
2599
|
available,
|
|
2463
2600
|
schedule,
|
|
2601
|
+
promotions,
|
|
2464
2602
|
currentStatus,
|
|
2465
2603
|
serviceState,
|
|
2466
2604
|
refresh,
|
|
@@ -2547,6 +2685,21 @@ function createBalanceContribution() {
|
|
|
2547
2685
|
holidays: z.array(z.string()).optional(),
|
|
2548
2686
|
note: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional()
|
|
2549
2687
|
}).nullable();
|
|
2688
|
+
const promotionSchema = z.object({
|
|
2689
|
+
models: z.array(z.string()),
|
|
2690
|
+
chip: z.object({ zh: z.string().optional(), en: z.string().optional() }),
|
|
2691
|
+
note: z.object({ zh: z.string().optional(), en: z.string().optional() }),
|
|
2692
|
+
// A static declaration carries a date window; a live catalog read may
|
|
2693
|
+
// carry a daily one (a night offer badges only at night), or none at all.
|
|
2694
|
+
timezone: z.string().optional(),
|
|
2695
|
+
from: z.string().optional(),
|
|
2696
|
+
to: z.string().optional(),
|
|
2697
|
+
daily: z.object({ from: z.string(), to: z.string() }).optional()
|
|
2698
|
+
});
|
|
2699
|
+
const promotionsSchema = z.object({
|
|
2700
|
+
provider: z.string(),
|
|
2701
|
+
promotions: z.array(promotionSchema)
|
|
2702
|
+
}).nullable();
|
|
2550
2703
|
const strict = (schema, description, typeSymbol) => ({
|
|
2551
2704
|
mode: "strict",
|
|
2552
2705
|
typeSymbol,
|
|
@@ -2686,6 +2839,17 @@ function createBalanceContribution() {
|
|
|
2686
2839
|
invocation: { kind: "direct" },
|
|
2687
2840
|
parameters: [providerParameter],
|
|
2688
2841
|
result: strict(scheduleSchema, "The schedule, or null.", "dsh-model-allowance#schedule")
|
|
2842
|
+
},
|
|
2843
|
+
"balance/promotions": {
|
|
2844
|
+
service: "balanceController",
|
|
2845
|
+
description: "The model-scoped usage promotions for one provider, when it declares any.",
|
|
2846
|
+
invocation: { kind: "direct" },
|
|
2847
|
+
parameters: [providerParameter],
|
|
2848
|
+
result: strict(
|
|
2849
|
+
promotionsSchema,
|
|
2850
|
+
"The promotions, or null.",
|
|
2851
|
+
"dsh-model-allowance#promotions"
|
|
2852
|
+
)
|
|
2689
2853
|
}
|
|
2690
2854
|
}
|
|
2691
2855
|
};
|
|
@@ -2693,7 +2857,7 @@ function createBalanceContribution() {
|
|
|
2693
2857
|
|
|
2694
2858
|
// src/client/credentials-page.js
|
|
2695
2859
|
var React7 = __toESM(require("react"), 1);
|
|
2696
|
-
var
|
|
2860
|
+
var import_react9 = require("react");
|
|
2697
2861
|
|
|
2698
2862
|
// src/client/credential-groups.js
|
|
2699
2863
|
var CREDENTIAL_GROUPS = Object.freeze([
|
|
@@ -2887,10 +3051,10 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2887
3051
|
};
|
|
2888
3052
|
const renderField = (field, editMode) => {
|
|
2889
3053
|
const info = infos?.[field.ref];
|
|
2890
|
-
return (0,
|
|
3054
|
+
return (0, import_react9.createElement)(
|
|
2891
3055
|
"div",
|
|
2892
3056
|
{ key: field.ref, className: "dsh-allowance-cfg-field" },
|
|
2893
|
-
(0,
|
|
3057
|
+
(0, import_react9.createElement)(
|
|
2894
3058
|
editMode ? "label" : "div",
|
|
2895
3059
|
{
|
|
2896
3060
|
className: "dsh-allowance-cfg-field-label",
|
|
@@ -2898,7 +3062,7 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2898
3062
|
},
|
|
2899
3063
|
pick(field.label)
|
|
2900
3064
|
),
|
|
2901
|
-
editMode ? (0,
|
|
3065
|
+
editMode ? (0, import_react9.createElement)("input", {
|
|
2902
3066
|
id: `dsh-allowance-cfg-${field.ref}`,
|
|
2903
3067
|
className: "dsh-allowance-cfg-input",
|
|
2904
3068
|
type: "password",
|
|
@@ -2910,7 +3074,7 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2910
3074
|
}) : (
|
|
2911
3075
|
// A stored record reads as text, not as a box that mimics the
|
|
2912
3076
|
// entry form: the two states must be told apart at a glance.
|
|
2913
|
-
(0,
|
|
3077
|
+
(0, import_react9.createElement)(
|
|
2914
3078
|
"span",
|
|
2915
3079
|
{ className: "dsh-allowance-cfg-text" },
|
|
2916
3080
|
typeof info?.masked === "string" && info.masked !== "" ? info.masked : "********"
|
|
@@ -2921,18 +3085,18 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2921
3085
|
const renderGroup = (group) => {
|
|
2922
3086
|
const allStored = group.fields.every((field) => infos?.[field.ref]?.configured === true);
|
|
2923
3087
|
const editMode = !allStored || editing[group.id] === true;
|
|
2924
|
-
return (0,
|
|
3088
|
+
return (0, import_react9.createElement)(
|
|
2925
3089
|
"section",
|
|
2926
3090
|
{ key: group.id, className: "dsh-allowance-cfg-card" },
|
|
2927
|
-
(0,
|
|
3091
|
+
(0, import_react9.createElement)(
|
|
2928
3092
|
"div",
|
|
2929
3093
|
{ className: "dsh-allowance-cfg-card-head" },
|
|
2930
|
-
(0,
|
|
3094
|
+
(0, import_react9.createElement)("h3", { className: "dsh-allowance-cfg-card-title" }, pick(group.name)),
|
|
2931
3095
|
// The stored state names itself, so the card reads as configured or
|
|
2932
3096
|
// as a form to fill without reading any field.
|
|
2933
|
-
allStored ? (0,
|
|
3097
|
+
allStored ? (0, import_react9.createElement)("span", { className: "dsh-allowance-cfg-status" }, t("settings.configured")) : null
|
|
2934
3098
|
),
|
|
2935
|
-
group.docUrl ? (0,
|
|
3099
|
+
group.docUrl ? (0, import_react9.createElement)(
|
|
2936
3100
|
"a",
|
|
2937
3101
|
{
|
|
2938
3102
|
className: "dsh-allowance-cfg-link",
|
|
@@ -2943,10 +3107,10 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2943
3107
|
`${group.docLabel ? pick(group.docLabel) : t("settings.doc")} \u2197`
|
|
2944
3108
|
) : null,
|
|
2945
3109
|
group.fields.map((field) => renderField(field, editMode)),
|
|
2946
|
-
(0,
|
|
3110
|
+
(0, import_react9.createElement)(
|
|
2947
3111
|
"div",
|
|
2948
3112
|
{ className: "dsh-allowance-cfg-actions" },
|
|
2949
|
-
editMode ? (0,
|
|
3113
|
+
editMode ? (0, import_react9.createElement)(
|
|
2950
3114
|
"button",
|
|
2951
3115
|
{
|
|
2952
3116
|
type: "button",
|
|
@@ -2957,7 +3121,7 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2957
3121
|
},
|
|
2958
3122
|
busy ? t("settings.testing") : t("settings.save")
|
|
2959
3123
|
) : [
|
|
2960
|
-
(0,
|
|
3124
|
+
(0, import_react9.createElement)(
|
|
2961
3125
|
"button",
|
|
2962
3126
|
{
|
|
2963
3127
|
type: "button",
|
|
@@ -2969,7 +3133,7 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2969
3133
|
},
|
|
2970
3134
|
t("settings.edit")
|
|
2971
3135
|
),
|
|
2972
|
-
(0,
|
|
3136
|
+
(0, import_react9.createElement)(
|
|
2973
3137
|
"button",
|
|
2974
3138
|
{
|
|
2975
3139
|
type: "button",
|
|
@@ -2982,7 +3146,7 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2982
3146
|
t("settings.delete")
|
|
2983
3147
|
)
|
|
2984
3148
|
],
|
|
2985
|
-
allStored && editMode ? (0,
|
|
3149
|
+
allStored && editMode ? (0, import_react9.createElement)(
|
|
2986
3150
|
"button",
|
|
2987
3151
|
{
|
|
2988
3152
|
type: "button",
|
|
@@ -2996,17 +3160,17 @@ function CredentialsSection({ ctx, t }) {
|
|
|
2996
3160
|
)
|
|
2997
3161
|
);
|
|
2998
3162
|
};
|
|
2999
|
-
return (0,
|
|
3163
|
+
return (0, import_react9.createElement)(
|
|
3000
3164
|
React7.Fragment,
|
|
3001
3165
|
null,
|
|
3002
3166
|
// Component-local styles: React removes them with the component.
|
|
3003
|
-
(0,
|
|
3004
|
-
(0,
|
|
3167
|
+
(0, import_react9.createElement)("style", { key: "styles" }, STYLES2),
|
|
3168
|
+
(0, import_react9.createElement)(
|
|
3005
3169
|
"div",
|
|
3006
3170
|
{ className: "dsh-allowance-cfg" },
|
|
3007
|
-
(0,
|
|
3008
|
-
credentials === void 0 ? (0,
|
|
3009
|
-
notice === void 0 ? null : (0,
|
|
3171
|
+
(0, import_react9.createElement)("h2", { className: "dsh-allowance-cfg-title" }, t("settings.title")),
|
|
3172
|
+
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)),
|
|
3173
|
+
notice === void 0 ? null : (0, import_react9.createElement)(
|
|
3010
3174
|
"p",
|
|
3011
3175
|
{
|
|
3012
3176
|
key: "notice",
|
|
@@ -3083,7 +3247,7 @@ function apply(ctx) {
|
|
|
3083
3247
|
id: "model-allowance",
|
|
3084
3248
|
order: 10
|
|
3085
3249
|
},
|
|
3086
|
-
(props) => (0,
|
|
3250
|
+
(props) => (0, import_react10.createElement)(BalanceBadge, { ...props, ctx, t })
|
|
3087
3251
|
)
|
|
3088
3252
|
);
|
|
3089
3253
|
const SECTION = "settings.section";
|
|
@@ -3096,7 +3260,7 @@ function apply(ctx) {
|
|
|
3096
3260
|
order: 30,
|
|
3097
3261
|
label: () => t("settings.nav")
|
|
3098
3262
|
},
|
|
3099
|
-
(props) => (0,
|
|
3263
|
+
(props) => (0, import_react10.createElement)(CredentialsSection, { ...props, ctx, t })
|
|
3100
3264
|
)
|
|
3101
3265
|
);
|
|
3102
3266
|
}
|