fix: review fixes, GitHub Releases update check (0.1.1)
- Wallet/subscription/window exhaustion skips a key for 10 minutes instead of disabling it; a balance read showing money brings it back. Only the gateway's own key refusals and a used-up key cap still disable a key. - Classify by sub2api's exact wording; a bare 401 or upstream text no longer retires a key; 'No available accounts' is capacity, not coverage. - Hosts keep only an https origin (no doubled /v1); timeouts and HTTP answers no longer set a host aside; hand edits are re-probed. - Balance: inactive subscriptions, per-plan subscription pooling, key caps kept out of the total, rate windows shown. - Endpoint editor no longer empties itself after Save. - Update check reads GitHub Releases and installs the release tarball; release workflow replaces npm publishing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
86b8e4d24f
commit
f4f4ce55b3
34 files changed
+953
-521
No files matched your search
+90
-29
@@ -46,12 +46,14 @@ window.__ModuleLoader__.load({
|
||||
totalLimit: "合计额度",
|
||||
totalPartial: "有 {count} 个 Key 未读到余额,未计入合计。",
|
||||
totalStale: "其中 {count} 个 Key 本次读取失败,显示的是上次读到的余额。",
|
||||
totalShared: "{count} 个 Key 与其他 Key 共用同一个钱包,只计一次。",
|
||||
totalShared: "{count} 个 Key 与其他 Key 共用同一个钱包或订阅,只计一次。",
|
||||
totalCapped: "{count} 个 Key 设有自己的限额,它们花的是账户钱包,限额不计入合计。",
|
||||
staleNote: "上次读取于 {time},本次读取失败:{error}",
|
||||
empty: "还没有 Key。添加一个即可在模型选择器里看到 Geek2API 的模型。",
|
||||
keysHint: "按顺序使用:当前 Key 不可用时自动切到下一个;「切到此 Key」指定优先使用的 Key。",
|
||||
keyActive: "使用中",
|
||||
keyDisabled: "已停用",
|
||||
keySkipped: "余额不足,暂时跳过",
|
||||
keyUse: "切到此 Key",
|
||||
keyEnable: "重新启用",
|
||||
keyRemove: "删除",
|
||||
@@ -69,7 +71,10 @@ window.__ModuleLoader__.load({
|
||||
keyToday: "今日",
|
||||
planWallet: "钱包余额(同账户的 Key 共用)",
|
||||
planSubscription: "订阅:{name}",
|
||||
planQuota: "Key 限额",
|
||||
planQuota: "Key 限额(从账户钱包扣费)",
|
||||
planSubscriptionInactive: "订阅:{name}(未开通或已过期)",
|
||||
keyCapRemaining: "Key 剩余限额",
|
||||
keyWindow: "{window} 窗口 {used}/{limit}",
|
||||
keyExpires: "{date} 到期",
|
||||
resetMonthly: "每月重置",
|
||||
resetWeekly: "每周重置",
|
||||
@@ -80,7 +85,7 @@ window.__ModuleLoader__.load({
|
||||
addKeyPlaceholder: "粘贴 API Key",
|
||||
addLabelPlaceholder: "备注(可选)",
|
||||
add: "添加",
|
||||
notWritable: "当前 profile 不允许写入设置,改动只在本次运行内生效。",
|
||||
notWritable: "当前 profile 不允许写入设置,这些选项暂时不能修改。",
|
||||
error: "读取 Geek2API 状态失败",
|
||||
groupsTitle: "分组",
|
||||
groupsExtra: "另有 {count} 个模型不在内置列表中",
|
||||
@@ -108,7 +113,7 @@ window.__ModuleLoader__.load({
|
||||
hostsCooling: "暂时跳过",
|
||||
hostsUnprobed: "未测速",
|
||||
hostsEdit: "编辑地址列表",
|
||||
hostsEditHint: "每行一个地址,按优先顺序排列。留空则恢复默认列表。",
|
||||
hostsEditHint: "每行一个地址(只取域名部分,必须是 https),按优先顺序排列。要恢复内置列表请点「恢复默认」。",
|
||||
hostsSave: "保存",
|
||||
hostsReset: "恢复默认",
|
||||
composerLabel: "Geek2API 剩余额度",
|
||||
@@ -152,7 +157,8 @@ window.__ModuleLoader__.load({
|
||||
versionUpToDate: "已是最新版本",
|
||||
versionAvailable: "发现新版本 v{version}",
|
||||
versionLinked: "当前是本地开发安装,请在插件仓库拉取代码并重新构建。",
|
||||
versionManual: "无法在这里更新。请在桌面应用的插件页重新安装 dsh-geek2api。",
|
||||
versionManual: "无法在这里自动更新。请到 GitHub Releases 下载新版本,在桌面应用的插件页重新安装。",
|
||||
versionNotes: "更新说明",
|
||||
versionUpdate: "更新插件",
|
||||
versionUpdating: "正在更新…",
|
||||
versionUpdateFailed: "更新失败,请重试,或在插件页重新安装。",
|
||||
@@ -208,12 +214,14 @@ window.__ModuleLoader__.load({
|
||||
totalLimit: "Total limit",
|
||||
totalPartial: "{count} key(s) could not be read and are not counted here.",
|
||||
totalStale: "{count} of these keys failed this read and show their last read balance.",
|
||||
totalShared: "{count} key(s) share a wallet with another key and are counted once.",
|
||||
totalShared: "{count} key(s) share a wallet or subscription with another key and are counted once.",
|
||||
totalCapped: "{count} key(s) have their own cap; they spend the account wallet, so caps are not added to the total.",
|
||||
staleNote: "Last read at {time}; this read failed: {error}",
|
||||
empty: "No keys yet. Add one and the Geek2API models appear in the model picker.",
|
||||
keysHint: "Used in order: when the active key cannot serve a request, the next one takes over. “Use this key” picks the preferred key.",
|
||||
keyActive: "Active",
|
||||
keyDisabled: "Disabled",
|
||||
keySkipped: "Out of balance, skipped for now",
|
||||
keyUse: "Use this key",
|
||||
keyEnable: "Re-enable",
|
||||
keyRemove: "Remove",
|
||||
@@ -231,7 +239,10 @@ window.__ModuleLoader__.load({
|
||||
keyToday: "Today",
|
||||
planWallet: "Wallet (shared by the account’s keys)",
|
||||
planSubscription: "Subscription: {name}",
|
||||
planQuota: "Key quota",
|
||||
planQuota: "Key quota (spends the account wallet)",
|
||||
planSubscriptionInactive: "Subscription: {name} (not active)",
|
||||
keyCapRemaining: "Cap left",
|
||||
keyWindow: "{window} window {used}/{limit}",
|
||||
keyExpires: "expires {date}",
|
||||
resetMonthly: "resets monthly",
|
||||
resetWeekly: "resets weekly",
|
||||
@@ -242,7 +253,7 @@ window.__ModuleLoader__.load({
|
||||
addKeyPlaceholder: "Paste API key",
|
||||
addLabelPlaceholder: "Label (optional)",
|
||||
add: "Add",
|
||||
notWritable: "This profile does not allow settings writes; changes apply to this run only.",
|
||||
notWritable: "This profile does not allow settings writes; these options cannot be changed here.",
|
||||
error: "Could not read Geek2API status",
|
||||
groupsTitle: "Groups",
|
||||
groupsExtra: "{count} more model(s) outside the built-in list",
|
||||
@@ -262,7 +273,7 @@ window.__ModuleLoader__.load({
|
||||
hostsCooling: "skipped for now",
|
||||
hostsUnprobed: "not measured",
|
||||
hostsEdit: "Edit endpoint list",
|
||||
hostsEditHint: "One endpoint per line, in order of preference. Leave empty to restore the defaults.",
|
||||
hostsEditHint: "One endpoint per line (origin only, https), in order of preference. Use Restore defaults to go back to the built-in list.",
|
||||
hostsSave: "Save",
|
||||
hostsReset: "Restore defaults",
|
||||
composerLabel: "Geek2API remaining balance",
|
||||
@@ -306,7 +317,8 @@ window.__ModuleLoader__.load({
|
||||
versionUpToDate: "Up to date",
|
||||
versionAvailable: "v{version} is available",
|
||||
versionLinked: "Installed from a local checkout. Pull and rebuild the plugin repository instead.",
|
||||
versionManual: "This install cannot be updated here. Reinstall dsh-geek2api from the desktop Plugins page.",
|
||||
versionManual: "This install cannot update itself. Download the new version from GitHub Releases and reinstall it from the Plugins page.",
|
||||
versionNotes: "Release notes",
|
||||
versionUpdate: "Update plugin",
|
||||
versionUpdating: "Updating…",
|
||||
versionUpdateFailed: "The update failed. Try again, or reinstall from the Plugins page.",
|
||||
@@ -381,6 +393,8 @@ window.__ModuleLoader__.load({
|
||||
.pkc-input:focus{border-color:var(--dsw-alias-state-business-primary)}
|
||||
.pkc-input::placeholder{color:var(--dsw-alias-label-caption)}
|
||||
.pkc-input:disabled{opacity:.5}
|
||||
.pkc-link{color:var(--dsw-alias-state-business-primary);font-size:12px;text-decoration:none}
|
||||
.pkc-link:hover{text-decoration:underline}
|
||||
.pkc-textarea{display:block;width:100%;height:auto;min-height:96px;padding:8px 10px;line-height:1.6;resize:vertical;white-space:pre;overflow-x:auto}
|
||||
.pkc-form{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
|
||||
|
||||
@@ -464,17 +478,21 @@ window.__ModuleLoader__.load({
|
||||
/**
|
||||
* Totals across the keys a balance read returned.
|
||||
*
|
||||
* Keys of one Geek2API account spend the same wallet, so a wallet is counted
|
||||
* once however many of its keys are stored. Two wallet rows are the same
|
||||
* wallet when the gateway names the same account (`accountRef`) or, when it
|
||||
* names none, when they report the same balance to the micro-dollar. Key
|
||||
* quotas and subscriptions are the key's own and add up.
|
||||
* In sub2api money belongs to the account, not the key:
|
||||
* - every wallet key of one account spends the same wallet, counted once —
|
||||
* the same wallet when the gateway names the same account (`accountRef`)
|
||||
* or, when it names none, when the balances agree to the micro-dollar;
|
||||
* - a subscription belongs to the user and its group, so keys on the same
|
||||
* plan count it once;
|
||||
* - a key quota is a cap on top of the wallet, not money of its own, so it
|
||||
* is left out of the sums and reported as `capped`.
|
||||
*
|
||||
* @module dsh-geek2api/totals
|
||||
*/
|
||||
const amount = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
||||
/** Which pool of money a row draws on; rows with the same pool count once. */
|
||||
function poolOf(row, usage) {
|
||||
if (usage.mode === "subscription") return `subscription:${usage.planName ?? row?.id}`;
|
||||
if (usage.mode !== "wallet") return `key:${row?.id}`;
|
||||
if (typeof usage.accountRef === "string") return `account:${usage.accountRef}`;
|
||||
const remaining = amount(usage.availableUsd);
|
||||
@@ -484,8 +502,8 @@ window.__ModuleLoader__.load({
|
||||
* Add up the balance rows the host returned.
|
||||
* @param rows - the `keys` array of a balance projection.
|
||||
* @returns summed amounts plus the conditions that make a sum incomplete:
|
||||
* keys whose read failed, keys with no limit at all, and how many wallet
|
||||
* rows were folded into a wallet already counted.
|
||||
* keys whose read failed, keys with no limit at all, rows folded into a
|
||||
* pool already counted, and key caps left out of the sum.
|
||||
*/
|
||||
function sumBalances(rows) {
|
||||
const total = {
|
||||
@@ -494,6 +512,7 @@ window.__ModuleLoader__.load({
|
||||
unread: 0,
|
||||
unlimited: 0,
|
||||
shared: 0,
|
||||
capped: 0,
|
||||
remainingUsd: 0,
|
||||
usedUsd: 0,
|
||||
limitUsd: 0
|
||||
@@ -507,6 +526,10 @@ window.__ModuleLoader__.load({
|
||||
continue;
|
||||
}
|
||||
total.counted += 1;
|
||||
if (usage.mode === "quota") {
|
||||
total.capped += 1;
|
||||
continue;
|
||||
}
|
||||
const pool = poolOf(row, usage);
|
||||
if (seen.has(pool)) {
|
||||
total.shared += 1;
|
||||
@@ -619,6 +642,7 @@ window.__ModuleLoader__.load({
|
||||
/** What a key draws on: the shared wallet, a subscription plan, or its own quota. */
|
||||
function planLabel(usage, t) {
|
||||
if (usage?.mode === "wallet") return t("planWallet");
|
||||
if (usage?.mode === "subscription" && usage.inactive === true) return fill(t("planSubscriptionInactive"), { name: usage.planName ?? "" });
|
||||
if (usage?.mode === "subscription") return fill(t("planSubscription"), { name: usage.planName ?? "" });
|
||||
if (usage?.mode === "quota") return t("planQuota");
|
||||
}
|
||||
@@ -735,11 +759,12 @@ window.__ModuleLoader__.load({
|
||||
})
|
||||
] });
|
||||
}
|
||||
function KeyRow({ entry, row, group, descriptions, groupsLoading, busy, renaming, onRename, onAction, t }) {
|
||||
function KeyRow({ entry, row, group, descriptions, groupsLoading, busy, renaming, onRename, onAction, skippedUntil, t }) {
|
||||
const usage = row?.usage;
|
||||
const share = remainingShare(usage);
|
||||
const remainingLabel = usage?.mode === "quota" ? t("keyCapRemaining") : t("keyRemaining");
|
||||
const figures = [
|
||||
usage?.unlimitedQuota === true ? [t("keyRemaining"), t("keyUnlimited")] : usage?.availableUsd === void 0 ? void 0 : [t("keyRemaining"), formatUsd(usage.availableUsd)],
|
||||
usage?.unlimitedQuota === true ? [remainingLabel, t("keyUnlimited")] : usage?.availableUsd === void 0 ? void 0 : [remainingLabel, formatUsd(usage.availableUsd)],
|
||||
usage?.usedUsd === void 0 ? void 0 : [t("keyUsed"), formatUsd(usage.usedUsd)],
|
||||
usage?.limitUsd === void 0 ? void 0 : [t("accountLimit"), formatUsd(usage.limitUsd)]
|
||||
].filter(Boolean);
|
||||
@@ -748,7 +773,12 @@ window.__ModuleLoader__.load({
|
||||
usage?.keyName === void 0 ? void 0 : `${t("keyName")} ${usage.keyName}`,
|
||||
resetLabel(usage?.resetPeriod, t),
|
||||
usage?.todayUsd === void 0 ? void 0 : `${t("keyToday")} ${formatUsd(usage.todayUsd)}`,
|
||||
usage?.expiresAt === void 0 ? void 0 : fill(t("keyExpires"), { date: new Date(usage.expiresAt).toLocaleDateString() })
|
||||
usage?.expiresAt === void 0 ? void 0 : fill(t("keyExpires"), { date: new Date(usage.expiresAt).toLocaleDateString() }),
|
||||
...Array.isArray(usage?.rateLimits) ? usage.rateLimits.map((window) => fill(t("keyWindow"), {
|
||||
window: window.window,
|
||||
used: formatUsd(window.usedUsd) ?? "?",
|
||||
limit: formatUsd(window.limitUsd) ?? "?"
|
||||
})) : []
|
||||
].filter(Boolean).join(" · ");
|
||||
const editing = renaming?.id === entry.id;
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||
@@ -797,6 +827,11 @@ window.__ModuleLoader__.load({
|
||||
"data-tone": "success",
|
||||
children: t("keyActive")
|
||||
}),
|
||||
!entry.disabled && skippedUntil !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
||||
className: "pkc-chip",
|
||||
"data-tone": "warn",
|
||||
children: t("keySkipped")
|
||||
}),
|
||||
entry.disabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
||||
className: "pkc-chip",
|
||||
"data-tone": "danger",
|
||||
@@ -999,10 +1034,11 @@ window.__ModuleLoader__.load({
|
||||
})
|
||||
]
|
||||
}),
|
||||
(totals.unread > 0 || staleCount > 0 || totals.shared > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
(totals.unread > 0 || staleCount > 0 || totals.shared > 0 || totals.capped > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
className: "pkc-note",
|
||||
children: [
|
||||
totals.shared > 0 ? fill(t("totalShared"), { count: totals.shared }) : void 0,
|
||||
totals.capped > 0 ? fill(t("totalCapped"), { count: totals.capped }) : void 0,
|
||||
totals.unread > 0 ? fill(t("totalPartial"), { count: totals.unread }) : void 0,
|
||||
staleCount > 0 ? fill(t("totalStale"), { count: staleCount }) : void 0
|
||||
].filter(Boolean).join(" ")
|
||||
@@ -1019,6 +1055,7 @@ window.__ModuleLoader__.load({
|
||||
renaming,
|
||||
onRename: rename,
|
||||
onAction: mutate,
|
||||
skippedUntil: status?.skipped?.[entry.id],
|
||||
t
|
||||
}, entry.id))
|
||||
}),
|
||||
@@ -1085,16 +1122,33 @@ window.__ModuleLoader__.load({
|
||||
const [busy, setBusy] = react.useState(false);
|
||||
const [error, setError] = react.useState();
|
||||
const [draft, setDraft] = react.useState();
|
||||
const [editing, setEditing] = react.useState(false);
|
||||
const run = react.useCallback((endpoint, payload) => {
|
||||
setBusy(true);
|
||||
setError(void 0);
|
||||
return call(endpoint, payload).then(setStatus).catch((failure) => setError(clearMessage(failure))).finally(() => setBusy(false));
|
||||
return call(endpoint, payload).then((next) => {
|
||||
setStatus(next);
|
||||
return next;
|
||||
}).catch((failure) => {
|
||||
setError(clearMessage(failure));
|
||||
}).finally(() => setBusy(false));
|
||||
}, [call]);
|
||||
react.useEffect(() => {
|
||||
run("hosts/probe", {});
|
||||
}, [run]);
|
||||
const hosts = Array.isArray(status?.hosts) ? status.hosts : [];
|
||||
const save = (list) => run("hosts/update", { apiHosts: list }).then(() => setDraft(void 0));
|
||||
const listText = (list) => Array.isArray(list) ? list.map((entry) => entry.host).join("\n") : "";
|
||||
react.useEffect(() => {
|
||||
if (editing && draft === void 0 && hosts.length > 0) setDraft(listText(hosts));
|
||||
}, [
|
||||
editing,
|
||||
draft,
|
||||
hosts
|
||||
]);
|
||||
const save = (list) => run("hosts/update", { apiHosts: list }).then((next) => {
|
||||
if (next !== void 0) setDraft(listText(next.hosts));
|
||||
});
|
||||
const draftHosts = (draft ?? "").split(/\s+/u).filter(Boolean);
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Card, {
|
||||
title: t("hostsTitle"),
|
||||
aside: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
||||
@@ -1127,14 +1181,14 @@ window.__ModuleLoader__.load({
|
||||
}),
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
||||
className: "pkc-meta",
|
||||
children: entry.coolingUntil !== void 0 ? t("hostsCooling") : entry.latencyMs !== void 0 ? `${entry.latencyMs} ms` : t("hostsDown")
|
||||
children: entry.coolingUntil !== void 0 ? t("hostsCooling") : entry.latencyMs !== void 0 ? `${entry.latencyMs} ms` : entry.probed === false ? t("hostsUnprobed") : t("hostsDown")
|
||||
})
|
||||
]
|
||||
}, entry.host))
|
||||
}),
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
||||
className: "pkc-advanced",
|
||||
onToggle: (event) => event.currentTarget.open && draft === void 0 && setDraft(hosts.map((entry) => entry.host).join("\n")),
|
||||
onToggle: (event) => setEditing(event.currentTarget.open),
|
||||
children: [
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t("hostsEdit") }),
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
@@ -1152,8 +1206,8 @@ window.__ModuleLoader__.load({
|
||||
className: "pkc-split",
|
||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
||||
variant: "primary",
|
||||
disabled: status?.writable !== true || busy,
|
||||
onClick: () => save((draft ?? "").split(/\s+/u).filter(Boolean)),
|
||||
disabled: status?.writable !== true || busy || draftHosts.length === 0,
|
||||
onClick: () => save(draftHosts),
|
||||
children: t("hostsSave")
|
||||
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
||||
variant: "ghost",
|
||||
@@ -1657,7 +1711,7 @@ window.__ModuleLoader__.load({
|
||||
};
|
||||
const installKind = info?.install?.kind;
|
||||
const showStatus = info !== void 0 && updated === void 0;
|
||||
const canUpdate = showStatus && info.updateAvailable && installKind === "npm";
|
||||
const canUpdate = showStatus && info.updateAvailable && (info.updatable === true || info.updatable === void 0 && installKind === "npm");
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Card, {
|
||||
title: t("versionTitle"),
|
||||
aside: updated === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
||||
@@ -1696,6 +1750,13 @@ window.__ModuleLoader__.load({
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
||||
className: "pkc-meta",
|
||||
children: [info.updateAvailable ? fill(t("versionAvailable"), { version: info.latest }) : t("versionUpToDate"), info.updateAvailable && ` · ${t("versionLatest")} v${info.latest}`]
|
||||
}),
|
||||
info.releaseUrl !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
||||
className: "pkc-link",
|
||||
href: info.releaseUrl,
|
||||
target: "_blank",
|
||||
rel: "noreferrer noopener",
|
||||
children: t("versionNotes")
|
||||
})
|
||||
]
|
||||
}),
|
||||
@@ -1703,7 +1764,7 @@ window.__ModuleLoader__.load({
|
||||
className: "pkc-note",
|
||||
children: t("versionLinked")
|
||||
}),
|
||||
showStatus && info.updateAvailable && installKind === "unknown" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
showStatus && info.updateAvailable && !canUpdate && installKind !== "link" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
className: "pkc-note",
|
||||
children: t("versionManual")
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user