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

@augmentcode/cosmos-agent-sdk-mongo

v0.0.1-alpha.0

Published

MongoDB SessionSink adapter for @augmentcode/cosmos-agent-sdk (opt-in; keeps the mongodb driver out of the core client)

Readme

@augmentcode/cosmos-agent-sdk-mongo

Opt-in MongoDB SessionSink adapter for @augmentcode/cosmos-agent-sdk. Exports a parsed agent session to MongoDB as typed, queryable documents (per-entry docs + a per-session rollup) for observability and cost analysis — so a Mongo aggregation pipeline runs directly against the collection.

Keeps the mongodb driver out of the core client per the dependency-isolation rule (see the repo AGENTS.md): a consumer that only uses the core client ships no mongodb. Install this package to opt into MongoDB export.

Install

npm install @augmentcode/cosmos-agent-sdk @augmentcode/cosmos-agent-sdk-mongo mongodb

Usage

The sink takes a caller-constructed mongodb client (or Db/Collection) — it never parses a connection URL, so connection secrets stay out of the sink. It runs the SDK's redact() on every batch before the off-box write; redaction is not skippable (a caller may override the policy, not disable it).

import { readSession, redact } from "@augmentcode/cosmos-agent-sdk";
import { MongoSink } from "@augmentcode/cosmos-agent-sdk-mongo";
import { MongoClient } from "mongodb";

const client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const { header, entries } = /* parseSession(...) — see below */ ({} as any);

const sink = new MongoSink({
  client, // or: db / collection — a caller-supplied handle
  database: "cosmos_sdk",
  collectionName: "sessions",
  sessionId: header.id, // read from the reader's header
});

await sink.write(entries); // redacts, then writes one doc per entry
await sink.flush(); // writes the per-session rollup doc
await client.close();

Reading a session from disk (via the core reader) and streaming it live both work — feed write() batches from readSession(...) or from watchSession(...).

Document shape

Per entry (SessionEntryDocument): sessionId, entryId, parentId, entryType, timestamp, and — on usage-bearing entries — model (provider/modelId), toolName, and a flat usage projection ({ input, output, cacheRead, cacheWrite, totalTokens, cost }). The full redacted entry is preserved under entry.

Per session (SessionRollupDocument, kind: "session-rollup"): sessionId, entryCount, totalCost, totalTokens, and perModel[] ({ model, provider, modelId, cost, tokens }).

Per-entry docs are upserted on (sessionId, entryId) and the rollup on (kind, sessionId), so re-running the sink over a growing session is idempotent.

Spend-by-model aggregation

Because the documents are typed (not opaque blobs), a spend-by-model report is a plain aggregation over the per-entry docs:

const spend = await collection
  .aggregate([
    { $match: { kind: { $exists: false }, usage: { $exists: true } } },
    {
      $group: {
        _id: "$model",
        cost: { $sum: "$usage.cost" },
        tokens: { $sum: "$usage.totalTokens" },
      },
    },
    { $sort: { cost: -1 } },
  ])
  .toArray();
// -> [{ _id: "anthropic/claude-sonnet-4-5", cost: 0.03, tokens: 3000 }, ...]

The same totals are also available directly on the rollup document's perModel[] — both agree by construction.