@te-river/opencode-alibabatokenplan 0.1.0
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/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/core.mjs +918 -0
- package/dist/server.js +1258 -0
- package/dist/tui.js +1142 -0
- package/package.json +79 -0
- package/src/core/bailian-snapshot.ts +146 -0
- package/src/core/index.ts +10 -0
- package/src/core/merge.ts +148 -0
- package/src/core/qoder-snapshot.ts +153 -0
- package/src/core/rules.ts +105 -0
- package/src/core/status.ts +407 -0
- package/src/core/text.ts +68 -0
- package/src/core/types.ts +102 -0
- package/src/server/index.ts +476 -0
- package/src/server/panel.html +137 -0
- package/src/tui/index.tsx +418 -0
- package/src/tui/read-status.ts +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 te-river
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @te-river/opencode-alibabatokenplan
|
|
2
|
+
|
|
3
|
+
Opencode 双入口插件(server + TUI):把阿里云百炼 **Token Plan 优惠雷达**常驻在 Opencode 侧栏/首页 ——
|
|
4
|
+
三级动态数据源 + Qoder 快照第四源(来源:Qoder 客户端公开界面快照转录 2026-08-31),合并后原子持久化到 `status.json`,附倒计时、模型倍率、
|
|
5
|
+
`/tokenplan` 分类明细、边界 toast 与查询工具。
|
|
6
|
+
|
|
7
|
+
> 📸 截图位(文字版)
|
|
8
|
+
> ```
|
|
9
|
+
> ┌ Token Plan 优惠雷达(sidebar_content · order 160)────────┐
|
|
10
|
+
> │ Token Plan 优惠 实时 20:15 · Qoder快照08-31 │
|
|
11
|
+
> │ ▸ 错峰 5 折(Off-Peak 50% off) 22:00–08:00 0.25x │
|
|
12
|
+
> │ 03:47:12 后开始 │
|
|
13
|
+
> │ 当前 qwen3.8-max 0̶.̶5̶x̶ 0.25x 错峰 5 折 │
|
|
14
|
+
> │ 目录夜间优惠 · 距 1h45m 开始 │
|
|
15
|
+
> │ 折叠态点击标题切换(kv: atp.collapsed) │
|
|
16
|
+
> └────────────────────────────────────────────────────────────┘
|
|
17
|
+
> home_bottom: 错峰 22:00–08:00 · qwen3.8-max×0.5/×0.25 · 距开始 5h23m · 源:Qoder快照08-31
|
|
18
|
+
> ```
|
|
19
|
+
|
|
20
|
+
## 安装(两行手工注册)
|
|
21
|
+
|
|
22
|
+
`~/.config/opencode/opencode.jsonc` → `"plugin"` 数组追加一条:
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
// ~/.config/opencode/opencode.jsonc → "plugin": [ …原有条目…, "@te-river/opencode-alibabatokenplan@latest" ]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`~/.config/opencode/tui.json` → `"plugin"` 数组追加**同一字符串**:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
// ~/.config/opencode/tui.json → { "$schema": "https://opencode.ai/tui.json",
|
|
32
|
+
// "plugin": [ "@slkiser/opencode-quota@latest", "@te-river/opencode-alibabatokenplan@latest" ] }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
无 postinstall 魔法;两个入口都吃同一份 `~/.cache/opencode/alibabatokenplan/status.json`。
|
|
36
|
+
|
|
37
|
+
## 数据源与隐私声明
|
|
38
|
+
|
|
39
|
+
- **百炼目录三级回退(零登录)**:公开控制台匿名接口(live)→ 本机 `bl model list`(cli)→ 随包内置快照(snapshot)。
|
|
40
|
+
实时额度可选走 `bl usage token-plan`(需 `bl auth login --console --console-site domestic`)。
|
|
41
|
+
- **Qoder 数据 = 2026-08-31 静态快照**:全部优惠规则/倍率以常量形式内嵌(`src/core/qoder-snapshot.ts`),
|
|
42
|
+
**不调用任何 Qoder 私有端点**(包内 0 处相关 fetch 代码);展示一律带「截至 2026-08-31」标注,
|
|
43
|
+
过期公告位会显示「快照可能失效」。快照更新流程:修订该文件 → `npm run build && npm test` → 重发版。
|
|
44
|
+
- 两套单位(Qoder Credits 倍率 / 百炼 ¥ 价格倍率)**永不互算**,各居其 facet;仅 (模型,窗口,倍率,单位)
|
|
45
|
+
全等才合并为「双源印证」行。1 元 = 250 Credits 仅为展示换算注记(据百炼计费示例验证,非官方汇率)。
|
|
46
|
+
- 与旧版 `bailian-discount-panel.ts` 兼容:`bailian_discounts` 工具保留(委托到新名
|
|
47
|
+
`tokenplan_discounts`);旧缓存 `~/.cache/opencode/bailian-discount-cache.json` 首启自动迁移。
|
|
48
|
+
|
|
49
|
+
## 配置(可选)
|
|
50
|
+
|
|
51
|
+
`~/.config/opencode/alibabatokenplan/config.jsonc`(server + TUI 同读;缺失/坏 = 全默认):
|
|
52
|
+
|
|
53
|
+
```jsonc
|
|
54
|
+
{
|
|
55
|
+
"webpanel": { "enabled": false, "port": 7777 }, // 本地 HTTP 面板(默认关;样式见随包 src/server/panel.html)
|
|
56
|
+
"sidebar": { "order": 160, "showNonTokenPlan": false }, // 非 Token Plan 会话默认整块隐藏;true=弱化一行
|
|
57
|
+
"toast": true, // 窗口边界翻转提醒(每窗口每日恰 2 次)
|
|
58
|
+
"refresh": { "catalogMin": 10, "quotaMin": 5 } // server 刷新周期(分钟)
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
status.json schema、陈旧降级(`staleAfterSec`/坏 JSON/缺席 → TUI 内嵌快照+灰徽标)见包内架构契约。
|
|
63
|
+
|
|
64
|
+
## 开发
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install # devDeps: esbuild/typescript/@types/node/@opencode-ai/plugin
|
|
68
|
+
npm run typecheck # tsc --noEmit
|
|
69
|
+
npm run build # esbuild → dist/server.js dist/tui.js dist/core.mjs(packages:external)
|
|
70
|
+
npm test # 零宿主单测(回退链/合并/跨午夜/JSONC/陈旧判定)
|
|
71
|
+
npm run smoke # 零宿主冒烟:窗口断言(23:30/15:00 注入 now)+status.json 落盘
|
|
72
|
+
npm run publish:check
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Changelog
|
|
76
|
+
|
|
77
|
+
### 0.1.0(初版要点)
|
|
78
|
+
|
|
79
|
+
- server + TUI 双入口:百炼目录三级回退(live→cli→snapshot)+ Qoder 静态快照并入,原子持久化 `status.json`(`staleAfterSec` 陈旧降级 + 灰徽标)。
|
|
80
|
+
- TUI:sidebar 优惠面板 / 折叠、home_bottom 一行摘要、`/tokenplan` 分类明细对话框,秒级本地倒计时。
|
|
81
|
+
- 边界 toast(双源同窗只弹一次)、`tokenplan_discounts` 查询工具(旧名 `bailian_discounts` 委托)、可选本地 web 面板(默认关)。
|
|
82
|
+
- Qoder 数据为纯静态快照(来源:Qoder 客户端公开界面快照转录 2026-08-31),不调用任何 Qoder 私有端点。
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT © te-river
|