@trazum/core 2.7.11 → 3.0.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 +1 -1
- 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/budget.d.ts.map +1 -1
- package/dist/budget.js +2 -1
- package/dist/budget.js.map +1 -1
- package/dist/connector.js +1 -1
- package/dist/connector.js.map +1 -1
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +4 -2
- package/dist/conversation.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/input-shape.d.ts.map +1 -1
- package/dist/input-shape.js +4 -2
- package/dist/input-shape.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/phrases.d.ts +39 -0
- package/dist/phrases.d.ts.map +1 -1
- package/dist/phrases.js +130 -0
- package/dist/phrases.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 +21 -11
- package/dist/pricing-overlay.js.map +1 -1
- package/dist/pricing.d.ts +33 -6
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +77 -115
- package/dist/pricing.js.map +1 -1
- package/dist/repeats.d.ts.map +1 -1
- package/dist/repeats.js +4 -2
- package/dist/repeats.js.map +1 -1
- package/dist/reprice.js +1 -1
- package/dist/reprice.js.map +1 -1
- package/dist/review.js +2 -1
- package/dist/review.js.map +1 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +119 -3
- package/dist/rules.js.map +1 -1
- package/dist/segment.d.ts +31 -1
- package/dist/segment.d.ts.map +1 -1
- package/dist/segment.js +128 -2
- package/dist/segment.js.map +1 -1
- package/dist/session-cost.d.ts.map +1 -1
- package/dist/session-cost.js +4 -2
- package/dist/session-cost.js.map +1 -1
- package/dist/session-ledger.d.ts.map +1 -1
- package/dist/session-ledger.js +4 -2
- package/dist/session-ledger.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/truncation-retry.d.ts.map +1 -1
- package/dist/truncation-retry.js +4 -2
- package/dist/truncation-retry.js.map +1 -1
- package/dist/ttl-fit.d.ts.map +1 -1
- package/dist/ttl-fit.js +4 -2
- package/dist/ttl-fit.js.map +1 -1
- package/dist/types.d.ts +17 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +13 -12
- package/dist/usage.js.map +1 -1
- 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/budget.ts +2 -1
- package/src/connector.ts +1 -1
- package/src/conversation.ts +4 -2
- 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/input-shape.ts +4 -2
- package/src/openrouter.ts +1 -2
- package/src/phrases.ts +134 -0
- package/src/pricing-overlay.ts +23 -14
- package/src/pricing.ts +82 -120
- package/src/repeats.ts +4 -2
- package/src/reprice.ts +1 -1
- package/src/review.ts +1 -1
- package/src/rules.ts +135 -2
- package/src/segment.ts +131 -3
- package/src/session-cost.ts +4 -2
- package/src/session-ledger.ts +4 -2
- package/src/structure.ts +152 -13
- package/src/truncation-retry.ts +4 -2
- package/src/ttl-fit.ts +4 -2
- package/src/types.ts +18 -7
- package/src/usage.ts +13 -12
- package/src/watch.ts +12 -1
- package/src/weekly.ts +281 -0
- package/src/write.ts +2 -2
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/input-shape.ts
CHANGED
|
@@ -192,8 +192,10 @@ export function createInputShapeTracker(options: InputShapeOptions): InputShapeT
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
const at = billedAt(record, on);
|
|
195
|
-
const
|
|
196
|
-
const
|
|
195
|
+
const how = promptSizeOf(record);
|
|
196
|
+
const { inputPerMTok } = effectivePricing(model, at, how);
|
|
197
|
+
// The same call, so a batch call's cache read is the Batch table's.
|
|
198
|
+
const rates = multipliersFor(model, at, how);
|
|
197
199
|
const per = (count: number, rate: number): number => (count / 1_000_000) * rate;
|
|
198
200
|
|
|
199
201
|
slice.calls += 1;
|
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/phrases.ts
CHANGED
|
@@ -184,6 +184,7 @@ export const POLITENESS: readonly string[] = [
|
|
|
184
184
|
"if you don't mind",
|
|
185
185
|
'if you would be so kind',
|
|
186
186
|
'much appreciated',
|
|
187
|
+
'many thanks',
|
|
187
188
|
|
|
188
189
|
// Spanish
|
|
189
190
|
'por favor',
|
|
@@ -237,6 +238,139 @@ export const POLITENESS: readonly string[] = [
|
|
|
237
238
|
'dank u',
|
|
238
239
|
];
|
|
239
240
|
|
|
241
|
+
/**
|
|
242
|
+
* The entries of `POLITENESS` that thank somebody, as opposed to softening an
|
|
243
|
+
* instruction.
|
|
244
|
+
*
|
|
245
|
+
* The two were one list and one behaviour, delete the phrase wherever it
|
|
246
|
+
* stands, and that is right for "please" and wrong for a thanks. A thanks is
|
|
247
|
+
* rarely a word on its own: it has an object ("thank you **for your help**"),
|
|
248
|
+
* or it is the thing the prompt is talking about ("if the user says
|
|
249
|
+
* **thanks**", "start every reply with **Thank you for contacting us**").
|
|
250
|
+
* Measured on 2026-11-17, at the safe level:
|
|
251
|
+
*
|
|
252
|
+
* Thank you so much for your help with this. -> So much for your help with this.
|
|
253
|
+
* Tell the customer: thank you for your order. -> Tell the customer: for your order.
|
|
254
|
+
* If the user says thanks, reply politely. -> If the user says reply politely.
|
|
255
|
+
* Thanks to the new policy refunds take five days. -> To the new policy refunds take five days.
|
|
256
|
+
*
|
|
257
|
+
* A fragment, a broken instruction, a changed instruction and a deleted
|
|
258
|
+
* preposition. So these are removed only as a whole sentence that does nothing
|
|
259
|
+
* but thank, and left exactly as written anywhere else: `rules.ts`,
|
|
260
|
+
* `removeThanks`.
|
|
261
|
+
*/
|
|
262
|
+
export const THANKS: readonly string[] = [
|
|
263
|
+
// English
|
|
264
|
+
'thanks in advance',
|
|
265
|
+
'thank you very much',
|
|
266
|
+
'thank you',
|
|
267
|
+
'thanks',
|
|
268
|
+
'much appreciated',
|
|
269
|
+
'many thanks',
|
|
270
|
+
// Spanish
|
|
271
|
+
'muchas gracias',
|
|
272
|
+
'gracias de antemano',
|
|
273
|
+
'te lo agradezco',
|
|
274
|
+
'te agradecería',
|
|
275
|
+
'gracias',
|
|
276
|
+
// French
|
|
277
|
+
'merci beaucoup',
|
|
278
|
+
"merci d'avance",
|
|
279
|
+
'merci',
|
|
280
|
+
'je vous remercie',
|
|
281
|
+
// German
|
|
282
|
+
'vielen Dank',
|
|
283
|
+
'danke im Voraus',
|
|
284
|
+
'danke',
|
|
285
|
+
'ich danke Ihnen',
|
|
286
|
+
// Portuguese
|
|
287
|
+
'muito obrigado',
|
|
288
|
+
'muito obrigada',
|
|
289
|
+
'obrigado',
|
|
290
|
+
'obrigada',
|
|
291
|
+
'agradeço desde já',
|
|
292
|
+
// Italian
|
|
293
|
+
'grazie mille',
|
|
294
|
+
'grazie in anticipo',
|
|
295
|
+
'grazie',
|
|
296
|
+
'ti ringrazio',
|
|
297
|
+
// Dutch
|
|
298
|
+
'hartelijk dank',
|
|
299
|
+
'bedankt',
|
|
300
|
+
'dank je',
|
|
301
|
+
'dank u',
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* What may follow a thanks and still leave the sentence nothing but a thanks:
|
|
306
|
+
* how much, and when. "Thank you **so much**", "gracias **de antemano**".
|
|
307
|
+
*/
|
|
308
|
+
export const THANKS_DEGREE: readonly string[] = [
|
|
309
|
+
// English
|
|
310
|
+
'so much',
|
|
311
|
+
'so very much',
|
|
312
|
+
'very much',
|
|
313
|
+
'a lot',
|
|
314
|
+
'again',
|
|
315
|
+
'in advance',
|
|
316
|
+
// Spanish
|
|
317
|
+
'mucho',
|
|
318
|
+
'de antemano',
|
|
319
|
+
'de nuevo',
|
|
320
|
+
// French
|
|
321
|
+
'beaucoup',
|
|
322
|
+
"d'avance",
|
|
323
|
+
'par avance',
|
|
324
|
+
'infiniment',
|
|
325
|
+
'encore',
|
|
326
|
+
// German
|
|
327
|
+
'vielmals',
|
|
328
|
+
'im Voraus',
|
|
329
|
+
'nochmals',
|
|
330
|
+
// Portuguese
|
|
331
|
+
'desde já',
|
|
332
|
+
'antecipadamente',
|
|
333
|
+
// Italian
|
|
334
|
+
'mille',
|
|
335
|
+
'in anticipo',
|
|
336
|
+
'ancora',
|
|
337
|
+
// Dutch
|
|
338
|
+
'alvast',
|
|
339
|
+
'bij voorbaat',
|
|
340
|
+
'nogmaals',
|
|
341
|
+
];
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The word that introduces what the thanks is for. Deliberately not "to":
|
|
345
|
+
* "thanks **to** the new policy" is a cause, not a courtesy, and the same goes
|
|
346
|
+
* for "gracias **a**" and "grazie **a**".
|
|
347
|
+
*/
|
|
348
|
+
export const THANKS_FOR: readonly string[] = [
|
|
349
|
+
'for', // English
|
|
350
|
+
'por', // Spanish, Portuguese
|
|
351
|
+
'pela',
|
|
352
|
+
'pelo',
|
|
353
|
+
'pour', // French
|
|
354
|
+
'für', // German
|
|
355
|
+
'per', // Italian
|
|
356
|
+
'voor', // Dutch
|
|
357
|
+
];
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* A verb that makes "thank you for X ..." a statement about the phrase rather
|
|
361
|
+
* than a thanks: "Thank you for your order **is** the subject line". Seen
|
|
362
|
+
* after the thanks, the sentence is left alone.
|
|
363
|
+
*/
|
|
364
|
+
export const THANKS_NOT_A_THANKS: readonly string[] = [
|
|
365
|
+
'is', 'are', 'was', 'were', 'should', 'must', 'means', 'will', 'can',
|
|
366
|
+
'es', 'son', 'debe', 'significa',
|
|
367
|
+
'est', 'sont', 'doit',
|
|
368
|
+
'ist', 'sind', 'muss', 'soll',
|
|
369
|
+
'são', 'deve',
|
|
370
|
+
'sono',
|
|
371
|
+
'zijn', 'moet',
|
|
372
|
+
];
|
|
373
|
+
|
|
240
374
|
/** Filler and throat-clearing with no content. */
|
|
241
375
|
export const FILLER: readonly string[] = [
|
|
242
376
|
// English
|
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',
|
|
@@ -59,9 +58,8 @@ const PROMO_KEYS = ['inputPerMTok', 'outputPerMTok', 'until'] as const;
|
|
|
59
58
|
* has no batch API" should stop the advisory offering a discount nobody sells,
|
|
60
59
|
* while "nobody has said" should fall back to the default.
|
|
61
60
|
*/
|
|
62
|
-
const MULTIPLIER_KEYS = ['cacheRead', 'cacheWrite5m', 'cacheWrite1h', 'batch'] as const;
|
|
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
|
|
|
@@ -165,7 +163,7 @@ function parseMultipliers(raw: unknown, label: string, source: string): CostMult
|
|
|
165
163
|
}
|
|
166
164
|
|
|
167
165
|
const multipliers: CostMultipliers = {};
|
|
168
|
-
for (const key of ['cacheRead', 'cacheWrite5m', 'cacheWrite1h'] as const) {
|
|
166
|
+
for (const key of ['cacheRead', 'cacheWrite5m', 'cacheWrite1h', 'batchCacheRead'] as const) {
|
|
169
167
|
if (raw[key] === undefined) continue;
|
|
170
168
|
/**
|
|
171
169
|
* Zero is refused along with the negatives. A free cache read is not a price
|
|
@@ -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) {
|