@trazum/core 2.7.12 → 3.0.1
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/advisories.d.ts +14 -7
- package/dist/advisories.d.ts.map +1 -1
- package/dist/advisories.js +27 -20
- package/dist/advisories.js.map +1 -1
- package/dist/i18n/en.js +2 -2
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.js +2 -2
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +2 -1
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/openrouter.d.ts +1 -1
- package/dist/openrouter.d.ts.map +1 -1
- package/dist/openrouter.js +1 -2
- package/dist/openrouter.js.map +1 -1
- package/dist/pricing-overlay.d.ts +1 -1
- package/dist/pricing-overlay.d.ts.map +1 -1
- package/dist/pricing-overlay.js +19 -9
- package/dist/pricing-overlay.js.map +1 -1
- package/dist/pricing.d.ts +8 -5
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +11 -99
- package/dist/pricing.js.map +1 -1
- package/dist/review.js +2 -1
- package/dist/review.js.map +1 -1
- package/dist/segment.d.ts +31 -1
- package/dist/segment.d.ts.map +1 -1
- package/dist/segment.js +52 -4
- package/dist/segment.js.map +1 -1
- package/dist/structure.d.ts +34 -0
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +143 -12
- package/dist/structure.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.js +11 -11
- package/dist/watch.d.ts +11 -1
- package/dist/watch.d.ts.map +1 -1
- package/dist/watch.js.map +1 -1
- package/dist/weekly.d.ts +140 -0
- package/dist/weekly.d.ts.map +1 -0
- package/dist/weekly.js +176 -0
- package/dist/weekly.js.map +1 -0
- package/dist/write.js +2 -2
- package/dist/write.js.map +1 -1
- package/package.json +1 -1
- package/src/advisories.ts +41 -25
- package/src/i18n/en.ts +2 -2
- package/src/i18n/es.ts +2 -2
- package/src/i18n/types.ts +2 -1
- package/src/index.ts +4 -2
- package/src/openrouter.ts +1 -2
- package/src/pricing-overlay.ts +21 -12
- package/src/pricing.ts +13 -101
- package/src/review.ts +1 -1
- package/src/segment.ts +50 -6
- package/src/structure.ts +152 -13
- package/src/types.ts +6 -6
- package/src/usage.ts +11 -11
- package/src/watch.ts +12 -1
- package/src/weekly.ts +281 -0
- package/src/write.ts +2 -2
package/dist/weekly.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The week in three paragraphs: what it cost, what moved against the week
|
|
3
|
+
* before, and the three changes worth making first.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here is estimated. The bill and the movement are two measured
|
|
6
|
+
* reports, one per week, priced by the same catalogue; the changes are the
|
|
7
|
+
* ranked actions `buildPlan` already derives from the week's own report, and
|
|
8
|
+
* each carries what was measured before it. A saving that has not happened is
|
|
9
|
+
* a projection and says so; `verify` is what measures it afterwards.
|
|
10
|
+
*
|
|
11
|
+
* **A figure in the summary is a figure in the bill.** The summary is text a
|
|
12
|
+
* person reads in an issue and acts on, so every dollar amount and every
|
|
13
|
+
* percentage it prints has to be one the two reports (or the plan made from
|
|
14
|
+
* them) hold. `billFigures` works the allowed set out from the reports
|
|
15
|
+
* themselves, by a route that shares no code with the builder, and
|
|
16
|
+
* `strayFigures` reads a rendered summary and names what is not in it. The CLI
|
|
17
|
+
* refuses to write a summary with a stray figure in it: a wrong number in a
|
|
18
|
+
* weekly note is worse than no note, because nobody re-adds it.
|
|
19
|
+
*
|
|
20
|
+
* Browser-safe like the rest of the core: reports in, one document out. The
|
|
21
|
+
* words belong to whoever renders it, in the reader's language.
|
|
22
|
+
*/
|
|
23
|
+
import { formatUsd } from './savings.js';
|
|
24
|
+
const DAY_MS = 86_400_000;
|
|
25
|
+
export const WEEK_MS = 7 * DAY_MS;
|
|
26
|
+
/** How many changes a weekly summary names. Three is the issue's number; more is a list nobody acts on. */
|
|
27
|
+
export const WEEKLY_CHANGES = 3;
|
|
28
|
+
/** How many models the bill and the movement name before saying how many more there are. */
|
|
29
|
+
export const WEEKLY_MODELS = 5;
|
|
30
|
+
export const WEEKLY_MOVERS = 3;
|
|
31
|
+
const dayOf = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
32
|
+
const windowOf = (sinceMs, untilMs) => ({
|
|
33
|
+
sinceMs,
|
|
34
|
+
untilMs,
|
|
35
|
+
firstDay: dayOf(sinceMs),
|
|
36
|
+
lastDay: dayOf(untilMs - 1),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* The week ending at `untilMs` and the week before it.
|
|
40
|
+
*
|
|
41
|
+
* Seven days each, back to back, with no overlap and no gap: the week before
|
|
42
|
+
* ends at the instant this one begins.
|
|
43
|
+
*/
|
|
44
|
+
export function weekWindows(untilMs) {
|
|
45
|
+
return {
|
|
46
|
+
current: windowOf(untilMs - WEEK_MS, untilMs),
|
|
47
|
+
previous: windowOf(untilMs - 2 * WEEK_MS, untilMs - WEEK_MS),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const pricedModels = (report) => report.byModel
|
|
51
|
+
.filter((row) => !report.unpricedModels.includes(row.model))
|
|
52
|
+
.map((row) => ({ model: row.model, calls: row.breakdown.calls, usd: row.breakdown.totalUsd }));
|
|
53
|
+
/**
|
|
54
|
+
* Builds the summary from the week's report, the week before's, and the plan
|
|
55
|
+
* made from this week's.
|
|
56
|
+
*/
|
|
57
|
+
export function buildWeeklySummary(current, previous, plan, windows) {
|
|
58
|
+
const models = pricedModels(current);
|
|
59
|
+
let comparison = null;
|
|
60
|
+
if (previous.total.calls > 0) {
|
|
61
|
+
const before = new Map(pricedModels(previous).map((row) => [row.model, row.usd]));
|
|
62
|
+
const now = new Map(models.map((row) => [row.model, row.usd]));
|
|
63
|
+
const movers = [...new Set([...before.keys(), ...now.keys()])]
|
|
64
|
+
.map((model) => {
|
|
65
|
+
const previousUsd = before.get(model) ?? 0;
|
|
66
|
+
const currentUsd = now.get(model) ?? 0;
|
|
67
|
+
return { model, previousUsd, currentUsd, deltaUsd: currentUsd - previousUsd };
|
|
68
|
+
})
|
|
69
|
+
.filter((row) => row.deltaUsd !== 0)
|
|
70
|
+
.sort((a, b) => Math.abs(b.deltaUsd) - Math.abs(a.deltaUsd) || a.model.localeCompare(b.model))
|
|
71
|
+
.slice(0, WEEKLY_MOVERS);
|
|
72
|
+
const previousUsd = previous.total.totalUsd;
|
|
73
|
+
const deltaUsd = current.total.totalUsd - previousUsd;
|
|
74
|
+
comparison = {
|
|
75
|
+
previousUsd,
|
|
76
|
+
previousCalls: previous.total.calls,
|
|
77
|
+
deltaUsd,
|
|
78
|
+
deltaPct: previousUsd > 0 ? (deltaUsd / previousUsd) * 100 : null,
|
|
79
|
+
movers,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const changes = plan.actions.slice(0, WEEKLY_CHANGES).map((action, index) => ({
|
|
83
|
+
rank: index + 1,
|
|
84
|
+
kind: action.kind,
|
|
85
|
+
label: action.label,
|
|
86
|
+
model: action.model,
|
|
87
|
+
projectedSavingUsd: action.savingUsd,
|
|
88
|
+
measuredStakeUsd: action.stakeUsd,
|
|
89
|
+
sliceUsd: action.detail.baseline?.usd ?? null,
|
|
90
|
+
sliceCalls: action.detail.baseline?.calls ?? null,
|
|
91
|
+
routeTo: action.detail.routeTo?.displayName ?? null,
|
|
92
|
+
assumes: [...action.assumes],
|
|
93
|
+
}));
|
|
94
|
+
return {
|
|
95
|
+
current: windows.current,
|
|
96
|
+
previous: windows.previous,
|
|
97
|
+
totalUsd: current.total.totalUsd,
|
|
98
|
+
calls: current.total.calls,
|
|
99
|
+
models: models.slice(0, WEEKLY_MODELS),
|
|
100
|
+
moreModels: Math.max(0, models.length - WEEKLY_MODELS),
|
|
101
|
+
unpricedModels: [...current.unpricedModels],
|
|
102
|
+
unpricedCalls: current.unpriced.calls,
|
|
103
|
+
undatedExcluded: current.timeWindow?.undatedExcluded ?? 0,
|
|
104
|
+
comparison,
|
|
105
|
+
changes,
|
|
106
|
+
changesAvailable: plan.actions.length,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* What the reports hold, worked out from the reports.
|
|
111
|
+
*
|
|
112
|
+
* It reads the two reports and the plan directly and shares nothing with
|
|
113
|
+
* `buildWeeklySummary`, so a figure the builder gets wrong (a total scaled, a
|
|
114
|
+
* delta taken the wrong way round, a saving summed across actions that
|
|
115
|
+
* overlap) is not in this set and is named by `strayFigures`.
|
|
116
|
+
*/
|
|
117
|
+
export function billFigures(current, previous, plan) {
|
|
118
|
+
const usd = new Set(['$0']);
|
|
119
|
+
const pct = new Set();
|
|
120
|
+
const add = (value) => {
|
|
121
|
+
if (value === null || value === undefined || !Number.isFinite(value))
|
|
122
|
+
return;
|
|
123
|
+
usd.add(formatUsd(Math.abs(value)));
|
|
124
|
+
};
|
|
125
|
+
add(current.total.totalUsd);
|
|
126
|
+
add(previous.total.totalUsd);
|
|
127
|
+
add(current.total.totalUsd - previous.total.totalUsd);
|
|
128
|
+
const rows = (report) => new Map(report.byModel.map((row) => [row.model, row.breakdown.totalUsd]));
|
|
129
|
+
const now = rows(current);
|
|
130
|
+
const before = rows(previous);
|
|
131
|
+
for (const model of new Set([...now.keys(), ...before.keys()])) {
|
|
132
|
+
const a = now.get(model) ?? 0;
|
|
133
|
+
const b = before.get(model) ?? 0;
|
|
134
|
+
add(a);
|
|
135
|
+
add(b);
|
|
136
|
+
add(a - b);
|
|
137
|
+
}
|
|
138
|
+
for (const action of plan.actions) {
|
|
139
|
+
add(action.savingUsd);
|
|
140
|
+
add(action.stakeUsd);
|
|
141
|
+
add(action.detail.baseline?.usd);
|
|
142
|
+
}
|
|
143
|
+
if (previous.total.totalUsd > 0) {
|
|
144
|
+
const change = ((current.total.totalUsd - previous.total.totalUsd) / previous.total.totalUsd) * 100;
|
|
145
|
+
pct.add(Math.abs(change).toFixed(1));
|
|
146
|
+
}
|
|
147
|
+
return { usd, pct };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Prose a reader sees as prose is checked; what names a workload, a model or a
|
|
151
|
+
* command is not. Those are written between backticks, and a label such as
|
|
152
|
+
* `50% off` is the author's word, not a figure Trazum computed.
|
|
153
|
+
*/
|
|
154
|
+
const withoutCode = (text) => text.replace(/`[^`\n]*`/g, '');
|
|
155
|
+
/**
|
|
156
|
+
* The dollar amounts and percentages in a rendered summary that no report
|
|
157
|
+
* holds. Empty when every one is accounted for.
|
|
158
|
+
*/
|
|
159
|
+
export function strayFigures(markdown, figures) {
|
|
160
|
+
const prose = withoutCode(markdown);
|
|
161
|
+
const stray = [];
|
|
162
|
+
for (const [amount] of prose.matchAll(/\$\d[\d,]*(?:\.\d+)?/g)) {
|
|
163
|
+
if (!figures.usd.has(amount))
|
|
164
|
+
stray.push(amount);
|
|
165
|
+
}
|
|
166
|
+
for (const [, number] of prose.matchAll(/(\d+(?:\.\d+)?)%/g)) {
|
|
167
|
+
if (number !== undefined && !figures.pct.has(number))
|
|
168
|
+
stray.push(`${number}%`);
|
|
169
|
+
}
|
|
170
|
+
return [...new Set(stray)];
|
|
171
|
+
}
|
|
172
|
+
/** The identifier a weekly summary carries so a re-run replaces it rather than adding a second. */
|
|
173
|
+
export function weeklyMarker(lastDay) {
|
|
174
|
+
return `<!-- trazum-weekly:${lastDay} -->`;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=weekly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly.js","sourceRoot":"","sources":["../src/weekly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAA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,CAAC;AAC7C,CAAC"}
|
package/dist/write.js
CHANGED
|
@@ -43,7 +43,7 @@ export const SECTIONS = [
|
|
|
43
43
|
* imports the wrong one.
|
|
44
44
|
*/
|
|
45
45
|
export const OUTPUT_FORMATS = ['prose', 'json', 'list', 'table'];
|
|
46
|
-
const answered = (answers, id) => Object.
|
|
46
|
+
const answered = (answers, id) => Object.hasOwn(answers, id) && answers[id] !== null;
|
|
47
47
|
const shapeIs = (...formats) => (answers) => {
|
|
48
48
|
const shape = answers['output-shape'];
|
|
49
49
|
return typeof shape === 'string' && formats.includes(shape);
|
|
@@ -86,7 +86,7 @@ export function isOpen(entry, answers) {
|
|
|
86
86
|
}
|
|
87
87
|
export function interview(answers) {
|
|
88
88
|
const open = SLOTS.filter((entry) => isOpen(entry, answers));
|
|
89
|
-
const has = (entry) => Object.
|
|
89
|
+
const has = (entry) => Object.hasOwn(answers, entry.id);
|
|
90
90
|
const unasked = open.filter((entry) => !has(entry));
|
|
91
91
|
return {
|
|
92
92
|
next: unasked[0]?.id ?? null,
|
package/dist/write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM;IACN,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,aAAa;IACb,UAAU;IACV,eAAe;CACP,CAAC;AAkCX;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAG1E,MAAM,QAAQ,GAAG,CAAC,OAAgB,EAAE,EAAU,EAAW,EAAE,CACzD,MAAM,CAAC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AAI,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM;YAClF,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;YAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB;QACD,KAAK,EAAE;YACL,MAAM,EAAE,MAAM,CAAC,YAAY;YAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,KAAK;YACL,UAAU;YACV,UAAU,EAAE,WAAW;YACvB,SAAS;YACT,OAAO;YACP,MAAM;SACP;QACD,KAAK,EAAE;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;iBAChB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;iBACjC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACvD,iBAAiB,EAAE,MAAM,CAAC,WAAW;SACtC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trazum/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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
|
@@ -15,7 +15,7 @@ import { analyzeExamples, findContradictions, findMovableSchema,
|
|
|
15
15
|
findRestatedFormat } from './structure.js';
|
|
16
16
|
import { bandGoverns, estimateTokens } from './tokenizer.js';
|
|
17
17
|
import { bandFor } from './band.js';
|
|
18
|
-
import type { Advisory, ModelPricing, TokenCounter, UsageProfile } from './types.js';
|
|
18
|
+
import type { Advisory, Capability, ModelPricing, TokenCounter, UsageProfile } from './types.js';
|
|
19
19
|
|
|
20
20
|
function countSignals(haystack: string, signals: readonly string[]): number {
|
|
21
21
|
let count = 0;
|
|
@@ -23,9 +23,16 @@ function countSignals(haystack: string, signals: readonly string[]): number {
|
|
|
23
23
|
return count;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* What `recommendTier` answers: a capability a model can carry, in the
|
|
28
|
+
* catalogue's own vocabulary. The heuristic has three answers, so `frontier`
|
|
29
|
+
* and `unknown` are never among them.
|
|
30
|
+
*/
|
|
31
|
+
type RecommendedCapability = Extract<Capability, 'small' | 'mid' | 'large'>;
|
|
32
|
+
|
|
26
33
|
/** What `recommendTierDetailed` saw, not only what it concluded. */
|
|
27
34
|
export interface TierRecommendation {
|
|
28
|
-
|
|
35
|
+
capability: RecommendedCapability;
|
|
29
36
|
complexSignals: number;
|
|
30
37
|
simpleSignals: number;
|
|
31
38
|
/**
|
|
@@ -33,7 +40,7 @@ export interface TierRecommendation {
|
|
|
33
40
|
* heuristic has no business preferring either.
|
|
34
41
|
*
|
|
35
42
|
* The score subtracts one side from the other, so three complex signals
|
|
36
|
-
* against three simple ones cancels to zero and returns `
|
|
43
|
+
* against three simple ones cancels to zero and returns `mid` — the same
|
|
37
44
|
* answer as a prompt with **no signals at all**. Those are opposite
|
|
38
45
|
* situations reported identically: one is "nothing here suggests a tier", the
|
|
39
46
|
* other is "this prompt contradicts itself about which tier it needs", and
|
|
@@ -49,7 +56,7 @@ export interface TierRecommendation {
|
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
|
-
* Estimates the capability
|
|
59
|
+
* Estimates the capability the prompt needs, and says what it saw.
|
|
53
60
|
*
|
|
54
61
|
* This is a keyword-and-size heuristic, not a judgement about answer quality.
|
|
55
62
|
* Treat it as a hypothesis to validate with your own evaluations before
|
|
@@ -67,9 +74,9 @@ export function recommendTierDetailed(prompt: string, tokens: number): TierRecom
|
|
|
67
74
|
|
|
68
75
|
if (/```|~~~/.test(prompt)) score += 1;
|
|
69
76
|
|
|
70
|
-
const
|
|
77
|
+
const capability: RecommendedCapability = score >= 3 ? 'large' : score >= 0 ? 'mid' : 'small';
|
|
71
78
|
return {
|
|
72
|
-
|
|
79
|
+
capability,
|
|
73
80
|
complexSignals,
|
|
74
81
|
simpleSignals,
|
|
75
82
|
conflicted:
|
|
@@ -78,37 +85,42 @@ export function recommendTierDetailed(prompt: string, tokens: number): TierRecom
|
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
/**
|
|
81
|
-
* The
|
|
88
|
+
* The capability alone: `small`, `mid` or `large`, the names a model's
|
|
89
|
+
* `capability` carries. Until 3.0.0 it answered `haiku`, `sonnet` or `opus`.
|
|
82
90
|
*
|
|
83
|
-
* Kept because it is public API and the 1.x line does not change shapes.
|
|
84
91
|
* Callers that need to know whether the answer is trustworthy reach for
|
|
85
92
|
* `recommendTierDetailed`.
|
|
86
93
|
*/
|
|
87
|
-
export function recommendTier(prompt: string, tokens: number):
|
|
88
|
-
return recommendTierDetailed(prompt, tokens).
|
|
94
|
+
export function recommendTier(prompt: string, tokens: number): RecommendedCapability {
|
|
95
|
+
return recommendTierDetailed(prompt, tokens).capability;
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Capabilities in order, so a suggestion can be compared with the model in use.
|
|
100
|
+
*
|
|
101
|
+
* Keyed by `capability`, the one scale a model and a recommendation share.
|
|
102
|
+
*/
|
|
103
|
+
const CAPABILITY_ORDER: Record<Capability, number> = {
|
|
92
104
|
/**
|
|
93
105
|
* Below every real tier, so no tier is ever "less capable than unknown".
|
|
94
106
|
*
|
|
95
107
|
* The value carries the intent rather than the guard below carrying it alone.
|
|
96
108
|
* Set the other way — above everything — the comparison
|
|
97
|
-
* `
|
|
109
|
+
* `CAPABILITY_ORDER[suggested] < CAPABILITY_ORDER['unknown']` is true for every prompt,
|
|
98
110
|
* and the only thing left standing between that and a recommendation is an
|
|
99
111
|
* unrelated provider filter. Mutation testing found exactly that: deleting
|
|
100
112
|
* the guard changed no test result, because a second accident was covering
|
|
101
113
|
* for it. Two accidents in a row is not a design.
|
|
102
114
|
*/
|
|
103
115
|
unknown: Number.NEGATIVE_INFINITY,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
small: 0,
|
|
117
|
+
mid: 1,
|
|
118
|
+
large: 2,
|
|
107
119
|
frontier: 3,
|
|
108
120
|
};
|
|
109
121
|
|
|
110
122
|
/**
|
|
111
|
-
* Cheapest model of a capability
|
|
123
|
+
* Cheapest model of a capability, using today's effective input price.
|
|
112
124
|
*
|
|
113
125
|
* **Within the same provider**, which is a product decision rather than an
|
|
114
126
|
* implementation detail. Dropping from Opus to Sonnet is a one-line change;
|
|
@@ -120,8 +132,8 @@ const TIER_ORDER: Record<ModelPricing['tier'], number> = {
|
|
|
120
132
|
* A model with no provider recorded only matches others with none, so an overlay
|
|
121
133
|
* that adds a bare model cannot pull a switch out of thin air.
|
|
122
134
|
*/
|
|
123
|
-
function
|
|
124
|
-
|
|
135
|
+
function cheapestInCapability(
|
|
136
|
+
capability: Capability,
|
|
125
137
|
on: Date,
|
|
126
138
|
pricing: PricingCatalogue,
|
|
127
139
|
provider: string | undefined,
|
|
@@ -129,7 +141,7 @@ function cheapestInTier(
|
|
|
129
141
|
): ModelPricing | undefined {
|
|
130
142
|
const candidates = pricing.models.filter(
|
|
131
143
|
(m) =>
|
|
132
|
-
m.
|
|
144
|
+
m.capability === capability &&
|
|
133
145
|
m.provider === provider &&
|
|
134
146
|
// Not generally available, or refused outright by the provider:
|
|
135
147
|
// recommending a model the reader cannot call is worse than
|
|
@@ -464,14 +476,14 @@ export function buildAdvisories(
|
|
|
464
476
|
|
|
465
477
|
// --- Recommended model ---
|
|
466
478
|
const recommendation = recommendTierDetailed(optimizedPrompt, tokensAfter);
|
|
467
|
-
const
|
|
479
|
+
const suggestedCapability = recommendation.capability;
|
|
468
480
|
|
|
469
481
|
/**
|
|
470
482
|
* When the prompt argues with itself about which tier it needs, say so and
|
|
471
483
|
* recommend nothing.
|
|
472
484
|
*
|
|
473
485
|
* The score subtracts one side from the other, so a prompt demanding depth
|
|
474
|
-
* and brevity in equal measure cancels to zero and lands on `
|
|
486
|
+
* and brevity in equal measure cancels to zero and lands on `mid` — the
|
|
475
487
|
* identical answer to a prompt with no signals at all. Reporting two opposite
|
|
476
488
|
* situations with one number is the failure; the fix is not a better score,
|
|
477
489
|
* it is declining to pretend there is one.
|
|
@@ -502,14 +514,18 @@ export function buildAdvisories(
|
|
|
502
514
|
* stop reading the prompt.
|
|
503
515
|
*
|
|
504
516
|
* **Deliberately redundant**, and the one surviving mutant in this change.
|
|
505
|
-
* `
|
|
517
|
+
* `CAPABILITY_ORDER.unknown` is `-Infinity`, so the comparison is already false and
|
|
506
518
|
* deleting this clause changes no behaviour and no test. It stays because the
|
|
507
519
|
* two express the same rule in different places: an ordering that forgets it
|
|
508
520
|
* and a condition that forgets it both have to happen before a model of
|
|
509
521
|
* unrecorded capability is told it is overpowered.
|
|
510
522
|
*/
|
|
511
|
-
if (
|
|
512
|
-
|
|
523
|
+
if (
|
|
524
|
+
!recommendation.conflicted &&
|
|
525
|
+
model.capability !== 'unknown' &&
|
|
526
|
+
CAPABILITY_ORDER[suggestedCapability] < CAPABILITY_ORDER[model.capability]
|
|
527
|
+
) {
|
|
528
|
+
const candidate = cheapestInCapability(suggestedCapability, on, pricing, model.provider, size);
|
|
513
529
|
if (candidate) {
|
|
514
530
|
const candidatePricing = effectivePricing(candidate, on, size);
|
|
515
531
|
/**
|
|
@@ -540,7 +556,7 @@ export function buildAdvisories(
|
|
|
540
556
|
severity: 'opportunity',
|
|
541
557
|
...t.advisories.modelDowngrade({
|
|
542
558
|
modelName: model.displayName,
|
|
543
|
-
|
|
559
|
+
capability: suggestedCapability,
|
|
544
560
|
candidateName: candidate.displayName,
|
|
545
561
|
currentUsd: formatUsd(monthlyInputUsd + monthlyOutputUsd),
|
|
546
562
|
candidateUsd: formatUsd(candidateMonthly),
|
package/src/i18n/en.ts
CHANGED
|
@@ -198,9 +198,9 @@ export const en: CoreMessages = {
|
|
|
198
198
|
'The Batch API applies a 50% discount on both input and output. Most batches finish in under an hour, with a 24-hour maximum. It fits bulk classification, data enrichment or evaluations: anything that is not answering a user in real time.',
|
|
199
199
|
}),
|
|
200
200
|
|
|
201
|
-
modelDowngrade: ({ modelName,
|
|
201
|
+
modelDowngrade: ({ modelName, capability, candidateName, currentUsd, candidateUsd }) => ({
|
|
202
202
|
title: `This task may not need ${modelName}`,
|
|
203
|
-
detail: `By length and vocabulary the prompt looks like "${
|
|
203
|
+
detail: `By length and vocabulary the prompt looks like "${capability}" complexity. On ${candidateName} you would go from ${currentUsd} to ${candidateUsd} per month. This is a keyword heuristic, not a judgement about answer quality. Measure it before switching in production: \`trazum route <log.jsonl> --prompt-file <prompt> --cases <cases> --yes\` sends the same cases to both models and reports whether the cheaper one still does the job.`,
|
|
204
204
|
}),
|
|
205
205
|
|
|
206
206
|
tierSignalsConflict: ({ complexSignals, simpleSignals }) => ({
|
package/src/i18n/es.ts
CHANGED
|
@@ -182,9 +182,9 @@ export const es: CoreMessages = {
|
|
|
182
182
|
'La Batch API aplica un 50% de descuento sobre entrada y salida. La mayoría de lotes terminan en menos de una hora, con un máximo de 24. Sirve para clasificación masiva, enriquecimiento de datos o evaluaciones: cualquier cosa que no responda a un usuario en tiempo real.',
|
|
183
183
|
}),
|
|
184
184
|
|
|
185
|
-
modelDowngrade: ({ modelName,
|
|
185
|
+
modelDowngrade: ({ modelName, capability, candidateName, currentUsd, candidateUsd }) => ({
|
|
186
186
|
title: `Esta tarea quizá no necesite ${modelName}`,
|
|
187
|
-
detail: `Por longitud y vocabulario, el prompt parece de complejidad "${
|
|
187
|
+
detail: `Por longitud y vocabulario, el prompt parece de complejidad "${capability}". Con ${candidateName} pasarías de ${currentUsd} a ${candidateUsd} al mes. Es una heurística por palabras clave, no un juicio de calidad. Mídelo antes de cambiar en producción: \`trazum route <log.jsonl> --prompt-file <prompt> --cases <casos> --yes\` envía los mismos casos a ambos modelos y dice si el barato sigue haciendo el trabajo.`,
|
|
188
188
|
}),
|
|
189
189
|
|
|
190
190
|
tierSignalsConflict: ({ complexSignals, simpleSignals }) => ({
|
package/src/i18n/types.ts
CHANGED
|
@@ -149,7 +149,8 @@ export interface CachePrefixReorderParams {
|
|
|
149
149
|
|
|
150
150
|
export interface ModelDowngradeParams {
|
|
151
151
|
modelName: string;
|
|
152
|
-
|
|
152
|
+
/** What the prompt looks like it needs: `small`, `mid` or `large`. */
|
|
153
|
+
capability: string;
|
|
153
154
|
candidateName: string;
|
|
154
155
|
currentUsd: string;
|
|
155
156
|
candidateUsd: string;
|
package/src/index.ts
CHANGED
|
@@ -79,6 +79,8 @@ export { buildPlan, planLabelName, parsePlanDocument, PLAN_ACTION_KINDS } from '
|
|
|
79
79
|
export type { PlanParseFailure, PlanParseResult } from './plan.js';
|
|
80
80
|
export type { PlanAction, PlanActionKind, PlanAssumption, PlanDocument } from './plan.js';
|
|
81
81
|
export { verifyPlan } from './verify.js';
|
|
82
|
+
export { buildWeeklySummary, billFigures, strayFigures, weekWindows, weeklyMarker, WEEK_MS, WEEKLY_CHANGES, WEEKLY_MODELS, WEEKLY_MOVERS } from './weekly.js';
|
|
83
|
+
export type { BillFigures, WeekWindow, WeeklyChange, WeeklyModelRow, WeeklyMover, WeeklySummary } from './weekly.js';
|
|
82
84
|
export { buildHistory, storedReportFrom, MIN_RUN } from './history.js';
|
|
83
85
|
export { outcomeReport, judgeOutcome, OUTCOME_UNLOCKS } from './outcome.js';
|
|
84
86
|
export {
|
|
@@ -442,9 +444,9 @@ export {
|
|
|
442
444
|
getModel,
|
|
443
445
|
listModels,
|
|
444
446
|
effectivePricing,
|
|
445
|
-
|
|
447
|
+
cheapestOfCapability,
|
|
446
448
|
modelFrom,
|
|
447
|
-
|
|
449
|
+
cheapestOfCapabilityIn,
|
|
448
450
|
multipliersFor,
|
|
449
451
|
isOffered,
|
|
450
452
|
serviceTierOf,
|
package/src/openrouter.ts
CHANGED
|
@@ -61,7 +61,7 @@ function perMillion(raw: unknown): number | null {
|
|
|
61
61
|
*
|
|
62
62
|
* `knownIds` is the set the bundled catalogue already has. For those, only the
|
|
63
63
|
* three things OpenRouter actually knows are overridden — price in, price out,
|
|
64
|
-
* context window. `cacheMinTokens`, `caching
|
|
64
|
+
* context window. `cacheMinTokens`, `caching` and `capability` are left
|
|
65
65
|
* alone, because the bundled entry was written by somebody who looked them up
|
|
66
66
|
* and this feed has nothing to say about them. Overwriting a researched fact
|
|
67
67
|
* with a blank is not a refresh.
|
|
@@ -117,7 +117,6 @@ export function openrouterOverlay(
|
|
|
117
117
|
cacheMinTokens: null,
|
|
118
118
|
caching: 'unknown',
|
|
119
119
|
capability: 'unknown',
|
|
120
|
-
tier: 'unknown',
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
|
package/src/pricing-overlay.ts
CHANGED
|
@@ -29,7 +29,6 @@ export const PRICING_MODEL_KEYS = [
|
|
|
29
29
|
'outputPerMTok',
|
|
30
30
|
'contextWindow',
|
|
31
31
|
'cacheMinTokens',
|
|
32
|
-
'tier',
|
|
33
32
|
'capability',
|
|
34
33
|
'caching',
|
|
35
34
|
'notes',
|
|
@@ -61,7 +60,6 @@ const PROMO_KEYS = ['inputPerMTok', 'outputPerMTok', 'until'] as const;
|
|
|
61
60
|
*/
|
|
62
61
|
const MULTIPLIER_KEYS = ['cacheRead', 'cacheWrite5m', 'cacheWrite1h', 'batch', 'batchCacheRead'] as const;
|
|
63
62
|
|
|
64
|
-
const TIERS: ModelPricing['tier'][] = ['frontier', 'opus', 'sonnet', 'haiku', 'unknown'];
|
|
65
63
|
const CAPABILITIES: Capability[] = ['small', 'mid', 'large', 'frontier', 'unknown'];
|
|
66
64
|
const CACHING_MODES: CachingMode[] = ['explicit', 'automatic', 'none', 'unknown'];
|
|
67
65
|
|
|
@@ -182,6 +180,24 @@ function parseMultipliers(raw: unknown, label: string, source: string): CostMult
|
|
|
182
180
|
return multipliers;
|
|
183
181
|
}
|
|
184
182
|
|
|
183
|
+
/**
|
|
184
|
+
* `tier` was a key on a model until 3.0.0, which removed it.
|
|
185
|
+
*
|
|
186
|
+
* Refused by name, ahead of the unknown-key check, so the reader is told what
|
|
187
|
+
* to write instead rather than offered the nearest spelling. Not ignored: a
|
|
188
|
+
* key somebody wrote and nothing reads is a setting that looks set. Checked on
|
|
189
|
+
* a parsed document and again on an overlay handed to `applyPricingOverlay` as
|
|
190
|
+
* an object, which no parser has read.
|
|
191
|
+
*/
|
|
192
|
+
function refuseTier(raw: unknown, id: string, source: string): void {
|
|
193
|
+
if (!isPlainObject(raw) || !('tier' in raw)) return;
|
|
194
|
+
throw new PricingOverlayError(
|
|
195
|
+
`"models.${id}.tier" was removed in 3.0.0. Write "capability" instead: ` +
|
|
196
|
+
'haiku is "small", sonnet is "mid", opus is "large", frontier is "frontier", unknown is "unknown"',
|
|
197
|
+
source,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
185
201
|
function parseModel(
|
|
186
202
|
raw: unknown,
|
|
187
203
|
id: string,
|
|
@@ -190,6 +206,7 @@ function parseModel(
|
|
|
190
206
|
if (!isPlainObject(raw)) {
|
|
191
207
|
throw new PricingOverlayError(`"models.${id}" must be an object`, source);
|
|
192
208
|
}
|
|
209
|
+
refuseTier(raw, id, source);
|
|
193
210
|
rejectUnknownKeys(raw, PRICING_MODEL_KEYS, source, `models.${id}.`);
|
|
194
211
|
if (Object.keys(raw).length === 0) {
|
|
195
212
|
throw new PricingOverlayError(
|
|
@@ -243,15 +260,6 @@ function parseModel(
|
|
|
243
260
|
}
|
|
244
261
|
model.caching = raw.caching as CachingMode;
|
|
245
262
|
}
|
|
246
|
-
if (raw.tier !== undefined) {
|
|
247
|
-
if (typeof raw.tier !== 'string' || !TIERS.includes(raw.tier as ModelPricing['tier'])) {
|
|
248
|
-
throw new PricingOverlayError(
|
|
249
|
-
`"models.${id}.tier" must be one of ${TIERS.join(', ')}`,
|
|
250
|
-
source,
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
model.tier = raw.tier as ModelPricing['tier'];
|
|
254
|
-
}
|
|
255
263
|
if (raw.notes !== undefined) {
|
|
256
264
|
if (typeof raw.notes !== 'string') {
|
|
257
265
|
throw new PricingOverlayError(`"models.${id}.notes" must be a string`, source);
|
|
@@ -356,6 +364,7 @@ export function applyPricingOverlay(
|
|
|
356
364
|
): PricingCatalogue {
|
|
357
365
|
const overridden: string[] = [];
|
|
358
366
|
const added: string[] = [];
|
|
367
|
+
for (const [id, patch] of Object.entries(overlay.models)) refuseTier(patch, id, source);
|
|
359
368
|
|
|
360
369
|
const models = base.models.map((model) => {
|
|
361
370
|
const patch = overlay.models[model.id];
|
|
@@ -389,7 +398,7 @@ export function applyPricingOverlay(
|
|
|
389
398
|
// `cacheMinTokens` is checked for `undefined` and not for falsiness, so an
|
|
390
399
|
// explicit `null` counts as supplied. That is the point of it: saying "not
|
|
391
400
|
// known" is an answer, leaving it out is not.
|
|
392
|
-
const missing = (['displayName', 'inputPerMTok', 'outputPerMTok', 'contextWindow', 'cacheMinTokens', '
|
|
401
|
+
const missing = (['displayName', 'inputPerMTok', 'outputPerMTok', 'contextWindow', 'cacheMinTokens', 'capability'] as const).filter(
|
|
393
402
|
(key) => patch[key] === undefined,
|
|
394
403
|
);
|
|
395
404
|
if (missing.length > 0) {
|