dsh-model-allowance 1.0.7 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -6
- package/README.zh.md +14 -6
- package/client.js +1894 -1295
- package/lib/balance.js +70 -5
- package/lib/debug.js +72 -13
- package/lib/providers/deepseek.js +4 -82
- package/lib/providers/holidays.js +89 -0
- package/lib/providers/placeholder.js +3 -101
- package/lib/providers/qwen_token_plan.js +713 -0
- package/lib/providers/schedule.js +8 -6
- package/lib/providers/shared.js +16 -4
- package/lib/providers/xiaomi.js +285 -0
- package/lib/providers.js +13 -19
- package/lib/remote.js +21 -1
- package/package.json +2 -1
package/client.js
CHANGED
|
@@ -42,11 +42,14 @@ __export(index_exports, {
|
|
|
42
42
|
inject: () => inject
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
|
-
var
|
|
45
|
+
var import_react9 = require("react");
|
|
46
46
|
|
|
47
47
|
// src/client/badge.js
|
|
48
|
-
var
|
|
49
|
-
var
|
|
48
|
+
var React6 = __toESM(require("react"), 1);
|
|
49
|
+
var import_react7 = require("react");
|
|
50
|
+
|
|
51
|
+
// src/client/components/balance-panel.js
|
|
52
|
+
var import_react6 = require("react");
|
|
50
53
|
|
|
51
54
|
// src/client/format.js
|
|
52
55
|
var CURRENCY_SYMBOLS = {
|
|
@@ -280,6 +283,11 @@ var QWEN_GRADIENT_STOPS = [
|
|
|
280
283
|
["#082DFF", "0"],
|
|
281
284
|
["#3FD2F9", "1"]
|
|
282
285
|
];
|
|
286
|
+
var XIAOMI_PATHS = [
|
|
287
|
+
"M73.7449 15.9987C73.4083 15.998 73.0857 15.8638 72.8479 15.6256C72.6101 15.3873 72.4766 15.0644 72.4766 14.7278V7.165C72.4914 6.83757 72.632 6.52848 72.869 6.30203C73.1059 6.07559 73.4211 5.94922 73.7488 5.94922C74.0766 5.94922 74.3918 6.07559 74.6287 6.30203C74.8657 6.52848 75.0062 6.83757 75.0211 7.165V14.7278C75.0208 14.895 74.9875 15.0606 74.9232 15.215C74.8588 15.3693 74.7647 15.5095 74.6462 15.6276C74.5277 15.7456 74.3871 15.8391 74.2325 15.9028C74.0778 15.9665 73.9122 15.9991 73.7449 15.9987Z",
|
|
288
|
+
"M87.3607 15.9993C87.0234 15.9993 86.6998 15.8655 86.4611 15.6272C86.2223 15.389 86.0878 15.0657 86.0871 14.7284V4.67881L81.4654 9.45281C81.2304 9.69657 80.9081 9.83697 80.5695 9.84312C80.231 9.84928 79.9038 9.72069 79.6601 9.48563C79.4163 9.25058 79.2759 8.92832 79.2697 8.58976C79.2667 8.42211 79.2967 8.25551 79.358 8.09947C79.4194 7.94342 79.5108 7.80098 79.6272 7.68028L86.4469 0.661082C86.6229 0.478921 86.8494 0.35354 87.0973 0.301033C87.3451 0.248526 87.603 0.271291 87.8378 0.366403C88.0727 0.461516 88.2737 0.624637 88.4151 0.834827C88.5566 1.04502 88.632 1.29268 88.6317 1.54603V14.7284C88.6317 15.0655 88.4978 15.3887 88.2594 15.6271C88.021 15.8654 87.6978 15.9993 87.3607 15.9993Z",
|
|
289
|
+
"M80.5514 9.82621C80.3824 9.82749 80.2149 9.79518 80.0584 9.73117C79.902 9.66716 79.7599 9.57272 79.6402 9.45332L72.8337 2.4315C72.599 2.18948 72.4701 1.86414 72.4752 1.52705C72.4804 1.18996 72.6193 0.868726 72.8613 0.634023C73.1033 0.399319 73.4287 0.270369 73.7658 0.27554C74.1028 0.280711 74.4241 0.419579 74.6588 0.661595L81.4653 7.66767C81.6389 7.84735 81.7558 8.07413 81.8015 8.31977C81.8472 8.56541 81.8196 8.81906 81.7222 9.04914C81.6248 9.27922 81.4618 9.47557 81.2537 9.61374C81.0455 9.75191 80.8013 9.8258 80.5514 9.82621Z"
|
|
290
|
+
];
|
|
283
291
|
var ICON_GEOMETRY = {
|
|
284
292
|
// DeepSeek's square icon draws 1..49.35 across and 7..43.35 down.
|
|
285
293
|
deepseek: { x: 1, y: 7, vbW: 48.35, vbH: 36.35, inkW: 48.35, inkH: 36.35 },
|
|
@@ -292,7 +300,10 @@ var ICON_GEOMETRY = {
|
|
|
292
300
|
opencode: { x: 0, y: 0, vbW: 240, vbH: 300, inkW: 240, inkH: 300 },
|
|
293
301
|
// Qwen's petals draw 0.42..27.58 across and -0.05..28.05 down, so the
|
|
294
302
|
// published 28x28 box would clip a hair of the outer petals.
|
|
295
|
-
qwen: { x: 0.4155, y: -0.048, vbW: 27.169, vbH: 28.0988, inkW: 27.169, inkH: 28.0988 }
|
|
303
|
+
qwen: { x: 0.4155, y: -0.048, vbW: 27.169, vbH: 28.0988, inkW: 27.169, inkH: 28.0988 },
|
|
304
|
+
// MiMo's M draws 72.475..88.632 across and 0.273..16.0 down inside the
|
|
305
|
+
// wordmark's own space; the box is cropped to the glyph.
|
|
306
|
+
xiaomi: { x: 72.475, y: 0.2734, vbW: 16.1567, vbH: 15.7259, inkW: 16.1567, inkH: 15.7259 }
|
|
296
307
|
};
|
|
297
308
|
function markOf(entry, route) {
|
|
298
309
|
const color = typeof entry?.color === "string" && entry.color !== "" ? entry.color : "#6b7280";
|
|
@@ -388,6 +399,10 @@ function providerIcon(route, inkHeight, mark) {
|
|
|
388
399
|
fillOpacity: path.opacity
|
|
389
400
|
})
|
|
390
401
|
);
|
|
402
|
+
} else if (mark.icon === "xiaomi") {
|
|
403
|
+
content = XIAOMI_PATHS.map(
|
|
404
|
+
(d, index) => (0, import_react.createElement)("path", { key: `xiaomi-${String(index)}`, d, fill: "#1F2329" })
|
|
405
|
+
);
|
|
391
406
|
} else {
|
|
392
407
|
content = [(0, import_react.createElement)("path", { key: "mark", d: DEEPSEEK_PATH, fill: "currentColor" })];
|
|
393
408
|
}
|
|
@@ -469,7 +484,28 @@ var zh = {
|
|
|
469
484
|
"duration.daysHours": "{days} \u5929 {hours} \u5C0F\u65F6",
|
|
470
485
|
"duration.hoursMinutes": "{hours} \u5C0F\u65F6 {minutes} \u5206",
|
|
471
486
|
"duration.minutes": "{minutes} \u5206\u949F",
|
|
472
|
-
"duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F"
|
|
487
|
+
"duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F",
|
|
488
|
+
"settings.nav": "Model Allowance",
|
|
489
|
+
"settings.title": "Model Allowance",
|
|
490
|
+
"settings.loading": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u2026",
|
|
491
|
+
"settings.unavailable": "\u672C\u673A\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u51ED\u636E\u3002",
|
|
492
|
+
"settings.edit": "\u4FEE\u6539",
|
|
493
|
+
"settings.delete": "\u5220\u9664",
|
|
494
|
+
"settings.cancel": "\u53D6\u6D88",
|
|
495
|
+
"settings.save": "\u4FDD\u5B58",
|
|
496
|
+
"settings.testing": "\u9A8C\u8BC1\u4E2D\u2026",
|
|
497
|
+
"settings.fillAll": "\u8BF7\u586B\u5199\u5B8C\u6574\u7684\u51ED\u636E\u540E\u518D\u4FDD\u5B58",
|
|
498
|
+
"settings.testFailed": "\u51ED\u636E\u9A8C\u8BC1\u672A\u901A\u8FC7\uFF0C\u672A\u4FDD\u5B58",
|
|
499
|
+
"settings.testRejected": "\u5382\u5546\u62D2\u7EDD\u4E86\u8FD9\u5BF9\u51ED\u636E",
|
|
500
|
+
"settings.doc": "\u5982\u4F55\u83B7\u53D6\u51ED\u636E\uFF1F",
|
|
501
|
+
"settings.saved": "\u5DF2\u4FDD\u5B58",
|
|
502
|
+
"settings.configured": "\u5DF2\u914D\u7F6E",
|
|
503
|
+
"settings.deleted": "\u5DF2\u5220\u9664",
|
|
504
|
+
"settings.saveFailed": "\u4FDD\u5B58\u5931\u8D25",
|
|
505
|
+
"settings.deleteFailed": "\u5220\u9664\u5931\u8D25",
|
|
506
|
+
"settings.loadFailed": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25",
|
|
507
|
+
"badge.setupHint": "\u5C1A\u672A\u914D\u7F6E\u8BE5\u5382\u5546\u7684\u67E5\u8BE2\u51ED\u636E\u3002\u6253\u5F00 \u8BBE\u7F6E \u2192 Model Allowance \u5F55\u5165\u3002",
|
|
508
|
+
"badge.setupDoc": "\u67E5\u770B\u914D\u7F6E\u6307\u5357"
|
|
473
509
|
};
|
|
474
510
|
var en = {
|
|
475
511
|
"badge.loading": "Loading\u2026",
|
|
@@ -533,7 +569,28 @@ var en = {
|
|
|
533
569
|
"duration.daysHours": "{days}d {hours}h",
|
|
534
570
|
"duration.hoursMinutes": "{hours}h {minutes}m",
|
|
535
571
|
"duration.minutes": "{minutes}m",
|
|
536
|
-
"duration.lessThanMinute": "under a minute"
|
|
572
|
+
"duration.lessThanMinute": "under a minute",
|
|
573
|
+
"settings.nav": "Model Allowance",
|
|
574
|
+
"settings.title": "Model Allowance",
|
|
575
|
+
"settings.loading": "Reading credential status\u2026",
|
|
576
|
+
"settings.unavailable": "This host provides no credential store, so credentials cannot be saved.",
|
|
577
|
+
"settings.edit": "Edit",
|
|
578
|
+
"settings.delete": "Delete",
|
|
579
|
+
"settings.cancel": "Cancel",
|
|
580
|
+
"settings.save": "Save",
|
|
581
|
+
"settings.testing": "Verifying\u2026",
|
|
582
|
+
"settings.fillAll": "Fill in every field before saving",
|
|
583
|
+
"settings.testFailed": "The credentials were rejected and were not saved",
|
|
584
|
+
"settings.testRejected": "the vendor refused this credential pair",
|
|
585
|
+
"settings.doc": "How do I get the credentials?",
|
|
586
|
+
"settings.saved": "Saved",
|
|
587
|
+
"settings.configured": "Configured",
|
|
588
|
+
"settings.deleted": "Deleted",
|
|
589
|
+
"settings.saveFailed": "Save failed",
|
|
590
|
+
"settings.deleteFailed": "Delete failed",
|
|
591
|
+
"settings.loadFailed": "Could not read credential status",
|
|
592
|
+
"badge.setupHint": "No credentials are stored for this provider yet. Open Settings \u2192 Model Allowance to add them.",
|
|
593
|
+
"badge.setupDoc": "Open the setup guide"
|
|
537
594
|
};
|
|
538
595
|
function activeLanguage() {
|
|
539
596
|
const tag = typeof document !== "undefined" ? document.documentElement?.lang : void 0;
|
|
@@ -559,96 +616,6 @@ function statusLabel(state, t) {
|
|
|
559
616
|
return key === void 0 ? t("status.unknown") : t(key);
|
|
560
617
|
}
|
|
561
618
|
|
|
562
|
-
// src/client/models.js
|
|
563
|
-
function providerGroup(catalog, provider) {
|
|
564
|
-
const groups = Array.isArray(catalog?.groups) ? catalog.groups : [];
|
|
565
|
-
return groups.find((group) => group?.id === provider);
|
|
566
|
-
}
|
|
567
|
-
function modelsForProvider(catalog, provider) {
|
|
568
|
-
const group = providerGroup(catalog, provider);
|
|
569
|
-
const models = Array.isArray(group?.models) ? group.models : [];
|
|
570
|
-
return models.filter((model) => typeof model?.id === "string" && model.id !== "");
|
|
571
|
-
}
|
|
572
|
-
function providerModelGroup(catalog, routes) {
|
|
573
|
-
const seen = /* @__PURE__ */ new Set();
|
|
574
|
-
for (const route of routes) {
|
|
575
|
-
if (typeof route !== "string" || route === "" || seen.has(route)) continue;
|
|
576
|
-
seen.add(route);
|
|
577
|
-
const models = modelsForProvider(catalog, route);
|
|
578
|
-
if (models.length > 0) return { provider: route, models };
|
|
579
|
-
}
|
|
580
|
-
return void 0;
|
|
581
|
-
}
|
|
582
|
-
function effortChoices(model) {
|
|
583
|
-
const reasoning = model?.reasoning;
|
|
584
|
-
const efforts = Array.isArray(reasoning?.efforts) ? reasoning.efforts : [];
|
|
585
|
-
if (efforts.length === 0) return null;
|
|
586
|
-
const entries = efforts.filter((effort) => typeof effort?.id === "string" && effort.id !== "").map((effort) => ({
|
|
587
|
-
id: effort.id,
|
|
588
|
-
name: typeof effort.name === "string" && effort.name !== "" ? effort.name : effort.id,
|
|
589
|
-
isDefault: effort.id === reasoning.defaultEffort
|
|
590
|
-
}));
|
|
591
|
-
if (reasoning.defaultEffort === void 0) {
|
|
592
|
-
entries.unshift({ id: void 0, providerDefault: true });
|
|
593
|
-
}
|
|
594
|
-
return entries;
|
|
595
|
-
}
|
|
596
|
-
function currentModelFor(selection, provider) {
|
|
597
|
-
const next = selection?.next ?? selection?.lastUsed;
|
|
598
|
-
if (next?.provider !== provider) return void 0;
|
|
599
|
-
return typeof next.model === "string" ? next.model : void 0;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// src/client/namespace.js
|
|
603
|
-
var balanceNamespace = null;
|
|
604
|
-
var settleBalanceNamespace;
|
|
605
|
-
var balanceNamespaceReady = new Promise((resolve) => {
|
|
606
|
-
settleBalanceNamespace = resolve;
|
|
607
|
-
});
|
|
608
|
-
async function getBalanceApi() {
|
|
609
|
-
if (balanceNamespace) return balanceNamespace;
|
|
610
|
-
return await balanceNamespaceReady;
|
|
611
|
-
}
|
|
612
|
-
function lookupBalanceNamespace(ctx) {
|
|
613
|
-
try {
|
|
614
|
-
return ctx.get("remote.balance");
|
|
615
|
-
} catch {
|
|
616
|
-
return void 0;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
function setBalanceNamespace(value) {
|
|
620
|
-
balanceNamespace = value;
|
|
621
|
-
settleBalanceNamespace(value);
|
|
622
|
-
return value;
|
|
623
|
-
}
|
|
624
|
-
var modelSupport;
|
|
625
|
-
function resetBalanceNamespace() {
|
|
626
|
-
balanceNamespace = null;
|
|
627
|
-
modelSupport = void 0;
|
|
628
|
-
}
|
|
629
|
-
function lookupSessionFace(ctx) {
|
|
630
|
-
try {
|
|
631
|
-
const face = ctx.get("remote.session");
|
|
632
|
-
if (face !== void 0) return face;
|
|
633
|
-
} catch {
|
|
634
|
-
}
|
|
635
|
-
return ctx.remote?.session;
|
|
636
|
-
}
|
|
637
|
-
async function supportsModel(api) {
|
|
638
|
-
if (modelSupport !== void 0) return modelSupport;
|
|
639
|
-
if (typeof api?.capabilities !== "function") {
|
|
640
|
-
modelSupport = false;
|
|
641
|
-
return modelSupport;
|
|
642
|
-
}
|
|
643
|
-
try {
|
|
644
|
-
const result = await api.capabilities();
|
|
645
|
-
modelSupport = result?.ok === true && result.value?.modelScoped === true;
|
|
646
|
-
} catch {
|
|
647
|
-
modelSupport = false;
|
|
648
|
-
}
|
|
649
|
-
return modelSupport;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
619
|
// src/client/schedule.js
|
|
653
620
|
var import_react2 = require("react");
|
|
654
621
|
function formatCountdown(ms) {
|
|
@@ -843,337 +810,6 @@ function scheduleView(schedule, now, t) {
|
|
|
843
810
|
);
|
|
844
811
|
}
|
|
845
812
|
|
|
846
|
-
// src/client/styles.js
|
|
847
|
-
var STYLES = [
|
|
848
|
-
".dsh-model-allowance-root{position:relative;display:inline-flex;align-items:center}",
|
|
849
|
-
// The badge is a trigger, the way the harness's own composer triggers
|
|
850
|
-
// are: no frame of its own, a transparent surface, and the hover tint
|
|
851
|
-
// only while the pointer is on it or the card is open. A bordered pill
|
|
852
|
-
// read as a field rather than a control.
|
|
853
|
-
".dsh-model-allowance-badge{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px;",
|
|
854
|
-
"border:0;border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
855
|
-
"color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1;cursor:pointer;",
|
|
856
|
-
"font-variant-numeric:tabular-nums;white-space:nowrap}",
|
|
857
|
-
".dsh-model-allowance-badge:hover{color:var(--dsw-alias-label-secondary);",
|
|
858
|
-
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
859
|
-
'.dsh-model-allowance-badge[aria-expanded="true"]{color:var(--dsw-alias-label-secondary);',
|
|
860
|
-
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
861
|
-
".dsh-model-allowance-badge:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
862
|
-
"outline-offset:1px}",
|
|
863
|
-
".dsh-model-allowance-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
864
|
-
"background:var(--dsw-alias-state-idle-primary)}",
|
|
865
|
-
// The dot reports the platform, not the reading: green while the service
|
|
866
|
-
// is available, red once its own status page says otherwise, and grey
|
|
867
|
-
// when this installation has no status source for the route.
|
|
868
|
-
'.dsh-model-allowance-root[data-service="operational"] .dsh-model-allowance-dot{',
|
|
869
|
-
"background:var(--dsw-alias-state-success-primary)}",
|
|
870
|
-
'.dsh-model-allowance-root[data-service="degraded"] .dsh-model-allowance-dot,',
|
|
871
|
-
'.dsh-model-allowance-root[data-service="partial-outage"] .dsh-model-allowance-dot,',
|
|
872
|
-
'.dsh-model-allowance-root[data-service="major-outage"] .dsh-model-allowance-dot,',
|
|
873
|
-
'.dsh-model-allowance-root[data-service="maintenance"] .dsh-model-allowance-dot{',
|
|
874
|
-
"background:var(--dsw-alias-state-error-primary)}",
|
|
875
|
-
'.dsh-model-allowance-root[data-loading="true"] .dsh-model-allowance-dot{opacity:.5}',
|
|
876
|
-
// The turn's difference rides beside the value for a few seconds. It is
|
|
877
|
-
// quieter than the value so the balance stays the thing being read, and
|
|
878
|
-
// it fades in rather than popping.
|
|
879
|
-
".dsh-model-allowance-delta{margin-left:-2px;font-size:11px;",
|
|
880
|
-
"color:var(--dsw-alias-label-secondary);animation:dsh-model-allowance-fade 200ms ease-out}",
|
|
881
|
-
'.dsh-model-allowance-delta[data-direction="up"]{',
|
|
882
|
-
"color:var(--dsw-alias-state-success-primary)}",
|
|
883
|
-
"@keyframes dsh-model-allowance-fade{from{opacity:0}to{opacity:1}}",
|
|
884
|
-
// Anchored to its own right edge: the badge sits next to the model seat
|
|
885
|
-
// near the trailing edge, so the panel opens leftwards instead of
|
|
886
|
-
// running off the side of the composer.
|
|
887
|
-
//
|
|
888
|
-
// The surface is the harness's own menu surface — a translucent white
|
|
889
|
-
// behind a heavy blur — and the shadow is its own elevation scale. The
|
|
890
|
-
// overlay token reads as a mask over the page behind, not as a panel
|
|
891
|
-
// surface: on it this card came out a flat grey slab.
|
|
892
|
-
// The floor is set for the layout, not for the content: with it removed
|
|
893
|
-
// the card collapses to 248px, so 300px is the slack that lets a label
|
|
894
|
-
// and its value read as two columns instead of one run-on line. The cap
|
|
895
|
-
// is the harness's own idiom for a floating surface, so a narrow window
|
|
896
|
-
// shrinks the card rather than pushing it off the composer.
|
|
897
|
-
".dsh-model-allowance-panel{position:absolute;bottom:calc(100% + 6px);right:0;z-index:20;",
|
|
898
|
-
"box-sizing:border-box;min-width:300px;max-width:calc(100vw - 24px);",
|
|
899
|
-
"padding:8px 10px 10px;border:0;",
|
|
900
|
-
"border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-2);",
|
|
901
|
-
"box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);",
|
|
902
|
-
"font-size:12px}",
|
|
903
|
-
".dsh-model-allowance-row{display:flex;justify-content:space-between;gap:16px;padding:2px 0}",
|
|
904
|
-
// Label first, value second, matching every other pair in the card
|
|
905
|
-
// (schedule title/state, status/reading time): the label carries the
|
|
906
|
-
// emphasis and the value reads as its detail. Reversed, the balance row
|
|
907
|
-
// stood out as the one pair laid out the other way round.
|
|
908
|
-
".dsh-model-allowance-row>span:first-child{color:var(--dsw-alias-label-primary)}",
|
|
909
|
-
".dsh-model-allowance-row>span:last-child{color:var(--dsw-alias-label-secondary)}",
|
|
910
|
-
".dsh-model-allowance-usage{font-variant-numeric:tabular-nums;",
|
|
911
|
-
"color:var(--dsw-alias-label-secondary)}",
|
|
912
|
-
// The row cancels the panel's own horizontal padding so the divider under
|
|
913
|
-
// it runs edge to edge, then puts the same padding back so the first mark
|
|
914
|
-
// lines up with the labels below. Without this the marks sit further from
|
|
915
|
-
// the edge than every other row and the whole strip reads as shifted left.
|
|
916
|
-
".dsh-model-allowance-switcher-wrap{position:relative;margin:-2px -10px 6px;",
|
|
917
|
-
"padding:0 10px 8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",
|
|
918
|
-
".dsh-model-allowance-switcher{display:flex;flex-wrap:nowrap;align-items:center;",
|
|
919
|
-
"gap:4px;overflow:hidden}",
|
|
920
|
-
// The mark sits straight on the panel; the chip draws no surface of its
|
|
921
|
-
// own, so the panel's own surface shows through behind the logo.
|
|
922
|
-
//
|
|
923
|
-
// A frame means one thing here: this is the provider being read. It is
|
|
924
|
-
// not used to say anything else about a route, because a second meaning
|
|
925
|
-
// makes an unselected mark look selected.
|
|
926
|
-
".dsh-model-allowance-tab{display:inline-flex;align-items:center;justify-content:center;",
|
|
927
|
-
"box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
928
|
-
"border:1px solid transparent;border-radius:var(--dsw-radius-sm);",
|
|
929
|
-
"background:0 0;line-height:1;cursor:pointer;",
|
|
930
|
-
"color:var(--provider-mark,var(--dsw-alias-label-primary));opacity:.66}",
|
|
931
|
-
".dsh-model-allowance-tab:hover{opacity:.9}",
|
|
932
|
-
// The selected mark gains the one frame the chip already has, and stops
|
|
933
|
-
// being dimmed. It must not use the brand colour: in this theme that is
|
|
934
|
-
// #0f1115, so a selected chip wore a near-black frame. It also gains no
|
|
935
|
-
// background, since any fill here reintroduces a tile on the panel.
|
|
936
|
-
'.dsh-model-allowance-tab[data-active="true"]{opacity:1;',
|
|
937
|
-
"border-color:var(--dsw-alias-border-l2)}",
|
|
938
|
-
".dsh-model-allowance-tab:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
939
|
-
"outline-offset:-1px}",
|
|
940
|
-
".dsh-model-allowance-tab svg{display:block}",
|
|
941
|
-
".dsh-model-allowance-tab-letter{font-size:11px;font-weight:600;line-height:1}",
|
|
942
|
-
".dsh-model-allowance-more{display:inline-flex;align-items:center;justify-content:center;",
|
|
943
|
-
"box-sizing:border-box;width:26px;height:26px;flex:none;margin-left:auto;padding:0;",
|
|
944
|
-
"border-radius:var(--dsw-radius-sm);",
|
|
945
|
-
"border:1px solid var(--dsw-alias-border-l1);background:0 0;cursor:pointer;",
|
|
946
|
-
"color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}",
|
|
947
|
-
".dsh-model-allowance-more:hover{color:var(--dsw-alias-label-secondary);",
|
|
948
|
-
"border-color:var(--dsw-alias-border-l2)}",
|
|
949
|
-
// The overflow menu is a second floating surface, so it carries the same
|
|
950
|
-
// solid layer and elevation as the card it belongs to.
|
|
951
|
-
".dsh-model-allowance-menu{position:absolute;top:calc(100% + 2px);right:0;z-index:30;",
|
|
952
|
-
"min-width:150px;padding:4px;border:0;",
|
|
953
|
-
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
954
|
-
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
955
|
-
".dsh-model-allowance-menu-item{display:flex;align-items:center;gap:8px;width:100%;",
|
|
956
|
-
"padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);background:0 0;",
|
|
957
|
-
"color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
958
|
-
".dsh-model-allowance-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
959
|
-
// Same rule as the strip chips: no surface of its own, so the mark sits
|
|
960
|
-
// on the menu instead of on a tile.
|
|
961
|
-
".dsh-model-allowance-menu-mark{display:inline-flex;align-items:center;",
|
|
962
|
-
"justify-content:center;width:20px;height:20px;flex:none;border-radius:var(--dsw-radius-xs);",
|
|
963
|
-
"line-height:1;background:0 0;",
|
|
964
|
-
"color:var(--provider-mark,var(--dsw-alias-label-primary))}",
|
|
965
|
-
".dsh-model-allowance-menu-mark svg{display:block}",
|
|
966
|
-
// The model list is a third floating surface. It opens upwards from the
|
|
967
|
-
// footer button, so it carries the same menu surface and elevation as the
|
|
968
|
-
// card and the provider overflow menu.
|
|
969
|
-
//
|
|
970
|
-
// It is the one surface that is not translucent: the list floats over the
|
|
971
|
-
// conversation, and a frosted panel there let the text underneath show
|
|
972
|
-
// through the model names. A solid layer keeps the list readable wherever
|
|
973
|
-
// it opens.
|
|
974
|
-
".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
|
|
975
|
-
".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
|
|
976
|
-
"min-width:180px;max-width:260px;max-height:240px;overflow-y:auto;padding:4px;border:0;",
|
|
977
|
-
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
978
|
-
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
979
|
-
".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
|
|
980
|
-
"gap:10px;width:100%;padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
981
|
-
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
982
|
-
".dsh-model-allowance-model-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
983
|
-
// The model the session uses is dimmed rather than framed: a frame here
|
|
984
|
-
// would give the chip a second meaning it does not have.
|
|
985
|
-
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
986
|
-
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
987
|
-
".dsh-model-allowance-model-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
988
|
-
// The trailing side of a model row carries its state label and, for a
|
|
989
|
-
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
990
|
-
// the right.
|
|
991
|
-
".dsh-model-allowance-model-side{display:inline-flex;align-items:center;gap:4px;flex:none}",
|
|
992
|
-
".dsh-model-allowance-model-arrow{color:var(--dsw-alias-label-tertiary);font-size:12px;",
|
|
993
|
-
"line-height:1}",
|
|
994
|
-
// The effort flyout opens to the right of the list, on the row the
|
|
995
|
-
// pointer rests on, as a fourth floating surface of the card. It overlaps
|
|
996
|
-
// the list, so it is solid for the same reason the list is.
|
|
997
|
-
".dsh-model-allowance-effort-menu{position:absolute;left:calc(100% + 4px);z-index:31;",
|
|
998
|
-
"display:flex;flex-direction:column;min-width:130px;max-width:220px;padding:4px;border:0;",
|
|
999
|
-
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
1000
|
-
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
1001
|
-
".dsh-model-allowance-effort-item{display:flex;align-items:center;justify-content:space-between;",
|
|
1002
|
-
"gap:10px;width:100%;padding:3px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
1003
|
-
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
1004
|
-
".dsh-model-allowance-effort-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1005
|
-
// The provider's own default effort is dimmed like the model in use, so
|
|
1006
|
-
// the open submenu points at it before anything is picked.
|
|
1007
|
-
'.dsh-model-allowance-effort-item[data-default="true"],',
|
|
1008
|
-
'.dsh-model-allowance-effort-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
1009
|
-
".dsh-model-allowance-effort-item[disabled]{opacity:.6;cursor:default}",
|
|
1010
|
-
// The trailing label names the state of one model: the one in use, or the
|
|
1011
|
-
// one being switched to.
|
|
1012
|
-
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
1013
|
-
// A message covers the whole list: it loads, it is empty, or the switch
|
|
1014
|
-
// failed and says why.
|
|
1015
|
-
".dsh-model-allowance-model-message{padding:4px 6px;color:var(--dsw-alias-label-secondary);",
|
|
1016
|
-
"font-size:11px;word-break:break-word}",
|
|
1017
|
-
'.dsh-model-allowance-model-message[data-tone="error"]{',
|
|
1018
|
-
"color:var(--dsw-alias-state-error-primary)}",
|
|
1019
|
-
".dsh-model-allowance-window{margin-top:10px;padding-top:10px;",
|
|
1020
|
-
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
1021
|
-
// The first window has no boundary above it: the switcher already ends
|
|
1022
|
-
// in a divider, and a bare provider row should not be underlined.
|
|
1023
|
-
'.dsh-model-allowance-window[data-first="true"]{margin-top:0;padding-top:8px;',
|
|
1024
|
-
"border-top:0}",
|
|
1025
|
-
".dsh-model-allowance-window-head{display:flex;justify-content:space-between;",
|
|
1026
|
-
"align-items:baseline;gap:12px}",
|
|
1027
|
-
".dsh-model-allowance-window-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
1028
|
-
".dsh-model-allowance-percent{margin-top:2px;color:var(--dsw-alias-label-secondary);",
|
|
1029
|
-
"font-size:11px;font-variant-numeric:tabular-nums}",
|
|
1030
|
-
// The bar's track is the harness's own hover tint, not a white well: on
|
|
1031
|
-
// a white card a white track was invisible, and the inset frame around
|
|
1032
|
-
// it drew the eye to the groove instead of to the fill.
|
|
1033
|
-
".dsh-model-allowance-bar{margin-top:6px;height:6px;border-radius:999px;overflow:hidden;",
|
|
1034
|
-
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1035
|
-
".dsh-model-allowance-bar-fill{height:100%;border-radius:999px;",
|
|
1036
|
-
"background:var(--dsw-alias-state-success-primary);transition:width 300ms ease}",
|
|
1037
|
-
'.dsh-model-allowance-bar-fill[data-tone="warn"]{',
|
|
1038
|
-
"background:var(--dsw-alias-state-warn-primary)}",
|
|
1039
|
-
'.dsh-model-allowance-bar-fill[data-tone="error"]{',
|
|
1040
|
-
"background:var(--dsw-alias-state-error-primary)}",
|
|
1041
|
-
".dsh-model-allowance-foot{display:flex;justify-content:space-between;",
|
|
1042
|
-
"align-items:baseline;gap:10px;flex-wrap:wrap;margin-top:5px;",
|
|
1043
|
-
"color:var(--dsw-alias-label-secondary);",
|
|
1044
|
-
"font-size:11px;font-variant-numeric:tabular-nums;word-break:break-word}",
|
|
1045
|
-
".dsh-model-allowance-error{padding:4px 0;color:var(--dsw-alias-state-error-primary)}",
|
|
1046
|
-
".dsh-model-allowance-reason{padding:2px 0;color:var(--dsw-alias-label-secondary);",
|
|
1047
|
-
"font-size:11px;word-break:break-word}",
|
|
1048
|
-
// The footer is one right-aligned cluster: the reading time sits directly
|
|
1049
|
-
// left of the two icon buttons.
|
|
1050
|
-
".dsh-model-allowance-actions{display:flex;align-items:center;",
|
|
1051
|
-
"justify-content:flex-end;gap:8px;margin-top:8px;padding-top:8px;",
|
|
1052
|
-
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
1053
|
-
".dsh-model-allowance-updated{color:var(--dsw-alias-label-secondary);font-size:11px;",
|
|
1054
|
-
"font-variant-numeric:tabular-nums;white-space:nowrap;margin-right:2px}",
|
|
1055
|
-
".dsh-model-allowance-icon-button{display:inline-flex;align-items:center;",
|
|
1056
|
-
"justify-content:center;box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
1057
|
-
"border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
1058
|
-
"color:var(--dsw-alias-label-tertiary);cursor:pointer;text-decoration:none}",
|
|
1059
|
-
".dsh-model-allowance-icon-button:hover{color:var(--dsw-alias-label-secondary);",
|
|
1060
|
-
"border-color:var(--dsw-alias-border-l3);background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1061
|
-
// The vendor in use paints the switch glyph in that vendor's own colour,
|
|
1062
|
-
// so the button says which vendor the card is on. The frame stays
|
|
1063
|
-
// neutral: a coloured frame would fight the vendor marks in the strip
|
|
1064
|
-
// above it.
|
|
1065
|
-
'.dsh-model-allowance-icon-button[data-in-use="true"]{',
|
|
1066
|
-
"color:var(--provider-mark,var(--dsw-alias-label-primary));",
|
|
1067
|
-
"border-color:var(--dsw-alias-border-l3)}",
|
|
1068
|
-
'.dsh-model-allowance-icon-button[data-in-use="true"]:hover{',
|
|
1069
|
-
"color:var(--provider-mark,var(--dsw-alias-label-primary));",
|
|
1070
|
-
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1071
|
-
".dsh-model-allowance-icon-button:focus-visible{",
|
|
1072
|
-
"outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
|
|
1073
|
-
".dsh-model-allowance-icon-button[disabled]{opacity:.5;cursor:default}",
|
|
1074
|
-
".dsh-model-allowance-icon-button svg{display:block}",
|
|
1075
|
-
// The platform status row: one dot whose colour is the state, the
|
|
1076
|
-
// localized label, and a link to the source page when the vendor
|
|
1077
|
-
// publishes one. It sits at the left edge of the footer, so the margin
|
|
1078
|
-
// below pushes the reading time and the buttons to the right edge.
|
|
1079
|
-
".dsh-model-allowance-status-wrap{display:inline-flex;align-items:center;gap:5px;",
|
|
1080
|
-
"margin-right:auto;min-width:0;font-size:11px}",
|
|
1081
|
-
".dsh-model-allowance-status{display:inline-flex;align-items:center;gap:5px;",
|
|
1082
|
-
"color:var(--dsw-alias-label-primary);text-decoration:none}",
|
|
1083
|
-
"a.dsh-model-allowance-status:hover{text-decoration:underline}",
|
|
1084
|
-
".dsh-model-allowance-status-label{flex:none}",
|
|
1085
|
-
// The degraded reason hides behind a warning mark: the footer keeps one
|
|
1086
|
-
// row, and the detail is one hover away. The mark wears the same hue an
|
|
1087
|
-
// exhausted allowance does, so the two warnings read alike.
|
|
1088
|
-
".dsh-model-allowance-status-help{position:relative;display:inline-flex;",
|
|
1089
|
-
"align-items:center;justify-content:center;box-sizing:border-box;width:14px;height:14px;",
|
|
1090
|
-
"flex:none;border:1px solid var(--dsw-alias-state-error-primary);border-radius:50%;",
|
|
1091
|
-
"color:var(--dsw-alias-state-error-primary);font-size:9px;font-weight:700;line-height:1;",
|
|
1092
|
-
"cursor:help}",
|
|
1093
|
-
".dsh-model-allowance-status-help:hover,",
|
|
1094
|
-
".dsh-model-allowance-status-help:focus-visible{background:var(--dsw-alias-state-error-primary);",
|
|
1095
|
-
"color:var(--dsw-alias-label-primary-foreground);outline:none}",
|
|
1096
|
-
".dsh-model-allowance-status-tip{display:none;position:absolute;left:0;",
|
|
1097
|
-
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
1098
|
-
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
1099
|
-
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
1100
|
-
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
1101
|
-
// The hint sits on the harness's own tooltip surface, so it takes the
|
|
1102
|
-
// text colour that surface is read with: white on the dark tooltip.
|
|
1103
|
-
"color:var(--dsw-static-neutral-bluish-00);",
|
|
1104
|
-
"white-space:normal;text-align:left}",
|
|
1105
|
-
".dsh-model-allowance-status-help:hover .dsh-model-allowance-status-tip,",
|
|
1106
|
-
".dsh-model-allowance-status-help:focus-visible .dsh-model-allowance-status-tip{display:block}",
|
|
1107
|
-
".dsh-model-allowance-status-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
1108
|
-
"background:var(--dsw-alias-state-success-primary)}",
|
|
1109
|
-
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot,',
|
|
1110
|
-
'.dsh-model-allowance-status[data-state="unsupported"] .dsh-model-allowance-status-dot,',
|
|
1111
|
-
'.dsh-model-allowance-status[data-state="unknown"] .dsh-model-allowance-status-dot{',
|
|
1112
|
-
"background:var(--dsw-alias-state-idle-primary)}",
|
|
1113
|
-
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot{opacity:.5}',
|
|
1114
|
-
'.dsh-model-allowance-status[data-state="degraded"] .dsh-model-allowance-status-dot,',
|
|
1115
|
-
'.dsh-model-allowance-status[data-state="maintenance"] .dsh-model-allowance-status-dot{',
|
|
1116
|
-
"background:var(--dsw-alias-state-warn-primary)}",
|
|
1117
|
-
'.dsh-model-allowance-status[data-state="partial-outage"] .dsh-model-allowance-status-dot,',
|
|
1118
|
-
'.dsh-model-allowance-status[data-state="major-outage"] .dsh-model-allowance-status-dot{',
|
|
1119
|
-
"background:var(--dsw-alias-state-error-primary)}",
|
|
1120
|
-
".dsh-model-allowance-status-arrow{font-size:10px;flex:none;",
|
|
1121
|
-
"color:var(--dsw-alias-label-tertiary)}",
|
|
1122
|
-
// The time-of-day pricing block: the phase the clock is in, how far
|
|
1123
|
-
// through that stretch of time it is, and the countdown. The rule itself
|
|
1124
|
-
// hides behind the help mark, so the card stays readable.
|
|
1125
|
-
".dsh-model-allowance-schedule{margin-top:10px;padding-top:10px;",
|
|
1126
|
-
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
1127
|
-
".dsh-model-allowance-schedule-head{display:flex;justify-content:space-between;",
|
|
1128
|
-
"align-items:center;gap:12px}",
|
|
1129
|
-
".dsh-model-allowance-schedule-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
1130
|
-
".dsh-model-allowance-schedule-help{position:relative;display:inline-flex;",
|
|
1131
|
-
"align-items:center;justify-content:center;box-sizing:border-box;width:16px;height:16px;",
|
|
1132
|
-
"flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:50%;",
|
|
1133
|
-
"color:var(--dsw-alias-label-tertiary);font-size:10px;font-weight:600;line-height:1;",
|
|
1134
|
-
"cursor:help}",
|
|
1135
|
-
".dsh-model-allowance-schedule-help:hover,",
|
|
1136
|
-
".dsh-model-allowance-schedule-help:focus-visible{color:var(--dsw-alias-label-primary);",
|
|
1137
|
-
"border-color:var(--dsw-alias-label-secondary);outline:none}",
|
|
1138
|
-
// Opens upwards: the block sits just above the footer, so a tooltip
|
|
1139
|
-
// hanging below it would leave the panel.
|
|
1140
|
-
".dsh-model-allowance-schedule-tip{display:none;position:absolute;right:0;",
|
|
1141
|
-
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
1142
|
-
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
1143
|
-
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
1144
|
-
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
1145
|
-
"color:var(--dsw-static-neutral-bluish-00);",
|
|
1146
|
-
"white-space:normal;text-align:left}",
|
|
1147
|
-
".dsh-model-allowance-schedule-help:hover .dsh-model-allowance-schedule-tip,",
|
|
1148
|
-
".dsh-model-allowance-schedule-help:focus-visible .dsh-model-allowance-schedule-tip{",
|
|
1149
|
-
"display:block}",
|
|
1150
|
-
".dsh-model-allowance-schedule-tip-line{display:block}",
|
|
1151
|
-
// One 24-hour strip for the vendor's day: its peak windows tinted red
|
|
1152
|
-
// and the off-peak day tinted green, both at low saturation so the
|
|
1153
|
-
// strip reads at a glance without glaring, and a cursor where the
|
|
1154
|
-
// clock stands.
|
|
1155
|
-
".dsh-model-allowance-schedule-timeline{position:relative;margin-top:8px;height:8px;",
|
|
1156
|
-
"border-radius:4px;overflow:hidden;",
|
|
1157
|
-
"background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 12%,",
|
|
1158
|
-
"var(--dsw-alias-interactive-bg-hover));}",
|
|
1159
|
-
".dsh-model-allowance-schedule-timeline-peak{position:absolute;top:0;bottom:0;",
|
|
1160
|
-
// The same hue the exhausted allowance uses, so "peak" and "spent" read
|
|
1161
|
-
// as one family of warnings rather than two unrelated colours.
|
|
1162
|
-
"background:var(--dsw-alias-state-error-primary);opacity:.4}",
|
|
1163
|
-
".dsh-model-allowance-schedule-timeline-now{position:absolute;top:0;bottom:0;width:2px;",
|
|
1164
|
-
"margin-left:-1px;border-radius:1px;background:var(--dsw-alias-label-primary);",
|
|
1165
|
-
"box-shadow:0 0 0 1px var(--dsw-alias-bg-layer-1)}",
|
|
1166
|
-
".dsh-model-allowance-schedule-ticks{display:flex;justify-content:space-between;",
|
|
1167
|
-
"margin-top:2px;font-size:9px;line-height:1;color:var(--dsw-alias-label-secondary);",
|
|
1168
|
-
"font-variant-numeric:tabular-nums}",
|
|
1169
|
-
".dsh-model-allowance-schedule-countdown{margin-top:4px;text-align:right;font-size:11px;",
|
|
1170
|
-
"color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
|
|
1171
|
-
// A badge that fades or grows while a user asks for less motion is noise.
|
|
1172
|
-
"@media (prefers-reduced-motion:reduce){.dsh-model-allowance-delta{animation:none}",
|
|
1173
|
-
".dsh-model-allowance-bar-fill{transition:none}}"
|
|
1174
|
-
];
|
|
1175
|
-
var STYLES_JOINED = STYLES.join("");
|
|
1176
|
-
|
|
1177
813
|
// src/client/windows.js
|
|
1178
814
|
function windowTitle(window, t) {
|
|
1179
815
|
const label = window.label?.[activeLanguage()] ?? window.label?.en ?? window.label?.zh;
|
|
@@ -1231,84 +867,262 @@ function barTone(percent) {
|
|
|
1231
867
|
return "ok";
|
|
1232
868
|
}
|
|
1233
869
|
|
|
1234
|
-
// src/client/
|
|
1235
|
-
var
|
|
1236
|
-
|
|
1237
|
-
|
|
870
|
+
// src/client/components/effort-flyout.js
|
|
871
|
+
var import_react3 = require("react");
|
|
872
|
+
|
|
873
|
+
// src/client/models.js
|
|
874
|
+
function providerGroup(catalog, provider) {
|
|
875
|
+
const groups = Array.isArray(catalog?.groups) ? catalog.groups : [];
|
|
876
|
+
return groups.find((group) => group?.id === provider);
|
|
1238
877
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
return
|
|
1251
|
-
} catch (error) {
|
|
1252
|
-
console.error("[model-allowance] reading provider status failed", { provider, error });
|
|
1253
|
-
return { provider, state: "unknown", error: describe(error) };
|
|
878
|
+
function modelsForProvider(catalog, provider) {
|
|
879
|
+
const group = providerGroup(catalog, provider);
|
|
880
|
+
const models = Array.isArray(group?.models) ? group.models : [];
|
|
881
|
+
return models.filter((model) => typeof model?.id === "string" && model.id !== "");
|
|
882
|
+
}
|
|
883
|
+
function providerModelGroup(catalog, routes) {
|
|
884
|
+
const seen = /* @__PURE__ */ new Set();
|
|
885
|
+
for (const route of routes) {
|
|
886
|
+
if (typeof route !== "string" || route === "" || seen.has(route)) continue;
|
|
887
|
+
seen.add(route);
|
|
888
|
+
const models = modelsForProvider(catalog, route);
|
|
889
|
+
if (models.length > 0) return { provider: route, models };
|
|
1254
890
|
}
|
|
891
|
+
return void 0;
|
|
1255
892
|
}
|
|
1256
|
-
function
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
return
|
|
893
|
+
function effortChoices(model) {
|
|
894
|
+
const reasoning = model?.reasoning;
|
|
895
|
+
const efforts = Array.isArray(reasoning?.efforts) ? reasoning.efforts : [];
|
|
896
|
+
if (efforts.length === 0) return null;
|
|
897
|
+
const entries = efforts.filter((effort) => typeof effort?.id === "string" && effort.id !== "").map((effort) => ({
|
|
898
|
+
id: effort.id,
|
|
899
|
+
name: typeof effort.name === "string" && effort.name !== "" ? effort.name : effort.id,
|
|
900
|
+
isDefault: effort.id === reasoning.defaultEffort
|
|
901
|
+
}));
|
|
902
|
+
if (reasoning.defaultEffort === void 0) {
|
|
903
|
+
entries.unshift({ id: void 0, providerDefault: true });
|
|
904
|
+
}
|
|
905
|
+
return entries;
|
|
1260
906
|
}
|
|
1261
|
-
function
|
|
1262
|
-
|
|
1263
|
-
if (
|
|
1264
|
-
return
|
|
907
|
+
function currentModelFor(selection, provider) {
|
|
908
|
+
const next = selection?.next ?? selection?.lastUsed;
|
|
909
|
+
if (next?.provider !== provider) return void 0;
|
|
910
|
+
return typeof next.model === "string" ? next.model : void 0;
|
|
1265
911
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
912
|
+
|
|
913
|
+
// src/client/components/effort-flyout.js
|
|
914
|
+
function EffortFlyout({
|
|
915
|
+
t,
|
|
916
|
+
hoverModel,
|
|
917
|
+
currentModel,
|
|
918
|
+
selectedEffort,
|
|
919
|
+
switchingModel,
|
|
920
|
+
switchToModel,
|
|
921
|
+
keepEffortFlyout,
|
|
922
|
+
scheduleEffortFlyoutClose
|
|
923
|
+
}) {
|
|
924
|
+
return (0, import_react3.createElement)(
|
|
925
|
+
"div",
|
|
926
|
+
{
|
|
927
|
+
className: "dsh-model-allowance-effort-menu",
|
|
928
|
+
role: "menu",
|
|
929
|
+
"aria-label": t("model.title"),
|
|
930
|
+
style: { top: `${hoverModel.top}px` },
|
|
931
|
+
onMouseEnter: keepEffortFlyout,
|
|
932
|
+
onMouseLeave: () => {
|
|
933
|
+
scheduleEffortFlyoutClose(hoverModel.model.id);
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
...effortChoices(hoverModel.model).map((effort) => {
|
|
937
|
+
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
938
|
+
return (0, import_react3.createElement)(
|
|
939
|
+
"button",
|
|
940
|
+
{
|
|
941
|
+
type: "button",
|
|
942
|
+
key: effort.id ?? "provider-default",
|
|
943
|
+
role: "menuitemradio",
|
|
944
|
+
"aria-checked": isCurrentEffort ? "true" : "false",
|
|
945
|
+
"data-current": isCurrentEffort ? "true" : "false",
|
|
946
|
+
"data-default": effort.isDefault ? "true" : "false",
|
|
947
|
+
className: "dsh-model-allowance-effort-item",
|
|
948
|
+
disabled: switchingModel !== null,
|
|
949
|
+
onClick: () => {
|
|
950
|
+
void switchToModel(hoverModel.model, effort.id);
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
(0, import_react3.createElement)(
|
|
954
|
+
"span",
|
|
955
|
+
{ className: "dsh-model-allowance-model-name" },
|
|
956
|
+
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
957
|
+
),
|
|
958
|
+
effort.isDefault && !isCurrentEffort ? (0, import_react3.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.effortDefault")) : null
|
|
959
|
+
);
|
|
960
|
+
})
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/client/components/model-menu.js
|
|
965
|
+
var import_react4 = require("react");
|
|
966
|
+
function ModelMenu({
|
|
967
|
+
t,
|
|
968
|
+
models,
|
|
969
|
+
state,
|
|
970
|
+
modelError,
|
|
971
|
+
currentModel,
|
|
972
|
+
switchingModel,
|
|
973
|
+
switchToModel,
|
|
974
|
+
modelWrapRef,
|
|
975
|
+
showEffortFlyout,
|
|
976
|
+
scheduleEffortFlyoutClose
|
|
977
|
+
}) {
|
|
978
|
+
return (0, import_react4.createElement)(
|
|
979
|
+
"div",
|
|
980
|
+
{
|
|
981
|
+
className: "dsh-model-allowance-model-menu",
|
|
982
|
+
role: "menu",
|
|
983
|
+
"aria-label": t("model.title")
|
|
984
|
+
},
|
|
985
|
+
state === "loading" ? (0, import_react4.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.loading")) : null,
|
|
986
|
+
state === "empty" ? (0, import_react4.createElement)("div", { className: "dsh-model-allowance-model-message" }, t("model.empty")) : null,
|
|
987
|
+
state === "error" ? (0, import_react4.createElement)(
|
|
988
|
+
"div",
|
|
989
|
+
{
|
|
990
|
+
className: "dsh-model-allowance-model-message",
|
|
991
|
+
"data-tone": "error"
|
|
992
|
+
},
|
|
993
|
+
modelError ?? t("model.unavailable")
|
|
994
|
+
) : null,
|
|
995
|
+
...models.map((model) => {
|
|
996
|
+
const isCurrent = model.id === currentModel;
|
|
997
|
+
const efforts = effortChoices(model);
|
|
998
|
+
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
999
|
+
return (0, import_react4.createElement)(
|
|
1000
|
+
"button",
|
|
1001
|
+
{
|
|
1002
|
+
type: "button",
|
|
1003
|
+
key: model.id,
|
|
1004
|
+
role: "menuitemradio",
|
|
1005
|
+
"aria-checked": isCurrent ? "true" : "false",
|
|
1006
|
+
"data-current": isCurrent ? "true" : "false",
|
|
1007
|
+
className: "dsh-model-allowance-model-item",
|
|
1008
|
+
disabled: switchingModel !== null,
|
|
1009
|
+
title: model.id,
|
|
1010
|
+
...efforts === null ? {} : { "aria-haspopup": "menu" },
|
|
1011
|
+
onClick: () => {
|
|
1012
|
+
void switchToModel(model, defaultEffortId);
|
|
1013
|
+
},
|
|
1014
|
+
...efforts === null ? {} : {
|
|
1015
|
+
onMouseEnter: (event) => {
|
|
1016
|
+
const wrap = modelWrapRef.current;
|
|
1017
|
+
if (!wrap) return;
|
|
1018
|
+
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
1019
|
+
showEffortFlyout(model, top);
|
|
1020
|
+
},
|
|
1021
|
+
onMouseLeave: () => {
|
|
1022
|
+
scheduleEffortFlyoutClose(model.id);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
(0, import_react4.createElement)("span", { className: "dsh-model-allowance-model-name" }, model.name ?? model.id),
|
|
1027
|
+
(0, import_react4.createElement)(
|
|
1028
|
+
"span",
|
|
1029
|
+
{ className: "dsh-model-allowance-model-side" },
|
|
1030
|
+
switchingModel === model.id ? (0, import_react4.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.switching")) : isCurrent ? (0, import_react4.createElement)("span", { className: "dsh-model-allowance-model-note" }, t("model.current")) : null,
|
|
1031
|
+
efforts === null ? null : (0, import_react4.createElement)(
|
|
1032
|
+
"span",
|
|
1033
|
+
{
|
|
1034
|
+
className: "dsh-model-allowance-model-arrow",
|
|
1035
|
+
"aria-hidden": true
|
|
1036
|
+
},
|
|
1037
|
+
"\u203A"
|
|
1038
|
+
)
|
|
1039
|
+
)
|
|
1040
|
+
);
|
|
1041
|
+
}),
|
|
1042
|
+
// A failed switch keeps the list open and says why.
|
|
1043
|
+
modelError && state !== "error" ? (0, import_react4.createElement)(
|
|
1044
|
+
"div",
|
|
1045
|
+
{
|
|
1046
|
+
className: "dsh-model-allowance-model-message",
|
|
1047
|
+
"data-tone": "error"
|
|
1048
|
+
},
|
|
1049
|
+
modelError
|
|
1050
|
+
) : null
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/client/components/provider-strip.js
|
|
1055
|
+
var React2 = __toESM(require("react"), 1);
|
|
1056
|
+
var import_react5 = require("react");
|
|
1057
|
+
|
|
1058
|
+
// src/client/hooks/use-provider-directory.js
|
|
1059
|
+
var React = __toESM(require("react"), 1);
|
|
1060
|
+
|
|
1061
|
+
// src/client/namespace.js
|
|
1062
|
+
var balanceNamespace = null;
|
|
1063
|
+
var settleBalanceNamespace;
|
|
1064
|
+
var balanceNamespaceReady = new Promise((resolve) => {
|
|
1065
|
+
settleBalanceNamespace = resolve;
|
|
1066
|
+
});
|
|
1067
|
+
async function getBalanceApi() {
|
|
1068
|
+
if (balanceNamespace) return balanceNamespace;
|
|
1069
|
+
return await balanceNamespaceReady;
|
|
1070
|
+
}
|
|
1071
|
+
function lookupBalanceNamespace(ctx) {
|
|
1072
|
+
try {
|
|
1073
|
+
return ctx.get("remote.balance");
|
|
1074
|
+
} catch {
|
|
1075
|
+
return void 0;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
function setBalanceNamespace(value) {
|
|
1079
|
+
balanceNamespace = value;
|
|
1080
|
+
settleBalanceNamespace(value);
|
|
1081
|
+
return value;
|
|
1082
|
+
}
|
|
1083
|
+
var modelSupport;
|
|
1084
|
+
function resetBalanceNamespace() {
|
|
1085
|
+
balanceNamespace = null;
|
|
1086
|
+
modelSupport = void 0;
|
|
1087
|
+
}
|
|
1088
|
+
function lookupSessionFace(ctx) {
|
|
1089
|
+
try {
|
|
1090
|
+
const face = ctx.get("remote.session");
|
|
1091
|
+
if (face !== void 0) return face;
|
|
1092
|
+
} catch {
|
|
1093
|
+
}
|
|
1094
|
+
return ctx.remote?.session;
|
|
1095
|
+
}
|
|
1096
|
+
async function supportsModel(api) {
|
|
1097
|
+
if (modelSupport !== void 0) return modelSupport;
|
|
1098
|
+
if (typeof api?.capabilities !== "function") {
|
|
1099
|
+
modelSupport = false;
|
|
1100
|
+
return modelSupport;
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
const result = await api.capabilities();
|
|
1104
|
+
modelSupport = result?.ok === true && result.value?.modelScoped === true;
|
|
1105
|
+
} catch {
|
|
1106
|
+
modelSupport = false;
|
|
1107
|
+
}
|
|
1108
|
+
return modelSupport;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/client/hooks/use-provider-directory.js
|
|
1112
|
+
function entryCovers(entry, route) {
|
|
1113
|
+
if (entry === void 0 || entry === null) return false;
|
|
1114
|
+
if (entry.route === route) return true;
|
|
1115
|
+
return Array.isArray(entry.aliases) && entry.aliases.includes(route);
|
|
1116
|
+
}
|
|
1117
|
+
function useProviderDirectory(selected) {
|
|
1118
|
+
const [directory, setDirectory] = React.useState([]);
|
|
1119
|
+
const [defaultProvider, setDefaultProvider] = React.useState(null);
|
|
1120
|
+
React.useEffect(() => {
|
|
1121
|
+
let cancelled = false;
|
|
1122
|
+
(async () => {
|
|
1123
|
+
try {
|
|
1124
|
+
const api = await getBalanceApi();
|
|
1125
|
+
if (!api || typeof api.list !== "function") return;
|
|
1312
1126
|
const result = await api.list();
|
|
1313
1127
|
if (cancelled || !result.ok) return;
|
|
1314
1128
|
setDirectory(result.value);
|
|
@@ -1329,8 +1143,8 @@ function BalanceBadge(props) {
|
|
|
1329
1143
|
if (!api || typeof api.defaultProvider !== "function") return;
|
|
1330
1144
|
const result = await api.defaultProvider();
|
|
1331
1145
|
if (cancelled || result?.ok !== true) return;
|
|
1332
|
-
const
|
|
1333
|
-
if (typeof
|
|
1146
|
+
const provider = result.value?.provider;
|
|
1147
|
+
if (typeof provider === "string" && provider !== "") setDefaultProvider(provider);
|
|
1334
1148
|
} catch (error) {
|
|
1335
1149
|
console.error("[model-allowance] reading the default provider failed", { error });
|
|
1336
1150
|
}
|
|
@@ -1339,34 +1153,50 @@ function BalanceBadge(props) {
|
|
|
1339
1153
|
cancelled = true;
|
|
1340
1154
|
};
|
|
1341
1155
|
}, [selected]);
|
|
1342
|
-
const
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
const
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1156
|
+
const available = directory.filter((entry) => entry.configured);
|
|
1157
|
+
const entryOf = React.useCallback(
|
|
1158
|
+
(route) => directory.find((entry) => entryCovers(entry, route)),
|
|
1159
|
+
[directory]
|
|
1160
|
+
);
|
|
1161
|
+
const nameOf = React.useCallback((route) => pickName(entryOf(route), route), [entryOf]);
|
|
1162
|
+
return { available, defaultProvider, entryOf, nameOf };
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// src/client/components/provider-strip.js
|
|
1166
|
+
function splitStrip(entries, stripWidth, activeProvider) {
|
|
1167
|
+
const MARK_SIZE = 26;
|
|
1168
|
+
const MARK_GAP = 4;
|
|
1169
|
+
const MENU_SIZE = 26;
|
|
1170
|
+
const perMark = MARK_SIZE + MARK_GAP;
|
|
1171
|
+
let visibleCount = entries.length;
|
|
1172
|
+
if (stripWidth > 0 && entries.length * perMark - MARK_GAP > stripWidth) {
|
|
1173
|
+
visibleCount = Math.max(1, Math.floor((stripWidth - MENU_SIZE - MARK_GAP) / perMark));
|
|
1174
|
+
visibleCount = Math.min(visibleCount, entries.length - 1);
|
|
1175
|
+
}
|
|
1176
|
+
let shown = entries.slice(0, visibleCount);
|
|
1177
|
+
let overflow = entries.slice(visibleCount);
|
|
1178
|
+
const activeIndex = overflow.findIndex((entry) => entryCovers(entry, activeProvider));
|
|
1179
|
+
if (activeIndex >= 0 && shown.length > 0) {
|
|
1180
|
+
const displaced = shown[shown.length - 1];
|
|
1181
|
+
shown = [...shown.slice(0, -1), overflow[activeIndex]];
|
|
1182
|
+
overflow = [...overflow.slice(0, activeIndex), displaced, ...overflow.slice(activeIndex + 1)];
|
|
1183
|
+
}
|
|
1184
|
+
return { shown, overflow };
|
|
1185
|
+
}
|
|
1186
|
+
function ProviderStrip({
|
|
1187
|
+
t,
|
|
1188
|
+
available,
|
|
1189
|
+
activeProvider,
|
|
1190
|
+
markFor,
|
|
1191
|
+
nameOf,
|
|
1192
|
+
onPick,
|
|
1193
|
+
menuOpen,
|
|
1194
|
+
setMenuOpen,
|
|
1195
|
+
stripWidth,
|
|
1196
|
+
setStripWidth,
|
|
1197
|
+
stripRef
|
|
1198
|
+
}) {
|
|
1199
|
+
React2.useEffect(() => {
|
|
1370
1200
|
const node = stripRef.current;
|
|
1371
1201
|
if (!node) return;
|
|
1372
1202
|
const measure = () => setStripWidth(node.clientWidth ?? 0);
|
|
@@ -1375,153 +1205,1109 @@ function BalanceBadge(props) {
|
|
|
1375
1205
|
const observer = new ResizeObserver(measure);
|
|
1376
1206
|
observer.observe(node);
|
|
1377
1207
|
return () => observer.disconnect();
|
|
1378
|
-
}, [
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1208
|
+
}, [setStripWidth]);
|
|
1209
|
+
const { shown, overflow } = splitStrip(available, stripWidth, activeProvider);
|
|
1210
|
+
const markButton = (entry) => {
|
|
1211
|
+
const mark = markFor(entry.route);
|
|
1212
|
+
const name = nameOf(entry.route);
|
|
1213
|
+
const active = entryCovers(entry, activeProvider);
|
|
1214
|
+
return (0, import_react5.createElement)(
|
|
1215
|
+
"button",
|
|
1216
|
+
{
|
|
1217
|
+
type: "button",
|
|
1218
|
+
key: entry.route,
|
|
1219
|
+
role: "tab",
|
|
1220
|
+
className: "dsh-model-allowance-tab",
|
|
1221
|
+
"data-active": active ? "true" : "false",
|
|
1222
|
+
"aria-selected": active ? "true" : "false",
|
|
1223
|
+
"aria-label": name,
|
|
1224
|
+
title: name,
|
|
1225
|
+
style: { "--provider-mark": mark.color },
|
|
1226
|
+
onClick: () => {
|
|
1227
|
+
onPick(entry.route);
|
|
1228
|
+
setMenuOpen(false);
|
|
1229
|
+
}
|
|
1230
|
+
},
|
|
1231
|
+
providerIcon(entry.route, 14, mark)
|
|
1232
|
+
);
|
|
1233
|
+
};
|
|
1234
|
+
const onTabKeyDown = (event) => {
|
|
1235
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
1236
|
+
const tabs = [...event.currentTarget.querySelectorAll('[role="tab"]')];
|
|
1237
|
+
if (tabs.length === 0) return;
|
|
1238
|
+
const index = tabs.indexOf(document.activeElement);
|
|
1239
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + tabs.length) % tabs.length;
|
|
1240
|
+
event.preventDefault();
|
|
1241
|
+
tabs[next]?.focus();
|
|
1242
|
+
};
|
|
1243
|
+
return (0, import_react5.createElement)(
|
|
1244
|
+
"div",
|
|
1245
|
+
{ className: "dsh-model-allowance-switcher-wrap" },
|
|
1246
|
+
(0, import_react5.createElement)(
|
|
1247
|
+
"div",
|
|
1248
|
+
{
|
|
1249
|
+
ref: stripRef,
|
|
1250
|
+
className: "dsh-model-allowance-switcher",
|
|
1251
|
+
role: "tablist",
|
|
1252
|
+
"aria-label": t("detail.provider"),
|
|
1253
|
+
onKeyDown: onTabKeyDown
|
|
1254
|
+
},
|
|
1255
|
+
...shown.map(markButton),
|
|
1256
|
+
overflow.length > 0 ? (0, import_react5.createElement)(
|
|
1257
|
+
"button",
|
|
1258
|
+
{
|
|
1259
|
+
type: "button",
|
|
1260
|
+
className: "dsh-model-allowance-more",
|
|
1261
|
+
"aria-haspopup": "menu",
|
|
1262
|
+
"aria-expanded": menuOpen ? "true" : "false",
|
|
1263
|
+
"aria-label": t("detail.moreProviders"),
|
|
1264
|
+
title: t("detail.moreProviders"),
|
|
1265
|
+
onClick: () => setMenuOpen((value) => !value)
|
|
1266
|
+
},
|
|
1267
|
+
"\u22EF"
|
|
1268
|
+
) : null
|
|
1269
|
+
),
|
|
1270
|
+
menuOpen && overflow.length > 0 ? (0, import_react5.createElement)(
|
|
1271
|
+
"div",
|
|
1272
|
+
{ className: "dsh-model-allowance-menu", role: "menu" },
|
|
1273
|
+
...overflow.map(
|
|
1274
|
+
(entry) => (0, import_react5.createElement)(
|
|
1275
|
+
"button",
|
|
1276
|
+
{
|
|
1277
|
+
type: "button",
|
|
1278
|
+
key: entry.route,
|
|
1279
|
+
role: "menuitem",
|
|
1280
|
+
className: "dsh-model-allowance-menu-item",
|
|
1281
|
+
onClick: () => {
|
|
1282
|
+
onPick(entry.route);
|
|
1283
|
+
setMenuOpen(false);
|
|
1284
|
+
}
|
|
1285
|
+
},
|
|
1286
|
+
(0, import_react5.createElement)(
|
|
1287
|
+
"span",
|
|
1288
|
+
{
|
|
1289
|
+
className: "dsh-model-allowance-menu-mark",
|
|
1290
|
+
style: { "--provider-mark": markFor(entry.route).color }
|
|
1291
|
+
},
|
|
1292
|
+
providerIcon(entry.route, 11, markFor(entry.route))
|
|
1293
|
+
),
|
|
1294
|
+
(0, import_react5.createElement)("span", null, nameOf(entry.route))
|
|
1295
|
+
)
|
|
1296
|
+
)
|
|
1297
|
+
) : null
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// src/client/components/balance-panel.js
|
|
1302
|
+
function BalancePanel({
|
|
1303
|
+
t,
|
|
1304
|
+
now,
|
|
1305
|
+
view,
|
|
1306
|
+
activeProvider,
|
|
1307
|
+
available,
|
|
1308
|
+
schedule,
|
|
1309
|
+
currentStatus,
|
|
1310
|
+
serviceState,
|
|
1311
|
+
refresh,
|
|
1312
|
+
refreshing,
|
|
1313
|
+
canSwitch,
|
|
1314
|
+
inUse,
|
|
1315
|
+
switchLabel,
|
|
1316
|
+
selectedEffort,
|
|
1317
|
+
setPicked,
|
|
1318
|
+
nameOf,
|
|
1319
|
+
markFor,
|
|
1320
|
+
catalog,
|
|
1321
|
+
menuOpen,
|
|
1322
|
+
setMenuOpen,
|
|
1323
|
+
stripWidth,
|
|
1324
|
+
setStripWidth,
|
|
1325
|
+
stripRef
|
|
1326
|
+
}) {
|
|
1327
|
+
return (0, import_react6.createElement)(
|
|
1328
|
+
"div",
|
|
1329
|
+
{
|
|
1330
|
+
className: "dsh-model-allowance-panel",
|
|
1331
|
+
id: "dsh-model-allowance-panel",
|
|
1332
|
+
role: "dialog",
|
|
1333
|
+
"aria-label": t("detail.title")
|
|
1334
|
+
},
|
|
1335
|
+
// With more than one readable provider the card opens a switcher;
|
|
1336
|
+
// with one there is nothing to switch, so it just names it.
|
|
1337
|
+
available.length > 1 ? (0, import_react6.createElement)(ProviderStrip, {
|
|
1338
|
+
t,
|
|
1339
|
+
available,
|
|
1340
|
+
activeProvider,
|
|
1341
|
+
markFor,
|
|
1342
|
+
nameOf,
|
|
1343
|
+
onPick: setPicked,
|
|
1344
|
+
menuOpen,
|
|
1345
|
+
setMenuOpen,
|
|
1346
|
+
stripWidth,
|
|
1347
|
+
setStripWidth,
|
|
1348
|
+
stripRef
|
|
1349
|
+
}) : (0, import_react6.createElement)(
|
|
1350
|
+
"div",
|
|
1351
|
+
{ className: "dsh-model-allowance-row" },
|
|
1352
|
+
(0, import_react6.createElement)("span", null, t("detail.provider")),
|
|
1353
|
+
(0, import_react6.createElement)("span", null, nameOf(activeProvider))
|
|
1354
|
+
),
|
|
1355
|
+
view?.kind === "amount" && typeof view.amount === "number" ? (0, import_react6.createElement)(
|
|
1356
|
+
"div",
|
|
1357
|
+
{ className: "dsh-model-allowance-row" },
|
|
1358
|
+
(0, import_react6.createElement)("span", null, t("detail.amount")),
|
|
1359
|
+
(0, import_react6.createElement)("span", null, formatAmount(view.amount, view.currency))
|
|
1360
|
+
) : null,
|
|
1361
|
+
...Array.isArray(view?.windows) && view.windows.length > 0 ? view.windows.map((window, index) => {
|
|
1362
|
+
const consumed = windowUsedPercent(window);
|
|
1363
|
+
const percent = consumed === void 0 ? void 0 : Math.max(0, Math.round(consumed));
|
|
1364
|
+
const filled = consumed === void 0 ? 0 : Math.min(100, Math.max(0, consumed));
|
|
1365
|
+
const usage = windowUsage(window, t);
|
|
1366
|
+
return (0, import_react6.createElement)(
|
|
1367
|
+
"div",
|
|
1368
|
+
{
|
|
1369
|
+
className: "dsh-model-allowance-window",
|
|
1370
|
+
key: `w-${String(index)}`,
|
|
1371
|
+
// The first block needs no divider: the switcher above
|
|
1372
|
+
// it already ends in one, and a bare provider row does
|
|
1373
|
+
// not deserve a line either. Only the boundaries
|
|
1374
|
+
// *between* windows are drawn.
|
|
1375
|
+
"data-first": index === 0 ? "true" : void 0
|
|
1376
|
+
},
|
|
1377
|
+
(0, import_react6.createElement)(
|
|
1378
|
+
"div",
|
|
1379
|
+
{ className: "dsh-model-allowance-window-head" },
|
|
1380
|
+
(0, import_react6.createElement)("span", { className: "dsh-model-allowance-window-title" }, windowTitle(window, t)),
|
|
1381
|
+
// Countable units sit beside the title; a plan that
|
|
1382
|
+
// reports only a percentage has none to show.
|
|
1383
|
+
usage === void 0 ? null : (0, import_react6.createElement)("span", { className: "dsh-model-allowance-usage" }, usage)
|
|
1384
|
+
),
|
|
1385
|
+
percent === void 0 ? null : (0, import_react6.createElement)(
|
|
1386
|
+
"div",
|
|
1387
|
+
{ className: "dsh-model-allowance-percent" },
|
|
1388
|
+
t("window.usedPercent", { percent })
|
|
1389
|
+
),
|
|
1390
|
+
percent === void 0 ? null : (0, import_react6.createElement)(
|
|
1391
|
+
"div",
|
|
1392
|
+
{
|
|
1393
|
+
className: "dsh-model-allowance-bar",
|
|
1394
|
+
role: "progressbar",
|
|
1395
|
+
"aria-valuenow": percent,
|
|
1396
|
+
"aria-valuemin": 0,
|
|
1397
|
+
"aria-valuemax": 100,
|
|
1398
|
+
"aria-valuetext": t("window.usedPercent", { percent })
|
|
1399
|
+
},
|
|
1400
|
+
(0, import_react6.createElement)("div", {
|
|
1401
|
+
className: "dsh-model-allowance-bar-fill",
|
|
1402
|
+
"data-tone": barTone(percent),
|
|
1403
|
+
style: { width: `${String(filled)}%` }
|
|
1404
|
+
})
|
|
1405
|
+
),
|
|
1406
|
+
// A window with zero usage has not started its rolling timer
|
|
1407
|
+
// yet, so the countdown would be misleading. Hide it until
|
|
1408
|
+
// consumption begins.
|
|
1409
|
+
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0, import_react6.createElement)(
|
|
1410
|
+
"div",
|
|
1411
|
+
{ className: "dsh-model-allowance-foot" },
|
|
1412
|
+
(0, import_react6.createElement)(
|
|
1413
|
+
"span",
|
|
1414
|
+
null,
|
|
1415
|
+
t("window.resetIn", {
|
|
1416
|
+
duration: formatCountdown(window.resetAt - now)
|
|
1417
|
+
})
|
|
1418
|
+
),
|
|
1419
|
+
(0, import_react6.createElement)("span", null, formatResetAt(window.resetAt))
|
|
1420
|
+
) : null
|
|
1421
|
+
);
|
|
1422
|
+
}) : [],
|
|
1423
|
+
// A single scalar reading has no windows to break down.
|
|
1424
|
+
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0, import_react6.createElement)(
|
|
1425
|
+
"div",
|
|
1426
|
+
{ className: "dsh-model-allowance-row" },
|
|
1427
|
+
(0, import_react6.createElement)("span", null, t("detail.remaining")),
|
|
1428
|
+
(0, import_react6.createElement)("span", null, formatDuration(view.remainingMs, t))
|
|
1429
|
+
) : null,
|
|
1430
|
+
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0, import_react6.createElement)(
|
|
1431
|
+
"div",
|
|
1432
|
+
{ className: "dsh-model-allowance-row" },
|
|
1433
|
+
(0, import_react6.createElement)("span", null, t("detail.remaining")),
|
|
1434
|
+
(0, import_react6.createElement)("span", null, String(view.remaining))
|
|
1435
|
+
) : null,
|
|
1436
|
+
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0, import_react6.createElement)(
|
|
1437
|
+
"div",
|
|
1438
|
+
{ className: "dsh-model-allowance-row" },
|
|
1439
|
+
(0, import_react6.createElement)("span", null, t("detail.total")),
|
|
1440
|
+
(0, import_react6.createElement)("span", null, String(view.total))
|
|
1441
|
+
) : null,
|
|
1442
|
+
view?.status === "failed" ? (0, import_react6.createElement)(
|
|
1443
|
+
"div",
|
|
1444
|
+
{ className: "dsh-model-allowance-error" },
|
|
1445
|
+
t("detail.error"),
|
|
1446
|
+
// The Host reports why a reading failed; showing it is what
|
|
1447
|
+
// turns "it does not work" into something actionable.
|
|
1448
|
+
view.error ? (0, import_react6.createElement)("div", { className: "dsh-model-allowance-reason" }, view.error) : null
|
|
1449
|
+
) : null,
|
|
1450
|
+
view?.status === "unsupported" ? (0, import_react6.createElement)(
|
|
1451
|
+
"div",
|
|
1452
|
+
{ className: "dsh-model-allowance-reason" },
|
|
1453
|
+
t("badge.unsupportedWithName", { name: nameOf(activeProvider) })
|
|
1454
|
+
) : null,
|
|
1455
|
+
view?.status === "unconfigured" ? (0, import_react6.createElement)(
|
|
1456
|
+
"div",
|
|
1457
|
+
{ className: "dsh-model-allowance-reason" },
|
|
1458
|
+
t("badge.setupHint"),
|
|
1459
|
+
// The reading carries the provider's setup guide; it is the walk
|
|
1460
|
+
// from "no credential" to a stored pair, so it is one click away.
|
|
1461
|
+
view.setupUrl ? (0, import_react6.createElement)(
|
|
1462
|
+
"a",
|
|
1463
|
+
{
|
|
1464
|
+
className: "dsh-model-allowance-setup-link",
|
|
1465
|
+
href: view.setupUrl,
|
|
1466
|
+
target: "_blank",
|
|
1467
|
+
rel: "noreferrer noopener"
|
|
1468
|
+
},
|
|
1469
|
+
`${t("badge.setupDoc")} \u2197`
|
|
1470
|
+
) : null
|
|
1471
|
+
) : null,
|
|
1472
|
+
// A vendor that prices by the wall clock gets its phase and
|
|
1473
|
+
// countdown here, above the footer.
|
|
1474
|
+
schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
|
|
1475
|
+
(0, import_react6.createElement)(
|
|
1476
|
+
"div",
|
|
1477
|
+
{ className: "dsh-model-allowance-actions" },
|
|
1478
|
+
// The platform status sits at the left edge of the footer, on
|
|
1479
|
+
// the same line as the reading time: the card gains no extra
|
|
1480
|
+
// row, and the state and the source page stay together.
|
|
1481
|
+
(0, import_react6.createElement)(
|
|
1482
|
+
"span",
|
|
1483
|
+
{ className: "dsh-model-allowance-status-wrap" },
|
|
1484
|
+
(0, import_react6.createElement)(
|
|
1485
|
+
currentStatus?.url ? "a" : "span",
|
|
1486
|
+
{
|
|
1487
|
+
className: "dsh-model-allowance-status",
|
|
1488
|
+
"data-state": serviceState,
|
|
1489
|
+
...currentStatus?.url ? {
|
|
1490
|
+
href: currentStatus.url,
|
|
1491
|
+
target: "_blank",
|
|
1492
|
+
rel: "noreferrer noopener"
|
|
1493
|
+
} : {}
|
|
1494
|
+
},
|
|
1495
|
+
(0, import_react6.createElement)("span", {
|
|
1496
|
+
className: "dsh-model-allowance-status-dot",
|
|
1497
|
+
"aria-hidden": true
|
|
1498
|
+
}),
|
|
1499
|
+
(0, import_react6.createElement)(
|
|
1500
|
+
"span",
|
|
1501
|
+
{ className: "dsh-model-allowance-status-label" },
|
|
1502
|
+
statusLabel(serviceState, t)
|
|
1503
|
+
),
|
|
1504
|
+
...currentStatus?.url ? [
|
|
1505
|
+
(0, import_react6.createElement)(
|
|
1506
|
+
"span",
|
|
1507
|
+
{
|
|
1508
|
+
className: "dsh-model-allowance-status-arrow",
|
|
1509
|
+
"aria-hidden": true
|
|
1510
|
+
},
|
|
1511
|
+
"\u2197"
|
|
1512
|
+
)
|
|
1513
|
+
] : []
|
|
1514
|
+
),
|
|
1515
|
+
// The reason is a warning mark rather than another line:
|
|
1516
|
+
// the footer stays one row, and the detail is one hover
|
|
1517
|
+
// — or one keyboard focus — away.
|
|
1518
|
+
currentStatus?.summary ? (0, import_react6.createElement)(
|
|
1519
|
+
"span",
|
|
1520
|
+
{
|
|
1521
|
+
className: "dsh-model-allowance-status-help",
|
|
1522
|
+
tabIndex: 0,
|
|
1523
|
+
role: "note",
|
|
1524
|
+
"aria-label": currentStatus.summary
|
|
1525
|
+
},
|
|
1526
|
+
(0, import_react6.createElement)(
|
|
1527
|
+
"span",
|
|
1528
|
+
{
|
|
1529
|
+
"aria-hidden": true
|
|
1530
|
+
},
|
|
1531
|
+
"!"
|
|
1532
|
+
),
|
|
1533
|
+
(0, import_react6.createElement)(
|
|
1534
|
+
"span",
|
|
1535
|
+
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
1536
|
+
currentStatus.summary
|
|
1537
|
+
)
|
|
1538
|
+
) : null
|
|
1539
|
+
),
|
|
1540
|
+
view?.updatedAt ? (0, import_react6.createElement)(
|
|
1541
|
+
"span",
|
|
1542
|
+
{ className: "dsh-model-allowance-updated" },
|
|
1543
|
+
t("detail.updatedAt", { time: formatClock(view.updatedAt) })
|
|
1544
|
+
) : null,
|
|
1545
|
+
(0, import_react6.createElement)(
|
|
1546
|
+
"button",
|
|
1547
|
+
{
|
|
1548
|
+
type: "button",
|
|
1549
|
+
className: "dsh-model-allowance-icon-button",
|
|
1550
|
+
onClick: refresh,
|
|
1551
|
+
disabled: refreshing,
|
|
1552
|
+
title: refreshing ? t("detail.refreshing") : t("detail.refresh"),
|
|
1553
|
+
"aria-label": refreshing ? t("detail.refreshing") : t("detail.refresh")
|
|
1554
|
+
},
|
|
1555
|
+
refreshGlyph(16)
|
|
1556
|
+
),
|
|
1557
|
+
view?.consoleUrl ? (0, import_react6.createElement)(
|
|
1558
|
+
"a",
|
|
1559
|
+
{
|
|
1560
|
+
className: "dsh-model-allowance-icon-button",
|
|
1561
|
+
href: view.consoleUrl,
|
|
1562
|
+
target: "_blank",
|
|
1563
|
+
rel: "noreferrer noopener",
|
|
1564
|
+
title: t("detail.console"),
|
|
1565
|
+
"aria-label": t("detail.console")
|
|
1566
|
+
},
|
|
1567
|
+
consoleGlyph(16)
|
|
1568
|
+
) : null,
|
|
1569
|
+
// The switch to another model of this provider. It sits to the
|
|
1570
|
+
// right of the console link, which is the last thing the footer
|
|
1571
|
+
// offered before, so the two never trade places.
|
|
1572
|
+
canSwitch ? (0, import_react6.createElement)(
|
|
1573
|
+
"span",
|
|
1574
|
+
{ ref: catalog.modelWrapRef, className: "dsh-model-allowance-model-wrap" },
|
|
1575
|
+
(0, import_react6.createElement)(
|
|
1576
|
+
"button",
|
|
1577
|
+
{
|
|
1578
|
+
type: "button",
|
|
1579
|
+
className: "dsh-model-allowance-icon-button",
|
|
1580
|
+
"aria-haspopup": "menu",
|
|
1581
|
+
"aria-expanded": catalog.modelMenuOpen ? "true" : "false",
|
|
1582
|
+
// The vendor in use paints the glyph in its own
|
|
1583
|
+
// colour, so the button says which vendor the card is
|
|
1584
|
+
// on instead of the strip having to say it twice.
|
|
1585
|
+
"data-in-use": inUse ? "true" : "false",
|
|
1586
|
+
style: { "--provider-mark": markFor(activeProvider).color },
|
|
1587
|
+
title: switchLabel,
|
|
1588
|
+
"aria-label": switchLabel,
|
|
1589
|
+
onClick: catalog.toggleModelMenu
|
|
1590
|
+
},
|
|
1591
|
+
modelGlyph(16)
|
|
1592
|
+
),
|
|
1593
|
+
catalog.modelMenuOpen ? (0, import_react6.createElement)(ModelMenu, {
|
|
1594
|
+
t,
|
|
1595
|
+
models: catalog.shownModelList,
|
|
1596
|
+
state: catalog.shownModelListState,
|
|
1597
|
+
modelError: catalog.modelError,
|
|
1598
|
+
currentModel: catalog.currentModel,
|
|
1599
|
+
switchingModel: catalog.switchingModel,
|
|
1600
|
+
switchToModel: catalog.switchToModel,
|
|
1601
|
+
modelWrapRef: catalog.modelWrapRef,
|
|
1602
|
+
showEffortFlyout: catalog.showEffortFlyout,
|
|
1603
|
+
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1604
|
+
}) : null,
|
|
1605
|
+
// The effort flyout is a sibling of the list, not a
|
|
1606
|
+
// child: the list scrolls, and a nested panel would be
|
|
1607
|
+
// clipped by it.
|
|
1608
|
+
catalog.modelMenuOpen && catalog.hoverModel !== null && catalog.shownModelList.includes(catalog.hoverModel.model) ? (0, import_react6.createElement)(EffortFlyout, {
|
|
1609
|
+
t,
|
|
1610
|
+
hoverModel: catalog.hoverModel,
|
|
1611
|
+
currentModel: catalog.currentModel,
|
|
1612
|
+
selectedEffort,
|
|
1613
|
+
switchingModel: catalog.switchingModel,
|
|
1614
|
+
switchToModel: catalog.switchToModel,
|
|
1615
|
+
keepEffortFlyout: catalog.keepEffortFlyout,
|
|
1616
|
+
scheduleEffortFlyoutClose: catalog.scheduleEffortFlyoutClose
|
|
1617
|
+
}) : null
|
|
1618
|
+
) : null
|
|
1619
|
+
)
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// src/client/hooks/use-balance-stream.js
|
|
1624
|
+
var React3 = __toESM(require("react"), 1);
|
|
1625
|
+
function describe(error) {
|
|
1626
|
+
return error instanceof Error ? error.message : String(error);
|
|
1627
|
+
}
|
|
1628
|
+
async function readProviderStatus(provider) {
|
|
1629
|
+
try {
|
|
1630
|
+
const api = await getBalanceApi();
|
|
1631
|
+
if (!api || typeof api.status !== "function") {
|
|
1632
|
+
return { provider, state: "unknown", error: "status API unavailable" };
|
|
1633
|
+
}
|
|
1634
|
+
const result = await api.status(provider);
|
|
1635
|
+
if (!result.ok) {
|
|
1636
|
+
const error = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "status reading failed";
|
|
1637
|
+
return { provider, state: "unknown", error };
|
|
1638
|
+
}
|
|
1639
|
+
return result.value;
|
|
1640
|
+
} catch (error) {
|
|
1641
|
+
console.error("[model-allowance] reading provider status failed", { provider, error });
|
|
1642
|
+
return { provider, state: "unknown", error: describe(error) };
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
function useBalanceStream({ activeProvider, activeModel, ctx, setView, setLoading }) {
|
|
1646
|
+
React3.useEffect(() => {
|
|
1647
|
+
if (!activeProvider) {
|
|
1648
|
+
setView(null);
|
|
1649
|
+
setLoading(false);
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
let cancelled = false;
|
|
1653
|
+
let handle;
|
|
1654
|
+
setLoading(true);
|
|
1655
|
+
const readOnce = async (api, model) => {
|
|
1656
|
+
try {
|
|
1657
|
+
let result = await api.balance(activeProvider, model);
|
|
1658
|
+
if (!result.ok && model !== void 0) {
|
|
1659
|
+
result = await api.balance(activeProvider, void 0);
|
|
1660
|
+
}
|
|
1661
|
+
if (cancelled) return;
|
|
1662
|
+
if (!result.ok) {
|
|
1663
|
+
const detail = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "balance reading failed";
|
|
1664
|
+
throw new Error(detail);
|
|
1665
|
+
}
|
|
1666
|
+
setView(result.value);
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
console.error("[model-allowance] reading failed", {
|
|
1669
|
+
provider: activeProvider,
|
|
1670
|
+
model,
|
|
1671
|
+
error
|
|
1672
|
+
});
|
|
1673
|
+
if (!cancelled) {
|
|
1674
|
+
setView({
|
|
1675
|
+
provider: activeProvider,
|
|
1676
|
+
status: "failed",
|
|
1677
|
+
kind: "quota",
|
|
1678
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
} finally {
|
|
1682
|
+
if (!cancelled) setLoading(false);
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
(async () => {
|
|
1686
|
+
const api = await getBalanceApi();
|
|
1687
|
+
if (cancelled) return;
|
|
1688
|
+
if (!api) {
|
|
1689
|
+
setView({
|
|
1690
|
+
provider: activeProvider,
|
|
1691
|
+
status: "failed",
|
|
1692
|
+
kind: "quota",
|
|
1693
|
+
error: "balance namespace unavailable"
|
|
1694
|
+
});
|
|
1695
|
+
setLoading(false);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
const readModel = await supportsModel(api) ? activeModel : void 0;
|
|
1699
|
+
if (cancelled) return;
|
|
1700
|
+
const remote = ctx.remote;
|
|
1701
|
+
if (typeof remote?.$stream === "function" && typeof api.watch === "function") {
|
|
1702
|
+
try {
|
|
1703
|
+
handle = remote.$stream({
|
|
1704
|
+
name: "balance",
|
|
1705
|
+
open: (signal) => api.watch(activeProvider, readModel, signal),
|
|
1706
|
+
ended: () => new Error("balance stream ended")
|
|
1707
|
+
});
|
|
1708
|
+
} catch (error) {
|
|
1709
|
+
console.error("[model-allowance] opening the reading stream failed", { error });
|
|
1710
|
+
handle = void 0;
|
|
1711
|
+
}
|
|
1712
|
+
if (handle) {
|
|
1713
|
+
let received = false;
|
|
1714
|
+
try {
|
|
1715
|
+
for await (const item of handle) {
|
|
1716
|
+
if (cancelled) return;
|
|
1717
|
+
const frame = item?.value;
|
|
1718
|
+
if (frame === void 0) continue;
|
|
1719
|
+
received = true;
|
|
1720
|
+
setView(frame);
|
|
1721
|
+
setLoading(false);
|
|
1722
|
+
item?.accept?.();
|
|
1723
|
+
}
|
|
1724
|
+
} catch (error) {
|
|
1725
|
+
if (!cancelled) {
|
|
1726
|
+
console.error("[model-allowance] reading stream failed", {
|
|
1727
|
+
provider: activeProvider,
|
|
1728
|
+
error
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
} finally {
|
|
1732
|
+
if (!cancelled && !received) await readOnce(api, readModel);
|
|
1733
|
+
}
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
await readOnce(api, readModel);
|
|
1738
|
+
})();
|
|
1739
|
+
return () => {
|
|
1740
|
+
cancelled = true;
|
|
1741
|
+
handle?.dispose?.();
|
|
1742
|
+
};
|
|
1743
|
+
}, [activeProvider, activeModel, ctx, setView, setLoading]);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
// src/client/hooks/use-dismiss.js
|
|
1747
|
+
var React4 = __toESM(require("react"), 1);
|
|
1748
|
+
function useDismiss({ open, rootRef, modelMenuOpen, setOpen, setModelMenuOpen }) {
|
|
1749
|
+
React4.useEffect(() => {
|
|
1750
|
+
if (!open) return;
|
|
1751
|
+
const onPointerDown = (event) => {
|
|
1752
|
+
const root = rootRef.current;
|
|
1753
|
+
if (root && event.target instanceof Node && root.contains(event.target)) return;
|
|
1754
|
+
setOpen(false);
|
|
1755
|
+
};
|
|
1756
|
+
const onKeyDown = (event) => {
|
|
1757
|
+
if (event.key !== "Escape") return;
|
|
1758
|
+
if (modelMenuOpen) {
|
|
1759
|
+
setModelMenuOpen(false);
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
setOpen(false);
|
|
1763
|
+
};
|
|
1764
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1765
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1766
|
+
return () => {
|
|
1767
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1768
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1769
|
+
};
|
|
1770
|
+
}, [open, modelMenuOpen, setOpen, setModelMenuOpen]);
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// src/client/hooks/use-model-catalog.js
|
|
1774
|
+
var React5 = __toESM(require("react"), 1);
|
|
1775
|
+
var CATALOG_TTL_MS = 60 * 1e3;
|
|
1776
|
+
function useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection }) {
|
|
1777
|
+
const [modelList, setModelList] = React5.useState([]);
|
|
1778
|
+
const [modelListRoute, setModelListRoute] = React5.useState(null);
|
|
1779
|
+
const [catalogProvider, setCatalogProvider] = React5.useState(null);
|
|
1780
|
+
const [modelListState, setModelListState] = React5.useState("idle");
|
|
1781
|
+
const [modelError, setModelError] = React5.useState(null);
|
|
1782
|
+
const [modelMenuOpen, setModelMenuOpen] = React5.useState(false);
|
|
1783
|
+
const [hoverModel, setHoverModel] = React5.useState(null);
|
|
1784
|
+
const hoverModelTimer = React5.useRef(null);
|
|
1785
|
+
const [switchingModel, setSwitchingModel] = React5.useState(null);
|
|
1786
|
+
const modelWrapRef = React5.useRef(null);
|
|
1787
|
+
const catalogRef = React5.useRef({ value: null, at: 0 });
|
|
1788
|
+
const showModels = React5.useCallback(
|
|
1789
|
+
(catalog) => {
|
|
1790
|
+
const routes = [activeProvider, ...entryOf(activeProvider)?.modelRoutes ?? []];
|
|
1791
|
+
const group = providerModelGroup(catalog, routes);
|
|
1792
|
+
const models = group?.models ?? [];
|
|
1793
|
+
setCatalogProvider(group?.provider ?? null);
|
|
1794
|
+
setModelListRoute(activeProvider);
|
|
1795
|
+
setModelList(models);
|
|
1796
|
+
setModelListState(models.length > 0 ? "ready" : "empty");
|
|
1797
|
+
},
|
|
1798
|
+
[activeProvider, entryOf]
|
|
1799
|
+
);
|
|
1800
|
+
React5.useEffect(() => {
|
|
1801
|
+
if (!modelMenuOpen) return void 0;
|
|
1802
|
+
let cancelled = false;
|
|
1803
|
+
(async () => {
|
|
1804
|
+
const face = lookupSessionFace(ctx);
|
|
1805
|
+
if (face === void 0 || typeof face.modelCatalog !== "function") {
|
|
1806
|
+
setModelListState("error");
|
|
1807
|
+
setModelError(t("model.unavailable"));
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
const cached = catalogRef.current;
|
|
1811
|
+
if (cached.value !== null && Date.now() - cached.at < CATALOG_TTL_MS) {
|
|
1812
|
+
if (!cancelled) showModels(cached.value);
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
setModelListState("loading");
|
|
1816
|
+
try {
|
|
1817
|
+
const result = await face.modelCatalog();
|
|
1818
|
+
if (cancelled) return;
|
|
1819
|
+
if (!result?.ok) {
|
|
1820
|
+
setModelListState("error");
|
|
1821
|
+
setModelError(
|
|
1822
|
+
t("model.loadFailed", { error: result?.error?.message ?? result?.error?.code ?? "" })
|
|
1823
|
+
);
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
catalogRef.current = { value: result.value, at: Date.now() };
|
|
1827
|
+
showModels(result.value);
|
|
1828
|
+
} catch (error) {
|
|
1829
|
+
if (cancelled) return;
|
|
1830
|
+
setModelListState("error");
|
|
1831
|
+
setModelError(t("model.loadFailed", { error: describe(error) }));
|
|
1832
|
+
}
|
|
1833
|
+
})();
|
|
1834
|
+
return () => {
|
|
1835
|
+
cancelled = true;
|
|
1836
|
+
};
|
|
1837
|
+
}, [modelMenuOpen, ctx, t, showModels]);
|
|
1838
|
+
React5.useEffect(() => {
|
|
1839
|
+
if (!modelMenuOpen) return void 0;
|
|
1840
|
+
const onPointerDown = (event) => {
|
|
1841
|
+
const wrap = modelWrapRef.current;
|
|
1842
|
+
if (wrap && event.target instanceof Node && wrap.contains(event.target)) return;
|
|
1843
|
+
setModelMenuOpen(false);
|
|
1844
|
+
};
|
|
1845
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1846
|
+
return () => {
|
|
1847
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1848
|
+
};
|
|
1849
|
+
}, [modelMenuOpen]);
|
|
1850
|
+
const switchToModel = React5.useCallback(
|
|
1851
|
+
async (model, effort) => {
|
|
1852
|
+
const face = lookupSessionFace(ctx);
|
|
1853
|
+
if (face === void 0 || typeof face.selectModel !== "function") {
|
|
1854
|
+
setModelError(t("model.unavailable"));
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
if (typeof sessionId !== "string" || sessionId === "") {
|
|
1858
|
+
setModelError(t("model.unavailable"));
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
setSwitchingModel(model.id);
|
|
1862
|
+
try {
|
|
1863
|
+
const result = await face.selectModel({
|
|
1864
|
+
sessionId,
|
|
1865
|
+
provider: catalogProvider ?? activeProvider,
|
|
1866
|
+
model: model.id,
|
|
1867
|
+
...typeof effort === "string" && effort !== "" ? { reasoningEffort: effort } : {}
|
|
1868
|
+
});
|
|
1869
|
+
if (!result?.ok) {
|
|
1870
|
+
setModelError(
|
|
1871
|
+
t("model.failed", { error: result?.error?.message ?? result?.error?.code ?? "" })
|
|
1872
|
+
);
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
setModelError(null);
|
|
1876
|
+
setModelMenuOpen(false);
|
|
1877
|
+
} catch (error) {
|
|
1878
|
+
console.error("[model-allowance] switching the model failed", { error });
|
|
1879
|
+
setModelError(t("model.failed", { error: describe(error) }));
|
|
1880
|
+
} finally {
|
|
1881
|
+
setSwitchingModel(null);
|
|
1882
|
+
}
|
|
1883
|
+
},
|
|
1884
|
+
[ctx, sessionId, activeProvider, catalogProvider, t]
|
|
1885
|
+
);
|
|
1886
|
+
const showEffortFlyout = React5.useCallback((model, top) => {
|
|
1887
|
+
clearTimeout(hoverModelTimer.current);
|
|
1888
|
+
setHoverModel({ model, top });
|
|
1889
|
+
}, []);
|
|
1890
|
+
const scheduleEffortFlyoutClose = React5.useCallback((id) => {
|
|
1891
|
+
clearTimeout(hoverModelTimer.current);
|
|
1892
|
+
hoverModelTimer.current = setTimeout(() => {
|
|
1893
|
+
setHoverModel((current) => current?.model?.id === id ? null : current);
|
|
1894
|
+
}, 150);
|
|
1895
|
+
}, []);
|
|
1896
|
+
const keepEffortFlyout = React5.useCallback(() => {
|
|
1897
|
+
clearTimeout(hoverModelTimer.current);
|
|
1898
|
+
}, []);
|
|
1899
|
+
const toggleModelMenu = React5.useCallback(() => {
|
|
1900
|
+
setModelError(null);
|
|
1901
|
+
clearTimeout(hoverModelTimer.current);
|
|
1902
|
+
setHoverModel(null);
|
|
1903
|
+
setModelMenuOpen((value) => !value);
|
|
1904
|
+
}, []);
|
|
1905
|
+
const modelProvider = catalogProvider ?? activeProvider;
|
|
1906
|
+
const currentModel = currentModelFor(selection, modelProvider);
|
|
1907
|
+
const shownModelList = modelListRoute === activeProvider ? modelList : [];
|
|
1908
|
+
const shownModelListState = modelListRoute === activeProvider ? modelListState : "loading";
|
|
1909
|
+
return {
|
|
1910
|
+
modelMenuOpen,
|
|
1911
|
+
setModelMenuOpen,
|
|
1912
|
+
modelWrapRef,
|
|
1913
|
+
shownModelList,
|
|
1914
|
+
shownModelListState,
|
|
1915
|
+
modelError,
|
|
1916
|
+
setModelError,
|
|
1917
|
+
currentModel,
|
|
1918
|
+
switchingModel,
|
|
1919
|
+
hoverModel,
|
|
1920
|
+
showEffortFlyout,
|
|
1921
|
+
scheduleEffortFlyoutClose,
|
|
1922
|
+
keepEffortFlyout,
|
|
1923
|
+
toggleModelMenu,
|
|
1924
|
+
switchToModel
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
// src/client/styles.js
|
|
1929
|
+
var STYLES = [
|
|
1930
|
+
".dsh-model-allowance-root{position:relative;display:inline-flex;align-items:center}",
|
|
1931
|
+
// The badge is a trigger, the way the harness's own composer triggers
|
|
1932
|
+
// are: no frame of its own, a transparent surface, and the hover tint
|
|
1933
|
+
// only while the pointer is on it or the card is open. A bordered pill
|
|
1934
|
+
// read as a field rather than a control.
|
|
1935
|
+
".dsh-model-allowance-badge{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px;",
|
|
1936
|
+
"border:0;border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
1937
|
+
"color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1;cursor:pointer;",
|
|
1938
|
+
"font-variant-numeric:tabular-nums;white-space:nowrap}",
|
|
1939
|
+
".dsh-model-allowance-badge:hover{color:var(--dsw-alias-label-secondary);",
|
|
1940
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1941
|
+
'.dsh-model-allowance-badge[aria-expanded="true"]{color:var(--dsw-alias-label-secondary);',
|
|
1942
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
1943
|
+
".dsh-model-allowance-badge:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
1944
|
+
"outline-offset:1px}",
|
|
1945
|
+
".dsh-model-allowance-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
1946
|
+
"background:var(--dsw-alias-state-idle-primary)}",
|
|
1947
|
+
// The dot reports the platform, not the reading: green while the service
|
|
1948
|
+
// is available, red once its own status page says otherwise, and grey
|
|
1949
|
+
// when this installation has no status source for the route.
|
|
1950
|
+
'.dsh-model-allowance-root[data-service="operational"] .dsh-model-allowance-dot{',
|
|
1951
|
+
"background:var(--dsw-alias-state-success-primary)}",
|
|
1952
|
+
'.dsh-model-allowance-root[data-service="degraded"] .dsh-model-allowance-dot,',
|
|
1953
|
+
'.dsh-model-allowance-root[data-service="partial-outage"] .dsh-model-allowance-dot,',
|
|
1954
|
+
'.dsh-model-allowance-root[data-service="major-outage"] .dsh-model-allowance-dot,',
|
|
1955
|
+
'.dsh-model-allowance-root[data-service="maintenance"] .dsh-model-allowance-dot{',
|
|
1956
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
1957
|
+
'.dsh-model-allowance-root[data-loading="true"] .dsh-model-allowance-dot{opacity:.5}',
|
|
1958
|
+
// The turn's difference rides beside the value for a few seconds. It is
|
|
1959
|
+
// quieter than the value so the balance stays the thing being read, and
|
|
1960
|
+
// it fades in rather than popping.
|
|
1961
|
+
".dsh-model-allowance-delta{margin-left:-2px;font-size:11px;",
|
|
1962
|
+
"color:var(--dsw-alias-label-secondary);animation:dsh-model-allowance-fade 200ms ease-out}",
|
|
1963
|
+
'.dsh-model-allowance-delta[data-direction="up"]{',
|
|
1964
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
1965
|
+
"@keyframes dsh-model-allowance-fade{from{opacity:0}to{opacity:1}}",
|
|
1966
|
+
// Anchored to its own right edge: the badge sits next to the model seat
|
|
1967
|
+
// near the trailing edge, so the panel opens leftwards instead of
|
|
1968
|
+
// running off the side of the composer.
|
|
1969
|
+
//
|
|
1970
|
+
// The surface is the harness's own menu surface — a translucent white
|
|
1971
|
+
// behind a heavy blur — and the shadow is its own elevation scale. The
|
|
1972
|
+
// overlay token reads as a mask over the page behind, not as a panel
|
|
1973
|
+
// surface: on it this card came out a flat grey slab.
|
|
1974
|
+
// The floor is set for the layout, not for the content: with it removed
|
|
1975
|
+
// the card collapses to 248px, so 300px is the slack that lets a label
|
|
1976
|
+
// and its value read as two columns instead of one run-on line. The cap
|
|
1977
|
+
// is the harness's own idiom for a floating surface, so a narrow window
|
|
1978
|
+
// shrinks the card rather than pushing it off the composer.
|
|
1979
|
+
".dsh-model-allowance-panel{position:absolute;bottom:calc(100% + 6px);right:0;z-index:20;",
|
|
1980
|
+
"box-sizing:border-box;min-width:300px;max-width:calc(100vw - 24px);",
|
|
1981
|
+
"padding:8px 10px 10px;border:0;",
|
|
1982
|
+
"border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-2);",
|
|
1983
|
+
"box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);",
|
|
1984
|
+
"font-size:12px}",
|
|
1985
|
+
".dsh-model-allowance-row{display:flex;justify-content:space-between;gap:16px;padding:2px 0}",
|
|
1986
|
+
// Label first, value second, matching every other pair in the card
|
|
1987
|
+
// (schedule title/state, status/reading time): the label carries the
|
|
1988
|
+
// emphasis and the value reads as its detail. Reversed, the balance row
|
|
1989
|
+
// stood out as the one pair laid out the other way round.
|
|
1990
|
+
".dsh-model-allowance-row>span:first-child{color:var(--dsw-alias-label-primary)}",
|
|
1991
|
+
".dsh-model-allowance-row>span:last-child{color:var(--dsw-alias-label-secondary)}",
|
|
1992
|
+
".dsh-model-allowance-usage{font-variant-numeric:tabular-nums;",
|
|
1993
|
+
"color:var(--dsw-alias-label-secondary)}",
|
|
1994
|
+
// The row cancels the panel's own horizontal padding so the divider under
|
|
1995
|
+
// it runs edge to edge, then puts the same padding back so the first mark
|
|
1996
|
+
// lines up with the labels below. Without this the marks sit further from
|
|
1997
|
+
// the edge than every other row and the whole strip reads as shifted left.
|
|
1998
|
+
".dsh-model-allowance-switcher-wrap{position:relative;margin:-2px -10px 6px;",
|
|
1999
|
+
"padding:0 10px 8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",
|
|
2000
|
+
".dsh-model-allowance-switcher{display:flex;flex-wrap:nowrap;align-items:center;",
|
|
2001
|
+
"gap:4px;overflow:hidden}",
|
|
2002
|
+
// The mark sits straight on the panel; the chip draws no surface of its
|
|
2003
|
+
// own, so the panel's own surface shows through behind the logo.
|
|
2004
|
+
//
|
|
2005
|
+
// A frame means one thing here: this is the provider being read. It is
|
|
2006
|
+
// not used to say anything else about a route, because a second meaning
|
|
2007
|
+
// makes an unselected mark look selected.
|
|
2008
|
+
".dsh-model-allowance-tab{display:inline-flex;align-items:center;justify-content:center;",
|
|
2009
|
+
"box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
2010
|
+
"border:1px solid transparent;border-radius:var(--dsw-radius-sm);",
|
|
2011
|
+
"background:0 0;line-height:1;cursor:pointer;",
|
|
2012
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary));opacity:.66}",
|
|
2013
|
+
".dsh-model-allowance-tab:hover{opacity:.9}",
|
|
2014
|
+
// The selected mark gains the one frame the chip already has, and stops
|
|
2015
|
+
// being dimmed. It must not use the brand colour: in this theme that is
|
|
2016
|
+
// #0f1115, so a selected chip wore a near-black frame. It also gains no
|
|
2017
|
+
// background, since any fill here reintroduces a tile on the panel.
|
|
2018
|
+
'.dsh-model-allowance-tab[data-active="true"]{opacity:1;',
|
|
2019
|
+
"border-color:var(--dsw-alias-border-l2)}",
|
|
2020
|
+
".dsh-model-allowance-tab:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);",
|
|
2021
|
+
"outline-offset:-1px}",
|
|
2022
|
+
".dsh-model-allowance-tab svg{display:block}",
|
|
2023
|
+
".dsh-model-allowance-tab-letter{font-size:11px;font-weight:600;line-height:1}",
|
|
2024
|
+
".dsh-model-allowance-more{display:inline-flex;align-items:center;justify-content:center;",
|
|
2025
|
+
"box-sizing:border-box;width:26px;height:26px;flex:none;margin-left:auto;padding:0;",
|
|
2026
|
+
"border-radius:var(--dsw-radius-sm);",
|
|
2027
|
+
"border:1px solid var(--dsw-alias-border-l1);background:0 0;cursor:pointer;",
|
|
2028
|
+
"color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}",
|
|
2029
|
+
".dsh-model-allowance-more:hover{color:var(--dsw-alias-label-secondary);",
|
|
2030
|
+
"border-color:var(--dsw-alias-border-l2)}",
|
|
2031
|
+
// The overflow menu is a second floating surface, so it carries the same
|
|
2032
|
+
// solid layer and elevation as the card it belongs to.
|
|
2033
|
+
".dsh-model-allowance-menu{position:absolute;top:calc(100% + 2px);right:0;z-index:30;",
|
|
2034
|
+
"min-width:150px;padding:4px;border:0;",
|
|
2035
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
2036
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
2037
|
+
".dsh-model-allowance-menu-item{display:flex;align-items:center;gap:8px;width:100%;",
|
|
2038
|
+
"padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);background:0 0;",
|
|
2039
|
+
"color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
2040
|
+
".dsh-model-allowance-menu-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2041
|
+
// Same rule as the strip chips: no surface of its own, so the mark sits
|
|
2042
|
+
// on the menu instead of on a tile.
|
|
2043
|
+
".dsh-model-allowance-menu-mark{display:inline-flex;align-items:center;",
|
|
2044
|
+
"justify-content:center;width:20px;height:20px;flex:none;border-radius:var(--dsw-radius-xs);",
|
|
2045
|
+
"line-height:1;background:0 0;",
|
|
2046
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary))}",
|
|
2047
|
+
".dsh-model-allowance-menu-mark svg{display:block}",
|
|
2048
|
+
// The model list is a third floating surface. It opens upwards from the
|
|
2049
|
+
// footer button, so it carries the same menu surface and elevation as the
|
|
2050
|
+
// card and the provider overflow menu.
|
|
2051
|
+
//
|
|
2052
|
+
// It is the one surface that is not translucent: the list floats over the
|
|
2053
|
+
// conversation, and a frosted panel there let the text underneath show
|
|
2054
|
+
// through the model names. A solid layer keeps the list readable wherever
|
|
2055
|
+
// it opens.
|
|
2056
|
+
".dsh-model-allowance-model-wrap{position:relative;display:inline-flex}",
|
|
2057
|
+
".dsh-model-allowance-model-menu{position:absolute;bottom:calc(100% + 4px);right:0;z-index:30;",
|
|
2058
|
+
"min-width:180px;max-width:260px;max-height:240px;overflow-y:auto;padding:4px;border:0;",
|
|
2059
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
2060
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
2061
|
+
".dsh-model-allowance-model-item{display:flex;align-items:center;justify-content:space-between;",
|
|
2062
|
+
"gap:10px;width:100%;padding:4px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
2063
|
+
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
2064
|
+
".dsh-model-allowance-model-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2065
|
+
// The model the session uses is dimmed rather than framed: a frame here
|
|
2066
|
+
// would give the chip a second meaning it does not have.
|
|
2067
|
+
'.dsh-model-allowance-model-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
2068
|
+
".dsh-model-allowance-model-item[disabled]{opacity:.6;cursor:default}",
|
|
2069
|
+
".dsh-model-allowance-model-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
2070
|
+
// The trailing side of a model row carries its state label and, for a
|
|
2071
|
+
// model with reasoning efforts, the arrow that says a flyout waits to
|
|
2072
|
+
// the right.
|
|
2073
|
+
".dsh-model-allowance-model-side{display:inline-flex;align-items:center;gap:4px;flex:none}",
|
|
2074
|
+
".dsh-model-allowance-model-arrow{color:var(--dsw-alias-label-tertiary);font-size:12px;",
|
|
2075
|
+
"line-height:1}",
|
|
2076
|
+
// The effort flyout opens to the right of the list, on the row the
|
|
2077
|
+
// pointer rests on, as a fourth floating surface of the card. It overlaps
|
|
2078
|
+
// the list, so it is solid for the same reason the list is.
|
|
2079
|
+
".dsh-model-allowance-effort-menu{position:absolute;left:calc(100% + 4px);z-index:31;",
|
|
2080
|
+
"display:flex;flex-direction:column;min-width:130px;max-width:220px;padding:4px;border:0;",
|
|
2081
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-2);",
|
|
2082
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
2083
|
+
".dsh-model-allowance-effort-item{display:flex;align-items:center;justify-content:space-between;",
|
|
2084
|
+
"gap:10px;width:100%;padding:3px 6px;border:0;border-radius:var(--dsw-radius-xs);",
|
|
2085
|
+
"background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;text-align:left;cursor:pointer}",
|
|
2086
|
+
".dsh-model-allowance-effort-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2087
|
+
// The provider's own default effort is dimmed like the model in use, so
|
|
2088
|
+
// the open submenu points at it before anything is picked.
|
|
2089
|
+
'.dsh-model-allowance-effort-item[data-default="true"],',
|
|
2090
|
+
'.dsh-model-allowance-effort-item[data-current="true"]{color:var(--dsw-alias-label-secondary)}',
|
|
2091
|
+
".dsh-model-allowance-effort-item[disabled]{opacity:.6;cursor:default}",
|
|
2092
|
+
// The trailing label names the state of one model: the one in use, or the
|
|
2093
|
+
// one being switched to.
|
|
2094
|
+
".dsh-model-allowance-model-note{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px}",
|
|
2095
|
+
// A message covers the whole list: it loads, it is empty, or the switch
|
|
2096
|
+
// failed and says why.
|
|
2097
|
+
".dsh-model-allowance-model-message{padding:4px 6px;color:var(--dsw-alias-label-secondary);",
|
|
2098
|
+
"font-size:11px;word-break:break-word}",
|
|
2099
|
+
'.dsh-model-allowance-model-message[data-tone="error"]{',
|
|
2100
|
+
"color:var(--dsw-alias-state-error-primary)}",
|
|
2101
|
+
".dsh-model-allowance-window{margin-top:10px;padding-top:10px;",
|
|
2102
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
2103
|
+
// The first window has no boundary above it: the switcher already ends
|
|
2104
|
+
// in a divider, and a bare provider row should not be underlined.
|
|
2105
|
+
'.dsh-model-allowance-window[data-first="true"]{margin-top:0;padding-top:8px;',
|
|
2106
|
+
"border-top:0}",
|
|
2107
|
+
".dsh-model-allowance-window-head{display:flex;justify-content:space-between;",
|
|
2108
|
+
"align-items:baseline;gap:12px}",
|
|
2109
|
+
".dsh-model-allowance-window-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
2110
|
+
".dsh-model-allowance-percent{margin-top:2px;color:var(--dsw-alias-label-secondary);",
|
|
2111
|
+
"font-size:11px;font-variant-numeric:tabular-nums}",
|
|
2112
|
+
// The bar's track is the harness's own hover tint, not a white well: on
|
|
2113
|
+
// a white card a white track was invisible, and the inset frame around
|
|
2114
|
+
// it drew the eye to the groove instead of to the fill.
|
|
2115
|
+
".dsh-model-allowance-bar{margin-top:6px;height:6px;border-radius:999px;overflow:hidden;",
|
|
2116
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2117
|
+
".dsh-model-allowance-bar-fill{height:100%;border-radius:999px;",
|
|
2118
|
+
"background:var(--dsw-alias-state-success-primary);transition:width 300ms ease}",
|
|
2119
|
+
'.dsh-model-allowance-bar-fill[data-tone="warn"]{',
|
|
2120
|
+
"background:var(--dsw-alias-state-warn-primary)}",
|
|
2121
|
+
'.dsh-model-allowance-bar-fill[data-tone="error"]{',
|
|
2122
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
2123
|
+
".dsh-model-allowance-foot{display:flex;justify-content:space-between;",
|
|
2124
|
+
"align-items:baseline;gap:10px;flex-wrap:wrap;margin-top:5px;",
|
|
2125
|
+
"color:var(--dsw-alias-label-secondary);",
|
|
2126
|
+
"font-size:11px;font-variant-numeric:tabular-nums;word-break:break-word}",
|
|
2127
|
+
".dsh-model-allowance-error{padding:4px 0;color:var(--dsw-alias-state-error-primary)}",
|
|
2128
|
+
".dsh-model-allowance-reason{padding:2px 0;color:var(--dsw-alias-label-secondary);",
|
|
2129
|
+
"font-size:11px;word-break:break-word}",
|
|
2130
|
+
".dsh-model-allowance-setup-link{margin-left:6px;color:var(--dsw-alias-state-business-primary);",
|
|
2131
|
+
"text-decoration:none;white-space:nowrap}",
|
|
2132
|
+
".dsh-model-allowance-setup-link:hover,.dsh-model-allowance-setup-link:focus-visible",
|
|
2133
|
+
"{text-decoration:underline}",
|
|
2134
|
+
// The footer is one right-aligned cluster: the reading time sits directly
|
|
2135
|
+
// left of the two icon buttons.
|
|
2136
|
+
".dsh-model-allowance-actions{display:flex;align-items:center;",
|
|
2137
|
+
"justify-content:flex-end;gap:8px;margin-top:8px;padding-top:8px;",
|
|
2138
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
2139
|
+
".dsh-model-allowance-updated{color:var(--dsw-alias-label-secondary);font-size:11px;",
|
|
2140
|
+
"font-variant-numeric:tabular-nums;white-space:nowrap;margin-right:2px}",
|
|
2141
|
+
".dsh-model-allowance-icon-button{display:inline-flex;align-items:center;",
|
|
2142
|
+
"justify-content:center;box-sizing:border-box;width:26px;height:26px;flex:none;padding:0;",
|
|
2143
|
+
"border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);background:0 0;",
|
|
2144
|
+
"color:var(--dsw-alias-label-tertiary);cursor:pointer;text-decoration:none}",
|
|
2145
|
+
".dsh-model-allowance-icon-button:hover{color:var(--dsw-alias-label-secondary);",
|
|
2146
|
+
"border-color:var(--dsw-alias-border-l3);background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2147
|
+
// The vendor in use paints the switch glyph in that vendor's own colour,
|
|
2148
|
+
// so the button says which vendor the card is on. The frame stays
|
|
2149
|
+
// neutral: a coloured frame would fight the vendor marks in the strip
|
|
2150
|
+
// above it.
|
|
2151
|
+
'.dsh-model-allowance-icon-button[data-in-use="true"]{',
|
|
2152
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary));",
|
|
2153
|
+
"border-color:var(--dsw-alias-border-l3)}",
|
|
2154
|
+
'.dsh-model-allowance-icon-button[data-in-use="true"]:hover{',
|
|
2155
|
+
"color:var(--provider-mark,var(--dsw-alias-label-primary));",
|
|
2156
|
+
"background:var(--dsw-alias-interactive-bg-hover)}",
|
|
2157
|
+
".dsh-model-allowance-icon-button:focus-visible{",
|
|
2158
|
+
"outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
|
|
2159
|
+
".dsh-model-allowance-icon-button[disabled]{opacity:.5;cursor:default}",
|
|
2160
|
+
".dsh-model-allowance-icon-button svg{display:block}",
|
|
2161
|
+
// The platform status row: one dot whose colour is the state, the
|
|
2162
|
+
// localized label, and a link to the source page when the vendor
|
|
2163
|
+
// publishes one. It sits at the left edge of the footer, so the margin
|
|
2164
|
+
// below pushes the reading time and the buttons to the right edge.
|
|
2165
|
+
".dsh-model-allowance-status-wrap{display:inline-flex;align-items:center;gap:5px;",
|
|
2166
|
+
"margin-right:auto;min-width:0;font-size:11px}",
|
|
2167
|
+
".dsh-model-allowance-status{display:inline-flex;align-items:center;gap:5px;",
|
|
2168
|
+
"color:var(--dsw-alias-label-primary);text-decoration:none}",
|
|
2169
|
+
"a.dsh-model-allowance-status:hover{text-decoration:underline}",
|
|
2170
|
+
".dsh-model-allowance-status-label{flex:none}",
|
|
2171
|
+
// The degraded reason hides behind a warning mark: the footer keeps one
|
|
2172
|
+
// row, and the detail is one hover away. The mark wears the same hue an
|
|
2173
|
+
// exhausted allowance does, so the two warnings read alike.
|
|
2174
|
+
".dsh-model-allowance-status-help{position:relative;display:inline-flex;",
|
|
2175
|
+
"align-items:center;justify-content:center;box-sizing:border-box;width:14px;height:14px;",
|
|
2176
|
+
"flex:none;border:1px solid var(--dsw-alias-state-error-primary);border-radius:50%;",
|
|
2177
|
+
"color:var(--dsw-alias-state-error-primary);font-size:9px;font-weight:700;line-height:1;",
|
|
2178
|
+
"cursor:help}",
|
|
2179
|
+
".dsh-model-allowance-status-help:hover,",
|
|
2180
|
+
".dsh-model-allowance-status-help:focus-visible{background:var(--dsw-alias-state-error-primary);",
|
|
2181
|
+
"color:var(--dsw-alias-label-primary-foreground);outline:none}",
|
|
2182
|
+
".dsh-model-allowance-status-tip{display:none;position:absolute;left:0;",
|
|
2183
|
+
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
2184
|
+
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
2185
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
2186
|
+
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
2187
|
+
// The hint sits on the harness's own tooltip surface, so it takes the
|
|
2188
|
+
// text colour that surface is read with: white on the dark tooltip.
|
|
2189
|
+
"color:var(--dsw-static-neutral-bluish-00);",
|
|
2190
|
+
"white-space:normal;text-align:left}",
|
|
2191
|
+
".dsh-model-allowance-status-help:hover .dsh-model-allowance-status-tip,",
|
|
2192
|
+
".dsh-model-allowance-status-help:focus-visible .dsh-model-allowance-status-tip{display:block}",
|
|
2193
|
+
".dsh-model-allowance-status-dot{width:6px;height:6px;border-radius:50%;flex:none;",
|
|
2194
|
+
"background:var(--dsw-alias-state-success-primary)}",
|
|
2195
|
+
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot,',
|
|
2196
|
+
'.dsh-model-allowance-status[data-state="unsupported"] .dsh-model-allowance-status-dot,',
|
|
2197
|
+
'.dsh-model-allowance-status[data-state="unknown"] .dsh-model-allowance-status-dot{',
|
|
2198
|
+
"background:var(--dsw-alias-state-idle-primary)}",
|
|
2199
|
+
'.dsh-model-allowance-status[data-state="loading"] .dsh-model-allowance-status-dot{opacity:.5}',
|
|
2200
|
+
'.dsh-model-allowance-status[data-state="degraded"] .dsh-model-allowance-status-dot,',
|
|
2201
|
+
'.dsh-model-allowance-status[data-state="maintenance"] .dsh-model-allowance-status-dot{',
|
|
2202
|
+
"background:var(--dsw-alias-state-warn-primary)}",
|
|
2203
|
+
'.dsh-model-allowance-status[data-state="partial-outage"] .dsh-model-allowance-status-dot,',
|
|
2204
|
+
'.dsh-model-allowance-status[data-state="major-outage"] .dsh-model-allowance-status-dot{',
|
|
2205
|
+
"background:var(--dsw-alias-state-error-primary)}",
|
|
2206
|
+
".dsh-model-allowance-status-arrow{font-size:10px;flex:none;",
|
|
2207
|
+
"color:var(--dsw-alias-label-tertiary)}",
|
|
2208
|
+
// The time-of-day pricing block: the phase the clock is in, how far
|
|
2209
|
+
// through that stretch of time it is, and the countdown. The rule itself
|
|
2210
|
+
// hides behind the help mark, so the card stays readable.
|
|
2211
|
+
".dsh-model-allowance-schedule{margin-top:10px;padding-top:10px;",
|
|
2212
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
2213
|
+
".dsh-model-allowance-schedule-head{display:flex;justify-content:space-between;",
|
|
2214
|
+
"align-items:center;gap:12px}",
|
|
2215
|
+
".dsh-model-allowance-schedule-title{font-weight:500;color:var(--dsw-alias-label-primary)}",
|
|
2216
|
+
".dsh-model-allowance-schedule-help{position:relative;display:inline-flex;",
|
|
2217
|
+
"align-items:center;justify-content:center;box-sizing:border-box;width:16px;height:16px;",
|
|
2218
|
+
"flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:50%;",
|
|
2219
|
+
"color:var(--dsw-alias-label-tertiary);font-size:10px;font-weight:600;line-height:1;",
|
|
2220
|
+
"cursor:help}",
|
|
2221
|
+
".dsh-model-allowance-schedule-help:hover,",
|
|
2222
|
+
".dsh-model-allowance-schedule-help:focus-visible{color:var(--dsw-alias-label-primary);",
|
|
2223
|
+
"border-color:var(--dsw-alias-label-secondary);outline:none}",
|
|
2224
|
+
// Opens upwards: the block sits just above the footer, so a tooltip
|
|
2225
|
+
// hanging below it would leave the panel.
|
|
2226
|
+
".dsh-model-allowance-schedule-tip{display:none;position:absolute;right:0;",
|
|
2227
|
+
"bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:240px;padding:6px 8px;",
|
|
2228
|
+
"border:0;border-radius:var(--dsw-radius-sm);",
|
|
2229
|
+
"background:var(--dsw-alias-tooltip-bg);box-shadow:var(--dsw-elevation-prominent);",
|
|
2230
|
+
"font-size:11px;font-weight:400;line-height:1.5;",
|
|
2231
|
+
"color:var(--dsw-static-neutral-bluish-00);",
|
|
2232
|
+
"white-space:normal;text-align:left}",
|
|
2233
|
+
".dsh-model-allowance-schedule-help:hover .dsh-model-allowance-schedule-tip,",
|
|
2234
|
+
".dsh-model-allowance-schedule-help:focus-visible .dsh-model-allowance-schedule-tip{",
|
|
2235
|
+
"display:block}",
|
|
2236
|
+
".dsh-model-allowance-schedule-tip-line{display:block}",
|
|
2237
|
+
// One 24-hour strip for the vendor's day: its peak windows tinted red
|
|
2238
|
+
// and the off-peak day tinted green, both at low saturation so the
|
|
2239
|
+
// strip reads at a glance without glaring, and a cursor where the
|
|
2240
|
+
// clock stands.
|
|
2241
|
+
".dsh-model-allowance-schedule-timeline{position:relative;margin-top:8px;height:8px;",
|
|
2242
|
+
"border-radius:4px;overflow:hidden;",
|
|
2243
|
+
"background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 12%,",
|
|
2244
|
+
"var(--dsw-alias-interactive-bg-hover));}",
|
|
2245
|
+
".dsh-model-allowance-schedule-timeline-peak{position:absolute;top:0;bottom:0;",
|
|
2246
|
+
// The same hue the exhausted allowance uses, so "peak" and "spent" read
|
|
2247
|
+
// as one family of warnings rather than two unrelated colours.
|
|
2248
|
+
"background:var(--dsw-alias-state-error-primary);opacity:.4}",
|
|
2249
|
+
".dsh-model-allowance-schedule-timeline-now{position:absolute;top:0;bottom:0;width:2px;",
|
|
2250
|
+
"margin-left:-1px;border-radius:1px;background:var(--dsw-alias-label-primary);",
|
|
2251
|
+
"box-shadow:0 0 0 1px var(--dsw-alias-bg-layer-1)}",
|
|
2252
|
+
".dsh-model-allowance-schedule-ticks{display:flex;justify-content:space-between;",
|
|
2253
|
+
"margin-top:2px;font-size:9px;line-height:1;color:var(--dsw-alias-label-secondary);",
|
|
2254
|
+
"font-variant-numeric:tabular-nums}",
|
|
2255
|
+
".dsh-model-allowance-schedule-countdown{margin-top:4px;text-align:right;font-size:11px;",
|
|
2256
|
+
"color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
|
|
2257
|
+
// A badge that fades or grows while a user asks for less motion is noise.
|
|
2258
|
+
"@media (prefers-reduced-motion:reduce){.dsh-model-allowance-delta{animation:none}",
|
|
2259
|
+
".dsh-model-allowance-bar-fill{transition:none}}"
|
|
2260
|
+
];
|
|
2261
|
+
var STYLES_JOINED = STYLES.join("");
|
|
2262
|
+
|
|
2263
|
+
// src/client/badge.js
|
|
2264
|
+
function statusDisplayState(status) {
|
|
2265
|
+
if (status === null) return "loading";
|
|
2266
|
+
if (status.state === "unknown" && !status.url && !status.error) return "unsupported";
|
|
2267
|
+
return status.state;
|
|
2268
|
+
}
|
|
2269
|
+
function BalanceBadge(props) {
|
|
2270
|
+
const { useProjection, ctx, t } = props;
|
|
2271
|
+
const selection = useProjection("modelSelection");
|
|
2272
|
+
const selected = selection?.next?.provider ?? selection?.lastUsed?.provider ?? null;
|
|
2273
|
+
const selectedModel = selection?.next?.model ?? selection?.lastUsed?.model ?? void 0;
|
|
2274
|
+
const selectedEffort = selection?.next?.reasoningEffort ?? selection?.lastUsed?.reasoningEffort ?? void 0;
|
|
2275
|
+
const sessionId = props.sessionId;
|
|
2276
|
+
const [rawView, setView] = React6.useState(null);
|
|
2277
|
+
const [loading, setLoading] = React6.useState(false);
|
|
2278
|
+
const [open, setOpen] = React6.useState(false);
|
|
2279
|
+
const [refreshing, setRefreshing] = React6.useState(false);
|
|
2280
|
+
const rootRef = React6.useRef(null);
|
|
2281
|
+
const [now, setNow] = React6.useState(() => Date.now());
|
|
2282
|
+
const [picked, setPicked] = React6.useState(null);
|
|
2283
|
+
const [menuOpen, setMenuOpen] = React6.useState(false);
|
|
2284
|
+
const [providerStatus, setProviderStatus] = React6.useState(null);
|
|
2285
|
+
const [schedule, setSchedule] = React6.useState(null);
|
|
2286
|
+
const lastModelProvider = React6.useRef(null);
|
|
2287
|
+
React6.useEffect(() => {
|
|
2288
|
+
if (open) return;
|
|
2289
|
+
setPicked(null);
|
|
2290
|
+
setMenuOpen(false);
|
|
2291
|
+
}, [open]);
|
|
2292
|
+
const [stripWidth, setStripWidth] = React6.useState(0);
|
|
2293
|
+
const stripRef = React6.useRef(null);
|
|
2294
|
+
const { available, defaultProvider, entryOf, nameOf } = useProviderDirectory(selected);
|
|
2295
|
+
const provider = selected ?? defaultProvider;
|
|
2296
|
+
const activeProvider = picked ?? provider;
|
|
2297
|
+
const inUse = activeProvider === provider || entryOf(provider)?.route === activeProvider;
|
|
2298
|
+
const activeModel = inUse ? selectedModel : void 0;
|
|
2299
|
+
const switchLabel = t(inUse ? "detail.switchModelHere" : "detail.switchModelThere", {
|
|
2300
|
+
name: nameOf(activeProvider)
|
|
2301
|
+
});
|
|
2302
|
+
const view = rawView?.provider === activeProvider ? rawView : null;
|
|
1401
2303
|
const showingDifference = consumptionFreshAt(view?.consumption, now);
|
|
1402
|
-
|
|
2304
|
+
React6.useEffect(() => {
|
|
1403
2305
|
if (!open && !showingDifference) return;
|
|
1404
2306
|
setNow(Date.now());
|
|
1405
2307
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
1406
2308
|
return () => clearInterval(timer);
|
|
1407
2309
|
}, [open, showingDifference]);
|
|
1408
|
-
|
|
1409
|
-
if (!open) return;
|
|
1410
|
-
let cancelled = false;
|
|
1411
|
-
(async () => {
|
|
1412
|
-
try {
|
|
1413
|
-
const api = await getBalanceApi();
|
|
1414
|
-
if (!api || typeof api.list !== "function") return;
|
|
1415
|
-
const result = await api.list();
|
|
1416
|
-
if (cancelled || !result.ok) return;
|
|
1417
|
-
setDirectory(result.value);
|
|
1418
|
-
} catch (error) {
|
|
1419
|
-
console.error("[model-allowance] listing providers failed", { error });
|
|
1420
|
-
}
|
|
1421
|
-
})();
|
|
1422
|
-
return () => {
|
|
1423
|
-
cancelled = true;
|
|
1424
|
-
};
|
|
1425
|
-
}, [open]);
|
|
1426
|
-
React.useEffect(() => {
|
|
1427
|
-
if (!activeProvider) {
|
|
1428
|
-
setView(null);
|
|
1429
|
-
setLoading(false);
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
let cancelled = false;
|
|
1433
|
-
let handle;
|
|
1434
|
-
setLoading(true);
|
|
1435
|
-
const readOnce = async (api, model) => {
|
|
1436
|
-
try {
|
|
1437
|
-
let result = await api.balance(activeProvider, model);
|
|
1438
|
-
if (!result.ok && model !== void 0) {
|
|
1439
|
-
result = await api.balance(activeProvider, void 0);
|
|
1440
|
-
}
|
|
1441
|
-
if (cancelled) return;
|
|
1442
|
-
if (!result.ok) {
|
|
1443
|
-
const detail = typeof result.error?.message === "string" ? result.error.message : typeof result.error === "string" ? result.error : "balance reading failed";
|
|
1444
|
-
throw new Error(detail);
|
|
1445
|
-
}
|
|
1446
|
-
setView(result.value);
|
|
1447
|
-
} catch (error) {
|
|
1448
|
-
console.error("[model-allowance] reading failed", {
|
|
1449
|
-
provider: activeProvider,
|
|
1450
|
-
model,
|
|
1451
|
-
error
|
|
1452
|
-
});
|
|
1453
|
-
if (!cancelled) {
|
|
1454
|
-
setView({
|
|
1455
|
-
provider: activeProvider,
|
|
1456
|
-
status: "failed",
|
|
1457
|
-
kind: "quota",
|
|
1458
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
} finally {
|
|
1462
|
-
if (!cancelled) setLoading(false);
|
|
1463
|
-
}
|
|
1464
|
-
};
|
|
1465
|
-
(async () => {
|
|
1466
|
-
const api = await getBalanceApi();
|
|
1467
|
-
if (cancelled) return;
|
|
1468
|
-
if (!api) {
|
|
1469
|
-
setView({
|
|
1470
|
-
provider: activeProvider,
|
|
1471
|
-
status: "failed",
|
|
1472
|
-
kind: "quota",
|
|
1473
|
-
error: "balance namespace unavailable"
|
|
1474
|
-
});
|
|
1475
|
-
setLoading(false);
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
const readModel = await supportsModel(api) ? activeModel : void 0;
|
|
1479
|
-
if (cancelled) return;
|
|
1480
|
-
const remote = ctx.remote;
|
|
1481
|
-
if (typeof remote?.$stream === "function" && typeof api.watch === "function") {
|
|
1482
|
-
try {
|
|
1483
|
-
handle = remote.$stream({
|
|
1484
|
-
name: "balance",
|
|
1485
|
-
open: (signal) => api.watch(activeProvider, readModel, signal),
|
|
1486
|
-
ended: () => new Error("balance stream ended")
|
|
1487
|
-
});
|
|
1488
|
-
} catch (error) {
|
|
1489
|
-
console.error("[model-allowance] opening the reading stream failed", { error });
|
|
1490
|
-
handle = void 0;
|
|
1491
|
-
}
|
|
1492
|
-
if (handle) {
|
|
1493
|
-
let received = false;
|
|
1494
|
-
try {
|
|
1495
|
-
for await (const item of handle) {
|
|
1496
|
-
if (cancelled) return;
|
|
1497
|
-
const frame = item?.value;
|
|
1498
|
-
if (frame === void 0) continue;
|
|
1499
|
-
received = true;
|
|
1500
|
-
setView(frame);
|
|
1501
|
-
setLoading(false);
|
|
1502
|
-
item?.accept?.();
|
|
1503
|
-
}
|
|
1504
|
-
} catch (error) {
|
|
1505
|
-
if (!cancelled) {
|
|
1506
|
-
console.error("[model-allowance] reading stream failed", {
|
|
1507
|
-
provider: activeProvider,
|
|
1508
|
-
error
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
} finally {
|
|
1512
|
-
if (!cancelled && !received) await readOnce(api, readModel);
|
|
1513
|
-
}
|
|
1514
|
-
return;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
await readOnce(api, readModel);
|
|
1518
|
-
})();
|
|
1519
|
-
return () => {
|
|
1520
|
-
cancelled = true;
|
|
1521
|
-
handle?.dispose?.();
|
|
1522
|
-
};
|
|
1523
|
-
}, [activeProvider, activeModel, ctx]);
|
|
1524
|
-
React.useEffect(() => {
|
|
2310
|
+
React6.useEffect(() => {
|
|
1525
2311
|
if (!activeProvider) return void 0;
|
|
1526
2312
|
let cancelled = false;
|
|
1527
2313
|
const readStatus = async () => {
|
|
@@ -1535,7 +2321,7 @@ function BalanceBadge(props) {
|
|
|
1535
2321
|
clearInterval(timer);
|
|
1536
2322
|
};
|
|
1537
2323
|
}, [activeProvider]);
|
|
1538
|
-
|
|
2324
|
+
React6.useEffect(() => {
|
|
1539
2325
|
if (!activeProvider) return void 0;
|
|
1540
2326
|
let cancelled = false;
|
|
1541
2327
|
(async () => {
|
|
@@ -1553,7 +2339,22 @@ function BalanceBadge(props) {
|
|
|
1553
2339
|
cancelled = true;
|
|
1554
2340
|
};
|
|
1555
2341
|
}, [activeProvider]);
|
|
1556
|
-
|
|
2342
|
+
useBalanceStream({ activeProvider, activeModel, ctx, setView, setLoading });
|
|
2343
|
+
const catalog = useModelCatalog({ ctx, t, sessionId, activeProvider, entryOf, selection });
|
|
2344
|
+
useDismiss({
|
|
2345
|
+
open,
|
|
2346
|
+
rootRef,
|
|
2347
|
+
modelMenuOpen: catalog.modelMenuOpen,
|
|
2348
|
+
setOpen,
|
|
2349
|
+
setModelMenuOpen: catalog.setModelMenuOpen
|
|
2350
|
+
});
|
|
2351
|
+
const selectionKey = `${provider ?? ""}\0${selectedModel ?? ""}`;
|
|
2352
|
+
React6.useEffect(() => {
|
|
2353
|
+
if (lastModelProvider.current === selectionKey) return;
|
|
2354
|
+
lastModelProvider.current = selectionKey;
|
|
2355
|
+
setPicked(null);
|
|
2356
|
+
});
|
|
2357
|
+
const refresh = React6.useCallback(async () => {
|
|
1557
2358
|
setRefreshing(true);
|
|
1558
2359
|
try {
|
|
1559
2360
|
const api = await getBalanceApi();
|
|
@@ -1571,120 +2372,15 @@ function BalanceBadge(props) {
|
|
|
1571
2372
|
provider: activeProvider,
|
|
1572
2373
|
model: activeModel,
|
|
1573
2374
|
error
|
|
1574
|
-
});
|
|
1575
|
-
} finally {
|
|
1576
|
-
setRefreshing(false);
|
|
1577
|
-
}
|
|
1578
|
-
}, [activeProvider, activeModel]);
|
|
1579
|
-
const
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
const models = group?.models ?? [];
|
|
1584
|
-
setCatalogProvider(group?.provider ?? null);
|
|
1585
|
-
setModelListRoute(activeProvider);
|
|
1586
|
-
setModelList(models);
|
|
1587
|
-
setModelListState(models.length > 0 ? "ready" : "empty");
|
|
1588
|
-
},
|
|
1589
|
-
[activeProvider, entryOf]
|
|
1590
|
-
);
|
|
1591
|
-
React.useEffect(() => {
|
|
1592
|
-
if (!modelMenuOpen) return void 0;
|
|
1593
|
-
let cancelled = false;
|
|
1594
|
-
(async () => {
|
|
1595
|
-
const face = lookupSessionFace(ctx);
|
|
1596
|
-
if (face === void 0 || typeof face.modelCatalog !== "function") {
|
|
1597
|
-
setModelListState("error");
|
|
1598
|
-
setModelError(t("model.unavailable"));
|
|
1599
|
-
return;
|
|
1600
|
-
}
|
|
1601
|
-
const cached = catalogRef.current;
|
|
1602
|
-
if (cached.value !== null && Date.now() - cached.at < CATALOG_TTL_MS) {
|
|
1603
|
-
if (!cancelled) showModels(cached.value);
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
setModelListState("loading");
|
|
1607
|
-
try {
|
|
1608
|
-
const result = await face.modelCatalog();
|
|
1609
|
-
if (cancelled) return;
|
|
1610
|
-
if (!result?.ok) {
|
|
1611
|
-
setModelListState("error");
|
|
1612
|
-
setModelError(
|
|
1613
|
-
t("model.loadFailed", { error: result?.error?.message ?? result?.error?.code ?? "" })
|
|
1614
|
-
);
|
|
1615
|
-
return;
|
|
1616
|
-
}
|
|
1617
|
-
catalogRef.current = { value: result.value, at: Date.now() };
|
|
1618
|
-
showModels(result.value);
|
|
1619
|
-
} catch (error) {
|
|
1620
|
-
if (cancelled) return;
|
|
1621
|
-
setModelListState("error");
|
|
1622
|
-
setModelError(t("model.loadFailed", { error: describe(error) }));
|
|
1623
|
-
}
|
|
1624
|
-
})();
|
|
1625
|
-
return () => {
|
|
1626
|
-
cancelled = true;
|
|
1627
|
-
};
|
|
1628
|
-
}, [modelMenuOpen, ctx, t, showModels]);
|
|
1629
|
-
React.useEffect(() => {
|
|
1630
|
-
if (!modelMenuOpen) return void 0;
|
|
1631
|
-
const onPointerDown = (event) => {
|
|
1632
|
-
const wrap = modelWrapRef.current;
|
|
1633
|
-
if (wrap && event.target instanceof Node && wrap.contains(event.target)) return;
|
|
1634
|
-
setModelMenuOpen(false);
|
|
1635
|
-
};
|
|
1636
|
-
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1637
|
-
return () => {
|
|
1638
|
-
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1639
|
-
};
|
|
1640
|
-
}, [modelMenuOpen]);
|
|
1641
|
-
const switchToModel = React.useCallback(
|
|
1642
|
-
async (model, effort) => {
|
|
1643
|
-
const face = lookupSessionFace(ctx);
|
|
1644
|
-
if (face === void 0 || typeof face.selectModel !== "function") {
|
|
1645
|
-
setModelError(t("model.unavailable"));
|
|
1646
|
-
return;
|
|
1647
|
-
}
|
|
1648
|
-
if (typeof sessionId !== "string" || sessionId === "") {
|
|
1649
|
-
setModelError(t("model.unavailable"));
|
|
1650
|
-
return;
|
|
1651
|
-
}
|
|
1652
|
-
setSwitchingModel(model.id);
|
|
1653
|
-
try {
|
|
1654
|
-
const result = await face.selectModel({
|
|
1655
|
-
sessionId,
|
|
1656
|
-
provider: catalogProvider ?? activeProvider,
|
|
1657
|
-
model: model.id,
|
|
1658
|
-
...typeof effort === "string" && effort !== "" ? { reasoningEffort: effort } : {}
|
|
1659
|
-
});
|
|
1660
|
-
if (!result?.ok) {
|
|
1661
|
-
setModelError(
|
|
1662
|
-
t("model.failed", { error: result?.error?.message ?? result?.error?.code ?? "" })
|
|
1663
|
-
);
|
|
1664
|
-
return;
|
|
1665
|
-
}
|
|
1666
|
-
setModelError(null);
|
|
1667
|
-
setModelMenuOpen(false);
|
|
1668
|
-
} catch (error) {
|
|
1669
|
-
console.error("[model-allowance] switching the model failed", { error });
|
|
1670
|
-
setModelError(t("model.failed", { error: describe(error) }));
|
|
1671
|
-
} finally {
|
|
1672
|
-
setSwitchingModel(null);
|
|
1673
|
-
}
|
|
1674
|
-
},
|
|
1675
|
-
[ctx, sessionId, activeProvider, catalogProvider, t]
|
|
1676
|
-
);
|
|
1677
|
-
const showEffortFlyout = React.useCallback((model, top) => {
|
|
1678
|
-
clearTimeout(hoverModelTimer.current);
|
|
1679
|
-
setHoverModel({ model, top });
|
|
1680
|
-
}, []);
|
|
1681
|
-
const scheduleEffortFlyoutClose = React.useCallback((id) => {
|
|
1682
|
-
clearTimeout(hoverModelTimer.current);
|
|
1683
|
-
hoverModelTimer.current = setTimeout(() => {
|
|
1684
|
-
setHoverModel((current) => current?.model?.id === id ? null : current);
|
|
1685
|
-
}, 150);
|
|
1686
|
-
}, []);
|
|
1687
|
-
const label = React.useMemo(() => {
|
|
2375
|
+
});
|
|
2376
|
+
} finally {
|
|
2377
|
+
setRefreshing(false);
|
|
2378
|
+
}
|
|
2379
|
+
}, [activeProvider, activeModel]);
|
|
2380
|
+
const markFor = (route) => markOf(entryOf(route), route);
|
|
2381
|
+
const sessionFace = lookupSessionFace(ctx);
|
|
2382
|
+
const canSwitch = typeof sessionId === "string" && sessionId !== "" && sessionFace !== void 0 && typeof sessionFace.selectModel === "function";
|
|
2383
|
+
const label = React6.useMemo(() => {
|
|
1688
2384
|
if (!provider) return "";
|
|
1689
2385
|
if (!view) return t("badge.loading");
|
|
1690
2386
|
if (view.status === "ready") {
|
|
@@ -1722,57 +2418,7 @@ function BalanceBadge(props) {
|
|
|
1722
2418
|
if (!provider) return null;
|
|
1723
2419
|
const currentStatus = providerStatus?.provider === activeProvider ? providerStatus : null;
|
|
1724
2420
|
const serviceState = statusDisplayState(currentStatus);
|
|
1725
|
-
|
|
1726
|
-
const MARK_GAP = 4;
|
|
1727
|
-
const MENU_SIZE = 26;
|
|
1728
|
-
const perMark = MARK_SIZE + MARK_GAP;
|
|
1729
|
-
let visibleCount = available.length;
|
|
1730
|
-
if (stripWidth > 0 && available.length * perMark - MARK_GAP > stripWidth) {
|
|
1731
|
-
visibleCount = Math.max(1, Math.floor((stripWidth - MENU_SIZE - MARK_GAP) / perMark));
|
|
1732
|
-
visibleCount = Math.min(visibleCount, available.length - 1);
|
|
1733
|
-
}
|
|
1734
|
-
let shown = available.slice(0, visibleCount);
|
|
1735
|
-
let overflow = available.slice(visibleCount);
|
|
1736
|
-
const activeIndex = overflow.findIndex((entry) => entryCovers(entry, activeProvider));
|
|
1737
|
-
if (activeIndex >= 0 && shown.length > 0) {
|
|
1738
|
-
const displaced = shown[shown.length - 1];
|
|
1739
|
-
shown = [...shown.slice(0, -1), overflow[activeIndex]];
|
|
1740
|
-
overflow = [...overflow.slice(0, activeIndex), displaced, ...overflow.slice(activeIndex + 1)];
|
|
1741
|
-
}
|
|
1742
|
-
const markButton = (entry) => {
|
|
1743
|
-
const mark = markFor(entry.route);
|
|
1744
|
-
const name = nameOf(entry.route);
|
|
1745
|
-
const active = entryCovers(entry, activeProvider);
|
|
1746
|
-
return (0, import_react3.createElement)(
|
|
1747
|
-
"button",
|
|
1748
|
-
{
|
|
1749
|
-
type: "button",
|
|
1750
|
-
key: entry.route,
|
|
1751
|
-
role: "tab",
|
|
1752
|
-
className: "dsh-model-allowance-tab",
|
|
1753
|
-
"data-active": active ? "true" : "false",
|
|
1754
|
-
"aria-selected": active ? "true" : "false",
|
|
1755
|
-
"aria-label": name,
|
|
1756
|
-
title: name,
|
|
1757
|
-
style: { "--provider-mark": mark.color },
|
|
1758
|
-
onClick: () => {
|
|
1759
|
-
setPicked(entry.route);
|
|
1760
|
-
setMenuOpen(false);
|
|
1761
|
-
}
|
|
1762
|
-
},
|
|
1763
|
-
providerIcon(entry.route, 14, mark)
|
|
1764
|
-
);
|
|
1765
|
-
};
|
|
1766
|
-
const onTabKeyDown = (event) => {
|
|
1767
|
-
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
1768
|
-
const tabs = [...event.currentTarget.querySelectorAll('[role="tab"]')];
|
|
1769
|
-
if (tabs.length === 0) return;
|
|
1770
|
-
const index = tabs.indexOf(document.activeElement);
|
|
1771
|
-
const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + tabs.length) % tabs.length;
|
|
1772
|
-
event.preventDefault();
|
|
1773
|
-
tabs[next]?.focus();
|
|
1774
|
-
};
|
|
1775
|
-
return (0, import_react3.createElement)(
|
|
2421
|
+
return (0, import_react7.createElement)(
|
|
1776
2422
|
"div",
|
|
1777
2423
|
{
|
|
1778
2424
|
ref: rootRef,
|
|
@@ -1782,8 +2428,8 @@ function BalanceBadge(props) {
|
|
|
1782
2428
|
},
|
|
1783
2429
|
// Component-local styles: React removes them with the component, and
|
|
1784
2430
|
// every colour comes from a theme token so light and dark both follow.
|
|
1785
|
-
(0,
|
|
1786
|
-
(0,
|
|
2431
|
+
(0, import_react7.createElement)("style", { key: "styles" }, STYLES_JOINED),
|
|
2432
|
+
(0, import_react7.createElement)(
|
|
1787
2433
|
"button",
|
|
1788
2434
|
{
|
|
1789
2435
|
type: "button",
|
|
@@ -1793,12 +2439,12 @@ function BalanceBadge(props) {
|
|
|
1793
2439
|
"aria-controls": open ? "dsh-model-allowance-panel" : void 0,
|
|
1794
2440
|
onClick: () => setOpen((value) => !value)
|
|
1795
2441
|
},
|
|
1796
|
-
(0,
|
|
1797
|
-
(0,
|
|
2442
|
+
(0, import_react7.createElement)("span", { className: "dsh-model-allowance-dot", "aria-hidden": true }),
|
|
2443
|
+
(0, import_react7.createElement)("span", { className: "dsh-model-allowance-label" }, label),
|
|
1798
2444
|
// How far the number moved since the last reading, for a few seconds
|
|
1799
2445
|
// after it lands. The arrow follows the number shown beside it: down
|
|
1800
2446
|
// means the balance fell.
|
|
1801
|
-
showingDifference ? (0,
|
|
2447
|
+
showingDifference ? (0, import_react7.createElement)(
|
|
1802
2448
|
"span",
|
|
1803
2449
|
{
|
|
1804
2450
|
className: "dsh-model-allowance-delta",
|
|
@@ -1808,456 +2454,31 @@ function BalanceBadge(props) {
|
|
|
1808
2454
|
`${view.consumption.delta < 0 ? "\u2193" : "\u2191"}${formatDelta(view.consumption)}`
|
|
1809
2455
|
) : null
|
|
1810
2456
|
),
|
|
1811
|
-
open ? (0,
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
...shown.map(markButton),
|
|
1837
|
-
overflow.length > 0 ? (0, import_react3.createElement)(
|
|
1838
|
-
"button",
|
|
1839
|
-
{
|
|
1840
|
-
type: "button",
|
|
1841
|
-
className: "dsh-model-allowance-more",
|
|
1842
|
-
"aria-haspopup": "menu",
|
|
1843
|
-
"aria-expanded": menuOpen ? "true" : "false",
|
|
1844
|
-
"aria-label": t("detail.moreProviders"),
|
|
1845
|
-
title: t("detail.moreProviders"),
|
|
1846
|
-
onClick: () => setMenuOpen((value) => !value)
|
|
1847
|
-
},
|
|
1848
|
-
"\u22EF"
|
|
1849
|
-
) : null
|
|
1850
|
-
),
|
|
1851
|
-
menuOpen && overflow.length > 0 ? (0, import_react3.createElement)(
|
|
1852
|
-
"div",
|
|
1853
|
-
{ className: "dsh-model-allowance-menu", role: "menu" },
|
|
1854
|
-
...overflow.map(
|
|
1855
|
-
(entry) => (0, import_react3.createElement)(
|
|
1856
|
-
"button",
|
|
1857
|
-
{
|
|
1858
|
-
type: "button",
|
|
1859
|
-
key: entry.route,
|
|
1860
|
-
role: "menuitem",
|
|
1861
|
-
className: "dsh-model-allowance-menu-item",
|
|
1862
|
-
onClick: () => {
|
|
1863
|
-
setPicked(entry.route);
|
|
1864
|
-
setMenuOpen(false);
|
|
1865
|
-
}
|
|
1866
|
-
},
|
|
1867
|
-
(0, import_react3.createElement)(
|
|
1868
|
-
"span",
|
|
1869
|
-
{
|
|
1870
|
-
className: "dsh-model-allowance-menu-mark",
|
|
1871
|
-
style: { "--provider-mark": markFor(entry.route).color }
|
|
1872
|
-
},
|
|
1873
|
-
providerIcon(entry.route, 11, markFor(entry.route))
|
|
1874
|
-
),
|
|
1875
|
-
(0, import_react3.createElement)("span", null, nameOf(entry.route))
|
|
1876
|
-
)
|
|
1877
|
-
)
|
|
1878
|
-
) : null
|
|
1879
|
-
) : (0, import_react3.createElement)(
|
|
1880
|
-
"div",
|
|
1881
|
-
{ className: "dsh-model-allowance-row" },
|
|
1882
|
-
(0, import_react3.createElement)("span", null, t("detail.provider")),
|
|
1883
|
-
(0, import_react3.createElement)("span", null, nameOf(activeProvider))
|
|
1884
|
-
),
|
|
1885
|
-
view?.kind === "amount" && typeof view.amount === "number" ? (0, import_react3.createElement)(
|
|
1886
|
-
"div",
|
|
1887
|
-
{ className: "dsh-model-allowance-row" },
|
|
1888
|
-
(0, import_react3.createElement)("span", null, t("detail.amount")),
|
|
1889
|
-
(0, import_react3.createElement)("span", null, formatAmount(view.amount, view.currency))
|
|
1890
|
-
) : null,
|
|
1891
|
-
...Array.isArray(view?.windows) && view.windows.length > 0 ? view.windows.map((window, index) => {
|
|
1892
|
-
const consumed = windowUsedPercent(window);
|
|
1893
|
-
const percent = consumed === void 0 ? void 0 : Math.max(0, Math.round(consumed));
|
|
1894
|
-
const filled = consumed === void 0 ? 0 : Math.min(100, Math.max(0, consumed));
|
|
1895
|
-
const usage = windowUsage(window, t);
|
|
1896
|
-
return (0, import_react3.createElement)(
|
|
1897
|
-
"div",
|
|
1898
|
-
{
|
|
1899
|
-
className: "dsh-model-allowance-window",
|
|
1900
|
-
key: `w-${String(index)}`,
|
|
1901
|
-
// The first block needs no divider: the switcher above
|
|
1902
|
-
// it already ends in one, and a bare provider row does
|
|
1903
|
-
// not deserve a line either. Only the boundaries
|
|
1904
|
-
// *between* windows are drawn.
|
|
1905
|
-
"data-first": index === 0 ? "true" : void 0
|
|
1906
|
-
},
|
|
1907
|
-
(0, import_react3.createElement)(
|
|
1908
|
-
"div",
|
|
1909
|
-
{ className: "dsh-model-allowance-window-head" },
|
|
1910
|
-
(0, import_react3.createElement)(
|
|
1911
|
-
"span",
|
|
1912
|
-
{ className: "dsh-model-allowance-window-title" },
|
|
1913
|
-
windowTitle(window, t)
|
|
1914
|
-
),
|
|
1915
|
-
// Countable units sit beside the title; a plan that
|
|
1916
|
-
// reports only a percentage has none to show.
|
|
1917
|
-
usage === void 0 ? null : (0, import_react3.createElement)("span", { className: "dsh-model-allowance-usage" }, usage)
|
|
1918
|
-
),
|
|
1919
|
-
percent === void 0 ? null : (0, import_react3.createElement)(
|
|
1920
|
-
"div",
|
|
1921
|
-
{ className: "dsh-model-allowance-percent" },
|
|
1922
|
-
t("window.usedPercent", { percent })
|
|
1923
|
-
),
|
|
1924
|
-
percent === void 0 ? null : (0, import_react3.createElement)(
|
|
1925
|
-
"div",
|
|
1926
|
-
{
|
|
1927
|
-
className: "dsh-model-allowance-bar",
|
|
1928
|
-
role: "progressbar",
|
|
1929
|
-
"aria-valuenow": percent,
|
|
1930
|
-
"aria-valuemin": 0,
|
|
1931
|
-
"aria-valuemax": 100,
|
|
1932
|
-
"aria-valuetext": t("window.usedPercent", { percent })
|
|
1933
|
-
},
|
|
1934
|
-
(0, import_react3.createElement)("div", {
|
|
1935
|
-
className: "dsh-model-allowance-bar-fill",
|
|
1936
|
-
"data-tone": barTone(percent),
|
|
1937
|
-
style: { width: `${String(filled)}%` }
|
|
1938
|
-
})
|
|
1939
|
-
),
|
|
1940
|
-
// A window with zero usage has not started its rolling timer
|
|
1941
|
-
// yet, so the countdown would be misleading. Hide it until
|
|
1942
|
-
// consumption begins.
|
|
1943
|
-
typeof window.resetAt === "number" && (typeof window.remainingPercent !== "number" || window.remainingPercent < 100) ? (0, import_react3.createElement)(
|
|
1944
|
-
"div",
|
|
1945
|
-
{ className: "dsh-model-allowance-foot" },
|
|
1946
|
-
(0, import_react3.createElement)(
|
|
1947
|
-
"span",
|
|
1948
|
-
null,
|
|
1949
|
-
t("window.resetIn", {
|
|
1950
|
-
duration: formatCountdown(window.resetAt - now)
|
|
1951
|
-
})
|
|
1952
|
-
),
|
|
1953
|
-
(0, import_react3.createElement)("span", null, formatResetAt(window.resetAt))
|
|
1954
|
-
) : null
|
|
1955
|
-
);
|
|
1956
|
-
}) : [],
|
|
1957
|
-
// A single scalar reading has no windows to break down.
|
|
1958
|
-
!Array.isArray(view?.windows) && typeof view?.remainingMs === "number" ? (0, import_react3.createElement)(
|
|
1959
|
-
"div",
|
|
1960
|
-
{ className: "dsh-model-allowance-row" },
|
|
1961
|
-
(0, import_react3.createElement)("span", null, t("detail.remaining")),
|
|
1962
|
-
(0, import_react3.createElement)("span", null, formatDuration(view.remainingMs, t))
|
|
1963
|
-
) : null,
|
|
1964
|
-
!Array.isArray(view?.windows) && typeof view?.remaining === "number" ? (0, import_react3.createElement)(
|
|
1965
|
-
"div",
|
|
1966
|
-
{ className: "dsh-model-allowance-row" },
|
|
1967
|
-
(0, import_react3.createElement)("span", null, t("detail.remaining")),
|
|
1968
|
-
(0, import_react3.createElement)("span", null, String(view.remaining))
|
|
1969
|
-
) : null,
|
|
1970
|
-
!Array.isArray(view?.windows) && typeof view?.total === "number" ? (0, import_react3.createElement)(
|
|
1971
|
-
"div",
|
|
1972
|
-
{ className: "dsh-model-allowance-row" },
|
|
1973
|
-
(0, import_react3.createElement)("span", null, t("detail.total")),
|
|
1974
|
-
(0, import_react3.createElement)("span", null, String(view.total))
|
|
1975
|
-
) : null,
|
|
1976
|
-
view?.status === "failed" ? (0, import_react3.createElement)(
|
|
1977
|
-
"div",
|
|
1978
|
-
{ className: "dsh-model-allowance-error" },
|
|
1979
|
-
t("detail.error"),
|
|
1980
|
-
// The Host reports why a reading failed; showing it is what
|
|
1981
|
-
// turns "it does not work" into something actionable.
|
|
1982
|
-
view.error ? (0, import_react3.createElement)("div", { className: "dsh-model-allowance-reason" }, view.error) : null
|
|
1983
|
-
) : null,
|
|
1984
|
-
view?.status === "unsupported" ? (0, import_react3.createElement)(
|
|
1985
|
-
"div",
|
|
1986
|
-
{ className: "dsh-model-allowance-reason" },
|
|
1987
|
-
t("badge.unsupportedWithName", { name: nameOf(activeProvider) })
|
|
1988
|
-
) : null,
|
|
1989
|
-
view?.status === "unconfigured" ? (0, import_react3.createElement)("div", { className: "dsh-model-allowance-reason" }, t("badge.unconfigured")) : null,
|
|
1990
|
-
// A vendor that prices by the wall clock gets its phase and
|
|
1991
|
-
// countdown here, above the footer.
|
|
1992
|
-
schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
|
|
1993
|
-
(0, import_react3.createElement)(
|
|
1994
|
-
"div",
|
|
1995
|
-
{ className: "dsh-model-allowance-actions" },
|
|
1996
|
-
// The platform status sits at the left edge of the footer, on
|
|
1997
|
-
// the same line as the reading time: the card gains no extra
|
|
1998
|
-
// row, and the state and the source page stay together.
|
|
1999
|
-
(0, import_react3.createElement)(
|
|
2000
|
-
"span",
|
|
2001
|
-
{ className: "dsh-model-allowance-status-wrap" },
|
|
2002
|
-
(0, import_react3.createElement)(
|
|
2003
|
-
currentStatus?.url ? "a" : "span",
|
|
2004
|
-
{
|
|
2005
|
-
className: "dsh-model-allowance-status",
|
|
2006
|
-
"data-state": serviceState,
|
|
2007
|
-
...currentStatus?.url ? {
|
|
2008
|
-
href: currentStatus.url,
|
|
2009
|
-
target: "_blank",
|
|
2010
|
-
rel: "noreferrer noopener"
|
|
2011
|
-
} : {}
|
|
2012
|
-
},
|
|
2013
|
-
(0, import_react3.createElement)("span", {
|
|
2014
|
-
className: "dsh-model-allowance-status-dot",
|
|
2015
|
-
"aria-hidden": true
|
|
2016
|
-
}),
|
|
2017
|
-
(0, import_react3.createElement)(
|
|
2018
|
-
"span",
|
|
2019
|
-
{ className: "dsh-model-allowance-status-label" },
|
|
2020
|
-
statusLabel(serviceState, t)
|
|
2021
|
-
),
|
|
2022
|
-
...currentStatus?.url ? [
|
|
2023
|
-
(0, import_react3.createElement)(
|
|
2024
|
-
"span",
|
|
2025
|
-
{
|
|
2026
|
-
className: "dsh-model-allowance-status-arrow",
|
|
2027
|
-
"aria-hidden": true
|
|
2028
|
-
},
|
|
2029
|
-
"\u2197"
|
|
2030
|
-
)
|
|
2031
|
-
] : []
|
|
2032
|
-
),
|
|
2033
|
-
// The reason is a warning mark rather than another line:
|
|
2034
|
-
// the footer stays one row, and the detail is one hover
|
|
2035
|
-
// — or one keyboard focus — away.
|
|
2036
|
-
currentStatus?.summary ? (0, import_react3.createElement)(
|
|
2037
|
-
"span",
|
|
2038
|
-
{
|
|
2039
|
-
className: "dsh-model-allowance-status-help",
|
|
2040
|
-
tabIndex: 0,
|
|
2041
|
-
role: "note",
|
|
2042
|
-
"aria-label": currentStatus.summary
|
|
2043
|
-
},
|
|
2044
|
-
(0, import_react3.createElement)(
|
|
2045
|
-
"span",
|
|
2046
|
-
{
|
|
2047
|
-
"aria-hidden": true
|
|
2048
|
-
},
|
|
2049
|
-
"!"
|
|
2050
|
-
),
|
|
2051
|
-
(0, import_react3.createElement)(
|
|
2052
|
-
"span",
|
|
2053
|
-
{ className: "dsh-model-allowance-status-tip", role: "tooltip" },
|
|
2054
|
-
currentStatus.summary
|
|
2055
|
-
)
|
|
2056
|
-
) : null
|
|
2057
|
-
),
|
|
2058
|
-
view?.updatedAt ? (0, import_react3.createElement)(
|
|
2059
|
-
"span",
|
|
2060
|
-
{ className: "dsh-model-allowance-updated" },
|
|
2061
|
-
t("detail.updatedAt", { time: formatClock(view.updatedAt) })
|
|
2062
|
-
) : null,
|
|
2063
|
-
(0, import_react3.createElement)(
|
|
2064
|
-
"button",
|
|
2065
|
-
{
|
|
2066
|
-
type: "button",
|
|
2067
|
-
className: "dsh-model-allowance-icon-button",
|
|
2068
|
-
onClick: refresh,
|
|
2069
|
-
disabled: refreshing,
|
|
2070
|
-
title: refreshing ? t("detail.refreshing") : t("detail.refresh"),
|
|
2071
|
-
"aria-label": refreshing ? t("detail.refreshing") : t("detail.refresh")
|
|
2072
|
-
},
|
|
2073
|
-
refreshGlyph(16)
|
|
2074
|
-
),
|
|
2075
|
-
view?.consoleUrl ? (0, import_react3.createElement)(
|
|
2076
|
-
"a",
|
|
2077
|
-
{
|
|
2078
|
-
className: "dsh-model-allowance-icon-button",
|
|
2079
|
-
href: view.consoleUrl,
|
|
2080
|
-
target: "_blank",
|
|
2081
|
-
rel: "noreferrer noopener",
|
|
2082
|
-
title: t("detail.console"),
|
|
2083
|
-
"aria-label": t("detail.console")
|
|
2084
|
-
},
|
|
2085
|
-
consoleGlyph(16)
|
|
2086
|
-
) : null,
|
|
2087
|
-
// The switch to another model of this provider. It sits to the
|
|
2088
|
-
// right of the console link, which is the last thing the footer
|
|
2089
|
-
// offered before, so the two never trade places.
|
|
2090
|
-
canSwitch ? (0, import_react3.createElement)(
|
|
2091
|
-
"span",
|
|
2092
|
-
{ ref: modelWrapRef, className: "dsh-model-allowance-model-wrap" },
|
|
2093
|
-
(0, import_react3.createElement)(
|
|
2094
|
-
"button",
|
|
2095
|
-
{
|
|
2096
|
-
type: "button",
|
|
2097
|
-
className: "dsh-model-allowance-icon-button",
|
|
2098
|
-
"aria-haspopup": "menu",
|
|
2099
|
-
"aria-expanded": modelMenuOpen ? "true" : "false",
|
|
2100
|
-
// The vendor in use paints the glyph in its own
|
|
2101
|
-
// colour, so the button says which vendor the card is
|
|
2102
|
-
// on instead of the strip having to say it twice.
|
|
2103
|
-
"data-in-use": inUse ? "true" : "false",
|
|
2104
|
-
style: { "--provider-mark": markFor(activeProvider).color },
|
|
2105
|
-
title: switchLabel,
|
|
2106
|
-
"aria-label": switchLabel,
|
|
2107
|
-
onClick: () => {
|
|
2108
|
-
setModelError(null);
|
|
2109
|
-
clearTimeout(hoverModelTimer.current);
|
|
2110
|
-
setHoverModel(null);
|
|
2111
|
-
setModelMenuOpen((value) => !value);
|
|
2112
|
-
}
|
|
2113
|
-
},
|
|
2114
|
-
modelGlyph(16)
|
|
2115
|
-
),
|
|
2116
|
-
modelMenuOpen ? (0, import_react3.createElement)(
|
|
2117
|
-
"div",
|
|
2118
|
-
{
|
|
2119
|
-
className: "dsh-model-allowance-model-menu",
|
|
2120
|
-
role: "menu",
|
|
2121
|
-
"aria-label": t("model.title")
|
|
2122
|
-
},
|
|
2123
|
-
shownModelListState === "loading" ? (0, import_react3.createElement)(
|
|
2124
|
-
"div",
|
|
2125
|
-
{ className: "dsh-model-allowance-model-message" },
|
|
2126
|
-
t("model.loading")
|
|
2127
|
-
) : null,
|
|
2128
|
-
shownModelListState === "empty" ? (0, import_react3.createElement)(
|
|
2129
|
-
"div",
|
|
2130
|
-
{ className: "dsh-model-allowance-model-message" },
|
|
2131
|
-
t("model.empty")
|
|
2132
|
-
) : null,
|
|
2133
|
-
shownModelListState === "error" ? (0, import_react3.createElement)(
|
|
2134
|
-
"div",
|
|
2135
|
-
{
|
|
2136
|
-
className: "dsh-model-allowance-model-message",
|
|
2137
|
-
"data-tone": "error"
|
|
2138
|
-
},
|
|
2139
|
-
modelError ?? t("model.unavailable")
|
|
2140
|
-
) : null,
|
|
2141
|
-
...shownModelList.map((model) => {
|
|
2142
|
-
const isCurrent = model.id === currentModel;
|
|
2143
|
-
const efforts = effortChoices(model);
|
|
2144
|
-
const defaultEffortId = efforts?.find((effort) => effort.isDefault)?.id;
|
|
2145
|
-
return (0, import_react3.createElement)(
|
|
2146
|
-
"button",
|
|
2147
|
-
{
|
|
2148
|
-
type: "button",
|
|
2149
|
-
key: model.id,
|
|
2150
|
-
role: "menuitemradio",
|
|
2151
|
-
"aria-checked": isCurrent ? "true" : "false",
|
|
2152
|
-
"data-current": isCurrent ? "true" : "false",
|
|
2153
|
-
className: "dsh-model-allowance-model-item",
|
|
2154
|
-
disabled: switchingModel !== null,
|
|
2155
|
-
title: model.id,
|
|
2156
|
-
...efforts === null ? {} : { "aria-haspopup": "menu" },
|
|
2157
|
-
onClick: () => {
|
|
2158
|
-
void switchToModel(model, defaultEffortId);
|
|
2159
|
-
},
|
|
2160
|
-
...efforts === null ? {} : {
|
|
2161
|
-
onMouseEnter: (event) => {
|
|
2162
|
-
const wrap = modelWrapRef.current;
|
|
2163
|
-
if (!wrap) return;
|
|
2164
|
-
const top = event.currentTarget.getBoundingClientRect().top - wrap.getBoundingClientRect().top;
|
|
2165
|
-
showEffortFlyout(model, top);
|
|
2166
|
-
},
|
|
2167
|
-
onMouseLeave: () => {
|
|
2168
|
-
scheduleEffortFlyoutClose(model.id);
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
},
|
|
2172
|
-
(0, import_react3.createElement)(
|
|
2173
|
-
"span",
|
|
2174
|
-
{ className: "dsh-model-allowance-model-name" },
|
|
2175
|
-
model.name ?? model.id
|
|
2176
|
-
),
|
|
2177
|
-
(0, import_react3.createElement)(
|
|
2178
|
-
"span",
|
|
2179
|
-
{ className: "dsh-model-allowance-model-side" },
|
|
2180
|
-
switchingModel === model.id ? (0, import_react3.createElement)(
|
|
2181
|
-
"span",
|
|
2182
|
-
{ className: "dsh-model-allowance-model-note" },
|
|
2183
|
-
t("model.switching")
|
|
2184
|
-
) : isCurrent ? (0, import_react3.createElement)(
|
|
2185
|
-
"span",
|
|
2186
|
-
{ className: "dsh-model-allowance-model-note" },
|
|
2187
|
-
t("model.current")
|
|
2188
|
-
) : null,
|
|
2189
|
-
efforts === null ? null : (0, import_react3.createElement)(
|
|
2190
|
-
"span",
|
|
2191
|
-
{
|
|
2192
|
-
className: "dsh-model-allowance-model-arrow",
|
|
2193
|
-
"aria-hidden": true
|
|
2194
|
-
},
|
|
2195
|
-
"\u203A"
|
|
2196
|
-
)
|
|
2197
|
-
)
|
|
2198
|
-
);
|
|
2199
|
-
}),
|
|
2200
|
-
// A failed switch keeps the list open and says why.
|
|
2201
|
-
modelError && shownModelListState !== "error" ? (0, import_react3.createElement)(
|
|
2202
|
-
"div",
|
|
2203
|
-
{
|
|
2204
|
-
className: "dsh-model-allowance-model-message",
|
|
2205
|
-
"data-tone": "error"
|
|
2206
|
-
},
|
|
2207
|
-
modelError
|
|
2208
|
-
) : null
|
|
2209
|
-
) : null,
|
|
2210
|
-
// The effort flyout is a sibling of the list, not a
|
|
2211
|
-
// child: the list scrolls, and a nested panel would be
|
|
2212
|
-
// clipped by it. Sharing the hover with the row keeps
|
|
2213
|
-
// it open while the pointer crosses over.
|
|
2214
|
-
modelMenuOpen && hoverModel !== null && shownModelList.includes(hoverModel.model) ? (0, import_react3.createElement)(
|
|
2215
|
-
"div",
|
|
2216
|
-
{
|
|
2217
|
-
className: "dsh-model-allowance-effort-menu",
|
|
2218
|
-
role: "menu",
|
|
2219
|
-
"aria-label": t("model.title"),
|
|
2220
|
-
style: { top: `${hoverModel.top}px` },
|
|
2221
|
-
onMouseEnter: () => {
|
|
2222
|
-
clearTimeout(hoverModelTimer.current);
|
|
2223
|
-
},
|
|
2224
|
-
onMouseLeave: () => {
|
|
2225
|
-
scheduleEffortFlyoutClose(hoverModel.model.id);
|
|
2226
|
-
}
|
|
2227
|
-
},
|
|
2228
|
-
...effortChoices(hoverModel.model).map((effort) => {
|
|
2229
|
-
const isCurrentEffort = hoverModel.model.id === currentModel && effort.id === selectedEffort;
|
|
2230
|
-
return (0, import_react3.createElement)(
|
|
2231
|
-
"button",
|
|
2232
|
-
{
|
|
2233
|
-
type: "button",
|
|
2234
|
-
key: effort.id ?? "provider-default",
|
|
2235
|
-
role: "menuitemradio",
|
|
2236
|
-
"aria-checked": isCurrentEffort ? "true" : "false",
|
|
2237
|
-
"data-current": isCurrentEffort ? "true" : "false",
|
|
2238
|
-
"data-default": effort.isDefault ? "true" : "false",
|
|
2239
|
-
className: "dsh-model-allowance-effort-item",
|
|
2240
|
-
disabled: switchingModel !== null,
|
|
2241
|
-
onClick: () => {
|
|
2242
|
-
void switchToModel(hoverModel.model, effort.id);
|
|
2243
|
-
}
|
|
2244
|
-
},
|
|
2245
|
-
(0, import_react3.createElement)(
|
|
2246
|
-
"span",
|
|
2247
|
-
{ className: "dsh-model-allowance-model-name" },
|
|
2248
|
-
effort.providerDefault ? t("model.effortDefault") : effort.name
|
|
2249
|
-
),
|
|
2250
|
-
effort.isDefault && !isCurrentEffort ? (0, import_react3.createElement)(
|
|
2251
|
-
"span",
|
|
2252
|
-
{ className: "dsh-model-allowance-model-note" },
|
|
2253
|
-
t("model.effortDefault")
|
|
2254
|
-
) : null
|
|
2255
|
-
);
|
|
2256
|
-
})
|
|
2257
|
-
) : null
|
|
2258
|
-
) : null
|
|
2259
|
-
)
|
|
2260
|
-
) : null
|
|
2457
|
+
open ? (0, import_react7.createElement)(BalancePanel, {
|
|
2458
|
+
t,
|
|
2459
|
+
now,
|
|
2460
|
+
view,
|
|
2461
|
+
activeProvider,
|
|
2462
|
+
available,
|
|
2463
|
+
schedule,
|
|
2464
|
+
currentStatus,
|
|
2465
|
+
serviceState,
|
|
2466
|
+
refresh,
|
|
2467
|
+
refreshing,
|
|
2468
|
+
canSwitch,
|
|
2469
|
+
inUse,
|
|
2470
|
+
switchLabel,
|
|
2471
|
+
selectedEffort,
|
|
2472
|
+
setPicked,
|
|
2473
|
+
nameOf,
|
|
2474
|
+
markFor,
|
|
2475
|
+
catalog,
|
|
2476
|
+
menuOpen,
|
|
2477
|
+
setMenuOpen,
|
|
2478
|
+
stripWidth,
|
|
2479
|
+
setStripWidth,
|
|
2480
|
+
stripRef
|
|
2481
|
+
}) : null
|
|
2261
2482
|
);
|
|
2262
2483
|
}
|
|
2263
2484
|
|
|
@@ -2296,6 +2517,9 @@ function createBalanceContribution() {
|
|
|
2296
2517
|
at: z.number()
|
|
2297
2518
|
}).optional(),
|
|
2298
2519
|
consoleUrl: z.string().optional(),
|
|
2520
|
+
// The setup guide rides an unconfigured reading: the card links it so the
|
|
2521
|
+
// user lands on the walkthrough for this provider's credentials.
|
|
2522
|
+
setupUrl: z.string().optional(),
|
|
2299
2523
|
updatedAt: z.number().optional(),
|
|
2300
2524
|
error: z.string().optional()
|
|
2301
2525
|
});
|
|
@@ -2353,7 +2577,9 @@ function createBalanceContribution() {
|
|
|
2353
2577
|
configured: z.boolean(),
|
|
2354
2578
|
name: z.object({ zh: z.string().optional(), en: z.string().optional() }).optional(),
|
|
2355
2579
|
color: z.string().optional(),
|
|
2356
|
-
iconHint: z.string().optional()
|
|
2580
|
+
iconHint: z.string().optional(),
|
|
2581
|
+
aliases: z.array(z.string()).optional(),
|
|
2582
|
+
modelRoutes: z.array(z.string()).optional()
|
|
2357
2583
|
})
|
|
2358
2584
|
);
|
|
2359
2585
|
return {
|
|
@@ -2395,6 +2621,38 @@ function createBalanceContribution() {
|
|
|
2395
2621
|
"dsh-model-allowance#defaultProvider"
|
|
2396
2622
|
)
|
|
2397
2623
|
},
|
|
2624
|
+
"balance/testCredentials": {
|
|
2625
|
+
service: "balanceController",
|
|
2626
|
+
description: "Walk a provider's credential chain against the live endpoints.",
|
|
2627
|
+
invocation: { kind: "direct" },
|
|
2628
|
+
parameters: [
|
|
2629
|
+
{
|
|
2630
|
+
name: "accessKeyId",
|
|
2631
|
+
wire: "accessKeyId",
|
|
2632
|
+
source: "json",
|
|
2633
|
+
codec: strict(
|
|
2634
|
+
z.string().min(1),
|
|
2635
|
+
"AccessKey ID candidate.",
|
|
2636
|
+
"dsh-model-allowance#accessKeyId"
|
|
2637
|
+
)
|
|
2638
|
+
},
|
|
2639
|
+
{
|
|
2640
|
+
name: "secretAccessKey",
|
|
2641
|
+
wire: "secretAccessKey",
|
|
2642
|
+
source: "json",
|
|
2643
|
+
codec: strict(
|
|
2644
|
+
z.string().min(1),
|
|
2645
|
+
"AccessKey secret candidate.",
|
|
2646
|
+
"dsh-model-allowance#secretAccessKey"
|
|
2647
|
+
)
|
|
2648
|
+
}
|
|
2649
|
+
],
|
|
2650
|
+
result: strict(
|
|
2651
|
+
z.object({ ok: z.boolean(), error: z.string().optional() }),
|
|
2652
|
+
"The outcome.",
|
|
2653
|
+
"dsh-model-allowance#testOutcome"
|
|
2654
|
+
)
|
|
2655
|
+
},
|
|
2398
2656
|
"balance/refresh": {
|
|
2399
2657
|
service: "balanceController",
|
|
2400
2658
|
description: "Force a fresh reading for one provider, bypassing the cache.",
|
|
@@ -2433,6 +2691,334 @@ function createBalanceContribution() {
|
|
|
2433
2691
|
};
|
|
2434
2692
|
}
|
|
2435
2693
|
|
|
2694
|
+
// src/client/credentials-page.js
|
|
2695
|
+
var React7 = __toESM(require("react"), 1);
|
|
2696
|
+
var import_react8 = require("react");
|
|
2697
|
+
|
|
2698
|
+
// src/client/credential-groups.js
|
|
2699
|
+
var CREDENTIAL_GROUPS = Object.freeze([
|
|
2700
|
+
{
|
|
2701
|
+
id: "aliyun",
|
|
2702
|
+
name: {
|
|
2703
|
+
zh: "\u963F\u91CC\u4E91\uFF08\u5343\u95EE Token Plan\uFF09",
|
|
2704
|
+
en: "Alibaba Cloud (Qwen Token Plan)"
|
|
2705
|
+
},
|
|
2706
|
+
docLabel: {
|
|
2707
|
+
zh: "\u5982\u4F55\u83B7\u53D6 AccessKey\uFF1F",
|
|
2708
|
+
en: "How do I get an AccessKey?"
|
|
2709
|
+
},
|
|
2710
|
+
docUrl: "https://github.com/MeiK2333/dsh-model-allowance/blob/master/docs/qwen-token-plen-cn/README.md",
|
|
2711
|
+
test: "qwen",
|
|
2712
|
+
fields: [
|
|
2713
|
+
{
|
|
2714
|
+
ref: "ALIBABA_CLOUD_ACCESS_KEY_ID",
|
|
2715
|
+
label: { zh: "AccessKey ID", en: "AccessKey ID" }
|
|
2716
|
+
},
|
|
2717
|
+
{
|
|
2718
|
+
ref: "ALIBABA_CLOUD_ACCESS_KEY_SECRET",
|
|
2719
|
+
label: { zh: "AccessKey Secret", en: "AccessKey Secret" }
|
|
2720
|
+
}
|
|
2721
|
+
]
|
|
2722
|
+
}
|
|
2723
|
+
]);
|
|
2724
|
+
var CREDENTIAL_REFS = Object.freeze(
|
|
2725
|
+
CREDENTIAL_GROUPS.flatMap((group) => group.fields.map((field) => field.ref))
|
|
2726
|
+
);
|
|
2727
|
+
|
|
2728
|
+
// src/client/credentials-page.js
|
|
2729
|
+
var STYLES2 = [
|
|
2730
|
+
".dsh-allowance-cfg{display:flex;flex-direction:column;gap:12px;max-width:720px;",
|
|
2731
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2732
|
+
".dsh-allowance-cfg-title{margin:0;font-size:16px;line-height:24px;font-weight:500;",
|
|
2733
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2734
|
+
".dsh-allowance-cfg-card{display:flex;flex-direction:column;gap:12px;padding:12px 14px;",
|
|
2735
|
+
"border:0.5px solid var(--dsw-alias-settings-card-stroke);",
|
|
2736
|
+
"background:var(--dsw-alias-settings-card-fill);border-radius:var(--dsw-radius-xl)}",
|
|
2737
|
+
".dsh-allowance-cfg-card-title{margin:0;font-size:14px;line-height:22px;font-weight:500;",
|
|
2738
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2739
|
+
".dsh-allowance-cfg-card-head{display:flex;align-items:center;gap:8px}",
|
|
2740
|
+
".dsh-allowance-cfg-field{display:flex;flex-direction:column;gap:6px}",
|
|
2741
|
+
".dsh-allowance-cfg-field-label{font-size:12px;line-height:18px;font-weight:500;",
|
|
2742
|
+
"color:var(--dsw-alias-label-secondary)}",
|
|
2743
|
+
".dsh-allowance-cfg-text{font-size:14px;line-height:22px;",
|
|
2744
|
+
"color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
|
|
2745
|
+
".dsh-allowance-cfg-status{display:inline-flex;align-items:center;height:22px;",
|
|
2746
|
+
"padding:0 8px;border-radius:var(--dsw-radius-sm);font-size:12px;line-height:18px;",
|
|
2747
|
+
"border:0.5px solid var(--dsw-alias-state-success-primary);",
|
|
2748
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
2749
|
+
".dsh-allowance-cfg-input{box-sizing:border-box;width:100%;height:32px;padding:0 10px;",
|
|
2750
|
+
"border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);",
|
|
2751
|
+
"font:inherit;font-size:14px;line-height:22px;background:var(--dsw-alias-bg-layer-1);",
|
|
2752
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2753
|
+
".dsh-allowance-cfg-input:focus{outline:none;",
|
|
2754
|
+
"border-color:var(--dsw-alias-state-business-primary)}",
|
|
2755
|
+
".dsh-allowance-cfg-input:disabled{opacity:.6;cursor:default}",
|
|
2756
|
+
".dsh-allowance-cfg-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
2757
|
+
".dsh-allowance-cfg-button{box-sizing:border-box;display:inline-flex;align-items:center;",
|
|
2758
|
+
"justify-content:center;height:32px;padding:0 14px;border:none;",
|
|
2759
|
+
"border-radius:var(--dsw-radius-md);font:inherit;font-size:14px;line-height:22px;",
|
|
2760
|
+
"cursor:pointer}",
|
|
2761
|
+
'.dsh-allowance-cfg-button[data-tone="primary"]{',
|
|
2762
|
+
"background:var(--dsw-alias-button-primary-fill);",
|
|
2763
|
+
"color:var(--dsw-alias-label-primary-foreground)}",
|
|
2764
|
+
'.dsh-allowance-cfg-button[data-tone="primary"]:hover:not(:disabled){',
|
|
2765
|
+
"background:var(--dsw-alias-button-primary-hover)}",
|
|
2766
|
+
'.dsh-allowance-cfg-button[data-tone="secondary"]{',
|
|
2767
|
+
"border:0.5px solid var(--dsw-alias-border-l3);background:transparent;",
|
|
2768
|
+
"color:var(--dsw-alias-label-primary)}",
|
|
2769
|
+
'.dsh-allowance-cfg-button[data-tone="secondary"]:hover:not(:disabled){',
|
|
2770
|
+
"background:var(--dsw-alias-interactive-bg-hover-solid)}",
|
|
2771
|
+
".dsh-allowance-cfg-button:disabled{opacity:.5;cursor:default}",
|
|
2772
|
+
".dsh-allowance-cfg-link{font-size:12px;line-height:18px;",
|
|
2773
|
+
"color:var(--dsw-alias-state-business-primary);text-decoration:none}",
|
|
2774
|
+
".dsh-allowance-cfg-link:hover{text-decoration:underline}",
|
|
2775
|
+
".dsh-allowance-cfg-saved{margin:0;font-size:12px;line-height:18px;",
|
|
2776
|
+
"color:var(--dsw-alias-state-success-primary)}",
|
|
2777
|
+
".dsh-allowance-cfg-error{margin:0;font-size:12px;line-height:18px;",
|
|
2778
|
+
"color:var(--dsw-alias-state-error-primary)}",
|
|
2779
|
+
".dsh-allowance-cfg-hint{margin:0;font-size:12px;line-height:18px;",
|
|
2780
|
+
"color:var(--dsh-alias-label-tertiary)}"
|
|
2781
|
+
].join("");
|
|
2782
|
+
function pick(bilingual) {
|
|
2783
|
+
return bilingual[activeLanguage()] ?? bilingual.en ?? bilingual.zh;
|
|
2784
|
+
}
|
|
2785
|
+
function errorText(error) {
|
|
2786
|
+
return error instanceof Error ? error.message : String(error);
|
|
2787
|
+
}
|
|
2788
|
+
async function testGroup(group, drafts, refId, refSecret, t) {
|
|
2789
|
+
if (group.test !== "qwen") return { ok: true };
|
|
2790
|
+
try {
|
|
2791
|
+
const api = await getBalanceApi();
|
|
2792
|
+
if (!api || typeof api.testCredentials !== "function") return { ok: true };
|
|
2793
|
+
const result = await api.testCredentials(drafts[refId] ?? "", drafts[refSecret] ?? "");
|
|
2794
|
+
if (result.ok && result.value?.ok === true) return { ok: true };
|
|
2795
|
+
if (result.ok && result.value?.ok === false) {
|
|
2796
|
+
return { ok: false, error: result.value.error ?? t("settings.testRejected") };
|
|
2797
|
+
}
|
|
2798
|
+
return { ok: false, error: errorText(result.error ?? t("settings.testRejected")) };
|
|
2799
|
+
} catch (error) {
|
|
2800
|
+
return { ok: false, error: errorText(error) };
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function unwrap(response) {
|
|
2804
|
+
if (response?.ok) return response.value;
|
|
2805
|
+
const detail = response?.error;
|
|
2806
|
+
throw new Error(
|
|
2807
|
+
detail instanceof Error ? detail.message : typeof detail?.message === "string" ? detail.message : typeof detail === "string" ? detail : "the Host refused the call"
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
function CredentialsSection({ ctx, t }) {
|
|
2811
|
+
const credentials = ctx.get("remote.credentials");
|
|
2812
|
+
const [infos, setInfos] = React7.useState(void 0);
|
|
2813
|
+
const [drafts, setDrafts] = React7.useState({});
|
|
2814
|
+
const [editing, setEditing] = React7.useState({});
|
|
2815
|
+
const [busy, setBusy] = React7.useState(false);
|
|
2816
|
+
const [notice, setNotice] = React7.useState(void 0);
|
|
2817
|
+
const load = React7.useCallback(async () => {
|
|
2818
|
+
if (credentials === void 0) return;
|
|
2819
|
+
try {
|
|
2820
|
+
setInfos(unwrap(await credentials.describe([...CREDENTIAL_REFS])));
|
|
2821
|
+
} catch (error) {
|
|
2822
|
+
setInfos({});
|
|
2823
|
+
setNotice({ tone: "error", text: `${t("settings.loadFailed")}: ${errorText(error)}` });
|
|
2824
|
+
}
|
|
2825
|
+
}, [credentials, t]);
|
|
2826
|
+
React7.useEffect(() => {
|
|
2827
|
+
void load();
|
|
2828
|
+
}, [load]);
|
|
2829
|
+
const resetGroup = (group) => {
|
|
2830
|
+
setDrafts((previous) => {
|
|
2831
|
+
const next = { ...previous };
|
|
2832
|
+
for (const field of group.fields) delete next[field.ref];
|
|
2833
|
+
return next;
|
|
2834
|
+
});
|
|
2835
|
+
setEditing((previous) => ({ ...previous, [group.id]: false }));
|
|
2836
|
+
};
|
|
2837
|
+
const saveGroup = async (group) => {
|
|
2838
|
+
const values = group.fields.map((field) => (drafts[field.ref] ?? "").trim());
|
|
2839
|
+
if (values.some((value) => value === "")) {
|
|
2840
|
+
setNotice({ tone: "error", text: t("settings.fillAll") });
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
setBusy(true);
|
|
2844
|
+
setNotice(void 0);
|
|
2845
|
+
try {
|
|
2846
|
+
const [idField, secretField] = group.fields;
|
|
2847
|
+
const tested = await testGroup(
|
|
2848
|
+
group,
|
|
2849
|
+
Object.fromEntries(
|
|
2850
|
+
group.fields.map((field) => [field.ref, (drafts[field.ref] ?? "").trim()])
|
|
2851
|
+
),
|
|
2852
|
+
idField.ref,
|
|
2853
|
+
secretField.ref,
|
|
2854
|
+
t
|
|
2855
|
+
);
|
|
2856
|
+
if (!tested.ok) {
|
|
2857
|
+
setNotice({ tone: "error", text: `${t("settings.testFailed")}: ${tested.error}` });
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
for (const field of group.fields) {
|
|
2861
|
+
unwrap(await credentials.set(field.ref, (drafts[field.ref] ?? "").trim()));
|
|
2862
|
+
}
|
|
2863
|
+
resetGroup(group);
|
|
2864
|
+
setNotice({ tone: "ok", text: t("settings.saved") });
|
|
2865
|
+
} catch (error) {
|
|
2866
|
+
setNotice({ tone: "error", text: `${t("settings.saveFailed")}: ${errorText(error)}` });
|
|
2867
|
+
} finally {
|
|
2868
|
+
setBusy(false);
|
|
2869
|
+
await load();
|
|
2870
|
+
}
|
|
2871
|
+
};
|
|
2872
|
+
const deleteGroup = async (group) => {
|
|
2873
|
+
setBusy(true);
|
|
2874
|
+
setNotice(void 0);
|
|
2875
|
+
try {
|
|
2876
|
+
for (const field of group.fields) {
|
|
2877
|
+
unwrap(await credentials.unset(field.ref));
|
|
2878
|
+
}
|
|
2879
|
+
resetGroup(group);
|
|
2880
|
+
setNotice({ tone: "ok", text: t("settings.deleted") });
|
|
2881
|
+
} catch (error) {
|
|
2882
|
+
setNotice({ tone: "error", text: `${t("settings.deleteFailed")}: ${errorText(error)}` });
|
|
2883
|
+
} finally {
|
|
2884
|
+
setBusy(false);
|
|
2885
|
+
await load();
|
|
2886
|
+
}
|
|
2887
|
+
};
|
|
2888
|
+
const renderField = (field, editMode) => {
|
|
2889
|
+
const info = infos?.[field.ref];
|
|
2890
|
+
return (0, import_react8.createElement)(
|
|
2891
|
+
"div",
|
|
2892
|
+
{ key: field.ref, className: "dsh-allowance-cfg-field" },
|
|
2893
|
+
(0, import_react8.createElement)(
|
|
2894
|
+
editMode ? "label" : "div",
|
|
2895
|
+
{
|
|
2896
|
+
className: "dsh-allowance-cfg-field-label",
|
|
2897
|
+
htmlFor: editMode ? `dsh-allowance-cfg-${field.ref}` : void 0
|
|
2898
|
+
},
|
|
2899
|
+
pick(field.label)
|
|
2900
|
+
),
|
|
2901
|
+
editMode ? (0, import_react8.createElement)("input", {
|
|
2902
|
+
id: `dsh-allowance-cfg-${field.ref}`,
|
|
2903
|
+
className: "dsh-allowance-cfg-input",
|
|
2904
|
+
type: "password",
|
|
2905
|
+
autoComplete: "off",
|
|
2906
|
+
spellCheck: false,
|
|
2907
|
+
disabled: busy || info?.writable === false,
|
|
2908
|
+
value: drafts[field.ref] ?? "",
|
|
2909
|
+
onChange: (event) => setDrafts((previous) => ({ ...previous, [field.ref]: event.target.value }))
|
|
2910
|
+
}) : (
|
|
2911
|
+
// A stored record reads as text, not as a box that mimics the
|
|
2912
|
+
// entry form: the two states must be told apart at a glance.
|
|
2913
|
+
(0, import_react8.createElement)(
|
|
2914
|
+
"span",
|
|
2915
|
+
{ className: "dsh-allowance-cfg-text" },
|
|
2916
|
+
typeof info?.masked === "string" && info.masked !== "" ? info.masked : "********"
|
|
2917
|
+
)
|
|
2918
|
+
)
|
|
2919
|
+
);
|
|
2920
|
+
};
|
|
2921
|
+
const renderGroup = (group) => {
|
|
2922
|
+
const allStored = group.fields.every((field) => infos?.[field.ref]?.configured === true);
|
|
2923
|
+
const editMode = !allStored || editing[group.id] === true;
|
|
2924
|
+
return (0, import_react8.createElement)(
|
|
2925
|
+
"section",
|
|
2926
|
+
{ key: group.id, className: "dsh-allowance-cfg-card" },
|
|
2927
|
+
(0, import_react8.createElement)(
|
|
2928
|
+
"div",
|
|
2929
|
+
{ className: "dsh-allowance-cfg-card-head" },
|
|
2930
|
+
(0, import_react8.createElement)("h3", { className: "dsh-allowance-cfg-card-title" }, pick(group.name)),
|
|
2931
|
+
// The stored state names itself, so the card reads as configured or
|
|
2932
|
+
// as a form to fill without reading any field.
|
|
2933
|
+
allStored ? (0, import_react8.createElement)("span", { className: "dsh-allowance-cfg-status" }, t("settings.configured")) : null
|
|
2934
|
+
),
|
|
2935
|
+
group.docUrl ? (0, import_react8.createElement)(
|
|
2936
|
+
"a",
|
|
2937
|
+
{
|
|
2938
|
+
className: "dsh-allowance-cfg-link",
|
|
2939
|
+
href: group.docUrl,
|
|
2940
|
+
target: "_blank",
|
|
2941
|
+
rel: "noreferrer noopener"
|
|
2942
|
+
},
|
|
2943
|
+
`${group.docLabel ? pick(group.docLabel) : t("settings.doc")} \u2197`
|
|
2944
|
+
) : null,
|
|
2945
|
+
group.fields.map((field) => renderField(field, editMode)),
|
|
2946
|
+
(0, import_react8.createElement)(
|
|
2947
|
+
"div",
|
|
2948
|
+
{ className: "dsh-allowance-cfg-actions" },
|
|
2949
|
+
editMode ? (0, import_react8.createElement)(
|
|
2950
|
+
"button",
|
|
2951
|
+
{
|
|
2952
|
+
type: "button",
|
|
2953
|
+
className: "dsh-allowance-cfg-button",
|
|
2954
|
+
"data-tone": "primary",
|
|
2955
|
+
disabled: busy,
|
|
2956
|
+
onClick: () => void saveGroup(group)
|
|
2957
|
+
},
|
|
2958
|
+
busy ? t("settings.testing") : t("settings.save")
|
|
2959
|
+
) : [
|
|
2960
|
+
(0, import_react8.createElement)(
|
|
2961
|
+
"button",
|
|
2962
|
+
{
|
|
2963
|
+
type: "button",
|
|
2964
|
+
key: "edit",
|
|
2965
|
+
className: "dsh-allowance-cfg-button",
|
|
2966
|
+
"data-tone": "secondary",
|
|
2967
|
+
disabled: busy,
|
|
2968
|
+
onClick: () => setEditing((previous) => ({ ...previous, [group.id]: true }))
|
|
2969
|
+
},
|
|
2970
|
+
t("settings.edit")
|
|
2971
|
+
),
|
|
2972
|
+
(0, import_react8.createElement)(
|
|
2973
|
+
"button",
|
|
2974
|
+
{
|
|
2975
|
+
type: "button",
|
|
2976
|
+
key: "delete",
|
|
2977
|
+
className: "dsh-allowance-cfg-button",
|
|
2978
|
+
"data-tone": "secondary",
|
|
2979
|
+
disabled: busy,
|
|
2980
|
+
onClick: () => void deleteGroup(group)
|
|
2981
|
+
},
|
|
2982
|
+
t("settings.delete")
|
|
2983
|
+
)
|
|
2984
|
+
],
|
|
2985
|
+
allStored && editMode ? (0, import_react8.createElement)(
|
|
2986
|
+
"button",
|
|
2987
|
+
{
|
|
2988
|
+
type: "button",
|
|
2989
|
+
className: "dsh-allowance-cfg-button",
|
|
2990
|
+
"data-tone": "secondary",
|
|
2991
|
+
disabled: busy,
|
|
2992
|
+
onClick: () => resetGroup(group)
|
|
2993
|
+
},
|
|
2994
|
+
t("settings.cancel")
|
|
2995
|
+
) : null
|
|
2996
|
+
)
|
|
2997
|
+
);
|
|
2998
|
+
};
|
|
2999
|
+
return (0, import_react8.createElement)(
|
|
3000
|
+
React7.Fragment,
|
|
3001
|
+
null,
|
|
3002
|
+
// Component-local styles: React removes them with the component.
|
|
3003
|
+
(0, import_react8.createElement)("style", { key: "styles" }, STYLES2),
|
|
3004
|
+
(0, import_react8.createElement)(
|
|
3005
|
+
"div",
|
|
3006
|
+
{ className: "dsh-allowance-cfg" },
|
|
3007
|
+
(0, import_react8.createElement)("h2", { className: "dsh-allowance-cfg-title" }, t("settings.title")),
|
|
3008
|
+
credentials === void 0 ? (0, import_react8.createElement)("p", { className: "dsh-allowance-cfg-error" }, t("settings.unavailable")) : infos === void 0 ? (0, import_react8.createElement)("p", { className: "dsh-allowance-cfg-hint" }, t("settings.loading")) : CREDENTIAL_GROUPS.map((group) => renderGroup(group)),
|
|
3009
|
+
notice === void 0 ? null : (0, import_react8.createElement)(
|
|
3010
|
+
"p",
|
|
3011
|
+
{
|
|
3012
|
+
key: "notice",
|
|
3013
|
+
role: "status",
|
|
3014
|
+
className: notice.tone === "error" ? "dsh-allowance-cfg-error" : "dsh-allowance-cfg-saved"
|
|
3015
|
+
},
|
|
3016
|
+
notice.text
|
|
3017
|
+
)
|
|
3018
|
+
)
|
|
3019
|
+
);
|
|
3020
|
+
}
|
|
3021
|
+
|
|
2436
3022
|
// src/client/index.js
|
|
2437
3023
|
var inject = ["slots", "locale", "remote"];
|
|
2438
3024
|
function apply(ctx) {
|
|
@@ -2497,7 +3083,20 @@ function apply(ctx) {
|
|
|
2497
3083
|
id: "model-allowance",
|
|
2498
3084
|
order: 10
|
|
2499
3085
|
},
|
|
2500
|
-
(props) => (0,
|
|
3086
|
+
(props) => (0, import_react9.createElement)(BalanceBadge, { ...props, ctx, t })
|
|
3087
|
+
)
|
|
3088
|
+
);
|
|
3089
|
+
const SECTION = "settings.section";
|
|
3090
|
+
ctx.slots.inject(
|
|
3091
|
+
SECTION,
|
|
3092
|
+
() => ctx.slots.register(
|
|
3093
|
+
{
|
|
3094
|
+
name: SECTION,
|
|
3095
|
+
id: "model-allowance",
|
|
3096
|
+
order: 30,
|
|
3097
|
+
label: () => t("settings.nav")
|
|
3098
|
+
},
|
|
3099
|
+
(props) => (0, import_react9.createElement)(CredentialsSection, { ...props, ctx, t })
|
|
2501
3100
|
)
|
|
2502
3101
|
);
|
|
2503
3102
|
}
|