@trazum/cli 2.7.3 → 2.7.5
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/dist/gateway-spend.d.ts.map +1 -1
- package/dist/gateway-spend.js +4 -0
- package/dist/gateway-spend.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +13 -5
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +13 -5
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +16 -2
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -6
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +4 -0
- package/dist/markdown.js.map +1 -1
- package/package.json +2 -2
- package/src/gateway-spend.ts +4 -0
- package/src/i18n/en.ts +22 -7
- package/src/i18n/es.ts +22 -7
- package/src/i18n/types.ts +16 -2
- package/src/index.ts +58 -4
- package/src/markdown.ts +6 -0
package/src/index.ts
CHANGED
|
@@ -140,6 +140,8 @@ import {
|
|
|
140
140
|
looksLikeLiteLlm,
|
|
141
141
|
looksLikeOpenaiUsage,
|
|
142
142
|
looksLikeOpenrouterActivity,
|
|
143
|
+
looksLikeBatchResults,
|
|
144
|
+
batchResultRecords,
|
|
143
145
|
looksLikeOtel,
|
|
144
146
|
openaiCostReport,
|
|
145
147
|
openaiUsageRecords,
|
|
@@ -3336,7 +3338,10 @@ async function commandReconcile(args: Args, t: CliMessages): Promise<void> {
|
|
|
3336
3338
|
const against = stringFlag(args, 'against');
|
|
3337
3339
|
if (against === undefined) throw new Error(t.reconcile.noReport());
|
|
3338
3340
|
|
|
3339
|
-
let receipt: {
|
|
3341
|
+
let receipt: {
|
|
3342
|
+
total?: { usd?: unknown; batchUsd?: unknown; webSearchUsd?: unknown };
|
|
3343
|
+
span?: { fromMs?: unknown; toMs?: unknown };
|
|
3344
|
+
};
|
|
3340
3345
|
try {
|
|
3341
3346
|
receipt = JSON.parse(await readFile(file, 'utf8'));
|
|
3342
3347
|
} catch {
|
|
@@ -3361,7 +3366,19 @@ async function commandReconcile(args: Args, t: CliMessages): Promise<void> {
|
|
|
3361
3366
|
const billed = openai ?? anthropicCostReport(billedText);
|
|
3362
3367
|
if (billed.unparseable) throw new Error(t.reconcile.notAReport(against));
|
|
3363
3368
|
|
|
3364
|
-
|
|
3369
|
+
/* The receipt's own batch and search figures, when it is new enough to carry them. */
|
|
3370
|
+
const figure = (value: unknown): number | undefined =>
|
|
3371
|
+
typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
3372
|
+
const batchUsd = figure(receipt.total?.batchUsd);
|
|
3373
|
+
const webSearchUsd = figure(receipt.total?.webSearchUsd);
|
|
3374
|
+
const answer = reconcile(
|
|
3375
|
+
{
|
|
3376
|
+
usd, fromMs, toMs,
|
|
3377
|
+
...(batchUsd === undefined ? {} : { batchUsd }),
|
|
3378
|
+
...(webSearchUsd === undefined ? {} : { webSearchUsd }),
|
|
3379
|
+
},
|
|
3380
|
+
billed,
|
|
3381
|
+
);
|
|
3365
3382
|
const json = JSON.stringify(answer, null, 2);
|
|
3366
3383
|
|
|
3367
3384
|
const out = stringFlag(args, 'out') ?? stringFlag(args, 'o');
|
|
@@ -3393,8 +3410,15 @@ async function commandReconcile(args: Args, t: CliMessages): Promise<void> {
|
|
|
3393
3410
|
|
|
3394
3411
|
console.error(t.reconcile.summary(answer.computedUsd, answer.billedUsd, answer.differenceUsd));
|
|
3395
3412
|
if (answer.attributable) {
|
|
3396
|
-
if (answer.notTokensUsd !== 0
|
|
3397
|
-
|
|
3413
|
+
if (answer.notTokensUsd !== 0 || (answer.computedWebSearchUsd ?? 0) !== 0) {
|
|
3414
|
+
console.error(t.reconcile.notTokens(answer.notTokensUsd, answer.computedWebSearchUsd ?? 0));
|
|
3415
|
+
}
|
|
3416
|
+
if (answer.batchUsd !== 0 || (answer.computedBatchUsd ?? 0) !== 0) {
|
|
3417
|
+
console.error(t.reconcile.batch(answer.batchUsd, answer.computedBatchUsd ?? 0));
|
|
3418
|
+
}
|
|
3419
|
+
if (!answer.computedSplitKnown && (answer.batchUsd !== 0 || answer.notTokensUsd !== 0)) {
|
|
3420
|
+
console.error(t.reconcile.splitUnknown());
|
|
3421
|
+
}
|
|
3398
3422
|
console.error(t.reconcile.remainder(answer.remainderUsd));
|
|
3399
3423
|
if (!answer.batchSeparable) console.error(t.reconcile.batchNotSeparable());
|
|
3400
3424
|
if (openai !== null && openai.unknownUnitUsd !== 0) {
|
|
@@ -3516,7 +3540,18 @@ function printReceiptSummary(document: ReceiptDocument, t: CliMessages): void {
|
|
|
3516
3540
|
t.profile.tierCeiling(gap.calls, gap.models.join(', '), formatUsd(gap.ceilingUsd), formatUsd(gap.floorUsd)),
|
|
3517
3541
|
);
|
|
3518
3542
|
}
|
|
3543
|
+
if (gap.kind === 'unpriced-web-search') {
|
|
3544
|
+
console.error(t.receipt.unpricedWebSearch(gap.requests, gap.models.join(', ')));
|
|
3545
|
+
}
|
|
3519
3546
|
}
|
|
3547
|
+
/*
|
|
3548
|
+
* Priced searches are not a gap: they are in the total. Said once anyway,
|
|
3549
|
+
* because a per-search fee is a line nobody expects on a token bill, and a
|
|
3550
|
+
* total that grew by it with nothing on screen reads as a pricing error.
|
|
3551
|
+
*/
|
|
3552
|
+
const searches = document.lines.reduce((sum, line) => sum + line.webSearchRequests, 0);
|
|
3553
|
+
const searchUsd = document.lines.reduce((sum, line) => sum + line.money.webSearchUsd, 0);
|
|
3554
|
+
if (searches > 0) console.error(t.receipt.webSearch(searches, formatUsd(searchUsd)));
|
|
3520
3555
|
}
|
|
3521
3556
|
|
|
3522
3557
|
/** The shapes `bill` can tell apart from a file's own text. */
|
|
@@ -3530,6 +3565,7 @@ type UsageSource =
|
|
|
3530
3565
|
| 'langsmith'
|
|
3531
3566
|
| 'anthropic-usage'
|
|
3532
3567
|
| 'openai-usage'
|
|
3568
|
+
| 'batch-results'
|
|
3533
3569
|
| 'openrouter'
|
|
3534
3570
|
| 'usage-log';
|
|
3535
3571
|
|
|
@@ -3546,6 +3582,7 @@ function usageSourcesOf(text: string): UsageSource[] {
|
|
|
3546
3582
|
if (looksLikeOtel(text)) claims.push('otel');
|
|
3547
3583
|
if (looksLikeAnthropicUsage(text)) claims.push('anthropic-usage');
|
|
3548
3584
|
if (looksLikeOpenaiUsage(text)) claims.push('openai-usage');
|
|
3585
|
+
if (looksLikeBatchResults(text)) claims.push('batch-results');
|
|
3549
3586
|
if (looksLikeOpenrouterActivity(text)) claims.push('openrouter');
|
|
3550
3587
|
if (looksLikeHelicone(text)) claims.push('helicone');
|
|
3551
3588
|
if (looksLikeLangsmith(text)) claims.push('langsmith');
|
|
@@ -3771,6 +3808,14 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
|
|
|
3771
3808
|
leftOut = c.unnamedModel + c.batch + c.nonDefaultTier + c.unsplitRows;
|
|
3772
3809
|
break;
|
|
3773
3810
|
}
|
|
3811
|
+
case 'batch-results': {
|
|
3812
|
+
/* A provider's Batch API results: every billed line at the batch rate,
|
|
3813
|
+
and the requests the provider says it did not bill left out. */
|
|
3814
|
+
const c = batchResultRecords(text, withLabel);
|
|
3815
|
+
records = c.records;
|
|
3816
|
+
leftOut = c.unpriceable + c.unparseable;
|
|
3817
|
+
break;
|
|
3818
|
+
}
|
|
3774
3819
|
case 'openrouter': {
|
|
3775
3820
|
const c = openrouterActivityRecords(text, withLabel);
|
|
3776
3821
|
records = c.records;
|
|
@@ -4723,6 +4768,7 @@ async function commandFromAnthropic(args: Args, t: CliMessages): Promise<void> {
|
|
|
4723
4768
|
acts in: what was read, then what was left out, then what to ask for. */
|
|
4724
4769
|
console.error(t.fromAnthropic.summary(conversion.buckets, conversion.rows));
|
|
4725
4770
|
if (conversion.unnamedModel > 0) console.error(t.fromAnthropic.unnamedModel(conversion.unnamedModel));
|
|
4771
|
+
if (conversion.batchRows > 0) console.error(t.fromAnthropic.batchPriced(conversion.batchRows));
|
|
4726
4772
|
if (conversion.nonStandardTier > 0) {
|
|
4727
4773
|
console.error(t.fromAnthropic.nonStandardTier(conversion.nonStandardTier));
|
|
4728
4774
|
}
|
|
@@ -4740,6 +4786,7 @@ async function commandFromAnthropic(args: Args, t: CliMessages): Promise<void> {
|
|
|
4740
4786
|
console.error(t.fromAnthropic.geoUnknown(conversion.geoUnknownMultiplied));
|
|
4741
4787
|
}
|
|
4742
4788
|
if (conversion.webSearchRequests > 0) console.error(t.fromAnthropic.webSearch(conversion.webSearchRequests));
|
|
4789
|
+
if (conversion.webSearchLeftOut > 0) console.error(t.fromAnthropic.webSearchLeftOut(conversion.webSearchLeftOut));
|
|
4743
4790
|
if (conversion.labelledByWorkspace > 0) {
|
|
4744
4791
|
console.error(t.fromAnthropic.labelledByWorkspace(conversion.labelledByWorkspace));
|
|
4745
4792
|
}
|
|
@@ -4790,6 +4837,7 @@ async function commandFromOpenai(args: Args, t: CliMessages): Promise<void> {
|
|
|
4790
4837
|
was left out and why, what to ask the endpoint for next time. */
|
|
4791
4838
|
console.error(t.fromOpenai.summary(conversion.buckets, conversion.rows, conversion.requests));
|
|
4792
4839
|
if (conversion.unnamedModel > 0) console.error(t.fromOpenai.unnamedModel(conversion.unnamedModel));
|
|
4840
|
+
if (conversion.batchRows > 0) console.error(t.fromOpenai.batchPriced(conversion.batchRows));
|
|
4793
4841
|
if (conversion.batch > 0) console.error(t.fromOpenai.batch(conversion.batch));
|
|
4794
4842
|
if (!conversion.batchNamed && conversion.rows > 0) console.error(t.fromOpenai.batchUnknown());
|
|
4795
4843
|
if (conversion.serviceTierRows > 0) {
|
|
@@ -11877,6 +11925,12 @@ async function commandProfile(
|
|
|
11877
11925
|
for (const [name, usd, share, tokens] of parts) {
|
|
11878
11926
|
console.log(` ${bar(share)} ${t.profile.part(name, formatUsd(usd), pct(share), n(tokens))}`);
|
|
11879
11927
|
}
|
|
11928
|
+
// Billed per search, so it counts searches where the rows above count tokens.
|
|
11929
|
+
if (report.total.webSearchRequests > 0) {
|
|
11930
|
+
console.log(
|
|
11931
|
+
` ${bar(shares.webSearch)} ${t.profile.partSearches(t.profile.partWebSearch(), formatUsd(report.total.webSearchUsd), pct(shares.webSearch), report.total.webSearchRequests)}`,
|
|
11932
|
+
);
|
|
11933
|
+
}
|
|
11880
11934
|
|
|
11881
11935
|
/**
|
|
11882
11936
|
* The line the command exists for: which part of the bill to argue with.
|
package/src/markdown.ts
CHANGED
|
@@ -968,6 +968,12 @@ export function renderProfileMarkdown(input: ProfileMarkdownInput): string {
|
|
|
968
968
|
// Catalogue text, not user data: no escaping into a code cell needed.
|
|
969
969
|
lines.push(`| ${name} | ${formatUsd(usd)} | ${pct(share)} | ${n(tokens)} |`);
|
|
970
970
|
}
|
|
971
|
+
// Billed per search, not per token, so its count is not in the tokens column.
|
|
972
|
+
if (report.total.webSearchRequests > 0) {
|
|
973
|
+
lines.push(
|
|
974
|
+
`| ${t.profile.partWebSearch()} (${n(report.total.webSearchRequests)}) | ${formatUsd(report.total.webSearchUsd)} | ${pct(shares.webSearch)} | — |`,
|
|
975
|
+
);
|
|
976
|
+
}
|
|
971
977
|
lines.push('');
|
|
972
978
|
|
|
973
979
|
/**
|