dsh-sidebar-usage 1.0.2 → 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 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 (typeof id === "string" && id !== "") window.localStorage.setItem(PRESET_PROVIDER_KEY, id);
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
  /**
@@ -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
 
@@ -4362,6 +4385,18 @@ menu !== null && h(ProviderMenu, {
4362
4385
  const [saving, setSaving] = useState(false);
4363
4386
  const mountedRef = useRef(true);
4364
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
+ }, []);
4365
4400
 
4366
4401
  useEffect(() => () => { mountedRef.current = false; }, []);
4367
4402
 
@@ -4783,6 +4818,21 @@ menu !== null && h(ProviderMenu, {
4783
4818
  style: { ...rowStyleOf(rowStyle, provider, open ? provider : focusId), display: "flex", flexDirection: "column", gap: 8 },
4784
4819
  },
4785
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
+ }),
4786
4836
  h("span", { style: { fontSize: 12, fontWeight: 600 } }, provider === "" ? t("alias.providerRequired") : provider),
4787
4837
  h("span", { style: { ...mutedStyle, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, summaryOf(type, row)),
4788
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: z.union(CUSTOM_KINDS.map((id) => z.const(id))),
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(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sidebar-usage",
3
- "version": "1.0.2",
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",