dsh-keys-manager 0.2.6 → 0.2.8
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/CHANGELOG.md +40 -0
- package/README.md +219 -269
- package/README.zh-CN.md +142 -136
- package/lib/client/format.d.ts +29 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/types.d.ts +10 -2
- package/lib/client.js +222 -7
- package/lib/domain.d.ts +30 -5
- package/lib/index.d.ts +44 -5
- package/lib/index.js +214 -78
- package/lib/index.js.map +1 -1
- package/lib/quota/cache.d.ts +61 -0
- package/lib/quota/cache.js +88 -0
- package/lib/quota/cache.js.map +1 -0
- package/lib/quota/fetch.d.ts +33 -0
- package/lib/quota/fetch.js +36 -0
- package/lib/quota/fetch.js.map +1 -0
- package/lib/quota/model.d.ts +56 -0
- package/lib/quota/model.js +62 -0
- package/lib/quota/model.js.map +1 -0
- package/lib/quota/providers.d.ts +48 -0
- package/lib/quota/providers.js +364 -0
- package/lib/quota/providers.js.map +1 -0
- package/locale/en.json +10 -1
- package/locale/zh.json +10 -1
- package/package.json +15 -15
package/lib/client.js
CHANGED
|
@@ -73,6 +73,7 @@ var zh = {
|
|
|
73
73
|
notConfigured: "\u672A\u914D\u7F6E",
|
|
74
74
|
adopt: "\u63A5\u7BA1 Provider",
|
|
75
75
|
adopting: "\u63A5\u7BA1\u4E2D\u2026",
|
|
76
|
+
signingIn: "\u6B63\u5728\u767B\u5F55\u2026",
|
|
76
77
|
release: "\u505C\u6B62\u63A5\u7BA1",
|
|
77
78
|
releasing: "\u6B63\u5728\u91CA\u653E\u2026",
|
|
78
79
|
addKey: "\u6DFB\u52A0\u5BC6\u94A5",
|
|
@@ -226,7 +227,18 @@ var zh = {
|
|
|
226
227
|
transportModelsLoading: "\u6B63\u5728\u52A0\u8F7D\u6A21\u578B\u2026",
|
|
227
228
|
transportModelsClear: "\u6E05\u9664\u9009\u62E9",
|
|
228
229
|
transportModelsHint: "\u4E0D\u52FE\u9009\u4EFB\u4F55\u6A21\u578B\u8868\u793A\u4F7F\u7528\u5168\u90E8\u6A21\u578B\uFF1B\u4FDD\u5B58\u540E\u8BE5\u8DEF\u7531\u7684\u6A21\u578B\u5217\u8868\u968F\u4E4B\u6536\u7A84\u3002",
|
|
229
|
-
transportModelsMissingCatalog: "\u5DF2\u5B89\u88C5\u7684\u4F20\u8F93\u6784\u5EFA\u6CA1\u6709\u4E3A\u8BE5\u8DEF\u7531\u63D0\u4F9B\u6A21\u578B\u76EE\u5F55\uFF1B\u5217\u8868\u4F1A\u4E00\u76F4\u4E3A\u7A7A\uFF0C\u76F4\u5230\u91CD\u65B0\u6784\u5EFA\u6216\u5347\u7EA7 dsh-llm-omp-transports\u3002"
|
|
230
|
+
transportModelsMissingCatalog: "\u5DF2\u5B89\u88C5\u7684\u4F20\u8F93\u6784\u5EFA\u6CA1\u6709\u4E3A\u8BE5\u8DEF\u7531\u63D0\u4F9B\u6A21\u578B\u76EE\u5F55\uFF1B\u5217\u8868\u4F1A\u4E00\u76F4\u4E3A\u7A7A\uFF0C\u76F4\u5230\u91CD\u65B0\u6784\u5EFA\u6216\u5347\u7EA7 dsh-llm-omp-transports\u3002",
|
|
231
|
+
// Plan usage on a provider card (issue #22). The window abbreviations
|
|
232
|
+
// (5h / W) are technical and stay untranslated, so they are code, not
|
|
233
|
+
// dictionary entries.
|
|
234
|
+
quotaTitle: "\u8BA1\u5212\u7528\u91CF",
|
|
235
|
+
quotaRefreshing: "\u5237\u65B0\u4E2D\u2026",
|
|
236
|
+
quotaChecking: "\u6B63\u5728\u68C0\u67E5\u2026",
|
|
237
|
+
quotaNotReported: "\u672A\u62A5\u544A",
|
|
238
|
+
quotaSignInAgain: "\u8BF7\u91CD\u65B0\u767B\u5F55",
|
|
239
|
+
quotaStale: "\u6570\u636E\u8F83\u65E7",
|
|
240
|
+
quotaCompactHint: "\u8BE5 Provider \u5404\u8D26\u53F7\u4E2D\u6700\u7D27\u7684\u8BA1\u5212\u7528\u91CF\u7A97\u53E3\uFF1B\u5C55\u5F00\u5361\u7247\u67E5\u770B\u6BCF\u4E2A\u8D26\u53F7\u3002",
|
|
241
|
+
quotaBarLabel: "{window} \u7A97\u53E3\u5DF2\u7528 {percent}%"
|
|
230
242
|
};
|
|
231
243
|
var en = {
|
|
232
244
|
nav: "Keys Manager",
|
|
@@ -260,6 +272,7 @@ var en = {
|
|
|
260
272
|
notConfigured: "not configured",
|
|
261
273
|
adopt: "Adopt provider",
|
|
262
274
|
adopting: "Adopting\u2026",
|
|
275
|
+
signingIn: "Signing in\u2026",
|
|
263
276
|
release: "Stop managing",
|
|
264
277
|
releasing: "Releasing\u2026",
|
|
265
278
|
addKey: "Add key",
|
|
@@ -412,7 +425,16 @@ var en = {
|
|
|
412
425
|
transportModelsLoading: "Loading models\u2026",
|
|
413
426
|
transportModelsClear: "Clear selection",
|
|
414
427
|
transportModelsHint: "Leave every model unchecked to use the full catalog; saving narrows the list this route advertises.",
|
|
415
|
-
transportModelsMissingCatalog: "The installed transport build ships no model catalog for this route; the list stays empty until dsh-llm-omp-transports is rebuilt or upgraded."
|
|
428
|
+
transportModelsMissingCatalog: "The installed transport build ships no model catalog for this route; the list stays empty until dsh-llm-omp-transports is rebuilt or upgraded.",
|
|
429
|
+
// Plan usage on a provider card (issue #22).
|
|
430
|
+
quotaTitle: "Plan usage",
|
|
431
|
+
quotaRefreshing: "Refreshing\u2026",
|
|
432
|
+
quotaChecking: "Checking\u2026",
|
|
433
|
+
quotaNotReported: "Not reported",
|
|
434
|
+
quotaSignInAgain: "Sign in again",
|
|
435
|
+
quotaStale: "Stale",
|
|
436
|
+
quotaCompactHint: "The tightest plan window across this provider's accounts; expand the card for every account.",
|
|
437
|
+
quotaBarLabel: "{window} window {percent}% used"
|
|
416
438
|
};
|
|
417
439
|
var LOCALE_DICTS = { zh, en };
|
|
418
440
|
|
|
@@ -566,6 +588,27 @@ select.km-input{appearance:auto}
|
|
|
566
588
|
.km-notice-action{flex:0 0 auto}
|
|
567
589
|
.km-empty-keys{padding:12px;border:1px dashed var(--dsw-alias-border-l2);border-radius:8px;color:var(--dsw-alias-label-secondary);font-size:12px}
|
|
568
590
|
.km-empty{display:flex;align-items:center;gap:8px;padding:14px;border:1px dashed var(--dsw-alias-border-l2);border-radius:10px;color:var(--dsw-alias-label-secondary);font-size:12.5px}
|
|
591
|
+
.km-quota-compact{align-self:center;flex-shrink:1;min-width:0;max-width:76px;overflow:hidden;text-overflow:ellipsis;padding:1px 6px;border-radius:999px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);font-size:11px;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
592
|
+
.km-quota-compact.km-quota-warn{color:var(--dsw-alias-state-warn-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 34%,var(--dsw-alias-border-l1))}
|
|
593
|
+
.km-quota-compact.km-quota-error{color:var(--dsw-alias-state-error-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 34%,var(--dsw-alias-border-l1))}
|
|
594
|
+
.km-quota-strip{display:flex;flex-direction:column;gap:2px;margin:8px 0 9px;padding:6px 9px 5px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-1)}
|
|
595
|
+
.km-quota-head{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:10.5px;letter-spacing:.04em;text-transform:uppercase;color:var(--dsw-alias-label-secondary)}
|
|
596
|
+
.km-quota-busy{color:var(--dsw-alias-brand-primary);letter-spacing:0;text-transform:none}
|
|
597
|
+
.km-quota-list{display:flex;flex-direction:column;margin:0;padding:0;list-style:none}
|
|
598
|
+
.km-quota-row{display:flex;align-items:center;gap:8px;min-height:22px;max-height:26px;padding:0;font-size:11px;line-height:1.3}
|
|
599
|
+
.km-quota-alias{flex:0 1 30%;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-primary)}
|
|
600
|
+
.km-quota-metrics{display:flex;flex:1;align-items:center;justify-content:flex-end;gap:7px;min-width:0}
|
|
601
|
+
.km-quota-stale .km-quota-track,.km-quota-stale .km-quota-pct,.km-quota-stale .km-quota-reset{opacity:.55}
|
|
602
|
+
.km-quota-metric{display:inline-flex;align-items:center;gap:4px;flex-shrink:0}
|
|
603
|
+
.km-quota-window{min-width:15px;font-size:10.5px;color:var(--dsw-alias-label-secondary)}
|
|
604
|
+
.km-quota-track{position:relative;display:inline-block;width:42px;height:5px;border-radius:999px;background:var(--dsw-alias-bg-layer-2);box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l1);overflow:hidden}
|
|
605
|
+
.km-quota-fill{display:block;height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary)}
|
|
606
|
+
.km-quota-fill-warn{background:var(--dsw-alias-state-warn-primary)}
|
|
607
|
+
.km-quota-fill-error{background:var(--dsw-alias-state-error-primary)}
|
|
608
|
+
.km-quota-pct{min-width:28px;text-align:right;font-size:11px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary)}
|
|
609
|
+
.km-quota-reset{font-size:10.5px;font-variant-numeric:tabular-nums;white-space:nowrap;color:var(--dsw-alias-label-secondary)}
|
|
610
|
+
.km-quota-flag{padding:0 4px;border-radius:4px;font-size:10px;color:var(--dsw-alias-state-warn-primary);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 12%,transparent)}
|
|
611
|
+
.km-quota-note{margin-left:auto;font-size:10.5px;color:var(--dsw-alias-label-secondary)}
|
|
569
612
|
.km-provider-foot{display:flex;justify-content:space-between;gap:10px;align-items:center;margin-top:10px;padding-top:9px;border-top:1px dashed var(--dsw-alias-border-l1);font-size:11px;min-height:15px}
|
|
570
613
|
.km-settings{padding:14px}
|
|
571
614
|
.km-settings-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px}
|
|
@@ -622,6 +665,10 @@ select.km-input{appearance:auto}
|
|
|
622
665
|
.km-settings-grid{grid-template-columns:1fr}
|
|
623
666
|
.km-form-grid{grid-template-columns:1fr}
|
|
624
667
|
.km-provider-side .km-status{display:none}
|
|
668
|
+
/* Narrow cards drop the supplementary one-liner and the countdown rather
|
|
669
|
+
than wrapping; the expanded strip stays the primary carrier. */
|
|
670
|
+
.km-provider-side .km-quota-compact{display:none}
|
|
671
|
+
.km-quota-reset{display:none}
|
|
625
672
|
.km-embedded-head{flex-direction:column;gap:10px}
|
|
626
673
|
.km-embedded-actions{padding-top:0}
|
|
627
674
|
}
|
|
@@ -704,13 +751,42 @@ function shapeTransportModels(value) {
|
|
|
704
751
|
}
|
|
705
752
|
}
|
|
706
753
|
const models = Array.isArray(record.models) ? record.models.filter((id) => typeof id === "string") : [];
|
|
707
|
-
|
|
708
|
-
return warning === void 0 ? { catalog, models } : { catalog, models, warning };
|
|
754
|
+
return record.missingCatalog === true ? { catalog, models, missingCatalog: true } : { catalog, models };
|
|
709
755
|
}
|
|
710
756
|
function modelPickerRows(view) {
|
|
711
757
|
const selected = new Set(view.models);
|
|
712
758
|
return view.catalog.map((row) => ({ id: row.id, name: row.name, selected: selected.has(row.id) }));
|
|
713
759
|
}
|
|
760
|
+
var QUOTA_TTL_MS = 375e3;
|
|
761
|
+
var QUOTA_WINDOW_LABEL = { session: "5h", week: "W" };
|
|
762
|
+
var QUOTA_WINDOW_ORDER = ["session", "week"];
|
|
763
|
+
function quotaPercent(fraction) {
|
|
764
|
+
return Math.min(100, Math.max(0, Math.round(fraction * 100)));
|
|
765
|
+
}
|
|
766
|
+
function quotaTone(usedFraction) {
|
|
767
|
+
if (usedFraction >= 1) return "error";
|
|
768
|
+
return usedFraction >= 0.9 ? "warn" : "normal";
|
|
769
|
+
}
|
|
770
|
+
function quotaWindows(quota) {
|
|
771
|
+
if (quota === void 0 || quota.status !== "ok") return [];
|
|
772
|
+
return QUOTA_WINDOW_ORDER.map((id) => quota.windows.find((window) => window.id === id)).filter(
|
|
773
|
+
(window) => window !== void 0
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
function tightestQuotaWindow(quotas) {
|
|
777
|
+
let tightest;
|
|
778
|
+
for (const quota of quotas) {
|
|
779
|
+
for (const window of quotaWindows(quota)) {
|
|
780
|
+
if (tightest === void 0 || window.usedFraction > tightest.usedFraction) tightest = window;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return tightest;
|
|
784
|
+
}
|
|
785
|
+
function quotaNeedsRefresh(quotas, now) {
|
|
786
|
+
return quotas.some(
|
|
787
|
+
(quota) => quota === void 0 || quota.status === "ok" && now - quota.fetchedAt > QUOTA_TTL_MS
|
|
788
|
+
);
|
|
789
|
+
}
|
|
714
790
|
|
|
715
791
|
// src/client/store.ts
|
|
716
792
|
function messageOf(error) {
|
|
@@ -744,6 +820,7 @@ function createStore(ctx) {
|
|
|
744
820
|
let testGeneration = 0;
|
|
745
821
|
let mutationGeneration = 0;
|
|
746
822
|
let stateDropped = false;
|
|
823
|
+
const quotaInFlight = /* @__PURE__ */ new Map();
|
|
747
824
|
const listeners = /* @__PURE__ */ new Set();
|
|
748
825
|
const emit = () => {
|
|
749
826
|
for (const listener of [...listeners]) {
|
|
@@ -910,6 +987,33 @@ function createStore(ctx) {
|
|
|
910
987
|
if (!result.ok) return { ok: false, error: result.error.message };
|
|
911
988
|
return { ok: true, value: shapeTransportModels(result.value) };
|
|
912
989
|
},
|
|
990
|
+
refreshQuota(provider) {
|
|
991
|
+
const pending = quotaInFlight.get(provider);
|
|
992
|
+
if (pending !== void 0) return pending;
|
|
993
|
+
const generation = testGeneration;
|
|
994
|
+
let dropped = false;
|
|
995
|
+
const request = (async () => {
|
|
996
|
+
try {
|
|
997
|
+
const result = await rpc("quotaRefresh", { provider });
|
|
998
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
999
|
+
const state = result.value;
|
|
1000
|
+
if (activeTests > 0 || testGeneration !== generation) {
|
|
1001
|
+
stateDropped = true;
|
|
1002
|
+
dropped = true;
|
|
1003
|
+
} else {
|
|
1004
|
+
update({ status: "ready", state, now: Date.now(), error: snapshot.error });
|
|
1005
|
+
}
|
|
1006
|
+
return { ok: true, value: state };
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
return { ok: false, error: messageOf(error) };
|
|
1009
|
+
} finally {
|
|
1010
|
+
quotaInFlight.delete(provider);
|
|
1011
|
+
if (dropped) refreshDroppedState();
|
|
1012
|
+
}
|
|
1013
|
+
})();
|
|
1014
|
+
quotaInFlight.set(provider, request);
|
|
1015
|
+
return request;
|
|
1016
|
+
},
|
|
913
1017
|
saveTransportModels(route, models) {
|
|
914
1018
|
return send("saveTransportModels", { provider: route, models }, modelsOutcome);
|
|
915
1019
|
},
|
|
@@ -1839,7 +1943,7 @@ function TransportModels({ route }) {
|
|
|
1839
1943
|
}
|
|
1840
1944
|
const rows = view === null ? [] : modelPickerRows(view);
|
|
1841
1945
|
const emptyCatalog = view !== null && view.catalog.length === 0;
|
|
1842
|
-
const
|
|
1946
|
+
const missingCatalog = view !== null && view.missingCatalog === true;
|
|
1843
1947
|
const errorLine = error === null ? null : h("div", { className: "km-inline-error", role: "alert" }, error);
|
|
1844
1948
|
return h(
|
|
1845
1949
|
"div",
|
|
@@ -1886,7 +1990,7 @@ function TransportModels({ route }) {
|
|
|
1886
1990
|
))),
|
|
1887
1991
|
// An empty grid is also the all-models state: only the host's report of
|
|
1888
1992
|
// a missing catalog explains it.
|
|
1889
|
-
emptyCatalog &&
|
|
1993
|
+
emptyCatalog && missingCatalog ? h("div", { className: "km-field-hint", role: "status" }, t("transportModelsMissingCatalog")) : null,
|
|
1890
1994
|
h(
|
|
1891
1995
|
"div",
|
|
1892
1996
|
{ className: "km-models-actions" },
|
|
@@ -1908,6 +2012,103 @@ function TransportModels({ route }) {
|
|
|
1908
2012
|
) : null
|
|
1909
2013
|
);
|
|
1910
2014
|
}
|
|
2015
|
+
function quotaRow(row, t, now) {
|
|
2016
|
+
const windows = quotaWindows(row.quota);
|
|
2017
|
+
const alias = h("span", { className: "km-quota-alias", title: row.alias }, row.alias);
|
|
2018
|
+
if (windows.length === 0) {
|
|
2019
|
+
const note = row.quota === void 0 ? t("quotaChecking") : row.quota.status === "unauthorized" && row.kind === "oauth" ? t("quotaSignInAgain") : t("quotaNotReported");
|
|
2020
|
+
return h("li", { key: row.id, className: "km-quota-row" }, alias, h("span", { className: "km-quota-note" }, note));
|
|
2021
|
+
}
|
|
2022
|
+
const tightest = windows.reduce((best, window) => window.usedFraction > best.usedFraction ? window : best);
|
|
2023
|
+
return h(
|
|
2024
|
+
"li",
|
|
2025
|
+
{ key: row.id, className: "km-quota-row" },
|
|
2026
|
+
alias,
|
|
2027
|
+
h(
|
|
2028
|
+
"span",
|
|
2029
|
+
{ className: cx("km-quota-metrics", row.quota?.stale === true && "km-quota-stale") },
|
|
2030
|
+
windows.map((window) => {
|
|
2031
|
+
const percent = quotaPercent(window.usedFraction);
|
|
2032
|
+
const label = QUOTA_WINDOW_LABEL[window.id];
|
|
2033
|
+
return h(
|
|
2034
|
+
"span",
|
|
2035
|
+
{ key: window.id, className: "km-quota-metric" },
|
|
2036
|
+
h("span", { className: "km-quota-window", "aria-hidden": true }, label),
|
|
2037
|
+
h("span", {
|
|
2038
|
+
className: "km-quota-track",
|
|
2039
|
+
role: "progressbar",
|
|
2040
|
+
"aria-valuemin": 0,
|
|
2041
|
+
"aria-valuemax": 100,
|
|
2042
|
+
"aria-valuenow": percent,
|
|
2043
|
+
"aria-label": t("quotaBarLabel", { window: label, percent })
|
|
2044
|
+
}, h("span", {
|
|
2045
|
+
className: cx("km-quota-fill", `km-quota-fill-${quotaTone(window.usedFraction)}`),
|
|
2046
|
+
style: { width: `${percent}%` }
|
|
2047
|
+
})),
|
|
2048
|
+
h("span", { className: "km-quota-pct" }, `${percent}%`)
|
|
2049
|
+
);
|
|
2050
|
+
}),
|
|
2051
|
+
h("span", { className: "km-quota-reset" }, durationText(tightest.resetsAt - now, t)),
|
|
2052
|
+
row.quota?.stale === true ? h("span", { className: "km-quota-flag" }, t("quotaStale")) : null
|
|
2053
|
+
)
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
function quotaSignature(provider) {
|
|
2057
|
+
return provider.keys.map((key) => `${key.id}:${key.quota?.status ?? "-"}:${key.quota?.fetchedAt ?? 0}`).join("|");
|
|
2058
|
+
}
|
|
2059
|
+
function QuotaStrip({ provider, now }) {
|
|
2060
|
+
const runtime = useRuntime();
|
|
2061
|
+
const t = useT();
|
|
2062
|
+
const [refreshing, setRefreshing] = import_react2.default.useState(false);
|
|
2063
|
+
const attempted = import_react2.default.useRef(null);
|
|
2064
|
+
const pending = import_react2.default.useRef(null);
|
|
2065
|
+
const retryBudget = import_react2.default.useRef(null);
|
|
2066
|
+
const retried = import_react2.default.useRef(null);
|
|
2067
|
+
const quotas = provider.keys.map((key) => key.quota);
|
|
2068
|
+
const needsRefresh = quotaNeedsRefresh(quotas, now);
|
|
2069
|
+
const minute = Math.floor(now / 6e4);
|
|
2070
|
+
const signature = quotaSignature(provider);
|
|
2071
|
+
import_react2.default.useEffect(() => {
|
|
2072
|
+
if (!needsRefresh) {
|
|
2073
|
+
attempted.current = null;
|
|
2074
|
+
retried.current = null;
|
|
2075
|
+
retryBudget.current = null;
|
|
2076
|
+
return void 0;
|
|
2077
|
+
}
|
|
2078
|
+
if (attempted.current === signature) return void 0;
|
|
2079
|
+
if (retried.current === signature) return void 0;
|
|
2080
|
+
attempted.current = signature;
|
|
2081
|
+
if (retryBudget.current === signature) {
|
|
2082
|
+
retried.current = signature;
|
|
2083
|
+
retryBudget.current = null;
|
|
2084
|
+
}
|
|
2085
|
+
setRefreshing(true);
|
|
2086
|
+
const request = runtime.store.refreshQuota(provider.provider);
|
|
2087
|
+
pending.current = request;
|
|
2088
|
+
void request.then((outcome) => {
|
|
2089
|
+
if (pending.current !== request) return;
|
|
2090
|
+
pending.current = null;
|
|
2091
|
+
setRefreshing(false);
|
|
2092
|
+
if (!outcome.ok) return;
|
|
2093
|
+
const latest = runtime.store.getSnapshot().state?.providers.find((row) => row.provider === provider.provider);
|
|
2094
|
+
const moved = latest === void 0 || quotaSignature(latest) !== signature;
|
|
2095
|
+
attempted.current = null;
|
|
2096
|
+
retryBudget.current = moved ? null : signature;
|
|
2097
|
+
});
|
|
2098
|
+
return void 0;
|
|
2099
|
+
}, [provider.provider, signature, minute, needsRefresh]);
|
|
2100
|
+
return h(
|
|
2101
|
+
"div",
|
|
2102
|
+
{ className: "km-quota-strip" },
|
|
2103
|
+
h(
|
|
2104
|
+
"div",
|
|
2105
|
+
{ className: "km-quota-head" },
|
|
2106
|
+
h("span", { className: "km-quota-title" }, t("quotaTitle")),
|
|
2107
|
+
refreshing ? h("span", { className: "km-quota-busy", role: "status" }, t("quotaRefreshing")) : null
|
|
2108
|
+
),
|
|
2109
|
+
h("ul", { className: "km-quota-list" }, provider.keys.map((key) => quotaRow(key, t, now)))
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
1911
2112
|
function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
1912
2113
|
const runtime = useRuntime();
|
|
1913
2114
|
const t = useT();
|
|
@@ -1979,6 +2180,7 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
1979
2180
|
}
|
|
1980
2181
|
await openLogin();
|
|
1981
2182
|
}
|
|
2183
|
+
const tightest = managed ? tightestQuotaWindow(provider.keys.map((key) => key.quota)) : void 0;
|
|
1982
2184
|
const accountAdoptable = oauthCapable(provider);
|
|
1983
2185
|
const adoptable = provider.supported || accountAdoptable;
|
|
1984
2186
|
const signInCreatesRoute = provider.extra === true && accountAdoptable;
|
|
@@ -2018,6 +2220,16 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2018
2220
|
h(
|
|
2019
2221
|
"span",
|
|
2020
2222
|
{ className: "km-provider-side" },
|
|
2223
|
+
// D5: the tightest plan window across this provider's accounts, as a
|
|
2224
|
+
// supplementary one-liner next to the key count. Narrow screens drop
|
|
2225
|
+
// it (the expanded strip is the primary carrier) instead of wrapping.
|
|
2226
|
+
tightest === void 0 ? null : h("span", {
|
|
2227
|
+
className: cx(
|
|
2228
|
+
"km-quota-compact",
|
|
2229
|
+
tightest.usedFraction >= 1 ? "km-quota-error" : tightest.usedFraction >= 0.9 ? "km-quota-warn" : null
|
|
2230
|
+
),
|
|
2231
|
+
title: t("quotaCompactHint")
|
|
2232
|
+
}, `${QUOTA_WINDOW_LABEL[tightest.id]} ${quotaPercent(tightest.usedFraction)}%`),
|
|
2021
2233
|
// I-000120 / D8: requests this route served without an attributed
|
|
2022
2234
|
// account. Rendered only above zero, and the visible label carries the
|
|
2023
2235
|
// count so it is the accessible name; the hint stays a description.
|
|
@@ -2073,7 +2285,9 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2073
2285
|
Button,
|
|
2074
2286
|
{ variant: "secondary", onClick: () => void adoptThenLogin(), disabled: adopting || startingLogin },
|
|
2075
2287
|
startingLogin ? h(Icon, { name: "refresh", size: 14, className: "km-spin" }) : h(Icon, { name: "user", size: 14 }),
|
|
2076
|
-
|
|
2288
|
+
// I-000263: this path signs in without adopting, so its
|
|
2289
|
+
// progress copy names the sign-in, not an adopt.
|
|
2290
|
+
h("span", null, startingLogin ? t("signingIn") : t("addAccount"))
|
|
2077
2291
|
)
|
|
2078
2292
|
) : null,
|
|
2079
2293
|
h(KeyForm, { provider, autoFocus: true })
|
|
@@ -2130,6 +2344,7 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2130
2344
|
)
|
|
2131
2345
|
),
|
|
2132
2346
|
adding ? h(KeyForm, { provider, onDone: () => setAdding(false), autoFocus: true }) : null,
|
|
2347
|
+
provider.keys.length > 0 ? h(QuotaStrip, { provider, now }) : null,
|
|
2133
2348
|
provider.keys.length === 0 ? h(
|
|
2134
2349
|
"div",
|
|
2135
2350
|
{ className: "km-empty-keys" },
|
package/lib/domain.d.ts
CHANGED
|
@@ -124,6 +124,25 @@ export interface StateDocument {
|
|
|
124
124
|
boundAt: number;
|
|
125
125
|
}>;
|
|
126
126
|
}
|
|
127
|
+
/** One plan window projected into an account row. */
|
|
128
|
+
export interface QuotaWindowView {
|
|
129
|
+
id: 'session' | 'week';
|
|
130
|
+
/** Share of the window already used, `0`..`1`. */
|
|
131
|
+
usedFraction: number;
|
|
132
|
+
/** Reset time as epoch milliseconds. */
|
|
133
|
+
resetsAt: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Latest quota snapshot of one account row. Runtime-only: never persisted, so
|
|
137
|
+
* it is deliberately absent from `KeyRecord` and `sanitizeState` (plan D1).
|
|
138
|
+
*/
|
|
139
|
+
export interface QuotaView {
|
|
140
|
+
status: 'ok' | 'absent' | 'unauthorized' | 'error';
|
|
141
|
+
fetchedAt: number;
|
|
142
|
+
/** True when the windows are last-good data served behind a failed probe. */
|
|
143
|
+
stale?: boolean;
|
|
144
|
+
windows: QuotaWindowView[];
|
|
145
|
+
}
|
|
127
146
|
/** Public key row returned to the UI (no credential reference or value). */
|
|
128
147
|
export interface KeyView {
|
|
129
148
|
id: string;
|
|
@@ -149,6 +168,8 @@ export interface KeyView {
|
|
|
149
168
|
* the provider-view `projectedAccountId` duplicate was removed.
|
|
150
169
|
*/
|
|
151
170
|
projected?: boolean;
|
|
171
|
+
/** Latest cached plan usage; absent until a quota refresh ran for this row. */
|
|
172
|
+
quota?: QuotaView;
|
|
152
173
|
}
|
|
153
174
|
/** Public provider row returned to the UI. */
|
|
154
175
|
export interface ProviderView {
|
|
@@ -240,12 +261,16 @@ export interface TransportModelsView {
|
|
|
240
261
|
catalog: TransportCatalogModel[];
|
|
241
262
|
models: string[];
|
|
242
263
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
264
|
+
* The installed transport build ships no catalog accessor for this route.
|
|
265
|
+
*
|
|
266
|
+
* A stable marker rather than host copy: the picker explains the empty list
|
|
267
|
+
* with its own localized string, so the wire carries only the fact. Set on
|
|
268
|
+
* every read whose accessor is missing, so a remounted or reloaded picker
|
|
269
|
+
* still explains the empty list; absent for every route that does ship a
|
|
270
|
+
* catalog. The one-shot part of this report is the {@link StateView.warnings}
|
|
271
|
+
* entry, not this field.
|
|
247
272
|
*/
|
|
248
|
-
|
|
273
|
+
missingCatalog?: boolean;
|
|
249
274
|
}
|
|
250
275
|
/** Complete manager snapshot the UI renders. */
|
|
251
276
|
export interface StateView {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AccountAttemptView, KeyTestResult, StateView, TransportModelsView } from './domain.js';
|
|
2
2
|
import type { CredentialsLike, GenerateOptionsLike, HostContext, KeySelection, RequestErrorAction, AgentRequestPayload, RequestErrorPayload, SettingsLike, StreamChunkLike } from './host-types.js';
|
|
3
|
+
import type { QuotaFetch } from './quota/fetch.js';
|
|
3
4
|
import { KeysManagerStore } from './store.js';
|
|
4
5
|
export declare const name = "keys-manager";
|
|
5
6
|
export declare const inject: string[];
|
|
@@ -365,6 +366,17 @@ export declare class KeysManagerService {
|
|
|
365
366
|
* channel.
|
|
366
367
|
*/
|
|
367
368
|
private readonly unattributedRequests;
|
|
369
|
+
/**
|
|
370
|
+
* Plan-usage snapshots per provider (issue #22, D1). In-memory only and
|
|
371
|
+
* never persisted: a restart loses them and the next card open re-probes.
|
|
372
|
+
* One cache per provider so single-flight and backoff are scoped to it.
|
|
373
|
+
*/
|
|
374
|
+
private readonly quotaCaches;
|
|
375
|
+
/**
|
|
376
|
+
* Test/embedding seam for the quota probes, mirroring `signInAdapter`.
|
|
377
|
+
* Production leaves it undefined and the probes use the platform `fetch`.
|
|
378
|
+
*/
|
|
379
|
+
quotaFetch: QuotaFetch | undefined;
|
|
368
380
|
/** Channels whose lost-subscription warning already fired (warn once). */
|
|
369
381
|
private readonly subscriptionLostWarnings;
|
|
370
382
|
/** Disposer for the `authorization/settled` subscription. */
|
|
@@ -770,13 +782,13 @@ export declare class KeysManagerService {
|
|
|
770
782
|
/** The route's removal epoch; absent means never removed. */
|
|
771
783
|
private transportGenerationOf;
|
|
772
784
|
/**
|
|
773
|
-
*
|
|
785
|
+
* Record that a registered transport flow has no catalog.
|
|
774
786
|
*
|
|
775
787
|
* An empty list is also the legitimate all-models state, so the only honest
|
|
776
|
-
* way to tell a stale transport build apart is to say so. The
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
788
|
+
* way to tell a stale transport build apart is to say so. The read answers a
|
|
789
|
+
* stable marker (never host copy — the picker owns the localized wording),
|
|
790
|
+
* while `catalogReports` keeps the human-readable state warning to one push
|
|
791
|
+
* per route.
|
|
780
792
|
*/
|
|
781
793
|
private reportMissingCatalog;
|
|
782
794
|
/**
|
|
@@ -1565,6 +1577,33 @@ export declare class KeysManagerService {
|
|
|
1565
1577
|
* start.
|
|
1566
1578
|
*/
|
|
1567
1579
|
getState(): StateView;
|
|
1580
|
+
/**
|
|
1581
|
+
* Remote: probe one provider's plan usage and answer the refreshed state.
|
|
1582
|
+
*
|
|
1583
|
+
* Pull-only (D2) and observation-only: a slow or failing vendor call can
|
|
1584
|
+
* change nothing but a row's `quota` field. Selection, cooldown, cursor,
|
|
1585
|
+
* sticky bindings and the durable document are untouched, and nothing is
|
|
1586
|
+
* written to disk.
|
|
1587
|
+
*/
|
|
1588
|
+
quotaRefresh(provider: string): Promise<StateView>;
|
|
1589
|
+
/** One provider's quota cache, created on first use. */
|
|
1590
|
+
private quotaCache;
|
|
1591
|
+
/**
|
|
1592
|
+
* Refresh one row, resolving its credential first. TTL, backoff and
|
|
1593
|
+
* single-flight live in the cache, so two concurrent refreshes of the same
|
|
1594
|
+
* row share one probe.
|
|
1595
|
+
*/
|
|
1596
|
+
private refreshQuotaRow;
|
|
1597
|
+
/** The credential one row's plan usage is read with, or undefined. */
|
|
1598
|
+
private quotaCredential;
|
|
1599
|
+
/** Project the cached quota of one row; a pure memory read, never a probe. */
|
|
1600
|
+
private quotaViewFor;
|
|
1601
|
+
/**
|
|
1602
|
+
* Build one provider view from a directory entry (live or the transports
|
|
1603
|
+
* package's static list, which unions the signed-out transport routes back
|
|
1604
|
+
* in). Extracted from `buildState` so both sources share one construction.
|
|
1605
|
+
*/
|
|
1606
|
+
private providerViewOf;
|
|
1568
1607
|
/** Find one directory entry by route id. */
|
|
1569
1608
|
private directoryEntry;
|
|
1570
1609
|
/**
|