@trazum/core 1.82.0 → 1.83.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.
@@ -0,0 +1,253 @@
1
+ import type { PricingCatalogue } from './pricing.js';
2
+ import type { UsageProfileReport } from './usage.js';
3
+ /**
4
+ * The receipt: a bill's counts, with the provenance of every figure attached.
5
+ *
6
+ * ## What it is for
7
+ *
8
+ * A profile answers a question on the terminal where it ran. A receipt is the
9
+ * same figures shaped so they can still answer it somewhere else: aggregated by
10
+ * somebody's dashboard, filed against an invoice, or compared against last
11
+ * month's by a reader who was not there when the command ran.
12
+ *
13
+ * That is why every line carries the rate behind its money and the date that
14
+ * rate was last read. A dollar figure with no provenance cannot tell a
15
+ * repricing from a team whose spend moved, and the consumer that most needs
16
+ * that distinction is the one that cannot read a sentence explaining it.
17
+ *
18
+ * ## Why a line carries money per bucket and not only a rate
19
+ *
20
+ * The first version of this module published the catalogue's `inputPerMTok`
21
+ * and `outputPerMTok` beside a dollar figure computed by `profileUsage`. Those
22
+ * are not always the same rates. A model in a promotional window, or one whose
23
+ * long-context tier applied, is billed at `effectivePricing`'s figure, and a
24
+ * cached read is billed at a fraction of input that no published field named at
25
+ * all. **A consumer multiplying the stated rates by the stated tokens got a
26
+ * different number from the stated total, with nothing saying which was
27
+ * wrong.**
28
+ *
29
+ * That is a bad defect in a document whose entire purpose is that a figure can
30
+ * be recomputed by whoever receives it, and it is the exact failure the
31
+ * doctrine line at the foot of this comment is about.
32
+ *
33
+ * So a line now carries the **money as it was actually apportioned** -- input,
34
+ * cache reads, cache writes and output -- and `usd` is their sum. The rates stay
35
+ * as provenance, labelled as the catalogue's published figures rather than as
36
+ * the arithmetic. `receipt-arithmetic.test.js` fails if the four stop adding up,
37
+ * which is a property a reader can check on any receipt they are handed rather
38
+ * than a promise they have to take.
39
+ *
40
+ * ## What it carries, and what it has no field for
41
+ *
42
+ * Counts, model, provider, the money split by bucket, the published rates, the
43
+ * review date, the label the log carried, the period, and what could not be
44
+ * priced. There is **no field
45
+ * for prompt text, for an answer, for a file path, for a branch name or for a
46
+ * credential** — not redacted, not hashed, absent, because the input this takes
47
+ * has nowhere to hold them either.
48
+ *
49
+ * `receipt-redaction.test.js` holds that by planting all 4 in a log — in the
50
+ * session field among other places, which is the value this package has
51
+ * promised since it shipped never comes back out — and failing if any reaches
52
+ * the output. A property about what a document does not contain is exactly the
53
+ * kind this repository proves by breaking rather than by asserting.
54
+ *
55
+ * ## What it is not
56
+ *
57
+ * **Not a transport.** Nothing here opens a socket, reads an environment
58
+ * variable or takes an endpoint. `receiptFrom` returns a value; where it goes
59
+ * is the caller's decision. A module in this package that phoned home would
60
+ * break the roadmap's first rule, which is that no feature may make a network
61
+ * call a prerequisite for anything.
62
+ *
63
+ * **Not a new measurement.** Every figure is one `profileUsage` already
64
+ * produced. This adds provenance around them and takes nothing away.
65
+ *
66
+ * Doctrine: [A machine reader gets the provenance too](../../../docs/doctrine.md#a-machine-reader-gets-the-provenance-too)
67
+ */
68
+ /**
69
+ * The catalogue's published rates for this model, and when a human last read
70
+ * them off the provider's own page.
71
+ *
72
+ * **Provenance, not the arithmetic.** These are list rates. The money that was
73
+ * actually apportioned is in `ReceiptLine.money`, and the two differ whenever a
74
+ * promotion or a long-context tier applied, or for any token billed at a
75
+ * fraction of input -- which is every cached read. A consumer wanting the rate
76
+ * that was really charged divides a bucket's money by its tokens; a consumer
77
+ * wanting to know whether a provider repriced compares these.
78
+ */
79
+ export interface ReceiptPricing {
80
+ provider: string;
81
+ inputPerMTok: number;
82
+ outputPerMTok: number;
83
+ /**
84
+ * The date this provider's rates were last read off its own page, `null`
85
+ * when the catalogue carries no date for that provider.
86
+ *
87
+ * Per provider rather than per catalogue, because that is how the prices are
88
+ * actually reviewed: looking at one page and finding nothing changed is not
89
+ * the same event as not looking. A server comparing two receipts a month
90
+ * apart reads a repricing as a repricing instead of as a team missing a
91
+ * target.
92
+ */
93
+ reviewedOn: string | null;
94
+ }
95
+ /** Where a line's money went. The four add to `ReceiptLine.usd`. */
96
+ export interface ReceiptMoney {
97
+ inputUsd: number;
98
+ cacheReadUsd: number;
99
+ cacheWriteUsd: number;
100
+ outputUsd: number;
101
+ }
102
+ /** One slice of a bill: a label's calls to one model. */
103
+ export interface ReceiptLine {
104
+ /**
105
+ * The attribution the log carried, or `null` for the unlabelled bucket.
106
+ *
107
+ * `null` rather than the sentinel, which is an internal grouping key and is
108
+ * never serialised. A consumer that saw the raw sentinel would have to know
109
+ * this package's internals to render it.
110
+ */
111
+ label: string | null;
112
+ model: string;
113
+ calls: number;
114
+ inputTokens: number;
115
+ cacheReadTokens: number;
116
+ /** Every cache write, whatever its TTL. The sum of the two fields below. */
117
+ cacheWriteTokens: number;
118
+ /**
119
+ * The two write TTLs kept apart, because they are billed at different rates.
120
+ *
121
+ * They are here for the same reason `UsageBreakdown` keeps them: the ratio
122
+ * between them is not a constant across providers, so a total that has lost
123
+ * the split can be repriced only by guessing at it. A consumer repricing this
124
+ * traffic against another model's rates needs both.
125
+ */
126
+ cacheWrite5mTokens: number;
127
+ cacheWrite1hTokens: number;
128
+ outputTokens: number;
129
+ /**
130
+ * What it cost, which is exactly the sum of `money` below.
131
+ *
132
+ * Every line here is priced; what is not is in `gaps`.
133
+ */
134
+ usd: number;
135
+ /**
136
+ * Where the money went, as it was apportioned rather than as it might be
137
+ * recomputed.
138
+ *
139
+ * This is the field that makes a receipt checkable. `usd` alone can only be
140
+ * believed; these four can be added up, and each can be divided by its own
141
+ * token count to recover the rate that was really charged -- including the
142
+ * one for cached reads, which no published rate names.
143
+ */
144
+ money: ReceiptMoney;
145
+ /** The catalogue's published rates, as provenance. */
146
+ pricing: ReceiptPricing;
147
+ }
148
+ /** Everything a receipt refuses to answer, typed rather than left implicit. */
149
+ export type ReceiptGap =
150
+ /**
151
+ * Models the catalogue does not price, with the size of what they used.
152
+ *
153
+ * The counts are here rather than in a line, and the first draft of this
154
+ * module got that wrong in a way its own guard caught. `byLabelAndModel`
155
+ * excludes unpriced calls on purpose — the profile keeps them apart so that
156
+ * a total is never tokens from one set of calls over dollars from another —
157
+ * so a receipt built from that list alone silently loses them.
158
+ *
159
+ * The obvious repair was worse than the bug: emit a line with `label: null`.
160
+ * That reads as *this call carried no label*, when in fact it carried one the
161
+ * profile could not attach to a priced slice. Conflating "unlabelled" with
162
+ * "unattributable" is the exact failure this project refuses elsewhere, so
163
+ * the gap carries the magnitude instead and nothing pretends to an
164
+ * attribution it does not have.
165
+ */
166
+ {
167
+ kind: 'unpriced';
168
+ models: string[];
169
+ calls: number;
170
+ inputTokens: number;
171
+ outputTokens: number;
172
+ } | {
173
+ kind: 'unread-lines';
174
+ count: number;
175
+ } | {
176
+ kind: 'no-clock';
177
+ }
178
+ /**
179
+ * Calls whose cache-write TTL the log did not state, so the cheaper rate was
180
+ * assumed.
181
+ *
182
+ * Reported because it changes what kind of figure this is. A total that
183
+ * includes an assumed TTL is a **floor** on those calls, not a measurement,
184
+ * and a document that says `counting: 'counted'` while quietly resting on an
185
+ * assumption is claiming a precision it does not have.
186
+ */
187
+ | {
188
+ kind: 'assumed-write-ttl';
189
+ calls: number;
190
+ };
191
+ export interface ReceiptDocument {
192
+ /** The one thing a consumer must branch on. Set here, by the builder. */
193
+ schemaVersion: 1;
194
+ /**
195
+ * When this receipt was made, or `null`.
196
+ *
197
+ * Optional on purpose, and the reason is the same one `plan.json` gives: a
198
+ * document without a stamp is undated, which a reader can act on. A document
199
+ * with an invented stamp is wrong, which they cannot.
200
+ */
201
+ emittedAt: string | null;
202
+ /** The period the counts cover, from the log's own clock. */
203
+ span: {
204
+ fromMs: number;
205
+ toMs: number;
206
+ calls: number;
207
+ } | null;
208
+ /**
209
+ * How the tokens were arrived at.
210
+ *
211
+ * `counted` for every receipt this function builds, because a usage log
212
+ * carries the provider's own counts. The field exists because a receipt built
213
+ * from an estimate would be a different kind of evidence, and a consumer must
214
+ * never have to guess which one it is holding.
215
+ */
216
+ counting: 'counted';
217
+ lines: ReceiptLine[];
218
+ total: {
219
+ calls: number;
220
+ usd: number;
221
+ };
222
+ /**
223
+ * What this receipt cannot say, and why.
224
+ *
225
+ * Present and empty rather than absent when there is nothing to report:
226
+ * "nothing was refused" and "this document does not record refusals" are
227
+ * different statements, and a server aggregating a thousand receipts has to
228
+ * be able to tell them apart.
229
+ */
230
+ gaps: ReceiptGap[];
231
+ }
232
+ /**
233
+ * The fields that leave this machine, listed once, in one place.
234
+ *
235
+ * The redaction guard reads this array rather than a copy of it, so a field
236
+ * added to `ReceiptLine` and not added here fails the guard. A whitelist
237
+ * maintained in two places is a whitelist with a hole in it.
238
+ */
239
+ export declare const RECEIPT_LINE_FIELDS: readonly ["label", "model", "calls", "inputTokens", "cacheReadTokens", "cacheWriteTokens", "cacheWrite5mTokens", "cacheWrite1hTokens", "outputTokens", "usd", "money", "pricing"];
240
+ export interface ReceiptOptions {
241
+ /** Stamp the document. Omit for an undated receipt, which is valid. */
242
+ emittedAt?: Date;
243
+ }
244
+ /**
245
+ * Build a receipt from a profile the caller already computed.
246
+ *
247
+ * Takes the report rather than the log text, and that is the guarantee rather
248
+ * than an ergonomic choice: `UsageProfileReport` has no field that can hold
249
+ * prompt content, so this function could not emit any even if it tried. The
250
+ * narrow input is what makes the promise checkable instead of merely stated.
251
+ */
252
+ export declare function receiptFrom(report: UsageProfileReport, catalogue: PricingCatalogue, options?: ReceiptOptions): ReceiptDocument;
253
+ //# sourceMappingURL=receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt.d.ts","sourceRoot":"","sources":["../src/receipt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAA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,IAAI,EAAE,mBAAmB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,aAAa,EAAE,CAAC,CAAC;IACjB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,6DAA6D;IAC7D,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC7D;;;;;;;OAOG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC;;;;;;;OAOG;IACH,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,mLAarB,CAAC;AA8CZ,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,gBAAgB,EAC3B,OAAO,GAAE,cAAmB,GAC3B,eAAe,CA8CjB"}
@@ -0,0 +1,111 @@
1
+ import { PROVIDER_REVIEWED, modelFrom } from './pricing.js';
2
+ import { UNLABELLED } from './usage.js';
3
+ /**
4
+ * The fields that leave this machine, listed once, in one place.
5
+ *
6
+ * The redaction guard reads this array rather than a copy of it, so a field
7
+ * added to `ReceiptLine` and not added here fails the guard. A whitelist
8
+ * maintained in two places is a whitelist with a hole in it.
9
+ */
10
+ export const RECEIPT_LINE_FIELDS = Object.freeze([
11
+ 'label',
12
+ 'model',
13
+ 'calls',
14
+ 'inputTokens',
15
+ 'cacheReadTokens',
16
+ 'cacheWriteTokens',
17
+ 'cacheWrite5mTokens',
18
+ 'cacheWrite1hTokens',
19
+ 'outputTokens',
20
+ 'usd',
21
+ 'money',
22
+ 'pricing',
23
+ ]);
24
+ const lineFrom = (label, model, breakdown, catalogue) => {
25
+ /*
26
+ * Every slice reaching here is priced: `byLabelAndModel` holds only what the
27
+ * catalogue knows. What it does not know is reported by the `unpriced` gap,
28
+ * with its size, so the receipt's total is never mistaken for the whole bill.
29
+ */
30
+ const priced = modelFrom(catalogue, model);
31
+ return {
32
+ label: label === UNLABELLED ? null : label,
33
+ model,
34
+ calls: breakdown.calls,
35
+ inputTokens: breakdown.inputTokens,
36
+ cacheReadTokens: breakdown.cacheReadTokens,
37
+ cacheWriteTokens: breakdown.cacheWriteTokens,
38
+ cacheWrite5mTokens: breakdown.cacheWrite5mTokens,
39
+ cacheWrite1hTokens: breakdown.cacheWrite1hTokens,
40
+ outputTokens: breakdown.outputTokens,
41
+ usd: breakdown.totalUsd,
42
+ /*
43
+ * Copied from the breakdown rather than recomputed from the rates below.
44
+ * Recomputing would reintroduce the defect this field exists to fix: the
45
+ * published rates are list rates, and a promotion, a long-context tier or
46
+ * any cached token is billed at something else.
47
+ */
48
+ money: {
49
+ inputUsd: breakdown.inputUsd,
50
+ cacheReadUsd: breakdown.cacheReadUsd,
51
+ cacheWriteUsd: breakdown.cacheWriteUsd,
52
+ outputUsd: breakdown.outputUsd,
53
+ },
54
+ pricing: {
55
+ provider: priced.provider ?? 'unknown',
56
+ inputPerMTok: priced.inputPerMTok,
57
+ outputPerMTok: priced.outputPerMTok,
58
+ reviewedOn: PROVIDER_REVIEWED[priced.provider ?? ''] ?? null,
59
+ },
60
+ };
61
+ };
62
+ /**
63
+ * Build a receipt from a profile the caller already computed.
64
+ *
65
+ * Takes the report rather than the log text, and that is the guarantee rather
66
+ * than an ergonomic choice: `UsageProfileReport` has no field that can hold
67
+ * prompt content, so this function could not emit any even if it tried. The
68
+ * narrow input is what makes the promise checkable instead of merely stated.
69
+ */
70
+ export function receiptFrom(report, catalogue, options = {}) {
71
+ const lines = report.byLabelAndModel.map((slice) => lineFrom(slice.label, slice.model, slice.breakdown, catalogue));
72
+ const gaps = [];
73
+ if (report.unpricedModels.length > 0) {
74
+ gaps.push({
75
+ kind: 'unpriced',
76
+ models: [...report.unpricedModels],
77
+ calls: report.unpriced.calls,
78
+ inputTokens: report.unpriced.inputTokens,
79
+ outputTokens: report.unpriced.outputTokens,
80
+ });
81
+ }
82
+ if (report.skippedLines.length > 0) {
83
+ gaps.push({ kind: 'unread-lines', count: report.skippedLines.length });
84
+ }
85
+ if (report.span === null)
86
+ gaps.push({ kind: 'no-clock' });
87
+ /*
88
+ * Summed across the lines rather than read off a total, because the profile
89
+ * keeps this per slice and a receipt reports it once for the document.
90
+ */
91
+ const assumed = report.byLabelAndModel.reduce((sum, slice) => sum + slice.breakdown.assumedWriteTtlCalls, 0);
92
+ if (assumed > 0)
93
+ gaps.push({ kind: 'assumed-write-ttl', calls: assumed });
94
+ return {
95
+ schemaVersion: 1,
96
+ emittedAt: options.emittedAt?.toISOString() ?? null,
97
+ span: report.span === null ? null : { ...report.span },
98
+ counting: 'counted',
99
+ lines,
100
+ /*
101
+ * `report.total` already excludes what could not be priced — the profile
102
+ * keeps those in `unpriced` precisely so a total is never tokens from one
103
+ * set of calls divided by dollars from another. The receipt inherits that
104
+ * separation rather than re-deriving it, and `gaps` carries the size of
105
+ * what is missing.
106
+ */
107
+ total: { calls: report.total.calls, usd: report.total.totalUsd },
108
+ gaps,
109
+ };
110
+ }
111
+ //# sourceMappingURL=receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt.js","sourceRoot":"","sources":["../src/receipt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA2NxC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CA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,mBAAmB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAE1E,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,IAAI;QACnD,IAAI,EAAE,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE;QACtD,QAAQ,EAAE,SAAS;QACnB,KAAK;QACL;;;;;;WAMG;QACH,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;QAChE,IAAI;KACL,CAAC;AACJ,CAAC"}
package/dist/types.d.ts CHANGED
@@ -48,7 +48,7 @@ export interface RuleResult {
48
48
  /** Severity of an advisory: the higher it is, the more money is usually at stake. */
49
49
  export type AdvisorySeverity = 'info' | 'opportunity' | 'warning';
50
50
  /** Every advisory the core can emit. */
51
- export type AdvisoryId = 'context-overflow' | 'context-near-limit' | 'prompt-caching' | 'prompt-caching-not-worth-it' | 'below-cache-minimum' | 'cache-prefix-reorder' | 'batch-api' | 'model-downgrade' | 'tier-signals-conflict' | 'output-dominated' | 'promo-pricing' | 'contradictory-instructions' | 'redundant-examples' | 'restated-output-format' | 'movable-output-schema';
51
+ export type AdvisoryId = 'context-overflow' | 'context-near-limit' | 'prompt-caching' | 'prompt-caching-not-worth-it' | 'below-cache-minimum' | 'cache-prefix-reorder' | 'batch-api' | 'model-downgrade' | 'tier-signals-conflict' | 'output-dominated' | 'promo-pricing' | 'model-retired' | 'contradictory-instructions' | 'redundant-examples' | 'restated-output-format' | 'movable-output-schema';
52
52
  /** A recommendation that does NOT modify the prompt, only informs. */
53
53
  export interface Advisory {
54
54
  id: AdvisoryId;
@@ -125,6 +125,64 @@ export type CachingMode =
125
125
  * what it says.
126
126
  */
127
127
  export type Capability = 'small' | 'mid' | 'large' | 'frontier' | 'unknown';
128
+ /**
129
+ * What makes a conditional rate apply, as data a machine can evaluate.
130
+ *
131
+ * Deliberately a closed union rather than a predicate function. A catalogue
132
+ * entry is reviewed the way a price is reviewed, and a reviewer can check
133
+ * "peak is 01:00-04:00 and 06:00-10:00 UTC on weekdays" against a provider's
134
+ * page; nobody can review a closure. It also means the condition survives
135
+ * `JSON.stringify`, which matters because the catalogue can be overlaid from a
136
+ * file.
137
+ */
138
+ export type TierCondition =
139
+ /**
140
+ * The prompt is larger than `tokens` input tokens.
141
+ *
142
+ * Decidable only where the token count is known, which is most of the places
143
+ * that price a specific call and none of the places that merely rank models.
144
+ * `effectivePricing` says which happened rather than guessing.
145
+ */
146
+ {
147
+ kind: 'input-tokens-above';
148
+ tokens: number;
149
+ }
150
+ /**
151
+ * The call falls inside one of `hours` in UTC, optionally on weekdays only.
152
+ *
153
+ * Decidable everywhere, because every caller already passes the date it is
154
+ * pricing for. `hours` lists the hour each window *starts*, so 01:00-04:00
155
+ * is `[1, 2, 3]` and not `[1, 4]`: an endpoint convention is the kind of
156
+ * thing two readers disagree about silently.
157
+ */
158
+ | {
159
+ kind: 'utc-hours';
160
+ hours: number[];
161
+ weekdaysOnly: boolean;
162
+ };
163
+ /**
164
+ * A rate that applies when its condition holds.
165
+ *
166
+ * Deliberately carries no multipliers of its own, and the first draft did. The
167
+ * reasoning for adding them was that DeepSeek halves the cache-hit price at
168
+ * off-peak along with everything else, so a cache read priced off the base
169
+ * would be wrong about the money — which is true of the *price* and false of
170
+ * the *ratio*: $0.007 against $0.22 and $0.014 against $0.44 are the same
171
+ * 3.18% to the last digit, on both models. Multiplying a tier's own input rate
172
+ * by the model's multiplier already gives the right answer.
173
+ *
174
+ * It was removed because the guard written to prove it mattered could not: with
175
+ * the tier multiplier equal to the base one, dropping it changed nothing and
176
+ * the test passed either way. An option nothing can distinguish from its
177
+ * absence is a claim nobody checks, which is worse than not having it.
178
+ */
179
+ export interface PricingTier {
180
+ /** Short, stable, and printed: a reader has to be able to see which applied. */
181
+ id: string;
182
+ when: TierCondition;
183
+ inputPerMTok: number;
184
+ outputPerMTok: number;
185
+ }
128
186
  export interface ModelPricing {
129
187
  id: string;
130
188
  displayName: string;
@@ -156,6 +214,32 @@ export interface ModelPricing {
156
214
  * buy is advice that wastes their time.
157
215
  */
158
216
  recommendable?: boolean;
217
+ /**
218
+ * Set when the provider refused a real request for this id.
219
+ *
220
+ * A retired model keeps its price and loses its future. Both halves matter:
221
+ * a log full of `deepseek-v3` calls records money that was genuinely spent,
222
+ * so deleting the row would make somebody's own history unpriceable — and a
223
+ * *new* call on that id will not happen at all, so quoting it as an option is
224
+ * a number for a question nobody can ask.
225
+ *
226
+ * `on` is the day `scripts/check-model-availability.mjs` was refused, and
227
+ * `because` is the provider's own sentence, quoted rather than paraphrased.
228
+ * Neither is a judgement, and neither implies anything about what the
229
+ * replacement costs: that is a price, and a price comes off the provider's
230
+ * own page or not at all.
231
+ *
232
+ * A retired model is never recommended, never offered as a cheaper
233
+ * alternative and never chosen as a tier's representative, in the same places
234
+ * `recommendable: false` is honoured — this is a stronger statement than that
235
+ * one and must not be weaker in effect.
236
+ */
237
+ retired?: {
238
+ /** ISO date the refusal was recorded. */
239
+ on: string;
240
+ /** What the provider answered, in the provider's words. */
241
+ because: string;
242
+ };
159
243
  /** Capability, on a vendor-neutral scale. */
160
244
  capability: Capability;
161
245
  /**
@@ -171,6 +255,29 @@ export interface ModelPricing {
171
255
  /** ISO date (inclusive) the promotional price applies until. */
172
256
  until: string;
173
257
  };
258
+ /**
259
+ * Rates that apply only under a stated condition.
260
+ *
261
+ * The catalogue held one input price and one output price per model until a
262
+ * real credential was pointed at the providers and two of them turned out not
263
+ * to charge that way:
264
+ *
265
+ * - **DeepSeek V4 bills by the clock.** Peak is 01:00-04:00 and 06:00-10:00
266
+ * UTC, Monday to Friday, and off-peak is exactly half. That is 35 hours of
267
+ * 168, so the common case is the cheap one and a single number would have
268
+ * been wrong by 2x in whichever direction it was chosen.
269
+ * - **Gemini 3.1 Pro bills by prompt size**, $2/$12 up to 200k input tokens
270
+ * and $4/$18 above it.
271
+ *
272
+ * Both are *conditions*, so both are written as data rather than as prose in
273
+ * `notes`: a note is something a reader has to apply by hand, and this
274
+ * product exists to stop people doing arithmetic by hand.
275
+ *
276
+ * The base `inputPerMTok` and `outputPerMTok` stay the rate that applies when
277
+ * no condition matches, which keeps every model that has no tiers unchanged
278
+ * and keeps this field optional in effect as well as in the type.
279
+ */
280
+ tiers?: PricingTier[];
174
281
  /**
175
282
  * Other ids that bill at exactly this rate.
176
283
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,gEAAgE;AAChE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,YAAI,MAAM,EAAE,YAAY,CAAU,CAAC;AAE3D,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,wEAAwE;IACxE,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED,4EAA4E;AAC5E,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,MA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M,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACpE;AAED,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/core",
3
- "version": "1.82.0",
3
+ "version": "1.83.0",
4
4
  "description": "Trazum core: priced advisories for LLM prompts (caching, model tier, batching, schemas), plus deterministic trimming, token counting and pricing.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
package/src/advisories.ts CHANGED
@@ -2,7 +2,13 @@ import { analyzeCachePrefix } from './cache.js';
2
2
  import { getMessages } from './i18n/index.js';
3
3
  import type { Locale } from './i18n/types.js';
4
4
  import { COMPLEX_SIGNALS, SIMPLE_SIGNALS } from './phrases.js';
5
- import { BUNDLED_CATALOGUE, effectivePricing, modelFrom, multipliersFor } from './pricing.js';
5
+ import {
6
+ BUNDLED_CATALOGUE,
7
+ effectivePricing,
8
+ isOffered,
9
+ modelFrom,
10
+ multipliersFor,
11
+ } from './pricing.js';
6
12
  import type { PricingCatalogue } from './pricing.js';
7
13
  import { formatUsd } from './savings.js';
8
14
  import { analyzeExamples, findContradictions, findMovableSchema,
@@ -124,9 +130,10 @@ function cheapestInTier(
124
130
  (m) =>
125
131
  m.tier === tier &&
126
132
  m.provider === provider &&
127
- // Not generally available: recommending a model the reader cannot call is
128
- // worse than recommending nothing.
129
- m.recommendable !== false,
133
+ // Not generally available, or refused outright by the provider:
134
+ // recommending a model the reader cannot call is worse than
135
+ // recommending nothing. Both halves live in `isOffered`.
136
+ isOffered(m),
130
137
  );
131
138
  if (candidates.length === 0) return undefined;
132
139
  return candidates.reduce((best, m) =>
@@ -639,6 +646,29 @@ export function buildAdvisories(
639
646
  });
640
647
  }
641
648
 
649
+ if (model.retired) {
650
+ /**
651
+ * The most severe thing this function can say about a model, and it is
652
+ * placed before the promotional note deliberately: a price that is about to
653
+ * change matters less than a model that cannot be called at all.
654
+ *
655
+ * Not suppressed when the reader asked for this model by name. They asked
656
+ * because something in their world still says this id, and the whole value
657
+ * of the answer is that it no longer works.
658
+ */
659
+ advisories.push({
660
+ id: 'model-retired',
661
+ severity: 'warning',
662
+ ...t.advisories.modelRetired({
663
+ modelName: model.displayName,
664
+ modelId: model.id,
665
+ on: model.retired.on,
666
+ because: model.retired.because,
667
+ }),
668
+ estimatedMonthlyUsd: null,
669
+ });
670
+ }
671
+
642
672
  if (promoApplied && model.promo) {
643
673
  advisories.push({
644
674
  id: 'promo-pricing',
package/src/i18n/en.ts CHANGED
@@ -218,6 +218,15 @@ export const en: CoreMessages = {
218
218
  detail: `${modelName} has introductory pricing of ${promoInput}/${promoOutput} per million tokens until ${until}. After that date it moves to ${listInput}/${listOutput}: your bill goes up even if you change nothing.`,
219
219
  }),
220
220
 
221
+ modelRetired: ({ modelName, modelId, on, because }) => ({
222
+ title: `${modelName} is priced here and refused by its provider`,
223
+ detail:
224
+ `A real request for \`${modelId}\` was answered with an error on ${on}: "${because}" `
225
+ + 'The price above is still the right one for calls already in your log, because that '
226
+ + 'money was spent. A new call on this id will not run. Nothing here proposes what the '
227
+ + 'replacement costs: that figure comes off the provider\'s own pricing page or not at all.',
228
+ }),
229
+
221
230
  contradictoryInstructions: ({
222
231
  axis,
223
232
  firstValue,
package/src/i18n/es.ts CHANGED
@@ -202,6 +202,16 @@ export const es: CoreMessages = {
202
202
  detail: `${modelName} tiene precio de lanzamiento ${promoInput}/${promoOutput} por millón de tokens hasta el ${until}. A partir de esa fecha pasa a ${listInput}/${listOutput}: tu factura subirá aunque no cambies nada.`,
203
203
  }),
204
204
 
205
+ modelRetired: ({ modelName, modelId, on, because }) => ({
206
+ title: `${modelName} está tarifado aquí y su proveedor lo rechaza`,
207
+ detail:
208
+ `Una petición real a \`${modelId}\` se respondió con un error el ${on}: "${because}" `
209
+ + 'El precio de arriba sigue siendo el correcto para las llamadas que ya están en tu '
210
+ + 'registro, porque ese dinero se gastó. Una llamada nueva a este id no se ejecutará. '
211
+ + 'Aquí no se propone lo que cuesta el reemplazo: esa cifra sale de la página de precios '
212
+ + 'del proveedor o no sale.',
213
+ }),
214
+
205
215
  contradictoryInstructions: ({
206
216
  axis,
207
217
  firstValue,