dsh-magpie-connect 0.7.0 → 0.7.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/dsh.plugin.json +1 -1
- package/lib/client.js +14 -2
- package/lib/index.js +26 -7
- package/lib/index.js.map +2 -2
- package/lib/types/client/trace-format.d.ts +9 -0
- package/lib/types/trace-contract.d.ts +2 -0
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -158,8 +158,11 @@ var EN = {
|
|
|
158
158
|
"trace.candidate.used": "{n}% used",
|
|
159
159
|
"trace.candidate.amount": "{amount} / {limit} {unit}",
|
|
160
160
|
"trace.unit.credits": "credits",
|
|
161
|
+
"trace.unit.credits.total": "total credits",
|
|
161
162
|
"trace.unit.tokens": "tokens",
|
|
163
|
+
"trace.unit.tokens.total": "total tokens",
|
|
162
164
|
"trace.unit.requests": "requests",
|
|
165
|
+
"trace.unit.requests.total": "total requests",
|
|
163
166
|
"trace.webTraceMissing": "Save the Magpie Web Key for full routing-group detail.",
|
|
164
167
|
"trace.webTraceUnauthorized": "Magpie Web Key was refused; the simplified routing view remains.",
|
|
165
168
|
"trace.webTraceUnavailable": "Full routing-group detail is unavailable; showing the simplified view.",
|
|
@@ -303,8 +306,11 @@ var ZH = {
|
|
|
303
306
|
"trace.candidate.used": "\u5DF2\u7528 {n}%",
|
|
304
307
|
"trace.candidate.amount": "{amount} / {limit} {unit}",
|
|
305
308
|
"trace.unit.credits": "\u79EF\u5206",
|
|
309
|
+
"trace.unit.credits.total": "\u603B\u79EF\u5206",
|
|
306
310
|
"trace.unit.tokens": "tokens",
|
|
311
|
+
"trace.unit.tokens.total": "\u603B tokens",
|
|
307
312
|
"trace.unit.requests": "\u6B21",
|
|
313
|
+
"trace.unit.requests.total": "\u603B\u6B21\u6570",
|
|
308
314
|
"trace.webTraceMissing": "\u4FDD\u5B58 Magpie Web Key \u540E\u53EF\u663E\u793A\u5B8C\u6574\u8DEF\u7531\u7EC4\u8BE6\u60C5\u3002",
|
|
309
315
|
"trace.webTraceUnauthorized": "Magpie Web Key \u88AB\u62D2\u7EDD\uFF1B\u5F53\u524D\u663E\u793A\u7B80\u5316\u8DEF\u7531\u89C6\u56FE\u3002",
|
|
310
316
|
"trace.webTraceUnavailable": "\u5B8C\u6574\u8DEF\u7531\u7EC4\u8BE6\u60C5\u6682\u4E0D\u53EF\u7528\uFF1B\u5F53\u524D\u663E\u793A\u7B80\u5316\u89C6\u56FE\u3002",
|
|
@@ -775,7 +781,7 @@ function shouldRetryPending(snapshot2, attempts, limit = PENDING_RETRY_LIMIT) {
|
|
|
775
781
|
|
|
776
782
|
// src/client/page.tsx
|
|
777
783
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
778
|
-
var PLUGIN_VERSION = "0.
|
|
784
|
+
var PLUGIN_VERSION = "0.7.1";
|
|
779
785
|
var REPO_URL = "https://github.com/bitxeno/dsh-magpie-connect";
|
|
780
786
|
var css2 = {
|
|
781
787
|
section: { display: "flex", flexDirection: "column", gap: 16, maxWidth: 780, paddingBottom: 32 },
|
|
@@ -1282,6 +1288,10 @@ function resetParts(resetsAt, now = Date.now()) {
|
|
|
1282
1288
|
if (hours < 48) return { n: hours, unit: "h" };
|
|
1283
1289
|
return { n: Math.ceil(hours / 24), unit: "d" };
|
|
1284
1290
|
}
|
|
1291
|
+
function isTotalWindowName(windowName) {
|
|
1292
|
+
if (windowName === void 0) return false;
|
|
1293
|
+
return /^(grand\s+)?total\b/i.test(windowName.trim());
|
|
1294
|
+
}
|
|
1285
1295
|
function maskUser(user) {
|
|
1286
1296
|
if (user === void 0) return void 0;
|
|
1287
1297
|
const at = user.indexOf("@");
|
|
@@ -1899,7 +1909,9 @@ function candidateDetail(candidate) {
|
|
|
1899
1909
|
}
|
|
1900
1910
|
const amount = candidate.amount !== void 0 && Number.isFinite(candidate.amount) ? Math.round(candidate.amount * 100) / 100 : void 0;
|
|
1901
1911
|
const limit = candidate.limit !== void 0 && Number.isFinite(candidate.limit) ? Math.round(candidate.limit * 100) / 100 : void 0;
|
|
1902
|
-
const
|
|
1912
|
+
const windowName = candidate.windowName;
|
|
1913
|
+
const unitKey = candidate.unit !== void 0 && candidate.unit !== "" ? `trace.unit.${candidate.unit}` : "";
|
|
1914
|
+
const unit = isTotalWindowName(windowName) && unitKey !== "" && text(`${unitKey}.total`) !== `${unitKey}.total` ? text(`${unitKey}.total`) : unitKey !== "" && text(unitKey) !== unitKey ? text(unitKey) : candidate.unit ?? "";
|
|
1903
1915
|
const amountText = amount !== void 0 && limit !== void 0 ? text("trace.candidate.amount", { amount, limit, unit }).trim() : candidate.usedPct !== void 0 ? text("trace.candidate.used", { n: candidate.usedPct }) : "";
|
|
1904
1916
|
const renew = candidate.renews?.[0] !== void 0 ? resetParts(candidate.renews[0]) : void 0;
|
|
1905
1917
|
const resetText = renew !== void 0 ? text("trace.quotaReset", { d: formatDuration(renew, "reset") }) : "";
|
package/lib/index.js
CHANGED
|
@@ -1860,8 +1860,16 @@ function maskHolder(user) {
|
|
|
1860
1860
|
const head = user.slice(0, Math.max(1, Math.min(at, 4)));
|
|
1861
1861
|
return `${head}\u2026`;
|
|
1862
1862
|
}
|
|
1863
|
+
function isTotalWindow(entry) {
|
|
1864
|
+
return /^(grand\s+)?total\b/i.test((str(entry, "name") ?? "").trim());
|
|
1865
|
+
}
|
|
1866
|
+
function hasShare(entry) {
|
|
1867
|
+
return num(entry, "used") !== void 0 || pctOfParts(entry) !== void 0;
|
|
1868
|
+
}
|
|
1863
1869
|
function pickWindow(windows) {
|
|
1864
|
-
|
|
1870
|
+
const usable = windows.filter((entry) => entry.unlimited !== true && hasShare(entry));
|
|
1871
|
+
const counted = windows.filter((entry) => entry.unlimited !== true);
|
|
1872
|
+
return usable.find(isTotalWindow) ?? usable[0] ?? counted.find((entry) => str(entry, "resetsAt") !== void 0) ?? counted[0] ?? windows[0];
|
|
1865
1873
|
}
|
|
1866
1874
|
function toAccountRow(account) {
|
|
1867
1875
|
const provider = str(account, "name") ?? str(account, "provider");
|
|
@@ -1929,6 +1937,8 @@ function toTraceCandidate(entry, outcome, restOverride) {
|
|
|
1929
1937
|
const via = Array.isArray(entry.via) ? entry.via.filter((value) => typeof value === "string" && value !== "") : [];
|
|
1930
1938
|
const amount = num(entry, "amount");
|
|
1931
1939
|
const limit = num(entry, "limit");
|
|
1940
|
+
const partsPct = pctOfParts(entry);
|
|
1941
|
+
const usedPct = amount !== void 0 && limit !== void 0 && limit > 0 ? partsPct ?? pctOf(used) : pctOf(used);
|
|
1932
1942
|
const restRaw = restOverride ?? (entry.rest && typeof entry.rest === "object" ? entry.rest : void 0);
|
|
1933
1943
|
const status = num(entry, "status");
|
|
1934
1944
|
const ms = num(entry, "ms");
|
|
@@ -1944,10 +1954,11 @@ function toTraceCandidate(entry, outcome, restOverride) {
|
|
|
1944
1954
|
...str(entry, "model") !== void 0 ? { model: str(entry, "model") } : {},
|
|
1945
1955
|
...str(entry, "fixed") !== void 0 ? { fixed: str(entry, "fixed") } : {},
|
|
1946
1956
|
...via.length > 0 ? { via } : {},
|
|
1947
|
-
...
|
|
1957
|
+
...usedPct !== void 0 ? { usedPct } : {},
|
|
1948
1958
|
...amount !== void 0 ? { amount } : {},
|
|
1949
1959
|
...limit !== void 0 ? { limit } : {},
|
|
1950
1960
|
...str(entry, "unit") !== void 0 ? { unit: str(entry, "unit") } : {},
|
|
1961
|
+
...str(entry, "windowName") !== void 0 ? { windowName: str(entry, "windowName") } : {},
|
|
1951
1962
|
...renews.length > 0 ? { renews } : {},
|
|
1952
1963
|
...restRaw !== void 0 ? { rest: restRaw } : {},
|
|
1953
1964
|
outcome,
|
|
@@ -2016,12 +2027,20 @@ function toSessionTrace(route, accounts) {
|
|
|
2016
2027
|
const quota = accounts.find(
|
|
2017
2028
|
(account) => account.providerId === str(entry, "provider") && ((account.user ?? "").toLowerCase() === maskHolder(str(entry, "who"))?.toLowerCase() || account.user === void 0)
|
|
2018
2029
|
);
|
|
2030
|
+
const entryAmount = num(entry, "amount");
|
|
2031
|
+
const entryLimit = num(entry, "limit");
|
|
2032
|
+
const namesPickedWindow = quota?.windowName !== void 0 && (entryAmount === void 0 && entryLimit === void 0 || entryLimit !== void 0 && quota.limit !== void 0 && Math.abs(entryLimit - quota.limit) < 0.01);
|
|
2019
2033
|
const quotaEnrichment = {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
...quota?.
|
|
2034
|
+
// The trace row's own counters are what routing weighed, so they win;
|
|
2035
|
+
// the quota windows only fill what the row left out. Filling `used` from
|
|
2036
|
+
// one window while `amount`/`limit` came from another is exactly the
|
|
2037
|
+
// mismatch this guard prevents.
|
|
2038
|
+
...num(entry, "used") === void 0 && quota?.usedPct !== void 0 ? { used: quota.usedPct } : {},
|
|
2039
|
+
...entryAmount === void 0 && quota?.amount !== void 0 ? { amount: quota.amount } : {},
|
|
2040
|
+
...entryLimit === void 0 && quota?.limit !== void 0 ? { limit: quota.limit } : {},
|
|
2041
|
+
...str(entry, "unit") === void 0 && quota?.unit !== void 0 ? { unit: quota.unit } : {},
|
|
2042
|
+
...str(entry, "windowName") === void 0 && namesPickedWindow ? { windowName: quota.windowName } : {},
|
|
2043
|
+
...!Array.isArray(entry.renews) && quota?.resetsAt !== void 0 ? { renews: [quota.resetsAt] } : {}
|
|
2025
2044
|
};
|
|
2026
2045
|
const row = toTraceCandidate({ ...entry, ...quotaEnrichment }, kind, tried?.rest);
|
|
2027
2046
|
if (row === void 0) return void 0;
|