@trazum/cli 2.2.1 → 2.3.0
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/index.d.ts.map +1 -1
- package/dist/index.js +48 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +52 -10
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA8JA,OAAO,KAAK,EAEV,UAAU,EAIV,WAAW,EAuBZ,MAAM,cAAc,CAAC;AA6sKtB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CACjC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAC9E;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;SAAE,CAAA;KAAE,CACtF,CAAC;CACH;AA65JD;;;;;;;;;;;;;;;;;GAiBG;AACH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAkBzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAe1D"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createInterface } from 'node:readline/promises';
|
|
|
7
7
|
import { dirname, join, resolve as resolvePath } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { gunzipSync } from 'node:zlib';
|
|
10
|
-
import { CONTRACT_NAMES, contractSchema, applyRewrites, BASELINE_FILENAME, BASELINE_VERSION, breaches, cacheableMinimum, analyzeCachePrefix, billLevers, bucketedCacheEconomics, bucketedProfile, buildHistory, buildPlan, connectorFor, CONNECTORS, normalizeAnthropicUsage, normalizeOpenAIUsage, bucketsFromRecords, evaluateWatch, firedKey, pruneRecords, recordsFromBuckets, storeInventory, storedReportFrom, verifyPlan, cacheEconomics, cacheHitRate, contextPressure, comparePrompts, compareToBaseline, computeSavings, bandGoverns, countTokensAnthropic, DEFAULT_USAGE, budgetPositions, conform, BREAK_EVEN_BAND, allocate, annualRecord, replayCommitment, coversTheTerm, runExperiment, qualityGate, semanticPassCost, verifySemanticProposals, SEMANTIC_SYSTEM_PROMPT, ladderPosition, validateLadder, outcomeReport, rankPerOutcome, FAILURE_POLICIES, detectFromSource, matchLocale, parsePlanDocument, waiverDay, waiverHistory, proposeInit, MIN_RATE_DAYS, parseConfig, coverageDrift, driversBetween, explainGateFailure, assignSources, fleetRollup, rollUp, heartbeats, ruleYield, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, receiptFrom, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, matchGlob, MAX_INPUT_CHARS, moneyIsComparable, mostSpecificMatch, assemble, interview, nearestName, slot, SLOT_IDS, optimize, parseBaseline, PHRASE_LANGUAGES, detectTextLanguage, dictionaryStanding, languagesWithStanding, indexUsage, parseUsageLine, plannedCalls, claudeCodeRecords, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, heliconeRecords, langsmithRecords, litellmRecords, otelRecords, ownRate, positionAt, positionReport, PRICING_LAST_REVIEWED, PROVIDER_REVIEWED, STALE_PRICING_DAYS, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, switchAnalysis, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, isOffered, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, TTL_1H_MS, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
|
|
10
|
+
import { CONTRACT_NAMES, contractSchema, applyRewrites, BASELINE_FILENAME, BASELINE_VERSION, breaches, cacheableMinimum, analyzeCachePrefix, billLevers, bucketedCacheEconomics, bucketedProfile, buildHistory, buildPlan, connectorFor, CONNECTORS, normalizeAnthropicUsage, normalizeOpenAIUsage, bucketsFromRecords, evaluateWatch, firedKey, pruneRecords, recordsFromBuckets, storeInventory, storedReportFrom, verifyPlan, cacheEconomics, cacheHitRate, contextPressure, comparePrompts, compareToBaseline, computeSavings, bandGoverns, countTokensAnthropic, DEFAULT_USAGE, budgetPositions, conform, BREAK_EVEN_BAND, allocate, annualRecord, replayCommitment, coversTheTerm, runExperiment, qualityGate, semanticPassCost, verifySemanticProposals, SEMANTIC_SYSTEM_PROMPT, ladderPosition, validateLadder, outcomeReport, rankPerOutcome, FAILURE_POLICIES, detectFromSource, matchLocale, parsePlanDocument, waiverDay, waiverHistory, proposeInit, MIN_RATE_DAYS, parseConfig, coverageDrift, driversBetween, explainGateFailure, assignSources, fleetRollup, rollUp, heartbeats, ruleYield, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, receiptFrom, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, matchGlob, MAX_INPUT_CHARS, moneyIsComparable, mostSpecificMatch, assemble, interview, nearestName, slot, SLOT_IDS, optimize, parseBaseline, PHRASE_LANGUAGES, detectTextLanguage, dictionaryStanding, languagesWithStanding, indexUsage, parseUsageLine, plannedCalls, claudeCodeRecords, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, heliconeRecords, langsmithRecords, litellmRecords, otelRecords, ownRate, positionAt, positionReport, PRICING_LAST_REVIEWED, reviewedForModels, PROVIDER_REVIEWED, STALE_PRICING_DAYS, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, switchAnalysis, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, isOffered, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, TTL_1H_MS, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
|
|
11
11
|
import { cacheDir, cacheStats, cachingProvider, clearCache } from './suggest-cache.js';
|
|
12
12
|
import { OPTIONAL_COUNTERS } from './optional-counters.js';
|
|
13
13
|
import { dayOf, formatGap, median, spanDays } from './time.js';
|
|
@@ -8167,6 +8167,7 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
8167
8167
|
throw new Error(t.profile.sinceAfterUntil());
|
|
8168
8168
|
}
|
|
8169
8169
|
const windowed = sinceMs !== undefined || untilMs !== undefined;
|
|
8170
|
+
const report = profileUsage(raw, { catalogue: pricing, label: onlyLabel, sinceMs, untilMs });
|
|
8170
8171
|
/**
|
|
8171
8172
|
* How old the price table behind every dollar below is. Stated only when it
|
|
8172
8173
|
* is old enough to matter: `models` and `doctor` always print the date, but
|
|
@@ -8175,12 +8176,21 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
8175
8176
|
* The threshold is in the sentence, and the number behind it is
|
|
8176
8177
|
* `STALE_PRICING_DAYS` — shared with the MCP report and the browser's bill,
|
|
8177
8178
|
* which used to keep their own copies of it.
|
|
8179
|
+
*
|
|
8180
|
+
* **The date is this report's, not the catalogue's**, and it is computed
|
|
8181
|
+
* after the report for that reason rather than before it as it used to be.
|
|
8182
|
+
* `PRICING_LAST_REVIEWED` is the oldest provider's, so a log of Claude and
|
|
8183
|
+
* OpenAI calls was told its prices were 68 days old on a morning when both
|
|
8184
|
+
* halves had been read that week — by a sentence that says, in these words,
|
|
8185
|
+
* that the table behind *every dollar here* was reviewed then. It was not.
|
|
8186
|
+
* `reviewedForModels` answers for the providers that actually priced this
|
|
8187
|
+
* report and falls back to the catalogue's own date wherever it cannot.
|
|
8178
8188
|
*/
|
|
8179
|
-
const
|
|
8189
|
+
const reportReviewed = reviewedForModels(report.byModel.map((row) => row.model), pricing);
|
|
8190
|
+
const pricingAgeDays = reviewAgeDays(reportReviewed, new Date());
|
|
8180
8191
|
const pricingStale = pricingAgeDays !== null && pricingAgeDays > STALE_PRICING_DAYS
|
|
8181
|
-
? { date:
|
|
8192
|
+
? { date: reportReviewed, days: pricingAgeDays }
|
|
8182
8193
|
: null;
|
|
8183
|
-
const report = profileUsage(raw, { catalogue: pricing, label: onlyLabel, sinceMs, untilMs });
|
|
8184
8194
|
if (report.total.calls === 0 && report.unpriced.calls === 0) {
|
|
8185
8195
|
if (onlyLabel !== undefined || windowed) {
|
|
8186
8196
|
// Diagnose against the log without the failed filter, so the error can
|
|
@@ -8376,8 +8386,32 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
8376
8386
|
label: r.label,
|
|
8377
8387
|
cache: cacheEconomics(r.breakdown),
|
|
8378
8388
|
})),
|
|
8379
|
-
|
|
8380
|
-
|
|
8389
|
+
/*
|
|
8390
|
+
The provenance of every dollar above, in two parts that are not the
|
|
8391
|
+
same question.
|
|
8392
|
+
|
|
8393
|
+
`lastReviewed` and `ageDays` are the **table's**: its oldest
|
|
8394
|
+
provider, which is what "how old is this catalogue" means and what
|
|
8395
|
+
these two keys have always carried. Unchanged, because a key cannot
|
|
8396
|
+
change meaning under a minor and a consumer branching on them keeps
|
|
8397
|
+
working.
|
|
8398
|
+
|
|
8399
|
+
`reportReviewed` and `reportAgeDays` are **these figures'**: the
|
|
8400
|
+
oldest provider among the models actually priced here, which is the
|
|
8401
|
+
pair the staleness warning is decided from. They are new keys, and
|
|
8402
|
+
new keys are additions the contract allows.
|
|
8403
|
+
|
|
8404
|
+
The two differ exactly when a report uses none of the models
|
|
8405
|
+
holding the table back — which was the whole defect: a log of
|
|
8406
|
+
Claude and OpenAI calls was told its prices were 68 days old on a
|
|
8407
|
+
morning both halves had been read that week.
|
|
8408
|
+
*/
|
|
8409
|
+
pricing: {
|
|
8410
|
+
lastReviewed: pricing.lastReviewed,
|
|
8411
|
+
ageDays: reviewAgeDays(pricing.lastReviewed, new Date()),
|
|
8412
|
+
reportReviewed,
|
|
8413
|
+
reportAgeDays: pricingAgeDays,
|
|
8414
|
+
},
|
|
8381
8415
|
levers: billLevers(report, { catalogue: pricing }),
|
|
8382
8416
|
// Present only when --against was passed: null delta means the
|
|
8383
8417
|
// previous log had nothing priced, which is a different answer from
|
|
@@ -10455,7 +10489,14 @@ function printDoctor(report, context) {
|
|
|
10455
10489
|
const model = pricing.models.find((m) => m.id === usage.model);
|
|
10456
10490
|
console.log(`\n${c.bold(t.doctor.heading(root, seen.length))}`);
|
|
10457
10491
|
console.log(c.dim(t.doctor.subheading(model?.displayName ?? usage.model, n(usage.callsPerMonth))));
|
|
10458
|
-
|
|
10492
|
+
/*
|
|
10493
|
+
This prompt's own model, not the catalogue's oldest provider. `doctor`
|
|
10494
|
+
reports on one model and one bill, so the date that qualifies it is the
|
|
10495
|
+
date that model's provider was read — the catalogue-wide answer named a
|
|
10496
|
+
provider this prompt does not use.
|
|
10497
|
+
*/
|
|
10498
|
+
const reviewed = reviewedForModels([usage.model], pricing);
|
|
10499
|
+
console.log(c.dim(t.doctor.pricesReviewed(reviewed, reviewAgeDays(reviewed, new Date()))));
|
|
10459
10500
|
// Budgets first. Everything below is money; this is whether anything is
|
|
10460
10501
|
// watching at all, and an unwatched prompt is how the money got there.
|
|
10461
10502
|
console.log(`\n${c.bold(t.doctor.budgetsHeading())}`);
|