<div align="center">
  🌏 <b>中文</b> · <a href="./README.md">English</a>
</div>

<div align="center">
  <b style="font-size: 1.15em;">自包含的 DeepSeek Harness (DSH) 插件：余额 + 今日用量 + 应用用量，一个桥接搞定</b><br /><br />
  <a href="https://opensource.org/licenses/MIT"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" /></a>
  <a href="https://github.com/YpipaQ/dsh-whale-usage"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-YpipaQ%2Fdsh--whale--usage-4d6bfe" /></a>
  <a href="https://github.com/YpipaQ/dsh-whale-usage/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/YpipaQ/dsh-whale-usage" /></a>
  <a href="https://opensource.org/licenses/MIT"><img alt="DSH" src="https://img.shields.io/badge/DSH-0.1.0--rc%2B-4d6bfe" /></a>
</div>

# 🐳 dsh-whale-usage

> **自包含**的 DSH 插件：把两款插件**合并成一个**，并在桌面小鲸鱼挂件上新增**「记账 / 实时令牌 / 应用用量」**配置界面。
>
> **不改动原插件包** —— 从底层吸收原插件源码逻辑，因此 **对上游更新免疫**。安装后你可以**少维护两个插件**（原 `dsh-whale-widget` 与 `dsh-usage-stats` 可卸载）。

## ✨ 这是什么

| 吸收的来源 | 底层能力 | 原作者 / 仓库 |
|---|---|---|
| `dsh-whale-widget` | 右下角 DeepSeek **余额小鲸鱼挂件**（余额、峰谷定价、随机台词与音效、**记账 / 令牌**两种用量模式） | [zhu1090093659/dsh-web-ui](https://github.com/zhu1090093659/dsh-web-ui) |
| `dsh-usage-stats` | 按 DSH 会话计算的**应用用量**数据引擎（token 趋势、模型分解、活跃度） | [lanlandeli/dsh-usage-stats](https://github.com/lanlandeli/dsh-usage-stats) |

`dsh-whale-usage` 是二者的**桥接与合并产物**：用一个自包含插件**取代**上面两个插件。版权致谢见 [CREDITS.md](./CREDITS.md)。

## 💡 功能

- **鲸鱼挂件** —— 原样保留：余额、今日已用、峰谷定价、音效、可拖拽。
- **用量配置界面** —— 点击侧边栏底部鲸鱼按钮打开「小鲸鱼 · 用量配置」浮层，可配置：
  - **记账**：用余额正差值累计当天用量（跨天自动归零并入历史账本）。
  - **实时令牌**：用 DeepSeek 平台令牌实时计算今日用量。
  - **应用用量**：展示 DSH 会话的本机用量（今日/近 7 天 Tokens、会话、消息、最常用模型）。

## 🖼️ 截图

<div align="center">
  <img src="./docs/screenshot-config.png" alt="用量配置面板" width="62%" />
</div>
<p align="center"><i>用量配置面板 —— 用量模式 / 价格 / 音效 / 音量 / 记账峰谷时间。</i></p>

<div align="center">
  <img src="./docs/screenshot-app-usage.png" alt="应用用量仪表盘" width="82%" />
</div>
<p align="center"><i>应用用量仪表盘 —— Tokens / 会话 / 消息 / 活跃热力图 / 最常用模型。</i></p>

<div align="center">
  <img src="./docs/screenshot-peak-times.png" alt="记账峰谷时间" width="62%" />
</div>
<p align="center"><i>记账峰谷时间 —— 每周各天的高峰计费时间段。</i></p>

## 🚀 安装

> **作为普通包安装，切勿用 junction 链接。** junction 会让依赖（如 `schemastery`/`react`）无法向上解析，并使包名与 `cordis.patch.yml` 不一致——两者都会导致 DSH 启动失败。

```sh
# 推荐 —— 从 npm 安装（已发布）：https://www.npmjs.com/package/dsh-whale-usage
dsh plugin --profile web add dsh-whale-usage
# 或：npm install dsh-whale-usage

# 从源码：本仓库（或在目标机器上 git clone 后）
dsh plugin --profile web add <本仓库绝对路径>

# 或安装构建产物
dsh plugin --profile web add <路径>/dsh-whale-usage-0.1.4.tgz

# 或用一键脚本
bash scripts/install.sh                                        # macOS / Linux / Git Bash
powershell -ExecutionPolicy Bypass -File scripts/install.ps1   # Windows
```

安装后**重启 DSH 并硬刷新浏览器**（Cmd/Ctrl+Shift+R）：

- 右下角出现鲸鱼挂件；
- 侧边栏底部出现「小鲸鱼·用量」按钮。

> 因为本插件**取代**了原两个插件，建议确认正常后再卸载：
> `dsh plugin --profile web remove dsh-whale-widget` · `dsh plugin --profile web remove dsh-usage-stats`

## ⚙️ 配置

```yaml
config:
  indexConcurrency: 2      # 用量引擎读取历史会话的并发
  cacheWriteDelayMs: 1000  # 本地统计写入前的防抖延迟
  apiPath: /usage-stats/v1 # 应用用量 API 前缀
```

数据均保存在本机：

- 鲸鱼记账 / 配置：`~/.dsh/.dshw-*.json`
- 应用用量索引：`$DSH_HOME/usage-stats`

## 🗂️ 仓库结构

```
dsh-whale-usage/
├── lib/                # 构建产物（宿主: index.js, usage-host.js, whale-host.js；客户端: client.js）
├── assets/             # 鲸鱼图片 / 音效
├── cordis.patch.yml    # DSH bundle patch（插件 id dsh-whale-usage）
├── dsh.plugin.json     # DSH 插件清单（id / version / main / client.main）
├── package.json        # npm 包（name dsh-whale-usage, MIT）
├── LICENSE / CREDITS.md# MIT + 上游致谢
├── README.md / README.zh.md
├── docs/               # 开发说明（development.md）+ 截图
└── scripts/install.*   # 一键安装脚本
```

## 🛠️ 开发

架构、`npm pack` 出 tgz、以及**同步上游修复**（`lib/whale-host.js`、`lib/usage-host.js`）见 [`docs/development.md`](./docs/development.md)。

## 📄 许可与致谢

- **许可**：[MIT](./LICENSE)。合并吸收的第三方源码版权归其原作者——见 [CREDITS.md](./CREDITS.md)。
- 本插件**自包含**：不随上游自动变化；修复/跟进见 `docs/development.md`。

---

*English README: [`README.md`](./README.md)。*


