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

context-window-economics

v0.1.0

Published

Bilateral cost allocation, context pricing, and resource markets for autonomous agent interactions — TypeScript reference implementation

Downloads

110

Readme

context-window-economics (TypeScript)

Bilateral cost allocation, context pricing, and resource markets for autonomous agent interactions. TypeScript reference implementation of the Context Window Economics Protocol (CWEP).

Part of the AB Support Trust Ecosystem — Layer 4 (Market/Economics).

What It Does

CWEP tracks and allocates the real inference costs of agent-to-agent interactions across all four token flows:

  • Request Output (RO) — requestor generates the request
  • Request Input (RI) — responder processes the request (the "cost of understanding")
  • Response Output (SO) — responder generates the response
  • Response Input (SI) — requestor processes the response

Install

npm install context-window-economics

Requires Node.js >= 18.0.0. Zero runtime dependencies.

Quick Start

import { Meter, allocate, SettlementEngine, SettlementTier } from "context-window-economics";

// Create a meter for your agent
const meter = new Meter({
  agentId: "did:web:my-agent",
  model: "claude-sonnet-4-6",
  provider: "anthropic",
});

// Record an interaction
const cmr = meter.recordInteraction({
  responderId: "did:web:other-agent",
  requestTokens: 10000,
  responseTokens: 3000,
});

console.log(`Total cost: $${cmr.totals.totalCostUsd.toFixed(4)}`);
console.log(`Requestor incurred: $${cmr.totals.requestorIncurredUsd.toFixed(4)}`);
console.log(`Responder incurred: $${cmr.totals.responderIncurredUsd.toFixed(4)}`);

// Compute fair cost allocation (Shapley value)
const proposal = allocate(cmr, "shapley");
console.log(`Requestor should pay: $${proposal.requestorPaysUsd.toFixed(4)}`);
console.log(`Responder should pay: $${proposal.responderPaysUsd.toFixed(4)}`);

Modules

| Module | Description | |--------|-------------| | types | Enums, constants, data structures (CMR, AgentPricing, TokenFlow, etc.) | | metering | Token meter, flow cost computation, cost estimation | | allocation | Cost allocation: requestor-pays, responder-pays, equal split, proportional, Shapley, Nash | | settlement | Settlement engine, batching, CMR hashing, payment rail abstraction | | spam | Deposit calculation, reputation-based access, progressive request limits | | congestion | Congestion pricing, QoS tiers, back-pressure signals, position-dependent pricing | | caching | Cache amortization, compression ROI, memory vs. context crossover analysis | | store | Append-only JSONL persistence for CMRs, settlements, and deposits |

Allocation Methods

  • Requestor pays — status quo: requestor bears 100% of cost
  • Responder pays — responder bears 100%
  • Equal split — 50/50
  • Proportional — split by token share
  • Shapley value — fair division based on marginal contribution (recommended)
  • Nash bargaining — bilateral negotiation with configurable bargaining power

Build

npm install
npm run build
npm test

Configuration

Provider pricing defaults are included for Anthropic, OpenAI, and Google models as of March 2026. Custom pricing:

import { AgentPricing, Meter } from "context-window-economics";

const customPricing = new AgentPricing({
  inputRatePerMtok: 2.0,
  outputRatePerMtok: 10.0,
  cacheHitRatePerMtok: 0.2,
});

const meter = new Meter({
  agentId: "my-agent",
  pricing: customPricing,
});

Trust Ecosystem Integration

CWEP integrates with:

  • Chain of ConsciousnesscocChainRef field links CMRs to CoC entries
  • Agent Rating Protocol — reputation scores drive deposit multipliers and access tiers
  • Agent Service Agreements — cost terms embedded in contracts reference CWEP allocation methods

License

Apache-2.0