@dougen/dsh-deepseek-usage 0.3.1 → 0.3.2

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/README.md CHANGED
@@ -11,7 +11,7 @@ DeepSeek 用量侧边栏插件(DeepSeek Harness Web UI)
11
11
  ## 功能
12
12
 
13
13
  - **余额**:`¥ 110.00` 大字显示(符号随账号币种自动切换:人民币 `¥` / 美元 `$`)
14
- - **档单价**:`→|1.5 ⚡0.05 |→4.5`(输入 / 输入缓存 / 输出,位于卡片右下角;随当前启用模型与峰谷时段自动切换)
14
+ - **档单价**:`→|1.5 ⚡0.05 |→4.5`(输入 / 输入缓存 / 输出,位于卡片右下角;随当前启用模型与峰谷时段自动切换,**切换模型时立即同步**)
15
15
  - **峰谷指示灯**:卡片右上角,高峰(9:00–12:00、14:00–18:00 北京时间)橙色,空闲绿色
16
16
  - **自动刷新**:每 5 分钟一次;点击卡片任意位置立即刷新
17
17
  - 跟随应用明暗主题
package/lib/client.js CHANGED
@@ -71,6 +71,7 @@ window.__ModuleLoader__.load({
71
71
 
72
72
  // ---- the widget -------------------------------------------------
73
73
  function UsageCell(props) {
74
+ const ctx = props.ctx;
74
75
  const wide = !!props.wide;
75
76
  const [data, setData] = useState(null);
76
77
  const [error, setError] = useState("");
@@ -99,11 +100,25 @@ window.__ModuleLoader__.load({
99
100
  mounted.current = true;
100
101
  load();
101
102
  const timer = setInterval(load, POLL_MS);
103
+ // 模型切换(写入 settings 触发 document-updated)时立即刷新,价格同步。
104
+ let off = null;
105
+ try {
106
+ if (ctx && ctx.remote && typeof ctx.remote.$on === "function") {
107
+ off = ctx.remote.$on("settings/document-updated", () => {
108
+ try { load(); } catch (e) { /* 忽略刷新错误 */ }
109
+ });
110
+ }
111
+ } catch (e) {
112
+ off = null;
113
+ }
102
114
  return () => {
103
115
  mounted.current = false;
104
116
  clearInterval(timer);
117
+ try {
118
+ if (typeof off === "function") off();
119
+ } catch (e) { /* 忽略退订错误 */ }
105
120
  };
106
- }, [load]);
121
+ }, [load, ctx]);
107
122
 
108
123
  const balance = data && data.balance ? data.balance : null;
109
124
  const tier = data && data.tier ? data.tier : null;
@@ -194,7 +209,7 @@ window.__ModuleLoader__.load({
194
209
  }
195
210
 
196
211
  // ---- client plugin body -----------------------------------------
197
- const inject = ["slots"];
212
+ const inject = ["slots", "remote"];
198
213
 
199
214
  function apply(ctx) {
200
215
  // 注入本包样式:footerActions 换行(卡片独占一行)。
@@ -208,7 +223,7 @@ window.__ModuleLoader__.load({
208
223
  }
209
224
  ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register(
210
225
  { name: "sidebar.footer.action", id: "dsh-usage", order: 100, label: "DeepSeek 用量" },
211
- (props) => h(UsageCell, { wide: props.wide }),
226
+ (props) => h(UsageCell, { wide: props.wide, ctx }),
212
227
  ));
213
228
  }
214
229
 
package/lib/index.js CHANGED
@@ -93,6 +93,16 @@ function apply(ctx) {
93
93
  return sendJson(res, 403, { ok: false, error: "forbidden", message: "仅允许本机访问" });
94
94
  }
95
95
 
96
+ // ---- 当前模型当前档单价(展示用)----
97
+ const now = Date.now();
98
+ let model = DEFAULT_MODEL;
99
+ try {
100
+ const adm = ctx.get("agentDefaultModel");
101
+ const selection = adm && typeof adm.currentSelection === "function" ? adm.currentSelection() : void 0;
102
+ if (selection && typeof selection.model === "string") model = selection.model;
103
+ } catch {}
104
+ const unit = unitAt(model, now);
105
+
96
106
  const errors = [];
97
107
 
98
108
  // ---- 余额(官方接口,API Key)----
@@ -124,15 +134,7 @@ function apply(ctx) {
124
134
  errors.push(`余额获取失败: ${error instanceof Error ? error.message : String(error)}`);
125
135
  }
126
136
 
127
- // ---- 当前模型当前档单价 + 峰谷(展示用)----
128
- const now = Date.now();
129
- let model = DEFAULT_MODEL;
130
- try {
131
- const adm = ctx.get("agentDefaultModel");
132
- const selection = adm && typeof adm.currentSelection === "function" ? adm.currentSelection() : void 0;
133
- if (selection && typeof selection.model === "string") model = selection.model;
134
- } catch {}
135
- const unit = unitAt(model, now);
137
+ // ---- 档单价提示(未知模型回退 chat 档)----
136
138
  if (!unit.known) errors.push(`当前模型 ${model} 不在价格表,档单价按 deepseek-chat 展示`);
137
139
 
138
140
  sendJson(res, 200, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dougen/dsh-deepseek-usage",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "DeepSeek 用量侧边栏插件:余额(官方 API)、当前档单价与峰谷时段指示灯。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",