usage-tab 1.0.0 → 1.2.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/README.md +64 -8
- package/dist/index.cjs +555 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -3
- package/dist/index.d.ts +66 -3
- package/dist/index.js +555 -192
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -154,7 +154,7 @@ type ModelMatchKind = 'override' | 'canonical-qualified' | 'alias-scoped' | 'ali
|
|
|
154
154
|
* Verify: pnpm exec tsx scripts/generate-model-registry.ts --check
|
|
155
155
|
*/
|
|
156
156
|
|
|
157
|
-
declare const REGISTRY_VERSION = "registry-
|
|
157
|
+
declare const REGISTRY_VERSION = "registry-e5f4ec7eb681a235";
|
|
158
158
|
declare const MODEL_REGISTRY: readonly ModelDescriptor[];
|
|
159
159
|
|
|
160
160
|
/**
|
|
@@ -201,7 +201,18 @@ interface PriceRequest {
|
|
|
201
201
|
readonly usage: LlmUsage | unknown;
|
|
202
202
|
/** `'batch'` applies the resolved period's `batchMultiplier` when one is published; falls back to standard pricing (with a warning) otherwise. */
|
|
203
203
|
readonly mode?: PriceMode;
|
|
204
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Effective date for pricing-period selection. Defaults to `new Date()`.
|
|
206
|
+
*
|
|
207
|
+
* Pricing periods start at UTC midnight, so every ISO string form is read
|
|
208
|
+
* as UTC: an ISO date (`'2026-09-01'`) and an offset-carrying datetime
|
|
209
|
+
* (`'2026-09-01T05:00:00Z'`) already are, and one *without* an offset
|
|
210
|
+
* (`'2026-09-01T05:00:00'` — a log timestamp, a `datetime-local` input,
|
|
211
|
+
* several DB drivers) is read as UTC too, rather than in whatever timezone
|
|
212
|
+
* the process happens to run. A non-ISO string (`'2026/09/01'`,
|
|
213
|
+
* `'September 1, 2026'`) is implementation-defined and local in practice —
|
|
214
|
+
* pass a `Date` or an ISO form instead.
|
|
215
|
+
*/
|
|
205
216
|
readonly at?: Date | string;
|
|
206
217
|
}
|
|
207
218
|
interface CostLine {
|
|
@@ -323,6 +334,32 @@ interface CustomPriceInput {
|
|
|
323
334
|
readonly observedAt?: string;
|
|
324
335
|
readonly notes?: readonly string[];
|
|
325
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* An exact running total over one or more `CostBreakdown`s — see
|
|
339
|
+
* `createCostAggregator`.
|
|
340
|
+
*/
|
|
341
|
+
interface CostTotal {
|
|
342
|
+
/** How many breakdowns this total covers. */
|
|
343
|
+
readonly count: number;
|
|
344
|
+
/** Ergonomic numeric total. Not the authoritative value — see `totalUsdExact`. */
|
|
345
|
+
readonly totalUsd: number;
|
|
346
|
+
/** Exact decimal string total, summed with the same fixed-point arithmetic each individual cost was computed with. */
|
|
347
|
+
readonly totalUsdExact: string;
|
|
348
|
+
/**
|
|
349
|
+
* Every distinct `registryVersion` the aggregated breakdowns were priced
|
|
350
|
+
* against, sorted. More than one means the total mixes pricing snapshots —
|
|
351
|
+
* expected for a report spanning a registry update, a bug for a total meant
|
|
352
|
+
* to be reproducible against a single one.
|
|
353
|
+
*/
|
|
354
|
+
readonly registryVersions: readonly string[];
|
|
355
|
+
}
|
|
356
|
+
interface CostAggregator {
|
|
357
|
+
/** Adds one breakdown to the running totals. Throws `InvalidRateError` if its `totalUsdExact` is not a non-negative decimal string. */
|
|
358
|
+
add(breakdown: CostBreakdown): void;
|
|
359
|
+
total(): CostTotal;
|
|
360
|
+
/** Per-model totals, keyed `` `${provider}:${canonicalModel}` `` — the resolved identity, so two aliases of one model share a bucket. */
|
|
361
|
+
byModel(): ReadonlyMap<string, CostTotal>;
|
|
362
|
+
}
|
|
326
363
|
|
|
327
364
|
declare function calculateCost(request: PriceRequest, options?: PriceOptions): CostBreakdown;
|
|
328
365
|
|
|
@@ -345,6 +382,32 @@ declare function createPriceCalculator(defaults?: PriceCalculatorOptions): Price
|
|
|
345
382
|
*/
|
|
346
383
|
declare function createPriceOverride(input: CustomPriceInput): ModelDescriptor;
|
|
347
384
|
|
|
385
|
+
/**
|
|
386
|
+
* Exact sum of decimal USD strings — `totalUsdExact`/`costUsdExact` values,
|
|
387
|
+
* or any string in the same non-negative decimal format. Returns a decimal
|
|
388
|
+
* string in that same format (`"0.00"` for an empty list).
|
|
389
|
+
*
|
|
390
|
+
* Throws `InvalidRateError` (`INVALID_RATE`) for anything that is not a
|
|
391
|
+
* non-negative decimal string, rather than coercing it: a stringified
|
|
392
|
+
* `NaN`, a float-formatted `"1e-7"`, or a `number` that slipped past a
|
|
393
|
+
* `readonly string[]` at the type level are all silent under-reporting
|
|
394
|
+
* waiting to happen.
|
|
395
|
+
*/
|
|
396
|
+
declare function sumExactUsd(values: readonly string[]): string;
|
|
397
|
+
/**
|
|
398
|
+
* Accumulates `CostBreakdown`s into exact running totals — overall and per
|
|
399
|
+
* `provider:canonicalModel`. Sums are kept as exact fixed-point amounts, so
|
|
400
|
+
* memory does not grow with the number of breakdowns added; only the number
|
|
401
|
+
* of distinct models does.
|
|
402
|
+
*
|
|
403
|
+
* `total().registryVersions` carries the aggregate's provenance: more than
|
|
404
|
+
* one entry means the total mixes pricing snapshots, which is legitimate for
|
|
405
|
+
* a historical report spanning a registry update and a bug for a total that
|
|
406
|
+
* was supposed to be priced against one snapshot. This package cannot tell
|
|
407
|
+
* the two apart, so it reports rather than warns.
|
|
408
|
+
*/
|
|
409
|
+
declare function createCostAggregator(): CostAggregator;
|
|
410
|
+
|
|
348
411
|
/**
|
|
349
412
|
* Stable error types this package throws directly. `resolveModel` and
|
|
350
413
|
* `calculateCost` also propagate `AmbiguousAliasError`, `UnknownModelError`,
|
|
@@ -417,4 +480,4 @@ declare function normalizeGoogleUsage(value: unknown): NormalizedUsageResult;
|
|
|
417
480
|
|
|
418
481
|
declare function normalizeOpenAICompatibleUsage(value: unknown): NormalizedUsageResult;
|
|
419
482
|
|
|
420
|
-
export { AmbiguousAliasError, type CostBreakdown, type CostLine, type CustomPriceInput, InvalidLookupDateError, InvalidRateError, InvalidTokenCountError, InvalidUsageError, type LlmUsage, MODEL_REGISTRY, type ModelCandidate, type ModelDescriptor, NoPricingPeriodError, type NormalizedUsageResult, type PriceCalculator, type PriceCalculatorOptions, type PriceMode, type PriceOptions, type PriceRequest, type PriceWarning, type PriceWarningCode, type PricingPeriod, type ProviderId, REGISTRY_VERSION, type RegistrySource, type ResolveModelOptions, type ResolvedModel, UnknownModelError, calculateCost, createPriceCalculator, createPriceOverride, normalizeAnthropicUsage, normalizeGoogleUsage, normalizeOpenAICompatibleUsage, normalizeOpenAIUsage, resolveModel };
|
|
483
|
+
export { AmbiguousAliasError, type CostAggregator, type CostBreakdown, type CostLine, type CostTotal, type CustomPriceInput, InvalidLookupDateError, InvalidRateError, InvalidTokenCountError, InvalidUsageError, type LlmUsage, MODEL_REGISTRY, type ModelCandidate, type ModelDescriptor, NoPricingPeriodError, type NormalizedUsageResult, type PriceCalculator, type PriceCalculatorOptions, type PriceMode, type PriceOptions, type PriceRequest, type PriceWarning, type PriceWarningCode, type PricingPeriod, type ProviderId, REGISTRY_VERSION, type RegistrySource, type ResolveModelOptions, type ResolvedModel, UnknownModelError, calculateCost, createCostAggregator, createPriceCalculator, createPriceOverride, normalizeAnthropicUsage, normalizeGoogleUsage, normalizeOpenAICompatibleUsage, normalizeOpenAIUsage, resolveModel, sumExactUsd };
|
package/dist/index.d.ts
CHANGED
|
@@ -154,7 +154,7 @@ type ModelMatchKind = 'override' | 'canonical-qualified' | 'alias-scoped' | 'ali
|
|
|
154
154
|
* Verify: pnpm exec tsx scripts/generate-model-registry.ts --check
|
|
155
155
|
*/
|
|
156
156
|
|
|
157
|
-
declare const REGISTRY_VERSION = "registry-
|
|
157
|
+
declare const REGISTRY_VERSION = "registry-e5f4ec7eb681a235";
|
|
158
158
|
declare const MODEL_REGISTRY: readonly ModelDescriptor[];
|
|
159
159
|
|
|
160
160
|
/**
|
|
@@ -201,7 +201,18 @@ interface PriceRequest {
|
|
|
201
201
|
readonly usage: LlmUsage | unknown;
|
|
202
202
|
/** `'batch'` applies the resolved period's `batchMultiplier` when one is published; falls back to standard pricing (with a warning) otherwise. */
|
|
203
203
|
readonly mode?: PriceMode;
|
|
204
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Effective date for pricing-period selection. Defaults to `new Date()`.
|
|
206
|
+
*
|
|
207
|
+
* Pricing periods start at UTC midnight, so every ISO string form is read
|
|
208
|
+
* as UTC: an ISO date (`'2026-09-01'`) and an offset-carrying datetime
|
|
209
|
+
* (`'2026-09-01T05:00:00Z'`) already are, and one *without* an offset
|
|
210
|
+
* (`'2026-09-01T05:00:00'` — a log timestamp, a `datetime-local` input,
|
|
211
|
+
* several DB drivers) is read as UTC too, rather than in whatever timezone
|
|
212
|
+
* the process happens to run. A non-ISO string (`'2026/09/01'`,
|
|
213
|
+
* `'September 1, 2026'`) is implementation-defined and local in practice —
|
|
214
|
+
* pass a `Date` or an ISO form instead.
|
|
215
|
+
*/
|
|
205
216
|
readonly at?: Date | string;
|
|
206
217
|
}
|
|
207
218
|
interface CostLine {
|
|
@@ -323,6 +334,32 @@ interface CustomPriceInput {
|
|
|
323
334
|
readonly observedAt?: string;
|
|
324
335
|
readonly notes?: readonly string[];
|
|
325
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* An exact running total over one or more `CostBreakdown`s — see
|
|
339
|
+
* `createCostAggregator`.
|
|
340
|
+
*/
|
|
341
|
+
interface CostTotal {
|
|
342
|
+
/** How many breakdowns this total covers. */
|
|
343
|
+
readonly count: number;
|
|
344
|
+
/** Ergonomic numeric total. Not the authoritative value — see `totalUsdExact`. */
|
|
345
|
+
readonly totalUsd: number;
|
|
346
|
+
/** Exact decimal string total, summed with the same fixed-point arithmetic each individual cost was computed with. */
|
|
347
|
+
readonly totalUsdExact: string;
|
|
348
|
+
/**
|
|
349
|
+
* Every distinct `registryVersion` the aggregated breakdowns were priced
|
|
350
|
+
* against, sorted. More than one means the total mixes pricing snapshots —
|
|
351
|
+
* expected for a report spanning a registry update, a bug for a total meant
|
|
352
|
+
* to be reproducible against a single one.
|
|
353
|
+
*/
|
|
354
|
+
readonly registryVersions: readonly string[];
|
|
355
|
+
}
|
|
356
|
+
interface CostAggregator {
|
|
357
|
+
/** Adds one breakdown to the running totals. Throws `InvalidRateError` if its `totalUsdExact` is not a non-negative decimal string. */
|
|
358
|
+
add(breakdown: CostBreakdown): void;
|
|
359
|
+
total(): CostTotal;
|
|
360
|
+
/** Per-model totals, keyed `` `${provider}:${canonicalModel}` `` — the resolved identity, so two aliases of one model share a bucket. */
|
|
361
|
+
byModel(): ReadonlyMap<string, CostTotal>;
|
|
362
|
+
}
|
|
326
363
|
|
|
327
364
|
declare function calculateCost(request: PriceRequest, options?: PriceOptions): CostBreakdown;
|
|
328
365
|
|
|
@@ -345,6 +382,32 @@ declare function createPriceCalculator(defaults?: PriceCalculatorOptions): Price
|
|
|
345
382
|
*/
|
|
346
383
|
declare function createPriceOverride(input: CustomPriceInput): ModelDescriptor;
|
|
347
384
|
|
|
385
|
+
/**
|
|
386
|
+
* Exact sum of decimal USD strings — `totalUsdExact`/`costUsdExact` values,
|
|
387
|
+
* or any string in the same non-negative decimal format. Returns a decimal
|
|
388
|
+
* string in that same format (`"0.00"` for an empty list).
|
|
389
|
+
*
|
|
390
|
+
* Throws `InvalidRateError` (`INVALID_RATE`) for anything that is not a
|
|
391
|
+
* non-negative decimal string, rather than coercing it: a stringified
|
|
392
|
+
* `NaN`, a float-formatted `"1e-7"`, or a `number` that slipped past a
|
|
393
|
+
* `readonly string[]` at the type level are all silent under-reporting
|
|
394
|
+
* waiting to happen.
|
|
395
|
+
*/
|
|
396
|
+
declare function sumExactUsd(values: readonly string[]): string;
|
|
397
|
+
/**
|
|
398
|
+
* Accumulates `CostBreakdown`s into exact running totals — overall and per
|
|
399
|
+
* `provider:canonicalModel`. Sums are kept as exact fixed-point amounts, so
|
|
400
|
+
* memory does not grow with the number of breakdowns added; only the number
|
|
401
|
+
* of distinct models does.
|
|
402
|
+
*
|
|
403
|
+
* `total().registryVersions` carries the aggregate's provenance: more than
|
|
404
|
+
* one entry means the total mixes pricing snapshots, which is legitimate for
|
|
405
|
+
* a historical report spanning a registry update and a bug for a total that
|
|
406
|
+
* was supposed to be priced against one snapshot. This package cannot tell
|
|
407
|
+
* the two apart, so it reports rather than warns.
|
|
408
|
+
*/
|
|
409
|
+
declare function createCostAggregator(): CostAggregator;
|
|
410
|
+
|
|
348
411
|
/**
|
|
349
412
|
* Stable error types this package throws directly. `resolveModel` and
|
|
350
413
|
* `calculateCost` also propagate `AmbiguousAliasError`, `UnknownModelError`,
|
|
@@ -417,4 +480,4 @@ declare function normalizeGoogleUsage(value: unknown): NormalizedUsageResult;
|
|
|
417
480
|
|
|
418
481
|
declare function normalizeOpenAICompatibleUsage(value: unknown): NormalizedUsageResult;
|
|
419
482
|
|
|
420
|
-
export { AmbiguousAliasError, type CostBreakdown, type CostLine, type CustomPriceInput, InvalidLookupDateError, InvalidRateError, InvalidTokenCountError, InvalidUsageError, type LlmUsage, MODEL_REGISTRY, type ModelCandidate, type ModelDescriptor, NoPricingPeriodError, type NormalizedUsageResult, type PriceCalculator, type PriceCalculatorOptions, type PriceMode, type PriceOptions, type PriceRequest, type PriceWarning, type PriceWarningCode, type PricingPeriod, type ProviderId, REGISTRY_VERSION, type RegistrySource, type ResolveModelOptions, type ResolvedModel, UnknownModelError, calculateCost, createPriceCalculator, createPriceOverride, normalizeAnthropicUsage, normalizeGoogleUsage, normalizeOpenAICompatibleUsage, normalizeOpenAIUsage, resolveModel };
|
|
483
|
+
export { AmbiguousAliasError, type CostAggregator, type CostBreakdown, type CostLine, type CostTotal, type CustomPriceInput, InvalidLookupDateError, InvalidRateError, InvalidTokenCountError, InvalidUsageError, type LlmUsage, MODEL_REGISTRY, type ModelCandidate, type ModelDescriptor, NoPricingPeriodError, type NormalizedUsageResult, type PriceCalculator, type PriceCalculatorOptions, type PriceMode, type PriceOptions, type PriceRequest, type PriceWarning, type PriceWarningCode, type PricingPeriod, type ProviderId, REGISTRY_VERSION, type RegistrySource, type ResolveModelOptions, type ResolvedModel, UnknownModelError, calculateCost, createCostAggregator, createPriceCalculator, createPriceOverride, normalizeAnthropicUsage, normalizeGoogleUsage, normalizeOpenAICompatibleUsage, normalizeOpenAIUsage, resolveModel, sumExactUsd };
|