Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## Features

- Shows token quota usage (e.g. `45% (2h30m)`) in the status bar
- Shows token quota usage (e.g. `45% (2h30m)`) or remaining tokens (e.g. `55% (2h30m)`) in the status bar
- Displays time remaining until quota resets when available
- Automatically refreshes at a configurable interval
- Secure API key storage via VS Code Secret Storage
Expand All @@ -26,10 +26,11 @@
| ------------------------------ | --------------- |
| Authenticated, usage available | `⬡ 45% (2h30m)` |
| Authenticated, no reset time | `⬡ 45%` |
| Authenticated, remaining mode | `⬡ 55% (2h30m)` |
| API key not set | `⬡ Set API Key` |
| Error / fetch failed | `⬡ -` |

> The `⬡` icon is the z.ai icon. Set `zaiUsage.useIcon: false` to display `z.ai:` as a text prefix instead.
> The `⬡` icon is the z.ai icon. Set `zaiUsage.useIcon: false` to display `z.ai:` as a text prefix instead. Set `zaiUsage.displayMode: "remaining"` to show remaining tokens instead of usage.

## Setup

Expand All @@ -47,10 +48,11 @@

## Settings

| Setting | Type | Default | Description |
| -------------------------- | --------- | ------- | -------------------------------------------------- |
| `zaiUsage.refreshInterval` | `number` | `60` | Data refresh interval in seconds |
| `zaiUsage.useIcon` | `boolean` | `true` | Use z.ai icon (`⬡`) instead of text prefix `z.ai:` |
| Setting | Type | Default | Description |
| -------------------------- | --------- | ------- | ------------------------------------------------------------------------------------ |
| `zaiUsage.refreshInterval` | `number` | `60` | Data refresh interval in seconds |
| `zaiUsage.useIcon` | `boolean` | `true` | Use z.ai icon (`⬡`) instead of text prefix `z.ai:` |
| `zaiUsage.displayMode` | `string` | `usage` | Display mode: `"usage"` (e.g. `75.3%`) or `"remaining"` (e.g. `24.7%`) in status bar |

## Requirements

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
"type": "number",
"default": 10000,
"description": "Priority of the z.ai Usage item in the status bar (higher = further left among right-aligned items). Change takes effect after reloading the window."
},
"zaiUsage.displayMode": {
"type": "string",
"enum": ["usage", "remaining"],
"default": "usage",
"enumDescriptions": [
"Display token usage (e.g. 75.3%)",
"Display remaining tokens (e.g. 24.7%)"
],
"description": "Whether to display token usage or remaining tokens in the status bar."
}
}
}
Expand Down
32 changes: 26 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,30 @@ export function activate(context: vscode.ExtensionContext): void {
statusBarItem.command = undefined;
const refreshSec = getRefreshInterval() / 1000;
const resetStr = formatResetTime(usage.nextResetTime);

// Get display mode setting (default: "usage")
const displayMode = vscode.workspace
.getConfiguration("zaiUsage")
.get<string>("displayMode", "usage");

// Calculate display percentage based on display mode
const isRemaining = displayMode === "remaining";
const displayPercentage = isRemaining
? Math.round((100 - usage.percentage) * 10) / 10
: usage.percentage;

const suffix = resetStr
? `${usage.percentage}% ${resetStr}`
: `${usage.percentage}%`;
? `${displayPercentage}% ${resetStr}`
: `${displayPercentage}%`;
statusBarItem.text = getLabel(suffix);
statusBarItem.tooltip = `z.ai token usage: ${usage.percentage}%${resetStr ? ` — resets in ${resetStr.replace(/[()]/g, "")}` : ""} (auto-refreshes every ${refreshSec}s)`;

// Build tooltip text
const resetTooltip = resetStr
? ` — resets in ${resetStr.replace(/[()]/g, "")}`
: "";
statusBarItem.tooltip =
`z.ai token ${displayMode}: ${displayPercentage}%${resetTooltip} ` +
`(auto-refreshes every ${refreshSec}s)`;
}

if (apiCalled) {
Expand Down Expand Up @@ -462,8 +481,8 @@ export function activate(context: vscode.ExtensionContext): void {
/**
* Listens for workspace configuration changes and re-applies them immediately.
*
* When `zaiUsage.refreshInterval` or `zaiUsage.useIcon` changes, the status bar
* is refreshed and the polling interval is restarted so the new settings take
* When `zaiUsage.refreshInterval`, `zaiUsage.useIcon`, or `zaiUsage.displayMode` changes,
* the status bar is refreshed and the polling interval is restarted so the new settings take
* effect without requiring a window reload.
*
* When `zaiUsage.statusBarPriority` changes, the user is notified that a window
Expand All @@ -473,7 +492,8 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.workspace.onDidChangeConfiguration((e) => {
if (
e.affectsConfiguration("zaiUsage.refreshInterval") ||
e.affectsConfiguration("zaiUsage.useIcon")
e.affectsConfiguration("zaiUsage.useIcon") ||
e.affectsConfiguration("zaiUsage.displayMode")
) {
updateStatusBar();
startInterval();
Expand Down
Loading