dsh-cost-meter 1.9.74 → 1.9.75

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
@@ -3,7 +3,7 @@
3
3
  <p align="center">Cost tracking and subscription quotas for DeepSeek Harness</p>
4
4
 
5
5
  <p align="center">
6
- <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.74-4176E6?style=flat-square" alt="version"></a>
6
+ <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.75-4176E6?style=flat-square" alt="version"></a>
7
7
  <a href="https://www.npmjs.com/package/dsh-cost-meter"><img src="https://img.shields.io/npm/dm/dsh-cost-meter?label=downloads&style=flat-square&color=4176E6" alt="npm monthly downloads"></a>
8
8
  <a href="https://github.com/Han-1413141/dsh-cost-meter/stargazers"><img src="https://img.shields.io/github/stars/Han-1413141/dsh-cost-meter?label=stars&style=flat-square&color=D9A400" alt="GitHub stars"></a>
9
9
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT license"></a>
@@ -42,20 +42,20 @@ Restart `dsh web` after installation or updates. **Desktop** uses its bundled CL
42
42
  The PowerShell installer checks pnpm and Git and uses the `web` profile by default:
43
43
 
44
44
  ```powershell
45
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.74/install.ps1 | iex
45
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.75/install.ps1 | iex
46
46
  ```
47
47
 
48
48
  Install a pinned Git tag:
49
49
 
50
50
  ```sh
51
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.74
51
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.75
52
52
  ```
53
53
 
54
54
  See [installation and updates](docs/install.en.md) for uninstalling or installing without Git.
55
55
 
56
56
  </details>
57
57
 
58
- Current release **v1.9.74**: [release notes](docs/update-notes-1.9.74.md#english) · [troubleshooting](docs/install-troubleshooting.md)
58
+ Current release **v1.9.75**: [release notes](docs/release-notes/v1.9.75.md) · [troubleshooting](docs/install-troubleshooting.md)
59
59
 
60
60
  ## Feature overview
61
61
 
package/README.zh-CN.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <p align="center">DeepSeek Harness 费用统计与订阅额度插件</p>
4
4
 
5
5
  <p align="center">
6
- <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.74-4176E6?style=flat-square" alt="version"></a>
6
+ <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.75-4176E6?style=flat-square" alt="version"></a>
7
7
  <a href="https://www.npmjs.com/package/dsh-cost-meter"><img src="https://img.shields.io/npm/dm/dsh-cost-meter?label=downloads&style=flat-square&color=4176E6" alt="npm monthly downloads"></a>
8
8
  <a href="https://github.com/Han-1413141/dsh-cost-meter/stargazers"><img src="https://img.shields.io/github/stars/Han-1413141/dsh-cost-meter?label=stars&style=flat-square&color=D9A400" alt="GitHub stars"></a>
9
9
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT license"></a>
@@ -42,20 +42,20 @@ dsh plugin --profile web add dsh-cost-meter
42
42
  PowerShell 脚本自动检查 pnpm 和 Git,默认安装到 `web` Profile:
43
43
 
44
44
  ```powershell
45
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.74/install.ps1 | iex
45
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.75/install.ps1 | iex
46
46
  ```
47
47
 
48
48
  固定 Git tag 安装:
49
49
 
50
50
  ```sh
51
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.74
51
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.75
52
52
  ```
53
53
 
54
54
  更新、卸载及无 Git 的安装方法见[安装说明](docs/install.md)。
55
55
 
56
56
  </details>
57
57
 
58
- 当前版本 **v1.9.74**:[更新说明](docs/update-notes-1.9.74.md#中文) · [安装排障](docs/install-troubleshooting.md)
58
+ 当前版本 **v1.9.75**:[更新说明](docs/release-notes/v1.9.75.md) · [安装排障](docs/install-troubleshooting.md)
59
59
 
60
60
  ## 功能总览
61
61
 
@@ -30,6 +30,8 @@ The global exchange rate converts **USD to the display currency**. CNY/EUR sourc
30
30
 
31
31
  For Qianwen / Alibaba Cloud fund accounts, use **Add Qianwen / Alibaba Cloud balance** to query available funds with a RAM AccessKey signature. The card uses the currency returned by the API. See the [setup, permissions and balance definition](qianwen-balance.md#english).
32
32
 
33
+ **Cash coupons.** The card totals fund-account availability and active, same-currency coupons eligible for general or Model Studio pay-as-you-go use. It uses each coupon’s remaining `Balance`. The card identifies incomplete or unavailable coupon data. Grant `bss:DescribeBillingAccount` for the fund account and `bss:DescribeCoupons` for coupon lookup. Alibaba Cloud determines the actual deduction at billing time.
34
+
33
35
  Qwen Token Plan can use the [official CLI subscription quota](qwen-cli-quota.md#english). Install the CLI on the DSH host and run `qianwen auth login` as the same OS user. Local estimates remain the default; CLI mode shows current account credits without changing the local ledger.
34
36
 
35
37
  Local Qwen Token Plan credits include Plan calls assigned to Qwen. Existing subscription aliases such as `qwen` and `qwen-tokenplan` remain supported; custom providers can select Qwen under Model statistics → Billing class, or use an explicit vendor name and plan marker for auto detection. Explicit API calls are excluded. The pay-as-you-go `qianwen` provider is not assigned merely because its model ID is identical. Models outside the credits table need all three rates configured.
@@ -28,6 +28,8 @@
28
28
 
29
29
  千问 / 阿里云资金账户余额可直接点击「添加千问 / 阿里云余额」,使用 RAM AccessKey 签名查询,显示接口返回的可用金与币种;配置步骤、所需权限及口径见[千问余额说明](qianwen-balance.md)。
30
30
 
31
+ **代金券。** 卡片汇总资金账户可用额度和币种一致、当前可用于通用或百炼按量付费的有效券余额。券按 `Balance` 统计。券数据不完整或查询失败时,卡片会提示当前金额的范围。查询资金账户需要 `bss:DescribeBillingAccount`,查询券需要 `bss:DescribeCoupons`。实际抵扣以阿里云账单为准。
32
+
31
33
  千问 Token Plan 可在卡片内选择[官方 CLI 订阅额度](qwen-cli-quota.md),需在 DSH 主机以同一系统账号安装 CLI 并运行 `qianwen auth login`。默认保留本地估算;CLI 模式显示账号当前 Credits,不修改本地账本。
32
34
 
33
35
  千问 Token Plan 的本地 Credits 统计归属千问套餐的 Plan 调用。保留 `qwen`、`qwen-tokenplan` 等订阅别名,自定义渠道也可在「按模型统计 → 计费方式」选择千问套餐,或使用明确的厂商名与套餐特征自动识别。显式 API 调用不计;`qianwen` 按量渠道不会仅因同名模型自动归入。模型不在抵扣表中时需补充三项费率。
@@ -15,7 +15,9 @@ v1.9.16 读取 DSH `web.searchProvider`/`web.fetchProvider`,按调用开始
15
15
  |---|---|
16
16
  | 官方独立 Search/Fetch API | 在 DSH 网页服务或工具执行期间观察真实成功响应,按上面的规则入账。支持直接工具调用及宿主网页服务调用。 |
17
17
  | DSH 的本地 HTTP 抓取后端 | 没有官方 Fetch API 请求就不增加次数费。模型随后阅读网页的 Token 仍由正常用量记录计费。 |
18
- | 旧版 Messages/服务端内置搜索 | 保留模型 Token 费用。观察到成功且有结果的服务端搜索时,按实际调用另记请求:北京时间 2026 年 11 月 1 日 00:00 前免请求费,此后每次 ¥0.005;没有成功证据时不估补。 |
18
+ | 旧版 Messages/服务端内置搜索 | 保留模型 Token 费用。成功且有结果的搜索保留次数。次数费仅适用于北京时间 2026 年 11 月 1 日 00:00 至 11 月 18 日 12:00 前,每次 ¥0.005。 |
19
+
20
+ 如果旧版已将 11 月 18 日 12:00 起的服务端搜索次数费计入累计统计,可在「价格 → 历史费用」选择 `deepseek-official:deepseek-search-server` 后重算。重算会备份账本,仅调整请求日志与账本用量一致的会话日期记录。
19
21
 
20
22
  只有官方域名和精确端点被纳入上述固定单价,第三方渠道不会被强行套价。没有会话/工具作用域的独立进程请求不在此插件的观察范围。插件不主动发起搜索或抓取,不替换提供方,不自动重试,也不修改宿主网络策略。
21
23
 
@@ -36,7 +38,7 @@ npx --yes --package=dsh-cost-meter@1.9.49 dsh-cost-meter record-search --ledger
36
38
  - `--count` 为已确认成功且尚未计费的请求数,1~10000;八条搜索结果仍是一条成功请求。
37
39
  - `--at` 为带时区的实际发生时间,不能晚于当前时间或早于最后一次清空历史。
38
40
  - `--id` 是本次补记的稳定标识。重试必须使用相同 ID 和参数;重复执行不会再次收费。不同 ID 视为不同补记,不能给同一批请求换 ID 重复执行。
39
- - `--source server-tool` 为默认值,按服务端工具收费起点计算;独立 Search API 使用 `--source search-api`。
41
+ - `--source server-tool` 为默认值,按调用时间判断当时的服务端工具单价。独立 Search API 使用 `--source search-api`。
40
42
  - 只补请求费,不补模型 Token,不消除原覆盖缺口,不自动推断未观察到的请求是否成功。
41
43
 
42
44
  补记元数据保存在账本旁的 `ledger.json.native-search-manual/`;历史明细保留 `recordedBy: manual`。备份时一并保留账本、该目录及 `ledger.json.native-search/`。写入与正常计费共用账本锁、原子替换和请求去重;中断后可用原命令重试。
@@ -47,6 +49,6 @@ v1.8.35 meters the official standalone Search and Fetch endpoints separately fro
47
49
 
48
50
  Request fees use their own billing rows, remain API expenses, and retain historical exchange rates. They do not add tokens or inherit model multipliers, peak discounts or subscriptions. Observations are limited to exact official endpoints in DSH web/tool execution scopes; local HTTP fetching and third-party providers are not assigned this price. Journals contain no queries, URLs, page bodies or credentials. The plugin makes no search/fetch requests itself.
49
51
 
50
- Legacy Messages search retains model-token accounting. Observed successful server-side searches have a request-fee waiver until November 1, 2026 at 00:00 Beijing time, then cost CNY 0.005 per request. Selection is read from DSH’s live web settings and snapshotted at call start; historical records retain their source and rate. Presentation items alone do not create charges. See the [official billing rules](https://api-docs.deepseek.com/guides/search/).
52
+ Legacy Messages search retains model-token accounting. Successful server-side searches cost CNY 0.005 per request from November 1, 2026 at 00:00 up to November 18 at 12:00, Beijing time. Only model tokens are billed after that. To correct previously recorded fees, select `deepseek-official:deepseek-search-server` under Pricing → Historical pricing and recalculate. Recalculation backs up the ledger and updates records whose request logs match the ledger. See the [official pricing rules](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/).
51
53
 
52
54
  The `record-search` command previews confirmed missing successful search fees; add `--apply` to persist them. Reuse the same `--id`, timestamp, count and session when retrying. `--source server-tool` observes the server-tool waiver; `--source search-api` selects direct Search API fees. The command never infers successful counts from coverage gaps and never fabricates model tokens. Manual records and metadata are retained next to the ledger.
@@ -0,0 +1,95 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { setTimeout as sleep } from 'node:timers/promises'
3
+ import { fetchWithRetry, readJsonBounded } from './net.js'
4
+
5
+ const POOL_PATH = '/plugins/agy-link/pool'
6
+ const FAMILIES = { google: 'Gemini', argon: 'Gemini Argon', anthropic: 'Claude', openai: 'GPT', unknown: 'Other' }
7
+
8
+ function accountRows(payload, zh) {
9
+ const byId = new Map()
10
+ for (const raw of payload.accounts.slice(0, 16)) {
11
+ if (typeof raw?.id !== 'string' || !raw.id || raw.enabled === false) continue
12
+ const id = createHash('sha256').update(raw.id).digest('hex').slice(0, 16)
13
+ const windows = []
14
+ const timestamps = []
15
+ for (const [family, label] of Object.entries(FAMILIES)) {
16
+ const quota = raw.quotas?.[family]
17
+ if (!quota || raw.authRequired === true) continue
18
+ if (Number.isFinite(quota.updatedAt) && quota.updatedAt > 0) timestamps.push(quota.updatedAt)
19
+ for (const [key, hours, value, reset] of [
20
+ ['rolling', 5, quota.remainingFraction, quota.resetTime],
21
+ ['weekly', 168, quota.weeklyFraction, quota.weeklyResetTime],
22
+ ]) {
23
+ if (!Number.isFinite(value) || value < 0 || value > 1) continue
24
+ const resetMs = typeof reset === 'string' ? Date.parse(reset) : NaN
25
+ windows.push({ id: `${family}-${key}`, label: label + (hours === 5 ? (zh ? ' · 5 小时' : ' · 5 h') : (zh ? ' · 7 天' : ' · 7 d')),
26
+ percent: (1 - value) * 100, resetsAt: Number.isFinite(resetMs) ? new Date(resetMs).toISOString() : null, periodHours: hours, scope: family })
27
+ }
28
+ }
29
+ const alias = typeof raw.alias === 'string' ? raw.alias.trim() : ''
30
+ const label = alias && !/[@\u0000-\u001f\u007f]/.test(alias) ? alias.slice(0, 80) : (zh ? '账号 ' : 'Account ') + (byId.size + 1)
31
+ const status = raw.authRequired === true ? 'error' : windows.length ? 'ok' : 'unknown'
32
+ const message = status === 'error' ? (zh ? '请在 dsh-agy-link 重新登录' : 'Sign in again in dsh-agy-link')
33
+ : status === 'unknown' ? (zh ? '上游暂未返回额度' : 'No quota reported yet') : ''
34
+ byId.set(id, { account: { id, provider: 'antigravity', label, status, message, windows }, updatedAt: Math.max(0, ...timestamps) })
35
+ }
36
+ return byId
37
+ }
38
+
39
+ export async function queryAgyLinkQuota(base, { hostOrigin, force, locale, signal, fetchImpl,
40
+ now = Date.now, wait = sleep } = {}) {
41
+ const zh = locale !== 'en'
42
+ const fail = message => ({ ...base, status: 'error', message })
43
+ if (base.status === 'off') return base
44
+ if (!hostOrigin) return fail(zh ? 'DSH Web 服务尚未就绪' : 'The DSH web server is not ready')
45
+ const read = async (path, init) => {
46
+ const response = await fetchWithRetry(hostOrigin + path, { ...init, signal, redirect: 'error' }, { attempts: 1, timeoutMs: 3500, fetchImpl })
47
+ if (!response.ok) {
48
+ await response.body?.cancel().catch(() => {})
49
+ throw Object.assign(new Error('dsh-agy-link query failed'), { status: response.status })
50
+ }
51
+ return readJsonBounded(response, 524288, { signal })
52
+ }
53
+ const readAccounts = async () => {
54
+ const payload = await read(POOL_PATH)
55
+ if (!Array.isArray(payload?.accounts)) throw new Error('Invalid account pool')
56
+ return accountRows(payload, zh)
57
+ }
58
+ let rows
59
+ let refreshing = false
60
+ try {
61
+ rows = await readAccounts()
62
+ const expected = [...rows].filter(([, row]) => row.account.status !== 'error')
63
+ if (force && expected.length > 0) {
64
+ const result = await read(POOL_PATH + '/refresh-quota', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
65
+ if (result?.ok !== true) throw new Error('Refresh failed')
66
+ if (result.pending === true) {
67
+ refreshing = true
68
+ for (let i = 0; i < 12; i++) {
69
+ await wait(2000, undefined, { signal })
70
+ rows = await readAccounts()
71
+ refreshing = expected.some(([id, before]) => {
72
+ const latest = rows.get(id)
73
+ return latest && latest.account.status !== 'error' && latest.updatedAt <= before.updatedAt
74
+ && JSON.stringify(latest.account.windows) === JSON.stringify(before.account.windows)
75
+ })
76
+ if (!refreshing) break
77
+ }
78
+ } else rows = await readAccounts()
79
+ }
80
+ } catch (error) {
81
+ signal?.throwIfAborted()
82
+ if (!rows || rows.size === 0) return fail(error?.status === 404
83
+ ? (zh ? '请安装并启用 dsh-agy-link' : 'Install and enable dsh-agy-link')
84
+ : (zh ? '读取 dsh-agy-link 额度失败,请重试' : 'Could not read dsh-agy-link quota. Retry later.'))
85
+ refreshing = true
86
+ }
87
+ const accounts = [...rows.values()].map(row => row.account)
88
+ const updatedAt = Math.max(0, ...[...rows.values()].map(row => row.updatedAt))
89
+ const hasQuota = accounts.some(row => row.windows.length > 0)
90
+ return { ...base, accounts,
91
+ status: !refreshing && hasQuota && accounts.every(row => row.status === 'ok') ? 'ok' : 'partial',
92
+ message: refreshing ? (zh ? '上游尚未确认刷新完成,显示最近一次读取的额度' : 'Refresh is unconfirmed; showing the last quota read')
93
+ : !accounts.length ? (zh ? '请在 dsh-agy-link 登录 Google 账号' : 'Sign in to Google in dsh-agy-link') : '',
94
+ fetchedAt: updatedAt || (hasQuota ? now() : 0) }
95
+ }