dsh-sidebar-usage 1.0.1 → 1.0.3
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/lib/client.js +98 -2
- package/lib/index.js +9 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1683,11 +1683,18 @@ window.__ModuleLoader__.load({
|
|
|
1683
1683
|
return "";
|
|
1684
1684
|
}
|
|
1685
1685
|
}
|
|
1686
|
+
/** 看板与设置页共用的「当前看的是哪家」变更事件。 */
|
|
1687
|
+
const PRESET_EVENT = "dsh-usage:preset-provider-changed";
|
|
1686
1688
|
function writePresetProvider(id) {
|
|
1689
|
+
const next = typeof id === "string" && id !== "" ? id : "";
|
|
1687
1690
|
try {
|
|
1688
|
-
if (
|
|
1691
|
+
if (next !== "") window.localStorage.setItem(PRESET_PROVIDER_KEY, next);
|
|
1689
1692
|
else window.localStorage.removeItem(PRESET_PROVIDER_KEY);
|
|
1690
1693
|
} catch (e) { /* 隐私模式写不进去:本次会话内仍然生效,只是刷新后回到跟随模型 */ }
|
|
1694
|
+
// 同一个页面里的看板与设置页都要跟着变:localStorage 的 storage 事件不派发给自己。
|
|
1695
|
+
try {
|
|
1696
|
+
window.dispatchEvent(new CustomEvent(PRESET_EVENT, { detail: { provider: next } }));
|
|
1697
|
+
} catch (e) { /* 老环境没有 CustomEvent:至少 localStorage 已写入 */ }
|
|
1691
1698
|
}
|
|
1692
1699
|
|
|
1693
1700
|
/**
|
|
@@ -2054,7 +2061,7 @@ window.__ModuleLoader__.load({
|
|
|
2054
2061
|
"status.peak": "高峰时段",
|
|
2055
2062
|
"status.idle": "空闲时段",
|
|
2056
2063
|
"status.error": "余额读取失败",
|
|
2057
|
-
"status.unavailable": "
|
|
2064
|
+
"status.unavailable": "该提供商不支持查询(可在设置页配接口)",
|
|
2058
2065
|
"status.mapAction": "去映射",
|
|
2059
2066
|
"card.label": "账户用量,点击刷新",
|
|
2060
2067
|
"sidebar.label": "账户用量",
|
|
@@ -2069,6 +2076,9 @@ window.__ModuleLoader__.load({
|
|
|
2069
2076
|
"settings.intro": "已添加的提供商会显示在侧栏看板的右键菜单里。这里只管理账户:映射本插件已支持的提供商,或用自定义 URL 接入中转站、自建网关。",
|
|
2070
2077
|
"providers.title": "模型提供商",
|
|
2071
2078
|
"providers.intro": "每项只占一行摘要:点「编辑」展开改配置,点「删除」移除。",
|
|
2079
|
+
"providers.watching": "看板显示这一家(单选)",
|
|
2080
|
+
"providers.watchingFollow": "跟随当前模型(不指定)",
|
|
2081
|
+
"providers.watchingGone": "这一项配置里已经没有了,看板会回落",
|
|
2072
2082
|
"providers.empty": "还没有添加提供商。侧栏看板只会显示这里已添加的项,用下面的按钮添加。",
|
|
2073
2083
|
"providers.edit": "编辑",
|
|
2074
2084
|
"providers.cancel": "收起",
|
|
@@ -2247,6 +2257,9 @@ window.__ModuleLoader__.load({
|
|
|
2247
2257
|
"settings.intro": "Added providers show up in the sidebar card's right-click menu. This page only manages accounts: map a provider this plugin already supports, or connect a relay / self-hosted gateway by custom URL.",
|
|
2248
2258
|
"providers.title": "Model providers",
|
|
2249
2259
|
"providers.intro": "Each provider takes one summary row: click Edit to change it, Remove to delete it.",
|
|
2260
|
+
"providers.watching": "Show this provider on the card (single choice)",
|
|
2261
|
+
"providers.watchingFollow": "Follow the current model (unspecified)",
|
|
2262
|
+
"providers.watchingGone": "This provider is no longer configured; the card falls back",
|
|
2250
2263
|
"providers.empty": "No providers yet. The sidebar card lists only what is added here — use the buttons below.",
|
|
2251
2264
|
"providers.edit": "Edit",
|
|
2252
2265
|
"providers.cancel": "Collapse",
|
|
@@ -2925,6 +2938,16 @@ window.__ModuleLoader__.load({
|
|
|
2925
2938
|
const presetRef = useRef(preset);
|
|
2926
2939
|
presetRef.current = preset;
|
|
2927
2940
|
|
|
2941
|
+
// 设置页里切了服务商 → 看板立刻跟着切(反之亦然)。
|
|
2942
|
+
useEffect(() => {
|
|
2943
|
+
const onPreset = (event) => {
|
|
2944
|
+
const next = event && event.detail && typeof event.detail.provider === "string" ? event.detail.provider : readPresetProvider();
|
|
2945
|
+
if (next !== presetRef.current) setPreset(next);
|
|
2946
|
+
};
|
|
2947
|
+
window.addEventListener(PRESET_EVENT, onPreset);
|
|
2948
|
+
return () => window.removeEventListener(PRESET_EVENT, onPreset);
|
|
2949
|
+
}, []);
|
|
2950
|
+
|
|
2928
2951
|
// loadRef 让下面两个回调可以互相引用而不必谁先声明。
|
|
2929
2952
|
const loadRef = useRef(null);
|
|
2930
2953
|
|
|
@@ -3718,6 +3741,10 @@ menu !== null && h(ProviderMenu, {
|
|
|
3718
3741
|
}, windowBadge(w.key)));
|
|
3719
3742
|
}));
|
|
3720
3743
|
|
|
3744
|
+
// 走到这里说明还没有任何读数:要么接口报错(blanked 分支已在上面返回红卡),
|
|
3745
|
+
// 要么根本没配好(无 provider / 无密钥)。画一张空卡只会显示 "undefined",
|
|
3746
|
+
// 所以直接返回 null;但**失败卡已覆盖了全部错误路径**,用户仍能右键切走。
|
|
3747
|
+
|
|
3721
3748
|
return h("div", {
|
|
3722
3749
|
// 侧栏 dock 插件(dsh-sidebar-dock)靠这个标记认出"这是用量看板",
|
|
3723
3750
|
// 好把它排成横跨三格;没有 dock 插件时这个属性没有任何副作用。
|
|
@@ -4019,6 +4046,48 @@ menu !== null && h(ProviderMenu, {
|
|
|
4019
4046
|
Price(h(IconIn, null), tier.input),
|
|
4020
4047
|
Price(h(IconCache, null), tier.cacheRead),
|
|
4021
4048
|
Price(h(IconOut, null), tier.output))));
|
|
4049
|
+
|
|
4050
|
+
// 兜底:真的什么都没有(首次加载慢、或宿主没给 provider)时也给一张薄卡,
|
|
4051
|
+
// 避免侧栏那一格突然消失、用户找不到入口。点一下就重试。
|
|
4052
|
+
if (!hasReading && usageRows.length === 0) {
|
|
4053
|
+
return h("div", {
|
|
4054
|
+
"data-dock": "usage",
|
|
4055
|
+
onContextMenu: openMenu,
|
|
4056
|
+
role: "button",
|
|
4057
|
+
tabIndex: 0,
|
|
4058
|
+
"aria-label": t("card.label"),
|
|
4059
|
+
title: errs.length > 0 ? errs.join("\n") : t("status.unavailable"),
|
|
4060
|
+
onClick: onCardClick,
|
|
4061
|
+
style: {
|
|
4062
|
+
position: "relative",
|
|
4063
|
+
boxSizing: "border-box",
|
|
4064
|
+
flex: "0 0 auto",
|
|
4065
|
+
width: "calc(100% - 7px)",
|
|
4066
|
+
marginLeft: 7,
|
|
4067
|
+
minHeight: CARD_MIN_HEIGHT,
|
|
4068
|
+
padding: "8px 10px",
|
|
4069
|
+
borderRadius: 10,
|
|
4070
|
+
border: "0.5px solid " + C.cardBorder,
|
|
4071
|
+
background: C.bg,
|
|
4072
|
+
color: C.err,
|
|
4073
|
+
display: "flex",
|
|
4074
|
+
alignItems: "center",
|
|
4075
|
+
fontSize: 12,
|
|
4076
|
+
lineHeight: "16px",
|
|
4077
|
+
cursor: "pointer",
|
|
4078
|
+
userSelect: "none",
|
|
4079
|
+
},
|
|
4080
|
+
},
|
|
4081
|
+
errs.length > 0 ? errs.join(" | ") : t("status.unavailable"),
|
|
4082
|
+
menu !== null && h(ProviderMenu, {
|
|
4083
|
+
menu,
|
|
4084
|
+
t,
|
|
4085
|
+
current: preset !== "" ? preset : (data && typeof data.provider === "string" ? data.provider : ""),
|
|
4086
|
+
onChoose: chooseProvider,
|
|
4087
|
+
onEdit: editProvider,
|
|
4088
|
+
onClose: closeMenu,
|
|
4089
|
+
}));
|
|
4090
|
+
}
|
|
4022
4091
|
}
|
|
4023
4092
|
|
|
4024
4093
|
// ---- 设置页:OAuth 订阅令牌 --------------------------------------
|
|
@@ -4316,6 +4385,18 @@ menu !== null && h(ProviderMenu, {
|
|
|
4316
4385
|
const [saving, setSaving] = useState(false);
|
|
4317
4386
|
const mountedRef = useRef(true);
|
|
4318
4387
|
const focusId = useProviderFocus();
|
|
4388
|
+
// 看板当前显示的是哪一家(localStorage 里的选择,和卡片右键菜单同一份)。
|
|
4389
|
+
// 设置页必须能看见它:不然"看板没数字"时用户不知道卡片到底在查谁。
|
|
4390
|
+
const [watching, setWatching] = useState(() => readPresetProvider());
|
|
4391
|
+
useEffect(() => {
|
|
4392
|
+
const onPreset = () => setWatching(readPresetProvider());
|
|
4393
|
+
window.addEventListener(PRESET_EVENT, onPreset);
|
|
4394
|
+
window.addEventListener("storage", onPreset);
|
|
4395
|
+
return () => {
|
|
4396
|
+
window.removeEventListener(PRESET_EVENT, onPreset);
|
|
4397
|
+
window.removeEventListener("storage", onPreset);
|
|
4398
|
+
};
|
|
4399
|
+
}, []);
|
|
4319
4400
|
|
|
4320
4401
|
useEffect(() => () => { mountedRef.current = false; }, []);
|
|
4321
4402
|
|
|
@@ -4737,6 +4818,21 @@ menu !== null && h(ProviderMenu, {
|
|
|
4737
4818
|
style: { ...rowStyleOf(rowStyle, provider, open ? provider : focusId), display: "flex", flexDirection: "column", gap: 8 },
|
|
4738
4819
|
},
|
|
4739
4820
|
h("div", { style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0, flexWrap: "wrap" } },
|
|
4821
|
+
// 勾选=看板在看这一家。单选语义:勾一个,其他自动取消。
|
|
4822
|
+
// 与看板右键菜单共用 writePresetProvider,双向同步。
|
|
4823
|
+
h("input", {
|
|
4824
|
+
type: "radio",
|
|
4825
|
+
name: "dsh-usage-watching",
|
|
4826
|
+
checked: watching === provider,
|
|
4827
|
+
disabled: disabled || provider === "",
|
|
4828
|
+
title: t("providers.watching"),
|
|
4829
|
+
"aria-label": t("providers.watching"),
|
|
4830
|
+
onChange: () => {
|
|
4831
|
+
setWatching(provider);
|
|
4832
|
+
writePresetProvider(provider);
|
|
4833
|
+
},
|
|
4834
|
+
style: { margin: 0, flex: "none", cursor: disabled ? "default" : "pointer" },
|
|
4835
|
+
}),
|
|
4740
4836
|
h("span", { style: { fontSize: 12, fontWeight: 600 } }, provider === "" ? t("alias.providerRequired") : provider),
|
|
4741
4837
|
h("span", { style: { ...mutedStyle, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, summaryOf(type, row)),
|
|
4742
4838
|
h("span", { style: { marginLeft: "auto", display: "flex", gap: 6, flex: "none" } },
|
package/lib/index.js
CHANGED
|
@@ -130,7 +130,9 @@ function buildConfig(z) {
|
|
|
130
130
|
provider: z.string().required(),
|
|
131
131
|
baseUrl: z.string().required(),
|
|
132
132
|
label: z.string(),
|
|
133
|
-
kind
|
|
133
|
+
// 容错:`kind` 写错不该让整条插件配置校验失败(那会把看板整个弄没)。
|
|
134
|
+
// 认不出的值在 custom.js 里已经回落成 balance,这里只要放行不认识的字符串。
|
|
135
|
+
kind: z.string(),
|
|
134
136
|
preset: z.union(CUSTOM_PRESETS.map((id) => z.const(id))),
|
|
135
137
|
path: z.string(),
|
|
136
138
|
usagePath: z.string(),
|
|
@@ -1209,6 +1211,12 @@ function apply(ctx, config = {}) {
|
|
|
1209
1211
|
if (typeof relayBase !== "string" || relayBase === "") {
|
|
1210
1212
|
return { ok: false, reason: "not-custom" };
|
|
1211
1213
|
}
|
|
1214
|
+
// 第二道闸:refresh cookie 只属于 asnia 那家中转。当前 provider 不是它时,
|
|
1215
|
+
// 拿同一枚 cookie 去别人的域名换 token 只会 404/401(实测 jc-asnia 就是
|
|
1216
|
+
// `refresh-failed:http-404`),所以按域名放行。
|
|
1217
|
+
if (!/hzfzlz/i.test(relayBase)) {
|
|
1218
|
+
return { ok: false, reason: "not-relay" };
|
|
1219
|
+
}
|
|
1212
1220
|
// 顺序反过来了:先直读 `.credentials.yaml`(实测拿到的就是站点 token 原文),
|
|
1213
1221
|
// credentials.resolve() 作回退——它返回的标量可能带引号/空白,会被站点判 401。
|
|
1214
1222
|
let secret = await readRefFromYaml("ASNIA_REFRESH_COOKIE");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sidebar-usage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Sidebar usage HUD for DeepSeek Harness: provider balance / subscription quota, cumulative tokens & calls, drag-to-resize card, hover-out drawer that collects bottom-bar entries.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|