@ponbac/token-ledger 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/main.js +36 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -324,8 +324,11 @@ tool charges, taxes, negotiated discounts, and subscription allocations are not
|
|
|
324
324
|
modeled. Provider-reported credit or dollar figures do not override this estimate.
|
|
325
325
|
|
|
326
326
|
JSON is a versioned report with pricing provenance, applied unit rates, coverage diagnostics, and rows
|
|
327
|
-
grouped by project/day/provider/model. CSV
|
|
328
|
-
|
|
327
|
+
grouped by project/day/provider/model. CSV instead matches the terminal summary:
|
|
328
|
+
one row per project, sorted by known API cost, plus a Total row. It includes token
|
|
329
|
+
totals, API estimates rounded to two decimals, and cost percentages. Incomplete
|
|
330
|
+
costs display `+ unknown`, and percentages use only the known subtotal. Neither
|
|
331
|
+
format includes prompts or responses;
|
|
329
332
|
JSON coverage does contain configured source paths. CSV escapes spreadsheet formula
|
|
330
333
|
prefixes in identifiers. Coverage diagnostics also go to stderr, leaving stdout
|
|
331
334
|
usable for piping.
|
|
@@ -366,7 +369,7 @@ For manual publication:
|
|
|
366
369
|
1. Log in with `npm login` using an account with publish access to `@ponbac/token-ledger`.
|
|
367
370
|
2. Run `bun run check`. The CLI test packs the package, installs it offline outside
|
|
368
371
|
the repository with lifecycle scripts disabled, and exercises the installed CLI.
|
|
369
|
-
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.1.
|
|
372
|
+
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.1.2.tgz` (filename follows version).
|
|
370
373
|
4. Inspect `npm publish ./dist/npm --dry-run`.
|
|
371
374
|
5. Publish with `npm publish ./dist/npm --access public`; complete npm's authentication
|
|
372
375
|
prompt if requested.
|
package/dist/main.js
CHANGED
|
@@ -32623,9 +32623,6 @@ function codexParser(file2) {
|
|
|
32623
32623
|
};
|
|
32624
32624
|
}
|
|
32625
32625
|
|
|
32626
|
-
// packages/core/src/providers/copilot-db.ts
|
|
32627
|
-
import { DatabaseSync } from "node:sqlite";
|
|
32628
|
-
|
|
32629
32626
|
// packages/core/src/providers/copilot.ts
|
|
32630
32627
|
var CopilotAttributes = exports_Schema.Struct({
|
|
32631
32628
|
"gen_ai.operation.name": exports_Schema.optionalKey(exports_Schema.String),
|
|
@@ -32775,6 +32772,10 @@ var Row = exports_Schema.Struct({
|
|
|
32775
32772
|
var databaseError = () => new CopilotDatabaseError({ message: "Cannot read the Copilot span database." });
|
|
32776
32773
|
var copilotDatabaseLines = exports_Effect.fn("Copilot.readDatabase")(function* (file2) {
|
|
32777
32774
|
return yield* exports_Effect.gen(function* () {
|
|
32775
|
+
const { DatabaseSync } = yield* exports_Effect.tryPromise({
|
|
32776
|
+
try: () => import("node:sqlite"),
|
|
32777
|
+
catch: databaseError
|
|
32778
|
+
});
|
|
32778
32779
|
const db = yield* exports_Effect.acquireRelease(exports_Effect.try({ try: () => new DatabaseSync(file2, { readOnly: true }), catch: databaseError }), (connection) => exports_Effect.sync(() => connection.close()));
|
|
32779
32780
|
const keys4 = Object.keys(CopilotAttributes.fields);
|
|
32780
32781
|
const rows = yield* exports_Effect.try({
|
|
@@ -39400,7 +39401,7 @@ var runWith2 = (command, config) => {
|
|
|
39400
39401
|
// packages/cli/package.json
|
|
39401
39402
|
var package_default = {
|
|
39402
39403
|
name: "@ponbac/token-ledger",
|
|
39403
|
-
version: "0.1.
|
|
39404
|
+
version: "0.1.2",
|
|
39404
39405
|
private: true,
|
|
39405
39406
|
type: "module",
|
|
39406
39407
|
bin: {
|
|
@@ -40340,40 +40341,15 @@ function csvCell(value5) {
|
|
|
40340
40341
|
return `"${safe.replaceAll('"', '""')}"`;
|
|
40341
40342
|
}
|
|
40342
40343
|
function csv(report) {
|
|
40343
|
-
const
|
|
40344
|
-
|
|
40345
|
-
|
|
40346
|
-
"provider",
|
|
40347
|
-
"model",
|
|
40348
|
-
"input_tokens",
|
|
40349
|
-
"cache_read_tokens",
|
|
40350
|
-
"cache_write_tokens",
|
|
40351
|
-
"output_tokens",
|
|
40352
|
-
"estimated_api_cost_usd",
|
|
40353
|
-
"priced_subtotal_usd",
|
|
40354
|
-
"unpriced_records"
|
|
40355
|
-
];
|
|
40356
|
-
const rows = report.rows.map((row) => [
|
|
40357
|
-
row.project,
|
|
40358
|
-
row.day,
|
|
40359
|
-
row.provider,
|
|
40360
|
-
row.model,
|
|
40361
|
-
row.tokens.input,
|
|
40362
|
-
row.tokens.cacheRead,
|
|
40363
|
-
row.tokens.cacheWrite,
|
|
40364
|
-
row.tokens.output,
|
|
40365
|
-
row.estimatedCostUsd,
|
|
40366
|
-
row.pricedCostUsd,
|
|
40367
|
-
row.unpricedRecords
|
|
40368
|
-
].map(csvCell).join(","));
|
|
40369
|
-
return [header.join(","), ...rows].join(`
|
|
40344
|
+
const summary = projectSummary(report, false);
|
|
40345
|
+
const headings = summary.headings.map((heading) => heading === "API estimate" ? "API estimate (USD)" : heading);
|
|
40346
|
+
return [headings, ...summary.rows].map((row) => row.map(csvCell).join(",")).join(`
|
|
40370
40347
|
`);
|
|
40371
40348
|
}
|
|
40372
40349
|
function terminalText(value5) {
|
|
40373
40350
|
return value5.replace(/[\x00-\x1f\x7f-\x9f]/g, " ");
|
|
40374
40351
|
}
|
|
40375
|
-
function
|
|
40376
|
-
const paint = (format8, value5) => colorful ? styleText(format8, value5, { validateStream: false }) : value5;
|
|
40352
|
+
function projectSummary(report, grouped2) {
|
|
40377
40353
|
const projects = new Map;
|
|
40378
40354
|
for (const row of report.rows) {
|
|
40379
40355
|
const previous = projects.get(row.project);
|
|
@@ -40383,8 +40359,6 @@ function table2(report, columns = 120, colorful = false) {
|
|
|
40383
40359
|
unpriced: (previous?.unpriced ?? 0) + row.unpricedRecords
|
|
40384
40360
|
});
|
|
40385
40361
|
}
|
|
40386
|
-
if (projects.size === 0)
|
|
40387
|
-
return `No observed usage from ${report.since} through ${report.until} (UTC).`;
|
|
40388
40362
|
const cost = [...projects.values()].reduce((sum3, project) => sum3 + project.cost, 0);
|
|
40389
40363
|
const unpriced = [...projects.values()].reduce((sum3, project) => sum3 + project.unpriced, 0);
|
|
40390
40364
|
const headings = [
|
|
@@ -40402,14 +40376,18 @@ function table2(report, columns = 120, colorful = false) {
|
|
|
40402
40376
|
maximumFractionDigits: 1
|
|
40403
40377
|
});
|
|
40404
40378
|
const share2 = (value5) => cost > 0 ? percentage.format(value5 / cost) : "—";
|
|
40405
|
-
const number4 = new Intl.NumberFormat("en-US");
|
|
40406
|
-
const dollars = new Intl.NumberFormat("en-US", {
|
|
40379
|
+
const number4 = new Intl.NumberFormat("en-US", { useGrouping: grouped2 });
|
|
40380
|
+
const dollars = new Intl.NumberFormat("en-US", {
|
|
40381
|
+
style: "currency",
|
|
40382
|
+
currency: "USD",
|
|
40383
|
+
useGrouping: grouped2
|
|
40384
|
+
});
|
|
40407
40385
|
let allTokens = zeroTokens;
|
|
40408
40386
|
const rows = [];
|
|
40409
40387
|
const ranked = [...projects].toSorted(([leftProject, left], [rightProject, right]) => right.cost - left.cost || leftProject.localeCompare(rightProject));
|
|
40410
40388
|
for (const [project, total] of ranked) {
|
|
40411
40389
|
rows.push([
|
|
40412
|
-
|
|
40390
|
+
project,
|
|
40413
40391
|
number4.format(total.tokens.input),
|
|
40414
40392
|
number4.format(total.tokens.cacheRead),
|
|
40415
40393
|
number4.format(total.tokens.cacheWrite),
|
|
@@ -40419,15 +40397,24 @@ function table2(report, columns = 120, colorful = false) {
|
|
|
40419
40397
|
]);
|
|
40420
40398
|
allTokens = addTokens(allTokens, total.tokens);
|
|
40421
40399
|
}
|
|
40422
|
-
|
|
40423
|
-
|
|
40424
|
-
|
|
40425
|
-
|
|
40426
|
-
|
|
40427
|
-
|
|
40428
|
-
|
|
40429
|
-
|
|
40430
|
-
|
|
40400
|
+
if (projects.size > 0)
|
|
40401
|
+
rows.push([
|
|
40402
|
+
"Total",
|
|
40403
|
+
number4.format(allTokens.input),
|
|
40404
|
+
number4.format(allTokens.cacheRead),
|
|
40405
|
+
number4.format(allTokens.cacheWrite),
|
|
40406
|
+
number4.format(allTokens.output),
|
|
40407
|
+
`${dollars.format(cost)}${unpriced ? " + unknown" : ""}`,
|
|
40408
|
+
share2(cost)
|
|
40409
|
+
]);
|
|
40410
|
+
return { headings, rows, allTokens, unpriced, projectCount: projects.size };
|
|
40411
|
+
}
|
|
40412
|
+
function table2(report, columns = 120, colorful = false) {
|
|
40413
|
+
const paint = (format8, value5) => colorful ? styleText(format8, value5, { validateStream: false }) : value5;
|
|
40414
|
+
const { headings, rows, allTokens, unpriced, projectCount } = projectSummary(report, true);
|
|
40415
|
+
const number4 = new Intl.NumberFormat("en-US");
|
|
40416
|
+
if (projectCount === 0)
|
|
40417
|
+
return `No observed usage from ${report.since} through ${report.until} (UTC).`;
|
|
40431
40418
|
const numericWidths = headings.slice(1).map((heading, i) => Math.max(heading.length, ...rows.map((row) => row[i + 1]?.length ?? 0)) + 2);
|
|
40432
40419
|
const projectWidth = columns - numericWidths.reduce((sum3, width2) => sum3 + width2, 0) - (headings.length + 1);
|
|
40433
40420
|
const narrow = projectWidth < 22;
|
|
@@ -40450,7 +40437,7 @@ function table2(report, columns = 120, colorful = false) {
|
|
|
40450
40437
|
for (const [index2, row] of rows.entries()) {
|
|
40451
40438
|
const styled = row.map((value5, column) => {
|
|
40452
40439
|
const width2 = narrow ? column === 0 ? columns - 4 : columns - 21 : (colWidths[column] ?? 4) - 2;
|
|
40453
|
-
const cell = wrapAnsi(value5, Math.max(2, width2), {
|
|
40440
|
+
const cell = wrapAnsi(terminalText(value5), Math.max(2, width2), {
|
|
40454
40441
|
hard: true,
|
|
40455
40442
|
wordWrap: false,
|
|
40456
40443
|
trim: false
|
|
@@ -40477,7 +40464,7 @@ function table2(report, columns = 120, colorful = false) {
|
|
|
40477
40464
|
"",
|
|
40478
40465
|
output.toString(),
|
|
40479
40466
|
"",
|
|
40480
|
-
paint("bold", `${colorful ? "\uD83D\uDCCA " : ""}${number4.format(totalTokens(allTokens))} observed tokens · ${number4.format(
|
|
40467
|
+
paint("bold", `${colorful ? "\uD83D\uDCCA " : ""}${number4.format(totalTokens(allTokens))} observed tokens · ${number4.format(projectCount)} ${projectCount === 1 ? "project" : "projects"}`),
|
|
40481
40468
|
...unpriced > 0 ? [
|
|
40482
40469
|
paint("yellow", "Incomplete pricing: sorting and percentages use known API subtotals; unknown costs are additional.")
|
|
40483
40470
|
] : [],
|