{"_id":"@augmentcode/cosmos-agent-sdk-mongo","_rev":"4-d98b7cdd77f209c100096904a7672875","name":"@augmentcode/cosmos-agent-sdk-mongo","dist-tags":{"latest":"0.0.1-alpha.0","alpha":"0.0.1-alpha.0"},"versions":{"0.0.1-alpha.0":{"name":"@augmentcode/cosmos-agent-sdk-mongo","version":"0.0.1-alpha.0","keywords":["augment","auggie","agent","sdk","mongodb","sink"],"author":{"name":"Augment Code Inc."},"license":"MIT","_id":"@augmentcode/cosmos-agent-sdk-mongo@0.0.1-alpha.0","maintainers":[{"name":"arnabauggie","email":"arnab@augmentcode.com"},{"name":"dmitirykh-augmentcode","email":"dmitriy@augmentcode.com"},{"name":"mgm-augment","email":"matthewm@augmentcode.com"},{"name":"harry-augmentcode","email":"harry@augmentcode.com"},{"name":"moogi","email":"moogi@augmentcode.com"},{"name":"siyu-augment","email":"siyu@augmentcode.com"},{"name":"tulga","email":"tulga@augmentcode.com"},{"name":"augmentck","email":"chris@augmentcode.com"},{"name":"justinxu421","email":"justinxu@augmentcode.com"}],"homepage":"https://github.com/augmentcode/cosmos-agent-sdk/tree/main/clients/typescript-mongo#readme","bugs":{"url":"https://github.com/augmentcode/cosmos-agent-sdk/issues"},"dist":{"shasum":"820d21ac998a710306c23d3dcb026053d311c888","tarball":"https://registry.npmjs.org/@augmentcode/cosmos-agent-sdk-mongo/-/cosmos-agent-sdk-mongo-0.0.1-alpha.0.tgz","fileCount":4,"integrity":"sha512-qJFubxnOfY2zTIE9Lb1KcGNPlq6XJ5ANc0JgJvxOQNNTc1FtLzbtVs1la+n7kWVK54xeOgVvbmnzUxPLtxVeUw==","signatures":[{"sig":"MEUCIQCRJN6V9kMnhKmMeeJRBcuyfbCXyL8NvKEQEqd20ttzHQIgDofZeSOmpNdHZQNOD9bWU9e0yQL98cgjNThYFj7FH/k=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12754},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"1cf016ac6c11e8b8611a2e11926bc5bfc3a83b6d","scripts":{"demo":"bun run demo.ts","lint":"biome ci --reporter=github .","test":"bun test","build":"tsup","format":"biome format --write .","prepublishOnly":"bun run build"},"_npmUser":{"name":"mgm-augment","email":"matthewm@augmentcode.com"},"repository":{"url":"git+https://github.com/augmentcode/cosmos-agent-sdk.git","type":"git","directory":"clients/typescript-mongo"},"_npmVersion":"10.8.2","description":"MongoDB SessionSink adapter for @augmentcode/cosmos-agent-sdk (opt-in; keeps the mongodb driver out of the core client)","directories":{},"_nodeVersion":"20.20.2","dependencies":{"mongodb":"^6","@augmentcode/cosmos-agent-sdk":"^0.0.1-alpha.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","ultracite":"6.3.0","@types/bun":"latest","typescript":"^5","@biomejs/biome":"2.3.4"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/cosmos-agent-sdk-mongo_0.0.1-alpha.0_1783810876022_0.8947161608710699","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-07-11T23:01:15.816Z","modified":"2026-08-25T18:16:42.209Z","0.0.1-alpha.0":"2026-07-11T23:01:16.142Z"},"bugs":{"url":"https://github.com/augmentcode/cosmos-agent-sdk/issues"},"author":{"name":"Augment Code Inc."},"license":"MIT","homepage":"https://github.com/augmentcode/cosmos-agent-sdk/tree/main/clients/typescript-mongo#readme","keywords":["augment","auggie","agent","sdk","mongodb","sink"],"repository":{"url":"git+https://github.com/augmentcode/cosmos-agent-sdk.git","type":"git","directory":"clients/typescript-mongo"},"description":"MongoDB SessionSink adapter for @augmentcode/cosmos-agent-sdk (opt-in; keeps the mongodb driver out of the core client)","maintainers":[{"email":"arnab@augmentcode.com","name":"arnabauggie"},{"email":"dmitriy@augmentcode.com","name":"dmitirykh-augmentcode"},{"email":"matthewm@augmentcode.com","name":"mgm-augment"},{"email":"moogi@augmentcode.com","name":"moogi"},{"email":"harry@augmentcode.com","name":"harry-augmentcode"},{"email":"siyu@augmentcode.com","name":"siyu-augment"},{"email":"theonlytulga@gmail.com","name":"tulga"},{"email":"chris@augmentcode.com","name":"augmentck"}],"readme":"# @augmentcode/cosmos-agent-sdk-mongo\n\nOpt-in MongoDB `SessionSink` adapter for\n[`@augmentcode/cosmos-agent-sdk`](../typescript). Exports a parsed agent session\nto MongoDB as **typed, queryable documents** (per-entry docs + a per-session\nrollup) for observability and cost analysis — so a Mongo aggregation pipeline\nruns directly against the collection.\n\nKeeps the `mongodb` driver out of the core client per the dependency-isolation\nrule (see the repo [`AGENTS.md`](../../AGENTS.md#dependency-isolation-standing-rule)):\na consumer that only uses the core client ships no `mongodb`. Install this\npackage to opt into MongoDB export.\n\n## Install\n\n```sh\nnpm install @augmentcode/cosmos-agent-sdk @augmentcode/cosmos-agent-sdk-mongo mongodb\n```\n\n## Usage\n\nThe sink takes a **caller-constructed** `mongodb` client (or `Db`/`Collection`) —\nit never parses a connection URL, so connection secrets stay out of the sink. It\nruns the SDK's `redact()` on every batch **before** the off-box write; redaction\nis not skippable (a caller may override the policy, not disable it).\n\n```ts\nimport { readSession, redact } from \"@augmentcode/cosmos-agent-sdk\";\nimport { MongoSink } from \"@augmentcode/cosmos-agent-sdk-mongo\";\nimport { MongoClient } from \"mongodb\";\n\nconst client = new MongoClient(process.env.MONGODB_URI!);\nawait client.connect();\n\nconst { header, entries } = /* parseSession(...) — see below */ ({} as any);\n\nconst sink = new MongoSink({\n  client, // or: db / collection — a caller-supplied handle\n  database: \"cosmos_sdk\",\n  collectionName: \"sessions\",\n  sessionId: header.id, // read from the reader's header\n});\n\nawait sink.write(entries); // redacts, then writes one doc per entry\nawait sink.flush(); // writes the per-session rollup doc\nawait client.close();\n```\n\nReading a session from disk (via the core reader) and streaming it live both\nwork — feed `write()` batches from `readSession(...)` or from `watchSession(...)`.\n\n### Document shape\n\nPer entry (`SessionEntryDocument`): `sessionId`, `entryId`, `parentId`,\n`entryType`, `timestamp`, and — on usage-bearing entries — `model`\n(`provider/modelId`), `toolName`, and a flat `usage` projection\n(`{ input, output, cacheRead, cacheWrite, totalTokens, cost }`). The full\nredacted entry is preserved under `entry`.\n\nPer session (`SessionRollupDocument`, `kind: \"session-rollup\"`): `sessionId`,\n`entryCount`, `totalCost`, `totalTokens`, and `perModel[]`\n(`{ model, provider, modelId, cost, tokens }`).\n\nPer-entry docs are upserted on `(sessionId, entryId)` and the rollup on\n`(kind, sessionId)`, so re-running the sink over a growing session is idempotent.\n\n### Spend-by-model aggregation\n\nBecause the documents are typed (not opaque blobs), a spend-by-model report is a\nplain aggregation over the per-entry docs:\n\n```ts\nconst spend = await collection\n  .aggregate([\n    { $match: { kind: { $exists: false }, usage: { $exists: true } } },\n    {\n      $group: {\n        _id: \"$model\",\n        cost: { $sum: \"$usage.cost\" },\n        tokens: { $sum: \"$usage.totalTokens\" },\n      },\n    },\n    { $sort: { cost: -1 } },\n  ])\n  .toArray();\n// -> [{ _id: \"anthropic/claude-sonnet-4-5\", cost: 0.03, tokens: 3000 }, ...]\n```\n\nThe same totals are also available directly on the rollup document's\n`perModel[]` — both agree by construction.\n","readmeFilename":"README.md"}