dsh-model-allowance 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +147 -2
- package/README.zh.md +128 -0
- package/client.js +1897 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/index.js +457 -0
- package/lib/balance.js +413 -0
- package/lib/credentials.js +174 -0
- package/lib/debug.js +70 -0
- package/lib/providers/deepseek.js +408 -0
- package/lib/providers/kimi.js +474 -0
- package/lib/providers/minimax.js +383 -0
- package/lib/providers/opencode.js +209 -0
- package/lib/providers/schedule.js +153 -0
- package/lib/providers/shared.js +324 -0
- package/lib/providers/status.js +133 -0
- package/lib/providers/zhipu.js +185 -0
- package/lib/providers.js +112 -0
- package/lib/remote.js +214 -0
- package/lib/status.js +196 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +82 -4
package/client.js
ADDED
|
@@ -0,0 +1,1897 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated from src/client by tools/build-client.mjs.
|
|
3
|
+
* Do not edit this file; edit the source modules and run `npm run build`.
|
|
4
|
+
*/
|
|
5
|
+
window.__ModuleLoader__.load({
|
|
6
|
+
id: 'dsh-model-allowance',
|
|
7
|
+
factory(require) {
|
|
8
|
+
const module = { exports: {} }
|
|
9
|
+
;(function (module, exports, require) {
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
|
|
38
|
+
// src/client/index.js
|
|
39
|
+
var index_exports = {};
|
|
40
|
+
__export(index_exports, {
|
|
41
|
+
apply: () => apply,
|
|
42
|
+
inject: () => inject
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
var import_react4 = require("react");
|
|
46
|
+
|
|
47
|
+
// src/client/badge.js
|
|
48
|
+
var React = __toESM(require("react"), 1);
|
|
49
|
+
var import_react3 = require("react");
|
|
50
|
+
|
|
51
|
+
// src/client/format.js
|
|
52
|
+
var CURRENCY_SYMBOLS = {
|
|
53
|
+
CNY: "\xA5",
|
|
54
|
+
USD: "$",
|
|
55
|
+
EUR: "\u20AC",
|
|
56
|
+
GBP: "\xA3",
|
|
57
|
+
JPY: "\xA5",
|
|
58
|
+
KRW: "\u20A9"
|
|
59
|
+
};
|
|
60
|
+
function formatAmount(amount, currency) {
|
|
61
|
+
const value = Math.abs(amount) >= 0.01 ? amount.toFixed(2) : amount.toFixed(4);
|
|
62
|
+
const code = typeof currency === "string" && currency !== "" ? currency : "CNY";
|
|
63
|
+
const symbol = CURRENCY_SYMBOLS[code];
|
|
64
|
+
return symbol === void 0 ? `${code} ${value}` : `${symbol}${value}`;
|
|
65
|
+
}
|
|
66
|
+
function formatDuration(ms, t) {
|
|
67
|
+
if (!Number.isFinite(ms) || ms < 0) return "\u2014";
|
|
68
|
+
const totalMinutes = Math.round(ms / 6e4);
|
|
69
|
+
const days = Math.floor(totalMinutes / 1440);
|
|
70
|
+
const hours = Math.floor(totalMinutes % 1440 / 60);
|
|
71
|
+
const minutes = totalMinutes % 60;
|
|
72
|
+
if (days > 0) return t("duration.daysHours", { days, hours });
|
|
73
|
+
if (hours > 0) return t("duration.hoursMinutes", { hours, minutes });
|
|
74
|
+
if (minutes > 0) return t("duration.minutes", { minutes });
|
|
75
|
+
return t("duration.lessThanMinute");
|
|
76
|
+
}
|
|
77
|
+
function formatResetAt(epochMs) {
|
|
78
|
+
const at = new Date(epochMs);
|
|
79
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
80
|
+
return `${String(at.getFullYear())}-${pad(at.getMonth() + 1)}-${pad(at.getDate())} ${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;
|
|
81
|
+
}
|
|
82
|
+
function formatNumber(value) {
|
|
83
|
+
return Number.isInteger(value) ? value.toLocaleString() : String(value);
|
|
84
|
+
}
|
|
85
|
+
var CONSUMPTION_MS = 10 * 1e3;
|
|
86
|
+
var STATUS_REFRESH_MS = 60 * 1e3;
|
|
87
|
+
function consumptionFreshAt(consumption, now) {
|
|
88
|
+
if (!consumption) return false;
|
|
89
|
+
if (!Number.isFinite(consumption.delta)) return false;
|
|
90
|
+
if (formatDelta(consumption) === "") return false;
|
|
91
|
+
return now - consumption.at < CONSUMPTION_MS;
|
|
92
|
+
}
|
|
93
|
+
function formatDelta(consumption) {
|
|
94
|
+
const magnitude = Math.abs(consumption.delta);
|
|
95
|
+
if (consumption.kind === "percent") {
|
|
96
|
+
if (magnitude >= 0.95) return `${String(Math.round(magnitude))}%`;
|
|
97
|
+
if (magnitude >= 0.05) return `${magnitude.toFixed(1)}%`;
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
const value = magnitude >= 0.01 ? magnitude.toFixed(2) : magnitude.toFixed(4);
|
|
101
|
+
return Number(value) === 0 ? "" : value;
|
|
102
|
+
}
|
|
103
|
+
function formatClock(epochMs) {
|
|
104
|
+
const at = new Date(epochMs);
|
|
105
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
106
|
+
return `${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/client/icons.js
|
|
110
|
+
var import_react = require("react");
|
|
111
|
+
function refreshGlyph(size) {
|
|
112
|
+
return (0, import_react.createElement)(
|
|
113
|
+
"svg",
|
|
114
|
+
{ viewBox: "0 0 20 20", width: size, height: size, "aria-hidden": "true", focusable: "false" },
|
|
115
|
+
(0, import_react.createElement)("path", {
|
|
116
|
+
d: "M12.05 4.36A6 6 0 1 1 7.95 4.36",
|
|
117
|
+
fill: "none",
|
|
118
|
+
stroke: "currentColor",
|
|
119
|
+
strokeWidth: 1.7,
|
|
120
|
+
strokeLinecap: "round"
|
|
121
|
+
}),
|
|
122
|
+
(0, import_react.createElement)("path", {
|
|
123
|
+
d: "M15.05 5.45L10.48 6.35L12.12 1.83Z",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
stroke: "currentColor",
|
|
126
|
+
strokeWidth: 0.6,
|
|
127
|
+
strokeLinejoin: "round"
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
function consoleGlyph(size) {
|
|
132
|
+
return (0, import_react.createElement)(
|
|
133
|
+
"svg",
|
|
134
|
+
{ viewBox: "0 0 20 20", width: size, height: size, "aria-hidden": "true", focusable: "false" },
|
|
135
|
+
(0, import_react.createElement)("rect", {
|
|
136
|
+
x: 3.4,
|
|
137
|
+
y: 4.2,
|
|
138
|
+
width: 13.2,
|
|
139
|
+
height: 11.6,
|
|
140
|
+
rx: 2,
|
|
141
|
+
fill: "none",
|
|
142
|
+
stroke: "currentColor",
|
|
143
|
+
strokeWidth: 1.6
|
|
144
|
+
}),
|
|
145
|
+
(0, import_react.createElement)("path", {
|
|
146
|
+
d: "M3.4 8.1h13.2",
|
|
147
|
+
fill: "none",
|
|
148
|
+
stroke: "currentColor",
|
|
149
|
+
strokeWidth: 1.6
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
var DEEPSEEK_PATH = "M48.8354 10.0479C48.3232 9.79199 48.1025 10.2798 47.8032 10.5278C47.7007 10.6079 47.6143 10.7119 47.5273 10.8076C46.7793 11.624 45.9048 12.1597 44.7622 12.0957C43.0923 12 41.666 12.5356 40.4058 13.8398C40.1377 12.2319 39.2476 11.272 37.8926 10.6558C37.1836 10.3359 36.4668 10.0156 35.9702 9.31982C35.6235 8.82373 35.5293 8.27197 35.356 7.72754C35.2456 7.3999 35.1353 7.06396 34.7651 7.00781C34.3633 6.94385 34.2056 7.2876 34.0479 7.57568C33.418 8.75195 33.1733 10.0479 33.1973 11.3599C33.2524 14.312 34.4736 16.6641 36.8999 18.3359C37.1758 18.5278 37.2466 18.7197 37.1597 19C36.9946 19.5757 36.7974 20.1357 36.624 20.7119C36.5137 21.0801 36.3486 21.1597 35.9624 21C34.6309 20.4321 33.481 19.5918 32.4644 18.5757C30.7393 16.8721 29.1792 14.9917 27.2334 13.52C26.7764 13.1758 26.3193 12.856 25.8467 12.5518C23.8618 10.584 26.1069 8.96777 26.627 8.77588C27.1704 8.57568 26.8159 7.8877 25.0591 7.896C23.3022 7.90381 21.6953 8.50391 19.647 9.30371C19.3477 9.42383 19.0322 9.51172 18.7095 9.58398C16.8501 9.22363 14.9199 9.14355 12.9033 9.37598C9.10596 9.80762 6.07275 11.6396 3.84326 14.7681C1.16455 18.5278 0.53418 22.7998 1.30664 27.2559C2.11768 31.9521 4.46582 35.8398 8.07373 38.8799C11.8159 42.0322 16.1255 43.5762 21.041 43.2803C24.0269 43.104 27.3516 42.6963 31.1016 39.4561C32.0469 39.936 33.0396 40.1279 34.686 40.272C35.9546 40.3921 37.1758 40.208 38.1211 40.0078C39.6021 39.688 39.4995 38.2881 38.9639 38.0322C34.623 35.9678 35.5762 36.8081 34.71 36.1279C36.9155 33.4639 40.2402 30.6958 41.54 21.728C41.6426 21.0161 41.5557 20.5679 41.54 19.9917C41.5322 19.6396 41.6108 19.5039 42.0049 19.4639C43.0923 19.3359 44.1479 19.0317 45.1167 18.4878C47.9292 16.9199 49.064 14.3438 49.3315 11.2559C49.3711 10.7837 49.3237 10.2959 48.8354 10.0479ZM24.3262 37.8398C20.1196 34.4639 18.0791 33.3521 17.2358 33.3999C16.4482 33.4482 16.5898 34.3682 16.7632 34.9678C16.9443 35.5601 17.1812 35.9683 17.5117 36.4878C17.7402 36.832 17.8979 37.3442 17.2832 37.728C15.9282 38.584 13.5728 37.4399 13.4624 37.3838C10.7207 35.7358 8.42822 33.5601 6.81348 30.584C5.25342 27.7197 4.34766 24.6479 4.19775 21.3677C4.1582 20.5757 4.38672 20.2959 5.15869 20.1519C6.17529 19.96 7.22314 19.9199 8.23926 20.0718C12.5327 20.7119 16.1885 22.6719 19.2529 25.7759C21.002 27.5439 22.3252 29.6558 23.6885 31.7202C25.1377 33.9121 26.6978 36 28.6831 37.7119C29.3843 38.312 29.9434 38.7681 30.479 39.104C28.8643 39.2881 26.1699 39.3281 24.3262 37.8398ZM26.3433 24.6001C26.3433 24.248 26.6191 23.9678 26.9658 23.9678C27.0444 23.9678 27.1152 23.9839 27.1782 24.0078C27.2651 24.04 27.3438 24.0879 27.4067 24.1602C27.5171 24.272 27.5801 24.4321 27.5801 24.6001C27.5801 24.9521 27.3042 25.2319 26.9575 25.2319C26.6108 25.2319 26.3433 24.9521 26.3433 24.6001ZM32.6064 27.8799C32.2046 28.0479 31.8027 28.1919 31.4165 28.208C30.8179 28.2397 30.1641 27.9922 29.8096 27.688C29.2583 27.2158 28.8643 26.9521 28.6987 26.1279C28.6279 25.7759 28.6675 25.2319 28.7305 24.9199C28.8721 24.248 28.7144 23.8159 28.2495 23.4238C27.8716 23.104 27.3911 23.0161 26.8633 23.0161C26.666 23.0161 26.4849 22.9277 26.3511 22.856C26.1304 22.7441 25.9492 22.4639 26.1226 22.1201C26.1777 22.0078 26.4458 21.7358 26.5088 21.688C27.2256 21.272 28.0527 21.4077 28.8169 21.7197C29.5259 22.0161 30.0615 22.5601 30.834 23.3281C31.6216 24.2559 31.7632 24.5117 32.2124 25.208C32.5669 25.752 32.8901 26.312 33.1104 26.9521C33.2446 27.3521 33.0713 27.6802 32.6064 27.8799Z";
|
|
154
|
+
var MINIMAX_PATH = "M17.5802 3.08155C17.5802 2.35036 16.987 1.75702 16.2589 1.75702C15.5309 1.75702 14.9377 2.35171 14.9377 3.08155V25.0348C14.9377 26.7337 13.5586 28.1164 11.8639 28.1164C10.1693 28.1164 8.79008 26.7337 8.79008 25.0348V10.9503C8.79008 10.2191 8.19688 9.62575 7.46886 9.62575C6.74085 9.62575 6.14765 10.2204 6.14765 10.9503V16.9201C6.14765 18.619 4.76846 20.0016 3.07381 20.0016C1.37915 20.0016 0 18.619 0 16.9201V14.7563C0 14.2711 0.392318 13.8778 0.876312 13.8778C1.36031 13.8778 1.75262 14.2711 1.75262 14.7563V16.9201C1.75262 17.6513 2.34579 18.2446 3.07381 18.2446C3.80182 18.2446 4.39502 17.6499 4.39502 16.9201V10.9503C4.39502 9.25138 5.77421 7.86874 7.46886 7.86874C9.16352 7.86874 10.5427 9.25138 10.5427 10.9503V25.0348C10.5427 25.766 11.1359 26.3593 11.8639 26.3593C12.5919 26.3593 13.1851 25.7646 13.1851 25.0348V16.4227V3.08155C13.1851 1.38265 14.5643 0 16.2589 0C17.9536 0 19.3328 1.38265 19.3328 3.08155V21.2599C19.3328 21.7451 18.9405 22.1384 18.4565 22.1384C17.9725 22.1384 17.5802 21.7451 17.5802 21.2599V3.08155ZM33.8405 7.86874C32.1458 7.86874 30.7666 9.25138 30.7666 10.9503V22.7155C30.7666 23.4467 30.1734 24.0401 29.4454 24.0401C28.7174 24.0401 28.1242 23.4454 28.1242 22.7155V3.08155C28.1242 1.38265 26.745 0 25.0504 0C23.3557 0 21.9766 1.38265 21.9766 3.08155V28.0042C21.9766 28.7354 21.3834 29.3287 20.6553 29.3287C19.9273 29.3287 19.3341 28.734 19.3341 28.0042V24.9186C19.3341 24.4334 18.9418 24.0401 18.4578 24.0401C17.9738 24.0401 17.5815 24.4334 17.5815 24.9186V28.0042C17.5815 29.7031 18.9607 31.0857 20.6553 31.0857C22.35 31.0857 23.7292 29.7031 23.7292 28.0042V3.08155C23.7292 2.35036 24.3224 1.75702 25.0504 1.75702C25.7784 1.75702 26.3716 2.35171 26.3716 3.08155V22.7155C26.3716 24.4144 27.7508 25.7971 29.4454 25.7971C31.1401 25.7971 32.5193 24.4144 32.5193 22.7155V10.9503C32.5193 10.2191 33.1125 9.62575 33.8405 9.62575C34.5685 9.62575 35.1617 10.2204 35.1617 10.9503V21.2599C35.1617 21.7451 35.554 22.1384 36.038 22.1384C36.522 22.1384 36.9143 21.7451 36.9143 21.2599V10.9503C36.9143 9.25138 35.5351 7.86874 33.8405 7.86874Z";
|
|
155
|
+
var MINIMAX_GRADIENT = {
|
|
156
|
+
id: "dsh-balance-minimax-wave",
|
|
157
|
+
x1: 0,
|
|
158
|
+
y1: 15.5,
|
|
159
|
+
x2: 36.9143,
|
|
160
|
+
y2: 15.5,
|
|
161
|
+
stops: [
|
|
162
|
+
["#E21680", "0"],
|
|
163
|
+
["#FF633A", "1"]
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
var ZHIPU_PATHS = [
|
|
167
|
+
{
|
|
168
|
+
d: "M21.0517 11.7895V5.91559C21.0517 5.89816 21.0422 5.88207 21.0268 5.87346L10.5497 0.00632824C10.5422 0.00210946 10.5338 2.92206e-08 10.5254 0V2.45801C10.5254 7.22726 14.5109 11.784 19.4278 11.784C19.3287 11.784 19.2299 11.7858 19.1316 11.7895H21.0517Z",
|
|
169
|
+
fill: "#5b6fe8"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
d: "M-0.000925064 11.7895V17.8731C-0.000925064 17.8912 0.00857449 17.9079 0.0239525 17.9168L10.5011 23.9934C10.5086 23.9978 10.517 24 10.5254 24V21.4542C10.5254 16.5146 6.53987 11.7952 1.62302 11.7952C1.72212 11.7952 1.82085 11.7933 1.91917 11.7895H-0.000925064Z",
|
|
173
|
+
fill: "#57a4ee"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
d: "M-0.000925064 11.7895V5.91559C-0.000925064 5.89816 0.00857449 5.88207 0.0239525 5.87346L10.5011 0.00632824C10.5086 0.00210946 10.517 2.92206e-08 10.5254 0V2.45801C10.5254 7.22726 6.53987 11.784 1.62302 11.784C1.72212 11.784 1.82085 11.7858 1.91917 11.7895H-0.000925064Z",
|
|
177
|
+
fill: "#5b6fe8"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
d: "M21.0517 11.7895V17.8731C21.0517 17.8912 21.0422 17.9079 21.0268 17.9168L10.5497 23.9934C10.5422 23.9978 10.5338 24 10.5254 24V21.4542C10.5254 16.5146 14.5109 11.7952 19.4278 11.7952C19.3287 11.7952 19.2299 11.7933 19.1316 11.7895H21.0517Z",
|
|
181
|
+
fill: "#5a84ee"
|
|
182
|
+
}
|
|
183
|
+
];
|
|
184
|
+
var KIMI_PATHS = [
|
|
185
|
+
"M21.7202 0.939941C22.9502 0.939941 23.9502 1.93994 23.9502 3.16994C23.9502 4.39994 22.9502 5.39994 21.7202 5.39994H19.7502C19.6002 5.39994 19.4902 5.27994 19.4902 5.13994V3.16994C19.4902 1.93994 20.4902 0.939941 21.7202 0.939941Z",
|
|
186
|
+
"M9.39 13.9501L17.82 5.59012C17.98 5.43012 17.89 5.12012 17.68 5.12012H13.14C13.14 5.12012 13.04 5.14012 13 5.18012L3.92 14.1901C3.78 14.3301 3.57 14.2101 3.57 13.9801V5.39012C3.57 5.24012 3.47 5.12012 3.35 5.12012H0.219999C0.0999993 5.12012 0 5.24012 0 5.39012V23.9201C0 24.0701 0.0999993 24.1901 0.219999 24.1901H3.35C3.47 24.1901 3.57 24.0701 3.57 23.9201V20.1401C3.57 20.0601 3.6 19.9801 3.65 19.9301L6.47 17.1401C6.54 17.0701 6.63 17.0601 6.71 17.1101L14.24 22.6501C15.47 23.4801 16.85 23.9901 18.25 24.1401C18.37 24.1501 18.48 24.0301 18.48 23.8701V20.3101C18.48 20.1701 18.4 20.0601 18.29 20.0501C17.47 19.9201 16.66 19.6001 15.94 19.1101L9.42 14.3901C9.28 14.3001 9.27 14.0701 9.39 13.9501Z"
|
|
187
|
+
];
|
|
188
|
+
var OPENCODE_PATHS = [
|
|
189
|
+
{ d: "M180 240H60V120H180V240Z", opacity: 0.5 },
|
|
190
|
+
{ d: "M180 60H60V240H180V60ZM240 300H0V0H240V300Z", opacity: 1 }
|
|
191
|
+
];
|
|
192
|
+
var ICON_GEOMETRY = {
|
|
193
|
+
// DeepSeek's square icon draws 1..49.35 across and 7..43.35 down.
|
|
194
|
+
deepseek: { x: 1, y: 7, vbW: 48.35, vbH: 36.35, inkW: 48.35, inkH: 36.35 },
|
|
195
|
+
// MiniMax's waveform occupies 0..37.02 by 0..31.10 of the wordmark.
|
|
196
|
+
minimax: { x: 0, y: 0, vbW: 37.023, vbH: 31.097, inkW: 37.023, inkH: 31.097 },
|
|
197
|
+
zhipu: { x: 0, y: 0, vbW: 21.052, vbH: 24, inkW: 21.052, inkH: 24 },
|
|
198
|
+
// Kimi's K-only glyph draws 0..23.95 across and 0.94..24.19 down.
|
|
199
|
+
kimi: { x: 0, y: 0.94, vbW: 23.95, vbH: 23.25, inkW: 23.95, inkH: 23.25 },
|
|
200
|
+
// OpenCode's logo draws its 240x300 frame from the origin.
|
|
201
|
+
opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 }
|
|
202
|
+
};
|
|
203
|
+
function markOf(entry, route) {
|
|
204
|
+
const color = typeof entry?.color === "string" && entry.color !== "" ? entry.color : "#6b7280";
|
|
205
|
+
if (typeof entry?.iconHint === "string" && entry.iconHint !== "") {
|
|
206
|
+
return { icon: entry.iconHint, color };
|
|
207
|
+
}
|
|
208
|
+
return { letter: route.slice(0, 1).toUpperCase(), color };
|
|
209
|
+
}
|
|
210
|
+
function providerIcon(route, inkHeight, mark) {
|
|
211
|
+
const geo = mark.icon === void 0 ? void 0 : ICON_GEOMETRY[mark.icon];
|
|
212
|
+
if (mark.letter !== void 0 || geo === void 0) {
|
|
213
|
+
return (0, import_react.createElement)(
|
|
214
|
+
"span",
|
|
215
|
+
{ className: "dsh-model-allowance-tab-letter" },
|
|
216
|
+
mark.letter ?? route.slice(0, 1).toUpperCase()
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
const even = (value) => Math.max(2, Math.round(value / 2) * 2);
|
|
220
|
+
const boxH = even(inkHeight * geo.vbH / geo.inkH);
|
|
221
|
+
const boxW = even(inkHeight * geo.vbW / geo.inkH);
|
|
222
|
+
let content;
|
|
223
|
+
if (mark.icon === "zhipu") {
|
|
224
|
+
content = ZHIPU_PATHS.map(
|
|
225
|
+
(path, index) => (0, import_react.createElement)("path", { key: `z-${String(index)}`, d: path.d, fill: path.fill })
|
|
226
|
+
);
|
|
227
|
+
} else if (mark.icon === "minimax") {
|
|
228
|
+
content = [
|
|
229
|
+
(0, import_react.createElement)(
|
|
230
|
+
"defs",
|
|
231
|
+
{ key: "defs" },
|
|
232
|
+
(0, import_react.createElement)(
|
|
233
|
+
"linearGradient",
|
|
234
|
+
{
|
|
235
|
+
id: MINIMAX_GRADIENT.id,
|
|
236
|
+
x1: MINIMAX_GRADIENT.x1,
|
|
237
|
+
y1: MINIMAX_GRADIENT.y1,
|
|
238
|
+
x2: MINIMAX_GRADIENT.x2,
|
|
239
|
+
y2: MINIMAX_GRADIENT.y2,
|
|
240
|
+
gradientUnits: "userSpaceOnUse"
|
|
241
|
+
},
|
|
242
|
+
...MINIMAX_GRADIENT.stops.map(
|
|
243
|
+
([color, offset]) => (0, import_react.createElement)("stop", { key: offset, offset, stopColor: color })
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
),
|
|
247
|
+
(0, import_react.createElement)("path", {
|
|
248
|
+
key: "wave",
|
|
249
|
+
d: MINIMAX_PATH,
|
|
250
|
+
fill: `url(#${MINIMAX_GRADIENT.id})`
|
|
251
|
+
})
|
|
252
|
+
];
|
|
253
|
+
} else if (mark.icon === "kimi") {
|
|
254
|
+
content = KIMI_PATHS.map(
|
|
255
|
+
(d, index) => (0, import_react.createElement)("path", { key: `kimi-${String(index)}`, d, fill: "currentColor" })
|
|
256
|
+
);
|
|
257
|
+
} else if (mark.icon === "opencode") {
|
|
258
|
+
content = OPENCODE_PATHS.map(
|
|
259
|
+
(path, index) => (0, import_react.createElement)("path", {
|
|
260
|
+
key: `opencode-${String(index)}`,
|
|
261
|
+
d: path.d,
|
|
262
|
+
fill: "currentColor",
|
|
263
|
+
fillOpacity: path.opacity
|
|
264
|
+
})
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
content = [(0, import_react.createElement)("path", { key: "mark", d: DEEPSEEK_PATH, fill: "currentColor" })];
|
|
268
|
+
}
|
|
269
|
+
return (0, import_react.createElement)(
|
|
270
|
+
"svg",
|
|
271
|
+
{
|
|
272
|
+
viewBox: `${String(geo.x)} ${String(geo.y)} ${String(geo.vbW)} ${String(geo.vbH)}`,
|
|
273
|
+
width: boxW,
|
|
274
|
+
height: boxH,
|
|
275
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
276
|
+
"aria-hidden": "true",
|
|
277
|
+
focusable: "false"
|
|
278
|
+
},
|
|
279
|
+
...content
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/client/locales.js
|
|
284
|
+
var NS = "model-allowance";
|
|
285
|
+
var zh = {
|
|
286
|
+
"badge.loading": "\u52A0\u8F7D\u4E2D\u2026",
|
|
287
|
+
"badge.noData": "\u6682\u65E0\u6570\u636E",
|
|
288
|
+
"badge.amount": "{amount}",
|
|
289
|
+
"badge.quotaPercent": "\u5269\u4F59 {percent}%",
|
|
290
|
+
"badge.quotaRatio": "{remaining} / {total}",
|
|
291
|
+
"badge.quotaDuration": "\u5269\u4F59 {duration}",
|
|
292
|
+
"badge.unsupported": "\u65E0\u4F59\u989D\u63A5\u53E3",
|
|
293
|
+
"badge.unconfigured": "\u672A\u914D\u7F6E\u51ED\u8BC1",
|
|
294
|
+
"badge.failed": "\u65E0\u6CD5\u83B7\u53D6",
|
|
295
|
+
"detail.title": "\u5382\u5546\u4F59\u989D",
|
|
296
|
+
"detail.provider": "\u5382\u5546",
|
|
297
|
+
"detail.amount": "\u4F59\u989D",
|
|
298
|
+
"detail.remaining": "\u5269\u4F59",
|
|
299
|
+
"detail.total": "\u603B\u989D",
|
|
300
|
+
"detail.updatedAt": "\u66F4\u65B0\u4E8E {time}",
|
|
301
|
+
"detail.refresh": "\u5237\u65B0",
|
|
302
|
+
"detail.refreshing": "\u5237\u65B0\u4E2D\u2026",
|
|
303
|
+
"detail.console": "\u63A7\u5236\u53F0",
|
|
304
|
+
"detail.error": "\u65E0\u6CD5\u8BFB\u53D6\u5382\u5546\u4F59\u989D\u3002",
|
|
305
|
+
"detail.moreProviders": "\u66F4\u591A\u5382\u5546",
|
|
306
|
+
"status.operational": "\u8FD0\u884C\u6B63\u5E38",
|
|
307
|
+
"status.degraded": "\u670D\u52A1\u964D\u7EA7",
|
|
308
|
+
"status.partialOutage": "\u90E8\u5206\u670D\u52A1\u4E2D\u65AD",
|
|
309
|
+
"status.majorOutage": "\u5927\u9762\u79EF\u4E2D\u65AD",
|
|
310
|
+
"status.maintenance": "\u7EF4\u62A4\u4E2D",
|
|
311
|
+
"status.unknown": "\u72B6\u6001\u672A\u77E5",
|
|
312
|
+
"schedule.peakTitle": "\u9AD8\u5CF0\u65F6\u6BB5",
|
|
313
|
+
"schedule.offPeakTitle": "\u4F4E\u8C37\u65F6\u6BB5",
|
|
314
|
+
"schedule.daysWeekdays": "\u5DE5\u4F5C\u65E5",
|
|
315
|
+
"schedule.daysDaily": "\u6BCF\u5929",
|
|
316
|
+
"schedule.daysOther": "\u6307\u5B9A\u65E5\u671F",
|
|
317
|
+
"schedule.ranges": "{days} {windows}\uFF08{timezone}\uFF09",
|
|
318
|
+
"schedule.holidays": "\u6CD5\u5B9A\u8282\u5047\u65E5\u5168\u5929\u4F4E\u8C37",
|
|
319
|
+
"schedule.toPeak": "\u8DDD\u9AD8\u5CF0\u5F00\u59CB {duration}",
|
|
320
|
+
"schedule.toOffPeak": "\u8DDD\u4F4E\u8C37\u5F00\u59CB {duration}",
|
|
321
|
+
"badge.consumption": "\u76F8\u5BF9\u4E0A\u6B21\u8BFB\u6570\u7684\u53D8\u5316",
|
|
322
|
+
"window.title.hour": "{count} \u5C0F\u65F6\u989D\u5EA6",
|
|
323
|
+
"window.title.day": "{count} \u5929\u989D\u5EA6",
|
|
324
|
+
"window.title.week": "\u6BCF\u5468\u989D\u5EA6",
|
|
325
|
+
"window.title.month": "\u6BCF\u6708\u989D\u5EA6",
|
|
326
|
+
"window.title.unknown": "\u5F53\u524D\u989D\u5EA6",
|
|
327
|
+
"window.usedOfTotal": "{used} / {total}",
|
|
328
|
+
"window.usedPercent": "{percent}% \u5DF2\u4F7F\u7528",
|
|
329
|
+
"window.resetIn": "{duration} \u540E\u91CD\u7F6E",
|
|
330
|
+
"duration.daysHours": "{days} \u5929 {hours} \u5C0F\u65F6",
|
|
331
|
+
"duration.hoursMinutes": "{hours} \u5C0F\u65F6 {minutes} \u5206",
|
|
332
|
+
"duration.minutes": "{minutes} \u5206\u949F",
|
|
333
|
+
"duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F"
|
|
334
|
+
};
|
|
335
|
+
var en = {
|
|
336
|
+
"badge.loading": "Loading\u2026",
|
|
337
|
+
"badge.noData": "No data",
|
|
338
|
+
"badge.amount": "{amount}",
|
|
339
|
+
"badge.quotaPercent": "{percent}% left",
|
|
340
|
+
"badge.quotaRatio": "{remaining} / {total}",
|
|
341
|
+
"badge.quotaDuration": "{duration} left",
|
|
342
|
+
"badge.unsupported": "No balance API",
|
|
343
|
+
"badge.unconfigured": "No credential",
|
|
344
|
+
"badge.failed": "Unavailable",
|
|
345
|
+
"detail.title": "Provider balance",
|
|
346
|
+
"detail.provider": "Provider",
|
|
347
|
+
"detail.amount": "Balance",
|
|
348
|
+
"detail.remaining": "Remaining",
|
|
349
|
+
"detail.total": "Total",
|
|
350
|
+
"detail.updatedAt": "updated {time}",
|
|
351
|
+
"detail.refresh": "Refresh",
|
|
352
|
+
"detail.refreshing": "Refreshing\u2026",
|
|
353
|
+
"detail.console": "Console",
|
|
354
|
+
"detail.error": "Could not read the provider balance.",
|
|
355
|
+
"detail.moreProviders": "More providers",
|
|
356
|
+
"status.operational": "Operational",
|
|
357
|
+
"status.degraded": "Degraded",
|
|
358
|
+
"status.partialOutage": "Partial outage",
|
|
359
|
+
"status.majorOutage": "Major outage",
|
|
360
|
+
"status.maintenance": "Maintenance",
|
|
361
|
+
"status.unknown": "Status unknown",
|
|
362
|
+
"schedule.peakTitle": "Peak hours",
|
|
363
|
+
"schedule.offPeakTitle": "Off-peak",
|
|
364
|
+
"schedule.daysWeekdays": "Weekdays",
|
|
365
|
+
"schedule.daysDaily": "Every day",
|
|
366
|
+
"schedule.daysOther": "Selected days",
|
|
367
|
+
"schedule.ranges": "{days} {windows} ({timezone})",
|
|
368
|
+
"schedule.holidays": "Statutory holidays are off-peak all day",
|
|
369
|
+
"schedule.toPeak": "{duration} until peak",
|
|
370
|
+
"schedule.toOffPeak": "{duration} until off-peak",
|
|
371
|
+
"badge.consumption": "Change since the last reading",
|
|
372
|
+
"window.title.hour": "{count}-hour quota",
|
|
373
|
+
"window.title.day": "{count}-day quota",
|
|
374
|
+
"window.title.week": "Weekly quota",
|
|
375
|
+
"window.title.month": "Monthly quota",
|
|
376
|
+
"window.title.unknown": "Current quota",
|
|
377
|
+
"window.usedOfTotal": "{used} / {total}",
|
|
378
|
+
"window.usedPercent": "{percent}% used",
|
|
379
|
+
"window.resetIn": "resets in {duration}",
|
|
380
|
+
"duration.daysHours": "{days}d {hours}h",
|
|
381
|
+
"duration.hoursMinutes": "{hours}h {minutes}m",
|
|
382
|
+
"duration.minutes": "{minutes}m",
|
|
383
|
+
"duration.lessThanMinute": "under a minute"
|
|
384
|
+
};
|
|
385
|
+
function activeLanguage() {
|
|
386
|
+
const tag = typeof document !== "undefined" ? document.documentElement?.lang : void 0;
|
|
387
|
+
return typeof tag === "string" && tag.toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
388
|
+
}
|
|
389
|
+
function pickName(entry, route) {
|
|
390
|
+
const name = entry?.name;
|
|
391
|
+
if (!name) return route;
|
|
392
|
+
return name[activeLanguage()] ?? name.en ?? name.zh ?? route;
|
|
393
|
+
}
|
|
394
|
+
var STATUS_LABEL_KEYS = {
|
|
395
|
+
operational: "status.operational",
|
|
396
|
+
degraded: "status.degraded",
|
|
397
|
+
"partial-outage": "status.partialOutage",
|
|
398
|
+
"major-outage": "status.majorOutage",
|
|
399
|
+
maintenance: "status.maintenance",
|
|
400
|
+
unknown: "status.unknown"
|
|
401
|
+
};
|
|
402
|
+
function statusLabel(state, t) {
|
|
403
|
+
const key = STATUS_LABEL_KEYS[state];
|
|
404
|
+
return key === void 0 ? t("status.unknown") : t(key);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/client/namespace.js
|
|
408
|
+
var balanceNamespace = null;
|
|
409
|
+
var settleBalanceNamespace;
|
|
410
|
+
var balanceNamespaceReady = new Promise((resolve) => {
|
|
411
|
+
settleBalanceNamespace = resolve;
|
|
412
|
+
});
|
|
413
|
+
async function getBalanceApi() {
|
|
414
|
+
if (balanceNamespace) return balanceNamespace;
|
|
415
|
+
return await balanceNamespaceReady;
|
|
416
|
+
}
|
|
417
|
+
function lookupBalanceNamespace(ctx) {
|
|
418
|
+
try {
|
|
419
|
+
return ctx.get("remote.balance");
|
|
420
|
+
} catch {
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function setBalanceNamespace(value) {
|
|
425
|
+
balanceNamespace = value;
|
|
426
|
+
settleBalanceNamespace(value);
|
|
427
|
+
return value;
|
|
428
|
+
}
|
|
429
|
+
var modelSupport;
|
|
430
|
+
function resetBalanceNamespace() {
|
|
431
|
+
balanceNamespace = null;
|
|
432
|
+
modelSupport = void 0;
|
|
433
|
+
}
|
|
434
|
+
async function supportsModel(api) {
|
|
435
|
+
if (modelSupport !== void 0) return modelSupport;
|
|
436
|
+
if (typeof api?.capabilities !== "function") {
|
|
437
|
+
modelSupport = false;
|
|
438
|
+
return modelSupport;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const result = await api.capabilities();
|
|
442
|
+
modelSupport = result?.ok === true && result.value?.modelScoped === true;
|
|
443
|
+
} catch {
|
|
444
|
+
modelSupport = false;
|
|
445
|
+
}
|
|
446
|
+
return modelSupport;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/client/schedule.js
|
|
450
|
+
var import_react2 = require("react");
|
|
451
|
+
function formatCountdown(ms) {
|
|
452
|
+
const remaining = Number.isFinite(ms) && ms > 0 ? ms : 0;
|
|
453
|
+
const totalSeconds = Math.floor(remaining / 1e3);
|
|
454
|
+
const days = Math.floor(totalSeconds / 86400);
|
|
455
|
+
const hours = Math.floor(totalSeconds % 86400 / 3600);
|
|
456
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
457
|
+
const seconds = totalSeconds % 60;
|
|
458
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
459
|
+
const clock = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
|
|
460
|
+
return days > 0 ? `${pad(days)}.${clock}` : clock;
|
|
461
|
+
}
|
|
462
|
+
var pad2 = (value) => String(value).padStart(2, "0");
|
|
463
|
+
var ZONE_FORMATTERS = /* @__PURE__ */ new Map();
|
|
464
|
+
function zoneFormatter(timeZone) {
|
|
465
|
+
let formatter = ZONE_FORMATTERS.get(timeZone);
|
|
466
|
+
if (formatter === void 0) {
|
|
467
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
468
|
+
timeZone,
|
|
469
|
+
year: "numeric",
|
|
470
|
+
month: "2-digit",
|
|
471
|
+
day: "2-digit",
|
|
472
|
+
hour: "2-digit",
|
|
473
|
+
minute: "2-digit",
|
|
474
|
+
second: "2-digit",
|
|
475
|
+
hour12: false,
|
|
476
|
+
weekday: "short"
|
|
477
|
+
});
|
|
478
|
+
ZONE_FORMATTERS.set(timeZone, formatter);
|
|
479
|
+
}
|
|
480
|
+
return formatter;
|
|
481
|
+
}
|
|
482
|
+
function zoneParts(ms, timeZone) {
|
|
483
|
+
const parts = zoneFormatter(timeZone).formatToParts(new Date(ms));
|
|
484
|
+
const value = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
485
|
+
return {
|
|
486
|
+
year: Number(value("year")),
|
|
487
|
+
month: Number(value("month")),
|
|
488
|
+
day: Number(value("day")),
|
|
489
|
+
// Some runtimes render midnight as 24 with hour12 turned off.
|
|
490
|
+
hour: Number(value("hour")) % 24,
|
|
491
|
+
minute: Number(value("minute")),
|
|
492
|
+
second: Number(value("second")),
|
|
493
|
+
weekday: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].indexOf(value("weekday"))
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function zoneOffsetMs(ms, timeZone) {
|
|
497
|
+
const parts = zoneParts(ms, timeZone);
|
|
498
|
+
const wall = Date.UTC(
|
|
499
|
+
parts.year,
|
|
500
|
+
parts.month - 1,
|
|
501
|
+
parts.day,
|
|
502
|
+
parts.hour,
|
|
503
|
+
parts.minute,
|
|
504
|
+
parts.second
|
|
505
|
+
);
|
|
506
|
+
return wall - Math.floor(ms / 1e3) * 1e3;
|
|
507
|
+
}
|
|
508
|
+
function zoneInstant(timeZone, year, month, day, hour, minute) {
|
|
509
|
+
const wall = Date.UTC(year, month - 1, day, hour, minute, 0);
|
|
510
|
+
const first = wall - zoneOffsetMs(wall, timeZone);
|
|
511
|
+
return wall - zoneOffsetMs(first, timeZone);
|
|
512
|
+
}
|
|
513
|
+
function wallMinutes(time) {
|
|
514
|
+
const [hour, minute] = time.split(":").map(Number);
|
|
515
|
+
return hour * 60 + minute;
|
|
516
|
+
}
|
|
517
|
+
function dayPercent(minutes) {
|
|
518
|
+
return `${String(Number((minutes / 1440 * 100).toFixed(2)))}%`;
|
|
519
|
+
}
|
|
520
|
+
function schedulePhase(schedule, now) {
|
|
521
|
+
const parts = zoneParts(now, schedule.timezone);
|
|
522
|
+
const date = `${String(parts.year)}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
523
|
+
if ((schedule.holidays ?? []).includes(date)) return "off-peak";
|
|
524
|
+
if (!schedule.days.includes(parts.weekday)) return "off-peak";
|
|
525
|
+
const minutes = parts.hour * 60 + parts.minute;
|
|
526
|
+
for (const window of schedule.windows) {
|
|
527
|
+
if (minutes >= wallMinutes(window.from) && minutes < wallMinutes(window.to)) return "peak";
|
|
528
|
+
}
|
|
529
|
+
return "off-peak";
|
|
530
|
+
}
|
|
531
|
+
function nextScheduleChange(schedule, now) {
|
|
532
|
+
const parts = zoneParts(now, schedule.timezone);
|
|
533
|
+
let next;
|
|
534
|
+
for (let offset = 0; offset <= 10; offset += 1) {
|
|
535
|
+
const day = new Date(Date.UTC(parts.year, parts.month - 1, parts.day) + offset * 864e5);
|
|
536
|
+
const year = day.getUTCFullYear();
|
|
537
|
+
const month = day.getUTCMonth() + 1;
|
|
538
|
+
const date = day.getUTCDate();
|
|
539
|
+
const key = `${String(year)}-${pad2(month)}-${pad2(date)}`;
|
|
540
|
+
if ((schedule.holidays ?? []).includes(key)) continue;
|
|
541
|
+
if (!schedule.days.includes(day.getUTCDay())) continue;
|
|
542
|
+
for (const window of schedule.windows) {
|
|
543
|
+
for (const time of [window.from, window.to]) {
|
|
544
|
+
const [hour, minute] = time.split(":").map(Number);
|
|
545
|
+
const at = zoneInstant(schedule.timezone, year, month, date, hour, minute);
|
|
546
|
+
if (at > now && (next === void 0 || at < next)) next = at;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return next;
|
|
551
|
+
}
|
|
552
|
+
function scheduleView(schedule, now, t) {
|
|
553
|
+
const language = activeLanguage();
|
|
554
|
+
const phase = schedulePhase(schedule, now);
|
|
555
|
+
const change = nextScheduleChange(schedule, now);
|
|
556
|
+
const separator = language === "zh" ? "\u3001" : ", ";
|
|
557
|
+
const windows = schedule.windows.map((window) => `${window.from}\u2013${window.to}`).join(separator);
|
|
558
|
+
const days = schedule.days.length === 7 ? t("schedule.daysDaily") : [1, 2, 3, 4, 5].every((day) => schedule.days.includes(day)) ? t("schedule.daysWeekdays") : t("schedule.daysOther");
|
|
559
|
+
const timezone = schedule.timezoneLabel?.[language] ?? schedule.timezoneLabel?.en ?? schedule.timezone;
|
|
560
|
+
const note = schedule.note?.[language] ?? schedule.note?.en ?? schedule.note?.zh;
|
|
561
|
+
const rules = [t("schedule.ranges", { days, windows, timezone })];
|
|
562
|
+
if ((schedule.holidays ?? []).length > 0) rules.push(t("schedule.holidays"));
|
|
563
|
+
if (note !== void 0) rules.push(note);
|
|
564
|
+
const parts = zoneParts(now, schedule.timezone);
|
|
565
|
+
const date = `${String(parts.year)}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
566
|
+
const offToday = (schedule.holidays ?? []).includes(date) || !schedule.days.includes(parts.weekday);
|
|
567
|
+
const segments = offToday ? [] : schedule.windows.map((window) => ({
|
|
568
|
+
left: dayPercent(wallMinutes(window.from)),
|
|
569
|
+
width: dayPercent(wallMinutes(window.to) - wallMinutes(window.from))
|
|
570
|
+
}));
|
|
571
|
+
const cursor = dayPercent(parts.hour * 60 + parts.minute + parts.second / 60);
|
|
572
|
+
return (0, import_react2.createElement)(
|
|
573
|
+
"div",
|
|
574
|
+
{ className: "dsh-model-allowance-schedule", "data-phase": phase },
|
|
575
|
+
(0, import_react2.createElement)(
|
|
576
|
+
"div",
|
|
577
|
+
{ className: "dsh-model-allowance-schedule-head" },
|
|
578
|
+
(0, import_react2.createElement)(
|
|
579
|
+
"span",
|
|
580
|
+
{ className: "dsh-model-allowance-schedule-title" },
|
|
581
|
+
phase === "peak" ? t("schedule.peakTitle") : t("schedule.offPeakTitle")
|
|
582
|
+
),
|
|
583
|
+
// The rule itself is one hover — or one keyboard focus — away.
|
|
584
|
+
(0, import_react2.createElement)(
|
|
585
|
+
"span",
|
|
586
|
+
{
|
|
587
|
+
className: "dsh-model-allowance-schedule-help",
|
|
588
|
+
tabIndex: 0,
|
|
589
|
+
role: "note",
|
|
590
|
+
"aria-label": rules.join(" ")
|
|
591
|
+
},
|
|
592
|
+
(0, import_react2.createElement)("span", { "aria-hidden": true }, "?"),
|
|
593
|
+
(0, import_react2.createElement)(
|
|
594
|
+
"span",
|
|
595
|
+
{ className: "dsh-model-allowance-schedule-tip", role: "tooltip" },
|
|
596
|
+
...rules.map(
|
|
597
|
+
(line, index) => (0, import_react2.createElement)(
|
|
598
|
+
"span",
|
|
599
|
+
{
|
|
600
|
+
key: `rule-${String(index)}`,
|
|
601
|
+
className: "dsh-model-allowance-schedule-tip-line"
|
|
602
|
+
},
|
|
603
|
+
line
|
|
604
|
+
)
|
|
605
|
+
)
|
|
606
|
+
)
|
|
607
|
+
)
|
|
608
|
+
),
|
|
609
|
+
(0, import_react2.createElement)(
|
|
610
|
+
"div",
|
|
611
|
+
{ className: "dsh-model-allowance-schedule-timeline", role: "img", "aria-label": rules[0] },
|
|
612
|
+
...segments.map(
|
|
613
|
+
(segment, index) => (0, import_react2.createElement)("span", {
|
|
614
|
+
key: `peak-${String(index)}`,
|
|
615
|
+
className: "dsh-model-allowance-schedule-timeline-peak",
|
|
616
|
+
style: { left: segment.left, width: segment.width }
|
|
617
|
+
})
|
|
618
|
+
),
|
|
619
|
+
(0, import_react2.createElement)("span", {
|
|
620
|
+
className: "dsh-model-allowance-schedule-timeline-now",
|
|
621
|
+
style: { left: cursor }
|
|
622
|
+
})
|
|
623
|
+
),
|
|
624
|
+
// Quarter ticks: the strip is the vendor's day, so the scale is its
|
|
625
|
+
// wall clock, matching the windows drawn on it.
|
|
626
|
+
(0, import_react2.createElement)(
|
|
627
|
+
"div",
|
|
628
|
+
{ className: "dsh-model-allowance-schedule-ticks" },
|
|
629
|
+
...["00:00", "06:00", "12:00", "18:00", "24:00"].map(
|
|
630
|
+
(tick) => (0, import_react2.createElement)("span", { key: tick, className: "dsh-model-allowance-schedule-tick" }, tick)
|
|
631
|
+
)
|
|
632
|
+
),
|
|
633
|
+
change === void 0 ? null : (0, import_react2.createElement)(
|
|
634
|
+
"div",
|
|
635
|
+
{ className: "dsh-model-allowance-schedule-countdown" },
|
|
636
|
+
t(phase === "peak" ? "schedule.toOffPeak" : "schedule.toPeak", {
|
|
637
|
+
duration: formatCountdown(change - now)
|
|
638
|
+
})
|
|
639
|
+
)
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/client/styles.js
|
|
644
|
+
var STYLES = [
|
|
645
|
+
".dsh-model-allowance-root{position:relative;display:inline-flex;align-items:center}",
|
|
646
|
+
// The badge is a trigger, the way the harness's own composer triggers
|
|
647
|
+
// are: no frame of its own, a transparent surface, and the hover tint
|
|
648
|
+
// only while the pointer is on it or the card is open. A bordered pill
|
|
649
|
+
// read as a field rather than a control.
|
|
650
|
+
".dsh-model-allowance-badge{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px;",
|
|
651
|
+
"border:0;border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
652
|
+
"color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1;cursor:pointer;",
|
|
653
|
+
"font-variant-numeric:tabular-nums;white-space:nowrap}",
|
|
654
|
+
".dsh-model-allowance-badge:hover{color:var(--dsw-alias-label-secondary);",
|
|
655
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
656
|
+
'.dsh-model-allowance-badge[aria-expanded="true"]{color:var(--dsw-alias-label-secondary);',
|
|
657
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
658
|
+
".dsh-model-allowance-badge:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
659
|
+
"outline-offset:1px}",
|
|
660
|
+
".dsh-model-allowance-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
661
|
+
"background:var(--dsw-alias-state-idle-primary)}",
|
|
662
|
+
// The dot reports the platform, not the reading: green while the service
|
|
663
|
+
// is available, red once its own status page says otherwise, and grey
|
|
664
|
+
// when this installation has no status source for the route.
|
|
665
|
+
'.dsh-model-allowance-root[data-service="operational"] .dsh-model-allowance-dot{',
|
|
666
|
+
"background:var(--dsw-alias-state-success-primary)}",
|
|
667
|
+
'.dsh-model-allowance-root[data-service="degraded"] .dsh-model-allowance-dot,',
|
|
668
|
+
'.dsh-model-allowance-root[data-service="partial-outage"] .dsh-model-allowance-dot,',
|
|
669
|
+
'.dsh-model-allowance-root[data-service="major-outage"] .dsh-model-allowance-dot,',
|
|
670
|
+
'.dsh-model-allowance-root[data-service="maintenance"] .dsh-model-allowance-dot{',
|
|
671
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
672
|
+
'.dsh-model-allowance-root[data-loading="true"] .dsh-model-allowance-dot{opacity:.5}',
|
|
673
|
+
// The turn's difference rides beside the value for a few seconds. It is
|
|
674
|
+
// quieter than the value so the balance stays the thing being read, and
|
|
675
|
+
// it fades in rather than popping.
|
|
676
|
+
".dsh-model-allowance-delta{margin-left:-2px;font-size:11px;",
|
|
677
|
+
"color:var(--dsw-alias-label-secondary);animation:dsh-model-allowance-fade 200ms ease-out}",
|
|
678
|
+
'.dsh-model-allowance-delta[data-direction="up"]{',
|
|
679
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
680
|
+
"@keyframes dsh-model-allowance-fade{from{opacity:0}to{opacity:1}}",
|
|
681
|
+
// Anchored to its own right edge: the badge sits next to the model seat
|
|
682
|
+
// near the trailing edge, so the panel opens leftwards instead of
|
|
683
|
+
// running off the side of the composer.
|
|
684
|
+
//
|
|
685
|
+
// The surface is the harness's own menu surface — a translucent white
|
|
686
|
+
// behind a heavy blur — and the shadow is its own elevation scale. The
|
|
687
|
+
// overlay token reads as a mask over the page behind, not as a panel
|
|
688
|
+
// surface: on it this card came out a flat grey slab.
|
|
689
|
+
// The floor is set for the layout, not for the content: with it removed
|
|
690
|
+
// the card collapses to 248px, so 300px is the slack that lets a label
|
|
691
|
+
// and its value read as two columns instead of one run-on line. The cap
|
|
692
|
+
// is the harness's own idiom for a floating surface, so a narrow window
|
|
693
|
+
// shrinks the card rather than pushing it off the composer.
|
|
694
|
+
".dsh-model-allowance-panel{position:absolute;bottom:calc(100% + 6px);right:0;z-index:20;",
|
|
695
|
+
"box-sizing:border-box;min-width:300px;max-width:calc(100vw - 24px);",
|
|
696
|
+
"padding:8px 10px 10px;border:0;",
|
|
697
|
+
"border-radius:var(--dsw-radius-lg);background:var(--dsw-specific-menu);",
|
|
698
|
+
"backdrop-filter:var(--dsw-menu-backdrop-filter);",
|
|
699
|
+
"box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);",
|
|
700
|
+
"font-size:12px}",
|
|
701
|
+
".dsh-model-allowance-row{display:flex;justify-content:space-between;gap:16px;padding:2px 0}",
|
|
702
|
+
// Label first, value second, matching every other pair in the card
|
|
703
|
+
// (schedule title/state, status/reading time): the label carries the
|
|
704
|
+
// emphasis and the value reads as its detail. Reversed, the balance row
|
|
705
|
+
// stood out as the one pair laid out the other way round.
|
|
706
|
+
".dsh-model-allowance-row>span:first-child{color:var(--dsw-alias-label-primary)}",
|
|
707
|
+
".dsh-model-allowance-row>span:last-child{color:var(--dsw-alias-label-secondary)}",
|
|
708
|
+
".dsh-model-allowance-usage{font-variant-numeric:tabular-nums;",
|
|
709
|
+
"color:var(--dsw-alias-label-secondary)}",
|
|
710
|
+
// The row cancels the panel's own horizontal padding so the divider under
|
|
711
|
+
// it runs edge to edge, then puts the same padding back so the first mark
|
|
712
|
+
// lines up with the labels below. Without this the marks sit further from
|
|
713
|
+
// the edge than every other row and the whole strip reads as shifted left.
|
|
714
|
+
".dsh-model-allowance-switcher-wrap{position:relative;margin:-2px -10px 6px;",
|
|
715
|
+
"padding:0 10px 8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",
|
|
716
|
+
".dsh-model-allowance-switcher{display:flex;flex-wrap:nowrap;align-items:center;",
|
|
717
|
+
"gap:4px;overflow:hidden}",
|
|
718
|
+
// The mark sits straight on the panel; the chip draws no surface of its
|
|
719
|
+
// own, so the panel's own surface shows through behind the logo.
|
|
720
|
+
//
|
|
721
|
+
// A frame means one thing here: this is the provider being read. It is
|
|
722
|
+
// not used to say anything else about a route, because a second meaning
|
|
723
|
+
// makes an unselected mark look selected.
|
|
724
|
+
".dsh-model-allowance-tab{display:inline-flex;align-items:center;justify-content:center;",
|
|
725
|
+
"box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
726
|
+
"border:1px solid transparent;border-radius:var(--dsw-radius-sm);",
|
|
727
|
+
"background:0 0;line-height:1;cursor:pointer;",
|
|
728
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary));opacity:.66}",
|
|
729
|
+
".dsh-model-allowance-tab:hover{opacity:.9}",
|
|
730
|
+
// The selected mark gains the one frame the chip already has, and stops
|
|
731
|
+
// being dimmed. It must not use the brand colour: in this theme that is
|
|
732
|
+
// #0f1115, so a selected chip wore a near-black frame. It also gains no
|
|
733
|
+
// background, since any fill here reintroduces a tile on the panel.
|
|
734
|
+
'.dsh-model-allowance-tab[data-active="true"]{opacity:1;',
|
|
735
|
+
"border-color:var(--dsw-alias-border-l2)}",
|
|
736
|
+
".dsh-model-allowance-tab:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
737
|
+
"outline-offset:-1px}",
|
|
738
|
+
".dsh-model-allowance-tab svg{display:block}",
|
|
739
|
+
".dsh-model-allowance-tab-letter{font-size:11px;font-weight:600;line-height:1}",
|
|
740
|
+
".dsh-model-allowance-more{display:inline-flex;align-items:center;justify-content:center;",
|
|
741
|
+
"box-sizing:border-box;width:26px;height:26px;flex:none;margin-left:auto;padding:0;",
|
|
742
|
+
"border-radius:var(--dsw-radius-sm);",
|
|
743
|
+
"border:1px solid var(--dsw-alias-border-l1);background:0 0;cursor:pointer;",
|
|
744
|
+
"color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}",
|
|
745
|
+
".dsh-model-allowance-more:hover{color:var(--dsw-alias-label-secondary);",
|
|
746
|
+
"border-color:var(--dsw-alias-border-l2)}",
|
|
747
|
+
// The overflow menu is a second floating surface, so it carries the same
|
|
748
|
+
// menu surface and elevation as the card it belongs to.
|
|
749
|
+
".dsh-model-allowance-menu{position:absolute;top:calc(100% + 2px);right:0;z-index:30;",
|
|
750
|
+
"min-width:150px;padding:4px;border:0;",
|
|
751
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-specific-menu);",
|
|
752
|
+
"backdrop-filter:var(--dsw-menu-backdrop-filter);",
|
|
753
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
754
|
+
".dsh-model-allowance-menu-item{display:flex;align-items:center;gap:8px;width:100%;",
|
|
755
|
+
"padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);background:0 0;",
|
|
756
|
+
"color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
757
|
+
".dsh-model-allowance-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
758
|
+
// Same rule as the strip chips: no surface of its own, so the mark sits
|
|
759
|
+
// on the menu instead of on a tile.
|
|
760
|
+
".dsh-model-allowance-menu-mark{display:inline-flex;align-items:center;",
|
|
761
|
+
"justify-content:center;width:20px;height:20px;flex:none;border-radius:var(--dsw-radius-xs);",
|
|
762
|
+
"line-height:1;background:0 0;",
|
|
763
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary))}",
|
|
764
|
+
".dsh-model-allowance-menu-mark svg{display:block}",
|
|
765
|
+
".dsh-model-allowance-window{margin-top:10px;padding-top:10px;",
|
|
766
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
767
|
+
// The first window has no boundary above it: the switcher already ends
|
|
768
|
+
// in a divider, and a bare provider row should not be underlined.
|
|
769
|
+
'.dsh-model-allowance-window[data-first="true"]{margin-top:0;padding-top:8px;',
|
|
770
|
+
"border-top:0}",
|
|
771
|
+
".dsh-model-allowance-window-head{display:flex;justify-content:space-between;",
|
|
772
|
+
"align-items:baseline;gap:12px}",
|
|
773
|
+
".dsh-model-allowance-window-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
774
|
+
".dsh-model-allowance-percent{margin-top:2px;color:var(--dsw-alias-label-secondary);",
|
|
775
|
+
"font-size:11px;font-variant-numeric:tabular-nums}",
|
|
776
|
+
// The bar's track is the harness's own hover tint, not a white well: on
|
|
777
|
+
// a white card a white track was invisible, and the inset frame around
|
|
778
|
+
// it drew the eye to the groove instead of to the fill.
|
|
779
|
+
".dsh-model-allowance-bar{margin-top:6px;height:6px;border-radius:999px;overflow:hidden;",
|
|
780
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
781
|
+
".dsh-model-allowance-bar-fill{height:100%;border-radius:999px;",
|
|
782
|
+
"background:var(--dsw-alias-state-success-primary);transition:width 300ms ease}",
|
|
783
|
+
'.dsh-model-allowance-bar-fill[data-tone="warn"]{',
|
|
784
|
+
"background:var(--dsw-alias-state-warn-primary)}",
|
|
785
|
+
'.dsh-model-allowance-bar-fill[data-tone="error"]{',
|
|
786
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
787
|
+
".dsh-model-allowance-foot{display:flex;justify-content:space-between;",
|
|
788
|
+
"align-items:baseline;gap:10px;flex-wrap:wrap;margin-top:5px;",
|
|
789
|
+
"color:var(--dsw-alias-label-secondary);",
|
|
790
|
+
"font-size:11px;font-variant-numeric:tabular-nums;word-break:break-word}",
|
|
791
|
+
".dsh-model-allowance-error{padding:4px 0;color:var(--dsw-alias-state-error-primary)}",
|
|
792
|
+
".dsh-model-allowance-reason{padding:2px 0;color:var(--dsw-alias-label-secondary);",
|
|
793
|
+
"font-size:11px;word-break:break-word}",
|
|
794
|
+
// The footer is one right-aligned cluster: the reading time sits directly
|
|
795
|
+
// left of the two icon buttons.
|
|
796
|
+
".dsh-model-allowance-actions{display:flex;align-items:center;",
|
|
797
|
+
"justify-content:flex-end;gap:8px;margin-top:8px;padding-top:8px;",
|
|
798
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
799
|
+
".dsh-model-allowance-updated{color:var(--dsw-alias-label-secondary);font-size:11px;",
|
|
800
|
+
"font-variant-numeric:tabular-nums;white-space:nowrap;margin-right:2px}",
|
|
801
|
+
".dsh-model-allowance-icon-button{display:inline-flex;align-items:center;",
|
|
802
|
+
"justify-content:center;box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
803
|
+
"border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
804
|
+
"color:var(--dsw-alias-label-tertiary);cursor:pointer;text-decoration:none}",
|
|
805
|
+
".dsh-model-allowance-icon-button:hover{color:var(--dsw-alias-label-secondary);",
|
|
806
|
+
"border-color:var(--dsw-alias-border-l3);background:var(--dsw-alias-interactive-bg-hover)}",
|
|
807
|
+
".dsh-model-allowance-icon-button:focus-visible{",
|
|
808
|
+
"outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
|
|
809
|
+
".dsh-model-allowance-icon-button[disabled]{opacity:.5;cursor:default}",
|
|
810
|
+
".dsh-model-allowance-icon-button svg{display:block}",
|
|
811
|
+
// The platform status row: one dot whose colour is the state, the
|
|
812
|
+
// localized label, and a link to the source page when the vendor
|
|
813
|
+
// publishes one. It sits at the left edge of the footer, so the margin
|
|
814
|
+
// below pushes the reading time and the buttons to the right edge.
|
|
815
|
+
".dsh-model-allowance-status-wrap{display:inline-flex;align-items:center;gap:5px;",
|
|
816
|
+
"margin-right:auto;min-width:0;font-size:11px}",
|
|
817
|
+
".dsh-model-allowance-status{display:inline-flex;align-items:center;gap:5px;",
|
|
818
|
+
"color:var(--dsw-alias-label-primary);text-decoration:none}",
|
|
819
|
+
"a.dsh-model-allowance-status:hover{text-decoration:underline}",
|
|
820
|
+
".dsh-model-allowance-status-label{flex:none}",
|
|
821
|
+
// The degraded reason hides behind a warning mark: the footer keeps one
|
|
822
|
+
// row, and the detail is one hover away. The mark wears the same hue an
|
|
823
|
+
// exhausted allowance does, so the two warnings read alike.
|
|
824
|
+
".dsh-model-allowance-status-help{position:relative;display:inline-flex;",
|
|
825
|
+
"align-items:center;justify-content:center;box-sizing:border-box;width:14px;height:14px;",
|
|
826
|
+
"flex:none;border:1px solid var(--dsw-alias-state-error-primary);border-radius:50%;",
|
|
827
|
+
"color:var(--dsw-alias-state-error-primary);font-size:9px;font-weight:700;line-height:1;",
|
|
828
|
+
"cursor:help}",
|
|
829
|
+
".dsh-model-allowance-status-help:hover,",
|
|
830
|
+
".dsh-model-allowance-status-help:focus-visible{background:var(--dsw-alias-state-error-primary);",
|
|
831
|
+
"color:var(--dsw-alias-label-primary-foreground);outline:none}",
|
|
832
|
+
".dsh-model-allowance-status-tip{display:none;position:absolute;left:0;",
|
|
833
|
+
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
834
|
+
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
835
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
836
|
+
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
837
|
+
// The hint sits on the harness's own tooltip surface, so it takes the
|
|
838
|
+
// text colour that surface is read with: white on the dark tooltip.
|
|
839
|
+
"color:var(--dsw-static-neutral-bluish-00);",
|
|
840
|
+
"white-space:normal;text-align:left}",
|
|
841
|
+
".dsh-model-allowance-status-help:hover .dsh-model-allowance-status-tip,",
|
|
842
|
+
".dsh-model-allowance-status-help:focus-visible .dsh-model-allowance-status-tip{display:block}",
|
|
843
|
+
".dsh-model-allowance-status-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
844
|
+
"background:var(--dsw-alias-state-success-primary)}",
|
|
845
|
+
'.dsh-model-allowance-status[data-state="degraded"] .dsh-model-allowance-status-dot,',
|
|
846
|
+
'.dsh-model-allowance-status[data-state="maintenance"] .dsh-model-allowance-status-dot{',
|
|
847
|
+
"background:var(--dsw-alias-state-warn-primary)}",
|
|
848
|
+
'.dsh-model-allowance-status[data-state="partial-outage"] .dsh-model-allowance-status-dot,',
|
|
849
|
+
'.dsh-model-allowance-status[data-state="major-outage"] .dsh-model-allowance-status-dot{',
|
|
850
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
851
|
+
".dsh-model-allowance-status-arrow{font-size:10px;flex:none;",
|
|
852
|
+
"color:var(--dsw-alias-label-tertiary)}",
|
|
853
|
+
// The time-of-day pricing block: the phase the clock is in, how far
|
|
854
|
+
// through that stretch of time it is, and the countdown. The rule itself
|
|
855
|
+
// hides behind the help mark, so the card stays readable.
|
|
856
|
+
".dsh-model-allowance-schedule{margin-top:10px;padding-top:10px;",
|
|
857
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
858
|
+
".dsh-model-allowance-schedule-head{display:flex;justify-content:space-between;",
|
|
859
|
+
"align-items:center;gap:12px}",
|
|
860
|
+
".dsh-model-allowance-schedule-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
861
|
+
".dsh-model-allowance-schedule-help{position:relative;display:inline-flex;",
|
|
862
|
+
"align-items:center;justify-content:center;box-sizing:border-box;width:16px;height:16px;",
|
|
863
|
+
"flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:50%;",
|
|
864
|
+
"color:var(--dsw-alias-label-tertiary);font-size:10px;font-weight:600;line-height:1;",
|
|
865
|
+
"cursor:help}",
|
|
866
|
+
".dsh-model-allowance-schedule-help:hover,",
|
|
867
|
+
".dsh-model-allowance-schedule-help:focus-visible{color:var(--dsw-alias-label-primary);",
|
|
868
|
+
"border-color:var(--dsw-alias-label-secondary);outline:none}",
|
|
869
|
+
// Opens upwards: the block sits just above the footer, so a tooltip
|
|
870
|
+
// hanging below it would leave the panel.
|
|
871
|
+
".dsh-model-allowance-schedule-tip{display:none;position:absolute;right:0;",
|
|
872
|
+
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
873
|
+
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
874
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
875
|
+
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
876
|
+
"color:var(--dsw-static-neutral-bluish-00);",
|
|
877
|
+
"white-space:normal;text-align:left}",
|
|
878
|
+
".dsh-model-allowance-schedule-help:hover .dsh-model-allowance-schedule-tip,",
|
|
879
|
+
".dsh-model-allowance-schedule-help:focus-visible .dsh-model-allowance-schedule-tip{",
|
|
880
|
+
"display:block}",
|
|
881
|
+
".dsh-model-allowance-schedule-tip-line{display:block}",
|
|
882
|
+
// One 24-hour strip for the vendor's day: its peak windows tinted red
|
|
883
|
+
// and the off-peak day tinted green, both at low saturation so the
|
|
884
|
+
// strip reads at a glance without glaring, and a cursor where the
|
|
885
|
+
// clock stands.
|
|
886
|
+
".dsh-model-allowance-schedule-timeline{position:relative;margin-top:8px;height:8px;",
|
|
887
|
+
"border-radius:4px;overflow:hidden;",
|
|
888
|
+
"background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 12%,",
|
|
889
|
+
"var(--dsw-alias-interactive-bg-hover));}",
|
|
890
|
+
".dsh-model-allowance-schedule-timeline-peak{position:absolute;top:0;bottom:0;",
|
|
891
|
+
// The same hue the exhausted allowance uses, so "peak" and "spent" read
|
|
892
|
+
// as one family of warnings rather than two unrelated colours.
|
|
893
|
+
"background:var(--dsw-alias-state-error-primary);opacity:.4}",
|
|
894
|
+
".dsh-model-allowance-schedule-timeline-now{position:absolute;top:0;bottom:0;width:2px;",
|
|
895
|
+
"margin-left:-1px;border-radius:1px;background:var(--dsw-alias-label-primary);",
|
|
896
|
+
"box-shadow:0 0 0 1px var(--dsw-alias-bg-layer-1)}",
|
|
897
|
+
".dsh-model-allowance-schedule-ticks{display:flex;justify-content:space-between;",
|
|
898
|
+
"margin-top:2px;font-size:9px;line-height:1;color:var(--dsw-alias-label-secondary);",
|
|
899
|
+
"font-variant-numeric:tabular-nums}",
|
|
900
|
+
".dsh-model-allowance-schedule-countdown{margin-top:4px;text-align:right;font-size:11px;",
|
|
901
|
+
"color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
|
|
902
|
+
// A badge that fades or grows while a user asks for less motion is noise.
|
|
903
|
+
"@media (prefers-reduced-motion:reduce){.dsh-model-allowance-delta{animation:none}",
|
|
904
|
+
".dsh-model-allowance-bar-fill{transition:none}}"
|
|
905
|
+
];
|
|
906
|
+
var STYLES_JOINED = STYLES.join("");
|
|
907
|
+
|
|
908
|
+
// src/client/windows.js
|
|
909
|
+
function windowTitle(window, t) {
|
|
910
|
+
const label = window.label?.[activeLanguage()] ?? window.label?.en ?? window.label?.zh;
|
|
911
|
+
if (typeof label === "string" && label !== "") return label;
|
|
912
|
+
if (window.unit === "hour" && window.count) {
|
|
913
|
+
return t("window.title.hour", { count: window.count });
|
|
914
|
+
}
|
|
915
|
+
if (window.unit === "week") return t("window.title.week");
|
|
916
|
+
if (window.unit === "day" && window.count === 7) return t("window.title.week");
|
|
917
|
+
if (window.unit === "day" && window.count) {
|
|
918
|
+
return t("window.title.day", { count: window.count });
|
|
919
|
+
}
|
|
920
|
+
if (window.unit === "month") return t("window.title.month");
|
|
921
|
+
return t("window.title.unknown");
|
|
922
|
+
}
|
|
923
|
+
function windowUsedPercent(window) {
|
|
924
|
+
if (typeof window.remainingPercent === "number") return 100 - window.remainingPercent;
|
|
925
|
+
if (typeof window.used === "number" && typeof window.total === "number" && window.total > 0) {
|
|
926
|
+
return window.used / window.total * 100;
|
|
927
|
+
}
|
|
928
|
+
return void 0;
|
|
929
|
+
}
|
|
930
|
+
var UNIT_MS = {
|
|
931
|
+
hour: 36e5,
|
|
932
|
+
day: 864e5,
|
|
933
|
+
week: 7 * 864e5,
|
|
934
|
+
month: 30 * 864e5
|
|
935
|
+
};
|
|
936
|
+
function shortestWindow(windows) {
|
|
937
|
+
let shortest;
|
|
938
|
+
let shortestMs = Number.POSITIVE_INFINITY;
|
|
939
|
+
for (const window of windows) {
|
|
940
|
+
if (typeof window.remainingPercent !== "number") continue;
|
|
941
|
+
const unit = UNIT_MS[window.unit];
|
|
942
|
+
if (unit === void 0) continue;
|
|
943
|
+
const count = typeof window.count === "number" && window.count > 0 ? window.count : 1;
|
|
944
|
+
const lengthMs = unit * count;
|
|
945
|
+
if (lengthMs < shortestMs) {
|
|
946
|
+
shortest = window;
|
|
947
|
+
shortestMs = lengthMs;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return shortest;
|
|
951
|
+
}
|
|
952
|
+
function windowUsage(window, t) {
|
|
953
|
+
if (typeof window.total !== "number" || typeof window.used !== "number") return void 0;
|
|
954
|
+
return t("window.usedOfTotal", {
|
|
955
|
+
used: formatNumber(window.used),
|
|
956
|
+
total: formatNumber(window.total)
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
function barTone(percent) {
|
|
960
|
+
if (percent >= 85) return "error";
|
|
961
|
+
if (percent >= 60) return "warn";
|
|
962
|
+
return "ok";
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// src/client/badge.js
|
|
966
|
+
function BalanceBadge(props) {
|
|
967
|
+
const { useProjection, ctx, t } = props;
|
|
968
|
+
const selection = useProjection("modelSelection");
|
|
969
|
+
const selected = selection?.next?.provider ?? selection?.lastUsed?.provider ?? null;
|
|
970
|
+
const selectedModel = selection?.next?.model ?? selection?.lastUsed?.model ?? void 0;
|
|
971
|
+
const [rawView, setView] = React.useState(null);
|
|
972
|
+
const [loading, setLoading] = React.useState(false);
|
|
973
|
+
const [open, setOpen] = React.useState(false);
|
|
974
|
+
const [refreshing, setRefreshing] = React.useState(false);
|
|
975
|
+
const rootRef = React.useRef(null);
|
|
976
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
977
|
+
const [picked, setPicked] = React.useState(null);
|
|
978
|
+
const [directory, setDirectory] = React.useState([]);
|
|
979
|
+
const lastModelProvider = React.useRef(null);
|
|
980
|
+
const available = directory.filter((entry) => entry.configured);
|
|
981
|
+
const entryOf = (route) => directory.find((entry) => entry.route === route);
|
|
982
|
+
const nameOf = (route) => pickName(entryOf(route), route);
|
|
983
|
+
const markFor = (route) => markOf(entryOf(route), route);
|
|
984
|
+
const [menuOpen, setMenuOpen] = React.useState(false);
|
|
985
|
+
const [stripWidth, setStripWidth] = React.useState(0);
|
|
986
|
+
const stripRef = React.useRef(null);
|
|
987
|
+
const [defaultProvider, setDefaultProvider] = React.useState(null);
|
|
988
|
+
const [providerStatus, setProviderStatus] = React.useState(null);
|
|
989
|
+
const [schedule, setSchedule] = React.useState(null);
|
|
990
|
+
React.useEffect(() => {
|
|
991
|
+
let cancelled = false;
|
|
992
|
+
(async () => {
|
|
993
|
+
try {
|
|
994
|
+
const api = await getBalanceApi();
|
|
995
|
+
if (!api || typeof api.list !== "function") return;
|
|
996
|
+
const result = await api.list();
|
|
997
|
+
if (cancelled || !result.ok) return;
|
|
998
|
+
setDirectory(result.value);
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
console.error("[model-allowance] listing providers failed", { error });
|
|
1001
|
+
}
|
|
1002
|
+
})();
|
|
1003
|
+
return () => {
|
|
1004
|
+
cancelled = true;
|
|
1005
|
+
};
|
|
1006
|
+
}, []);
|
|
1007
|
+
React.useEffect(() => {
|
|
1008
|
+
if (selected !== null) return void 0;
|
|
1009
|
+
let cancelled = false;
|
|
1010
|
+
(async () => {
|
|
1011
|
+
try {
|
|
1012
|
+
const api = await getBalanceApi();
|
|
1013
|
+
if (!api || typeof api.defaultProvider !== "function") return;
|
|
1014
|
+
const result = await api.defaultProvider();
|
|
1015
|
+
if (cancelled || result?.ok !== true) return;
|
|
1016
|
+
const provider2 = result.value?.provider;
|
|
1017
|
+
if (typeof provider2 === "string" && provider2 !== "") setDefaultProvider(provider2);
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
console.error("[model-allowance] reading the default provider failed", { error });
|
|
1020
|
+
}
|
|
1021
|
+
})();
|
|
1022
|
+
return () => {
|
|
1023
|
+
cancelled = true;
|
|
1024
|
+
};
|
|
1025
|
+
}, [selected]);
|
|
1026
|
+
const provider = selected ?? defaultProvider;
|
|
1027
|
+
const selectionKey = `${provider ?? ""}\0${selectedModel ?? ""}`;
|
|
1028
|
+
React.useEffect(() => {
|
|
1029
|
+
if (lastModelProvider.current === selectionKey) return;
|
|
1030
|
+
lastModelProvider.current = selectionKey;
|
|
1031
|
+
setPicked(null);
|
|
1032
|
+
});
|
|
1033
|
+
const activeProvider = picked ?? provider;
|
|
1034
|
+
const activeModel = picked === null || picked === provider ? selectedModel : void 0;
|
|
1035
|
+
const view = rawView?.provider === activeProvider ? rawView : null;
|
|
1036
|
+
React.useEffect(() => {
|
|
1037
|
+
if (open) return;
|
|
1038
|
+
setPicked(null);
|
|
1039
|
+
setMenuOpen(false);
|
|
1040
|
+
}, [open]);
|
|
1041
|
+
React.useEffect(() => {
|
|
1042
|
+
if (!open) return;
|
|
1043
|
+
const node = stripRef.current;
|
|
1044
|
+
if (!node) return;
|
|
1045
|
+
const measure = () => setStripWidth(node.clientWidth ?? 0);
|
|
1046
|
+
measure();
|
|
1047
|
+
if (typeof ResizeObserver !== "function") return;
|
|
1048
|
+
const observer = new ResizeObserver(measure);
|
|
1049
|
+
observer.observe(node);
|
|
1050
|
+
return () => observer.disconnect();
|
|
1051
|
+
}, [open]);
|
|
1052
|
+
React.useEffect(() => {
|
|
1053
|
+
if (!open) return;
|
|
1054
|
+
const onPointerDown = (event) => {
|
|
1055
|
+
const root = rootRef.current;
|
|
1056
|
+
if (root && event.target instanceof Node && root.contains(event.target)) return;
|
|
1057
|
+
setOpen(false);
|
|
1058
|
+
};
|
|
1059
|
+
const onKeyDown = (event) => {
|
|
1060
|
+
if (event.key === "Escape") setOpen(false);
|
|
1061
|
+
};
|
|
1062
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1063
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1064
|
+
return () => {
|
|
1065
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1066
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1067
|
+
};
|
|
1068
|
+
}, [open]);
|
|
1069
|
+
const showingDifference = consumptionFreshAt(view?.consumption, now);
|
|
1070
|
+
React.useEffect(() => {
|
|
1071
|
+
if (!open && !showingDifference) return;
|
|
1072
|
+
setNow(Date.now());
|
|
1073
|
+
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
1074
|
+
return () => clearInterval(timer);
|
|
1075
|
+
}, [open, showingDifference]);
|
|
1076
|
+
React.useEffect(() => {
|
|
1077
|
+
if (!open) return;
|
|
1078
|
+
let cancelled = false;
|
|
1079
|
+
(async () => {
|
|
1080
|
+
try {
|
|
1081
|
+
const api = await getBalanceApi();
|
|
1082
|
+
if (!api || typeof api.list !== "function") return;
|
|
1083
|
+
const result = await api.list();
|
|
1084
|
+
if (cancelled || !result.ok) return;
|
|
1085
|
+
setDirectory(result.value);
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
console.error("[model-allowance] listing providers failed", { error });
|
|
1088
|
+
}
|
|
1089
|
+
})();
|
|
1090
|
+
return () => {
|
|
1091
|
+
cancelled = true;
|
|
1092
|
+
};
|
|
1093
|
+
}, [open]);
|
|
1094
|
+
React.useEffect(() => {
|
|
1095
|
+
if (!activeProvider) {
|
|
1096
|
+
setView(null);
|
|
1097
|
+
setLoading(false);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
let cancelled = false;
|
|
1101
|
+
let handle;
|
|
1102
|
+
setLoading(true);
|
|
1103
|
+
const readOnce = async (api, model) => {
|
|
1104
|
+
try {
|
|
1105
|
+
let result = await api.balance(activeProvider, model);
|
|
1106
|
+
if (!result.ok && model !== void 0) {
|
|
1107
|
+
result = await api.balance(activeProvider, void 0);
|
|
1108
|
+
}
|
|
1109
|
+
if (cancelled) return;
|
|
1110
|
+
if (!result.ok) {
|
|
1111
|
+
const detail = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "balance reading failed";
|
|
1112
|
+
throw new Error(detail);
|
|
1113
|
+
}
|
|
1114
|
+
setView(result.value);
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
console.error("[model-allowance] reading failed", {
|
|
1117
|
+
provider: activeProvider,
|
|
1118
|
+
model,
|
|
1119
|
+
error
|
|
1120
|
+
});
|
|
1121
|
+
if (!cancelled) {
|
|
1122
|
+
setView({
|
|
1123
|
+
provider: activeProvider,
|
|
1124
|
+
status: "failed",
|
|
1125
|
+
kind: "quota",
|
|
1126
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
} finally {
|
|
1130
|
+
if (!cancelled) setLoading(false);
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
(async () => {
|
|
1134
|
+
const api = await getBalanceApi();
|
|
1135
|
+
if (cancelled) return;
|
|
1136
|
+
if (!api) {
|
|
1137
|
+
setView({
|
|
1138
|
+
provider: activeProvider,
|
|
1139
|
+
status: "failed",
|
|
1140
|
+
kind: "quota",
|
|
1141
|
+
error: "balance namespace unavailable"
|
|
1142
|
+
});
|
|
1143
|
+
setLoading(false);
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
const readModel = await supportsModel(api) ? activeModel : void 0;
|
|
1147
|
+
if (cancelled) return;
|
|
1148
|
+
const remote = ctx.remote;
|
|
1149
|
+
if (typeof remote?.$stream === "function" && typeof api.watch === "function") {
|
|
1150
|
+
try {
|
|
1151
|
+
handle = remote.$stream({
|
|
1152
|
+
name: "balance",
|
|
1153
|
+
open: (signal) => api.watch(activeProvider, readModel, signal),
|
|
1154
|
+
ended: () => new Error("balance stream ended")
|
|
1155
|
+
});
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
console.error("[model-allowance] opening the reading stream failed", { error });
|
|
1158
|
+
handle = void 0;
|
|
1159
|
+
}
|
|
1160
|
+
if (handle) {
|
|
1161
|
+
let received = false;
|
|
1162
|
+
try {
|
|
1163
|
+
for await (const item of handle) {
|
|
1164
|
+
if (cancelled) return;
|
|
1165
|
+
const frame = item?.value;
|
|
1166
|
+
if (frame === void 0) continue;
|
|
1167
|
+
received = true;
|
|
1168
|
+
setView(frame);
|
|
1169
|
+
setLoading(false);
|
|
1170
|
+
item?.accept?.();
|
|
1171
|
+
}
|
|
1172
|
+
} catch (error) {
|
|
1173
|
+
if (!cancelled) {
|
|
1174
|
+
console.error("[model-allowance] reading stream failed", {
|
|
1175
|
+
provider: activeProvider,
|
|
1176
|
+
error
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
} finally {
|
|
1180
|
+
if (!cancelled && !received) await readOnce(api, readModel);
|
|
1181
|
+
}
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
await readOnce(api, readModel);
|
|
1186
|
+
})();
|
|
1187
|
+
return () => {
|
|
1188
|
+
cancelled = true;
|
|
1189
|
+
handle?.dispose?.();
|
|
1190
|
+
};
|
|
1191
|
+
}, [activeProvider, activeModel, ctx]);
|
|
1192
|
+
React.useEffect(() => {
|
|
1193
|
+
if (!activeProvider) return void 0;
|
|
1194
|
+
let cancelled = false;
|
|
1195
|
+
const readStatus = async () => {
|
|
1196
|
+
try {
|
|
1197
|
+
const api = await getBalanceApi();
|
|
1198
|
+
if (!api || typeof api.status !== "function") return;
|
|
1199
|
+
const result = await api.status(activeProvider);
|
|
1200
|
+
if (cancelled || !result.ok) return;
|
|
1201
|
+
setProviderStatus(result.value);
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
console.error("[model-allowance] reading provider status failed", { error });
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
void readStatus();
|
|
1207
|
+
const timer = setInterval(readStatus, STATUS_REFRESH_MS);
|
|
1208
|
+
return () => {
|
|
1209
|
+
cancelled = true;
|
|
1210
|
+
clearInterval(timer);
|
|
1211
|
+
};
|
|
1212
|
+
}, [activeProvider]);
|
|
1213
|
+
React.useEffect(() => {
|
|
1214
|
+
if (!activeProvider) return void 0;
|
|
1215
|
+
let cancelled = false;
|
|
1216
|
+
(async () => {
|
|
1217
|
+
try {
|
|
1218
|
+
const api = await getBalanceApi();
|
|
1219
|
+
if (!api || typeof api.schedule !== "function") return;
|
|
1220
|
+
const result = await api.schedule(activeProvider);
|
|
1221
|
+
if (cancelled || !result.ok) return;
|
|
1222
|
+
setSchedule(result.value);
|
|
1223
|
+
} catch (error) {
|
|
1224
|
+
console.error("[model-allowance] reading the pricing schedule failed", { error });
|
|
1225
|
+
}
|
|
1226
|
+
})();
|
|
1227
|
+
return () => {
|
|
1228
|
+
cancelled = true;
|
|
1229
|
+
};
|
|
1230
|
+
}, [activeProvider]);
|
|
1231
|
+
const refresh = React.useCallback(async () => {
|
|
1232
|
+
setRefreshing(true);
|
|
1233
|
+
try {
|
|
1234
|
+
const api = await getBalanceApi();
|
|
1235
|
+
if (!api) return;
|
|
1236
|
+
const readModel = await supportsModel(api) ? activeModel : void 0;
|
|
1237
|
+
let result = await api.refresh(activeProvider, readModel);
|
|
1238
|
+
if (!result.ok && readModel !== void 0) {
|
|
1239
|
+
result = await api.refresh(activeProvider, void 0);
|
|
1240
|
+
}
|
|
1241
|
+
if (result.ok) setView(result.value);
|
|
1242
|
+
if (typeof api.status === "function") {
|
|
1243
|
+
const status = await api.status(activeProvider);
|
|
1244
|
+
if (status.ok) setProviderStatus(status.value);
|
|
1245
|
+
}
|
|
1246
|
+
} catch (error) {
|
|
1247
|
+
console.error("[model-allowance] refresh failed", {
|
|
1248
|
+
provider: activeProvider,
|
|
1249
|
+
model: activeModel,
|
|
1250
|
+
error
|
|
1251
|
+
});
|
|
1252
|
+
} finally {
|
|
1253
|
+
setRefreshing(false);
|
|
1254
|
+
}
|
|
1255
|
+
}, [activeProvider, activeModel]);
|
|
1256
|
+
const label = React.useMemo(() => {
|
|
1257
|
+
if (!provider) return "";
|
|
1258
|
+
if (!view) return t("badge.loading");
|
|
1259
|
+
if (view.status === "ready") {
|
|
1260
|
+
if (view.kind === "amount" && typeof view.amount === "number") {
|
|
1261
|
+
return t("badge.amount", { amount: formatAmount(view.amount, view.currency) });
|
|
1262
|
+
}
|
|
1263
|
+
const windows = Array.isArray(view.windows) ? view.windows : [];
|
|
1264
|
+
const exhausted = windows.some(
|
|
1265
|
+
(window) => typeof window.remainingPercent === "number" && window.remainingPercent <= 0
|
|
1266
|
+
);
|
|
1267
|
+
const percent = exhausted ? 0 : shortestWindow(windows)?.remainingPercent ?? view.percent;
|
|
1268
|
+
if (typeof percent === "number") {
|
|
1269
|
+
return t("badge.quotaPercent", { percent: Math.round(percent) });
|
|
1270
|
+
}
|
|
1271
|
+
if (typeof view.remainingMs === "number") {
|
|
1272
|
+
return t("badge.quotaDuration", {
|
|
1273
|
+
duration: formatDuration(view.remainingMs, t)
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
if (typeof view.remaining === "number" && typeof view.total === "number") {
|
|
1277
|
+
return t("badge.quotaRatio", { remaining: view.remaining, total: view.total });
|
|
1278
|
+
}
|
|
1279
|
+
if (typeof view.remaining === "number") {
|
|
1280
|
+
return t("badge.quotaRatio", { remaining: view.remaining, total: "\u2014" });
|
|
1281
|
+
}
|
|
1282
|
+
return t("badge.noData");
|
|
1283
|
+
}
|
|
1284
|
+
if (view.status === "unsupported") return t("badge.unsupported");
|
|
1285
|
+
if (view.status === "unconfigured") return t("badge.unconfigured");
|
|
1286
|
+
return t("badge.failed");
|
|
1287
|
+
}, [view, provider, t]);
|
|
1288
|
+
if (!provider) return null;
|
|
1289
|
+
const serviceState = providerStatus && providerStatus.provider === activeProvider ? providerStatus.state : "unknown";
|
|
1290
|
+
const MARK_SIZE = 26;
|
|
1291
|
+
const MARK_GAP = 4;
|
|
1292
|
+
const MENU_SIZE = 26;
|
|
1293
|
+
const perMark = MARK_SIZE + MARK_GAP;
|
|
1294
|
+
let visibleCount = available.length;
|
|
1295
|
+
if (stripWidth > 0 && available.length * perMark - MARK_GAP > stripWidth) {
|
|
1296
|
+
visibleCount = Math.max(1, Math.floor((stripWidth - MENU_SIZE - MARK_GAP) / perMark));
|
|
1297
|
+
visibleCount = Math.min(visibleCount, available.length - 1);
|
|
1298
|
+
}
|
|
1299
|
+
let shown = available.slice(0, visibleCount);
|
|
1300
|
+
let overflow = available.slice(visibleCount);
|
|
1301
|
+
const activeIndex = overflow.findIndex((entry) => entry.route === activeProvider);
|
|
1302
|
+
if (activeIndex >= 0 && shown.length > 0) {
|
|
1303
|
+
const displaced = shown[shown.length - 1];
|
|
1304
|
+
shown = [...shown.slice(0, -1), overflow[activeIndex]];
|
|
1305
|
+
overflow = [...overflow.slice(0, activeIndex), displaced, ...overflow.slice(activeIndex + 1)];
|
|
1306
|
+
}
|
|
1307
|
+
const markButton = (entry) => {
|
|
1308
|
+
const mark = markFor(entry.route);
|
|
1309
|
+
const name = nameOf(entry.route);
|
|
1310
|
+
return (0, import_react3.createElement)(
|
|
1311
|
+
"button",
|
|
1312
|
+
{
|
|
1313
|
+
type: "button",
|
|
1314
|
+
key: entry.route,
|
|
1315
|
+
role: "tab",
|
|
1316
|
+
className: "dsh-model-allowance-tab",
|
|
1317
|
+
"data-active": entry.route === activeProvider ? "true" : "false",
|
|
1318
|
+
"aria-selected": entry.route === activeProvider ? "true" : "false",
|
|
1319
|
+
"aria-label": name,
|
|
1320
|
+
title: name,
|
|
1321
|
+
style: { "--provider-mark": mark.color },
|
|
1322
|
+
onClick: () => {
|
|
1323
|
+
setPicked(entry.route);
|
|
1324
|
+
setMenuOpen(false);
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
providerIcon(entry.route, 14, mark)
|
|
1328
|
+
);
|
|
1329
|
+
};
|
|
1330
|
+
const onTabKeyDown = (event) => {
|
|
1331
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
1332
|
+
const tabs = [...event.currentTarget.querySelectorAll('[role="tab"]')];
|
|
1333
|
+
if (tabs.length === 0) return;
|
|
1334
|
+
const index = tabs.indexOf(document.activeElement);
|
|
1335
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + tabs.length) % tabs.length;
|
|
1336
|
+
event.preventDefault();
|
|
1337
|
+
tabs[next]?.focus();
|
|
1338
|
+
};
|
|
1339
|
+
return (0, import_react3.createElement)(
|
|
1340
|
+
"div",
|
|
1341
|
+
{
|
|
1342
|
+
ref: rootRef,
|
|
1343
|
+
className: "dsh-model-allowance-root",
|
|
1344
|
+
"data-service": serviceState,
|
|
1345
|
+
"data-loading": loading ? "true" : "false"
|
|
1346
|
+
},
|
|
1347
|
+
// Component-local styles: React removes them with the component, and
|
|
1348
|
+
// every colour comes from a theme token so light and dark both follow.
|
|
1349
|
+
(0, import_react3.createElement)("style", { key: "styles" }, STYLES_JOINED),
|
|
1350
|
+
(0, import_react3.createElement)(
|
|
1351
|
+
"button",
|
|
1352
|
+
{
|
|
1353
|
+
type: "button",
|
|
1354
|
+
className: "dsh-model-allowance-badge",
|
|
1355
|
+
"data-provider": activeProvider,
|
|
1356
|
+
"aria-expanded": open ? "true" : "false",
|
|
1357
|
+
"aria-controls": open ? "dsh-model-allowance-panel" : void 0,
|
|
1358
|
+
onClick: () => setOpen((value) => !value)
|
|
1359
|
+
},
|
|
1360
|
+
(0, import_react3.createElement)("span", { className: "dsh-model-allowance-dot", "aria-hidden": true }),
|
|
1361
|
+
(0, import_react3.createElement)("span", { className: "dsh-model-allowance-label" }, label),
|
|
1362
|
+
// How far the number moved since the last reading, for a few seconds
|
|
1363
|
+
// after it lands. The arrow follows the number shown beside it: down
|
|
1364
|
+
// means the balance fell.
|
|
1365
|
+
showingDifference ? (0, import_react3.createElement)(
|
|
1366
|
+
"span",
|
|
1367
|
+
{
|
|
1368
|
+
className: "dsh-model-allowance-delta",
|
|
1369
|
+
"data-direction": view.consumption.delta < 0 ? "down" : "up",
|
|
1370
|
+
title: t("badge.consumption")
|
|
1371
|
+
},
|
|
1372
|
+
`${view.consumption.delta < 0 ? "\u2193" : "\u2191"}${formatDelta(view.consumption)}`
|
|
1373
|
+
) : null
|
|
1374
|
+
),
|
|
1375
|
+
open ? (0, import_react3.createElement)(
|
|
1376
|
+
"div",
|
|
1377
|
+
{
|
|
1378
|
+
className: "dsh-model-allowance-panel",
|
|
1379
|
+
id: "dsh-model-allowance-panel",
|
|
1380
|
+
role: "dialog",
|
|
1381
|
+
"aria-label": t("detail.title")
|
|
1382
|
+
},
|
|
1383
|
+
// With more than one readable provider the card opens a switcher;
|
|
1384
|
+
// with one there is nothing to switch, so it just names it.
|
|
1385
|
+
available.length > 1 ? (0, import_react3.createElement)(
|
|
1386
|
+
// The clipping strip and the menu are siblings: the strip
|
|
1387
|
+
// hides what does not fit, and the menu would be clipped
|
|
1388
|
+
// with it if it lived inside.
|
|
1389
|
+
"div",
|
|
1390
|
+
{ className: "dsh-model-allowance-switcher-wrap" },
|
|
1391
|
+
(0, import_react3.createElement)(
|
|
1392
|
+
"div",
|
|
1393
|
+
{
|
|
1394
|
+
ref: stripRef,
|
|
1395
|
+
className: "dsh-model-allowance-switcher",
|
|
1396
|
+
role: "tablist",
|
|
1397
|
+
"aria-label": t("detail.provider"),
|
|
1398
|
+
onKeyDown: onTabKeyDown
|
|
1399
|
+
},
|
|
1400
|
+
...shown.map(markButton),
|
|
1401
|
+
overflow.length > 0 ? (0, import_react3.createElement)(
|
|
1402
|
+
"button",
|
|
1403
|
+
{
|
|
1404
|
+
type: "button",
|
|
1405
|
+
className: "dsh-model-allowance-more",
|
|
1406
|
+
"aria-haspopup": "menu",
|
|
1407
|
+
"aria-expanded": menuOpen ? "true" : "false",
|
|
1408
|
+
"aria-label": t("detail.moreProviders"),
|
|
1409
|
+
title: t("detail.moreProviders"),
|
|
1410
|
+
onClick: () => setMenuOpen((value) => !value)
|
|
1411
|
+
},
|
|
1412
|
+
"\u22EF"
|
|
1413
|
+
) : null
|
|
1414
|
+
),
|
|
1415
|
+
menuOpen && overflow.length > 0 ? (0, import_react3.createElement)(
|
|
1416
|
+
"div",
|
|
1417
|
+
{ className: "dsh-model-allowance-menu", role: "menu" },
|
|
1418
|
+
...overflow.map(
|
|
1419
|
+
(entry) => (0, import_react3.createElement)(
|
|
1420
|
+
"button",
|
|
1421
|
+
{
|
|
1422
|
+
type: "button",
|
|
1423
|
+
key: entry.route,
|
|
1424
|
+
role: "menuitem",
|
|
1425
|
+
className: "dsh-model-allowance-menu-item",
|
|
1426
|
+
onClick: () => {
|
|
1427
|
+
setPicked(entry.route);
|
|
1428
|
+
setMenuOpen(false);
|
|
1429
|
+
}
|
|
1430
|
+
},
|
|
1431
|
+
(0, import_react3.createElement)(
|
|
1432
|
+
"span",
|
|
1433
|
+
{
|
|
1434
|
+
className: "dsh-model-allowance-menu-mark",
|
|
1435
|
+
style: { "--provider-mark": markFor(entry.route).color }
|
|
1436
|
+
},
|
|
1437
|
+
providerIcon(entry.route, 11, markFor(entry.route))
|
|
1438
|
+
),
|
|
1439
|
+
(0, import_react3.createElement)("span", null, nameOf(entry.route))
|
|
1440
|
+
)
|
|
1441
|
+
)
|
|
1442
|
+
) : null
|
|
1443
|
+
) : (0, import_react3.createElement)(
|
|
1444
|
+
"div",
|
|
1445
|
+
{ className: "dsh-model-allowance-row" },
|
|
1446
|
+
(0, import_react3.createElement)("span", null, t("detail.provider")),
|
|
1447
|
+
(0, import_react3.createElement)("span", null, nameOf(activeProvider))
|
|
1448
|
+
),
|
|
1449
|
+
view?.kind === "amount" && typeof view.amount === "number" ? (0, import_react3.createElement)(
|
|
1450
|
+
"div",
|
|
1451
|
+
{ className: "dsh-model-allowance-row" },
|
|
1452
|
+
(0, import_react3.createElement)("span", null, t("detail.amount")),
|
|
1453
|
+
(0, import_react3.createElement)("span", null, formatAmount(view.amount, view.currency))
|
|
1454
|
+
) : null,
|
|
1455
|
+
...Array.isArray(view?.windows) && view.windows.length > 0 ? view.windows.map((window, index) => {
|
|
1456
|
+
const consumed = windowUsedPercent(window);
|
|
1457
|
+
const percent = consumed === void 0 ? void 0 : Math.max(0, Math.round(consumed));
|
|
1458
|
+
const filled = consumed === void 0 ? 0 : Math.min(100, Math.max(0, consumed));
|
|
1459
|
+
const usage = windowUsage(window, t);
|
|
1460
|
+
return (0, import_react3.createElement)(
|
|
1461
|
+
"div",
|
|
1462
|
+
{
|
|
1463
|
+
className: "dsh-model-allowance-window",
|
|
1464
|
+
key: `w-${String(index)}`,
|
|
1465
|
+
// The first block needs no divider: the switcher above
|
|
1466
|
+
// it already ends in one, and a bare provider row does
|
|
1467
|
+
// not deserve a line either. Only the boundaries
|
|
1468
|
+
// *between* windows are drawn.
|
|
1469
|
+
"data-first": index === 0 ? "true" : void 0
|
|
1470
|
+
},
|
|
1471
|
+
(0, import_react3.createElement)(
|
|
1472
|
+
"div",
|
|
1473
|
+
{ className: "dsh-model-allowance-window-head" },
|
|
1474
|
+
(0, import_react3.createElement)(
|
|
1475
|
+
"span",
|
|
1476
|
+
{ className: "dsh-model-allowance-window-title" },
|
|
1477
|
+
windowTitle(window, t)
|
|
1478
|
+
),
|
|
1479
|
+
// Countable units sit beside the title; a plan that
|
|
1480
|
+
// reports only a percentage has none to show.
|
|
1481
|
+
usage === void 0 ? null : (0, import_react3.createElement)("span", { className: "dsh-model-allowance-usage" }, usage)
|
|
1482
|
+
),
|
|
1483
|
+
percent === void 0 ? null : (0, import_react3.createElement)(
|
|
1484
|
+
"div",
|
|
1485
|
+
{ className: "dsh-model-allowance-percent" },
|
|
1486
|
+
t("window.usedPercent", { percent })
|
|
1487
|
+
),
|
|
1488
|
+
percent === void 0 ? null : (0, import_react3.createElement)(
|
|
1489
|
+
"div",
|
|
1490
|
+
{
|
|
1491
|
+
className: "dsh-model-allowance-bar",
|
|
1492
|
+
role: "progressbar",
|
|
1493
|
+
"aria-valuenow": percent,
|
|
1494
|
+
"aria-valuemin": 0,
|
|
1495
|
+
"aria-valuemax": 100,
|
|
1496
|
+
"aria-valuetext": t("window.usedPercent", { percent })
|
|
1497
|
+
},
|
|
1498
|
+
(0, import_react3.createElement)("div", {
|
|
1499
|
+
className: "dsh-model-allowance-bar-fill",
|
|
1500
|
+
"data-tone": barTone(percent),
|
|
1501
|
+
style: { width: `${String(filled)}%` }
|
|
1502
|
+
})
|
|
1503
|
+
),
|
|
1504
|
+
// A window the account has not started spending yet has no
|
|
1505
|
+
// reset to report, and saying so would be a line of noise.
|
|
1506
|
+
// Otherwise the countdown holds the left edge and the
|
|
1507
|
+
// target instant the right, so the eye can compare them.
|
|
1508
|
+
typeof window.resetAt === "number" ? (0, import_react3.createElement)(
|
|
1509
|
+
"div",
|
|
1510
|
+
{ className: "dsh-model-allowance-foot" },
|
|
1511
|
+
(0, import_react3.createElement)(
|
|
1512
|
+
"span",
|
|
1513
|
+
null,
|
|
1514
|
+
t("window.resetIn", {
|
|
1515
|
+
duration: formatCountdown(window.resetAt - now)
|
|
1516
|
+
})
|
|
1517
|
+
),
|
|
1518
|
+
(0, import_react3.createElement)("span", null, formatResetAt(window.resetAt))
|
|
1519
|
+
) : null
|
|
1520
|
+
);
|
|
1521
|
+
}) : [],
|
|
1522
|
+
// A single scalar reading has no windows to break down.
|
|
1523
|
+
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0, import_react3.createElement)(
|
|
1524
|
+
"div",
|
|
1525
|
+
{ className: "dsh-model-allowance-row" },
|
|
1526
|
+
(0, import_react3.createElement)("span", null, t("detail.remaining")),
|
|
1527
|
+
(0, import_react3.createElement)("span", null, formatDuration(view.remainingMs, t))
|
|
1528
|
+
) : null,
|
|
1529
|
+
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0, import_react3.createElement)(
|
|
1530
|
+
"div",
|
|
1531
|
+
{ className: "dsh-model-allowance-row" },
|
|
1532
|
+
(0, import_react3.createElement)("span", null, t("detail.remaining")),
|
|
1533
|
+
(0, import_react3.createElement)("span", null, String(view.remaining))
|
|
1534
|
+
) : null,
|
|
1535
|
+
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0, import_react3.createElement)(
|
|
1536
|
+
"div",
|
|
1537
|
+
{ className: "dsh-model-allowance-row" },
|
|
1538
|
+
(0, import_react3.createElement)("span", null, t("detail.total")),
|
|
1539
|
+
(0, import_react3.createElement)("span", null, String(view.total))
|
|
1540
|
+
) : null,
|
|
1541
|
+
view?.status === "failed" ? (0, import_react3.createElement)(
|
|
1542
|
+
"div",
|
|
1543
|
+
{ className: "dsh-model-allowance-error" },
|
|
1544
|
+
t("detail.error"),
|
|
1545
|
+
// The Host reports why a reading failed; showing it is what
|
|
1546
|
+
// turns "it does not work" into something actionable.
|
|
1547
|
+
view.error ? (0, import_react3.createElement)("div", { className: "dsh-model-allowance-reason" }, view.error) : null
|
|
1548
|
+
) : null,
|
|
1549
|
+
view?.status === "unsupported" ? (0, import_react3.createElement)("div", { className: "dsh-model-allowance-reason" }, t("badge.unsupported")) : null,
|
|
1550
|
+
view?.status === "unconfigured" ? (0, import_react3.createElement)("div", { className: "dsh-model-allowance-reason" }, t("badge.unconfigured")) : null,
|
|
1551
|
+
// A vendor that prices by the wall clock gets its phase and
|
|
1552
|
+
// countdown here, above the footer.
|
|
1553
|
+
schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
|
|
1554
|
+
(0, import_react3.createElement)(
|
|
1555
|
+
"div",
|
|
1556
|
+
{ className: "dsh-model-allowance-actions" },
|
|
1557
|
+
// The platform status sits at the left edge of the footer, on
|
|
1558
|
+
// the same line as the reading time: the card gains no extra
|
|
1559
|
+
// row, and the state and the source page stay together.
|
|
1560
|
+
serviceState !== "unknown" ? (0, import_react3.createElement)(
|
|
1561
|
+
"span",
|
|
1562
|
+
{ className: "dsh-model-allowance-status-wrap" },
|
|
1563
|
+
(0, import_react3.createElement)(
|
|
1564
|
+
providerStatus.url ? "a" : "span",
|
|
1565
|
+
{
|
|
1566
|
+
className: "dsh-model-allowance-status",
|
|
1567
|
+
"data-state": providerStatus.state,
|
|
1568
|
+
...providerStatus.url ? {
|
|
1569
|
+
href: providerStatus.url,
|
|
1570
|
+
target: "_blank",
|
|
1571
|
+
rel: "noreferrer noopener"
|
|
1572
|
+
} : {}
|
|
1573
|
+
},
|
|
1574
|
+
(0, import_react3.createElement)("span", {
|
|
1575
|
+
className: "dsh-model-allowance-status-dot",
|
|
1576
|
+
"aria-hidden": true
|
|
1577
|
+
}),
|
|
1578
|
+
(0, import_react3.createElement)(
|
|
1579
|
+
"span",
|
|
1580
|
+
{ className: "dsh-model-allowance-status-label" },
|
|
1581
|
+
statusLabel(providerStatus.state, t)
|
|
1582
|
+
),
|
|
1583
|
+
...providerStatus.url ? [
|
|
1584
|
+
(0, import_react3.createElement)(
|
|
1585
|
+
"span",
|
|
1586
|
+
{
|
|
1587
|
+
className: "dsh-model-allowance-status-arrow",
|
|
1588
|
+
"aria-hidden": true
|
|
1589
|
+
},
|
|
1590
|
+
"\u2197"
|
|
1591
|
+
)
|
|
1592
|
+
] : []
|
|
1593
|
+
),
|
|
1594
|
+
// The reason is a warning mark rather than another line:
|
|
1595
|
+
// the footer stays one row, and the detail is one hover
|
|
1596
|
+
// — or one keyboard focus — away.
|
|
1597
|
+
providerStatus.summary ? (0, import_react3.createElement)(
|
|
1598
|
+
"span",
|
|
1599
|
+
{
|
|
1600
|
+
className: "dsh-model-allowance-status-help",
|
|
1601
|
+
tabIndex: 0,
|
|
1602
|
+
role: "note",
|
|
1603
|
+
"aria-label": providerStatus.summary
|
|
1604
|
+
},
|
|
1605
|
+
(0, import_react3.createElement)(
|
|
1606
|
+
"span",
|
|
1607
|
+
{
|
|
1608
|
+
"aria-hidden": true
|
|
1609
|
+
},
|
|
1610
|
+
"!"
|
|
1611
|
+
),
|
|
1612
|
+
(0, import_react3.createElement)(
|
|
1613
|
+
"span",
|
|
1614
|
+
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
1615
|
+
providerStatus.summary
|
|
1616
|
+
)
|
|
1617
|
+
) : null
|
|
1618
|
+
) : null,
|
|
1619
|
+
view?.updatedAt ? (0, import_react3.createElement)(
|
|
1620
|
+
"span",
|
|
1621
|
+
{ className: "dsh-model-allowance-updated" },
|
|
1622
|
+
t("detail.updatedAt", { time: formatClock(view.updatedAt) })
|
|
1623
|
+
) : null,
|
|
1624
|
+
(0, import_react3.createElement)(
|
|
1625
|
+
"button",
|
|
1626
|
+
{
|
|
1627
|
+
type: "button",
|
|
1628
|
+
className: "dsh-model-allowance-icon-button",
|
|
1629
|
+
onClick: refresh,
|
|
1630
|
+
disabled: refreshing,
|
|
1631
|
+
title: refreshing ? t("detail.refreshing") : t("detail.refresh"),
|
|
1632
|
+
"aria-label": refreshing ? t("detail.refreshing") : t("detail.refresh")
|
|
1633
|
+
},
|
|
1634
|
+
refreshGlyph(16)
|
|
1635
|
+
),
|
|
1636
|
+
view?.consoleUrl ? (0, import_react3.createElement)(
|
|
1637
|
+
"a",
|
|
1638
|
+
{
|
|
1639
|
+
className: "dsh-model-allowance-icon-button",
|
|
1640
|
+
href: view.consoleUrl,
|
|
1641
|
+
target: "_blank",
|
|
1642
|
+
rel: "noreferrer noopener",
|
|
1643
|
+
title: t("detail.console"),
|
|
1644
|
+
"aria-label": t("detail.console")
|
|
1645
|
+
},
|
|
1646
|
+
consoleGlyph(16)
|
|
1647
|
+
) : null
|
|
1648
|
+
)
|
|
1649
|
+
) : null
|
|
1650
|
+
);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// src/client/contract.js
|
|
1654
|
+
var z = __toESM(require("zod"), 1);
|
|
1655
|
+
function createBalanceContribution() {
|
|
1656
|
+
const providerSchema = z.string().min(1);
|
|
1657
|
+
const windowSchema = z.object({
|
|
1658
|
+
id: z.string(),
|
|
1659
|
+
unit: z.enum(["hour", "day", "week", "month", "unknown"]),
|
|
1660
|
+
label: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional(),
|
|
1661
|
+
count: z.number().optional(),
|
|
1662
|
+
used: z.number().optional(),
|
|
1663
|
+
total: z.number().optional(),
|
|
1664
|
+
remainingPercent: z.number().optional(),
|
|
1665
|
+
resetAt: z.number().optional()
|
|
1666
|
+
});
|
|
1667
|
+
const balanceViewSchema = z.object({
|
|
1668
|
+
provider: z.string(),
|
|
1669
|
+
status: z.enum(["ready", "unsupported", "unconfigured", "failed"]),
|
|
1670
|
+
kind: z.enum(["amount", "quota"]).optional(),
|
|
1671
|
+
amount: z.number().optional(),
|
|
1672
|
+
currency: z.string().optional(),
|
|
1673
|
+
remaining: z.number().optional(),
|
|
1674
|
+
total: z.number().optional(),
|
|
1675
|
+
percent: z.number().optional(),
|
|
1676
|
+
remainingMs: z.number().optional(),
|
|
1677
|
+
resetsAt: z.number().optional(),
|
|
1678
|
+
windows: z.array(windowSchema).optional(),
|
|
1679
|
+
// A reading that moved since the last one carries the movement; the
|
|
1680
|
+
// badge renders it for a few seconds. Omitting it here would make a
|
|
1681
|
+
// stricter result codec strip the very field the badge reads.
|
|
1682
|
+
consumption: z.object({
|
|
1683
|
+
kind: z.enum(["amount", "percent"]),
|
|
1684
|
+
delta: z.number(),
|
|
1685
|
+
at: z.number()
|
|
1686
|
+
}).optional(),
|
|
1687
|
+
consoleUrl: z.string().optional(),
|
|
1688
|
+
updatedAt: z.number().optional(),
|
|
1689
|
+
error: z.string().optional()
|
|
1690
|
+
});
|
|
1691
|
+
const balanceStatusSchema = z.object({
|
|
1692
|
+
provider: z.string(),
|
|
1693
|
+
state: z.enum([
|
|
1694
|
+
"operational",
|
|
1695
|
+
"degraded",
|
|
1696
|
+
"partial-outage",
|
|
1697
|
+
"major-outage",
|
|
1698
|
+
"maintenance",
|
|
1699
|
+
"unknown"
|
|
1700
|
+
]),
|
|
1701
|
+
summary: z.string().optional(),
|
|
1702
|
+
url: z.string().optional(),
|
|
1703
|
+
updatedAt: z.number().optional(),
|
|
1704
|
+
error: z.string().optional()
|
|
1705
|
+
});
|
|
1706
|
+
const scheduleSchema = z.object({
|
|
1707
|
+
provider: z.string(),
|
|
1708
|
+
timezone: z.string(),
|
|
1709
|
+
timezoneLabel: z.object({ zh: z.string().optional(), en: z.string().optional() }),
|
|
1710
|
+
days: z.array(z.number()),
|
|
1711
|
+
windows: z.array(z.object({ from: z.string(), to: z.string() })),
|
|
1712
|
+
holidays: z.array(z.string()).optional(),
|
|
1713
|
+
note: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional()
|
|
1714
|
+
}).nullable();
|
|
1715
|
+
const strict = (schema, description, typeSymbol) => ({
|
|
1716
|
+
mode: "strict",
|
|
1717
|
+
typeSymbol,
|
|
1718
|
+
create: () => schema,
|
|
1719
|
+
jsonSchema: { type: "object" },
|
|
1720
|
+
description
|
|
1721
|
+
});
|
|
1722
|
+
const providerParameter = {
|
|
1723
|
+
name: "provider",
|
|
1724
|
+
wire: "provider",
|
|
1725
|
+
source: "json",
|
|
1726
|
+
codec: strict(providerSchema, "Provider route to read.", "dsh-model-allowance#provider")
|
|
1727
|
+
};
|
|
1728
|
+
const modelParameter = {
|
|
1729
|
+
name: "model",
|
|
1730
|
+
wire: "model",
|
|
1731
|
+
source: "json",
|
|
1732
|
+
acceptsUndefined: true,
|
|
1733
|
+
codec: strict(
|
|
1734
|
+
z.string().nullable().optional(),
|
|
1735
|
+
"Provider-owned model id, when the session names one.",
|
|
1736
|
+
"dsh-model-allowance#model"
|
|
1737
|
+
)
|
|
1738
|
+
};
|
|
1739
|
+
const providerListSchema = z.array(
|
|
1740
|
+
z.object({
|
|
1741
|
+
route: z.string(),
|
|
1742
|
+
configured: z.boolean(),
|
|
1743
|
+
name: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional(),
|
|
1744
|
+
color: z.string().optional(),
|
|
1745
|
+
iconHint: z.string().optional()
|
|
1746
|
+
})
|
|
1747
|
+
);
|
|
1748
|
+
return {
|
|
1749
|
+
package: "dsh-model-allowance",
|
|
1750
|
+
methods: {
|
|
1751
|
+
"balance/list": {
|
|
1752
|
+
service: "balanceController",
|
|
1753
|
+
description: "List the provider routes this installation can read.",
|
|
1754
|
+
invocation: { kind: "direct" },
|
|
1755
|
+
parameters: [],
|
|
1756
|
+
result: strict(providerListSchema, "The routes.", "dsh-model-allowance#routes")
|
|
1757
|
+
},
|
|
1758
|
+
"balance/capabilities": {
|
|
1759
|
+
service: "balanceController",
|
|
1760
|
+
description: "The wire capabilities this Host supports.",
|
|
1761
|
+
invocation: { kind: "direct" },
|
|
1762
|
+
parameters: [],
|
|
1763
|
+
result: strict(
|
|
1764
|
+
z.object({ modelScoped: z.boolean() }),
|
|
1765
|
+
"The capabilities.",
|
|
1766
|
+
"dsh-model-allowance#capabilities"
|
|
1767
|
+
)
|
|
1768
|
+
},
|
|
1769
|
+
"balance/balance": {
|
|
1770
|
+
service: "balanceController",
|
|
1771
|
+
description: "Read one provider's balance or remaining allowance.",
|
|
1772
|
+
invocation: { kind: "direct" },
|
|
1773
|
+
parameters: [providerParameter, modelParameter],
|
|
1774
|
+
result: strict(balanceViewSchema, "The reading.", "dsh-model-allowance#balanceView")
|
|
1775
|
+
},
|
|
1776
|
+
"balance/defaultProvider": {
|
|
1777
|
+
service: "balanceController",
|
|
1778
|
+
description: "The provider a session with no model selection would use.",
|
|
1779
|
+
invocation: { kind: "direct" },
|
|
1780
|
+
parameters: [],
|
|
1781
|
+
result: strict(
|
|
1782
|
+
z.object({ provider: z.string().optional() }),
|
|
1783
|
+
"The default provider.",
|
|
1784
|
+
"dsh-model-allowance#defaultProvider"
|
|
1785
|
+
)
|
|
1786
|
+
},
|
|
1787
|
+
"balance/refresh": {
|
|
1788
|
+
service: "balanceController",
|
|
1789
|
+
description: "Force a fresh reading for one provider, bypassing the cache.",
|
|
1790
|
+
invocation: { kind: "direct" },
|
|
1791
|
+
parameters: [providerParameter, modelParameter],
|
|
1792
|
+
result: strict(balanceViewSchema, "The reading.", "dsh-model-allowance#balanceView")
|
|
1793
|
+
},
|
|
1794
|
+
"balance/watch": {
|
|
1795
|
+
service: "balanceController",
|
|
1796
|
+
description: "Stream readings for one provider until the stream ends.",
|
|
1797
|
+
mode: "stream",
|
|
1798
|
+
invocation: { kind: "direct" },
|
|
1799
|
+
parameters: [providerParameter, modelParameter],
|
|
1800
|
+
cancellation: { parameter: "signal" },
|
|
1801
|
+
result: strict(balanceViewSchema, "One reading.", "dsh-model-allowance#balanceView")
|
|
1802
|
+
},
|
|
1803
|
+
"balance/status": {
|
|
1804
|
+
service: "balanceController",
|
|
1805
|
+
description: "Read one provider's platform status.",
|
|
1806
|
+
invocation: { kind: "direct" },
|
|
1807
|
+
parameters: [providerParameter],
|
|
1808
|
+
result: strict(
|
|
1809
|
+
balanceStatusSchema,
|
|
1810
|
+
"The status reading.",
|
|
1811
|
+
"dsh-model-allowance#balanceStatus"
|
|
1812
|
+
)
|
|
1813
|
+
},
|
|
1814
|
+
"balance/schedule": {
|
|
1815
|
+
service: "balanceController",
|
|
1816
|
+
description: "The time-of-day pricing schedule for one provider, when it has one.",
|
|
1817
|
+
invocation: { kind: "direct" },
|
|
1818
|
+
parameters: [providerParameter],
|
|
1819
|
+
result: strict(scheduleSchema, "The schedule, or null.", "dsh-model-allowance#schedule")
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
// src/client/index.js
|
|
1826
|
+
var inject = ["slots", "locale", "remote"];
|
|
1827
|
+
function apply(ctx) {
|
|
1828
|
+
ctx.effect(() => ctx.locale.register(NS, { en, zh }));
|
|
1829
|
+
const t = ctx.locale.bind(NS);
|
|
1830
|
+
ctx.effect(() => {
|
|
1831
|
+
let disposed = false;
|
|
1832
|
+
let unmount;
|
|
1833
|
+
(async () => {
|
|
1834
|
+
const contribution = createBalanceContribution();
|
|
1835
|
+
const info = {
|
|
1836
|
+
package: contribution.package,
|
|
1837
|
+
get descriptors() {
|
|
1838
|
+
const descriptors = [];
|
|
1839
|
+
for (const [endpoint, definition] of Object.entries(contribution.methods)) {
|
|
1840
|
+
const separator = endpoint.indexOf("/");
|
|
1841
|
+
const namespace2 = endpoint.slice(0, separator);
|
|
1842
|
+
const method = endpoint.slice(separator + 1);
|
|
1843
|
+
descriptors.push({
|
|
1844
|
+
...definition,
|
|
1845
|
+
id: `${contribution.package}#${endpoint}`,
|
|
1846
|
+
namespace: namespace2,
|
|
1847
|
+
method,
|
|
1848
|
+
parameters: definition.parameters.map((parameter) => ({
|
|
1849
|
+
...parameter,
|
|
1850
|
+
wire: parameter.wire ?? parameter.name
|
|
1851
|
+
}))
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
return descriptors;
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
const disposer = await ctx.remote.$mount(info);
|
|
1858
|
+
if (disposed) {
|
|
1859
|
+
await disposer();
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
unmount = disposer;
|
|
1863
|
+
const namespace = lookupBalanceNamespace(ctx);
|
|
1864
|
+
if (namespace) {
|
|
1865
|
+
setBalanceNamespace(namespace);
|
|
1866
|
+
} else {
|
|
1867
|
+
console.error("[model-allowance] the balance namespace did not register");
|
|
1868
|
+
setBalanceNamespace(null);
|
|
1869
|
+
}
|
|
1870
|
+
})().catch((error) => {
|
|
1871
|
+
console.error("[model-allowance] mounting the balance namespace failed", { error });
|
|
1872
|
+
setBalanceNamespace(lookupBalanceNamespace(ctx) ?? null);
|
|
1873
|
+
});
|
|
1874
|
+
return () => {
|
|
1875
|
+
disposed = true;
|
|
1876
|
+
resetBalanceNamespace();
|
|
1877
|
+
unmount?.();
|
|
1878
|
+
};
|
|
1879
|
+
}, "model-allowance: balance namespace");
|
|
1880
|
+
const SLOT = "conversation.input.right";
|
|
1881
|
+
ctx.slots.inject(
|
|
1882
|
+
SLOT,
|
|
1883
|
+
() => ctx.slots.register(
|
|
1884
|
+
{
|
|
1885
|
+
name: SLOT,
|
|
1886
|
+
id: "model-allowance",
|
|
1887
|
+
order: 10
|
|
1888
|
+
},
|
|
1889
|
+
(props) => (0, import_react4.createElement)(BalanceBadge, { ...props, ctx, t })
|
|
1890
|
+
)
|
|
1891
|
+
);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
})(module, module.exports, require)
|
|
1895
|
+
return module.exports
|
|
1896
|
+
},
|
|
1897
|
+
})
|