dsh-keys-manager 0.2.6 → 0.2.9
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 +52 -0
- package/README.md +219 -269
- package/README.zh-CN.md +142 -136
- package/lib/client/format.d.ts +27 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/types.d.ts +10 -2
- package/lib/client.js +155 -7
- package/lib/domain.d.ts +30 -5
- package/lib/index.d.ts +66 -5
- package/lib/index.js +295 -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 +60 -0
- package/lib/quota/model.js +62 -0
- package/lib/quota/model.js.map +1 -0
- package/lib/quota/providers.d.ts +89 -0
- package/lib/quota/providers.js +533 -0
- package/lib/quota/providers.js.map +1 -0
- package/locale/en.json +7 -1
- package/locale/zh.json +7 -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,17 @@ 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 key row (issue #22). The window abbreviations (5h / W)
|
|
232
|
+
// are technical and stay untranslated, so they are code, not dictionary
|
|
233
|
+
// entries; a pending, `absent` or `error` snapshot needs no copy at all.
|
|
234
|
+
// `natively-managed` does: it is the host saying a DSH projection serves
|
|
235
|
+
// the route while its usage stays unreadable, which is its own verdict.
|
|
236
|
+
quotaNativelyManaged: "\u7531 DSH \u539F\u751F\u7BA1\u7406",
|
|
237
|
+
quotaResetDue: "\u5DF2\u5230\u91CD\u7F6E\u65F6\u95F4",
|
|
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"
|
|
230
241
|
};
|
|
231
242
|
var en = {
|
|
232
243
|
nav: "Keys Manager",
|
|
@@ -260,6 +271,7 @@ var en = {
|
|
|
260
271
|
notConfigured: "not configured",
|
|
261
272
|
adopt: "Adopt provider",
|
|
262
273
|
adopting: "Adopting\u2026",
|
|
274
|
+
signingIn: "Signing in\u2026",
|
|
263
275
|
release: "Stop managing",
|
|
264
276
|
releasing: "Releasing\u2026",
|
|
265
277
|
addKey: "Add key",
|
|
@@ -412,7 +424,13 @@ var en = {
|
|
|
412
424
|
transportModelsLoading: "Loading models\u2026",
|
|
413
425
|
transportModelsClear: "Clear selection",
|
|
414
426
|
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."
|
|
427
|
+
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
|
+
// Plan usage on a key row (issue #22).
|
|
429
|
+
quotaNativelyManaged: "Managed by DSH",
|
|
430
|
+
quotaResetDue: "Reset due",
|
|
431
|
+
quotaSignInAgain: "Sign in again",
|
|
432
|
+
quotaStale: "Stale",
|
|
433
|
+
quotaCompactHint: "The tightest plan window across this provider's accounts; expand the card for every account."
|
|
416
434
|
};
|
|
417
435
|
var LOCALE_DICTS = { zh, en };
|
|
418
436
|
|
|
@@ -566,6 +584,10 @@ select.km-input{appearance:auto}
|
|
|
566
584
|
.km-notice-action{flex:0 0 auto}
|
|
567
585
|
.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
586
|
.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}
|
|
587
|
+
.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}
|
|
588
|
+
.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))}
|
|
589
|
+
.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))}
|
|
590
|
+
.km-quota-inline{grid-column:1/-1;margin-top:-2px;font-size:11px;line-height:1.3;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
569
591
|
.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
592
|
.km-settings{padding:14px}
|
|
571
593
|
.km-settings-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px}
|
|
@@ -622,6 +644,9 @@ select.km-input{appearance:auto}
|
|
|
622
644
|
.km-settings-grid{grid-template-columns:1fr}
|
|
623
645
|
.km-form-grid{grid-template-columns:1fr}
|
|
624
646
|
.km-provider-side .km-status{display:none}
|
|
647
|
+
/* Narrow cards drop the supplementary pill instead of wrapping; the muted
|
|
648
|
+
line on each account row stays the primary carrier. */
|
|
649
|
+
.km-provider-side .km-quota-compact{display:none}
|
|
625
650
|
.km-embedded-head{flex-direction:column;gap:10px}
|
|
626
651
|
.km-embedded-actions{padding-top:0}
|
|
627
652
|
}
|
|
@@ -704,13 +729,38 @@ function shapeTransportModels(value) {
|
|
|
704
729
|
}
|
|
705
730
|
}
|
|
706
731
|
const models = Array.isArray(record.models) ? record.models.filter((id) => typeof id === "string") : [];
|
|
707
|
-
|
|
708
|
-
return warning === void 0 ? { catalog, models } : { catalog, models, warning };
|
|
732
|
+
return record.missingCatalog === true ? { catalog, models, missingCatalog: true } : { catalog, models };
|
|
709
733
|
}
|
|
710
734
|
function modelPickerRows(view) {
|
|
711
735
|
const selected = new Set(view.models);
|
|
712
736
|
return view.catalog.map((row) => ({ id: row.id, name: row.name, selected: selected.has(row.id) }));
|
|
713
737
|
}
|
|
738
|
+
var QUOTA_TTL_MS = 375e3;
|
|
739
|
+
var QUOTA_WINDOW_LABEL = { session: "5h", week: "W" };
|
|
740
|
+
var QUOTA_WINDOW_ORDER = ["session", "week"];
|
|
741
|
+
function quotaPercent(fraction) {
|
|
742
|
+
return Math.min(100, Math.max(0, Math.round(fraction * 100)));
|
|
743
|
+
}
|
|
744
|
+
function quotaWindows(quota) {
|
|
745
|
+
if (quota === void 0 || quota.status !== "ok") return [];
|
|
746
|
+
return QUOTA_WINDOW_ORDER.map((id) => quota.windows.find((window) => window.id === id)).filter(
|
|
747
|
+
(window) => window !== void 0
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
function tightestQuotaWindow(quotas) {
|
|
751
|
+
let tightest;
|
|
752
|
+
for (const quota of quotas) {
|
|
753
|
+
for (const window of quotaWindows(quota)) {
|
|
754
|
+
if (tightest === void 0 || window.usedFraction > tightest.usedFraction) tightest = window;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return tightest;
|
|
758
|
+
}
|
|
759
|
+
function quotaNeedsRefresh(quotas, now) {
|
|
760
|
+
return quotas.some(
|
|
761
|
+
(quota) => quota === void 0 || quota.status === "ok" && now - quota.fetchedAt > QUOTA_TTL_MS
|
|
762
|
+
);
|
|
763
|
+
}
|
|
714
764
|
|
|
715
765
|
// src/client/store.ts
|
|
716
766
|
function messageOf(error) {
|
|
@@ -744,6 +794,7 @@ function createStore(ctx) {
|
|
|
744
794
|
let testGeneration = 0;
|
|
745
795
|
let mutationGeneration = 0;
|
|
746
796
|
let stateDropped = false;
|
|
797
|
+
const quotaInFlight = /* @__PURE__ */ new Map();
|
|
747
798
|
const listeners = /* @__PURE__ */ new Set();
|
|
748
799
|
const emit = () => {
|
|
749
800
|
for (const listener of [...listeners]) {
|
|
@@ -910,6 +961,33 @@ function createStore(ctx) {
|
|
|
910
961
|
if (!result.ok) return { ok: false, error: result.error.message };
|
|
911
962
|
return { ok: true, value: shapeTransportModels(result.value) };
|
|
912
963
|
},
|
|
964
|
+
refreshQuota(provider) {
|
|
965
|
+
const pending = quotaInFlight.get(provider);
|
|
966
|
+
if (pending !== void 0) return pending;
|
|
967
|
+
const generation = testGeneration;
|
|
968
|
+
let dropped = false;
|
|
969
|
+
const request = (async () => {
|
|
970
|
+
try {
|
|
971
|
+
const result = await rpc("quotaRefresh", { provider });
|
|
972
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
973
|
+
const state = result.value;
|
|
974
|
+
if (activeTests > 0 || testGeneration !== generation) {
|
|
975
|
+
stateDropped = true;
|
|
976
|
+
dropped = true;
|
|
977
|
+
} else {
|
|
978
|
+
update({ status: "ready", state, now: Date.now(), error: snapshot.error });
|
|
979
|
+
}
|
|
980
|
+
return { ok: true, value: state };
|
|
981
|
+
} catch (error) {
|
|
982
|
+
return { ok: false, error: messageOf(error) };
|
|
983
|
+
} finally {
|
|
984
|
+
quotaInFlight.delete(provider);
|
|
985
|
+
if (dropped) refreshDroppedState();
|
|
986
|
+
}
|
|
987
|
+
})();
|
|
988
|
+
quotaInFlight.set(provider, request);
|
|
989
|
+
return request;
|
|
990
|
+
},
|
|
913
991
|
saveTransportModels(route, models) {
|
|
914
992
|
return send("saveTransportModels", { provider: route, models }, modelsOutcome);
|
|
915
993
|
},
|
|
@@ -1503,6 +1581,7 @@ function KeyRow({ provider, keyRecord, now, onReauthenticate }) {
|
|
|
1503
1581
|
}, disabled: busy }, h(Icon, { name: "trash", size: 15 }), t("delete"))
|
|
1504
1582
|
) : null
|
|
1505
1583
|
),
|
|
1584
|
+
quotaInline(key, t, now),
|
|
1506
1585
|
error !== null ? h("div", { className: "km-key-error", role: "alert" }, error) : null,
|
|
1507
1586
|
testLine(test, t),
|
|
1508
1587
|
confirm ? h(Modal, {
|
|
@@ -1663,6 +1742,7 @@ function AccountRow({ provider, keyRecord, now, onReauthenticate }) {
|
|
|
1663
1742
|
}, disabled: busy }, h(Icon, { name: "trash", size: 15 }), t("delete"))
|
|
1664
1743
|
) : null
|
|
1665
1744
|
),
|
|
1745
|
+
quotaInline(keyRecord, t, now),
|
|
1666
1746
|
error !== null ? h("div", { className: "km-key-error", role: "alert" }, error) : null,
|
|
1667
1747
|
testLine(test, t),
|
|
1668
1748
|
confirm ? h(Modal, {
|
|
@@ -1839,7 +1919,7 @@ function TransportModels({ route }) {
|
|
|
1839
1919
|
}
|
|
1840
1920
|
const rows = view === null ? [] : modelPickerRows(view);
|
|
1841
1921
|
const emptyCatalog = view !== null && view.catalog.length === 0;
|
|
1842
|
-
const
|
|
1922
|
+
const missingCatalog = view !== null && view.missingCatalog === true;
|
|
1843
1923
|
const errorLine = error === null ? null : h("div", { className: "km-inline-error", role: "alert" }, error);
|
|
1844
1924
|
return h(
|
|
1845
1925
|
"div",
|
|
@@ -1886,7 +1966,7 @@ function TransportModels({ route }) {
|
|
|
1886
1966
|
))),
|
|
1887
1967
|
// An empty grid is also the all-models state: only the host's report of
|
|
1888
1968
|
// a missing catalog explains it.
|
|
1889
|
-
emptyCatalog &&
|
|
1969
|
+
emptyCatalog && missingCatalog ? h("div", { className: "km-field-hint", role: "status" }, t("transportModelsMissingCatalog")) : null,
|
|
1890
1970
|
h(
|
|
1891
1971
|
"div",
|
|
1892
1972
|
{ className: "km-models-actions" },
|
|
@@ -1908,6 +1988,60 @@ function TransportModels({ route }) {
|
|
|
1908
1988
|
) : null
|
|
1909
1989
|
);
|
|
1910
1990
|
}
|
|
1991
|
+
function quotaInline(row, t, now) {
|
|
1992
|
+
const windows = quotaWindows(row.quota);
|
|
1993
|
+
if (windows.length === 0) {
|
|
1994
|
+
if (row.quota?.status === "natively-managed") {
|
|
1995
|
+
return h("div", { className: "km-quota-inline" }, t("quotaNativelyManaged"));
|
|
1996
|
+
}
|
|
1997
|
+
return row.quota?.status === "unauthorized" && row.kind === "oauth" ? h("div", { className: "km-quota-inline" }, t("quotaSignInAgain")) : null;
|
|
1998
|
+
}
|
|
1999
|
+
const tightest = windows.reduce((best, window) => window.usedFraction > best.usedFraction ? window : best);
|
|
2000
|
+
const remainingMs = tightest.resetsAt - now;
|
|
2001
|
+
const parts = [
|
|
2002
|
+
...windows.map((window) => `${QUOTA_WINDOW_LABEL[window.id]} ${quotaPercent(window.usedFraction)}%`).reverse(),
|
|
2003
|
+
remainingMs > 0 ? durationText(remainingMs, t) : t("quotaResetDue")
|
|
2004
|
+
];
|
|
2005
|
+
if (row.quota?.stale === true) parts.push(t("quotaStale"));
|
|
2006
|
+
return h("div", { className: "km-quota-inline", title: parts.join(" \xB7 ") }, parts.join(" \xB7 "));
|
|
2007
|
+
}
|
|
2008
|
+
function quotaSignature(provider) {
|
|
2009
|
+
return provider.keys.map((key) => `${key.id}:${key.quota?.status ?? "-"}:${key.quota?.fetchedAt ?? 0}`).join("|");
|
|
2010
|
+
}
|
|
2011
|
+
function QuotaRefresh({ provider, now }) {
|
|
2012
|
+
const runtime = useRuntime();
|
|
2013
|
+
const attempted = import_react2.default.useRef(null);
|
|
2014
|
+
const retryBudget = import_react2.default.useRef(null);
|
|
2015
|
+
const retried = import_react2.default.useRef(null);
|
|
2016
|
+
const quotas = provider.keys.map((key) => key.quota);
|
|
2017
|
+
const needsRefresh = quotaNeedsRefresh(quotas, now);
|
|
2018
|
+
const minute = Math.floor(now / 6e4);
|
|
2019
|
+
const signature = quotaSignature(provider);
|
|
2020
|
+
import_react2.default.useEffect(() => {
|
|
2021
|
+
if (!needsRefresh) {
|
|
2022
|
+
attempted.current = null;
|
|
2023
|
+
retried.current = null;
|
|
2024
|
+
retryBudget.current = null;
|
|
2025
|
+
return void 0;
|
|
2026
|
+
}
|
|
2027
|
+
if (attempted.current === signature) return void 0;
|
|
2028
|
+
if (retried.current === signature) return void 0;
|
|
2029
|
+
attempted.current = signature;
|
|
2030
|
+
if (retryBudget.current === signature) {
|
|
2031
|
+
retried.current = signature;
|
|
2032
|
+
retryBudget.current = null;
|
|
2033
|
+
}
|
|
2034
|
+
void runtime.store.refreshQuota(provider.provider).then((outcome) => {
|
|
2035
|
+
if (!outcome.ok) return;
|
|
2036
|
+
const latest = runtime.store.getSnapshot().state?.providers.find((row) => row.provider === provider.provider);
|
|
2037
|
+
const moved = latest === void 0 || quotaSignature(latest) !== signature;
|
|
2038
|
+
attempted.current = null;
|
|
2039
|
+
retryBudget.current = moved ? null : signature;
|
|
2040
|
+
});
|
|
2041
|
+
return void 0;
|
|
2042
|
+
}, [provider.provider, signature, minute, needsRefresh]);
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
1911
2045
|
function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
1912
2046
|
const runtime = useRuntime();
|
|
1913
2047
|
const t = useT();
|
|
@@ -1979,6 +2113,7 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
1979
2113
|
}
|
|
1980
2114
|
await openLogin();
|
|
1981
2115
|
}
|
|
2116
|
+
const tightest = managed ? tightestQuotaWindow(provider.keys.map((key) => key.quota)) : void 0;
|
|
1982
2117
|
const accountAdoptable = oauthCapable(provider);
|
|
1983
2118
|
const adoptable = provider.supported || accountAdoptable;
|
|
1984
2119
|
const signInCreatesRoute = provider.extra === true && accountAdoptable;
|
|
@@ -2018,6 +2153,16 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2018
2153
|
h(
|
|
2019
2154
|
"span",
|
|
2020
2155
|
{ className: "km-provider-side" },
|
|
2156
|
+
// D5: the tightest plan window across this provider's accounts, as a
|
|
2157
|
+
// supplementary one-liner next to the key count. Narrow screens drop
|
|
2158
|
+
// it (the per-row usage line is the primary carrier) instead of wrapping.
|
|
2159
|
+
tightest === void 0 ? null : h("span", {
|
|
2160
|
+
className: cx(
|
|
2161
|
+
"km-quota-compact",
|
|
2162
|
+
tightest.usedFraction >= 1 ? "km-quota-error" : tightest.usedFraction >= 0.9 ? "km-quota-warn" : null
|
|
2163
|
+
),
|
|
2164
|
+
title: t("quotaCompactHint")
|
|
2165
|
+
}, `${QUOTA_WINDOW_LABEL[tightest.id]} ${quotaPercent(tightest.usedFraction)}%`),
|
|
2021
2166
|
// I-000120 / D8: requests this route served without an attributed
|
|
2022
2167
|
// account. Rendered only above zero, and the visible label carries the
|
|
2023
2168
|
// count so it is the accessible name; the hint stays a description.
|
|
@@ -2073,7 +2218,9 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2073
2218
|
Button,
|
|
2074
2219
|
{ variant: "secondary", onClick: () => void adoptThenLogin(), disabled: adopting || startingLogin },
|
|
2075
2220
|
startingLogin ? h(Icon, { name: "refresh", size: 14, className: "km-spin" }) : h(Icon, { name: "user", size: 14 }),
|
|
2076
|
-
|
|
2221
|
+
// I-000263: this path signs in without adopting, so its
|
|
2222
|
+
// progress copy names the sign-in, not an adopt.
|
|
2223
|
+
h("span", null, startingLogin ? t("signingIn") : t("addAccount"))
|
|
2077
2224
|
)
|
|
2078
2225
|
) : null,
|
|
2079
2226
|
h(KeyForm, { provider, autoFocus: true })
|
|
@@ -2130,6 +2277,7 @@ function ProviderCard({ provider, expanded, onToggle, now, transportAccount }) {
|
|
|
2130
2277
|
)
|
|
2131
2278
|
),
|
|
2132
2279
|
adding ? h(KeyForm, { provider, onDone: () => setAdding(false), autoFocus: true }) : null,
|
|
2280
|
+
provider.keys.length > 0 ? h(QuotaRefresh, { provider, now }) : null,
|
|
2133
2281
|
provider.keys.length === 0 ? h(
|
|
2134
2282
|
"div",
|
|
2135
2283
|
{ 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' | 'natively-managed';
|
|
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,55 @@ 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
|
+
/**
|
|
1598
|
+
* The credential one row's plan usage is read with.
|
|
1599
|
+
*
|
|
1600
|
+
* For an OAuth row the pool copy wins; when it is unreadable the projection
|
|
1601
|
+
* record (`llm-pi-ai/<provider>`) is consulted, because that grant — not the
|
|
1602
|
+
* pool row — is what actually serves the route. Reading is the only thing
|
|
1603
|
+
* this does: no write, no rebind, no `modifyRecord`.
|
|
1604
|
+
*/
|
|
1605
|
+
private quotaCredential;
|
|
1606
|
+
/**
|
|
1607
|
+
* A readable pool grant for one row, `undefined` when no usable record exists,
|
|
1608
|
+
* or `unreadable` when the read itself failed. The distinction matters: only
|
|
1609
|
+
* a foreign route may fall back to the projection after a failed read.
|
|
1610
|
+
*/
|
|
1611
|
+
private readGrantCredential;
|
|
1612
|
+
/**
|
|
1613
|
+
* The provider's live projection as a quota credential.
|
|
1614
|
+
*
|
|
1615
|
+
* A record that exists but cannot be read (wrong kind, unrecognized payload)
|
|
1616
|
+
* or a read that throws is classified `natively-managed`, never `missing`: we
|
|
1617
|
+
* cannot prove no account serves the route, and claiming otherwise is exactly
|
|
1618
|
+
* the false "sign in again" this plan removes.
|
|
1619
|
+
*/
|
|
1620
|
+
private projectionQuotaCredential;
|
|
1621
|
+
/** Project the cached quota of one row; a pure memory read, never a probe. */
|
|
1622
|
+
private quotaViewFor;
|
|
1623
|
+
/**
|
|
1624
|
+
* Build one provider view from a directory entry (live or the transports
|
|
1625
|
+
* package's static list, which unions the signed-out transport routes back
|
|
1626
|
+
* in). Extracted from `buildState` so both sources share one construction.
|
|
1627
|
+
*/
|
|
1628
|
+
private providerViewOf;
|
|
1568
1629
|
/** Find one directory entry by route id. */
|
|
1569
1630
|
private directoryEntry;
|
|
1570
1631
|
/**
|