@alecliu/pi-zai-usage 0.0.0-stage → 0.1.5
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 +22 -0
- package/README.md +144 -3
- package/extensions/zai-usage.ts +548 -0
- package/package.json +37 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Feng-H (original work)
|
|
4
|
+
Copyright (c) Alec (modifications)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,144 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# pi-zai-usage
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@alecliu/pi-zai-usage)
|
|
4
|
+
[](https://www.npmjs.com/package/@alecliu/pi-zai-usage)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://pi.dev/packages)
|
|
7
|
+
|
|
8
|
+
> Forked from [Feng-H/pi-zai-usage](https://github.com/Feng-H/pi-zai-usage) — maintained by Alec.
|
|
9
|
+
|
|
10
|
+
**[English](#what-it-is) | [简体中文](#中文说明)**
|
|
11
|
+
|
|
12
|
+
> A [pi](https://pi.dev) extension that shows your **real server-side quota** for Zhipu GLM / Z.ai Coding Plans inline in the footer status bar.
|
|
13
|
+
|
|
14
|
+
## What it is
|
|
15
|
+
|
|
16
|
+
Displays Zhipu/Z.ai Coding Plan quotas directly in pi's footer — accurate across devices, with reset countdown. No more switching to a web page to check "how much am I down to".
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
~/proj (main) ↑1k ↓227 0.6%/200K zai 5h 28% (auto) glm-5.1
|
|
20
|
+
└──── badge
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `zai 5h 28%` — 28% of the 5-hour rolling token window used, colored green/yellow/red by usage
|
|
24
|
+
- When the server API is unreachable, falls back to scanning local session JSONLs for a **local approximation** (distinguished by a `~` prefix)
|
|
25
|
+
- `/usage` toggles a detail popup: plan tier / 5h tokens / weekly quota / tool quotas / reset times
|
|
26
|
+
|
|
27
|
+
## Data source
|
|
28
|
+
|
|
29
|
+
Zhipu/Z.ai actually exposes a quota endpoint (per cc-switch's coding_plan implementation):
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
GET {base}/api/monitor/usage/quota/limit
|
|
33
|
+
Authorization: Bearer <api_key>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Response `data.limits[]` (unit semantics from the z.ai frontend source):
|
|
37
|
+
|
|
38
|
+
| type | unit | meaning |
|
|
39
|
+
| -------------- | ---- | ------------------------------------------------------ |
|
|
40
|
+
| `TOKENS_LIMIT` | 3 | 5-hour rolling token window (main badge) |
|
|
41
|
+
| `TOKENS_LIMIT` | 6 | weekly quota (some plans / international site only) |
|
|
42
|
+
| `TIME_LIMIT` | 5 | tools/search (monthly, shown in `/usage`) |
|
|
43
|
+
|
|
44
|
+
`base` is auto-selected per provider (`zai-coding-cn` / containing `bigmodel` → `open.bigmodel.cn`, else `api.z.ai`).
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
Install via **npm** (recommended):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pi install npm:@alecliu/pi-zai-usage
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or install directly from **GitHub**:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pi install git:github.com/Alec01/pi-zai-usage
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Environment variables (optional)
|
|
61
|
+
|
|
62
|
+
| Variable | Default | Meaning |
|
|
63
|
+
| ------------------ | -------------------- | ------------------------------------------ |
|
|
64
|
+
| `PI_USAGE_BASE` | auto per provider | quota endpoint host |
|
|
65
|
+
| `PI_USAGE_WINDOW_H`| `5` | rolling window hours for the local fallback|
|
|
66
|
+
| `PI_USAGE_PROVIDER`| provider or `zai` | provider substring match for local fallback|
|
|
67
|
+
|
|
68
|
+
## Rendering notes
|
|
69
|
+
|
|
70
|
+
Uses `ctx.ui.setFooter()` with a single-line layout `pwd stats ···· model`; the badge is injected into stats between the context-window % and `(auto)`. On narrow terminals it trims progressively (provider prefix → pwd → model name) while keeping stats (badge / context %) intact.
|
|
71
|
+
|
|
72
|
+
> `setStatus()` pins badges to a separate extension status row that can't merge into the stats line — hence `setFooter`.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 中文说明
|
|
77
|
+
|
|
78
|
+
> pi coding agent 扩展:在 footer 状态行内联显示智谱 GLM / Z.ai Coding Plan 的**真实服务端配额**。
|
|
79
|
+
|
|
80
|
+
### 这是什么
|
|
81
|
+
|
|
82
|
+
把智谱/Z.ai Coding Plan 的服务端配额,直接显示在 pi 的底部状态行(footer)里,跨设备准确、带重置倒计时。不再需要切到网页查「我还剩多少额度」。
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
~/proj (main) ↑1k ↓227 0.6%/200K zai 5h 28% (auto) glm-5.1
|
|
86
|
+
└──── 徽标
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `zai 5h 28%` — 5 小时滚动 token 窗口已用 28%,绿/黄/红按用量着色
|
|
90
|
+
- 当服务端 API 不可达时,回退到扫描本机会话 JSONL 做**本地近似**(`~` 前缀区分)
|
|
91
|
+
- `/usage` 命令弹出配额明细:套餐档位 / 5h token / 周配额 / 工具额度 / 重置时间,再次执行关闭
|
|
92
|
+
|
|
93
|
+
### 数据源
|
|
94
|
+
|
|
95
|
+
智谱/Z.ai 其实开放了配额查询接口(参考 cc-switch 的 coding_plan 实现):
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
GET {base}/api/monitor/usage/quota/limit
|
|
99
|
+
Authorization: Bearer <api_key>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
响应 `data.limits[]`(unit 含义来自 z.ai 前端源码):
|
|
103
|
+
|
|
104
|
+
| type | unit | 含义 |
|
|
105
|
+
| -------------- | ---- | ------------------------------------------ |
|
|
106
|
+
| `TOKENS_LIMIT` | 3 | 5 小时滚动 token 窗口(徽标主显示) |
|
|
107
|
+
| `TOKENS_LIMIT` | 6 | 周配额(部分套餐/国际站才有,`/usage` 展示)|
|
|
108
|
+
| `TIME_LIMIT` | 5 | 工具/搜索类(月度,`/usage` 展示) |
|
|
109
|
+
|
|
110
|
+
`base` 按 provider 自动选择(`zai-coding-cn`/含 `bigmodel` → `open.bigmodel.cn`,否则 `api.z.ai`)。
|
|
111
|
+
|
|
112
|
+
### 安装方式
|
|
113
|
+
|
|
114
|
+
通过 **npm 官方镜像** 安装(推荐):
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pi install npm:@alecliu/pi-zai-usage
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
或者直接从 **GitHub** 安装:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pi install git:github.com/Alec01/pi-zai-usage
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- npm 官方包页面:[https://www.npmjs.com/package/@alecliu/pi-zai-usage](https://www.npmjs.com/package/@alecliu/pi-zai-usage)
|
|
127
|
+
|
|
128
|
+
### 环境变量(可选)
|
|
129
|
+
|
|
130
|
+
| 变量 | 默认 | 说明 |
|
|
131
|
+
| ------------------ | --------------------------------- | ------------------------------------------ |
|
|
132
|
+
| `PI_USAGE_BASE` | 按 provider 自动 | 配额端点 host |
|
|
133
|
+
| `PI_USAGE_WINDOW_H`| `5` | 本地回退的滚动窗口小时数 |
|
|
134
|
+
| `PI_USAGE_PROVIDER`| provider 或 `zai` | 本地回退的 provider 匹配子串 |
|
|
135
|
+
|
|
136
|
+
### 渲染说明
|
|
137
|
+
|
|
138
|
+
用 `ctx.ui.setFooter()` 接管 footer,采用**单行布局** `pwd stats ···· model`,徽标注入 stats 的「上下文窗口」与「(auto)」之间。窄终端按 provider 前缀 → pwd → 模型名 逐级裁剪,stats(含徽标 / 上下文%)核心信息尽量保完整。
|
|
139
|
+
|
|
140
|
+
> `setStatus()` 的徽标会被固定到单独的「扩展状态行」,无法并入 stats 行,故用 `setFooter`。
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zai-usage.ts — 在 footer 状态行内联显示智谱 GLM / Z.ai Coding Plan 的「真实服务端配额」。
|
|
3
|
+
*
|
|
4
|
+
* 关键突破(参考 cc-switch 的 coding_plan 实现):
|
|
5
|
+
* 智谱/Z.ai 其实【开放】配额查询接口,我先前「不开放」的判断是错的。
|
|
6
|
+
* GET {base}/api/monitor/usage/quota/limit
|
|
7
|
+
* Authorization: Bearer <api_key> ← 实测:国内站裸 key/Bearer 都接受;国际站用 Bearer(参考 cc-switch / pi-glm-usage)。统一用 Bearer 最通用。
|
|
8
|
+
* Content-Type: application/json
|
|
9
|
+
* Accept-Language: en-US,en
|
|
10
|
+
* 响应 data.limits[](unit 含义来自 z.ai 前端源码):
|
|
11
|
+
* - TOKENS_LIMIT unit=3:5 小时滚动 token 窗口(徽标主显示)
|
|
12
|
+
* - TOKENS_LIMIT unit=6:周配额(部分套餐/国际站才有,有则 /usage 展示)
|
|
13
|
+
* - TIME_LIMIT unit=5:工具/搜索类(月度)
|
|
14
|
+
* 本扩展取 TOKENS_LIMIT(unit=3) 作为主徽标,跨设备准确、带重置倒计时。
|
|
15
|
+
* 当 API 不可达时,回退到扫描本机会话 JSONL 做本地近似(带 ~ 前缀区分)。
|
|
16
|
+
*
|
|
17
|
+
* 渲染:用 ctx.ui.setFooter() 接管 footer,**单行布局** `pwd stats ···· model`,
|
|
18
|
+
* 徽标注入 stats 的「上下文窗口」与「(auto)」之间:
|
|
19
|
+
* `~/proj (main) ↑1k ↓227 0.6%/200K zai 5h 28% (auto) glm-5.1`
|
|
20
|
+
* setStatus() 的徽标会被固定到单独的「扩展状态行」,无法并入 stats 行,故用 setFooter。
|
|
21
|
+
*
|
|
22
|
+
* 环境变量:
|
|
23
|
+
* PI_USAGE_BASE 配额端点 host(默认按 provider 自动:zai-coding-cn→bigmodel.cn,否则 z.ai)
|
|
24
|
+
* PI_USAGE_WINDOW_H 本地回退的滚动窗口小时数(默认 5)
|
|
25
|
+
* PI_USAGE_PROVIDER 本地回退的 provider 匹配子串
|
|
26
|
+
*
|
|
27
|
+
* 命令:
|
|
28
|
+
* /usage 弹出配额明细(套餐档位 / 5h token / 工具额度 / 重置时间),再次执行关闭
|
|
29
|
+
*/
|
|
30
|
+
import fs from "node:fs";
|
|
31
|
+
import path from "node:path";
|
|
32
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
33
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
34
|
+
|
|
35
|
+
const WIDGET_KEY = "zai-usage-detail";
|
|
36
|
+
|
|
37
|
+
// ── 紧凑数字格式 ────────────────────────────────────────────
|
|
38
|
+
function fmt(n: number): string {
|
|
39
|
+
if (n < 1000) return `${Math.round(n)}`;
|
|
40
|
+
if (n < 1_000_000) return `${(n / 1000).toFixed(n < 10_000 ? 1 : 0)}k`;
|
|
41
|
+
return `${(n / 1_000_000).toFixed(2)}M`;
|
|
42
|
+
}
|
|
43
|
+
/** footer token 格式(忠实复刻 pi 默认 footer 的 formatTokens) */
|
|
44
|
+
function formatTokens(count: number): string {
|
|
45
|
+
if (count < 1000) return count.toString();
|
|
46
|
+
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
47
|
+
if (count < 1_000_000) return `${Math.round(count / 1000)}k`;
|
|
48
|
+
if (count < 10_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
|
|
49
|
+
return `${Math.round(count / 1_000_000)}M`;
|
|
50
|
+
}
|
|
51
|
+
/** cwd → footer 显示(~ 替换 home) */
|
|
52
|
+
function formatCwdForFooter(cwd: string, home: string | undefined): string {
|
|
53
|
+
if (!home) return cwd;
|
|
54
|
+
const resolvedCwd = path.resolve(cwd);
|
|
55
|
+
const resolvedHome = path.resolve(home);
|
|
56
|
+
const rel = path.relative(resolvedHome, resolvedCwd);
|
|
57
|
+
const inside =
|
|
58
|
+
rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
|
|
59
|
+
if (!inside) return cwd;
|
|
60
|
+
return rel === "" ? "~" : `~${path.sep}${rel}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── 服务端配额 ──────────────────────────────────────────────
|
|
64
|
+
interface LimitTier {
|
|
65
|
+
percentage: number;
|
|
66
|
+
resetMs: number | null;
|
|
67
|
+
}
|
|
68
|
+
interface Quota {
|
|
69
|
+
level: string | null; // 套餐档位: lite / pro / ...
|
|
70
|
+
tokens: LimitTier | null; // TOKENS_LIMIT, unit=3(5h token 窗口)— 徽标主显示
|
|
71
|
+
weekly: LimitTier | null; // TOKENS_LIMIT, unit=6(周配额,部分套餐/国际站才有)
|
|
72
|
+
time: LimitTier | null; // TIME_LIMIT, unit=5(工具/搜索类,月度)
|
|
73
|
+
timeDetails?: { model: string; usage: number }[];
|
|
74
|
+
queriedAt: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** GET 配额接口,解析 TOKENS_LIMIT(unit=3) 与 TIME_LIMIT。Authorization 不加 Bearer。 */
|
|
78
|
+
async function fetchQuota(base: string, apiKey: string): Promise<Quota | null> {
|
|
79
|
+
let resp: Response;
|
|
80
|
+
try {
|
|
81
|
+
resp = await fetch(`${base}/api/monitor/usage/quota/limit`, {
|
|
82
|
+
method: "GET",
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: `Bearer ${apiKey}`,
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"Accept-Language": "en-US,en",
|
|
87
|
+
},
|
|
88
|
+
signal: AbortSignal.timeout(15000),
|
|
89
|
+
});
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (resp.status === 401 || resp.status === 403) return null;
|
|
94
|
+
if (!resp.ok) return null;
|
|
95
|
+
let body: any;
|
|
96
|
+
try {
|
|
97
|
+
body = await resp.json();
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
if (body?.success === false) return null;
|
|
102
|
+
const data = body?.data;
|
|
103
|
+
if (!data) return null;
|
|
104
|
+
|
|
105
|
+
let tokens: LimitTier | null = null;
|
|
106
|
+
let weekly: LimitTier | null = null;
|
|
107
|
+
let time: LimitTier | null = null;
|
|
108
|
+
let timeDetails: { model: string; usage: number }[] | undefined;
|
|
109
|
+
for (const lim of data.limits ?? []) {
|
|
110
|
+
if (lim.type === "TOKENS_LIMIT" && lim.unit === 3 && !tokens) {
|
|
111
|
+
tokens = { percentage: Number(lim.percentage) || 0, resetMs: lim.nextResetTime ?? null };
|
|
112
|
+
} else if (lim.type === "TOKENS_LIMIT" && lim.unit === 6 && !weekly) {
|
|
113
|
+
weekly = { percentage: Number(lim.percentage) || 0, resetMs: lim.nextResetTime ?? null };
|
|
114
|
+
} else if (lim.type === "TIME_LIMIT" && !time) {
|
|
115
|
+
time = { percentage: Number(lim.percentage) || 0, resetMs: lim.nextResetTime ?? null };
|
|
116
|
+
timeDetails = (lim.usageDetails ?? []).map((d: any) => ({
|
|
117
|
+
model: String(d.modelCode ?? "?"),
|
|
118
|
+
usage: Number(d.usage) || 0,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
level: data.level ? String(data.level) : null,
|
|
124
|
+
tokens,
|
|
125
|
+
weekly,
|
|
126
|
+
time,
|
|
127
|
+
timeDetails,
|
|
128
|
+
queriedAt: Date.now(),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ── 本地兜底:扫描会话 JSONL ────────────────────────────────
|
|
133
|
+
interface LocalTotals {
|
|
134
|
+
total: number;
|
|
135
|
+
input: number;
|
|
136
|
+
output: number;
|
|
137
|
+
cache: number;
|
|
138
|
+
}
|
|
139
|
+
function computeWindowLocal(globalRoot: string, windowMs: number, providerMatch: string): LocalTotals {
|
|
140
|
+
const cutoff = Date.now() - windowMs;
|
|
141
|
+
let total = 0,
|
|
142
|
+
input = 0,
|
|
143
|
+
output = 0,
|
|
144
|
+
cache = 0;
|
|
145
|
+
let projectDirs: string[] = [];
|
|
146
|
+
try {
|
|
147
|
+
projectDirs = fs
|
|
148
|
+
.readdirSync(globalRoot, { withFileTypes: true })
|
|
149
|
+
.filter((d) => d.isDirectory())
|
|
150
|
+
.map((d) => path.join(globalRoot, d.name));
|
|
151
|
+
} catch {
|
|
152
|
+
return { total, input, output, cache };
|
|
153
|
+
}
|
|
154
|
+
for (const dir of projectDirs) {
|
|
155
|
+
let files: string[] = [];
|
|
156
|
+
try {
|
|
157
|
+
files = fs
|
|
158
|
+
.readdirSync(dir)
|
|
159
|
+
.filter((f) => f.endsWith(".jsonl"))
|
|
160
|
+
.map((f) => path.join(dir, f));
|
|
161
|
+
} catch {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
for (const file of files) {
|
|
165
|
+
let stat;
|
|
166
|
+
try {
|
|
167
|
+
stat = fs.statSync(file);
|
|
168
|
+
} catch {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (stat.mtimeMs < cutoff) continue;
|
|
172
|
+
let content: string;
|
|
173
|
+
try {
|
|
174
|
+
content = fs.readFileSync(file, "utf8");
|
|
175
|
+
} catch {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
for (const line of content.split("\n")) {
|
|
179
|
+
const t = line.trim();
|
|
180
|
+
if (!t) continue;
|
|
181
|
+
let e: any;
|
|
182
|
+
try {
|
|
183
|
+
e = JSON.parse(t);
|
|
184
|
+
} catch {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (e.type !== "message") continue;
|
|
188
|
+
const m = e.message;
|
|
189
|
+
if (!m || m.role !== "assistant") continue;
|
|
190
|
+
if (!(typeof m.provider === "string" && m.provider.includes(providerMatch))) continue;
|
|
191
|
+
const ts =
|
|
192
|
+
typeof e.timestamp === "string"
|
|
193
|
+
? Date.parse(e.timestamp)
|
|
194
|
+
: typeof m.timestamp === "number"
|
|
195
|
+
? m.timestamp
|
|
196
|
+
: 0;
|
|
197
|
+
if (!ts || ts < cutoff) continue;
|
|
198
|
+
const u = m.usage || {};
|
|
199
|
+
input += u.input || 0;
|
|
200
|
+
output += u.output || 0;
|
|
201
|
+
cache += (u.cacheRead || 0) + (u.cacheWrite || 0);
|
|
202
|
+
total += u.totalTokens ?? (u.input || 0) + (u.output || 0) + (u.cacheRead || 0) + (u.cacheWrite || 0);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return { total, input, output, cache };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default function (pi: ExtensionAPI) {
|
|
210
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
211
|
+
let widgetOpen = false;
|
|
212
|
+
let capturedTui: any;
|
|
213
|
+
|
|
214
|
+
const windowH = Number(process.env.PI_USAGE_WINDOW_H ?? 5) || 5;
|
|
215
|
+
const windowMs = windowH * 3600 * 1000;
|
|
216
|
+
|
|
217
|
+
let quota: Quota | null = null;
|
|
218
|
+
let local: LocalTotals | null = null; // 本地兜底
|
|
219
|
+
let lastFetch = 0;
|
|
220
|
+
let fetching = false;
|
|
221
|
+
let autoCompact: boolean | undefined;
|
|
222
|
+
|
|
223
|
+
function providerMatch(ctx: any): string {
|
|
224
|
+
return process.env.PI_USAGE_PROVIDER ?? ctx?.model?.provider ?? "zai";
|
|
225
|
+
}
|
|
226
|
+
function globalRoot(ctx: any): string {
|
|
227
|
+
return path.dirname(ctx.sessionManager.getSessionDir());
|
|
228
|
+
}
|
|
229
|
+
function quotaBase(ctx: any): string {
|
|
230
|
+
if (process.env.PI_USAGE_BASE) return process.env.PI_USAGE_BASE;
|
|
231
|
+
const prov = String(ctx?.model?.provider ?? "");
|
|
232
|
+
// zai-coding-cn / 含 bigmodel → 国内站;其余 → 国际站
|
|
233
|
+
if (prov.includes("cn") || prov.includes("bigmodel")) return "https://open.bigmodel.cn";
|
|
234
|
+
return "https://api.z.ai";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function refreshQuota(ctx: any): Promise<void> {
|
|
238
|
+
if (fetching) return;
|
|
239
|
+
// 最小间隔 30s,避免 message_end 频繁打 API
|
|
240
|
+
if (Date.now() - lastFetch < 30_000 && quota) return;
|
|
241
|
+
fetching = true;
|
|
242
|
+
lastFetch = Date.now();
|
|
243
|
+
try {
|
|
244
|
+
const provider = ctx?.model?.provider;
|
|
245
|
+
let key: string | undefined;
|
|
246
|
+
try {
|
|
247
|
+
key = await ctx.modelRegistry?.getApiKeyForProvider?.(provider);
|
|
248
|
+
} catch {
|
|
249
|
+
/* ignore */
|
|
250
|
+
}
|
|
251
|
+
if (!key) {
|
|
252
|
+
// 兜底:直接读 auth.json
|
|
253
|
+
try {
|
|
254
|
+
const auth = JSON.parse(
|
|
255
|
+
fs.readFileSync(path.join(path.dirname(globalRoot(ctx)), "auth.json"), "utf8"),
|
|
256
|
+
);
|
|
257
|
+
key = auth?.[provider]?.key;
|
|
258
|
+
} catch {
|
|
259
|
+
/* ignore */
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (key) {
|
|
263
|
+
const q = await fetchQuota(quotaBase(ctx), key);
|
|
264
|
+
if (q) quota = q;
|
|
265
|
+
}
|
|
266
|
+
// 本地兜底数据始终刷新一次(用于 /usage 明细与 API 失败徽标)
|
|
267
|
+
local = computeWindowLocal(globalRoot(ctx), windowMs, providerMatch(ctx));
|
|
268
|
+
} catch {
|
|
269
|
+
/* ignore */
|
|
270
|
+
} finally {
|
|
271
|
+
fetching = false;
|
|
272
|
+
capturedTui?.requestRender();
|
|
273
|
+
if (widgetOpen) renderWidget(ctx);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function readAutoCompact(ctx: any): boolean {
|
|
278
|
+
if (autoCompact !== undefined) return autoCompact;
|
|
279
|
+
let enabled = true;
|
|
280
|
+
try {
|
|
281
|
+
const agentDir = path.dirname(globalRoot(ctx));
|
|
282
|
+
for (const f of [path.join(agentDir, "settings.json"), path.join(ctx.cwd, ".pi", "settings.json")]) {
|
|
283
|
+
if (fs.existsSync(f)) {
|
|
284
|
+
const s = JSON.parse(fs.readFileSync(f, "utf8"));
|
|
285
|
+
if (s?.compaction?.enabled !== undefined) enabled = !!s.compaction.enabled;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch {
|
|
289
|
+
/* 默认 true */
|
|
290
|
+
}
|
|
291
|
+
autoCompact = enabled;
|
|
292
|
+
return enabled;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 徽标(含颜色),注入 stats 行;quota 未就绪返回 undefined 表示省略 */
|
|
296
|
+
function zaiBadge(ctx: any, theme: any): string | undefined {
|
|
297
|
+
if (quota?.tokens) {
|
|
298
|
+
const pct = quota.tokens.percentage;
|
|
299
|
+
const color = pct >= 90 ? "error" : pct >= 70 ? "warning" : "success";
|
|
300
|
+
return theme.fg(color, `zai ${windowH}h ${Math.round(pct)}%`);
|
|
301
|
+
}
|
|
302
|
+
if (local && local.total > 0) return `zai ${windowH}h ~${fmt(local.total)}`; // ~ 表示本地近似
|
|
303
|
+
return undefined; // 加载中/失败,省略徽标
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 单行 footer:`pwd stats ···· model`,zai 徽标注入「窗口」与「(auto)」之间(不再拆两行) */
|
|
307
|
+
function renderFooter(ctx: any, theme: any, footerData: any, width: number): string[] {
|
|
308
|
+
const state: any = { model: ctx.model, thinkingLevel: ctx.thinkingLevel };
|
|
309
|
+
let inT = 0,
|
|
310
|
+
outT = 0,
|
|
311
|
+
cacheRead = 0,
|
|
312
|
+
cacheWrite = 0,
|
|
313
|
+
cost = 0;
|
|
314
|
+
let latestCacheHitRate: number | undefined;
|
|
315
|
+
try {
|
|
316
|
+
for (const e of ctx.sessionManager.getEntries()) {
|
|
317
|
+
if (e.type === "message" && e.message?.role === "assistant") {
|
|
318
|
+
const u = e.message.usage || {};
|
|
319
|
+
inT += u.input || 0;
|
|
320
|
+
outT += u.output || 0;
|
|
321
|
+
cacheRead += u.cacheRead || 0;
|
|
322
|
+
cacheWrite += u.cacheWrite || 0;
|
|
323
|
+
cost += u.cost?.total || 0;
|
|
324
|
+
const p = (u.input || 0) + (u.cacheRead || 0) + (u.cacheWrite || 0);
|
|
325
|
+
latestCacheHitRate = p > 0 ? ((u.cacheRead || 0) / p) * 100 : undefined;
|
|
326
|
+
} else if (e.type === "message" && e.message?.role === "toolResult" && e.message?.usage) {
|
|
327
|
+
const u = e.message.usage;
|
|
328
|
+
inT += u.input || 0;
|
|
329
|
+
outT += u.output || 0;
|
|
330
|
+
cacheRead += u.cacheRead || 0;
|
|
331
|
+
cacheWrite += u.cacheWrite || 0;
|
|
332
|
+
cost += u.cost?.total || 0;
|
|
333
|
+
} else if ((e.type === "branch_summary" || e.type === "compaction") && e.usage) {
|
|
334
|
+
const u = e.usage;
|
|
335
|
+
inT += u.input || 0;
|
|
336
|
+
outT += u.output || 0;
|
|
337
|
+
cacheRead += u.cacheRead || 0;
|
|
338
|
+
cacheWrite += u.cacheWrite || 0;
|
|
339
|
+
cost += u.cost?.total || 0;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} catch {
|
|
343
|
+
/* ignore */
|
|
344
|
+
}
|
|
345
|
+
const contextUsage = ctx.getContextUsage?.();
|
|
346
|
+
const contextWindow = contextUsage?.contextWindow ?? ctx.model?.contextWindow ?? 0;
|
|
347
|
+
const contextPercentValue = contextUsage?.percent ?? 0;
|
|
348
|
+
const contextPercent =
|
|
349
|
+
contextUsage?.percent !== null && contextUsage?.percent !== undefined
|
|
350
|
+
? contextPercentValue.toFixed(1)
|
|
351
|
+
: "?";
|
|
352
|
+
|
|
353
|
+
let pwd = formatCwdForFooter(ctx.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);
|
|
354
|
+
const branch = footerData.getGitBranch();
|
|
355
|
+
if (branch) pwd = `${pwd} (${branch})`;
|
|
356
|
+
const sessionName = ctx.sessionManager.getSessionName?.();
|
|
357
|
+
if (sessionName) pwd = `${pwd} • ${sessionName}`;
|
|
358
|
+
|
|
359
|
+
const statsParts: string[] = [];
|
|
360
|
+
if (inT) statsParts.push(`↑${formatTokens(inT)}`);
|
|
361
|
+
if (outT) statsParts.push(`↓${formatTokens(outT)}`);
|
|
362
|
+
if (cacheRead) statsParts.push(`R${formatTokens(cacheRead)}`);
|
|
363
|
+
if (cacheWrite) statsParts.push(`W${formatTokens(cacheWrite)}`);
|
|
364
|
+
if ((cacheRead > 0 || cacheWrite > 0) && latestCacheHitRate !== undefined) {
|
|
365
|
+
statsParts.push(`CH${latestCacheHitRate.toFixed(1)}%`);
|
|
366
|
+
}
|
|
367
|
+
const usingSubscription = state.model ? state.model.provider === "kimi-coding" : false;
|
|
368
|
+
if (cost || usingSubscription) statsParts.push(`$${cost.toFixed(3)}${usingSubscription ? " (sub)" : ""}`);
|
|
369
|
+
|
|
370
|
+
// 上下文百分比:`pct/window [zai] (auto)`
|
|
371
|
+
const autoIndicator = readAutoCompact(ctx) ? " (auto)" : "";
|
|
372
|
+
const windowStr =
|
|
373
|
+
contextPercent === "?"
|
|
374
|
+
? `?/${formatTokens(contextWindow)}`
|
|
375
|
+
: `${contextPercent}%/${formatTokens(contextWindow)}`;
|
|
376
|
+
const badge = zaiBadge(ctx, theme);
|
|
377
|
+
const contextPercentDisplay = badge ? `${windowStr} ${badge}${autoIndicator}` : `${windowStr}${autoIndicator}`;
|
|
378
|
+
|
|
379
|
+
let contextPercentStr: string;
|
|
380
|
+
if (contextPercentValue > 90) contextPercentStr = theme.fg("error", contextPercentDisplay);
|
|
381
|
+
else if (contextPercentValue > 70) contextPercentStr = theme.fg("warning", contextPercentDisplay);
|
|
382
|
+
else contextPercentStr = contextPercentDisplay;
|
|
383
|
+
statsParts.push(contextPercentStr);
|
|
384
|
+
if (process.env.PI_EXPERIMENTAL === "1") {
|
|
385
|
+
statsParts.push(`${theme.fg("dim", "•")} ${theme.bold(theme.fg("warning", "xp"))}`);
|
|
386
|
+
}
|
|
387
|
+
let statsLeft = statsParts.join(" ");
|
|
388
|
+
|
|
389
|
+
// 右侧模型名(+ thinking / provider)
|
|
390
|
+
const modelName = state.model?.id || "no-model";
|
|
391
|
+
let rightSideWithoutProvider = modelName;
|
|
392
|
+
if (state.model?.reasoning) {
|
|
393
|
+
const thinkingLevel = state.thinkingLevel || "off";
|
|
394
|
+
rightSideWithoutProvider =
|
|
395
|
+
thinkingLevel === "off" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;
|
|
396
|
+
}
|
|
397
|
+
let rightSide = rightSideWithoutProvider;
|
|
398
|
+
if (footerData.getAvailableProviderCount() > 1 && state.model) {
|
|
399
|
+
rightSide = `(${state.model.provider}) ${rightSideWithoutProvider}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ── 单行 footer:`pwd stats ···· model`(不再拆两行换行) ──
|
|
403
|
+
// 宽度不足时按可舍弃程度逐级裁剪:provider 前缀 → pwd → 右侧模型名;
|
|
404
|
+
// stats(含 zai 徽标 / 上下文%)是核心信息,尽量保完整
|
|
405
|
+
const sep = " ";
|
|
406
|
+
const minPad = 2;
|
|
407
|
+
const statsW = visibleWidth(statsLeft);
|
|
408
|
+
|
|
409
|
+
// 1) 去掉 provider 前缀
|
|
410
|
+
if (
|
|
411
|
+
rightSide !== rightSideWithoutProvider &&
|
|
412
|
+
visibleWidth(pwd) + sep.length + statsW + minPad + visibleWidth(rightSide) > width
|
|
413
|
+
) {
|
|
414
|
+
rightSide = rightSideWithoutProvider;
|
|
415
|
+
}
|
|
416
|
+
// 2) 截断/舍弃 pwd
|
|
417
|
+
let pwdStr = pwd;
|
|
418
|
+
if (visibleWidth(pwdStr) + sep.length + statsW + minPad + visibleWidth(rightSide) > width) {
|
|
419
|
+
const availForPwd = width - minPad - visibleWidth(rightSide) - sep.length - statsW;
|
|
420
|
+
pwdStr = availForPwd >= 3 ? truncateToWidth(pwd, availForPwd, "...") : "";
|
|
421
|
+
}
|
|
422
|
+
const leftW = pwdStr === "" ? statsW : visibleWidth(pwdStr) + sep.length + statsW;
|
|
423
|
+
// 3) 右侧模型名仍放不下 → 截断
|
|
424
|
+
if (leftW + minPad + visibleWidth(rightSide) > width) {
|
|
425
|
+
const availForRight = width - leftW - minPad;
|
|
426
|
+
rightSide = availForRight > 4 ? truncateToWidth(rightSide, availForRight, "") : "";
|
|
427
|
+
}
|
|
428
|
+
const rightW = visibleWidth(rightSide);
|
|
429
|
+
|
|
430
|
+
// 着色:pwd / token 统计用 dim,上下文百分比保留自身颜色
|
|
431
|
+
const pwdColored = pwdStr === "" ? "" : theme.fg("dim", pwdStr) + sep;
|
|
432
|
+
const statsColored = theme.fg("dim", statsLeft);
|
|
433
|
+
const rightColored = rightW === 0 ? "" : theme.fg("dim", rightSide);
|
|
434
|
+
const pad = " ".repeat(Math.max(minPad, width - leftW - rightW));
|
|
435
|
+
const lines = [pwdColored + statsColored + pad + rightColored];
|
|
436
|
+
|
|
437
|
+
const extensionStatuses = footerData.getExtensionStatuses();
|
|
438
|
+
if (extensionStatuses.size > 0) {
|
|
439
|
+
const others = Array.from(extensionStatuses.entries())
|
|
440
|
+
.filter(([key]) => key !== "zai-usage")
|
|
441
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
442
|
+
.map(([, text]) => text.replace(/[\r\n\t]/g, " ").replace(/ +/g, " ").trim());
|
|
443
|
+
if (others.length > 0) lines.push(truncateToWidth(others.join(" "), width, theme.fg("dim", "...")));
|
|
444
|
+
}
|
|
445
|
+
return lines;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function setupFooter(ctx: any): void {
|
|
449
|
+
ctx.ui.setFooter((tui: any, theme: any, footerData: any) => {
|
|
450
|
+
capturedTui = tui;
|
|
451
|
+
const unsub = footerData.onBranchChange(() => tui.requestRender());
|
|
452
|
+
return {
|
|
453
|
+
dispose: unsub,
|
|
454
|
+
invalidate() {},
|
|
455
|
+
render: (width: number) => renderFooter(ctx, theme, footerData, width),
|
|
456
|
+
};
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function renderWidget(ctx: any): void {
|
|
461
|
+
if (!quota && !local) return;
|
|
462
|
+
const th = ctx.ui.theme;
|
|
463
|
+
const lines: string[] = [];
|
|
464
|
+
lines.push(th.fg("accent", `zai · 智谱 GLM Coding Plan 配额(${quotaBase(ctx)})`));
|
|
465
|
+
if (quota?.level) lines.push(th.fg("dim", `套餐档位: ${quota.level}`));
|
|
466
|
+
if (quota?.tokens) {
|
|
467
|
+
const color = quota.tokens.percentage >= 90 ? "error" : quota.tokens.percentage >= 70 ? "warning" : "success";
|
|
468
|
+
lines.push(th.fg(color, `5h Token 窗口: ${Math.round(quota.tokens.percentage)}% 已用`));
|
|
469
|
+
if (quota.tokens.resetMs) {
|
|
470
|
+
const mins = Math.max(0, Math.round((quota.tokens.resetMs - Date.now()) / 60000));
|
|
471
|
+
lines.push(th.fg("dim", ` 重置: ${new Date(quota.tokens.resetMs).toLocaleString()}(约 ${mins} 分钟后)`));
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
lines.push(th.fg("warning", "5h Token 窗口: 接口未返回(仅本地近似)"));
|
|
475
|
+
}
|
|
476
|
+
if (quota?.weekly) {
|
|
477
|
+
const color = quota.weekly.percentage >= 90 ? "error" : quota.weekly.percentage >= 70 ? "warning" : "success";
|
|
478
|
+
lines.push(th.fg(color, `周配额: ${Math.round(quota.weekly.percentage)}% 已用`));
|
|
479
|
+
if (quota.weekly.resetMs) {
|
|
480
|
+
const days = Math.max(0, Math.round((quota.weekly.resetMs - Date.now()) / 86400000));
|
|
481
|
+
lines.push(th.fg("dim", ` 重置: ${new Date(quota.weekly.resetMs).toLocaleString()}(约 ${days} 天后)`));
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (quota?.time) {
|
|
485
|
+
const color = quota.time.percentage >= 90 ? "error" : quota.time.percentage >= 70 ? "warning" : "success";
|
|
486
|
+
lines.push(th.fg(color, `工具/搜索额度: ${Math.round(quota.time.percentage)}% 已用`));
|
|
487
|
+
if (quota.timeDetails?.length) {
|
|
488
|
+
lines.push(th.fg("dim", " " + quota.timeDetails.map((d) => `${d.model} ${d.usage}`).join(" · ")));
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (local && local.total > 0) {
|
|
492
|
+
lines.push(
|
|
493
|
+
th.fg(
|
|
494
|
+
"dim",
|
|
495
|
+
`本地近似(~): ${fmt(local.total)} tok 输入 ${fmt(local.input)} 输出 ${fmt(local.output)} 缓存 ${fmt(local.cache)}`,
|
|
496
|
+
),
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
lines.push(th.fg("muted", "数据源: 智谱 /api/monitor/usage/quota/limit · /usage 关闭"));
|
|
500
|
+
ctx.ui.setWidget(WIDGET_KEY, lines);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
let lastCtx: any;
|
|
504
|
+
|
|
505
|
+
pi.on("session_start", (_e, ctx) => {
|
|
506
|
+
lastCtx = ctx;
|
|
507
|
+
if (ctx.mode !== "tui") return;
|
|
508
|
+
setupFooter(ctx);
|
|
509
|
+
refreshQuota(ctx);
|
|
510
|
+
if (!timer) {
|
|
511
|
+
// 周期刷新:窗口滑动 / 配额随时间变化
|
|
512
|
+
timer = setInterval(() => {
|
|
513
|
+
if (lastCtx) refreshQuota(lastCtx);
|
|
514
|
+
}, 60_000);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
pi.on("message_end", (_e, ctx) => {
|
|
519
|
+
lastCtx = ctx;
|
|
520
|
+
refreshQuota(ctx);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
pi.on("session_shutdown", () => {
|
|
524
|
+
if (timer) {
|
|
525
|
+
clearInterval(timer);
|
|
526
|
+
timer = undefined;
|
|
527
|
+
}
|
|
528
|
+
widgetOpen = false;
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
pi.registerCommand("usage", {
|
|
532
|
+
description: "显示/关闭智谱 Coding Plan 配额明细",
|
|
533
|
+
handler: async (_args, ctx) => {
|
|
534
|
+
if (ctx.mode !== "tui") {
|
|
535
|
+
ctx.ui.notify("此命令仅在交互式 TUI 下可用", "info");
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
widgetOpen = !widgetOpen;
|
|
539
|
+
if (!widgetOpen) {
|
|
540
|
+
ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
541
|
+
ctx.ui.notify("已关闭配额明细", "info");
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
await refreshQuota(ctx);
|
|
545
|
+
renderWidget(ctx);
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@alecliu/pi-zai-usage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@alecliu/pi-zai-usage",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "pi 扩展:在 footer 状态行内联显示智谱 GLM / Z.ai Coding Plan 的真实服务端配额(5h token 窗口、周配额、工具额度),并支持本地会话兜底近似与 /usage 明细命令。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Alec",
|
|
11
|
+
"url": "https://github.com/Alec01"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Alec01/pi-zai-usage.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Alec01/pi-zai-usage/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/Alec01/pi-zai-usage#readme",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"extensions",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"pi": {
|
|
29
|
+
"extensions": [
|
|
30
|
+
"./extensions"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
35
|
+
"@earendil-works/pi-tui": "*"
|
|
36
|
+
}
|
|
37
|
+
}
|