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

pi-rate-limit

v1.0.0

Published

Pi-native runtime resilience toolkit — rate limiting, retry/backoff planning, and circuit-breaker state tracking for pi.dev extensions

Readme

pi-rate-limit

Pi-native runtime resilience toolkit — rate limiting, retry/backoff planning, and circuit-breaker state tracking for pi.dev extensions.

Installation

pi install npm:pi-rate-limit

What It Does

pi-rate-limit gives pi.dev extension developers three essential runtime resilience primitives:

  1. Rate Limiting — Token bucket and sliding window policies to throttle tool/provider calls
  2. Retry Planning — Deterministic exponential backoff with jitter, max attempts, and error classification
  3. Circuit Breakers — Closed/open/half-open state machines to protect against cascading failures

All tools are deterministic, in-memory, and optionally persistent via JSON files. No LLM calls. Integrates conceptually with pi-log, pi-config, pi-perf, and pi-token-router.

Tools

rate_limit_check

Evaluate whether a named tool/provider/action is allowed under a configured rate-limit policy. Supports token bucket (capacity + refill rate) and sliding window (limit + window duration) algorithms.

Parameters:

  • key (string, required) — Named key for the policy
  • action (string) — check | add_policy | remove_policy | reset (default: check)
  • algorithm (string) — token_bucket | sliding_window (required for add_policy)
  • capacity (number) — Token bucket capacity
  • refillRate (number) — Tokens per second
  • limit (number) — Max requests per window
  • windowMs (number) — Window duration in ms
  • consume (boolean) — Whether to consume a token on check (default: true)

Example:

Add a token bucket policy for "openai" with capacity 60 and refill rate 1/sec,
then check if a request is allowed.

retry_plan

Generate a deterministic retry/backoff plan for a failed action. Supports exponential backoff with configurable base delay, multiplier, jitter strategies (none/full/equal), and retryable error classification.

Parameters:

  • attempt (number, required) — Current attempt number
  • maxAttempts (number, required) — Maximum number of attempts
  • baseDelayMs (number, required) — Base delay in milliseconds
  • multiplier (number) — Backoff multiplier (default: 2)
  • maxDelayMs (number) — Maximum delay cap in ms (default: 30000)
  • jitter (object) — { type: "none"|"full"|"equal", seed?: number }
  • retryableErrors (string[]) — List of retryable error class names
  • errorCode (string) — Error code to check
  • errorMessage (string) — Error message to check

Example:

Generate a retry plan for attempt 2 of 5, with 1000ms base delay and full jitter.

circuit_status

Track and report circuit-breaker state (closed/open/half-open) for a named tool/provider. Record successes and failures, check current status, configure thresholds, or manually reset.

Parameters:

  • key (string, required) — Named key for the circuit
  • action (string) — record_success | record_failure | status | reset (default: status)
  • configure (boolean) — Set to true to (re)configure the circuit
  • failureThreshold (number) — Failures to trip circuit (default: 5)
  • cooldownMs (number) — Cooldown duration in ms (default: 30000)
  • halfOpenMaxAttempts (number) — Probe attempts in half-open (default: 1)
  • now (number) — Deterministic timestamp for testing

Example:

Configure a circuit breaker for "anthropic" with threshold 3 and 60s cooldown,
then record a failure and check the status.

Resources

License

MIT