dsh-sidebar-usage 1.0.3 → 1.0.4

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
@@ -2133,6 +2133,7 @@ window.__ModuleLoader__.load({
2133
2133
  "custom.preset": "接口类型",
2134
2134
  "custom.preset.json": "通用 JSON(自己填路径)",
2135
2135
  "custom.preset.jichuanai": "济川AI(订阅/余额)",
2136
+ "custom.preset.newapi-account": "new-api 账号接口(余额+已用)",
2136
2137
  "custom.preset.newapi": "new-api / one-api 中转",
2137
2138
  "custom.preset.openaiBilling": "OpenAI 计费接口",
2138
2139
  "custom.preset.deepseek": "DeepSeek /user/balance",
@@ -2314,6 +2315,7 @@ window.__ModuleLoader__.load({
2314
2315
  "custom.preset": "Endpoint type",
2315
2316
  "custom.preset.json": "Generic JSON (paths in YAML)",
2316
2317
  "custom.preset.jichuanai": "JichuanAI (subscription/balance)",
2318
+ "custom.preset.newapi-account": "new-api account API (balance + used)",
2317
2319
  "custom.preset.newapi": "new-api / one-api relay",
2318
2320
  "custom.preset.openaiBilling": "OpenAI billing API",
2319
2321
  "custom.preset.deepseek": "DeepSeek /user/balance",
@@ -4324,7 +4326,7 @@ menu !== null && h(ProviderMenu, {
4324
4326
  // ---- 设置页:模型提供商账户 --------------------------------------
4325
4327
  // 已保存的项只占一行摘要(provider + 查询口径),点「编辑」才展开表单;
4326
4328
  // 新增与编辑共用同一入口,页面里不再并排两套列表 —— 控件少一半。
4327
- const CUSTOM_PRESET_OPTIONS = ["newapi", "openai-billing", "deepseek-balance", "jichuanai", "json"];
4329
+ const CUSTOM_PRESET_OPTIONS = ["newapi", "newapi-account", "openai-billing", "deepseek-balance", "jichuanai", "json"];
4328
4330
  const CUSTOM_KIND_OPTIONS = ["balance", "usage"];
4329
4331
  const presetLabelKey = (id) => (id === "openai-billing"
4330
4332
  ? "custom.preset.openaiBilling"
package/lib/custom.js CHANGED
@@ -27,7 +27,7 @@ const REF_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
27
27
 
28
28
  export const CUSTOM_KINDS = ['balance', 'usage'];
29
29
  export const CUSTOM_AUTHS = ['bearer', 'raw', 'none'];
30
- export const CUSTOM_PRESETS = ['json', 'deepseek-balance', 'openai-billing', 'newapi', 'jichuanai'];
30
+ export const CUSTOM_PRESETS = ['json', 'deepseek-balance', 'openai-billing', 'newapi', 'newapi-account', 'jichuanai'];
31
31
 
32
32
  /**
33
33
  * 预设默认值。`path` 是主请求,`usagePath` 是第二段请求(可选)。
@@ -49,6 +49,17 @@ const PRESET_DEFAULTS = {
49
49
  currency: 'CNY',
50
50
  scale: 1,
51
51
  },
52
+ // new-api 账号接口:GET /api/user/self → data.quota(剩余额度)/ data.used_quota(已用)
53
+ // 换算率每家不同(1 元 = 500000 配额是 new-api 默认),由 currency/scale 决定怎么显示。
54
+ // availablePath 用 data.status:status 为 1 表示账号可用,0 表示被禁用。
55
+ 'newapi-account': {
56
+ path: '/api/user/self',
57
+ totalPath: 'data.quota',
58
+ usedPath: 'data.used_quota',
59
+ availablePath: 'data.status',
60
+ currency: 'CNY',
61
+ scale: 1 / 500000,
62
+ },
52
63
  // 济川AI(jc.jichuanai.com):实测 GET /api/v1/subscriptions →
53
64
  // data[0].group.weekly_limit_usd(额度)/ weekly_usage_usd(已用)/ expires_at(到期)
54
65
  // 余额口径:GET /api/v1/user/profile → data.balance
@@ -73,6 +84,11 @@ function text(value) {
73
84
  return typeof value === 'string' ? value.trim() : '';
74
85
  }
75
86
 
87
+ /** 同 text(),但 undefined/null 也给空串以外的东西不炸:专供预设默认值。 */
88
+ function orEmpty(value) {
89
+ return typeof value === 'string' ? value : '';
90
+ }
91
+
76
92
  /** 接受字符串或数字,返回有限数或 null(绝不把缺失变成 0)。 */
77
93
  function num(value) {
78
94
  if (typeof value === 'number') return Number.isFinite(value) ? value : null;
@@ -105,7 +121,8 @@ function normalizeBaseUrl(raw) {
105
121
  /** 路径:缺省用预设值;必须以 / 开头。 */
106
122
  function normalizePath(raw, fallback) {
107
123
  const value = text(raw);
108
- const path = value === '' ? fallback : value;
124
+ const fb = typeof fallback === 'string' ? fallback : '';
125
+ const path = value === '' ? fb : value;
109
126
  if (path === '') return '';
110
127
  return path.startsWith('/') ? path : `/${path}`;
111
128
  }
@@ -225,7 +242,10 @@ export function normalizeCustomProviders(raw) {
225
242
  const subUsedPath = text(item.usedPath) || (defaults.usedPath ?? '');
226
243
  const subExpiresPath = text(item.expiresPath) || (defaults.expiresPath ?? '');
227
244
  const pickedTotal = useSubscription ? subTotalPath : (balanceTotalPath !== '' ? balanceTotalPath : subTotalPath);
228
- const pickedUsed = useSubscription ? subUsedPath : '';
245
+ // 余额形态也要认 usedPath:new-api 账号接口同时给"剩余 quota"和"已用 used_quota",
246
+ // 有了两段才能算出百分比条;订阅形态才需要到期时间。
247
+ const balUsedPath = text(item.balanceUsedPath) || (defaults.usedPath ?? '');
248
+ const pickedUsed = useSubscription ? subUsedPath : balUsedPath;
229
249
  const pickedExpires = useSubscription ? subExpiresPath : '';
230
250
  if (pickedPath === '') {
231
251
  warnings.push(`忽略自定义 provider ${provider}:path / balancePath 至少要给一个`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sidebar-usage",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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",