@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/dist/weekly.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
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 type { PlanActionKind, PlanAssumption, PlanDocument } from './plan.js';
|
|
24
|
+
import type { UsageProfileReport } from './usage.js';
|
|
25
|
+
export declare const WEEK_MS: number;
|
|
26
|
+
/** How many changes a weekly summary names. Three is the issue's number; more is a list nobody acts on. */
|
|
27
|
+
export declare const WEEKLY_CHANGES = 3;
|
|
28
|
+
/** How many models the bill and the movement name before saying how many more there are. */
|
|
29
|
+
export declare const WEEKLY_MODELS = 5;
|
|
30
|
+
export declare const WEEKLY_MOVERS = 3;
|
|
31
|
+
/** A window, half-open like every window in the profile: two adjacent weeks share no call. */
|
|
32
|
+
export interface WeekWindow {
|
|
33
|
+
sinceMs: number;
|
|
34
|
+
untilMs: number;
|
|
35
|
+
/** The first UTC day inside it, `YYYY-MM-DD`. */
|
|
36
|
+
firstDay: string;
|
|
37
|
+
/** The last UTC day inside it. */
|
|
38
|
+
lastDay: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The week ending at `untilMs` and the week before it.
|
|
42
|
+
*
|
|
43
|
+
* Seven days each, back to back, with no overlap and no gap: the week before
|
|
44
|
+
* ends at the instant this one begins.
|
|
45
|
+
*/
|
|
46
|
+
export declare function weekWindows(untilMs: number): {
|
|
47
|
+
current: WeekWindow;
|
|
48
|
+
previous: WeekWindow;
|
|
49
|
+
};
|
|
50
|
+
export interface WeeklyModelRow {
|
|
51
|
+
model: string;
|
|
52
|
+
calls: number;
|
|
53
|
+
usd: number;
|
|
54
|
+
}
|
|
55
|
+
export interface WeeklyMover {
|
|
56
|
+
model: string;
|
|
57
|
+
previousUsd: number;
|
|
58
|
+
currentUsd: number;
|
|
59
|
+
deltaUsd: number;
|
|
60
|
+
}
|
|
61
|
+
export interface WeeklyChange {
|
|
62
|
+
rank: number;
|
|
63
|
+
kind: PlanActionKind;
|
|
64
|
+
/** The workload, `UNLABELLED` when the log named none. */
|
|
65
|
+
label: string;
|
|
66
|
+
model: string;
|
|
67
|
+
/** Projected, for route and batch: not measured, and never rendered as if it were. */
|
|
68
|
+
projectedSavingUsd: number | null;
|
|
69
|
+
/** Measured: money already spent on the problem the change fixes. */
|
|
70
|
+
measuredStakeUsd: number | null;
|
|
71
|
+
/** What this workload and model cost this week, measured. Null when the plan did not record it. */
|
|
72
|
+
sliceUsd: number | null;
|
|
73
|
+
sliceCalls: number | null;
|
|
74
|
+
routeTo: string | null;
|
|
75
|
+
/** What the log cannot confirm about this change, as the plan states it. */
|
|
76
|
+
assumes: PlanAssumption[];
|
|
77
|
+
}
|
|
78
|
+
export interface WeeklySummary {
|
|
79
|
+
current: WeekWindow;
|
|
80
|
+
previous: WeekWindow;
|
|
81
|
+
/** This week's bill: what could be priced, and only that. */
|
|
82
|
+
totalUsd: number;
|
|
83
|
+
calls: number;
|
|
84
|
+
/** Priced models, largest first, at most `WEEKLY_MODELS`; `moreModels` counts the rest. */
|
|
85
|
+
models: WeeklyModelRow[];
|
|
86
|
+
moreModels: number;
|
|
87
|
+
unpricedModels: string[];
|
|
88
|
+
unpricedCalls: number;
|
|
89
|
+
/** Calls with no clock that a windowed report cannot place in any week. */
|
|
90
|
+
undatedExcluded: number;
|
|
91
|
+
/**
|
|
92
|
+
* Against the week before, or null when that week holds no call: a ratio
|
|
93
|
+
* against nothing is not a change, and the summary says there was no week
|
|
94
|
+
* to compare rather than print a number for it.
|
|
95
|
+
*/
|
|
96
|
+
comparison: null | {
|
|
97
|
+
previousUsd: number;
|
|
98
|
+
previousCalls: number;
|
|
99
|
+
deltaUsd: number;
|
|
100
|
+
/** Null when the week before cost nothing priced: no percentage of zero. */
|
|
101
|
+
deltaPct: number | null;
|
|
102
|
+
movers: WeeklyMover[];
|
|
103
|
+
};
|
|
104
|
+
/** The first `WEEKLY_CHANGES` actions of the plan, largest money first. */
|
|
105
|
+
changes: WeeklyChange[];
|
|
106
|
+
/** How many actions the plan had in all. */
|
|
107
|
+
changesAvailable: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Builds the summary from the week's report, the week before's, and the plan
|
|
111
|
+
* made from this week's.
|
|
112
|
+
*/
|
|
113
|
+
export declare function buildWeeklySummary(current: UsageProfileReport, previous: UsageProfileReport, plan: PlanDocument, windows: {
|
|
114
|
+
current: WeekWindow;
|
|
115
|
+
previous: WeekWindow;
|
|
116
|
+
}): WeeklySummary;
|
|
117
|
+
/** The figures a summary may print, as the strings it prints them as. */
|
|
118
|
+
export interface BillFigures {
|
|
119
|
+
/** Every dollar amount, as `formatUsd` writes it and without a sign. */
|
|
120
|
+
usd: ReadonlySet<string>;
|
|
121
|
+
/** Every percentage, one decimal, without a sign and without the `%`. */
|
|
122
|
+
pct: ReadonlySet<string>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* What the reports hold, worked out from the reports.
|
|
126
|
+
*
|
|
127
|
+
* It reads the two reports and the plan directly and shares nothing with
|
|
128
|
+
* `buildWeeklySummary`, so a figure the builder gets wrong (a total scaled, a
|
|
129
|
+
* delta taken the wrong way round, a saving summed across actions that
|
|
130
|
+
* overlap) is not in this set and is named by `strayFigures`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function billFigures(current: UsageProfileReport, previous: UsageProfileReport, plan: PlanDocument): BillFigures;
|
|
133
|
+
/**
|
|
134
|
+
* The dollar amounts and percentages in a rendered summary that no report
|
|
135
|
+
* holds. Empty when every one is accounted for.
|
|
136
|
+
*/
|
|
137
|
+
export declare function strayFigures(markdown: string, figures: BillFigures): string[];
|
|
138
|
+
/** The identifier a weekly summary carries so a re-run replaces it rather than adding a second. */
|
|
139
|
+
export declare function weeklyMarker(lastDay: string): string;
|
|
140
|
+
//# sourceMappingURL=weekly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly.d.ts","sourceRoot":"","sources":["../src/weekly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGrD,eAAO,MAAM,OAAO,QAAa,CAAC;AAElC,2GAA2G;AAC3G,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,4FAA4F;AAC5F,eA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AAG,MAAM,EAAE,CAU7E;AAED,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
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,GAAG,MAAM,CAAC;AAElC,2GAA2G;AAC3G,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAY/B,MAAM,KAAK,GAAG,CAAC,EAAU,E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C,CAAC;IACvC,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,OAAoB;IACjE,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAC/D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IACD,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,sBAAsB,OAAO,MAAM,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,
|
|
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,M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,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.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
|
@@ -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/budget.ts
CHANGED
|
@@ -159,7 +159,8 @@ function priceOf(record: StoreRecord, catalogue: PricingCatalogue): number | nul
|
|
|
159
159
|
/* A record of one request says its prompt; any other only bounds it. */
|
|
160
160
|
const prompt = record.input + record.cacheRead + record.write5m + record.write1h;
|
|
161
161
|
const rates = effectivePricing(model, at, record.calls === 1 ? { inputTokens: prompt } : { inputTokensAtMost: prompt });
|
|
162
|
-
|
|
162
|
+
// The ratios of the call as priced; a store record does not say it was a batch call.
|
|
163
|
+
const ratios = multipliersFor(model, at, rates);
|
|
163
164
|
return (
|
|
164
165
|
(record.input * rates.inputPerMTok +
|
|
165
166
|
record.cacheRead * rates.inputPerMTok * ratios.cacheRead +
|
package/src/connector.ts
CHANGED
|
@@ -618,7 +618,7 @@ export function bucketedProfile(
|
|
|
618
618
|
bucket.calls === 1 ? { inputTokens: prompt, ...how } : { inputTokensAtMost: prompt, ...how },
|
|
619
619
|
);
|
|
620
620
|
const { inputPerMTok, outputPerMTok } = priced;
|
|
621
|
-
const rates = multipliersFor(model, at);
|
|
621
|
+
const rates = multipliersFor(model, at, priced);
|
|
622
622
|
const per = (count: number, rate: number): number => (count / 1_000_000) * rate;
|
|
623
623
|
const costAt = (input: number, output: number): number =>
|
|
624
624
|
per(bucket.inputTokens, input) +
|
package/src/conversation.ts
CHANGED
|
@@ -97,8 +97,10 @@ function inputCostOf(record: UsageRecord, catalogue: PricingCatalogue, on: Date)
|
|
|
97
97
|
const model = catalogue.byId.get(record.model);
|
|
98
98
|
if (!model) return null;
|
|
99
99
|
const at = billedAt(record, on);
|
|
100
|
-
const
|
|
101
|
-
const
|
|
100
|
+
const how = promptSizeOf(record);
|
|
101
|
+
const { inputPerMTok } = effectivePricing(model, at, how);
|
|
102
|
+
// The same call, so a batch call's cache read is the Batch table's.
|
|
103
|
+
const rates = multipliersFor(model, at, how);
|
|
102
104
|
const per = (tokens: number, rate: number): number => (tokens / 1_000_000) * rate;
|
|
103
105
|
return (
|
|
104
106
|
per(record.inputTokens, inputPerMTok) +
|
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 }) => ({
|