zusage 1.0.1 β 1.0.2
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 +8 -8
- package/bin/index.js +24 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This tool connects to the Z.ai API to fetch and display your current token consu
|
|
|
11
11
|
- Visual progress bar showing token usage percentage
|
|
12
12
|
- Current tokens used, remaining, and total limit
|
|
13
13
|
- Time remaining until next reset
|
|
14
|
-
- Next reset date and time
|
|
14
|
+
- Next reset date and time
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -47,17 +47,17 @@ zusage
|
|
|
47
47
|
|
|
48
48
|
```
|
|
49
49
|
==================================================
|
|
50
|
-
π Z.AI -
|
|
50
|
+
π Z.AI - TOKEN USAGE
|
|
51
51
|
==================================================
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Progress: [βββββββββββββββββββββββββββ] 72%
|
|
54
54
|
|
|
55
|
-
π
|
|
56
|
-
π
|
|
57
|
-
π―
|
|
55
|
+
π Used: 145,000 tokens
|
|
56
|
+
π Remaining: 55,000 tokens
|
|
57
|
+
π― Limit: 200,000 tokens
|
|
58
58
|
|
|
59
|
-
β±οΈ Reset
|
|
60
|
-
π
|
|
59
|
+
β±οΈ Reset in: 2h 15m
|
|
60
|
+
π
Next reset: Monday, January 11, 2026 at 2:30 PM
|
|
61
61
|
|
|
62
62
|
==================================================
|
|
63
63
|
```
|
package/bin/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Simple program to display Z.ai token usage
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const BASE_URL = 'https://api.z.ai';
|
|
7
7
|
const AUTH_TOKEN = process.env.ANTHROPIC_AUTH_TOKEN;
|
|
8
8
|
|
|
9
9
|
if (!AUTH_TOKEN) {
|
|
10
|
-
console.error('β
|
|
10
|
+
console.error('β Error: ANTHROPIC_AUTH_TOKEN environment variable is not set');
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Fetches token limits from Z.ai API
|
|
16
16
|
*/
|
|
17
17
|
async function getTokenLimit() {
|
|
18
18
|
const response = await fetch(`${BASE_URL}/api/monitor/usage/quota/limit`, {
|
|
@@ -34,36 +34,35 @@ async function getTokenLimit() {
|
|
|
34
34
|
throw new Error(`API Error: ${data.msg}`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// Find and return only the TOKENS_LIMIT part
|
|
38
38
|
const tokensLimit = data.data.limits.find(limit => limit.type === 'TOKENS_LIMIT');
|
|
39
39
|
|
|
40
40
|
if (!tokensLimit) {
|
|
41
|
-
throw new Error('TOKENS_LIMIT
|
|
41
|
+
throw new Error('TOKENS_LIMIT not found in response');
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return tokensLimit;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Formats a number with thousand separators
|
|
49
49
|
*/
|
|
50
50
|
function formatNumber(num) {
|
|
51
|
-
return new Intl.NumberFormat('
|
|
51
|
+
return new Intl.NumberFormat('en-US').format(num);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Formats a timestamp into a readable date
|
|
56
56
|
*/
|
|
57
57
|
function formatDate(timestamp) {
|
|
58
|
-
return new Date(timestamp).toLocaleString('
|
|
59
|
-
timeZone: 'Europe/Paris',
|
|
58
|
+
return new Date(timestamp).toLocaleString('en-US', {
|
|
60
59
|
dateStyle: 'full',
|
|
61
60
|
timeStyle: 'short',
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
|
-
*
|
|
65
|
+
* Calculates time remaining until reset
|
|
67
66
|
*/
|
|
68
67
|
function getTimeRemaining(nextResetTime) {
|
|
69
68
|
const now = Date.now();
|
|
@@ -74,47 +73,47 @@ function getTimeRemaining(nextResetTime) {
|
|
|
74
73
|
const minutes = Math.floor((remaining % (1000 * 60 * 60)) / (1000 * 60));
|
|
75
74
|
|
|
76
75
|
if (days > 0) {
|
|
77
|
-
return `${days}
|
|
76
|
+
return `${days}d ${hours}h ${minutes}m`;
|
|
78
77
|
} else if (hours > 0) {
|
|
79
|
-
return `${hours}h ${minutes}
|
|
78
|
+
return `${hours}h ${minutes}m`;
|
|
80
79
|
} else {
|
|
81
|
-
return `${minutes}
|
|
80
|
+
return `${minutes}m`;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
85
|
+
* Displays token info in a stylized manner
|
|
87
86
|
*/
|
|
88
87
|
function displayTokenInfo(info) {
|
|
89
88
|
console.log('\n' + '='.repeat(50));
|
|
90
|
-
console.log(' π Z.AI -
|
|
89
|
+
console.log(' π Z.AI - TOKEN USAGE');
|
|
91
90
|
console.log('='.repeat(50));
|
|
92
91
|
|
|
93
|
-
//
|
|
92
|
+
// Visual progress bar
|
|
94
93
|
const barLength = 30;
|
|
95
94
|
const filled = Math.round((info.percentage / 100) * barLength);
|
|
96
95
|
const empty = barLength - filled;
|
|
97
96
|
const bar = 'β'.repeat(filled) + 'β'.repeat(empty);
|
|
98
97
|
|
|
99
|
-
console.log(`\n
|
|
100
|
-
console.log(`\n π
|
|
101
|
-
console.log(` π
|
|
102
|
-
console.log(` π―
|
|
98
|
+
console.log(`\n Progress: [${bar}] ${info.percentage}%`);
|
|
99
|
+
console.log(`\n π Used: ${formatNumber(info.currentValue)} tokens`);
|
|
100
|
+
console.log(` π Remaining: ${formatNumber(info.remaining)} tokens`);
|
|
101
|
+
console.log(` π― Limit: ${formatNumber(info.usage)} tokens`);
|
|
103
102
|
|
|
104
103
|
const timeRemaining = getTimeRemaining(info.nextResetTime);
|
|
105
|
-
console.log(`\n β±οΈ Reset
|
|
106
|
-
console.log(` π
|
|
104
|
+
console.log(`\n β±οΈ Reset in: ${timeRemaining}`);
|
|
105
|
+
console.log(` π
Next reset: ${formatDate(info.nextResetTime)}`);
|
|
107
106
|
|
|
108
107
|
console.log('\n' + '='.repeat(50) + '\n');
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
//
|
|
110
|
+
// Entry point
|
|
112
111
|
async function main() {
|
|
113
112
|
try {
|
|
114
113
|
const tokenInfo = await getTokenLimit();
|
|
115
114
|
displayTokenInfo(tokenInfo);
|
|
116
115
|
} catch (error) {
|
|
117
|
-
console.error('β
|
|
116
|
+
console.error('β Error:', error.message);
|
|
118
117
|
process.exit(1);
|
|
119
118
|
}
|
|
120
119
|
}
|