Skip to content

feat: add z.ai token usage status bar extension#1

Merged
j4rviscmd merged 4 commits intomainfrom
feat/zai-statusbar
Mar 12, 2026
Merged

feat: add z.ai token usage status bar extension#1
j4rviscmd merged 4 commits intomainfrom
feat/zai-statusbar

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

@j4rviscmd j4rviscmd commented Mar 12, 2026

Summary

  • Add VSCode extension that displays z.ai token usage percentage in the status bar
  • Implement API key management via VSCode Secrets API (set/clear commands)
  • Add caching layer with configurable refresh interval to reduce API calls
  • Support custom icon or text label via zaiUsage.useIcon setting
  • Automatically invalidate cache when reset time has passed

Changes

src/extension.ts

  • Status bar item showing token usage percentage with time-until-reset
  • fetchFromApi: fetches /api/monitor/usage/quota/limit with Bearer auth
  • fetchUsage: cache-first fetch with fallback to stale cache on API failure
  • isCacheValid: invalidates cache when refresh interval elapsed or nextResetTime passed
  • Commands: zaiUsage.setApiKey (with verification), zaiUsage.clearApiKey
  • Configuration change listener for live refresh interval / icon toggle

Config files

  • package.json: extension manifest, commands, configuration schema, CI scripts
  • tsconfig.json: TypeScript compiler settings (ES2020, strict)
  • biome.json: Biome linter/formatter configuration

Code quality

  • Redundant intermediate variables removed (refreshIntervalMs, nowMs, cacheData)
  • Section divider comments removed (function names are self-explanatory)
  • Inline comments scoped to non-obvious logic only
  • Array.isArray guard simplified (covers null/undefined implicitly)
  • setCache uses satisfies CacheData for type safety without intermediate variable

Refactoring

  • Extract API_URL constant at module level to eliminate magic strings
  • Reorder function definitions by dependency for top-to-bottom readability
  • Extract applyNoApiKeyState() helper to consolidate duplicated 3-line block (DRY)
  • Inline headers in fetchFromApi to reduce nesting
  • Align return object literals in fetchUsage for visual consistency
  • Annotate return type : void consistently on activate, startInterval, updateStatusBar, and deactivate

Documentation

  • Add JSDoc comments (English) to all interfaces: ZaiLimit, ZaiApiResponse, CacheData, UsageData
  • Document all interface properties with @ field descriptions
  • Add JSDoc to module-level constants: CACHE_VERSION, CACHE_KEY, API_KEY_SECRET, API_URL
  • Add JSDoc to setApiKeyCmd and clearApiKeyCmd command callbacks
  • Add JSDoc to the onDidChangeConfiguration handler
  • All comments and documentation are in English

- Add z.ai token usage display in VS Code status bar
- Implement API key management via VS Code Secret Storage
- Add configurable refresh interval with 10s minimum clamp
- Fix clearApiKey command not resetting statusBarItem.command
- Replace deprecated actions/create-release@v1 with softprops/action-gh-release@v2
- Add CI workflow (Biome check, TypeScript typecheck, build)
- Add publish workflow with tag-based deduplication
@j4rviscmd j4rviscmd marked this pull request as draft March 12, 2026 12:10
@j4rviscmd j4rviscmd self-assigned this Mar 12, 2026
@j4rviscmd j4rviscmd added the enhancement New feature or request label Mar 12, 2026
@j4rviscmd j4rviscmd marked this pull request as ready for review March 12, 2026 13:52
@j4rviscmd j4rviscmd merged commit c88ac9f into main Mar 12, 2026
4 checks passed
@j4rviscmd j4rviscmd deleted the feat/zai-statusbar branch March 12, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant