npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@harms-haus/pi-zai-usage

v0.1.0

Published

Z.ai API quota monitor extension for pi-coding-agent

Readme

pi-zai-usage

A lightweight pi coding agent extension that monitors your Z.ai token quota in real time and displays a color-coded progress bar in the terminal footer via pi-powerline.

Features

  • Fetches Z.ai token quota usage from the official API
  • Displays a color-coded progress bar in the pi-powerline footer (Line 2, right-aligned)
  • Caches responses for 60 seconds to minimize API calls
  • Automatically activates only when a Z.ai provider is selected
  • Gracefully handles network errors, missing API keys, and headless sessions

Installation

pi install git:github.com/harms-haus/pi-zai-usage

Then restart pi or run /reload.

How It Works

When a Z.ai model is selected (provider name starts with "zai"), this extension:

  1. Fetches your current token quota from GET https://api.z.ai/api/monitor/usage/quota/limit
  2. Extracts the TOKENS_LIMIT entry from the response
  3. Publishes the usage percentage and reset time to the UI via ctx.ui.setStatus()

The published status is consumed by pi-powerline, which renders it as a color-coded progress bar on footer Line 2, right-aligned.

Caching

Responses are cached for 60 seconds. Within the TTL, cached data is returned immediately without an API call. The cache is cleared when the selected provider changes (e.g., switching from Z.ai to another provider). Switching between Z.ai models preserves the cache.

Events

The extension listens to the following pi lifecycle events:

| Event | Behavior | | ------------------ | ------------------------------------------------------------------------------- | | session_start | Fetches and publishes usage data | | model_select | Clears the cache if the provider changed, then fetches and publishes usage data | | turn_end | Fetches and publishes usage data (respects cache TTL) | | session_shutdown | Clears the status display |

When no UI is available, all events return early. When the active provider is not Z.ai, the handlers clear any previously published status rather than fetching new data.

Status Payload

The extension publishes under the status key "zai-usage":

{ "percentage": 42.5, "resetTimeMs": 1719360000000 }

| Field | Type | Description | | ------------- | --------------------- | ---------------------------------------------------------------------- | | percentage | number | Token quota used, rounded to one decimal place and clamped to [0, 100] | | resetTimeMs | number \| undefined | Unix timestamp (ms) when the quota resets |

Requirements

  • Z.ai API key — configure via /login for the zai provider in pi
  • pi-powerline — renders the progress bar in the footer (optional; without it the status is still published but not displayed)

Integration with pi-powerline

The progress bar is rendered by pi-powerline on footer Line 2, right-aligned. Install both extensions for the full experience:

pi install git:github.com/harms-haus/pi-powerline
pi install git:github.com/harms-haus/pi-zai-usage

License

MIT

Contributing

See CONTRIBUTING.md for development setup and PR guidelines.